-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
195 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.0.0" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,28 @@ | ||
import waitlist from "../../waitlist.app.mjs"; | ||
import { axios } from "@pipedream/platform"; | ||
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 list is created. [See the documentation](https://getwaitlist.com/docs/api-docs/waitlist)", | ||
version: "0.0.{{ts}}", | ||
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", | ||
props: { | ||
waitlist, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: 60, | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_getLastListId() { | ||
return this.db.get("lastListId"); | ||
}, | ||
_setLastListId(listId) { | ||
this.db.set("lastListId", listId); | ||
...common.methods, | ||
getFunction() { | ||
return this.waitlist.listWaitlists; | ||
}, | ||
async getLists() { | ||
return this.waitlist._makeRequest({ | ||
path: "/waitlist", | ||
}); | ||
getSummary(item) { | ||
return `New waitlist with Id: ${item.id}`; | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
const lists = await this.getLists(); | ||
if (lists.length > 0) { | ||
this._setLastListId(lists[0].id); | ||
for (const list of lists.slice(0, 50)) { | ||
this.$emit(list, { | ||
id: list.id, | ||
summary: `New list created: ${list.waitlist_name}`, | ||
ts: Date.parse(list.created_at), | ||
}); | ||
} | ||
} | ||
}, | ||
async activate() { | ||
// Hook to handle activation logic if necessary | ||
getField() { | ||
return "id"; | ||
}, | ||
async deactivate() { | ||
// Hook to handle deactivation logic if necessary | ||
getFilter(item, lastValue) { | ||
return item > lastValue; | ||
}, | ||
}, | ||
async run() { | ||
const lastListId = this._getLastListId(); | ||
const lists = await this.getLists(); | ||
for (const list of lists) { | ||
if (list.id === lastListId) break; | ||
this.$emit(list, { | ||
id: list.id, | ||
summary: `New list created: ${list.waitlist_name}`, | ||
ts: Date.parse(list.created_at), | ||
}); | ||
} | ||
if (lists.length > 0) { | ||
this._setLastListId(lists[0].id); | ||
} | ||
}, | ||
sampleEmit, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
} |
90 changes: 25 additions & 65 deletions
90
components/waitlist/sources/new-subscriber/new-subscriber.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,44 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import waitlist from "../../waitlist.app.mjs"; | ||
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 a new event each time a subscriber is added. [See the documentation](https://getwaitlist.com/docs/api-docs/waitlist)", | ||
version: "0.0.{{ts}}", | ||
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: { | ||
waitlist, | ||
db: "$.service.db", | ||
listId: { | ||
...common.props, | ||
waitlistId: { | ||
propDefinition: [ | ||
waitlist, | ||
"listId", | ||
common.props.waitlist, | ||
"waitlistId", | ||
], | ||
}, | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: 60, | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_getLastSubscriberId() { | ||
return this.db.get("lastSubscriberId"); | ||
}, | ||
_setLastSubscriberId(lastSubscriberId) { | ||
this.db.set("lastSubscriberId", lastSubscriberId); | ||
...common.methods, | ||
getFunction() { | ||
return this.waitlist.listSignups; | ||
}, | ||
async _getSubscribers() { | ||
const listDetails = await this.waitlist.getListDetails({ | ||
listId: this.listId, | ||
}); | ||
return listDetails.signups || []; | ||
getProps() { | ||
return { | ||
waitlistId: this.waitlistId, | ||
}; | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
const subscribers = await this._getSubscribers(); | ||
const lastSubscriber = subscribers[0]; | ||
if (lastSubscriber) { | ||
this._setLastSubscriberId(lastSubscriber.uuid); | ||
subscribers.slice(0, 50).forEach((subscriber) => { | ||
this.$emit(subscriber, { | ||
id: subscriber.uuid, | ||
summary: `New subscriber added: ${subscriber.email}`, | ||
ts: new Date(subscriber.created_at).getTime(), | ||
}); | ||
}); | ||
} | ||
getSummary(item) { | ||
return `New signup with Id: ${item.uuid}`; | ||
}, | ||
async activate() { | ||
console.log("Source activated"); | ||
getField() { | ||
return "created_at"; | ||
}, | ||
async deactivate() { | ||
console.log("Source deactivated"); | ||
getFilter(item, lastValue) { | ||
let parseDate = item.split("_"); | ||
const itemDate = `${parseDate[0]}T${parseDate[1].replace(/-/g, ":")}`; | ||
return Date.parse(itemDate) > Date.parse(lastValue); | ||
}, | ||
}, | ||
async run() { | ||
const lastSubscriberId = this._getLastSubscriberId(); | ||
const subscribers = await this._getSubscribers(); | ||
const newSubscribers = []; | ||
|
||
for (const subscriber of subscribers) { | ||
if (subscriber.uuid === lastSubscriberId) break; | ||
newSubscribers.push(subscriber); | ||
} | ||
|
||
if (newSubscribers.length > 0) { | ||
this._setLastSubscriberId(newSubscribers[0].uuid); | ||
newSubscribers.reverse().forEach((subscriber) => { | ||
this.$emit(subscriber, { | ||
id: subscriber.uuid, | ||
summary: `New subscriber added: ${subscriber.email}`, | ||
ts: new Date(subscriber.created_at).getTime(), | ||
}); | ||
}); | ||
} | ||
}, | ||
sampleEmit, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default { | ||
"amount_referred": 0, | ||
"created_at": "2022-04-10_18-34-28", | ||
"email": "[email protected]", | ||
"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 | ||
} |
Oops, something went wrong.