@alienplatform/sdk 1.10.7 → 1.11.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/.turbo/turbo-build.log +37 -8
- package/dist/bearerTokenAuthenticationPolicy.js +3028 -0
- package/dist/bindings/index.d.ts +1 -0
- package/dist/bindings/index.d.ts.map +1 -1
- package/dist/bindings/postgres.d.ts +90 -0
- package/dist/bindings/postgres.d.ts.map +1 -0
- package/dist/bindings/postgres.test.d.ts +2 -0
- package/dist/bindings/postgres.test.d.ts.map +1 -0
- package/dist/client.js +2376 -0
- package/dist/commands/index.js +1 -1
- package/dist/dist-cjs.js +3 -0
- package/dist/dist-cjs2.js +718 -0
- package/dist/dist-cjs3.js +2486 -0
- package/dist/dist-cjs4.js +171 -0
- package/dist/dist-cjs5.js +429 -0
- package/dist/dist-cjs6.js +60 -0
- package/dist/dist-cjs7.js +978 -0
- package/dist/dist-cjs8.js +86 -0
- package/dist/dist-cjs9.js +319 -0
- package/dist/dist.js +498 -36
- package/dist/dist2.js +1239 -0
- package/dist/errors.d.ts +25 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/es5.js +1624 -0
- package/dist/esm.js +18211 -0
- package/dist/esm2.js +3104 -0
- package/dist/event-streams.js +203 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +336 -24996
- package/dist/jws.js +611 -0
- package/dist/open.js +460 -0
- package/dist/package.js +4 -0
- package/dist/protocols.js +954 -0
- package/dist/protocols2.js +5565 -0
- package/dist/rolldown-runtime.js +37 -0
- package/dist/serde.js +5542 -0
- package/dist/signin.js +723 -0
- package/dist/src.js +24900 -0
- package/dist/src2.js +114030 -0
- package/dist/sso-oidc.js +940 -0
- package/dist/sts.js +1329 -0
- package/dist/tslib.es6.js +543 -0
- package/package.json +26 -2
- package/src/bindings/index.ts +1 -0
- package/src/bindings/postgres.test.ts +17 -0
- package/src/bindings/postgres.ts +446 -0
- package/src/errors.ts +21 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1,718 @@
|
|
|
1
|
+
import { a as __toCommonJS, i as __require, t as __commonJSMin } from "./rolldown-runtime.js";
|
|
2
|
+
import { n as protocols_exports, t as init_protocols } from "./protocols.js";
|
|
3
|
+
//#region ../../node_modules/.pnpm/@smithy+node-http-handler@4.7.8/node_modules/@smithy/node-http-handler/dist-cjs/index.js
|
|
4
|
+
var require_dist_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
5
|
+
var protocols = (init_protocols(), __toCommonJS(protocols_exports));
|
|
6
|
+
var node_https = __require("node:https");
|
|
7
|
+
var node_stream = __require("node:stream");
|
|
8
|
+
var http2 = __require("node:http2");
|
|
9
|
+
function buildAbortError(abortSignal) {
|
|
10
|
+
const reason = abortSignal && typeof abortSignal === "object" && "reason" in abortSignal ? abortSignal.reason : void 0;
|
|
11
|
+
if (reason) {
|
|
12
|
+
if (reason instanceof Error) {
|
|
13
|
+
const abortError = /* @__PURE__ */ new Error("Request aborted");
|
|
14
|
+
abortError.name = "AbortError";
|
|
15
|
+
abortError.cause = reason;
|
|
16
|
+
return abortError;
|
|
17
|
+
}
|
|
18
|
+
const abortError = new Error(String(reason));
|
|
19
|
+
abortError.name = "AbortError";
|
|
20
|
+
return abortError;
|
|
21
|
+
}
|
|
22
|
+
const abortError = /* @__PURE__ */ new Error("Request aborted");
|
|
23
|
+
abortError.name = "AbortError";
|
|
24
|
+
return abortError;
|
|
25
|
+
}
|
|
26
|
+
const NODEJS_TIMEOUT_ERROR_CODES = [
|
|
27
|
+
"ECONNRESET",
|
|
28
|
+
"EPIPE",
|
|
29
|
+
"ETIMEDOUT"
|
|
30
|
+
];
|
|
31
|
+
const getTransformedHeaders = (headers) => {
|
|
32
|
+
const transformedHeaders = {};
|
|
33
|
+
for (const name in headers) {
|
|
34
|
+
const headerValues = headers[name];
|
|
35
|
+
transformedHeaders[name] = Array.isArray(headerValues) ? headerValues.join(",") : headerValues;
|
|
36
|
+
}
|
|
37
|
+
return transformedHeaders;
|
|
38
|
+
};
|
|
39
|
+
const timing = {
|
|
40
|
+
setTimeout: (cb, ms) => setTimeout(cb, ms),
|
|
41
|
+
clearTimeout: (timeoutId) => clearTimeout(timeoutId)
|
|
42
|
+
};
|
|
43
|
+
const DEFER_EVENT_LISTENER_TIME$2 = 1e3;
|
|
44
|
+
const setConnectionTimeout = (request, reject, timeoutInMs = 0) => {
|
|
45
|
+
if (!timeoutInMs) return -1;
|
|
46
|
+
const registerTimeout = (offset) => {
|
|
47
|
+
const timeoutId = timing.setTimeout(() => {
|
|
48
|
+
request.destroy();
|
|
49
|
+
reject(Object.assign(/* @__PURE__ */ new Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${timeoutInMs} ms.`), { name: "TimeoutError" }));
|
|
50
|
+
}, timeoutInMs - offset);
|
|
51
|
+
const doWithSocket = (socket) => {
|
|
52
|
+
if (socket?.connecting) socket.on("connect", () => {
|
|
53
|
+
timing.clearTimeout(timeoutId);
|
|
54
|
+
});
|
|
55
|
+
else timing.clearTimeout(timeoutId);
|
|
56
|
+
};
|
|
57
|
+
if (request.socket) doWithSocket(request.socket);
|
|
58
|
+
else request.on("socket", doWithSocket);
|
|
59
|
+
};
|
|
60
|
+
if (timeoutInMs < 2e3) {
|
|
61
|
+
registerTimeout(0);
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
return timing.setTimeout(registerTimeout.bind(null, DEFER_EVENT_LISTENER_TIME$2), DEFER_EVENT_LISTENER_TIME$2);
|
|
65
|
+
};
|
|
66
|
+
const setRequestTimeout = (req, reject, timeoutInMs = 0, throwOnRequestTimeout, logger) => {
|
|
67
|
+
if (timeoutInMs) return timing.setTimeout(() => {
|
|
68
|
+
let msg = `@smithy/node-http-handler - [${throwOnRequestTimeout ? "ERROR" : "WARN"}] a request has exceeded the configured ${timeoutInMs} ms requestTimeout.`;
|
|
69
|
+
if (throwOnRequestTimeout) {
|
|
70
|
+
const error = Object.assign(new Error(msg), {
|
|
71
|
+
name: "TimeoutError",
|
|
72
|
+
code: "ETIMEDOUT"
|
|
73
|
+
});
|
|
74
|
+
req.destroy(error);
|
|
75
|
+
reject(error);
|
|
76
|
+
} else {
|
|
77
|
+
msg += ` Init client requestHandler with throwOnRequestTimeout=true to turn this into an error.`;
|
|
78
|
+
logger?.warn?.(msg);
|
|
79
|
+
}
|
|
80
|
+
}, timeoutInMs);
|
|
81
|
+
return -1;
|
|
82
|
+
};
|
|
83
|
+
const DEFER_EVENT_LISTENER_TIME$1 = 3e3;
|
|
84
|
+
const setSocketKeepAlive = (request, { keepAlive, keepAliveMsecs }, deferTimeMs = DEFER_EVENT_LISTENER_TIME$1) => {
|
|
85
|
+
if (keepAlive !== true) return -1;
|
|
86
|
+
const registerListener = () => {
|
|
87
|
+
if (request.socket) request.socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
|
|
88
|
+
else request.on("socket", (socket) => {
|
|
89
|
+
socket.setKeepAlive(keepAlive, keepAliveMsecs || 0);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
if (deferTimeMs === 0) {
|
|
93
|
+
registerListener();
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
return timing.setTimeout(registerListener, deferTimeMs);
|
|
97
|
+
};
|
|
98
|
+
const DEFER_EVENT_LISTENER_TIME = 3e3;
|
|
99
|
+
const setSocketTimeout = (request, reject, timeoutInMs = 0) => {
|
|
100
|
+
const registerTimeout = (offset) => {
|
|
101
|
+
const timeout = timeoutInMs - offset;
|
|
102
|
+
const onTimeout = () => {
|
|
103
|
+
request.destroy();
|
|
104
|
+
reject(Object.assign(/* @__PURE__ */ new Error(`@smithy/node-http-handler - the request socket timed out after ${timeoutInMs} ms of inactivity (configured by client requestHandler).`), { name: "TimeoutError" }));
|
|
105
|
+
};
|
|
106
|
+
if (request.socket) {
|
|
107
|
+
request.socket.setTimeout(timeout, onTimeout);
|
|
108
|
+
request.on("close", () => request.socket?.removeListener("timeout", onTimeout));
|
|
109
|
+
} else request.setTimeout(timeout, onTimeout);
|
|
110
|
+
};
|
|
111
|
+
if (0 < timeoutInMs && timeoutInMs < 6e3) {
|
|
112
|
+
registerTimeout(0);
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
return timing.setTimeout(registerTimeout.bind(null, timeoutInMs === 0 ? 0 : DEFER_EVENT_LISTENER_TIME), DEFER_EVENT_LISTENER_TIME);
|
|
116
|
+
};
|
|
117
|
+
const MIN_WAIT_TIME = 6e3;
|
|
118
|
+
async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME, externalAgent = false) {
|
|
119
|
+
const headers = request.headers;
|
|
120
|
+
const expect = headers ? headers.Expect || headers.expect : void 0;
|
|
121
|
+
let timeoutId = -1;
|
|
122
|
+
let sendBody = true;
|
|
123
|
+
if (!externalAgent && expect === "100-continue") sendBody = await Promise.race([new Promise((resolve) => {
|
|
124
|
+
timeoutId = Number(timing.setTimeout(() => resolve(true), Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
|
|
125
|
+
}), new Promise((resolve) => {
|
|
126
|
+
httpRequest.on("continue", () => {
|
|
127
|
+
timing.clearTimeout(timeoutId);
|
|
128
|
+
resolve(true);
|
|
129
|
+
});
|
|
130
|
+
httpRequest.on("response", () => {
|
|
131
|
+
timing.clearTimeout(timeoutId);
|
|
132
|
+
resolve(false);
|
|
133
|
+
});
|
|
134
|
+
httpRequest.on("error", () => {
|
|
135
|
+
timing.clearTimeout(timeoutId);
|
|
136
|
+
resolve(false);
|
|
137
|
+
});
|
|
138
|
+
})]);
|
|
139
|
+
if (sendBody) writeBody(httpRequest, request.body);
|
|
140
|
+
}
|
|
141
|
+
function writeBody(httpRequest, body) {
|
|
142
|
+
if (body instanceof node_stream.Readable) {
|
|
143
|
+
body.pipe(httpRequest);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (body) {
|
|
147
|
+
const isBuffer = Buffer.isBuffer(body);
|
|
148
|
+
if (isBuffer || typeof body === "string") {
|
|
149
|
+
if (isBuffer && body.byteLength === 0) httpRequest.end();
|
|
150
|
+
else httpRequest.end(body);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const uint8 = body;
|
|
154
|
+
if (typeof uint8 === "object" && uint8.buffer && typeof uint8.byteOffset === "number" && typeof uint8.byteLength === "number") {
|
|
155
|
+
httpRequest.end(Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
httpRequest.end(Buffer.from(body));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
httpRequest.end();
|
|
162
|
+
}
|
|
163
|
+
const DEFAULT_REQUEST_TIMEOUT = 0;
|
|
164
|
+
let hAgent = void 0;
|
|
165
|
+
let hRequest = void 0;
|
|
166
|
+
var NodeHttpHandler = class NodeHttpHandler {
|
|
167
|
+
config;
|
|
168
|
+
configProvider;
|
|
169
|
+
socketWarningTimestamp = 0;
|
|
170
|
+
externalAgent = false;
|
|
171
|
+
metadata = { handlerProtocol: "http/1.1" };
|
|
172
|
+
static create(instanceOrOptions) {
|
|
173
|
+
if (typeof instanceOrOptions?.handle === "function") return instanceOrOptions;
|
|
174
|
+
return new NodeHttpHandler(instanceOrOptions);
|
|
175
|
+
}
|
|
176
|
+
static checkSocketUsage(agent, socketWarningTimestamp, logger = console) {
|
|
177
|
+
const { sockets, requests, maxSockets } = agent;
|
|
178
|
+
if (typeof maxSockets !== "number" || maxSockets === Infinity) return socketWarningTimestamp;
|
|
179
|
+
if (Date.now() - 15e3 < socketWarningTimestamp) return socketWarningTimestamp;
|
|
180
|
+
if (sockets && requests) for (const origin in sockets) {
|
|
181
|
+
const socketsInUse = sockets[origin]?.length ?? 0;
|
|
182
|
+
const requestsEnqueued = requests[origin]?.length ?? 0;
|
|
183
|
+
if (socketsInUse >= maxSockets && requestsEnqueued >= 2 * maxSockets) {
|
|
184
|
+
logger?.warn?.(`@smithy/node-http-handler:WARN - socket usage at capacity=${socketsInUse} and ${requestsEnqueued} additional requests are enqueued.
|
|
185
|
+
See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
|
|
186
|
+
or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`);
|
|
187
|
+
return Date.now();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return socketWarningTimestamp;
|
|
191
|
+
}
|
|
192
|
+
constructor(options) {
|
|
193
|
+
this.configProvider = new Promise((resolve, reject) => {
|
|
194
|
+
if (typeof options === "function") options().then((_options) => {
|
|
195
|
+
resolve(this.resolveDefaultConfig(_options));
|
|
196
|
+
}).catch(reject);
|
|
197
|
+
else resolve(this.resolveDefaultConfig(options));
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
destroy() {
|
|
201
|
+
this.config?.httpAgent?.destroy();
|
|
202
|
+
this.config?.httpsAgent?.destroy();
|
|
203
|
+
}
|
|
204
|
+
async handle(request, { abortSignal, requestTimeout } = {}) {
|
|
205
|
+
if (!this.config) this.config = await this.configProvider;
|
|
206
|
+
const config = this.config;
|
|
207
|
+
const isSSL = request.protocol === "https:";
|
|
208
|
+
if (!isSSL && !this.config.httpAgent) this.config.httpAgent = await this.config.httpAgentProvider();
|
|
209
|
+
return new Promise((_resolve, _reject) => {
|
|
210
|
+
let writeRequestBodyPromise = void 0;
|
|
211
|
+
let socketWarningTimeoutId = -1;
|
|
212
|
+
let connectionTimeoutId = -1;
|
|
213
|
+
let requestTimeoutId = -1;
|
|
214
|
+
let socketTimeoutId = -1;
|
|
215
|
+
let keepAliveTimeoutId = -1;
|
|
216
|
+
const clearTimeouts = () => {
|
|
217
|
+
timing.clearTimeout(socketWarningTimeoutId);
|
|
218
|
+
timing.clearTimeout(connectionTimeoutId);
|
|
219
|
+
timing.clearTimeout(requestTimeoutId);
|
|
220
|
+
timing.clearTimeout(socketTimeoutId);
|
|
221
|
+
timing.clearTimeout(keepAliveTimeoutId);
|
|
222
|
+
};
|
|
223
|
+
const resolve = async (arg) => {
|
|
224
|
+
await writeRequestBodyPromise;
|
|
225
|
+
clearTimeouts();
|
|
226
|
+
_resolve(arg);
|
|
227
|
+
};
|
|
228
|
+
const reject = async (arg) => {
|
|
229
|
+
await writeRequestBodyPromise;
|
|
230
|
+
clearTimeouts();
|
|
231
|
+
_reject(arg);
|
|
232
|
+
};
|
|
233
|
+
if (abortSignal?.aborted) {
|
|
234
|
+
reject(buildAbortError(abortSignal));
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const headers = request.headers;
|
|
238
|
+
const expectContinue = headers ? (headers.Expect ?? headers.expect) === "100-continue" : false;
|
|
239
|
+
let agent = isSSL ? config.httpsAgent : config.httpAgent;
|
|
240
|
+
if (expectContinue && !this.externalAgent) agent = new (isSSL ? node_https.Agent : hAgent)({
|
|
241
|
+
keepAlive: false,
|
|
242
|
+
maxSockets: Infinity
|
|
243
|
+
});
|
|
244
|
+
socketWarningTimeoutId = timing.setTimeout(() => {
|
|
245
|
+
this.socketWarningTimestamp = NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp, config.logger);
|
|
246
|
+
}, config.socketAcquisitionWarningTimeout ?? (config.requestTimeout ?? 2e3) + (config.connectionTimeout ?? 1e3));
|
|
247
|
+
const queryString = request.query ? protocols.buildQueryString(request.query) : "";
|
|
248
|
+
let auth = void 0;
|
|
249
|
+
if (request.username != null || request.password != null) auth = `${request.username ?? ""}:${request.password ?? ""}`;
|
|
250
|
+
let path = request.path;
|
|
251
|
+
if (queryString) path += `?${queryString}`;
|
|
252
|
+
if (request.fragment) path += `#${request.fragment}`;
|
|
253
|
+
let hostname = request.hostname ?? "";
|
|
254
|
+
if (hostname[0] === "[" && hostname.endsWith("]")) hostname = request.hostname.slice(1, -1);
|
|
255
|
+
else hostname = request.hostname;
|
|
256
|
+
const nodeHttpsOptions = {
|
|
257
|
+
headers: request.headers,
|
|
258
|
+
host: hostname,
|
|
259
|
+
method: request.method,
|
|
260
|
+
path,
|
|
261
|
+
port: request.port,
|
|
262
|
+
agent,
|
|
263
|
+
auth
|
|
264
|
+
};
|
|
265
|
+
const req = (isSSL ? node_https.request : hRequest)(nodeHttpsOptions, (res) => {
|
|
266
|
+
resolve({ response: new protocols.HttpResponse({
|
|
267
|
+
statusCode: res.statusCode || -1,
|
|
268
|
+
reason: res.statusMessage,
|
|
269
|
+
headers: getTransformedHeaders(res.headers),
|
|
270
|
+
body: res
|
|
271
|
+
}) });
|
|
272
|
+
});
|
|
273
|
+
req.on("error", (err) => {
|
|
274
|
+
if (NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) reject(Object.assign(err, { name: "TimeoutError" }));
|
|
275
|
+
else reject(err);
|
|
276
|
+
});
|
|
277
|
+
if (abortSignal) {
|
|
278
|
+
const onAbort = () => {
|
|
279
|
+
req.destroy();
|
|
280
|
+
reject(buildAbortError(abortSignal));
|
|
281
|
+
};
|
|
282
|
+
if (typeof abortSignal.addEventListener === "function") {
|
|
283
|
+
const signal = abortSignal;
|
|
284
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
285
|
+
req.once("close", () => signal.removeEventListener("abort", onAbort));
|
|
286
|
+
} else abortSignal.onabort = onAbort;
|
|
287
|
+
}
|
|
288
|
+
const effectiveRequestTimeout = requestTimeout ?? config.requestTimeout;
|
|
289
|
+
connectionTimeoutId = setConnectionTimeout(req, reject, config.connectionTimeout);
|
|
290
|
+
requestTimeoutId = setRequestTimeout(req, reject, effectiveRequestTimeout, config.throwOnRequestTimeout, config.logger ?? console);
|
|
291
|
+
socketTimeoutId = setSocketTimeout(req, reject, config.socketTimeout);
|
|
292
|
+
const httpAgent = nodeHttpsOptions.agent;
|
|
293
|
+
if (typeof httpAgent === "object" && "keepAlive" in httpAgent) keepAliveTimeoutId = setSocketKeepAlive(req, {
|
|
294
|
+
keepAlive: httpAgent.keepAlive,
|
|
295
|
+
keepAliveMsecs: httpAgent.keepAliveMsecs
|
|
296
|
+
});
|
|
297
|
+
writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout, this.externalAgent).catch((e) => {
|
|
298
|
+
clearTimeouts();
|
|
299
|
+
return _reject(e);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
updateHttpClientConfig(key, value) {
|
|
304
|
+
this.config = void 0;
|
|
305
|
+
this.configProvider = this.configProvider.then((config) => {
|
|
306
|
+
return {
|
|
307
|
+
...config,
|
|
308
|
+
[key]: value
|
|
309
|
+
};
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
httpHandlerConfigs() {
|
|
313
|
+
return this.config ?? {};
|
|
314
|
+
}
|
|
315
|
+
resolveDefaultConfig(options) {
|
|
316
|
+
const { requestTimeout, connectionTimeout, socketTimeout, socketAcquisitionWarningTimeout, httpAgent, httpsAgent, throwOnRequestTimeout, logger } = options || {};
|
|
317
|
+
const keepAlive = true;
|
|
318
|
+
const maxSockets = 50;
|
|
319
|
+
return {
|
|
320
|
+
connectionTimeout,
|
|
321
|
+
requestTimeout,
|
|
322
|
+
socketTimeout,
|
|
323
|
+
socketAcquisitionWarningTimeout,
|
|
324
|
+
throwOnRequestTimeout,
|
|
325
|
+
httpAgentProvider: async () => {
|
|
326
|
+
const node_http = await import("node:http");
|
|
327
|
+
const { Agent, request } = node_http.default ?? node_http;
|
|
328
|
+
hRequest = request;
|
|
329
|
+
hAgent = Agent;
|
|
330
|
+
if (httpAgent instanceof hAgent || typeof httpAgent?.destroy === "function") {
|
|
331
|
+
this.externalAgent = true;
|
|
332
|
+
return httpAgent;
|
|
333
|
+
}
|
|
334
|
+
return new hAgent({
|
|
335
|
+
keepAlive,
|
|
336
|
+
maxSockets,
|
|
337
|
+
...httpAgent
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
httpsAgent: (() => {
|
|
341
|
+
if (httpsAgent instanceof node_https.Agent || typeof httpsAgent?.destroy === "function") {
|
|
342
|
+
this.externalAgent = true;
|
|
343
|
+
return httpsAgent;
|
|
344
|
+
}
|
|
345
|
+
return new node_https.Agent({
|
|
346
|
+
keepAlive,
|
|
347
|
+
maxSockets,
|
|
348
|
+
...httpsAgent
|
|
349
|
+
});
|
|
350
|
+
})(),
|
|
351
|
+
logger
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
const ids = new Uint16Array(1);
|
|
356
|
+
var ClientHttp2SessionRef = class {
|
|
357
|
+
id = ids[0]++;
|
|
358
|
+
total = 0;
|
|
359
|
+
max = 0;
|
|
360
|
+
session;
|
|
361
|
+
refs = 0;
|
|
362
|
+
constructor(session) {
|
|
363
|
+
session.unref();
|
|
364
|
+
this.session = session;
|
|
365
|
+
}
|
|
366
|
+
retain() {
|
|
367
|
+
if (this.session.destroyed) throw new Error("@smithy/node-http-handler - cannot acquire reference to destroyed session.");
|
|
368
|
+
this.refs += 1;
|
|
369
|
+
this.total += 1;
|
|
370
|
+
this.max = Math.max(this.refs, this.max);
|
|
371
|
+
this.session.ref();
|
|
372
|
+
}
|
|
373
|
+
free() {
|
|
374
|
+
if (this.session.destroyed) return;
|
|
375
|
+
this.refs -= 1;
|
|
376
|
+
if (this.refs === 0) this.session.unref();
|
|
377
|
+
if (this.refs < 0) throw new Error("@smithy/node-http-handler - ClientHttp2Session refcount at zero, cannot decrement.");
|
|
378
|
+
}
|
|
379
|
+
deref() {
|
|
380
|
+
return this.session;
|
|
381
|
+
}
|
|
382
|
+
close() {
|
|
383
|
+
if (!this.session.closed) this.session.close();
|
|
384
|
+
}
|
|
385
|
+
destroy() {
|
|
386
|
+
this.refs = 0;
|
|
387
|
+
if (!this.session.destroyed) this.session.destroy();
|
|
388
|
+
}
|
|
389
|
+
useCount() {
|
|
390
|
+
return this.refs;
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
var NodeHttp2ConnectionPool = class {
|
|
394
|
+
sessions = [];
|
|
395
|
+
maxConcurrency = 0;
|
|
396
|
+
constructor(sessions) {
|
|
397
|
+
this.sessions = (sessions ?? []).map((session) => new ClientHttp2SessionRef(session));
|
|
398
|
+
}
|
|
399
|
+
poll() {
|
|
400
|
+
let cleanup = false;
|
|
401
|
+
for (const session of this.sessions) {
|
|
402
|
+
if (session.deref().destroyed) {
|
|
403
|
+
cleanup = true;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (!this.maxConcurrency || session.useCount() < this.maxConcurrency) return session;
|
|
407
|
+
}
|
|
408
|
+
if (cleanup) {
|
|
409
|
+
for (const session of this.sessions) if (session.deref().destroyed) this.remove(session);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
offerLast(ref) {
|
|
413
|
+
this.sessions.push(ref);
|
|
414
|
+
}
|
|
415
|
+
remove(ref) {
|
|
416
|
+
const ix = this.sessions.indexOf(ref);
|
|
417
|
+
if (ix > -1) this.sessions.splice(ix, 1);
|
|
418
|
+
}
|
|
419
|
+
[Symbol.iterator]() {
|
|
420
|
+
return this.sessions[Symbol.iterator]();
|
|
421
|
+
}
|
|
422
|
+
setMaxConcurrency(maxConcurrency) {
|
|
423
|
+
this.maxConcurrency = maxConcurrency;
|
|
424
|
+
}
|
|
425
|
+
destroy(ref) {
|
|
426
|
+
this.remove(ref);
|
|
427
|
+
ref.destroy();
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
var NodeHttp2ConnectionManager = class {
|
|
431
|
+
config;
|
|
432
|
+
connectOptions;
|
|
433
|
+
connectionPools = /* @__PURE__ */ new Map();
|
|
434
|
+
constructor(config) {
|
|
435
|
+
this.config = config;
|
|
436
|
+
if (this.config.maxConcurrency && this.config.maxConcurrency <= 0) throw new RangeError("maxConcurrency must be greater than zero.");
|
|
437
|
+
}
|
|
438
|
+
lease(requestContext, connectionConfiguration) {
|
|
439
|
+
const url = this.getUrlString(requestContext);
|
|
440
|
+
const pool = this.getPool(url);
|
|
441
|
+
if (!this.config.disableConcurrency && !connectionConfiguration.isEventStream) {
|
|
442
|
+
const available = pool.poll();
|
|
443
|
+
if (available) {
|
|
444
|
+
available.retain();
|
|
445
|
+
return available;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const ref = new ClientHttp2SessionRef(this.connect(url));
|
|
449
|
+
const session = ref.deref();
|
|
450
|
+
if (this.config.maxConcurrency) session.settings({ maxConcurrentStreams: this.config.maxConcurrency }, (err) => {
|
|
451
|
+
if (err) throw new Error("Fail to set maxConcurrentStreams to " + this.config.maxConcurrency + "when creating new session for " + requestContext.destination.toString());
|
|
452
|
+
});
|
|
453
|
+
const graceful = () => {
|
|
454
|
+
this.removeFromPoolAndClose(url, ref);
|
|
455
|
+
};
|
|
456
|
+
const ensureDestroyed = () => {
|
|
457
|
+
this.removeFromPoolAndCheckedDestroy(url, ref);
|
|
458
|
+
};
|
|
459
|
+
session.on("goaway", graceful);
|
|
460
|
+
session.on("error", ensureDestroyed);
|
|
461
|
+
session.on("frameError", ensureDestroyed);
|
|
462
|
+
session.on("close", ensureDestroyed);
|
|
463
|
+
if (connectionConfiguration.requestTimeout) session.setTimeout(connectionConfiguration.requestTimeout, ensureDestroyed);
|
|
464
|
+
pool.offerLast(ref);
|
|
465
|
+
ref.retain();
|
|
466
|
+
return ref;
|
|
467
|
+
}
|
|
468
|
+
release(_requestContext, ref) {
|
|
469
|
+
ref.free();
|
|
470
|
+
}
|
|
471
|
+
createIsolatedSession(requestContext, connectionConfiguration) {
|
|
472
|
+
const url = this.getUrlString(requestContext);
|
|
473
|
+
const ref = new ClientHttp2SessionRef(this.connect(url));
|
|
474
|
+
const session = ref.deref();
|
|
475
|
+
session.settings({ maxConcurrentStreams: 1 });
|
|
476
|
+
const ensureDestroyed = () => {
|
|
477
|
+
ref.destroy();
|
|
478
|
+
};
|
|
479
|
+
session.on("error", ensureDestroyed);
|
|
480
|
+
session.on("frameError", ensureDestroyed);
|
|
481
|
+
session.on("close", ensureDestroyed);
|
|
482
|
+
if (connectionConfiguration.requestTimeout) session.setTimeout(connectionConfiguration.requestTimeout, ensureDestroyed);
|
|
483
|
+
ref.retain();
|
|
484
|
+
return ref;
|
|
485
|
+
}
|
|
486
|
+
destroy() {
|
|
487
|
+
for (const [url, connectionPool] of this.connectionPools) {
|
|
488
|
+
for (const session of [...connectionPool]) session.destroy();
|
|
489
|
+
this.connectionPools.delete(url);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
setMaxConcurrentStreams(maxConcurrentStreams) {
|
|
493
|
+
if (maxConcurrentStreams && maxConcurrentStreams <= 0) throw new RangeError("maxConcurrentStreams must be greater than zero.");
|
|
494
|
+
this.config.maxConcurrency = maxConcurrentStreams;
|
|
495
|
+
for (const pool of this.connectionPools.values()) pool.setMaxConcurrency(maxConcurrentStreams);
|
|
496
|
+
}
|
|
497
|
+
setDisableConcurrentStreams(disableConcurrentStreams) {
|
|
498
|
+
this.config.disableConcurrency = disableConcurrentStreams;
|
|
499
|
+
}
|
|
500
|
+
setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions) {
|
|
501
|
+
this.connectOptions = nodeHttp2ConnectOptions;
|
|
502
|
+
}
|
|
503
|
+
debug() {
|
|
504
|
+
const pools = {};
|
|
505
|
+
for (const [url, pool] of this.connectionPools) {
|
|
506
|
+
const sessions = [];
|
|
507
|
+
for (const ref of pool) sessions.push({
|
|
508
|
+
id: ref.id,
|
|
509
|
+
active: ref.useCount(),
|
|
510
|
+
maxConcurrent: ref.max,
|
|
511
|
+
totalRequests: ref.total
|
|
512
|
+
});
|
|
513
|
+
pools[url] = { sessions };
|
|
514
|
+
}
|
|
515
|
+
return pools;
|
|
516
|
+
}
|
|
517
|
+
removeFromPoolAndClose(authority, ref) {
|
|
518
|
+
this.connectionPools.get(authority)?.remove(ref);
|
|
519
|
+
ref.close();
|
|
520
|
+
}
|
|
521
|
+
removeFromPoolAndCheckedDestroy(authority, ref) {
|
|
522
|
+
this.connectionPools.get(authority)?.remove(ref);
|
|
523
|
+
ref.destroy();
|
|
524
|
+
}
|
|
525
|
+
getPool(url) {
|
|
526
|
+
if (!this.connectionPools.has(url)) {
|
|
527
|
+
const pool = new NodeHttp2ConnectionPool();
|
|
528
|
+
if (this.config.maxConcurrency) pool.setMaxConcurrency(this.config.maxConcurrency);
|
|
529
|
+
this.connectionPools.set(url, pool);
|
|
530
|
+
}
|
|
531
|
+
return this.connectionPools.get(url);
|
|
532
|
+
}
|
|
533
|
+
getUrlString(request) {
|
|
534
|
+
return request.destination.toString();
|
|
535
|
+
}
|
|
536
|
+
connect(url) {
|
|
537
|
+
return this.connectOptions === void 0 ? http2.connect(url) : http2.connect(url, this.connectOptions);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
const { constants } = http2;
|
|
541
|
+
var NodeHttp2Handler = class NodeHttp2Handler {
|
|
542
|
+
config;
|
|
543
|
+
configProvider;
|
|
544
|
+
metadata = { handlerProtocol: "h2" };
|
|
545
|
+
connectionManager = new NodeHttp2ConnectionManager({});
|
|
546
|
+
static create(instanceOrOptions) {
|
|
547
|
+
if (typeof instanceOrOptions?.handle === "function") return instanceOrOptions;
|
|
548
|
+
return new NodeHttp2Handler(instanceOrOptions);
|
|
549
|
+
}
|
|
550
|
+
constructor(options) {
|
|
551
|
+
this.configProvider = new Promise((resolve, reject) => {
|
|
552
|
+
if (typeof options === "function") options().then((opts) => {
|
|
553
|
+
resolve(opts || {});
|
|
554
|
+
}).catch(reject);
|
|
555
|
+
else resolve(options || {});
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
destroy() {
|
|
559
|
+
this.connectionManager.destroy();
|
|
560
|
+
}
|
|
561
|
+
async handle(request, { abortSignal, requestTimeout, isEventStream } = {}) {
|
|
562
|
+
if (!this.config) {
|
|
563
|
+
this.config = await this.configProvider;
|
|
564
|
+
const { disableConcurrentStreams, maxConcurrentStreams, nodeHttp2ConnectOptions } = this.config;
|
|
565
|
+
this.connectionManager.setDisableConcurrentStreams(disableConcurrentStreams ?? false);
|
|
566
|
+
if (maxConcurrentStreams) this.connectionManager.setMaxConcurrentStreams(maxConcurrentStreams);
|
|
567
|
+
if (nodeHttp2ConnectOptions) this.connectionManager.setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions);
|
|
568
|
+
}
|
|
569
|
+
const { requestTimeout: configRequestTimeout, disableConcurrentStreams } = this.config;
|
|
570
|
+
const useIsolatedSession = disableConcurrentStreams || isEventStream;
|
|
571
|
+
const effectiveRequestTimeout = requestTimeout ?? configRequestTimeout;
|
|
572
|
+
return new Promise((_resolve, _reject) => {
|
|
573
|
+
let fulfilled = false;
|
|
574
|
+
let writeRequestBodyPromise = void 0;
|
|
575
|
+
const resolve = async (arg) => {
|
|
576
|
+
await writeRequestBodyPromise;
|
|
577
|
+
_resolve(arg);
|
|
578
|
+
};
|
|
579
|
+
const reject = async (arg) => {
|
|
580
|
+
await writeRequestBodyPromise;
|
|
581
|
+
_reject(arg);
|
|
582
|
+
};
|
|
583
|
+
if (abortSignal?.aborted) {
|
|
584
|
+
fulfilled = true;
|
|
585
|
+
reject(buildAbortError(abortSignal));
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const { hostname, method, port, protocol, query } = request;
|
|
589
|
+
let auth = "";
|
|
590
|
+
if (request.username != null || request.password != null) auth = `${request.username ?? ""}:${request.password ?? ""}@`;
|
|
591
|
+
const authority = `${protocol}//${auth}${hostname}${port ? `:${port}` : ""}`;
|
|
592
|
+
const requestContext = { destination: new URL(authority) };
|
|
593
|
+
const connectConfig = {
|
|
594
|
+
requestTimeout: this.config?.sessionTimeout,
|
|
595
|
+
isEventStream
|
|
596
|
+
};
|
|
597
|
+
const ref = useIsolatedSession ? this.connectionManager.createIsolatedSession(requestContext, connectConfig) : this.connectionManager.lease(requestContext, connectConfig);
|
|
598
|
+
const session = ref.deref();
|
|
599
|
+
const rejectWithDestroy = (err) => {
|
|
600
|
+
if (useIsolatedSession) ref.destroy();
|
|
601
|
+
fulfilled = true;
|
|
602
|
+
reject(err);
|
|
603
|
+
};
|
|
604
|
+
const queryString = query ? protocols.buildQueryString(query) : "";
|
|
605
|
+
let path = request.path;
|
|
606
|
+
if (queryString) path += `?${queryString}`;
|
|
607
|
+
if (request.fragment) path += `#${request.fragment}`;
|
|
608
|
+
const clientHttp2Stream = session.request({
|
|
609
|
+
...request.headers,
|
|
610
|
+
[constants.HTTP2_HEADER_PATH]: path,
|
|
611
|
+
[constants.HTTP2_HEADER_METHOD]: method
|
|
612
|
+
});
|
|
613
|
+
if (effectiveRequestTimeout) clientHttp2Stream.setTimeout(effectiveRequestTimeout, () => {
|
|
614
|
+
clientHttp2Stream.close();
|
|
615
|
+
const timeoutError = /* @__PURE__ */ new Error(`Stream timed out because of no activity for ${effectiveRequestTimeout} ms`);
|
|
616
|
+
timeoutError.name = "TimeoutError";
|
|
617
|
+
rejectWithDestroy(timeoutError);
|
|
618
|
+
});
|
|
619
|
+
if (abortSignal) {
|
|
620
|
+
const onAbort = () => {
|
|
621
|
+
clientHttp2Stream.close();
|
|
622
|
+
rejectWithDestroy(buildAbortError(abortSignal));
|
|
623
|
+
};
|
|
624
|
+
if (typeof abortSignal.addEventListener === "function") {
|
|
625
|
+
const signal = abortSignal;
|
|
626
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
627
|
+
clientHttp2Stream.once("close", () => signal.removeEventListener("abort", onAbort));
|
|
628
|
+
} else abortSignal.onabort = onAbort;
|
|
629
|
+
}
|
|
630
|
+
clientHttp2Stream.on("frameError", (type, code, id) => {
|
|
631
|
+
rejectWithDestroy(/* @__PURE__ */ new Error(`Frame type id ${type} in stream id ${id} has failed with code ${code}.`));
|
|
632
|
+
});
|
|
633
|
+
clientHttp2Stream.on("error", rejectWithDestroy);
|
|
634
|
+
clientHttp2Stream.on("aborted", () => {
|
|
635
|
+
rejectWithDestroy(/* @__PURE__ */ new Error(`HTTP/2 stream is abnormally aborted in mid-communication with result code ${clientHttp2Stream.rstCode}.`));
|
|
636
|
+
});
|
|
637
|
+
clientHttp2Stream.on("response", (headers) => {
|
|
638
|
+
const httpResponse = new protocols.HttpResponse({
|
|
639
|
+
statusCode: headers[":status"] ?? -1,
|
|
640
|
+
headers: getTransformedHeaders(headers),
|
|
641
|
+
body: clientHttp2Stream
|
|
642
|
+
});
|
|
643
|
+
fulfilled = true;
|
|
644
|
+
resolve({ response: httpResponse });
|
|
645
|
+
if (useIsolatedSession) session.close();
|
|
646
|
+
});
|
|
647
|
+
clientHttp2Stream.on("close", () => {
|
|
648
|
+
if (useIsolatedSession) ref.destroy();
|
|
649
|
+
else this.connectionManager.release(requestContext, ref);
|
|
650
|
+
if (!fulfilled) rejectWithDestroy(/* @__PURE__ */ new Error("Unexpected error: http2 request did not get a response"));
|
|
651
|
+
});
|
|
652
|
+
writeRequestBodyPromise = writeRequestBody(clientHttp2Stream, request, effectiveRequestTimeout);
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
updateHttpClientConfig(key, value) {
|
|
656
|
+
this.config = void 0;
|
|
657
|
+
this.configProvider = this.configProvider.then((config) => {
|
|
658
|
+
return {
|
|
659
|
+
...config,
|
|
660
|
+
[key]: value
|
|
661
|
+
};
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
httpHandlerConfigs() {
|
|
665
|
+
return this.config ?? {};
|
|
666
|
+
}
|
|
667
|
+
};
|
|
668
|
+
var Collector = class extends node_stream.Writable {
|
|
669
|
+
bufferedBytes = [];
|
|
670
|
+
_write(chunk, encoding, callback) {
|
|
671
|
+
this.bufferedBytes.push(chunk);
|
|
672
|
+
callback();
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
const streamCollector = (stream) => {
|
|
676
|
+
if (isReadableStreamInstance(stream)) return collectReadableStream(stream);
|
|
677
|
+
return new Promise((resolve, reject) => {
|
|
678
|
+
const collector = new Collector();
|
|
679
|
+
stream.pipe(collector);
|
|
680
|
+
stream.on("error", (err) => {
|
|
681
|
+
collector.end();
|
|
682
|
+
reject(err);
|
|
683
|
+
});
|
|
684
|
+
collector.on("error", reject);
|
|
685
|
+
collector.on("finish", function() {
|
|
686
|
+
resolve(new Uint8Array(Buffer.concat(this.bufferedBytes)));
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
};
|
|
690
|
+
const isReadableStreamInstance = (stream) => typeof ReadableStream === "function" && stream instanceof ReadableStream;
|
|
691
|
+
async function collectReadableStream(stream) {
|
|
692
|
+
const chunks = [];
|
|
693
|
+
const reader = stream.getReader();
|
|
694
|
+
let isDone = false;
|
|
695
|
+
let length = 0;
|
|
696
|
+
while (!isDone) {
|
|
697
|
+
const { done, value } = await reader.read();
|
|
698
|
+
if (value) {
|
|
699
|
+
chunks.push(value);
|
|
700
|
+
length += value.length;
|
|
701
|
+
}
|
|
702
|
+
isDone = done;
|
|
703
|
+
}
|
|
704
|
+
const collected = new Uint8Array(length);
|
|
705
|
+
let offset = 0;
|
|
706
|
+
for (const chunk of chunks) {
|
|
707
|
+
collected.set(chunk, offset);
|
|
708
|
+
offset += chunk.length;
|
|
709
|
+
}
|
|
710
|
+
return collected;
|
|
711
|
+
}
|
|
712
|
+
exports.DEFAULT_REQUEST_TIMEOUT = DEFAULT_REQUEST_TIMEOUT;
|
|
713
|
+
exports.NodeHttp2Handler = NodeHttp2Handler;
|
|
714
|
+
exports.NodeHttpHandler = NodeHttpHandler;
|
|
715
|
+
exports.streamCollector = streamCollector;
|
|
716
|
+
}));
|
|
717
|
+
//#endregion
|
|
718
|
+
export { require_dist_cjs as t };
|