diff --git a/components/stripo/actions/get-raw-html/get-raw-html.mjs b/components/stripo/actions/get-raw-html/get-raw-html.mjs new file mode 100644 index 0000000000000..f7146d996e402 --- /dev/null +++ b/components/stripo/actions/get-raw-html/get-raw-html.mjs @@ -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; + }, +}; diff --git a/components/stripo/actions/remove-email/remove-email.mjs b/components/stripo/actions/remove-email/remove-email.mjs new file mode 100644 index 0000000000000..0572393109732 --- /dev/null +++ b/components/stripo/actions/remove-email/remove-email.mjs @@ -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; + }, +}; diff --git a/components/stripo/actions/search-emails/search-emails.mjs b/components/stripo/actions/search-emails/search-emails.mjs new file mode 100644 index 0000000000000..b9c2a586cb4a5 --- /dev/null +++ b/components/stripo/actions/search-emails/search-emails.mjs @@ -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; + }, +}; diff --git a/components/stripo/package.json b/components/stripo/package.json index 445122f4bb721..f4200d7bf8425 100644 --- a/components/stripo/package.json +++ b/components/stripo/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/stripo", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Stripo Components", "main": "stripo.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/components/stripo/sources/new-email-created/new-email-created.mjs b/components/stripo/sources/new-email-created/new-email-created.mjs new file mode 100644 index 0000000000000..bcca28cca9157 --- /dev/null +++ b/components/stripo/sources/new-email-created/new-email-created.mjs @@ -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, +}; diff --git a/components/stripo/sources/new-email-created/test-event.mjs b/components/stripo/sources/new-email-created/test-event.mjs new file mode 100644 index 0000000000000..516b4ed70b184 --- /dev/null +++ b/components/stripo/sources/new-email-created/test-event.mjs @@ -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" +} \ No newline at end of file diff --git a/components/stripo/stripo.app.mjs b/components/stripo/stripo.app.mjs index b50391386481a..433af24ff2f07 100644 --- a/components/stripo/stripo.app.mjs +++ b/components/stripo/stripo.app.mjs @@ -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); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d66742efa5ea7..3cceb39e13ddf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1522,8 +1522,7 @@ importers: specifier: ^0.1.4 version: 0.1.6 - components/buysellads: - specifiers: {} + components/buysellads: {} components/bybit: dependencies: @@ -5697,8 +5696,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/klipy: - specifiers: {} + components/klipy: {} components/knack: dependencies: @@ -10367,7 +10365,11 @@ importers: specifier: ^8.168.0 version: 8.222.0 - components/stripo: {} + components/stripo: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/studio_by_ai21_labs: {}