From c942588bb89f8b9b6f6b1c26d749e118287ed9d7 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Mon, 26 May 2025 15:32:46 -0400 Subject: [PATCH 1/3] new components --- components/jvzoo/jvzoo.app.mjs | 35 ++++++++++ components/jvzoo/package.json | 15 +++++ .../new-transaction-created.mjs | 67 +++++++++++++++++++ .../new-transaction-created/test-event.mjs | 14 ++++ 4 files changed, 131 insertions(+) create mode 100644 components/jvzoo/jvzoo.app.mjs create mode 100644 components/jvzoo/package.json create mode 100644 components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs create mode 100644 components/jvzoo/sources/new-transaction-created/test-event.mjs diff --git a/components/jvzoo/jvzoo.app.mjs b/components/jvzoo/jvzoo.app.mjs new file mode 100644 index 0000000000000..0330b0dae4e2c --- /dev/null +++ b/components/jvzoo/jvzoo.app.mjs @@ -0,0 +1,35 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "jvzoo", + propDefinitions: {}, + methods: { + _baseUrl() { + return "https://api.jvzoo.com/v2.0"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + auth: { + username: `${this.$auth.api_key}`, + password: "x", + }, + headers: { + "Content-Type": "application/json", + }, + ...opts, + }); + }, + getLatestTransactions({ + paykey, ...opts + }) { + return this._makeRequest({ + path: `/latest-transactions/${paykey}`, + ...opts, + }); + }, + }, +}; diff --git a/components/jvzoo/package.json b/components/jvzoo/package.json new file mode 100644 index 0000000000000..05eee4e5fdff2 --- /dev/null +++ b/components/jvzoo/package.json @@ -0,0 +1,15 @@ +{ + "name": "@pipedream/jvzoo", + "version": "0.0.1", + "description": "Pipedream Jvzoo Components", + "main": "jvzoo.app.mjs", + "keywords": [ + "pipedream", + "jvzoo" + ], + "homepage": "https://pipedream.com/apps/jvzoo", + "author": "Pipedream (https://pipedream.com)", + "publishConfig": { + "access": "public" + } +} diff --git a/components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs b/components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs new file mode 100644 index 0000000000000..c729ac47f2702 --- /dev/null +++ b/components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs @@ -0,0 +1,67 @@ +import jvzoo from "../../jvzoo.app.mjs"; +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "jvzoo-new-transaction-created", + name: "New Transaction Created", + description: "Emit new event when a new transaction is created. [See the documentation](https://api.jvzoo.com/docs/versions/v2.0.html#transactions-latest-transactions-get)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + jvzoo, + db: "$.service.db", + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getPaykey() { + return this.db.get("paykey"); + }, + _setPaykey(paykey) { + this.db.set("paykey", paykey); + }, + generateMeta(transaction) { + return { + id: transaction.id, + summary: `New transaction created: ${transaction.id}`, + ts: Date.parse(transaction.date), + }; + }, + async processEvent(max) { + const paykey = this._getPaykey(); + const params = paykey + ? { + paykey, + } + : {}; + const { results } = await this.jvzoo.getLatestTransactions({ + params, + }); + if (!results?.length) { + return; + } + const transactions = max + ? results.slice(max * -1) + : results; + for (const transaction of transactions) { + this.$emit(transaction, this.generateMeta(transaction)); + } + this._setPaykey(results[results.length - 1].id); + }, + }, + hooks: { + async deploy() { + await this.processEvent(25); + }, + }, + async run() { + await this.processEvent(); + }, + sampleEmit, +}; diff --git a/components/jvzoo/sources/new-transaction-created/test-event.mjs b/components/jvzoo/sources/new-transaction-created/test-event.mjs new file mode 100644 index 0000000000000..cb1ec68ff0789 --- /dev/null +++ b/components/jvzoo/sources/new-transaction-created/test-event.mjs @@ -0,0 +1,14 @@ +export default { + "transaction_id": "AP-1234567890ABCDEFG", + "date": "2016-12-02T12:50:30+00:00", + "product_name": "Example Product Name", + "product_id": 123456, + "status": "COMPLETED", + "price": "27.00", + "customer_email": "email@domain.com", + "ip": "1.1.1.1", + "first_name": "Joe", + "last_name": "Le Feuvre", + "affiliate_id": 1, + "affiliate_name": "John Doe" +} \ No newline at end of file From 1e69e73f732bb96ae8e5f8e46ce25efd9a88e7de Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Mon, 26 May 2025 15:34:06 -0400 Subject: [PATCH 2/3] pnpm-lock.yaml --- pnpm-lock.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04842669c8cd6..7c2478b50f22a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6849,6 +6849,8 @@ importers: specifier: ^1.5.1 version: 1.6.6 + components/jvzoo: {} + components/jw_player: dependencies: '@pipedream/platform': From 611e8d4afff95a62ff7619edc23dd3049e5abb16 Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Mon, 26 May 2025 15:52:10 -0400 Subject: [PATCH 3/3] updates --- .../new-transaction-created/new-transaction-created.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs b/components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs index c729ac47f2702..4bd0751c08636 100644 --- a/components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs +++ b/components/jvzoo/sources/new-transaction-created/new-transaction-created.mjs @@ -28,8 +28,8 @@ export default { }, generateMeta(transaction) { return { - id: transaction.id, - summary: `New transaction created: ${transaction.id}`, + id: transaction.transaction_id, + summary: `New transaction created: ${transaction.transaction_id}`, ts: Date.parse(transaction.date), }; }, @@ -52,7 +52,7 @@ export default { for (const transaction of transactions) { this.$emit(transaction, this.generateMeta(transaction)); } - this._setPaykey(results[results.length - 1].id); + this._setPaykey(results[results.length - 1].transaction_id); }, }, hooks: {