@smplkit/sdk 1.5.8 → 1.6.0

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 CHANGED
@@ -17097,11 +17097,11 @@ var ConfigClient = class {
17097
17097
  _initialized = false;
17098
17098
  _listeners = [];
17099
17099
  /** @internal */
17100
- constructor(apiKey, timeout) {
17100
+ constructor(apiKey, timeout, baseUrl) {
17101
17101
  this._apiKey = apiKey;
17102
17102
  const ms = timeout ?? 3e4;
17103
17103
  this._http = (0, import_openapi_fetch.default)({
17104
- baseUrl: BASE_URL,
17104
+ baseUrl: baseUrl ?? BASE_URL,
17105
17105
  headers: {
17106
17106
  Authorization: `Bearer ${apiKey}`,
17107
17107
  Accept: "application/json"
@@ -17816,7 +17816,7 @@ var FlagsClient = class {
17816
17816
  /** Management API — CRUD operations on Flag models. */
17817
17817
  management;
17818
17818
  /** @internal */
17819
- constructor(apiKey, ensureWs, timeout) {
17819
+ constructor(apiKey, ensureWs, timeout, flagsBaseUrl, appBaseUrl) {
17820
17820
  this._apiKey = apiKey;
17821
17821
  this._ensureWs = ensureWs;
17822
17822
  const ms = timeout ?? 3e4;
@@ -17835,7 +17835,7 @@ var FlagsClient = class {
17835
17835
  }
17836
17836
  };
17837
17837
  this._http = (0, import_openapi_fetch2.default)({
17838
- baseUrl: FLAGS_BASE_URL,
17838
+ baseUrl: flagsBaseUrl ?? FLAGS_BASE_URL,
17839
17839
  headers: {
17840
17840
  Authorization: `Bearer ${apiKey}`,
17841
17841
  Accept: "application/json"
@@ -17843,7 +17843,7 @@ var FlagsClient = class {
17843
17843
  fetch: fetchWithTimeout
17844
17844
  });
17845
17845
  this._appHttp = (0, import_openapi_fetch2.default)({
17846
- baseUrl: APP_BASE_URL,
17846
+ baseUrl: appBaseUrl ?? APP_BASE_URL,
17847
17847
  headers: {
17848
17848
  Authorization: `Bearer ${apiKey}`,
17849
17849
  Accept: "application/json"
@@ -18744,12 +18744,12 @@ var LoggingClient = class {
18744
18744
  _loggerBuffer = new LoggerRegistrationBuffer();
18745
18745
  _loggerFlushTimer = null;
18746
18746
  /** @internal */
18747
- constructor(apiKey, ensureWs, timeout) {
18747
+ constructor(apiKey, ensureWs, timeout, baseUrl) {
18748
18748
  this._apiKey = apiKey;
18749
18749
  this._ensureWs = ensureWs;
18750
18750
  const ms = timeout ?? 3e4;
18751
18751
  this._http = (0, import_openapi_fetch3.default)({
18752
- baseUrl: LOGGING_BASE_URL,
18752
+ baseUrl: baseUrl ?? LOGGING_BASE_URL,
18753
18753
  headers: {
18754
18754
  Authorization: `Bearer ${apiKey}`,
18755
18755
  Accept: "application/json"
@@ -19491,6 +19491,7 @@ var MetricsReporter = class {
19491
19491
  _environment;
19492
19492
  _service;
19493
19493
  _flushInterval;
19494
+ _appBaseUrl;
19494
19495
  _counters = /* @__PURE__ */ new Map();
19495
19496
  _gauges = /* @__PURE__ */ new Map();
19496
19497
  _timer = null;
@@ -19500,6 +19501,7 @@ var MetricsReporter = class {
19500
19501
  this._environment = options.environment;
19501
19502
  this._service = options.service;
19502
19503
  this._flushInterval = options.flushInterval ?? 60;
19504
+ this._appBaseUrl = options.appBaseUrl ?? APP_BASE_URL2;
19503
19505
  }
19504
19506
  // ------------------------------------------------------------------
19505
19507
  // Public recording API
@@ -19576,7 +19578,7 @@ var MetricsReporter = class {
19576
19578
  if (counters.size === 0 && gauges.size === 0) return;
19577
19579
  const payload = this._buildPayload(counters, gauges);
19578
19580
  try {
19579
- fetch(`${APP_BASE_URL2}/api/v1/metrics/bulk`, {
19581
+ fetch(`${this._appBaseUrl}/api/v1/metrics/bulk`, {
19580
19582
  method: "POST",
19581
19583
  headers: {
19582
19584
  Authorization: `Bearer ${this._apiKey}`,
@@ -19615,7 +19617,6 @@ var MetricsReporter = class {
19615
19617
  };
19616
19618
 
19617
19619
  // src/client.ts
19618
- var APP_BASE_URL3 = "https://app.smplkit.com";
19619
19620
  var NO_ENVIRONMENT_MESSAGE = "No environment provided. Set one of:\n 1. Pass environment to the constructor\n 2. Set the SMPLKIT_ENVIRONMENT environment variable";
19620
19621
  var NO_SERVICE_MESSAGE = "No service provided. Set one of:\n 1. Pass service in options\n 2. Set the SMPLKIT_SERVICE environment variable";
19621
19622
  var SmplClient = class {
@@ -19634,6 +19635,7 @@ var SmplClient = class {
19634
19635
  /** @internal */
19635
19636
  _metrics = null;
19636
19637
  _timeout;
19638
+ _appBaseUrl;
19637
19639
  _appHttp;
19638
19640
  constructor(options = {}) {
19639
19641
  const environment = options.environment || process.env.SMPLKIT_ENVIRONMENT;
@@ -19649,13 +19651,20 @@ var SmplClient = class {
19649
19651
  const apiKey = resolveApiKey(options.apiKey, environment);
19650
19652
  this._apiKey = apiKey;
19651
19653
  this._timeout = options.timeout ?? 3e4;
19654
+ const baseDomain = options.baseDomain ?? "smplkit.com";
19655
+ const scheme = options.scheme ?? "https";
19656
+ const appBaseUrl = `${scheme}://app.${baseDomain}`;
19657
+ const configBaseUrl = `${scheme}://config.${baseDomain}`;
19658
+ const flagsBaseUrl = `${scheme}://flags.${baseDomain}`;
19659
+ const loggingBaseUrl = `${scheme}://logging.${baseDomain}`;
19660
+ this._appBaseUrl = appBaseUrl;
19652
19661
  const maskedKey = apiKey.length > 14 ? apiKey.slice(0, 10) + "..." + apiKey.slice(-4) : apiKey.slice(0, Math.min(4, apiKey.length)) + "...";
19653
19662
  debug(
19654
19663
  "lifecycle",
19655
19664
  `SmplClient created (api_key=${maskedKey}, environment=${environment}, service=${service})`
19656
19665
  );
19657
19666
  this._appHttp = (0, import_openapi_fetch4.default)({
19658
- baseUrl: APP_BASE_URL3,
19667
+ baseUrl: appBaseUrl,
19659
19668
  headers: {
19660
19669
  Authorization: `Bearer ${apiKey}`,
19661
19670
  Accept: "application/json"
@@ -19665,12 +19674,19 @@ var SmplClient = class {
19665
19674
  this._metrics = new MetricsReporter({
19666
19675
  apiKey,
19667
19676
  environment: this._environment,
19668
- service: this._service
19677
+ service: this._service,
19678
+ appBaseUrl
19669
19679
  });
19670
19680
  }
19671
- this.config = new ConfigClient(apiKey, this._timeout);
19672
- this.flags = new FlagsClient(apiKey, () => this._ensureWs(), this._timeout);
19673
- this.logging = new LoggingClient(apiKey, () => this._ensureWs(), this._timeout);
19681
+ this.config = new ConfigClient(apiKey, this._timeout, configBaseUrl);
19682
+ this.flags = new FlagsClient(
19683
+ apiKey,
19684
+ () => this._ensureWs(),
19685
+ this._timeout,
19686
+ flagsBaseUrl,
19687
+ appBaseUrl
19688
+ );
19689
+ this.logging = new LoggingClient(apiKey, () => this._ensureWs(), this._timeout, loggingBaseUrl);
19674
19690
  this.config._getSharedWs = () => this._ensureWs();
19675
19691
  this.flags._parent = this;
19676
19692
  this.config._parent = this;
@@ -19701,7 +19717,7 @@ var SmplClient = class {
19701
19717
  /** Lazily create and start the shared WebSocket. @internal */
19702
19718
  _ensureWs() {
19703
19719
  if (this._wsManager === null) {
19704
- this._wsManager = new SharedWebSocket(APP_BASE_URL3, this._apiKey, this._metrics);
19720
+ this._wsManager = new SharedWebSocket(this._appBaseUrl, this._apiKey, this._metrics);
19705
19721
  this._wsManager.start();
19706
19722
  }
19707
19723
  return this._wsManager;