@rainbow-o23/n3 1.0.58 → 1.0.59

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/index.js CHANGED
@@ -649,23 +649,19 @@ class AbstractFragmentaryPipelineStep extends AbstractPipelineStep {
649
649
  }
650
650
  async setToOutput($result, $request) {
651
651
  const $helpers = this.getHelpers();
652
- return { content: await this._toResponseFunc($result, $request, $helpers, $helpers) };
652
+ return {
653
+ content: await this._toResponseFunc($result, $request, $helpers, $helpers),
654
+ $context: $request.$context
655
+ };
653
656
  }
654
657
  buildStepOptions() {
655
658
  return { config: this.getConfig(), logger: this.getLogger() };
656
659
  }
657
660
  createErrorHandleContext(request) {
658
- const context = request.$context;
659
- if (context == null) {
660
- return {};
661
- }
662
- else {
663
- const { authorization, traceId, ...rest } = context;
664
- return { authorization, traceId, ...Utils.clone(rest) };
665
- }
661
+ return request.$context;
666
662
  }
667
663
  async handleErrorSteps(fragment, errorCode, error, request, builders) {
668
- const { $context: { authorization, traceId } = {} } = request;
664
+ const traceId = request.$context.traceId;
669
665
  const errorContext = this.createErrorHandleContext(request);
670
666
  const options = this.buildStepOptions();
671
667
  const steps = await Promise.all(builders.map(async (builder) => await builder.create(options)));
@@ -675,7 +671,7 @@ class AbstractFragmentaryPipelineStep extends AbstractPipelineStep {
675
671
  .execute(async () => {
676
672
  this.traceStepIn(traceId, step, request);
677
673
  const response = await step.perform({
678
- ...request, $context: { ...errorContext, authorization, traceId }
674
+ ...request, $context: errorContext
679
675
  });
680
676
  this.traceStepOut(traceId, step, response);
681
677
  return this.returnOrContinueOrClear(request, response);
@@ -771,14 +767,7 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
771
767
  return await Promise.all(this.getStepBuilders().map(async (builder) => await builder.create(options)));
772
768
  }
773
769
  inheritContext(request) {
774
- const context = request.$context;
775
- if (context == null) {
776
- return {};
777
- }
778
- else {
779
- const { authorization, traceId, ...rest } = context;
780
- return { authorization, traceId, ...Utils.clone(rest) };
781
- }
770
+ return request.$context;
782
771
  }
783
772
  async attachMineToInternalContext(inheritedContext, _request) {
784
773
  return inheritedContext;
@@ -792,7 +781,7 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
792
781
  }
793
782
  async doPerform(data, request) {
794
783
  return await this.performWithContext(request, async (request, context) => {
795
- const { $context: { authorization, traceId } = {} } = request;
784
+ const traceId = context.traceId;
796
785
  const steps = await this.createSteps();
797
786
  const response = await steps.reduce(async (promise, step) => {
798
787
  const request = await promise;
@@ -800,7 +789,7 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
800
789
  .execute(async () => {
801
790
  this.traceStepIn(traceId, step, request);
802
791
  const response = await step.perform({
803
- ...request, $context: { ...context, authorization, traceId }
792
+ ...request, $context: context
804
793
  });
805
794
  this.traceStepOut(traceId, step, response);
806
795
  return this.returnOrContinueOrClear(request, response);
@@ -812,6 +801,9 @@ class PipelineStepSets extends AbstractFragmentaryPipelineStep {
812
801
  }
813
802
 
814
803
  class AsyncPipelineStepSets extends PipelineStepSets {
804
+ inheritContext(request) {
805
+ return request.$context.clone('$trans');
806
+ }
815
807
  async doPerform(data, request) {
816
808
  super.doPerform(data, request);
817
809
  return;
@@ -852,14 +844,14 @@ class ParallelPipelineStepSets extends PipelineStepSets {
852
844
  }
853
845
  async doPerform(data, request) {
854
846
  return await this.performWithContext(request, async (request, context) => {
855
- const { $context: { authorization, traceId } = {} } = request;
847
+ const traceId = context.traceId;
856
848
  const steps = await this.createSteps();
857
849
  const execute = () => {
858
850
  return steps.map(async (step) => {
859
851
  return await this.measurePerformance(traceId, 'STEP', step.constructor.name)
860
852
  .execute(async () => {
861
853
  const eachData = await this.cloneDataForEach(data, request);
862
- const eachRequest = { content: eachData, $context: { ...context, authorization, traceId } };
854
+ const eachRequest = { content: eachData, $context: context };
863
855
  this.traceStepIn(traceId, step, request);
864
856
  const response = await step.perform(eachRequest);
865
857
  this.traceStepOut(traceId, step, response);
@@ -1224,9 +1216,8 @@ class RefPipelinePipelineStep extends AbstractFragmentaryPipelineStep {
1224
1216
  return { config: this.getConfig(), logger: this.getLogger() };
1225
1217
  }
1226
1218
  async doPerform(data, request) {
1227
- const { $context: { authorization, traceId } = {} } = request;
1228
1219
  const pipeline = await this.getPipelineBuilder().create(this.buildPipelineOptions());
1229
- const result = await pipeline.perform({ payload: data, authorization, traceId });
1220
+ const result = await pipeline.perform({ payload: data, $context: request.$context });
1230
1221
  return result.payload;
1231
1222
  }
1232
1223
  }
@@ -1273,6 +1264,7 @@ const HttpAbortErrorCode = '600';
1273
1264
  class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1274
1265
  _endpointSystemCode;
1275
1266
  _endpointName;
1267
+ _endpointKey;
1276
1268
  _endpointUrl;
1277
1269
  _endpointMethod;
1278
1270
  _endpointHeaders;
@@ -1283,6 +1275,8 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1283
1275
  _omittedTransparentHeaderNames;
1284
1276
  _headersGenerateSnippet;
1285
1277
  _headersGenerateFunc;
1278
+ _endpointTraceIdHeaderName;
1279
+ _endpointTraceIdScope;
1286
1280
  _bodyUsed;
1287
1281
  _bodyGenerateSnippet;
1288
1282
  _bodyGenerateFunc;
@@ -1294,13 +1288,13 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1294
1288
  const config = this.getConfig();
1295
1289
  this._endpointSystemCode = options.endpointSystemCode;
1296
1290
  this._endpointName = options.endpointName;
1297
- const endpointKey = this.getEndpointKey();
1298
- this._endpointUrl = config.getString(`endpoints.${endpointKey}.url`);
1291
+ this._endpointKey = `${this._endpointSystemCode}.${this._endpointName}`;
1292
+ this._endpointUrl = config.getString(`endpoints.${this._endpointKey}.url`);
1299
1293
  this._endpointMethod = (options.method ?? 'POST').trim().toLowerCase();
1300
- this._endpointHeaders = this.generateEndpointHeaders(config.getString(`endpoints.${endpointKey}.headers`), this.generateEndpointHeaders(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers`)));
1294
+ this._endpointHeaders = this.generateEndpointHeaders(config.getString(`endpoints.${this._endpointKey}.headers`), this.generateEndpointHeaders(config.getString(`endpoints.${this._endpointSystemCode}.global.headers`)));
1301
1295
  this._endpointTimeout = options.timeout
1302
- ?? config.getNumber(`endpoints.${endpointKey}.timeout`)
1303
- ?? config.getNumber(`endpoints.${this.getEndpointSystemCode()}.global.timeout`, -1);
1296
+ ?? config.getNumber(`endpoints.${this._endpointKey}.timeout`)
1297
+ ?? config.getNumber(`endpoints.${this._endpointSystemCode}.global.timeout`, -1);
1304
1298
  this._endpointTimeout = this._endpointTimeout > 0 ? this._endpointTimeout * 1000 : -1;
1305
1299
  this._urlGenerateSnippet = options.urlGenerate;
1306
1300
  this._urlGenerateFunc = Utils.createAsyncFunction(this.getUrlGenerateSnippet(), {
@@ -1312,9 +1306,9 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1312
1306
  }
1313
1307
  });
1314
1308
  this._transparentHeaderNames = options.transparentHeaderNames
1315
- ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${endpointKey}.headers.transparent`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers.transparent`)));
1309
+ ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointKey}.headers.transparent`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointSystemCode}.global.headers.transparent`)));
1316
1310
  this._omittedTransparentHeaderNames = options.omittedTransparentHeaderNames
1317
- ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${endpointKey}.headers.transparent.omitted`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this.getEndpointSystemCode()}.global.headers.transparent.omitted`)));
1311
+ ?? this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointKey}.headers.transparent.omitted`), this.generateTransparentHeaderNames(config.getString(`endpoints.${this._endpointSystemCode}.global.headers.transparent.omitted`)));
1318
1312
  this._headersGenerateSnippet = options.headersGenerate;
1319
1313
  this._headersGenerateFunc = Utils.createAsyncFunction(this.getHeadersGenerateSnippet(), {
1320
1314
  createDefault: () => async (_$factor, _$request, _$helpers, _$) => (void 0),
@@ -1324,6 +1318,22 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1324
1318
  throw e;
1325
1319
  }
1326
1320
  });
1321
+ let traceIdHeaderName = config.getString(`endpoints.${this._endpointKey}.trace.header.name`)?.trim();
1322
+ if (traceIdHeaderName != null) {
1323
+ this._endpointTraceIdHeaderName = traceIdHeaderName.toLowerCase();
1324
+ this._endpointTraceIdScope = 'endpoint';
1325
+ }
1326
+ else {
1327
+ traceIdHeaderName = config.getString(`endpoints.${this._endpointSystemCode}.global.trace.header.name`)?.trim();
1328
+ if (traceIdHeaderName != null) {
1329
+ this._endpointTraceIdHeaderName = traceIdHeaderName.toLowerCase();
1330
+ this._endpointTraceIdScope = 'system';
1331
+ }
1332
+ else {
1333
+ this._endpointTraceIdHeaderName = (void 0);
1334
+ this._endpointTraceIdScope = (void 0);
1335
+ }
1336
+ }
1327
1337
  this._bodyUsed = options.bodyUsed;
1328
1338
  this._bodyGenerateSnippet = options.bodyGenerate;
1329
1339
  this._bodyGenerateFunc = Utils.createAsyncFunction(this.getBodyGenerateSnippet(), {
@@ -1403,7 +1413,7 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1403
1413
  return this._endpointName;
1404
1414
  }
1405
1415
  getEndpointKey() {
1406
- return `${this.getEndpointSystemCode()}.${this.getEndpointName()}`;
1416
+ return this._endpointKey;
1407
1417
  }
1408
1418
  getEndpointUrl() {
1409
1419
  return this._endpointUrl;
@@ -1458,6 +1468,12 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1458
1468
  getHeadersGenerateVariableNames() {
1459
1469
  return ['$factor', '$request', ...this.getHelpersVariableNames()];
1460
1470
  }
1471
+ getEndpointTraceIdHeaderName() {
1472
+ return this._endpointTraceIdHeaderName;
1473
+ }
1474
+ getEndpointTraceIdScope() {
1475
+ return this._endpointTraceIdScope;
1476
+ }
1461
1477
  isBodyUsed() {
1462
1478
  return this._bodyUsed;
1463
1479
  }
@@ -1476,79 +1492,141 @@ class FetchPipelineStep extends AbstractFragmentaryPipelineStep {
1476
1492
  getErrorHandlerVariableName() {
1477
1493
  return ['$options', ...this.getHelpersVariableNames()];
1478
1494
  }
1479
- async doPerform(data, request) {
1480
- const $helpers = this.getHelpers();
1481
- let url = '';
1482
- try {
1483
- url = await this._urlGenerateFunc(this.getEndpointUrl(), data, request, $helpers, $helpers);
1484
- const method = this.getEndpointMethod();
1485
- const staticHeaders = this.getEndpointHeaders() ?? {};
1486
- const transparentHeaders = (this.getTransparentHeaderNames() ?? []).reduce((headers, name) => {
1487
- const value = Utils.getValue(data, name);
1488
- if (value == null) {
1489
- }
1490
- else if (Array.isArray(value)) {
1491
- const headerValue = value.filter(v => v != null && `${v}`.length !== 0).join(', ');
1492
- if (headerValue.length !== 0) {
1493
- headers[name] = headerValue;
1494
- }
1495
- }
1496
- else if (typeof value === 'object') {
1497
- Object.keys(value).forEach(key => {
1498
- const headerValue = value[key];
1499
- if (headerValue != null) {
1500
- const s = `${headerValue}`;
1501
- if (s.length !== 0) {
1502
- headers[key] = s;
1503
- }
1504
- }
1505
- });
1506
- }
1507
- else {
1508
- const headerValue = `${value}`;
1509
- if (headerValue.length !== 0) {
1510
- headers[name] = headerValue;
1511
- }
1512
- }
1513
- return headers;
1514
- }, {});
1515
- (this.getOmittedTransparentHeaderNames() ?? []).forEach(name => delete transparentHeaders[name]);
1516
- const generatedHeaders = await this._headersGenerateFunc(data, request, $helpers, $helpers) ?? {};
1517
- let body;
1518
- const bodyUsed = this.isBodyUsed();
1519
- if (bodyUsed === true || (bodyUsed == null && method !== 'get')) {
1520
- body = await this._bodyGenerateFunc(data, request, $helpers, $helpers);
1495
+ syncEndpointTraceId(headers, request) {
1496
+ const endpointTraceIdHeaderName = this.getEndpointTraceIdHeaderName();
1497
+ if (endpointTraceIdHeaderName == null) {
1498
+ return (void 0);
1499
+ }
1500
+ const headerName = Object.keys(headers).find(name => name.toLowerCase() === endpointTraceIdHeaderName);
1501
+ if (headerName != null) {
1502
+ return (void 0);
1503
+ }
1504
+ let endpointTraceId = headers[headerName];
1505
+ const endpointTraceIdScope = this.getEndpointTraceIdScope();
1506
+ if (endpointTraceId != null) {
1507
+ if (endpointTraceIdScope === 'system') {
1508
+ request.$context.setScopedTraceId(this.getEndpointSystemCode(), endpointTraceIdHeaderName, endpointTraceId);
1521
1509
  }
1522
1510
  else {
1523
- body = (void 0);
1511
+ request.$context.setScopedTraceId(this.getEndpointKey(), endpointTraceIdHeaderName, endpointTraceId);
1524
1512
  }
1525
- if (body != null && typeof body !== 'string') {
1526
- body = JSON.stringify(body);
1513
+ }
1514
+ else {
1515
+ if (endpointTraceIdScope === 'system') {
1516
+ endpointTraceId = request.$context.findScopedTraceId(this.getEndpointSystemCode())?.[1];
1527
1517
  }
1528
- const headers = { ...staticHeaders, ...transparentHeaders, ...generatedHeaders };
1529
- Object.keys(headers).filter(name => {
1530
- return ['content-encoding', 'content-length'].includes(name.toLowerCase());
1531
- }).forEach(name => {
1532
- delete headers[name];
1533
- });
1534
- const response = await fetch(url, {
1535
- method, headers, body,
1536
- signal: this.needTimeout() ? (() => {
1537
- const controller = new AbortController();
1538
- setTimeout(() => controller.abort(), this.getEndpointTimeout());
1539
- return controller.signal;
1540
- })() : (void 0)
1541
- });
1542
- const status = response.status;
1543
- if (status >= 400) {
1544
- return await this._responseErrorHandleFunc({
1545
- $url: url, $factor: data, $request: request, $response: response,
1546
- $errorCode: `${status}`
1547
- }, $helpers, $helpers);
1518
+ else {
1519
+ endpointTraceId = request.$context.findScopedTraceId(this.getEndpointKey())?.[1];
1520
+ }
1521
+ if (endpointTraceId != null) {
1522
+ headers[endpointTraceIdHeaderName] = endpointTraceId;
1523
+ }
1524
+ }
1525
+ return endpointTraceId;
1526
+ }
1527
+ async generateRequestHeaders(data, request, $helpers) {
1528
+ const staticHeaders = this.getEndpointHeaders() ?? {};
1529
+ const transparentHeaders = (this.getTransparentHeaderNames() ?? []).reduce((headers, name) => {
1530
+ const value = Utils.getValue(data, name);
1531
+ if (value == null) ;
1532
+ else if (Array.isArray(value)) {
1533
+ const headerValue = value.filter(v => v != null && `${v}`.length !== 0).join(', ');
1534
+ if (headerValue.length !== 0) {
1535
+ headers[name] = headerValue;
1536
+ }
1537
+ }
1538
+ else if (typeof value === 'object') {
1539
+ Object.keys(value).forEach(key => {
1540
+ const headerValue = value[key];
1541
+ if (headerValue != null) {
1542
+ const s = `${headerValue}`;
1543
+ if (s.length !== 0) {
1544
+ headers[key] = s;
1545
+ }
1546
+ }
1547
+ });
1548
1548
  }
1549
1549
  else {
1550
- return await this._responseGenerateFunc(response, data, request, $helpers, $helpers);
1550
+ const headerValue = `${value}`;
1551
+ if (headerValue.length !== 0) {
1552
+ headers[name] = headerValue;
1553
+ }
1551
1554
  }
1555
+ return headers;
1556
+ }, {});
1557
+ (this.getOmittedTransparentHeaderNames() ?? []).forEach(name => delete transparentHeaders[name]);
1558
+ const generatedHeaders = await this._headersGenerateFunc(data, request, $helpers, $helpers) ?? {};
1559
+ const headers = { ...staticHeaders, ...transparentHeaders, ...generatedHeaders };
1560
+ Object.keys(headers).filter(name => {
1561
+ return ['content-encoding', 'content-length'].includes(name.toLowerCase());
1562
+ }).forEach(name => {
1563
+ delete headers[name];
1564
+ });
1565
+ return headers;
1566
+ }
1567
+ async generateRequestBody(method, data, request, $helpers) {
1568
+ let body;
1569
+ const bodyUsed = this.isBodyUsed();
1570
+ if (bodyUsed === true || (bodyUsed == null && method !== 'get')) {
1571
+ body = await this._bodyGenerateFunc(data, request, $helpers, $helpers);
1572
+ }
1573
+ else {
1574
+ body = (void 0);
1575
+ }
1576
+ if (body != null && typeof body !== 'string') {
1577
+ body = JSON.stringify(body);
1578
+ }
1579
+ return body;
1580
+ }
1581
+ tryToRetrieveTraceIdFromResponse(request, response) {
1582
+ const endpointTraceIdHeaderName = this.getEndpointTraceIdHeaderName();
1583
+ if (endpointTraceIdHeaderName == null) {
1584
+ return (void 0);
1585
+ }
1586
+ const endpointTraceId = response.headers.get(endpointTraceIdHeaderName);
1587
+ if (endpointTraceId == null || endpointTraceId.length === 0) {
1588
+ return (void 0);
1589
+ }
1590
+ const endpointTraceIdScope = this.getEndpointTraceIdScope();
1591
+ if (endpointTraceIdScope === 'system') {
1592
+ request.$context.setScopedTraceId(this.getEndpointSystemCode(), endpointTraceIdHeaderName, endpointTraceId);
1593
+ }
1594
+ else {
1595
+ request.$context.setScopedTraceId(this.getEndpointKey(), endpointTraceIdHeaderName, endpointTraceId);
1596
+ }
1597
+ return endpointTraceId;
1598
+ }
1599
+ async sendRequest(url, method, headers, body, data, request, $helpers) {
1600
+ const response = await fetch(url, {
1601
+ method, headers, body,
1602
+ signal: this.needTimeout() ? (() => {
1603
+ const controller = new AbortController();
1604
+ setTimeout(() => controller.abort(), this.getEndpointTimeout());
1605
+ return controller.signal;
1606
+ })() : (void 0)
1607
+ });
1608
+ this.tryToRetrieveTraceIdFromResponse(request, response);
1609
+ const status = response.status;
1610
+ if (status >= 400) {
1611
+ return await this._responseErrorHandleFunc({
1612
+ $url: url, $factor: data, $request: request, $response: response,
1613
+ $errorCode: `${status}`
1614
+ }, $helpers, $helpers);
1615
+ }
1616
+ else {
1617
+ return await this._responseGenerateFunc(response, data, request, $helpers, $helpers);
1618
+ }
1619
+ }
1620
+ async doPerform(data, request) {
1621
+ const $helpers = this.getHelpers();
1622
+ let url = '';
1623
+ try {
1624
+ url = await this._urlGenerateFunc(this.getEndpointUrl(), data, request, $helpers, $helpers);
1625
+ const method = this.getEndpointMethod();
1626
+ const headers = await this.generateRequestHeaders(data, request, $helpers);
1627
+ this.syncEndpointTraceId(headers, request);
1628
+ const body = await this.generateRequestBody(method, data, request, $helpers);
1629
+ return await this.sendRequest(url, method, headers, body, data, request, $helpers);
1552
1630
  }
1553
1631
  catch (e) {
1554
1632
  if (e instanceof DOMException || e.name === 'AbortError') {
@@ -2338,7 +2416,9 @@ class TypeOrmLoadManyBySQLUseCursorPipelineStep extends AbstractTypeOrmBySQLPipe
2338
2416
  ...this.buildStepOptions(), name: this.getName(), steps: this.getStepBuilders()
2339
2417
  });
2340
2418
  const { content: _, $context, ...rest } = request;
2341
- const contextForSub = { ...$context, $typeOrmCursorRound: cursorRound, $typeOrmCursorEnd: end };
2419
+ const contextForSub = $context.temporaryWith({
2420
+ $typeOrmCursorRound: cursorRound, $typeOrmCursorEnd: end
2421
+ });
2342
2422
  const requestForSub = { ...rest, $context: contextForSub, content: contentForSub };
2343
2423
  const result = await sets.perform(requestForSub);
2344
2424
  const { content } = result;
@@ -1,4 +1,5 @@
1
- import { PipelineStepData, PipelineStepPayload } from '@rainbow-o23/n1';
1
+ import { PipelineStepData, PipelineStepHelpers, PipelineStepPayload } from '@rainbow-o23/n1';
2
+ import { Response } from 'node-fetch';
2
3
  import { AbstractFragmentaryPipelineStep, FragmentaryPipelineStepOptions, ScriptFuncOrBody } from '../step';
3
4
  import { HttpErrorCode, HttpGenerateBody, HttpGenerateHeaders, HttpGenerateResponse, HttpGenerateUrl, HttpHandleError } from './types';
4
5
  export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = In, OutFragment = Out, BodyData = any> extends FragmentaryPipelineStepOptions<In, Out, InFragment, OutFragment> {
@@ -20,6 +21,7 @@ export interface FetchPipelineStepOptions<In = PipelineStepPayload, Out = Pipeli
20
21
  export declare class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = In, OutFragment = Out, BodyData = any> extends AbstractFragmentaryPipelineStep<In, Out, InFragment, OutFragment> {
21
22
  private readonly _endpointSystemCode;
22
23
  private readonly _endpointName;
24
+ private readonly _endpointKey;
23
25
  private readonly _endpointUrl;
24
26
  private readonly _endpointMethod;
25
27
  private readonly _endpointHeaders;
@@ -30,6 +32,8 @@ export declare class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineS
30
32
  private readonly _omittedTransparentHeaderNames;
31
33
  private readonly _headersGenerateSnippet;
32
34
  private readonly _headersGenerateFunc;
35
+ private readonly _endpointTraceIdHeaderName?;
36
+ private readonly _endpointTraceIdScope?;
33
37
  private readonly _bodyUsed;
34
38
  private readonly _bodyGenerateSnippet;
35
39
  private readonly _bodyGenerateFunc;
@@ -53,11 +57,18 @@ export declare class FetchPipelineStep<In = PipelineStepPayload, Out = PipelineS
53
57
  protected generateTransparentHeaderNames(headerNames?: string, base?: Array<string>): Array<string>;
54
58
  getHeadersGenerateSnippet(): ScriptFuncOrBody<HttpGenerateHeaders<In, InFragment>>;
55
59
  protected getHeadersGenerateVariableNames(): Array<string>;
60
+ getEndpointTraceIdHeaderName(): string | undefined;
61
+ getEndpointTraceIdScope(): 'system' | 'endpoint' | undefined;
56
62
  protected isBodyUsed(): boolean | undefined;
57
63
  getBodyGenerateSnippet(): ScriptFuncOrBody<HttpGenerateBody<In, InFragment, BodyData>>;
58
64
  protected getBodyGenerateVariableNames(): Array<string>;
59
65
  getResponseGenerateSnippet(): ScriptFuncOrBody<HttpGenerateResponse<In, InFragment, OutFragment>>;
60
66
  protected getResponseGenerateVariableName(): Array<string>;
61
67
  protected getErrorHandlerVariableName(): Array<string>;
68
+ protected syncEndpointTraceId(headers: Record<string, string>, request: PipelineStepData<In>): string | undefined;
69
+ protected generateRequestHeaders(data: InFragment, request: PipelineStepData<In>, $helpers: PipelineStepHelpers): Promise<Record<string, string>>;
70
+ protected generateRequestBody(method: string, data: InFragment, request: PipelineStepData<In>, $helpers: PipelineStepHelpers): Promise<any>;
71
+ protected tryToRetrieveTraceIdFromResponse(request: PipelineStepData<In>, response: Response): string | undefined;
72
+ protected sendRequest(url: string, method: string, headers: Record<string, string>, body: any, data: InFragment, request: PipelineStepData<In>, $helpers: PipelineStepHelpers): Promise<OutFragment>;
62
73
  protected doPerform(data: InFragment, request: PipelineStepData<In>): Promise<OutFragment>;
63
74
  }
@@ -1,5 +1,5 @@
1
1
  import { AbstractPipelineStep, PipelineStepBuilder, PipelineStepData, PipelineStepHelpers, PipelineStepOptions, PipelineStepPayload } from '@rainbow-o23/n1';
2
- import { PipelineStepSetsContext } from './step-sets';
2
+ import { PipelineStepSetsExecutionContext } from './step-sets';
3
3
  import { HandleAnyError, HandleCatchableError, HandleExposedUncatchableError, HandleUncatchableError, ScriptFuncOrBody } from './types';
4
4
  export interface FragmentaryPipelineStepOptions<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = In, OutFragment = Out> extends PipelineStepOptions {
5
5
  fromRequest?: ScriptFuncOrBody<GetInFragmentFromRequestFunc<In, InFragment>>;
@@ -36,7 +36,7 @@ export declare abstract class AbstractFragmentaryPipelineStep<In = PipelineStepP
36
36
  protected setToOutput($result: OutFragment, $request: PipelineStepData<In>): Promise<PipelineStepData<Out>>;
37
37
  protected abstract doPerform(data: InFragment, request: PipelineStepData<In>): Promise<OutFragment>;
38
38
  protected buildStepOptions(): Pick<PipelineStepOptions, 'config' | 'logger'>;
39
- protected createErrorHandleContext(request: PipelineStepData<In>): PipelineStepSetsContext;
39
+ protected createErrorHandleContext(request: PipelineStepData<In>): PipelineStepSetsExecutionContext;
40
40
  protected handleErrorSteps(fragment: InFragment, errorCode: string, error: any, request: PipelineStepData<In>, builders: Array<PipelineStepBuilder>): Promise<OutFragment>;
41
41
  protected handleError(fragment: InFragment, request: PipelineStepData<In>, error: any): Promise<OutFragment>;
42
42
  performAndCatch(request: PipelineStepData<In>, perform: (data: InFragment) => Promise<PipelineStepData<Out>>): Promise<PipelineStepData<Out>>;
@@ -1,5 +1,6 @@
1
1
  import { PipelineStepData, PipelineStepPayload } from '@rainbow-o23/n1';
2
- import { PipelineStepSets } from './step-sets';
2
+ import { PipelineStepSets, PipelineStepSetsExecutionContext } from './step-sets';
3
3
  export declare class AsyncPipelineStepSets<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = In> extends PipelineStepSets<In, Out, InFragment, void> {
4
+ protected inheritContext(request: PipelineStepData<In>): PipelineStepSetsExecutionContext;
4
5
  protected doPerform(data: InFragment, request: PipelineStepData<In>): Promise<void>;
5
6
  }
@@ -1,6 +1,6 @@
1
- import { PipelineStep, PipelineStepBuilder, PipelineStepData, PipelineStepOptions, PipelineStepPayload } from '@rainbow-o23/n1';
1
+ import { PipelineExecutionContext, PipelineStep, PipelineStepBuilder, PipelineStepData, PipelineStepOptions, PipelineStepPayload } from '@rainbow-o23/n1';
2
2
  import { AbstractFragmentaryPipelineStep, FragmentaryPipelineStepOptions } from './abstract-fragmentary-pipeline-step';
3
- export interface PipelineStepSetsContext {
3
+ export interface PipelineStepSetsExecutionContext extends PipelineExecutionContext {
4
4
  }
5
5
  export interface PipelineStepSetsOptions<In = PipelineStepPayload, Out = PipelineStepPayload, InFragment = In, OutFragment = Out> extends FragmentaryPipelineStepOptions<In, Out, InFragment, OutFragment> {
6
6
  steps: Array<PipelineStepBuilder>;
@@ -11,9 +11,9 @@ export declare class PipelineStepSets<In = PipelineStepPayload, Out = PipelineSt
11
11
  protected getStepBuilders(): Array<PipelineStepBuilder>;
12
12
  protected buildStepOptions(): Pick<PipelineStepOptions, 'config' | 'logger'>;
13
13
  createSteps(): Promise<Array<PipelineStep>>;
14
- protected inheritContext(request: PipelineStepData<In>): PipelineStepSetsContext;
15
- protected attachMineToInternalContext(inheritedContext: PipelineStepSetsContext, _request: PipelineStepData<In>): Promise<PipelineStepSetsContext>;
16
- protected createInternalContext<Ctx extends PipelineStepSetsContext>(request: PipelineStepData<In>): Promise<Ctx>;
17
- protected performWithContext(request: PipelineStepData<In>, run: (request: PipelineStepData<In>, context: PipelineStepSetsContext) => Promise<OutFragment>): Promise<OutFragment>;
14
+ protected inheritContext(request: PipelineStepData<In>): PipelineStepSetsExecutionContext;
15
+ protected attachMineToInternalContext(inheritedContext: PipelineStepSetsExecutionContext, _request: PipelineStepData<In>): Promise<PipelineStepSetsExecutionContext>;
16
+ protected createInternalContext<Ctx extends PipelineStepSetsExecutionContext>(request: PipelineStepData<In>): Promise<Ctx>;
17
+ protected performWithContext(request: PipelineStepData<In>, run: (request: PipelineStepData<In>, context: PipelineStepSetsExecutionContext) => Promise<OutFragment>): Promise<OutFragment>;
18
18
  protected doPerform(data: InFragment, request: PipelineStepData<In>): Promise<OutFragment>;
19
19
  }
@@ -1,6 +1,6 @@
1
1
  import { PipelineStepData, PipelineStepPayload, Undefinable } from '@rainbow-o23/n1';
2
2
  import { QueryRunner } from 'typeorm';
3
- import { PipelineStepSets, PipelineStepSetsContext, PipelineStepSetsOptions } from '../step';
3
+ import { PipelineStepSets, PipelineStepSetsExecutionContext, PipelineStepSetsOptions } from '../step';
4
4
  import { TypeOrmDataSource } from '../typeorm';
5
5
  import { TypeOrmDataSourceName, TypeOrmTransactionalContext, TypeOrmTransactionKey, TypeOrmTransactionName } from './types';
6
6
  export interface TypeOrmTransactionalPipelineStepSetsOptions extends PipelineStepSetsOptions {
@@ -16,7 +16,7 @@ export declare class TypeOrmTransactionalPipelineStepSets<In = PipelineStepPaylo
16
16
  getTransactionKey(): TypeOrmTransactionKey;
17
17
  protected findDataSourceOrThrow(): Promise<Undefinable<TypeOrmDataSource>>;
18
18
  protected createRunner(): Promise<[TypeOrmDataSource, QueryRunner]>;
19
- protected attachMineToInternalContext(inheritedContext: PipelineStepSetsContext, _request: PipelineStepData<In>): Promise<TypeOrmTransactionalContext>;
19
+ protected attachMineToInternalContext(inheritedContext: PipelineStepSetsExecutionContext, _request: PipelineStepData<In>): Promise<TypeOrmTransactionalContext>;
20
20
  private getRunner;
21
- protected performWithContext(request: PipelineStepData<In>, run: (request: PipelineStepData<In>, context: PipelineStepSetsContext) => Promise<OutFragment>): Promise<OutFragment>;
21
+ protected performWithContext(request: PipelineStepData<In>, run: (request: PipelineStepData<In>, context: PipelineStepSetsExecutionContext) => Promise<OutFragment>): Promise<OutFragment>;
22
22
  }
@@ -1,5 +1,5 @@
1
1
  import { DeepPartial, ObjectLiteral, QueryRunner } from 'typeorm';
2
- import { PipelineStepSetsContext } from '../step';
2
+ import { PipelineStepSetsExecutionContext } from '../step';
3
3
  import { TypeOrmDataSource } from '../typeorm';
4
4
  export type TypeOrmIdType = string | number | bigint;
5
5
  export type TypeOrmDataSourceName = string;
@@ -16,6 +16,6 @@ export type TypeOrmCountsOfAffected = Array<TypeOrmCountOfAffected>;
16
16
  export type TypeOrmWrittenResult = TypeOrmIdOfInserted | TypeOrmCountOfAffected;
17
17
  export type TypeOrmBulkWrittenResult = TypeOrmIdsOfInserted | TypeOrmCountsOfAffected;
18
18
  export declare const DEFAULT_TRANSACTION_NAME: TypeOrmTransactionName;
19
- export interface TypeOrmTransactionalContext extends PipelineStepSetsContext {
19
+ export interface TypeOrmTransactionalContext extends PipelineStepSetsExecutionContext {
20
20
  $trans: Record<TypeOrmTransactionKey, [TypeOrmDataSource, QueryRunner]>;
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainbow-o23/n3",
3
- "version": "1.0.58",
3
+ "version": "1.0.59",
4
4
  "description": "o23 pipelines",
5
5
  "main": "index.cjs",
6
6
  "module": "index.js",
@@ -21,7 +21,7 @@
21
21
  "url": "https://github.com/InsureMO/rainbow-o23/issues"
22
22
  },
23
23
  "dependencies": {
24
- "@rainbow-o23/n1": "1.0.58",
24
+ "@rainbow-o23/n1": "1.0.59",
25
25
  "node-fetch": "2.6.7",
26
26
  "typeorm": "^0.3.20",
27
27
  "typescript": "5.5.4"