Skip to content

Commit 106b401

Browse files
authored
[Components] modelry #12525 (#16350)
* Added actions * Added return id
1 parent d285e5f commit 106b401

File tree

6 files changed

+241
-6
lines changed

6 files changed

+241
-6
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import app from "../../modelry.app.mjs";
2+
3+
export default {
4+
key: "modelry-create-product",
5+
name: "Create Product",
6+
description: "Create a new product. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-CreateProduct)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
sku: {
12+
propDefinition: [
13+
app,
14+
"sku",
15+
],
16+
},
17+
title: {
18+
propDefinition: [
19+
app,
20+
"title",
21+
],
22+
},
23+
batchId: {
24+
propDefinition: [
25+
app,
26+
"batchId",
27+
],
28+
},
29+
description: {
30+
propDefinition: [
31+
app,
32+
"description",
33+
],
34+
},
35+
tags: {
36+
propDefinition: [
37+
app,
38+
"tags",
39+
],
40+
},
41+
dimensions: {
42+
propDefinition: [
43+
app,
44+
"dimensions",
45+
],
46+
},
47+
externalUrl: {
48+
propDefinition: [
49+
app,
50+
"externalUrl",
51+
],
52+
},
53+
},
54+
async run({ $ }) {
55+
const response = await this.app.createProduct({
56+
$,
57+
data: {
58+
product: {
59+
sku: this.sku,
60+
title: this.title,
61+
batch_id: this.batchId,
62+
description: this.description,
63+
tags: this.tags,
64+
dimensions: this.dimensions,
65+
external_url: this.externalUrl,
66+
},
67+
},
68+
});
69+
$.export("$summary", `Successfully created product "${response.data.attributes.title}" with ID: ${response.data.id}`);
70+
return response;
71+
},
72+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import app from "../../modelry.app.mjs";
2+
3+
export default {
4+
key: "modelry-delete-product",
5+
name: "Delete Product",
6+
description: "Delete the product with the specified ID. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-DeleteProduct)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
productId: {
12+
propDefinition: [
13+
app,
14+
"productId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.deleteProduct({
20+
$,
21+
productId: this.productId,
22+
});
23+
$.export("$summary", "Successfully deleted the product");
24+
return response;
25+
},
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import app from "../../modelry.app.mjs";
2+
3+
export default {
4+
key: "modelry-get-product",
5+
name: "Get Product",
6+
description: "Get details of the product with the specified ID. [See the documentation](https://files.cgtarsenal.com/api/doc/index.html#api-Products-GetProduct)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
productId: {
12+
propDefinition: [
13+
app,
14+
"productId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.app.getProduct({
20+
$,
21+
productId: this.productId,
22+
});
23+
$.export("$summary", `Successfully retrieved the details for the product "${response.data.attributes.title}" with ID: ${response.data.id}`);
24+
return response;
25+
},
26+
};

components/modelry/modelry.app.mjs

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,115 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "modelry",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
sku: {
8+
type: "string",
9+
label: "SKU",
10+
description: "SKU of the product",
11+
},
12+
title: {
13+
type: "string",
14+
label: "Title",
15+
description: "Name or title of the product",
16+
},
17+
batchId: {
18+
type: "string",
19+
label: "Batch ID",
20+
description: "Identifier of the product's batch",
21+
optional: true,
22+
},
23+
description: {
24+
type: "string",
25+
label: "Description",
26+
description: "Description of the product",
27+
optional: true,
28+
},
29+
tags: {
30+
type: "string[]",
31+
label: "Tags",
32+
description: "Keywords associated with the product",
33+
optional: true,
34+
},
35+
dimensions: {
36+
type: "string",
37+
label: "Dimensions",
38+
description: "Dimensions of the product",
39+
optional: true,
40+
},
41+
externalUrl: {
42+
type: "string",
43+
label: "External URL",
44+
description: "External URL of the product",
45+
optional: true,
46+
},
47+
productId: {
48+
type: "string",
49+
label: "Product ID",
50+
description: "Identifier of the product",
51+
async options() {
52+
const response = await this.getProducts();
53+
const products = response.data;
54+
return products.map(({
55+
attributes, id,
56+
}) => ({
57+
label: attributes.title,
58+
value: id,
59+
}));
60+
},
61+
},
62+
},
563
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
64+
_baseUrl() {
65+
return "https://api.modelry.ai/api/v1";
66+
},
67+
async _makeRequest(opts = {}) {
68+
const {
69+
$ = this,
70+
path,
71+
headers,
72+
...otherOpts
73+
} = opts;
74+
return axios($, {
75+
...otherOpts,
76+
url: this._baseUrl() + path,
77+
headers: {
78+
...headers,
79+
"Content-Type": "application/json",
80+
"Authorization": `${this.$auth.api_token}`,
81+
},
82+
});
83+
},
84+
async createProduct(args = {}) {
85+
return this._makeRequest({
86+
path: "/products",
87+
method: "post",
88+
...args,
89+
});
90+
},
91+
async getProduct({
92+
productId, args,
93+
}) {
94+
return this._makeRequest({
95+
path: `/products/${productId}/`,
96+
...args,
97+
});
98+
},
99+
async deleteProduct({
100+
productId, args,
101+
}) {
102+
return this._makeRequest({
103+
path: `/products/${productId}/`,
104+
method: "delete",
105+
...args,
106+
});
107+
},
108+
async getProducts(args = {}) {
109+
return this._makeRequest({
110+
path: "/products",
111+
...args,
112+
});
9113
},
10114
},
11115
};

components/modelry/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/modelry",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Modelry Components",
55
"main": "modelry.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)