lambder 1.0.144 → 1.0.146

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.
@@ -2,12 +2,12 @@ import crypto from "crypto";
2
2
  import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
3
3
  import { DynamoDBDocumentClient, QueryCommand, DeleteCommand, PutCommand, GetCommand } from "@aws-sdk/lib-dynamodb";
4
4
 
5
- export type LambderSessionContext = {
5
+ export type LambderSessionContext<SessionData = any> = {
6
6
  [x: string]: any;
7
7
  sessionToken: string;
8
8
  csrfToken: string;
9
9
  sessionKey: string;
10
- data: any;
10
+ data: SessionData;
11
11
  createdAt: number;
12
12
  expiresAt: number;
13
13
  lastAccessedAt: number;
@@ -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(