@arbidocs/client 0.5.58 → 0.5.60
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/README.md +10 -0
- package/dist/index.cjs +61 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -6
- package/dist/index.d.ts +30 -6
- package/dist/index.js +59 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -281,6 +281,16 @@ import {
|
|
|
281
281
|
} from '@arbidocs/client'
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
+
### Logger
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import { configureLogger, logger } from '@arbidocs/client'
|
|
288
|
+
|
|
289
|
+
configureLogger({ verbose: import.meta.env.DEV }) // once, at startup
|
|
290
|
+
logger.error('always printed')
|
|
291
|
+
logger.warn('printed only when verbose') // likewise info, debug
|
|
292
|
+
```
|
|
293
|
+
|
|
284
294
|
## How It Works
|
|
285
295
|
|
|
286
296
|
### Zero-Knowledge Auth
|
package/dist/index.cjs
CHANGED
|
@@ -10,6 +10,36 @@ var sodium__default = /*#__PURE__*/_interopDefault(sodium);
|
|
|
10
10
|
|
|
11
11
|
// src/client.ts
|
|
12
12
|
|
|
13
|
+
// src/memory-persistence.ts
|
|
14
|
+
function copy(keys) {
|
|
15
|
+
return {
|
|
16
|
+
...keys,
|
|
17
|
+
signingPrivateKey: keys.signingPrivateKey.slice(),
|
|
18
|
+
...keys.serverSessionKey ? { serverSessionKey: keys.serverSessionKey.slice() } : {}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function createMemorySessionPersistence() {
|
|
22
|
+
let saved = null;
|
|
23
|
+
const clear = () => {
|
|
24
|
+
saved?.signingPrivateKey.fill(0);
|
|
25
|
+
saved?.serverSessionKey?.fill(0);
|
|
26
|
+
saved = null;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
async getSession() {
|
|
30
|
+
return saved ? copy(saved) : null;
|
|
31
|
+
},
|
|
32
|
+
async saveSession(keys) {
|
|
33
|
+
const next = copy(keys);
|
|
34
|
+
clear();
|
|
35
|
+
saved = next;
|
|
36
|
+
},
|
|
37
|
+
async clearSession() {
|
|
38
|
+
clear();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
13
43
|
// src/http-transport.ts
|
|
14
44
|
function createHttpTransport(options = {}) {
|
|
15
45
|
const { timeoutMs } = options;
|
|
@@ -2013,8 +2043,8 @@ function createArbiClient(options) {
|
|
|
2013
2043
|
decryptMessageWithSharedSecret
|
|
2014
2044
|
},
|
|
2015
2045
|
storage: {
|
|
2016
|
-
getSession,
|
|
2017
|
-
saveSession
|
|
2046
|
+
getSession: () => persistence.getSession(),
|
|
2047
|
+
saveSession: (data) => persistence.saveSession(data)
|
|
2018
2048
|
}
|
|
2019
2049
|
};
|
|
2020
2050
|
}
|
|
@@ -2028,7 +2058,7 @@ function createTransport(options) {
|
|
|
2028
2058
|
onRetryCloneFailed,
|
|
2029
2059
|
userEmail
|
|
2030
2060
|
} = options;
|
|
2031
|
-
const persistence = options.persistence ?? { getSession, saveSession };
|
|
2061
|
+
const persistence = options.persistence ?? (typeof indexedDB === "undefined" ? createMemorySessionPersistence() : { getSession, saveSession, clearSession: clearAllData });
|
|
2032
2062
|
const baseUrlOption = options.baseUrl;
|
|
2033
2063
|
const base = typeof baseUrlOption === "function" ? baseUrlOption : () => baseUrlOption;
|
|
2034
2064
|
const transport = createHttpTransport(options.transport);
|
|
@@ -2290,7 +2320,10 @@ function createTransport(options) {
|
|
|
2290
2320
|
}).catch((error) => console.warn("[API] Server logout failed:", error));
|
|
2291
2321
|
}
|
|
2292
2322
|
session.clear();
|
|
2293
|
-
if (everywhere)
|
|
2323
|
+
if (everywhere) {
|
|
2324
|
+
if (persistence.clearSession) await persistence.clearSession();
|
|
2325
|
+
else if (typeof indexedDB !== "undefined") await clearAllData();
|
|
2326
|
+
}
|
|
2294
2327
|
} finally {
|
|
2295
2328
|
gate.reopen();
|
|
2296
2329
|
}
|
|
@@ -2373,6 +2406,27 @@ function isMessageType(msg, type) {
|
|
|
2373
2406
|
return msg.type === type;
|
|
2374
2407
|
}
|
|
2375
2408
|
|
|
2409
|
+
// src/logger.ts
|
|
2410
|
+
var verbose = false;
|
|
2411
|
+
function configureLogger(options) {
|
|
2412
|
+
verbose = options.verbose;
|
|
2413
|
+
}
|
|
2414
|
+
var logger = {
|
|
2415
|
+
/** Always printed, production included. */
|
|
2416
|
+
error: (...args) => {
|
|
2417
|
+
console.error(...args);
|
|
2418
|
+
},
|
|
2419
|
+
warn: (...args) => {
|
|
2420
|
+
if (verbose) console.warn(...args);
|
|
2421
|
+
},
|
|
2422
|
+
info: (...args) => {
|
|
2423
|
+
if (verbose) console.info(...args);
|
|
2424
|
+
},
|
|
2425
|
+
debug: (...args) => {
|
|
2426
|
+
if (verbose) console.debug(...args);
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
|
|
2376
2430
|
exports.ACCESS_TOKEN_STORAGE_KEY = ACCESS_TOKEN_STORAGE_KEY;
|
|
2377
2431
|
exports.API_PREFIX = API_PREFIX;
|
|
2378
2432
|
exports.CALL_KEY_BYTES = CALL_KEY_BYTES;
|
|
@@ -2397,6 +2451,7 @@ exports.changePassword = changePassword;
|
|
|
2397
2451
|
exports.clearAllData = clearAllData;
|
|
2398
2452
|
exports.clearSession = clearSession;
|
|
2399
2453
|
exports.computeSharedSecret = computeSharedSecret;
|
|
2454
|
+
exports.configureLogger = configureLogger;
|
|
2400
2455
|
exports.createAllWorkspacesOpener = createAllWorkspacesOpener;
|
|
2401
2456
|
exports.createArbiClient = createArbiClient;
|
|
2402
2457
|
exports.createAuthMessage = createAuthMessage;
|
|
@@ -2404,6 +2459,7 @@ exports.createAutoReloginMiddleware = createAutoReloginMiddleware;
|
|
|
2404
2459
|
exports.createBearerAuthMiddleware = createBearerAuthMiddleware;
|
|
2405
2460
|
exports.createContentHash = createContentHash;
|
|
2406
2461
|
exports.createHttpTransport = createHttpTransport;
|
|
2462
|
+
exports.createMemorySessionPersistence = createMemorySessionPersistence;
|
|
2407
2463
|
exports.createOfflineSealer = createOfflineSealer;
|
|
2408
2464
|
exports.createRecoveryFile = createRecoveryFile;
|
|
2409
2465
|
exports.createRecoveryUrl = createRecoveryUrl;
|
|
@@ -2452,6 +2508,7 @@ exports.initializeDatabase = initializeDatabase;
|
|
|
2452
2508
|
exports.isAbortError = isAbortError;
|
|
2453
2509
|
exports.isEncryptedRecoveryKey = isEncryptedRecoveryKey;
|
|
2454
2510
|
exports.isMessageType = isMessageType;
|
|
2511
|
+
exports.logger = logger;
|
|
2455
2512
|
exports.openCallKeyOf = openCallKeyOf;
|
|
2456
2513
|
exports.openSealedCallKey = openSealedCallKey;
|
|
2457
2514
|
exports.openSealedChatKey = openSealedChatKey;
|