Skip to content

Commit

Permalink
fix: fix depreaction warn of get subscribers using pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 committed Nov 22, 2023
1 parent 33e0ca9 commit 39a2a1b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
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

0 comments on commit 39a2a1b

Please sign in to comment.