@smithy/core 3.2.0 → 3.3.1
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 +27 -1
- package/dist-cjs/middleware-http-auth-scheme/resolveAuthOptions.js +1 -0
- package/dist-cjs/submodules/cbor/index.js +4 -1
- package/dist-es/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +4 -1
- package/dist-es/middleware-http-auth-scheme/resolveAuthOptions.js +20 -0
- package/dist-es/submodules/cbor/parseCborBody.js +3 -1
- package/dist-types/middleware-http-auth-scheme/httpAuthSchemeMiddleware.d.ts +2 -1
- package/dist-types/middleware-http-auth-scheme/resolveAuthOptions.d.ts +10 -0
- package/dist-types/ts3.4/middleware-http-auth-scheme/httpAuthSchemeMiddleware.d.ts +2 -1
- package/dist-types/ts3.4/middleware-http-auth-scheme/resolveAuthOptions.d.ts +10 -0
- package/package.json +1 -1
package/dist-cjs/index.js
CHANGED
|
@@ -51,6 +51,30 @@ var getSmithyContext = /* @__PURE__ */ __name((context) => context[import_types.
|
|
|
51
51
|
|
|
52
52
|
// src/middleware-http-auth-scheme/httpAuthSchemeMiddleware.ts
|
|
53
53
|
var import_util_middleware = require("@smithy/util-middleware");
|
|
54
|
+
|
|
55
|
+
// src/middleware-http-auth-scheme/resolveAuthOptions.ts
|
|
56
|
+
var resolveAuthOptions = /* @__PURE__ */ __name((candidateAuthOptions, authSchemePreference) => {
|
|
57
|
+
if (!authSchemePreference || authSchemePreference.length === 0) {
|
|
58
|
+
return candidateAuthOptions;
|
|
59
|
+
}
|
|
60
|
+
const preferredAuthOptions = [];
|
|
61
|
+
for (const preferredSchemeName of authSchemePreference) {
|
|
62
|
+
for (const candidateAuthOption of candidateAuthOptions) {
|
|
63
|
+
const candidateAuthSchemeName = candidateAuthOption.schemeId.split("#")[1];
|
|
64
|
+
if (candidateAuthSchemeName === preferredSchemeName) {
|
|
65
|
+
preferredAuthOptions.push(candidateAuthOption);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const candidateAuthOption of candidateAuthOptions) {
|
|
70
|
+
if (!preferredAuthOptions.find(({ schemeId }) => schemeId === candidateAuthOption.schemeId)) {
|
|
71
|
+
preferredAuthOptions.push(candidateAuthOption);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return preferredAuthOptions;
|
|
75
|
+
}, "resolveAuthOptions");
|
|
76
|
+
|
|
77
|
+
// src/middleware-http-auth-scheme/httpAuthSchemeMiddleware.ts
|
|
54
78
|
function convertHttpAuthSchemesToMap(httpAuthSchemes) {
|
|
55
79
|
const map = /* @__PURE__ */ new Map();
|
|
56
80
|
for (const scheme of httpAuthSchemes) {
|
|
@@ -63,10 +87,12 @@ var httpAuthSchemeMiddleware = /* @__PURE__ */ __name((config, mwOptions) => (ne
|
|
|
63
87
|
const options = config.httpAuthSchemeProvider(
|
|
64
88
|
await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input)
|
|
65
89
|
);
|
|
90
|
+
const authSchemePreference = config.authSchemePreference ? await config.authSchemePreference() : [];
|
|
91
|
+
const resolvedOptions = resolveAuthOptions(options, authSchemePreference);
|
|
66
92
|
const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
|
|
67
93
|
const smithyContext = (0, import_util_middleware.getSmithyContext)(context);
|
|
68
94
|
const failureReasons = [];
|
|
69
|
-
for (const option of
|
|
95
|
+
for (const option of resolvedOptions) {
|
|
70
96
|
const scheme = authSchemes.get(option.schemeId);
|
|
71
97
|
if (!scheme) {
|
|
72
98
|
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("../index.js");
|
|
@@ -702,7 +702,10 @@ var buildHttpRpcRequest = async (context, headers, path, resolvedHostname, body)
|
|
|
702
702
|
port,
|
|
703
703
|
method: "POST",
|
|
704
704
|
path: basePath.endsWith("/") ? basePath.slice(0, -1) + path : basePath + path,
|
|
705
|
-
headers
|
|
705
|
+
headers: {
|
|
706
|
+
// intentional copy.
|
|
707
|
+
...headers
|
|
708
|
+
}
|
|
706
709
|
};
|
|
707
710
|
if (resolvedHostname !== void 0) {
|
|
708
711
|
contents.hostname = resolvedHostname;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SMITHY_CONTEXT_KEY, } from "@smithy/types";
|
|
2
2
|
import { getSmithyContext } from "@smithy/util-middleware";
|
|
3
|
+
import { resolveAuthOptions } from "./resolveAuthOptions";
|
|
3
4
|
function convertHttpAuthSchemesToMap(httpAuthSchemes) {
|
|
4
5
|
const map = new Map();
|
|
5
6
|
for (const scheme of httpAuthSchemes) {
|
|
@@ -9,10 +10,12 @@ function convertHttpAuthSchemesToMap(httpAuthSchemes) {
|
|
|
9
10
|
}
|
|
10
11
|
export const httpAuthSchemeMiddleware = (config, mwOptions) => (next, context) => async (args) => {
|
|
11
12
|
const options = config.httpAuthSchemeProvider(await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input));
|
|
13
|
+
const authSchemePreference = config.authSchemePreference ? await config.authSchemePreference() : [];
|
|
14
|
+
const resolvedOptions = resolveAuthOptions(options, authSchemePreference);
|
|
12
15
|
const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
|
|
13
16
|
const smithyContext = getSmithyContext(context);
|
|
14
17
|
const failureReasons = [];
|
|
15
|
-
for (const option of
|
|
18
|
+
for (const option of resolvedOptions) {
|
|
16
19
|
const scheme = authSchemes.get(option.schemeId);
|
|
17
20
|
if (!scheme) {
|
|
18
21
|
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const resolveAuthOptions = (candidateAuthOptions, authSchemePreference) => {
|
|
2
|
+
if (!authSchemePreference || authSchemePreference.length === 0) {
|
|
3
|
+
return candidateAuthOptions;
|
|
4
|
+
}
|
|
5
|
+
const preferredAuthOptions = [];
|
|
6
|
+
for (const preferredSchemeName of authSchemePreference) {
|
|
7
|
+
for (const candidateAuthOption of candidateAuthOptions) {
|
|
8
|
+
const candidateAuthSchemeName = candidateAuthOption.schemeId.split("#")[1];
|
|
9
|
+
if (candidateAuthSchemeName === preferredSchemeName) {
|
|
10
|
+
preferredAuthOptions.push(candidateAuthOption);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
for (const candidateAuthOption of candidateAuthOptions) {
|
|
15
|
+
if (!preferredAuthOptions.find(({ schemeId }) => schemeId === candidateAuthOption.schemeId)) {
|
|
16
|
+
preferredAuthOptions.push(candidateAuthOption);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return preferredAuthOptions;
|
|
20
|
+
};
|
|
@@ -67,7 +67,9 @@ export const buildHttpRpcRequest = async (context, headers, path, resolvedHostna
|
|
|
67
67
|
port,
|
|
68
68
|
method: "POST",
|
|
69
69
|
path: basePath.endsWith("/") ? basePath.slice(0, -1) + path : basePath + path,
|
|
70
|
-
headers
|
|
70
|
+
headers: {
|
|
71
|
+
...headers,
|
|
72
|
+
},
|
|
71
73
|
};
|
|
72
74
|
if (resolvedHostname !== undefined) {
|
|
73
75
|
contents.hostname = resolvedHostname;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { HandlerExecutionContext, HttpAuthScheme, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider, IdentityProviderConfig, SelectedHttpAuthScheme, SerializeMiddleware, SMITHY_CONTEXT_KEY } from "@smithy/types";
|
|
1
|
+
import { HandlerExecutionContext, HttpAuthScheme, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider, IdentityProviderConfig, Provider, SelectedHttpAuthScheme, SerializeMiddleware, SMITHY_CONTEXT_KEY } from "@smithy/types";
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
5
|
export interface PreviouslyResolved<TParameters extends HttpAuthSchemeParameters> {
|
|
6
|
+
authSchemePreference?: Provider<string[]>;
|
|
6
7
|
httpAuthSchemes: HttpAuthScheme[];
|
|
7
8
|
httpAuthSchemeProvider: HttpAuthSchemeProvider<TParameters>;
|
|
8
9
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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,8 +1,9 @@
|
|
|
1
|
-
import { HandlerExecutionContext, HttpAuthScheme, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider, IdentityProviderConfig, SelectedHttpAuthScheme, SerializeMiddleware, SMITHY_CONTEXT_KEY } from "@smithy/types";
|
|
1
|
+
import { HandlerExecutionContext, HttpAuthScheme, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider, IdentityProviderConfig, Provider, SelectedHttpAuthScheme, SerializeMiddleware, SMITHY_CONTEXT_KEY } from "@smithy/types";
|
|
2
2
|
/**
|
|
3
3
|
* @internal
|
|
4
4
|
*/
|
|
5
5
|
export interface PreviouslyResolved<TParameters extends HttpAuthSchemeParameters> {
|
|
6
|
+
authSchemePreference?: Provider<string[]>;
|
|
6
7
|
httpAuthSchemes: HttpAuthScheme[];
|
|
7
8
|
httpAuthSchemeProvider: HttpAuthSchemeProvider<TParameters>;
|
|
8
9
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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[];
|
package/package.json
CHANGED