@oxidezap/baileyrs 0.3.9 → 0.3.11
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 +29 -0
- package/lib/Bridge/schema.js +57 -16
- package/lib/Bridge/types.d.ts +26 -5
- package/lib/Compatibility/auth-state.js +2 -11
- package/lib/Compatibility/group-metadata.js +2 -2
- package/lib/Compatibility/host-auth-state.js +2 -0
- package/lib/Compatibility/internal/auth-state.js +6 -0
- package/lib/Compatibility/internal/host-auth-state.js +3 -0
- package/lib/Compatibility/legacy-store/adapter.js +137 -3
- package/lib/Compatibility/legacy-store/codecs/basic.js +5 -8
- package/lib/Compatibility/legacy-store/multi-file.d.ts +12 -1
- package/lib/Compatibility/legacy-store/multi-file.js +37 -25
- package/lib/Compatibility/legacy-store/record-files.d.ts +3 -0
- package/lib/Compatibility/legacy-store/record-files.js +5 -0
- package/lib/Compatibility/legacy-store/rollback.d.ts +8 -0
- package/lib/Compatibility/legacy-store/rollback.js +16 -0
- package/lib/Compatibility/legacy-store/snapshot.d.ts +7 -0
- package/lib/Compatibility/legacy-store/snapshot.js +53 -0
- package/lib/Compatibility/legacy-store/types.d.ts +4 -1
- package/lib/Compatibility/newsletter-results.d.ts +2 -3
- package/lib/Compatibility/newsletter-results.js +3 -3
- package/lib/Compatibility/reachout.d.ts +17 -0
- package/lib/Compatibility/reachout.js +47 -0
- package/lib/Socket/chat-actions.js +1 -1
- package/lib/Socket/communities.js +10 -5
- package/lib/Socket/core.js +10 -3
- package/lib/Socket/events-core.js +19 -10
- package/lib/Socket/groups.js +10 -5
- package/lib/Socket/index.d.ts +3 -717
- package/lib/Socket/newsletter.d.ts +3 -3
- package/lib/Socket/newsletter.js +5 -5
- package/lib/Socket/reachout.d.ts +1 -21
- package/lib/Socket/reachout.js +1 -49
- package/lib/Types/Auth.d.ts +5 -0
- package/lib/Types/Events.d.ts +6 -1
- package/lib/Utils/atomic-store.d.ts +20 -0
- package/lib/Utils/atomic-store.js +116 -0
- package/lib/Utils/durable-directory.d.ts +3 -0
- package/lib/Utils/durable-directory.js +35 -0
- package/lib/Utils/flush-deadline.d.ts +19 -0
- package/lib/Utils/flush-deadline.js +97 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/native-auth-rollback.d.ts +14 -0
- package/lib/Utils/native-auth-rollback.js +17 -0
- package/lib/Utils/process-file-lock.d.ts +6 -0
- package/lib/Utils/process-file-lock.js +38 -0
- package/lib/Utils/snapshot-rollback-proof.d.ts +9 -0
- package/lib/Utils/snapshot-rollback-proof.js +43 -0
- package/lib/Utils/snapshot-rollback.d.ts +5 -0
- package/lib/Utils/snapshot-rollback.js +69 -0
- package/lib/Utils/snapshot-transactions.d.ts +10 -0
- package/lib/Utils/snapshot-transactions.js +108 -0
- package/lib/Utils/store-migration.d.ts +10 -0
- package/lib/Utils/store-migration.js +16 -0
- package/lib/Utils/transactional-file-store.d.ts +7 -0
- package/lib/Utils/transactional-file-store.js +157 -0
- package/lib/Utils/use-bridge-store.d.ts +3 -49
- package/lib/Utils/use-bridge-store.js +121 -109
- package/lib/Utils/use-memory-store.js +17 -4
- package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
- package/lib/Utils/use-multi-file-auth-state.js +2 -2
- package/lib/Utils/wrap-legacy-store.d.ts +1 -0
- package/lib/Utils/wrap-legacy-store.js +1 -0
- package/lib/host-types.d.ts +1 -15
- package/lib/node-surface.d.ts +2 -1
- package/lib/node-surface.js +2 -1
- package/package.json +10 -8
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { recordFlushFailure, settledFlushError, trackFlushFailures, withTrackedFailures } from './flush-deadline.js';
|
|
2
|
+
import { defaultSyncDir } from './durable-directory.js';
|
|
3
|
+
import { transactionalFileStore } from './transactional-file-store.js';
|
|
1
4
|
import { Buffer } from 'node:buffer';
|
|
2
5
|
import { mkdir, open, readdir, readFile, rename, unlink } from 'node:fs/promises';
|
|
3
6
|
import { randomBytes } from 'node:crypto';
|
|
@@ -73,14 +76,7 @@ const copyBytes = (value) => Uint8Array.from(value);
|
|
|
73
76
|
* `platform` defaults to the running platform; tests pass explicit values
|
|
74
77
|
* to cover the matrix deterministically on any OS.
|
|
75
78
|
*/
|
|
76
|
-
export
|
|
77
|
-
const code = errnoOf(e);
|
|
78
|
-
if (code === 'ENOSYS' || code === 'ENOTSUP')
|
|
79
|
-
return true;
|
|
80
|
-
if (platform === 'win32' && (code === 'EINVAL' || code === 'EPERM' || code === 'EISDIR'))
|
|
81
|
-
return true;
|
|
82
|
-
return false;
|
|
83
|
-
};
|
|
79
|
+
export { isUnsupportedDirSync } from './durable-directory.js';
|
|
84
80
|
// Thrown by `durableWrite` when the temp file was published (rename
|
|
85
81
|
// attempted) but the post-rename barrier did not certify. At that point
|
|
86
82
|
// the target may or may not hold the new bytes, so prior durable
|
|
@@ -92,30 +88,6 @@ class BarrierUncertainty extends Error {
|
|
|
92
88
|
this.detail = detail;
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
|
-
const defaultSyncDir = async (dir) => {
|
|
96
|
-
let handle;
|
|
97
|
-
try {
|
|
98
|
-
handle = await open(dir, 'r');
|
|
99
|
-
}
|
|
100
|
-
catch (e) {
|
|
101
|
-
// A store folder that cannot even be opened is not a platform
|
|
102
|
-
// quirk, except where the platform cannot open directory handles
|
|
103
|
-
// at all (classified above).
|
|
104
|
-
if (!isUnsupportedDirSync(e))
|
|
105
|
-
throw e;
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
try {
|
|
109
|
-
await handle.sync();
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
if (!isUnsupportedDirSync(e))
|
|
113
|
-
throw e;
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
await handle.close().catch(() => { });
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
91
|
// Exclusive temp creation with a restrictive mode for sensitive auth
|
|
120
92
|
// bytes. `0o600` regardless of umask: replacement renames this inode over
|
|
121
93
|
// the target, so an existing `0600` file can never be widened (a previously
|
|
@@ -176,6 +148,8 @@ let tmpSeq = 0;
|
|
|
176
148
|
* with any failure stops at that pass and leaves the failed entries
|
|
177
149
|
* for the next explicit flush. `flush()` never reports quiescence
|
|
178
150
|
* while prior admitted work is still running.
|
|
151
|
+
* - A 30s flush timeout leaves backend operations and their locks pending.
|
|
152
|
+
* Await a later successful flush before deleting auth state or starting an older writer.
|
|
179
153
|
* - All operations on one key (set, delete, flush, concurrent batches) run
|
|
180
154
|
* through a per-key chain, so a stale failure can never erase newer
|
|
181
155
|
* state and an in-flight write can never resurrect a deleted key.
|
|
@@ -192,7 +166,7 @@ let tmpSeq = 0;
|
|
|
192
166
|
* seam only: the default implementation is the sole provider of the
|
|
193
167
|
* durability contract above.
|
|
194
168
|
*/
|
|
195
|
-
|
|
169
|
+
async function usePerKeyBridgeStore(folder, options) {
|
|
196
170
|
await mkdir(folder, { recursive: true });
|
|
197
171
|
const openTmp = options?.io?.openTmp ?? realOpenTmp;
|
|
198
172
|
const io = {
|
|
@@ -345,15 +319,21 @@ export async function useBridgeStore(folder, options) {
|
|
|
345
319
|
// `flush()` wait on itself). On failure the entry is RETAINED (timer
|
|
346
320
|
// cleared) so an explicit `flush()` retries the same bytes, and the
|
|
347
321
|
// error propagates to that caller.
|
|
348
|
-
const flushOne = (cacheKey) => withKeyLockInternal(cacheKey, async () => {
|
|
322
|
+
const flushOne = (cacheKey, failedEntries) => withKeyLockInternal(cacheKey, async () => {
|
|
349
323
|
const pending = pendingWrites.get(cacheKey);
|
|
350
|
-
if (!pending)
|
|
324
|
+
if (!pending || failedEntries?.has(pending))
|
|
351
325
|
return;
|
|
352
326
|
if (pending.timer) {
|
|
353
327
|
clearTimeout(pending.timer);
|
|
354
328
|
pending.timer = undefined;
|
|
355
329
|
}
|
|
356
|
-
|
|
330
|
+
try {
|
|
331
|
+
await certifyWrite(cacheKey, pending.path, pending.value);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
failedEntries?.add(pending);
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
357
337
|
if (pendingWrites.get(cacheKey) === pending)
|
|
358
338
|
pendingWrites.delete(cacheKey);
|
|
359
339
|
});
|
|
@@ -372,53 +352,68 @@ export async function useBridgeStore(folder, options) {
|
|
|
372
352
|
return next;
|
|
373
353
|
};
|
|
374
354
|
const FLUSH_MAX_PASSES = 32;
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
// never waits on the drain loop itself (no self-deadlock).
|
|
383
|
-
// Failures observed by the barrier propagate: a failed admitted
|
|
384
|
-
// write fails the flush. Only operations outstanding during this
|
|
385
|
-
// flush are reported — settled history never poisons later flushes.
|
|
386
|
-
// After a drain pass with any failure, stop and leave the failed
|
|
387
|
-
// entries for a subsequent explicit flush: retrying them inside the
|
|
388
|
-
// same call would resolve-or-reject on a stale error while hiding
|
|
389
|
-
// whether the retry itself persisted. A fully successful pass loops,
|
|
390
|
-
// since new work may have landed during the drain. The pass cap only
|
|
391
|
-
// guards a caller emitting writes in a tight loop —
|
|
392
|
-
// `Socket/index.ts.end()` waits on this and must return.
|
|
393
|
-
const errors = [];
|
|
394
|
-
for (let i = 0; i < FLUSH_MAX_PASSES; i++) {
|
|
395
|
-
const outstanding = [...admitted];
|
|
396
|
-
if (outstanding.length > 0) {
|
|
397
|
-
const settled = await Promise.allSettled(outstanding);
|
|
398
|
-
for (const result of settled) {
|
|
399
|
-
if (result.status === 'rejected')
|
|
400
|
-
errors.push(result.reason);
|
|
401
|
-
}
|
|
355
|
+
const newDrainScope = () => ({ failedEntries: new WeakSet() });
|
|
356
|
+
const flushAll = (scope = newDrainScope()) => {
|
|
357
|
+
const errors = new Map();
|
|
358
|
+
const drain = async () => {
|
|
359
|
+
if (scope.exhausted) {
|
|
360
|
+
errors.set(scope.exhausted.operation, scope.exhausted.error);
|
|
361
|
+
throw scope.exhausted.error;
|
|
402
362
|
}
|
|
403
|
-
|
|
404
|
-
|
|
363
|
+
const eligibleKeys = () => [...pendingWrites].filter(([, entry]) => !scope.failedEntries.has(entry)).map(([key]) => key);
|
|
364
|
+
// Each pass first waits for every operation admitted so far
|
|
365
|
+
// (barrier), then drains the pending writes those operations
|
|
366
|
+
// produced. A `set()` queued just before `flush()` is therefore
|
|
367
|
+
// observed even if it had not reached `pendingWrites` yet, and an
|
|
368
|
+
// already-running critical write completes before quiescence is
|
|
369
|
+
// declared. `flushOne` internals are not admitted, so the barrier
|
|
370
|
+
// never waits on the drain loop itself (no self-deadlock).
|
|
371
|
+
// Failures observed by the barrier propagate: a failed admitted
|
|
372
|
+
// write fails the flush. Only operations outstanding during this
|
|
373
|
+
// flush are reported — settled history never poisons later flushes.
|
|
374
|
+
// After a drain pass with any failure, stop and leave the failed
|
|
375
|
+
// entries for a subsequent explicit flush: retrying them inside the
|
|
376
|
+
// same call would resolve-or-reject on a stale error while hiding
|
|
377
|
+
// whether the retry itself persisted. A fully successful pass loops,
|
|
378
|
+
// since new work may have landed during the drain. The pass cap only
|
|
379
|
+
// guards a caller emitting writes in a tight loop —
|
|
380
|
+
// `Socket/index.ts.end()` waits on this and must return.
|
|
381
|
+
for (let i = 0; i < FLUSH_MAX_PASSES; i++) {
|
|
382
|
+
const outstanding = [...admitted];
|
|
383
|
+
if (outstanding.length > 0) {
|
|
384
|
+
await Promise.all(outstanding.map(operation => operation.catch(error => {
|
|
385
|
+
recordFlushFailure(errors, operation, error);
|
|
386
|
+
})));
|
|
387
|
+
}
|
|
388
|
+
if (eligibleKeys().length === 0) {
|
|
389
|
+
if (admitted.size === 0)
|
|
390
|
+
break;
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const keys = eligibleKeys();
|
|
394
|
+
let failed = false;
|
|
395
|
+
await Promise.all(keys.map(key => {
|
|
396
|
+
const operation = flushOne(key, scope.failedEntries);
|
|
397
|
+
return operation.then(() => { }, e => {
|
|
398
|
+
failed = true;
|
|
399
|
+
recordFlushFailure(errors, operation, e);
|
|
400
|
+
});
|
|
401
|
+
}));
|
|
402
|
+
if (failed)
|
|
405
403
|
break;
|
|
406
|
-
continue;
|
|
407
404
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
throw new Error(`use-bridge-store flushAll did not quiesce after ${FLUSH_MAX_PASSES} passes (${pendingWrites.size} pending writes, ${admitted.size} in-flight operations remain)`);
|
|
421
|
-
}
|
|
405
|
+
if (errors.size)
|
|
406
|
+
throw settledFlushError('use-bridge-store flush failed', errors.values());
|
|
407
|
+
if (eligibleKeys().length > 0 || admitted.size > 0) {
|
|
408
|
+
scope.exhausted = {
|
|
409
|
+
operation: Promise.resolve(),
|
|
410
|
+
error: new Error(`use-bridge-store flushAll did not quiesce after ${FLUSH_MAX_PASSES} passes (${pendingWrites.size} pending writes, ${admitted.size} in-flight operations remain)`)
|
|
411
|
+
};
|
|
412
|
+
errors.set(scope.exhausted.operation, scope.exhausted.error);
|
|
413
|
+
throw scope.exhausted.error;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
return trackFlushFailures(drain(), errors);
|
|
422
417
|
};
|
|
423
418
|
// Write path shared by `set` and `setMany`. `incoming` is already a
|
|
424
419
|
// private admission-time copy. Must run under the key lock — callers
|
|
@@ -430,7 +425,7 @@ export async function useBridgeStore(folder, options) {
|
|
|
430
425
|
// resolving without persisting.
|
|
431
426
|
const pending = pendingWrites.get(cacheKey);
|
|
432
427
|
if (pending) {
|
|
433
|
-
if (bytesEqual(pending.value, incoming))
|
|
428
|
+
if (bytesEqual(pending.value, incoming) && pending.timer !== undefined)
|
|
434
429
|
return;
|
|
435
430
|
}
|
|
436
431
|
else {
|
|
@@ -582,11 +577,11 @@ export async function useBridgeStore(folder, options) {
|
|
|
582
577
|
// don't depend on `this` — the bridge invokes every store callback with
|
|
583
578
|
// `this = null`. Best-effort across keys: every key is attempted even
|
|
584
579
|
// when a sibling fails, and the first error propagates.
|
|
585
|
-
const doDeleteMany =
|
|
580
|
+
const doDeleteMany = (store, keys) => withTrackedFailures(async (observe) => {
|
|
586
581
|
if (keys.length === 0)
|
|
587
582
|
return;
|
|
588
|
-
await Promise.all(keys.map(key => doDeleteOne(store, key)));
|
|
589
|
-
};
|
|
583
|
+
await Promise.all(keys.map(key => observe(doDeleteOne(store, key))));
|
|
584
|
+
});
|
|
590
585
|
// Enumerate live keys in a namespace (shared by `listKeys` and
|
|
591
586
|
// `deletePrefix`). Closure, not a method, so it never depends on `this`.
|
|
592
587
|
// Files are `<store>-<encodeURIComponent(key)>.bin`; store names never
|
|
@@ -595,8 +590,8 @@ export async function useBridgeStore(folder, options) {
|
|
|
595
590
|
// before the readdir; its failure propagates rather than enumerating a
|
|
596
591
|
// stale view. Pending deletes both cancel their `pendingWrites` entry
|
|
597
592
|
// AND unlink immediately, so they never appear here.
|
|
598
|
-
const doListKeys =
|
|
599
|
-
await flushAll();
|
|
593
|
+
const doListKeys = (store, prefix) => withTrackedFailures(async (observe) => {
|
|
594
|
+
await observe(flushAll());
|
|
600
595
|
const filePrefix = `${store}-`;
|
|
601
596
|
const found = new Set();
|
|
602
597
|
let entries;
|
|
@@ -639,8 +634,8 @@ export async function useBridgeStore(folder, options) {
|
|
|
639
634
|
found.add(key);
|
|
640
635
|
}
|
|
641
636
|
return [...found];
|
|
642
|
-
};
|
|
643
|
-
|
|
637
|
+
});
|
|
638
|
+
const callbacks = {
|
|
644
639
|
get: doGet,
|
|
645
640
|
set: doSet,
|
|
646
641
|
delete: doDeleteOne,
|
|
@@ -653,14 +648,16 @@ export async function useBridgeStore(folder, options) {
|
|
|
653
648
|
// a sibling fails (writes are idempotent by key, so the core can
|
|
654
649
|
// retry the batch), and the first error propagates. No multi-key
|
|
655
650
|
// transaction is attempted — the filesystem does not provide one.
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
651
|
+
setMany(store, entries) {
|
|
652
|
+
return withTrackedFailures(async (observe) => {
|
|
653
|
+
// Empty batch is a valid no-op.
|
|
654
|
+
if (entries.length === 0)
|
|
655
|
+
return;
|
|
656
|
+
// Schedule every entry synchronously so same-key duplicates chain
|
|
657
|
+
// in batch order; per-key locks serialize against concurrent
|
|
658
|
+
// sets, deletes and flushes.
|
|
659
|
+
await Promise.all(entries.map(([key, value]) => observe(doSet(store, key, value))));
|
|
660
|
+
});
|
|
664
661
|
},
|
|
665
662
|
// Batched variant of `delete`. Per-key semantics are identical to
|
|
666
663
|
// `delete`; unlinks run concurrently via Promise.all.
|
|
@@ -668,25 +665,40 @@ export async function useBridgeStore(folder, options) {
|
|
|
668
665
|
// Read many keys at once. Cache-aside per key (like `get`), so a hit
|
|
669
666
|
// never touches disk; misses read the file. Missing keys are omitted;
|
|
670
667
|
// real read failures propagate rather than silently dropping keys.
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
668
|
+
getMany(store, keys) {
|
|
669
|
+
return withTrackedFailures(async (observe) => {
|
|
670
|
+
if (keys.length === 0)
|
|
671
|
+
return [];
|
|
672
|
+
const results = await Promise.all(keys.map(async (key) => {
|
|
673
|
+
const value = await observe(doGet(store, key));
|
|
674
|
+
return value === null ? null : [key, value];
|
|
675
|
+
}));
|
|
676
|
+
return results.filter((r) => r !== null);
|
|
677
|
+
});
|
|
679
678
|
},
|
|
680
679
|
listKeys: doListKeys,
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
680
|
+
deletePrefix(store, prefix) {
|
|
681
|
+
return withTrackedFailures(async (observe) => {
|
|
682
|
+
const keys = await observe(doListKeys(store, prefix));
|
|
683
|
+
await observe(doDeleteMany(store, keys));
|
|
684
|
+
return keys.length;
|
|
685
|
+
});
|
|
685
686
|
},
|
|
686
687
|
// File-per-key can do everything; enumeration via readdir lets the core
|
|
687
688
|
// drop its hand-maintained meta-indexes for this backend.
|
|
688
689
|
capabilities: { batch: true, enumerate: true, prefixDelete: true },
|
|
689
|
-
flush: flushAll
|
|
690
|
+
flush: () => flushAll()
|
|
690
691
|
};
|
|
692
|
+
return {
|
|
693
|
+
callbacks,
|
|
694
|
+
createFlushDrain: () => {
|
|
695
|
+
const scope = newDrainScope();
|
|
696
|
+
return () => flushAll(scope);
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
export async function useBridgeStore(folder, options = {}) {
|
|
701
|
+
const { callbacks, createFlushDrain } = await usePerKeyBridgeStore(folder, options);
|
|
702
|
+
return transactionalFileStore(folder, callbacks, options.io?.syncDir ?? defaultSyncDir, options, createFlushDrain);
|
|
691
703
|
}
|
|
692
704
|
//# sourceMappingURL=use-bridge-store.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { atomicCallbacks, rowKey } from './atomic-store.js';
|
|
1
2
|
import { markNativeMemoryStore } from '../Compatibility/internal/native-memory-store.js';
|
|
2
3
|
/**
|
|
3
4
|
* Creates a purely in-memory authentication store.
|
|
@@ -22,11 +23,23 @@ export function useMemoryStore(options = {}) {
|
|
|
22
23
|
stores.delete(store);
|
|
23
24
|
};
|
|
24
25
|
const memoryStore = {
|
|
26
|
+
...atomicCallbacks(async (change) => {
|
|
27
|
+
const rows = new Map();
|
|
28
|
+
for (const [namespace, bucket] of stores)
|
|
29
|
+
for (const [key, value] of bucket)
|
|
30
|
+
rows.set(rowKey(namespace, key), value);
|
|
31
|
+
change(rows);
|
|
32
|
+
stores.clear();
|
|
33
|
+
for (const [rawKey, value] of rows) {
|
|
34
|
+
const [namespace, key] = JSON.parse(rawKey);
|
|
35
|
+
bucketForWrite(namespace).set(key, value);
|
|
36
|
+
}
|
|
37
|
+
}),
|
|
25
38
|
async get(store, key) {
|
|
26
|
-
return stores.get(store)?.get(key) ?? null;
|
|
39
|
+
return stores.get(store)?.get(key)?.slice() ?? null;
|
|
27
40
|
},
|
|
28
41
|
async set(store, key, value) {
|
|
29
|
-
bucketForWrite(store).set(key, value);
|
|
42
|
+
bucketForWrite(store).set(key, Uint8Array.from(value));
|
|
30
43
|
},
|
|
31
44
|
async delete(store, key) {
|
|
32
45
|
const bucket = stores.get(store);
|
|
@@ -40,7 +53,7 @@ export function useMemoryStore(options = {}) {
|
|
|
40
53
|
return;
|
|
41
54
|
const bucket = bucketForWrite(store);
|
|
42
55
|
for (const [key, value] of entries)
|
|
43
|
-
bucket.set(key, value);
|
|
56
|
+
bucket.set(key, Uint8Array.from(value));
|
|
44
57
|
},
|
|
45
58
|
async getMany(store, keys) {
|
|
46
59
|
const bucket = stores.get(store);
|
|
@@ -50,7 +63,7 @@ export function useMemoryStore(options = {}) {
|
|
|
50
63
|
for (const key of keys) {
|
|
51
64
|
const value = bucket.get(key);
|
|
52
65
|
if (value !== undefined)
|
|
53
|
-
out.push([key, value]);
|
|
66
|
+
out.push([key, Uint8Array.from(value)]);
|
|
54
67
|
}
|
|
55
68
|
return out;
|
|
56
69
|
},
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StoreMigrationOptions } from './store-migration.js';
|
|
1
2
|
import type { AuthenticationState } from '../Types/index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Creates a file-based authentication state for the Rust bridge.
|
|
@@ -15,7 +16,7 @@ import type { AuthenticationState } from '../Types/index.js';
|
|
|
15
16
|
*
|
|
16
17
|
* @param folder Directory to store bridge state files
|
|
17
18
|
*/
|
|
18
|
-
export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
19
|
+
export declare const useMultiFileAuthState: (folder: string, options?: StoreMigrationOptions) => Promise<{
|
|
19
20
|
state: AuthenticationState;
|
|
20
21
|
saveCreds: () => Promise<void>;
|
|
21
22
|
}>;
|
|
@@ -55,7 +55,7 @@ const hydrateFromStore = async (store, creds) => {
|
|
|
55
55
|
*
|
|
56
56
|
* @param folder Directory to store bridge state files
|
|
57
57
|
*/
|
|
58
|
-
export const useMultiFileAuthState = async (folder) => {
|
|
58
|
+
export const useMultiFileAuthState = async (folder, options = {}) => {
|
|
59
59
|
const folderInfo = await stat(folder).catch(() => { });
|
|
60
60
|
if (folderInfo) {
|
|
61
61
|
if (!folderInfo.isDirectory()) {
|
|
@@ -65,7 +65,7 @@ export const useMultiFileAuthState = async (folder) => {
|
|
|
65
65
|
else {
|
|
66
66
|
await mkdir(folder, { recursive: true });
|
|
67
67
|
}
|
|
68
|
-
const store = await useBridgeStore(folder);
|
|
68
|
+
const store = await useBridgeStore(folder, options);
|
|
69
69
|
const creds = initAuthCreds();
|
|
70
70
|
// Before `projectNativeStore`, and that ordering is the whole point: the
|
|
71
71
|
// projection captures `signedIdentityKey.public` and `registrationId` off
|
|
@@ -10,4 +10,5 @@ export { wrapLegacyStore } from '../Compatibility/legacy-store/adapter.js';
|
|
|
10
10
|
export { useLegacyMultiFileAuthState } from '../Compatibility/legacy-store/multi-file.js';
|
|
11
11
|
export { BRIDGE_INTERNAL_KEY_PREFIX, BRIDGE_INTERNAL_KEY_TYPES, isBridgeInternalKeyType } from '../Compatibility/legacy-store/namespaces.js';
|
|
12
12
|
export type { WrappedLegacyStore } from '../Compatibility/legacy-store/types.js';
|
|
13
|
+
export { prepareLegacyAuthRollback } from '../Compatibility/legacy-store/rollback.js';
|
|
13
14
|
//# sourceMappingURL=wrap-legacy-store.d.ts.map
|
|
@@ -9,4 +9,5 @@
|
|
|
9
9
|
export { wrapLegacyStore } from '../Compatibility/legacy-store/adapter.js';
|
|
10
10
|
export { useLegacyMultiFileAuthState } from '../Compatibility/legacy-store/multi-file.js';
|
|
11
11
|
export { BRIDGE_INTERNAL_KEY_PREFIX, BRIDGE_INTERNAL_KEY_TYPES, isBridgeInternalKeyType } from '../Compatibility/legacy-store/namespaces.js';
|
|
12
|
+
export { prepareLegacyAuthRollback } from '../Compatibility/legacy-store/rollback.js';
|
|
12
13
|
//# sourceMappingURL=wrap-legacy-store.js.map
|
package/lib/host-types.d.ts
CHANGED
|
@@ -4,21 +4,7 @@ import type { HostSocketOperationName } from './host-socket-operations.js';
|
|
|
4
4
|
import type * as HostBridge from '@oxidezap/whatsapp-rust-bridge/host';
|
|
5
5
|
import type Long from 'long';
|
|
6
6
|
export type HostLoggerSink = (line: string, delivered: () => void) => void;
|
|
7
|
-
export type HostStoreCallbacks = {
|
|
8
|
-
get(store: string, key: string): Promise<Uint8Array | null>;
|
|
9
|
-
set(store: string, key: string, value: Uint8Array): Promise<void>;
|
|
10
|
-
delete(store: string, key: string): Promise<void>;
|
|
11
|
-
setMany?(store: string, entries: [key: string, value: Uint8Array][]): Promise<void>;
|
|
12
|
-
getMany?(store: string, keys: string[]): Promise<[key: string, value: Uint8Array][]>;
|
|
13
|
-
deleteMany?(store: string, keys: string[]): Promise<void>;
|
|
14
|
-
listKeys?(store: string, prefix?: string): Promise<string[]>;
|
|
15
|
-
listEntries?(store: string, prefix?: string): Promise<[key: string, value: Uint8Array][]>;
|
|
16
|
-
deletePrefix?(store: string, prefix: string): Promise<number>;
|
|
17
|
-
capabilities?: {
|
|
18
|
-
batch?: boolean;
|
|
19
|
-
enumerate?: boolean;
|
|
20
|
-
prefixDelete?: boolean;
|
|
21
|
-
};
|
|
7
|
+
export type HostStoreCallbacks = HostBridge.JsStoreCallbacks & {
|
|
22
8
|
flush?(): Promise<void>;
|
|
23
9
|
};
|
|
24
10
|
export type HostKeyPair = {
|
package/lib/node-surface.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { useMultiFileAuthState } from './Utils/use-multi-file-auth-state.js';
|
|
2
2
|
export { useBridgeStore } from './Utils/use-bridge-store.js';
|
|
3
|
-
export { useLegacyMultiFileAuthState } from './Utils/wrap-legacy-store.js';
|
|
3
|
+
export { useLegacyMultiFileAuthState, prepareLegacyAuthRollback } from './Utils/wrap-legacy-store.js';
|
|
4
4
|
export * from './Utils/messages-media.js';
|
|
5
5
|
export { getUrlInfo } from './Utils/link-preview.js';
|
|
6
6
|
export { makeNativeCryptoProvider } from './Utils/native-crypto-provider.js';
|
|
7
7
|
export { nodeRuntime } from './Runtime/node.js';
|
|
8
8
|
export { default, makeNodeWASocket, createWASocketFactory, createWASocketFactoryFor } from './Socket/index.js';
|
|
9
|
+
export { prepareNativeAuthRollback } from './Utils/native-auth-rollback.js';
|
|
9
10
|
//# sourceMappingURL=node-surface.d.ts.map
|
package/lib/node-surface.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
// Hosts import `../host-surface.ts` (or `@oxidezap/baileyrs/host`) instead.
|
|
7
7
|
export { useMultiFileAuthState } from './Utils/use-multi-file-auth-state.js';
|
|
8
8
|
export { useBridgeStore } from './Utils/use-bridge-store.js';
|
|
9
|
-
export { useLegacyMultiFileAuthState } from './Utils/wrap-legacy-store.js';
|
|
9
|
+
export { useLegacyMultiFileAuthState, prepareLegacyAuthRollback } from './Utils/wrap-legacy-store.js';
|
|
10
10
|
export * from './Utils/messages-media.js';
|
|
11
11
|
export { getUrlInfo } from './Utils/link-preview.js';
|
|
12
12
|
export { makeNativeCryptoProvider } from './Utils/native-crypto-provider.js';
|
|
13
13
|
export { nodeRuntime } from './Runtime/node.js';
|
|
14
14
|
export { default, makeNodeWASocket, createWASocketFactory, createWASocketFactoryFor } from './Socket/index.js';
|
|
15
|
+
export { prepareNativeAuthRollback } from './Utils/native-auth-rollback.js';
|
|
15
16
|
//# sourceMappingURL=node-surface.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxidezap/baileyrs",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.11",
|
|
5
5
|
"description": "A Rust-powered WhatsApp Web library for JavaScript, with a Baileys-compatible API",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"whatsapp",
|
|
@@ -88,12 +88,14 @@
|
|
|
88
88
|
"fuzz:report": "node scripts/fuzz/report.ts",
|
|
89
89
|
"test:compat-auditor": "node --test scripts/compatibility/__tests__/audit.test.ts",
|
|
90
90
|
"test:packaged": "node scripts/packaged-upstream-alias.mjs",
|
|
91
|
-
"typecheck:compat-auditor": "npm run build --silent && npm run compat:check-waproto --silent && npm run compat:layers --silent &&
|
|
92
|
-
"test:e2e": "NODE_TLS_REJECT_UNAUTHORIZED=0 ADV_SECRET_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= node --expose-gc --test --test-concurrency=1 ./src/__tests__/e2e/*.test-e2e.ts ./scripts/compatibility/__tests__/*.test-e2e.ts"
|
|
91
|
+
"typecheck:compat-auditor": "npm run build --silent && npm run compat:check-waproto --silent && npm run compat:layers --silent && npm run typecheck:compat-declarations --silent",
|
|
92
|
+
"test:e2e": "NODE_TLS_REJECT_UNAUTHORIZED=0 ADV_SECRET_KEY=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= node --expose-gc --test --test-concurrency=1 ./src/__tests__/e2e/*.test-e2e.ts ./scripts/compatibility/__tests__/*.test-e2e.ts",
|
|
93
|
+
"typecheck:compat-declarations": "node node_modules/typescript-compat-auditor/bin/tsc -p scripts/compatibility/tsconfig.json"
|
|
93
94
|
},
|
|
94
95
|
"dependencies": {
|
|
95
|
-
"@oxidezap/whatsapp-rust-bridge": "0.
|
|
96
|
+
"@oxidezap/whatsapp-rust-bridge": "0.26.0",
|
|
96
97
|
"events": "^3.3.0",
|
|
98
|
+
"fs-native-extensions": "1.5.1",
|
|
97
99
|
"long": "^5.3.2"
|
|
98
100
|
},
|
|
99
101
|
"devDependencies": {
|
|
@@ -104,16 +106,16 @@
|
|
|
104
106
|
"jimp": "^1.6.0",
|
|
105
107
|
"link-preview-js": "^5.0.0",
|
|
106
108
|
"music-metadata": "^11.14.0",
|
|
107
|
-
"oxfmt": "^0.
|
|
108
|
-
"oxlint": "1.
|
|
109
|
+
"oxfmt": "^0.72.0",
|
|
110
|
+
"oxlint": "1.87.0",
|
|
109
111
|
"pino": "^10.3.1",
|
|
110
112
|
"pino-pretty": "^13.1.3",
|
|
111
|
-
"pkg-pr-new": "^0.0.
|
|
113
|
+
"pkg-pr-new": "^0.0.91",
|
|
112
114
|
"protobufjs": "^8.8.0",
|
|
113
115
|
"tsc-esm-fix": "^3.1.2",
|
|
114
116
|
"typescript": "^7.0.2",
|
|
115
117
|
"typescript-compat-auditor": "npm:typescript@6.0.3",
|
|
116
|
-
"wrangler": "4.
|
|
118
|
+
"wrangler": "4.149.0"
|
|
117
119
|
},
|
|
118
120
|
"peerDependencies": {
|
|
119
121
|
"@hapi/boom": "^9.1.0 || ^10.0.0",
|