-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathmodelry.app.mjs
115 lines (114 loc) · 2.52 KB
/
modelry.app.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { axios } from "@pipedream/platform";
export default {
type: "app",
app: "modelry",
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: {
_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,
});
},
},
};