@mstuercke/api-utils 3.1.1 → 4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"closeConnection.d.ts","sourceRoot":"","sources":["../../../src/ws/server/closeConnection.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAC;AAEzC,eAAO,MAAM,eAAe,+BAAoC,eAAe,kBAW9E,CAAC"}
1
+ {"version":3,"file":"closeConnection.d.ts","sourceRoot":"","sources":["../../../src/ws/server/closeConnection.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,UAAU,CAAC;AAGzC,eAAO,MAAM,eAAe,+BAAoC,eAAe,kBAW9E,CAAC"}
@@ -1,7 +1,8 @@
1
- import { ApiGatewayManagementApiClient, DeleteConnectionCommand } from '@aws-sdk/client-apigatewaymanagementapi';
1
+ import { DeleteConnectionCommand } from '@aws-sdk/client-apigatewaymanagementapi';
2
+ import { getApiGatewayManagementApiClient } from './getApiGatewayManagementApiClient';
2
3
  export const closeConnection = async ({ endpoint, connectionId }) => {
3
4
  try {
4
- await new ApiGatewayManagementApiClient({ endpoint }).send(new DeleteConnectionCommand({ ConnectionId: connectionId }));
5
+ await getApiGatewayManagementApiClient(endpoint).send(new DeleteConnectionCommand({ ConnectionId: connectionId }));
5
6
  }
6
7
  catch (err) {
7
8
  if (err && typeof err === 'object' && 'name' in err && err?.name === 'GoneException')
@@ -1 +1 @@
1
- {"version":3,"file":"closeConnection.js","sourceRoot":"","sources":["../../../src/ws/server/closeConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,6BAA6B,EAAE,uBAAuB,EAAC,MAAM,yCAAyC,CAAC;AAG/G,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAAC,QAAQ,EAAE,YAAY,EAAkB,EAAE,EAAE;IACjF,IAAI,CAAC;QACH,MAAM,IAAI,6BAA6B,CAAC,EAAC,QAAQ,EAAC,CAAC,CAAC,IAAI,CACpD,IAAI,uBAAuB,CAAC,EAAC,YAAY,EAAE,YAAY,EAAC,CAAC,CAC5D,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,IAAI,KAAK,eAAe;YAClF,OAAO;QAET,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"closeConnection.js","sourceRoot":"","sources":["../../../src/ws/server/closeConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,yCAAyC,CAAC;AAEhF,OAAO,EAAC,gCAAgC,EAAC,MAAM,oCAAoC,CAAC;AAEpF,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAAC,QAAQ,EAAE,YAAY,EAAkB,EAAE,EAAE;IACjF,IAAI,CAAC;QACH,MAAM,gCAAgC,CAAC,QAAQ,CAAC,CAAC,IAAI,CACjD,IAAI,uBAAuB,CAAC,EAAC,YAAY,EAAE,YAAY,EAAC,CAAC,CAC5D,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,IAAI,KAAK,eAAe;YAClF,OAAO;QAET,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ApiGatewayManagementApiClient } from '@aws-sdk/client-apigatewaymanagementapi';
2
+ export declare const getApiGatewayManagementApiClient: (endpoint: string) => ApiGatewayManagementApiClient;
3
+ //# sourceMappingURL=getApiGatewayManagementApiClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getApiGatewayManagementApiClient.d.ts","sourceRoot":"","sources":["../../../src/ws/server/getApiGatewayManagementApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,6BAA6B,EAAC,MAAM,yCAAyC,CAAC;AAGtF,eAAO,MAAM,gCAAgC,aAAc,MAAM,KAAG,6BAOnE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ApiGatewayManagementApiClient } from '@aws-sdk/client-apigatewaymanagementapi';
2
+ const clients = {};
3
+ export const getApiGatewayManagementApiClient = (endpoint) => {
4
+ if (clients[endpoint])
5
+ return clients[endpoint];
6
+ const client = new ApiGatewayManagementApiClient({ endpoint });
7
+ clients[endpoint] = client;
8
+ return client;
9
+ };
10
+ //# sourceMappingURL=getApiGatewayManagementApiClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getApiGatewayManagementApiClient.js","sourceRoot":"","sources":["../../../src/ws/server/getApiGatewayManagementApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,6BAA6B,EAAC,MAAM,yCAAyC,CAAC;AAEtF,MAAM,OAAO,GAA0D,EAAE,CAAC;AAC1E,MAAM,CAAC,MAAM,gCAAgC,GAAG,CAAC,QAAgB,EAAiC,EAAE;IAClG,IAAI,OAAO,CAAC,QAAQ,CAAC;QACnB,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE3B,MAAM,MAAM,GAAG,IAAI,6BAA6B,CAAC,EAAC,QAAQ,EAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;IAC3B,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -1,4 +1,3 @@
1
1
  import { WsApiConnection } from '../types';
2
- export type SendResponseResult = 'SUCCESS' | 'CONNECTION_CLOSED';
3
- export declare const sendResponse: <Response_1 extends object>({ endpoint, connectionId }: WsApiConnection, response: Response_1, ignoreClosedConnection?: boolean) => Promise<SendResponseResult>;
2
+ export declare const sendResponse: <Response_1 extends object>({ endpoint, connectionId, }: WsApiConnection, response: Response_1) => Promise<void>;
4
3
  //# sourceMappingURL=sendResponse.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sendResponse.d.ts","sourceRoot":"","sources":["../../../src/ws/server/sendResponse.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAgB,MAAM,UAAU,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,mBAAmB,CAAA;AAChE,eAAO,MAAM,YAAY,0DAAoE,eAAe,iDAA8C,OAAO,KAAU,QAAQ,kBAAkB,CAepM,CAAC"}
1
+ {"version":3,"file":"sendResponse.d.ts","sourceRoot":"","sources":["../../../src/ws/server/sendResponse.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAgB,MAAM,UAAU,CAAC;AAGxD,eAAO,MAAM,YAAY,2DAKpB,eAAe,2BAAuB,QAAQ,IAAI,CAOtD,CAAC"}
@@ -1,16 +1,9 @@
1
- import { ApiGatewayManagementApiClient, PostToConnectionCommand } from '@aws-sdk/client-apigatewaymanagementapi';
2
- export const sendResponse = async ({ endpoint, connectionId }, response, ignoreClosedConnection = true) => {
3
- try {
4
- await new ApiGatewayManagementApiClient({ endpoint }).send(new PostToConnectionCommand({
5
- ConnectionId: connectionId,
6
- Data: JSON.stringify(response),
7
- }));
8
- return 'SUCCESS';
9
- }
10
- catch (error) {
11
- if (ignoreClosedConnection && error && typeof error === 'object' && 'name' in error && error?.name === 'GoneException')
12
- return 'CONNECTION_CLOSED';
13
- throw error;
14
- }
1
+ import { PostToConnectionCommand } from '@aws-sdk/client-apigatewaymanagementapi';
2
+ import { getApiGatewayManagementApiClient } from './getApiGatewayManagementApiClient';
3
+ export const sendResponse = async ({ endpoint, connectionId, }, response) => {
4
+ await getApiGatewayManagementApiClient(endpoint).send(new PostToConnectionCommand({
5
+ ConnectionId: connectionId,
6
+ Data: JSON.stringify(response),
7
+ }));
15
8
  };
16
9
  //# sourceMappingURL=sendResponse.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sendResponse.js","sourceRoot":"","sources":["../../../src/ws/server/sendResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,6BAA6B,EAAE,uBAAuB,EAAC,MAAM,yCAAyC,CAAC;AAI/G,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAkC,EAAC,QAAQ,EAAE,YAAY,EAAkB,EAAE,QAAkB,EAAE,yBAAkC,IAAI,EAA+B,EAAE;IACvM,IAAI,CAAC;QACH,MAAM,IAAI,6BAA6B,CAAC,EAAC,QAAQ,EAAC,CAAC,CAAC,IAAI,CACpD,IAAI,uBAAuB,CAAC;YAC1B,YAAY,EAAE,YAAY;YAC1B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;SAC/B,CAAC,CACL,CAAC;QACF,OAAO,SAAS,CAAC;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,sBAAsB,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,EAAE,IAAI,KAAK,eAAe;YACpH,OAAO,mBAAmB,CAAC;QAE7B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
1
+ {"version":3,"file":"sendResponse.js","sourceRoot":"","sources":["../../../src/ws/server/sendResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,yCAAyC,CAAC;AAEhF,OAAO,EAAC,gCAAgC,EAAC,MAAM,oCAAoC,CAAC;AAEpF,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAE/B,EACE,QAAQ,EACR,YAAY,GACI,EAAE,QAAkB,EAAiB,EAAE;IACzD,MAAM,gCAAgC,CAAC,QAAQ,CAAC,CAAC,IAAI,CACjD,IAAI,uBAAuB,CAAC;QAC1B,YAAY,EAAE,YAAY;QAC1B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;KAC/B,CAAC,CACL,CAAC;AACJ,CAAC,CAAC"}
@@ -1,12 +1,11 @@
1
1
  import { OmitNever } from '../../types/OmitNever';
2
- import { SendResponseResult } from '../server';
3
2
  import { WsApiConnection } from './WsApiConnection';
4
3
  import { WsApiAction, WsApiRequest, WsApiResponse } from './common';
5
4
  export type WsApiRequestHandler<Action extends WsApiAction, Request extends WsApiRequest, Response extends WsApiResponse> = (request: Request & {
6
5
  action: Action;
7
6
  }, responseActions: OmitNever<{
8
7
  connection: WsApiConnection;
9
- sendResponse: [Response] extends [never] ? never : (response: Response) => Promise<SendResponseResult>;
8
+ sendResponse: [Response] extends [never] ? never : (response: Response) => Promise<void>;
10
9
  closeConnection: () => Promise<void>;
11
10
  }>) => Promise<void>;
12
11
  //# sourceMappingURL=WsApiRequestHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WsApiRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/ws/types/WsApiRequestHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,WAAW,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AAElE,MAAM,MAAM,mBAAmB,CAC3B,MAAM,SAAS,WAAW,EAC1B,OAAO,SAAS,YAAY,EAC5B,QAAQ,SAAS,aAAa,IAC9B,CAAC,OAAO,EAAE,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,eAAe,EAAE,SAAS,CAAC;IACrE,UAAU,EAAE,eAAe,CAAA;IAC3B,YAAY,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACtG,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACrC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
1
+ {"version":3,"file":"WsApiRequestHandler.d.ts","sourceRoot":"","sources":["../../../src/ws/types/WsApiRequestHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,WAAW,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AAElE,MAAM,MAAM,mBAAmB,CAC3B,MAAM,SAAS,WAAW,EAC1B,OAAO,SAAS,YAAY,EAC5B,QAAQ,SAAS,aAAa,IAC9B,CAAC,OAAO,EAAE,OAAO,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,eAAe,EAAE,SAAS,CAAC;IACrE,UAAU,EAAE,eAAe,CAAA;IAC3B,YAAY,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,KAAK,GAAG,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxF,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACrC,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mstuercke/api-utils",
3
- "version": "3.1.1",
3
+ "version": "4.1.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist/**/*.js",