@arms/rum-reactnative 0.0.2-bate.1 → 0.0.2-bate.3

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/src/shell.ts DELETED
@@ -1,81 +0,0 @@
1
- import { Shell } from '@arms/rum-core';
2
- import PvCollector from './collector/view/pv';
3
- import ExceptionCollector from './collector/exception';
4
- import ApiCollector from './collector/resource/api';
5
- import DefaultProcessor from './processor/default-processor';
6
- import SessionProcessor from './processor/session-processor';
7
- import Reporter from './reporter';
8
- import { IRNConfig } from "./types/client";
9
- import { VERSION } from "./utils/platform";
10
- import { RumSession } from "./utils/session"
11
- import { startTrackingViews, stopTrackingViews} from "./utils/view"
12
- import { NavigationContainerRef } from './types'
13
-
14
- /**
15
- * 对外导出 shell 层, 所有 shell 层模型的 API 设计约定:
16
- * 1. API 命名空间按照 variables / functions / events 来组织
17
- * 2. 事件(events)的命名格式为:on[Will|Did]VerbNoun?,参考 https://code.visualstudio.com/api/references/vscode-api#events
18
- * 3. 基于 Disposable 模式,对于事件的绑定、快捷键的绑定函数,返回值则是解绑函数
19
- */
20
- export class ArmsRum extends Shell {
21
- version = VERSION;
22
-
23
- /**
24
- * 初始化
25
- */
26
- init(config: IRNConfig) {
27
- this.client.useCollectors([
28
- new PvCollector(),
29
- new ExceptionCollector(),
30
- new ApiCollector(),
31
- ]);
32
- this.client.useProcessors([
33
- new DefaultProcessor(),
34
- new SessionProcessor(),
35
- ]);
36
- this.client.useReporter(new Reporter());
37
- this.client.init(config, new RumSession());
38
- }
39
-
40
- /**
41
- * set config
42
- */
43
- setConfig<T extends keyof IRNConfig>(key: T, value: IRNConfig[T]): void;
44
- setConfig(value: IRNConfig): void;
45
- setConfig(...params: any[]): void {
46
- const ctx = this.client.getContext();
47
-
48
- if (params.length === 2) {
49
- const ctx = this.client.getContext();
50
- const oldConfig = ctx.getConfig();
51
- ctx.setConfig({
52
- ...oldConfig,
53
- [params[0]]: params[1],
54
- });
55
- } else {
56
- ctx.setConfig(params[0]);
57
- }
58
- }
59
-
60
- getLocalConfig(_duration: number, _pid: string): any {
61
- }
62
-
63
- getRemoteConfig(_url: string, _config: any): any {
64
-
65
- }
66
-
67
- storeRemoteConfig(_config: any, _pid: string): boolean {
68
- return false;
69
- }
70
-
71
- startTrackingViews(navigationRef: NavigationContainerRef | any) {
72
- if (!navigationRef) return;
73
- startTrackingViews(navigationRef);
74
- }
75
-
76
- stopTrackingViews() {
77
- stopTrackingViews();
78
- }
79
- }
80
-
81
- export default new ArmsRum();
@@ -1,32 +0,0 @@
1
- import { IConfiguration, ITracingOption } from "@arms/rum-core";
2
- import { IApiBaseAttr } from "../utils/api";
3
-
4
- export interface IPage {
5
- id: string;
6
- path?: string;
7
- name?: string;
8
- params?: object;
9
- }
10
-
11
- export interface IRNConfig extends IConfiguration{
12
-
13
- /**
14
- * view.name 解析
15
- */
16
- parseViewName?(url: string, page?: IPage): string;
17
-
18
- /**
19
- * resource.name 解析
20
- */
21
- parseResourceName?(url: string): string;
22
-
23
- /**
24
- * tracing 配置 'tracecontext' | 'b3' | 'b3multi' | 'jaeger';
25
- */
26
- tracing?: boolean | ITracingOption;
27
-
28
- /**
29
- * request 自定义解析;
30
- */
31
- evaluateApi? (request: any, response: any, error?: Error, xhr?: XMLHttpRequest): Promise<IApiBaseAttr>;
32
- }
@@ -1,159 +0,0 @@
1
- /**
2
- * This file contains copy/pastes from react-navigation types. The types have been simplified to be able to work with
3
- * both v5 and v6.
4
- * This is needed because NavigationContainerRef became NavigationContainerRef<T> in v6, and so we cannot keep compatibility
5
- * between the 2 types. Also this way we never import '@react-navigation/native-vX' in our code.
6
- */
7
-
8
- /**
9
- * Route
10
- */
11
- export declare type Route<
12
- RouteName extends string,
13
- Params extends object | undefined = object | undefined
14
- > = Readonly<{
15
- /**
16
- * Unique key for the route.
17
- */
18
- key: string;
19
- /**
20
- * User-provided name for the route.
21
- */
22
- name: RouteName;
23
- path?: string;
24
- }> &
25
- (undefined extends Params
26
- ? Readonly<{
27
- /**
28
- * Params for this route
29
- */
30
- params?: Readonly<Params>;
31
- }>
32
- : Readonly<{
33
- /**
34
- * Params for this route
35
- */
36
- params: Readonly<Params>;
37
- }>);
38
-
39
- /**
40
- * Navigation Container
41
- */
42
-
43
- export declare type NavigationContainerRef = EventConsumer<NavigationContainerEventMap> & {
44
- canGoBack(): boolean;
45
- getCurrentRoute(): Route<string> | undefined;
46
- };
47
-
48
- export declare type NavigationContainerEventMap = {
49
- /**
50
- * Event which fires when the navigation state changes.
51
- */
52
- state: {
53
- data: {
54
- /**
55
- * The updated state object after the state change.
56
- */
57
- state: any;
58
- };
59
- };
60
- /**
61
- * Event which fires when current options changes.
62
- */
63
- options: {
64
- data: {
65
- options: object;
66
- };
67
- };
68
- /**
69
- * Event which fires when an action is dispatched.
70
- * Only intended for debugging purposes, don't use it for app logic.
71
- * This event will be emitted before state changes have been applied.
72
- */
73
- __unsafe_action__: {
74
- data: {
75
- /**
76
- * The action object which was dispatched.
77
- */
78
- action: any;
79
- /**
80
- * Whether the action was a no-op, i.e. resulted any state changes.
81
- */
82
- noop: boolean;
83
- /**
84
- * Stack trace of the action, this will only be available during development.
85
- */
86
- stack: string | undefined;
87
- };
88
- };
89
- };
90
-
91
- export declare type EventConsumer<EventMap extends EventMapBase> = {
92
- /**
93
- * Subscribe to events from the parent navigator.
94
- *
95
- * @param type Type of the event (e.g. `focus`, `blur`)
96
- * @param callback Callback listener which is executed upon receiving the event.
97
- */
98
- addListener<EventName extends Extract<keyof EventMap, string>>(
99
- type: EventName,
100
- callback: (...args: any[]) => any
101
- ): () => void;
102
- removeListener<EventName extends Extract<keyof EventMap, string>>(
103
- type: EventName,
104
- callback: (...args: any[]) => any
105
- ): void;
106
- };
107
-
108
- export declare type EventMapBase = Record<
109
- string,
110
- {
111
- data?: any;
112
- canPreventDefault?: boolean;
113
- }
114
- >;
115
-
116
- /**
117
- * NavigationListener
118
- */
119
-
120
- export declare type NavigationListener = (
121
- event: EventArg<string, boolean, any>
122
- ) => void | null;
123
-
124
- export declare type EventArg<
125
- EventName extends string,
126
- CanPreventDefault extends boolean | undefined = false,
127
- Data = undefined
128
- > = {
129
- /**
130
- * Type of the event (e.g. `focus`, `blur`)
131
- */
132
- readonly type: EventName;
133
- readonly target?: string;
134
- } & (CanPreventDefault extends true
135
- ? {
136
- /**
137
- * Whether `event.preventDefault()` was called on this event object.
138
- */
139
- readonly defaultPrevented: boolean;
140
- /**
141
- * Prevent the default action which happens on this event.
142
- */
143
- preventDefault(): void;
144
- }
145
- : any) &
146
- (undefined extends Data
147
- ? {
148
- readonly data?: Readonly<Data>;
149
- }
150
- : {
151
- readonly data: Readonly<Data>;
152
- });
153
-
154
-
155
-
156
- // export type ViewNameParser = (
157
- // route: Route<string, any | undefined>,
158
- // trackedName: string
159
- // ) => string | null;
package/src/utils/api.ts DELETED
@@ -1,119 +0,0 @@
1
- import { isFunction, isNumber, isObject, isString, IViewData, ResourceStatus } from "@arms/rum-core";
2
-
3
- export interface IMeasure {
4
- [key: string]: number
5
- }
6
-
7
- export const ApiType = {
8
- FETCH: 'fetch',
9
- XHR: 'xmlhttprequest',
10
- // NativeXHR: 'fetch',
11
- }
12
-
13
- export interface IApiBaseAttr {
14
- name?: string;
15
- message?: string;
16
- success?: ResourceStatus;
17
- duration?: number;
18
- size?: number;
19
- status_code?: number | string;
20
- snapshots?: string;
21
- }
22
-
23
- export interface IApiAttr extends IApiBaseAttr {
24
- view?: IViewData;
25
- url?: string;
26
- name?: string;
27
- timestamp: number;
28
- method?: string;
29
- trace_id?: string;
30
- trace_data?: string;
31
- }
32
-
33
- export interface IApiCache {
34
- url: string | URL;
35
- method: string;
36
- type: string;
37
- async?: boolean;
38
- user?: string;
39
- password?: string;
40
- headers?: Record<string, string>;
41
- data?: any;
42
- }
43
-
44
- export interface Options {
45
- url: string;
46
- method?: string;
47
- header?: any;
48
- success?: (res: any) => void;
49
- fail?: (res: any) => void;
50
- complete?: (res: any) => void;
51
- }
52
-
53
- export function reviseApiAttr(attrs: IApiBaseAttr): IApiBaseAttr | undefined {
54
- if (!attrs || !isObject(attrs)) return;
55
- const obj: IApiBaseAttr = {};
56
- if (isString(attrs.name)) {
57
- obj['name'] = attrs.name.substring(0, 1e3);
58
- }
59
- if (isString(attrs.message)) {
60
- obj['message'] = attrs.message.substring(0, 1e3);
61
- }
62
- if ('success' in attrs) {
63
- obj['success'] = !!attrs.success ? 1 : 0;
64
- }
65
- if (isNumber(attrs.duration) && attrs.duration >= 0) {
66
- obj['duration'] = attrs.duration;
67
- }
68
- if (isString(attrs.status_code)) {
69
- obj['status_code'] = attrs.status_code.substring(0, 100);
70
- }
71
- if (isNumber(attrs.status_code)) {
72
- obj['status_code'] = attrs.status_code;
73
- }
74
- if (isString(attrs.snapshots)) {
75
- obj['snapshots'] = attrs.snapshots.substring(0, 5e3);
76
- }
77
- return obj;
78
- }
79
-
80
- /**
81
- * 根据指定 URL 获取视图的名称,默认为其 path 部分
82
- * @param url 需要提取路径部分的 URL
83
- * @param spaMode 页面 SPA 路由模式
84
- */
85
- export function getPathByURL(url: string) {
86
- try {
87
- const urlObj = new URL(url);
88
- return urlObj.pathname || '/';
89
- } catch (error) {
90
- return url;
91
- }
92
- }
93
-
94
- export function getResourceName(url: string, parseFunction?: (url: string) => string) {
95
- let name: string;
96
- if (parseFunction && isFunction(parseFunction)) {
97
- name = parseFunction(url);
98
- } else {
99
- name = getPathByURL(url);
100
- }
101
- return name
102
- }
103
-
104
- /**
105
- * 判断成功还是失败
106
- * @param status_code
107
- * @returns
108
- */
109
- export function getResourceSuccessByCode(status_code: number | string) {
110
- let status: ResourceStatus;
111
- const THRESHOLD = [200, 300];
112
- if (status_code) {
113
- // @ts-ignore
114
- status = status_code >= THRESHOLD[0] && status_code < THRESHOLD[1] ? ResourceStatus.Success : ResourceStatus.Failed;
115
- } else {
116
- status = ResourceStatus.Unknown;
117
- }
118
- return status;
119
- }
package/src/utils/base.ts DELETED
@@ -1,92 +0,0 @@
1
- // /**
2
- // * 保留指定位数的小数
3
- // * @param num 原数据
4
- // * @param decimal 小数位数
5
- // * @returns
6
- // */
7
- // export function formatNumber(num: number, decimal: number = 3): number {
8
- // if (!num) {
9
- // return num;
10
- // }
11
- // let str = num.toString();
12
- // const index = str.indexOf('.');
13
- // if (index !== -1) {
14
- // str = str.substring(0, decimal + index + 1);
15
- // } else {
16
- // str = str.substring(0);
17
- // }
18
- // return parseFloat(str);
19
- // }
20
-
21
- /**
22
- * 获取获取当前时间 fix Data.now() 存在的缺陷
23
- * duration方法用于计算时间跨度,由于Date.now存在bug,可能为负数,尽可能使用performance.now计算
24
- * @returns
25
- */
26
- export function getCurrentTime() {
27
- return new Date().getTime();
28
- }
29
-
30
- export function getStringSize(str: string, encode = 'utf8') {
31
- if (typeof str !== 'string') {
32
- throw new TypeError('Input must be a string');
33
- }
34
-
35
- const encoding = encode.toLowerCase();
36
-
37
- if (encoding === 'utf16') {
38
- let bytes = 0;
39
- for (let i = 0; i < str.length; i++) {
40
- const code = str.charCodeAt(i);
41
-
42
- // 检查代理对(有效的高位代理后跟低位代理)
43
- if (code >= 0xD800 && code <= 0xDBFF) {
44
- if (i + 1 < str.length) {
45
- const nextCode = str.charCodeAt(i + 1);
46
- if (nextCode >= 0xDC00 && nextCode <= 0xDFFF) {
47
- bytes += 4; // 有效的代理对(4字节)
48
- i++; // 跳过低位代理
49
- continue;
50
- }
51
- }
52
- }
53
- bytes += 2; // 基本字符或无效代理(2字节)
54
- }
55
- return bytes;
56
- }
57
-
58
- if (encoding === 'utf8') {
59
- let totalBytes = 0;
60
- for (let i = 0; i < str.length; i++) {
61
- let code = str.charCodeAt(i);
62
-
63
- // 处理代理对(UTF-16辅助平面)
64
- if (code >= 0xD800 && code <= 0xDBFF) {
65
- if (i + 1 < str.length) {
66
- const nextCode = str.charCodeAt(i + 1);
67
- if (nextCode >= 0xDC00 && nextCode <= 0xDFFF) {
68
- // 计算实际的Unicode码点
69
- code = (code - 0xD800) * 0x400 + (nextCode - 0xDC00) + 0x10000;
70
- i++; // 跳过低位代理
71
- }
72
- }
73
- }
74
-
75
- // 根据码点值计算UTF-8字节长度
76
- if (code <= 0x7F) {
77
- totalBytes += 1; // ASCII字符(1字节)
78
- } else if (code <= 0x7FF) {
79
- totalBytes += 2; // 拉丁文补充等(2字节)
80
- } else if (code <= 0xFFFF) {
81
- totalBytes += 3; // 基本多语言平面(3字节)
82
- } else if (code <= 0x10FFFF) {
83
- totalBytes += 4; // 辅助平面(4字节)
84
- } else {
85
- totalBytes += 3; // 无效码点,使用替换字符长度
86
- }
87
- }
88
- return totalBytes;
89
- }
90
-
91
- throw new Error('Unsupported encoding. Use "utf8" or "utf16".');
92
- }
@@ -1,107 +0,0 @@
1
- import { AppType, RumEventBundle } from "@arms/rum-core";
2
- import AsyncStorage from '@react-native-async-storage/async-storage';
3
-
4
- // declare var __VERSION__: string;
5
- // export const VERSION = __VERSION__;
6
- export const VERSION = 'test';
7
-
8
- export interface Global {
9
- ErrorUtils: {
10
- setGlobalHandler: any
11
- reportFatalError: any
12
- getGlobalHandler: any
13
- }
14
- }
15
-
16
- export declare var global: Global;
17
- declare var window: any;
18
-
19
- export const appName = 'react-native';
20
-
21
- export function getStorage(key: string) {
22
- return AsyncStorage.getItem(key)
23
- }
24
-
25
- export function setStorage(key: string, data: string) {
26
- return AsyncStorage.setItem(key, data)
27
- }
28
-
29
- // export function getNetType(): Promise<string> {
30
- // return new Promise((resolve) => {
31
- // try {
32
- // sdk.getNetworkType({
33
- // success: function (e) {
34
- // const networkType = e.networkType || e.subtype;
35
- // resolve(networkType ? networkType.toLowerCase() : undefined)
36
- // },
37
- // fail: function (res) {
38
- // resolve(undefined)
39
- // }
40
- // });
41
- // } catch (e) {
42
- // resolve(undefined)
43
- // }
44
- // })
45
- // }
46
-
47
- export const fixAttrs = function (bundle: RumEventBundle): RumEventBundle | undefined {
48
- if (!bundle) return
49
- let device = {} as any;
50
- let os = {} as any;
51
- let net = {} as any;
52
- // try {
53
- // device = {
54
- // id: DeviceInfo.getUniqueIdSync(),
55
- // type: DeviceInfo.getDeviceType(),
56
- // brand: DeviceInfo.getBrand(),
57
- // model: DeviceInfo.getModel(),
58
- // name: DeviceInfo.getDeviceNameSync(),
59
- // }
60
- //
61
- // os = {
62
- // type: DeviceInfo.getSystemName(),
63
- // version: DeviceInfo.getSystemVersion(),
64
- // container: appName,
65
- // container_version: DeviceInfo.getVersion(),
66
- // };
67
- //
68
- // net = {
69
- // // model: ,
70
- // // @ts-ignore
71
- // ip: DeviceInfo.getIpAddressSync(),
72
- // }
73
- // } catch (err) {
74
- // console.warn('[rum] react-native-device-info fail', err);
75
- // const info = Platform.constants;
76
- // const rn = info.reactNativeVersion;
77
- // os.type = info.systemName;
78
- // os.version = info.osVersion;
79
- // os.container_version = `${rn.major}.${rn.minor}.${rn.patch}`;
80
- // }
81
- // try {
82
- // const info = Platform.constants;
83
- // const rn = info.reactNativeVersion;
84
- // os.type = info.systemName;
85
- // os.version = info.osVersion;
86
- // os.container = appName;
87
- // os.container_version = `${rn.major}.${rn.minor}.${rn.patch}`;
88
- // } catch (e) {
89
- // //
90
- // }
91
- bundle.app.type = AppType.reactnative;
92
- bundle._v = VERSION;
93
- bundle.net = {
94
- ...net,
95
- ...bundle.net,
96
- }
97
- bundle.device = {
98
- ...device,
99
- ...bundle.device,
100
- }
101
- bundle.os = {
102
- ...os,
103
- ...bundle.os,
104
- }
105
- return bundle;
106
- }
107
-