-
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.
- Loading branch information
1 parent
57d1f2f
commit 2872ef1
Showing
4 changed files
with
224 additions
and
6 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 |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
"publishConfig": { | ||
"access": "public" | ||
} | ||
} | ||
} |
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,70 @@ | ||
import waitlist from "../../waitlist.app.mjs"; | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
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}}", | ||
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); | ||
}, | ||
async getLists() { | ||
return this.waitlist._makeRequest({ | ||
path: "/waitlist", | ||
}); | ||
}, | ||
}, | ||
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 | ||
}, | ||
async deactivate() { | ||
// Hook to handle deactivation logic if necessary | ||
}, | ||
}, | ||
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); | ||
} | ||
}, | ||
}; |
84 changes: 84 additions & 0 deletions
84
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import waitlist from "../../waitlist.app.mjs"; | ||
|
||
export default { | ||
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}}", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
waitlist, | ||
db: "$.service.db", | ||
listId: { | ||
propDefinition: [ | ||
waitlist, | ||
"listId", | ||
], | ||
}, | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: 60, | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
_getLastSubscriberId() { | ||
return this.db.get("lastSubscriberId"); | ||
}, | ||
_setLastSubscriberId(lastSubscriberId) { | ||
this.db.set("lastSubscriberId", lastSubscriberId); | ||
}, | ||
async _getSubscribers() { | ||
const listDetails = await this.waitlist.getListDetails({ | ||
listId: this.listId, | ||
}); | ||
return listDetails.signups || []; | ||
}, | ||
}, | ||
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(), | ||
}); | ||
}); | ||
} | ||
}, | ||
async activate() { | ||
console.log("Source activated"); | ||
}, | ||
async deactivate() { | ||
console.log("Source deactivated"); | ||
}, | ||
}, | ||
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(), | ||
}); | ||
}); | ||
} | ||
}, | ||
}; |
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,11 +1,75 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "waitlist", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
listId: { | ||
type: "string", | ||
label: "List ID", | ||
description: "The ID of the waitlist", | ||
}, | ||
subscriberId: { | ||
type: "string", | ||
label: "Subscriber ID", | ||
description: "The ID of the subscriber", | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.getwaitlist.com/api/v1"; | ||
}, | ||
async _makeRequest(opts = {}) { | ||
const { | ||
$ = this, | ||
method = "GET", | ||
path = "/", | ||
headers, | ||
...otherOpts | ||
} = opts; | ||
return axios($, { | ||
...otherOpts, | ||
method, | ||
url: this._baseUrl() + path, | ||
headers: { | ||
...headers, | ||
Authorization: `Bearer ${this.$auth.oauth_access_token}`, | ||
}, | ||
}); | ||
}, | ||
async getListDetails({ | ||
listId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/waitlist/${listId}`, | ||
...opts, | ||
}); | ||
}, | ||
async getSubscriberDetails({ | ||
subscriberId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
path: `/signup/${subscriberId}`, | ||
...opts, | ||
}); | ||
}, | ||
async emitNewListEvent(listId) { | ||
const listDetails = await this.getListDetails({ | ||
listId, | ||
}); | ||
this.$emit(listDetails, { | ||
name: "new_list", | ||
summary: `New list created with ID: ${listId}`, | ||
}); | ||
}, | ||
async emitNewSubscriberEvent(subscriberId) { | ||
const subscriberDetails = await this.getSubscriberDetails({ | ||
subscriberId, | ||
}); | ||
this.$emit(subscriberDetails, { | ||
name: "new_subscriber", | ||
summary: `New subscriber added with ID: ${subscriberId}`, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |