Skip to content

Commit 22e9810

Browse files
authored
New Components - stripo (#15511)
* wip * wip * new components * pnpm-lock.yaml
1 parent 5657705 commit 22e9810

File tree

8 files changed

+292
-7
lines changed

8 files changed

+292
-7
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import stripo from "../../stripo.app.mjs";
2+
3+
export default {
4+
key: "stripo-get-raw-html",
5+
name: "Get Raw HTML & CSS",
6+
description: "Retrieves the HTML and CSS code of the selected email message in Stripo. [See the documentation](https://api.stripo.email/reference/getrawemail)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
stripo,
11+
emailId: {
12+
propDefinition: [
13+
stripo,
14+
"emailId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.stripo.getRawHtml({
20+
$,
21+
emailId: this.emailId,
22+
});
23+
$.export("$summary", `Successfully retrieved HTML & CSS from email with ID: ${this.emailId}`);
24+
return response;
25+
},
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import stripo from "../../stripo.app.mjs";
2+
3+
export default {
4+
key: "stripo-remove-email",
5+
name: "Remove Email",
6+
description: "Removes an existing message from the user's project in Stripo. [See the documentation](https://api.stripo.email/reference/deleteemail)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
stripo,
11+
emailId: {
12+
propDefinition: [
13+
stripo,
14+
"emailId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.stripo.removeEmail({
20+
$,
21+
emailId: this.emailId,
22+
});
23+
$.export("$summary", `Successfully removed email with ID: ${this.emailId}`);
24+
return response;
25+
},
26+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import stripo from "../../stripo.app.mjs";
2+
3+
export default {
4+
key: "stripo-search-emails",
5+
name: "Search Emails",
6+
description: "Searches existing emails by search query in Stripo. [See the documentation](https://api.stripo.email/reference/findemails)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
stripo,
11+
query: {
12+
propDefinition: [
13+
stripo,
14+
"query",
15+
],
16+
},
17+
maxResults: {
18+
type: "integer",
19+
label: "Max Results",
20+
description: "The maximum number of results to return",
21+
default: 100,
22+
optional: true,
23+
},
24+
},
25+
async run({ $ }) {
26+
const results = this.stripo.paginate({
27+
fn: this.stripo.listEmails,
28+
params: {
29+
queryStr: this.query,
30+
},
31+
max: this.maxResults,
32+
});
33+
34+
const emails = [];
35+
for await (const item of results) {
36+
emails.push(item);
37+
}
38+
39+
$.export("$summary", `Successfully retrieved ${emails.length} email${emails.length === 1
40+
? ""
41+
: "s"}`);
42+
return emails;
43+
},
44+
};

components/stripo/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/stripo",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Stripo Components",
55
"main": "stripo.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
}
15-
}
18+
}
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+
propDefinition: [
23+
stripo,
24+
"query",
25+
],
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: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,98 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "stripo",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
emailId: {
8+
type: "string",
9+
label: "Email ID",
10+
description: "The identifier of an email",
11+
async options({ page }) {
12+
const { data } = await this.listEmails({
13+
params: {
14+
page,
15+
},
16+
});
17+
return data?.map(({
18+
emailId: value, name: label,
19+
}) => ({
20+
value,
21+
label,
22+
})) || [];
23+
},
24+
},
25+
query: {
26+
type: "string",
27+
label: "Query",
28+
description: "The query to search for",
29+
optional: true,
30+
},
31+
},
532
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
33+
_baseUrl() {
34+
return "https://my.stripo.email/emailgeneration/v1";
35+
},
36+
_makeRequest({
37+
$ = this,
38+
path,
39+
...opts
40+
}) {
41+
return axios($, {
42+
url: `${this._baseUrl()}${path}`,
43+
headers: {
44+
"Stripo-Api-Auth": this.$auth.api_key,
45+
"Content-Type": "application/json",
46+
},
47+
...opts,
48+
});
49+
},
50+
listEmails(opts = {}) {
51+
return this._makeRequest({
52+
path: "/emails",
53+
...opts,
54+
});
55+
},
56+
getRawHtml({
57+
emailId, ...opts
58+
}) {
59+
return this._makeRequest({
60+
path: `/raw-email/${emailId}`,
61+
...opts,
62+
});
63+
},
64+
removeEmail({
65+
emailId, ...opts
66+
}) {
67+
return this._makeRequest({
68+
method: "DELETE",
69+
path: `/emails/${emailId}`,
70+
...opts,
71+
});
72+
},
73+
async *paginate({
74+
fn, params, max,
75+
}) {
76+
params = {
77+
...params,
78+
page: 0,
79+
};
80+
let totalResults, count = 0;
81+
do {
82+
const {
83+
data, total,
84+
} = await fn({
85+
params,
86+
});
87+
totalResults = total;
88+
for (const item of data) {
89+
yield item;
90+
count++;
91+
if (max && count >= max) {
92+
return;
93+
}
94+
}
95+
} while (count < totalResults);
996
},
1097
},
1198
};

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)