Skip to content

Commit 5751b0a

Browse files
feat: add support for getBounceMetrics (#84)
Signed-off-by: nitish <nitish.kulkarni3@ibm.com> Co-authored-by: Nitish-Kulkarni3 <nitish.kulkarni3@ibm.com>
1 parent 014ca9d commit 5751b0a

6 files changed

Lines changed: 384 additions & 4 deletions

File tree

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "package-lock.json|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2025-10-28T09:15:04Z",
6+
"generated_at": "2025-12-09T16:56:26Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ SDK Methods to consume
146146
- [Delete SMTP Configuration](#delete-smtp-user)
147147
- [Verify SMTP](#verify-smtp)
148148
- [Metrics](#Metrics)
149-
- [Get Metrics](#get-metrics)
149+
- [Get Metrics](#get-metrics)
150+
- [Get Bounce Metrics](#get-bounce-metrics)
150151
- [Send Notifications](#send-notifications)
151152

152153
## Source
@@ -1468,6 +1469,8 @@ const getMetricsParams = {
14681469
gte: <gte-timestamp>,
14691470
lte: <lte-timestamp>,
14701471
destinationId: <destination-id>,
1472+
subscriptionId: <subscription-id>,
1473+
sourceId: <source-id>,
14711474
emailTo: <email-to>,
14721475
notificationId: <notification-id>,
14731476
subject: <subject>,
@@ -1481,6 +1484,30 @@ try {
14811484
}
14821485
```
14831486
1487+
### Get Bounce Metrics
1488+
1489+
```js
1490+
const getBounceMetricsParams = {
1491+
instanceId: <instance-id>,
1492+
destinationType: 'smtp_custom',
1493+
gte: <gte-timestamp>,
1494+
lte: <lte-timestamp>,
1495+
destinationId: <destination-id>,
1496+
subscriptionId: <subscription-id>,
1497+
sourceId: <source-id>,
1498+
emailTo: <email-to>,
1499+
notificationId: <notification-id>,
1500+
subject: <subject>,
1501+
};
1502+
1503+
try {
1504+
const res = await eventNotificationsService.getBounceMetrics(getBounceMetricsParams);
1505+
console.log(JSON.stringify(res.result, null, 2));
1506+
} catch (err) {
1507+
console.warn(err);
1508+
}
1509+
```
1510+
14841511
## Send Notifications
14851512
14861513
```js

event-notifications/v1.ts

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class EventNotificationsV1 extends BaseService {
112112
* @param {string} params.gte - GTE (greater than equal), start timestamp in UTC.
113113
* @param {string} params.lte - LTE (less than equal), end timestamp in UTC.
114114
* @param {string} [params.destinationId] - Unique identifier for Destination.
115+
* @param {string} [params.subscriptionId] - Unique identifier for Subscription.
115116
* @param {string} [params.sourceId] - Unique identifier for Source.
116117
* @param {string} [params.emailTo] - Receiver email id.
117118
* @param {string} [params.notificationId] - Notification Id.
@@ -130,6 +131,7 @@ class EventNotificationsV1 extends BaseService {
130131
'gte',
131132
'lte',
132133
'destinationId',
134+
'subscriptionId',
133135
'sourceId',
134136
'emailTo',
135137
'notificationId',
@@ -146,6 +148,7 @@ class EventNotificationsV1 extends BaseService {
146148
'gte': _params.gte,
147149
'lte': _params.lte,
148150
'destination_id': _params.destinationId,
151+
'subscription_id': _params.subscriptionId,
149152
'source_id': _params.sourceId,
150153
'email_to': _params.emailTo,
151154
'notification_id': _params.notificationId,
@@ -179,6 +182,98 @@ class EventNotificationsV1 extends BaseService {
179182

180183
return this.createRequest(parameters);
181184
}
185+
186+
/**
187+
* Get bounce metrics.
188+
*
189+
* Get bounce metrics.
190+
*
191+
* @param {Object} params - The parameters to send to the service.
192+
* @param {string} params.instanceId - Unique identifier for IBM Cloud Event Notifications instance.
193+
* @param {string} params.destinationType - Destination type. Allowed values are [smtp_custom].
194+
* @param {string} params.gte - GTE (greater than equal), start timestamp in UTC.
195+
* @param {string} params.lte - LTE (less than equal), end timestamp in UTC.
196+
* @param {string} [params.destinationId] - Unique identifier for Destination.
197+
* @param {string} [params.subscriptionId] - Unique identifier for Subscription.
198+
* @param {string} [params.sourceId] - Unique identifier for Source.
199+
* @param {string} [params.emailTo] - Receiver email id.
200+
* @param {string} [params.notificationId] - Notification Id.
201+
* @param {string} [params.subject] - Email subject.
202+
* @param {number} [params.limit] - Page limit for paginated results.
203+
* @param {number} [params.offset] - offset for paginated results.
204+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
205+
* @returns {Promise<EventNotificationsV1.Response<EventNotificationsV1.BounceMetrics>>}
206+
*/
207+
public getBounceMetrics(
208+
params: EventNotificationsV1.GetBounceMetricsParams
209+
): Promise<EventNotificationsV1.Response<EventNotificationsV1.BounceMetrics>> {
210+
const _params = { ...params };
211+
const _requiredParams = ['instanceId', 'destinationType', 'gte', 'lte'];
212+
const _validParams = [
213+
'instanceId',
214+
'destinationType',
215+
'gte',
216+
'lte',
217+
'destinationId',
218+
'subscriptionId',
219+
'sourceId',
220+
'emailTo',
221+
'notificationId',
222+
'subject',
223+
'limit',
224+
'offset',
225+
'headers',
226+
];
227+
const _validationErrors = validateParams(_params, _requiredParams, _validParams);
228+
if (_validationErrors) {
229+
return Promise.reject(_validationErrors);
230+
}
231+
232+
const query = {
233+
'destination_type': _params.destinationType,
234+
'gte': _params.gte,
235+
'lte': _params.lte,
236+
'destination_id': _params.destinationId,
237+
'subscription_id': _params.subscriptionId,
238+
'source_id': _params.sourceId,
239+
'email_to': _params.emailTo,
240+
'notification_id': _params.notificationId,
241+
'subject': _params.subject,
242+
'limit': _params.limit,
243+
'offset': _params.offset,
244+
};
245+
246+
const path = {
247+
'instance_id': _params.instanceId,
248+
};
249+
250+
const sdkHeaders = getSdkHeaders(
251+
EventNotificationsV1.DEFAULT_SERVICE_NAME,
252+
'v1',
253+
'getBounceMetrics'
254+
);
255+
256+
const parameters = {
257+
options: {
258+
url: '/v1/instances/{instance_id}/metrics/bounce',
259+
method: 'GET',
260+
qs: query,
261+
path,
262+
},
263+
defaultOptions: extend(true, {}, this.baseOptions, {
264+
headers: extend(
265+
true,
266+
sdkHeaders,
267+
{
268+
'Accept': 'application/json',
269+
},
270+
_params.headers
271+
),
272+
}),
273+
};
274+
275+
return this.createRequest(parameters);
276+
}
182277
/*************************
183278
* sendNotifications
184279
************************/
@@ -3391,6 +3486,8 @@ namespace EventNotificationsV1 {
33913486
lte: string;
33923487
/** Unique identifier for Destination. */
33933488
destinationId?: string;
3489+
/** Unique identifier for Subscription. */
3490+
subscriptionId?: string;
33943491
/** Unique identifier for Source. */
33953492
sourceId?: string;
33963493
/** Receiver email id. */
@@ -3410,6 +3507,43 @@ namespace EventNotificationsV1 {
34103507
}
34113508
}
34123509

3510+
/** Parameters for the `getBounceMetrics` operation. */
3511+
export interface GetBounceMetricsParams {
3512+
/** Unique identifier for IBM Cloud Event Notifications instance. */
3513+
instanceId: string;
3514+
/** Destination type. Allowed values are [smtp_custom]. */
3515+
destinationType: GetBounceMetricsConstants.DestinationType | string;
3516+
/** GTE (greater than equal), start timestamp in UTC. */
3517+
gte: string;
3518+
/** LTE (less than equal), end timestamp in UTC. */
3519+
lte: string;
3520+
/** Unique identifier for Destination. */
3521+
destinationId?: string;
3522+
/** Unique identifier for Subscription. */
3523+
subscriptionId?: string;
3524+
/** Unique identifier for Source. */
3525+
sourceId?: string;
3526+
/** Receiver email id. */
3527+
emailTo?: string;
3528+
/** Notification Id. */
3529+
notificationId?: string;
3530+
/** Email subject. */
3531+
subject?: string;
3532+
/** Page limit for paginated results. */
3533+
limit?: number;
3534+
/** offset for paginated results. */
3535+
offset?: number;
3536+
headers?: OutgoingHttpHeaders;
3537+
}
3538+
3539+
/** Constants for the `getBounceMetrics` operation. */
3540+
export namespace GetBounceMetricsConstants {
3541+
/** Destination type. Allowed values are [smtp_custom]. */
3542+
export enum DestinationType {
3543+
SMTP_CUSTOM = 'smtp_custom',
3544+
}
3545+
}
3546+
34133547
/** Parameters for the `sendNotifications` operation. */
34143548
export interface SendNotificationsParams {
34153549
/** Unique identifier for IBM Cloud Event Notifications instance. */
@@ -4114,6 +4248,30 @@ namespace EventNotificationsV1 {
41144248
* model interfaces
41154249
************************/
41164250

4251+
/** Bounce metric object. */
4252+
export interface BounceMetricItem {
4253+
/** Email address. */
4254+
email_address: string;
4255+
/** Subject. */
4256+
subject: string;
4257+
/** Error message. */
4258+
error_message: string;
4259+
/** IP address. */
4260+
ip_address?: string;
4261+
/** Subscription ID. */
4262+
subscription_id?: string;
4263+
/** Bounced at. */
4264+
timestamp: string;
4265+
}
4266+
4267+
/** Payload describing bounce metrics. */
4268+
export interface BounceMetrics {
4269+
/** array of bounce metrics. */
4270+
metrics: BounceMetricItem[];
4271+
/** total number of bounce metrics. */
4272+
total_count: number;
4273+
}
4274+
41174275
/** Bucket object. */
41184276
export interface Buckets {
41194277
/** Total count. */

examples/event-notifications.v1.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,8 @@ describe('EventNotificationsV1', () => {
30843084
gte,
30853085
lte,
30863086
destinationId: destinationId16,
3087+
subscriptionId: subscriptionId6,
3088+
sourceId,
30873089
emailTo: email_to,
30883090
notificationId: notificationID,
30893091
subject,
@@ -3098,6 +3100,45 @@ describe('EventNotificationsV1', () => {
30983100
// end-metrics
30993101
});
31003102

3103+
test('getBounceMetrics request example', async () => {
3104+
consoleLogMock.mockImplementation((output) => {
3105+
originalLog(output);
3106+
});
3107+
consoleWarnMock.mockImplementation((output) => {
3108+
// if an error occurs, display the message and then fail the test
3109+
originalWarn(output);
3110+
expect(true).toBeFalsy();
3111+
});
3112+
3113+
originalLog('getBounceMetrics() result:');
3114+
// begin-bounce-metrics
3115+
const destination_type = 'smtp_custom';
3116+
const gte = '2025-12-08T17:18:43Z';
3117+
const lte = '2025-12-09T17:18:43Z';
3118+
const email_to = 'testuser@in.ibm.com';
3119+
const subject = 'Test Metrics Subject';
3120+
const getBounceMetricsParams = {
3121+
instanceId,
3122+
destinationType: destination_type,
3123+
gte,
3124+
lte,
3125+
destinationId: destinationId16,
3126+
subscriptionId: subscriptionId6,
3127+
sourceId,
3128+
emailTo: email_to,
3129+
notificationId: notificationID,
3130+
subject,
3131+
};
3132+
3133+
try {
3134+
const res = await eventNotificationsService.getBounceMetrics(getBounceMetricsParams);
3135+
console.log(JSON.stringify(res.result, null, 2));
3136+
} catch (err) {
3137+
console.warn(err);
3138+
}
3139+
// end-bounce-metrics
3140+
});
3141+
31013142
test('createSMTPConfiguration request example', async () => {
31023143
consoleLogMock.mockImplementation((output) => {
31033144
originalLog(output);

test/integration/event-notifications.v1.test.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3434,8 +3434,8 @@ describe('EventNotificationsV1_integration', () => {
34343434

34353435
test('getMetrics()', async () => {
34363436
const destination_type = 'smtp_custom';
3437-
const gte = '2024-08-01T17:18:43Z';
3438-
const lte = '2024-08-02T11:55:22Z';
3437+
const gte = '2025-12-08T17:18:43Z';
3438+
const lte = '2025-12-09T11:55:22Z';
34393439
const email_to = 'testuser@in.ibm.com';
34403440
const subject = 'Test Metrics Subject';
34413441
const getMetricsParams = {
@@ -3444,6 +3444,8 @@ describe('EventNotificationsV1_integration', () => {
34443444
gte,
34453445
lte,
34463446
destinationId: destinationId16,
3447+
subscriptionId: subscriptionId16,
3448+
sourceId,
34473449
emailTo: email_to,
34483450
notificationId: notificationID,
34493451
subject,
@@ -3455,6 +3457,31 @@ describe('EventNotificationsV1_integration', () => {
34553457
expect(res.result).toBeDefined();
34563458
});
34573459

3460+
test('getBounceMetrics()', async () => {
3461+
const destination_type = 'smtp_custom';
3462+
const gte = '2025-12-08T17:18:43Z';
3463+
const lte = '2025-12-09T11:55:22Z';
3464+
const email_to = 'testuser@in.ibm.com';
3465+
const subject = 'Test Metrics Subject';
3466+
const getBounceMetricsParams = {
3467+
instanceId,
3468+
destinationType: destination_type,
3469+
gte,
3470+
lte,
3471+
destinationId: destinationId16,
3472+
subscriptionId: subscriptionId16,
3473+
sourceId,
3474+
emailTo: email_to,
3475+
notificationId: notificationID,
3476+
subject,
3477+
};
3478+
3479+
const res = await eventNotificationsService.getBounceMetrics(getBounceMetricsParams);
3480+
expect(res).toBeDefined();
3481+
expect(res.status).toBe(200);
3482+
expect(res.result).toBeDefined();
3483+
});
3484+
34583485
test('createSMTPConfiguration()', async () => {
34593486
const name = 'SMTP Configuration';
34603487
const domain = 'test.event-notifications.test.cloud.ibm.com';

0 commit comments

Comments
 (0)