diff --git a/components/modelry/actions/create-product/create-product.mjs b/components/modelry/actions/create-product/create-product.mjs new file mode 100644 index 0000000000000..0ca7d44ef022c --- /dev/null +++ b/components/modelry/actions/create-product/create-product.mjs @@ -0,0 +1,72 @@ +import app from "../../modelry.app.mjs"; + +export default { + key: "modelry-create-product", + name: "Create Product", + description: "Create a new product. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-CreateProduct)", + version: "0.0.1", + type: "action", + props: { + app, + sku: { + propDefinition: [ + app, + "sku", + ], + }, + title: { + propDefinition: [ + app, + "title", + ], + }, + batchId: { + propDefinition: [ + app, + "batchId", + ], + }, + description: { + propDefinition: [ + app, + "description", + ], + }, + tags: { + propDefinition: [ + app, + "tags", + ], + }, + dimensions: { + propDefinition: [ + app, + "dimensions", + ], + }, + externalUrl: { + propDefinition: [ + app, + "externalUrl", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createProduct({ + $, + data: { + product: { + sku: this.sku, + title: this.title, + batch_id: this.batchId, + description: this.description, + tags: this.tags, + dimensions: this.dimensions, + external_url: this.externalUrl, + }, + }, + }); + $.export("$summary", `Successfully created product "${response.data.attributes.title}" with ID: ${response.data.id}`); + return response; + }, +}; diff --git a/components/modelry/actions/delete-product/delete-product.mjs b/components/modelry/actions/delete-product/delete-product.mjs new file mode 100644 index 0000000000000..03de485ba2724 --- /dev/null +++ b/components/modelry/actions/delete-product/delete-product.mjs @@ -0,0 +1,26 @@ +import app from "../../modelry.app.mjs"; + +export default { + key: "modelry-delete-product", + name: "Delete Product", + description: "Delete the product with the specified ID. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-DeleteProduct)", + version: "0.0.1", + type: "action", + props: { + app, + productId: { + propDefinition: [ + app, + "productId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.deleteProduct({ + $, + productId: this.productId, + }); + $.export("$summary", "Successfully deleted the product"); + return response; + }, +}; diff --git a/components/modelry/actions/get-product/get-product.mjs b/components/modelry/actions/get-product/get-product.mjs new file mode 100644 index 0000000000000..1c2df38ce4568 --- /dev/null +++ b/components/modelry/actions/get-product/get-product.mjs @@ -0,0 +1,26 @@ +import app from "../../modelry.app.mjs"; + +export default { + key: "modelry-get-product", + name: "Get Product", + description: "Get details of the product with the specified ID. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-GetProduct)", + version: "0.0.1", + type: "action", + props: { + app, + productId: { + propDefinition: [ + app, + "productId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getProduct({ + $, + productId: this.productId, + }); + $.export("$summary", `Successfully retrieved the details for the product "${response.data.attributes.title}" with ID: ${response.data.id}`); + return response; + }, +}; diff --git a/components/modelry/modelry.app.mjs b/components/modelry/modelry.app.mjs index 4ffe3be2c6abc..b4b2f9eacf6fd 100644 --- a/components/modelry/modelry.app.mjs +++ b/components/modelry/modelry.app.mjs @@ -1,11 +1,115 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "modelry", - propDefinitions: {}, + propDefinitions: { + sku: { + type: "string", + label: "SKU", + description: "SKU of the product", + }, + title: { + type: "string", + label: "Title", + description: "Name or title of the product", + }, + batchId: { + type: "string", + label: "Batch ID", + description: "Identifier of the product's batch", + optional: true, + }, + description: { + type: "string", + label: "Description", + description: "Description of the product", + optional: true, + }, + tags: { + type: "string[]", + label: "Tags", + description: "Keywords associated with the product", + optional: true, + }, + dimensions: { + type: "string", + label: "Dimensions", + description: "Dimensions of the product", + optional: true, + }, + externalUrl: { + type: "string", + label: "External URL", + description: "External URL of the product", + optional: true, + }, + productId: { + type: "string", + label: "Product ID", + description: "Identifier of the product", + async options() { + const response = await this.getProducts(); + const products = response.data; + return products.map(({ + attributes, id, + }) => ({ + label: attributes.title, + value: id, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.modelry.ai/api/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "Content-Type": "application/json", + "Authorization": `${this.$auth.api_token}`, + }, + }); + }, + async createProduct(args = {}) { + return this._makeRequest({ + path: "/products", + method: "post", + ...args, + }); + }, + async getProduct({ + productId, args, + }) { + return this._makeRequest({ + path: `/products/${productId}/`, + ...args, + }); + }, + async deleteProduct({ + productId, args, + }) { + return this._makeRequest({ + path: `/products/${productId}/`, + method: "delete", + ...args, + }); + }, + async getProducts(args = {}) { + return this._makeRequest({ + path: "/products", + ...args, + }); }, }, }; diff --git a/components/modelry/package.json b/components/modelry/package.json index 25c76568ef418..95a818668cb22 100644 --- a/components/modelry/package.json +++ b/components/modelry/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/modelry", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Modelry Components", "main": "modelry.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6f7c7a68c5507..9aff9ab8a8b11 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8209,7 +8209,11 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/modelry: {} + components/modelry: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/modern_treasury: dependencies: