@smplkit/sdk 1.3.27 → 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.cjs +173 -230
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -73
- package/dist/index.d.ts +55 -73
- package/dist/index.js +173 -230
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16756,15 +16756,13 @@ function resolveChain(chain, environment) {
|
|
|
16756
16756
|
|
|
16757
16757
|
// src/config/types.ts
|
|
16758
16758
|
var Config = class {
|
|
16759
|
-
/**
|
|
16759
|
+
/** Unique identifier (slug, e.g. `"user-service"`). */
|
|
16760
16760
|
id;
|
|
16761
|
-
/** Human-readable key (e.g. `"user-service"`). */
|
|
16762
|
-
key;
|
|
16763
16761
|
/** Display name. */
|
|
16764
16762
|
name;
|
|
16765
16763
|
/** Optional description. */
|
|
16766
16764
|
description;
|
|
16767
|
-
/** Parent config
|
|
16765
|
+
/** Parent config id (slug), or null if this is a root config. */
|
|
16768
16766
|
parent;
|
|
16769
16767
|
/** Base key-value pairs. */
|
|
16770
16768
|
items;
|
|
@@ -16783,7 +16781,6 @@ var Config = class {
|
|
|
16783
16781
|
constructor(client, fields) {
|
|
16784
16782
|
this._client = client;
|
|
16785
16783
|
this.id = fields.id;
|
|
16786
|
-
this.key = fields.key;
|
|
16787
16784
|
this.name = fields.name;
|
|
16788
16785
|
this.description = fields.description;
|
|
16789
16786
|
this.parent = fields.parent;
|
|
@@ -16799,7 +16796,7 @@ var Config = class {
|
|
|
16799
16796
|
* Updates this instance in-place with the server response.
|
|
16800
16797
|
*/
|
|
16801
16798
|
async save() {
|
|
16802
|
-
if (this.
|
|
16799
|
+
if (this.createdAt === null) {
|
|
16803
16800
|
const created = await this._client._createConfig(this);
|
|
16804
16801
|
this._apply(created);
|
|
16805
16802
|
} else {
|
|
@@ -16833,7 +16830,6 @@ var Config = class {
|
|
|
16833
16830
|
/** @internal — copy all fields from another Config instance. */
|
|
16834
16831
|
_apply(other) {
|
|
16835
16832
|
this.id = other.id;
|
|
16836
|
-
this.key = other.key;
|
|
16837
16833
|
this.name = other.name;
|
|
16838
16834
|
this.description = other.description;
|
|
16839
16835
|
this.parent = other.parent;
|
|
@@ -16843,7 +16839,7 @@ var Config = class {
|
|
|
16843
16839
|
this.updatedAt = other.updatedAt;
|
|
16844
16840
|
}
|
|
16845
16841
|
toString() {
|
|
16846
|
-
return `Config(id=${this.id},
|
|
16842
|
+
return `Config(id=${this.id}, name=${this.name})`;
|
|
16847
16843
|
}
|
|
16848
16844
|
};
|
|
16849
16845
|
|
|
@@ -16936,7 +16932,6 @@ function resourceToConfig(resource, client) {
|
|
|
16936
16932
|
const attrs = resource.attributes;
|
|
16937
16933
|
return new Config(client, {
|
|
16938
16934
|
id: resource.id ?? null,
|
|
16939
|
-
key: attrs.key ?? "",
|
|
16940
16935
|
name: attrs.name,
|
|
16941
16936
|
description: attrs.description ?? null,
|
|
16942
16937
|
parent: attrs.parent ?? null,
|
|
@@ -16996,7 +16991,6 @@ function buildRequestBody(options) {
|
|
|
16996
16991
|
const attrs = {
|
|
16997
16992
|
name: options.name
|
|
16998
16993
|
};
|
|
16999
|
-
if (options.key !== void 0) attrs.key = options.key;
|
|
17000
16994
|
if (options.description !== void 0) attrs.description = options.description;
|
|
17001
16995
|
if (options.parent !== void 0) attrs.parent = options.parent;
|
|
17002
16996
|
if (options.items !== void 0)
|
|
@@ -17055,11 +17049,10 @@ var ConfigClient = class {
|
|
|
17055
17049
|
// Management: factory method
|
|
17056
17050
|
// ------------------------------------------------------------------
|
|
17057
17051
|
/** Create an unsaved config. Call `.save()` to persist. */
|
|
17058
|
-
new(
|
|
17052
|
+
new(id, options) {
|
|
17059
17053
|
return new Config(this, {
|
|
17060
|
-
id
|
|
17061
|
-
|
|
17062
|
-
name: options?.name ?? keyToDisplayName(key),
|
|
17054
|
+
id,
|
|
17055
|
+
name: options?.name ?? keyToDisplayName(id),
|
|
17063
17056
|
description: options?.description ?? null,
|
|
17064
17057
|
parent: options?.parent ?? null,
|
|
17065
17058
|
items: {},
|
|
@@ -17071,9 +17064,9 @@ var ConfigClient = class {
|
|
|
17071
17064
|
// ------------------------------------------------------------------
|
|
17072
17065
|
// Management: CRUD
|
|
17073
17066
|
// ------------------------------------------------------------------
|
|
17074
|
-
/** Fetch a config by
|
|
17075
|
-
async get(
|
|
17076
|
-
return this.
|
|
17067
|
+
/** Fetch a config by id. */
|
|
17068
|
+
async get(id) {
|
|
17069
|
+
return this._getById(id);
|
|
17077
17070
|
}
|
|
17078
17071
|
/** List all configs. */
|
|
17079
17072
|
async list() {
|
|
@@ -17088,15 +17081,14 @@ var ConfigClient = class {
|
|
|
17088
17081
|
if (!data) return [];
|
|
17089
17082
|
return data.data.map((r) => resourceToConfig(r, this));
|
|
17090
17083
|
}
|
|
17091
|
-
/** Delete a config by
|
|
17092
|
-
async delete(
|
|
17093
|
-
const config = await this.get(key);
|
|
17084
|
+
/** Delete a config by id. */
|
|
17085
|
+
async delete(id) {
|
|
17094
17086
|
try {
|
|
17095
17087
|
const result = await this._http.DELETE("/api/v1/configs/{id}", {
|
|
17096
|
-
params: { path: { id
|
|
17088
|
+
params: { path: { id } }
|
|
17097
17089
|
});
|
|
17098
17090
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
17099
|
-
await checkError(result.response, `Failed to delete config '${
|
|
17091
|
+
await checkError(result.response, `Failed to delete config '${id}'`);
|
|
17100
17092
|
} catch (err) {
|
|
17101
17093
|
wrapFetchError(err);
|
|
17102
17094
|
}
|
|
@@ -17107,8 +17099,8 @@ var ConfigClient = class {
|
|
|
17107
17099
|
/** @internal — POST a new config. */
|
|
17108
17100
|
async _createConfig(config) {
|
|
17109
17101
|
const body = buildRequestBody({
|
|
17102
|
+
id: config.id,
|
|
17110
17103
|
name: config.name,
|
|
17111
|
-
key: config.key,
|
|
17112
17104
|
description: config.description,
|
|
17113
17105
|
parent: config.parent,
|
|
17114
17106
|
items: config.items,
|
|
@@ -17130,7 +17122,6 @@ var ConfigClient = class {
|
|
|
17130
17122
|
const body = buildRequestBody({
|
|
17131
17123
|
id: config.id,
|
|
17132
17124
|
name: config.name,
|
|
17133
|
-
key: config.key,
|
|
17134
17125
|
description: config.description,
|
|
17135
17126
|
parent: config.parent,
|
|
17136
17127
|
items: config.items,
|
|
@@ -17151,20 +17142,20 @@ var ConfigClient = class {
|
|
|
17151
17142
|
if (!data || !data.data) throw new SmplValidationError(`Failed to update config ${config.id}`);
|
|
17152
17143
|
return resourceToConfig(data.data, this);
|
|
17153
17144
|
}
|
|
17154
|
-
/** @internal — fetch a config by
|
|
17155
|
-
async _getById(
|
|
17145
|
+
/** @internal — fetch a config by id. */
|
|
17146
|
+
async _getById(id) {
|
|
17156
17147
|
let data;
|
|
17157
17148
|
try {
|
|
17158
17149
|
const result = await this._http.GET("/api/v1/configs/{id}", {
|
|
17159
|
-
params: { path: { id
|
|
17150
|
+
params: { path: { id } }
|
|
17160
17151
|
});
|
|
17161
17152
|
if (result.error !== void 0)
|
|
17162
|
-
await checkError(result.response, `Config ${
|
|
17153
|
+
await checkError(result.response, `Config with id '${id}' not found`);
|
|
17163
17154
|
data = result.data;
|
|
17164
17155
|
} catch (err) {
|
|
17165
17156
|
wrapFetchError(err);
|
|
17166
17157
|
}
|
|
17167
|
-
if (!data || !data.data) throw new SmplNotFoundError(`Config ${
|
|
17158
|
+
if (!data || !data.data) throw new SmplNotFoundError(`Config with id '${id}' not found`);
|
|
17168
17159
|
return resourceToConfig(data.data, this);
|
|
17169
17160
|
}
|
|
17170
17161
|
// ------------------------------------------------------------------
|
|
@@ -17176,15 +17167,15 @@ var ConfigClient = class {
|
|
|
17176
17167
|
* Returns the resolved key-value pairs for the given config.
|
|
17177
17168
|
* Optionally pass a model class to map the resolved values.
|
|
17178
17169
|
*/
|
|
17179
|
-
async resolve(
|
|
17170
|
+
async resolve(id, model) {
|
|
17180
17171
|
await this._ensureInitialized();
|
|
17181
|
-
const values = this._configCache[
|
|
17172
|
+
const values = this._configCache[id];
|
|
17182
17173
|
if (values === void 0) {
|
|
17183
|
-
throw new SmplNotFoundError(`Config with
|
|
17174
|
+
throw new SmplNotFoundError(`Config with id '${id}' not found in cache`);
|
|
17184
17175
|
}
|
|
17185
17176
|
const metrics = this._parent?._metrics;
|
|
17186
17177
|
if (metrics) {
|
|
17187
|
-
metrics.record("config.resolutions", 1, "resolutions", { config_id:
|
|
17178
|
+
metrics.record("config.resolutions", 1, "resolutions", { config_id: id });
|
|
17188
17179
|
}
|
|
17189
17180
|
if (model) {
|
|
17190
17181
|
return new model(values);
|
|
@@ -17197,12 +17188,12 @@ var ConfigClient = class {
|
|
|
17197
17188
|
*
|
|
17198
17189
|
* Optionally pass a model class to map the resolved values.
|
|
17199
17190
|
*/
|
|
17200
|
-
async subscribe(
|
|
17191
|
+
async subscribe(id, model) {
|
|
17201
17192
|
await this._ensureInitialized();
|
|
17202
|
-
if (!(
|
|
17203
|
-
throw new SmplNotFoundError(`Config with
|
|
17193
|
+
if (!(id in this._configCache)) {
|
|
17194
|
+
throw new SmplNotFoundError(`Config with id '${id}' not found in cache`);
|
|
17204
17195
|
}
|
|
17205
|
-
return new LiveConfigProxy(this,
|
|
17196
|
+
return new LiveConfigProxy(this, id, model);
|
|
17206
17197
|
}
|
|
17207
17198
|
// ------------------------------------------------------------------
|
|
17208
17199
|
// Runtime: change listeners (3-level overloads)
|
|
@@ -17211,26 +17202,26 @@ var ConfigClient = class {
|
|
|
17211
17202
|
* Register a change listener.
|
|
17212
17203
|
*
|
|
17213
17204
|
* - `onChange(callback)` — fires for any config change (global).
|
|
17214
|
-
* - `onChange(
|
|
17215
|
-
* - `onChange(
|
|
17205
|
+
* - `onChange(configId, callback)` — fires for changes to a specific config.
|
|
17206
|
+
* - `onChange(configId, itemKey, callback)` — fires for a specific item.
|
|
17216
17207
|
*/
|
|
17217
|
-
onChange(
|
|
17218
|
-
if (typeof
|
|
17208
|
+
onChange(callbackOrConfigId, callbackOrItemKey, callback) {
|
|
17209
|
+
if (typeof callbackOrConfigId === "function") {
|
|
17219
17210
|
this._listeners.push({
|
|
17220
|
-
callback:
|
|
17221
|
-
|
|
17211
|
+
callback: callbackOrConfigId,
|
|
17212
|
+
configId: null,
|
|
17222
17213
|
itemKey: null
|
|
17223
17214
|
});
|
|
17224
17215
|
} else if (typeof callbackOrItemKey === "function") {
|
|
17225
17216
|
this._listeners.push({
|
|
17226
17217
|
callback: callbackOrItemKey,
|
|
17227
|
-
|
|
17218
|
+
configId: callbackOrConfigId,
|
|
17228
17219
|
itemKey: null
|
|
17229
17220
|
});
|
|
17230
17221
|
} else if (typeof callbackOrItemKey === "string" && callback) {
|
|
17231
17222
|
this._listeners.push({
|
|
17232
17223
|
callback,
|
|
17233
|
-
|
|
17224
|
+
configId: callbackOrConfigId,
|
|
17234
17225
|
itemKey: callbackOrItemKey
|
|
17235
17226
|
});
|
|
17236
17227
|
}
|
|
@@ -17254,7 +17245,7 @@ var ConfigClient = class {
|
|
|
17254
17245
|
const newCache = {};
|
|
17255
17246
|
for (const cfg of configs) {
|
|
17256
17247
|
const chain = await cfg._buildChain(configs);
|
|
17257
|
-
newCache[cfg.
|
|
17248
|
+
newCache[cfg.id] = resolveChain(chain, environment);
|
|
17258
17249
|
}
|
|
17259
17250
|
const oldCache = this._configCache;
|
|
17260
17251
|
this._configCache = newCache;
|
|
@@ -17274,7 +17265,7 @@ var ConfigClient = class {
|
|
|
17274
17265
|
const cache = {};
|
|
17275
17266
|
for (const cfg of configs) {
|
|
17276
17267
|
const chain = await cfg._buildChain(configs);
|
|
17277
|
-
cache[cfg.
|
|
17268
|
+
cache[cfg.id] = resolveChain(chain, environment);
|
|
17278
17269
|
}
|
|
17279
17270
|
this._configCache = cache;
|
|
17280
17271
|
this._initialized = true;
|
|
@@ -17290,7 +17281,7 @@ var ConfigClient = class {
|
|
|
17290
17281
|
const cache = {};
|
|
17291
17282
|
for (const cfg of configs) {
|
|
17292
17283
|
const chain = await cfg._buildChain(configs);
|
|
17293
|
-
cache[cfg.
|
|
17284
|
+
cache[cfg.id] = resolveChain(chain, environment);
|
|
17294
17285
|
}
|
|
17295
17286
|
this._configCache = cache;
|
|
17296
17287
|
this._initialized = true;
|
|
@@ -17325,14 +17316,14 @@ var ConfigClient = class {
|
|
|
17325
17316
|
metrics.record("config.changes", 1, "changes", { config_id: cfgKey });
|
|
17326
17317
|
}
|
|
17327
17318
|
const event = {
|
|
17328
|
-
|
|
17319
|
+
configId: cfgKey,
|
|
17329
17320
|
itemKey: iKey,
|
|
17330
17321
|
oldValue: oldVal,
|
|
17331
17322
|
newValue: newVal,
|
|
17332
17323
|
source
|
|
17333
17324
|
};
|
|
17334
17325
|
for (const listener of this._listeners) {
|
|
17335
|
-
if (listener.
|
|
17326
|
+
if (listener.configId !== null && listener.configId !== cfgKey) continue;
|
|
17336
17327
|
if (listener.itemKey !== null && listener.itemKey !== iKey) continue;
|
|
17337
17328
|
try {
|
|
17338
17329
|
listener.callback(event);
|
|
@@ -17343,26 +17334,6 @@ var ConfigClient = class {
|
|
|
17343
17334
|
}
|
|
17344
17335
|
}
|
|
17345
17336
|
}
|
|
17346
|
-
// ------------------------------------------------------------------
|
|
17347
|
-
// Internal: fetch by key
|
|
17348
|
-
// ------------------------------------------------------------------
|
|
17349
|
-
async _getByKey(key) {
|
|
17350
|
-
let data;
|
|
17351
|
-
try {
|
|
17352
|
-
const result = await this._http.GET("/api/v1/configs", {
|
|
17353
|
-
params: { query: { "filter[key]": key } }
|
|
17354
|
-
});
|
|
17355
|
-
if (result.error !== void 0)
|
|
17356
|
-
await checkError(result.response, `Config with key '${key}' not found`);
|
|
17357
|
-
data = result.data;
|
|
17358
|
-
} catch (err) {
|
|
17359
|
-
wrapFetchError(err);
|
|
17360
|
-
}
|
|
17361
|
-
if (!data || !data.data || data.data.length === 0) {
|
|
17362
|
-
throw new SmplNotFoundError(`Config with key '${key}' not found`);
|
|
17363
|
-
}
|
|
17364
|
-
return resourceToConfig(data.data[0], this);
|
|
17365
|
-
}
|
|
17366
17337
|
};
|
|
17367
17338
|
|
|
17368
17339
|
// src/flags/client.ts
|
|
@@ -17370,10 +17341,8 @@ import createClient2 from "openapi-fetch";
|
|
|
17370
17341
|
|
|
17371
17342
|
// src/flags/models.ts
|
|
17372
17343
|
var Flag = class {
|
|
17373
|
-
/**
|
|
17344
|
+
/** Unique identifier (slug) within the account. */
|
|
17374
17345
|
id;
|
|
17375
|
-
/** Unique key within the account. */
|
|
17376
|
-
key;
|
|
17377
17346
|
/** Human-readable display name. */
|
|
17378
17347
|
name;
|
|
17379
17348
|
/** Value type: BOOLEAN, STRING, NUMERIC, or JSON. */
|
|
@@ -17396,7 +17365,6 @@ var Flag = class {
|
|
|
17396
17365
|
constructor(client, fields) {
|
|
17397
17366
|
this._client = client;
|
|
17398
17367
|
this.id = fields.id;
|
|
17399
|
-
this.key = fields.key;
|
|
17400
17368
|
this.name = fields.name;
|
|
17401
17369
|
this.type = fields.type;
|
|
17402
17370
|
this.default = fields.default;
|
|
@@ -17413,7 +17381,7 @@ var Flag = class {
|
|
|
17413
17381
|
* Updates this instance in-place with the server response.
|
|
17414
17382
|
*/
|
|
17415
17383
|
async save() {
|
|
17416
|
-
if (this.
|
|
17384
|
+
if (this.createdAt === null) {
|
|
17417
17385
|
const created = await this._client._createFlag(this);
|
|
17418
17386
|
this._apply(created);
|
|
17419
17387
|
} else {
|
|
@@ -17477,12 +17445,11 @@ var Flag = class {
|
|
|
17477
17445
|
* Requires `initialize()` to have been called on the flags client.
|
|
17478
17446
|
*/
|
|
17479
17447
|
get(options) {
|
|
17480
|
-
return this._client._evaluateHandle(this.
|
|
17448
|
+
return this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17481
17449
|
}
|
|
17482
17450
|
/** @internal — copy all fields from another Flag instance. */
|
|
17483
17451
|
_apply(other) {
|
|
17484
17452
|
this.id = other.id;
|
|
17485
|
-
this.key = other.key;
|
|
17486
17453
|
this.name = other.name;
|
|
17487
17454
|
this.type = other.type;
|
|
17488
17455
|
this.default = other.default;
|
|
@@ -17493,12 +17460,12 @@ var Flag = class {
|
|
|
17493
17460
|
this.updatedAt = other.updatedAt;
|
|
17494
17461
|
}
|
|
17495
17462
|
toString() {
|
|
17496
|
-
return `Flag(
|
|
17463
|
+
return `Flag(id=${this.id}, type=${this.type}, default=${this.default})`;
|
|
17497
17464
|
}
|
|
17498
17465
|
};
|
|
17499
17466
|
var BooleanFlag = class extends Flag {
|
|
17500
17467
|
get(options) {
|
|
17501
|
-
const value = this._client._evaluateHandle(this.
|
|
17468
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17502
17469
|
if (typeof value === "boolean") {
|
|
17503
17470
|
return value;
|
|
17504
17471
|
}
|
|
@@ -17507,7 +17474,7 @@ var BooleanFlag = class extends Flag {
|
|
|
17507
17474
|
};
|
|
17508
17475
|
var StringFlag = class extends Flag {
|
|
17509
17476
|
get(options) {
|
|
17510
|
-
const value = this._client._evaluateHandle(this.
|
|
17477
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17511
17478
|
if (typeof value === "string") {
|
|
17512
17479
|
return value;
|
|
17513
17480
|
}
|
|
@@ -17516,7 +17483,7 @@ var StringFlag = class extends Flag {
|
|
|
17516
17483
|
};
|
|
17517
17484
|
var NumberFlag = class extends Flag {
|
|
17518
17485
|
get(options) {
|
|
17519
|
-
const value = this._client._evaluateHandle(this.
|
|
17486
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17520
17487
|
if (typeof value === "number") {
|
|
17521
17488
|
return value;
|
|
17522
17489
|
}
|
|
@@ -17525,7 +17492,7 @@ var NumberFlag = class extends Flag {
|
|
|
17525
17492
|
};
|
|
17526
17493
|
var JsonFlag = class extends Flag {
|
|
17527
17494
|
get(options) {
|
|
17528
|
-
const value = this._client._evaluateHandle(this.
|
|
17495
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17529
17496
|
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
17530
17497
|
return value;
|
|
17531
17498
|
}
|
|
@@ -17608,10 +17575,10 @@ function evaluateFlag(flagDef, environment, evalDict) {
|
|
|
17608
17575
|
return fallback;
|
|
17609
17576
|
}
|
|
17610
17577
|
var FlagChangeEvent = class {
|
|
17611
|
-
|
|
17578
|
+
id;
|
|
17612
17579
|
source;
|
|
17613
|
-
constructor(
|
|
17614
|
-
this.
|
|
17580
|
+
constructor(id, source) {
|
|
17581
|
+
this.id = id;
|
|
17615
17582
|
this.source = source;
|
|
17616
17583
|
}
|
|
17617
17584
|
};
|
|
@@ -17753,11 +17720,10 @@ var FlagsClient = class {
|
|
|
17753
17720
|
// Management: factory methods (return unsaved flags)
|
|
17754
17721
|
// ------------------------------------------------------------------
|
|
17755
17722
|
/** Create an unsaved boolean flag. Call `.save()` to persist. */
|
|
17756
|
-
newBooleanFlag(
|
|
17723
|
+
newBooleanFlag(id, options) {
|
|
17757
17724
|
return new BooleanFlag(this, {
|
|
17758
|
-
id
|
|
17759
|
-
|
|
17760
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17725
|
+
id,
|
|
17726
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17761
17727
|
type: "BOOLEAN",
|
|
17762
17728
|
default: options.default,
|
|
17763
17729
|
values: [
|
|
@@ -17771,11 +17737,10 @@ var FlagsClient = class {
|
|
|
17771
17737
|
});
|
|
17772
17738
|
}
|
|
17773
17739
|
/** Create an unsaved string flag. Call `.save()` to persist. */
|
|
17774
|
-
newStringFlag(
|
|
17740
|
+
newStringFlag(id, options) {
|
|
17775
17741
|
return new StringFlag(this, {
|
|
17776
|
-
id
|
|
17777
|
-
|
|
17778
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17742
|
+
id,
|
|
17743
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17779
17744
|
type: "STRING",
|
|
17780
17745
|
default: options.default,
|
|
17781
17746
|
values: options.values ?? null,
|
|
@@ -17786,11 +17751,10 @@ var FlagsClient = class {
|
|
|
17786
17751
|
});
|
|
17787
17752
|
}
|
|
17788
17753
|
/** Create an unsaved number flag. Call `.save()` to persist. */
|
|
17789
|
-
newNumberFlag(
|
|
17754
|
+
newNumberFlag(id, options) {
|
|
17790
17755
|
return new NumberFlag(this, {
|
|
17791
|
-
id
|
|
17792
|
-
|
|
17793
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17756
|
+
id,
|
|
17757
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17794
17758
|
type: "NUMERIC",
|
|
17795
17759
|
default: options.default,
|
|
17796
17760
|
values: options.values ?? null,
|
|
@@ -17801,11 +17765,10 @@ var FlagsClient = class {
|
|
|
17801
17765
|
});
|
|
17802
17766
|
}
|
|
17803
17767
|
/** Create an unsaved JSON flag. Call `.save()` to persist. */
|
|
17804
|
-
newJsonFlag(
|
|
17768
|
+
newJsonFlag(id, options) {
|
|
17805
17769
|
return new JsonFlag(this, {
|
|
17806
|
-
id
|
|
17807
|
-
|
|
17808
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17770
|
+
id,
|
|
17771
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17809
17772
|
type: "JSON",
|
|
17810
17773
|
default: options.default,
|
|
17811
17774
|
values: options.values ?? null,
|
|
@@ -17818,23 +17781,23 @@ var FlagsClient = class {
|
|
|
17818
17781
|
// ------------------------------------------------------------------
|
|
17819
17782
|
// Management: CRUD
|
|
17820
17783
|
// ------------------------------------------------------------------
|
|
17821
|
-
/** Fetch a flag by
|
|
17822
|
-
async get(
|
|
17784
|
+
/** Fetch a flag by id. */
|
|
17785
|
+
async get(id) {
|
|
17823
17786
|
let data;
|
|
17824
17787
|
try {
|
|
17825
|
-
const result = await this._http.GET("/api/v1/flags", {
|
|
17826
|
-
params: {
|
|
17788
|
+
const result = await this._http.GET("/api/v1/flags/{id}", {
|
|
17789
|
+
params: { path: { id } }
|
|
17827
17790
|
});
|
|
17828
17791
|
if (result.error !== void 0)
|
|
17829
|
-
await checkError2(result.response, `Flag with
|
|
17792
|
+
await checkError2(result.response, `Flag with id '${id}' not found`);
|
|
17830
17793
|
data = result.data;
|
|
17831
17794
|
} catch (err) {
|
|
17832
17795
|
wrapFetchError2(err);
|
|
17833
17796
|
}
|
|
17834
|
-
if (!data || !data.data
|
|
17835
|
-
throw new SmplNotFoundError(`Flag with
|
|
17797
|
+
if (!data || !data.data) {
|
|
17798
|
+
throw new SmplNotFoundError(`Flag with id '${id}' not found`);
|
|
17836
17799
|
}
|
|
17837
|
-
return this._resourceToModel(data.data
|
|
17800
|
+
return this._resourceToModel(data.data);
|
|
17838
17801
|
}
|
|
17839
17802
|
/** List all flags. */
|
|
17840
17803
|
async list() {
|
|
@@ -17849,15 +17812,14 @@ var FlagsClient = class {
|
|
|
17849
17812
|
if (!data) return [];
|
|
17850
17813
|
return data.data.map((r) => this._resourceToModel(r));
|
|
17851
17814
|
}
|
|
17852
|
-
/** Delete a flag by
|
|
17853
|
-
async delete(
|
|
17854
|
-
const flag = await this.get(key);
|
|
17815
|
+
/** Delete a flag by id. */
|
|
17816
|
+
async delete(id) {
|
|
17855
17817
|
try {
|
|
17856
17818
|
const result = await this._http.DELETE("/api/v1/flags/{id}", {
|
|
17857
|
-
params: { path: { id
|
|
17819
|
+
params: { path: { id } }
|
|
17858
17820
|
});
|
|
17859
17821
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
17860
|
-
await checkError2(result.response, `Failed to delete flag '${
|
|
17822
|
+
await checkError2(result.response, `Failed to delete flag '${id}'`);
|
|
17861
17823
|
} catch (err) {
|
|
17862
17824
|
wrapFetchError2(err);
|
|
17863
17825
|
}
|
|
@@ -17869,9 +17831,9 @@ var FlagsClient = class {
|
|
|
17869
17831
|
async _createFlag(flag) {
|
|
17870
17832
|
const body = {
|
|
17871
17833
|
data: {
|
|
17834
|
+
id: flag.id,
|
|
17872
17835
|
type: "flag",
|
|
17873
17836
|
attributes: {
|
|
17874
|
-
key: flag.key,
|
|
17875
17837
|
name: flag.name,
|
|
17876
17838
|
description: flag.description ?? "",
|
|
17877
17839
|
type: flag.type,
|
|
@@ -17898,7 +17860,6 @@ var FlagsClient = class {
|
|
|
17898
17860
|
data: {
|
|
17899
17861
|
type: "flag",
|
|
17900
17862
|
attributes: {
|
|
17901
|
-
key: flag.key,
|
|
17902
17863
|
name: flag.name,
|
|
17903
17864
|
type: flag.type,
|
|
17904
17865
|
default: flag.default,
|
|
@@ -17927,11 +17888,10 @@ var FlagsClient = class {
|
|
|
17927
17888
|
// Runtime: typed flag handles
|
|
17928
17889
|
// ------------------------------------------------------------------
|
|
17929
17890
|
/** Declare a boolean flag handle for runtime evaluation. */
|
|
17930
|
-
booleanFlag(
|
|
17891
|
+
booleanFlag(id, defaultValue) {
|
|
17931
17892
|
const handle = new BooleanFlag(this, {
|
|
17932
|
-
id
|
|
17933
|
-
|
|
17934
|
-
name: key,
|
|
17893
|
+
id,
|
|
17894
|
+
name: id,
|
|
17935
17895
|
type: "BOOLEAN",
|
|
17936
17896
|
default: defaultValue,
|
|
17937
17897
|
values: [],
|
|
@@ -17940,15 +17900,14 @@ var FlagsClient = class {
|
|
|
17940
17900
|
createdAt: null,
|
|
17941
17901
|
updatedAt: null
|
|
17942
17902
|
});
|
|
17943
|
-
this._handles[
|
|
17903
|
+
this._handles[id] = handle;
|
|
17944
17904
|
return handle;
|
|
17945
17905
|
}
|
|
17946
17906
|
/** Declare a string flag handle for runtime evaluation. */
|
|
17947
|
-
stringFlag(
|
|
17907
|
+
stringFlag(id, defaultValue) {
|
|
17948
17908
|
const handle = new StringFlag(this, {
|
|
17949
|
-
id
|
|
17950
|
-
|
|
17951
|
-
name: key,
|
|
17909
|
+
id,
|
|
17910
|
+
name: id,
|
|
17952
17911
|
type: "STRING",
|
|
17953
17912
|
default: defaultValue,
|
|
17954
17913
|
values: [],
|
|
@@ -17957,15 +17916,14 @@ var FlagsClient = class {
|
|
|
17957
17916
|
createdAt: null,
|
|
17958
17917
|
updatedAt: null
|
|
17959
17918
|
});
|
|
17960
|
-
this._handles[
|
|
17919
|
+
this._handles[id] = handle;
|
|
17961
17920
|
return handle;
|
|
17962
17921
|
}
|
|
17963
17922
|
/** Declare a numeric flag handle for runtime evaluation. */
|
|
17964
|
-
numberFlag(
|
|
17923
|
+
numberFlag(id, defaultValue) {
|
|
17965
17924
|
const handle = new NumberFlag(this, {
|
|
17966
|
-
id
|
|
17967
|
-
|
|
17968
|
-
name: key,
|
|
17925
|
+
id,
|
|
17926
|
+
name: id,
|
|
17969
17927
|
type: "NUMERIC",
|
|
17970
17928
|
default: defaultValue,
|
|
17971
17929
|
values: [],
|
|
@@ -17974,15 +17932,14 @@ var FlagsClient = class {
|
|
|
17974
17932
|
createdAt: null,
|
|
17975
17933
|
updatedAt: null
|
|
17976
17934
|
});
|
|
17977
|
-
this._handles[
|
|
17935
|
+
this._handles[id] = handle;
|
|
17978
17936
|
return handle;
|
|
17979
17937
|
}
|
|
17980
17938
|
/** Declare a JSON flag handle for runtime evaluation. */
|
|
17981
|
-
jsonFlag(
|
|
17939
|
+
jsonFlag(id, defaultValue) {
|
|
17982
17940
|
const handle = new JsonFlag(this, {
|
|
17983
|
-
id
|
|
17984
|
-
|
|
17985
|
-
name: key,
|
|
17941
|
+
id,
|
|
17942
|
+
name: id,
|
|
17986
17943
|
type: "JSON",
|
|
17987
17944
|
default: defaultValue,
|
|
17988
17945
|
values: [],
|
|
@@ -17991,7 +17948,7 @@ var FlagsClient = class {
|
|
|
17991
17948
|
createdAt: null,
|
|
17992
17949
|
updatedAt: null
|
|
17993
17950
|
});
|
|
17994
|
-
this._handles[
|
|
17951
|
+
this._handles[id] = handle;
|
|
17995
17952
|
return handle;
|
|
17996
17953
|
}
|
|
17997
17954
|
// ------------------------------------------------------------------
|
|
@@ -18068,20 +18025,20 @@ var FlagsClient = class {
|
|
|
18068
18025
|
* Register a change listener.
|
|
18069
18026
|
*
|
|
18070
18027
|
* - `onChange(callback)` — fires for any flag change.
|
|
18071
|
-
* - `onChange(
|
|
18028
|
+
* - `onChange(id, callback)` — fires only for the specified flag id.
|
|
18072
18029
|
*/
|
|
18073
|
-
onChange(
|
|
18074
|
-
if (typeof
|
|
18075
|
-
this._globalListeners.push(
|
|
18030
|
+
onChange(callbackOrId, callback) {
|
|
18031
|
+
if (typeof callbackOrId === "function") {
|
|
18032
|
+
this._globalListeners.push(callbackOrId);
|
|
18076
18033
|
} else {
|
|
18077
|
-
const
|
|
18034
|
+
const id = callbackOrId;
|
|
18078
18035
|
if (!callback) {
|
|
18079
|
-
throw new SmplError("onChange(
|
|
18036
|
+
throw new SmplError("onChange(id, callback) requires a callback function.");
|
|
18080
18037
|
}
|
|
18081
|
-
if (!this._keyListeners.has(
|
|
18082
|
-
this._keyListeners.set(
|
|
18038
|
+
if (!this._keyListeners.has(id)) {
|
|
18039
|
+
this._keyListeners.set(id, []);
|
|
18083
18040
|
}
|
|
18084
|
-
this._keyListeners.get(
|
|
18041
|
+
this._keyListeners.get(id).push(callback);
|
|
18085
18042
|
}
|
|
18086
18043
|
}
|
|
18087
18044
|
// ------------------------------------------------------------------
|
|
@@ -18109,18 +18066,18 @@ var FlagsClient = class {
|
|
|
18109
18066
|
/**
|
|
18110
18067
|
* Evaluate a flag with an explicit environment and context.
|
|
18111
18068
|
*/
|
|
18112
|
-
async evaluate(
|
|
18069
|
+
async evaluate(id, options) {
|
|
18113
18070
|
const evalDict = contextsToEvalDict(options.context);
|
|
18114
18071
|
if (this._parent?._service && !("service" in evalDict)) {
|
|
18115
18072
|
evalDict["service"] = { key: this._parent._service };
|
|
18116
18073
|
}
|
|
18117
18074
|
let flagDef = null;
|
|
18118
|
-
if (this._initialized &&
|
|
18119
|
-
flagDef = this._flagStore[
|
|
18075
|
+
if (this._initialized && id in this._flagStore) {
|
|
18076
|
+
flagDef = this._flagStore[id];
|
|
18120
18077
|
} else {
|
|
18121
18078
|
const flags = await this._fetchFlagsList();
|
|
18122
18079
|
for (const f of flags) {
|
|
18123
|
-
if (f.
|
|
18080
|
+
if (f.id === id) {
|
|
18124
18081
|
flagDef = f;
|
|
18125
18082
|
break;
|
|
18126
18083
|
}
|
|
@@ -18200,17 +18157,17 @@ var FlagsClient = class {
|
|
|
18200
18157
|
// Internal: event handlers (called by SharedWebSocket)
|
|
18201
18158
|
// ------------------------------------------------------------------
|
|
18202
18159
|
_handleFlagChanged = (data) => {
|
|
18203
|
-
const
|
|
18160
|
+
const flagId = data.id;
|
|
18204
18161
|
void this._fetchAllFlags().then(() => {
|
|
18205
18162
|
this._cache.clear();
|
|
18206
|
-
this._fireChangeListeners(
|
|
18163
|
+
this._fireChangeListeners(flagId ?? null, "websocket");
|
|
18207
18164
|
});
|
|
18208
18165
|
};
|
|
18209
18166
|
_handleFlagDeleted = (data) => {
|
|
18210
|
-
const
|
|
18167
|
+
const flagId = data.id;
|
|
18211
18168
|
void this._fetchAllFlags().then(() => {
|
|
18212
18169
|
this._cache.clear();
|
|
18213
|
-
this._fireChangeListeners(
|
|
18170
|
+
this._fireChangeListeners(flagId ?? null, "websocket");
|
|
18214
18171
|
});
|
|
18215
18172
|
};
|
|
18216
18173
|
// ------------------------------------------------------------------
|
|
@@ -18220,7 +18177,7 @@ var FlagsClient = class {
|
|
|
18220
18177
|
const flags = await this._fetchFlagsList();
|
|
18221
18178
|
const store = {};
|
|
18222
18179
|
for (const f of flags) {
|
|
18223
|
-
store[f.
|
|
18180
|
+
store[f.id] = f;
|
|
18224
18181
|
}
|
|
18225
18182
|
this._flagStore = store;
|
|
18226
18183
|
}
|
|
@@ -18239,18 +18196,18 @@ var FlagsClient = class {
|
|
|
18239
18196
|
// ------------------------------------------------------------------
|
|
18240
18197
|
// Internal: change listeners
|
|
18241
18198
|
// ------------------------------------------------------------------
|
|
18242
|
-
_fireChangeListeners(
|
|
18243
|
-
if (
|
|
18244
|
-
const event = new FlagChangeEvent(
|
|
18199
|
+
_fireChangeListeners(flagId, source) {
|
|
18200
|
+
if (flagId) {
|
|
18201
|
+
const event = new FlagChangeEvent(flagId, source);
|
|
18245
18202
|
for (const cb of this._globalListeners) {
|
|
18246
18203
|
try {
|
|
18247
18204
|
cb(event);
|
|
18248
18205
|
} catch {
|
|
18249
18206
|
}
|
|
18250
18207
|
}
|
|
18251
|
-
const
|
|
18252
|
-
if (
|
|
18253
|
-
for (const cb of
|
|
18208
|
+
const idCallbacks = this._keyListeners.get(flagId);
|
|
18209
|
+
if (idCallbacks) {
|
|
18210
|
+
for (const cb of idCallbacks) {
|
|
18254
18211
|
try {
|
|
18255
18212
|
cb(event);
|
|
18256
18213
|
} catch {
|
|
@@ -18260,8 +18217,8 @@ var FlagsClient = class {
|
|
|
18260
18217
|
}
|
|
18261
18218
|
}
|
|
18262
18219
|
_fireChangeListenersAll(source) {
|
|
18263
|
-
for (const
|
|
18264
|
-
this._fireChangeListeners(
|
|
18220
|
+
for (const flagId of Object.keys(this._flagStore)) {
|
|
18221
|
+
this._fireChangeListeners(flagId, source);
|
|
18265
18222
|
}
|
|
18266
18223
|
}
|
|
18267
18224
|
// ------------------------------------------------------------------
|
|
@@ -18291,7 +18248,6 @@ var FlagsClient = class {
|
|
|
18291
18248
|
const attrs = resource.attributes;
|
|
18292
18249
|
return new Flag(this, {
|
|
18293
18250
|
id: resource.id ?? null,
|
|
18294
|
-
key: attrs.key,
|
|
18295
18251
|
name: attrs.name,
|
|
18296
18252
|
type: attrs.type,
|
|
18297
18253
|
default: attrs.default,
|
|
@@ -18305,7 +18261,7 @@ var FlagsClient = class {
|
|
|
18305
18261
|
_resourceToPlainDict(resource) {
|
|
18306
18262
|
const attrs = resource.attributes;
|
|
18307
18263
|
return {
|
|
18308
|
-
|
|
18264
|
+
id: resource.id ?? null,
|
|
18309
18265
|
name: attrs.name,
|
|
18310
18266
|
type: attrs.type,
|
|
18311
18267
|
default: attrs.default,
|
|
@@ -18321,15 +18277,13 @@ import createClient3 from "openapi-fetch";
|
|
|
18321
18277
|
|
|
18322
18278
|
// src/logging/models.ts
|
|
18323
18279
|
var Logger = class {
|
|
18324
|
-
/**
|
|
18280
|
+
/** Unique identifier (dot-separated hierarchy, e.g. `"sqlalchemy.engine"`). */
|
|
18325
18281
|
id;
|
|
18326
|
-
/** Unique key (dot-separated hierarchy). */
|
|
18327
|
-
key;
|
|
18328
18282
|
/** Human-readable display name. */
|
|
18329
18283
|
name;
|
|
18330
18284
|
/** Base log level, or null if inherited. */
|
|
18331
18285
|
level;
|
|
18332
|
-
/**
|
|
18286
|
+
/** Id of the parent log group, or null. */
|
|
18333
18287
|
group;
|
|
18334
18288
|
/** Whether this logger is managed by the platform. */
|
|
18335
18289
|
managed;
|
|
@@ -18347,7 +18301,6 @@ var Logger = class {
|
|
|
18347
18301
|
constructor(client, fields) {
|
|
18348
18302
|
this._client = client;
|
|
18349
18303
|
this.id = fields.id;
|
|
18350
|
-
this.key = fields.key;
|
|
18351
18304
|
this.name = fields.name;
|
|
18352
18305
|
this.level = fields.level;
|
|
18353
18306
|
this.group = fields.group;
|
|
@@ -18397,7 +18350,6 @@ var Logger = class {
|
|
|
18397
18350
|
/** @internal — copy all fields from another Logger instance. */
|
|
18398
18351
|
_apply(other) {
|
|
18399
18352
|
this.id = other.id;
|
|
18400
|
-
this.key = other.key;
|
|
18401
18353
|
this.name = other.name;
|
|
18402
18354
|
this.level = other.level;
|
|
18403
18355
|
this.group = other.group;
|
|
@@ -18408,19 +18360,17 @@ var Logger = class {
|
|
|
18408
18360
|
this.updatedAt = other.updatedAt;
|
|
18409
18361
|
}
|
|
18410
18362
|
toString() {
|
|
18411
|
-
return `Logger(
|
|
18363
|
+
return `Logger(id=${this.id}, level=${this.level})`;
|
|
18412
18364
|
}
|
|
18413
18365
|
};
|
|
18414
18366
|
var LogGroup = class {
|
|
18415
|
-
/**
|
|
18367
|
+
/** Unique identifier (slug), or `null` if unsaved. */
|
|
18416
18368
|
id;
|
|
18417
|
-
/** Unique key. */
|
|
18418
|
-
key;
|
|
18419
18369
|
/** Human-readable display name. */
|
|
18420
18370
|
name;
|
|
18421
18371
|
/** Base log level, or null if inherited. */
|
|
18422
18372
|
level;
|
|
18423
|
-
/**
|
|
18373
|
+
/** Id of the parent log group, or null. */
|
|
18424
18374
|
group;
|
|
18425
18375
|
/** Per-environment level overrides. */
|
|
18426
18376
|
environments;
|
|
@@ -18434,7 +18384,6 @@ var LogGroup = class {
|
|
|
18434
18384
|
constructor(client, fields) {
|
|
18435
18385
|
this._client = client;
|
|
18436
18386
|
this.id = fields.id;
|
|
18437
|
-
this.key = fields.key;
|
|
18438
18387
|
this.name = fields.name;
|
|
18439
18388
|
this.level = fields.level;
|
|
18440
18389
|
this.group = fields.group;
|
|
@@ -18482,7 +18431,6 @@ var LogGroup = class {
|
|
|
18482
18431
|
/** @internal — copy all fields from another LogGroup instance. */
|
|
18483
18432
|
_apply(other) {
|
|
18484
18433
|
this.id = other.id;
|
|
18485
|
-
this.key = other.key;
|
|
18486
18434
|
this.name = other.name;
|
|
18487
18435
|
this.level = other.level;
|
|
18488
18436
|
this.group = other.group;
|
|
@@ -18491,7 +18439,7 @@ var LogGroup = class {
|
|
|
18491
18439
|
this.updatedAt = other.updatedAt;
|
|
18492
18440
|
}
|
|
18493
18441
|
toString() {
|
|
18494
|
-
return `LogGroup(
|
|
18442
|
+
return `LogGroup(id=${this.id}, level=${this.level})`;
|
|
18495
18443
|
}
|
|
18496
18444
|
};
|
|
18497
18445
|
|
|
@@ -18575,11 +18523,10 @@ var LoggingClient = class {
|
|
|
18575
18523
|
// Management: Logger factory
|
|
18576
18524
|
// ------------------------------------------------------------------
|
|
18577
18525
|
/** Create an unsaved logger. Call `.save()` to persist. */
|
|
18578
|
-
new(
|
|
18526
|
+
new(id, options) {
|
|
18579
18527
|
return new Logger(this, {
|
|
18580
|
-
id
|
|
18581
|
-
|
|
18582
|
-
name: options?.name ?? keyToDisplayName(key),
|
|
18528
|
+
id,
|
|
18529
|
+
name: options?.name ?? keyToDisplayName(id),
|
|
18583
18530
|
level: null,
|
|
18584
18531
|
group: null,
|
|
18585
18532
|
managed: options?.managed ?? false,
|
|
@@ -18592,23 +18539,23 @@ var LoggingClient = class {
|
|
|
18592
18539
|
// ------------------------------------------------------------------
|
|
18593
18540
|
// Management: Logger CRUD
|
|
18594
18541
|
// ------------------------------------------------------------------
|
|
18595
|
-
/** Fetch a logger by
|
|
18596
|
-
async get(
|
|
18542
|
+
/** Fetch a logger by id. */
|
|
18543
|
+
async get(id) {
|
|
18597
18544
|
let data;
|
|
18598
18545
|
try {
|
|
18599
|
-
const result = await this._http.GET("/api/v1/loggers", {
|
|
18600
|
-
params: {
|
|
18546
|
+
const result = await this._http.GET("/api/v1/loggers/{id}", {
|
|
18547
|
+
params: { path: { id } }
|
|
18601
18548
|
});
|
|
18602
18549
|
if (result.error !== void 0)
|
|
18603
|
-
await checkError3(result.response, `Logger with
|
|
18550
|
+
await checkError3(result.response, `Logger with id '${id}' not found`);
|
|
18604
18551
|
data = result.data;
|
|
18605
18552
|
} catch (err) {
|
|
18606
18553
|
wrapFetchError3(err);
|
|
18607
18554
|
}
|
|
18608
|
-
if (!data || !data.data
|
|
18609
|
-
throw new SmplNotFoundError(`Logger with
|
|
18555
|
+
if (!data || !data.data) {
|
|
18556
|
+
throw new SmplNotFoundError(`Logger with id '${id}' not found`);
|
|
18610
18557
|
}
|
|
18611
|
-
return this._loggerToModel(data.data
|
|
18558
|
+
return this._loggerToModel(data.data);
|
|
18612
18559
|
}
|
|
18613
18560
|
/** List all loggers. */
|
|
18614
18561
|
async list() {
|
|
@@ -18623,15 +18570,14 @@ var LoggingClient = class {
|
|
|
18623
18570
|
if (!data) return [];
|
|
18624
18571
|
return data.data.map((r) => this._loggerToModel(r));
|
|
18625
18572
|
}
|
|
18626
|
-
/** Delete a logger by
|
|
18627
|
-
async delete(
|
|
18628
|
-
const logger = await this.get(key);
|
|
18573
|
+
/** Delete a logger by id. */
|
|
18574
|
+
async delete(id) {
|
|
18629
18575
|
try {
|
|
18630
18576
|
const result = await this._http.DELETE("/api/v1/loggers/{id}", {
|
|
18631
|
-
params: { path: { id
|
|
18577
|
+
params: { path: { id } }
|
|
18632
18578
|
});
|
|
18633
18579
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
18634
|
-
await checkError3(result.response, `Failed to delete logger '${
|
|
18580
|
+
await checkError3(result.response, `Failed to delete logger '${id}'`);
|
|
18635
18581
|
} catch (err) {
|
|
18636
18582
|
wrapFetchError3(err);
|
|
18637
18583
|
}
|
|
@@ -18640,11 +18586,10 @@ var LoggingClient = class {
|
|
|
18640
18586
|
// Management: LogGroup factory
|
|
18641
18587
|
// ------------------------------------------------------------------
|
|
18642
18588
|
/** Create an unsaved log group. Call `.save()` to persist. */
|
|
18643
|
-
newGroup(
|
|
18589
|
+
newGroup(id, options) {
|
|
18644
18590
|
return new LogGroup(this, {
|
|
18645
|
-
id
|
|
18646
|
-
|
|
18647
|
-
name: options?.name ?? keyToDisplayName(key),
|
|
18591
|
+
id,
|
|
18592
|
+
name: options?.name ?? keyToDisplayName(id),
|
|
18648
18593
|
level: null,
|
|
18649
18594
|
group: options?.group ?? null,
|
|
18650
18595
|
environments: {},
|
|
@@ -18655,12 +18600,12 @@ var LoggingClient = class {
|
|
|
18655
18600
|
// ------------------------------------------------------------------
|
|
18656
18601
|
// Management: LogGroup CRUD
|
|
18657
18602
|
// ------------------------------------------------------------------
|
|
18658
|
-
/** Fetch a log group by
|
|
18659
|
-
async getGroup(
|
|
18603
|
+
/** Fetch a log group by id. */
|
|
18604
|
+
async getGroup(id) {
|
|
18660
18605
|
const groups = await this.listGroups();
|
|
18661
|
-
const match = groups.find((g) => g.
|
|
18606
|
+
const match = groups.find((g) => g.id === id);
|
|
18662
18607
|
if (!match) {
|
|
18663
|
-
throw new SmplNotFoundError(`LogGroup with
|
|
18608
|
+
throw new SmplNotFoundError(`LogGroup with id '${id}' not found`);
|
|
18664
18609
|
}
|
|
18665
18610
|
return match;
|
|
18666
18611
|
}
|
|
@@ -18678,15 +18623,15 @@ var LoggingClient = class {
|
|
|
18678
18623
|
if (!data) return [];
|
|
18679
18624
|
return data.data.map((r) => this._groupToModel(r));
|
|
18680
18625
|
}
|
|
18681
|
-
/** Delete a log group by
|
|
18682
|
-
async deleteGroup(
|
|
18683
|
-
const group = await this.getGroup(
|
|
18626
|
+
/** Delete a log group by id. */
|
|
18627
|
+
async deleteGroup(id) {
|
|
18628
|
+
const group = await this.getGroup(id);
|
|
18684
18629
|
try {
|
|
18685
18630
|
const result = await this._http.DELETE("/api/v1/log_groups/{id}", {
|
|
18686
18631
|
params: { path: { id: group.id } }
|
|
18687
18632
|
});
|
|
18688
18633
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
18689
|
-
await checkError3(result.response, `Failed to delete log group '${
|
|
18634
|
+
await checkError3(result.response, `Failed to delete log group '${id}'`);
|
|
18690
18635
|
} catch (err) {
|
|
18691
18636
|
wrapFetchError3(err);
|
|
18692
18637
|
}
|
|
@@ -18698,9 +18643,9 @@ var LoggingClient = class {
|
|
|
18698
18643
|
async _saveLogger(logger) {
|
|
18699
18644
|
const body = {
|
|
18700
18645
|
data: {
|
|
18646
|
+
id: logger.id,
|
|
18701
18647
|
type: "logger",
|
|
18702
18648
|
attributes: {
|
|
18703
|
-
key: logger.key,
|
|
18704
18649
|
name: logger.name,
|
|
18705
18650
|
level: logger.level,
|
|
18706
18651
|
group: logger.group,
|
|
@@ -18709,7 +18654,7 @@ var LoggingClient = class {
|
|
|
18709
18654
|
}
|
|
18710
18655
|
}
|
|
18711
18656
|
};
|
|
18712
|
-
if (logger.
|
|
18657
|
+
if (logger.createdAt === null) {
|
|
18713
18658
|
let data;
|
|
18714
18659
|
try {
|
|
18715
18660
|
const result = await this._http.POST("/api/v1/loggers", { body });
|
|
@@ -18743,9 +18688,9 @@ var LoggingClient = class {
|
|
|
18743
18688
|
async _saveLogGroup(group) {
|
|
18744
18689
|
const body = {
|
|
18745
18690
|
data: {
|
|
18691
|
+
id: group.id,
|
|
18746
18692
|
type: "log_group",
|
|
18747
18693
|
attributes: {
|
|
18748
|
-
key: group.key,
|
|
18749
18694
|
name: group.name,
|
|
18750
18695
|
level: group.level,
|
|
18751
18696
|
group: group.group,
|
|
@@ -18753,7 +18698,7 @@ var LoggingClient = class {
|
|
|
18753
18698
|
}
|
|
18754
18699
|
}
|
|
18755
18700
|
};
|
|
18756
|
-
if (group.
|
|
18701
|
+
if (group.createdAt === null) {
|
|
18757
18702
|
let data;
|
|
18758
18703
|
try {
|
|
18759
18704
|
const result = await this._http.POST("/api/v1/log_groups", { body });
|
|
@@ -18844,20 +18789,20 @@ var LoggingClient = class {
|
|
|
18844
18789
|
* Register a change listener.
|
|
18845
18790
|
*
|
|
18846
18791
|
* - `onChange(callback)` — fires for any logger change.
|
|
18847
|
-
* - `onChange(
|
|
18792
|
+
* - `onChange(id, callback)` — fires only for the specified logger id.
|
|
18848
18793
|
*/
|
|
18849
|
-
onChange(
|
|
18850
|
-
if (typeof
|
|
18851
|
-
this._globalListeners.push(
|
|
18794
|
+
onChange(callbackOrId, callback) {
|
|
18795
|
+
if (typeof callbackOrId === "function") {
|
|
18796
|
+
this._globalListeners.push(callbackOrId);
|
|
18852
18797
|
} else {
|
|
18853
|
-
const
|
|
18798
|
+
const id = callbackOrId;
|
|
18854
18799
|
if (!callback) {
|
|
18855
|
-
throw new SmplError("onChange(
|
|
18800
|
+
throw new SmplError("onChange(id, callback) requires a callback function.");
|
|
18856
18801
|
}
|
|
18857
|
-
if (!this._keyListeners.has(
|
|
18858
|
-
this._keyListeners.set(
|
|
18802
|
+
if (!this._keyListeners.has(id)) {
|
|
18803
|
+
this._keyListeners.set(id, []);
|
|
18859
18804
|
}
|
|
18860
|
-
this._keyListeners.get(
|
|
18805
|
+
this._keyListeners.get(id).push(callback);
|
|
18861
18806
|
}
|
|
18862
18807
|
}
|
|
18863
18808
|
// ------------------------------------------------------------------
|
|
@@ -18916,11 +18861,11 @@ var LoggingClient = class {
|
|
|
18916
18861
|
}
|
|
18917
18862
|
const metrics = this._parent?._metrics;
|
|
18918
18863
|
if (metrics) {
|
|
18919
|
-
metrics.record("logging.level_changes", 1, "changes", { logger_id: logger.
|
|
18864
|
+
metrics.record("logging.level_changes", 1, "changes", { logger_id: logger.id });
|
|
18920
18865
|
}
|
|
18921
18866
|
for (const adapter of this._adapters) {
|
|
18922
18867
|
try {
|
|
18923
|
-
adapter.applyLevel(logger.
|
|
18868
|
+
adapter.applyLevel(logger.id, effectiveLevel);
|
|
18924
18869
|
} catch {
|
|
18925
18870
|
}
|
|
18926
18871
|
}
|
|
@@ -18937,11 +18882,11 @@ var LoggingClient = class {
|
|
|
18937
18882
|
// Internal: WebSocket handler
|
|
18938
18883
|
// ------------------------------------------------------------------
|
|
18939
18884
|
_handleLoggerChanged = (data) => {
|
|
18940
|
-
const
|
|
18941
|
-
if (
|
|
18885
|
+
const id = data.id;
|
|
18886
|
+
if (id) {
|
|
18942
18887
|
const level = data.level ?? null;
|
|
18943
18888
|
const event = {
|
|
18944
|
-
|
|
18889
|
+
id,
|
|
18945
18890
|
level,
|
|
18946
18891
|
source: "websocket"
|
|
18947
18892
|
};
|
|
@@ -18951,9 +18896,9 @@ var LoggingClient = class {
|
|
|
18951
18896
|
} catch {
|
|
18952
18897
|
}
|
|
18953
18898
|
}
|
|
18954
|
-
const
|
|
18955
|
-
if (
|
|
18956
|
-
for (const cb of
|
|
18899
|
+
const idCallbacks = this._keyListeners.get(id);
|
|
18900
|
+
if (idCallbacks) {
|
|
18901
|
+
for (const cb of idCallbacks) {
|
|
18957
18902
|
try {
|
|
18958
18903
|
cb(event);
|
|
18959
18904
|
} catch {
|
|
@@ -18969,7 +18914,6 @@ var LoggingClient = class {
|
|
|
18969
18914
|
const attrs = resource.attributes;
|
|
18970
18915
|
return new Logger(this, {
|
|
18971
18916
|
id: resource.id ?? null,
|
|
18972
|
-
key: attrs.key ?? "",
|
|
18973
18917
|
name: attrs.name,
|
|
18974
18918
|
level: attrs.level ?? null,
|
|
18975
18919
|
group: attrs.group ?? null,
|
|
@@ -18984,7 +18928,6 @@ var LoggingClient = class {
|
|
|
18984
18928
|
const attrs = resource.attributes;
|
|
18985
18929
|
return new LogGroup(this, {
|
|
18986
18930
|
id: resource.id ?? null,
|
|
18987
|
-
key: attrs.key ?? "",
|
|
18988
18931
|
name: attrs.name,
|
|
18989
18932
|
level: attrs.level ?? null,
|
|
18990
18933
|
group: attrs.group ?? null,
|