Skip to content

Commit 47f1222

Browse files
authored
Added actions (#12841)
1 parent 2f8c3b4 commit 47f1222

File tree

6 files changed

+343
-8
lines changed

6 files changed

+343
-8
lines changed

components/_4dem/_4dem.app.mjs

Lines changed: 139 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,145 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "_4dem",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
name: {
8+
type: "string",
9+
label: "Name",
10+
description: "Name of the sender",
11+
},
12+
email: {
13+
type: "string",
14+
label: "Email",
15+
description: "Email address",
16+
},
17+
nominative: {
18+
type: "string",
19+
label: "Nominative",
20+
description: "Sender nominativa, i.e. `My Company`",
21+
},
22+
ivaFCode: {
23+
type: "string",
24+
label: "IVA Code",
25+
description: "Sender IVA code, i.e. `IT123456789`",
26+
},
27+
address: {
28+
type: "string",
29+
label: "Address",
30+
description: "Sender address, i.e. `Via Roma 1`",
31+
},
32+
city: {
33+
type: "string",
34+
label: "City",
35+
description: "Sender city, i.e. `Torino`",
36+
},
37+
province: {
38+
type: "string",
39+
label: "Province",
40+
description: "Abbreviation of the province, i.e. `TO`",
41+
},
42+
country: {
43+
type: "string",
44+
label: "Country",
45+
description: "Sender country, i.e. `Italia`",
46+
},
47+
cap: {
48+
type: "string",
49+
label: "Postal Code",
50+
description: "Sender postal code, i.e. `10100`",
51+
},
52+
telephone: {
53+
type: "string",
54+
label: "Telephone",
55+
description: "Telephone number, i.e.`+393331234567`",
56+
},
57+
senderId: {
58+
type: "string",
59+
label: "Sender ID",
60+
description: "ID of the sender",
61+
async options() {
62+
const { data: sendersIds } = await this.getSenders();
63+
64+
return sendersIds.map(({
65+
id, name,
66+
}) => ({
67+
value: id,
68+
label: name,
69+
}));
70+
},
71+
},
72+
authCode: {
73+
type: "string",
74+
label: "Auth Code",
75+
description: "Authenticator code sent to the provided email",
76+
},
77+
subject: {
78+
type: "string",
79+
label: "Email Subject",
80+
description: "Subject of the email",
81+
},
82+
plain: {
83+
type: "string",
84+
label: "Plain Content",
85+
description: "Plain content of the email",
86+
optional: true,
87+
},
88+
html: {
89+
type: "string",
90+
label: "HTML Content",
91+
description: "HTML content of the email",
92+
optional: true,
93+
},
94+
},
595
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
96+
_baseUrl() {
97+
return "https://api.4dem.it";
98+
},
99+
async _makeRequest(opts = {}) {
100+
const {
101+
$ = this,
102+
path,
103+
headers,
104+
...otherOpts
105+
} = opts;
106+
return axios($, {
107+
...otherOpts,
108+
url: this._baseUrl() + path,
109+
headers: {
110+
...headers,
111+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
112+
},
113+
});
114+
},
115+
async createSender(args = {}) {
116+
return this._makeRequest({
117+
method: "post",
118+
path: "/senders/email",
119+
...args,
120+
});
121+
},
122+
async confirmEmail({
123+
senderId, ...args
124+
}) {
125+
return this._makeRequest({
126+
method: "post",
127+
path: `/senders/email/${senderId}/confirm`,
128+
...args,
129+
});
130+
},
131+
async createEmail(args = {}) {
132+
return this._makeRequest({
133+
method: "post",
134+
path: "/contents/emails",
135+
...args,
136+
});
137+
},
138+
async getSenders(args = {}) {
139+
return this._makeRequest({
140+
path: "/senders/email",
141+
...args,
142+
});
9143
},
10144
},
11-
};
145+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import app from "../../_4dem.app.mjs";
2+
3+
export default {
4+
key: "_4dem-confirm-email",
5+
name: "Confirm Email",
6+
description: "Confirm sender email address. [See the documentation](https://api.4dem.it/#/operations/senders.email.confirm)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
senderId: {
12+
propDefinition: [
13+
app,
14+
"senderId",
15+
],
16+
},
17+
authCode: {
18+
propDefinition: [
19+
app,
20+
"authCode",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const response = await this.app.confirmEmail({
26+
$,
27+
senderId: this.senderId,
28+
data: {
29+
auth_code: this.authCode,
30+
},
31+
});
32+
33+
$.export("$summary", "Successfully confirmed the sender email");
34+
35+
return response;
36+
},
37+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import app from "../../_4dem.app.mjs";
2+
3+
export default {
4+
key: "_4dem-create-email",
5+
name: "Create Email",
6+
description: "Create a new email. [See the documentation](https://api.4dem.it/#/operations/contents.email.store)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name",
15+
],
16+
description: "Email Name",
17+
},
18+
subject: {
19+
propDefinition: [
20+
app,
21+
"subject",
22+
],
23+
},
24+
senderId: {
25+
propDefinition: [
26+
app,
27+
"senderId",
28+
],
29+
},
30+
plain: {
31+
propDefinition: [
32+
app,
33+
"plain",
34+
],
35+
},
36+
html: {
37+
propDefinition: [
38+
app,
39+
"html",
40+
],
41+
},
42+
},
43+
async run({ $ }) {
44+
const response = await this.app.createEmail({
45+
$,
46+
data: {
47+
name: this.name,
48+
subject: this.subject,
49+
sender: {
50+
id: this.senderId,
51+
},
52+
content: {
53+
plain: this.plain,
54+
html: this.html,
55+
},
56+
},
57+
});
58+
59+
$.export("$summary", `Successfully created email '${this.name}'`);
60+
61+
return response;
62+
},
63+
};
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import app from "../../_4dem.app.mjs";
2+
3+
export default {
4+
key: "_4dem-create-sender",
5+
name: "Create Sender",
6+
description: "Create an email sender. You will need to confirm the email address used during creation. [See the documentation](https://api.4dem.it/#/operations/senders.email.store)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
propDefinition: [
13+
app,
14+
"name",
15+
],
16+
},
17+
email: {
18+
propDefinition: [
19+
app,
20+
"email",
21+
],
22+
},
23+
nominative: {
24+
propDefinition: [
25+
app,
26+
"nominative",
27+
],
28+
},
29+
ivaFCode: {
30+
propDefinition: [
31+
app,
32+
"ivaFCode",
33+
],
34+
},
35+
address: {
36+
propDefinition: [
37+
app,
38+
"address",
39+
],
40+
},
41+
city: {
42+
propDefinition: [
43+
app,
44+
"city",
45+
],
46+
},
47+
province: {
48+
propDefinition: [
49+
app,
50+
"province",
51+
],
52+
},
53+
country: {
54+
propDefinition: [
55+
app,
56+
"country",
57+
],
58+
},
59+
cap: {
60+
propDefinition: [
61+
app,
62+
"cap",
63+
],
64+
},
65+
telephone: {
66+
propDefinition: [
67+
app,
68+
"telephone",
69+
],
70+
},
71+
},
72+
async run({ $ }) {
73+
const response = await this.app.createSender({
74+
$,
75+
data: {
76+
name: this.name,
77+
email: this.email,
78+
csa_data: {
79+
nominative: this.nominative,
80+
ivaFCode: this.ivaFCode,
81+
address: this.address,
82+
city: this.city,
83+
province: this.province,
84+
country: this.country,
85+
cap: this.cap,
86+
telephone: this.telephone,
87+
},
88+
},
89+
});
90+
91+
$.export("$summary", "Successfully created the sender, now it's necessary to confirm it with the code sent to the provided email");
92+
93+
return response;
94+
},
95+
};

components/_4dem/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/_4dem",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream 4Dem Components",
55
"main": "_4dem.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.0"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 4 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)