Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions components/modelry/actions/create-product/create-product.mjs
Original file line number Diff line number Diff line change
@@ -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 the product");
return response;
Copy link
Contributor

@coderabbitai coderabbitai bot Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add response validation before reporting success.

The action currently reports successful product creation regardless of the API response. Consider checking the response status or structure before declaring success.

- $.export("$summary", "Successfully created the product");
- return response;
+ const { data } = response;
+ $.export("$summary", `Successfully created product "${data.product.title}" with ID: ${data.product.id}`);
+ return data;

This assumes the response includes the created product details. Adjust according to the actual API response structure.

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lcaresia if the response includes an ID, I'd apply this suggestion from CodeRabbit, since that is the standard we adopt for summaries

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

},
};
26 changes: 26 additions & 0 deletions components/modelry/actions/delete-product/delete-product.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};
26 changes: 26 additions & 0 deletions components/modelry/actions/get-product/get-product.mjs
Original file line number Diff line number Diff line change
@@ -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 product details");
return response;
},
};
112 changes: 108 additions & 4 deletions components/modelry/modelry.app.mjs
Original file line number Diff line number Diff line change
@@ -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,
});
},
},
};
5 changes: 4 additions & 1 deletion components/modelry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/modelry",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Modelry Components",
"main": "modelry.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading