Skip to content

Commit

Permalink
Add support for cursor query param in Audience API (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbiesek authored Oct 24, 2023
1 parent b243cb8 commit 3d6b872
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ const { audienceId } = await courier.audiences.put({
// To retrieve list of members in a given audience, you can use the following:
const { items: audienceMembers } = await courier.audiences.listMembers(
audienceId
cursor: "<CURSOR>", // optional
);

// To send a notification to all users that match the given filter criteria, you can use the following:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trycourier/courier",
"version": "5.5.0",
"version": "5.6.0",
"description": "A node.js module for communicating with the Courier REST API.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
19 changes: 14 additions & 5 deletions src/audiences/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,30 @@ const getAudience = (options: ICourierClientConfiguration) => {
};

const listAudiences = (options: ICourierClientConfiguration) => {
return async (): Promise<AudienceTypes.IAudienceListResponse> => {
return async (params?: {
cursor: string;
}): Promise<AudienceTypes.IAudienceListResponse> => {
const response = await options.httpClient.get<
AudienceTypes.IAudienceListResponse
>("/audiences");
AudienceTypes.IAudienceListResponse>(
"/audiences",
params
);
return response.data;
};
};

const listMembers = (options: ICourierClientConfiguration) => {
return async (
audienceId: string
audienceId: string,
params?: {
cursor: string;
}
): Promise<AudienceTypes.IAudienceMemberListResponse> => {
const response = await options.httpClient.get<
AudienceTypes.IAudienceMemberListResponse
>(`/audiences/${audienceId}/members`);
>(
`/audiences/${audienceId}/members`,
params);
return response.data;
};
};
Expand Down
8 changes: 6 additions & 2 deletions src/audiences/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ export interface IAudiencePutResponse {
export interface ICourierClientAudiences {
delete: (id: string) => Promise<void>;
get: (id: string) => Promise<IAudience>;
listAudiences: () => Promise<IAudienceListResponse>;
listMembers: (id: string) => Promise<IAudienceMemberListResponse>;
listAudiences: (params?: {
cursor: string;
}) => Promise<IAudienceListResponse>;
listMembers: (id: string, params?: {
cursor: string;
}) => Promise<IAudienceMemberListResponse>;
put: (
audience: Omit<IAudience, "created_at" | "updated_at">
) => Promise<IAudience>;
Expand Down

0 comments on commit 3d6b872

Please sign in to comment.