@arms/rum-reactnative 0.0.2-bate.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 (108) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +37 -0
  3. package/RumSdkReactnative.podspec +21 -0
  4. package/android/build.gradle +77 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativeModule.kt +23 -0
  8. package/android/src/main/java/com/rumsdkreactnative/RumSdkReactnativePackage.kt +33 -0
  9. package/ios/RumSdkReactnative.h +5 -0
  10. package/ios/RumSdkReactnative.mm +18 -0
  11. package/lib/module/collector/action/index.js +68 -0
  12. package/lib/module/collector/action/index.js.map +1 -0
  13. package/lib/module/collector/exception/index.js +135 -0
  14. package/lib/module/collector/exception/index.js.map +1 -0
  15. package/lib/module/collector/resource/api.js +281 -0
  16. package/lib/module/collector/resource/api.js.map +1 -0
  17. package/lib/module/collector/view/perf.js +79 -0
  18. package/lib/module/collector/view/perf.js.map +1 -0
  19. package/lib/module/collector/view/pv.js +72 -0
  20. package/lib/module/collector/view/pv.js.map +1 -0
  21. package/lib/module/index.js +6 -0
  22. package/lib/module/index.js.map +1 -0
  23. package/lib/module/package.json +1 -0
  24. package/lib/module/plugin.js +39 -0
  25. package/lib/module/plugin.js.map +1 -0
  26. package/lib/module/processor/default-processor.js +22 -0
  27. package/lib/module/processor/default-processor.js.map +1 -0
  28. package/lib/module/processor/session-processor.js +20 -0
  29. package/lib/module/processor/session-processor.js.map +1 -0
  30. package/lib/module/reporter/index.js +56 -0
  31. package/lib/module/reporter/index.js.map +1 -0
  32. package/lib/module/shell.js +63 -0
  33. package/lib/module/shell.js.map +1 -0
  34. package/lib/module/types/client.js +4 -0
  35. package/lib/module/types/client.js.map +1 -0
  36. package/lib/module/types/index.js +2 -0
  37. package/lib/module/types/index.js.map +1 -0
  38. package/lib/module/utils/api.js +75 -0
  39. package/lib/module/utils/api.js.map +1 -0
  40. package/lib/module/utils/base.js +90 -0
  41. package/lib/module/utils/base.js.map +1 -0
  42. package/lib/module/utils/platform.js +95 -0
  43. package/lib/module/utils/platform.js.map +1 -0
  44. package/lib/module/utils/session.js +135 -0
  45. package/lib/module/utils/session.js.map +1 -0
  46. package/lib/module/utils/url.js +54 -0
  47. package/lib/module/utils/url.js.map +1 -0
  48. package/lib/module/utils/view.js +87 -0
  49. package/lib/module/utils/view.js.map +1 -0
  50. package/lib/typescript/package.json +1 -0
  51. package/lib/typescript/src/collector/action/index.d.ts +15 -0
  52. package/lib/typescript/src/collector/action/index.d.ts.map +1 -0
  53. package/lib/typescript/src/collector/exception/index.d.ts +25 -0
  54. package/lib/typescript/src/collector/exception/index.d.ts.map +1 -0
  55. package/lib/typescript/src/collector/resource/api.d.ts +21 -0
  56. package/lib/typescript/src/collector/resource/api.d.ts.map +1 -0
  57. package/lib/typescript/src/collector/view/perf.d.ts +1 -0
  58. package/lib/typescript/src/collector/view/perf.d.ts.map +1 -0
  59. package/lib/typescript/src/collector/view/pv.d.ts +16 -0
  60. package/lib/typescript/src/collector/view/pv.d.ts.map +1 -0
  61. package/lib/typescript/src/index.d.ts +4 -0
  62. package/lib/typescript/src/index.d.ts.map +1 -0
  63. package/lib/typescript/src/plugin.d.ts +3 -0
  64. package/lib/typescript/src/plugin.d.ts.map +1 -0
  65. package/lib/typescript/src/processor/default-processor.d.ts +6 -0
  66. package/lib/typescript/src/processor/default-processor.d.ts.map +1 -0
  67. package/lib/typescript/src/processor/session-processor.d.ts +9 -0
  68. package/lib/typescript/src/processor/session-processor.d.ts.map +1 -0
  69. package/lib/typescript/src/reporter/index.d.ts +16 -0
  70. package/lib/typescript/src/reporter/index.d.ts.map +1 -0
  71. package/lib/typescript/src/shell.d.ts +29 -0
  72. package/lib/typescript/src/shell.d.ts.map +1 -0
  73. package/lib/typescript/src/types/client.d.ts +27 -0
  74. package/lib/typescript/src/types/client.d.ts.map +1 -0
  75. package/lib/typescript/src/types/index.d.ts +118 -0
  76. package/lib/typescript/src/types/index.d.ts.map +1 -0
  77. package/lib/typescript/src/utils/api.d.ts +59 -0
  78. package/lib/typescript/src/utils/api.d.ts.map +1 -0
  79. package/lib/typescript/src/utils/base.d.ts +8 -0
  80. package/lib/typescript/src/utils/base.d.ts.map +1 -0
  81. package/lib/typescript/src/utils/platform.d.ts +15 -0
  82. package/lib/typescript/src/utils/platform.d.ts.map +1 -0
  83. package/lib/typescript/src/utils/session.d.ts +37 -0
  84. package/lib/typescript/src/utils/session.d.ts.map +1 -0
  85. package/lib/typescript/src/utils/url.d.ts +17 -0
  86. package/lib/typescript/src/utils/url.d.ts.map +1 -0
  87. package/lib/typescript/src/utils/view.d.ts +13 -0
  88. package/lib/typescript/src/utils/view.d.ts.map +1 -0
  89. package/package.json +158 -0
  90. package/src/collector/action/index.ts +67 -0
  91. package/src/collector/exception/index.ts +158 -0
  92. package/src/collector/resource/api.ts +379 -0
  93. package/src/collector/view/perf.ts +77 -0
  94. package/src/collector/view/pv.ts +73 -0
  95. package/src/index.ts +4 -0
  96. package/src/plugin.ts +41 -0
  97. package/src/processor/default-processor.ts +22 -0
  98. package/src/processor/session-processor.ts +23 -0
  99. package/src/reporter/index.ts +67 -0
  100. package/src/shell.ts +81 -0
  101. package/src/types/client.ts +32 -0
  102. package/src/types/index.ts +159 -0
  103. package/src/utils/api.ts +119 -0
  104. package/src/utils/base.ts +92 -0
  105. package/src/utils/platform.ts +107 -0
  106. package/src/utils/session.ts +168 -0
  107. package/src/utils/url.ts +53 -0
  108. package/src/utils/view.ts +93 -0
package/package.json ADDED
@@ -0,0 +1,158 @@
1
+ {
2
+ "name": "@arms/rum-reactnative",
3
+ "version": "0.0.2-bate.1",
4
+ "description": "RUM SDK For ReactNative",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "*.podspec",
22
+ "react-native.config.js",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace rum-sdk-reactnative-example",
36
+ "test": "jest",
37
+ "typecheck": "tsc",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
40
+ "prepare": "bob build",
41
+ "release": "release-it --only-version"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "author": "guangli.fj <guangli.fj@alibaba-inc.com>",
49
+ "license": "MIT",
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "devDependencies": {
54
+ "@commitlint/config-conventional": "^19.6.0",
55
+ "@eslint/compat": "^1.2.7",
56
+ "@eslint/eslintrc": "^3.3.0",
57
+ "@eslint/js": "^9.22.0",
58
+ "@evilmartians/lefthook": "^1.5.0",
59
+ "@react-native-community/cli": "15.0.0-alpha.2",
60
+ "@react-native/babel-preset": "0.79.2",
61
+ "@react-native/eslint-config": "^0.78.0",
62
+ "@release-it/conventional-changelog": "^9.0.2",
63
+ "@types/jest": "^29.5.5",
64
+ "@types/react": "^19.0.0",
65
+ "commitlint": "^19.6.1",
66
+ "del-cli": "^5.1.0",
67
+ "eslint": "^9.22.0",
68
+ "eslint-config-prettier": "^10.1.1",
69
+ "eslint-plugin-prettier": "^5.2.3",
70
+ "jest": "^29.7.0",
71
+ "prettier": "^3.0.3",
72
+ "react": "19.0.0",
73
+ "react-native": "0.79.2",
74
+ "react-native-builder-bob": "^0.40.8",
75
+ "release-it": "^17.10.0",
76
+ "turbo": "^1.10.7",
77
+ "typescript": "^5.8.3"
78
+ },
79
+ "peerDependencies": {
80
+ "@arms/rum-core": "0.0.40",
81
+ "@react-native-async-storage/async-storage": "*",
82
+ "react": "*",
83
+ "react-native": "*"
84
+ },
85
+ "workspaces": [
86
+ "example"
87
+ ],
88
+ "packageManager": "yarn@3.6.1",
89
+ "jest": {
90
+ "preset": "react-native",
91
+ "modulePathIgnorePatterns": [
92
+ "<rootDir>/example/node_modules",
93
+ "<rootDir>/lib/"
94
+ ]
95
+ },
96
+ "commitlint": {
97
+ "extends": [
98
+ "@commitlint/config-conventional"
99
+ ]
100
+ },
101
+ "release-it": {
102
+ "git": {
103
+ "commitMessage": "chore: release ${version}",
104
+ "tagName": "v${version}"
105
+ },
106
+ "npm": {
107
+ "publish": true
108
+ },
109
+ "github": {
110
+ "release": true
111
+ },
112
+ "plugins": {
113
+ "@release-it/conventional-changelog": {
114
+ "preset": {
115
+ "name": "angular"
116
+ }
117
+ }
118
+ }
119
+ },
120
+ "prettier": {
121
+ "quoteProps": "consistent",
122
+ "singleQuote": true,
123
+ "tabWidth": 2,
124
+ "trailingComma": "es5",
125
+ "useTabs": false
126
+ },
127
+ "react-native-builder-bob": {
128
+ "source": "src",
129
+ "output": "lib",
130
+ "targets": [
131
+ [
132
+ "module",
133
+ {
134
+ "esm": true
135
+ }
136
+ ],
137
+ [
138
+ "typescript",
139
+ {
140
+ "project": "tsconfig.build.json"
141
+ }
142
+ ]
143
+ ]
144
+ },
145
+ "codegenConfig": {
146
+ "name": "RumSdkReactnativeSpec",
147
+ "type": "modules",
148
+ "jsSrcsDir": "src",
149
+ "android": {
150
+ "javaPackageName": "com.rumsdkreactnative"
151
+ }
152
+ },
153
+ "create-react-native-library": {
154
+ "languages": "kotlin-objc",
155
+ "type": "turbo-module",
156
+ "version": "0.52.1"
157
+ }
158
+ }
@@ -0,0 +1,67 @@
1
+ import { ICollector, IContext, IViewData, RumActionEvent, RumEvent, RumEventType } from '@arms/rum-core';
2
+ import { getCurView } from "../../utils/view";
3
+
4
+ export default class ActionCollector implements ICollector {
5
+ name = 'action-collector';
6
+ private DELAY_TIME = 300;
7
+ ctx?: IContext;
8
+ sendEvent?: ((payload: RumEvent) => void);
9
+ events = ['tap'];
10
+ lastEvent?: RumActionEvent;
11
+ timer: any;
12
+
13
+ setup(ctx: IContext, sendEvent: (payload: RumEvent) => void) {
14
+ const { collectors = {} } = ctx.getConfig();
15
+ if (collectors.action === false) {
16
+ return;
17
+ }
18
+ this.ctx = ctx;
19
+ this.sendEvent = sendEvent;
20
+ // addPageListener('*', this.onEvent)
21
+ }
22
+
23
+ onEvent = (e: any) => {
24
+ if (e && this.events.includes(e.type) && e.target) {
25
+ const { target, currentTarget, type } = e;
26
+ const { dataset, id } = target;
27
+ if (!id) return;
28
+ if (currentTarget && id !== currentTarget.id) return;
29
+ let view: undefined | IViewData;
30
+ if (this.ctx) {
31
+ view = getCurView(this.ctx) as IViewData;
32
+ }
33
+ const event: RumActionEvent = {
34
+ event_type: RumEventType.ACTION,
35
+ type,
36
+ name: id,
37
+ snapshots: Object.keys(dataset).length
38
+ ? JSON.stringify(dataset)
39
+ : undefined,
40
+ times: 1,
41
+ view,
42
+ };
43
+ clearTimeout(this.timer);
44
+ if (this.lastEvent) {
45
+ if (this.lastEvent.name !== event.name) {
46
+ this.sendAction();
47
+ } else {
48
+ // @ts-ignore
49
+ this.lastEvent.times += 1;
50
+ }
51
+ } else {
52
+ this.lastEvent = event;
53
+ }
54
+ this.timer = setTimeout(this.sendAction, this.DELAY_TIME);
55
+ }
56
+ };
57
+
58
+ sendAction = () => {
59
+ // @ts-ignore
60
+ this.sendEvent(this.lastEvent);
61
+ this.lastEvent = undefined;
62
+ };
63
+
64
+ destroy() {
65
+ // removePageListener('*', this.onEvent);
66
+ }
67
+ }
@@ -0,0 +1,158 @@
1
+ import {
2
+ ICollector,
3
+ IContext,
4
+ isArray,
5
+ interceptFunction,
6
+ matchList,
7
+ RumEvent,
8
+ RumEventType,
9
+ } from '@arms/rum-core';
10
+
11
+ declare const console: any;
12
+ declare const ErrorUtils: any;
13
+ declare const HermesInternal: any;
14
+
15
+ export default class ExceptionCollector implements ICollector {
16
+ name = 'exception-collector';
17
+ ctx?: IContext;
18
+ sendEvent?: (payload: RumEvent) => void;
19
+
20
+ private origin = {
21
+ consoleError: console.error,
22
+ originalOnError: null,
23
+ };
24
+
25
+ setup(ctx: IContext, sendEvent: (payload: RumEvent) => void) {
26
+ this.ctx = ctx;
27
+ this.sendEvent = sendEvent;
28
+ this.hackOrigin();
29
+ }
30
+
31
+ hackOrigin() {
32
+ const self = this;
33
+ const { collectors = {} } = (this.ctx as IContext).getConfig();
34
+ if (collectors.jsError !== false) {
35
+ if (ErrorUtils) {
36
+ this.origin.originalOnError = ErrorUtils.getGlobalHandler?.();
37
+ ErrorUtils.setGlobalHandler(this.onError);
38
+ }
39
+ if (
40
+ HermesInternal?.enablePromiseRejectionTracker &&
41
+ HermesInternal?.hasPromise?.()
42
+ ) {
43
+ HermesInternal.enablePromiseRejectionTracker({
44
+ allRejections: true,
45
+ onUnhandled: this.onUnhandled,
46
+ });
47
+ }
48
+ }
49
+ if (collectors.consoleError !== false) {
50
+ interceptFunction(console, 'error', function (error: any) {
51
+ self.errorHandle(error, 'console.error');
52
+ });
53
+ }
54
+ }
55
+
56
+ onError = (e: Error | string, isFatal?: boolean) => {
57
+ if (this.origin.originalOnError) {
58
+ // @ts-ignore
59
+ this.origin.originalOnError(e, isFatal);
60
+ }
61
+ this.errorHandle(e, 'onError');
62
+ };
63
+
64
+ onUnhandled = (_id: string, error: unknown) => {
65
+ this.errorHandle(error, 'onUnhandled');
66
+ };
67
+
68
+ errorHandle = (error: any, source = '') => {
69
+ let name: string = '';
70
+ let message: string = '';
71
+ let file: string = '';
72
+ let stack: string = '';
73
+ let line: string = '';
74
+ let column: string = '';
75
+ if (error instanceof Object) {
76
+ name = error.name;
77
+ message = error.message;
78
+ file = error.filename || error.fileName;
79
+ stack = error.stack;
80
+ line = error.lineno || error.lineNumber;
81
+ column = error.colno || error.columnNumber;
82
+ } else if (typeof error === 'string') {
83
+ stack = error;
84
+ const err = this.getErrorByStack(error);
85
+ if (err) {
86
+ name = err.name;
87
+ message = err.message;
88
+ }
89
+ }
90
+ if (!name || !message || this.errorFilter(error)) {
91
+ return;
92
+ }
93
+ if (this.ctx && this.sendEvent) {
94
+ const baseRumEvent = this.ctx.session.getBaseEvent();
95
+ this.sendEvent({
96
+ ...baseRumEvent,
97
+ event_type: RumEventType.EXCEPTION,
98
+ source,
99
+ type: 'error',
100
+ name,
101
+ message,
102
+ file,
103
+ stack,
104
+ line,
105
+ column,
106
+ });
107
+ }
108
+ };
109
+
110
+ /**
111
+ * 根据stack获取Error信息
112
+ * TODO: 增加基于Stack解析filename和lineNumber的能力
113
+ * @param stack
114
+ * @returns
115
+ */
116
+ getErrorByStack(stack: string = '') {
117
+ const res = stack.split('\n');
118
+ const prefix = 'at ';
119
+ if (res.length < 2) return;
120
+ for (let i = 1; i < res.length; i++) {
121
+ const str = res[i] || '';
122
+ if (str.trim().startsWith(prefix)) {
123
+ const line = res[i - 1] || '';
124
+ const index = line.indexOf(': ');
125
+ return {
126
+ name: line.substring(0, index),
127
+ message: line.substring(index + 2),
128
+ };
129
+ }
130
+ }
131
+ return;
132
+ }
133
+
134
+ errorFilter(err: Error) {
135
+ let { exception: filters } = (this.ctx as IContext).getConfig().filters || {};
136
+ if (!filters) {
137
+ return false;
138
+ }
139
+ if (!isArray(filters)) {
140
+ filters = [filters];
141
+ }
142
+ return (
143
+ matchList(filters, err.name, true, err) ||
144
+ matchList(filters, err.message, true, err) ||
145
+ matchList(filters, err.stack || '', true, err)
146
+ );
147
+ }
148
+
149
+ destroy() {
150
+ const origin = this.origin;
151
+ if (origin.consoleError) {
152
+ console.error = origin.consoleError;
153
+ }
154
+ // if (isFunction(sdk.offError)) {
155
+ // sdk.offError(this.onError);
156
+ // }
157
+ }
158
+ }