Skip to content

Commit

Permalink
waitlist init
Browse files Browse the repository at this point in the history
  • Loading branch information
luancazarine committed Jul 15, 2024
1 parent 57d1f2f commit 2872ef1
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/waitlist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}
70 changes: 70 additions & 0 deletions components/waitlist/sources/new-list/new-list.mjs
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";

Check failure on line 2 in components/waitlist/sources/new-list/new-list.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

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 components/waitlist/sources/new-subscriber/new-subscriber.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { axios } from "@pipedream/platform";

Check failure on line 1 in components/waitlist/sources/new-subscriber/new-subscriber.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used
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(),
});
});
}
},
};
74 changes: 69 additions & 5 deletions components/waitlist/waitlist.app.mjs
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}`,
});
},
},
};
};

0 comments on commit 2872ef1

Please sign in to comment.