Backend half
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
# `@aws-sdk/core`
|
||||
|
||||
This package provides common or core functionality to the AWS SDK for JavaScript (v3).
|
||||
|
||||
You do not need to explicitly install this package, since it will be transitively installed by AWS SDK clients.
|
||||
|
||||
## `@aws-sdk/core` submodules
|
||||
|
||||
Core submodules are organized for distribution via the `package.json` `exports` field.
|
||||
|
||||
`exports` is supported by default by the latest Node.js, webpack, and esbuild. For react-native, it can be
|
||||
enabled via instructions found at [reactnative.dev/blog](https://reactnative.dev/blog/2023/06/21/package-exports-support).
|
||||
|
||||
Think of `@aws-sdk/core` as a mono-package within the monorepo.
|
||||
It preserves the benefits of modularization, for example to optimize Node.js initialization speed,
|
||||
while making it easier to have a consistent version of core dependencies, reducing package sprawl when
|
||||
installing an SDK client.
|
||||
|
||||
### Guide for submodules
|
||||
|
||||
- Each `index.ts` file corresponding to the pattern `./src/submodules/<MODULE_NAME>/index.ts` will be
|
||||
published as a separate `dist-cjs` bundled submodule index using the `Inliner.js` build script.
|
||||
- create a folder as `./src/submodules/<SUBMODULE>` including an `index.ts` file and a `README.md` file.
|
||||
- The linter will throw an error on missing submodule metadata in `package.json` and the various `tsconfig.json` files, but it will automatically fix them if possible.
|
||||
- a submodule is equivalent to a standalone `@aws-sdk/<pkg>` package in that importing it in Node.js will resolve a separate bundle.
|
||||
- submodules may not relatively import files from other submodules. Instead, directly use the `@scope/pkg/submodule` name as the import.
|
||||
- The linter will check for this and throw an error.
|
||||
- To the extent possible, correctly declaring submodule metadata is validated by the linter in `@aws-sdk/core`.
|
||||
The linter runs during `yarn build` and also as `yarn lint`.
|
||||
|
||||
### When should I create an `@aws-sdk/core/submodule` vs. `@aws-sdk/new-package`?
|
||||
|
||||
Keep in mind that the core package is installed by all AWS SDK clients.
|
||||
|
||||
If the component functionality is upstream of multiple clients, it is
|
||||
a good candidate for a core submodule. For example, XML serialization.
|
||||
|
||||
If the component's functionality is downstream of a client, for example S3 pre-signing,
|
||||
it should be a standalone package with potentially a peer or runtime dependency on an AWS SDK client.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Do not edit:
|
||||
* This is a compatibility redirect for contexts that do not understand package.json exports field.
|
||||
*/
|
||||
declare module "@aws-sdk/core/account-id-endpoint" {
|
||||
export * from "@aws-sdk/core/dist-types/submodules/account-id-endpoint/index.d";
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
|
||||
/**
|
||||
* Do not edit:
|
||||
* This is a compatibility redirect for contexts that do not understand package.json exports field.
|
||||
*/
|
||||
module.exports = require("./dist-cjs/submodules/account-id-endpoint/index.js");
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Do not edit:
|
||||
* This is a compatibility redirect for contexts that do not understand package.json exports field.
|
||||
*/
|
||||
declare module "@aws-sdk/core/client" {
|
||||
export * from "@aws-sdk/core/dist-types/submodules/client/index.d";
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Do not edit:
|
||||
* This is a compatibility redirect for contexts that do not understand package.json exports field.
|
||||
*/
|
||||
module.exports = require("./dist-cjs/submodules/client/index.js");
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const tslib_1 = require("tslib");
|
||||
tslib_1.__exportStar(require("./submodules/client/index"), exports);
|
||||
tslib_1.__exportStar(require("./submodules/httpAuthSchemes/index"), exports);
|
||||
tslib_1.__exportStar(require("./submodules/protocols/index"), exports);
|
||||
Generated
Vendored
+95
@@ -0,0 +1,95 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/submodules/account-id-endpoint/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
ACCOUNT_ID_ENDPOINT_MODE_VALUES: () => ACCOUNT_ID_ENDPOINT_MODE_VALUES,
|
||||
CONFIG_ACCOUNT_ID_ENDPOINT_MODE: () => CONFIG_ACCOUNT_ID_ENDPOINT_MODE,
|
||||
DEFAULT_ACCOUNT_ID_ENDPOINT_MODE: () => DEFAULT_ACCOUNT_ID_ENDPOINT_MODE,
|
||||
ENV_ACCOUNT_ID_ENDPOINT_MODE: () => ENV_ACCOUNT_ID_ENDPOINT_MODE,
|
||||
NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS: () => NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS,
|
||||
resolveAccountIdEndpointModeConfig: () => resolveAccountIdEndpointModeConfig,
|
||||
validateAccountIdEndpointMode: () => validateAccountIdEndpointMode
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
|
||||
// src/submodules/account-id-endpoint/AccountIdEndpointModeConfigResolver.ts
|
||||
var import_util_middleware = require("@smithy/util-middleware");
|
||||
|
||||
// src/submodules/account-id-endpoint/AccountIdEndpointModeConstants.ts
|
||||
var DEFAULT_ACCOUNT_ID_ENDPOINT_MODE = "preferred";
|
||||
var ACCOUNT_ID_ENDPOINT_MODE_VALUES = ["disabled", "preferred", "required"];
|
||||
function validateAccountIdEndpointMode(value) {
|
||||
return ACCOUNT_ID_ENDPOINT_MODE_VALUES.includes(value);
|
||||
}
|
||||
__name(validateAccountIdEndpointMode, "validateAccountIdEndpointMode");
|
||||
|
||||
// src/submodules/account-id-endpoint/AccountIdEndpointModeConfigResolver.ts
|
||||
var resolveAccountIdEndpointModeConfig = /* @__PURE__ */ __name((input) => {
|
||||
const { accountIdEndpointMode } = input;
|
||||
const accountIdEndpointModeProvider = (0, import_util_middleware.normalizeProvider)(accountIdEndpointMode ?? DEFAULT_ACCOUNT_ID_ENDPOINT_MODE);
|
||||
return Object.assign(input, {
|
||||
accountIdEndpointMode: /* @__PURE__ */ __name(async () => {
|
||||
const accIdMode = await accountIdEndpointModeProvider();
|
||||
if (!validateAccountIdEndpointMode(accIdMode)) {
|
||||
throw new Error(
|
||||
`Invalid value for accountIdEndpointMode: ${accIdMode}. Valid values are: "required", "preferred", "disabled".`
|
||||
);
|
||||
}
|
||||
return accIdMode;
|
||||
}, "accountIdEndpointMode")
|
||||
});
|
||||
}, "resolveAccountIdEndpointModeConfig");
|
||||
|
||||
// src/submodules/account-id-endpoint/NodeAccountIdEndpointModeConfigOptions.ts
|
||||
var err = "Invalid AccountIdEndpointMode value";
|
||||
var _throw = /* @__PURE__ */ __name((message) => {
|
||||
throw new Error(message);
|
||||
}, "_throw");
|
||||
var ENV_ACCOUNT_ID_ENDPOINT_MODE = "AWS_ACCOUNT_ID_ENDPOINT_MODE";
|
||||
var CONFIG_ACCOUNT_ID_ENDPOINT_MODE = "account_id_endpoint_mode";
|
||||
var NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS = {
|
||||
environmentVariableSelector: /* @__PURE__ */ __name((env) => {
|
||||
const value = env[ENV_ACCOUNT_ID_ENDPOINT_MODE];
|
||||
if (value && !validateAccountIdEndpointMode(value)) {
|
||||
_throw(err);
|
||||
}
|
||||
return value;
|
||||
}, "environmentVariableSelector"),
|
||||
configFileSelector: /* @__PURE__ */ __name((profile) => {
|
||||
const value = profile[CONFIG_ACCOUNT_ID_ENDPOINT_MODE];
|
||||
if (value && !validateAccountIdEndpointMode(value)) {
|
||||
_throw(err);
|
||||
}
|
||||
return value;
|
||||
}, "configFileSelector"),
|
||||
default: DEFAULT_ACCOUNT_ID_ENDPOINT_MODE
|
||||
};
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
ACCOUNT_ID_ENDPOINT_MODE_VALUES,
|
||||
CONFIG_ACCOUNT_ID_ENDPOINT_MODE,
|
||||
DEFAULT_ACCOUNT_ID_ENDPOINT_MODE,
|
||||
ENV_ACCOUNT_ID_ENDPOINT_MODE,
|
||||
NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS,
|
||||
resolveAccountIdEndpointModeConfig,
|
||||
validateAccountIdEndpointMode
|
||||
});
|
||||
Generated
Vendored
+90
@@ -0,0 +1,90 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/submodules/client/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
emitWarningIfUnsupportedVersion: () => emitWarningIfUnsupportedVersion,
|
||||
setCredentialFeature: () => setCredentialFeature,
|
||||
setFeature: () => setFeature,
|
||||
setTokenFeature: () => setTokenFeature,
|
||||
state: () => state
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
|
||||
// src/submodules/client/emitWarningIfUnsupportedVersion.ts
|
||||
var state = {
|
||||
warningEmitted: false
|
||||
};
|
||||
var emitWarningIfUnsupportedVersion = /* @__PURE__ */ __name((version) => {
|
||||
if (version && !state.warningEmitted && parseInt(version.substring(1, version.indexOf("."))) < 18) {
|
||||
state.warningEmitted = true;
|
||||
process.emitWarning(
|
||||
`NodeDeprecationWarning: The AWS SDK for JavaScript (v3) will
|
||||
no longer support Node.js 16.x on January 6, 2025.
|
||||
|
||||
To continue receiving updates to AWS services, bug fixes, and security
|
||||
updates please upgrade to a supported Node.js LTS version.
|
||||
|
||||
More information can be found at: https://a.co/74kJMmI`
|
||||
);
|
||||
}
|
||||
}, "emitWarningIfUnsupportedVersion");
|
||||
|
||||
// src/submodules/client/setCredentialFeature.ts
|
||||
function setCredentialFeature(credentials, feature, value) {
|
||||
if (!credentials.$source) {
|
||||
credentials.$source = {};
|
||||
}
|
||||
credentials.$source[feature] = value;
|
||||
return credentials;
|
||||
}
|
||||
__name(setCredentialFeature, "setCredentialFeature");
|
||||
|
||||
// src/submodules/client/setFeature.ts
|
||||
function setFeature(context, feature, value) {
|
||||
if (!context.__aws_sdk_context) {
|
||||
context.__aws_sdk_context = {
|
||||
features: {}
|
||||
};
|
||||
} else if (!context.__aws_sdk_context.features) {
|
||||
context.__aws_sdk_context.features = {};
|
||||
}
|
||||
context.__aws_sdk_context.features[feature] = value;
|
||||
}
|
||||
__name(setFeature, "setFeature");
|
||||
|
||||
// src/submodules/client/setTokenFeature.ts
|
||||
function setTokenFeature(token, feature, value) {
|
||||
if (!token.$source) {
|
||||
token.$source = {};
|
||||
}
|
||||
token.$source[feature] = value;
|
||||
return token;
|
||||
}
|
||||
__name(setTokenFeature, "setTokenFeature");
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
emitWarningIfUnsupportedVersion,
|
||||
setCredentialFeature,
|
||||
setFeature,
|
||||
setTokenFeature,
|
||||
state
|
||||
});
|
||||
Generated
Vendored
+391
@@ -0,0 +1,391 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/submodules/httpAuthSchemes/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
AWSSDKSigV4Signer: () => AWSSDKSigV4Signer,
|
||||
AwsSdkSigV4ASigner: () => AwsSdkSigV4ASigner,
|
||||
AwsSdkSigV4Signer: () => AwsSdkSigV4Signer,
|
||||
NODE_AUTH_SCHEME_PREFERENCE_OPTIONS: () => NODE_AUTH_SCHEME_PREFERENCE_OPTIONS,
|
||||
NODE_SIGV4A_CONFIG_OPTIONS: () => NODE_SIGV4A_CONFIG_OPTIONS,
|
||||
getBearerTokenEnvKey: () => getBearerTokenEnvKey,
|
||||
resolveAWSSDKSigV4Config: () => resolveAWSSDKSigV4Config,
|
||||
resolveAwsSdkSigV4AConfig: () => resolveAwsSdkSigV4AConfig,
|
||||
resolveAwsSdkSigV4Config: () => resolveAwsSdkSigV4Config,
|
||||
validateSigningProperties: () => validateSigningProperties
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
|
||||
// src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts
|
||||
var import_protocol_http2 = require("@smithy/protocol-http");
|
||||
|
||||
// src/submodules/httpAuthSchemes/utils/getDateHeader.ts
|
||||
var import_protocol_http = require("@smithy/protocol-http");
|
||||
var getDateHeader = /* @__PURE__ */ __name((response) => import_protocol_http.HttpResponse.isInstance(response) ? response.headers?.date ?? response.headers?.Date : void 0, "getDateHeader");
|
||||
|
||||
// src/submodules/httpAuthSchemes/utils/getSkewCorrectedDate.ts
|
||||
var getSkewCorrectedDate = /* @__PURE__ */ __name((systemClockOffset) => new Date(Date.now() + systemClockOffset), "getSkewCorrectedDate");
|
||||
|
||||
// src/submodules/httpAuthSchemes/utils/isClockSkewed.ts
|
||||
var isClockSkewed = /* @__PURE__ */ __name((clockTime, systemClockOffset) => Math.abs(getSkewCorrectedDate(systemClockOffset).getTime() - clockTime) >= 3e5, "isClockSkewed");
|
||||
|
||||
// src/submodules/httpAuthSchemes/utils/getUpdatedSystemClockOffset.ts
|
||||
var getUpdatedSystemClockOffset = /* @__PURE__ */ __name((clockTime, currentSystemClockOffset) => {
|
||||
const clockTimeInMs = Date.parse(clockTime);
|
||||
if (isClockSkewed(clockTimeInMs, currentSystemClockOffset)) {
|
||||
return clockTimeInMs - Date.now();
|
||||
}
|
||||
return currentSystemClockOffset;
|
||||
}, "getUpdatedSystemClockOffset");
|
||||
|
||||
// src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.ts
|
||||
var throwSigningPropertyError = /* @__PURE__ */ __name((name, property) => {
|
||||
if (!property) {
|
||||
throw new Error(`Property \`${name}\` is not resolved for AWS SDK SigV4Auth`);
|
||||
}
|
||||
return property;
|
||||
}, "throwSigningPropertyError");
|
||||
var validateSigningProperties = /* @__PURE__ */ __name(async (signingProperties) => {
|
||||
const context = throwSigningPropertyError(
|
||||
"context",
|
||||
signingProperties.context
|
||||
);
|
||||
const config = throwSigningPropertyError("config", signingProperties.config);
|
||||
const authScheme = context.endpointV2?.properties?.authSchemes?.[0];
|
||||
const signerFunction = throwSigningPropertyError(
|
||||
"signer",
|
||||
config.signer
|
||||
);
|
||||
const signer = await signerFunction(authScheme);
|
||||
const signingRegion = signingProperties?.signingRegion;
|
||||
const signingRegionSet = signingProperties?.signingRegionSet;
|
||||
const signingName = signingProperties?.signingName;
|
||||
return {
|
||||
config,
|
||||
signer,
|
||||
signingRegion,
|
||||
signingRegionSet,
|
||||
signingName
|
||||
};
|
||||
}, "validateSigningProperties");
|
||||
var AwsSdkSigV4Signer = class {
|
||||
static {
|
||||
__name(this, "AwsSdkSigV4Signer");
|
||||
}
|
||||
async sign(httpRequest, identity, signingProperties) {
|
||||
if (!import_protocol_http2.HttpRequest.isInstance(httpRequest)) {
|
||||
throw new Error("The request is not an instance of `HttpRequest` and cannot be signed");
|
||||
}
|
||||
const validatedProps = await validateSigningProperties(signingProperties);
|
||||
const { config, signer } = validatedProps;
|
||||
let { signingRegion, signingName } = validatedProps;
|
||||
const handlerExecutionContext = signingProperties.context;
|
||||
if (handlerExecutionContext?.authSchemes?.length ?? 0 > 1) {
|
||||
const [first, second] = handlerExecutionContext.authSchemes;
|
||||
if (first?.name === "sigv4a" && second?.name === "sigv4") {
|
||||
signingRegion = second?.signingRegion ?? signingRegion;
|
||||
signingName = second?.signingName ?? signingName;
|
||||
}
|
||||
}
|
||||
const signedRequest = await signer.sign(httpRequest, {
|
||||
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
||||
signingRegion,
|
||||
signingService: signingName
|
||||
});
|
||||
return signedRequest;
|
||||
}
|
||||
errorHandler(signingProperties) {
|
||||
return (error) => {
|
||||
const serverTime = error.ServerTime ?? getDateHeader(error.$response);
|
||||
if (serverTime) {
|
||||
const config = throwSigningPropertyError("config", signingProperties.config);
|
||||
const initialSystemClockOffset = config.systemClockOffset;
|
||||
config.systemClockOffset = getUpdatedSystemClockOffset(serverTime, config.systemClockOffset);
|
||||
const clockSkewCorrected = config.systemClockOffset !== initialSystemClockOffset;
|
||||
if (clockSkewCorrected && error.$metadata) {
|
||||
error.$metadata.clockSkewCorrected = true;
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
};
|
||||
}
|
||||
successHandler(httpResponse, signingProperties) {
|
||||
const dateHeader = getDateHeader(httpResponse);
|
||||
if (dateHeader) {
|
||||
const config = throwSigningPropertyError("config", signingProperties.config);
|
||||
config.systemClockOffset = getUpdatedSystemClockOffset(dateHeader, config.systemClockOffset);
|
||||
}
|
||||
}
|
||||
};
|
||||
var AWSSDKSigV4Signer = AwsSdkSigV4Signer;
|
||||
|
||||
// src/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4ASigner.ts
|
||||
var import_protocol_http3 = require("@smithy/protocol-http");
|
||||
var AwsSdkSigV4ASigner = class extends AwsSdkSigV4Signer {
|
||||
static {
|
||||
__name(this, "AwsSdkSigV4ASigner");
|
||||
}
|
||||
async sign(httpRequest, identity, signingProperties) {
|
||||
if (!import_protocol_http3.HttpRequest.isInstance(httpRequest)) {
|
||||
throw new Error("The request is not an instance of `HttpRequest` and cannot be signed");
|
||||
}
|
||||
const { config, signer, signingRegion, signingRegionSet, signingName } = await validateSigningProperties(
|
||||
signingProperties
|
||||
);
|
||||
const configResolvedSigningRegionSet = await config.sigv4aSigningRegionSet?.();
|
||||
const multiRegionOverride = (configResolvedSigningRegionSet ?? signingRegionSet ?? [signingRegion]).join(",");
|
||||
const signedRequest = await signer.sign(httpRequest, {
|
||||
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
||||
signingRegion: multiRegionOverride,
|
||||
signingService: signingName
|
||||
});
|
||||
return signedRequest;
|
||||
}
|
||||
};
|
||||
|
||||
// src/submodules/httpAuthSchemes/utils/getArrayForCommaSeparatedString.ts
|
||||
var getArrayForCommaSeparatedString = /* @__PURE__ */ __name((str) => typeof str === "string" && str.length > 0 ? str.split(",").map((item) => item.trim()) : [], "getArrayForCommaSeparatedString");
|
||||
|
||||
// src/submodules/httpAuthSchemes/utils/getBearerTokenEnvKey.ts
|
||||
var getBearerTokenEnvKey = /* @__PURE__ */ __name((signingName) => `AWS_BEARER_TOKEN_${signingName.replace(/[\s-]/g, "_").toUpperCase()}`, "getBearerTokenEnvKey");
|
||||
|
||||
// src/submodules/httpAuthSchemes/aws_sdk/NODE_AUTH_SCHEME_PREFERENCE_OPTIONS.ts
|
||||
var NODE_AUTH_SCHEME_PREFERENCE_ENV_KEY = "AWS_AUTH_SCHEME_PREFERENCE";
|
||||
var NODE_AUTH_SCHEME_PREFERENCE_CONFIG_KEY = "auth_scheme_preference";
|
||||
var NODE_AUTH_SCHEME_PREFERENCE_OPTIONS = {
|
||||
/**
|
||||
* Retrieves auth scheme preference from environment variables
|
||||
* @param env - Node process environment object
|
||||
* @returns Array of auth scheme strings if preference is set, undefined otherwise
|
||||
*/
|
||||
environmentVariableSelector: /* @__PURE__ */ __name((env, options) => {
|
||||
if (options?.signingName) {
|
||||
const bearerTokenKey = getBearerTokenEnvKey(options.signingName);
|
||||
if (bearerTokenKey in env) return ["httpBearerAuth"];
|
||||
}
|
||||
if (!(NODE_AUTH_SCHEME_PREFERENCE_ENV_KEY in env)) return void 0;
|
||||
return getArrayForCommaSeparatedString(env[NODE_AUTH_SCHEME_PREFERENCE_ENV_KEY]);
|
||||
}, "environmentVariableSelector"),
|
||||
/**
|
||||
* Retrieves auth scheme preference from config file
|
||||
* @param profile - Config profile object
|
||||
* @returns Array of auth scheme strings if preference is set, undefined otherwise
|
||||
*/
|
||||
configFileSelector: /* @__PURE__ */ __name((profile) => {
|
||||
if (!(NODE_AUTH_SCHEME_PREFERENCE_CONFIG_KEY in profile)) return void 0;
|
||||
return getArrayForCommaSeparatedString(profile[NODE_AUTH_SCHEME_PREFERENCE_CONFIG_KEY]);
|
||||
}, "configFileSelector"),
|
||||
/**
|
||||
* Default auth scheme preference if not specified in environment or config
|
||||
*/
|
||||
default: []
|
||||
};
|
||||
|
||||
// src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4AConfig.ts
|
||||
var import_core = require("@smithy/core");
|
||||
var import_property_provider = require("@smithy/property-provider");
|
||||
var resolveAwsSdkSigV4AConfig = /* @__PURE__ */ __name((config) => {
|
||||
config.sigv4aSigningRegionSet = (0, import_core.normalizeProvider)(config.sigv4aSigningRegionSet);
|
||||
return config;
|
||||
}, "resolveAwsSdkSigV4AConfig");
|
||||
var NODE_SIGV4A_CONFIG_OPTIONS = {
|
||||
environmentVariableSelector(env) {
|
||||
if (env.AWS_SIGV4A_SIGNING_REGION_SET) {
|
||||
return env.AWS_SIGV4A_SIGNING_REGION_SET.split(",").map((_) => _.trim());
|
||||
}
|
||||
throw new import_property_provider.ProviderError("AWS_SIGV4A_SIGNING_REGION_SET not set in env.", {
|
||||
tryNextLink: true
|
||||
});
|
||||
},
|
||||
configFileSelector(profile) {
|
||||
if (profile.sigv4a_signing_region_set) {
|
||||
return (profile.sigv4a_signing_region_set ?? "").split(",").map((_) => _.trim());
|
||||
}
|
||||
throw new import_property_provider.ProviderError("sigv4a_signing_region_set not set in profile.", {
|
||||
tryNextLink: true
|
||||
});
|
||||
},
|
||||
default: void 0
|
||||
};
|
||||
|
||||
// src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.ts
|
||||
var import_client = require("@aws-sdk/core/client");
|
||||
var import_core2 = require("@smithy/core");
|
||||
var import_signature_v4 = require("@smithy/signature-v4");
|
||||
var resolveAwsSdkSigV4Config = /* @__PURE__ */ __name((config) => {
|
||||
let inputCredentials = config.credentials;
|
||||
let isUserSupplied = !!config.credentials;
|
||||
let resolvedCredentials = void 0;
|
||||
Object.defineProperty(config, "credentials", {
|
||||
set(credentials) {
|
||||
if (credentials && credentials !== inputCredentials && credentials !== resolvedCredentials) {
|
||||
isUserSupplied = true;
|
||||
}
|
||||
inputCredentials = credentials;
|
||||
const memoizedProvider = normalizeCredentialProvider(config, {
|
||||
credentials: inputCredentials,
|
||||
credentialDefaultProvider: config.credentialDefaultProvider
|
||||
});
|
||||
const boundProvider = bindCallerConfig(config, memoizedProvider);
|
||||
if (isUserSupplied && !boundProvider.attributed) {
|
||||
resolvedCredentials = /* @__PURE__ */ __name(async (options) => boundProvider(options).then(
|
||||
(creds) => (0, import_client.setCredentialFeature)(creds, "CREDENTIALS_CODE", "e")
|
||||
), "resolvedCredentials");
|
||||
resolvedCredentials.memoized = boundProvider.memoized;
|
||||
resolvedCredentials.configBound = boundProvider.configBound;
|
||||
resolvedCredentials.attributed = true;
|
||||
} else {
|
||||
resolvedCredentials = boundProvider;
|
||||
}
|
||||
},
|
||||
get() {
|
||||
return resolvedCredentials;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
config.credentials = inputCredentials;
|
||||
const {
|
||||
// Default for signingEscapePath
|
||||
signingEscapePath = true,
|
||||
// Default for systemClockOffset
|
||||
systemClockOffset = config.systemClockOffset || 0,
|
||||
// No default for sha256 since it is platform dependent
|
||||
sha256
|
||||
} = config;
|
||||
let signer;
|
||||
if (config.signer) {
|
||||
signer = (0, import_core2.normalizeProvider)(config.signer);
|
||||
} else if (config.regionInfoProvider) {
|
||||
signer = /* @__PURE__ */ __name(() => (0, import_core2.normalizeProvider)(config.region)().then(
|
||||
async (region) => [
|
||||
await config.regionInfoProvider(region, {
|
||||
useFipsEndpoint: await config.useFipsEndpoint(),
|
||||
useDualstackEndpoint: await config.useDualstackEndpoint()
|
||||
}) || {},
|
||||
region
|
||||
]
|
||||
).then(([regionInfo, region]) => {
|
||||
const { signingRegion, signingService } = regionInfo;
|
||||
config.signingRegion = config.signingRegion || signingRegion || region;
|
||||
config.signingName = config.signingName || signingService || config.serviceId;
|
||||
const params = {
|
||||
...config,
|
||||
credentials: config.credentials,
|
||||
region: config.signingRegion,
|
||||
service: config.signingName,
|
||||
sha256,
|
||||
uriEscapePath: signingEscapePath
|
||||
};
|
||||
const SignerCtor = config.signerConstructor || import_signature_v4.SignatureV4;
|
||||
return new SignerCtor(params);
|
||||
}), "signer");
|
||||
} else {
|
||||
signer = /* @__PURE__ */ __name(async (authScheme) => {
|
||||
authScheme = Object.assign(
|
||||
{},
|
||||
{
|
||||
name: "sigv4",
|
||||
signingName: config.signingName || config.defaultSigningName,
|
||||
signingRegion: await (0, import_core2.normalizeProvider)(config.region)(),
|
||||
properties: {}
|
||||
},
|
||||
authScheme
|
||||
);
|
||||
const signingRegion = authScheme.signingRegion;
|
||||
const signingService = authScheme.signingName;
|
||||
config.signingRegion = config.signingRegion || signingRegion;
|
||||
config.signingName = config.signingName || signingService || config.serviceId;
|
||||
const params = {
|
||||
...config,
|
||||
credentials: config.credentials,
|
||||
region: config.signingRegion,
|
||||
service: config.signingName,
|
||||
sha256,
|
||||
uriEscapePath: signingEscapePath
|
||||
};
|
||||
const SignerCtor = config.signerConstructor || import_signature_v4.SignatureV4;
|
||||
return new SignerCtor(params);
|
||||
}, "signer");
|
||||
}
|
||||
const resolvedConfig = Object.assign(config, {
|
||||
systemClockOffset,
|
||||
signingEscapePath,
|
||||
signer
|
||||
});
|
||||
return resolvedConfig;
|
||||
}, "resolveAwsSdkSigV4Config");
|
||||
var resolveAWSSDKSigV4Config = resolveAwsSdkSigV4Config;
|
||||
function normalizeCredentialProvider(config, {
|
||||
credentials,
|
||||
credentialDefaultProvider
|
||||
}) {
|
||||
let credentialsProvider;
|
||||
if (credentials) {
|
||||
if (!credentials?.memoized) {
|
||||
credentialsProvider = (0, import_core2.memoizeIdentityProvider)(credentials, import_core2.isIdentityExpired, import_core2.doesIdentityRequireRefresh);
|
||||
} else {
|
||||
credentialsProvider = credentials;
|
||||
}
|
||||
} else {
|
||||
if (credentialDefaultProvider) {
|
||||
credentialsProvider = (0, import_core2.normalizeProvider)(
|
||||
credentialDefaultProvider(
|
||||
Object.assign({}, config, {
|
||||
parentClientConfig: config
|
||||
})
|
||||
)
|
||||
);
|
||||
} else {
|
||||
credentialsProvider = /* @__PURE__ */ __name(async () => {
|
||||
throw new Error(
|
||||
"@aws-sdk/core::resolveAwsSdkSigV4Config - `credentials` not provided and no credentialDefaultProvider was configured."
|
||||
);
|
||||
}, "credentialsProvider");
|
||||
}
|
||||
}
|
||||
credentialsProvider.memoized = true;
|
||||
return credentialsProvider;
|
||||
}
|
||||
__name(normalizeCredentialProvider, "normalizeCredentialProvider");
|
||||
function bindCallerConfig(config, credentialsProvider) {
|
||||
if (credentialsProvider.configBound) {
|
||||
return credentialsProvider;
|
||||
}
|
||||
const fn = /* @__PURE__ */ __name(async (options) => credentialsProvider({ ...options, callerClientConfig: config }), "fn");
|
||||
fn.memoized = credentialsProvider.memoized;
|
||||
fn.configBound = true;
|
||||
return fn;
|
||||
}
|
||||
__name(bindCallerConfig, "bindCallerConfig");
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
AWSSDKSigV4Signer,
|
||||
AwsSdkSigV4ASigner,
|
||||
AwsSdkSigV4Signer,
|
||||
NODE_AUTH_SCHEME_PREFERENCE_OPTIONS,
|
||||
NODE_SIGV4A_CONFIG_OPTIONS,
|
||||
getBearerTokenEnvKey,
|
||||
resolveAWSSDKSigV4Config,
|
||||
resolveAwsSdkSigV4AConfig,
|
||||
resolveAwsSdkSigV4Config,
|
||||
validateSigningProperties
|
||||
});
|
||||
Generated
Vendored
+1712
File diff suppressed because it is too large
Load Diff
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./submodules/client/index";
|
||||
export * from "./submodules/httpAuthSchemes/index";
|
||||
export * from "./submodules/protocols/index";
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import { normalizeProvider } from "@smithy/util-middleware";
|
||||
import { DEFAULT_ACCOUNT_ID_ENDPOINT_MODE, validateAccountIdEndpointMode, } from "./AccountIdEndpointModeConstants";
|
||||
export const resolveAccountIdEndpointModeConfig = (input) => {
|
||||
const { accountIdEndpointMode } = input;
|
||||
const accountIdEndpointModeProvider = normalizeProvider(accountIdEndpointMode ?? DEFAULT_ACCOUNT_ID_ENDPOINT_MODE);
|
||||
return Object.assign(input, {
|
||||
accountIdEndpointMode: async () => {
|
||||
const accIdMode = await accountIdEndpointModeProvider();
|
||||
if (!validateAccountIdEndpointMode(accIdMode)) {
|
||||
throw new Error(`Invalid value for accountIdEndpointMode: ${accIdMode}. Valid values are: "required", "preferred", "disabled".`);
|
||||
}
|
||||
return accIdMode;
|
||||
},
|
||||
});
|
||||
};
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export const DEFAULT_ACCOUNT_ID_ENDPOINT_MODE = "preferred";
|
||||
export const ACCOUNT_ID_ENDPOINT_MODE_VALUES = ["disabled", "preferred", "required"];
|
||||
export function validateAccountIdEndpointMode(value) {
|
||||
return ACCOUNT_ID_ENDPOINT_MODE_VALUES.includes(value);
|
||||
}
|
||||
Generated
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
import { DEFAULT_ACCOUNT_ID_ENDPOINT_MODE, validateAccountIdEndpointMode, } from "./AccountIdEndpointModeConstants";
|
||||
const err = "Invalid AccountIdEndpointMode value";
|
||||
const _throw = (message) => {
|
||||
throw new Error(message);
|
||||
};
|
||||
export const ENV_ACCOUNT_ID_ENDPOINT_MODE = "AWS_ACCOUNT_ID_ENDPOINT_MODE";
|
||||
export const CONFIG_ACCOUNT_ID_ENDPOINT_MODE = "account_id_endpoint_mode";
|
||||
export const NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS = {
|
||||
environmentVariableSelector: (env) => {
|
||||
const value = env[ENV_ACCOUNT_ID_ENDPOINT_MODE];
|
||||
if (value && !validateAccountIdEndpointMode(value)) {
|
||||
_throw(err);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
configFileSelector: (profile) => {
|
||||
const value = profile[CONFIG_ACCOUNT_ID_ENDPOINT_MODE];
|
||||
if (value && !validateAccountIdEndpointMode(value)) {
|
||||
_throw(err);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
default: DEFAULT_ACCOUNT_ID_ENDPOINT_MODE,
|
||||
};
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./AccountIdEndpointModeConfigResolver";
|
||||
export * from "./AccountIdEndpointModeConstants";
|
||||
export * from "./NodeAccountIdEndpointModeConfigOptions";
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
export const state = {
|
||||
warningEmitted: false,
|
||||
};
|
||||
export const emitWarningIfUnsupportedVersion = (version) => {
|
||||
if (version && !state.warningEmitted && parseInt(version.substring(1, version.indexOf("."))) < 18) {
|
||||
state.warningEmitted = true;
|
||||
process.emitWarning(`NodeDeprecationWarning: The AWS SDK for JavaScript (v3) will
|
||||
no longer support Node.js 16.x on January 6, 2025.
|
||||
|
||||
To continue receiving updates to AWS services, bug fixes, and security
|
||||
updates please upgrade to a supported Node.js LTS version.
|
||||
|
||||
More information can be found at: https://a.co/74kJMmI`);
|
||||
}
|
||||
};
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
export * from "./emitWarningIfUnsupportedVersion";
|
||||
export * from "./setCredentialFeature";
|
||||
export * from "./setFeature";
|
||||
export * from "./setTokenFeature";
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
export function setCredentialFeature(credentials, feature, value) {
|
||||
if (!credentials.$source) {
|
||||
credentials.$source = {};
|
||||
}
|
||||
credentials.$source[feature] = value;
|
||||
return credentials;
|
||||
}
|
||||
Generated
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
export function setFeature(context, feature, value) {
|
||||
if (!context.__aws_sdk_context) {
|
||||
context.__aws_sdk_context = {
|
||||
features: {},
|
||||
};
|
||||
}
|
||||
else if (!context.__aws_sdk_context.features) {
|
||||
context.__aws_sdk_context.features = {};
|
||||
}
|
||||
context.__aws_sdk_context.features[feature] = value;
|
||||
}
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
export function setTokenFeature(token, feature, value) {
|
||||
if (!token.$source) {
|
||||
token.$source = {};
|
||||
}
|
||||
token.$source[feature] = value;
|
||||
return token;
|
||||
}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import { HttpRequest } from "@smithy/protocol-http";
|
||||
import { getSkewCorrectedDate } from "../utils";
|
||||
import { AwsSdkSigV4Signer, validateSigningProperties } from "./AwsSdkSigV4Signer";
|
||||
export class AwsSdkSigV4ASigner extends AwsSdkSigV4Signer {
|
||||
async sign(httpRequest, identity, signingProperties) {
|
||||
if (!HttpRequest.isInstance(httpRequest)) {
|
||||
throw new Error("The request is not an instance of `HttpRequest` and cannot be signed");
|
||||
}
|
||||
const { config, signer, signingRegion, signingRegionSet, signingName } = await validateSigningProperties(signingProperties);
|
||||
const configResolvedSigningRegionSet = await config.sigv4aSigningRegionSet?.();
|
||||
const multiRegionOverride = (configResolvedSigningRegionSet ??
|
||||
signingRegionSet ?? [signingRegion]).join(",");
|
||||
const signedRequest = await signer.sign(httpRequest, {
|
||||
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
||||
signingRegion: multiRegionOverride,
|
||||
signingService: signingName,
|
||||
});
|
||||
return signedRequest;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
import { HttpRequest } from "@smithy/protocol-http";
|
||||
import { getDateHeader, getSkewCorrectedDate, getUpdatedSystemClockOffset } from "../utils";
|
||||
const throwSigningPropertyError = (name, property) => {
|
||||
if (!property) {
|
||||
throw new Error(`Property \`${name}\` is not resolved for AWS SDK SigV4Auth`);
|
||||
}
|
||||
return property;
|
||||
};
|
||||
export const validateSigningProperties = async (signingProperties) => {
|
||||
const context = throwSigningPropertyError("context", signingProperties.context);
|
||||
const config = throwSigningPropertyError("config", signingProperties.config);
|
||||
const authScheme = context.endpointV2?.properties?.authSchemes?.[0];
|
||||
const signerFunction = throwSigningPropertyError("signer", config.signer);
|
||||
const signer = await signerFunction(authScheme);
|
||||
const signingRegion = signingProperties?.signingRegion;
|
||||
const signingRegionSet = signingProperties?.signingRegionSet;
|
||||
const signingName = signingProperties?.signingName;
|
||||
return {
|
||||
config,
|
||||
signer,
|
||||
signingRegion,
|
||||
signingRegionSet,
|
||||
signingName,
|
||||
};
|
||||
};
|
||||
export class AwsSdkSigV4Signer {
|
||||
async sign(httpRequest, identity, signingProperties) {
|
||||
if (!HttpRequest.isInstance(httpRequest)) {
|
||||
throw new Error("The request is not an instance of `HttpRequest` and cannot be signed");
|
||||
}
|
||||
const validatedProps = await validateSigningProperties(signingProperties);
|
||||
const { config, signer } = validatedProps;
|
||||
let { signingRegion, signingName } = validatedProps;
|
||||
const handlerExecutionContext = signingProperties.context;
|
||||
if (handlerExecutionContext?.authSchemes?.length ?? 0 > 1) {
|
||||
const [first, second] = handlerExecutionContext.authSchemes;
|
||||
if (first?.name === "sigv4a" && second?.name === "sigv4") {
|
||||
signingRegion = second?.signingRegion ?? signingRegion;
|
||||
signingName = second?.signingName ?? signingName;
|
||||
}
|
||||
}
|
||||
const signedRequest = await signer.sign(httpRequest, {
|
||||
signingDate: getSkewCorrectedDate(config.systemClockOffset),
|
||||
signingRegion: signingRegion,
|
||||
signingService: signingName,
|
||||
});
|
||||
return signedRequest;
|
||||
}
|
||||
errorHandler(signingProperties) {
|
||||
return (error) => {
|
||||
const serverTime = error.ServerTime ?? getDateHeader(error.$response);
|
||||
if (serverTime) {
|
||||
const config = throwSigningPropertyError("config", signingProperties.config);
|
||||
const initialSystemClockOffset = config.systemClockOffset;
|
||||
config.systemClockOffset = getUpdatedSystemClockOffset(serverTime, config.systemClockOffset);
|
||||
const clockSkewCorrected = config.systemClockOffset !== initialSystemClockOffset;
|
||||
if (clockSkewCorrected && error.$metadata) {
|
||||
error.$metadata.clockSkewCorrected = true;
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
};
|
||||
}
|
||||
successHandler(httpResponse, signingProperties) {
|
||||
const dateHeader = getDateHeader(httpResponse);
|
||||
if (dateHeader) {
|
||||
const config = throwSigningPropertyError("config", signingProperties.config);
|
||||
config.systemClockOffset = getUpdatedSystemClockOffset(dateHeader, config.systemClockOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
export const AWSSDKSigV4Signer = AwsSdkSigV4Signer;
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
import { getArrayForCommaSeparatedString } from "../utils/getArrayForCommaSeparatedString";
|
||||
import { getBearerTokenEnvKey } from "../utils/getBearerTokenEnvKey";
|
||||
const NODE_AUTH_SCHEME_PREFERENCE_ENV_KEY = "AWS_AUTH_SCHEME_PREFERENCE";
|
||||
const NODE_AUTH_SCHEME_PREFERENCE_CONFIG_KEY = "auth_scheme_preference";
|
||||
export const NODE_AUTH_SCHEME_PREFERENCE_OPTIONS = {
|
||||
environmentVariableSelector: (env, options) => {
|
||||
if (options?.signingName) {
|
||||
const bearerTokenKey = getBearerTokenEnvKey(options.signingName);
|
||||
if (bearerTokenKey in env)
|
||||
return ["httpBearerAuth"];
|
||||
}
|
||||
if (!(NODE_AUTH_SCHEME_PREFERENCE_ENV_KEY in env))
|
||||
return undefined;
|
||||
return getArrayForCommaSeparatedString(env[NODE_AUTH_SCHEME_PREFERENCE_ENV_KEY]);
|
||||
},
|
||||
configFileSelector: (profile) => {
|
||||
if (!(NODE_AUTH_SCHEME_PREFERENCE_CONFIG_KEY in profile))
|
||||
return undefined;
|
||||
return getArrayForCommaSeparatedString(profile[NODE_AUTH_SCHEME_PREFERENCE_CONFIG_KEY]);
|
||||
},
|
||||
default: [],
|
||||
};
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export { AwsSdkSigV4Signer, AWSSDKSigV4Signer, validateSigningProperties } from "./AwsSdkSigV4Signer";
|
||||
export { AwsSdkSigV4ASigner } from "./AwsSdkSigV4ASigner";
|
||||
export * from "./NODE_AUTH_SCHEME_PREFERENCE_OPTIONS";
|
||||
export * from "./resolveAwsSdkSigV4AConfig";
|
||||
export * from "./resolveAwsSdkSigV4Config";
|
||||
Generated
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
import { normalizeProvider } from "@smithy/core";
|
||||
import { ProviderError } from "@smithy/property-provider";
|
||||
export const resolveAwsSdkSigV4AConfig = (config) => {
|
||||
config.sigv4aSigningRegionSet = normalizeProvider(config.sigv4aSigningRegionSet);
|
||||
return config;
|
||||
};
|
||||
export const NODE_SIGV4A_CONFIG_OPTIONS = {
|
||||
environmentVariableSelector(env) {
|
||||
if (env.AWS_SIGV4A_SIGNING_REGION_SET) {
|
||||
return env.AWS_SIGV4A_SIGNING_REGION_SET.split(",").map((_) => _.trim());
|
||||
}
|
||||
throw new ProviderError("AWS_SIGV4A_SIGNING_REGION_SET not set in env.", {
|
||||
tryNextLink: true,
|
||||
});
|
||||
},
|
||||
configFileSelector(profile) {
|
||||
if (profile.sigv4a_signing_region_set) {
|
||||
return (profile.sigv4a_signing_region_set ?? "").split(",").map((_) => _.trim());
|
||||
}
|
||||
throw new ProviderError("sigv4a_signing_region_set not set in profile.", {
|
||||
tryNextLink: true,
|
||||
});
|
||||
},
|
||||
default: undefined,
|
||||
};
|
||||
Generated
Vendored
+131
@@ -0,0 +1,131 @@
|
||||
import { setCredentialFeature } from "@aws-sdk/core/client";
|
||||
import { doesIdentityRequireRefresh, isIdentityExpired, memoizeIdentityProvider, normalizeProvider, } from "@smithy/core";
|
||||
import { SignatureV4 } from "@smithy/signature-v4";
|
||||
export const resolveAwsSdkSigV4Config = (config) => {
|
||||
let inputCredentials = config.credentials;
|
||||
let isUserSupplied = !!config.credentials;
|
||||
let resolvedCredentials = undefined;
|
||||
Object.defineProperty(config, "credentials", {
|
||||
set(credentials) {
|
||||
if (credentials && credentials !== inputCredentials && credentials !== resolvedCredentials) {
|
||||
isUserSupplied = true;
|
||||
}
|
||||
inputCredentials = credentials;
|
||||
const memoizedProvider = normalizeCredentialProvider(config, {
|
||||
credentials: inputCredentials,
|
||||
credentialDefaultProvider: config.credentialDefaultProvider,
|
||||
});
|
||||
const boundProvider = bindCallerConfig(config, memoizedProvider);
|
||||
if (isUserSupplied && !boundProvider.attributed) {
|
||||
resolvedCredentials = async (options) => boundProvider(options).then((creds) => setCredentialFeature(creds, "CREDENTIALS_CODE", "e"));
|
||||
resolvedCredentials.memoized = boundProvider.memoized;
|
||||
resolvedCredentials.configBound = boundProvider.configBound;
|
||||
resolvedCredentials.attributed = true;
|
||||
}
|
||||
else {
|
||||
resolvedCredentials = boundProvider;
|
||||
}
|
||||
},
|
||||
get() {
|
||||
return resolvedCredentials;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
});
|
||||
config.credentials = inputCredentials;
|
||||
const { signingEscapePath = true, systemClockOffset = config.systemClockOffset || 0, sha256, } = config;
|
||||
let signer;
|
||||
if (config.signer) {
|
||||
signer = normalizeProvider(config.signer);
|
||||
}
|
||||
else if (config.regionInfoProvider) {
|
||||
signer = () => normalizeProvider(config.region)()
|
||||
.then(async (region) => [
|
||||
(await config.regionInfoProvider(region, {
|
||||
useFipsEndpoint: await config.useFipsEndpoint(),
|
||||
useDualstackEndpoint: await config.useDualstackEndpoint(),
|
||||
})) || {},
|
||||
region,
|
||||
])
|
||||
.then(([regionInfo, region]) => {
|
||||
const { signingRegion, signingService } = regionInfo;
|
||||
config.signingRegion = config.signingRegion || signingRegion || region;
|
||||
config.signingName = config.signingName || signingService || config.serviceId;
|
||||
const params = {
|
||||
...config,
|
||||
credentials: config.credentials,
|
||||
region: config.signingRegion,
|
||||
service: config.signingName,
|
||||
sha256,
|
||||
uriEscapePath: signingEscapePath,
|
||||
};
|
||||
const SignerCtor = config.signerConstructor || SignatureV4;
|
||||
return new SignerCtor(params);
|
||||
});
|
||||
}
|
||||
else {
|
||||
signer = async (authScheme) => {
|
||||
authScheme = Object.assign({}, {
|
||||
name: "sigv4",
|
||||
signingName: config.signingName || config.defaultSigningName,
|
||||
signingRegion: await normalizeProvider(config.region)(),
|
||||
properties: {},
|
||||
}, authScheme);
|
||||
const signingRegion = authScheme.signingRegion;
|
||||
const signingService = authScheme.signingName;
|
||||
config.signingRegion = config.signingRegion || signingRegion;
|
||||
config.signingName = config.signingName || signingService || config.serviceId;
|
||||
const params = {
|
||||
...config,
|
||||
credentials: config.credentials,
|
||||
region: config.signingRegion,
|
||||
service: config.signingName,
|
||||
sha256,
|
||||
uriEscapePath: signingEscapePath,
|
||||
};
|
||||
const SignerCtor = config.signerConstructor || SignatureV4;
|
||||
return new SignerCtor(params);
|
||||
};
|
||||
}
|
||||
const resolvedConfig = Object.assign(config, {
|
||||
systemClockOffset,
|
||||
signingEscapePath,
|
||||
signer,
|
||||
});
|
||||
return resolvedConfig;
|
||||
};
|
||||
export const resolveAWSSDKSigV4Config = resolveAwsSdkSigV4Config;
|
||||
function normalizeCredentialProvider(config, { credentials, credentialDefaultProvider, }) {
|
||||
let credentialsProvider;
|
||||
if (credentials) {
|
||||
if (!credentials?.memoized) {
|
||||
credentialsProvider = memoizeIdentityProvider(credentials, isIdentityExpired, doesIdentityRequireRefresh);
|
||||
}
|
||||
else {
|
||||
credentialsProvider = credentials;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (credentialDefaultProvider) {
|
||||
credentialsProvider = normalizeProvider(credentialDefaultProvider(Object.assign({}, config, {
|
||||
parentClientConfig: config,
|
||||
})));
|
||||
}
|
||||
else {
|
||||
credentialsProvider = async () => {
|
||||
throw new Error("@aws-sdk/core::resolveAwsSdkSigV4Config - `credentials` not provided and no credentialDefaultProvider was configured.");
|
||||
};
|
||||
}
|
||||
}
|
||||
credentialsProvider.memoized = true;
|
||||
return credentialsProvider;
|
||||
}
|
||||
function bindCallerConfig(config, credentialsProvider) {
|
||||
if (credentialsProvider.configBound) {
|
||||
return credentialsProvider;
|
||||
}
|
||||
const fn = async (options) => credentialsProvider({ ...options, callerClientConfig: config });
|
||||
fn.memoized = credentialsProvider.memoized;
|
||||
fn.configBound = true;
|
||||
return fn;
|
||||
}
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./aws_sdk";
|
||||
export * from "./utils/getBearerTokenEnvKey";
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export const getArrayForCommaSeparatedString = (str) => typeof str === "string" && str.length > 0 ? str.split(",").map((item) => item.trim()) : [];
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export const getBearerTokenEnvKey = (signingName) => `AWS_BEARER_TOKEN_${signingName.replace(/[\s-]/g, "_").toUpperCase()}`;
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import { HttpResponse } from "@smithy/protocol-http";
|
||||
export const getDateHeader = (response) => HttpResponse.isInstance(response) ? response.headers?.date ?? response.headers?.Date : undefined;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export const getSkewCorrectedDate = (systemClockOffset) => new Date(Date.now() + systemClockOffset);
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import { isClockSkewed } from "./isClockSkewed";
|
||||
export const getUpdatedSystemClockOffset = (clockTime, currentSystemClockOffset) => {
|
||||
const clockTimeInMs = Date.parse(clockTime);
|
||||
if (isClockSkewed(clockTimeInMs, currentSystemClockOffset)) {
|
||||
return clockTimeInMs - Date.now();
|
||||
}
|
||||
return currentSystemClockOffset;
|
||||
};
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./getDateHeader";
|
||||
export * from "./getSkewCorrectedDate";
|
||||
export * from "./getUpdatedSystemClockOffset";
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import { getSkewCorrectedDate } from "./getSkewCorrectedDate";
|
||||
export const isClockSkewed = (clockTime, systemClockOffset) => Math.abs(getSkewCorrectedDate(systemClockOffset).getTime() - clockTime) >= 300000;
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
export class SerdeContextConfig {
|
||||
serdeContext;
|
||||
setSerdeContext(serdeContext) {
|
||||
this.serdeContext = serdeContext;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
export const _toStr = (val) => {
|
||||
if (val == null) {
|
||||
return val;
|
||||
}
|
||||
if (typeof val === "number" || typeof val === "bigint") {
|
||||
const warning = new Error(`Received number ${val} where a string was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
return String(val);
|
||||
}
|
||||
if (typeof val === "boolean") {
|
||||
const warning = new Error(`Received boolean ${val} where a string was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
return String(val);
|
||||
}
|
||||
return val;
|
||||
};
|
||||
export const _toBool = (val) => {
|
||||
if (val == null) {
|
||||
return val;
|
||||
}
|
||||
if (typeof val === "number") {
|
||||
}
|
||||
if (typeof val === "string") {
|
||||
const lowercase = val.toLowerCase();
|
||||
if (val !== "" && lowercase !== "false" && lowercase !== "true") {
|
||||
const warning = new Error(`Received string "${val}" where a boolean was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
}
|
||||
return val !== "" && lowercase !== "false";
|
||||
}
|
||||
return val;
|
||||
};
|
||||
export const _toNum = (val) => {
|
||||
if (val == null) {
|
||||
return val;
|
||||
}
|
||||
if (typeof val === "boolean") {
|
||||
}
|
||||
if (typeof val === "string") {
|
||||
const num = Number(val);
|
||||
if (num.toString() !== val) {
|
||||
const warning = new Error(`Received string "${val}" where a number was expected.`);
|
||||
warning.name = "Warning";
|
||||
console.warn(warning);
|
||||
return val;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
return val;
|
||||
};
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import { collectBody } from "@smithy/smithy-client";
|
||||
export const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
export * from "./coercing-serializers";
|
||||
export * from "./json/AwsJson1_0Protocol";
|
||||
export * from "./json/AwsJson1_1Protocol";
|
||||
export * from "./json/AwsJsonRpcProtocol";
|
||||
export * from "./json/AwsRestJsonProtocol";
|
||||
export * from "./json/JsonCodec";
|
||||
export * from "./json/JsonShapeDeserializer";
|
||||
export * from "./json/JsonShapeSerializer";
|
||||
export * from "./json/awsExpectUnion";
|
||||
export * from "./json/parseJsonBody";
|
||||
export * from "./query/AwsEc2QueryProtocol";
|
||||
export * from "./query/AwsQueryProtocol";
|
||||
export * from "./xml/AwsRestXmlProtocol";
|
||||
export * from "./xml/XmlCodec";
|
||||
export * from "./xml/XmlShapeDeserializer";
|
||||
export * from "./xml/XmlShapeSerializer";
|
||||
export * from "./xml/parseXmlBody";
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
||||
export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
||||
constructor({ defaultNamespace }) {
|
||||
super({
|
||||
defaultNamespace,
|
||||
});
|
||||
}
|
||||
getShapeId() {
|
||||
return "aws.protocols#awsJson1_0";
|
||||
}
|
||||
getJsonRpcVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
||||
export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
||||
constructor({ defaultNamespace }) {
|
||||
super({
|
||||
defaultNamespace,
|
||||
});
|
||||
}
|
||||
getShapeId() {
|
||||
return "aws.protocols#awsJson1_1";
|
||||
}
|
||||
getJsonRpcVersion() {
|
||||
return "1.1";
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+84
@@ -0,0 +1,84 @@
|
||||
import { RpcProtocol } from "@smithy/core/protocols";
|
||||
import { deref, NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
|
||||
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
||||
import { JsonCodec } from "./JsonCodec";
|
||||
import { loadRestJsonErrorCode } from "./parseJsonBody";
|
||||
export class AwsJsonRpcProtocol extends RpcProtocol {
|
||||
serializer;
|
||||
deserializer;
|
||||
codec;
|
||||
constructor({ defaultNamespace }) {
|
||||
super({
|
||||
defaultNamespace,
|
||||
});
|
||||
this.codec = new JsonCodec({
|
||||
timestampFormat: {
|
||||
useTrait: true,
|
||||
default: SCHEMA.TIMESTAMP_EPOCH_SECONDS,
|
||||
},
|
||||
jsonName: false,
|
||||
});
|
||||
this.serializer = this.codec.createSerializer();
|
||||
this.deserializer = this.codec.createDeserializer();
|
||||
}
|
||||
async serializeRequest(operationSchema, input, context) {
|
||||
const request = await super.serializeRequest(operationSchema, input, context);
|
||||
if (!request.path.endsWith("/")) {
|
||||
request.path += "/";
|
||||
}
|
||||
Object.assign(request.headers, {
|
||||
"content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
|
||||
"x-amz-target": (this.getJsonRpcVersion() === "1.0" ? `JsonRpc10.` : `JsonProtocol.`) +
|
||||
NormalizedSchema.of(operationSchema).getName(),
|
||||
});
|
||||
if (deref(operationSchema.input) === "unit" || !request.body) {
|
||||
request.body = "{}";
|
||||
}
|
||||
try {
|
||||
request.headers["content-length"] = String(calculateBodyLength(request.body));
|
||||
}
|
||||
catch (e) { }
|
||||
return request;
|
||||
}
|
||||
getPayloadCodec() {
|
||||
return this.codec;
|
||||
}
|
||||
async handleError(operationSchema, context, response, dataObject, metadata) {
|
||||
const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
|
||||
let namespace = this.options.defaultNamespace;
|
||||
let errorName = errorIdentifier;
|
||||
if (errorIdentifier.includes("#")) {
|
||||
[namespace, errorName] = errorIdentifier.split("#");
|
||||
}
|
||||
const registry = TypeRegistry.for(namespace);
|
||||
let errorSchema;
|
||||
try {
|
||||
errorSchema = registry.getSchema(errorIdentifier);
|
||||
}
|
||||
catch (e) {
|
||||
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
||||
if (baseExceptionSchema) {
|
||||
const ErrorCtor = baseExceptionSchema.ctor;
|
||||
throw Object.assign(new ErrorCtor(errorName), dataObject);
|
||||
}
|
||||
throw new Error(errorName);
|
||||
}
|
||||
const ns = NormalizedSchema.of(errorSchema);
|
||||
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
||||
const exception = new errorSchema.ctor(message);
|
||||
await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
|
||||
const output = {};
|
||||
for (const [name, member] of ns.structIterator()) {
|
||||
const target = member.getMergedTraits().jsonName ?? name;
|
||||
output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
|
||||
}
|
||||
Object.assign(exception, {
|
||||
$metadata: metadata,
|
||||
$response: response,
|
||||
$fault: ns.getMergedTraits().error,
|
||||
message,
|
||||
...output,
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+118
@@ -0,0 +1,118 @@
|
||||
import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
|
||||
import { NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
|
||||
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
||||
import { JsonCodec } from "./JsonCodec";
|
||||
import { loadRestJsonErrorCode } from "./parseJsonBody";
|
||||
export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
||||
serializer;
|
||||
deserializer;
|
||||
codec;
|
||||
constructor({ defaultNamespace }) {
|
||||
super({
|
||||
defaultNamespace,
|
||||
});
|
||||
const settings = {
|
||||
timestampFormat: {
|
||||
useTrait: true,
|
||||
default: SCHEMA.TIMESTAMP_EPOCH_SECONDS,
|
||||
},
|
||||
httpBindings: true,
|
||||
jsonName: true,
|
||||
};
|
||||
this.codec = new JsonCodec(settings);
|
||||
this.serializer = new HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
|
||||
this.deserializer = new HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
|
||||
}
|
||||
getShapeId() {
|
||||
return "aws.protocols#restJson1";
|
||||
}
|
||||
getPayloadCodec() {
|
||||
return this.codec;
|
||||
}
|
||||
setSerdeContext(serdeContext) {
|
||||
this.codec.setSerdeContext(serdeContext);
|
||||
super.setSerdeContext(serdeContext);
|
||||
}
|
||||
async serializeRequest(operationSchema, input, context) {
|
||||
const request = await super.serializeRequest(operationSchema, input, context);
|
||||
const inputSchema = NormalizedSchema.of(operationSchema.input);
|
||||
const members = inputSchema.getMemberSchemas();
|
||||
if (!request.headers["content-type"]) {
|
||||
const httpPayloadMember = Object.values(members).find((m) => {
|
||||
return !!m.getMergedTraits().httpPayload;
|
||||
});
|
||||
if (httpPayloadMember) {
|
||||
const mediaType = httpPayloadMember.getMergedTraits().mediaType;
|
||||
if (mediaType) {
|
||||
request.headers["content-type"] = mediaType;
|
||||
}
|
||||
else if (httpPayloadMember.isStringSchema()) {
|
||||
request.headers["content-type"] = "text/plain";
|
||||
}
|
||||
else if (httpPayloadMember.isBlobSchema()) {
|
||||
request.headers["content-type"] = "application/octet-stream";
|
||||
}
|
||||
else {
|
||||
request.headers["content-type"] = "application/json";
|
||||
}
|
||||
}
|
||||
else if (!inputSchema.isUnitSchema()) {
|
||||
const hasBody = Object.values(members).find((m) => {
|
||||
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
|
||||
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
|
||||
});
|
||||
if (hasBody) {
|
||||
request.headers["content-type"] = "application/json";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (request.headers["content-type"] && !request.body) {
|
||||
request.body = "{}";
|
||||
}
|
||||
if (request.body) {
|
||||
try {
|
||||
request.headers["content-length"] = String(calculateBodyLength(request.body));
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
return request;
|
||||
}
|
||||
async handleError(operationSchema, context, response, dataObject, metadata) {
|
||||
const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
|
||||
let namespace = this.options.defaultNamespace;
|
||||
let errorName = errorIdentifier;
|
||||
if (errorIdentifier.includes("#")) {
|
||||
[namespace, errorName] = errorIdentifier.split("#");
|
||||
}
|
||||
const registry = TypeRegistry.for(namespace);
|
||||
let errorSchema;
|
||||
try {
|
||||
errorSchema = registry.getSchema(errorIdentifier);
|
||||
}
|
||||
catch (e) {
|
||||
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
||||
if (baseExceptionSchema) {
|
||||
const ErrorCtor = baseExceptionSchema.ctor;
|
||||
throw Object.assign(new ErrorCtor(errorName), dataObject);
|
||||
}
|
||||
throw new Error(errorName);
|
||||
}
|
||||
const ns = NormalizedSchema.of(errorSchema);
|
||||
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
||||
const exception = new errorSchema.ctor(message);
|
||||
await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
|
||||
const output = {};
|
||||
for (const [name, member] of ns.structIterator()) {
|
||||
const target = member.getMergedTraits().jsonName ?? name;
|
||||
output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
|
||||
}
|
||||
Object.assign(exception, {
|
||||
$metadata: metadata,
|
||||
$response: response,
|
||||
$fault: ns.getMergedTraits().error,
|
||||
message,
|
||||
...output,
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
import { JsonShapeDeserializer } from "./JsonShapeDeserializer";
|
||||
import { JsonShapeSerializer } from "./JsonShapeSerializer";
|
||||
export class JsonCodec extends SerdeContextConfig {
|
||||
settings;
|
||||
constructor(settings) {
|
||||
super();
|
||||
this.settings = settings;
|
||||
}
|
||||
createSerializer() {
|
||||
const serializer = new JsonShapeSerializer(this.settings);
|
||||
serializer.setSerdeContext(this.serdeContext);
|
||||
return serializer;
|
||||
}
|
||||
createDeserializer() {
|
||||
const deserializer = new JsonShapeDeserializer(this.settings);
|
||||
deserializer.setSerdeContext(this.serdeContext);
|
||||
return deserializer;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+105
@@ -0,0 +1,105 @@
|
||||
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
||||
import { LazyJsonString, NumericValue, parseEpochTimestamp, parseRfc3339DateTimeWithOffset, parseRfc7231DateTime, } from "@smithy/core/serde";
|
||||
import { fromBase64 } from "@smithy/util-base64";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
import { jsonReviver } from "./jsonReviver";
|
||||
import { parseJsonBody } from "./parseJsonBody";
|
||||
export class JsonShapeDeserializer extends SerdeContextConfig {
|
||||
settings;
|
||||
constructor(settings) {
|
||||
super();
|
||||
this.settings = settings;
|
||||
}
|
||||
async read(schema, data) {
|
||||
return this._read(schema, typeof data === "string" ? JSON.parse(data, jsonReviver) : await parseJsonBody(data, this.serdeContext));
|
||||
}
|
||||
readObject(schema, data) {
|
||||
return this._read(schema, data);
|
||||
}
|
||||
_read(schema, value) {
|
||||
const isObject = value !== null && typeof value === "object";
|
||||
const ns = NormalizedSchema.of(schema);
|
||||
if (ns.isListSchema() && Array.isArray(value)) {
|
||||
const listMember = ns.getValueSchema();
|
||||
const out = [];
|
||||
const sparse = !!ns.getMergedTraits().sparse;
|
||||
for (const item of value) {
|
||||
if (sparse || item != null) {
|
||||
out.push(this._read(listMember, item));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
else if (ns.isMapSchema() && isObject) {
|
||||
const mapMember = ns.getValueSchema();
|
||||
const out = {};
|
||||
const sparse = !!ns.getMergedTraits().sparse;
|
||||
for (const [_k, _v] of Object.entries(value)) {
|
||||
if (sparse || _v != null) {
|
||||
out[_k] = this._read(mapMember, _v);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
else if (ns.isStructSchema() && isObject) {
|
||||
const out = {};
|
||||
for (const [memberName, memberSchema] of ns.structIterator()) {
|
||||
const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
|
||||
const deserializedValue = this._read(memberSchema, value[fromKey]);
|
||||
if (deserializedValue != null) {
|
||||
out[memberName] = deserializedValue;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
if (ns.isBlobSchema() && typeof value === "string") {
|
||||
return fromBase64(value);
|
||||
}
|
||||
const mediaType = ns.getMergedTraits().mediaType;
|
||||
if (ns.isStringSchema() && typeof value === "string" && mediaType) {
|
||||
const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
|
||||
if (isJson) {
|
||||
return LazyJsonString.from(value);
|
||||
}
|
||||
}
|
||||
if (ns.isTimestampSchema()) {
|
||||
const options = this.settings.timestampFormat;
|
||||
const format = options.useTrait
|
||||
? ns.getSchema() === SCHEMA.TIMESTAMP_DEFAULT
|
||||
? options.default
|
||||
: ns.getSchema() ?? options.default
|
||||
: options.default;
|
||||
switch (format) {
|
||||
case SCHEMA.TIMESTAMP_DATE_TIME:
|
||||
return parseRfc3339DateTimeWithOffset(value);
|
||||
case SCHEMA.TIMESTAMP_HTTP_DATE:
|
||||
return parseRfc7231DateTime(value);
|
||||
case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
|
||||
return parseEpochTimestamp(value);
|
||||
default:
|
||||
console.warn("Missing timestamp format, parsing value with Date constructor:", value);
|
||||
return new Date(value);
|
||||
}
|
||||
}
|
||||
if (ns.isBigIntegerSchema() && (typeof value === "number" || typeof value === "string")) {
|
||||
return BigInt(value);
|
||||
}
|
||||
if (ns.isBigDecimalSchema() && value != undefined) {
|
||||
if (value instanceof NumericValue) {
|
||||
return value;
|
||||
}
|
||||
return new NumericValue(String(value), "bigDecimal");
|
||||
}
|
||||
if (ns.isNumericSchema() && typeof value === "string") {
|
||||
switch (value) {
|
||||
case "Infinity":
|
||||
return Infinity;
|
||||
case "-Infinity":
|
||||
return -Infinity;
|
||||
case "NaN":
|
||||
return NaN;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+106
@@ -0,0 +1,106 @@
|
||||
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
||||
import { dateToUtcString } from "@smithy/core/serde";
|
||||
import { LazyJsonString } from "@smithy/core/serde";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
import { JsonReplacer } from "./jsonReplacer";
|
||||
export class JsonShapeSerializer extends SerdeContextConfig {
|
||||
settings;
|
||||
buffer;
|
||||
rootSchema;
|
||||
constructor(settings) {
|
||||
super();
|
||||
this.settings = settings;
|
||||
}
|
||||
write(schema, value) {
|
||||
this.rootSchema = NormalizedSchema.of(schema);
|
||||
this.buffer = this._write(this.rootSchema, value);
|
||||
}
|
||||
flush() {
|
||||
if (this.rootSchema?.isStructSchema() || this.rootSchema?.isDocumentSchema()) {
|
||||
const replacer = new JsonReplacer();
|
||||
return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
|
||||
}
|
||||
return this.buffer;
|
||||
}
|
||||
_write(schema, value, container) {
|
||||
const isObject = value !== null && typeof value === "object";
|
||||
const ns = NormalizedSchema.of(schema);
|
||||
if (ns.isListSchema() && Array.isArray(value)) {
|
||||
const listMember = ns.getValueSchema();
|
||||
const out = [];
|
||||
const sparse = !!ns.getMergedTraits().sparse;
|
||||
for (const item of value) {
|
||||
if (sparse || item != null) {
|
||||
out.push(this._write(listMember, item));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
else if (ns.isMapSchema() && isObject) {
|
||||
const mapMember = ns.getValueSchema();
|
||||
const out = {};
|
||||
const sparse = !!ns.getMergedTraits().sparse;
|
||||
for (const [_k, _v] of Object.entries(value)) {
|
||||
if (sparse || _v != null) {
|
||||
out[_k] = this._write(mapMember, _v);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
else if (ns.isStructSchema() && isObject) {
|
||||
const out = {};
|
||||
for (const [memberName, memberSchema] of ns.structIterator()) {
|
||||
const targetKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
|
||||
const serializableValue = this._write(memberSchema, value[memberName], ns);
|
||||
if (serializableValue !== undefined) {
|
||||
out[targetKey] = serializableValue;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
if (value === null && container?.isStructSchema()) {
|
||||
return void 0;
|
||||
}
|
||||
if (ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) {
|
||||
if (ns === this.rootSchema) {
|
||||
return value;
|
||||
}
|
||||
if (!this.serdeContext?.base64Encoder) {
|
||||
throw new Error("Missing base64Encoder in serdeContext");
|
||||
}
|
||||
return this.serdeContext?.base64Encoder(value);
|
||||
}
|
||||
if (ns.isTimestampSchema() && value instanceof Date) {
|
||||
const options = this.settings.timestampFormat;
|
||||
const format = options.useTrait
|
||||
? ns.getSchema() === SCHEMA.TIMESTAMP_DEFAULT
|
||||
? options.default
|
||||
: ns.getSchema() ?? options.default
|
||||
: options.default;
|
||||
switch (format) {
|
||||
case SCHEMA.TIMESTAMP_DATE_TIME:
|
||||
return value.toISOString().replace(".000Z", "Z");
|
||||
case SCHEMA.TIMESTAMP_HTTP_DATE:
|
||||
return dateToUtcString(value);
|
||||
case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
|
||||
return value.getTime() / 1000;
|
||||
default:
|
||||
console.warn("Missing timestamp format, using epoch seconds", value);
|
||||
return value.getTime() / 1000;
|
||||
}
|
||||
}
|
||||
if (ns.isNumericSchema() && typeof value === "number") {
|
||||
if (Math.abs(value) === Infinity || isNaN(value)) {
|
||||
return String(value);
|
||||
}
|
||||
}
|
||||
const mediaType = ns.getMergedTraits().mediaType;
|
||||
if (ns.isStringSchema() && typeof value === "string" && mediaType) {
|
||||
const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
|
||||
if (isJson) {
|
||||
return LazyJsonString.from(value);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
import { expectUnion } from "@smithy/smithy-client";
|
||||
export const awsExpectUnion = (value) => {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value === "object" && "__type" in value) {
|
||||
delete value.__type;
|
||||
}
|
||||
return expectUnion(value);
|
||||
};
|
||||
Generated
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
import { NumericValue } from "@smithy/core/serde";
|
||||
const NUMERIC_CONTROL_CHAR = String.fromCharCode(925);
|
||||
export class JsonReplacer {
|
||||
values = new Map();
|
||||
counter = 0;
|
||||
stage = 0;
|
||||
createReplacer() {
|
||||
if (this.stage === 1) {
|
||||
throw new Error("@aws-sdk/core/protocols - JsonReplacer already created.");
|
||||
}
|
||||
if (this.stage === 2) {
|
||||
throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
|
||||
}
|
||||
this.stage = 1;
|
||||
return (key, value) => {
|
||||
if (value instanceof NumericValue) {
|
||||
const v = `${NUMERIC_CONTROL_CHAR + +"nv" + this.counter++}_` + value.string;
|
||||
this.values.set(`"${v}"`, value.string);
|
||||
return v;
|
||||
}
|
||||
if (typeof value === "bigint") {
|
||||
const s = value.toString();
|
||||
const v = `${NUMERIC_CONTROL_CHAR + "b" + this.counter++}_` + s;
|
||||
this.values.set(`"${v}"`, s);
|
||||
return v;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
}
|
||||
replaceInJson(json) {
|
||||
if (this.stage === 0) {
|
||||
throw new Error("@aws-sdk/core/protocols - JsonReplacer not created yet.");
|
||||
}
|
||||
if (this.stage === 2) {
|
||||
throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
|
||||
}
|
||||
this.stage = 2;
|
||||
if (this.counter === 0) {
|
||||
return json;
|
||||
}
|
||||
for (const [key, value] of this.values) {
|
||||
json = json.replace(key, value);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import { NumericValue } from "@smithy/core/serde";
|
||||
export function jsonReviver(key, value, context) {
|
||||
if (context?.source) {
|
||||
const numericString = context.source;
|
||||
if (typeof value === "number") {
|
||||
if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER || numericString !== String(value)) {
|
||||
const isFractional = numericString.includes(".");
|
||||
if (isFractional) {
|
||||
return new NumericValue(numericString, "bigDecimal");
|
||||
}
|
||||
else {
|
||||
return BigInt(numericString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
Generated
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
import { collectBodyString } from "../common";
|
||||
export const parseJsonBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
|
||||
if (encoded.length) {
|
||||
try {
|
||||
return JSON.parse(encoded);
|
||||
}
|
||||
catch (e) {
|
||||
if (e?.name === "SyntaxError") {
|
||||
Object.defineProperty(e, "$responseBodyText", {
|
||||
value: encoded,
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
});
|
||||
export const parseJsonErrorBody = async (errorBody, context) => {
|
||||
const value = await parseJsonBody(errorBody, context);
|
||||
value.message = value.message ?? value.Message;
|
||||
return value;
|
||||
};
|
||||
export const loadRestJsonErrorCode = (output, data) => {
|
||||
const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
|
||||
const sanitizeErrorCode = (rawValue) => {
|
||||
let cleanValue = rawValue;
|
||||
if (typeof cleanValue === "number") {
|
||||
cleanValue = cleanValue.toString();
|
||||
}
|
||||
if (cleanValue.indexOf(",") >= 0) {
|
||||
cleanValue = cleanValue.split(",")[0];
|
||||
}
|
||||
if (cleanValue.indexOf(":") >= 0) {
|
||||
cleanValue = cleanValue.split(":")[0];
|
||||
}
|
||||
if (cleanValue.indexOf("#") >= 0) {
|
||||
cleanValue = cleanValue.split("#")[1];
|
||||
}
|
||||
return cleanValue;
|
||||
};
|
||||
const headerKey = findKey(output.headers, "x-amzn-errortype");
|
||||
if (headerKey !== undefined) {
|
||||
return sanitizeErrorCode(output.headers[headerKey]);
|
||||
}
|
||||
if (data && typeof data === "object") {
|
||||
const codeKey = findKey(data, "code");
|
||||
if (codeKey && data[codeKey] !== undefined) {
|
||||
return sanitizeErrorCode(data[codeKey]);
|
||||
}
|
||||
if (data["__type"] !== undefined) {
|
||||
return sanitizeErrorCode(data["__type"]);
|
||||
}
|
||||
}
|
||||
};
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import { AwsQueryProtocol } from "./AwsQueryProtocol";
|
||||
export class AwsEc2QueryProtocol extends AwsQueryProtocol {
|
||||
options;
|
||||
constructor(options) {
|
||||
super(options);
|
||||
this.options = options;
|
||||
const ec2Settings = {
|
||||
capitalizeKeys: true,
|
||||
flattenLists: true,
|
||||
serializeEmptyLists: false,
|
||||
};
|
||||
Object.assign(this.serializer.settings, ec2Settings);
|
||||
}
|
||||
useNestedResult() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+147
@@ -0,0 +1,147 @@
|
||||
import { collectBody, RpcProtocol } from "@smithy/core/protocols";
|
||||
import { deref, NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
|
||||
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
||||
import { XmlShapeDeserializer } from "../xml/XmlShapeDeserializer";
|
||||
import { QueryShapeSerializer } from "./QueryShapeSerializer";
|
||||
export class AwsQueryProtocol extends RpcProtocol {
|
||||
options;
|
||||
serializer;
|
||||
deserializer;
|
||||
constructor(options) {
|
||||
super({
|
||||
defaultNamespace: options.defaultNamespace,
|
||||
});
|
||||
this.options = options;
|
||||
const settings = {
|
||||
timestampFormat: {
|
||||
useTrait: true,
|
||||
default: SCHEMA.TIMESTAMP_DATE_TIME,
|
||||
},
|
||||
httpBindings: false,
|
||||
xmlNamespace: options.xmlNamespace,
|
||||
serviceNamespace: options.defaultNamespace,
|
||||
serializeEmptyLists: true,
|
||||
};
|
||||
this.serializer = new QueryShapeSerializer(settings);
|
||||
this.deserializer = new XmlShapeDeserializer(settings);
|
||||
}
|
||||
getShapeId() {
|
||||
return "aws.protocols#awsQuery";
|
||||
}
|
||||
setSerdeContext(serdeContext) {
|
||||
this.serializer.setSerdeContext(serdeContext);
|
||||
this.deserializer.setSerdeContext(serdeContext);
|
||||
}
|
||||
getPayloadCodec() {
|
||||
throw new Error("AWSQuery protocol has no payload codec.");
|
||||
}
|
||||
async serializeRequest(operationSchema, input, context) {
|
||||
const request = await super.serializeRequest(operationSchema, input, context);
|
||||
if (!request.path.endsWith("/")) {
|
||||
request.path += "/";
|
||||
}
|
||||
Object.assign(request.headers, {
|
||||
"content-type": `application/x-www-form-urlencoded`,
|
||||
});
|
||||
if (deref(operationSchema.input) === "unit" || !request.body) {
|
||||
request.body = "";
|
||||
}
|
||||
request.body = `Action=${operationSchema.name.split("#")[1]}&Version=${this.options.version}` + request.body;
|
||||
if (request.body.endsWith("&")) {
|
||||
request.body = request.body.slice(-1);
|
||||
}
|
||||
try {
|
||||
request.headers["content-length"] = String(calculateBodyLength(request.body));
|
||||
}
|
||||
catch (e) { }
|
||||
return request;
|
||||
}
|
||||
async deserializeResponse(operationSchema, context, response) {
|
||||
const deserializer = this.deserializer;
|
||||
const ns = NormalizedSchema.of(operationSchema.output);
|
||||
const dataObject = {};
|
||||
if (response.statusCode >= 300) {
|
||||
const bytes = await collectBody(response.body, context);
|
||||
if (bytes.byteLength > 0) {
|
||||
Object.assign(dataObject, await deserializer.read(SCHEMA.DOCUMENT, bytes));
|
||||
}
|
||||
await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
|
||||
}
|
||||
for (const header in response.headers) {
|
||||
const value = response.headers[header];
|
||||
delete response.headers[header];
|
||||
response.headers[header.toLowerCase()] = value;
|
||||
}
|
||||
const awsQueryResultKey = ns.isStructSchema() && this.useNestedResult() ? operationSchema.name.split("#")[1] + "Result" : undefined;
|
||||
const bytes = await collectBody(response.body, context);
|
||||
if (bytes.byteLength > 0) {
|
||||
Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
|
||||
}
|
||||
const output = {
|
||||
$metadata: this.deserializeMetadata(response),
|
||||
...dataObject,
|
||||
};
|
||||
return output;
|
||||
}
|
||||
useNestedResult() {
|
||||
return true;
|
||||
}
|
||||
async handleError(operationSchema, context, response, dataObject, metadata) {
|
||||
const errorIdentifier = this.loadQueryErrorCode(response, dataObject) ?? "Unknown";
|
||||
let namespace = this.options.defaultNamespace;
|
||||
let errorName = errorIdentifier;
|
||||
if (errorIdentifier.includes("#")) {
|
||||
[namespace, errorName] = errorIdentifier.split("#");
|
||||
}
|
||||
const errorDataSource = this.loadQueryError(dataObject);
|
||||
const registry = TypeRegistry.for(namespace);
|
||||
let errorSchema;
|
||||
try {
|
||||
errorSchema = registry.find((schema) => NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName);
|
||||
if (!errorSchema) {
|
||||
errorSchema = registry.getSchema(errorIdentifier);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
||||
if (baseExceptionSchema) {
|
||||
const ErrorCtor = baseExceptionSchema.ctor;
|
||||
throw Object.assign(new ErrorCtor(errorName), errorDataSource);
|
||||
}
|
||||
throw new Error(errorName);
|
||||
}
|
||||
const ns = NormalizedSchema.of(errorSchema);
|
||||
const message = this.loadQueryErrorMessage(dataObject);
|
||||
const exception = new errorSchema.ctor(message);
|
||||
const output = {};
|
||||
for (const [name, member] of ns.structIterator()) {
|
||||
const target = member.getMergedTraits().xmlName ?? name;
|
||||
const value = errorDataSource[target] ?? dataObject[target];
|
||||
output[name] = this.deserializer.readSchema(member, value);
|
||||
}
|
||||
Object.assign(exception, {
|
||||
$metadata: metadata,
|
||||
$response: response,
|
||||
$fault: ns.getMergedTraits().error,
|
||||
message,
|
||||
...output,
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
loadQueryErrorCode(output, data) {
|
||||
const code = (data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error)?.Code;
|
||||
if (code !== undefined) {
|
||||
return code;
|
||||
}
|
||||
if (output.statusCode == 404) {
|
||||
return "NotFound";
|
||||
}
|
||||
}
|
||||
loadQueryError(data) {
|
||||
return data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error;
|
||||
}
|
||||
loadQueryErrorMessage(data) {
|
||||
const errorData = this.loadQueryError(data);
|
||||
return errorData?.message ?? errorData?.Message ?? data.message ?? data.Message ?? "Unknown";
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Generated
Vendored
+152
@@ -0,0 +1,152 @@
|
||||
import { determineTimestampFormat, extendedEncodeURIComponent } from "@smithy/core/protocols";
|
||||
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
||||
import { NumericValue } from "@smithy/core/serde";
|
||||
import { dateToUtcString } from "@smithy/smithy-client";
|
||||
import { toBase64 } from "@smithy/util-base64";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
export class QueryShapeSerializer extends SerdeContextConfig {
|
||||
settings;
|
||||
buffer;
|
||||
constructor(settings) {
|
||||
super();
|
||||
this.settings = settings;
|
||||
}
|
||||
write(schema, value, prefix = "") {
|
||||
if (this.buffer === undefined) {
|
||||
this.buffer = "";
|
||||
}
|
||||
const ns = NormalizedSchema.of(schema);
|
||||
if (prefix && !prefix.endsWith(".")) {
|
||||
prefix += ".";
|
||||
}
|
||||
if (ns.isBlobSchema()) {
|
||||
if (typeof value === "string" || value instanceof Uint8Array) {
|
||||
this.writeKey(prefix);
|
||||
this.writeValue((this.serdeContext?.base64Encoder ?? toBase64)(value));
|
||||
}
|
||||
}
|
||||
else if (ns.isBooleanSchema() || ns.isNumericSchema() || ns.isStringSchema()) {
|
||||
if (value != null) {
|
||||
this.writeKey(prefix);
|
||||
this.writeValue(String(value));
|
||||
}
|
||||
}
|
||||
else if (ns.isBigIntegerSchema()) {
|
||||
if (value != null) {
|
||||
this.writeKey(prefix);
|
||||
this.writeValue(String(value));
|
||||
}
|
||||
}
|
||||
else if (ns.isBigDecimalSchema()) {
|
||||
if (value != null) {
|
||||
this.writeKey(prefix);
|
||||
this.writeValue(value instanceof NumericValue ? value.string : String(value));
|
||||
}
|
||||
}
|
||||
else if (ns.isTimestampSchema()) {
|
||||
if (value instanceof Date) {
|
||||
this.writeKey(prefix);
|
||||
const format = determineTimestampFormat(ns, this.settings);
|
||||
switch (format) {
|
||||
case SCHEMA.TIMESTAMP_DATE_TIME:
|
||||
this.writeValue(value.toISOString().replace(".000Z", "Z"));
|
||||
break;
|
||||
case SCHEMA.TIMESTAMP_HTTP_DATE:
|
||||
this.writeValue(dateToUtcString(value));
|
||||
break;
|
||||
case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
|
||||
this.writeValue(String(value.getTime() / 1000));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ns.isDocumentSchema()) {
|
||||
throw new Error(`@aws-sdk/core/protocols - QuerySerializer unsupported document type ${ns.getName(true)}`);
|
||||
}
|
||||
else if (ns.isListSchema()) {
|
||||
if (Array.isArray(value)) {
|
||||
if (value.length === 0) {
|
||||
if (this.settings.serializeEmptyLists) {
|
||||
this.writeKey(prefix);
|
||||
this.writeValue("");
|
||||
}
|
||||
}
|
||||
else {
|
||||
const member = ns.getValueSchema();
|
||||
const flat = this.settings.flattenLists || ns.getMergedTraits().xmlFlattened;
|
||||
let i = 1;
|
||||
for (const item of value) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
const suffix = this.getKey("member", member.getMergedTraits().xmlName);
|
||||
const key = flat ? `${prefix}${i}` : `${prefix}${suffix}.${i}`;
|
||||
this.write(member, item, key);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ns.isMapSchema()) {
|
||||
if (value && typeof value === "object") {
|
||||
const keySchema = ns.getKeySchema();
|
||||
const memberSchema = ns.getValueSchema();
|
||||
const flat = ns.getMergedTraits().xmlFlattened;
|
||||
let i = 1;
|
||||
for (const [k, v] of Object.entries(value)) {
|
||||
if (v == null) {
|
||||
continue;
|
||||
}
|
||||
const keySuffix = this.getKey("key", keySchema.getMergedTraits().xmlName);
|
||||
const key = flat ? `${prefix}${i}.${keySuffix}` : `${prefix}entry.${i}.${keySuffix}`;
|
||||
const valueSuffix = this.getKey("value", memberSchema.getMergedTraits().xmlName);
|
||||
const valueKey = flat ? `${prefix}${i}.${valueSuffix}` : `${prefix}entry.${i}.${valueSuffix}`;
|
||||
this.write(keySchema, k, key);
|
||||
this.write(memberSchema, v, valueKey);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ns.isStructSchema()) {
|
||||
if (value && typeof value === "object") {
|
||||
for (const [memberName, member] of ns.structIterator()) {
|
||||
if (value[memberName] == null) {
|
||||
continue;
|
||||
}
|
||||
const suffix = this.getKey(memberName, member.getMergedTraits().xmlName);
|
||||
const key = `${prefix}${suffix}`;
|
||||
this.write(member, value[memberName], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ns.isUnitSchema()) {
|
||||
}
|
||||
else {
|
||||
throw new Error(`@aws-sdk/core/protocols - QuerySerializer unrecognized schema type ${ns.getName(true)}`);
|
||||
}
|
||||
}
|
||||
flush() {
|
||||
if (this.buffer === undefined) {
|
||||
throw new Error("@aws-sdk/core/protocols - QuerySerializer cannot flush with nothing written to buffer.");
|
||||
}
|
||||
const str = this.buffer;
|
||||
delete this.buffer;
|
||||
return str;
|
||||
}
|
||||
getKey(memberName, xmlName) {
|
||||
const key = xmlName ?? memberName;
|
||||
if (this.settings.capitalizeKeys) {
|
||||
return key[0].toUpperCase() + key.slice(1);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
writeKey(key) {
|
||||
if (key.endsWith(".")) {
|
||||
key = key.slice(0, key.length - 1);
|
||||
}
|
||||
this.buffer += `&${extendedEncodeURIComponent(key)}=`;
|
||||
}
|
||||
writeValue(value) {
|
||||
this.buffer += extendedEncodeURIComponent(value);
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+126
@@ -0,0 +1,126 @@
|
||||
import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
|
||||
import { NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
|
||||
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
||||
import { loadRestXmlErrorCode } from "./parseXmlBody";
|
||||
import { XmlCodec } from "./XmlCodec";
|
||||
export class AwsRestXmlProtocol extends HttpBindingProtocol {
|
||||
codec;
|
||||
serializer;
|
||||
deserializer;
|
||||
constructor(options) {
|
||||
super(options);
|
||||
const settings = {
|
||||
timestampFormat: {
|
||||
useTrait: true,
|
||||
default: SCHEMA.TIMESTAMP_DATE_TIME,
|
||||
},
|
||||
httpBindings: true,
|
||||
xmlNamespace: options.xmlNamespace,
|
||||
serviceNamespace: options.defaultNamespace,
|
||||
};
|
||||
this.codec = new XmlCodec(settings);
|
||||
this.serializer = new HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
|
||||
this.deserializer = new HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
|
||||
}
|
||||
getPayloadCodec() {
|
||||
return this.codec;
|
||||
}
|
||||
getShapeId() {
|
||||
return "aws.protocols#restXml";
|
||||
}
|
||||
async serializeRequest(operationSchema, input, context) {
|
||||
const request = await super.serializeRequest(operationSchema, input, context);
|
||||
const ns = NormalizedSchema.of(operationSchema.input);
|
||||
const members = ns.getMemberSchemas();
|
||||
request.path =
|
||||
String(request.path)
|
||||
.split("/")
|
||||
.filter((segment) => {
|
||||
return segment !== "{Bucket}";
|
||||
})
|
||||
.join("/") || "/";
|
||||
if (!request.headers["content-type"]) {
|
||||
const httpPayloadMember = Object.values(members).find((m) => {
|
||||
return !!m.getMergedTraits().httpPayload;
|
||||
});
|
||||
if (httpPayloadMember) {
|
||||
const mediaType = httpPayloadMember.getMergedTraits().mediaType;
|
||||
if (mediaType) {
|
||||
request.headers["content-type"] = mediaType;
|
||||
}
|
||||
else if (httpPayloadMember.isStringSchema()) {
|
||||
request.headers["content-type"] = "text/plain";
|
||||
}
|
||||
else if (httpPayloadMember.isBlobSchema()) {
|
||||
request.headers["content-type"] = "application/octet-stream";
|
||||
}
|
||||
else {
|
||||
request.headers["content-type"] = "application/xml";
|
||||
}
|
||||
}
|
||||
else if (!ns.isUnitSchema()) {
|
||||
const hasBody = Object.values(members).find((m) => {
|
||||
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
|
||||
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
|
||||
});
|
||||
if (hasBody) {
|
||||
request.headers["content-type"] = "application/xml";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (request.headers["content-type"] === "application/xml") {
|
||||
if (typeof request.body === "string") {
|
||||
request.body = '<?xml version="1.0" encoding="UTF-8"?>' + request.body;
|
||||
}
|
||||
}
|
||||
if (request.body) {
|
||||
try {
|
||||
request.headers["content-length"] = String(calculateBodyLength(request.body));
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
return request;
|
||||
}
|
||||
async deserializeResponse(operationSchema, context, response) {
|
||||
return super.deserializeResponse(operationSchema, context, response);
|
||||
}
|
||||
async handleError(operationSchema, context, response, dataObject, metadata) {
|
||||
const errorIdentifier = loadRestXmlErrorCode(response, dataObject) ?? "Unknown";
|
||||
let namespace = this.options.defaultNamespace;
|
||||
let errorName = errorIdentifier;
|
||||
if (errorIdentifier.includes("#")) {
|
||||
[namespace, errorName] = errorIdentifier.split("#");
|
||||
}
|
||||
const registry = TypeRegistry.for(namespace);
|
||||
let errorSchema;
|
||||
try {
|
||||
errorSchema = registry.getSchema(errorIdentifier);
|
||||
}
|
||||
catch (e) {
|
||||
const baseExceptionSchema = TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace).getBaseException();
|
||||
if (baseExceptionSchema) {
|
||||
const ErrorCtor = baseExceptionSchema.ctor;
|
||||
throw Object.assign(new ErrorCtor(errorName), dataObject);
|
||||
}
|
||||
throw new Error(errorName);
|
||||
}
|
||||
const ns = NormalizedSchema.of(errorSchema);
|
||||
const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
|
||||
const exception = new errorSchema.ctor(message);
|
||||
await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
|
||||
const output = {};
|
||||
for (const [name, member] of ns.structIterator()) {
|
||||
const target = member.getMergedTraits().xmlName ?? name;
|
||||
const value = dataObject.Error?.[target] ?? dataObject[target];
|
||||
output[name] = this.codec.createDeserializer().readSchema(member, value);
|
||||
}
|
||||
Object.assign(exception, {
|
||||
$metadata: metadata,
|
||||
$response: response,
|
||||
$fault: ns.getMergedTraits().error,
|
||||
message,
|
||||
...output,
|
||||
});
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
import { XmlShapeDeserializer } from "./XmlShapeDeserializer";
|
||||
import { XmlShapeSerializer } from "./XmlShapeSerializer";
|
||||
export class XmlCodec extends SerdeContextConfig {
|
||||
settings;
|
||||
constructor(settings) {
|
||||
super();
|
||||
this.settings = settings;
|
||||
}
|
||||
createSerializer() {
|
||||
const serializer = new XmlShapeSerializer(this.settings);
|
||||
serializer.setSerdeContext(this.serdeContext);
|
||||
return serializer;
|
||||
}
|
||||
createDeserializer() {
|
||||
const deserializer = new XmlShapeDeserializer(this.settings);
|
||||
deserializer.setSerdeContext(this.serdeContext);
|
||||
return deserializer;
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+154
@@ -0,0 +1,154 @@
|
||||
import { FromStringShapeDeserializer } from "@smithy/core/protocols";
|
||||
import { NormalizedSchema } from "@smithy/core/schema";
|
||||
import { getValueFromTextNode } from "@smithy/smithy-client";
|
||||
import { toUtf8 } from "@smithy/util-utf8";
|
||||
import { XMLParser } from "fast-xml-parser";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
export class XmlShapeDeserializer extends SerdeContextConfig {
|
||||
settings;
|
||||
stringDeserializer;
|
||||
constructor(settings) {
|
||||
super();
|
||||
this.settings = settings;
|
||||
this.stringDeserializer = new FromStringShapeDeserializer(settings);
|
||||
}
|
||||
setSerdeContext(serdeContext) {
|
||||
this.serdeContext = serdeContext;
|
||||
this.stringDeserializer.setSerdeContext(serdeContext);
|
||||
}
|
||||
read(schema, bytes, key) {
|
||||
const ns = NormalizedSchema.of(schema);
|
||||
const memberSchemas = ns.getMemberSchemas();
|
||||
const isEventPayload = ns.isStructSchema() &&
|
||||
ns.isMemberSchema() &&
|
||||
!!Object.values(memberSchemas).find((memberNs) => {
|
||||
return !!memberNs.getMemberTraits().eventPayload;
|
||||
});
|
||||
if (isEventPayload) {
|
||||
const output = {};
|
||||
const memberName = Object.keys(memberSchemas)[0];
|
||||
const eventMemberSchema = memberSchemas[memberName];
|
||||
if (eventMemberSchema.isBlobSchema()) {
|
||||
output[memberName] = bytes;
|
||||
}
|
||||
else {
|
||||
output[memberName] = this.read(memberSchemas[memberName], bytes);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
const xmlString = (this.serdeContext?.utf8Encoder ?? toUtf8)(bytes);
|
||||
const parsedObject = this.parseXml(xmlString);
|
||||
return this.readSchema(schema, key ? parsedObject[key] : parsedObject);
|
||||
}
|
||||
readSchema(_schema, value) {
|
||||
const ns = NormalizedSchema.of(_schema);
|
||||
const traits = ns.getMergedTraits();
|
||||
const schema = ns.getSchema();
|
||||
if (ns.isListSchema() && !Array.isArray(value)) {
|
||||
return this.readSchema(schema, [value]);
|
||||
}
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
if (typeof value === "object") {
|
||||
const sparse = !!traits.sparse;
|
||||
const flat = !!traits.xmlFlattened;
|
||||
if (ns.isListSchema()) {
|
||||
const listValue = ns.getValueSchema();
|
||||
const buffer = [];
|
||||
const sourceKey = listValue.getMergedTraits().xmlName ?? "member";
|
||||
const source = flat ? value : (value[0] ?? value)[sourceKey];
|
||||
const sourceArray = Array.isArray(source) ? source : [source];
|
||||
for (const v of sourceArray) {
|
||||
if (v != null || sparse) {
|
||||
buffer.push(this.readSchema(listValue, v));
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
const buffer = {};
|
||||
if (ns.isMapSchema()) {
|
||||
const keyNs = ns.getKeySchema();
|
||||
const memberNs = ns.getValueSchema();
|
||||
let entries;
|
||||
if (flat) {
|
||||
entries = Array.isArray(value) ? value : [value];
|
||||
}
|
||||
else {
|
||||
entries = Array.isArray(value.entry) ? value.entry : [value.entry];
|
||||
}
|
||||
const keyProperty = keyNs.getMergedTraits().xmlName ?? "key";
|
||||
const valueProperty = memberNs.getMergedTraits().xmlName ?? "value";
|
||||
for (const entry of entries) {
|
||||
const key = entry[keyProperty];
|
||||
const value = entry[valueProperty];
|
||||
if (value != null || sparse) {
|
||||
buffer[key] = this.readSchema(memberNs, value);
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
if (ns.isStructSchema()) {
|
||||
for (const [memberName, memberSchema] of ns.structIterator()) {
|
||||
const memberTraits = memberSchema.getMergedTraits();
|
||||
const xmlObjectKey = !memberTraits.httpPayload
|
||||
? memberSchema.getMemberTraits().xmlName ?? memberName
|
||||
: memberTraits.xmlName ?? memberSchema.getName();
|
||||
if (value[xmlObjectKey] != null) {
|
||||
buffer[memberName] = this.readSchema(memberSchema, value[xmlObjectKey]);
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
if (ns.isDocumentSchema()) {
|
||||
return value;
|
||||
}
|
||||
throw new Error(`@aws-sdk/core/protocols - xml deserializer unhandled schema type for ${ns.getName(true)}`);
|
||||
}
|
||||
else {
|
||||
if (ns.isListSchema()) {
|
||||
return [];
|
||||
}
|
||||
else if (ns.isMapSchema() || ns.isStructSchema()) {
|
||||
return {};
|
||||
}
|
||||
return this.stringDeserializer.read(ns, value);
|
||||
}
|
||||
}
|
||||
parseXml(xml) {
|
||||
if (xml.length) {
|
||||
const parser = new XMLParser({
|
||||
attributeNamePrefix: "",
|
||||
htmlEntities: true,
|
||||
ignoreAttributes: false,
|
||||
ignoreDeclaration: true,
|
||||
parseTagValue: false,
|
||||
trimValues: false,
|
||||
tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
|
||||
});
|
||||
parser.addEntity("#xD", "\r");
|
||||
parser.addEntity("#10", "\n");
|
||||
let parsedObj;
|
||||
try {
|
||||
parsedObj = parser.parse(xml, true);
|
||||
}
|
||||
catch (e) {
|
||||
if (e && typeof e === "object") {
|
||||
Object.defineProperty(e, "$responseBodyText", {
|
||||
value: xml,
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
const textNodeName = "#text";
|
||||
const key = Object.keys(parsedObj)[0];
|
||||
const parsedObjToReturn = parsedObj[key];
|
||||
if (parsedObjToReturn[textNodeName]) {
|
||||
parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
|
||||
delete parsedObjToReturn[textNodeName];
|
||||
}
|
||||
return getValueFromTextNode(parsedObjToReturn);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+279
@@ -0,0 +1,279 @@
|
||||
import { XmlNode, XmlText } from "@aws-sdk/xml-builder";
|
||||
import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
|
||||
import { NumericValue } from "@smithy/core/serde";
|
||||
import { dateToUtcString } from "@smithy/smithy-client";
|
||||
import { fromBase64, toBase64 } from "@smithy/util-base64";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
export class XmlShapeSerializer extends SerdeContextConfig {
|
||||
settings;
|
||||
stringBuffer;
|
||||
byteBuffer;
|
||||
buffer;
|
||||
constructor(settings) {
|
||||
super();
|
||||
this.settings = settings;
|
||||
}
|
||||
write(schema, value) {
|
||||
const ns = NormalizedSchema.of(schema);
|
||||
if (ns.isStringSchema() && typeof value === "string") {
|
||||
this.stringBuffer = value;
|
||||
}
|
||||
else if (ns.isBlobSchema()) {
|
||||
this.byteBuffer =
|
||||
"byteLength" in value
|
||||
? value
|
||||
: (this.serdeContext?.base64Decoder ?? fromBase64)(value);
|
||||
}
|
||||
else {
|
||||
this.buffer = this.writeStruct(ns, value, undefined);
|
||||
const traits = ns.getMergedTraits();
|
||||
if (traits.httpPayload && !traits.xmlName) {
|
||||
this.buffer.withName(ns.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
flush() {
|
||||
if (this.byteBuffer !== undefined) {
|
||||
const bytes = this.byteBuffer;
|
||||
delete this.byteBuffer;
|
||||
return bytes;
|
||||
}
|
||||
if (this.stringBuffer !== undefined) {
|
||||
const str = this.stringBuffer;
|
||||
delete this.stringBuffer;
|
||||
return str;
|
||||
}
|
||||
const buffer = this.buffer;
|
||||
if (this.settings.xmlNamespace) {
|
||||
if (!buffer?.attributes?.["xmlns"]) {
|
||||
buffer.addAttribute("xmlns", this.settings.xmlNamespace);
|
||||
}
|
||||
}
|
||||
delete this.buffer;
|
||||
return buffer.toString();
|
||||
}
|
||||
writeStruct(ns, value, parentXmlns) {
|
||||
const traits = ns.getMergedTraits();
|
||||
const name = ns.isMemberSchema() && !traits.httpPayload
|
||||
? ns.getMemberTraits().xmlName ?? ns.getMemberName()
|
||||
: traits.xmlName ?? ns.getName();
|
||||
if (!name || !ns.isStructSchema()) {
|
||||
throw new Error(`@aws-sdk/core/protocols - xml serializer, cannot write struct with empty name or non-struct, schema=${ns.getName(true)}.`);
|
||||
}
|
||||
const structXmlNode = XmlNode.of(name);
|
||||
const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
|
||||
if (xmlns) {
|
||||
structXmlNode.addAttribute(xmlnsAttr, xmlns);
|
||||
}
|
||||
for (const [memberName, memberSchema] of ns.structIterator()) {
|
||||
const val = value[memberName];
|
||||
if (val != null) {
|
||||
if (memberSchema.getMergedTraits().xmlAttribute) {
|
||||
structXmlNode.addAttribute(memberSchema.getMergedTraits().xmlName ?? memberName, this.writeSimple(memberSchema, val));
|
||||
continue;
|
||||
}
|
||||
if (memberSchema.isListSchema()) {
|
||||
this.writeList(memberSchema, val, structXmlNode, xmlns);
|
||||
}
|
||||
else if (memberSchema.isMapSchema()) {
|
||||
this.writeMap(memberSchema, val, structXmlNode, xmlns);
|
||||
}
|
||||
else if (memberSchema.isStructSchema()) {
|
||||
structXmlNode.addChildNode(this.writeStruct(memberSchema, val, xmlns));
|
||||
}
|
||||
else {
|
||||
const memberNode = XmlNode.of(memberSchema.getMergedTraits().xmlName ?? memberSchema.getMemberName());
|
||||
this.writeSimpleInto(memberSchema, val, memberNode, xmlns);
|
||||
structXmlNode.addChildNode(memberNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
return structXmlNode;
|
||||
}
|
||||
writeList(listMember, array, container, parentXmlns) {
|
||||
if (!listMember.isMemberSchema()) {
|
||||
throw new Error(`@aws-sdk/core/protocols - xml serializer, cannot write non-member list: ${listMember.getName(true)}`);
|
||||
}
|
||||
const listTraits = listMember.getMergedTraits();
|
||||
const listValueSchema = listMember.getValueSchema();
|
||||
const listValueTraits = listValueSchema.getMergedTraits();
|
||||
const sparse = !!listValueTraits.sparse;
|
||||
const flat = !!listTraits.xmlFlattened;
|
||||
const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(listMember, parentXmlns);
|
||||
const writeItem = (container, value) => {
|
||||
if (listValueSchema.isListSchema()) {
|
||||
this.writeList(listValueSchema, Array.isArray(value) ? value : [value], container, xmlns);
|
||||
}
|
||||
else if (listValueSchema.isMapSchema()) {
|
||||
this.writeMap(listValueSchema, value, container, xmlns);
|
||||
}
|
||||
else if (listValueSchema.isStructSchema()) {
|
||||
const struct = this.writeStruct(listValueSchema, value, xmlns);
|
||||
container.addChildNode(struct.withName(flat ? listTraits.xmlName ?? listMember.getMemberName() : listValueTraits.xmlName ?? "member"));
|
||||
}
|
||||
else {
|
||||
const listItemNode = XmlNode.of(flat ? listTraits.xmlName ?? listMember.getMemberName() : listValueTraits.xmlName ?? "member");
|
||||
this.writeSimpleInto(listValueSchema, value, listItemNode, xmlns);
|
||||
container.addChildNode(listItemNode);
|
||||
}
|
||||
};
|
||||
if (flat) {
|
||||
for (const value of array) {
|
||||
if (sparse || value != null) {
|
||||
writeItem(container, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
const listNode = XmlNode.of(listTraits.xmlName ?? listMember.getMemberName());
|
||||
if (xmlns) {
|
||||
listNode.addAttribute(xmlnsAttr, xmlns);
|
||||
}
|
||||
for (const value of array) {
|
||||
if (sparse || value != null) {
|
||||
writeItem(listNode, value);
|
||||
}
|
||||
}
|
||||
container.addChildNode(listNode);
|
||||
}
|
||||
}
|
||||
writeMap(mapMember, map, container, parentXmlns, containerIsMap = false) {
|
||||
if (!mapMember.isMemberSchema()) {
|
||||
throw new Error(`@aws-sdk/core/protocols - xml serializer, cannot write non-member map: ${mapMember.getName(true)}`);
|
||||
}
|
||||
const mapTraits = mapMember.getMergedTraits();
|
||||
const mapKeySchema = mapMember.getKeySchema();
|
||||
const mapKeyTraits = mapKeySchema.getMergedTraits();
|
||||
const keyTag = mapKeyTraits.xmlName ?? "key";
|
||||
const mapValueSchema = mapMember.getValueSchema();
|
||||
const mapValueTraits = mapValueSchema.getMergedTraits();
|
||||
const valueTag = mapValueTraits.xmlName ?? "value";
|
||||
const sparse = !!mapValueTraits.sparse;
|
||||
const flat = !!mapTraits.xmlFlattened;
|
||||
const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(mapMember, parentXmlns);
|
||||
const addKeyValue = (entry, key, val) => {
|
||||
const keyNode = XmlNode.of(keyTag, key);
|
||||
const [keyXmlnsAttr, keyXmlns] = this.getXmlnsAttribute(mapKeySchema, xmlns);
|
||||
if (keyXmlns) {
|
||||
keyNode.addAttribute(keyXmlnsAttr, keyXmlns);
|
||||
}
|
||||
entry.addChildNode(keyNode);
|
||||
let valueNode = XmlNode.of(valueTag);
|
||||
if (mapValueSchema.isListSchema()) {
|
||||
this.writeList(mapValueSchema, val, valueNode, xmlns);
|
||||
}
|
||||
else if (mapValueSchema.isMapSchema()) {
|
||||
this.writeMap(mapValueSchema, val, valueNode, xmlns, true);
|
||||
}
|
||||
else if (mapValueSchema.isStructSchema()) {
|
||||
valueNode = this.writeStruct(mapValueSchema, val, xmlns);
|
||||
}
|
||||
else {
|
||||
this.writeSimpleInto(mapValueSchema, val, valueNode, xmlns);
|
||||
}
|
||||
entry.addChildNode(valueNode);
|
||||
};
|
||||
if (flat) {
|
||||
for (const [key, val] of Object.entries(map)) {
|
||||
if (sparse || val != null) {
|
||||
const entry = XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
|
||||
addKeyValue(entry, key, val);
|
||||
container.addChildNode(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
let mapNode;
|
||||
if (!containerIsMap) {
|
||||
mapNode = XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
|
||||
if (xmlns) {
|
||||
mapNode.addAttribute(xmlnsAttr, xmlns);
|
||||
}
|
||||
container.addChildNode(mapNode);
|
||||
}
|
||||
for (const [key, val] of Object.entries(map)) {
|
||||
if (sparse || val != null) {
|
||||
const entry = XmlNode.of("entry");
|
||||
addKeyValue(entry, key, val);
|
||||
(containerIsMap ? container : mapNode).addChildNode(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
writeSimple(_schema, value) {
|
||||
if (null === value) {
|
||||
throw new Error("@aws-sdk/core/protocols - (XML serializer) cannot write null value.");
|
||||
}
|
||||
const ns = NormalizedSchema.of(_schema);
|
||||
let nodeContents = null;
|
||||
if (value && typeof value === "object") {
|
||||
if (ns.isBlobSchema()) {
|
||||
nodeContents = (this.serdeContext?.base64Encoder ?? toBase64)(value);
|
||||
}
|
||||
else if (ns.isTimestampSchema() && value instanceof Date) {
|
||||
const options = this.settings.timestampFormat;
|
||||
const format = options.useTrait
|
||||
? ns.getSchema() === SCHEMA.TIMESTAMP_DEFAULT
|
||||
? options.default
|
||||
: ns.getSchema() ?? options.default
|
||||
: options.default;
|
||||
switch (format) {
|
||||
case SCHEMA.TIMESTAMP_DATE_TIME:
|
||||
nodeContents = value.toISOString().replace(".000Z", "Z");
|
||||
break;
|
||||
case SCHEMA.TIMESTAMP_HTTP_DATE:
|
||||
nodeContents = dateToUtcString(value);
|
||||
break;
|
||||
case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
|
||||
nodeContents = String(value.getTime() / 1000);
|
||||
break;
|
||||
default:
|
||||
console.warn("Missing timestamp format, using http date", value);
|
||||
nodeContents = dateToUtcString(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (ns.isBigDecimalSchema() && value) {
|
||||
if (value instanceof NumericValue) {
|
||||
return value.string;
|
||||
}
|
||||
return String(value);
|
||||
}
|
||||
else if (ns.isMapSchema() || ns.isListSchema()) {
|
||||
throw new Error("@aws-sdk/core/protocols - xml serializer, cannot call _write() on List/Map schema, call writeList or writeMap() instead.");
|
||||
}
|
||||
else {
|
||||
throw new Error(`@aws-sdk/core/protocols - xml serializer, unhandled schema type for object value and schema: ${ns.getName(true)}`);
|
||||
}
|
||||
}
|
||||
if (ns.isStringSchema() ||
|
||||
ns.isBooleanSchema() ||
|
||||
ns.isNumericSchema() ||
|
||||
ns.isBigIntegerSchema() ||
|
||||
ns.isBigDecimalSchema()) {
|
||||
nodeContents = String(value);
|
||||
}
|
||||
if (nodeContents === null) {
|
||||
throw new Error(`Unhandled schema-value pair ${ns.getName(true)}=${value}`);
|
||||
}
|
||||
return nodeContents;
|
||||
}
|
||||
writeSimpleInto(_schema, value, into, parentXmlns) {
|
||||
const nodeContents = this.writeSimple(_schema, value);
|
||||
const ns = NormalizedSchema.of(_schema);
|
||||
const content = new XmlText(nodeContents);
|
||||
const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
|
||||
if (xmlns) {
|
||||
into.addAttribute(xmlnsAttr, xmlns);
|
||||
}
|
||||
into.addChildNode(content);
|
||||
}
|
||||
getXmlnsAttribute(ns, parentXmlns) {
|
||||
const traits = ns.getMergedTraits();
|
||||
const [prefix, xmlns] = traits.xmlNamespace ?? [];
|
||||
if (xmlns && xmlns !== parentXmlns) {
|
||||
return [prefix ? `xmlns:${prefix}` : "xmlns", xmlns];
|
||||
}
|
||||
return [void 0, void 0];
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+57
@@ -0,0 +1,57 @@
|
||||
import { getValueFromTextNode } from "@smithy/smithy-client";
|
||||
import { XMLParser } from "fast-xml-parser";
|
||||
import { collectBodyString } from "../common";
|
||||
export const parseXmlBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
|
||||
if (encoded.length) {
|
||||
const parser = new XMLParser({
|
||||
attributeNamePrefix: "",
|
||||
htmlEntities: true,
|
||||
ignoreAttributes: false,
|
||||
ignoreDeclaration: true,
|
||||
parseTagValue: false,
|
||||
trimValues: false,
|
||||
tagValueProcessor: (_, val) => (val.trim() === "" && val.includes("\n") ? "" : undefined),
|
||||
});
|
||||
parser.addEntity("#xD", "\r");
|
||||
parser.addEntity("#10", "\n");
|
||||
let parsedObj;
|
||||
try {
|
||||
parsedObj = parser.parse(encoded, true);
|
||||
}
|
||||
catch (e) {
|
||||
if (e && typeof e === "object") {
|
||||
Object.defineProperty(e, "$responseBodyText", {
|
||||
value: encoded,
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
const textNodeName = "#text";
|
||||
const key = Object.keys(parsedObj)[0];
|
||||
const parsedObjToReturn = parsedObj[key];
|
||||
if (parsedObjToReturn[textNodeName]) {
|
||||
parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
|
||||
delete parsedObjToReturn[textNodeName];
|
||||
}
|
||||
return getValueFromTextNode(parsedObjToReturn);
|
||||
}
|
||||
return {};
|
||||
});
|
||||
export const parseXmlErrorBody = async (errorBody, context) => {
|
||||
const value = await parseXmlBody(errorBody, context);
|
||||
if (value.Error) {
|
||||
value.Error.message = value.Error.message ?? value.Error.Message;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
export const loadRestXmlErrorCode = (output, data) => {
|
||||
if (data?.Error?.Code !== undefined) {
|
||||
return data.Error.Code;
|
||||
}
|
||||
if (data?.Code !== undefined) {
|
||||
return data.Code;
|
||||
}
|
||||
if (output.statusCode == 404) {
|
||||
return "NotFound";
|
||||
}
|
||||
};
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
export function simpleFormatXml(xml) {
|
||||
let b = "";
|
||||
let indentation = 0;
|
||||
for (let i = 0; i < xml.length; ++i) {
|
||||
const c = xml[i];
|
||||
if (c === "<") {
|
||||
if (xml[i + 1] === "/") {
|
||||
b += "\n" + " ".repeat(indentation - 2) + c;
|
||||
indentation -= 4;
|
||||
}
|
||||
else {
|
||||
b += c;
|
||||
}
|
||||
}
|
||||
else if (c === ">") {
|
||||
indentation += 2;
|
||||
b += c + "\n" + " ".repeat(indentation);
|
||||
}
|
||||
else {
|
||||
b += c;
|
||||
}
|
||||
}
|
||||
return b
|
||||
.split("\n")
|
||||
.filter((s) => !!s.trim())
|
||||
.join("\n");
|
||||
}
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export * from "./index";
|
||||
export * from "./submodules/account-id-endpoint/index";
|
||||
export * from "./submodules/client/index";
|
||||
export * from "./submodules/httpAuthSchemes/index";
|
||||
export * from "./submodules/protocols/index";
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Submodules annotated with "Legacy" are from prior to the submodule system.
|
||||
* They are exported from the package's root index to preserve backwards compatibility.
|
||||
*
|
||||
* New development should go in a proper submodule and not be exported from the root index.
|
||||
*/
|
||||
/**
|
||||
* Legacy submodule.
|
||||
*/
|
||||
export * from "./submodules/client/index";
|
||||
/**
|
||||
* Legacy submodule.
|
||||
*/
|
||||
export * from "./submodules/httpAuthSchemes/index";
|
||||
/**
|
||||
* Legacy submodule.
|
||||
*/
|
||||
export * from "./submodules/protocols/index";
|
||||
/**
|
||||
* Warning: do not export any additional submodules from the root of this package. See readme.md for
|
||||
* guide on developing submodules.
|
||||
*/
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
import { Provider } from "@smithy/types";
|
||||
import { AccountIdEndpointMode } from "./AccountIdEndpointModeConstants";
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface AccountIdEndpointModeInputConfig {
|
||||
/**
|
||||
* The account ID endpoint mode to use.
|
||||
*/
|
||||
accountIdEndpointMode?: AccountIdEndpointMode | Provider<AccountIdEndpointMode>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface PreviouslyResolved {
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface AccountIdEndpointModeResolvedConfig {
|
||||
accountIdEndpointMode: Provider<AccountIdEndpointMode>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const resolveAccountIdEndpointModeConfig: <T>(input: T & AccountIdEndpointModeInputConfig & PreviouslyResolved) => T & AccountIdEndpointModeResolvedConfig;
|
||||
export {};
|
||||
Generated
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export type AccountIdEndpointMode = "disabled" | "preferred" | "required";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const DEFAULT_ACCOUNT_ID_ENDPOINT_MODE = "preferred";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const ACCOUNT_ID_ENDPOINT_MODE_VALUES: AccountIdEndpointMode[];
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare function validateAccountIdEndpointMode(value: any): value is AccountIdEndpointMode;
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import { LoadedConfigSelectors } from "@smithy/node-config-provider";
|
||||
import { AccountIdEndpointMode } from "./AccountIdEndpointModeConstants";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const ENV_ACCOUNT_ID_ENDPOINT_MODE = "AWS_ACCOUNT_ID_ENDPOINT_MODE";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const CONFIG_ACCOUNT_ID_ENDPOINT_MODE = "account_id_endpoint_mode";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const NODE_ACCOUNT_ID_ENDPOINT_MODE_CONFIG_OPTIONS: LoadedConfigSelectors<AccountIdEndpointMode>;
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./AccountIdEndpointModeConfigResolver";
|
||||
export * from "./AccountIdEndpointModeConstants";
|
||||
export * from "./NodeAccountIdEndpointModeConfigOptions";
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
export declare const state: {
|
||||
warningEmitted: boolean;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Emits warning if the provided Node.js version string is
|
||||
* pending deprecation by AWS SDK JSv3.
|
||||
*
|
||||
* @param version - The Node.js version string.
|
||||
*/
|
||||
export declare const emitWarningIfUnsupportedVersion: (version: string) => void;
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
export * from "./emitWarningIfUnsupportedVersion";
|
||||
export * from "./setCredentialFeature";
|
||||
export * from "./setFeature";
|
||||
export * from "./setTokenFeature";
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import type { AttributedAwsCredentialIdentity, AwsSdkCredentialsFeatures } from "@aws-sdk/types";
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @returns the credentials with source feature attribution.
|
||||
*/
|
||||
export declare function setCredentialFeature<F extends keyof AwsSdkCredentialsFeatures>(credentials: AttributedAwsCredentialIdentity, feature: F, value: AwsSdkCredentialsFeatures[F]): AttributedAwsCredentialIdentity;
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
import type { AwsHandlerExecutionContext, AwsSdkFeatures } from "@aws-sdk/types";
|
||||
/**
|
||||
* @internal
|
||||
* Indicates to the request context that a given feature is active.
|
||||
*
|
||||
* @param context - handler execution context.
|
||||
* @param feature - readable name of feature.
|
||||
* @param value - encoding value of feature. This is required because the
|
||||
* specification asks the SDK not to include a runtime lookup of all
|
||||
* the feature identifiers.
|
||||
*/
|
||||
export declare function setFeature<F extends keyof AwsSdkFeatures>(context: AwsHandlerExecutionContext, feature: F, value: AwsSdkFeatures[F]): void;
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import type { AttributedTokenIdentity, AwsSdkTokenFeatures } from "@aws-sdk/types";
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @returns the token with source feature attribution.
|
||||
*/
|
||||
export declare function setTokenFeature<F extends keyof AwsSdkTokenFeatures>(token: AttributedTokenIdentity, feature: F, value: AwsSdkTokenFeatures[F]): AttributedTokenIdentity;
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
import { AwsCredentialIdentity, HttpRequest as IHttpRequest } from "@smithy/types";
|
||||
import { AwsSdkSigV4Signer } from "./AwsSdkSigV4Signer";
|
||||
/**
|
||||
* @internal
|
||||
* Note: this is not a signing algorithm implementation. The sign method
|
||||
* accepts the real signer as an input parameter.
|
||||
*/
|
||||
export declare class AwsSdkSigV4ASigner extends AwsSdkSigV4Signer {
|
||||
sign(httpRequest: IHttpRequest, identity: AwsCredentialIdentity, signingProperties: Record<string, unknown>): Promise<IHttpRequest>;
|
||||
}
|
||||
Generated
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
import { AuthScheme, AwsCredentialIdentity, HttpRequest as IHttpRequest, HttpResponse, HttpSigner, RequestSigner } from "@smithy/types";
|
||||
import { AwsSdkSigV4AAuthResolvedConfig } from "./resolveAwsSdkSigV4AConfig";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface AwsSdkSigV4Config extends AwsSdkSigV4AAuthResolvedConfig {
|
||||
systemClockOffset: number;
|
||||
signer: (authScheme?: AuthScheme) => Promise<RequestSigner>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
interface AwsSdkSigV4AuthSigningProperties {
|
||||
config: AwsSdkSigV4Config;
|
||||
signer: RequestSigner;
|
||||
signingRegion?: string;
|
||||
signingRegionSet?: string[];
|
||||
signingName?: string;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const validateSigningProperties: (signingProperties: Record<string, unknown>) => Promise<AwsSdkSigV4AuthSigningProperties>;
|
||||
/**
|
||||
* Note: this is not a signing algorithm implementation. The sign method
|
||||
* accepts the real signer as an input parameter.
|
||||
* @internal
|
||||
*/
|
||||
export declare class AwsSdkSigV4Signer implements HttpSigner {
|
||||
sign(httpRequest: IHttpRequest,
|
||||
/**
|
||||
* `identity` is bound in {@link resolveAWSSDKSigV4Config}
|
||||
*/
|
||||
identity: AwsCredentialIdentity, signingProperties: Record<string, unknown>): Promise<IHttpRequest>;
|
||||
errorHandler(signingProperties: Record<string, unknown>): (error: Error) => never;
|
||||
successHandler(httpResponse: HttpResponse | unknown, signingProperties: Record<string, unknown>): void;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated renamed to {@link AwsSdkSigV4Signer}
|
||||
*/
|
||||
export declare const AWSSDKSigV4Signer: typeof AwsSdkSigV4Signer;
|
||||
export {};
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import { LoadedConfigSelectors } from "@smithy/node-config-provider";
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare const NODE_AUTH_SCHEME_PREFERENCE_OPTIONS: LoadedConfigSelectors<string[]>;
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export { AwsSdkSigV4Signer, AWSSDKSigV4Signer, validateSigningProperties } from "./AwsSdkSigV4Signer";
|
||||
export { AwsSdkSigV4ASigner } from "./AwsSdkSigV4ASigner";
|
||||
export * from "./NODE_AUTH_SCHEME_PREFERENCE_OPTIONS";
|
||||
export * from "./resolveAwsSdkSigV4AConfig";
|
||||
export * from "./resolveAwsSdkSigV4Config";
|
||||
Generated
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
import { LoadedConfigSelectors } from "@smithy/node-config-provider";
|
||||
import { Provider } from "@smithy/types";
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface AwsSdkSigV4AAuthInputConfig {
|
||||
/**
|
||||
* This option will override the AWS sigv4a
|
||||
* signing regionSet from any other source.
|
||||
*
|
||||
* The lookup order is:
|
||||
* 1. this value
|
||||
* 2. configuration file value of sigv4a_signing_region_set.
|
||||
* 3. environment value of AWS_SIGV4A_SIGNING_REGION_SET.
|
||||
* 4. signingRegionSet given by endpoint resolution.
|
||||
* 5. the singular region of the SDK client.
|
||||
*/
|
||||
sigv4aSigningRegionSet?: string[] | undefined | Provider<string[] | undefined>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface AwsSdkSigV4APreviouslyResolved {
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface AwsSdkSigV4AAuthResolvedConfig {
|
||||
sigv4aSigningRegionSet: Provider<string[] | undefined>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const resolveAwsSdkSigV4AConfig: <T>(config: T & AwsSdkSigV4AAuthInputConfig & AwsSdkSigV4APreviouslyResolved) => T & AwsSdkSigV4AAuthResolvedConfig;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const NODE_SIGV4A_CONFIG_OPTIONS: LoadedConfigSelectors<string[] | undefined>;
|
||||
Generated
Vendored
+117
@@ -0,0 +1,117 @@
|
||||
import type { MergeFunctions } from "@aws-sdk/types";
|
||||
import { SignatureV4CryptoInit, SignatureV4Init } from "@smithy/signature-v4";
|
||||
import { AuthScheme, AwsCredentialIdentity, AwsCredentialIdentityProvider, ChecksumConstructor, HashConstructor, MemoizedProvider, Provider, RegionInfoProvider, RequestSigner } from "@smithy/types";
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface AwsSdkSigV4AuthInputConfig {
|
||||
/**
|
||||
* The credentials used to sign requests.
|
||||
*/
|
||||
credentials?: AwsCredentialIdentity | AwsCredentialIdentityProvider;
|
||||
/**
|
||||
* The signer to use when signing requests.
|
||||
*/
|
||||
signer?: RequestSigner | ((authScheme?: AuthScheme) => Promise<RequestSigner>);
|
||||
/**
|
||||
* Whether to escape request path when signing the request.
|
||||
*/
|
||||
signingEscapePath?: boolean;
|
||||
/**
|
||||
* An offset value in milliseconds to apply to all signing times.
|
||||
*/
|
||||
systemClockOffset?: number;
|
||||
/**
|
||||
* The region where you want to sign your request against. This
|
||||
* can be different to the region in the endpoint.
|
||||
*/
|
||||
signingRegion?: string;
|
||||
/**
|
||||
* The injectable SigV4-compatible signer class constructor. If not supplied,
|
||||
* regular SignatureV4 constructor will be used.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
signerConstructor?: new (options: SignatureV4Init & SignatureV4CryptoInit) => RequestSigner;
|
||||
}
|
||||
/**
|
||||
* Used to indicate whether a credential provider function was memoized by this resolver.
|
||||
* @public
|
||||
*/
|
||||
export type AwsSdkSigV4Memoized = {
|
||||
/**
|
||||
* The credential provider has been memoized by the AWS SDK SigV4 config resolver.
|
||||
*/
|
||||
memoized?: boolean;
|
||||
/**
|
||||
* The credential provider has the caller client config object bound to its arguments.
|
||||
*/
|
||||
configBound?: boolean;
|
||||
/**
|
||||
* Function is wrapped with attribution transform.
|
||||
*/
|
||||
attributed?: boolean;
|
||||
};
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface AwsSdkSigV4PreviouslyResolved {
|
||||
credentialDefaultProvider?: (input: any) => MemoizedProvider<AwsCredentialIdentity>;
|
||||
region: string | Provider<string>;
|
||||
sha256: ChecksumConstructor | HashConstructor;
|
||||
signingName?: string;
|
||||
regionInfoProvider?: RegionInfoProvider;
|
||||
defaultSigningName?: string;
|
||||
serviceId: string;
|
||||
useFipsEndpoint: Provider<boolean>;
|
||||
useDualstackEndpoint: Provider<boolean>;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface AwsSdkSigV4AuthResolvedConfig {
|
||||
/**
|
||||
* Resolved value for input config {@link AwsSdkSigV4AuthInputConfig.credentials}
|
||||
* This provider MAY memoize the loaded credentials for certain period.
|
||||
*/
|
||||
credentials: MergeFunctions<AwsCredentialIdentityProvider, MemoizedProvider<AwsCredentialIdentity>> & AwsSdkSigV4Memoized;
|
||||
/**
|
||||
* Resolved value for input config {@link AwsSdkSigV4AuthInputConfig.signer}
|
||||
*/
|
||||
signer: (authScheme?: AuthScheme) => Promise<RequestSigner>;
|
||||
/**
|
||||
* Resolved value for input config {@link AwsSdkSigV4AuthInputConfig.signingEscapePath}
|
||||
*/
|
||||
signingEscapePath: boolean;
|
||||
/**
|
||||
* Resolved value for input config {@link AwsSdkSigV4AuthInputConfig.systemClockOffset}
|
||||
*/
|
||||
systemClockOffset: number;
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const resolveAwsSdkSigV4Config: <T>(config: T & AwsSdkSigV4AuthInputConfig & AwsSdkSigV4PreviouslyResolved) => T & AwsSdkSigV4AuthResolvedConfig;
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated renamed to {@link AwsSdkSigV4AuthInputConfig}
|
||||
*/
|
||||
export interface AWSSDKSigV4AuthInputConfig extends AwsSdkSigV4AuthInputConfig {
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated renamed to {@link AwsSdkSigV4PreviouslyResolved}
|
||||
*/
|
||||
export interface AWSSDKSigV4PreviouslyResolved extends AwsSdkSigV4PreviouslyResolved {
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated renamed to {@link AwsSdkSigV4AuthResolvedConfig}
|
||||
*/
|
||||
export interface AWSSDKSigV4AuthResolvedConfig extends AwsSdkSigV4AuthResolvedConfig {
|
||||
}
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated renamed to {@link resolveAwsSdkSigV4Config}
|
||||
*/
|
||||
export declare const resolveAWSSDKSigV4Config: <T>(config: T & AwsSdkSigV4AuthInputConfig & AwsSdkSigV4PreviouslyResolved) => T & AwsSdkSigV4AuthResolvedConfig;
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./aws_sdk";
|
||||
export * from "./utils/getBearerTokenEnvKey";
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Converts a comma-separated string into an array of trimmed strings
|
||||
* @param str The comma-separated input string to split
|
||||
* @returns Array of trimmed strings split from the input
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export declare const getArrayForCommaSeparatedString: (str: string) => string[];
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Returns an environment variable key base on signing name.
|
||||
* @param signingName - The signing name to use in the key
|
||||
* @returns The environment variable key in format AWS_BEARER_TOKEN_<SIGNING_NAME>
|
||||
*/
|
||||
export declare const getBearerTokenEnvKey: (signingName: string) => string;
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const getDateHeader: (response: unknown) => string | undefined;
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Returns a date that is corrected for clock skew.
|
||||
*
|
||||
* @param systemClockOffset The offset of the system clock in milliseconds.
|
||||
*/
|
||||
export declare const getSkewCorrectedDate: (systemClockOffset: number) => Date;
|
||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* If clock is skewed, it returns the difference between serverTime and current time.
|
||||
* If clock is not skewed, it returns currentSystemClockOffset.
|
||||
*
|
||||
* @param clockTime The string value of the server time.
|
||||
* @param currentSystemClockOffset The current system clock offset.
|
||||
*/
|
||||
export declare const getUpdatedSystemClockOffset: (clockTime: string, currentSystemClockOffset: number) => number;
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export * from "./getDateHeader";
|
||||
export * from "./getSkewCorrectedDate";
|
||||
export * from "./getUpdatedSystemClockOffset";
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Checks if the provided date is within the skew window of 300000ms.
|
||||
*
|
||||
* @param clockTime - The time to check for skew in milliseconds.
|
||||
* @param systemClockOffset - The offset of the system clock in milliseconds.
|
||||
*/
|
||||
export declare const isClockSkewed: (clockTime: number, systemClockOffset: number) => boolean;
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
import { ConfigurableSerdeContext, SerdeFunctions } from "@smithy/types";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare class SerdeContextConfig implements ConfigurableSerdeContext {
|
||||
protected serdeContext?: SerdeFunctions;
|
||||
setSerdeContext(serdeContext: SerdeFunctions): void;
|
||||
}
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Used for awsQueryCompatibility trait.
|
||||
*/
|
||||
export declare const _toStr: (val: unknown) => string | undefined;
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Used for awsQueryCompatibility trait.
|
||||
*/
|
||||
export declare const _toBool: (val: unknown) => boolean | undefined;
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Used for awsQueryCompatibility trait.
|
||||
*/
|
||||
export declare const _toNum: (val: unknown) => number | undefined;
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import type { SerdeFunctions } from "@smithy/types";
|
||||
export declare const collectBodyString: (streamBody: any, context: SerdeFunctions) => Promise<string>;
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
export * from "./coercing-serializers";
|
||||
export * from "./json/AwsJson1_0Protocol";
|
||||
export * from "./json/AwsJson1_1Protocol";
|
||||
export * from "./json/AwsJsonRpcProtocol";
|
||||
export * from "./json/AwsRestJsonProtocol";
|
||||
export * from "./json/JsonCodec";
|
||||
export * from "./json/JsonShapeDeserializer";
|
||||
export * from "./json/JsonShapeSerializer";
|
||||
export * from "./json/awsExpectUnion";
|
||||
export * from "./json/parseJsonBody";
|
||||
export * from "./query/AwsEc2QueryProtocol";
|
||||
export * from "./query/AwsQueryProtocol";
|
||||
export * from "./xml/AwsRestXmlProtocol";
|
||||
export * from "./xml/XmlCodec";
|
||||
export * from "./xml/XmlShapeDeserializer";
|
||||
export * from "./xml/XmlShapeSerializer";
|
||||
export * from "./xml/parseXmlBody";
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
||||
/**
|
||||
* @alpha
|
||||
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
|
||||
*/
|
||||
export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
||||
constructor({ defaultNamespace }: {
|
||||
defaultNamespace: string;
|
||||
});
|
||||
getShapeId(): string;
|
||||
protected getJsonRpcVersion(): "1.0";
|
||||
}
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
||||
/**
|
||||
* @alpha
|
||||
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
|
||||
*/
|
||||
export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
||||
constructor({ defaultNamespace }: {
|
||||
defaultNamespace: string;
|
||||
});
|
||||
getShapeId(): string;
|
||||
protected getJsonRpcVersion(): "1.1";
|
||||
}
|
||||
Generated
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import { RpcProtocol } from "@smithy/core/protocols";
|
||||
import { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, OperationSchema, ResponseMetadata, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
|
||||
import { JsonCodec } from "./JsonCodec";
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export declare abstract class AwsJsonRpcProtocol extends RpcProtocol {
|
||||
protected serializer: ShapeSerializer<string | Uint8Array>;
|
||||
protected deserializer: ShapeDeserializer<string | Uint8Array>;
|
||||
private codec;
|
||||
protected constructor({ defaultNamespace }: {
|
||||
defaultNamespace: string;
|
||||
});
|
||||
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<HttpRequest>;
|
||||
getPayloadCodec(): JsonCodec;
|
||||
protected abstract getJsonRpcVersion(): "1.1" | "1.0";
|
||||
protected handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: HttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
|
||||
}
|
||||
Generated
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
import { HttpBindingProtocol } from "@smithy/core/protocols";
|
||||
import { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, OperationSchema, ResponseMetadata, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
|
||||
import { JsonCodec } from "./JsonCodec";
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export declare class AwsRestJsonProtocol extends HttpBindingProtocol {
|
||||
protected serializer: ShapeSerializer<string | Uint8Array>;
|
||||
protected deserializer: ShapeDeserializer<string | Uint8Array>;
|
||||
private readonly codec;
|
||||
constructor({ defaultNamespace }: {
|
||||
defaultNamespace: string;
|
||||
});
|
||||
getShapeId(): string;
|
||||
getPayloadCodec(): JsonCodec;
|
||||
setSerdeContext(serdeContext: SerdeFunctions): void;
|
||||
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<HttpRequest>;
|
||||
protected handleError(operationSchema: OperationSchema, context: HandlerExecutionContext & SerdeFunctions, response: HttpResponse, dataObject: any, metadata: ResponseMetadata): Promise<never>;
|
||||
}
|
||||
Generated
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
import { Codec, CodecSettings } from "@smithy/types";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
import { JsonShapeDeserializer } from "./JsonShapeDeserializer";
|
||||
import { JsonShapeSerializer } from "./JsonShapeSerializer";
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export type JsonSettings = CodecSettings & {
|
||||
jsonName: boolean;
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export declare class JsonCodec extends SerdeContextConfig implements Codec<string, string> {
|
||||
readonly settings: JsonSettings;
|
||||
constructor(settings: JsonSettings);
|
||||
createSerializer(): JsonShapeSerializer;
|
||||
createDeserializer(): JsonShapeDeserializer;
|
||||
}
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import { DocumentType, Schema, ShapeDeserializer } from "@smithy/types";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
import { JsonSettings } from "./JsonCodec";
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export declare class JsonShapeDeserializer extends SerdeContextConfig implements ShapeDeserializer<string> {
|
||||
readonly settings: JsonSettings;
|
||||
constructor(settings: JsonSettings);
|
||||
read(schema: Schema, data: string | Uint8Array | unknown): Promise<any>;
|
||||
readObject(schema: Schema, data: DocumentType): any;
|
||||
private _read;
|
||||
}
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
import { Schema, ShapeSerializer } from "@smithy/types";
|
||||
import { SerdeContextConfig } from "../ConfigurableSerdeContext";
|
||||
import { JsonSettings } from "./JsonCodec";
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export declare class JsonShapeSerializer extends SerdeContextConfig implements ShapeSerializer<string> {
|
||||
readonly settings: JsonSettings;
|
||||
private buffer;
|
||||
private rootSchema;
|
||||
constructor(settings: JsonSettings);
|
||||
write(schema: Schema, value: unknown): void;
|
||||
flush(): string;
|
||||
private _write;
|
||||
}
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Forwards to Smithy's expectUnion function, but also ignores
|
||||
* the `__type` field if it is present.
|
||||
*/
|
||||
export declare const awsExpectUnion: (value: unknown) => Record<string, any> | undefined;
|
||||
Generated
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Serializes BigInt and NumericValue to JSON-number.
|
||||
* @internal
|
||||
*/
|
||||
export declare class JsonReplacer {
|
||||
/**
|
||||
* Stores placeholder key to true serialized value lookup.
|
||||
*/
|
||||
private readonly values;
|
||||
private counter;
|
||||
private stage;
|
||||
/**
|
||||
* Creates a jsonReplacer function that reserves big integer and big decimal values
|
||||
* for later replacement.
|
||||
*/
|
||||
createReplacer(): (key: string, value: unknown) => unknown;
|
||||
/**
|
||||
* Replaces placeholder keys with their true values.
|
||||
*/
|
||||
replaceInJson(json: string): string;
|
||||
}
|
||||
SerpentRace_Backend/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/jsonReviver.d.ts
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @param key - JSON object key.
|
||||
* @param value - parsed value.
|
||||
* @param context - original JSON string for reference. Not available until Node.js 21 and unavailable in Safari as
|
||||
* of April 2025.
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#browser_compatibility
|
||||
*
|
||||
* @alpha
|
||||
*
|
||||
* @returns transformed value.
|
||||
*/
|
||||
export declare function jsonReviver(key: string, value: any, context?: {
|
||||
source?: string;
|
||||
}): any;
|
||||
Generated
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
import type { HttpResponse, SerdeFunctions } from "@smithy/types";
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const parseJsonBody: (streamBody: any, context: SerdeFunctions) => any;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const parseJsonErrorBody: (errorBody: any, context: SerdeFunctions) => Promise<any>;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export declare const loadRestJsonErrorCode: (output: HttpResponse, data: any) => string | undefined;
|
||||
Generated
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
import { AwsQueryProtocol } from "./AwsQueryProtocol";
|
||||
/**
|
||||
* @alpha
|
||||
*/
|
||||
export declare class AwsEc2QueryProtocol extends AwsQueryProtocol {
|
||||
options: {
|
||||
defaultNamespace: string;
|
||||
xmlNamespace: string;
|
||||
version: string;
|
||||
};
|
||||
constructor(options: {
|
||||
defaultNamespace: string;
|
||||
xmlNamespace: string;
|
||||
version: string;
|
||||
});
|
||||
/**
|
||||
* EC2 Query reads XResponse.XResult instead of XResponse directly.
|
||||
*/
|
||||
protected useNestedResult(): boolean;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user