Skip to content

Commit 46238a0

Browse files
committed
[FIX] Google My Business pagination
1 parent c4e584e commit 46238a0

File tree

11 files changed

+90
-46
lines changed

11 files changed

+90
-46
lines changed

components/google_my_business/actions/create-post/create-post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineAction({
1212
key: "google_my_business-create-post",
1313
name: "Create Post",
1414
description: `Create a new local post associated with a location. [See the documentation](${DOCS_LINK})`,
15-
version: "0.0.3",
15+
version: "0.0.4",
1616
type: "action",
1717
props: {
1818
app,

components/google_my_business/actions/create-update-reply-to-review/create-update-reply-to-review.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineAction({
88
key: "google_my_business-create-update-reply-to-review",
99
name: "Create or Update Reply to Review",
1010
description: `Create or update a reply to the specified review. [See the documentation](${DOCS_LINK})`,
11-
version: "0.0.2",
11+
version: "0.0.3",
1212
type: "action",
1313
props: {
1414
app,

components/google_my_business/actions/get-reviews-multiple-locations/get-reviews-multiple-locations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineAction({
88
key: "google_my_business-get-reviews-multiple-locations",
99
name: "Get Reviews from Multiple Locations",
1010
description: `Get reviews from multiple locations at once. [See the documentation](${DOCS_LINK})`,
11-
version: "0.0.1",
11+
version: "0.0.2",
1212
type: "action",
1313
props: {
1414
app,

components/google_my_business/actions/get-specific-review/get-specific-review.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineAction({
88
key: "google_my_business-get-specific-review",
99
name: "Get a Specific Review",
1010
description: `Return a specific review by name. [See the documentation](${DOCS_LINK})`,
11-
version: "0.0.1",
11+
version: "0.0.2",
1212
type: "action",
1313
props: {
1414
app,

components/google_my_business/actions/list-all-reviews/list-all-reviews.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default defineAction({
88
key: "google_my_business-list-all-reviews",
99
name: "List All Reviews",
1010
description: `List all reviews of a location to audit reviews in bulk. [See the documentation](${DOCS_LINK})`,
11-
version: "0.0.1",
11+
version: "0.0.2",
1212
type: "action",
1313
props: {
1414
app,

components/google_my_business/actions/list-posts/list-posts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default defineAction({
99
key: "google_my_business-list-posts",
1010
name: "List Posts",
1111
description: `List local posts associated with a location. [See the documentation](${DOCS_LINK})`,
12-
version: "0.0.2",
12+
version: "0.0.3",
1313
type: "action",
1414
props: {
1515
app,

components/google_my_business/app/google_my_business.app.ts

Lines changed: 80 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineApp } from "@pipedream/types";
22
import { axios } from "@pipedream/platform";
33
import {
44
CreatePostParams,
5-
HttpRequestParams, ListPostsParams, ListReviewsParams, PaginatedRequestParams, UpdateReplyParams, GetReviewParams, BatchGetReviewsParams,
5+
HttpRequestParams, ListPostsParams, PaginatedRequestParams, UpdateReplyParams, GetReviewParams, BatchGetReviewsParams,
66
} from "../common/requestParams";
77
import {
88
Account, LocalPost, Location, Review,
@@ -16,14 +16,31 @@ export default defineApp({
1616
type: "string",
1717
label: "Account Name",
1818
description: "Select an **Account** or provide a custom *Account Name*.",
19-
async options() {
20-
const accounts: Account[] = await this.listAccounts();
21-
return accounts.map(({
19+
async options({ prevContext: { pageToken } }: {
20+
prevContext: { pageToken: string | null; };
21+
}) {
22+
if (pageToken === null) {
23+
return [];
24+
}
25+
const response = await this.listAccounts({
26+
params: {
27+
pageSize: 50,
28+
pageToken,
29+
},
30+
});
31+
const accounts: Account[] = response?.accounts ?? [];
32+
const options = accounts?.map?.(({
2233
name, accountName, type,
23-
}) => ({
34+
}: Account) => ({
2435
label: `${accountName ?? name} (${type})`,
2536
value: this.getCleanName(name) as string,
26-
}));
37+
})) ?? [];
38+
return {
39+
options,
40+
context: {
41+
pageToken: response?.nextPageToken ?? null,
42+
},
43+
};
2744
},
2845
},
2946
location: {
@@ -32,43 +49,76 @@ export default defineApp({
3249
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.",
3350
useQuery: true,
3451
async options({
35-
account, query,
36-
}: Record<string, string>) {
52+
account, query, prevContext: { pageToken },
53+
}: Record<string, string> & {
54+
prevContext: { pageToken: string | null; };
55+
}) {
56+
if (pageToken === null) {
57+
return [];
58+
}
3759
const filter = query
3860
? (query.match(/[=:]/)
3961
? query
4062
: `title="${query}"`).replace(/ /g, "+").replace(/"/g, "%22")
4163
: undefined;
4264

43-
const locations: Location[] = await this.listLocations({
65+
const response = await this.listLocations({
4466
account,
45-
filter,
67+
params: {
68+
pageSize: 50,
69+
pageToken,
70+
filter,
71+
readMask: "name,title",
72+
},
4673
});
47-
return locations?.map?.(({
74+
const locations: Location[] = response?.locations ?? [];
75+
const options = locations?.map?.(({
4876
name, title,
4977
}: Location) => ({
5078
label: title,
5179
value: this.getCleanName(name) as string,
5280
})) ?? [];
81+
return {
82+
options,
83+
context: {
84+
pageToken: response?.nextPageToken ?? null,
85+
},
86+
};
5387
},
5488
},
5589
review: {
5690
type: "string",
5791
label: "Review",
5892
description: "Select a **Review** or provide a custom *Review Name*.",
5993
async options({
60-
account, location,
61-
}: Record<string, string>) {
62-
const reviews: Review[] = await this.listReviews({
94+
account, location, prevContext: { pageToken },
95+
}: Record<string, string> & {
96+
prevContext: { pageToken: string | null; };
97+
}) {
98+
if (pageToken === null) {
99+
return [];
100+
}
101+
const response = await this.listReviews({
63102
account,
64103
location,
104+
params: {
105+
pageSize: 50,
106+
pageToken,
107+
},
65108
});
66-
return reviews?.map?.(({
109+
const reviews: Review[] = response?.reviews ?? [];
110+
const options = reviews?.map?.(({
67111
name, title,
68-
}: Location) => ({
112+
}: Review) => ({
69113
label: title,
70114
value: this.getCleanName(name) as string,
71-
}));
115+
})) ?? [];
116+
return {
117+
options,
118+
context: {
119+
pageToken: response?.nextPageToken ?? null,
120+
},
121+
};
72122
},
73123
},
74124
},
@@ -123,33 +173,27 @@ export default defineApp({
123173

124174
return result;
125175
},
126-
async listAccounts(): Promise<Account[]> {
127-
const response = await this._httpRequest({
176+
listAccounts(args: object = {}): Promise<unknown> {
177+
return this._httpRequest({
128178
url: "https://mybusinessaccountmanagement.googleapis.com/v1/accounts",
179+
...args,
129180
});
130-
return response?.accounts ?? [];
131181
},
132-
async listLocations({
133-
account, filter,
134-
}: Record<string, string>): Promise<Location[]> {
135-
const response = await this._httpRequest({
182+
listLocations({
183+
account, ...args
184+
}: Record<string, string> & { args: object }): Promise<unknown> {
185+
return this._httpRequest({
136186
url: `https://mybusinessbusinessinformation.googleapis.com/v1/accounts/${account}/locations`,
137-
pageSize: 100,
138-
params: {
139-
filter,
140-
readMask: "name,title",
141-
},
187+
...args,
142188
});
143-
return response?.locations ?? [];
144189
},
145-
async listReviews({
146-
account, location,
147-
}: ListReviewsParams): Promise<Review[]> {
148-
const response = await this._httpRequest({
190+
listReviews({
191+
account, location, ...args
192+
}: Record<string, string> & { args: object }): Promise<unknown> {
193+
return this._httpRequest({
149194
url: `https://mybusiness.googleapis.com/v4/accounts/${account}/locations/${location}/reviews`,
150-
pageSize: 50,
195+
...args,
151196
});
152-
return response?.reviews ?? [];
153197
},
154198
async listPosts({
155199
account, location, ...args

components/google_my_business/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/google_my_business",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "Pipedream Google My Business Components",
55
"main": "dist/app/google_my_business.app.mjs",
66
"keywords": [

components/google_my_business/sources/new-post-created/new-post-created.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineSource({
1010
key: "google_my_business-new-post-created",
1111
name: "New Post Created",
1212
description: `Emit new event for each new local post on a location [See the documentation](${DOCS_LINK})`,
13-
version: "0.0.4",
13+
version: "0.0.5",
1414
type: "source",
1515
dedupe: "unique",
1616
methods: {

components/google_my_business/sources/new-review-created-multiple-locations/new-review-created-multiple-locations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default defineSource({
1313
key: "google_my_business-new-review-created-multiple-locations",
1414
name: "New Review Created (Multiple Locations)",
1515
description: `Emit new event for each new review on any of the selected locations [See the documentation](${DOCS_LINK})`,
16-
version: "0.0.1",
16+
version: "0.0.2",
1717
type: "source",
1818
dedupe: "unique",
1919
props: {

0 commit comments

Comments
 (0)