@tengence/track-sdk-web 1.1.3 → 1.1.14

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.
@@ -47,8 +47,22 @@ export declare function safeFixed(v: number | undefined): number | null;
47
47
  export declare function getIdGenerator(bytes: number): () => string;
48
48
  export declare function generateTraceId(): string;
49
49
  export declare function generateSpanId(): string;
50
+ /**
51
+ * 生成全局唯一 ID(RFC 4122 v4)
52
+ * 优先使用浏览器原生 crypto.randomUUID()(主流方式,现代浏览器全覆盖),
53
+ * 在不支持或非安全上下文(非 HTTPS)时回退到 32 位 hex 随机串。
54
+ * 用于 event_id / device_id 等需要唯一标识的场景。
55
+ */
56
+ export declare function generateId(): string;
50
57
  export declare const getErrorKey: (event: ErrorEvent | Event) => "resource" | "cors" | "js";
51
58
  export declare const getErrorUuid: (str: string) => string;
52
59
  export declare const isChromeExtensionError: (event: ErrorEvent) => boolean;
53
60
  export declare function shouldSample(probability: number): boolean;
54
61
  export declare function isVisible(element: Element): boolean;
62
+ /**
63
+ * 浏览器全局隐私控制信号(GPC,Global Privacy Control):
64
+ * 用户在浏览器层选择"不出售/不分享我的数据"时,navigator.globalPrivacyControl === true;
65
+ * 不支持或未开启时为 undefined/false → 返回 false。读取零成本(单布尔),
66
+ * init 时读取一次 + 每次 report 前复查(浏览器无 GPC 变化事件)。
67
+ */
68
+ export declare function isGpcActive(): boolean;
@@ -1,7 +1,7 @@
1
1
  import { ReportData } from "@/interface";
2
2
  /**
3
3
  * 彩色打印埋点数据
4
- * @param method 上报方式 (SendBeacon | XHR)
4
+ * @param method 上报方式(Fetch / XHR / RealTimeFetch 等)
5
5
  * @param data 上报数据数组
6
6
  */
7
- export declare const logTrackData: (method: 'SendBeacon' | 'XHR', data: ReportData[]) => void;
7
+ export declare const logTrackData: (method: string, data: ReportData[]) => void;
@@ -5,6 +5,8 @@ interface HasherState {
5
5
  state: number[];
6
6
  }
7
7
  export declare class Md5 {
8
+ private static selfTested;
9
+ private static selfTest;
8
10
  /**
9
11
  * Hash a UTF-8 string on the spot
10
12
  * @param str String to hash
@@ -1,24 +1,40 @@
1
1
  type RequestMethod = "GET" | "POST";
2
+ /**
3
+ * 鉴权错误(401/403),供上层识别并触发 token 刷新
4
+ */
5
+ export declare class AuthError extends Error {
6
+ status: number;
7
+ constructor(status: number, message?: string);
8
+ }
2
9
  interface AjaxOptions {
3
10
  method: RequestMethod;
4
11
  url: string;
5
12
  data?: any;
6
13
  headers?: Record<string, string>;
7
14
  withCredentials?: boolean;
15
+ timeoutMs?: number;
8
16
  }
9
17
  /**
10
- * 是否支持sendBeacon
18
+ * ajax请求(XHR,作为 fetch 不可用时的回退)
19
+ * @param {AjaxOptions} params 请求配置
11
20
  */
12
- export declare const isSupportBeacon = true;
21
+ export declare const ajax: <T>({ method, url, data, headers, withCredentials, timeoutMs, }: AjaxOptions) => Promise<T>;
13
22
  /**
14
- * ajax请求
15
- * @param {AjaxOptions} params 请求配置
23
+ * 无鉴权 JSON POST(供 SDK 内部换取 accessToken 使用,不携带 Authorization 头)
24
+ * 与 postJsonWithAuth 相同的 fetch 优先、网络失败回退 XHR 策略。
25
+ * HTTP 状态错误(服务端已响应)直接抛出,不回退 XHR。
26
+ * @param url 请求地址(鉴权地址)
27
+ * @param payload 请求体(如 {"module":"track"})
28
+ * @param timeoutMs 请求超时(毫秒,G2;默认 10s 由调用方传 options.requestTimeout)
16
29
  */
17
- export declare const ajax: <T>({ method, url, data, headers, withCredentials, }: AjaxOptions) => Promise<T>;
30
+ export declare const postJson: <T>(url: string, payload: any, timeoutMs?: number) => Promise<T>;
18
31
  /**
19
- * sendBeacon请求
20
- * @param {string} url 接口地址
21
- * @param {BodyInit | null} data 请求数据
32
+ * 带 Bearer 鉴权的 JSON POST:优先 fetch keepalive,不支持/网络失败时回退 XHR。
33
+ * 彻底弃用 sendBeacon(无法携带 Authorization 头)。
34
+ * @param url 上报地址
35
+ * @param payload 上报数据
36
+ * @param credential accessToken 或 apiKey(作为 Bearer)
37
+ * @param timeoutMs 请求超时(毫秒,G2);0/undefined 不设超时(页面卸载补发路径)
22
38
  */
23
- export declare const sendBeacon: (url: string, data?: BodyInit | null) => boolean;
39
+ export declare const postJsonWithAuth: <T>(url: string, payload: any, credential?: string, timeoutMs?: number) => Promise<T>;
24
40
  export {};
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@tengence/track-sdk-web",
3
- "version": "1.1.3",
3
+ "version": "1.1.14",
4
4
  "description": "tengence web client track sdk",
5
5
  "main": "dist/index.mjs",
6
6
  "module": "dist/index.mjs",
7
+ "unpkg": "dist/tengence-track-sdk@1.1.14.js",
7
8
  "exports": {
8
9
  ".": {
9
10
  "import": {
@@ -14,13 +15,22 @@
14
15
  },
15
16
  "scripts": {
16
17
  "build": "rollup --c rollup.config.ts --configPlugin typescript",
17
- "release": "npm publish --access public --registry https://registry.npmjs.org/"
18
+ "release": "npm publish --access public --registry https://registry.npmjs.org/",
19
+ "deploy": "node scripts/deploy.mjs",
20
+ "publish:all": "npm run build && npm run release && npm run deploy",
21
+ "test": "vitest run",
22
+ "test:watch": "vitest",
23
+ "test:e2e": "node scripts/smoke-test.mjs",
24
+ "typecheck": "tsc --noEmit"
18
25
  },
19
26
  "private": false,
20
27
  "author": "tengence",
21
28
  "license": "ISC",
22
29
  "devDependencies": {
30
+ "@babel/core": "^7.29.7",
31
+ "@babel/preset-env": "^7.29.7",
23
32
  "@rollup/plugin-alias": "^5.1.1",
33
+ "@rollup/plugin-babel": "^7.1.0",
24
34
  "@rollup/plugin-commonjs": "^28.0.1",
25
35
  "@rollup/plugin-json": "^6.1.0",
26
36
  "@rollup/plugin-node-resolve": "^15.3.0",
@@ -28,10 +38,14 @@
28
38
  "@rollup/plugin-typescript": "^12.1.1",
29
39
  "@types/node": "^22.13.1",
30
40
  "cors": "^2.8.5",
41
+ "dotenv": "^17.4.2",
31
42
  "express": "^4.21.2",
43
+ "jsdom": "^30.1.3",
32
44
  "rollup": "^4.34.6",
45
+ "ssh2": "^1.17.0",
33
46
  "tslib": "^2.8.0",
34
47
  "typescript": "^4.9.5",
48
+ "vitest": "^5.0.5",
35
49
  "web-vitals": "^5.1.0"
36
50
  },
37
51
  "files": [