Skip to content

Commit 1de9273

Browse files
committed
Added actions
1 parent 4329ac8 commit 1de9273

File tree

6 files changed

+305
-11
lines changed

6 files changed

+305
-11
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import app from "../../swell.app.mjs";
2+
3+
export default {
4+
key: "swell-create-account",
5+
name: "Create Account",
6+
description: "Create a new customer account. [See the documentation](https://developers.swell.is/backend-api/accounts/create-an-account)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
email: {
12+
propDefinition: [
13+
app,
14+
"email",
15+
],
16+
},
17+
firstName: {
18+
propDefinition: [
19+
app,
20+
"firstName",
21+
],
22+
},
23+
lastName: {
24+
propDefinition: [
25+
app,
26+
"lastName",
27+
],
28+
},
29+
phone: {
30+
propDefinition: [
31+
app,
32+
"phone",
33+
],
34+
},
35+
notes: {
36+
propDefinition: [
37+
app,
38+
"notes",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.app.createAccount({
44+
$,
45+
data: {
46+
email: this.email,
47+
first_name: this.firstName,
48+
last_name: this.lastName,
49+
phone: this.phone,
50+
notes: this.notes,
51+
},
52+
});
53+
$.export("$summary", "Successfully created account with ID: " + response.id);
54+
return response;
55+
},
56+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import app from "../../swell.app.mjs";
2+
3+
export default {
4+
key: "swell-create-product",
5+
name: "Create Product",
6+
description: "Create a new product. [See the documentation](https://developers.swell.is/backend-api/products/create-a-product)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name",
15+
],
16+
},
17+
price: {
18+
propDefinition: [
19+
app,
20+
"price",
21+
],
22+
},
23+
active: {
24+
propDefinition: [
25+
app,
26+
"active",
27+
],
28+
},
29+
description: {
30+
propDefinition: [
31+
app,
32+
"description",
33+
],
34+
},
35+
discontinued: {
36+
propDefinition: [
37+
app,
38+
"discontinued",
39+
],
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.app.createProduct({
44+
$,
45+
data: {
46+
name: this.name,
47+
price: this.price,
48+
active: this.active,
49+
description: this.description,
50+
discontinued: this.discontinued,
51+
},
52+
});
53+
$.export("$summary", "Successfully created product with ID: " + response.id);
54+
return response;
55+
},
56+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../swell.app.mjs";
2+
3+
export default {
4+
key: "swell-update-account",
5+
name: "Update Account",
6+
description: "Update an existing account with the corresponding ID. [See the documentation](https://developers.swell.is/backend-api/accounts/update-an-account)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
email: {
12+
propDefinition: [
13+
app,
14+
"email",
15+
],
16+
},
17+
firstName: {
18+
propDefinition: [
19+
app,
20+
"firstName",
21+
],
22+
},
23+
lastName: {
24+
propDefinition: [
25+
app,
26+
"lastName",
27+
],
28+
},
29+
phone: {
30+
propDefinition: [
31+
app,
32+
"phone",
33+
],
34+
},
35+
notes: {
36+
propDefinition: [
37+
app,
38+
"notes",
39+
],
40+
},
41+
accountId: {
42+
propDefinition: [
43+
app,
44+
"accountId",
45+
],
46+
},
47+
},
48+
async run({ $ }) {
49+
const response = await this.app.updateAccount({
50+
$,
51+
accountId: this.accountId,
52+
data: {
53+
email: this.email,
54+
first_name: this.firstName,
55+
last_name: this.lastName,
56+
phone: this.phone,
57+
notes: this.notes,
58+
},
59+
});
60+
$.export("$summary", "Successfully updated account with ID: " + this.id);
61+
return response;
62+
},
63+
};

components/swell/package.json

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

components/swell/swell.app.mjs

Lines changed: 119 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,125 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "swell",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
email: {
8+
type: "string",
9+
label: "Email",
10+
description: "The account's email address",
11+
},
12+
firstName: {
13+
type: "string",
14+
label: "First Name",
15+
description: "The account's first name",
16+
optional: true,
17+
},
18+
lastName: {
19+
type: "string",
20+
label: "Last Name",
21+
description: "The account's last name",
22+
optional: true,
23+
},
24+
phone: {
25+
type: "string",
26+
label: "Phone",
27+
description: "The account's phone number",
28+
optional: true,
29+
},
30+
notes: {
31+
type: "string",
32+
label: "Notes",
33+
description: "Additional notes about the account",
34+
optional: true,
35+
},
36+
name: {
37+
type: "string",
38+
label: "Name",
39+
description: "The product's full name or display name",
40+
},
41+
price: {
42+
type: "string",
43+
label: "Price",
44+
description: "The price associated with the product",
45+
optional: true,
46+
},
47+
active: {
48+
type: "boolean",
49+
label: "Active",
50+
description: "Whether the product is active",
51+
optional: true,
52+
},
53+
description: {
54+
type: "string",
55+
label: "Description",
56+
description: "A description of the product",
57+
optional: true,
58+
},
59+
discontinued: {
60+
type: "boolean",
61+
label: "Discontinued",
62+
description: "Whether the product is discontinued",
63+
optional: true,
64+
},
65+
accountId: {
66+
type: "string",
67+
label: "Account ID",
68+
description: "ID of the account that will be updated",
69+
async options() {
70+
const { results } = await this.getAccounts();
71+
return results.map(({
72+
email, id,
73+
}) => ({
74+
label: email,
75+
value: id,
76+
}));
77+
},
78+
},
79+
},
580
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
81+
_baseUrl() {
82+
return `https://${this.$auth.store_id}:${this.$auth.secret_key}@api.swell.store`;
83+
},
84+
async _makeRequest(opts = {}) {
85+
const {
86+
$ = this,
87+
path,
88+
...otherOpts
89+
} = opts;
90+
return axios($, {
91+
...otherOpts,
92+
url: this._baseUrl() + path,
93+
});
94+
},
95+
async createAccount(args = {}) {
96+
return this._makeRequest({
97+
path: "/accounts",
98+
method: "post",
99+
...args,
100+
});
101+
},
102+
async createProduct(args = {}) {
103+
return this._makeRequest({
104+
path: "/products",
105+
method: "post",
106+
...args,
107+
});
108+
},
109+
async updateAccount({
110+
accountId, ...args
111+
}) {
112+
return this._makeRequest({
113+
path: `/accounts/${accountId}`,
114+
method: "put",
115+
...args,
116+
});
117+
},
118+
async getAccounts(args = {}) {
119+
return this._makeRequest({
120+
path: "/accounts",
121+
...args,
122+
});
9123
},
10124
},
11-
};
125+
};

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)