@smplkit/sdk 1.3.39 → 1.3.40

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
@@ -17005,6 +17005,27 @@ function buildRequestBody(options) {
17005
17005
  }
17006
17006
  };
17007
17007
  }
17008
+ var ConfigManagement = class {
17009
+ constructor(_client) {
17010
+ this._client = _client;
17011
+ }
17012
+ /** Create an unsaved config. Call `.save()` to persist. */
17013
+ new(id, options) {
17014
+ return this._client._mgNew(id, options);
17015
+ }
17016
+ /** Fetch a config by id. */
17017
+ async get(id) {
17018
+ return this._client._getById(id);
17019
+ }
17020
+ /** List all configs. */
17021
+ async list() {
17022
+ return this._client._mgList();
17023
+ }
17024
+ /** Delete a config by id. */
17025
+ async delete(id) {
17026
+ return this._client._mgDelete(id);
17027
+ }
17028
+ };
17008
17029
  var ConfigClient = class {
17009
17030
  /** @internal */
17010
17031
  _apiKey;
@@ -17016,6 +17037,8 @@ var ConfigClient = class {
17016
17037
  _getSharedWs;
17017
17038
  /** @internal — set by SmplClient after construction. */
17018
17039
  _parent = null;
17040
+ /** Management API — CRUD operations on Config models. */
17041
+ management;
17019
17042
  _configCache = {};
17020
17043
  _initialized = false;
17021
17044
  _listeners = [];
@@ -17044,12 +17067,13 @@ var ConfigClient = class {
17044
17067
  }
17045
17068
  }
17046
17069
  });
17070
+ this.management = new ConfigManagement(this);
17047
17071
  }
17048
17072
  // ------------------------------------------------------------------
17049
- // Management: factory method
17073
+ // Management: internal implementations (delegated from ConfigManagement)
17050
17074
  // ------------------------------------------------------------------
17051
- /** Create an unsaved config. Call `.save()` to persist. */
17052
- new(id, options) {
17075
+ /** @internal */
17076
+ _mgNew(id, options) {
17053
17077
  return new Config(this, {
17054
17078
  id,
17055
17079
  name: options?.name ?? keyToDisplayName(id),
@@ -17061,15 +17085,8 @@ var ConfigClient = class {
17061
17085
  updatedAt: null
17062
17086
  });
17063
17087
  }
17064
- // ------------------------------------------------------------------
17065
- // Management: CRUD
17066
- // ------------------------------------------------------------------
17067
- /** Fetch a config by id. */
17068
- async get(id) {
17069
- return this._getById(id);
17070
- }
17071
- /** List all configs. */
17072
- async list() {
17088
+ /** @internal */
17089
+ async _mgList() {
17073
17090
  let data;
17074
17091
  try {
17075
17092
  const result = await this._http.GET("/api/v1/configs", {});
@@ -17081,8 +17098,8 @@ var ConfigClient = class {
17081
17098
  if (!data) return [];
17082
17099
  return data.data.map((r) => resourceToConfig(r, this));
17083
17100
  }
17084
- /** Delete a config by id. */
17085
- async delete(id) {
17101
+ /** @internal */
17102
+ async _mgDelete(id) {
17086
17103
  try {
17087
17104
  const result = await this._http.DELETE("/api/v1/configs/{id}", {
17088
17105
  params: { path: { id } }
@@ -17162,12 +17179,12 @@ var ConfigClient = class {
17162
17179
  // Runtime: resolve and subscribe
17163
17180
  // ------------------------------------------------------------------
17164
17181
  /**
17165
- * Resolve a config's values for the current environment.
17182
+ * Get a config's resolved values for the current environment.
17166
17183
  *
17167
17184
  * Returns the resolved key-value pairs for the given config.
17168
17185
  * Optionally pass a model class to map the resolved values.
17169
17186
  */
17170
- async resolve(id, model) {
17187
+ async get(id, model) {
17171
17188
  await this._ensureInitialized();
17172
17189
  const values = this._configCache[id];
17173
17190
  if (values === void 0) {
@@ -17235,13 +17252,13 @@ var ConfigClient = class {
17235
17252
  */
17236
17253
  async refresh() {
17237
17254
  if (!this._initialized) {
17238
- throw new SmplError("Config not initialized. Call resolve() or subscribe() first.");
17255
+ throw new SmplError("Config not initialized. Call get() or subscribe() first.");
17239
17256
  }
17240
17257
  const environment = this._parent?._environment;
17241
17258
  if (!environment) {
17242
17259
  throw new SmplError("No environment set.");
17243
17260
  }
17244
- const configs = await this.list();
17261
+ const configs = await this.management.list();
17245
17262
  const newCache = {};
17246
17263
  for (const cfg of configs) {
17247
17264
  const chain = await cfg._buildChain(configs);
@@ -17261,7 +17278,7 @@ var ConfigClient = class {
17261
17278
  if (!environment) {
17262
17279
  throw new SmplError("No environment set. Ensure SmplClient is configured.");
17263
17280
  }
17264
- const configs = await this.list();
17281
+ const configs = await this.management.list();
17265
17282
  const cache = {};
17266
17283
  for (const cfg of configs) {
17267
17284
  const chain = await cfg._buildChain(configs);
@@ -17277,7 +17294,7 @@ var ConfigClient = class {
17277
17294
  /** @internal — called by SmplClient for backward compat. */
17278
17295
  async _connectInternal(environment) {
17279
17296
  if (this._initialized) return;
17280
- const configs = await this.list();
17297
+ const configs = await this.management.list();
17281
17298
  const cache = {};
17282
17299
  for (const cfg of configs) {
17283
17300
  const chain = await cfg._buildChain(configs);
@@ -17656,6 +17673,39 @@ var ContextRegistrationBuffer = class {
17656
17673
  return this._pending.length;
17657
17674
  }
17658
17675
  };
17676
+ var FlagsManagement = class {
17677
+ constructor(_client) {
17678
+ this._client = _client;
17679
+ }
17680
+ /** Create an unsaved boolean flag. Call `.save()` to persist. */
17681
+ newBooleanFlag(id, options) {
17682
+ return this._client._mgNewBooleanFlag(id, options);
17683
+ }
17684
+ /** Create an unsaved string flag. Call `.save()` to persist. */
17685
+ newStringFlag(id, options) {
17686
+ return this._client._mgNewStringFlag(id, options);
17687
+ }
17688
+ /** Create an unsaved number flag. Call `.save()` to persist. */
17689
+ newNumberFlag(id, options) {
17690
+ return this._client._mgNewNumberFlag(id, options);
17691
+ }
17692
+ /** Create an unsaved JSON flag. Call `.save()` to persist. */
17693
+ newJsonFlag(id, options) {
17694
+ return this._client._mgNewJsonFlag(id, options);
17695
+ }
17696
+ /** Fetch a flag by id. */
17697
+ async get(id) {
17698
+ return this._client._mgGet(id);
17699
+ }
17700
+ /** List all flags. */
17701
+ async list() {
17702
+ return this._client._mgList();
17703
+ }
17704
+ /** Delete a flag by id. */
17705
+ async delete(id) {
17706
+ return this._client._mgDelete(id);
17707
+ }
17708
+ };
17659
17709
  var FlagsClient = class {
17660
17710
  /** @internal */
17661
17711
  _apiKey;
@@ -17680,6 +17730,8 @@ var FlagsClient = class {
17680
17730
  _ensureWs;
17681
17731
  /** @internal — set by SmplClient after construction. */
17682
17732
  _parent = null;
17733
+ /** Management API — CRUD operations on Flag models. */
17734
+ management;
17683
17735
  /** @internal */
17684
17736
  constructor(apiKey, ensureWs, timeout) {
17685
17737
  this._apiKey = apiKey;
@@ -17715,12 +17767,13 @@ var FlagsClient = class {
17715
17767
  },
17716
17768
  fetch: fetchWithTimeout
17717
17769
  });
17770
+ this.management = new FlagsManagement(this);
17718
17771
  }
17719
17772
  // ------------------------------------------------------------------
17720
- // Management: factory methods (return unsaved flags)
17773
+ // Management: internal implementations (delegated from FlagsManagement)
17721
17774
  // ------------------------------------------------------------------
17722
- /** Create an unsaved boolean flag. Call `.save()` to persist. */
17723
- newBooleanFlag(id, options) {
17775
+ /** @internal */
17776
+ _mgNewBooleanFlag(id, options) {
17724
17777
  return new BooleanFlag(this, {
17725
17778
  id,
17726
17779
  name: options.name ?? keyToDisplayName(id),
@@ -17736,8 +17789,8 @@ var FlagsClient = class {
17736
17789
  updatedAt: null
17737
17790
  });
17738
17791
  }
17739
- /** Create an unsaved string flag. Call `.save()` to persist. */
17740
- newStringFlag(id, options) {
17792
+ /** @internal */
17793
+ _mgNewStringFlag(id, options) {
17741
17794
  return new StringFlag(this, {
17742
17795
  id,
17743
17796
  name: options.name ?? keyToDisplayName(id),
@@ -17750,8 +17803,8 @@ var FlagsClient = class {
17750
17803
  updatedAt: null
17751
17804
  });
17752
17805
  }
17753
- /** Create an unsaved number flag. Call `.save()` to persist. */
17754
- newNumberFlag(id, options) {
17806
+ /** @internal */
17807
+ _mgNewNumberFlag(id, options) {
17755
17808
  return new NumberFlag(this, {
17756
17809
  id,
17757
17810
  name: options.name ?? keyToDisplayName(id),
@@ -17764,8 +17817,8 @@ var FlagsClient = class {
17764
17817
  updatedAt: null
17765
17818
  });
17766
17819
  }
17767
- /** Create an unsaved JSON flag. Call `.save()` to persist. */
17768
- newJsonFlag(id, options) {
17820
+ /** @internal */
17821
+ _mgNewJsonFlag(id, options) {
17769
17822
  return new JsonFlag(this, {
17770
17823
  id,
17771
17824
  name: options.name ?? keyToDisplayName(id),
@@ -17778,11 +17831,8 @@ var FlagsClient = class {
17778
17831
  updatedAt: null
17779
17832
  });
17780
17833
  }
17781
- // ------------------------------------------------------------------
17782
- // Management: CRUD
17783
- // ------------------------------------------------------------------
17784
- /** Fetch a flag by id. */
17785
- async get(id) {
17834
+ /** @internal */
17835
+ async _mgGet(id) {
17786
17836
  let data;
17787
17837
  try {
17788
17838
  const result = await this._http.GET("/api/v1/flags/{id}", {
@@ -17799,8 +17849,8 @@ var FlagsClient = class {
17799
17849
  }
17800
17850
  return this._resourceToModel(data.data);
17801
17851
  }
17802
- /** List all flags. */
17803
- async list() {
17852
+ /** @internal */
17853
+ async _mgList() {
17804
17854
  let data;
17805
17855
  try {
17806
17856
  const result = await this._http.GET("/api/v1/flags", {});
@@ -17812,8 +17862,8 @@ var FlagsClient = class {
17812
17862
  if (!data) return [];
17813
17863
  return data.data.map((r) => this._resourceToModel(r));
17814
17864
  }
17815
- /** Delete a flag by id. */
17816
- async delete(id) {
17865
+ /** @internal */
17866
+ async _mgDelete(id) {
17817
17867
  try {
17818
17868
  const result = await this._http.DELETE("/api/v1/flags/{id}", {
17819
17869
  params: { path: { id } }
@@ -18460,6 +18510,43 @@ function wrapFetchError3(err) {
18460
18510
  `Request failed: ${err instanceof Error ? err.message : String(err)}`
18461
18511
  );
18462
18512
  }
18513
+ var LoggingManagement = class {
18514
+ constructor(_client) {
18515
+ this._client = _client;
18516
+ }
18517
+ /** Create an unsaved logger. Call `.save()` to persist. */
18518
+ new(id, options) {
18519
+ return this._client._mgNew(id, options);
18520
+ }
18521
+ /** Fetch a logger by id. */
18522
+ async get(id) {
18523
+ return this._client._mgGet(id);
18524
+ }
18525
+ /** List all loggers. */
18526
+ async list() {
18527
+ return this._client._mgList();
18528
+ }
18529
+ /** Delete a logger by id. */
18530
+ async delete(id) {
18531
+ return this._client._mgDelete(id);
18532
+ }
18533
+ /** Create an unsaved log group. Call `.save()` to persist. */
18534
+ newGroup(id, options) {
18535
+ return this._client._mgNewGroup(id, options);
18536
+ }
18537
+ /** Fetch a log group by id. */
18538
+ async getGroup(id) {
18539
+ return this._client._mgGetGroup(id);
18540
+ }
18541
+ /** List all log groups. */
18542
+ async listGroups() {
18543
+ return this._client._mgListGroups();
18544
+ }
18545
+ /** Delete a log group by id. */
18546
+ async deleteGroup(id) {
18547
+ return this._client._mgDeleteGroup(id);
18548
+ }
18549
+ };
18463
18550
  var LoggingClient = class {
18464
18551
  /** @internal */
18465
18552
  _apiKey;
@@ -18469,6 +18556,8 @@ var LoggingClient = class {
18469
18556
  _http;
18470
18557
  /** @internal — set by SmplClient after construction. */
18471
18558
  _parent = null;
18559
+ /** Management API — CRUD operations on Logger and LogGroup models. */
18560
+ management;
18472
18561
  _ensureWs;
18473
18562
  _wsManager = null;
18474
18563
  _started = false;
@@ -18502,6 +18591,7 @@ var LoggingClient = class {
18502
18591
  }
18503
18592
  }
18504
18593
  });
18594
+ this.management = new LoggingManagement(this);
18505
18595
  }
18506
18596
  // ------------------------------------------------------------------
18507
18597
  // Adapter registration
@@ -18520,10 +18610,10 @@ var LoggingClient = class {
18520
18610
  this._adapters.push(adapter);
18521
18611
  }
18522
18612
  // ------------------------------------------------------------------
18523
- // Management: Logger factory
18613
+ // Management: internal implementations (delegated from LoggingManagement)
18524
18614
  // ------------------------------------------------------------------
18525
- /** Create an unsaved logger. Call `.save()` to persist. */
18526
- new(id, options) {
18615
+ /** @internal */
18616
+ _mgNew(id, options) {
18527
18617
  return new Logger(this, {
18528
18618
  id,
18529
18619
  name: options?.name ?? keyToDisplayName(id),
@@ -18536,11 +18626,8 @@ var LoggingClient = class {
18536
18626
  updatedAt: null
18537
18627
  });
18538
18628
  }
18539
- // ------------------------------------------------------------------
18540
- // Management: Logger CRUD
18541
- // ------------------------------------------------------------------
18542
- /** Fetch a logger by id. */
18543
- async get(id) {
18629
+ /** @internal */
18630
+ async _mgGet(id) {
18544
18631
  let data;
18545
18632
  try {
18546
18633
  const result = await this._http.GET("/api/v1/loggers/{id}", {
@@ -18557,8 +18644,8 @@ var LoggingClient = class {
18557
18644
  }
18558
18645
  return this._loggerToModel(data.data);
18559
18646
  }
18560
- /** List all loggers. */
18561
- async list() {
18647
+ /** @internal */
18648
+ async _mgList() {
18562
18649
  let data;
18563
18650
  try {
18564
18651
  const result = await this._http.GET("/api/v1/loggers", {});
@@ -18570,8 +18657,8 @@ var LoggingClient = class {
18570
18657
  if (!data) return [];
18571
18658
  return data.data.map((r) => this._loggerToModel(r));
18572
18659
  }
18573
- /** Delete a logger by id. */
18574
- async delete(id) {
18660
+ /** @internal */
18661
+ async _mgDelete(id) {
18575
18662
  try {
18576
18663
  const result = await this._http.DELETE("/api/v1/loggers/{id}", {
18577
18664
  params: { path: { id } }
@@ -18582,11 +18669,8 @@ var LoggingClient = class {
18582
18669
  wrapFetchError3(err);
18583
18670
  }
18584
18671
  }
18585
- // ------------------------------------------------------------------
18586
- // Management: LogGroup factory
18587
- // ------------------------------------------------------------------
18588
- /** Create an unsaved log group. Call `.save()` to persist. */
18589
- newGroup(id, options) {
18672
+ /** @internal */
18673
+ _mgNewGroup(id, options) {
18590
18674
  return new LogGroup(this, {
18591
18675
  id,
18592
18676
  name: options?.name ?? keyToDisplayName(id),
@@ -18597,20 +18681,17 @@ var LoggingClient = class {
18597
18681
  updatedAt: null
18598
18682
  });
18599
18683
  }
18600
- // ------------------------------------------------------------------
18601
- // Management: LogGroup CRUD
18602
- // ------------------------------------------------------------------
18603
- /** Fetch a log group by id. */
18604
- async getGroup(id) {
18605
- const groups = await this.listGroups();
18684
+ /** @internal */
18685
+ async _mgGetGroup(id) {
18686
+ const groups = await this.management.listGroups();
18606
18687
  const match = groups.find((g) => g.id === id);
18607
18688
  if (!match) {
18608
18689
  throw new SmplNotFoundError(`LogGroup with id '${id}' not found`);
18609
18690
  }
18610
18691
  return match;
18611
18692
  }
18612
- /** List all log groups. */
18613
- async listGroups() {
18693
+ /** @internal */
18694
+ async _mgListGroups() {
18614
18695
  let data;
18615
18696
  try {
18616
18697
  const result = await this._http.GET("/api/v1/log_groups", {});
@@ -18623,9 +18704,9 @@ var LoggingClient = class {
18623
18704
  if (!data) return [];
18624
18705
  return data.data.map((r) => this._groupToModel(r));
18625
18706
  }
18626
- /** Delete a log group by id. */
18627
- async deleteGroup(id) {
18628
- const group = await this.getGroup(id);
18707
+ /** @internal */
18708
+ async _mgDeleteGroup(id) {
18709
+ const group = await this.management.getGroup(id);
18629
18710
  try {
18630
18711
  const result = await this._http.DELETE("/api/v1/log_groups/{id}", {
18631
18712
  params: { path: { id: group.id } }
@@ -18767,14 +18848,20 @@ var LoggingClient = class {
18767
18848
  }
18768
18849
  for (const { name, level } of discovered) {
18769
18850
  try {
18770
- const logger = this.new(name, { managed: true });
18851
+ const logger = this.management.new(name, { managed: true });
18771
18852
  logger.setLevel(level);
18772
18853
  await logger.save();
18773
- } catch {
18854
+ } catch (err) {
18855
+ console.warn(
18856
+ `[smplkit] Failed to register logger "${name}": ${err instanceof Error ? err.message : String(err)}`
18857
+ );
18774
18858
  }
18775
18859
  }
18776
18860
  try {
18777
- const [serverLoggers] = await Promise.all([this.list(), this.listGroups()]);
18861
+ const [serverLoggers] = await Promise.all([
18862
+ this.management.list(),
18863
+ this.management.listGroups()
18864
+ ]);
18778
18865
  this._applyLevels(serverLoggers);
18779
18866
  } catch {
18780
18867
  }
@@ -18873,7 +18960,7 @@ var LoggingClient = class {
18873
18960
  }
18874
18961
  /** Called by adapter hooks when a new logger is created in the framework. */
18875
18962
  _onAdapterNewLogger(_name, _level) {
18876
- const logger = this.new(_name, { managed: true });
18963
+ const logger = this.management.new(_name, { managed: true });
18877
18964
  logger.setLevel(_level);
18878
18965
  logger.save().catch(() => {
18879
18966
  });
@@ -19689,17 +19776,20 @@ export {
19689
19776
  BooleanFlag,
19690
19777
  Config,
19691
19778
  ConfigClient,
19779
+ ConfigManagement,
19692
19780
  Context,
19693
19781
  Flag,
19694
19782
  FlagChangeEvent,
19695
19783
  FlagStats,
19696
19784
  FlagsClient,
19785
+ FlagsManagement,
19697
19786
  JsonFlag,
19698
19787
  LiveConfigProxy,
19699
19788
  LogGroup,
19700
19789
  LogLevel,
19701
19790
  Logger,
19702
19791
  LoggingClient,
19792
+ LoggingManagement,
19703
19793
  NumberFlag,
19704
19794
  PinoAdapter,
19705
19795
  Rule,