@dotbep/core 0.2.13 → 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 +80 -96
- package/dist/index.js +1812 -1831
- 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
|
|
@@ -856,10 +859,8 @@ export declare type EffectHandler = (instance: WorkflowInstance, payload: Record
|
|
|
856
859
|
export declare interface EffectOutcome {
|
|
857
860
|
effectId: string;
|
|
858
861
|
fromEdgeId: string;
|
|
859
|
-
/** executed = handler ran ok | skipped = no handler
|
|
862
|
+
/** executed = handler ran ok | skipped = no handler registered | failed = handler threw */
|
|
860
863
|
status: 'executed' | 'skipped' | 'failed';
|
|
861
|
-
/** Required context fields that were missing. Present when status = 'skipped'. */
|
|
862
|
-
missingFields?: string[];
|
|
863
864
|
/** Error message thrown by the handler. Present when status = 'failed'. */
|
|
864
865
|
error?: string;
|
|
865
866
|
}
|
|
@@ -873,71 +874,50 @@ export declare class Engine {
|
|
|
873
874
|
private readonly getHistoricalBep?;
|
|
874
875
|
private _runtime;
|
|
875
876
|
private storage;
|
|
876
|
-
get runtime(): Runtime<any>;
|
|
877
877
|
private skipRaci;
|
|
878
|
-
private readonly
|
|
879
|
-
private readonly
|
|
880
|
-
private readonly
|
|
881
|
-
private readonly
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
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
|
+
};
|
|
886
902
|
constructor(getBep: () => BEP, getHistoricalBep?: (version: string) => Promise<BEP>);
|
|
887
903
|
/**
|
|
888
904
|
* Configures the engine with a runtime and storage backend.
|
|
889
|
-
* Must be called before any operations (
|
|
905
|
+
* Must be called before any operations (workflows.create, workflows.emit, etc.).
|
|
890
906
|
* Returns `this` for chaining.
|
|
891
907
|
*/
|
|
892
908
|
init(config: EngineInitConfig): this;
|
|
893
|
-
/** Fires after every successful emit() — all listeners run concurrently. */
|
|
894
|
-
onTransition(listener: TransitionListener): this;
|
|
895
|
-
/** Fires after createInstance() persists the new instance. */
|
|
896
|
-
onInstanceCreated(listener: LifecycleListener): this;
|
|
897
|
-
/** Fires when instance.status becomes 'completed'. */
|
|
898
|
-
onInstanceCompleted(listener: LifecycleListener): this;
|
|
899
|
-
/** Fires when an effect handler throws or returns status 'failed'. */
|
|
900
|
-
onEffectFailed(listener: EffectFailedListener): this;
|
|
901
|
-
/**
|
|
902
|
-
* Creates a new workflow instance positioned at the first node after start and persists it.
|
|
903
|
-
* Records the current BEP version on the instance for historical resolution.
|
|
904
|
-
* Returns null if the workflowId does not exist or has no start node.
|
|
905
|
-
*/
|
|
906
|
-
createInstance(workflowId: string, trackedAsset: WorkflowInstance['trackedAsset'], initiatedBy: string): Promise<WorkflowInstance | null>;
|
|
907
|
-
/**
|
|
908
|
-
* Emits an event against a workflow instance.
|
|
909
|
-
*
|
|
910
|
-
* 1. Loads the instance from storage.
|
|
911
|
-
* 2. Resolves the BEP version the instance was created against.
|
|
912
|
-
* 3. Processes the event (pure transition logic — transitions + decision auto-traversal).
|
|
913
|
-
* 4. Persists the updated instance.
|
|
914
|
-
* 5. Executes effect handlers declared in the runtime.
|
|
915
|
-
* 6. Fires lifecycle listeners concurrently.
|
|
916
|
-
* 7. Returns the result with the updated instance and effect outcomes.
|
|
917
|
-
*/
|
|
918
|
-
emit(instanceId: string, event: IncomingEvent): Promise<EventResult>;
|
|
919
|
-
getInstance(instanceId: string): Promise<WorkflowInstance | null>;
|
|
920
|
-
/**
|
|
921
|
-
* Returns instances matching the filter.
|
|
922
|
-
* `pendingActionFor` (Member.email) is resolved at the Engine level using
|
|
923
|
-
* the BEP RACI data — the storage layer does not need to understand it.
|
|
924
|
-
*/
|
|
925
|
-
getInstances(filter?: InstanceFilter): Promise<WorkflowInstance[]>;
|
|
926
|
-
/**
|
|
927
|
-
* Returns what a specific actor can do from the current node of an instance.
|
|
928
|
-
* Returns null if the instance does not exist.
|
|
929
|
-
*/
|
|
930
|
-
getNodeConfig(instanceId: string, actorEmail: string): Promise<NodeConfig | null>;
|
|
931
|
-
deleteInstance(instanceId: string): Promise<void>;
|
|
932
|
-
/**
|
|
933
|
-
* Runs the resolver declared for a remote data source and returns the raw payload.
|
|
934
|
-
* Throws if the remoteDataId does not exist in the BEP or has no resolver assigned.
|
|
935
|
-
*/
|
|
936
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;
|
|
937
918
|
private _assertInit;
|
|
938
919
|
private _resolveBep;
|
|
939
920
|
private _fire;
|
|
940
|
-
private _resolveFromHistory;
|
|
941
921
|
private _executeAutomationNode;
|
|
942
922
|
private _executeEffect;
|
|
943
923
|
}
|
|
@@ -954,6 +934,13 @@ export declare interface EngineInitConfig {
|
|
|
954
934
|
};
|
|
955
935
|
}
|
|
956
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
|
+
|
|
957
944
|
export declare class Entity<T extends object, AutoId extends boolean = false> {
|
|
958
945
|
private getItems;
|
|
959
946
|
protected getBep: () => BEP;
|
|
@@ -1674,7 +1661,7 @@ export declare interface InstanceFilter {
|
|
|
1674
1661
|
trackedAssetId?: string;
|
|
1675
1662
|
}
|
|
1676
1663
|
|
|
1677
|
-
export declare type InstanceStatus = 'active' | 'completed' | '
|
|
1664
|
+
export declare type InstanceStatus = 'active' | 'completed' | 'cancelled';
|
|
1678
1665
|
|
|
1679
1666
|
/** Abstraction over where instances are persisted. */
|
|
1680
1667
|
export declare interface InstanceStore {
|
|
@@ -2031,44 +2018,6 @@ export declare const NamingTokenSchema: z.ZodEnum<{
|
|
|
2031
2018
|
lbsLocation: "lbsLocation";
|
|
2032
2019
|
}>;
|
|
2033
2020
|
|
|
2034
|
-
/** Describes what a specific actor can do from the current node of an instance. */
|
|
2035
|
-
export declare interface NodeConfig {
|
|
2036
|
-
currentNode: {
|
|
2037
|
-
id: string;
|
|
2038
|
-
type: string;
|
|
2039
|
-
label: string;
|
|
2040
|
-
};
|
|
2041
|
-
/** Transitions this actor can trigger right now. */
|
|
2042
|
-
availableTransitions: {
|
|
2043
|
-
edgeId: string;
|
|
2044
|
-
label: string;
|
|
2045
|
-
/** eventId to emit */
|
|
2046
|
-
emits: string;
|
|
2047
|
-
requiredPayload: {
|
|
2048
|
-
key: string;
|
|
2049
|
-
type: string;
|
|
2050
|
-
required: boolean;
|
|
2051
|
-
}[];
|
|
2052
|
-
}[];
|
|
2053
|
-
/** Transitions that exist but this actor cannot trigger. */
|
|
2054
|
-
blockedTransitions: {
|
|
2055
|
-
edgeId: string;
|
|
2056
|
-
label: string;
|
|
2057
|
-
reason: 'UNAUTHORIZED' | 'GUARD_UNSATISFIABLE';
|
|
2058
|
-
/** What the node requires to authorize this transition. */
|
|
2059
|
-
required: RaciLevel;
|
|
2060
|
-
}[];
|
|
2061
|
-
/** RACI assignment for the current node — resolved to roles, teams and emails. */
|
|
2062
|
-
raci: {
|
|
2063
|
-
responsible: RaciLevel;
|
|
2064
|
-
accountable: RaciLevel;
|
|
2065
|
-
consulted: RaciLevel;
|
|
2066
|
-
informed: RaciLevel;
|
|
2067
|
-
};
|
|
2068
|
-
/** True if the current node is type "end". */
|
|
2069
|
-
isTerminal: boolean;
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
2021
|
export declare type NodeTimeout = z.infer<typeof NodeTimeoutSchema>;
|
|
2073
2022
|
|
|
2074
2023
|
export declare const NodeTimeoutSchema: z.ZodObject<{
|
|
@@ -2291,6 +2240,9 @@ export declare class Runtime<T extends {
|
|
|
2291
2240
|
readonly effects: Record<string, EffectHandler>;
|
|
2292
2241
|
readonly automations: Record<string, AutomationHandler>;
|
|
2293
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;
|
|
2294
2246
|
constructor({ env }?: RuntimeOptions);
|
|
2295
2247
|
protected effect<K extends keyof T['effects'] & string>(key: K, handler: (instance: WorkflowInstance, ...args: Parameters<T['effects'][K]>) => Promise<void>): this;
|
|
2296
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;
|
|
@@ -2665,4 +2617,36 @@ export declare const WorkflowSchema: z.ZodObject<{
|
|
|
2665
2617
|
}, z.core.$strip>;
|
|
2666
2618
|
}, z.core.$strip>;
|
|
2667
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
|
+
|
|
2668
2652
|
export { }
|