@smithy/core 3.13.0 → 3.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.js +308 -412
- package/dist-cjs/submodules/cbor/index.js +957 -969
- package/dist-cjs/submodules/event-streams/index.js +198 -249
- package/dist-cjs/submodules/protocols/index.js +793 -895
- package/dist-cjs/submodules/schema/index.js +617 -811
- package/dist-cjs/submodules/serde/index.js +584 -680
- package/dist-es/submodules/cbor/CborCodec.js +4 -0
- package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +3 -3
- package/dist-es/submodules/cbor/cbor-decode.js +18 -18
- package/dist-es/submodules/cbor/cbor-encode.js +5 -5
- package/dist-es/submodules/event-streams/EventStreamSerde.js +5 -0
- package/dist-es/submodules/protocols/HttpProtocol.js +2 -0
- package/dist-es/submodules/protocols/requestBuilder.js +9 -7
- package/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +2 -0
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeDeserializer.js +3 -0
- package/dist-es/submodules/protocols/serde/HttpInterceptingShapeSerializer.js +3 -0
- package/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +3 -2
- package/dist-es/submodules/schema/TypeRegistry.js +4 -1
- package/dist-es/submodules/schema/schemas/ErrorSchema.js +3 -5
- package/dist-es/submodules/schema/schemas/ListSchema.js +5 -5
- package/dist-es/submodules/schema/schemas/MapSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/NormalizedSchema.js +16 -8
- package/dist-es/submodules/schema/schemas/OperationSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/Schema.js +3 -0
- package/dist-es/submodules/schema/schemas/SimpleSchema.js +5 -5
- package/dist-es/submodules/schema/schemas/StructureSchema.js +6 -5
- package/dist-es/submodules/schema/schemas/sentinels.js +14 -14
- package/dist-es/submodules/serde/value/NumericValue.js +2 -0
- package/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +1 -1
- package/dist-es/util-identity-and-auth/memoizeIdentityProvider.js +4 -2
- package/package.json +11 -11
package/dist-cjs/index.js
CHANGED
|
@@ -1,453 +1,349 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
DefaultIdentityProviderConfig: () => DefaultIdentityProviderConfig,
|
|
24
|
-
EXPIRATION_MS: () => EXPIRATION_MS,
|
|
25
|
-
HttpApiKeyAuthSigner: () => HttpApiKeyAuthSigner,
|
|
26
|
-
HttpBearerAuthSigner: () => HttpBearerAuthSigner,
|
|
27
|
-
NoAuthSigner: () => NoAuthSigner,
|
|
28
|
-
createIsIdentityExpiredFunction: () => createIsIdentityExpiredFunction,
|
|
29
|
-
createPaginator: () => createPaginator,
|
|
30
|
-
doesIdentityRequireRefresh: () => doesIdentityRequireRefresh,
|
|
31
|
-
getHttpAuthSchemeEndpointRuleSetPlugin: () => getHttpAuthSchemeEndpointRuleSetPlugin,
|
|
32
|
-
getHttpAuthSchemePlugin: () => getHttpAuthSchemePlugin,
|
|
33
|
-
getHttpSigningPlugin: () => getHttpSigningPlugin,
|
|
34
|
-
getSmithyContext: () => getSmithyContext,
|
|
35
|
-
httpAuthSchemeEndpointRuleSetMiddlewareOptions: () => httpAuthSchemeEndpointRuleSetMiddlewareOptions,
|
|
36
|
-
httpAuthSchemeMiddleware: () => httpAuthSchemeMiddleware,
|
|
37
|
-
httpAuthSchemeMiddlewareOptions: () => httpAuthSchemeMiddlewareOptions,
|
|
38
|
-
httpSigningMiddleware: () => httpSigningMiddleware,
|
|
39
|
-
httpSigningMiddlewareOptions: () => httpSigningMiddlewareOptions,
|
|
40
|
-
isIdentityExpired: () => isIdentityExpired,
|
|
41
|
-
memoizeIdentityProvider: () => memoizeIdentityProvider,
|
|
42
|
-
normalizeProvider: () => normalizeProvider,
|
|
43
|
-
requestBuilder: () => import_protocols.requestBuilder,
|
|
44
|
-
setFeature: () => setFeature
|
|
45
|
-
});
|
|
46
|
-
module.exports = __toCommonJS(index_exports);
|
|
1
|
+
'use strict';
|
|
47
2
|
|
|
48
|
-
|
|
49
|
-
var
|
|
50
|
-
var
|
|
3
|
+
var types = require('@smithy/types');
|
|
4
|
+
var utilMiddleware = require('@smithy/util-middleware');
|
|
5
|
+
var middlewareSerde = require('@smithy/middleware-serde');
|
|
6
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
7
|
+
var protocols = require('@smithy/core/protocols');
|
|
51
8
|
|
|
52
|
-
|
|
53
|
-
var import_util_middleware = require("@smithy/util-middleware");
|
|
9
|
+
const getSmithyContext = (context) => context[types.SMITHY_CONTEXT_KEY] || (context[types.SMITHY_CONTEXT_KEY] = {});
|
|
54
10
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
11
|
+
const resolveAuthOptions = (candidateAuthOptions, authSchemePreference) => {
|
|
12
|
+
if (!authSchemePreference || authSchemePreference.length === 0) {
|
|
13
|
+
return candidateAuthOptions;
|
|
14
|
+
}
|
|
15
|
+
const preferredAuthOptions = [];
|
|
16
|
+
for (const preferredSchemeName of authSchemePreference) {
|
|
17
|
+
for (const candidateAuthOption of candidateAuthOptions) {
|
|
18
|
+
const candidateAuthSchemeName = candidateAuthOption.schemeId.split("#")[1];
|
|
19
|
+
if (candidateAuthSchemeName === preferredSchemeName) {
|
|
20
|
+
preferredAuthOptions.push(candidateAuthOption);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
67
23
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
24
|
+
for (const candidateAuthOption of candidateAuthOptions) {
|
|
25
|
+
if (!preferredAuthOptions.find(({ schemeId }) => schemeId === candidateAuthOption.schemeId)) {
|
|
26
|
+
preferredAuthOptions.push(candidateAuthOption);
|
|
27
|
+
}
|
|
72
28
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}, "resolveAuthOptions");
|
|
29
|
+
return preferredAuthOptions;
|
|
30
|
+
};
|
|
76
31
|
|
|
77
|
-
// src/middleware-http-auth-scheme/httpAuthSchemeMiddleware.ts
|
|
78
32
|
function convertHttpAuthSchemesToMap(httpAuthSchemes) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
33
|
+
const map = new Map();
|
|
34
|
+
for (const scheme of httpAuthSchemes) {
|
|
35
|
+
map.set(scheme.schemeId, scheme);
|
|
36
|
+
}
|
|
37
|
+
return map;
|
|
84
38
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
39
|
+
const httpAuthSchemeMiddleware = (config, mwOptions) => (next, context) => async (args) => {
|
|
40
|
+
const options = config.httpAuthSchemeProvider(await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input));
|
|
41
|
+
const authSchemePreference = config.authSchemePreference ? await config.authSchemePreference() : [];
|
|
42
|
+
const resolvedOptions = resolveAuthOptions(options, authSchemePreference);
|
|
43
|
+
const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
|
|
44
|
+
const smithyContext = utilMiddleware.getSmithyContext(context);
|
|
45
|
+
const failureReasons = [];
|
|
46
|
+
for (const option of resolvedOptions) {
|
|
47
|
+
const scheme = authSchemes.get(option.schemeId);
|
|
48
|
+
if (!scheme) {
|
|
49
|
+
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const identityProvider = scheme.identityProvider(await mwOptions.identityProviderConfigProvider(config));
|
|
53
|
+
if (!identityProvider) {
|
|
54
|
+
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const { identityProperties = {}, signingProperties = {} } = option.propertiesExtractor?.(config, context) || {};
|
|
58
|
+
option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties);
|
|
59
|
+
option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties);
|
|
60
|
+
smithyContext.selectedHttpAuthScheme = {
|
|
61
|
+
httpAuthOption: option,
|
|
62
|
+
identity: await identityProvider(option.identityProperties),
|
|
63
|
+
signer: scheme.signer,
|
|
64
|
+
};
|
|
65
|
+
break;
|
|
100
66
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
|
|
104
|
-
continue;
|
|
67
|
+
if (!smithyContext.selectedHttpAuthScheme) {
|
|
68
|
+
throw new Error(failureReasons.join("\n"));
|
|
105
69
|
}
|
|
106
|
-
|
|
107
|
-
option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties);
|
|
108
|
-
option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties);
|
|
109
|
-
smithyContext.selectedHttpAuthScheme = {
|
|
110
|
-
httpAuthOption: option,
|
|
111
|
-
identity: await identityProvider(option.identityProperties),
|
|
112
|
-
signer: scheme.signer
|
|
113
|
-
};
|
|
114
|
-
break;
|
|
115
|
-
}
|
|
116
|
-
if (!smithyContext.selectedHttpAuthScheme) {
|
|
117
|
-
throw new Error(failureReasons.join("\n"));
|
|
118
|
-
}
|
|
119
|
-
return next(args);
|
|
120
|
-
}, "httpAuthSchemeMiddleware");
|
|
121
|
-
|
|
122
|
-
// src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts
|
|
123
|
-
var httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
|
|
124
|
-
step: "serialize",
|
|
125
|
-
tags: ["HTTP_AUTH_SCHEME"],
|
|
126
|
-
name: "httpAuthSchemeMiddleware",
|
|
127
|
-
override: true,
|
|
128
|
-
relation: "before",
|
|
129
|
-
toMiddleware: "endpointV2Middleware"
|
|
70
|
+
return next(args);
|
|
130
71
|
};
|
|
131
|
-
var getHttpAuthSchemeEndpointRuleSetPlugin = /* @__PURE__ */ __name((config, {
|
|
132
|
-
httpAuthSchemeParametersProvider,
|
|
133
|
-
identityProviderConfigProvider
|
|
134
|
-
}) => ({
|
|
135
|
-
applyToStack: /* @__PURE__ */ __name((clientStack) => {
|
|
136
|
-
clientStack.addRelativeTo(
|
|
137
|
-
httpAuthSchemeMiddleware(config, {
|
|
138
|
-
httpAuthSchemeParametersProvider,
|
|
139
|
-
identityProviderConfigProvider
|
|
140
|
-
}),
|
|
141
|
-
httpAuthSchemeEndpointRuleSetMiddlewareOptions
|
|
142
|
-
);
|
|
143
|
-
}, "applyToStack")
|
|
144
|
-
}), "getHttpAuthSchemeEndpointRuleSetPlugin");
|
|
145
72
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
relation: "before",
|
|
154
|
-
toMiddleware: import_middleware_serde.serializerMiddlewareOption.name
|
|
73
|
+
const httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
|
|
74
|
+
step: "serialize",
|
|
75
|
+
tags: ["HTTP_AUTH_SCHEME"],
|
|
76
|
+
name: "httpAuthSchemeMiddleware",
|
|
77
|
+
override: true,
|
|
78
|
+
relation: "before",
|
|
79
|
+
toMiddleware: "endpointV2Middleware",
|
|
155
80
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
identityProviderConfigProvider
|
|
165
|
-
}),
|
|
166
|
-
httpAuthSchemeMiddlewareOptions
|
|
167
|
-
);
|
|
168
|
-
}, "applyToStack")
|
|
169
|
-
}), "getHttpAuthSchemePlugin");
|
|
170
|
-
|
|
171
|
-
// src/middleware-http-signing/httpSigningMiddleware.ts
|
|
172
|
-
var import_protocol_http = require("@smithy/protocol-http");
|
|
173
|
-
|
|
174
|
-
var defaultErrorHandler = /* @__PURE__ */ __name((signingProperties) => (error) => {
|
|
175
|
-
throw error;
|
|
176
|
-
}, "defaultErrorHandler");
|
|
177
|
-
var defaultSuccessHandler = /* @__PURE__ */ __name((httpResponse, signingProperties) => {
|
|
178
|
-
}, "defaultSuccessHandler");
|
|
179
|
-
var httpSigningMiddleware = /* @__PURE__ */ __name((config) => (next, context) => async (args) => {
|
|
180
|
-
if (!import_protocol_http.HttpRequest.isInstance(args.request)) {
|
|
181
|
-
return next(args);
|
|
182
|
-
}
|
|
183
|
-
const smithyContext = (0, import_util_middleware.getSmithyContext)(context);
|
|
184
|
-
const scheme = smithyContext.selectedHttpAuthScheme;
|
|
185
|
-
if (!scheme) {
|
|
186
|
-
throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
|
|
187
|
-
}
|
|
188
|
-
const {
|
|
189
|
-
httpAuthOption: { signingProperties = {} },
|
|
190
|
-
identity,
|
|
191
|
-
signer
|
|
192
|
-
} = scheme;
|
|
193
|
-
const output = await next({
|
|
194
|
-
...args,
|
|
195
|
-
request: await signer.sign(args.request, identity, signingProperties)
|
|
196
|
-
}).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
|
|
197
|
-
(signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
|
|
198
|
-
return output;
|
|
199
|
-
}, "httpSigningMiddleware");
|
|
81
|
+
const getHttpAuthSchemeEndpointRuleSetPlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
|
|
82
|
+
applyToStack: (clientStack) => {
|
|
83
|
+
clientStack.addRelativeTo(httpAuthSchemeMiddleware(config, {
|
|
84
|
+
httpAuthSchemeParametersProvider,
|
|
85
|
+
identityProviderConfigProvider,
|
|
86
|
+
}), httpAuthSchemeEndpointRuleSetMiddlewareOptions);
|
|
87
|
+
},
|
|
88
|
+
});
|
|
200
89
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
relation: "after",
|
|
209
|
-
toMiddleware: "retryMiddleware"
|
|
90
|
+
const httpAuthSchemeMiddlewareOptions = {
|
|
91
|
+
step: "serialize",
|
|
92
|
+
tags: ["HTTP_AUTH_SCHEME"],
|
|
93
|
+
name: "httpAuthSchemeMiddleware",
|
|
94
|
+
override: true,
|
|
95
|
+
relation: "before",
|
|
96
|
+
toMiddleware: middlewareSerde.serializerMiddlewareOption.name,
|
|
210
97
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
if (typeof input === "function") return input;
|
|
220
|
-
const promisified = Promise.resolve(input);
|
|
221
|
-
return () => promisified;
|
|
222
|
-
}, "normalizeProvider");
|
|
98
|
+
const getHttpAuthSchemePlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
|
|
99
|
+
applyToStack: (clientStack) => {
|
|
100
|
+
clientStack.addRelativeTo(httpAuthSchemeMiddleware(config, {
|
|
101
|
+
httpAuthSchemeParametersProvider,
|
|
102
|
+
identityProviderConfigProvider,
|
|
103
|
+
}), httpAuthSchemeMiddlewareOptions);
|
|
104
|
+
},
|
|
105
|
+
});
|
|
223
106
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
return /* @__PURE__ */ __name(async function* paginateOperation(config, input, ...additionalArguments) {
|
|
232
|
-
const _input = input;
|
|
233
|
-
let token = config.startingToken ?? _input[inputTokenName];
|
|
234
|
-
let hasNext = true;
|
|
235
|
-
let page;
|
|
236
|
-
while (hasNext) {
|
|
237
|
-
_input[inputTokenName] = token;
|
|
238
|
-
if (pageSizeTokenName) {
|
|
239
|
-
_input[pageSizeTokenName] = _input[pageSizeTokenName] ?? config.pageSize;
|
|
240
|
-
}
|
|
241
|
-
if (config.client instanceof ClientCtor) {
|
|
242
|
-
page = await makePagedClientRequest(
|
|
243
|
-
CommandCtor,
|
|
244
|
-
config.client,
|
|
245
|
-
input,
|
|
246
|
-
config.withCommand,
|
|
247
|
-
...additionalArguments
|
|
248
|
-
);
|
|
249
|
-
} else {
|
|
250
|
-
throw new Error(`Invalid client, expected instance of ${ClientCtor.name}`);
|
|
251
|
-
}
|
|
252
|
-
yield page;
|
|
253
|
-
const prevToken = token;
|
|
254
|
-
token = get(page, outputTokenName);
|
|
255
|
-
hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
|
|
107
|
+
const defaultErrorHandler = (signingProperties) => (error) => {
|
|
108
|
+
throw error;
|
|
109
|
+
};
|
|
110
|
+
const defaultSuccessHandler = (httpResponse, signingProperties) => { };
|
|
111
|
+
const httpSigningMiddleware = (config) => (next, context) => async (args) => {
|
|
112
|
+
if (!protocolHttp.HttpRequest.isInstance(args.request)) {
|
|
113
|
+
return next(args);
|
|
256
114
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var get = /* @__PURE__ */ __name((fromObject, path) => {
|
|
262
|
-
let cursor = fromObject;
|
|
263
|
-
const pathComponents = path.split(".");
|
|
264
|
-
for (const step of pathComponents) {
|
|
265
|
-
if (!cursor || typeof cursor !== "object") {
|
|
266
|
-
return void 0;
|
|
115
|
+
const smithyContext = utilMiddleware.getSmithyContext(context);
|
|
116
|
+
const scheme = smithyContext.selectedHttpAuthScheme;
|
|
117
|
+
if (!scheme) {
|
|
118
|
+
throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
|
|
267
119
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
120
|
+
const { httpAuthOption: { signingProperties = {} }, identity, signer, } = scheme;
|
|
121
|
+
const output = await next({
|
|
122
|
+
...args,
|
|
123
|
+
request: await signer.sign(args.request, identity, signingProperties),
|
|
124
|
+
}).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
|
|
125
|
+
(signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
|
|
126
|
+
return output;
|
|
127
|
+
};
|
|
272
128
|
|
|
273
|
-
|
|
274
|
-
|
|
129
|
+
const httpSigningMiddlewareOptions = {
|
|
130
|
+
step: "finalizeRequest",
|
|
131
|
+
tags: ["HTTP_SIGNING"],
|
|
132
|
+
name: "httpSigningMiddleware",
|
|
133
|
+
aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"],
|
|
134
|
+
override: true,
|
|
135
|
+
relation: "after",
|
|
136
|
+
toMiddleware: "retryMiddleware",
|
|
137
|
+
};
|
|
138
|
+
const getHttpSigningPlugin = (config) => ({
|
|
139
|
+
applyToStack: (clientStack) => {
|
|
140
|
+
clientStack.addRelativeTo(httpSigningMiddleware(), httpSigningMiddlewareOptions);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
275
143
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
144
|
+
const normalizeProvider = (input) => {
|
|
145
|
+
if (typeof input === "function")
|
|
146
|
+
return input;
|
|
147
|
+
const promisified = Promise.resolve(input);
|
|
148
|
+
return () => promisified;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const makePagedClientRequest = async (CommandCtor, client, input, withCommand = (_) => _, ...args) => {
|
|
152
|
+
let command = new CommandCtor(input);
|
|
153
|
+
command = withCommand(command) ?? command;
|
|
154
|
+
return await client.send(command, ...args);
|
|
155
|
+
};
|
|
156
|
+
function createPaginator(ClientCtor, CommandCtor, inputTokenName, outputTokenName, pageSizeTokenName) {
|
|
157
|
+
return async function* paginateOperation(config, input, ...additionalArguments) {
|
|
158
|
+
const _input = input;
|
|
159
|
+
let token = config.startingToken ?? _input[inputTokenName];
|
|
160
|
+
let hasNext = true;
|
|
161
|
+
let page;
|
|
162
|
+
while (hasNext) {
|
|
163
|
+
_input[inputTokenName] = token;
|
|
164
|
+
if (pageSizeTokenName) {
|
|
165
|
+
_input[pageSizeTokenName] = _input[pageSizeTokenName] ?? config.pageSize;
|
|
166
|
+
}
|
|
167
|
+
if (config.client instanceof ClientCtor) {
|
|
168
|
+
page = await makePagedClientRequest(CommandCtor, config.client, input, config.withCommand, ...additionalArguments);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
throw new Error(`Invalid client, expected instance of ${ClientCtor.name}`);
|
|
172
|
+
}
|
|
173
|
+
yield page;
|
|
174
|
+
const prevToken = token;
|
|
175
|
+
token = get(page, outputTokenName);
|
|
176
|
+
hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
281
179
|
};
|
|
282
|
-
} else if (!context.__smithy_context.features) {
|
|
283
|
-
context.__smithy_context.features = {};
|
|
284
|
-
}
|
|
285
|
-
context.__smithy_context.features[feature] = value;
|
|
286
180
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*/
|
|
296
|
-
constructor(config) {
|
|
297
|
-
this.authSchemes = /* @__PURE__ */ new Map();
|
|
298
|
-
for (const [key, value] of Object.entries(config)) {
|
|
299
|
-
if (value !== void 0) {
|
|
300
|
-
this.authSchemes.set(key, value);
|
|
301
|
-
}
|
|
181
|
+
const get = (fromObject, path) => {
|
|
182
|
+
let cursor = fromObject;
|
|
183
|
+
const pathComponents = path.split(".");
|
|
184
|
+
for (const step of pathComponents) {
|
|
185
|
+
if (!cursor || typeof cursor !== "object") {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
cursor = cursor[step];
|
|
302
189
|
}
|
|
303
|
-
|
|
304
|
-
static {
|
|
305
|
-
__name(this, "DefaultIdentityProviderConfig");
|
|
306
|
-
}
|
|
307
|
-
getIdentityProvider(schemeId) {
|
|
308
|
-
return this.authSchemes.get(schemeId);
|
|
309
|
-
}
|
|
190
|
+
return cursor;
|
|
310
191
|
};
|
|
311
192
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
__name(this, "HttpApiKeyAuthSigner");
|
|
318
|
-
}
|
|
319
|
-
async sign(httpRequest, identity, signingProperties) {
|
|
320
|
-
if (!signingProperties) {
|
|
321
|
-
throw new Error(
|
|
322
|
-
"request could not be signed with `apiKey` since the `name` and `in` signer properties are missing"
|
|
323
|
-
);
|
|
193
|
+
function setFeature(context, feature, value) {
|
|
194
|
+
if (!context.__smithy_context) {
|
|
195
|
+
context.__smithy_context = {
|
|
196
|
+
features: {},
|
|
197
|
+
};
|
|
324
198
|
}
|
|
325
|
-
if (!
|
|
326
|
-
|
|
199
|
+
else if (!context.__smithy_context.features) {
|
|
200
|
+
context.__smithy_context.features = {};
|
|
327
201
|
}
|
|
328
|
-
|
|
329
|
-
|
|
202
|
+
context.__smithy_context.features[feature] = value;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
class DefaultIdentityProviderConfig {
|
|
206
|
+
authSchemes = new Map();
|
|
207
|
+
constructor(config) {
|
|
208
|
+
for (const [key, value] of Object.entries(config)) {
|
|
209
|
+
if (value !== undefined) {
|
|
210
|
+
this.authSchemes.set(key, value);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
330
213
|
}
|
|
331
|
-
|
|
332
|
-
|
|
214
|
+
getIdentityProvider(schemeId) {
|
|
215
|
+
return this.authSchemes.get(schemeId);
|
|
333
216
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
class HttpApiKeyAuthSigner {
|
|
220
|
+
async sign(httpRequest, identity, signingProperties) {
|
|
221
|
+
if (!signingProperties) {
|
|
222
|
+
throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
|
|
223
|
+
}
|
|
224
|
+
if (!signingProperties.name) {
|
|
225
|
+
throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
|
|
226
|
+
}
|
|
227
|
+
if (!signingProperties.in) {
|
|
228
|
+
throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
|
|
229
|
+
}
|
|
230
|
+
if (!identity.apiKey) {
|
|
231
|
+
throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
|
|
232
|
+
}
|
|
233
|
+
const clonedRequest = protocolHttp.HttpRequest.clone(httpRequest);
|
|
234
|
+
if (signingProperties.in === types.HttpApiKeyAuthLocation.QUERY) {
|
|
235
|
+
clonedRequest.query[signingProperties.name] = identity.apiKey;
|
|
236
|
+
}
|
|
237
|
+
else if (signingProperties.in === types.HttpApiKeyAuthLocation.HEADER) {
|
|
238
|
+
clonedRequest.headers[signingProperties.name] = signingProperties.scheme
|
|
239
|
+
? `${signingProperties.scheme} ${identity.apiKey}`
|
|
240
|
+
: identity.apiKey;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
|
|
244
|
+
"but found: `" +
|
|
245
|
+
signingProperties.in +
|
|
246
|
+
"`");
|
|
247
|
+
}
|
|
248
|
+
return clonedRequest;
|
|
343
249
|
}
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
};
|
|
250
|
+
}
|
|
347
251
|
|
|
348
|
-
|
|
252
|
+
class HttpBearerAuthSigner {
|
|
253
|
+
async sign(httpRequest, identity, signingProperties) {
|
|
254
|
+
const clonedRequest = protocolHttp.HttpRequest.clone(httpRequest);
|
|
255
|
+
if (!identity.token) {
|
|
256
|
+
throw new Error("request could not be signed with `token` since the `token` is not defined");
|
|
257
|
+
}
|
|
258
|
+
clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
|
|
259
|
+
return clonedRequest;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
349
262
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
async sign(httpRequest, identity, signingProperties) {
|
|
355
|
-
const clonedRequest = import_protocol_http.HttpRequest.clone(httpRequest);
|
|
356
|
-
if (!identity.token) {
|
|
357
|
-
throw new Error("request could not be signed with `token` since the `token` is not defined");
|
|
263
|
+
class NoAuthSigner {
|
|
264
|
+
async sign(httpRequest, identity, signingProperties) {
|
|
265
|
+
return httpRequest;
|
|
358
266
|
}
|
|
359
|
-
|
|
360
|
-
return clonedRequest;
|
|
361
|
-
}
|
|
362
|
-
};
|
|
267
|
+
}
|
|
363
268
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
static {
|
|
367
|
-
__name(this, "NoAuthSigner");
|
|
368
|
-
}
|
|
369
|
-
async sign(httpRequest, identity, signingProperties) {
|
|
370
|
-
return httpRequest;
|
|
371
|
-
}
|
|
269
|
+
const createIsIdentityExpiredFunction = (expirationMs) => function isIdentityExpired(identity) {
|
|
270
|
+
return doesIdentityRequireRefresh(identity) && identity.expiration.getTime() - Date.now() < expirationMs;
|
|
372
271
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
var memoizeIdentityProvider = /* @__PURE__ */ __name((provider, isExpired, requiresRefresh) => {
|
|
380
|
-
if (provider === void 0) {
|
|
381
|
-
return void 0;
|
|
382
|
-
}
|
|
383
|
-
const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
|
|
384
|
-
let resolved;
|
|
385
|
-
let pending;
|
|
386
|
-
let hasResult;
|
|
387
|
-
let isConstant = false;
|
|
388
|
-
const coalesceProvider = /* @__PURE__ */ __name(async (options) => {
|
|
389
|
-
if (!pending) {
|
|
390
|
-
pending = normalizedProvider(options);
|
|
272
|
+
const EXPIRATION_MS = 300_000;
|
|
273
|
+
const isIdentityExpired = createIsIdentityExpiredFunction(EXPIRATION_MS);
|
|
274
|
+
const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
|
|
275
|
+
const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
|
|
276
|
+
if (provider === undefined) {
|
|
277
|
+
return undefined;
|
|
391
278
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
279
|
+
const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
|
|
280
|
+
let resolved;
|
|
281
|
+
let pending;
|
|
282
|
+
let hasResult;
|
|
283
|
+
let isConstant = false;
|
|
284
|
+
const coalesceProvider = async (options) => {
|
|
285
|
+
if (!pending) {
|
|
286
|
+
pending = normalizedProvider(options);
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
resolved = await pending;
|
|
290
|
+
hasResult = true;
|
|
291
|
+
isConstant = false;
|
|
292
|
+
}
|
|
293
|
+
finally {
|
|
294
|
+
pending = undefined;
|
|
295
|
+
}
|
|
296
|
+
return resolved;
|
|
297
|
+
};
|
|
298
|
+
if (isExpired === undefined) {
|
|
299
|
+
return async (options) => {
|
|
300
|
+
if (!hasResult || options?.forceRefresh) {
|
|
301
|
+
resolved = await coalesceProvider(options);
|
|
302
|
+
}
|
|
303
|
+
return resolved;
|
|
304
|
+
};
|
|
398
305
|
}
|
|
399
|
-
return resolved;
|
|
400
|
-
}, "coalesceProvider");
|
|
401
|
-
if (isExpired === void 0) {
|
|
402
306
|
return async (options) => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
307
|
+
if (!hasResult || options?.forceRefresh) {
|
|
308
|
+
resolved = await coalesceProvider(options);
|
|
309
|
+
}
|
|
310
|
+
if (isConstant) {
|
|
311
|
+
return resolved;
|
|
312
|
+
}
|
|
313
|
+
if (!requiresRefresh(resolved)) {
|
|
314
|
+
isConstant = true;
|
|
315
|
+
return resolved;
|
|
316
|
+
}
|
|
317
|
+
if (isExpired(resolved)) {
|
|
318
|
+
await coalesceProvider(options);
|
|
319
|
+
return resolved;
|
|
320
|
+
}
|
|
321
|
+
return resolved;
|
|
407
322
|
};
|
|
408
|
-
|
|
409
|
-
return async (options) => {
|
|
410
|
-
if (!hasResult || options?.forceRefresh) {
|
|
411
|
-
resolved = await coalesceProvider(options);
|
|
412
|
-
}
|
|
413
|
-
if (isConstant) {
|
|
414
|
-
return resolved;
|
|
415
|
-
}
|
|
416
|
-
if (!requiresRefresh(resolved)) {
|
|
417
|
-
isConstant = true;
|
|
418
|
-
return resolved;
|
|
419
|
-
}
|
|
420
|
-
if (isExpired(resolved)) {
|
|
421
|
-
await coalesceProvider(options);
|
|
422
|
-
return resolved;
|
|
423
|
-
}
|
|
424
|
-
return resolved;
|
|
425
|
-
};
|
|
426
|
-
}, "memoizeIdentityProvider");
|
|
427
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
323
|
+
};
|
|
428
324
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
httpAuthSchemeMiddleware,
|
|
433
|
-
httpAuthSchemeEndpointRuleSetMiddlewareOptions,
|
|
434
|
-
getHttpAuthSchemeEndpointRuleSetPlugin,
|
|
435
|
-
httpAuthSchemeMiddlewareOptions,
|
|
436
|
-
getHttpAuthSchemePlugin,
|
|
437
|
-
httpSigningMiddleware,
|
|
438
|
-
httpSigningMiddlewareOptions,
|
|
439
|
-
getHttpSigningPlugin,
|
|
440
|
-
normalizeProvider,
|
|
441
|
-
requestBuilder,
|
|
442
|
-
setFeature,
|
|
443
|
-
DefaultIdentityProviderConfig,
|
|
444
|
-
HttpApiKeyAuthSigner,
|
|
445
|
-
HttpBearerAuthSigner,
|
|
446
|
-
NoAuthSigner,
|
|
447
|
-
createIsIdentityExpiredFunction,
|
|
448
|
-
EXPIRATION_MS,
|
|
449
|
-
isIdentityExpired,
|
|
450
|
-
doesIdentityRequireRefresh,
|
|
451
|
-
memoizeIdentityProvider
|
|
325
|
+
Object.defineProperty(exports, "requestBuilder", {
|
|
326
|
+
enumerable: true,
|
|
327
|
+
get: function () { return protocols.requestBuilder; }
|
|
452
328
|
});
|
|
453
|
-
|
|
329
|
+
exports.DefaultIdentityProviderConfig = DefaultIdentityProviderConfig;
|
|
330
|
+
exports.EXPIRATION_MS = EXPIRATION_MS;
|
|
331
|
+
exports.HttpApiKeyAuthSigner = HttpApiKeyAuthSigner;
|
|
332
|
+
exports.HttpBearerAuthSigner = HttpBearerAuthSigner;
|
|
333
|
+
exports.NoAuthSigner = NoAuthSigner;
|
|
334
|
+
exports.createIsIdentityExpiredFunction = createIsIdentityExpiredFunction;
|
|
335
|
+
exports.createPaginator = createPaginator;
|
|
336
|
+
exports.doesIdentityRequireRefresh = doesIdentityRequireRefresh;
|
|
337
|
+
exports.getHttpAuthSchemeEndpointRuleSetPlugin = getHttpAuthSchemeEndpointRuleSetPlugin;
|
|
338
|
+
exports.getHttpAuthSchemePlugin = getHttpAuthSchemePlugin;
|
|
339
|
+
exports.getHttpSigningPlugin = getHttpSigningPlugin;
|
|
340
|
+
exports.getSmithyContext = getSmithyContext;
|
|
341
|
+
exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions = httpAuthSchemeEndpointRuleSetMiddlewareOptions;
|
|
342
|
+
exports.httpAuthSchemeMiddleware = httpAuthSchemeMiddleware;
|
|
343
|
+
exports.httpAuthSchemeMiddlewareOptions = httpAuthSchemeMiddlewareOptions;
|
|
344
|
+
exports.httpSigningMiddleware = httpSigningMiddleware;
|
|
345
|
+
exports.httpSigningMiddlewareOptions = httpSigningMiddlewareOptions;
|
|
346
|
+
exports.isIdentityExpired = isIdentityExpired;
|
|
347
|
+
exports.memoizeIdentityProvider = memoizeIdentityProvider;
|
|
348
|
+
exports.normalizeProvider = normalizeProvider;
|
|
349
|
+
exports.setFeature = setFeature;
|