lambder 1.0.145 → 1.0.147

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
@@ -1,4 +1,3 @@
1
- import querystring from "querystring";
2
1
  import cookieParser from "cookie";
3
2
  import { match } from "path-to-regexp";
4
3
  import LambderResolver from "./LambderResolver.js";
@@ -22,7 +21,11 @@ export const createContext = (event, lambdaContext, apiPath) => {
22
21
  post = JSON.parse(decodedBody) || {};
23
22
  }
24
23
  catch (e) {
25
- post = querystring.parse(decodedBody) || {};
24
+ const params = new URLSearchParams(decodedBody);
25
+ post = {};
26
+ for (const [key, value] of params.entries()) {
27
+ post[key] = value;
28
+ }
26
29
  }
27
30
  }
28
31
  catch (e) { }
@@ -1,3 +1,5 @@
1
+ import { createRequire } from 'module';
2
+ const require = createRequire(import.meta.url);
1
3
  export default class LambderMSW {
2
4
  apiPath;
3
5
  apiVersion;
@@ -28,12 +28,12 @@ export default class LambderResponseBuilder {
28
28
  throw new Error("File system operations are not available in browser environment");
29
29
  }
30
30
  const publicPath = path.resolve(this.publicPath);
31
- const absolutePath = path.join(publicPath, filePath);
31
+ const absolutePath = path.resolve(publicPath, filePath);
32
32
  console.log("readPublicFileSync", { filePath, publicPath, absolutePath });
33
- if (!absolutePath.includes(publicPath)) {
33
+ if (!absolutePath.startsWith(publicPath)) {
34
34
  return "forbidden-public-path";
35
35
  }
36
- return fs.readFileSync(absolutePath);
36
+ return await fs.promises.readFile(absolutePath);
37
37
  }
38
38
  ;
39
39
  async checkPublicFileExist(filePath) {
@@ -43,12 +43,18 @@ export default class LambderResponseBuilder {
43
43
  return false;
44
44
  }
45
45
  const publicPath = path.resolve(this.publicPath);
46
- const absolutePath = path.join(this.publicPath, filePath);
46
+ const absolutePath = path.resolve(publicPath, filePath);
47
47
  console.log("checkPublicFileExist", { filePath, publicPath, absolutePath });
48
- if (!absolutePath.includes(publicPath)) {
48
+ if (!absolutePath.startsWith(publicPath)) {
49
+ return false;
50
+ }
51
+ try {
52
+ const stat = await fs.promises.stat(absolutePath);
53
+ return stat.isFile();
54
+ }
55
+ catch {
49
56
  return false;
50
57
  }
51
- return fs.existsSync(absolutePath) && fs.statSync(absolutePath).isFile();
52
58
  }
53
59
  ;
54
60
  addHeader(key, value) {
@@ -128,8 +128,8 @@ export default class LambderSessionManager {
128
128
  if (this.enableSlidingExpiration) {
129
129
  session.lastAccessedAt = Math.floor(Date.now() / 1000);
130
130
  session.expiresAt = session.lastAccessedAt + session.ttlInSeconds;
131
- // Fire and forget - don't wait for the update
132
- this.ddbPutItem(session).catch(() => { });
131
+ // Wait for the update to ensure it persists before Lambda freezes
132
+ await this.ddbPutItem(session).catch(() => { });
133
133
  }
134
134
  return session;
135
135
  }
@@ -16,12 +16,12 @@ export default class LambderUtils {
16
16
  return "EJS PATH NOT SET!";
17
17
  }
18
18
  const ejsPath = path.resolve(this.ejsPath);
19
- const absolutePath = path.join(ejsPath, filePath);
19
+ const absolutePath = path.resolve(ejsPath, filePath);
20
20
  console.log("readEjsFileSync", { filePath, ejsPath, absolutePath });
21
- if (!absolutePath.includes(ejsPath)) {
21
+ if (!absolutePath.startsWith(ejsPath)) {
22
22
  return "forbidden-ejs-path";
23
23
  }
24
- return String(fs.readFileSync(absolutePath));
24
+ return String(await fs.promises.readFile(absolutePath));
25
25
  }
26
26
  ;
27
27
  async checkEjsFileExist(filePath) {
@@ -34,12 +34,18 @@ export default class LambderUtils {
34
34
  return "EJS PATH NOT SET!";
35
35
  }
36
36
  const ejsPath = path.resolve(this.ejsPath);
37
- const absolutePath = path.join(this.ejsPath, filePath);
37
+ const absolutePath = path.resolve(ejsPath, filePath);
38
38
  console.log("checkEjsFileExist", { filePath, ejsPath, absolutePath });
39
- if (!absolutePath.includes(ejsPath)) {
39
+ if (!absolutePath.startsWith(ejsPath)) {
40
+ return false;
41
+ }
42
+ try {
43
+ const stat = await fs.promises.stat(absolutePath);
44
+ return stat.isFile();
45
+ }
46
+ catch {
40
47
  return false;
41
48
  }
42
- return fs.existsSync(absolutePath) && fs.statSync(absolutePath).isFile();
43
49
  }
44
50
  ;
45
51
  async renderEjs(template, pageData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lambder",
3
- "version": "1.0.145",
3
+ "version": "1.0.147",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/Lambder.ts CHANGED
@@ -1,4 +1,3 @@
1
- import querystring from "querystring";
2
1
  import cookieParser from "cookie";
3
2
  import { match } from "path-to-regexp";
4
3
 
@@ -76,7 +75,13 @@ export const createContext = (
76
75
  try {
77
76
  const decodedBody = event.isBase64Encoded ? ( event.body ? Buffer.from(event.body,"base64").toString() : "{}" ) : ( event.body || "{}" );
78
77
  try { post = JSON.parse(decodedBody) || {}; }
79
- catch(e){ post = querystring.parse(decodedBody) || {}; }
78
+ catch(e){
79
+ const params = new URLSearchParams(decodedBody);
80
+ post = {};
81
+ for(const [key, value] of params.entries()){
82
+ post[key] = value;
83
+ }
84
+ }
80
85
  }catch(e){}
81
86
  // Parse api variables
82
87
 
package/src/LambderMSW.ts CHANGED
@@ -1,6 +1,9 @@
1
+ import { createRequire } from 'module';
1
2
  import type { ApiContractShape } from './LambderApiContract';
2
3
  import type { LambderApiResponse } from './LambderResponseBuilder';
3
4
 
5
+ const require = createRequire(import.meta.url);
6
+
4
7
  // MSW types - these will be resolved at runtime when msw is installed
5
8
  type RequestHandler = any;
6
9
 
@@ -70,10 +70,10 @@ export default class LambderResponseBuilder<TContract extends ApiContractShape =
70
70
  }
71
71
 
72
72
  const publicPath = path.resolve(this.publicPath);
73
- const absolutePath = path.join(publicPath, filePath);
73
+ const absolutePath = path.resolve(publicPath, filePath);
74
74
  console.log("readPublicFileSync", { filePath, publicPath, absolutePath });
75
- if(!absolutePath.includes(publicPath)){ return "forbidden-public-path"; }
76
- return fs.readFileSync(absolutePath);
75
+ if(!absolutePath.startsWith(publicPath)){ return "forbidden-public-path"; }
76
+ return await fs.promises.readFile(absolutePath);
77
77
  };
78
78
 
79
79
  private async checkPublicFileExist(filePath: string){
@@ -83,10 +83,15 @@ export default class LambderResponseBuilder<TContract extends ApiContractShape =
83
83
  if (!fs || !path) { return false; }
84
84
 
85
85
  const publicPath = path.resolve(this.publicPath);
86
- const absolutePath = path.join(this.publicPath, filePath);
86
+ const absolutePath = path.resolve(publicPath, filePath);
87
87
  console.log("checkPublicFileExist", { filePath, publicPath, absolutePath });
88
- if(!absolutePath.includes(publicPath)){ return false; }
89
- return fs.existsSync(absolutePath) && fs.statSync(absolutePath).isFile();
88
+ if(!absolutePath.startsWith(publicPath)){ return false; }
89
+ try {
90
+ const stat = await fs.promises.stat(absolutePath);
91
+ return stat.isFile();
92
+ } catch {
93
+ return false;
94
+ }
90
95
  };
91
96
 
92
97
  addHeader(key: string, value: string){
@@ -167,8 +167,8 @@ export default class LambderSessionManager{
167
167
  if(this.enableSlidingExpiration){
168
168
  session.lastAccessedAt = Math.floor(Date.now()/1000);
169
169
  session.expiresAt = session.lastAccessedAt + session.ttlInSeconds;
170
- // Fire and forget - don't wait for the update
171
- this.ddbPutItem(session).catch(() => {});
170
+ // Wait for the update to ensure it persists before Lambda freezes
171
+ await this.ddbPutItem(session).catch(() => {});
172
172
  }
173
173
 
174
174
  return session;
@@ -21,10 +21,10 @@ export default class LambderUtils {
21
21
  }
22
22
  if(!this.ejsPath){ return "EJS PATH NOT SET!"; }
23
23
  const ejsPath = path.resolve(this.ejsPath);
24
- const absolutePath = path.join(ejsPath, filePath);
24
+ const absolutePath = path.resolve(ejsPath, filePath);
25
25
  console.log("readEjsFileSync", { filePath, ejsPath, absolutePath });
26
- if(!absolutePath.includes(ejsPath)){ return "forbidden-ejs-path"; }
27
- return String(fs.readFileSync(absolutePath));
26
+ if(!absolutePath.startsWith(ejsPath)){ return "forbidden-ejs-path"; }
27
+ return String(await fs.promises.readFile(absolutePath));
28
28
  };
29
29
 
30
30
  private async checkEjsFileExist(filePath: string){
@@ -36,10 +36,15 @@ export default class LambderUtils {
36
36
  }
37
37
  if(!this.ejsPath){ return "EJS PATH NOT SET!"; }
38
38
  const ejsPath = path.resolve(this.ejsPath);
39
- const absolutePath = path.join(this.ejsPath, filePath);
39
+ const absolutePath = path.resolve(ejsPath, filePath);
40
40
  console.log("checkEjsFileExist", { filePath, ejsPath, absolutePath });
41
- if(!absolutePath.includes(ejsPath)){ return false; }
42
- return fs.existsSync(absolutePath) && fs.statSync(absolutePath).isFile();
41
+ if(!absolutePath.startsWith(ejsPath)){ return false; }
42
+ try {
43
+ const stat = await fs.promises.stat(absolutePath);
44
+ return stat.isFile();
45
+ } catch {
46
+ return false;
47
+ }
43
48
  };
44
49
 
45
50
  async renderEjs(