Skip to content

Commit 00aa66a

Browse files
authored
Merge pull request #32 from notificationapi-com/tqLKwvhB/2053-query-log
add query log
2 parents f814549 + f1bce1b commit 00aa66a

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notificationapi-node-server-sdk",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "NotificationAPI server-side library for Node.js",
55
"keywords": [
66
"notificationapi",

src/__tests__/notificationapi.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
CreateSubNotificationRequest,
99
DeleteSubNotificationRequest,
1010
InAppNotificationPatchRequest,
11+
queryLogsPostBody,
1112
PushProviders,
1213
SendRequest,
1314
SetUserPreferencesRequest,
@@ -317,6 +318,46 @@ describe('send', () => {
317318
);
318319
});
319320
});
321+
describe('queryLogs', () => {
322+
const queryLogsEndPointRegex = /.*\/logs\/query/;
323+
const clientId = 'testClientId';
324+
const clientSecret = 'testClientSecret';
325+
326+
test('makes API calls to the correct end-point, non custom', async () => {
327+
const nonCostumeQuery: queryLogsPostBody = {
328+
dateRangeFilter: { startTime: 1715904000000, endTime: 1718668799999 },
329+
notificationFilter: ['test'],
330+
channelFilter: [Channels.CALL],
331+
userFilter: ['[email protected]'],
332+
statusFilter: ['FAILURE'],
333+
trackingIds: ['e2d6987f-52c'],
334+
envIdFilter: [clientId]
335+
};
336+
axiosMock.onPost(queryLogsEndPointRegex).reply(200);
337+
notificationapi.init(clientId, clientSecret);
338+
await notificationapi.queryLogs(nonCostumeQuery);
339+
expect(axiosMock.history.post).toHaveLength(1);
340+
expect(axiosMock.history.post[0].url).toEqual(
341+
`https://api.notificationapi.com/${clientId}/logs/query`
342+
);
343+
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual(nonCostumeQuery);
344+
});
345+
test('makes API calls to the correct end-point, custom', async () => {
346+
const nonCostumeQuery: queryLogsPostBody = {
347+
dateRangeFilter: { startTime: 1715904000000, endTime: 1718668799999 },
348+
customFilter:
349+
'fields @message| filter @logStream like /NotificationsSummary/| sort @timestamp desc'
350+
};
351+
axiosMock.onPost(queryLogsEndPointRegex).reply(200);
352+
notificationapi.init(clientId, clientSecret);
353+
await notificationapi.queryLogs(nonCostumeQuery);
354+
expect(axiosMock.history.post).toHaveLength(1);
355+
expect(axiosMock.history.post[0].url).toEqual(
356+
`https://api.notificationapi.com/${clientId}/logs/query`
357+
);
358+
expect(JSON.parse(axiosMock.history.post[0].data)).toEqual(nonCostumeQuery);
359+
});
360+
});
320361

321362
describe('retract by secondaryId', () => {
322363
const retractEndPointRegex = /.*\/sender\/retract/;

src/interfaces.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,17 @@ export interface InAppNotificationPatchRequest {
167167
message: string;
168168
};
169169
}
170+
export interface queryLogsPostBody {
171+
dateRangeFilter?: {
172+
startTime?: number;
173+
endTime?: number;
174+
};
175+
notificationFilter?: string[];
176+
channelFilter?: Channels[];
177+
userFilter?: string[];
178+
statusFilter?: string[];
179+
trackingIds?: string[];
180+
requestFilter?: string[];
181+
envIdFilter?: string[];
182+
customFilter?: string;
183+
}

src/notificationapi.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
DeleteSubNotificationRequest,
44
InAppNotificationPatchRequest,
55
InitConfiguration,
6+
queryLogsPostBody,
67
RetractRequest,
78
SendRequest,
89
SetUserPreferencesRequest,
@@ -15,7 +16,7 @@ const DEFAULT_BASE_URL = 'https://api.notificationapi.com';
1516

1617
class NotificationAPIService {
1718
private USER_AGENT = 'notificationapi-node-server-sdk';
18-
private VERSION = '2.1.0';
19+
private VERSION = '2.2.0';
1920

2021
clientId: null | string = null;
2122
clientSecret: null | string = null;
@@ -69,6 +70,10 @@ class NotificationAPIService {
6970
retract = async (retractRequest: RetractRequest): Promise<AxiosResponse> => {
7071
return this.request('POST', 'sender/retract', retractRequest);
7172
};
73+
/** create a query on logs */
74+
queryLogs = async (params: queryLogsPostBody): Promise<AxiosResponse> => {
75+
return this.request('POST', 'logs/query', params);
76+
};
7277
/** Used to create a subNotification of a specified notification. */
7378
createSubNotification = async (
7479
params: CreateSubNotificationRequest

0 commit comments

Comments
 (0)