serverless-offline 10.3.1 → 10.3.2

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,7 @@
1
1
  {
2
2
  "dedicatedTo": "Blue, a great migrating bird.",
3
3
  "name": "serverless-offline",
4
- "version": "10.3.1",
4
+ "version": "10.3.2",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -1,19 +1,11 @@
1
- import { log } from '@serverless/utils/log.js'
2
1
  import HttpEventDefinition from './HttpEventDefinition.js'
3
2
  import HttpServer from './HttpServer.js'
4
- import { orange } from '../../config/colors.js'
5
- import { createApiKey } from '../../utils/index.js'
6
3
 
7
4
  export default class Http {
8
- #hasPrivateHttpEvent = false
9
-
10
5
  #httpServer = null
11
6
 
12
- #options = null
13
-
14
7
  constructor(serverless, options, lambda) {
15
8
  this.#httpServer = new HttpServer(serverless, options, lambda)
16
- this.#options = options
17
9
  }
18
10
 
19
11
  start() {
@@ -38,36 +30,8 @@ export default class Http {
38
30
  create(events) {
39
31
  events.forEach(({ functionKey, handler, http }) => {
40
32
  this.#createEvent(functionKey, http, handler)
41
-
42
- if (http.private) {
43
- this.#hasPrivateHttpEvent = true
44
- }
45
33
  })
46
34
 
47
- if (this.#hasPrivateHttpEvent) {
48
- if (this.#options.apiKey) {
49
- log.notice()
50
- log.warning(
51
- orange(`'--apiKey' is deprecated and will be removed in the next major version.
52
- Please define the apiKey value in the 'provider.apiGateway.apiKeys' section of the serverless config.
53
- If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
54
- )
55
- log.notice()
56
- } else {
57
- this.#options.apiKey = createApiKey()
58
- }
59
-
60
- log.notice(`Key with token: ${this.#options.apiKey}`)
61
-
62
- if (this.#options.noAuth) {
63
- log.notice(
64
- `Authorizers are turned off. You do not need to use 'x-api-key' header.`,
65
- )
66
- } else {
67
- log.notice(`Remember to use 'x-api-key' on the request headers.`)
68
- }
69
- }
70
-
71
35
  this.#httpServer.writeRoutesTerminal()
72
36
  }
73
37
 
@@ -20,8 +20,10 @@ import {
20
20
  import LambdaProxyIntegrationEventV2 from './lambda-events/LambdaProxyIntegrationEventV2.js'
21
21
  import parseResources from './parseResources.js'
22
22
  import payloadSchemaValidator from './payloadSchemaValidator.js'
23
+ import { orange } from '../../config/colors.js'
23
24
  import logRoutes from '../../utils/logRoutes.js'
24
25
  import {
26
+ createApiKey,
25
27
  detectEncoding,
26
28
  generateHapiPath,
27
29
  getApiKeysValues,
@@ -36,21 +38,19 @@ const { assign, entries, keys } = Object
36
38
  export default class HttpServer {
37
39
  #apiKeysValues = null
38
40
 
41
+ #hasPrivateHttpEvent = false
42
+
39
43
  #lambda = null
40
44
 
41
45
  #options = null
42
46
 
43
- #serverless = null
44
-
45
47
  #server = null
46
48
 
49
+ #serverless = null
50
+
47
51
  #terminalInfo = []
48
52
 
49
53
  constructor(serverless, options, lambda) {
50
- this.#apiKeysValues = getApiKeysValues(
51
- serverless.service.provider.apiGateway?.apiKeys ?? [],
52
- )
53
-
54
54
  this.#lambda = lambda
55
55
  this.#options = options
56
56
  this.#serverless = serverless
@@ -435,10 +435,7 @@ export default class HttpServer {
435
435
  const apiKey = request.headers['x-api-key']
436
436
 
437
437
  if (apiKey) {
438
- if (
439
- apiKey !== this.#options.apiKey &&
440
- !this.#apiKeysValues.has(apiKey)
441
- ) {
438
+ if (!this.#apiKeysValues.has(apiKey)) {
442
439
  log.debug(
443
440
  `Method '${method}' of function '${functionKey}' token '${apiKey}' not valid.`,
444
441
  )
@@ -452,10 +449,7 @@ export default class HttpServer {
452
449
  ) {
453
450
  const { usageIdentifierKey } = request.auth.credentials
454
451
 
455
- if (
456
- usageIdentifierKey !== this.#options.apiKey &&
457
- !this.#apiKeysValues.has(usageIdentifierKey)
458
- ) {
452
+ if (!this.#apiKeysValues.has(usageIdentifierKey)) {
459
453
  log.debug(
460
454
  `Method '${method}' of function '${functionKey}' token '${usageIdentifierKey}' not valid.`,
461
455
  )
@@ -898,6 +892,40 @@ export default class HttpServer {
898
892
  }
899
893
 
900
894
  createRoutes(functionKey, httpEvent, handler) {
895
+ if (!this.#hasPrivateHttpEvent && httpEvent.private) {
896
+ this.#hasPrivateHttpEvent = true
897
+
898
+ if (this.#options.apiKey) {
899
+ log.notice()
900
+ log.warning(
901
+ orange(`'--apiKey' is deprecated and will be removed in the next major version.
902
+ Please define the apiKey value in the 'provider.apiGateway.apiKeys' section of the serverless config.
903
+ If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
904
+ )
905
+ log.notice()
906
+ }
907
+
908
+ if (this.#options.noAuth) {
909
+ log.notice(
910
+ `Authorizers are turned off. You do not need to use 'x-api-key' header.`,
911
+ )
912
+ } else {
913
+ log.notice(`Remember to use 'x-api-key' on the request headers.`)
914
+ }
915
+
916
+ if (this.#apiKeysValues == null) {
917
+ const apiKey = this.#options.apiKey ?? createApiKey()
918
+
919
+ log.notice(`Key with token: ${apiKey}`)
920
+
921
+ this.#apiKeysValues = getApiKeysValues(
922
+ this.#serverless.service.provider.apiGateway?.apiKeys ?? [],
923
+ )
924
+
925
+ this.#apiKeysValues.add(apiKey)
926
+ }
927
+ }
928
+
901
929
  let method
902
930
  let path
903
931
  let hapiPath