@smplkit/sdk 1.3.20 → 1.3.22

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
@@ -950,6 +950,42 @@ declare class LogGroup {
950
950
  toString(): string;
951
951
  }
952
952
 
953
+ /**
954
+ * Contract for pluggable logging framework integration.
955
+ *
956
+ * Adapters bridge the smplkit logging runtime to a specific logging framework.
957
+ * The core LoggingClient delegates all framework-specific work through this interface.
958
+ *
959
+ * Adapters are NOT responsible for: key normalization, caching, bulk registration,
960
+ * level resolution, or WebSocket handling. Those remain in the core client.
961
+ */
962
+ interface LoggingAdapter {
963
+ /** Human-readable adapter name for diagnostics (e.g., 'winston'). */
964
+ readonly name: string;
965
+ /**
966
+ * Scan the runtime for existing loggers.
967
+ * Returns an array of { name, level } where level is a smplkit level string.
968
+ */
969
+ discover(): Array<{
970
+ name: string;
971
+ level: string;
972
+ }>;
973
+ /**
974
+ * Set the level on a specific logger.
975
+ * @param loggerName - The original (non-normalized) logger name.
976
+ * @param level - smplkit level string (e.g., 'DEBUG', 'INFO', 'WARN').
977
+ */
978
+ applyLevel(loggerName: string, level: string): void;
979
+ /**
980
+ * Install continuous discovery hook.
981
+ * The callback receives (original_name, smplkit_level_string) whenever
982
+ * a new logger is created in the framework.
983
+ */
984
+ installHook(onNewLogger: (name: string, level: string) => void): void;
985
+ /** Remove the hook installed by installHook(). Called on client close(). */
986
+ uninstallHook(): void;
987
+ }
988
+
953
989
  /**
954
990
  * LoggingClient — management plane + scaffolded runtime for Smpl Logging.
955
991
  *
@@ -979,8 +1015,17 @@ declare class LoggingClient {
979
1015
  private _started;
980
1016
  private _globalListeners;
981
1017
  private _keyListeners;
1018
+ private _adapters;
1019
+ private _explicitAdapters;
982
1020
  /** @internal */
983
1021
  constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
1022
+ /**
1023
+ * Register a logging framework adapter.
1024
+ *
1025
+ * Must be called before `start()`. Disables auto-loading of built-in
1026
+ * adapters — only explicitly registered adapters will be used.
1027
+ */
1028
+ registerAdapter(adapter: LoggingAdapter): void;
984
1029
  /** Create an unsaved logger. Call `.save()` to persist. */
985
1030
  new(key: string, options?: {
986
1031
  name?: string;
@@ -1010,11 +1055,17 @@ declare class LoggingClient {
1010
1055
  /**
1011
1056
  * Start the logging runtime.
1012
1057
  *
1013
- * Fetches existing loggers/groups and wires WebSocket listeners for
1014
- * live updates. Idempotent safe to call multiple times.
1058
+ * Performs the full runtime pipeline:
1059
+ * 1. Auto-load adapters (if none registered explicitly)
1060
+ * 2. Discover existing loggers from each adapter
1061
+ * 3. Install hooks on each adapter for new logger creation
1062
+ * 4. Bulk-register discovered loggers with the server
1063
+ * 5. Fetch all loggers and groups from the server
1064
+ * 6. Resolve levels and apply to adapters
1065
+ * 7. Wire WebSocket for live updates
1015
1066
  *
1016
- * Note: Node.js auto-discovery (equivalent to Python's logging module
1017
- * monkey-patching) is deferred. Management methods work without start().
1067
+ * Idempotent safe to call multiple times.
1068
+ * Management methods work without start().
1018
1069
  */
1019
1070
  start(): Promise<void>;
1020
1071
  /**
@@ -1026,6 +1077,12 @@ declare class LoggingClient {
1026
1077
  onChange(callbackOrKey: string | ((event: LoggerChangeEvent) => void), callback?: (event: LoggerChangeEvent) => void): void;
1027
1078
  /** @internal */
1028
1079
  _close(): void;
1080
+ /** Auto-load built-in adapters by attempting to require each framework. */
1081
+ private _autoLoadAdapters;
1082
+ /** Apply resolved levels from server loggers to all adapters. */
1083
+ private _applyLevels;
1084
+ /** Called by adapter hooks when a new logger is created in the framework. */
1085
+ private _onAdapterNewLogger;
1029
1086
  private _handleLoggerChanged;
1030
1087
  private _loggerToModel;
1031
1088
  private _groupToModel;
@@ -1109,6 +1166,68 @@ declare class SmplClient {
1109
1166
  close(): void;
1110
1167
  }
1111
1168
 
1169
+ /**
1170
+ * Winston logging framework adapter.
1171
+ *
1172
+ * Bridges the smplkit logging runtime to winston's logger container.
1173
+ * Discovers loggers via `winston.loggers` (the Container), hooks into
1174
+ * new logger creation by monkey-patching `Container.add()`, and applies
1175
+ * levels by setting `logger.level` on the winston logger instance.
1176
+ */
1177
+
1178
+ interface WinstonAdapterConfig {
1179
+ /** Whether to include the default logger in discovery (default: true). */
1180
+ discoverDefault?: boolean;
1181
+ /** @internal — inject a winston module for testing. */
1182
+ _winston?: unknown;
1183
+ }
1184
+ declare class WinstonAdapter implements LoggingAdapter {
1185
+ readonly name = "winston";
1186
+ private readonly _discoverDefault;
1187
+ private _winston;
1188
+ private _originalAdd;
1189
+ constructor(config?: WinstonAdapterConfig);
1190
+ discover(): Array<{
1191
+ name: string;
1192
+ level: string;
1193
+ }>;
1194
+ applyLevel(loggerName: string, level: string): void;
1195
+ installHook(onNewLogger: (name: string, level: string) => void): void;
1196
+ uninstallHook(): void;
1197
+ }
1198
+
1199
+ /**
1200
+ * Pino logging framework adapter.
1201
+ *
1202
+ * Pino has no global logger registry. This adapter builds its own internal
1203
+ * registry by monkey-patching the pino module's default export and the
1204
+ * `child()` method on created loggers. Logger instances are tracked via
1205
+ * WeakRef to avoid memory leaks.
1206
+ */
1207
+
1208
+ interface PinoAdapterConfig {
1209
+ /** Which binding field to use as the logger name (default: 'name'). */
1210
+ nameField?: string;
1211
+ /** @internal — inject a pino module for testing. */
1212
+ _pino?: unknown;
1213
+ }
1214
+ declare class PinoAdapter implements LoggingAdapter {
1215
+ readonly name = "pino";
1216
+ private readonly _nameField;
1217
+ private _pino;
1218
+ private _registry;
1219
+ private _originalPino;
1220
+ private _pinoModule;
1221
+ constructor(config?: PinoAdapterConfig);
1222
+ discover(): Array<{
1223
+ name: string;
1224
+ level: string;
1225
+ }>;
1226
+ applyLevel(loggerName: string, level: string): void;
1227
+ installHook(onNewLogger: (name: string, level: string) => void): void;
1228
+ uninstallHook(): void;
1229
+ }
1230
+
1112
1231
  /**
1113
1232
  * Structured SDK error types.
1114
1233
  *
@@ -1155,4 +1274,4 @@ declare class SmplValidationError extends SmplError {
1155
1274
  constructor(message: string, statusCode?: number, responseBody?: string, errors?: ApiErrorObject[]);
1156
1275
  }
1157
1276
 
1158
- export { type ApiErrorObject, BooleanFlag, Config, type ConfigChangeEvent, ConfigClient, Context, Flag, FlagChangeEvent, FlagStats, FlagsClient, JsonFlag, LiveConfigProxy, LogGroup, LogLevel, Logger, type LoggerChangeEvent, LoggingClient, NumberFlag, Rule, SharedWebSocket, SmplClient, type SmplClientOptions, SmplConflictError, SmplConnectionError, SmplError, SmplNotFoundError, SmplTimeoutError, SmplValidationError, StringFlag };
1277
+ export { type ApiErrorObject, BooleanFlag, Config, type ConfigChangeEvent, ConfigClient, Context, Flag, FlagChangeEvent, FlagStats, FlagsClient, JsonFlag, LiveConfigProxy, LogGroup, LogLevel, Logger, type LoggerChangeEvent, type LoggingAdapter, LoggingClient, NumberFlag, PinoAdapter, type PinoAdapterConfig, Rule, SharedWebSocket, SmplClient, type SmplClientOptions, SmplConflictError, SmplConnectionError, SmplError, SmplNotFoundError, SmplTimeoutError, SmplValidationError, StringFlag, WinstonAdapter, type WinstonAdapterConfig };
package/dist/index.d.ts CHANGED
@@ -950,6 +950,42 @@ declare class LogGroup {
950
950
  toString(): string;
951
951
  }
952
952
 
953
+ /**
954
+ * Contract for pluggable logging framework integration.
955
+ *
956
+ * Adapters bridge the smplkit logging runtime to a specific logging framework.
957
+ * The core LoggingClient delegates all framework-specific work through this interface.
958
+ *
959
+ * Adapters are NOT responsible for: key normalization, caching, bulk registration,
960
+ * level resolution, or WebSocket handling. Those remain in the core client.
961
+ */
962
+ interface LoggingAdapter {
963
+ /** Human-readable adapter name for diagnostics (e.g., 'winston'). */
964
+ readonly name: string;
965
+ /**
966
+ * Scan the runtime for existing loggers.
967
+ * Returns an array of { name, level } where level is a smplkit level string.
968
+ */
969
+ discover(): Array<{
970
+ name: string;
971
+ level: string;
972
+ }>;
973
+ /**
974
+ * Set the level on a specific logger.
975
+ * @param loggerName - The original (non-normalized) logger name.
976
+ * @param level - smplkit level string (e.g., 'DEBUG', 'INFO', 'WARN').
977
+ */
978
+ applyLevel(loggerName: string, level: string): void;
979
+ /**
980
+ * Install continuous discovery hook.
981
+ * The callback receives (original_name, smplkit_level_string) whenever
982
+ * a new logger is created in the framework.
983
+ */
984
+ installHook(onNewLogger: (name: string, level: string) => void): void;
985
+ /** Remove the hook installed by installHook(). Called on client close(). */
986
+ uninstallHook(): void;
987
+ }
988
+
953
989
  /**
954
990
  * LoggingClient — management plane + scaffolded runtime for Smpl Logging.
955
991
  *
@@ -979,8 +1015,17 @@ declare class LoggingClient {
979
1015
  private _started;
980
1016
  private _globalListeners;
981
1017
  private _keyListeners;
1018
+ private _adapters;
1019
+ private _explicitAdapters;
982
1020
  /** @internal */
983
1021
  constructor(apiKey: string, ensureWs: () => SharedWebSocket, timeout?: number);
1022
+ /**
1023
+ * Register a logging framework adapter.
1024
+ *
1025
+ * Must be called before `start()`. Disables auto-loading of built-in
1026
+ * adapters — only explicitly registered adapters will be used.
1027
+ */
1028
+ registerAdapter(adapter: LoggingAdapter): void;
984
1029
  /** Create an unsaved logger. Call `.save()` to persist. */
985
1030
  new(key: string, options?: {
986
1031
  name?: string;
@@ -1010,11 +1055,17 @@ declare class LoggingClient {
1010
1055
  /**
1011
1056
  * Start the logging runtime.
1012
1057
  *
1013
- * Fetches existing loggers/groups and wires WebSocket listeners for
1014
- * live updates. Idempotent safe to call multiple times.
1058
+ * Performs the full runtime pipeline:
1059
+ * 1. Auto-load adapters (if none registered explicitly)
1060
+ * 2. Discover existing loggers from each adapter
1061
+ * 3. Install hooks on each adapter for new logger creation
1062
+ * 4. Bulk-register discovered loggers with the server
1063
+ * 5. Fetch all loggers and groups from the server
1064
+ * 6. Resolve levels and apply to adapters
1065
+ * 7. Wire WebSocket for live updates
1015
1066
  *
1016
- * Note: Node.js auto-discovery (equivalent to Python's logging module
1017
- * monkey-patching) is deferred. Management methods work without start().
1067
+ * Idempotent safe to call multiple times.
1068
+ * Management methods work without start().
1018
1069
  */
1019
1070
  start(): Promise<void>;
1020
1071
  /**
@@ -1026,6 +1077,12 @@ declare class LoggingClient {
1026
1077
  onChange(callbackOrKey: string | ((event: LoggerChangeEvent) => void), callback?: (event: LoggerChangeEvent) => void): void;
1027
1078
  /** @internal */
1028
1079
  _close(): void;
1080
+ /** Auto-load built-in adapters by attempting to require each framework. */
1081
+ private _autoLoadAdapters;
1082
+ /** Apply resolved levels from server loggers to all adapters. */
1083
+ private _applyLevels;
1084
+ /** Called by adapter hooks when a new logger is created in the framework. */
1085
+ private _onAdapterNewLogger;
1029
1086
  private _handleLoggerChanged;
1030
1087
  private _loggerToModel;
1031
1088
  private _groupToModel;
@@ -1109,6 +1166,68 @@ declare class SmplClient {
1109
1166
  close(): void;
1110
1167
  }
1111
1168
 
1169
+ /**
1170
+ * Winston logging framework adapter.
1171
+ *
1172
+ * Bridges the smplkit logging runtime to winston's logger container.
1173
+ * Discovers loggers via `winston.loggers` (the Container), hooks into
1174
+ * new logger creation by monkey-patching `Container.add()`, and applies
1175
+ * levels by setting `logger.level` on the winston logger instance.
1176
+ */
1177
+
1178
+ interface WinstonAdapterConfig {
1179
+ /** Whether to include the default logger in discovery (default: true). */
1180
+ discoverDefault?: boolean;
1181
+ /** @internal — inject a winston module for testing. */
1182
+ _winston?: unknown;
1183
+ }
1184
+ declare class WinstonAdapter implements LoggingAdapter {
1185
+ readonly name = "winston";
1186
+ private readonly _discoverDefault;
1187
+ private _winston;
1188
+ private _originalAdd;
1189
+ constructor(config?: WinstonAdapterConfig);
1190
+ discover(): Array<{
1191
+ name: string;
1192
+ level: string;
1193
+ }>;
1194
+ applyLevel(loggerName: string, level: string): void;
1195
+ installHook(onNewLogger: (name: string, level: string) => void): void;
1196
+ uninstallHook(): void;
1197
+ }
1198
+
1199
+ /**
1200
+ * Pino logging framework adapter.
1201
+ *
1202
+ * Pino has no global logger registry. This adapter builds its own internal
1203
+ * registry by monkey-patching the pino module's default export and the
1204
+ * `child()` method on created loggers. Logger instances are tracked via
1205
+ * WeakRef to avoid memory leaks.
1206
+ */
1207
+
1208
+ interface PinoAdapterConfig {
1209
+ /** Which binding field to use as the logger name (default: 'name'). */
1210
+ nameField?: string;
1211
+ /** @internal — inject a pino module for testing. */
1212
+ _pino?: unknown;
1213
+ }
1214
+ declare class PinoAdapter implements LoggingAdapter {
1215
+ readonly name = "pino";
1216
+ private readonly _nameField;
1217
+ private _pino;
1218
+ private _registry;
1219
+ private _originalPino;
1220
+ private _pinoModule;
1221
+ constructor(config?: PinoAdapterConfig);
1222
+ discover(): Array<{
1223
+ name: string;
1224
+ level: string;
1225
+ }>;
1226
+ applyLevel(loggerName: string, level: string): void;
1227
+ installHook(onNewLogger: (name: string, level: string) => void): void;
1228
+ uninstallHook(): void;
1229
+ }
1230
+
1112
1231
  /**
1113
1232
  * Structured SDK error types.
1114
1233
  *
@@ -1155,4 +1274,4 @@ declare class SmplValidationError extends SmplError {
1155
1274
  constructor(message: string, statusCode?: number, responseBody?: string, errors?: ApiErrorObject[]);
1156
1275
  }
1157
1276
 
1158
- export { type ApiErrorObject, BooleanFlag, Config, type ConfigChangeEvent, ConfigClient, Context, Flag, FlagChangeEvent, FlagStats, FlagsClient, JsonFlag, LiveConfigProxy, LogGroup, LogLevel, Logger, type LoggerChangeEvent, LoggingClient, NumberFlag, Rule, SharedWebSocket, SmplClient, type SmplClientOptions, SmplConflictError, SmplConnectionError, SmplError, SmplNotFoundError, SmplTimeoutError, SmplValidationError, StringFlag };
1277
+ export { type ApiErrorObject, BooleanFlag, Config, type ConfigChangeEvent, ConfigClient, Context, Flag, FlagChangeEvent, FlagStats, FlagsClient, JsonFlag, LiveConfigProxy, LogGroup, LogLevel, Logger, type LoggerChangeEvent, type LoggingAdapter, LoggingClient, NumberFlag, PinoAdapter, type PinoAdapterConfig, Rule, SharedWebSocket, SmplClient, type SmplClientOptions, SmplConflictError, SmplConnectionError, SmplError, SmplNotFoundError, SmplTimeoutError, SmplValidationError, StringFlag, WinstonAdapter, type WinstonAdapterConfig };