@quiltt/react-native 5.0.0 → 5.0.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.
@@ -0,0 +1,107 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var React = require('react');
5
+ var core = require('@quiltt/core');
6
+ var react = require('@quiltt/react');
7
+ var reactNative = require('react-native');
8
+ require('react-native-device-info');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefault(React);
13
+
14
+ /**
15
+ * Gets the React version from the runtime
16
+ */ const getReactVersion = ()=>{
17
+ return React__default.default.version || 'unknown';
18
+ };
19
+ /**
20
+ * Gets the React Native version from Platform constants
21
+ */ const getReactNativeVersion = ()=>{
22
+ try {
23
+ const rnVersion = reactNative.Platform.constants?.reactNativeVersion;
24
+ if (rnVersion) {
25
+ return `${rnVersion.major}.${rnVersion.minor}.${rnVersion.patch}`;
26
+ }
27
+ } catch (error) {
28
+ console.warn('Failed to get React Native version:', error);
29
+ }
30
+ return 'unknown';
31
+ };
32
+ /**
33
+ * Gets OS information (platform and version)
34
+ */ const getOSInfo = ()=>{
35
+ try {
36
+ const os = reactNative.Platform.OS // 'ios' or 'android'
37
+ ;
38
+ const osVersion = reactNative.Platform.Version // string (iOS) or number (Android)
39
+ ;
40
+ // Map platform names to correct capitalization
41
+ const platformNames = {
42
+ ios: 'iOS',
43
+ android: 'Android'
44
+ };
45
+ const osName = platformNames[os] || 'Unknown';
46
+ return `${osName}/${osVersion}`;
47
+ } catch (error) {
48
+ console.warn('Failed to get OS info:', error);
49
+ return 'Unknown/Unknown';
50
+ }
51
+ };
52
+ /**
53
+ * Synchronously generates platform information string for React Native
54
+ * Format: React/<version>; ReactNative/<version>; <OS>/<version>; Unknown
55
+ * Note: Device model is set to 'Unknown' since it requires async DeviceInfo call
56
+ */ const getPlatformInfoSync = ()=>{
57
+ const reactVersion = getReactVersion();
58
+ const rnVersion = getReactNativeVersion();
59
+ const osInfo = getOSInfo();
60
+ return `React/${reactVersion}; ReactNative/${rnVersion}; ${osInfo}; Unknown`;
61
+ };
62
+
63
+ /**
64
+ * React Native-specific QuilttAuthProvider that injects platform information
65
+ * into the GraphQL client's User-Agent header.
66
+ *
67
+ * If a token is provided, will validate the token against the api and then import
68
+ * it into trusted storage. While this process is happening, the component is put
69
+ * into a loading state and the children are not rendered to prevent race conditions
70
+ * from triggering within the transitionary state.
71
+ */ const QuilttAuthProvider = ({ graphqlClient, token, children })=>{
72
+ // Create React Native-specific GraphQL client with platform info if no custom client provided
73
+ const platformClient = React.useMemo(()=>{
74
+ if (graphqlClient) {
75
+ return graphqlClient;
76
+ }
77
+ const platformInfo = getPlatformInfoSync();
78
+ return new core.QuilttClient({
79
+ cache: new core.InMemoryCache(),
80
+ versionLink: core.createVersionLink(platformInfo)
81
+ });
82
+ }, [
83
+ graphqlClient
84
+ ]);
85
+ return /*#__PURE__*/ jsxRuntime.jsx(react.QuilttAuthProvider, {
86
+ token: token,
87
+ graphqlClient: platformClient,
88
+ children: children
89
+ });
90
+ };
91
+
92
+ /**
93
+ * React Native-specific QuilttProvider that combines settings and auth providers
94
+ * with platform-specific GraphQL client configuration.
95
+ */ const QuilttProvider = ({ clientId, graphqlClient, token, children })=>{
96
+ return /*#__PURE__*/ jsxRuntime.jsx(react.QuilttSettingsProvider, {
97
+ clientId: clientId,
98
+ children: /*#__PURE__*/ jsxRuntime.jsx(QuilttAuthProvider, {
99
+ token: token,
100
+ graphqlClient: graphqlClient,
101
+ children: children
102
+ })
103
+ });
104
+ };
105
+
106
+ exports.QuilttAuthProvider = QuilttAuthProvider;
107
+ exports.QuilttProvider = QuilttProvider;
@@ -0,0 +1,24 @@
1
+ import { FC } from 'react';
2
+ import { QuilttAuthProviderProps as QuilttAuthProviderProps$1, QuilttSettingsProviderProps } from '@quiltt/react';
3
+
4
+ type QuilttAuthProviderProps = QuilttAuthProviderProps$1;
5
+ /**
6
+ * React Native-specific QuilttAuthProvider that injects platform information
7
+ * into the GraphQL client's User-Agent header.
8
+ *
9
+ * If a token is provided, will validate the token against the api and then import
10
+ * it into trusted storage. While this process is happening, the component is put
11
+ * into a loading state and the children are not rendered to prevent race conditions
12
+ * from triggering within the transitionary state.
13
+ */
14
+ declare const QuilttAuthProvider: FC<QuilttAuthProviderProps>;
15
+
16
+ type QuilttProviderProps = QuilttSettingsProviderProps & QuilttAuthProviderProps;
17
+ /**
18
+ * React Native-specific QuilttProvider that combines settings and auth providers
19
+ * with platform-specific GraphQL client configuration.
20
+ */
21
+ declare const QuilttProvider: FC<QuilttProviderProps>;
22
+
23
+ export { QuilttAuthProvider, QuilttProvider };
24
+ export type { QuilttAuthProviderProps };
@@ -0,0 +1,100 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import React, { useMemo } from 'react';
3
+ import { QuilttClient, InMemoryCache, createVersionLink } from '@quiltt/core';
4
+ import { QuilttAuthProvider as QuilttAuthProvider$1, QuilttSettingsProvider } from '@quiltt/react';
5
+ import { Platform } from 'react-native';
6
+ import 'react-native-device-info';
7
+
8
+ /**
9
+ * Gets the React version from the runtime
10
+ */ const getReactVersion = ()=>{
11
+ return React.version || 'unknown';
12
+ };
13
+ /**
14
+ * Gets the React Native version from Platform constants
15
+ */ const getReactNativeVersion = ()=>{
16
+ try {
17
+ const rnVersion = Platform.constants?.reactNativeVersion;
18
+ if (rnVersion) {
19
+ return `${rnVersion.major}.${rnVersion.minor}.${rnVersion.patch}`;
20
+ }
21
+ } catch (error) {
22
+ console.warn('Failed to get React Native version:', error);
23
+ }
24
+ return 'unknown';
25
+ };
26
+ /**
27
+ * Gets OS information (platform and version)
28
+ */ const getOSInfo = ()=>{
29
+ try {
30
+ const os = Platform.OS // 'ios' or 'android'
31
+ ;
32
+ const osVersion = Platform.Version // string (iOS) or number (Android)
33
+ ;
34
+ // Map platform names to correct capitalization
35
+ const platformNames = {
36
+ ios: 'iOS',
37
+ android: 'Android'
38
+ };
39
+ const osName = platformNames[os] || 'Unknown';
40
+ return `${osName}/${osVersion}`;
41
+ } catch (error) {
42
+ console.warn('Failed to get OS info:', error);
43
+ return 'Unknown/Unknown';
44
+ }
45
+ };
46
+ /**
47
+ * Synchronously generates platform information string for React Native
48
+ * Format: React/<version>; ReactNative/<version>; <OS>/<version>; Unknown
49
+ * Note: Device model is set to 'Unknown' since it requires async DeviceInfo call
50
+ */ const getPlatformInfoSync = ()=>{
51
+ const reactVersion = getReactVersion();
52
+ const rnVersion = getReactNativeVersion();
53
+ const osInfo = getOSInfo();
54
+ return `React/${reactVersion}; ReactNative/${rnVersion}; ${osInfo}; Unknown`;
55
+ };
56
+
57
+ /**
58
+ * React Native-specific QuilttAuthProvider that injects platform information
59
+ * into the GraphQL client's User-Agent header.
60
+ *
61
+ * If a token is provided, will validate the token against the api and then import
62
+ * it into trusted storage. While this process is happening, the component is put
63
+ * into a loading state and the children are not rendered to prevent race conditions
64
+ * from triggering within the transitionary state.
65
+ */ const QuilttAuthProvider = ({ graphqlClient, token, children })=>{
66
+ // Create React Native-specific GraphQL client with platform info if no custom client provided
67
+ const platformClient = useMemo(()=>{
68
+ if (graphqlClient) {
69
+ return graphqlClient;
70
+ }
71
+ const platformInfo = getPlatformInfoSync();
72
+ return new QuilttClient({
73
+ cache: new InMemoryCache(),
74
+ versionLink: createVersionLink(platformInfo)
75
+ });
76
+ }, [
77
+ graphqlClient
78
+ ]);
79
+ return /*#__PURE__*/ jsx(QuilttAuthProvider$1, {
80
+ token: token,
81
+ graphqlClient: platformClient,
82
+ children: children
83
+ });
84
+ };
85
+
86
+ /**
87
+ * React Native-specific QuilttProvider that combines settings and auth providers
88
+ * with platform-specific GraphQL client configuration.
89
+ */ const QuilttProvider = ({ clientId, graphqlClient, token, children })=>{
90
+ return /*#__PURE__*/ jsx(QuilttSettingsProvider, {
91
+ clientId: clientId,
92
+ children: /*#__PURE__*/ jsx(QuilttAuthProvider, {
93
+ token: token,
94
+ graphqlClient: graphqlClient,
95
+ children: children
96
+ })
97
+ });
98
+ };
99
+
100
+ export { QuilttAuthProvider, QuilttProvider };
@@ -0,0 +1,221 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ var Honeybadger = require('@honeybadger-io/react-native');
4
+ var React = require('react');
5
+ var reactNative = require('react-native');
6
+ var core = require('@quiltt/core');
7
+ var DeviceInfo = require('react-native-device-info');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var Honeybadger__default = /*#__PURE__*/_interopDefault(Honeybadger);
12
+ var React__default = /*#__PURE__*/_interopDefault(React);
13
+ var DeviceInfo__default = /*#__PURE__*/_interopDefault(DeviceInfo);
14
+
15
+ var version = "5.0.1";
16
+
17
+ // Custom Error Reporter to avoid hooking into or colliding with a client's Honeybadger singleton
18
+ class ErrorReporter {
19
+ constructor(userAgent){
20
+ // Create an isolated Honeybadger instance to avoid colliding with client's singleton
21
+ this.client = Honeybadger__default.default.factory({
22
+ apiKey: process.env.HONEYBADGER_API_KEY_REACT_NATIVE || '',
23
+ environment: userAgent,
24
+ revision: version,
25
+ reportData: true,
26
+ enableUncaught: false,
27
+ enableUnhandledRejection: false
28
+ });
29
+ }
30
+ async notify(error, context) {
31
+ if (!this.client) {
32
+ console.warn('ErrorReporter: Honeybadger client not initialized');
33
+ return;
34
+ }
35
+ try {
36
+ // Set context for this error report
37
+ if (context) {
38
+ this.client.setContext(context);
39
+ }
40
+ // Notify Honeybadger
41
+ await this.client.notify(error);
42
+ } catch (err) {
43
+ console.error('ErrorReporter: Failed to send error report', err);
44
+ } finally{
45
+ // Clear context after reporting (always runs if context was set)
46
+ if (context) {
47
+ this.client.clear();
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ const getErrorMessage = (responseStatus, error)=>{
54
+ if (error) return `An error occurred while checking the Connector URL: ${error?.name} \n${error?.message}`;
55
+ return responseStatus ? `An error occurred loading the Connector. Response status: ${responseStatus}` : 'An error occurred while checking the Connector URL';
56
+ };
57
+
58
+ /**
59
+ * Gets the React version from the runtime
60
+ */ const getReactVersion = ()=>{
61
+ return React__default.default.version || 'unknown';
62
+ };
63
+ /**
64
+ * Gets the React Native version from Platform constants
65
+ */ const getReactNativeVersion = ()=>{
66
+ try {
67
+ const rnVersion = reactNative.Platform.constants?.reactNativeVersion;
68
+ if (rnVersion) {
69
+ return `${rnVersion.major}.${rnVersion.minor}.${rnVersion.patch}`;
70
+ }
71
+ } catch (error) {
72
+ console.warn('Failed to get React Native version:', error);
73
+ }
74
+ return 'unknown';
75
+ };
76
+ /**
77
+ * Gets OS information (platform and version)
78
+ */ const getOSInfo = ()=>{
79
+ try {
80
+ const os = reactNative.Platform.OS // 'ios' or 'android'
81
+ ;
82
+ const osVersion = reactNative.Platform.Version // string (iOS) or number (Android)
83
+ ;
84
+ // Map platform names to correct capitalization
85
+ const platformNames = {
86
+ ios: 'iOS',
87
+ android: 'Android'
88
+ };
89
+ const osName = platformNames[os] || 'Unknown';
90
+ return `${osName}/${osVersion}`;
91
+ } catch (error) {
92
+ console.warn('Failed to get OS info:', error);
93
+ return 'Unknown/Unknown';
94
+ }
95
+ };
96
+ /**
97
+ * Gets device model information
98
+ */ const getDeviceModel = async ()=>{
99
+ try {
100
+ const model = await DeviceInfo__default.default.getModel();
101
+ return model || 'Unknown';
102
+ } catch (error) {
103
+ console.warn('Failed to get device model:', error);
104
+ return 'Unknown';
105
+ }
106
+ };
107
+ /**
108
+ * Generates platform information string for React Native
109
+ * Format: React/<version>; ReactNative/<version>; <OS>/<version>; <device-model>
110
+ */ const getPlatformInfo = async ()=>{
111
+ const reactVersion = getReactVersion();
112
+ const rnVersion = getReactNativeVersion();
113
+ const osInfo = getOSInfo();
114
+ const deviceModel = await getDeviceModel();
115
+ return `React/${reactVersion}; ReactNative/${rnVersion}; ${osInfo}; ${deviceModel}`;
116
+ };
117
+ /**
118
+ * Synchronously generates platform information string for React Native
119
+ * Format: React/<version>; ReactNative/<version>; <OS>/<version>; Unknown
120
+ * Note: Device model is set to 'Unknown' since it requires async DeviceInfo call
121
+ */ const getPlatformInfoSync = ()=>{
122
+ const reactVersion = getReactVersion();
123
+ const rnVersion = getReactNativeVersion();
124
+ const osInfo = getOSInfo();
125
+ return `React/${reactVersion}; ReactNative/${rnVersion}; ${osInfo}; Unknown`;
126
+ };
127
+ /**
128
+ * Generates User-Agent string for React Native SDK
129
+ * Format: Quiltt/<sdk-version> (React/<version>; ReactNative/<version>; <OS>/<version>; <device-model>)
130
+ */ const getUserAgent = async (sdkVersion)=>{
131
+ const platformInfo = await getPlatformInfo();
132
+ return core.getUserAgent(sdkVersion, platformInfo);
133
+ };
134
+
135
+ /**
136
+ * Checks if a string appears to be already URL encoded
137
+ * @param str The string to check
138
+ * @returns boolean indicating if the string appears to be URL encoded
139
+ */ const isEncoded = (str)=>{
140
+ // Check for typical URL encoding patterns like %20, %3A, etc.
141
+ const hasEncodedChars = /%[0-9A-F]{2}/i.test(str);
142
+ // Check if double encoding has occurred (e.g., %253A instead of %3A)
143
+ const hasDoubleEncoding = /%25[0-9A-F]{2}/i.test(str);
144
+ // If we have encoded chars but no double encoding, it's likely properly encoded
145
+ return hasEncodedChars && !hasDoubleEncoding;
146
+ };
147
+ /**
148
+ * Smart URL encoder that ensures a string is encoded exactly once
149
+ * @param str The string to encode
150
+ * @returns A properly URL encoded string
151
+ */ const smartEncodeURIComponent = (str)=>{
152
+ if (!str) return str;
153
+ // If it's already encoded, return as is
154
+ if (isEncoded(str)) {
155
+ console.log('URL already encoded, skipping encoding');
156
+ return str;
157
+ }
158
+ // Otherwise, encode it
159
+ const encoded = encodeURIComponent(str);
160
+ console.log('URL encoded');
161
+ return encoded;
162
+ };
163
+ /**
164
+ * Creates a URL with proper parameter encoding
165
+ * @param baseUrl The base URL string
166
+ * @param params Object containing key-value pairs to be added as search params
167
+ * @returns A properly formatted URL string
168
+ */ const createUrlWithParams = (baseUrl, params)=>{
169
+ try {
170
+ const url = new URL(baseUrl);
171
+ // Add each parameter without additional encoding
172
+ // (URLSearchParams.append will encode them automatically)
173
+ Object.entries(params).forEach(([key, value])=>{
174
+ // Skip undefined or null values
175
+ if (value == null) return;
176
+ // For oauth_redirect_url specifically, ensure it's not double encoded
177
+ if (key === 'oauth_redirect_url' && isEncoded(value)) {
178
+ // Decode once to counteract the automatic encoding that will happen
179
+ const decodedOnce = decodeURIComponent(value);
180
+ url.searchParams.append(key, decodedOnce);
181
+ } else {
182
+ url.searchParams.append(key, value);
183
+ }
184
+ });
185
+ return url.toString();
186
+ } catch (error) {
187
+ console.error('Error creating URL with params:', error);
188
+ return baseUrl;
189
+ }
190
+ };
191
+ /**
192
+ * Checks if a string appears to be double-encoded
193
+ */ const isDoubleEncoded = (str)=>{
194
+ if (!str) return false;
195
+ return /%25[0-9A-F]{2}/i.test(str);
196
+ };
197
+ /**
198
+ * Normalizes a URL string by decoding it once if it appears to be double-encoded
199
+ */ const normalizeUrlEncoding = (urlStr)=>{
200
+ if (isDoubleEncoded(urlStr)) {
201
+ console.log('Detected double-encoded URL:', urlStr);
202
+ const normalized = decodeURIComponent(urlStr);
203
+ console.log('Normalized to:', normalized);
204
+ return normalized;
205
+ }
206
+ return urlStr;
207
+ };
208
+
209
+ exports.ErrorReporter = ErrorReporter;
210
+ exports.createUrlWithParams = createUrlWithParams;
211
+ exports.getDeviceModel = getDeviceModel;
212
+ exports.getErrorMessage = getErrorMessage;
213
+ exports.getOSInfo = getOSInfo;
214
+ exports.getPlatformInfo = getPlatformInfo;
215
+ exports.getPlatformInfoSync = getPlatformInfoSync;
216
+ exports.getReactNativeVersion = getReactNativeVersion;
217
+ exports.getReactVersion = getReactVersion;
218
+ exports.getUserAgent = getUserAgent;
219
+ exports.isEncoded = isEncoded;
220
+ exports.normalizeUrlEncoding = normalizeUrlEncoding;
221
+ exports.smartEncodeURIComponent = smartEncodeURIComponent;
@@ -0,0 +1,66 @@
1
+ declare class ErrorReporter {
2
+ private client;
3
+ constructor(userAgent: string);
4
+ notify(error: Error, context?: any): Promise<void>;
5
+ }
6
+
7
+ declare const getErrorMessage: (responseStatus?: number, error?: Error) => string;
8
+
9
+ /**
10
+ * Gets the React version from the runtime
11
+ */
12
+ declare const getReactVersion: () => string;
13
+ /**
14
+ * Gets the React Native version from Platform constants
15
+ */
16
+ declare const getReactNativeVersion: () => string;
17
+ /**
18
+ * Gets OS information (platform and version)
19
+ */
20
+ declare const getOSInfo: () => string;
21
+ /**
22
+ * Gets device model information
23
+ */
24
+ declare const getDeviceModel: () => Promise<string>;
25
+ /**
26
+ * Generates platform information string for React Native
27
+ * Format: React/<version>; ReactNative/<version>; <OS>/<version>; <device-model>
28
+ */
29
+ declare const getPlatformInfo: () => Promise<string>;
30
+ /**
31
+ * Synchronously generates platform information string for React Native
32
+ * Format: React/<version>; ReactNative/<version>; <OS>/<version>; Unknown
33
+ * Note: Device model is set to 'Unknown' since it requires async DeviceInfo call
34
+ */
35
+ declare const getPlatformInfoSync: () => string;
36
+ /**
37
+ * Generates User-Agent string for React Native SDK
38
+ * Format: Quiltt/<sdk-version> (React/<version>; ReactNative/<version>; <OS>/<version>; <device-model>)
39
+ */
40
+ declare const getUserAgent: (sdkVersion: string) => Promise<string>;
41
+
42
+ /**
43
+ * Checks if a string appears to be already URL encoded
44
+ * @param str The string to check
45
+ * @returns boolean indicating if the string appears to be URL encoded
46
+ */
47
+ declare const isEncoded: (str: string) => boolean;
48
+ /**
49
+ * Smart URL encoder that ensures a string is encoded exactly once
50
+ * @param str The string to encode
51
+ * @returns A properly URL encoded string
52
+ */
53
+ declare const smartEncodeURIComponent: (str: string) => string;
54
+ /**
55
+ * Creates a URL with proper parameter encoding
56
+ * @param baseUrl The base URL string
57
+ * @param params Object containing key-value pairs to be added as search params
58
+ * @returns A properly formatted URL string
59
+ */
60
+ declare const createUrlWithParams: (baseUrl: string, params: Record<string, string>) => string;
61
+ /**
62
+ * Normalizes a URL string by decoding it once if it appears to be double-encoded
63
+ */
64
+ declare const normalizeUrlEncoding: (urlStr: string) => string;
65
+
66
+ export { ErrorReporter, createUrlWithParams, getDeviceModel, getErrorMessage, getOSInfo, getPlatformInfo, getPlatformInfoSync, getReactNativeVersion, getReactVersion, getUserAgent, isEncoded, normalizeUrlEncoding, smartEncodeURIComponent };