@smithy/core 1.2.2 → 1.3.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.
@@ -1,6 +1 @@
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;
1
+ module.exports = require("./index.js");
package/dist-cjs/index.js CHANGED
@@ -1,12 +1,480 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPaginator = void 0;
4
- const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./middleware-http-auth-scheme"), exports);
6
- tslib_1.__exportStar(require("./middleware-http-signing"), exports);
7
- tslib_1.__exportStar(require("./util-identity-and-auth"), exports);
8
- tslib_1.__exportStar(require("./getSmithyContext"), exports);
9
- tslib_1.__exportStar(require("./normalizeProvider"), exports);
10
- tslib_1.__exportStar(require("./protocols/requestBuilder"), exports);
11
- var createPaginator_1 = require("./pagination/createPaginator");
12
- Object.defineProperty(exports, "createPaginator", { enumerable: true, get: function () { return createPaginator_1.createPaginator; } });
1
+ var __defProp = Object.defineProperty;
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 src_exports = {};
22
+ __export(src_exports, {
23
+ DefaultIdentityProviderConfig: () => DefaultIdentityProviderConfig,
24
+ EXPIRATION_MS: () => EXPIRATION_MS,
25
+ HttpApiKeyAuthSigner: () => HttpApiKeyAuthSigner,
26
+ HttpBearerAuthSigner: () => HttpBearerAuthSigner,
27
+ NoAuthSigner: () => NoAuthSigner,
28
+ RequestBuilder: () => RequestBuilder,
29
+ createIsIdentityExpiredFunction: () => createIsIdentityExpiredFunction,
30
+ createPaginator: () => createPaginator,
31
+ doesIdentityRequireRefresh: () => doesIdentityRequireRefresh,
32
+ getHttpAuthSchemeEndpointRuleSetPlugin: () => getHttpAuthSchemeEndpointRuleSetPlugin,
33
+ getHttpAuthSchemePlugin: () => getHttpAuthSchemePlugin,
34
+ getHttpSigningPlugin: () => getHttpSigningPlugin,
35
+ getSmithyContext: () => getSmithyContext3,
36
+ httpAuthSchemeEndpointRuleSetMiddlewareOptions: () => httpAuthSchemeEndpointRuleSetMiddlewareOptions,
37
+ httpAuthSchemeMiddleware: () => httpAuthSchemeMiddleware,
38
+ httpAuthSchemeMiddlewareOptions: () => httpAuthSchemeMiddlewareOptions,
39
+ httpSigningMiddleware: () => httpSigningMiddleware,
40
+ httpSigningMiddlewareOptions: () => httpSigningMiddlewareOptions,
41
+ isIdentityExpired: () => isIdentityExpired,
42
+ memoizeIdentityProvider: () => memoizeIdentityProvider,
43
+ normalizeProvider: () => normalizeProvider,
44
+ requestBuilder: () => requestBuilder
45
+ });
46
+ module.exports = __toCommonJS(src_exports);
47
+
48
+ // src/middleware-http-auth-scheme/httpAuthSchemeMiddleware.ts
49
+ var import_util_middleware = require("@smithy/util-middleware");
50
+ function convertHttpAuthSchemesToMap(httpAuthSchemes) {
51
+ const map = /* @__PURE__ */ new Map();
52
+ for (const scheme of httpAuthSchemes) {
53
+ map.set(scheme.schemeId, scheme);
54
+ }
55
+ return map;
56
+ }
57
+ __name(convertHttpAuthSchemesToMap, "convertHttpAuthSchemesToMap");
58
+ var httpAuthSchemeMiddleware = /* @__PURE__ */ __name((config, mwOptions) => (next, context) => async (args) => {
59
+ var _a;
60
+ const options = config.httpAuthSchemeProvider(
61
+ await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input)
62
+ );
63
+ const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
64
+ const smithyContext = (0, import_util_middleware.getSmithyContext)(context);
65
+ const failureReasons = [];
66
+ for (const option of options) {
67
+ const scheme = authSchemes.get(option.schemeId);
68
+ if (!scheme) {
69
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`);
70
+ continue;
71
+ }
72
+ const identityProvider = scheme.identityProvider(await mwOptions.identityProviderConfigProvider(config));
73
+ if (!identityProvider) {
74
+ failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
75
+ continue;
76
+ }
77
+ const { identityProperties = {}, signingProperties = {} } = ((_a = option.propertiesExtractor) == null ? void 0 : _a.call(option, config, context)) || {};
78
+ option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties);
79
+ option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties);
80
+ smithyContext.selectedHttpAuthScheme = {
81
+ httpAuthOption: option,
82
+ identity: await identityProvider(option.identityProperties),
83
+ signer: scheme.signer
84
+ };
85
+ break;
86
+ }
87
+ if (!smithyContext.selectedHttpAuthScheme) {
88
+ throw new Error(failureReasons.join("\n"));
89
+ }
90
+ return next(args);
91
+ }, "httpAuthSchemeMiddleware");
92
+
93
+ // src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts
94
+ var import_middleware_endpoint = require("@smithy/middleware-endpoint");
95
+ var httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
96
+ step: "serialize",
97
+ tags: ["HTTP_AUTH_SCHEME"],
98
+ name: "httpAuthSchemeMiddleware",
99
+ override: true,
100
+ relation: "before",
101
+ toMiddleware: import_middleware_endpoint.endpointMiddlewareOptions.name
102
+ };
103
+ var getHttpAuthSchemeEndpointRuleSetPlugin = /* @__PURE__ */ __name((config, {
104
+ httpAuthSchemeParametersProvider,
105
+ identityProviderConfigProvider
106
+ }) => ({
107
+ applyToStack: (clientStack) => {
108
+ clientStack.addRelativeTo(
109
+ httpAuthSchemeMiddleware(config, {
110
+ httpAuthSchemeParametersProvider,
111
+ identityProviderConfigProvider
112
+ }),
113
+ httpAuthSchemeEndpointRuleSetMiddlewareOptions
114
+ );
115
+ }
116
+ }), "getHttpAuthSchemeEndpointRuleSetPlugin");
117
+
118
+ // src/middleware-http-auth-scheme/getHttpAuthSchemePlugin.ts
119
+ var import_middleware_serde = require("@smithy/middleware-serde");
120
+ var httpAuthSchemeMiddlewareOptions = {
121
+ step: "serialize",
122
+ tags: ["HTTP_AUTH_SCHEME"],
123
+ name: "httpAuthSchemeMiddleware",
124
+ override: true,
125
+ relation: "before",
126
+ toMiddleware: import_middleware_serde.serializerMiddlewareOption.name
127
+ };
128
+ var getHttpAuthSchemePlugin = /* @__PURE__ */ __name((config, {
129
+ httpAuthSchemeParametersProvider,
130
+ identityProviderConfigProvider
131
+ }) => ({
132
+ applyToStack: (clientStack) => {
133
+ clientStack.addRelativeTo(
134
+ httpAuthSchemeMiddleware(config, {
135
+ httpAuthSchemeParametersProvider,
136
+ identityProviderConfigProvider
137
+ }),
138
+ httpAuthSchemeMiddlewareOptions
139
+ );
140
+ }
141
+ }), "getHttpAuthSchemePlugin");
142
+
143
+ // src/middleware-http-signing/httpSigningMiddleware.ts
144
+ var import_protocol_http = require("@smithy/protocol-http");
145
+
146
+ var defaultErrorHandler = /* @__PURE__ */ __name((signingProperties) => (error) => {
147
+ throw error;
148
+ }, "defaultErrorHandler");
149
+ var defaultSuccessHandler = /* @__PURE__ */ __name((httpResponse, signingProperties) => {
150
+ }, "defaultSuccessHandler");
151
+ var httpSigningMiddleware = /* @__PURE__ */ __name((config) => (next, context) => async (args) => {
152
+ if (!import_protocol_http.HttpRequest.isInstance(args.request)) {
153
+ return next(args);
154
+ }
155
+ const smithyContext = (0, import_util_middleware.getSmithyContext)(context);
156
+ const scheme = smithyContext.selectedHttpAuthScheme;
157
+ if (!scheme) {
158
+ throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
159
+ }
160
+ const {
161
+ httpAuthOption: { signingProperties = {} },
162
+ identity,
163
+ signer
164
+ } = scheme;
165
+ const output = await next({
166
+ ...args,
167
+ request: await signer.sign(args.request, identity, signingProperties)
168
+ }).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
169
+ (signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
170
+ return output;
171
+ }, "httpSigningMiddleware");
172
+
173
+ // src/middleware-http-signing/getHttpSigningMiddleware.ts
174
+ var import_middleware_retry = require("@smithy/middleware-retry");
175
+ var httpSigningMiddlewareOptions = {
176
+ step: "finalizeRequest",
177
+ tags: ["HTTP_SIGNING"],
178
+ name: "httpSigningMiddleware",
179
+ aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"],
180
+ override: true,
181
+ relation: "after",
182
+ toMiddleware: import_middleware_retry.retryMiddlewareOptions.name
183
+ };
184
+ var getHttpSigningPlugin = /* @__PURE__ */ __name((config) => ({
185
+ applyToStack: (clientStack) => {
186
+ clientStack.addRelativeTo(httpSigningMiddleware(config), httpSigningMiddlewareOptions);
187
+ }
188
+ }), "getHttpSigningPlugin");
189
+
190
+ // src/util-identity-and-auth/DefaultIdentityProviderConfig.ts
191
+ var _DefaultIdentityProviderConfig = class _DefaultIdentityProviderConfig {
192
+ /**
193
+ * Creates an IdentityProviderConfig with a record of scheme IDs to identity providers.
194
+ *
195
+ * @param config scheme IDs and identity providers to configure
196
+ */
197
+ constructor(config) {
198
+ this.authSchemes = /* @__PURE__ */ new Map();
199
+ for (const [key, value] of Object.entries(config)) {
200
+ if (value !== void 0) {
201
+ this.authSchemes.set(key, value);
202
+ }
203
+ }
204
+ }
205
+ getIdentityProvider(schemeId) {
206
+ return this.authSchemes.get(schemeId);
207
+ }
208
+ };
209
+ __name(_DefaultIdentityProviderConfig, "DefaultIdentityProviderConfig");
210
+ var DefaultIdentityProviderConfig = _DefaultIdentityProviderConfig;
211
+
212
+ // src/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.ts
213
+ var import_types = require("@smithy/types");
214
+ var _HttpApiKeyAuthSigner = class _HttpApiKeyAuthSigner {
215
+ async sign(httpRequest, identity, signingProperties) {
216
+ if (!signingProperties) {
217
+ throw new Error(
218
+ "request could not be signed with `apiKey` since the `name` and `in` signer properties are missing"
219
+ );
220
+ }
221
+ if (!signingProperties.name) {
222
+ throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
223
+ }
224
+ if (!signingProperties.in) {
225
+ throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
226
+ }
227
+ if (!identity.apiKey) {
228
+ throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
229
+ }
230
+ const clonedRequest = httpRequest.clone();
231
+ if (signingProperties.in === import_types.HttpApiKeyAuthLocation.QUERY) {
232
+ clonedRequest.query[signingProperties.name] = identity.apiKey;
233
+ } else if (signingProperties.in === import_types.HttpApiKeyAuthLocation.HEADER) {
234
+ clonedRequest.headers[signingProperties.name] = signingProperties.scheme ? `${signingProperties.scheme} ${identity.apiKey}` : identity.apiKey;
235
+ } else {
236
+ throw new Error(
237
+ "request can only be signed with `apiKey` locations `query` or `header`, but found: `" + signingProperties.in + "`"
238
+ );
239
+ }
240
+ return clonedRequest;
241
+ }
242
+ };
243
+ __name(_HttpApiKeyAuthSigner, "HttpApiKeyAuthSigner");
244
+ var HttpApiKeyAuthSigner = _HttpApiKeyAuthSigner;
245
+
246
+ // src/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.ts
247
+ var _HttpBearerAuthSigner = class _HttpBearerAuthSigner {
248
+ async sign(httpRequest, identity, signingProperties) {
249
+ const clonedRequest = httpRequest.clone();
250
+ if (!identity.token) {
251
+ throw new Error("request could not be signed with `token` since the `token` is not defined");
252
+ }
253
+ clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
254
+ return clonedRequest;
255
+ }
256
+ };
257
+ __name(_HttpBearerAuthSigner, "HttpBearerAuthSigner");
258
+ var HttpBearerAuthSigner = _HttpBearerAuthSigner;
259
+
260
+ // src/util-identity-and-auth/httpAuthSchemes/noAuth.ts
261
+ var _NoAuthSigner = class _NoAuthSigner {
262
+ async sign(httpRequest, identity, signingProperties) {
263
+ return httpRequest;
264
+ }
265
+ };
266
+ __name(_NoAuthSigner, "NoAuthSigner");
267
+ var NoAuthSigner = _NoAuthSigner;
268
+
269
+ // src/util-identity-and-auth/memoizeIdentityProvider.ts
270
+ var createIsIdentityExpiredFunction = /* @__PURE__ */ __name((expirationMs) => (identity) => doesIdentityRequireRefresh(identity) && identity.expiration.getTime() - Date.now() < expirationMs, "createIsIdentityExpiredFunction");
271
+ var EXPIRATION_MS = 3e5;
272
+ var isIdentityExpired = createIsIdentityExpiredFunction(EXPIRATION_MS);
273
+ var doesIdentityRequireRefresh = /* @__PURE__ */ __name((identity) => identity.expiration !== void 0, "doesIdentityRequireRefresh");
274
+ var memoizeIdentityProvider = /* @__PURE__ */ __name((provider, isExpired, requiresRefresh) => {
275
+ if (provider === void 0) {
276
+ return void 0;
277
+ }
278
+ const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
279
+ let resolved;
280
+ let pending;
281
+ let hasResult;
282
+ let isConstant = false;
283
+ const coalesceProvider = /* @__PURE__ */ __name(async (options) => {
284
+ if (!pending) {
285
+ pending = normalizedProvider(options);
286
+ }
287
+ try {
288
+ resolved = await pending;
289
+ hasResult = true;
290
+ isConstant = false;
291
+ } finally {
292
+ pending = void 0;
293
+ }
294
+ return resolved;
295
+ }, "coalesceProvider");
296
+ if (isExpired === void 0) {
297
+ return async (options) => {
298
+ if (!hasResult || (options == null ? void 0 : options.forceRefresh)) {
299
+ resolved = await coalesceProvider(options);
300
+ }
301
+ return resolved;
302
+ };
303
+ }
304
+ return async (options) => {
305
+ if (!hasResult || (options == null ? void 0 : options.forceRefresh)) {
306
+ resolved = await coalesceProvider(options);
307
+ }
308
+ if (isConstant) {
309
+ return resolved;
310
+ }
311
+ if (!requiresRefresh(resolved)) {
312
+ isConstant = true;
313
+ return resolved;
314
+ }
315
+ if (isExpired(resolved)) {
316
+ await coalesceProvider(options);
317
+ return resolved;
318
+ }
319
+ return resolved;
320
+ };
321
+ }, "memoizeIdentityProvider");
322
+
323
+ // src/getSmithyContext.ts
324
+
325
+ var getSmithyContext3 = /* @__PURE__ */ __name((context) => context[import_types.SMITHY_CONTEXT_KEY] || (context[import_types.SMITHY_CONTEXT_KEY] = {}), "getSmithyContext");
326
+
327
+ // src/normalizeProvider.ts
328
+ var normalizeProvider = /* @__PURE__ */ __name((input) => {
329
+ if (typeof input === "function")
330
+ return input;
331
+ const promisified = Promise.resolve(input);
332
+ return () => promisified;
333
+ }, "normalizeProvider");
334
+
335
+ // src/protocols/requestBuilder.ts
336
+
337
+ var import_smithy_client = require("@smithy/smithy-client");
338
+ function requestBuilder(input, context) {
339
+ return new RequestBuilder(input, context);
340
+ }
341
+ __name(requestBuilder, "requestBuilder");
342
+ var _RequestBuilder = class _RequestBuilder {
343
+ constructor(input, context) {
344
+ this.input = input;
345
+ this.context = context;
346
+ this.query = {};
347
+ this.method = "";
348
+ this.headers = {};
349
+ this.path = "";
350
+ this.body = null;
351
+ this.hostname = "";
352
+ this.resolvePathStack = [];
353
+ }
354
+ async build() {
355
+ const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint();
356
+ this.path = basePath;
357
+ for (const resolvePath of this.resolvePathStack) {
358
+ resolvePath(this.path);
359
+ }
360
+ return new import_protocol_http.HttpRequest({
361
+ protocol,
362
+ hostname: this.hostname || hostname,
363
+ port,
364
+ method: this.method,
365
+ path: this.path,
366
+ query: this.query,
367
+ body: this.body,
368
+ headers: this.headers
369
+ });
370
+ }
371
+ /**
372
+ * Brevity setter for "hostname".
373
+ */
374
+ hn(hostname) {
375
+ this.hostname = hostname;
376
+ return this;
377
+ }
378
+ /**
379
+ * Brevity initial builder for "basepath".
380
+ */
381
+ bp(uriLabel) {
382
+ this.resolvePathStack.push((basePath) => {
383
+ this.path = `${(basePath == null ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + uriLabel;
384
+ });
385
+ return this;
386
+ }
387
+ /**
388
+ * Brevity incremental builder for "path".
389
+ */
390
+ p(memberName, labelValueProvider, uriLabel, isGreedyLabel) {
391
+ this.resolvePathStack.push((path) => {
392
+ this.path = (0, import_smithy_client.resolvedPath)(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
393
+ });
394
+ return this;
395
+ }
396
+ /**
397
+ * Brevity setter for "headers".
398
+ */
399
+ h(headers) {
400
+ this.headers = headers;
401
+ return this;
402
+ }
403
+ /**
404
+ * Brevity setter for "query".
405
+ */
406
+ q(query) {
407
+ this.query = query;
408
+ return this;
409
+ }
410
+ /**
411
+ * Brevity setter for "body".
412
+ */
413
+ b(body) {
414
+ this.body = body;
415
+ return this;
416
+ }
417
+ /**
418
+ * Brevity setter for "method".
419
+ */
420
+ m(method) {
421
+ this.method = method;
422
+ return this;
423
+ }
424
+ };
425
+ __name(_RequestBuilder, "RequestBuilder");
426
+ var RequestBuilder = _RequestBuilder;
427
+
428
+ // src/pagination/createPaginator.ts
429
+ var makePagedClientRequest = /* @__PURE__ */ __name(async (CommandCtor, client, input, ...args) => {
430
+ return await client.send(new CommandCtor(input), ...args);
431
+ }, "makePagedClientRequest");
432
+ function createPaginator(ClientCtor, CommandCtor, inputTokenName, outputTokenName, pageSizeTokenName) {
433
+ return /* @__PURE__ */ __name(async function* paginateOperation(config, input, ...additionalArguments) {
434
+ let token = config.startingToken || void 0;
435
+ let hasNext = true;
436
+ let page;
437
+ while (hasNext) {
438
+ input[inputTokenName] = token;
439
+ if (pageSizeTokenName) {
440
+ input[pageSizeTokenName] = input[pageSizeTokenName] ?? config.pageSize;
441
+ }
442
+ if (config.client instanceof ClientCtor) {
443
+ page = await makePagedClientRequest(CommandCtor, config.client, input, ...additionalArguments);
444
+ } else {
445
+ throw new Error(`Invalid client, expected instance of ${ClientCtor.name}`);
446
+ }
447
+ yield page;
448
+ const prevToken = token;
449
+ token = page[outputTokenName];
450
+ hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
451
+ }
452
+ return void 0;
453
+ }, "paginateOperation");
454
+ }
455
+ __name(createPaginator, "createPaginator");
456
+ // Annotate the CommonJS export names for ESM import in node:
457
+ 0 && (module.exports = {
458
+ DefaultIdentityProviderConfig,
459
+ EXPIRATION_MS,
460
+ HttpApiKeyAuthSigner,
461
+ HttpBearerAuthSigner,
462
+ NoAuthSigner,
463
+ RequestBuilder,
464
+ createIsIdentityExpiredFunction,
465
+ createPaginator,
466
+ doesIdentityRequireRefresh,
467
+ getHttpAuthSchemeEndpointRuleSetPlugin,
468
+ getHttpAuthSchemePlugin,
469
+ getHttpSigningPlugin,
470
+ getSmithyContext,
471
+ httpAuthSchemeEndpointRuleSetMiddlewareOptions,
472
+ httpAuthSchemeMiddleware,
473
+ httpAuthSchemeMiddlewareOptions,
474
+ httpSigningMiddleware,
475
+ httpSigningMiddlewareOptions,
476
+ isIdentityExpired,
477
+ memoizeIdentityProvider,
478
+ normalizeProvider,
479
+ requestBuilder
480
+ });
@@ -1,22 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHttpAuthSchemeEndpointRuleSetPlugin = exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions = void 0;
4
- const middleware_endpoint_1 = require("@smithy/middleware-endpoint");
5
- const httpAuthSchemeMiddleware_1 = require("./httpAuthSchemeMiddleware");
6
- exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
7
- step: "serialize",
8
- tags: ["HTTP_AUTH_SCHEME"],
9
- name: "httpAuthSchemeMiddleware",
10
- override: true,
11
- relation: "before",
12
- toMiddleware: middleware_endpoint_1.endpointMiddlewareOptions.name,
13
- };
14
- const getHttpAuthSchemeEndpointRuleSetPlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
15
- applyToStack: (clientStack) => {
16
- clientStack.addRelativeTo((0, httpAuthSchemeMiddleware_1.httpAuthSchemeMiddleware)(config, {
17
- httpAuthSchemeParametersProvider,
18
- identityProviderConfigProvider,
19
- }), exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions);
20
- },
21
- });
22
- exports.getHttpAuthSchemeEndpointRuleSetPlugin = getHttpAuthSchemeEndpointRuleSetPlugin;
1
+ module.exports = require("../index.js");
@@ -1,22 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHttpAuthSchemePlugin = exports.httpAuthSchemeMiddlewareOptions = void 0;
4
- const middleware_serde_1 = require("@smithy/middleware-serde");
5
- const httpAuthSchemeMiddleware_1 = require("./httpAuthSchemeMiddleware");
6
- exports.httpAuthSchemeMiddlewareOptions = {
7
- step: "serialize",
8
- tags: ["HTTP_AUTH_SCHEME"],
9
- name: "httpAuthSchemeMiddleware",
10
- override: true,
11
- relation: "before",
12
- toMiddleware: middleware_serde_1.serializerMiddlewareOption.name,
13
- };
14
- const getHttpAuthSchemePlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
15
- applyToStack: (clientStack) => {
16
- clientStack.addRelativeTo((0, httpAuthSchemeMiddleware_1.httpAuthSchemeMiddleware)(config, {
17
- httpAuthSchemeParametersProvider,
18
- identityProviderConfigProvider,
19
- }), exports.httpAuthSchemeMiddlewareOptions);
20
- },
21
- });
22
- exports.getHttpAuthSchemePlugin = getHttpAuthSchemePlugin;
1
+ module.exports = require("../index.js");
@@ -1,45 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.httpAuthSchemeMiddleware = void 0;
4
- const types_1 = require("@smithy/types");
5
- const util_middleware_1 = require("@smithy/util-middleware");
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
- var _a;
15
- const options = config.httpAuthSchemeProvider(await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input));
16
- const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
17
- const smithyContext = (0, util_middleware_1.getSmithyContext)(context);
18
- const failureReasons = [];
19
- for (const option of options) {
20
- const scheme = authSchemes.get(option.schemeId);
21
- if (!scheme) {
22
- failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`);
23
- continue;
24
- }
25
- const identityProvider = scheme.identityProvider(await mwOptions.identityProviderConfigProvider(config));
26
- if (!identityProvider) {
27
- failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
28
- continue;
29
- }
30
- const { identityProperties = {}, signingProperties = {} } = ((_a = option.propertiesExtractor) === null || _a === void 0 ? void 0 : _a.call(option, config, context)) || {};
31
- option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties);
32
- option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties);
33
- smithyContext.selectedHttpAuthScheme = {
34
- httpAuthOption: option,
35
- identity: await identityProvider(option.identityProperties),
36
- signer: scheme.signer,
37
- };
38
- break;
39
- }
40
- if (!smithyContext.selectedHttpAuthScheme) {
41
- throw new Error(failureReasons.join("\n"));
42
- }
43
- return next(args);
44
- };
45
- exports.httpAuthSchemeMiddleware = httpAuthSchemeMiddleware;
1
+ module.exports = require("../index.js");
@@ -1,6 +1 @@
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);
1
+ module.exports = require("../index.js");
@@ -1,20 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHttpSigningPlugin = exports.httpSigningMiddlewareOptions = void 0;
4
- const middleware_retry_1 = require("@smithy/middleware-retry");
5
- const httpSigningMiddleware_1 = require("./httpSigningMiddleware");
6
- exports.httpSigningMiddlewareOptions = {
7
- step: "finalizeRequest",
8
- tags: ["HTTP_SIGNING"],
9
- name: "httpSigningMiddleware",
10
- aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"],
11
- override: true,
12
- relation: "after",
13
- toMiddleware: middleware_retry_1.retryMiddlewareOptions.name,
14
- };
15
- const getHttpSigningPlugin = (config) => ({
16
- applyToStack: (clientStack) => {
17
- clientStack.addRelativeTo((0, httpSigningMiddleware_1.httpSigningMiddleware)(config), exports.httpSigningMiddlewareOptions);
18
- },
19
- });
20
- exports.getHttpSigningPlugin = getHttpSigningPlugin;
1
+ module.exports = require("../index.js");
@@ -1,28 +1 @@
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 types_1 = require("@smithy/types");
6
- const util_middleware_1 = require("@smithy/util-middleware");
7
- const defaultErrorHandler = (signingProperties) => (error) => {
8
- throw error;
9
- };
10
- const defaultSuccessHandler = (httpResponse, signingProperties) => { };
11
- const httpSigningMiddleware = (config) => (next, context) => async (args) => {
12
- if (!protocol_http_1.HttpRequest.isInstance(args.request)) {
13
- return next(args);
14
- }
15
- const smithyContext = (0, util_middleware_1.getSmithyContext)(context);
16
- const scheme = smithyContext.selectedHttpAuthScheme;
17
- if (!scheme) {
18
- throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
19
- }
20
- const { httpAuthOption: { signingProperties = {} }, identity, signer, } = scheme;
21
- const output = await next({
22
- ...args,
23
- request: await signer.sign(args.request, identity, signingProperties),
24
- }).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
25
- (signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
26
- return output;
27
- };
28
- exports.httpSigningMiddleware = httpSigningMiddleware;
1
+ module.exports = require("../index.js");
@@ -1,5 +1 @@
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);
1
+ module.exports = require("../index.js");
@@ -1,10 +1 @@
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;
1
+ module.exports = require("./index.js");
@@ -1,32 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPaginator = void 0;
4
- const makePagedClientRequest = async (CommandCtor, client, input, ...args) => {
5
- return await client.send(new CommandCtor(input), ...args);
6
- };
7
- function createPaginator(ClientCtor, CommandCtor, inputTokenName, outputTokenName, pageSizeTokenName) {
8
- return async function* paginateOperation(config, input, ...additionalArguments) {
9
- var _a;
10
- let token = config.startingToken || undefined;
11
- let hasNext = true;
12
- let page;
13
- while (hasNext) {
14
- input[inputTokenName] = token;
15
- if (pageSizeTokenName) {
16
- input[pageSizeTokenName] = (_a = input[pageSizeTokenName]) !== null && _a !== void 0 ? _a : config.pageSize;
17
- }
18
- if (config.client instanceof ClientCtor) {
19
- page = await makePagedClientRequest(CommandCtor, config.client, input, ...additionalArguments);
20
- }
21
- else {
22
- throw new Error(`Invalid client, expected instance of ${ClientCtor.name}`);
23
- }
24
- yield page;
25
- const prevToken = token;
26
- token = page[outputTokenName];
27
- hasNext = !!(token && (!config.stopOnSameToken || token !== prevToken));
28
- }
29
- return undefined;
30
- };
31
- }
32
- exports.createPaginator = createPaginator;
1
+ module.exports = require("../index.js");
@@ -1,72 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RequestBuilder = exports.requestBuilder = void 0;
4
- const protocol_http_1 = require("@smithy/protocol-http");
5
- const smithy_client_1 = require("@smithy/smithy-client");
6
- function requestBuilder(input, context) {
7
- return new RequestBuilder(input, context);
8
- }
9
- exports.requestBuilder = requestBuilder;
10
- class RequestBuilder {
11
- constructor(input, context) {
12
- this.input = input;
13
- this.context = context;
14
- this.query = {};
15
- this.method = "";
16
- this.headers = {};
17
- this.path = "";
18
- this.body = null;
19
- this.hostname = "";
20
- this.resolvePathStack = [];
21
- }
22
- async build() {
23
- const { hostname, protocol = "https", port, path: basePath } = await this.context.endpoint();
24
- this.path = basePath;
25
- for (const resolvePath of this.resolvePathStack) {
26
- resolvePath(this.path);
27
- }
28
- return new protocol_http_1.HttpRequest({
29
- protocol,
30
- hostname: this.hostname || hostname,
31
- port,
32
- method: this.method,
33
- path: this.path,
34
- query: this.query,
35
- body: this.body,
36
- headers: this.headers,
37
- });
38
- }
39
- hn(hostname) {
40
- this.hostname = hostname;
41
- return this;
42
- }
43
- bp(uriLabel) {
44
- this.resolvePathStack.push((basePath) => {
45
- this.path = `${(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith("/")) ? basePath.slice(0, -1) : basePath || ""}` + uriLabel;
46
- });
47
- return this;
48
- }
49
- p(memberName, labelValueProvider, uriLabel, isGreedyLabel) {
50
- this.resolvePathStack.push((path) => {
51
- this.path = (0, smithy_client_1.resolvedPath)(path, this.input, memberName, labelValueProvider, uriLabel, isGreedyLabel);
52
- });
53
- return this;
54
- }
55
- h(headers) {
56
- this.headers = headers;
57
- return this;
58
- }
59
- q(query) {
60
- this.query = query;
61
- return this;
62
- }
63
- b(body) {
64
- this.body = body;
65
- return this;
66
- }
67
- m(method) {
68
- this.method = method;
69
- return this;
70
- }
71
- }
72
- exports.RequestBuilder = RequestBuilder;
1
+ module.exports = require("../index.js");
@@ -1,17 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultIdentityProviderConfig = void 0;
4
- class DefaultIdentityProviderConfig {
5
- constructor(config) {
6
- this.authSchemes = new Map();
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;
1
+ module.exports = require("../index.js");
@@ -1,37 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpApiKeyAuthSigner = void 0;
4
- const types_1 = require("@smithy/types");
5
- class HttpApiKeyAuthSigner {
6
- async sign(httpRequest, identity, signingProperties) {
7
- if (!signingProperties) {
8
- throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
9
- }
10
- if (!signingProperties.name) {
11
- throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
12
- }
13
- if (!signingProperties.in) {
14
- throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
15
- }
16
- if (!identity.apiKey) {
17
- throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
18
- }
19
- const clonedRequest = httpRequest.clone();
20
- if (signingProperties.in === types_1.HttpApiKeyAuthLocation.QUERY) {
21
- clonedRequest.query[signingProperties.name] = identity.apiKey;
22
- }
23
- else if (signingProperties.in === types_1.HttpApiKeyAuthLocation.HEADER) {
24
- clonedRequest.headers[signingProperties.name] = signingProperties.scheme
25
- ? `${signingProperties.scheme} ${identity.apiKey}`
26
- : identity.apiKey;
27
- }
28
- else {
29
- throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
30
- "but found: `" +
31
- signingProperties.in +
32
- "`");
33
- }
34
- return clonedRequest;
35
- }
36
- }
37
- exports.HttpApiKeyAuthSigner = HttpApiKeyAuthSigner;
1
+ module.exports = require("../../index.js");
@@ -1,14 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpBearerAuthSigner = void 0;
4
- class HttpBearerAuthSigner {
5
- async sign(httpRequest, identity, signingProperties) {
6
- const clonedRequest = httpRequest.clone();
7
- if (!identity.token) {
8
- throw new Error("request could not be signed with `token` since the `token` is not defined");
9
- }
10
- clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
11
- return clonedRequest;
12
- }
13
- }
14
- exports.HttpBearerAuthSigner = HttpBearerAuthSigner;
1
+ module.exports = require("../../index.js");
@@ -1,6 +1 @@
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);
1
+ module.exports = require("../../index.js");
@@ -1,9 +1 @@
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;
1
+ module.exports = require("../../index.js");
@@ -1,6 +1 @@
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);
1
+ module.exports = require("../index.js");
@@ -1,59 +1 @@
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) => (identity) => (0, exports.doesIdentityRequireRefresh)(identity) && identity.expiration.getTime() - Date.now() < expirationMs;
5
- exports.createIsIdentityExpiredFunction = createIsIdentityExpiredFunction;
6
- exports.EXPIRATION_MS = 300000;
7
- exports.isIdentityExpired = (0, exports.createIsIdentityExpiredFunction)(exports.EXPIRATION_MS);
8
- const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
9
- exports.doesIdentityRequireRefresh = doesIdentityRequireRefresh;
10
- const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
11
- if (provider === undefined) {
12
- return undefined;
13
- }
14
- const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
15
- let resolved;
16
- let pending;
17
- let hasResult;
18
- let isConstant = false;
19
- const coalesceProvider = async (options) => {
20
- if (!pending) {
21
- pending = normalizedProvider(options);
22
- }
23
- try {
24
- resolved = await pending;
25
- hasResult = true;
26
- isConstant = false;
27
- }
28
- finally {
29
- pending = undefined;
30
- }
31
- return resolved;
32
- };
33
- if (isExpired === undefined) {
34
- return async (options) => {
35
- if (!hasResult || (options === null || options === void 0 ? void 0 : options.forceRefresh)) {
36
- resolved = await coalesceProvider(options);
37
- }
38
- return resolved;
39
- };
40
- }
41
- return async (options) => {
42
- if (!hasResult || (options === null || options === void 0 ? void 0 : options.forceRefresh)) {
43
- resolved = await coalesceProvider(options);
44
- }
45
- if (isConstant) {
46
- return resolved;
47
- }
48
- if (!requiresRefresh(resolved)) {
49
- isConstant = true;
50
- return resolved;
51
- }
52
- if (isExpired(resolved)) {
53
- await coalesceProvider(options);
54
- return resolved;
55
- }
56
- return resolved;
57
- };
58
- };
59
- exports.memoizeIdentityProvider = memoizeIdentityProvider;
1
+ module.exports = require("../index.js");
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
- "build:cjs": "yarn g:tsc -p tsconfig.cjs.json",
6
+ "build:cjs": "node ../../scripts/inline core",
7
7
  "build:es": "yarn g:tsc -p tsconfig.es.json",
8
8
  "build:types": "yarn g:tsc -p tsconfig.types.json",
9
9
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
@@ -23,13 +23,13 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
- "@smithy/middleware-endpoint": "^2.3.0",
27
- "@smithy/middleware-retry": "^2.0.26",
28
- "@smithy/middleware-serde": "^2.0.16",
29
- "@smithy/protocol-http": "^3.0.12",
30
- "@smithy/smithy-client": "^2.2.1",
31
- "@smithy/types": "^2.8.0",
32
- "@smithy/util-middleware": "^2.0.9",
26
+ "@smithy/middleware-endpoint": "^2.4.0",
27
+ "@smithy/middleware-retry": "^2.1.0",
28
+ "@smithy/middleware-serde": "^2.1.0",
29
+ "@smithy/protocol-http": "^3.1.0",
30
+ "@smithy/smithy-client": "^2.3.0",
31
+ "@smithy/types": "^2.9.0",
32
+ "@smithy/util-middleware": "^2.1.0",
33
33
  "tslib": "^2.5.0"
34
34
  },
35
35
  "engines": {