@songtonyli/dsh-cli 0.1.86 → 0.1.88

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 (97) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/LICENSE +201 -0
  4. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/README.md +9 -0
  5. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-cjs/index.js +859 -0
  6. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/build-abort-error.js +19 -0
  7. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/constants.js +1 -0
  8. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js +12 -0
  9. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/http2/ClientHttp2SessionRef.js +51 -0
  10. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/index.js +3 -0
  11. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +251 -0
  12. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +135 -0
  13. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js +46 -0
  14. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +180 -0
  15. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/node-http2.js +2 -0
  16. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/node-https.js +2 -0
  17. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/set-connection-timeout.js +36 -0
  18. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/set-request-timeout.js +21 -0
  19. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/set-socket-keep-alive.js +22 -0
  20. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +23 -0
  21. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/timing.js +4 -0
  22. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/dist-es/write-request-body.js +63 -0
  23. package/node_modules/@aws-sdk/client-bedrock-runtime/node_modules/@smithy/node-http-handler/package.json +56 -0
  24. package/node_modules/@aws-sdk/core/package.json +2 -2
  25. package/node_modules/@aws-sdk/credential-provider-env/package.json +3 -3
  26. package/node_modules/@aws-sdk/credential-provider-http/package.json +4 -4
  27. package/node_modules/@aws-sdk/credential-provider-ini/package.json +10 -10
  28. package/node_modules/@aws-sdk/credential-provider-login/package.json +4 -4
  29. package/node_modules/@aws-sdk/credential-provider-node/package.json +8 -8
  30. package/node_modules/@aws-sdk/credential-provider-process/package.json +3 -3
  31. package/node_modules/@aws-sdk/credential-provider-sso/package.json +5 -5
  32. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +4 -4
  33. package/node_modules/@aws-sdk/eventstream-handler-node/package.json +2 -2
  34. package/node_modules/@aws-sdk/middleware-eventstream/package.json +2 -2
  35. package/node_modules/@aws-sdk/middleware-websocket/package.json +3 -3
  36. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  37. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  38. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  39. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  40. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  41. package/node_modules/@aws-sdk/nested-clients/package.json +4 -4
  42. package/node_modules/@aws-sdk/token-providers/package.json +4 -4
  43. package/node_modules/@deepseek-ai/dsh-client-modules/lib/index.js +1 -1
  44. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  45. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +6 -6
  46. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +3 -2
  47. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +3 -2
  48. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +256 -32
  49. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/LICENSE +201 -0
  50. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/README.md +9 -0
  51. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-cjs/index.js +859 -0
  52. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/build-abort-error.js +19 -0
  53. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/constants.js +1 -0
  54. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js +12 -0
  55. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/http2/ClientHttp2SessionRef.js +51 -0
  56. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/index.js +3 -0
  57. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +251 -0
  58. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +135 -0
  59. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js +46 -0
  60. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +180 -0
  61. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-http2.js +2 -0
  62. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/node-https.js +2 -0
  63. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-connection-timeout.js +36 -0
  64. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-request-timeout.js +21 -0
  65. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-socket-keep-alive.js +22 -0
  66. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +23 -0
  67. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/timing.js +4 -0
  68. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/dist-es/write-request-body.js +63 -0
  69. package/node_modules/@earendil-works/pi-ai/node_modules/@smithy/node-http-handler/package.json +56 -0
  70. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +13 -37
  71. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +44 -29
  72. package/node_modules/@smithy/core/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +12 -37
  73. package/node_modules/@smithy/core/dist-es/submodules/protocols/AbstractRpcV2Protocol.js +35 -0
  74. package/node_modules/@smithy/core/dist-es/submodules/protocols/RpcProtocol.js +4 -1
  75. package/node_modules/@smithy/core/dist-es/submodules/protocols/index.js +1 -0
  76. package/node_modules/@smithy/core/dist-es/submodules/protocols/json/SmithyRpcV2JsonProtocol.js +8 -31
  77. package/node_modules/@smithy/core/package.json +1 -1
  78. package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +48 -6
  79. package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +9 -1
  80. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +20 -2
  81. package/node_modules/@smithy/node-http-handler/dist-es/resolve-default-socket-timeout.js +4 -0
  82. package/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +16 -3
  83. package/node_modules/@smithy/node-http-handler/package.json +3 -3
  84. package/node_modules/bowser/README.md +26 -3
  85. package/node_modules/bowser/bowser.mjs +2225 -0
  86. package/node_modules/bowser/bundled.js +14 -1
  87. package/node_modules/bowser/es5.js +14 -1
  88. package/node_modules/bowser/package.json +84 -27
  89. package/node_modules/bowser/src/bowser.js +9 -1
  90. package/node_modules/bowser/src/constants.js +7 -0
  91. package/node_modules/bowser/src/parser-browsers.js +73 -7
  92. package/node_modules/bowser/src/parser-engines.js +12 -0
  93. package/node_modules/bowser/src/parser-os.js +3 -1
  94. package/node_modules/bowser/src/parser-platforms.js +3 -1
  95. package/node_modules/bowser/src/parser.js +22 -5
  96. package/node_modules/bowser/src/utils.js +16 -0
  97. package/package.json +18 -18
@@ -0,0 +1,180 @@
1
+ import { HttpResponse, buildQueryString } from "@smithy/core/protocols";
2
+ import { buildAbortError } from "./build-abort-error";
3
+ import { getTransformedHeaders } from "./get-transformed-headers";
4
+ import { node_http2 } from "./node-http2";
5
+ import { NodeHttp2ConnectionManager } from "./node-http2-connection-manager";
6
+ import { writeRequestBody } from "./write-request-body";
7
+ const { constants } = node_http2;
8
+ export class NodeHttp2Handler {
9
+ config;
10
+ configProvider;
11
+ metadata = { handlerProtocol: "h2" };
12
+ connectionManager = new NodeHttp2ConnectionManager({});
13
+ static create(instanceOrOptions) {
14
+ if (typeof instanceOrOptions?.handle === "function") {
15
+ return instanceOrOptions;
16
+ }
17
+ return new NodeHttp2Handler(instanceOrOptions);
18
+ }
19
+ constructor(options) {
20
+ this.configProvider = new Promise((resolve, reject) => {
21
+ if (typeof options === "function") {
22
+ options()
23
+ .then((opts) => {
24
+ resolve(opts || {});
25
+ })
26
+ .catch(reject);
27
+ }
28
+ else {
29
+ resolve(options || {});
30
+ }
31
+ });
32
+ }
33
+ destroy() {
34
+ this.connectionManager.destroy();
35
+ }
36
+ async handle(request, { abortSignal, requestTimeout, isEventStream } = {}) {
37
+ if (!this.config) {
38
+ this.config = await this.configProvider;
39
+ const { disableConcurrentStreams, maxConcurrentStreams, nodeHttp2ConnectOptions } = this.config;
40
+ this.connectionManager.setDisableConcurrentStreams(disableConcurrentStreams ?? false);
41
+ if (maxConcurrentStreams) {
42
+ this.connectionManager.setMaxConcurrentStreams(maxConcurrentStreams);
43
+ }
44
+ if (nodeHttp2ConnectOptions) {
45
+ this.connectionManager.setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions);
46
+ }
47
+ }
48
+ const { requestTimeout: configRequestTimeout, disableConcurrentStreams } = this.config;
49
+ const useIsolatedSession = disableConcurrentStreams || isEventStream;
50
+ const effectiveRequestTimeout = requestTimeout ?? configRequestTimeout;
51
+ return new Promise((_resolve, _reject) => {
52
+ let fulfilled = false;
53
+ let writeRequestBodyPromise = undefined;
54
+ const resolve = async (arg) => {
55
+ await writeRequestBodyPromise;
56
+ _resolve(arg);
57
+ };
58
+ const reject = async (arg) => {
59
+ await writeRequestBodyPromise;
60
+ _reject(arg);
61
+ };
62
+ if (abortSignal?.aborted) {
63
+ fulfilled = true;
64
+ const abortError = buildAbortError(abortSignal);
65
+ reject(abortError);
66
+ return;
67
+ }
68
+ const { hostname, method, port, protocol, query } = request;
69
+ let auth = "";
70
+ if (request.username != null || request.password != null) {
71
+ const username = request.username ?? "";
72
+ const password = request.password ?? "";
73
+ auth = `${username}:${password}@`;
74
+ }
75
+ const authority = `${protocol}//${auth}${hostname}${port ? `:${port}` : ""}`;
76
+ const requestContext = { destination: new URL(authority) };
77
+ const connectConfig = {
78
+ requestTimeout: this.config?.sessionTimeout,
79
+ isEventStream,
80
+ };
81
+ const ref = useIsolatedSession
82
+ ? this.connectionManager.createIsolatedSession(requestContext, connectConfig)
83
+ : this.connectionManager.lease(requestContext, connectConfig);
84
+ const session = ref.deref();
85
+ const rejectWithDestroy = (err) => {
86
+ if (useIsolatedSession) {
87
+ ref.destroy();
88
+ }
89
+ fulfilled = true;
90
+ reject(err);
91
+ };
92
+ const queryString = query ? buildQueryString(query) : "";
93
+ let path = request.path;
94
+ if (queryString) {
95
+ path += `?${queryString}`;
96
+ }
97
+ if (request.fragment) {
98
+ path += `#${request.fragment}`;
99
+ }
100
+ const clientHttp2Stream = session.request({
101
+ ...request.headers,
102
+ [constants.HTTP2_HEADER_PATH]: path,
103
+ [constants.HTTP2_HEADER_METHOD]: method,
104
+ });
105
+ if (effectiveRequestTimeout) {
106
+ clientHttp2Stream.setTimeout(effectiveRequestTimeout, () => {
107
+ clientHttp2Stream.close();
108
+ const timeoutError = new Error(`Stream timed out because of no activity for ${effectiveRequestTimeout} ms`);
109
+ timeoutError.name = "TimeoutError";
110
+ rejectWithDestroy(timeoutError);
111
+ });
112
+ }
113
+ if (abortSignal) {
114
+ const onAbort = () => {
115
+ clientHttp2Stream.close();
116
+ const abortError = buildAbortError(abortSignal);
117
+ rejectWithDestroy(abortError);
118
+ };
119
+ if (typeof abortSignal.addEventListener === "function") {
120
+ const signal = abortSignal;
121
+ signal.addEventListener("abort", onAbort, { once: true });
122
+ clientHttp2Stream.once("close", () => signal.removeEventListener("abort", onAbort));
123
+ }
124
+ else {
125
+ abortSignal.onabort = onAbort;
126
+ }
127
+ }
128
+ clientHttp2Stream.on("frameError", (type, code, id) => {
129
+ rejectWithDestroy(new Error(`Frame type id ${type} in stream id ${id} has failed with code ${code}.`));
130
+ });
131
+ clientHttp2Stream.on("error", rejectWithDestroy);
132
+ clientHttp2Stream.on("aborted", () => {
133
+ rejectWithDestroy(new Error(`HTTP/2 stream is abnormally aborted in mid-communication with result code ${clientHttp2Stream.rstCode}.`));
134
+ });
135
+ clientHttp2Stream.on("response", (headers) => {
136
+ const httpResponse = new HttpResponse({
137
+ statusCode: headers[":status"] ?? -1,
138
+ headers: getTransformedHeaders(headers),
139
+ body: clientHttp2Stream,
140
+ });
141
+ fulfilled = true;
142
+ resolve({ response: httpResponse });
143
+ if (useIsolatedSession) {
144
+ session.close();
145
+ clientHttp2Stream.on("end", () => {
146
+ ref.destroy();
147
+ });
148
+ }
149
+ });
150
+ clientHttp2Stream.on("close", () => {
151
+ if (useIsolatedSession) {
152
+ ref.destroy();
153
+ }
154
+ else {
155
+ this.connectionManager.release(requestContext, ref);
156
+ }
157
+ if (!fulfilled) {
158
+ const error = new Error("Unexpected error: http2 request did not get a response");
159
+ if (session.destroyed) {
160
+ error.name = "TimeoutError";
161
+ }
162
+ rejectWithDestroy(error);
163
+ }
164
+ });
165
+ writeRequestBodyPromise = writeRequestBody(clientHttp2Stream, request, effectiveRequestTimeout);
166
+ });
167
+ }
168
+ updateHttpClientConfig(key, value) {
169
+ this.config = undefined;
170
+ this.configProvider = this.configProvider.then((config) => {
171
+ return {
172
+ ...config,
173
+ [key]: value,
174
+ };
175
+ });
176
+ }
177
+ httpHandlerConfigs() {
178
+ return this.config ?? {};
179
+ }
180
+ }
@@ -0,0 +1,2 @@
1
+ import node_http2 from "node:http2";
2
+ export { node_http2 };
@@ -0,0 +1,2 @@
1
+ import node_https from "node:https";
2
+ export { node_https };
@@ -0,0 +1,36 @@
1
+ import { timing } from "./timing";
2
+ const DEFER_EVENT_LISTENER_TIME = 1000;
3
+ export const setConnectionTimeout = (request, reject, timeoutInMs = 0) => {
4
+ if (!timeoutInMs) {
5
+ return -1;
6
+ }
7
+ const registerTimeout = (offset) => {
8
+ const timeoutId = timing.setTimeout(() => {
9
+ request.destroy();
10
+ reject(Object.assign(new Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${timeoutInMs} ms.`), {
11
+ name: "TimeoutError",
12
+ }));
13
+ }, timeoutInMs - offset);
14
+ const doWithSocket = (socket) => {
15
+ if (socket?.connecting) {
16
+ socket.on("connect", () => {
17
+ timing.clearTimeout(timeoutId);
18
+ });
19
+ }
20
+ else {
21
+ timing.clearTimeout(timeoutId);
22
+ }
23
+ };
24
+ if (request.socket) {
25
+ doWithSocket(request.socket);
26
+ }
27
+ else {
28
+ request.on("socket", doWithSocket);
29
+ }
30
+ };
31
+ if (timeoutInMs < 2000) {
32
+ registerTimeout(0);
33
+ return 0;
34
+ }
35
+ return timing.setTimeout(registerTimeout.bind(null, DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
36
+ };
@@ -0,0 +1,21 @@
1
+ import { timing } from "./timing";
2
+ export const setRequestTimeout = (req, reject, timeoutInMs = 0, throwOnRequestTimeout, logger) => {
3
+ if (timeoutInMs) {
4
+ return timing.setTimeout(() => {
5
+ let msg = `@smithy/node-http-handler - [${throwOnRequestTimeout ? "ERROR" : "WARN"}] a request has exceeded the configured ${timeoutInMs} ms requestTimeout.`;
6
+ if (throwOnRequestTimeout) {
7
+ const error = Object.assign(new Error(msg), {
8
+ name: "TimeoutError",
9
+ code: "ETIMEDOUT",
10
+ });
11
+ req.destroy(error);
12
+ reject(error);
13
+ }
14
+ else {
15
+ msg += ` Init client requestHandler with throwOnRequestTimeout=true to turn this into an error.`;
16
+ logger?.warn?.(msg);
17
+ }
18
+ }, timeoutInMs);
19
+ }
20
+ return -1;
21
+ };
@@ -0,0 +1,22 @@
1
+ import { timing } from "./timing";
2
+ const DEFER_EVENT_LISTENER_TIME = 3000;
3
+ export const setSocketKeepAlive = (request, { keepAlive, keepAliveMsecs }, deferTimeMs = DEFER_EVENT_LISTENER_TIME) => {
4
+ if (keepAlive !== true) {
5
+ return -1;
6
+ }
7
+ const registerListener = () => {
8
+ if (request.socket) {
9
+ request.socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
10
+ }
11
+ else {
12
+ request.on("socket", (socket) => {
13
+ socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
14
+ });
15
+ }
16
+ };
17
+ if (deferTimeMs === 0) {
18
+ registerListener();
19
+ return 0;
20
+ }
21
+ return timing.setTimeout(registerListener, deferTimeMs);
22
+ };
@@ -0,0 +1,23 @@
1
+ import { timing } from "./timing";
2
+ const DEFER_EVENT_LISTENER_TIME = 3000;
3
+ export const setSocketTimeout = (request, reject, timeoutInMs = 0) => {
4
+ const registerTimeout = (offset) => {
5
+ const timeout = timeoutInMs - offset;
6
+ const onTimeout = () => {
7
+ request.destroy();
8
+ reject(Object.assign(new Error(`@smithy/node-http-handler - the request socket timed out after ${timeoutInMs} ms of inactivity (configured by client requestHandler).`), { name: "TimeoutError" }));
9
+ };
10
+ if (request.socket) {
11
+ request.socket.setTimeout(timeout, onTimeout);
12
+ request.on("close", () => request.socket?.removeListener("timeout", onTimeout));
13
+ }
14
+ else {
15
+ request.setTimeout(timeout, onTimeout);
16
+ }
17
+ };
18
+ if (0 < timeoutInMs && timeoutInMs < 6000) {
19
+ registerTimeout(0);
20
+ return 0;
21
+ }
22
+ return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
23
+ };
@@ -0,0 +1,4 @@
1
+ export const timing = {
2
+ setTimeout: (cb, ms) => setTimeout(cb, ms),
3
+ clearTimeout: (timeoutId) => clearTimeout(timeoutId),
4
+ };
@@ -0,0 +1,63 @@
1
+ import { Readable } from "node:stream";
2
+ import { timing } from "./timing";
3
+ const MIN_WAIT_TIME = 6_000;
4
+ export async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME, externalAgent = false) {
5
+ const headers = request.headers;
6
+ const expect = headers ? headers.Expect || headers.expect : undefined;
7
+ let timeoutId = -1;
8
+ let sendBody = true;
9
+ if (!externalAgent && expect === "100-continue") {
10
+ sendBody = await Promise.race([
11
+ new Promise((resolve) => {
12
+ timeoutId = Number(timing.setTimeout(() => resolve(true), Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
13
+ }),
14
+ new Promise((resolve) => {
15
+ httpRequest.on("continue", () => {
16
+ timing.clearTimeout(timeoutId);
17
+ resolve(true);
18
+ });
19
+ httpRequest.on("response", () => {
20
+ timing.clearTimeout(timeoutId);
21
+ resolve(false);
22
+ });
23
+ httpRequest.on("error", () => {
24
+ timing.clearTimeout(timeoutId);
25
+ resolve(false);
26
+ });
27
+ }),
28
+ ]);
29
+ }
30
+ if (sendBody) {
31
+ writeBody(httpRequest, request.body);
32
+ }
33
+ }
34
+ function writeBody(httpRequest, body) {
35
+ if (body instanceof Readable) {
36
+ body.pipe(httpRequest);
37
+ return;
38
+ }
39
+ if (body) {
40
+ const isBuffer = Buffer.isBuffer(body);
41
+ const isString = typeof body === "string";
42
+ if (isBuffer || isString) {
43
+ if (isBuffer && body.byteLength === 0) {
44
+ httpRequest.end();
45
+ }
46
+ else {
47
+ httpRequest.end(body);
48
+ }
49
+ return;
50
+ }
51
+ const uint8 = body;
52
+ if (typeof uint8 === "object" &&
53
+ uint8.buffer &&
54
+ typeof uint8.byteOffset === "number" &&
55
+ typeof uint8.byteLength === "number") {
56
+ httpRequest.end(Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength));
57
+ return;
58
+ }
59
+ httpRequest.end(Buffer.from(body));
60
+ return;
61
+ }
62
+ httpRequest.end();
63
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@smithy/node-http-handler",
3
+ "version": "4.12.1",
4
+ "description": "Provides a way to make requests",
5
+ "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/node-http-handler",
6
+ "license": "Apache-2.0",
7
+ "author": {
8
+ "name": "AWS SDK for JavaScript Team",
9
+ "email": "",
10
+ "url": "https://aws.amazon.com/sdk-for-javascript/"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/smithy-lang/smithy-typescript.git",
15
+ "directory": "packages/node-http-handler"
16
+ },
17
+ "files": [
18
+ "dist-*/**"
19
+ ],
20
+ "sideEffects": false,
21
+ "main": "./dist-cjs/index.js",
22
+ "module": "./dist-es/index.js",
23
+ "types": "./dist-types/index.d.ts",
24
+ "typesVersions": {
25
+ "<4.5": {
26
+ "dist-types/*": [
27
+ "dist-types/ts3.4/*"
28
+ ]
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
33
+ "build:es:cjs": "node ../../scripts/compilation/es_cjs.js",
34
+ "build:types": "premove dist-types && yarn g:tsc -p tsconfig.types.json",
35
+ "build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
36
+ "clean": "premove dist-cjs dist-es dist-types",
37
+ "extract:docs": "api-extractor run --local",
38
+ "test": "yarn g:vitest run",
39
+ "test:watch": "yarn g:vitest watch"
40
+ },
41
+ "dependencies": {
42
+ "@smithy/core": "^3.33.3",
43
+ "@smithy/types": "^4.18.0",
44
+ "tslib": "^2.6.2"
45
+ },
46
+ "devDependencies": {
47
+ "@smithy/abort-controller": "^4.4.2",
48
+ "@types/node": "^18.11.9",
49
+ "concurrently": "7.0.0",
50
+ "downlevel-dts": "0.10.1",
51
+ "premove": "4.0.0"
52
+ },
53
+ "engines": {
54
+ "node": ">=18.0.0"
55
+ }
56
+ }
@@ -1,7 +1,7 @@
1
1
  const { nv, NumericValue, calculateBodyLength, generateIdempotencyToken, fromBase64, _parseEpochTimestamp } = require("@smithy/core/serde");
2
- const { hasOwn, getSmithyContext } = require("@smithy/core/transport");
3
- const { HttpRequest, collectBody, SerdeContext, RpcProtocol } = require("@smithy/core/protocols");
4
- const { NormalizedSchema, deref, TypeRegistry } = require("@smithy/core/schema");
2
+ const { hasOwn } = require("@smithy/core/transport");
3
+ const { HttpRequest, collectBody, SerdeContext, AbstractRpcV2Protocol } = require("@smithy/core/protocols");
4
+ const { NormalizedSchema, TypeRegistry } = require("@smithy/core/schema");
5
5
 
6
6
  const majorUint64 = 0;
7
7
  const majorNegativeInt64 = 1;
@@ -2216,51 +2216,27 @@ class CborCodec extends SerdeContext {
2216
2216
  }
2217
2217
  }
2218
2218
 
2219
- class SmithyRpcV2CborProtocol extends RpcProtocol {
2219
+ class SmithyRpcV2CborProtocol extends AbstractRpcV2Protocol {
2220
2220
  codec = new CborCodec();
2221
2221
  serializer = this.codec.createSerializer();
2222
2222
  deserializer = this.codec.createDeserializer();
2223
- constructor({ defaultNamespace, errorTypeRegistries, }) {
2224
- super({ defaultNamespace, errorTypeRegistries });
2225
- }
2226
2223
  getShapeId() {
2227
2224
  return "smithy.protocols#rpcv2Cbor";
2228
2225
  }
2229
2226
  getPayloadCodec() {
2230
2227
  return this.codec;
2231
2228
  }
2232
- async serializeRequest(operationSchema, input, context) {
2233
- const request = await super.serializeRequest(operationSchema, input, context);
2234
- Object.assign(request.headers, {
2235
- "content-type": this.getDefaultContentType(),
2236
- "smithy-protocol": "rpc-v2-cbor",
2237
- accept: this.getDefaultContentType(),
2238
- });
2239
- if (deref(operationSchema.input) === "unit") {
2240
- delete request.body;
2241
- delete request.headers["content-type"];
2242
- }
2243
- else {
2244
- if (!request.body) {
2245
- this.serializer.write(15, {});
2246
- request.body = this.serializer.flush();
2247
- }
2248
- if (request.body instanceof Uint8Array) {
2249
- request.headers["content-length"] = String(request.body.byteLength);
2250
- }
2251
- }
2252
- const { service, operation } = getSmithyContext(context);
2253
- const path = `/service/${service}/operation/${operation}`;
2254
- if (request.path.endsWith("/")) {
2255
- request.path += path.slice(1);
2229
+ getSmithyProtocolHeaderValue() {
2230
+ return "rpc-v2-cbor";
2231
+ }
2232
+ applyEmptyBody(request) {
2233
+ if (!request.body) {
2234
+ this.serializer.write(15, {});
2235
+ request.body = this.serializer.flush();
2256
2236
  }
2257
- else {
2258
- request.path += path;
2237
+ if (request.body instanceof Uint8Array) {
2238
+ request.headers["content-length"] = String(request.body.byteLength);
2259
2239
  }
2260
- return request;
2261
- }
2262
- async deserializeResponse(operationSchema, context, response) {
2263
- return super.deserializeResponse(operationSchema, context, response);
2264
2240
  }
2265
2241
  async handleError(operationSchema, context, response, dataObject, metadata) {
2266
2242
  const errorIdentifier = loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
@@ -574,7 +574,7 @@ class RpcProtocol extends HttpProtocol {
574
574
  const deserializer = this.deserializer;
575
575
  const ns = NormalizedSchema.of(operationSchema.output);
576
576
  const dataObject = {};
577
- if (response.statusCode >= 300) {
577
+ if (this.isErrorResponse(response.statusCode)) {
578
578
  const bytes = await collectBody(response.body, context);
579
579
  if (bytes.byteLength > 0) {
580
580
  Object.assign(dataObject, await deserializer.read(15, bytes));
@@ -606,6 +606,42 @@ class RpcProtocol extends HttpProtocol {
606
606
  dataObject.$metadata = this.deserializeMetadata(response);
607
607
  return dataObject;
608
608
  }
609
+ isErrorResponse(statusCode) {
610
+ return statusCode >= 300;
611
+ }
612
+ }
613
+
614
+ class AbstractRpcV2Protocol extends RpcProtocol {
615
+ constructor({ defaultNamespace, errorTypeRegistries, }) {
616
+ super({ defaultNamespace, errorTypeRegistries });
617
+ }
618
+ async serializeRequest(operationSchema, input, context) {
619
+ const request = await super.serializeRequest(operationSchema, input, context);
620
+ Object.assign(request.headers, {
621
+ "content-type": this.getDefaultContentType(),
622
+ "smithy-protocol": this.getSmithyProtocolHeaderValue(),
623
+ accept: this.getDefaultContentType(),
624
+ });
625
+ if (deref(operationSchema.input) === "unit") {
626
+ delete request.body;
627
+ delete request.headers["content-type"];
628
+ }
629
+ else {
630
+ this.applyEmptyBody(request);
631
+ }
632
+ const { service, operation } = getSmithyContext(context);
633
+ const path = `/service/${service}/operation/${operation}`;
634
+ if (request.path.endsWith("/")) {
635
+ request.path += path.slice(1);
636
+ }
637
+ else {
638
+ request.path += path;
639
+ }
640
+ return request;
641
+ }
642
+ isErrorResponse(statusCode) {
643
+ return statusCode !== 200;
644
+ }
609
645
  }
610
646
 
611
647
  const resolvedPath = (resolvedPath, input, memberName, labelValueProvider, uriLabel, isGreedyLabel) => {
@@ -2240,7 +2276,7 @@ class JsonCodec2 extends SerdeContextConfig {
2240
2276
  }
2241
2277
  }
2242
2278
 
2243
- class SmithyRpcV2JsonProtocol extends RpcProtocol {
2279
+ class SmithyRpcV2JsonProtocol extends AbstractRpcV2Protocol {
2244
2280
  codec = new JsonCodec2({
2245
2281
  timestampFormat: {
2246
2282
  useTrait: false,
@@ -2251,41 +2287,19 @@ class SmithyRpcV2JsonProtocol extends RpcProtocol {
2251
2287
  });
2252
2288
  serializer = this.codec.createSerializer();
2253
2289
  deserializer = this.codec.createDeserializer();
2254
- constructor({ defaultNamespace, errorTypeRegistries, }) {
2255
- super({ defaultNamespace, errorTypeRegistries });
2256
- }
2257
2290
  getShapeId() {
2258
2291
  return "smithy.protocols#rpcv2Json";
2259
2292
  }
2260
2293
  getPayloadCodec() {
2261
2294
  return this.codec;
2262
2295
  }
2263
- async serializeRequest(operationSchema, input, context) {
2264
- const request = await super.serializeRequest(operationSchema, input, context);
2265
- Object.assign(request.headers, {
2266
- "content-type": this.getDefaultContentType(),
2267
- "smithy-protocol": "rpc-v2-json",
2268
- accept: this.getDefaultContentType(),
2269
- });
2270
- if (deref(operationSchema.input) === "unit") {
2271
- delete request.body;
2272
- delete request.headers["content-type"];
2273
- }
2274
- else if (!request.body) {
2296
+ getSmithyProtocolHeaderValue() {
2297
+ return "rpc-v2-json";
2298
+ }
2299
+ applyEmptyBody(request) {
2300
+ if (!request.body) {
2275
2301
  request.body = "{}";
2276
2302
  }
2277
- const { service, operation } = getSmithyContext(context);
2278
- const path = `/service/${service}/operation/${operation}`;
2279
- if (request.path.endsWith("/")) {
2280
- request.path += path.slice(1);
2281
- }
2282
- else {
2283
- request.path += path;
2284
- }
2285
- return request;
2286
- }
2287
- async deserializeResponse(operationSchema, context, response) {
2288
- return super.deserializeResponse(operationSchema, context, response);
2289
2303
  }
2290
2304
  async handleError(operationSchema, context, response, dataObject, metadata) {
2291
2305
  const errorName = loadSmithyRpcV2JsonErrorCode(response, dataObject) ?? "Unknown";
@@ -2753,6 +2767,7 @@ class JsonCodec extends SerdeContextConfig {
2753
2767
  }
2754
2768
  }
2755
2769
 
2770
+ exports.AbstractRpcV2Protocol = AbstractRpcV2Protocol;
2756
2771
  exports.Field = Field;
2757
2772
  exports.Fields = Fields;
2758
2773
  exports.FromStringShapeDeserializer = FromStringShapeDeserializer;