lambder 2.0.18 → 3.0.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/Readme.md +162 -41
- package/dist/Lambder.d.ts +154 -46
- package/dist/Lambder.js +312 -166
- package/dist/LambderCaller.js +6 -3
- package/dist/LambderContext.d.ts +20 -9
- package/dist/LambderContext.js +57 -17
- package/dist/LambderCors.d.ts +12 -0
- package/dist/LambderCors.js +30 -0
- package/dist/LambderHtml.d.ts +33 -0
- package/dist/LambderHtml.js +62 -0
- package/dist/LambderMSW.d.ts +16 -1
- package/dist/LambderMSW.js +5 -9
- package/dist/LambderPublicFiles.d.ts +47 -0
- package/dist/LambderPublicFiles.js +108 -0
- package/dist/LambderResolver.d.ts +30 -31
- package/dist/LambderResolver.js +29 -43
- package/dist/LambderResponse.d.ts +71 -0
- package/dist/LambderResponse.js +196 -0
- package/dist/LambderResponseBuilder.d.ts +58 -33
- package/dist/LambderResponseBuilder.js +114 -167
- package/dist/LambderRouting.d.ts +23 -0
- package/dist/LambderRouting.js +67 -0
- package/dist/LambderSessionController.d.ts +13 -1
- package/dist/LambderSessionController.js +33 -10
- package/dist/LambderSessionManager.d.ts +3 -1
- package/dist/LambderSessionManager.js +15 -6
- package/dist/LambderTemplatingEngine.d.ts +87 -0
- package/dist/LambderTemplatingEngine.js +156 -0
- package/dist/index.d.ts +14 -2
- package/dist/index.js +10 -1
- package/dist/node-polyfills.d.ts +4 -2
- package/dist/node-polyfills.js +28 -0
- package/package.json +7 -5
- package/.eslintrc.cjs +0 -26
- package/.vscode/settings.json +0 -26
- package/deploy +0 -22
- package/dist/LambderUtils.d.ts +0 -10
- package/dist/LambderUtils.js +0 -70
- package/docs/DYNAMODB_SETUP.md +0 -96
- package/docs/LAMBDER_MSW.md +0 -409
- package/docs/TYPE_SAFE_QUICK_START.md +0 -77
- package/examples/msw-testing-example.ts +0 -280
- package/examples/secure-session-example.ts +0 -207
- package/examples/zod-chained-api-example.ts +0 -63
- package/src/Lambder.ts +0 -430
- package/src/LambderApiContract.ts +0 -20
- package/src/LambderCaller.ts +0 -238
- package/src/LambderContext.ts +0 -78
- package/src/LambderMSW.ts +0 -180
- package/src/LambderResolver.ts +0 -101
- package/src/LambderResponseBuilder.ts +0 -332
- package/src/LambderSessionController.ts +0 -114
- package/src/LambderSessionManager.ts +0 -217
- package/src/LambderUtils.ts +0 -75
- package/src/index.ts +0 -17
- package/src/node-polyfills.ts +0 -27
- package/tests/error-handling.test.ts +0 -585
- package/tests/file-serving.test.ts +0 -194
- package/tests/fixtures/public/index.html +0 -1
- package/tests/fixtures/public/main.css +0 -1
- package/tests/hooks.test.ts +0 -561
- package/tests/output-type-runtime.test.ts +0 -381
- package/tests/redirect.test.ts +0 -88
- package/tests/routes.test.ts +0 -543
- package/tests/session.test.ts +0 -1083
- package/tests/use-plugin.test.ts +0 -460
- package/tsconfig.json +0 -24
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File Serving Tests
|
|
3
|
-
*
|
|
4
|
-
* Tests for file serving functionality including:
|
|
5
|
-
* - Serving existing files correctly
|
|
6
|
-
* - Fallback to index.html for non-existent files
|
|
7
|
-
* - Not serving index.html when the requested file exists
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { describe, it, expect } from 'vitest';
|
|
11
|
-
import Lambder from '../src/Lambder.js';
|
|
12
|
-
import type { APIGatewayProxyEvent, Context } from 'aws-lambda';
|
|
13
|
-
import path from 'path';
|
|
14
|
-
|
|
15
|
-
const createMockEvent = (path: string, method: string = 'GET'): APIGatewayProxyEvent => ({
|
|
16
|
-
body: null,
|
|
17
|
-
headers: {
|
|
18
|
-
Host: 'localhost',
|
|
19
|
-
},
|
|
20
|
-
multiValueHeaders: {},
|
|
21
|
-
httpMethod: method,
|
|
22
|
-
isBase64Encoded: false,
|
|
23
|
-
path,
|
|
24
|
-
pathParameters: null,
|
|
25
|
-
queryStringParameters: null,
|
|
26
|
-
multiValueQueryStringParameters: null,
|
|
27
|
-
stageVariables: null,
|
|
28
|
-
requestContext: {} as any,
|
|
29
|
-
resource: '',
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
const createMockContext = (): Context => ({
|
|
33
|
-
callbackWaitsForEmptyEventLoop: false,
|
|
34
|
-
functionName: 'test',
|
|
35
|
-
functionVersion: '1',
|
|
36
|
-
invokedFunctionArn: 'arn',
|
|
37
|
-
memoryLimitInMB: '128',
|
|
38
|
-
awsRequestId: '123',
|
|
39
|
-
logGroupName: 'group',
|
|
40
|
-
logStreamName: 'stream',
|
|
41
|
-
getRemainingTimeInMillis: () => 1000,
|
|
42
|
-
done: () => {},
|
|
43
|
-
fail: () => {},
|
|
44
|
-
succeed: () => {},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('File Serving with Fallback', () => {
|
|
48
|
-
it('should serve main.css when it exists, NOT index.html', async () => {
|
|
49
|
-
const lambder = new Lambder({
|
|
50
|
-
publicPath: path.resolve('./tests/fixtures/public'),
|
|
51
|
-
apiPath: '/api'
|
|
52
|
-
})
|
|
53
|
-
.addRoute('/(.*)', (ctx, res) => {
|
|
54
|
-
return res.file(ctx.path, {}, 'index.html');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const handler = lambder.getHandler();
|
|
58
|
-
const event = createMockEvent('/main.css');
|
|
59
|
-
const result = await handler(event, createMockContext());
|
|
60
|
-
|
|
61
|
-
expect(result.statusCode).toBe(200);
|
|
62
|
-
|
|
63
|
-
// Check content type is CSS
|
|
64
|
-
expect(result.multiValueHeaders?.['Content-Type']).toContain('text/css');
|
|
65
|
-
|
|
66
|
-
// Check body contains CSS content
|
|
67
|
-
const body = Buffer.from(result.body || '', 'base64').toString();
|
|
68
|
-
expect(body).toContain('body { margin: 0; }');
|
|
69
|
-
expect(body).not.toContain('<h1>Test HTML</h1>');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should serve index.html when requested file does not exist', async () => {
|
|
73
|
-
const lambder = new Lambder({
|
|
74
|
-
publicPath: path.resolve('./tests/fixtures/public'),
|
|
75
|
-
apiPath: '/api'
|
|
76
|
-
})
|
|
77
|
-
.addRoute('/(.*)', (ctx, res) => {
|
|
78
|
-
return res.file(ctx.path, {}, 'index.html');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const handler = lambder.getHandler();
|
|
82
|
-
const event = createMockEvent('/non-existent-file.js');
|
|
83
|
-
const result = await handler(event, createMockContext());
|
|
84
|
-
|
|
85
|
-
expect(result.statusCode).toBe(200);
|
|
86
|
-
|
|
87
|
-
// Check content type is HTML
|
|
88
|
-
expect(result.multiValueHeaders?.['Content-Type']).toContain('text/html');
|
|
89
|
-
|
|
90
|
-
// Check body contains HTML content from index.html
|
|
91
|
-
const body = Buffer.from(result.body || '', 'base64').toString();
|
|
92
|
-
expect(body).toContain('<h1>Test HTML</h1>');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should serve index.html when requested directly', async () => {
|
|
96
|
-
const lambder = new Lambder({
|
|
97
|
-
publicPath: path.resolve('./tests/fixtures/public'),
|
|
98
|
-
apiPath: '/api'
|
|
99
|
-
})
|
|
100
|
-
.addRoute('/(.*)', (ctx, res) => {
|
|
101
|
-
return res.file(ctx.path, {}, 'index.html');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const handler = lambder.getHandler();
|
|
105
|
-
const event = createMockEvent('/index.html');
|
|
106
|
-
const result = await handler(event, createMockContext());
|
|
107
|
-
|
|
108
|
-
expect(result.statusCode).toBe(200);
|
|
109
|
-
|
|
110
|
-
// Check content type is HTML
|
|
111
|
-
expect(result.multiValueHeaders?.['Content-Type']).toContain('text/html');
|
|
112
|
-
|
|
113
|
-
// Check body contains HTML content
|
|
114
|
-
const body = Buffer.from(result.body || '', 'base64').toString();
|
|
115
|
-
expect(body).toContain('<h1>Test HTML</h1>');
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('should return error when both requested file and fallback do not exist', async () => {
|
|
119
|
-
const lambder = new Lambder({
|
|
120
|
-
publicPath: path.resolve('./tests/fixtures/public'),
|
|
121
|
-
apiPath: '/api'
|
|
122
|
-
})
|
|
123
|
-
.addRoute('/(.*)', (ctx, res) => {
|
|
124
|
-
return res.file(ctx.path, {}, 'non-existent-fallback.html');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const handler = lambder.getHandler();
|
|
128
|
-
const event = createMockEvent('/non-existent-file.js');
|
|
129
|
-
const result = await handler(event, createMockContext());
|
|
130
|
-
|
|
131
|
-
expect(result.statusCode).toBe(200);
|
|
132
|
-
|
|
133
|
-
// Should return JSON error
|
|
134
|
-
const body = JSON.parse(result.body || '{}');
|
|
135
|
-
expect(body.error).toContain('File not found');
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should serve correct file even when catch-all route is last', async () => {
|
|
139
|
-
const lambder = new Lambder({
|
|
140
|
-
publicPath: path.resolve('./tests/fixtures/public'),
|
|
141
|
-
apiPath: '/api'
|
|
142
|
-
})
|
|
143
|
-
.addRoute('/specific', (ctx, res) => {
|
|
144
|
-
return res.html('Specific Route');
|
|
145
|
-
})
|
|
146
|
-
.addRoute('/(.*)', (ctx, res) => {
|
|
147
|
-
return res.file(ctx.path, {}, 'index.html');
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
const handler = lambder.getHandler();
|
|
151
|
-
|
|
152
|
-
// Test specific route still works
|
|
153
|
-
const specificEvent = createMockEvent('/specific');
|
|
154
|
-
const specificResult = await handler(specificEvent, createMockContext());
|
|
155
|
-
const specificBody = Buffer.from(specificResult.body || '', 'base64').toString();
|
|
156
|
-
expect(specificBody).toBe('Specific Route');
|
|
157
|
-
|
|
158
|
-
// Test main.css is served correctly
|
|
159
|
-
const cssEvent = createMockEvent('/main.css');
|
|
160
|
-
const cssResult = await handler(cssEvent, createMockContext());
|
|
161
|
-
const cssBody = Buffer.from(cssResult.body || '', 'base64').toString();
|
|
162
|
-
expect(cssBody).toContain('body { margin: 0; }');
|
|
163
|
-
|
|
164
|
-
// Test fallback to index.html for non-existent files
|
|
165
|
-
const fallbackEvent = createMockEvent('/some-route');
|
|
166
|
-
const fallbackResult = await handler(fallbackEvent, createMockContext());
|
|
167
|
-
const fallbackBody = Buffer.from(fallbackResult.body || '', 'base64').toString();
|
|
168
|
-
expect(fallbackBody).toContain('<h1>Test HTML</h1>');
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should serve CSS file with correct text/css MIME type', async () => {
|
|
172
|
-
const lambder = new Lambder({
|
|
173
|
-
publicPath: path.resolve('./tests/fixtures/public'),
|
|
174
|
-
apiPath: '/api'
|
|
175
|
-
})
|
|
176
|
-
.addRoute('/(.*)', (ctx, res) => {
|
|
177
|
-
return res.file(ctx.path);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const handler = lambder.getHandler();
|
|
181
|
-
const event = createMockEvent('/main.css');
|
|
182
|
-
const result = await handler(event, createMockContext());
|
|
183
|
-
|
|
184
|
-
expect(result.statusCode).toBe(200);
|
|
185
|
-
|
|
186
|
-
// Verify Content-Type header is exactly text/css
|
|
187
|
-
expect(result.multiValueHeaders?.['Content-Type']).toBeDefined();
|
|
188
|
-
expect(result.multiValueHeaders?.['Content-Type']?.[0]).toBe('text/css');
|
|
189
|
-
|
|
190
|
-
// Verify body contains CSS content
|
|
191
|
-
const body = Buffer.from(result.body || '', 'base64').toString();
|
|
192
|
-
expect(body).toContain('body { margin: 0; }');
|
|
193
|
-
});
|
|
194
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<h1>Test HTML</h1>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
body { margin: 0; }
|