@smplkit/sdk 1.8.4 → 1.9.1

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.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import createClient from 'openapi-fetch';
2
+
1
3
  /**
2
4
  * Internal SDK telemetry engine.
3
5
  *
@@ -906,6 +908,14 @@ declare class FlagStats {
906
908
  readonly cacheMisses: number;
907
909
  constructor(cacheHits: number, cacheMisses: number);
908
910
  }
911
+ /** @internal — exported so ManagementClient.contexts can share the same buffer. */
912
+ declare class ContextRegistrationBuffer {
913
+ private _seen;
914
+ private _pending;
915
+ observe(contexts: Context[]): void;
916
+ drain(): Array<Record<string, any>>;
917
+ get pendingCount(): number;
918
+ }
909
919
  /**
910
920
  * Management API for smplkit Flags — CRUD operations on Flag models.
911
921
  *
@@ -993,7 +1003,7 @@ declare class FlagsClient {
993
1003
  /** Management API — CRUD operations on Flag models. */
994
1004
  readonly management: FlagsManagement;
995
1005
  /** @internal */
996
- constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number, flagsBaseUrl?: string, appBaseUrl?: string);
1006
+ constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number, flagsBaseUrl?: string, appBaseUrl?: string, contextBuffer?: ContextRegistrationBuffer);
997
1007
  /** @internal */
998
1008
  _mgNewBooleanFlag(id: string, options: {
999
1009
  default: boolean;
@@ -1080,14 +1090,6 @@ declare class FlagsClient {
1080
1090
  * - `onChange(id, callback)` — fires only for the specified flag id.
1081
1091
  */
1082
1092
  onChange(callbackOrId: string | ((event: FlagChangeEvent) => void), callback?: (event: FlagChangeEvent) => void): void;
1083
- /**
1084
- * Register context(s) with the server.
1085
- *
1086
- * Accepts a single Context or an array. Works before `initialize()` is called.
1087
- */
1088
- register(context: Context | Context[]): void;
1089
- /** Flush pending context registrations to the server. */
1090
- flushContexts(): Promise<void>;
1091
1093
  /**
1092
1094
  * Evaluate a flag with an explicit environment and context.
1093
1095
  */
@@ -1139,6 +1141,31 @@ interface LoggerChangeEvent {
1139
1141
  /** True when the logger or group was deleted. */
1140
1142
  deleted?: true;
1141
1143
  }
1144
+ /**
1145
+ * Describes a logger to register via `client.logging.management.registerSources()`.
1146
+ *
1147
+ * Unlike auto-discovery (which reads the current process's logging framework),
1148
+ * `registerSources` accepts explicit `service` and `environment` overrides —
1149
+ * useful for sample-data seeding, cross-tenant migration, and test fixtures.
1150
+ */
1151
+ declare class LoggerSource {
1152
+ /** Logger name (e.g. `"sqlalchemy.engine"`). */
1153
+ readonly name: string;
1154
+ /** Service name this source belongs to. */
1155
+ readonly service: string;
1156
+ /** Environment name this source belongs to. */
1157
+ readonly environment: string;
1158
+ /** Effective log level for this source. */
1159
+ readonly resolvedLevel: LogLevel;
1160
+ /** Explicit (configured) log level, if different from `resolvedLevel`. */
1161
+ readonly level: LogLevel | null;
1162
+ constructor(name: string, options: {
1163
+ service: string;
1164
+ environment: string;
1165
+ resolved_level: LogLevel;
1166
+ level?: LogLevel | null;
1167
+ });
1168
+ }
1142
1169
 
1143
1170
  /**
1144
1171
  * Logger and LogGroup active-record models for the Logging SDK.
@@ -1155,7 +1182,7 @@ declare class Logger {
1155
1182
  /** Human-readable display name. */
1156
1183
  name: string;
1157
1184
  /** Base log level, or null if inherited. */
1158
- level: string | null;
1185
+ level: LogLevel | null;
1159
1186
  /** Id of the parent log group, or null. */
1160
1187
  group: string | null;
1161
1188
  /** Whether this logger is managed by the platform. */
@@ -1174,7 +1201,7 @@ declare class Logger {
1174
1201
  constructor(client: LoggingClient, fields: {
1175
1202
  id: string | null;
1176
1203
  name: string;
1177
- level: string | null;
1204
+ level: LogLevel | null;
1178
1205
  group: string | null;
1179
1206
  managed: boolean;
1180
1207
  sources: Array<Record<string, any>>;
@@ -1215,7 +1242,7 @@ declare class LogGroup {
1215
1242
  /** Human-readable display name. */
1216
1243
  name: string;
1217
1244
  /** Base log level, or null if inherited. */
1218
- level: string | null;
1245
+ level: LogLevel | null;
1219
1246
  /** Id of the parent log group, or null. */
1220
1247
  group: string | null;
1221
1248
  /** Per-environment level overrides. */
@@ -1231,7 +1258,7 @@ declare class LogGroup {
1231
1258
  id: string | null;
1232
1259
  key: string | null;
1233
1260
  name: string;
1234
- level: string | null;
1261
+ level: LogLevel | null;
1235
1262
  group: string | null;
1236
1263
  environments: Record<string, any>;
1237
1264
  createdAt: string | null;
@@ -1321,6 +1348,14 @@ declare class LoggingManagement {
1321
1348
  listGroups(): Promise<LogGroup[]>;
1322
1349
  /** Delete a log group by id. */
1323
1350
  deleteGroup(id: string): Promise<void>;
1351
+ /**
1352
+ * Bulk-register explicit logger sources with the logging service.
1353
+ *
1354
+ * Unlike `start()`, which auto-discovers loggers from the current
1355
+ * process, this method accepts explicit `service` and `environment`
1356
+ * overrides — useful for sample-data seeding and test fixtures.
1357
+ */
1358
+ registerSources(sources: LoggerSource[]): Promise<void>;
1324
1359
  }
1325
1360
  /**
1326
1361
  * Client for the smplkit Logging API.
@@ -1383,6 +1418,8 @@ declare class LoggingClient {
1383
1418
  /** @internal */
1384
1419
  _mgListGroups(): Promise<LogGroup[]>;
1385
1420
  /** @internal */
1421
+ _mgRegisterSources(sources: LoggerSource[]): Promise<void>;
1422
+ /** @internal */
1386
1423
  _mgDeleteGroup(id: string): Promise<void>;
1387
1424
  /** @internal — PUT a logger (upsert: server creates if not found). */
1388
1425
  _saveLogger(logger: Logger): Promise<Logger>;
@@ -1426,6 +1463,285 @@ declare class LoggingClient {
1426
1463
  private _groupToModel;
1427
1464
  }
1428
1465
 
1466
+ /**
1467
+ * Shared types for the management namespace.
1468
+ */
1469
+ /** Whether an environment participates in the canonical ordering.
1470
+ *
1471
+ * STANDARD environments are the customer's deploy targets (production,
1472
+ * staging, development, etc.) and appear in the environment_order list.
1473
+ * AD_HOC environments are transient targets (preview branches,
1474
+ * developer sandboxes) that are excluded from the standard ordering.
1475
+ */
1476
+ declare enum EnvironmentClassification {
1477
+ STANDARD = "STANDARD",
1478
+ AD_HOC = "AD_HOC"
1479
+ }
1480
+
1481
+ /**
1482
+ * Active-record models for client.management.* resources.
1483
+ */
1484
+
1485
+ /**
1486
+ * An environment resource managed by the smplkit platform.
1487
+ *
1488
+ * Mutate fields, then call `save()` to create or update.
1489
+ */
1490
+ declare class Environment {
1491
+ /** Unique slug identifier (e.g. `"production"`). */
1492
+ id: string | null;
1493
+ /** Human-readable display name. */
1494
+ name: string;
1495
+ /** Hex color code, or null. */
1496
+ color: string | null;
1497
+ /** Whether this is a STANDARD or AD_HOC environment. */
1498
+ classification: EnvironmentClassification;
1499
+ /** When the environment was created. */
1500
+ createdAt: string | null;
1501
+ /** When the environment was last updated. */
1502
+ updatedAt: string | null;
1503
+ /** @internal */
1504
+ readonly _client: EnvironmentsClient | null;
1505
+ /** @internal */
1506
+ constructor(client: EnvironmentsClient | null, fields: {
1507
+ id: string | null;
1508
+ name: string;
1509
+ color: string | null;
1510
+ classification: EnvironmentClassification;
1511
+ createdAt: string | null;
1512
+ updatedAt: string | null;
1513
+ });
1514
+ /** Persist this environment to the server (creates if new, updates if existing). */
1515
+ save(): Promise<void>;
1516
+ /** @internal */
1517
+ _apply(other: Environment): void;
1518
+ toString(): string;
1519
+ }
1520
+ /**
1521
+ * A context-type resource managed by the smplkit platform.
1522
+ *
1523
+ * Mutate fields or use `addAttribute`/`removeAttribute`/`updateAttribute`,
1524
+ * then call `save()` to persist.
1525
+ */
1526
+ declare class ContextType {
1527
+ /** Unique slug identifier (e.g. `"user"`). */
1528
+ id: string | null;
1529
+ /** Human-readable display name. */
1530
+ name: string;
1531
+ /** Known attribute keys with metadata objects. */
1532
+ attributes: Record<string, Record<string, any>>;
1533
+ /** When the context type was created. */
1534
+ createdAt: string | null;
1535
+ /** When the context type was last updated. */
1536
+ updatedAt: string | null;
1537
+ /** @internal */
1538
+ readonly _client: ContextTypesClient | null;
1539
+ /** @internal */
1540
+ constructor(client: ContextTypesClient | null, fields: {
1541
+ id: string | null;
1542
+ name: string;
1543
+ attributes: Record<string, Record<string, any>>;
1544
+ createdAt: string | null;
1545
+ updatedAt: string | null;
1546
+ });
1547
+ /** Add a known-attribute slot. Local; call `save()` to persist. */
1548
+ addAttribute(name: string, metadata?: Record<string, any>): void;
1549
+ /** Remove a known-attribute slot. Local; call `save()` to persist. */
1550
+ removeAttribute(name: string): void;
1551
+ /** Replace a known-attribute slot's metadata. Local; call `save()` to persist. */
1552
+ updateAttribute(name: string, metadata: Record<string, any>): void;
1553
+ /** Persist this context type to the server (creates if new, updates if existing). */
1554
+ save(): Promise<void>;
1555
+ /** @internal */
1556
+ _apply(other: ContextType): void;
1557
+ toString(): string;
1558
+ }
1559
+ /**
1560
+ * A context instance as returned by the management API.
1561
+ *
1562
+ * The write path is `client.management.contexts.register([...])`.
1563
+ * This model is what comes back from `list`/`get`.
1564
+ */
1565
+ declare class ContextEntity {
1566
+ /** Context type key (e.g. `"user"`). */
1567
+ type: string;
1568
+ /** Entity key (e.g. `"user-123"`). */
1569
+ key: string;
1570
+ /** Human-readable display name, or null. */
1571
+ name: string | null;
1572
+ /** Observed attributes. */
1573
+ attributes: Record<string, any>;
1574
+ /** When the context was created. */
1575
+ createdAt: string | null;
1576
+ /** When the context was last updated. */
1577
+ updatedAt: string | null;
1578
+ /** @internal */
1579
+ constructor(fields: {
1580
+ type: string;
1581
+ key: string;
1582
+ name: string | null;
1583
+ attributes: Record<string, any>;
1584
+ createdAt: string | null;
1585
+ updatedAt: string | null;
1586
+ });
1587
+ /** Composite `"type:key"` identifier. */
1588
+ get id(): string;
1589
+ toString(): string;
1590
+ }
1591
+ /**
1592
+ * Active-record account-settings model.
1593
+ *
1594
+ * The wire format is opaque JSON. Documented keys are exposed as typed
1595
+ * properties; unknown keys live in `raw`. Call `save()` to write back.
1596
+ */
1597
+ declare class AccountSettings {
1598
+ /** @internal */
1599
+ private _data;
1600
+ /** @internal */
1601
+ readonly _client: AccountSettingsClient | null;
1602
+ /** @internal */
1603
+ constructor(client: AccountSettingsClient | null, data: Record<string, any>);
1604
+ /** The full settings dict. Direct mutations are reflected in `save()`. */
1605
+ get raw(): Record<string, any>;
1606
+ set raw(value: Record<string, any>);
1607
+ /** Canonical ordering of STANDARD environments. Empty array if unset. */
1608
+ get environmentOrder(): string[];
1609
+ set environmentOrder(value: string[]);
1610
+ /** Persist the settings to the server. */
1611
+ save(): Promise<void>;
1612
+ /** @internal */
1613
+ _apply(other: AccountSettings): void;
1614
+ /** @internal — expose raw data for _save(). */
1615
+ get _rawData(): Record<string, any>;
1616
+ toString(): string;
1617
+ }
1618
+
1619
+ type AppClient = ReturnType<typeof createClient<___generated_app_d_ts.paths>>;
1620
+ /**
1621
+ * CRUD client for environments.
1622
+ *
1623
+ * Accessed via `client.management.environments`.
1624
+ */
1625
+ declare class EnvironmentsClient {
1626
+ private readonly _http;
1627
+ /** @internal */
1628
+ constructor(_http: AppClient);
1629
+ /**
1630
+ * Return an unsaved `Environment`. Call `.save()` to persist.
1631
+ */
1632
+ new(id: string, options: {
1633
+ name: string;
1634
+ color?: string | null;
1635
+ classification?: EnvironmentClassification;
1636
+ }): Environment;
1637
+ /** List all environments. */
1638
+ list(): Promise<Environment[]>;
1639
+ /** Fetch an environment by id. */
1640
+ get(id: string): Promise<Environment>;
1641
+ /** Delete an environment by id. */
1642
+ delete(id: string): Promise<void>;
1643
+ /** @internal — called by Environment.save() for new resources. */
1644
+ _create(env: Environment): Promise<Environment>;
1645
+ /** @internal — called by Environment.save() for existing resources. */
1646
+ _update(env: Environment): Promise<Environment>;
1647
+ }
1648
+ /**
1649
+ * CRUD client for context types.
1650
+ *
1651
+ * Accessed via `client.management.context_types`.
1652
+ */
1653
+ declare class ContextTypesClient {
1654
+ private readonly _http;
1655
+ /** @internal */
1656
+ constructor(_http: AppClient);
1657
+ /**
1658
+ * Return an unsaved `ContextType`. Call `.save()` to persist.
1659
+ */
1660
+ new(id: string, options?: {
1661
+ name?: string;
1662
+ attributes?: Record<string, Record<string, any>>;
1663
+ }): ContextType;
1664
+ /** List all context types. */
1665
+ list(): Promise<ContextType[]>;
1666
+ /** Fetch a context type by id. */
1667
+ get(id: string): Promise<ContextType>;
1668
+ /** Delete a context type by id. */
1669
+ delete(id: string): Promise<void>;
1670
+ /** @internal — called by ContextType.save() for new resources. */
1671
+ _create(ct: ContextType): Promise<ContextType>;
1672
+ /** @internal — called by ContextType.save() for existing resources. */
1673
+ _update(ct: ContextType): Promise<ContextType>;
1674
+ }
1675
+ /**
1676
+ * Context registration + read/delete client.
1677
+ *
1678
+ * Accessed via `client.management.contexts`.
1679
+ */
1680
+ declare class ContextsClient {
1681
+ private readonly _http;
1682
+ private readonly _buffer;
1683
+ /** @internal */
1684
+ constructor(_http: AppClient, _buffer: ContextRegistrationBuffer);
1685
+ /**
1686
+ * Buffer context(s) for registration; optionally flush immediately.
1687
+ *
1688
+ * When `flush` is false (default), contexts are queued for the SDK's
1689
+ * background flush — right for high-frequency observation from a live
1690
+ * request handler. When `flush` is true the call awaits the round-trip
1691
+ * — right for IaC scripts.
1692
+ */
1693
+ register(items: Context | Context[], options?: {
1694
+ flush?: boolean;
1695
+ }): Promise<void>;
1696
+ /** Send any pending context observations to the server. */
1697
+ flush(): Promise<void>;
1698
+ /** List all contexts of a given type. */
1699
+ list(type: string): Promise<ContextEntity[]>;
1700
+ /** Fetch a context by composite id (`"type:key"`) or by separate type and key. */
1701
+ get(idOrType: string, key?: string): Promise<ContextEntity>;
1702
+ /** Delete a context by composite id (`"type:key"`) or by separate type and key. */
1703
+ delete(idOrType: string, key?: string): Promise<void>;
1704
+ }
1705
+ /**
1706
+ * Account-settings get/save client.
1707
+ *
1708
+ * The settings endpoint is not JSON:API — body is a raw JSON object — so
1709
+ * we use fetch directly rather than the typed openapi-fetch client.
1710
+ *
1711
+ * Accessed via `client.management.account_settings`.
1712
+ */
1713
+ declare class AccountSettingsClient {
1714
+ private readonly _appBaseUrl;
1715
+ private readonly _headers;
1716
+ /** @internal */
1717
+ constructor(_appBaseUrl: string, apiKey: string);
1718
+ /** Fetch the current account settings. */
1719
+ get(): Promise<AccountSettings>;
1720
+ /** @internal — called by AccountSettings.save(). */
1721
+ _save(data: Record<string, any>): Promise<AccountSettings>;
1722
+ }
1723
+ /**
1724
+ * Top-level management namespace.
1725
+ *
1726
+ * Accessed via `client.management`.
1727
+ */
1728
+ declare class ManagementClient {
1729
+ /** CRUD for environments. */
1730
+ readonly environments: EnvironmentsClient;
1731
+ /** Registration, list, get, and delete for context instances. */
1732
+ readonly contexts: ContextsClient;
1733
+ /** CRUD for context types (entity schemas). */
1734
+ readonly context_types: ContextTypesClient;
1735
+ /** Get/save for account-level settings. */
1736
+ readonly account_settings: AccountSettingsClient;
1737
+ /** @internal */
1738
+ constructor(options: {
1739
+ appBaseUrl: string;
1740
+ apiKey: string;
1741
+ buffer: ContextRegistrationBuffer;
1742
+ });
1743
+ }
1744
+
1429
1745
  /**
1430
1746
  * Top-level SDK client — SmplClient.
1431
1747
  *
@@ -1518,6 +1834,8 @@ declare class SmplClient {
1518
1834
  readonly flags: FlagsClient;
1519
1835
  /** Client for logging management and runtime. */
1520
1836
  readonly logging: LoggingClient;
1837
+ /** Client for app-plane management (environments, contexts, context types, account settings). */
1838
+ readonly management: ManagementClient;
1521
1839
  private _wsManager;
1522
1840
  private readonly _apiKey;
1523
1841
  /** @internal */
@@ -1636,4 +1954,4 @@ declare class SmplValidationError extends SmplError {
1636
1954
  constructor(message: string, statusCode?: number, responseBody?: string, errors?: ApiErrorObject[]);
1637
1955
  }
1638
1956
 
1639
- export { type ApiErrorObject, BooleanFlag, Config, type ConfigChangeEvent, ConfigClient, ConfigManagement, Context, Flag, FlagChangeEvent, FlagStats, FlagsClient, FlagsManagement, JsonFlag, LiveConfigProxy, LogGroup, LogLevel, Logger, type LoggerChangeEvent, type LoggingAdapter, LoggingClient, LoggingManagement, NumberFlag, PinoAdapter, type PinoAdapterConfig, Rule, SharedWebSocket, SmplClient, type SmplClientOptions, SmplConflictError, SmplConnectionError, SmplError, SmplNotFoundError, SmplTimeoutError, SmplValidationError, StringFlag, WinstonAdapter, type WinstonAdapterConfig };
1957
+ export { AccountSettings, AccountSettingsClient, type ApiErrorObject, BooleanFlag, Config, type ConfigChangeEvent, ConfigClient, ConfigManagement, Context, ContextEntity, ContextType, ContextTypesClient, ContextsClient, Environment, EnvironmentClassification, EnvironmentsClient, Flag, FlagChangeEvent, FlagStats, FlagsClient, FlagsManagement, JsonFlag, LiveConfigProxy, LogGroup, LogLevel, Logger, type LoggerChangeEvent, LoggerSource, type LoggingAdapter, LoggingClient, LoggingManagement, ManagementClient, NumberFlag, PinoAdapter, type PinoAdapterConfig, Rule, SharedWebSocket, SmplClient, type SmplClientOptions, SmplConflictError, SmplConnectionError, SmplError, SmplNotFoundError, SmplTimeoutError, SmplValidationError, StringFlag, WinstonAdapter, type WinstonAdapterConfig };