chargebee 3.17.0-beta.2 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +0,0 @@
1
- export const basicAuthValidator = (validateCredentials) => {
2
- return (headers) => {
3
- const authHeader = headers['authorization'] || headers['Authorization'];
4
- if (!authHeader) {
5
- throw new Error('Invalid authorization header');
6
- }
7
- const authStr = Array.isArray(authHeader) ? authHeader[0] : authHeader;
8
- if (!authStr) {
9
- throw new Error('Invalid authorization header');
10
- }
11
- const parts = authStr.split(' ');
12
- if (parts.length !== 2 || parts[0] !== 'Basic') {
13
- throw new Error('Invalid authorization header');
14
- }
15
- const credentials = Buffer.from(parts[1], 'base64').toString().split(':');
16
- if (credentials.length !== 2) {
17
- throw new Error('Invalid credentials');
18
- }
19
- if (!validateCredentials(credentials[0], credentials[1])) {
20
- throw new Error('Invalid credentials');
21
- }
22
- };
23
- };
@@ -1,2 +0,0 @@
1
- ///<reference path='../../../types/index.d.ts'/>
2
- export {};
@@ -1,35 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { basicAuthValidator } from './auth.js';
3
- import { WebhookEventType, WebhookContentType } from './eventType.js';
4
- export { WebhookEventType, WebhookContentType };
5
- export class WebhookHandler extends EventEmitter {
6
- constructor() {
7
- super({ captureRejections: true });
8
- }
9
- handle(body, headers) {
10
- try {
11
- if (this.requestValidator && headers) {
12
- this.requestValidator(headers);
13
- }
14
- const event = typeof body === 'string' ? JSON.parse(body) : body;
15
- const eventType = event.event_type;
16
- if (this.listenerCount(eventType) > 0) {
17
- this.emit(eventType, event);
18
- }
19
- else {
20
- this.emit('unhandled_event', event);
21
- }
22
- }
23
- catch (err) {
24
- this.emit('error', err instanceof Error ? err : new Error(String(err)));
25
- }
26
- }
27
- }
28
- const webhook = new WebhookHandler();
29
- // Auto-configure basic auth if env vars are present
30
- const username = process.env.CHARGEBEE_WEBHOOK_USERNAME;
31
- const password = process.env.CHARGEBEE_WEBHOOK_PASSWORD;
32
- if (username && password) {
33
- webhook.requestValidator = basicAuthValidator((u, p) => u === username && p === password);
34
- }
35
- export default webhook;