@smplkit/sdk 1.3.26 → 1.3.28

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.cts CHANGED
@@ -1,6 +1,43 @@
1
+ /**
2
+ * Internal SDK telemetry engine.
3
+ *
4
+ * Accumulates usage metrics in memory and periodically flushes them to the
5
+ * app service via `POST /api/v1/metrics/bulk`. This module is entirely
6
+ * private — nothing here is exported or documented for customers.
7
+ *
8
+ * @internal
9
+ */
10
+ /** @internal */
11
+ declare class MetricsReporter {
12
+ private readonly _apiKey;
13
+ private readonly _environment;
14
+ private readonly _service;
15
+ private readonly _flushInterval;
16
+ private _counters;
17
+ private _gauges;
18
+ private _timer;
19
+ private _closed;
20
+ constructor(options: {
21
+ apiKey: string;
22
+ environment: string;
23
+ service: string;
24
+ flushInterval?: number;
25
+ });
26
+ record(name: string, value?: number, unit?: string | null, dimensions?: Record<string, string>): void;
27
+ recordGauge(name: string, value: number, unit?: string | null, dimensions?: Record<string, string>): void;
28
+ flush(): void;
29
+ close(): void;
30
+ private _mergeDimensions;
31
+ private _maybeStartTimer;
32
+ private _flush;
33
+ private _buildPayload;
34
+ private _entry;
35
+ }
36
+
1
37
  /**
2
38
  * Shared WebSocket connection for real-time event delivery.
3
39
  */
40
+
4
41
  type EventCallback = (data: Record<string, any>) => void;
5
42
  /**
6
43
  * Manages a WebSocket connection for real-time event delivery.
@@ -8,13 +45,14 @@ type EventCallback = (data: Record<string, any>) => void;
8
45
  declare class SharedWebSocket {
9
46
  private readonly _appBaseUrl;
10
47
  private readonly _apiKey;
48
+ private readonly _metrics;
11
49
  private _listeners;
12
50
  private _connectionStatus;
13
51
  private _closed;
14
52
  private _ws;
15
53
  private _reconnectTimer;
16
54
  private _backoffIndex;
17
- constructor(appBaseUrl: string, apiKey: string);
55
+ constructor(appBaseUrl: string, apiKey: string, metrics?: MetricsReporter | null);
18
56
  /** Register a listener for a specific event type. */
19
57
  on(eventName: string, callback: EventCallback): void;
20
58
  /** Unregister a listener for a specific event type. */
@@ -41,15 +79,13 @@ declare class SharedWebSocket {
41
79
  * Creates if new, updates if existing.
42
80
  */
43
81
  declare class Config {
44
- /** UUID of the config, or `null` if unsaved. */
82
+ /** Unique identifier (slug, e.g. `"user-service"`). */
45
83
  id: string | null;
46
- /** Human-readable key (e.g. `"user-service"`). */
47
- key: string;
48
84
  /** Display name. */
49
85
  name: string;
50
86
  /** Optional description. */
51
87
  description: string | null;
52
- /** Parent config UUID, or null if this is a root config. */
88
+ /** Parent config id (slug), or null if this is a root config. */
53
89
  parent: string | null;
54
90
  /** Base key-value pairs. */
55
91
  items: Record<string, unknown>;
@@ -67,7 +103,6 @@ declare class Config {
67
103
  /** @internal */
68
104
  constructor(client: ConfigClient, fields: {
69
105
  id: string | null;
70
- key: string;
71
106
  name: string;
72
107
  description: string | null;
73
108
  parent: string | null;
@@ -130,8 +165,8 @@ declare class LiveConfigProxy<T = Record<string, unknown>> {
130
165
 
131
166
  /** Describes a single config value change detected on refresh. */
132
167
  interface ConfigChangeEvent {
133
- /** The config key that changed. */
134
- configKey: string;
168
+ /** The config id that changed. */
169
+ configId: string;
135
170
  /** The item key within the config that changed. */
136
171
  itemKey: string;
137
172
  /** The previous value (null if the key was absent). */
@@ -159,6 +194,7 @@ declare class ConfigClient {
159
194
  _parent: {
160
195
  readonly _environment: string;
161
196
  readonly _service: string | null;
197
+ readonly _metrics: MetricsReporter | null;
162
198
  } | null;
163
199
  private _configCache;
164
200
  private _initialized;
@@ -166,45 +202,45 @@ declare class ConfigClient {
166
202
  /** @internal */
167
203
  constructor(apiKey: string, timeout?: number);
168
204
  /** Create an unsaved config. Call `.save()` to persist. */
169
- new(key: string, options?: {
205
+ new(id: string, options?: {
170
206
  name?: string;
171
207
  description?: string;
172
208
  parent?: string;
173
209
  }): Config;
174
- /** Fetch a config by key. */
175
- get(key: string): Promise<Config>;
210
+ /** Fetch a config by id. */
211
+ get(id: string): Promise<Config>;
176
212
  /** List all configs. */
177
213
  list(): Promise<Config[]>;
178
- /** Delete a config by key. */
179
- delete(key: string): Promise<void>;
214
+ /** Delete a config by id. */
215
+ delete(id: string): Promise<void>;
180
216
  /** @internal — POST a new config. */
181
217
  _createConfig(config: Config): Promise<Config>;
182
218
  /** @internal — PUT a config update. */
183
219
  _updateConfig(config: Config): Promise<Config>;
184
- /** @internal — fetch a config by UUID. */
185
- _getById(configId: string): Promise<Config>;
220
+ /** @internal — fetch a config by id. */
221
+ _getById(id: string): Promise<Config>;
186
222
  /**
187
223
  * Resolve a config's values for the current environment.
188
224
  *
189
225
  * Returns the resolved key-value pairs for the given config.
190
226
  * Optionally pass a model class to map the resolved values.
191
227
  */
192
- resolve<T = Record<string, unknown>>(key: string, model?: new (data: any) => T): Promise<T>;
228
+ resolve<T = Record<string, unknown>>(id: string, model?: new (data: any) => T): Promise<T>;
193
229
  /**
194
230
  * Subscribe to a config's values. Returns a proxy whose properties
195
231
  * always reflect the latest resolved values.
196
232
  *
197
233
  * Optionally pass a model class to map the resolved values.
198
234
  */
199
- subscribe<T = Record<string, unknown>>(key: string, model?: new (data: any) => T): Promise<LiveConfigProxy<T>>;
235
+ subscribe<T = Record<string, unknown>>(id: string, model?: new (data: any) => T): Promise<LiveConfigProxy<T>>;
200
236
  /**
201
237
  * Register a change listener.
202
238
  *
203
239
  * - `onChange(callback)` — fires for any config change (global).
204
- * - `onChange(configKey, callback)` — fires for changes to a specific config.
205
- * - `onChange(configKey, itemKey, callback)` — fires for a specific item.
240
+ * - `onChange(configId, callback)` — fires for changes to a specific config.
241
+ * - `onChange(configId, itemKey, callback)` — fires for a specific item.
206
242
  */
207
- onChange(callbackOrConfigKey: string | ((event: ConfigChangeEvent) => void), callbackOrItemKey?: string | ((event: ConfigChangeEvent) => void), callback?: (event: ConfigChangeEvent) => void): void;
243
+ onChange(callbackOrConfigId: string | ((event: ConfigChangeEvent) => void), callbackOrItemKey?: string | ((event: ConfigChangeEvent) => void), callback?: (event: ConfigChangeEvent) => void): void;
208
244
  /**
209
245
  * Refresh all config values from the server.
210
246
  * Fires change listeners for any values that changed.
@@ -219,7 +255,6 @@ declare class ConfigClient {
219
255
  private _handleConfigChanged;
220
256
  /** @internal */
221
257
  private _diffAndFire;
222
- private _getByKey;
223
258
  }
224
259
 
225
260
  interface components {
@@ -252,7 +287,6 @@ interface components {
252
287
  * "rules": []
253
288
  * }
254
289
  * },
255
- * "key": "dark_mode",
256
290
  * "name": "Dark Mode",
257
291
  * "type": "BOOLEAN",
258
292
  * "updated_at": "2026-03-27T10:00:00Z",
@@ -269,11 +303,8 @@ interface components {
269
303
  * }
270
304
  */
271
305
  Flag: {
272
- /**
273
- * Key
274
- * @description Unique key within account
275
- */
276
- key: string;
306
+ /** Id */
307
+ id?: string | null;
277
308
  /**
278
309
  * Name
279
310
  * @description Human-readable display name
@@ -349,7 +380,6 @@ interface components {
349
380
  * ]
350
381
  * }
351
382
  * },
352
- * "key": "dark_mode",
353
383
  * "name": "Dark Mode",
354
384
  * "type": "BOOLEAN",
355
385
  * "updated_at": "2026-03-27T10:00:00Z",
@@ -364,7 +394,7 @@ interface components {
364
394
  * }
365
395
  * ]
366
396
  * },
367
- * "id": "550e8400-e29b-41d4-a716-446655440000",
397
+ * "id": "dark_mode",
368
398
  * "type": "flag"
369
399
  * }
370
400
  */
@@ -503,10 +533,8 @@ declare class Rule {
503
533
  * Call `save()` to persist changes. Call `get()` to evaluate the flag.
504
534
  */
505
535
  declare class Flag {
506
- /** UUID of the flag, or `null` if unsaved. */
536
+ /** Unique identifier (slug) within the account. */
507
537
  id: string | null;
508
- /** Unique key within the account. */
509
- key: string;
510
538
  /** Human-readable display name. */
511
539
  name: string;
512
540
  /** Value type: BOOLEAN, STRING, NUMERIC, or JSON. */
@@ -531,7 +559,6 @@ declare class Flag {
531
559
  /** @internal */
532
560
  constructor(client: FlagsClient, fields: {
533
561
  id: string | null;
534
- key: string;
535
562
  name: string;
536
563
  type: string;
537
564
  default: unknown;
@@ -610,9 +637,9 @@ declare class JsonFlag extends Flag {
610
637
  type FlagResource = components["schemas"]["FlagResource"];
611
638
  /** Describes a flag definition change. */
612
639
  declare class FlagChangeEvent {
613
- readonly key: string;
640
+ readonly id: string;
614
641
  readonly source: string;
615
- constructor(key: string, source: string);
642
+ constructor(id: string, source: string);
616
643
  }
617
644
  /** Evaluation statistics for the flags runtime. */
618
645
  declare class FlagStats {
@@ -649,17 +676,18 @@ declare class FlagsClient {
649
676
  _parent: {
650
677
  readonly _environment: string;
651
678
  readonly _service: string | null;
679
+ readonly _metrics: MetricsReporter | null;
652
680
  } | null;
653
681
  /** @internal */
654
682
  constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
655
683
  /** Create an unsaved boolean flag. Call `.save()` to persist. */
656
- newBooleanFlag(key: string, options: {
684
+ newBooleanFlag(id: string, options: {
657
685
  default: boolean;
658
686
  name?: string;
659
687
  description?: string;
660
688
  }): BooleanFlag;
661
689
  /** Create an unsaved string flag. Call `.save()` to persist. */
662
- newStringFlag(key: string, options: {
690
+ newStringFlag(id: string, options: {
663
691
  default: string;
664
692
  name?: string;
665
693
  description?: string;
@@ -669,7 +697,7 @@ declare class FlagsClient {
669
697
  }>;
670
698
  }): StringFlag;
671
699
  /** Create an unsaved number flag. Call `.save()` to persist. */
672
- newNumberFlag(key: string, options: {
700
+ newNumberFlag(id: string, options: {
673
701
  default: number;
674
702
  name?: string;
675
703
  description?: string;
@@ -679,7 +707,7 @@ declare class FlagsClient {
679
707
  }>;
680
708
  }): NumberFlag;
681
709
  /** Create an unsaved JSON flag. Call `.save()` to persist. */
682
- newJsonFlag(key: string, options: {
710
+ newJsonFlag(id: string, options: {
683
711
  default: Record<string, any>;
684
712
  name?: string;
685
713
  description?: string;
@@ -688,24 +716,24 @@ declare class FlagsClient {
688
716
  value: unknown;
689
717
  }>;
690
718
  }): JsonFlag;
691
- /** Fetch a flag by key. */
692
- get(key: string): Promise<Flag>;
719
+ /** Fetch a flag by id. */
720
+ get(id: string): Promise<Flag>;
693
721
  /** List all flags. */
694
722
  list(): Promise<Flag[]>;
695
- /** Delete a flag by key. */
696
- delete(key: string): Promise<void>;
723
+ /** Delete a flag by id. */
724
+ delete(id: string): Promise<void>;
697
725
  /** @internal — POST a new flag. */
698
726
  _createFlag(flag: Flag): Promise<Flag>;
699
727
  /** @internal — PUT a flag update. */
700
728
  _updateFlag(flag: Flag): Promise<Flag>;
701
729
  /** Declare a boolean flag handle for runtime evaluation. */
702
- booleanFlag(key: string, defaultValue: boolean): BooleanFlag;
730
+ booleanFlag(id: string, defaultValue: boolean): BooleanFlag;
703
731
  /** Declare a string flag handle for runtime evaluation. */
704
- stringFlag(key: string, defaultValue: string): StringFlag;
732
+ stringFlag(id: string, defaultValue: string): StringFlag;
705
733
  /** Declare a numeric flag handle for runtime evaluation. */
706
- numberFlag(key: string, defaultValue: number): NumberFlag;
734
+ numberFlag(id: string, defaultValue: number): NumberFlag;
707
735
  /** Declare a JSON flag handle for runtime evaluation. */
708
- jsonFlag(key: string, defaultValue: Record<string, any>): JsonFlag;
736
+ jsonFlag(id: string, defaultValue: Record<string, any>): JsonFlag;
709
737
  /**
710
738
  * Register a context provider function.
711
739
  *
@@ -735,9 +763,9 @@ declare class FlagsClient {
735
763
  * Register a change listener.
736
764
  *
737
765
  * - `onChange(callback)` — fires for any flag change.
738
- * - `onChange(key, callback)` — fires only for the specified flag key.
766
+ * - `onChange(id, callback)` — fires only for the specified flag id.
739
767
  */
740
- onChange(callbackOrKey: string | ((event: FlagChangeEvent) => void), callback?: (event: FlagChangeEvent) => void): void;
768
+ onChange(callbackOrId: string | ((event: FlagChangeEvent) => void), callback?: (event: FlagChangeEvent) => void): void;
741
769
  /**
742
770
  * Register context(s) with the server.
743
771
  *
@@ -749,7 +777,7 @@ declare class FlagsClient {
749
777
  /**
750
778
  * Evaluate a flag with an explicit environment and context.
751
779
  */
752
- evaluate(key: string, options: {
780
+ evaluate(id: string, options: {
753
781
  environment: string;
754
782
  context: Context[];
755
783
  }): Promise<any>;
@@ -784,8 +812,8 @@ declare enum LogLevel {
784
812
  }
785
813
  /** Describes a logger configuration change. */
786
814
  interface LoggerChangeEvent {
787
- /** The logger key that changed. */
788
- key: string;
815
+ /** The logger id that changed. */
816
+ id: string;
789
817
  /** The new effective log level, or null if removed. */
790
818
  level: LogLevel | null;
791
819
  /** How the change was delivered. */
@@ -802,15 +830,13 @@ interface LoggerChangeEvent {
802
830
  * Mutate properties or use convenience methods, then call `save()` to persist.
803
831
  */
804
832
  declare class Logger {
805
- /** UUID of the logger, or `null` if unsaved. */
833
+ /** Unique identifier (dot-separated hierarchy, e.g. `"sqlalchemy.engine"`). */
806
834
  id: string | null;
807
- /** Unique key (dot-separated hierarchy). */
808
- key: string;
809
835
  /** Human-readable display name. */
810
836
  name: string;
811
837
  /** Base log level, or null if inherited. */
812
838
  level: string | null;
813
- /** UUID of the parent log group, or null. */
839
+ /** Id of the parent log group, or null. */
814
840
  group: string | null;
815
841
  /** Whether this logger is managed by the platform. */
816
842
  managed: boolean;
@@ -827,7 +853,6 @@ declare class Logger {
827
853
  /** @internal */
828
854
  constructor(client: LoggingClient, fields: {
829
855
  id: string | null;
830
- key: string;
831
856
  name: string;
832
857
  level: string | null;
833
858
  group: string | null;
@@ -863,15 +888,13 @@ declare class Logger {
863
888
  * Management: mutate properties and call `save()` to persist.
864
889
  */
865
890
  declare class LogGroup {
866
- /** UUID of the log group, or `null` if unsaved. */
891
+ /** Unique identifier (slug), or `null` if unsaved. */
867
892
  id: string | null;
868
- /** Unique key. */
869
- key: string;
870
893
  /** Human-readable display name. */
871
894
  name: string;
872
895
  /** Base log level, or null if inherited. */
873
896
  level: string | null;
874
- /** UUID of the parent log group, or null. */
897
+ /** Id of the parent log group, or null. */
875
898
  group: string | null;
876
899
  /** Per-environment level overrides. */
877
900
  environments: Record<string, any>;
@@ -884,7 +907,6 @@ declare class LogGroup {
884
907
  /** @internal */
885
908
  constructor(client: LoggingClient, fields: {
886
909
  id: string | null;
887
- key: string;
888
910
  name: string;
889
911
  level: string | null;
890
912
  group: string | null;
@@ -962,6 +984,7 @@ declare class LoggingClient {
962
984
  _parent: {
963
985
  readonly _environment: string;
964
986
  readonly _service: string | null;
987
+ readonly _metrics: MetricsReporter | null;
965
988
  } | null;
966
989
  private readonly _ensureWs;
967
990
  private _wsManager;
@@ -980,27 +1003,27 @@ declare class LoggingClient {
980
1003
  */
981
1004
  registerAdapter(adapter: LoggingAdapter): void;
982
1005
  /** Create an unsaved logger. Call `.save()` to persist. */
983
- new(key: string, options?: {
1006
+ new(id: string, options?: {
984
1007
  name?: string;
985
1008
  managed?: boolean;
986
1009
  }): Logger;
987
- /** Fetch a logger by key. */
988
- get(key: string): Promise<Logger>;
1010
+ /** Fetch a logger by id. */
1011
+ get(id: string): Promise<Logger>;
989
1012
  /** List all loggers. */
990
1013
  list(): Promise<Logger[]>;
991
- /** Delete a logger by key. */
992
- delete(key: string): Promise<void>;
1014
+ /** Delete a logger by id. */
1015
+ delete(id: string): Promise<void>;
993
1016
  /** Create an unsaved log group. Call `.save()` to persist. */
994
- newGroup(key: string, options?: {
1017
+ newGroup(id: string, options?: {
995
1018
  name?: string;
996
1019
  group?: string;
997
1020
  }): LogGroup;
998
- /** Fetch a log group by key. */
999
- getGroup(key: string): Promise<LogGroup>;
1021
+ /** Fetch a log group by id. */
1022
+ getGroup(id: string): Promise<LogGroup>;
1000
1023
  /** List all log groups. */
1001
1024
  listGroups(): Promise<LogGroup[]>;
1002
- /** Delete a log group by key. */
1003
- deleteGroup(key: string): Promise<void>;
1025
+ /** Delete a log group by id. */
1026
+ deleteGroup(id: string): Promise<void>;
1004
1027
  /** @internal — POST or PUT a logger. */
1005
1028
  _saveLogger(logger: Logger): Promise<Logger>;
1006
1029
  /** @internal — POST or PUT a log group. */
@@ -1017,9 +1040,9 @@ declare class LoggingClient {
1017
1040
  * Register a change listener.
1018
1041
  *
1019
1042
  * - `onChange(callback)` — fires for any logger change.
1020
- * - `onChange(key, callback)` — fires only for the specified logger key.
1043
+ * - `onChange(id, callback)` — fires only for the specified logger id.
1021
1044
  */
1022
- onChange(callbackOrKey: string | ((event: LoggerChangeEvent) => void), callback?: (event: LoggerChangeEvent) => void): void;
1045
+ onChange(callbackOrId: string | ((event: LoggerChangeEvent) => void), callback?: (event: LoggerChangeEvent) => void): void;
1023
1046
  /** @internal */
1024
1047
  _close(): void;
1025
1048
  /** Auto-load built-in adapters by attempting to require each framework. */
@@ -1064,6 +1087,12 @@ interface SmplClientOptions {
1064
1087
  * @default 30000
1065
1088
  */
1066
1089
  timeout?: number;
1090
+ /**
1091
+ * Disable SDK telemetry reporting.
1092
+ * When `true`, no usage metrics are collected or sent.
1093
+ * @default false
1094
+ */
1095
+ disableTelemetry?: boolean;
1067
1096
  }
1068
1097
  /**
1069
1098
  * Entry point for the smplkit TypeScript SDK.
@@ -1100,6 +1129,8 @@ declare class SmplClient {
1100
1129
  readonly _environment: string;
1101
1130
  /** @internal */
1102
1131
  readonly _service: string;
1132
+ /** @internal */
1133
+ readonly _metrics: MetricsReporter | null;
1103
1134
  private readonly _timeout;
1104
1135
  private readonly _appHttp;
1105
1136
  constructor(options?: SmplClientOptions);