@flowcore/pathways 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +14 -14
- package/esm/contracts/event.d.ts +11 -19
- package/esm/contracts/event.d.ts.map +1 -1
- package/esm/contracts/event.js +1 -15
- package/esm/pathways/builder.d.ts +18 -18
- package/esm/pathways/builder.d.ts.map +1 -1
- package/esm/pathways/builder.js +16 -11
- package/esm/pathways/session-pathway.d.ts +5 -2
- package/esm/pathways/session-pathway.d.ts.map +1 -1
- package/esm/pathways/types.d.ts +2 -2
- package/esm/pathways/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/script/contracts/event.d.ts +11 -19
- package/script/contracts/event.d.ts.map +1 -1
- package/script/contracts/event.js +0 -16
- package/script/pathways/builder.d.ts +18 -18
- package/script/pathways/builder.d.ts.map +1 -1
- package/script/pathways/builder.js +16 -11
- package/script/pathways/session-pathway.d.ts +5 -2
- package/script/pathways/session-pathway.d.ts.map +1 -1
- package/script/pathways/types.d.ts +2 -2
- package/script/pathways/types.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.14.0](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.2...v0.14.0) (2025-05-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* switch from typebox to zod ([e20e8f8](https://github.com/flowcore-io/flowcore-pathways/commit/e20e8f81a9cf68eaa598be5d43ef34f346f136ea))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* fix tests ([05496b9](https://github.com/flowcore-io/flowcore-pathways/commit/05496b993669449d8bfe758e2647d4f2a2dbbf06))
|
|
14
|
+
* set defaults on write and process ([c01ac59](https://github.com/flowcore-io/flowcore-pathways/commit/c01ac59cd4097d832c009e90e7259644e84a9612))
|
|
15
|
+
|
|
3
16
|
## [0.13.2](https://github.com/flowcore-io/flowcore-pathways/compare/v0.13.1...v0.13.2) (2025-05-14)
|
|
4
17
|
|
|
5
18
|
|
package/README.md
CHANGED
|
@@ -55,14 +55,14 @@ yarn add @flowcore/pathways
|
|
|
55
55
|
Here's a basic example to get you started with Flowcore Pathways:
|
|
56
56
|
|
|
57
57
|
```typescript
|
|
58
|
-
import {
|
|
58
|
+
import { z } from "zod"
|
|
59
59
|
import { PathwaysBuilder } from "@flowcore/pathways"
|
|
60
60
|
|
|
61
61
|
// Define your event schema
|
|
62
|
-
const userSchema =
|
|
63
|
-
id:
|
|
64
|
-
name:
|
|
65
|
-
email:
|
|
62
|
+
const userSchema = z.object({
|
|
63
|
+
id: z.string(),
|
|
64
|
+
name: z.string(),
|
|
65
|
+
email: z.string(),
|
|
66
66
|
})
|
|
67
67
|
|
|
68
68
|
// Create a pathways builder
|
|
@@ -130,17 +130,17 @@ const pathways = new PathwaysBuilder({
|
|
|
130
130
|
Register pathways with their schemas for type-safe event handling:
|
|
131
131
|
|
|
132
132
|
```typescript
|
|
133
|
-
import {
|
|
133
|
+
import { z } from "zod"
|
|
134
134
|
|
|
135
135
|
// Define your event schema
|
|
136
|
-
const orderSchema =
|
|
137
|
-
orderId:
|
|
138
|
-
userId:
|
|
139
|
-
total:
|
|
140
|
-
items:
|
|
141
|
-
|
|
142
|
-
id:
|
|
143
|
-
quantity:
|
|
136
|
+
const orderSchema = z.object({
|
|
137
|
+
orderId: z.string(),
|
|
138
|
+
userId: z.string(),
|
|
139
|
+
total: z.number(),
|
|
140
|
+
items: z.array(
|
|
141
|
+
z.Object({
|
|
142
|
+
id: z.string(),
|
|
143
|
+
quantity: z.number(),
|
|
144
144
|
}),
|
|
145
145
|
),
|
|
146
146
|
})
|
package/esm/contracts/event.d.ts
CHANGED
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
metadata: TRecord<TString, TUnknown>;
|
|
13
|
-
payload: TRecord<TString, TUnknown>;
|
|
14
|
-
validTime: TString;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* The type for an event
|
|
18
|
-
*/
|
|
19
|
-
export type FlowcoreEvent = Static<typeof FlowcoreEventSchema>;
|
|
1
|
+
export interface FlowcoreEvent<Payload = unknown, Metadata = Record<string, unknown>> {
|
|
2
|
+
eventId: string;
|
|
3
|
+
timeBucket: string;
|
|
4
|
+
tenant: string;
|
|
5
|
+
dataCoreId: string;
|
|
6
|
+
flowType: string;
|
|
7
|
+
eventType: string;
|
|
8
|
+
metadata: Metadata;
|
|
9
|
+
payload: Payload;
|
|
10
|
+
validTime: string;
|
|
11
|
+
}
|
|
20
12
|
//# sourceMappingURL=event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/contracts/event.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/contracts/event.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,OAAO,GAAG,OAAO,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClF,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB"}
|
package/esm/contracts/event.js
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* The schema for an event
|
|
4
|
-
*/
|
|
5
|
-
export const FlowcoreEventSchema = Type.Object({
|
|
6
|
-
eventId: Type.String(),
|
|
7
|
-
timeBucket: Type.String(),
|
|
8
|
-
tenant: Type.String(),
|
|
9
|
-
dataCoreId: Type.String(),
|
|
10
|
-
flowType: Type.String(),
|
|
11
|
-
eventType: Type.String(),
|
|
12
|
-
metadata: Type.Record(Type.String(), Type.Unknown()),
|
|
13
|
-
payload: Type.Record(Type.String(), Type.Unknown()),
|
|
14
|
-
validTime: Type.String(),
|
|
15
|
-
});
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z, type ZodTypeAny } from "zod";
|
|
2
2
|
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";
|
|
@@ -45,7 +45,7 @@ export interface AuditWebhookSendOptions extends WebhookSendOptions {
|
|
|
45
45
|
* @property warn Log level for warn messages
|
|
46
46
|
* @property error Log level for error messages
|
|
47
47
|
*/
|
|
48
|
-
export type LogLevel = keyof Pick<Logger,
|
|
48
|
+
export type LogLevel = keyof Pick<Logger, "debug" | "info" | "warn" | "error">;
|
|
49
49
|
/**
|
|
50
50
|
* Configuration for log levels
|
|
51
51
|
* @property writeSuccess Log level used when a write operation is successful. Defaults to 'info'.
|
|
@@ -118,7 +118,10 @@ export declare class SessionUser implements SessionUserResolver {
|
|
|
118
118
|
* @template TPathway Record type that maps pathway keys to their payload types
|
|
119
119
|
* @template TWritablePaths Union type of pathway keys that can be written to
|
|
120
120
|
*/
|
|
121
|
-
export declare class PathwaysBuilder<TPathway extends Record<string,
|
|
121
|
+
export declare class PathwaysBuilder<TPathway extends Record<string, {
|
|
122
|
+
input: unknown;
|
|
123
|
+
output: unknown;
|
|
124
|
+
}> = {}, TWritablePaths extends keyof TPathway = never> {
|
|
122
125
|
private readonly pathways;
|
|
123
126
|
private readonly handlers;
|
|
124
127
|
private readonly beforeObservable;
|
|
@@ -239,16 +242,19 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
239
242
|
* Registers a new pathway with the given contract
|
|
240
243
|
* @template F The flow type string
|
|
241
244
|
* @template E The event type string
|
|
242
|
-
* @template S The schema type extending
|
|
245
|
+
* @template S The schema type extending ZodTypeAny
|
|
243
246
|
* @template W Boolean indicating if the pathway is writable (defaults to true)
|
|
244
247
|
* @param contract The pathway contract describing the pathway
|
|
245
248
|
* @returns The PathwaysBuilder instance with the new pathway registered
|
|
246
249
|
*/
|
|
247
|
-
register<F extends string, E extends string, S extends
|
|
250
|
+
register<F extends string, E extends string, S extends ZodTypeAny, W extends boolean = true>(contract: PathwayContract<F, E, S> & {
|
|
248
251
|
writable?: W;
|
|
249
252
|
maxRetries?: number;
|
|
250
253
|
retryDelayMs?: number;
|
|
251
|
-
}): PathwaysBuilder<TPathway & Record<PathwayKey<F, E>,
|
|
254
|
+
}): PathwaysBuilder<TPathway & Record<PathwayKey<F, E>, {
|
|
255
|
+
output: z.infer<S>;
|
|
256
|
+
input: z.input<S>;
|
|
257
|
+
}>, TWritablePaths | WritablePathway<PathwayKey<F, E>, W>>;
|
|
252
258
|
/**
|
|
253
259
|
* Gets a pathway instance by its path
|
|
254
260
|
*
|
|
@@ -256,7 +262,7 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
256
262
|
* @param path The pathway key to get
|
|
257
263
|
* @returns The pathway instance
|
|
258
264
|
*/
|
|
259
|
-
get<TPath extends keyof TPathway>(path: TPath): TPathway[TPath];
|
|
265
|
+
get<TPath extends keyof TPathway>(path: TPath): TPathway[TPath]["output"];
|
|
260
266
|
/**
|
|
261
267
|
* Sets a handler function for a pathway
|
|
262
268
|
*
|
|
@@ -268,26 +274,20 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
268
274
|
* @param handler The function that will process events for this pathway
|
|
269
275
|
* @throws Error if the pathway doesn't exist or already has a handler
|
|
270
276
|
*/
|
|
271
|
-
handle<TPath extends keyof TPathway>(path: TPath, handler: (event:
|
|
272
|
-
payload: TPathway[TPath];
|
|
273
|
-
}) => Promise<void> | void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
277
|
+
handle<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent<TPathway[TPath]["output"]>) => Promise<void> | void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
274
278
|
/**
|
|
275
279
|
* Subscribe to pathway events (before or after processing)
|
|
276
280
|
* @param path The pathway to subscribe to
|
|
277
281
|
* @param handler The handler function for the events
|
|
278
282
|
* @param type The event type to subscribe to (before, after, or all)
|
|
279
283
|
*/
|
|
280
|
-
subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event:
|
|
281
|
-
payload: TPathway[TPath];
|
|
282
|
-
}) => void, type?: "before" | "after" | "all"): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
284
|
+
subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent<TPathway[TPath]["output"]>) => void, type?: "before" | "after" | "all"): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
283
285
|
/**
|
|
284
286
|
* Subscribe to errors for a specific pathway
|
|
285
287
|
* @param path The pathway to subscribe to errors for
|
|
286
288
|
* @param handler The handler function that receives the error and event
|
|
287
289
|
*/
|
|
288
|
-
onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event:
|
|
289
|
-
payload: TPathway[TPath];
|
|
290
|
-
}) => void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
290
|
+
onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event: FlowcoreEvent<TPathway[TPath]["output"]>) => void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
291
291
|
/**
|
|
292
292
|
* Subscribe to errors for all pathways
|
|
293
293
|
* @param handler The handler function that receives the error, event, and pathway name
|
|
@@ -301,8 +301,8 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
301
301
|
* @param options Optional write options
|
|
302
302
|
* @returns A promise that resolves to the event ID(s)
|
|
303
303
|
*/
|
|
304
|
-
write<TPath extends TWritablePaths>(path: TPath,
|
|
305
|
-
writeBatch<TPath extends TWritablePaths>(path: TPath,
|
|
304
|
+
write<TPath extends TWritablePaths>(path: TPath, inputData: TPathway[TPath]["input"], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
305
|
+
writeBatch<TPath extends TWritablePaths>(path: TPath, inputData: TPathway[TPath]["input"][], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
306
306
|
/**
|
|
307
307
|
* Waits for a specific event to be processed
|
|
308
308
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAA;AACxC,OAAO,KAAK,EAGV,kBAAkB,EACnB,MAAM,gCAAgC,CAAA;AAGvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,UAAU,EACV,YAAY,EACZ,mBAAmB,EAInB,eAAe,EAChB,MAAM,YAAY,CAAA;AA8BnB;;;;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,CAA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KAAgB,GAC1C,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC;IA8B5C;;;;OAIG;IACH,OAAO,CAAC,KAAK,SAAS,MAAM,QAAQ,EAClC,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,IAAI,GAC/E,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC;IAqB5C;;;OAGG;IACH,UAAU,CACR,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GACrE,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC;IAQ5C;;;;;;;OAOG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EACnC,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IAgIvB,UAAU,CAAC,KAAK,SAAS,cAAc,EAC3C,IAAI,EAAE,KAAK,EACX,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,EACrC,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IA8H7B;;;;;;;;;;OAUG;YACW,2BAA2B;CA4C1C"}
|
package/esm/pathways/builder.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Value } from "@sinclair/typebox/value";
|
|
1
|
+
import { z } from "zod";
|
|
3
2
|
import { Subject } from "rxjs";
|
|
4
3
|
import { WebhookBuilder } from "../compatibility/flowcore-transformer-core.sdk.js";
|
|
5
4
|
import { InternalPathwayState } from "./internal-pathway.state.js";
|
|
@@ -269,7 +268,7 @@ export class PathwaysBuilder {
|
|
|
269
268
|
this.logger = logger ?? new NoopLogger();
|
|
270
269
|
// Initialize log levels with defaults
|
|
271
270
|
this.logLevel = {
|
|
272
|
-
writeSuccess: logLevel?.writeSuccess ??
|
|
271
|
+
writeSuccess: logLevel?.writeSuccess ?? "info",
|
|
273
272
|
};
|
|
274
273
|
// Store configuration values for cloning
|
|
275
274
|
this.baseUrl = baseUrl;
|
|
@@ -402,9 +401,9 @@ export class PathwaysBuilder {
|
|
|
402
401
|
}
|
|
403
402
|
// Validate event payload against schema if available
|
|
404
403
|
if (this.schemas[pathway]) {
|
|
404
|
+
const parsedPayload = this.schemas[pathway].safeParse(data.payload);
|
|
405
405
|
try {
|
|
406
|
-
|
|
407
|
-
if (!isValid) {
|
|
406
|
+
if (!parsedPayload.success) {
|
|
408
407
|
const error = `Event payload does not match schema for pathway ${pathwayStr}`;
|
|
409
408
|
this.logger.error(error);
|
|
410
409
|
throw new Error(error);
|
|
@@ -415,6 +414,7 @@ export class PathwaysBuilder {
|
|
|
415
414
|
this.logger.error(error);
|
|
416
415
|
throw new Error(error);
|
|
417
416
|
}
|
|
417
|
+
data.payload = parsedPayload.data;
|
|
418
418
|
}
|
|
419
419
|
// Call audit handler if configured
|
|
420
420
|
if (this.auditHandler) {
|
|
@@ -515,7 +515,7 @@ export class PathwaysBuilder {
|
|
|
515
515
|
* Registers a new pathway with the given contract
|
|
516
516
|
* @template F The flow type string
|
|
517
517
|
* @template E The event type string
|
|
518
|
-
* @template S The schema type extending
|
|
518
|
+
* @template S The schema type extending ZodTypeAny
|
|
519
519
|
* @template W Boolean indicating if the pathway is writable (defaults to true)
|
|
520
520
|
* @param contract The pathway contract describing the pathway
|
|
521
521
|
* @returns The PathwaysBuilder instance with the new pathway registered
|
|
@@ -548,7 +548,8 @@ export class PathwaysBuilder {
|
|
|
548
548
|
this.writers[path] = this.webhookBuilderFactory()
|
|
549
549
|
.buildWebhook(contract.flowType, contract.eventType).send;
|
|
550
550
|
this.batchWriters[path] = this.webhookBuilderFactory()
|
|
551
|
-
.buildWebhook(contract.flowType, contract.eventType)
|
|
551
|
+
.buildWebhook(contract.flowType, contract.eventType)
|
|
552
|
+
.sendBatch;
|
|
552
553
|
}
|
|
553
554
|
}
|
|
554
555
|
if (contract.timeoutMs) {
|
|
@@ -677,7 +678,7 @@ export class PathwaysBuilder {
|
|
|
677
678
|
* @param options Optional write options
|
|
678
679
|
* @returns A promise that resolves to the event ID(s)
|
|
679
680
|
*/
|
|
680
|
-
async write(path,
|
|
681
|
+
async write(path, inputData, metadata, options) {
|
|
681
682
|
const pathStr = String(path);
|
|
682
683
|
this.logger.debug(`Writing to pathway`, {
|
|
683
684
|
pathway: pathStr,
|
|
@@ -698,7 +699,8 @@ export class PathwaysBuilder {
|
|
|
698
699
|
throw new Error(error);
|
|
699
700
|
}
|
|
700
701
|
const schema = this.schemas[path];
|
|
701
|
-
|
|
702
|
+
const parsedData = schema.safeParse(inputData);
|
|
703
|
+
if (!parsedData.success) {
|
|
702
704
|
const errorMessage = `Invalid data for pathway ${pathStr}`;
|
|
703
705
|
this.logger.error(errorMessage, new Error(errorMessage), {
|
|
704
706
|
pathway: pathStr,
|
|
@@ -706,6 +708,7 @@ export class PathwaysBuilder {
|
|
|
706
708
|
});
|
|
707
709
|
throw new Error(errorMessage);
|
|
708
710
|
}
|
|
711
|
+
const data = parsedData.data;
|
|
709
712
|
// Create a copy of the metadata to avoid modifying the original
|
|
710
713
|
const finalMetadata = metadata ? { ...metadata } : {};
|
|
711
714
|
// Check for session-specific user resolver
|
|
@@ -784,7 +787,7 @@ export class PathwaysBuilder {
|
|
|
784
787
|
}
|
|
785
788
|
return eventIds;
|
|
786
789
|
}
|
|
787
|
-
async writeBatch(path,
|
|
790
|
+
async writeBatch(path, inputData, metadata, options) {
|
|
788
791
|
const pathStr = String(path);
|
|
789
792
|
this.logger.debug(`Writing batch to pathway`, {
|
|
790
793
|
pathway: pathStr,
|
|
@@ -805,7 +808,8 @@ export class PathwaysBuilder {
|
|
|
805
808
|
throw new Error(error);
|
|
806
809
|
}
|
|
807
810
|
const schema = this.schemas[path];
|
|
808
|
-
|
|
811
|
+
const parsedData = z.array(schema).safeParse(inputData);
|
|
812
|
+
if (!parsedData.success) {
|
|
809
813
|
const errorMessage = `Invalid batch data for pathway ${pathStr}`;
|
|
810
814
|
this.logger.error(errorMessage, new Error(errorMessage), {
|
|
811
815
|
pathway: pathStr,
|
|
@@ -813,6 +817,7 @@ export class PathwaysBuilder {
|
|
|
813
817
|
});
|
|
814
818
|
throw new Error(errorMessage);
|
|
815
819
|
}
|
|
820
|
+
const data = parsedData.data;
|
|
816
821
|
// Create a copy of the metadata to avoid modifying the original
|
|
817
822
|
const finalMetadata = metadata ? { ...metadata } : {};
|
|
818
823
|
// Check for session-specific user resolver
|
|
@@ -39,7 +39,10 @@ import type { EventMetadata, PathwayWriteOptions } from "./types.js";
|
|
|
39
39
|
* // All events will be associated with the same session ID
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare class SessionPathwayBuilder<TPathway extends Record<string,
|
|
42
|
+
export declare class SessionPathwayBuilder<TPathway extends Record<string, {
|
|
43
|
+
input: unknown;
|
|
44
|
+
output: unknown;
|
|
45
|
+
}> = {}, TWritablePaths extends keyof TPathway = never> {
|
|
43
46
|
private readonly pathwaysBuilder;
|
|
44
47
|
private readonly sessionId;
|
|
45
48
|
/**
|
|
@@ -94,6 +97,6 @@ export declare class SessionPathwayBuilder<TPathway extends Record<string, unkno
|
|
|
94
97
|
* @param options Optional write options
|
|
95
98
|
* @returns A promise that resolves to the event ID(s)
|
|
96
99
|
*/
|
|
97
|
-
write<TPath extends TWritablePaths>(path: TPath, data: TPathway[TPath], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
100
|
+
write<TPath extends TWritablePaths>(path: TPath, data: TPathway[TPath]["input"], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
98
101
|
}
|
|
99
102
|
//# sourceMappingURL=session-pathway.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-pathway.d.ts","sourceRoot":"","sources":["../../src/pathways/session-pathway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,qBAAqB,CAEhC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"session-pathway.d.ts","sourceRoot":"","sources":["../../src/pathways/session-pathway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,qBAAqB,CAEhC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,GAAG,EAAE,EACzE,cAAc,SAAS,MAAM,QAAQ,GAAG,KAAK;IAE7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2C;IAC3E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;IAElC;;;;;OAKG;gBAED,eAAe,EAAE,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,EAC1D,SAAS,CAAC,EAAE,MAAM;IAMpB;;;;OAIG;IACH,YAAY,IAAI,MAAM;IAItB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD;;;;;;;;OAQG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAC9B,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;CAU9B"}
|
package/esm/pathways/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ZodTypeAny } from "zod";
|
|
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
|
|
@@ -13,7 +13,7 @@ type NonWritablePathwayError<T extends string> = T & {
|
|
|
13
13
|
* @template E The event type
|
|
14
14
|
* @template T The schema type
|
|
15
15
|
*/
|
|
16
|
-
export interface PathwayContract<F extends string, E extends string, T extends
|
|
16
|
+
export interface PathwayContract<F extends string, E extends string, T extends ZodTypeAny> {
|
|
17
17
|
/**
|
|
18
18
|
* The flow type for this pathway
|
|
19
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pathways/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pathways/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEzF;;;GAGG;AACH,KAAK,uBAAuB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IACnD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;AACH,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,eAAe,EACxB,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,kBAAkB,KACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;AAEtB;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,UAAU,SAAS,OAAO,IAAI,UAAU,SAAS,KAAK,GAChG,uBAAuB,CAAC,CAAC,CAAC,GAC1B,CAAC,CAAA;AAEL;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;;OAIG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAE5D;;;OAGG;IACH,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACxD,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;IAEhC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAA;IAE7B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowcore/pathways",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
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-pathways#readme",
|
|
6
6
|
"repository": {
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@flowcore/sdk-transformer-core": "^2.3.6",
|
|
27
|
-
"@sinclair/typebox": "^0.34.27",
|
|
28
27
|
"node-cache": "5.1.2",
|
|
29
28
|
"postgres": "^3.4.3",
|
|
30
|
-
"rxjs": "^7.8.1"
|
|
29
|
+
"rxjs": "^7.8.1",
|
|
30
|
+
"zod": "^3.25.23"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^20.9.0",
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
metadata: TRecord<TString, TUnknown>;
|
|
13
|
-
payload: TRecord<TString, TUnknown>;
|
|
14
|
-
validTime: TString;
|
|
15
|
-
}>;
|
|
16
|
-
/**
|
|
17
|
-
* The type for an event
|
|
18
|
-
*/
|
|
19
|
-
export type FlowcoreEvent = Static<typeof FlowcoreEventSchema>;
|
|
1
|
+
export interface FlowcoreEvent<Payload = unknown, Metadata = Record<string, unknown>> {
|
|
2
|
+
eventId: string;
|
|
3
|
+
timeBucket: string;
|
|
4
|
+
tenant: string;
|
|
5
|
+
dataCoreId: string;
|
|
6
|
+
flowType: string;
|
|
7
|
+
eventType: string;
|
|
8
|
+
metadata: Metadata;
|
|
9
|
+
payload: Payload;
|
|
10
|
+
validTime: string;
|
|
11
|
+
}
|
|
20
12
|
//# sourceMappingURL=event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/contracts/event.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../src/contracts/event.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa,CAAC,OAAO,GAAG,OAAO,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClF,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;CAClB"}
|
|
@@ -1,18 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlowcoreEventSchema = void 0;
|
|
4
|
-
const typebox_1 = require("@sinclair/typebox");
|
|
5
|
-
/**
|
|
6
|
-
* The schema for an event
|
|
7
|
-
*/
|
|
8
|
-
exports.FlowcoreEventSchema = typebox_1.Type.Object({
|
|
9
|
-
eventId: typebox_1.Type.String(),
|
|
10
|
-
timeBucket: typebox_1.Type.String(),
|
|
11
|
-
tenant: typebox_1.Type.String(),
|
|
12
|
-
dataCoreId: typebox_1.Type.String(),
|
|
13
|
-
flowType: typebox_1.Type.String(),
|
|
14
|
-
eventType: typebox_1.Type.String(),
|
|
15
|
-
metadata: typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Unknown()),
|
|
16
|
-
payload: typebox_1.Type.Record(typebox_1.Type.String(), typebox_1.Type.Unknown()),
|
|
17
|
-
validTime: typebox_1.Type.String(),
|
|
18
|
-
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z, type ZodTypeAny } from "zod";
|
|
2
2
|
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";
|
|
@@ -45,7 +45,7 @@ export interface AuditWebhookSendOptions extends WebhookSendOptions {
|
|
|
45
45
|
* @property warn Log level for warn messages
|
|
46
46
|
* @property error Log level for error messages
|
|
47
47
|
*/
|
|
48
|
-
export type LogLevel = keyof Pick<Logger,
|
|
48
|
+
export type LogLevel = keyof Pick<Logger, "debug" | "info" | "warn" | "error">;
|
|
49
49
|
/**
|
|
50
50
|
* Configuration for log levels
|
|
51
51
|
* @property writeSuccess Log level used when a write operation is successful. Defaults to 'info'.
|
|
@@ -118,7 +118,10 @@ export declare class SessionUser implements SessionUserResolver {
|
|
|
118
118
|
* @template TPathway Record type that maps pathway keys to their payload types
|
|
119
119
|
* @template TWritablePaths Union type of pathway keys that can be written to
|
|
120
120
|
*/
|
|
121
|
-
export declare class PathwaysBuilder<TPathway extends Record<string,
|
|
121
|
+
export declare class PathwaysBuilder<TPathway extends Record<string, {
|
|
122
|
+
input: unknown;
|
|
123
|
+
output: unknown;
|
|
124
|
+
}> = {}, TWritablePaths extends keyof TPathway = never> {
|
|
122
125
|
private readonly pathways;
|
|
123
126
|
private readonly handlers;
|
|
124
127
|
private readonly beforeObservable;
|
|
@@ -239,16 +242,19 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
239
242
|
* Registers a new pathway with the given contract
|
|
240
243
|
* @template F The flow type string
|
|
241
244
|
* @template E The event type string
|
|
242
|
-
* @template S The schema type extending
|
|
245
|
+
* @template S The schema type extending ZodTypeAny
|
|
243
246
|
* @template W Boolean indicating if the pathway is writable (defaults to true)
|
|
244
247
|
* @param contract The pathway contract describing the pathway
|
|
245
248
|
* @returns The PathwaysBuilder instance with the new pathway registered
|
|
246
249
|
*/
|
|
247
|
-
register<F extends string, E extends string, S extends
|
|
250
|
+
register<F extends string, E extends string, S extends ZodTypeAny, W extends boolean = true>(contract: PathwayContract<F, E, S> & {
|
|
248
251
|
writable?: W;
|
|
249
252
|
maxRetries?: number;
|
|
250
253
|
retryDelayMs?: number;
|
|
251
|
-
}): PathwaysBuilder<TPathway & Record<PathwayKey<F, E>,
|
|
254
|
+
}): PathwaysBuilder<TPathway & Record<PathwayKey<F, E>, {
|
|
255
|
+
output: z.infer<S>;
|
|
256
|
+
input: z.input<S>;
|
|
257
|
+
}>, TWritablePaths | WritablePathway<PathwayKey<F, E>, W>>;
|
|
252
258
|
/**
|
|
253
259
|
* Gets a pathway instance by its path
|
|
254
260
|
*
|
|
@@ -256,7 +262,7 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
256
262
|
* @param path The pathway key to get
|
|
257
263
|
* @returns The pathway instance
|
|
258
264
|
*/
|
|
259
|
-
get<TPath extends keyof TPathway>(path: TPath): TPathway[TPath];
|
|
265
|
+
get<TPath extends keyof TPathway>(path: TPath): TPathway[TPath]["output"];
|
|
260
266
|
/**
|
|
261
267
|
* Sets a handler function for a pathway
|
|
262
268
|
*
|
|
@@ -268,26 +274,20 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
268
274
|
* @param handler The function that will process events for this pathway
|
|
269
275
|
* @throws Error if the pathway doesn't exist or already has a handler
|
|
270
276
|
*/
|
|
271
|
-
handle<TPath extends keyof TPathway>(path: TPath, handler: (event:
|
|
272
|
-
payload: TPathway[TPath];
|
|
273
|
-
}) => Promise<void> | void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
277
|
+
handle<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent<TPathway[TPath]["output"]>) => Promise<void> | void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
274
278
|
/**
|
|
275
279
|
* Subscribe to pathway events (before or after processing)
|
|
276
280
|
* @param path The pathway to subscribe to
|
|
277
281
|
* @param handler The handler function for the events
|
|
278
282
|
* @param type The event type to subscribe to (before, after, or all)
|
|
279
283
|
*/
|
|
280
|
-
subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event:
|
|
281
|
-
payload: TPathway[TPath];
|
|
282
|
-
}) => void, type?: "before" | "after" | "all"): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
284
|
+
subscribe<TPath extends keyof TPathway>(path: TPath, handler: (event: FlowcoreEvent<TPathway[TPath]["output"]>) => void, type?: "before" | "after" | "all"): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
283
285
|
/**
|
|
284
286
|
* Subscribe to errors for a specific pathway
|
|
285
287
|
* @param path The pathway to subscribe to errors for
|
|
286
288
|
* @param handler The handler function that receives the error and event
|
|
287
289
|
*/
|
|
288
|
-
onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event:
|
|
289
|
-
payload: TPathway[TPath];
|
|
290
|
-
}) => void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
290
|
+
onError<TPath extends keyof TPathway>(path: TPath, handler: (error: Error, event: FlowcoreEvent<TPathway[TPath]["output"]>) => void): PathwaysBuilder<TPathway, TWritablePaths>;
|
|
291
291
|
/**
|
|
292
292
|
* Subscribe to errors for all pathways
|
|
293
293
|
* @param handler The handler function that receives the error, event, and pathway name
|
|
@@ -301,8 +301,8 @@ export declare class PathwaysBuilder<TPathway extends Record<string, unknown> =
|
|
|
301
301
|
* @param options Optional write options
|
|
302
302
|
* @returns A promise that resolves to the event ID(s)
|
|
303
303
|
*/
|
|
304
|
-
write<TPath extends TWritablePaths>(path: TPath,
|
|
305
|
-
writeBatch<TPath extends TWritablePaths>(path: TPath,
|
|
304
|
+
write<TPath extends TWritablePaths>(path: TPath, inputData: TPathway[TPath]["input"], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
305
|
+
writeBatch<TPath extends TWritablePaths>(path: TPath, inputData: TPathway[TPath]["input"][], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
306
306
|
/**
|
|
307
307
|
* Waits for a specific event to be processed
|
|
308
308
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/pathways/builder.ts"],"names":[],"mappings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,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IAgIvB,UAAU,CAAC,KAAK,SAAS,cAAc,EAC3C,IAAI,EAAE,KAAK,EACX,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,EACrC,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;IA8H7B;;;;;;;;;;OAUG;YACW,2BAA2B;CA4C1C"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PathwaysBuilder = exports.SessionUser = void 0;
|
|
4
|
-
const
|
|
5
|
-
const value_1 = require("@sinclair/typebox/value");
|
|
4
|
+
const zod_1 = require("zod");
|
|
6
5
|
const rxjs_1 = require("rxjs");
|
|
7
6
|
const flowcore_transformer_core_sdk_js_1 = require("../compatibility/flowcore-transformer-core.sdk.js");
|
|
8
7
|
const internal_pathway_state_js_1 = require("./internal-pathway.state.js");
|
|
@@ -273,7 +272,7 @@ class PathwaysBuilder {
|
|
|
273
272
|
this.logger = logger ?? new logger_js_1.NoopLogger();
|
|
274
273
|
// Initialize log levels with defaults
|
|
275
274
|
this.logLevel = {
|
|
276
|
-
writeSuccess: logLevel?.writeSuccess ??
|
|
275
|
+
writeSuccess: logLevel?.writeSuccess ?? "info",
|
|
277
276
|
};
|
|
278
277
|
// Store configuration values for cloning
|
|
279
278
|
this.baseUrl = baseUrl;
|
|
@@ -406,9 +405,9 @@ class PathwaysBuilder {
|
|
|
406
405
|
}
|
|
407
406
|
// Validate event payload against schema if available
|
|
408
407
|
if (this.schemas[pathway]) {
|
|
408
|
+
const parsedPayload = this.schemas[pathway].safeParse(data.payload);
|
|
409
409
|
try {
|
|
410
|
-
|
|
411
|
-
if (!isValid) {
|
|
410
|
+
if (!parsedPayload.success) {
|
|
412
411
|
const error = `Event payload does not match schema for pathway ${pathwayStr}`;
|
|
413
412
|
this.logger.error(error);
|
|
414
413
|
throw new Error(error);
|
|
@@ -419,6 +418,7 @@ class PathwaysBuilder {
|
|
|
419
418
|
this.logger.error(error);
|
|
420
419
|
throw new Error(error);
|
|
421
420
|
}
|
|
421
|
+
data.payload = parsedPayload.data;
|
|
422
422
|
}
|
|
423
423
|
// Call audit handler if configured
|
|
424
424
|
if (this.auditHandler) {
|
|
@@ -519,7 +519,7 @@ class PathwaysBuilder {
|
|
|
519
519
|
* Registers a new pathway with the given contract
|
|
520
520
|
* @template F The flow type string
|
|
521
521
|
* @template E The event type string
|
|
522
|
-
* @template S The schema type extending
|
|
522
|
+
* @template S The schema type extending ZodTypeAny
|
|
523
523
|
* @template W Boolean indicating if the pathway is writable (defaults to true)
|
|
524
524
|
* @param contract The pathway contract describing the pathway
|
|
525
525
|
* @returns The PathwaysBuilder instance with the new pathway registered
|
|
@@ -552,7 +552,8 @@ class PathwaysBuilder {
|
|
|
552
552
|
this.writers[path] = this.webhookBuilderFactory()
|
|
553
553
|
.buildWebhook(contract.flowType, contract.eventType).send;
|
|
554
554
|
this.batchWriters[path] = this.webhookBuilderFactory()
|
|
555
|
-
.buildWebhook(contract.flowType, contract.eventType)
|
|
555
|
+
.buildWebhook(contract.flowType, contract.eventType)
|
|
556
|
+
.sendBatch;
|
|
556
557
|
}
|
|
557
558
|
}
|
|
558
559
|
if (contract.timeoutMs) {
|
|
@@ -681,7 +682,7 @@ class PathwaysBuilder {
|
|
|
681
682
|
* @param options Optional write options
|
|
682
683
|
* @returns A promise that resolves to the event ID(s)
|
|
683
684
|
*/
|
|
684
|
-
async write(path,
|
|
685
|
+
async write(path, inputData, metadata, options) {
|
|
685
686
|
const pathStr = String(path);
|
|
686
687
|
this.logger.debug(`Writing to pathway`, {
|
|
687
688
|
pathway: pathStr,
|
|
@@ -702,7 +703,8 @@ class PathwaysBuilder {
|
|
|
702
703
|
throw new Error(error);
|
|
703
704
|
}
|
|
704
705
|
const schema = this.schemas[path];
|
|
705
|
-
|
|
706
|
+
const parsedData = schema.safeParse(inputData);
|
|
707
|
+
if (!parsedData.success) {
|
|
706
708
|
const errorMessage = `Invalid data for pathway ${pathStr}`;
|
|
707
709
|
this.logger.error(errorMessage, new Error(errorMessage), {
|
|
708
710
|
pathway: pathStr,
|
|
@@ -710,6 +712,7 @@ class PathwaysBuilder {
|
|
|
710
712
|
});
|
|
711
713
|
throw new Error(errorMessage);
|
|
712
714
|
}
|
|
715
|
+
const data = parsedData.data;
|
|
713
716
|
// Create a copy of the metadata to avoid modifying the original
|
|
714
717
|
const finalMetadata = metadata ? { ...metadata } : {};
|
|
715
718
|
// Check for session-specific user resolver
|
|
@@ -788,7 +791,7 @@ class PathwaysBuilder {
|
|
|
788
791
|
}
|
|
789
792
|
return eventIds;
|
|
790
793
|
}
|
|
791
|
-
async writeBatch(path,
|
|
794
|
+
async writeBatch(path, inputData, metadata, options) {
|
|
792
795
|
const pathStr = String(path);
|
|
793
796
|
this.logger.debug(`Writing batch to pathway`, {
|
|
794
797
|
pathway: pathStr,
|
|
@@ -809,7 +812,8 @@ class PathwaysBuilder {
|
|
|
809
812
|
throw new Error(error);
|
|
810
813
|
}
|
|
811
814
|
const schema = this.schemas[path];
|
|
812
|
-
|
|
815
|
+
const parsedData = zod_1.z.array(schema).safeParse(inputData);
|
|
816
|
+
if (!parsedData.success) {
|
|
813
817
|
const errorMessage = `Invalid batch data for pathway ${pathStr}`;
|
|
814
818
|
this.logger.error(errorMessage, new Error(errorMessage), {
|
|
815
819
|
pathway: pathStr,
|
|
@@ -817,6 +821,7 @@ class PathwaysBuilder {
|
|
|
817
821
|
});
|
|
818
822
|
throw new Error(errorMessage);
|
|
819
823
|
}
|
|
824
|
+
const data = parsedData.data;
|
|
820
825
|
// Create a copy of the metadata to avoid modifying the original
|
|
821
826
|
const finalMetadata = metadata ? { ...metadata } : {};
|
|
822
827
|
// Check for session-specific user resolver
|
|
@@ -39,7 +39,10 @@ import type { EventMetadata, PathwayWriteOptions } from "./types.js";
|
|
|
39
39
|
* // All events will be associated with the same session ID
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
|
-
export declare class SessionPathwayBuilder<TPathway extends Record<string,
|
|
42
|
+
export declare class SessionPathwayBuilder<TPathway extends Record<string, {
|
|
43
|
+
input: unknown;
|
|
44
|
+
output: unknown;
|
|
45
|
+
}> = {}, TWritablePaths extends keyof TPathway = never> {
|
|
43
46
|
private readonly pathwaysBuilder;
|
|
44
47
|
private readonly sessionId;
|
|
45
48
|
/**
|
|
@@ -94,6 +97,6 @@ export declare class SessionPathwayBuilder<TPathway extends Record<string, unkno
|
|
|
94
97
|
* @param options Optional write options
|
|
95
98
|
* @returns A promise that resolves to the event ID(s)
|
|
96
99
|
*/
|
|
97
|
-
write<TPath extends TWritablePaths>(path: TPath, data: TPathway[TPath], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
100
|
+
write<TPath extends TWritablePaths>(path: TPath, data: TPathway[TPath]["input"], metadata?: EventMetadata, options?: PathwayWriteOptions): Promise<string | string[]>;
|
|
98
101
|
}
|
|
99
102
|
//# sourceMappingURL=session-pathway.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-pathway.d.ts","sourceRoot":"","sources":["../../src/pathways/session-pathway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,qBAAqB,CAEhC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"session-pathway.d.ts","sourceRoot":"","sources":["../../src/pathways/session-pathway.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAqBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,qBAAqB,CAEhC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,GAAG,EAAE,EACzE,cAAc,SAAS,MAAM,QAAQ,GAAG,KAAK;IAE7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2C;IAC3E,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;IAElC;;;;;OAKG;gBAED,eAAe,EAAE,eAAe,CAAC,QAAQ,EAAE,cAAc,CAAC,EAC1D,SAAS,CAAC,EAAE,MAAM;IAMpB;;;;OAIG;IACH,YAAY,IAAI,MAAM;IAItB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACH,gBAAgB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD;;;;;;;;OAQG;IACG,KAAK,CAAC,KAAK,SAAS,cAAc,EACtC,IAAI,EAAE,KAAK,EACX,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,EAC9B,QAAQ,CAAC,EAAE,aAAa,EACxB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;CAU9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ZodTypeAny } from "zod";
|
|
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
|
|
@@ -13,7 +13,7 @@ type NonWritablePathwayError<T extends string> = T & {
|
|
|
13
13
|
* @template E The event type
|
|
14
14
|
* @template T The schema type
|
|
15
15
|
*/
|
|
16
|
-
export interface PathwayContract<F extends string, E extends string, T extends
|
|
16
|
+
export interface PathwayContract<F extends string, E extends string, T extends ZodTypeAny> {
|
|
17
17
|
/**
|
|
18
18
|
* The flow type for this pathway
|
|
19
19
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pathways/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/pathways/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AACrC,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,EAChC,wGAAwG,CAAA;CAC3G,CAAA;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,UAAU;IACvF;;OAEG;IACH,QAAQ,EAAE,CAAC,CAAA;IAEX;;OAEG;IACH,SAAS,EAAE,CAAC,CAAA;IAEZ;;OAEG;IACH,MAAM,EAAE,CAAC,CAAA;IAET;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAE3B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,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