uni-log-sdk 0.2.3 → 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/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  `uni-log-sdk` 的版本变更记录,按新→旧排列,日期为 npm 实际发布日期。
4
4
 
5
+ ## [0.3.0] — 2026-11-24
6
+
7
+ ### 新增
8
+
9
+ - **Web SPA 路由支持**:浏览器适配器自动识别 hash 路由(`#/path`、`#!/path`)与 history 路由(`pathname`);监听 `pushState` / `replaceState` / `popstate` / `hashchange`,路由变化自动累计 `page_count`,无需再手写 `pageView()`。`page` 只记录路径,不记录 query 和普通锚点,避免高基数。
10
+ - **Web 页面隐藏自动 flush**:`document.visibilitychange` 进入 `hidden` 时立即上报,降低切后台/关页丢失最后一批日志的概率。
11
+ - **业务租户维度**:新增 `header.bizTenantId`,SDK 支持 `bizTenantId` / `getBizTenantId`(登录后可变);与 `getUserId` 一起用于「账号级 + 租户级」归属,看板可按业务租户筛选。
12
+
13
+ ### 说明
14
+
15
+ - SPA 路由与 visibilitychange 仅影响浏览器适配器;`bizTenantId` 适用于 uni-app / Web / RN 所有适配器。
16
+ - **Web 端请移除原有路由变化处的 `pageView()` 调用**,否则会与自动累计重复计数。
17
+ - SSR 场景请在客户端挂载后再 `init()`。
18
+
19
+ ## [0.2.4] — 2026-11-16
20
+
21
+ ### 修复
22
+
23
+ - `initRN()` 现在要求显式传入 `serverUrl` 与 `appKey`,二者缺失时直接抛出 `[uni-log] initRN 缺少 serverUrl 或 appKey`。此前默认参数用 `{} as ...` 绕过了类型必填,JS 调用方漏传时不会报错,而是把日志发往 `undefined/ingest/v1/logs`,失败后难以定位。**这是破坏性变更**:如果你的项目正在无参或只传部分参数调用 `initRN()`,升级后会立刻抛错,请补齐这两个参数。
24
+
5
25
  ## [0.2.3] — 2026-11-16
6
26
 
7
27
  ### 新增
package/README.md CHANGED
@@ -12,7 +12,8 @@
12
12
  | --- | --- | --- |
13
13
  | uniapp / uniapp x(App·H5·小程序) | 主入口 `init()` 自动探测 uni 适配器 | console 劫持、页面栈、错误钩子全自动 |
14
14
  | **React Native(CLI / Expo)** | 子路径 `uni-log-sdk/react-native` 的 `initRN()` | 存储经 AsyncStorage(Expo Go 内置);页面路由需一行接线 |
15
- | **任意 TS Web 应用**(React / Vue / 纯浏览器) | 主入口 `init()` 自动探测浏览器适配器 | fetch + localStorage + window 错误事件,零配置 |
15
+ | **任意 TS Web 应用**(React / Vue / 纯浏览器) | 主入口 `init()` 自动探测浏览器适配器 | fetch + localStorage + window 错误事件;SPA hash/history 路由自动识别、页面隐藏自动 flush |
16
+ | **HarmonyOS 原生(ArkTS)** | 独立 HAR 包 `@tlovers/uni-log-sdk`(`packages/sdk-harmony`)的 `initHarmony()` | ohpm 安装;设备标识用 `deviceInfo.ODID`;详见下方「HarmonyOS 原生接入」 |
16
17
  | 非 TS 技术栈(Flutter / 原生) | 按协议自行实现(HTTP + JSON + HMAC-SHA256) | 服务端零改动,详见协议定义 `@uni-log/shared` |
17
18
 
18
19
  ### 适配器架构(贡献者向)
@@ -23,7 +24,7 @@
23
24
  src/adapters/
24
25
  ├── types.ts # PlatformAdapter / RequestOptions / RequestTask 纯接口
25
26
  ├── uni.ts # uni 适配器(uni-app / uni-app x):uni.request / 同步 storage / 页面栈三级兜底
26
- ├── web.ts # 浏览器适配器:localStorage / window 错误事件(SSR 防御)
27
+ ├── web.ts # 浏览器适配器:localStorage / window 错误事件 / SPA 路由与 visibilitychange(SSR 防御)
27
28
  ├── react-native.ts # RN 适配器:AsyncStorage 异步写穿+预读(ready 信号)/ ErrorUtils 链式
28
29
  ├── fetch.ts # web / react-native 共用的 fetch 请求实现(POST + AbortController)
29
30
  ├── detect.ts # detectAdapter:有 uni 全局走 uni,否则浏览器
@@ -112,7 +113,9 @@ init({
112
113
  | `channel` | string | - | 渠道 code / 小程序场景值 |
113
114
  | `deviceName` | string | - | 设备名称(给人看的) |
114
115
  | `getDeviceName` | `() => string` | - | 动态设备名称,优先级高于 `deviceName` |
115
- | `getUserId` | `() => string` | - | 业务用户标识 |
116
+ | `getUserId` | `() => string` | - | 业务用户标识(账号级归属) |
117
+ | `bizTenantId` | string | - | 业务租户/商户标识(静态) |
118
+ | `getBizTenantId` | `() => string` | - | 动态业务租户标识,优先级高于 `bizTenantId` |
116
119
  | `getNet` | `() => string` | - | 网络类型 |
117
120
  | `flushInterval` | number | `10000` | 上报间隔(毫秒) |
118
121
  | `collectErrors` | boolean | `true` | 自动捕获 `uni.onError` / `onUnhandledRejection` |
@@ -120,6 +123,31 @@ init({
120
123
  | `enabled` | boolean | `true` | 采集上报总开关;`false` 时不采集/不上报/不挂错误钩子 |
121
124
  | `debug` | boolean | `false` | 打印 SDK 内部日志 |
122
125
 
126
+ ### 业务租户 / 账号归属
127
+
128
+ 一个应用服务多个业务租户(客户/商户)时,用 `getUserId` 记账号、`getBizTenantId` 记租户:
129
+
130
+ ```ts
131
+ let userId: string | undefined
132
+ let bizTenantId: string | undefined
133
+
134
+ init({
135
+ serverUrl,
136
+ appKey,
137
+ appSecret,
138
+ getUserId: () => userId,
139
+ getBizTenantId: () => bizTenantId,
140
+ })
141
+
142
+ // 登录成功后
143
+ userId = account.id
144
+ bizTenantId = account.tenantId
145
+ ```
146
+
147
+ - `userId` 写入日志/事件/会话的 `userId`,用于账号级归属;
148
+ - `bizTenantId` 写入 `header.bizTenantId`,用于看板「业务租户」筛选与错误/事件/设备报表;
149
+ - 两者都是业务字段,**不参与看板登录权限**;不担心伪造时按普通字段使用即可。
150
+
123
151
  ### 开发环境不上报
124
152
 
125
153
  SDK 不会自己判断「这是开发版还是打包版」——各端机制不同(RN 有 `__DEV__`,Vite/webpack 注入 `NODE_ENV`,HBuilderX 自定义基座两者都没有),所以由宿主明确告知:
@@ -165,6 +193,15 @@ setEnabled(false) // 总开关:停采集并丢弃待发数据(isEnabled()
165
193
  await flush() // 应用退后台/页面隐藏时可主动上报
166
194
  ```
167
195
 
196
+ ## Web SPA 说明
197
+
198
+ - 自动识别 hash 路由(`#/path`、`#!/path`)与 history 路由(`pathname`);
199
+ - `page` 只记录路径,不记录 query 和普通锚点(避免 `?id=123` 把页面维度打散);hash 路由记为去掉 `#` 的 `/path`;
200
+ - 监听 `pushState` / `replaceState` / `popstate` / `hashchange`,路由变化自动累计 `page_count`;
201
+ - **Web 端不要再在路由变化处调用 `pageView()`**,否则会重复计数;uni-app / RN 仍按原方式手动调用;
202
+ - `document.visibilitychange` 进入 `hidden` 时自动 `flush()`,降低切后台/关页丢最后一批日志的概率;
203
+ - SSR 场景请在客户端挂载后再 `init()`(服务端没有 `window` 时不会挂路由/隐藏监听)。
204
+
168
205
  ## React Native / Expo 接入
169
206
 
170
207
  ```bash
@@ -187,6 +224,44 @@ initRN({
187
224
  - 未处理 Promise rejection 需宿主接线:`require('promise/setimmediate/rejection-tracking').enable({ allRejections: true, onUnhandled: (id, e) => ulog('error', String(e)) })`。
188
225
  - 存储经 AsyncStorage 异步写穿 + 冷启动预读;Expo Go 内置 async-storage,bare RN 需安装。
189
226
 
227
+ ## HarmonyOS 原生接入(ArkTS)
228
+
229
+ npm 包用于 uni-app / Web / React Native;**HarmonyOS 原生应用用独立 HAR 包**,两者协议与服务端完全一致。
230
+
231
+ ```bash
232
+ # 工程根 oh-package.json5
233
+ {
234
+ "dependencies": {
235
+ "@tlovers/uni-log-sdk": "file:../uni-log-sdk.har"
236
+ }
237
+ }
238
+ # 然后 ohpm install
239
+ ```
240
+
241
+ 在 `EntryAbility.ets` 里初始化(需要 `UIAbilityContext` 用于持久化):
242
+
243
+ ```ts
244
+ import { initHarmony } from '@tlovers/uni-log-sdk'
245
+
246
+ export default class EntryAbility extends UIAbility {
247
+ onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
248
+ initHarmony({
249
+ context: this.context,
250
+ serverUrl: 'https://log.example.com',
251
+ appKey: '<看板分配>',
252
+ appSecret: '<与 appKey 成对>',
253
+ appVer: '1.0.0',
254
+ getPage: () => 'pages/Index', // 可选:鸿蒙无全局页面栈
255
+ })
256
+ }
257
+ }
258
+ ```
259
+
260
+ - 设备标识用 `deviceInfo.ODID`(同步、无权限、同一开发者应用在同设备共享);ODID 为空时降级为本地持久化 UUID
261
+ - 网络需 `ohos.permission.INTERNET`(在宿主 `module.json5` 声明)
262
+ - 错误经 `errorManager.on('error')` 捕获;这是观察者语义,不会阻止应用退出
263
+ - 构建:`cd packages/sdk-harmony && hvigorw assembleHar`(产物 `uni_log_sdk/build/default/outputs/default/uni_log_sdk.har`)
264
+
190
265
  ## 注意事项
191
266
 
192
267
  - `serverUrl` 不要带尾斜杠;App 真机需用局域网 IP 或 HTTPS 域名,Android 9+ 默认禁止明文 HTTP。
@@ -1,4 +1,4 @@
1
- import { P as PlatformAdapter, U as UniLogOptions, a as UniLogClient } from '../client-ipC9gS50.mjs';
1
+ import { P as PlatformAdapter, U as UniLogOptions, a as UniLogClient } from '../client-D63QZD4X.mjs';
2
2
 
3
3
  interface ReactNativeAdapterOptions {
4
4
  /** 页面路由接线:返回当前页面名(如 react-navigation) */
@@ -9,6 +9,6 @@ declare function createReactNativeAdapter(options?: ReactNativeAdapterOptions):
9
9
  * RN / Expo 一键初始化:等价 init({ ...options, adapter: createReactNativeAdapter(options) })。
10
10
  * 页面接线:initRN({ getPage: () => navigationRef.getCurrentRoute()?.name, serverUrl, appKey, appSecret })
11
11
  */
12
- declare function initRN(options?: Omit<UniLogOptions, 'adapter'> & ReactNativeAdapterOptions): UniLogClient;
12
+ declare function initRN(options: Omit<UniLogOptions, 'adapter'> & ReactNativeAdapterOptions): UniLogClient;
13
13
 
14
14
  export { type ReactNativeAdapterOptions, createReactNativeAdapter, initRN };
@@ -1,4 +1,4 @@
1
- import { P as PlatformAdapter, U as UniLogOptions, a as UniLogClient } from '../client-ipC9gS50.js';
1
+ import { P as PlatformAdapter, U as UniLogOptions, a as UniLogClient } from '../client-D63QZD4X.js';
2
2
 
3
3
  interface ReactNativeAdapterOptions {
4
4
  /** 页面路由接线:返回当前页面名(如 react-navigation) */
@@ -9,6 +9,6 @@ declare function createReactNativeAdapter(options?: ReactNativeAdapterOptions):
9
9
  * RN / Expo 一键初始化:等价 init({ ...options, adapter: createReactNativeAdapter(options) })。
10
10
  * 页面接线:initRN({ getPage: () => navigationRef.getCurrentRoute()?.name, serverUrl, appKey, appSecret })
11
11
  */
12
- declare function initRN(options?: Omit<UniLogOptions, 'adapter'> & ReactNativeAdapterOptions): UniLogClient;
12
+ declare function initRN(options: Omit<UniLogOptions, 'adapter'> & ReactNativeAdapterOptions): UniLogClient;
13
13
 
14
14
  export { type ReactNativeAdapterOptions, createReactNativeAdapter, initRN };
@@ -1,3 +1,3 @@
1
- "use strict";var ae=Object.create;var U=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var $=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),ue=(n,t)=>{for(var e in t)U(n,e,{get:t[e],enumerable:!0})},J=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ce(t))!ge.call(n,o)&&o!==e&&U(n,o,{get:()=>t[o],enumerable:!(r=de(t,o))||r.enumerable});return n};var Y=(n,t,e)=>(e=n!=null?ae(le(n)):{},J(t||!n||!n.__esModule?U(e,"default",{value:n,enumerable:!0}):e,n)),fe=n=>J(U({},"__esModule",{value:!0}),n);var Q=$(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var Z=$(P=>{"use strict";var xe=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),be=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&xe(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});be(Q(),P)});var Oe={};ue(Oe,{createReactNativeAdapter:()=>ie,initRN:()=>Ne});module.exports=fe(Oe);function C(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}function S(){let n=globalThis.uni;return n!=null?n:null}function he(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function pe(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function G(n){return typeof n=="string"&&n.length>0?n:void 0}function me(n){let t=c=>{var u;try{return(u=c==null?void 0:c())!=null?u:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let d=(...c)=>c.map(G).find(Boolean),s=(...c)=>c.map(pe).find(u=>u!==void 0),a=d(r.deviceId,e.deviceId,e.deviceUUID),l=d(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!a||!l?null:{deviceId:a,platform:l,deviceName:d(r.deviceName,e.deviceName),model:d(r.deviceModel,e.deviceModel,e.model),vendor:d(r.deviceBrand,e.deviceBrand,e.brand),os:d(e.osVersion,e.system,r.osVersion,r.system),osVersion:d(e.osVersion,r.osVersion),osName:d(e.osName,r.osName,o.osName),net:d(e.networkType,e.netType),language:d(o.language,e.language),pixelRatio:s(i.pixelRatio,e.pixelRatio),windowWidth:s(i.windowWidth,e.windowWidth),windowHeight:s(i.windowHeight,e.windowHeight),screenWidth:s(i.screenWidth,e.screenWidth),screenHeight:s(i.screenHeight,e.screenHeight)}}function L(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return me(S())}catch{return null}},getCurrentPage(){var n;try{let t=he(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let d=r();return d&&(i=(o=G(d.hostVersion))!=null?o:G(d.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}var F="uni-log:web-did",B;function X(n){try{return window.localStorage.getItem(n)}catch{return null}}function z(n,t){try{window.localStorage.setItem(n,t)}catch{}}function ye(){var e;let n=(e=X(F))!=null?e:B;if(n)return B=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return B=t,z(F,t),t}function T(){return{request:C,getStorage:n=>X(n),setStorage:(n,t)=>z(n,t),getDeviceInfo(){return{deviceId:ye(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>typeof location!="undefined"?location.pathname:null,getPlatformVersion:()=>null,onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function V(){let n=globalThis;return typeof n!="undefined"&&n.uni?L():T()}var h=Y(Z());var ve=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function x(n,t){return n>>>t|n<<32-t}function ee(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function j(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),d=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(d>>>24&255,d>>>16&255,d>>>8&255,d&255);let s=new Array(64);for(let l=0;l<r.length;l+=64){for(let g=0;g<16;g++){let y=l+g*4;s[g]=(r[y]<<24|r[y+1]<<16|r[y+2]<<8|r[y+3])>>>0}for(let g=16;g<64;g++){let y=x(s[g-15],7)^x(s[g-15],18)^s[g-15]>>>3,A=x(s[g-2],17)^x(s[g-2],19)^s[g-2]>>>10;s[g]=s[g-16]+y+s[g-7]+A>>>0}let[c,u,b,R,m,v,w,k]=t;for(let g=0;g<64;g++){let y=x(m,6)^x(m,11)^x(m,25),A=m&v^~m&w,O=k+y+A+ve[g]+s[g]>>>0,_=x(c,2)^x(c,13)^x(c,22),D=c&u^c&b^u&b,se=_+D>>>0;k=w,w=v,v=m,m=R+O>>>0,R=b,b=u,u=c,c=O+se>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+u>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+R>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let a=[];for(let l of t)a.push(l>>>24&255,l>>>16&255,l>>>8&255,l&255);return a}function we(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function te(n,t){let e=ee(n);for(e.length>64&&(e=j(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return we(j(o.concat(j(r.concat(ee(t))))))}function q(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var I="uni-log:pending",ne=20,Se="0.2.3";function N(n,t){return n.length>t?n.slice(0,t):n}function W(n){let t=n==null?void 0:n.trim();return t?N(t,128):void 0}function Pe(n,t,e){var o;let r={t:Date.now(),lv:n,msg:N(t||"(empty)",h.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=N(e.stack,h.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=N(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var H=class{constructor(t,e=L()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(I,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=h.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(Pe(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=h.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>h.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=N(e,h.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=h.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?N(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var d,s,a,l,c,u,b,R,m,v,w,k,g,y,A,O,_,D;let e=(d=this.deviceInfo)!=null?d:this.deviceInfo=this.adapter.getDeviceInfo(),r=(u=(c=(l=this.deviceNameOverride)!=null?l:W((a=(s=this.options).getDeviceName)==null?void 0:a.call(s)))!=null?c:W(this.options.deviceName))!=null?u:W(e==null?void 0:e.deviceName),o={deviceId:(b=e==null?void 0:e.deviceId)!=null?b:this.fallbackDeviceId(),platform:(R=e==null?void 0:e.platform)!=null?R:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((w=e==null?void 0:e.net)!=null?w:(v=(m=this.options).getNet)!=null&&v.call(m))?{net:(y=e==null?void 0:e.net)!=null?y:(g=(k=this.options).getNet)==null?void 0:g.call(k)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}};return{header:{appKey:this.options.appKey,batchId:q(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(O=(A=this.options).getUserId)!=null&&O.call(A)?{userId:this.options.getUserId()}:{},...(D=(_=this.options).getNet)!=null&&D.call(_)?{net:this.options.getNet()}:{},sdkVer:Se,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,h.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,h.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var s;let r=!1,o,i=a=>{r||(r=!0,clearTimeout(d),e(a))},d=setTimeout(()=>{var a;try{(a=o==null?void 0:o.abort)==null||a.call(o)}catch{}i(!1)},8e3);try{let a=JSON.stringify(t),l={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),u=q(16);l[h.SIGNATURE_HEADERS.ts]=c,l[h.SIGNATURE_HEADERS.nonce]=u,l[h.SIGNATURE_HEADERS.sign]=te(this.options.appSecret,`${c}
1
+ "use strict";var he=Object.create;var U=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ye=Object.getPrototypeOf,xe=Object.prototype.hasOwnProperty;var X=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),be=(n,t)=>{for(var e in t)U(n,e,{get:t[e],enumerable:!0})},Q=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of me(t))!xe.call(n,o)&&o!==e&&U(n,o,{get:()=>t[o],enumerable:!(r=pe(t,o))||r.enumerable});return n};var Z=(n,t,e)=>(e=n!=null?he(ye(n)):{},Q(t||!n||!n.__esModule?U(e,"default",{value:n,enumerable:!0}):e,n)),ve=n=>Q(U({},"__esModule",{value:!0}),n);var se=X(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var ae=X(P=>{"use strict";var ke=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),Re=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&ke(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});Re(se(),P)});var Ve={};be(Ve,{createReactNativeAdapter:()=>fe,initRN:()=>He});module.exports=ve(Ve);function T(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}function S(){let n=globalThis.uni;return n!=null?n:null}function we(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function Se(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function j(n){return typeof n=="string"&&n.length>0?n:void 0}function Pe(n){let t=c=>{var u;try{return(u=c==null?void 0:c())!=null?u:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let d=(...c)=>c.map(j).find(Boolean),s=(...c)=>c.map(Se).find(u=>u!==void 0),a=d(r.deviceId,e.deviceId,e.deviceUUID),l=d(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!a||!l?null:{deviceId:a,platform:l,deviceName:d(r.deviceName,e.deviceName),model:d(r.deviceModel,e.deviceModel,e.model),vendor:d(r.deviceBrand,e.deviceBrand,e.brand),os:d(e.osVersion,e.system,r.osVersion,r.system),osVersion:d(e.osVersion,r.osVersion),osName:d(e.osName,r.osName,o.osName),net:d(e.networkType,e.netType),language:d(o.language,e.language),pixelRatio:s(i.pixelRatio,e.pixelRatio),windowWidth:s(i.windowWidth,e.windowWidth),windowHeight:s(i.windowHeight,e.windowHeight),screenWidth:s(i.screenWidth,e.screenWidth),screenHeight:s(i.screenHeight,e.screenHeight)}}function O(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return Pe(S())}catch{return null}},getCurrentPage(){var n;try{let t=we(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let d=r();return d&&(i=(o=j(d.hostVersion))!=null?o:j(d.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}var ee="uni-log:web-did",q,ne=new Set,te=!1;function re(){if(typeof location=="undefined")return null;let n=location.pathname||"/",t=location.hash||"";return/^#!?\//.test(t)?t.replace(/^#!?/,"").split("?")[0]||"/":n||"/"}function W(){let n=re();for(let t of ne)try{t(n)}catch{}}function Ie(){if(te||typeof window=="undefined")return;te=!0,window.addEventListener("popstate",W),window.addEventListener("hashchange",W);let n=window.history;for(let t of["pushState","replaceState"]){let e=n[t];typeof e=="function"&&(n[t]=function(...r){let o=e.apply(this,r);return W(),o})}}function oe(n){try{return window.localStorage.getItem(n)}catch{return null}}function ie(n,t){try{window.localStorage.setItem(n,t)}catch{}}function Ee(){var e;let n=(e=oe(ee))!=null?e:q;if(n)return q=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return q=t,ie(ee,t),t}function H(){return{request:T,getStorage:n=>oe(n),setStorage:(n,t)=>ie(n,t),getDeviceInfo(){return{deviceId:Ee(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>re(),getPlatformVersion:()=>null,onPageChange(n){ne.add(n),Ie()},onHidden(n){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&n()})},onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function V(){let n=globalThis;return typeof n!="undefined"&&n.uni?O():H()}var h=Z(ae());var Le=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function x(n,t){return n>>>t|n<<32-t}function de(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function K(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),d=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(d>>>24&255,d>>>16&255,d>>>8&255,d&255);let s=new Array(64);for(let l=0;l<r.length;l+=64){for(let g=0;g<16;g++){let y=l+g*4;s[g]=(r[y]<<24|r[y+1]<<16|r[y+2]<<8|r[y+3])>>>0}for(let g=16;g<64;g++){let y=x(s[g-15],7)^x(s[g-15],18)^s[g-15]>>>3,L=x(s[g-2],17)^x(s[g-2],19)^s[g-2]>>>10;s[g]=s[g-16]+y+s[g-7]+L>>>0}let[c,u,b,k,m,v,w,R]=t;for(let g=0;g<64;g++){let y=x(m,6)^x(m,11)^x(m,25),L=m&v^~m&w,N=R+y+L+Le[g]+s[g]>>>0,_=x(c,2)^x(c,13)^x(c,22),D=c&u^c&b^u&b,C=_+D>>>0;R=w,w=v,v=m,m=k+N>>>0,k=b,b=u,u=c,c=N+C>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+u>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+k>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+R>>>0}let a=[];for(let l of t)a.push(l>>>24&255,l>>>16&255,l>>>8&255,l&255);return a}function Ae(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function ce(n,t){let e=de(n);for(e.length>64&&(e=K(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return Ae(K(o.concat(K(r.concat(de(t))))))}function $(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var I="uni-log:pending",le=20,Ne="0.3.0";function A(n,t){return n.length>t?n.slice(0,t):n}function M(n){let t=n==null?void 0:n.trim();return t?A(t,128):void 0}function Oe(n,t,e){var o;let r={t:Date.now(),lv:n,msg:A(t||"(empty)",h.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=A(e.stack,h.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=A(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var B=class{constructor(t,e=O()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.lifecycleInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r,o,i,d,s;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.lifecycleInstalled||((i=(o=this.adapter).onPageChange)==null||i.call(o,a=>{!this.ready||!a||a===this.lastPage||(this.lastPage=a,this.pageCount+=1)}),(s=(d=this.adapter).onHidden)==null||s.call(d,()=>{this.flush().catch(()=>{})}),this.lifecycleInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(I,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=h.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(Oe(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=h.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>h.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=A(e,h.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=h.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?A(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var s,a,l,c,u,b,k,m,v,w,R,g,y,L,N,_,D,C,z,Y,F;let e=(s=this.deviceInfo)!=null?s:this.deviceInfo=this.adapter.getDeviceInfo(),r=(b=(u=(c=this.deviceNameOverride)!=null?c:M((l=(a=this.options).getDeviceName)==null?void 0:l.call(a)))!=null?u:M(this.options.deviceName))!=null?b:M(e==null?void 0:e.deviceName),o={deviceId:(k=e==null?void 0:e.deviceId)!=null?k:this.fallbackDeviceId(),platform:(m=e==null?void 0:e.platform)!=null?m:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((R=e==null?void 0:e.net)!=null?R:(w=(v=this.options).getNet)!=null&&w.call(v))?{net:(L=e==null?void 0:e.net)!=null?L:(y=(g=this.options).getNet)==null?void 0:y.call(g)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}},i=M((D=(_=(N=this.options).getBizTenantId)==null?void 0:_.call(N))!=null?D:this.options.bizTenantId);return{header:{appKey:this.options.appKey,batchId:$(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(z=(C=this.options).getUserId)!=null&&z.call(C)?{userId:this.options.getUserId()}:{},...i?{bizTenantId:i}:{},...(F=(Y=this.options).getNet)!=null&&F.call(Y)?{net:this.options.getNet()}:{},sdkVer:Ne,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,h.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,h.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var s;let r=!1,o,i=a=>{r||(r=!0,clearTimeout(d),e(a))},d=setTimeout(()=>{var a;try{(a=o==null?void 0:o.abort)==null||a.call(o)}catch{}i(!1)},8e3);try{let a=JSON.stringify(t),l={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),u=$(16);l[h.SIGNATURE_HEADERS.ts]=c,l[h.SIGNATURE_HEADERS.nonce]=u,l[h.SIGNATURE_HEADERS.sign]=ce(this.options.appSecret,`${c}
2
2
  ${u}
3
- ${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:l,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?s:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let d={};for(let s of Object.keys(i))d[s]=r(i[s]);return d}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(I),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>ne&&(r=r.slice(-ne));try{this.adapter.setStorage(I,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(I);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(I,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(I,"");return}this.adapter.setStorage(I,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var f=null;function oe(n){var t;return f==null||f.stop(),f=new H(n,(t=n.adapter)!=null?t:V()),f.start(),n.hookConsole!==!1&&Re(),f}var Ie={debug:(n,t)=>f==null?void 0:f.log("debug",n,t),info:(n,t)=>f==null?void 0:f.log("info",n,t),warn:(n,t)=>f==null?void 0:f.log("warn",n,t),error:(n,t)=>f==null?void 0:f.log("error",n,t)},re=new Set,Ee=!0;function Re(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(re.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...d)=>{Ee&&Ie[r](d.map(ke).join(" ")),i(...d)},re.add(e)}}function ke(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}var E=require("react-native"),K=Y(require("@react-native-async-storage/async-storage")),Ae="uni-log:pending",M="uni-log:did";function ie(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[Ae,M]){let l=await K.default.getItem(a);l!=null&&t.set(a,l)}let s=t.get(M);s&&(e=s)}catch{}})(),o=s=>{var a;return(a=t.get(s))!=null?a:null},i=(s,a)=>{t.set(s,a),K.default.setItem(s,a).catch(()=>{})},d=()=>{var s;return e||(e=(s=o(M))!=null?s:void 0,e||(e=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,i(M,e))),e};return{ready:r,request:C,getStorage:s=>o(s),setStorage:(s,a)=>i(s,a),getDeviceInfo(){return{deviceId:d(),platform:E.Platform.OS==="ios"?"ios":E.Platform.OS==="android"?"android":E.Platform.OS,osName:E.Platform.OS,os:String(E.Platform.Version),osVersion:String(E.Platform.Version)}},getCurrentPage:()=>{var s,a;return(a=(s=n.getPage)==null?void 0:s.call(n))!=null?a:null},getPlatformVersion:()=>null,onError(s){let a=globalThis.ErrorUtils;if(typeof(a==null?void 0:a.setGlobalHandler)!="function")return;let l=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((c,u)=>{s(c),typeof l=="function"&&l(c,u)})},onUnhandledRejection(s){}}}function Ne(n={}){let{getPage:t,...e}=n;return oe({...e,adapter:ie({getPage:t})})}0&&(module.exports={createReactNativeAdapter,initRN});
3
+ ${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:l,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?s:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let d={};for(let s of Object.keys(i))d[s]=r(i[s]);return d}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(I),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>le&&(r=r.slice(-le));try{this.adapter.setStorage(I,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(I);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(I,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(I,"");return}this.adapter.setStorage(I,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var f=null;function ue(n){var t;return f==null||f.stop(),f=new B(n,(t=n.adapter)!=null?t:V()),f.start(),n.hookConsole!==!1&&Ce(),f}var _e={debug:(n,t)=>f==null?void 0:f.log("debug",n,t),info:(n,t)=>f==null?void 0:f.log("info",n,t),warn:(n,t)=>f==null?void 0:f.log("warn",n,t),error:(n,t)=>f==null?void 0:f.log("error",n,t)},ge=new Set,De=!0;function Ce(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(ge.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...d)=>{De&&_e[r](d.map(Ue).join(" ")),i(...d)},ge.add(e)}}function Ue(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}var E=require("react-native"),J=Z(require("@react-native-async-storage/async-storage")),Te="uni-log:pending",G="uni-log:did";function fe(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[Te,G]){let l=await J.default.getItem(a);l!=null&&t.set(a,l)}let s=t.get(G);s&&(e=s)}catch{}})(),o=s=>{var a;return(a=t.get(s))!=null?a:null},i=(s,a)=>{t.set(s,a),J.default.setItem(s,a).catch(()=>{})},d=()=>{var s;return e||(e=(s=o(G))!=null?s:void 0,e||(e=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,i(G,e))),e};return{ready:r,request:T,getStorage:s=>o(s),setStorage:(s,a)=>i(s,a),getDeviceInfo(){return{deviceId:d(),platform:E.Platform.OS==="ios"?"ios":E.Platform.OS==="android"?"android":E.Platform.OS,osName:E.Platform.OS,os:String(E.Platform.Version),osVersion:String(E.Platform.Version)}},getCurrentPage:()=>{var s,a;return(a=(s=n.getPage)==null?void 0:s.call(n))!=null?a:null},getPlatformVersion:()=>null,onError(s){let a=globalThis.ErrorUtils;if(typeof(a==null?void 0:a.setGlobalHandler)!="function")return;let l=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((c,u)=>{s(c),typeof l=="function"&&l(c,u)})},onUnhandledRejection(s){}}}function He(n){if(!(n!=null&&n.serverUrl)||!(n!=null&&n.appKey))throw new Error("[uni-log] initRN \u7F3A\u5C11 serverUrl \u6216 appKey");let{getPage:t,...e}=n;return ue({...e,adapter:fe({getPage:t})})}0&&(module.exports={createReactNativeAdapter,initRN});
@@ -1,3 +1,3 @@
1
- var oe=Object.create;var W=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var K=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var ce=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of se(t))!de.call(n,o)&&o!==e&&W(n,o,{get:()=>t[o],enumerable:!(r=ie(t,o))||r.enumerable});return n};var le=(n,t,e)=>(e=n!=null?oe(ae(n)):{},ce(t||!n||!n.__esModule?W(e,"default",{value:n,enumerable:!0}):e,n));var F=K(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var X=K(P=>{"use strict";var pe=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),me=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&pe(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});me(F(),P)});function U(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}function S(){let n=globalThis.uni;return n!=null?n:null}function ge(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function ue(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function M(n){return typeof n=="string"&&n.length>0?n:void 0}function fe(n){let t=c=>{var u;try{return(u=c==null?void 0:c())!=null?u:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let d=(...c)=>c.map(M).find(Boolean),s=(...c)=>c.map(ue).find(u=>u!==void 0),a=d(r.deviceId,e.deviceId,e.deviceUUID),l=d(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!a||!l?null:{deviceId:a,platform:l,deviceName:d(r.deviceName,e.deviceName),model:d(r.deviceModel,e.deviceModel,e.model),vendor:d(r.deviceBrand,e.deviceBrand,e.brand),os:d(e.osVersion,e.system,r.osVersion,r.system),osVersion:d(e.osVersion,r.osVersion),osName:d(e.osName,r.osName,o.osName),net:d(e.networkType,e.netType),language:d(o.language,e.language),pixelRatio:s(i.pixelRatio,e.pixelRatio),windowWidth:s(i.windowWidth,e.windowWidth),windowHeight:s(i.windowHeight,e.windowHeight),screenWidth:s(i.screenWidth,e.screenWidth),screenHeight:s(i.screenHeight,e.screenHeight)}}function L(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return fe(S())}catch{return null}},getCurrentPage(){var n;try{let t=ge(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let d=r();return d&&(i=(o=M(d.hostVersion))!=null?o:M(d.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}var $="uni-log:web-did",G;function J(n){try{return window.localStorage.getItem(n)}catch{return null}}function Y(n,t){try{window.localStorage.setItem(n,t)}catch{}}function he(){var e;let n=(e=J($))!=null?e:G;if(n)return G=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return G=t,Y($,t),t}function C(){return{request:U,getStorage:n=>J(n),setStorage:(n,t)=>Y(n,t),getDeviceInfo(){return{deviceId:he(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>typeof location!="undefined"?location.pathname:null,getPlatformVersion:()=>null,onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function T(){let n=globalThis;return typeof n!="undefined"&&n.uni?L():C()}var h=le(X());var ye=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function x(n,t){return n>>>t|n<<32-t}function z(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function B(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),d=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(d>>>24&255,d>>>16&255,d>>>8&255,d&255);let s=new Array(64);for(let l=0;l<r.length;l+=64){for(let g=0;g<16;g++){let y=l+g*4;s[g]=(r[y]<<24|r[y+1]<<16|r[y+2]<<8|r[y+3])>>>0}for(let g=16;g<64;g++){let y=x(s[g-15],7)^x(s[g-15],18)^s[g-15]>>>3,k=x(s[g-2],17)^x(s[g-2],19)^s[g-2]>>>10;s[g]=s[g-16]+y+s[g-7]+k>>>0}let[c,u,b,E,m,v,w,R]=t;for(let g=0;g<64;g++){let y=x(m,6)^x(m,11)^x(m,25),k=m&v^~m&w,O=R+y+k+ye[g]+s[g]>>>0,_=x(c,2)^x(c,13)^x(c,22),D=c&u^c&b^u&b,re=_+D>>>0;R=w,w=v,v=m,m=E+O>>>0,E=b,b=u,u=c,c=O+re>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+u>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+E>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+R>>>0}let a=[];for(let l of t)a.push(l>>>24&255,l>>>16&255,l>>>8&255,l&255);return a}function xe(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function Q(n,t){let e=z(n);for(e.length>64&&(e=B(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return xe(B(o.concat(B(r.concat(z(t))))))}function j(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var I="uni-log:pending",Z=20,be="0.2.3";function A(n,t){return n.length>t?n.slice(0,t):n}function q(n){let t=n==null?void 0:n.trim();return t?A(t,128):void 0}function ve(n,t,e){var o;let r={t:Date.now(),lv:n,msg:A(t||"(empty)",h.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=A(e.stack,h.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=A(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var V=class{constructor(t,e=L()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(I,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=h.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(ve(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=h.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>h.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=A(e,h.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=h.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?A(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var d,s,a,l,c,u,b,E,m,v,w,R,g,y,k,O,_,D;let e=(d=this.deviceInfo)!=null?d:this.deviceInfo=this.adapter.getDeviceInfo(),r=(u=(c=(l=this.deviceNameOverride)!=null?l:q((a=(s=this.options).getDeviceName)==null?void 0:a.call(s)))!=null?c:q(this.options.deviceName))!=null?u:q(e==null?void 0:e.deviceName),o={deviceId:(b=e==null?void 0:e.deviceId)!=null?b:this.fallbackDeviceId(),platform:(E=e==null?void 0:e.platform)!=null?E:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((w=e==null?void 0:e.net)!=null?w:(v=(m=this.options).getNet)!=null&&v.call(m))?{net:(y=e==null?void 0:e.net)!=null?y:(g=(R=this.options).getNet)==null?void 0:g.call(R)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}};return{header:{appKey:this.options.appKey,batchId:j(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(O=(k=this.options).getUserId)!=null&&O.call(k)?{userId:this.options.getUserId()}:{},...(D=(_=this.options).getNet)!=null&&D.call(_)?{net:this.options.getNet()}:{},sdkVer:be,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,h.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,h.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var s;let r=!1,o,i=a=>{r||(r=!0,clearTimeout(d),e(a))},d=setTimeout(()=>{var a;try{(a=o==null?void 0:o.abort)==null||a.call(o)}catch{}i(!1)},8e3);try{let a=JSON.stringify(t),l={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),u=j(16);l[h.SIGNATURE_HEADERS.ts]=c,l[h.SIGNATURE_HEADERS.nonce]=u,l[h.SIGNATURE_HEADERS.sign]=Q(this.options.appSecret,`${c}
1
+ var ge=Object.create;var Y=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var F=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var me=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of fe(t))!pe.call(n,o)&&o!==e&&Y(n,o,{get:()=>t[o],enumerable:!(r=ue(t,o))||r.enumerable});return n};var ye=(n,t,e)=>(e=n!=null?ge(he(n)):{},me(t||!n||!n.__esModule?Y(e,"default",{value:n,enumerable:!0}):e,n));var re=F(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var oe=F(P=>{"use strict";var Pe=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),Ie=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&Pe(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});Ie(re(),P)});function U(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}function S(){let n=globalThis.uni;return n!=null?n:null}function xe(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function be(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function G(n){return typeof n=="string"&&n.length>0?n:void 0}function ve(n){let t=c=>{var u;try{return(u=c==null?void 0:c())!=null?u:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let d=(...c)=>c.map(G).find(Boolean),s=(...c)=>c.map(be).find(u=>u!==void 0),a=d(r.deviceId,e.deviceId,e.deviceUUID),l=d(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!a||!l?null:{deviceId:a,platform:l,deviceName:d(r.deviceName,e.deviceName),model:d(r.deviceModel,e.deviceModel,e.model),vendor:d(r.deviceBrand,e.deviceBrand,e.brand),os:d(e.osVersion,e.system,r.osVersion,r.system),osVersion:d(e.osVersion,r.osVersion),osName:d(e.osName,r.osName,o.osName),net:d(e.networkType,e.netType),language:d(o.language,e.language),pixelRatio:s(i.pixelRatio,e.pixelRatio),windowWidth:s(i.windowWidth,e.windowWidth),windowHeight:s(i.windowHeight,e.windowHeight),screenWidth:s(i.screenWidth,e.screenWidth),screenHeight:s(i.screenHeight,e.screenHeight)}}function O(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return ve(S())}catch{return null}},getCurrentPage(){var n;try{let t=xe(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let d=r();return d&&(i=(o=G(d.hostVersion))!=null?o:G(d.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}var X="uni-log:web-did",j,Z=new Set,Q=!1;function ee(){if(typeof location=="undefined")return null;let n=location.pathname||"/",t=location.hash||"";return/^#!?\//.test(t)?t.replace(/^#!?/,"").split("?")[0]||"/":n||"/"}function q(){let n=ee();for(let t of Z)try{t(n)}catch{}}function we(){if(Q||typeof window=="undefined")return;Q=!0,window.addEventListener("popstate",q),window.addEventListener("hashchange",q);let n=window.history;for(let t of["pushState","replaceState"]){let e=n[t];typeof e=="function"&&(n[t]=function(...r){let o=e.apply(this,r);return q(),o})}}function te(n){try{return window.localStorage.getItem(n)}catch{return null}}function ne(n,t){try{window.localStorage.setItem(n,t)}catch{}}function Se(){var e;let n=(e=te(X))!=null?e:j;if(n)return j=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return j=t,ne(X,t),t}function T(){return{request:U,getStorage:n=>te(n),setStorage:(n,t)=>ne(n,t),getDeviceInfo(){return{deviceId:Se(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>ee(),getPlatformVersion:()=>null,onPageChange(n){Z.add(n),we()},onHidden(n){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&n()})},onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function H(){let n=globalThis;return typeof n!="undefined"&&n.uni?O():T()}var h=ye(oe());var Ee=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function x(n,t){return n>>>t|n<<32-t}function ie(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function W(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),d=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(d>>>24&255,d>>>16&255,d>>>8&255,d&255);let s=new Array(64);for(let l=0;l<r.length;l+=64){for(let g=0;g<16;g++){let y=l+g*4;s[g]=(r[y]<<24|r[y+1]<<16|r[y+2]<<8|r[y+3])>>>0}for(let g=16;g<64;g++){let y=x(s[g-15],7)^x(s[g-15],18)^s[g-15]>>>3,R=x(s[g-2],17)^x(s[g-2],19)^s[g-2]>>>10;s[g]=s[g-16]+y+s[g-7]+R>>>0}let[c,u,b,E,m,v,w,k]=t;for(let g=0;g<64;g++){let y=x(m,6)^x(m,11)^x(m,25),R=m&v^~m&w,N=k+y+R+Ee[g]+s[g]>>>0,_=x(c,2)^x(c,13)^x(c,22),D=c&u^c&b^u&b,C=_+D>>>0;k=w,w=v,v=m,m=E+N>>>0,E=b,b=u,u=c,c=N+C>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+u>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+E>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let a=[];for(let l of t)a.push(l>>>24&255,l>>>16&255,l>>>8&255,l&255);return a}function ke(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function se(n,t){let e=ie(n);for(e.length>64&&(e=W(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return ke(W(o.concat(W(r.concat(ie(t))))))}function K(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var I="uni-log:pending",ae=20,Re="0.3.0";function L(n,t){return n.length>t?n.slice(0,t):n}function V(n){let t=n==null?void 0:n.trim();return t?L(t,128):void 0}function Le(n,t,e){var o;let r={t:Date.now(),lv:n,msg:L(t||"(empty)",h.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=L(e.stack,h.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=L(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var M=class{constructor(t,e=O()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.lifecycleInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r,o,i,d,s;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.lifecycleInstalled||((i=(o=this.adapter).onPageChange)==null||i.call(o,a=>{!this.ready||!a||a===this.lastPage||(this.lastPage=a,this.pageCount+=1)}),(s=(d=this.adapter).onHidden)==null||s.call(d,()=>{this.flush().catch(()=>{})}),this.lifecycleInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(I,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=h.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(Le(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=h.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>h.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=L(e,h.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=h.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?L(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var s,a,l,c,u,b,E,m,v,w,k,g,y,R,N,_,D,C,$,J,z;let e=(s=this.deviceInfo)!=null?s:this.deviceInfo=this.adapter.getDeviceInfo(),r=(b=(u=(c=this.deviceNameOverride)!=null?c:V((l=(a=this.options).getDeviceName)==null?void 0:l.call(a)))!=null?u:V(this.options.deviceName))!=null?b:V(e==null?void 0:e.deviceName),o={deviceId:(E=e==null?void 0:e.deviceId)!=null?E:this.fallbackDeviceId(),platform:(m=e==null?void 0:e.platform)!=null?m:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((k=e==null?void 0:e.net)!=null?k:(w=(v=this.options).getNet)!=null&&w.call(v))?{net:(R=e==null?void 0:e.net)!=null?R:(y=(g=this.options).getNet)==null?void 0:y.call(g)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}},i=V((D=(_=(N=this.options).getBizTenantId)==null?void 0:_.call(N))!=null?D:this.options.bizTenantId);return{header:{appKey:this.options.appKey,batchId:K(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...($=(C=this.options).getUserId)!=null&&$.call(C)?{userId:this.options.getUserId()}:{},...i?{bizTenantId:i}:{},...(z=(J=this.options).getNet)!=null&&z.call(J)?{net:this.options.getNet()}:{},sdkVer:Re,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,h.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,h.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var s;let r=!1,o,i=a=>{r||(r=!0,clearTimeout(d),e(a))},d=setTimeout(()=>{var a;try{(a=o==null?void 0:o.abort)==null||a.call(o)}catch{}i(!1)},8e3);try{let a=JSON.stringify(t),l={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),u=K(16);l[h.SIGNATURE_HEADERS.ts]=c,l[h.SIGNATURE_HEADERS.nonce]=u,l[h.SIGNATURE_HEADERS.sign]=se(this.options.appSecret,`${c}
2
2
  ${u}
3
- ${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:l,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?s:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let d={};for(let s of Object.keys(i))d[s]=r(i[s]);return d}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(I),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>Z&&(r=r.slice(-Z));try{this.adapter.setStorage(I,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(I);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(I,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(I,"");return}this.adapter.setStorage(I,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var f=null;function te(n){var t;return f==null||f.stop(),f=new V(n,(t=n.adapter)!=null?t:T()),f.start(),n.hookConsole!==!1&&Pe(),f}var we={debug:(n,t)=>f==null?void 0:f.log("debug",n,t),info:(n,t)=>f==null?void 0:f.log("info",n,t),warn:(n,t)=>f==null?void 0:f.log("warn",n,t),error:(n,t)=>f==null?void 0:f.log("error",n,t)},ee=new Set,Se=!0;function Pe(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(ee.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...d)=>{Se&&we[r](d.map(Ie).join(" ")),i(...d)},ee.add(e)}}function Ie(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}import{Platform as N}from"react-native";import ne from"@react-native-async-storage/async-storage";var Ee="uni-log:pending",H="uni-log:did";function Re(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[Ee,H]){let l=await ne.getItem(a);l!=null&&t.set(a,l)}let s=t.get(H);s&&(e=s)}catch{}})(),o=s=>{var a;return(a=t.get(s))!=null?a:null},i=(s,a)=>{t.set(s,a),ne.setItem(s,a).catch(()=>{})},d=()=>{var s;return e||(e=(s=o(H))!=null?s:void 0,e||(e=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,i(H,e))),e};return{ready:r,request:U,getStorage:s=>o(s),setStorage:(s,a)=>i(s,a),getDeviceInfo(){return{deviceId:d(),platform:N.OS==="ios"?"ios":N.OS==="android"?"android":N.OS,osName:N.OS,os:String(N.Version),osVersion:String(N.Version)}},getCurrentPage:()=>{var s,a;return(a=(s=n.getPage)==null?void 0:s.call(n))!=null?a:null},getPlatformVersion:()=>null,onError(s){let a=globalThis.ErrorUtils;if(typeof(a==null?void 0:a.setGlobalHandler)!="function")return;let l=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((c,u)=>{s(c),typeof l=="function"&&l(c,u)})},onUnhandledRejection(s){}}}function Ze(n={}){let{getPage:t,...e}=n;return te({...e,adapter:Re({getPage:t})})}export{Re as createReactNativeAdapter,Ze as initRN};
3
+ ${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:l,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?s:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let d={};for(let s of Object.keys(i))d[s]=r(i[s]);return d}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(I),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>ae&&(r=r.slice(-ae));try{this.adapter.setStorage(I,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(I);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(I,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(I,"");return}this.adapter.setStorage(I,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var f=null;function ce(n){var t;return f==null||f.stop(),f=new M(n,(t=n.adapter)!=null?t:H()),f.start(),n.hookConsole!==!1&&Oe(),f}var Ae={debug:(n,t)=>f==null?void 0:f.log("debug",n,t),info:(n,t)=>f==null?void 0:f.log("info",n,t),warn:(n,t)=>f==null?void 0:f.log("warn",n,t),error:(n,t)=>f==null?void 0:f.log("error",n,t)},de=new Set,Ne=!0;function Oe(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(de.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...d)=>{Ne&&Ae[r](d.map(_e).join(" ")),i(...d)},de.add(e)}}function _e(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}import{Platform as A}from"react-native";import le from"@react-native-async-storage/async-storage";var De="uni-log:pending",B="uni-log:did";function Ce(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[De,B]){let l=await le.getItem(a);l!=null&&t.set(a,l)}let s=t.get(B);s&&(e=s)}catch{}})(),o=s=>{var a;return(a=t.get(s))!=null?a:null},i=(s,a)=>{t.set(s,a),le.setItem(s,a).catch(()=>{})},d=()=>{var s;return e||(e=(s=o(B))!=null?s:void 0,e||(e=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,i(B,e))),e};return{ready:r,request:U,getStorage:s=>o(s),setStorage:(s,a)=>i(s,a),getDeviceInfo(){return{deviceId:d(),platform:A.OS==="ios"?"ios":A.OS==="android"?"android":A.OS,osName:A.OS,os:String(A.Version),osVersion:String(A.Version)}},getCurrentPage:()=>{var s,a;return(a=(s=n.getPage)==null?void 0:s.call(n))!=null?a:null},getPlatformVersion:()=>null,onError(s){let a=globalThis.ErrorUtils;if(typeof(a==null?void 0:a.setGlobalHandler)!="function")return;let l=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((c,u)=>{s(c),typeof l=="function"&&l(c,u)})},onUnhandledRejection(s){}}}function at(n){if(!(n!=null&&n.serverUrl)||!(n!=null&&n.appKey))throw new Error("[uni-log] initRN \u7F3A\u5C11 serverUrl \u6216 appKey");let{getPage:t,...e}=n;return ce({...e,adapter:Ce({getPage:t})})}export{Ce as createReactNativeAdapter,at as initRN};
@@ -91,6 +91,11 @@ interface ReportHeader {
91
91
  sessionId: string;
92
92
  /** 业务侧用户标识(可选) */
93
93
  userId?: string;
94
+ /**
95
+ * 业务租户/商户标识(可选):一个应用服务多个业务租户时用于数据归属与报表筛选。
96
+ * 与看板内部的 Tenant/Team 无关,不参与权限判定。
97
+ */
98
+ bizTenantId?: string;
94
99
  /** 网络类型 wifi/4g/... */
95
100
  net?: string;
96
101
  /** SDK 版本,对应官方 sdk_version / 基础库版本号 */
@@ -169,6 +174,16 @@ interface PlatformAdapter {
169
174
  getPlatformVersion(): string | null;
170
175
  onError(cb: (err: unknown) => void): void;
171
176
  onUnhandledRejection(cb: (err: unknown) => void): void;
177
+ /**
178
+ * 可选:SPA 路由变化通知(web 适配器实现)。
179
+ * 客户端收到后自动累计 page_count,无需宿主手写 pageView。
180
+ */
181
+ onPageChange?(cb: (page: string | null) => void): void;
182
+ /**
183
+ * 可选:页面隐藏通知(web `visibilitychange`)。
184
+ * 客户端收到后立即 flush,降低页面关闭前丢最后一批日志的概率。
185
+ */
186
+ onHidden?(cb: () => void): void;
172
187
  }
173
188
 
174
189
  interface UniLogOptions {
@@ -191,6 +206,10 @@ interface UniLogOptions {
191
206
  getDeviceName?: () => string | undefined;
192
207
  getUserId?: () => string | undefined;
193
208
  getNet?: () => string | undefined;
209
+ /** 业务租户/商户标识;与 getBizTenantId 同时传时以 getBizTenantId 为准 */
210
+ bizTenantId?: string;
211
+ /** 动态业务租户标识(登录后可变),优先级高于 bizTenantId */
212
+ getBizTenantId?: () => string | undefined;
194
213
  /** 定时上报间隔毫秒,默认 10000(对标 uni-stat reportInterval) */
195
214
  flushInterval?: number;
196
215
  /** 自动捕获 uni.onError / onUnhandledRejection,默认 true */
@@ -231,6 +250,8 @@ declare class UniLogClient {
231
250
  private userEnabled;
232
251
  /** 错误钩子只能挂一次:stop() 后再 start() 不能重复注册,否则同一条错误会重复上报 */
233
252
  private hooksInstalled;
253
+ /** SPA 路由/页面隐藏监听只挂一次,setEnabled 反复开关不重复注册 */
254
+ private lifecycleInstalled;
234
255
  constructor(options: UniLogOptions, adapter?: PlatformAdapter);
235
256
  /** 启动定时器、续传失败暂存、按需挂错误钩子 */
236
257
  start(): void;
@@ -91,6 +91,11 @@ interface ReportHeader {
91
91
  sessionId: string;
92
92
  /** 业务侧用户标识(可选) */
93
93
  userId?: string;
94
+ /**
95
+ * 业务租户/商户标识(可选):一个应用服务多个业务租户时用于数据归属与报表筛选。
96
+ * 与看板内部的 Tenant/Team 无关,不参与权限判定。
97
+ */
98
+ bizTenantId?: string;
94
99
  /** 网络类型 wifi/4g/... */
95
100
  net?: string;
96
101
  /** SDK 版本,对应官方 sdk_version / 基础库版本号 */
@@ -169,6 +174,16 @@ interface PlatformAdapter {
169
174
  getPlatformVersion(): string | null;
170
175
  onError(cb: (err: unknown) => void): void;
171
176
  onUnhandledRejection(cb: (err: unknown) => void): void;
177
+ /**
178
+ * 可选:SPA 路由变化通知(web 适配器实现)。
179
+ * 客户端收到后自动累计 page_count,无需宿主手写 pageView。
180
+ */
181
+ onPageChange?(cb: (page: string | null) => void): void;
182
+ /**
183
+ * 可选:页面隐藏通知(web `visibilitychange`)。
184
+ * 客户端收到后立即 flush,降低页面关闭前丢最后一批日志的概率。
185
+ */
186
+ onHidden?(cb: () => void): void;
172
187
  }
173
188
 
174
189
  interface UniLogOptions {
@@ -191,6 +206,10 @@ interface UniLogOptions {
191
206
  getDeviceName?: () => string | undefined;
192
207
  getUserId?: () => string | undefined;
193
208
  getNet?: () => string | undefined;
209
+ /** 业务租户/商户标识;与 getBizTenantId 同时传时以 getBizTenantId 为准 */
210
+ bizTenantId?: string;
211
+ /** 动态业务租户标识(登录后可变),优先级高于 bizTenantId */
212
+ getBizTenantId?: () => string | undefined;
194
213
  /** 定时上报间隔毫秒,默认 10000(对标 uni-stat reportInterval) */
195
214
  flushInterval?: number;
196
215
  /** 自动捕获 uni.onError / onUnhandledRejection,默认 true */
@@ -231,6 +250,8 @@ declare class UniLogClient {
231
250
  private userEnabled;
232
251
  /** 错误钩子只能挂一次:stop() 后再 start() 不能重复注册,否则同一条错误会重复上报 */
233
252
  private hooksInstalled;
253
+ /** SPA 路由/页面隐藏监听只挂一次,setEnabled 反复开关不重复注册 */
254
+ private lifecycleInstalled;
234
255
  constructor(options: UniLogOptions, adapter?: PlatformAdapter);
235
256
  /** 启动定时器、续传失败暂存、按需挂错误钩子 */
236
257
  start(): void;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PlatformAdapter, a as UniLogClient, U as UniLogOptions, L as LogLevel } from './client-ipC9gS50.mjs';
2
- export { E as EventEntry, b as LogEntry, R as ReportPayload } from './client-ipC9gS50.mjs';
1
+ import { P as PlatformAdapter, a as UniLogClient, U as UniLogOptions, L as LogLevel } from './client-D63QZD4X.mjs';
2
+ export { E as EventEntry, b as LogEntry, R as ReportPayload } from './client-D63QZD4X.mjs';
3
3
 
4
4
  declare function createBrowserAdapter(): PlatformAdapter;
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { P as PlatformAdapter, a as UniLogClient, U as UniLogOptions, L as LogLevel } from './client-ipC9gS50.js';
2
- export { E as EventEntry, b as LogEntry, R as ReportPayload } from './client-ipC9gS50.js';
1
+ import { P as PlatformAdapter, a as UniLogClient, U as UniLogOptions, L as LogLevel } from './client-D63QZD4X.js';
2
+ export { E as EventEntry, b as LogEntry, R as ReportPayload } from './client-D63QZD4X.js';
3
3
 
4
4
  declare function createBrowserAdapter(): PlatformAdapter;
5
5
 
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var oe=Object.create;var U=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ae=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var q=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),ce=(n,t)=>{for(var e in t)U(n,e,{get:t[e],enumerable:!0})},G=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of se(t))!de.call(n,o)&&o!==e&&U(n,o,{get:()=>t[o],enumerable:!(r=ie(t,o))||r.enumerable});return n};var le=(n,t,e)=>(e=n!=null?oe(ae(n)):{},G(t||!n||!n.__esModule?U(e,"default",{value:n,enumerable:!0}):e,n)),ge=n=>G(U({},"__esModule",{value:!0}),n);var X=q(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var Y=q(P=>{"use strict";var me=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),xe=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&me(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});xe(X(),P)});var Oe={};ce(Oe,{createBrowserAdapter:()=>_,detectAdapter:()=>O,flush:()=>_e,getClient:()=>Pe,hookConsole:()=>ne,init:()=>Se,isEnabled:()=>Ie,report:()=>Le,setConsoleReport:()=>Re,setDeviceName:()=>Ne,setEnabled:()=>Ee,ulog:()=>ke,ulogger:()=>ee});module.exports=ge(Oe);function S(){let n=globalThis.uni;return n!=null?n:null}function ue(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function fe(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function V(n){return typeof n=="string"&&n.length>0?n:void 0}function he(n){let t=c=>{var h;try{return(h=c==null?void 0:c())!=null?h:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let a=(...c)=>c.map(V).find(Boolean),d=(...c)=>c.map(fe).find(h=>h!==void 0),f=a(r.deviceId,e.deviceId,e.deviceUUID),g=a(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!f||!g?null:{deviceId:f,platform:g,deviceName:a(r.deviceName,e.deviceName),model:a(r.deviceModel,e.deviceModel,e.model),vendor:a(r.deviceBrand,e.deviceBrand,e.brand),os:a(e.osVersion,e.system,r.osVersion,r.system),osVersion:a(e.osVersion,r.osVersion),osName:a(e.osName,r.osName,o.osName),net:a(e.networkType,e.netType),language:a(o.language,e.language),pixelRatio:d(i.pixelRatio,e.pixelRatio),windowWidth:d(i.windowWidth,e.windowWidth),windowHeight:d(i.windowHeight,e.windowHeight),screenWidth:d(i.screenWidth,e.screenWidth),screenHeight:d(i.screenHeight,e.screenHeight)}}function N(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return he(S())}catch{return null}},getCurrentPage(){var n;try{let t=ue(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let a=r();return a&&(i=(o=V(a.hostVersion))!=null?o:V(a.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}function W(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}var K="uni-log:web-did",M;function $(n){try{return window.localStorage.getItem(n)}catch{return null}}function J(n,t){try{window.localStorage.setItem(n,t)}catch{}}function pe(){var e;let n=(e=$(K))!=null?e:M;if(n)return M=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return M=t,J(K,t),t}function _(){return{request:W,getStorage:n=>$(n),setStorage:(n,t)=>J(n,t),getDeviceInfo(){return{deviceId:pe(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>typeof location!="undefined"?location.pathname:null,getPlatformVersion:()=>null,onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function O(){let n=globalThis;return typeof n!="undefined"&&n.uni?N():_()}var u=le(Y());var ye=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function y(n,t){return n>>>t|n<<32-t}function F(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function B(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),a=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(a>>>24&255,a>>>16&255,a>>>8&255,a&255);let d=new Array(64);for(let g=0;g<r.length;g+=64){for(let l=0;l<16;l++){let x=g+l*4;d[l]=(r[x]<<24|r[x+1]<<16|r[x+2]<<8|r[x+3])>>>0}for(let l=16;l<64;l++){let x=y(d[l-15],7)^y(d[l-15],18)^d[l-15]>>>3,R=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+R>>>0}let[c,h,b,I,m,v,w,k]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),R=m&v^~m&w,L=k+x+R+ye[l]+d[l]>>>0,C=y(c,2)^y(c,13)^y(c,22),D=c&h^c&b^h&b,re=C+D>>>0;k=w,w=v,v=m,m=I+L>>>0,I=b,b=h,h=c,c=L+re>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+h>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+I>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let f=[];for(let g of t)f.push(g>>>24&255,g>>>16&255,g>>>8&255,g&255);return f}function be(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function z(n,t){let e=F(n);for(e.length>64&&(e=B(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return be(B(o.concat(B(r.concat(F(t))))))}function H(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var E="uni-log:pending",Q=20,ve="0.2.3";function A(n,t){return n.length>t?n.slice(0,t):n}function j(n){let t=n==null?void 0:n.trim();return t?A(t,128):void 0}function we(n,t,e){var o;let r={t:Date.now(),lv:n,msg:A(t||"(empty)",u.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=A(e.stack,u.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=A(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var T=class{constructor(t,e=N()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(E,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=u.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(we(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=u.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>u.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=A(e,u.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=u.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?A(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var a,d,f,g,c,h,b,I,m,v,w,k,l,x,R,L,C,D;let e=(a=this.deviceInfo)!=null?a:this.deviceInfo=this.adapter.getDeviceInfo(),r=(h=(c=(g=this.deviceNameOverride)!=null?g:j((f=(d=this.options).getDeviceName)==null?void 0:f.call(d)))!=null?c:j(this.options.deviceName))!=null?h:j(e==null?void 0:e.deviceName),o={deviceId:(b=e==null?void 0:e.deviceId)!=null?b:this.fallbackDeviceId(),platform:(I=e==null?void 0:e.platform)!=null?I:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((w=e==null?void 0:e.net)!=null?w:(v=(m=this.options).getNet)!=null&&v.call(m))?{net:(x=e==null?void 0:e.net)!=null?x:(l=(k=this.options).getNet)==null?void 0:l.call(k)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}};return{header:{appKey:this.options.appKey,batchId:H(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(L=(R=this.options).getUserId)!=null&&L.call(R)?{userId:this.options.getUserId()}:{},...(D=(C=this.options).getNet)!=null&&D.call(C)?{net:this.options.getNet()}:{},sdkVer:ve,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,u.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,u.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var d;let r=!1,o,i=f=>{r||(r=!0,clearTimeout(a),e(f))},a=setTimeout(()=>{var f;try{(f=o==null?void 0:o.abort)==null||f.call(o)}catch{}i(!1)},8e3);try{let f=JSON.stringify(t),g={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),h=H(16);g[u.SIGNATURE_HEADERS.ts]=c,g[u.SIGNATURE_HEADERS.nonce]=h,g[u.SIGNATURE_HEADERS.sign]=z(this.options.appSecret,`${c}
1
+ "use strict";var ue=Object.create;var U=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var J=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),me=(n,t)=>{for(var e in t)U(n,e,{get:t[e],enumerable:!0})},z=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of fe(t))!pe.call(n,o)&&o!==e&&U(n,o,{get:()=>t[o],enumerable:!(r=ge(t,o))||r.enumerable});return n};var ye=(n,t,e)=>(e=n!=null?ue(he(n)):{},z(t||!n||!n.__esModule?U(e,"default",{value:n,enumerable:!0}):e,n)),xe=n=>z(U({},"__esModule",{value:!0}),n);var ne=J(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var re=J(P=>{"use strict";var Ie=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),Ee=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&Ie(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});Ee(ne(),P)});var Me={};me(Me,{createBrowserAdapter:()=>_,detectAdapter:()=>O,flush:()=>He,getClient:()=>_e,hookConsole:()=>le,init:()=>Ne,isEnabled:()=>Ce,report:()=>Ve,setConsoleReport:()=>Te,setDeviceName:()=>Be,setEnabled:()=>Oe,ulog:()=>De,ulogger:()=>de});module.exports=xe(Me);function S(){let n=globalThis.uni;return n!=null?n:null}function be(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function ve(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function H(n){return typeof n=="string"&&n.length>0?n:void 0}function we(n){let t=c=>{var h;try{return(h=c==null?void 0:c())!=null?h:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let a=(...c)=>c.map(H).find(Boolean),d=(...c)=>c.map(ve).find(h=>h!==void 0),u=a(r.deviceId,e.deviceId,e.deviceUUID),g=a(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!u||!g?null:{deviceId:u,platform:g,deviceName:a(r.deviceName,e.deviceName),model:a(r.deviceModel,e.deviceModel,e.model),vendor:a(r.deviceBrand,e.deviceBrand,e.brand),os:a(e.osVersion,e.system,r.osVersion,r.system),osVersion:a(e.osVersion,r.osVersion),osName:a(e.osName,r.osName,o.osName),net:a(e.networkType,e.netType),language:a(o.language,e.language),pixelRatio:d(i.pixelRatio,e.pixelRatio),windowWidth:d(i.windowWidth,e.windowWidth),windowHeight:d(i.windowHeight,e.windowHeight),screenWidth:d(i.screenWidth,e.screenWidth),screenHeight:d(i.screenHeight,e.screenHeight)}}function N(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return we(S())}catch{return null}},getCurrentPage(){var n;try{let t=be(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let a=r();return a&&(i=(o=H(a.hostVersion))!=null?o:H(a.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}function X(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}var Y="uni-log:web-did",M,Q=new Set,F=!1;function Z(){if(typeof location=="undefined")return null;let n=location.pathname||"/",t=location.hash||"";return/^#!?\//.test(t)?t.replace(/^#!?/,"").split("?")[0]||"/":n||"/"}function j(){let n=Z();for(let t of Q)try{t(n)}catch{}}function Se(){if(F||typeof window=="undefined")return;F=!0,window.addEventListener("popstate",j),window.addEventListener("hashchange",j);let n=window.history;for(let t of["pushState","replaceState"]){let e=n[t];typeof e=="function"&&(n[t]=function(...r){let o=e.apply(this,r);return j(),o})}}function ee(n){try{return window.localStorage.getItem(n)}catch{return null}}function te(n,t){try{window.localStorage.setItem(n,t)}catch{}}function Pe(){var e;let n=(e=ee(Y))!=null?e:M;if(n)return M=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return M=t,te(Y,t),t}function _(){return{request:X,getStorage:n=>ee(n),setStorage:(n,t)=>te(n,t),getDeviceInfo(){return{deviceId:Pe(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>Z(),getPlatformVersion:()=>null,onPageChange(n){Q.add(n),Se()},onHidden(n){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&n()})},onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function O(){let n=globalThis;return typeof n!="undefined"&&n.uni?N():_()}var f=ye(re());var ke=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function x(n,t){return n>>>t|n<<32-t}function oe(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function q(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),a=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(a>>>24&255,a>>>16&255,a>>>8&255,a&255);let d=new Array(64);for(let g=0;g<r.length;g+=64){for(let l=0;l<16;l++){let y=g+l*4;d[l]=(r[y]<<24|r[y+1]<<16|r[y+2]<<8|r[y+3])>>>0}for(let l=16;l<64;l++){let y=x(d[l-15],7)^x(d[l-15],18)^d[l-15]>>>3,R=x(d[l-2],17)^x(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+y+d[l-7]+R>>>0}let[c,h,b,E,m,v,w,k]=t;for(let l=0;l<64;l++){let y=x(m,6)^x(m,11)^x(m,25),R=m&v^~m&w,A=k+y+R+ke[l]+d[l]>>>0,C=x(c,2)^x(c,13)^x(c,22),D=c&h^c&b^h&b,T=C+D>>>0;k=w,w=v,v=m,m=E+A>>>0,E=b,b=h,h=c,c=A+T>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+h>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+E>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let u=[];for(let g of t)u.push(g>>>24&255,g>>>16&255,g>>>8&255,g&255);return u}function Re(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function ie(n,t){let e=oe(n);for(e.length>64&&(e=q(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return Re(q(o.concat(q(r.concat(oe(t))))))}function G(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var I="uni-log:pending",se=20,Le="0.3.0";function L(n,t){return n.length>t?n.slice(0,t):n}function V(n){let t=n==null?void 0:n.trim();return t?L(t,128):void 0}function Ae(n,t,e){var o;let r={t:Date.now(),lv:n,msg:L(t||"(empty)",f.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=L(e.stack,f.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=L(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var B=class{constructor(t,e=N()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.lifecycleInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r,o,i,a,d;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.lifecycleInstalled||((i=(o=this.adapter).onPageChange)==null||i.call(o,u=>{!this.ready||!u||u===this.lastPage||(this.lastPage=u,this.pageCount+=1)}),(d=(a=this.adapter).onHidden)==null||d.call(a,()=>{this.flush().catch(()=>{})}),this.lifecycleInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(I,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=f.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(Ae(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=f.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>f.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=L(e,f.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=f.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?L(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var d,u,g,c,h,b,E,m,v,w,k,l,y,R,A,C,D,T,W,K,$;let e=(d=this.deviceInfo)!=null?d:this.deviceInfo=this.adapter.getDeviceInfo(),r=(b=(h=(c=this.deviceNameOverride)!=null?c:V((g=(u=this.options).getDeviceName)==null?void 0:g.call(u)))!=null?h:V(this.options.deviceName))!=null?b:V(e==null?void 0:e.deviceName),o={deviceId:(E=e==null?void 0:e.deviceId)!=null?E:this.fallbackDeviceId(),platform:(m=e==null?void 0:e.platform)!=null?m:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((k=e==null?void 0:e.net)!=null?k:(w=(v=this.options).getNet)!=null&&w.call(v))?{net:(R=e==null?void 0:e.net)!=null?R:(y=(l=this.options).getNet)==null?void 0:y.call(l)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}},i=V((D=(C=(A=this.options).getBizTenantId)==null?void 0:C.call(A))!=null?D:this.options.bizTenantId);return{header:{appKey:this.options.appKey,batchId:G(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(W=(T=this.options).getUserId)!=null&&W.call(T)?{userId:this.options.getUserId()}:{},...i?{bizTenantId:i}:{},...($=(K=this.options).getNet)!=null&&$.call(K)?{net:this.options.getNet()}:{},sdkVer:Le,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,f.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,f.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var d;let r=!1,o,i=u=>{r||(r=!0,clearTimeout(a),e(u))},a=setTimeout(()=>{var u;try{(u=o==null?void 0:o.abort)==null||u.call(o)}catch{}i(!1)},8e3);try{let u=JSON.stringify(t),g={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),h=G(16);g[f.SIGNATURE_HEADERS.ts]=c,g[f.SIGNATURE_HEADERS.nonce]=h,g[f.SIGNATURE_HEADERS.sign]=ie(this.options.appSecret,`${c}
2
2
  ${h}
3
- ${f}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${u.INGEST_PATH}`,data:f,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(E),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>Q&&(r=r.slice(-Q));try{this.adapter.setStorage(E,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(E);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(E,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(E,"");return}this.adapter.setStorage(E,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function Se(n){var t;return s==null||s.stop(),s=new T(n,(t=n.adapter)!=null?t:O()),s.start(),n.hookConsole!==!1&&ne(),s}function Pe(){return s}function Ee(n){s==null||s.setEnabled(n)}function Ie(){var n;return(n=s==null?void 0:s.isEnabled())!=null?n:!1}function ke(n,t,e){s==null||s.log(n,t,e)}var ee={debug:(n,t)=>s==null?void 0:s.log("debug",n,t),info:(n,t)=>s==null?void 0:s.log("info",n,t),warn:(n,t)=>s==null?void 0:s.log("warn",n,t),error:(n,t)=>s==null?void 0:s.log("error",n,t)},Z=new Set,te=!0;function Re(n){te=n}function ne(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(Z.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...a)=>{te&&ee[r](a.map(Ae).join(" ")),i(...a)},Z.add(e)}}function Ae(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}function Le(n,t){s==null||s.report(n,t)}function Ne(n){s==null||s.setDeviceName(n)}async function _e(){await(s==null?void 0:s.flush())}0&&(module.exports={createBrowserAdapter,detectAdapter,flush,getClient,hookConsole,init,isEnabled,report,setConsoleReport,setDeviceName,setEnabled,ulog,ulogger});
3
+ ${u}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${f.INGEST_PATH}`,data:u,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(I),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>se&&(r=r.slice(-se));try{this.adapter.setStorage(I,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(I);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(I,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(I,"");return}this.adapter.setStorage(I,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function Ne(n){var t;return s==null||s.stop(),s=new B(n,(t=n.adapter)!=null?t:O()),s.start(),n.hookConsole!==!1&&le(),s}function _e(){return s}function Oe(n){s==null||s.setEnabled(n)}function Ce(){var n;return(n=s==null?void 0:s.isEnabled())!=null?n:!1}function De(n,t,e){s==null||s.log(n,t,e)}var de={debug:(n,t)=>s==null?void 0:s.log("debug",n,t),info:(n,t)=>s==null?void 0:s.log("info",n,t),warn:(n,t)=>s==null?void 0:s.log("warn",n,t),error:(n,t)=>s==null?void 0:s.log("error",n,t)},ae=new Set,ce=!0;function Te(n){ce=n}function le(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(ae.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...a)=>{ce&&de[r](a.map(Ue).join(" ")),i(...a)},ae.add(e)}}function Ue(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}function Ve(n,t){s==null||s.report(n,t)}function Be(n){s==null||s.setDeviceName(n)}async function He(){await(s==null?void 0:s.flush())}0&&(module.exports={createBrowserAdapter,detectAdapter,flush,getClient,hookConsole,init,isEnabled,report,setConsoleReport,setDeviceName,setEnabled,ulog,ulogger});
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- var te=Object.create;var j=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var q=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var se=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of re(t))!ie.call(n,o)&&o!==e&&j(n,o,{get:()=>t[o],enumerable:!(r=ne(t,o))||r.enumerable});return n};var ae=(n,t,e)=>(e=n!=null?te(oe(n)):{},se(t||!n||!n.__esModule?j(e,"default",{value:n,enumerable:!0}):e,n));var J=q(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var X=q(P=>{"use strict";var ue=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),fe=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&ue(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});fe(J(),P)});function S(){let n=globalThis.uni;return n!=null?n:null}function de(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function ce(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function T(n){return typeof n=="string"&&n.length>0?n:void 0}function le(n){let t=c=>{var h;try{return(h=c==null?void 0:c())!=null?h:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let a=(...c)=>c.map(T).find(Boolean),d=(...c)=>c.map(ce).find(h=>h!==void 0),f=a(r.deviceId,e.deviceId,e.deviceUUID),g=a(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!f||!g?null:{deviceId:f,platform:g,deviceName:a(r.deviceName,e.deviceName),model:a(r.deviceModel,e.deviceModel,e.model),vendor:a(r.deviceBrand,e.deviceBrand,e.brand),os:a(e.osVersion,e.system,r.osVersion,r.system),osVersion:a(e.osVersion,r.osVersion),osName:a(e.osName,r.osName,o.osName),net:a(e.networkType,e.netType),language:a(o.language,e.language),pixelRatio:d(i.pixelRatio,e.pixelRatio),windowWidth:d(i.windowWidth,e.windowWidth),windowHeight:d(i.windowHeight,e.windowHeight),screenWidth:d(i.screenWidth,e.screenWidth),screenHeight:d(i.screenHeight,e.screenHeight)}}function N(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return le(S())}catch{return null}},getCurrentPage(){var n;try{let t=de(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let a=r();return a&&(i=(o=T(a.hostVersion))!=null?o:T(a.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}function G(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}var W="uni-log:web-did",V;function K(n){try{return window.localStorage.getItem(n)}catch{return null}}function $(n,t){try{window.localStorage.setItem(n,t)}catch{}}function ge(){var e;let n=(e=K(W))!=null?e:V;if(n)return V=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return V=t,$(W,t),t}function C(){return{request:G,getStorage:n=>K(n),setStorage:(n,t)=>$(n,t),getDeviceInfo(){return{deviceId:ge(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>typeof location!="undefined"?location.pathname:null,getPlatformVersion:()=>null,onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function D(){let n=globalThis;return typeof n!="undefined"&&n.uni?N():C()}var u=ae(X());var he=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function y(n,t){return n>>>t|n<<32-t}function Y(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function M(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),a=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(a>>>24&255,a>>>16&255,a>>>8&255,a&255);let d=new Array(64);for(let g=0;g<r.length;g+=64){for(let l=0;l<16;l++){let x=g+l*4;d[l]=(r[x]<<24|r[x+1]<<16|r[x+2]<<8|r[x+3])>>>0}for(let l=16;l<64;l++){let x=y(d[l-15],7)^y(d[l-15],18)^d[l-15]>>>3,R=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+R>>>0}let[c,h,b,I,m,v,w,k]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),R=m&v^~m&w,L=k+x+R+he[l]+d[l]>>>0,_=y(c,2)^y(c,13)^y(c,22),O=c&h^c&b^h&b,ee=_+O>>>0;k=w,w=v,v=m,m=I+L>>>0,I=b,b=h,h=c,c=L+ee>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+h>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+I>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let f=[];for(let g of t)f.push(g>>>24&255,g>>>16&255,g>>>8&255,g&255);return f}function pe(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function F(n,t){let e=Y(n);for(e.length>64&&(e=M(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return pe(M(o.concat(M(r.concat(Y(t))))))}function B(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var E="uni-log:pending",z=20,me="0.2.3";function A(n,t){return n.length>t?n.slice(0,t):n}function H(n){let t=n==null?void 0:n.trim();return t?A(t,128):void 0}function xe(n,t,e){var o;let r={t:Date.now(),lv:n,msg:A(t||"(empty)",u.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=A(e.stack,u.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=A(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var U=class{constructor(t,e=N()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(E,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=u.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(xe(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=u.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>u.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=A(e,u.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=u.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?A(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var a,d,f,g,c,h,b,I,m,v,w,k,l,x,R,L,_,O;let e=(a=this.deviceInfo)!=null?a:this.deviceInfo=this.adapter.getDeviceInfo(),r=(h=(c=(g=this.deviceNameOverride)!=null?g:H((f=(d=this.options).getDeviceName)==null?void 0:f.call(d)))!=null?c:H(this.options.deviceName))!=null?h:H(e==null?void 0:e.deviceName),o={deviceId:(b=e==null?void 0:e.deviceId)!=null?b:this.fallbackDeviceId(),platform:(I=e==null?void 0:e.platform)!=null?I:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((w=e==null?void 0:e.net)!=null?w:(v=(m=this.options).getNet)!=null&&v.call(m))?{net:(x=e==null?void 0:e.net)!=null?x:(l=(k=this.options).getNet)==null?void 0:l.call(k)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}};return{header:{appKey:this.options.appKey,batchId:B(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(L=(R=this.options).getUserId)!=null&&L.call(R)?{userId:this.options.getUserId()}:{},...(O=(_=this.options).getNet)!=null&&O.call(_)?{net:this.options.getNet()}:{},sdkVer:me,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,u.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,u.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var d;let r=!1,o,i=f=>{r||(r=!0,clearTimeout(a),e(f))},a=setTimeout(()=>{var f;try{(f=o==null?void 0:o.abort)==null||f.call(o)}catch{}i(!1)},8e3);try{let f=JSON.stringify(t),g={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),h=B(16);g[u.SIGNATURE_HEADERS.ts]=c,g[u.SIGNATURE_HEADERS.nonce]=h,g[u.SIGNATURE_HEADERS.sign]=F(this.options.appSecret,`${c}
1
+ var de=Object.create;var $=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var J=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var fe=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of le(t))!ge.call(n,o)&&o!==e&&$(n,o,{get:()=>t[o],enumerable:!(r=ce(t,o))||r.enumerable});return n};var he=(n,t,e)=>(e=n!=null?de(ue(n)):{},fe(t||!n||!n.__esModule?$(e,"default",{value:n,enumerable:!0}):e,n));var te=J(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var ne=J(P=>{"use strict";var ve=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),we=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&ve(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});we(te(),P)});function S(){let n=globalThis.uni;return n!=null?n:null}function pe(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function me(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function B(n){return typeof n=="string"&&n.length>0?n:void 0}function ye(n){let t=c=>{var h;try{return(h=c==null?void 0:c())!=null?h:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let a=(...c)=>c.map(B).find(Boolean),d=(...c)=>c.map(me).find(h=>h!==void 0),u=a(r.deviceId,e.deviceId,e.deviceUUID),g=a(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!u||!g?null:{deviceId:u,platform:g,deviceName:a(r.deviceName,e.deviceName),model:a(r.deviceModel,e.deviceModel,e.model),vendor:a(r.deviceBrand,e.deviceBrand,e.brand),os:a(e.osVersion,e.system,r.osVersion,r.system),osVersion:a(e.osVersion,r.osVersion),osName:a(e.osName,r.osName,o.osName),net:a(e.networkType,e.netType),language:a(o.language,e.language),pixelRatio:d(i.pixelRatio,e.pixelRatio),windowWidth:d(i.windowWidth,e.windowWidth),windowHeight:d(i.windowHeight,e.windowHeight),screenWidth:d(i.screenWidth,e.screenWidth),screenHeight:d(i.screenHeight,e.screenHeight)}}function N(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return ye(S())}catch{return null}},getCurrentPage(){var n;try{let t=pe(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let a=r();return a&&(i=(o=B(a.hostVersion))!=null?o:B(a.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}function z(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}var X="uni-log:web-did",H,F=new Set,Y=!1;function Q(){if(typeof location=="undefined")return null;let n=location.pathname||"/",t=location.hash||"";return/^#!?\//.test(t)?t.replace(/^#!?/,"").split("?")[0]||"/":n||"/"}function M(){let n=Q();for(let t of F)try{t(n)}catch{}}function xe(){if(Y||typeof window=="undefined")return;Y=!0,window.addEventListener("popstate",M),window.addEventListener("hashchange",M);let n=window.history;for(let t of["pushState","replaceState"]){let e=n[t];typeof e=="function"&&(n[t]=function(...r){let o=e.apply(this,r);return M(),o})}}function Z(n){try{return window.localStorage.getItem(n)}catch{return null}}function ee(n,t){try{window.localStorage.setItem(n,t)}catch{}}function be(){var e;let n=(e=Z(X))!=null?e:H;if(n)return H=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return H=t,ee(X,t),t}function D(){return{request:z,getStorage:n=>Z(n),setStorage:(n,t)=>ee(n,t),getDeviceInfo(){return{deviceId:be(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>Q(),getPlatformVersion:()=>null,onPageChange(n){F.add(n),xe()},onHidden(n){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&n()})},onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function T(){let n=globalThis;return typeof n!="undefined"&&n.uni?N():D()}var f=he(ne());var Se=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function x(n,t){return n>>>t|n<<32-t}function re(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function j(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),a=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(a>>>24&255,a>>>16&255,a>>>8&255,a&255);let d=new Array(64);for(let g=0;g<r.length;g+=64){for(let l=0;l<16;l++){let y=g+l*4;d[l]=(r[y]<<24|r[y+1]<<16|r[y+2]<<8|r[y+3])>>>0}for(let l=16;l<64;l++){let y=x(d[l-15],7)^x(d[l-15],18)^d[l-15]>>>3,R=x(d[l-2],17)^x(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+y+d[l-7]+R>>>0}let[c,h,b,E,m,v,w,k]=t;for(let l=0;l<64;l++){let y=x(m,6)^x(m,11)^x(m,25),R=m&v^~m&w,A=k+y+R+Se[l]+d[l]>>>0,_=x(c,2)^x(c,13)^x(c,22),O=c&h^c&b^h&b,C=_+O>>>0;k=w,w=v,v=m,m=E+A>>>0,E=b,b=h,h=c,c=A+C>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+h>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+E>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let u=[];for(let g of t)u.push(g>>>24&255,g>>>16&255,g>>>8&255,g&255);return u}function Pe(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function oe(n,t){let e=re(n);for(e.length>64&&(e=j(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return Pe(j(o.concat(j(r.concat(re(t))))))}function q(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var I="uni-log:pending",ie=20,Ie="0.3.0";function L(n,t){return n.length>t?n.slice(0,t):n}function U(n){let t=n==null?void 0:n.trim();return t?L(t,128):void 0}function Ee(n,t,e){var o;let r={t:Date.now(),lv:n,msg:L(t||"(empty)",f.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=L(e.stack,f.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=L(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var V=class{constructor(t,e=N()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.lifecycleInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r,o,i,a,d;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.lifecycleInstalled||((i=(o=this.adapter).onPageChange)==null||i.call(o,u=>{!this.ready||!u||u===this.lastPage||(this.lastPage=u,this.pageCount+=1)}),(d=(a=this.adapter).onHidden)==null||d.call(a,()=>{this.flush().catch(()=>{})}),this.lifecycleInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(I,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=f.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(Ee(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=f.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>f.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=L(e,f.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=f.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?L(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var d,u,g,c,h,b,E,m,v,w,k,l,y,R,A,_,O,C,G,W,K;let e=(d=this.deviceInfo)!=null?d:this.deviceInfo=this.adapter.getDeviceInfo(),r=(b=(h=(c=this.deviceNameOverride)!=null?c:U((g=(u=this.options).getDeviceName)==null?void 0:g.call(u)))!=null?h:U(this.options.deviceName))!=null?b:U(e==null?void 0:e.deviceName),o={deviceId:(E=e==null?void 0:e.deviceId)!=null?E:this.fallbackDeviceId(),platform:(m=e==null?void 0:e.platform)!=null?m:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((k=e==null?void 0:e.net)!=null?k:(w=(v=this.options).getNet)!=null&&w.call(v))?{net:(R=e==null?void 0:e.net)!=null?R:(y=(l=this.options).getNet)==null?void 0:y.call(l)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}},i=U((O=(_=(A=this.options).getBizTenantId)==null?void 0:_.call(A))!=null?O:this.options.bizTenantId);return{header:{appKey:this.options.appKey,batchId:q(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(G=(C=this.options).getUserId)!=null&&G.call(C)?{userId:this.options.getUserId()}:{},...i?{bizTenantId:i}:{},...(K=(W=this.options).getNet)!=null&&K.call(W)?{net:this.options.getNet()}:{},sdkVer:Ie,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,f.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,f.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var d;let r=!1,o,i=u=>{r||(r=!0,clearTimeout(a),e(u))},a=setTimeout(()=>{var u;try{(u=o==null?void 0:o.abort)==null||u.call(o)}catch{}i(!1)},8e3);try{let u=JSON.stringify(t),g={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),h=q(16);g[f.SIGNATURE_HEADERS.ts]=c,g[f.SIGNATURE_HEADERS.nonce]=h,g[f.SIGNATURE_HEADERS.sign]=oe(this.options.appSecret,`${c}
2
2
  ${h}
3
- ${f}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${u.INGEST_PATH}`,data:f,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(E),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>z&&(r=r.slice(-z));try{this.adapter.setStorage(E,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(E);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(E,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(E,"");return}this.adapter.setStorage(E,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function je(n){var t;return s==null||s.stop(),s=new U(n,(t=n.adapter)!=null?t:D()),s.start(),n.hookConsole!==!1&&be(),s}function qe(){return s}function Ge(n){s==null||s.setEnabled(n)}function We(){var n;return(n=s==null?void 0:s.isEnabled())!=null?n:!1}function Ke(n,t,e){s==null||s.log(n,t,e)}var ye={debug:(n,t)=>s==null?void 0:s.log("debug",n,t),info:(n,t)=>s==null?void 0:s.log("info",n,t),warn:(n,t)=>s==null?void 0:s.log("warn",n,t),error:(n,t)=>s==null?void 0:s.log("error",n,t)},Q=new Set,Z=!0;function $e(n){Z=n}function be(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(Q.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...a)=>{Z&&ye[r](a.map(ve).join(" ")),i(...a)},Q.add(e)}}function ve(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}function Je(n,t){s==null||s.report(n,t)}function Xe(n){s==null||s.setDeviceName(n)}async function Ye(){await(s==null?void 0:s.flush())}export{C as createBrowserAdapter,D as detectAdapter,Ye as flush,qe as getClient,be as hookConsole,je as init,We as isEnabled,Je as report,$e as setConsoleReport,Xe as setDeviceName,Ge as setEnabled,Ke as ulog,ye as ulogger};
3
+ ${u}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${f.INGEST_PATH}`,data:u,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(I),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>ie&&(r=r.slice(-ie));try{this.adapter.setStorage(I,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(I);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(I,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(I,"");return}this.adapter.setStorage(I,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function Xe(n){var t;return s==null||s.stop(),s=new V(n,(t=n.adapter)!=null?t:T()),s.start(),n.hookConsole!==!1&&Re(),s}function Ye(){return s}function Fe(n){s==null||s.setEnabled(n)}function Qe(){var n;return(n=s==null?void 0:s.isEnabled())!=null?n:!1}function Ze(n,t,e){s==null||s.log(n,t,e)}var ke={debug:(n,t)=>s==null?void 0:s.log("debug",n,t),info:(n,t)=>s==null?void 0:s.log("info",n,t),warn:(n,t)=>s==null?void 0:s.log("warn",n,t),error:(n,t)=>s==null?void 0:s.log("error",n,t)},se=new Set,ae=!0;function et(n){ae=n}function Re(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(se.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...a)=>{ae&&ke[r](a.map(Le).join(" ")),i(...a)},se.add(e)}}function Le(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}function tt(n,t){s==null||s.report(n,t)}function nt(n){s==null||s.setDeviceName(n)}async function rt(){await(s==null?void 0:s.flush())}export{D as createBrowserAdapter,T as detectAdapter,rt as flush,Ye as getClient,Re as hookConsole,Xe as init,Qe as isEnabled,tt as report,et as setConsoleReport,nt as setDeviceName,Fe as setEnabled,Ze as ulog,ke as ulogger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-log-sdk",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "description": "uni-app / uni-app x 日志上报 SDK:console、JS 错误、自定义事件与设备信息批量上报",
6
6
  "keywords": [
@@ -1,3 +1,3 @@
1
- var te=Object.create;var j=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var q=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var se=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of re(t))!ie.call(n,o)&&o!==e&&j(n,o,{get:()=>t[o],enumerable:!(r=ne(t,o))||r.enumerable});return n};var ae=(n,t,e)=>(e=n!=null?te(oe(n)):{},se(t||!n||!n.__esModule?j(e,"default",{value:n,enumerable:!0}):e,n));var J=q(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var X=q(P=>{"use strict";var ue=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),fe=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&ue(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});fe(J(),P)});function S(){let n=globalThis.uni;return n!=null?n:null}function de(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function ce(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function T(n){return typeof n=="string"&&n.length>0?n:void 0}function le(n){let t=c=>{var h;try{return(h=c==null?void 0:c())!=null?h:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let a=(...c)=>c.map(T).find(Boolean),d=(...c)=>c.map(ce).find(h=>h!==void 0),f=a(r.deviceId,e.deviceId,e.deviceUUID),g=a(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!f||!g?null:{deviceId:f,platform:g,deviceName:a(r.deviceName,e.deviceName),model:a(r.deviceModel,e.deviceModel,e.model),vendor:a(r.deviceBrand,e.deviceBrand,e.brand),os:a(e.osVersion,e.system,r.osVersion,r.system),osVersion:a(e.osVersion,r.osVersion),osName:a(e.osName,r.osName,o.osName),net:a(e.networkType,e.netType),language:a(o.language,e.language),pixelRatio:d(i.pixelRatio,e.pixelRatio),windowWidth:d(i.windowWidth,e.windowWidth),windowHeight:d(i.windowHeight,e.windowHeight),screenWidth:d(i.screenWidth,e.screenWidth),screenHeight:d(i.screenHeight,e.screenHeight)}}function N(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return le(S())}catch{return null}},getCurrentPage(){var n;try{let t=de(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let a=r();return a&&(i=(o=T(a.hostVersion))!=null?o:T(a.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}function G(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}var W="uni-log:web-did",V;function K(n){try{return window.localStorage.getItem(n)}catch{return null}}function $(n,t){try{window.localStorage.setItem(n,t)}catch{}}function ge(){var e;let n=(e=K(W))!=null?e:V;if(n)return V=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return V=t,$(W,t),t}function C(){return{request:G,getStorage:n=>K(n),setStorage:(n,t)=>$(n,t),getDeviceInfo(){return{deviceId:ge(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>typeof location!="undefined"?location.pathname:null,getPlatformVersion:()=>null,onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function D(){let n=globalThis;return typeof n!="undefined"&&n.uni?N():C()}var u=ae(X());var he=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function y(n,t){return n>>>t|n<<32-t}function Y(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function M(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),a=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(a>>>24&255,a>>>16&255,a>>>8&255,a&255);let d=new Array(64);for(let g=0;g<r.length;g+=64){for(let l=0;l<16;l++){let x=g+l*4;d[l]=(r[x]<<24|r[x+1]<<16|r[x+2]<<8|r[x+3])>>>0}for(let l=16;l<64;l++){let x=y(d[l-15],7)^y(d[l-15],18)^d[l-15]>>>3,R=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+R>>>0}let[c,h,b,I,m,v,w,k]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),R=m&v^~m&w,L=k+x+R+he[l]+d[l]>>>0,_=y(c,2)^y(c,13)^y(c,22),O=c&h^c&b^h&b,ee=_+O>>>0;k=w,w=v,v=m,m=I+L>>>0,I=b,b=h,h=c,c=L+ee>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+h>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+I>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let f=[];for(let g of t)f.push(g>>>24&255,g>>>16&255,g>>>8&255,g&255);return f}function pe(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function F(n,t){let e=Y(n);for(e.length>64&&(e=M(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return pe(M(o.concat(M(r.concat(Y(t))))))}function B(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var E="uni-log:pending",z=20,me="0.2.3";function A(n,t){return n.length>t?n.slice(0,t):n}function H(n){let t=n==null?void 0:n.trim();return t?A(t,128):void 0}function xe(n,t,e){var o;let r={t:Date.now(),lv:n,msg:A(t||"(empty)",u.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=A(e.stack,u.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=A(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var U=class{constructor(t,e=N()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(E,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=u.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(xe(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=u.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>u.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=A(e,u.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=u.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?A(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var a,d,f,g,c,h,b,I,m,v,w,k,l,x,R,L,_,O;let e=(a=this.deviceInfo)!=null?a:this.deviceInfo=this.adapter.getDeviceInfo(),r=(h=(c=(g=this.deviceNameOverride)!=null?g:H((f=(d=this.options).getDeviceName)==null?void 0:f.call(d)))!=null?c:H(this.options.deviceName))!=null?h:H(e==null?void 0:e.deviceName),o={deviceId:(b=e==null?void 0:e.deviceId)!=null?b:this.fallbackDeviceId(),platform:(I=e==null?void 0:e.platform)!=null?I:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((w=e==null?void 0:e.net)!=null?w:(v=(m=this.options).getNet)!=null&&v.call(m))?{net:(x=e==null?void 0:e.net)!=null?x:(l=(k=this.options).getNet)==null?void 0:l.call(k)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}};return{header:{appKey:this.options.appKey,batchId:B(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(L=(R=this.options).getUserId)!=null&&L.call(R)?{userId:this.options.getUserId()}:{},...(O=(_=this.options).getNet)!=null&&O.call(_)?{net:this.options.getNet()}:{},sdkVer:me,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,u.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,u.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var d;let r=!1,o,i=f=>{r||(r=!0,clearTimeout(a),e(f))},a=setTimeout(()=>{var f;try{(f=o==null?void 0:o.abort)==null||f.call(o)}catch{}i(!1)},8e3);try{let f=JSON.stringify(t),g={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),h=B(16);g[u.SIGNATURE_HEADERS.ts]=c,g[u.SIGNATURE_HEADERS.nonce]=h,g[u.SIGNATURE_HEADERS.sign]=F(this.options.appSecret,`${c}
1
+ var de=Object.create;var $=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var J=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports);var fe=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of le(t))!ge.call(n,o)&&o!==e&&$(n,o,{get:()=>t[o],enumerable:!(r=ce(t,o))||r.enumerable});return n};var he=(n,t,e)=>(e=n!=null?de(ue(n)):{},fe(t||!n||!n.__esModule?$(e,"default",{value:n,enumerable:!0}):e,n));var te=J(p=>{"use strict";Object.defineProperty(p,"__esModule",{value:!0});p.PROTOCOL_LIMITS=p.SIGNATURE_MAX_SKEW_MS=p.SIGNATURE_HEADERS=p.INGEST_PATH=p.LOG_LEVELS=void 0;p.LOG_LEVELS=["debug","info","warn","error","crash"];p.INGEST_PATH="/ingest/v1/logs";p.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};p.SIGNATURE_MAX_SKEW_MS=300*1e3;p.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var ne=J(P=>{"use strict";var ve=P&&P.__createBinding||(Object.create?(function(n,t,e,r){r===void 0&&(r=e);var o=Object.getOwnPropertyDescriptor(t,e);(!o||("get"in o?!t.__esModule:o.writable||o.configurable))&&(o={enumerable:!0,get:function(){return t[e]}}),Object.defineProperty(n,r,o)}):(function(n,t,e,r){r===void 0&&(r=e),n[r]=t[e]})),we=P&&P.__exportStar||function(n,t){for(var e in n)e!=="default"&&!Object.prototype.hasOwnProperty.call(t,e)&&ve(t,n,e)};Object.defineProperty(P,"__esModule",{value:!0});we(te(),P)});function S(){let n=globalThis.uni;return n!=null?n:null}function pe(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function me(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function B(n){return typeof n=="string"&&n.length>0?n:void 0}function ye(n){let t=c=>{var h;try{return(h=c==null?void 0:c())!=null?h:{}}catch{return{}}},e=t(n==null?void 0:n.getSystemInfoSync),r=t(n==null?void 0:n.getDeviceInfo),o=t(n==null?void 0:n.getAppBaseInfo),i=t(n==null?void 0:n.getWindowInfo);if(Object.keys(e).length===0&&Object.keys(r).length===0)return null;let a=(...c)=>c.map(B).find(Boolean),d=(...c)=>c.map(me).find(h=>h!==void 0),u=a(r.deviceId,e.deviceId,e.deviceUUID),g=a(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!u||!g?null:{deviceId:u,platform:g,deviceName:a(r.deviceName,e.deviceName),model:a(r.deviceModel,e.deviceModel,e.model),vendor:a(r.deviceBrand,e.deviceBrand,e.brand),os:a(e.osVersion,e.system,r.osVersion,r.system),osVersion:a(e.osVersion,r.osVersion),osName:a(e.osName,r.osName,o.osName),net:a(e.networkType,e.netType),language:a(o.language,e.language),pixelRatio:d(i.pixelRatio,e.pixelRatio),windowWidth:d(i.windowWidth,e.windowWidth),windowHeight:d(i.windowHeight,e.windowHeight),screenWidth:d(i.screenWidth,e.screenWidth),screenHeight:d(i.screenHeight,e.screenHeight)}}function N(){return{request(n){var e;let t=S();if(!(t!=null&&t.request)){(e=n.fail)==null||e.call(n,{errMsg:"uni-log: uni.request \u4E0D\u53EF\u7528"});return}return t.request({...n,method:"POST"})},getStorage(n){var t,e;try{let r=(e=(t=S())==null?void 0:t.getStorageSync)==null?void 0:e.call(t,n);return typeof r=="string"&&r.length>0?r:null}catch{return null}},setStorage(n,t){var e,r;try{(r=(e=S())==null?void 0:e.setStorageSync)==null||r.call(e,n,t)}catch{}},getDeviceInfo(){try{return ye(S())}catch{return null}},getCurrentPage(){var n;try{let t=pe(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let a=r();return a&&(i=(o=B(a.hostVersion))!=null?o:B(a.version))!=null?i:null}catch{return null}},e=n!=null&&n.getAppBaseInfo?t(()=>n.getAppBaseInfo()):null;return e||(n!=null&&n.getSystemInfoSync?t(()=>n.getSystemInfoSync()):null)},onError(n){var t,e;try{(e=(t=S())==null?void 0:t.onError)==null||e.call(t,n)}catch{}},onUnhandledRejection(n){var t,e;try{(e=(t=S())==null?void 0:t.onUnhandledRejection)==null||e.call(t,n)}catch{}}}}function z(n){let t=new AbortController;return fetch(n.url,{method:"POST",headers:n.header,body:typeof n.data=="string"?n.data:JSON.stringify(n.data),signal:t.signal}).then(async e=>{var i;let r=await e.text(),o;try{o=JSON.parse(r)}catch{o=r}(i=n.success)==null||i.call(n,{statusCode:e.status,data:o})}).catch(()=>{var e;return(e=n.fail)==null?void 0:e.call(n,{errMsg:"fetch failed"})}),{abort:()=>t.abort()}}var X="uni-log:web-did",H,F=new Set,Y=!1;function Q(){if(typeof location=="undefined")return null;let n=location.pathname||"/",t=location.hash||"";return/^#!?\//.test(t)?t.replace(/^#!?/,"").split("?")[0]||"/":n||"/"}function M(){let n=Q();for(let t of F)try{t(n)}catch{}}function xe(){if(Y||typeof window=="undefined")return;Y=!0,window.addEventListener("popstate",M),window.addEventListener("hashchange",M);let n=window.history;for(let t of["pushState","replaceState"]){let e=n[t];typeof e=="function"&&(n[t]=function(...r){let o=e.apply(this,r);return M(),o})}}function Z(n){try{return window.localStorage.getItem(n)}catch{return null}}function ee(n,t){try{window.localStorage.setItem(n,t)}catch{}}function be(){var e;let n=(e=Z(X))!=null?e:H;if(n)return H=n,n;let t=`web-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`;return H=t,ee(X,t),t}function D(){return{request:z,getStorage:n=>Z(n),setStorage:(n,t)=>ee(n,t),getDeviceInfo(){return{deviceId:be(),platform:"web",osName:"web",language:typeof navigator!="undefined"?navigator.language:void 0,screenWidth:typeof screen!="undefined"&&Number(screen.width)||void 0,screenHeight:typeof screen!="undefined"&&Number(screen.height)||void 0}},getCurrentPage:()=>Q(),getPlatformVersion:()=>null,onPageChange(n){F.add(n),xe()},onHidden(n){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="hidden"&&n()})},onError(n){typeof window!="undefined"&&window.addEventListener("error",t=>{var e,r;return n((r=(e=t.error)!=null?e:t.message)!=null?r:"window error")})},onUnhandledRejection(n){typeof window!="undefined"&&window.addEventListener("unhandledrejection",t=>{var e;return n((e=t.reason)!=null?e:t)})}}}function T(){let n=globalThis;return typeof n!="undefined"&&n.uni?N():D()}var f=he(ne());var Se=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function x(n,t){return n>>>t|n<<32-t}function re(n){let t=[];for(let e=0;e<n.length;e++){let r=n.charCodeAt(e);if(r<128)t.push(r);else if(r<2048)t.push(192|r>>6,128|r&63);else if(r>=55296&&r<=56319&&e+1<n.length){let o=n.charCodeAt(e+1);if(o>=56320&&o<=57343){e+=1;let i=65536+(r-55296<<10)+(o-56320);t.push(240|i>>18,128|i>>12&63,128|i>>6&63,128|i&63)}else t.push(239,191,189)}else r>=56320&&r<=57343?t.push(239,191,189):t.push(224|r>>12,128|r>>6&63,128|r&63)}return t}function j(n){let t=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],e=n.length,r=n.slice();for(r.push(128);r.length%64!==56;)r.push(0);let o=e*8,i=Math.floor(o/4294967296),a=o>>>0;r.push(i>>>24&255,i>>>16&255,i>>>8&255,i&255),r.push(a>>>24&255,a>>>16&255,a>>>8&255,a&255);let d=new Array(64);for(let g=0;g<r.length;g+=64){for(let l=0;l<16;l++){let y=g+l*4;d[l]=(r[y]<<24|r[y+1]<<16|r[y+2]<<8|r[y+3])>>>0}for(let l=16;l<64;l++){let y=x(d[l-15],7)^x(d[l-15],18)^d[l-15]>>>3,R=x(d[l-2],17)^x(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+y+d[l-7]+R>>>0}let[c,h,b,E,m,v,w,k]=t;for(let l=0;l<64;l++){let y=x(m,6)^x(m,11)^x(m,25),R=m&v^~m&w,A=k+y+R+Se[l]+d[l]>>>0,_=x(c,2)^x(c,13)^x(c,22),O=c&h^c&b^h&b,C=_+O>>>0;k=w,w=v,v=m,m=E+A>>>0,E=b,b=h,h=c,c=A+C>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+h>>>0,t[2]=t[2]+b>>>0,t[3]=t[3]+E>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+v>>>0,t[6]=t[6]+w>>>0,t[7]=t[7]+k>>>0}let u=[];for(let g of t)u.push(g>>>24&255,g>>>16&255,g>>>8&255,g&255);return u}function Pe(n){let t="";for(let e of n)t+=e.toString(16).padStart(2,"0");return t}function oe(n,t){let e=re(n);for(e.length>64&&(e=j(e));e.length<64;)e.push(0);let r=e.map(i=>i^54),o=e.map(i=>i^92);return Pe(j(o.concat(j(r.concat(re(t))))))}function q(n=16){let t="";for(let e=0;e<n;e++)t+=Math.floor(Math.random()*256).toString(16).padStart(2,"0");return t}var I="uni-log:pending",ie=20,Ie="0.3.0";function L(n,t){return n.length>t?n.slice(0,t):n}function U(n){let t=n==null?void 0:n.trim();return t?L(t,128):void 0}function Ee(n,t,e){var o;let r={t:Date.now(),lv:n,msg:L(t||"(empty)",f.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=L(e.stack,f.PROTOCOL_LIMITS.maxStackLength)),e!=null&&e.page&&(r.page=L(e.page,255)),e!=null&&e.extra&&(r.extra=e.extra),(o=e==null?void 0:e.tags)!=null&&o.length&&(r.tags=e.tags),r}var V=class{constructor(t,e=N()){this.ready=!1;this.logs=[];this.events=[];this.timer=null;this.flushingPromise=null;this.launchTime=Date.now();this.pageCount=0;this.lastPage=null;this.deviceInfo=null;this.deviceNameOverride=null;this.hooksInstalled=!1;this.lifecycleInstalled=!1;this.options=t,this.adapter=e,this.userEnabled=t.enabled!==!1,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r,o,i,a,d;if(this.ready||!this.userEnabled)return;this.ready=!0;let t=Math.max(1e3,(e=this.options.flushInterval)!=null?e:1e4);this.timer=setInterval(()=>{this.flush().catch(()=>{})},t),((r=this.adapter.ready)!=null?r:Promise.resolve()).then(()=>this.retryPending()).catch(()=>{}),this.options.collectErrors!==!1&&!this.hooksInstalled&&(this.installErrorHooks(),this.hooksInstalled=!0),this.lifecycleInstalled||((i=(o=this.adapter).onPageChange)==null||i.call(o,u=>{!this.ready||!u||u===this.lastPage||(this.lastPage=u,this.pageCount+=1)}),(d=(a=this.adapter).onHidden)==null||d.call(a,()=>{this.flush().catch(()=>{})}),this.lifecycleInstalled=!0),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}setEnabled(t){if(this.userEnabled!==t){if(this.userEnabled=t,t){this.start();return}this.stop(),this.logs=[],this.events=[];try{this.adapter.setStorage(I,"")}catch{}}}isEnabled(){return this.ready&&this.userEnabled}log(t,e,r){if(!this.ready)return;let o=f.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(Ee(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=f.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>f.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=L(e,f.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=f.PROTOCOL_LIMITS.maxEventsPerBatch&&this.flush()}pageView(t){if(!this.ready)return;let e=t!=null?t:this.adapter.getCurrentPage();this.pageCount+=1,e&&(this.lastPage=e)}setDeviceName(t){let e=t.trim();this.deviceNameOverride=e?L(e,128):null}samplePage(){let t=this.adapter.getCurrentPage();t&&t!==this.lastPage&&(this.lastPage=t,this.pageCount+=1)}async flush(){if(!this.ready)return;if(this.flushingPromise)return this.flushingPromise;let t=async()=>{var r;let e;try{for(this.samplePage(),e=this.buildPayload(!0);;){if(!await this.send(e)){(e.logs.length||(r=e.events)!=null&&r.length)&&(this.persistPending([e]),this.options.debug&&console.warn("[uni-log] \u4E0A\u62A5\u5931\u8D25\uFF0C\u5DF2\u6682\u5B58\u5F85\u7EED\u4F20"));break}if(this.logs.length===0&&this.events.length===0)break;e=this.buildPayload(!1)}}catch(o){if(e)try{this.persistPending([e])}catch{}this.options.debug&&console.warn("[uni-log] flush \u5F02\u5E38",o)}finally{this.flushingPromise=null}};return this.flushingPromise=t(),this.flushingPromise}buildPayload(t){var d,u,g,c,h,b,E,m,v,w,k,l,y,R,A,_,O,C,G,W,K;let e=(d=this.deviceInfo)!=null?d:this.deviceInfo=this.adapter.getDeviceInfo(),r=(b=(h=(c=this.deviceNameOverride)!=null?c:U((g=(u=this.options).getDeviceName)==null?void 0:g.call(u)))!=null?h:U(this.options.deviceName))!=null?b:U(e==null?void 0:e.deviceName),o={deviceId:(E=e==null?void 0:e.deviceId)!=null?E:this.fallbackDeviceId(),platform:(m=e==null?void 0:e.platform)!=null?m:"unknown",...r?{deviceName:r}:{},...e!=null&&e.model?{model:e.model}:{},...e!=null&&e.vendor?{vendor:e.vendor}:{},...e!=null&&e.os?{os:e.os}:{},...e!=null&&e.osVersion?{osVersion:e.osVersion}:{},...e!=null&&e.osName?{osName:e.osName}:{},...((k=e==null?void 0:e.net)!=null?k:(w=(v=this.options).getNet)!=null&&w.call(v))?{net:(R=e==null?void 0:e.net)!=null?R:(y=(l=this.options).getNet)==null?void 0:y.call(l)}:{},...e!=null&&e.language?{language:e.language}:{},...e!=null&&e.pixelRatio?{pixelRatio:e.pixelRatio}:{},...e!=null&&e.windowWidth?{windowWidth:e.windowWidth}:{},...e!=null&&e.windowHeight?{windowHeight:e.windowHeight}:{},...e!=null&&e.screenWidth?{screenWidth:e.screenWidth}:{},...e!=null&&e.screenHeight?{screenHeight:e.screenHeight}:{}},i=U((O=(_=(A=this.options).getBizTenantId)==null?void 0:_.call(A))!=null?O:this.options.bizTenantId);return{header:{appKey:this.options.appKey,batchId:q(12),...this.options.appVer?{appVer:this.options.appVer}:{},...this.options.release?{release:this.options.release}:{},...this.options.channel?{channel:this.options.channel}:{},sessionId:this.sessionId,...(G=(C=this.options).getUserId)!=null&&G.call(C)?{userId:this.options.getUserId()}:{},...i?{bizTenantId:i}:{},...(K=(W=this.options).getNet)!=null&&K.call(W)?{net:this.options.getNet()}:{},sdkVer:Ie,...this.adapter.getPlatformVersion()?{platformVersion:this.adapter.getPlatformVersion()}:{}},device:o,...t?{session:{launchTime:this.launchTime,duration:Math.max(0,Math.round((Date.now()-this.launchTime)/1e3)),pageCount:this.pageCount}}:{},logs:this.logs.splice(0,f.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,f.PROTOCOL_LIMITS.maxEventsPerBatch)}:{}}}fallbackDeviceId(){let t=this.adapter.getStorage("uni-log:did");return t||(t=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,this.adapter.setStorage("uni-log:did",t)),t}send(t){return new Promise(e=>{var d;let r=!1,o,i=u=>{r||(r=!0,clearTimeout(a),e(u))},a=setTimeout(()=>{var u;try{(u=o==null?void 0:o.abort)==null||u.call(o)}catch{}i(!1)},8e3);try{let u=JSON.stringify(t),g={"Content-Type":"application/json"};if(this.options.appSecret){let c=String(Date.now()),h=q(16);g[f.SIGNATURE_HEADERS.ts]=c,g[f.SIGNATURE_HEADERS.nonce]=h,g[f.SIGNATURE_HEADERS.sign]=oe(this.options.appSecret,`${c}
2
2
  ${h}
3
- ${f}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${u.INGEST_PATH}`,data:f,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(E),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>z&&(r=r.slice(-z));try{this.adapter.setStorage(E,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(E);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(E,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(E,"");return}this.adapter.setStorage(E,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function je(n){var t;return s==null||s.stop(),s=new U(n,(t=n.adapter)!=null?t:D()),s.start(),n.hookConsole!==!1&&be(),s}function qe(){return s}function Ge(n){s==null||s.setEnabled(n)}function We(){var n;return(n=s==null?void 0:s.isEnabled())!=null?n:!1}function Ke(n,t,e){s==null||s.log(n,t,e)}var ye={debug:(n,t)=>s==null?void 0:s.log("debug",n,t),info:(n,t)=>s==null?void 0:s.log("info",n,t),warn:(n,t)=>s==null?void 0:s.log("warn",n,t),error:(n,t)=>s==null?void 0:s.log("error",n,t)},Q=new Set,Z=!0;function $e(n){Z=n}function be(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(Q.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...a)=>{Z&&ye[r](a.map(ve).join(" ")),i(...a)},Q.add(e)}}function ve(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}function Je(n,t){s==null||s.report(n,t)}function Xe(n){s==null||s.setDeviceName(n)}async function Ye(){await(s==null?void 0:s.flush())}export{C as createBrowserAdapter,D as detectAdapter,Ye as flush,qe as getClient,be as hookConsole,je as init,We as isEnabled,Je as report,$e as setConsoleReport,Xe as setDeviceName,Ge as setEnabled,Ke as ulog,ye as ulogger};
3
+ ${u}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${f.INGEST_PATH}`,data:u,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(I),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>ie&&(r=r.slice(-ie));try{this.adapter.setStorage(I,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(I);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(I,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(I,"");return}this.adapter.setStorage(I,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function Xe(n){var t;return s==null||s.stop(),s=new V(n,(t=n.adapter)!=null?t:T()),s.start(),n.hookConsole!==!1&&Re(),s}function Ye(){return s}function Fe(n){s==null||s.setEnabled(n)}function Qe(){var n;return(n=s==null?void 0:s.isEnabled())!=null?n:!1}function Ze(n,t,e){s==null||s.log(n,t,e)}var ke={debug:(n,t)=>s==null?void 0:s.log("debug",n,t),info:(n,t)=>s==null?void 0:s.log("info",n,t),warn:(n,t)=>s==null?void 0:s.log("warn",n,t),error:(n,t)=>s==null?void 0:s.log("error",n,t)},se=new Set,ae=!0;function et(n){ae=n}function Re(){let n={debug:"debug",log:"info",info:"info",warn:"warn",error:"error"},t=console;for(let[e,r]of Object.entries(n)){if(se.has(e))continue;let o=t[e];if(typeof o!="function")continue;let i=o.bind(console);t[e]=(...a)=>{ae&&ke[r](a.map(Le).join(" ")),i(...a)},se.add(e)}}function Le(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}function tt(n,t){s==null||s.report(n,t)}function nt(n){s==null||s.setDeviceName(n)}async function rt(){await(s==null?void 0:s.flush())}export{D as createBrowserAdapter,T as detectAdapter,rt as flush,Ye as getClient,Re as hookConsole,Xe as init,Qe as isEnabled,tt as report,et as setConsoleReport,nt as setDeviceName,Fe as setEnabled,Ze as ulog,ke as ulogger};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "uni-log",
3
3
  "displayName": "uni-log 日志上报",
4
- "version": "0.2.3",
4
+ "version": "0.3.0",
5
5
  "description": "uni-app / uni-app x 日志上报 SDK:console、JS 错误、自定义事件与设备信息批量上报",
6
6
  "keywords": [
7
7
  "uni-app",
@@ -12,7 +12,8 @@
12
12
  | --- | --- | --- |
13
13
  | uniapp / uniapp x(App·H5·小程序) | 主入口 `init()` 自动探测 uni 适配器 | console 劫持、页面栈、错误钩子全自动 |
14
14
  | **React Native(CLI / Expo)** | 子路径 `uni-log-sdk/react-native` 的 `initRN()` | 存储经 AsyncStorage(Expo Go 内置);页面路由需一行接线 |
15
- | **任意 TS Web 应用**(React / Vue / 纯浏览器) | 主入口 `init()` 自动探测浏览器适配器 | fetch + localStorage + window 错误事件,零配置 |
15
+ | **任意 TS Web 应用**(React / Vue / 纯浏览器) | 主入口 `init()` 自动探测浏览器适配器 | fetch + localStorage + window 错误事件;SPA hash/history 路由自动识别、页面隐藏自动 flush |
16
+ | **HarmonyOS 原生(ArkTS)** | 独立 HAR 包 `@tlovers/uni-log-sdk`(`packages/sdk-harmony`)的 `initHarmony()` | ohpm 安装;设备标识用 `deviceInfo.ODID`;详见下方「HarmonyOS 原生接入」 |
16
17
  | 非 TS 技术栈(Flutter / 原生) | 按协议自行实现(HTTP + JSON + HMAC-SHA256) | 服务端零改动,详见协议定义 `@uni-log/shared` |
17
18
 
18
19
  ### 适配器架构(贡献者向)
@@ -23,7 +24,7 @@
23
24
  src/adapters/
24
25
  ├── types.ts # PlatformAdapter / RequestOptions / RequestTask 纯接口
25
26
  ├── uni.ts # uni 适配器(uni-app / uni-app x):uni.request / 同步 storage / 页面栈三级兜底
26
- ├── web.ts # 浏览器适配器:localStorage / window 错误事件(SSR 防御)
27
+ ├── web.ts # 浏览器适配器:localStorage / window 错误事件 / SPA 路由与 visibilitychange(SSR 防御)
27
28
  ├── react-native.ts # RN 适配器:AsyncStorage 异步写穿+预读(ready 信号)/ ErrorUtils 链式
28
29
  ├── fetch.ts # web / react-native 共用的 fetch 请求实现(POST + AbortController)
29
30
  ├── detect.ts # detectAdapter:有 uni 全局走 uni,否则浏览器
@@ -112,7 +113,9 @@ init({
112
113
  | `channel` | string | - | 渠道 code / 小程序场景值 |
113
114
  | `deviceName` | string | - | 设备名称(给人看的) |
114
115
  | `getDeviceName` | `() => string` | - | 动态设备名称,优先级高于 `deviceName` |
115
- | `getUserId` | `() => string` | - | 业务用户标识 |
116
+ | `getUserId` | `() => string` | - | 业务用户标识(账号级归属) |
117
+ | `bizTenantId` | string | - | 业务租户/商户标识(静态) |
118
+ | `getBizTenantId` | `() => string` | - | 动态业务租户标识,优先级高于 `bizTenantId` |
116
119
  | `getNet` | `() => string` | - | 网络类型 |
117
120
  | `flushInterval` | number | `10000` | 上报间隔(毫秒) |
118
121
  | `collectErrors` | boolean | `true` | 自动捕获 `uni.onError` / `onUnhandledRejection` |
@@ -120,6 +123,31 @@ init({
120
123
  | `enabled` | boolean | `true` | 采集上报总开关;`false` 时不采集/不上报/不挂错误钩子 |
121
124
  | `debug` | boolean | `false` | 打印 SDK 内部日志 |
122
125
 
126
+ ### 业务租户 / 账号归属
127
+
128
+ 一个应用服务多个业务租户(客户/商户)时,用 `getUserId` 记账号、`getBizTenantId` 记租户:
129
+
130
+ ```ts
131
+ let userId: string | undefined
132
+ let bizTenantId: string | undefined
133
+
134
+ init({
135
+ serverUrl,
136
+ appKey,
137
+ appSecret,
138
+ getUserId: () => userId,
139
+ getBizTenantId: () => bizTenantId,
140
+ })
141
+
142
+ // 登录成功后
143
+ userId = account.id
144
+ bizTenantId = account.tenantId
145
+ ```
146
+
147
+ - `userId` 写入日志/事件/会话的 `userId`,用于账号级归属;
148
+ - `bizTenantId` 写入 `header.bizTenantId`,用于看板「业务租户」筛选与错误/事件/设备报表;
149
+ - 两者都是业务字段,**不参与看板登录权限**;不担心伪造时按普通字段使用即可。
150
+
123
151
  ### 开发环境不上报
124
152
 
125
153
  SDK 不会自己判断「这是开发版还是打包版」——各端机制不同(RN 有 `__DEV__`,Vite/webpack 注入 `NODE_ENV`,HBuilderX 自定义基座两者都没有),所以由宿主明确告知:
@@ -165,6 +193,15 @@ setEnabled(false) // 总开关:停采集并丢弃待发数据(isEnabled()
165
193
  await flush() // 应用退后台/页面隐藏时可主动上报
166
194
  ```
167
195
 
196
+ ## Web SPA 说明
197
+
198
+ - 自动识别 hash 路由(`#/path`、`#!/path`)与 history 路由(`pathname`);
199
+ - `page` 只记录路径,不记录 query 和普通锚点(避免 `?id=123` 把页面维度打散);hash 路由记为去掉 `#` 的 `/path`;
200
+ - 监听 `pushState` / `replaceState` / `popstate` / `hashchange`,路由变化自动累计 `page_count`;
201
+ - **Web 端不要再在路由变化处调用 `pageView()`**,否则会重复计数;uni-app / RN 仍按原方式手动调用;
202
+ - `document.visibilitychange` 进入 `hidden` 时自动 `flush()`,降低切后台/关页丢最后一批日志的概率;
203
+ - SSR 场景请在客户端挂载后再 `init()`(服务端没有 `window` 时不会挂路由/隐藏监听)。
204
+
168
205
  ## React Native / Expo 接入
169
206
 
170
207
  ```bash
@@ -187,6 +224,44 @@ initRN({
187
224
  - 未处理 Promise rejection 需宿主接线:`require('promise/setimmediate/rejection-tracking').enable({ allRejections: true, onUnhandled: (id, e) => ulog('error', String(e)) })`。
188
225
  - 存储经 AsyncStorage 异步写穿 + 冷启动预读;Expo Go 内置 async-storage,bare RN 需安装。
189
226
 
227
+ ## HarmonyOS 原生接入(ArkTS)
228
+
229
+ npm 包用于 uni-app / Web / React Native;**HarmonyOS 原生应用用独立 HAR 包**,两者协议与服务端完全一致。
230
+
231
+ ```bash
232
+ # 工程根 oh-package.json5
233
+ {
234
+ "dependencies": {
235
+ "@tlovers/uni-log-sdk": "file:../uni-log-sdk.har"
236
+ }
237
+ }
238
+ # 然后 ohpm install
239
+ ```
240
+
241
+ 在 `EntryAbility.ets` 里初始化(需要 `UIAbilityContext` 用于持久化):
242
+
243
+ ```ts
244
+ import { initHarmony } from '@tlovers/uni-log-sdk'
245
+
246
+ export default class EntryAbility extends UIAbility {
247
+ onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
248
+ initHarmony({
249
+ context: this.context,
250
+ serverUrl: 'https://log.example.com',
251
+ appKey: '<看板分配>',
252
+ appSecret: '<与 appKey 成对>',
253
+ appVer: '1.0.0',
254
+ getPage: () => 'pages/Index', // 可选:鸿蒙无全局页面栈
255
+ })
256
+ }
257
+ }
258
+ ```
259
+
260
+ - 设备标识用 `deviceInfo.ODID`(同步、无权限、同一开发者应用在同设备共享);ODID 为空时降级为本地持久化 UUID
261
+ - 网络需 `ohos.permission.INTERNET`(在宿主 `module.json5` 声明)
262
+ - 错误经 `errorManager.on('error')` 捕获;这是观察者语义,不会阻止应用退出
263
+ - 构建:`cd packages/sdk-harmony && hvigorw assembleHar`(产物 `uni_log_sdk/build/default/outputs/default/uni_log_sdk.har`)
264
+
190
265
  ## 注意事项
191
266
 
192
267
  - `serverUrl` 不要带尾斜杠;App 真机需用局域网 IP 或 HTTPS 域名,Android 9+ 默认禁止明文 HTTP。