serverless-offline 14.7.0 → 14.7.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-offline",
3
- "version": "14.7.0",
3
+ "version": "14.7.1",
4
4
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
5
5
  "license": "MIT",
6
6
  "exports": {
@@ -15,7 +15,7 @@
15
15
  "lint:fix": "eslint . --fix",
16
16
  "list-contributors": "echo 'clone https://github.com/mgechev/github-contributors-list.git first, then run npm install' && cd ../github-contributors-list && node bin/githubcontrib --owner dherault --repo serverless-offline --sortBy contributions --sortOrder desc > contributors.md",
17
17
  "prepublishOnly": "npm run lint",
18
- "changelog": "auto-changelog",
18
+ "version": "auto-changelog -p && git add CHANGELOG.md",
19
19
  "prettier": "prettier --check .",
20
20
  "prettier:fix": "prettier --write .",
21
21
  "test": "mocha --require ./tests/mochaHooks.cjs",
@@ -24,6 +24,7 @@ import logRoutes from "../../utils/logRoutes.js"
24
24
  import {
25
25
  createApiKey,
26
26
  detectEncoding,
27
+ generateHapiCookie,
27
28
  generateHapiPath,
28
29
  getApiKeysValues,
29
30
  getHttpApiCorsConfig,
@@ -883,13 +884,8 @@ export default class HttpServer {
883
884
  log.debug("headers", headers)
884
885
 
885
886
  const parseCookies = (headerValue) => {
886
- const cookieName = headerValue.slice(0, headerValue.indexOf("="))
887
- const cookieValue = headerValue.slice(headerValue.indexOf("=") + 1)
888
-
889
- h.state(cookieName, cookieValue, {
890
- encoding: "none",
891
- strictHeader: false,
892
- })
887
+ const hapiCookie = generateHapiCookie(headerValue)
888
+ h.state(hapiCookie.name, hapiCookie.value, hapiCookie.options)
893
889
  }
894
890
 
895
891
  entries(headers).forEach(([headerKey, headerValue]) => {
@@ -0,0 +1,70 @@
1
+ function calculateTtl(attributes) {
2
+ // Try max-age first (in seconds, convert to milliseconds)
3
+ const maxAgeSeconds = Number(attributes["max-age"])
4
+ if (Number.isFinite(maxAgeSeconds)) {
5
+ return maxAgeSeconds * 1000
6
+ }
7
+
8
+ // Fall back to expires (absolute date)
9
+ if (attributes.expires) {
10
+ const expiresDate = new Date(attributes.expires)
11
+ const now = new Date()
12
+ const expiresMs = expiresDate.getTime() - now.getTime()
13
+ return Number.isFinite(expiresMs) ? expiresMs : undefined
14
+ }
15
+
16
+ return undefined
17
+ }
18
+
19
+ export default function generateHapiCookie(cookieString) {
20
+ const equalsIndex = cookieString.indexOf("=")
21
+ if (equalsIndex === -1) {
22
+ return {
23
+ name: cookieString,
24
+ options: {
25
+ domain: undefined,
26
+ encoding: "none",
27
+ isHttpOnly: false,
28
+ isSameSite: false,
29
+ isSecure: false,
30
+ path: undefined,
31
+ strictHeader: false,
32
+ ttl: undefined,
33
+ },
34
+ value: "",
35
+ }
36
+ }
37
+ const semicolonIndex = cookieString.indexOf(";")
38
+ const valueEndIndex =
39
+ semicolonIndex === -1 ? cookieString.length : semicolonIndex
40
+ const name = cookieString.slice(0, equalsIndex)
41
+ const value = cookieString.slice(equalsIndex + 1, valueEndIndex)
42
+
43
+ // Parse attributes into a map
44
+ const attributes = cookieString
45
+ .split(";")
46
+ .slice(1) // skip the name=value part
47
+ .reduce((acc, part) => {
48
+ const [key, val] = part.trim().split("=")
49
+ acc[key.trim().toLowerCase()] = val ? val.trim() : true
50
+ return acc
51
+ }, {})
52
+
53
+ // Calculate TTL from max-age or expires attribute
54
+ const ttl = calculateTtl(attributes)
55
+
56
+ return {
57
+ name,
58
+ options: {
59
+ domain: attributes.domain,
60
+ encoding: "none",
61
+ isHttpOnly: attributes.httponly === true ? true : undefined,
62
+ isSameSite: attributes.samesite || false,
63
+ isSecure: attributes.secure === true ? true : undefined,
64
+ path: attributes.path,
65
+ strictHeader: false,
66
+ ttl,
67
+ },
68
+ value,
69
+ }
70
+ }
@@ -3,6 +3,7 @@ export { default as checkGoVersion } from "./checkGoVersion.js"
3
3
  export { default as createApiKey } from "./createApiKey.js"
4
4
  export { default as detectExecutable } from "./detectExecutable.js"
5
5
  export { default as formatToClfTime } from "./formatToClfTime.js"
6
+ export { default as generateHapiCookie } from "./generateHapiCookie.js"
6
7
  export { default as generateHapiPath } from "./generateHapiPath.js"
7
8
  export { default as getApiKeysValues } from "./getApiKeysValues.js"
8
9
  export { default as getHttpApiCorsConfig } from "./getHttpApiCorsConfig.js"