diff --git a/components/klaviyo/actions/add-member-to-list/add-member-to-list.mjs b/components/klaviyo/actions/add-member-to-list/add-member-to-list.mjs index 62e4e47a01909..d96b79b182fef 100644 --- a/components/klaviyo/actions/add-member-to-list/add-member-to-list.mjs +++ b/components/klaviyo/actions/add-member-to-list/add-member-to-list.mjs @@ -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, @@ -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; }, }; diff --git a/components/klaviyo/actions/create-new-list/create-new-list.mjs b/components/klaviyo/actions/create-new-list/create-new-list.mjs index 6d9d7563b5d64..82324f53467c6 100644 --- a/components/klaviyo/actions/create-new-list/create-new-list.mjs +++ b/components/klaviyo/actions/create-new-list/create-new-list.mjs @@ -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, diff --git a/components/klaviyo/actions/get-lists/get-lists.mjs b/components/klaviyo/actions/get-lists/get-lists.mjs index d16a68825e086..b856da9df4213 100644 --- a/components/klaviyo/actions/get-lists/get-lists.mjs +++ b/components/klaviyo/actions/get-lists/get-lists.mjs @@ -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; }, }; diff --git a/components/klaviyo/klaviyo.app.mjs b/components/klaviyo/klaviyo.app.mjs index 044b2d8e0dd7d..d8c8f2a982458 100644 --- a/components/klaviyo/klaviyo.app.mjs +++ b/components/klaviyo/klaviyo.app.mjs @@ -10,23 +10,34 @@ 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 { @@ -34,7 +45,7 @@ export default { data, links, }, } = await this.listProfiles({ - "page[cursor]": prevContext.nextCursor, + pageCursor: prevContext?.nextCursor, }); return { @@ -45,7 +56,7 @@ export default { value, })), context: { - nextCursor: links.next, + nextCursor: this.getCursorFromNextLink(links?.next), }, }; }, @@ -53,7 +64,7 @@ export default { listName: { type: "string", label: "List Name", - description: "The name of the new list.", + description: "The name of the new list", }, }, methods: { @@ -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 @@ -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); + }, }, }; diff --git a/components/klaviyo/package.json b/components/klaviyo/package.json index 81e4cc8c1721e..33b90351097a8 100644 --- a/components/klaviyo/package.json +++ b/components/klaviyo/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/klaviyo", - "version": "0.1.1", + "version": "0.1.2", "description": "Pipedream Klaviyo Components", "main": "klaviyo.app.mjs", "keywords": [ @@ -14,6 +14,6 @@ }, "dependencies": { "@babel/core": "^7.0.0-0", - "klaviyo-api": "^11.0.0" + "klaviyo-api": "^18.0.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 80e973774d94e..a07b465550e0f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2112,8 +2112,7 @@ importers: specifier: ^1.6.0 version: 1.6.6 - components/catch_all_verifier: - specifiers: {} + components/catch_all_verifier: {} components/cats: dependencies: @@ -6940,8 +6939,8 @@ importers: specifier: ^7.0.0-0 version: 7.26.0 klaviyo-api: - specifier: ^11.0.0 - version: 11.0.0 + specifier: ^18.0.0 + version: 18.0.0 components/klaxoon: dependencies: @@ -9920,8 +9919,7 @@ importers: components/planning_center: {} - components/planpoint: - specifiers: {} + components/planpoint: {} components/planso_forms: {} @@ -15315,14 +15313,6 @@ importers: specifier: ^6.0.0 version: 6.2.0 - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/cjs: {} - - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/esm: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/cjs: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/esm: {} - packages/browsers: dependencies: '@sparticuz/chromium': @@ -23185,9 +23175,6 @@ packages: resolution: {integrity: sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} - exponential-backoff@3.1.1: - resolution: {integrity: sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==} - express-rate-limit@7.5.0: resolution: {integrity: sha512-eB5zbQh5h+VenMPM3fh+nw1YExi5nMr6HUCR62ELSP11huvxm/Uir1H1QEyTkk5QX6A58pX6NmaTMceKZ0Eodg==} engines: {node: '>= 16'} @@ -25211,8 +25198,8 @@ packages: resolution: {integrity: sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==} engines: {node: '>=0.10.0'} - klaviyo-api@11.0.0: - resolution: {integrity: sha512-lzWNSZO962HECjCWKAylCwdvyClpilUBPJAW7J1Zk9H1qvbVvg/UaLow7iOORw6EzXsPa8YL8xNE4OTKGn1tjQ==} + klaviyo-api@18.0.0: + resolution: {integrity: sha512-EtiqQwKVi7LzmrNXfTWelTIG4SYPnrILzGNOa9PUAuLFM5LhRGZkfR4tzfFI8FJLTwOcBdpvLRkNZdkaJAcRLg==} klaw@3.0.0: resolution: {integrity: sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==} @@ -40962,8 +40949,6 @@ snapshots: jest-message-util: 29.7.0 jest-util: 29.7.0 - exponential-backoff@3.1.1: {} - express-rate-limit@7.5.0(express@5.1.0): dependencies: express: 5.1.0 @@ -43790,10 +43775,9 @@ snapshots: kind-of@6.0.3: {} - klaviyo-api@11.0.0: + klaviyo-api@18.0.0: dependencies: axios: 1.8.4(debug@3.2.7) - exponential-backoff: 3.1.1 form-data: 4.0.2 transitivePeerDependencies: - debug