Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import klaviyo from "../../klaviyo.app.mjs";
export default {
key: "klaviyo-add-member-to-list",
name: "Add Member To List",
description: "Add member to a specific list. [See the docs here](https://developers.klaviyo.com/en/v1-2/reference/add-members)",
version: "1.0.0",
description: "Add member to a specific list. [See the documentation](https://developers.klaviyo.com/en/reference/add_profiles_to_list)",
version: "1.0.1",
type: "action",
props: {
klaviyo,
Expand All @@ -31,7 +31,7 @@ export default {
})),
});

$.export("$summary", `${this.profileId} successfully added to "${this.list.label}"!`);
$.export("$summary", `Member(s) successfully added to "${this.list.label}"!`);
return response.data;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import klaviyo from "../../klaviyo.app.mjs";
export default {
key: "klaviyo-create-new-list",
name: "Create New List",
description: "Creates a new list in an account. [See the docs here](https://developers.klaviyo.com/en/v1-2/reference/create-list)",
version: "0.0.2",
description: "Creates a new list in an account. [See the documentation](https://developers.klaviyo.com/en/reference/create_list)",
version: "0.0.3",
type: "action",
props: {
klaviyo,
Expand Down
56 changes: 51 additions & 5 deletions components/klaviyo/actions/get-lists/get-lists.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,62 @@ import klaviyo from "../../klaviyo.app.mjs";
export default {
key: "klaviyo-get-lists",
name: "Get Lists",
description: "Get a listing of all of the lists in an account. [See the docs here](https://developers.klaviyo.com/en/v1-2/reference/get-lists)",
version: "0.0.3",
description: "Get a listing of all of the lists in an account. [See the documentation](https://developers.klaviyo.com/en/reference/get_lists)",
version: "0.0.4",
type: "action",
props: {
klaviyo,
sort: {
type: "string",
label: "Sort",
description: "The field to sort by",
options: [
"created",
"id",
"name",
"updated",
],
default: "created",
optional: true,
},
sortDirection: {
type: "string",
label: "Sort Direction",
description: "Whether to sort ascending or descending. Default: `descending`",
options: [
"asc",
"desc",
],
default: "desc",
optional: true,
},
maxResults: {
type: "integer",
label: "Max Results",
description: "The maximum number of results to return",
default: 100,
optional: true,
},
},
async run({ $ }) {
const response = await this.klaviyo.getLists();
const lists = this.klaviyo.paginate({
fn: this.klaviyo.getLists,
opts: {
sort: `${this.sortDirection === "desc"
? "-"
: ""}${this.sort}`,
},
max: this.maxResults,
});

$.export("$summary", "List Successfully fetched!");
return response.body;
const results = [];
for await (const list of lists) {
results.push(list);
}

$.export("$summary", `Successfully fetched ${results.length} list${results.length === 1
? ""
: "s"}`);
return results;
},
};
69 changes: 53 additions & 16 deletions components/klaviyo/klaviyo.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,42 @@ export default {
list: {
type: "string",
label: "List",
description: "The list which will be affected.",
description: "The list which will be affected",
withLabel: true,
async options() {
const { body: { data } } = await this.getLists();
async options({ prevContext }) {
const {
body: {
data, links,
},
} = await this.getLists({
pageCursor: prevContext?.nextCursor,
});

return data.map(({
id: value, attributes: { name: label },
}) => ({
label,
value,
}));
return {
options: data.map(({
id: value, attributes: { name: label },
}) => ({
label,
value,
})),
context: {
nextCursor: this.getCursorFromNextLink(links?.next),
},
};
},
},
profileIds: {
type: "string[]",
label: "Profile Ids",
description: "An array with profile Ids.",
label: "Profile IDs",
description: "An array of profile IDs",
withLabel: true,
async options({ prevContext }) {
const {
body: {
data, links,
},
} = await this.listProfiles({
"page[cursor]": prevContext.nextCursor,
pageCursor: prevContext?.nextCursor,
});

return {
Expand All @@ -45,15 +56,15 @@ export default {
value,
})),
context: {
nextCursor: links.next,
nextCursor: this.getCursorFromNextLink(links?.next),
},
};
},
},
listName: {
type: "string",
label: "List Name",
description: "The name of the new list.",
description: "The name of the new list",
},
},
methods: {
Expand All @@ -64,9 +75,9 @@ export default {
this.sdk();
return Lists.createList(data);
},
getLists() {
getLists(opts = {}) {
this.sdk();
return Lists.getLists();
return Lists.getLists(opts);
},
subscribeProfiles({
listId, ...opts
Expand All @@ -78,5 +89,31 @@ export default {
this.sdk();
return Profiles.getProfiles(opts);
},
getCursorFromNextLink(url) {
if (!url) {
return;
}
return (new URL(url)).searchParams.get("page[cursor]");
},
async *paginate({
fn, opts = {}, max,
}) {
let hasMore, count = 0;
do {
const {
body: {
data, links,
},
} = await fn(opts);
for (const item of data) {
yield item;
if (max && ++count >= max) {
return;
}
}
opts.pageCursor = this.getCursorFromNextLink(links?.next);
hasMore = links?.next;
} while (hasMore);
},
},
};
4 changes: 2 additions & 2 deletions components/klaviyo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/klaviyo",
"version": "0.1.1",
"version": "0.1.2",
"description": "Pipedream Klaviyo Components",
"main": "klaviyo.app.mjs",
"keywords": [
Expand All @@ -14,6 +14,6 @@
},
"dependencies": {
"@babel/core": "^7.0.0-0",
"klaviyo-api": "^11.0.0"
"klaviyo-api": "^18.0.0"
}
}
30 changes: 7 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading