@dotbep/core 0.2.13 → 0.2.15
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 +90 -96
- package/dist/index.js +1817 -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
|
|
@@ -216,6 +219,11 @@ export declare const BEPSchema: z.ZodObject<{
|
|
|
216
219
|
description: z.ZodOptional<z.ZodString>;
|
|
217
220
|
image: z.ZodOptional<z.ZodString>;
|
|
218
221
|
websiteUrl: z.ZodOptional<z.ZodURL>;
|
|
222
|
+
location: z.ZodOptional<z.ZodObject<{
|
|
223
|
+
address: z.ZodOptional<z.ZodString>;
|
|
224
|
+
coordinates: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
225
|
+
}, z.core.$strip>>;
|
|
226
|
+
customData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
219
227
|
}, z.core.$strip>;
|
|
220
228
|
deliverableNamingConvention: z.ZodOptional<z.ZodObject<{
|
|
221
229
|
delimiter: z.ZodString;
|
|
@@ -856,10 +864,8 @@ export declare type EffectHandler = (instance: WorkflowInstance, payload: Record
|
|
|
856
864
|
export declare interface EffectOutcome {
|
|
857
865
|
effectId: string;
|
|
858
866
|
fromEdgeId: string;
|
|
859
|
-
/** executed = handler ran ok | skipped = no handler
|
|
867
|
+
/** executed = handler ran ok | skipped = no handler registered | failed = handler threw */
|
|
860
868
|
status: 'executed' | 'skipped' | 'failed';
|
|
861
|
-
/** Required context fields that were missing. Present when status = 'skipped'. */
|
|
862
|
-
missingFields?: string[];
|
|
863
869
|
/** Error message thrown by the handler. Present when status = 'failed'. */
|
|
864
870
|
error?: string;
|
|
865
871
|
}
|
|
@@ -873,71 +879,50 @@ export declare class Engine {
|
|
|
873
879
|
private readonly getHistoricalBep?;
|
|
874
880
|
private _runtime;
|
|
875
881
|
private storage;
|
|
876
|
-
get runtime(): Runtime<any>;
|
|
877
882
|
private skipRaci;
|
|
878
|
-
private readonly
|
|
879
|
-
private readonly
|
|
880
|
-
private readonly
|
|
881
|
-
private readonly
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
883
|
+
private readonly _transitionListeners;
|
|
884
|
+
private readonly _createdListeners;
|
|
885
|
+
private readonly _completedListeners;
|
|
886
|
+
private readonly _cancelledListeners;
|
|
887
|
+
private readonly _effectFailedListeners;
|
|
888
|
+
private readonly _automationFailedListeners;
|
|
889
|
+
get runtime(): Runtime<any>;
|
|
890
|
+
/** Namespaced workflow instance operations. */
|
|
891
|
+
readonly workflows: {
|
|
892
|
+
create(workflowId: string, trackedAsset: WorkflowInstance['trackedAsset'], initiatedBy: string): Promise<WorkflowInstance | null>;
|
|
893
|
+
emit(instanceId: string, event: IncomingEvent): Promise<EventResult>;
|
|
894
|
+
get(instanceId: string): Promise<WorkflowInstance | null>;
|
|
895
|
+
list(filter?: InstanceFilter): Promise<WorkflowInstance[]>;
|
|
896
|
+
delete(instanceId: string): Promise<void>;
|
|
897
|
+
cancel(instanceId: string): Promise<void>;
|
|
898
|
+
getStatus(instanceId: string): Promise<WorkflowStatus | null>;
|
|
899
|
+
resolveContext(instanceId: string): Promise<Record<string, unknown>>;
|
|
900
|
+
onTransition(listener: TransitionListener): Engine;
|
|
901
|
+
onCreated(listener: LifecycleListener): Engine;
|
|
902
|
+
onCompleted(listener: LifecycleListener): Engine;
|
|
903
|
+
onCancelled(listener: LifecycleListener): Engine;
|
|
904
|
+
onEffectFailed(listener: EffectFailedListener): Engine;
|
|
905
|
+
onAutomationFailed(listener: AutomationFailedListener): Engine;
|
|
906
|
+
};
|
|
886
907
|
constructor(getBep: () => BEP, getHistoricalBep?: (version: string) => Promise<BEP>);
|
|
887
908
|
/**
|
|
888
909
|
* Configures the engine with a runtime and storage backend.
|
|
889
|
-
* Must be called before any operations (
|
|
910
|
+
* Must be called before any operations (workflows.create, workflows.emit, etc.).
|
|
890
911
|
* Returns `this` for chaining.
|
|
891
912
|
*/
|
|
892
913
|
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
914
|
getRemoteData(remoteDataId: string): Promise<unknown>;
|
|
915
|
+
private _create;
|
|
916
|
+
private _emit;
|
|
917
|
+
private _get;
|
|
918
|
+
private _list;
|
|
919
|
+
private _delete;
|
|
920
|
+
private _cancel;
|
|
921
|
+
private _getStatus;
|
|
922
|
+
private _resolveContext;
|
|
937
923
|
private _assertInit;
|
|
938
924
|
private _resolveBep;
|
|
939
925
|
private _fire;
|
|
940
|
-
private _resolveFromHistory;
|
|
941
926
|
private _executeAutomationNode;
|
|
942
927
|
private _executeEffect;
|
|
943
928
|
}
|
|
@@ -954,6 +939,13 @@ export declare interface EngineInitConfig {
|
|
|
954
939
|
};
|
|
955
940
|
}
|
|
956
941
|
|
|
942
|
+
/** Minimal engine reference available to runtime handlers via this.engine. */
|
|
943
|
+
export declare interface EngineRef {
|
|
944
|
+
workflows: {
|
|
945
|
+
resolveContext(instanceId: string): Promise<Record<string, unknown>>;
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
|
|
957
949
|
export declare class Entity<T extends object, AutoId extends boolean = false> {
|
|
958
950
|
private getItems;
|
|
959
951
|
protected getBep: () => BEP;
|
|
@@ -1674,7 +1666,7 @@ export declare interface InstanceFilter {
|
|
|
1674
1666
|
trackedAssetId?: string;
|
|
1675
1667
|
}
|
|
1676
1668
|
|
|
1677
|
-
export declare type InstanceStatus = 'active' | 'completed' | '
|
|
1669
|
+
export declare type InstanceStatus = 'active' | 'completed' | 'cancelled';
|
|
1678
1670
|
|
|
1679
1671
|
/** Abstraction over where instances are persisted. */
|
|
1680
1672
|
export declare interface InstanceStore {
|
|
@@ -2031,44 +2023,6 @@ export declare const NamingTokenSchema: z.ZodEnum<{
|
|
|
2031
2023
|
lbsLocation: "lbsLocation";
|
|
2032
2024
|
}>;
|
|
2033
2025
|
|
|
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
2026
|
export declare type NodeTimeout = z.infer<typeof NodeTimeoutSchema>;
|
|
2073
2027
|
|
|
2074
2028
|
export declare const NodeTimeoutSchema: z.ZodObject<{
|
|
@@ -2164,6 +2118,11 @@ export declare const ProjectSchema: z.ZodObject<{
|
|
|
2164
2118
|
description: z.ZodOptional<z.ZodString>;
|
|
2165
2119
|
image: z.ZodOptional<z.ZodString>;
|
|
2166
2120
|
websiteUrl: z.ZodOptional<z.ZodURL>;
|
|
2121
|
+
location: z.ZodOptional<z.ZodObject<{
|
|
2122
|
+
address: z.ZodOptional<z.ZodString>;
|
|
2123
|
+
coordinates: z.ZodOptional<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
2124
|
+
}, z.core.$strip>>;
|
|
2125
|
+
customData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
2167
2126
|
}, z.core.$strip>;
|
|
2168
2127
|
|
|
2169
2128
|
export declare type RaciAssignment = {
|
|
@@ -2291,6 +2250,9 @@ export declare class Runtime<T extends {
|
|
|
2291
2250
|
readonly effects: Record<string, EffectHandler>;
|
|
2292
2251
|
readonly automations: Record<string, AutomationHandler>;
|
|
2293
2252
|
readonly resolvers: Record<string, ResolverHandler>;
|
|
2253
|
+
/** Set by Engine.init() — available inside handlers via this.engine */
|
|
2254
|
+
_engine: EngineRef | null;
|
|
2255
|
+
get engine(): EngineRef;
|
|
2294
2256
|
constructor({ env }?: RuntimeOptions);
|
|
2295
2257
|
protected effect<K extends keyof T['effects'] & string>(key: K, handler: (instance: WorkflowInstance, ...args: Parameters<T['effects'][K]>) => Promise<void>): this;
|
|
2296
2258
|
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 +2627,36 @@ export declare const WorkflowSchema: z.ZodObject<{
|
|
|
2665
2627
|
}, z.core.$strip>;
|
|
2666
2628
|
}, z.core.$strip>;
|
|
2667
2629
|
|
|
2630
|
+
/** Current state of a workflow instance — node, transitions, and RACI. Actor-independent. */
|
|
2631
|
+
export declare interface WorkflowStatus {
|
|
2632
|
+
currentNode: {
|
|
2633
|
+
id: string;
|
|
2634
|
+
type: string;
|
|
2635
|
+
label: string;
|
|
2636
|
+
};
|
|
2637
|
+
status: InstanceStatus;
|
|
2638
|
+
/** All transitions available from the current node. Authorization is enforced at emit() time. */
|
|
2639
|
+
transitions: {
|
|
2640
|
+
edgeId: string;
|
|
2641
|
+
label: string;
|
|
2642
|
+
/** eventId to emit */
|
|
2643
|
+
emits: string;
|
|
2644
|
+
requiredPayload: {
|
|
2645
|
+
key: string;
|
|
2646
|
+
type: string;
|
|
2647
|
+
required: boolean;
|
|
2648
|
+
label?: string;
|
|
2649
|
+
}[];
|
|
2650
|
+
}[];
|
|
2651
|
+
/** RACI assignment for the current node — resolved to roles, teams and emails. */
|
|
2652
|
+
raci: {
|
|
2653
|
+
responsible: RaciLevel;
|
|
2654
|
+
accountable: RaciLevel;
|
|
2655
|
+
consulted: RaciLevel;
|
|
2656
|
+
informed: RaciLevel;
|
|
2657
|
+
};
|
|
2658
|
+
/** True if the current node is type "end". */
|
|
2659
|
+
isTerminal: boolean;
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2668
2662
|
export { }
|