@quiltt/react-native 5.0.0 → 5.0.2
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/CHANGELOG.md +28 -0
- package/README.md +6 -0
- package/dist/components/index.cjs +534 -0
- package/dist/components/index.d.ts +27 -0
- package/dist/components/index.js +530 -0
- package/dist/index.cjs +76 -0
- package/dist/index.d.ts +2 -57
- package/dist/index.js +2 -792
- package/dist/providers/index.cjs +107 -0
- package/dist/providers/index.d.ts +24 -0
- package/dist/providers/index.js +100 -0
- package/dist/utils/index.cjs +221 -0
- package/dist/utils/index.d.ts +66 -0
- package/dist/utils/index.js +201 -0
- package/package.json +27 -7
- package/src/utils/error/ErrorReporter.ts +29 -80
- package/src/utils/telemetry.ts +1 -13
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import Honeybadger from '@honeybadger-io/react-native';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { getUserAgent as getUserAgent$1 } from '@quiltt/core';
|
|
5
|
+
import DeviceInfo from 'react-native-device-info';
|
|
6
|
+
|
|
7
|
+
var version = "5.0.2";
|
|
8
|
+
|
|
9
|
+
// Custom Error Reporter to avoid hooking into or colliding with a client's Honeybadger singleton
|
|
10
|
+
class ErrorReporter {
|
|
11
|
+
constructor(userAgent){
|
|
12
|
+
// Create an isolated Honeybadger instance to avoid colliding with client's singleton
|
|
13
|
+
this.client = Honeybadger.factory({
|
|
14
|
+
apiKey: process.env.HONEYBADGER_API_KEY_REACT_NATIVE || '',
|
|
15
|
+
environment: userAgent,
|
|
16
|
+
revision: version,
|
|
17
|
+
reportData: true,
|
|
18
|
+
enableUncaught: false,
|
|
19
|
+
enableUnhandledRejection: false
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async notify(error, context) {
|
|
23
|
+
if (!this.client) {
|
|
24
|
+
console.warn('ErrorReporter: Honeybadger client not initialized');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
// Set context for this error report
|
|
29
|
+
if (context) {
|
|
30
|
+
this.client.setContext(context);
|
|
31
|
+
}
|
|
32
|
+
// Notify Honeybadger
|
|
33
|
+
await this.client.notify(error);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error('ErrorReporter: Failed to send error report', err);
|
|
36
|
+
} finally{
|
|
37
|
+
// Clear context after reporting (always runs if context was set)
|
|
38
|
+
if (context) {
|
|
39
|
+
this.client.clear();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const getErrorMessage = (responseStatus, error)=>{
|
|
46
|
+
if (error) return `An error occurred while checking the Connector URL: ${error?.name} \n${error?.message}`;
|
|
47
|
+
return responseStatus ? `An error occurred loading the Connector. Response status: ${responseStatus}` : 'An error occurred while checking the Connector URL';
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Gets the React version from the runtime
|
|
52
|
+
*/ const getReactVersion = ()=>{
|
|
53
|
+
return React.version || 'unknown';
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Gets the React Native version from Platform constants
|
|
57
|
+
*/ const getReactNativeVersion = ()=>{
|
|
58
|
+
try {
|
|
59
|
+
const rnVersion = Platform.constants?.reactNativeVersion;
|
|
60
|
+
if (rnVersion) {
|
|
61
|
+
return `${rnVersion.major}.${rnVersion.minor}.${rnVersion.patch}`;
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.warn('Failed to get React Native version:', error);
|
|
65
|
+
}
|
|
66
|
+
return 'unknown';
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Gets OS information (platform and version)
|
|
70
|
+
*/ const getOSInfo = ()=>{
|
|
71
|
+
try {
|
|
72
|
+
const os = Platform.OS // 'ios' or 'android'
|
|
73
|
+
;
|
|
74
|
+
const osVersion = Platform.Version // string (iOS) or number (Android)
|
|
75
|
+
;
|
|
76
|
+
// Map platform names to correct capitalization
|
|
77
|
+
const platformNames = {
|
|
78
|
+
ios: 'iOS',
|
|
79
|
+
android: 'Android'
|
|
80
|
+
};
|
|
81
|
+
const osName = platformNames[os] || 'Unknown';
|
|
82
|
+
return `${osName}/${osVersion}`;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.warn('Failed to get OS info:', error);
|
|
85
|
+
return 'Unknown/Unknown';
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Gets device model information
|
|
90
|
+
*/ const getDeviceModel = async ()=>{
|
|
91
|
+
try {
|
|
92
|
+
const model = await DeviceInfo.getModel();
|
|
93
|
+
return model || 'Unknown';
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.warn('Failed to get device model:', error);
|
|
96
|
+
return 'Unknown';
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Generates platform information string for React Native
|
|
101
|
+
* Format: React/<version>; ReactNative/<version>; <OS>/<version>; <device-model>
|
|
102
|
+
*/ const getPlatformInfo = async ()=>{
|
|
103
|
+
const reactVersion = getReactVersion();
|
|
104
|
+
const rnVersion = getReactNativeVersion();
|
|
105
|
+
const osInfo = getOSInfo();
|
|
106
|
+
const deviceModel = await getDeviceModel();
|
|
107
|
+
return `React/${reactVersion}; ReactNative/${rnVersion}; ${osInfo}; ${deviceModel}`;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Synchronously generates platform information string for React Native
|
|
111
|
+
* Format: React/<version>; ReactNative/<version>; <OS>/<version>; Unknown
|
|
112
|
+
* Note: Device model is set to 'Unknown' since it requires async DeviceInfo call
|
|
113
|
+
*/ const getPlatformInfoSync = ()=>{
|
|
114
|
+
const reactVersion = getReactVersion();
|
|
115
|
+
const rnVersion = getReactNativeVersion();
|
|
116
|
+
const osInfo = getOSInfo();
|
|
117
|
+
return `React/${reactVersion}; ReactNative/${rnVersion}; ${osInfo}; Unknown`;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Generates User-Agent string for React Native SDK
|
|
121
|
+
* Format: Quiltt/<sdk-version> (React/<version>; ReactNative/<version>; <OS>/<version>; <device-model>)
|
|
122
|
+
*/ const getUserAgent = async (sdkVersion)=>{
|
|
123
|
+
const platformInfo = await getPlatformInfo();
|
|
124
|
+
return getUserAgent$1(sdkVersion, platformInfo);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Checks if a string appears to be already URL encoded
|
|
129
|
+
* @param str The string to check
|
|
130
|
+
* @returns boolean indicating if the string appears to be URL encoded
|
|
131
|
+
*/ const isEncoded = (str)=>{
|
|
132
|
+
// Check for typical URL encoding patterns like %20, %3A, etc.
|
|
133
|
+
const hasEncodedChars = /%[0-9A-F]{2}/i.test(str);
|
|
134
|
+
// Check if double encoding has occurred (e.g., %253A instead of %3A)
|
|
135
|
+
const hasDoubleEncoding = /%25[0-9A-F]{2}/i.test(str);
|
|
136
|
+
// If we have encoded chars but no double encoding, it's likely properly encoded
|
|
137
|
+
return hasEncodedChars && !hasDoubleEncoding;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Smart URL encoder that ensures a string is encoded exactly once
|
|
141
|
+
* @param str The string to encode
|
|
142
|
+
* @returns A properly URL encoded string
|
|
143
|
+
*/ const smartEncodeURIComponent = (str)=>{
|
|
144
|
+
if (!str) return str;
|
|
145
|
+
// If it's already encoded, return as is
|
|
146
|
+
if (isEncoded(str)) {
|
|
147
|
+
console.log('URL already encoded, skipping encoding');
|
|
148
|
+
return str;
|
|
149
|
+
}
|
|
150
|
+
// Otherwise, encode it
|
|
151
|
+
const encoded = encodeURIComponent(str);
|
|
152
|
+
console.log('URL encoded');
|
|
153
|
+
return encoded;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Creates a URL with proper parameter encoding
|
|
157
|
+
* @param baseUrl The base URL string
|
|
158
|
+
* @param params Object containing key-value pairs to be added as search params
|
|
159
|
+
* @returns A properly formatted URL string
|
|
160
|
+
*/ const createUrlWithParams = (baseUrl, params)=>{
|
|
161
|
+
try {
|
|
162
|
+
const url = new URL(baseUrl);
|
|
163
|
+
// Add each parameter without additional encoding
|
|
164
|
+
// (URLSearchParams.append will encode them automatically)
|
|
165
|
+
Object.entries(params).forEach(([key, value])=>{
|
|
166
|
+
// Skip undefined or null values
|
|
167
|
+
if (value == null) return;
|
|
168
|
+
// For oauth_redirect_url specifically, ensure it's not double encoded
|
|
169
|
+
if (key === 'oauth_redirect_url' && isEncoded(value)) {
|
|
170
|
+
// Decode once to counteract the automatic encoding that will happen
|
|
171
|
+
const decodedOnce = decodeURIComponent(value);
|
|
172
|
+
url.searchParams.append(key, decodedOnce);
|
|
173
|
+
} else {
|
|
174
|
+
url.searchParams.append(key, value);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
return url.toString();
|
|
178
|
+
} catch (error) {
|
|
179
|
+
console.error('Error creating URL with params:', error);
|
|
180
|
+
return baseUrl;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Checks if a string appears to be double-encoded
|
|
185
|
+
*/ const isDoubleEncoded = (str)=>{
|
|
186
|
+
if (!str) return false;
|
|
187
|
+
return /%25[0-9A-F]{2}/i.test(str);
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Normalizes a URL string by decoding it once if it appears to be double-encoded
|
|
191
|
+
*/ const normalizeUrlEncoding = (urlStr)=>{
|
|
192
|
+
if (isDoubleEncoded(urlStr)) {
|
|
193
|
+
console.log('Detected double-encoded URL:', urlStr);
|
|
194
|
+
const normalized = decodeURIComponent(urlStr);
|
|
195
|
+
console.log('Normalized to:', normalized);
|
|
196
|
+
return normalized;
|
|
197
|
+
}
|
|
198
|
+
return urlStr;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export { ErrorReporter, createUrlWithParams, getDeviceModel, getErrorMessage, getOSInfo, getPlatformInfo, getPlatformInfoSync, getReactNativeVersion, getReactVersion, getUserAgent, isEncoded, normalizeUrlEncoding, smartEncodeURIComponent };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiltt/react-native",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "React Native Components for Quiltt Connector",
|
|
5
5
|
"homepage": "https://github.com/quiltt/quiltt-js/tree/main/packages/react-native#readme",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,27 @@
|
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
18
|
"types": "./dist/index.d.ts",
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"import": "./dist/index.js",
|
|
19
21
|
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./components": {
|
|
24
|
+
"types": "./dist/components/index.d.ts",
|
|
25
|
+
"require": "./dist/components/index.cjs",
|
|
26
|
+
"import": "./dist/components/index.js",
|
|
27
|
+
"default": "./dist/components/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./providers": {
|
|
30
|
+
"types": "./dist/providers/index.d.ts",
|
|
31
|
+
"require": "./dist/providers/index.cjs",
|
|
32
|
+
"import": "./dist/providers/index.js",
|
|
33
|
+
"default": "./dist/providers/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./utils": {
|
|
36
|
+
"types": "./dist/utils/index.d.ts",
|
|
37
|
+
"require": "./dist/utils/index.cjs",
|
|
38
|
+
"import": "./dist/utils/index.js",
|
|
39
|
+
"default": "./dist/utils/index.js"
|
|
20
40
|
}
|
|
21
41
|
},
|
|
22
42
|
"module": "./dist/index.js",
|
|
@@ -28,18 +48,18 @@
|
|
|
28
48
|
],
|
|
29
49
|
"main": "dist/index.js",
|
|
30
50
|
"dependencies": {
|
|
31
|
-
"@honeybadger-io/
|
|
51
|
+
"@honeybadger-io/react-native": "6.4.7",
|
|
32
52
|
"lodash.debounce": "4.0.8",
|
|
33
53
|
"react-native-device-info": "15.0.1",
|
|
34
|
-
"@quiltt/core": "5.0.
|
|
35
|
-
"@quiltt/react": "5.0.
|
|
54
|
+
"@quiltt/core": "5.0.2",
|
|
55
|
+
"@quiltt/react": "5.0.2"
|
|
36
56
|
},
|
|
37
57
|
"devDependencies": {
|
|
38
|
-
"@biomejs/biome": "2.3.
|
|
58
|
+
"@biomejs/biome": "2.3.14",
|
|
39
59
|
"@types/base-64": "1.0.2",
|
|
40
60
|
"@types/lodash.debounce": "4.0.9",
|
|
41
|
-
"@types/node": "24.10.
|
|
42
|
-
"@types/react": "19.2.
|
|
61
|
+
"@types/node": "24.10.10",
|
|
62
|
+
"@types/react": "19.2.11",
|
|
43
63
|
"base-64": "1.0.0",
|
|
44
64
|
"bunchee": "6.9.4",
|
|
45
65
|
"react": "19.2.4",
|
|
@@ -1,95 +1,44 @@
|
|
|
1
1
|
// Custom Error Reporter to avoid hooking into or colliding with a client's Honeybadger singleton
|
|
2
|
-
import
|
|
3
|
-
import { generateStackTrace, getCauses, makeBacktrace } from '@honeybadger-io/core/build/src/util'
|
|
2
|
+
import Honeybadger from '@honeybadger-io/react-native'
|
|
4
3
|
|
|
5
4
|
import { version } from '@/version'
|
|
6
5
|
|
|
7
|
-
const notifier = {
|
|
8
|
-
name: 'Quiltt React Native SDK Reporter',
|
|
9
|
-
url: 'https://www.quiltt.dev/connector/sdk/react-native',
|
|
10
|
-
version: version,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type HoneybadgerResponseData = {
|
|
14
|
-
id: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
6
|
class ErrorReporter {
|
|
18
|
-
private
|
|
19
|
-
private apiKey: string
|
|
20
|
-
private logger: Console
|
|
21
|
-
private userAgent: string
|
|
7
|
+
private client: typeof Honeybadger
|
|
22
8
|
|
|
23
9
|
constructor(userAgent: string) {
|
|
24
|
-
|
|
25
|
-
this.
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
// Create an isolated Honeybadger instance to avoid colliding with client's singleton
|
|
11
|
+
this.client = Honeybadger.factory({
|
|
12
|
+
apiKey: process.env.HONEYBADGER_API_KEY_REACT_NATIVE || '',
|
|
13
|
+
environment: userAgent,
|
|
14
|
+
revision: version,
|
|
15
|
+
reportData: true,
|
|
16
|
+
enableUncaught: false, // Don't hook into global error handlers
|
|
17
|
+
enableUnhandledRejection: false, // Don't hook into global rejection handlers
|
|
18
|
+
})
|
|
28
19
|
}
|
|
29
20
|
|
|
30
21
|
async notify(error: Error, context?: any): Promise<void> {
|
|
31
|
-
|
|
32
|
-
'
|
|
33
|
-
|
|
34
|
-
Accept: 'application/json',
|
|
35
|
-
'User-Agent': this.userAgent,
|
|
22
|
+
if (!this.client) {
|
|
23
|
+
console.warn('ErrorReporter: Honeybadger client not initialized')
|
|
24
|
+
return
|
|
36
25
|
}
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
.then((data: HoneybadgerResponseData) => {
|
|
54
|
-
if (data) {
|
|
55
|
-
this.logger.info(`Error report sent ⚡ https://app.honeybadger.io/notice/${data?.id}`)
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async buildPayload(error: Error, localContext = {}): Promise<Partial<NoticeTransportPayload>> {
|
|
61
|
-
const notice: Notice = error as Notice
|
|
62
|
-
notice.stack = generateStackTrace()
|
|
63
|
-
|
|
64
|
-
notice.backtrace = makeBacktrace(notice.stack)
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
notifier,
|
|
68
|
-
error: {
|
|
69
|
-
class: notice.name as string,
|
|
70
|
-
message: notice.message as string,
|
|
71
|
-
backtrace: notice.backtrace,
|
|
72
|
-
// fingerprint: this.calculateFingerprint(notice),
|
|
73
|
-
tags: notice.tags || [],
|
|
74
|
-
causes: getCauses(notice, this.logger),
|
|
75
|
-
},
|
|
76
|
-
request: {
|
|
77
|
-
url: notice.url,
|
|
78
|
-
component: notice.component,
|
|
79
|
-
action: notice.action,
|
|
80
|
-
context: localContext || {},
|
|
81
|
-
cgi_data: {},
|
|
82
|
-
params: {},
|
|
83
|
-
session: {},
|
|
84
|
-
},
|
|
85
|
-
server: {
|
|
86
|
-
project_root: notice.projectRoot,
|
|
87
|
-
environment_name: this.userAgent,
|
|
88
|
-
revision: version,
|
|
89
|
-
hostname: this.userAgent,
|
|
90
|
-
time: new Date().toUTCString(),
|
|
91
|
-
},
|
|
92
|
-
details: notice.details || {},
|
|
27
|
+
try {
|
|
28
|
+
// Set context for this error report
|
|
29
|
+
if (context) {
|
|
30
|
+
this.client.setContext(context)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Notify Honeybadger
|
|
34
|
+
await this.client.notify(error)
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error('ErrorReporter: Failed to send error report', err)
|
|
37
|
+
} finally {
|
|
38
|
+
// Clear context after reporting (always runs if context was set)
|
|
39
|
+
if (context) {
|
|
40
|
+
this.client.clear()
|
|
41
|
+
}
|
|
93
42
|
}
|
|
94
43
|
}
|
|
95
44
|
}
|
package/src/utils/telemetry.ts
CHANGED
|
@@ -2,14 +2,7 @@ import React from 'react'
|
|
|
2
2
|
import { Platform } from 'react-native'
|
|
3
3
|
|
|
4
4
|
import { getUserAgent as coreGetUserAgent } from '@quiltt/core'
|
|
5
|
-
|
|
6
|
-
// Optionally import react-native-device-info if available
|
|
7
|
-
let DeviceInfo: any = null
|
|
8
|
-
try {
|
|
9
|
-
DeviceInfo = require('react-native-device-info').default
|
|
10
|
-
} catch {
|
|
11
|
-
// react-native-device-info is not installed - will use fallback
|
|
12
|
-
}
|
|
5
|
+
import DeviceInfo from 'react-native-device-info'
|
|
13
6
|
|
|
14
7
|
/**
|
|
15
8
|
* Gets the React version from the runtime
|
|
@@ -57,13 +50,8 @@ export const getOSInfo = (): string => {
|
|
|
57
50
|
|
|
58
51
|
/**
|
|
59
52
|
* Gets device model information
|
|
60
|
-
* Falls back to 'Unknown' if react-native-device-info is not installed
|
|
61
53
|
*/
|
|
62
54
|
export const getDeviceModel = async (): Promise<string> => {
|
|
63
|
-
if (!DeviceInfo) {
|
|
64
|
-
return 'Unknown'
|
|
65
|
-
}
|
|
66
|
-
|
|
67
55
|
try {
|
|
68
56
|
const model = await DeviceInfo.getModel()
|
|
69
57
|
return model || 'Unknown'
|