@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.d.cts CHANGED
@@ -13,6 +13,7 @@ declare class MetricsReporter {
13
13
  private readonly _environment;
14
14
  private readonly _service;
15
15
  private readonly _flushInterval;
16
+ private readonly _appBaseUrl;
16
17
  private _counters;
17
18
  private _gauges;
18
19
  private _timer;
@@ -22,6 +23,7 @@ declare class MetricsReporter {
22
23
  environment: string;
23
24
  service: string;
24
25
  flushInterval?: number;
26
+ appBaseUrl?: string;
25
27
  });
26
28
  record(name: string, value?: number, unit?: string | null, dimensions?: Record<string, string>): void;
27
29
  recordGauge(name: string, value: number, unit?: string | null, dimensions?: Record<string, string>): void;
@@ -223,7 +225,7 @@ declare class ConfigClient {
223
225
  private _initialized;
224
226
  private _listeners;
225
227
  /** @internal */
226
- constructor(apiKey: string, timeout?: number);
228
+ constructor(apiKey: string, timeout?: number, baseUrl?: string);
227
229
  /** @internal */
228
230
  _mgNew(id: string, options?: {
229
231
  name?: string;
@@ -922,7 +924,7 @@ declare class FlagsClient {
922
924
  /** Management API — CRUD operations on Flag models. */
923
925
  readonly management: FlagsManagement;
924
926
  /** @internal */
925
- constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
927
+ constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number, flagsBaseUrl?: string, appBaseUrl?: string);
926
928
  /** @internal */
927
929
  _mgNewBooleanFlag(id: string, options: {
928
930
  default: boolean;
@@ -1273,7 +1275,7 @@ declare class LoggingClient {
1273
1275
  private _loggerBuffer;
1274
1276
  private _loggerFlushTimer;
1275
1277
  /** @internal */
1276
- constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
1278
+ constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number, baseUrl?: string);
1277
1279
  /**
1278
1280
  * Register a logging framework adapter.
1279
1281
  *
@@ -1375,6 +1377,18 @@ interface SmplClientOptions {
1375
1377
  * @default false
1376
1378
  */
1377
1379
  disableTelemetry?: boolean;
1380
+ /**
1381
+ * Base domain for all smplkit service URLs.
1382
+ * Override for local development (e.g. `"localhost"`).
1383
+ * @default "smplkit.com"
1384
+ */
1385
+ baseDomain?: string;
1386
+ /**
1387
+ * URL scheme used when constructing service URLs.
1388
+ * Override for local development (e.g. `"http"`).
1389
+ * @default "https"
1390
+ */
1391
+ scheme?: string;
1378
1392
  }
1379
1393
  /**
1380
1394
  * Entry point for the smplkit TypeScript SDK.
@@ -1414,6 +1428,7 @@ declare class SmplClient {
1414
1428
  /** @internal */
1415
1429
  readonly _metrics: MetricsReporter | null;
1416
1430
  private readonly _timeout;
1431
+ private readonly _appBaseUrl;
1417
1432
  private readonly _appHttp;
1418
1433
  constructor(options?: SmplClientOptions);
1419
1434
  /** @internal */
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ declare class MetricsReporter {
13
13
  private readonly _environment;
14
14
  private readonly _service;
15
15
  private readonly _flushInterval;
16
+ private readonly _appBaseUrl;
16
17
  private _counters;
17
18
  private _gauges;
18
19
  private _timer;
@@ -22,6 +23,7 @@ declare class MetricsReporter {
22
23
  environment: string;
23
24
  service: string;
24
25
  flushInterval?: number;
26
+ appBaseUrl?: string;
25
27
  });
26
28
  record(name: string, value?: number, unit?: string | null, dimensions?: Record<string, string>): void;
27
29
  recordGauge(name: string, value: number, unit?: string | null, dimensions?: Record<string, string>): void;
@@ -223,7 +225,7 @@ declare class ConfigClient {
223
225
  private _initialized;
224
226
  private _listeners;
225
227
  /** @internal */
226
- constructor(apiKey: string, timeout?: number);
228
+ constructor(apiKey: string, timeout?: number, baseUrl?: string);
227
229
  /** @internal */
228
230
  _mgNew(id: string, options?: {
229
231
  name?: string;
@@ -922,7 +924,7 @@ declare class FlagsClient {
922
924
  /** Management API — CRUD operations on Flag models. */
923
925
  readonly management: FlagsManagement;
924
926
  /** @internal */
925
- constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
927
+ constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number, flagsBaseUrl?: string, appBaseUrl?: string);
926
928
  /** @internal */
927
929
  _mgNewBooleanFlag(id: string, options: {
928
930
  default: boolean;
@@ -1273,7 +1275,7 @@ declare class LoggingClient {
1273
1275
  private _loggerBuffer;
1274
1276
  private _loggerFlushTimer;
1275
1277
  /** @internal */
1276
- constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
1278
+ constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number, baseUrl?: string);
1277
1279
  /**
1278
1280
  * Register a logging framework adapter.
1279
1281
  *
@@ -1375,6 +1377,18 @@ interface SmplClientOptions {
1375
1377
  * @default false
1376
1378
  */
1377
1379
  disableTelemetry?: boolean;
1380
+ /**
1381
+ * Base domain for all smplkit service URLs.
1382
+ * Override for local development (e.g. `"localhost"`).
1383
+ * @default "smplkit.com"
1384
+ */
1385
+ baseDomain?: string;
1386
+ /**
1387
+ * URL scheme used when constructing service URLs.
1388
+ * Override for local development (e.g. `"http"`).
1389
+ * @default "https"
1390
+ */
1391
+ scheme?: string;
1378
1392
  }
1379
1393
  /**
1380
1394
  * Entry point for the smplkit TypeScript SDK.
@@ -1414,6 +1428,7 @@ declare class SmplClient {
1414
1428
  /** @internal */
1415
1429
  readonly _metrics: MetricsReporter | null;
1416
1430
  private readonly _timeout;
1431
+ private readonly _appBaseUrl;
1417
1432
  private readonly _appHttp;
1418
1433
  constructor(options?: SmplClientOptions);
1419
1434
  /** @internal */
package/dist/index.js CHANGED
@@ -17056,11 +17056,11 @@ var ConfigClient = class {
17056
17056
  _initialized = false;
17057
17057
  _listeners = [];
17058
17058
  /** @internal */
17059
- constructor(apiKey, timeout) {
17059
+ constructor(apiKey, timeout, baseUrl) {
17060
17060
  this._apiKey = apiKey;
17061
17061
  const ms = timeout ?? 3e4;
17062
17062
  this._http = createClient({
17063
- baseUrl: BASE_URL,
17063
+ baseUrl: baseUrl ?? BASE_URL,
17064
17064
  headers: {
17065
17065
  Authorization: `Bearer ${apiKey}`,
17066
17066
  Accept: "application/json"
@@ -17775,7 +17775,7 @@ var FlagsClient = class {
17775
17775
  /** Management API — CRUD operations on Flag models. */
17776
17776
  management;
17777
17777
  /** @internal */
17778
- constructor(apiKey, ensureWs, timeout) {
17778
+ constructor(apiKey, ensureWs, timeout, flagsBaseUrl, appBaseUrl) {
17779
17779
  this._apiKey = apiKey;
17780
17780
  this._ensureWs = ensureWs;
17781
17781
  const ms = timeout ?? 3e4;
@@ -17794,7 +17794,7 @@ var FlagsClient = class {
17794
17794
  }
17795
17795
  };
17796
17796
  this._http = createClient2({
17797
- baseUrl: FLAGS_BASE_URL,
17797
+ baseUrl: flagsBaseUrl ?? FLAGS_BASE_URL,
17798
17798
  headers: {
17799
17799
  Authorization: `Bearer ${apiKey}`,
17800
17800
  Accept: "application/json"
@@ -17802,7 +17802,7 @@ var FlagsClient = class {
17802
17802
  fetch: fetchWithTimeout
17803
17803
  });
17804
17804
  this._appHttp = createClient2({
17805
- baseUrl: APP_BASE_URL,
17805
+ baseUrl: appBaseUrl ?? APP_BASE_URL,
17806
17806
  headers: {
17807
17807
  Authorization: `Bearer ${apiKey}`,
17808
17808
  Accept: "application/json"
@@ -18703,12 +18703,12 @@ var LoggingClient = class {
18703
18703
  _loggerBuffer = new LoggerRegistrationBuffer();
18704
18704
  _loggerFlushTimer = null;
18705
18705
  /** @internal */
18706
- constructor(apiKey, ensureWs, timeout) {
18706
+ constructor(apiKey, ensureWs, timeout, baseUrl) {
18707
18707
  this._apiKey = apiKey;
18708
18708
  this._ensureWs = ensureWs;
18709
18709
  const ms = timeout ?? 3e4;
18710
18710
  this._http = createClient3({
18711
- baseUrl: LOGGING_BASE_URL,
18711
+ baseUrl: baseUrl ?? LOGGING_BASE_URL,
18712
18712
  headers: {
18713
18713
  Authorization: `Bearer ${apiKey}`,
18714
18714
  Accept: "application/json"
@@ -19450,6 +19450,7 @@ var MetricsReporter = class {
19450
19450
  _environment;
19451
19451
  _service;
19452
19452
  _flushInterval;
19453
+ _appBaseUrl;
19453
19454
  _counters = /* @__PURE__ */ new Map();
19454
19455
  _gauges = /* @__PURE__ */ new Map();
19455
19456
  _timer = null;
@@ -19459,6 +19460,7 @@ var MetricsReporter = class {
19459
19460
  this._environment = options.environment;
19460
19461
  this._service = options.service;
19461
19462
  this._flushInterval = options.flushInterval ?? 60;
19463
+ this._appBaseUrl = options.appBaseUrl ?? APP_BASE_URL2;
19462
19464
  }
19463
19465
  // ------------------------------------------------------------------
19464
19466
  // Public recording API
@@ -19535,7 +19537,7 @@ var MetricsReporter = class {
19535
19537
  if (counters.size === 0 && gauges.size === 0) return;
19536
19538
  const payload = this._buildPayload(counters, gauges);
19537
19539
  try {
19538
- fetch(`${APP_BASE_URL2}/api/v1/metrics/bulk`, {
19540
+ fetch(`${this._appBaseUrl}/api/v1/metrics/bulk`, {
19539
19541
  method: "POST",
19540
19542
  headers: {
19541
19543
  Authorization: `Bearer ${this._apiKey}`,
@@ -19574,7 +19576,6 @@ var MetricsReporter = class {
19574
19576
  };
19575
19577
 
19576
19578
  // src/client.ts
19577
- var APP_BASE_URL3 = "https://app.smplkit.com";
19578
19579
  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";
19579
19580
  var NO_SERVICE_MESSAGE = "No service provided. Set one of:\n 1. Pass service in options\n 2. Set the SMPLKIT_SERVICE environment variable";
19580
19581
  var SmplClient = class {
@@ -19593,6 +19594,7 @@ var SmplClient = class {
19593
19594
  /** @internal */
19594
19595
  _metrics = null;
19595
19596
  _timeout;
19597
+ _appBaseUrl;
19596
19598
  _appHttp;
19597
19599
  constructor(options = {}) {
19598
19600
  const environment = options.environment || process.env.SMPLKIT_ENVIRONMENT;
@@ -19608,13 +19610,20 @@ var SmplClient = class {
19608
19610
  const apiKey = resolveApiKey(options.apiKey, environment);
19609
19611
  this._apiKey = apiKey;
19610
19612
  this._timeout = options.timeout ?? 3e4;
19613
+ const baseDomain = options.baseDomain ?? "smplkit.com";
19614
+ const scheme = options.scheme ?? "https";
19615
+ const appBaseUrl = `${scheme}://app.${baseDomain}`;
19616
+ const configBaseUrl = `${scheme}://config.${baseDomain}`;
19617
+ const flagsBaseUrl = `${scheme}://flags.${baseDomain}`;
19618
+ const loggingBaseUrl = `${scheme}://logging.${baseDomain}`;
19619
+ this._appBaseUrl = appBaseUrl;
19611
19620
  const maskedKey = apiKey.length > 14 ? apiKey.slice(0, 10) + "..." + apiKey.slice(-4) : apiKey.slice(0, Math.min(4, apiKey.length)) + "...";
19612
19621
  debug(
19613
19622
  "lifecycle",
19614
19623
  `SmplClient created (api_key=${maskedKey}, environment=${environment}, service=${service})`
19615
19624
  );
19616
19625
  this._appHttp = createClient4({
19617
- baseUrl: APP_BASE_URL3,
19626
+ baseUrl: appBaseUrl,
19618
19627
  headers: {
19619
19628
  Authorization: `Bearer ${apiKey}`,
19620
19629
  Accept: "application/json"
@@ -19624,12 +19633,19 @@ var SmplClient = class {
19624
19633
  this._metrics = new MetricsReporter({
19625
19634
  apiKey,
19626
19635
  environment: this._environment,
19627
- service: this._service
19636
+ service: this._service,
19637
+ appBaseUrl
19628
19638
  });
19629
19639
  }
19630
- this.config = new ConfigClient(apiKey, this._timeout);
19631
- this.flags = new FlagsClient(apiKey, () => this._ensureWs(), this._timeout);
19632
- this.logging = new LoggingClient(apiKey, () => this._ensureWs(), this._timeout);
19640
+ this.config = new ConfigClient(apiKey, this._timeout, configBaseUrl);
19641
+ this.flags = new FlagsClient(
19642
+ apiKey,
19643
+ () => this._ensureWs(),
19644
+ this._timeout,
19645
+ flagsBaseUrl,
19646
+ appBaseUrl
19647
+ );
19648
+ this.logging = new LoggingClient(apiKey, () => this._ensureWs(), this._timeout, loggingBaseUrl);
19633
19649
  this.config._getSharedWs = () => this._ensureWs();
19634
19650
  this.flags._parent = this;
19635
19651
  this.config._parent = this;
@@ -19660,7 +19676,7 @@ var SmplClient = class {
19660
19676
  /** Lazily create and start the shared WebSocket. @internal */
19661
19677
  _ensureWs() {
19662
19678
  if (this._wsManager === null) {
19663
- this._wsManager = new SharedWebSocket(APP_BASE_URL3, this._apiKey, this._metrics);
19679
+ this._wsManager = new SharedWebSocket(this._appBaseUrl, this._apiKey, this._metrics);
19664
19680
  this._wsManager.start();
19665
19681
  }
19666
19682
  return this._wsManager;