diff --git a/components/waitlist/package.json b/components/waitlist/package.json index cc4eb4d9fd20f..414adf3421baa 100644 --- a/components/waitlist/package.json +++ b/components/waitlist/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/waitlist", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Waitlist Components", "main": "waitlist.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.0" } -} \ No newline at end of file +} + diff --git a/components/waitlist/sources/common/base.mjs b/components/waitlist/sources/common/base.mjs new file mode 100644 index 0000000000000..bfd05af0e8ab8 --- /dev/null +++ b/components/waitlist/sources/common/base.mjs @@ -0,0 +1,62 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import waitlist from "../../waitlist.app.mjs"; + +export default { + props: { + waitlist, + db: "$.service.db", + timer: { + label: "Polling interval", + description: "Pipedream will poll the Waitlist API on this schedule", + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + }, + methods: { + _getLastValue() { + return this.db.get("lastValue") || 0; + }, + _setLastValue(lastValue) { + this.db.set("lastValue", lastValue); + }, + getProps() { + return {}; + }, + async startEvent(maxResults = 0) { + const lastValue = this._getLastValue(); + const fn = this.getFunction(); + const field = this.getField(); + + const items = await fn({ + ...this.getProps(), + }); + + const filteredResponse = items.filter((item) => this.getFilter(item[field], lastValue)); + + if (filteredResponse.length) { + if (maxResults && filteredResponse.length > maxResults) { + filteredResponse.length = maxResults; + } + this._setLastValue(filteredResponse[filteredResponse.length - 1][field]); + } + + for (const item of filteredResponse) { + this.$emit( item, { + id: item.id || item.uuid, + summary: this.getSummary(item), + ts: Date.parse(item.created_at), + }); + } + }, + }, + hooks: { + async deploy() { + await this.startEvent(25); + }, + }, + async run() { + await this.startEvent(); + }, +}; diff --git a/components/waitlist/sources/new-list/new-list.mjs b/components/waitlist/sources/new-list/new-list.mjs new file mode 100644 index 0000000000000..c2a32f635ee80 --- /dev/null +++ b/components/waitlist/sources/new-list/new-list.mjs @@ -0,0 +1,28 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "waitlist-new-list", + name: "New List Created", + description: "Emit new event each time a waitlist is created. [See the documentation](https://getwaitlist.com/docs/api-docs/waitlist)", + version: "0.0.1", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getFunction() { + return this.waitlist.listWaitlists; + }, + getSummary(item) { + return `New waitlist with Id: ${item.id}`; + }, + getField() { + return "id"; + }, + getFilter(item, lastValue) { + return item > lastValue; + }, + }, + sampleEmit, +}; diff --git a/components/waitlist/sources/new-list/test-event.mjs b/components/waitlist/sources/new-list/test-event.mjs new file mode 100644 index 0000000000000..c82b16c2b75e1 --- /dev/null +++ b/components/waitlist/sources/new-list/test-event.mjs @@ -0,0 +1,40 @@ +export default { + "id": 213, + "configuration_style_json": { + "social_links": { + "facebook": "", + "instagram": "", + "linkedin": "", + "pinterest": "", + "twitter": "https://twitter.com/WaitlistAPI" + }, + "status_description": "Thanks for signing up!", + "status_font_color": "#000000", + "status_main_color": "#222222", + "widget_background_color": "#4937E7", + "widget_button_color": "#000000", + "widget_font_color": "#000000" + }, + "logo": null, + "spots_to_move_upon_referral": 3, + "uses_firstname_lastname": false, + "uses_leaderboard": true, + "uses_signup_verification": false, + "waitlist_name": "Title", + "waitlist_url_location": "https://getwaitlist.com", + "statistics": { + 'total_signups': 2200, + 'current_signups': 2200, + }, + "title": null, + "success_title": null, + "required_contact_detail": "EMAIL", + "widget_shows_social_links": false, + "signup_button_title": "Sign Up", + "hide_counts": false, + "leaderboard_length": 5, + "remove_widget_headers": false, + "questions": [{'question_value': "What is your favorite animal?", 'optional': false, "answer_value": ["Cat", "Dog", "Duck", "Other"]}], + "twitter_message": "", + "organization_uuid_fk": "30120c24-0ddc-4f35-9bc6-f5e3c7b09257", +} diff --git a/components/waitlist/sources/new-subscriber/new-subscriber.mjs b/components/waitlist/sources/new-subscriber/new-subscriber.mjs new file mode 100644 index 0000000000000..43286931a82ae --- /dev/null +++ b/components/waitlist/sources/new-subscriber/new-subscriber.mjs @@ -0,0 +1,44 @@ +import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + ...common, + key: "waitlist-new-subscriber", + name: "New Subscriber Added", + description: "Emit new event each time a subscriber is added. [See the documentation](https://getwaitlist.com/docs/api-docs/waitlist)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + ...common.props, + waitlistId: { + propDefinition: [ + common.props.waitlist, + "waitlistId", + ], + }, + }, + methods: { + ...common.methods, + getFunction() { + return this.waitlist.listSignups; + }, + getProps() { + return { + waitlistId: this.waitlistId, + }; + }, + getSummary(item) { + return `New signup with Id: ${item.uuid}`; + }, + getField() { + return "created_at"; + }, + getFilter(item, lastValue) { + let parseDate = item.split("_"); + const itemDate = `${parseDate[0]}T${parseDate[1].replace(/-/g, ":")}`; + return Date.parse(itemDate) > Date.parse(lastValue); + }, + }, + sampleEmit, +}; diff --git a/components/waitlist/sources/new-subscriber/test-event.mjs b/components/waitlist/sources/new-subscriber/test-event.mjs new file mode 100644 index 0000000000000..8892bfbe7006f --- /dev/null +++ b/components/waitlist/sources/new-subscriber/test-event.mjs @@ -0,0 +1,19 @@ +export default { + "amount_referred": 0, + "created_at": "2022-04-10_18-34-28", + "email": "maya@getwaitlist.com", + "priority": 4985, + "referral_link": "https://getwaitlist.com?ref_id=4F0BTBMAB", + "referral_token": "4F0BTBMAB", + "referred_by_signup_token": null, + "removed_date": null, + "removed_priority": null, + "uuid": "c60ff9f2-1a58-4551-87ea-414991184fba", + "verified": false, + "answers": [{'question_value': "What is your favorite animal?", 'optional': false, "answer_value": "Cat"}], + "phone": null, + "first_name": "Maya", + "last_name": "Kyler", + "metadata": {}, + "waitlist_id": 1234 +} diff --git a/components/waitlist/waitlist.app.mjs b/components/waitlist/waitlist.app.mjs index 8a1205ffc23b8..238191563350c 100644 --- a/components/waitlist/waitlist.app.mjs +++ b/components/waitlist/waitlist.app.mjs @@ -1,11 +1,57 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "waitlist", - propDefinitions: {}, + propDefinitions: { + waitlistId: { + type: "string", + label: "Waitlist Id", + description: "The ID of your waitlist.", + async options() { + const waitlists = await this.listWaitlists(); + + return waitlists.map(({ + id: value, waitlist_name: label, + }) => ({ + label, + value, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.getwaitlist.com/api/v1"; + }, + _headers() { + return { + "Content-Type": "application/json", + "api-key": `${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + headers: this._headers(), + ...opts, + }); + }, + listWaitlists(opts = {}) { + return this._makeRequest({ + path: "/waitlist", + ...opts, + }); + }, + listSignups({ + waitlistId, ...opts + }) { + return this._makeRequest({ + path: `/signup/waitlist/${waitlistId}`, + ...opts, + }); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f817390c7667b..2d49ecf412a35 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10034,7 +10034,10 @@ importers: specifiers: {} components/waitlist: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.0 + dependencies: + '@pipedream/platform': 3.0.0 components/waitwhile: specifiers: