Skip to content

Commit

Permalink
Merge pull request #32 from notificationapi-com/tqLKwvhB/2053-query-log
Browse files Browse the repository at this point in the history
add query log
  • Loading branch information
mbasadi authored Jun 24, 2024
2 parents f814549 + f1bce1b commit 00aa66a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notificationapi-node-server-sdk",
"version": "2.1.0",
"version": "2.2.0",
"description": "NotificationAPI server-side library for Node.js",
"keywords": [
"notificationapi",
Expand Down
41 changes: 41 additions & 0 deletions src/__tests__/notificationapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CreateSubNotificationRequest,
DeleteSubNotificationRequest,
InAppNotificationPatchRequest,
queryLogsPostBody,
PushProviders,
SendRequest,
SetUserPreferencesRequest,
Expand Down Expand Up @@ -317,6 +318,46 @@ describe('send', () => {
);
});
});
describe('queryLogs', () => {
const queryLogsEndPointRegex = /.*\/logs\/query/;
const clientId = 'testClientId';
const clientSecret = 'testClientSecret';

test('makes API calls to the correct end-point, non custom', async () => {
const nonCostumeQuery: queryLogsPostBody = {
dateRangeFilter: { startTime: 1715904000000, endTime: 1718668799999 },
notificationFilter: ['test'],
channelFilter: [Channels.CALL],
userFilter: ['[email protected]'],
statusFilter: ['FAILURE'],
trackingIds: ['e2d6987f-52c'],
envIdFilter: [clientId]
};
axiosMock.onPost(queryLogsEndPointRegex).reply(200);
notificationapi.init(clientId, clientSecret);
await notificationapi.queryLogs(nonCostumeQuery);
expect(axiosMock.history.post).toHaveLength(1);
expect(axiosMock.history.post[0].url).toEqual(
`https://api.notificationapi.com/${clientId}/logs/query`
);
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual(nonCostumeQuery);
});
test('makes API calls to the correct end-point, custom', async () => {
const nonCostumeQuery: queryLogsPostBody = {
dateRangeFilter: { startTime: 1715904000000, endTime: 1718668799999 },
customFilter:
'fields @message| filter @logStream like /NotificationsSummary/| sort @timestamp desc'
};
axiosMock.onPost(queryLogsEndPointRegex).reply(200);
notificationapi.init(clientId, clientSecret);
await notificationapi.queryLogs(nonCostumeQuery);
expect(axiosMock.history.post).toHaveLength(1);
expect(axiosMock.history.post[0].url).toEqual(
`https://api.notificationapi.com/${clientId}/logs/query`
);
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual(nonCostumeQuery);
});
});

describe('retract by secondaryId', () => {
const retractEndPointRegex = /.*\/sender\/retract/;
Expand Down
14 changes: 14 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,17 @@ export interface InAppNotificationPatchRequest {
message: string;
};
}
export interface queryLogsPostBody {
dateRangeFilter?: {
startTime?: number;
endTime?: number;
};
notificationFilter?: string[];
channelFilter?: Channels[];
userFilter?: string[];
statusFilter?: string[];
trackingIds?: string[];
requestFilter?: string[];
envIdFilter?: string[];
customFilter?: string;
}
7 changes: 6 additions & 1 deletion src/notificationapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DeleteSubNotificationRequest,
InAppNotificationPatchRequest,
InitConfiguration,
queryLogsPostBody,
RetractRequest,
SendRequest,
SetUserPreferencesRequest,
Expand All @@ -15,7 +16,7 @@ const DEFAULT_BASE_URL = 'https://api.notificationapi.com';

class NotificationAPIService {
private USER_AGENT = 'notificationapi-node-server-sdk';
private VERSION = '2.1.0';
private VERSION = '2.2.0';

clientId: null | string = null;
clientSecret: null | string = null;
Expand Down Expand Up @@ -69,6 +70,10 @@ class NotificationAPIService {
retract = async (retractRequest: RetractRequest): Promise<AxiosResponse> => {
return this.request('POST', 'sender/retract', retractRequest);
};
/** create a query on logs */
queryLogs = async (params: queryLogsPostBody): Promise<AxiosResponse> => {
return this.request('POST', 'logs/query', params);
};
/** Used to create a subNotification of a specified notification. */
createSubNotification = async (
params: CreateSubNotificationRequest
Expand Down

0 comments on commit 00aa66a

Please sign in to comment.