@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.
Files changed (98) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/esm/common/flowcore.type.d.ts +3 -3
  3. package/esm/common/flowcore.type.d.ts.map +1 -1
  4. package/esm/common/index.d.ts +2 -0
  5. package/esm/common/index.d.ts.map +1 -1
  6. package/esm/common/index.js +2 -0
  7. package/esm/compatibility/flowcore-transformer-core.sdk.d.ts +4 -0
  8. package/esm/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -1
  9. package/esm/compatibility/flowcore-transformer-core.sdk.js +2 -0
  10. package/esm/contracts/index.d.ts +2 -0
  11. package/esm/contracts/index.d.ts.map +1 -1
  12. package/esm/contracts/index.js +2 -0
  13. package/esm/mod.d.ts +2 -0
  14. package/esm/mod.d.ts.map +1 -1
  15. package/esm/mod.js +2 -0
  16. package/esm/pathways/builder.d.ts +87 -0
  17. package/esm/pathways/builder.d.ts.map +1 -1
  18. package/esm/pathways/builder.js +83 -8
  19. package/esm/pathways/index.d.ts +2 -0
  20. package/esm/pathways/index.d.ts.map +1 -1
  21. package/esm/pathways/index.js +2 -0
  22. package/esm/pathways/internal-pathway.state.d.ts +5 -7
  23. package/esm/pathways/internal-pathway.state.d.ts.map +1 -1
  24. package/esm/pathways/internal-pathway.state.js +5 -7
  25. package/esm/pathways/kv/bun-kv-adapter.d.ts +5 -7
  26. package/esm/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
  27. package/esm/pathways/kv/bun-kv-adapter.js +5 -7
  28. package/esm/pathways/kv/kv-adapter.d.ts +7 -7
  29. package/esm/pathways/kv/kv-adapter.js +1 -1
  30. package/esm/pathways/kv/node-kv-adapter.d.ts +6 -8
  31. package/esm/pathways/kv/node-kv-adapter.d.ts.map +1 -1
  32. package/esm/pathways/kv/node-kv-adapter.js +6 -8
  33. package/esm/pathways/logger.d.ts +46 -3
  34. package/esm/pathways/logger.d.ts.map +1 -1
  35. package/esm/pathways/logger.js +45 -3
  36. package/esm/pathways/postgres/index.d.ts +2 -0
  37. package/esm/pathways/postgres/index.d.ts.map +1 -1
  38. package/esm/pathways/postgres/index.js +2 -0
  39. package/esm/pathways/postgres/postgres-adapter.d.ts +20 -29
  40. package/esm/pathways/postgres/postgres-adapter.d.ts.map +1 -1
  41. package/esm/pathways/postgres/postgres-adapter.js +12 -17
  42. package/esm/pathways/postgres/postgres-pathway-state.d.ts +2 -6
  43. package/esm/pathways/postgres/postgres-pathway-state.d.ts.map +1 -1
  44. package/esm/pathways/postgres/postgres-pathway-state.js +2 -4
  45. package/esm/pathways/types.d.ts +48 -3
  46. package/esm/pathways/types.d.ts.map +1 -1
  47. package/esm/router/index.d.ts +17 -11
  48. package/esm/router/index.d.ts.map +1 -1
  49. package/esm/router/index.js +21 -24
  50. package/package.json +2 -2
  51. package/script/common/flowcore.type.d.ts +3 -3
  52. package/script/common/flowcore.type.d.ts.map +1 -1
  53. package/script/common/index.d.ts +2 -0
  54. package/script/common/index.d.ts.map +1 -1
  55. package/script/common/index.js +2 -0
  56. package/script/compatibility/flowcore-transformer-core.sdk.d.ts +4 -0
  57. package/script/compatibility/flowcore-transformer-core.sdk.d.ts.map +1 -1
  58. package/script/compatibility/flowcore-transformer-core.sdk.js +2 -0
  59. package/script/contracts/index.d.ts +2 -0
  60. package/script/contracts/index.d.ts.map +1 -1
  61. package/script/contracts/index.js +2 -0
  62. package/script/mod.d.ts +2 -0
  63. package/script/mod.d.ts.map +1 -1
  64. package/script/mod.js +2 -0
  65. package/script/pathways/builder.d.ts +87 -0
  66. package/script/pathways/builder.d.ts.map +1 -1
  67. package/script/pathways/builder.js +83 -8
  68. package/script/pathways/index.d.ts +2 -0
  69. package/script/pathways/index.d.ts.map +1 -1
  70. package/script/pathways/index.js +2 -0
  71. package/script/pathways/internal-pathway.state.d.ts +5 -7
  72. package/script/pathways/internal-pathway.state.d.ts.map +1 -1
  73. package/script/pathways/internal-pathway.state.js +5 -7
  74. package/script/pathways/kv/bun-kv-adapter.d.ts +5 -7
  75. package/script/pathways/kv/bun-kv-adapter.d.ts.map +1 -1
  76. package/script/pathways/kv/bun-kv-adapter.js +5 -7
  77. package/script/pathways/kv/kv-adapter.d.ts +7 -7
  78. package/script/pathways/kv/kv-adapter.js +1 -1
  79. package/script/pathways/kv/node-kv-adapter.d.ts +6 -8
  80. package/script/pathways/kv/node-kv-adapter.d.ts.map +1 -1
  81. package/script/pathways/kv/node-kv-adapter.js +6 -8
  82. package/script/pathways/logger.d.ts +46 -3
  83. package/script/pathways/logger.d.ts.map +1 -1
  84. package/script/pathways/logger.js +45 -3
  85. package/script/pathways/postgres/index.d.ts +2 -0
  86. package/script/pathways/postgres/index.d.ts.map +1 -1
  87. package/script/pathways/postgres/index.js +2 -0
  88. package/script/pathways/postgres/postgres-adapter.d.ts +20 -29
  89. package/script/pathways/postgres/postgres-adapter.d.ts.map +1 -1
  90. package/script/pathways/postgres/postgres-adapter.js +12 -17
  91. package/script/pathways/postgres/postgres-pathway-state.d.ts +2 -6
  92. package/script/pathways/postgres/postgres-pathway-state.d.ts.map +1 -1
  93. package/script/pathways/postgres/postgres-pathway-state.js +2 -4
  94. package/script/pathways/types.d.ts +48 -3
  95. package/script/pathways/types.d.ts.map +1 -1
  96. package/script/router/index.d.ts +17 -11
  97. package/script/router/index.d.ts.map +1 -1
  98. package/script/router/index.js +21 -24
@@ -1,8 +1,6 @@
1
1
  import type { PathwayState } from "../types.js";
2
2
  /**
3
3
  * Configuration options for PostgreSQL pathway state storage
4
- *
5
- * @interface PostgresPathwayStateConfig
6
4
  */
7
5
  export interface PostgresPathwayStateConfig {
8
6
  /** PostgreSQL server hostname */
@@ -27,8 +25,6 @@ export interface PostgresPathwayStateConfig {
27
25
  *
28
26
  * This class provides persistent storage of pathway state using a PostgreSQL database,
29
27
  * which allows for state to be shared across multiple instances of the application.
30
- *
31
- * @implements {PathwayState}
32
28
  */
33
29
  export declare class PostgresPathwayState implements PathwayState {
34
30
  private config;
@@ -106,8 +102,8 @@ export declare class PostgresPathwayState implements PathwayState {
106
102
  /**
107
103
  * Creates a new PostgreSQL pathway state instance
108
104
  *
109
- * @param {PostgresPathwayStateConfig} config The PostgreSQL configuration
110
- * @returns {PostgresPathwayState} A new PostgresPathwayState instance
105
+ * @param config The PostgreSQL configuration
106
+ * @returns A new PostgresPathwayState instance
111
107
  */
112
108
  export declare function createPostgresPathwayState(config: PostgresPathwayStateConfig): PostgresPathwayState;
113
109
  //# sourceMappingURL=postgres-pathway-state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"postgres-pathway-state.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-pathway-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;;;GAIG;AACH,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IA0C3C,OAAO,CAAC,MAAM;IAzC1B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAmB;IAE7D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAkB;IAElC;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;OAIG;gBACiB,MAAM,EAAE,0BAA0B;IAMtD;;;;;OAKG;YACW,UAAU;IAgCxB;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAcpD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelD;;;;;OAKG;YACW,cAAc;IAQ5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAGnG"}
1
+ {"version":3,"file":"postgres-pathway-state.d.ts","sourceRoot":"","sources":["../../../src/pathways/postgres/postgres-pathway-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIhD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IA0C3C,OAAO,CAAC,MAAM;IAzC1B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEvD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAmB;IAE7D;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAkB;IAElC;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B;;;;OAIG;gBACiB,MAAM,EAAE,0BAA0B;IAMtD;;;;;OAKG;YACW,UAAU;IAgCxB;;;;;OAKG;IACG,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAcpD;;;;;OAKG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAelD;;;;;OAKG;YACW,cAAc;IAQ5B;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAGnG"}
@@ -8,8 +8,6 @@ const postgres_adapter_js_1 = require("./postgres-adapter.js");
8
8
  *
9
9
  * This class provides persistent storage of pathway state using a PostgreSQL database,
10
10
  * which allows for state to be shared across multiple instances of the application.
11
- *
12
- * @implements {PathwayState}
13
11
  */
14
12
  class PostgresPathwayState {
15
13
  /**
@@ -184,8 +182,8 @@ Object.defineProperty(PostgresPathwayState, "DEFAULT_TABLE_NAME", {
184
182
  /**
185
183
  * Creates a new PostgreSQL pathway state instance
186
184
  *
187
- * @param {PostgresPathwayStateConfig} config The PostgreSQL configuration
188
- * @returns {PostgresPathwayState} A new PostgresPathwayState instance
185
+ * @param config The PostgreSQL configuration
186
+ * @returns A new PostgresPathwayState instance
189
187
  */
190
188
  function createPostgresPathwayState(config) {
191
189
  const state = new PostgresPathwayState(config);
@@ -2,19 +2,29 @@ import type { TSchema } from "@sinclair/typebox";
2
2
  import type { WebhookFileData, WebhookSendOptions } from "@flowcore/sdk-transformer-core";
3
3
  /**
4
4
  * Helper type to create a custom type error for non-writable pathways
5
+ * @template T The string type to create an error for
5
6
  */
6
7
  type NonWritablePathwayError<T extends string> = T & {
7
8
  readonly __nonWritablePathwayError: "This pathway is not writable. To make it writable, remove 'writable: false' from the pathway contract.";
8
9
  };
9
10
  /**
10
11
  * Contract for defining a pathway
11
- * @template F - The flow type
12
- * @template E - The event type
13
- * @template T - The schema type
12
+ * @template F The flow type
13
+ * @template E The event type
14
+ * @template T The schema type
14
15
  */
15
16
  export interface PathwayContract<F extends string, E extends string, T extends TSchema> {
17
+ /**
18
+ * The flow type for this pathway
19
+ */
16
20
  flowType: F;
21
+ /**
22
+ * The event type for this pathway
23
+ */
17
24
  eventType: E;
25
+ /**
26
+ * The schema that defines the structure of events for this pathway
27
+ */
18
28
  schema: T;
19
29
  /**
20
30
  * Whether the pathway is writable. Use `false as const` to make the pathway non-writable at compile time.
@@ -63,24 +73,59 @@ export interface PathwayContract<F extends string, E extends string, T extends T
63
73
  */
64
74
  isFilePathway?: boolean;
65
75
  }
76
+ /**
77
+ * Creates a string key from flow type and event type in the format `flowType/eventType`
78
+ * @template F The flow type
79
+ * @template E The event type
80
+ */
66
81
  export type PathwayKey<F extends string, E extends string> = `${F}/${E}`;
82
+ /**
83
+ * Interface for event metadata, extending Record<string, unknown>
84
+ */
67
85
  export interface EventMetadata extends Record<string, unknown> {
68
86
  }
87
+ /**
88
+ * Function type for sending an event to a webhook
89
+ * @template EventPayload The type of the event payload
90
+ */
69
91
  export type SendWebhook<EventPayload> = (payload: EventPayload, metadata?: EventMetadata, options?: WebhookSendOptions) => Promise<string>;
92
+ /**
93
+ * Function type for sending a file to a webhook
94
+ */
70
95
  export type SendFilehook = (payload: WebhookFileData, metadata?: EventMetadata, options?: WebhookSendOptions) => Promise<string[]>;
71
96
  /**
72
97
  * Helper type to create a better error message for non-writable pathways
98
+ * @template T The string type for the pathway
99
+ * @template IsWritable Boolean indicating if the pathway is writable
73
100
  */
74
101
  export type WritablePathway<T extends string, IsWritable extends boolean> = IsWritable extends false ? NonWritablePathwayError<T> : T;
102
+ /**
103
+ * Interface for managing pathway processing state
104
+ */
75
105
  export type PathwayState = {
106
+ /**
107
+ * Checks if an event has been processed
108
+ * @param eventId The ID of the event to check
109
+ * @returns Boolean indicating if the event has been processed
110
+ */
76
111
  isProcessed: (eventId: string) => (boolean | Promise<boolean>);
112
+ /**
113
+ * Marks an event as processed
114
+ * @param eventId The ID of the event to mark as processed
115
+ */
77
116
  setProcessed: (eventId: string) => (void | Promise<void>);
78
117
  };
79
118
  /**
80
119
  * Options for pathway writes, extending WebhookSendOptions
81
120
  */
82
121
  export type PathwayWriteOptions = WebhookSendOptions & {
122
+ /**
123
+ * If true, doesn't wait for confirmation of event delivery
124
+ */
83
125
  fireAndForget?: boolean;
126
+ /**
127
+ * Additional HTTP headers to include with the request
128
+ */
84
129
  headers?: Record<string, string>;
85
130
  };
86
131
  export {};
@@ -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;;GAEG;AACH,KAAK,uBAAuB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IACnD,QAAQ,CAAC,yBAAyB,EAAE,wGAAwG,CAAA;CAC7I,CAAA;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO;IACpF,QAAQ,EAAE,CAAC,CAAA;IACX,SAAS,EAAE,CAAC,CAAA;IACZ,MAAM,EAAE,CAAC,CAAA;IACT;;;;;;;;;;;;;;;;;;;;OAoBG;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Ac,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAAG;AAEjE;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,YAAY,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;AAE1I;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;AAElI;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,SAAS,OAAO,IAAI,UAAU,SAAS,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"}
@@ -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 {PathwaysBuilder<Record<string, any>>} pathways - The pathways builder instance that contains all registered pathways
17
- * @param {string} secretKey - Secret key used for authentication when processing events
18
- * @param {Logger} [logger] - Optional logger instance (defaults to NoopLogger if not provided)
19
- * @throws {Error} Will throw an error if secretKey is empty or not provided
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
- * Processes an incoming event by routing it to the appropriate pathway
29
+ * Process an incoming event by routing it to the appropriate pathway handler
24
30
  *
25
- * @param {FlowcoreLegacyEvent} event - The event to process
26
- * @param {string} providedSecret - The secret key provided for authentication
27
- * @returns {Promise<{ success: boolean; message: string }>} Result of the event processing
28
- * @throws {Error} Will throw an error if authentication fails, pathway is not found, or processing fails
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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OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAkDvH"}
@@ -4,17 +4,15 @@ exports.PathwayRouter = void 0;
4
4
  const logger_js_1 = require("../pathways/logger.js");
5
5
  /**
6
6
  * Router class that handles directing events to the appropriate pathway handlers
7
- *
8
- * @class PathwayRouter
9
7
  */
10
8
  class PathwayRouter {
11
9
  /**
12
10
  * Creates a new instance of PathwayRouter
13
11
  *
14
- * @param {PathwaysBuilder<Record<string, any>>} pathways - The pathways builder instance that contains all registered pathways
15
- * @param {string} secretKey - Secret key used for authentication when processing events
16
- * @param {Logger} [logger] - Optional logger instance (defaults to NoopLogger if not provided)
17
- * @throws {Error} Will throw an error if secretKey is empty or not provided
12
+ * @param pathways The pathways builder instance that contains all registered pathways
13
+ * @param secretKey Secret key used for authentication when processing events
14
+ * @param logger Optional logger instance (defaults to NoopLogger if not provided)
15
+ * @throws Error if secretKey is empty or not provided
18
16
  */
19
17
  constructor(
20
18
  // deno-lint-ignore no-explicit-any
@@ -39,24 +37,26 @@ class PathwayRouter {
39
37
  });
40
38
  this.logger = logger ?? new logger_js_1.NoopLogger();
41
39
  if (!secretKey || secretKey.trim() === "") {
42
- this.logger.error("Secret key is required for PathwayRouter");
43
- throw new Error("Secret key is required for PathwayRouter");
40
+ const errorMsg = "Secret key is required for PathwayRouter";
41
+ this.logger.error(errorMsg, new Error(errorMsg));
42
+ throw new Error(errorMsg);
44
43
  }
45
44
  this.logger.debug("PathwayRouter initialized");
46
45
  }
47
46
  /**
48
- * Processes an incoming event by routing it to the appropriate pathway
47
+ * Process an incoming event by routing it to the appropriate pathway handler
49
48
  *
50
- * @param {FlowcoreLegacyEvent} event - The event to process
51
- * @param {string} providedSecret - The secret key provided for authentication
52
- * @returns {Promise<{ success: boolean; message: string }>} Result of the event processing
53
- * @throws {Error} Will throw an error if authentication fails, pathway is not found, or processing fails
49
+ * @param event The event to process
50
+ * @param providedSecret The secret key provided for authentication
51
+ * @returns Result of the event processing with success status and message
52
+ * @throws Error if authentication fails, pathway is not found, or processing fails
54
53
  */
55
54
  async processEvent(event, providedSecret) {
56
55
  // Validate secret key
57
56
  if (!providedSecret || providedSecret !== this.secretKey) {
58
- this.logger.error("Invalid secret key provided");
59
- throw new Error("Invalid secret key");
57
+ const errorMsg = "Invalid secret key";
58
+ this.logger.error(errorMsg, new Error(errorMsg));
59
+ throw new Error(errorMsg);
60
60
  }
61
61
  const compatibleEvent = {
62
62
  ...event,
@@ -68,9 +68,9 @@ class PathwayRouter {
68
68
  });
69
69
  const pathway = this.pathways.get(pathwayKey);
70
70
  if (!pathway) {
71
- const error = `Pathway ${pathwayKey} not found`;
72
- this.logger.error(error);
73
- throw new Error(error);
71
+ const errorMsg = `Pathway ${pathwayKey} not found`;
72
+ this.logger.error(errorMsg, new Error(errorMsg));
73
+ throw new Error(errorMsg);
74
74
  }
75
75
  try {
76
76
  this.logger.debug(`Delegating event processing to pathway handler`, {
@@ -85,15 +85,12 @@ class PathwayRouter {
85
85
  return { success: true, message: `Event processed through pathway ${pathwayKey}` };
86
86
  }
87
87
  catch (error) {
88
- const errorMessage = error instanceof Error
89
- ? error.message
90
- : String(error);
91
- this.logger.error(`Error processing pathway ${pathwayKey}`, {
92
- error: errorMessage,
88
+ const errorObj = error instanceof Error ? error : new Error(String(error));
89
+ this.logger.error(`Error processing pathway ${pathwayKey}`, errorObj, {
93
90
  eventId: compatibleEvent.eventId
94
91
  });
95
92
  // Rethrow the error with additional context
96
- throw new Error(`Failed to process event in pathway ${pathwayKey}: ${errorMessage}`);
93
+ throw new Error(`Failed to process event in pathway ${pathwayKey}: ${errorObj.message}`);
97
94
  }
98
95
  }
99
96
  }