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
26 changes: 26 additions & 0 deletions components/stripo/actions/get-raw-html/get-raw-html.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import stripo from "../../stripo.app.mjs";

export default {
key: "stripo-get-raw-html",
name: "Get Raw HTML & CSS",
description: "Retrieves the HTML and CSS code of the selected email message in Stripo. [See the documentation](https://api.stripo.email/reference/getrawemail)",
version: "0.0.1",
type: "action",
props: {
stripo,
emailId: {
propDefinition: [
stripo,
"emailId",
],
},
},
async run({ $ }) {
const response = await this.stripo.getRawHtml({
$,
emailId: this.emailId,
});
$.export("$summary", `Successfully retrieved HTML & CSS from email with ID: ${this.emailId}`);
return response;
},
};
26 changes: 26 additions & 0 deletions components/stripo/actions/remove-email/remove-email.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import stripo from "../../stripo.app.mjs";

export default {
key: "stripo-remove-email",
name: "Remove Email",
description: "Removes an existing message from the user's project in Stripo. [See the documentation](https://api.stripo.email/reference/deleteemail)",
version: "0.0.1",
type: "action",
props: {
stripo,
emailId: {
propDefinition: [
stripo,
"emailId",
],
},
},
async run({ $ }) {
const response = await this.stripo.removeEmail({
$,
emailId: this.emailId,
});
$.export("$summary", `Successfully removed email with ID: ${this.emailId}`);
return response;
},
};
44 changes: 44 additions & 0 deletions components/stripo/actions/search-emails/search-emails.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import stripo from "../../stripo.app.mjs";

export default {
key: "stripo-search-emails",
name: "Search Emails",
description: "Searches existing emails by search query in Stripo. [See the documentation](https://api.stripo.email/reference/findemails)",
version: "0.0.1",
type: "action",
props: {
stripo,
query: {
propDefinition: [
stripo,
"query",
],
},
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of results to return",
default: 100,
optional: true,
},
},
async run({ $ }) {
const results = this.stripo.paginate({
fn: this.stripo.listEmails,
params: {
queryStr: this.query,
},
max: this.maxResults,
});

const emails = [];
for await (const item of results) {
emails.push(item);
}

$.export("$summary", `Successfully retrieved ${emails.length} email${emails.length === 1
? ""
: "s"}`);
return emails;
},
};
7 changes: 5 additions & 2 deletions components/stripo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/stripo",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Stripo Components",
"main": "stripo.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
84 changes: 84 additions & 0 deletions components/stripo/sources/new-email-created/new-email-created.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import stripo from "../../stripo.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import sampleEmit from "./test-event.mjs";

export default {
key: "stripo-new-email-created",
name: "New Email Created",
description: "Emit new event when a new email is created in Stripo. [See the documentation](https://api.stripo.email/reference/findemails)",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
stripo,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
query: {
propDefinition: [
stripo,
"query",
],
},
},
methods: {
_getLastTs() {
return this.db.get("lastTs") || 0;
},
_setLastTs(lastTs) {
this.db.set("lastTs", lastTs);
},
generateMeta(email) {
return {
id: email.emailId,
summary: `New Email: ${email.name}`,
ts: Date.parse(email.updatedTime),
};
},
async processEvent(max) {
const lastTs = this._getLastTs();

const results = this.stripo.paginate({
fn: this.stripo.listEmails,
params: {
queryStr: this.query,
sortingColumn: "createdTime",
sortingAsc: false,
},
max,
});

const emails = [];
for await (const item of results) {
const ts = Date.parse(item.updatedTime);
if (ts >= lastTs) {
emails.push(item);
}
}

if (!emails.length) {
return;
}

this._setLastTs(Date.parse(emails[0].updatedTime));

emails.reverse().forEach((email) => {
const meta = this.generateMeta(email);
this.$emit(email, meta);
});
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
async run() {
await this.processEvent();
},
sampleEmit,
};
11 changes: 11 additions & 0 deletions components/stripo/sources/new-email-created/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
"emailId": 9031276,
"name": "New Message",
"editorUrl": "https://my.stripo.email/cabinet/#/template-editor/?emailId=9031276&projectId=1189279&type=EMAIL",
"previewUrl": "https://viewstripo.email/575439dc-9d57-4e3f-989e-23a1a63971901738788020521",
"updatedTime": "2025-02-05T20:40:34.46",
"hasAmp": false,
"preheader": null,
"title": "",
"previewImage": "https://doc.stripocdn.email/content/guids/cabinet-icons/87baef10-e401-11ef-a29e-e99b514f747b.png"
}
95 changes: 91 additions & 4 deletions components/stripo/stripo.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,98 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "stripo",
propDefinitions: {},
propDefinitions: {
emailId: {
type: "string",
label: "Email ID",
description: "The identifier of an email",
async options({ page }) {
const { data } = await this.listEmails({
params: {
page,
},
});
return data?.map(({
emailId: value, name: label,
}) => ({
value,
label,
})) || [];
},
},
query: {
type: "string",
label: "Query",
description: "The query to search for",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://my.stripo.email/emailgeneration/v1";
},
_makeRequest({
$ = this,
path,
...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"Stripo-Api-Auth": this.$auth.api_key,
"Content-Type": "application/json",
},
...opts,
});
},
listEmails(opts = {}) {
return this._makeRequest({
path: "/emails",
...opts,
});
},
getRawHtml({
emailId, ...opts
}) {
return this._makeRequest({
path: `/raw-email/${emailId}`,
...opts,
});
},
removeEmail({
emailId, ...opts
}) {
return this._makeRequest({
method: "DELETE",
path: `/emails/${emailId}`,
...opts,
});
},
async *paginate({
fn, params, max,
}) {
params = {
...params,
page: 0,
};
let totalResults, count = 0;
do {
const {
data, total,
} = await fn({
params,
});
totalResults = total;
for (const item of data) {
yield item;
count++;
if (max && count >= max) {
return;
}
}
} while (count < totalResults);
},
},
};
12 changes: 7 additions & 5 deletions pnpm-lock.yaml

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

Loading