@aws-sdk/middleware-websocket 3.305.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/LICENSE +201 -0
- package/README.md +12 -0
- package/dist-cjs/EventStreamPayloadHandler.js +35 -0
- package/dist-cjs/WebsocketSignatureV4.js +29 -0
- package/dist-cjs/configuration.js +16 -0
- package/dist-cjs/eventstream-payload-handler-provider.js +6 -0
- package/dist-cjs/get-event-signing-stream.js +42 -0
- package/dist-cjs/index.js +7 -0
- package/dist-cjs/middleware-session-id.js +21 -0
- package/dist-cjs/middleware-websocket-endpoint.js +36 -0
- package/dist-cjs/plugin.js +12 -0
- package/dist-cjs/utils.js +5 -0
- package/dist-cjs/websocket-fetch-handler.js +143 -0
- package/dist-es/EventStreamPayloadHandler.js +31 -0
- package/dist-es/WebsocketSignatureV4.js +25 -0
- package/dist-es/configuration.js +12 -0
- package/dist-es/eventstream-payload-handler-provider.js +2 -0
- package/dist-es/get-event-signing-stream.js +38 -0
- package/dist-es/index.js +4 -0
- package/dist-es/middleware-session-id.js +17 -0
- package/dist-es/middleware-websocket-endpoint.js +31 -0
- package/dist-es/plugin.js +8 -0
- package/dist-es/utils.js +1 -0
- package/dist-es/websocket-fetch-handler.js +139 -0
- package/dist-types/EventStreamPayloadHandler.d.ts +19 -0
- package/dist-types/WebsocketSignatureV4.d.ts +10 -0
- package/dist-types/configuration.d.ts +19 -0
- package/dist-types/eventstream-payload-handler-provider.d.ts +3 -0
- package/dist-types/get-event-signing-stream.d.ts +8 -0
- package/dist-types/index.d.ts +4 -0
- package/dist-types/middleware-session-id.d.ts +10 -0
- package/dist-types/middleware-websocket-endpoint.d.ts +13 -0
- package/dist-types/plugin.d.ts +8 -0
- package/dist-types/ts3.4/EventStreamPayloadHandler.d.ts +29 -0
- package/dist-types/ts3.4/WebsocketSignatureV4.d.ts +22 -0
- package/dist-types/ts3.4/configuration.d.ts +14 -0
- package/dist-types/ts3.4/eventstream-payload-handler-provider.d.ts +2 -0
- package/dist-types/ts3.4/get-event-signing-stream.d.ts +7 -0
- package/dist-types/ts3.4/index.d.ts +4 -0
- package/dist-types/ts3.4/middleware-session-id.d.ts +6 -0
- package/dist-types/ts3.4/middleware-websocket-endpoint.d.ts +14 -0
- package/dist-types/ts3.4/plugin.d.ts +11 -0
- package/dist-types/ts3.4/utils.d.ts +2 -0
- package/dist-types/ts3.4/websocket-fetch-handler.d.ts +28 -0
- package/dist-types/utils.d.ts +2 -0
- package/dist-types/websocket-fetch-handler.d.ts +36 -0
- package/package.json +67 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { fromHex } from "@aws-sdk/util-hex-encoding";
|
|
2
|
+
export const getEventSigningTransformStream = (initialSignature, eventSigner, eventStreamCodec) => {
|
|
3
|
+
let priorSignature = initialSignature;
|
|
4
|
+
const transformer = {
|
|
5
|
+
start() { },
|
|
6
|
+
async transform(chunk, controller) {
|
|
7
|
+
try {
|
|
8
|
+
const now = new Date();
|
|
9
|
+
const dateHeader = {
|
|
10
|
+
":date": { type: "timestamp", value: now },
|
|
11
|
+
};
|
|
12
|
+
const signature = await eventSigner.sign({
|
|
13
|
+
payload: chunk,
|
|
14
|
+
headers: eventStreamCodec.formatHeaders(dateHeader),
|
|
15
|
+
}, {
|
|
16
|
+
priorSignature,
|
|
17
|
+
signingDate: now,
|
|
18
|
+
});
|
|
19
|
+
priorSignature = signature;
|
|
20
|
+
const serializedSigned = eventStreamCodec.encode({
|
|
21
|
+
headers: {
|
|
22
|
+
...dateHeader,
|
|
23
|
+
":chunk-signature": {
|
|
24
|
+
type: "binary",
|
|
25
|
+
value: fromHex(signature),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
body: chunk,
|
|
29
|
+
});
|
|
30
|
+
controller.enqueue(serializedSigned);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
controller.error(error);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
return new TransformStream({ ...transformer });
|
|
38
|
+
};
|
package/dist-es/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const injectSessionIdMiddleware = () => (next) => async (args) => {
|
|
2
|
+
const requestParams = {
|
|
3
|
+
...args.input,
|
|
4
|
+
};
|
|
5
|
+
const response = await next(args);
|
|
6
|
+
const output = response.output;
|
|
7
|
+
if (requestParams.SessionId && output.SessionId == null) {
|
|
8
|
+
output.SessionId = requestParams.SessionId;
|
|
9
|
+
}
|
|
10
|
+
return response;
|
|
11
|
+
};
|
|
12
|
+
export const injectSessionIdMiddlewareOptions = {
|
|
13
|
+
step: "initialize",
|
|
14
|
+
name: "injectSessionIdMiddleware",
|
|
15
|
+
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
16
|
+
override: true,
|
|
17
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HttpRequest } from "@aws-sdk/protocol-http";
|
|
2
|
+
export const websocketEndpointMiddleware = (config, options) => (next) => (args) => {
|
|
3
|
+
const { request } = args;
|
|
4
|
+
if (HttpRequest.isInstance(request) &&
|
|
5
|
+
config.requestHandler.metadata?.handlerProtocol?.toLowerCase().includes("websocket")) {
|
|
6
|
+
request.protocol = "wss:";
|
|
7
|
+
request.method = "GET";
|
|
8
|
+
request.path = `${request.path}-websocket`;
|
|
9
|
+
const { headers } = request;
|
|
10
|
+
delete headers["Content-Type"];
|
|
11
|
+
delete headers["x-amz-content-sha256"];
|
|
12
|
+
for (const name of Object.keys(headers)) {
|
|
13
|
+
if (name.indexOf(options.headerPrefix) === 0) {
|
|
14
|
+
const chunkedName = name.replace(options.headerPrefix, "");
|
|
15
|
+
request.query[chunkedName] = headers[name];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (headers["x-amz-user-agent"]) {
|
|
19
|
+
request.query["user-agent"] = headers["x-amz-user-agent"];
|
|
20
|
+
}
|
|
21
|
+
request.headers = { host: headers.host ?? request.hostname };
|
|
22
|
+
}
|
|
23
|
+
return next(args);
|
|
24
|
+
};
|
|
25
|
+
export const websocketEndpointMiddlewareOptions = {
|
|
26
|
+
name: "websocketEndpointMiddleware",
|
|
27
|
+
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
28
|
+
relation: "after",
|
|
29
|
+
toMiddleware: "eventStreamHeaderMiddleware",
|
|
30
|
+
override: true,
|
|
31
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { injectSessionIdMiddleware, injectSessionIdMiddlewareOptions } from "./middleware-session-id";
|
|
2
|
+
import { websocketEndpointMiddleware, websocketEndpointMiddlewareOptions } from "./middleware-websocket-endpoint";
|
|
3
|
+
export const getWebSocketPlugin = (config, options) => ({
|
|
4
|
+
applyToStack: (clientStack) => {
|
|
5
|
+
clientStack.addRelativeTo(websocketEndpointMiddleware(config, options), websocketEndpointMiddlewareOptions);
|
|
6
|
+
clientStack.add(injectSessionIdMiddleware(), injectSessionIdMiddlewareOptions);
|
|
7
|
+
},
|
|
8
|
+
});
|
package/dist-es/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isWebSocketRequest = (request) => request.protocol === "ws:" || request.protocol === "wss:";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { iterableToReadableStream, readableStreamtoIterable } from "@aws-sdk/eventstream-serde-browser";
|
|
2
|
+
import { FetchHttpHandler } from "@aws-sdk/fetch-http-handler";
|
|
3
|
+
import { HttpResponse } from "@aws-sdk/protocol-http";
|
|
4
|
+
import { formatUrl } from "@aws-sdk/util-format-url";
|
|
5
|
+
import { isWebSocketRequest } from "./utils";
|
|
6
|
+
const DEFAULT_WS_CONNECTION_TIMEOUT_MS = 2000;
|
|
7
|
+
export class WebSocketFetchHandler {
|
|
8
|
+
constructor(options, httpHandler = new FetchHttpHandler()) {
|
|
9
|
+
this.metadata = {
|
|
10
|
+
handlerProtocol: "websocket/h1.1",
|
|
11
|
+
};
|
|
12
|
+
this.sockets = {};
|
|
13
|
+
this.httpHandler = httpHandler;
|
|
14
|
+
if (typeof options === "function") {
|
|
15
|
+
this.configPromise = options().then((opts) => opts ?? {});
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.configPromise = Promise.resolve(options ?? {});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
destroy() {
|
|
22
|
+
for (const [key, sockets] of Object.entries(this.sockets)) {
|
|
23
|
+
for (const socket of sockets) {
|
|
24
|
+
socket.close(1000, `Socket closed through destroy() call`);
|
|
25
|
+
}
|
|
26
|
+
delete this.sockets[key];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async handle(request) {
|
|
30
|
+
if (!isWebSocketRequest(request)) {
|
|
31
|
+
return this.httpHandler.handle(request);
|
|
32
|
+
}
|
|
33
|
+
const url = formatUrl(request);
|
|
34
|
+
const socket = new WebSocket(url);
|
|
35
|
+
if (!this.sockets[url]) {
|
|
36
|
+
this.sockets[url] = [];
|
|
37
|
+
}
|
|
38
|
+
this.sockets[url].push(socket);
|
|
39
|
+
socket.binaryType = "arraybuffer";
|
|
40
|
+
const { connectionTimeout = DEFAULT_WS_CONNECTION_TIMEOUT_MS } = await this.configPromise;
|
|
41
|
+
await this.waitForReady(socket, connectionTimeout);
|
|
42
|
+
const { body } = request;
|
|
43
|
+
const bodyStream = getIterator(body);
|
|
44
|
+
const asyncIterable = this.connect(socket, bodyStream);
|
|
45
|
+
const outputPayload = toReadableStream(asyncIterable);
|
|
46
|
+
return {
|
|
47
|
+
response: new HttpResponse({
|
|
48
|
+
statusCode: 200,
|
|
49
|
+
body: outputPayload,
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
removeNotUsableSockets(url) {
|
|
54
|
+
this.sockets[url] = this.sockets[url].filter((socket) => ![WebSocket.CLOSING, WebSocket.CLOSED].includes(socket.readyState));
|
|
55
|
+
}
|
|
56
|
+
waitForReady(socket, connectionTimeout) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const timeout = setTimeout(() => {
|
|
59
|
+
this.removeNotUsableSockets(socket.url);
|
|
60
|
+
reject({
|
|
61
|
+
$metadata: {
|
|
62
|
+
httpStatusCode: 500,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}, connectionTimeout);
|
|
66
|
+
socket.onopen = () => {
|
|
67
|
+
clearTimeout(timeout);
|
|
68
|
+
resolve();
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
connect(socket, data) {
|
|
73
|
+
let streamError = undefined;
|
|
74
|
+
const outputStream = {
|
|
75
|
+
[Symbol.asyncIterator]: () => ({
|
|
76
|
+
next: () => {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
let socketErrorOccurred = false;
|
|
79
|
+
socket.onerror = (error) => {
|
|
80
|
+
socketErrorOccurred = true;
|
|
81
|
+
socket.close();
|
|
82
|
+
reject(error);
|
|
83
|
+
};
|
|
84
|
+
socket.onclose = () => {
|
|
85
|
+
this.removeNotUsableSockets(socket.url);
|
|
86
|
+
if (socketErrorOccurred)
|
|
87
|
+
return;
|
|
88
|
+
if (streamError) {
|
|
89
|
+
reject(streamError);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
resolve({
|
|
93
|
+
done: true,
|
|
94
|
+
value: undefined,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
socket.onmessage = (event) => {
|
|
99
|
+
resolve({
|
|
100
|
+
done: false,
|
|
101
|
+
value: new Uint8Array(event.data),
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
};
|
|
108
|
+
const send = async () => {
|
|
109
|
+
try {
|
|
110
|
+
for await (const inputChunk of data) {
|
|
111
|
+
socket.send(inputChunk);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
streamError = err;
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
socket.close(1000);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
send();
|
|
122
|
+
return outputStream;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const getIterator = (stream) => {
|
|
126
|
+
if (stream[Symbol.asyncIterator]) {
|
|
127
|
+
return stream;
|
|
128
|
+
}
|
|
129
|
+
if (isReadableStream(stream)) {
|
|
130
|
+
return readableStreamtoIterable(stream);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
[Symbol.asyncIterator]: async function* () {
|
|
134
|
+
yield stream;
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
const toReadableStream = (asyncIterable) => typeof ReadableStream === "function" ? iterableToReadableStream(asyncIterable) : asyncIterable;
|
|
139
|
+
const isReadableStream = (payload) => typeof ReadableStream === "function" && payload instanceof ReadableStream;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Decoder, Encoder, EventSigner, EventStreamPayloadHandler as IEventStreamPayloadHandler, FinalizeHandler, FinalizeHandlerArguments, FinalizeHandlerOutput, HandlerExecutionContext, MetadataBearer, Provider } from "@aws-sdk/types";
|
|
2
|
+
export interface EventStreamPayloadHandlerOptions {
|
|
3
|
+
eventSigner: Provider<EventSigner>;
|
|
4
|
+
utf8Encoder: Encoder;
|
|
5
|
+
utf8Decoder: Decoder;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A handler that control the eventstream payload flow:
|
|
9
|
+
* 1. Pause stream for initial request.
|
|
10
|
+
* 2. Close the stream if initial request fails.
|
|
11
|
+
* 3. Start piping payload when connection is established.
|
|
12
|
+
* 4. Sign the payload after payload stream starting to flow.
|
|
13
|
+
*/
|
|
14
|
+
export declare class EventStreamPayloadHandler implements IEventStreamPayloadHandler {
|
|
15
|
+
private readonly eventSigner;
|
|
16
|
+
private readonly eventStreamCodec;
|
|
17
|
+
constructor(options: EventStreamPayloadHandlerOptions);
|
|
18
|
+
handle<T extends MetadataBearer>(next: FinalizeHandler<any, T>, args: FinalizeHandlerArguments<any>, context?: HandlerExecutionContext): Promise<FinalizeHandlerOutput<T>>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SignatureV4 as BaseSignatureV4 } from "@aws-sdk/signature-v4";
|
|
2
|
+
import { HttpRequest as IHttpRequest, RequestPresigner, RequestPresigningArguments, RequestSigner, RequestSigningArguments } from "@aws-sdk/types";
|
|
3
|
+
export declare class WebsocketSignatureV4 implements RequestSigner, RequestPresigner {
|
|
4
|
+
private readonly signer;
|
|
5
|
+
constructor(options: {
|
|
6
|
+
signer: BaseSignatureV4;
|
|
7
|
+
});
|
|
8
|
+
presign(originalRequest: IHttpRequest, options?: RequestPresigningArguments): Promise<IHttpRequest>;
|
|
9
|
+
sign(toSign: IHttpRequest, options?: RequestSigningArguments): Promise<IHttpRequest>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AuthScheme, RequestHandler, RequestSigner } from "@aws-sdk/types";
|
|
2
|
+
export interface WebSocketInputConfig {
|
|
3
|
+
}
|
|
4
|
+
interface PreviouslyResolved {
|
|
5
|
+
signer: (authScheme: AuthScheme) => Promise<RequestSigner>;
|
|
6
|
+
requestHandler: RequestHandler<any, any>;
|
|
7
|
+
}
|
|
8
|
+
export interface WebSocketResolvedConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Resolved value of input config {@link AwsAuthInputConfig.signer}
|
|
11
|
+
*/
|
|
12
|
+
signer: (authScheme: AuthScheme) => Promise<RequestSigner>;
|
|
13
|
+
/**
|
|
14
|
+
* The HTTP handler to use. Fetch in browser and Https in Nodejs.
|
|
15
|
+
*/
|
|
16
|
+
requestHandler: RequestHandler<any, any>;
|
|
17
|
+
}
|
|
18
|
+
export declare const resolveWebSocketConfig: <T>(input: T & WebSocketInputConfig & PreviouslyResolved) => T & WebSocketResolvedConfig;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EventStreamCodec } from "@aws-sdk/eventstream-codec";
|
|
2
|
+
import { EventSigner } from "@aws-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
* Get a transform stream that signs the eventstream
|
|
5
|
+
* Implementation replicated from @aws-sdk/eventstream-handler-node::EventSigningStream
|
|
6
|
+
* but modified to be compatible with WHATWG stream interface
|
|
7
|
+
*/
|
|
8
|
+
export declare const getEventSigningTransformStream: (initialSignature: string, eventSigner: EventSigner, eventStreamCodec: EventStreamCodec) => TransformStream<Uint8Array, Uint8Array>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InitializeHandlerOptions, InitializeMiddleware } from "@aws-sdk/types";
|
|
2
|
+
/**
|
|
3
|
+
* Most WebSocket operations contains `SessionId` parameter in both input and
|
|
4
|
+
* output, with the same value. This middleware populates the `SessionId`
|
|
5
|
+
* parameter from request to the response. This is necessary because in
|
|
6
|
+
* WebSocket, the SDK cannot access any parameters other than the response
|
|
7
|
+
* stream. So we fake response parameter.
|
|
8
|
+
*/
|
|
9
|
+
export declare const injectSessionIdMiddleware: () => InitializeMiddleware<any, any>;
|
|
10
|
+
export declare const injectSessionIdMiddlewareOptions: InitializeHandlerOptions;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BuildMiddleware, RelativeMiddlewareOptions, RequestHandler } from "@aws-sdk/types";
|
|
2
|
+
/**
|
|
3
|
+
* Middleware that modify the request to from http to WebSocket
|
|
4
|
+
* This middleware can only be applied to commands that supports bi-directional event streaming via WebSocket.
|
|
5
|
+
* Example of headerPrefix is "x-amz-rekognition-streaming-liveness-*" prefix exists for all rekognition streaming
|
|
6
|
+
* websocket API's headers. The common prefix are to be removed when moving them from headers to querystring.
|
|
7
|
+
*/
|
|
8
|
+
export declare const websocketEndpointMiddleware: (config: {
|
|
9
|
+
requestHandler: RequestHandler<any, any>;
|
|
10
|
+
}, options: {
|
|
11
|
+
headerPrefix: string;
|
|
12
|
+
}) => BuildMiddleware<any, any>;
|
|
13
|
+
export declare const websocketEndpointMiddlewareOptions: RelativeMiddlewareOptions;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Pluggable, RequestHandler } from "@aws-sdk/types";
|
|
2
|
+
interface WebSocketResolvedConfig {
|
|
3
|
+
requestHandler: RequestHandler<any, any>;
|
|
4
|
+
}
|
|
5
|
+
export declare const getWebSocketPlugin: (config: WebSocketResolvedConfig, options: {
|
|
6
|
+
headerPrefix: string;
|
|
7
|
+
}) => Pluggable<any, any>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Decoder,
|
|
3
|
+
Encoder,
|
|
4
|
+
EventSigner,
|
|
5
|
+
EventStreamPayloadHandler as IEventStreamPayloadHandler,
|
|
6
|
+
FinalizeHandler,
|
|
7
|
+
FinalizeHandlerArguments,
|
|
8
|
+
FinalizeHandlerOutput,
|
|
9
|
+
HandlerExecutionContext,
|
|
10
|
+
MetadataBearer,
|
|
11
|
+
Provider,
|
|
12
|
+
} from "@aws-sdk/types";
|
|
13
|
+
export interface EventStreamPayloadHandlerOptions {
|
|
14
|
+
eventSigner: Provider<EventSigner>;
|
|
15
|
+
utf8Encoder: Encoder;
|
|
16
|
+
utf8Decoder: Decoder;
|
|
17
|
+
}
|
|
18
|
+
export declare class EventStreamPayloadHandler
|
|
19
|
+
implements IEventStreamPayloadHandler
|
|
20
|
+
{
|
|
21
|
+
private readonly eventSigner;
|
|
22
|
+
private readonly eventStreamCodec;
|
|
23
|
+
constructor(options: EventStreamPayloadHandlerOptions);
|
|
24
|
+
handle<T extends MetadataBearer>(
|
|
25
|
+
next: FinalizeHandler<any, T>,
|
|
26
|
+
args: FinalizeHandlerArguments<any>,
|
|
27
|
+
context?: HandlerExecutionContext
|
|
28
|
+
): Promise<FinalizeHandlerOutput<T>>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SignatureV4 as BaseSignatureV4 } from "@aws-sdk/signature-v4";
|
|
2
|
+
import {
|
|
3
|
+
HttpRequest as IHttpRequest,
|
|
4
|
+
RequestPresigner,
|
|
5
|
+
RequestPresigningArguments,
|
|
6
|
+
RequestSigner,
|
|
7
|
+
RequestSigningArguments,
|
|
8
|
+
} from "@aws-sdk/types";
|
|
9
|
+
export declare class WebsocketSignatureV4
|
|
10
|
+
implements RequestSigner, RequestPresigner
|
|
11
|
+
{
|
|
12
|
+
private readonly signer;
|
|
13
|
+
constructor(options: { signer: BaseSignatureV4 });
|
|
14
|
+
presign(
|
|
15
|
+
originalRequest: IHttpRequest,
|
|
16
|
+
options?: RequestPresigningArguments
|
|
17
|
+
): Promise<IHttpRequest>;
|
|
18
|
+
sign(
|
|
19
|
+
toSign: IHttpRequest,
|
|
20
|
+
options?: RequestSigningArguments
|
|
21
|
+
): Promise<IHttpRequest>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AuthScheme, RequestHandler, RequestSigner } from "@aws-sdk/types";
|
|
2
|
+
export interface WebSocketInputConfig {}
|
|
3
|
+
interface PreviouslyResolved {
|
|
4
|
+
signer: (authScheme: AuthScheme) => Promise<RequestSigner>;
|
|
5
|
+
requestHandler: RequestHandler<any, any>;
|
|
6
|
+
}
|
|
7
|
+
export interface WebSocketResolvedConfig {
|
|
8
|
+
signer: (authScheme: AuthScheme) => Promise<RequestSigner>;
|
|
9
|
+
requestHandler: RequestHandler<any, any>;
|
|
10
|
+
}
|
|
11
|
+
export declare const resolveWebSocketConfig: <T>(
|
|
12
|
+
input: T & WebSocketInputConfig & PreviouslyResolved
|
|
13
|
+
) => T & WebSocketResolvedConfig;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EventStreamCodec } from "@aws-sdk/eventstream-codec";
|
|
2
|
+
import { EventSigner } from "@aws-sdk/types";
|
|
3
|
+
export declare const getEventSigningTransformStream: (
|
|
4
|
+
initialSignature: string,
|
|
5
|
+
eventSigner: EventSigner,
|
|
6
|
+
eventStreamCodec: EventStreamCodec
|
|
7
|
+
) => TransformStream<Uint8Array, Uint8Array>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BuildMiddleware,
|
|
3
|
+
RelativeMiddlewareOptions,
|
|
4
|
+
RequestHandler,
|
|
5
|
+
} from "@aws-sdk/types";
|
|
6
|
+
export declare const websocketEndpointMiddleware: (
|
|
7
|
+
config: {
|
|
8
|
+
requestHandler: RequestHandler<any, any>;
|
|
9
|
+
},
|
|
10
|
+
options: {
|
|
11
|
+
headerPrefix: string;
|
|
12
|
+
}
|
|
13
|
+
) => BuildMiddleware<any, any>;
|
|
14
|
+
export declare const websocketEndpointMiddlewareOptions: RelativeMiddlewareOptions;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Pluggable, RequestHandler } from "@aws-sdk/types";
|
|
2
|
+
interface WebSocketResolvedConfig {
|
|
3
|
+
requestHandler: RequestHandler<any, any>;
|
|
4
|
+
}
|
|
5
|
+
export declare const getWebSocketPlugin: (
|
|
6
|
+
config: WebSocketResolvedConfig,
|
|
7
|
+
options: {
|
|
8
|
+
headerPrefix: string;
|
|
9
|
+
}
|
|
10
|
+
) => Pluggable<any, any>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
|
|
2
|
+
import {
|
|
3
|
+
Provider,
|
|
4
|
+
RequestHandler,
|
|
5
|
+
RequestHandlerMetadata,
|
|
6
|
+
} from "@aws-sdk/types";
|
|
7
|
+
export interface WebSocketFetchHandlerOptions {
|
|
8
|
+
connectionTimeout?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class WebSocketFetchHandler {
|
|
11
|
+
readonly metadata: RequestHandlerMetadata;
|
|
12
|
+
private readonly configPromise;
|
|
13
|
+
private readonly httpHandler;
|
|
14
|
+
private readonly sockets;
|
|
15
|
+
constructor(
|
|
16
|
+
options?:
|
|
17
|
+
| WebSocketFetchHandlerOptions
|
|
18
|
+
| Provider<WebSocketFetchHandlerOptions>,
|
|
19
|
+
httpHandler?: RequestHandler<any, any>
|
|
20
|
+
);
|
|
21
|
+
destroy(): void;
|
|
22
|
+
handle(request: HttpRequest): Promise<{
|
|
23
|
+
response: HttpResponse;
|
|
24
|
+
}>;
|
|
25
|
+
private removeNotUsableSockets;
|
|
26
|
+
private waitForReady;
|
|
27
|
+
private connect;
|
|
28
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
|
|
2
|
+
import { Provider, RequestHandler, RequestHandlerMetadata } from "@aws-sdk/types";
|
|
3
|
+
export interface WebSocketFetchHandlerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The maximum time in milliseconds that the connection phase of a request
|
|
6
|
+
* may take before the connection attempt is abandoned.
|
|
7
|
+
*/
|
|
8
|
+
connectionTimeout?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base handler for websocket requests and HTTP request. By default, the request input and output
|
|
12
|
+
* body will be in a ReadableStream, because of interface consistency among middleware.
|
|
13
|
+
* If ReadableStream is not available, like in React-Native, the response body
|
|
14
|
+
* will be an async iterable.
|
|
15
|
+
*/
|
|
16
|
+
export declare class WebSocketFetchHandler {
|
|
17
|
+
readonly metadata: RequestHandlerMetadata;
|
|
18
|
+
private readonly configPromise;
|
|
19
|
+
private readonly httpHandler;
|
|
20
|
+
private readonly sockets;
|
|
21
|
+
constructor(options?: WebSocketFetchHandlerOptions | Provider<WebSocketFetchHandlerOptions>, httpHandler?: RequestHandler<any, any>);
|
|
22
|
+
/**
|
|
23
|
+
* Destroys the WebSocketHandler.
|
|
24
|
+
* Closes all sockets from the socket pool.
|
|
25
|
+
*/
|
|
26
|
+
destroy(): void;
|
|
27
|
+
handle(request: HttpRequest): Promise<{
|
|
28
|
+
response: HttpResponse;
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Removes all closing/closed sockets from the socket pool for URL.
|
|
32
|
+
*/
|
|
33
|
+
private removeNotUsableSockets;
|
|
34
|
+
private waitForReady;
|
|
35
|
+
private connect;
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aws-sdk/middleware-websocket",
|
|
3
|
+
"version": "3.305.0",
|
|
4
|
+
"main": "./dist-cjs/index.js",
|
|
5
|
+
"module": "./dist-es/index.js",
|
|
6
|
+
"types": "./dist-types/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
9
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
10
|
+
"build:es": "tsc -p tsconfig.es.json",
|
|
11
|
+
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
|
|
12
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
13
|
+
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
14
|
+
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
|
|
15
|
+
"test": "jest"
|
|
16
|
+
},
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "AWS SDK for JavaScript Team",
|
|
19
|
+
"url": "https://aws.amazon.com/javascript/"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@aws-sdk/eventstream-serde-browser": "3.303.0",
|
|
24
|
+
"@aws-sdk/fetch-http-handler": "3.303.0",
|
|
25
|
+
"@aws-sdk/middleware-signing": "3.303.0",
|
|
26
|
+
"@aws-sdk/protocol-http": "3.303.0",
|
|
27
|
+
"@aws-sdk/signature-v4": "3.303.0",
|
|
28
|
+
"@aws-sdk/types": "3.303.0",
|
|
29
|
+
"@aws-sdk/util-format-url": "3.303.0",
|
|
30
|
+
"@aws-sdk/util-hex-encoding": "3.295.0",
|
|
31
|
+
"tslib": "^2.5.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@tsconfig/recommended": "1.0.1",
|
|
35
|
+
"@types/uuid": "^8.3.0",
|
|
36
|
+
"concurrently": "7.0.0",
|
|
37
|
+
"downlevel-dts": "0.7.0",
|
|
38
|
+
"jest-websocket-mock": "^2.0.2",
|
|
39
|
+
"mock-socket": "9.1.5",
|
|
40
|
+
"rimraf": "3.0.2",
|
|
41
|
+
"typedoc": "0.23.23",
|
|
42
|
+
"typescript": "~4.9.5",
|
|
43
|
+
"web-streams-polyfill": "3.2.1"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">= 14.0.0"
|
|
47
|
+
},
|
|
48
|
+
"typesVersions": {
|
|
49
|
+
"<4.0": {
|
|
50
|
+
"dist-types/*": [
|
|
51
|
+
"dist-types/ts3.4/*"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"files": [
|
|
56
|
+
"dist-*"
|
|
57
|
+
],
|
|
58
|
+
"homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/middleware-websocket",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/aws/aws-sdk-js-v3.git",
|
|
62
|
+
"directory": "packages/middleware-websocket"
|
|
63
|
+
},
|
|
64
|
+
"typedoc": {
|
|
65
|
+
"entryPoint": "src/index.ts"
|
|
66
|
+
}
|
|
67
|
+
}
|