@liteguard/liteguard-browser 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-browser
16
16
  ```ts
17
17
  import { LiteguardClient } from "@liteguard/liteguard-browser";
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, LiteguardScope, Properties, ProtectedContext } 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
  type SyncResult<T> = T extends PromiseLike<unknown> ? never : T;
5
5
  /**
@@ -13,7 +13,7 @@ type SyncResult<T> = T extends PromiseLike<unknown> ? never : T;
13
13
  * ```ts
14
14
  * import { LiteguardClient } from '@liteguard/liteguard-browser';
15
15
  *
16
- * const client = new LiteguardClient('pk_live_...');
16
+ * const client = new LiteguardClient('pctok_live_...');
17
17
  * await client.start();
18
18
  *
19
19
  * if (client.isOpen('feature.beta')) {
@@ -23,10 +23,10 @@ type SyncResult<T> = T extends PromiseLike<unknown> ? never : T;
23
23
  */
24
24
  declare class LiteguardClient extends BaseLiteguardClient {
25
25
  /**
26
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
26
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
27
27
  * @param options - Optional SDK configuration overrides.
28
28
  */
29
- constructor(projectClientKeyId: string, options?: ClientOptions);
29
+ constructor(projectClientToken: string, options?: ClientOptions);
30
30
  /**
31
31
  * Run `fn` inside `scope` for synchronous browser work only.
32
32
  *
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BaseLiteguardClient, ClientOptions, LiteguardScope, Properties, ProtectedContext } 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
  type SyncResult<T> = T extends PromiseLike<unknown> ? never : T;
5
5
  /**
@@ -13,7 +13,7 @@ type SyncResult<T> = T extends PromiseLike<unknown> ? never : T;
13
13
  * ```ts
14
14
  * import { LiteguardClient } from '@liteguard/liteguard-browser';
15
15
  *
16
- * const client = new LiteguardClient('pk_live_...');
16
+ * const client = new LiteguardClient('pctok_live_...');
17
17
  * await client.start();
18
18
  *
19
19
  * if (client.isOpen('feature.beta')) {
@@ -23,10 +23,10 @@ type SyncResult<T> = T extends PromiseLike<unknown> ? never : T;
23
23
  */
24
24
  declare class LiteguardClient extends BaseLiteguardClient {
25
25
  /**
26
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
26
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
27
27
  * @param options - Optional SDK configuration overrides.
28
28
  */
29
- constructor(projectClientKeyId: string, options?: ClientOptions);
29
+ constructor(projectClientToken: string, options?: ClientOptions);
30
30
  /**
31
31
  * Run `fn` inside `scope` for synchronous browser work only.
32
32
  *
package/dist/index.js CHANGED
@@ -139,11 +139,11 @@ var browserRuntime = {
139
139
  // src/client.ts
140
140
  var LiteguardClient = class extends import_core.BaseLiteguardClient {
141
141
  /**
142
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
142
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
143
143
  * @param options - Optional SDK configuration overrides.
144
144
  */
145
- constructor(projectClientKeyId, options = {}) {
146
- super(browserRuntime, projectClientKeyId, options);
145
+ constructor(projectClientToken, options = {}) {
146
+ super(browserRuntime, projectClientToken, options);
147
147
  }
148
148
  /**
149
149
  * Run `fn` inside `scope` for synchronous browser work only.
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, LiteguardScope, Properties, ProtectedContext } from '@liteguard/core';\nimport { browserRuntime } from './runtime.js';\n\ntype SyncResult<T> = T extends PromiseLike<unknown> ? never : T;\n\n/**\n * Liteguard client for browser environments.\n *\n * Uses a stack-based execution adapter (no `AsyncLocalStorage`) and\n * `performance.now()` / `performance.memory` for measurement. Automatically\n * flushes buffered signals on `visibilitychange` and `pagehide`.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-browser';\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(browserRuntime, projectClientKeyId, options);\n }\n\n /**\n * Run `fn` inside `scope` for synchronous browser work only.\n *\n * Browser runtimes do not propagate Liteguard scope across `await`\n * boundaries. For async work, pass an explicit `scope` to each call or use\n * `scope.executeIfOpenAsync()`.\n */\n override runWithScope<T>(scope: LiteguardScope, fn: () => SyncResult<T>): SyncResult<T> {\n return super.runWithScope(scope, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Convenience helper for synchronous browser-only scope callbacks.\n */\n override withProperties<T>(properties: Properties, fn: () => SyncResult<T>): SyncResult<T> {\n return super.withProperties(properties, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Bind protected context and run a synchronous callback in the derived scope.\n */\n override async withProtectedContext<T>(\n protectedContext: ProtectedContext,\n fn: () => SyncResult<T>,\n ): Promise<Awaited<T>> {\n return await super.withProtectedContext(protectedContext, fn as () => T);\n }\n\n /**\n * Run `fn` inside a correlated synchronous execution scope.\n */\n override withExecution<T>(fn: () => SyncResult<T>): SyncResult<T> {\n return super.withExecution(fn as () => T) as SyncResult<T>;\n }\n}\n","import type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\ntype MemoryInfo = {\n usedJSHeapSize?: number;\n totalJSHeapSize?: number;\n jsHeapSizeLimit?: number;\n};\n\nclass StackExecutionAdapter implements ExecutionAdapter {\n private current: ExecutionState | undefined;\n\n /** Return the currently active browser execution scope, if any. */\n getStore(): ExecutionState | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's execution scope is active. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\nclass StackRequestScopeAdapter implements RequestScopeAdapter {\n private current: RequestScopeStore | undefined;\n\n /** Return the currently active browser request scope, if any. */\n getStore(): RequestScopeStore | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's request scope is active. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\n/** Read browser heap statistics when the runtime exposes them. */\nfunction getMemoryInfo(): MemoryInfo | undefined {\n const perf = globalThis.performance as Performance & { memory?: MemoryInfo };\n return perf.memory;\n}\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a monotonic start time for a guarded execution in the browser. */\n beginGuardExecution(): number {\n return globalThis.performance?.now?.() ?? Date.now();\n },\n /** Capture heap statistics for a `guard_check` signal when available. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memory = getMemoryInfo();\n return {\n guardCheck: {\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalBytes: memory.totalJSHeapSize } : {}),\n },\n };\n },\n /** Capture completion metrics for a guarded code path in the browser. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'number' ? startToken : globalThis.performance?.now?.() ?? Date.now();\n const end = globalThis.performance?.now?.() ?? Date.now();\n const memory = getMemoryInfo();\n return {\n guardExecution: {\n durationNs: Math.round((end - start) * 1_000_000),\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedEndBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalEndBytes: memory.totalJSHeapSize } : {}),\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\nconst executionAdapter = new StackExecutionAdapter();\nconst requestScopeAdapter = new StackRequestScopeAdapter();\n\n/** Browser runtime adapter used by the platform-specific Liteguard client. */\nexport const browserRuntime: RuntimeAdapter = {\n name: 'browser',\n supportsAsyncContextPropagation: false,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-browser/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => globalThis.performance?.now?.() ?? Date.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 installLifecycleHooks: ({ flushKeepalive }) => {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const onVisibilityChange = () => {\n if (document.visibilityState === 'hidden') {\n flushKeepalive();\n }\n };\n const onPageHide = () => {\n flushKeepalive();\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n window.addEventListener('pagehide', onPageHide);\n\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n window.removeEventListener('pagehide', onPageHide);\n };\n },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,uBAAe;AAAA,MACjB;AAAA,IACF;AACA,UAAM,aAAa,MAAM;AACvB,qBAAe;AAAA,IACjB;AAEA,aAAS,iBAAiB,oBAAoB,kBAAkB;AAChE,WAAO,iBAAiB,YAAY,UAAU;AAE9C,WAAO,MAAM;AACX,eAAS,oBAAoB,oBAAoB,kBAAkB;AACnE,aAAO,oBAAoB,YAAY,UAAU;AAAA,IACnD;AAAA,EACF;AACF;;;AD7GO,IAAM,kBAAN,cAA8B,gCAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,gBAAgB,oBAAoB,OAAO;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASS,aAAgB,OAAuB,IAAwC;AACtF,WAAO,MAAM,aAAa,OAAO,EAAa;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKS,eAAkB,YAAwB,IAAwC;AACzF,WAAO,MAAM,eAAe,YAAY,EAAa;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAe,qBACb,kBACA,IACqB;AACrB,WAAO,MAAM,MAAM,qBAAqB,kBAAkB,EAAa;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKS,cAAiB,IAAwC;AAChE,WAAO,MAAM,cAAc,EAAa;AAAA,EAC1C;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, LiteguardScope, Properties, ProtectedContext } from '@liteguard/core';\nimport { browserRuntime } from './runtime.js';\n\ntype SyncResult<T> = T extends PromiseLike<unknown> ? never : T;\n\n/**\n * Liteguard client for browser environments.\n *\n * Uses a stack-based execution adapter (no `AsyncLocalStorage`) and\n * `performance.now()` / `performance.memory` for measurement. Automatically\n * flushes buffered signals on `visibilitychange` and `pagehide`.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-browser';\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(browserRuntime, projectClientToken, options);\n }\n\n /**\n * Run `fn` inside `scope` for synchronous browser work only.\n *\n * Browser runtimes do not propagate Liteguard scope across `await`\n * boundaries. For async work, pass an explicit `scope` to each call or use\n * `scope.executeIfOpenAsync()`.\n */\n override runWithScope<T>(scope: LiteguardScope, fn: () => SyncResult<T>): SyncResult<T> {\n return super.runWithScope(scope, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Convenience helper for synchronous browser-only scope callbacks.\n */\n override withProperties<T>(properties: Properties, fn: () => SyncResult<T>): SyncResult<T> {\n return super.withProperties(properties, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Bind protected context and run a synchronous callback in the derived scope.\n */\n override async withProtectedContext<T>(\n protectedContext: ProtectedContext,\n fn: () => SyncResult<T>,\n ): Promise<Awaited<T>> {\n return await super.withProtectedContext(protectedContext, fn as () => T);\n }\n\n /**\n * Run `fn` inside a correlated synchronous execution scope.\n */\n override withExecution<T>(fn: () => SyncResult<T>): SyncResult<T> {\n return super.withExecution(fn as () => T) as SyncResult<T>;\n }\n}\n","import type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\ntype MemoryInfo = {\n usedJSHeapSize?: number;\n totalJSHeapSize?: number;\n jsHeapSizeLimit?: number;\n};\n\nclass StackExecutionAdapter implements ExecutionAdapter {\n private current: ExecutionState | undefined;\n\n /** Return the currently active browser execution scope, if any. */\n getStore(): ExecutionState | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's execution scope is active. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\nclass StackRequestScopeAdapter implements RequestScopeAdapter {\n private current: RequestScopeStore | undefined;\n\n /** Return the currently active browser request scope, if any. */\n getStore(): RequestScopeStore | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's request scope is active. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\n/** Read browser heap statistics when the runtime exposes them. */\nfunction getMemoryInfo(): MemoryInfo | undefined {\n const perf = globalThis.performance as Performance & { memory?: MemoryInfo };\n return perf.memory;\n}\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a monotonic start time for a guarded execution in the browser. */\n beginGuardExecution(): number {\n return globalThis.performance?.now?.() ?? Date.now();\n },\n /** Capture heap statistics for a `guard_check` signal when available. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memory = getMemoryInfo();\n return {\n guardCheck: {\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalBytes: memory.totalJSHeapSize } : {}),\n },\n };\n },\n /** Capture completion metrics for a guarded code path in the browser. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'number' ? startToken : globalThis.performance?.now?.() ?? Date.now();\n const end = globalThis.performance?.now?.() ?? Date.now();\n const memory = getMemoryInfo();\n return {\n guardExecution: {\n durationNs: Math.round((end - start) * 1_000_000),\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedEndBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalEndBytes: memory.totalJSHeapSize } : {}),\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\nconst executionAdapter = new StackExecutionAdapter();\nconst requestScopeAdapter = new StackRequestScopeAdapter();\n\n/** Browser runtime adapter used by the platform-specific Liteguard client. */\nexport const browserRuntime: RuntimeAdapter = {\n name: 'browser',\n supportsAsyncContextPropagation: false,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-browser/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => globalThis.performance?.now?.() ?? Date.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 installLifecycleHooks: ({ flushKeepalive }) => {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const onVisibilityChange = () => {\n if (document.visibilityState === 'hidden') {\n flushKeepalive();\n }\n };\n const onPageHide = () => {\n flushKeepalive();\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n window.addEventListener('pagehide', onPageHide);\n\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n window.removeEventListener('pagehide', onPageHide);\n };\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;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ACA,UAAM,aAAa,MAAM;AACvB,qBAAe;AAAA,IACjB;AAEA,aAAS,iBAAiB,oBAAoB,kBAAkB;AAChE,WAAO,iBAAiB,YAAY,UAAU;AAE9C,WAAO,MAAM;AACX,eAAS,oBAAoB,oBAAoB,kBAAkB;AACnE,aAAO,oBAAoB,YAAY,UAAU;AAAA,IACnD;AAAA,EACF;AACF;;;AD7GO,IAAM,kBAAN,cAA8B,gCAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,gBAAgB,oBAAoB,OAAO;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASS,aAAgB,OAAuB,IAAwC;AACtF,WAAO,MAAM,aAAa,OAAO,EAAa;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKS,eAAkB,YAAwB,IAAwC;AACzF,WAAO,MAAM,eAAe,YAAY,EAAa;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAe,qBACb,kBACA,IACqB;AACrB,WAAO,MAAM,MAAM,qBAAqB,kBAAkB,EAAa;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKS,cAAiB,IAAwC;AAChE,WAAO,MAAM,cAAc,EAAa;AAAA,EAC1C;AACF;","names":["import_core"]}
package/dist/index.mjs CHANGED
@@ -114,11 +114,11 @@ var browserRuntime = {
114
114
  // src/client.ts
115
115
  var LiteguardClient = class extends BaseLiteguardClient {
116
116
  /**
117
- * @param projectClientKeyId - Your project client key ID from the Liteguard dashboard.
117
+ * @param projectClientToken - Your project client token from the Liteguard dashboard.
118
118
  * @param options - Optional SDK configuration overrides.
119
119
  */
120
- constructor(projectClientKeyId, options = {}) {
121
- super(browserRuntime, projectClientKeyId, options);
120
+ constructor(projectClientToken, options = {}) {
121
+ super(browserRuntime, projectClientToken, options);
122
122
  }
123
123
  /**
124
124
  * Run `fn` inside `scope` for synchronous browser work only.
@@ -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, LiteguardScope, Properties, ProtectedContext } from '@liteguard/core';\nimport { browserRuntime } from './runtime.js';\n\ntype SyncResult<T> = T extends PromiseLike<unknown> ? never : T;\n\n/**\n * Liteguard client for browser environments.\n *\n * Uses a stack-based execution adapter (no `AsyncLocalStorage`) and\n * `performance.now()` / `performance.memory` for measurement. Automatically\n * flushes buffered signals on `visibilitychange` and `pagehide`.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-browser';\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(browserRuntime, projectClientKeyId, options);\n }\n\n /**\n * Run `fn` inside `scope` for synchronous browser work only.\n *\n * Browser runtimes do not propagate Liteguard scope across `await`\n * boundaries. For async work, pass an explicit `scope` to each call or use\n * `scope.executeIfOpenAsync()`.\n */\n override runWithScope<T>(scope: LiteguardScope, fn: () => SyncResult<T>): SyncResult<T> {\n return super.runWithScope(scope, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Convenience helper for synchronous browser-only scope callbacks.\n */\n override withProperties<T>(properties: Properties, fn: () => SyncResult<T>): SyncResult<T> {\n return super.withProperties(properties, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Bind protected context and run a synchronous callback in the derived scope.\n */\n override async withProtectedContext<T>(\n protectedContext: ProtectedContext,\n fn: () => SyncResult<T>,\n ): Promise<Awaited<T>> {\n return await super.withProtectedContext(protectedContext, fn as () => T);\n }\n\n /**\n * Run `fn` inside a correlated synchronous execution scope.\n */\n override withExecution<T>(fn: () => SyncResult<T>): SyncResult<T> {\n return super.withExecution(fn as () => T) as SyncResult<T>;\n }\n}\n","import type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\ntype MemoryInfo = {\n usedJSHeapSize?: number;\n totalJSHeapSize?: number;\n jsHeapSizeLimit?: number;\n};\n\nclass StackExecutionAdapter implements ExecutionAdapter {\n private current: ExecutionState | undefined;\n\n /** Return the currently active browser execution scope, if any. */\n getStore(): ExecutionState | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's execution scope is active. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\nclass StackRequestScopeAdapter implements RequestScopeAdapter {\n private current: RequestScopeStore | undefined;\n\n /** Return the currently active browser request scope, if any. */\n getStore(): RequestScopeStore | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's request scope is active. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\n/** Read browser heap statistics when the runtime exposes them. */\nfunction getMemoryInfo(): MemoryInfo | undefined {\n const perf = globalThis.performance as Performance & { memory?: MemoryInfo };\n return perf.memory;\n}\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a monotonic start time for a guarded execution in the browser. */\n beginGuardExecution(): number {\n return globalThis.performance?.now?.() ?? Date.now();\n },\n /** Capture heap statistics for a `guard_check` signal when available. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memory = getMemoryInfo();\n return {\n guardCheck: {\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalBytes: memory.totalJSHeapSize } : {}),\n },\n };\n },\n /** Capture completion metrics for a guarded code path in the browser. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'number' ? startToken : globalThis.performance?.now?.() ?? Date.now();\n const end = globalThis.performance?.now?.() ?? Date.now();\n const memory = getMemoryInfo();\n return {\n guardExecution: {\n durationNs: Math.round((end - start) * 1_000_000),\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedEndBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalEndBytes: memory.totalJSHeapSize } : {}),\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\nconst executionAdapter = new StackExecutionAdapter();\nconst requestScopeAdapter = new StackRequestScopeAdapter();\n\n/** Browser runtime adapter used by the platform-specific Liteguard client. */\nexport const browserRuntime: RuntimeAdapter = {\n name: 'browser',\n supportsAsyncContextPropagation: false,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-browser/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => globalThis.performance?.now?.() ?? Date.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 installLifecycleHooks: ({ flushKeepalive }) => {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const onVisibilityChange = () => {\n if (document.visibilityState === 'hidden') {\n flushKeepalive();\n }\n };\n const onPageHide = () => {\n flushKeepalive();\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n window.addEventListener('pagehide', onPageHide);\n\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n window.removeEventListener('pagehide', onPageHide);\n };\n },\n};\n"],"mappings":";AAuBA,SAAS,qBAAqB;;;ACvB9B,SAAS,2BAA2B;;;ACgBpC,IAAM,wBAAN,MAAwD;AAAA,EAC9C;AAAA;AAAA,EAGR,WAAuC;AACrC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAO,cAA8B,IAAgB;AACnD,UAAM,WAAW,KAAK;AACtB,SAAK,UAAU;AACf,QAAI;AACF,aAAO,GAAG;AAAA,IACZ,UAAE;AACA,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AACF;AAEA,IAAM,2BAAN,MAA8D;AAAA,EACpD;AAAA;AAAA,EAGR,WAA0C;AACxC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAO,cAAiC,IAAgB;AACtD,UAAM,WAAW,KAAK;AACtB,SAAK,UAAU;AACf,QAAI;AACF,aAAO,GAAG;AAAA,IACZ,UAAE;AACA,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AACF;AAGA,SAAS,gBAAwC;AAC/C,QAAM,OAAO,WAAW;AACxB,SAAO,KAAK;AACd;AAEA,IAAM,qBAAyC;AAAA;AAAA,EAE7C,sBAA8B;AAC5B,WAAO,WAAW,aAAa,MAAM,KAAK,KAAK,IAAI;AAAA,EACrD;AAAA;AAAA,EAEA,oBAAwD;AACtD,UAAM,SAAS,cAAc;AAC7B,WAAO;AAAA,MACL,YAAY;AAAA,QACV,GAAI,QAAQ,mBAAmB,SAAY,EAAE,eA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zF,aAAa,CAAC,UAAU,OAAO,WAAW,YAAY,UAAU,EAAE;AAAA,EAClE,eAAe,CAAC,WAAW,WAAW,cAAc,MAAwC;AAAA,EAC5F,uBAAuB,CAAC,EAAE,eAAe,MAAM;AAC7C,QAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aAAa;AACpE;AAAA,IACF;AAEA,UAAM,qBAAqB,MAAM;AAC/B,UAAI,SAAS,oBAAoB,UAAU;AACzC,uBAAe;AAAA,MACjB;AAAA,IACF;AACA,UAAM,aAAa,MAAM;AACvB,qBAAe;AAAA,IACjB;AAEA,aAAS,iBAAiB,oBAAoB,kBAAkB;AAChE,WAAO,iBAAiB,YAAY,UAAU;AAE9C,WAAO,MAAM;AACX,eAAS,oBAAoB,oBAAoB,kBAAkB;AACnE,aAAO,oBAAoB,YAAY,UAAU;AAAA,IACnD;AAAA,EACF;AACF;;;AD7GO,IAAM,kBAAN,cAA8B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,gBAAgB,oBAAoB,OAAO;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASS,aAAgB,OAAuB,IAAwC;AACtF,WAAO,MAAM,aAAa,OAAO,EAAa;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKS,eAAkB,YAAwB,IAAwC;AACzF,WAAO,MAAM,eAAe,YAAY,EAAa;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAe,qBACb,kBACA,IACqB;AACrB,WAAO,MAAM,MAAM,qBAAqB,kBAAkB,EAAa;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKS,cAAiB,IAAwC;AAChE,WAAO,MAAM,cAAc,EAAa;AAAA,EAC1C;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, LiteguardScope, Properties, ProtectedContext } from '@liteguard/core';\nimport { browserRuntime } from './runtime.js';\n\ntype SyncResult<T> = T extends PromiseLike<unknown> ? never : T;\n\n/**\n * Liteguard client for browser environments.\n *\n * Uses a stack-based execution adapter (no `AsyncLocalStorage`) and\n * `performance.now()` / `performance.memory` for measurement. Automatically\n * flushes buffered signals on `visibilitychange` and `pagehide`.\n *\n * @example\n * ```ts\n * import { LiteguardClient } from '@liteguard/liteguard-browser';\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(browserRuntime, projectClientToken, options);\n }\n\n /**\n * Run `fn` inside `scope` for synchronous browser work only.\n *\n * Browser runtimes do not propagate Liteguard scope across `await`\n * boundaries. For async work, pass an explicit `scope` to each call or use\n * `scope.executeIfOpenAsync()`.\n */\n override runWithScope<T>(scope: LiteguardScope, fn: () => SyncResult<T>): SyncResult<T> {\n return super.runWithScope(scope, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Convenience helper for synchronous browser-only scope callbacks.\n */\n override withProperties<T>(properties: Properties, fn: () => SyncResult<T>): SyncResult<T> {\n return super.withProperties(properties, fn as () => T) as SyncResult<T>;\n }\n\n /**\n * Bind protected context and run a synchronous callback in the derived scope.\n */\n override async withProtectedContext<T>(\n protectedContext: ProtectedContext,\n fn: () => SyncResult<T>,\n ): Promise<Awaited<T>> {\n return await super.withProtectedContext(protectedContext, fn as () => T);\n }\n\n /**\n * Run `fn` inside a correlated synchronous execution scope.\n */\n override withExecution<T>(fn: () => SyncResult<T>): SyncResult<T> {\n return super.withExecution(fn as () => T) as SyncResult<T>;\n }\n}\n","import type {\n ExecutionAdapter,\n ExecutionState,\n MeasurementAdapter,\n RequestScopeAdapter,\n RequestScopeStore,\n RuntimeAdapter,\n Signal,\n} from '@liteguard/core';\n\ntype MemoryInfo = {\n usedJSHeapSize?: number;\n totalJSHeapSize?: number;\n jsHeapSizeLimit?: number;\n};\n\nclass StackExecutionAdapter implements ExecutionAdapter {\n private current: ExecutionState | undefined;\n\n /** Return the currently active browser execution scope, if any. */\n getStore(): ExecutionState | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's execution scope is active. */\n run<T>(initialState: ExecutionState, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\nclass StackRequestScopeAdapter implements RequestScopeAdapter {\n private current: RequestScopeStore | undefined;\n\n /** Return the currently active browser request scope, if any. */\n getStore(): RequestScopeStore | undefined {\n return this.current;\n }\n\n /** Run a callback while this adapter's request scope is active. */\n run<T>(initialState: RequestScopeStore, fn: () => T): T {\n const previous = this.current;\n this.current = initialState;\n try {\n return fn();\n } finally {\n this.current = previous;\n }\n }\n}\n\n/** Read browser heap statistics when the runtime exposes them. */\nfunction getMemoryInfo(): MemoryInfo | undefined {\n const perf = globalThis.performance as Performance & { memory?: MemoryInfo };\n return perf.memory;\n}\n\nconst measurementAdapter: MeasurementAdapter = {\n /** Capture a monotonic start time for a guarded execution in the browser. */\n beginGuardExecution(): number {\n return globalThis.performance?.now?.() ?? Date.now();\n },\n /** Capture heap statistics for a `guard_check` signal when available. */\n captureGuardCheck(): NonNullable<Signal['measurement']> {\n const memory = getMemoryInfo();\n return {\n guardCheck: {\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalBytes: memory.totalJSHeapSize } : {}),\n },\n };\n },\n /** Capture completion metrics for a guarded code path in the browser. */\n captureGuardExecution(startToken: unknown, completed: boolean, error?: unknown): NonNullable<Signal['measurement']> {\n const start = typeof startToken === 'number' ? startToken : globalThis.performance?.now?.() ?? Date.now();\n const end = globalThis.performance?.now?.() ?? Date.now();\n const memory = getMemoryInfo();\n return {\n guardExecution: {\n durationNs: Math.round((end - start) * 1_000_000),\n ...(memory?.usedJSHeapSize !== undefined ? { heapUsedEndBytes: memory.usedJSHeapSize } : {}),\n ...(memory?.totalJSHeapSize !== undefined ? { heapTotalEndBytes: memory.totalJSHeapSize } : {}),\n completed,\n ...(error && error instanceof Error && error.name ? { errorClass: error.name } : {}),\n },\n };\n },\n};\n\nconst executionAdapter = new StackExecutionAdapter();\nconst requestScopeAdapter = new StackRequestScopeAdapter();\n\n/** Browser runtime adapter used by the platform-specific Liteguard client. */\nexport const browserRuntime: RuntimeAdapter = {\n name: 'browser',\n supportsAsyncContextPropagation: false,\n internalStackMarkers: ['/packages/core/src/', '/packages/liteguard-browser/src/', '/sdk/js/packages/'],\n execution: executionAdapter,\n requestScope: requestScopeAdapter,\n measurement: measurementAdapter,\n now: () => Date.now(),\n monotonicNow: () => globalThis.performance?.now?.() ?? Date.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 installLifecycleHooks: ({ flushKeepalive }) => {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const onVisibilityChange = () => {\n if (document.visibilityState === 'hidden') {\n flushKeepalive();\n }\n };\n const onPageHide = () => {\n flushKeepalive();\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n window.addEventListener('pagehide', onPageHide);\n\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n window.removeEventListener('pagehide', onPageHide);\n };\n },\n};\n"],"mappings":";AAwBA,SAAS,qBAAqB;;;ACxB9B,SAAS,2BAA2B;;;ACgBpC,IAAM,wBAAN,MAAwD;AAAA,EAC9C;AAAA;AAAA,EAGR,WAAuC;AACrC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAO,cAA8B,IAAgB;AACnD,UAAM,WAAW,KAAK;AACtB,SAAK,UAAU;AACf,QAAI;AACF,aAAO,GAAG;AAAA,IACZ,UAAE;AACA,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AACF;AAEA,IAAM,2BAAN,MAA8D;AAAA,EACpD;AAAA;AAAA,EAGR,WAA0C;AACxC,WAAO,KAAK;AAAA,EACd;AAAA;AAAA,EAGA,IAAO,cAAiC,IAAgB;AACtD,UAAM,WAAW,KAAK;AACtB,SAAK,UAAU;AACf,QAAI;AACF,aAAO,GAAG;AAAA,IACZ,UAAE;AACA,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AACF;AAGA,SAAS,gBAAwC;AAC/C,QAAM,OAAO,WAAW;AACxB,SAAO,KAAK;AACd;AAEA,IAAM,qBAAyC;AAAA;AAAA,EAE7C,sBAA8B;AAC5B,WAAO,WAAW,aAAa,MAAM,KAAK,KAAK,IAAI;AAAA,EACrD;AAAA;AAAA,EAEA,oBAAwD;AACtD,UAAM,SAAS,cAAc;AAC7B,WAAO;AAAA,MACL,YAAY;AAAA,QACV,GAAI,QAAQ,mBAAmB,SAAY,EAAE,eAAe,OAAO,eAAe,IAAI,CAAC;AAAA,QACvF,GAAI,QAAQ,oBAAoB,SAAY,EAAE,gBAAgB,OAAO,gB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Ac,MAAwC;AAAA,EAC5F,uBAAuB,CAAC,EAAE,eAAe,MAAM;AAC7C,QAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aAAa;AACpE;AAAA,IACF;AAEA,UAAM,qBAAqB,MAAM;AAC/B,UAAI,SAAS,oBAAoB,UAAU;AACzC,uBAAe;AAAA,MACjB;AAAA,IACF;AACA,UAAM,aAAa,MAAM;AACvB,qBAAe;AAAA,IACjB;AAEA,aAAS,iBAAiB,oBAAoB,kBAAkB;AAChE,WAAO,iBAAiB,YAAY,UAAU;AAE9C,WAAO,MAAM;AACX,eAAS,oBAAoB,oBAAoB,kBAAkB;AACnE,aAAO,oBAAoB,YAAY,UAAU;AAAA,IACnD;AAAA,EACF;AACF;;;AD7GO,IAAM,kBAAN,cAA8B,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvD,YAAY,oBAA4B,UAAyB,CAAC,GAAG;AACnE,UAAM,gBAAgB,oBAAoB,OAAO;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASS,aAAgB,OAAuB,IAAwC;AACtF,WAAO,MAAM,aAAa,OAAO,EAAa;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA,EAKS,eAAkB,YAAwB,IAAwC;AACzF,WAAO,MAAM,eAAe,YAAY,EAAa;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAe,qBACb,kBACA,IACqB;AACrB,WAAO,MAAM,MAAM,qBAAqB,kBAAkB,EAAa;AAAA,EACzE;AAAA;AAAA;AAAA;AAAA,EAKS,cAAiB,IAAwC;AAChE,WAAO,MAAM,cAAc,EAAa;AAAA,EAC1C;AACF;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@liteguard/liteguard-browser",
3
- "version": "0.2.20260314",
4
- "description": "Liteguard SDK for browser 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 browser 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",