diff --git a/components/swell/actions/create-account/create-account.mjs b/components/swell/actions/create-account/create-account.mjs new file mode 100644 index 0000000000000..7d90fd5a7b57f --- /dev/null +++ b/components/swell/actions/create-account/create-account.mjs @@ -0,0 +1,56 @@ +import app from "../../swell.app.mjs"; + +export default { + key: "swell-create-account", + name: "Create Account", + description: "Create a new customer account. [See the documentation](https://developers.swell.is/backend-api/accounts/create-an-account)", + version: "0.0.1", + type: "action", + props: { + app, + email: { + propDefinition: [ + app, + "email", + ], + }, + firstName: { + propDefinition: [ + app, + "firstName", + ], + }, + lastName: { + propDefinition: [ + app, + "lastName", + ], + }, + phone: { + propDefinition: [ + app, + "phone", + ], + }, + notes: { + propDefinition: [ + app, + "notes", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createAccount({ + $, + data: { + email: this.email, + first_name: this.firstName, + last_name: this.lastName, + phone: this.phone, + notes: this.notes, + }, + }); + $.export("$summary", "Successfully created account with ID: " + response.id); + return response; + }, +}; diff --git a/components/swell/actions/create-product/create-product.mjs b/components/swell/actions/create-product/create-product.mjs new file mode 100644 index 0000000000000..394fce5d1bf8c --- /dev/null +++ b/components/swell/actions/create-product/create-product.mjs @@ -0,0 +1,56 @@ +import app from "../../swell.app.mjs"; + +export default { + key: "swell-create-product", + name: "Create Product", + description: "Create a new product. [See the documentation](https://developers.swell.is/backend-api/products/create-a-product)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + propDefinition: [ + app, + "name", + ], + }, + price: { + propDefinition: [ + app, + "price", + ], + }, + active: { + propDefinition: [ + app, + "active", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + discontinued: { + propDefinition: [ + app, + "discontinued", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createProduct({ + $, + data: { + name: this.name, + price: this.price, + active: this.active, + description: this.description, + discontinued: this.discontinued, + }, + }); + $.export("$summary", "Successfully created product with ID: " + response.id); + return response; + }, +}; diff --git a/components/swell/actions/update-account/update-account.mjs b/components/swell/actions/update-account/update-account.mjs new file mode 100644 index 0000000000000..17ad04316bc1e --- /dev/null +++ b/components/swell/actions/update-account/update-account.mjs @@ -0,0 +1,63 @@ +import app from "../../swell.app.mjs"; + +export default { + key: "swell-update-account", + name: "Update Account", + description: "Update an existing account with the corresponding ID. [See the documentation](https://developers.swell.is/backend-api/accounts/update-an-account)", + version: "0.0.1", + type: "action", + props: { + app, + email: { + propDefinition: [ + app, + "email", + ], + }, + firstName: { + propDefinition: [ + app, + "firstName", + ], + }, + lastName: { + propDefinition: [ + app, + "lastName", + ], + }, + phone: { + propDefinition: [ + app, + "phone", + ], + }, + notes: { + propDefinition: [ + app, + "notes", + ], + }, + accountId: { + propDefinition: [ + app, + "accountId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.updateAccount({ + $, + accountId: this.accountId, + data: { + email: this.email, + first_name: this.firstName, + last_name: this.lastName, + phone: this.phone, + notes: this.notes, + }, + }); + $.export("$summary", "Successfully updated account with ID: " + this.id); + return response; + }, +}; diff --git a/components/swell/package.json b/components/swell/package.json index 51f4fc82d16db..6bb3eb92ef86d 100644 --- a/components/swell/package.json +++ b/components/swell/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/swell", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Swell Components", "main": "swell.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/swell/swell.app.mjs b/components/swell/swell.app.mjs index b40551e180569..9742b471d7a01 100644 --- a/components/swell/swell.app.mjs +++ b/components/swell/swell.app.mjs @@ -1,11 +1,125 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "swell", - propDefinitions: {}, + propDefinitions: { + email: { + type: "string", + label: "Email", + description: "The account's email address", + }, + firstName: { + type: "string", + label: "First Name", + description: "The account's first name", + optional: true, + }, + lastName: { + type: "string", + label: "Last Name", + description: "The account's last name", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "The account's phone number", + optional: true, + }, + notes: { + type: "string", + label: "Notes", + description: "Additional notes about the account", + optional: true, + }, + name: { + type: "string", + label: "Name", + description: "The product's full name or display name", + }, + price: { + type: "string", + label: "Price", + description: "The price associated with the product", + optional: true, + }, + active: { + type: "boolean", + label: "Active", + description: "Whether the product is active", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "A description of the product", + optional: true, + }, + discontinued: { + type: "boolean", + label: "Discontinued", + description: "Whether the product is discontinued", + optional: true, + }, + accountId: { + type: "string", + label: "Account ID", + description: "ID of the account that will be updated", + async options() { + const { results } = await this.getAccounts(); + return results.map(({ + email, id, + }) => ({ + label: email, + value: id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `https://${this.$auth.store_id}:${this.$auth.secret_key}@api.swell.store`; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + }); + }, + async createAccount(args = {}) { + return this._makeRequest({ + path: "/accounts", + method: "post", + ...args, + }); + }, + async createProduct(args = {}) { + return this._makeRequest({ + path: "/products", + method: "post", + ...args, + }); + }, + async updateAccount({ + accountId, ...args + }) { + return this._makeRequest({ + path: `/accounts/${accountId}`, + method: "put", + ...args, + }); + }, + async getAccounts(args = {}) { + return this._makeRequest({ + path: "/accounts", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a3850d51c9e4f..6c75965045b1f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4308,8 +4308,7 @@ importers: components/facebook_conversions: {} - components/facebook_graph_api: - specifiers: {} + components/facebook_graph_api: {} components/facebook_groups: dependencies: @@ -4929,8 +4928,7 @@ importers: components/gatekeeper: {} - components/gather: - specifiers: {} + components/gather: {} components/gatherup: dependencies: @@ -12664,7 +12662,11 @@ importers: specifier: ^1.2.0 version: 1.6.6 - components/swell: {} + components/swell: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/swiftype: {}