diff --git a/components/crowdpower/actions/create-customer-charge/create-customer-charge.mjs b/components/crowdpower/actions/create-customer-charge/create-customer-charge.mjs new file mode 100644 index 0000000000000..64bd9f65f9e10 --- /dev/null +++ b/components/crowdpower/actions/create-customer-charge/create-customer-charge.mjs @@ -0,0 +1,44 @@ +import app from "../../crowdpower.app.mjs"; + +export default { + key: "crowdpower-create-customer-charge", + name: "Create Customer Charge", + description: "Create a charge for a user. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#d89820d6-5d65-4ff7-87ba-6cddb359d8f3)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + app, + userId: { + propDefinition: [ + app, + "userId", + ], + }, + amount: { + propDefinition: [ + app, + "amount", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createCustomerCharge({ + $, + data: { + user_id: this.userId, + amount: this.amount, + }, + }); + + $.export("$summary", response.success + ? `Request succeeded with code ${response.code}` + : `Request failed with code ${response.code}`); + + return response; + }, +}; diff --git a/components/crowdpower/actions/create-customer-event/create-customer-event.mjs b/components/crowdpower/actions/create-customer-event/create-customer-event.mjs new file mode 100644 index 0000000000000..b4087a4a7f6e2 --- /dev/null +++ b/components/crowdpower/actions/create-customer-event/create-customer-event.mjs @@ -0,0 +1,50 @@ +import app from "../../crowdpower.app.mjs"; + +export default { + key: "crowdpower-create-customer-event", + name: "Create Customer Event", + description: "Create a new event related to a customer. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#63159fcd-7df3-46c5-ac83-eeb72678b650)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + app, + userId: { + propDefinition: [ + app, + "userId", + ], + }, + customAttributes: { + propDefinition: [ + app, + "customAttributes", + ], + description: "Custom attributes of the event", + }, + action: { + propDefinition: [ + app, + "action", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createCustomerEvent({ + $, + data: { + user_id: this.userId, + custom_attributes: this.customAttributes, + action: this.action, + }, + }); + $.export("$summary", response.success + ? `Request succeeded with code ${response.code}` + : `Request failed with code ${response.code}`); + return response; + }, +}; diff --git a/components/crowdpower/actions/upsert-customer/upsert-customer.mjs b/components/crowdpower/actions/upsert-customer/upsert-customer.mjs new file mode 100644 index 0000000000000..50e0801b2024f --- /dev/null +++ b/components/crowdpower/actions/upsert-customer/upsert-customer.mjs @@ -0,0 +1,57 @@ +import app from "../../crowdpower.app.mjs"; + +export default { + key: "crowdpower-upsert-customer", + name: "Upsert Customer", + description: "Create or update a customer. [See the documentation](https://documenter.getpostman.com/view/17896162/UV5TFKbh#9415bd14-59ab-47b1-b0ec-73826d9cb5db)", + version: "0.0.1", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + type: "action", + props: { + app, + userId: { + propDefinition: [ + app, + "userId", + ], + description: "ID of the customer that will be created or updated", + }, + email: { + propDefinition: [ + app, + "email", + ], + }, + name: { + propDefinition: [ + app, + "name", + ], + }, + customAttributes: { + propDefinition: [ + app, + "customAttributes", + ], + }, + }, + async run({ $ }) { + const response = await this.app.upsertCustomer({ + $, + data: { + user_id: this.userId, + email: this.email, + name: this.name, + custom_attributes: this.customAttributes, + }, + }); + $.export("$summary", response.success + ? `Request succeeded with code ${response.code}` + : `Request failed with code ${response.code}`); + return response; + }, +}; diff --git a/components/crowdpower/crowdpower.app.mjs b/components/crowdpower/crowdpower.app.mjs index 92280f098b7ae..7add8268f06e4 100644 --- a/components/crowdpower/crowdpower.app.mjs +++ b/components/crowdpower/crowdpower.app.mjs @@ -1,11 +1,80 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "crowdpower", - propDefinitions: {}, + propDefinitions: { + userId: { + type: "string", + label: "User ID", + description: "ID of the user", + }, + amount: { + type: "string", + label: "Amount", + description: "Amount of the charge", + }, + email: { + type: "string", + label: "Email", + description: "Email of the customer", + }, + name: { + type: "string", + label: "Name", + description: "Name of the customer", + }, + customAttributes: { + type: "object", + label: "Custom Attributes", + description: "Custom attributes", + }, + action: { + type: "string", + label: "Action", + description: "Action related to the event", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://beacon.crowdpower.io"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + "Authorization": `Bearer ${this.$auth.application_key}`, + ...headers, + }, + }); + }, + async createCustomerCharge(args = {}) { + return this._makeRequest({ + path: "/charges", + method: "post", + ...args, + }); + }, + async upsertCustomer(args = {}) { + return this._makeRequest({ + path: "/customers", + method: "post", + ...args, + }); + }, + async createCustomerEvent(args = {}) { + return this._makeRequest({ + path: "/events", + method: "post", + ...args, + }); }, }, }; diff --git a/components/crowdpower/package.json b/components/crowdpower/package.json index 1c836fdd3c64e..6e6f9203ebda1 100644 --- a/components/crowdpower/package.json +++ b/components/crowdpower/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/crowdpower", - "version": "0.0.4", + "version": "0.1.0", "description": "Pipedream CrowdPower Components", "main": "crowdpower.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 67b1fae5d8a03..725f7f3e6f3c8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3558,7 +3558,11 @@ importers: specifier: ^0.0.1-security version: 0.0.1-security - components/crowdpower: {} + components/crowdpower: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/crunchbase: dependencies: @@ -31832,17 +31836,17 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net supports-color@10.2.2: resolution: {integrity: sha512-SS+jx45GF1QjgEXQx4NJZV9ImqmO2NPz5FNsIHrsDjh2YsHnawpan7SNQ1o8NuhrbHZy9AZhIoCUiCeaW/C80g==} @@ -39533,7 +39537,6 @@ snapshots: transitivePeerDependencies: - rolldown - rollup - - supports-color '@putout/operator-parens@2.0.0(rolldown@1.0.0-beta.9)(rollup@4.53.2)': dependencies: