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(node): add includeInactiveChannels option in sdk method #7115

Merged
merged 5 commits into from
Nov 29, 2024
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
24 changes: 22 additions & 2 deletions packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,22 @@ await novu.subscribers.updateOnlineStatus('subscriberId', false);

- #### Get subscriber preference for all workflows

This method returns subscriber preference for all workflows with inactive channels by default. To get subscriber preference for all workflows without inactive (means only active) channels, pass `false` as second argument.

```ts
import { Novu } from '@novu/node';

const novu = new Novu('<NOVU_SECRET_KEY>');

await novu.subscribers.getPreference('subscriberId');
// return subscriber preference for all workflows without inactive channels
await novu.subscribers.getPreference('subscriberId', {
includeInactiveChannels: false,
});

// return subscriber preference for all workflows with inactive channels
await novu.subscribers.getPreference('subscriberId', {
includeInactiveChannels: true,
});
```

- #### Get subscriber global preference
Expand Down Expand Up @@ -756,13 +766,23 @@ await novu.messages.list(params);
- #### Delete a message by `messageId`

```ts
import { Novu, ChannelTypeEnum } from '@novu/node';
import { Novu } from '@novu/node';

const novu = new Novu('<NOVU_SECRET_KEY>');

await novu.messages.deleteById('messageId');
```

- #### Delete multiple messages by `transactionId`

```ts
import { Novu } from '@novu/node';

const novu = new Novu('<NOVU_SECRET_KEY>');

await novu.messages.deleteByTransactionId('transactionId');
```

### Layouts

- #### Create a layout
Expand Down
5 changes: 4 additions & 1 deletion packages/node/src/lib/subscribers/subscriber.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export interface ISubscribers {
*/
unsetCredentials(subscriberId: string, providerId: string);
updateOnlineStatus(subscriberId: string, online: boolean);
getPreference(subscriberId: string);
getPreference(
subscriberId: string,
{ includeInactiveChannels }: { includeInactiveChannels: boolean },
);
getGlobalPreference(subscriberId: string);
getPreferenceByLevel(subscriberId: string, level: PreferenceLevelEnum);
updatePreference(
Expand Down
6 changes: 4 additions & 2 deletions packages/node/src/lib/subscribers/subscribers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ describe('test use of novus node package - Subscribers class', () => {
test('should get subscriber preference', async () => {
mockedAxios.get.mockResolvedValue({});

await novu.subscribers.getPreference('test-subscriber-preference');
await novu.subscribers.getPreference('test-subscriber-preference', {
includeInactiveChannels: true,
});

expect(mockedAxios.get).toHaveBeenCalled();
expect(mockedAxios.get).toHaveBeenCalledWith(
'/subscribers/test-subscriber-preference/preferences',
'/subscribers/test-subscriber-preference/preferences?includeInactiveChannels=true',
);
});

Expand Down
9 changes: 7 additions & 2 deletions packages/node/src/lib/subscribers/subscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ export class Subscribers extends WithHttp implements ISubscribers {
return await this.http.delete(`/subscribers/${subscriberId}`);
}

async getPreference(subscriberId: string) {
return await this.http.get(`/subscribers/${subscriberId}/preferences`);
async getPreference(
subscriberId: string,
{ includeInactiveChannels = true }: { includeInactiveChannels: boolean },
) {
return await this.http.get(
`/subscribers/${subscriberId}/preferences?includeInactiveChannels=${includeInactiveChannels}`,
);
}

async getGlobalPreference(subscriberId: string) {
Expand Down
Loading