diff --git a/packages/restapi/src/lib/channels/getChannels.ts b/packages/restapi/src/lib/channels/getChannels.ts index 9ea71d88b..e9d1fe909 100644 --- a/packages/restapi/src/lib/channels/getChannels.ts +++ b/packages/restapi/src/lib/channels/getChannels.ts @@ -4,7 +4,7 @@ import CONSTANTS from '../constantsV2'; import { getAPIBaseUrls, getCAIPAddress } from '../helpers'; import { axiosGet } from '../utils/axiosUtil'; import { parseSettings } from '../utils/parseSettings'; - +import { SOURCE_TYPES } from '../payloads/constants'; /** * GET /v1/channels/{addressinCAIP} */ @@ -16,20 +16,22 @@ type getChannelsOptionsType = { limit?: number; sort?: string; order?: string; -} + filter?: keyof typeof SOURCE_TYPES | 'ALL'; +}; export const getChannels = async (options: getChannelsOptionsType) => { - const { - env = CONSTANTS.ENV.PROD, - page = 1, - limit = 10, + const { + env = CONSTANTS.ENV.PROD, + page = 1, + limit = 10, sort = CONSTANTS.FILTER.CHANNEL_LIST.SORT.SUBSCRIBER, order = CONSTANTS.FILTER.CHANNEL_LIST.ORDER.DESCENDING, + filter = 'ALL', } = options || {}; const API_BASE_URL = getAPIBaseUrls(env); const apiEndpoint = `${API_BASE_URL}/v1/channels`; - const requestUrl = `${apiEndpoint}?page=${page}&limit=${limit}&sort=${sort}&order=${order}`; + const requestUrl = `${apiEndpoint}?page=${page}&limit=${limit}&sort=${sort}&order=${order}&filter=${filter}`; return await axiosGet(requestUrl) .then((response) => { diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index dc3c6c20f..c24e4b560 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -1,6 +1,7 @@ import { ADDITIONAL_META_TYPE } from '../../lib/payloads/constants'; import { GetAliasInfoOptionsType } from '../alias'; import { NotifictaionType, ProgressHookType } from '../types'; +import { SOURCE_TYPES } from '../payloads/constants'; export type SubscriptionOptions = { account?: string; @@ -151,6 +152,7 @@ export type ChannelListOptions = { limit?: number; sort?: ChannelListSortType; order?: ChannelListOrderType; + filter?: keyof typeof SOURCE_TYPES | 'ALL'; }; diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index cc2a48f8f..6fddf57a6 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -444,6 +444,7 @@ export class Channel extends PushNotificationBaseClass { limit, sort = ChannelListSortType.SUBSCRIBER, order = ChannelListOrderType.DESCENDING, + filter = 'ALL', } = options || {}; return await PUSH_CHANNEL.getChannels({ @@ -452,6 +453,7 @@ export class Channel extends PushNotificationBaseClass { limit, sort, order, + filter }); } catch (error) { throw new Error(`Push SDK Error: Contract : channel::list : ${error}`); diff --git a/packages/restapi/tests/lib/notification/channel.test.ts b/packages/restapi/tests/lib/notification/channel.test.ts index f2193db11..ca70a7f97 100644 --- a/packages/restapi/tests/lib/notification/channel.test.ts +++ b/packages/restapi/tests/lib/notification/channel.test.ts @@ -586,4 +586,16 @@ describe('PushAPI.channel functionality', () => { expect(res).not.null; }); }); + + describe('list', async () => { + it('Should the channel details', async () => { + const res = await userAlice.channel.list({}); + expect(res).not.null; + }); + + it('Should fetch channel details based on the filter', async () => { + const res = await userAlice.channel.list({ filter: 'POLYGON_TEST_AMOY' }); + expect(res).not.null; + }); + }); });