Skip to content

Commit 407d8d0

Browse files
authored
Merging pull request #18955
* Added actions * Added actions
1 parent 1e00997 commit 407d8d0

File tree

7 files changed

+280
-7
lines changed

7 files changed

+280
-7
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import app from "../../asin_data_api.app.mjs";
2+
3+
export default {
4+
key: "asin_data_api-create-collection",
5+
name: "Create Collection",
6+
description: "Create a collection to run requests in Asin Data API. [See the documentation](https://docs.trajectdata.com/asindataapi/collections-api/collections/create)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
name: {
17+
propDefinition: [
18+
app,
19+
"name",
20+
],
21+
},
22+
enabled: {
23+
propDefinition: [
24+
app,
25+
"enabled",
26+
],
27+
},
28+
priority: {
29+
propDefinition: [
30+
app,
31+
"priority",
32+
],
33+
},
34+
notificationEmail: {
35+
propDefinition: [
36+
app,
37+
"notificationEmail",
38+
],
39+
},
40+
notificationAsCsv: {
41+
propDefinition: [
42+
app,
43+
"notificationAsCsv",
44+
],
45+
},
46+
},
47+
async run({ $ }) {
48+
const response = await this.app.createCollection({
49+
$,
50+
data: {
51+
name: this.name,
52+
enabled: this.enabled,
53+
priority: this.priority,
54+
notification_email: this.notificationEmail,
55+
notification_as_csv: this.notificationAsCsv,
56+
},
57+
});
58+
$.export("$summary", "Successfully created a collection named: " + this.name);
59+
return response;
60+
},
61+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import app from "../../asin_data_api.app.mjs";
2+
3+
export default {
4+
key: "asin_data_api-delete-collection",
5+
name: "Delete Collection",
6+
description: "Delete a collection from Asin Data API. [See the documentation](https://docs.trajectdata.com/asindataapi/collections-api/collections/delete)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: true,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
collectionId: {
17+
propDefinition: [
18+
app,
19+
"collectionId",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
const response = await this.app.deleteCollection({
25+
$,
26+
collectionId: this.collectionId,
27+
});
28+
$.export("$summary", "Successfully deleted the collection with ID: " + this.collectionId);
29+
return response;
30+
},
31+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import app from "../../asin_data_api.app.mjs";
2+
3+
export default {
4+
key: "asin_data_api-update-collection",
5+
name: "Update Collection",
6+
description: "Update a collection in Asin Data API. [See the documentation](https://docs.trajectdata.com/asindataapi/collections-api/collections/update)",
7+
version: "0.0.1",
8+
annotations: {
9+
destructiveHint: false,
10+
openWorldHint: true,
11+
readOnlyHint: false,
12+
},
13+
type: "action",
14+
props: {
15+
app,
16+
collectionId: {
17+
propDefinition: [
18+
app,
19+
"collectionId",
20+
],
21+
},
22+
name: {
23+
propDefinition: [
24+
app,
25+
"name",
26+
],
27+
},
28+
enabled: {
29+
propDefinition: [
30+
app,
31+
"enabled",
32+
],
33+
},
34+
priority: {
35+
propDefinition: [
36+
app,
37+
"priority",
38+
],
39+
},
40+
notificationEmail: {
41+
propDefinition: [
42+
app,
43+
"notificationEmail",
44+
],
45+
},
46+
notificationAsCsv: {
47+
propDefinition: [
48+
app,
49+
"notificationAsCsv",
50+
],
51+
},
52+
},
53+
async run({ $ }) {
54+
const response = await this.app.updateCollection({
55+
$,
56+
collectionId: this.collectionId,
57+
data: {
58+
name: this.name,
59+
enabled: this.enabled,
60+
priority: this.priority,
61+
notification_email: this.notificationEmail,
62+
notification_as_csv: this.notificationAsCsv,
63+
},
64+
});
65+
$.export("$summary", "Successfully updated the collection with ID: " + this.collectionId);
66+
return response;
67+
},
68+
};
Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,108 @@
1+
import { axios } from "@pipedream/platform";
2+
import constants from "./common/constants.mjs";
3+
14
export default {
25
type: "app",
36
app: "asin_data_api",
4-
propDefinitions: {},
7+
propDefinitions: {
8+
name: {
9+
type: "string",
10+
label: "Name",
11+
description: "The name of the Collection",
12+
},
13+
enabled: {
14+
type: "boolean",
15+
label: "Enabled",
16+
description: "Determines whether the Collection is enabled; disabled Collections do not start automatically",
17+
optional: true,
18+
},
19+
priority: {
20+
type: "string",
21+
label: "Priority",
22+
description: "Determines the priority level of the Collection when multiple Collections are queued",
23+
optional: true,
24+
options: constants.PRIORITY_OPTIONS,
25+
},
26+
notificationEmail: {
27+
type: "string",
28+
label: "Notification Email",
29+
description: "Email address to receive notifications",
30+
optional: true,
31+
},
32+
notificationAsCsv: {
33+
type: "boolean",
34+
label: "Notification as CSV",
35+
description: "Determines whether results are sent in CSV format",
36+
optional: true,
37+
},
38+
collectionId: {
39+
type: "string",
40+
label: "Collection ID",
41+
description: "Unique identifier of the Collection",
42+
async options() {
43+
const response = await this.listCollections();
44+
const collections = response.collections;
45+
return collections.map(({
46+
id,
47+
name,
48+
}) => ({
49+
value: id,
50+
label: name,
51+
}));
52+
},
53+
},
54+
55+
},
556
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
57+
_baseUrl() {
58+
return "https://api.asindataapi.com";
59+
},
60+
async _makeRequest(opts = {}) {
61+
const {
62+
$ = this,
63+
path,
64+
params,
65+
...otherOpts
66+
} = opts;
67+
return axios($, {
68+
...otherOpts,
69+
url: this._baseUrl() + path,
70+
params: {
71+
api_key: `${this.$auth.api_key}`,
72+
...params,
73+
},
74+
});
75+
},
76+
async createCollection(args = {}) {
77+
return this._makeRequest({
78+
path: "/collections",
79+
method: "post",
80+
...args,
81+
});
82+
},
83+
async updateCollection({
84+
collectionId, ...args
85+
}) {
86+
return this._makeRequest({
87+
path: `/collections/${collectionId}`,
88+
method: "put",
89+
...args,
90+
});
91+
},
92+
async deleteCollection({
93+
collectionId, ...args
94+
}) {
95+
return this._makeRequest({
96+
path: `/collections/${collectionId}`,
97+
method: "delete",
98+
...args,
99+
});
100+
},
101+
async listCollections(args = {}) {
102+
return this._makeRequest({
103+
path: "/collections",
104+
...args,
105+
});
9106
},
10107
},
11-
};
108+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
PRIORITY_OPTIONS: [
3+
"highest",
4+
"high",
5+
"normal",
6+
"low",
7+
"lowest",
8+
],
9+
};

components/asin_data_api/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/asin_data_api",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream ASIN Data API Components",
55
"main": "asin_data_api.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.1.0"
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)