@liteguard/liteguard-node 0.2.20260314 → 0.3.20260315

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/README.md CHANGED
@@ -16,7 +16,7 @@ npm install @liteguard/liteguard-node
16
16
  ```ts
17
17
  import { LiteguardClient } from "@liteguard/liteguard-node";
18
18
 
19
- const client = await LiteguardClient.create("pckid-...", {
19
+ const client = await LiteguardClient.create("pct-...", {
20
20
  environment: "production",
21
21
  });
22
22
 
@@ -47,4 +47,4 @@ await client.shutdown();
47
47
 
48
48
  ## License
49
49
 
50
- Apache 2.0 see [LICENSE](https://github.com/liteguard/liteguard/blob/main/LICENSE).
50
+ Apache 2.0 see [LICENSE](https://github.com/liteguard/liteguard/blob/main/LICENSE).
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BaseLiteguardClient, ClientOptions } from '@liteguard/core';
2
- export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard, GuardCheckPerformance, GuardExecutionPerformance, LiteguardChangeListener, LiteguardScope, Operator, Options, Properties, PropertyValue, ProtectedContext, Rule, ScopedOptions, SendUnadoptedGuardsRequest, SendUnadoptedGuardsResponse, Signal, SignalPerformance, TraceContext, evaluateGuard } from '@liteguard/core';
2
+ export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard, GuardCheckPerformance, GuardExecutionPerformance, LiteguardChangeListener, LiteguardScope, Operator, Options, Properties, PropertyValue, ProtectedContext, Rule, ScopedOptions, SendUnadoptedGuardsRequest, SendUnadoptedGuardsResponse, Signal, SignalPerformance, TraceContext, UnadoptedGuardObservation, evaluateGuard } from '@liteguard/core';
3
3
 
4
4
  /**
5
5
  * Liteguard client for Node.js environments.
@@ -11,7 +11,7 @@ export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard
11
11
  * ```ts
12
12
  * import { LiteguardClient } from '@liteguard/liteguard-node';
13
13
  *
14
- * const client = new LiteguardClient('pk_live_...');
14
+ * const client = new LiteguardClient('pctok_live_...');
15
15
  * await client.start();
16
16
  *
17
17
  * if (client.isOpen('feature.beta')) {
@@ -21,10 +21,10 @@ export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard
21
21
  */
22
22
  declare class LiteguardClient extends BaseLiteguardClient {
23
23
  /**
24
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
24
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
25
25
  * @param options - Optional SDK configuration overrides.
26
26
  */
27
- constructor(projectClientKeyId: string, options?: ClientOptions);
27
+ constructor(projectClientToken: string, options?: ClientOptions);
28
28
  }
29
29
 
30
30
  export { LiteguardClient };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BaseLiteguardClient, ClientOptions } from '@liteguard/core';
2
- export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard, GuardCheckPerformance, GuardExecutionPerformance, LiteguardChangeListener, LiteguardScope, Operator, Options, Properties, PropertyValue, ProtectedContext, Rule, ScopedOptions, SendUnadoptedGuardsRequest, SendUnadoptedGuardsResponse, Signal, SignalPerformance, TraceContext, evaluateGuard } from '@liteguard/core';
2
+ export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard, GuardCheckPerformance, GuardExecutionPerformance, LiteguardChangeListener, LiteguardScope, Operator, Options, Properties, PropertyValue, ProtectedContext, Rule, ScopedOptions, SendUnadoptedGuardsRequest, SendUnadoptedGuardsResponse, Signal, SignalPerformance, TraceContext, UnadoptedGuardObservation, evaluateGuard } from '@liteguard/core';
3
3
 
4
4
  /**
5
5
  * Liteguard client for Node.js environments.
@@ -11,7 +11,7 @@ export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard
11
11
  * ```ts
12
12
  * import { LiteguardClient } from '@liteguard/liteguard-node';
13
13
  *
14
- * const client = new LiteguardClient('pk_live_...');
14
+ * const client = new LiteguardClient('pctok_live_...');
15
15
  * await client.start();
16
16
  *
17
17
  * if (client.isOpen('feature.beta')) {
@@ -21,10 +21,10 @@ export { ClientOptions, FlushOptions, GetGuardsRequest, GetGuardsResponse, Guard
21
21
  */
22
22
  declare class LiteguardClient extends BaseLiteguardClient {
23
23
  /**
24
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
24
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
25
25
  * @param options - Optional SDK configuration overrides.
26
26
  */
27
- constructor(projectClientKeyId: string, options?: ClientOptions);
27
+ constructor(projectClientToken: string, options?: ClientOptions);
28
28
  }
29
29
 
30
30
  export { LiteguardClient };
package/dist/index.js CHANGED
@@ -113,11 +113,11 @@ var nodeRuntime = {
113
113
  // src/client.ts
114
114
  var LiteguardClient = class extends import_core.BaseLiteguardClient {
115
115
  /**
116
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
116
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
117
117
  * @param options - Optional SDK configuration overrides.
118
118
  */
119
- constructor(projectClientKeyId, options = {}) {
120
- super(nodeRuntime, projectClientKeyId, options);
119
+ constructor(projectClientToken, options = {}) {
120
+ super(nodeRuntime, projectClientToken, options);
121
121
  }
122
122
  };
123
123
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/runtime.ts"],"sourcesContent":["export type {\n GetGuardsRequest,\n GetGuardsResponse,\n Guard,\n GuardCheckPerformance,\n GuardExecutionPerformance,\n ClientOptions,\n FlushOptions,\n LiteguardChangeListener,\n LiteguardScope,\n Options,\n Operator,\n Properties,\n PropertyValue,\n ProtectedContext,\n Rule,\n SendUnadoptedGuardsRequest,\n SendUnadoptedGuardsResponse,\n Signal,\n SignalPerformance,\n ScopedOptions,\n TraceContext,\n} from '@liteguard/core';\nexport { evaluateGuard } from '@liteguard/core';\nexport { LiteguardClient } from './client.js';\n","import { BaseLiteguardClient } from '@liteguard/core';\nimport type { ClientOptions } from '@liteguard/core';\nimport { nodeRuntime } from './runtime.js';\n\n/**\n * Liteguard client for Node.js environments.\n *\n * Uses `AsyncLocalStorage` for per-request scope propagation and\n * `process.hrtime` / `process.memoryUsage` for performance measurement.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-node';\n *\n * const client = new LiteguardClient('pk_live_...');\n * await client.start();\n *\n * if (client.isOpen('feature.beta')) {\n * // new code path\n * }\n * ```\n */\nexport class LiteguardClient extends BaseLiteguardClient {\n /**\n * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.\n * @param options - Optional SDK configuration overrides.\n */\n constructor(projectClientKeyId: string, options: ClientOptions = {}) {\n super(nodeRuntime, projectClientKeyId, options);\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\nconst executionStorage = new AsyncLocalStorage<ExecutionState>();\nconst requestScopeStorage = new AsyncLocalStorage<RequestScopeStore>();\n\nconst executionAdapter: ExecutionAdapter = {\n /** Return the current execution context for correlated signal emission. */\n getStore(): ExecutionState | undefined {\n return executionStorage.getStore();\n },\n /** Run a callback inside a new correlated execution context. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n return executionStorage.run(initialState, fn);\n },\n};\n\nconst requestScopeAdapter: RequestScopeAdapter = {\n /** Return the current request-scope context for this async call chain. */\n getStore(): RequestScopeStore | undefined {\n return requestScopeStorage.getStore();\n },\n /** Run a callback with a request scope bound to the current async chain. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n return requestScopeStorage.run(initialState, fn);\n },\n};\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a high-resolution start time for a guarded execution. */\n beginGuardExecution(): bigint {\n return process.hrtime.bigint();\n },\n /** Capture point-in-time runtime metrics for a `guard_check` signal. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n return {\n guardCheck: {\n rssBytes: memoryUsage.rss,\n heapUsedBytes: memoryUsage.heapUsed,\n heapTotalBytes: memoryUsage.heapTotal,\n cpuTimeNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n },\n };\n },\n /** Capture completion metrics for a guarded code path on Node.js. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'bigint' ? startToken : process.hrtime.bigint();\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n const durationNs = Number(process.hrtime.bigint() - start);\n return {\n guardExecution: {\n durationNs,\n rssEndBytes: memoryUsage.rss,\n heapUsedEndBytes: memoryUsage.heapUsed,\n heapTotalEndBytes: memoryUsage.heapTotal,\n cpuTimeEndNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\n/** Node.js runtime adapter used by the platform-specific Liteguard client. */\nexport const nodeRuntime: RuntimeAdapter = {\n name: 'node',\n supportsAsyncContextPropagation: true,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-node/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => performance.now(),\n fetch: (input, init) => globalThis.fetch(input, init),\n setTimeout: (callback, ms) => globalThis.setTimeout(callback, ms),\n clearTimeout: (handle) => globalThis.clearTimeout(handle as ReturnType<typeof setTimeout>),\n setInterval: (callback, ms) => globalThis.setInterval(callback, ms),\n clearInterval: (handle) => globalThis.clearInterval(handle as ReturnType<typeof setInterval>),\n detachTimer: (handle) => {\n const maybeTimer = handle as { unref?: () => void };\n maybeTimer.unref?.();\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AO,SAAS,UAAU;AAAA,QAClD;AAAA,QACA,GAAI,SAAS,iBAAiB,SAAS,MAAM,OAAO,EAAE,YAAY,MAAM,KAAK,IAAI,CAAC;AAAA,MACpF;AAAA,IACF;AAAA,EACF;AACF;AAGO,IAAM,cAA8B;AAAA,EACzC,MAAM;AAAA,EACN,iCAAiC;AAAA,EACjC,sBAAsB,CAAC,uBAAuB,iCAAiC,mBAAmB;AAAA,EAClG,WAAW;AAAA,EACX,cAAc;AAAA,EACd,aAAa;AAAA,EACb,KAAK,MAAM,KAAK,IAAI;AAAA,EACpB,cAAc,MAAM,YAAY,IAAI;AAAA,EACpC,OAAO,CAAC,OAAO,SAAS,WAAW,MAAM,OAAO,IAAI;AAAA,EACpD,YAAY,CAAC,UAAU,OAAO,WAAW,WAAW,UAAU,EAAE;AAAA,EAChE,cAAc,CAAC,WAAW,WAAW,aAAa,MAAuC;AAAA,EACzF,aAAa,CAAC,UAAU,OAAO,WAAW,YAAY,UAAU,EAAE;AAAA,EAClE,eAAe,CAAC,WAAW,WAAW,cAAc,MAAwC;AAAA,EAC5F,aAAa,CAAC,WAAW;AACvB,UAAM,aAAa;AACnB,eAAW,QAAQ;AAAA,EACrB;AACF;;;ADvEO,IAAM,kBAAN,cAA8B,gCAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,aAAa,oBAAoB,OAAO;AAAA,EAChD;AACF;","names":["import_core"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/runtime.ts"],"sourcesContent":["export type {\n GetGuardsRequest,\n GetGuardsResponse,\n Guard,\n GuardCheckPerformance,\n GuardExecutionPerformance,\n ClientOptions,\n FlushOptions,\n LiteguardChangeListener,\n LiteguardScope,\n Options,\n Operator,\n Properties,\n PropertyValue,\n ProtectedContext,\n Rule,\n UnadoptedGuardObservation,\n SendUnadoptedGuardsRequest,\n SendUnadoptedGuardsResponse,\n Signal,\n SignalPerformance,\n ScopedOptions,\n TraceContext,\n} from '@liteguard/core';\nexport { evaluateGuard } from '@liteguard/core';\nexport { LiteguardClient } from './client.js';\n","import { BaseLiteguardClient } from '@liteguard/core';\nimport type { ClientOptions } from '@liteguard/core';\nimport { nodeRuntime } from './runtime.js';\n\n/**\n * Liteguard client for Node.js environments.\n *\n * Uses `AsyncLocalStorage` for per-request scope propagation and\n * `process.hrtime` / `process.memoryUsage` for performance measurement.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-node';\n *\n * const client = new LiteguardClient('pctok_live_...');\n * await client.start();\n *\n * if (client.isOpen('feature.beta')) {\n * // new code path\n * }\n * ```\n */\nexport class LiteguardClient extends BaseLiteguardClient {\n /**\n * @param projectClientToken - Your project client token from the Liteguard dashboard.\n * @param options - Optional SDK configuration overrides.\n */\n constructor(projectClientToken: string, options: ClientOptions = {}) {\n super(nodeRuntime, projectClientToken, options);\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\nconst executionStorage = new AsyncLocalStorage<ExecutionState>();\nconst requestScopeStorage = new AsyncLocalStorage<RequestScopeStore>();\n\nconst executionAdapter: ExecutionAdapter = {\n /** Return the current execution context for correlated signal emission. */\n getStore(): ExecutionState | undefined {\n return executionStorage.getStore();\n },\n /** Run a callback inside a new correlated execution context. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n return executionStorage.run(initialState, fn);\n },\n};\n\nconst requestScopeAdapter: RequestScopeAdapter = {\n /** Return the current request-scope context for this async call chain. */\n getStore(): RequestScopeStore | undefined {\n return requestScopeStorage.getStore();\n },\n /** Run a callback with a request scope bound to the current async chain. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n return requestScopeStorage.run(initialState, fn);\n },\n};\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a high-resolution start time for a guarded execution. */\n beginGuardExecution(): bigint {\n return process.hrtime.bigint();\n },\n /** Capture point-in-time runtime metrics for a `guard_check` signal. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n return {\n guardCheck: {\n rssBytes: memoryUsage.rss,\n heapUsedBytes: memoryUsage.heapUsed,\n heapTotalBytes: memoryUsage.heapTotal,\n cpuTimeNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n },\n };\n },\n /** Capture completion metrics for a guarded code path on Node.js. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'bigint' ? startToken : process.hrtime.bigint();\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n const durationNs = Number(process.hrtime.bigint() - start);\n return {\n guardExecution: {\n durationNs,\n rssEndBytes: memoryUsage.rss,\n heapUsedEndBytes: memoryUsage.heapUsed,\n heapTotalEndBytes: memoryUsage.heapTotal,\n cpuTimeEndNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\n/** Node.js runtime adapter used by the platform-specific Liteguard client. */\nexport const nodeRuntime: RuntimeAdapter = {\n name: 'node',\n supportsAsyncContextPropagation: true,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-node/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => performance.now(),\n fetch: (input, init) => globalThis.fetch(input, init),\n setTimeout: (callback, ms) => globalThis.setTimeout(callback, ms),\n clearTimeout: (handle) => globalThis.clearTimeout(handle as ReturnType<typeof setTimeout>),\n setInterval: (callback, ms) => globalThis.setInterval(callback, ms),\n clearInterval: (handle) => globalThis.clearInterval(handle as ReturnType<typeof setInterval>),\n detachTimer: (handle) => {\n const maybeTimer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d;AAAA,QACA,aAAa,YAAY;AAAA,QACzB,kBAAkB,YAAY;AAAA,QAC9B,mBAAmB,YAAY;AAAA,QAC/B,eAAe,SAAS,OAAO,SAAS,UAAU;AAAA,QAClD;AAAA,QACA,GAAI,SAAS,iBAAiB,SAAS,MAAM,OAAO,EAAE,YAAY,MAAM,KAAK,IAAI,CAAC;AAAA,MACpF;AAAA,IACF;AAAA,EACF;AACF;AAGO,IAAM,cAA8B;AAAA,EACzC,MAAM;AAAA,EACN,iCAAiC;AAAA,EACjC,sBAAsB,CAAC,uBAAuB,iCAAiC,mBAAmB;AAAA,EAClG,WAAW;AAAA,EACX,cAAc;AAAA,EACd,aAAa;AAAA,EACb,KAAK,MAAM,KAAK,IAAI;AAAA,EACpB,cAAc,MAAM,YAAY,IAAI;AAAA,EACpC,OAAO,CAAC,OAAO,SAAS,WAAW,MAAM,OAAO,IAAI;AAAA,EACpD,YAAY,CAAC,UAAU,OAAO,WAAW,WAAW,UAAU,EAAE;AAAA,EAChE,cAAc,CAAC,WAAW,WAAW,aAAa,MAAuC;AAAA,EACzF,aAAa,CAAC,UAAU,OAAO,WAAW,YAAY,UAAU,EAAE;AAAA,EAClE,eAAe,CAAC,WAAW,WAAW,cAAc,MAAwC;AAAA,EAC5F,aAAa,CAAC,WAAW;AACvB,UAAM,aAAa;AACnB,eAAW,QAAQ;AAAA,EACrB;AACF;;;ADvEO,IAAM,kBAAN,cAA8B,gCAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,aAAa,oBAAoB,OAAO;AAAA,EAChD;AACF;","names":["import_core"]}
package/dist/index.mjs CHANGED
@@ -88,11 +88,11 @@ var nodeRuntime = {
88
88
  // src/client.ts
89
89
  var LiteguardClient = class extends BaseLiteguardClient {
90
90
  /**
91
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
91
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
92
92
  * @param options - Optional SDK configuration overrides.
93
93
  */
94
- constructor(projectClientKeyId, options = {}) {
95
- super(nodeRuntime, projectClientKeyId, options);
94
+ constructor(projectClientToken, options = {}) {
95
+ super(nodeRuntime, projectClientToken, options);
96
96
  }
97
97
  };
98
98
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/runtime.ts"],"sourcesContent":["export type {\n GetGuardsRequest,\n GetGuardsResponse,\n Guard,\n GuardCheckPerformance,\n GuardExecutionPerformance,\n ClientOptions,\n FlushOptions,\n LiteguardChangeListener,\n LiteguardScope,\n Options,\n Operator,\n Properties,\n PropertyValue,\n ProtectedContext,\n Rule,\n SendUnadoptedGuardsRequest,\n SendUnadoptedGuardsResponse,\n Signal,\n SignalPerformance,\n ScopedOptions,\n TraceContext,\n} from '@liteguard/core';\nexport { evaluateGuard } from '@liteguard/core';\nexport { LiteguardClient } from './client.js';\n","import { BaseLiteguardClient } from '@liteguard/core';\nimport type { ClientOptions } from '@liteguard/core';\nimport { nodeRuntime } from './runtime.js';\n\n/**\n * Liteguard client for Node.js environments.\n *\n * Uses `AsyncLocalStorage` for per-request scope propagation and\n * `process.hrtime` / `process.memoryUsage` for performance measurement.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-node';\n *\n * const client = new LiteguardClient('pk_live_...');\n * await client.start();\n *\n * if (client.isOpen('feature.beta')) {\n * // new code path\n * }\n * ```\n */\nexport class LiteguardClient extends BaseLiteguardClient {\n /**\n * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.\n * @param options - Optional SDK configuration overrides.\n */\n constructor(projectClientKeyId: string, options: ClientOptions = {}) {\n super(nodeRuntime, projectClientKeyId, options);\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\nconst executionStorage = new AsyncLocalStorage<ExecutionState>();\nconst requestScopeStorage = new AsyncLocalStorage<RequestScopeStore>();\n\nconst executionAdapter: ExecutionAdapter = {\n /** Return the current execution context for correlated signal emission. */\n getStore(): ExecutionState | undefined {\n return executionStorage.getStore();\n },\n /** Run a callback inside a new correlated execution context. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n return executionStorage.run(initialState, fn);\n },\n};\n\nconst requestScopeAdapter: RequestScopeAdapter = {\n /** Return the current request-scope context for this async call chain. */\n getStore(): RequestScopeStore | undefined {\n return requestScopeStorage.getStore();\n },\n /** Run a callback with a request scope bound to the current async chain. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n return requestScopeStorage.run(initialState, fn);\n },\n};\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a high-resolution start time for a guarded execution. */\n beginGuardExecution(): bigint {\n return process.hrtime.bigint();\n },\n /** Capture point-in-time runtime metrics for a `guard_check` signal. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n return {\n guardCheck: {\n rssBytes: memoryUsage.rss,\n heapUsedBytes: memoryUsage.heapUsed,\n heapTotalBytes: memoryUsage.heapTotal,\n cpuTimeNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n },\n };\n },\n /** Capture completion metrics for a guarded code path on Node.js. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'bigint' ? startToken : process.hrtime.bigint();\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n const durationNs = Number(process.hrtime.bigint() - start);\n return {\n guardExecution: {\n durationNs,\n rssEndBytes: memoryUsage.rss,\n heapUsedEndBytes: memoryUsage.heapUsed,\n heapTotalEndBytes: memoryUsage.heapTotal,\n cpuTimeEndNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\n/** Node.js runtime adapter used by the platform-specific Liteguard client. */\nexport const nodeRuntime: RuntimeAdapter = {\n name: 'node',\n supportsAsyncContextPropagation: true,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-node/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => performance.now(),\n fetch: (input, init) => globalThis.fetch(input, init),\n setTimeout: (callback, ms) => globalThis.setTimeout(callback, ms),\n clearTimeout: (handle) => globalThis.clearTimeout(handle as ReturnType<typeof setTimeout>),\n setInterval: (callback, ms) => globalThis.setInterval(callback, ms),\n clearInterval: (handle) => globalThis.clearInterval(handle as ReturnType<typeof setInterval>),\n detachTimer: (handle) => {\n const maybeTimer = handle as { unref?: () => void };\n maybeTimer.unref?.();\n },\n};\n"],"mappings":";AAuBA,SAAS,qBAAqB;;;ACvB9B,SAAS,2BAA2B;;;ACApC,SAAS,yBAAyB;AAWlC,IAAM,mBAAmB,IAAI,kBAAkC;AAC/D,IAAM,sBAAsB,IAAI,kBAAqC;AAErE,IAAM,mBAAqC;AAAA;AAAA,EAEzC,WAAuC;AACrC,WAAO,iBAAiB,SAAS;AAAA,EACnC;AAAA;AAAA,EAEA,IAAO,cAA8B,IAAgB;AACnD,WAAO,iBAAiB,IAAI,cAAc,EAAE;AAAA,EAC9C;AACF;AAEA,IAAM,sBAA2C;AAAA;AAAA,EAE/C,WAA0C;AACxC,WAAO,oBAAoB,SAAS;AAAA,EACtC;AAAA;AAAA,EAEA,IAAO,cAAiC,IAAgB;AACtD,WAAO,oBAAoB,IAAI,cAAc,EAAE;AAAA,EACjD;AACF;AAEA,IAAM,qBAAyC;AAAA;AAAA,EAE7C,sBAA8B;AAC5B,WAAO,QAAQ,OAAO,OAAO;AAAA,EAC/B;AAAA;AAAA,EAEA,oBAAwD;AACtD,UAAM,cAAc,QAAQ,YAAY;AACxC,UAAM,WAAW,QAAQ,SAAS;AAClC,WAAO;AAA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;AACvB,UAAM,aAAa;AACnB,eAAW,QAAQ;AAAA,EACrB;AACF;;;ADvEO,IAAM,kBAAN,cAA8B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,aAAa,oBAAoB,OAAO;AAAA,EAChD;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/runtime.ts"],"sourcesContent":["export type {\n GetGuardsRequest,\n GetGuardsResponse,\n Guard,\n GuardCheckPerformance,\n GuardExecutionPerformance,\n ClientOptions,\n FlushOptions,\n LiteguardChangeListener,\n LiteguardScope,\n Options,\n Operator,\n Properties,\n PropertyValue,\n ProtectedContext,\n Rule,\n UnadoptedGuardObservation,\n SendUnadoptedGuardsRequest,\n SendUnadoptedGuardsResponse,\n Signal,\n SignalPerformance,\n ScopedOptions,\n TraceContext,\n} from '@liteguard/core';\nexport { evaluateGuard } from '@liteguard/core';\nexport { LiteguardClient } from './client.js';\n","import { BaseLiteguardClient } from '@liteguard/core';\nimport type { ClientOptions } from '@liteguard/core';\nimport { nodeRuntime } from './runtime.js';\n\n/**\n * Liteguard client for Node.js environments.\n *\n * Uses `AsyncLocalStorage` for per-request scope propagation and\n * `process.hrtime` / `process.memoryUsage` for performance measurement.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-node';\n *\n * const client = new LiteguardClient('pctok_live_...');\n * await client.start();\n *\n * if (client.isOpen('feature.beta')) {\n * // new code path\n * }\n * ```\n */\nexport class LiteguardClient extends BaseLiteguardClient {\n /**\n * @param projectClientToken - Your project client token from the Liteguard dashboard.\n * @param options - Optional SDK configuration overrides.\n */\n constructor(projectClientToken: string, options: ClientOptions = {}) {\n super(nodeRuntime, projectClientToken, options);\n }\n}\n","import { AsyncLocalStorage } from 'node:async_hooks';\nimport type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\nconst executionStorage = new AsyncLocalStorage<ExecutionState>();\nconst requestScopeStorage = new AsyncLocalStorage<RequestScopeStore>();\n\nconst executionAdapter: ExecutionAdapter = {\n /** Return the current execution context for correlated signal emission. */\n getStore(): ExecutionState | undefined {\n return executionStorage.getStore();\n },\n /** Run a callback inside a new correlated execution context. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n return executionStorage.run(initialState, fn);\n },\n};\n\nconst requestScopeAdapter: RequestScopeAdapter = {\n /** Return the current request-scope context for this async call chain. */\n getStore(): RequestScopeStore | undefined {\n return requestScopeStorage.getStore();\n },\n /** Run a callback with a request scope bound to the current async chain. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n return requestScopeStorage.run(initialState, fn);\n },\n};\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a high-resolution start time for a guarded execution. */\n beginGuardExecution(): bigint {\n return process.hrtime.bigint();\n },\n /** Capture point-in-time runtime metrics for a `guard_check` signal. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n return {\n guardCheck: {\n rssBytes: memoryUsage.rss,\n heapUsedBytes: memoryUsage.heapUsed,\n heapTotalBytes: memoryUsage.heapTotal,\n cpuTimeNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n },\n };\n },\n /** Capture completion metrics for a guarded code path on Node.js. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'bigint' ? startToken : process.hrtime.bigint();\n const memoryUsage = process.memoryUsage();\n const cpuUsage = process.cpuUsage();\n const durationNs = Number(process.hrtime.bigint() - start);\n return {\n guardExecution: {\n durationNs,\n rssEndBytes: memoryUsage.rss,\n heapUsedEndBytes: memoryUsage.heapUsed,\n heapTotalEndBytes: memoryUsage.heapTotal,\n cpuTimeEndNs: (cpuUsage.user + cpuUsage.system) * 1_000,\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\n/** Node.js runtime adapter used by the platform-specific Liteguard client. */\nexport const nodeRuntime: RuntimeAdapter = {\n name: 'node',\n supportsAsyncContextPropagation: true,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-node/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => performance.now(),\n fetch: (input, init) => globalThis.fetch(input, init),\n setTimeout: (callback, ms) => globalThis.setTimeout(callback, ms),\n clearTimeout: (handle) => globalThis.clearTimeout(handle as ReturnType<typeof setTimeout>),\n setInterval: (callback, ms) => globalThis.setInterval(callback, ms),\n clearInterval: (handle) => globalThis.clearInterval(handle as ReturnType<typeof setInterval>),\n detachTimer: (handle) => {\n const maybeTimer = handle as { unref?: () => void };\n maybeTimer.unref?.();\n },\n};\n"],"mappings":";AAwBA,SAAS,qBAAqB;;;ACxB9B,SAAS,2BAA2B;;;ACApC,SAAS,yBAAyB;AAWlC,IAAM,mBAAmB,IAAI,kBAAkC;AAC/D,IAAM,sBAAsB,IAAI,kBAAqC;AAErE,IAAM,mBAAqC;AAAA;AAAA,EAEzC,WAAuC;AACrC,WAAO,iBAAiB,SAAS;AAAA,EACnC;AAAA;AAAA,EAEA,IAAO,cAA8B,IAAgB;AACnD,WAAO,iBAAiB,IAAI,cAAc,EAAE;AAAA,EAC9C;AACF;AAEA,IAAM,sBAA2C;AAAA;AAAA,EAE/C,WAA0C;AACxC,WAAO,oBAAoB,SAAS;AAAA,EACtC;AAAA;AAAA,EAEA,IAAO,cAAiC,IAAgB;AACtD,WAAO,oBAAoB,IAAI,cAAc,EAAE;AAAA,EACjD;AACF;AAEA,IAAM,qBAAyC;AAAA;AAAA,EAE7C,sBAA8B;AAC5B,WAAO,QAAQ,OAAO,OAAO;AAAA,EAC/B;AAAA;AAAA,EAEA,oBAAwD;AACtD,UAAM,cAAc,QAAQ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WAAW,WAAW,cAAc,MAAwC;AAAA,EAC5F,aAAa,CAAC,WAAW;AACvB,UAAM,aAAa;AACnB,eAAW,QAAQ;AAAA,EACrB;AACF;;;ADvEO,IAAM,kBAAN,cAA8B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,aAAa,oBAAoB,OAAO;AAAA,EAChD;AACF;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@liteguard/liteguard-node",
3
- "version": "0.2.20260314",
4
- "description": "Liteguard SDK for Node.js runtimes feature guards, observability, and security response evaluated locally with zero network overhead per check",
3
+ "version": "0.3.20260315",
4
+ "description": "Liteguard SDK for Node.js runtimes. Feature guards, observability, and security response evaluated locally with zero network overhead per check",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",