Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 139 additions & 5 deletions components/_4dem/_4dem.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,145 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "_4dem",
propDefinitions: {},
propDefinitions: {
name: {
type: "string",
label: "Name",
description: "Name of the sender",
},
email: {
type: "string",
label: "Email",
description: "Email address",
},
nominative: {
type: "string",
label: "Nominative",
description: "Sender nominativa, i.e. `My Company`",
},
ivaFCode: {
type: "string",
label: "IVA Code",
description: "Sender IVA code, i.e. `IT123456789`",
},
address: {
type: "string",
label: "Address",
description: "Sender address, i.e. `Via Roma 1`",
},
city: {
type: "string",
label: "City",
description: "Sender city, i.e. `Torino`",
},
province: {
type: "string",
label: "Province",
description: "Abbreviation of the province, i.e. `TO`",
},
country: {
type: "string",
label: "Country",
description: "Sender country, i.e. `Italia`",
},
cap: {
type: "string",
label: "Postal Code",
description: "Sender postal code, i.e. `10100`",
},
telephone: {
type: "string",
label: "Telephone",
description: "Telephone number, i.e.`+393331234567`",
},
senderId: {
type: "string",
label: "Sender ID",
description: "ID of the sender",
async options() {
const { data: sendersIds } = await this.getSenders();

return sendersIds.map(({
id, name,
}) => ({
value: id,
label: name,
}));
},
},
authCode: {
type: "string",
label: "Auth Code",
description: "Authenticator code sent to the provided email",
},
subject: {
type: "string",
label: "Email Subject",
description: "Subject of the email",
},
plain: {
type: "string",
label: "Plain Content",
description: "Plain content of the email",
optional: true,
},
html: {
type: "string",
label: "HTML Content",
description: "HTML content of the email",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.4dem.it";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
},
});
},
async createSender(args = {}) {
return this._makeRequest({
method: "post",
path: "/senders/email",
...args,
});
},
async confirmEmail({
senderId, ...args
}) {
return this._makeRequest({
method: "post",
path: `/senders/email/${senderId}/confirm`,
...args,
});
},
async createEmail(args = {}) {
return this._makeRequest({
method: "post",
path: "/contents/emails",
...args,
});
},
async getSenders(args = {}) {
return this._makeRequest({
path: "/senders/email",
...args,
});
},
},
};
};
37 changes: 37 additions & 0 deletions components/_4dem/actions/confirm-email/confirm-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import app from "../../_4dem.app.mjs";

export default {
key: "_4dem-confirm-email",
name: "Confirm Email",
description: "Confirm sender email address. [See the documentation](https://api.4dem.it/#/operations/senders.email.confirm)",
version: "0.0.1",
type: "action",
props: {
app,
senderId: {
propDefinition: [
app,
"senderId",
],
},
authCode: {
propDefinition: [
app,
"authCode",
],
},
},
async run({ $ }) {
const response = await this.app.confirmEmail({
$,
senderId: this.senderId,
data: {
auth_code: this.authCode,
},
});

$.export("$summary", "Successfully confirmed the sender email");

return response;
},
};
63 changes: 63 additions & 0 deletions components/_4dem/actions/create-email/create-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import app from "../../_4dem.app.mjs";

export default {
key: "_4dem-create-email",
name: "Create Email",
description: "Create a new email. [See the documentation](https://api.4dem.it/#/operations/contents.email.store)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
propDefinition: [
app,
"name",
],
description: "Email Name",
},
subject: {
propDefinition: [
app,
"subject",
],
},
senderId: {
propDefinition: [
app,
"senderId",
],
},
plain: {
propDefinition: [
app,
"plain",
],
},
html: {
propDefinition: [
app,
"html",
],
},
},
async run({ $ }) {
const response = await this.app.createEmail({
$,
data: {
name: this.name,
subject: this.subject,
sender: {
id: this.senderId,
},
content: {
plain: this.plain,
html: this.html,
},
},
});

$.export("$summary", `Successfully created email '${this.name}'`);

return response;
},
};
95 changes: 95 additions & 0 deletions components/_4dem/actions/create-sender/create-sender.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import app from "../../_4dem.app.mjs";

export default {
key: "_4dem-create-sender",
name: "Create Sender",
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)",
version: "0.0.1",
type: "action",
props: {
app,
name: {
propDefinition: [
app,
"name",
],
},
email: {
propDefinition: [
app,
"email",
],
},
nominative: {
propDefinition: [
app,
"nominative",
],
},
ivaFCode: {
propDefinition: [
app,
"ivaFCode",
],
},
address: {
propDefinition: [
app,
"address",
],
},
city: {
propDefinition: [
app,
"city",
],
},
province: {
propDefinition: [
app,
"province",
],
},
country: {
propDefinition: [
app,
"country",
],
},
cap: {
propDefinition: [
app,
"cap",
],
},
telephone: {
propDefinition: [
app,
"telephone",
],
},
},
async run({ $ }) {
const response = await this.app.createSender({
$,
data: {
name: this.name,
email: this.email,
csa_data: {
nominative: this.nominative,
ivaFCode: this.ivaFCode,
address: this.address,
city: this.city,
province: this.province,
country: this.country,
cap: this.cap,
telephone: this.telephone,
},
},
});

$.export("$summary", "Successfully created the sender, now it's necessary to confirm it with the code sent to the provided email");

return response;
},
};
7 changes: 5 additions & 2 deletions components/_4dem/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/_4dem",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream 4Dem Components",
"main": "_4dem.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.