@bernierllc/contentful-webhook-handler 1.0.3
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.
- package/.eslintrc.cjs +36 -0
- package/LICENSE.md +9 -0
- package/README.md +385 -0
- package/dist/ContentfulWebhookHandler.d.ts +71 -0
- package/dist/ContentfulWebhookHandler.js +213 -0
- package/dist/__tests__/ContentfulWebhookHandler.test.d.ts +1 -0
- package/dist/__tests__/ContentfulWebhookHandler.test.js +576 -0
- package/dist/__tests__/index.test.d.ts +1 -0
- package/dist/__tests__/index.test.js +62 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -0
- package/jest.config.cjs +33 -0
- package/package.json +45 -0
- package/src/ContentfulWebhookHandler.ts +260 -0
- package/src/__tests__/ContentfulWebhookHandler.test.ts +682 -0
- package/src/__tests__/index.test.ts +78 -0
- package/src/index.ts +21 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
ContentfulWebhookHandler,
|
|
11
|
+
type WebhookValidationResult,
|
|
12
|
+
type EventType,
|
|
13
|
+
type ContentfulWebhookHandlerOptions,
|
|
14
|
+
type ContentfulWebhookTopic,
|
|
15
|
+
type ContentfulWebhookHeaders,
|
|
16
|
+
type ContentfulWebhookPayload
|
|
17
|
+
} from '../index';
|
|
18
|
+
|
|
19
|
+
describe('index exports', () => {
|
|
20
|
+
it('should export ContentfulWebhookHandler class', () => {
|
|
21
|
+
expect(ContentfulWebhookHandler).toBeDefined();
|
|
22
|
+
expect(typeof ContentfulWebhookHandler).toBe('function');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should create a ContentfulWebhookHandler instance', () => {
|
|
26
|
+
const handler = new ContentfulWebhookHandler({
|
|
27
|
+
webhookSecret: 'test-secret'
|
|
28
|
+
});
|
|
29
|
+
expect(handler).toBeInstanceOf(ContentfulWebhookHandler);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should export type definitions', () => {
|
|
33
|
+
// Type check - these should compile
|
|
34
|
+
const payload: ContentfulWebhookPayload = {
|
|
35
|
+
sys: {
|
|
36
|
+
type: 'Entry',
|
|
37
|
+
id: 'test',
|
|
38
|
+
space: {
|
|
39
|
+
sys: { type: 'Link', linkType: 'Space', id: 'space' }
|
|
40
|
+
},
|
|
41
|
+
environment: {
|
|
42
|
+
sys: { type: 'Link', linkType: 'Environment', id: 'master' }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const validationResult: WebhookValidationResult = {
|
|
48
|
+
valid: true,
|
|
49
|
+
payload,
|
|
50
|
+
topic: 'Entry.publish'
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const eventType: EventType = {
|
|
54
|
+
resource: 'Entry',
|
|
55
|
+
action: 'publish'
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const options: ContentfulWebhookHandlerOptions = {
|
|
59
|
+
webhookSecret: 'test'
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const topic: ContentfulWebhookTopic = 'Entry.publish';
|
|
63
|
+
|
|
64
|
+
const headers: ContentfulWebhookHeaders = {
|
|
65
|
+
'x-contentful-signature': 'sig',
|
|
66
|
+
'x-contentful-topic': 'Entry.publish',
|
|
67
|
+
'x-contentful-webhook-name': 'test',
|
|
68
|
+
'x-contentful-crn': 'crn:test'
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// If these compile, the types are exported correctly
|
|
72
|
+
expect(validationResult).toBeDefined();
|
|
73
|
+
expect(eventType).toBeDefined();
|
|
74
|
+
expect(options).toBeDefined();
|
|
75
|
+
expect(topic).toBeDefined();
|
|
76
|
+
expect(headers).toBeDefined();
|
|
77
|
+
});
|
|
78
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
ContentfulWebhookHandler,
|
|
11
|
+
WebhookValidationResult,
|
|
12
|
+
EventType,
|
|
13
|
+
ContentfulWebhookHandlerOptions
|
|
14
|
+
} from './ContentfulWebhookHandler';
|
|
15
|
+
|
|
16
|
+
// Re-export commonly used types from contentful-types
|
|
17
|
+
export type {
|
|
18
|
+
ContentfulWebhookPayload,
|
|
19
|
+
ContentfulWebhookTopic,
|
|
20
|
+
ContentfulWebhookHeaders
|
|
21
|
+
} from '@bernierllc/contentful-types';
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"moduleResolution": "node",
|
|
15
|
+
"noUnusedLocals": true,
|
|
16
|
+
"noUnusedParameters": true,
|
|
17
|
+
"noImplicitReturns": true,
|
|
18
|
+
"noFallthroughCasesInSwitch": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*"],
|
|
21
|
+
"exclude": ["node_modules", "dist"]
|
|
22
|
+
}
|