lambder 1.0.74 → 1.0.76

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
@@ -13,8 +13,6 @@ export const createContext = (event, lambdaContext, apiPath) => {
13
13
  const headers = event.headers;
14
14
  let post = {};
15
15
  const session = null;
16
- const isAPICall = method === "POST" && apiPath && path === apiPath && post.apiName;
17
- const apiName = isAPICall ? post.apiName : null;
18
16
  try {
19
17
  const decodedBody = event.isBase64Encoded ? (event.body ? Buffer.from(event.body, "base64").toString() : "{}") : (event.body || "{}");
20
18
  try {
@@ -25,6 +23,8 @@ export const createContext = (event, lambdaContext, apiPath) => {
25
23
  }
26
24
  }
27
25
  catch (e) { }
26
+ const isAPICall = method === "POST" && apiPath && path === apiPath && post.apiName;
27
+ const apiName = isAPICall ? post.apiName : null;
28
28
  if (/^(((\d+\.)+\d+)|(([a-f\d]+:)+[a-f\d]+))$/.test(host)) {
29
29
  throw new Error("[404] Host cannot be an ip address: " + host);
30
30
  }
@@ -154,18 +154,18 @@ export default class Lambder {
154
154
  ;
155
155
  addApi(apiName, actionFn) {
156
156
  this.actionList.push({
157
- conditionFn: (ctx) => ((typeof apiName === "string" && ctx.apiName === apiName) ||
157
+ conditionFn: (ctx) => (!!ctx.apiName && ((typeof apiName === "string" && ctx.apiName === apiName) ||
158
158
  (typeof apiName === "function" && apiName(ctx)) ||
159
- (apiName?.constructor == RegExp && apiName.test(ctx.apiName))),
159
+ (apiName?.constructor == RegExp && apiName.test(ctx.apiName)))),
160
160
  actionFn: async (ctx, resolver) => await actionFn(ctx, resolver),
161
161
  });
162
162
  }
163
163
  ;
164
164
  addSessionApi(apiName, actionFn) {
165
165
  this.actionList.push({
166
- conditionFn: (ctx) => ((typeof apiName === "string" && ctx.apiName === apiName) ||
166
+ conditionFn: (ctx) => (!!ctx.apiName && ((typeof apiName === "string" && ctx.apiName === apiName) ||
167
167
  (typeof apiName === "function" && apiName(ctx)) ||
168
- (apiName?.constructor == RegExp && apiName.test(ctx.apiName))),
168
+ (apiName?.constructor == RegExp && apiName.test(ctx.apiName)))),
169
169
  actionFn: async (ctx, resolver) => {
170
170
  const isSessionValid = this.validateSession(ctx);
171
171
  if (!isSessionValid)
@@ -54,7 +54,7 @@ export default class LambderCaller {
54
54
  if (this.fetchEndedHandler) {
55
55
  fetchTracker.fetchEndCalled = true;
56
56
  await this.fetchEndedHandler({
57
- fetchParams: { apiName, payload, headers, },
57
+ fetchParams: { apiName, payload, headers },
58
58
  fetchResult: data,
59
59
  activeFetchList: this.fetchTrackerList.filter(v => !v.done),
60
60
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.74",
3
+ "version": "1.0.76",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/Lambder.ts CHANGED
@@ -61,13 +61,14 @@ export const createContext = (
61
61
  const headers = event.headers;
62
62
  let post: Record<string, any> = {};
63
63
  const session = null;
64
- const isAPICall = method === "POST" && apiPath && path === apiPath && post.apiName;
65
- const apiName:string = isAPICall ? post.apiName : null;
66
64
  try {
67
65
  const decodedBody = event.isBase64Encoded ? ( event.body ? Buffer.from(event.body,"base64").toString() : "{}" ) : ( event.body || "{}" );
68
66
  try { post = JSON.parse(decodedBody) || {}; }
69
67
  catch(e){ post = querystring.parse(decodedBody) || {}; }
70
68
  }catch(e){}
69
+ const isAPICall = method === "POST" && apiPath && path === apiPath && post.apiName;
70
+ const apiName:string = isAPICall ? post.apiName : null;
71
+
71
72
  if(/^(((\d+\.)+\d+)|(([a-f\d]+:)+[a-f\d]+))$/.test(host)){ throw new Error("[404] Host cannot be an ip address: " + host); }
72
73
  return { host, path, pathParams, method, get, post, cookie, apiName, headers, session, lambdaContext };
73
74
  }
@@ -206,9 +207,11 @@ export default class Lambder {
206
207
  addApi(apiName: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
207
208
  this.actionList.push({
208
209
  conditionFn: (ctx:LambderRenderContext) => (
209
- (typeof apiName === "string" && ctx.apiName === apiName) ||
210
- (typeof apiName === "function" && apiName(ctx)) ||
211
- (apiName?.constructor == RegExp && apiName.test(ctx.apiName))
210
+ !!ctx.apiName && (
211
+ (typeof apiName === "string" && ctx.apiName === apiName) ||
212
+ (typeof apiName === "function" && apiName(ctx)) ||
213
+ (apiName?.constructor == RegExp && apiName.test(ctx.apiName))
214
+ )
212
215
  ),
213
216
  actionFn: async (ctx:LambderRenderContext, resolver: LambderResolver) => await actionFn(ctx, resolver),
214
217
  });
@@ -217,9 +220,11 @@ export default class Lambder {
217
220
  addSessionApi(apiName: string|ConditionFunction|RegExp, actionFn: ActionFunction):void{
218
221
  this.actionList.push({
219
222
  conditionFn: (ctx:LambderRenderContext) => (
220
- (typeof apiName === "string" && ctx.apiName === apiName) ||
221
- (typeof apiName === "function" && apiName(ctx)) ||
222
- (apiName?.constructor == RegExp && apiName.test(ctx.apiName))
223
+ !!ctx.apiName && (
224
+ (typeof apiName === "string" && ctx.apiName === apiName) ||
225
+ (typeof apiName === "function" && apiName(ctx)) ||
226
+ (apiName?.constructor == RegExp && apiName.test(ctx.apiName))
227
+ )
223
228
  ),
224
229
  actionFn: async (ctx:LambderRenderContext, resolver: LambderResolver) => {
225
230
  const isSessionValid = this.validateSession(ctx);
@@ -116,7 +116,7 @@ export default class LambderCaller {
116
116
  if(this.fetchEndedHandler){
117
117
  fetchTracker.fetchEndCalled = true;
118
118
  await this.fetchEndedHandler({
119
- fetchParams: { apiName, payload, headers, },
119
+ fetchParams: { apiName, payload, headers },
120
120
  fetchResult: data,
121
121
  activeFetchList: this.fetchTrackerList.filter(v=>!v.done),
122
122
  });