@sdux-vault/engine 0.25.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.25.0",
3
+ "version": "0.26.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,8 @@
12
12
  "private": false,
13
13
  "homepage": "https://www.sdux-vault.com",
14
14
  "dependencies": {
15
- "@sdux-vault/devtools": "0.7.0",
16
- "@sdux-vault/shared": "0.6.0",
15
+ "@sdux-vault/devtools": "0.8.0",
16
+ "@sdux-vault/shared": "0.7.0",
17
17
  "tslib": "^2.3.0"
18
18
  },
19
19
  "peerDependencies": {
@@ -45,5 +45,6 @@
45
45
  "types": "./types/sdux-vault-engine.d.ts",
46
46
  "default": "./fesm2022/sdux-vault-engine.mjs"
47
47
  }
48
- }
48
+ },
49
+ "type": "module"
49
50
  }
@@ -128,9 +128,6 @@ declare const ControllerEventTypes: {
128
128
  * Represents the union of all valid controller event type values.
129
129
  * This type constrains controller events to the supported identifiers defined by the event type registry.
130
130
  *
131
- * --RelatedStart--
132
- * ControllerEventTypes
133
- * --RelatedEnd--
134
131
  */
135
132
  type ControllerEventType = (typeof ControllerEventTypes)[keyof typeof ControllerEventTypes];
136
133
 
@@ -138,9 +135,6 @@ type ControllerEventType = (typeof ControllerEventTypes)[keyof typeof Controller
138
135
  * Describes the shape of an event emitted by a controller during execution.
139
136
  * This interface defines the minimal contract required to identify the event type, associate it with a trace, and optionally carry error information.
140
137
  *
141
- * --RelatedStart--
142
- * ControllerEventType
143
- * --RelatedEnd--
144
138
  */
145
139
  interface ControllerEventShape {
146
140
  /**
@@ -203,28 +197,88 @@ declare class DecisionEngine<T> {
203
197
  notifyFinalize(ctx: ControllerContext<T> | BehaviorContext<T>): void;
204
198
  }
205
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
+ */
206
206
  declare abstract class Orchestrator<T> {
207
207
  #private;
208
+ /** Unique key identifying the FeatureCell that owns this orchestrator. */
208
209
  protected cellKey: string;
210
+ /** Decision engine used for controller vote evaluation. */
209
211
  protected decisionEngine: DecisionEngine<T>;
212
+ /** Global error service for broadcasting errors across FeatureCells. */
210
213
  protected privateErrorService: VaultPrivateErrorServiceContract;
214
+ /** Vault monitor instance for tracing pipeline lifecycle events. */
211
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
+ */
212
221
  constructor(config: OrchestratorConfig<T>);
222
+ /** Registers all behaviors from the orchestrator configuration. */
213
223
  protected initializeOrchestrator(config: OrchestratorConfig<T>): void;
224
+ /** Loads the initial state and runs the first pipeline cycle. */
214
225
  protected initializeFeatureCell(ctx: BehaviorContext<T>): Promise<void>;
226
+ /** Invokes destroy on all registered behaviors. */
215
227
  protected destroyBehaviors(ctx: BehaviorContext<T>): void;
228
+ /** Invokes reset on all registered behaviors. */
216
229
  protected resetBehaviors(ctx: BehaviorContext<T>): void;
230
+ /** Routes the pipeline context to the appropriate replace or merge orchestration flow. */
217
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
+ */
218
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
+ */
219
243
  protected normalizeIncoming<T>(incoming: StateInputType<T>): StateInputType<T>;
244
+ /** Notifies the core state behavior of a controller abort or deny outcome. */
220
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
+ */
221
251
  protected prepareIncoming(ctx: BehaviorContext<T>, incoming: StateInputType<T>, operation: OperationType): StateInputType<T> | typeof VAULT_NOOP | typeof VAULT_CLEAR_STATE;
222
252
  }
223
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
+ */
224
260
  declare class Conductor<T> extends Orchestrator<T> {
225
261
  #private;
262
+ /**
263
+ * Creates a new Conductor and initializes controllers and licensing.
264
+ *
265
+ * @param config - Configuration describing behaviors, controllers, and callbacks.
266
+ */
226
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
+ */
227
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
+ */
228
282
  conduct(ctx: BehaviorContext<T>, incoming: StateInputType<T>, operation: OperationType, options?: unknown): void;
229
283
  /**
230
284
  * Resets pipeline + controller state for this FeatureCell.
@@ -299,10 +353,6 @@ interface VaultStateRef<T> {
299
353
  * Defines the public shape of a Feature Cell with an exposed resolved state reference.
300
354
  * This interface extends the base Feature Cell contract by adding access to the reactive state produced by resolution.
301
355
  *
302
- * --RelatedStart--
303
- * FeatureCellBaseShape
304
- * VaultStateRef
305
- * --RelatedEnd--
306
356
  */
307
357
  interface FeatureCellShape<T> extends FeatureCellBaseShape<T> {
308
358
  /**
@@ -311,33 +361,93 @@ interface FeatureCellShape<T> extends FeatureCellBaseShape<T> {
311
361
  state: VaultStateRef<T>;
312
362
  }
313
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
+ */
314
371
  declare abstract class FeatureCellBuilder<T> {
315
372
  #private;
316
373
  protected readonly featureCellConfiguration: FeatureCellConfig<T>;
317
374
  private readonly defaultBehaviors;
318
375
  protected readonly behaviors: BehaviorClassContract<T>[];
319
376
  protected readonly controllers: ControllerClassContract<T>[];
377
+ /** Reference to the constructed FeatureCellBaseShape. */
320
378
  protected cell: FeatureCellBaseShape<T>;
379
+ /** Unique key identifying this FeatureCell. */
321
380
  protected readonly cellKey: string;
381
+ /** Shared behavior context for pipeline execution. */
322
382
  protected readonly ctx: BehaviorContext<T>;
383
+ /** Subject signaling cell destruction. */
323
384
  protected readonly destroyed$: Subject<void>;
385
+ /** Subject signaling cell reset. */
324
386
  protected readonly reset$: Subject<void>;
387
+ /** Subject emitting state snapshots to subscribers. */
325
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
+ */
326
397
  constructor(featureCellConfiguration: FeatureCellConfig<T>, defaultBehaviors: BehaviorClassContract<T>[], behaviors: BehaviorClassContract<T>[], controllers: ControllerClassContract<T>[]);
398
+ /** Resets the conductor and emits a reset signal. */
327
399
  protected reset(): void;
400
+ /** Destroys the conductor, completes all subjects, and emits destruction signals. */
328
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
+ */
329
407
  protected setup(): CellBuilderContract<T>;
408
+ /** Dispatches a merge operation through the conductor pipeline. */
330
409
  protected mergeState(incoming: StateInputType<T>, options?: unknown): void;
410
+ /** Dispatches a replace operation through the conductor pipeline. */
331
411
  protected replaceState(incoming: StateInputType<T>, options?: unknown): void;
332
412
  }
333
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
+ */
334
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
+ */
335
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
+ */
336
435
  build(): FeatureCellShape<T>;
337
436
  }
338
437
 
438
+ /**
439
+ * Verifies a signed license payload string.
440
+ *
441
+ * @param licensePayload - The signed license token to verify.
442
+ * @returns A promise resolving to true if the license is valid.
443
+ */
339
444
  declare function verifyLicensePayload(licensePayload: string): Promise<boolean>;
340
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.
450
+ */
341
451
  declare const VerifyLicenseToken: {
342
452
  /**
343
453
  * Verifies the supplied signed license token using the public key associated
@@ -351,15 +461,45 @@ declare const VerifyLicenseToken: {
351
461
  verify: (token: string) => Promise<boolean>;
352
462
  };
353
463
 
464
+ /** Shape identifying a FeatureCell registered with the runtime. */
354
465
  interface RegisteredFeatureCellShape {
466
+ /** Unique key identifying the registered FeatureCell. */
355
467
  key: string;
356
468
  }
357
469
 
470
+ /**
471
+ * Initializes the global Vault runtime singleton with the supplied configuration.
472
+ *
473
+ * @param config - Optional Vault configuration overriding defaults.
474
+ */
358
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
+ */
359
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
+ */
360
488
  declare function getLicensePayload(licenseId: string): unknown;
489
+ /** Awaits settled callbacks for all registered FeatureCells. */
361
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
+ */
362
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
+ */
363
503
  declare function registerVaultSettled(key: string, vaultSettled?: () => Promise<void>): void;
364
504
  /**
365
505
  * Resets the global Vault configuration for isolated tests.
@@ -367,20 +507,59 @@ declare function registerVaultSettled(key: string, vaultSettled?: () => Promise<
367
507
  * This function should **never** be called in production builds.
368
508
  */
369
509
  declare function resetVaultForTests(): void;
510
+ /** Clears the FeatureCell registration registry. */
370
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
+ */
371
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
+ */
372
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
+ */
373
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
+ */
374
536
  declare function hasVaultLicense(): boolean;
375
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
+ */
376
543
  declare abstract class LicensingAbstract<T> {
377
544
  #private;
545
+ /** Whether this class requires a valid license to operate. */
378
546
  static readonly needsLicense: boolean;
547
+ /** Static key assigned by the VaultBehavior or VaultController decorator. */
379
548
  static readonly key: string;
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
+ */
380
554
  constructor(ctx: {
381
555
  readonly featureCellKey: string;
382
556
  readonly licensePayload?: unknown;
383
557
  });
558
+ /**
559
+ * Validates the previously requested license token.
560
+ *
561
+ * @param valid - Whether the license should be marked as approved.
562
+ */
384
563
  validateLicense(valid: boolean): void;
385
564
  }
386
565