uni-log-sdk 0.2.3 → 0.2.4
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 +6 -0
- package/dist/adapters/react-native.d.mts +1 -1
- package/dist/adapters/react-native.d.ts +1 -1
- package/dist/adapters/react-native.js +2 -2
- package/dist/adapters/react-native.mjs +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/uni_modules/uni-log/index.js +1 -1
- package/uni_modules/uni-log/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
`uni-log-sdk` 的版本变更记录,按新→旧排列,日期为 npm 实际发布日期。
|
|
4
4
|
|
|
5
|
+
## [0.2.4] — 2026-11-16
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
|
|
9
|
+
- `initRN()` 现在要求显式传入 `serverUrl` 与 `appKey`,二者缺失时直接抛出 `[uni-log] initRN 缺少 serverUrl 或 appKey`。此前默认参数用 `{} as ...` 绕过了类型必填,JS 调用方漏传时不会报错,而是把日志发往 `undefined/ingest/v1/logs`,失败后难以定位。**这是破坏性变更**:如果你的项目正在无参或只传部分参数调用 `initRN()`,升级后会立刻抛错,请补齐这两个参数。
|
|
10
|
+
|
|
5
11
|
## [0.2.3] — 2026-11-16
|
|
6
12
|
|
|
7
13
|
### 新增
|
|
@@ -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
|
|
12
|
+
declare function initRN(options: Omit<UniLogOptions, 'adapter'> & ReactNativeAdapterOptions): UniLogClient;
|
|
13
13
|
|
|
14
14
|
export { type ReactNativeAdapterOptions, createReactNativeAdapter, initRN };
|
|
@@ -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
|
|
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 ae=Object.create;var U=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var ce=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 le(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(ce(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 Le={};ue(Le,{createReactNativeAdapter:()=>ie,initRN:()=>Ae});module.exports=fe(Le);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=l=>{var u;try{return(u=l==null?void 0:l())!=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=(...l)=>l.map(G).find(Boolean),s=(...l)=>l.map(pe).find(u=>u!==void 0),a=d(r.deviceId,e.deviceId,e.deviceUUID),c=d(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!a||!c?null:{deviceId:a,platform:c,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 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?O():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 c=0;c<r.length;c+=64){for(let g=0;g<16;g++){let y=c+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,N=x(s[g-2],17)^x(s[g-2],19)^s[g-2]>>>10;s[g]=s[g-16]+y+s[g-7]+N>>>0}let[l,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),N=m&v^~m&w,L=k+y+N+ve[g]+s[g]>>>0,_=x(l,2)^x(l,13)^x(l,22),D=l&u^l&b^u&b,se=_+D>>>0;k=w,w=v,v=m,m=R+L>>>0,R=b,b=u,u=l,l=L+se>>>0}t[0]=t[0]+l>>>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 c of t)a.push(c>>>24&255,c>>>16&255,c>>>8&255,c&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 E="uni-log:pending",ne=20,Se="0.2.4";function A(n,t){return n.length>t?n.slice(0,t):n}function W(n){let t=n==null?void 0:n.trim();return t?A(t,128):void 0}function Pe(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 H=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.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=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=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,c,l,u,b,R,m,v,w,k,g,y,N,L,_,D;let e=(d=this.deviceInfo)!=null?d:this.deviceInfo=this.adapter.getDeviceInfo(),r=(u=(l=(c=this.deviceNameOverride)!=null?c:W((a=(s=this.options).getDeviceName)==null?void 0:a.call(s)))!=null?l: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,...(L=(N=this.options).getUserId)!=null&&L.call(N)?{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),c={"Content-Type":"application/json"};if(this.options.appSecret){let l=String(Date.now()),u=q(16);c[h.SIGNATURE_HEADERS.ts]=l,c[h.SIGNATURE_HEADERS.nonce]=u,c[h.SIGNATURE_HEADERS.sign]=te(this.options.appSecret,`${l}
|
|
2
2
|
${u}
|
|
3
|
-
${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:
|
|
3
|
+
${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:c,success:l=>i(!!l&&l.statusCode>=200&&l.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(E),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(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 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 Ee={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,Ie=!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)=>{Ie&&Ee[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 I=require("react-native"),K=Y(require("@react-native-async-storage/async-storage")),Ne="uni-log:pending",M="uni-log:did";function ie(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[Ne,M]){let c=await K.default.getItem(a);c!=null&&t.set(a,c)}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:I.Platform.OS==="ios"?"ios":I.Platform.OS==="android"?"android":I.Platform.OS,osName:I.Platform.OS,os:String(I.Platform.Version),osVersion:String(I.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 c=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((l,u)=>{s(l),typeof c=="function"&&c(l,u)})},onUnhandledRejection(s){}}}function Ae(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 oe({...e,adapter:ie({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 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 le=(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 ce=(n,t,e)=>(e=n!=null?oe(ae(n)):{},le(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=l=>{var u;try{return(u=l==null?void 0:l())!=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=(...l)=>l.map(M).find(Boolean),s=(...l)=>l.map(ue).find(u=>u!==void 0),a=d(r.deviceId,e.deviceId,e.deviceUUID),c=d(e.uniPlatform,e.platform,r.platform,r.uniPlatform);return!a||!c?null:{deviceId:a,platform:c,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 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?O():C()}var h=ce(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 c=0;c<r.length;c+=64){for(let g=0;g<16;g++){let y=c+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[l,u,b,I,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,L=R+y+k+ye[g]+s[g]>>>0,_=x(l,2)^x(l,13)^x(l,22),D=l&u^l&b^u&b,re=_+D>>>0;R=w,w=v,v=m,m=I+L>>>0,I=b,b=u,u=l,l=L+re>>>0}t[0]=t[0]+l>>>0,t[1]=t[1]+u>>>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]+R>>>0}let a=[];for(let c of t)a.push(c>>>24&255,c>>>16&255,c>>>8&255,c&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 E="uni-log:pending",Z=20,be="0.2.4";function N(n,t){return n.length>t?n.slice(0,t):n}function q(n){let t=n==null?void 0:n.trim();return t?N(t,128):void 0}function ve(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 V=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.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=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=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,c,l,u,b,I,m,v,w,R,g,y,k,L,_,D;let e=(d=this.deviceInfo)!=null?d:this.deviceInfo=this.adapter.getDeviceInfo(),r=(u=(l=(c=this.deviceNameOverride)!=null?c:q((a=(s=this.options).getDeviceName)==null?void 0:a.call(s)))!=null?l: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:(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:(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,...(L=(k=this.options).getUserId)!=null&&L.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),c={"Content-Type":"application/json"};if(this.options.appSecret){let l=String(Date.now()),u=j(16);c[h.SIGNATURE_HEADERS.ts]=l,c[h.SIGNATURE_HEADERS.nonce]=u,c[h.SIGNATURE_HEADERS.sign]=Q(this.options.appSecret,`${l}
|
|
2
2
|
${u}
|
|
3
|
-
${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:
|
|
3
|
+
${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${h.INGEST_PATH}`,data:a,header:c,success:l=>i(!!l&&l.statusCode>=200&&l.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(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 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(Ee).join(" ")),i(...d)},ee.add(e)}}function Ee(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 ne from"@react-native-async-storage/async-storage";var Ie="uni-log:pending",H="uni-log:did";function Re(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[Ie,H]){let c=await ne.getItem(a);c!=null&&t.set(a,c)}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: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 c=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((l,u)=>{s(l),typeof c=="function"&&c(l,u)})},onUnhandledRejection(s){}}}function Ze(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 te({...e,adapter:Re({getPage:t})})}export{Re as createReactNativeAdapter,Ze as initRN};
|
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 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.4";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}
|
|
2
2
|
${h}
|
|
3
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});
|
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 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.4";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}
|
|
2
2
|
${h}
|
|
3
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};
|
package/package.json
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 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.4";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}
|
|
2
2
|
${h}
|
|
3
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};
|