mirror of
https://github.com/tvytlx/ai-agent-deep-dive.git
synced 2026-04-05 08:34:47 +08:00
Add extracted source directory and README navigation
This commit is contained in:
347
extracted-source/node_modules/@aws-sdk/middleware-websocket/dist-cjs/index.js
generated
vendored
Normal file
347
extracted-source/node_modules/@aws-sdk/middleware-websocket/dist-cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,347 @@
|
||||
'use strict';
|
||||
|
||||
var eventstreamCodec = require('@smithy/eventstream-codec');
|
||||
var utilHexEncoding = require('@smithy/util-hex-encoding');
|
||||
var protocolHttp = require('@smithy/protocol-http');
|
||||
var utilFormatUrl = require('@aws-sdk/util-format-url');
|
||||
var eventstreamSerdeBrowser = require('@smithy/eventstream-serde-browser');
|
||||
var fetchHttpHandler = require('@smithy/fetch-http-handler');
|
||||
|
||||
const getEventSigningTransformStream = (initialSignature, messageSigner, eventStreamCodec, systemClockOffsetProvider) => {
|
||||
let priorSignature = initialSignature;
|
||||
const transformer = {
|
||||
start() { },
|
||||
async transform(chunk, controller) {
|
||||
try {
|
||||
const now = new Date(Date.now() + (await systemClockOffsetProvider()));
|
||||
const dateHeader = {
|
||||
":date": { type: "timestamp", value: now },
|
||||
};
|
||||
const signedMessage = await messageSigner.sign({
|
||||
message: {
|
||||
body: chunk,
|
||||
headers: dateHeader,
|
||||
},
|
||||
priorSignature: priorSignature,
|
||||
}, {
|
||||
signingDate: now,
|
||||
});
|
||||
priorSignature = signedMessage.signature;
|
||||
const serializedSigned = eventStreamCodec.encode({
|
||||
headers: {
|
||||
...dateHeader,
|
||||
":chunk-signature": {
|
||||
type: "binary",
|
||||
value: utilHexEncoding.fromHex(signedMessage.signature),
|
||||
},
|
||||
},
|
||||
body: chunk,
|
||||
});
|
||||
controller.enqueue(serializedSigned);
|
||||
}
|
||||
catch (error) {
|
||||
controller.error(error);
|
||||
}
|
||||
},
|
||||
};
|
||||
return new TransformStream({ ...transformer });
|
||||
};
|
||||
|
||||
class EventStreamPayloadHandler {
|
||||
messageSigner;
|
||||
eventStreamCodec;
|
||||
systemClockOffsetProvider;
|
||||
constructor(options) {
|
||||
this.messageSigner = options.messageSigner;
|
||||
this.eventStreamCodec = new eventstreamCodec.EventStreamCodec(options.utf8Encoder, options.utf8Decoder);
|
||||
this.systemClockOffsetProvider = async () => options.systemClockOffset ?? 0;
|
||||
}
|
||||
async handle(next, args, context = {}) {
|
||||
const request = args.request;
|
||||
const { body: payload, headers, query } = request;
|
||||
if (!(payload instanceof ReadableStream)) {
|
||||
throw new Error("Eventstream payload must be a ReadableStream.");
|
||||
}
|
||||
const placeHolderStream = new TransformStream();
|
||||
request.body = placeHolderStream.readable;
|
||||
let result;
|
||||
try {
|
||||
result = await next(args);
|
||||
}
|
||||
catch (e) {
|
||||
request.body.cancel();
|
||||
throw e;
|
||||
}
|
||||
const match = (headers["authorization"] || "").match(/Signature=([\w]+)$/);
|
||||
const priorSignature = (match || [])[1] || (query && query["X-Amz-Signature"]) || "";
|
||||
const signingStream = getEventSigningTransformStream(priorSignature, await this.messageSigner(), this.eventStreamCodec, this.systemClockOffsetProvider);
|
||||
const signedPayload = payload.pipeThrough(signingStream);
|
||||
signedPayload.pipeThrough(placeHolderStream);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
const eventStreamPayloadHandlerProvider = (options) => new EventStreamPayloadHandler(options);
|
||||
|
||||
const injectSessionIdMiddleware = () => (next) => async (args) => {
|
||||
const requestParams = {
|
||||
...args.input,
|
||||
};
|
||||
const response = await next(args);
|
||||
const output = response.output;
|
||||
if (requestParams.SessionId && output.SessionId == null) {
|
||||
output.SessionId = requestParams.SessionId;
|
||||
}
|
||||
return response;
|
||||
};
|
||||
const injectSessionIdMiddlewareOptions = {
|
||||
step: "initialize",
|
||||
name: "injectSessionIdMiddleware",
|
||||
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
||||
override: true,
|
||||
};
|
||||
|
||||
const websocketEndpointMiddleware = (config, options) => (next) => (args) => {
|
||||
const { request } = args;
|
||||
if (protocolHttp.HttpRequest.isInstance(request) &&
|
||||
config.requestHandler.metadata?.handlerProtocol?.toLowerCase().includes("websocket")) {
|
||||
request.protocol = "wss:";
|
||||
request.method = "GET";
|
||||
request.path = `${request.path}-websocket`;
|
||||
const { headers } = request;
|
||||
delete headers["content-type"];
|
||||
delete headers["x-amz-content-sha256"];
|
||||
for (const name of Object.keys(headers)) {
|
||||
if (name.indexOf(options.headerPrefix) === 0) {
|
||||
const chunkedName = name.replace(options.headerPrefix, "");
|
||||
request.query[chunkedName] = headers[name];
|
||||
}
|
||||
}
|
||||
if (headers["x-amz-user-agent"]) {
|
||||
request.query["user-agent"] = headers["x-amz-user-agent"];
|
||||
}
|
||||
request.headers = { host: headers.host ?? request.hostname };
|
||||
}
|
||||
return next(args);
|
||||
};
|
||||
const websocketEndpointMiddlewareOptions = {
|
||||
name: "websocketEndpointMiddleware",
|
||||
tags: ["WEBSOCKET", "EVENT_STREAM"],
|
||||
relation: "after",
|
||||
toMiddleware: "eventStreamHeaderMiddleware",
|
||||
override: true,
|
||||
};
|
||||
|
||||
const getWebSocketPlugin = (config, options) => ({
|
||||
applyToStack: (clientStack) => {
|
||||
clientStack.addRelativeTo(websocketEndpointMiddleware(config, options), websocketEndpointMiddlewareOptions);
|
||||
clientStack.add(injectSessionIdMiddleware(), injectSessionIdMiddlewareOptions);
|
||||
},
|
||||
});
|
||||
|
||||
const isWebSocketRequest = (request) => request.protocol === "ws:" || request.protocol === "wss:";
|
||||
|
||||
class WebsocketSignatureV4 {
|
||||
signer;
|
||||
constructor(options) {
|
||||
this.signer = options.signer;
|
||||
}
|
||||
presign(originalRequest, options = {}) {
|
||||
return this.signer.presign(originalRequest, options);
|
||||
}
|
||||
async sign(toSign, options) {
|
||||
if (protocolHttp.HttpRequest.isInstance(toSign) && isWebSocketRequest(toSign)) {
|
||||
const signedRequest = await this.signer.presign({ ...toSign, body: "" }, {
|
||||
...options,
|
||||
expiresIn: 60,
|
||||
unsignableHeaders: new Set(Object.keys(toSign.headers).filter((header) => header !== "host")),
|
||||
});
|
||||
return {
|
||||
...signedRequest,
|
||||
body: toSign.body,
|
||||
};
|
||||
}
|
||||
else {
|
||||
return this.signer.sign(toSign, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const resolveWebSocketConfig = (input) => {
|
||||
const { signer } = input;
|
||||
return Object.assign(input, {
|
||||
signer: async (authScheme) => {
|
||||
const signerObj = await signer(authScheme);
|
||||
if (validateSigner(signerObj)) {
|
||||
return new WebsocketSignatureV4({ signer: signerObj });
|
||||
}
|
||||
throw new Error("Expected WebsocketSignatureV4 signer, please check the client constructor.");
|
||||
},
|
||||
});
|
||||
};
|
||||
const validateSigner = (signer) => !!signer;
|
||||
|
||||
const DEFAULT_WS_CONNECTION_TIMEOUT_MS = 2000;
|
||||
class WebSocketFetchHandler {
|
||||
metadata = {
|
||||
handlerProtocol: "websocket/h1.1",
|
||||
};
|
||||
config;
|
||||
configPromise;
|
||||
httpHandler;
|
||||
sockets = {};
|
||||
static create(instanceOrOptions, httpHandler = new fetchHttpHandler.FetchHttpHandler()) {
|
||||
if (typeof instanceOrOptions?.handle === "function") {
|
||||
return instanceOrOptions;
|
||||
}
|
||||
return new WebSocketFetchHandler(instanceOrOptions, httpHandler);
|
||||
}
|
||||
constructor(options, httpHandler = new fetchHttpHandler.FetchHttpHandler()) {
|
||||
this.httpHandler = httpHandler;
|
||||
if (typeof options === "function") {
|
||||
this.config = {};
|
||||
this.configPromise = options().then((opts) => (this.config = opts ?? {}));
|
||||
}
|
||||
else {
|
||||
this.config = options ?? {};
|
||||
this.configPromise = Promise.resolve(this.config);
|
||||
}
|
||||
}
|
||||
destroy() {
|
||||
for (const [key, sockets] of Object.entries(this.sockets)) {
|
||||
for (const socket of sockets) {
|
||||
socket.close(1000, `Socket closed through destroy() call`);
|
||||
}
|
||||
delete this.sockets[key];
|
||||
}
|
||||
}
|
||||
async handle(request) {
|
||||
if (!isWebSocketRequest(request)) {
|
||||
return this.httpHandler.handle(request);
|
||||
}
|
||||
const url = utilFormatUrl.formatUrl(request);
|
||||
const socket = new WebSocket(url);
|
||||
if (!this.sockets[url]) {
|
||||
this.sockets[url] = [];
|
||||
}
|
||||
this.sockets[url].push(socket);
|
||||
socket.binaryType = "arraybuffer";
|
||||
this.config = await this.configPromise;
|
||||
const { connectionTimeout = DEFAULT_WS_CONNECTION_TIMEOUT_MS } = this.config;
|
||||
await this.waitForReady(socket, connectionTimeout);
|
||||
const { body } = request;
|
||||
const bodyStream = getIterator(body);
|
||||
const asyncIterable = this.connect(socket, bodyStream);
|
||||
const outputPayload = toReadableStream(asyncIterable);
|
||||
return {
|
||||
response: new protocolHttp.HttpResponse({
|
||||
statusCode: 200,
|
||||
body: outputPayload,
|
||||
}),
|
||||
};
|
||||
}
|
||||
updateHttpClientConfig(key, value) {
|
||||
this.configPromise = this.configPromise.then((config) => {
|
||||
config[key] = value;
|
||||
return config;
|
||||
});
|
||||
}
|
||||
httpHandlerConfigs() {
|
||||
return this.config ?? {};
|
||||
}
|
||||
removeNotUsableSockets(url) {
|
||||
this.sockets[url] = (this.sockets[url] ?? []).filter((socket) => ![WebSocket.CLOSING, WebSocket.CLOSED].includes(socket.readyState));
|
||||
}
|
||||
waitForReady(socket, connectionTimeout) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
this.removeNotUsableSockets(socket.url);
|
||||
reject({
|
||||
$metadata: {
|
||||
httpStatusCode: 500,
|
||||
},
|
||||
});
|
||||
}, connectionTimeout);
|
||||
socket.onopen = () => {
|
||||
clearTimeout(timeout);
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
}
|
||||
connect(socket, data) {
|
||||
let streamError = undefined;
|
||||
let socketErrorOccurred = false;
|
||||
let reject = () => { };
|
||||
let resolve = () => { };
|
||||
socket.onmessage = (event) => {
|
||||
resolve({
|
||||
done: false,
|
||||
value: new Uint8Array(event.data),
|
||||
});
|
||||
};
|
||||
socket.onerror = (error) => {
|
||||
socketErrorOccurred = true;
|
||||
socket.close();
|
||||
reject(error);
|
||||
};
|
||||
socket.onclose = () => {
|
||||
this.removeNotUsableSockets(socket.url);
|
||||
if (socketErrorOccurred)
|
||||
return;
|
||||
if (streamError) {
|
||||
reject(streamError);
|
||||
}
|
||||
else {
|
||||
resolve({
|
||||
done: true,
|
||||
value: undefined,
|
||||
});
|
||||
}
|
||||
};
|
||||
const outputStream = {
|
||||
[Symbol.asyncIterator]: () => ({
|
||||
next: () => {
|
||||
return new Promise((_resolve, _reject) => {
|
||||
resolve = _resolve;
|
||||
reject = _reject;
|
||||
});
|
||||
},
|
||||
}),
|
||||
};
|
||||
const send = async () => {
|
||||
try {
|
||||
for await (const inputChunk of data) {
|
||||
socket.send(inputChunk);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
streamError = err;
|
||||
}
|
||||
finally {
|
||||
socket.close(1000);
|
||||
}
|
||||
};
|
||||
send();
|
||||
return outputStream;
|
||||
}
|
||||
}
|
||||
const getIterator = (stream) => {
|
||||
if (stream[Symbol.asyncIterator]) {
|
||||
return stream;
|
||||
}
|
||||
if (isReadableStream(stream)) {
|
||||
return eventstreamSerdeBrowser.readableStreamtoIterable(stream);
|
||||
}
|
||||
return {
|
||||
[Symbol.asyncIterator]: async function* () {
|
||||
yield stream;
|
||||
},
|
||||
};
|
||||
};
|
||||
const toReadableStream = (asyncIterable) => typeof ReadableStream === "function" ? eventstreamSerdeBrowser.iterableToReadableStream(asyncIterable) : asyncIterable;
|
||||
const isReadableStream = (payload) => typeof ReadableStream === "function" && payload instanceof ReadableStream;
|
||||
|
||||
exports.WebSocketFetchHandler = WebSocketFetchHandler;
|
||||
exports.eventStreamPayloadHandlerProvider = eventStreamPayloadHandlerProvider;
|
||||
exports.getWebSocketPlugin = getWebSocketPlugin;
|
||||
exports.resolveWebSocketConfig = resolveWebSocketConfig;
|
||||
216
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js
generated
vendored
Normal file
216
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
'use strict';
|
||||
|
||||
var protocolHttp = require('@smithy/protocol-http');
|
||||
var querystringBuilder = require('@smithy/querystring-builder');
|
||||
var utilBase64 = require('@smithy/util-base64');
|
||||
|
||||
function createRequest(url, requestOptions) {
|
||||
return new Request(url, requestOptions);
|
||||
}
|
||||
|
||||
function requestTimeout(timeoutInMs = 0) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (timeoutInMs) {
|
||||
setTimeout(() => {
|
||||
const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
|
||||
timeoutError.name = "TimeoutError";
|
||||
reject(timeoutError);
|
||||
}, timeoutInMs);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const keepAliveSupport = {
|
||||
supported: undefined,
|
||||
};
|
||||
class FetchHttpHandler {
|
||||
config;
|
||||
configProvider;
|
||||
static create(instanceOrOptions) {
|
||||
if (typeof instanceOrOptions?.handle === "function") {
|
||||
return instanceOrOptions;
|
||||
}
|
||||
return new FetchHttpHandler(instanceOrOptions);
|
||||
}
|
||||
constructor(options) {
|
||||
if (typeof options === "function") {
|
||||
this.configProvider = options().then((opts) => opts || {});
|
||||
}
|
||||
else {
|
||||
this.config = options ?? {};
|
||||
this.configProvider = Promise.resolve(this.config);
|
||||
}
|
||||
if (keepAliveSupport.supported === undefined) {
|
||||
keepAliveSupport.supported = Boolean(typeof Request !== "undefined" && "keepalive" in createRequest("https://[::1]"));
|
||||
}
|
||||
}
|
||||
destroy() {
|
||||
}
|
||||
async handle(request, { abortSignal, requestTimeout: requestTimeout$1 } = {}) {
|
||||
if (!this.config) {
|
||||
this.config = await this.configProvider;
|
||||
}
|
||||
const requestTimeoutInMs = requestTimeout$1 ?? this.config.requestTimeout;
|
||||
const keepAlive = this.config.keepAlive === true;
|
||||
const credentials = this.config.credentials;
|
||||
if (abortSignal?.aborted) {
|
||||
const abortError = new Error("Request aborted");
|
||||
abortError.name = "AbortError";
|
||||
return Promise.reject(abortError);
|
||||
}
|
||||
let path = request.path;
|
||||
const queryString = querystringBuilder.buildQueryString(request.query || {});
|
||||
if (queryString) {
|
||||
path += `?${queryString}`;
|
||||
}
|
||||
if (request.fragment) {
|
||||
path += `#${request.fragment}`;
|
||||
}
|
||||
let auth = "";
|
||||
if (request.username != null || request.password != null) {
|
||||
const username = request.username ?? "";
|
||||
const password = request.password ?? "";
|
||||
auth = `${username}:${password}@`;
|
||||
}
|
||||
const { port, method } = request;
|
||||
const url = `${request.protocol}//${auth}${request.hostname}${port ? `:${port}` : ""}${path}`;
|
||||
const body = method === "GET" || method === "HEAD" ? undefined : request.body;
|
||||
const requestOptions = {
|
||||
body,
|
||||
headers: new Headers(request.headers),
|
||||
method: method,
|
||||
credentials,
|
||||
};
|
||||
if (this.config?.cache) {
|
||||
requestOptions.cache = this.config.cache;
|
||||
}
|
||||
if (body) {
|
||||
requestOptions.duplex = "half";
|
||||
}
|
||||
if (typeof AbortController !== "undefined") {
|
||||
requestOptions.signal = abortSignal;
|
||||
}
|
||||
if (keepAliveSupport.supported) {
|
||||
requestOptions.keepalive = keepAlive;
|
||||
}
|
||||
if (typeof this.config.requestInit === "function") {
|
||||
Object.assign(requestOptions, this.config.requestInit(request));
|
||||
}
|
||||
let removeSignalEventListener = () => { };
|
||||
const fetchRequest = createRequest(url, requestOptions);
|
||||
const raceOfPromises = [
|
||||
fetch(fetchRequest).then((response) => {
|
||||
const fetchHeaders = response.headers;
|
||||
const transformedHeaders = {};
|
||||
for (const pair of fetchHeaders.entries()) {
|
||||
transformedHeaders[pair[0]] = pair[1];
|
||||
}
|
||||
const hasReadableStream = response.body != undefined;
|
||||
if (!hasReadableStream) {
|
||||
return response.blob().then((body) => ({
|
||||
response: new protocolHttp.HttpResponse({
|
||||
headers: transformedHeaders,
|
||||
reason: response.statusText,
|
||||
statusCode: response.status,
|
||||
body,
|
||||
}),
|
||||
}));
|
||||
}
|
||||
return {
|
||||
response: new protocolHttp.HttpResponse({
|
||||
headers: transformedHeaders,
|
||||
reason: response.statusText,
|
||||
statusCode: response.status,
|
||||
body: response.body,
|
||||
}),
|
||||
};
|
||||
}),
|
||||
requestTimeout(requestTimeoutInMs),
|
||||
];
|
||||
if (abortSignal) {
|
||||
raceOfPromises.push(new Promise((resolve, reject) => {
|
||||
const onAbort = () => {
|
||||
const abortError = new Error("Request aborted");
|
||||
abortError.name = "AbortError";
|
||||
reject(abortError);
|
||||
};
|
||||
if (typeof abortSignal.addEventListener === "function") {
|
||||
const signal = abortSignal;
|
||||
signal.addEventListener("abort", onAbort, { once: true });
|
||||
removeSignalEventListener = () => signal.removeEventListener("abort", onAbort);
|
||||
}
|
||||
else {
|
||||
abortSignal.onabort = onAbort;
|
||||
}
|
||||
}));
|
||||
}
|
||||
return Promise.race(raceOfPromises).finally(removeSignalEventListener);
|
||||
}
|
||||
updateHttpClientConfig(key, value) {
|
||||
this.config = undefined;
|
||||
this.configProvider = this.configProvider.then((config) => {
|
||||
config[key] = value;
|
||||
return config;
|
||||
});
|
||||
}
|
||||
httpHandlerConfigs() {
|
||||
return this.config ?? {};
|
||||
}
|
||||
}
|
||||
|
||||
const streamCollector = async (stream) => {
|
||||
if ((typeof Blob === "function" && stream instanceof Blob) || stream.constructor?.name === "Blob") {
|
||||
if (Blob.prototype.arrayBuffer !== undefined) {
|
||||
return new Uint8Array(await stream.arrayBuffer());
|
||||
}
|
||||
return collectBlob(stream);
|
||||
}
|
||||
return collectStream(stream);
|
||||
};
|
||||
async function collectBlob(blob) {
|
||||
const base64 = await readToBase64(blob);
|
||||
const arrayBuffer = utilBase64.fromBase64(base64);
|
||||
return new Uint8Array(arrayBuffer);
|
||||
}
|
||||
async function collectStream(stream) {
|
||||
const chunks = [];
|
||||
const reader = stream.getReader();
|
||||
let isDone = false;
|
||||
let length = 0;
|
||||
while (!isDone) {
|
||||
const { done, value } = await reader.read();
|
||||
if (value) {
|
||||
chunks.push(value);
|
||||
length += value.length;
|
||||
}
|
||||
isDone = done;
|
||||
}
|
||||
const collected = new Uint8Array(length);
|
||||
let offset = 0;
|
||||
for (const chunk of chunks) {
|
||||
collected.set(chunk, offset);
|
||||
offset += chunk.length;
|
||||
}
|
||||
return collected;
|
||||
}
|
||||
function readToBase64(blob) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
if (reader.readyState !== 2) {
|
||||
return reject(new Error("Reader aborted too early"));
|
||||
}
|
||||
const result = (reader.result ?? "");
|
||||
const commaIndex = result.indexOf(",");
|
||||
const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
|
||||
resolve(result.substring(dataOffset));
|
||||
};
|
||||
reader.onabort = () => reject(new Error("Read aborted"));
|
||||
reader.onerror = () => reject(reader.error);
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
|
||||
exports.FetchHttpHandler = FetchHttpHandler;
|
||||
exports.keepAliveSupport = keepAliveSupport;
|
||||
exports.streamCollector = streamCollector;
|
||||
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var utilUriEscape = require('@smithy/util-uri-escape');
|
||||
|
||||
function buildQueryString(query) {
|
||||
const parts = [];
|
||||
for (let key of Object.keys(query).sort()) {
|
||||
const value = query[key];
|
||||
key = utilUriEscape.escapeUri(key);
|
||||
if (Array.isArray(value)) {
|
||||
for (let i = 0, iLen = value.length; i < iLen; i++) {
|
||||
parts.push(`${key}=${utilUriEscape.escapeUri(value[i])}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let qsEntry = key;
|
||||
if (value || typeof value === "string") {
|
||||
qsEntry += `=${utilUriEscape.escapeUri(value)}`;
|
||||
}
|
||||
parts.push(qsEntry);
|
||||
}
|
||||
}
|
||||
return parts.join("&");
|
||||
}
|
||||
|
||||
exports.buildQueryString = buildQueryString;
|
||||
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const escapeUri = (uri) => encodeURIComponent(uri).replace(/[!'()*]/g, hexEncode);
|
||||
const hexEncode = (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`;
|
||||
|
||||
const escapeUriPath = (uri) => uri.split("/").map(escapeUri).join("/");
|
||||
|
||||
exports.escapeUri = escapeUri;
|
||||
exports.escapeUriPath = escapeUriPath;
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.fromBase64 = void 0;
|
||||
const util_buffer_from_1 = require("@smithy/util-buffer-from");
|
||||
const BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/;
|
||||
const fromBase64 = (input) => {
|
||||
if ((input.length * 3) % 4 !== 0) {
|
||||
throw new TypeError(`Incorrect padding on base64 string.`);
|
||||
}
|
||||
if (!BASE64_REGEX.exec(input)) {
|
||||
throw new TypeError(`Invalid base64 string.`);
|
||||
}
|
||||
const buffer = (0, util_buffer_from_1.fromString)(input, "base64");
|
||||
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
||||
};
|
||||
exports.fromBase64 = fromBase64;
|
||||
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var fromBase64 = require('./fromBase64');
|
||||
var toBase64 = require('./toBase64');
|
||||
|
||||
|
||||
|
||||
Object.keys(fromBase64).forEach(function (k) {
|
||||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
||||
enumerable: true,
|
||||
get: function () { return fromBase64[k]; }
|
||||
});
|
||||
});
|
||||
Object.keys(toBase64).forEach(function (k) {
|
||||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
||||
enumerable: true,
|
||||
get: function () { return toBase64[k]; }
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.toBase64 = void 0;
|
||||
const util_buffer_from_1 = require("@smithy/util-buffer-from");
|
||||
const util_utf8_1 = require("@smithy/util-utf8");
|
||||
const toBase64 = (_input) => {
|
||||
let input;
|
||||
if (typeof _input === "string") {
|
||||
input = (0, util_utf8_1.fromUtf8)(_input);
|
||||
}
|
||||
else {
|
||||
input = _input;
|
||||
}
|
||||
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
|
||||
throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");
|
||||
}
|
||||
return (0, util_buffer_from_1.fromArrayBuffer)(input.buffer, input.byteOffset, input.byteLength).toString("base64");
|
||||
};
|
||||
exports.toBase64 = toBase64;
|
||||
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var isArrayBuffer = require('@smithy/is-array-buffer');
|
||||
var buffer = require('buffer');
|
||||
|
||||
const fromArrayBuffer = (input, offset = 0, length = input.byteLength - offset) => {
|
||||
if (!isArrayBuffer.isArrayBuffer(input)) {
|
||||
throw new TypeError(`The "input" argument must be ArrayBuffer. Received type ${typeof input} (${input})`);
|
||||
}
|
||||
return buffer.Buffer.from(input, offset, length);
|
||||
};
|
||||
const fromString = (input, encoding) => {
|
||||
if (typeof input !== "string") {
|
||||
throw new TypeError(`The "input" argument must be of type string. Received type ${typeof input} (${input})`);
|
||||
}
|
||||
return encoding ? buffer.Buffer.from(input, encoding) : buffer.Buffer.from(input);
|
||||
};
|
||||
|
||||
exports.fromArrayBuffer = fromArrayBuffer;
|
||||
exports.fromString = fromString;
|
||||
@@ -0,0 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const isArrayBuffer = (arg) => (typeof ArrayBuffer === "function" && arg instanceof ArrayBuffer) ||
|
||||
Object.prototype.toString.call(arg) === "[object ArrayBuffer]";
|
||||
|
||||
exports.isArrayBuffer = isArrayBuffer;
|
||||
169
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/protocol-http/dist-cjs/index.js
generated
vendored
Normal file
169
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/protocol-http/dist-cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
'use strict';
|
||||
|
||||
var types = require('@smithy/types');
|
||||
|
||||
const getHttpHandlerExtensionConfiguration = (runtimeConfig) => {
|
||||
return {
|
||||
setHttpHandler(handler) {
|
||||
runtimeConfig.httpHandler = handler;
|
||||
},
|
||||
httpHandler() {
|
||||
return runtimeConfig.httpHandler;
|
||||
},
|
||||
updateHttpClientConfig(key, value) {
|
||||
runtimeConfig.httpHandler?.updateHttpClientConfig(key, value);
|
||||
},
|
||||
httpHandlerConfigs() {
|
||||
return runtimeConfig.httpHandler.httpHandlerConfigs();
|
||||
},
|
||||
};
|
||||
};
|
||||
const resolveHttpHandlerRuntimeConfig = (httpHandlerExtensionConfiguration) => {
|
||||
return {
|
||||
httpHandler: httpHandlerExtensionConfiguration.httpHandler(),
|
||||
};
|
||||
};
|
||||
|
||||
class Field {
|
||||
name;
|
||||
kind;
|
||||
values;
|
||||
constructor({ name, kind = types.FieldPosition.HEADER, values = [] }) {
|
||||
this.name = name;
|
||||
this.kind = kind;
|
||||
this.values = values;
|
||||
}
|
||||
add(value) {
|
||||
this.values.push(value);
|
||||
}
|
||||
set(values) {
|
||||
this.values = values;
|
||||
}
|
||||
remove(value) {
|
||||
this.values = this.values.filter((v) => v !== value);
|
||||
}
|
||||
toString() {
|
||||
return this.values.map((v) => (v.includes(",") || v.includes(" ") ? `"${v}"` : v)).join(", ");
|
||||
}
|
||||
get() {
|
||||
return this.values;
|
||||
}
|
||||
}
|
||||
|
||||
class Fields {
|
||||
entries = {};
|
||||
encoding;
|
||||
constructor({ fields = [], encoding = "utf-8" }) {
|
||||
fields.forEach(this.setField.bind(this));
|
||||
this.encoding = encoding;
|
||||
}
|
||||
setField(field) {
|
||||
this.entries[field.name.toLowerCase()] = field;
|
||||
}
|
||||
getField(name) {
|
||||
return this.entries[name.toLowerCase()];
|
||||
}
|
||||
removeField(name) {
|
||||
delete this.entries[name.toLowerCase()];
|
||||
}
|
||||
getByType(kind) {
|
||||
return Object.values(this.entries).filter((field) => field.kind === kind);
|
||||
}
|
||||
}
|
||||
|
||||
class HttpRequest {
|
||||
method;
|
||||
protocol;
|
||||
hostname;
|
||||
port;
|
||||
path;
|
||||
query;
|
||||
headers;
|
||||
username;
|
||||
password;
|
||||
fragment;
|
||||
body;
|
||||
constructor(options) {
|
||||
this.method = options.method || "GET";
|
||||
this.hostname = options.hostname || "localhost";
|
||||
this.port = options.port;
|
||||
this.query = options.query || {};
|
||||
this.headers = options.headers || {};
|
||||
this.body = options.body;
|
||||
this.protocol = options.protocol
|
||||
? options.protocol.slice(-1) !== ":"
|
||||
? `${options.protocol}:`
|
||||
: options.protocol
|
||||
: "https:";
|
||||
this.path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/";
|
||||
this.username = options.username;
|
||||
this.password = options.password;
|
||||
this.fragment = options.fragment;
|
||||
}
|
||||
static clone(request) {
|
||||
const cloned = new HttpRequest({
|
||||
...request,
|
||||
headers: { ...request.headers },
|
||||
});
|
||||
if (cloned.query) {
|
||||
cloned.query = cloneQuery(cloned.query);
|
||||
}
|
||||
return cloned;
|
||||
}
|
||||
static isInstance(request) {
|
||||
if (!request) {
|
||||
return false;
|
||||
}
|
||||
const req = request;
|
||||
return ("method" in req &&
|
||||
"protocol" in req &&
|
||||
"hostname" in req &&
|
||||
"path" in req &&
|
||||
typeof req["query"] === "object" &&
|
||||
typeof req["headers"] === "object");
|
||||
}
|
||||
clone() {
|
||||
return HttpRequest.clone(this);
|
||||
}
|
||||
}
|
||||
function cloneQuery(query) {
|
||||
return Object.keys(query).reduce((carry, paramName) => {
|
||||
const param = query[paramName];
|
||||
return {
|
||||
...carry,
|
||||
[paramName]: Array.isArray(param) ? [...param] : param,
|
||||
};
|
||||
}, {});
|
||||
}
|
||||
|
||||
class HttpResponse {
|
||||
statusCode;
|
||||
reason;
|
||||
headers;
|
||||
body;
|
||||
constructor(options) {
|
||||
this.statusCode = options.statusCode;
|
||||
this.reason = options.reason;
|
||||
this.headers = options.headers || {};
|
||||
this.body = options.body;
|
||||
}
|
||||
static isInstance(response) {
|
||||
if (!response)
|
||||
return false;
|
||||
const resp = response;
|
||||
return typeof resp.statusCode === "number" && typeof resp.headers === "object";
|
||||
}
|
||||
}
|
||||
|
||||
function isValidHostname(hostname) {
|
||||
const hostPattern = /^[a-z0-9][a-z0-9\.\-]*[a-z0-9]$/;
|
||||
return hostPattern.test(hostname);
|
||||
}
|
||||
|
||||
exports.Field = Field;
|
||||
exports.Fields = Fields;
|
||||
exports.HttpRequest = HttpRequest;
|
||||
exports.HttpResponse = HttpResponse;
|
||||
exports.getHttpHandlerExtensionConfiguration = getHttpHandlerExtensionConfiguration;
|
||||
exports.isValidHostname = isValidHostname;
|
||||
exports.resolveHttpHandlerRuntimeConfig = resolveHttpHandlerRuntimeConfig;
|
||||
91
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/types/dist-cjs/index.js
generated
vendored
Normal file
91
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/types/dist-cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
'use strict';
|
||||
|
||||
exports.HttpAuthLocation = void 0;
|
||||
(function (HttpAuthLocation) {
|
||||
HttpAuthLocation["HEADER"] = "header";
|
||||
HttpAuthLocation["QUERY"] = "query";
|
||||
})(exports.HttpAuthLocation || (exports.HttpAuthLocation = {}));
|
||||
|
||||
exports.HttpApiKeyAuthLocation = void 0;
|
||||
(function (HttpApiKeyAuthLocation) {
|
||||
HttpApiKeyAuthLocation["HEADER"] = "header";
|
||||
HttpApiKeyAuthLocation["QUERY"] = "query";
|
||||
})(exports.HttpApiKeyAuthLocation || (exports.HttpApiKeyAuthLocation = {}));
|
||||
|
||||
exports.EndpointURLScheme = void 0;
|
||||
(function (EndpointURLScheme) {
|
||||
EndpointURLScheme["HTTP"] = "http";
|
||||
EndpointURLScheme["HTTPS"] = "https";
|
||||
})(exports.EndpointURLScheme || (exports.EndpointURLScheme = {}));
|
||||
|
||||
exports.AlgorithmId = void 0;
|
||||
(function (AlgorithmId) {
|
||||
AlgorithmId["MD5"] = "md5";
|
||||
AlgorithmId["CRC32"] = "crc32";
|
||||
AlgorithmId["CRC32C"] = "crc32c";
|
||||
AlgorithmId["SHA1"] = "sha1";
|
||||
AlgorithmId["SHA256"] = "sha256";
|
||||
})(exports.AlgorithmId || (exports.AlgorithmId = {}));
|
||||
const getChecksumConfiguration = (runtimeConfig) => {
|
||||
const checksumAlgorithms = [];
|
||||
if (runtimeConfig.sha256 !== undefined) {
|
||||
checksumAlgorithms.push({
|
||||
algorithmId: () => exports.AlgorithmId.SHA256,
|
||||
checksumConstructor: () => runtimeConfig.sha256,
|
||||
});
|
||||
}
|
||||
if (runtimeConfig.md5 != undefined) {
|
||||
checksumAlgorithms.push({
|
||||
algorithmId: () => exports.AlgorithmId.MD5,
|
||||
checksumConstructor: () => runtimeConfig.md5,
|
||||
});
|
||||
}
|
||||
return {
|
||||
addChecksumAlgorithm(algo) {
|
||||
checksumAlgorithms.push(algo);
|
||||
},
|
||||
checksumAlgorithms() {
|
||||
return checksumAlgorithms;
|
||||
},
|
||||
};
|
||||
};
|
||||
const resolveChecksumRuntimeConfig = (clientConfig) => {
|
||||
const runtimeConfig = {};
|
||||
clientConfig.checksumAlgorithms().forEach((checksumAlgorithm) => {
|
||||
runtimeConfig[checksumAlgorithm.algorithmId()] = checksumAlgorithm.checksumConstructor();
|
||||
});
|
||||
return runtimeConfig;
|
||||
};
|
||||
|
||||
const getDefaultClientConfiguration = (runtimeConfig) => {
|
||||
return getChecksumConfiguration(runtimeConfig);
|
||||
};
|
||||
const resolveDefaultRuntimeConfig = (config) => {
|
||||
return resolveChecksumRuntimeConfig(config);
|
||||
};
|
||||
|
||||
exports.FieldPosition = void 0;
|
||||
(function (FieldPosition) {
|
||||
FieldPosition[FieldPosition["HEADER"] = 0] = "HEADER";
|
||||
FieldPosition[FieldPosition["TRAILER"] = 1] = "TRAILER";
|
||||
})(exports.FieldPosition || (exports.FieldPosition = {}));
|
||||
|
||||
const SMITHY_CONTEXT_KEY = "__smithy_context";
|
||||
|
||||
exports.IniSectionType = void 0;
|
||||
(function (IniSectionType) {
|
||||
IniSectionType["PROFILE"] = "profile";
|
||||
IniSectionType["SSO_SESSION"] = "sso-session";
|
||||
IniSectionType["SERVICES"] = "services";
|
||||
})(exports.IniSectionType || (exports.IniSectionType = {}));
|
||||
|
||||
exports.RequestHandlerProtocol = void 0;
|
||||
(function (RequestHandlerProtocol) {
|
||||
RequestHandlerProtocol["HTTP_0_9"] = "http/0.9";
|
||||
RequestHandlerProtocol["HTTP_1_0"] = "http/1.0";
|
||||
RequestHandlerProtocol["TDS_8_0"] = "tds/8.0";
|
||||
})(exports.RequestHandlerProtocol || (exports.RequestHandlerProtocol = {}));
|
||||
|
||||
exports.SMITHY_CONTEXT_KEY = SMITHY_CONTEXT_KEY;
|
||||
exports.getDefaultClientConfiguration = getDefaultClientConfiguration;
|
||||
exports.resolveDefaultRuntimeConfig = resolveDefaultRuntimeConfig;
|
||||
38
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/util-hex-encoding/dist-cjs/index.js
generated
vendored
Normal file
38
extracted-source/node_modules/@aws-sdk/middleware-websocket/node_modules/@smithy/util-hex-encoding/dist-cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const SHORT_TO_HEX = {};
|
||||
const HEX_TO_SHORT = {};
|
||||
for (let i = 0; i < 256; i++) {
|
||||
let encodedByte = i.toString(16).toLowerCase();
|
||||
if (encodedByte.length === 1) {
|
||||
encodedByte = `0${encodedByte}`;
|
||||
}
|
||||
SHORT_TO_HEX[i] = encodedByte;
|
||||
HEX_TO_SHORT[encodedByte] = i;
|
||||
}
|
||||
function fromHex(encoded) {
|
||||
if (encoded.length % 2 !== 0) {
|
||||
throw new Error("Hex encoded strings must have an even number length");
|
||||
}
|
||||
const out = new Uint8Array(encoded.length / 2);
|
||||
for (let i = 0; i < encoded.length; i += 2) {
|
||||
const encodedByte = encoded.slice(i, i + 2).toLowerCase();
|
||||
if (encodedByte in HEX_TO_SHORT) {
|
||||
out[i / 2] = HEX_TO_SHORT[encodedByte];
|
||||
}
|
||||
else {
|
||||
throw new Error(`Cannot decode unrecognized sequence ${encodedByte} as hexadecimal`);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function toHex(bytes) {
|
||||
let out = "";
|
||||
for (let i = 0; i < bytes.byteLength; i++) {
|
||||
out += SHORT_TO_HEX[bytes[i]];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
exports.fromHex = fromHex;
|
||||
exports.toHex = toHex;
|
||||
Reference in New Issue
Block a user