@rainbow-o23/n3 1.0.58 → 1.0.60

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/README.md CHANGED
@@ -601,6 +601,8 @@ step set. Additionally, nested transactions are also supported, which means Tran
601
601
  | `endpoints.SYSTEM.global.headers.transparent` | string | | Endpoint system global request transparent-passed headers names.<br>Format follows `name1[;name2[...]]`. |
602
602
  | `endpoints.SYSTEM.ENDPOINT.headers.transparent.omitted` | string | | Endpoint request headers names which omitted from transparent-passed headers, use global headers if this parameter doesn't present.<br>Format follows `name1[;name2[...]]`. |
603
603
  | `endpoints.SYSTEM.global.headers.transparent.omitted` | string | | Endpoint system global request headers names which omitted from transparent-passed headers.<br>Format follows `name1[;name2[...]]`. |
604
+ | `endpoints.SYSTEM.ENDPOINT.trace.header.name` | string | | Endpoint trace header name. |
605
+ | `endpoints.SYSTEM.global.trace.header.name` | string | | Endpoint system global trace header name. |
604
606
  | `endpoints.SYSTEM.ENDPOINT.timeout` | number | | Endpoint request timeout, in seconds, use global timeout if this parameter doesn't present. |
605
607
  | `endpoints.SYSTEM.global.timeout` | number | -1 | Endpoint system global timeout, in seconds, `-1` represents no timeout. |
606
608
 
@@ -632,7 +634,7 @@ CFG_ENDPOINTS_ORDER_PAYMENT_URL=https://order.com/payment
632
634
 
633
635
  - `transparentHeaderNames` and `omittedTransparentHeaderNames`:
634
636
  Use `transparentHeaderNames` to specify the names of request headers whose values need to be transparently passed from the input
635
- parameters to the downstream service. Separate the names with `;`. The names support using `.` for connection so that values from
637
+ parameters to the upstream service. Separate the names with `;`. The names support using `.` for connection so that values from
636
638
  multi-level objects can be directly retrieved. For example, `account.name` will retrieve the value of the `name` property from the
637
639
  `account` property of the input object. When writing the values into the header values, the following rules apply:
638
640
  - If the value is an array, use `, ` to connect the elements. `null` and empty strings will be filtered out.
@@ -653,23 +655,29 @@ CFG_ENDPOINTS_ORDER_PAYMENT_URL=https://order.com/payment
653
655
  For example:
654
656
  If the input data contains `{account: {name: 'John', token: '******'}}` and `transparentHeaderNames` is defined as `account`, then two
655
657
  transparently passed headers will be obtained: `name=John` and `token=******`. At this time, if `omittedTransparentHeaderNames` is defined
656
- as `name`, the headers that will be finally transparently passed to the downstream service are `token=******`, and `name` will be ignored.
658
+ as `name`, the headers that will be finally transparently passed to the upstream service are `token=******`, and `name` will be ignored.
657
659
 
658
660
  ## Request headers
659
661
 
660
- There are three ways to transmit request headers to downstream services. In order of priority from high to low, they are `headersGenerate`,
662
+ There are three ways to transmit request headers to upstream services. In order of priority from high to low, they are `headersGenerate`,
661
663
  `headers.transparent`, and `headers`. If a header appears in a higher-priority method, the header with the same name generated by a
662
664
  lower-priority method will be ignored. Note that the matching is case-sensitive.
663
665
 
664
- Normally, if you need to transparently pass the request headers from the client to the downstream service, you should use `headers: true` in
666
+ Normally, if you need to transparently pass the request headers from the client to the upstream service, you should use `headers: true` in
665
667
  the pipeline definition. Then you can directly use `transparentHeaderNames: headers` to obtain all the request headers, and then use
666
668
  `omittedTransparentHeaderNames` for necessary filtering.
667
669
 
668
- > It should be noted that since the fetch step initiates a new request to the downstream service, its request structure and data will be
670
+ > It should be noted that since the fetch step initiates a new request to the upstream service, its request structure and data will be
669
671
  > modified or reset according to requirements. Therefore, even if you need to transparently pass the request headers, some of the headers
670
672
  > are still not applicable. So by default, the two headers `content-encoding` and `content-length` will be filtered out. No matter how the
671
673
  > request headers are generated in the above process, these two headers are always automatically generated by `node-fetch`.
672
674
 
675
+ ### Tracing in upstream service groups
676
+
677
+ Use `endpoints.SYSTEM.ENDPOINT.trace.header.name` or `endpoints.SYSTEM.global.trace.header.name` to define the trace request header name for
678
+ the upstream system. The value will be attempted to be retrieved from the response and stored in the execution context to be passed to the
679
+ upstream system within the same `SYSTEM.ENDPOINT` or `SYSTEM`.
680
+
673
681
  ## Installation
674
682
 
675
683
  Note since `nestjs` only support commonjs module, which means `node-fetch` 3 series cannot be imported since it is built on esm mode.
package/index.cjs CHANGED
@@ -651,23 +651,19 @@ class AbstractFragmentaryPipelineStep extends n1.AbstractPipelineStep {
651
651
  }
652
652
  async setToOutput($result, $request) {
653
653
  const $helpers = this.getHelpers();
654
- return { content: await this._toResponseFunc($result, $request, $helpers, $helpers) };
654
+ return {
655
+ content: await this._toResponseFunc($result, $request, $helpers, $helpers),
656
+ $context: $request.$context
657
+ };
655
658
  }
656
659
  buildStepOptions() {
657
660
  return { config: this.getConfig(), logger: this.getLogger() };
658
661
  }
659
662
  createErrorHandleContext(request) {
660
- const context = request.$context;
661
- if (context == null) {
662
- return {};
663
- }
664
- else {
665
- const { authorization, traceId, ...rest } = context;
666
- return { authorization, traceId, ...Utils.clone(rest) };
667
- }
663
+ return request.$context;
668
664
  }
669
665
  async handleErrorSteps(fragment, errorCode, error, request, builders) {
670
- const { $context: { authorization, traceId } = {} } = request;
666
+ const traceId = request.$context.traceId;
671
667
  const errorContext = this.createErrorHandleContext(request);
672
668
  const options = this.buildStepOptions();
673
669
  const steps = await Promise.all(builders.map(async (builder) => await builder.create(options)));
@@ -677,7 +673,7 @@ class AbstractFragmentaryPipelineStep extends n1.AbstractPipelineStep {
677
673
  .execute(async () => {
678
674
  this.traceStepIn(traceId, step, request);
679
675
  const response = await step.perform({
680
- ...request, $context: { ...errorContext, authorization, traceId }
676
+ ...request, $context: errorContext
681
677
  });
682
678
  this.traceStepOut(traceId, step, response);
683
679
  return this.returnOrContinueOrClear(request, response);
@@ -773,14 +769,7 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
773
769
  return await Promise.all(this.getStepBuilders().map(async (builder) => await builder.create(options)));
774
770
  }
775
771
  inheritContext(request) {
776
- const context = request.$context;
777
- if (context == null) {
778
- return {};
779
- }
780
- else {
781
- const { authorization, traceId, ...rest } = context;
782
- return { authorization, traceId, ...Utils.clone(rest) };
783
- }
772
+ return request.$context;
784
773
  }
785
774
  async attachMineToInternalContext(inheritedContext, _request) {
786
775
  return inheritedContext;
@@ -794,7 +783,7 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
794
783
  }
795
784
  async doPerform(data, request) {
796
785
  return await this.performWithContext(request, async (request, context) => {
797
- const { $context: { authorization, traceId } = {} } = request;
786
+ const traceId = context.traceId;
798
787
  const steps = await this.createSteps();
799
788
  const response = await steps.reduce(async (promise, step) => {
800
789
  const request = await promise;
@@ -802,7 +791,7 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
802
791
  .execute(async () => {
803
792
  this.traceStepIn(traceId, step, request);
804
793
  const response = await step.perform({
805
- ...request, $context: { ...context, authorization, traceId }
794
+ ...request, $context: context
806
795
  });
807
796
  this.traceStepOut(traceId, step, response);
808
797
  return this.returnOrContinueOrClear(request, response);
@@ -814,6 +803,9 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
814
803
  }
815
804
 
816
805
  class AsyncPipelineStepSets extends PipelineStepSets {
806
+ inheritContext(request) {
807
+ return request.$context.clone('$trans');
808
+ }
817
809
  async doPerform(data, request) {
818
810
  super.doPerform(data, request);
819
811
  return;
@@ -854,14 +846,14 @@ class ParallelPipelineStepSets extends PipelineStepSets {
854
846
  }
855
847
  async doPerform(data, request) {
856
848
  return await this.performWithContext(request, async (request, context) => {
857
- const { $context: { authorization, traceId } = {} } = request;
849
+ const traceId = context.traceId;
858
850
  const steps = await this.createSteps();
859
851
  const execute = () => {
860
852
  return steps.map(async (step) => {
861
853
  return await this.measurePerformance(traceId, 'STEP', step.constructor.name)
862
854
  .execute(async () => {
863
855
  const eachData = await this.cloneDataForEach(data, request);
864
- const eachRequest = { content: eachData, $context: { ...context, authorization, traceId } };
856
+ const eachRequest = { content: eachData, $context: context };
865
857
  this.traceStepIn(traceId, step, request);
866
858
  const response = await step.perform(eachRequest);
867
859
  this.traceStepOut(traceId, step, response);
@@ -1226,9 +1218,8 @@ class RefPipelinePipelineStep extends AbstractFragmentaryPipelineStep {
1226
1218
  return { config: this.getConfig(), logger: this.getLogger() };
1227
1219
  }
1228
1220
  async doPerform(data, request) {
1229
- const { $context: { authorization, traceId } = {} } = request;
1230
1221
  const pipeline = await this.getPipelineBuilder().create(this.buildPipelineOptions());
1231
- const result = await pipeline.perform({ payload: data, authorization, traceId });
1222
+ const result = await pipeline.perform({ payload: data, $context: request.$context });
1232
1223
  return result.payload;
1233
1224
  }
1234
1225
  }
@@ -1275,6 +1266,7 @@ const HttpAbortErrorCode = '600';
1275
1266
  class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1276
1267
  _endpointSystemCode;
1277
1268
  _endpointName;
1269
+ _endpointKey;
1278
1270
  _endpointUrl;
1279
1271
  _endpointMethod;
1280
1272
  _endpointHeaders;
@@ -1285,6 +1277,8 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1285
1277
  _omittedTransparentHeaderNames;
1286
1278
  _headersGenerateSnippet;
1287
1279
  _headersGenerateFunc;
1280
+ _endpointTraceIdHeaderName;
1281
+ _endpointTraceIdScope;
1288
1282
  _bodyUsed;
1289
1283
  _bodyGenerateSnippet;
1290
1284
  _bodyGenerateFunc;
@@ -1296,13 +1290,13 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1296
1290
  const config = this.getConfig();
1297
1291
  this._endpointSystemCode = options.endpointSystemCode;
1298
1292
  this._endpointName = options.endpointName;
1299
- const endpointKey = this.getEndpointKey();
1300
- this._endpointUrl = config.getString(`endpoints.${endpointKey}.url`);
1293
+ this._endpointKey = `${this._endpointSystemCode}.${this._endpointName}`;
1294
+ this._endpointUrl = config.getString(`endpoints.${this._endpointKey}.url`);
1301
1295
  this._endpointMethod = (options.method ?? 'POST').trim().toLowerCase();
1302
- this._endpointHeaders = this.generateEndpointHeaders(config.getString(`endpoints.${endpointKey}.headers`), this.generateEndpointHeaders(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers`)));
1296
+ this._endpointHeaders = this.generateEndpointHeaders(config.getString(`endpoints.${this._endpointKey}.headers`), this.generateEndpointHeaders(config.getString(`endpoints.${this._endpointSystemCode}.global.headers`)));
1303
1297
  this._endpointTimeout = options.timeout
1304
- ?? config.getNumber(`endpoints.${endpointKey}.timeout`)
1305
- ?? config.getNumber(`endpoints.${this.getEndpointSystemCode()}.global.timeout`, -1);
1298
+ ?? config.getNumber(`endpoints.${this._endpointKey}.timeout`)
1299
+ ?? config.getNumber(`endpoints.${this._endpointSystemCode}.global.timeout`, -1);
1306
1300
  this._endpointTimeout = this._endpointTimeout > 0 ? this._endpointTimeout * 1000 : -1;
1307
1301
  this._urlGenerateSnippet = options.urlGenerate;
1308
1302
  this._urlGenerateFunc = Utils.createAsyncFunction(this.getUrlGenerateSnippet(), {
@@ -1314,9 +1308,9 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1314
1308
  }
1315
1309
  });
1316
1310
  this._transparentHeaderNames = options.transparentHeaderNames
1317
- ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${endpointKey}.headers.transparent`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers.transparent`)));
1311
+ ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointKey}.headers.transparent`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointSystemCode}.global.headers.transparent`)));
1318
1312
  this._omittedTransparentHeaderNames = options.omittedTransparentHeaderNames
1319
- ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${endpointKey}.headers.transparent.omitted`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers.transparent.omitted`)));
1313
+ ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointKey}.headers.transparent.omitted`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointSystemCode}.global.headers.transparent.omitted`)));
1320
1314
  this._headersGenerateSnippet = options.headersGenerate;
1321
1315
  this._headersGenerateFunc = Utils.createAsyncFunction(this.getHeadersGenerateSnippet(), {
1322
1316
  createDefault: () => async (_$factor, _$request, _$helpers, _$) => (void 0),
@@ -1326,6 +1320,22 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1326
1320
  throw e;
1327
1321
  }
1328
1322
  });
1323
+ let traceIdHeaderName = config.getString(`endpoints.${this._endpointKey}.trace.header.name`)?.trim();
1324
+ if (traceIdHeaderName != null) {
1325
+ this._endpointTraceIdHeaderName = traceIdHeaderName.toLowerCase();
1326
+ this._endpointTraceIdScope = 'endpoint';
1327
+ }
1328
+ else {
1329
+ traceIdHeaderName = config.getString(`endpoints.${this._endpointSystemCode}.global.trace.header.name`)?.trim();
1330
+ if (traceIdHeaderName != null) {
1331
+ this._endpointTraceIdHeaderName = traceIdHeaderName.toLowerCase();
1332
+ this._endpointTraceIdScope = 'system';
1333
+ }
1334
+ else {
1335
+ this._endpointTraceIdHeaderName = (void 0);
1336
+ this._endpointTraceIdScope = (void 0);
1337
+ }
1338
+ }
1329
1339
  this._bodyUsed = options.bodyUsed;
1330
1340
  this._bodyGenerateSnippet = options.bodyGenerate;
1331
1341
  this._bodyGenerateFunc = Utils.createAsyncFunction(this.getBodyGenerateSnippet(), {
@@ -1405,7 +1415,7 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1405
1415
  return this._endpointName;
1406
1416
  }
1407
1417
  getEndpointKey() {
1408
- return `${this.getEndpointSystemCode()}.${this.getEndpointName()}`;
1418
+ return this._endpointKey;
1409
1419
  }
1410
1420
  getEndpointUrl() {
1411
1421
  return this._endpointUrl;
@@ -1460,6 +1470,12 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1460
1470
  getHeadersGenerateVariableNames() {
1461
1471
  return ['$factor', '$request', ...this.getHelpersVariableNames()];
1462
1472
  }
1473
+ getEndpointTraceIdHeaderName() {
1474
+ return this._endpointTraceIdHeaderName;
1475
+ }
1476
+ getEndpointTraceIdScope() {
1477
+ return this._endpointTraceIdScope;
1478
+ }
1463
1479
  isBodyUsed() {
1464
1480
  return this._bodyUsed;
1465
1481
  }
@@ -1478,79 +1494,141 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1478
1494
  getErrorHandlerVariableName() {
1479
1495
  return ['$options', ...this.getHelpersVariableNames()];
1480
1496
  }
1481
- async doPerform(data, request) {
1482
- const $helpers = this.getHelpers();
1483
- let url = '';
1484
- try {
1485
- url = await this._urlGenerateFunc(this.getEndpointUrl(), data, request, $helpers, $helpers);
1486
- const method = this.getEndpointMethod();
1487
- const staticHeaders = this.getEndpointHeaders() ?? {};
1488
- const transparentHeaders = (this.getTransparentHeaderNames() ?? []).reduce((headers, name) => {
1489
- const value = Utils.getValue(data, name);
1490
- if (value == null) {
1491
- }
1492
- else if (Array.isArray(value)) {
1493
- const headerValue = value.filter(v => v != null && `${v}`.length !== 0).join(', ');
1494
- if (headerValue.length !== 0) {
1495
- headers[name] = headerValue;
1496
- }
1497
- }
1498
- else if (typeof value === 'object') {
1499
- Object.keys(value).forEach(key => {
1500
- const headerValue = value[key];
1501
- if (headerValue != null) {
1502
- const s = `${headerValue}`;
1503
- if (s.length !== 0) {
1504
- headers[key] = s;
1505
- }
1506
- }
1507
- });
1508
- }
1509
- else {
1510
- const headerValue = `${value}`;
1511
- if (headerValue.length !== 0) {
1512
- headers[name] = headerValue;
1513
- }
1514
- }
1515
- return headers;
1516
- }, {});
1517
- (this.getOmittedTransparentHeaderNames() ?? []).forEach(name => delete transparentHeaders[name]);
1518
- const generatedHeaders = await this._headersGenerateFunc(data, request, $helpers, $helpers) ?? {};
1519
- let body;
1520
- const bodyUsed = this.isBodyUsed();
1521
- if (bodyUsed === true || (bodyUsed == null && method !== 'get')) {
1522
- body = await this._bodyGenerateFunc(data, request, $helpers, $helpers);
1497
+ syncEndpointTraceId(headers, request) {
1498
+ const endpointTraceIdHeaderName = this.getEndpointTraceIdHeaderName();
1499
+ if (endpointTraceIdHeaderName == null) {
1500
+ return (void 0);
1501
+ }
1502
+ const headerName = Object.keys(headers).find(name => name.toLowerCase() === endpointTraceIdHeaderName);
1503
+ if (headerName != null) {
1504
+ return (void 0);
1505
+ }
1506
+ let endpointTraceId = headers[headerName];
1507
+ const endpointTraceIdScope = this.getEndpointTraceIdScope();
1508
+ if (endpointTraceId != null) {
1509
+ if (endpointTraceIdScope === 'system') {
1510
+ request.$context.setScopedTraceId(this.getEndpointSystemCode(), endpointTraceIdHeaderName, endpointTraceId);
1523
1511
  }
1524
1512
  else {
1525
- body = (void 0);
1513
+ request.$context.setScopedTraceId(this.getEndpointKey(), endpointTraceIdHeaderName, endpointTraceId);
1526
1514
  }
1527
- if (body != null && typeof body !== 'string') {
1528
- body = JSON.stringify(body);
1515
+ }
1516
+ else {
1517
+ if (endpointTraceIdScope === 'system') {
1518
+ endpointTraceId = request.$context.findScopedTraceId(this.getEndpointSystemCode())?.[1];
1529
1519
  }
1530
- const headers = { ...staticHeaders, ...transparentHeaders, ...generatedHeaders };
1531
- Object.keys(headers).filter(name => {
1532
- return ['content-encoding', 'content-length'].includes(name.toLowerCase());
1533
- }).forEach(name => {
1534
- delete headers[name];
1535
- });
1536
- const response = await fetch(url, {
1537
- method, headers, body,
1538
- signal: this.needTimeout() ? (() => {
1539
- const controller = new AbortController();
1540
- setTimeout(() => controller.abort(), this.getEndpointTimeout());
1541
- return controller.signal;
1542
- })() : (void 0)
1543
- });
1544
- const status = response.status;
1545
- if (status >= 400) {
1546
- return await this._responseErrorHandleFunc({
1547
- $url: url, $factor: data, $request: request, $response: response,
1548
- $errorCode: `${status}`
1549
- }, $helpers, $helpers);
1520
+ else {
1521
+ endpointTraceId = request.$context.findScopedTraceId(this.getEndpointKey())?.[1];
1522
+ }
1523
+ if (endpointTraceId != null) {
1524
+ headers[endpointTraceIdHeaderName] = endpointTraceId;
1525
+ }
1526
+ }
1527
+ return endpointTraceId;
1528
+ }
1529
+ async generateRequestHeaders(data, request, $helpers) {
1530
+ const staticHeaders = this.getEndpointHeaders() ?? {};
1531
+ const transparentHeaders = (this.getTransparentHeaderNames() ?? []).reduce((headers, name) => {
1532
+ const value = Utils.getValue(data, name);
1533
+ if (value == null) ;
1534
+ else if (Array.isArray(value)) {
1535
+ const headerValue = value.filter(v => v != null && `${v}`.length !== 0).join(', ');
1536
+ if (headerValue.length !== 0) {
1537
+ headers[name] = headerValue;
1538
+ }
1539
+ }
1540
+ else if (typeof value === 'object') {
1541
+ Object.keys(value).forEach(key => {
1542
+ const headerValue = value[key];
1543
+ if (headerValue != null) {
1544
+ const s = `${headerValue}`;
1545
+ if (s.length !== 0) {
1546
+ headers[key] = s;
1547
+ }
1548
+ }
1549
+ });
1550
1550
  }
1551
1551
  else {
1552
- return await this._responseGenerateFunc(response, data, request, $helpers, $helpers);
1552
+ const headerValue = `${value}`;
1553
+ if (headerValue.length !== 0) {
1554
+ headers[name] = headerValue;
1555
+ }
1553
1556
  }
1557
+ return headers;
1558
+ }, {});
1559
+ (this.getOmittedTransparentHeaderNames() ?? []).forEach(name => delete transparentHeaders[name]);
1560
+ const generatedHeaders = await this._headersGenerateFunc(data, request, $helpers, $helpers) ?? {};
1561
+ const headers = { ...staticHeaders, ...transparentHeaders, ...generatedHeaders };
1562
+ Object.keys(headers).filter(name => {
1563
+ return ['content-encoding', 'content-length'].includes(name.toLowerCase());
1564
+ }).forEach(name => {
1565
+ delete headers[name];
1566
+ });
1567
+ return headers;
1568
+ }
1569
+ async generateRequestBody(method, data, request, $helpers) {
1570
+ let body;
1571
+ const bodyUsed = this.isBodyUsed();
1572
+ if (bodyUsed === true || (bodyUsed == null && method !== 'get')) {
1573
+ body = await this._bodyGenerateFunc(data, request, $helpers, $helpers);
1574
+ }
1575
+ else {
1576
+ body = (void 0);
1577
+ }
1578
+ if (body != null && typeof body !== 'string') {
1579
+ body = JSON.stringify(body);
1580
+ }
1581
+ return body;
1582
+ }
1583
+ tryToRetrieveTraceIdFromResponse(request, response) {
1584
+ const endpointTraceIdHeaderName = this.getEndpointTraceIdHeaderName();
1585
+ if (endpointTraceIdHeaderName == null) {
1586
+ return (void 0);
1587
+ }
1588
+ const endpointTraceId = response.headers.get(endpointTraceIdHeaderName);
1589
+ if (endpointTraceId == null || endpointTraceId.length === 0) {
1590
+ return (void 0);
1591
+ }
1592
+ const endpointTraceIdScope = this.getEndpointTraceIdScope();
1593
+ if (endpointTraceIdScope === 'system') {
1594
+ request.$context.setScopedTraceId(this.getEndpointSystemCode(), endpointTraceIdHeaderName, endpointTraceId);
1595
+ }
1596
+ else {
1597
+ request.$context.setScopedTraceId(this.getEndpointKey(), endpointTraceIdHeaderName, endpointTraceId);
1598
+ }
1599
+ return endpointTraceId;
1600
+ }
1601
+ async sendRequest(url, method, headers, body, data, request, $helpers) {
1602
+ const response = await fetch(url, {
1603
+ method, headers, body,
1604
+ signal: this.needTimeout() ? (() => {
1605
+ const controller = new AbortController();
1606
+ setTimeout(() => controller.abort(), this.getEndpointTimeout());
1607
+ return controller.signal;
1608
+ })() : (void 0)
1609
+ });
1610
+ this.tryToRetrieveTraceIdFromResponse(request, response);
1611
+ const status = response.status;
1612
+ if (status >= 400) {
1613
+ return await this._responseErrorHandleFunc({
1614
+ $url: url, $factor: data, $request: request, $response: response,
1615
+ $errorCode: `${status}`
1616
+ }, $helpers, $helpers);
1617
+ }
1618
+ else {
1619
+ return await this._responseGenerateFunc(response, data, request, $helpers, $helpers);
1620
+ }
1621
+ }
1622
+ async doPerform(data, request) {
1623
+ const $helpers = this.getHelpers();
1624
+ let url = '';
1625
+ try {
1626
+ url = await this._urlGenerateFunc(this.getEndpointUrl(), data, request, $helpers, $helpers);
1627
+ const method = this.getEndpointMethod();
1628
+ const headers = await this.generateRequestHeaders(data, request, $helpers);
1629
+ this.syncEndpointTraceId(headers, request);
1630
+ const body = await this.generateRequestBody(method, data, request, $helpers);
1631
+ return await this.sendRequest(url, method, headers, body, data, request, $helpers);
1554
1632
  }
1555
1633
  catch (e) {
1556
1634
  if (e instanceof DOMException || e.name === 'AbortError') {
@@ -2340,7 +2418,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2340
2418
  ...this.buildStepOptions(), name: this.getName(), steps: this.getStepBuilders()
2341
2419
  });
2342
2420
  const { content: _, $context, ...rest } = request;
2343
- const contextForSub = { ...$context, $typeOrmCursorRound: cursorRound, $typeOrmCursorEnd: end };
2421
+ const contextForSub = $context.temporaryWith({
2422
+ $typeOrmCursorRound: cursorRound, $typeOrmCursorEnd: end
2423
+ });
2344
2424
  const requestForSub = { ...rest, $context: contextForSub, content: contentForSub };
2345
2425
  const result = await sets.perform(requestForSub);
2346
2426
  const { content } = result;