Skip to content

Commit 2d91852

Browse files
Support api key exposure event (#209)
* feat: Add ApiKeyExposure enums and notification handling * Introduced new enums for ApiKeyExposure including action taken, risk level, and source. * Added ApiKeyExposureNotification class to handle notifications related to API key exposure. * Implemented ApiKeyExposureCreatedEvent for event handling. * Updated relevant index files to export new types and classes. * Enhanced event handling to include ApiKeyExposureCreated events. * test: Add mock for ApiKeyExposureCreated notification * Introduced ApiKeyExposureCreatedMock and ApiKeyExposureCreatedMockExpectation for testing. * Updated notifications-parser tests to include the new ApiKeyExposureCreated mock data. * chore: Update CHANGELOG to include support for `api_key_exposure.created` event * Update CHANGELOG.md Co-authored-by: davidgrayston-paddle <david.grayston@paddle.com> --------- Co-authored-by: davidgrayston-paddle <david.grayston@paddle.com>
1 parent 8800133 commit 2d91852

File tree

20 files changed

+184
-0
lines changed

20 files changed

+184
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ adding additional type guards.
2525
### Added
2626

2727
- Added support for `wechat_pay` payment method.
28+
- Added support for `api_key_exposure.created` event. See [related changelog](https://developer.paddle.com/api-reference/about/api-keys?utm_source=dx&utm_medium=paddle-node-sdk#secret-scanning).
2829

2930
---
3031

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
import { type IEventsResponse } from '../../../types/index.js';
8+
import { IApiKeyExposureNotificationResponse } from '../../../notifications/index.js';
9+
10+
export const ApiKeyExposureCreatedMock: IEventsResponse<IApiKeyExposureNotificationResponse> = {
11+
event_id: 'evt_01jkdr0rc527wcjdg1txsdxhtg',
12+
event_type: 'api_key_exposure.created',
13+
occurred_at: '2025-06-24T12:58:38.746382Z',
14+
notification_id: 'ntf_01jkdr1mgbe62eqkh3p0fq8b0w',
15+
data: {
16+
id: 'apikeyexp_01jkdpbhazdpn3wpcya45as9tg',
17+
api_key_id: 'apikey_01jkdpbhazdpn3wpcya45as9tg',
18+
risk_level: 'high',
19+
action_taken: 'revoked',
20+
source: 'github',
21+
reference: 'https://github.com/example/repo/blob/main/config.js',
22+
description: 'API key found exposed in public GitHub repository.',
23+
created_at: '2025-06-24T12:58:38.746382Z',
24+
},
25+
};
26+
27+
export const ApiKeyExposureCreatedMockExpectation = {
28+
eventId: 'evt_01jkdr0rc527wcjdg1txsdxhtg',
29+
eventType: 'api_key_exposure.created',
30+
occurredAt: '2025-06-24T12:58:38.746382Z',
31+
notificationId: 'ntf_01jkdr1mgbe62eqkh3p0fq8b0w',
32+
data: {
33+
id: 'apikeyexp_01jkdpbhazdpn3wpcya45as9tg',
34+
apiKeyId: 'apikey_01jkdpbhazdpn3wpcya45as9tg',
35+
riskLevel: 'high',
36+
actionTaken: 'revoked',
37+
source: 'github',
38+
reference: 'https://github.com/example/repo/blob/main/config.js',
39+
description: 'API key found exposed in public GitHub repository.',
40+
createdAt: '2025-06-24T12:58:38.746382Z',
41+
},
42+
};

src/__tests__/notifications/notifications-parser.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import { ApiKeyExpiredMock, ApiKeyExpiredMockExpectation } from '../mocks/notifi
1414
import { ApiKeyRevokedMock, ApiKeyRevokedMockExpectation } from '../mocks/notifications/api-key-revoked.mock.js';
1515
import { ApiKeyExpiringMock, ApiKeyExpiringMockExpectation } from '../mocks/notifications/api-key-expiring.mock.js';
1616
import { ApiKeyUpdatedMock, ApiKeyUpdatedMockExpectation } from '../mocks/notifications/api-key-updated.mock.js';
17+
import {
18+
ApiKeyExposureCreatedMock,
19+
ApiKeyExposureCreatedMockExpectation,
20+
} from '../mocks/notifications/api-key-exposure-created.mock.js';
1721
import { BusinessCreatedMock, BusinessCreatedMockExpectation } from '../mocks/notifications/business-created.mock.js';
1822
import { BusinessUpdatedMock, BusinessUpdatedMockExpectation } from '../mocks/notifications/business-updated.mock.js';
1923
import {
@@ -159,6 +163,7 @@ describe('Notifications Parser', () => {
159163
[ApiKeyExpiringMock.event_type, ApiKeyExpiringMock, ApiKeyExpiringMockExpectation],
160164
[ApiKeyRevokedMock.event_type, ApiKeyRevokedMock, ApiKeyRevokedMockExpectation],
161165
[ApiKeyUpdatedMock.event_type, ApiKeyUpdatedMock, ApiKeyUpdatedMockExpectation],
166+
[ApiKeyExposureCreatedMock.event_type, ApiKeyExposureCreatedMock, ApiKeyExposureCreatedMockExpectation],
162167
[BusinessCreatedMock.event_type, BusinessCreatedMock, BusinessCreatedMockExpectation],
163168
[BusinessUpdatedMock.event_type, BusinessUpdatedMock, BusinessUpdatedMockExpectation],
164169
[BusinessImportedMock.event_type, BusinessImportedMock, BusinessImportedMockExpectation],
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
export type ApiKeyExposureActionTaken = 'revoked' | 'none';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
export * from './risk-level.js';
8+
export * from './action-taken.js';
9+
export * from './source.js';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
export type ApiKeyExposureRiskLevel = 'high' | 'low';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
export type ApiKeyExposureSource = 'github';

src/enums/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ export * from './simulation/index.js';
1919
export * from './simulation-run/index.js';
2020
export * from './simulation-run-event/index.js';
2121
export * from './api-key/index.js';
22+
export * from './api-key-exposure/index.js';
2223
export * from './client-tokens/index.js';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
import { IApiKeyExposureNotificationResponse } from '../../types/index.js';
7+
import { ApiKeyExposureRiskLevel, ApiKeyExposureActionTaken, ApiKeyExposureSource } from '../../../enums/index.js';
8+
9+
export class ApiKeyExposureNotification {
10+
public readonly id: string;
11+
public readonly apiKeyId: string;
12+
public readonly riskLevel: ApiKeyExposureRiskLevel;
13+
public readonly actionTaken: ApiKeyExposureActionTaken;
14+
public readonly source: ApiKeyExposureSource;
15+
public readonly reference: string;
16+
public readonly description: string | null;
17+
public readonly createdAt: string;
18+
19+
constructor(apiKeyExposure: IApiKeyExposureNotificationResponse) {
20+
this.id = apiKeyExposure.id;
21+
this.apiKeyId = apiKeyExposure.api_key_id;
22+
this.riskLevel = apiKeyExposure.risk_level;
23+
this.actionTaken = apiKeyExposure.action_taken;
24+
this.source = apiKeyExposure.source;
25+
this.reference = apiKeyExposure.reference;
26+
this.description = apiKeyExposure.description ?? null;
27+
this.createdAt = apiKeyExposure.created_at;
28+
}
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* ! Autogenerated code !
3+
* Do not make changes to this file.
4+
* Changes may be overwritten as part of auto-generation.
5+
*/
6+
7+
export * from './api-key-exposure-notification.js';

0 commit comments

Comments
 (0)