diff --git a/packages/restapi/src/lib/channels/getSubscribers.ts b/packages/restapi/src/lib/channels/getSubscribers.ts index 50f2f7824..74884f686 100644 --- a/packages/restapi/src/lib/channels/getSubscribers.ts +++ b/packages/restapi/src/lib/channels/getSubscribers.ts @@ -18,6 +18,7 @@ export type GetChannelSubscribersOptionsType = { channel: string; // plain ETH Format only page?: number, limit?: number, + category?: number, env?: ENV } @@ -28,6 +29,7 @@ export const getSubscribers = async ( channel, page = 1, limit = 10, + category, env = Constants.ENV.PROD, } = options || {}; @@ -49,7 +51,10 @@ export const getSubscribers = async ( } const _channel = await getCAIPAddress(env, channel, 'Channel'); const API_BASE_URL = getAPIBaseUrls(env); - const apiEndpoint = `${API_BASE_URL}/v1/channels/${_channel}/subscribers?page=${page}&limit=${limit}`; + let apiEndpoint = `${API_BASE_URL}/v1/channels/${_channel}/subscribers?page=${page}&limit=${limit}`; + if(category){ + apiEndpoint = apiEndpoint+`&category=${category}` + } return await axios.get(apiEndpoint) .then((response) => response.data) .catch((err) => { diff --git a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts index 060dfe53f..e7956414e 100644 --- a/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts +++ b/packages/restapi/src/lib/pushNotification/PushNotificationTypes.ts @@ -11,6 +11,7 @@ export type ChannelInfoOptions = { channel?: string; page?: number; limit?: number; + category?: number }; export type SubscribeUnsubscribeOptions = { diff --git a/packages/restapi/src/lib/pushNotification/channel.ts b/packages/restapi/src/lib/pushNotification/channel.ts index 0e5f80c5d..9d01033b9 100644 --- a/packages/restapi/src/lib/pushNotification/channel.ts +++ b/packages/restapi/src/lib/pushNotification/channel.ts @@ -99,6 +99,7 @@ export class Channel extends PushNotificationBaseClass { env: this.env, page: options.page, limit: options.limit ?? 10, + category: options.category }); } else { /** @dev - Fallback to deprecated method when page is not provided ( to ensure backward compatibility ) */ diff --git a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts index 7280c98de..f67905210 100644 --- a/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts +++ b/packages/restapi/src/lib/pushNotification/pushNotificationBase.ts @@ -762,15 +762,28 @@ export class PushNotificationBaseClass { const ele = setting[i]; const enabled = ele.enabled ? 1 : 0; if (ele.enabled) numberOfSettings++; - // slider type + if (Object.keys(ele).includes('value')) { - userSetting = - userSetting + - SLIDER_TYPE + - SETTING_DELIMITER + - enabled + - SETTING_DELIMITER + - ele.value; + // slider type + if (typeof ele.value == 'number') + userSetting = + userSetting + + SLIDER_TYPE + + SETTING_DELIMITER + + enabled + + SETTING_DELIMITER + + ele.value; + else { + userSetting = + userSetting + + RANGE_TYPE + + SETTING_DELIMITER + + enabled + + SETTING_DELIMITER + + ele.value?.lower + + SETTING_DELIMITER + + ele.value?.upper; + } } else { // boolean type userSetting = userSetting + BOOLEAN_TYPE + SETTING_DELIMITER + enabled; diff --git a/packages/restapi/tests/lib/pushNotification/base.test.ts b/packages/restapi/tests/lib/pushNotification/base.test.ts index 041b9ff2b..4374aaa22 100644 --- a/packages/restapi/tests/lib/pushNotification/base.test.ts +++ b/packages/restapi/tests/lib/pushNotification/base.test.ts @@ -25,39 +25,41 @@ enum ENV { LOCAL = 'local', } describe.only('test', () => { - const signer = createWalletClient({ - account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`), - chain: goerli, - transport: http('https://goerli.blockpi.network/v1/rpc/public'), - }); + // const signer = createWalletClient({ + // account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`), + // chain: goerli, + // transport: http('https://goerli.blockpi.network/v1/rpc/public'), + // }); - const signer3 = createWalletClient({ - account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`), - chain: polygonMumbai, - transport: http(), - }); + // const signer3 = createWalletClient({ + // account: privateKeyToAccount(`0x${process.env['WALLET_PRIVATE_KEY']}`), + // chain: polygonMumbai, + // transport: http(), + // }); - const provider = new ethers.providers.JsonRpcProvider( - 'https://goerli.blockpi.network/v1/rpc/public' - ); - const signer2 = new ethers.Wallet( - `0x${process.env['WALLET_PRIVATE_KEY']}`, - provider - ); + // const provider = new ethers.providers.JsonRpcProvider( + // 'https://goerli.blockpi.network/v1/rpc/public' + // ); + // const signer2 = new ethers.Wallet( + // `0x${process.env['WALLET_PRIVATE_KEY']}`, + // provider + // ); - // it.only('Test minimal conversion', async () => { + // it('Test minimal conversion', async () => { // const account2 = await signer2.getAddress(); // const viemUser = new PushNotificationBaseClass( // signer, // ENV.STAGING, // account2 // ); - // viemUser.getMinimalUserSetting([ + // const res = viemUser.getMinimalUserSetting([ // { enabled: true }, // { enabled: false, value: 10 }, // { enabled: false }, // { enabled: true, value: 10 }, + // {enabled: true, value: {lower:10, upper:100}} // ]); + // console.log(res) // }); // it('testing with viem', async () => { // const account2 = await signer2.getAddress(); diff --git a/packages/restapi/tests/lib/pushNotification/channel.test.ts b/packages/restapi/tests/lib/pushNotification/channel.test.ts index 01121b12e..f52fbf0bd 100644 --- a/packages/restapi/tests/lib/pushNotification/channel.test.ts +++ b/packages/restapi/tests/lib/pushNotification/channel.test.ts @@ -126,6 +126,11 @@ describe('PushAPI.channel functionality', () => { expect(res).not.null; }); + it('Without signer and account : Should return response without passing the options', async () => { + const res = await userKate.channel.subscribers({page:1, limit:10, category:2}); + expect(res).not.null; + }); + it('Without signer and account : Should throw error for invalid caip', async () => { await expect(() => userBob.channel.subscribers({ diff --git a/packages/restapi/tests/lib/pushNotification/notification.test.ts b/packages/restapi/tests/lib/pushNotification/notification.test.ts index 7c3976882..a918bd182 100644 --- a/packages/restapi/tests/lib/pushNotification/notification.test.ts +++ b/packages/restapi/tests/lib/pushNotification/notification.test.ts @@ -21,28 +21,37 @@ describe('PushAPI.notification functionality', () => { let userViem: PushAPI; beforeEach(async () => { signer1 = new ethers.Wallet( - `0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}` + `0x${process.env['WALLET_PRIVATE_KEY']}` ); account1 = await signer1.getAddress(); - + const provider = new ethers.providers.JsonRpcProvider( 'https://rpc.sepolia.org' ); signer2 = new ethers.Wallet( - `0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}`, + `0x${process.env['WALLET_PRIVATE_KEY']}`, provider ); account2 = await signer2.getAddress(); viemSigner = createWalletClient({ account: privateKeyToAccount( - `0x${process.env['NFT_HOLDER_WALLET_PRIVATE_KEY_1']}` + `0x${process.env['WALLET_PRIVATE_KEY']}` ), chain: sepolia, transport: http(), }); + enum ENV { + PROD = 'prod', + STAGING = 'staging', + DEV = 'dev', + /** + * **This is for local development only** + */ + LOCAL = 'local', + } // initialisation with signer and provider - userKate = await PushAPI.initialize(signer2); + userKate = await PushAPI.initialize(signer2, {env:ENV.DEV}); // initialisation with signer userAlice = await PushAPI.initialize(signer1); // TODO: remove signer1 after signer becomes optional @@ -85,7 +94,7 @@ describe('PushAPI.notification functionality', () => { it('Should return feeds when viem is used', async () => { const response = await userViem.notification.list('SPAM'); - console.log(response) + console.log(response); expect(response).not.null; }); @@ -95,30 +104,30 @@ describe('PushAPI.notification functionality', () => { channels: ['0xD8634C39BBFd4033c0d3289C4515275102423681'], raw: true, }); - // console.log(response) + // console.log(response) expect(response).not.null; }); }); describe('notification :: subscribe', () => { beforeEach(async () => { - await userAlice.notification.unsubscribe( - 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - ); + // await userAlice.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); - await userKate.notification.unsubscribe( - 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - ); - }); + // await userKate.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); + // }); - afterEach(async () => { - await userAlice.notification.unsubscribe( - 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - ); + // afterEach(async () => { + // await userAlice.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); - await userKate.notification.unsubscribe( - 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' - ); + // await userKate.notification.unsubscribe( + // 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' + // ); }); it.skip('Without signer object: should throw error', async () => { await expect(() => @@ -138,13 +147,17 @@ describe('PushAPI.notification functionality', () => { it('With signer object: Should subscribe', async () => { const res = await userAlice.notification.subscribe( - 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681', { - settings: [{ - enabled: false - },{ - enabled: false, - value: 0 - }, ] + 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681', + { + settings: [ + { + enabled: false, + }, + { + enabled: false, + value: 0, + }, + ], } ); // console.log(res) @@ -159,6 +172,39 @@ describe('PushAPI.notification functionality', () => { expect(res).not.null; }); + it('With signer and provider: Should subscribe', async () => { + const res = await userKate.notification.subscribe( + 'eip155:11155111:0xC8c243a4fd7F34c49901fe441958953402b7C024', + { + settings: [ + { + enabled: false, + }, + { + enabled: true, + value: 15, + }, + { + enabled: true, + value: { + lower: 5, + upper: 10, + }, + }, + { + enabled: true, + value: { + lower: 5, + upper: 10, + }, + }, + ], + } + ); + console.log(res) + expect(res).not.null; + }); + it('With viem signer and provider: Should subscribe', async () => { const res = await userViem.notification.subscribe( 'eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681' @@ -175,7 +221,7 @@ describe('PushAPI.notification functionality', () => { it('Signer with no account: Should return response', async () => { const response = await userAlice.notification.subscriptions(); - console.log(response); + console.log(response); expect(response).not.null; }); @@ -208,7 +254,5 @@ describe('PushAPI.notification functionality', () => { // it("Uploading data to ipfs via push node", async () => { // await userAlice.uploadToIPFSViaPushNode("test") // }) - - - }); +}); // });