lambder 1.0.140 → 1.0.142
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/dist/Lambder.js
CHANGED
|
@@ -236,6 +236,14 @@ export default class Lambder {
|
|
|
236
236
|
return resolver.cors();
|
|
237
237
|
const firstMatchedAction = this.actionList.find(action => action.conditionFn(ctx));
|
|
238
238
|
if (firstMatchedAction) {
|
|
239
|
+
// Check version if provided by the client and the server
|
|
240
|
+
if (this.apiVersion && ctx.post?.apiVersion) {
|
|
241
|
+
if (ctx.post.apiVersion !== this.apiVersion) {
|
|
242
|
+
const responseBuilder = this.getResponseBuilder();
|
|
243
|
+
return resolve(responseBuilder.versionExpired());
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
;
|
|
239
247
|
// Run beforeRender hooks
|
|
240
248
|
for (const hook of this.hookList["beforeRender"]) {
|
|
241
249
|
const hookCtx = await hook.hookFn(ctx, resolver);
|
package/dist/LambderMSW.js
CHANGED
|
@@ -31,7 +31,8 @@ export default class LambderMSW {
|
|
|
31
31
|
return this.http.post(this.apiPath, async ({ request }) => {
|
|
32
32
|
let body;
|
|
33
33
|
try {
|
|
34
|
-
|
|
34
|
+
const clonedRequest = request.clone();
|
|
35
|
+
body = await clonedRequest.json();
|
|
35
36
|
}
|
|
36
37
|
catch (parseErr) {
|
|
37
38
|
// If JSON parsing fails, return undefined to let other handlers try
|
|
@@ -40,15 +41,12 @@ export default class LambderMSW {
|
|
|
40
41
|
}
|
|
41
42
|
// Check if body is valid and has apiName
|
|
42
43
|
if (!body || typeof body.apiName !== 'string') {
|
|
43
|
-
// Invalid request format, let other handlers try
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
|
-
console.log("LambderMSW called for:", body.apiName, "matching against:", apiName);
|
|
47
|
-
// Check if this is the API we're mocking
|
|
48
46
|
if (body.apiName !== apiName) {
|
|
49
|
-
// If this handler doesn't match, return undefined to let MSW try other handlers
|
|
50
47
|
return;
|
|
51
48
|
}
|
|
49
|
+
console.log("LambderMSW called for:", body.apiName);
|
|
52
50
|
try {
|
|
53
51
|
// Add artificial delay if specified
|
|
54
52
|
if (options?.delay) {
|
|
@@ -42,11 +42,12 @@ export default class LambderResponseBuilder<TContract extends ApiContractShape =
|
|
|
42
42
|
html(data: string, headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
43
43
|
status301(url: string, headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
44
44
|
status404(data: string, headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
45
|
+
versionExpired(headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
45
46
|
cors(): LambderResolverResponse;
|
|
46
47
|
fileBase64(fileBase64: string, mimeType: string, headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
47
48
|
file(filePath: string, headers?: Record<string, string | string[]>, fallbackFilePath?: string): Promise<LambderResolverResponse>;
|
|
48
49
|
ejsTemplate(template: string, pageData: Record<string, any>, headers?: Record<string, string | string[]>): Promise<LambderResolverResponse>;
|
|
49
50
|
ejsFile(filePath: string, pageData: Record<string, any>, headers?: Record<string, string | string[]>): Promise<LambderResolverResponse>;
|
|
50
51
|
api<T = any>(payload: T | null, { versionExpired, sessionExpired, notAuthorized, message, errorMessage, logList, }?: LambderApiResponseConfig, headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
51
|
-
|
|
52
|
+
apiBinary<T = any>(payload: T | null, { versionExpired, sessionExpired, notAuthorized, message, errorMessage, logList, }?: LambderApiResponseConfig, headers?: Record<string, string | string[]>): LambderResolverResponse;
|
|
52
53
|
}
|
package/package.json
CHANGED
package/src/Lambder.ts
CHANGED
|
@@ -377,6 +377,13 @@ export default class Lambder<TContract extends ApiContractShape = any> {
|
|
|
377
377
|
|
|
378
378
|
const firstMatchedAction = this.actionList.find(action => action.conditionFn(ctx));
|
|
379
379
|
if(firstMatchedAction){
|
|
380
|
+
// Check version if provided by the client and the server
|
|
381
|
+
if(this.apiVersion && ctx.post?.apiVersion){
|
|
382
|
+
if(ctx.post.apiVersion !== this.apiVersion){
|
|
383
|
+
const responseBuilder = this.getResponseBuilder();
|
|
384
|
+
return resolve(responseBuilder.versionExpired());
|
|
385
|
+
}
|
|
386
|
+
};
|
|
380
387
|
// Run beforeRender hooks
|
|
381
388
|
for(const hook of this.hookList["beforeRender"]){
|
|
382
389
|
const hookCtx = await hook.hookFn(ctx, resolver);
|
package/src/LambderMSW.ts
CHANGED
|
@@ -65,7 +65,8 @@ export default class LambderMSW<TContract extends ApiContractShape = any> {
|
|
|
65
65
|
let body: any;
|
|
66
66
|
|
|
67
67
|
try {
|
|
68
|
-
|
|
68
|
+
const clonedRequest = request.clone();
|
|
69
|
+
body = await clonedRequest.json();
|
|
69
70
|
} catch (parseErr) {
|
|
70
71
|
// If JSON parsing fails, return undefined to let other handlers try
|
|
71
72
|
console.warn("LambderMSW: Failed to parse request body as JSON");
|
|
@@ -73,18 +74,10 @@ export default class LambderMSW<TContract extends ApiContractShape = any> {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
// Check if body is valid and has apiName
|
|
76
|
-
if (!body || typeof body.apiName !== 'string') {
|
|
77
|
-
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
console.log("LambderMSW called for:", body.apiName, "matching against:", apiName);
|
|
77
|
+
if (!body || typeof body.apiName !== 'string') { return; }
|
|
78
|
+
if (body.apiName !== apiName) { return; }
|
|
82
79
|
|
|
83
|
-
|
|
84
|
-
if (body.apiName !== apiName) {
|
|
85
|
-
// If this handler doesn't match, return undefined to let MSW try other handlers
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
80
|
+
console.log("LambderMSW called for:", body.apiName);
|
|
88
81
|
|
|
89
82
|
try {
|
|
90
83
|
// Add artificial delay if specified
|
|
@@ -176,6 +176,12 @@ export default class LambderResponseBuilder<TContract extends ApiContractShape =
|
|
|
176
176
|
});
|
|
177
177
|
};
|
|
178
178
|
|
|
179
|
+
versionExpired(
|
|
180
|
+
headers?: Record<string, string|string[]>,
|
|
181
|
+
):LambderResolverResponse{
|
|
182
|
+
return this.api(null, { versionExpired: true }, headers);
|
|
183
|
+
};
|
|
184
|
+
|
|
179
185
|
cors():LambderResolverResponse{
|
|
180
186
|
return this.raw({
|
|
181
187
|
statusCode: 200,
|
|
@@ -275,7 +281,7 @@ export default class LambderResponseBuilder<TContract extends ApiContractShape =
|
|
|
275
281
|
}, headers);
|
|
276
282
|
};
|
|
277
283
|
|
|
278
|
-
|
|
284
|
+
apiBinary<T=any>(
|
|
279
285
|
payload: T | null,
|
|
280
286
|
{
|
|
281
287
|
versionExpired, sessionExpired, notAuthorized,
|