@flowcore/pathways 0.2.1 → 0.2.2
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/CHANGELOG.md +9 -0
- package/esm/common/flowcore.type.d.ts +3 -3
- package/esm/common/flowcore.type.d.ts.map +1 -1
- package/esm/common/index.d.ts +2 -0
- package/esm/common/index.d.ts.map +1 -1
- package/esm/common/index.js +2 -0
- package/esm/compatibility/flowcore-transformer-core.sdk.d.ts +4 -0
- package/esm/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -1
- package/esm/compatibility/flowcore-transformer-core.sdk.js +2 -0
- package/esm/contracts/index.d.ts +2 -0
- package/esm/contracts/index.d.ts.map +1 -1
- package/esm/contracts/index.js +2 -0
- package/esm/mod.d.ts +2 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +2 -0
- package/esm/pathways/builder.d.ts +87 -0
- package/esm/pathways/builder.d.ts.map +1 -1
- package/esm/pathways/builder.js +83 -8
- package/esm/pathways/index.d.ts +2 -0
- package/esm/pathways/index.d.ts.map +1 -1
- package/esm/pathways/index.js +2 -0
- package/esm/pathways/internal-pathway.state.d.ts +5 -7
- package/esm/pathways/internal-pathway.state.d.ts.map +1 -1
- package/esm/pathways/internal-pathway.state.js +5 -7
- package/esm/pathways/kv/bun-kv-adapter.d.ts +5 -7
- package/esm/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
- package/esm/pathways/kv/bun-kv-adapter.js +5 -7
- package/esm/pathways/kv/kv-adapter.d.ts +7 -7
- package/esm/pathways/kv/kv-adapter.js +1 -1
- package/esm/pathways/kv/node-kv-adapter.d.ts +6 -8
- package/esm/pathways/kv/node-kv-adapter.d.ts.map +1 -1
- package/esm/pathways/kv/node-kv-adapter.js +6 -8
- package/esm/pathways/logger.d.ts +46 -3
- package/esm/pathways/logger.d.ts.map +1 -1
- package/esm/pathways/logger.js +45 -3
- package/esm/pathways/postgres/index.d.ts +2 -0
- package/esm/pathways/postgres/index.d.ts.map +1 -1
- package/esm/pathways/postgres/index.js +2 -0
- package/esm/pathways/postgres/postgres-adapter.d.ts +20 -29
- package/esm/pathways/postgres/postgres-adapter.d.ts.map +1 -1
- package/esm/pathways/postgres/postgres-adapter.js +12 -17
- package/esm/pathways/postgres/postgres-pathway-state.d.ts +2 -6
- package/esm/pathways/postgres/postgres-pathway-state.d.ts.map +1 -1
- package/esm/pathways/postgres/postgres-pathway-state.js +2 -4
- package/esm/pathways/types.d.ts +48 -3
- package/esm/pathways/types.d.ts.map +1 -1
- package/esm/router/index.d.ts +17 -11
- package/esm/router/index.d.ts.map +1 -1
- package/esm/router/index.js +21 -24
- package/package.json +2 -2
- package/script/common/flowcore.type.d.ts +3 -3
- package/script/common/flowcore.type.d.ts.map +1 -1
- package/script/common/index.d.ts +2 -0
- package/script/common/index.d.ts.map +1 -1
- package/script/common/index.js +2 -0
- package/script/compatibility/flowcore-transformer-core.sdk.d.ts +4 -0
- package/script/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -1
- package/script/compatibility/flowcore-transformer-core.sdk.js +2 -0
- package/script/contracts/index.d.ts +2 -0
- package/script/contracts/index.d.ts.map +1 -1
- package/script/contracts/index.js +2 -0
- package/script/mod.d.ts +2 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +2 -0
- package/script/pathways/builder.d.ts +87 -0
- package/script/pathways/builder.d.ts.map +1 -1
- package/script/pathways/builder.js +83 -8
- package/script/pathways/index.d.ts +2 -0
- package/script/pathways/index.d.ts.map +1 -1
- package/script/pathways/index.js +2 -0
- package/script/pathways/internal-pathway.state.d.ts +5 -7
- package/script/pathways/internal-pathway.state.d.ts.map +1 -1
- package/script/pathways/internal-pathway.state.js +5 -7
- package/script/pathways/kv/bun-kv-adapter.d.ts +5 -7
- package/script/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
- package/script/pathways/kv/bun-kv-adapter.js +5 -7
- package/script/pathways/kv/kv-adapter.d.ts +7 -7
- package/script/pathways/kv/kv-adapter.js +1 -1
- package/script/pathways/kv/node-kv-adapter.d.ts +6 -8
- package/script/pathways/kv/node-kv-adapter.d.ts.map +1 -1
- package/script/pathways/kv/node-kv-adapter.js +6 -8
- package/script/pathways/logger.d.ts +46 -3
- package/script/pathways/logger.d.ts.map +1 -1
- package/script/pathways/logger.js +45 -3
- package/script/pathways/postgres/index.d.ts +2 -0
- package/script/pathways/postgres/index.d.ts.map +1 -1
- package/script/pathways/postgres/index.js +2 -0
- package/script/pathways/postgres/postgres-adapter.d.ts +20 -29
- package/script/pathways/postgres/postgres-adapter.d.ts.map +1 -1
- package/script/pathways/postgres/postgres-adapter.js +12 -17
- package/script/pathways/postgres/postgres-pathway-state.d.ts +2 -6
- package/script/pathways/postgres/postgres-pathway-state.d.ts.map +1 -1
- package/script/pathways/postgres/postgres-pathway-state.js +2 -4
- package/script/pathways/types.d.ts +48 -3
- package/script/pathways/types.d.ts.map +1 -1
- package/script/router/index.d.ts +17 -11
- package/script/router/index.d.ts.map +1 -1
- package/script/router/index.js +21 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pathways/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEzF
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pathways/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEzF;;;GAGG;AACH,KAAK,uBAAuB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IACnD,QAAQ,CAAC,yBAAyB,EAAE,wGAAwG,CAAA;CAC7I,CAAA;AAED;;;;;GA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KAAK,GAAG,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAErI;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;IAE9D;;;OAGG;IACH,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;CAC1D,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,GAAG;IACrD;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC,CAAA"}
|
package/esm/router/index.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Router module for Flowcore Pathways
|
|
3
|
+
*
|
|
4
|
+
* This module provides routing functionality to direct incoming events
|
|
5
|
+
* to the appropriate pathway handlers based on flow type and event type.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
1
9
|
import type { FlowcoreLegacyEvent } from "../common/flowcore.type.js";
|
|
2
10
|
import type { PathwaysBuilder } from "../pathways/index.js";
|
|
3
11
|
import type { Logger } from "../pathways/logger.js";
|
|
4
12
|
/**
|
|
5
13
|
* Router class that handles directing events to the appropriate pathway handlers
|
|
6
|
-
*
|
|
7
|
-
* @class PathwayRouter
|
|
8
14
|
*/
|
|
9
15
|
export declare class PathwayRouter {
|
|
10
16
|
private readonly pathways;
|
|
@@ -13,19 +19,19 @@ export declare class PathwayRouter {
|
|
|
13
19
|
/**
|
|
14
20
|
* Creates a new instance of PathwayRouter
|
|
15
21
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @throws
|
|
22
|
+
* @param pathways The pathways builder instance that contains all registered pathways
|
|
23
|
+
* @param secretKey Secret key used for authentication when processing events
|
|
24
|
+
* @param logger Optional logger instance (defaults to NoopLogger if not provided)
|
|
25
|
+
* @throws Error if secretKey is empty or not provided
|
|
20
26
|
*/
|
|
21
27
|
constructor(pathways: PathwaysBuilder<Record<string, any>>, secretKey: string, logger?: Logger);
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
29
|
+
* Process an incoming event by routing it to the appropriate pathway handler
|
|
24
30
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @returns
|
|
28
|
-
* @throws
|
|
31
|
+
* @param event The event to process
|
|
32
|
+
* @param providedSecret The secret key provided for authentication
|
|
33
|
+
* @returns Result of the event processing with success status and message
|
|
34
|
+
* @throws Error if authentication fails, pathway is not found, or processing fails
|
|
29
35
|
*/
|
|
30
36
|
processEvent(event: FlowcoreLegacyEvent, providedSecret: string): Promise<{
|
|
31
37
|
success: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAGnD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAErE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAGnD;;GAEG;AACH,qBAAa,aAAa;IAatB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAb5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;;;OAOG;gBAGgB,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC9C,SAAS,EAAE,MAAM,EAClC,MAAM,CAAC,EAAE,MAAM;IAajB;;;;;;;OAOG;IACG,YAAY,CAAC,KAAK,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAkDvH"}
|
package/esm/router/index.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { NoopLogger } from "../pathways/logger.js";
|
|
2
2
|
/**
|
|
3
3
|
* Router class that handles directing events to the appropriate pathway handlers
|
|
4
|
-
*
|
|
5
|
-
* @class PathwayRouter
|
|
6
4
|
*/
|
|
7
5
|
export class PathwayRouter {
|
|
8
6
|
/**
|
|
9
7
|
* Creates a new instance of PathwayRouter
|
|
10
8
|
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @throws
|
|
9
|
+
* @param pathways The pathways builder instance that contains all registered pathways
|
|
10
|
+
* @param secretKey Secret key used for authentication when processing events
|
|
11
|
+
* @param logger Optional logger instance (defaults to NoopLogger if not provided)
|
|
12
|
+
* @throws Error if secretKey is empty or not provided
|
|
15
13
|
*/
|
|
16
14
|
constructor(
|
|
17
15
|
// deno-lint-ignore no-explicit-any
|
|
@@ -36,24 +34,26 @@ export class PathwayRouter {
|
|
|
36
34
|
});
|
|
37
35
|
this.logger = logger ?? new NoopLogger();
|
|
38
36
|
if (!secretKey || secretKey.trim() === "") {
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const errorMsg = "Secret key is required for PathwayRouter";
|
|
38
|
+
this.logger.error(errorMsg, new Error(errorMsg));
|
|
39
|
+
throw new Error(errorMsg);
|
|
41
40
|
}
|
|
42
41
|
this.logger.debug("PathwayRouter initialized");
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
|
-
*
|
|
44
|
+
* Process an incoming event by routing it to the appropriate pathway handler
|
|
46
45
|
*
|
|
47
|
-
* @param
|
|
48
|
-
* @param
|
|
49
|
-
* @returns
|
|
50
|
-
* @throws
|
|
46
|
+
* @param event The event to process
|
|
47
|
+
* @param providedSecret The secret key provided for authentication
|
|
48
|
+
* @returns Result of the event processing with success status and message
|
|
49
|
+
* @throws Error if authentication fails, pathway is not found, or processing fails
|
|
51
50
|
*/
|
|
52
51
|
async processEvent(event, providedSecret) {
|
|
53
52
|
// Validate secret key
|
|
54
53
|
if (!providedSecret || providedSecret !== this.secretKey) {
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const errorMsg = "Invalid secret key";
|
|
55
|
+
this.logger.error(errorMsg, new Error(errorMsg));
|
|
56
|
+
throw new Error(errorMsg);
|
|
57
57
|
}
|
|
58
58
|
const compatibleEvent = {
|
|
59
59
|
...event,
|
|
@@ -65,9 +65,9 @@ export class PathwayRouter {
|
|
|
65
65
|
});
|
|
66
66
|
const pathway = this.pathways.get(pathwayKey);
|
|
67
67
|
if (!pathway) {
|
|
68
|
-
const
|
|
69
|
-
this.logger.error(
|
|
70
|
-
throw new Error(
|
|
68
|
+
const errorMsg = `Pathway ${pathwayKey} not found`;
|
|
69
|
+
this.logger.error(errorMsg, new Error(errorMsg));
|
|
70
|
+
throw new Error(errorMsg);
|
|
71
71
|
}
|
|
72
72
|
try {
|
|
73
73
|
this.logger.debug(`Delegating event processing to pathway handler`, {
|
|
@@ -82,15 +82,12 @@ export class PathwayRouter {
|
|
|
82
82
|
return { success: true, message: `Event processed through pathway ${pathwayKey}` };
|
|
83
83
|
}
|
|
84
84
|
catch (error) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
: String(error);
|
|
88
|
-
this.logger.error(`Error processing pathway ${pathwayKey}`, {
|
|
89
|
-
error: errorMessage,
|
|
85
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
86
|
+
this.logger.error(`Error processing pathway ${pathwayKey}`, errorObj, {
|
|
90
87
|
eventId: compatibleEvent.eventId
|
|
91
88
|
});
|
|
92
89
|
// Rethrow the error with additional context
|
|
93
|
-
throw new Error(`Failed to process event in pathway ${pathwayKey}: ${
|
|
90
|
+
throw new Error(`Failed to process event in pathway ${pathwayKey}: ${errorObj.message}`);
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
93
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowcore/pathways",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "A TypeScript Library for creating Flowcore Pathways, simplifying the integration with the flowcore platform",
|
|
5
5
|
"homepage": "https://github.com/flowcore-io/flowcore-sdk#readme",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { FlowcoreEvent } from "../contracts/event.js";
|
|
2
2
|
/**
|
|
3
3
|
* Extends the FlowcoreEvent with legacy fields
|
|
4
|
-
*
|
|
5
|
-
* @typedef {Object} FlowcoreLegacyEvent
|
|
6
|
-
* @property {string} [aggregator] - Optional aggregator information for legacy support
|
|
7
4
|
*/
|
|
8
5
|
export type FlowcoreLegacyEvent = FlowcoreEvent & {
|
|
6
|
+
/**
|
|
7
|
+
* Optional aggregator information for legacy support
|
|
8
|
+
*/
|
|
9
9
|
aggregator?: string;
|
|
10
10
|
};
|
|
11
11
|
//# sourceMappingURL=flowcore.type.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowcore.type.d.ts","sourceRoot":"","sources":["../../src/common/flowcore.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D
|
|
1
|
+
{"version":3,"file":"flowcore.type.d.ts","sourceRoot":"","sources":["../../src/common/flowcore.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG;IAChD;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA"}
|
package/script/common/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,oBAAoB,CAAC"}
|
package/script/common/index.js
CHANGED
|
@@ -18,5 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
* Common types and utilities for Flowcore Pathways
|
|
19
19
|
*
|
|
20
20
|
* This module exports common types and utilities that are used across the Flowcore Pathways library.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
21
23
|
*/
|
|
22
24
|
__exportStar(require("./flowcore.type.js"), exports);
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This module re-exports components from the @flowcore/sdk-transformer-core package
|
|
5
5
|
* to provide backwards compatibility with existing transformer implementations.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
6
8
|
*/
|
|
7
9
|
import transformerCore from "@flowcore/sdk-transformer-core";
|
|
8
10
|
/**
|
|
@@ -11,6 +13,8 @@ import transformerCore from "@flowcore/sdk-transformer-core";
|
|
|
11
13
|
export declare const WebhookBuilder: typeof transformerCore.WebhookBuilder;
|
|
12
14
|
/**
|
|
13
15
|
* Options for configuring webhook send operations
|
|
16
|
+
*
|
|
17
|
+
* These options control how webhook requests are sent, including timestamps and headers.
|
|
14
18
|
*/
|
|
15
19
|
export type { WebhookSendOptions } from "@flowcore/sdk-transformer-core";
|
|
16
20
|
//# sourceMappingURL=flowcore-transformer-core.sdk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowcore-transformer-core.sdk.d.ts","sourceRoot":"","sources":["../../src/compatibility/flowcore-transformer-core.sdk.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"flowcore-transformer-core.sdk.d.ts","sourceRoot":"","sources":["../../src/compatibility/flowcore-transformer-core.sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,eAAe,MAAM,gCAAgC,CAAA;AAE5D;;GAEG;AACH,eAAO,MAAQ,cAAc,uCAAoB,CAAA;AAEjD;;;;GAIG;AACH,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA"}
|
|
@@ -9,6 +9,8 @@ exports.WebhookBuilder = void 0;
|
|
|
9
9
|
*
|
|
10
10
|
* This module re-exports components from the @flowcore/sdk-transformer-core package
|
|
11
11
|
* to provide backwards compatibility with existing transformer implementations.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
12
14
|
*/
|
|
13
15
|
const sdk_transformer_core_1 = __importDefault(require("@flowcore/sdk-transformer-core"));
|
|
14
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,CAAC"}
|
|
@@ -16,5 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
/**
|
|
18
18
|
* Export all contract types and schemas for Flowcore events
|
|
19
|
+
*
|
|
20
|
+
* @module
|
|
19
21
|
*/
|
|
20
22
|
__exportStar(require("./event.js"), exports);
|
package/script/mod.d.ts
CHANGED
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC"}
|
package/script/mod.js
CHANGED
|
@@ -22,6 +22,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
22
|
* - Event contracts and schemas
|
|
23
23
|
* - Pathway definitions and builders
|
|
24
24
|
* - Event routing functionality
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
25
27
|
*/
|
|
26
28
|
__exportStar(require("./common/index.js"), exports);
|
|
27
29
|
__exportStar(require("./contracts/index.js"), exports);
|
|
@@ -3,12 +3,46 @@ import type { WebhookSendOptions } from "@flowcore/sdk-transformer-core";
|
|
|
3
3
|
import type { FlowcoreEvent } from "../contracts/event.js";
|
|
4
4
|
import type { Logger } from "./logger.js";
|
|
5
5
|
import type { EventMetadata, PathwayContract, PathwayKey, PathwayState, PathwayWriteOptions, WritablePathway } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Defines the mode for auditing pathway operations
|
|
8
|
+
* - "user": Normal user-initiated operations
|
|
9
|
+
* - "system": System-initiated operations on behalf of a user
|
|
10
|
+
*/
|
|
6
11
|
export type AuditMode = "user" | "system";
|
|
12
|
+
/**
|
|
13
|
+
* Handler function for auditing pathway events
|
|
14
|
+
* @param path The pathway path being audited
|
|
15
|
+
* @param event The event data being processed
|
|
16
|
+
*/
|
|
7
17
|
export type AuditHandler = (path: string, event: FlowcoreEvent) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Async function that resolves to the current user ID
|
|
20
|
+
* Used for audit functionality to track which user initiated an action
|
|
21
|
+
*/
|
|
8
22
|
export type UserIdResolver = () => Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Extended webhook send options with additional audit-specific options
|
|
25
|
+
*/
|
|
9
26
|
export interface AuditWebhookSendOptions extends WebhookSendOptions {
|
|
27
|
+
/**
|
|
28
|
+
* Custom HTTP headers to include with the webhook request
|
|
29
|
+
*/
|
|
10
30
|
headers?: Record<string, string>;
|
|
11
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Main builder class for creating and managing Flowcore pathways
|
|
34
|
+
*
|
|
35
|
+
* The PathwaysBuilder provides an interface for:
|
|
36
|
+
* - Registering pathways with type-safe schemas
|
|
37
|
+
* - Handling events sent to pathways
|
|
38
|
+
* - Writing data to pathways
|
|
39
|
+
* - Managing event processing and retries
|
|
40
|
+
* - Observing event lifecycle (before/after/error)
|
|
41
|
+
* - Audit logging of pathway operations
|
|
42
|
+
*
|
|
43
|
+
* @template TPathway Record type that maps pathway keys to their payload types
|
|
44
|
+
* @template TWritablePaths Union type of pathway keys that can be written to
|
|
45
|
+
*/
|
|
12
46
|
export declare class PathwaysBuilder<TPathway extends Record<string, unknown> = {}, TWritablePaths extends keyof TPathway = never> {
|
|
13
47
|
private readonly pathways;
|
|
14
48
|
private readonly handlers;
|
|
@@ -29,6 +63,16 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
29
63
|
private auditHandler?;
|
|
30
64
|
private userIdResolver?;
|
|
31
65
|
private readonly logger;
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new PathwaysBuilder instance
|
|
68
|
+
* @param options Configuration options for the PathwaysBuilder
|
|
69
|
+
* @param options.baseUrl The base URL for the Flowcore API
|
|
70
|
+
* @param options.tenant The tenant name
|
|
71
|
+
* @param options.dataCore The data core name
|
|
72
|
+
* @param options.apiKey The API key for authentication
|
|
73
|
+
* @param options.pathwayTimeoutMs Optional timeout for pathway processing in milliseconds
|
|
74
|
+
* @param options.logger Optional logger instance
|
|
75
|
+
*/
|
|
32
76
|
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger, }: {
|
|
33
77
|
baseUrl: string;
|
|
34
78
|
tenant: string;
|
|
@@ -37,6 +81,11 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
37
81
|
pathwayTimeoutMs?: number;
|
|
38
82
|
logger?: Logger;
|
|
39
83
|
});
|
|
84
|
+
/**
|
|
85
|
+
* Configures the PathwaysBuilder to use a custom pathway state implementation
|
|
86
|
+
* @param state The PathwayState implementation to use
|
|
87
|
+
* @returns The PathwaysBuilder instance with custom state configured
|
|
88
|
+
*/
|
|
40
89
|
withPathwayState(state: PathwayState): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
41
90
|
/**
|
|
42
91
|
* Configures the PathwaysBuilder to use audit functionality
|
|
@@ -52,12 +101,39 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
52
101
|
* @returns Promise that resolves when processing is complete
|
|
53
102
|
*/
|
|
54
103
|
process(pathway: keyof TPathway, data: FlowcoreEvent): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Registers a new pathway with the given contract
|
|
106
|
+
* @template F The flow type string
|
|
107
|
+
* @template E The event type string
|
|
108
|
+
* @template S The schema type extending TSchema
|
|
109
|
+
* @template W Boolean indicating if the pathway is writable (defaults to true)
|
|
110
|
+
* @param contract The pathway contract describing the pathway
|
|
111
|
+
* @returns The PathwaysBuilder instance with the new pathway registered
|
|
112
|
+
*/
|
|
55
113
|
register<F extends string, E extends string, S extends TSchema, W extends boolean = true>(contract: PathwayContract<F, E, S> & {
|
|
56
114
|
writable?: W;
|
|
57
115
|
maxRetries?: number;
|
|
58
116
|
retryDelayMs?: number;
|
|
59
117
|
}): PathwaysBuilder<TPathway & Record<PathwayKey<F, E>, Static<S>>, TWritablePaths | WritablePathway<PathwayKey<F, E>, W>>;
|
|
118
|
+
/**
|
|
119
|
+
* Gets a pathway instance by its path
|
|
120
|
+
*
|
|
121
|
+
* @template TPath The specific pathway key to retrieve
|
|
122
|
+
* @param path The pathway key to get
|
|
123
|
+
* @returns The pathway instance
|
|
124
|
+
*/
|
|
60
125
|
get<TPath extends keyof TPathway>(path: TPath): TPathway[TPath];
|
|
126
|
+
/**
|
|
127
|
+
* Sets a handler function for a pathway
|
|
128
|
+
*
|
|
129
|
+
* This handler will be called whenever an event is received for the specified pathway.
|
|
130
|
+
* Only one handler can be registered per pathway in a given PathwaysBuilder instance.
|
|
131
|
+
*
|
|
132
|
+
* @template TPath The specific pathway key to handle
|
|
133
|
+
* @param path The pathway key to handle
|
|
134
|
+
* @param handler The function that will process events for this pathway
|
|
135
|
+
* @throws Error if the pathway doesn't exist or already has a handler
|
|
136
|
+
*/
|
|
61
137
|
handle<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent) => (Promise<void> | void)): void;
|
|
62
138
|
/**
|
|
63
139
|
* Subscribe to pathway events (before or after processing)
|
|
@@ -86,6 +162,17 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
86
162
|
* @returns A promise that resolves to the event ID(s)
|
|
87
163
|
*/
|
|
88
164
|
write<TPath extends TWritablePaths>(path: TPath, data: TPathway[TPath], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Waits for a specific event to be processed
|
|
167
|
+
*
|
|
168
|
+
* This method polls the pathway state to check if an event has been processed,
|
|
169
|
+
* with a configurable timeout. It will throw an error if the timeout is exceeded.
|
|
170
|
+
*
|
|
171
|
+
* @private
|
|
172
|
+
* @param eventId The ID of the event to wait for
|
|
173
|
+
* @returns Promise that resolves when the event is processed
|
|
174
|
+
* @throws Error if the timeout is exceeded
|
|
175
|
+
*/
|
|
89
176
|
private waitForPathwayToBeProcessed;
|
|
90
177
|
}
|
|
91
178
|
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAExD,OAAO,KAAK,EAAyD,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAG/H,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAA6B,eAAe,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAExD,OAAO,KAAK,EAAyD,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAG/H,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,mBAAmB,EAA6B,eAAe,EAAE,MAAM,YAAY,CAAA;AAiB3J;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,CAAA;AAEzC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;AAEvE;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;AAElD;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE;;OAEG;I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IAAI,CAAC,GAAG,IAAI,CAAE,GAAG,IAAI;IAqBnH;;;;;OAKG;IACH,SAAS,CAAC,KAAK,SAAS,MAAM,QAAQ,EACpC,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EACvC,IAAI,GAAE,QAAQ,GAAG,OAAO,GAAG,KAAgB,GAC1C,IAAI;IA6BP;;;;OAIG;IACH,OAAO,CAAC,KAAK,SAAS,MAAM,QAAQ,EAClC,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,GACpD,IAAI;IAcP;;;OAGG;IACH,UAAU,CACR,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GACrE,IAAI;IAMP;;;;;;;OAOG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,EACrB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IA4F7B;;;;;;;;;;OAUG;YACW,2BAA2B;CA4C1C"}
|
|
@@ -6,10 +6,43 @@ const rxjs_1 = require("rxjs");
|
|
|
6
6
|
const flowcore_transformer_core_sdk_js_1 = require("../compatibility/flowcore-transformer-core.sdk.js");
|
|
7
7
|
const internal_pathway_state_js_1 = require("./internal-pathway.state.js");
|
|
8
8
|
const logger_js_1 = require("./logger.js");
|
|
9
|
+
/**
|
|
10
|
+
* Default timeout for pathway processing in milliseconds (10 seconds)
|
|
11
|
+
*/
|
|
9
12
|
const DEFAULT_PATHWAY_TIMEOUT_MS = 10000;
|
|
13
|
+
/**
|
|
14
|
+
* Default maximum number of retry attempts for failed pathway processing
|
|
15
|
+
*/
|
|
10
16
|
const DEFAULT_MAX_RETRIES = 3;
|
|
17
|
+
/**
|
|
18
|
+
* Default delay between retry attempts in milliseconds
|
|
19
|
+
*/
|
|
11
20
|
const DEFAULT_RETRY_DELAY_MS = 500;
|
|
21
|
+
/**
|
|
22
|
+
* Main builder class for creating and managing Flowcore pathways
|
|
23
|
+
*
|
|
24
|
+
* The PathwaysBuilder provides an interface for:
|
|
25
|
+
* - Registering pathways with type-safe schemas
|
|
26
|
+
* - Handling events sent to pathways
|
|
27
|
+
* - Writing data to pathways
|
|
28
|
+
* - Managing event processing and retries
|
|
29
|
+
* - Observing event lifecycle (before/after/error)
|
|
30
|
+
* - Audit logging of pathway operations
|
|
31
|
+
*
|
|
32
|
+
* @template TPathway Record type that maps pathway keys to their payload types
|
|
33
|
+
* @template TWritablePaths Union type of pathway keys that can be written to
|
|
34
|
+
*/
|
|
12
35
|
class PathwaysBuilder {
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new PathwaysBuilder instance
|
|
38
|
+
* @param options Configuration options for the PathwaysBuilder
|
|
39
|
+
* @param options.baseUrl The base URL for the Flowcore API
|
|
40
|
+
* @param options.tenant The tenant name
|
|
41
|
+
* @param options.dataCore The data core name
|
|
42
|
+
* @param options.apiKey The API key for authentication
|
|
43
|
+
* @param options.pathwayTimeoutMs Optional timeout for pathway processing in milliseconds
|
|
44
|
+
* @param options.logger Optional logger instance
|
|
45
|
+
*/
|
|
13
46
|
constructor({ baseUrl, tenant, dataCore, apiKey, pathwayTimeoutMs, logger, }) {
|
|
14
47
|
Object.defineProperty(this, "pathways", {
|
|
15
48
|
enumerable: true,
|
|
@@ -150,6 +183,11 @@ class PathwaysBuilder {
|
|
|
150
183
|
this.pathwayTimeoutMs = pathwayTimeoutMs;
|
|
151
184
|
}
|
|
152
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Configures the PathwaysBuilder to use a custom pathway state implementation
|
|
188
|
+
* @param state The PathwayState implementation to use
|
|
189
|
+
* @returns The PathwaysBuilder instance with custom state configured
|
|
190
|
+
*/
|
|
153
191
|
withPathwayState(state) {
|
|
154
192
|
this.logger.debug('Setting custom pathway state');
|
|
155
193
|
this.pathwayState = state;
|
|
@@ -227,10 +265,9 @@ class PathwaysBuilder {
|
|
|
227
265
|
catch (error) {
|
|
228
266
|
// Create error object if needed
|
|
229
267
|
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
230
|
-
this.logger.error(`Error processing pathway event`, {
|
|
268
|
+
this.logger.error(`Error processing pathway event`, errorObj, {
|
|
231
269
|
pathway: pathwayStr,
|
|
232
270
|
eventId: data.eventId,
|
|
233
|
-
error: errorObj.message,
|
|
234
271
|
retryCount,
|
|
235
272
|
maxRetries
|
|
236
273
|
});
|
|
@@ -280,6 +317,15 @@ class PathwaysBuilder {
|
|
|
280
317
|
await this.pathwayState.setProcessed(data.eventId);
|
|
281
318
|
}
|
|
282
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Registers a new pathway with the given contract
|
|
322
|
+
* @template F The flow type string
|
|
323
|
+
* @template E The event type string
|
|
324
|
+
* @template S The schema type extending TSchema
|
|
325
|
+
* @template W Boolean indicating if the pathway is writable (defaults to true)
|
|
326
|
+
* @param contract The pathway contract describing the pathway
|
|
327
|
+
* @returns The PathwaysBuilder instance with the new pathway registered
|
|
328
|
+
*/
|
|
283
329
|
register(contract) {
|
|
284
330
|
const path = `${contract.flowType}/${contract.eventType}`;
|
|
285
331
|
const writable = contract.writable ?? true;
|
|
@@ -328,10 +374,28 @@ class PathwaysBuilder {
|
|
|
328
374
|
});
|
|
329
375
|
return this;
|
|
330
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Gets a pathway instance by its path
|
|
379
|
+
*
|
|
380
|
+
* @template TPath The specific pathway key to retrieve
|
|
381
|
+
* @param path The pathway key to get
|
|
382
|
+
* @returns The pathway instance
|
|
383
|
+
*/
|
|
331
384
|
get(path) {
|
|
332
385
|
this.logger.debug(`Getting pathway`, { pathway: String(path) });
|
|
333
386
|
return this.pathways[path];
|
|
334
387
|
}
|
|
388
|
+
/**
|
|
389
|
+
* Sets a handler function for a pathway
|
|
390
|
+
*
|
|
391
|
+
* This handler will be called whenever an event is received for the specified pathway.
|
|
392
|
+
* Only one handler can be registered per pathway in a given PathwaysBuilder instance.
|
|
393
|
+
*
|
|
394
|
+
* @template TPath The specific pathway key to handle
|
|
395
|
+
* @param path The pathway key to handle
|
|
396
|
+
* @param handler The function that will process events for this pathway
|
|
397
|
+
* @throws Error if the pathway doesn't exist or already has a handler
|
|
398
|
+
*/
|
|
335
399
|
handle(path, handler) {
|
|
336
400
|
const pathStr = String(path);
|
|
337
401
|
this.logger.debug(`Setting handler for pathway`, { pathway: pathStr });
|
|
@@ -436,12 +500,12 @@ class PathwaysBuilder {
|
|
|
436
500
|
}
|
|
437
501
|
const schema = this.schemas[path];
|
|
438
502
|
if (!value_1.Value.Check(schema, data)) {
|
|
439
|
-
const
|
|
440
|
-
this.logger.error(
|
|
503
|
+
const errorMessage = `Invalid data for pathway ${pathStr}`;
|
|
504
|
+
this.logger.error(errorMessage, new Error(errorMessage), {
|
|
441
505
|
pathway: pathStr,
|
|
442
506
|
schema: schema.toString()
|
|
443
507
|
});
|
|
444
|
-
throw new Error(
|
|
508
|
+
throw new Error(errorMessage);
|
|
445
509
|
}
|
|
446
510
|
// Create a copy of the metadata to avoid modifying the original
|
|
447
511
|
const finalMetadata = metadata ? { ...metadata } : {};
|
|
@@ -493,6 +557,17 @@ class PathwaysBuilder {
|
|
|
493
557
|
}
|
|
494
558
|
return eventIds;
|
|
495
559
|
}
|
|
560
|
+
/**
|
|
561
|
+
* Waits for a specific event to be processed
|
|
562
|
+
*
|
|
563
|
+
* This method polls the pathway state to check if an event has been processed,
|
|
564
|
+
* with a configurable timeout. It will throw an error if the timeout is exceeded.
|
|
565
|
+
*
|
|
566
|
+
* @private
|
|
567
|
+
* @param eventId The ID of the event to wait for
|
|
568
|
+
* @returns Promise that resolves when the event is processed
|
|
569
|
+
* @throws Error if the timeout is exceeded
|
|
570
|
+
*/
|
|
496
571
|
async waitForPathwayToBeProcessed(eventId) {
|
|
497
572
|
const startTime = Date.now();
|
|
498
573
|
const timeoutMs = this.timeouts[eventId] ?? this.pathwayTimeoutMs;
|
|
@@ -505,14 +580,14 @@ class PathwaysBuilder {
|
|
|
505
580
|
attempts++;
|
|
506
581
|
const elapsedTime = Date.now() - startTime;
|
|
507
582
|
if (elapsedTime > timeoutMs) {
|
|
508
|
-
const
|
|
509
|
-
this.logger.error(
|
|
583
|
+
const errorMessage = `Pathway processing timed out after ${timeoutMs}ms for event ${eventId}`;
|
|
584
|
+
this.logger.error(errorMessage, new Error(errorMessage), {
|
|
510
585
|
eventId,
|
|
511
586
|
timeoutMs,
|
|
512
587
|
elapsedTime,
|
|
513
588
|
attempts
|
|
514
589
|
});
|
|
515
|
-
throw new Error(
|
|
590
|
+
throw new Error(errorMessage);
|
|
516
591
|
}
|
|
517
592
|
if (attempts % 10 === 0) { // Log every 10 attempts (1 second)
|
|
518
593
|
this.logger.debug(`Still waiting for event to be processed`, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pathways/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,cAAc,cAAc,CAAC;AAC7B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC"}
|
package/script/pathways/index.js
CHANGED
|
@@ -23,6 +23,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
23
23
|
* - Storage adapters (KV, Postgres)
|
|
24
24
|
* - Logging
|
|
25
25
|
* - Type definitions
|
|
26
|
+
*
|
|
27
|
+
* @module
|
|
26
28
|
*/
|
|
27
29
|
__exportStar(require("./builder.js"), exports);
|
|
28
30
|
__exportStar(require("./internal-pathway.state.js"), exports);
|