@smplkit/sdk 1.3.23 → 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.cjs +38 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -109
- package/dist/index.d.ts +61 -109
- package/dist/index.js +38 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared WebSocket connection
|
|
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
|
|
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;
|
|
@@ -66,7 +51,7 @@ 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
|
|
54
|
+
/** Base key-value pairs. */
|
|
70
55
|
items: Record<string, unknown>;
|
|
71
56
|
/**
|
|
72
57
|
* Per-environment overrides.
|
|
@@ -118,23 +103,17 @@ declare class Config {
|
|
|
118
103
|
|
|
119
104
|
/**
|
|
120
105
|
* LiveConfigProxy — live configuration access.
|
|
121
|
-
*
|
|
122
|
-
* Property reads always return the latest resolved values. When the
|
|
123
|
-
* underlying config changes, subsequent reads automatically reflect
|
|
124
|
-
* the new values.
|
|
125
106
|
*/
|
|
126
107
|
|
|
127
108
|
/**
|
|
128
|
-
* A live proxy
|
|
129
|
-
*
|
|
130
|
-
* Access properties directly — each read returns the latest resolved value.
|
|
109
|
+
* A live proxy whose properties always reflect the latest config values.
|
|
131
110
|
*
|
|
132
111
|
* @example
|
|
133
112
|
* ```typescript
|
|
134
113
|
* const proxy = await client.config.subscribe("user-service");
|
|
135
|
-
* console.log(proxy.timeout); //
|
|
136
|
-
* // ... later, after a
|
|
137
|
-
* console.log(proxy.timeout); //
|
|
114
|
+
* console.log(proxy.timeout); // current value
|
|
115
|
+
* // ... later, after a config change ...
|
|
116
|
+
* console.log(proxy.timeout); // updated value
|
|
138
117
|
* ```
|
|
139
118
|
*/
|
|
140
119
|
declare class LiveConfigProxy<T = Record<string, unknown>> {
|
|
@@ -163,7 +142,7 @@ interface ConfigChangeEvent {
|
|
|
163
142
|
source: "websocket" | "manual";
|
|
164
143
|
}
|
|
165
144
|
/**
|
|
166
|
-
* Client for the smplkit Config API
|
|
145
|
+
* Client for the smplkit Config API.
|
|
167
146
|
*
|
|
168
147
|
* Obtained via `SmplClient.config`.
|
|
169
148
|
*/
|
|
@@ -207,15 +186,13 @@ declare class ConfigClient {
|
|
|
207
186
|
/**
|
|
208
187
|
* Resolve a config's values for the current environment.
|
|
209
188
|
*
|
|
210
|
-
* Returns
|
|
211
|
-
* values and environment overrides applied.
|
|
212
|
-
*
|
|
189
|
+
* Returns the resolved key-value pairs for the given config.
|
|
213
190
|
* Optionally pass a model class to map the resolved values.
|
|
214
191
|
*/
|
|
215
192
|
resolve<T = Record<string, unknown>>(key: string, model?: new (data: any) => T): Promise<T>;
|
|
216
193
|
/**
|
|
217
|
-
* Subscribe to a config's values
|
|
218
|
-
*
|
|
194
|
+
* Subscribe to a config's values. Returns a proxy whose properties
|
|
195
|
+
* always reflect the latest resolved values.
|
|
219
196
|
*
|
|
220
197
|
* Optionally pass a model class to map the resolved values.
|
|
221
198
|
*/
|
|
@@ -229,8 +206,8 @@ declare class ConfigClient {
|
|
|
229
206
|
*/
|
|
230
207
|
onChange(callbackOrConfigKey: string | ((event: ConfigChangeEvent) => void), callbackOrItemKey?: string | ((event: ConfigChangeEvent) => void), callback?: (event: ConfigChangeEvent) => void): void;
|
|
231
208
|
/**
|
|
232
|
-
*
|
|
233
|
-
* Fires change listeners for any values that
|
|
209
|
+
* Refresh all config values from the server.
|
|
210
|
+
* Fires change listeners for any values that changed.
|
|
234
211
|
*/
|
|
235
212
|
refresh(): Promise<void>;
|
|
236
213
|
/** @internal */
|
|
@@ -487,7 +464,7 @@ declare class Context {
|
|
|
487
464
|
toString(): string;
|
|
488
465
|
}
|
|
489
466
|
/**
|
|
490
|
-
* Fluent builder for
|
|
467
|
+
* Fluent builder for flag targeting rules.
|
|
491
468
|
*
|
|
492
469
|
* @example
|
|
493
470
|
* ```typescript
|
|
@@ -498,8 +475,7 @@ declare class Context {
|
|
|
498
475
|
* .build()
|
|
499
476
|
* ```
|
|
500
477
|
*
|
|
501
|
-
* Multiple `.when()` calls are AND
|
|
502
|
-
* built dict with an environment key for use with `Flag.addRule()`.
|
|
478
|
+
* Multiple `.when()` calls are combined with AND logic.
|
|
503
479
|
*/
|
|
504
480
|
declare class Rule {
|
|
505
481
|
private _description;
|
|
@@ -518,18 +494,13 @@ declare class Rule {
|
|
|
518
494
|
}
|
|
519
495
|
|
|
520
496
|
/**
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
* A single {@link Flag} class replaces the old separate Flag + FlagHandle
|
|
524
|
-
* classes. Typed subclasses ({@link BooleanFlag}, {@link StringFlag},
|
|
525
|
-
* {@link NumberFlag}, {@link JsonFlag}) override `get()` for type safety.
|
|
497
|
+
* Flag model hierarchy with typed subclasses for type-safe evaluation.
|
|
526
498
|
*/
|
|
527
499
|
|
|
528
500
|
/**
|
|
529
|
-
* A flag resource
|
|
501
|
+
* A flag resource.
|
|
530
502
|
*
|
|
531
|
-
*
|
|
532
|
-
* Runtime: call `get()` to evaluate the flag locally.
|
|
503
|
+
* Call `save()` to persist changes. Call `get()` to evaluate the flag.
|
|
533
504
|
*/
|
|
534
505
|
declare class Flag {
|
|
535
506
|
/** UUID of the flag, or `null` if unsaved. */
|
|
@@ -581,24 +552,24 @@ declare class Flag {
|
|
|
581
552
|
*/
|
|
582
553
|
save(): Promise<void>;
|
|
583
554
|
/**
|
|
584
|
-
* Add a rule to a specific environment
|
|
555
|
+
* Add a rule to a specific environment.
|
|
585
556
|
*
|
|
586
557
|
* The built rule must include an `environment` key (set via
|
|
587
|
-
* `Rule(...).environment("env_key")`).
|
|
558
|
+
* `Rule(...).environment("env_key")`). Call `save()` to persist.
|
|
588
559
|
*
|
|
589
560
|
* @returns `this` for chaining.
|
|
590
561
|
*/
|
|
591
562
|
addRule(builtRule: Record<string, any>): Flag;
|
|
592
|
-
/** Enable or disable a flag in a specific environment (
|
|
563
|
+
/** Enable or disable a flag in a specific environment. Call `save()` to persist. */
|
|
593
564
|
setEnvironmentEnabled(envKey: string, enabled: boolean): void;
|
|
594
|
-
/** Set the default value for a specific environment (
|
|
565
|
+
/** Set the default value for a specific environment. Call `save()` to persist. */
|
|
595
566
|
setEnvironmentDefault(envKey: string, defaultValue: unknown): void;
|
|
596
|
-
/** Clear all rules for a specific environment (
|
|
567
|
+
/** Clear all rules for a specific environment. Call `save()` to persist. */
|
|
597
568
|
clearRules(envKey: string): void;
|
|
598
569
|
/**
|
|
599
|
-
* Evaluate the flag
|
|
570
|
+
* Evaluate the flag and return its current value.
|
|
600
571
|
*
|
|
601
|
-
* Requires `initialize()` to have been called.
|
|
572
|
+
* Requires `initialize()` to have been called on the flags client.
|
|
602
573
|
*/
|
|
603
574
|
get(options?: {
|
|
604
575
|
context?: Context[];
|
|
@@ -633,7 +604,7 @@ declare class JsonFlag extends Flag {
|
|
|
633
604
|
}
|
|
634
605
|
|
|
635
606
|
/**
|
|
636
|
-
* FlagsClient — management
|
|
607
|
+
* FlagsClient — management and runtime for Smpl Flags.
|
|
637
608
|
*/
|
|
638
609
|
|
|
639
610
|
type FlagResource = components["schemas"]["FlagResource"];
|
|
@@ -643,14 +614,14 @@ declare class FlagChangeEvent {
|
|
|
643
614
|
readonly source: string;
|
|
644
615
|
constructor(key: string, source: string);
|
|
645
616
|
}
|
|
646
|
-
/**
|
|
617
|
+
/** Evaluation statistics for the flags runtime. */
|
|
647
618
|
declare class FlagStats {
|
|
648
619
|
readonly cacheHits: number;
|
|
649
620
|
readonly cacheMisses: number;
|
|
650
621
|
constructor(cacheHits: number, cacheMisses: number);
|
|
651
622
|
}
|
|
652
623
|
/**
|
|
653
|
-
* Client for the smplkit Flags API
|
|
624
|
+
* Client for the smplkit Flags API.
|
|
654
625
|
*
|
|
655
626
|
* Obtained via `SmplClient.flags`.
|
|
656
627
|
*/
|
|
@@ -746,40 +717,37 @@ declare class FlagsClient {
|
|
|
746
717
|
*/
|
|
747
718
|
contextProvider(fn: () => Context[]): () => Context[];
|
|
748
719
|
/**
|
|
749
|
-
* Initialize the flags runtime
|
|
720
|
+
* Initialize the flags runtime.
|
|
750
721
|
*
|
|
751
722
|
* Idempotent — safe to call multiple times. Must be called (and awaited)
|
|
752
723
|
* before using `.get()` on flag handles.
|
|
753
724
|
*/
|
|
754
725
|
initialize(): Promise<void>;
|
|
755
|
-
/** Disconnect
|
|
726
|
+
/** Disconnect the flags runtime and release resources. */
|
|
756
727
|
disconnect(): Promise<void>;
|
|
757
|
-
/**
|
|
728
|
+
/** Refresh all flag definitions from the server. */
|
|
758
729
|
refresh(): Promise<void>;
|
|
759
|
-
/** Return the current
|
|
730
|
+
/** Return the current real-time connection status. */
|
|
760
731
|
connectionStatus(): string;
|
|
761
|
-
/** Return
|
|
732
|
+
/** Return evaluation statistics. */
|
|
762
733
|
stats(): FlagStats;
|
|
763
734
|
/**
|
|
764
735
|
* Register a change listener.
|
|
765
736
|
*
|
|
766
|
-
* - `onChange(callback)` — fires for any flag change
|
|
737
|
+
* - `onChange(callback)` — fires for any flag change.
|
|
767
738
|
* - `onChange(key, callback)` — fires only for the specified flag key.
|
|
768
739
|
*/
|
|
769
740
|
onChange(callbackOrKey: string | ((event: FlagChangeEvent) => void), callback?: (event: FlagChangeEvent) => void): void;
|
|
770
741
|
/**
|
|
771
742
|
* Register context(s) with the server.
|
|
772
743
|
*
|
|
773
|
-
* Accepts a single Context or an array.
|
|
774
|
-
* and never blocks. Works before `initialize()` is called.
|
|
744
|
+
* Accepts a single Context or an array. Works before `initialize()` is called.
|
|
775
745
|
*/
|
|
776
746
|
register(context: Context | Context[]): void;
|
|
777
747
|
/** Flush pending context registrations to the server. */
|
|
778
748
|
flushContexts(): Promise<void>;
|
|
779
749
|
/**
|
|
780
750
|
* Evaluate a flag with an explicit environment and context.
|
|
781
|
-
*
|
|
782
|
-
* Stateless — does not use the context provider or cached results.
|
|
783
751
|
*/
|
|
784
752
|
evaluate(key: string, options: {
|
|
785
753
|
environment: string;
|
|
@@ -831,9 +799,7 @@ interface LoggerChangeEvent {
|
|
|
831
799
|
/**
|
|
832
800
|
* A logger resource managed by the smplkit platform.
|
|
833
801
|
*
|
|
834
|
-
*
|
|
835
|
-
* Convenience methods (`setLevel`, `setEnvironmentLevel`, etc.) are
|
|
836
|
-
* sync local mutations — no HTTP until `save()`.
|
|
802
|
+
* Mutate properties or use convenience methods, then call `save()` to persist.
|
|
837
803
|
*/
|
|
838
804
|
declare class Logger {
|
|
839
805
|
/** UUID of the logger, or `null` if unsaved. */
|
|
@@ -877,15 +843,15 @@ declare class Logger {
|
|
|
877
843
|
* Creates if new, updates if existing.
|
|
878
844
|
*/
|
|
879
845
|
save(): Promise<void>;
|
|
880
|
-
/** Set the base log level (
|
|
846
|
+
/** Set the base log level. Call `save()` to persist. */
|
|
881
847
|
setLevel(level: LogLevel): void;
|
|
882
|
-
/** Clear the base log level (
|
|
848
|
+
/** Clear the base log level. Call `save()` to persist. */
|
|
883
849
|
clearLevel(): void;
|
|
884
|
-
/** Set an environment-specific log level (
|
|
850
|
+
/** Set an environment-specific log level. Call `save()` to persist. */
|
|
885
851
|
setEnvironmentLevel(env: string, level: LogLevel): void;
|
|
886
|
-
/** Clear an environment-specific log level (
|
|
852
|
+
/** Clear an environment-specific log level. Call `save()` to persist. */
|
|
887
853
|
clearEnvironmentLevel(env: string): void;
|
|
888
|
-
/** Clear all environment-specific log levels (
|
|
854
|
+
/** Clear all environment-specific log levels. Call `save()` to persist. */
|
|
889
855
|
clearAllEnvironmentLevels(): void;
|
|
890
856
|
/** @internal — copy all fields from another Logger instance. */
|
|
891
857
|
_apply(other: Logger): void;
|
|
@@ -932,15 +898,15 @@ declare class LogGroup {
|
|
|
932
898
|
* Creates if new, updates if existing.
|
|
933
899
|
*/
|
|
934
900
|
save(): Promise<void>;
|
|
935
|
-
/** Set the base log level (
|
|
901
|
+
/** Set the base log level. Call `save()` to persist. */
|
|
936
902
|
setLevel(level: LogLevel): void;
|
|
937
|
-
/** Clear the base log level (
|
|
903
|
+
/** Clear the base log level. Call `save()` to persist. */
|
|
938
904
|
clearLevel(): void;
|
|
939
|
-
/** Set an environment-specific log level (
|
|
905
|
+
/** Set an environment-specific log level. Call `save()` to persist. */
|
|
940
906
|
setEnvironmentLevel(env: string, level: LogLevel): void;
|
|
941
|
-
/** Clear an environment-specific log level (
|
|
907
|
+
/** Clear an environment-specific log level. Call `save()` to persist. */
|
|
942
908
|
clearEnvironmentLevel(env: string): void;
|
|
943
|
-
/** Clear all environment-specific log levels (
|
|
909
|
+
/** Clear all environment-specific log levels. Call `save()` to persist. */
|
|
944
910
|
clearAllEnvironmentLevels(): void;
|
|
945
911
|
/** @internal — copy all fields from another LogGroup instance. */
|
|
946
912
|
_apply(other: LogGroup): void;
|
|
@@ -948,17 +914,14 @@ declare class LogGroup {
|
|
|
948
914
|
}
|
|
949
915
|
|
|
950
916
|
/**
|
|
951
|
-
* Contract for
|
|
952
|
-
*
|
|
953
|
-
* Adapters bridge the smplkit logging runtime to a specific logging
|
|
954
|
-
* framework (e.g., Winston, Pino).
|
|
917
|
+
* Contract for logging framework adapters.
|
|
955
918
|
*/
|
|
956
919
|
interface LoggingAdapter {
|
|
957
920
|
/** Human-readable adapter name for diagnostics (e.g., 'winston'). */
|
|
958
921
|
readonly name: string;
|
|
959
922
|
/**
|
|
960
|
-
*
|
|
961
|
-
*
|
|
923
|
+
* Return all existing loggers known to the framework.
|
|
924
|
+
* Each entry contains a name and a level string.
|
|
962
925
|
*/
|
|
963
926
|
discover(): Array<{
|
|
964
927
|
name: string;
|
|
@@ -966,26 +929,25 @@ interface LoggingAdapter {
|
|
|
966
929
|
}>;
|
|
967
930
|
/**
|
|
968
931
|
* Set the level on a specific logger.
|
|
969
|
-
* @param loggerName - The
|
|
932
|
+
* @param loggerName - The logger name.
|
|
970
933
|
* @param level - smplkit level string (e.g., 'DEBUG', 'INFO', 'WARN').
|
|
971
934
|
*/
|
|
972
935
|
applyLevel(loggerName: string, level: string): void;
|
|
973
936
|
/**
|
|
974
|
-
* Install
|
|
975
|
-
* The callback receives
|
|
976
|
-
* 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.
|
|
977
939
|
*/
|
|
978
940
|
installHook(onNewLogger: (name: string, level: string) => void): void;
|
|
979
|
-
/** Remove the hook installed by installHook()
|
|
941
|
+
/** Remove the hook installed by `installHook()`. */
|
|
980
942
|
uninstallHook(): void;
|
|
981
943
|
}
|
|
982
944
|
|
|
983
945
|
/**
|
|
984
|
-
* LoggingClient — management
|
|
946
|
+
* LoggingClient — management and runtime for Smpl Logging.
|
|
985
947
|
*/
|
|
986
948
|
|
|
987
949
|
/**
|
|
988
|
-
* Client for the smplkit Logging API
|
|
950
|
+
* Client for the smplkit Logging API.
|
|
989
951
|
*
|
|
990
952
|
* Obtained via `SmplClient.logging`.
|
|
991
953
|
*/
|
|
@@ -1013,8 +975,8 @@ declare class LoggingClient {
|
|
|
1013
975
|
/**
|
|
1014
976
|
* Register a logging framework adapter.
|
|
1015
977
|
*
|
|
1016
|
-
* Must be called before `start()`.
|
|
1017
|
-
*
|
|
978
|
+
* Must be called before `start()`. When called, only explicitly
|
|
979
|
+
* registered adapters will be used.
|
|
1018
980
|
*/
|
|
1019
981
|
registerAdapter(adapter: LoggingAdapter): void;
|
|
1020
982
|
/** Create an unsaved logger. Call `.save()` to persist. */
|
|
@@ -1046,18 +1008,15 @@ declare class LoggingClient {
|
|
|
1046
1008
|
/**
|
|
1047
1009
|
* Start the logging runtime.
|
|
1048
1010
|
*
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
* Idempotent — safe to call multiple times.
|
|
1054
|
-
* 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()`.
|
|
1055
1014
|
*/
|
|
1056
1015
|
start(): Promise<void>;
|
|
1057
1016
|
/**
|
|
1058
1017
|
* Register a change listener.
|
|
1059
1018
|
*
|
|
1060
|
-
* - `onChange(callback)` — fires for any logger change
|
|
1019
|
+
* - `onChange(callback)` — fires for any logger change.
|
|
1061
1020
|
* - `onChange(key, callback)` — fires only for the specified logger key.
|
|
1062
1021
|
*/
|
|
1063
1022
|
onChange(callbackOrKey: string | ((event: LoggerChangeEvent) => void), callback?: (event: LoggerChangeEvent) => void): void;
|
|
@@ -1154,10 +1113,6 @@ declare class SmplClient {
|
|
|
1154
1113
|
|
|
1155
1114
|
/**
|
|
1156
1115
|
* Winston logging framework adapter.
|
|
1157
|
-
*
|
|
1158
|
-
* Integrates the smplkit logging runtime with Winston. Discovers
|
|
1159
|
-
* existing loggers, tracks new logger creation, and applies
|
|
1160
|
-
* server-managed log levels.
|
|
1161
1116
|
*/
|
|
1162
1117
|
|
|
1163
1118
|
interface WinstonAdapterConfig {
|
|
@@ -1183,9 +1138,6 @@ declare class WinstonAdapter implements LoggingAdapter {
|
|
|
1183
1138
|
|
|
1184
1139
|
/**
|
|
1185
1140
|
* Pino logging framework adapter.
|
|
1186
|
-
*
|
|
1187
|
-
* Integrates the smplkit logging runtime with Pino. Tracks logger
|
|
1188
|
-
* instances (including child loggers) for discovery and level control.
|
|
1189
1141
|
*/
|
|
1190
1142
|
|
|
1191
1143
|
interface PinoAdapterConfig {
|