From 46238a03dbe5c73cf02eeafab85e8b72d76332a3 Mon Sep 17 00:00:00 2001 From: Jorge Cortes Date: Thu, 11 Sep 2025 11:45:59 -0500 Subject: [PATCH] [FIX] Google My Business pagination --- .../actions/create-post/create-post.ts | 2 +- .../create-update-reply-to-review.ts | 2 +- .../get-reviews-multiple-locations.ts | 2 +- .../get-specific-review.ts | 2 +- .../list-all-reviews/list-all-reviews.ts | 2 +- .../actions/list-posts/list-posts.ts | 2 +- .../app/google_my_business.app.ts | 116 ++++++++++++------ components/google_my_business/package.json | 2 +- .../new-post-created/new-post-created.ts | 2 +- .../new-review-created-multiple-locations.ts | 2 +- .../new-review-created/new-review-created.ts | 2 +- 11 files changed, 90 insertions(+), 46 deletions(-) diff --git a/components/google_my_business/actions/create-post/create-post.ts b/components/google_my_business/actions/create-post/create-post.ts index 1fe460b264379..129596e146d39 100644 --- a/components/google_my_business/actions/create-post/create-post.ts +++ b/components/google_my_business/actions/create-post/create-post.ts @@ -12,7 +12,7 @@ export default defineAction({ key: "google_my_business-create-post", name: "Create Post", description: `Create a new local post associated with a location. [See the documentation](${DOCS_LINK})`, - version: "0.0.3", + version: "0.0.4", type: "action", props: { app, diff --git a/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts b/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts index cc7b7a4289988..5f0f309b8f6c9 100644 --- a/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts +++ b/components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts @@ -8,7 +8,7 @@ export default defineAction({ key: "google_my_business-create-update-reply-to-review", name: "Create or Update Reply to Review", description: `Create or update a reply to the specified review. [See the documentation](${DOCS_LINK})`, - version: "0.0.2", + version: "0.0.3", type: "action", props: { app, diff --git a/components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts b/components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts index 0b388f4aabdf3..5d688dd2834ec 100644 --- a/components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts +++ b/components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts @@ -8,7 +8,7 @@ export default defineAction({ key: "google_my_business-get-reviews-multiple-locations", name: "Get Reviews from Multiple Locations", description: `Get reviews from multiple locations at once. [See the documentation](${DOCS_LINK})`, - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/google_my_business/actions/get-specific-review/get-specific-review.ts b/components/google_my_business/actions/get-specific-review/get-specific-review.ts index 62e9c7f8a06eb..2b976f155cba9 100644 --- a/components/google_my_business/actions/get-specific-review/get-specific-review.ts +++ b/components/google_my_business/actions/get-specific-review/get-specific-review.ts @@ -8,7 +8,7 @@ export default defineAction({ key: "google_my_business-get-specific-review", name: "Get a Specific Review", description: `Return a specific review by name. [See the documentation](${DOCS_LINK})`, - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/google_my_business/actions/list-all-reviews/list-all-reviews.ts b/components/google_my_business/actions/list-all-reviews/list-all-reviews.ts index 19133efb9f6e2..0de038f37dc39 100644 --- a/components/google_my_business/actions/list-all-reviews/list-all-reviews.ts +++ b/components/google_my_business/actions/list-all-reviews/list-all-reviews.ts @@ -8,7 +8,7 @@ export default defineAction({ key: "google_my_business-list-all-reviews", name: "List All Reviews", description: `List all reviews of a location to audit reviews in bulk. [See the documentation](${DOCS_LINK})`, - version: "0.0.1", + version: "0.0.2", type: "action", props: { app, diff --git a/components/google_my_business/actions/list-posts/list-posts.ts b/components/google_my_business/actions/list-posts/list-posts.ts index 4515931cceb32..a1d98f5716006 100644 --- a/components/google_my_business/actions/list-posts/list-posts.ts +++ b/components/google_my_business/actions/list-posts/list-posts.ts @@ -9,7 +9,7 @@ export default defineAction({ key: "google_my_business-list-posts", name: "List Posts", description: `List local posts associated with a location. [See the documentation](${DOCS_LINK})`, - version: "0.0.2", + version: "0.0.3", type: "action", props: { app, diff --git a/components/google_my_business/app/google_my_business.app.ts b/components/google_my_business/app/google_my_business.app.ts index 2b39fb87d3390..dff6219bf5ccc 100644 --- a/components/google_my_business/app/google_my_business.app.ts +++ b/components/google_my_business/app/google_my_business.app.ts @@ -2,7 +2,7 @@ import { defineApp } from "@pipedream/types"; import { axios } from "@pipedream/platform"; import { CreatePostParams, - HttpRequestParams, ListPostsParams, ListReviewsParams, PaginatedRequestParams, UpdateReplyParams, GetReviewParams, BatchGetReviewsParams, + HttpRequestParams, ListPostsParams, PaginatedRequestParams, UpdateReplyParams, GetReviewParams, BatchGetReviewsParams, } from "../common/requestParams"; import { Account, LocalPost, Location, Review, @@ -16,14 +16,31 @@ export default defineApp({ type: "string", label: "Account Name", description: "Select an **Account** or provide a custom *Account Name*.", - async options() { - const accounts: Account[] = await this.listAccounts(); - return accounts.map(({ + async options({ prevContext: { pageToken } }: { + prevContext: { pageToken: string | null; }; + }) { + if (pageToken === null) { + return []; + } + const response = await this.listAccounts({ + params: { + pageSize: 50, + pageToken, + }, + }); + const accounts: Account[] = response?.accounts ?? []; + const options = accounts?.map?.(({ name, accountName, type, - }) => ({ + }: Account) => ({ label: `${accountName ?? name} (${type})`, value: this.getCleanName(name) as string, - })); + })) ?? []; + return { + options, + context: { + pageToken: response?.nextPageToken ?? null, + }, + }; }, }, location: { @@ -32,24 +49,41 @@ export default defineApp({ description: "The location whose local posts will be listed. [See the documentation](https://developers.google.com/my-business/content/location-data#filter_results_when_you_list_locations) on how to filter locations.", useQuery: true, async options({ - account, query, - }: Record) { + account, query, prevContext: { pageToken }, + }: Record & { + prevContext: { pageToken: string | null; }; + }) { + if (pageToken === null) { + return []; + } const filter = query ? (query.match(/[=:]/) ? query : `title="${query}"`).replace(/ /g, "+").replace(/"/g, "%22") : undefined; - const locations: Location[] = await this.listLocations({ + const response = await this.listLocations({ account, - filter, + params: { + pageSize: 50, + pageToken, + filter, + readMask: "name,title", + }, }); - return locations?.map?.(({ + const locations: Location[] = response?.locations ?? []; + const options = locations?.map?.(({ name, title, }: Location) => ({ label: title, value: this.getCleanName(name) as string, })) ?? []; + return { + options, + context: { + pageToken: response?.nextPageToken ?? null, + }, + }; }, }, review: { @@ -57,18 +91,34 @@ export default defineApp({ label: "Review", description: "Select a **Review** or provide a custom *Review Name*.", async options({ - account, location, - }: Record) { - const reviews: Review[] = await this.listReviews({ + account, location, prevContext: { pageToken }, + }: Record & { + prevContext: { pageToken: string | null; }; + }) { + if (pageToken === null) { + return []; + } + const response = await this.listReviews({ account, location, + params: { + pageSize: 50, + pageToken, + }, }); - return reviews?.map?.(({ + const reviews: Review[] = response?.reviews ?? []; + const options = reviews?.map?.(({ name, title, - }: Location) => ({ + }: Review) => ({ label: title, value: this.getCleanName(name) as string, - })); + })) ?? []; + return { + options, + context: { + pageToken: response?.nextPageToken ?? null, + }, + }; }, }, }, @@ -123,33 +173,27 @@ export default defineApp({ return result; }, - async listAccounts(): Promise { - const response = await this._httpRequest({ + listAccounts(args: object = {}): Promise { + return this._httpRequest({ url: "https://mybusinessaccountmanagement.googleapis.com/v1/accounts", + ...args, }); - return response?.accounts ?? []; }, - async listLocations({ - account, filter, - }: Record): Promise { - const response = await this._httpRequest({ + listLocations({ + account, ...args + }: Record & { args: object }): Promise { + return this._httpRequest({ url: `https://mybusinessbusinessinformation.googleapis.com/v1/accounts/${account}/locations`, - pageSize: 100, - params: { - filter, - readMask: "name,title", - }, + ...args, }); - return response?.locations ?? []; }, - async listReviews({ - account, location, - }: ListReviewsParams): Promise { - const response = await this._httpRequest({ + listReviews({ + account, location, ...args + }: Record & { args: object }): Promise { + return this._httpRequest({ url: `https://mybusiness.googleapis.com/v4/accounts/${account}/locations/${location}/reviews`, - pageSize: 50, + ...args, }); - return response?.reviews ?? []; }, async listPosts({ account, location, ...args diff --git a/components/google_my_business/package.json b/components/google_my_business/package.json index b908cad8359c4..a5e75a73c25f1 100644 --- a/components/google_my_business/package.json +++ b/components/google_my_business/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/google_my_business", - "version": "0.2.0", + "version": "0.2.1", "description": "Pipedream Google My Business Components", "main": "dist/app/google_my_business.app.mjs", "keywords": [ diff --git a/components/google_my_business/sources/new-post-created/new-post-created.ts b/components/google_my_business/sources/new-post-created/new-post-created.ts index bfceee27b090d..4e2ac9a9f436d 100644 --- a/components/google_my_business/sources/new-post-created/new-post-created.ts +++ b/components/google_my_business/sources/new-post-created/new-post-created.ts @@ -10,7 +10,7 @@ export default defineSource({ key: "google_my_business-new-post-created", name: "New Post Created", description: `Emit new event for each new local post on a location [See the documentation](${DOCS_LINK})`, - version: "0.0.4", + version: "0.0.5", type: "source", dedupe: "unique", methods: { diff --git a/components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts b/components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts index 11ceeaa0a2e26..53bf8255ca218 100644 --- a/components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts +++ b/components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts @@ -13,7 +13,7 @@ export default defineSource({ key: "google_my_business-new-review-created-multiple-locations", name: "New Review Created (Multiple Locations)", description: `Emit new event for each new review on any of the selected locations [See the documentation](${DOCS_LINK})`, - version: "0.0.1", + version: "0.0.2", type: "source", dedupe: "unique", props: { diff --git a/components/google_my_business/sources/new-review-created/new-review-created.ts b/components/google_my_business/sources/new-review-created/new-review-created.ts index e40fd6f8c5c26..27e7dca54f05b 100644 --- a/components/google_my_business/sources/new-review-created/new-review-created.ts +++ b/components/google_my_business/sources/new-review-created/new-review-created.ts @@ -10,7 +10,7 @@ export default defineSource({ key: "google_my_business-new-review-created", name: "New Review Created", description: `Emit new event for each new review on a location [See the documentation](${DOCS_LINK})`, - version: "0.0.4", + version: "0.0.5", type: "source", dedupe: "unique", methods: {