lambder 1.0.141 → 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);
@@ -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
- private apiBinary;
52
+ apiBinary<T = any>(payload: T | null, { versionExpired, sessionExpired, notAuthorized, message, errorMessage, logList, }?: LambderApiResponseConfig, headers?: Record<string, string | string[]>): LambderResolverResponse;
52
53
  }
@@ -127,6 +127,10 @@ export default class LambderResponseBuilder {
127
127
  });
128
128
  }
129
129
  ;
130
+ versionExpired(headers) {
131
+ return this.api(null, { versionExpired: true }, headers);
132
+ }
133
+ ;
130
134
  cors() {
131
135
  return this.raw({
132
136
  statusCode: 200,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.141",
3
+ "version": "1.0.142",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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);
@@ -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
- private apiBinary<T=any>(
284
+ apiBinary<T=any>(
279
285
  payload: T | null,
280
286
  {
281
287
  versionExpired, sessionExpired, notAuthorized,