serverless-offline 10.3.1 → 11.0.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/README.md CHANGED
@@ -108,13 +108,6 @@ to list all the options for the plugin run:
108
108
 
109
109
  All CLI options are optional:
110
110
 
111
- #### apiKey
112
-
113
- _This option is deprecated and will be removed in the next major version. If you want to specify the apiKey value yourself, please define it under 'provider.apiGateway.apiKeys' in the serverless config._
114
-
115
- Defines the API key value to be used for endpoints marked as private.<br />
116
- Defaults to a random value.
117
-
118
111
  #### corsAllowHeaders
119
112
 
120
113
  Used as default Access-Control-Allow-Headers header value for responses. Delimit multiple values with commas.<br />
@@ -139,12 +132,6 @@ Default: 'WWW-Authenticate,Server-Authorization'
139
132
 
140
133
  Used to disable cookie-validation on hapi.js-server.
141
134
 
142
- #### disableScheduledEvents
143
-
144
- _This option is deprecated and will be removed in the next major version. If you want to disable the event, please define it in the 'events.schedule.enabled' section of the serverless config._
145
-
146
- Disables all scheduled events. Overrides configurations in serverless.yml.
147
-
148
135
  #### dockerHost
149
136
 
150
137
  The host name of Docker.<br />
@@ -183,7 +170,7 @@ Default: 3000
183
170
 
184
171
  #### ignoreJWTSignature
185
172
 
186
- When using HttpApi with a JWT authorizer, don't check the signature of the JWT token. This should only be used for local development.
173
+ When using HttpApi with a JWT authorizer, don't check the signature of the JWT token.
187
174
 
188
175
  #### lambdaPort
189
176
 
@@ -484,7 +471,7 @@ By default layers are downloaded on a per-project basis, however, if you want to
484
471
 
485
472
  As defined in the [Serverless Documentation](https://serverless.com/framework/docs/providers/aws/events/apigateway/#setting-api-keys-for-your-rest-api) you can use API Keys as a simple authentication method.
486
473
 
487
- Serverless-offline will emulate the behaviour of APIG and create a random token that's printed on the screen. With this token you can access your private methods adding `x-api-key: generatedToken` to your request header. All api keys will share the same token. To specify a custom token use the `--apiKey` cli option.
474
+ Serverless-offline will emulate the behaviour of APIG and create a random token that's printed on the screen. With this token you can access your private methods adding `x-api-key: generatedToken` to your request header. All api keys will share the same token.
488
475
 
489
476
  ### Custom authorizers
490
477
 
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": "11.0.0",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -86,13 +86,13 @@
86
86
  "@hapi/h2o2": "^10.0.0",
87
87
  "@hapi/hapi": "^20.2.2",
88
88
  "@serverless/utils": "^6.7.0",
89
- "aws-sdk": "^2.1224.0",
89
+ "aws-sdk": "^2.1225.0",
90
90
  "boxen": "^7.0.0",
91
91
  "chalk": "^5.0.1",
92
92
  "execa": "^6.1.0",
93
93
  "fs-extra": "^10.1.0",
94
94
  "java-invoke-local": "0.0.6",
95
- "jose": "^4.9.3",
95
+ "jose": "^4.10.0",
96
96
  "js-string-escape": "^1.0.1",
97
97
  "jsonpath-plus": "^7.2.0",
98
98
  "jsonschema": "^1.4.1",
@@ -6,7 +6,7 @@ import {
6
6
  defaultOptions,
7
7
  SERVER_SHUTDOWN_TIMEOUT,
8
8
  } from './config/index.js'
9
- import { gray, orange } from './config/colors.js'
9
+ import { gray } from './config/colors.js'
10
10
 
11
11
  export default class ServerlessOffline {
12
12
  #cliOptions = null
@@ -61,16 +61,6 @@ export default class ServerlessOffline {
61
61
  async start() {
62
62
  this.#mergeOptions()
63
63
 
64
- if (this.#options.disableScheduledEvents) {
65
- log.notice()
66
- log.warning(
67
- orange(`'--disableScheduledEvents' is deprecated and will be removed in the next major version.
68
- Please disable the event in the 'events.schedule.enabled' section of the serverless config.
69
- If you are experiencing any issues please let us know: https://github.com/dherault/serverless-offline/issues`),
70
- )
71
- log.notice()
72
- }
73
-
74
64
  const { httpEvents, lambdas, scheduleEvents, webSocketEvents } =
75
65
  this.#getEvents()
76
66
 
@@ -84,7 +74,7 @@ If you are experiencing any issues please let us know: https://github.com/dherau
84
74
  eventModules.push(this.#createHttp(httpEvents))
85
75
  }
86
76
 
87
- if (!this.#options.disableScheduledEvents && scheduleEvents.length > 0) {
77
+ if (scheduleEvents.length > 0) {
88
78
  eventModules.push(this.#createSchedule(scheduleEvents))
89
79
  }
90
80
 
@@ -1,9 +1,4 @@
1
1
  export default {
2
- apiKey: {
3
- type: 'string',
4
- usage:
5
- '[This option is deprecated] Defines the API key value to be used for endpoints marked as private. Defaults to a random hash.',
6
- },
7
2
  corsAllowHeaders: {
8
3
  type: 'string',
9
4
  usage:
@@ -28,11 +23,6 @@ export default {
28
23
  type: 'boolean',
29
24
  usage: 'Used to disable cookie-validation on hapi.js-server.',
30
25
  },
31
- disableScheduledEvents: {
32
- type: 'boolean',
33
- usage:
34
- '[This option is deprecated] Disables all scheduled events. Overrides configurations in serverless.yml. Default: false.',
35
- },
36
26
  dockerHost: {
37
27
  type: 'string',
38
28
  usage: 'The host name of Docker. Default: localhost.',
@@ -72,7 +62,7 @@ export default {
72
62
  ignoreJWTSignature: {
73
63
  type: 'boolean',
74
64
  usage:
75
- "When using HttpApi with a JWT authorizer, don't check the signature of the JWT token. This should only be used for local development.",
65
+ "When using HttpApi with a JWT authorizer, don't check the signature of the JWT token.",
76
66
  },
77
67
  lambdaPort: {
78
68
  type: 'string',
@@ -1,11 +1,9 @@
1
1
  export default {
2
- apiKey: null,
3
2
  corsAllowHeaders: 'accept,content-type,x-api-key,authorization',
4
3
  corsAllowOrigin: '*',
5
4
  corsDisallowCredentials: true,
6
5
  corsExposedHeaders: 'WWW-Authenticate,Server-Authorization',
7
6
  disableCookieValidation: false,
8
- disableScheduledEvents: false,
9
7
  dockerHost: 'localhost',
10
8
  dockerHostServicePath: null,
11
9
  dockerNetwork: null,
@@ -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
 
@@ -22,6 +22,7 @@ import parseResources from './parseResources.js'
22
22
  import payloadSchemaValidator from './payloadSchemaValidator.js'
23
23
  import logRoutes from '../../utils/logRoutes.js'
24
24
  import {
25
+ createApiKey,
25
26
  detectEncoding,
26
27
  generateHapiPath,
27
28
  getApiKeysValues,
@@ -36,21 +37,19 @@ const { assign, entries, keys } = Object
36
37
  export default class HttpServer {
37
38
  #apiKeysValues = null
38
39
 
40
+ #hasPrivateHttpEvent = false
41
+
39
42
  #lambda = null
40
43
 
41
44
  #options = null
42
45
 
43
- #serverless = null
44
-
45
46
  #server = null
46
47
 
48
+ #serverless = null
49
+
47
50
  #terminalInfo = []
48
51
 
49
52
  constructor(serverless, options, lambda) {
50
- this.#apiKeysValues = getApiKeysValues(
51
- serverless.service.provider.apiGateway?.apiKeys ?? [],
52
- )
53
-
54
53
  this.#lambda = lambda
55
54
  this.#options = options
56
55
  this.#serverless = serverless
@@ -435,10 +434,7 @@ export default class HttpServer {
435
434
  const apiKey = request.headers['x-api-key']
436
435
 
437
436
  if (apiKey) {
438
- if (
439
- apiKey !== this.#options.apiKey &&
440
- !this.#apiKeysValues.has(apiKey)
441
- ) {
437
+ if (!this.#apiKeysValues.has(apiKey)) {
442
438
  log.debug(
443
439
  `Method '${method}' of function '${functionKey}' token '${apiKey}' not valid.`,
444
440
  )
@@ -452,10 +448,7 @@ export default class HttpServer {
452
448
  ) {
453
449
  const { usageIdentifierKey } = request.auth.credentials
454
450
 
455
- if (
456
- usageIdentifierKey !== this.#options.apiKey &&
457
- !this.#apiKeysValues.has(usageIdentifierKey)
458
- ) {
451
+ if (!this.#apiKeysValues.has(usageIdentifierKey)) {
459
452
  log.debug(
460
453
  `Method '${method}' of function '${functionKey}' token '${usageIdentifierKey}' not valid.`,
461
454
  )
@@ -898,6 +891,28 @@ export default class HttpServer {
898
891
  }
899
892
 
900
893
  createRoutes(functionKey, httpEvent, handler) {
894
+ if (!this.#hasPrivateHttpEvent && httpEvent.private) {
895
+ this.#hasPrivateHttpEvent = true
896
+
897
+ if (this.#options.noAuth) {
898
+ log.notice(
899
+ `Authorizers are turned off. You do not need to use 'x-api-key' header.`,
900
+ )
901
+ } else {
902
+ log.notice(`Remember to use 'x-api-key' on the request headers.`)
903
+ }
904
+
905
+ if (this.#apiKeysValues == null) {
906
+ const apiKey = createApiKey()
907
+
908
+ this.#apiKeysValues = getApiKeysValues(
909
+ this.#serverless.service.provider.apiGateway?.apiKeys ?? [apiKey],
910
+ )
911
+
912
+ log.notice(`Key with token: ${apiKey}`)
913
+ }
914
+ }
915
+
901
916
  let method
902
917
  let path
903
918
  let hapiPath