Skip to content

Commit 6997b04

Browse files
committed
wip
1 parent 0b62f17 commit 6997b04

File tree

4 files changed

+122
-26
lines changed

4 files changed

+122
-26
lines changed

components/stripo/actions/create-email/create-email.mjs

Whitespace-only changes.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import stripo from "../../stripo.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
key: "stripo-new-email-created",
7+
name: "New Email Created",
8+
description: "Emit new event when a new email is created in Stripo. [See the documentation](https://api.stripo.email/reference/findemails)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
stripo,
14+
db: "$.service.db",
15+
timer: {
16+
type: "$.interface.timer",
17+
default: {
18+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
19+
},
20+
},
21+
query: {
22+
type: "string",
23+
label: "Query",
24+
description: "A query to search for",
25+
optional: true,
26+
},
27+
},
28+
methods: {
29+
_getLastTs() {
30+
return this.db.get("lastTs") || 0;
31+
},
32+
_setLastTs(lastTs) {
33+
this.db.set("lastTs", lastTs);
34+
},
35+
generateMeta(email) {
36+
return {
37+
id: email.emailId,
38+
summary: `New Email: ${email.name}`,
39+
ts: Date.parse(email.updatedTime),
40+
};
41+
},
42+
async processEvent(max) {
43+
const lastTs = this._getLastTs();
44+
45+
const results = this.stripo.paginate({
46+
fn: this.stripo.listEmails,
47+
params: {
48+
queryStr: this.query,
49+
sortingColumn: "createdTime",
50+
sortingAsc: false,
51+
},
52+
max,
53+
});
54+
55+
const emails = [];
56+
for await (const item of results) {
57+
const ts = Date.parse(item.updatedTime);
58+
if (ts >= lastTs) {
59+
emails.push(item);
60+
}
61+
}
62+
63+
if (!emails.length) {
64+
return;
65+
}
66+
67+
this._setLastTs(Date.parse(emails[0].updatedTime));
68+
69+
emails.reverse().forEach((email) => {
70+
const meta = this.generateMeta(email);
71+
this.$emit(email, meta);
72+
});
73+
},
74+
},
75+
hooks: {
76+
async deploy() {
77+
await this.processEvent(25);
78+
},
79+
},
80+
async run() {
81+
await this.processEvent();
82+
},
83+
sampleEmit,
84+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
"emailId": 9031276,
3+
"name": "New Message",
4+
"editorUrl": "https://my.stripo.email/cabinet/#/template-editor/?emailId=9031276&projectId=1189279&type=EMAIL",
5+
"previewUrl": "https://viewstripo.email/575439dc-9d57-4e3f-989e-23a1a63971901738788020521",
6+
"updatedTime": "2025-02-05T20:40:34.46",
7+
"hasAmp": false,
8+
"preheader": null,
9+
"title": "",
10+
"previewImage": "https://doc.stripocdn.email/content/guids/cabinet-icons/87baef10-e401-11ef-a29e-e99b514f747b.png"
11+
}

components/stripo/stripo.app.mjs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,7 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "stripo",
6-
propDefinitions: {
7-
templateId: {
8-
type: "string",
9-
label: "Template ID",
10-
description: "An ID of a template with the auto-generated area. Please note that this template should be yours (saved in the project you have access to), not a basic or a public one.",
11-
async options({ page }) {
12-
const { data } = await this.listTemplates({
13-
params: page,
14-
});
15-
return data?.map(({
16-
templateId: value, name: label,
17-
}) => ({
18-
value,
19-
label,
20-
})) || [];
21-
},
22-
},
23-
},
6+
propDefinitions: {},
247
methods: {
258
_baseUrl() {
269
return "https://my.stripo.email/emailgeneration/v1";
@@ -34,22 +17,40 @@ export default {
3417
url: `${this._baseUrl()}${path}`,
3518
headers: {
3619
"Stripo-Api-Auth": this.$auth.api_key,
20+
"Content-Type": "application/json",
3721
},
3822
...opts,
3923
});
4024
},
41-
listTemplates(opts = {}) {
25+
listEmails(opts = {}) {
4226
return this._makeRequest({
43-
path: "/templates",
27+
path: "/emails",
4428
...opts,
4529
});
4630
},
47-
createEmail(opts = {}) {
48-
return this._makeRequest({
49-
method: "POST",
50-
path: "/email",
51-
...opts,
52-
});
31+
async *paginate({
32+
fn, params, max,
33+
}) {
34+
params = {
35+
...params,
36+
page: 0,
37+
};
38+
let totalResults, count = 0;
39+
do {
40+
const {
41+
data, total,
42+
} = await fn({
43+
params,
44+
});
45+
totalResults = total;
46+
for (const item of data) {
47+
yield item;
48+
count++;
49+
if (max && count >= max) {
50+
return;
51+
}
52+
}
53+
} while (count < totalResults);
5354
},
5455
},
5556
};

0 commit comments

Comments
 (0)