@aws-sdk/middleware-websocket 3.901.0 → 3.910.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/dist-cjs/index.js +319 -402
- package/package.json +9 -9
package/dist-cjs/index.js
CHANGED
|
@@ -1,430 +1,347 @@
|
|
|
1
|
-
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
20
2
|
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
resolveWebSocketConfig: () => resolveWebSocketConfig
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var eventstreamCodec = require('@smithy/eventstream-codec');
|
|
4
|
+
var utilHexEncoding = require('@smithy/util-hex-encoding');
|
|
5
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
6
|
+
var utilFormatUrl = require('@aws-sdk/util-format-url');
|
|
7
|
+
var eventstreamSerdeBrowser = require('@smithy/eventstream-serde-browser');
|
|
8
|
+
var fetchHttpHandler = require('@smithy/fetch-http-handler');
|
|
30
9
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...dateHeader,
|
|
63
|
-
":chunk-signature": {
|
|
64
|
-
type: "binary",
|
|
65
|
-
value: (0, import_util_hex_encoding.fromHex)(signedMessage.signature)
|
|
10
|
+
const getEventSigningTransformStream = (initialSignature, messageSigner, eventStreamCodec, systemClockOffsetProvider) => {
|
|
11
|
+
let priorSignature = initialSignature;
|
|
12
|
+
const transformer = {
|
|
13
|
+
start() { },
|
|
14
|
+
async transform(chunk, controller) {
|
|
15
|
+
try {
|
|
16
|
+
const now = new Date(Date.now() + (await systemClockOffsetProvider()));
|
|
17
|
+
const dateHeader = {
|
|
18
|
+
":date": { type: "timestamp", value: now },
|
|
19
|
+
};
|
|
20
|
+
const signedMessage = await messageSigner.sign({
|
|
21
|
+
message: {
|
|
22
|
+
body: chunk,
|
|
23
|
+
headers: dateHeader,
|
|
24
|
+
},
|
|
25
|
+
priorSignature: priorSignature,
|
|
26
|
+
}, {
|
|
27
|
+
signingDate: now,
|
|
28
|
+
});
|
|
29
|
+
priorSignature = signedMessage.signature;
|
|
30
|
+
const serializedSigned = eventStreamCodec.encode({
|
|
31
|
+
headers: {
|
|
32
|
+
...dateHeader,
|
|
33
|
+
":chunk-signature": {
|
|
34
|
+
type: "binary",
|
|
35
|
+
value: utilHexEncoding.fromHex(signedMessage.signature),
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
body: chunk,
|
|
39
|
+
});
|
|
40
|
+
controller.enqueue(serializedSigned);
|
|
66
41
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
return new TransformStream({ ...transformer });
|
|
77
|
-
}, "getEventSigningTransformStream");
|
|
42
|
+
catch (error) {
|
|
43
|
+
controller.error(error);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
return new TransformStream({ ...transformer });
|
|
48
|
+
};
|
|
78
49
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
constructor(options) {
|
|
88
|
-
this.messageSigner = options.messageSigner;
|
|
89
|
-
this.eventStreamCodec = new import_eventstream_codec.EventStreamCodec(options.utf8Encoder, options.utf8Decoder);
|
|
90
|
-
this.systemClockOffsetProvider = async () => options.systemClockOffset ?? 0;
|
|
91
|
-
}
|
|
92
|
-
async handle(next, args, context = {}) {
|
|
93
|
-
const request = args.request;
|
|
94
|
-
const { body: payload, headers, query } = request;
|
|
95
|
-
if (!(payload instanceof ReadableStream)) {
|
|
96
|
-
throw new Error("Eventstream payload must be a ReadableStream.");
|
|
50
|
+
class EventStreamPayloadHandler {
|
|
51
|
+
messageSigner;
|
|
52
|
+
eventStreamCodec;
|
|
53
|
+
systemClockOffsetProvider;
|
|
54
|
+
constructor(options) {
|
|
55
|
+
this.messageSigner = options.messageSigner;
|
|
56
|
+
this.eventStreamCodec = new eventstreamCodec.EventStreamCodec(options.utf8Encoder, options.utf8Decoder);
|
|
57
|
+
this.systemClockOffsetProvider = async () => options.systemClockOffset ?? 0;
|
|
97
58
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
59
|
+
async handle(next, args, context = {}) {
|
|
60
|
+
const request = args.request;
|
|
61
|
+
const { body: payload, headers, query } = request;
|
|
62
|
+
if (!(payload instanceof ReadableStream)) {
|
|
63
|
+
throw new Error("Eventstream payload must be a ReadableStream.");
|
|
64
|
+
}
|
|
65
|
+
const placeHolderStream = new TransformStream();
|
|
66
|
+
request.body = placeHolderStream.readable;
|
|
67
|
+
let result;
|
|
68
|
+
try {
|
|
69
|
+
result = await next(args);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
request.body.cancel();
|
|
73
|
+
throw e;
|
|
74
|
+
}
|
|
75
|
+
const match = (headers["authorization"] || "").match(/Signature=([\w]+)$/);
|
|
76
|
+
const priorSignature = (match || [])[1] || (query && query["X-Amz-Signature"]) || "";
|
|
77
|
+
const signingStream = getEventSigningTransformStream(priorSignature, await this.messageSigner(), this.eventStreamCodec, this.systemClockOffsetProvider);
|
|
78
|
+
const signedPayload = payload.pipeThrough(signingStream);
|
|
79
|
+
signedPayload.pipeThrough(placeHolderStream);
|
|
80
|
+
return result;
|
|
106
81
|
}
|
|
107
|
-
|
|
108
|
-
const priorSignature = (match || [])[1] || query && query["X-Amz-Signature"] || "";
|
|
109
|
-
const signingStream = getEventSigningTransformStream(
|
|
110
|
-
priorSignature,
|
|
111
|
-
await this.messageSigner(),
|
|
112
|
-
this.eventStreamCodec,
|
|
113
|
-
this.systemClockOffsetProvider
|
|
114
|
-
);
|
|
115
|
-
const signedPayload = payload.pipeThrough(signingStream);
|
|
116
|
-
signedPayload.pipeThrough(placeHolderStream);
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
82
|
+
}
|
|
120
83
|
|
|
121
|
-
|
|
122
|
-
var eventStreamPayloadHandlerProvider = /* @__PURE__ */ __name((options) => new EventStreamPayloadHandler(options), "eventStreamPayloadHandlerProvider");
|
|
84
|
+
const eventStreamPayloadHandlerProvider = (options) => new EventStreamPayloadHandler(options);
|
|
123
85
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
override: true
|
|
86
|
+
const injectSessionIdMiddleware = () => (next) => async (args) => {
|
|
87
|
+
const requestParams = {
|
|
88
|
+
...args.input,
|
|
89
|
+
};
|
|
90
|
+
const response = await next(args);
|
|
91
|
+
const output = response.output;
|
|
92
|
+
if (requestParams.SessionId && output.SessionId == null) {
|
|
93
|
+
output.SessionId = requestParams.SessionId;
|
|
94
|
+
}
|
|
95
|
+
return response;
|
|
96
|
+
};
|
|
97
|
+
const injectSessionIdMiddlewareOptions = {
|
|
98
|
+
step: "initialize",
|
|
99
|
+
name: "injectSessionIdMiddleware",
|
|
100
|
+
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
101
|
+
override: true,
|
|
141
102
|
};
|
|
142
103
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
104
|
+
const websocketEndpointMiddleware = (config, options) => (next) => (args) => {
|
|
105
|
+
const { request } = args;
|
|
106
|
+
if (protocolHttp.HttpRequest.isInstance(request) &&
|
|
107
|
+
config.requestHandler.metadata?.handlerProtocol?.toLowerCase().includes("websocket")) {
|
|
108
|
+
request.protocol = "wss:";
|
|
109
|
+
request.method = "GET";
|
|
110
|
+
request.path = `${request.path}-websocket`;
|
|
111
|
+
const { headers } = request;
|
|
112
|
+
delete headers["content-type"];
|
|
113
|
+
delete headers["x-amz-content-sha256"];
|
|
114
|
+
for (const name of Object.keys(headers)) {
|
|
115
|
+
if (name.indexOf(options.headerPrefix) === 0) {
|
|
116
|
+
const chunkedName = name.replace(options.headerPrefix, "");
|
|
117
|
+
request.query[chunkedName] = headers[name];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (headers["x-amz-user-agent"]) {
|
|
121
|
+
request.query["user-agent"] = headers["x-amz-user-agent"];
|
|
122
|
+
}
|
|
123
|
+
request.headers = { host: headers.host ?? request.hostname };
|
|
162
124
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
toMiddleware: "eventStreamHeaderMiddleware",
|
|
172
|
-
override: true
|
|
125
|
+
return next(args);
|
|
126
|
+
};
|
|
127
|
+
const websocketEndpointMiddlewareOptions = {
|
|
128
|
+
name: "websocketEndpointMiddleware",
|
|
129
|
+
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
130
|
+
relation: "after",
|
|
131
|
+
toMiddleware: "eventStreamHeaderMiddleware",
|
|
132
|
+
override: true,
|
|
173
133
|
};
|
|
174
134
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}), "getWebSocketPlugin");
|
|
182
|
-
|
|
183
|
-
// src/WebsocketSignatureV4.ts
|
|
184
|
-
|
|
135
|
+
const getWebSocketPlugin = (config, options) => ({
|
|
136
|
+
applyToStack: (clientStack) => {
|
|
137
|
+
clientStack.addRelativeTo(websocketEndpointMiddleware(config, options), websocketEndpointMiddlewareOptions);
|
|
138
|
+
clientStack.add(injectSessionIdMiddleware(), injectSessionIdMiddlewareOptions);
|
|
139
|
+
},
|
|
140
|
+
});
|
|
185
141
|
|
|
186
|
-
|
|
187
|
-
var isWebSocketRequest = /* @__PURE__ */ __name((request) => request.protocol === "ws:" || request.protocol === "wss:", "isWebSocketRequest");
|
|
142
|
+
const isWebSocketRequest = (request) => request.protocol === "ws:" || request.protocol === "wss:";
|
|
188
143
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// the other headers, the signature could be mismatch.
|
|
212
|
-
unsignableHeaders: new Set(Object.keys(toSign.headers).filter((header) => header !== "host"))
|
|
144
|
+
class WebsocketSignatureV4 {
|
|
145
|
+
signer;
|
|
146
|
+
constructor(options) {
|
|
147
|
+
this.signer = options.signer;
|
|
148
|
+
}
|
|
149
|
+
presign(originalRequest, options = {}) {
|
|
150
|
+
return this.signer.presign(originalRequest, options);
|
|
151
|
+
}
|
|
152
|
+
async sign(toSign, options) {
|
|
153
|
+
if (protocolHttp.HttpRequest.isInstance(toSign) && isWebSocketRequest(toSign)) {
|
|
154
|
+
const signedRequest = await this.signer.presign({ ...toSign, body: "" }, {
|
|
155
|
+
...options,
|
|
156
|
+
expiresIn: 60,
|
|
157
|
+
unsignableHeaders: new Set(Object.keys(toSign.headers).filter((header) => header !== "host")),
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
...signedRequest,
|
|
161
|
+
body: toSign.body,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
return this.signer.sign(toSign, options);
|
|
213
166
|
}
|
|
214
|
-
);
|
|
215
|
-
return {
|
|
216
|
-
...signedRequest,
|
|
217
|
-
body: toSign.body
|
|
218
|
-
};
|
|
219
|
-
} else {
|
|
220
|
-
return this.signer.sign(toSign, options);
|
|
221
167
|
}
|
|
222
|
-
|
|
223
|
-
};
|
|
168
|
+
}
|
|
224
169
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
var validateSigner = /* @__PURE__ */ __name((signer) => !!signer, "validateSigner");
|
|
239
|
-
|
|
240
|
-
// src/websocket-fetch-handler.ts
|
|
241
|
-
var import_util_format_url = require("@aws-sdk/util-format-url");
|
|
242
|
-
var import_eventstream_serde_browser = require("@smithy/eventstream-serde-browser");
|
|
243
|
-
var import_fetch_http_handler = require("@smithy/fetch-http-handler");
|
|
170
|
+
const resolveWebSocketConfig = (input) => {
|
|
171
|
+
const { signer } = input;
|
|
172
|
+
return Object.assign(input, {
|
|
173
|
+
signer: async (authScheme) => {
|
|
174
|
+
const signerObj = await signer(authScheme);
|
|
175
|
+
if (validateSigner(signerObj)) {
|
|
176
|
+
return new WebsocketSignatureV4({ signer: signerObj });
|
|
177
|
+
}
|
|
178
|
+
throw new Error("Expected WebsocketSignatureV4 signer, please check the client constructor.");
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
const validateSigner = (signer) => !!signer;
|
|
244
183
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
* or instantiates a new instance of this handler.
|
|
260
|
-
*/
|
|
261
|
-
static create(instanceOrOptions, httpHandler = new import_fetch_http_handler.FetchHttpHandler()) {
|
|
262
|
-
if (typeof instanceOrOptions?.handle === "function") {
|
|
263
|
-
return instanceOrOptions;
|
|
264
|
-
}
|
|
265
|
-
return new _WebSocketFetchHandler(
|
|
266
|
-
instanceOrOptions,
|
|
267
|
-
httpHandler
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
constructor(options, httpHandler = new import_fetch_http_handler.FetchHttpHandler()) {
|
|
271
|
-
this.httpHandler = httpHandler;
|
|
272
|
-
if (typeof options === "function") {
|
|
273
|
-
this.config = {};
|
|
274
|
-
this.configPromise = options().then((opts) => this.config = opts ?? {});
|
|
275
|
-
} else {
|
|
276
|
-
this.config = options ?? {};
|
|
277
|
-
this.configPromise = Promise.resolve(this.config);
|
|
184
|
+
const DEFAULT_WS_CONNECTION_TIMEOUT_MS = 2000;
|
|
185
|
+
class WebSocketFetchHandler {
|
|
186
|
+
metadata = {
|
|
187
|
+
handlerProtocol: "websocket/h1.1",
|
|
188
|
+
};
|
|
189
|
+
config;
|
|
190
|
+
configPromise;
|
|
191
|
+
httpHandler;
|
|
192
|
+
sockets = {};
|
|
193
|
+
static create(instanceOrOptions, httpHandler = new fetchHttpHandler.FetchHttpHandler()) {
|
|
194
|
+
if (typeof instanceOrOptions?.handle === "function") {
|
|
195
|
+
return instanceOrOptions;
|
|
196
|
+
}
|
|
197
|
+
return new WebSocketFetchHandler(instanceOrOptions, httpHandler);
|
|
278
198
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
delete this.sockets[key];
|
|
199
|
+
constructor(options, httpHandler = new fetchHttpHandler.FetchHttpHandler()) {
|
|
200
|
+
this.httpHandler = httpHandler;
|
|
201
|
+
if (typeof options === "function") {
|
|
202
|
+
this.config = {};
|
|
203
|
+
this.configPromise = options().then((opts) => (this.config = opts ?? {}));
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
this.config = options ?? {};
|
|
207
|
+
this.configPromise = Promise.resolve(this.config);
|
|
208
|
+
}
|
|
290
209
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
210
|
+
destroy() {
|
|
211
|
+
for (const [key, sockets] of Object.entries(this.sockets)) {
|
|
212
|
+
for (const socket of sockets) {
|
|
213
|
+
socket.close(1000, `Socket closed through destroy() call`);
|
|
214
|
+
}
|
|
215
|
+
delete this.sockets[key];
|
|
216
|
+
}
|
|
295
217
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
218
|
+
async handle(request) {
|
|
219
|
+
if (!isWebSocketRequest(request)) {
|
|
220
|
+
return this.httpHandler.handle(request);
|
|
221
|
+
}
|
|
222
|
+
const url = utilFormatUrl.formatUrl(request);
|
|
223
|
+
const socket = new WebSocket(url);
|
|
224
|
+
if (!this.sockets[url]) {
|
|
225
|
+
this.sockets[url] = [];
|
|
226
|
+
}
|
|
227
|
+
this.sockets[url].push(socket);
|
|
228
|
+
socket.binaryType = "arraybuffer";
|
|
229
|
+
this.config = await this.configPromise;
|
|
230
|
+
const { connectionTimeout = DEFAULT_WS_CONNECTION_TIMEOUT_MS } = this.config;
|
|
231
|
+
await this.waitForReady(socket, connectionTimeout);
|
|
232
|
+
const { body } = request;
|
|
233
|
+
const bodyStream = getIterator(body);
|
|
234
|
+
const asyncIterable = this.connect(socket, bodyStream);
|
|
235
|
+
const outputPayload = toReadableStream(asyncIterable);
|
|
236
|
+
return {
|
|
237
|
+
response: new protocolHttp.HttpResponse({
|
|
238
|
+
statusCode: 200,
|
|
239
|
+
body: outputPayload,
|
|
240
|
+
}),
|
|
241
|
+
};
|
|
300
242
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
await this.waitForReady(socket, connectionTimeout);
|
|
306
|
-
const { body } = request;
|
|
307
|
-
const bodyStream = getIterator(body);
|
|
308
|
-
const asyncIterable = this.connect(socket, bodyStream);
|
|
309
|
-
const outputPayload = toReadableStream(asyncIterable);
|
|
310
|
-
return {
|
|
311
|
-
response: new import_protocol_http.HttpResponse({
|
|
312
|
-
statusCode: 200,
|
|
313
|
-
// indicates connection success
|
|
314
|
-
body: outputPayload
|
|
315
|
-
})
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
updateHttpClientConfig(key, value) {
|
|
319
|
-
this.configPromise = this.configPromise.then((config) => {
|
|
320
|
-
config[key] = value;
|
|
321
|
-
return config;
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
httpHandlerConfigs() {
|
|
325
|
-
return this.config ?? {};
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Removes all closing/closed sockets from the socket pool for URL.
|
|
329
|
-
*/
|
|
330
|
-
removeNotUsableSockets(url) {
|
|
331
|
-
this.sockets[url] = (this.sockets[url] ?? []).filter(
|
|
332
|
-
(socket) => ![WebSocket.CLOSING, WebSocket.CLOSED].includes(socket.readyState)
|
|
333
|
-
);
|
|
334
|
-
}
|
|
335
|
-
waitForReady(socket, connectionTimeout) {
|
|
336
|
-
return new Promise((resolve, reject) => {
|
|
337
|
-
const timeout = setTimeout(() => {
|
|
338
|
-
this.removeNotUsableSockets(socket.url);
|
|
339
|
-
reject({
|
|
340
|
-
$metadata: {
|
|
341
|
-
httpStatusCode: 500
|
|
342
|
-
}
|
|
243
|
+
updateHttpClientConfig(key, value) {
|
|
244
|
+
this.configPromise = this.configPromise.then((config) => {
|
|
245
|
+
config[key] = value;
|
|
246
|
+
return config;
|
|
343
247
|
});
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
socketErrorOccurred = true;
|
|
366
|
-
socket.close();
|
|
367
|
-
reject(error);
|
|
368
|
-
};
|
|
369
|
-
socket.onclose = () => {
|
|
370
|
-
this.removeNotUsableSockets(socket.url);
|
|
371
|
-
if (socketErrorOccurred) return;
|
|
372
|
-
if (streamError) {
|
|
373
|
-
reject(streamError);
|
|
374
|
-
} else {
|
|
375
|
-
resolve({
|
|
376
|
-
done: true,
|
|
377
|
-
value: void 0
|
|
378
|
-
// unchecked because done=true.
|
|
248
|
+
}
|
|
249
|
+
httpHandlerConfigs() {
|
|
250
|
+
return this.config ?? {};
|
|
251
|
+
}
|
|
252
|
+
removeNotUsableSockets(url) {
|
|
253
|
+
this.sockets[url] = (this.sockets[url] ?? []).filter((socket) => ![WebSocket.CLOSING, WebSocket.CLOSED].includes(socket.readyState));
|
|
254
|
+
}
|
|
255
|
+
waitForReady(socket, connectionTimeout) {
|
|
256
|
+
return new Promise((resolve, reject) => {
|
|
257
|
+
const timeout = setTimeout(() => {
|
|
258
|
+
this.removeNotUsableSockets(socket.url);
|
|
259
|
+
reject({
|
|
260
|
+
$metadata: {
|
|
261
|
+
httpStatusCode: 500,
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
}, connectionTimeout);
|
|
265
|
+
socket.onopen = () => {
|
|
266
|
+
clearTimeout(timeout);
|
|
267
|
+
resolve();
|
|
268
|
+
};
|
|
379
269
|
});
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
270
|
+
}
|
|
271
|
+
connect(socket, data) {
|
|
272
|
+
let streamError = undefined;
|
|
273
|
+
let socketErrorOccurred = false;
|
|
274
|
+
let reject = () => { };
|
|
275
|
+
let resolve = () => { };
|
|
276
|
+
socket.onmessage = (event) => {
|
|
277
|
+
resolve({
|
|
278
|
+
done: false,
|
|
279
|
+
value: new Uint8Array(event.data),
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
socket.onerror = (error) => {
|
|
283
|
+
socketErrorOccurred = true;
|
|
284
|
+
socket.close();
|
|
285
|
+
reject(error);
|
|
286
|
+
};
|
|
287
|
+
socket.onclose = () => {
|
|
288
|
+
this.removeNotUsableSockets(socket.url);
|
|
289
|
+
if (socketErrorOccurred)
|
|
290
|
+
return;
|
|
291
|
+
if (streamError) {
|
|
292
|
+
reject(streamError);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
resolve({
|
|
296
|
+
done: true,
|
|
297
|
+
value: undefined,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
const outputStream = {
|
|
302
|
+
[Symbol.asyncIterator]: () => ({
|
|
303
|
+
next: () => {
|
|
304
|
+
return new Promise((_resolve, _reject) => {
|
|
305
|
+
resolve = _resolve;
|
|
306
|
+
reject = _reject;
|
|
307
|
+
});
|
|
308
|
+
},
|
|
309
|
+
}),
|
|
310
|
+
};
|
|
311
|
+
const send = async () => {
|
|
312
|
+
try {
|
|
313
|
+
for await (const inputChunk of data) {
|
|
314
|
+
socket.send(inputChunk);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
streamError = err;
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
socket.close(1000);
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
send();
|
|
325
|
+
return outputStream;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const getIterator = (stream) => {
|
|
329
|
+
if (stream[Symbol.asyncIterator]) {
|
|
330
|
+
return stream;
|
|
331
|
+
}
|
|
332
|
+
if (isReadableStream(stream)) {
|
|
333
|
+
return eventstreamSerdeBrowser.readableStreamtoIterable(stream);
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
[Symbol.asyncIterator]: async function* () {
|
|
337
|
+
yield stream;
|
|
338
|
+
},
|
|
391
339
|
};
|
|
392
|
-
const send = /* @__PURE__ */ __name(async () => {
|
|
393
|
-
try {
|
|
394
|
-
for await (const inputChunk of data) {
|
|
395
|
-
socket.send(inputChunk);
|
|
396
|
-
}
|
|
397
|
-
} catch (err) {
|
|
398
|
-
streamError = err;
|
|
399
|
-
} finally {
|
|
400
|
-
socket.close(1e3);
|
|
401
|
-
}
|
|
402
|
-
}, "send");
|
|
403
|
-
send();
|
|
404
|
-
return outputStream;
|
|
405
|
-
}
|
|
406
340
|
};
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return stream;
|
|
410
|
-
}
|
|
411
|
-
if (isReadableStream(stream)) {
|
|
412
|
-
return (0, import_eventstream_serde_browser.readableStreamtoIterable)(stream);
|
|
413
|
-
}
|
|
414
|
-
return {
|
|
415
|
-
[Symbol.asyncIterator]: async function* () {
|
|
416
|
-
yield stream;
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
}, "getIterator");
|
|
420
|
-
var toReadableStream = /* @__PURE__ */ __name((asyncIterable) => typeof ReadableStream === "function" ? (0, import_eventstream_serde_browser.iterableToReadableStream)(asyncIterable) : asyncIterable, "toReadableStream");
|
|
421
|
-
var isReadableStream = /* @__PURE__ */ __name((payload) => typeof ReadableStream === "function" && payload instanceof ReadableStream, "isReadableStream");
|
|
422
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
423
|
-
|
|
424
|
-
0 && (module.exports = {
|
|
425
|
-
eventStreamPayloadHandlerProvider,
|
|
426
|
-
getWebSocketPlugin,
|
|
427
|
-
resolveWebSocketConfig,
|
|
428
|
-
WebSocketFetchHandler
|
|
429
|
-
});
|
|
341
|
+
const toReadableStream = (asyncIterable) => typeof ReadableStream === "function" ? eventstreamSerdeBrowser.iterableToReadableStream(asyncIterable) : asyncIterable;
|
|
342
|
+
const isReadableStream = (payload) => typeof ReadableStream === "function" && payload instanceof ReadableStream;
|
|
430
343
|
|
|
344
|
+
exports.WebSocketFetchHandler = WebSocketFetchHandler;
|
|
345
|
+
exports.eventStreamPayloadHandlerProvider = eventStreamPayloadHandlerProvider;
|
|
346
|
+
exports.getWebSocketPlugin = getWebSocketPlugin;
|
|
347
|
+
exports.resolveWebSocketConfig = resolveWebSocketConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-websocket",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.910.0",
|
|
4
4
|
"main": "./dist-cjs/index.js",
|
|
5
5
|
"module": "./dist-es/index.js",
|
|
6
6
|
"types": "./dist-types/index.d.ts",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@aws-sdk/types": "3.
|
|
28
|
-
"@aws-sdk/util-format-url": "3.
|
|
29
|
-
"@smithy/eventstream-codec": "^4.2.
|
|
30
|
-
"@smithy/eventstream-serde-browser": "^4.2.
|
|
31
|
-
"@smithy/fetch-http-handler": "^5.3.
|
|
32
|
-
"@smithy/protocol-http": "^5.3.
|
|
33
|
-
"@smithy/signature-v4": "^5.3.
|
|
34
|
-
"@smithy/types": "^4.
|
|
27
|
+
"@aws-sdk/types": "3.910.0",
|
|
28
|
+
"@aws-sdk/util-format-url": "3.910.0",
|
|
29
|
+
"@smithy/eventstream-codec": "^4.2.2",
|
|
30
|
+
"@smithy/eventstream-serde-browser": "^4.2.2",
|
|
31
|
+
"@smithy/fetch-http-handler": "^5.3.3",
|
|
32
|
+
"@smithy/protocol-http": "^5.3.2",
|
|
33
|
+
"@smithy/signature-v4": "^5.3.2",
|
|
34
|
+
"@smithy/types": "^4.7.1",
|
|
35
35
|
"@smithy/util-hex-encoding": "^4.2.0",
|
|
36
36
|
"tslib": "^2.6.2"
|
|
37
37
|
},
|