@sheeptrack/web 0.0.0-stage → 0.1.0
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 +61 -2
- package/dist/consent.js +23 -0
- package/dist/esm/consent.js +23 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/replay.js +53 -0
- package/dist/replay.js +53 -0
- package/dist/sheeptrack.js +2 -0
- package/dist/types/autocapture.d.ts +9 -0
- package/dist/types/consent.d.ts +3 -0
- package/dist/types/ctx.d.ts +29 -0
- package/dist/types/debug.d.ts +17 -0
- package/dist/types/flags.d.ts +21 -0
- package/dist/types/iife.d.ts +1 -0
- package/dist/types/index.d.ts +42 -0
- package/dist/types/replay.d.ts +2 -0
- package/dist/types/util.d.ts +15 -0
- package/package.json +37 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ConsentCategory, ConsentState, RemoteConfig } from '@sheeptrack/protocol';
|
|
2
|
+
export type Choices = Partial<Record<ConsentCategory, boolean>>;
|
|
3
|
+
export type ConsentCfg = NonNullable<RemoteConfig['consent']>;
|
|
4
|
+
/** What the lazy replay module receives from the core (it never imports the core). */
|
|
5
|
+
export interface ReplayCtx {
|
|
6
|
+
cfg: RemoteConfig['replay'];
|
|
7
|
+
sessionId(): string;
|
|
8
|
+
distinctId(): string;
|
|
9
|
+
consent(): ConsentState;
|
|
10
|
+
nextSeq(): number;
|
|
11
|
+
dropParams: string[];
|
|
12
|
+
/** Resolves with the final HTTP status (0 = gave up). */
|
|
13
|
+
post(sid: string, seq: number, json: string): Promise<number>;
|
|
14
|
+
beacon(sid: string, seq: number, json: string): void;
|
|
15
|
+
}
|
|
16
|
+
export interface ReplayHandle {
|
|
17
|
+
stop(): void;
|
|
18
|
+
pause(): void;
|
|
19
|
+
resume(): void;
|
|
20
|
+
beacon(): void;
|
|
21
|
+
}
|
|
22
|
+
export interface BannerArgs {
|
|
23
|
+
cfg: ConsentCfg;
|
|
24
|
+
/** Current choices when reopened through consent.open(). */
|
|
25
|
+
current: Choices | null;
|
|
26
|
+
onChoice(c: Choices): void;
|
|
27
|
+
/** Banner removed, with or without a choice (Escape = no choice recorded). */
|
|
28
|
+
onClose(): void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type Capture = (name: string, props: Record<string, unknown>) => void;
|
|
2
|
+
export interface DebugOpts {
|
|
3
|
+
errors: boolean;
|
|
4
|
+
network: boolean;
|
|
5
|
+
console: string[] | false;
|
|
6
|
+
vitals: boolean;
|
|
7
|
+
drop: () => string[];
|
|
8
|
+
host: string;
|
|
9
|
+
release?: string;
|
|
10
|
+
/** Called with the fingerprint and type of each captured $error (error clicks). */
|
|
11
|
+
onError?: (e: {
|
|
12
|
+
fingerprint: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}) => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function installDebug(capture: Capture, o: DebugOpts, onNav: (cb: () => void) => void): void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface FlagsCtx {
|
|
2
|
+
json(path: string, body?: unknown): Promise<any>;
|
|
3
|
+
id(): string;
|
|
4
|
+
props(): Record<string, unknown>;
|
|
5
|
+
/** Cache read/write (the write is a no-op without analytics consent). */
|
|
6
|
+
load(): string | null;
|
|
7
|
+
save(v: string): void;
|
|
8
|
+
capture(name: string, p: Record<string, unknown>): void;
|
|
9
|
+
key: string;
|
|
10
|
+
env?: string;
|
|
11
|
+
pollMs: number;
|
|
12
|
+
canPost(): boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function createFlags(c: FlagsCtx): {
|
|
15
|
+
isEnabled: (k: string) => boolean;
|
|
16
|
+
getVariant: (k: string) => string | undefined;
|
|
17
|
+
getPayload: (k: string) => unknown;
|
|
18
|
+
reload: () => Promise<void>;
|
|
19
|
+
onChange(cb: () => void): () => void;
|
|
20
|
+
reset(): void;
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** Copy of the protocol type so the published .d.ts does not import the private workspace package. */
|
|
2
|
+
export type ConsentCategory = 'necessary' | 'analytics' | 'replay' | 'personalization' | 'marketing';
|
|
3
|
+
export interface InitOptions {
|
|
4
|
+
host: string;
|
|
5
|
+
/** Default: the project's "default environment" setting. */
|
|
6
|
+
environment?: 'prod' | 'dev';
|
|
7
|
+
/** App version, sent as `app_version` and with every `$error`. */
|
|
8
|
+
release?: string;
|
|
9
|
+
autocapture?: boolean;
|
|
10
|
+
pageviews?: boolean;
|
|
11
|
+
errors?: boolean;
|
|
12
|
+
network?: boolean;
|
|
13
|
+
vitals?: boolean;
|
|
14
|
+
frustration?: boolean;
|
|
15
|
+
/** Console levels captured. Default warn+error: console.log often carries personal data. */
|
|
16
|
+
console?: ('log' | 'info' | 'warn' | 'error' | 'debug')[] | false;
|
|
17
|
+
/** Extra query params stripped from every URL we record. */
|
|
18
|
+
sensitiveParams?: string[];
|
|
19
|
+
batchInterval?: number;
|
|
20
|
+
batchSize?: number;
|
|
21
|
+
flagsPollMs?: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function init(publicKey: string, options: InitOptions): void;
|
|
24
|
+
export declare function track(event: string, p?: Record<string, unknown>): void;
|
|
25
|
+
export declare function identify(userId_: string, t?: Record<string, unknown>): void;
|
|
26
|
+
export declare function reset(): void;
|
|
27
|
+
export declare const optIn: (cats?: ConsentCategory[]) => void;
|
|
28
|
+
export declare const optOut: () => void;
|
|
29
|
+
export declare const consent: {
|
|
30
|
+
open: () => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
export declare const replay: {
|
|
33
|
+
pause(): void;
|
|
34
|
+
resume(): void;
|
|
35
|
+
};
|
|
36
|
+
export declare const flags: {
|
|
37
|
+
isEnabled: (k: string) => boolean;
|
|
38
|
+
getVariant: (k: string) => string | undefined;
|
|
39
|
+
getPayload: (k: string) => unknown;
|
|
40
|
+
reload: () => Promise<void> | undefined;
|
|
41
|
+
onChange: (cb: () => void) => () => void;
|
|
42
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const SENSITIVE_PARAMS: string[];
|
|
2
|
+
export declare function uuid7(): string;
|
|
3
|
+
export declare const trunc: (s: unknown, n: number) => string;
|
|
4
|
+
/** Absolute URL without credentials, sensitive query params, or a hash that is not a plain route. */
|
|
5
|
+
export declare function cleanUrl(u: string, drop: string[]): string;
|
|
6
|
+
/** Short CSS path (max 4 levels, tag + #id or first plain class). Never uses text content. */
|
|
7
|
+
export declare function selector(el: Element): string;
|
|
8
|
+
/** gzip when CompressionStream exists; text/plain avoids the CORS preflight. */
|
|
9
|
+
export declare function pack(s: string): Promise<Blob>;
|
|
10
|
+
export declare function ua(): {
|
|
11
|
+
os: string;
|
|
12
|
+
os_version?: string;
|
|
13
|
+
browser: string;
|
|
14
|
+
browser_version?: string;
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheeptrack/web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SheepTrack browser SDK: analytics, consent banner, session replay, debug.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "dist/esm/index.js",
|
|
9
|
+
"module": "dist/esm/index.js",
|
|
10
|
+
"types": "dist/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/types/index.d.ts",
|
|
14
|
+
"default": "./dist/esm/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@sheeptrack/protocol": "0.1.0",
|
|
23
|
+
"@types/node": "^24.19.2",
|
|
24
|
+
"esbuild": "^0.28.2",
|
|
25
|
+
"happy-dom": "^21.0.3",
|
|
26
|
+
"jsdom": "^30.1.3",
|
|
27
|
+
"rrweb": "2.0.0-alpha.20",
|
|
28
|
+
"typescript": "^7.0.2",
|
|
29
|
+
"vitest": "^5.0.5"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "node scripts/build.mjs && tsc -p tsconfig.build.json",
|
|
36
|
+
"size": "node scripts/build.mjs && node scripts/size.mjs",
|
|
37
|
+
"typecheck": "pnpm --filter @sheeptrack/protocol run build && tsc -p tsconfig.json --noEmit",
|
|
38
|
+
"test": "vitest run"
|
|
39
|
+
}
|
|
6
40
|
}
|