@be-link/cls-logger 1.0.12 → 1.2.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/dist/web.esm.js CHANGED
@@ -308,6 +308,7 @@ class ClsLoggerCore {
308
308
  * 设置页面可见性监听
309
309
  * - visibilitychange: 页面隐藏时使用 sendBeacon 发送队列
310
310
  * - pagehide: 作为移动端 fallback
311
+ * - 子类可覆写此方法以实现平台特定的监听(如小程序的 wx.onAppHide)
311
312
  */
312
313
  setupVisibilityListener() {
313
314
  if (typeof document === 'undefined' || typeof window === 'undefined')
@@ -979,6 +980,26 @@ function shouldIgnoreUrl$1(url, ignoreUrls) {
979
980
  }
980
981
  return false;
981
982
  }
983
+ function shouldAllowUrl$1(url, allowUrls) {
984
+ if (!allowUrls || allowUrls.length === 0)
985
+ return true;
986
+ const lowerUrl = url.toLowerCase();
987
+ for (const rule of allowUrls) {
988
+ if (typeof rule === 'string') {
989
+ if (lowerUrl.includes(rule.toLowerCase()))
990
+ return true;
991
+ continue;
992
+ }
993
+ try {
994
+ if (rule.test(url))
995
+ return true;
996
+ }
997
+ catch {
998
+ // ignore invalid regex
999
+ }
1000
+ }
1001
+ return false;
1002
+ }
982
1003
  function sampleHit$2(sampleRate) {
983
1004
  if (sampleRate >= 1)
984
1005
  return true;
@@ -997,6 +1018,8 @@ function buildPayload(params) {
997
1018
  return null;
998
1019
  if (shouldIgnoreUrl$1(url, options.ignoreUrls))
999
1020
  return null;
1021
+ if (!shouldAllowUrl$1(url, options.allowUrls))
1022
+ return null;
1000
1023
  if (!sampleHit$2(options.sampleRate))
1001
1024
  return null;
1002
1025
  const payload = { url };
@@ -1209,6 +1232,7 @@ function installWebRequestMonitor(report, opts = {}) {
1209
1232
  reportType: opts.reportType ?? 'http',
1210
1233
  sampleRate: opts.sampleRate ?? 1,
1211
1234
  ignoreUrls,
1235
+ allowUrls: opts.allowUrls ?? ['wejourney.top'],
1212
1236
  includeMethod: opts.includeMethod ?? true,
1213
1237
  includeQuery: opts.includeQuery ?? true,
1214
1238
  includeBody: opts.includeBody ?? true,
@@ -1455,6 +1479,26 @@ function shouldIgnoreUrl(url, ignoreUrls) {
1455
1479
  }
1456
1480
  return false;
1457
1481
  }
1482
+ function shouldAllowUrl(url, allowUrls) {
1483
+ if (!allowUrls || allowUrls.length === 0)
1484
+ return true;
1485
+ const lowerUrl = url.toLowerCase();
1486
+ for (const rule of allowUrls) {
1487
+ if (typeof rule === 'string') {
1488
+ if (lowerUrl.includes(rule.toLowerCase()))
1489
+ return true;
1490
+ continue;
1491
+ }
1492
+ try {
1493
+ if (rule.test(url))
1494
+ return true;
1495
+ }
1496
+ catch {
1497
+ // ignore invalid regex
1498
+ }
1499
+ }
1500
+ return false;
1501
+ }
1458
1502
  function getPagePath() {
1459
1503
  try {
1460
1504
  if (typeof window === 'undefined')
@@ -1481,6 +1525,7 @@ function installBrowserPerformanceMonitor(report, options) {
1481
1525
  return;
1482
1526
  w.__beLinkClsLoggerPerfInstalled__ = true;
1483
1527
  const ignoreUrls = [...DEFAULT_IGNORE, ...(options.ignoreUrls ?? [])];
1528
+ const allowUrls = options.allowUrls ?? [];
1484
1529
  // Navigation timing: TTFB 等
1485
1530
  if (options.navigationTiming) {
1486
1531
  try {
@@ -1628,7 +1673,7 @@ function installBrowserPerformanceMonitor(report, options) {
1628
1673
  return;
1629
1674
  for (const entry of list.getEntries()) {
1630
1675
  const name = String(entry?.name ?? '');
1631
- if (!name || shouldIgnoreUrl(name, ignoreUrls))
1676
+ if (!name || shouldIgnoreUrl(name, ignoreUrls) || !shouldAllowUrl(name, allowUrls))
1632
1677
  continue;
1633
1678
  const initiatorType = String(entry?.initiatorType ?? '');
1634
1679
  // 关注 fetch/xhr/img/script(同时允许 css/other 但不强制)
@@ -1703,6 +1748,7 @@ function installWebPerformanceMonitor(report, opts = {}) {
1703
1748
  reportType: raw.reportType ?? 'perf',
1704
1749
  sampleRate: raw.sampleRate ?? 1,
1705
1750
  ignoreUrls: raw.ignoreUrls ?? [],
1751
+ allowUrls: raw.allowUrls ?? ['wejourney.top', 'travelkeep.top', ' 8848top.com', 'yuanqiclub.com'],
1706
1752
  webVitals: raw.webVitals ?? true,
1707
1753
  navigationTiming: raw.navigationTiming ?? true,
1708
1754
  resourceTiming: raw.resourceTiming ?? true,
package/dist/web.js CHANGED
@@ -331,6 +331,7 @@ class ClsLoggerCore {
331
331
  * 设置页面可见性监听
332
332
  * - visibilitychange: 页面隐藏时使用 sendBeacon 发送队列
333
333
  * - pagehide: 作为移动端 fallback
334
+ * - 子类可覆写此方法以实现平台特定的监听(如小程序的 wx.onAppHide)
334
335
  */
335
336
  setupVisibilityListener() {
336
337
  if (typeof document === 'undefined' || typeof window === 'undefined')
@@ -1002,6 +1003,26 @@ function shouldIgnoreUrl$1(url, ignoreUrls) {
1002
1003
  }
1003
1004
  return false;
1004
1005
  }
1006
+ function shouldAllowUrl$1(url, allowUrls) {
1007
+ if (!allowUrls || allowUrls.length === 0)
1008
+ return true;
1009
+ const lowerUrl = url.toLowerCase();
1010
+ for (const rule of allowUrls) {
1011
+ if (typeof rule === 'string') {
1012
+ if (lowerUrl.includes(rule.toLowerCase()))
1013
+ return true;
1014
+ continue;
1015
+ }
1016
+ try {
1017
+ if (rule.test(url))
1018
+ return true;
1019
+ }
1020
+ catch {
1021
+ // ignore invalid regex
1022
+ }
1023
+ }
1024
+ return false;
1025
+ }
1005
1026
  function sampleHit$2(sampleRate) {
1006
1027
  if (sampleRate >= 1)
1007
1028
  return true;
@@ -1020,6 +1041,8 @@ function buildPayload(params) {
1020
1041
  return null;
1021
1042
  if (shouldIgnoreUrl$1(url, options.ignoreUrls))
1022
1043
  return null;
1044
+ if (!shouldAllowUrl$1(url, options.allowUrls))
1045
+ return null;
1023
1046
  if (!sampleHit$2(options.sampleRate))
1024
1047
  return null;
1025
1048
  const payload = { url };
@@ -1232,6 +1255,7 @@ function installWebRequestMonitor(report, opts = {}) {
1232
1255
  reportType: opts.reportType ?? 'http',
1233
1256
  sampleRate: opts.sampleRate ?? 1,
1234
1257
  ignoreUrls,
1258
+ allowUrls: opts.allowUrls ?? ['wejourney.top'],
1235
1259
  includeMethod: opts.includeMethod ?? true,
1236
1260
  includeQuery: opts.includeQuery ?? true,
1237
1261
  includeBody: opts.includeBody ?? true,
@@ -1478,6 +1502,26 @@ function shouldIgnoreUrl(url, ignoreUrls) {
1478
1502
  }
1479
1503
  return false;
1480
1504
  }
1505
+ function shouldAllowUrl(url, allowUrls) {
1506
+ if (!allowUrls || allowUrls.length === 0)
1507
+ return true;
1508
+ const lowerUrl = url.toLowerCase();
1509
+ for (const rule of allowUrls) {
1510
+ if (typeof rule === 'string') {
1511
+ if (lowerUrl.includes(rule.toLowerCase()))
1512
+ return true;
1513
+ continue;
1514
+ }
1515
+ try {
1516
+ if (rule.test(url))
1517
+ return true;
1518
+ }
1519
+ catch {
1520
+ // ignore invalid regex
1521
+ }
1522
+ }
1523
+ return false;
1524
+ }
1481
1525
  function getPagePath() {
1482
1526
  try {
1483
1527
  if (typeof window === 'undefined')
@@ -1504,6 +1548,7 @@ function installBrowserPerformanceMonitor(report, options) {
1504
1548
  return;
1505
1549
  w.__beLinkClsLoggerPerfInstalled__ = true;
1506
1550
  const ignoreUrls = [...DEFAULT_IGNORE, ...(options.ignoreUrls ?? [])];
1551
+ const allowUrls = options.allowUrls ?? [];
1507
1552
  // Navigation timing: TTFB 等
1508
1553
  if (options.navigationTiming) {
1509
1554
  try {
@@ -1651,7 +1696,7 @@ function installBrowserPerformanceMonitor(report, options) {
1651
1696
  return;
1652
1697
  for (const entry of list.getEntries()) {
1653
1698
  const name = String(entry?.name ?? '');
1654
- if (!name || shouldIgnoreUrl(name, ignoreUrls))
1699
+ if (!name || shouldIgnoreUrl(name, ignoreUrls) || !shouldAllowUrl(name, allowUrls))
1655
1700
  continue;
1656
1701
  const initiatorType = String(entry?.initiatorType ?? '');
1657
1702
  // 关注 fetch/xhr/img/script(同时允许 css/other 但不强制)
@@ -1726,6 +1771,7 @@ function installWebPerformanceMonitor(report, opts = {}) {
1726
1771
  reportType: raw.reportType ?? 'perf',
1727
1772
  sampleRate: raw.sampleRate ?? 1,
1728
1773
  ignoreUrls: raw.ignoreUrls ?? [],
1774
+ allowUrls: raw.allowUrls ?? ['wejourney.top', 'travelkeep.top', ' 8848top.com', 'yuanqiclub.com'],
1729
1775
  webVitals: raw.webVitals ?? true,
1730
1776
  navigationTiming: raw.navigationTiming ?? true,
1731
1777
  resourceTiming: raw.resourceTiming ?? true,
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@be-link/cls-logger",
3
- "version": "1.0.12",
3
+ "version": "1.2.0",
4
4
  "description": "@be-link cls-logger - 腾讯云 CLS 日志上报封装",
5
5
  "homepage": "https://github.com/snowmountain-top/be-link",
6
6
  "author": "zhuiyi",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/index.esm.js",
10
- "browser": "dist/index.umd.js",
11
10
  "types": "dist/index.d.ts",
12
11
  "exports": {
13
12
  ".": {
@@ -47,15 +46,6 @@
47
46
  "tencentcloud-cls-sdk-js-web": "^1.0.11",
48
47
  "tencentcloud-cls-sdk-js-mini": "^1.0.3"
49
48
  },
50
- "devDependencies": {
51
- "rimraf": "^5.0.0",
52
- "rollup": "^4.0.0",
53
- "@rollup/plugin-node-resolve": "^15.0.0",
54
- "@rollup/plugin-commonjs": "^25.0.0",
55
- "@rollup/plugin-typescript": "^11.0.0",
56
- "@rollup/plugin-json": "^6.0.0",
57
- "typescript": "^5.0.0"
58
- },
59
49
  "publishConfig": {
60
50
  "access": "public"
61
51
  },
@@ -66,6 +56,8 @@
66
56
  "clean": "rimraf ./dist && rimraf .rollup.cache",
67
57
  "build:js": "rollup --config rollup.config.ts --configPlugin typescript",
68
58
  "build:types": "tsc --project tsconfig.json",
69
- "build": "pnpm clean && pnpm build:js && pnpm build:types"
59
+ "build": "pnpm clean && pnpm build:js && pnpm build:types",
60
+ "lint": "eslint src --ext .ts,.tsx --fix",
61
+ "test": "echo \"No tests yet\" && exit 0"
70
62
  }
71
63
  }