@amplitude/amp-semantic 0.2.0 → 0.3.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 +12 -4
- package/lib/cjs/index.d.ts +9 -4
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +10 -7
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/recorders/context.d.ts +4 -0
- package/lib/cjs/recorders/context.d.ts.map +1 -0
- package/lib/cjs/recorders/context.js +50 -0
- package/lib/cjs/recorders/context.js.map +1 -0
- package/lib/cjs/types.d.ts +32 -2
- package/lib/cjs/types.d.ts.map +1 -1
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/index.d.ts +9 -4
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +9 -7
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/recorders/context.d.ts +4 -0
- package/lib/esm/recorders/context.d.ts.map +1 -0
- package/lib/esm/recorders/context.js +47 -0
- package/lib/esm/recorders/context.js.map +1 -0
- package/lib/esm/types.d.ts +32 -2
- package/lib/esm/types.d.ts.map +1 -1
- package/lib/esm/types.js.map +1 -1
- package/package.json +5 -2
- package/schema.json +137 -0
package/README.md
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
# @amplitude/amp-semantic
|
|
2
2
|
|
|
3
|
-
Internal, composable semantic capture runtime for Amplitude. This increment
|
|
3
|
+
Internal, composable semantic capture runtime for Amplitude. This increment adds context capture through a host interface. Session Replay wiring follows separately.
|
|
4
4
|
|
|
5
|
-
The host supplies a document, window, and transport callback. `
|
|
5
|
+
The host supplies a document, window, and transport callback. `createCapture` accepts typed recorder factories and optional per-family budgets (200 events per session by default). With no recorders supplied it emits nothing and installs no browser listeners.
|
|
6
6
|
|
|
7
|
-
The runtime owns opt-in sampling, start/stop and session reset, event version/timestamp/identity stamping, host signals,
|
|
7
|
+
The runtime owns opt-in sampling, start/stop and session reset, event version/timestamp/identity stamping, host snapshot signals, exception isolation, and cleanup rollback. Sampling and caps survive stop/start and reset only for a new session. Identity is allocated lazily when an event is accepted; its fallback is document-scoped memory, with no storage access.
|
|
8
8
|
|
|
9
9
|
Recorders register teardown immediately with `onCleanup` when setup can fail. `canEmit` lets them avoid expensive payload work at capacity. `dropped` returns delivery-cap diagnostics; recorders acknowledge successfully delivered diagnostics with `clearDropped`.
|
|
10
10
|
|
|
11
11
|
The `snapshot` host signal describes an accepted full snapshot; the runtime does not subscribe to rrweb itself. The host remains responsible for privacy-safe payloads, recording consent, transport, and any persisted tab identity.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Session Replay integration and visibility are added in separate follow-up PRs. No analytics SDK depends on this package in this increment.
|
|
14
14
|
|
|
15
15
|
## Development
|
|
16
16
|
|
|
17
17
|
From the repository root, install dependencies and build with Node 24, `pnpm install`, and `pnpm build`. Run `pnpm --filter @amplitude/amp-semantic test` for runtime lifecycle and public contract tests.
|
|
18
|
+
|
|
19
|
+
## Context recorder
|
|
20
|
+
|
|
21
|
+
`createSemanticCapture(config, host)` installs the context recorder by default. The host additionally supplies `sdk`, `getPrivacy`, and optional analytics context and stylesheet-inlining configuration. Call `notify('snapshot', undefined)` after an accepted full snapshot to emit context. Starting capture alone emits nothing.
|
|
22
|
+
|
|
23
|
+
`amp-semantic/context` records the effective mask level for the snapshot URL (including URL overrides), stylesheet counts, viewport, a device heuristic, language, user agent, visibility and focus snapshots, analytics SDK configuration, and dropped-event counts. The runtime stamps version, timestamp and document identity. It never captures input values or page text.
|
|
24
|
+
|
|
25
|
+
The context budget is 200 events per session. At capacity the recorder skips stylesheet and other payload reads. Successfully delivered context acknowledges dropped-event diagnostics; failed delivery preserves them. `schema.json` describes the rrweb custom-event envelope expected from a future transport adapter.
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { contextRecorder } from './recorders/context';
|
|
2
|
+
import type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';
|
|
3
|
+
export { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
4
|
+
export { contextRecorder };
|
|
5
|
+
export declare const defaultRecorders: readonly SemanticRecorder[];
|
|
6
|
+
export declare const SEMANTIC_CAPS: {
|
|
7
|
+
context: number;
|
|
8
|
+
};
|
|
2
9
|
export * from './types';
|
|
3
10
|
export type { SemanticCapture } from './capture';
|
|
4
|
-
export { DEFAULT_SEMANTIC_CAP } from './capture';
|
|
5
11
|
export { getDocumentIdentity } from './identity';
|
|
6
|
-
|
|
7
|
-
export declare function createSemanticCapture<P extends object = SemanticPayloads>(config: SemanticCaptureConfig<P>, host: SemanticHost<P>, recorders?: readonly SemanticRecorder<P>[], caps?: Partial<Record<Extract<keyof P, string>, number>>): import("./capture").SemanticCapture<P>;
|
|
12
|
+
export declare function createSemanticCapture(config: SemanticCaptureConfig, host: SemanticHost, recorders?: readonly SemanticRecorder[]): import("./capture").SemanticCapture<import("./types").SemanticPayloads>;
|
|
8
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,eAAO,MAAM,gBAAgB,EAAE,SAAS,gBAAgB,EAAsB,CAAC;AAC/E,eAAO,MAAM,aAAa;;CAAoC,CAAC;AAC/D,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,YAAY,EAClB,SAAS,GAAE,SAAS,gBAAgB,EAAqB,2EAG1D"}
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSemanticCapture = exports.getDocumentIdentity = exports.DEFAULT_SEMANTIC_CAP = void 0;
|
|
3
|
+
exports.createSemanticCapture = exports.getDocumentIdentity = exports.SEMANTIC_CAPS = exports.defaultRecorders = exports.contextRecorder = exports.DEFAULT_SEMANTIC_CAP = exports.createCapture = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
5
|
var capture_1 = require("./capture");
|
|
6
|
-
|
|
6
|
+
var context_1 = require("./recorders/context");
|
|
7
|
+
Object.defineProperty(exports, "contextRecorder", { enumerable: true, get: function () { return context_1.contextRecorder; } });
|
|
7
8
|
var capture_2 = require("./capture");
|
|
9
|
+
Object.defineProperty(exports, "createCapture", { enumerable: true, get: function () { return capture_2.createCapture; } });
|
|
8
10
|
Object.defineProperty(exports, "DEFAULT_SEMANTIC_CAP", { enumerable: true, get: function () { return capture_2.DEFAULT_SEMANTIC_CAP; } });
|
|
11
|
+
exports.defaultRecorders = [context_1.contextRecorder];
|
|
12
|
+
exports.SEMANTIC_CAPS = { context: capture_1.DEFAULT_SEMANTIC_CAP };
|
|
13
|
+
tslib_1.__exportStar(require("./types"), exports);
|
|
9
14
|
var identity_1 = require("./identity");
|
|
10
15
|
Object.defineProperty(exports, "getDocumentIdentity", { enumerable: true, get: function () { return identity_1.getDocumentIdentity; } });
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (caps === void 0) { caps = {}; }
|
|
15
|
-
return (0, capture_1.createCapture)(config, host, recorders, caps);
|
|
16
|
+
function createSemanticCapture(config, host, recorders) {
|
|
17
|
+
if (recorders === void 0) { recorders = exports.defaultRecorders; }
|
|
18
|
+
return (0, capture_1.createCapture)(config, host, recorders, exports.SEMANTIC_CAPS);
|
|
16
19
|
}
|
|
17
20
|
exports.createSemanticCapture = createSemanticCapture;
|
|
18
21
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAAgE;AAChE,+CAAsD;AAI7C,gGAJA,yBAAe,OAIA;AADxB,qCAAgE;AAAvD,wGAAA,aAAa,OAAA;AAAE,+GAAA,oBAAoB,OAAA;AAE/B,QAAA,gBAAgB,GAAgC,CAAC,yBAAe,CAAC,CAAC;AAClE,QAAA,aAAa,GAAG,EAAE,OAAO,EAAE,8BAAoB,EAAE,CAAC;AAC/D,kDAAwB;AAExB,uCAAiD;AAAxC,+GAAA,mBAAmB,OAAA;AAE5B,SAAgB,qBAAqB,CACnC,MAA6B,EAC7B,IAAkB,EAClB,SAAyD;IAAzD,0BAAA,EAAA,YAAyC,wBAAgB;IAEzD,OAAO,IAAA,uBAAa,EAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,qBAAa,CAAC,CAAC;AAC/D,CAAC;AAND,sDAMC","sourcesContent":["import { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nimport { contextRecorder } from './recorders/context';\nimport type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';\n\nexport { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nexport { contextRecorder };\nexport const defaultRecorders: readonly SemanticRecorder[] = [contextRecorder];\nexport const SEMANTIC_CAPS = { context: DEFAULT_SEMANTIC_CAP };\nexport * from './types';\nexport type { SemanticCapture } from './capture';\nexport { getDocumentIdentity } from './identity';\n\nexport function createSemanticCapture(\n config: SemanticCaptureConfig,\n host: SemanticHost,\n recorders: readonly SemanticRecorder[] = defaultRecorders,\n) {\n return createCapture(config, host, recorders, SEMANTIC_CAPS);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/recorders/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAoClE,8EAA8E;AAC9E,eAAO,MAAM,eAAe,EAAE,gBAK7B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contextRecorder = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var session_replay_dom_privacy_1 = require("@amplitude/session-replay-dom-privacy");
|
|
6
|
+
function captureContext(context) {
|
|
7
|
+
var e_1, _a;
|
|
8
|
+
var _b, _c;
|
|
9
|
+
if (!context.canEmit('context'))
|
|
10
|
+
return;
|
|
11
|
+
var host = context.host;
|
|
12
|
+
var document = host.document, scope = host.window;
|
|
13
|
+
var css = { total: 0, inlined: 0, unreadable: 0 };
|
|
14
|
+
try {
|
|
15
|
+
for (var _d = tslib_1.__values(Array.from(document.styleSheets)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
16
|
+
var sheet = _e.value;
|
|
17
|
+
css.total++;
|
|
18
|
+
try {
|
|
19
|
+
// Reading cssRules can throw for cross-origin stylesheets.
|
|
20
|
+
void sheet.cssRules;
|
|
21
|
+
if (host.inlineStylesheet !== false)
|
|
22
|
+
css.inlined++;
|
|
23
|
+
}
|
|
24
|
+
catch (_f) {
|
|
25
|
+
css.unreadable++;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
30
|
+
finally {
|
|
31
|
+
try {
|
|
32
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
33
|
+
}
|
|
34
|
+
finally { if (e_1) throw e_1.error; }
|
|
35
|
+
}
|
|
36
|
+
var coarse = typeof scope.matchMedia === 'function' && scope.matchMedia('(pointer:coarse)').matches;
|
|
37
|
+
var device = coarse && scope.innerWidth < 768 ? 'mobile' : coarse && scope.innerWidth < 1024 ? 'tablet' : 'desktop';
|
|
38
|
+
var caps = context.dropped();
|
|
39
|
+
var emitted = context.emit('context', tslib_1.__assign({ sdk: host.sdk, mask: (0, session_replay_dom_privacy_1.getEffectiveMaskLevel)(scope.location.href, host.getPrivacy()), css: css, viewport: { w: scope.innerWidth, h: scope.innerHeight }, device: device, language: scope.navigator.language, visibility_state: document.visibilityState === 'hidden' ? 'hidden' : 'visible', focused: document.hasFocus(), user_agent: scope.navigator.userAgent, analytics_sdk: (_c = (_b = host.getAnalyticsContext) === null || _b === void 0 ? void 0 : _b.call(host)) !== null && _c !== void 0 ? _c : { present: false, autocapture: [] } }, (Object.keys(caps).length ? { caps_hit: caps } : {})));
|
|
40
|
+
if (emitted)
|
|
41
|
+
context.clearDropped();
|
|
42
|
+
}
|
|
43
|
+
/** Context is refreshed only when the host accepts a full replay snapshot. */
|
|
44
|
+
exports.contextRecorder = {
|
|
45
|
+
families: ['context'],
|
|
46
|
+
setup: function (context) {
|
|
47
|
+
return context.on('snapshot', function () { return captureContext(context); });
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/recorders/context.ts"],"names":[],"mappings":";;;;AAAA,oFAA8E;AAG9E,SAAS,cAAc,CAAC,OAAwB;;;IAC9C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;QAAE,OAAO;IAChC,IAAA,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AAE,KAAK,CAAC,UAAU,EAAE,CAAC,EAAE,KAAK,CAAC,WAAW,EAAE,EACvD,MAAM,QAAA,EACN,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,EAClC,gBAAgB,EAAE,QAAQ,CAAC,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAC9E,OAAO,EAAE,QAAQ,CAAC,QAAQ,EAAE,EAC5B,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,EACrC,aAAa,EAAE,MAAA,MAAA,IAAI,CAAC,mBAAmB,oDAAI,mCAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,IAC/E,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACvD,CAAC;IACH,IAAI,OAAO;QAAE,OAAO,CAAC,YAAY,EAAE,CAAC;AACtC,CAAC;AAED,8EAA8E;AACjE,QAAA,eAAe,GAAqB;IAC/C,QAAQ,EAAE,CAAC,SAAS,CAAC;IACrB,KAAK,YAAC,OAAO;QACX,OAAO,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,cAAM,OAAA,cAAc,CAAC,OAAO,CAAC,EAAvB,CAAuB,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC","sourcesContent":["import { getEffectiveMaskLevel } from '@amplitude/session-replay-dom-privacy';\nimport type { RecorderContext, SemanticRecorder } from '../types';\n\nfunction captureContext(context: RecorderContext): void {\n if (!context.canEmit('context')) return;\n const { host } = context;\n const { document, window: scope } = host;\n const css = { total: 0, inlined: 0, unreadable: 0 };\n for (const sheet of Array.from(document.styleSheets)) {\n css.total++;\n try {\n // Reading cssRules can throw for cross-origin stylesheets.\n void sheet.cssRules;\n if (host.inlineStylesheet !== false) css.inlined++;\n } catch {\n css.unreadable++;\n }\n }\n const coarse = typeof scope.matchMedia === 'function' && scope.matchMedia('(pointer:coarse)').matches;\n const device = coarse && scope.innerWidth < 768 ? 'mobile' : coarse && scope.innerWidth < 1024 ? 'tablet' : 'desktop';\n const caps = context.dropped();\n const emitted = context.emit('context', {\n sdk: host.sdk,\n mask: getEffectiveMaskLevel(scope.location.href, host.getPrivacy()),\n css,\n viewport: { w: scope.innerWidth, h: scope.innerHeight },\n device,\n language: scope.navigator.language,\n visibility_state: document.visibilityState === 'hidden' ? 'hidden' : 'visible',\n focused: document.hasFocus(),\n user_agent: scope.navigator.userAgent,\n analytics_sdk: host.getAnalyticsContext?.() ?? { present: false, autocapture: [] },\n ...(Object.keys(caps).length ? { caps_hit: caps } : {}),\n });\n if (emitted) context.clearDropped();\n}\n\n/** Context is refreshed only when the host accepts a full replay snapshot. */\nexport const contextRecorder: SemanticRecorder = {\n families: ['context'],\n setup(context) {\n return context.on('snapshot', () => captureContext(context));\n },\n};\n"]}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';
|
|
1
2
|
export declare const SEMANTIC_VERSION = 1;
|
|
3
|
+
export interface AnalyticsContext {
|
|
4
|
+
present: boolean;
|
|
5
|
+
autocapture: string[];
|
|
6
|
+
}
|
|
2
7
|
export interface SemanticIdentity {
|
|
3
8
|
readonly tab_id: string;
|
|
4
9
|
readonly document_id: string;
|
|
@@ -11,8 +16,29 @@ export interface SemanticEventEnvelope<Name extends string, Payload extends obje
|
|
|
11
16
|
v: typeof SEMANTIC_VERSION;
|
|
12
17
|
};
|
|
13
18
|
}
|
|
14
|
-
/**
|
|
15
|
-
export
|
|
19
|
+
/** Payloads exclude version and identity, which are owned by the runtime. */
|
|
20
|
+
export interface SemanticPayloads {
|
|
21
|
+
context: {
|
|
22
|
+
sdk: string;
|
|
23
|
+
mask: 'light' | 'medium' | 'conservative';
|
|
24
|
+
css: {
|
|
25
|
+
total: number;
|
|
26
|
+
inlined: number;
|
|
27
|
+
unreadable: number;
|
|
28
|
+
};
|
|
29
|
+
viewport: {
|
|
30
|
+
w: number;
|
|
31
|
+
h: number;
|
|
32
|
+
};
|
|
33
|
+
device: 'desktop' | 'tablet' | 'mobile';
|
|
34
|
+
language: string;
|
|
35
|
+
visibility_state: 'hidden' | 'visible';
|
|
36
|
+
focused: boolean;
|
|
37
|
+
user_agent: string;
|
|
38
|
+
analytics_sdk: AnalyticsContext;
|
|
39
|
+
caps_hit?: Partial<Record<SemanticFamily, number>>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
16
42
|
export type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;
|
|
17
43
|
export type SemanticEvent<P extends object = SemanticPayloads> = {
|
|
18
44
|
[K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;
|
|
@@ -33,6 +59,10 @@ export type Cleanup = () => void;
|
|
|
33
59
|
export interface SemanticHost<P extends object = SemanticPayloads> {
|
|
34
60
|
document: Document;
|
|
35
61
|
window: Window;
|
|
62
|
+
sdk: string;
|
|
63
|
+
getPrivacy: () => PrivacyConfig;
|
|
64
|
+
getAnalyticsContext?: () => AnalyticsContext;
|
|
65
|
+
inlineStylesheet?: boolean;
|
|
36
66
|
emit: (event: SemanticEvent<P>) => void;
|
|
37
67
|
/** Called lazily for accepted events. Defaults to document-scoped memory only. */
|
|
38
68
|
getIdentity?: () => SemanticIdentity;
|
package/lib/cjs/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AACD,oFAAoF;AACpF,MAAM,WAAW,qBAAqB,C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E;AACzE,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,gBAAgB;IACnE,QAAQ,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,KAAK,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;CACjD"}
|
package/lib/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';\n\nexport const SEMANTIC_VERSION = 1;\nexport interface AnalyticsContext {\n present: boolean;\n autocapture: string[];\n}\nexport interface SemanticIdentity {\n readonly tab_id: string;\n readonly document_id: string;\n}\n/** Internal event envelope, independent of any event family or replay transport. */\nexport interface SemanticEventEnvelope<Name extends string, Payload extends object> {\n name: Name;\n timestamp: number;\n payload: Payload & SemanticIdentity & { v: typeof SEMANTIC_VERSION };\n}\n\n/** Payloads exclude version and identity, which are owned by the runtime. */\nexport interface SemanticPayloads {\n context: {\n sdk: string;\n mask: 'light' | 'medium' | 'conservative';\n css: { total: number; inlined: number; unreadable: number };\n viewport: { w: number; h: number };\n device: 'desktop' | 'tablet' | 'mobile';\n language: string;\n visibility_state: 'hidden' | 'visible';\n focused: boolean;\n user_agent: string;\n analytics_sdk: AnalyticsContext;\n caps_hit?: Partial<Record<SemanticFamily, number>>;\n };\n}\nexport type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;\nexport type SemanticEvent<P extends object = SemanticPayloads> = {\n [K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;\n}[SemanticFamily<P>];\nexport interface SemanticCaptureConfig<P extends object = SemanticPayloads> {\n enabled: boolean;\n /** Additional sampling within recorded replay sessions. Defaults to 1. */\n sampleRate?: number;\n /** Registered families are enabled unless explicitly false. */\n families?: Partial<Record<SemanticFamily<P>, boolean>>;\n}\nexport interface HostSignals {\n /** An accepted full snapshot, forwarded after the recorder is ready. */\n snapshot: undefined;\n}\nexport type Cleanup = () => void;\n/** The host owns transport; the runtime has no rrweb dependency. */\nexport interface SemanticHost<P extends object = SemanticPayloads> {\n document: Document;\n window: Window;\n sdk: string;\n getPrivacy: () => PrivacyConfig;\n getAnalyticsContext?: () => AnalyticsContext;\n inlineStylesheet?: boolean;\n emit: (event: SemanticEvent<P>) => void;\n /** Called lazily for accepted events. Defaults to document-scoped memory only. */\n getIdentity?: () => SemanticIdentity;\n now?: () => number;\n random?: () => number;\n onError?: (error: unknown) => void;\n}\nexport interface RecorderContext<P extends object = SemanticPayloads> {\n /** Register resources immediately so failed setup can roll them back. */\n onCleanup: (cleanup: Cleanup) => void;\n host: SemanticHost<P>;\n now: () => number;\n /** Check before expensive payload work. A rejected candidate increments the dropped count. */\n canEmit: (family: SemanticFamily<P>) => boolean;\n emit: <K extends SemanticFamily<P>>(family: K, payload: P[K], timestamp?: number) => boolean;\n on: <K extends keyof HostSignals>(signal: K, callback: (value: HostSignals[K]) => void) => Cleanup;\n /** Peek at dropped counts; a recorder can acknowledge them after successful delivery. */\n dropped: () => Partial<Record<SemanticFamily<P>, number>>;\n clearDropped: () => void;\n}\n/** A factory owns its listeners/timers and returns complete teardown. */\nexport interface SemanticRecorder<P extends object = SemanticPayloads> {\n families: readonly SemanticFamily<P>[];\n setup: (context: RecorderContext<P>) => Cleanup;\n}\n"]}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { contextRecorder } from './recorders/context';
|
|
2
|
+
import type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';
|
|
3
|
+
export { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
4
|
+
export { contextRecorder };
|
|
5
|
+
export declare const defaultRecorders: readonly SemanticRecorder[];
|
|
6
|
+
export declare const SEMANTIC_CAPS: {
|
|
7
|
+
context: number;
|
|
8
|
+
};
|
|
2
9
|
export * from './types';
|
|
3
10
|
export type { SemanticCapture } from './capture';
|
|
4
|
-
export { DEFAULT_SEMANTIC_CAP } from './capture';
|
|
5
11
|
export { getDocumentIdentity } from './identity';
|
|
6
|
-
|
|
7
|
-
export declare function createSemanticCapture<P extends object = SemanticPayloads>(config: SemanticCaptureConfig<P>, host: SemanticHost<P>, recorders?: readonly SemanticRecorder<P>[], caps?: Partial<Record<Extract<keyof P, string>, number>>): import("./capture").SemanticCapture<P>;
|
|
12
|
+
export declare function createSemanticCapture(config: SemanticCaptureConfig, host: SemanticHost, recorders?: readonly SemanticRecorder[]): import("./capture").SemanticCapture<import("./types").SemanticPayloads>;
|
|
8
13
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAErF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,eAAO,MAAM,gBAAgB,EAAE,SAAS,gBAAgB,EAAsB,CAAC;AAC/E,eAAO,MAAM,aAAa;;CAAoC,CAAC;AAC/D,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,YAAY,EAClB,SAAS,GAAE,SAAS,gBAAgB,EAAqB,2EAG1D"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { createCapture } from './capture';
|
|
1
|
+
import { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
2
|
+
import { contextRecorder } from './recorders/context';
|
|
3
|
+
export { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';
|
|
4
|
+
export { contextRecorder };
|
|
5
|
+
export var defaultRecorders = [contextRecorder];
|
|
6
|
+
export var SEMANTIC_CAPS = { context: DEFAULT_SEMANTIC_CAP };
|
|
2
7
|
export * from './types';
|
|
3
|
-
export { DEFAULT_SEMANTIC_CAP } from './capture';
|
|
4
8
|
export { getDocumentIdentity } from './identity';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (caps === void 0) { caps = {}; }
|
|
9
|
-
return createCapture(config, host, recorders, caps);
|
|
9
|
+
export function createSemanticCapture(config, host, recorders) {
|
|
10
|
+
if (recorders === void 0) { recorders = defaultRecorders; }
|
|
11
|
+
return createCapture(config, host, recorders, SEMANTIC_CAPS);
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,MAAM,CAAC,IAAM,gBAAgB,GAAgC,CAAC,eAAe,CAAC,CAAC;AAC/E,MAAM,CAAC,IAAM,aAAa,GAAG,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAC/D,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,UAAU,qBAAqB,CACnC,MAA6B,EAC7B,IAAkB,EAClB,SAAyD;IAAzD,0BAAA,EAAA,4BAAyD;IAEzD,OAAO,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nimport { contextRecorder } from './recorders/context';\nimport type { SemanticCaptureConfig, SemanticHost, SemanticRecorder } from './types';\n\nexport { createCapture, DEFAULT_SEMANTIC_CAP } from './capture';\nexport { contextRecorder };\nexport const defaultRecorders: readonly SemanticRecorder[] = [contextRecorder];\nexport const SEMANTIC_CAPS = { context: DEFAULT_SEMANTIC_CAP };\nexport * from './types';\nexport type { SemanticCapture } from './capture';\nexport { getDocumentIdentity } from './identity';\n\nexport function createSemanticCapture(\n config: SemanticCaptureConfig,\n host: SemanticHost,\n recorders: readonly SemanticRecorder[] = defaultRecorders,\n) {\n return createCapture(config, host, recorders, SEMANTIC_CAPS);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/recorders/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAoClE,8EAA8E;AAC9E,eAAO,MAAM,eAAe,EAAE,gBAK7B,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __assign, __values } from "tslib";
|
|
2
|
+
import { getEffectiveMaskLevel } from '@amplitude/session-replay-dom-privacy';
|
|
3
|
+
function captureContext(context) {
|
|
4
|
+
var e_1, _a;
|
|
5
|
+
var _b, _c;
|
|
6
|
+
if (!context.canEmit('context'))
|
|
7
|
+
return;
|
|
8
|
+
var host = context.host;
|
|
9
|
+
var document = host.document, scope = host.window;
|
|
10
|
+
var css = { total: 0, inlined: 0, unreadable: 0 };
|
|
11
|
+
try {
|
|
12
|
+
for (var _d = __values(Array.from(document.styleSheets)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
13
|
+
var sheet = _e.value;
|
|
14
|
+
css.total++;
|
|
15
|
+
try {
|
|
16
|
+
// Reading cssRules can throw for cross-origin stylesheets.
|
|
17
|
+
void sheet.cssRules;
|
|
18
|
+
if (host.inlineStylesheet !== false)
|
|
19
|
+
css.inlined++;
|
|
20
|
+
}
|
|
21
|
+
catch (_f) {
|
|
22
|
+
css.unreadable++;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
27
|
+
finally {
|
|
28
|
+
try {
|
|
29
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
30
|
+
}
|
|
31
|
+
finally { if (e_1) throw e_1.error; }
|
|
32
|
+
}
|
|
33
|
+
var coarse = typeof scope.matchMedia === 'function' && scope.matchMedia('(pointer:coarse)').matches;
|
|
34
|
+
var device = coarse && scope.innerWidth < 768 ? 'mobile' : coarse && scope.innerWidth < 1024 ? 'tablet' : 'desktop';
|
|
35
|
+
var caps = context.dropped();
|
|
36
|
+
var emitted = context.emit('context', __assign({ sdk: host.sdk, mask: getEffectiveMaskLevel(scope.location.href, host.getPrivacy()), css: css, viewport: { w: scope.innerWidth, h: scope.innerHeight }, device: device, language: scope.navigator.language, visibility_state: document.visibilityState === 'hidden' ? 'hidden' : 'visible', focused: document.hasFocus(), user_agent: scope.navigator.userAgent, analytics_sdk: (_c = (_b = host.getAnalyticsContext) === null || _b === void 0 ? void 0 : _b.call(host)) !== null && _c !== void 0 ? _c : { present: false, autocapture: [] } }, (Object.keys(caps).length ? { caps_hit: caps } : {})));
|
|
37
|
+
if (emitted)
|
|
38
|
+
context.clearDropped();
|
|
39
|
+
}
|
|
40
|
+
/** Context is refreshed only when the host accepts a full replay snapshot. */
|
|
41
|
+
export var contextRecorder = {
|
|
42
|
+
families: ['context'],
|
|
43
|
+
setup: function (context) {
|
|
44
|
+
return context.on('snapshot', function () { return captureContext(context); });
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/recorders/context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAG9E,SAAS,cAAc,CAAC,OAAwB;;;IAC9C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;QAAE,OAAO;IAChC,IAAA,IAAI,GAAK,OAAO,KAAZ,CAAa;IACjB,IAAA,QAAQ,GAAoB,IAAI,SAAxB,EAAU,KAAK,GAAK,IAAI,OAAT,CAAU;IACzC,IAAM,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;;QACpD,KAAoB,IAAA,KAAA,SAAA,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA,gBAAA,4BAAE;YAAjD,IAAM,KAAK,WAAA;YACd,GAAG,CAAC,KAAK,EAAE,CAAC;YACZ,IAAI;gBACF,2DAA2D;gBAC3D,KAAK,KAAK,CAAC,QAAQ,CAAC;gBACpB,IAAI,IAAI,CAAC,gBAAgB,KAAK,KAAK;oBAAE,GAAG,CAAC,OAAO,EAAE,CAAC;aACpD;YAAC,WAAM;gBACN,GAAG,CAAC,UAAU,EAAE,CAAC;aAClB;SACF;;;;;;;;;IACD,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AO;QAAE,OAAO,CAAC,YAAY,EAAE,CAAC;AACtC,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,IAAM,eAAe,GAAqB;IAC/C,QAAQ,EAAE,CAAC,SAAS,CAAC;IACrB,KAAK,YAAC,OAAO;QACX,OAAO,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,cAAM,OAAA,cAAc,CAAC,OAAO,CAAC,EAAvB,CAAuB,CAAC,CAAC;IAC/D,CAAC;CACF,CAAC","sourcesContent":["import { getEffectiveMaskLevel } from '@amplitude/session-replay-dom-privacy';\nimport type { RecorderContext, SemanticRecorder } from '../types';\n\nfunction captureContext(context: RecorderContext): void {\n if (!context.canEmit('context')) return;\n const { host } = context;\n const { document, window: scope } = host;\n const css = { total: 0, inlined: 0, unreadable: 0 };\n for (const sheet of Array.from(document.styleSheets)) {\n css.total++;\n try {\n // Reading cssRules can throw for cross-origin stylesheets.\n void sheet.cssRules;\n if (host.inlineStylesheet !== false) css.inlined++;\n } catch {\n css.unreadable++;\n }\n }\n const coarse = typeof scope.matchMedia === 'function' && scope.matchMedia('(pointer:coarse)').matches;\n const device = coarse && scope.innerWidth < 768 ? 'mobile' : coarse && scope.innerWidth < 1024 ? 'tablet' : 'desktop';\n const caps = context.dropped();\n const emitted = context.emit('context', {\n sdk: host.sdk,\n mask: getEffectiveMaskLevel(scope.location.href, host.getPrivacy()),\n css,\n viewport: { w: scope.innerWidth, h: scope.innerHeight },\n device,\n language: scope.navigator.language,\n visibility_state: document.visibilityState === 'hidden' ? 'hidden' : 'visible',\n focused: document.hasFocus(),\n user_agent: scope.navigator.userAgent,\n analytics_sdk: host.getAnalyticsContext?.() ?? { present: false, autocapture: [] },\n ...(Object.keys(caps).length ? { caps_hit: caps } : {}),\n });\n if (emitted) context.clearDropped();\n}\n\n/** Context is refreshed only when the host accepts a full replay snapshot. */\nexport const contextRecorder: SemanticRecorder = {\n families: ['context'],\n setup(context) {\n return context.on('snapshot', () => captureContext(context));\n },\n};\n"]}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';
|
|
1
2
|
export declare const SEMANTIC_VERSION = 1;
|
|
3
|
+
export interface AnalyticsContext {
|
|
4
|
+
present: boolean;
|
|
5
|
+
autocapture: string[];
|
|
6
|
+
}
|
|
2
7
|
export interface SemanticIdentity {
|
|
3
8
|
readonly tab_id: string;
|
|
4
9
|
readonly document_id: string;
|
|
@@ -11,8 +16,29 @@ export interface SemanticEventEnvelope<Name extends string, Payload extends obje
|
|
|
11
16
|
v: typeof SEMANTIC_VERSION;
|
|
12
17
|
};
|
|
13
18
|
}
|
|
14
|
-
/**
|
|
15
|
-
export
|
|
19
|
+
/** Payloads exclude version and identity, which are owned by the runtime. */
|
|
20
|
+
export interface SemanticPayloads {
|
|
21
|
+
context: {
|
|
22
|
+
sdk: string;
|
|
23
|
+
mask: 'light' | 'medium' | 'conservative';
|
|
24
|
+
css: {
|
|
25
|
+
total: number;
|
|
26
|
+
inlined: number;
|
|
27
|
+
unreadable: number;
|
|
28
|
+
};
|
|
29
|
+
viewport: {
|
|
30
|
+
w: number;
|
|
31
|
+
h: number;
|
|
32
|
+
};
|
|
33
|
+
device: 'desktop' | 'tablet' | 'mobile';
|
|
34
|
+
language: string;
|
|
35
|
+
visibility_state: 'hidden' | 'visible';
|
|
36
|
+
focused: boolean;
|
|
37
|
+
user_agent: string;
|
|
38
|
+
analytics_sdk: AnalyticsContext;
|
|
39
|
+
caps_hit?: Partial<Record<SemanticFamily, number>>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
16
42
|
export type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;
|
|
17
43
|
export type SemanticEvent<P extends object = SemanticPayloads> = {
|
|
18
44
|
[K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;
|
|
@@ -33,6 +59,10 @@ export type Cleanup = () => void;
|
|
|
33
59
|
export interface SemanticHost<P extends object = SemanticPayloads> {
|
|
34
60
|
document: Document;
|
|
35
61
|
window: Window;
|
|
62
|
+
sdk: string;
|
|
63
|
+
getPrivacy: () => PrivacyConfig;
|
|
64
|
+
getAnalyticsContext?: () => AnalyticsContext;
|
|
65
|
+
inlineStylesheet?: boolean;
|
|
36
66
|
emit: (event: SemanticEvent<P>) => void;
|
|
37
67
|
/** Called lazily for accepted events. Defaults to document-scoped memory only. */
|
|
38
68
|
getIdentity?: () => SemanticIdentity;
|
package/lib/esm/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AACD,oFAAoF;AACpF,MAAM,WAAW,qBAAqB,CAAC,IAAI,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM;IAChF,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,GAAG,gBAAgB,GAAG;QAAE,CAAC,EAAE,OAAO,gBAAgB,CAAA;KAAE,CAAC;CACtE;AAED,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3E,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAClC,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AACD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;A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AAE,MAAM,MAAM,CAAC;IAClB,8FAA8F;IAC9F,OAAO,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;IAChD,IAAI,EAAE,CAAC,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7F,EAAE,EAAE,CAAC,CAAC,SAAS,MAAM,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC;IACnG,yFAAyF;IACzF,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1D,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AACD,yEAAyE;AACzE,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,MAAM,GAAG,gBAAgB;IACnE,QAAQ,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACvC,KAAK,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC;CACjD"}
|
package/lib/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,IAAM,gBAAgB,GAAG,CAAC,CAAC","sourcesContent":["import type { PrivacyConfig } from '@amplitude/session-replay-dom-privacy';\n\nexport const SEMANTIC_VERSION = 1;\nexport interface AnalyticsContext {\n present: boolean;\n autocapture: string[];\n}\nexport interface SemanticIdentity {\n readonly tab_id: string;\n readonly document_id: string;\n}\n/** Internal event envelope, independent of any event family or replay transport. */\nexport interface SemanticEventEnvelope<Name extends string, Payload extends object> {\n name: Name;\n timestamp: number;\n payload: Payload & SemanticIdentity & { v: typeof SEMANTIC_VERSION };\n}\n\n/** Payloads exclude version and identity, which are owned by the runtime. */\nexport interface SemanticPayloads {\n context: {\n sdk: string;\n mask: 'light' | 'medium' | 'conservative';\n css: { total: number; inlined: number; unreadable: number };\n viewport: { w: number; h: number };\n device: 'desktop' | 'tablet' | 'mobile';\n language: string;\n visibility_state: 'hidden' | 'visible';\n focused: boolean;\n user_agent: string;\n analytics_sdk: AnalyticsContext;\n caps_hit?: Partial<Record<SemanticFamily, number>>;\n };\n}\nexport type SemanticFamily<P extends object = SemanticPayloads> = Extract<keyof P, string>;\nexport type SemanticEvent<P extends object = SemanticPayloads> = {\n [K in SemanticFamily<P>]: SemanticEventEnvelope<K, P[K] & object>;\n}[SemanticFamily<P>];\nexport interface SemanticCaptureConfig<P extends object = SemanticPayloads> {\n enabled: boolean;\n /** Additional sampling within recorded replay sessions. Defaults to 1. */\n sampleRate?: number;\n /** Registered families are enabled unless explicitly false. */\n families?: Partial<Record<SemanticFamily<P>, boolean>>;\n}\nexport interface HostSignals {\n /** An accepted full snapshot, forwarded after the recorder is ready. */\n snapshot: undefined;\n}\nexport type Cleanup = () => void;\n/** The host owns transport; the runtime has no rrweb dependency. */\nexport interface SemanticHost<P extends object = SemanticPayloads> {\n document: Document;\n window: Window;\n sdk: string;\n getPrivacy: () => PrivacyConfig;\n getAnalyticsContext?: () => AnalyticsContext;\n inlineStylesheet?: boolean;\n emit: (event: SemanticEvent<P>) => void;\n /** Called lazily for accepted events. Defaults to document-scoped memory only. */\n getIdentity?: () => SemanticIdentity;\n now?: () => number;\n random?: () => number;\n onError?: (error: unknown) => void;\n}\nexport interface RecorderContext<P extends object = SemanticPayloads> {\n /** Register resources immediately so failed setup can roll them back. */\n onCleanup: (cleanup: Cleanup) => void;\n host: SemanticHost<P>;\n now: () => number;\n /** Check before expensive payload work. A rejected candidate increments the dropped count. */\n canEmit: (family: SemanticFamily<P>) => boolean;\n emit: <K extends SemanticFamily<P>>(family: K, payload: P[K], timestamp?: number) => boolean;\n on: <K extends keyof HostSignals>(signal: K, callback: (value: HostSignals[K]) => void) => Cleanup;\n /** Peek at dropped counts; a recorder can acknowledge them after successful delivery. */\n dropped: () => Partial<Record<SemanticFamily<P>, number>>;\n clearDropped: () => void;\n}\n/** A factory owns its listeners/timers and returns complete teardown. */\nexport interface SemanticRecorder<P extends object = SemanticPayloads> {\n families: readonly SemanticFamily<P>[];\n setup: (context: RecorderContext<P>) => Cleanup;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/amp-semantic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Shared package foundation for Amplitude semantic event capture",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/cjs/index.js",
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
"types": "lib/esm/index.d.ts",
|
|
9
9
|
"sideEffects": false,
|
|
10
10
|
"files": [
|
|
11
|
-
"lib"
|
|
11
|
+
"lib",
|
|
12
|
+
"schema.json"
|
|
12
13
|
],
|
|
13
14
|
"publishConfig": {
|
|
14
15
|
"access": "public"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
18
|
+
"@amplitude/session-replay-dom-privacy": "0.2.0",
|
|
17
19
|
"tslib": "^2.4.1"
|
|
18
20
|
},
|
|
19
21
|
"repository": {
|
|
@@ -22,6 +24,7 @@
|
|
|
22
24
|
},
|
|
23
25
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
24
26
|
"devDependencies": {
|
|
27
|
+
"ajv": "^8.17.1",
|
|
25
28
|
"rimraf": "^3.0.2"
|
|
26
29
|
},
|
|
27
30
|
"scripts": {
|
package/schema.json
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Amplitude semantic capture v1 events",
|
|
4
|
+
"oneOf": [
|
|
5
|
+
{
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"type": {
|
|
9
|
+
"const": 5
|
|
10
|
+
},
|
|
11
|
+
"timestamp": {
|
|
12
|
+
"type": "number"
|
|
13
|
+
},
|
|
14
|
+
"data": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"properties": {
|
|
17
|
+
"tag": {
|
|
18
|
+
"const": "amp-semantic/context"
|
|
19
|
+
},
|
|
20
|
+
"payload": {
|
|
21
|
+
"type": "object",
|
|
22
|
+
"properties": {
|
|
23
|
+
"sdk": {
|
|
24
|
+
"type": "string"
|
|
25
|
+
},
|
|
26
|
+
"mask": {
|
|
27
|
+
"enum": ["light", "medium", "conservative"]
|
|
28
|
+
},
|
|
29
|
+
"css": {
|
|
30
|
+
"type": "object",
|
|
31
|
+
"properties": {
|
|
32
|
+
"total": {
|
|
33
|
+
"type": "integer",
|
|
34
|
+
"minimum": 0
|
|
35
|
+
},
|
|
36
|
+
"inlined": {
|
|
37
|
+
"type": "integer",
|
|
38
|
+
"minimum": 0
|
|
39
|
+
},
|
|
40
|
+
"unreadable": {
|
|
41
|
+
"type": "integer",
|
|
42
|
+
"minimum": 0
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"required": ["total", "inlined", "unreadable"],
|
|
46
|
+
"additionalProperties": false
|
|
47
|
+
},
|
|
48
|
+
"viewport": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"w": {
|
|
52
|
+
"type": "number"
|
|
53
|
+
},
|
|
54
|
+
"h": {
|
|
55
|
+
"type": "number"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"required": ["w", "h"],
|
|
59
|
+
"additionalProperties": false
|
|
60
|
+
},
|
|
61
|
+
"device": {
|
|
62
|
+
"enum": ["desktop", "tablet", "mobile"]
|
|
63
|
+
},
|
|
64
|
+
"language": {
|
|
65
|
+
"type": "string"
|
|
66
|
+
},
|
|
67
|
+
"visibility_state": {
|
|
68
|
+
"enum": ["hidden", "visible"]
|
|
69
|
+
},
|
|
70
|
+
"focused": {
|
|
71
|
+
"type": "boolean"
|
|
72
|
+
},
|
|
73
|
+
"user_agent": {
|
|
74
|
+
"type": "string"
|
|
75
|
+
},
|
|
76
|
+
"analytics_sdk": {
|
|
77
|
+
"type": "object",
|
|
78
|
+
"properties": {
|
|
79
|
+
"present": {
|
|
80
|
+
"type": "boolean"
|
|
81
|
+
},
|
|
82
|
+
"autocapture": {
|
|
83
|
+
"type": "array",
|
|
84
|
+
"items": {
|
|
85
|
+
"type": "string"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"required": ["present", "autocapture"],
|
|
90
|
+
"additionalProperties": false
|
|
91
|
+
},
|
|
92
|
+
"caps_hit": {
|
|
93
|
+
"type": "object",
|
|
94
|
+
"properties": {
|
|
95
|
+
"context": {
|
|
96
|
+
"type": "integer",
|
|
97
|
+
"minimum": 0
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"additionalProperties": false
|
|
101
|
+
},
|
|
102
|
+
"tab_id": {
|
|
103
|
+
"type": "string",
|
|
104
|
+
"minLength": 1
|
|
105
|
+
},
|
|
106
|
+
"document_id": {
|
|
107
|
+
"type": "string",
|
|
108
|
+
"minLength": 1
|
|
109
|
+
},
|
|
110
|
+
"v": {
|
|
111
|
+
"const": 1
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"required": [
|
|
115
|
+
"sdk",
|
|
116
|
+
"mask",
|
|
117
|
+
"css",
|
|
118
|
+
"viewport",
|
|
119
|
+
"device",
|
|
120
|
+
"language",
|
|
121
|
+
"analytics_sdk",
|
|
122
|
+
"v",
|
|
123
|
+
"tab_id",
|
|
124
|
+
"document_id"
|
|
125
|
+
],
|
|
126
|
+
"additionalProperties": false
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"required": ["tag", "payload"],
|
|
130
|
+
"additionalProperties": false
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"required": ["type", "timestamp", "data"],
|
|
134
|
+
"additionalProperties": false
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|