@zerogpu/browser-extension-sdk 0.2.1 → 0.2.2-dev.202608281547.g2914c9a

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.
Files changed (30) hide show
  1. package/README.md +31 -6
  2. package/bin/zerogpu.mjs +155 -27
  3. package/dist/assets/zerogpu-assets.json +5 -3
  4. package/dist/extension/zerogpu-background.js +365 -0
  5. package/dist/extension/zerogpu-background.js.map +1 -0
  6. package/dist/extension/zerogpu-offscreen.js +483 -229
  7. package/dist/extension/zerogpu-offscreen.js.map +1 -1
  8. package/dist/extension/zerogpu-settings-link.js +160 -0
  9. package/dist/extension/zerogpu-settings-link.js.map +1 -0
  10. package/dist/manifest.json +6 -6
  11. package/dist/types/config/types.d.ts +6 -1
  12. package/dist/types/device/types.d.ts +0 -12
  13. package/dist/types/extension/background.d.ts +71 -0
  14. package/dist/types/extension/consent.d.ts +62 -0
  15. package/dist/types/extension/settings-link.d.ts +14 -0
  16. package/dist/types/runtime/host-api.d.ts +1 -2
  17. package/dist/types/runtime/tracking-script.d.ts +9 -5
  18. package/dist/types/transport/websocket.d.ts +0 -1
  19. package/dist/types/utils/logger.d.ts +44 -5
  20. package/dist/v/{zerogpu-browser-sdk.b4f27a5bea4f.umd.js → zerogpu-browser-sdk.5c257bfc21aa.umd.js} +377 -231
  21. package/dist/v/zerogpu-browser-sdk.5c257bfc21aa.umd.js.map +1 -0
  22. package/dist/zerogpu-browser-sdk.cjs +376 -230
  23. package/dist/zerogpu-browser-sdk.cjs.map +1 -1
  24. package/dist/zerogpu-browser-sdk.esm.js +376 -230
  25. package/dist/zerogpu-browser-sdk.esm.js.map +1 -1
  26. package/dist/zerogpu-browser-sdk.umd.js +376 -230
  27. package/dist/zerogpu-browser-sdk.umd.js.map +1 -1
  28. package/docs/extension-developer-guide.md +178 -3
  29. package/package.json +9 -2
  30. package/dist/v/zerogpu-browser-sdk.b4f27a5bea4f.umd.js.map +0 -1
@@ -0,0 +1,160 @@
1
+ var ZeroGpuSettingsLink = (function (exports) {
2
+ 'use strict';
3
+
4
+ /**
5
+ * ZeroGPU "extension kit" — end-user consent store.
6
+ *
7
+ * An end user must be able to stop the SDK on their own device, and have that
8
+ * stick across browser restarts. That decision lives in `chrome.storage.local`
9
+ * rather than the offscreen document's `localStorage`, because the service
10
+ * worker has to read it *before* deciding whether to create the offscreen
11
+ * document at all — and it has no access to that document's storage.
12
+ *
13
+ * Enforcement is entirely client-side: opting out stops the device connecting.
14
+ * Nothing is deregistered server-side.
15
+ */
16
+ /** Single `chrome.storage.local` key holding the whole record. */
17
+ /** Default host for the ZeroGPU-hosted end-user settings page. */
18
+ const ZEROGPU_SETTINGS_BASE_URL = 'https://zerogpu.ai/extension-settings';
19
+ /**
20
+ * Build the end-user settings URL for this extension. Deliberately carries no
21
+ * operator key: the page only needs the extension id to address a message, and
22
+ * keeping keys out is what lets the page stay backend-free.
23
+ */
24
+ const buildZeroGpuSettingsUrl = ({ extensionId, appName, baseUrl = ZEROGPU_SETTINGS_BASE_URL, debug = false }) => {
25
+ const url = new URL(baseUrl);
26
+ url.searchParams.set('browser', 'chrome');
27
+ url.searchParams.set('extension_id', extensionId);
28
+ if (appName)
29
+ url.searchParams.set('app_name', appName);
30
+ if (debug)
31
+ url.searchParams.set('debug_mode', 'true');
32
+ return url.toString();
33
+ };
34
+
35
+ /**
36
+ * ZeroGPU "extension kit" — drop-in settings link.
37
+ *
38
+ * Any extension page (popup, options, a settings screen) can offer the end-user
39
+ * opt-out with no JavaScript of its own:
40
+ *
41
+ * <a data-zerogpu-settings>Resource sharing</a>
42
+ * <script src="vendor/zerogpu/zerogpu-settings-link.js"></script>
43
+ *
44
+ * Nothing is configured per host: the extension id comes from `chrome.runtime.id`
45
+ * and the display name from the manifest, so those two lines are identical in
46
+ * every extension. Built as a classic script rather than a module, because a
47
+ * plain popup.html has to be able to `<script src>` it without the host
48
+ * declaring `"type": "module"`.
49
+ */
50
+ /** Marks an element as the settings entry point. */
51
+ const ZEROGPU_SETTINGS_ATTRIBUTE = 'data-zerogpu-settings';
52
+ /** Set once an element is wired, so a repeat call cannot stack click handlers. */
53
+ const WIRED_ATTRIBUTE = 'data-zerogpu-settings-wired';
54
+ const getChrome = () => (typeof chrome !== 'undefined' ? chrome : undefined);
55
+ /**
56
+ * Build the settings URL for this extension. Per-element overrides are read from
57
+ * `data-zerogpu-app-name`, `data-zerogpu-base-url` and `data-zerogpu-debug`.
58
+ * Returns null outside an extension page, where there is no id to address.
59
+ */
60
+ const resolveZeroGpuSettingsUrl = (element) => {
61
+ const runtime = getChrome()?.runtime;
62
+ const extensionId = runtime?.id;
63
+ if (!extensionId)
64
+ return null;
65
+ const data = element?.dataset ?? {};
66
+ return buildZeroGpuSettingsUrl({
67
+ extensionId,
68
+ // The manifest name is what the user already knows the extension as, so it
69
+ // is a better default than anything the host would have to repeat here.
70
+ appName: data.zerogpuAppName || runtime.getManifest?.()?.name,
71
+ baseUrl: data.zerogpuBaseUrl || undefined,
72
+ debug: data.zerogpuDebug === 'true'
73
+ });
74
+ };
75
+ /**
76
+ * Elements that already turn a keypress into a click. A <button> fires click on
77
+ * both Enter and Space for free, so giving it `role="button"` and a tabindex
78
+ * would be redundant markup, not an improvement. Anchors never reach here.
79
+ */
80
+ const activatesOnKeyPress = (element) => element.tagName === 'BUTTON' || element.tagName === 'INPUT';
81
+ const openInNewTab = (url) => {
82
+ const api = getChrome();
83
+ // chrome.tabs.create needs no "tabs" permission; that permission only gates
84
+ // reading sensitive tab properties.
85
+ if (api?.tabs?.create)
86
+ api.tabs.create({ url });
87
+ else
88
+ window.open(url, '_blank', 'noopener');
89
+ };
90
+ /**
91
+ * Wire every marked element under `root`. An anchor gets a real href, so it can
92
+ * be middle-clicked or copied; anything else gets a click handler. Returns how
93
+ * many were wired, and is safe to call again after rendering more markup.
94
+ */
95
+ const applyZeroGpuSettingsLinks = (root = document) => {
96
+ const elements = Array.from(root.querySelectorAll(`[${ZEROGPU_SETTINGS_ATTRIBUTE}]:not([${WIRED_ATTRIBUTE}])`));
97
+ let wired = 0;
98
+ for (const element of elements) {
99
+ const url = resolveZeroGpuSettingsUrl(element);
100
+ // Outside an extension page there is no id to send, and the settings page
101
+ // cannot answer without one. Leave the markup alone rather than shipping a
102
+ // link that is guaranteed to fail.
103
+ if (!url)
104
+ continue;
105
+ if (element instanceof HTMLAnchorElement) {
106
+ element.href = url;
107
+ if (!element.target)
108
+ element.target = '_blank';
109
+ element.rel = 'noopener noreferrer';
110
+ }
111
+ else {
112
+ const activate = (event) => {
113
+ event.preventDefault();
114
+ openInNewTab(url);
115
+ };
116
+ element.addEventListener('click', activate);
117
+ // A bare <span> or <div> is neither focusable nor keyboard-activatable,
118
+ // so a click handler alone would leave the opt-out reachable by mouse
119
+ // only. Give it the button semantics it is being used as, without
120
+ // overriding anything the host set deliberately.
121
+ if (!activatesOnKeyPress(element)) {
122
+ if (!element.hasAttribute('tabindex'))
123
+ element.setAttribute('tabindex', '0');
124
+ if (!element.hasAttribute('role'))
125
+ element.setAttribute('role', 'button');
126
+ element.addEventListener('keydown', (event) => {
127
+ const { key } = event;
128
+ // role="button" has to answer to both. Space also needs the default
129
+ // suppressed, or it scrolls the page.
130
+ if (key === 'Enter' || key === ' ')
131
+ activate(event);
132
+ });
133
+ }
134
+ }
135
+ element.setAttribute(WIRED_ATTRIBUTE, '');
136
+ wired += 1;
137
+ }
138
+ return wired;
139
+ };
140
+ // Wire whatever is in the document already. Covers a <script> in <head> as well
141
+ // as one at the end of <body>.
142
+ if (typeof document !== 'undefined') {
143
+ if (document.readyState === 'loading') {
144
+ document.addEventListener('DOMContentLoaded', () => {
145
+ applyZeroGpuSettingsLinks();
146
+ });
147
+ }
148
+ else {
149
+ applyZeroGpuSettingsLinks();
150
+ }
151
+ }
152
+
153
+ exports.ZEROGPU_SETTINGS_ATTRIBUTE = ZEROGPU_SETTINGS_ATTRIBUTE;
154
+ exports.applyZeroGpuSettingsLinks = applyZeroGpuSettingsLinks;
155
+ exports.resolveZeroGpuSettingsUrl = resolveZeroGpuSettingsUrl;
156
+
157
+ return exports;
158
+
159
+ })({});
160
+ //# sourceMappingURL=zerogpu-settings-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zerogpu-settings-link.js","sources":["../../../src/extension/consent.ts","../../../src/extension/settings-link.ts"],"sourcesContent":[null,null],"names":[],"mappings":";;;IAAA;;;;;;;;;;;IAWG;IAEH;IA8HA;IACO,MAAM,yBAAyB,GAAG,uCAAuC;IAahF;;;;IAIG;IACI,MAAM,uBAAuB,GAAG,CAAC,EACtC,WAAW,EACX,OAAO,EACP,OAAO,GAAG,yBAAyB,EACnC,KAAK,GAAG,KAAK,EACM,KAAY;IAC/B,IAAA,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC;QAC5B,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,QAAQ,CAAC;QACzC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC;IACjD,IAAA,IAAI,OAAO;YAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC;IACtD,IAAA,IAAI,KAAK;YAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC;IACrD,IAAA,OAAO,GAAG,CAAC,QAAQ,EAAE;IACvB,CAAC;;IC1KD;;;;;;;;;;;;;;IAcG;IAGH;AACO,UAAM,0BAA0B,GAAG;IAE1C;IACA,MAAM,eAAe,GAAG,6BAA6B;IAcrD,MAAM,SAAS,GAAG,OAA+B,OAAO,MAAM,KAAK,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;IAEpG;;;;IAIG;AACI,UAAM,yBAAyB,GAAG,CAAC,OAAwB,KAAmB;IACnF,IAAA,MAAM,OAAO,GAAG,SAAS,EAAE,EAAE,OAAO;IACpC,IAAA,MAAM,WAAW,GAAG,OAAO,EAAE,EAAE;IAC/B,IAAA,I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AC7B,QAAA,CAAC,CAAC;QACJ;aAAO;IACL,QAAA,yBAAyB,EAAE;QAC7B;IACF;;;;;;;;;;;;"}
@@ -1,8 +1,8 @@
1
1
  {
2
- "version": "0.2.1+8a18008",
3
- "channel": "official",
4
- "buildId": "b4f27a5bea4f",
5
- "coreBundleUrl": "v/zerogpu-browser-sdk.b4f27a5bea4f.umd.js",
6
- "integrity": "sha384-LqbBBw2XracS7WxJQhX55mkNSl9irxeK2lQ82ISZqc4CuSgam72VhU/Pdspib/MU",
7
- "builtAt": "2026-08-13T00:40:39.053Z"
2
+ "version": "0.2.2-dev.202608281547.g2914c9a+2914c9a",
3
+ "channel": "development",
4
+ "buildId": "5c257bfc21aa",
5
+ "coreBundleUrl": "v/zerogpu-browser-sdk.5c257bfc21aa.umd.js",
6
+ "integrity": "sha384-RK0Blk4FXYPBFw9LIrT7xzh6BSjtK4WMQb1hi5I5Wnt+FWyp5AdNwpEe2dyGbJG6",
7
+ "builtAt": "2026-08-28T15:49:18.931Z"
8
8
  }
@@ -58,7 +58,12 @@ export interface OrchestratorConfig {
58
58
  export interface TelemetryConfig {
59
59
  enableConsoleLogs: boolean;
60
60
  locationData: boolean;
61
- cameraData: boolean;
61
+ /**
62
+ * @deprecated The camera-capture path was removed from the SDK (ZGA-538).
63
+ * The flag is accepted for backwards type-compatibility and ignored; no
64
+ * camera code exists in the bundle.
65
+ */
66
+ cameraData?: boolean;
62
67
  events: boolean;
63
68
  }
64
69
  export interface SdkConfig {
@@ -17,17 +17,6 @@ export interface LocationInfo {
17
17
  lon: number;
18
18
  accuracy: number;
19
19
  }
20
- export interface CameraSampleInfo {
21
- permission: 'granted' | 'denied' | 'error';
22
- facingMode?: string;
23
- width?: number;
24
- height?: number;
25
- bytes?: number;
26
- mime?: string;
27
- timestamp?: number;
28
- error?: string;
29
- previewDataUrl?: string;
30
- }
31
20
  export interface DeviceInfo {
32
21
  appUserId?: string;
33
22
  appUsername?: string;
@@ -54,5 +43,4 @@ export interface DeviceInfo {
54
43
  pageUrl?: string;
55
44
  referrer?: string;
56
45
  location?: LocationInfo;
57
- camera?: CameraSampleInfo;
58
46
  }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * ZeroGPU "extension kit" — service-worker consent bridge.
3
+ *
4
+ * This is the piece that makes an end user's opt-out real. It owns the offscreen
5
+ * document's lifecycle and refuses to create it while the user is opted out, so
6
+ * the decision survives browser restarts rather than lasting only as long as the
7
+ * current document.
8
+ *
9
+ * It also exposes a deliberately tiny message vocabulary to the ZeroGPU-hosted
10
+ * settings page via `chrome.runtime.onMessageExternal`, so a user can flip the
11
+ * switch from a normal web page (the Mellowtel-style flow) without the host
12
+ * extension needing a content script.
13
+ *
14
+ * Built as an IIFE (`dist/extension/zerogpu-background.js`) exposing
15
+ * `self.ZeroGpuBackground`, NOT as an ES module: the scaffolded service worker
16
+ * is a classic worker, and hosts with an existing worker are told to
17
+ * `importScripts(...)` it. Shipping ESM would force `"type": "module"` onto
18
+ * every host extension and break their existing service-worker code.
19
+ */
20
+ import { ZeroGpuConsent } from './consent';
21
+ /** The three messages the bridge answers. Nothing here can start inference,
22
+ * read device data, or reach the model store — by design. */
23
+ export declare const ZEROGPU_BRIDGE_MESSAGES: {
24
+ readonly ping: "zerogpu:ping";
25
+ readonly getConsent: "zerogpu:getConsent";
26
+ readonly setConsent: "zerogpu:setConsent";
27
+ };
28
+ /** Origins allowed to talk to the extension. Must stay in step with the
29
+ * `externally_connectable.matches` entry the CLI writes into manifest.json. */
30
+ export declare const DEFAULT_ALLOWED_ORIGINS: string[];
31
+ export interface ConsentBridgeOptions {
32
+ /**
33
+ * Exact origins permitted to send `onMessageExternal` messages. Checked as a
34
+ * strict equality against `sender.origin` — never a substring or suffix test,
35
+ * which `https://zerogpu.ai.attacker.com` would pass.
36
+ */
37
+ allowedOrigins?: string[];
38
+ /** Path to the offscreen document inside the extension. */
39
+ offscreenPath?: string;
40
+ /** Reason strings passed to `chrome.offscreen.createDocument`. */
41
+ offscreenReasons?: string[];
42
+ justification?: string;
43
+ }
44
+ /**
45
+ * Create the offscreen document if the user is opted in and it isn't already
46
+ * there. The consent check lives here rather than at the call sites so that
47
+ * every path into starting the SDK is gated by construction.
48
+ */
49
+ export declare const ensureZeroGpuOffscreen: (options?: ConsentBridgeOptions) => Promise<boolean>;
50
+ /**
51
+ * Stop the SDK: ask the offscreen document to run its ordered shutdown (close
52
+ * the socket, flush telemetry, dispose adapters, mark a clean exit), then tear
53
+ * the document down so nothing restarts inside it.
54
+ */
55
+ export declare const stopZeroGpuOffscreen: (options?: ConsentBridgeOptions) => Promise<void>;
56
+ /** Start or stop to match the stored decision. Safe to call repeatedly. */
57
+ export declare const applyZeroGpuConsent: (consent: ZeroGpuConsent, options?: ConsentBridgeOptions) => Promise<void>;
58
+ /** Start only if the user is opted in — for `onInstalled` / `onStartup`. */
59
+ export declare const startZeroGpuIfConsented: (options?: ConsentBridgeOptions) => Promise<void>;
60
+ /**
61
+ * Install the bridge. Call once from the service worker:
62
+ *
63
+ * ZeroGpuBackground.registerZeroGpuConsentBridge();
64
+ *
65
+ * Wires up: external messages from the allowlisted settings page, internal
66
+ * messages from the extension's own popup/options, storage changes from any
67
+ * context, and the install/startup gate.
68
+ */
69
+ export declare const registerZeroGpuConsentBridge: (options?: ConsentBridgeOptions) => void;
70
+ export { ZEROGPU_CONSENT_KEY, DEFAULT_CONSENT, getZeroGpuConsent, isZeroGpuOptedIn, setZeroGpuConsent, onZeroGpuConsentChanged, buildZeroGpuSettingsUrl, ZEROGPU_SETTINGS_BASE_URL } from './consent';
71
+ export type { ZeroGpuConsent, ZeroGpuConsentSource } from './consent';
@@ -0,0 +1,62 @@
1
+ /**
2
+ * ZeroGPU "extension kit" — end-user consent store.
3
+ *
4
+ * An end user must be able to stop the SDK on their own device, and have that
5
+ * stick across browser restarts. That decision lives in `chrome.storage.local`
6
+ * rather than the offscreen document's `localStorage`, because the service
7
+ * worker has to read it *before* deciding whether to create the offscreen
8
+ * document at all — and it has no access to that document's storage.
9
+ *
10
+ * Enforcement is entirely client-side: opting out stops the device connecting.
11
+ * Nothing is deregistered server-side.
12
+ */
13
+ /** Single `chrome.storage.local` key holding the whole record. */
14
+ export declare const ZEROGPU_CONSENT_KEY = "zerogpu:consent";
15
+ /** Where a decision came from. Recorded so a surprising flip is traceable. */
16
+ export type ZeroGpuConsentSource = 'default' | 'extension' | 'settings-page';
17
+ export interface ZeroGpuConsent {
18
+ optedIn: boolean;
19
+ /** ISO timestamp of the decision; `null` while it is still the default. */
20
+ updatedAt: string | null;
21
+ source: ZeroGpuConsentSource;
22
+ }
23
+ /**
24
+ * Opted IN until told otherwise, which preserves the behaviour every already
25
+ * shipped extension has today: adding this module must not silently stop
26
+ * existing installs. The hosted settings page is what turns it off.
27
+ */
28
+ export declare const DEFAULT_CONSENT: ZeroGpuConsent;
29
+ /** Read the stored decision, or the default when nothing has been stored. */
30
+ export declare const getZeroGpuConsent: () => Promise<ZeroGpuConsent>;
31
+ /** Convenience for the common gate: "may the SDK run right now?" */
32
+ export declare const isZeroGpuOptedIn: () => Promise<boolean>;
33
+ /**
34
+ * Record a decision. The write is what drives everything else — the background
35
+ * bridge listens on `chrome.storage.onChanged` and starts or stops the SDK in
36
+ * response, so no caller needs to do both.
37
+ */
38
+ export declare const setZeroGpuConsent: (optedIn: boolean, source?: ZeroGpuConsentSource) => Promise<ZeroGpuConsent>;
39
+ /**
40
+ * Subscribe to consent changes from any extension context (the hosted settings
41
+ * page writing through the service worker, the options page, another window).
42
+ * Returns an unsubscribe function.
43
+ */
44
+ export declare const onZeroGpuConsentChanged: (listener: (consent: ZeroGpuConsent) => void) => (() => void);
45
+ /** Default host for the ZeroGPU-hosted end-user settings page. */
46
+ export declare const ZEROGPU_SETTINGS_BASE_URL = "https://zerogpu.ai/extension-settings";
47
+ export interface SettingsUrlOptions {
48
+ /** The extension's own id — `chrome.runtime.id` in an extension context. */
49
+ extensionId: string;
50
+ /** Display-only app name shown to the user. Never used for a lookup. */
51
+ appName?: string;
52
+ /** Override the page host (staging, local dev). */
53
+ baseUrl?: string;
54
+ /** Render the page's raw ping/consent payload. */
55
+ debug?: boolean;
56
+ }
57
+ /**
58
+ * Build the end-user settings URL for this extension. Deliberately carries no
59
+ * operator key: the page only needs the extension id to address a message, and
60
+ * keeping keys out is what lets the page stay backend-free.
61
+ */
62
+ export declare const buildZeroGpuSettingsUrl: ({ extensionId, appName, baseUrl, debug }: SettingsUrlOptions) => string;
@@ -0,0 +1,14 @@
1
+ /** Marks an element as the settings entry point. */
2
+ export declare const ZEROGPU_SETTINGS_ATTRIBUTE = "data-zerogpu-settings";
3
+ /**
4
+ * Build the settings URL for this extension. Per-element overrides are read from
5
+ * `data-zerogpu-app-name`, `data-zerogpu-base-url` and `data-zerogpu-debug`.
6
+ * Returns null outside an extension page, where there is no id to address.
7
+ */
8
+ export declare const resolveZeroGpuSettingsUrl: (element?: Element | null) => string | null;
9
+ /**
10
+ * Wire every marked element under `root`. An anchor gets a real href, so it can
11
+ * be middle-clicked or copied; anything else gets a click handler. Returns how
12
+ * many were wired, and is safe to call again after rendering more markup.
13
+ */
14
+ export declare const applyZeroGpuSettingsLinks: (root?: ParentNode) => number;
@@ -2,8 +2,7 @@
2
2
  * Host-facing lifecycle status and events. The SDK is a guest in someone
3
3
  * else's app: this module is how the host observes guardrail state (degraded /
4
4
  * recovered / shutdown) without the SDK ever throwing into it. Script-tag
5
- * consumers get the same signals as `zerogpu:*` window events, matching the
6
- * existing `zerogpu:cameraPreview` pattern.
5
+ * consumers get the same signals as `zerogpu:*` window events.
7
6
  */
8
7
  export type SdkLifecycleStatus = 'starting' | 'running' | 'degraded' | 'shutdown' | 'error';
9
8
  export type HostEventName = 'degraded' | 'recovered' | 'shutdown';
@@ -14,9 +14,12 @@
14
14
  *
15
15
  * Progressive:
16
16
  * 1. If a runner URL is configured, run the tag in the framed runner.
17
- * 2. Otherwise fall back to a credentialed request beacon so the impression at
18
- * least reaches the ad server with the user's real IP/UA/cookies (the tag's
19
- * JS does not run).
17
+ * 2. Otherwise, on an ordinary web page or WebView (including a Telegram Mini
18
+ * App) with no restrictive `script-src` CSP, inject a real `<script>`
19
+ * element so the tag executes directly in the page.
20
+ * 3. Failing both (no DOM, or a CSP that blocks the injected script), fall back
21
+ * to a credentialed request beacon so the impression at least reaches the ad
22
+ * server with the user's real IP/UA/cookies (the tag's JS does not run).
20
23
  *
21
24
  * Never rejects: a tag is best-effort and must not affect inference.
22
25
  */
@@ -27,7 +30,8 @@ import { TrackingPixelOutcome } from './tracking-pixel';
27
30
  */
28
31
  export declare const setTrackingScriptRunnerUrl: (url: string | null | undefined) => void;
29
32
  /**
30
- * Fire a JavaScript tracking tag. Runs it in the framed runner when one is
31
- * available; otherwise fires the request as a beacon. Never rejects.
33
+ * Fire a JavaScript tracking tag. Executes it wherever it can — the framed
34
+ * runner, or an injected `<script>` on a normal page/WebView — and only falls
35
+ * back to a non-executing beacon when neither can run it. Never rejects.
32
36
  */
33
37
  export declare const fireTrackingScript: (url: string, timeoutMs?: number) => Promise<TrackingPixelOutcome>;
@@ -29,7 +29,6 @@ export declare class WebSocketClient {
29
29
  private logger;
30
30
  private pingTimer;
31
31
  private pingIntervalMs;
32
- private consoleWithVerbose;
33
32
  constructor(options: WebSocketClientOptions);
34
33
  private handleOpen;
35
34
  private handleMessage;
@@ -1,15 +1,54 @@
1
1
  import { TelemetryConfig } from '../config/types';
2
2
  export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
+ /**
4
+ * Redaction-safe logging (ZGA-538).
5
+ *
6
+ * The SDK runs inside someone else's app, and with console logs enabled the
7
+ * host's crash/session-replay tooling may collect whatever we print. So the
8
+ * logger's contract is: *what happened, ids, sizes, timings — never content.*
9
+ * Every field passes through `sanitizeLogFields` before it reaches the
10
+ * console; there is no code path that prints a value verbatim:
11
+ *
12
+ * - numbers / booleans / null / undefined pass through (counts, byte lengths,
13
+ * durations, flags);
14
+ * - strings pass through only under an allowlisted identifier/enum key
15
+ * (requestId, modelId, code, reason, …), capped in length;
16
+ * - URL-shaped keys are stripped to origin + path — query strings carry
17
+ * session credentials on our WS URLs;
18
+ * - keys that look like credentials (sessionKey, token, operator key, …) are
19
+ * always `[redacted]`, whatever the value;
20
+ * - error/message keys keep a capped error summary (diagnostics, not payload);
21
+ * - any other string is replaced by `[string:<length>]`, and objects/arrays of
22
+ * objects collapse to a shape summary — full frames, payloads and model
23
+ * output are unprintable by construction.
24
+ *
25
+ * This module is the single allowed `console.*` sink in the SDK runtime (the
26
+ * self-contained loader stub and the offscreen console-silencer are the two
27
+ * audited exceptions) — enforced by the `no-console` lint rule and
28
+ * `scripts/check-safe-logging.mjs`.
29
+ */
30
+ type SafePrimitive = string | number | boolean | null | undefined;
31
+ export type SafeFieldValue = SafePrimitive | Error | ReadonlyArray<SafePrimitive>;
32
+ export type SafeFields = Record<string, SafeFieldValue>;
33
+ /** One-line, capped error summary — diagnostics survive, payloads cannot ride along uncapped. */
34
+ export declare const summarizeError: (error: unknown) => string;
35
+ /**
36
+ * The runtime redaction gate. Whatever a caller manages to pass (the types
37
+ * merely guide), nothing but ids, enums, counts, sizes, durations and capped
38
+ * error summaries comes out the other side.
39
+ */
40
+ export declare const sanitizeLogFields: (fields: unknown) => Record<string, unknown>;
3
41
  declare class Logger {
4
42
  private enabled;
5
43
  constructor(config: TelemetryConfig);
6
44
  setEnabled(enabled: boolean): void;
7
45
  isEnabled(): boolean;
8
- debug(...args: unknown[]): void;
9
- info(...args: unknown[]): void;
10
- warn(...args: unknown[]): void;
11
- error(...args: unknown[]): void;
46
+ private emit;
47
+ debug(message: string, fields?: SafeFields | Error): void;
48
+ info(message: string, fields?: SafeFields | Error): void;
49
+ warn(message: string, fields?: SafeFields | Error): void;
50
+ error(message: string, fields?: SafeFields | Error): void;
12
51
  }
52
+ export type { Logger };
13
53
  export declare const initLogger: (config: TelemetryConfig) => Logger;
14
54
  export declare const getLogger: () => Logger;
15
- export {};