@smplkit/sdk 1.3.22 → 1.3.24

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 CHANGED
@@ -1,24 +1,9 @@
1
1
  /**
2
- * Shared WebSocket connection to the app service event gateway.
3
- *
4
- * A single {@link SharedWebSocket} instance is shared across all product
5
- * modules (config, flags) within one {@link SmplClient}. Product modules
6
- * register listeners for specific event types; the shared connection
7
- * dispatches incoming events to the appropriate listeners.
8
- *
9
- * Protocol:
10
- * - Connect to `wss://app.smplkit.com/api/ws/v1/events?api_key={key}`
11
- * - Receive `{"type": "connected"}` on success
12
- * - Receive events: `{"event": "config_changed", ...}`, `{"event": "flag_changed", ...}`
13
- * - No subscribe message — the API key determines the account
14
- * - Heartbeat: server sends `ping`, client responds with `pong`
15
- * - Reconnect with exponential backoff
2
+ * Shared WebSocket connection for real-time event delivery.
16
3
  */
17
4
  type EventCallback = (data: Record<string, any>) => void;
18
5
  /**
19
- * Manages a single WebSocket connection to the app service event gateway.
20
- *
21
- * Shared across config and flags modules for efficient multiplexing.
6
+ * Manages a WebSocket connection for real-time event delivery.
22
7
  */
23
8
  declare class SharedWebSocket {
24
9
  private readonly _appBaseUrl;
@@ -53,7 +38,7 @@ declare class SharedWebSocket {
53
38
  * A configuration resource managed by the smplkit platform.
54
39
  *
55
40
  * Management: mutate properties directly and call `save()` to persist.
56
- * POST if `id` is null (new), PUT if `id` is set (update).
41
+ * Creates if new, updates if existing.
57
42
  */
58
43
  declare class Config {
59
44
  /** UUID of the config, or `null` if unsaved. */
@@ -66,12 +51,11 @@ declare class Config {
66
51
  description: string | null;
67
52
  /** Parent config UUID, or null if this is a root config. */
68
53
  parent: string | null;
69
- /** Base key-value pairs (unwrapped from typed item definitions). */
54
+ /** Base key-value pairs. */
70
55
  items: Record<string, unknown>;
71
56
  /**
72
57
  * Per-environment overrides.
73
- * Stored as `{ env_name: { values: { key: value } } }` — values are
74
- * unwrapped from the server's `{ value: raw }` wrapper.
58
+ * Structured as `{ env_name: { values: { key: value } } }`.
75
59
  */
76
60
  environments: Record<string, unknown>;
77
61
  /** When the config was created, or null if unavailable. */
@@ -95,7 +79,7 @@ declare class Config {
95
79
  /**
96
80
  * Persist this config to the server.
97
81
  *
98
- * POST if `id` is null (new config), PUT if `id` is set (update).
82
+ * Creates if new, updates if existing.
99
83
  * Updates this instance in-place with the server response.
100
84
  */
101
85
  save(): Promise<void>;
@@ -118,24 +102,18 @@ declare class Config {
118
102
  }
119
103
 
120
104
  /**
121
- * LiveConfigProxy — ES6 Proxy-based live configuration access.
122
- *
123
- * Property reads are delegated to the latest resolved values in the
124
- * ConfigClient cache. When the cache updates via WebSocket, subsequent
125
- * reads automatically reflect the new values.
105
+ * LiveConfigProxy — live configuration access.
126
106
  */
127
107
 
128
108
  /**
129
- * A live proxy that auto-updates when the underlying config changes.
130
- *
131
- * Access properties directly — each read re-resolves from the cache.
109
+ * A live proxy whose properties always reflect the latest config values.
132
110
  *
133
111
  * @example
134
112
  * ```typescript
135
113
  * const proxy = await client.config.subscribe("user-service");
136
- * console.log(proxy.timeout); // reads from live cache
137
- * // ... later, after a WebSocket update ...
138
- * console.log(proxy.timeout); // reads the updated value
114
+ * console.log(proxy.timeout); // current value
115
+ * // ... later, after a config change ...
116
+ * console.log(proxy.timeout); // updated value
139
117
  * ```
140
118
  */
141
119
  declare class LiveConfigProxy<T = Record<string, unknown>> {
@@ -164,7 +142,7 @@ interface ConfigChangeEvent {
164
142
  source: "websocket" | "manual";
165
143
  }
166
144
  /**
167
- * Client for the smplkit Config API — management plane + runtime.
145
+ * Client for the smplkit Config API.
168
146
  *
169
147
  * Obtained via `SmplClient.config`.
170
148
  */
@@ -208,15 +186,13 @@ declare class ConfigClient {
208
186
  /**
209
187
  * Resolve a config's values for the current environment.
210
188
  *
211
- * Returns a flat dict of resolved key-value pairs, walking the
212
- * parent chain and applying environment overrides.
213
- *
189
+ * Returns the resolved key-value pairs for the given config.
214
190
  * Optionally pass a model class to map the resolved values.
215
191
  */
216
192
  resolve<T = Record<string, unknown>>(key: string, model?: new (data: any) => T): Promise<T>;
217
193
  /**
218
- * Subscribe to a config's values returns a live proxy that
219
- * auto-updates when the underlying config changes.
194
+ * Subscribe to a config's values. Returns a proxy whose properties
195
+ * always reflect the latest resolved values.
220
196
  *
221
197
  * Optionally pass a model class to map the resolved values.
222
198
  */
@@ -230,8 +206,8 @@ declare class ConfigClient {
230
206
  */
231
207
  onChange(callbackOrConfigKey: string | ((event: ConfigChangeEvent) => void), callbackOrItemKey?: string | ((event: ConfigChangeEvent) => void), callback?: (event: ConfigChangeEvent) => void): void;
232
208
  /**
233
- * Re-fetch all configs, re-resolve values, and update the cache.
234
- * Fires change listeners for any values that differ.
209
+ * Refresh all config values from the server.
210
+ * Fires change listeners for any values that changed.
235
211
  */
236
212
  refresh(): Promise<void>;
237
213
  /** @internal */
@@ -488,7 +464,7 @@ declare class Context {
488
464
  toString(): string;
489
465
  }
490
466
  /**
491
- * Fluent builder for JSON Logic rule dicts.
467
+ * Fluent builder for flag targeting rules.
492
468
  *
493
469
  * @example
494
470
  * ```typescript
@@ -499,8 +475,7 @@ declare class Context {
499
475
  * .build()
500
476
  * ```
501
477
  *
502
- * Multiple `.when()` calls are AND'd. `.environment()` tags the
503
- * built dict with an environment key for use with `Flag.addRule()`.
478
+ * Multiple `.when()` calls are combined with AND logic.
504
479
  */
505
480
  declare class Rule {
506
481
  private _description;
@@ -519,18 +494,13 @@ declare class Rule {
519
494
  }
520
495
 
521
496
  /**
522
- * Unified Flag hierarchy management model + runtime handle.
523
- *
524
- * A single {@link Flag} class replaces the old separate Flag + FlagHandle
525
- * classes. Typed subclasses ({@link BooleanFlag}, {@link StringFlag},
526
- * {@link NumberFlag}, {@link JsonFlag}) override `get()` for type safety.
497
+ * Flag model hierarchy with typed subclasses for type-safe evaluation.
527
498
  */
528
499
 
529
500
  /**
530
- * A flag resource that doubles as a runtime handle.
501
+ * A flag resource.
531
502
  *
532
- * Management: call `save()` to persist (POST if new, PUT if existing).
533
- * Runtime: call `get()` for local JSON Logic evaluation.
503
+ * Call `save()` to persist changes. Call `get()` to evaluate the flag.
534
504
  */
535
505
  declare class Flag {
536
506
  /** UUID of the flag, or `null` if unsaved. */
@@ -577,29 +547,29 @@ declare class Flag {
577
547
  /**
578
548
  * Persist this flag to the server.
579
549
  *
580
- * POST if `id` is null (new flag), PUT if `id` is set (update).
550
+ * Creates if new, updates if existing.
581
551
  * Updates this instance in-place with the server response.
582
552
  */
583
553
  save(): Promise<void>;
584
554
  /**
585
- * Add a rule to a specific environment (sync local mutation).
555
+ * Add a rule to a specific environment.
586
556
  *
587
557
  * The built rule must include an `environment` key (set via
588
- * `Rule(...).environment("env_key")`). No HTTP call is made.
558
+ * `Rule(...).environment("env_key")`). Call `save()` to persist.
589
559
  *
590
560
  * @returns `this` for chaining.
591
561
  */
592
562
  addRule(builtRule: Record<string, any>): Flag;
593
- /** Enable or disable a flag in a specific environment (sync local mutation). */
563
+ /** Enable or disable a flag in a specific environment. Call `save()` to persist. */
594
564
  setEnvironmentEnabled(envKey: string, enabled: boolean): void;
595
- /** Set the default value for a specific environment (sync local mutation). */
565
+ /** Set the default value for a specific environment. Call `save()` to persist. */
596
566
  setEnvironmentDefault(envKey: string, defaultValue: unknown): void;
597
- /** Clear all rules for a specific environment (sync local mutation). */
567
+ /** Clear all rules for a specific environment. Call `save()` to persist. */
598
568
  clearRules(envKey: string): void;
599
569
  /**
600
- * Evaluate the flag locally (sync, no HTTP).
570
+ * Evaluate the flag and return its current value.
601
571
  *
602
- * Requires `initialize()` to have been called.
572
+ * Requires `initialize()` to have been called on the flags client.
603
573
  */
604
574
  get(options?: {
605
575
  context?: Context[];
@@ -634,11 +604,7 @@ declare class JsonFlag extends Flag {
634
604
  }
635
605
 
636
606
  /**
637
- * FlagsClient — management + prescriptive runtime for Smpl Flags.
638
- *
639
- * Uses the generated OpenAPI types (`src/generated/flags.d.ts`) via
640
- * `openapi-fetch` for all flag HTTP calls. Context registration uses
641
- * the generated app service types (`src/generated/app.d.ts`).
607
+ * FlagsClient — management and runtime for Smpl Flags.
642
608
  */
643
609
 
644
610
  type FlagResource = components["schemas"]["FlagResource"];
@@ -648,14 +614,14 @@ declare class FlagChangeEvent {
648
614
  readonly source: string;
649
615
  constructor(key: string, source: string);
650
616
  }
651
- /** Cache statistics for the flags runtime. */
617
+ /** Evaluation statistics for the flags runtime. */
652
618
  declare class FlagStats {
653
619
  readonly cacheHits: number;
654
620
  readonly cacheMisses: number;
655
621
  constructor(cacheHits: number, cacheMisses: number);
656
622
  }
657
623
  /**
658
- * Client for the smplkit Flags API — management plane + prescriptive runtime.
624
+ * Client for the smplkit Flags API.
659
625
  *
660
626
  * Obtained via `SmplClient.flags`.
661
627
  */
@@ -751,38 +717,37 @@ declare class FlagsClient {
751
717
  */
752
718
  contextProvider(fn: () => Context[]): () => Context[];
753
719
  /**
754
- * Initialize the flags runtime: fetch definitions and wire WebSocket.
720
+ * Initialize the flags runtime.
755
721
  *
756
722
  * Idempotent — safe to call multiple times. Must be called (and awaited)
757
723
  * before using `.get()` on flag handles.
758
724
  */
759
725
  initialize(): Promise<void>;
760
- /** Disconnect: unregister from WebSocket, flush contexts, clear state. */
726
+ /** Disconnect the flags runtime and release resources. */
761
727
  disconnect(): Promise<void>;
762
- /** Re-fetch all flag definitions and clear cache. */
728
+ /** Refresh all flag definitions from the server. */
763
729
  refresh(): Promise<void>;
764
- /** Return the current WebSocket connection status. */
730
+ /** Return the current real-time connection status. */
765
731
  connectionStatus(): string;
766
- /** Return cache statistics. */
732
+ /** Return evaluation statistics. */
767
733
  stats(): FlagStats;
768
734
  /**
769
735
  * Register a change listener.
770
736
  *
771
- * - `onChange(callback)` — fires for any flag change (global).
737
+ * - `onChange(callback)` — fires for any flag change.
772
738
  * - `onChange(key, callback)` — fires only for the specified flag key.
773
739
  */
774
740
  onChange(callbackOrKey: string | ((event: FlagChangeEvent) => void), callback?: (event: FlagChangeEvent) => void): void;
775
741
  /**
776
- * Explicitly register context(s) for background batch registration.
742
+ * Register context(s) with the server.
777
743
  *
778
- * Accepts a single Context or an array. Fire-and-forget never
779
- * blocks. Works before `initialize()` is called.
744
+ * Accepts a single Context or an array. Works before `initialize()` is called.
780
745
  */
781
746
  register(context: Context | Context[]): void;
782
747
  /** Flush pending context registrations to the server. */
783
748
  flushContexts(): Promise<void>;
784
749
  /**
785
- * Tier 1 explicit evaluation stateless, no provider or cache.
750
+ * Evaluate a flag with an explicit environment and context.
786
751
  */
787
752
  evaluate(key: string, options: {
788
753
  environment: string;
@@ -834,9 +799,7 @@ interface LoggerChangeEvent {
834
799
  /**
835
800
  * A logger resource managed by the smplkit platform.
836
801
  *
837
- * Management: mutate properties and call `save()` to persist.
838
- * Convenience methods (`setLevel`, `setEnvironmentLevel`, etc.) are
839
- * sync local mutations — no HTTP until `save()`.
802
+ * Mutate properties or use convenience methods, then call `save()` to persist.
840
803
  */
841
804
  declare class Logger {
842
805
  /** UUID of the logger, or `null` if unsaved. */
@@ -877,18 +840,18 @@ declare class Logger {
877
840
  /**
878
841
  * Persist this logger to the server.
879
842
  *
880
- * POST if `id` is null (new), PUT if `id` is set (update).
843
+ * Creates if new, updates if existing.
881
844
  */
882
845
  save(): Promise<void>;
883
- /** Set the base log level (sync local mutation). */
846
+ /** Set the base log level. Call `save()` to persist. */
884
847
  setLevel(level: LogLevel): void;
885
- /** Clear the base log level (sync local mutation). */
848
+ /** Clear the base log level. Call `save()` to persist. */
886
849
  clearLevel(): void;
887
- /** Set an environment-specific log level (sync local mutation). */
850
+ /** Set an environment-specific log level. Call `save()` to persist. */
888
851
  setEnvironmentLevel(env: string, level: LogLevel): void;
889
- /** Clear an environment-specific log level (sync local mutation). */
852
+ /** Clear an environment-specific log level. Call `save()` to persist. */
890
853
  clearEnvironmentLevel(env: string): void;
891
- /** Clear all environment-specific log levels (sync local mutation). */
854
+ /** Clear all environment-specific log levels. Call `save()` to persist. */
892
855
  clearAllEnvironmentLevels(): void;
893
856
  /** @internal — copy all fields from another Logger instance. */
894
857
  _apply(other: Logger): void;
@@ -932,18 +895,18 @@ declare class LogGroup {
932
895
  /**
933
896
  * Persist this log group to the server.
934
897
  *
935
- * POST if `id` is null (new), PUT if `id` is set (update).
898
+ * Creates if new, updates if existing.
936
899
  */
937
900
  save(): Promise<void>;
938
- /** Set the base log level (sync local mutation). */
901
+ /** Set the base log level. Call `save()` to persist. */
939
902
  setLevel(level: LogLevel): void;
940
- /** Clear the base log level (sync local mutation). */
903
+ /** Clear the base log level. Call `save()` to persist. */
941
904
  clearLevel(): void;
942
- /** Set an environment-specific log level (sync local mutation). */
905
+ /** Set an environment-specific log level. Call `save()` to persist. */
943
906
  setEnvironmentLevel(env: string, level: LogLevel): void;
944
- /** Clear an environment-specific log level (sync local mutation). */
907
+ /** Clear an environment-specific log level. Call `save()` to persist. */
945
908
  clearEnvironmentLevel(env: string): void;
946
- /** Clear all environment-specific log levels (sync local mutation). */
909
+ /** Clear all environment-specific log levels. Call `save()` to persist. */
947
910
  clearAllEnvironmentLevels(): void;
948
911
  /** @internal — copy all fields from another LogGroup instance. */
949
912
  _apply(other: LogGroup): void;
@@ -951,20 +914,14 @@ declare class LogGroup {
951
914
  }
952
915
 
953
916
  /**
954
- * Contract for pluggable logging framework integration.
955
- *
956
- * Adapters bridge the smplkit logging runtime to a specific logging framework.
957
- * The core LoggingClient delegates all framework-specific work through this interface.
958
- *
959
- * Adapters are NOT responsible for: key normalization, caching, bulk registration,
960
- * level resolution, or WebSocket handling. Those remain in the core client.
917
+ * Contract for logging framework adapters.
961
918
  */
962
919
  interface LoggingAdapter {
963
920
  /** Human-readable adapter name for diagnostics (e.g., 'winston'). */
964
921
  readonly name: string;
965
922
  /**
966
- * Scan the runtime for existing loggers.
967
- * Returns an array of { name, level } where level is a smplkit level string.
923
+ * Return all existing loggers known to the framework.
924
+ * Each entry contains a name and a level string.
968
925
  */
969
926
  discover(): Array<{
970
927
  name: string;
@@ -972,29 +929,25 @@ interface LoggingAdapter {
972
929
  }>;
973
930
  /**
974
931
  * Set the level on a specific logger.
975
- * @param loggerName - The original (non-normalized) logger name.
932
+ * @param loggerName - The logger name.
976
933
  * @param level - smplkit level string (e.g., 'DEBUG', 'INFO', 'WARN').
977
934
  */
978
935
  applyLevel(loggerName: string, level: string): void;
979
936
  /**
980
- * Install continuous discovery hook.
981
- * The callback receives (original_name, smplkit_level_string) whenever
982
- * a new logger is created in the framework.
937
+ * Install a hook that fires whenever a new logger is created in the framework.
938
+ * The callback receives the logger name and level string.
983
939
  */
984
940
  installHook(onNewLogger: (name: string, level: string) => void): void;
985
- /** Remove the hook installed by installHook(). Called on client close(). */
941
+ /** Remove the hook installed by `installHook()`. */
986
942
  uninstallHook(): void;
987
943
  }
988
944
 
989
945
  /**
990
- * LoggingClient — management plane + scaffolded runtime for Smpl Logging.
991
- *
992
- * Uses the generated OpenAPI types (`src/generated/logging.d.ts`) via
993
- * `openapi-fetch` for all HTTP calls.
946
+ * LoggingClient — management and runtime for Smpl Logging.
994
947
  */
995
948
 
996
949
  /**
997
- * Client for the smplkit Logging API — management plane + scaffolded runtime.
950
+ * Client for the smplkit Logging API.
998
951
  *
999
952
  * Obtained via `SmplClient.logging`.
1000
953
  */
@@ -1022,8 +975,8 @@ declare class LoggingClient {
1022
975
  /**
1023
976
  * Register a logging framework adapter.
1024
977
  *
1025
- * Must be called before `start()`. Disables auto-loading of built-in
1026
- * adapters — only explicitly registered adapters will be used.
978
+ * Must be called before `start()`. When called, only explicitly
979
+ * registered adapters will be used.
1027
980
  */
1028
981
  registerAdapter(adapter: LoggingAdapter): void;
1029
982
  /** Create an unsaved logger. Call `.save()` to persist. */
@@ -1055,23 +1008,15 @@ declare class LoggingClient {
1055
1008
  /**
1056
1009
  * Start the logging runtime.
1057
1010
  *
1058
- * Performs the full runtime pipeline:
1059
- * 1. Auto-load adapters (if none registered explicitly)
1060
- * 2. Discover existing loggers from each adapter
1061
- * 3. Install hooks on each adapter for new logger creation
1062
- * 4. Bulk-register discovered loggers with the server
1063
- * 5. Fetch all loggers and groups from the server
1064
- * 6. Resolve levels and apply to adapters
1065
- * 7. Wire WebSocket for live updates
1066
- *
1067
- * Idempotent — safe to call multiple times.
1068
- * Management methods work without start().
1011
+ * Synchronizes loggers with the server and subscribes to live level
1012
+ * updates. Idempotent safe to call multiple times.
1013
+ * Management methods work without calling `start()`.
1069
1014
  */
1070
1015
  start(): Promise<void>;
1071
1016
  /**
1072
1017
  * Register a change listener.
1073
1018
  *
1074
- * - `onChange(callback)` — fires for any logger change (global).
1019
+ * - `onChange(callback)` — fires for any logger change.
1075
1020
  * - `onChange(key, callback)` — fires only for the specified logger key.
1076
1021
  */
1077
1022
  onChange(callbackOrKey: string | ((event: LoggerChangeEvent) => void), callback?: (event: LoggerChangeEvent) => void): void;
@@ -1168,11 +1113,6 @@ declare class SmplClient {
1168
1113
 
1169
1114
  /**
1170
1115
  * Winston logging framework adapter.
1171
- *
1172
- * Bridges the smplkit logging runtime to winston's logger container.
1173
- * Discovers loggers via `winston.loggers` (the Container), hooks into
1174
- * new logger creation by monkey-patching `Container.add()`, and applies
1175
- * levels by setting `logger.level` on the winston logger instance.
1176
1116
  */
1177
1117
 
1178
1118
  interface WinstonAdapterConfig {
@@ -1198,11 +1138,6 @@ declare class WinstonAdapter implements LoggingAdapter {
1198
1138
 
1199
1139
  /**
1200
1140
  * Pino logging framework adapter.
1201
- *
1202
- * Pino has no global logger registry. This adapter builds its own internal
1203
- * registry by monkey-patching the pino module's default export and the
1204
- * `child()` method on created loggers. Logger instances are tracked via
1205
- * WeakRef to avoid memory leaks.
1206
1141
  */
1207
1142
 
1208
1143
  interface PinoAdapterConfig {