@a-cube-io/ereceipts-js-sdk 1.0.0
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/LICENSE +41 -0
- package/README.md +444 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/auth-D6UEILKY.cjs +56 -0
- package/dist/auth-D6UEILKY.cjs.map +1 -0
- package/dist/auth-RZRIC4PK.js +7 -0
- package/dist/auth-RZRIC4PK.js.map +1 -0
- package/dist/chunk-24ZJ6SNG.cjs +624 -0
- package/dist/chunk-24ZJ6SNG.cjs.map +1 -0
- package/dist/chunk-C3YEL4ED.js +511 -0
- package/dist/chunk-C3YEL4ED.js.map +1 -0
- package/dist/chunk-K65HAAAO.js +44 -0
- package/dist/chunk-K65HAAAO.js.map +1 -0
- package/dist/chunk-NARXAXFL.cjs +215 -0
- package/dist/chunk-NARXAXFL.cjs.map +1 -0
- package/dist/chunk-UBEIMFLN.js +209 -0
- package/dist/chunk-UBEIMFLN.js.map +1 -0
- package/dist/chunk-UVUWF5FV.cjs +3964 -0
- package/dist/chunk-UVUWF5FV.cjs.map +1 -0
- package/dist/chunk-UXVFQRZK.cjs +533 -0
- package/dist/chunk-UXVFQRZK.cjs.map +1 -0
- package/dist/chunk-VDHN3FKS.js +3929 -0
- package/dist/chunk-VDHN3FKS.js.map +1 -0
- package/dist/chunk-XQKCXG4I.cjs +52 -0
- package/dist/chunk-XQKCXG4I.cjs.map +1 -0
- package/dist/chunk-YX3PJ4FC.js +590 -0
- package/dist/chunk-YX3PJ4FC.js.map +1 -0
- package/dist/client-WPBRHPKX.cjs +31 -0
- package/dist/client-WPBRHPKX.cjs.map +1 -0
- package/dist/client-Z2LXQJMF.js +6 -0
- package/dist/client-Z2LXQJMF.js.map +1 -0
- package/dist/index.cjs +1326 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +960 -0
- package/dist/index.d.ts +960 -0
- package/dist/index.js +1065 -0
- package/dist/index.js.map +1 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/queue-D7PJ536B.js +4 -0
- package/dist/queue-D7PJ536B.js.map +1 -0
- package/dist/queue-JHWXWX2B.cjs +13 -0
- package/dist/queue-JHWXWX2B.cjs.map +1 -0
- package/dist/token-3CIX4E64.cjs +13 -0
- package/dist/token-3CIX4E64.cjs.map +1 -0
- package/dist/token-4OAGWTVG.js +4 -0
- package/dist/token-4OAGWTVG.js.map +1 -0
- package/openapi.yaml +2732 -0
- package/package.json +115 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXQKCXG4I_cjs = require('./chunk-XQKCXG4I.cjs');
|
|
4
|
+
var AsyncStorage = require('@react-native-async-storage/async-storage');
|
|
5
|
+
var Keychain = require('react-native-keychain');
|
|
6
|
+
var idbKeyval = require('idb-keyval');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var AsyncStorage__default = /*#__PURE__*/_interopDefault(AsyncStorage);
|
|
29
|
+
var Keychain__namespace = /*#__PURE__*/_interopNamespace(Keychain);
|
|
30
|
+
|
|
31
|
+
/* A-Cube SDK - Professional TypeScript SDK for Italian e-receipt system */
|
|
32
|
+
|
|
33
|
+
// src/utils/logger.ts
|
|
34
|
+
var LogLevel = /* @__PURE__ */ function(LogLevel2) {
|
|
35
|
+
LogLevel2[LogLevel2["ERROR"] = 0] = "ERROR";
|
|
36
|
+
LogLevel2[LogLevel2["WARN"] = 1] = "WARN";
|
|
37
|
+
LogLevel2[LogLevel2["INFO"] = 2] = "INFO";
|
|
38
|
+
LogLevel2[LogLevel2["DEBUG"] = 3] = "DEBUG";
|
|
39
|
+
return LogLevel2;
|
|
40
|
+
}({});
|
|
41
|
+
var _a;
|
|
42
|
+
var Logger = (_a = class {
|
|
43
|
+
constructor() {
|
|
44
|
+
chunkXQKCXG4I_cjs.__publicField(this, "level", 2);
|
|
45
|
+
chunkXQKCXG4I_cjs.__publicField(this, "enableConsoleOutput", true);
|
|
46
|
+
chunkXQKCXG4I_cjs.__publicField(this, "listeners", /* @__PURE__ */ new Set());
|
|
47
|
+
chunkXQKCXG4I_cjs.__publicField(this, "logHistory", []);
|
|
48
|
+
chunkXQKCXG4I_cjs.__publicField(this, "maxHistorySize", 1e3);
|
|
49
|
+
{
|
|
50
|
+
this.level = 3;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
setLevel(level) {
|
|
54
|
+
this.level = level;
|
|
55
|
+
}
|
|
56
|
+
setConsoleOutput(enabled) {
|
|
57
|
+
this.enableConsoleOutput = enabled;
|
|
58
|
+
}
|
|
59
|
+
setMaxHistorySize(size) {
|
|
60
|
+
this.maxHistorySize = size;
|
|
61
|
+
this.trimHistory();
|
|
62
|
+
}
|
|
63
|
+
shouldLog(level) {
|
|
64
|
+
return level <= this.level;
|
|
65
|
+
}
|
|
66
|
+
createLogEntry(level, message, data, source) {
|
|
67
|
+
return {
|
|
68
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
69
|
+
level,
|
|
70
|
+
message,
|
|
71
|
+
data,
|
|
72
|
+
source
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
logToConsole(entry) {
|
|
76
|
+
if (!this.enableConsoleOutput) return;
|
|
77
|
+
const prefix = `[${entry.timestamp}] ${entry.source ? `[${entry.source}]` : ""}`;
|
|
78
|
+
const message = `${prefix} ${entry.message}`;
|
|
79
|
+
switch (entry.level) {
|
|
80
|
+
case 0:
|
|
81
|
+
console.error(message, entry.data || "");
|
|
82
|
+
break;
|
|
83
|
+
case 1:
|
|
84
|
+
console.warn(message, entry.data || "");
|
|
85
|
+
break;
|
|
86
|
+
case 2:
|
|
87
|
+
console.info(message, entry.data || "");
|
|
88
|
+
break;
|
|
89
|
+
case 3:
|
|
90
|
+
console.log(message, entry.data || "");
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
addToHistory(entry) {
|
|
95
|
+
this.logHistory.push(entry);
|
|
96
|
+
this.trimHistory();
|
|
97
|
+
}
|
|
98
|
+
trimHistory() {
|
|
99
|
+
if (this.logHistory.length > this.maxHistorySize) {
|
|
100
|
+
this.logHistory = this.logHistory.slice(-this.maxHistorySize);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
notifyListeners(entry) {
|
|
104
|
+
this.listeners.forEach((listener) => {
|
|
105
|
+
try {
|
|
106
|
+
listener(entry);
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error("Logger listener error:", error);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
log(level, message, data, source) {
|
|
113
|
+
if (!this.shouldLog(level)) return;
|
|
114
|
+
const entry = this.createLogEntry(level, message, data, source);
|
|
115
|
+
this.logToConsole(entry);
|
|
116
|
+
this.addToHistory(entry);
|
|
117
|
+
this.notifyListeners(entry);
|
|
118
|
+
}
|
|
119
|
+
error(message, data, source) {
|
|
120
|
+
this.log(0, message, data, source);
|
|
121
|
+
}
|
|
122
|
+
warn(message, data, source) {
|
|
123
|
+
this.log(1, message, data, source);
|
|
124
|
+
}
|
|
125
|
+
info(message, data, source) {
|
|
126
|
+
this.log(2, message, data, source);
|
|
127
|
+
}
|
|
128
|
+
debug(message, data, source) {
|
|
129
|
+
this.log(3, message, data, source);
|
|
130
|
+
}
|
|
131
|
+
// API-specific logging methods
|
|
132
|
+
apiRequest(url, method, data) {
|
|
133
|
+
this.debug(`API Request: ${method.toUpperCase()} ${url}`, data, "API");
|
|
134
|
+
}
|
|
135
|
+
apiResponse(url, status, data) {
|
|
136
|
+
const level = status >= 400 ? 0 : 3;
|
|
137
|
+
this.log(level, `API Response: ${status} ${url}`, data, "API");
|
|
138
|
+
}
|
|
139
|
+
apiError(url, error) {
|
|
140
|
+
this.error(`API Error: ${url}`, error, "API");
|
|
141
|
+
}
|
|
142
|
+
// Authentication logging
|
|
143
|
+
authSuccess(method, userInfo) {
|
|
144
|
+
this.info(`Authentication successful: ${method}`, userInfo, "AUTH");
|
|
145
|
+
}
|
|
146
|
+
authFailure(method, error) {
|
|
147
|
+
this.error(`Authentication failed: ${method}`, error, "AUTH");
|
|
148
|
+
}
|
|
149
|
+
// Storage logging
|
|
150
|
+
storageSet(key, isSecure = false) {
|
|
151
|
+
this.debug(`Storage set: ${key} (secure: ${isSecure})`, void 0, "STORAGE");
|
|
152
|
+
}
|
|
153
|
+
storageGet(key, found) {
|
|
154
|
+
this.debug(`Storage get: ${key} (found: ${found})`, void 0, "STORAGE");
|
|
155
|
+
}
|
|
156
|
+
storageError(operation, key, error) {
|
|
157
|
+
this.error(`Storage ${operation} error: ${key}`, error, "STORAGE");
|
|
158
|
+
}
|
|
159
|
+
// Network logging
|
|
160
|
+
networkStateChange(isConnected, connectionType) {
|
|
161
|
+
this.info(`Network state changed: ${isConnected ? "connected" : "disconnected"}`, {
|
|
162
|
+
connectionType
|
|
163
|
+
}, "NETWORK");
|
|
164
|
+
}
|
|
165
|
+
retryAttempt(attempt, maxAttempts, delay) {
|
|
166
|
+
this.warn(`Retry attempt ${attempt}/${maxAttempts} in ${delay}ms`, void 0, "RETRY");
|
|
167
|
+
}
|
|
168
|
+
// Utility methods
|
|
169
|
+
addListener(listener) {
|
|
170
|
+
this.listeners.add(listener);
|
|
171
|
+
return () => this.listeners.delete(listener);
|
|
172
|
+
}
|
|
173
|
+
removeListener(listener) {
|
|
174
|
+
this.listeners.delete(listener);
|
|
175
|
+
}
|
|
176
|
+
getHistory(level) {
|
|
177
|
+
if (level !== void 0) {
|
|
178
|
+
return this.logHistory.filter((entry) => entry.level === level);
|
|
179
|
+
}
|
|
180
|
+
return [
|
|
181
|
+
...this.logHistory
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
clearHistory() {
|
|
185
|
+
this.logHistory = [];
|
|
186
|
+
}
|
|
187
|
+
// Export logs (useful for debugging)
|
|
188
|
+
exportLogs() {
|
|
189
|
+
return this.logHistory.map((entry) => {
|
|
190
|
+
const levelName = LogLevel[entry.level];
|
|
191
|
+
const dataStr = entry.data ? ` ${JSON.stringify(entry.data)}` : "";
|
|
192
|
+
const sourceStr = entry.source ? ` [${entry.source}]` : "";
|
|
193
|
+
return `${entry.timestamp} ${levelName}${sourceStr}: ${entry.message}${dataStr}`;
|
|
194
|
+
}).join("\n");
|
|
195
|
+
}
|
|
196
|
+
// Create a scoped logger for specific components
|
|
197
|
+
createScope(source) {
|
|
198
|
+
return new ScopedLogger(this, source);
|
|
199
|
+
}
|
|
200
|
+
}, chunkXQKCXG4I_cjs.__name(_a, "Logger"), _a);
|
|
201
|
+
var _a2;
|
|
202
|
+
var ScopedLogger = (_a2 = class {
|
|
203
|
+
constructor(logger2, source) {
|
|
204
|
+
chunkXQKCXG4I_cjs.__publicField(this, "logger");
|
|
205
|
+
chunkXQKCXG4I_cjs.__publicField(this, "source");
|
|
206
|
+
this.logger = logger2;
|
|
207
|
+
this.source = source;
|
|
208
|
+
}
|
|
209
|
+
error(message, data) {
|
|
210
|
+
this.logger.error(message, data, this.source);
|
|
211
|
+
}
|
|
212
|
+
warn(message, data) {
|
|
213
|
+
this.logger.warn(message, data, this.source);
|
|
214
|
+
}
|
|
215
|
+
info(message, data) {
|
|
216
|
+
this.logger.info(message, data, this.source);
|
|
217
|
+
}
|
|
218
|
+
debug(message, data) {
|
|
219
|
+
this.logger.debug(message, data, this.source);
|
|
220
|
+
}
|
|
221
|
+
// API-specific logging methods
|
|
222
|
+
apiRequest(url, method, data) {
|
|
223
|
+
this.logger.apiRequest(url, method, data);
|
|
224
|
+
}
|
|
225
|
+
apiResponse(url, status, data) {
|
|
226
|
+
this.logger.apiResponse(url, status, data);
|
|
227
|
+
}
|
|
228
|
+
apiError(url, error) {
|
|
229
|
+
this.logger.apiError(url, error);
|
|
230
|
+
}
|
|
231
|
+
// Authentication logging
|
|
232
|
+
authSuccess(method, userInfo) {
|
|
233
|
+
this.logger.authSuccess(method, userInfo);
|
|
234
|
+
}
|
|
235
|
+
authFailure(method, error) {
|
|
236
|
+
this.logger.authFailure(method, error);
|
|
237
|
+
}
|
|
238
|
+
// Storage logging
|
|
239
|
+
storageSet(key, isSecure = false) {
|
|
240
|
+
this.logger.storageSet(key, isSecure);
|
|
241
|
+
}
|
|
242
|
+
storageGet(key, found) {
|
|
243
|
+
this.logger.storageGet(key, found);
|
|
244
|
+
}
|
|
245
|
+
storageError(operation, key, error) {
|
|
246
|
+
this.logger.storageError(operation, key, error);
|
|
247
|
+
}
|
|
248
|
+
// Network logging
|
|
249
|
+
networkStateChange(isConnected, connectionType) {
|
|
250
|
+
this.logger.networkStateChange(isConnected, connectionType);
|
|
251
|
+
}
|
|
252
|
+
retryAttempt(attempt, maxAttempts, delay) {
|
|
253
|
+
this.logger.retryAttempt(attempt, maxAttempts, delay);
|
|
254
|
+
}
|
|
255
|
+
}, chunkXQKCXG4I_cjs.__name(_a2, "ScopedLogger"), _a2);
|
|
256
|
+
var logger = new Logger();
|
|
257
|
+
var logError = /* @__PURE__ */ chunkXQKCXG4I_cjs.__name((message, data, source) => logger.error(message, data, source), "logError");
|
|
258
|
+
var logWarn = /* @__PURE__ */ chunkXQKCXG4I_cjs.__name((message, data, source) => logger.warn(message, data, source), "logWarn");
|
|
259
|
+
var logInfo = /* @__PURE__ */ chunkXQKCXG4I_cjs.__name((message, data, source) => logger.info(message, data, source), "logInfo");
|
|
260
|
+
var logDebug = /* @__PURE__ */ chunkXQKCXG4I_cjs.__name((message, data, source) => logger.debug(message, data, source), "logDebug");
|
|
261
|
+
var apiLogger = logger.createScope("API");
|
|
262
|
+
var authLogger = logger.createScope("AUTH");
|
|
263
|
+
var storageLogger = logger.createScope("STORAGE");
|
|
264
|
+
var networkLogger = logger.createScope("NETWORK");
|
|
265
|
+
var uiLogger = logger.createScope("UI");
|
|
266
|
+
|
|
267
|
+
// src/storage/token.ts
|
|
268
|
+
var isWeb = typeof window !== "undefined" && !!window?.document;
|
|
269
|
+
var isReactNative = !isWeb;
|
|
270
|
+
var DEFAULT_CONFIG = {
|
|
271
|
+
encryptionKeyId: "acube-default-key",
|
|
272
|
+
storeNamespace: "acube-secure-store"
|
|
273
|
+
};
|
|
274
|
+
var currentConfig = {
|
|
275
|
+
...DEFAULT_CONFIG
|
|
276
|
+
};
|
|
277
|
+
var _a3;
|
|
278
|
+
var WebSecureStorage = (_a3 = class {
|
|
279
|
+
static getStore() {
|
|
280
|
+
if (!this.customStore) {
|
|
281
|
+
try {
|
|
282
|
+
this.customStore = idbKeyval.createStore(currentConfig.storeNamespace, "secure-data");
|
|
283
|
+
} catch (error) {
|
|
284
|
+
apiLogger.warn("Failed to create IndexedDB store, using default", error);
|
|
285
|
+
this.customStore = null;
|
|
286
|
+
this.isIndexedDBAvailable = false;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return this.customStore;
|
|
290
|
+
}
|
|
291
|
+
static async setItem(key, value) {
|
|
292
|
+
const secureKey = `${currentConfig.encryptionKeyId}_${key}`;
|
|
293
|
+
if (this.isIndexedDBAvailable) {
|
|
294
|
+
try {
|
|
295
|
+
const store = this.getStore();
|
|
296
|
+
if (store) {
|
|
297
|
+
await idbKeyval.set(secureKey, value, store);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
} catch (error) {
|
|
301
|
+
apiLogger.warn("IndexedDB failed, falling back to localStorage", {
|
|
302
|
+
key: secureKey,
|
|
303
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
304
|
+
});
|
|
305
|
+
this.isIndexedDBAvailable = false;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
localStorage.setItem(`secure_${secureKey}`, value);
|
|
310
|
+
} catch (error) {
|
|
311
|
+
apiLogger.error("Failed to store secure item in localStorage", {
|
|
312
|
+
key: secureKey,
|
|
313
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
314
|
+
});
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
static async getItem(key) {
|
|
319
|
+
const secureKey = `${currentConfig.encryptionKeyId}_${key}`;
|
|
320
|
+
if (this.isIndexedDBAvailable) {
|
|
321
|
+
try {
|
|
322
|
+
const store = this.getStore();
|
|
323
|
+
if (store) {
|
|
324
|
+
const value = await idbKeyval.get(secureKey, store);
|
|
325
|
+
return value ?? null;
|
|
326
|
+
}
|
|
327
|
+
} catch (error) {
|
|
328
|
+
apiLogger.warn("IndexedDB read failed, trying localStorage", {
|
|
329
|
+
key: secureKey,
|
|
330
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
331
|
+
});
|
|
332
|
+
this.isIndexedDBAvailable = false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
const value = localStorage.getItem(`secure_${secureKey}`);
|
|
337
|
+
return value;
|
|
338
|
+
} catch (error) {
|
|
339
|
+
apiLogger.error("Failed to get secure item from localStorage", {
|
|
340
|
+
key: secureKey,
|
|
341
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
342
|
+
});
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
static async removeItem(key) {
|
|
347
|
+
const secureKey = `${currentConfig.encryptionKeyId}_${key}`;
|
|
348
|
+
if (this.isIndexedDBAvailable) {
|
|
349
|
+
try {
|
|
350
|
+
const store = this.getStore();
|
|
351
|
+
if (store) {
|
|
352
|
+
await idbKeyval.del(secureKey, store);
|
|
353
|
+
}
|
|
354
|
+
} catch (error) {
|
|
355
|
+
apiLogger.warn("IndexedDB delete failed", {
|
|
356
|
+
key: secureKey,
|
|
357
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
try {
|
|
362
|
+
localStorage.removeItem(`secure_${secureKey}`);
|
|
363
|
+
} catch (error) {
|
|
364
|
+
apiLogger.warn("localStorage delete failed", {
|
|
365
|
+
key: secureKey,
|
|
366
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Reset IndexedDB availability for testing/recovery
|
|
371
|
+
static resetIndexedDBStatus() {
|
|
372
|
+
this.isIndexedDBAvailable = true;
|
|
373
|
+
this.customStore = null;
|
|
374
|
+
}
|
|
375
|
+
}, chunkXQKCXG4I_cjs.__name(_a3, "WebSecureStorage"), chunkXQKCXG4I_cjs.__publicField(_a3, "customStore", null), chunkXQKCXG4I_cjs.__publicField(_a3, "isIndexedDBAvailable", true), _a3);
|
|
376
|
+
var _SecureTokenStorage = class _SecureTokenStorage {
|
|
377
|
+
// Configuration method
|
|
378
|
+
static configure(config) {
|
|
379
|
+
currentConfig = {
|
|
380
|
+
...DEFAULT_CONFIG,
|
|
381
|
+
...config
|
|
382
|
+
};
|
|
383
|
+
if (isWeb) {
|
|
384
|
+
WebSecureStorage.resetIndexedDBStatus();
|
|
385
|
+
}
|
|
386
|
+
apiLogger.info("SecureTokenStorage configured", {
|
|
387
|
+
encryptionKeyId: currentConfig.encryptionKeyId,
|
|
388
|
+
storeNamespace: currentConfig.storeNamespace
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
// Get current configuration
|
|
392
|
+
static getConfig() {
|
|
393
|
+
return {
|
|
394
|
+
...currentConfig
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
// Store data securely based on platform
|
|
398
|
+
static async setSecureItem(key, value) {
|
|
399
|
+
if (isReactNative) {
|
|
400
|
+
await Keychain__namespace.setInternetCredentials(key, key, value);
|
|
401
|
+
} else {
|
|
402
|
+
await WebSecureStorage.setItem(key, value);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
static async getSecureItem(key) {
|
|
406
|
+
try {
|
|
407
|
+
if (isReactNative) {
|
|
408
|
+
const credentials = await Keychain__namespace.getInternetCredentials(key);
|
|
409
|
+
return credentials ? credentials.password : null;
|
|
410
|
+
} else {
|
|
411
|
+
return await WebSecureStorage.getItem(key);
|
|
412
|
+
}
|
|
413
|
+
} catch (error) {
|
|
414
|
+
apiLogger.warn("Failed to get secure item", {
|
|
415
|
+
key,
|
|
416
|
+
platform: isReactNative ? "react-native" : "web",
|
|
417
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
418
|
+
});
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
static async removeSecureItem(key) {
|
|
423
|
+
try {
|
|
424
|
+
if (isReactNative) {
|
|
425
|
+
await Keychain__namespace.resetInternetCredentials(key);
|
|
426
|
+
} else {
|
|
427
|
+
await WebSecureStorage.removeItem(key);
|
|
428
|
+
}
|
|
429
|
+
} catch (error) {
|
|
430
|
+
apiLogger.warn("Failed to remove secure item", {
|
|
431
|
+
key,
|
|
432
|
+
platform: isReactNative ? "react-native" : "web",
|
|
433
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
// Store data using appropriate method based on sensitivity
|
|
438
|
+
static async setItem(key, value) {
|
|
439
|
+
const isSecure = chunkXQKCXG4I_cjs.SECURE_KEYS.has(key);
|
|
440
|
+
if (isSecure) {
|
|
441
|
+
await this.setSecureItem(key, value);
|
|
442
|
+
} else {
|
|
443
|
+
await AsyncStorage__default.default.setItem(key, value);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
static async getItem(key) {
|
|
447
|
+
const isSecure = chunkXQKCXG4I_cjs.SECURE_KEYS.has(key);
|
|
448
|
+
if (isSecure) {
|
|
449
|
+
return await this.getSecureItem(key);
|
|
450
|
+
} else {
|
|
451
|
+
return await AsyncStorage__default.default.getItem(key);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
static async removeItem(key) {
|
|
455
|
+
const isSecure = chunkXQKCXG4I_cjs.SECURE_KEYS.has(key);
|
|
456
|
+
if (isSecure) {
|
|
457
|
+
await this.removeSecureItem(key);
|
|
458
|
+
} else {
|
|
459
|
+
await AsyncStorage__default.default.removeItem(key);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
// Token-specific methods
|
|
463
|
+
static async storeToken(token) {
|
|
464
|
+
await this.setItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.ACCESS_TOKEN, token.access_token);
|
|
465
|
+
if (token.expires_in) {
|
|
466
|
+
const expiryTime = Date.now() + token.expires_in * 1e3;
|
|
467
|
+
await this.setItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.TOKEN_EXPIRY, expiryTime.toString());
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
static async getToken() {
|
|
471
|
+
return await this.getItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.ACCESS_TOKEN);
|
|
472
|
+
}
|
|
473
|
+
static async isTokenValid() {
|
|
474
|
+
const token = await this.getToken();
|
|
475
|
+
if (!token) return false;
|
|
476
|
+
const expiryStr = await this.getItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.TOKEN_EXPIRY);
|
|
477
|
+
if (!expiryStr) return true;
|
|
478
|
+
const expiry = parseInt(expiryStr, 10);
|
|
479
|
+
return Date.now() < expiry;
|
|
480
|
+
}
|
|
481
|
+
static async removeToken() {
|
|
482
|
+
await Promise.all([
|
|
483
|
+
this.removeItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.ACCESS_TOKEN),
|
|
484
|
+
this.removeItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.TOKEN_EXPIRY),
|
|
485
|
+
this.removeItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.USER_ROLE),
|
|
486
|
+
this.removeItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.USER_EMAIL)
|
|
487
|
+
]);
|
|
488
|
+
}
|
|
489
|
+
// JWT payload extraction
|
|
490
|
+
static parseJWT(token) {
|
|
491
|
+
try {
|
|
492
|
+
const base64Url = token.split(".")[1];
|
|
493
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
494
|
+
const jsonPayload = decodeURIComponent(atob(base64).split("").map((c) => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""));
|
|
495
|
+
return JSON.parse(jsonPayload);
|
|
496
|
+
} catch (error) {
|
|
497
|
+
apiLogger.warn("Failed to parse JWT", {
|
|
498
|
+
tokenLength: token?.length ?? 0,
|
|
499
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
500
|
+
});
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
// Store user info from JWT
|
|
505
|
+
static async storeUserInfo(token) {
|
|
506
|
+
const payload = this.parseJWT(token);
|
|
507
|
+
if (payload) {
|
|
508
|
+
await Promise.all([
|
|
509
|
+
this.setItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.USER_ROLE, payload.role || ""),
|
|
510
|
+
this.setItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.USER_EMAIL, payload.email || "")
|
|
511
|
+
]);
|
|
512
|
+
apiLogger.info("User info stored successfully", {
|
|
513
|
+
email: payload.email,
|
|
514
|
+
role: payload.role,
|
|
515
|
+
hasExpiry: !!payload.exp
|
|
516
|
+
});
|
|
517
|
+
} else {
|
|
518
|
+
apiLogger.warn("Failed to store user info: invalid token payload");
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
static async getUserRole() {
|
|
522
|
+
return await this.getItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.USER_ROLE);
|
|
523
|
+
}
|
|
524
|
+
static async getUserEmail() {
|
|
525
|
+
return await this.getItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.USER_EMAIL);
|
|
526
|
+
}
|
|
527
|
+
// Clear all stored data
|
|
528
|
+
static async clearAll() {
|
|
529
|
+
const keysToRemove = Object.values(chunkXQKCXG4I_cjs.STORAGE_KEYS);
|
|
530
|
+
await Promise.all(keysToRemove.map((key) => this.removeItem(key)));
|
|
531
|
+
apiLogger.info("All stored data cleared", {
|
|
532
|
+
keysCleared: keysToRemove.length
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
// Advanced utility methods
|
|
536
|
+
// Get token expiry information
|
|
537
|
+
static async getTokenExpiryInfo() {
|
|
538
|
+
const expiryStr = await this.getItem(chunkXQKCXG4I_cjs.STORAGE_KEYS.TOKEN_EXPIRY);
|
|
539
|
+
const expiresAt = expiryStr ? parseInt(expiryStr, 10) : null;
|
|
540
|
+
const now = Date.now();
|
|
541
|
+
return {
|
|
542
|
+
expiresAt,
|
|
543
|
+
isExpired: expiresAt ? now >= expiresAt : false,
|
|
544
|
+
expiresInMs: expiresAt ? Math.max(0, expiresAt - now) : null
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
// Check if storage is properly configured and accessible
|
|
548
|
+
static async checkStorageHealth() {
|
|
549
|
+
const issues = [];
|
|
550
|
+
let storageType;
|
|
551
|
+
if (isReactNative) {
|
|
552
|
+
storageType = "keychain";
|
|
553
|
+
try {
|
|
554
|
+
await this.setItem("__health_check__", "test");
|
|
555
|
+
await this.getItem("__health_check__");
|
|
556
|
+
await this.removeItem("__health_check__");
|
|
557
|
+
} catch (error) {
|
|
558
|
+
issues.push("Keychain access failed");
|
|
559
|
+
storageType = "asyncStorage";
|
|
560
|
+
}
|
|
561
|
+
} else {
|
|
562
|
+
try {
|
|
563
|
+
await WebSecureStorage.setItem("__health_check__", "test");
|
|
564
|
+
await WebSecureStorage.getItem("__health_check__");
|
|
565
|
+
await WebSecureStorage.removeItem("__health_check__");
|
|
566
|
+
storageType = "indexeddb";
|
|
567
|
+
} catch (error) {
|
|
568
|
+
issues.push("IndexedDB access failed, using localStorage fallback");
|
|
569
|
+
storageType = "localStorage";
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
const result = {
|
|
573
|
+
isHealthy: issues.length === 0,
|
|
574
|
+
platform: isReactNative ? "react-native" : "web",
|
|
575
|
+
storageType,
|
|
576
|
+
issues
|
|
577
|
+
};
|
|
578
|
+
apiLogger.info("Storage health check completed", result);
|
|
579
|
+
return result;
|
|
580
|
+
}
|
|
581
|
+
// Get storage statistics
|
|
582
|
+
static async getStorageStats() {
|
|
583
|
+
const [token, userRole, userEmail, tokenExpiryInfo] = await Promise.all([
|
|
584
|
+
this.getToken(),
|
|
585
|
+
this.getUserRole(),
|
|
586
|
+
this.getUserEmail(),
|
|
587
|
+
this.getTokenExpiryInfo()
|
|
588
|
+
]);
|
|
589
|
+
return {
|
|
590
|
+
hasToken: !!token,
|
|
591
|
+
hasUserInfo: !!(userRole ?? userEmail),
|
|
592
|
+
tokenExpiryInfo,
|
|
593
|
+
configuredNamespace: currentConfig.storeNamespace,
|
|
594
|
+
encryptionKeyId: currentConfig.encryptionKeyId
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
// Import/Export for migration purposes (development only)
|
|
598
|
+
static async exportData() {
|
|
599
|
+
const keys = Object.values(chunkXQKCXG4I_cjs.STORAGE_KEYS);
|
|
600
|
+
const data = {};
|
|
601
|
+
await Promise.all(keys.map(async (key) => {
|
|
602
|
+
data[key] = await this.getItem(key);
|
|
603
|
+
}));
|
|
604
|
+
apiLogger.info("Data exported", {
|
|
605
|
+
keysExported: Object.keys(data).length
|
|
606
|
+
});
|
|
607
|
+
return data;
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
chunkXQKCXG4I_cjs.__name(_SecureTokenStorage, "SecureTokenStorage");
|
|
611
|
+
var SecureTokenStorage = _SecureTokenStorage;
|
|
612
|
+
|
|
613
|
+
exports.SecureTokenStorage = SecureTokenStorage;
|
|
614
|
+
exports.apiLogger = apiLogger;
|
|
615
|
+
exports.authLogger = authLogger;
|
|
616
|
+
exports.logDebug = logDebug;
|
|
617
|
+
exports.logError = logError;
|
|
618
|
+
exports.logInfo = logInfo;
|
|
619
|
+
exports.logWarn = logWarn;
|
|
620
|
+
exports.networkLogger = networkLogger;
|
|
621
|
+
exports.storageLogger = storageLogger;
|
|
622
|
+
exports.uiLogger = uiLogger;
|
|
623
|
+
//# sourceMappingURL=chunk-24ZJ6SNG.cjs.map
|
|
624
|
+
//# sourceMappingURL=chunk-24ZJ6SNG.cjs.map
|