@smithy/core 1.0.1 → 1.0.3

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.
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSmithyContext = void 0;
4
+ const types_1 = require("@smithy/types");
5
+ const getSmithyContext = (context) => context[types_1.SMITHY_CONTEXT_KEY] || (context[types_1.SMITHY_CONTEXT_KEY] = {});
6
+ exports.getSmithyContext = getSmithyContext;
package/dist-cjs/index.js CHANGED
@@ -4,3 +4,5 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./middleware-http-auth-scheme"), exports);
5
5
  tslib_1.__exportStar(require("./middleware-http-signing"), exports);
6
6
  tslib_1.__exportStar(require("./util-identity-and-auth"), exports);
7
+ tslib_1.__exportStar(require("./getSmithyContext"), exports);
8
+ tslib_1.__exportStar(require("./normalizeProvider"), exports);
@@ -4,6 +4,10 @@ exports.httpSigningMiddleware = void 0;
4
4
  const protocol_http_1 = require("@smithy/protocol-http");
5
5
  const types_1 = require("@smithy/types");
6
6
  const util_middleware_1 = require("@smithy/util-middleware");
7
+ const defaultErrorHandler = (signingProperties) => (error) => {
8
+ throw error;
9
+ };
10
+ const defaultSuccessHandler = (httpResponse, signingProperties) => { };
7
11
  const httpSigningMiddleware = (config) => (next, context) => async (args) => {
8
12
  if (!protocol_http_1.HttpRequest.isInstance(args.request)) {
9
13
  return next(args);
@@ -13,10 +17,12 @@ const httpSigningMiddleware = (config) => (next, context) => async (args) => {
13
17
  if (!scheme) {
14
18
  throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
15
19
  }
16
- const { httpAuthOption: { signingProperties }, identity, signer, } = scheme;
17
- return next({
20
+ const { httpAuthOption: { signingProperties = {} }, identity, signer, } = scheme;
21
+ const output = await next({
18
22
  ...args,
19
- request: await signer.sign(args.request, identity, signingProperties || {}),
20
- });
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;
21
27
  };
22
28
  exports.httpSigningMiddleware = httpSigningMiddleware;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeProvider = void 0;
4
+ const normalizeProvider = (input) => {
5
+ if (typeof input === "function")
6
+ return input;
7
+ const promisified = Promise.resolve(input);
8
+ return () => promisified;
9
+ };
10
+ exports.normalizeProvider = normalizeProvider;
@@ -0,0 +1,2 @@
1
+ import { SMITHY_CONTEXT_KEY } from "@smithy/types";
2
+ export const getSmithyContext = (context) => context[SMITHY_CONTEXT_KEY] || (context[SMITHY_CONTEXT_KEY] = {});
package/dist-es/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from "./middleware-http-auth-scheme";
2
2
  export * from "./middleware-http-signing";
3
3
  export * from "./util-identity-and-auth";
4
+ export * from "./getSmithyContext";
5
+ export * from "./normalizeProvider";
@@ -1,6 +1,10 @@
1
1
  import { HttpRequest } from "@smithy/protocol-http";
2
2
  import { SMITHY_CONTEXT_KEY, } from "@smithy/types";
3
3
  import { getSmithyContext } from "@smithy/util-middleware";
4
+ const defaultErrorHandler = (signingProperties) => (error) => {
5
+ throw error;
6
+ };
7
+ const defaultSuccessHandler = (httpResponse, signingProperties) => { };
4
8
  export const httpSigningMiddleware = (config) => (next, context) => async (args) => {
5
9
  if (!HttpRequest.isInstance(args.request)) {
6
10
  return next(args);
@@ -10,9 +14,11 @@ export const httpSigningMiddleware = (config) => (next, context) => async (args)
10
14
  if (!scheme) {
11
15
  throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
12
16
  }
13
- const { httpAuthOption: { signingProperties }, identity, signer, } = scheme;
14
- return next({
17
+ const { httpAuthOption: { signingProperties = {} }, identity, signer, } = scheme;
18
+ const output = await next({
15
19
  ...args,
16
- request: await signer.sign(args.request, identity, signingProperties || {}),
17
- });
20
+ request: await signer.sign(args.request, identity, signingProperties),
21
+ }).catch((signer.errorHandler || defaultErrorHandler)(signingProperties));
22
+ (signer.successHandler || defaultSuccessHandler)(output.response, signingProperties);
23
+ return output;
18
24
  };
@@ -0,0 +1,6 @@
1
+ export const normalizeProvider = (input) => {
2
+ if (typeof input === "function")
3
+ return input;
4
+ const promisified = Promise.resolve(input);
5
+ return () => promisified;
6
+ };
@@ -0,0 +1,5 @@
1
+ import { HandlerExecutionContext } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const getSmithyContext: (context: HandlerExecutionContext) => Record<string, unknown>;
@@ -1,3 +1,5 @@
1
1
  export * from "./middleware-http-auth-scheme";
2
2
  export * from "./middleware-http-signing";
3
3
  export * from "./util-identity-and-auth";
4
+ export * from "./getSmithyContext";
5
+ export * from "./normalizeProvider";
@@ -0,0 +1,7 @@
1
+ import { Provider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ *
5
+ * @returns a provider function for the input value if it isn't already one.
6
+ */
7
+ export declare const normalizeProvider: <T>(input: T | Provider<T>) => Provider<T>;
@@ -0,0 +1,5 @@
1
+ import { HandlerExecutionContext } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const getSmithyContext: (context: HandlerExecutionContext) => Record<string, unknown>;
@@ -1,3 +1,5 @@
1
1
  export * from "./middleware-http-auth-scheme";
2
2
  export * from "./middleware-http-signing";
3
3
  export * from "./util-identity-and-auth";
4
+ export * from "./getSmithyContext";
5
+ export * from "./normalizeProvider";
@@ -0,0 +1,7 @@
1
+ import { Provider } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ *
5
+ * @returns a provider function for the input value if it isn't already one.
6
+ */
7
+ export declare const normalizeProvider: <T>(input: T | Provider<T>) => Provider<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "yarn g:tsc -p tsconfig.cjs.json",
@@ -8,10 +8,10 @@
8
8
  "build:types": "yarn g:tsc -p tsconfig.types.json",
9
9
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
10
10
  "stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
11
- "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
11
+ "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
12
12
  "lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
13
13
  "format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
14
- "test": "yarn g:jest --passWithNoTests"
14
+ "test": "yarn g:jest"
15
15
  },
16
16
  "main": "./dist-cjs/index.js",
17
17
  "module": "./dist-es/index.js",
@@ -23,11 +23,11 @@
23
23
  },
24
24
  "license": "Apache-2.0",
25
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",
26
+ "@smithy/middleware-endpoint": "^2.2.2",
27
+ "@smithy/middleware-retry": "^2.0.22",
28
+ "@smithy/middleware-serde": "^2.0.15",
29
+ "@smithy/protocol-http": "^3.0.11",
30
+ "@smithy/types": "^2.7.0",
31
31
  "tslib": "^2.5.0"
32
32
  },
33
33
  "engines": {