@aws-sdk/middleware-sdk-transcribe-streaming 3.299.0 → 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/dist-cjs/index.js +2 -5
- package/dist-cjs/{middleware-session-id.js → middleware-inject-response-values.js} +6 -6
- package/dist-cjs/middleware-port.js +21 -0
- package/dist-cjs/plugin.js +7 -7
- package/dist-es/index.js +2 -5
- package/dist-es/{middleware-session-id.js → middleware-inject-response-values.js} +4 -4
- package/dist-es/middleware-port.js +16 -0
- package/dist-es/plugin.js +5 -5
- package/dist-types/index.d.ts +2 -5
- package/dist-types/{middleware-session-id.d.ts → middleware-inject-response-values.d.ts} +2 -2
- package/dist-types/{middleware-endpoint.d.ts → middleware-port.d.ts} +2 -2
- package/dist-types/plugin.d.ts +6 -3
- package/dist-types/ts3.4/index.d.ts +2 -5
- package/dist-types/ts3.4/{middleware-session-id.d.ts → middleware-inject-response-values.d.ts} +2 -2
- package/dist-types/ts3.4/{middleware-endpoint.d.ts → middleware-port.d.ts} +2 -2
- package/dist-types/ts3.4/plugin.d.ts +7 -4
- package/package.json +6 -6
- package/dist-cjs/configuration.js +0 -21
- package/dist-cjs/middleware-endpoint.js +0 -36
- package/dist-cjs/signer.js +0 -28
- package/dist-cjs/websocket-handler.js +0 -130
- package/dist-es/configuration.js +0 -14
- package/dist-es/middleware-endpoint.js +0 -31
- package/dist-es/signer.js +0 -24
- package/dist-es/websocket-handler.js +0 -126
- package/dist-types/configuration.d.ts +0 -19
- package/dist-types/signer.d.ts +0 -10
- package/dist-types/ts3.4/configuration.d.ts +0 -14
- package/dist-types/ts3.4/signer.d.ts +0 -20
- package/dist-types/ts3.4/websocket-handler.d.ts +0 -18
- package/dist-types/websocket-handler.d.ts +0 -35
package/dist-cjs/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./configuration"), exports);
|
|
5
4
|
tslib_1.__exportStar(require("./eventstream-handler"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./middleware-
|
|
7
|
-
tslib_1.__exportStar(require("./middleware-
|
|
5
|
+
tslib_1.__exportStar(require("./middleware-inject-response-values"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./middleware-port"), exports);
|
|
8
7
|
tslib_1.__exportStar(require("./plugin"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./signer"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./websocket-handler"), exports);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.injectResponseValuesMiddlewareOptions = exports.injectResponseValuesMiddleware = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
|
-
const
|
|
5
|
+
const injectResponseValuesMiddleware = (config) => (next) => async (args) => {
|
|
6
6
|
if (args.input.SessionId === undefined && isWebSocket(config)) {
|
|
7
7
|
args.input.SessionId = (0, uuid_1.v4)();
|
|
8
8
|
}
|
|
@@ -18,11 +18,11 @@ const injectSessionIdMiddleware = (config) => (next) => async (args) => {
|
|
|
18
18
|
}
|
|
19
19
|
return response;
|
|
20
20
|
};
|
|
21
|
-
exports.
|
|
22
|
-
const isWebSocket = (config) => { var _a; return ((_a = config.requestHandler.metadata) === null || _a === void 0 ? void 0 : _a.handlerProtocol) === "websocket"; };
|
|
23
|
-
exports.
|
|
21
|
+
exports.injectResponseValuesMiddleware = injectResponseValuesMiddleware;
|
|
22
|
+
const isWebSocket = (config) => { var _a, _b; return (_b = (_a = config.requestHandler.metadata) === null || _a === void 0 ? void 0 : _a.handlerProtocol) === null || _b === void 0 ? void 0 : _b.includes("websocket"); };
|
|
23
|
+
exports.injectResponseValuesMiddlewareOptions = {
|
|
24
24
|
step: "initialize",
|
|
25
|
-
name: "
|
|
25
|
+
name: "injectResponseValuesMiddleware",
|
|
26
26
|
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
27
27
|
override: true,
|
|
28
28
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.websocketPortMiddlewareOptions = exports.websocketPortMiddleware = void 0;
|
|
4
|
+
const protocol_http_1 = require("@aws-sdk/protocol-http");
|
|
5
|
+
const websocketPortMiddleware = (options) => (next) => (args) => {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const { request } = args;
|
|
8
|
+
if (protocol_http_1.HttpRequest.isInstance(request) && ((_b = (_a = options.requestHandler.metadata) === null || _a === void 0 ? void 0 : _a.handlerProtocol) === null || _b === void 0 ? void 0 : _b.includes("websocket"))) {
|
|
9
|
+
request.hostname = `${request.hostname}:8443`;
|
|
10
|
+
request.headers.host = request.hostname;
|
|
11
|
+
}
|
|
12
|
+
return next(args);
|
|
13
|
+
};
|
|
14
|
+
exports.websocketPortMiddleware = websocketPortMiddleware;
|
|
15
|
+
exports.websocketPortMiddlewareOptions = {
|
|
16
|
+
name: "websocketPortMiddleware",
|
|
17
|
+
tags: ["WEBSOCKET", "EVENT_STREAM", "PORT"],
|
|
18
|
+
relation: "after",
|
|
19
|
+
toMiddleware: "eventStreamHeaderMiddleware",
|
|
20
|
+
override: true,
|
|
21
|
+
};
|
package/dist-cjs/plugin.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
3
|
+
exports.getTranscribeStreamingPlugin = void 0;
|
|
4
|
+
const middleware_inject_response_values_1 = require("./middleware-inject-response-values");
|
|
5
|
+
const middleware_port_1 = require("./middleware-port");
|
|
6
|
+
const getTranscribeStreamingPlugin = (config) => ({
|
|
7
7
|
applyToStack: (clientStack) => {
|
|
8
|
-
clientStack.addRelativeTo((0,
|
|
9
|
-
clientStack.add((0,
|
|
8
|
+
clientStack.addRelativeTo((0, middleware_port_1.websocketPortMiddleware)(config), middleware_port_1.websocketPortMiddlewareOptions);
|
|
9
|
+
clientStack.add((0, middleware_inject_response_values_1.injectResponseValuesMiddleware)(config), middleware_inject_response_values_1.injectResponseValuesMiddlewareOptions);
|
|
10
10
|
},
|
|
11
11
|
});
|
|
12
|
-
exports.
|
|
12
|
+
exports.getTranscribeStreamingPlugin = getTranscribeStreamingPlugin;
|
package/dist-es/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "./configuration";
|
|
2
1
|
export * from "./eventstream-handler";
|
|
3
|
-
export * from "./middleware-
|
|
4
|
-
export * from "./middleware-
|
|
2
|
+
export * from "./middleware-inject-response-values";
|
|
3
|
+
export * from "./middleware-port";
|
|
5
4
|
export * from "./plugin";
|
|
6
|
-
export * from "./signer";
|
|
7
|
-
export * from "./websocket-handler";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { v4 } from "uuid";
|
|
2
|
-
export const
|
|
2
|
+
export const injectResponseValuesMiddleware = (config) => (next) => async (args) => {
|
|
3
3
|
if (args.input.SessionId === undefined && isWebSocket(config)) {
|
|
4
4
|
args.input.SessionId = v4();
|
|
5
5
|
}
|
|
@@ -15,10 +15,10 @@ export const injectSessionIdMiddleware = (config) => (next) => async (args) => {
|
|
|
15
15
|
}
|
|
16
16
|
return response;
|
|
17
17
|
};
|
|
18
|
-
const isWebSocket = (config) => config.requestHandler.metadata?.handlerProtocol
|
|
19
|
-
export const
|
|
18
|
+
const isWebSocket = (config) => config.requestHandler.metadata?.handlerProtocol?.includes("websocket");
|
|
19
|
+
export const injectResponseValuesMiddlewareOptions = {
|
|
20
20
|
step: "initialize",
|
|
21
|
-
name: "
|
|
21
|
+
name: "injectResponseValuesMiddleware",
|
|
22
22
|
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
23
23
|
override: true,
|
|
24
24
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HttpRequest } from "@aws-sdk/protocol-http";
|
|
2
|
+
export const websocketPortMiddleware = (options) => (next) => (args) => {
|
|
3
|
+
const { request } = args;
|
|
4
|
+
if (HttpRequest.isInstance(request) && options.requestHandler.metadata?.handlerProtocol?.includes("websocket")) {
|
|
5
|
+
request.hostname = `${request.hostname}:8443`;
|
|
6
|
+
request.headers.host = request.hostname;
|
|
7
|
+
}
|
|
8
|
+
return next(args);
|
|
9
|
+
};
|
|
10
|
+
export const websocketPortMiddlewareOptions = {
|
|
11
|
+
name: "websocketPortMiddleware",
|
|
12
|
+
tags: ["WEBSOCKET", "EVENT_STREAM", "PORT"],
|
|
13
|
+
relation: "after",
|
|
14
|
+
toMiddleware: "eventStreamHeaderMiddleware",
|
|
15
|
+
override: true,
|
|
16
|
+
};
|
package/dist-es/plugin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export const
|
|
1
|
+
import { injectResponseValuesMiddleware, injectResponseValuesMiddlewareOptions, } from "./middleware-inject-response-values";
|
|
2
|
+
import { websocketPortMiddleware, websocketPortMiddlewareOptions } from "./middleware-port";
|
|
3
|
+
export const getTranscribeStreamingPlugin = (config) => ({
|
|
4
4
|
applyToStack: (clientStack) => {
|
|
5
|
-
clientStack.addRelativeTo(
|
|
6
|
-
clientStack.add(
|
|
5
|
+
clientStack.addRelativeTo(websocketPortMiddleware(config), websocketPortMiddlewareOptions);
|
|
6
|
+
clientStack.add(injectResponseValuesMiddleware(config), injectResponseValuesMiddlewareOptions);
|
|
7
7
|
},
|
|
8
8
|
});
|
package/dist-types/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "./configuration";
|
|
2
1
|
export * from "./eventstream-handler";
|
|
3
|
-
export * from "./middleware-
|
|
4
|
-
export * from "./middleware-
|
|
2
|
+
export * from "./middleware-inject-response-values";
|
|
3
|
+
export * from "./middleware-port";
|
|
5
4
|
export * from "./plugin";
|
|
6
|
-
export * from "./signer";
|
|
7
|
-
export * from "./websocket-handler";
|
|
@@ -6,7 +6,7 @@ import { InitializeHandlerOptions, InitializeMiddleware, RequestHandler } from "
|
|
|
6
6
|
* the result stream. So it copies the parameters from input to the same
|
|
7
7
|
* parameters in the output.
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const injectResponseValuesMiddleware: (config: {
|
|
10
10
|
requestHandler: RequestHandler<any, any>;
|
|
11
11
|
}) => InitializeMiddleware<any, any>;
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const injectResponseValuesMiddlewareOptions: InitializeHandlerOptions;
|
|
@@ -3,7 +3,7 @@ import { BuildMiddleware, RelativeMiddlewareOptions, RequestHandler } from "@aws
|
|
|
3
3
|
* Middleware that generates WebSocket URL to TranscribeStreaming service
|
|
4
4
|
* Reference: https://docs.aws.amazon.com/transcribe/latest/dg/websocket.html
|
|
5
5
|
*/
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const websocketPortMiddleware: (options: {
|
|
7
7
|
requestHandler: RequestHandler<any, any>;
|
|
8
8
|
}) => BuildMiddleware<any, any>;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const websocketPortMiddlewareOptions: RelativeMiddlewareOptions;
|
package/dist-types/plugin.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { Pluggable } from "@aws-sdk/types";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Pluggable, RequestHandler } from "@aws-sdk/types";
|
|
2
|
+
interface PreviouslyResolved {
|
|
3
|
+
requestHandler: RequestHandler<any, any>;
|
|
4
|
+
}
|
|
5
|
+
export declare const getTranscribeStreamingPlugin: (config: PreviouslyResolved) => Pluggable<any, any>;
|
|
6
|
+
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "./configuration";
|
|
2
1
|
export * from "./eventstream-handler";
|
|
3
|
-
export * from "./middleware-
|
|
4
|
-
export * from "./middleware-
|
|
2
|
+
export * from "./middleware-inject-response-values";
|
|
3
|
+
export * from "./middleware-port";
|
|
5
4
|
export * from "./plugin";
|
|
6
|
-
export * from "./signer";
|
|
7
|
-
export * from "./websocket-handler";
|
package/dist-types/ts3.4/{middleware-session-id.d.ts → middleware-inject-response-values.d.ts}
RENAMED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
InitializeMiddleware,
|
|
4
4
|
RequestHandler,
|
|
5
5
|
} from "@aws-sdk/types";
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const injectResponseValuesMiddleware: (config: {
|
|
7
7
|
requestHandler: RequestHandler<any, any>;
|
|
8
8
|
}) => InitializeMiddleware<any, any>;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const injectResponseValuesMiddlewareOptions: InitializeHandlerOptions;
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
RelativeMiddlewareOptions,
|
|
4
4
|
RequestHandler,
|
|
5
5
|
} from "@aws-sdk/types";
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const websocketPortMiddleware: (options: {
|
|
7
7
|
requestHandler: RequestHandler<any, any>;
|
|
8
8
|
}) => BuildMiddleware<any, any>;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const websocketPortMiddlewareOptions: RelativeMiddlewareOptions;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { Pluggable } from "@aws-sdk/types";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Pluggable, RequestHandler } from "@aws-sdk/types";
|
|
2
|
+
interface PreviouslyResolved {
|
|
3
|
+
requestHandler: RequestHandler<any, any>;
|
|
4
|
+
}
|
|
5
|
+
export declare const getTranscribeStreamingPlugin: (
|
|
6
|
+
config: PreviouslyResolved
|
|
5
7
|
) => Pluggable<any, any>;
|
|
8
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-sdk-transcribe-streaming",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.305.0",
|
|
4
4
|
"main": "./dist-cjs/index.js",
|
|
5
5
|
"module": "./dist-es/index.js",
|
|
6
6
|
"types": "./dist-types/index.d.ts",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@aws-sdk/eventstream-serde-browser": "3.
|
|
24
|
-
"@aws-sdk/protocol-http": "3.
|
|
25
|
-
"@aws-sdk/signature-v4": "3.
|
|
26
|
-
"@aws-sdk/types": "3.
|
|
27
|
-
"@aws-sdk/util-format-url": "3.
|
|
23
|
+
"@aws-sdk/eventstream-serde-browser": "3.303.0",
|
|
24
|
+
"@aws-sdk/protocol-http": "3.303.0",
|
|
25
|
+
"@aws-sdk/signature-v4": "3.303.0",
|
|
26
|
+
"@aws-sdk/types": "3.303.0",
|
|
27
|
+
"@aws-sdk/util-format-url": "3.303.0",
|
|
28
28
|
"tslib": "^2.5.0",
|
|
29
29
|
"uuid": "^8.3.2"
|
|
30
30
|
},
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveWebSocketConfig = void 0;
|
|
4
|
-
const signer_1 = require("./signer");
|
|
5
|
-
const resolveWebSocketConfig = (input) => {
|
|
6
|
-
var _a;
|
|
7
|
-
return ((_a = input.requestHandler.metadata) === null || _a === void 0 ? void 0 : _a.handlerProtocol) !== "websocket"
|
|
8
|
-
? input
|
|
9
|
-
: {
|
|
10
|
-
...input,
|
|
11
|
-
signer: async (authScheme) => {
|
|
12
|
-
const signerObj = await input.signer(authScheme);
|
|
13
|
-
if (validateSigner(signerObj)) {
|
|
14
|
-
return new signer_1.SignatureV4({ signer: signerObj });
|
|
15
|
-
}
|
|
16
|
-
throw new Error("Expected SignatureV4 signer, please check the client constructor.");
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
exports.resolveWebSocketConfig = resolveWebSocketConfig;
|
|
21
|
-
const validateSigner = (signer) => !!signer;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.websocketURLMiddlewareOptions = exports.websocketURLMiddleware = void 0;
|
|
4
|
-
const protocol_http_1 = require("@aws-sdk/protocol-http");
|
|
5
|
-
const websocketURLMiddleware = (options) => (next) => (args) => {
|
|
6
|
-
var _a;
|
|
7
|
-
const { request } = args;
|
|
8
|
-
if (protocol_http_1.HttpRequest.isInstance(request) && ((_a = options.requestHandler.metadata) === null || _a === void 0 ? void 0 : _a.handlerProtocol) === "websocket") {
|
|
9
|
-
request.protocol = "wss:";
|
|
10
|
-
request.hostname = `${request.hostname}:8443`;
|
|
11
|
-
request.path = `${request.path}-websocket`;
|
|
12
|
-
request.method = "GET";
|
|
13
|
-
const { headers } = request;
|
|
14
|
-
delete headers["Content-Type"];
|
|
15
|
-
delete headers["x-amz-content-sha256"];
|
|
16
|
-
for (const name of Object.keys(headers)) {
|
|
17
|
-
if (name.indexOf("x-amzn-transcribe-") === 0) {
|
|
18
|
-
const chunkedName = name.replace("x-amzn-transcribe-", "");
|
|
19
|
-
request.query[chunkedName] = headers[name];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (headers["x-amz-user-agent"]) {
|
|
23
|
-
request.query["user-agent"] = headers["x-amz-user-agent"];
|
|
24
|
-
}
|
|
25
|
-
request.headers = { host: request.hostname };
|
|
26
|
-
}
|
|
27
|
-
return next(args);
|
|
28
|
-
};
|
|
29
|
-
exports.websocketURLMiddleware = websocketURLMiddleware;
|
|
30
|
-
exports.websocketURLMiddlewareOptions = {
|
|
31
|
-
name: "websocketURLMiddleware",
|
|
32
|
-
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
33
|
-
relation: "after",
|
|
34
|
-
toMiddleware: "eventStreamHeaderMiddleware",
|
|
35
|
-
override: true,
|
|
36
|
-
};
|
package/dist-cjs/signer.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SignatureV4 = void 0;
|
|
4
|
-
const protocol_http_1 = require("@aws-sdk/protocol-http");
|
|
5
|
-
class SignatureV4 {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
this.signer = options.signer;
|
|
8
|
-
}
|
|
9
|
-
presign(originalRequest, options = {}) {
|
|
10
|
-
return this.signer.presign(originalRequest, options);
|
|
11
|
-
}
|
|
12
|
-
async sign(toSign, options) {
|
|
13
|
-
if (protocol_http_1.HttpRequest.isInstance(toSign)) {
|
|
14
|
-
const signedRequest = await this.signer.presign({ ...toSign, body: "" }, {
|
|
15
|
-
expiresIn: 5 * 60,
|
|
16
|
-
unsignableHeaders: new Set(Object.keys(toSign.headers).filter((header) => header !== "host")),
|
|
17
|
-
});
|
|
18
|
-
return {
|
|
19
|
-
...signedRequest,
|
|
20
|
-
body: toSign.body,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
return this.signer.sign(toSign, options);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.SignatureV4 = SignatureV4;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebSocketHandler = void 0;
|
|
4
|
-
const eventstream_serde_browser_1 = require("@aws-sdk/eventstream-serde-browser");
|
|
5
|
-
const protocol_http_1 = require("@aws-sdk/protocol-http");
|
|
6
|
-
const util_format_url_1 = require("@aws-sdk/util-format-url");
|
|
7
|
-
class WebSocketHandler {
|
|
8
|
-
constructor({ connectionTimeout } = {}) {
|
|
9
|
-
this.metadata = {
|
|
10
|
-
handlerProtocol: "websocket",
|
|
11
|
-
};
|
|
12
|
-
this.sockets = {};
|
|
13
|
-
this.connectionTimeout = connectionTimeout || 2000;
|
|
14
|
-
}
|
|
15
|
-
destroy() {
|
|
16
|
-
for (const [key, sockets] of Object.entries(this.sockets)) {
|
|
17
|
-
for (const socket of sockets) {
|
|
18
|
-
socket.close(1000, `Socket closed through destroy() call`);
|
|
19
|
-
}
|
|
20
|
-
delete this.sockets[key];
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
removeNotUsableSockets(url) {
|
|
24
|
-
this.sockets[url] = this.sockets[url].filter((socket) => ![WebSocket.CLOSING, WebSocket.CLOSED].includes(socket.readyState));
|
|
25
|
-
}
|
|
26
|
-
async handle(request) {
|
|
27
|
-
const url = (0, util_format_url_1.formatUrl)(request);
|
|
28
|
-
const socket = new WebSocket(url);
|
|
29
|
-
if (!this.sockets[url]) {
|
|
30
|
-
this.sockets[url] = [];
|
|
31
|
-
}
|
|
32
|
-
this.sockets[url].push(socket);
|
|
33
|
-
socket.binaryType = "arraybuffer";
|
|
34
|
-
await this.waitForReady(socket, this.connectionTimeout);
|
|
35
|
-
const { body } = request;
|
|
36
|
-
const bodyStream = getIterator(body);
|
|
37
|
-
const asyncIterable = this.connect(socket, bodyStream);
|
|
38
|
-
const outputPayload = toReadableStream(asyncIterable);
|
|
39
|
-
return {
|
|
40
|
-
response: new protocol_http_1.HttpResponse({
|
|
41
|
-
statusCode: 200,
|
|
42
|
-
body: outputPayload,
|
|
43
|
-
}),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
waitForReady(socket, connectionTimeout) {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
const timeout = setTimeout(() => {
|
|
49
|
-
this.removeNotUsableSockets(socket.url);
|
|
50
|
-
reject({
|
|
51
|
-
$metadata: {
|
|
52
|
-
httpStatusCode: 500,
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
}, connectionTimeout);
|
|
56
|
-
socket.onopen = () => {
|
|
57
|
-
clearTimeout(timeout);
|
|
58
|
-
resolve();
|
|
59
|
-
};
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
connect(socket, data) {
|
|
63
|
-
let streamError = undefined;
|
|
64
|
-
const outputStream = {
|
|
65
|
-
[Symbol.asyncIterator]: () => ({
|
|
66
|
-
next: () => {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
let socketErrorOccurred = false;
|
|
69
|
-
socket.onerror = (error) => {
|
|
70
|
-
socketErrorOccurred = true;
|
|
71
|
-
socket.close();
|
|
72
|
-
reject(error);
|
|
73
|
-
};
|
|
74
|
-
socket.onclose = () => {
|
|
75
|
-
this.removeNotUsableSockets(socket.url);
|
|
76
|
-
if (socketErrorOccurred)
|
|
77
|
-
return;
|
|
78
|
-
if (streamError) {
|
|
79
|
-
reject(streamError);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
resolve({
|
|
83
|
-
done: true,
|
|
84
|
-
value: undefined,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
socket.onmessage = (event) => {
|
|
89
|
-
resolve({
|
|
90
|
-
done: false,
|
|
91
|
-
value: new Uint8Array(event.data),
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
}),
|
|
97
|
-
};
|
|
98
|
-
const send = async () => {
|
|
99
|
-
try {
|
|
100
|
-
for await (const inputChunk of data) {
|
|
101
|
-
socket.send(inputChunk);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
streamError = err;
|
|
106
|
-
}
|
|
107
|
-
finally {
|
|
108
|
-
socket.close(1000);
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
send();
|
|
112
|
-
return outputStream;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.WebSocketHandler = WebSocketHandler;
|
|
116
|
-
const getIterator = (stream) => {
|
|
117
|
-
if (stream[Symbol.asyncIterator]) {
|
|
118
|
-
return stream;
|
|
119
|
-
}
|
|
120
|
-
if (isReadableStream(stream)) {
|
|
121
|
-
return (0, eventstream_serde_browser_1.readableStreamtoIterable)(stream);
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
[Symbol.asyncIterator]: async function* () {
|
|
125
|
-
yield stream;
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
const toReadableStream = (asyncIterable) => typeof ReadableStream === "function" ? (0, eventstream_serde_browser_1.iterableToReadableStream)(asyncIterable) : asyncIterable;
|
|
130
|
-
const isReadableStream = (payload) => typeof ReadableStream === "function" && payload instanceof ReadableStream;
|
package/dist-es/configuration.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SignatureV4 } from "./signer";
|
|
2
|
-
export const resolveWebSocketConfig = (input) => input.requestHandler.metadata?.handlerProtocol !== "websocket"
|
|
3
|
-
? input
|
|
4
|
-
: {
|
|
5
|
-
...input,
|
|
6
|
-
signer: async (authScheme) => {
|
|
7
|
-
const signerObj = await input.signer(authScheme);
|
|
8
|
-
if (validateSigner(signerObj)) {
|
|
9
|
-
return new SignatureV4({ signer: signerObj });
|
|
10
|
-
}
|
|
11
|
-
throw new Error("Expected SignatureV4 signer, please check the client constructor.");
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
const validateSigner = (signer) => !!signer;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { HttpRequest } from "@aws-sdk/protocol-http";
|
|
2
|
-
export const websocketURLMiddleware = (options) => (next) => (args) => {
|
|
3
|
-
const { request } = args;
|
|
4
|
-
if (HttpRequest.isInstance(request) && options.requestHandler.metadata?.handlerProtocol === "websocket") {
|
|
5
|
-
request.protocol = "wss:";
|
|
6
|
-
request.hostname = `${request.hostname}:8443`;
|
|
7
|
-
request.path = `${request.path}-websocket`;
|
|
8
|
-
request.method = "GET";
|
|
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("x-amzn-transcribe-") === 0) {
|
|
14
|
-
const chunkedName = name.replace("x-amzn-transcribe-", "");
|
|
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: request.hostname };
|
|
22
|
-
}
|
|
23
|
-
return next(args);
|
|
24
|
-
};
|
|
25
|
-
export const websocketURLMiddlewareOptions = {
|
|
26
|
-
name: "websocketURLMiddleware",
|
|
27
|
-
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
|
28
|
-
relation: "after",
|
|
29
|
-
toMiddleware: "eventStreamHeaderMiddleware",
|
|
30
|
-
override: true,
|
|
31
|
-
};
|
package/dist-es/signer.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { HttpRequest } from "@aws-sdk/protocol-http";
|
|
2
|
-
export class SignatureV4 {
|
|
3
|
-
constructor(options) {
|
|
4
|
-
this.signer = options.signer;
|
|
5
|
-
}
|
|
6
|
-
presign(originalRequest, options = {}) {
|
|
7
|
-
return this.signer.presign(originalRequest, options);
|
|
8
|
-
}
|
|
9
|
-
async sign(toSign, options) {
|
|
10
|
-
if (HttpRequest.isInstance(toSign)) {
|
|
11
|
-
const signedRequest = await this.signer.presign({ ...toSign, body: "" }, {
|
|
12
|
-
expiresIn: 5 * 60,
|
|
13
|
-
unsignableHeaders: new Set(Object.keys(toSign.headers).filter((header) => header !== "host")),
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
...signedRequest,
|
|
17
|
-
body: toSign.body,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
return this.signer.sign(toSign, options);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { iterableToReadableStream, readableStreamtoIterable } from "@aws-sdk/eventstream-serde-browser";
|
|
2
|
-
import { HttpResponse } from "@aws-sdk/protocol-http";
|
|
3
|
-
import { formatUrl } from "@aws-sdk/util-format-url";
|
|
4
|
-
export class WebSocketHandler {
|
|
5
|
-
constructor({ connectionTimeout } = {}) {
|
|
6
|
-
this.metadata = {
|
|
7
|
-
handlerProtocol: "websocket",
|
|
8
|
-
};
|
|
9
|
-
this.sockets = {};
|
|
10
|
-
this.connectionTimeout = connectionTimeout || 2000;
|
|
11
|
-
}
|
|
12
|
-
destroy() {
|
|
13
|
-
for (const [key, sockets] of Object.entries(this.sockets)) {
|
|
14
|
-
for (const socket of sockets) {
|
|
15
|
-
socket.close(1000, `Socket closed through destroy() call`);
|
|
16
|
-
}
|
|
17
|
-
delete this.sockets[key];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
removeNotUsableSockets(url) {
|
|
21
|
-
this.sockets[url] = this.sockets[url].filter((socket) => ![WebSocket.CLOSING, WebSocket.CLOSED].includes(socket.readyState));
|
|
22
|
-
}
|
|
23
|
-
async handle(request) {
|
|
24
|
-
const url = formatUrl(request);
|
|
25
|
-
const socket = new WebSocket(url);
|
|
26
|
-
if (!this.sockets[url]) {
|
|
27
|
-
this.sockets[url] = [];
|
|
28
|
-
}
|
|
29
|
-
this.sockets[url].push(socket);
|
|
30
|
-
socket.binaryType = "arraybuffer";
|
|
31
|
-
await this.waitForReady(socket, this.connectionTimeout);
|
|
32
|
-
const { body } = request;
|
|
33
|
-
const bodyStream = getIterator(body);
|
|
34
|
-
const asyncIterable = this.connect(socket, bodyStream);
|
|
35
|
-
const outputPayload = toReadableStream(asyncIterable);
|
|
36
|
-
return {
|
|
37
|
-
response: new HttpResponse({
|
|
38
|
-
statusCode: 200,
|
|
39
|
-
body: outputPayload,
|
|
40
|
-
}),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
waitForReady(socket, connectionTimeout) {
|
|
44
|
-
return new Promise((resolve, reject) => {
|
|
45
|
-
const timeout = setTimeout(() => {
|
|
46
|
-
this.removeNotUsableSockets(socket.url);
|
|
47
|
-
reject({
|
|
48
|
-
$metadata: {
|
|
49
|
-
httpStatusCode: 500,
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
}, connectionTimeout);
|
|
53
|
-
socket.onopen = () => {
|
|
54
|
-
clearTimeout(timeout);
|
|
55
|
-
resolve();
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
connect(socket, data) {
|
|
60
|
-
let streamError = undefined;
|
|
61
|
-
const outputStream = {
|
|
62
|
-
[Symbol.asyncIterator]: () => ({
|
|
63
|
-
next: () => {
|
|
64
|
-
return new Promise((resolve, reject) => {
|
|
65
|
-
let socketErrorOccurred = false;
|
|
66
|
-
socket.onerror = (error) => {
|
|
67
|
-
socketErrorOccurred = true;
|
|
68
|
-
socket.close();
|
|
69
|
-
reject(error);
|
|
70
|
-
};
|
|
71
|
-
socket.onclose = () => {
|
|
72
|
-
this.removeNotUsableSockets(socket.url);
|
|
73
|
-
if (socketErrorOccurred)
|
|
74
|
-
return;
|
|
75
|
-
if (streamError) {
|
|
76
|
-
reject(streamError);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
resolve({
|
|
80
|
-
done: true,
|
|
81
|
-
value: undefined,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
socket.onmessage = (event) => {
|
|
86
|
-
resolve({
|
|
87
|
-
done: false,
|
|
88
|
-
value: new Uint8Array(event.data),
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
},
|
|
93
|
-
}),
|
|
94
|
-
};
|
|
95
|
-
const send = async () => {
|
|
96
|
-
try {
|
|
97
|
-
for await (const inputChunk of data) {
|
|
98
|
-
socket.send(inputChunk);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
streamError = err;
|
|
103
|
-
}
|
|
104
|
-
finally {
|
|
105
|
-
socket.close(1000);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
send();
|
|
109
|
-
return outputStream;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const getIterator = (stream) => {
|
|
113
|
-
if (stream[Symbol.asyncIterator]) {
|
|
114
|
-
return stream;
|
|
115
|
-
}
|
|
116
|
-
if (isReadableStream(stream)) {
|
|
117
|
-
return readableStreamtoIterable(stream);
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
[Symbol.asyncIterator]: async function* () {
|
|
121
|
-
yield stream;
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
const toReadableStream = (asyncIterable) => typeof ReadableStream === "function" ? iterableToReadableStream(asyncIterable) : asyncIterable;
|
|
126
|
-
const isReadableStream = (payload) => typeof ReadableStream === "function" && payload instanceof ReadableStream;
|
|
@@ -1,19 +0,0 @@
|
|
|
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 {};
|
package/dist-types/signer.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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 SignatureV4 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
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,20 +0,0 @@
|
|
|
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 SignatureV4 implements RequestSigner, RequestPresigner {
|
|
10
|
-
private readonly signer;
|
|
11
|
-
constructor(options: { signer: BaseSignatureV4 });
|
|
12
|
-
presign(
|
|
13
|
-
originalRequest: IHttpRequest,
|
|
14
|
-
options?: RequestPresigningArguments
|
|
15
|
-
): Promise<IHttpRequest>;
|
|
16
|
-
sign(
|
|
17
|
-
toSign: IHttpRequest,
|
|
18
|
-
options?: RequestSigningArguments
|
|
19
|
-
): Promise<IHttpRequest>;
|
|
20
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
|
|
2
|
-
import { RequestHandlerMetadata } from "@aws-sdk/types";
|
|
3
|
-
export interface WebSocketHandlerOptions {
|
|
4
|
-
connectionTimeout?: number;
|
|
5
|
-
}
|
|
6
|
-
export declare class WebSocketHandler implements HttpHandler {
|
|
7
|
-
readonly metadata: RequestHandlerMetadata;
|
|
8
|
-
private readonly connectionTimeout;
|
|
9
|
-
private readonly sockets;
|
|
10
|
-
constructor({ connectionTimeout }?: WebSocketHandlerOptions);
|
|
11
|
-
destroy(): void;
|
|
12
|
-
private removeNotUsableSockets;
|
|
13
|
-
handle(request: HttpRequest): Promise<{
|
|
14
|
-
response: HttpResponse;
|
|
15
|
-
}>;
|
|
16
|
-
private waitForReady;
|
|
17
|
-
private connect;
|
|
18
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
|
|
2
|
-
import { RequestHandlerMetadata } from "@aws-sdk/types";
|
|
3
|
-
export interface WebSocketHandlerOptions {
|
|
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. 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 WebSocketHandler implements HttpHandler {
|
|
17
|
-
readonly metadata: RequestHandlerMetadata;
|
|
18
|
-
private readonly connectionTimeout;
|
|
19
|
-
private readonly sockets;
|
|
20
|
-
constructor({ connectionTimeout }?: WebSocketHandlerOptions);
|
|
21
|
-
/**
|
|
22
|
-
* Destroys the WebSocketHandler.
|
|
23
|
-
* Closes all sockets from the socket pool.
|
|
24
|
-
*/
|
|
25
|
-
destroy(): void;
|
|
26
|
-
/**
|
|
27
|
-
* Removes all closing/closed sockets from the socket pool for URL.
|
|
28
|
-
*/
|
|
29
|
-
private removeNotUsableSockets;
|
|
30
|
-
handle(request: HttpRequest): Promise<{
|
|
31
|
-
response: HttpResponse;
|
|
32
|
-
}>;
|
|
33
|
-
private waitForReady;
|
|
34
|
-
private connect;
|
|
35
|
-
}
|