Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix depreaction warn of get subscribers using pagination #864

Merged
merged 1 commit into from
Nov 22, 2023
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
7 changes: 4 additions & 3 deletions packages/restapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ const searchResult = await userAlice.channel.search("push")
### **Get Subscribers Of A Channel**

```tsx
// fetches subscribers of a channel
const subscribersResult = await userAlice.channel.subscribers()
// fetches subscribers of a channel in a paginated manner
const subscribersResult = await userAlice.channel.subscribers({page: 1, limit: 10})

```

Expand All @@ -335,7 +335,8 @@ const subscribersResult = await userAlice.channel.subscribers()
| --- | --- | --- | --- |
| options* | ChannelInfoOptions | - | Configuration options for retrieving subscribers. |
| options.channel* | string | - | Channel address in CAIP |

| options.page* | number | - | The page number for pagination |
| options.limit* | number | - | The maximum number of items to retrieve per page |
\* - Optional

---
Expand Down
2 changes: 1 addition & 1 deletion packages/restapi/src/lib/channels/_getSubscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const deprecationWarning = `

export const _getSubscribers = async (
options: GetSubscribersOptionsType
) => {
) : Promise<string[]> => {

console.warn(deprecationWarning);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export type SubscriptionOptions = {
};
export type ChannelInfoOptions = {
channel?: string;
page?: number;
limit?: number;
};

export type SubscribeUnsubscribeOptions = {
Expand Down
19 changes: 15 additions & 4 deletions packages/restapi/src/lib/pushNotification/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,21 @@ export class Channel extends PushNotificationBaseClass {
if (!validateCAIP(channel!)) {
throw new Error('Invalid CAIP');
}
return await PUSH_CHANNEL._getSubscribers({
channel: channel!,
env: this.env,
});
if (options && options.page) {
return await PUSH_CHANNEL.getSubscribers({
channel: channel!,
env: this.env,
page: options.page,
limit: options.limit ?? 10,
});
} else {
/** @dev - Fallback to deprecated method when page is not provided ( to ensure backward compatibility ) */
/** @notice - This will be removed in V2 Publish */
return await PUSH_CHANNEL._getSubscribers({
channel: channel!,
env: this.env,
});
}
} catch (error) {
throw new Error(`Push SDK Error: API : channel::subscribers : ${error}`);
}
Expand Down
Loading