@aws-sdk/middleware-token 3.901.0 → 3.907.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 (2) hide show
  1. package/dist-cjs/index.js +52 -85
  2. package/package.json +2 -2
package/dist-cjs/index.js CHANGED
@@ -1,93 +1,60 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ 'use strict';
2
+
3
+ var protocolHttp = require('@smithy/protocol-http');
4
+ var types = require('@smithy/types');
5
+ var propertyProvider = require('@smithy/property-provider');
6
+ var utilMiddleware = require('@smithy/util-middleware');
7
+ var tokenDefaultProvider = require('./tokenDefaultProvider');
8
+
9
+ const tokenMiddlewareOptions = {
10
+ name: "tokenMiddleware",
11
+ tags: ["TOKEN", "AUTH"],
12
+ relation: "after",
13
+ toMiddleware: "retryMiddleware",
14
+ override: true,
10
15
  };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
16
+ const tokenMiddleware = (options) => (next, context) => async (args) => {
17
+ if (!protocolHttp.HttpRequest.isInstance(args.request) || context.currentAuthConfig)
18
+ return next(args);
19
+ const token = options.token && (await options.token());
20
+ if (token?.token) {
21
+ const authConfig = {
22
+ in: types.HttpAuthLocation.HEADER,
23
+ name: "authorization",
24
+ scheme: "Bearer",
25
+ };
26
+ context.currentAuthConfig = authConfig;
27
+ args.request.headers[authConfig.name] = `${authConfig.scheme} ${token.token}`;
28
+ }
29
+ else {
30
+ context.currentAuthConfig = undefined;
31
+ }
32
+ return next(args);
18
33
  };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
34
 
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- getTokenPlugin: () => getTokenPlugin,
25
- resolveTokenConfig: () => resolveTokenConfig,
26
- tokenMiddleware: () => tokenMiddleware,
27
- tokenMiddlewareOptions: () => tokenMiddlewareOptions
35
+ const getTokenPlugin = (options) => ({
36
+ applyToStack: (clientStack) => {
37
+ clientStack.addRelativeTo(tokenMiddleware(options), tokenMiddlewareOptions);
38
+ },
28
39
  });
29
- module.exports = __toCommonJS(index_exports);
30
40
 
31
- // src/tokenMiddleware.ts
32
- var import_protocol_http = require("@smithy/protocol-http");
33
- var import_types = require("@smithy/types");
34
- var tokenMiddlewareOptions = {
35
- name: "tokenMiddleware",
36
- tags: ["TOKEN", "AUTH"],
37
- relation: "after",
38
- toMiddleware: "retryMiddleware",
39
- override: true
41
+ const isTokenWithExpiry = (token) => token.expiration !== undefined;
42
+ const isTokenExpiringWithinFiveMins = (token) => isTokenWithExpiry(token) && token.expiration.getTime() - Date.now() < 300000;
43
+ const normalizeTokenProvider = (token) => {
44
+ if (typeof token === "function") {
45
+ return propertyProvider.memoize(token, isTokenExpiringWithinFiveMins, isTokenWithExpiry);
46
+ }
47
+ return utilMiddleware.normalizeProvider(token);
40
48
  };
41
- var tokenMiddleware = /* @__PURE__ */ __name((options) => (next, context) => async (args) => {
42
- if (!import_protocol_http.HttpRequest.isInstance(args.request) || context.currentAuthConfig) return next(args);
43
- const token = options.token && await options.token();
44
- if (token?.token) {
45
- const authConfig = {
46
- in: import_types.HttpAuthLocation.HEADER,
47
- name: "authorization",
48
- scheme: "Bearer"
49
- };
50
- context.currentAuthConfig = authConfig;
51
- args.request.headers[authConfig.name] = `${authConfig.scheme} ${token.token}`;
52
- } else {
53
- context.currentAuthConfig = void 0;
54
- }
55
- return next(args);
56
- }, "tokenMiddleware");
57
-
58
- // src/getTokenPlugin.ts
59
- var getTokenPlugin = /* @__PURE__ */ __name((options) => ({
60
- applyToStack: /* @__PURE__ */ __name((clientStack) => {
61
- clientStack.addRelativeTo(tokenMiddleware(options), tokenMiddlewareOptions);
62
- }, "applyToStack")
63
- }), "getTokenPlugin");
64
-
65
- // src/normalizeTokenProvider.ts
66
- var import_property_provider = require("@smithy/property-provider");
67
- var import_util_middleware = require("@smithy/util-middleware");
68
- var isTokenWithExpiry = /* @__PURE__ */ __name((token) => token.expiration !== void 0, "isTokenWithExpiry");
69
- var isTokenExpiringWithinFiveMins = /* @__PURE__ */ __name((token) => isTokenWithExpiry(token) && token.expiration.getTime() - Date.now() < 3e5, "isTokenExpiringWithinFiveMins");
70
- var normalizeTokenProvider = /* @__PURE__ */ __name((token) => {
71
- if (typeof token === "function") {
72
- return (0, import_property_provider.memoize)(token, isTokenExpiringWithinFiveMins, isTokenWithExpiry);
73
- }
74
- return (0, import_util_middleware.normalizeProvider)(token);
75
- }, "normalizeTokenProvider");
76
49
 
77
- // src/resolveTokenConfig.ts
78
- var import_tokenDefaultProvider = require("././tokenDefaultProvider");
79
- var resolveTokenConfig = /* @__PURE__ */ __name((input) => {
80
- const { token } = input;
81
- return Object.assign(input, {
82
- token: token ? normalizeTokenProvider(token) : (0, import_tokenDefaultProvider.tokenDefaultProvider)(input)
83
- });
84
- }, "resolveTokenConfig");
85
- // Annotate the CommonJS export names for ESM import in node:
86
-
87
- 0 && (module.exports = {
88
- getTokenPlugin,
89
- resolveTokenConfig,
90
- tokenMiddlewareOptions,
91
- tokenMiddleware
92
- });
50
+ const resolveTokenConfig = (input) => {
51
+ const { token } = input;
52
+ return Object.assign(input, {
53
+ token: token ? normalizeTokenProvider(token) : tokenDefaultProvider.tokenDefaultProvider(input),
54
+ });
55
+ };
93
56
 
57
+ exports.getTokenPlugin = getTokenPlugin;
58
+ exports.resolveTokenConfig = resolveTokenConfig;
59
+ exports.tokenMiddleware = tokenMiddleware;
60
+ exports.tokenMiddlewareOptions = tokenMiddlewareOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-token",
3
- "version": "3.901.0",
3
+ "version": "3.907.0",
4
4
  "description": "Middleware and Plugin for setting token authentication",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "license": "Apache-2.0",
32
32
  "dependencies": {
33
- "@aws-sdk/token-providers": "3.901.0",
33
+ "@aws-sdk/token-providers": "3.907.0",
34
34
  "@aws-sdk/types": "3.901.0",
35
35
  "@smithy/property-provider": "^4.2.0",
36
36
  "@smithy/protocol-http": "^5.3.0",