@arms/rum-core 0.0.35 → 0.0.37

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 (48) hide show
  1. package/es/index.d.ts +18 -0
  2. package/es/index.js +18 -0
  3. package/es/model/client.d.ts +21 -0
  4. package/es/model/client.js +76 -0
  5. package/es/model/context.d.ts +18 -0
  6. package/es/model/context.js +44 -0
  7. package/es/model/reporter.d.ts +31 -0
  8. package/es/model/reporter.js +196 -0
  9. package/es/model/shell.d.ts +51 -0
  10. package/es/model/shell.js +160 -0
  11. package/es/style.js +1 -0
  12. package/es/types/client.d.ts +170 -0
  13. package/es/types/client.js +7 -0
  14. package/es/types/collector.d.ts +7 -0
  15. package/es/types/collector.js +1 -0
  16. package/es/types/processor.d.ts +8 -0
  17. package/es/types/processor.js +1 -0
  18. package/es/types/reporter.d.ts +8 -0
  19. package/es/types/reporter.js +1 -0
  20. package/es/types/rum-event.d.ts +179 -0
  21. package/es/types/rum-event.js +27 -0
  22. package/es/types/shell.d.ts +28 -0
  23. package/es/types/shell.js +1 -0
  24. package/es/utils/base.d.ts +60 -0
  25. package/es/utils/base.js +216 -0
  26. package/es/utils/combineConfig.d.ts +15 -0
  27. package/es/utils/combineConfig.js +101 -0
  28. package/es/utils/exception.d.ts +7 -0
  29. package/es/utils/exception.js +10 -0
  30. package/es/utils/is.d.ts +12 -0
  31. package/es/utils/is.js +39 -0
  32. package/es/utils/match.d.ts +7 -0
  33. package/es/utils/match.js +40 -0
  34. package/es/utils/number.d.ts +17 -0
  35. package/es/utils/number.js +40 -0
  36. package/es/utils/polyfills.d.ts +7 -0
  37. package/es/utils/polyfills.js +28 -0
  38. package/es/utils/trace.d.ts +28 -0
  39. package/es/utils/trace.js +105 -0
  40. package/es/utils/verify.d.ts +2 -0
  41. package/es/utils/verify.js +35 -0
  42. package/lib/model/context.js +6 -0
  43. package/lib/types/client.d.ts +8 -0
  44. package/lib/types/rum-event.d.ts +3 -1
  45. package/lib/types/rum-event.js +1 -0
  46. package/lib/utils/base.d.ts +2 -2
  47. package/lib/utils/base.js +10 -6
  48. package/package.json +6 -2
@@ -0,0 +1,170 @@
1
+ import { ICollector } from './collector';
2
+ import { IProcessor } from './processor';
3
+ import { IReporter } from './reporter';
4
+ import { RumEvent, RumEventBundle, IViewData } from './rum-event';
5
+ import { MatchOption } from "../utils/match";
6
+ export declare enum EventType {
7
+ /**
8
+ * 收集数据
9
+ */
10
+ collect = "collect"
11
+ }
12
+ export interface IContext {
13
+ session: IRumSession;
14
+ /**
15
+ * user config
16
+ */
17
+ getConfig(): IConfiguration;
18
+ setConfig(config: IConfiguration): void;
19
+ /**
20
+ * view
21
+ */
22
+ getViews(): IViewData[];
23
+ addView(view: IViewData): void;
24
+ removeView(viewId: string): void;
25
+ /**
26
+ * event
27
+ */
28
+ getRumEvent(): RumEvent;
29
+ setRumEvent(rumEvent: RumEvent): void;
30
+ [key: string]: any;
31
+ }
32
+ export interface SessionConfig {
33
+ sampleRate?: number;
34
+ maxDuration?: number;
35
+ overtime?: number;
36
+ storage?: string;
37
+ }
38
+ export interface IRumSession {
39
+ init(ctx: IContext): void;
40
+ sessionConfig: SessionConfig;
41
+ getSessionId: () => string;
42
+ getSampled: () => boolean;
43
+ updateSession: () => void;
44
+ getEventId: () => string;
45
+ getViewId: () => string;
46
+ getUserId: () => string;
47
+ getBaseEvent: () => any;
48
+ }
49
+ export interface IClient {
50
+ /**
51
+ * 初始化
52
+ */
53
+ init: (configuration: IConfiguration, rumSession?: IRumSession) => void;
54
+ /**
55
+ * 业务自定义上传数据
56
+ */
57
+ sendEvent(payload: RumEvent): void;
58
+ /**
59
+ * 修改运行时上下文
60
+ */
61
+ setContext(ctx: IContext): void;
62
+ /**
63
+ * 获取运行时上下文
64
+ */
65
+ getContext(): IContext;
66
+ /**
67
+ * 装载 client 需要的 Collector
68
+ */
69
+ useCollectors(collectors: ICollector[]): void;
70
+ /**
71
+ * 返回装载的collector
72
+ */
73
+ getCollectors(): ICollector[];
74
+ /**
75
+ * 装载 client 需要的 processor
76
+ */
77
+ useProcessors(processors: IProcessor[]): void;
78
+ /**
79
+ * 装载 client 需要的 report
80
+ */
81
+ useReporter(reporter: IReporter): void;
82
+ }
83
+ export interface IConfiguration {
84
+ /**
85
+ * 项目 id
86
+ */
87
+ pid: string;
88
+ /**
89
+ * 应用环境
90
+ */
91
+ env?: 'prod' | 'gray' | 'pre' | 'daily' | 'local';
92
+ /**
93
+ * 应用版本
94
+ */
95
+ version?: string;
96
+ /**
97
+ * 应用配置
98
+ */
99
+ app?: {
100
+ id?: string;
101
+ name?: string;
102
+ version?: string;
103
+ channel?: string;
104
+ env?: string;
105
+ type?: string;
106
+ package?: string;
107
+ framework?: string;
108
+ };
109
+ /**
110
+ * 用户配置
111
+ */
112
+ user?: {
113
+ id?: string;
114
+ tags?: string;
115
+ name?: string;
116
+ };
117
+ /**
118
+ * 上报地址
119
+ */
120
+ endpoint: string;
121
+ /**
122
+ * reporter 发送事件之前
123
+ */
124
+ beforeReport?(bundle: RumEventBundle): any;
125
+ /**
126
+ * reporter 发送节奏配置
127
+ */
128
+ reportConfig?: {
129
+ flushTime?: number;
130
+ maxEventCount?: number;
131
+ };
132
+ /**
133
+ * 配置下发
134
+ * - 运行时动态配置更新,根据端侧特点来做定制化配置
135
+ */
136
+ remoteConfig?: Boolean;
137
+ /**
138
+ * session config
139
+ */
140
+ sessionConfig?: SessionConfig;
141
+ /**
142
+ * 各个 collector config
143
+ */
144
+ collectors?: {
145
+ [key: string]: boolean;
146
+ };
147
+ /**
148
+ * 事件过滤器配置
149
+ */
150
+ filters?: {
151
+ view?: MatchOption | MatchOption[];
152
+ resource?: MatchOption | MatchOption[];
153
+ exception?: MatchOption | MatchOption[];
154
+ };
155
+ /**
156
+ * 全局自定义属性
157
+ */
158
+ properties?: {
159
+ [key: string]: number | string;
160
+ };
161
+ /**
162
+ * 检测元素是否溢出的弹性长度
163
+ */
164
+ overflowPx?: number;
165
+ /**
166
+ * 检测正则匹配内容
167
+ */
168
+ regexp?: string;
169
+ [key: string]: unknown;
170
+ }
@@ -0,0 +1,7 @@
1
+ export var EventType = /*#__PURE__*/function (EventType) {
2
+ /**
3
+ * 收集数据
4
+ */
5
+ EventType["collect"] = "collect";
6
+ return EventType;
7
+ }({});
@@ -0,0 +1,7 @@
1
+ import { IContext } from './client';
2
+ import { RumEvent } from './rum-event';
3
+ export interface ICollector {
4
+ name: string;
5
+ setup(ctx: IContext, sendEvent: (payload: RumEvent) => void): void;
6
+ destroy?(): void;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { IContext } from './client';
2
+ import { RumEvent } from './rum-event';
3
+ export interface IProcessor {
4
+ name: string;
5
+ setup?(ctx: IContext): void;
6
+ process(ctx: IContext): RumEvent;
7
+ match?(ctx: IContext): boolean;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { IContext } from './client';
2
+ import { RumEventBundle } from './rum-event';
3
+ export interface IReporter {
4
+ name: string;
5
+ init(ctx: IContext): void;
6
+ request(ctx: IContext, bundle: RumEventBundle): void;
7
+ report(ctx: IContext): void;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,179 @@
1
+ export declare enum RumEventType {
2
+ VIEW = "view",
3
+ RESOURCE = "resource",
4
+ EXCEPTION = "exception",
5
+ LONG_TASK = "longTask",
6
+ ACTION = "action",
7
+ CUSTOM = "custom",
8
+ APPLICATION = "application"
9
+ }
10
+ export interface BaseObject {
11
+ [key: string]: BaseObjectValue;
12
+ }
13
+ export interface IViewData {
14
+ id: string;
15
+ name: string;
16
+ }
17
+ export type BaseObjectPrimitiveValue = string | number | boolean | null | undefined;
18
+ export type BaseObjectValue = BaseObjectPrimitiveValue | BaseObject | BaseObjectPrimitiveValue[] | IViewData;
19
+ export interface RumBaseEvent extends BaseObject {
20
+ event_type?: RumEventType;
21
+ event_id?: string;
22
+ session_id?: string;
23
+ timestamp?: number;
24
+ times?: number;
25
+ view?: IViewData;
26
+ snapshots?: string;
27
+ properties?: BaseObject;
28
+ }
29
+ export interface RumViewEvent extends RumBaseEvent {
30
+ loading_type?: 'initial_load' | 'route_change';
31
+ type: 'pv' | 'perf' | 'webvitals' | 'custom';
32
+ largest_contentful_paint?: number;
33
+ first_input_delay?: number;
34
+ cumulative_layout_shift?: number;
35
+ first_input_time?: number;
36
+ loading_time?: number;
37
+ first_paint?: number;
38
+ first_contentful_paint?: number;
39
+ dom_interactive?: number;
40
+ dom_content_loaded?: number;
41
+ dom_complete?: number;
42
+ load_event?: number;
43
+ t1?: number;
44
+ t2?: number;
45
+ t3?: number;
46
+ referrer?: string;
47
+ url?: string;
48
+ timing_data?: string;
49
+ }
50
+ /**
51
+ * 枚举值,表示资源是否加载成功
52
+ */
53
+ export declare enum ResourceStatus {
54
+ Unknown = -1,
55
+ Failed = 0,
56
+ Success = 1
57
+ }
58
+ export interface RumResourceEvent extends RumBaseEvent {
59
+ name?: string;
60
+ type?: string;
61
+ method?: string;
62
+ status_code?: number | string;
63
+ message?: string;
64
+ success?: -1 | 0 | 1 | ResourceStatus;
65
+ trace_id?: string;
66
+ duration?: number;
67
+ size?: number;
68
+ connect_duration?: number;
69
+ ssl_duration?: number;
70
+ dns_duration?: number;
71
+ redirect_duration?: number;
72
+ first_byte_duration?: number;
73
+ download_duration?: number;
74
+ url?: string;
75
+ timing_data?: string;
76
+ tracing_data?: string;
77
+ }
78
+ export interface RumExceptionEvent extends RumBaseEvent {
79
+ source?: string;
80
+ type?: 'crash' | 'custom' | 'error' | 'blank';
81
+ name?: string;
82
+ message?: string;
83
+ file?: string;
84
+ stack?: string;
85
+ line?: number;
86
+ column?: number;
87
+ }
88
+ export interface RumLongTaskEvent extends RumBaseEvent {
89
+ source?: string;
90
+ type?: string;
91
+ message?: string;
92
+ duration?: number;
93
+ fps?: number;
94
+ stack?: string;
95
+ caused_by?: string;
96
+ snapshots: string;
97
+ }
98
+ export interface RumActionEvent extends RumBaseEvent {
99
+ type?: string;
100
+ name?: string;
101
+ target_name?: string;
102
+ duration?: number;
103
+ }
104
+ export interface RumCustomEvent extends RumBaseEvent {
105
+ type: string;
106
+ name: string;
107
+ group?: string;
108
+ value: number;
109
+ }
110
+ export interface RumApplicationEvent extends RumBaseEvent {
111
+ state: string;
112
+ scene: string;
113
+ duration: number;
114
+ }
115
+ export type RumEvent = RumViewEvent | RumResourceEvent | RumExceptionEvent | RumActionEvent | RumCustomEvent | RumApplicationEvent;
116
+ export declare enum AppType {
117
+ browser = "browser",
118
+ miniapp = "miniapp",
119
+ minigame = "minigame",
120
+ uniapp = "uniapp",
121
+ reactnative = "reactnative"
122
+ }
123
+ export interface RumEventBundle {
124
+ app: {
125
+ id: string;
126
+ type: AppType | string;
127
+ name?: string;
128
+ version?: string;
129
+ channel?: string;
130
+ env?: string;
131
+ package?: string;
132
+ framework?: string;
133
+ };
134
+ user: {
135
+ id: string;
136
+ name?: string;
137
+ tags?: string;
138
+ };
139
+ session: {
140
+ id: string;
141
+ };
142
+ view: {
143
+ id: string;
144
+ name: string;
145
+ };
146
+ device?: {
147
+ id?: string;
148
+ type?: string;
149
+ brand?: string;
150
+ model?: string;
151
+ name?: string;
152
+ };
153
+ os?: {
154
+ type?: string;
155
+ version?: string;
156
+ container?: string;
157
+ container_version?: string;
158
+ };
159
+ geo?: {
160
+ country?: string;
161
+ country_id?: string;
162
+ province?: string;
163
+ province_id?: string;
164
+ city?: string;
165
+ city_id?: string;
166
+ };
167
+ isp?: {
168
+ id?: string;
169
+ name?: string;
170
+ };
171
+ net?: {
172
+ model?: string;
173
+ name?: string;
174
+ ip?: string;
175
+ };
176
+ events: Array<RumEvent>;
177
+ properties?: BaseObject;
178
+ _v?: string;
179
+ }
@@ -0,0 +1,27 @@
1
+ export var RumEventType = /*#__PURE__*/function (RumEventType) {
2
+ RumEventType["VIEW"] = "view";
3
+ RumEventType["RESOURCE"] = "resource";
4
+ RumEventType["EXCEPTION"] = "exception";
5
+ RumEventType["LONG_TASK"] = "longTask";
6
+ RumEventType["ACTION"] = "action";
7
+ RumEventType["CUSTOM"] = "custom";
8
+ RumEventType["APPLICATION"] = "application";
9
+ return RumEventType;
10
+ }({});
11
+ /**
12
+ * 枚举值,表示资源是否加载成功
13
+ */
14
+ export var ResourceStatus = /*#__PURE__*/function (ResourceStatus) {
15
+ ResourceStatus[ResourceStatus["Unknown"] = -1] = "Unknown";
16
+ ResourceStatus[ResourceStatus["Failed"] = 0] = "Failed";
17
+ ResourceStatus[ResourceStatus["Success"] = 1] = "Success";
18
+ return ResourceStatus;
19
+ }({});
20
+ export var AppType = /*#__PURE__*/function (AppType) {
21
+ AppType["browser"] = "browser";
22
+ AppType["miniapp"] = "miniapp";
23
+ AppType["minigame"] = "minigame";
24
+ AppType["uniapp"] = "uniapp";
25
+ AppType["reactnative"] = "reactnative";
26
+ return AppType;
27
+ }({});
@@ -0,0 +1,28 @@
1
+ import { IConfiguration } from "./client";
2
+ import { RumEvent } from "./rum-event";
3
+ /**
4
+ * 每个 sdk shell 导出固定需要实现的基础 api
5
+ * 对外导出 shell 层, 所有 shell 层模型的 API 设计约定:
6
+ * 1. API 命名空间按照 variables / functions / events 来组织
7
+ * 2. 事件(events)的命名格式为:on[Will|Did]VerbNoun?,参考 https://code.visualstudio.com/api/references/vscode-api#events
8
+ * 3. 基于 Disposable 模式,对于事件的绑定、快捷键的绑定函数,返回值则是解绑函数
9
+ */
10
+ export interface IShell {
11
+ /**
12
+ * 初始化
13
+ */
14
+ init(configuration: IConfiguration): void;
15
+ /**
16
+ * 自定义上传数据
17
+ */
18
+ sendEvent(payload: RumEvent): void;
19
+ /**
20
+ * get config
21
+ */
22
+ getConfig(): IConfiguration;
23
+ /**
24
+ * set config
25
+ */
26
+ setConfig<T extends keyof IConfiguration>(key: T, value: IConfiguration[T]): void;
27
+ setConfig(value: IConfiguration): void;
28
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 劫持函数或原型
3
+ */
4
+ export declare function interceptFunction(target: any, name: string, callback: Function, isPrototype?: boolean): void;
5
+ /**
6
+ * 还原函数
7
+ */
8
+ export declare function restoreFunction(target: any, name: string): void;
9
+ /**
10
+ * @description: GUID v4
11
+ * @return {String}
12
+ */
13
+ export declare function generateGUID(): string;
14
+ /**
15
+ * @description: 随机生成 traceId 或 sessionId
16
+ * @return {String}
17
+ */
18
+ export declare function generateTraceId(): string;
19
+ /**
20
+ * @description: 随机生成 spanId
21
+ * @param len {number}
22
+ * @param radix {number}
23
+ * @return {String}
24
+ */
25
+ export declare function generateSpanId(len?: number, radix?: number): string;
26
+ /**
27
+ * @description: 随机生成 eventId
28
+ * @param sessionId {string} sessionId
29
+ * @return {String}
30
+ */
31
+ export declare function generateEventId(sessionId: string): string;
32
+ /**
33
+ * @desc 函数防抖
34
+ * @param func 回调函数
35
+ * @param wait 延迟执行毫秒数
36
+ */
37
+ export declare function debounce(func: Function, wait: number): () => void;
38
+ /**
39
+ * @desc 函数延迟执行
40
+ * @param func 回调函数
41
+ * @param wait 延迟执行毫秒数
42
+ */
43
+ export declare function delay(func: Function, wait: number, ...args: any[]): number;
44
+ /**
45
+ * @desc 需要严格区分object和array
46
+ * @param obj 任意对象
47
+ */
48
+ export declare function getType(obj: any): any;
49
+ /**
50
+ * @desc 将字符串转换成正则表达式
51
+ * @param str 任意字符串
52
+ * 注意,这里只支持 /xxx/ 这种格式,不支持修饰符,例如 /xxx/ig
53
+ */
54
+ export declare function transStrToReg(str: string): string | RegExp;
55
+ /**
56
+ *
57
+ * @param config 配置
58
+ * @param keys 需要转换的字段
59
+ */
60
+ export declare function toRegFormat(config: any, keys: any[]): void;