@arms/rum-browser
Advanced tools
Comparing version 0.0.27-beta.10 to 0.0.27-beta.11
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_performance=require("../../utils/performance"),_url=require("../../utils/url"),_base=require("../../utils/base"),_global=require("../../utils/global"),_api=require("../../utils/api"),PerfObserver=_global.global.PerformanceObserver,ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.entryTypes=Object.values(_api.ApiType),this.entryCacheMap={},this.ctx=void 0,this.sendEvent=void 0}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig().collectors||{};!1===c.api||(this.sendEvent=b,this.ctx=a,this.perfObserver(),this.hackXhr(),this.hackFetch())},b.perfObserver=function perfObserver(){var a=this;if((0,_rumCore.isFunction)(PerfObserver)){var b=new PerformanceObserver(function(b){var c=b.getEntries().filter(function(b){return a.entryTypes.includes(b.initiatorType)});c&&c.length&&c.forEach(function(b){var c=b.name;a.entryCacheMap[c]?a.entryCacheMap[c].push(b):a.entryCacheMap[c]=[b]})});b.observe({entryTypes:["resource"]})}},b.injectTracing=function injectTracing(a,b){var c,d=this.ctx.getConfig(),e=d.tracing,f=d.pid,g=d.version,h=void 0===g?"1.0.0":g,i=(0,_rumCore.parseTracingOptions)(e),j=i.enable,k=i.sample,l=i.propagatorTypes,m=i.allowedUrls,n=i.tracestate,o=i.baggage;if(j){m.push({match:function match(a){return /^https?:\/\/*/.test(a)&&(0,_rumCore.startsWith)(a,_global.location.origin)},propagatorTypes:l});var p=(0,_rumCore.find)(m,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(p){var q=p.propagatorTypes;0===q.length&&(q=l);// skywalking | ||
var r=!1;-1<q.indexOf("sw8")&&(q=["sw8"],r=!0);var s=this.ctx.session,t=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateTraceId)(),u=r?(0,_rumCore.generateGUID)():(0,_rumCore.generateSpanId)(),v=(0,_rumCore.performDraw)(k),w=s.getUserId(),x=s.getSessionId(),y=void 0===n||n?"rum=v2&browser&"+f+"&"+x+"&"+w:void 0,z=void 0!==o&&o?"rum=v2,appType=browser,pid="+f+",sid="+x+",uid="+w:void 0,A=(0,_rumCore.makeTracingHeaders)(t,u,v,q,{tracestate:y,baggage:z,appId:f,appVersion:h,viewName:null===(c=a.view)||void 0===c?void 0:c.name,host:_global.location.host});v&&(a.trace_id=t,a.trace_data=JSON.stringify({spanId:u,sample:k,sampled:v,headers:A})),b(A)}}// Browser 情况下一直允许同域请求的trace | ||
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!((0,_rumCore.urlMatch)(g)||"HEAD"===h)){this.apiCache={type:_api.ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},i,{url:(0,_url.fixRelativeUrl)(g),method:h})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),this.addEventListener("loadend",/*#__PURE__*/(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function a(){var e,f,g,h,i,j,k,l;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,j={name:c.apiAttr.url,entryType:_api.ApiType.XHR,duration:(0,_base.getCurrentTime)()-d.timestamp},!(0,_rumCore.isFunction)(i)){a.next=16;break}return a.prev=6,d.success===_rumCore.ResourceStatus.Failed&&(k=new Error(_api.ApiType.XHR+" error")),a.next=10,i(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=(0,_extends2["default"])({},c.apiAttr,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.delayHandle({attr:d,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=_rumCore.ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(_global.global,"fetch",function(b){return function(c,d){var e,f,g;function h(){return i.apply(this,arguments)}function i(){return i=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,g={name:o.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-o.timestamp},!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:c},d),l,m);case 6:h=b.sent,o=(0,_extends2["default"])({},o,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.delayHandle({attr:o,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),i.apply(this,arguments)}void 0===d&&(d={});var j=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),k=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听 | ||
},b.hackXhr=function hackXhr(){var a=XMLHttpRequest.prototype,b=this;(0,_rumCore.interceptFunction)(a,"open",function(a,c,d,e,f){var g=c+"",h=a.toUpperCase();if(!((0,_rumCore.urlMatch)(g)||"HEAD"===h)){this.apiCache={type:_api.ApiType.XHR,method:a,url:c,async:d,user:e,password:f,headers:{}};var i=b.ctx.session.getBaseEvent();this.apiAttr=(0,_extends2["default"])({},i,{url:(0,_url.fixRelativeUrl)(g),method:h})}}),(0,_rumCore.interceptFunction)(a,"setRequestHeader",function(a,b){this.apiCache&&(this.apiCache.headers[a]=b)}),(0,_rumCore.interceptFunction)(a,"send",function(a){var c=this;if(this.apiAttr){var d=this.apiAttr;this.apiCache.data=a,b.injectTracing(this.apiAttr,function(a){Object.keys(a).forEach(function(b){c.setRequestHeader(b,a[b])})}),this.addEventListener("loadend",/*#__PURE__*/(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function a(){var e,f,g,h,i,j,k,l;return _regenerator["default"].wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(e=c.status,f=c.statusText,g=c.response,h=b.ctx.getConfig(),i=h.evaluateApi,d.status_code=e,d.message=f,j={name:c.apiAttr.url,entryType:_api.ApiType.XHR,duration:(0,_base.getCurrentTime)()-d.timestamp},!(0,_rumCore.isFunction)(i)){a.next=16;break}return a.prev=6,d.success===_rumCore.ResourceStatus.Failed&&(k=new Error(_api.ApiType.XHR+" error")),a.next=10,i(c.apiCache,g,k);case 10:l=a.sent,c.apiAttr=d=(0,_extends2["default"])({},d,(0,_api.reviseApiAttr)(l)),a.next=16;break;case 14:a.prev=14,a.t0=a["catch"](6);case 16:b.delayHandle({attr:d,entry:j});case 17:case"end":return a.stop()}},a,null,[[6,14]])}))),this.addEventListener("error",function(){c.apiAttr.success=_rumCore.ResourceStatus.Failed})}})},b.hackFetch=function hackFetch(){var a=this;(0,_base.hackFunction)(_global.global,"fetch",function(b){return function(c,d){var e,f,g;function h(){return i.apply(this,arguments)}function i(){return i=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(){var e,f,g,h;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(e=a.ctx.getConfig(),f=e.evaluateApi,g={name:o.url,entryType:_api.ApiType.FETCH,duration:(0,_base.getCurrentTime)()-o.timestamp},!(0,_rumCore.isFunction)(f)){b.next=12;break}return b.prev=3,b.next=6,f((0,_extends2["default"])({url:c},d),l,m);case 6:h=b.sent,o=(0,_extends2["default"])({},o,(0,_api.reviseApiAttr)(h)),b.next=12;break;case 10:b.prev=10,b.t0=b["catch"](3);case 12:a.delayHandle({attr:o,entry:g});case 13:case"end":return b.stop()}},b,null,[[3,10]])})),i.apply(this,arguments)}void 0===d&&(d={});var j=c instanceof Request?c.url:(0,_rumCore.isString)(c)?c:c.toString(),k=(null===(e=d)||void 0===e||null===(f=e.method)||void 0===f?void 0:f.toUpperCase())||"GET";// method: 'HEAD' 或 mode: 'no-cors' 的请求不监听 | ||
if((0,_rumCore.urlMatch)(j)||"HEAD"===k||"no-cors"===(null===(g=d)||void 0===g?void 0:g.mode))return b.call(_global.global,c,d);var l,m,n=a.ctx.session.getBaseEvent(),o=(0,_extends2["default"])({},n,{url:(0,_url.fixRelativeUrl)(j),type:_api.ApiType.FETCH,method:k});return a.injectTracing(o,function(a){d.headers=d.headers||{},Object.keys(a).forEach(function(b){d.headers[b]=a[b]})}),b.call(_global.global,c,d).then(function(a){l=a.clone();var b=l,c=b.status,d=b.statusText;return o.status_code=c,o.message=d,h().then(),a})["catch"](function(a){throw m=a,o.message=a+"",o.success=_rumCore.ResourceStatus.Failed,h().then(),a})}})},b.delayHandle=function delayHandle(a){var b=this;(0,_rumCore.delay)(function(){b.mergeEntry(a)},200)},b.mergeEntry=function mergeEntry(a){var b=a.attr,c=a.entry;c=this.findRealEntry(c);var d=this.ctx.getConfig(),e=d.parseResourceName,f=b.url,g=b.status_code,h=b.view;b.name=(0,_url.getResourceName)(f,e);var i=(0,_performance.getResourceSuccessByCode)(g),j=(0,_performance.calcResourceTimingData)(c)||{duration:c.duration},k=(0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:f,name:(0,_url.getResourceName)(f,e),type:c.initiatorType||c.entryType,success:i},b,{timing_data:JSON.stringify(c)},j,{view:h});this.sendEvent(k)},b.findRealEntry=function findRealEntry(a){var b=a.name,c=this.entryCacheMap[b]||[],d=c.shift();return c.length||delete this.entryCacheMap[b],d||a},a}(); |
@@ -1,2 +0,2 @@ | ||
import { IContext, IReporter, IViewData, Reporter, RumEvent } from '@arms/rum-core'; | ||
import { IContext, IReporter, Reporter, RumEventBundle } from '@arms/rum-core'; | ||
/** | ||
@@ -8,4 +8,4 @@ * browser reporter | ||
init(ctx: IContext): void; | ||
request(ctx: IContext, events: RumEvent[], view: IViewData): void; | ||
request(ctx: IContext, bundle: RumEventBundle): void; | ||
} | ||
export default BrowserReporter; |
@@ -1,4 +0,3 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_global=require("../utils/global"),BrowserReporter=/*#__PURE__*/function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,b.name="browser-reporter",b}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=function init(){var a=this;_global.document.addEventListener("visibilitychange",function(){"hidden"===_global.document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b,c){var d,e=a.getConfig(),f=a.session,g=f.getSessionId();b.forEach(function(a){a.session_id===g&&delete a.session_id});var h={app:{id:e.pid,env:e.env||"prod",version:e.version,type:_rumCore.AppType.browser},user:{id:f.getUserId()},session:{id:g},view:c,net:{model:(null===(d=navigator.connection)||void 0===d?void 0:d.effectiveType)||""},events:b,_v:_global.VERSION};if(["app","user","device","os","geo","isp","net"].forEach(function(a){var b=e[a];(0,_rumCore.isObject)(b)&&Object.keys(b).forEach(function(c){var d=b[c];// user 的 id 不能被覆盖 | ||
"user"===a&&"id"===c||((0,_rumCore.isString)(d)||(0,_rumCore.isNumber)(d))&&(!(a in h)&&(h[a]={}),h[a][c]=d)})}),!("function"==typeof e.beforeReport&&(h=e.beforeReport(h),!h))){var i,j=JSON.stringify(h),k=new Blob([j]).size;if(6e4>k)try{i=navigator.sendBeacon(e.endpoint,j)}catch(a){i=!1}if(!i){var l=new XMLHttpRequest;l.open("POST",e.endpoint,!0),l.setRequestHeader("Content-Type","text/plain"),l.send(j)}}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/** | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose")),_rumCore=require("@arms/rum-core"),_global=require("../utils/global"),BrowserReporter=/*#__PURE__*/function(a){function b(){for(var b,c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return b=a.call.apply(a,[this].concat(d))||this,b.name="browser-reporter",b}(0,_inheritsLoose2["default"])(b,a);var c=b.prototype;return c.init=function init(){var a=this;_global.document.addEventListener("visibilitychange",function(){"hidden"===_global.document.visibilityState&&a.flushEventQueue()})},c.request=function request(a,b){var c,d=a.getConfig();b.app.type=_rumCore.AppType.browser,b.net.model=(null===(c=navigator.connection)||void 0===c?void 0:c.effectiveType)||"",b._v=_global.VERSION;var e,f=JSON.stringify(b),g=new Blob([f]).size;if(6e4>g)try{e=navigator.sendBeacon(d.endpoint,f)}catch(a){e=!1}if(!e){var h=new XMLHttpRequest;h.open("POST",d.endpoint,!0),h.setRequestHeader("Content-Type","text/plain"),h.send(f)}},b}(_rumCore.Reporter),_default=exports["default"]=BrowserReporter;/** | ||
* browser reporter | ||
*/ |
@@ -1,2 +0,2 @@ | ||
import { IViewData, ResourceStatus } from "@arms/rum-core"; | ||
import { IViewData, ResourceStatus, BaseObject } from "@arms/rum-core"; | ||
export declare const ApiType: { | ||
@@ -20,2 +20,3 @@ XHR: string; | ||
trace_data?: string; | ||
attributes?: BaseObject; | ||
} | ||
@@ -22,0 +23,0 @@ export interface IApiCache { |
@@ -1,1 +0,1 @@ | ||
"use strict";exports.__esModule=!0,exports.ApiType=void 0,exports.reviseApiAttr=reviseApiAttr;var _rumCore=require("@arms/rum-core"),ApiType=exports.ApiType={XHR:"xmlhttprequest",FETCH:"fetch"};function reviseApiAttr(a){if((0,_rumCore.isObject)(a)){var b={};return(0,_rumCore.isString)(a.name)&&(b.name=a.name.substring(0,1e3)),(0,_rumCore.isString)(a.message)&&(b.message=a.message.substring(0,1e3)),(0,_rumCore.isNumber)(a.success)&&-1<=a.success&&1>=a.success&&(b.success=a.success),(0,_rumCore.isNumber)(a.duration)&&0<=a.duration&&(b.duration=a.duration),(0,_rumCore.isString)(a.status_code)&&(b.status_code=a.status_code.substring(0,100)),(0,_rumCore.isNumber)(a.status_code)&&(b.status_code=a.status_code),(0,_rumCore.isString)(a.snapshots)&&(b.snapshots=a.snapshots.substring(0,5e3)),(0,_rumCore.isString)(a.trace_id)&&(b.trace_id=a.trace_id.substring(0,100)),b}} | ||
"use strict";exports.__esModule=!0,exports.ApiType=void 0,exports.reviseApiAttr=reviseApiAttr;var _rumCore=require("@arms/rum-core"),ApiType=exports.ApiType={XHR:"xmlhttprequest",FETCH:"fetch"};function reviseApiAttr(a){if((0,_rumCore.isObject)(a)){var b={};(0,_rumCore.isString)(a.name)&&(b.name=a.name.substring(0,1e3)),(0,_rumCore.isString)(a.message)&&(b.message=a.message.substring(0,1e3)),(0,_rumCore.isNumber)(a.success)&&-1<=a.success&&1>=a.success&&(b.success=a.success),(0,_rumCore.isNumber)(a.duration)&&0<=a.duration&&(b.duration=a.duration),(0,_rumCore.isString)(a.status_code)&&(b.status_code=a.status_code.substring(0,100)),(0,_rumCore.isNumber)(a.status_code)&&(b.status_code=a.status_code),(0,_rumCore.isString)(a.snapshots)&&(b.snapshots=a.snapshots.substring(0,5e3)),(0,_rumCore.isString)(a.trace_id)&&(b.trace_id=a.trace_id.substring(0,100));var c=(0,_rumCore.verifyAttributes)(a.attributes);return c&&(b.attributes=c),b}} |
@@ -1,1 +0,1 @@ | ||
"use strict";exports.__esModule=!0,exports.location=exports.history=exports.global=exports.document=exports.VERSION=void 0;var global=exports.global=window,document=exports.document=window.document,location=exports.location=window.location,history=exports.history=window.history,VERSION=exports.VERSION='0.0.27-beta.10'; | ||
"use strict";exports.__esModule=!0,exports.location=exports.history=exports.global=exports.document=exports.VERSION=void 0;var global=exports.global=window,document=exports.document=window.document,location=exports.location=window.location,history=exports.history=window.history,VERSION=exports.VERSION='0.0.27-beta.11'; |
import { IContext, SessionConfig, IRumSession, RumEvent } from "@arms/rum-core"; | ||
import { IBrowserConfig } from "../types/client"; | ||
interface SessionInfo { | ||
@@ -13,3 +12,3 @@ sessionId: string; | ||
sessionConfig: SessionConfig; | ||
init(config: IBrowserConfig): void; | ||
init(ctx: IContext): void; | ||
getSessionId(): string; | ||
@@ -16,0 +15,0 @@ getSampled(): boolean; |
@@ -1,2 +0,2 @@ | ||
"use strict";exports.__esModule=!0,exports.RumSession=void 0;var _rumCore=require("@arms/rum-core"),_base=require("./base"),_view=require("./view"),_cookie=require("./cookie"),USER_ID="_arms_uid",RUM_SESSION="_arms_session",RumSession=exports.RumSession=/*#__PURE__*/function(){function a(){this.ctx=void 0,this.sessionConfig=void 0}var b=a.prototype;return b.init=function init(a){this.sessionConfig=this.fixSessionConfig(a.sessionConfig)},b.getSessionId=function getSessionId(){return this.getSessionInfo().sessionId},b.getSampled=function getSampled(){return this.getSessionInfo().sampled},b.checkSession=function checkSession(a){var b=this.sessionConfig,c=b.overtime,d=b.maxDuration,e=(0,_base.getCurrentTime)();return!(a.startTime+d<e||a.lastTime+c<e)},b.updateSession=function updateSession(){var a=this.getSessionInfo();if(!a.isNew){var b=a.startTime,c=(0,_base.getCurrentTime)(),d=a.sampled?1:0;this.setItem(RUM_SESSION,a.sessionId+"-"+d+"-"+b+"-"+c)}},b.getSessionInfo=function getSessionInfo(){var a=(this.getItem(RUM_SESSION)||"").split("-"),b=a[0],c=a[1],d=a[2],e=a[3],f={sessionId:b,sampled:"0"!==c,startTime:parseInt(d||"")||0,lastTime:parseInt(e||"")||0};return this.checkSession(f)||(f=this.resetSession()),f},b.getEventId=function getEventId(){return(0,_rumCore.generateEventId)(this.getSessionId())},b.getViewId=function getViewId(){return this.getUUID()},b.getUserId=function getUserId(){var a=this.getItem(USER_ID);return a&&0===a.indexOf("user_")&&(a=""),a||(a="uid_"+(0,_rumCore.generateSpanId)(16,36),this.setItem(USER_ID,a)),a},b.resetSession=function resetSession(){var a=this.sessionConfig.sampleRate,b=this.getUUID(),c=(0,_base.getCurrentTime)(),d=(0,_rumCore.performDraw)(100*a),e=b+"-"+(d?1:0)+"-"+c+"-"+c;return this.setItem(RUM_SESSION,e),{sessionId:b,sampled:d,startTime:c,lastTime:c,isNew:!0}},b.getUUID=function getUUID(){return(0,_rumCore.generateGUID)().replace(/-/g,"")},b.fixSessionConfig=function fixSessionConfig(a){void 0===a&&(a={});var b=a,c=b.sampleRate,d=b.maxDuration,e=b.overtime,f=b.storage;return(!(0,_rumCore.isNumber)(c)||0>c||1<c)&&(c=1),(!(0,_rumCore.isNumber)(d)||d<4*_rumCore.ONE_HOUR||d>_rumCore.ONE_DAY)&&(d=_rumCore.ONE_DAY),(!(0,_rumCore.isNumber)(e)||e>_rumCore.ONE_HOUR||e<10*_rumCore.ONE_MINUTE)&&(e=30*_rumCore.ONE_MINUTE),"cookie"!==f&&(f="localStorage"),{sampleRate:c,maxDuration:d,overtime:e,storage:f}},b.getBaseEvent=function getBaseEvent(){var a={timestamp:(0,_base.getCurrentTime)(),session_id:this.getSessionId(),event_id:this.getEventId(),view:this.ctx?(0,_view.getCurView)(this.ctx):void 0,times:1};return a},b.setItem=function setItem(a,b){"cookie"===this.sessionConfig.storage?(0,_cookie.setCookie)(a,b,365*_rumCore.ONE_DAY):localStorage.setItem(a,b)},b.getItem=function getItem(a){return"cookie"===this.sessionConfig.storage?(0,_cookie.getCookie)(a):void localStorage.getItem(a)},a}();// 存储userID的键名 | ||
"use strict";exports.__esModule=!0,exports.RumSession=void 0;var _rumCore=require("@arms/rum-core"),_base=require("./base"),_view=require("./view"),_cookie=require("./cookie"),USER_ID="_arms_uid",RUM_SESSION="_arms_session",RumSession=exports.RumSession=/*#__PURE__*/function(){function a(){this.ctx=void 0,this.sessionConfig=void 0}var b=a.prototype;return b.init=function init(a){var b;this.ctx=a,this.sessionConfig=this.fixSessionConfig(null===(b=a.config)||void 0===b?void 0:b.sessionConfig)},b.getSessionId=function getSessionId(){return this.getSessionInfo().sessionId},b.getSampled=function getSampled(){return this.getSessionInfo().sampled},b.checkSession=function checkSession(a){var b=this.sessionConfig,c=b.overtime,d=b.maxDuration,e=(0,_base.getCurrentTime)();return!(a.startTime+d<e||a.lastTime+c<e)},b.updateSession=function updateSession(){var a=this.getSessionInfo();if(!a.isNew){var b=a.startTime,c=(0,_base.getCurrentTime)(),d=a.sampled?1:0;this.setItem(RUM_SESSION,a.sessionId+"-"+d+"-"+b+"-"+c)}},b.getSessionInfo=function getSessionInfo(){var a=(this.getItem(RUM_SESSION)||"").split("-"),b=a[0],c=a[1],d=a[2],e=a[3],f={sessionId:b,sampled:"0"!==c,startTime:parseInt(d||"")||0,lastTime:parseInt(e||"")||0};return this.checkSession(f)||(f=this.resetSession()),f},b.getEventId=function getEventId(){return(0,_rumCore.generateEventId)(this.getSessionId())},b.getViewId=function getViewId(){return this.getUUID()},b.getUserId=function getUserId(){var a=this.getItem(USER_ID);return a&&0===a.indexOf("user_")&&(a=""),a||(a="uid_"+(0,_rumCore.generateSpanId)(16,36),this.setItem(USER_ID,a)),a},b.resetSession=function resetSession(){var a=this.sessionConfig.sampleRate,b=this.getUUID(),c=(0,_base.getCurrentTime)(),d=(0,_rumCore.performDraw)(100*a),e=b+"-"+(d?1:0)+"-"+c+"-"+c;return this.setItem(RUM_SESSION,e),{sessionId:b,sampled:d,startTime:c,lastTime:c,isNew:!0}},b.getUUID=function getUUID(){return(0,_rumCore.generateGUID)().replace(/-/g,"")},b.fixSessionConfig=function fixSessionConfig(a){void 0===a&&(a={});var b=a,c=b.sampleRate,d=b.maxDuration,e=b.overtime,f=b.storage;return(!(0,_rumCore.isNumber)(c)||0>c||1<c)&&(c=1),(!(0,_rumCore.isNumber)(d)||d<4*_rumCore.ONE_HOUR||d>_rumCore.ONE_DAY)&&(d=_rumCore.ONE_DAY),(!(0,_rumCore.isNumber)(e)||e>_rumCore.ONE_HOUR||e<10*_rumCore.ONE_MINUTE)&&(e=30*_rumCore.ONE_MINUTE),"cookie"!==f&&(f="localStorage"),{sampleRate:c,maxDuration:d,overtime:e,storage:f}},b.getBaseEvent=function getBaseEvent(){var a={timestamp:(0,_base.getCurrentTime)(),session_id:this.getSessionId(),event_id:this.getEventId(),view:this.ctx?(0,_view.getCurView)(this.ctx):void 0,times:1};return a},b.setItem=function setItem(a,b){"cookie"===this.sessionConfig.storage?(0,_cookie.setCookie)(a,b,365*_rumCore.ONE_DAY):localStorage.setItem(a,b)},b.getItem=function getItem(a){return"cookie"===this.sessionConfig.storage?(0,_cookie.getCookie)(a):void localStorage.getItem(a)},a}();// 存储userID的键名 | ||
// 存储session |
{ | ||
"name": "@arms/rum-browser", | ||
"version": "0.0.27-beta.10", | ||
"version": "0.0.27-beta.11", | ||
"description": "arms rum javascript sdk for browser", | ||
@@ -26,3 +26,3 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>", | ||
"dependencies": { | ||
"@arms/rum-core": "0.0.25-beta.19", | ||
"@arms/rum-core": "0.0.25-beta.20", | ||
"web-vitals": "3.5.2" | ||
@@ -29,0 +29,0 @@ }, |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
221616
1005
+ Added@arms/rum-core@0.0.25-beta.20(transitive)
- Removed@arms/rum-core@0.0.25-beta.19(transitive)