@smplkit/sdk 1.0.0 → 1.1.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.js CHANGED
@@ -1,35 +1,9 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ import {
2
+ ConfigRuntime
3
+ } from "./chunk-PZD5PSQY.js";
19
4
 
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- ConfigClient: () => ConfigClient,
24
- SmplConflictError: () => SmplConflictError,
25
- SmplConnectionError: () => SmplConnectionError,
26
- SmplError: () => SmplError,
27
- SmplNotFoundError: () => SmplNotFoundError,
28
- SmplTimeoutError: () => SmplTimeoutError,
29
- SmplValidationError: () => SmplValidationError,
30
- SmplkitClient: () => SmplkitClient
31
- });
32
- module.exports = __toCommonJS(index_exports);
5
+ // src/config/client.ts
6
+ import createClient from "openapi-fetch";
33
7
 
34
8
  // src/errors.ts
35
9
  var SmplError = class extends Error {
@@ -81,277 +55,439 @@ var SmplValidationError = class extends SmplError {
81
55
  }
82
56
  };
83
57
 
84
- // src/config/client.ts
85
- var CONFIGS_PATH = "/api/v1/configs";
86
- var ConfigClient = class {
87
- /** @internal */
88
- transport;
58
+ // src/config/types.ts
59
+ var Config = class {
60
+ /** UUID of the config. */
61
+ id;
62
+ /** Human-readable key (e.g. `"user_service"`). */
63
+ key;
64
+ /** Display name. */
65
+ name;
66
+ /** Optional description. */
67
+ description;
68
+ /** Parent config UUID, or null if this is a root config. */
69
+ parent;
70
+ /** Base key-value pairs. */
71
+ values;
72
+ /**
73
+ * Per-environment overrides.
74
+ * Stored as `{ env_name: { values: { key: value } } }` to match the
75
+ * server's format.
76
+ */
77
+ environments;
78
+ /** When the config was created, or null if unavailable. */
79
+ createdAt;
80
+ /** When the config was last updated, or null if unavailable. */
81
+ updatedAt;
82
+ /**
83
+ * Internal reference to the parent client.
84
+ * @internal
85
+ */
86
+ _client;
89
87
  /** @internal */
90
- constructor(transport) {
91
- this.transport = transport;
88
+ constructor(client, fields) {
89
+ this._client = client;
90
+ this.id = fields.id;
91
+ this.key = fields.key;
92
+ this.name = fields.name;
93
+ this.description = fields.description;
94
+ this.parent = fields.parent;
95
+ this.values = fields.values;
96
+ this.environments = fields.environments;
97
+ this.createdAt = fields.createdAt;
98
+ this.updatedAt = fields.updatedAt;
92
99
  }
93
100
  /**
94
- * Fetch a single config by key or UUID.
101
+ * Update this config's attributes on the server.
95
102
  *
96
- * Exactly one of `key` or `id` must be provided.
103
+ * Builds the request from current attribute values, overriding with any
104
+ * provided options. Updates local attributes in place on success.
97
105
  *
98
- * @param options - Lookup options.
99
- * @returns The matching config.
100
- * @throws {SmplNotFoundError} If no matching config exists.
101
- * @throws {Error} If neither or both of `key` and `id` are provided.
106
+ * @param options.name - New display name.
107
+ * @param options.description - New description (pass empty string to clear).
108
+ * @param options.values - New base values (replaces entirely).
109
+ * @param options.environments - New environments dict (replaces entirely).
102
110
  */
103
- async get(options) {
104
- const { key, id } = options;
105
- if (key === void 0 === (id === void 0)) {
106
- throw new Error("Exactly one of 'key' or 'id' must be provided.");
107
- }
108
- if (id !== void 0) {
109
- return this.getById(id);
110
- }
111
- return this.getByKey(key);
111
+ async update(options) {
112
+ const updated = await this._client._updateConfig({
113
+ configId: this.id,
114
+ name: options.name ?? this.name,
115
+ key: this.key,
116
+ description: options.description !== void 0 ? options.description : this.description,
117
+ parent: this.parent,
118
+ values: options.values ?? this.values,
119
+ environments: options.environments ?? this.environments
120
+ });
121
+ this.name = updated.name;
122
+ this.description = updated.description;
123
+ this.values = updated.values;
124
+ this.environments = updated.environments;
125
+ this.updatedAt = updated.updatedAt;
112
126
  }
113
127
  /**
114
- * List all configs for the account.
128
+ * Replace base or environment-specific values.
115
129
  *
116
- * @returns An array of config objects.
130
+ * When `environment` is provided, replaces that environment's `values`
131
+ * sub-dict (other environments are preserved). When omitted, replaces
132
+ * the base `values`.
133
+ *
134
+ * @param values - The complete set of values to set.
135
+ * @param environment - Target environment, or omit for base values.
117
136
  */
118
- async list() {
119
- const response = await this.transport.get(CONFIGS_PATH);
120
- const resources = response.data;
121
- return resources.map((r) => this.resourceToModel(r));
137
+ async setValues(values, environment) {
138
+ let newValues;
139
+ let newEnvs;
140
+ if (environment === void 0) {
141
+ newValues = values;
142
+ newEnvs = this.environments;
143
+ } else {
144
+ newValues = this.values;
145
+ const existingEntry = typeof this.environments[environment] === "object" && this.environments[environment] !== null ? { ...this.environments[environment] } : {};
146
+ existingEntry.values = values;
147
+ newEnvs = { ...this.environments, [environment]: existingEntry };
148
+ }
149
+ const updated = await this._client._updateConfig({
150
+ configId: this.id,
151
+ name: this.name,
152
+ key: this.key,
153
+ description: this.description,
154
+ parent: this.parent,
155
+ values: newValues,
156
+ environments: newEnvs
157
+ });
158
+ this.values = updated.values;
159
+ this.environments = updated.environments;
160
+ this.updatedAt = updated.updatedAt;
122
161
  }
123
162
  /**
124
- * Create a new config.
163
+ * Set a single key within base or environment-specific values.
125
164
  *
126
- * @param options - Config creation options.
127
- * @returns The created config.
128
- * @throws {SmplValidationError} If the server rejects the request.
165
+ * Merges the key into existing values rather than replacing all values.
166
+ *
167
+ * @param key - The config key to set.
168
+ * @param value - The value to assign.
169
+ * @param environment - Target environment, or omit for base values.
129
170
  */
130
- async create(options) {
131
- const body = this.buildRequestBody(options);
132
- const response = await this.transport.post(CONFIGS_PATH, body);
133
- if (!response.data) {
134
- throw new SmplValidationError("Failed to create config");
171
+ async setValue(key, value, environment) {
172
+ if (environment === void 0) {
173
+ const merged = { ...this.values, [key]: value };
174
+ await this.setValues(merged);
175
+ } else {
176
+ const envEntry = typeof this.environments[environment] === "object" && this.environments[environment] !== null ? this.environments[environment] : {};
177
+ const existing = {
178
+ ...typeof envEntry.values === "object" && envEntry.values !== null ? envEntry.values : {}
179
+ };
180
+ existing[key] = value;
181
+ await this.setValues(existing, environment);
135
182
  }
136
- return this.resourceToModel(response.data);
137
183
  }
138
184
  /**
139
- * Delete a config by UUID.
185
+ * Connect to this config for runtime value resolution.
140
186
  *
141
- * @param configId - The UUID of the config to delete.
142
- * @throws {SmplNotFoundError} If the config does not exist.
143
- * @throws {SmplConflictError} If the config has children.
187
+ * Eagerly fetches this config and its full parent chain, resolves values
188
+ * for the given environment via deep merge, and returns a
189
+ * {@link ConfigRuntime} with a fully populated local cache.
190
+ *
191
+ * A background WebSocket connection is started for real-time updates.
192
+ * If the WebSocket fails to connect, the runtime operates in cache-only
193
+ * mode and reconnects automatically.
194
+ *
195
+ * Supports both `await` and `await using` (TypeScript 5.2+)::
196
+ *
197
+ * ```typescript
198
+ * // Simple await
199
+ * const runtime = await config.connect("production");
200
+ * try { ... } finally { await runtime.close(); }
201
+ *
202
+ * // await using (auto-close)
203
+ * await using runtime = await config.connect("production");
204
+ * ```
205
+ *
206
+ * @param environment - The environment to resolve for (e.g. `"production"`).
207
+ * @param options.timeout - Milliseconds to wait for the initial fetch.
144
208
  */
145
- async delete(configId) {
146
- await this.transport.delete(`${CONFIGS_PATH}/${configId}`);
147
- }
148
- /** Fetch a config by UUID. */
149
- async getById(configId) {
150
- const response = await this.transport.get(`${CONFIGS_PATH}/${configId}`);
151
- if (!response.data) {
152
- throw new SmplNotFoundError(`Config ${configId} not found`);
153
- }
154
- return this.resourceToModel(response.data);
155
- }
156
- /** Fetch a config by key using the list endpoint with a filter. */
157
- async getByKey(key) {
158
- const response = await this.transport.get(CONFIGS_PATH, { "filter[key]": key });
159
- const resources = response.data;
160
- if (!resources || resources.length === 0) {
161
- throw new SmplNotFoundError(`Config with key '${key}' not found`);
162
- }
163
- return this.resourceToModel(resources[0]);
209
+ async connect(environment, options) {
210
+ const { ConfigRuntime: ConfigRuntime2 } = await import("./runtime-CCRTBKED.js");
211
+ const timeout = options?.timeout ?? 3e4;
212
+ const chain = await this._buildChain(timeout);
213
+ return new ConfigRuntime2({
214
+ configKey: this.key,
215
+ configId: this.id,
216
+ environment,
217
+ chain,
218
+ apiKey: this._client._apiKey,
219
+ baseUrl: this._client._baseUrl,
220
+ fetchChain: () => this._buildChain(timeout)
221
+ });
164
222
  }
165
223
  /**
166
- * Convert a JSON:API resource to a Config domain model.
224
+ * Walk the parent chain and return config data objects, child-to-root.
167
225
  * @internal
168
226
  */
169
- resourceToModel(resource) {
170
- const attrs = resource.attributes;
171
- return {
172
- id: resource.id,
173
- key: attrs.key ?? "",
174
- name: attrs.name,
175
- description: attrs.description ?? null,
176
- parent: attrs.parent ?? null,
177
- values: attrs.values ?? {},
178
- environments: attrs.environments ?? {},
179
- createdAt: attrs.created_at ? new Date(attrs.created_at) : null,
180
- updatedAt: attrs.updated_at ? new Date(attrs.updated_at) : null
181
- };
227
+ async _buildChain(_timeout) {
228
+ const chain = [{ id: this.id, values: this.values, environments: this.environments }];
229
+ let parentId = this.parent;
230
+ while (parentId !== null) {
231
+ const parentConfig = await this._client.get({ id: parentId });
232
+ chain.push({
233
+ id: parentConfig.id,
234
+ values: parentConfig.values,
235
+ environments: parentConfig.environments
236
+ });
237
+ parentId = parentConfig.parent;
238
+ }
239
+ return chain;
182
240
  }
183
- /** Build a JSON:API request body for create operations. */
184
- buildRequestBody(options) {
185
- const attributes = {
186
- name: options.name
187
- };
188
- if (options.key !== void 0) attributes.key = options.key;
189
- if (options.description !== void 0) attributes.description = options.description;
190
- if (options.parent !== void 0) attributes.parent = options.parent;
191
- if (options.values !== void 0) attributes.values = options.values;
192
- return {
193
- data: {
194
- type: "config",
195
- attributes
196
- }
197
- };
241
+ toString() {
242
+ return `Config(id=${this.id}, key=${this.key}, name=${this.name})`;
198
243
  }
199
244
  };
200
245
 
201
- // src/auth.ts
202
- function buildAuthHeader(apiKey) {
203
- return `Bearer ${apiKey}`;
246
+ // src/config/client.ts
247
+ var BASE_URL = "https://config.smplkit.com";
248
+ function resourceToConfig(resource, client) {
249
+ const attrs = resource.attributes;
250
+ return new Config(client, {
251
+ id: resource.id ?? "",
252
+ key: attrs.key ?? "",
253
+ name: attrs.name,
254
+ description: attrs.description ?? null,
255
+ parent: attrs.parent ?? null,
256
+ values: attrs.values ?? {},
257
+ environments: attrs.environments ?? {},
258
+ createdAt: attrs.created_at ? new Date(attrs.created_at) : null,
259
+ updatedAt: attrs.updated_at ? new Date(attrs.updated_at) : null
260
+ });
204
261
  }
205
-
206
- // src/transport.ts
207
- var SDK_VERSION = "0.0.0";
208
- var DEFAULT_TIMEOUT_MS = 3e4;
209
- var Transport = class {
210
- apiKey;
211
- baseUrl;
212
- timeout;
213
- constructor(options) {
214
- this.apiKey = options.apiKey;
215
- this.baseUrl = options.baseUrl.replace(/\/+$/, "");
216
- this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
262
+ async function checkError(response, context) {
263
+ const body = await response.text().catch(() => "");
264
+ switch (response.status) {
265
+ case 404:
266
+ throw new SmplNotFoundError(body || context, 404, body);
267
+ case 409:
268
+ throw new SmplConflictError(body || context, 409, body);
269
+ case 422:
270
+ throw new SmplValidationError(body || context, 422, body);
271
+ default:
272
+ throw new SmplError(`HTTP ${response.status}: ${body}`, response.status, body);
273
+ }
274
+ }
275
+ function wrapFetchError(err) {
276
+ if (err instanceof SmplNotFoundError || err instanceof SmplConflictError || err instanceof SmplValidationError || err instanceof SmplError) {
277
+ throw err;
278
+ }
279
+ if (err instanceof TypeError) {
280
+ throw new SmplConnectionError(`Network error: ${err.message}`);
281
+ }
282
+ throw new SmplConnectionError(
283
+ `Request failed: ${err instanceof Error ? err.message : String(err)}`
284
+ );
285
+ }
286
+ function buildRequestBody(options) {
287
+ const attrs = {
288
+ name: options.name
289
+ };
290
+ if (options.key !== void 0) attrs.key = options.key;
291
+ if (options.description !== void 0) attrs.description = options.description;
292
+ if (options.parent !== void 0) attrs.parent = options.parent;
293
+ if (options.values !== void 0)
294
+ attrs.values = options.values;
295
+ if (options.environments !== void 0)
296
+ attrs.environments = options.environments;
297
+ return {
298
+ data: {
299
+ id: options.id ?? null,
300
+ type: "config",
301
+ attributes: attrs
302
+ }
303
+ };
304
+ }
305
+ var ConfigClient = class {
306
+ /** @internal — used by Config instances for reconnecting and WebSocket auth. */
307
+ _apiKey;
308
+ /** @internal */
309
+ _baseUrl = BASE_URL;
310
+ /** @internal */
311
+ _http;
312
+ /** @internal */
313
+ constructor(apiKey, timeout) {
314
+ this._apiKey = apiKey;
315
+ const ms = timeout ?? 3e4;
316
+ this._http = createClient({
317
+ baseUrl: BASE_URL,
318
+ headers: {
319
+ Authorization: `Bearer ${apiKey}`,
320
+ Accept: "application/json"
321
+ },
322
+ // openapi-fetch custom fetch receives a pre-built Request object
323
+ fetch: async (request) => {
324
+ const controller = new AbortController();
325
+ const timer = setTimeout(() => controller.abort(), ms);
326
+ try {
327
+ return await fetch(new Request(request, { signal: controller.signal }));
328
+ } catch (err) {
329
+ if (err instanceof DOMException && err.name === "AbortError") {
330
+ throw new SmplTimeoutError(`Request timed out after ${ms}ms`);
331
+ }
332
+ throw err;
333
+ } finally {
334
+ clearTimeout(timer);
335
+ }
336
+ }
337
+ });
217
338
  }
218
339
  /**
219
- * Send a GET request.
340
+ * Fetch a single config by key or UUID.
341
+ *
342
+ * Exactly one of `key` or `id` must be provided.
220
343
  *
221
- * @param path - URL path relative to `baseUrl` (e.g. `/api/v1/configs`).
222
- * @param params - Optional query parameters.
223
- * @returns Parsed JSON response body.
344
+ * @throws {SmplNotFoundError} If no matching config exists.
224
345
  */
225
- async get(path, params) {
226
- return this.request("GET", path, void 0, params);
346
+ async get(options) {
347
+ const { key, id } = options;
348
+ if (key === void 0 === (id === void 0)) {
349
+ throw new Error("Exactly one of 'key' or 'id' must be provided.");
350
+ }
351
+ return id !== void 0 ? this._getById(id) : this._getByKey(key);
227
352
  }
228
353
  /**
229
- * Send a POST request with a JSON body.
230
- *
231
- * @param path - URL path relative to `baseUrl`.
232
- * @param body - JSON-serializable request body.
233
- * @returns Parsed JSON response body.
354
+ * List all configs for the account.
234
355
  */
235
- async post(path, body) {
236
- return this.request("POST", path, body);
356
+ async list() {
357
+ let data;
358
+ try {
359
+ const result = await this._http.GET("/api/v1/configs", {});
360
+ if (result.error !== void 0) await checkError(result.response, "Failed to list configs");
361
+ data = result.data;
362
+ } catch (err) {
363
+ wrapFetchError(err);
364
+ }
365
+ if (!data) return [];
366
+ return data.data.map((r) => resourceToConfig(r, this));
237
367
  }
238
368
  /**
239
- * Send a PUT request with a JSON body.
369
+ * Create a new config.
240
370
  *
241
- * @param path - URL path relative to `baseUrl`.
242
- * @param body - JSON-serializable request body.
243
- * @returns Parsed JSON response body.
371
+ * @throws {SmplValidationError} If the server rejects the request.
244
372
  */
245
- async put(path, body) {
246
- return this.request("PUT", path, body);
373
+ async create(options) {
374
+ const body = buildRequestBody({
375
+ name: options.name,
376
+ key: options.key,
377
+ description: options.description,
378
+ parent: options.parent,
379
+ values: options.values
380
+ });
381
+ let data;
382
+ try {
383
+ const result = await this._http.POST("/api/v1/configs", { body });
384
+ if (result.error !== void 0) await checkError(result.response, "Failed to create config");
385
+ data = result.data;
386
+ } catch (err) {
387
+ wrapFetchError(err);
388
+ }
389
+ if (!data || !data.data) throw new SmplValidationError("Failed to create config");
390
+ return resourceToConfig(data.data, this);
247
391
  }
248
392
  /**
249
- * Send a DELETE request.
393
+ * Delete a config by UUID.
250
394
  *
251
- * @param path - URL path relative to `baseUrl`.
252
- * @returns Parsed JSON response body (empty object for 204 responses).
395
+ * @throws {SmplNotFoundError} If the config does not exist.
396
+ * @throws {SmplConflictError} If the config has child configs.
253
397
  */
254
- async delete(path) {
255
- return this.request("DELETE", path);
398
+ async delete(configId) {
399
+ try {
400
+ const result = await this._http.DELETE("/api/v1/configs/{id}", {
401
+ params: { path: { id: configId } }
402
+ });
403
+ if (result.error !== void 0 && result.response.status !== 204)
404
+ await checkError(result.response, `Failed to delete config ${configId}`);
405
+ } catch (err) {
406
+ wrapFetchError(err);
407
+ }
256
408
  }
257
409
  /**
258
- * Core request method. Handles headers, timeouts, and error mapping.
410
+ * Internal: PUT a full config update and return the updated model.
411
+ *
412
+ * Called by {@link Config} instance methods.
413
+ * @internal
259
414
  */
260
- async request(method, path, body, params) {
261
- let url = `${this.baseUrl}${path}`;
262
- if (params) {
263
- const searchParams = new URLSearchParams(params);
264
- url += `?${searchParams.toString()}`;
265
- }
266
- const headers = {
267
- Authorization: buildAuthHeader(this.apiKey),
268
- "User-Agent": `smplkit-typescript-sdk/${SDK_VERSION}`,
269
- Accept: "application/vnd.api+json"
270
- };
271
- if (body !== void 0) {
272
- headers["Content-Type"] = "application/vnd.api+json";
273
- }
274
- const controller = new AbortController();
275
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
276
- let response;
415
+ async _updateConfig(payload) {
416
+ const body = buildRequestBody({
417
+ id: payload.configId,
418
+ name: payload.name,
419
+ key: payload.key,
420
+ description: payload.description,
421
+ parent: payload.parent,
422
+ values: payload.values,
423
+ environments: payload.environments
424
+ });
425
+ let data;
277
426
  try {
278
- response = await fetch(url, {
279
- method,
280
- headers,
281
- body: body !== void 0 ? JSON.stringify(body) : void 0,
282
- signal: controller.signal
427
+ const result = await this._http.PUT("/api/v1/configs/{id}", {
428
+ params: { path: { id: payload.configId } },
429
+ body
283
430
  });
284
- } catch (error) {
285
- clearTimeout(timeoutId);
286
- if (error instanceof DOMException && error.name === "AbortError") {
287
- throw new SmplTimeoutError(`Request timed out after ${this.timeout}ms`);
288
- }
289
- if (error instanceof TypeError) {
290
- throw new SmplConnectionError(`Network error: ${error.message}`);
291
- }
292
- throw new SmplConnectionError(
293
- `Request failed: ${error instanceof Error ? error.message : String(error)}`
294
- );
295
- } finally {
296
- clearTimeout(timeoutId);
297
- }
298
- if (response.status === 204) {
299
- return {};
300
- }
301
- const responseText = await response.text();
302
- if (!response.ok) {
303
- this.throwForStatus(response.status, responseText);
431
+ if (result.error !== void 0)
432
+ await checkError(result.response, `Failed to update config ${payload.configId}`);
433
+ data = result.data;
434
+ } catch (err) {
435
+ wrapFetchError(err);
304
436
  }
437
+ if (!data || !data.data)
438
+ throw new SmplValidationError(`Failed to update config ${payload.configId}`);
439
+ return resourceToConfig(data.data, this);
440
+ }
441
+ // ---- Private helpers ----
442
+ async _getById(configId) {
443
+ let data;
305
444
  try {
306
- return JSON.parse(responseText);
307
- } catch {
308
- throw new SmplError(`Invalid JSON response: ${responseText}`, response.status, responseText);
445
+ const result = await this._http.GET("/api/v1/configs/{id}", {
446
+ params: { path: { id: configId } }
447
+ });
448
+ if (result.error !== void 0)
449
+ await checkError(result.response, `Config ${configId} not found`);
450
+ data = result.data;
451
+ } catch (err) {
452
+ wrapFetchError(err);
309
453
  }
454
+ if (!data || !data.data) throw new SmplNotFoundError(`Config ${configId} not found`);
455
+ return resourceToConfig(data.data, this);
310
456
  }
311
- /**
312
- * Map HTTP error status codes to typed SDK exceptions.
313
- *
314
- * @throws {SmplNotFoundError} On 404.
315
- * @throws {SmplConflictError} On 409.
316
- * @throws {SmplValidationError} On 422.
317
- * @throws {SmplError} On any other non-2xx status.
318
- */
319
- throwForStatus(status, body) {
320
- switch (status) {
321
- case 404:
322
- throw new SmplNotFoundError(body, 404, body);
323
- case 409:
324
- throw new SmplConflictError(body, 409, body);
325
- case 422:
326
- throw new SmplValidationError(body, 422, body);
327
- default:
328
- throw new SmplError(`HTTP ${status}: ${body}`, status, body);
457
+ async _getByKey(key) {
458
+ let data;
459
+ try {
460
+ const result = await this._http.GET("/api/v1/configs", {
461
+ params: { query: { "filter[key]": key } }
462
+ });
463
+ if (result.error !== void 0)
464
+ await checkError(result.response, `Config with key '${key}' not found`);
465
+ data = result.data;
466
+ } catch (err) {
467
+ wrapFetchError(err);
468
+ }
469
+ if (!data || !data.data || data.data.length === 0) {
470
+ throw new SmplNotFoundError(`Config with key '${key}' not found`);
329
471
  }
472
+ return resourceToConfig(data.data[0], this);
330
473
  }
331
474
  };
332
475
 
333
476
  // src/client.ts
334
- var DEFAULT_BASE_URL = "https://config.smplkit.com";
335
477
  var SmplkitClient = class {
336
478
  /** Client for config management-plane operations. */
337
479
  config;
338
- /** @internal */
339
- transport;
340
480
  constructor(options) {
341
481
  if (!options.apiKey) {
342
482
  throw new Error("apiKey is required");
343
483
  }
344
- this.transport = new Transport({
345
- apiKey: options.apiKey,
346
- baseUrl: options.baseUrl ?? DEFAULT_BASE_URL,
347
- timeout: options.timeout
348
- });
349
- this.config = new ConfigClient(this.transport);
484
+ this.config = new ConfigClient(options.apiKey, options.timeout);
350
485
  }
351
486
  };
352
- // Annotate the CommonJS export names for ESM import in node:
353
- 0 && (module.exports = {
487
+ export {
488
+ Config,
354
489
  ConfigClient,
490
+ ConfigRuntime,
355
491
  SmplConflictError,
356
492
  SmplConnectionError,
357
493
  SmplError,
@@ -359,5 +495,5 @@ var SmplkitClient = class {
359
495
  SmplTimeoutError,
360
496
  SmplValidationError,
361
497
  SmplkitClient
362
- });
498
+ };
363
499
  //# sourceMappingURL=index.js.map