serverless-offline 13.6.0 → 14.1.0

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,7 +1,6 @@
1
1
  {
2
- "dedicatedTo": "Blue, a great migrating bird.",
3
2
  "name": "serverless-offline",
4
- "version": "13.6.0",
3
+ "version": "14.1.0",
5
4
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
5
  "license": "MIT",
7
6
  "exports": {
@@ -77,10 +76,10 @@
77
76
  ]
78
77
  },
79
78
  "dependencies": {
80
- "@aws-sdk/client-lambda": "^3.509.0",
79
+ "@aws-sdk/client-lambda": "^3.632.0",
81
80
  "@hapi/boom": "^10.0.1",
82
81
  "@hapi/h2o2": "^10.0.4",
83
- "@hapi/hapi": "^21.3.3",
82
+ "@hapi/hapi": "^21.3.10",
84
83
  "array-unflat-js": "^0.1.3",
85
84
  "boxen": "^7.1.1",
86
85
  "chalk": "^5.3.0",
@@ -89,33 +88,35 @@
89
88
  "fs-extra": "^11.2.0",
90
89
  "is-wsl": "^3.1.0",
91
90
  "java-invoke-local": "0.0.6",
92
- "jose": "^5.2.1",
91
+ "jose": "^5.6.3",
93
92
  "js-string-escape": "^1.0.1",
94
- "jsonpath-plus": "^8.0.0",
93
+ "jsonpath-plus": "^9.0.0",
95
94
  "jsonschema": "^1.4.1",
96
95
  "jszip": "^3.10.1",
97
- "luxon": "^3.4.4",
96
+ "luxon": "^3.5.0",
98
97
  "node-schedule": "^2.1.1",
99
98
  "p-memoize": "^7.1.1",
99
+ "tree-kill": "^1.2.2",
100
+ "tsx": "^4.17.0",
100
101
  "velocityjs": "^2.0.6",
101
- "ws": "^8.16.0"
102
+ "ws": "^8.18.0"
102
103
  },
103
104
  "devDependencies": {
104
105
  "@istanbuljs/esm-loader-hook": "^0.2.0",
105
- "archiver": "^6.0.1",
106
- "commit-and-tag-version": "^12.2.0",
107
- "eslint": "^8.56.0",
106
+ "archiver": "^7.0.1",
107
+ "commit-and-tag-version": "^12.4.1",
108
+ "eslint": "^8.57.0",
108
109
  "eslint-config-airbnb-base": "^15.0.0",
109
110
  "eslint-config-prettier": "^9.1.0",
110
111
  "eslint-plugin-import": "^2.29.1",
111
- "eslint-plugin-prettier": "^5.1.3",
112
- "eslint-plugin-unicorn": "^51.0.1",
113
- "mocha": "^10.3.0",
114
- "nyc": "^15.1.0",
115
- "prettier": "^3.2.5",
116
- "serverless": "^3.38.0"
112
+ "eslint-plugin-prettier": "^5.2.1",
113
+ "eslint-plugin-unicorn": "^54.0.0",
114
+ "mocha": "^10.7.3",
115
+ "nyc": "^17.0.0",
116
+ "prettier": "^3.3.3",
117
+ "serverless": "^4.1.22"
117
118
  },
118
119
  "peerDependencies": {
119
- "serverless": "^3.2.0"
120
+ "serverless": "^4.0.0"
120
121
  }
121
122
  }
@@ -20,6 +20,7 @@ export const supportedRuntimesArchitecture = {
20
20
  "python3.9": [ARM64, X86_64],
21
21
  "python3.10": [ARM64, X86_64],
22
22
  "python3.11": [ARM64, X86_64],
23
+ "python3.12": [ARM64, X86_64],
23
24
  "ruby2.7": [ARM64, X86_64],
24
25
  "ruby3.2": [ARM64, X86_64],
25
26
  java8: [X86_64],
@@ -62,6 +63,7 @@ export const supportedPython = new Set([
62
63
  "python3.9",
63
64
  "python3.10",
64
65
  "python3.11",
66
+ "python3.12",
65
67
  ])
66
68
 
67
69
  // RUBY
@@ -267,6 +267,8 @@ export default class HttpServer {
267
267
  override: false,
268
268
  })
269
269
 
270
+ response.headers = headers
271
+
270
272
  if (typeof result === "string") {
271
273
  response.source = stringify(result)
272
274
  } else if (result && result.body !== undefined) {
@@ -1,7 +1,8 @@
1
1
  function parseResource(resource) {
2
- const [, region, accountId, restApiId, path] = resource.match(
3
- /arn:aws:execute-api:(.*?):(.*?):(.*?)\/(.*)/,
4
- )
2
+ const [, region = "*", accountId = "*", restApiId = "*", path = "*"] =
3
+ resource.match(
4
+ /arn:aws:execute-api:([^\s:]+)(?::([^\s:]+))?(?::([^\s/:]+))?(?:\/(.*))?/,
5
+ )
5
6
 
6
7
  return {
7
8
  accountId,
@@ -26,10 +27,6 @@ export default function authMatchPolicyResource(policyResource, resource) {
26
27
  return true
27
28
  }
28
29
 
29
- if (policyResource === "arn:aws:execute-api:*:*:*") {
30
- return true
31
- }
32
-
33
30
  if (policyResource.includes("*") || policyResource.includes("?")) {
34
31
  // Policy contains a wildcard resource
35
32
 
@@ -61,7 +58,7 @@ export default function authMatchPolicyResource(policyResource, resource) {
61
58
  // for the requested resource and the resource defined in the policy
62
59
  // Need to create a regex replacing ? with one character and * with any number of characters
63
60
  const regExp = new RegExp(
64
- parsedPolicyResource.path.replaceAll("*", ".*").replaceAll("?", "."),
61
+ `${parsedPolicyResource.path.replaceAll("*", ".*").replaceAll("?", ".")}$`,
65
62
  )
66
63
 
67
64
  return regExp.test(parsedResource.path)
@@ -295,7 +295,7 @@ export default class HttpServer {
295
295
  return null
296
296
  }
297
297
 
298
- const authFunctionName = this.#extractAuthFunctionName(endpoint)
298
+ let authFunctionName = this.#extractAuthFunctionName(endpoint)
299
299
 
300
300
  if (!authFunctionName) {
301
301
  return null
@@ -303,16 +303,32 @@ export default class HttpServer {
303
303
 
304
304
  log.notice(`Configuring Authorization: ${path} ${authFunctionName}`)
305
305
 
306
+ const standardFunctionExists =
307
+ this.#serverless.service.functions &&
308
+ this.#serverless.service.functions[authFunctionName]
309
+ const serverlessAuthorizerOptions =
310
+ this.#serverless.service.provider.httpApi &&
311
+ this.#serverless.service.provider.httpApi.authorizers &&
312
+ this.#serverless.service.provider.httpApi.authorizers[authFunctionName]
313
+
314
+ if (
315
+ !standardFunctionExists &&
316
+ endpoint.isHttpApi &&
317
+ serverlessAuthorizerOptions &&
318
+ serverlessAuthorizerOptions.functionName
319
+ ) {
320
+ log.notice(
321
+ `Redirecting authorizer function: ${authFunctionName} to ${serverlessAuthorizerOptions.functionName}`,
322
+ )
323
+ authFunctionName = serverlessAuthorizerOptions.functionName
324
+ }
325
+
306
326
  const authFunction = this.#serverless.service.getFunction(authFunctionName)
307
327
 
308
328
  if (!authFunction) {
309
329
  log.error(`Authorization function ${authFunctionName} does not exist`)
310
330
  return null
311
331
  }
312
- const serverlessAuthorizerOptions =
313
- this.#serverless.service.provider.httpApi &&
314
- this.#serverless.service.provider.httpApi.authorizers &&
315
- this.#serverless.service.provider.httpApi.authorizers[authFunctionName]
316
332
 
317
333
  const authorizerOptions = {
318
334
  enableSimpleResponses:
@@ -326,7 +342,8 @@ export default class HttpServer {
326
342
  ? serverlessAuthorizerOptions?.payloadVersion || "2.0"
327
343
  : "1.0",
328
344
  resultTtlInSeconds:
329
- serverlessAuthorizerOptions?.resultTtlInSeconds || "300",
345
+ serverlessAuthorizerOptions?.resultTtlInSeconds ?? "300",
346
+ type: endpoint.isHttpApi ? serverlessAuthorizerOptions?.type : undefined,
330
347
  }
331
348
 
332
349
  if (
@@ -339,11 +356,10 @@ export default class HttpServer {
339
356
  return null
340
357
  }
341
358
 
342
- if (typeof endpoint.authorizer === "string") {
343
- authorizerOptions.name = authFunctionName
344
- } else {
359
+ if (typeof endpoint.authorizer !== "string") {
345
360
  assign(authorizerOptions, endpoint.authorizer)
346
361
  }
362
+ authorizerOptions.name = authFunctionName
347
363
 
348
364
  if (
349
365
  !authorizerOptions.identitySource &&
@@ -443,7 +459,7 @@ export default class HttpServer {
443
459
  request.payload = request.payload && request.payload.toString(encoding)
444
460
  request.rawPayload = request.payload
445
461
 
446
- // incomming request message
462
+ // incoming request message
447
463
  log.notice()
448
464
 
449
465
  log.notice()
@@ -143,6 +143,8 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
143
143
  event = {
144
144
  ...event,
145
145
  identitySource: [finalAuthorization],
146
+ pathParameters: nullIfEmpty(pathParams),
147
+ queryStringParameters: parseQueryStringParameters(url),
146
148
  rawPath: request.path,
147
149
  rawQueryString: getRawQueryParams(url),
148
150
  requestContext: {
@@ -5,7 +5,7 @@ import { log } from "../../utils/log.js"
5
5
  const { isArray } = Array
6
6
  const { now } = Date
7
7
 
8
- export default function createAuthScheme(jwtOptions) {
8
+ export default function createJWTAuthScheme(jwtOptions) {
9
9
  const authorizerName = jwtOptions.name
10
10
 
11
11
  const identitySourceMatch = /^\$request.header.((?:\w+-?)+\w+)$/.exec(
@@ -43,7 +43,7 @@ export default function createAuthScheme(jwtOptions) {
43
43
  return Boom.unauthorized("JWT Token expired")
44
44
  }
45
45
 
46
- const { aud, iss, scope, client_id: clientId } = claims
46
+ const { aud, iss, scope, scp, client_id: clientId } = claims
47
47
  if (iss !== jwtOptions.issuerUrl) {
48
48
  log.notice(`JWT Token not from correct issuer url`)
49
49
 
@@ -68,13 +68,13 @@ export default function createAuthScheme(jwtOptions) {
68
68
 
69
69
  let scopes = null
70
70
  if (jwtOptions.scopes && jwtOptions.scopes.length > 0) {
71
- if (!scope) {
71
+ if (!scope && !scp) {
72
72
  log.notice(`JWT Token missing valid scope`)
73
73
 
74
74
  return Boom.forbidden("JWT Token missing valid scope")
75
75
  }
76
76
 
77
- scopes = scope.split(" ")
77
+ scopes = scp || scope.split(" ")
78
78
  if (scopes.every((s) => !jwtOptions.scopes.includes(s))) {
79
79
  log.notice(`JWT Token missing valid scope`)
80
80
 
@@ -85,7 +85,6 @@ export default function createAuthScheme(jwtOptions) {
85
85
  log.notice(`JWT Token validated`)
86
86
 
87
87
  // Set the credentials for the rest of the pipeline
88
- // return resolve(
89
88
  return h.authenticated({
90
89
  credentials: {
91
90
  claims,
@@ -134,8 +134,8 @@ export default class LambdaProxyIntegrationEvent {
134
134
  if (token) {
135
135
  try {
136
136
  claims = decodeJwt(token)
137
- if (claims.scope) {
138
- scopes = claims.scope.split(" ")
137
+ if (claims.scp || claims.scope) {
138
+ scopes = claims.scp || claims.scope.split(" ")
139
139
  // In AWS HTTP Api the scope property is removed from the decoded JWT
140
140
  // I'm leaving this property because I'm not sure how all of the authorizers
141
141
  // for AWS REST Api handle JWT.
@@ -120,8 +120,8 @@ export default class LambdaProxyIntegrationEventV2 {
120
120
  if (token) {
121
121
  try {
122
122
  claims = decodeJwt(token)
123
- if (claims.scope) {
124
- scopes = claims.scope.split(" ")
123
+ if (claims.scp || claims.scope) {
124
+ scopes = claims.scp || claims.scope.split(" ")
125
125
  // In AWS HTTP Api the scope property is removed from the decoded JWT
126
126
  // I'm leaving this property because I'm not sure how all of the authorizers
127
127
  // for AWS REST Api handle JWT.
@@ -10,7 +10,7 @@ const { assign, entries, fromEntries } = Object
10
10
 
11
11
  function escapeJavaScript(x) {
12
12
  if (typeof x === "string") {
13
- return jsEscapeString(x).replaceAll("\\n", "\n") // See #26,
13
+ return jsEscapeString(x).replaceAll(String.raw`\n`, "\n") // See #26,
14
14
  }
15
15
 
16
16
  if (isPlainObject(x)) {
@@ -0,0 +1,32 @@
1
+ /* eslint-disable max-classes-per-file */
2
+ /**
3
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ *
5
+ * This code was copied from:
6
+ * https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/Errors.js
7
+ *
8
+ * Defines custom error types throwable by the runtime.
9
+ */
10
+
11
+ "use strict"
12
+
13
+ const errorClasses = [
14
+ class ImportModuleError extends Error {},
15
+ class HandlerNotFound extends Error {},
16
+ class MalformedHandlerName extends Error {},
17
+ class UserCodeSyntaxError extends Error {},
18
+ class MalformedStreamingHandler extends Error {},
19
+ class InvalidStreamingOperation extends Error {},
20
+ class UnhandledPromiseRejection extends Error {
21
+ constructor(reason, promise) {
22
+ super(reason)
23
+ this.reason = reason
24
+ this.promise = promise
25
+ }
26
+ },
27
+ ]
28
+
29
+ errorClasses.forEach((e) => {
30
+ module.exports[e.name] = e
31
+ e.prototype.name = `Runtime.${e.name}`
32
+ })
@@ -0,0 +1,38 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ /* eslint-disable no-param-reassign */
3
+ /**
4
+ * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ *
6
+ * This code was copied from:
7
+ * https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/HttpResponseStream.js
8
+ *
9
+ * HttpResponseStream is NOT used by the runtime.
10
+ * It is only exposed in the `awslambda` variable for customers to use.
11
+ */
12
+
13
+ "use strict"
14
+
15
+ const METADATA_PRELUDE_CONTENT_TYPE =
16
+ "application/vnd.awslambda.http-integration-response"
17
+ const DELIMITER_LEN = 8
18
+
19
+ // Implements the application/vnd.awslambda.http-integration-response content type.
20
+ class HttpResponseStream {
21
+ static from(underlyingStream, prelude) {
22
+ underlyingStream.setContentType(METADATA_PRELUDE_CONTENT_TYPE)
23
+
24
+ // JSON.stringify is required. NULL byte is not allowed in metadataPrelude.
25
+ const metadataPrelude = JSON.stringify(prelude)
26
+
27
+ underlyingStream._onBeforeFirstWrite = (write) => {
28
+ write(metadataPrelude)
29
+
30
+ // Write 8 null bytes after the JSON prelude.
31
+ write(new Uint8Array(DELIMITER_LEN))
32
+ }
33
+
34
+ return underlyingStream
35
+ }
36
+ }
37
+
38
+ module.exports.HttpResponseStream = HttpResponseStream