@middy/ws-response 6.1.6 → 6.2.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.
Files changed (3) hide show
  1. package/index.d.ts +19 -16
  2. package/index.js +53 -55
  3. package/package.json +71 -74
package/index.d.ts CHANGED
@@ -1,21 +1,24 @@
1
- import { ApiGatewayManagementApiClient, ApiGatewayManagementApiClientConfig } from '@aws-sdk/client-apigatewaymanagementapi'
2
- import middy from '@middy/core'
3
- import { Options as MiddyOptions } from '@middy/util'
1
+ import type {
2
+ ApiGatewayManagementApiClient,
3
+ ApiGatewayManagementApiClientConfig,
4
+ } from "@aws-sdk/client-apigatewaymanagementapi";
5
+ import type middy from "@middy/core";
6
+ import type { Options as MiddyOptions } from "@middy/util";
4
7
 
5
8
  interface Options<
6
- AwsApiGatewayManagementApiClient = ApiGatewayManagementApiClient
9
+ AwsApiGatewayManagementApiClient = ApiGatewayManagementApiClient,
7
10
  > extends Pick<
8
- MiddyOptions<
9
- AwsApiGatewayManagementApiClient,
10
- ApiGatewayManagementApiClientConfig
11
- >,
12
- | 'AwsClient'
13
- | 'awsClientOptions'
14
- | 'awsClientAssumeRole'
15
- | 'awsClientCapture'
16
- | 'disablePrefetch'
17
- > {}
11
+ MiddyOptions<
12
+ AwsApiGatewayManagementApiClient,
13
+ ApiGatewayManagementApiClientConfig
14
+ >,
15
+ | "AwsClient"
16
+ | "awsClientOptions"
17
+ | "awsClientAssumeRole"
18
+ | "awsClientCapture"
19
+ | "disablePrefetch"
20
+ > {}
18
21
 
19
- declare function wsResponse (options?: Options): middy.MiddlewareObj
22
+ declare function wsResponse(options?: Options): middy.MiddlewareObj;
20
23
 
21
- export default wsResponse
24
+ export default wsResponse;
package/index.js CHANGED
@@ -1,73 +1,71 @@
1
1
  import {
2
- ApiGatewayManagementApiClient,
3
- PostToConnectionCommand
4
- } from '@aws-sdk/client-apigatewaymanagementapi'
2
+ ApiGatewayManagementApiClient,
3
+ PostToConnectionCommand,
4
+ } from "@aws-sdk/client-apigatewaymanagementapi";
5
5
 
6
6
  import {
7
- canPrefetch,
8
- createClient,
9
- createPrefetchClient,
10
- catchInvalidSignatureException
11
- } from '@middy/util'
7
+ canPrefetch,
8
+ catchInvalidSignatureException,
9
+ createClient,
10
+ createPrefetchClient,
11
+ } from "@middy/util";
12
12
 
13
13
  const defaults = {
14
- AwsClient: ApiGatewayManagementApiClient,
15
- awsClientOptions: {}, // { endpoint }
16
- awsClientAssumeRole: undefined,
17
- awsClientCapture: undefined,
18
- disablePrefetch: false
19
- }
14
+ AwsClient: ApiGatewayManagementApiClient,
15
+ awsClientOptions: {}, // { endpoint }
16
+ awsClientAssumeRole: undefined,
17
+ awsClientCapture: undefined,
18
+ disablePrefetch: false,
19
+ };
20
20
 
21
21
  const wsResponseMiddleware = (opts) => {
22
- const options = { ...defaults, ...opts }
22
+ const options = { ...defaults, ...opts };
23
23
 
24
- let client
25
- if (canPrefetch(options) && options.awsClientOptions.endpoint) {
26
- client = createPrefetchClient(options)
27
- }
24
+ let client;
25
+ if (canPrefetch(options) && options.awsClientOptions.endpoint) {
26
+ client = createPrefetchClient(options);
27
+ }
28
28
 
29
- const wsResponseMiddlewareAfter = async (request) => {
30
- const normalizedResponse = normalizeWsResponse(request)
29
+ const wsResponseMiddlewareAfter = async (request) => {
30
+ const normalizedResponse = normalizeWsResponse(request);
31
31
 
32
- if (!normalizedResponse.ConnectionId) return
32
+ if (!normalizedResponse.ConnectionId) return;
33
33
 
34
- if (!options.awsClientOptions.endpoint && request.event.requestContext) {
35
- options.awsClientOptions.endpoint =
36
- 'https://' +
37
- request.event.requestContext.domainName +
38
- '/' +
39
- request.event.requestContext.stage
40
- }
41
- if (!client) {
42
- client = await createClient(options, request)
43
- }
34
+ if (!options.awsClientOptions.endpoint && request.event.requestContext) {
35
+ options.awsClientOptions.endpoint = `https://${
36
+ request.event.requestContext.domainName
37
+ }/${request.event.requestContext.stage}`;
38
+ }
39
+ if (!client) {
40
+ client = await createClient(options, request);
41
+ }
44
42
 
45
- const command = new PostToConnectionCommand(normalizedResponse)
46
- await client
47
- .send(command)
48
- .catch((e) => catchInvalidSignatureException(e, client, command))
43
+ const command = new PostToConnectionCommand(normalizedResponse);
44
+ await client
45
+ .send(command)
46
+ .catch((e) => catchInvalidSignatureException(e, client, command));
49
47
 
50
- request.response = { statusCode: 200 }
51
- }
48
+ request.response = { statusCode: 200 };
49
+ };
52
50
 
53
- return {
54
- after: wsResponseMiddlewareAfter
55
- }
56
- }
51
+ return {
52
+ after: wsResponseMiddlewareAfter,
53
+ };
54
+ };
57
55
 
58
56
  // TODO move to @middy/util?
59
57
  const normalizeWsResponse = (request) => {
60
- let { response } = request
61
- if (typeof response === 'undefined') {
62
- response = {}
63
- } else if (
64
- typeof response?.Data === 'undefined' &&
65
- typeof response?.ConnectionId === 'undefined'
66
- ) {
67
- response = { Data: response }
68
- }
69
- response.ConnectionId ??= request.event.requestContext?.connectionId
70
- return response
71
- }
58
+ let { response } = request;
59
+ if (typeof response === "undefined") {
60
+ response = {};
61
+ } else if (
62
+ typeof response?.Data === "undefined" &&
63
+ typeof response?.ConnectionId === "undefined"
64
+ ) {
65
+ response = { Data: response };
66
+ }
67
+ response.ConnectionId ??= request.event.requestContext?.connectionId;
68
+ return response;
69
+ };
72
70
 
73
- export default wsResponseMiddleware
71
+ export default wsResponseMiddleware;
package/package.json CHANGED
@@ -1,76 +1,73 @@
1
1
  {
2
- "name": "@middy/ws-response",
3
- "version": "6.1.6",
4
- "description": "WebSocket response handling middleware for the middy framework",
5
- "type": "module",
6
- "engines": {
7
- "node": ">=20"
8
- },
9
- "engineStrict": true,
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "module": "./index.js",
14
- "exports": {
15
- ".": {
16
- "import": {
17
- "types": "./index.d.ts",
18
- "default": "./index.js"
19
- },
20
- "require": {
21
- "default": "./index.js"
22
- }
23
- }
24
- },
25
- "types": "index.d.ts",
26
- "files": [
27
- "index.js",
28
- "index.d.ts"
29
- ],
30
- "scripts": {
31
- "test": "npm run test:unit && npm run test:fuzz",
32
- "test:unit": "node --test __tests__/index.js",
33
- "test:fuzz": "node --test __tests__/fuzz.js",
34
- "test:benchmark": "node __benchmarks__/index.js"
35
- },
36
- "license": "MIT",
37
- "keywords": [
38
- "Lambda",
39
- "Middleware",
40
- "Serverless",
41
- "Framework",
42
- "AWS",
43
- "AWS Lambda",
44
- "Middy",
45
- "API Gateway",
46
- "WebSocket",
47
- "PostToConnection"
48
- ],
49
- "author": {
50
- "name": "Middy contributors",
51
- "url": "https://github.com/middyjs/middy/graphs/contributors"
52
- },
53
- "repository": {
54
- "type": "git",
55
- "url": "git+https://github.com/middyjs/middy.git",
56
- "directory": "packages/sts"
57
- },
58
- "bugs": {
59
- "url": "https://github.com/middyjs/middy/issues"
60
- },
61
- "homepage": "https://middy.js.org",
62
- "funding": {
63
- "type": "github",
64
- "url": "https://github.com/sponsors/willfarrell"
65
- },
66
- "dependencies": {
67
- "@middy/util": "6.1.6"
68
- },
69
- "devDependencies": {
70
- "@aws-sdk/client-apigatewaymanagementapi": "^3.0.0",
71
- "@middy/core": "6.1.6",
72
- "@types/aws-lambda": "^8.10.97",
73
- "aws-xray-sdk": "^3.3.3"
74
- },
75
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
2
+ "name": "@middy/ws-response",
3
+ "version": "6.2.0",
4
+ "description": "WebSocket response handling middleware for the middy framework",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
9
+ "engineStrict": true,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "module": "./index.js",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./index.d.ts",
18
+ "default": "./index.js"
19
+ },
20
+ "require": {
21
+ "default": "./index.js"
22
+ }
23
+ }
24
+ },
25
+ "types": "index.d.ts",
26
+ "files": ["index.js", "index.d.ts"],
27
+ "scripts": {
28
+ "test": "npm run test:unit && npm run test:fuzz",
29
+ "test:unit": "node --test",
30
+ "test:fuzz": "node --test index.fuzz.js",
31
+ "test:perf": "node --test index.perf.js"
32
+ },
33
+ "license": "MIT",
34
+ "keywords": [
35
+ "Lambda",
36
+ "Middleware",
37
+ "Serverless",
38
+ "Framework",
39
+ "AWS",
40
+ "AWS Lambda",
41
+ "Middy",
42
+ "API Gateway",
43
+ "WebSocket",
44
+ "PostToConnection"
45
+ ],
46
+ "author": {
47
+ "name": "Middy contributors",
48
+ "url": "https://github.com/middyjs/middy/graphs/contributors"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/middyjs/middy.git",
53
+ "directory": "packages/sts"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/middyjs/middy/issues"
57
+ },
58
+ "homepage": "https://middy.js.org",
59
+ "funding": {
60
+ "type": "github",
61
+ "url": "https://github.com/sponsors/willfarrell"
62
+ },
63
+ "dependencies": {
64
+ "@middy/util": "6.2.0"
65
+ },
66
+ "devDependencies": {
67
+ "@aws-sdk/client-apigatewaymanagementapi": "^3.0.0",
68
+ "@middy/core": "6.2.0",
69
+ "@types/aws-lambda": "^8.10.97",
70
+ "aws-xray-sdk": "^3.3.3"
71
+ },
72
+ "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
76
73
  }