diff --git a/components/zylvie/common/constants.mjs b/components/zylvie/common/constants.mjs new file mode 100644 index 0000000000000..9a4dc25888918 --- /dev/null +++ b/components/zylvie/common/constants.mjs @@ -0,0 +1,5 @@ +const BASE_URL = "https://api.zylvie.com"; + +export default { + BASE_URL, +}; diff --git a/components/zylvie/package.json b/components/zylvie/package.json index e6fa8a734330b..1d67105bf8e5b 100644 --- a/components/zylvie/package.json +++ b/components/zylvie/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/zylvie", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Zylvie Components", "main": "zylvie.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.0" } -} \ No newline at end of file +} diff --git a/components/zylvie/sources/common/triggers.mjs b/components/zylvie/sources/common/triggers.mjs new file mode 100644 index 0000000000000..1cfda1acc1dbe --- /dev/null +++ b/components/zylvie/sources/common/triggers.mjs @@ -0,0 +1,7 @@ +export default { + SALE: "sale", + LEAD: "lead", + AFFILIATE: "affiliate", + SUBSCRIPTION: "subscription", + CANCEL: "cancel", +}; diff --git a/components/zylvie/sources/common/webhook.mjs b/components/zylvie/sources/common/webhook.mjs new file mode 100644 index 0000000000000..f0cc6c2c43b35 --- /dev/null +++ b/components/zylvie/sources/common/webhook.mjs @@ -0,0 +1,67 @@ +import { ConfigurationError } from "@pipedream/platform"; +import app from "../../zylvie.app.mjs"; + +export default { + props: { + app, + http: "$.interface.http", + }, + hooks: { + async activate() { + const { + createWebhook, + getTriggerName, + http: { endpoint }, + } = this; + await createWebhook({ + debug: true, + data: { + trigger: getTriggerName(), + webhook_url: endpoint, + }, + }); + }, + async deactivate() { + const { + deleteWebhook, + http: { endpoint }, + } = this; + await deleteWebhook({ + debug: true, + data: { + webhook_url: endpoint, + }, + }); + }, + }, + methods: { + generateMeta() { + throw new ConfigurationError("generateMeta is not implemented"); + }, + getTriggerName() { + throw new ConfigurationError("getTriggerName is not implemented"); + }, + processResource(resource) { + this.$emit(resource, this.generateMeta(resource)); + }, + createWebhook(args = {}) { + return this.app.post({ + path: "/webhooks/subscribe", + ...args, + }); + }, + deleteWebhook(args = {}) { + return this.app.delete({ + path: "/webhooks/unsubscribe", + ...args, + }); + }, + }, + async run({ body }) { + this.http.respond({ + status: 200, + }); + + this.processResource(body); + }, +}; diff --git a/components/zylvie/sources/new-affiliate-sign-up-instant/new-affiliate-sign-up-instant.mjs b/components/zylvie/sources/new-affiliate-sign-up-instant/new-affiliate-sign-up-instant.mjs new file mode 100644 index 0000000000000..a59d225fa6828 --- /dev/null +++ b/components/zylvie/sources/new-affiliate-sign-up-instant/new-affiliate-sign-up-instant.mjs @@ -0,0 +1,29 @@ +import common from "../common/webhook.mjs"; +import triggers from "../common/triggers.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "zylvie-new-affiliate-sign-up-instant", + name: "New Affiliate Sign Up (Instant)", + description: "Emit new event when a visitor signs up to be an affiliate or when they accept an invitation to be an affiliate. [See the documentation](https://developers.zylvie.com/webhooks/subscribe).", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getTriggerName() { + return triggers.AFFILIATE; + }, + generateMeta(payload) { + const { data: resource } = payload; + const ts = Date.parse(resource.accepted_at); + return { + id: resource.id, + summary: `New Affiliate: ${resource.affiliate.name || resource.affiliate.email}`, + ts, + }; + }, + }, + sampleEmit, +}; diff --git a/components/zylvie/sources/new-affiliate-sign-up-instant/test-event.mjs b/components/zylvie/sources/new-affiliate-sign-up-instant/test-event.mjs new file mode 100644 index 0000000000000..3f72b3ebb0301 --- /dev/null +++ b/components/zylvie/sources/new-affiliate-sign-up-instant/test-event.mjs @@ -0,0 +1,21 @@ +export default { + "event": "affiliate", + "data": { + "accepted_at": "2025-03-23T03:12:35Z", + "affiliate": { + "username": "stavros.flatley", + "name": "Stavros Flatley", + "email": "stavros@greek.com" + }, + "commission_percentage": 35.0, + "products": { + "allowed_for_all_products": false, + "allowed_products": [ + { + "title": "The Ultimate Business Book", + "price": 0.0 + } + ] + } + } +}; diff --git a/components/zylvie/sources/new-lead-instant/new-lead-instant.mjs b/components/zylvie/sources/new-lead-instant/new-lead-instant.mjs new file mode 100644 index 0000000000000..ef448dde155a3 --- /dev/null +++ b/components/zylvie/sources/new-lead-instant/new-lead-instant.mjs @@ -0,0 +1,28 @@ +import common from "../common/webhook.mjs"; +import triggers from "../common/triggers.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "zylvie-new-lead-instant", + name: "New Lead (Instant)", + description: "Emit new event when a user submits their name and email to receive a free product/lead magnet. [See the documentation](https://developers.zylvie.com/webhooks/subscribe).", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getTriggerName() { + return triggers.LEAD; + }, + generateMeta(payload) { + const { data: resource } = payload; + return { + id: resource.transaction_id, + summary: `New Lead: ${resource.transaction_id}`, + ts: Date.parse(resource.created_at), + }; + }, + }, + sampleEmit, +}; diff --git a/components/zylvie/sources/new-lead-instant/test-event.mjs b/components/zylvie/sources/new-lead-instant/test-event.mjs new file mode 100644 index 0000000000000..f3d360a205233 --- /dev/null +++ b/components/zylvie/sources/new-lead-instant/test-event.mjs @@ -0,0 +1,25 @@ +export default { + "event": "lead", + "data": { + "transaction_id": "free_1711078342965279", + "created_at": "2025-03-23T03:12:35Z", + "buyer": { + "name": "Stavros Flatley", + "email": "stavros@greek.com", + "permission_to_send_emails": true + }, + "products": [ + { + "title": "The Ultimate Business Book", + "price": 0.0, + "quantity": 1 + } + ], + "custom_fields": [ + { + "name": "Tax identification number", + "value": "TIN-5252445767" + } + ] + } +}; diff --git a/components/zylvie/sources/new-subscription-instant/new-subscription-instant.mjs b/components/zylvie/sources/new-subscription-instant/new-subscription-instant.mjs new file mode 100644 index 0000000000000..da8eee17f7c28 --- /dev/null +++ b/components/zylvie/sources/new-subscription-instant/new-subscription-instant.mjs @@ -0,0 +1,28 @@ +import common from "../common/webhook.mjs"; +import triggers from "../common/triggers.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "zylvie-new-subscription-instant", + name: "New Subscription (Instant)", + description: "Emit new event when a user subscribes to a subscription product, whether free trial or otherwise. [See the documentation](https://developers.zylvie.com/webhooks/subscribe).", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getTriggerName() { + return triggers.SUBSCRIPTION; + }, + generateMeta(payload) { + const { data: resource } = payload; + return { + id: resource.subscription_id, + summary: `New Subscription: ${resource.subscription_id}`, + ts: Date.parse(resource.created_at), + }; + }, + }, + sampleEmit, +}; diff --git a/components/zylvie/sources/new-subscription-instant/test-event.mjs b/components/zylvie/sources/new-subscription-instant/test-event.mjs new file mode 100644 index 0000000000000..859fdfcc5f3eb --- /dev/null +++ b/components/zylvie/sources/new-subscription-instant/test-event.mjs @@ -0,0 +1,51 @@ +export default { + "event": "subscription", + "data": { + "subscription_id": "sub_1OoXxPF18w81dttLN6XyvuBl", + "created_at": "2025-02-27T21:12:59Z", + "cancel_at": null, + "canceled_at": null, + "trial_end": "2025-03-22T21:12:59Z", + "trial_start": "2025-02-27T21:12:59Z", + "currency": "usd", + "amount": 99.99, + "interval": "month", + "interval_count": 1, + "stripe_price_id": "price_1OkfZsF18w81dttL2OgdOtEj", + "status": "active", + "product": { + "title": "Life Coaching (Pro Tier)" + }, + "buyer": { + "name": "Stavros Flatley", + "email": "stavros@greek.com", + "permission_to_send_emails": true, + "phone": "+353850163326", + "line1": "349 Navan Road", + "line2": "Ashtown", + "postal_code": "D07 R2C3", + "city": "Dublin 7", + "state": "County Dublin", + "country": "IE", + "payment_method_type": "card", + "card_brand": "visa", + "card_last4": "0005" + }, + "coupon": { + "code": "20OFF", + "type": "percentage", + "amount": 20.0 + }, + "referrer": { + "email": "john.cena@zlappo.com" + }, + "custom_fields": [ + { + "name": "Tax identification number", + "value": "TIN-5252445767" + } + ], + "commission_earned": 41.99, + "commission_paid": false + } +}; diff --git a/components/zylvie/zylvie.app.mjs b/components/zylvie/zylvie.app.mjs index daa27a32c4663..a1895f07ef18c 100644 --- a/components/zylvie/zylvie.app.mjs +++ b/components/zylvie/zylvie.app.mjs @@ -1,11 +1,39 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "zylvie", - propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + return `${constants.BASE_URL}${path}`; + }, + getHeaders(headers) { + return { + "Authorization": `Bearer ${this.$auth.api_key}`, + ...headers, + }; + }, + _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + return axios($, { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }); + }, + post(args = {}) { + return this._makeRequest({ + method: "POST", + ...args, + }); + }, + delete(args = {}) { + return this._makeRequest({ + method: "DELETE", + ...args, + }); }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 273cd3c531502..637ce4f9b5a83 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10903,7 +10903,10 @@ importers: specifiers: {} components/zylvie: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.0 + dependencies: + '@pipedream/platform': 3.0.0 components/zyte_api: specifiers: {}