Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notificationapi-node-server-sdk",
"version": "2.3.1",
"version": "2.3.2",
"description": "NotificationAPI server-side library for Node.js",
"keywords": [
"notificationapi",
Expand All @@ -22,10 +22,6 @@
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
},
"./interfaces": {
"import": "./lib/esm/interfaces.js",
"require": "./lib/cjs/interfaces.js"
}
},
"files": [
Expand Down
14 changes: 6 additions & 8 deletions src/__tests__/notificationapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
SendRequest,
SetUserPreferencesRequest,
User,
US_REGION,
EU_REGION,
CA_REGION
Region
} from '../interfaces';
import { createHmac } from 'crypto';

Expand Down Expand Up @@ -67,7 +65,7 @@
notificationapi.init(clientId, clientSecret);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const promise = notificationapi[func](params);

Check warning on line 68 in src/__tests__/notificationapi.test.ts

View workflow job for this annotation

GitHub Actions / Pull Request Pipeline

Function Call Object Injection Sink
expect(promise).toBeInstanceOf(Promise);
});

Expand All @@ -79,7 +77,7 @@
notificationapi.init(clientId, clientSecret);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await notificationapi[func](params);

Check warning on line 80 in src/__tests__/notificationapi.test.ts

View workflow job for this annotation

GitHub Actions / Pull Request Pipeline

Function Call Object Injection Sink
expect(axiosMock.history.post).toHaveLength(1);
});

Expand All @@ -92,7 +90,7 @@
notificationapi.init(clientId, clientSecret);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await notificationapi[func](params);

Check warning on line 93 in src/__tests__/notificationapi.test.ts

View workflow job for this annotation

GitHub Actions / Pull Request Pipeline

Function Call Object Injection Sink
expect(axiosMock.history.post).toHaveLength(1);
expect(axiosMock.history.post[0].headers?.['Authorization']).toEqual(
'Basic ' + cred
Expand All @@ -109,7 +107,7 @@
notificationapi.init(clientId, clientSecret);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await notificationapi[func](params);

Check warning on line 110 in src/__tests__/notificationapi.test.ts

View workflow job for this annotation

GitHub Actions / Pull Request Pipeline

Function Call Object Injection Sink
expect(console.log).toHaveBeenCalledTimes(1);
});

Expand All @@ -123,7 +121,7 @@
notificationapi.init(clientId, clientSecret);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return notificationapi[func](params).catch(() => {

Check warning on line 124 in src/__tests__/notificationapi.test.ts

View workflow job for this annotation

GitHub Actions / Pull Request Pipeline

Function Call Object Injection Sink
expect(console.error).toHaveBeenCalledTimes(1);
});
});
Expand All @@ -138,7 +136,7 @@
notificationapi.init(clientId, clientSecret);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(notificationapi[func](params)).rejects.toEqual(

Check warning on line 139 in src/__tests__/notificationapi.test.ts

View workflow job for this annotation

GitHub Actions / Pull Request Pipeline

Function Call Object Injection Sink
new Error('Request failed with status code 500')
);
});
Expand Down Expand Up @@ -816,31 +814,31 @@
notificationId: 'test'
});
expect(axiosMock.history.post[0].url).toEqual(
`${US_REGION}/${clientId}/sender`
`${Region.US_REGION}/${clientId}/sender`
);
});

test('uses EU region when specified', async () => {
axiosMock.onAny().reply(200);
notificationapi.init(clientId, clientSecret, { baseURL: EU_REGION });
notificationapi.init(clientId, clientSecret, { baseURL: Region.EU_REGION });
await notificationapi.send({
user: { id: 'test' },
notificationId: 'test'
});
expect(axiosMock.history.post[0].url).toEqual(
`${EU_REGION}/${clientId}/sender`
`${Region.EU_REGION}/${clientId}/sender`
);
});

test('uses CA region when specified', async () => {
axiosMock.onAny().reply(200);
notificationapi.init(clientId, clientSecret, { baseURL: CA_REGION });
notificationapi.init(clientId, clientSecret, { baseURL: Region.CA_REGION });
await notificationapi.send({
user: { id: 'test' },
notificationId: 'test'
});
expect(axiosMock.history.post[0].url).toEqual(
`${CA_REGION}/${clientId}/sender`
`${Region.CA_REGION}/${clientId}/sender`
);
});

Expand Down
18 changes: 13 additions & 5 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,22 @@ export enum Channels {
PUSH = 'PUSH',
WEB_PUSH = 'WEB_PUSH'
}
/** Region constants for API endpoints */
export const US_REGION = 'https://api.notificationapi.com';
export const EU_REGION = 'https://api.eu.notificationapi.com';
export const CA_REGION = 'https://api.ca.notificationapi.com';

/** Region enum defines the available API endpoints for different geographical regions:
* - US_REGION: United States region endpoint (https://api.notificationapi.com)
* - EU_REGION: European Union region endpoint (https://api.eu.notificationapi.com)
* - CA_REGION: Canada region endpoint (https://api.ca.notificationapi.com)
*/
export enum Region {
US_REGION = 'https://api.notificationapi.com',
EU_REGION = 'https://api.eu.notificationapi.com',
CA_REGION = 'https://api.ca.notificationapi.com'
}

/** To configure the SDK*/
export interface InitConfiguration {
/** To update the base url. Optional. Can be a region constant or a custom URL string. */
baseURL?: string;
baseURL?: string | Region;
}

export interface PushToken {
Expand Down
12 changes: 7 additions & 5 deletions src/notificationapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ import {
InAppNotificationPatchRequest,
InitConfiguration,
queryLogsPostBody,
US_REGION,
Region,
RetractRequest,
SendRequest,
SetUserPreferencesRequest,
User
} from './interfaces';
} from './interfaces.js';
import axios, { AxiosResponse, Method } from 'axios';
import { createHmac } from 'crypto';

const DEFAULT_BASE_URL = 'https://api.notificationapi.com';

class NotificationAPIService {
private USER_AGENT = 'notificationapi-node-server-sdk';
private VERSION = '2.3.1';
private VERSION = '2.3.2';

clientId: null | string = null;
clientSecret: null | string = null;
baseURL: string = US_REGION;
baseURL: string | Region = DEFAULT_BASE_URL;
/** To configure and initialize the the SDK*/
init = (
clientId: string,
Expand All @@ -37,7 +39,7 @@ class NotificationAPIService {
if (config?.baseURL) {
this.baseURL = config.baseURL;
} else {
this.baseURL = US_REGION;
this.baseURL = DEFAULT_BASE_URL;
}

this.clientId = clientId;
Expand Down