@middy/ws-response 3.6.1 → 4.0.0-alpha.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
@@ -47,19 +47,23 @@ npm install --save @middy/ws-response
47
47
  ```
48
48
 
49
49
  ## Options
50
- - `AwsClient` (object) (default `AWS.ApiGatewayManagementApi`): AWS.ApiGatewayManagementApi class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
51
- - `awsClientOptions` (object) (default `undefined`): Options to pass to AWS.ApiGatewayManagementApi class constructor.
50
+
51
+ - `AwsClient` (object) (default `ApiGatewayManagementApiClient`): ApiGatewayManagementApiClient class constructor (i.e. that has been instrumented with AWS XRay). Must be from `@aws-sdk/client-apigatewaymanagementapi`.
52
+ - `awsClientOptions` (object) (default `undefined`): Options to pass to ApiGatewayManagementApiClient class constructor.
52
53
  - `awsClientAssumeRole` (string) (default `undefined`): Internal key where secrets are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
53
54
  - `awsClientCapture` (function) (default `undefined`): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
54
55
  - `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
55
56
 
56
57
  NOTES:
58
+
57
59
  - Lambda is required to have IAM permission for `execute-api:ManageConnections`
58
60
  - If `awsClientOptions.endpoint` is not set it will be set using `event.requestContext.{domainName,stage}`
59
61
  - If response does not contain `ConnectId`, it will be set from `event.requestContext.connectionId`
60
62
 
61
63
  ## Sample usage
64
+
62
65
  ### API Gateway
66
+
63
67
  ```javascript
64
68
  import middy from '@middy/core'
65
69
  import wsResponse from '@middy/ws-response'
@@ -68,11 +72,11 @@ export const handler = middy((event, context) => {
68
72
  return 'message'
69
73
  })
70
74
 
71
- handler
72
- .use(wsResponse())
75
+ handler.use(wsResponse())
73
76
  ```
74
77
 
75
78
  ### General
79
+
76
80
  ```javascript
77
81
  import middy from '@middy/core'
78
82
  import wsResponse from '@middy/ws-response'
@@ -84,26 +88,23 @@ export const handler = middy((event, context) => {
84
88
  }
85
89
  })
86
90
 
87
- handler
88
- .use(wsResponse({
91
+ handler.use(
92
+ wsResponse({
89
93
  awsClientOptions: {
90
94
  endpoint: '...'
91
95
  }
92
- }))
96
+ })
97
+ )
93
98
  ```
94
99
 
95
-
96
-
97
100
  ## Middy documentation and examples
98
101
 
99
102
  For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
100
103
 
101
-
102
104
  ## Contributing
103
105
 
104
106
  Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
105
107
 
106
-
107
108
  ## License
108
109
 
109
110
  Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
package/index.cjs CHANGED
@@ -6,16 +6,10 @@ Object.defineProperty(module, "exports", {
6
6
  enumerable: true,
7
7
  get: ()=>_default
8
8
  });
9
- const _apigatewaymanagementapiJs = _interopRequireDefault(require("aws-sdk/clients/apigatewaymanagementapi.js"));
9
+ const _clientApigatewaymanagementapi = require("@aws-sdk/client-apigatewaymanagementapi");
10
10
  const _util = require("@middy/util");
11
- function _interopRequireDefault(obj) {
12
- return obj && obj.__esModule ? obj : {
13
- default: obj
14
- };
15
- }
16
- var _response;
17
11
  const defaults = {
18
- AwsClient: _apigatewaymanagementapiJs.default,
12
+ AwsClient: _clientApigatewaymanagementapi.ApiGatewayManagementApiClient,
19
13
  awsClientOptions: {},
20
14
  awsClientAssumeRole: undefined,
21
15
  awsClientCapture: undefined,
@@ -40,7 +34,7 @@ const wsResponseMiddleware = (opts)=>{
40
34
  if (!client) {
41
35
  client = await (0, _util.createClient)(options, request);
42
36
  }
43
- await client.postToConnection(response).promise();
37
+ await client.send(new _clientApigatewaymanagementapi.PostToConnectionCommand(response));
44
38
  request.response.statusCode = 200;
45
39
  };
46
40
  return {
@@ -56,7 +50,7 @@ const normalizeWsResponse = (request)=>{
56
50
  Data: response
57
51
  };
58
52
  }
59
- (_response = response).ConnectionId ?? (_response.ConnectionId = request.event.requestContext?.connectionId);
53
+ response.ConnectionId ??= request.event.requestContext?.connectionId;
60
54
  request.response = response;
61
55
  return response;
62
56
  };
package/index.d.ts CHANGED
@@ -1,11 +1,20 @@
1
- import ApiGatewayManagementApi from 'aws-sdk/clients/apigatewaymanagementapi'
1
+ import { ApiGatewayManagementApiClient, ApiGatewayManagementApiClientConfig } from '@aws-sdk/client-apigatewaymanagementapi'
2
2
  import middy from '@middy/core'
3
3
  import { Options as MiddyOptions } from '@middy/util'
4
4
 
5
- interface Options<S = ApiGatewayManagementApi>
6
- extends Pick<MiddyOptions<S, ApiGatewayManagementApi.Types.ClientConfiguration>,
7
- 'AwsClient' | 'awsClientOptions' | 'awsClientAssumeRole' | 'awsClientCapture' | 'disablePrefetch'> {
8
- }
5
+ interface Options<
6
+ AwsApiGatewayManagementApiClient = ApiGatewayManagementApiClient
7
+ > extends Pick<
8
+ MiddyOptions<
9
+ AwsApiGatewayManagementApiClient,
10
+ ApiGatewayManagementApiClientConfig
11
+ >,
12
+ | 'AwsClient'
13
+ | 'awsClientOptions'
14
+ | 'awsClientAssumeRole'
15
+ | 'awsClientCapture'
16
+ | 'disablePrefetch'
17
+ > {}
9
18
 
10
19
  declare function wsResponse (options?: Options): middy.MiddlewareObj
11
20
 
package/index.js CHANGED
@@ -1,8 +1,7 @@
1
- var _response;
2
- import ApiGatewayManagementApi from 'aws-sdk/clients/apigatewaymanagementapi.js';
1
+ import { ApiGatewayManagementApiClient, PostToConnectionCommand } from '@aws-sdk/client-apigatewaymanagementapi';
3
2
  import { canPrefetch, createClient, createPrefetchClient } from '@middy/util';
4
3
  const defaults = {
5
- AwsClient: ApiGatewayManagementApi,
4
+ AwsClient: ApiGatewayManagementApiClient,
6
5
  awsClientOptions: {},
7
6
  awsClientAssumeRole: undefined,
8
7
  awsClientCapture: undefined,
@@ -27,7 +26,7 @@ const wsResponseMiddleware = (opts)=>{
27
26
  if (!client) {
28
27
  client = await createClient(options, request);
29
28
  }
30
- await client.postToConnection(response).promise();
29
+ await client.send(new PostToConnectionCommand(response));
31
30
  request.response.statusCode = 200;
32
31
  };
33
32
  return {
@@ -43,7 +42,7 @@ const normalizeWsResponse = (request)=>{
43
42
  Data: response
44
43
  };
45
44
  }
46
- (_response = response).ConnectionId ?? (_response.ConnectionId = request.event.requestContext?.connectionId);
45
+ response.ConnectionId ??= request.event.requestContext?.connectionId;
47
46
  request.response = response;
48
47
  return response;
49
48
  };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@middy/ws-response",
3
- "version": "3.6.1",
3
+ "version": "4.0.0-alpha.0",
4
4
  "description": "WebSocket response handling middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=14"
7
+ "node": ">=16"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
@@ -61,13 +61,13 @@
61
61
  },
62
62
  "homepage": "https://middy.js.org",
63
63
  "dependencies": {
64
- "@middy/util": "3.6.1"
64
+ "@middy/util": "4.0.0-alpha.0"
65
65
  },
66
66
  "devDependencies": {
67
- "@middy/core": "3.6.1",
67
+ "@aws-sdk/client-apigatewaymanagementapi": "^3.186.0",
68
+ "@middy/core": "4.0.0-alpha.0",
68
69
  "@types/aws-lambda": "^8.10.97",
69
- "aws-sdk": "^2.939.0",
70
70
  "aws-xray-sdk": "^3.3.3"
71
71
  },
72
- "gitHead": "31a7f9f8e93a73a8be382b3022b9cfcbc13b2961"
72
+ "gitHead": "306fb9aa633d5757d11ced3dc192f046ef3c2685"
73
73
  }