@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.cjs
CHANGED
|
@@ -16794,15 +16794,13 @@ function resolveChain(chain, environment) {
|
|
|
16794
16794
|
|
|
16795
16795
|
// src/config/types.ts
|
|
16796
16796
|
var Config = class {
|
|
16797
|
-
/**
|
|
16797
|
+
/** Unique identifier (slug, e.g. `"user-service"`). */
|
|
16798
16798
|
id;
|
|
16799
|
-
/** Human-readable key (e.g. `"user-service"`). */
|
|
16800
|
-
key;
|
|
16801
16799
|
/** Display name. */
|
|
16802
16800
|
name;
|
|
16803
16801
|
/** Optional description. */
|
|
16804
16802
|
description;
|
|
16805
|
-
/** Parent config
|
|
16803
|
+
/** Parent config id (slug), or null if this is a root config. */
|
|
16806
16804
|
parent;
|
|
16807
16805
|
/** Base key-value pairs. */
|
|
16808
16806
|
items;
|
|
@@ -16821,7 +16819,6 @@ var Config = class {
|
|
|
16821
16819
|
constructor(client, fields) {
|
|
16822
16820
|
this._client = client;
|
|
16823
16821
|
this.id = fields.id;
|
|
16824
|
-
this.key = fields.key;
|
|
16825
16822
|
this.name = fields.name;
|
|
16826
16823
|
this.description = fields.description;
|
|
16827
16824
|
this.parent = fields.parent;
|
|
@@ -16837,7 +16834,7 @@ var Config = class {
|
|
|
16837
16834
|
* Updates this instance in-place with the server response.
|
|
16838
16835
|
*/
|
|
16839
16836
|
async save() {
|
|
16840
|
-
if (this.
|
|
16837
|
+
if (this.createdAt === null) {
|
|
16841
16838
|
const created = await this._client._createConfig(this);
|
|
16842
16839
|
this._apply(created);
|
|
16843
16840
|
} else {
|
|
@@ -16871,7 +16868,6 @@ var Config = class {
|
|
|
16871
16868
|
/** @internal — copy all fields from another Config instance. */
|
|
16872
16869
|
_apply(other) {
|
|
16873
16870
|
this.id = other.id;
|
|
16874
|
-
this.key = other.key;
|
|
16875
16871
|
this.name = other.name;
|
|
16876
16872
|
this.description = other.description;
|
|
16877
16873
|
this.parent = other.parent;
|
|
@@ -16881,7 +16877,7 @@ var Config = class {
|
|
|
16881
16877
|
this.updatedAt = other.updatedAt;
|
|
16882
16878
|
}
|
|
16883
16879
|
toString() {
|
|
16884
|
-
return `Config(id=${this.id},
|
|
16880
|
+
return `Config(id=${this.id}, name=${this.name})`;
|
|
16885
16881
|
}
|
|
16886
16882
|
};
|
|
16887
16883
|
|
|
@@ -16974,7 +16970,6 @@ function resourceToConfig(resource, client) {
|
|
|
16974
16970
|
const attrs = resource.attributes;
|
|
16975
16971
|
return new Config(client, {
|
|
16976
16972
|
id: resource.id ?? null,
|
|
16977
|
-
key: attrs.key ?? "",
|
|
16978
16973
|
name: attrs.name,
|
|
16979
16974
|
description: attrs.description ?? null,
|
|
16980
16975
|
parent: attrs.parent ?? null,
|
|
@@ -17034,7 +17029,6 @@ function buildRequestBody(options) {
|
|
|
17034
17029
|
const attrs = {
|
|
17035
17030
|
name: options.name
|
|
17036
17031
|
};
|
|
17037
|
-
if (options.key !== void 0) attrs.key = options.key;
|
|
17038
17032
|
if (options.description !== void 0) attrs.description = options.description;
|
|
17039
17033
|
if (options.parent !== void 0) attrs.parent = options.parent;
|
|
17040
17034
|
if (options.items !== void 0)
|
|
@@ -17093,11 +17087,10 @@ var ConfigClient = class {
|
|
|
17093
17087
|
// Management: factory method
|
|
17094
17088
|
// ------------------------------------------------------------------
|
|
17095
17089
|
/** Create an unsaved config. Call `.save()` to persist. */
|
|
17096
|
-
new(
|
|
17090
|
+
new(id, options) {
|
|
17097
17091
|
return new Config(this, {
|
|
17098
|
-
id
|
|
17099
|
-
|
|
17100
|
-
name: options?.name ?? keyToDisplayName(key),
|
|
17092
|
+
id,
|
|
17093
|
+
name: options?.name ?? keyToDisplayName(id),
|
|
17101
17094
|
description: options?.description ?? null,
|
|
17102
17095
|
parent: options?.parent ?? null,
|
|
17103
17096
|
items: {},
|
|
@@ -17109,9 +17102,9 @@ var ConfigClient = class {
|
|
|
17109
17102
|
// ------------------------------------------------------------------
|
|
17110
17103
|
// Management: CRUD
|
|
17111
17104
|
// ------------------------------------------------------------------
|
|
17112
|
-
/** Fetch a config by
|
|
17113
|
-
async get(
|
|
17114
|
-
return this.
|
|
17105
|
+
/** Fetch a config by id. */
|
|
17106
|
+
async get(id) {
|
|
17107
|
+
return this._getById(id);
|
|
17115
17108
|
}
|
|
17116
17109
|
/** List all configs. */
|
|
17117
17110
|
async list() {
|
|
@@ -17126,15 +17119,14 @@ var ConfigClient = class {
|
|
|
17126
17119
|
if (!data) return [];
|
|
17127
17120
|
return data.data.map((r) => resourceToConfig(r, this));
|
|
17128
17121
|
}
|
|
17129
|
-
/** Delete a config by
|
|
17130
|
-
async delete(
|
|
17131
|
-
const config = await this.get(key);
|
|
17122
|
+
/** Delete a config by id. */
|
|
17123
|
+
async delete(id) {
|
|
17132
17124
|
try {
|
|
17133
17125
|
const result = await this._http.DELETE("/api/v1/configs/{id}", {
|
|
17134
|
-
params: { path: { id
|
|
17126
|
+
params: { path: { id } }
|
|
17135
17127
|
});
|
|
17136
17128
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
17137
|
-
await checkError(result.response, `Failed to delete config '${
|
|
17129
|
+
await checkError(result.response, `Failed to delete config '${id}'`);
|
|
17138
17130
|
} catch (err) {
|
|
17139
17131
|
wrapFetchError(err);
|
|
17140
17132
|
}
|
|
@@ -17145,8 +17137,8 @@ var ConfigClient = class {
|
|
|
17145
17137
|
/** @internal — POST a new config. */
|
|
17146
17138
|
async _createConfig(config) {
|
|
17147
17139
|
const body = buildRequestBody({
|
|
17140
|
+
id: config.id,
|
|
17148
17141
|
name: config.name,
|
|
17149
|
-
key: config.key,
|
|
17150
17142
|
description: config.description,
|
|
17151
17143
|
parent: config.parent,
|
|
17152
17144
|
items: config.items,
|
|
@@ -17168,7 +17160,6 @@ var ConfigClient = class {
|
|
|
17168
17160
|
const body = buildRequestBody({
|
|
17169
17161
|
id: config.id,
|
|
17170
17162
|
name: config.name,
|
|
17171
|
-
key: config.key,
|
|
17172
17163
|
description: config.description,
|
|
17173
17164
|
parent: config.parent,
|
|
17174
17165
|
items: config.items,
|
|
@@ -17189,20 +17180,20 @@ var ConfigClient = class {
|
|
|
17189
17180
|
if (!data || !data.data) throw new SmplValidationError(`Failed to update config ${config.id}`);
|
|
17190
17181
|
return resourceToConfig(data.data, this);
|
|
17191
17182
|
}
|
|
17192
|
-
/** @internal — fetch a config by
|
|
17193
|
-
async _getById(
|
|
17183
|
+
/** @internal — fetch a config by id. */
|
|
17184
|
+
async _getById(id) {
|
|
17194
17185
|
let data;
|
|
17195
17186
|
try {
|
|
17196
17187
|
const result = await this._http.GET("/api/v1/configs/{id}", {
|
|
17197
|
-
params: { path: { id
|
|
17188
|
+
params: { path: { id } }
|
|
17198
17189
|
});
|
|
17199
17190
|
if (result.error !== void 0)
|
|
17200
|
-
await checkError(result.response, `Config ${
|
|
17191
|
+
await checkError(result.response, `Config with id '${id}' not found`);
|
|
17201
17192
|
data = result.data;
|
|
17202
17193
|
} catch (err) {
|
|
17203
17194
|
wrapFetchError(err);
|
|
17204
17195
|
}
|
|
17205
|
-
if (!data || !data.data) throw new SmplNotFoundError(`Config ${
|
|
17196
|
+
if (!data || !data.data) throw new SmplNotFoundError(`Config with id '${id}' not found`);
|
|
17206
17197
|
return resourceToConfig(data.data, this);
|
|
17207
17198
|
}
|
|
17208
17199
|
// ------------------------------------------------------------------
|
|
@@ -17214,15 +17205,15 @@ var ConfigClient = class {
|
|
|
17214
17205
|
* Returns the resolved key-value pairs for the given config.
|
|
17215
17206
|
* Optionally pass a model class to map the resolved values.
|
|
17216
17207
|
*/
|
|
17217
|
-
async resolve(
|
|
17208
|
+
async resolve(id, model) {
|
|
17218
17209
|
await this._ensureInitialized();
|
|
17219
|
-
const values = this._configCache[
|
|
17210
|
+
const values = this._configCache[id];
|
|
17220
17211
|
if (values === void 0) {
|
|
17221
|
-
throw new SmplNotFoundError(`Config with
|
|
17212
|
+
throw new SmplNotFoundError(`Config with id '${id}' not found in cache`);
|
|
17222
17213
|
}
|
|
17223
17214
|
const metrics = this._parent?._metrics;
|
|
17224
17215
|
if (metrics) {
|
|
17225
|
-
metrics.record("config.resolutions", 1, "resolutions", { config_id:
|
|
17216
|
+
metrics.record("config.resolutions", 1, "resolutions", { config_id: id });
|
|
17226
17217
|
}
|
|
17227
17218
|
if (model) {
|
|
17228
17219
|
return new model(values);
|
|
@@ -17235,12 +17226,12 @@ var ConfigClient = class {
|
|
|
17235
17226
|
*
|
|
17236
17227
|
* Optionally pass a model class to map the resolved values.
|
|
17237
17228
|
*/
|
|
17238
|
-
async subscribe(
|
|
17229
|
+
async subscribe(id, model) {
|
|
17239
17230
|
await this._ensureInitialized();
|
|
17240
|
-
if (!(
|
|
17241
|
-
throw new SmplNotFoundError(`Config with
|
|
17231
|
+
if (!(id in this._configCache)) {
|
|
17232
|
+
throw new SmplNotFoundError(`Config with id '${id}' not found in cache`);
|
|
17242
17233
|
}
|
|
17243
|
-
return new LiveConfigProxy(this,
|
|
17234
|
+
return new LiveConfigProxy(this, id, model);
|
|
17244
17235
|
}
|
|
17245
17236
|
// ------------------------------------------------------------------
|
|
17246
17237
|
// Runtime: change listeners (3-level overloads)
|
|
@@ -17249,26 +17240,26 @@ var ConfigClient = class {
|
|
|
17249
17240
|
* Register a change listener.
|
|
17250
17241
|
*
|
|
17251
17242
|
* - `onChange(callback)` — fires for any config change (global).
|
|
17252
|
-
* - `onChange(
|
|
17253
|
-
* - `onChange(
|
|
17243
|
+
* - `onChange(configId, callback)` — fires for changes to a specific config.
|
|
17244
|
+
* - `onChange(configId, itemKey, callback)` — fires for a specific item.
|
|
17254
17245
|
*/
|
|
17255
|
-
onChange(
|
|
17256
|
-
if (typeof
|
|
17246
|
+
onChange(callbackOrConfigId, callbackOrItemKey, callback) {
|
|
17247
|
+
if (typeof callbackOrConfigId === "function") {
|
|
17257
17248
|
this._listeners.push({
|
|
17258
|
-
callback:
|
|
17259
|
-
|
|
17249
|
+
callback: callbackOrConfigId,
|
|
17250
|
+
configId: null,
|
|
17260
17251
|
itemKey: null
|
|
17261
17252
|
});
|
|
17262
17253
|
} else if (typeof callbackOrItemKey === "function") {
|
|
17263
17254
|
this._listeners.push({
|
|
17264
17255
|
callback: callbackOrItemKey,
|
|
17265
|
-
|
|
17256
|
+
configId: callbackOrConfigId,
|
|
17266
17257
|
itemKey: null
|
|
17267
17258
|
});
|
|
17268
17259
|
} else if (typeof callbackOrItemKey === "string" && callback) {
|
|
17269
17260
|
this._listeners.push({
|
|
17270
17261
|
callback,
|
|
17271
|
-
|
|
17262
|
+
configId: callbackOrConfigId,
|
|
17272
17263
|
itemKey: callbackOrItemKey
|
|
17273
17264
|
});
|
|
17274
17265
|
}
|
|
@@ -17292,7 +17283,7 @@ var ConfigClient = class {
|
|
|
17292
17283
|
const newCache = {};
|
|
17293
17284
|
for (const cfg of configs) {
|
|
17294
17285
|
const chain = await cfg._buildChain(configs);
|
|
17295
|
-
newCache[cfg.
|
|
17286
|
+
newCache[cfg.id] = resolveChain(chain, environment);
|
|
17296
17287
|
}
|
|
17297
17288
|
const oldCache = this._configCache;
|
|
17298
17289
|
this._configCache = newCache;
|
|
@@ -17312,7 +17303,7 @@ var ConfigClient = class {
|
|
|
17312
17303
|
const cache = {};
|
|
17313
17304
|
for (const cfg of configs) {
|
|
17314
17305
|
const chain = await cfg._buildChain(configs);
|
|
17315
|
-
cache[cfg.
|
|
17306
|
+
cache[cfg.id] = resolveChain(chain, environment);
|
|
17316
17307
|
}
|
|
17317
17308
|
this._configCache = cache;
|
|
17318
17309
|
this._initialized = true;
|
|
@@ -17328,7 +17319,7 @@ var ConfigClient = class {
|
|
|
17328
17319
|
const cache = {};
|
|
17329
17320
|
for (const cfg of configs) {
|
|
17330
17321
|
const chain = await cfg._buildChain(configs);
|
|
17331
|
-
cache[cfg.
|
|
17322
|
+
cache[cfg.id] = resolveChain(chain, environment);
|
|
17332
17323
|
}
|
|
17333
17324
|
this._configCache = cache;
|
|
17334
17325
|
this._initialized = true;
|
|
@@ -17363,14 +17354,14 @@ var ConfigClient = class {
|
|
|
17363
17354
|
metrics.record("config.changes", 1, "changes", { config_id: cfgKey });
|
|
17364
17355
|
}
|
|
17365
17356
|
const event = {
|
|
17366
|
-
|
|
17357
|
+
configId: cfgKey,
|
|
17367
17358
|
itemKey: iKey,
|
|
17368
17359
|
oldValue: oldVal,
|
|
17369
17360
|
newValue: newVal,
|
|
17370
17361
|
source
|
|
17371
17362
|
};
|
|
17372
17363
|
for (const listener of this._listeners) {
|
|
17373
|
-
if (listener.
|
|
17364
|
+
if (listener.configId !== null && listener.configId !== cfgKey) continue;
|
|
17374
17365
|
if (listener.itemKey !== null && listener.itemKey !== iKey) continue;
|
|
17375
17366
|
try {
|
|
17376
17367
|
listener.callback(event);
|
|
@@ -17381,26 +17372,6 @@ var ConfigClient = class {
|
|
|
17381
17372
|
}
|
|
17382
17373
|
}
|
|
17383
17374
|
}
|
|
17384
|
-
// ------------------------------------------------------------------
|
|
17385
|
-
// Internal: fetch by key
|
|
17386
|
-
// ------------------------------------------------------------------
|
|
17387
|
-
async _getByKey(key) {
|
|
17388
|
-
let data;
|
|
17389
|
-
try {
|
|
17390
|
-
const result = await this._http.GET("/api/v1/configs", {
|
|
17391
|
-
params: { query: { "filter[key]": key } }
|
|
17392
|
-
});
|
|
17393
|
-
if (result.error !== void 0)
|
|
17394
|
-
await checkError(result.response, `Config with key '${key}' not found`);
|
|
17395
|
-
data = result.data;
|
|
17396
|
-
} catch (err) {
|
|
17397
|
-
wrapFetchError(err);
|
|
17398
|
-
}
|
|
17399
|
-
if (!data || !data.data || data.data.length === 0) {
|
|
17400
|
-
throw new SmplNotFoundError(`Config with key '${key}' not found`);
|
|
17401
|
-
}
|
|
17402
|
-
return resourceToConfig(data.data[0], this);
|
|
17403
|
-
}
|
|
17404
17375
|
};
|
|
17405
17376
|
|
|
17406
17377
|
// src/flags/client.ts
|
|
@@ -17408,10 +17379,8 @@ var import_openapi_fetch2 = __toESM(require("openapi-fetch"), 1);
|
|
|
17408
17379
|
|
|
17409
17380
|
// src/flags/models.ts
|
|
17410
17381
|
var Flag = class {
|
|
17411
|
-
/**
|
|
17382
|
+
/** Unique identifier (slug) within the account. */
|
|
17412
17383
|
id;
|
|
17413
|
-
/** Unique key within the account. */
|
|
17414
|
-
key;
|
|
17415
17384
|
/** Human-readable display name. */
|
|
17416
17385
|
name;
|
|
17417
17386
|
/** Value type: BOOLEAN, STRING, NUMERIC, or JSON. */
|
|
@@ -17434,7 +17403,6 @@ var Flag = class {
|
|
|
17434
17403
|
constructor(client, fields) {
|
|
17435
17404
|
this._client = client;
|
|
17436
17405
|
this.id = fields.id;
|
|
17437
|
-
this.key = fields.key;
|
|
17438
17406
|
this.name = fields.name;
|
|
17439
17407
|
this.type = fields.type;
|
|
17440
17408
|
this.default = fields.default;
|
|
@@ -17451,7 +17419,7 @@ var Flag = class {
|
|
|
17451
17419
|
* Updates this instance in-place with the server response.
|
|
17452
17420
|
*/
|
|
17453
17421
|
async save() {
|
|
17454
|
-
if (this.
|
|
17422
|
+
if (this.createdAt === null) {
|
|
17455
17423
|
const created = await this._client._createFlag(this);
|
|
17456
17424
|
this._apply(created);
|
|
17457
17425
|
} else {
|
|
@@ -17515,12 +17483,11 @@ var Flag = class {
|
|
|
17515
17483
|
* Requires `initialize()` to have been called on the flags client.
|
|
17516
17484
|
*/
|
|
17517
17485
|
get(options) {
|
|
17518
|
-
return this._client._evaluateHandle(this.
|
|
17486
|
+
return this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17519
17487
|
}
|
|
17520
17488
|
/** @internal — copy all fields from another Flag instance. */
|
|
17521
17489
|
_apply(other) {
|
|
17522
17490
|
this.id = other.id;
|
|
17523
|
-
this.key = other.key;
|
|
17524
17491
|
this.name = other.name;
|
|
17525
17492
|
this.type = other.type;
|
|
17526
17493
|
this.default = other.default;
|
|
@@ -17531,12 +17498,12 @@ var Flag = class {
|
|
|
17531
17498
|
this.updatedAt = other.updatedAt;
|
|
17532
17499
|
}
|
|
17533
17500
|
toString() {
|
|
17534
|
-
return `Flag(
|
|
17501
|
+
return `Flag(id=${this.id}, type=${this.type}, default=${this.default})`;
|
|
17535
17502
|
}
|
|
17536
17503
|
};
|
|
17537
17504
|
var BooleanFlag = class extends Flag {
|
|
17538
17505
|
get(options) {
|
|
17539
|
-
const value = this._client._evaluateHandle(this.
|
|
17506
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17540
17507
|
if (typeof value === "boolean") {
|
|
17541
17508
|
return value;
|
|
17542
17509
|
}
|
|
@@ -17545,7 +17512,7 @@ var BooleanFlag = class extends Flag {
|
|
|
17545
17512
|
};
|
|
17546
17513
|
var StringFlag = class extends Flag {
|
|
17547
17514
|
get(options) {
|
|
17548
|
-
const value = this._client._evaluateHandle(this.
|
|
17515
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17549
17516
|
if (typeof value === "string") {
|
|
17550
17517
|
return value;
|
|
17551
17518
|
}
|
|
@@ -17554,7 +17521,7 @@ var StringFlag = class extends Flag {
|
|
|
17554
17521
|
};
|
|
17555
17522
|
var NumberFlag = class extends Flag {
|
|
17556
17523
|
get(options) {
|
|
17557
|
-
const value = this._client._evaluateHandle(this.
|
|
17524
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17558
17525
|
if (typeof value === "number") {
|
|
17559
17526
|
return value;
|
|
17560
17527
|
}
|
|
@@ -17563,7 +17530,7 @@ var NumberFlag = class extends Flag {
|
|
|
17563
17530
|
};
|
|
17564
17531
|
var JsonFlag = class extends Flag {
|
|
17565
17532
|
get(options) {
|
|
17566
|
-
const value = this._client._evaluateHandle(this.
|
|
17533
|
+
const value = this._client._evaluateHandle(this.id, this.default, options?.context ?? null);
|
|
17567
17534
|
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
17568
17535
|
return value;
|
|
17569
17536
|
}
|
|
@@ -17646,10 +17613,10 @@ function evaluateFlag(flagDef, environment, evalDict) {
|
|
|
17646
17613
|
return fallback;
|
|
17647
17614
|
}
|
|
17648
17615
|
var FlagChangeEvent = class {
|
|
17649
|
-
|
|
17616
|
+
id;
|
|
17650
17617
|
source;
|
|
17651
|
-
constructor(
|
|
17652
|
-
this.
|
|
17618
|
+
constructor(id, source) {
|
|
17619
|
+
this.id = id;
|
|
17653
17620
|
this.source = source;
|
|
17654
17621
|
}
|
|
17655
17622
|
};
|
|
@@ -17791,11 +17758,10 @@ var FlagsClient = class {
|
|
|
17791
17758
|
// Management: factory methods (return unsaved flags)
|
|
17792
17759
|
// ------------------------------------------------------------------
|
|
17793
17760
|
/** Create an unsaved boolean flag. Call `.save()` to persist. */
|
|
17794
|
-
newBooleanFlag(
|
|
17761
|
+
newBooleanFlag(id, options) {
|
|
17795
17762
|
return new BooleanFlag(this, {
|
|
17796
|
-
id
|
|
17797
|
-
|
|
17798
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17763
|
+
id,
|
|
17764
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17799
17765
|
type: "BOOLEAN",
|
|
17800
17766
|
default: options.default,
|
|
17801
17767
|
values: [
|
|
@@ -17809,11 +17775,10 @@ var FlagsClient = class {
|
|
|
17809
17775
|
});
|
|
17810
17776
|
}
|
|
17811
17777
|
/** Create an unsaved string flag. Call `.save()` to persist. */
|
|
17812
|
-
newStringFlag(
|
|
17778
|
+
newStringFlag(id, options) {
|
|
17813
17779
|
return new StringFlag(this, {
|
|
17814
|
-
id
|
|
17815
|
-
|
|
17816
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17780
|
+
id,
|
|
17781
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17817
17782
|
type: "STRING",
|
|
17818
17783
|
default: options.default,
|
|
17819
17784
|
values: options.values ?? null,
|
|
@@ -17824,11 +17789,10 @@ var FlagsClient = class {
|
|
|
17824
17789
|
});
|
|
17825
17790
|
}
|
|
17826
17791
|
/** Create an unsaved number flag. Call `.save()` to persist. */
|
|
17827
|
-
newNumberFlag(
|
|
17792
|
+
newNumberFlag(id, options) {
|
|
17828
17793
|
return new NumberFlag(this, {
|
|
17829
|
-
id
|
|
17830
|
-
|
|
17831
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17794
|
+
id,
|
|
17795
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17832
17796
|
type: "NUMERIC",
|
|
17833
17797
|
default: options.default,
|
|
17834
17798
|
values: options.values ?? null,
|
|
@@ -17839,11 +17803,10 @@ var FlagsClient = class {
|
|
|
17839
17803
|
});
|
|
17840
17804
|
}
|
|
17841
17805
|
/** Create an unsaved JSON flag. Call `.save()` to persist. */
|
|
17842
|
-
newJsonFlag(
|
|
17806
|
+
newJsonFlag(id, options) {
|
|
17843
17807
|
return new JsonFlag(this, {
|
|
17844
|
-
id
|
|
17845
|
-
|
|
17846
|
-
name: options.name ?? keyToDisplayName(key),
|
|
17808
|
+
id,
|
|
17809
|
+
name: options.name ?? keyToDisplayName(id),
|
|
17847
17810
|
type: "JSON",
|
|
17848
17811
|
default: options.default,
|
|
17849
17812
|
values: options.values ?? null,
|
|
@@ -17856,23 +17819,23 @@ var FlagsClient = class {
|
|
|
17856
17819
|
// ------------------------------------------------------------------
|
|
17857
17820
|
// Management: CRUD
|
|
17858
17821
|
// ------------------------------------------------------------------
|
|
17859
|
-
/** Fetch a flag by
|
|
17860
|
-
async get(
|
|
17822
|
+
/** Fetch a flag by id. */
|
|
17823
|
+
async get(id) {
|
|
17861
17824
|
let data;
|
|
17862
17825
|
try {
|
|
17863
|
-
const result = await this._http.GET("/api/v1/flags", {
|
|
17864
|
-
params: {
|
|
17826
|
+
const result = await this._http.GET("/api/v1/flags/{id}", {
|
|
17827
|
+
params: { path: { id } }
|
|
17865
17828
|
});
|
|
17866
17829
|
if (result.error !== void 0)
|
|
17867
|
-
await checkError2(result.response, `Flag with
|
|
17830
|
+
await checkError2(result.response, `Flag with id '${id}' not found`);
|
|
17868
17831
|
data = result.data;
|
|
17869
17832
|
} catch (err) {
|
|
17870
17833
|
wrapFetchError2(err);
|
|
17871
17834
|
}
|
|
17872
|
-
if (!data || !data.data
|
|
17873
|
-
throw new SmplNotFoundError(`Flag with
|
|
17835
|
+
if (!data || !data.data) {
|
|
17836
|
+
throw new SmplNotFoundError(`Flag with id '${id}' not found`);
|
|
17874
17837
|
}
|
|
17875
|
-
return this._resourceToModel(data.data
|
|
17838
|
+
return this._resourceToModel(data.data);
|
|
17876
17839
|
}
|
|
17877
17840
|
/** List all flags. */
|
|
17878
17841
|
async list() {
|
|
@@ -17887,15 +17850,14 @@ var FlagsClient = class {
|
|
|
17887
17850
|
if (!data) return [];
|
|
17888
17851
|
return data.data.map((r) => this._resourceToModel(r));
|
|
17889
17852
|
}
|
|
17890
|
-
/** Delete a flag by
|
|
17891
|
-
async delete(
|
|
17892
|
-
const flag = await this.get(key);
|
|
17853
|
+
/** Delete a flag by id. */
|
|
17854
|
+
async delete(id) {
|
|
17893
17855
|
try {
|
|
17894
17856
|
const result = await this._http.DELETE("/api/v1/flags/{id}", {
|
|
17895
|
-
params: { path: { id
|
|
17857
|
+
params: { path: { id } }
|
|
17896
17858
|
});
|
|
17897
17859
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
17898
|
-
await checkError2(result.response, `Failed to delete flag '${
|
|
17860
|
+
await checkError2(result.response, `Failed to delete flag '${id}'`);
|
|
17899
17861
|
} catch (err) {
|
|
17900
17862
|
wrapFetchError2(err);
|
|
17901
17863
|
}
|
|
@@ -17907,9 +17869,9 @@ var FlagsClient = class {
|
|
|
17907
17869
|
async _createFlag(flag) {
|
|
17908
17870
|
const body = {
|
|
17909
17871
|
data: {
|
|
17872
|
+
id: flag.id,
|
|
17910
17873
|
type: "flag",
|
|
17911
17874
|
attributes: {
|
|
17912
|
-
key: flag.key,
|
|
17913
17875
|
name: flag.name,
|
|
17914
17876
|
description: flag.description ?? "",
|
|
17915
17877
|
type: flag.type,
|
|
@@ -17936,7 +17898,6 @@ var FlagsClient = class {
|
|
|
17936
17898
|
data: {
|
|
17937
17899
|
type: "flag",
|
|
17938
17900
|
attributes: {
|
|
17939
|
-
key: flag.key,
|
|
17940
17901
|
name: flag.name,
|
|
17941
17902
|
type: flag.type,
|
|
17942
17903
|
default: flag.default,
|
|
@@ -17965,11 +17926,10 @@ var FlagsClient = class {
|
|
|
17965
17926
|
// Runtime: typed flag handles
|
|
17966
17927
|
// ------------------------------------------------------------------
|
|
17967
17928
|
/** Declare a boolean flag handle for runtime evaluation. */
|
|
17968
|
-
booleanFlag(
|
|
17929
|
+
booleanFlag(id, defaultValue) {
|
|
17969
17930
|
const handle = new BooleanFlag(this, {
|
|
17970
|
-
id
|
|
17971
|
-
|
|
17972
|
-
name: key,
|
|
17931
|
+
id,
|
|
17932
|
+
name: id,
|
|
17973
17933
|
type: "BOOLEAN",
|
|
17974
17934
|
default: defaultValue,
|
|
17975
17935
|
values: [],
|
|
@@ -17978,15 +17938,14 @@ var FlagsClient = class {
|
|
|
17978
17938
|
createdAt: null,
|
|
17979
17939
|
updatedAt: null
|
|
17980
17940
|
});
|
|
17981
|
-
this._handles[
|
|
17941
|
+
this._handles[id] = handle;
|
|
17982
17942
|
return handle;
|
|
17983
17943
|
}
|
|
17984
17944
|
/** Declare a string flag handle for runtime evaluation. */
|
|
17985
|
-
stringFlag(
|
|
17945
|
+
stringFlag(id, defaultValue) {
|
|
17986
17946
|
const handle = new StringFlag(this, {
|
|
17987
|
-
id
|
|
17988
|
-
|
|
17989
|
-
name: key,
|
|
17947
|
+
id,
|
|
17948
|
+
name: id,
|
|
17990
17949
|
type: "STRING",
|
|
17991
17950
|
default: defaultValue,
|
|
17992
17951
|
values: [],
|
|
@@ -17995,15 +17954,14 @@ var FlagsClient = class {
|
|
|
17995
17954
|
createdAt: null,
|
|
17996
17955
|
updatedAt: null
|
|
17997
17956
|
});
|
|
17998
|
-
this._handles[
|
|
17957
|
+
this._handles[id] = handle;
|
|
17999
17958
|
return handle;
|
|
18000
17959
|
}
|
|
18001
17960
|
/** Declare a numeric flag handle for runtime evaluation. */
|
|
18002
|
-
numberFlag(
|
|
17961
|
+
numberFlag(id, defaultValue) {
|
|
18003
17962
|
const handle = new NumberFlag(this, {
|
|
18004
|
-
id
|
|
18005
|
-
|
|
18006
|
-
name: key,
|
|
17963
|
+
id,
|
|
17964
|
+
name: id,
|
|
18007
17965
|
type: "NUMERIC",
|
|
18008
17966
|
default: defaultValue,
|
|
18009
17967
|
values: [],
|
|
@@ -18012,15 +17970,14 @@ var FlagsClient = class {
|
|
|
18012
17970
|
createdAt: null,
|
|
18013
17971
|
updatedAt: null
|
|
18014
17972
|
});
|
|
18015
|
-
this._handles[
|
|
17973
|
+
this._handles[id] = handle;
|
|
18016
17974
|
return handle;
|
|
18017
17975
|
}
|
|
18018
17976
|
/** Declare a JSON flag handle for runtime evaluation. */
|
|
18019
|
-
jsonFlag(
|
|
17977
|
+
jsonFlag(id, defaultValue) {
|
|
18020
17978
|
const handle = new JsonFlag(this, {
|
|
18021
|
-
id
|
|
18022
|
-
|
|
18023
|
-
name: key,
|
|
17979
|
+
id,
|
|
17980
|
+
name: id,
|
|
18024
17981
|
type: "JSON",
|
|
18025
17982
|
default: defaultValue,
|
|
18026
17983
|
values: [],
|
|
@@ -18029,7 +17986,7 @@ var FlagsClient = class {
|
|
|
18029
17986
|
createdAt: null,
|
|
18030
17987
|
updatedAt: null
|
|
18031
17988
|
});
|
|
18032
|
-
this._handles[
|
|
17989
|
+
this._handles[id] = handle;
|
|
18033
17990
|
return handle;
|
|
18034
17991
|
}
|
|
18035
17992
|
// ------------------------------------------------------------------
|
|
@@ -18106,20 +18063,20 @@ var FlagsClient = class {
|
|
|
18106
18063
|
* Register a change listener.
|
|
18107
18064
|
*
|
|
18108
18065
|
* - `onChange(callback)` — fires for any flag change.
|
|
18109
|
-
* - `onChange(
|
|
18066
|
+
* - `onChange(id, callback)` — fires only for the specified flag id.
|
|
18110
18067
|
*/
|
|
18111
|
-
onChange(
|
|
18112
|
-
if (typeof
|
|
18113
|
-
this._globalListeners.push(
|
|
18068
|
+
onChange(callbackOrId, callback) {
|
|
18069
|
+
if (typeof callbackOrId === "function") {
|
|
18070
|
+
this._globalListeners.push(callbackOrId);
|
|
18114
18071
|
} else {
|
|
18115
|
-
const
|
|
18072
|
+
const id = callbackOrId;
|
|
18116
18073
|
if (!callback) {
|
|
18117
|
-
throw new SmplError("onChange(
|
|
18074
|
+
throw new SmplError("onChange(id, callback) requires a callback function.");
|
|
18118
18075
|
}
|
|
18119
|
-
if (!this._keyListeners.has(
|
|
18120
|
-
this._keyListeners.set(
|
|
18076
|
+
if (!this._keyListeners.has(id)) {
|
|
18077
|
+
this._keyListeners.set(id, []);
|
|
18121
18078
|
}
|
|
18122
|
-
this._keyListeners.get(
|
|
18079
|
+
this._keyListeners.get(id).push(callback);
|
|
18123
18080
|
}
|
|
18124
18081
|
}
|
|
18125
18082
|
// ------------------------------------------------------------------
|
|
@@ -18147,18 +18104,18 @@ var FlagsClient = class {
|
|
|
18147
18104
|
/**
|
|
18148
18105
|
* Evaluate a flag with an explicit environment and context.
|
|
18149
18106
|
*/
|
|
18150
|
-
async evaluate(
|
|
18107
|
+
async evaluate(id, options) {
|
|
18151
18108
|
const evalDict = contextsToEvalDict(options.context);
|
|
18152
18109
|
if (this._parent?._service && !("service" in evalDict)) {
|
|
18153
18110
|
evalDict["service"] = { key: this._parent._service };
|
|
18154
18111
|
}
|
|
18155
18112
|
let flagDef = null;
|
|
18156
|
-
if (this._initialized &&
|
|
18157
|
-
flagDef = this._flagStore[
|
|
18113
|
+
if (this._initialized && id in this._flagStore) {
|
|
18114
|
+
flagDef = this._flagStore[id];
|
|
18158
18115
|
} else {
|
|
18159
18116
|
const flags = await this._fetchFlagsList();
|
|
18160
18117
|
for (const f of flags) {
|
|
18161
|
-
if (f.
|
|
18118
|
+
if (f.id === id) {
|
|
18162
18119
|
flagDef = f;
|
|
18163
18120
|
break;
|
|
18164
18121
|
}
|
|
@@ -18238,17 +18195,17 @@ var FlagsClient = class {
|
|
|
18238
18195
|
// Internal: event handlers (called by SharedWebSocket)
|
|
18239
18196
|
// ------------------------------------------------------------------
|
|
18240
18197
|
_handleFlagChanged = (data) => {
|
|
18241
|
-
const
|
|
18198
|
+
const flagId = data.id;
|
|
18242
18199
|
void this._fetchAllFlags().then(() => {
|
|
18243
18200
|
this._cache.clear();
|
|
18244
|
-
this._fireChangeListeners(
|
|
18201
|
+
this._fireChangeListeners(flagId ?? null, "websocket");
|
|
18245
18202
|
});
|
|
18246
18203
|
};
|
|
18247
18204
|
_handleFlagDeleted = (data) => {
|
|
18248
|
-
const
|
|
18205
|
+
const flagId = data.id;
|
|
18249
18206
|
void this._fetchAllFlags().then(() => {
|
|
18250
18207
|
this._cache.clear();
|
|
18251
|
-
this._fireChangeListeners(
|
|
18208
|
+
this._fireChangeListeners(flagId ?? null, "websocket");
|
|
18252
18209
|
});
|
|
18253
18210
|
};
|
|
18254
18211
|
// ------------------------------------------------------------------
|
|
@@ -18258,7 +18215,7 @@ var FlagsClient = class {
|
|
|
18258
18215
|
const flags = await this._fetchFlagsList();
|
|
18259
18216
|
const store = {};
|
|
18260
18217
|
for (const f of flags) {
|
|
18261
|
-
store[f.
|
|
18218
|
+
store[f.id] = f;
|
|
18262
18219
|
}
|
|
18263
18220
|
this._flagStore = store;
|
|
18264
18221
|
}
|
|
@@ -18277,18 +18234,18 @@ var FlagsClient = class {
|
|
|
18277
18234
|
// ------------------------------------------------------------------
|
|
18278
18235
|
// Internal: change listeners
|
|
18279
18236
|
// ------------------------------------------------------------------
|
|
18280
|
-
_fireChangeListeners(
|
|
18281
|
-
if (
|
|
18282
|
-
const event = new FlagChangeEvent(
|
|
18237
|
+
_fireChangeListeners(flagId, source) {
|
|
18238
|
+
if (flagId) {
|
|
18239
|
+
const event = new FlagChangeEvent(flagId, source);
|
|
18283
18240
|
for (const cb of this._globalListeners) {
|
|
18284
18241
|
try {
|
|
18285
18242
|
cb(event);
|
|
18286
18243
|
} catch {
|
|
18287
18244
|
}
|
|
18288
18245
|
}
|
|
18289
|
-
const
|
|
18290
|
-
if (
|
|
18291
|
-
for (const cb of
|
|
18246
|
+
const idCallbacks = this._keyListeners.get(flagId);
|
|
18247
|
+
if (idCallbacks) {
|
|
18248
|
+
for (const cb of idCallbacks) {
|
|
18292
18249
|
try {
|
|
18293
18250
|
cb(event);
|
|
18294
18251
|
} catch {
|
|
@@ -18298,8 +18255,8 @@ var FlagsClient = class {
|
|
|
18298
18255
|
}
|
|
18299
18256
|
}
|
|
18300
18257
|
_fireChangeListenersAll(source) {
|
|
18301
|
-
for (const
|
|
18302
|
-
this._fireChangeListeners(
|
|
18258
|
+
for (const flagId of Object.keys(this._flagStore)) {
|
|
18259
|
+
this._fireChangeListeners(flagId, source);
|
|
18303
18260
|
}
|
|
18304
18261
|
}
|
|
18305
18262
|
// ------------------------------------------------------------------
|
|
@@ -18329,7 +18286,6 @@ var FlagsClient = class {
|
|
|
18329
18286
|
const attrs = resource.attributes;
|
|
18330
18287
|
return new Flag(this, {
|
|
18331
18288
|
id: resource.id ?? null,
|
|
18332
|
-
key: attrs.key,
|
|
18333
18289
|
name: attrs.name,
|
|
18334
18290
|
type: attrs.type,
|
|
18335
18291
|
default: attrs.default,
|
|
@@ -18343,7 +18299,7 @@ var FlagsClient = class {
|
|
|
18343
18299
|
_resourceToPlainDict(resource) {
|
|
18344
18300
|
const attrs = resource.attributes;
|
|
18345
18301
|
return {
|
|
18346
|
-
|
|
18302
|
+
id: resource.id ?? null,
|
|
18347
18303
|
name: attrs.name,
|
|
18348
18304
|
type: attrs.type,
|
|
18349
18305
|
default: attrs.default,
|
|
@@ -18359,15 +18315,13 @@ var import_openapi_fetch3 = __toESM(require("openapi-fetch"), 1);
|
|
|
18359
18315
|
|
|
18360
18316
|
// src/logging/models.ts
|
|
18361
18317
|
var Logger = class {
|
|
18362
|
-
/**
|
|
18318
|
+
/** Unique identifier (dot-separated hierarchy, e.g. `"sqlalchemy.engine"`). */
|
|
18363
18319
|
id;
|
|
18364
|
-
/** Unique key (dot-separated hierarchy). */
|
|
18365
|
-
key;
|
|
18366
18320
|
/** Human-readable display name. */
|
|
18367
18321
|
name;
|
|
18368
18322
|
/** Base log level, or null if inherited. */
|
|
18369
18323
|
level;
|
|
18370
|
-
/**
|
|
18324
|
+
/** Id of the parent log group, or null. */
|
|
18371
18325
|
group;
|
|
18372
18326
|
/** Whether this logger is managed by the platform. */
|
|
18373
18327
|
managed;
|
|
@@ -18385,7 +18339,6 @@ var Logger = class {
|
|
|
18385
18339
|
constructor(client, fields) {
|
|
18386
18340
|
this._client = client;
|
|
18387
18341
|
this.id = fields.id;
|
|
18388
|
-
this.key = fields.key;
|
|
18389
18342
|
this.name = fields.name;
|
|
18390
18343
|
this.level = fields.level;
|
|
18391
18344
|
this.group = fields.group;
|
|
@@ -18435,7 +18388,6 @@ var Logger = class {
|
|
|
18435
18388
|
/** @internal — copy all fields from another Logger instance. */
|
|
18436
18389
|
_apply(other) {
|
|
18437
18390
|
this.id = other.id;
|
|
18438
|
-
this.key = other.key;
|
|
18439
18391
|
this.name = other.name;
|
|
18440
18392
|
this.level = other.level;
|
|
18441
18393
|
this.group = other.group;
|
|
@@ -18446,19 +18398,17 @@ var Logger = class {
|
|
|
18446
18398
|
this.updatedAt = other.updatedAt;
|
|
18447
18399
|
}
|
|
18448
18400
|
toString() {
|
|
18449
|
-
return `Logger(
|
|
18401
|
+
return `Logger(id=${this.id}, level=${this.level})`;
|
|
18450
18402
|
}
|
|
18451
18403
|
};
|
|
18452
18404
|
var LogGroup = class {
|
|
18453
|
-
/**
|
|
18405
|
+
/** Unique identifier (slug), or `null` if unsaved. */
|
|
18454
18406
|
id;
|
|
18455
|
-
/** Unique key. */
|
|
18456
|
-
key;
|
|
18457
18407
|
/** Human-readable display name. */
|
|
18458
18408
|
name;
|
|
18459
18409
|
/** Base log level, or null if inherited. */
|
|
18460
18410
|
level;
|
|
18461
|
-
/**
|
|
18411
|
+
/** Id of the parent log group, or null. */
|
|
18462
18412
|
group;
|
|
18463
18413
|
/** Per-environment level overrides. */
|
|
18464
18414
|
environments;
|
|
@@ -18472,7 +18422,6 @@ var LogGroup = class {
|
|
|
18472
18422
|
constructor(client, fields) {
|
|
18473
18423
|
this._client = client;
|
|
18474
18424
|
this.id = fields.id;
|
|
18475
|
-
this.key = fields.key;
|
|
18476
18425
|
this.name = fields.name;
|
|
18477
18426
|
this.level = fields.level;
|
|
18478
18427
|
this.group = fields.group;
|
|
@@ -18520,7 +18469,6 @@ var LogGroup = class {
|
|
|
18520
18469
|
/** @internal — copy all fields from another LogGroup instance. */
|
|
18521
18470
|
_apply(other) {
|
|
18522
18471
|
this.id = other.id;
|
|
18523
|
-
this.key = other.key;
|
|
18524
18472
|
this.name = other.name;
|
|
18525
18473
|
this.level = other.level;
|
|
18526
18474
|
this.group = other.group;
|
|
@@ -18529,7 +18477,7 @@ var LogGroup = class {
|
|
|
18529
18477
|
this.updatedAt = other.updatedAt;
|
|
18530
18478
|
}
|
|
18531
18479
|
toString() {
|
|
18532
|
-
return `LogGroup(
|
|
18480
|
+
return `LogGroup(id=${this.id}, level=${this.level})`;
|
|
18533
18481
|
}
|
|
18534
18482
|
};
|
|
18535
18483
|
|
|
@@ -18613,11 +18561,10 @@ var LoggingClient = class {
|
|
|
18613
18561
|
// Management: Logger factory
|
|
18614
18562
|
// ------------------------------------------------------------------
|
|
18615
18563
|
/** Create an unsaved logger. Call `.save()` to persist. */
|
|
18616
|
-
new(
|
|
18564
|
+
new(id, options) {
|
|
18617
18565
|
return new Logger(this, {
|
|
18618
|
-
id
|
|
18619
|
-
|
|
18620
|
-
name: options?.name ?? keyToDisplayName(key),
|
|
18566
|
+
id,
|
|
18567
|
+
name: options?.name ?? keyToDisplayName(id),
|
|
18621
18568
|
level: null,
|
|
18622
18569
|
group: null,
|
|
18623
18570
|
managed: options?.managed ?? false,
|
|
@@ -18630,23 +18577,23 @@ var LoggingClient = class {
|
|
|
18630
18577
|
// ------------------------------------------------------------------
|
|
18631
18578
|
// Management: Logger CRUD
|
|
18632
18579
|
// ------------------------------------------------------------------
|
|
18633
|
-
/** Fetch a logger by
|
|
18634
|
-
async get(
|
|
18580
|
+
/** Fetch a logger by id. */
|
|
18581
|
+
async get(id) {
|
|
18635
18582
|
let data;
|
|
18636
18583
|
try {
|
|
18637
|
-
const result = await this._http.GET("/api/v1/loggers", {
|
|
18638
|
-
params: {
|
|
18584
|
+
const result = await this._http.GET("/api/v1/loggers/{id}", {
|
|
18585
|
+
params: { path: { id } }
|
|
18639
18586
|
});
|
|
18640
18587
|
if (result.error !== void 0)
|
|
18641
|
-
await checkError3(result.response, `Logger with
|
|
18588
|
+
await checkError3(result.response, `Logger with id '${id}' not found`);
|
|
18642
18589
|
data = result.data;
|
|
18643
18590
|
} catch (err) {
|
|
18644
18591
|
wrapFetchError3(err);
|
|
18645
18592
|
}
|
|
18646
|
-
if (!data || !data.data
|
|
18647
|
-
throw new SmplNotFoundError(`Logger with
|
|
18593
|
+
if (!data || !data.data) {
|
|
18594
|
+
throw new SmplNotFoundError(`Logger with id '${id}' not found`);
|
|
18648
18595
|
}
|
|
18649
|
-
return this._loggerToModel(data.data
|
|
18596
|
+
return this._loggerToModel(data.data);
|
|
18650
18597
|
}
|
|
18651
18598
|
/** List all loggers. */
|
|
18652
18599
|
async list() {
|
|
@@ -18661,15 +18608,14 @@ var LoggingClient = class {
|
|
|
18661
18608
|
if (!data) return [];
|
|
18662
18609
|
return data.data.map((r) => this._loggerToModel(r));
|
|
18663
18610
|
}
|
|
18664
|
-
/** Delete a logger by
|
|
18665
|
-
async delete(
|
|
18666
|
-
const logger = await this.get(key);
|
|
18611
|
+
/** Delete a logger by id. */
|
|
18612
|
+
async delete(id) {
|
|
18667
18613
|
try {
|
|
18668
18614
|
const result = await this._http.DELETE("/api/v1/loggers/{id}", {
|
|
18669
|
-
params: { path: { id
|
|
18615
|
+
params: { path: { id } }
|
|
18670
18616
|
});
|
|
18671
18617
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
18672
|
-
await checkError3(result.response, `Failed to delete logger '${
|
|
18618
|
+
await checkError3(result.response, `Failed to delete logger '${id}'`);
|
|
18673
18619
|
} catch (err) {
|
|
18674
18620
|
wrapFetchError3(err);
|
|
18675
18621
|
}
|
|
@@ -18678,11 +18624,10 @@ var LoggingClient = class {
|
|
|
18678
18624
|
// Management: LogGroup factory
|
|
18679
18625
|
// ------------------------------------------------------------------
|
|
18680
18626
|
/** Create an unsaved log group. Call `.save()` to persist. */
|
|
18681
|
-
newGroup(
|
|
18627
|
+
newGroup(id, options) {
|
|
18682
18628
|
return new LogGroup(this, {
|
|
18683
|
-
id
|
|
18684
|
-
|
|
18685
|
-
name: options?.name ?? keyToDisplayName(key),
|
|
18629
|
+
id,
|
|
18630
|
+
name: options?.name ?? keyToDisplayName(id),
|
|
18686
18631
|
level: null,
|
|
18687
18632
|
group: options?.group ?? null,
|
|
18688
18633
|
environments: {},
|
|
@@ -18693,12 +18638,12 @@ var LoggingClient = class {
|
|
|
18693
18638
|
// ------------------------------------------------------------------
|
|
18694
18639
|
// Management: LogGroup CRUD
|
|
18695
18640
|
// ------------------------------------------------------------------
|
|
18696
|
-
/** Fetch a log group by
|
|
18697
|
-
async getGroup(
|
|
18641
|
+
/** Fetch a log group by id. */
|
|
18642
|
+
async getGroup(id) {
|
|
18698
18643
|
const groups = await this.listGroups();
|
|
18699
|
-
const match = groups.find((g) => g.
|
|
18644
|
+
const match = groups.find((g) => g.id === id);
|
|
18700
18645
|
if (!match) {
|
|
18701
|
-
throw new SmplNotFoundError(`LogGroup with
|
|
18646
|
+
throw new SmplNotFoundError(`LogGroup with id '${id}' not found`);
|
|
18702
18647
|
}
|
|
18703
18648
|
return match;
|
|
18704
18649
|
}
|
|
@@ -18716,15 +18661,15 @@ var LoggingClient = class {
|
|
|
18716
18661
|
if (!data) return [];
|
|
18717
18662
|
return data.data.map((r) => this._groupToModel(r));
|
|
18718
18663
|
}
|
|
18719
|
-
/** Delete a log group by
|
|
18720
|
-
async deleteGroup(
|
|
18721
|
-
const group = await this.getGroup(
|
|
18664
|
+
/** Delete a log group by id. */
|
|
18665
|
+
async deleteGroup(id) {
|
|
18666
|
+
const group = await this.getGroup(id);
|
|
18722
18667
|
try {
|
|
18723
18668
|
const result = await this._http.DELETE("/api/v1/log_groups/{id}", {
|
|
18724
18669
|
params: { path: { id: group.id } }
|
|
18725
18670
|
});
|
|
18726
18671
|
if (result.error !== void 0 && result.response.status !== 204)
|
|
18727
|
-
await checkError3(result.response, `Failed to delete log group '${
|
|
18672
|
+
await checkError3(result.response, `Failed to delete log group '${id}'`);
|
|
18728
18673
|
} catch (err) {
|
|
18729
18674
|
wrapFetchError3(err);
|
|
18730
18675
|
}
|
|
@@ -18736,9 +18681,9 @@ var LoggingClient = class {
|
|
|
18736
18681
|
async _saveLogger(logger) {
|
|
18737
18682
|
const body = {
|
|
18738
18683
|
data: {
|
|
18684
|
+
id: logger.id,
|
|
18739
18685
|
type: "logger",
|
|
18740
18686
|
attributes: {
|
|
18741
|
-
key: logger.key,
|
|
18742
18687
|
name: logger.name,
|
|
18743
18688
|
level: logger.level,
|
|
18744
18689
|
group: logger.group,
|
|
@@ -18747,7 +18692,7 @@ var LoggingClient = class {
|
|
|
18747
18692
|
}
|
|
18748
18693
|
}
|
|
18749
18694
|
};
|
|
18750
|
-
if (logger.
|
|
18695
|
+
if (logger.createdAt === null) {
|
|
18751
18696
|
let data;
|
|
18752
18697
|
try {
|
|
18753
18698
|
const result = await this._http.POST("/api/v1/loggers", { body });
|
|
@@ -18781,9 +18726,9 @@ var LoggingClient = class {
|
|
|
18781
18726
|
async _saveLogGroup(group) {
|
|
18782
18727
|
const body = {
|
|
18783
18728
|
data: {
|
|
18729
|
+
id: group.id,
|
|
18784
18730
|
type: "log_group",
|
|
18785
18731
|
attributes: {
|
|
18786
|
-
key: group.key,
|
|
18787
18732
|
name: group.name,
|
|
18788
18733
|
level: group.level,
|
|
18789
18734
|
group: group.group,
|
|
@@ -18791,7 +18736,7 @@ var LoggingClient = class {
|
|
|
18791
18736
|
}
|
|
18792
18737
|
}
|
|
18793
18738
|
};
|
|
18794
|
-
if (group.
|
|
18739
|
+
if (group.createdAt === null) {
|
|
18795
18740
|
let data;
|
|
18796
18741
|
try {
|
|
18797
18742
|
const result = await this._http.POST("/api/v1/log_groups", { body });
|
|
@@ -18882,20 +18827,20 @@ var LoggingClient = class {
|
|
|
18882
18827
|
* Register a change listener.
|
|
18883
18828
|
*
|
|
18884
18829
|
* - `onChange(callback)` — fires for any logger change.
|
|
18885
|
-
* - `onChange(
|
|
18830
|
+
* - `onChange(id, callback)` — fires only for the specified logger id.
|
|
18886
18831
|
*/
|
|
18887
|
-
onChange(
|
|
18888
|
-
if (typeof
|
|
18889
|
-
this._globalListeners.push(
|
|
18832
|
+
onChange(callbackOrId, callback) {
|
|
18833
|
+
if (typeof callbackOrId === "function") {
|
|
18834
|
+
this._globalListeners.push(callbackOrId);
|
|
18890
18835
|
} else {
|
|
18891
|
-
const
|
|
18836
|
+
const id = callbackOrId;
|
|
18892
18837
|
if (!callback) {
|
|
18893
|
-
throw new SmplError("onChange(
|
|
18838
|
+
throw new SmplError("onChange(id, callback) requires a callback function.");
|
|
18894
18839
|
}
|
|
18895
|
-
if (!this._keyListeners.has(
|
|
18896
|
-
this._keyListeners.set(
|
|
18840
|
+
if (!this._keyListeners.has(id)) {
|
|
18841
|
+
this._keyListeners.set(id, []);
|
|
18897
18842
|
}
|
|
18898
|
-
this._keyListeners.get(
|
|
18843
|
+
this._keyListeners.get(id).push(callback);
|
|
18899
18844
|
}
|
|
18900
18845
|
}
|
|
18901
18846
|
// ------------------------------------------------------------------
|
|
@@ -18954,11 +18899,11 @@ var LoggingClient = class {
|
|
|
18954
18899
|
}
|
|
18955
18900
|
const metrics = this._parent?._metrics;
|
|
18956
18901
|
if (metrics) {
|
|
18957
|
-
metrics.record("logging.level_changes", 1, "changes", { logger_id: logger.
|
|
18902
|
+
metrics.record("logging.level_changes", 1, "changes", { logger_id: logger.id });
|
|
18958
18903
|
}
|
|
18959
18904
|
for (const adapter of this._adapters) {
|
|
18960
18905
|
try {
|
|
18961
|
-
adapter.applyLevel(logger.
|
|
18906
|
+
adapter.applyLevel(logger.id, effectiveLevel);
|
|
18962
18907
|
} catch {
|
|
18963
18908
|
}
|
|
18964
18909
|
}
|
|
@@ -18975,11 +18920,11 @@ var LoggingClient = class {
|
|
|
18975
18920
|
// Internal: WebSocket handler
|
|
18976
18921
|
// ------------------------------------------------------------------
|
|
18977
18922
|
_handleLoggerChanged = (data) => {
|
|
18978
|
-
const
|
|
18979
|
-
if (
|
|
18923
|
+
const id = data.id;
|
|
18924
|
+
if (id) {
|
|
18980
18925
|
const level = data.level ?? null;
|
|
18981
18926
|
const event = {
|
|
18982
|
-
|
|
18927
|
+
id,
|
|
18983
18928
|
level,
|
|
18984
18929
|
source: "websocket"
|
|
18985
18930
|
};
|
|
@@ -18989,9 +18934,9 @@ var LoggingClient = class {
|
|
|
18989
18934
|
} catch {
|
|
18990
18935
|
}
|
|
18991
18936
|
}
|
|
18992
|
-
const
|
|
18993
|
-
if (
|
|
18994
|
-
for (const cb of
|
|
18937
|
+
const idCallbacks = this._keyListeners.get(id);
|
|
18938
|
+
if (idCallbacks) {
|
|
18939
|
+
for (const cb of idCallbacks) {
|
|
18995
18940
|
try {
|
|
18996
18941
|
cb(event);
|
|
18997
18942
|
} catch {
|
|
@@ -19007,7 +18952,6 @@ var LoggingClient = class {
|
|
|
19007
18952
|
const attrs = resource.attributes;
|
|
19008
18953
|
return new Logger(this, {
|
|
19009
18954
|
id: resource.id ?? null,
|
|
19010
|
-
key: attrs.key ?? "",
|
|
19011
18955
|
name: attrs.name,
|
|
19012
18956
|
level: attrs.level ?? null,
|
|
19013
18957
|
group: attrs.group ?? null,
|
|
@@ -19022,7 +18966,6 @@ var LoggingClient = class {
|
|
|
19022
18966
|
const attrs = resource.attributes;
|
|
19023
18967
|
return new LogGroup(this, {
|
|
19024
18968
|
id: resource.id ?? null,
|
|
19025
|
-
key: attrs.key ?? "",
|
|
19026
18969
|
name: attrs.name,
|
|
19027
18970
|
level: attrs.level ?? null,
|
|
19028
18971
|
group: attrs.group ?? null,
|