@reown/appkit-core-react-native 0.0.0-accounts-canary.1-20251023174733
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/lib/commonjs/controllers/ApiController.js +410 -0
- package/lib/commonjs/controllers/ApiController.js.map +1 -0
- package/lib/commonjs/controllers/AssetController.js +30 -0
- package/lib/commonjs/controllers/AssetController.js.map +1 -0
- package/lib/commonjs/controllers/BlockchainApiController.js +384 -0
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -0
- package/lib/commonjs/controllers/ConnectionsController.js +425 -0
- package/lib/commonjs/controllers/ConnectionsController.js.map +1 -0
- package/lib/commonjs/controllers/EnsController.js +37 -0
- package/lib/commonjs/controllers/EnsController.js.map +1 -0
- package/lib/commonjs/controllers/EventsController.js +122 -0
- package/lib/commonjs/controllers/EventsController.js.map +1 -0
- package/lib/commonjs/controllers/LogController.js +188 -0
- package/lib/commonjs/controllers/LogController.js.map +1 -0
- package/lib/commonjs/controllers/ModalController.js +68 -0
- package/lib/commonjs/controllers/ModalController.js.map +1 -0
- package/lib/commonjs/controllers/OnRampController.js +502 -0
- package/lib/commonjs/controllers/OnRampController.js.map +1 -0
- package/lib/commonjs/controllers/OptionsController.js +96 -0
- package/lib/commonjs/controllers/OptionsController.js.map +1 -0
- package/lib/commonjs/controllers/PublicStateController.js +33 -0
- package/lib/commonjs/controllers/PublicStateController.js.map +1 -0
- package/lib/commonjs/controllers/RouterController.js +63 -0
- package/lib/commonjs/controllers/RouterController.js.map +1 -0
- package/lib/commonjs/controllers/SendController.js +192 -0
- package/lib/commonjs/controllers/SendController.js.map +1 -0
- package/lib/commonjs/controllers/SnackController.js +83 -0
- package/lib/commonjs/controllers/SnackController.js.map +1 -0
- package/lib/commonjs/controllers/SwapController.js +674 -0
- package/lib/commonjs/controllers/SwapController.js.map +1 -0
- package/lib/commonjs/controllers/ThemeController.js +45 -0
- package/lib/commonjs/controllers/ThemeController.js.map +1 -0
- package/lib/commonjs/controllers/TransactionsController.js +118 -0
- package/lib/commonjs/controllers/TransactionsController.js.map +1 -0
- package/lib/commonjs/controllers/WcController.js +73 -0
- package/lib/commonjs/controllers/WcController.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js +272 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js +48 -0
- package/lib/commonjs/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/commonjs/features/reown-authentication/index.js +28 -0
- package/lib/commonjs/features/reown-authentication/index.js.map +1 -0
- package/lib/commonjs/index.js +202 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ApiUtil.js +43 -0
- package/lib/commonjs/utils/ApiUtil.js.map +1 -0
- package/lib/commonjs/utils/AssetUtil.js +27 -0
- package/lib/commonjs/utils/AssetUtil.js.map +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +226 -0
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -0
- package/lib/commonjs/utils/CoreHelperUtil.js +298 -0
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -0
- package/lib/commonjs/utils/EventUtil.js +25 -0
- package/lib/commonjs/utils/EventUtil.js.map +1 -0
- package/lib/commonjs/utils/FetchUtil.js +158 -0
- package/lib/commonjs/utils/FetchUtil.js.map +1 -0
- package/lib/commonjs/utils/LogUtils.js +131 -0
- package/lib/commonjs/utils/LogUtils.js.map +1 -0
- package/lib/commonjs/utils/StorageUtil.js +319 -0
- package/lib/commonjs/utils/StorageUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapApiUtil.js +75 -0
- package/lib/commonjs/utils/SwapApiUtil.js.map +1 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js +97 -0
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/commonjs/utils/WalletUtil.js +23 -0
- package/lib/commonjs/utils/WalletUtil.js.map +1 -0
- package/lib/module/controllers/ApiController.js +407 -0
- package/lib/module/controllers/ApiController.js.map +1 -0
- package/lib/module/controllers/AssetController.js +27 -0
- package/lib/module/controllers/AssetController.js.map +1 -0
- package/lib/module/controllers/BlockchainApiController.js +381 -0
- package/lib/module/controllers/BlockchainApiController.js.map +1 -0
- package/lib/module/controllers/ConnectionsController.js +422 -0
- package/lib/module/controllers/ConnectionsController.js.map +1 -0
- package/lib/module/controllers/EnsController.js +34 -0
- package/lib/module/controllers/EnsController.js.map +1 -0
- package/lib/module/controllers/EventsController.js +118 -0
- package/lib/module/controllers/EventsController.js.map +1 -0
- package/lib/module/controllers/LogController.js +185 -0
- package/lib/module/controllers/LogController.js.map +1 -0
- package/lib/module/controllers/ModalController.js +65 -0
- package/lib/module/controllers/ModalController.js.map +1 -0
- package/lib/module/controllers/OnRampController.js +499 -0
- package/lib/module/controllers/OnRampController.js.map +1 -0
- package/lib/module/controllers/OptionsController.js +93 -0
- package/lib/module/controllers/OptionsController.js.map +1 -0
- package/lib/module/controllers/PublicStateController.js +30 -0
- package/lib/module/controllers/PublicStateController.js.map +1 -0
- package/lib/module/controllers/RouterController.js +60 -0
- package/lib/module/controllers/RouterController.js.map +1 -0
- package/lib/module/controllers/SendController.js +189 -0
- package/lib/module/controllers/SendController.js.map +1 -0
- package/lib/module/controllers/SnackController.js +80 -0
- package/lib/module/controllers/SnackController.js.map +1 -0
- package/lib/module/controllers/SwapController.js +671 -0
- package/lib/module/controllers/SwapController.js.map +1 -0
- package/lib/module/controllers/ThemeController.js +42 -0
- package/lib/module/controllers/ThemeController.js.map +1 -0
- package/lib/module/controllers/TransactionsController.js +115 -0
- package/lib/module/controllers/TransactionsController.js.map +1 -0
- package/lib/module/controllers/WcController.js +70 -0
- package/lib/module/controllers/WcController.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js +268 -0
- package/lib/module/features/reown-authentication/ReownAuthentication.js.map +1 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js +43 -0
- package/lib/module/features/reown-authentication/ReownAuthenticationMessenger.js.map +1 -0
- package/lib/module/features/reown-authentication/index.js +5 -0
- package/lib/module/features/reown-authentication/index.js.map +1 -0
- package/lib/module/index.js +38 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/ApiUtil.js +39 -0
- package/lib/module/utils/ApiUtil.js.map +1 -0
- package/lib/module/utils/AssetUtil.js +23 -0
- package/lib/module/utils/AssetUtil.js.map +1 -0
- package/lib/module/utils/ConstantsUtil.js +222 -0
- package/lib/module/utils/ConstantsUtil.js.map +1 -0
- package/lib/module/utils/CoreHelperUtil.js +294 -0
- package/lib/module/utils/CoreHelperUtil.js.map +1 -0
- package/lib/module/utils/EventUtil.js +21 -0
- package/lib/module/utils/EventUtil.js.map +1 -0
- package/lib/module/utils/FetchUtil.js +154 -0
- package/lib/module/utils/FetchUtil.js.map +1 -0
- package/lib/module/utils/LogUtils.js +121 -0
- package/lib/module/utils/LogUtils.js.map +1 -0
- package/lib/module/utils/StorageUtil.js +315 -0
- package/lib/module/utils/StorageUtil.js.map +1 -0
- package/lib/module/utils/SwapApiUtil.js +71 -0
- package/lib/module/utils/SwapApiUtil.js.map +1 -0
- package/lib/module/utils/SwapCalculationUtil.js +94 -0
- package/lib/module/utils/SwapCalculationUtil.js.map +1 -0
- package/lib/module/utils/WalletUtil.js +19 -0
- package/lib/module/utils/WalletUtil.js.map +1 -0
- package/lib/typescript/controllers/ApiController.d.ts +40 -0
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/AssetController.d.ts +12 -0
- package/lib/typescript/controllers/AssetController.d.ts.map +1 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts +55 -0
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts +47 -0
- package/lib/typescript/controllers/ConnectionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EnsController.d.ts +10 -0
- package/lib/typescript/controllers/EnsController.d.ts.map +1 -0
- package/lib/typescript/controllers/EventsController.d.ts +25 -0
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -0
- package/lib/typescript/controllers/LogController.d.ts +65 -0
- package/lib/typescript/controllers/LogController.d.ts.map +1 -0
- package/lib/typescript/controllers/ModalController.d.ts +17 -0
- package/lib/typescript/controllers/ModalController.d.ts.map +1 -0
- package/lib/typescript/controllers/OnRampController.d.ts +55 -0
- package/lib/typescript/controllers/OnRampController.d.ts.map +1 -0
- package/lib/typescript/controllers/OptionsController.d.ts +46 -0
- package/lib/typescript/controllers/OptionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/PublicStateController.d.ts +12 -0
- package/lib/typescript/controllers/PublicStateController.d.ts.map +1 -0
- package/lib/typescript/controllers/RouterController.d.ts +21 -0
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -0
- package/lib/typescript/controllers/SendController.d.ts +39 -0
- package/lib/typescript/controllers/SendController.d.ts.map +1 -0
- package/lib/typescript/controllers/SnackController.d.ts +20 -0
- package/lib/typescript/controllers/SnackController.d.ts.map +1 -0
- package/lib/typescript/controllers/SwapController.d.ts +116 -0
- package/lib/typescript/controllers/SwapController.d.ts.map +1 -0
- package/lib/typescript/controllers/ThemeController.d.ts +14 -0
- package/lib/typescript/controllers/ThemeController.d.ts.map +1 -0
- package/lib/typescript/controllers/TransactionsController.d.ts +21 -0
- package/lib/typescript/controllers/TransactionsController.d.ts.map +1 -0
- package/lib/typescript/controllers/WcController.d.ts +27 -0
- package/lib/typescript/controllers/WcController.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts +174 -0
- package/lib/typescript/features/reown-authentication/ReownAuthentication.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts +16 -0
- package/lib/typescript/features/reown-authentication/ReownAuthenticationMessenger.d.ts.map +1 -0
- package/lib/typescript/features/reown-authentication/index.d.ts +3 -0
- package/lib/typescript/features/reown-authentication/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +29 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/ApiUtil.d.ts +7 -0
- package/lib/typescript/utils/ApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/AssetUtil.d.ts +6 -0
- package/lib/typescript/utils/AssetUtil.d.ts.map +1 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts +79 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts +43 -0
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -0
- package/lib/typescript/utils/EventUtil.d.ts +5 -0
- package/lib/typescript/utils/EventUtil.d.ts.map +1 -0
- package/lib/typescript/utils/FetchUtil.d.ts +29 -0
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -0
- package/lib/typescript/utils/LogUtils.d.ts +15 -0
- package/lib/typescript/utils/LogUtils.d.ts.map +1 -0
- package/lib/typescript/utils/StorageUtil.d.ts +36 -0
- package/lib/typescript/utils/StorageUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts +11 -0
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +1 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +24 -0
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +1 -0
- package/lib/typescript/utils/WalletUtil.d.ts +5 -0
- package/lib/typescript/utils/WalletUtil.d.ts.map +1 -0
- package/package.json +57 -0
- package/readme.md +9 -0
- package/src/controllers/ApiController.ts +454 -0
- package/src/controllers/AssetController.ts +32 -0
- package/src/controllers/BlockchainApiController.ts +418 -0
- package/src/controllers/ConnectionsController.ts +575 -0
- package/src/controllers/EnsController.ts +41 -0
- package/src/controllers/EventsController.ts +146 -0
- package/src/controllers/LogController.ts +250 -0
- package/src/controllers/ModalController.ts +68 -0
- package/src/controllers/OnRampController.ts +698 -0
- package/src/controllers/OptionsController.ts +143 -0
- package/src/controllers/PublicStateController.ts +37 -0
- package/src/controllers/RouterController.ts +112 -0
- package/src/controllers/SendController.ts +270 -0
- package/src/controllers/SnackController.ts +95 -0
- package/src/controllers/SwapController.ts +863 -0
- package/src/controllers/ThemeController.ts +47 -0
- package/src/controllers/TransactionsController.ts +150 -0
- package/src/controllers/WcController.ts +93 -0
- package/src/features/reown-authentication/ReownAuthentication.ts +475 -0
- package/src/features/reown-authentication/ReownAuthenticationMessenger.ts +80 -0
- package/src/features/reown-authentication/index.ts +2 -0
- package/src/index.ts +70 -0
- package/src/utils/ApiUtil.ts +50 -0
- package/src/utils/AssetUtil.ts +27 -0
- package/src/utils/ConstantsUtil.ts +303 -0
- package/src/utils/CoreHelperUtil.ts +377 -0
- package/src/utils/EventUtil.ts +22 -0
- package/src/utils/FetchUtil.ts +164 -0
- package/src/utils/LogUtils.ts +179 -0
- package/src/utils/StorageUtil.ts +405 -0
- package/src/utils/SwapApiUtil.ts +101 -0
- package/src/utils/SwapCalculationUtil.ts +145 -0
- package/src/utils/WalletUtil.ts +14 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { RequestCache } from '@reown/appkit-common-react-native';
|
|
2
|
+
import { LogController } from '../controllers/LogController';
|
|
3
|
+
|
|
4
|
+
// -- Types ----------------------------------------------------------------------
|
|
5
|
+
interface Options {
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
clientId?: string | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface RequestArguments {
|
|
11
|
+
path: string;
|
|
12
|
+
headers?: HeadersInit;
|
|
13
|
+
params?: Record<string, string | undefined>;
|
|
14
|
+
cache?: RequestCache;
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface PostArguments extends RequestArguments {
|
|
19
|
+
body?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// -- Utility --------------------------------------------------------------------
|
|
23
|
+
export class FetchUtil {
|
|
24
|
+
public baseUrl: Options['baseUrl'];
|
|
25
|
+
public clientId: Options['clientId'];
|
|
26
|
+
|
|
27
|
+
public constructor({ baseUrl, clientId }: Options) {
|
|
28
|
+
this.baseUrl = baseUrl;
|
|
29
|
+
this.clientId = clientId;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async get<T>({ headers, signal, ...args }: RequestArguments) {
|
|
33
|
+
const url = this.createUrl(args);
|
|
34
|
+
const response = await fetch(url, { method: 'GET', headers, signal });
|
|
35
|
+
|
|
36
|
+
return this.processResponse<T>(response);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async post<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
40
|
+
const url = this.createUrl(args);
|
|
41
|
+
const response = await fetch(url, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
headers,
|
|
44
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
45
|
+
signal
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return this.processResponse<T>(response);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public async put<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
52
|
+
const url = this.createUrl(args);
|
|
53
|
+
const response = await fetch(url, {
|
|
54
|
+
method: 'PUT',
|
|
55
|
+
headers,
|
|
56
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
57
|
+
signal
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return this.processResponse<T>(response);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async delete<T>({ body, headers, signal, ...args }: PostArguments) {
|
|
64
|
+
const url = this.createUrl(args);
|
|
65
|
+
const response = await fetch(url, {
|
|
66
|
+
method: 'DELETE',
|
|
67
|
+
headers,
|
|
68
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
69
|
+
signal
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return this.processResponse<T>(response);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public async fetchImage(
|
|
76
|
+
path: string,
|
|
77
|
+
headers?: Record<string, string>,
|
|
78
|
+
params?: Record<string, string>
|
|
79
|
+
) {
|
|
80
|
+
try {
|
|
81
|
+
const url = this.createUrl({ path, params }).toString();
|
|
82
|
+
const response = await fetch(url, { headers });
|
|
83
|
+
const blob = await response.blob();
|
|
84
|
+
const reader = new FileReader();
|
|
85
|
+
reader.readAsDataURL(blob);
|
|
86
|
+
|
|
87
|
+
return new Promise<string>(resolve => {
|
|
88
|
+
reader.onloadend = () => resolve(reader.result as string);
|
|
89
|
+
});
|
|
90
|
+
} catch {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public createUrl({ path, params }: RequestArguments) {
|
|
96
|
+
let fullUrl: string;
|
|
97
|
+
|
|
98
|
+
const isAbsoluteUrl = path.startsWith('http://') || path.startsWith('https://');
|
|
99
|
+
|
|
100
|
+
if (isAbsoluteUrl) {
|
|
101
|
+
fullUrl = path;
|
|
102
|
+
} else {
|
|
103
|
+
const baseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
|
|
104
|
+
const pathUrl = path.startsWith('/') ? path.substring(1) : path;
|
|
105
|
+
fullUrl = `${baseUrl}${pathUrl}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const allParams: Record<string, string | undefined> = { ...params };
|
|
109
|
+
if (this.clientId) {
|
|
110
|
+
allParams['clientId'] = this.clientId;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const queryParams: string[] = [];
|
|
114
|
+
for (const key in allParams) {
|
|
115
|
+
const value = allParams[key];
|
|
116
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
117
|
+
queryParams.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (queryParams.length > 0) {
|
|
122
|
+
const queryString = queryParams.join('&');
|
|
123
|
+
if (fullUrl.includes('?')) {
|
|
124
|
+
fullUrl = `${fullUrl}&${queryString}`;
|
|
125
|
+
} else {
|
|
126
|
+
fullUrl = `${fullUrl}?${queryString}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return fullUrl;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private async processResponse<T>(response: Response) {
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
136
|
+
try {
|
|
137
|
+
const errorData = await response.json();
|
|
138
|
+
LogController.sendError(JSON.stringify(errorData), 'FetchUtil.ts', 'processResponse');
|
|
139
|
+
|
|
140
|
+
return Promise.reject(errorData);
|
|
141
|
+
} catch (jsonError) {
|
|
142
|
+
LogController.sendError(jsonError, 'FetchUtil.ts', 'processResponse');
|
|
143
|
+
|
|
144
|
+
return Promise.reject(`Code: ${response.status} - ${response.statusText}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const errorText = await response.text();
|
|
149
|
+
LogController.sendError(errorText, 'FetchUtil.ts', 'processResponse');
|
|
150
|
+
|
|
151
|
+
return Promise.reject(`Code: ${response.status} - ${response.statusText} - ${errorText}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (response.headers.get('content-length') === '0') {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (response.headers.get('content-type')?.includes('application/json')) {
|
|
159
|
+
return response.json() as T;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// -- Constants ----------------------------------------- //
|
|
2
|
+
const SENSITIVE_KEYS = [
|
|
3
|
+
'password',
|
|
4
|
+
'pass',
|
|
5
|
+
'pwd',
|
|
6
|
+
'secret',
|
|
7
|
+
'token',
|
|
8
|
+
'key',
|
|
9
|
+
'auth',
|
|
10
|
+
'authorization',
|
|
11
|
+
'bearer',
|
|
12
|
+
'credential',
|
|
13
|
+
'api_key',
|
|
14
|
+
'apikey',
|
|
15
|
+
'access_token',
|
|
16
|
+
'refresh_token',
|
|
17
|
+
'private_key',
|
|
18
|
+
'privatekey',
|
|
19
|
+
'mnemonic',
|
|
20
|
+
'seed',
|
|
21
|
+
'phrase',
|
|
22
|
+
'wallet',
|
|
23
|
+
'address',
|
|
24
|
+
'email',
|
|
25
|
+
'phone',
|
|
26
|
+
'ssn',
|
|
27
|
+
'social',
|
|
28
|
+
'credit',
|
|
29
|
+
'card',
|
|
30
|
+
'cvv',
|
|
31
|
+
'connection_string',
|
|
32
|
+
'connection',
|
|
33
|
+
'user_token'
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const MAX_STRING_LENGTH = 480; // Maximum length for any string value (account for potential replacements)
|
|
37
|
+
const MAX_STACK_LINES = 10; // Maximum lines in stack trace
|
|
38
|
+
|
|
39
|
+
// -- Data Sanitization Functions ---------------------- //
|
|
40
|
+
export const sanitizeString = (value: string): string => {
|
|
41
|
+
if (typeof value !== 'string') {
|
|
42
|
+
value = String(value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (value.length > MAX_STRING_LENGTH) {
|
|
46
|
+
return value.substring(0, MAX_STRING_LENGTH) + '... [truncated]';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const sanitizeStackTrace = (stack: string): string => {
|
|
53
|
+
if (typeof stack !== 'string') {
|
|
54
|
+
stack = String(stack);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const lines = stack.split('\n');
|
|
58
|
+
const sanitizedLines = lines.slice(0, MAX_STACK_LINES).map(line => {
|
|
59
|
+
// Remove file paths that might contain sensitive info
|
|
60
|
+
return line.replace(/\/[^\s]*\//g, '/[path]/');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (lines.length > MAX_STACK_LINES) {
|
|
64
|
+
sanitizedLines.push('... [stack trace truncated]');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return sanitizedLines.join('\n');
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const sanitizeUrl = (url: string): string => {
|
|
71
|
+
try {
|
|
72
|
+
const urlObj = new URL(url);
|
|
73
|
+
// Remove query parameters that might contain sensitive data
|
|
74
|
+
urlObj.search = '';
|
|
75
|
+
// Keep only the origin and pathname
|
|
76
|
+
|
|
77
|
+
return urlObj.origin + urlObj.pathname;
|
|
78
|
+
} catch {
|
|
79
|
+
// If URL parsing fails, just return sanitized string
|
|
80
|
+
|
|
81
|
+
return sanitizeString(url);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const isSensitiveKey = (key: string): boolean => {
|
|
86
|
+
const lowerKey = key.toLowerCase();
|
|
87
|
+
|
|
88
|
+
return SENSITIVE_KEYS.some(sensitiveKey => lowerKey.includes(sensitiveKey));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const sanitizeValue = (value: unknown, visited = new WeakSet()): unknown => {
|
|
92
|
+
if (value === null || value === undefined) {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof value === 'string') {
|
|
97
|
+
// Check if it looks like a URL
|
|
98
|
+
if (value.startsWith('http://') || value.startsWith('https://')) {
|
|
99
|
+
return sanitizeUrl(value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return sanitizeString(value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
106
|
+
return value;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
// Prevent circular references in arrays
|
|
111
|
+
if (visited.has(value)) {
|
|
112
|
+
return '[Circular Reference]';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
visited.add(value);
|
|
116
|
+
const result = value.slice(0, 10).map(item => sanitizeValue(item, visited));
|
|
117
|
+
visited.delete(value);
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof value === 'object') {
|
|
123
|
+
return sanitizeObject(value as Record<string, unknown>, visited);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// For other types, convert to string and sanitize
|
|
127
|
+
return sanitizeString(String(value));
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const sanitizeObject = (
|
|
131
|
+
obj: Record<string, unknown>,
|
|
132
|
+
visited = new WeakSet()
|
|
133
|
+
): Record<string, unknown> => {
|
|
134
|
+
// Prevent circular references
|
|
135
|
+
if (visited.has(obj)) {
|
|
136
|
+
return { '[Circular Reference]': true };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
visited.add(obj);
|
|
140
|
+
|
|
141
|
+
const sanitized: Record<string, unknown> = {};
|
|
142
|
+
const keys = Object.keys(obj).slice(0, 20); // Limit number of keys
|
|
143
|
+
|
|
144
|
+
for (const key of keys) {
|
|
145
|
+
if (isSensitiveKey(key)) {
|
|
146
|
+
sanitized[key] = '[REDACTED]';
|
|
147
|
+
} else {
|
|
148
|
+
sanitized[key] = sanitizeValue(obj[key], visited);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (Object.keys(obj).length > 20) {
|
|
153
|
+
sanitized['...'] = '[additional properties truncated]';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
visited.delete(obj);
|
|
157
|
+
|
|
158
|
+
return sanitized;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const sanitizeData = (
|
|
162
|
+
data?: Record<string, unknown>
|
|
163
|
+
): Record<string, unknown> | undefined => {
|
|
164
|
+
if (!data) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return sanitizeObject(data);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// -- Utility Functions --------------------------------- //
|
|
172
|
+
export const LogUtils = {
|
|
173
|
+
sanitizeString,
|
|
174
|
+
sanitizeStackTrace,
|
|
175
|
+
sanitizeUrl,
|
|
176
|
+
sanitizeValue,
|
|
177
|
+
sanitizeObject,
|
|
178
|
+
sanitizeData
|
|
179
|
+
};
|