@sailfish-ai/recorder 1.7.34 → 1.7.41

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.
@@ -1,26 +1,80 @@
1
- import { openDB } from 'idb';
2
- const DB_NAME = 'leapsNotifyDB';
3
- const STORE_NAME = 'notifyMessages';
4
- const dbPromise = openDB(DB_NAME, 1, {
5
- upgrade(db) {
6
- if (!db.objectStoreNames.contains(STORE_NAME)) {
7
- db.createObjectStore(STORE_NAME, { keyPath: 'id', autoIncrement: true });
1
+ // SSR/Edge-safe IndexedDB helpers for notify messages.
2
+ // No top-level access to `indexedDB`. No dependency on `idb` package.
3
+ // On server/edge (no IDB), calls are no-ops / return safe defaults.
4
+ const DB_NAME = "leapsNotifyDB";
5
+ const STORE_NAME = "notifyMessages";
6
+ const DB_VERSION = 1;
7
+ let _dbPromise = null;
8
+ // Narrow feature check that won’t throw in SSR/Edge
9
+ function hasIndexedDB() {
10
+ return typeof globalThis !== "undefined" && !!globalThis.indexedDB;
11
+ }
12
+ // Lazily open DB only in real browsers. Never at module init.
13
+ function openDb() {
14
+ if (!hasIndexedDB())
15
+ return Promise.resolve(null);
16
+ if (_dbPromise)
17
+ return _dbPromise;
18
+ _dbPromise = new Promise((resolve) => {
19
+ try {
20
+ const req = globalThis.indexedDB.open(DB_NAME, DB_VERSION);
21
+ req.onupgradeneeded = () => {
22
+ const db = req.result;
23
+ if (!db.objectStoreNames.contains(STORE_NAME)) {
24
+ db.createObjectStore(STORE_NAME, {
25
+ keyPath: "id",
26
+ autoIncrement: true,
27
+ });
28
+ }
29
+ };
30
+ req.onsuccess = () => resolve(req.result);
31
+ req.onerror = () => resolve(null); // fail closed, don’t throw
32
+ req.onblocked = () => resolve(null); // avoid hanging if blocked
33
+ }
34
+ catch {
35
+ resolve(null);
36
+ }
37
+ });
38
+ return _dbPromise;
39
+ }
40
+ async function withStore(mode, fn) {
41
+ const db = await openDb();
42
+ if (!db)
43
+ return null;
44
+ return new Promise((resolve) => {
45
+ try {
46
+ const tx = db.transaction(STORE_NAME, mode);
47
+ const store = tx.objectStore(STORE_NAME);
48
+ Promise.resolve(fn(store))
49
+ .then((result) => {
50
+ tx.oncomplete = () => resolve(result);
51
+ tx.onerror = () => resolve(null);
52
+ })
53
+ .catch(() => resolve(null));
54
+ }
55
+ catch {
56
+ resolve(null);
8
57
  }
9
- },
10
- });
58
+ });
59
+ }
60
+ // ── Public API (safe for SSR/Edge) ─────────────────────────────────────────────
11
61
  export async function saveNotifyMessageToIDB(message) {
12
- const db = await dbPromise;
13
- const tx = db.transaction(STORE_NAME, 'readwrite');
14
- await tx.store.add({ value: message });
15
- await tx.done;
62
+ await withStore("readwrite", (store) => {
63
+ store.add({ value: message });
64
+ });
16
65
  }
17
66
  export async function getAllNotifyMessages() {
18
- const db = await dbPromise;
19
- return await db.getAll(STORE_NAME);
67
+ const result = await withStore("readonly", (store) => {
68
+ return new Promise((resolve) => {
69
+ const req = store.getAll();
70
+ req.onsuccess = () => resolve(req.result);
71
+ req.onerror = () => resolve([]);
72
+ });
73
+ });
74
+ return result ?? []; // SSR/Edge → []
20
75
  }
21
76
  export async function deleteNotifyMessageById(id) {
22
- const db = await dbPromise;
23
- const tx = db.transaction(STORE_NAME, 'readwrite');
24
- await tx.store.delete(id);
25
- await tx.done;
77
+ await withStore("readwrite", (store) => {
78
+ store.delete(id);
79
+ });
26
80
  }