serverless-event-orchestrator 2.2.0 → 2.3.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.
- package/LICENSE +21 -21
- package/README.md +489 -489
- package/dist/dispatcher.d.ts +6 -1
- package/dist/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher.js +31 -7
- package/dist/dispatcher.js.map +1 -1
- package/jest.config.js +32 -32
- package/package.json +82 -81
- package/src/dispatcher.ts +586 -558
- package/src/http/body-parser.ts +60 -60
- package/src/http/cors.ts +76 -76
- package/src/http/index.ts +3 -3
- package/src/http/response.ts +209 -209
- package/src/identity/extractor.ts +207 -207
- package/src/identity/index.ts +2 -2
- package/src/identity/jwt-verifier.ts +41 -41
- package/src/index.ts +128 -128
- package/src/middleware/crm-guard.ts +51 -51
- package/src/middleware/index.ts +3 -3
- package/src/middleware/init-tenant-context.ts +59 -59
- package/src/middleware/tenant-guard.ts +54 -54
- package/src/tenant/TenantContext.ts +115 -115
- package/src/tenant/helpers.ts +112 -112
- package/src/tenant/index.ts +21 -21
- package/src/tenant/types.ts +101 -101
- package/src/types/event-type.enum.ts +21 -21
- package/src/types/index.ts +2 -2
- package/src/types/routes.ts +218 -218
- package/src/utils/headers.ts +72 -72
- package/src/utils/index.ts +2 -2
- package/src/utils/path-matcher.ts +84 -84
- package/tests/cors.test.ts +133 -133
- package/tests/dispatcher.test.ts +795 -715
- package/tests/headers.test.ts +99 -99
- package/tests/identity.test.ts +301 -301
- package/tests/middleware/crm-guard.test.ts +69 -69
- package/tests/middleware/init-tenant-context.test.ts +147 -147
- package/tests/middleware/tenant-guard.test.ts +100 -100
- package/tests/path-matcher.test.ts +102 -102
- package/tests/response.test.ts +155 -155
- package/tests/tenant/TenantContext.test.ts +134 -134
- package/tests/tenant/helpers.test.ts +187 -187
- package/tsconfig.json +24 -24
package/tests/headers.test.ts
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import { normalizeHeaders, getHeader, getCorsHeaders } from '../src/utils/headers';
|
|
2
|
-
|
|
3
|
-
describe('normalizeHeaders', () => {
|
|
4
|
-
it('should convert all header keys to lowercase', () => {
|
|
5
|
-
const headers = {
|
|
6
|
-
'Content-Type': 'application/json',
|
|
7
|
-
'X-Custom-Header': 'value',
|
|
8
|
-
'AUTHORIZATION': 'Bearer token'
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const normalized = normalizeHeaders(headers);
|
|
12
|
-
|
|
13
|
-
expect(normalized['content-type']).toBe('application/json');
|
|
14
|
-
expect(normalized['x-custom-header']).toBe('value');
|
|
15
|
-
expect(normalized['authorization']).toBe('Bearer token');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return empty object for undefined headers', () => {
|
|
19
|
-
expect(normalizeHeaders(undefined)).toEqual({});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should return empty object for empty headers', () => {
|
|
23
|
-
expect(normalizeHeaders({})).toEqual({});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('getHeader', () => {
|
|
28
|
-
const headers = {
|
|
29
|
-
'Content-Type': 'application/json',
|
|
30
|
-
'X-Request-ID': '12345'
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
it('should get header case-insensitively', () => {
|
|
34
|
-
expect(getHeader(headers, 'content-type')).toBe('application/json');
|
|
35
|
-
expect(getHeader(headers, 'Content-Type')).toBe('application/json');
|
|
36
|
-
expect(getHeader(headers, 'CONTENT-TYPE')).toBe('application/json');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should return undefined for missing header', () => {
|
|
40
|
-
expect(getHeader(headers, 'Authorization')).toBeUndefined();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should return undefined for undefined headers', () => {
|
|
44
|
-
expect(getHeader(undefined, 'Content-Type')).toBeUndefined();
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('getCorsHeaders', () => {
|
|
49
|
-
it('should return default CORS headers without config', () => {
|
|
50
|
-
const corsHeaders = getCorsHeaders();
|
|
51
|
-
|
|
52
|
-
expect(corsHeaders['Access-Control-Allow-Origin']).toBe('*');
|
|
53
|
-
expect(corsHeaders['Access-Control-Allow-Methods']).toContain('GET');
|
|
54
|
-
expect(corsHeaders['Access-Control-Allow-Methods']).toContain('POST');
|
|
55
|
-
expect(corsHeaders['Access-Control-Allow-Headers']).toContain('Content-Type');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should use custom origins', () => {
|
|
59
|
-
const corsHeaders = getCorsHeaders({
|
|
60
|
-
origins: ['https://example.com', 'https://app.example.com']
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
expect(corsHeaders['Access-Control-Allow-Origin']).toBe('https://example.com, https://app.example.com');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should use wildcard origin', () => {
|
|
67
|
-
const corsHeaders = getCorsHeaders({ origins: '*' });
|
|
68
|
-
|
|
69
|
-
expect(corsHeaders['Access-Control-Allow-Origin']).toBe('*');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should set credentials header', () => {
|
|
73
|
-
const corsHeaders = getCorsHeaders({ credentials: true });
|
|
74
|
-
|
|
75
|
-
expect(corsHeaders['Access-Control-Allow-Credentials']).toBe('true');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should set max age header', () => {
|
|
79
|
-
const corsHeaders = getCorsHeaders({ maxAge: 86400 });
|
|
80
|
-
|
|
81
|
-
expect(corsHeaders['Access-Control-Max-Age']).toBe('86400');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should use custom methods', () => {
|
|
85
|
-
const corsHeaders = getCorsHeaders({
|
|
86
|
-
methods: ['GET', 'POST']
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
expect(corsHeaders['Access-Control-Allow-Methods']).toBe('GET, POST');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should use custom headers', () => {
|
|
93
|
-
const corsHeaders = getCorsHeaders({
|
|
94
|
-
headers: ['X-Custom-Header', 'X-Another-Header']
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
expect(corsHeaders['Access-Control-Allow-Headers']).toBe('X-Custom-Header, X-Another-Header');
|
|
98
|
-
});
|
|
99
|
-
});
|
|
1
|
+
import { normalizeHeaders, getHeader, getCorsHeaders } from '../src/utils/headers';
|
|
2
|
+
|
|
3
|
+
describe('normalizeHeaders', () => {
|
|
4
|
+
it('should convert all header keys to lowercase', () => {
|
|
5
|
+
const headers = {
|
|
6
|
+
'Content-Type': 'application/json',
|
|
7
|
+
'X-Custom-Header': 'value',
|
|
8
|
+
'AUTHORIZATION': 'Bearer token'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const normalized = normalizeHeaders(headers);
|
|
12
|
+
|
|
13
|
+
expect(normalized['content-type']).toBe('application/json');
|
|
14
|
+
expect(normalized['x-custom-header']).toBe('value');
|
|
15
|
+
expect(normalized['authorization']).toBe('Bearer token');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return empty object for undefined headers', () => {
|
|
19
|
+
expect(normalizeHeaders(undefined)).toEqual({});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should return empty object for empty headers', () => {
|
|
23
|
+
expect(normalizeHeaders({})).toEqual({});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('getHeader', () => {
|
|
28
|
+
const headers = {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
'X-Request-ID': '12345'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
it('should get header case-insensitively', () => {
|
|
34
|
+
expect(getHeader(headers, 'content-type')).toBe('application/json');
|
|
35
|
+
expect(getHeader(headers, 'Content-Type')).toBe('application/json');
|
|
36
|
+
expect(getHeader(headers, 'CONTENT-TYPE')).toBe('application/json');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should return undefined for missing header', () => {
|
|
40
|
+
expect(getHeader(headers, 'Authorization')).toBeUndefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should return undefined for undefined headers', () => {
|
|
44
|
+
expect(getHeader(undefined, 'Content-Type')).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('getCorsHeaders', () => {
|
|
49
|
+
it('should return default CORS headers without config', () => {
|
|
50
|
+
const corsHeaders = getCorsHeaders();
|
|
51
|
+
|
|
52
|
+
expect(corsHeaders['Access-Control-Allow-Origin']).toBe('*');
|
|
53
|
+
expect(corsHeaders['Access-Control-Allow-Methods']).toContain('GET');
|
|
54
|
+
expect(corsHeaders['Access-Control-Allow-Methods']).toContain('POST');
|
|
55
|
+
expect(corsHeaders['Access-Control-Allow-Headers']).toContain('Content-Type');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should use custom origins', () => {
|
|
59
|
+
const corsHeaders = getCorsHeaders({
|
|
60
|
+
origins: ['https://example.com', 'https://app.example.com']
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(corsHeaders['Access-Control-Allow-Origin']).toBe('https://example.com, https://app.example.com');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should use wildcard origin', () => {
|
|
67
|
+
const corsHeaders = getCorsHeaders({ origins: '*' });
|
|
68
|
+
|
|
69
|
+
expect(corsHeaders['Access-Control-Allow-Origin']).toBe('*');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should set credentials header', () => {
|
|
73
|
+
const corsHeaders = getCorsHeaders({ credentials: true });
|
|
74
|
+
|
|
75
|
+
expect(corsHeaders['Access-Control-Allow-Credentials']).toBe('true');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should set max age header', () => {
|
|
79
|
+
const corsHeaders = getCorsHeaders({ maxAge: 86400 });
|
|
80
|
+
|
|
81
|
+
expect(corsHeaders['Access-Control-Max-Age']).toBe('86400');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should use custom methods', () => {
|
|
85
|
+
const corsHeaders = getCorsHeaders({
|
|
86
|
+
methods: ['GET', 'POST']
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(corsHeaders['Access-Control-Allow-Methods']).toBe('GET, POST');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should use custom headers', () => {
|
|
93
|
+
const corsHeaders = getCorsHeaders({
|
|
94
|
+
headers: ['X-Custom-Header', 'X-Another-Header']
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expect(corsHeaders['Access-Control-Allow-Headers']).toBe('X-Custom-Header, X-Another-Header');
|
|
98
|
+
});
|
|
99
|
+
});
|