@geekmidas/constructs 10.0.0-alpha.156 → 10.0.0-alpha.158

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 (127) hide show
  1. package/README.md +2 -1
  2. package/dist/{Construct-CRV3RN2U.mjs → Construct-CGuc_Ijk.mjs} +2 -11
  3. package/dist/{Construct-CRV3RN2U.mjs.map → Construct-CGuc_Ijk.mjs.map} +1 -1
  4. package/dist/{Construct-B8yWxGlR.cjs → Construct-DorKS0Ua.cjs} +2 -2
  5. package/dist/{Construct-B8yWxGlR.cjs.map → Construct-DorKS0Ua.cjs.map} +1 -1
  6. package/dist/{CronBuilder-CukJuL3b.mjs → CronBuilder-BJ5LoadF.mjs} +3 -3
  7. package/dist/{CronBuilder-CukJuL3b.mjs.map → CronBuilder-BJ5LoadF.mjs.map} +1 -1
  8. package/dist/{CronBuilder-B4DYaEjl.cjs → CronBuilder-B_NSP-Y5.cjs} +4 -4
  9. package/dist/{CronBuilder-B4DYaEjl.cjs.map → CronBuilder-B_NSP-Y5.cjs.map} +1 -1
  10. package/dist/{Endpoint-D2ckHqIx.cjs → Endpoint-52z1P0Ue.cjs} +3 -3
  11. package/dist/{Endpoint-D2ckHqIx.cjs.map → Endpoint-52z1P0Ue.cjs.map} +1 -1
  12. package/dist/{Endpoint-BuKHHVZc.mjs → Endpoint-sUOU7uLx.mjs} +3 -3
  13. package/dist/{Endpoint-BuKHHVZc.mjs.map → Endpoint-sUOU7uLx.mjs.map} +1 -1
  14. package/dist/{EndpointFactory-BsJUlUyL.mjs → EndpointFactory-Bzi9Sl7r.mjs} +4 -4
  15. package/dist/{EndpointFactory-BsJUlUyL.mjs.map → EndpointFactory-Bzi9Sl7r.mjs.map} +1 -1
  16. package/dist/{EndpointFactory-c4tHjQKM.cjs → EndpointFactory-Cf_Cs1ym.cjs} +5 -5
  17. package/dist/{EndpointFactory-c4tHjQKM.cjs.map → EndpointFactory-Cf_Cs1ym.cjs.map} +1 -1
  18. package/dist/{HonoEndpointAdaptor-BGEW1Tu8.cjs → HonoEndpointAdaptor-BTbqfSaa.cjs} +40 -15
  19. package/dist/HonoEndpointAdaptor-BTbqfSaa.cjs.map +1 -0
  20. package/dist/{HonoEndpointAdaptor-BC7CZ7Cr.mjs → HonoEndpointAdaptor-CBVey2cY.mjs} +40 -15
  21. package/dist/HonoEndpointAdaptor-CBVey2cY.mjs.map +1 -0
  22. package/dist/{Queue-DZpV13LN.cjs → Queue-D4Iaidrs.cjs} +2 -2
  23. package/dist/{Queue-DZpV13LN.cjs.map → Queue-D4Iaidrs.cjs.map} +1 -1
  24. package/dist/{Queue-0FpvxdOa.mjs → Queue-u8w8_HpE.mjs} +2 -2
  25. package/dist/{Queue-0FpvxdOa.mjs.map → Queue-u8w8_HpE.mjs.map} +1 -1
  26. package/dist/{QueueBuilder-Bmyay_Di.mjs → QueueBuilder-2wP5lEC8.mjs} +2 -2
  27. package/dist/{QueueBuilder-Bmyay_Di.mjs.map → QueueBuilder-2wP5lEC8.mjs.map} +1 -1
  28. package/dist/{QueueBuilder-FXkSDah1.cjs → QueueBuilder-BxsZ9o5z.cjs} +2 -2
  29. package/dist/{QueueBuilder-FXkSDah1.cjs.map → QueueBuilder-BxsZ9o5z.cjs.map} +1 -1
  30. package/dist/{SubscriberBuilder-CxG1OOug.mjs → SubscriberBuilder-CpFhShTJ.mjs} +2 -2
  31. package/dist/{SubscriberBuilder-CxG1OOug.mjs.map → SubscriberBuilder-CpFhShTJ.mjs.map} +1 -1
  32. package/dist/{SubscriberBuilder-Bfn-iDSk.cjs → SubscriberBuilder-DJEvNRdD.cjs} +2 -2
  33. package/dist/{SubscriberBuilder-Bfn-iDSk.cjs.map → SubscriberBuilder-DJEvNRdD.cjs.map} +1 -1
  34. package/dist/{Topic-DoEdDgh7.mjs → Topic-DN2gYJ-p.mjs} +2 -2
  35. package/dist/{Topic-DoEdDgh7.mjs.map → Topic-DN2gYJ-p.mjs.map} +1 -1
  36. package/dist/{Topic-t5GhqaeT.cjs → Topic-Dp9Q7Lj2.cjs} +2 -2
  37. package/dist/{Topic-t5GhqaeT.cjs.map → Topic-Dp9Q7Lj2.cjs.map} +1 -1
  38. package/dist/adaptors/aws.cjs +3 -10
  39. package/dist/adaptors/aws.cjs.map +1 -1
  40. package/dist/adaptors/aws.d.cts +0 -141
  41. package/dist/adaptors/aws.d.cts.map +1 -1
  42. package/dist/adaptors/aws.d.mts +0 -141
  43. package/dist/adaptors/aws.d.mts.map +1 -1
  44. package/dist/adaptors/aws.mjs +3 -4
  45. package/dist/adaptors/aws.mjs.map +1 -1
  46. package/dist/{apigateway-zHDoMwlI.cjs → adaptors/awsWebsocket.cjs} +125 -141
  47. package/dist/adaptors/awsWebsocket.cjs.map +1 -0
  48. package/dist/adaptors/awsWebsocket.d.cts +156 -0
  49. package/dist/adaptors/awsWebsocket.d.cts.map +1 -0
  50. package/dist/adaptors/awsWebsocket.d.mts +156 -0
  51. package/dist/adaptors/awsWebsocket.d.mts.map +1 -0
  52. package/dist/{apigateway-Dyjy_JwI.mjs → adaptors/awsWebsocket.mjs} +119 -101
  53. package/dist/adaptors/awsWebsocket.mjs.map +1 -0
  54. package/dist/adaptors/hono.cjs +1 -1
  55. package/dist/adaptors/hono.d.cts +3 -1
  56. package/dist/adaptors/hono.d.cts.map +1 -1
  57. package/dist/adaptors/hono.d.mts +3 -1
  58. package/dist/adaptors/hono.d.mts.map +1 -1
  59. package/dist/adaptors/hono.mjs +1 -1
  60. package/dist/adaptors/testing.cjs +8 -8
  61. package/dist/adaptors/testing.d.cts +1 -1
  62. package/dist/adaptors/testing.d.mts +1 -1
  63. package/dist/adaptors/testing.mjs +6 -6
  64. package/dist/crons/index.cjs +2 -2
  65. package/dist/crons/index.mjs +2 -2
  66. package/dist/database/kysely.cjs +1 -1
  67. package/dist/endpoints/index.cjs +3 -3
  68. package/dist/endpoints/index.mjs +3 -3
  69. package/dist/file-server.cjs +1 -1
  70. package/dist/file-server.mjs +1 -1
  71. package/dist/functions/index.cjs +1 -1
  72. package/dist/functions/index.mjs +1 -1
  73. package/dist/{functions-BF039DT8.mjs → functions-BvIDQKAA.mjs} +2 -2
  74. package/dist/{functions-BF039DT8.mjs.map → functions-BvIDQKAA.mjs.map} +1 -1
  75. package/dist/{functions-BqAq_0xQ.cjs → functions-DLF6-IK8.cjs} +3 -3
  76. package/dist/{functions-BqAq_0xQ.cjs.map → functions-DLF6-IK8.cjs.map} +1 -1
  77. package/dist/inbox.cjs +1 -1
  78. package/dist/inbox.mjs +1 -1
  79. package/dist/index.cjs +1 -1
  80. package/dist/index.mjs +1 -1
  81. package/dist/{kysely-CeoQdAkg.cjs → kysely-CukArHJ0.cjs} +2 -2
  82. package/dist/{kysely-CeoQdAkg.cjs.map → kysely-CukArHJ0.cjs.map} +1 -1
  83. package/dist/origins-BjxYht13.cjs +96 -0
  84. package/dist/origins-BjxYht13.cjs.map +1 -0
  85. package/dist/origins-Boc9qbo-.mjs +73 -0
  86. package/dist/origins-Boc9qbo-.mjs.map +1 -0
  87. package/dist/{pattern-YSqfAhXm.mjs → pattern-C1CEcglD.mjs} +2 -2
  88. package/dist/{pattern-YSqfAhXm.mjs.map → pattern-C1CEcglD.mjs.map} +1 -1
  89. package/dist/{pattern-HnNOPhE2.cjs → pattern-QFaUIr77.cjs} +2 -2
  90. package/dist/{pattern-HnNOPhE2.cjs.map → pattern-QFaUIr77.cjs.map} +1 -1
  91. package/dist/processors/index.cjs +1 -1
  92. package/dist/processors/index.mjs +1 -1
  93. package/dist/queue/index.cjs +2 -2
  94. package/dist/queue/index.mjs +2 -2
  95. package/dist/rest-api.cjs +1 -1
  96. package/dist/rest-api.mjs +1 -1
  97. package/dist/{rolldown-runtime-Ctb5zv51.cjs → rolldown-runtime-y5ARvAq5.cjs} +0 -15
  98. package/dist/subscribers/index.cjs +1 -1
  99. package/dist/subscribers/index.mjs +1 -1
  100. package/dist/topic/index.cjs +1 -1
  101. package/dist/topic/index.mjs +1 -1
  102. package/dist/{websocket-api-BvKS9x-l.mjs → websocket-api-Bg9SowJ5.mjs} +12 -13
  103. package/dist/{websocket-api-BvKS9x-l.mjs.map → websocket-api-Bg9SowJ5.mjs.map} +1 -1
  104. package/dist/{websocket-api-CDAxOTQZ.d.mts → websocket-api-CPEzJyDt.d.mts} +22 -2
  105. package/dist/websocket-api-CPEzJyDt.d.mts.map +1 -0
  106. package/dist/{websocket-api-C3dWKNxO.d.cts → websocket-api-DkF8Hva-.d.cts} +22 -2
  107. package/dist/websocket-api-DkF8Hva-.d.cts.map +1 -0
  108. package/dist/{websocket-api-CAQA_QOE.cjs → websocket-api-czxhekGG.cjs} +12 -13
  109. package/dist/websocket-api-czxhekGG.cjs.map +1 -0
  110. package/dist/websocket-api.cjs +4 -1
  111. package/dist/websocket-api.d.cts +2 -2
  112. package/dist/websocket-api.d.mts +2 -2
  113. package/dist/websocket-api.mjs +3 -2
  114. package/dist/worker.cjs +4 -4
  115. package/dist/worker.mjs +4 -4
  116. package/package.json +47 -31
  117. package/dist/HonoEndpointAdaptor-BC7CZ7Cr.mjs.map +0 -1
  118. package/dist/HonoEndpointAdaptor-BGEW1Tu8.cjs.map +0 -1
  119. package/dist/apigateway-Dyjy_JwI.mjs.map +0 -1
  120. package/dist/apigateway-zHDoMwlI.cjs.map +0 -1
  121. package/dist/origins-C7T9covD.cjs +0 -24
  122. package/dist/origins-C7T9covD.cjs.map +0 -1
  123. package/dist/origins-CX6Ot7ax.mjs +0 -19
  124. package/dist/origins-CX6Ot7ax.mjs.map +0 -1
  125. package/dist/websocket-api-C3dWKNxO.d.cts.map +0 -1
  126. package/dist/websocket-api-CAQA_QOE.cjs.map +0 -1
  127. package/dist/websocket-api-CDAxOTQZ.d.mts.map +0 -1
@@ -1,110 +1,127 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
2
- const require_optionalPeers = require("./optionalPeers-DuNQXXe1.cjs");
3
- const require_origins = require("./origins-C7T9covD.cjs");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_origins = require("../origins-BjxYht13.cjs");
4
3
  let _geekmidas_manifest = require("@geekmidas/manifest");
4
+ let _aws_sdk_client_apigatewaymanagementapi = require("@aws-sdk/client-apigatewaymanagementapi");
5
+ let _aws_sdk_client_dynamodb = require("@aws-sdk/client-dynamodb");
6
+ let electrodb = require("electrodb");
5
7
  //#region src/websocket/apigateway.ts
6
- var apigateway_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
7
- AmazonApiGatewayWebSocket: () => AmazonApiGatewayWebSocket,
8
- ApiGatewaySink: () => ApiGatewaySink,
9
- CONNECTION_TTL_SECONDS: () => CONNECTION_TTL_SECONDS,
10
- DynamoConnectionTable: () => DynamoConnectionTable,
11
- WebSocketPublisherNotConfigured: () => WebSocketPublisherNotConfigured,
12
- apiGatewayFromConnectionString: () => apiGatewayFromConnectionString
13
- });
8
+ /**
9
+ * The API Gateway (v2, WebSocket) adaptor: a Lambda per route, over the
10
+ * surface's `WebSocketCore`.
11
+ *
12
+ * API Gateway holds the sockets. A Lambda only sees events — `$connect`, a
13
+ * frame on a route, `$disconnect` — so this owns what the gateway does not:
14
+ *
15
+ * - **the Origin check** in `$connect`, against the same origins the Node
16
+ * adaptor trusts;
17
+ * - **the connection table**, where a connection's `data` (what the connect
18
+ * handler returned) is kept between invocations, and the ids a broadcast
19
+ * goes to are read from;
20
+ * - **the sink**, `postToConnection` and `deleteConnection` on the management
21
+ * API, with a connection that has gone (410) dropped from the table rather
22
+ * than reported — as a Redis publisher drops a socket nobody holds.
23
+ *
24
+ * Both are reached through the surface's `<ID>_PUBLISHER_CONNECTION_STRING`,
25
+ * an `apigateway://` string on an AWS stage, which is also what
26
+ * `services.<surface>` reads in any other Lambda.
27
+ *
28
+ * This is the AWS adaptor, `@geekmidas/constructs/aws-websocket`: it imports
29
+ * the AWS SDK clients it is built on, so they are needed only by a project
30
+ * that serves a surface from API Gateway.
31
+ */
14
32
  /**
15
33
  * How long a row outlives its connection's start. API Gateway closes every
16
34
  * connection after two hours, so a row the `$disconnect` never deleted — a
17
35
  * Lambda that timed out — expires a little after that.
18
36
  */
19
37
  const CONNECTION_TTL_SECONDS = 7800;
20
- async function loadDynamo() {
21
- try {
22
- return await import("@aws-sdk/client-dynamodb");
23
- } catch (cause) {
24
- throw new require_optionalPeers.OptionalPeerMissing("@aws-sdk/client-dynamodb", "A WebSocketApi served by API Gateway", cause);
25
- }
26
- }
27
- async function loadManagement() {
28
- try {
29
- return await import("@aws-sdk/client-apigatewaymanagementapi");
30
- } catch (cause) {
31
- throw new require_optionalPeers.OptionalPeerMissing("@aws-sdk/client-apigatewaymanagementapi", "A WebSocketApi served by API Gateway", cause);
32
- }
33
- }
34
38
  /**
35
39
  * The connection table in DynamoDB: one item per connection, keyed by
36
40
  * `connectionId`, with its `data` as JSON and an `expiresAt` the table's TTL
37
41
  * reads. Provisioned beside the API by `@geekmidas/cloud`, so a surface on
38
42
  * AWS needs nothing declared for it.
39
43
  */
40
- var DynamoConnectionTable = class {
44
+ var DynamoConnectionTable = class DynamoConnectionTable {
41
45
  table;
42
46
  options;
43
- client;
44
- constructor(table, options) {
47
+ connections;
48
+ /** A table on a client of DynamoDB at `region` (or an emulator's `endpoint`). */
49
+ static create(table, options) {
50
+ const client = new _aws_sdk_client_dynamodb.DynamoDBClient({
51
+ region: options.region,
52
+ ...options.endpoint ? { endpoint: options.endpoint } : {}
53
+ });
54
+ return new DynamoConnectionTable(table, client, { ttl: options.ttl });
55
+ }
56
+ constructor(table, client, options = {}) {
45
57
  this.table = table;
46
58
  this.options = options;
47
- }
48
- connect() {
49
- this.client ??= loadDynamo().then((dynamo) => ({
50
- dynamo,
51
- client: new dynamo.DynamoDBClient({
52
- region: this.options.region,
53
- ...this.options.endpoint ? { endpoint: this.options.endpoint } : {}
54
- })
55
- }));
56
- return this.client;
59
+ this.connections = connectionEntity(table, client);
57
60
  }
58
61
  async put(connection) {
59
- const { dynamo, client } = await this.connect();
60
62
  const ttl = this.options.ttl ?? 7800;
61
- await client.send(new dynamo.PutItemCommand({
62
- TableName: this.table,
63
- Item: {
64
- connectionId: { S: connection.id },
65
- data: { S: JSON.stringify(connection.data) },
66
- expiresAt: { N: String(nowSeconds() + ttl) }
67
- }
68
- }));
63
+ await this.connections.put({
64
+ connectionId: connection.id,
65
+ data: JSON.stringify(connection.data),
66
+ expiresAt: nowSeconds() + ttl
67
+ }).go();
69
68
  }
70
69
  async get(id) {
71
- const { dynamo, client } = await this.connect();
72
- const { Item: item } = await client.send(new dynamo.GetItemCommand({
73
- TableName: this.table,
74
- Key: { connectionId: { S: id } },
75
- ConsistentRead: true
76
- }));
77
- if (!item || expired(item)) return void 0;
70
+ const { data: item } = await this.connections.get({ connectionId: id }).go({ consistent: true });
71
+ if (!item || item.expiresAt <= nowSeconds()) return void 0;
78
72
  return {
79
73
  id,
80
- data: JSON.parse(item.data?.S ?? "{}")
74
+ data: JSON.parse(item.data)
81
75
  };
82
76
  }
83
77
  async delete(ids) {
84
78
  if (ids.length === 0) return;
85
- const { dynamo, client } = await this.connect();
86
- await Promise.all(ids.map((id) => client.send(new dynamo.DeleteItemCommand({
87
- TableName: this.table,
88
- Key: { connectionId: { S: id } }
89
- }))));
79
+ await this.connections.delete(ids.map((connectionId) => ({ connectionId }))).go();
90
80
  }
91
81
  async ids() {
92
- const { dynamo, client } = await this.connect();
93
- const ids = [];
94
- let start;
95
- do {
96
- const page = await client.send(new dynamo.ScanCommand({
97
- TableName: this.table,
98
- ProjectionExpression: "connectionId, expiresAt",
99
- ...start ? { ExclusiveStartKey: start } : {}
100
- }));
101
- for (const item of page.Items ?? []) if (item.connectionId?.S && !expired(item)) ids.push(item.connectionId.S);
102
- start = page.LastEvaluatedKey;
103
- } while (start);
104
- return ids;
82
+ const { data: items } = await this.connections.scan.where(({ expiresAt }, { gt }) => gt(expiresAt, nowSeconds())).go({
83
+ pages: "all",
84
+ attributes: ["connectionId", "expiresAt"]
85
+ });
86
+ return items.map((item) => item.connectionId);
105
87
  }
106
88
  };
107
89
  /**
90
+ * One connection's row. The table's hash key is the `connectionId` attribute
91
+ * itself, as `@geekmidas/cloud` provisions it, and `expiresAt` is its TTL.
92
+ */
93
+ function connectionEntity(table, client) {
94
+ return new electrodb.Entity({
95
+ model: {
96
+ entity: "connection",
97
+ service: "gkm-websocket",
98
+ version: "1"
99
+ },
100
+ attributes: {
101
+ connectionId: {
102
+ type: "string",
103
+ required: true
104
+ },
105
+ data: {
106
+ type: "string",
107
+ required: true
108
+ },
109
+ expiresAt: {
110
+ type: "number",
111
+ required: true
112
+ }
113
+ },
114
+ indexes: { primary: { pk: {
115
+ field: "connectionId",
116
+ composite: ["connectionId"],
117
+ casing: "none"
118
+ } } }
119
+ }, {
120
+ table,
121
+ client
122
+ });
123
+ }
124
+ /**
108
125
  * A publisher's sink on API Gateway: each send a `postToConnection`, each
109
126
  * close a `deleteConnection`, a broadcast every id in the table. A connection
110
127
  * that has gone answers 410; it is dropped from the table, and the send to
@@ -114,29 +131,25 @@ var DynamoConnectionTable = class {
114
131
  * reason)` ends the connections, but its client does not see `code` or
115
132
  * `reason`.
116
133
  */
117
- var ApiGatewaySink = class {
118
- target;
119
- table;
134
+ var ApiGatewaySink = class ApiGatewaySink {
120
135
  client;
121
- constructor(target, table) {
122
- this.target = target;
123
- this.table = table;
136
+ table;
137
+ /** A sink on a client of the management API at `target`. */
138
+ static create(target, table) {
139
+ const client = new _aws_sdk_client_apigatewaymanagementapi.ApiGatewayManagementApiClient({
140
+ region: target.region,
141
+ endpoint: target.endpoint
142
+ });
143
+ return new ApiGatewaySink(client, table);
124
144
  }
125
- connect() {
126
- this.client ??= loadManagement().then((management) => ({
127
- management,
128
- client: new management.ApiGatewayManagementApiClient({
129
- region: this.target.region,
130
- endpoint: this.target.endpoint
131
- })
132
- }));
133
- return this.client;
145
+ constructor(client, table) {
146
+ this.client = client;
147
+ this.table = table;
134
148
  }
135
149
  async send(ids, payload) {
136
150
  if (ids.length === 0) return;
137
- const { management, client } = await this.connect();
138
151
  const data = new TextEncoder().encode(payload);
139
- const gone = await this.each(ids, (id) => client.send(new management.PostToConnectionCommand({
152
+ const gone = await this.each(ids, (id) => this.client.send(new _aws_sdk_client_apigatewaymanagementapi.PostToConnectionCommand({
140
153
  ConnectionId: id,
141
154
  Data: data
142
155
  })));
@@ -149,8 +162,7 @@ var ApiGatewaySink = class {
149
162
  }
150
163
  async close(ids) {
151
164
  if (ids.length === 0) return;
152
- const { management, client } = await this.connect();
153
- await this.each(ids, (id) => client.send(new management.DeleteConnectionCommand({ ConnectionId: id })));
165
+ await this.each(ids, (id) => this.client.send(new _aws_sdk_client_apigatewaymanagementapi.DeleteConnectionCommand({ ConnectionId: id })));
154
166
  await this.table.delete(ids);
155
167
  }
156
168
  /** Call `fn` for each id; the ids that had gone. Anything else throws. */
@@ -167,17 +179,27 @@ var ApiGatewaySink = class {
167
179
  return gone;
168
180
  }
169
181
  };
182
+ /**
183
+ * `services.<surface>` on an AWS stage: the management API's sink for an
184
+ * `apigateway://` publisher string. An AWS build's entry registers it with
185
+ * `registerWebSocketSinkDriver`, and {@link AmazonApiGatewayWebSocket} does
186
+ * for its own Lambda.
187
+ */
188
+ const apiGatewayWebSocketDriver = {
189
+ scheme: _geekmidas_manifest.API_GATEWAY_WEBSOCKET_SCHEME,
190
+ sink: (connectionString) => apiGatewayFromConnectionString(connectionString).sink
191
+ };
170
192
  /** A table and a sink from an `apigateway://` publisher string. */
171
193
  function apiGatewayFromConnectionString(connectionString) {
172
194
  const target = (0, _geekmidas_manifest.parseApiGatewayWebSocketUrl)(connectionString);
173
- const table = new DynamoConnectionTable(target.table, {
195
+ const table = DynamoConnectionTable.create(target.table, {
174
196
  region: target.region,
175
197
  ...target.tableEndpoint ? { endpoint: target.tableEndpoint } : {}
176
198
  });
177
199
  return {
178
200
  target,
179
201
  table,
180
- sink: new ApiGatewaySink(target, table)
202
+ sink: ApiGatewaySink.create(target, table)
181
203
  };
182
204
  }
183
205
  /**
@@ -197,6 +219,7 @@ var AmazonApiGatewayWebSocket = class {
197
219
  constructor(surface, options = {}) {
198
220
  this.surface = surface;
199
221
  this.options = options;
222
+ require_origins.registerWebSocketSinkDriver(apiGatewayWebSocketDriver);
200
223
  }
201
224
  /** The Lambda handler. */
202
225
  handler = (event) => this.handle(event);
@@ -319,52 +342,13 @@ function isGone(error) {
319
342
  function nowSeconds() {
320
343
  return Math.floor(Date.now() / 1e3);
321
344
  }
322
- function expired(item) {
323
- const at = Number(item.expiresAt?.N);
324
- return Number.isFinite(at) && at > 0 && at <= nowSeconds();
325
- }
326
345
  //#endregion
327
- Object.defineProperty(exports, "AmazonApiGatewayWebSocket", {
328
- enumerable: true,
329
- get: function() {
330
- return AmazonApiGatewayWebSocket;
331
- }
332
- });
333
- Object.defineProperty(exports, "ApiGatewaySink", {
334
- enumerable: true,
335
- get: function() {
336
- return ApiGatewaySink;
337
- }
338
- });
339
- Object.defineProperty(exports, "CONNECTION_TTL_SECONDS", {
340
- enumerable: true,
341
- get: function() {
342
- return CONNECTION_TTL_SECONDS;
343
- }
344
- });
345
- Object.defineProperty(exports, "DynamoConnectionTable", {
346
- enumerable: true,
347
- get: function() {
348
- return DynamoConnectionTable;
349
- }
350
- });
351
- Object.defineProperty(exports, "WebSocketPublisherNotConfigured", {
352
- enumerable: true,
353
- get: function() {
354
- return WebSocketPublisherNotConfigured;
355
- }
356
- });
357
- Object.defineProperty(exports, "apiGatewayFromConnectionString", {
358
- enumerable: true,
359
- get: function() {
360
- return apiGatewayFromConnectionString;
361
- }
362
- });
363
- Object.defineProperty(exports, "apigateway_exports", {
364
- enumerable: true,
365
- get: function() {
366
- return apigateway_exports;
367
- }
368
- });
346
+ exports.AmazonApiGatewayWebSocket = AmazonApiGatewayWebSocket;
347
+ exports.ApiGatewaySink = ApiGatewaySink;
348
+ exports.CONNECTION_TTL_SECONDS = CONNECTION_TTL_SECONDS;
349
+ exports.DynamoConnectionTable = DynamoConnectionTable;
350
+ exports.WebSocketPublisherNotConfigured = WebSocketPublisherNotConfigured;
351
+ exports.apiGatewayFromConnectionString = apiGatewayFromConnectionString;
352
+ exports.apiGatewayWebSocketDriver = apiGatewayWebSocketDriver;
369
353
 
370
- //# sourceMappingURL=apigateway-zHDoMwlI.cjs.map
354
+ //# sourceMappingURL=awsWebsocket.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awsWebsocket.cjs","names":["DynamoDBClient","Entity","ApiGatewayManagementApiClient","PostToConnectionCommand","DeleteConnectionCommand","API_GATEWAY_WEBSOCKET_SCHEME","parseApiGatewayWebSocketUrl","ownOrigins","trustsOrigin"],"sources":["../../src/websocket/apigateway.ts"],"sourcesContent":["/**\n * The API Gateway (v2, WebSocket) adaptor: a Lambda per route, over the\n * surface's `WebSocketCore`.\n *\n * API Gateway holds the sockets. A Lambda only sees events — `$connect`, a\n * frame on a route, `$disconnect` — so this owns what the gateway does not:\n *\n * - **the Origin check** in `$connect`, against the same origins the Node\n * adaptor trusts;\n * - **the connection table**, where a connection's `data` (what the connect\n * handler returned) is kept between invocations, and the ids a broadcast\n * goes to are read from;\n * - **the sink**, `postToConnection` and `deleteConnection` on the management\n * API, with a connection that has gone (410) dropped from the table rather\n * than reported — as a Redis publisher drops a socket nobody holds.\n *\n * Both are reached through the surface's `<ID>_PUBLISHER_CONNECTION_STRING`,\n * an `apigateway://` string on an AWS stage, which is also what\n * `services.<surface>` reads in any other Lambda.\n *\n * This is the AWS adaptor, `@geekmidas/constructs/aws-websocket`: it imports\n * the AWS SDK clients it is built on, so they are needed only by a project\n * that serves a surface from API Gateway.\n */\n\nimport {\n\tApiGatewayManagementApiClient,\n\tDeleteConnectionCommand,\n\tPostToConnectionCommand,\n} from '@aws-sdk/client-apigatewaymanagementapi';\nimport { DynamoDBClient } from '@aws-sdk/client-dynamodb';\nimport type { EnvironmentParser } from '@geekmidas/envkit';\nimport type { Logger } from '@geekmidas/logger';\nimport {\n\tAPI_GATEWAY_WEBSOCKET_SCHEME,\n\ttype ApiGatewayWebSocketTarget,\n\tparseApiGatewayWebSocketUrl,\n\ttrustsOrigin,\n} from '@geekmidas/manifest';\nimport { Entity } from 'electrodb';\nimport type { WebSocketApi } from '../websocket-api';\nimport type { WebSocketCore } from './core';\nimport {\n\tregisterWebSocketSinkDriver,\n\ttype WebSocketSinkDriver,\n} from './drivers';\nimport { ownOrigins } from './origins';\nimport type { NoMessages, WebSocketMessages, WebSocketSink } from './publisher';\nimport type { Connection } from './route';\n\n/**\n * How long a row outlives its connection's start. API Gateway closes every\n * connection after two hours, so a row the `$disconnect` never deleted — a\n * Lambda that timed out — expires a little after that.\n */\nexport const CONNECTION_TTL_SECONDS = 2 * 60 * 60 + 10 * 60;\n\n/**\n * Where a surface's open connections are kept on API Gateway, by id: the\n * `data` its connect handler returned, which every later invocation hands\n * to its route, and the list a broadcast goes to.\n */\nexport interface ConnectionTable {\n\tput(connection: Connection): Promise<void>;\n\tget(id: string): Promise<Connection | undefined>;\n\tdelete(ids: readonly string[]): Promise<void>;\n\t/** Every open connection's id. */\n\tids(): Promise<string[]>;\n}\n\n/**\n * The connection table in DynamoDB: one item per connection, keyed by\n * `connectionId`, with its `data` as JSON and an `expiresAt` the table's TTL\n * reads. Provisioned beside the API by `@geekmidas/cloud`, so a surface on\n * AWS needs nothing declared for it.\n */\nexport class DynamoConnectionTable implements ConnectionTable {\n\tprivate readonly connections: ReturnType<typeof connectionEntity>;\n\n\t/** A table on a client of DynamoDB at `region` (or an emulator's `endpoint`). */\n\tstatic create(\n\t\ttable: string,\n\t\toptions: {\n\t\t\tregion: string;\n\t\t\t/** An emulator's address; AWS's own when absent. */\n\t\t\tendpoint?: string;\n\t\t\t/** Seconds a row is kept. Default {@link CONNECTION_TTL_SECONDS}. */\n\t\t\tttl?: number;\n\t\t},\n\t): DynamoConnectionTable {\n\t\tconst client = new DynamoDBClient({\n\t\t\tregion: options.region,\n\t\t\t...(options.endpoint ? { endpoint: options.endpoint } : {}),\n\t\t});\n\t\treturn new DynamoConnectionTable(table, client, { ttl: options.ttl });\n\t}\n\n\tconstructor(\n\t\treadonly table: string,\n\t\tclient: DynamoDBClient,\n\t\tprivate readonly options: {\n\t\t\t/** Seconds a row is kept. Default {@link CONNECTION_TTL_SECONDS}. */\n\t\t\tttl?: number;\n\t\t} = {},\n\t) {\n\t\tthis.connections = connectionEntity(table, client);\n\t}\n\n\tasync put(connection: Connection): Promise<void> {\n\t\tconst ttl = this.options.ttl ?? CONNECTION_TTL_SECONDS;\n\t\tawait this.connections\n\t\t\t.put({\n\t\t\t\tconnectionId: connection.id,\n\t\t\t\tdata: JSON.stringify(connection.data),\n\t\t\t\texpiresAt: nowSeconds() + ttl,\n\t\t\t})\n\t\t\t.go();\n\t}\n\n\tasync get(id: string): Promise<Connection | undefined> {\n\t\t// `$connect` wrote it a moment ago; the first frame must see it.\n\t\tconst { data: item } = await this.connections\n\t\t\t.get({ connectionId: id })\n\t\t\t.go({ consistent: true });\n\t\tif (!item || item.expiresAt <= nowSeconds()) return undefined;\n\t\treturn { id, data: JSON.parse(item.data) };\n\t}\n\n\tasync delete(ids: readonly string[]): Promise<void> {\n\t\tif (ids.length === 0) return;\n\t\tawait this.connections\n\t\t\t.delete(ids.map((connectionId) => ({ connectionId })))\n\t\t\t.go();\n\t}\n\n\tasync ids(): Promise<string[]> {\n\t\tconst { data: items } = await this.connections.scan\n\t\t\t.where(({ expiresAt }, { gt }) => gt(expiresAt, nowSeconds()))\n\t\t\t.go({ pages: 'all', attributes: ['connectionId', 'expiresAt'] });\n\t\t// DynamoDB deletes an expired item eventually, not on time.\n\t\treturn items.map((item) => item.connectionId);\n\t}\n}\n\n/**\n * One connection's row. The table's hash key is the `connectionId` attribute\n * itself, as `@geekmidas/cloud` provisions it, and `expiresAt` is its TTL.\n */\nfunction connectionEntity(table: string, client: DynamoDBClient) {\n\treturn new Entity(\n\t\t{\n\t\t\tmodel: {\n\t\t\t\tentity: 'connection',\n\t\t\t\tservice: 'gkm-websocket',\n\t\t\t\tversion: '1',\n\t\t\t},\n\t\t\tattributes: {\n\t\t\t\tconnectionId: { type: 'string', required: true },\n\t\t\t\tdata: { type: 'string', required: true },\n\t\t\t\texpiresAt: { type: 'number', required: true },\n\t\t\t},\n\t\t\tindexes: {\n\t\t\t\tprimary: {\n\t\t\t\t\t// A connection id is case-sensitive; ElectroDB lowercases keys\n\t\t\t\t\t// unless told not to, and a lowered id is a 410 on every post.\n\t\t\t\t\tpk: {\n\t\t\t\t\t\tfield: 'connectionId',\n\t\t\t\t\t\tcomposite: ['connectionId'],\n\t\t\t\t\t\tcasing: 'none',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{ table, client },\n\t);\n}\n\n/**\n * A publisher's sink on API Gateway: each send a `postToConnection`, each\n * close a `deleteConnection`, a broadcast every id in the table. A connection\n * that has gone answers 410; it is dropped from the table, and the send to\n * the rest goes on.\n *\n * API Gateway closes a connection with a code of its own: `close(ids, code,\n * reason)` ends the connections, but its client does not see `code` or\n * `reason`.\n */\nexport class ApiGatewaySink implements WebSocketSink {\n\t/** A sink on a client of the management API at `target`. */\n\tstatic create(\n\t\ttarget: Pick<ApiGatewayWebSocketTarget, 'endpoint' | 'region'>,\n\t\ttable: ConnectionTable,\n\t): ApiGatewaySink {\n\t\tconst client = new ApiGatewayManagementApiClient({\n\t\t\tregion: target.region,\n\t\t\tendpoint: target.endpoint,\n\t\t});\n\t\treturn new ApiGatewaySink(client, table);\n\t}\n\n\tconstructor(\n\t\tprivate readonly client: ApiGatewayManagementApiClient,\n\t\tprivate readonly table: ConnectionTable,\n\t) {}\n\n\tasync send(ids: readonly string[], payload: string): Promise<void> {\n\t\tif (ids.length === 0) return;\n\t\tconst data = new TextEncoder().encode(payload);\n\t\tconst gone = await this.each(ids, (id) =>\n\t\t\tthis.client.send(\n\t\t\t\tnew PostToConnectionCommand({\n\t\t\t\t\tConnectionId: id,\n\t\t\t\t\tData: data,\n\t\t\t\t}),\n\t\t\t),\n\t\t);\n\t\tawait this.table.delete(gone);\n\t}\n\n\tasync broadcast(payload: string, except?: readonly string[]): Promise<void> {\n\t\tconst skip = new Set(except ?? []);\n\t\tconst ids = (await this.table.ids()).filter((id) => !skip.has(id));\n\t\tawait this.send(ids, payload);\n\t}\n\n\tasync close(ids: readonly string[]): Promise<void> {\n\t\tif (ids.length === 0) return;\n\t\tawait this.each(ids, (id) =>\n\t\t\tthis.client.send(new DeleteConnectionCommand({ ConnectionId: id })),\n\t\t);\n\t\t// Its `$disconnect` deletes the row too; a connection that was already\n\t\t// gone has no `$disconnect` left to run.\n\t\tawait this.table.delete(ids);\n\t}\n\n\t/** Call `fn` for each id; the ids that had gone. Anything else throws. */\n\tprivate async each(\n\t\tids: readonly string[],\n\t\tfn: (id: string) => Promise<unknown>,\n\t): Promise<string[]> {\n\t\tconst gone: string[] = [];\n\t\tawait Promise.all(\n\t\t\tids.map(async (id) => {\n\t\t\t\ttry {\n\t\t\t\t\tawait fn(id);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (!isGone(error)) throw error;\n\t\t\t\t\tgone.push(id);\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\treturn gone;\n\t}\n}\n\n/**\n * `services.<surface>` on an AWS stage: the management API's sink for an\n * `apigateway://` publisher string. An AWS build's entry registers it with\n * `registerWebSocketSinkDriver`, and {@link AmazonApiGatewayWebSocket} does\n * for its own Lambda.\n */\nexport const apiGatewayWebSocketDriver: WebSocketSinkDriver = {\n\tscheme: API_GATEWAY_WEBSOCKET_SCHEME,\n\tsink: (connectionString) =>\n\t\tapiGatewayFromConnectionString(connectionString).sink,\n};\n\n/** A table and a sink from an `apigateway://` publisher string. */\nexport function apiGatewayFromConnectionString(connectionString: string): {\n\ttarget: ApiGatewayWebSocketTarget;\n\ttable: DynamoConnectionTable;\n\tsink: ApiGatewaySink;\n} {\n\tconst target = parseApiGatewayWebSocketUrl(connectionString);\n\tconst table = DynamoConnectionTable.create(target.table, {\n\t\tregion: target.region,\n\t\t...(target.tableEndpoint ? { endpoint: target.tableEndpoint } : {}),\n\t});\n\treturn { target, table, sink: ApiGatewaySink.create(target, table) };\n}\n\n/**\n * What API Gateway invokes a WebSocket route's Lambda with — the fields this\n * adaptor reads. `headers` and the query arrive on `$connect` only.\n */\nexport interface ApiGatewayWebSocketEvent {\n\trequestContext: {\n\t\tconnectionId: string;\n\t\teventType: 'CONNECT' | 'MESSAGE' | 'DISCONNECT';\n\t\trouteKey: string;\n\t\tdisconnectStatusCode?: number;\n\t\tdisconnectReason?: string;\n\t};\n\theaders?: Record<string, string | undefined> | null;\n\tmultiValueHeaders?: Record<string, string[] | undefined> | null;\n\tqueryStringParameters?: Record<string, string | undefined> | null;\n\tmultiValueQueryStringParameters?: Record<string, string[] | undefined> | null;\n\tbody?: string | null;\n\tisBase64Encoded?: boolean;\n}\n\n/** What the Lambda answers: a non-2xx on `$connect` refuses the socket. */\nexport interface ApiGatewayWebSocketResult {\n\tstatusCode: number;\n\tbody?: string;\n}\n\nexport interface AmazonApiGatewayWebSocketOptions {\n\t/**\n\t * Files exporting the routes this Lambda serves — the generated handler\n\t * hands in the one route API Gateway invokes it for.\n\t */\n\tmodules?: readonly object[];\n\t/** Where the surface's keys are read. Absent, the surface's own parser. */\n\tenvParser?: EnvironmentParser<{}>;\n\t/**\n\t * The connection table and the sink, in place of the ones the\n\t * `apigateway://` publisher string names.\n\t */\n\ttable?: ConnectionTable;\n\tsink?: WebSocketSink;\n}\n\n/**\n * A WebSocket surface served by API Gateway: `handler` is the Lambda for one\n * or more of its routes.\n *\n * ```ts\n * // .gkm/aws/websocket/routes/send.ts, as `gkm build --provider aws` writes it\n * const adaptor = new AmazonApiGatewayWebSocket(realtime, { modules: [{ send }] });\n * export const handler = adaptor.handler;\n * ```\n */\nexport class AmazonApiGatewayWebSocket<\n\tTMessages extends WebSocketMessages = NoMessages,\n> {\n\tprivate ready?: Promise<{\n\t\tcore: WebSocketCore<TMessages>;\n\t\ttable: ConnectionTable;\n\t\tsink: WebSocketSink;\n\t\ttrusted: string[];\n\t}>;\n\n\tconstructor(\n\t\tprivate readonly surface: WebSocketApi<string, TMessages>,\n\t\tprivate readonly options: AmazonApiGatewayWebSocketOptions = {},\n\t) {\n\t\t// A route's own `services.<surface>` publishes through API Gateway too.\n\t\tregisterWebSocketSinkDriver(apiGatewayWebSocketDriver);\n\t}\n\n\t/** The Lambda handler. */\n\treadonly handler = (\n\t\tevent: ApiGatewayWebSocketEvent,\n\t): Promise<ApiGatewayWebSocketResult> => this.handle(event);\n\n\tprivate get logger(): Logger {\n\t\treturn this.surface.logger;\n\t}\n\n\t/** Read the keys and build the core once per container. */\n\tprivate setup() {\n\t\tthis.ready ??= Promise.resolve().then(() => {\n\t\t\tconst envParser = this.options.envParser ?? this.surface.envParser;\n\t\t\tconst { keys } = this.surface;\n\t\t\tconst config = envParser\n\t\t\t\t.create((get) => ({\n\t\t\t\t\tconnectionString: get(keys.publisherConnectionString)\n\t\t\t\t\t\t.string()\n\t\t\t\t\t\t.optional(),\n\t\t\t\t\torigins: get(keys.trustedOrigins)\n\t\t\t\t\t\t.string()\n\t\t\t\t\t\t.default('')\n\t\t\t\t\t\t.transform((value: string) =>\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t\t\t.split(',')\n\t\t\t\t\t\t\t\t.map((origin) => origin.trim())\n\t\t\t\t\t\t\t\t.filter(Boolean),\n\t\t\t\t\t\t),\n\t\t\t\t\turl: get(keys.url).string().optional(),\n\t\t\t\t}))\n\t\t\t\t.parse();\n\n\t\t\tlet { table, sink } = this.options;\n\t\t\tif (!table || !sink) {\n\t\t\t\tif (!config.connectionString) {\n\t\t\t\t\tthrow new WebSocketPublisherNotConfigured(\n\t\t\t\t\t\tthis.surface.id,\n\t\t\t\t\t\tkeys.publisherConnectionString,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tconst fromString = apiGatewayFromConnectionString(\n\t\t\t\t\tconfig.connectionString,\n\t\t\t\t);\n\t\t\t\ttable ??= fromString.table;\n\t\t\t\tsink ??= fromString.sink;\n\t\t\t}\n\n\t\t\tconst core = this.surface.core({\n\t\t\t\tenvParser,\n\t\t\t\tsink,\n\t\t\t\t...(this.options.modules ? { modules: this.options.modules } : {}),\n\t\t\t});\n\t\t\treturn {\n\t\t\t\tcore,\n\t\t\t\ttable,\n\t\t\t\tsink,\n\t\t\t\ttrusted: [...config.origins, ...ownOrigins(config.url)],\n\t\t\t};\n\t\t});\n\t\treturn this.ready;\n\t}\n\n\tasync handle(\n\t\tevent: ApiGatewayWebSocketEvent,\n\t): Promise<ApiGatewayWebSocketResult> {\n\t\tconst { connectionId, eventType } = event.requestContext;\n\t\tconst { core, table, sink, trusted } = await this.setup();\n\n\t\tif (eventType === 'CONNECT') {\n\t\t\tconst headers = headersOf(event);\n\t\t\tconst origin = headers.get('origin');\n\t\t\tif (origin && !trustsOrigin(origin, trusted)) {\n\t\t\t\treturn { statusCode: 403, body: 'Forbidden' };\n\t\t\t}\n\n\t\t\tconst outcome = await core.connect({\n\t\t\t\tconnectionId,\n\t\t\t\theaders,\n\t\t\t\tquery: queryOf(event),\n\t\t\t});\n\t\t\tif (!outcome.accepted) {\n\t\t\t\treturn { statusCode: outcome.status, body: outcome.statusText };\n\t\t\t}\n\t\t\tawait table.put(outcome.connection);\n\t\t\treturn { statusCode: 200 };\n\t\t}\n\n\t\t// A connection the table no longer has — a row that expired early, or\n\t\t// one written by a `$connect` that failed after accepting — is still\n\t\t// served, with nothing its connect handler said about it.\n\t\tconst connection = (await table.get(connectionId)) ?? {\n\t\t\tid: connectionId,\n\t\t\tdata: {},\n\t\t};\n\n\t\tif (eventType === 'DISCONNECT') {\n\t\t\tawait core.disconnect(connection, {\n\t\t\t\tcode: event.requestContext.disconnectStatusCode ?? 1005,\n\t\t\t\treason: event.requestContext.disconnectReason ?? '',\n\t\t\t});\n\t\t\tawait table.delete([connectionId]);\n\t\t\treturn { statusCode: 200 };\n\t\t}\n\n\t\t// What the route writes back — its reply, `reply()`, an `$error` — is\n\t\t// posted to the caller, and waited for before the Lambda returns: a\n\t\t// frozen container sends nothing.\n\t\tconst writes: Promise<void>[] = [];\n\t\tconst write = (payload: string) => {\n\t\t\twrites.push(\n\t\t\t\tsink.send([connectionId], payload).catch((error) => {\n\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t{ err: error, connectionId },\n\t\t\t\t\t\t'WebSocket reply could not be posted',\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t\tconst raw = event.isBase64Encoded\n\t\t\t? Uint8Array.from(Buffer.from(event.body ?? '', 'base64'))\n\t\t\t: (event.body ?? '');\n\t\tawait core.message(connection, raw, write);\n\t\tawait Promise.all(writes);\n\t\treturn { statusCode: 200 };\n\t}\n}\n\n/** A Lambda of the surface was started without its publisher string. */\nexport class WebSocketPublisherNotConfigured extends Error {\n\tconstructor(\n\t\treadonly surface: string,\n\t\treadonly key: string,\n\t) {\n\t\tsuper(\n\t\t\t`${surface}'s Lambda has no ${key}, so it cannot reach its connections. Link the route to its surface — gkm build and @geekmidas/cloud's fromManifest do — or pass a table and a sink to AmazonApiGatewayWebSocket.`,\n\t\t);\n\t\tthis.name = 'WebSocketPublisherNotConfigured';\n\t}\n}\n\nfunction headersOf(event: ApiGatewayWebSocketEvent): Headers {\n\tconst headers = new Headers();\n\tif (event.multiValueHeaders) {\n\t\tfor (const [name, values] of Object.entries(event.multiValueHeaders)) {\n\t\t\tfor (const value of values ?? []) headers.append(name, value);\n\t\t}\n\t\treturn headers;\n\t}\n\tfor (const [name, value] of Object.entries(event.headers ?? {})) {\n\t\tif (value !== undefined) headers.append(name, value);\n\t}\n\treturn headers;\n}\n\nfunction queryOf(event: ApiGatewayWebSocketEvent): URLSearchParams {\n\tconst query = new URLSearchParams();\n\tif (event.multiValueQueryStringParameters) {\n\t\tfor (const [name, values] of Object.entries(\n\t\t\tevent.multiValueQueryStringParameters,\n\t\t)) {\n\t\t\tfor (const value of values ?? []) query.append(name, value);\n\t\t}\n\t\treturn query;\n\t}\n\tfor (const [name, value] of Object.entries(\n\t\tevent.queryStringParameters ?? {},\n\t)) {\n\t\tif (value !== undefined) query.append(name, value);\n\t}\n\treturn query;\n}\n\n/** A management API answer for a connection that has gone. */\nfunction isGone(error: unknown): boolean {\n\tconst e = error as {\n\t\tname?: string;\n\t\t$metadata?: { httpStatusCode?: number };\n\t} | null;\n\treturn e?.name === 'GoneException' || e?.$metadata?.httpStatusCode === 410;\n}\n\nfunction nowSeconds(): number {\n\treturn Math.floor(Date.now() / 1000);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,MAAa,yBAAyB;;;;;;;AAqBtC,IAAa,wBAAb,MAAa,sBAAiD;CAsBnD;CAEQ;CAvBlB;;CAGA,OAAO,OACN,OACA,SAOwB;EACxB,MAAM,SAAS,IAAIA,yBAAAA,eAAe;GACjC,QAAQ,QAAQ;GAChB,GAAI,QAAQ,WAAW,EAAE,UAAU,QAAQ,SAAS,IAAI,CAAC;EAC1D,CAAC;EACD,OAAO,IAAI,sBAAsB,OAAO,QAAQ,EAAE,KAAK,QAAQ,IAAI,CAAC;CACrE;CAEA,YACC,OACA,QACA,UAGI,CAAC,GACJ;EANQ,KAAA,QAAA;EAEQ,KAAA,UAAA;EAKjB,KAAK,cAAc,iBAAiB,OAAO,MAAM;CAClD;CAEA,MAAM,IAAI,YAAuC;EAChD,MAAM,MAAM,KAAK,QAAQ,OAAA;EACzB,MAAM,KAAK,YACT,IAAI;GACJ,cAAc,WAAW;GACzB,MAAM,KAAK,UAAU,WAAW,IAAI;GACpC,WAAW,WAAW,IAAI;EAC3B,CAAC,CAAC,CACD,GAAG;CACN;CAEA,MAAM,IAAI,IAA6C;EAEtD,MAAM,EAAE,MAAM,SAAS,MAAM,KAAK,YAChC,IAAI,EAAE,cAAc,GAAG,CAAC,CAAC,CACzB,GAAG,EAAE,YAAY,KAAK,CAAC;EACzB,IAAI,CAAC,QAAQ,KAAK,aAAa,WAAW,GAAG,OAAO,KAAA;E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,aAAqB;CAC7B,OAAO,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AACpC"}
@@ -0,0 +1,156 @@
1
+ import { L as Connection, _t as WebSocketSink, a as WebSocketSinkDriver, ht as WebSocketMessages, n as WebSocketApi, pt as NoMessages } from "../websocket-api-DkF8Hva-.cjs";
2
+ import { EnvironmentParser } from "@geekmidas/envkit";
3
+ import { ApiGatewayWebSocketTarget } from "@geekmidas/manifest";
4
+ import { ApiGatewayManagementApiClient } from "@aws-sdk/client-apigatewaymanagementapi";
5
+ import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
6
+ //#region src/websocket/apigateway.d.ts
7
+ /**
8
+ * How long a row outlives its connection's start. API Gateway closes every
9
+ * connection after two hours, so a row the `$disconnect` never deleted — a
10
+ * Lambda that timed out — expires a little after that.
11
+ */
12
+ export declare const CONNECTION_TTL_SECONDS: number;
13
+ /**
14
+ * Where a surface's open connections are kept on API Gateway, by id: the
15
+ * `data` its connect handler returned, which every later invocation hands
16
+ * to its route, and the list a broadcast goes to.
17
+ */
18
+ interface ConnectionTable {
19
+ put(connection: Connection): Promise<void>;
20
+ get(id: string): Promise<Connection | undefined>;
21
+ delete(ids: readonly string[]): Promise<void>;
22
+ /** Every open connection's id. */
23
+ ids(): Promise<string[]>;
24
+ }
25
+ /**
26
+ * The connection table in DynamoDB: one item per connection, keyed by
27
+ * `connectionId`, with its `data` as JSON and an `expiresAt` the table's TTL
28
+ * reads. Provisioned beside the API by `@geekmidas/cloud`, so a surface on
29
+ * AWS needs nothing declared for it.
30
+ */
31
+ export declare class DynamoConnectionTable implements ConnectionTable {
32
+ readonly table: string;
33
+ private readonly options;
34
+ private readonly connections;
35
+ /** A table on a client of DynamoDB at `region` (or an emulator's `endpoint`). */
36
+ static create(table: string, options: {
37
+ region: string;
38
+ /** An emulator's address; AWS's own when absent. */
39
+ endpoint?: string;
40
+ /** Seconds a row is kept. Default {@link CONNECTION_TTL_SECONDS}. */
41
+ ttl?: number;
42
+ }): DynamoConnectionTable;
43
+ constructor(table: string, client: DynamoDBClient, options?: {
44
+ /** Seconds a row is kept. Default {@link CONNECTION_TTL_SECONDS}. */
45
+ ttl?: number;
46
+ });
47
+ put(connection: Connection): Promise<void>;
48
+ get(id: string): Promise<Connection | undefined>;
49
+ delete(ids: readonly string[]): Promise<void>;
50
+ ids(): Promise<string[]>;
51
+ }
52
+ /**
53
+ * A publisher's sink on API Gateway: each send a `postToConnection`, each
54
+ * close a `deleteConnection`, a broadcast every id in the table. A connection
55
+ * that has gone answers 410; it is dropped from the table, and the send to
56
+ * the rest goes on.
57
+ *
58
+ * API Gateway closes a connection with a code of its own: `close(ids, code,
59
+ * reason)` ends the connections, but its client does not see `code` or
60
+ * `reason`.
61
+ */
62
+ export declare class ApiGatewaySink implements WebSocketSink {
63
+ private readonly client;
64
+ private readonly table;
65
+ /** A sink on a client of the management API at `target`. */
66
+ static create(target: Pick<ApiGatewayWebSocketTarget, 'endpoint' | 'region'>, table: ConnectionTable): ApiGatewaySink;
67
+ constructor(client: ApiGatewayManagementApiClient, table: ConnectionTable);
68
+ send(ids: readonly string[], payload: string): Promise<void>;
69
+ broadcast(payload: string, except?: readonly string[]): Promise<void>;
70
+ close(ids: readonly string[]): Promise<void>;
71
+ /** Call `fn` for each id; the ids that had gone. Anything else throws. */
72
+ private each;
73
+ }
74
+ /**
75
+ * `services.<surface>` on an AWS stage: the management API's sink for an
76
+ * `apigateway://` publisher string. An AWS build's entry registers it with
77
+ * `registerWebSocketSinkDriver`, and {@link AmazonApiGatewayWebSocket} does
78
+ * for its own Lambda.
79
+ */
80
+ export declare const apiGatewayWebSocketDriver: WebSocketSinkDriver;
81
+ /** A table and a sink from an `apigateway://` publisher string. */
82
+ export declare function apiGatewayFromConnectionString(connectionString: string): {
83
+ target: ApiGatewayWebSocketTarget;
84
+ table: DynamoConnectionTable;
85
+ sink: ApiGatewaySink;
86
+ };
87
+ /**
88
+ * What API Gateway invokes a WebSocket route's Lambda with — the fields this
89
+ * adaptor reads. `headers` and the query arrive on `$connect` only.
90
+ */
91
+ interface ApiGatewayWebSocketEvent {
92
+ requestContext: {
93
+ connectionId: string;
94
+ eventType: 'CONNECT' | 'MESSAGE' | 'DISCONNECT';
95
+ routeKey: string;
96
+ disconnectStatusCode?: number;
97
+ disconnectReason?: string;
98
+ };
99
+ headers?: Record<string, string | undefined> | null;
100
+ multiValueHeaders?: Record<string, string[] | undefined> | null;
101
+ queryStringParameters?: Record<string, string | undefined> | null;
102
+ multiValueQueryStringParameters?: Record<string, string[] | undefined> | null;
103
+ body?: string | null;
104
+ isBase64Encoded?: boolean;
105
+ }
106
+ /** What the Lambda answers: a non-2xx on `$connect` refuses the socket. */
107
+ interface ApiGatewayWebSocketResult {
108
+ statusCode: number;
109
+ body?: string;
110
+ }
111
+ interface AmazonApiGatewayWebSocketOptions {
112
+ /**
113
+ * Files exporting the routes this Lambda serves — the generated handler
114
+ * hands in the one route API Gateway invokes it for.
115
+ */
116
+ modules?: readonly object[];
117
+ /** Where the surface's keys are read. Absent, the surface's own parser. */
118
+ envParser?: EnvironmentParser<{}>;
119
+ /**
120
+ * The connection table and the sink, in place of the ones the
121
+ * `apigateway://` publisher string names.
122
+ */
123
+ table?: ConnectionTable;
124
+ sink?: WebSocketSink;
125
+ }
126
+ /**
127
+ * A WebSocket surface served by API Gateway: `handler` is the Lambda for one
128
+ * or more of its routes.
129
+ *
130
+ * ```ts
131
+ * // .gkm/aws/websocket/routes/send.ts, as `gkm build --provider aws` writes it
132
+ * const adaptor = new AmazonApiGatewayWebSocket(realtime, { modules: [{ send }] });
133
+ * export const handler = adaptor.handler;
134
+ * ```
135
+ */
136
+ export declare class AmazonApiGatewayWebSocket<TMessages extends WebSocketMessages = NoMessages> {
137
+ private readonly surface;
138
+ private readonly options;
139
+ private ready?;
140
+ constructor(surface: WebSocketApi<string, TMessages>, options?: AmazonApiGatewayWebSocketOptions);
141
+ /** The Lambda handler. */
142
+ readonly handler: (event: ApiGatewayWebSocketEvent) => Promise<ApiGatewayWebSocketResult>;
143
+ private get logger();
144
+ /** Read the keys and build the core once per container. */
145
+ private setup;
146
+ handle(event: ApiGatewayWebSocketEvent): Promise<ApiGatewayWebSocketResult>;
147
+ }
148
+ /** A Lambda of the surface was started without its publisher string. */
149
+ export declare class WebSocketPublisherNotConfigured extends Error {
150
+ readonly surface: string;
151
+ readonly key: string;
152
+ constructor(surface: string, key: string);
153
+ }
154
+ //#endregion
155
+ export type { AmazonApiGatewayWebSocketOptions, ApiGatewayWebSocketEvent, ApiGatewayWebSocketResult, ConnectionTable };
156
+ //# sourceMappingURL=awsWebsocket.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"awsWebsocket.d.cts","names":[],"sources":["../../src/websocket/apigateway.ts"],"mappings":";;;;;;;;;;;qBAuDa;;;;;;UAOI;EAChB,IAAI,YAAY,aAAa;EAC7B,IAAI,aAAa,QAAQ;EACzB,OAAO,yBAAyB;;EAEhC,OAAO;;;;;;;;qBASK,iCAAiC;WAsBnC;mBAEQ;mBAvBD;;SAGV,OACN,eACA;IACC;;IAEA;;IAEA;MAEC;EAQH,YACU,eACT,QAAQ,gBACS;;IAEhB;;EAMI,IAAI,YAAY,aAAa;EAW7B,IAAI,aAAa,QAAQ;EASzB,OAAO,yBAAyB;EAOhC,OAAO;;;;;;;;;;;;qBAoDD,0BAA0B;mBAcpB;mBACA;;SAbX,OACN,QAAQ,KAAK,mDACb,OAAO,kBACL;EAQH,YACkB,QAAQ,+BACR,OAAO;EAGnB,KAAK,wBAAwB,kBAAkB;EAc/C,UAAU,iBAAiB,6BAA6B;EAMxD,MAAM,yBAAyB;;UAWvB;;;;;;;;qBAyBF,2BAA2B;;wBAOxB,+BAA+B;EAC9C,QAAQ;EACR,OAAO;EACP,MAAM;;;;;;UAcU;EAChB;IACC;IACA;IACA;IACA;IACA;;EAED,UAAU;EACV,oBAAoB;EACpB,wBAAwB;EACxB,kCAAkC;EAClC;EACA;;;UAIgB;EAChB;EACA;;UAGgB;;;;;EAKhB;;EAEA,YAAY;;;;;EAKZ,QAAQ;EACR,OAAO;;;;;;;;;;;;qBAaK,0BACZ,kBAAkB,oBAAoB;mBAUpB;mBACA;UATV;EAOR,YACkB,SAAS,qBAAqB,YAC9B,UAAS;;WAOlB,UAAO,OACR,6BACL,QAAQ;cAEC;;UAKJ;EAoDF,OACL,OAAO,2BACL,QAAQ;;;qBAgEC,wCAAwC;WAE1C;WACA;EAFV,YACU,iBACA"}