@arms/rum-uniapp 0.0.1-beta.1

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.
Files changed (77) hide show
  1. package/README.md +15 -0
  2. package/dist/uniapp-sdk.js +1 -0
  3. package/es/collector/action/index.d.ts +14 -0
  4. package/es/collector/action/index.js +3 -0
  5. package/es/collector/exception/index.d.ts +23 -0
  6. package/es/collector/exception/index.js +7 -0
  7. package/es/collector/resource/api.d.ts +13 -0
  8. package/es/collector/resource/api.js +78 -0
  9. package/es/collector/view/perf.d.ts +10 -0
  10. package/es/collector/view/perf.js +1 -0
  11. package/es/collector/view/pv.d.ts +19 -0
  12. package/es/collector/view/pv.js +1 -0
  13. package/es/index.d.ts +3 -0
  14. package/es/index.js +1 -0
  15. package/es/processor/default-processor.d.ts +5 -0
  16. package/es/processor/default-processor.js +1 -0
  17. package/es/processor/session-processor.d.ts +8 -0
  18. package/es/processor/session-processor.js +1 -0
  19. package/es/reporter/index.d.ts +10 -0
  20. package/es/reporter/index.js +3 -0
  21. package/es/shell.d.ts +26 -0
  22. package/es/shell.js +15 -0
  23. package/es/style.js +1 -0
  24. package/es/types/client.d.ts +28 -0
  25. package/es/types/client.js +1 -0
  26. package/es/utils/api.d.ts +29 -0
  27. package/es/utils/api.js +1 -0
  28. package/es/utils/base.d.ts +13 -0
  29. package/es/utils/base.js +10 -0
  30. package/es/utils/mixin.d.ts +6 -0
  31. package/es/utils/mixin.js +1 -0
  32. package/es/utils/platform.d.ts +33 -0
  33. package/es/utils/platform.js +5 -0
  34. package/es/utils/session.d.ts +26 -0
  35. package/es/utils/session.js +3 -0
  36. package/es/utils/url.d.ts +23 -0
  37. package/es/utils/url.js +10 -0
  38. package/es/utils/view.d.ts +28 -0
  39. package/es/utils/view.js +31 -0
  40. package/lib/collector/action/index.d.ts +14 -0
  41. package/lib/collector/action/index.js +2 -0
  42. package/lib/collector/exception/index.d.ts +23 -0
  43. package/lib/collector/exception/index.js +7 -0
  44. package/lib/collector/resource/api.d.ts +13 -0
  45. package/lib/collector/resource/api.js +78 -0
  46. package/lib/collector/view/perf.d.ts +10 -0
  47. package/lib/collector/view/perf.js +1 -0
  48. package/lib/collector/view/pv.d.ts +19 -0
  49. package/lib/collector/view/pv.js +1 -0
  50. package/lib/index.d.ts +3 -0
  51. package/lib/index.js +1 -0
  52. package/lib/processor/default-processor.d.ts +5 -0
  53. package/lib/processor/default-processor.js +1 -0
  54. package/lib/processor/session-processor.d.ts +8 -0
  55. package/lib/processor/session-processor.js +1 -0
  56. package/lib/reporter/index.d.ts +10 -0
  57. package/lib/reporter/index.js +3 -0
  58. package/lib/shell.d.ts +26 -0
  59. package/lib/shell.js +15 -0
  60. package/lib/style.js +1 -0
  61. package/lib/types/client.d.ts +28 -0
  62. package/lib/types/client.js +1 -0
  63. package/lib/utils/api.d.ts +29 -0
  64. package/lib/utils/api.js +1 -0
  65. package/lib/utils/base.d.ts +13 -0
  66. package/lib/utils/base.js +10 -0
  67. package/lib/utils/mixin.d.ts +6 -0
  68. package/lib/utils/mixin.js +1 -0
  69. package/lib/utils/platform.d.ts +33 -0
  70. package/lib/utils/platform.js +5 -0
  71. package/lib/utils/session.d.ts +26 -0
  72. package/lib/utils/session.js +2 -0
  73. package/lib/utils/url.d.ts +23 -0
  74. package/lib/utils/url.js +10 -0
  75. package/lib/utils/view.d.ts +28 -0
  76. package/lib/utils/view.js +31 -0
  77. package/package.json +33 -0
@@ -0,0 +1,5 @@
1
+ "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports.fixAttrs=exports.appName=exports.VERSION=void 0,exports.getNetType=getNetType,exports.getPerformance=getPerformance,exports.getStorageSync=getStorageSync,exports.sdk=exports.global2=void 0,exports.setStorageSync=setStorageSync;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_rumCore=require("@arms/rum-core"),global2=exports.global2=global||window,VERSION=exports.VERSION='npm-0.0.1-beta.1',sdk=exports.sdk=uni,appName=exports.appName="uniapp";// export {
2
+ // // sdk: global.uni,
3
+ // appName: 'uniapp',
4
+ // }
5
+ function getStorageSync(a){return"function"==typeof sdk.getStorageSync?sdk.getStorageSync(a):void 0}function setStorageSync(a,b){return"function"==typeof sdk.setStorageSync?sdk.setStorageSync(a,b):void 0}function getPerformance(){return"performance"in global2?global2.performance:void 0}function getNetType(){return new Promise(function(a){try{sdk.getNetworkType({success:function(b){var c=b.networkType||b.subtype;a(c?c.toLowerCase():void 0)},fail:function(){a(void 0)}})}catch(b){a(void 0)}})}var fixAttrs=exports.fixAttrs=/*#__PURE__*/function(){var a=(0,_asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function b(a){var c,d,e,f,g;return _regenerator["default"].wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(a){b.next=2;break}return b.abrupt("return");case 2:return b.next=4,getNetType();case 4:return c=b.sent,a.app.type=_rumCore.AppType.uniapp,a._v=VERSION,a.net=(0,_extends2["default"])({model:c},a.net),d=sdk.getDeviceInfo()||{},e=sdk.getAppBaseInfo()||{},f={brand:d.brand,model:d.model},g={type:d.platform,version:d.system,container:appName,container_version:e.SDKVersion},a.device=(0,_extends2["default"])({},f,a.device),a.os=(0,_extends2["default"])({},g,a.os),b.abrupt("return",a);case 15:case"end":return b.stop()}},b)}));return function(){return a.apply(this,arguments)}}();
@@ -0,0 +1,26 @@
1
+ import { IContext, IRumSession, RumEvent, SessionConfig } from "@arms/rum-core";
2
+ interface SessionInfo {
3
+ sessionId: string;
4
+ sampled: boolean;
5
+ startTime: number;
6
+ lastTime: number;
7
+ isNew?: boolean;
8
+ }
9
+ export declare class RumSession implements IRumSession {
10
+ ctx: IContext;
11
+ sessionConfig: SessionConfig;
12
+ init(ctx: IContext): void;
13
+ getSessionId(): string;
14
+ getSampled(): boolean;
15
+ checkSession(info: SessionInfo): boolean;
16
+ updateSession(): void;
17
+ getSessionInfo(): SessionInfo;
18
+ getEventId(): string;
19
+ getViewId(): string;
20
+ getUserId(): any;
21
+ private resetSession;
22
+ private getUUID;
23
+ private fixSessionConfig;
24
+ getBaseEvent(): RumEvent;
25
+ }
26
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";exports.__esModule=!0,exports.RumSession=void 0;var _rumCore=require("@arms/rum-core"),_base=require("./base"),_view=require("./view"),_platform=require("./platform"),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(a){var b;this.ctx=a,this.sessionConfig=this.fixSessionConfig(null===(b=a.config)||void 0===b?void 0:b.sessionConfig)},b.getSessionId=function(){return this.getSessionInfo().sessionId},b.getSampled=function(){return this.getSessionInfo().sampled},b.checkSession=function(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(){var a=this.getSessionInfo();if(!a.isNew){var b=a.startTime,c=(0,_base.getCurrentTime)(),d=a.sampled?1:0;(0,_platform.setStorageSync)(RUM_SESSION,a.sessionId+"-"+d+"-"+b+"-"+c)}},b.getSessionInfo=function(){var a=((0,_platform.getStorageSync)(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(){return(0,_rumCore.generateEventId)(this.getSessionId())},b.getViewId=function(){return this.getUUID()},b.getUserId=function(){var a=(0,_platform.getStorageSync)(USER_ID);return a&&0===a.indexOf("user_")&&(a=""),a||(a="uid_"+(0,_rumCore.generateSpanId)(16,36),(0,_platform.setStorageSync)(USER_ID,a)),a},b.resetSession=function(){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(0,_platform.setStorageSync)(RUM_SESSION,e),{sessionId:b,sampled:d,startTime:c,lastTime:c,isNew:!0}},b.getUUID=function(){return(0,_rumCore.generateGUID)().replace(/-/g,"")},b.fixSessionConfig=function(a){void 0===a&&(a={});var b=a,c=b.sampleRate,d=b.maxDuration,e=b.overtime;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),{sampleRate:c,maxDuration:d,overtime:e}},b.getBaseEvent=function(){return{timestamp:(0,_base.getCurrentTime)(),session_id:this.getSessionId(),event_id:this.getEventId(),view:this.ctx?(0,_view.getCurView)(this.ctx):void 0,times:1}},a}();// 存储userID的键名
2
+ // 存储session
@@ -0,0 +1,23 @@
1
+ import { IContext } from "@arms/rum-core";
2
+ /**
3
+ * 根据指定 URL 获取视图的名称,默认为其path部分
4
+ * @param url 需要提取路径部分的 URL
5
+ * @param isHash 是否为 hash 模式路由的 URL
6
+ */
7
+ export declare function getPathByURL(url: string, isHash?: boolean): string;
8
+ /**
9
+ * 检查是否为上报域名
10
+ * @param ctx
11
+ * @param url 需要提取路径部分的 URL
12
+ */
13
+ export declare function isEndpoint(ctx: IContext, url: string): boolean;
14
+ export declare function getURL(url: string): {
15
+ uri: string;
16
+ protocol: string;
17
+ host: string;
18
+ hostname: string;
19
+ port: string;
20
+ pathname: string;
21
+ search: string;
22
+ hash: string;
23
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";exports.__esModule=!0,exports.getPathByURL=getPathByURL,exports.getURL=getURL,exports.isEndpoint=isEndpoint;/**
2
+ * 根据指定 URL 获取视图的名称,默认为其path部分
3
+ * @param url 需要提取路径部分的 URL
4
+ * @param isHash 是否为 hash 模式路由的 URL
5
+ */function getPathByURL(a,b){void 0===b&&(b=!1);try{var c=getURL(a);return b?c.hash:c.pathname}catch(a){return""}}/**
6
+ * 检查是否为上报域名
7
+ * @param ctx
8
+ * @param url 需要提取路径部分的 URL
9
+ */function isEndpoint(a,b){var c=a.getConfig(),d=c.endpoint;try{return getURL(b).hostname===getURL(d).hostname}catch(a){return!1}}var REGEX=/^(?:([^:\/?#]+):\/\/)?((?:([^\/?#@]*)@)?([^\/?#:]*)(?:\:(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n)*))?/i;function getURL(a){var b=decodeURIComponent(a).match(REGEX),c=(b[3]||"").split(":"),d=c.length?(b[2]||"").replace(/(.*\@)/,""):b[2];return{uri:b[0],protocol:b[1],host:d,hostname:b[4],port:b[5],pathname:b[6],search:b[7],// query: mapSearchParams(parts[7]),
10
+ hash:b[8]}}
@@ -0,0 +1,28 @@
1
+ import { IContext, IRumSession, IViewData } from '@arms/rum-core';
2
+ export interface Page {
3
+ route: string;
4
+ is: string;
5
+ getPageId: () => string;
6
+ __rum_view_id?: string;
7
+ }
8
+ export declare const PAGE_ID = "__rum_view_id";
9
+ /**
10
+ * 获取 RUM 内置的view_id标识
11
+ * @param page
12
+ * @param session
13
+ * @returns
14
+ */
15
+ export declare function getRumViewId(page: Page, session?: IRumSession): string;
16
+ /**
17
+ * 获取当前 view
18
+ * @param viewId
19
+ * @param ctx
20
+ * @returns
21
+ */
22
+ export declare function getViewById(viewId: string, ctx: IContext): IViewData;
23
+ /**
24
+ * 获取当前 view
25
+ * @param ctx
26
+ * @returns
27
+ */
28
+ export declare function getCurView(ctx: IContext): IViewData;
@@ -0,0 +1,31 @@
1
+ "use strict";exports.__esModule=!0,exports.PAGE_ID=void 0,exports.getCurView=getCurView,exports.getRumViewId=getRumViewId,exports.getViewById=getViewById;var PAGE_ID=exports.PAGE_ID="__rum_view_id";// declare var getCurrentPages: Function;
2
+ // /**
3
+ // * 获取当前 page
4
+ // * @returns
5
+ // */
6
+ // export function getCurPage() {
7
+ // // TODO: 改成从config里获取
8
+ // if (typeof getCurrentPages === 'function') {
9
+ // try {
10
+ // const pages = getCurrentPages() || [];
11
+ // return pages[pages.length - 1];
12
+ // } catch (error) {
13
+ // console.warn('[arms] error in getCurView', error);
14
+ // }
15
+ // }
16
+ // }
17
+ /**
18
+ * 获取 RUM 内置的view_id标识
19
+ * @param page
20
+ * @param session
21
+ * @returns
22
+ */function getRumViewId(a,b){return a?a[PAGE_ID]?a[PAGE_ID]:b?a[PAGE_ID]=b.getViewId():void 0:void 0}/**
23
+ * 获取当前 view
24
+ * @param viewId
25
+ * @param ctx
26
+ * @returns
27
+ */function getViewById(a,b){return a&&b?b.getViews().find(function(b){return b.id===a}):void 0}/**
28
+ * 获取当前 view
29
+ * @param ctx
30
+ * @returns
31
+ */function getCurView(a){if(a){var b=a.getViews();if(b&&b.length)return b[b.length-1]}}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@arms/rum-uniapp",
3
+ "version": "0.0.1-beta.1",
4
+ "description": "arms rum javascript sdk for uniapp native",
5
+ "author": "guangli.fj <guangli.fj@alibaba-inc.com>",
6
+ "license": "ISC",
7
+ "main": "lib/index.js",
8
+ "module": "es/index.js",
9
+ "directories": {
10
+ "lib": "lib",
11
+ "es": "es",
12
+ "test": "__tests__"
13
+ },
14
+ "files": [
15
+ "lib",
16
+ "es",
17
+ "dist"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "start": "build-scripts build --config build.dev.json",
24
+ "build": "build-scripts build --skip-demo",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "dependencies": {
28
+ "@arms/rum-core": "0.0.36"
29
+ },
30
+ "devDependencies": {
31
+ "typescript": "^4.9.4"
32
+ }
33
+ }