@smithy/core 1.0.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.
Files changed (63) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +12 -0
  3. package/dist-cjs/index.js +6 -0
  4. package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.js +22 -0
  5. package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemePlugin.js +22 -0
  6. package/dist-cjs/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +45 -0
  7. package/dist-cjs/middleware-http-auth-scheme/index.js +6 -0
  8. package/dist-cjs/middleware-http-signing/getHttpSigningMiddleware.js +20 -0
  9. package/dist-cjs/middleware-http-signing/httpSigningMiddleware.js +22 -0
  10. package/dist-cjs/middleware-http-signing/index.js +5 -0
  11. package/dist-cjs/util-identity-and-auth/DefaultIdentityProviderConfig.js +17 -0
  12. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js +37 -0
  13. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js +14 -0
  14. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/index.js +6 -0
  15. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/noAuth.js +9 -0
  16. package/dist-cjs/util-identity-and-auth/index.js +6 -0
  17. package/dist-cjs/util-identity-and-auth/memoizeIdentityProvider.js +59 -0
  18. package/dist-es/index.js +3 -0
  19. package/dist-es/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.js +18 -0
  20. package/dist-es/middleware-http-auth-scheme/getHttpAuthSchemePlugin.js +18 -0
  21. package/dist-es/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +40 -0
  22. package/dist-es/middleware-http-auth-scheme/index.js +3 -0
  23. package/dist-es/middleware-http-signing/getHttpSigningMiddleware.js +16 -0
  24. package/dist-es/middleware-http-signing/httpSigningMiddleware.js +18 -0
  25. package/dist-es/middleware-http-signing/index.js +2 -0
  26. package/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +13 -0
  27. package/dist-es/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js +33 -0
  28. package/dist-es/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js +10 -0
  29. package/dist-es/util-identity-and-auth/httpAuthSchemes/index.js +3 -0
  30. package/dist-es/util-identity-and-auth/httpAuthSchemes/noAuth.js +5 -0
  31. package/dist-es/util-identity-and-auth/index.js +3 -0
  32. package/dist-es/util-identity-and-auth/memoizeIdentityProvider.js +53 -0
  33. package/dist-types/index.d.ts +3 -0
  34. package/dist-types/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.d.ts +18 -0
  35. package/dist-types/middleware-http-auth-scheme/getHttpAuthSchemePlugin.d.ts +18 -0
  36. package/dist-types/middleware-http-auth-scheme/httpAuthSchemeMiddleware.d.ts +32 -0
  37. package/dist-types/middleware-http-auth-scheme/index.d.ts +3 -0
  38. package/dist-types/middleware-http-signing/getHttpSigningMiddleware.d.ts +9 -0
  39. package/dist-types/middleware-http-signing/httpSigningMiddleware.d.ts +5 -0
  40. package/dist-types/middleware-http-signing/index.d.ts +2 -0
  41. package/dist-types/ts3.4/index.d.ts +3 -0
  42. package/dist-types/ts3.4/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.d.ts +18 -0
  43. package/dist-types/ts3.4/middleware-http-auth-scheme/getHttpAuthSchemePlugin.d.ts +18 -0
  44. package/dist-types/ts3.4/middleware-http-auth-scheme/httpAuthSchemeMiddleware.d.ts +32 -0
  45. package/dist-types/ts3.4/middleware-http-auth-scheme/index.d.ts +3 -0
  46. package/dist-types/ts3.4/middleware-http-signing/getHttpSigningMiddleware.d.ts +9 -0
  47. package/dist-types/ts3.4/middleware-http-signing/httpSigningMiddleware.d.ts +5 -0
  48. package/dist-types/ts3.4/middleware-http-signing/index.d.ts +2 -0
  49. package/dist-types/ts3.4/util-identity-and-auth/DefaultIdentityProviderConfig.d.ts +15 -0
  50. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.d.ts +8 -0
  51. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.d.ts +8 -0
  52. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/index.d.ts +3 -0
  53. package/dist-types/ts3.4/util-identity-and-auth/httpAuthSchemes/noAuth.d.ts +8 -0
  54. package/dist-types/ts3.4/util-identity-and-auth/index.d.ts +3 -0
  55. package/dist-types/ts3.4/util-identity-and-auth/memoizeIdentityProvider.d.ts +30 -0
  56. package/dist-types/util-identity-and-auth/DefaultIdentityProviderConfig.d.ts +15 -0
  57. package/dist-types/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.d.ts +8 -0
  58. package/dist-types/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.d.ts +8 -0
  59. package/dist-types/util-identity-and-auth/httpAuthSchemes/index.d.ts +3 -0
  60. package/dist-types/util-identity-and-auth/httpAuthSchemes/noAuth.d.ts +8 -0
  61. package/dist-types/util-identity-and-auth/index.d.ts +3 -0
  62. package/dist-types/util-identity-and-auth/memoizeIdentityProvider.d.ts +30 -0
  63. package/package.json +65 -0
@@ -0,0 +1,18 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { SMITHY_CONTEXT_KEY, } from "@smithy/types";
3
+ import { getSmithyContext } from "@smithy/util-middleware";
4
+ export const httpSigningMiddleware = (config) => (next, context) => async (args) => {
5
+ if (!HttpRequest.isInstance(args.request)) {
6
+ return next(args);
7
+ }
8
+ const smithyContext = getSmithyContext(context);
9
+ const scheme = smithyContext.selectedHttpAuthScheme;
10
+ if (!scheme) {
11
+ throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
12
+ }
13
+ const { httpAuthOption: { signingProperties }, identity, signer, } = scheme;
14
+ return next({
15
+ ...args,
16
+ request: await signer.sign(args.request, identity, signingProperties || {}),
17
+ });
18
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./httpSigningMiddleware";
2
+ export * from "./getHttpSigningMiddleware";
@@ -0,0 +1,13 @@
1
+ export class DefaultIdentityProviderConfig {
2
+ constructor(config) {
3
+ this.authSchemes = new Map();
4
+ for (const [key, value] of Object.entries(config)) {
5
+ if (value !== undefined) {
6
+ this.authSchemes.set(key, value);
7
+ }
8
+ }
9
+ }
10
+ getIdentityProvider(schemeId) {
11
+ return this.authSchemes.get(schemeId);
12
+ }
13
+ }
@@ -0,0 +1,33 @@
1
+ import { HttpApiKeyAuthLocation } from "@smithy/types";
2
+ export class HttpApiKeyAuthSigner {
3
+ async sign(httpRequest, identity, signingProperties) {
4
+ if (!signingProperties) {
5
+ throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
6
+ }
7
+ if (!signingProperties.name) {
8
+ throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
9
+ }
10
+ if (!signingProperties.in) {
11
+ throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
12
+ }
13
+ if (!identity.apiKey) {
14
+ throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
15
+ }
16
+ const clonedRequest = httpRequest.clone();
17
+ if (signingProperties.in === HttpApiKeyAuthLocation.QUERY) {
18
+ clonedRequest.query[signingProperties.name] = identity.apiKey;
19
+ }
20
+ else if (signingProperties.in === HttpApiKeyAuthLocation.HEADER) {
21
+ clonedRequest.headers[signingProperties.name] = signingProperties.scheme
22
+ ? `${signingProperties.scheme} ${identity.apiKey}`
23
+ : identity.apiKey;
24
+ }
25
+ else {
26
+ throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
27
+ "but found: `" +
28
+ signingProperties.in +
29
+ "`");
30
+ }
31
+ return clonedRequest;
32
+ }
33
+ }
@@ -0,0 +1,10 @@
1
+ export class HttpBearerAuthSigner {
2
+ async sign(httpRequest, identity, signingProperties) {
3
+ const clonedRequest = httpRequest.clone();
4
+ if (!identity.token) {
5
+ throw new Error("request could not be signed with `token` since the `token` is not defined");
6
+ }
7
+ clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
8
+ return clonedRequest;
9
+ }
10
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./httpApiKeyAuth";
2
+ export * from "./httpBearerAuth";
3
+ export * from "./noAuth";
@@ -0,0 +1,5 @@
1
+ export class NoAuthSigner {
2
+ async sign(httpRequest, identity, signingProperties) {
3
+ return httpRequest;
4
+ }
5
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./DefaultIdentityProviderConfig";
2
+ export * from "./httpAuthSchemes";
3
+ export * from "./memoizeIdentityProvider";
@@ -0,0 +1,53 @@
1
+ export const createIsIdentityExpiredFunction = (expirationMs) => (identity) => doesIdentityRequireRefresh(identity) && identity.expiration.getTime() - Date.now() < expirationMs;
2
+ export const EXPIRATION_MS = 300000;
3
+ export const isIdentityExpired = createIsIdentityExpiredFunction(EXPIRATION_MS);
4
+ export const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
5
+ export const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
6
+ if (provider === undefined) {
7
+ return undefined;
8
+ }
9
+ const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
10
+ let resolved;
11
+ let pending;
12
+ let hasResult;
13
+ let isConstant = false;
14
+ const coalesceProvider = async (options) => {
15
+ if (!pending) {
16
+ pending = normalizedProvider(options);
17
+ }
18
+ try {
19
+ resolved = await pending;
20
+ hasResult = true;
21
+ isConstant = false;
22
+ }
23
+ finally {
24
+ pending = undefined;
25
+ }
26
+ return resolved;
27
+ };
28
+ if (isExpired === undefined) {
29
+ return async (options) => {
30
+ if (!hasResult || options?.forceRefresh) {
31
+ resolved = await coalesceProvider(options);
32
+ }
33
+ return resolved;
34
+ };
35
+ }
36
+ return async (options) => {
37
+ if (!hasResult || options?.forceRefresh) {
38
+ resolved = await coalesceProvider(options);
39
+ }
40
+ if (isConstant) {
41
+ return resolved;
42
+ }
43
+ if (!requiresRefresh(resolved)) {
44
+ isConstant = true;
45
+ return resolved;
46
+ }
47
+ if (isExpired(resolved)) {
48
+ await coalesceProvider(options);
49
+ return resolved;
50
+ }
51
+ return resolved;
52
+ };
53
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./middleware-http-auth-scheme";
2
+ export * from "./middleware-http-signing";
3
+ export * from "./util-identity-and-auth";
@@ -0,0 +1,18 @@
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 {};
@@ -0,0 +1,18 @@
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 {};
@@ -0,0 +1,32 @@
1
+ import { HandlerExecutionContext, HttpAuthScheme, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider, IdentityProviderConfig, SelectedHttpAuthScheme, SerializeMiddleware, SMITHY_CONTEXT_KEY } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export interface PreviouslyResolved<TParameters extends HttpAuthSchemeParameters> {
6
+ httpAuthSchemes: HttpAuthScheme[];
7
+ httpAuthSchemeProvider: HttpAuthSchemeProvider<TParameters>;
8
+ }
9
+ /**
10
+ * @internal
11
+ */
12
+ interface HttpAuthSchemeMiddlewareOptions<TConfig extends object, TContext extends HandlerExecutionContext, TParameters extends HttpAuthSchemeParameters, TInput extends object> {
13
+ httpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider<TConfig, TContext, TParameters, TInput>;
14
+ identityProviderConfigProvider: (config: TConfig) => Promise<IdentityProviderConfig>;
15
+ }
16
+ /**
17
+ * @internal
18
+ */
19
+ interface HttpAuthSchemeMiddlewareSmithyContext extends Record<string, unknown> {
20
+ selectedHttpAuthScheme?: SelectedHttpAuthScheme;
21
+ }
22
+ /**
23
+ * @internal
24
+ */
25
+ interface HttpAuthSchemeMiddlewareHandlerExecutionContext extends HandlerExecutionContext {
26
+ [SMITHY_CONTEXT_KEY]?: HttpAuthSchemeMiddlewareSmithyContext;
27
+ }
28
+ /**
29
+ * @internal
30
+ */
31
+ 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>;
32
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from "./httpAuthSchemeMiddleware";
2
+ export * from "./getHttpAuthSchemeEndpointRuleSetPlugin";
3
+ export * from "./getHttpAuthSchemePlugin";
@@ -0,0 +1,9 @@
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>;
@@ -0,0 +1,5 @@
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>;
@@ -0,0 +1,2 @@
1
+ export * from "./httpSigningMiddleware";
2
+ export * from "./getHttpSigningMiddleware";
@@ -0,0 +1,3 @@
1
+ export * from "./middleware-http-auth-scheme";
2
+ export * from "./middleware-http-signing";
3
+ export * from "./util-identity-and-auth";
@@ -0,0 +1,18 @@
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 {};
@@ -0,0 +1,18 @@
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 {};
@@ -0,0 +1,32 @@
1
+ import { HandlerExecutionContext, HttpAuthScheme, HttpAuthSchemeParameters, HttpAuthSchemeParametersProvider, HttpAuthSchemeProvider, IdentityProviderConfig, SelectedHttpAuthScheme, SerializeMiddleware, SMITHY_CONTEXT_KEY } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export interface PreviouslyResolved<TParameters extends HttpAuthSchemeParameters> {
6
+ httpAuthSchemes: HttpAuthScheme[];
7
+ httpAuthSchemeProvider: HttpAuthSchemeProvider<TParameters>;
8
+ }
9
+ /**
10
+ * @internal
11
+ */
12
+ interface HttpAuthSchemeMiddlewareOptions<TConfig extends object, TContext extends HandlerExecutionContext, TParameters extends HttpAuthSchemeParameters, TInput extends object> {
13
+ httpAuthSchemeParametersProvider: HttpAuthSchemeParametersProvider<TConfig, TContext, TParameters, TInput>;
14
+ identityProviderConfigProvider: (config: TConfig) => Promise<IdentityProviderConfig>;
15
+ }
16
+ /**
17
+ * @internal
18
+ */
19
+ interface HttpAuthSchemeMiddlewareSmithyContext extends Record<string, unknown> {
20
+ selectedHttpAuthScheme?: SelectedHttpAuthScheme;
21
+ }
22
+ /**
23
+ * @internal
24
+ */
25
+ interface HttpAuthSchemeMiddlewareHandlerExecutionContext extends HandlerExecutionContext {
26
+ [SMITHY_CONTEXT_KEY]?: HttpAuthSchemeMiddlewareSmithyContext;
27
+ }
28
+ /**
29
+ * @internal
30
+ */
31
+ 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>;
32
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from "./httpAuthSchemeMiddleware";
2
+ export * from "./getHttpAuthSchemeEndpointRuleSetPlugin";
3
+ export * from "./getHttpAuthSchemePlugin";
@@ -0,0 +1,9 @@
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>;
@@ -0,0 +1,5 @@
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>;
@@ -0,0 +1,2 @@
1
+ export * from "./httpSigningMiddleware";
2
+ export * from "./getHttpSigningMiddleware";
@@ -0,0 +1,15 @@
1
+ import { HttpAuthSchemeId, Identity, IdentityProvider, IdentityProviderConfig } from "@smithy/types";
2
+ /**
3
+ * Default implementation of IdentityProviderConfig
4
+ * @internal
5
+ */
6
+ export declare class DefaultIdentityProviderConfig implements IdentityProviderConfig {
7
+ private authSchemes;
8
+ /**
9
+ * Creates an IdentityProviderConfig with a record of scheme IDs to identity providers.
10
+ *
11
+ * @param config scheme IDs and identity providers to configure
12
+ */
13
+ constructor(config: Record<HttpAuthSchemeId, IdentityProvider<Identity> | undefined>);
14
+ getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined;
15
+ }
@@ -0,0 +1,8 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { ApiKeyIdentity, HttpRequest as IHttpRequest, HttpSigner } from "@smithy/types";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class HttpApiKeyAuthSigner implements HttpSigner {
7
+ sign(httpRequest: HttpRequest, identity: ApiKeyIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { HttpRequest as IHttpRequest, HttpSigner, TokenIdentity } from "@smithy/types";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class HttpBearerAuthSigner implements HttpSigner {
7
+ sign(httpRequest: HttpRequest, identity: TokenIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./httpApiKeyAuth";
2
+ export * from "./httpBearerAuth";
3
+ export * from "./noAuth";
@@ -0,0 +1,8 @@
1
+ import { HttpRequest, HttpSigner, Identity } from "@smithy/types";
2
+ /**
3
+ * Signer for the synthetic @smithy.api#noAuth auth scheme.
4
+ * @internal
5
+ */
6
+ export declare class NoAuthSigner implements HttpSigner {
7
+ sign(httpRequest: HttpRequest, identity: Identity, signingProperties: Record<string, unknown>): Promise<HttpRequest>;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./DefaultIdentityProviderConfig";
2
+ export * from "./httpAuthSchemes";
3
+ export * from "./memoizeIdentityProvider";
@@ -0,0 +1,30 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const createIsIdentityExpiredFunction: (expirationMs: number) => (identity: Identity) => boolean;
6
+ /**
7
+ * @internal
8
+ * This may need to be configurable in the future, but for now it is defaulted to 5min.
9
+ */
10
+ export declare const EXPIRATION_MS = 300000;
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare const isIdentityExpired: (identity: Identity) => boolean;
15
+ /**
16
+ * @internal
17
+ */
18
+ export declare const doesIdentityRequireRefresh: (identity: Identity) => boolean;
19
+ /**
20
+ * @internal
21
+ */
22
+ export interface MemoizedIdentityProvider<IdentityT extends Identity> {
23
+ (options?: Record<string, any> & {
24
+ forceRefresh?: boolean;
25
+ }): Promise<IdentityT>;
26
+ }
27
+ /**
28
+ * @internal
29
+ */
30
+ export declare const memoizeIdentityProvider: <IdentityT extends Identity>(provider: IdentityT | IdentityProvider<IdentityT> | undefined, isExpired: (resolved: Identity) => boolean, requiresRefresh: (resolved: Identity) => boolean) => MemoizedIdentityProvider<IdentityT> | undefined;
@@ -0,0 +1,15 @@
1
+ import { HttpAuthSchemeId, Identity, IdentityProvider, IdentityProviderConfig } from "@smithy/types";
2
+ /**
3
+ * Default implementation of IdentityProviderConfig
4
+ * @internal
5
+ */
6
+ export declare class DefaultIdentityProviderConfig implements IdentityProviderConfig {
7
+ private authSchemes;
8
+ /**
9
+ * Creates an IdentityProviderConfig with a record of scheme IDs to identity providers.
10
+ *
11
+ * @param config scheme IDs and identity providers to configure
12
+ */
13
+ constructor(config: Record<HttpAuthSchemeId, IdentityProvider<Identity> | undefined>);
14
+ getIdentityProvider(schemeId: HttpAuthSchemeId): IdentityProvider<Identity> | undefined;
15
+ }
@@ -0,0 +1,8 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { ApiKeyIdentity, HttpRequest as IHttpRequest, HttpSigner } from "@smithy/types";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class HttpApiKeyAuthSigner implements HttpSigner {
7
+ sign(httpRequest: HttpRequest, identity: ApiKeyIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { HttpRequest } from "@smithy/protocol-http";
2
+ import { HttpRequest as IHttpRequest, HttpSigner, TokenIdentity } from "@smithy/types";
3
+ /**
4
+ * @internal
5
+ */
6
+ export declare class HttpBearerAuthSigner implements HttpSigner {
7
+ sign(httpRequest: HttpRequest, identity: TokenIdentity, signingProperties: Record<string, any>): Promise<IHttpRequest>;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./httpApiKeyAuth";
2
+ export * from "./httpBearerAuth";
3
+ export * from "./noAuth";
@@ -0,0 +1,8 @@
1
+ import { HttpRequest, HttpSigner, Identity } from "@smithy/types";
2
+ /**
3
+ * Signer for the synthetic @smithy.api#noAuth auth scheme.
4
+ * @internal
5
+ */
6
+ export declare class NoAuthSigner implements HttpSigner {
7
+ sign(httpRequest: HttpRequest, identity: Identity, signingProperties: Record<string, unknown>): Promise<HttpRequest>;
8
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./DefaultIdentityProviderConfig";
2
+ export * from "./httpAuthSchemes";
3
+ export * from "./memoizeIdentityProvider";
@@ -0,0 +1,30 @@
1
+ import { Identity, IdentityProvider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const createIsIdentityExpiredFunction: (expirationMs: number) => (identity: Identity) => boolean;
6
+ /**
7
+ * @internal
8
+ * This may need to be configurable in the future, but for now it is defaulted to 5min.
9
+ */
10
+ export declare const EXPIRATION_MS = 300000;
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare const isIdentityExpired: (identity: Identity) => boolean;
15
+ /**
16
+ * @internal
17
+ */
18
+ export declare const doesIdentityRequireRefresh: (identity: Identity) => boolean;
19
+ /**
20
+ * @internal
21
+ */
22
+ export interface MemoizedIdentityProvider<IdentityT extends Identity> {
23
+ (options?: Record<string, any> & {
24
+ forceRefresh?: boolean;
25
+ }): Promise<IdentityT>;
26
+ }
27
+ /**
28
+ * @internal
29
+ */
30
+ export declare const memoizeIdentityProvider: <IdentityT extends Identity>(provider: IdentityT | IdentityProvider<IdentityT> | undefined, isExpired: (resolved: Identity) => boolean, requiresRefresh: (resolved: Identity) => boolean) => MemoizedIdentityProvider<IdentityT> | undefined;
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@smithy/core",
3
+ "version": "1.0.0",
4
+ "scripts": {
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",
7
+ "build:es": "yarn g:tsc -p tsconfig.es.json",
8
+ "build:types": "yarn g:tsc -p tsconfig.types.json",
9
+ "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
10
+ "stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
11
+ "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12
+ "lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
13
+ "format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
14
+ "test": "yarn g:jest"
15
+ },
16
+ "main": "./dist-cjs/index.js",
17
+ "module": "./dist-es/index.js",
18
+ "types": "./dist-types/index.d.ts",
19
+ "author": {
20
+ "name": "AWS Smithy Team",
21
+ "email": "",
22
+ "url": "https://smithy.io"
23
+ },
24
+ "license": "Apache-2.0",
25
+ "dependencies": {
26
+ "@smithy/middleware-endpoint": "^2.2.0",
27
+ "@smithy/middleware-retry": "^2.0.20",
28
+ "@smithy/middleware-serde": "^2.0.13",
29
+ "@smithy/protocol-http": "^3.0.9",
30
+ "@smithy/types": "^2.5.0",
31
+ "tslib": "^2.5.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=14.0.0"
35
+ },
36
+ "typesVersions": {
37
+ "<4.0": {
38
+ "dist-types/*": [
39
+ "dist-types/ts3.4/*"
40
+ ]
41
+ }
42
+ },
43
+ "files": [
44
+ "dist-*/**"
45
+ ],
46
+ "homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/core",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/awslabs/smithy-typescript.git",
50
+ "directory": "packages/core"
51
+ },
52
+ "devDependencies": {
53
+ "@tsconfig/recommended": "1.0.1",
54
+ "concurrently": "7.0.0",
55
+ "downlevel-dts": "0.10.1",
56
+ "rimraf": "3.0.2",
57
+ "typedoc": "0.23.23"
58
+ },
59
+ "typedoc": {
60
+ "entryPoint": "src/index.ts"
61
+ },
62
+ "publishConfig": {
63
+ "directory": ".release/package"
64
+ }
65
+ }