tdem-web-sdk 1.0.6 → 1.0.7
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 +25 -0
- package/lib/packages/core/src/core.d.ts +11 -2
- package/lib/packages/core/src/index.d.ts +1 -1
- package/lib/packages/core/src/interface/event.d.ts +5 -0
- package/lib/packages/core/src/interface/index.d.ts +1 -0
- package/lib/packages/core/src/interface/transport.d.ts +48 -0
- package/lib/packages/web-sdk/src/plugins/session-replay/constants.d.ts +13 -1
- package/lib/packages/web-sdk/src/plugins/session-replay/session-manager.d.ts +4 -1
- package/lib/packages/web-sdk/src/plugins/session-replay/types.d.ts +21 -1
- package/lib/packages/web-sdk/src/tdem.d.ts +2 -2
- package/lib/packages/web-sdk/src/transport/browser-transport.d.ts +6 -0
- package/lib/tdem.f.min.js +5 -5
- package/lib/tdem.global.min.js +5 -5
- package/lib/tdem.ie.min.js +5 -5
- package/lib/tdem.min.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,31 @@ const tdem = new TDEM({
|
|
|
58
58
|
| `beforeRequest` | `Function` | 否 | - | 请求发出前钩子 |
|
|
59
59
|
| `afterRequest` | `Function` | 否 | - | 请求完成后钩子 |
|
|
60
60
|
|
|
61
|
+
### SessionReplayConfig 会话回放配置
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
interface SessionReplayConfig {
|
|
65
|
+
enabled?: boolean; // 是否启用,默认 false
|
|
66
|
+
sessionSampleRate?: number; // 会话采样率 (0-1),默认 0.1
|
|
67
|
+
errorSampleRate?: number; // 错误采样率 (0-1),默认 1.0
|
|
68
|
+
errorOnlyUpload?: boolean; // buffer 模式下仅错误时上报,默认 true
|
|
69
|
+
// ... 其他配置见 types.ts
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**采样模式说明**:
|
|
74
|
+
|
|
75
|
+
| 模式 | 触发条件 | 上报行为 |
|
|
76
|
+
| --- | --- | --- |
|
|
77
|
+
| `session` | `sessionSampleRate` 命中 | 全程定时上报(20s 间隔)+ visibilitychange/unload 上报 |
|
|
78
|
+
| `buffer` | `sessionSampleRate` 未命中 + `errorSampleRate > 0` | **仅错误触发时上报**错误前的录制数据;visibilitychange/unload/checkout 不触发上报 |
|
|
79
|
+
| `false` | 均未命中 | 不录制 |
|
|
80
|
+
|
|
81
|
+
> **buffer 模式 + errorOnlyUpload 开关**:
|
|
82
|
+
> - `errorOnlyUpload: true`(默认):buffer 模式下仅错误触发时上报,降本意图。visibilitychange/unload/checkout 不 flush。
|
|
83
|
+
> - `errorOnlyUpload: false`:buffer 模式下上述触发点照常 flush(兼容旧行为)。
|
|
84
|
+
> - **优先级:本地配置 > 远程配置**。远程配置接口返回 `error_only_upload` 字段时会尝试覆盖,但仅在本地初始化时**未显式传入** `errorOnlyUpload` 字段时才会生效;只要本地显式配置了 `errorOnlyUpload`(无论 `true` 还是 `false`),远程值都会被忽略(远程接口待开发)。
|
|
85
|
+
|
|
61
86
|
## 实例方法
|
|
62
87
|
|
|
63
88
|
### 自定义事件
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InterfaceEventEmitter } from './util';
|
|
2
|
-
import { InternalConfig, Environment, SendOption, SendSuccess, SendFail, SpeedLog, BridgeLog, SendType, TDEMEvent, ReportFormSubmitResultParams, ReportStruggleParams, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions } from './interface';
|
|
2
|
+
import { InternalConfig, Environment, SendOption, SendSuccess, SendFail, SpeedLog, BridgeLog, SendType, TDEMEvent, ReportFormSubmitResultParams, ReportStruggleParams, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, InternalSdkOptions, Transport, TransportRequest, TransportResult, TransportCallbacks, RetrySchedule } from './interface';
|
|
3
3
|
import Plugin from './plugin';
|
|
4
4
|
import { Pipe } from './pipes';
|
|
5
5
|
/**
|
|
@@ -16,6 +16,8 @@ export default class Core {
|
|
|
16
16
|
static instances: Core[];
|
|
17
17
|
static environment: typeof Environment;
|
|
18
18
|
static installedPlugins: Plugin[];
|
|
19
|
+
sdkName: string;
|
|
20
|
+
sdkVersion: string;
|
|
19
21
|
/**
|
|
20
22
|
* 使用插件
|
|
21
23
|
* @param plugin
|
|
@@ -35,6 +37,8 @@ export default class Core {
|
|
|
35
37
|
[key: string]: string | number | boolean;
|
|
36
38
|
};
|
|
37
39
|
sendNow: boolean;
|
|
40
|
+
protected internalTransport?: Transport;
|
|
41
|
+
protected internalRetrySchedule: RetrySchedule;
|
|
38
42
|
_customPageUrl: string | null;
|
|
39
43
|
tdemEventPipeline: import("./pipes").Pipeline<any, any>;
|
|
40
44
|
private timeMap;
|
|
@@ -43,7 +47,12 @@ export default class Core {
|
|
|
43
47
|
* 构造函数
|
|
44
48
|
* @param config
|
|
45
49
|
*/
|
|
46
|
-
constructor(_config: InternalConfig);
|
|
50
|
+
constructor(_config: InternalConfig, options?: InternalSdkOptions);
|
|
51
|
+
getInternalTransport(): Transport | undefined;
|
|
52
|
+
setInternalTransport(transport: Transport): void;
|
|
53
|
+
getInternalRetrySchedule(): RetrySchedule;
|
|
54
|
+
transportRequest(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult>;
|
|
55
|
+
transportHandoff(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult>;
|
|
47
56
|
/**
|
|
48
57
|
* 初始化方法,用于记录用户传入参数和初始化 SDK 所有插件
|
|
49
58
|
* @param config
|
|
@@ -3,7 +3,7 @@ import Core from './core';
|
|
|
3
3
|
import Plugin from './plugin';
|
|
4
4
|
export { Plugin };
|
|
5
5
|
export default Core;
|
|
6
|
-
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, InternalConfig, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, ReportFormSubmitResultParams, EventOptions, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './interface';
|
|
6
|
+
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, Config, InternalConfig, CoreApiConfig, SendOption, SendSuccess, SendFail, SendType, Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, PlatTypeNum, NetworkTypeNum, PagePerformanceStruct, EventType, EventCategory, BaseEvent, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, ReportFormSubmitResultParams, EventOptions, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './interface';
|
|
7
7
|
export { getDefaultConfig, setConfigUrl, globalAny, REPORT_TIMEOUT, MAX_FROM_LENGTH, ERROR_MSG_IGNORE, URL_SPEED_IGNORE, RESOURCE_TYPE_FETCH, RESOURCE_TYPE_STATIC, UNKNOWN, RESOURCE_TYPE, MAX_PROMISE_ERROR_MSG_LENGTH, } from './constant';
|
|
8
8
|
export * from './pipes';
|
|
9
9
|
export * from './util';
|
|
@@ -67,6 +67,11 @@ export interface EventContext {
|
|
|
67
67
|
session_id: string;
|
|
68
68
|
user_id?: string;
|
|
69
69
|
platform: string;
|
|
70
|
+
runtime?: string;
|
|
71
|
+
process_type?: string;
|
|
72
|
+
window_id?: string;
|
|
73
|
+
web_contents_id?: string;
|
|
74
|
+
app_version?: string;
|
|
70
75
|
user_agent?: string;
|
|
71
76
|
screen_resolution?: string;
|
|
72
77
|
language?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Config, InternalConfig, CoreApiConfig, PagePerformanceStruct } from './config';
|
|
2
2
|
export { SpeedLog, BridgeLog, StaticAssetsLog, PagePerformanceLog, PagePerformanceLogForHippy3, HippyPagePerformanceLog, PlatTypeNum, NetworkTypeNum, } from './log';
|
|
3
3
|
export { SendOption, SendSuccess, SendFail, SendType, } from './send';
|
|
4
|
+
export { Transport, TransportRequest, TransportResult, TransportCallbacks, TransportMethod, TransportBody, RetryDelayResolver, RetrySchedule, DEFAULT_TRANSPORT_RETRY_SCHEDULE, InternalSdkOptions, } from './transport';
|
|
4
5
|
export { Environment, } from './env';
|
|
5
6
|
export { EventType, EventCategory, BaseEvent, EventContext, SDKInfo, AppInfo, CollectEventsRequest, ExceptionStack, ExceptionFrame, FormSubmitStatus, NavigationType, StruggleStatus, StruggleOwnerType, StruggleEventName, JSErrorEvent, PromiseErrorEvent, ResourceErrorEvent, APIErrorEvent, PageLoadEvent, ResourceLoadEvent, APICallEvent, WebVitalsEvent, EventContextData, BehaviorContextData, FormEventData, ClickEvent, PageViewEvent, FormFocusEvent, FormBlurEvent, FormChangeEvent, FormSubmitEvent, FormSubmitResultEvent, StruggleEvent, CustomEvent, CustomTimeEvent, LogEvent, TDEMEvent, ReportStruggleParams, ReportFormSubmitResultParams, EventOptions, TrackOptions, MeasureOptions, CaptureOptions, SetPageOptions, ReportPageViewOptions, generateEventId, parseErrorStack, } from './event';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SendFail, SendOption, SendSuccess } from './send';
|
|
2
|
+
export declare type TransportMethod = 'GET' | 'POST' | 'get' | 'post';
|
|
3
|
+
export declare type TransportBody = string | ArrayBuffer | ArrayBufferView | Record<string, any> | null | undefined;
|
|
4
|
+
export interface TransportRequest {
|
|
5
|
+
readonly id?: string;
|
|
6
|
+
readonly kind?: 'config' | 'events' | 'replay' | 'custom' | string;
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly method?: TransportMethod;
|
|
9
|
+
readonly headers?: Record<string, string>;
|
|
10
|
+
readonly contentType?: string;
|
|
11
|
+
readonly body?: TransportBody;
|
|
12
|
+
readonly data?: any;
|
|
13
|
+
readonly sendBeacon?: boolean;
|
|
14
|
+
readonly handoff?: boolean;
|
|
15
|
+
readonly timeout?: number;
|
|
16
|
+
readonly retry?: boolean;
|
|
17
|
+
readonly source?: SendOption;
|
|
18
|
+
}
|
|
19
|
+
export interface TransportResult {
|
|
20
|
+
readonly ok: boolean;
|
|
21
|
+
readonly status?: number;
|
|
22
|
+
readonly statusText?: string;
|
|
23
|
+
readonly headers?: Record<string, string>;
|
|
24
|
+
readonly body?: any;
|
|
25
|
+
readonly error?: any;
|
|
26
|
+
readonly request?: TransportRequest;
|
|
27
|
+
readonly handoffAccepted?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface TransportCallbacks {
|
|
30
|
+
readonly success?: SendSuccess;
|
|
31
|
+
readonly fail?: SendFail;
|
|
32
|
+
readonly final?: (result: TransportResult) => void;
|
|
33
|
+
}
|
|
34
|
+
export interface Transport {
|
|
35
|
+
request(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult> | TransportResult | void;
|
|
36
|
+
handoff?(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult> | TransportResult | void;
|
|
37
|
+
dispose?(): void;
|
|
38
|
+
}
|
|
39
|
+
export declare type RetryDelayResolver = (attempt: number, error?: any, request?: TransportRequest) => number;
|
|
40
|
+
export interface RetrySchedule {
|
|
41
|
+
readonly maxAttempts: number;
|
|
42
|
+
readonly delays: ReadonlyArray<number> | RetryDelayResolver;
|
|
43
|
+
}
|
|
44
|
+
export declare const DEFAULT_TRANSPORT_RETRY_SCHEDULE: RetrySchedule;
|
|
45
|
+
export interface InternalSdkOptions {
|
|
46
|
+
readonly transport?: Transport;
|
|
47
|
+
readonly retrySchedule?: RetrySchedule;
|
|
48
|
+
}
|
|
@@ -13,8 +13,18 @@ export declare const MAX_REPLAY_DURATION: number;
|
|
|
13
13
|
export declare const MIN_REPLAY_DURATION: number;
|
|
14
14
|
/** 事件缓冲区最大大小 (5MB) */
|
|
15
15
|
export declare const MAX_BUFFER_SIZE: number;
|
|
16
|
-
/** 单个 Segment 上报最大大小 (3MB),需小于后端 maxEventsSizeBytes(5MB) */
|
|
16
|
+
/** 单个 Segment 上报最大大小 (3MB),需小于后端 maxEventsSizeBytes(5MB),仅用于 fetch 上报路径 */
|
|
17
17
|
export declare const MAX_SEGMENT_SIZE: number;
|
|
18
|
+
/**
|
|
19
|
+
* sendBeacon 单个分片最大大小 (50KB)。
|
|
20
|
+
* navigator.sendBeacon 和 fetch(keepalive:true) 共享浏览器强制的 64KB 排队上限
|
|
21
|
+
* (Fetch 规范定义,Chrome/Safari 均严格执行,超出直接同步返回 false,请求根本不会发出)。
|
|
22
|
+
* 这里按 events 字段压缩前的原始 JSON 长度计算,留出安全余量给:
|
|
23
|
+
* 1. 上报体里 project_key/session_id/replay_id 等其它字段的开销(约几百字节);
|
|
24
|
+
* 2. events 字段即使开启 gzip+base64 压缩,也不保证压缩后一定比原始尺寸小很多;
|
|
25
|
+
* 仅用于 unload 时的 sendBeacon 上报路径,不影响 fetch 路径的 MAX_SEGMENT_SIZE。
|
|
26
|
+
*/
|
|
27
|
+
export declare const BEACON_MAX_CHUNK_SIZE: number;
|
|
18
28
|
/** 默认 flush 间隔 (20秒) */
|
|
19
29
|
export declare const DEFAULT_FLUSH_INTERVAL: number;
|
|
20
30
|
/** 最小 flush 事件数量 (至少10个事件才上报) */
|
|
@@ -27,6 +37,8 @@ export declare const BUFFER_CHECKOUT_EVERY_NMS: number;
|
|
|
27
37
|
export declare const DEFAULT_SESSION_SAMPLE_RATE = 0.1;
|
|
28
38
|
/** 默认错误采样率 (100%) */
|
|
29
39
|
export declare const DEFAULT_ERROR_SAMPLE_RATE = 1;
|
|
40
|
+
/** buffer 模式下默认仅错误时上报(降本意图) */
|
|
41
|
+
export declare const DEFAULT_ERROR_ONLY_UPLOAD = true;
|
|
30
42
|
/** Session 存储 key */
|
|
31
43
|
export declare const SESSION_STORAGE_KEY = "tdem_session";
|
|
32
44
|
/** 上报 API 路径 */
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Session, SamplingMode } from './types';
|
|
2
2
|
export interface SessionManagerConfig {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated 已废弃,构造函数不再读取此字段,不产生任何效果。
|
|
5
|
+
* 保留仅为兼容旧调用方传参不报错。
|
|
6
|
+
*/
|
|
4
7
|
stickySession?: boolean;
|
|
5
8
|
}
|
|
6
9
|
export declare class SessionManager {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { eventWithTime } from '@rrweb/types';
|
|
5
5
|
import type { recordOptions } from 'rrweb';
|
|
6
|
+
import type { Transport } from "../../../../core/src";
|
|
6
7
|
/** 会话回放插件配置 */
|
|
7
8
|
export interface SessionReplayConfig {
|
|
8
9
|
/** 是否启用 */
|
|
@@ -11,7 +12,24 @@ export interface SessionReplayConfig {
|
|
|
11
12
|
sessionSampleRate?: number;
|
|
12
13
|
/** 错误采样率 (0-1) */
|
|
13
14
|
errorSampleRate?: number;
|
|
14
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* buffer 模式下是否仅错误时上报(默认 true)
|
|
17
|
+
* 开启时:buffer 模式下 visibilitychange/unload/rrweb checkout 不触发 flush,
|
|
18
|
+
* 仅错误触发时才上报回放数据(降本意图)
|
|
19
|
+
* 关闭时:buffer 模式下上述触发点照常 flush(兼容旧行为)
|
|
20
|
+
*
|
|
21
|
+
* 优先级:本地配置 > 远程配置。
|
|
22
|
+
* 若此处显式传入了该字段(true 或 false),远程配置接口返回的 error_only_upload
|
|
23
|
+
* 字段将被忽略;仅当本地未传入(undefined)时,远程配置才会生效(远程接口待开发)。
|
|
24
|
+
*/
|
|
25
|
+
errorOnlyUpload?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated 已废弃,不再产生任何效果。
|
|
28
|
+
* 旧口径下用于控制是否从 sessionStorage 恢复 replay_id;
|
|
29
|
+
* 现在会话共享改为基于 Cookie 的站点级 sessionId 机制(见 shared-session.ts),
|
|
30
|
+
* SessionManager 构造函数已不再读取此字段(见 session-manager.ts 的 SessionManagerConfig)。
|
|
31
|
+
* 保留此字段仅为兼容旧调用方传参不报错,计划在下一个大版本移除。
|
|
32
|
+
*/
|
|
15
33
|
stickySession?: boolean;
|
|
16
34
|
/** 隐私配置 */
|
|
17
35
|
privacy?: PrivacyConfig;
|
|
@@ -227,6 +245,8 @@ export interface UploaderConfig {
|
|
|
227
245
|
onError?: (error: Error) => void;
|
|
228
246
|
/** 是否启用 events 字段级 gzip+base64 压缩 */
|
|
229
247
|
eventsCompression?: boolean;
|
|
248
|
+
/** SDK 内部 Transport(不属于公开配置) */
|
|
249
|
+
transport?: Transport;
|
|
230
250
|
}
|
|
231
251
|
/** Replay ID 生成器 */
|
|
232
252
|
export declare class ReplayIdGenerator {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Core, { SendOption, SendSuccess, SendFail } from "../../core/src";
|
|
1
|
+
import Core, { SendOption, SendSuccess, SendFail, InternalSdkOptions } from "../../core/src";
|
|
2
2
|
import { MarkDoms, InternalWebConfig } from './interface';
|
|
3
3
|
export default class TDEM extends Core {
|
|
4
4
|
static sessionID: string;
|
|
@@ -19,7 +19,7 @@ export default class TDEM extends Core {
|
|
|
19
19
|
* 临时方案:先拉远程配置,enabled 时才初始化插件,确保发布初期稳定可控
|
|
20
20
|
*/
|
|
21
21
|
_sdkInitialized: boolean;
|
|
22
|
-
constructor(config: InternalWebConfig);
|
|
22
|
+
constructor(config: InternalWebConfig, internalOptions?: InternalSdkOptions);
|
|
23
23
|
/**
|
|
24
24
|
* 初始化启动入口。
|
|
25
25
|
*
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transport, TransportCallbacks, TransportRequest, TransportResult } from "../../../core/src";
|
|
2
|
+
export declare class BrowserTransport implements Transport {
|
|
3
|
+
request(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult>;
|
|
4
|
+
handoff(request: TransportRequest, callbacks?: TransportCallbacks): Promise<TransportResult>;
|
|
5
|
+
private applyHeaders;
|
|
6
|
+
}
|