Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arms/rum-miniapp

Package Overview
Dependencies
Maintainers
5
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arms/rum-miniapp - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

22

lib/collector/resource/api.d.ts

@@ -1,5 +0,20 @@

import { ICollector, IContext, RumEvent } from '@arms/rum-core';
import { ICollector, IContext, ITracingHeaders, IViewData, RumEvent } from '@arms/rum-core';
interface IMeasure {
[key: string]: number;
}
interface IApiAttr {
view: IViewData;
url: string;
name?: string;
startTime: number;
method: string;
trace_id?: string;
}
interface Options {
url: string;
method?: string;
headers?: any;
success?: (res: any) => void;
fail?: (res: any) => void;
}
export default class ApiCollector implements ICollector {

@@ -14,5 +29,6 @@ name: string;

setup(ctx: IContext, sendEvent: (payload: RumEvent) => void): void;
injectTracing(apiAttr: IApiAttr, inject: (tracingHeaders: ITracingHeaders) => void): void;
hackRequest(key: any): void;
rebuildRequestOptions(options: any): any;
sendApi(resp: any, options: any, success: any, startTime: any): void;
rebuildRequestOptions(options: Options): Options;
sendApi(apiAttr: any, resp: any, success: any): void;
/**

@@ -19,0 +35,0 @@ * 解析小程序的性能数据

4

lib/collector/resource/api.js

@@ -1,3 +0,3 @@

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_platform=_interopRequireDefault(require("../../utils/platform")),_url=require("../../utils/url"),_base=require("../../utils/base"),_view=require("../../utils/view"),ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.ctx=void 0,this.sendEvent=void 0,this.origin={request:_platform["default"].request,httpRequest:_platform["default"].httpRequest}}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig(),e=d.collectors,f=void 0===e?{}:e;!1===f.api||(this.ctx=a,this.sendEvent=b,Object.keys(this.origin).forEach(function(a){return c.hackRequest(a)}))},b.hackRequest=function hackRequest(a){var b=this;a in _platform["default"]&&Object.defineProperty(_platform["default"],a,{configurable:!0,enumerable:!0,writable:!0,value:function value(){for(var c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return d[0]=b.rebuildRequestOptions(d[0]),b.origin[a].apply(this,d)}})},b.rebuildRequestOptions=function rebuildRequestOptions(a){var b=this,c=a.url,d=a.success,e=a.fail,f=(0,_base.getCurrentTime)();// SDK自己的请求不监控
if((0,_url.isEndpoint)(this.ctx,c))return a;var g=(0,_extends2["default"])({},a);return g.success=function(){for(var c=arguments.length,e=Array(c),g=0;g<c;g++)e[g]=arguments[g];b.sendApi(e[0],a,!0,f),d&&d.apply(this,e)},g.fail=function(){for(var c=arguments.length,d=Array(c),g=0;g<c;g++)d[g]=arguments[g];b.sendApi(d[0],a,!1,f),e&&e.apply(this,d)},g},b.sendApi=function sendApi(a,b,c,d){var e,f,g=(0,_view.getCurView)(this.ctx),h=a.statusCode,i=a.status,j=a.errMsg,k=a.errorMessage,l=a.message,m=a.profile,n=b.url,o=b.method,p=void 0===o?"GET":o,q=(0,_url.getPathByURL)(n),r=(0,_base.getCurrentTime)()-d;m&&(e=this.parseProfile(m),f=JSON.stringify(m)),this.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE,url:n,name:q,type:"api",method:p.toUpperCase(),status_code:i||h,message:k||j||l,view:g,success:c,duration:r},e,{times:1,timing_data:f}))}/**
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports["default"]=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_rumCore=require("@arms/rum-core"),_platform=_interopRequireDefault(require("../../utils/platform")),_url=require("../../utils/url"),_base=require("../../utils/base"),_view=require("../../utils/view"),_uuid=require("../../utils/uuid"),ApiCollector=exports["default"]=/*#__PURE__*/function(){function a(){this.name="api-collector",this.ctx=void 0,this.sendEvent=void 0,this.origin={request:_platform["default"].request,httpRequest:_platform["default"].httpRequest}}var b=a.prototype;return b.setup=function setup(a,b){var c=this,d=a.getConfig(),e=d.collectors,f=void 0===e?{}:e;!1===f.api||(this.ctx=a,this.sendEvent=b,Object.keys(this.origin).forEach(function(a){return c.hackRequest(a)}))},b.injectTracing=function injectTracing(a,b){var c=this.ctx.getConfig(),d=c.tracing,e=c.pid,f=(0,_rumCore.parseTracingOptions)(d),g=f.enable,h=f.allowedUrls,i=f.sample,j=f.tracestate;if(g){var k=(0,_rumCore.generateTraceId)(),l=(0,_rumCore.generateSpanId)(),m=(0,_rumCore.performDraw)(i),n=void 0===j||j?"rum=browser&"+e+"&"+(0,_uuid.getSessionID)():"",o=(0,_rumCore.find)(h,function(b){return(0,_rumCore.matchList)([b.match],a.url)});if(o){var p=(0,_rumCore.makeTracingHeaders)(k,l,m,o.propagatorTypes,n);a.trace_id=k,b(p)}}},b.hackRequest=function hackRequest(a){var b=this;a in _platform["default"]&&Object.defineProperty(_platform["default"],a,{configurable:!0,enumerable:!0,writable:!0,value:function value(){for(var c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return d[0]=b.rebuildRequestOptions(d[0]),b.origin[a].apply(this,d)}})},b.rebuildRequestOptions=function rebuildRequestOptions(a){var b=this,c=a.url,d=a.success,e=a.fail,f=(0,_base.getCurrentTime)();// SDK自己的请求不监控 & 过滤不需要监控的url
if((0,_url.isEndpoint)(this.ctx,c)||(0,_rumCore.urlMatch)(c))return a;var g=(0,_extends2["default"])({},a),h={view:(0,_view.getCurView)(this.ctx),startTime:f,url:c,name:(0,_url.getPathByURL)(c),method:a.method||"GET"};return this.injectTracing(h,function(a){g.headers=(0,_extends2["default"])({},g.headers,a)}),g.success=function(){for(var a=arguments.length,c=Array(a),e=0;e<a;e++)c[e]=arguments[e];b.sendApi(h,c[0],!0),d&&d.apply(this,c)},g.fail=function(){for(var a=arguments.length,c=Array(a),d=0;d<a;d++)c[d]=arguments[d];b.sendApi(h,c[0],!1),e&&e.apply(this,c)},g},b.sendApi=function sendApi(a,b,c){var d,e,f=(0,_view.getCurView)(this.ctx),g=b.statusCode,h=b.status,i=b.errMsg,j=b.errorMessage,k=b.message,l=b.profile;l&&(d=this.parseProfile(l),e=JSON.stringify(l)),this.sendEvent((0,_extends2["default"])({event_type:_rumCore.RumEventType.RESOURCE},a,{type:"api",status_code:h||g,message:j||i||k,view:f,success:c,duration:(0,_base.getCurrentTime)()-a.startTime},d,{times:1,timing_data:e}))}/**
* 解析小程序的性能数据

@@ -4,0 +4,0 @@ * 参考:https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html

@@ -1,3 +0,2 @@

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _platform=require("../../utils/platform"),_view=require("../../utils/view"),PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.perfObserver=void 0,this.observerHandler=function(b){var c=b.getEntries(),d={view:(0,_view.getCurView)(a.ctx)};if(Array.isArray(c)&&0<c.length)for(var e,f=0;f<c.length;f++)if(e=c[f],"number"==typeof e.duration)switch(e.name){case"appLaunch":case"app-click":d.launch=e.duration;break;case"firstPaint":d["first-paint"]=e.duration;break;case"firstRender":d.first_render=e.duration;break;case"firstContentfulPaint":d.first_contentful_paint=e.duration;break;case"largestContentfulPaint":d.largest_contentful_paint=e.duration;break;case"resourceTiming":case"resource-timing":d.timing_data=JSON.stringify(e);break;default:}Object.keys(d).length&&// TODO 处理性能数据
console.warn("perf-collector: ",d)}}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;if(!1!==e.perf){this.ctx=a,this.sendEvent=b;var f=(0,_platform.getPerformance)();f&&f.createObserver&&(this.perfObserver=f.createObserver(this.observerHandler),this.perfObserver.observe({entryTypes:["launch","navigation","render","paint","resource"]}))}},b.destroy=function destroy(){this.perfObserver&&this.perfObserver.disconnect()},a}();// import {addPageListener, removePageListener} from "../../utils/hackPage";
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _platform=require("../../utils/platform"),_view=require("../../utils/view"),PerfCollector=exports["default"]=/*#__PURE__*/function(){function a(){var a=this;this.name="perf-collector",this.ctx=void 0,this.sendEvent=void 0,this.perfObserver=void 0,this.observerHandler=function(b){var c=b.getEntries(),d={view:(0,_view.getCurView)(a.ctx)};if(Array.isArray(c)&&0<c.length)for(var e,f=0;f<c.length;f++)if(e=c[f],"number"==typeof e.duration)switch(e.name){case"appLaunch":case"app-click":d.launch=e.duration;break;case"firstPaint":d["first-paint"]=e.duration;break;case"firstRender":d.first_render=e.duration;break;case"firstContentfulPaint":d.first_contentful_paint=e.duration;break;case"largestContentfulPaint":d.largest_contentful_paint=e.duration;break;case"resourceTiming":case"resource-timing":d.timing_data=JSON.stringify(e);break;default:}!Object.keys(d).length}}var b=a.prototype;return b.setup=function setup(a,b){var c=a.getConfig(),d=c.collectors,e=void 0===d?{}:d;if(!1!==e.perf){this.ctx=a,this.sendEvent=b;var f=(0,_platform.getPerformance)();f&&f.createObserver&&(this.perfObserver=f.createObserver(this.observerHandler),this.perfObserver.observe({entryTypes:["launch","navigation","render","paint","resource"]}))}},b.destroy=function destroy(){this.perfObserver&&this.perfObserver.disconnect()},a}();// import {addPageListener, removePageListener} from "../../utils/hackPage";
/*

@@ -4,0 +3,0 @@ * 参考资料:

@@ -1,2 +0,2 @@

"use strict";exports.__esModule=!0,exports["default"]=void 0;var _uuid=require("../utils/uuid"),_base=require("../utils/base"),SessionProcessor=exports["default"]=/*#__PURE__*/function(){function a(){this.name="session-processor",this.lastTime=(0,_base.getCurrentTime)(),this.sessionOvertime=1800000}var b=a.prototype;return b.process=function process(a){var b=(0,_base.getCurrentTime)();// 30 分钟内不上报更新session
return b-this.lastTime>this.sessionOvertime&&((0,_uuid.setSessionID)(),this.lastTime=b),a.getRumEvent()},a}();
"use strict";exports.__esModule=!0,exports["default"]=void 0;var _uuid=require("../utils/uuid"),_base=require("../utils/base"),SessionProcessor=exports["default"]=/*#__PURE__*/function(){function a(){this.name="session-processor",this.lastTime=(0,_base.getCurrentTime)(),this.sessionOvertime=3600000}var b=a.prototype;return b.process=function process(a){var b=(0,_base.getCurrentTime)();// 30 分钟内不上报更新session
return b-this.lastTime>this.sessionOvertime&&(0,_uuid.setSessionID)(),this.lastTime=b,a.getRumEvent()},a}();

@@ -15,6 +15,6 @@ /**

* 字节跳动支持 tt.performance 但不支持now方法
* 微信、百度、字节小程序支持 window.performance.now
* 支付宝、钉钉小程序占不支持 window.performance.now
* 微信、百度、字节小程序支持 performance.now
* 支付宝、钉钉小程序占不支持 performance.now
* @returns
*/
export declare function getCurrentTime(timeOffset?: number): number;

@@ -1,2 +0,2 @@

"use strict";exports.__esModule=!0,exports.formatNumber=formatNumber,exports.getCurrentTime=getCurrentTime;/**
"use strict";var _platform=require("./platform");exports.__esModule=!0,exports.formatNumber=formatNumber,exports.getCurrentTime=getCurrentTime;/**
* 保留指定位数的小数

@@ -13,5 +13,5 @@ * @param num 原数据

* 字节跳动支持 tt.performance 但不支持now方法
* 微信、百度、字节小程序支持 window.performance.now
* 支付宝、钉钉小程序占不支持 window.performance.now
* 微信、百度、字节小程序支持 performance.now
* 支付宝、钉钉小程序占不支持 performance.now
* @returns
*/function getCurrentTime(a){var b,c;return null!==(b=performance)&&void 0!==b&&b.timeOrigin&&null!==(c=performance)&&void 0!==c&&c.now?Math.round(performance.timeOrigin+(a?a:performance.now())):Date.now()}
*/function getCurrentTime(a){var b=(0,_platform.getPerformance)();return b&&b.timeOrigin&&b.now?Math.round(b.timeOrigin+(a?a:b.now())):Date.now()}

@@ -7,3 +7,3 @@ import { IContext } from "@arms/rum-core";

*/
export declare function getPathByURL(url: string, isHash?: boolean): any;
export declare function getPathByURL(url: string, isHash?: boolean): string;
/**

@@ -15,7 +15,11 @@ * 检查是否为上报域名

export declare function isEndpoint(ctx: IContext, url: string): boolean;
/**
* @description: 获取类 URL 对象
* @param {String} url
* @return {Object} : urlObj
*/
export declare function getURL(url: any): any;
export declare function getURL(url: string): {
uri: string;
protocol: string;
host: string;
hostname: string;
port: string;
pathname: string;
search: string;
hash: string;
};

@@ -9,7 +9,18 @@ "use strict";exports.__esModule=!0,exports.getPathByURL=getPathByURL,exports.getURL=getURL,exports.isEndpoint=isEndpoint;/**

* @param url 需要提取路径部分的 URL
*/function isEndpoint(a,b){var c=a.getConfig(),d=c.endpoint;try{return getURL(b).domain===getURL(d).domain}catch(a){return!1}}/**
* @description: 获取类 URL 对象
* @param {String} url
* @return {Object} : urlObj
*/function getURL(a){if(!a)return null;var b={},c=a.length,d=a.indexOf("://");if(0>d)// url 不完整不再处理
return null;b.protocol=a.substring(0,d+1);var e=a.indexOf("#"),f=a.indexOf("?");0>e&&(e=c),b.search=a.substring(e),0>f&&(f=e),b.search=a.substring(f,e);var g=a.substring(d+3,f),h=g.indexOf("/");return 0>h&&(h=g.length),b.domain=g.substring(0,h).split(":")[0],b.pathname=g.substring(h,g.length),b}
*/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 mapSearchParams(search: string) {
// const map = {}
// if (typeof search === 'string') {
// search.split('&').forEach(function (str) {
// let values = str.split('=')
// if (map.hasOwnProperty(values[0])) {
// map[values[0]] = Array.isArray(map[values[0]]) ? map[values[0]] : [map[values[0]]]
// map[values[0]].push(values[1])
// } else {
// map[values[0]] = values[1]
// }
// })
// return map
// }
// }
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]),
hash:b[8]}}

@@ -1,2 +0,3 @@

"use strict";exports.__esModule=!0,exports.getEventId=getEventId,exports.getSessionID=getSessionID,exports.getUUID=getUUID,exports.getUserID=getUserID,exports.getViewId=getViewId,exports.setSessionID=setSessionID;var _platform=require("./platform"),_rumCore=require("@arms/rum-core"),SESSION_ID="ARMS_SESSION_ID",USER_ID="ARMS_USER_ID";// 存储sessionID的键名
"use strict";exports.__esModule=!0,exports.getEventId=getEventId,exports.getSessionID=getSessionID,exports.getUUID=getUUID,exports.getUserID=getUserID,exports.getViewId=getViewId,exports.setSessionID=setSessionID;var _platform=require("./platform"),_rumCore=require("@arms/rum-core"),SESSION_ID="_arms_sid",SESSION_ID_EXP="_arms_sid_exp",USER_ID="_arms_uid";// 存储sessionID的键名
// 存储sessionID的过期id
// 存储userID的键名

@@ -8,6 +9,6 @@ /**

* 获取唯一的sessionID
*/function getSessionID(){var a=(0,_platform.getStorageSync)(SESSION_ID);return a||(a=setSessionID()),a}/**
*/function getSessionID(){var a=(0,_platform.getStorageSync)(SESSION_ID),b=new Date((0,_platform.getStorageSync)(SESSION_ID_EXP));return a&&b.valueOf()&&!(b<new Date)||(a=setSessionID()),a}/**
* 设置唯一的sessionID
*/function setSessionID(){var a=(0,_rumCore.generateGUID)();return(0,_platform.setStorageSync)(SESSION_ID,a),a}/**
*/function setSessionID(){var a=(0,_rumCore.generateGUID)();return(0,_platform.setStorageSync)(SESSION_ID,a),(0,_platform.setStorageSync)(SESSION_ID_EXP,new Date(Date.now()+86400000).toString()),a}/**
* 获取唯一的userID
*/function getUserID(){var a=(0,_platform.getStorageSync)(USER_ID);return a||(a=getUUID("user"),(0,_platform.setStorageSync)(USER_ID,a)),a}function getEventId(){return(0,_rumCore.generateGUID)()}function getViewId(){return(0,_rumCore.generateGUID)()}
{
"name": "@arms/rum-miniapp",
"version": "0.0.2",
"version": "0.0.3",
"description": "arms rum javascript sdk for miniapp",

@@ -24,3 +24,3 @@ "author": "guangli.fj <guangli.fj@alibaba-inc.com>",

"dependencies": {
"@arms/rum-core": "^0.0.2"
"@arms/rum-core": "^0.0.5"
},

@@ -27,0 +27,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc