Skip to content

Commit

Permalink
Add execution-details and inbound-parse to node sdk (#4746)
Browse files Browse the repository at this point in the history
* feat: Add execution-details to node sdk

* feat: Add inbound-parse mx status to node sdk

* fix: Add notificationId and subscriberId params to execution details node sdk get method

* docs: Add execution details and inbound parse node sdk methods to readme

* update exection details params

* fix: change subscribers to events

* fix: update pnpm lock file

---------

Co-authored-by: Pawan Jain <[email protected]>
  • Loading branch information
peoray and jainpawan21 authored Dec 19, 2023
1 parent 5506919 commit 063aa16
Show file tree
Hide file tree
Showing 9 changed files with 642 additions and 464 deletions.
70 changes: 56 additions & 14 deletions packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ Novu provides a single API to manage providers across multiple channels with a s
- [Layouts](#layouts)
- [Integrations](#integrations)
- [Organizations](#organizations)

- [Inbound Parse](#inbound-parse)
- [Execution Details](#execution-details)

### Subscribers

Expand All @@ -171,6 +172,7 @@ await novu.subscribers.list(page,limit)
```

- #### Identify (create) a new subscriber

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

Expand All @@ -192,6 +194,7 @@ await novu.subscribers.identify("subscriberId", {


- #### Bulk create subscribers

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

Expand Down Expand Up @@ -230,6 +233,7 @@ await novu.subscribers.identify([


- #### Get a single subscriber

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

Expand Down Expand Up @@ -261,6 +265,7 @@ await novu.subscribers.update("subscriberId",{
```

- #### Update provider credentials

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

Expand All @@ -277,12 +282,13 @@ await novu.subscribers.setCredentials("subscriberId", "slack", {
})

// update slack weebhook for a subscriberId with selected integration
await novu.subscribers.setCredentials("subscriberId","slack",{
await novu.subscribers.setCredentials("subscriberId", "slack", {
webhookUrl: ["webhookUrl"]
},"identifier_slack")
}, "slack_identifier" )
```

- #### Delete provider credentials

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

Expand Down Expand Up @@ -317,6 +323,7 @@ await novu.subscribers.updateOnlineStatus("subscriberId", false)
```

- #### Get subscriber preference for all workflows

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

Expand All @@ -326,6 +333,7 @@ await novu.subscribers.getPreference("subscriberId")
```

- #### Get subscriber global preference

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

Expand All @@ -336,6 +344,7 @@ await novu.subscribers.getGlobalPreference("subscriberId" )


- #### Get subscriber preference by level

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

Expand All @@ -346,7 +355,9 @@ await novu.subscribers.getPreferenceByLevel("subscriberId", PreferenceLevelEnum.
// Get template level preference
await novu.subscribers.getPreferenceByLevel("subscriberId", PreferenceLevelEnum.TEMPLATE)
```

- #### Update subscriber preference for a workflow

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

Expand All @@ -371,6 +382,7 @@ await novu.subscribers.updatePreference("subscriberId", "workflowId", {
```

- #### Update subscriber preference globally

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

Expand Down Expand Up @@ -412,6 +424,7 @@ await novu.subscribers.getNotificationsFeed("subscriberId", params);
```

- #### Get seen/unseen in-app messages (notifications) count

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

Expand Down Expand Up @@ -485,7 +498,7 @@ import { Novu } from '@novu/node';
const novu = new Novu('<NOVU_API_KEY>');

// trigger to existing subscribers
await novu.subscribers.trigger("workflowIdentifier", {
await novu.events.trigger("workflowIdentifier", {
to: "subscriberId",
payload: {
customKey: "customValue",
Expand All @@ -508,7 +521,7 @@ await novu.subscribers.trigger("workflowIdentifier", {
});

// create new subscriber inline with trigger
await novu.subscribers.trigger("workflowIdentifier", {
await novu.events.trigger("workflowIdentifier", {
to: {
subscriberId: "1",
firstName: "Pawan",
Expand Down Expand Up @@ -536,7 +549,7 @@ import { Novu } from '@novu/node';

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

await novu.subscribers.trigger("workflowIdentifier", {
await novu.events.trigger("workflowIdentifier", {
to: [ "subscriberId1" , "subscriberId2" ],
payload: {},
overrides:{} ,
Expand All @@ -546,7 +559,7 @@ await novu.subscribers.trigger("workflowIdentifier", {


// create new subscribers inline with trigger
await novu.subscribers.trigger("workflowIdentifier", {
await novu.events.trigger("workflowIdentifier", {
to: [
{
subscriberId: "1",
Expand Down Expand Up @@ -583,6 +596,7 @@ await novu.subscribers.trigger("workflowIdentifier", {
```

- #### Trigger to a topic

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

Expand All @@ -605,7 +619,7 @@ import { Novu } from '@novu/node';

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

await novu.subscribers.bulkTrigger([
await novu.events.bulkTrigger([
{
name: "workflowIdentifier_1",
to: "subscriberId_1",
Expand Down Expand Up @@ -652,7 +666,7 @@ import { Novu } from '@novu/node';

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

await novu.subscribers.broadcast("workflowIdentifier", {
await novu.events.broadcast("workflowIdentifier", {
payload: {
customKey: "customValue",
customKey1: {
Expand All @@ -675,8 +689,9 @@ import { Novu } from '@novu/node';

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

await novu.subscribers.cancel("transactionId");
await novu.events.cancel("transactionId");
```

### Messages

- #### List all messages
Expand Down Expand Up @@ -1220,8 +1235,35 @@ import { Novu } from '@novu/node';
const novu = new Novu('<NOVU_API_KEY>');

await novu.organizations.updateBranding({
logo: 'https://s3.us-east-1.amazonaws.com/bucket/image.jpeg',
color: '#000000',
fontFamily: 'Lato',
};);
logo: 'https://s3.us-east-1.amazonaws.com/bucket/image.jpeg',
color: '#000000',
fontFamily: 'Lato',
});
```


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

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

// Validate the mx record setup for the inbound parse functionality
await novu.inboundParse.getMxStatus()
```

### Execution Details

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

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

const executionDetailsParams = {
subscriberId: 'subscriberId_123',
notificationId: 'notificationid_abcd'
}

// get execution details
await novu.executionDetails.get(executionDetailsParams)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface IExecutionDetails {
get(data: IExecutionDetailsPayload);
}

export interface IExecutionDetailsPayload {
notificationId: string;
subscriberId: string;
}
29 changes: 29 additions & 0 deletions packages/node/src/lib/execution-details/execution-details.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Novu } from '../novu';
import axios from 'axios';

const mockConfig = {
apiKey: '1234',
};

jest.mock('axios');

describe('test use of novus node package - ExecutionDetails class', () => {
const mockedAxios = axios as jest.Mocked<typeof axios>;
let novu: Novu;

beforeEach(() => {
mockedAxios.create.mockReturnThis();
novu = new Novu(mockConfig.apiKey);
});

test('should get execution details correctly', async () => {
const notificationId = '12345678';
const subscriberId = '987654321';
mockedAxios.get.mockResolvedValue({});

await novu.executionDetails.get({ notificationId, subscriberId });

expect(mockedAxios.get).toHaveBeenCalled();
expect(mockedAxios.get).toHaveBeenCalledWith('/execution-details');
});
});
15 changes: 15 additions & 0 deletions packages/node/src/lib/execution-details/execution-details.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
IExecutionDetails,
IExecutionDetailsPayload,
} from './execution-details.interface';
import { WithHttp } from '../novu.interface';

export class ExecutionDetails extends WithHttp implements IExecutionDetails {
async get(data: IExecutionDetailsPayload) {
const { notificationId, subscriberId } = data;

return await this.http.get(`/execution-details`, {
params: { notificationId, subscriberId },
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IInboundParse {
getMxStatus();
}
27 changes: 27 additions & 0 deletions packages/node/src/lib/inbound-parse/inbound-parse.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Novu } from '../novu';
import axios from 'axios';

const mockConfig = {
apiKey: '1234',
};

jest.mock('axios');

describe('test use of novus node package - InboundParse class', () => {
const mockedAxios = axios as jest.Mocked<typeof axios>;
let novu: Novu;

beforeEach(() => {
mockedAxios.create.mockReturnThis();
novu = new Novu(mockConfig.apiKey);
});

test('should get inbound parse correctly', async () => {
mockedAxios.get.mockResolvedValue({});

await novu.inboundParse.getMxStatus();

expect(mockedAxios.get).toHaveBeenCalled();
expect(mockedAxios.get).toHaveBeenCalledWith('/inbound-parse/mx/status');
});
});
8 changes: 8 additions & 0 deletions packages/node/src/lib/inbound-parse/inbound-parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { IInboundParse } from './inbound-parse.interface';
import { WithHttp } from '../novu.interface';

export class InboundParse extends WithHttp implements IInboundParse {
async getMxStatus() {
return await this.http.get(`/inbound-parse/mx/status`);
}
}
7 changes: 7 additions & 0 deletions packages/node/src/lib/novu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { Topics } from './topics/topics';
import { Integrations } from './integrations/integrations';
import { Messages } from './messages/messages';
import { Tenants } from './tenants/tenants';
import { ExecutionDetails } from './execution-details/execution-details';
import { InboundParse } from './inbound-parse/inbound-parse';
import { Organizations } from './organizations/organizations';

import { makeRetryable } from './retry';

export class Novu extends EventEmitter {
Expand All @@ -31,6 +34,8 @@ export class Novu extends EventEmitter {
readonly integrations: Integrations;
readonly messages: Messages;
readonly tenants: Tenants;
readonly executionDetails: ExecutionDetails;
readonly inboundParse: InboundParse;
readonly organizations: Organizations;

constructor(apiKey: string, config?: INovuConfiguration) {
Expand Down Expand Up @@ -61,6 +66,8 @@ export class Novu extends EventEmitter {
this.integrations = new Integrations(this.http);
this.messages = new Messages(this.http);
this.tenants = new Tenants(this.http);
this.executionDetails = new ExecutionDetails(this.http);
this.inboundParse = new InboundParse(this.http);
this.organizations = new Organizations(this.http);

this.trigger = this.events.trigger;
Expand Down
Loading

0 comments on commit 063aa16

Please sign in to comment.