diff --git a/packages/restapi/README.md b/packages/restapi/README.md index 793fd4af5..ef988b41d 100644 --- a/packages/restapi/README.md +++ b/packages/restapi/README.md @@ -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}) ``` @@ -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 --- diff --git a/packages/restapi/src/lib/channels/_getSubscribers.ts b/packages/restapi/src/lib/channels/_getSubscribers.ts index 704f09b99..5a8d7d07e 100644 --- a/packages/restapi/src/lib/channels/_getSubscribers.ts +++ b/packages/restapi/src/lib/channels/_getSubscribers.ts @@ -26,7 +26,7 @@ const deprecationWarning = ` export const _getSubscribers = async ( options: GetSubscribersOptionsType -) => { +) : Promise => { console.warn(deprecationWarning); diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index c67947978..696e18397 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -9,6 +9,8 @@ export type SubscriptionOptions = { }; export type ChannelInfoOptions = { channel?: string; + page?: number; + limit?: number; }; export type SubscribeUnsubscribeOptions = { diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index 0acbe9303..0e5f80c5d 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -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}`); }