@sdux-vault/engine 0.13.0 → 0.26.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdux-vault/engine",
3
- "version": "0.13.0",
3
+ "version": "0.26.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,10 +9,11 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
+ "private": false,
12
13
  "homepage": "https://www.sdux-vault.com",
13
14
  "dependencies": {
14
- "@sdux-vault/devtools": "0.6.0",
15
- "@sdux-vault/shared": "0.5.0",
15
+ "@sdux-vault/devtools": "0.8.0",
16
+ "@sdux-vault/shared": "0.7.0",
16
17
  "tslib": "^2.3.0"
17
18
  },
18
19
  "peerDependencies": {
@@ -44,5 +45,6 @@
44
45
  "types": "./types/sdux-vault-engine.d.ts",
45
46
  "default": "./fesm2022/sdux-vault-engine.mjs"
46
47
  }
47
- }
48
+ },
49
+ "type": "module"
48
50
  }
@@ -1,5 +1,5 @@
1
1
  import * as _sdux_vault_shared from '@sdux-vault/shared';
2
- import { TapCallback, BehaviorClassContract, FeatureCellBaseShape, CoreEmitStateCallback, VaultErrorCallback, FilterFunction, DeferredType, ReducerFunction, InterceptorBehaviorClassContract, OperatorsBehaviorClassContract, ControllerClassContract, ControllerContract, ControllerContext, VaultErrorShape, BehaviorContext, VaultPrivateErrorServiceContract, StateInputType, DecisionOutcomeType, OperationType, VAULT_NOOP, VAULT_CLEAR_STATE, InsightConfig, PipelineValue, StateEmitSnapshotShape, CellBuilderContract, VaultConfig, VaultRegistrationShape, BehaviorClassContext, FinalState } from '@sdux-vault/shared';
2
+ import { TapCallback, BehaviorClassContract, FeatureCellBaseShape, CoreEmitStateCallback, VaultErrorCallback, FilterFunction, DeferredType, StateSnapshotShape, ReducerFunction, StateEmitSnapshotShape, InterceptorBehaviorClassContract, OperatorsBehaviorClassContract, ControllerClassContract, ControllerContract, ControllerContext, VaultErrorShape, BehaviorContext, VaultPrivateErrorServiceContract, StateInputType, DecisionOutcomeType, OperationType, VAULT_NOOP, VAULT_CLEAR_STATE, InsightConfig, PipelineValue, CellBuilderContract, VaultConfig, VaultRegistrationShape, FinalState } from '@sdux-vault/shared';
3
3
  import * as rxjs from 'rxjs';
4
4
  import { Subject } from 'rxjs';
5
5
 
@@ -53,10 +53,21 @@ interface OrchestratorConfig<T> {
53
53
  * Initial state value that seeds the FeatureCell.
54
54
  */
55
55
  initialState: T | DeferredType<T>;
56
+ /**
57
+ * Live reference to the FeatureCell's mutable last-snapshot object.
58
+ * Passed through to behavior constructors so they can commit state
59
+ * outside the pipeline call stack.
60
+ */
61
+ lastSnapshot: StateSnapshotShape<T>;
56
62
  /**
57
63
  * Reducer callbacks responsible for state transformation.
58
64
  */
59
65
  reducerCallbacks: ReducerFunction<T>[];
66
+ /**
67
+ * Subject used by the FeatureCell to emit state snapshots.
68
+ * Passed through to behavior constructors.
69
+ */
70
+ state$: Subject<StateEmitSnapshotShape<T>>;
60
71
  /**
61
72
  * Interceptor behavior classes applied before pipeline execution.
62
73
  */
@@ -117,9 +128,6 @@ declare const ControllerEventTypes: {
117
128
  * Represents the union of all valid controller event type values.
118
129
  * This type constrains controller events to the supported identifiers defined by the event type registry.
119
130
  *
120
- * --RelatedStart--
121
- * ControllerEventTypes
122
- * --RelatedEnd--
123
131
  */
124
132
  type ControllerEventType = (typeof ControllerEventTypes)[keyof typeof ControllerEventTypes];
125
133
 
@@ -127,9 +135,6 @@ type ControllerEventType = (typeof ControllerEventTypes)[keyof typeof Controller
127
135
  * Describes the shape of an event emitted by a controller during execution.
128
136
  * This interface defines the minimal contract required to identify the event type, associate it with a trace, and optionally carry error information.
129
137
  *
130
- * --RelatedStart--
131
- * ControllerEventType
132
- * --RelatedEnd--
133
138
  */
134
139
  interface ControllerEventShape {
135
140
  /**
@@ -192,28 +197,88 @@ declare class DecisionEngine<T> {
192
197
  notifyFinalize(ctx: ControllerContext<T> | BehaviorContext<T>): void;
193
198
  }
194
199
 
200
+ /**
201
+ * Abstract base class that executes the FeatureCell behavior pipeline in
202
+ * a deterministic stage order. The Orchestrator resolves incoming state,
203
+ * runs operators, filters, reducers, tap callbacks, and persistence
204
+ * stages before committing the final state snapshot.
205
+ */
195
206
  declare abstract class Orchestrator<T> {
196
207
  #private;
208
+ /** Unique key identifying the FeatureCell that owns this orchestrator. */
197
209
  protected cellKey: string;
210
+ /** Decision engine used for controller vote evaluation. */
198
211
  protected decisionEngine: DecisionEngine<T>;
212
+ /** Global error service for broadcasting errors across FeatureCells. */
199
213
  protected privateErrorService: VaultPrivateErrorServiceContract;
214
+ /** Vault monitor instance for tracing pipeline lifecycle events. */
200
215
  protected vaultMonitor: _sdux_vault_shared.VaultMonitorContract;
216
+ /**
217
+ * Initializes the orchestrator with configuration callbacks and initial state.
218
+ *
219
+ * @param config - Orchestrator configuration containing behaviors and callbacks.
220
+ */
201
221
  constructor(config: OrchestratorConfig<T>);
222
+ /** Registers all behaviors from the orchestrator configuration. */
202
223
  protected initializeOrchestrator(config: OrchestratorConfig<T>): void;
224
+ /** Loads the initial state and runs the first pipeline cycle. */
203
225
  protected initializeFeatureCell(ctx: BehaviorContext<T>): Promise<void>;
226
+ /** Invokes destroy on all registered behaviors. */
204
227
  protected destroyBehaviors(ctx: BehaviorContext<T>): void;
228
+ /** Invokes reset on all registered behaviors. */
205
229
  protected resetBehaviors(ctx: BehaviorContext<T>): void;
230
+ /** Routes the pipeline context to the appropriate replace or merge orchestration flow. */
206
231
  protected orchestrate(ctx: BehaviorContext<T>, options?: unknown): Promise<void>;
232
+ /**
233
+ * Builds a controller context from the current behavior context.
234
+ *
235
+ * @returns The controller context snapshot.
236
+ */
207
237
  protected buildControllerCtx(ctx: BehaviorContext<T>): ControllerContext<T>;
238
+ /**
239
+ * Normalizes an incoming state input into a consistent shape.
240
+ *
241
+ * @returns The normalized state input value.
242
+ */
208
243
  protected normalizeIncoming<T>(incoming: StateInputType<T>): StateInputType<T>;
244
+ /** Notifies the core state behavior of a controller abort or deny outcome. */
209
245
  protected controllerOutcomeNotification(type: DecisionOutcomeType, ctx: BehaviorContext<T>): void;
246
+ /**
247
+ * Prepares the incoming value and handles noop and clear-state short-circuits.
248
+ *
249
+ * @returns The normalized incoming value or undefined for short-circuit paths.
250
+ */
210
251
  protected prepareIncoming(ctx: BehaviorContext<T>, incoming: StateInputType<T>, operation: OperationType): StateInputType<T> | typeof VAULT_NOOP | typeof VAULT_CLEAR_STATE;
211
252
  }
212
253
 
254
+ /**
255
+ * Coordinates pipeline execution, controller arbitration, and license
256
+ * gating for a single FeatureCell. The Conductor serializes pipeline
257
+ * attempts through a FIFO queue and delegates vote resolution to the
258
+ * DecisionEngine.
259
+ */
213
260
  declare class Conductor<T> extends Orchestrator<T> {
214
261
  #private;
262
+ /**
263
+ * Creates a new Conductor and initializes controllers and licensing.
264
+ *
265
+ * @param config - Configuration describing behaviors, controllers, and callbacks.
266
+ */
215
267
  constructor(config: ConductorConfig<T>);
268
+ /**
269
+ * Enqueues an initialization attempt for the FeatureCell pipeline.
270
+ *
271
+ * @param ctx - Behavior context for the initialization cycle.
272
+ */
216
273
  initialize(ctx: BehaviorContext<T>): void;
274
+ /**
275
+ * Enqueues a pipeline attempt for a merge or replace operation.
276
+ *
277
+ * @param ctx - Behavior context for the current pipeline cycle.
278
+ * @param incoming - Incoming state input value.
279
+ * @param operation - Pipeline operation type.
280
+ * @param options - Optional merge or replace options.
281
+ */
217
282
  conduct(ctx: BehaviorContext<T>, incoming: StateInputType<T>, operation: OperationType, options?: unknown): void;
218
283
  /**
219
284
  * Resets pipeline + controller state for this FeatureCell.
@@ -288,10 +353,6 @@ interface VaultStateRef<T> {
288
353
  * Defines the public shape of a Feature Cell with an exposed resolved state reference.
289
354
  * This interface extends the base Feature Cell contract by adding access to the reactive state produced by resolution.
290
355
  *
291
- * --RelatedStart--
292
- * FeatureCellBaseShape
293
- * VaultStateRef
294
- * --RelatedEnd--
295
356
  */
296
357
  interface FeatureCellShape<T> extends FeatureCellBaseShape<T> {
297
358
  /**
@@ -300,45 +361,92 @@ interface FeatureCellShape<T> extends FeatureCellBaseShape<T> {
300
361
  state: VaultStateRef<T>;
301
362
  }
302
363
 
364
+ /**
365
+ * Abstract builder that assembles the fluent configuration API and
366
+ * lifecycle wiring for a FeatureCell. Subclasses call setup() to obtain
367
+ * a CellBuilderContract, then build the final FeatureCellShape from it.
368
+ * The builder manages conductor creation, initialization guards, and
369
+ * state operation dispatch.
370
+ */
303
371
  declare abstract class FeatureCellBuilder<T> {
304
372
  #private;
305
373
  protected readonly featureCellConfiguration: FeatureCellConfig<T>;
306
374
  private readonly defaultBehaviors;
307
375
  protected readonly behaviors: BehaviorClassContract<T>[];
308
376
  protected readonly controllers: ControllerClassContract<T>[];
377
+ /** Reference to the constructed FeatureCellBaseShape. */
309
378
  protected cell: FeatureCellBaseShape<T>;
379
+ /** Unique key identifying this FeatureCell. */
310
380
  protected readonly cellKey: string;
381
+ /** Shared behavior context for pipeline execution. */
311
382
  protected readonly ctx: BehaviorContext<T>;
383
+ /** Subject signaling cell destruction. */
312
384
  protected readonly destroyed$: Subject<void>;
385
+ /** Subject signaling cell reset. */
313
386
  protected readonly reset$: Subject<void>;
387
+ /** Subject emitting state snapshots to subscribers. */
314
388
  protected readonly state$: Subject<StateEmitSnapshotShape<T>>;
389
+ /**
390
+ * Creates the builder and initializes the shared behavior context.
391
+ *
392
+ * @param featureCellConfiguration - FeatureCell descriptor configuration.
393
+ * @param defaultBehaviors - Default behavior classes provided by the framework.
394
+ * @param behaviors - User-supplied behavior classes.
395
+ * @param controllers - User-supplied controller classes.
396
+ */
315
397
  constructor(featureCellConfiguration: FeatureCellConfig<T>, defaultBehaviors: BehaviorClassContract<T>[], behaviors: BehaviorClassContract<T>[], controllers: ControllerClassContract<T>[]);
398
+ /** Resets the conductor and emits a reset signal. */
316
399
  protected reset(): void;
400
+ /** Destroys the conductor, completes all subjects, and emits destruction signals. */
317
401
  protected destroy(): void;
402
+ /**
403
+ * Constructs the fluent CellBuilderContract with pre-initialization guards.
404
+ *
405
+ * @returns The builder contract exposing configuration and initialize methods.
406
+ */
318
407
  protected setup(): CellBuilderContract<T>;
408
+ /** Dispatches a merge operation through the conductor pipeline. */
319
409
  protected mergeState(incoming: StateInputType<T>, options?: unknown): void;
410
+ /** Dispatches a replace operation through the conductor pipeline. */
320
411
  protected replaceState(incoming: StateInputType<T>, options?: unknown): void;
321
412
  }
322
413
 
414
+ /**
415
+ * Concrete FeatureCell factory that extends the builder to produce a
416
+ * fully configured FeatureCellShape instance. The class wires fluent
417
+ * API extensions from behaviors and controllers onto the resulting
418
+ * cell and attaches non-enumerable context and key properties.
419
+ */
323
420
  declare class FeatureCellClass<T> extends FeatureCellBuilder<T> {
421
+ /**
422
+ * Creates a new FeatureCellClass with the provided descriptor and behavior/controller lists.
423
+ *
424
+ * @param descriptor - FeatureCell configuration descriptor.
425
+ * @param defaultBehaviors - Default behavior classes provided by the framework.
426
+ * @param behaviors - User-supplied behavior classes.
427
+ * @param controllers - User-supplied controller classes.
428
+ */
324
429
  constructor(descriptor: FeatureCellConfig<T>, defaultBehaviors: BehaviorClassContract<T>[], behaviors: BehaviorClassContract<T>[], controllers: ControllerClassContract<T>[]);
430
+ /**
431
+ * Assembles and returns a fully configured FeatureCellShape with fluent API extensions.
432
+ *
433
+ * @returns The constructed FeatureCellShape instance.
434
+ */
325
435
  build(): FeatureCellShape<T>;
326
436
  }
327
437
 
328
438
  /**
329
- * Static license verification utility used to validate signed license tokens
330
- * against tier-specific public keys. Tokens use a dot-separated format:
331
- * `base64(payload).base64(signature)`.
439
+ * Verifies a signed license payload string.
332
440
  *
333
- * The verification process:
334
- * - Splits the token on `.` to extract the encoded payload and signature
335
- * - Decodes the payload from base64 to determine the license tier
336
- * - Rejects tokens with missing or unrecognized tier
337
- * - Loads the appropriate PEM-encoded public key for the tier
338
- * - Uses `crypto.subtle.verify()` (RSA-SHA256) to validate the signature
339
- * against the raw base64-encoded payload string
340
- *
341
- * Verification failures return `false` rather than throwing.
441
+ * @param licensePayload - The signed license token to verify.
442
+ * @returns A promise resolving to true if the license is valid.
443
+ */
444
+ declare function verifyLicensePayload(licensePayload: string): Promise<boolean>;
445
+
446
+ /**
447
+ * Static license verification utility that validates signed license tokens
448
+ * against tier-specific RSA public keys. Tokens use a dot-separated
449
+ * base64(payload).base64(signature) format verified via crypto.subtle.
342
450
  */
343
451
  declare const VerifyLicenseToken: {
344
452
  /**
@@ -353,15 +461,45 @@ declare const VerifyLicenseToken: {
353
461
  verify: (token: string) => Promise<boolean>;
354
462
  };
355
463
 
464
+ /** Shape identifying a FeatureCell registered with the runtime. */
356
465
  interface RegisteredFeatureCellShape {
466
+ /** Unique key identifying the registered FeatureCell. */
357
467
  key: string;
358
468
  }
359
469
 
470
+ /**
471
+ * Initializes the global Vault runtime singleton with the supplied configuration.
472
+ *
473
+ * @param config - Optional Vault configuration overriding defaults.
474
+ */
360
475
  declare function VaultCore(config?: VaultConfig): void;
476
+ /**
477
+ * Registers a FeatureCell entry in the global Vault registry.
478
+ *
479
+ * @param entry - Registration descriptor containing the FeatureCell key.
480
+ */
361
481
  declare function registerFeatureCell(entry: RegisteredFeatureCellShape): void;
482
+ /**
483
+ * Retrieves the decoded license payload for a given license ID.
484
+ *
485
+ * @param licenseId - License identifier to look up.
486
+ * @returns The decoded payload.
487
+ */
362
488
  declare function getLicensePayload(licenseId: string): unknown;
489
+ /** Awaits settled callbacks for all registered FeatureCells. */
363
490
  declare function vaultAllSettled(): Promise<void>;
491
+ /**
492
+ * Awaits the settled callback for a specific FeatureCell.
493
+ *
494
+ * @param key - FeatureCell key to await.
495
+ */
364
496
  declare function vaultSettled(key: string): Promise<void>;
497
+ /**
498
+ * Registers a settled callback for a FeatureCell in the global Vault.
499
+ *
500
+ * @param key - FeatureCell key.
501
+ * @param vaultSettled - Async function invoked when the cell settles.
502
+ */
365
503
  declare function registerVaultSettled(key: string, vaultSettled?: () => Promise<void>): void;
366
504
  /**
367
505
  * Resets the global Vault configuration for isolated tests.
@@ -369,17 +507,59 @@ declare function registerVaultSettled(key: string, vaultSettled?: () => Promise<
369
507
  * This function should **never** be called in production builds.
370
508
  */
371
509
  declare function resetVaultForTests(): void;
510
+ /** Clears the FeatureCell registration registry. */
372
511
  declare function resetFeatureCellRegistry(): void;
512
+ /**
513
+ * Returns a read-only snapshot of the FeatureCell registry for test inspection.
514
+ *
515
+ * @returns A read-only copy of the registry.
516
+ */
373
517
  declare function getVaultRegistryForTests(): ReadonlyMap<string, VaultRegistrationShape> | undefined;
518
+ /**
519
+ * Checks whether a key is authorized by the Vault runtime.
520
+ *
521
+ * @param key - The key to check.
522
+ * @returns True when the key is authorized or licensing is bypassed.
523
+ */
374
524
  declare function isAuthorizedKey(key: string): boolean;
525
+ /**
526
+ * Returns whether licensing checks are currently bypassed.
527
+ *
528
+ * @returns True when bypass licensing is active.
529
+ */
375
530
  declare function isBypassLicensing(): boolean;
531
+ /**
532
+ * Returns whether a Vault-level license has been registered.
533
+ *
534
+ * @returns True when a Vault license exists.
535
+ */
376
536
  declare function hasVaultLicense(): boolean;
377
537
 
538
+ /**
539
+ * Abstract base class providing license lifecycle management for behaviors
540
+ * and controllers. Subclasses automatically request a license token during
541
+ * construction when the static `needsLicense` flag is set.
542
+ */
378
543
  declare abstract class LicensingAbstract<T> {
379
544
  #private;
545
+ /** Whether this class requires a valid license to operate. */
380
546
  static readonly needsLicense: boolean;
547
+ /** Static key assigned by the VaultBehavior or VaultController decorator. */
381
548
  static readonly key: string;
382
- constructor(ctx: BehaviorClassContext);
549
+ /**
550
+ * Creates a new licensing-aware instance and requests a license if required.
551
+ *
552
+ * @param ctx - Context providing the FeatureCell key and optional license payload.
553
+ */
554
+ constructor(ctx: {
555
+ readonly featureCellKey: string;
556
+ readonly licensePayload?: unknown;
557
+ });
558
+ /**
559
+ * Validates the previously requested license token.
560
+ *
561
+ * @param valid - Whether the license should be marked as approved.
562
+ */
383
563
  validateLicense(valid: boolean): void;
384
564
  }
385
565
 
@@ -415,5 +595,5 @@ declare function getFeatureCellToken(key: string): FeatureCellToken;
415
595
  */
416
596
  declare const isPipelineTerminal: <T>(current: FinalState<T>) => boolean;
417
597
 
418
- export { Conductor, FeatureCellClass, LicensingAbstract, VAULT_LICENSE_ID, VaultCore, VerifyLicenseToken, createFeatureCellToken, getFeatureCellToken, getLicensePayload, getVaultRegistryForTests, hasVaultLicense, isAuthorizedKey, isBypassLicensing, isPipelineTerminal, registerFeatureCell, registerVaultSettled, resetFeatureCellRegistry, resetVaultForTests, vaultAllSettled, vaultSettled };
598
+ export { Conductor, FeatureCellClass, LicensingAbstract, VAULT_LICENSE_ID, VaultCore, VerifyLicenseToken, createFeatureCellToken, getFeatureCellToken, getLicensePayload, getVaultRegistryForTests, hasVaultLicense, isAuthorizedKey, isBypassLicensing, isPipelineTerminal, registerFeatureCell, registerVaultSettled, resetFeatureCellRegistry, resetVaultForTests, vaultAllSettled, vaultSettled, verifyLicensePayload };
419
599
  export type { ConductorConfig, FeatureCellConfig, FeatureCellShape, VaultStateRef };