@dotbep/core 0.2.12 → 0.2.14
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/dist/index.d.ts +89 -96
- package/dist/index.js +1812 -1830
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,9 @@ export declare const AssetTypeSchema: z.ZodObject<{
|
|
|
77
77
|
extensionIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
78
78
|
}, z.core.$strip>;
|
|
79
79
|
|
|
80
|
+
/** Fires when an automation handler throws. */
|
|
81
|
+
export declare type AutomationFailedListener = (instance: WorkflowInstance, automationId: string, error: string) => Promise<void>;
|
|
82
|
+
|
|
80
83
|
/**
|
|
81
84
|
* Handler for an automation node. Receives the instance and the payload filtered
|
|
82
85
|
* from instance.context according to FlowAutomation.payload. Must return an object
|
|
@@ -340,6 +343,7 @@ export declare const BEPSchema: z.ZodObject<{
|
|
|
340
343
|
pattern: z.ZodString;
|
|
341
344
|
flags: z.ZodOptional<z.ZodString>;
|
|
342
345
|
}, z.core.$strip>>;
|
|
346
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
343
347
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
344
348
|
}, z.core.$strip>>>;
|
|
345
349
|
}, z.core.$strip>>;
|
|
@@ -361,6 +365,7 @@ export declare const BEPSchema: z.ZodObject<{
|
|
|
361
365
|
pattern: z.ZodString;
|
|
362
366
|
flags: z.ZodOptional<z.ZodString>;
|
|
363
367
|
}, z.core.$strip>>;
|
|
368
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
364
369
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
365
370
|
}, z.core.$strip>>>;
|
|
366
371
|
}, z.core.$strip>>;
|
|
@@ -382,6 +387,7 @@ export declare const BEPSchema: z.ZodObject<{
|
|
|
382
387
|
pattern: z.ZodString;
|
|
383
388
|
flags: z.ZodOptional<z.ZodString>;
|
|
384
389
|
}, z.core.$strip>>;
|
|
390
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
385
391
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
386
392
|
}, z.core.$strip>>>;
|
|
387
393
|
output: z.ZodArray<z.ZodObject<{
|
|
@@ -398,6 +404,7 @@ export declare const BEPSchema: z.ZodObject<{
|
|
|
398
404
|
pattern: z.ZodString;
|
|
399
405
|
flags: z.ZodOptional<z.ZodString>;
|
|
400
406
|
}, z.core.$strip>>;
|
|
407
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
401
408
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
402
409
|
}, z.core.$strip>>;
|
|
403
410
|
}, z.core.$strip>>;
|
|
@@ -852,10 +859,8 @@ export declare type EffectHandler = (instance: WorkflowInstance, payload: Record
|
|
|
852
859
|
export declare interface EffectOutcome {
|
|
853
860
|
effectId: string;
|
|
854
861
|
fromEdgeId: string;
|
|
855
|
-
/** executed = handler ran ok | skipped = no handler
|
|
862
|
+
/** executed = handler ran ok | skipped = no handler registered | failed = handler threw */
|
|
856
863
|
status: 'executed' | 'skipped' | 'failed';
|
|
857
|
-
/** Required context fields that were missing. Present when status = 'skipped'. */
|
|
858
|
-
missingFields?: string[];
|
|
859
864
|
/** Error message thrown by the handler. Present when status = 'failed'. */
|
|
860
865
|
error?: string;
|
|
861
866
|
}
|
|
@@ -869,71 +874,50 @@ export declare class Engine {
|
|
|
869
874
|
private readonly getHistoricalBep?;
|
|
870
875
|
private _runtime;
|
|
871
876
|
private storage;
|
|
872
|
-
get runtime(): Runtime<any>;
|
|
873
877
|
private skipRaci;
|
|
874
|
-
private readonly
|
|
875
|
-
private readonly
|
|
876
|
-
private readonly
|
|
877
|
-
private readonly
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
878
|
+
private readonly _transitionListeners;
|
|
879
|
+
private readonly _createdListeners;
|
|
880
|
+
private readonly _completedListeners;
|
|
881
|
+
private readonly _cancelledListeners;
|
|
882
|
+
private readonly _effectFailedListeners;
|
|
883
|
+
private readonly _automationFailedListeners;
|
|
884
|
+
get runtime(): Runtime<any>;
|
|
885
|
+
/** Namespaced workflow instance operations. */
|
|
886
|
+
readonly workflows: {
|
|
887
|
+
create(workflowId: string, trackedAsset: WorkflowInstance['trackedAsset'], initiatedBy: string): Promise<WorkflowInstance | null>;
|
|
888
|
+
emit(instanceId: string, event: IncomingEvent): Promise<EventResult>;
|
|
889
|
+
get(instanceId: string): Promise<WorkflowInstance | null>;
|
|
890
|
+
list(filter?: InstanceFilter): Promise<WorkflowInstance[]>;
|
|
891
|
+
delete(instanceId: string): Promise<void>;
|
|
892
|
+
cancel(instanceId: string): Promise<void>;
|
|
893
|
+
getStatus(instanceId: string): Promise<WorkflowStatus | null>;
|
|
894
|
+
resolveContext(instanceId: string): Promise<Record<string, unknown>>;
|
|
895
|
+
onTransition(listener: TransitionListener): Engine;
|
|
896
|
+
onCreated(listener: LifecycleListener): Engine;
|
|
897
|
+
onCompleted(listener: LifecycleListener): Engine;
|
|
898
|
+
onCancelled(listener: LifecycleListener): Engine;
|
|
899
|
+
onEffectFailed(listener: EffectFailedListener): Engine;
|
|
900
|
+
onAutomationFailed(listener: AutomationFailedListener): Engine;
|
|
901
|
+
};
|
|
882
902
|
constructor(getBep: () => BEP, getHistoricalBep?: (version: string) => Promise<BEP>);
|
|
883
903
|
/**
|
|
884
904
|
* Configures the engine with a runtime and storage backend.
|
|
885
|
-
* Must be called before any operations (
|
|
905
|
+
* Must be called before any operations (workflows.create, workflows.emit, etc.).
|
|
886
906
|
* Returns `this` for chaining.
|
|
887
907
|
*/
|
|
888
908
|
init(config: EngineInitConfig): this;
|
|
889
|
-
/** Fires after every successful emit() — all listeners run concurrently. */
|
|
890
|
-
onTransition(listener: TransitionListener): this;
|
|
891
|
-
/** Fires after createInstance() persists the new instance. */
|
|
892
|
-
onInstanceCreated(listener: LifecycleListener): this;
|
|
893
|
-
/** Fires when instance.status becomes 'completed'. */
|
|
894
|
-
onInstanceCompleted(listener: LifecycleListener): this;
|
|
895
|
-
/** Fires when an effect handler throws or returns status 'failed'. */
|
|
896
|
-
onEffectFailed(listener: EffectFailedListener): this;
|
|
897
|
-
/**
|
|
898
|
-
* Creates a new workflow instance positioned at the first node after start and persists it.
|
|
899
|
-
* Records the current BEP version on the instance for historical resolution.
|
|
900
|
-
* Returns null if the workflowId does not exist or has no start node.
|
|
901
|
-
*/
|
|
902
|
-
createInstance(workflowId: string, trackedAsset: WorkflowInstance['trackedAsset'], initiatedBy: string): Promise<WorkflowInstance | null>;
|
|
903
|
-
/**
|
|
904
|
-
* Emits an event against a workflow instance.
|
|
905
|
-
*
|
|
906
|
-
* 1. Loads the instance from storage.
|
|
907
|
-
* 2. Resolves the BEP version the instance was created against.
|
|
908
|
-
* 3. Processes the event (pure transition logic — transitions + decision auto-traversal).
|
|
909
|
-
* 4. Persists the updated instance.
|
|
910
|
-
* 5. Executes effect handlers declared in the runtime.
|
|
911
|
-
* 6. Fires lifecycle listeners concurrently.
|
|
912
|
-
* 7. Returns the result with the updated instance and effect outcomes.
|
|
913
|
-
*/
|
|
914
|
-
emit(instanceId: string, event: IncomingEvent): Promise<EventResult>;
|
|
915
|
-
getInstance(instanceId: string): Promise<WorkflowInstance | null>;
|
|
916
|
-
/**
|
|
917
|
-
* Returns instances matching the filter.
|
|
918
|
-
* `pendingActionFor` (Member.email) is resolved at the Engine level using
|
|
919
|
-
* the BEP RACI data — the storage layer does not need to understand it.
|
|
920
|
-
*/
|
|
921
|
-
getInstances(filter?: InstanceFilter): Promise<WorkflowInstance[]>;
|
|
922
|
-
/**
|
|
923
|
-
* Returns what a specific actor can do from the current node of an instance.
|
|
924
|
-
* Returns null if the instance does not exist.
|
|
925
|
-
*/
|
|
926
|
-
getNodeConfig(instanceId: string, actorEmail: string): Promise<NodeConfig | null>;
|
|
927
|
-
deleteInstance(instanceId: string): Promise<void>;
|
|
928
|
-
/**
|
|
929
|
-
* Runs the resolver declared for a remote data source and returns the raw payload.
|
|
930
|
-
* Throws if the remoteDataId does not exist in the BEP or has no resolver assigned.
|
|
931
|
-
*/
|
|
932
909
|
getRemoteData(remoteDataId: string): Promise<unknown>;
|
|
910
|
+
private _create;
|
|
911
|
+
private _emit;
|
|
912
|
+
private _get;
|
|
913
|
+
private _list;
|
|
914
|
+
private _delete;
|
|
915
|
+
private _cancel;
|
|
916
|
+
private _getStatus;
|
|
917
|
+
private _resolveContext;
|
|
933
918
|
private _assertInit;
|
|
934
919
|
private _resolveBep;
|
|
935
920
|
private _fire;
|
|
936
|
-
private _resolveFromHistory;
|
|
937
921
|
private _executeAutomationNode;
|
|
938
922
|
private _executeEffect;
|
|
939
923
|
}
|
|
@@ -950,6 +934,13 @@ export declare interface EngineInitConfig {
|
|
|
950
934
|
};
|
|
951
935
|
}
|
|
952
936
|
|
|
937
|
+
/** Minimal engine reference available to runtime handlers via this.engine. */
|
|
938
|
+
export declare interface EngineRef {
|
|
939
|
+
workflows: {
|
|
940
|
+
resolveContext(instanceId: string): Promise<Record<string, unknown>>;
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
|
|
953
944
|
export declare class Entity<T extends object, AutoId extends boolean = false> {
|
|
954
945
|
private getItems;
|
|
955
946
|
protected getBep: () => BEP;
|
|
@@ -1168,6 +1159,7 @@ export declare const FlowAutomationSchema: z.ZodObject<{
|
|
|
1168
1159
|
pattern: z.ZodString;
|
|
1169
1160
|
flags: z.ZodOptional<z.ZodString>;
|
|
1170
1161
|
}, z.core.$strip>>;
|
|
1162
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
1171
1163
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1172
1164
|
}, z.core.$strip>>>;
|
|
1173
1165
|
output: z.ZodArray<z.ZodObject<{
|
|
@@ -1184,6 +1176,7 @@ export declare const FlowAutomationSchema: z.ZodObject<{
|
|
|
1184
1176
|
pattern: z.ZodString;
|
|
1185
1177
|
flags: z.ZodOptional<z.ZodString>;
|
|
1186
1178
|
}, z.core.$strip>>;
|
|
1179
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
1187
1180
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1188
1181
|
}, z.core.$strip>>;
|
|
1189
1182
|
}, z.core.$strip>;
|
|
@@ -1377,6 +1370,7 @@ export declare const FlowEffectSchema: z.ZodObject<{
|
|
|
1377
1370
|
pattern: z.ZodString;
|
|
1378
1371
|
flags: z.ZodOptional<z.ZodString>;
|
|
1379
1372
|
}, z.core.$strip>>;
|
|
1373
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
1380
1374
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1381
1375
|
}, z.core.$strip>>>;
|
|
1382
1376
|
}, z.core.$strip>;
|
|
@@ -1406,6 +1400,7 @@ export declare const FlowEventSchema: z.ZodObject<{
|
|
|
1406
1400
|
pattern: z.ZodString;
|
|
1407
1401
|
flags: z.ZodOptional<z.ZodString>;
|
|
1408
1402
|
}, z.core.$strip>>;
|
|
1403
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
1409
1404
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1410
1405
|
}, z.core.$strip>>>;
|
|
1411
1406
|
}, z.core.$strip>;
|
|
@@ -1479,6 +1474,7 @@ export declare const FlowPayloadFieldSchema: z.ZodObject<{
|
|
|
1479
1474
|
pattern: z.ZodString;
|
|
1480
1475
|
flags: z.ZodOptional<z.ZodString>;
|
|
1481
1476
|
}, z.core.$strip>>;
|
|
1477
|
+
validationMessage: z.ZodOptional<z.ZodString>;
|
|
1482
1478
|
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1483
1479
|
}, z.core.$strip>;
|
|
1484
1480
|
|
|
@@ -1665,7 +1661,7 @@ export declare interface InstanceFilter {
|
|
|
1665
1661
|
trackedAssetId?: string;
|
|
1666
1662
|
}
|
|
1667
1663
|
|
|
1668
|
-
export declare type InstanceStatus = 'active' | 'completed' | '
|
|
1664
|
+
export declare type InstanceStatus = 'active' | 'completed' | 'cancelled';
|
|
1669
1665
|
|
|
1670
1666
|
/** Abstraction over where instances are persisted. */
|
|
1671
1667
|
export declare interface InstanceStore {
|
|
@@ -2022,44 +2018,6 @@ export declare const NamingTokenSchema: z.ZodEnum<{
|
|
|
2022
2018
|
lbsLocation: "lbsLocation";
|
|
2023
2019
|
}>;
|
|
2024
2020
|
|
|
2025
|
-
/** Describes what a specific actor can do from the current node of an instance. */
|
|
2026
|
-
export declare interface NodeConfig {
|
|
2027
|
-
currentNode: {
|
|
2028
|
-
id: string;
|
|
2029
|
-
type: string;
|
|
2030
|
-
label: string;
|
|
2031
|
-
};
|
|
2032
|
-
/** Transitions this actor can trigger right now. */
|
|
2033
|
-
availableTransitions: {
|
|
2034
|
-
edgeId: string;
|
|
2035
|
-
label: string;
|
|
2036
|
-
/** eventId to emit */
|
|
2037
|
-
emits: string;
|
|
2038
|
-
requiredPayload: {
|
|
2039
|
-
key: string;
|
|
2040
|
-
type: string;
|
|
2041
|
-
required: boolean;
|
|
2042
|
-
}[];
|
|
2043
|
-
}[];
|
|
2044
|
-
/** Transitions that exist but this actor cannot trigger. */
|
|
2045
|
-
blockedTransitions: {
|
|
2046
|
-
edgeId: string;
|
|
2047
|
-
label: string;
|
|
2048
|
-
reason: 'UNAUTHORIZED' | 'GUARD_UNSATISFIABLE';
|
|
2049
|
-
/** What the node requires to authorize this transition. */
|
|
2050
|
-
required: RaciLevel;
|
|
2051
|
-
}[];
|
|
2052
|
-
/** RACI assignment for the current node — resolved to roles, teams and emails. */
|
|
2053
|
-
raci: {
|
|
2054
|
-
responsible: RaciLevel;
|
|
2055
|
-
accountable: RaciLevel;
|
|
2056
|
-
consulted: RaciLevel;
|
|
2057
|
-
informed: RaciLevel;
|
|
2058
|
-
};
|
|
2059
|
-
/** True if the current node is type "end". */
|
|
2060
|
-
isTerminal: boolean;
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
2021
|
export declare type NodeTimeout = z.infer<typeof NodeTimeoutSchema>;
|
|
2064
2022
|
|
|
2065
2023
|
export declare const NodeTimeoutSchema: z.ZodObject<{
|
|
@@ -2282,6 +2240,9 @@ export declare class Runtime<T extends {
|
|
|
2282
2240
|
readonly effects: Record<string, EffectHandler>;
|
|
2283
2241
|
readonly automations: Record<string, AutomationHandler>;
|
|
2284
2242
|
readonly resolvers: Record<string, ResolverHandler>;
|
|
2243
|
+
/** Set by Engine.init() — available inside handlers via this.engine */
|
|
2244
|
+
_engine: EngineRef | null;
|
|
2245
|
+
get engine(): EngineRef;
|
|
2285
2246
|
constructor({ env }?: RuntimeOptions);
|
|
2286
2247
|
protected effect<K extends keyof T['effects'] & string>(key: K, handler: (instance: WorkflowInstance, ...args: Parameters<T['effects'][K]>) => Promise<void>): this;
|
|
2287
2248
|
protected automation<K extends keyof T['automations'] & string>(key: K, handler: (instance: WorkflowInstance, ...args: Parameters<T['automations'][K]>) => Promise<ReturnType<T['automations'][K]>>): this;
|
|
@@ -2656,4 +2617,36 @@ export declare const WorkflowSchema: z.ZodObject<{
|
|
|
2656
2617
|
}, z.core.$strip>;
|
|
2657
2618
|
}, z.core.$strip>;
|
|
2658
2619
|
|
|
2620
|
+
/** Current state of a workflow instance — node, transitions, and RACI. Actor-independent. */
|
|
2621
|
+
export declare interface WorkflowStatus {
|
|
2622
|
+
currentNode: {
|
|
2623
|
+
id: string;
|
|
2624
|
+
type: string;
|
|
2625
|
+
label: string;
|
|
2626
|
+
};
|
|
2627
|
+
status: InstanceStatus;
|
|
2628
|
+
/** All transitions available from the current node. Authorization is enforced at emit() time. */
|
|
2629
|
+
transitions: {
|
|
2630
|
+
edgeId: string;
|
|
2631
|
+
label: string;
|
|
2632
|
+
/** eventId to emit */
|
|
2633
|
+
emits: string;
|
|
2634
|
+
requiredPayload: {
|
|
2635
|
+
key: string;
|
|
2636
|
+
type: string;
|
|
2637
|
+
required: boolean;
|
|
2638
|
+
label?: string;
|
|
2639
|
+
}[];
|
|
2640
|
+
}[];
|
|
2641
|
+
/** RACI assignment for the current node — resolved to roles, teams and emails. */
|
|
2642
|
+
raci: {
|
|
2643
|
+
responsible: RaciLevel;
|
|
2644
|
+
accountable: RaciLevel;
|
|
2645
|
+
consulted: RaciLevel;
|
|
2646
|
+
informed: RaciLevel;
|
|
2647
|
+
};
|
|
2648
|
+
/** True if the current node is type "end". */
|
|
2649
|
+
isTerminal: boolean;
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2659
2652
|
export { }
|