@smithy/core 3.23.13 → 3.23.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist-cjs/getSmithyContext.js +6 -0
  2. package/dist-cjs/index.js +1 -1
  3. package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.js +21 -0
  4. package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemePlugin.js +21 -0
  5. package/dist-cjs/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +46 -0
  6. package/dist-cjs/middleware-http-auth-scheme/index.js +6 -0
  7. package/dist-cjs/middleware-http-auth-scheme/resolveAuthOptions.js +24 -0
  8. package/dist-cjs/middleware-http-signing/getHttpSigningMiddleware.js +19 -0
  9. package/dist-cjs/middleware-http-signing/httpSigningMiddleware.js +27 -0
  10. package/dist-cjs/middleware-http-signing/index.js +5 -0
  11. package/dist-cjs/normalizeProvider.js +10 -0
  12. package/dist-cjs/pagination/createPaginator.js +44 -0
  13. package/dist-cjs/request-builder/requestBuilder.js +5 -0
  14. package/dist-cjs/setFeature.js +14 -0
  15. package/dist-cjs/util-identity-and-auth/DefaultIdentityProviderConfig.js +17 -0
  16. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js +38 -0
  17. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js +15 -0
  18. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/index.js +6 -0
  19. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/noAuth.js +9 -0
  20. package/dist-cjs/util-identity-and-auth/index.js +6 -0
  21. package/dist-cjs/util-identity-and-auth/memoizeIdentityProvider.js +61 -0
  22. package/package.json +15 -16
  23. package/dist-types/ts3.4/getSmithyContext.d.ts +0 -5
  24. package/dist-types/ts3.4/index.d.ts +0 -8
  25. package/dist-types/ts3.4/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.d.ts +0 -18
  26. package/dist-types/ts3.4/middleware-http-auth-scheme/getHttpAuthSchemePlugin.d.ts +0 -18
  27. package/dist-types/ts3.4/middleware-http-auth-scheme/httpAuthSchemeMiddleware.d.ts +0 -33
  28. package/dist-types/ts3.4/middleware-http-auth-scheme/index.d.ts +0 -3
  29. package/dist-types/ts3.4/middleware-http-auth-scheme/resolveAuthOptions.d.ts +0 -10
  30. package/dist-types/ts3.4/middleware-http-signing/getHttpSigningMiddleware.d.ts +0 -9
  31. package/dist-types/ts3.4/middleware-http-signing/httpSigningMiddleware.d.ts +0 -5
  32. package/dist-types/ts3.4/middleware-http-signing/index.d.ts +0 -2
  33. package/dist-types/ts3.4/normalizeProvider.d.ts +0 -7
  34. package/dist-types/ts3.4/pagination/createPaginator.d.ts +0 -7
  35. package/dist-types/ts3.4/request-builder/requestBuilder.d.ts +0 -5
  36. package/dist-types/ts3.4/setFeature.d.ts +0 -12
  37. package/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +0 -33
  38. package/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +0 -28
  39. package/dist-types/ts3.4/submodules/cbor/byte-printer.d.ts +0 -6
  40. package/dist-types/ts3.4/submodules/cbor/cbor-decode.d.ts +0 -17
  41. package/dist-types/ts3.4/submodules/cbor/cbor-encode.d.ts +0 -9
  42. package/dist-types/ts3.4/submodules/cbor/cbor-types.d.ts +0 -65
  43. package/dist-types/ts3.4/submodules/cbor/cbor.d.ts +0 -26
  44. package/dist-types/ts3.4/submodules/cbor/index.d.ts +0 -5
  45. package/dist-types/ts3.4/submodules/cbor/parseCborBody.d.ts +0 -31
  46. package/dist-types/ts3.4/submodules/endpoints/index.d.ts +0 -1
  47. package/dist-types/ts3.4/submodules/endpoints/toEndpointV1.d.ts +0 -6
  48. package/dist-types/ts3.4/submodules/event-streams/EventStreamSerde.d.ts +0 -60
  49. package/dist-types/ts3.4/submodules/event-streams/index.d.ts +0 -1
  50. package/dist-types/ts3.4/submodules/protocols/HttpBindingProtocol.d.ts +0 -31
  51. package/dist-types/ts3.4/submodules/protocols/HttpProtocol.d.ts +0 -89
  52. package/dist-types/ts3.4/submodules/protocols/RpcProtocol.d.ts +0 -16
  53. package/dist-types/ts3.4/submodules/protocols/SerdeContext.d.ts +0 -16
  54. package/dist-types/ts3.4/submodules/protocols/collect-stream-body.d.ts +0 -10
  55. package/dist-types/ts3.4/submodules/protocols/extended-encode-uri-component.d.ts +0 -7
  56. package/dist-types/ts3.4/submodules/protocols/index.d.ts +0 -13
  57. package/dist-types/ts3.4/submodules/protocols/requestBuilder.d.ts +0 -51
  58. package/dist-types/ts3.4/submodules/protocols/resolve-path.d.ts +0 -4
  59. package/dist-types/ts3.4/submodules/protocols/serde/FromStringShapeDeserializer.d.ts +0 -13
  60. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeDeserializer.d.ts +0 -21
  61. package/dist-types/ts3.4/submodules/protocols/serde/HttpInterceptingShapeSerializer.d.ts +0 -23
  62. package/dist-types/ts3.4/submodules/protocols/serde/ToStringShapeSerializer.d.ts +0 -14
  63. package/dist-types/ts3.4/submodules/protocols/serde/determineTimestampFormat.d.ts +0 -9
  64. package/dist-types/ts3.4/submodules/schema/TypeRegistry.d.ts +0 -71
  65. package/dist-types/ts3.4/submodules/schema/deref.d.ts +0 -6
  66. package/dist-types/ts3.4/submodules/schema/index.d.ts +0 -14
  67. package/dist-types/ts3.4/submodules/schema/middleware/getSchemaSerdePlugin.d.ts +0 -14
  68. package/dist-types/ts3.4/submodules/schema/middleware/schema-middleware-types.d.ts +0 -11
  69. package/dist-types/ts3.4/submodules/schema/middleware/schemaDeserializationMiddleware.d.ts +0 -9
  70. package/dist-types/ts3.4/submodules/schema/middleware/schemaSerializationMiddleware.d.ts +0 -6
  71. package/dist-types/ts3.4/submodules/schema/schemas/ErrorSchema.d.ts +0 -37
  72. package/dist-types/ts3.4/submodules/schema/schemas/ListSchema.d.ts +0 -23
  73. package/dist-types/ts3.4/submodules/schema/schemas/MapSchema.d.ts +0 -24
  74. package/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +0 -146
  75. package/dist-types/ts3.4/submodules/schema/schemas/OperationSchema.d.ts +0 -23
  76. package/dist-types/ts3.4/submodules/schema/schemas/Schema.d.ts +0 -16
  77. package/dist-types/ts3.4/submodules/schema/schemas/SimpleSchema.d.ts +0 -28
  78. package/dist-types/ts3.4/submodules/schema/schemas/StructureSchema.d.ts +0 -23
  79. package/dist-types/ts3.4/submodules/schema/schemas/operation.d.ts +0 -7
  80. package/dist-types/ts3.4/submodules/schema/schemas/sentinels.d.ts +0 -23
  81. package/dist-types/ts3.4/submodules/schema/schemas/translateTraits.d.ts +0 -13
  82. package/dist-types/ts3.4/submodules/serde/copyDocumentWithTransform.d.ts +0 -6
  83. package/dist-types/ts3.4/submodules/serde/date-utils.d.ts +0 -73
  84. package/dist-types/ts3.4/submodules/serde/generateIdempotencyToken.d.ts +0 -2
  85. package/dist-types/ts3.4/submodules/serde/index.d.ts +0 -10
  86. package/dist-types/ts3.4/submodules/serde/lazy-json.d.ts +0 -45
  87. package/dist-types/ts3.4/submodules/serde/parse-utils.d.ts +0 -270
  88. package/dist-types/ts3.4/submodules/serde/quote-header.d.ts +0 -6
  89. package/dist-types/ts3.4/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +0 -47
  90. package/dist-types/ts3.4/submodules/serde/split-every.d.ts +0 -11
  91. package/dist-types/ts3.4/submodules/serde/split-header.d.ts +0 -5
  92. package/dist-types/ts3.4/submodules/serde/value/NumericValue.d.ts +0 -33
  93. package/dist-types/ts3.4/util-identity-and-auth/DefaultIdentityProviderConfig.d.ts +0 -15
  94. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.d.ts +0 -8
  95. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.d.ts +0 -8
  96. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/index.d.ts +0 -3
  97. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/noAuth.d.ts +0 -8
  98. package/dist-types/ts3.4/util-identity-and-auth/index.d.ts +0 -3
  99. package/dist-types/ts3.4/util-identity-and-auth/memoizeIdentityProvider.d.ts +0 -30
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSmithyContext = void 0;
4
+ const types_1 = require("@smithy/types");
5
+ const getSmithyContext = (context) => context[types_1.SMITHY_CONTEXT_KEY] || (context[types_1.SMITHY_CONTEXT_KEY] = {});
6
+ exports.getSmithyContext = getSmithyContext;
package/dist-cjs/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var types = require('@smithy/types');
4
- var utilMiddleware = require('@smithy/util-middleware');
5
4
  var protocolHttp = require('@smithy/protocol-http');
5
+ var utilMiddleware = require('@smithy/util-middleware');
6
6
  var protocols = require('@smithy/core/protocols');
7
7
 
8
8
  const getSmithyContext = (context) => context[types.SMITHY_CONTEXT_KEY] || (context[types.SMITHY_CONTEXT_KEY] = {});
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHttpAuthSchemeEndpointRuleSetPlugin = exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions = void 0;
4
+ const httpAuthSchemeMiddleware_1 = require("./httpAuthSchemeMiddleware");
5
+ exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
6
+ step: "serialize",
7
+ tags: ["HTTP_AUTH_SCHEME"],
8
+ name: "httpAuthSchemeMiddleware",
9
+ override: true,
10
+ relation: "before",
11
+ toMiddleware: "endpointV2Middleware",
12
+ };
13
+ const getHttpAuthSchemeEndpointRuleSetPlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
14
+ applyToStack: (clientStack) => {
15
+ clientStack.addRelativeTo((0, httpAuthSchemeMiddleware_1.httpAuthSchemeMiddleware)(config, {
16
+ httpAuthSchemeParametersProvider,
17
+ identityProviderConfigProvider,
18
+ }), exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions);
19
+ },
20
+ });
21
+ exports.getHttpAuthSchemeEndpointRuleSetPlugin = getHttpAuthSchemeEndpointRuleSetPlugin;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHttpAuthSchemePlugin = exports.httpAuthSchemeMiddlewareOptions = void 0;
4
+ const httpAuthSchemeMiddleware_1 = require("./httpAuthSchemeMiddleware");
5
+ exports.httpAuthSchemeMiddlewareOptions = {
6
+ step: "serialize",
7
+ tags: ["HTTP_AUTH_SCHEME"],
8
+ name: "httpAuthSchemeMiddleware",
9
+ override: true,
10
+ relation: "before",
11
+ toMiddleware: "serializerMiddleware",
12
+ };
13
+ const getHttpAuthSchemePlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
14
+ applyToStack: (clientStack) => {
15
+ clientStack.addRelativeTo((0, httpAuthSchemeMiddleware_1.httpAuthSchemeMiddleware)(config, {
16
+ httpAuthSchemeParametersProvider,
17
+ identityProviderConfigProvider,
18
+ }), exports.httpAuthSchemeMiddlewareOptions);
19
+ },
20
+ });
21
+ exports.getHttpAuthSchemePlugin = getHttpAuthSchemePlugin;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.httpAuthSchemeMiddleware = void 0;
4
+ const util_middleware_1 = require("@smithy/util-middleware");
5
+ const resolveAuthOptions_1 = require("./resolveAuthOptions");
6
+ function convertHttpAuthSchemesToMap(httpAuthSchemes) {
7
+ const map = new Map();
8
+ for (const scheme of httpAuthSchemes) {
9
+ map.set(scheme.schemeId, scheme);
10
+ }
11
+ return map;
12
+ }
13
+ const httpAuthSchemeMiddleware = (config, mwOptions) => (next, context) => async (args) => {
14
+ const options = config.httpAuthSchemeProvider(await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input));
15
+ const authSchemePreference = config.authSchemePreference ? await config.authSchemePreference() : [];
16
+ const resolvedOptions = (0, resolveAuthOptions_1.resolveAuthOptions)(options, authSchemePreference);
17
+ const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
18
+ const smithyContext = (0, util_middleware_1.getSmithyContext)(context);
19
+ const failureReasons = [];
20
+ for (const option of resolvedOptions) {
21
+ const scheme = authSchemes.get(option.schemeId);
22
+ if (!scheme) {
23
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`);
24
+ continue;
25
+ }
26
+ const identityProvider = scheme.identityProvider(await mwOptions.identityProviderConfigProvider(config));
27
+ if (!identityProvider) {
28
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
29
+ continue;
30
+ }
31
+ const { identityProperties = {}, signingProperties = {} } = option.propertiesExtractor?.(config, context) || {};
32
+ option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties);
33
+ option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties);
34
+ smithyContext.selectedHttpAuthScheme = {
35
+ httpAuthOption: option,
36
+ identity: await identityProvider(option.identityProperties),
37
+ signer: scheme.signer,
38
+ };
39
+ break;
40
+ }
41
+ if (!smithyContext.selectedHttpAuthScheme) {
42
+ throw new Error(failureReasons.join("\n"));
43
+ }
44
+ return next(args);
45
+ };
46
+ exports.httpAuthSchemeMiddleware = httpAuthSchemeMiddleware;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./httpAuthSchemeMiddleware"), exports);
5
+ tslib_1.__exportStar(require("./getHttpAuthSchemeEndpointRuleSetPlugin"), exports);
6
+ tslib_1.__exportStar(require("./getHttpAuthSchemePlugin"), exports);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveAuthOptions = void 0;
4
+ const resolveAuthOptions = (candidateAuthOptions, authSchemePreference) => {
5
+ if (!authSchemePreference || authSchemePreference.length === 0) {
6
+ return candidateAuthOptions;
7
+ }
8
+ const preferredAuthOptions = [];
9
+ for (const preferredSchemeName of authSchemePreference) {
10
+ for (const candidateAuthOption of candidateAuthOptions) {
11
+ const candidateAuthSchemeName = candidateAuthOption.schemeId.split("#")[1];
12
+ if (candidateAuthSchemeName === preferredSchemeName) {
13
+ preferredAuthOptions.push(candidateAuthOption);
14
+ }
15
+ }
16
+ }
17
+ for (const candidateAuthOption of candidateAuthOptions) {
18
+ if (!preferredAuthOptions.find(({ schemeId }) => schemeId === candidateAuthOption.schemeId)) {
19
+ preferredAuthOptions.push(candidateAuthOption);
20
+ }
21
+ }
22
+ return preferredAuthOptions;
23
+ };
24
+ exports.resolveAuthOptions = resolveAuthOptions;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHttpSigningPlugin = exports.httpSigningMiddlewareOptions = void 0;
4
+ const httpSigningMiddleware_1 = require("./httpSigningMiddleware");
5
+ exports.httpSigningMiddlewareOptions = {
6
+ step: "finalizeRequest",
7
+ tags: ["HTTP_SIGNING"],
8
+ name: "httpSigningMiddleware",
9
+ aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"],
10
+ override: true,
11
+ relation: "after",
12
+ toMiddleware: "retryMiddleware",
13
+ };
14
+ const getHttpSigningPlugin = (config) => ({
15
+ applyToStack: (clientStack) => {
16
+ clientStack.addRelativeTo((0, httpSigningMiddleware_1.httpSigningMiddleware)(config), exports.httpSigningMiddlewareOptions);
17
+ },
18
+ });
19
+ exports.getHttpSigningPlugin = getHttpSigningPlugin;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.httpSigningMiddleware = void 0;
4
+ const protocol_http_1 = require("@smithy/protocol-http");
5
+ const util_middleware_1 = require("@smithy/util-middleware");
6
+ const defaultErrorHandler = (signingProperties) => (error) => {
7
+ throw error;
8
+ };
9
+ const defaultSuccessHandler = (httpResponse, signingProperties) => { };
10
+ const httpSigningMiddleware = (config) => (next, context) => async (args) => {
11
+ if (!protocol_http_1.HttpRequest.isInstance(args.request)) {
12
+ return next(args);
13
+ }
14
+ const smithyContext = (0, util_middleware_1.getSmithyContext)(context);
15
+ const scheme = smithyContext.selectedHttpAuthScheme;
16
+ if (!scheme) {
17
+ throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
18
+ }
19
+ const { httpAuthOption: { signingProperties = {} }, identity, signer, } = scheme;
20
+ const output = await next({
21
+ ...args,
22
+ request: await signer.sign(args.request, identity, signingProperties),
23
+ }).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
24
+ (signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
25
+ return output;
26
+ };
27
+ exports.httpSigningMiddleware = httpSigningMiddleware;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./httpSigningMiddleware"), exports);
5
+ tslib_1.__exportStar(require("./getHttpSigningMiddleware"), exports);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeProvider = void 0;
4
+ const normalizeProvider = (input) => {
5
+ if (typeof input === "function")
6
+ return input;
7
+ const promisified = Promise.resolve(input);
8
+ return () => promisified;
9
+ };
10
+ exports.normalizeProvider = normalizeProvider;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createPaginator = createPaginator;
4
+ const makePagedClientRequest = async (CommandCtor, client, input, withCommand = (_) => _, ...args) => {
5
+ let command = new CommandCtor(input);
6
+ command = withCommand(command) ?? command;
7
+ return await client.send(command, ...args);
8
+ };
9
+ function createPaginator(ClientCtor, CommandCtor, inputTokenName, outputTokenName, pageSizeTokenName) {
10
+ return async function* paginateOperation(config, input, ...additionalArguments) {
11
+ const _input = input;
12
+ let token = config.startingToken ?? _input[inputTokenName];
13
+ let hasNext = true;
14
+ let page;
15
+ while (hasNext) {
16
+ _input[inputTokenName] = token;
17
+ if (pageSizeTokenName) {
18
+ _input[pageSizeTokenName] = _input[pageSizeTokenName] ?? config.pageSize;
19
+ }
20
+ if (config.client instanceof ClientCtor) {
21
+ page = await makePagedClientRequest(CommandCtor, config.client, input, config.withCommand, ...additionalArguments);
22
+ }
23
+ else {
24
+ throw new Error(`Invalid client, expected instance of ${ClientCtor.name}`);
25
+ }
26
+ yield page;
27
+ const prevToken = token;
28
+ token = get(page, outputTokenName);
29
+ hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
30
+ }
31
+ return undefined;
32
+ };
33
+ }
34
+ const get = (fromObject, path) => {
35
+ let cursor = fromObject;
36
+ const pathComponents = path.split(".");
37
+ for (const step of pathComponents) {
38
+ if (!cursor || typeof cursor !== "object") {
39
+ return undefined;
40
+ }
41
+ cursor = cursor[step];
42
+ }
43
+ return cursor;
44
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestBuilder = void 0;
4
+ var protocols_1 = require("@smithy/core/protocols");
5
+ Object.defineProperty(exports, "requestBuilder", { enumerable: true, get: function () { return protocols_1.requestBuilder; } });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setFeature = setFeature;
4
+ function setFeature(context, feature, value) {
5
+ if (!context.__smithy_context) {
6
+ context.__smithy_context = {
7
+ features: {},
8
+ };
9
+ }
10
+ else if (!context.__smithy_context.features) {
11
+ context.__smithy_context.features = {};
12
+ }
13
+ context.__smithy_context.features[feature] = value;
14
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultIdentityProviderConfig = void 0;
4
+ class DefaultIdentityProviderConfig {
5
+ authSchemes = new Map();
6
+ constructor(config) {
7
+ for (const [key, value] of Object.entries(config)) {
8
+ if (value !== undefined) {
9
+ this.authSchemes.set(key, value);
10
+ }
11
+ }
12
+ }
13
+ getIdentityProvider(schemeId) {
14
+ return this.authSchemes.get(schemeId);
15
+ }
16
+ }
17
+ exports.DefaultIdentityProviderConfig = DefaultIdentityProviderConfig;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpApiKeyAuthSigner = void 0;
4
+ const protocol_http_1 = require("@smithy/protocol-http");
5
+ const types_1 = require("@smithy/types");
6
+ class HttpApiKeyAuthSigner {
7
+ async sign(httpRequest, identity, signingProperties) {
8
+ if (!signingProperties) {
9
+ throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
10
+ }
11
+ if (!signingProperties.name) {
12
+ throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
13
+ }
14
+ if (!signingProperties.in) {
15
+ throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
16
+ }
17
+ if (!identity.apiKey) {
18
+ throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
19
+ }
20
+ const clonedRequest = protocol_http_1.HttpRequest.clone(httpRequest);
21
+ if (signingProperties.in === types_1.HttpApiKeyAuthLocation.QUERY) {
22
+ clonedRequest.query[signingProperties.name] = identity.apiKey;
23
+ }
24
+ else if (signingProperties.in === types_1.HttpApiKeyAuthLocation.HEADER) {
25
+ clonedRequest.headers[signingProperties.name] = signingProperties.scheme
26
+ ? `${signingProperties.scheme} ${identity.apiKey}`
27
+ : identity.apiKey;
28
+ }
29
+ else {
30
+ throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
31
+ "but found: `" +
32
+ signingProperties.in +
33
+ "`");
34
+ }
35
+ return clonedRequest;
36
+ }
37
+ }
38
+ exports.HttpApiKeyAuthSigner = HttpApiKeyAuthSigner;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HttpBearerAuthSigner = void 0;
4
+ const protocol_http_1 = require("@smithy/protocol-http");
5
+ class HttpBearerAuthSigner {
6
+ async sign(httpRequest, identity, signingProperties) {
7
+ const clonedRequest = protocol_http_1.HttpRequest.clone(httpRequest);
8
+ if (!identity.token) {
9
+ throw new Error("request could not be signed with `token` since the `token` is not defined");
10
+ }
11
+ clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
12
+ return clonedRequest;
13
+ }
14
+ }
15
+ exports.HttpBearerAuthSigner = HttpBearerAuthSigner;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./httpApiKeyAuth"), exports);
5
+ tslib_1.__exportStar(require("./httpBearerAuth"), exports);
6
+ tslib_1.__exportStar(require("./noAuth"), exports);
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoAuthSigner = void 0;
4
+ class NoAuthSigner {
5
+ async sign(httpRequest, identity, signingProperties) {
6
+ return httpRequest;
7
+ }
8
+ }
9
+ exports.NoAuthSigner = NoAuthSigner;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./DefaultIdentityProviderConfig"), exports);
5
+ tslib_1.__exportStar(require("./httpAuthSchemes"), exports);
6
+ tslib_1.__exportStar(require("./memoizeIdentityProvider"), exports);
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.memoizeIdentityProvider = exports.doesIdentityRequireRefresh = exports.isIdentityExpired = exports.EXPIRATION_MS = exports.createIsIdentityExpiredFunction = void 0;
4
+ const createIsIdentityExpiredFunction = (expirationMs) => function isIdentityExpired(identity) {
5
+ return (0, exports.doesIdentityRequireRefresh)(identity) && identity.expiration.getTime() - Date.now() < expirationMs;
6
+ };
7
+ exports.createIsIdentityExpiredFunction = createIsIdentityExpiredFunction;
8
+ exports.EXPIRATION_MS = 300_000;
9
+ exports.isIdentityExpired = (0, exports.createIsIdentityExpiredFunction)(exports.EXPIRATION_MS);
10
+ const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
11
+ exports.doesIdentityRequireRefresh = doesIdentityRequireRefresh;
12
+ const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
13
+ if (provider === undefined) {
14
+ return undefined;
15
+ }
16
+ const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
17
+ let resolved;
18
+ let pending;
19
+ let hasResult;
20
+ let isConstant = false;
21
+ const coalesceProvider = async (options) => {
22
+ if (!pending) {
23
+ pending = normalizedProvider(options);
24
+ }
25
+ try {
26
+ resolved = await pending;
27
+ hasResult = true;
28
+ isConstant = false;
29
+ }
30
+ finally {
31
+ pending = undefined;
32
+ }
33
+ return resolved;
34
+ };
35
+ if (isExpired === undefined) {
36
+ return async (options) => {
37
+ if (!hasResult || options?.forceRefresh) {
38
+ resolved = await coalesceProvider(options);
39
+ }
40
+ return resolved;
41
+ };
42
+ }
43
+ return async (options) => {
44
+ if (!hasResult || options?.forceRefresh) {
45
+ resolved = await coalesceProvider(options);
46
+ }
47
+ if (isConstant) {
48
+ return resolved;
49
+ }
50
+ if (!requiresRefresh(resolved)) {
51
+ isConstant = true;
52
+ return resolved;
53
+ }
54
+ if (isExpired(resolved)) {
55
+ await coalesceProvider(options);
56
+ return resolved;
57
+ }
58
+ return resolved;
59
+ };
60
+ };
61
+ exports.memoizeIdentityProvider = memoizeIdentityProvider;
package/package.json CHANGED
@@ -1,22 +1,21 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.23.13",
3
+ "version": "3.23.14",
4
4
  "scripts": {
5
- "build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
- "build:cjs": "node ../../scripts/inline core",
7
- "build:es": "yarn g:tsc -p tsconfig.es.json",
5
+ "build": "concurrently 'yarn:build:types' 'yarn:build:es:cjs'",
6
+ "build:es:cjs": "yarn g:tsc -p tsconfig.es.json && node ../../scripts/inline core",
8
7
  "build:types": "yarn g:tsc -p tsconfig.types.json",
9
8
  "build:types:downlevel": "premove dist-types/ts3.4 && downlevel-dts dist-types dist-types/ts3.4",
10
- "stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
11
9
  "clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
12
- "lint": "npx eslint -c ../../.eslintrc.js \"src/**/*.ts\" --fix && node ./scripts/lint",
13
- "format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
14
10
  "extract:docs": "api-extractor run --local",
15
- "test:cbor:perf": "node ./scripts/cbor-perf.mjs",
11
+ "format": "prettier --config ../../prettier.config.js --ignore-path ../../.prettierignore --write \"**/*.{ts,md,json}\"",
12
+ "lint": "npx eslint -c ../../.eslintrc.js \"src/**/*.ts\" --fix && node ./scripts/lint",
13
+ "stage-release": "premove .release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
16
14
  "test": "yarn g:vitest run",
17
- "test:watch": "yarn g:vitest watch",
15
+ "test:cbor:perf": "node ./scripts/cbor-perf.mjs",
18
16
  "test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
19
- "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
17
+ "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts",
18
+ "test:watch": "yarn g:vitest watch"
20
19
  },
21
20
  "main": "./dist-cjs/index.js",
22
21
  "module": "./dist-es/index.js",
@@ -86,13 +85,13 @@
86
85
  "license": "Apache-2.0",
87
86
  "sideEffects": false,
88
87
  "dependencies": {
89
- "@smithy/protocol-http": "^5.3.12",
90
- "@smithy/types": "^4.13.1",
91
- "@smithy/url-parser": "^4.2.12",
88
+ "@smithy/protocol-http": "^5.3.13",
89
+ "@smithy/types": "^4.14.0",
90
+ "@smithy/url-parser": "^4.2.13",
92
91
  "@smithy/util-base64": "^4.3.2",
93
92
  "@smithy/util-body-length-browser": "^4.2.2",
94
- "@smithy/util-middleware": "^4.2.12",
95
- "@smithy/util-stream": "^4.5.21",
93
+ "@smithy/util-middleware": "^4.2.13",
94
+ "@smithy/util-stream": "^4.5.22",
96
95
  "@smithy/util-utf8": "^4.2.2",
97
96
  "@smithy/uuid": "^1.1.2",
98
97
  "tslib": "^2.6.2"
@@ -129,7 +128,7 @@
129
128
  "directory": "packages/core"
130
129
  },
131
130
  "devDependencies": {
132
- "@smithy/eventstream-serde-node": "^4.2.12",
131
+ "@smithy/eventstream-serde-node": "^4.2.13",
133
132
  "@types/node": "^18.11.9",
134
133
  "concurrently": "7.0.0",
135
134
  "downlevel-dts": "0.10.1",
@@ -1,5 +0,0 @@
1
- import { HandlerExecutionContext } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export declare const getSmithyContext: (context: HandlerExecutionContext) => Record<string, unknown>;
@@ -1,8 +0,0 @@
1
- export * from "./getSmithyContext";
2
- export * from "./middleware-http-auth-scheme";
3
- export * from "./middleware-http-signing";
4
- export * from "./normalizeProvider";
5
- export { createPaginator } from "./pagination/createPaginator";
6
- export * from "./request-builder/requestBuilder";
7
- export * from "./setFeature";
8
- export * from "./util-identity-and-auth";
@@ -1,18 +0,0 @@
1
- import { HandlerExecutionContext, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, IdentityProviderConfig, Pluggable, RelativeMiddlewareOptions, SerializeHandlerOptions } from "@smithy/types";
2
- import { PreviouslyResolved } from "./httpAuthSchemeMiddleware";
3
- /**
4
- * @internal
5
- */
6
- export declare const httpAuthSchemeEndpointRuleSetMiddlewareOptions: SerializeHandlerOptions & RelativeMiddlewareOptions;
7
- /**
8
- * @internal
9
- */
10
- interface HttpAuthSchemeEndpointRuleSetPluginOptions<TConfig extends object, TContext extends HandlerExecutionContext, TParameters extends HttpAuthSchemeParameters, TInput extends object> {
11
- httpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider<TConfig, TContext, TParameters, TInput>;
12
- identityProviderConfigProvider: (config: TConfig) => Promise<IdentityProviderConfig>;
13
- }
14
- /**
15
- * @internal
16
- */
17
- export declare const getHttpAuthSchemeEndpointRuleSetPlugin: <TConfig extends object, TContext extends HandlerExecutionContext, TParameters extends HttpAuthSchemeParameters, TInput extends object>(config: TConfig & PreviouslyResolved<TParameters>, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }: HttpAuthSchemeEndpointRuleSetPluginOptions<TConfig, TContext, TParameters, TInput>) => Pluggable<any, any>;
18
- export {};
@@ -1,18 +0,0 @@
1
- import { HandlerExecutionContext, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, IdentityProviderConfig, Pluggable, RelativeMiddlewareOptions, SerializeHandlerOptions } from "@smithy/types";
2
- import { PreviouslyResolved } from "./httpAuthSchemeMiddleware";
3
- /**
4
- * @internal
5
- */
6
- export declare const httpAuthSchemeMiddlewareOptions: SerializeHandlerOptions & RelativeMiddlewareOptions;
7
- /**
8
- * @internal
9
- */
10
- interface HttpAuthSchemePluginOptions<TConfig extends object, TContext extends HandlerExecutionContext, TParameters extends HttpAuthSchemeParameters, TInput extends object> {
11
- httpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider<TConfig, TContext, TParameters, TInput>;
12
- identityProviderConfigProvider: (config: TConfig) => Promise<IdentityProviderConfig>;
13
- }
14
- /**
15
- * @internal
16
- */
17
- export declare const getHttpAuthSchemePlugin: <TConfig extends object, TContext extends HandlerExecutionContext, TParameters extends HttpAuthSchemeParameters, TInput extends object>(config: TConfig & PreviouslyResolved<TParameters>, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }: HttpAuthSchemePluginOptions<TConfig, TContext, TParameters, TInput>) => Pluggable<any, any>;
18
- export {};
@@ -1,33 +0,0 @@
1
- import { HandlerExecutionContext, HttpAuthScheme, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider, IdentityProviderConfig, Provider, SelectedHttpAuthScheme, SerializeMiddleware, SMITHY_CONTEXT_KEY } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export interface PreviouslyResolved<TParameters extends HttpAuthSchemeParameters> {
6
- authSchemePreference?: Provider<string[]>;
7
- httpAuthSchemes: HttpAuthScheme[];
8
- httpAuthSchemeProvider: HttpAuthSchemeProvider<TParameters>;
9
- }
10
- /**
11
- * @internal
12
- */
13
- interface HttpAuthSchemeMiddlewareOptions<TConfig extends object, TContext extends HandlerExecutionContext, TParameters extends HttpAuthSchemeParameters, TInput extends object> {
14
- httpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider<TConfig, TContext, TParameters, TInput>;
15
- identityProviderConfigProvider: (config: TConfig) => Promise<IdentityProviderConfig>;
16
- }
17
- /**
18
- * @internal
19
- */
20
- interface HttpAuthSchemeMiddlewareSmithyContext extends Record<string, unknown> {
21
- selectedHttpAuthScheme?: SelectedHttpAuthScheme;
22
- }
23
- /**
24
- * @internal
25
- */
26
- interface HttpAuthSchemeMiddlewareHandlerExecutionContext extends HandlerExecutionContext {
27
- [SMITHY_CONTEXT_KEY]?: HttpAuthSchemeMiddlewareSmithyContext;
28
- }
29
- /**
30
- * @internal
31
- */
32
- export declare const httpAuthSchemeMiddleware: <TInput extends object, Output extends object, TConfig extends object, TContext extends HttpAuthSchemeMiddlewareHandlerExecutionContext, TParameters extends HttpAuthSchemeParameters>(config: TConfig & PreviouslyResolved<TParameters>, mwOptions: HttpAuthSchemeMiddlewareOptions<TConfig, TContext, TParameters, TInput>) => SerializeMiddleware<TInput, Output>;
33
- export {};
@@ -1,3 +0,0 @@
1
- export * from "./httpAuthSchemeMiddleware";
2
- export * from "./getHttpAuthSchemeEndpointRuleSetPlugin";
3
- export * from "./getHttpAuthSchemePlugin";
@@ -1,10 +0,0 @@
1
- import { HttpAuthOption } from "@smithy/types";
2
- /**
3
- * Resolves list of auth options based on the supported ones, vs the preference list.
4
- *
5
- * @param candidateAuthOptions list of supported auth options selected by the standard
6
- * resolution process (model-based, endpoints 2.0, etc.)
7
- * @param authSchemePreference list of auth schemes preferred by user.
8
- * @returns
9
- */
10
- export declare const resolveAuthOptions: (candidateAuthOptions: HttpAuthOption[], authSchemePreference: string[]) => HttpAuthOption[];
@@ -1,9 +0,0 @@
1
- import { FinalizeRequestHandlerOptions, Pluggable, RelativeMiddlewareOptions } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export declare const httpSigningMiddlewareOptions: FinalizeRequestHandlerOptions & RelativeMiddlewareOptions;
6
- /**
7
- * @internal
8
- */
9
- export declare const getHttpSigningPlugin: <Input extends object, Output extends object>(config: object) => Pluggable<Input, Output>;
@@ -1,5 +0,0 @@
1
- import { FinalizeRequestMiddleware } from "@smithy/types";
2
- /**
3
- * @internal
4
- */
5
- export declare const httpSigningMiddleware: <Input extends object, Output extends object>(config: object) => FinalizeRequestMiddleware<Input, Output>;
@@ -1,2 +0,0 @@
1
- export * from "./httpSigningMiddleware";
2
- export * from "./getHttpSigningMiddleware";
@@ -1,7 +0,0 @@
1
- import { Provider } from "@smithy/types";
2
- /**
3
- * @internal
4
- *
5
- * @returns a provider function for the input value if it isn't already one.
6
- */
7
- export declare const normalizeProvider: <T>(input: T | Provider<T>) => Provider<T>;