uni-log-sdk 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  `uni-log-sdk` 的版本变更记录,按新→旧排列,日期为 npm 实际发布日期。
4
4
 
5
+ ## [0.2.2] — 2026-11-16
6
+
7
+ ### 修复
8
+
9
+ - 修复 0.2.1 的 `uni_modules` 形态无法使用:`uni_modules/uni-log/index.js` 只有一句转发到 `./chunk-xxx.mjs`,而该文件只存在于 `dist/` 下,执行 `npx uni-log sync` 同步进 uni-app / uni-app x 工程后,HBuilderX 编译报 `Could not resolve "./chunk-xxx.mjs"`。现在构建产物不再分包,`uni_modules/uni-log/index.js` 为自包含单文件,HBuilderX 直接可用。
10
+
11
+ > 仅 `uni_modules` 形态受影响;`import { init } from 'uni-log-sdk'` 的 npm 用法在 0.2.1 下正常(chunk 随包发布)。
12
+
5
13
  ## [0.2.1] — 2026-11-14
6
14
 
7
15
  ### 新增
@@ -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=$(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.PROTOCOL_LIMITS=h.SIGNATURE_MAX_SKEW_MS=h.SIGNATURE_HEADERS=h.INGEST_PATH=h.LOG_LEVELS=void 0;h.LOG_LEVELS=["debug","info","warn","error","crash"];h.INGEST_PATH="/ingest/v1/logs";h.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};h.SIGNATURE_MAX_SKEW_MS=300*1e3;h.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]})),ve=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});ve(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 pe(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function he(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(he).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=pe(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let 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 p=Y(Z());var be=[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,E=x(s[g-2],17)^x(s[g-2],19)^s[g-2]>>>10;s[g]=s[g-16]+y+s[g-7]+E>>>0}let[c,u,v,R,m,b,w,k]=t;for(let g=0;g<64;g++){let y=x(m,6)^x(m,11)^x(m,25),E=m&b^~m&w,O=k+y+E+be[g]+s[g]>>>0,_=x(c,2)^x(c,13)^x(c,22),D=c&u^c&v^u&v,se=_+D>>>0;k=w,w=b,b=m,m=R+O>>>0,R=v,v=u,u=c,c=O+se>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+u>>>0,t[2]=t[2]+v>>>0,t[3]=t[3]+R>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+b>>>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 A="uni-log:pending",ne=20,Se="0.2.1";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)",p.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=N(e.stack,p.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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}log(t,e,r){if(!this.ready)return;let o=p.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>=p.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>p.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=N(e,p.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=p.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,v,R,m,b,w,k,g,y,E,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:(v=e==null?void 0:e.deviceId)!=null?v: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:(b=(m=this.options).getNet)!=null&&b.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=(E=this.options).getUserId)!=null&&O.call(E)?{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,p.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,p.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[p.SIGNATURE_HEADERS.ts]=c,l[p.SIGNATURE_HEADERS.nonce]=u,l[p.SIGNATURE_HEADERS.sign]=te(this.options.appSecret,`${c}
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=$(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.PROTOCOL_LIMITS=h.SIGNATURE_MAX_SKEW_MS=h.SIGNATURE_HEADERS=h.INGEST_PATH=h.LOG_LEVELS=void 0;h.LOG_LEVELS=["debug","info","warn","error","crash"];h.INGEST_PATH="/ingest/v1/logs";h.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};h.SIGNATURE_MAX_SKEW_MS=300*1e3;h.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]})),ve=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});ve(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 pe(){var n,t,e;try{let r=globalThis;return typeof r.getCurrentPages=="function"?r.getCurrentPages():typeof getCurrentPages=="function"?getCurrentPages():(e=(t=(n=r.uni)==null?void 0:n.getCurrentPages)==null?void 0:t.call(n))!=null?e:null}catch{return null}}function he(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(he).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=pe(),e=t==null?void 0:t[t.length-1];return(n=e==null?void 0:e.route)!=null?n:null}catch{return null}},getPlatformVersion(){let n=S(),t=r=>{var o,i;try{let 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 p=Y(Z());var be=[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,E=x(s[g-2],17)^x(s[g-2],19)^s[g-2]>>>10;s[g]=s[g-16]+y+s[g-7]+E>>>0}let[c,u,v,R,m,b,w,k]=t;for(let g=0;g<64;g++){let y=x(m,6)^x(m,11)^x(m,25),E=m&b^~m&w,O=k+y+E+be[g]+s[g]>>>0,_=x(c,2)^x(c,13)^x(c,22),D=c&u^c&v^u&v,se=_+D>>>0;k=w,w=b,b=m,m=R+O>>>0,R=v,v=u,u=c,c=O+se>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+u>>>0,t[2]=t[2]+v>>>0,t[3]=t[3]+R>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+b>>>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 A="uni-log:pending",ne=20,Se="0.2.2";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)",p.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=N(e.stack,p.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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}log(t,e,r){if(!this.ready)return;let o=p.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>=p.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>p.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=N(e,p.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=p.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,v,R,m,b,w,k,g,y,E,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:(v=e==null?void 0:e.deviceId)!=null?v: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:(b=(m=this.options).getNet)!=null&&b.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=(E=this.options).getUserId)!=null&&O.call(E)?{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,p.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,p.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[p.SIGNATURE_HEADERS.ts]=c,l[p.SIGNATURE_HEADERS.nonce]=u,l[p.SIGNATURE_HEADERS.sign]=te(this.options.appSecret,`${c}
2
2
  ${u}
3
3
  ${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${p.INGEST_PATH}`,data:a,header:l,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?s:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let d={};for(let s of Object.keys(i))d[s]=r(i[s]);return d}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(A),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(A,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(A);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(A,""),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(A,"");return}this.adapter.setStorage(A,"");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&&ke(),f}var Ie={debug:(n,t)=>f==null?void 0:f.log("debug",n,t),info:(n,t)=>f==null?void 0:f.log("info",n,t),warn:(n,t)=>f==null?void 0:f.log("warn",n,t),error:(n,t)=>f==null?void 0:f.log("error",n,t)},re=new Set,Re=!0;function ke(){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)=>{Re&&Ie[r](d.map(Ee).join(" ")),i(...d)},re.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)}}var I=require("react-native"),K=Y(require("@react-native-async-storage/async-storage")),Ae="uni-log:pending",M="uni-log:did";function ie(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[Ae,M]){let l=await K.default.getItem(a);l!=null&&t.set(a,l)}let s=t.get(M);s&&(e=s)}catch{}})(),o=s=>{var a;return(a=t.get(s))!=null?a:null},i=(s,a)=>{t.set(s,a),K.default.setItem(s,a).catch(()=>{})},d=()=>{var s;return e||(e=(s=o(M))!=null?s:void 0,e||(e=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,i(M,e))),e};return{ready:r,request:C,getStorage:s=>o(s),setStorage:(s,a)=>i(s,a),getDeviceInfo(){return{deviceId:d(),platform: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 l=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((c,u)=>{s(c),typeof l=="function"&&l(c,u)})},onUnhandledRejection(s){}}}function Ne(n={}){let{getPage:t,...e}=n;return oe({...e,adapter:ie({getPage:t})})}0&&(module.exports={createReactNativeAdapter,initRN});
@@ -1 +1,3 @@
1
- import{a as c,d as f}from"../chunk-SOQF2GQO.mjs";import{Platform as r}from"react-native";import p from"@react-native-async-storage/async-storage";var O="uni-log:pending",s="uni-log:did";function y(i={}){let o=new Map,n,u=(async()=>{try{for(let e of[O,s]){let a=await p.getItem(e);a!=null&&o.set(e,a)}let t=o.get(s);t&&(n=t)}catch{}})(),l=t=>{var e;return(e=o.get(t))!=null?e:null},d=(t,e)=>{o.set(t,e),p.setItem(t,e).catch(()=>{})},m=()=>{var t;return n||(n=(t=l(s))!=null?t:void 0,n||(n=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,d(s,n))),n};return{ready:u,request:c,getStorage:t=>l(t),setStorage:(t,e)=>d(t,e),getDeviceInfo(){return{deviceId:m(),platform:r.OS==="ios"?"ios":r.OS==="android"?"android":r.OS,osName:r.OS,os:String(r.Version),osVersion:String(r.Version)}},getCurrentPage:()=>{var t,e;return(e=(t=i.getPage)==null?void 0:t.call(i))!=null?e:null},getPlatformVersion:()=>null,onError(t){let e=globalThis.ErrorUtils;if(typeof(e==null?void 0:e.setGlobalHandler)!="function")return;let a=typeof e.getGlobalHandler=="function"?e.getGlobalHandler():void 0;e.setGlobalHandler((g,v)=>{t(g),typeof a=="function"&&a(g,v)})},onUnhandledRejection(t){}}}function D(i={}){let{getPage:o,...n}=i;return f({...n,adapter:y({getPage:o})})}export{y as createReactNativeAdapter,D as initRN};
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(h=>{"use strict";Object.defineProperty(h,"__esModule",{value:!0});h.PROTOCOL_LIMITS=h.SIGNATURE_MAX_SKEW_MS=h.SIGNATURE_HEADERS=h.INGEST_PATH=h.LOG_LEVELS=void 0;h.LOG_LEVELS=["debug","info","warn","error","crash"];h.INGEST_PATH="/ingest/v1/logs";h.SIGNATURE_HEADERS={ts:"x-uni-log-ts",nonce:"x-uni-log-nonce",sign:"x-uni-log-sign"};h.SIGNATURE_MAX_SKEW_MS=300*1e3;h.PROTOCOL_LIMITS={maxBatch:50,maxMsgLength:4e3,maxStackLength:8e3,maxEventsPerBatch:50,maxEventKeyLength:64,maxEventValLength:255,maxBodyBytes:512*1024}});var X=K(P=>{"use strict";var he=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)&&he(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 pe(){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: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 T(){let n=globalThis;return typeof n!="undefined"&&n.uni?L():C()}var p=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,v,I,m,b,w,R]=t;for(let g=0;g<64;g++){let y=x(m,6)^x(m,11)^x(m,25),k=m&b^~m&w,O=R+y+k+ye[g]+s[g]>>>0,_=x(c,2)^x(c,13)^x(c,22),D=c&u^c&v^u&v,re=_+D>>>0;R=w,w=b,b=m,m=I+O>>>0,I=v,v=u,u=c,c=O+re>>>0}t[0]=t[0]+c>>>0,t[1]=t[1]+u>>>0,t[2]=t[2]+v>>>0,t[3]=t[3]+I>>>0,t[4]=t[4]+m>>>0,t[5]=t[5]+b>>>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 E="uni-log:pending",Z=20,ve="0.2.2";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 be(n,t,e){var o;let r={t:Date.now(),lv:n,msg:A(t||"(empty)",p.PROTOCOL_LIMITS.maxMsgLength)};return e!=null&&e.stack&&(r.stack=A(e.stack,p.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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}log(t,e,r){if(!this.ready)return;let o=p.LOG_LEVELS.includes(t)?t:"info";this.samplePage();let i=this.adapter.getCurrentPage();this.logs.push(be(o,e,{...r,...i?{page:i}:{}})),this.logs.length>=p.PROTOCOL_LIMITS.maxBatch&&this.flush()}report(t,e){if(!this.ready||!t||t.length>p.PROTOCOL_LIMITS.maxEventKeyLength)return;this.samplePage();let r={t:Date.now(),ev:t};e&&(r.val=A(e,p.PROTOCOL_LIMITS.maxEventValLength));let o=this.adapter.getCurrentPage();o&&(r.page=o),this.events.push(r),this.events.length>=p.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,v,I,m,b,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:(v=e==null?void 0:e.deviceId)!=null?v: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:(b=(m=this.options).getNet)!=null&&b.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: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,p.PROTOCOL_LIMITS.maxBatch),...this.events.length?{events:this.events.splice(0,p.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[p.SIGNATURE_HEADERS.ts]=c,l[p.SIGNATURE_HEADERS.nonce]=u,l[p.SIGNATURE_HEADERS.sign]=Q(this.options.appSecret,`${c}
2
+ ${u}
3
+ ${a}`)}o=(s=this.adapter.request({url:`${this.options.serverUrl}${p.INGEST_PATH}`,data:a,header:l,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?s:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let d={};for(let s of Object.keys(i))d[s]=r(i[s]);return d}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(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(Ie).join(" ")),i(...d)},ee.add(e)}}function Ie(n){if(typeof n=="string")return n;if(n instanceof Error)return n.stack||n.message;try{let t=JSON.stringify(n);return t===void 0?String(n):t}catch{return String(n)}}import{Platform as N}from"react-native";import ne from"@react-native-async-storage/async-storage";var Re="uni-log:pending",H="uni-log:did";function ke(n={}){let t=new Map,e,r=(async()=>{try{for(let a of[Re,H]){let l=await ne.getItem(a);l!=null&&t.set(a,l)}let s=t.get(H);s&&(e=s)}catch{}})(),o=s=>{var a;return(a=t.get(s))!=null?a:null},i=(s,a)=>{t.set(s,a),ne.setItem(s,a).catch(()=>{})},d=()=>{var s;return e||(e=(s=o(H))!=null?s:void 0,e||(e=`did-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,i(H,e))),e};return{ready:r,request:U,getStorage:s=>o(s),setStorage:(s,a)=>i(s,a),getDeviceInfo(){return{deviceId:d(),platform:N.OS==="ios"?"ios":N.OS==="android"?"android":N.OS,osName:N.OS,os:String(N.Version),osVersion:String(N.Version)}},getCurrentPage:()=>{var s,a;return(a=(s=n.getPage)==null?void 0:s.call(n))!=null?a:null},getPlatformVersion:()=>null,onError(s){let a=globalThis.ErrorUtils;if(typeof(a==null?void 0:a.setGlobalHandler)!="function")return;let l=typeof a.getGlobalHandler=="function"?a.getGlobalHandler():void 0;a.setGlobalHandler((c,u)=>{s(c),typeof l=="function"&&l(c,u)})},onUnhandledRejection(s){}}}function Ze(n={}){let{getPage:t,...e}=n;return te({...e,adapter:ke({getPage:t})})}export{ke 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 Ne={};ce(Ne,{createBrowserAdapter:()=>_,detectAdapter:()=>O,flush:()=>Le,getClient:()=>Pe,hookConsole:()=>ne,init:()=>Se,report:()=>Ee,setConsoleReport:()=>Re,setDeviceName:()=>Ae,ulog:()=>Ie,ulogger:()=>ee});module.exports=ge(Ne);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,k=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+k>>>0}let[c,h,b,I,m,v,w,R]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),k=m&v^~m&w,L=R+x+k+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;R=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]+R>>>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.1";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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}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,R,l,x,k,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=(R=this.options).getNet)==null?void 0:l.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: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=(k=this.options).getUserId)!=null&&L.call(k)?{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 Ne={};ce(Ne,{createBrowserAdapter:()=>_,detectAdapter:()=>O,flush:()=>Le,getClient:()=>Pe,hookConsole:()=>ne,init:()=>Se,report:()=>Ee,setConsoleReport:()=>Re,setDeviceName:()=>Ae,ulog:()=>Ie,ulogger:()=>ee});module.exports=ge(Ne);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,k=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+k>>>0}let[c,h,b,I,m,v,w,R]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),k=m&v^~m&w,L=R+x+k+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;R=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]+R>>>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.2";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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}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,R,l,x,k,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=(R=this.options).getNet)==null?void 0:l.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: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=(k=this.options).getUserId)!=null&&L.call(k)?{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 Ie(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(ke).join(" ")),i(...a)},Z.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)}}function Ee(n,t){s==null||s.report(n,t)}function Ae(n){s==null||s.setDeviceName(n)}async function Le(){await(s==null?void 0:s.flush())}0&&(module.exports={createBrowserAdapter,detectAdapter,flush,getClient,hookConsole,init,report,setConsoleReport,setDeviceName,ulog,ulogger});
package/dist/index.mjs CHANGED
@@ -1 +1,3 @@
1
- import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k}from"./chunk-SOQF2GQO.mjs";export{a as createBrowserAdapter,b as detectAdapter,k as flush,d as getClient,h as hookConsole,c as init,i as report,g as setConsoleReport,j as setDeviceName,e as ulog,f as ulogger};
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,k=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+k>>>0}let[c,h,b,I,m,v,w,R]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),k=m&v^~m&w,L=R+x+k+he[l]+d[l]>>>0,_=y(c,2)^y(c,13)^y(c,22),O=c&h^c&b^h&b,ee=_+O>>>0;R=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]+R>>>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.2";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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}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,R,l,x,k,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=(R=this.options).getNet)==null?void 0:l.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: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=(k=this.options).getUserId)!=null&&L.call(k)?{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
+ ${h}
3
+ ${f}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${u.INGEST_PATH}`,data:f,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(E),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>z&&(r=r.slice(-z));try{this.adapter.setStorage(E,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(E);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(E,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(E,"");return}this.adapter.setStorage(E,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function je(n){var t;return s==null||s.stop(),s=new U(n,(t=n.adapter)!=null?t:D()),s.start(),n.hookConsole!==!1&&be(),s}function qe(){return s}function Ge(n,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 We(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 Ke(n,t){s==null||s.report(n,t)}function $e(n){s==null||s.setDeviceName(n)}async function Je(){await(s==null?void 0:s.flush())}export{C as createBrowserAdapter,D as detectAdapter,Je as flush,qe as getClient,be as hookConsole,je as init,Ke as report,We as setConsoleReport,$e as setDeviceName,Ge as ulog,ye as ulogger};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-log-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "private": false,
5
5
  "description": "uni-app / uni-app x 日志上报 SDK:console、JS 错误、自定义事件与设备信息批量上报",
6
6
  "keywords": [
@@ -1 +1,3 @@
1
- import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k}from"./chunk-SOQF2GQO.mjs";export{a as createBrowserAdapter,b as detectAdapter,k as flush,d as getClient,h as hookConsole,c as init,i as report,g as setConsoleReport,j as setDeviceName,e as ulog,f as ulogger};
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,k=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+k>>>0}let[c,h,b,I,m,v,w,R]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),k=m&v^~m&w,L=R+x+k+he[l]+d[l]>>>0,_=y(c,2)^y(c,13)^y(c,22),O=c&h^c&b^h&b,ee=_+O>>>0;R=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]+R>>>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.2";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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}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,R,l,x,k,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=(R=this.options).getNet)==null?void 0:l.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: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=(k=this.options).getUserId)!=null&&L.call(k)?{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
+ ${h}
3
+ ${f}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${u.INGEST_PATH}`,data:f,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(E),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>z&&(r=r.slice(-z));try{this.adapter.setStorage(E,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(E);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(E,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(E,"");return}this.adapter.setStorage(E,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function je(n){var t;return s==null||s.stop(),s=new U(n,(t=n.adapter)!=null?t:D()),s.start(),n.hookConsole!==!1&&be(),s}function qe(){return s}function Ge(n,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 We(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 Ke(n,t){s==null||s.report(n,t)}function $e(n){s==null||s.setDeviceName(n)}async function Je(){await(s==null?void 0:s.flush())}export{C as createBrowserAdapter,D as detectAdapter,Je as flush,qe as getClient,be as hookConsole,je as init,Ke as report,We as setConsoleReport,$e as setDeviceName,Ge as ulog,ye as ulogger};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "uni-log",
3
3
  "displayName": "uni-log 日志上报",
4
- "version": "0.2.1",
4
+ "version": "0.2.2",
5
5
  "description": "uni-app / uni-app x 日志上报 SDK:console、JS 错误、自定义事件与设备信息批量上报",
6
6
  "keywords": [
7
7
  "uni-app",
@@ -1,3 +0,0 @@
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,k=y(d[l-2],17)^y(d[l-2],19)^d[l-2]>>>10;d[l]=d[l-16]+x+d[l-7]+k>>>0}let[c,h,b,I,m,v,w,R]=t;for(let l=0;l<64;l++){let x=y(m,6)^y(m,11)^y(m,25),k=m&v^~m&w,L=R+x+k+he[l]+d[l]>>>0,_=y(c,2)^y(c,13)^y(c,22),O=c&h^c&b^h&b,ee=_+O>>>0;R=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]+R>>>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.1";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.options=t,this.adapter=e,this.sessionId=`sess-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}start(){var e,r;if(this.ready)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.installErrorHooks(),this.samplePage()}stop(){this.ready=!1,this.timer&&(clearInterval(this.timer),this.timer=null)}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,R,l,x,k,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=(R=this.options).getNet)==null?void 0:l.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: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=(k=this.options).getUserId)!=null&&L.call(k)?{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
- ${h}
3
- ${f}`)}o=(d=this.adapter.request({url:`${this.options.serverUrl}${u.INGEST_PATH}`,data:f,header:g,success:c=>i(!!c&&c.statusCode>=200&&c.statusCode<300),fail:()=>i(!1)}))!=null?d:void 0}catch{i(!1)}})}safeStringify(t){var o;let e=new Set,r=i=>{if(typeof i=="bigint")return i.toString();if(i!==null&&typeof i=="object"){if(e.has(i))return"[Circular]";e.add(i);try{if(Array.isArray(i))return i.map(r);let a={};for(let d of Object.keys(i))a[d]=r(i[d]);return a}finally{e.delete(i)}}return i};return(o=JSON.stringify(r(t)))!=null?o:""}persistPending(t){let e=this.adapter.getStorage(E),r=[];try{r=e?JSON.parse(e):[],Array.isArray(r)||(r=[])}catch{r=[]}r.push(...t),r.length>z&&(r=r.slice(-z));try{this.adapter.setStorage(E,this.safeStringify(r))}catch(o){this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u5931\u8D25",o)}}async retryPending(){let t=this.adapter.getStorage(E);if(!t)return;let e;try{e=JSON.parse(t)}catch{this.adapter.setStorage(E,""),this.options.debug&&console.warn("[uni-log] \u6682\u5B58\u6570\u636E\u635F\u574F\uFF0C\u5DF2\u4E22\u5F03");return}if(!Array.isArray(e)||e.length===0){this.adapter.setStorage(E,"");return}this.adapter.setStorage(E,"");for(let r=0;r<e.length;r++)if(!await this.send(e[r])){this.persistPending(e.slice(r)),this.options.debug&&console.warn("[uni-log] \u7EED\u4F20\u5931\u8D25\uFF0C\u6682\u5B58\u5DF2\u8FD8\u539F");return}}installErrorHooks(){this.adapter.onError(t=>{this.log("error",String(t),{stack:String(t)})}),this.adapter.onUnhandledRejection(t=>{var o;let e=t,r=(o=e==null?void 0:e.reason)!=null?o:t;this.log("error",String(r),{stack:r==null?void 0:r.stack})})}};var s=null;function je(n){var t;return s==null||s.stop(),s=new U(n,(t=n.adapter)!=null?t:D()),s.start(),n.hookConsole!==!1&&be(),s}function qe(){return s}function Ge(n,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 We(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 Ke(n,t){s==null||s.report(n,t)}function $e(n){s==null||s.setDeviceName(n)}async function Je(){await(s==null?void 0:s.flush())}export{G as a,C as b,D as c,je as d,qe as e,Ge as f,ye as g,We as h,be as i,Ke as j,$e as k,Je as l};