@smplkit/sdk 3.0.83 → 3.0.85

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.js CHANGED
@@ -16697,9 +16697,11 @@ function parseJsonApiErrors(body) {
16697
16697
  if (parsed && Array.isArray(parsed.errors)) {
16698
16698
  return parsed.errors.map((e) => ({
16699
16699
  ...e.status !== void 0 ? { status: String(e.status) } : {},
16700
+ ...e.code !== void 0 ? { code: String(e.code) } : {},
16700
16701
  ...e.title !== void 0 ? { title: String(e.title) } : {},
16701
16702
  ...e.detail !== void 0 ? { detail: String(e.detail) } : {},
16702
- ...e.source !== void 0 && typeof e.source === "object" && e.source !== null ? { source: e.source } : {}
16703
+ ...e.source !== void 0 && typeof e.source === "object" && e.source !== null ? { source: e.source } : {},
16704
+ ...e.meta !== void 0 && typeof e.meta === "object" && e.meta !== null ? { meta: e.meta } : {}
16703
16705
  }));
16704
16706
  }
16705
16707
  } catch {
@@ -17414,47 +17416,15 @@ var Config = class {
17414
17416
  };
17415
17417
 
17416
17418
  // src/config/proxy.ts
17417
- function _unflattenDotNotation(flat) {
17418
- const nested = {};
17419
- for (const [key, value] of Object.entries(flat)) {
17420
- const parts = key.split(".");
17421
- let current = nested;
17422
- for (let i = 0; i < parts.length - 1; i++) {
17423
- const part = parts[i];
17424
- if (current[part] === void 0 || typeof current[part] !== "object" || current[part] === null) {
17425
- current[part] = {};
17426
- }
17427
- current = current[part];
17428
- }
17429
- current[parts[parts.length - 1]] = value;
17430
- }
17431
- return nested;
17432
- }
17433
17419
  var LiveConfigProxy = class {
17434
17420
  /** @internal */
17435
17421
  _client;
17436
17422
  /** @internal */
17437
17423
  _key;
17438
- /** @internal */
17439
- _model;
17440
- constructor(client, key, model) {
17424
+ constructor(client, key) {
17441
17425
  this._client = client;
17442
17426
  this._key = key;
17443
- this._model = model;
17444
- const ownMethods = /* @__PURE__ */ new Set([
17445
- "keys",
17446
- "values",
17447
- "items",
17448
- "get",
17449
- "onChange",
17450
- "getBool",
17451
- "getInt",
17452
- "getFloat",
17453
- "getString",
17454
- "getJson",
17455
- "_currentValues",
17456
- "_registerItem"
17457
- ]);
17427
+ const ownMethods = /* @__PURE__ */ new Set(["keys", "values", "items", "get", "onChange", "_currentValues"]);
17458
17428
  return new Proxy(this, {
17459
17429
  get(target, prop, receiver) {
17460
17430
  if (typeof prop === "symbol" || prop === "constructor" || prop === "toJSON") {
@@ -17464,17 +17434,9 @@ var LiveConfigProxy = class {
17464
17434
  return Reflect.get(target, prop, receiver);
17465
17435
  }
17466
17436
  const values = target._currentValues();
17467
- if (target._model) {
17468
- const nested = _unflattenDotNotation(values);
17469
- const instance = new target._model(nested);
17470
- return instance[prop];
17471
- }
17472
17437
  return values[prop];
17473
17438
  },
17474
- set(target, prop, value, receiver) {
17475
- if (typeof prop === "string" && prop.startsWith("_")) {
17476
- return Reflect.set(target, prop, value, receiver);
17477
- }
17439
+ set(_target, prop) {
17478
17440
  throw new Error(
17479
17441
  `LiveConfigProxy is read-only; cannot set ${JSON.stringify(String(prop))}. Mutate config values via client.manage.config.*`
17480
17442
  );
@@ -17529,74 +17491,6 @@ var LiveConfigProxy = class {
17529
17491
  const values = this._currentValues();
17530
17492
  return key in values ? values[key] : defaultValue;
17531
17493
  }
17532
- // ------------------------------------------------------------------
17533
- // Typed getters (ADR-037 §2.13)
17534
- //
17535
- // Each registers the item (key, type, default, description) on first
17536
- // call within the process, then returns the resolved value. When the
17537
- // resolved value cannot be coerced to the getter's type — including
17538
- // the "not yet set on the server" case — the in-code default is
17539
- // returned and a structured warning is logged.
17540
- // ------------------------------------------------------------------
17541
- /** @internal */
17542
- _registerItem(itemKey, itemType, defaultValue, description) {
17543
- this._client._observeItemDeclaration(this._key, itemKey, itemType, defaultValue, description);
17544
- }
17545
- /** Read a BOOLEAN item, registering the declaration on first call. */
17546
- getBool(key, defaultValue, options = {}) {
17547
- this._registerItem(key, "BOOLEAN", defaultValue, options.description);
17548
- const values = this._currentValues();
17549
- if (!(key in values)) return defaultValue;
17550
- const value = values[key];
17551
- if (typeof value === "boolean") return value;
17552
- console.warn(
17553
- `[smplkit] config ${JSON.stringify(this._key)} item ${JSON.stringify(key)}: expected BOOLEAN, got ${typeof value}; returning default`
17554
- );
17555
- return defaultValue;
17556
- }
17557
- /** Read a NUMBER item as int, registering the declaration on first call. */
17558
- getInt(key, defaultValue, options = {}) {
17559
- this._registerItem(key, "NUMBER", defaultValue, options.description);
17560
- const values = this._currentValues();
17561
- if (!(key in values)) return defaultValue;
17562
- const value = values[key];
17563
- if (typeof value === "number" && Number.isInteger(value)) return value;
17564
- console.warn(
17565
- `[smplkit] config ${JSON.stringify(this._key)} item ${JSON.stringify(key)}: expected NUMBER (int), got ${typeof value}; returning default`
17566
- );
17567
- return defaultValue;
17568
- }
17569
- /** Read a NUMBER item as float, registering the declaration on first call. */
17570
- getFloat(key, defaultValue, options = {}) {
17571
- this._registerItem(key, "NUMBER", defaultValue, options.description);
17572
- const values = this._currentValues();
17573
- if (!(key in values)) return defaultValue;
17574
- const value = values[key];
17575
- if (typeof value === "number") return value;
17576
- console.warn(
17577
- `[smplkit] config ${JSON.stringify(this._key)} item ${JSON.stringify(key)}: expected NUMBER (float), got ${typeof value}; returning default`
17578
- );
17579
- return defaultValue;
17580
- }
17581
- /** Read a STRING item, registering the declaration on first call. */
17582
- getString(key, defaultValue, options = {}) {
17583
- this._registerItem(key, "STRING", defaultValue, options.description);
17584
- const values = this._currentValues();
17585
- if (!(key in values)) return defaultValue;
17586
- const value = values[key];
17587
- if (typeof value === "string") return value;
17588
- console.warn(
17589
- `[smplkit] config ${JSON.stringify(this._key)} item ${JSON.stringify(key)}: expected STRING, got ${typeof value}; returning default`
17590
- );
17591
- return defaultValue;
17592
- }
17593
- /** Read a JSON item, registering the declaration on first call. */
17594
- getJson(key, defaultValue, options = {}) {
17595
- this._registerItem(key, "JSON", defaultValue, options.description);
17596
- const values = this._currentValues();
17597
- if (!(key in values)) return defaultValue;
17598
- return values[key];
17599
- }
17600
17494
  onChange(callbackOrItemKey, callback) {
17601
17495
  if (typeof callbackOrItemKey === "function") {
17602
17496
  this._client.onChange(this._key, callbackOrItemKey);
@@ -17649,6 +17543,7 @@ var ConfigChangeEvent = class {
17649
17543
  }
17650
17544
  };
17651
17545
  var BASE_URL = "https://config.smplkit.com";
17546
+ var MISSING = /* @__PURE__ */ Symbol("smplkit.config.get.MISSING");
17652
17547
  function extractItemValues(items) {
17653
17548
  if (!items) return {};
17654
17549
  const result = {};
@@ -17688,6 +17583,40 @@ function resourceToConfig(resource) {
17688
17583
  updatedAt: attrs.updated_at ?? null
17689
17584
  });
17690
17585
  }
17586
+ function valueToItemType(value) {
17587
+ if (typeof value === "boolean") return "BOOLEAN";
17588
+ if (typeof value === "number") return "NUMBER";
17589
+ if (typeof value === "string") return "STRING";
17590
+ return "STRING";
17591
+ }
17592
+ function isPlainObject(value) {
17593
+ if (value === null || typeof value !== "object") return false;
17594
+ const proto = Object.getPrototypeOf(value);
17595
+ return proto === Object.prototype || proto === null;
17596
+ }
17597
+ function iterObjectItems(obj, prefix = "") {
17598
+ const out = [];
17599
+ for (const [key, value] of Object.entries(obj)) {
17600
+ const flatKey = `${prefix}${key}`;
17601
+ if (isPlainObject(value)) {
17602
+ out.push(...iterObjectItems(value, `${flatKey}.`));
17603
+ continue;
17604
+ }
17605
+ out.push([flatKey, valueToItemType(value), value]);
17606
+ }
17607
+ return out;
17608
+ }
17609
+ function applyChangeToTarget(target, dottedKey, value) {
17610
+ const parts = dottedKey.split(".");
17611
+ let current = target;
17612
+ for (let i = 0; i < parts.length - 1; i++) {
17613
+ const part = parts[i];
17614
+ if (current === null || typeof current !== "object" || !(part in current)) return;
17615
+ current = current[part];
17616
+ }
17617
+ if (current === null || typeof current !== "object") return;
17618
+ current[parts[parts.length - 1]] = value;
17619
+ }
17691
17620
  var ConfigClient = class {
17692
17621
  /** @internal */
17693
17622
  _apiKey;
@@ -17708,10 +17637,11 @@ var ConfigClient = class {
17708
17637
  * without a full re-list. Mirrors Python's `_raw_config_cache`. */
17709
17638
  _configStore = {};
17710
17639
  /** Cache of LiveConfigProxy instances by config id — ensures repeat
17711
- * `get_or_create(id)` (or `get(id)` after discovery) returns the same
17712
- * handle so callers can reference it as a parent via direct ref.
17713
- * Mirrors Python's `_proxies`. */
17640
+ * `get(id)` calls return the same handle. */
17714
17641
  _proxies = {};
17642
+ /** Bound targets (plain objects or class instances) keyed by config
17643
+ * id. WebSocket dispatch mutates these in place when values change. */
17644
+ _bindings = /* @__PURE__ */ new Map();
17715
17645
  _initialized = false;
17716
17646
  _listeners = [];
17717
17647
  /** @internal */
@@ -17744,66 +17674,126 @@ var ConfigClient = class {
17744
17674
  });
17745
17675
  }
17746
17676
  // ------------------------------------------------------------------
17747
- // Runtime: resolve and subscribe
17677
+ // Public API: bind, get
17748
17678
  // ------------------------------------------------------------------
17749
17679
  /**
17750
- * Return a live, dict-like view of the resolved values for *id*.
17680
+ * Bind an object to a config id; return the same object back, live.
17681
+ *
17682
+ * Declarative, code-first API. The object's keys are the schema; its
17683
+ * values are the in-code defaults. On first boot:
17751
17684
  *
17752
- * Without `model`, returns a {@link LiveConfigProxy} that behaves like a
17753
- * `Record<string, unknown>` (`proxy["key"]`, iteration, `proxy.items()`,
17754
- * `Object.keys(proxy)`) and updates automatically as the server pushes
17755
- * changes.
17685
+ * 1. Every leaf (recursively, through nested plain objects) is
17686
+ * registered with the server as a config item, with its value as
17687
+ * the in-code default and a type inferred from `typeof value`.
17688
+ * 2. After the SDK's cache is populated, any server-side overrides for
17689
+ * this config are applied to the bound object in place.
17756
17690
  *
17757
- * With `model`, the return value type-checks as `model` — attribute
17758
- * access (`cfg.database.host`) walks a model rebuilt from the current
17759
- * values on each read, so the customer sees the model's type signature
17760
- * in their IDE while still tracking live data.
17691
+ * On every WebSocket-delivered change thereafter the bound object is
17692
+ * mutated in place — readers of `obj.foo` and `obj["foo"]` always see
17693
+ * the current resolved value. The returned object is the same one you
17694
+ * passed in (referential identity preserved).
17761
17695
  *
17762
- * Mirrors Python's `client.config.get(id)` / `client.config.get(id, ModelCls)`.
17763
- * There is no `subscribe()` it was unified into `get()`.
17696
+ * Idempotent. Repeated calls with the same id return the originally-
17697
+ * bound object; the new `config` argument is ignored.
17698
+ *
17699
+ * **Plain object literals vs. class instances.** Plain object literals
17700
+ * (e.g., `{ a: 1, b: { c: 2 } }`) are the recommended input shape —
17701
+ * their keys are the explicit override set, and omitted keys inherit
17702
+ * from `parent`. Class instances are also accepted, but every
17703
+ * enumerable property is registered as an explicit override (there is
17704
+ * no JS equivalent of Python's `model_fields_set`); to get omit-to-
17705
+ * inherit semantics, use a plain object literal.
17706
+ *
17707
+ * @param id - The config id to register under.
17708
+ * @param config - A plain object literal (recommended) or class
17709
+ * instance carrying the in-code defaults.
17710
+ * @param options - Optional `parent`: another object previously
17711
+ * returned from a {@link bind} call. Activates parent-chain
17712
+ * inheritance for keys the caller omitted.
17713
+ * @returns The same `config` object, registered and live.
17714
+ * @throws TypeError if `config` is not an object.
17715
+ * @throws Error if `parent` was not previously bound via {@link bind}.
17764
17716
  */
17765
- async get(id, model) {
17717
+ async bind(id, config, options = {}) {
17718
+ if (config === null || typeof config !== "object") {
17719
+ throw new TypeError(`bind() requires an object; got ${typeof config}`);
17720
+ }
17721
+ const existing = this._bindings.get(id);
17722
+ if (existing !== void 0) {
17723
+ return existing;
17724
+ }
17725
+ let parentId = null;
17726
+ if (options.parent !== void 0 && options.parent !== null) {
17727
+ parentId = this._configIdFor(options.parent);
17728
+ if (parentId === null) {
17729
+ throw new Error(
17730
+ "bind(): parent must be an object previously returned from client.config.bind(). Bind the parent first."
17731
+ );
17732
+ }
17733
+ }
17734
+ const ctor = config.constructor;
17735
+ const className = typeof ctor === "function" && ctor !== Object && typeof ctor.name === "string" && ctor.name ? ctor.name : null;
17736
+ this._observeConfigDeclaration(id, parentId, className, null);
17737
+ for (const [itemKey, itemType, value] of iterObjectItems(config)) {
17738
+ this._observeItemDeclaration(id, itemKey, itemType, value, void 0);
17739
+ }
17740
+ this._bindings.set(id, config);
17741
+ await this._ensureInitialized();
17742
+ this._syncTargetFromCache(config, id);
17743
+ return config;
17744
+ }
17745
+ async get(id, key, defaultValue = MISSING) {
17766
17746
  await this._ensureInitialized();
17747
+ if (key === void 0) {
17748
+ if (!(id in this._configCache)) {
17749
+ throw new SmplNotFoundError(`Config with id '${id}' not found in cache`);
17750
+ }
17751
+ const metrics = this._parent?._metrics;
17752
+ if (metrics) {
17753
+ metrics.record("config.resolutions", 1, "resolutions", { config: id });
17754
+ }
17755
+ return this._cachedProxy(id);
17756
+ }
17757
+ const hasDefault = defaultValue !== MISSING;
17758
+ if (hasDefault) {
17759
+ this._observeConfigDeclaration(id, null, null, null);
17760
+ this._observeItemDeclaration(id, key, valueToItemType(defaultValue), defaultValue, void 0);
17761
+ }
17767
17762
  if (!(id in this._configCache)) {
17763
+ if (hasDefault) return defaultValue;
17768
17764
  throw new SmplNotFoundError(`Config with id '${id}' not found in cache`);
17769
17765
  }
17770
- const metrics = this._parent?._metrics;
17771
- if (metrics) {
17772
- metrics.record("config.resolutions", 1, "resolutions", { config: id });
17766
+ const values = this._configCache[id];
17767
+ if (!(key in values)) {
17768
+ if (hasDefault) return defaultValue;
17769
+ throw new SmplNotFoundError(`Config item '${key}' not found in config '${id}'`);
17773
17770
  }
17774
- return this._cachedProxy(id, model);
17771
+ return values[key];
17775
17772
  }
17776
- /**
17777
- * Declare a configuration from code; return a live, dict-like view.
17778
- *
17779
- * Idempotent. Repeated calls with the same `id` return the same
17780
- * {@link LiveConfigProxy} instance. The first call queues a discovery
17781
- * payload (the config and any items declared via typed getters on the
17782
- * returned handle) for upload to `POST /api/v1/configs/bulk` on next
17783
- * flush. If the config already exists server-side, `managed=true`
17784
- * configs are left untouched; `managed=false` configs receive the
17785
- * SDK's items via source-row upsert per ADR-024 §2.9.
17786
- *
17787
- * Unlike {@link get}, this method does NOT raise `NotFoundError` when
17788
- * the id is absent from the cache discovery handles that case.
17789
- *
17790
- * Mirrors Python's `client.config.get_or_create(id, ...)`.
17791
- */
17792
- async getOrCreate(id, options = {}) {
17793
- const parent = options.parent;
17794
- const parentId = parent instanceof LiveConfigProxy ? parent._key : parent ?? null;
17795
- this._observeConfigDeclaration(id, parentId, options.name ?? null, options.description ?? null);
17796
- await this._ensureInitialized();
17797
- return this._cachedProxy(id, options.model);
17773
+ // ------------------------------------------------------------------
17774
+ // Internal: binding helpers
17775
+ // ------------------------------------------------------------------
17776
+ /** @internal return the config_id this object was bound under, or null. */
17777
+ _configIdFor(target) {
17778
+ for (const [cid, bound] of this._bindings) {
17779
+ if (bound === target) return cid;
17780
+ }
17781
+ return null;
17782
+ }
17783
+ /** @internal — apply current cached values to a freshly-bound target. */
17784
+ _syncTargetFromCache(target, configId) {
17785
+ const cache = this._configCache[configId];
17786
+ if (!cache) return;
17787
+ for (const [dottedKey, value] of Object.entries(cache)) {
17788
+ applyChangeToTarget(target, dottedKey, value);
17789
+ }
17798
17790
  }
17799
17791
  /** @internal — return (and cache) the canonical proxy for a config id. */
17800
- _cachedProxy(id, model) {
17792
+ _cachedProxy(id) {
17801
17793
  let proxy = this._proxies[id];
17802
17794
  if (!proxy) {
17803
- proxy = new LiveConfigProxy(this, id, model);
17795
+ proxy = new LiveConfigProxy(this, id);
17804
17796
  this._proxies[id] = proxy;
17805
- } else if (model !== void 0 && proxy._model === void 0) {
17806
- proxy._model = model;
17807
17797
  }
17808
17798
  return proxy;
17809
17799
  }
@@ -17871,7 +17861,7 @@ var ConfigClient = class {
17871
17861
  */
17872
17862
  async refresh() {
17873
17863
  if (!this._initialized) {
17874
- throw new SmplError("Config not initialized. Call get() first.");
17864
+ throw new SmplError("Config not initialized. Call get() or bind() first.");
17875
17865
  }
17876
17866
  const environment = this._parent?._environment;
17877
17867
  if (!environment) {
@@ -17895,10 +17885,6 @@ var ConfigClient = class {
17895
17885
  * (set via `_resolveManagement`) so runtime + management share one HTTP
17896
17886
  * client; falls back to a direct GET when running without `SmplClient`
17897
17887
  * bootstrap (e.g. unit tests that construct `ConfigClient` directly).
17898
- *
17899
- * Pages through the server until a short page (less than the requested
17900
- * size) is returned — accounts with more than 1000 configs would
17901
- * otherwise silently lose everything past page one.
17902
17888
  */
17903
17889
  async _listConfigs() {
17904
17890
  const PAGE_SIZE = 1e3;
@@ -17940,7 +17926,8 @@ var ConfigClient = class {
17940
17926
  * Eagerly initialize the config subclient — fetch all configs, resolve
17941
17927
  * environment-scoped values into the local cache, and subscribe to the
17942
17928
  * shared WebSocket for live updates. Idempotent. Called automatically
17943
- * on first `client.config.get(...)` if not invoked manually.
17929
+ * on first `client.config.get(...)` / `client.config.bind(...)` if not
17930
+ * invoked manually.
17944
17931
  */
17945
17932
  async start() {
17946
17933
  return this._ensureInitialized();
@@ -18076,10 +18063,14 @@ var ConfigClient = class {
18076
18063
  const oldItems = oldCache[cfgKey] ?? {};
18077
18064
  const newItems = newCache[cfgKey] ?? {};
18078
18065
  const allItemKeys = /* @__PURE__ */ new Set([...Object.keys(oldItems), ...Object.keys(newItems)]);
18066
+ const target = this._bindings.get(cfgKey);
18079
18067
  for (const iKey of allItemKeys) {
18080
18068
  const oldVal = iKey in oldItems ? oldItems[iKey] : null;
18081
18069
  const newVal = iKey in newItems ? newItems[iKey] : null;
18082
18070
  if (JSON.stringify(oldVal) !== JSON.stringify(newVal)) {
18071
+ if (target !== void 0) {
18072
+ applyChangeToTarget(target, iKey, newVal);
18073
+ }
18083
18074
  const metrics = this._parent?._metrics;
18084
18075
  if (metrics) {
18085
18076
  metrics.record("config.changes", 1, "changes", { config: cfgKey });
@@ -18509,7 +18500,7 @@ var Environment = class {
18509
18500
  * environment. Unmanaged environments are view-only — existing values
18510
18501
  * render for comparison but no new values can be set. Managed
18511
18502
  * environments count toward the account's `platform.managed_environments`
18512
- * quota.
18503
+ * quota. `production` is always managed and cannot be demoted.
18513
18504
  */
18514
18505
  managed;
18515
18506
  /** When the environment was created. */
@@ -18895,8 +18886,17 @@ function wrapFetchError(err) {
18895
18886
  `Request failed: ${err instanceof Error ? err.message : String(err)}`
18896
18887
  );
18897
18888
  }
18898
- async function checkError(response) {
18899
- const body = await response.text().catch(() => "");
18889
+ async function checkError(response, error) {
18890
+ let body = "";
18891
+ if (error !== void 0 && error !== null) {
18892
+ try {
18893
+ body = typeof error === "string" ? error : JSON.stringify(error);
18894
+ } catch {
18895
+ }
18896
+ }
18897
+ if (!body) {
18898
+ body = await response.text().catch(() => "");
18899
+ }
18900
18900
  throwForStatus(response.status, body);
18901
18901
  }
18902
18902
  function buildBody(config) {
@@ -19051,7 +19051,7 @@ var ManagementConfigClient = class {
19051
19051
  const result = await this._http.GET("/api/v1/configs", {
19052
19052
  params: { query }
19053
19053
  });
19054
- if (!result.response.ok) await checkError(result.response);
19054
+ if (!result.response.ok) await checkError(result.response, result.error);
19055
19055
  data = result.data;
19056
19056
  } catch (err) {
19057
19057
  wrapFetchError(err);
@@ -19066,7 +19066,7 @@ var ManagementConfigClient = class {
19066
19066
  const result = await this._http.GET("/api/v1/configs/{id}", {
19067
19067
  params: { path: { id } }
19068
19068
  });
19069
- if (!result.response.ok) await checkError(result.response);
19069
+ if (!result.response.ok) await checkError(result.response, result.error);
19070
19070
  data = result.data;
19071
19071
  } catch (err) {
19072
19072
  wrapFetchError(err);
@@ -19087,7 +19087,7 @@ var ManagementConfigClient = class {
19087
19087
  params: { path: { id } }
19088
19088
  });
19089
19089
  if (!result.response.ok && result.response.status !== 204) {
19090
- await checkError(result.response);
19090
+ await checkError(result.response, result.error);
19091
19091
  }
19092
19092
  } catch (err) {
19093
19093
  wrapFetchError(err);
@@ -19103,7 +19103,7 @@ var ManagementConfigClient = class {
19103
19103
  let data;
19104
19104
  try {
19105
19105
  const result = await this._http.POST("/api/v1/configs", { body });
19106
- if (!result.response.ok) await checkError(result.response);
19106
+ if (!result.response.ok) await checkError(result.response, result.error);
19107
19107
  data = result.data;
19108
19108
  } catch (err) {
19109
19109
  wrapFetchError(err);
@@ -19121,7 +19121,7 @@ var ManagementConfigClient = class {
19121
19121
  params: { path: { id: config.id } },
19122
19122
  body
19123
19123
  });
19124
- if (!result.response.ok) await checkError(result.response);
19124
+ if (!result.response.ok) await checkError(result.response, result.error);
19125
19125
  data = result.data;
19126
19126
  } catch (err) {
19127
19127
  wrapFetchError(err);
@@ -19135,8 +19135,17 @@ var ManagementConfigClient = class {
19135
19135
 
19136
19136
  // src/management/flags.ts
19137
19137
  var FLAG_REGISTRATION_FLUSH_SIZE = 50;
19138
- async function checkError2(response) {
19139
- const body = await response.text().catch(() => "");
19138
+ async function checkError2(response, error) {
19139
+ let body = "";
19140
+ if (error !== void 0 && error !== null) {
19141
+ try {
19142
+ body = typeof error === "string" ? error : JSON.stringify(error);
19143
+ } catch {
19144
+ }
19145
+ }
19146
+ if (!body) {
19147
+ body = await response.text().catch(() => "");
19148
+ }
19140
19149
  throwForStatus(response.status, body);
19141
19150
  }
19142
19151
  function wrapFetchError2(err) {
@@ -19334,7 +19343,7 @@ var ManagementFlagsClient = class {
19334
19343
  const result = await this._http.GET("/api/v1/flags/{id}", {
19335
19344
  params: { path: { id } }
19336
19345
  });
19337
- if (!result.response.ok) await checkError2(result.response);
19346
+ if (!result.response.ok) await checkError2(result.response, result.error);
19338
19347
  data = result.data;
19339
19348
  } catch (err) {
19340
19349
  wrapFetchError2(err);
@@ -19361,7 +19370,7 @@ var ManagementFlagsClient = class {
19361
19370
  const result = await this._http.GET("/api/v1/flags", {
19362
19371
  params: { query }
19363
19372
  });
19364
- if (!result.response.ok) await checkError2(result.response);
19373
+ if (!result.response.ok) await checkError2(result.response, result.error);
19365
19374
  data = result.data;
19366
19375
  } catch (err) {
19367
19376
  wrapFetchError2(err);
@@ -19380,7 +19389,7 @@ var ManagementFlagsClient = class {
19380
19389
  params: { path: { id } }
19381
19390
  });
19382
19391
  if (!result.response.ok && result.response.status !== 204) {
19383
- await checkError2(result.response);
19392
+ await checkError2(result.response, result.error);
19384
19393
  }
19385
19394
  } catch (err) {
19386
19395
  wrapFetchError2(err);
@@ -19425,7 +19434,7 @@ var ManagementFlagsClient = class {
19425
19434
  let data;
19426
19435
  try {
19427
19436
  const result = await this._http.POST("/api/v1/flags", { body });
19428
- if (!result.response.ok) await checkError2(result.response);
19437
+ if (!result.response.ok) await checkError2(result.response, result.error);
19429
19438
  data = result.data;
19430
19439
  } catch (err) {
19431
19440
  wrapFetchError2(err);
@@ -19443,7 +19452,7 @@ var ManagementFlagsClient = class {
19443
19452
  params: { path: { id: flag.id } },
19444
19453
  body
19445
19454
  });
19446
- if (!result.response.ok) await checkError2(result.response);
19455
+ if (!result.response.ok) await checkError2(result.response, result.error);
19447
19456
  data = result.data;
19448
19457
  } catch (err) {
19449
19458
  wrapFetchError2(err);
@@ -19763,8 +19772,17 @@ var LogGroup = class {
19763
19772
 
19764
19773
  // src/management/logging.ts
19765
19774
  var LOGGER_REGISTRATION_FLUSH_SIZE = 50;
19766
- async function checkError3(response) {
19767
- const body = await response.text().catch(() => "");
19775
+ async function checkError3(response, error) {
19776
+ let body = "";
19777
+ if (error !== void 0 && error !== null) {
19778
+ try {
19779
+ body = typeof error === "string" ? error : JSON.stringify(error);
19780
+ } catch {
19781
+ }
19782
+ }
19783
+ if (!body) {
19784
+ body = await response.text().catch(() => "");
19785
+ }
19768
19786
  throwForStatus(response.status, body);
19769
19787
  }
19770
19788
  function wrapFetchError3(err) {
@@ -19899,7 +19917,7 @@ var LoggersClient = class {
19899
19917
  const result = await this._http.GET("/api/v1/loggers", {
19900
19918
  params: { query }
19901
19919
  });
19902
- if (!result.response.ok) await checkError3(result.response);
19920
+ if (!result.response.ok) await checkError3(result.response, result.error);
19903
19921
  data = result.data;
19904
19922
  } catch (err) {
19905
19923
  wrapFetchError3(err);
@@ -19913,7 +19931,7 @@ var LoggersClient = class {
19913
19931
  const result = await this._http.GET("/api/v1/loggers/{id}", {
19914
19932
  params: { path: { id } }
19915
19933
  });
19916
- if (!result.response.ok) await checkError3(result.response);
19934
+ if (!result.response.ok) await checkError3(result.response, result.error);
19917
19935
  data = result.data;
19918
19936
  } catch (err) {
19919
19937
  wrapFetchError3(err);
@@ -19933,7 +19951,7 @@ var LoggersClient = class {
19933
19951
  params: { path: { id } }
19934
19952
  });
19935
19953
  if (!result.response.ok && result.response.status !== 204) {
19936
- await checkError3(result.response);
19954
+ await checkError3(result.response, result.error);
19937
19955
  }
19938
19956
  } catch (err) {
19939
19957
  wrapFetchError3(err);
@@ -19974,7 +19992,7 @@ var LoggersClient = class {
19974
19992
  params: { path: { id: logger.id } },
19975
19993
  body
19976
19994
  });
19977
- if (!result.response.ok) await checkError3(result.response);
19995
+ if (!result.response.ok) await checkError3(result.response, result.error);
19978
19996
  data = result.data;
19979
19997
  } catch (err) {
19980
19998
  wrapFetchError3(err);
@@ -20017,7 +20035,7 @@ var LogGroupsClient = class {
20017
20035
  const result = await this._http.GET("/api/v1/log_groups", {
20018
20036
  params: { query }
20019
20037
  });
20020
- if (!result.response.ok) await checkError3(result.response);
20038
+ if (!result.response.ok) await checkError3(result.response, result.error);
20021
20039
  data = result.data;
20022
20040
  } catch (err) {
20023
20041
  wrapFetchError3(err);
@@ -20031,7 +20049,7 @@ var LogGroupsClient = class {
20031
20049
  const result = await this._http.GET("/api/v1/log_groups/{id}", {
20032
20050
  params: { path: { id } }
20033
20051
  });
20034
- if (!result.response.ok) await checkError3(result.response);
20052
+ if (!result.response.ok) await checkError3(result.response, result.error);
20035
20053
  data = result.data;
20036
20054
  } catch (err) {
20037
20055
  wrapFetchError3(err);
@@ -20051,7 +20069,7 @@ var LogGroupsClient = class {
20051
20069
  params: { path: { id } }
20052
20070
  });
20053
20071
  if (!result.response.ok && result.response.status !== 204) {
20054
- await checkError3(result.response);
20072
+ await checkError3(result.response, result.error);
20055
20073
  }
20056
20074
  } catch (err) {
20057
20075
  wrapFetchError3(err);
@@ -20068,7 +20086,7 @@ var LogGroupsClient = class {
20068
20086
  let data;
20069
20087
  try {
20070
20088
  const result = await this._http.POST("/api/v1/log_groups", { body });
20071
- if (!result.response.ok) await checkError3(result.response);
20089
+ if (!result.response.ok) await checkError3(result.response, result.error);
20072
20090
  data = result.data;
20073
20091
  } catch (err) {
20074
20092
  wrapFetchError3(err);
@@ -20086,7 +20104,7 @@ var LogGroupsClient = class {
20086
20104
  params: { path: { id: group.id } },
20087
20105
  body
20088
20106
  });
20089
- if (!result.response.ok) await checkError3(result.response);
20107
+ if (!result.response.ok) await checkError3(result.response, result.error);
20090
20108
  data = result.data;
20091
20109
  } catch (err) {
20092
20110
  wrapFetchError3(err);
@@ -20235,8 +20253,17 @@ var Forwarder = class {
20235
20253
  };
20236
20254
 
20237
20255
  // src/management/audit.ts
20238
- async function checkError4(response) {
20239
- const body = await response.text().catch(() => "");
20256
+ async function checkError4(response, error) {
20257
+ let body = "";
20258
+ if (error !== void 0 && error !== null) {
20259
+ try {
20260
+ body = typeof error === "string" ? error : JSON.stringify(error);
20261
+ } catch {
20262
+ }
20263
+ }
20264
+ if (!body) {
20265
+ body = await response.text().catch(() => "");
20266
+ }
20240
20267
  throwForStatus(response.status, body);
20241
20268
  }
20242
20269
  function wrapFetchError4(err) {
@@ -20392,7 +20419,7 @@ var ForwardersClient = class {
20392
20419
  const result = await this._http.GET("/api/v1/forwarders", {
20393
20420
  params: { query }
20394
20421
  });
20395
- if (!result.response.ok) await checkError4(result.response);
20422
+ if (!result.response.ok) await checkError4(result.response, result.error);
20396
20423
  data = result.data;
20397
20424
  } catch (err) {
20398
20425
  wrapFetchError4(err);
@@ -20413,7 +20440,7 @@ var ForwardersClient = class {
20413
20440
  const result = await this._http.GET("/api/v1/forwarders/{forwarder_id}", {
20414
20441
  params: { path: { forwarder_id: forwarderId } }
20415
20442
  });
20416
- if (!result.response.ok) await checkError4(result.response);
20443
+ if (!result.response.ok) await checkError4(result.response, result.error);
20417
20444
  data = result.data;
20418
20445
  } catch (err) {
20419
20446
  wrapFetchError4(err);
@@ -20427,7 +20454,7 @@ var ForwardersClient = class {
20427
20454
  const result = await this._http.DELETE("/api/v1/forwarders/{forwarder_id}", {
20428
20455
  params: { path: { forwarder_id: forwarderId } }
20429
20456
  });
20430
- if (result.response.status !== 204) await checkError4(result.response);
20457
+ if (result.response.status !== 204) await checkError4(result.response, result.error);
20431
20458
  } catch (err) {
20432
20459
  wrapFetchError4(err);
20433
20460
  }
@@ -20442,7 +20469,7 @@ var ForwardersClient = class {
20442
20469
  let data;
20443
20470
  try {
20444
20471
  const result = await this._http.POST("/api/v1/forwarders", { body });
20445
- if (!result.response.ok) await checkError4(result.response);
20472
+ if (!result.response.ok) await checkError4(result.response, result.error);
20446
20473
  data = result.data;
20447
20474
  } catch (err) {
20448
20475
  wrapFetchError4(err);
@@ -20469,7 +20496,7 @@ var ForwardersClient = class {
20469
20496
  params: { path: { forwarder_id: forwarder.id } },
20470
20497
  body
20471
20498
  });
20472
- if (!result.response.ok) await checkError4(result.response);
20499
+ if (!result.response.ok) await checkError4(result.response, result.error);
20473
20500
  data = result.data;
20474
20501
  } catch (err) {
20475
20502
  wrapFetchError4(err);
@@ -20632,8 +20659,17 @@ function splitContextId(idOrType, key) {
20632
20659
  }
20633
20660
  return [idOrType, key];
20634
20661
  }
20635
- async function checkError5(response) {
20636
- const body = await response.text().catch(() => "");
20662
+ async function checkError5(response, error) {
20663
+ let body = "";
20664
+ if (error !== void 0 && error !== null) {
20665
+ try {
20666
+ body = typeof error === "string" ? error : JSON.stringify(error);
20667
+ } catch {
20668
+ }
20669
+ }
20670
+ if (!body) {
20671
+ body = await response.text().catch(() => "");
20672
+ }
20637
20673
  throwForStatus(response.status, body);
20638
20674
  }
20639
20675
  function wrapFetchError5(err) {
@@ -20734,7 +20770,7 @@ var EnvironmentsClient = class {
20734
20770
  const result = await this._http.GET("/api/v1/environments", {
20735
20771
  params: { query }
20736
20772
  });
20737
- if (!result.response.ok) await checkError5(result.response);
20773
+ if (!result.response.ok) await checkError5(result.response, result.error);
20738
20774
  data = result.data;
20739
20775
  } catch (err) {
20740
20776
  wrapFetchError5(err);
@@ -20748,7 +20784,7 @@ var EnvironmentsClient = class {
20748
20784
  const result = await this._http.GET("/api/v1/environments/{id}", {
20749
20785
  params: { path: { id } }
20750
20786
  });
20751
- if (!result.response.ok) await checkError5(result.response);
20787
+ if (!result.response.ok) await checkError5(result.response, result.error);
20752
20788
  data = result.data;
20753
20789
  } catch (err) {
20754
20790
  wrapFetchError5(err);
@@ -20763,7 +20799,7 @@ var EnvironmentsClient = class {
20763
20799
  params: { path: { id } }
20764
20800
  });
20765
20801
  if (!result.response.ok && result.response.status !== 204) {
20766
- await checkError5(result.response);
20802
+ await checkError5(result.response, result.error);
20767
20803
  }
20768
20804
  } catch (err) {
20769
20805
  wrapFetchError5(err);
@@ -20786,7 +20822,7 @@ var EnvironmentsClient = class {
20786
20822
  let data;
20787
20823
  try {
20788
20824
  const result = await this._http.POST("/api/v1/environments", { body });
20789
- if (!result.response.ok) await checkError5(result.response);
20825
+ if (!result.response.ok) await checkError5(result.response, result.error);
20790
20826
  data = result.data;
20791
20827
  } catch (err) {
20792
20828
  wrapFetchError5(err);
@@ -20815,7 +20851,7 @@ var EnvironmentsClient = class {
20815
20851
  params: { path: { id: env.id } },
20816
20852
  body
20817
20853
  });
20818
- if (!result.response.ok) await checkError5(result.response);
20854
+ if (!result.response.ok) await checkError5(result.response, result.error);
20819
20855
  data = result.data;
20820
20856
  } catch (err) {
20821
20857
  wrapFetchError5(err);
@@ -20860,7 +20896,7 @@ var ContextTypesClient = class {
20860
20896
  const result = await this._http.GET("/api/v1/context_types", {
20861
20897
  params: { query }
20862
20898
  });
20863
- if (!result.response.ok) await checkError5(result.response);
20899
+ if (!result.response.ok) await checkError5(result.response, result.error);
20864
20900
  data = result.data;
20865
20901
  } catch (err) {
20866
20902
  wrapFetchError5(err);
@@ -20874,7 +20910,7 @@ var ContextTypesClient = class {
20874
20910
  const result = await this._http.GET("/api/v1/context_types/{id}", {
20875
20911
  params: { path: { id } }
20876
20912
  });
20877
- if (!result.response.ok) await checkError5(result.response);
20913
+ if (!result.response.ok) await checkError5(result.response, result.error);
20878
20914
  data = result.data;
20879
20915
  } catch (err) {
20880
20916
  wrapFetchError5(err);
@@ -20889,7 +20925,7 @@ var ContextTypesClient = class {
20889
20925
  params: { path: { id } }
20890
20926
  });
20891
20927
  if (!result.response.ok && result.response.status !== 204) {
20892
- await checkError5(result.response);
20928
+ await checkError5(result.response, result.error);
20893
20929
  }
20894
20930
  } catch (err) {
20895
20931
  wrapFetchError5(err);
@@ -20910,7 +20946,7 @@ var ContextTypesClient = class {
20910
20946
  let data;
20911
20947
  try {
20912
20948
  const result = await this._http.POST("/api/v1/context_types", { body });
20913
- if (!result.response.ok) await checkError5(result.response);
20949
+ if (!result.response.ok) await checkError5(result.response, result.error);
20914
20950
  data = result.data;
20915
20951
  } catch (err) {
20916
20952
  wrapFetchError5(err);
@@ -20937,7 +20973,7 @@ var ContextTypesClient = class {
20937
20973
  params: { path: { id: ct.id } },
20938
20974
  body
20939
20975
  });
20940
- if (!result.response.ok) await checkError5(result.response);
20976
+ if (!result.response.ok) await checkError5(result.response, result.error);
20941
20977
  data = result.data;
20942
20978
  } catch (err) {
20943
20979
  wrapFetchError5(err);
@@ -21016,7 +21052,7 @@ var ContextsClient = class {
21016
21052
  }))
21017
21053
  }
21018
21054
  });
21019
- if (!result.response.ok) await checkError5(result.response);
21055
+ if (!result.response.ok) await checkError5(result.response, result.error);
21020
21056
  } catch (err) {
21021
21057
  wrapFetchError5(err);
21022
21058
  }
@@ -21042,7 +21078,7 @@ var ContextsClient = class {
21042
21078
  const result = await this._http.GET("/api/v1/contexts", {
21043
21079
  params: { query }
21044
21080
  });
21045
- if (!result.response.ok) await checkError5(result.response);
21081
+ if (!result.response.ok) await checkError5(result.response, result.error);
21046
21082
  data = result.data;
21047
21083
  } catch (err) {
21048
21084
  wrapFetchError5(err);
@@ -21059,7 +21095,7 @@ var ContextsClient = class {
21059
21095
  const result = await this._http.GET("/api/v1/contexts/{id}", {
21060
21096
  params: { path: { id: composite } }
21061
21097
  });
21062
- if (!result.response.ok) await checkError5(result.response);
21098
+ if (!result.response.ok) await checkError5(result.response, result.error);
21063
21099
  data = result.data;
21064
21100
  } catch (err) {
21065
21101
  wrapFetchError5(err);
@@ -21077,7 +21113,7 @@ var ContextsClient = class {
21077
21113
  params: { path: { id: composite } }
21078
21114
  });
21079
21115
  if (!result.response.ok && result.response.status !== 204) {
21080
- await checkError5(result.response);
21116
+ await checkError5(result.response, result.error);
21081
21117
  }
21082
21118
  } catch (err) {
21083
21119
  wrapFetchError5(err);
@@ -21107,7 +21143,7 @@ var ContextsClient = class {
21107
21143
  params: { path: { id: ctx.id } },
21108
21144
  body
21109
21145
  });
21110
- if (!result.response.ok) await checkError5(result.response);
21146
+ if (!result.response.ok) await checkError5(result.response, result.error);
21111
21147
  data = result.data;
21112
21148
  } catch (err) {
21113
21149
  wrapFetchError5(err);