@smplkit/sdk 1.3.12 → 1.3.13
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 +1204 -613
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +728 -407
- package/dist/index.d.ts +728 -407
- package/dist/index.js +1195 -607
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -46,36 +46,19 @@ declare class SharedWebSocket {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Config resource —
|
|
50
|
-
*
|
|
51
|
-
* Instances are returned by {@link ConfigClient} methods and provide
|
|
52
|
-
* management-plane operations (`update`, `setValues`, `setValue`).
|
|
53
|
-
* Prescriptive value access is via `client.config.getValue()` after
|
|
54
|
-
* `client.connect()`.
|
|
55
|
-
*/
|
|
56
|
-
/**
|
|
57
|
-
* Internal type used by {@link ConfigClient}. Not part of the public API.
|
|
58
|
-
* @internal
|
|
49
|
+
* Config resource — active-record model with save() pattern.
|
|
59
50
|
*/
|
|
60
|
-
|
|
61
|
-
configId: string;
|
|
62
|
-
name: string;
|
|
63
|
-
key: string | null;
|
|
64
|
-
description: string | null;
|
|
65
|
-
parent: string | null;
|
|
66
|
-
items: Record<string, unknown>;
|
|
67
|
-
environments: Record<string, unknown>;
|
|
68
|
-
}
|
|
51
|
+
|
|
69
52
|
/**
|
|
70
|
-
* A configuration resource
|
|
53
|
+
* A configuration resource managed by the smplkit platform.
|
|
71
54
|
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
55
|
+
* Management: mutate properties directly and call `save()` to persist.
|
|
56
|
+
* POST if `id` is null (new), PUT if `id` is set (update).
|
|
74
57
|
*/
|
|
75
58
|
declare class Config {
|
|
76
|
-
/** UUID of the config. */
|
|
77
|
-
id: string;
|
|
78
|
-
/** Human-readable key (e.g. `"
|
|
59
|
+
/** UUID of the config, or `null` if unsaved. */
|
|
60
|
+
id: string | null;
|
|
61
|
+
/** Human-readable key (e.g. `"user-service"`). */
|
|
79
62
|
key: string;
|
|
80
63
|
/** Display name. */
|
|
81
64
|
name: string;
|
|
@@ -92,102 +75,75 @@ declare class Config {
|
|
|
92
75
|
*/
|
|
93
76
|
environments: Record<string, unknown>;
|
|
94
77
|
/** When the config was created, or null if unavailable. */
|
|
95
|
-
createdAt:
|
|
78
|
+
createdAt: string | null;
|
|
96
79
|
/** When the config was last updated, or null if unavailable. */
|
|
97
|
-
updatedAt:
|
|
98
|
-
/**
|
|
99
|
-
* Internal reference to the parent client.
|
|
100
|
-
* @internal
|
|
101
|
-
*/
|
|
102
|
-
private readonly _client;
|
|
80
|
+
updatedAt: string | null;
|
|
103
81
|
/** @internal */
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}): Promise<Config>;
|
|
109
|
-
readonly _apiKey: string;
|
|
110
|
-
readonly _baseUrl: string;
|
|
111
|
-
_getSharedWs?: () => SharedWebSocket;
|
|
112
|
-
}, fields: {
|
|
113
|
-
id: string;
|
|
82
|
+
readonly _client: ConfigClient;
|
|
83
|
+
/** @internal */
|
|
84
|
+
constructor(client: ConfigClient, fields: {
|
|
85
|
+
id: string | null;
|
|
114
86
|
key: string;
|
|
115
87
|
name: string;
|
|
116
88
|
description: string | null;
|
|
117
89
|
parent: string | null;
|
|
118
90
|
items: Record<string, unknown>;
|
|
119
91
|
environments: Record<string, unknown>;
|
|
120
|
-
createdAt:
|
|
121
|
-
updatedAt:
|
|
92
|
+
createdAt: string | null;
|
|
93
|
+
updatedAt: string | null;
|
|
122
94
|
});
|
|
123
95
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* Builds the request from current attribute values, overriding with any
|
|
127
|
-
* provided options. Updates local attributes in place on success.
|
|
128
|
-
*
|
|
129
|
-
* @param options.name - New display name.
|
|
130
|
-
* @param options.description - New description (pass empty string to clear).
|
|
131
|
-
* @param options.items - New base values (replaces entirely).
|
|
132
|
-
* @param options.environments - New environments dict (replaces entirely).
|
|
133
|
-
*/
|
|
134
|
-
update(options: {
|
|
135
|
-
name?: string;
|
|
136
|
-
description?: string;
|
|
137
|
-
items?: Record<string, unknown>;
|
|
138
|
-
environments?: Record<string, unknown>;
|
|
139
|
-
}): Promise<void>;
|
|
140
|
-
/**
|
|
141
|
-
* Replace base or environment-specific values.
|
|
142
|
-
*
|
|
143
|
-
* When `environment` is provided, replaces that environment's `values`
|
|
144
|
-
* sub-dict (other environments are preserved). When omitted, replaces
|
|
145
|
-
* the base `items`.
|
|
146
|
-
*
|
|
147
|
-
* @param values - The complete set of values to set.
|
|
148
|
-
* @param environment - Target environment, or omit for base values.
|
|
149
|
-
*/
|
|
150
|
-
setValues(values: Record<string, unknown>, environment?: string): Promise<void>;
|
|
151
|
-
/**
|
|
152
|
-
* Set a single key within base or environment-specific values.
|
|
153
|
-
*
|
|
154
|
-
* Merges the key into existing values rather than replacing all values.
|
|
96
|
+
* Persist this config to the server.
|
|
155
97
|
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* @param environment - Target environment, or omit for base values.
|
|
98
|
+
* POST if `id` is null (new config), PUT if `id` is set (update).
|
|
99
|
+
* Updates this instance in-place with the server response.
|
|
159
100
|
*/
|
|
160
|
-
|
|
101
|
+
save(): Promise<void>;
|
|
161
102
|
/**
|
|
162
103
|
* Walk the parent chain and return config data objects, child-to-root.
|
|
163
104
|
* @internal
|
|
164
105
|
*/
|
|
165
|
-
_buildChain(
|
|
106
|
+
_buildChain(): Promise<Array<{
|
|
166
107
|
id: string;
|
|
167
108
|
items: Record<string, unknown>;
|
|
168
109
|
environments: Record<string, unknown>;
|
|
169
110
|
}>>;
|
|
111
|
+
/** @internal — copy all fields from another Config instance. */
|
|
112
|
+
_apply(other: Config): void;
|
|
170
113
|
toString(): string;
|
|
171
114
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* LiveConfigProxy — ES6 Proxy-based live configuration access.
|
|
118
|
+
*
|
|
119
|
+
* Property reads are delegated to the latest resolved values in the
|
|
120
|
+
* ConfigClient cache. When the cache updates via WebSocket, subsequent
|
|
121
|
+
* reads automatically reflect the new values.
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A live proxy that auto-updates when the underlying config changes.
|
|
126
|
+
*
|
|
127
|
+
* Access properties directly — each read re-resolves from the cache.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const proxy = await client.config.subscribe("user-service");
|
|
132
|
+
* console.log(proxy.timeout); // reads from live cache
|
|
133
|
+
* // ... later, after a WebSocket update ...
|
|
134
|
+
* console.log(proxy.timeout); // reads the updated value
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare class LiveConfigProxy<T = Record<string, unknown>> {
|
|
138
|
+
/** @internal */
|
|
139
|
+
private readonly _client;
|
|
140
|
+
/** @internal */
|
|
141
|
+
private readonly _key;
|
|
142
|
+
/** @internal */
|
|
143
|
+
private readonly _model?;
|
|
144
|
+
constructor(client: ConfigClient, key: string, model?: new (data: any) => T);
|
|
145
|
+
/** @internal */
|
|
146
|
+
_currentValues(): Record<string, unknown>;
|
|
191
147
|
}
|
|
192
148
|
|
|
193
149
|
/** Describes a single config value change detected on refresh. */
|
|
@@ -204,15 +160,12 @@ interface ConfigChangeEvent {
|
|
|
204
160
|
source: "websocket" | "manual";
|
|
205
161
|
}
|
|
206
162
|
/**
|
|
207
|
-
* Client for the smplkit Config API
|
|
208
|
-
*
|
|
209
|
-
* All methods are async and return `Promise<T>`. Network and server
|
|
210
|
-
* errors are mapped to typed SDK exceptions.
|
|
163
|
+
* Client for the smplkit Config API — management plane + runtime.
|
|
211
164
|
*
|
|
212
165
|
* Obtained via `SmplClient.config`.
|
|
213
166
|
*/
|
|
214
167
|
declare class ConfigClient {
|
|
215
|
-
/** @internal
|
|
168
|
+
/** @internal */
|
|
216
169
|
readonly _apiKey: string;
|
|
217
170
|
/** @internal */
|
|
218
171
|
readonly _baseUrl: string;
|
|
@@ -226,205 +179,288 @@ declare class ConfigClient {
|
|
|
226
179
|
readonly _service: string | null;
|
|
227
180
|
} | null;
|
|
228
181
|
private _configCache;
|
|
229
|
-
|
|
182
|
+
_configStore: Config[];
|
|
183
|
+
private _initialized;
|
|
230
184
|
private _listeners;
|
|
231
185
|
/** @internal */
|
|
232
186
|
constructor(apiKey: string, timeout?: number);
|
|
233
|
-
/**
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
get(
|
|
241
|
-
/**
|
|
242
|
-
* List all configs for the account.
|
|
243
|
-
*/
|
|
187
|
+
/** Create an unsaved config. Call `.save()` to persist. */
|
|
188
|
+
new(key: string, options?: {
|
|
189
|
+
name?: string;
|
|
190
|
+
description?: string;
|
|
191
|
+
parent?: string;
|
|
192
|
+
}): Config;
|
|
193
|
+
/** Fetch a config by key. */
|
|
194
|
+
get(key: string): Promise<Config>;
|
|
195
|
+
/** List all configs. */
|
|
244
196
|
list(): Promise<Config[]>;
|
|
197
|
+
/** Delete a config by key. */
|
|
198
|
+
delete(key: string): Promise<void>;
|
|
199
|
+
/** @internal — POST a new config. */
|
|
200
|
+
_createConfig(config: Config): Promise<Config>;
|
|
201
|
+
/** @internal — PUT a config update. */
|
|
202
|
+
_updateConfig(config: Config): Promise<Config>;
|
|
203
|
+
/** @internal — fetch a config by UUID. */
|
|
204
|
+
_getById(configId: string): Promise<Config>;
|
|
245
205
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* @throws {SmplValidationError} If the server rejects the request.
|
|
249
|
-
*/
|
|
250
|
-
create(options: CreateConfigOptions): Promise<Config>;
|
|
251
|
-
/**
|
|
252
|
-
* Delete a config by UUID.
|
|
253
|
-
*
|
|
254
|
-
* @throws {SmplNotFoundError} If the config does not exist.
|
|
255
|
-
* @throws {SmplConflictError} If the config has child configs.
|
|
256
|
-
*/
|
|
257
|
-
delete(configId: string): Promise<void>;
|
|
258
|
-
/**
|
|
259
|
-
* Fetch all configs, resolve values for the environment, and cache.
|
|
260
|
-
* @internal — called by SmplClient.connect().
|
|
261
|
-
*/
|
|
262
|
-
_connectInternal(environment: string): Promise<void>;
|
|
263
|
-
/**
|
|
264
|
-
* Read a resolved config value (prescriptive access).
|
|
265
|
-
*
|
|
266
|
-
* Requires {@link SmplClient.connect} to have been called.
|
|
267
|
-
*
|
|
268
|
-
* @param configKey - The config key to look up.
|
|
269
|
-
* @param itemKey - Optional specific item key. If omitted, returns all values.
|
|
270
|
-
* @param defaultValue - Default value if the key is missing.
|
|
206
|
+
* Resolve a config's values for the current environment.
|
|
271
207
|
*
|
|
272
|
-
*
|
|
273
|
-
|
|
274
|
-
getValue(configKey: string, itemKey?: string, defaultValue?: unknown): unknown;
|
|
275
|
-
/**
|
|
276
|
-
* Return a config value as a string, or `defaultValue` if absent or not a string.
|
|
208
|
+
* Returns a flat dict of resolved key-value pairs, walking the
|
|
209
|
+
* parent chain and applying environment overrides.
|
|
277
210
|
*
|
|
278
|
-
*
|
|
211
|
+
* Optionally pass a model class to map the resolved values.
|
|
279
212
|
*/
|
|
280
|
-
|
|
213
|
+
resolve<T = Record<string, unknown>>(key: string, model?: new (data: any) => T): Promise<T>;
|
|
281
214
|
/**
|
|
282
|
-
*
|
|
215
|
+
* Subscribe to a config's values — returns a live proxy that
|
|
216
|
+
* auto-updates when the underlying config changes.
|
|
283
217
|
*
|
|
284
|
-
*
|
|
218
|
+
* Optionally pass a model class to map the resolved values.
|
|
285
219
|
*/
|
|
286
|
-
|
|
220
|
+
subscribe<T = Record<string, unknown>>(key: string, model?: new (data: any) => T): Promise<LiveConfigProxy<T>>;
|
|
287
221
|
/**
|
|
288
|
-
*
|
|
222
|
+
* Register a change listener.
|
|
289
223
|
*
|
|
290
|
-
*
|
|
224
|
+
* - `onChange(callback)` — fires for any config change (global).
|
|
225
|
+
* - `onChange(configKey, callback)` — fires for changes to a specific config.
|
|
226
|
+
* - `onChange(configKey, itemKey, callback)` — fires for a specific item.
|
|
291
227
|
*/
|
|
292
|
-
|
|
228
|
+
onChange(callbackOrConfigKey: string | ((event: ConfigChangeEvent) => void), callbackOrItemKey?: string | ((event: ConfigChangeEvent) => void), callback?: (event: ConfigChangeEvent) => void): void;
|
|
293
229
|
/**
|
|
294
230
|
* Re-fetch all configs, re-resolve values, and update the cache.
|
|
295
|
-
*
|
|
296
|
-
* Fires change listeners for any values that differ from the previous cache.
|
|
297
|
-
*
|
|
298
|
-
* @throws {SmplNotConnectedError} If connect() has not been called.
|
|
231
|
+
* Fires change listeners for any values that differ.
|
|
299
232
|
*/
|
|
300
233
|
refresh(): Promise<void>;
|
|
301
|
-
/**
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
onChange(callback: (event: ConfigChangeEvent) => void, options?: {
|
|
309
|
-
configKey?: string;
|
|
310
|
-
itemKey?: string;
|
|
311
|
-
}): void;
|
|
234
|
+
/** @internal */
|
|
235
|
+
private _ensureInitialized;
|
|
236
|
+
/** @internal — called by SmplClient for backward compat. */
|
|
237
|
+
_connectInternal(environment: string): Promise<void>;
|
|
238
|
+
/** @internal — get resolved config from cache. Used by LiveConfigProxy. */
|
|
239
|
+
_getCachedConfig(key: string): Record<string, unknown> | undefined;
|
|
240
|
+
private _handleConfigChanged;
|
|
312
241
|
/** @internal */
|
|
313
242
|
private _diffAndFire;
|
|
314
|
-
/**
|
|
315
|
-
* Internal: PUT a full config update and return the updated model.
|
|
316
|
-
*
|
|
317
|
-
* Called by {@link Config} instance methods.
|
|
318
|
-
* @internal
|
|
319
|
-
*/
|
|
320
|
-
_updateConfig(payload: ConfigUpdatePayload): Promise<Config>;
|
|
321
|
-
private _getById;
|
|
322
243
|
private _getByKey;
|
|
323
244
|
}
|
|
324
245
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
246
|
+
interface components {
|
|
247
|
+
schemas: {
|
|
248
|
+
/**
|
|
249
|
+
* Flag
|
|
250
|
+
* @example {
|
|
251
|
+
* "created_at": "2026-03-27T10:00:00Z",
|
|
252
|
+
* "default": false,
|
|
253
|
+
* "description": "Enable dark mode for the application UI",
|
|
254
|
+
* "environments": {
|
|
255
|
+
* "production": {
|
|
256
|
+
* "default": false,
|
|
257
|
+
* "enabled": true,
|
|
258
|
+
* "rules": [
|
|
259
|
+
* {
|
|
260
|
+
* "description": "Beta users get dark mode",
|
|
261
|
+
* "logic": {
|
|
262
|
+
* "attribute": "beta",
|
|
263
|
+
* "op": "eq",
|
|
264
|
+
* "value": true
|
|
265
|
+
* },
|
|
266
|
+
* "value": true
|
|
267
|
+
* }
|
|
268
|
+
* ]
|
|
269
|
+
* },
|
|
270
|
+
* "staging": {
|
|
271
|
+
* "default": true,
|
|
272
|
+
* "enabled": true,
|
|
273
|
+
* "rules": []
|
|
274
|
+
* }
|
|
275
|
+
* },
|
|
276
|
+
* "key": "dark_mode",
|
|
277
|
+
* "name": "Dark Mode",
|
|
278
|
+
* "type": "BOOLEAN",
|
|
279
|
+
* "updated_at": "2026-03-27T10:00:00Z",
|
|
280
|
+
* "values": [
|
|
281
|
+
* {
|
|
282
|
+
* "name": "on",
|
|
283
|
+
* "value": true
|
|
284
|
+
* },
|
|
285
|
+
* {
|
|
286
|
+
* "name": "off",
|
|
287
|
+
* "value": false
|
|
288
|
+
* }
|
|
289
|
+
* ]
|
|
290
|
+
* }
|
|
291
|
+
*/
|
|
292
|
+
Flag: {
|
|
293
|
+
/**
|
|
294
|
+
* Key
|
|
295
|
+
* @description Unique key within account
|
|
296
|
+
*/
|
|
297
|
+
key: string;
|
|
298
|
+
/**
|
|
299
|
+
* Name
|
|
300
|
+
* @description Human-readable display name
|
|
301
|
+
*/
|
|
369
302
|
name: string;
|
|
303
|
+
/**
|
|
304
|
+
* Description
|
|
305
|
+
* @default
|
|
306
|
+
*/
|
|
307
|
+
description: string;
|
|
308
|
+
/**
|
|
309
|
+
* Type
|
|
310
|
+
* @description Value type: STRING, BOOLEAN, NUMERIC, or JSON
|
|
311
|
+
*/
|
|
312
|
+
type: string;
|
|
313
|
+
/**
|
|
314
|
+
* Default
|
|
315
|
+
* @description Default value; must reference a value in the values array
|
|
316
|
+
*/
|
|
317
|
+
default: unknown;
|
|
318
|
+
/**
|
|
319
|
+
* Values
|
|
320
|
+
* @description Closed set of possible values
|
|
321
|
+
*/
|
|
322
|
+
values: components["schemas"]["FlagValue"][];
|
|
323
|
+
/** Environments */
|
|
324
|
+
environments?: {
|
|
325
|
+
[key: string]: components["schemas"]["FlagEnvironment"];
|
|
326
|
+
};
|
|
327
|
+
/** Created At */
|
|
328
|
+
readonly created_at?: string | null;
|
|
329
|
+
/** Updated At */
|
|
330
|
+
readonly updated_at?: string | null;
|
|
331
|
+
};
|
|
332
|
+
/** FlagEnvironment */
|
|
333
|
+
FlagEnvironment: {
|
|
334
|
+
/**
|
|
335
|
+
* Enabled
|
|
336
|
+
* @default false
|
|
337
|
+
*/
|
|
338
|
+
enabled: boolean;
|
|
339
|
+
/** Default */
|
|
340
|
+
default?: unknown | null;
|
|
341
|
+
/** Rules */
|
|
342
|
+
rules?: components["schemas"]["FlagRule"][];
|
|
343
|
+
};
|
|
344
|
+
/** FlagListResponse */
|
|
345
|
+
FlagListResponse: {
|
|
346
|
+
/** Data */
|
|
347
|
+
data: components["schemas"]["FlagResource"][];
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* FlagResource
|
|
351
|
+
* @example {
|
|
352
|
+
* "attributes": {
|
|
353
|
+
* "created_at": "2026-03-27T10:00:00Z",
|
|
354
|
+
* "default": false,
|
|
355
|
+
* "description": "Enable dark mode for the application UI",
|
|
356
|
+
* "environments": {
|
|
357
|
+
* "production": {
|
|
358
|
+
* "default": false,
|
|
359
|
+
* "enabled": true,
|
|
360
|
+
* "rules": [
|
|
361
|
+
* {
|
|
362
|
+
* "description": "Beta users get dark mode",
|
|
363
|
+
* "logic": {
|
|
364
|
+
* "attribute": "beta",
|
|
365
|
+
* "op": "eq",
|
|
366
|
+
* "value": true
|
|
367
|
+
* },
|
|
368
|
+
* "value": true
|
|
369
|
+
* }
|
|
370
|
+
* ]
|
|
371
|
+
* }
|
|
372
|
+
* },
|
|
373
|
+
* "key": "dark_mode",
|
|
374
|
+
* "name": "Dark Mode",
|
|
375
|
+
* "type": "BOOLEAN",
|
|
376
|
+
* "updated_at": "2026-03-27T10:00:00Z",
|
|
377
|
+
* "values": [
|
|
378
|
+
* {
|
|
379
|
+
* "name": "on",
|
|
380
|
+
* "value": true
|
|
381
|
+
* },
|
|
382
|
+
* {
|
|
383
|
+
* "name": "off",
|
|
384
|
+
* "value": false
|
|
385
|
+
* }
|
|
386
|
+
* ]
|
|
387
|
+
* },
|
|
388
|
+
* "id": "550e8400-e29b-41d4-a716-446655440000",
|
|
389
|
+
* "type": "flag"
|
|
390
|
+
* }
|
|
391
|
+
*/
|
|
392
|
+
FlagResource: {
|
|
393
|
+
/** Id */
|
|
394
|
+
id?: string | null;
|
|
395
|
+
/**
|
|
396
|
+
* Type
|
|
397
|
+
* @constant
|
|
398
|
+
*/
|
|
399
|
+
type: "flag";
|
|
400
|
+
attributes: components["schemas"]["Flag"];
|
|
401
|
+
};
|
|
402
|
+
/** FlagResponse */
|
|
403
|
+
FlagResponse: {
|
|
404
|
+
data: components["schemas"]["FlagResource"];
|
|
405
|
+
};
|
|
406
|
+
/** FlagRule */
|
|
407
|
+
FlagRule: {
|
|
408
|
+
/** Description */
|
|
409
|
+
description?: string | null;
|
|
410
|
+
/** Logic */
|
|
411
|
+
logic: {
|
|
412
|
+
[key: string]: unknown;
|
|
413
|
+
};
|
|
414
|
+
/** Value */
|
|
370
415
|
value: unknown;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
updatedAt: string | null;
|
|
376
|
-
});
|
|
377
|
-
/**
|
|
378
|
-
* Update this flag's attributes on the server.
|
|
379
|
-
*
|
|
380
|
-
* Only provided fields are changed; others retain their current values.
|
|
381
|
-
*/
|
|
382
|
-
update(options: {
|
|
383
|
-
environments?: Record<string, any>;
|
|
384
|
-
values?: Array<{
|
|
416
|
+
};
|
|
417
|
+
/** FlagValue */
|
|
418
|
+
FlagValue: {
|
|
419
|
+
/** Name */
|
|
385
420
|
name: string;
|
|
421
|
+
/** Value */
|
|
386
422
|
value: unknown;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
};
|
|
424
|
+
/** HTTPValidationError */
|
|
425
|
+
HTTPValidationError: {
|
|
426
|
+
/** Detail */
|
|
427
|
+
detail?: components["schemas"]["ValidationError"][];
|
|
428
|
+
};
|
|
429
|
+
/** Resource[Flag] */
|
|
430
|
+
Resource_Flag_: {
|
|
431
|
+
/** Id */
|
|
432
|
+
id?: string | null;
|
|
433
|
+
/**
|
|
434
|
+
* Type
|
|
435
|
+
* @default
|
|
436
|
+
*/
|
|
437
|
+
type: string;
|
|
438
|
+
attributes: components["schemas"]["Flag"];
|
|
439
|
+
};
|
|
440
|
+
/** Response[Flag] */
|
|
441
|
+
Response_Flag_: {
|
|
442
|
+
data: components["schemas"]["Resource_Flag_"];
|
|
443
|
+
};
|
|
444
|
+
/** ValidationError */
|
|
445
|
+
ValidationError: {
|
|
446
|
+
/** Location */
|
|
447
|
+
loc: (string | number)[];
|
|
448
|
+
/** Message */
|
|
449
|
+
msg: string;
|
|
450
|
+
/** Error Type */
|
|
451
|
+
type: string;
|
|
452
|
+
};
|
|
453
|
+
};
|
|
454
|
+
responses: never;
|
|
455
|
+
parameters: never;
|
|
456
|
+
requestBodies: never;
|
|
457
|
+
headers: never;
|
|
458
|
+
pathItems: never;
|
|
421
459
|
}
|
|
422
460
|
|
|
423
461
|
/**
|
|
424
|
-
* Public types for the Flags SDK:
|
|
462
|
+
* Public types for the Flags SDK: Context, Rule.
|
|
425
463
|
*/
|
|
426
|
-
/** The value type of a flag. */
|
|
427
|
-
type FlagType = "BOOLEAN" | "STRING" | "NUMERIC" | "JSON";
|
|
428
464
|
/**
|
|
429
465
|
* A typed evaluation context entity.
|
|
430
466
|
*
|
|
@@ -480,65 +516,141 @@ declare class Rule {
|
|
|
480
516
|
}
|
|
481
517
|
|
|
482
518
|
/**
|
|
483
|
-
*
|
|
519
|
+
* Unified Flag hierarchy — management model + runtime handle.
|
|
484
520
|
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
* (`src/generated/app.d.ts`) via a separate `openapi-fetch` client.
|
|
521
|
+
* A single {@link Flag} class replaces the old separate Flag + FlagHandle
|
|
522
|
+
* classes. Typed subclasses ({@link BooleanFlag}, {@link StringFlag},
|
|
523
|
+
* {@link NumberFlag}, {@link JsonFlag}) override `get()` for type safety.
|
|
489
524
|
*/
|
|
490
525
|
|
|
491
|
-
/**
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
|
|
508
|
-
/**
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
526
|
+
/**
|
|
527
|
+
* A flag resource that doubles as a runtime handle.
|
|
528
|
+
*
|
|
529
|
+
* Management: call `save()` to persist (POST if new, PUT if existing).
|
|
530
|
+
* Runtime: call `get()` for local JSON Logic evaluation.
|
|
531
|
+
*/
|
|
532
|
+
declare class Flag {
|
|
533
|
+
/** UUID of the flag, or `null` if unsaved. */
|
|
534
|
+
id: string | null;
|
|
535
|
+
/** Unique key within the account. */
|
|
536
|
+
key: string;
|
|
537
|
+
/** Human-readable display name. */
|
|
538
|
+
name: string;
|
|
539
|
+
/** Value type: BOOLEAN, STRING, NUMERIC, or JSON. */
|
|
540
|
+
type: string;
|
|
541
|
+
/** Flag-level default value. */
|
|
542
|
+
default: unknown;
|
|
543
|
+
/** Closed set of possible values. */
|
|
544
|
+
values: Array<{
|
|
545
|
+
name: string;
|
|
546
|
+
value: unknown;
|
|
547
|
+
}>;
|
|
548
|
+
/** Optional description. */
|
|
549
|
+
description: string | null;
|
|
550
|
+
/** Per-environment configuration. */
|
|
551
|
+
environments: Record<string, any>;
|
|
552
|
+
/** When the flag was created. */
|
|
553
|
+
createdAt: string | null;
|
|
554
|
+
/** When the flag was last updated. */
|
|
555
|
+
updatedAt: string | null;
|
|
556
|
+
/** @internal */
|
|
557
|
+
readonly _client: FlagsClient;
|
|
558
|
+
/** @internal */
|
|
559
|
+
constructor(client: FlagsClient, fields: {
|
|
560
|
+
id: string | null;
|
|
561
|
+
key: string;
|
|
562
|
+
name: string;
|
|
563
|
+
type: string;
|
|
564
|
+
default: unknown;
|
|
565
|
+
values: Array<{
|
|
566
|
+
name: string;
|
|
567
|
+
value: unknown;
|
|
568
|
+
}>;
|
|
569
|
+
description: string | null;
|
|
570
|
+
environments: Record<string, any>;
|
|
571
|
+
createdAt: string | null;
|
|
572
|
+
updatedAt: string | null;
|
|
573
|
+
});
|
|
574
|
+
/**
|
|
575
|
+
* Persist this flag to the server.
|
|
576
|
+
*
|
|
577
|
+
* POST if `id` is null (new flag), PUT if `id` is set (update).
|
|
578
|
+
* Updates this instance in-place with the server response.
|
|
579
|
+
*/
|
|
580
|
+
save(): Promise<void>;
|
|
581
|
+
/**
|
|
582
|
+
* Add a rule to a specific environment (sync local mutation).
|
|
583
|
+
*
|
|
584
|
+
* The built rule must include an `environment` key (set via
|
|
585
|
+
* `Rule(...).environment("env_key")`). No HTTP call is made.
|
|
586
|
+
*
|
|
587
|
+
* @returns `this` for chaining.
|
|
588
|
+
*/
|
|
589
|
+
addRule(builtRule: Record<string, any>): Flag;
|
|
590
|
+
/** Enable or disable a flag in a specific environment (sync local mutation). */
|
|
591
|
+
setEnvironmentEnabled(envKey: string, enabled: boolean): void;
|
|
592
|
+
/** Set the default value for a specific environment (sync local mutation). */
|
|
593
|
+
setEnvironmentDefault(envKey: string, defaultValue: unknown): void;
|
|
594
|
+
/** Clear all rules for a specific environment (sync local mutation). */
|
|
595
|
+
clearRules(envKey: string): void;
|
|
596
|
+
/**
|
|
597
|
+
* Evaluate the flag locally (sync, no HTTP).
|
|
598
|
+
*
|
|
599
|
+
* Requires `initialize()` to have been called.
|
|
600
|
+
*/
|
|
512
601
|
get(options?: {
|
|
513
602
|
context?: Context[];
|
|
514
|
-
}):
|
|
515
|
-
/**
|
|
516
|
-
|
|
603
|
+
}): unknown;
|
|
604
|
+
/** @internal — copy all fields from another Flag instance. */
|
|
605
|
+
_apply(other: Flag): void;
|
|
606
|
+
toString(): string;
|
|
517
607
|
}
|
|
518
|
-
/** Typed
|
|
519
|
-
declare class
|
|
608
|
+
/** Typed flag that returns `boolean` from `get()`. */
|
|
609
|
+
declare class BooleanFlag extends Flag {
|
|
520
610
|
get(options?: {
|
|
521
611
|
context?: Context[];
|
|
522
612
|
}): boolean;
|
|
523
613
|
}
|
|
524
|
-
/** Typed
|
|
525
|
-
declare class
|
|
614
|
+
/** Typed flag that returns `string` from `get()`. */
|
|
615
|
+
declare class StringFlag extends Flag {
|
|
526
616
|
get(options?: {
|
|
527
617
|
context?: Context[];
|
|
528
618
|
}): string;
|
|
529
619
|
}
|
|
530
|
-
/** Typed
|
|
531
|
-
declare class
|
|
620
|
+
/** Typed flag that returns `number` from `get()`. */
|
|
621
|
+
declare class NumberFlag extends Flag {
|
|
532
622
|
get(options?: {
|
|
533
623
|
context?: Context[];
|
|
534
624
|
}): number;
|
|
535
625
|
}
|
|
536
|
-
/** Typed
|
|
537
|
-
declare class
|
|
626
|
+
/** Typed flag that returns `Record<string, any>` from `get()`. */
|
|
627
|
+
declare class JsonFlag extends Flag {
|
|
538
628
|
get(options?: {
|
|
539
629
|
context?: Context[];
|
|
540
630
|
}): Record<string, any>;
|
|
541
631
|
}
|
|
632
|
+
|
|
633
|
+
/**
|
|
634
|
+
* FlagsClient — management + prescriptive runtime for Smpl Flags.
|
|
635
|
+
*
|
|
636
|
+
* Uses the generated OpenAPI types (`src/generated/flags.d.ts`) via
|
|
637
|
+
* `openapi-fetch` for all flag HTTP calls. Context registration uses
|
|
638
|
+
* the generated app service types (`src/generated/app.d.ts`).
|
|
639
|
+
*/
|
|
640
|
+
|
|
641
|
+
type FlagResource = components["schemas"]["FlagResource"];
|
|
642
|
+
/** Describes a flag definition change. */
|
|
643
|
+
declare class FlagChangeEvent {
|
|
644
|
+
readonly key: string;
|
|
645
|
+
readonly source: string;
|
|
646
|
+
constructor(key: string, source: string);
|
|
647
|
+
}
|
|
648
|
+
/** Cache statistics for the flags runtime. */
|
|
649
|
+
declare class FlagStats {
|
|
650
|
+
readonly cacheHits: number;
|
|
651
|
+
readonly cacheMisses: number;
|
|
652
|
+
constructor(cacheHits: number, cacheMisses: number);
|
|
653
|
+
}
|
|
542
654
|
/**
|
|
543
655
|
* Client for the smplkit Flags API — management plane + prescriptive runtime.
|
|
544
656
|
*
|
|
@@ -555,12 +667,13 @@ declare class FlagsClient {
|
|
|
555
667
|
private readonly _appHttp;
|
|
556
668
|
private _environment;
|
|
557
669
|
private _flagStore;
|
|
558
|
-
private
|
|
670
|
+
private _initialized;
|
|
559
671
|
private _cache;
|
|
560
672
|
private _contextProvider;
|
|
561
673
|
private _contextBuffer;
|
|
562
674
|
private _handles;
|
|
563
675
|
private _globalListeners;
|
|
676
|
+
private _keyListeners;
|
|
564
677
|
private _wsManager;
|
|
565
678
|
private readonly _ensureWs;
|
|
566
679
|
/** @internal — set by SmplClient after construction. */
|
|
@@ -570,92 +683,77 @@ declare class FlagsClient {
|
|
|
570
683
|
} | null;
|
|
571
684
|
/** @internal */
|
|
572
685
|
constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
|
|
573
|
-
/** Create
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
686
|
+
/** Create an unsaved boolean flag. Call `.save()` to persist. */
|
|
687
|
+
newBooleanFlag(key: string, options: {
|
|
688
|
+
default: boolean;
|
|
689
|
+
name?: string;
|
|
690
|
+
description?: string;
|
|
691
|
+
}): BooleanFlag;
|
|
692
|
+
/** Create an unsaved string flag. Call `.save()` to persist. */
|
|
693
|
+
newStringFlag(key: string, options: {
|
|
694
|
+
default: string;
|
|
695
|
+
name?: string;
|
|
578
696
|
description?: string;
|
|
579
697
|
values?: Array<{
|
|
580
698
|
name: string;
|
|
581
699
|
value: unknown;
|
|
582
700
|
}>;
|
|
583
|
-
}):
|
|
584
|
-
/**
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
delete(flagId: string): Promise<void>;
|
|
590
|
-
/**
|
|
591
|
-
* Internal: PUT a full flag update.
|
|
592
|
-
* Called by {@link Flag} instance methods.
|
|
593
|
-
* @internal
|
|
594
|
-
*/
|
|
595
|
-
_updateFlag(options: {
|
|
596
|
-
flag: Flag;
|
|
597
|
-
environments?: Record<string, any>;
|
|
701
|
+
}): StringFlag;
|
|
702
|
+
/** Create an unsaved number flag. Call `.save()` to persist. */
|
|
703
|
+
newNumberFlag(key: string, options: {
|
|
704
|
+
default: number;
|
|
705
|
+
name?: string;
|
|
706
|
+
description?: string;
|
|
598
707
|
values?: Array<{
|
|
599
708
|
name: string;
|
|
600
709
|
value: unknown;
|
|
601
710
|
}>;
|
|
602
|
-
|
|
603
|
-
|
|
711
|
+
}): NumberFlag;
|
|
712
|
+
/** Create an unsaved JSON flag. Call `.save()` to persist. */
|
|
713
|
+
newJsonFlag(key: string, options: {
|
|
714
|
+
default: Record<string, any>;
|
|
604
715
|
name?: string;
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
numberFlag(key: string, defaultValue: number): NumberFlagHandle;
|
|
630
|
-
/** Declare a JSON flag handle. */
|
|
631
|
-
jsonFlag(key: string, defaultValue: Record<string, any>): JsonFlagHandle;
|
|
716
|
+
description?: string;
|
|
717
|
+
values?: Array<{
|
|
718
|
+
name: string;
|
|
719
|
+
value: unknown;
|
|
720
|
+
}>;
|
|
721
|
+
}): JsonFlag;
|
|
722
|
+
/** Fetch a flag by key. */
|
|
723
|
+
get(key: string): Promise<Flag>;
|
|
724
|
+
/** List all flags. */
|
|
725
|
+
list(): Promise<Flag[]>;
|
|
726
|
+
/** Delete a flag by key. */
|
|
727
|
+
delete(key: string): Promise<void>;
|
|
728
|
+
/** @internal — POST a new flag. */
|
|
729
|
+
_createFlag(flag: Flag): Promise<Flag>;
|
|
730
|
+
/** @internal — PUT a flag update. */
|
|
731
|
+
_updateFlag(flag: Flag): Promise<Flag>;
|
|
732
|
+
/** Declare a boolean flag handle for runtime evaluation. */
|
|
733
|
+
booleanFlag(key: string, defaultValue: boolean): BooleanFlag;
|
|
734
|
+
/** Declare a string flag handle for runtime evaluation. */
|
|
735
|
+
stringFlag(key: string, defaultValue: string): StringFlag;
|
|
736
|
+
/** Declare a numeric flag handle for runtime evaluation. */
|
|
737
|
+
numberFlag(key: string, defaultValue: number): NumberFlag;
|
|
738
|
+
/** Declare a JSON flag handle for runtime evaluation. */
|
|
739
|
+
jsonFlag(key: string, defaultValue: Record<string, any>): JsonFlag;
|
|
632
740
|
/**
|
|
633
741
|
* Register a context provider function.
|
|
634
742
|
*
|
|
635
|
-
* Called on every `handle.get()` to supply the current evaluation
|
|
636
|
-
* context. Can also be used as a decorator:
|
|
637
|
-
*
|
|
638
|
-
* ```typescript
|
|
639
|
-
* client.flags.setContextProvider(() => [
|
|
640
|
-
* new Context("user", userId, { plan: userPlan }),
|
|
641
|
-
* ]);
|
|
642
|
-
* ```
|
|
743
|
+
* Called on every `handle.get()` to supply the current evaluation context.
|
|
643
744
|
*/
|
|
644
745
|
setContextProvider(fn: () => Context[]): void;
|
|
645
746
|
/**
|
|
646
747
|
* Register a context provider — decorator-style alias.
|
|
647
|
-
*
|
|
648
|
-
* ```typescript
|
|
649
|
-
* const provider = client.flags.contextProvider(() => [...]);
|
|
650
|
-
* ```
|
|
651
748
|
*/
|
|
652
749
|
contextProvider(fn: () => Context[]): () => Context[];
|
|
653
750
|
/**
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
751
|
+
* Initialize the flags runtime: fetch definitions and wire WebSocket.
|
|
752
|
+
*
|
|
753
|
+
* Idempotent — safe to call multiple times. Must be called (and awaited)
|
|
754
|
+
* before using `.get()` on flag handles.
|
|
657
755
|
*/
|
|
658
|
-
|
|
756
|
+
initialize(): Promise<void>;
|
|
659
757
|
/** Disconnect: unregister from WebSocket, flush contexts, clear state. */
|
|
660
758
|
disconnect(): Promise<void>;
|
|
661
759
|
/** Re-fetch all flag definitions and clear cache. */
|
|
@@ -664,29 +762,24 @@ declare class FlagsClient {
|
|
|
664
762
|
connectionStatus(): string;
|
|
665
763
|
/** Return cache statistics. */
|
|
666
764
|
stats(): FlagStats;
|
|
667
|
-
/** Register a global change listener that fires for any flag change. */
|
|
668
|
-
onChangeAny(callback: (event: FlagChangeEvent) => void): (event: FlagChangeEvent) => void;
|
|
669
765
|
/**
|
|
670
|
-
* Register a
|
|
766
|
+
* Register a change listener.
|
|
671
767
|
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
* ```
|
|
768
|
+
* - `onChange(callback)` — fires for any flag change (global).
|
|
769
|
+
* - `onChange(key, callback)` — fires only for the specified flag key.
|
|
675
770
|
*/
|
|
676
|
-
onChange(
|
|
771
|
+
onChange(callbackOrKey: string | ((event: FlagChangeEvent) => void), callback?: (event: FlagChangeEvent) => void): void;
|
|
677
772
|
/**
|
|
678
773
|
* Explicitly register context(s) for background batch registration.
|
|
679
774
|
*
|
|
680
775
|
* Accepts a single Context or an array. Fire-and-forget — never
|
|
681
|
-
* blocks. Works before `
|
|
776
|
+
* blocks. Works before `initialize()` is called.
|
|
682
777
|
*/
|
|
683
778
|
register(context: Context | Context[]): void;
|
|
684
779
|
/** Flush pending context registrations to the server. */
|
|
685
780
|
flushContexts(): Promise<void>;
|
|
686
781
|
/**
|
|
687
782
|
* Tier 1 explicit evaluation — stateless, no provider or cache.
|
|
688
|
-
*
|
|
689
|
-
* Useful for scripts, one-off jobs, and infrastructure code.
|
|
690
783
|
*/
|
|
691
784
|
evaluate(key: string, options: {
|
|
692
785
|
environment: string;
|
|
@@ -694,6 +787,8 @@ declare class FlagsClient {
|
|
|
694
787
|
}): Promise<any>;
|
|
695
788
|
/** @internal */
|
|
696
789
|
_evaluateHandle(key: string, defaultValue: any, context: Context[] | null): any;
|
|
790
|
+
/** @internal — called by SmplClient constructor / lazy init. */
|
|
791
|
+
_connectInternal(environment: string): Promise<void>;
|
|
697
792
|
private _handleFlagChanged;
|
|
698
793
|
private _handleFlagDeleted;
|
|
699
794
|
private _fetchAllFlags;
|
|
@@ -701,16 +796,243 @@ declare class FlagsClient {
|
|
|
701
796
|
private _fireChangeListeners;
|
|
702
797
|
private _fireChangeListenersAll;
|
|
703
798
|
private _flushContexts;
|
|
704
|
-
|
|
799
|
+
/** @internal */
|
|
800
|
+
_resourceToModel(resource: FlagResource): Flag;
|
|
705
801
|
private _resourceToPlainDict;
|
|
706
|
-
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Public types for the Logging SDK.
|
|
806
|
+
*/
|
|
807
|
+
/** Log level values matching the smplkit platform. */
|
|
808
|
+
declare enum LogLevel {
|
|
809
|
+
TRACE = "TRACE",
|
|
810
|
+
DEBUG = "DEBUG",
|
|
811
|
+
INFO = "INFO",
|
|
812
|
+
WARN = "WARN",
|
|
813
|
+
ERROR = "ERROR",
|
|
814
|
+
FATAL = "FATAL",
|
|
815
|
+
SILENT = "SILENT"
|
|
816
|
+
}
|
|
817
|
+
/** Describes a logger configuration change. */
|
|
818
|
+
interface LoggerChangeEvent {
|
|
819
|
+
/** The logger key that changed. */
|
|
820
|
+
key: string;
|
|
821
|
+
/** The new effective log level, or null if removed. */
|
|
822
|
+
level: LogLevel | null;
|
|
823
|
+
/** How the change was delivered. */
|
|
824
|
+
source: string;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Logger and LogGroup active-record models for the Logging SDK.
|
|
829
|
+
*/
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* A logger resource managed by the smplkit platform.
|
|
833
|
+
*
|
|
834
|
+
* Management: mutate properties and call `save()` to persist.
|
|
835
|
+
* Convenience methods (`setLevel`, `setEnvironmentLevel`, etc.) are
|
|
836
|
+
* sync local mutations — no HTTP until `save()`.
|
|
837
|
+
*/
|
|
838
|
+
declare class Logger {
|
|
839
|
+
/** UUID of the logger, or `null` if unsaved. */
|
|
840
|
+
id: string | null;
|
|
841
|
+
/** Unique key (dot-separated hierarchy). */
|
|
842
|
+
key: string;
|
|
843
|
+
/** Human-readable display name. */
|
|
844
|
+
name: string;
|
|
845
|
+
/** Base log level, or null if inherited. */
|
|
846
|
+
level: string | null;
|
|
847
|
+
/** UUID of the parent log group, or null. */
|
|
848
|
+
group: string | null;
|
|
849
|
+
/** Whether this logger is managed by the platform. */
|
|
850
|
+
managed: boolean;
|
|
851
|
+
/** Observed sources (services that report this logger). */
|
|
852
|
+
sources: Array<Record<string, any>>;
|
|
853
|
+
/** Per-environment level overrides. */
|
|
854
|
+
environments: Record<string, any>;
|
|
855
|
+
/** When the logger was created. */
|
|
856
|
+
createdAt: string | null;
|
|
857
|
+
/** When the logger was last updated. */
|
|
858
|
+
updatedAt: string | null;
|
|
859
|
+
/** @internal */
|
|
860
|
+
readonly _client: LoggingClient;
|
|
861
|
+
/** @internal */
|
|
862
|
+
constructor(client: LoggingClient, fields: {
|
|
863
|
+
id: string | null;
|
|
864
|
+
key: string;
|
|
865
|
+
name: string;
|
|
866
|
+
level: string | null;
|
|
867
|
+
group: string | null;
|
|
868
|
+
managed: boolean;
|
|
869
|
+
sources: Array<Record<string, any>>;
|
|
870
|
+
environments: Record<string, any>;
|
|
871
|
+
createdAt: string | null;
|
|
872
|
+
updatedAt: string | null;
|
|
873
|
+
});
|
|
874
|
+
/**
|
|
875
|
+
* Persist this logger to the server.
|
|
876
|
+
*
|
|
877
|
+
* POST if `id` is null (new), PUT if `id` is set (update).
|
|
878
|
+
*/
|
|
879
|
+
save(): Promise<void>;
|
|
880
|
+
/** Set the base log level (sync local mutation). */
|
|
881
|
+
setLevel(level: LogLevel): void;
|
|
882
|
+
/** Clear the base log level (sync local mutation). */
|
|
883
|
+
clearLevel(): void;
|
|
884
|
+
/** Set an environment-specific log level (sync local mutation). */
|
|
885
|
+
setEnvironmentLevel(env: string, level: LogLevel): void;
|
|
886
|
+
/** Clear an environment-specific log level (sync local mutation). */
|
|
887
|
+
clearEnvironmentLevel(env: string): void;
|
|
888
|
+
/** Clear all environment-specific log levels (sync local mutation). */
|
|
889
|
+
clearAllEnvironmentLevels(): void;
|
|
890
|
+
/** @internal — copy all fields from another Logger instance. */
|
|
891
|
+
_apply(other: Logger): void;
|
|
892
|
+
toString(): string;
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* A log group resource for organizing loggers.
|
|
896
|
+
*
|
|
897
|
+
* Management: mutate properties and call `save()` to persist.
|
|
898
|
+
*/
|
|
899
|
+
declare class LogGroup {
|
|
900
|
+
/** UUID of the log group, or `null` if unsaved. */
|
|
901
|
+
id: string | null;
|
|
902
|
+
/** Unique key. */
|
|
903
|
+
key: string;
|
|
904
|
+
/** Human-readable display name. */
|
|
905
|
+
name: string;
|
|
906
|
+
/** Base log level, or null if inherited. */
|
|
907
|
+
level: string | null;
|
|
908
|
+
/** UUID of the parent log group, or null. */
|
|
909
|
+
group: string | null;
|
|
910
|
+
/** Per-environment level overrides. */
|
|
911
|
+
environments: Record<string, any>;
|
|
912
|
+
/** When the log group was created. */
|
|
913
|
+
createdAt: string | null;
|
|
914
|
+
/** When the log group was last updated. */
|
|
915
|
+
updatedAt: string | null;
|
|
916
|
+
/** @internal */
|
|
917
|
+
readonly _client: LoggingClient;
|
|
918
|
+
/** @internal */
|
|
919
|
+
constructor(client: LoggingClient, fields: {
|
|
920
|
+
id: string | null;
|
|
921
|
+
key: string;
|
|
922
|
+
name: string;
|
|
923
|
+
level: string | null;
|
|
924
|
+
group: string | null;
|
|
925
|
+
environments: Record<string, any>;
|
|
926
|
+
createdAt: string | null;
|
|
927
|
+
updatedAt: string | null;
|
|
928
|
+
});
|
|
929
|
+
/**
|
|
930
|
+
* Persist this log group to the server.
|
|
931
|
+
*
|
|
932
|
+
* POST if `id` is null (new), PUT if `id` is set (update).
|
|
933
|
+
*/
|
|
934
|
+
save(): Promise<void>;
|
|
935
|
+
/** Set the base log level (sync local mutation). */
|
|
936
|
+
setLevel(level: LogLevel): void;
|
|
937
|
+
/** Clear the base log level (sync local mutation). */
|
|
938
|
+
clearLevel(): void;
|
|
939
|
+
/** Set an environment-specific log level (sync local mutation). */
|
|
940
|
+
setEnvironmentLevel(env: string, level: LogLevel): void;
|
|
941
|
+
/** Clear an environment-specific log level (sync local mutation). */
|
|
942
|
+
clearEnvironmentLevel(env: string): void;
|
|
943
|
+
/** Clear all environment-specific log levels (sync local mutation). */
|
|
944
|
+
clearAllEnvironmentLevels(): void;
|
|
945
|
+
/** @internal — copy all fields from another LogGroup instance. */
|
|
946
|
+
_apply(other: LogGroup): void;
|
|
947
|
+
toString(): string;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* LoggingClient — management plane + scaffolded runtime for Smpl Logging.
|
|
952
|
+
*
|
|
953
|
+
* Uses the generated OpenAPI types (`src/generated/logging.d.ts`) via
|
|
954
|
+
* `openapi-fetch` for all HTTP calls.
|
|
955
|
+
*/
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Client for the smplkit Logging API — management plane + scaffolded runtime.
|
|
959
|
+
*
|
|
960
|
+
* Obtained via `SmplClient.logging`.
|
|
961
|
+
*/
|
|
962
|
+
declare class LoggingClient {
|
|
963
|
+
/** @internal */
|
|
964
|
+
readonly _apiKey: string;
|
|
965
|
+
/** @internal */
|
|
966
|
+
readonly _baseUrl: string;
|
|
967
|
+
/** @internal */
|
|
968
|
+
private readonly _http;
|
|
969
|
+
/** @internal — set by SmplClient after construction. */
|
|
970
|
+
_parent: {
|
|
971
|
+
readonly _environment: string;
|
|
972
|
+
readonly _service: string | null;
|
|
973
|
+
} | null;
|
|
974
|
+
private readonly _ensureWs;
|
|
975
|
+
private _wsManager;
|
|
976
|
+
private _started;
|
|
977
|
+
private _globalListeners;
|
|
978
|
+
private _keyListeners;
|
|
979
|
+
/** @internal */
|
|
980
|
+
constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
|
|
981
|
+
/** Create an unsaved logger. Call `.save()` to persist. */
|
|
982
|
+
new(key: string, options?: {
|
|
983
|
+
name?: string;
|
|
984
|
+
managed?: boolean;
|
|
985
|
+
}): Logger;
|
|
986
|
+
/** Fetch a logger by key. */
|
|
987
|
+
get(key: string): Promise<Logger>;
|
|
988
|
+
/** List all loggers. */
|
|
989
|
+
list(): Promise<Logger[]>;
|
|
990
|
+
/** Delete a logger by key. */
|
|
991
|
+
delete(key: string): Promise<void>;
|
|
992
|
+
/** Create an unsaved log group. Call `.save()` to persist. */
|
|
993
|
+
newGroup(key: string, options?: {
|
|
994
|
+
name?: string;
|
|
995
|
+
group?: string;
|
|
996
|
+
}): LogGroup;
|
|
997
|
+
/** Fetch a log group by key. */
|
|
998
|
+
getGroup(key: string): Promise<LogGroup>;
|
|
999
|
+
/** List all log groups. */
|
|
1000
|
+
listGroups(): Promise<LogGroup[]>;
|
|
1001
|
+
/** Delete a log group by key. */
|
|
1002
|
+
deleteGroup(key: string): Promise<void>;
|
|
1003
|
+
/** @internal — POST or PUT a logger. */
|
|
1004
|
+
_saveLogger(logger: Logger): Promise<Logger>;
|
|
1005
|
+
/** @internal — POST or PUT a log group. */
|
|
1006
|
+
_saveLogGroup(group: LogGroup): Promise<LogGroup>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Start the logging runtime.
|
|
1009
|
+
*
|
|
1010
|
+
* Fetches existing loggers/groups and wires WebSocket listeners for
|
|
1011
|
+
* live updates. Idempotent — safe to call multiple times.
|
|
1012
|
+
*
|
|
1013
|
+
* Note: Node.js auto-discovery (equivalent to Python's logging module
|
|
1014
|
+
* monkey-patching) is deferred. Management methods work without start().
|
|
1015
|
+
*/
|
|
1016
|
+
start(): Promise<void>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Register a change listener.
|
|
1019
|
+
*
|
|
1020
|
+
* - `onChange(callback)` — fires for any logger change (global).
|
|
1021
|
+
* - `onChange(key, callback)` — fires only for the specified logger key.
|
|
1022
|
+
*/
|
|
1023
|
+
onChange(callbackOrKey: string | ((event: LoggerChangeEvent) => void), callback?: (event: LoggerChangeEvent) => void): void;
|
|
1024
|
+
/** @internal */
|
|
1025
|
+
_close(): void;
|
|
1026
|
+
private _handleLoggerChanged;
|
|
1027
|
+
private _loggerToModel;
|
|
1028
|
+
private _groupToModel;
|
|
707
1029
|
}
|
|
708
1030
|
|
|
709
1031
|
/**
|
|
710
1032
|
* Top-level SDK client — SmplClient.
|
|
711
1033
|
*
|
|
712
1034
|
* The main entry point for the smplkit TypeScript SDK. Provides access
|
|
713
|
-
* to sub-clients for each API domain (config, flags, logging
|
|
1035
|
+
* to sub-clients for each API domain (config, flags, logging).
|
|
714
1036
|
*/
|
|
715
1037
|
|
|
716
1038
|
/** Configuration options for the {@link SmplClient}. */
|
|
@@ -745,34 +1067,37 @@ interface SmplClientOptions {
|
|
|
745
1067
|
* ```typescript
|
|
746
1068
|
* import { SmplClient } from "@smplkit/sdk";
|
|
747
1069
|
*
|
|
748
|
-
* const client = new SmplClient({
|
|
749
|
-
*
|
|
1070
|
+
* const client = new SmplClient({
|
|
1071
|
+
* apiKey: "sk_api_...",
|
|
1072
|
+
* environment: "production",
|
|
1073
|
+
* service: "my-service",
|
|
1074
|
+
* });
|
|
1075
|
+
*
|
|
1076
|
+
* // Flags runtime
|
|
1077
|
+
* await client.flags.initialize();
|
|
1078
|
+
* const flag = client.flags.booleanFlag("checkout-v2", false);
|
|
1079
|
+
* console.log(flag.get());
|
|
1080
|
+
*
|
|
1081
|
+
* // Config runtime
|
|
1082
|
+
* const values = await client.config.resolve("user-service");
|
|
750
1083
|
* ```
|
|
751
1084
|
*/
|
|
752
1085
|
declare class SmplClient {
|
|
753
|
-
/** Client for config management
|
|
1086
|
+
/** Client for config management and runtime. */
|
|
754
1087
|
readonly config: ConfigClient;
|
|
755
|
-
/** Client for flags management and runtime
|
|
1088
|
+
/** Client for flags management and runtime. */
|
|
756
1089
|
readonly flags: FlagsClient;
|
|
1090
|
+
/** Client for logging management and runtime. */
|
|
1091
|
+
readonly logging: LoggingClient;
|
|
757
1092
|
private _wsManager;
|
|
758
1093
|
private readonly _apiKey;
|
|
759
1094
|
/** @internal */
|
|
760
1095
|
readonly _environment: string;
|
|
761
1096
|
/** @internal */
|
|
762
1097
|
readonly _service: string;
|
|
763
|
-
private _connected;
|
|
764
1098
|
private readonly _timeout;
|
|
765
1099
|
private readonly _appHttp;
|
|
766
1100
|
constructor(options?: SmplClientOptions);
|
|
767
|
-
/**
|
|
768
|
-
* Connect to the smplkit platform.
|
|
769
|
-
*
|
|
770
|
-
* Fetches initial flag and config data, opens the shared WebSocket,
|
|
771
|
-
* and registers the service as a context instance (if provided).
|
|
772
|
-
*
|
|
773
|
-
* This method is idempotent — calling it multiple times is safe.
|
|
774
|
-
*/
|
|
775
|
-
connect(): Promise<void>;
|
|
776
1101
|
/** @internal */
|
|
777
1102
|
private _registerServiceContext;
|
|
778
1103
|
/** Lazily create and start the shared WebSocket. @internal */
|
|
@@ -822,13 +1147,9 @@ declare class SmplNotFoundError extends SmplError {
|
|
|
822
1147
|
declare class SmplConflictError extends SmplError {
|
|
823
1148
|
constructor(message: string, statusCode?: number, responseBody?: string, errors?: ApiErrorObject[]);
|
|
824
1149
|
}
|
|
825
|
-
/** Raised when a method requiring connect() is called before connecting. */
|
|
826
|
-
declare class SmplNotConnectedError extends SmplError {
|
|
827
|
-
constructor(message: string);
|
|
828
|
-
}
|
|
829
1150
|
/** Raised when the server rejects a request due to validation errors (HTTP 422). */
|
|
830
1151
|
declare class SmplValidationError extends SmplError {
|
|
831
1152
|
constructor(message: string, statusCode?: number, responseBody?: string, errors?: ApiErrorObject[]);
|
|
832
1153
|
}
|
|
833
1154
|
|
|
834
|
-
export { type ApiErrorObject,
|
|
1155
|
+
export { type ApiErrorObject, BooleanFlag, Config, type ConfigChangeEvent, ConfigClient, Context, Flag, FlagChangeEvent, FlagStats, FlagsClient, JsonFlag, LiveConfigProxy, LogGroup, LogLevel, Logger, type LoggerChangeEvent, LoggingClient, NumberFlag, Rule, SharedWebSocket, SmplClient, type SmplClientOptions, SmplConflictError, SmplConnectionError, SmplError, SmplNotFoundError, SmplTimeoutError, SmplValidationError, StringFlag };
|