@aws-sdk/middleware-recursion-detection 3.862.0 → 3.886.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.
package/dist-cjs/index.js CHANGED
@@ -16,57 +16,39 @@ var __copyProps = (to, from, except, desc) => {
16
16
  }
17
17
  return to;
18
18
  };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
20
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
21
 
21
22
  // src/index.ts
22
23
  var index_exports = {};
23
24
  __export(index_exports, {
24
- addRecursionDetectionMiddlewareOptions: () => addRecursionDetectionMiddlewareOptions,
25
- getRecursionDetectionPlugin: () => getRecursionDetectionPlugin,
26
- recursionDetectionMiddleware: () => recursionDetectionMiddleware
25
+ getRecursionDetectionPlugin: () => getRecursionDetectionPlugin
27
26
  });
28
27
  module.exports = __toCommonJS(index_exports);
29
- var import_protocol_http = require("@smithy/protocol-http");
30
- var TRACE_ID_HEADER_NAME = "X-Amzn-Trace-Id";
31
- var ENV_LAMBDA_FUNCTION_NAME = "AWS_LAMBDA_FUNCTION_NAME";
32
- var ENV_TRACE_ID = "_X_AMZN_TRACE_ID";
33
- var recursionDetectionMiddleware = /* @__PURE__ */ __name((options) => (next) => async (args) => {
34
- const { request } = args;
35
- if (!import_protocol_http.HttpRequest.isInstance(request) || options.runtime !== "node") {
36
- return next(args);
37
- }
38
- const traceIdHeader = Object.keys(request.headers ?? {}).find((h) => h.toLowerCase() === TRACE_ID_HEADER_NAME.toLowerCase()) ?? TRACE_ID_HEADER_NAME;
39
- if (request.headers.hasOwnProperty(traceIdHeader)) {
40
- return next(args);
41
- }
42
- const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
43
- const traceId = process.env[ENV_TRACE_ID];
44
- const nonEmptyString = /* @__PURE__ */ __name((str) => typeof str === "string" && str.length > 0, "nonEmptyString");
45
- if (nonEmptyString(functionName) && nonEmptyString(traceId)) {
46
- request.headers[TRACE_ID_HEADER_NAME] = traceId;
47
- }
48
- return next({
49
- ...args,
50
- request
51
- });
52
- }, "recursionDetectionMiddleware");
53
- var addRecursionDetectionMiddlewareOptions = {
28
+
29
+ // src/configuration.ts
30
+ var recursionDetectionMiddlewareOptions = {
54
31
  step: "build",
55
32
  tags: ["RECURSION_DETECTION"],
56
33
  name: "recursionDetectionMiddleware",
57
34
  override: true,
58
35
  priority: "low"
59
36
  };
37
+
38
+ // src/getRecursionDetectionPlugin.ts
39
+ var import_recursionDetectionMiddleware = require("././recursionDetectionMiddleware");
60
40
  var getRecursionDetectionPlugin = /* @__PURE__ */ __name((options) => ({
61
41
  applyToStack: /* @__PURE__ */ __name((clientStack) => {
62
- clientStack.add(recursionDetectionMiddleware(options), addRecursionDetectionMiddlewareOptions);
42
+ clientStack.add((0, import_recursionDetectionMiddleware.recursionDetectionMiddleware)(), recursionDetectionMiddlewareOptions);
63
43
  }, "applyToStack")
64
44
  }), "getRecursionDetectionPlugin");
45
+
46
+ // src/index.ts
47
+ __reExport(index_exports, require("././recursionDetectionMiddleware"), module.exports);
65
48
  // Annotate the CommonJS export names for ESM import in node:
66
49
 
67
50
  0 && (module.exports = {
68
- recursionDetectionMiddleware,
69
- addRecursionDetectionMiddlewareOptions,
70
- getRecursionDetectionPlugin
51
+ getRecursionDetectionPlugin,
52
+ recursionDetectionMiddleware
71
53
  });
72
54
 
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.recursionDetectionMiddleware = void 0;
4
+ const lambda_invoke_store_1 = require("@aws/lambda-invoke-store");
5
+ const protocol_http_1 = require("@smithy/protocol-http");
6
+ const TRACE_ID_HEADER_NAME = "X-Amzn-Trace-Id";
7
+ const ENV_LAMBDA_FUNCTION_NAME = "AWS_LAMBDA_FUNCTION_NAME";
8
+ const ENV_TRACE_ID = "_X_AMZN_TRACE_ID";
9
+ const recursionDetectionMiddleware = () => (next) => async (args) => {
10
+ const { request } = args;
11
+ if (!protocol_http_1.HttpRequest.isInstance(request)) {
12
+ return next(args);
13
+ }
14
+ const traceIdHeader = Object.keys(request.headers ?? {}).find((h) => h.toLowerCase() === TRACE_ID_HEADER_NAME.toLowerCase()) ??
15
+ TRACE_ID_HEADER_NAME;
16
+ if (request.headers.hasOwnProperty(traceIdHeader)) {
17
+ return next(args);
18
+ }
19
+ const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
20
+ const traceIdFromEnv = process.env[ENV_TRACE_ID];
21
+ const traceIdFromInvokeStore = lambda_invoke_store_1.InvokeStore.getXRayTraceId();
22
+ const traceId = traceIdFromInvokeStore ?? traceIdFromEnv;
23
+ const nonEmptyString = (str) => typeof str === "string" && str.length > 0;
24
+ if (nonEmptyString(functionName) && nonEmptyString(traceId)) {
25
+ request.headers[TRACE_ID_HEADER_NAME] = traceId;
26
+ }
27
+ return next({
28
+ ...args,
29
+ request,
30
+ });
31
+ };
32
+ exports.recursionDetectionMiddleware = recursionDetectionMiddleware;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.recursionDetectionMiddleware = void 0;
4
+ const recursionDetectionMiddleware = () => (next) => async (args) => next(args);
5
+ exports.recursionDetectionMiddleware = recursionDetectionMiddleware;
@@ -0,0 +1,7 @@
1
+ export const recursionDetectionMiddlewareOptions = {
2
+ step: "build",
3
+ tags: ["RECURSION_DETECTION"],
4
+ name: "recursionDetectionMiddleware",
5
+ override: true,
6
+ priority: "low",
7
+ };
@@ -0,0 +1,7 @@
1
+ import { recursionDetectionMiddlewareOptions } from "./configuration";
2
+ import { recursionDetectionMiddleware } from "./recursionDetectionMiddleware";
3
+ export const getRecursionDetectionPlugin = (options) => ({
4
+ applyToStack: (clientStack) => {
5
+ clientStack.add(recursionDetectionMiddleware(), recursionDetectionMiddlewareOptions);
6
+ },
7
+ });
package/dist-es/index.js CHANGED
@@ -1,37 +1,2 @@
1
- import { HttpRequest } from "@smithy/protocol-http";
2
- const TRACE_ID_HEADER_NAME = "X-Amzn-Trace-Id";
3
- const ENV_LAMBDA_FUNCTION_NAME = "AWS_LAMBDA_FUNCTION_NAME";
4
- const ENV_TRACE_ID = "_X_AMZN_TRACE_ID";
5
- export const recursionDetectionMiddleware = (options) => (next) => async (args) => {
6
- const { request } = args;
7
- if (!HttpRequest.isInstance(request) || options.runtime !== "node") {
8
- return next(args);
9
- }
10
- const traceIdHeader = Object.keys(request.headers ?? {}).find((h) => h.toLowerCase() === TRACE_ID_HEADER_NAME.toLowerCase()) ??
11
- TRACE_ID_HEADER_NAME;
12
- if (request.headers.hasOwnProperty(traceIdHeader)) {
13
- return next(args);
14
- }
15
- const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
16
- const traceId = process.env[ENV_TRACE_ID];
17
- const nonEmptyString = (str) => typeof str === "string" && str.length > 0;
18
- if (nonEmptyString(functionName) && nonEmptyString(traceId)) {
19
- request.headers[TRACE_ID_HEADER_NAME] = traceId;
20
- }
21
- return next({
22
- ...args,
23
- request,
24
- });
25
- };
26
- export const addRecursionDetectionMiddlewareOptions = {
27
- step: "build",
28
- tags: ["RECURSION_DETECTION"],
29
- name: "recursionDetectionMiddleware",
30
- override: true,
31
- priority: "low",
32
- };
33
- export const getRecursionDetectionPlugin = (options) => ({
34
- applyToStack: (clientStack) => {
35
- clientStack.add(recursionDetectionMiddleware(options), addRecursionDetectionMiddlewareOptions);
36
- },
37
- });
1
+ export * from "./getRecursionDetectionPlugin";
2
+ export * from "./recursionDetectionMiddleware";
@@ -0,0 +1 @@
1
+ export const recursionDetectionMiddleware = () => (next) => async (args) => next(args);
@@ -0,0 +1,28 @@
1
+ import { InvokeStore } from "@aws/lambda-invoke-store";
2
+ import { HttpRequest } from "@smithy/protocol-http";
3
+ const TRACE_ID_HEADER_NAME = "X-Amzn-Trace-Id";
4
+ const ENV_LAMBDA_FUNCTION_NAME = "AWS_LAMBDA_FUNCTION_NAME";
5
+ const ENV_TRACE_ID = "_X_AMZN_TRACE_ID";
6
+ export const recursionDetectionMiddleware = () => (next) => async (args) => {
7
+ const { request } = args;
8
+ if (!HttpRequest.isInstance(request)) {
9
+ return next(args);
10
+ }
11
+ const traceIdHeader = Object.keys(request.headers ?? {}).find((h) => h.toLowerCase() === TRACE_ID_HEADER_NAME.toLowerCase()) ??
12
+ TRACE_ID_HEADER_NAME;
13
+ if (request.headers.hasOwnProperty(traceIdHeader)) {
14
+ return next(args);
15
+ }
16
+ const functionName = process.env[ENV_LAMBDA_FUNCTION_NAME];
17
+ const traceIdFromEnv = process.env[ENV_TRACE_ID];
18
+ const traceIdFromInvokeStore = InvokeStore.getXRayTraceId();
19
+ const traceId = traceIdFromInvokeStore ?? traceIdFromEnv;
20
+ const nonEmptyString = (str) => typeof str === "string" && str.length > 0;
21
+ if (nonEmptyString(functionName) && nonEmptyString(traceId)) {
22
+ request.headers[TRACE_ID_HEADER_NAME] = traceId;
23
+ }
24
+ return next({
25
+ ...args,
26
+ request,
27
+ });
28
+ };
@@ -0,0 +1 @@
1
+ export const recursionDetectionMiddleware = () => (next) => async (args) => next(args);
@@ -0,0 +1,5 @@
1
+ import { AbsoluteLocation, BuildHandlerOptions } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const recursionDetectionMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation;
@@ -0,0 +1,5 @@
1
+ import { Pluggable } from "@smithy/types";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const getRecursionDetectionPlugin: (options: any) => Pluggable<any, any>;
@@ -1,18 +1,2 @@
1
- import { AbsoluteLocation, BuildHandlerOptions, BuildMiddleware, Pluggable } from "@smithy/types";
2
- interface PreviouslyResolved {
3
- runtime: string;
4
- }
5
- /**
6
- * Inject to trace ID to request header to detect recursion invocation in Lambda.
7
- * @internal
8
- */
9
- export declare const recursionDetectionMiddleware: (options: PreviouslyResolved) => BuildMiddleware<any, any>;
10
- /**
11
- * @internal
12
- */
13
- export declare const addRecursionDetectionMiddlewareOptions: BuildHandlerOptions & AbsoluteLocation;
14
- /**
15
- * @internal
16
- */
17
- export declare const getRecursionDetectionPlugin: (options: PreviouslyResolved) => Pluggable<any, any>;
18
- export {};
1
+ export * from "./getRecursionDetectionPlugin";
2
+ export * from "./recursionDetectionMiddleware";
@@ -0,0 +1,6 @@
1
+ import { BuildMiddleware } from "@smithy/types";
2
+ /**
3
+ * No-op middleware for runtimes outside of Node.js
4
+ * @internal
5
+ */
6
+ export declare const recursionDetectionMiddleware: () => BuildMiddleware<any, any>;
@@ -0,0 +1,6 @@
1
+ import { BuildMiddleware } from "@smithy/types";
2
+ /**
3
+ * Inject to trace ID to request header to detect recursion invocation in Lambda.
4
+ * @internal
5
+ */
6
+ export declare const recursionDetectionMiddleware: () => BuildMiddleware<any, any>;
@@ -0,0 +1,6 @@
1
+ import { BuildMiddleware } from "@smithy/types";
2
+ /**
3
+ * No-op middleware for runtimes outside of Node.js
4
+ * @internal
5
+ */
6
+ export declare const recursionDetectionMiddleware: () => BuildMiddleware<any, any>;
@@ -0,0 +1,3 @@
1
+ import { AbsoluteLocation, BuildHandlerOptions } from "@smithy/types";
2
+ export declare const recursionDetectionMiddlewareOptions: BuildHandlerOptions &
3
+ AbsoluteLocation;
@@ -0,0 +1,4 @@
1
+ import { Pluggable } from "@smithy/types";
2
+ export declare const getRecursionDetectionPlugin: (
3
+ options: any
4
+ ) => Pluggable<any, any>;
@@ -1,18 +1,2 @@
1
- import {
2
- AbsoluteLocation,
3
- BuildHandlerOptions,
4
- BuildMiddleware,
5
- Pluggable,
6
- } from "@smithy/types";
7
- interface PreviouslyResolved {
8
- runtime: string;
9
- }
10
- export declare const recursionDetectionMiddleware: (
11
- options: PreviouslyResolved
12
- ) => BuildMiddleware<any, any>;
13
- export declare const addRecursionDetectionMiddlewareOptions: BuildHandlerOptions &
14
- AbsoluteLocation;
15
- export declare const getRecursionDetectionPlugin: (
16
- options: PreviouslyResolved
17
- ) => Pluggable<any, any>;
18
- export {};
1
+ export * from "./getRecursionDetectionPlugin";
2
+ export * from "./recursionDetectionMiddleware";
@@ -0,0 +1,5 @@
1
+ import { BuildMiddleware } from "@smithy/types";
2
+ export declare const recursionDetectionMiddleware: () => BuildMiddleware<
3
+ any,
4
+ any
5
+ >;
@@ -0,0 +1,5 @@
1
+ import { BuildMiddleware } from "@smithy/types";
2
+ export declare const recursionDetectionMiddleware: () => BuildMiddleware<
3
+ any,
4
+ any
5
+ >;
@@ -0,0 +1,5 @@
1
+ import { BuildMiddleware } from "@smithy/types";
2
+ export declare const recursionDetectionMiddleware: () => BuildMiddleware<
3
+ any,
4
+ any
5
+ >;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-recursion-detection",
3
- "version": "3.862.0",
3
+ "version": "3.886.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline middleware-recursion-detection",
@@ -10,9 +10,9 @@
10
10
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
11
11
  "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12
12
  "test": "yarn g:vitest run",
13
- "test:integration": "yarn g:vitest run -c vitest.config.integ.ts",
13
+ "test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
14
14
  "test:watch": "yarn g:vitest watch",
15
- "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.ts"
15
+ "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
16
16
  },
17
17
  "main": "./dist-cjs/index.js",
18
18
  "module": "./dist-es/index.js",
@@ -24,6 +24,7 @@
24
24
  "license": "Apache-2.0",
25
25
  "dependencies": {
26
26
  "@aws-sdk/types": "3.862.0",
27
+ "@aws/lambda-invoke-store": "^0.0.1",
27
28
  "@smithy/protocol-http": "^5.1.3",
28
29
  "@smithy/types": "^4.3.2",
29
30
  "tslib": "^2.6.2"
@@ -53,5 +54,9 @@
53
54
  "downlevel-dts": "0.10.1",
54
55
  "rimraf": "3.0.2",
55
56
  "typescript": "~5.8.3"
56
- }
57
+ },
58
+ "browser": {
59
+ "./dist-es/recursionDetectionMiddleware": "./dist-es/recursionDetectionMiddleware.browser"
60
+ },
61
+ "react-native": {}
57
62
  }