@witbitz/sdk 4.3.0 → 4.4.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/README.md +2 -2
- package/a2aCore.js +26 -5
- package/accountErase.js +6 -1
- package/accountRecord.js +2 -2
- package/agentDoorTools.js +28 -0
- package/chatLock.js +16 -0
- package/cloudDevicePins.js +2 -2
- package/codeAttachments.js +100 -0
- package/codeCache.js +149 -0
- package/codeCloud.js +0 -2
- package/codeComputers.js +1 -0
- package/codeFolders.js +116 -0
- package/codeHistory.js +76 -0
- package/codeLanguage.js +54 -0
- package/codeModes.js +2 -0
- package/codeProgress.js +54 -0
- package/codeSent.js +68 -0
- package/codeSubagents.js +107 -0
- package/codeTransport.js +22 -0
- package/connections.js +17 -18
- package/deviceAttest.js +9 -3
- package/idb.js +19 -3
- package/jobAgents.js +2 -2
- package/keptMerge.js +9 -2
- package/l1-worker-src.js +1 -1
- package/l1-worker.js +93 -30
- package/laneAssociation.js +68 -0
- package/laneConfig.js +4 -3
- package/manifest.json +80 -61
- package/memberChange.js +4 -2
- package/mirrorBatch.js +47 -0
- package/opRouting.js +10 -0
- package/package.json +21 -2
- package/pdfOptions.js +13 -0
- package/pdfText.js +107 -0
- package/pdfjs.mjs +28 -0
- package/pdfjs.worker.mjs +28 -0
- package/protectedLocal.js +18 -2
- package/removedMessage.js +1 -1
- package/roomEmbed.js +111 -0
- package/roomName.js +1 -1
- package/roomRoster.js +21 -5
- package/rosterCount.js +6 -3
- package/sdkA2A.js +160 -40
- package/sdkAccount.js +17 -4
- package/sdkAccountDoc.js +11 -3
- package/sdkAccountSections.js +117 -8
- package/sdkBackup.js +35 -8
- package/sdkCloudDevice.js +8 -2
- package/sdkComputers.js +582 -53
- package/sdkDictation.js +114 -24
- package/sdkErase.js +9 -4
- package/sdkExports.js +4 -2
- package/sdkLaneLink.js +3 -3
- package/sdkPlan.js +4 -2
- package/sdkRekey.js +50 -17
- package/sdkReport.js +1 -1
- package/sdkSafeMedia.js +1 -1
- package/sdkSpeech.js +19 -2
- package/sdkTemporaryRooms.js +123 -0
- package/sdkVault.js +66 -10
- package/sentinelRelease.js +1 -0
- package/sharedViews.js +17 -3
- package/siri.js +114 -7
- package/spaceClient.js +16 -5
- package/spaceEmailGate.js +2 -2
- package/spaceTemplates.js +99 -0
- package/speechOut.js +4 -2
- package/store.js +83 -14
- package/sw-notif-core.js +9 -7
- package/turnVerdict.js +1 -0
- package/vault-core.js +480 -112
- package/vault-kit.mjs +2 -2
- package/vault-screens.js +5 -7
- package/vaultAtRest.js +35 -4
- package/vaultKeep.js +9 -3
- package/vaultWorkerHost.js +23 -4
- package/witbitz-admin.mjs +12 -11
- package/witbitz-sdk.d.ts +115 -24
- package/witbitz-sdk.js +572 -149
package/sdkAccountSections.js
CHANGED
|
@@ -18,7 +18,7 @@ import { mergeContactLists, normContact, dedupePeople, contactKey } from './stor
|
|
|
18
18
|
import { cleanRoomDefaults, writeRoomDefaults, ROOM_DEFAULTS_DOC } from './roomDefaultPrefs.js'
|
|
19
19
|
import { sealDoc } from './accountSeal.js'
|
|
20
20
|
import { BLOCKS_DOC, cleanBlocks, mergeBlocks, isBlocked } from './blocks.js' // blocks: the app's list and its rules
|
|
21
|
-
import { CHAT_LOCKS_DOC, cleanChatLocks, mergeChatLocks, validPin, newSalt, newLockId, stretchPin, pinIdFor, addLock, dropLock, lockOfTarget, liveLocks, accountTries, wrongTryIn } from './chatLock.js'
|
|
21
|
+
import { CHAT_LOCKS_DOC, cleanChatLocks, mergeChatLocks, validPin, newSalt, saltsOf, newLockId, stretchPin, pinIdFor, addLock, dropLock, lockOfTarget, liveLocks, accountTries, wrongTryIn, deleteLockedTargets } from './chatLock.js'
|
|
22
22
|
|
|
23
23
|
const fail = (code, msg, extra = {}) => Object.assign(new Error('witbitz: ' + msg), { code, ...extra })
|
|
24
24
|
const canon = (x) => JSON.stringify(x === undefined ? null : x)
|
|
@@ -64,6 +64,36 @@ class Section {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
export function codeAgentPreference(ix, agent) {
|
|
68
|
+
const pref = new Section(ix, {
|
|
69
|
+
doc: 'xindex2',
|
|
70
|
+
of: doc => String(doc?.code?.agent || ''),
|
|
71
|
+
apply(doc, name) {
|
|
72
|
+
const code = doc?.code || {}
|
|
73
|
+
if ((code.agent || '') === name) return null
|
|
74
|
+
return { ...doc, code: { ...code, agent: name, mod: Math.max(Date.now(), (Number(code.mod) || 0) + 1) } }
|
|
75
|
+
},
|
|
76
|
+
})
|
|
77
|
+
return pref._pass(agent === undefined ? null : agent)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function computerModelPreference(ix, computer, model) {
|
|
81
|
+
const pref = new Section(ix, {
|
|
82
|
+
doc: 'xindex2',
|
|
83
|
+
of: doc => String(doc?.code?.models?.[computer] || ''),
|
|
84
|
+
apply(doc, ref) {
|
|
85
|
+
const code = doc?.code || {}, models = { ...code.models }
|
|
86
|
+
if ((models[computer] || '') === ref) return null
|
|
87
|
+
if (ref) {
|
|
88
|
+
if (!(computer in models) && Object.keys(models).length >= 32) throw fail('too_many_models', 'the account already keeps 32 computer model choices')
|
|
89
|
+
models[computer] = ref
|
|
90
|
+
} else delete models[computer]
|
|
91
|
+
return { ...doc, code: { ...code, models, mod: Math.max(Date.now(), (Number(code.mod) || 0) + 1) } }
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
return pref._pass(model === undefined ? null : model)
|
|
95
|
+
}
|
|
96
|
+
|
|
67
97
|
// ── contacts: xindex2.contacts ──
|
|
68
98
|
const contactsOf = (doc) => dedupePeople(((obj(doc) && Array.isArray(doc.contacts)) ? doc.contacts : []).map(normContact).filter(Boolean))
|
|
69
99
|
const withContacts = (doc, rows) => {
|
|
@@ -142,14 +172,14 @@ class Blocks extends Section {
|
|
|
142
172
|
|
|
143
173
|
/** Puts the sections on the account index (`ix.contacts`, `ix.name`, `ix.roomDefaults`, `ix.blocks`) and keeps them in `ix._sections`. */
|
|
144
174
|
class ChatLocks extends Section {
|
|
145
|
-
constructor(ix) { super(ix, { doc: 'x' + CHAT_LOCKS_DOC, of: cleanChatLocks, calls: ['get', 'merge', 'set', 'remove', 'check', 'changePin'], apply: (doc, incoming) => { const next = typeof incoming === 'function' ? incoming(cleanChatLocks(doc)) : mergeChatLocks(doc, incoming); return canon(next) === canon(cleanChatLocks(doc)) ? null : next } }) }
|
|
175
|
+
constructor(ix) { super(ix, { doc: 'x' + CHAT_LOCKS_DOC, of: cleanChatLocks, calls: ['get', 'merge', 'set', 'remove', 'check', 'match', 'changePin', 'previewDeleteAll', 'deleteAll'], apply: (doc, incoming) => { const next = typeof incoming === 'function' ? incoming(cleanChatLocks(doc)) : mergeChatLocks(doc, incoming); return canon(next) === canon(cleanChatLocks(doc)) ? null : next } }) }
|
|
146
176
|
async merge(doc) {
|
|
147
177
|
const clean = cleanChatLocks(doc); if (!clean) throw fail('invalid_argument', 'chatLocks.merge needs a chat-locks document')
|
|
148
178
|
return this._write(clean)
|
|
149
179
|
}
|
|
150
180
|
async set({ kind, target, pin, title } = {}) {
|
|
151
181
|
if (!['room', 'code'].includes(kind) || typeof target !== 'string' || !target || target.length > 300 || !validPin(pin)) throw fail('invalid_argument', 'chatLocks.set needs kind, target and a PIN of 4–12 digits')
|
|
152
|
-
const s0 = this._ix._backup._s, salt = newSalt(), fingerprint = await pinIdFor(await stretchPin(pin, salt)), id = newLockId()
|
|
182
|
+
const s0 = this._ix._backup._s, salt = saltsOf(await this.get())[0] || newSalt(), fingerprint = await pinIdFor(await stretchPin(pin, salt)), id = newLockId()
|
|
153
183
|
if (this._ix._backup._s !== s0) throw fail('account_changed', 'the account changed during PIN setup')
|
|
154
184
|
return this._write((doc) => { if (lockOfTarget(doc, kind, target)) throw fail('locked', 'this chat is already locked'); return addLock(doc, id, { kind, target, salt, pin: fingerprint, title }) })
|
|
155
185
|
}
|
|
@@ -171,6 +201,70 @@ class ChatLocks extends Section {
|
|
|
171
201
|
return addLock(cur, lockId, { kind: current.kind, target: current.target, salt: current.salt, title: current.title, pin: fingerprint })
|
|
172
202
|
})
|
|
173
203
|
}
|
|
204
|
+
_mintedAssistants(targets) {
|
|
205
|
+
const parents = new Set(targets.filter(t => t.kind === 'room').map(t => t.target))
|
|
206
|
+
return (this._ix._backup.rooms || []).filter(r => r.shared && parents.has(r.shared) && !r.detachedLane && r.laneOrigin === 'minted')
|
|
207
|
+
}
|
|
208
|
+
async previewDeleteAll() {
|
|
209
|
+
const owner = this._ix._backup._s
|
|
210
|
+
if (!(await this._ix.sync())?.ok || this._ix._backup._s !== owner) throw fail('index_unavailable', 'the account could not be synced')
|
|
211
|
+
const targets = liveLocks(await this.get()).map(({ kind, target, lockId }) => ({ kind, target, lockId }))
|
|
212
|
+
if (this._ix._backup._s !== owner) throw fail('account_changed', 'the account changed')
|
|
213
|
+
const locked = new Set(targets.filter(t => t.kind === 'room').map(t => t.target))
|
|
214
|
+
const privateAssistants = this._mintedAssistants(targets).filter(r => !locked.has(r.room))
|
|
215
|
+
.map(r => ({ room: r.room, parent: r.shared, title: r.label || '' }))
|
|
216
|
+
return { targets, privateAssistants }
|
|
217
|
+
}
|
|
218
|
+
async deleteAll({ includePrivateAssistants = false, privateAssistantRooms } = {}) {
|
|
219
|
+
if (privateAssistantRooms !== undefined && (!Array.isArray(privateAssistantRooms) || !privateAssistantRooms.every(r => typeof r === 'string'))) throw fail('invalid_argument', 'privateAssistantRooms must contain room IDs')
|
|
220
|
+
const owner = this._ix._backup._s, { targets, privateAssistants } = await this.previewDeleteAll()
|
|
221
|
+
const approved = privateAssistants.filter(r => privateAssistantRooms ? privateAssistantRooms.includes(r.room) : includePrivateAssistants === true).map(r => r.room)
|
|
222
|
+
return this._deleteTargets(targets, owner, undefined, approved)
|
|
223
|
+
}
|
|
224
|
+
async _deleteTargets(targets, owner, afterRemoval, assistants = []) {
|
|
225
|
+
const ix = this._ix
|
|
226
|
+
const current = () => !!owner && ix._backup._s === owner
|
|
227
|
+
const approved = new Set([...assistants, ...targets.filter(t => t.kind === 'room').map(t => t.target)])
|
|
228
|
+
return deleteLockedTargets(targets, {
|
|
229
|
+
stillLocked: async (id, kind, target) => {
|
|
230
|
+
if (!current()) return false
|
|
231
|
+
const lock = lockOfTarget(await this.get(), kind, target)
|
|
232
|
+
return current() && lock?.lockId === id
|
|
233
|
+
},
|
|
234
|
+
removeTarget: async (kind, target) => {
|
|
235
|
+
if (!current() || !await ix._deleteLockTarget(kind, target, current, approved, afterRemoval) || !current()) return false
|
|
236
|
+
if (afterRemoval) await afterRemoval(kind, target)
|
|
237
|
+
return current()
|
|
238
|
+
},
|
|
239
|
+
removeLock: async (id, kind, target) => {
|
|
240
|
+
if (!current()) throw fail('account_changed', 'the account changed')
|
|
241
|
+
await this._write(doc => lockOfTarget(doc, kind, target)?.lockId === id ? dropLock(doc, id) : doc, { retryMarker: true })
|
|
242
|
+
},
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
async match({ pin } = {}) {
|
|
246
|
+
if (!validPin(pin)) throw fail('invalid_argument', 'a PIN is 4–12 digits')
|
|
247
|
+
const owner = this._ix._backup._s, doc = await this.get(), dev = this._ix.deviceId
|
|
248
|
+
if (!dev) throw fail('not_enabled', 'this account has no device id for synced PIN attempts')
|
|
249
|
+
const before = accountTries(doc), salts = saltsOf(doc)
|
|
250
|
+
if (before.next > Date.now() || !salts.length) return { ok: false, matches: [], next: before.next }
|
|
251
|
+
const fingerprints = new Map()
|
|
252
|
+
for (const salt of salts) fingerprints.set(salt, await pinIdFor(await stretchPin(pin, salt)))
|
|
253
|
+
if (this._ix._backup._s !== owner) throw fail('account_changed', 'the account changed during PIN checking')
|
|
254
|
+
let matches = [], next = 0
|
|
255
|
+
await this._write(cur => {
|
|
256
|
+
const now = Date.now(), tries = accountTries(cur), locks = liveLocks(cur)
|
|
257
|
+
matches = []; next = tries.next
|
|
258
|
+
if (next > now || !locks.length) return cur
|
|
259
|
+
if (locks.some(l => !fingerprints.has(l.salt))) throw fail('changed_meanwhile', 'display locks changed; try again')
|
|
260
|
+
matches = locks.filter(l => fingerprints.get(l.salt) === l.pin)
|
|
261
|
+
.map(({ lockId, kind, target, title }) => ({ lockId, kind, target, title: title || '' }))
|
|
262
|
+
const result = matches.length ? cur : wrongTryIn(cur, dev, now)
|
|
263
|
+
next = accountTries(result, now).next
|
|
264
|
+
return result
|
|
265
|
+
})
|
|
266
|
+
return { ok: !!matches.length, matches, next }
|
|
267
|
+
}
|
|
174
268
|
async check({ lockId, pin } = {}) {
|
|
175
269
|
if (!validPin(pin)) throw fail('invalid_argument', 'a PIN is 4–12 digits')
|
|
176
270
|
const s0 = this._ix._backup._s, doc = await this.get(), lock = liveLocks(doc).find((l) => l.lockId === lockId)
|
|
@@ -194,9 +288,19 @@ class ChatLocks extends Section {
|
|
|
194
288
|
})
|
|
195
289
|
return { ok, next }
|
|
196
290
|
}
|
|
197
|
-
async _write(change) {
|
|
198
|
-
const ix = this._ix,
|
|
199
|
-
|
|
291
|
+
async _write(change, { retryMarker = false } = {}) {
|
|
292
|
+
const ix = this._ix, owner = ix._backup._s, merged = await this._pass(change)
|
|
293
|
+
if (retryMarker && owner === ix._backup._s) {
|
|
294
|
+
owner.chatLockMarkPending = Math.max(Date.now(), (owner.chatLockMarkPending || 0) + 1)
|
|
295
|
+
ix._backup._changed?.()
|
|
296
|
+
}
|
|
297
|
+
try { await this._mark(owner) } catch (error) {
|
|
298
|
+
if (!retryMarker || owner !== ix._backup._s) throw error
|
|
299
|
+
}
|
|
300
|
+
return merged
|
|
301
|
+
}
|
|
302
|
+
async _mark(s0) {
|
|
303
|
+
const ix = this._ix, pending = s0.chatLockMarkPending
|
|
200
304
|
for (let i = 0; i < 5; i++) {
|
|
201
305
|
const loc = await ix._where(), got = await ix._read(loc, 'xindex', loc.app)
|
|
202
306
|
if (ix._backup._s !== s0) throw fail('account_changed', 'the account changed during chatLocks.merge')
|
|
@@ -206,7 +310,8 @@ class ChatLocks extends Section {
|
|
|
206
310
|
const r = await ix._client().state(loc.room, loc.mk, 'xindex', await sealDoc(loc.app, next), 'chat locks present', 'device', got.v)
|
|
207
311
|
if (r && r.status === 409) continue
|
|
208
312
|
if (!r || r.status !== 200) throw fail('save_failed', 'the chat-lock presence mark could not be saved')
|
|
209
|
-
|
|
313
|
+
if (pending && ix._backup._s === s0 && s0.chatLockMarkPending === pending) { delete s0.chatLockMarkPending; ix._backup._changed?.() }
|
|
314
|
+
return
|
|
210
315
|
}
|
|
211
316
|
throw fail('save_failed', 'the account index kept changing; retry chatLocks.merge')
|
|
212
317
|
}
|
|
@@ -219,5 +324,9 @@ export function attachSections (ix) {
|
|
|
219
324
|
}
|
|
220
325
|
/** After an account sync: the sections the app uses are read again (a change another device made fires 'change'). */
|
|
221
326
|
export async function refreshSections (ix) {
|
|
222
|
-
for (const s of Object.values(ix._sections || {})) if (s._used && !s._remote)
|
|
327
|
+
for (const s of Object.values(ix._sections || {})) if (s._used && !s._remote) {
|
|
328
|
+
await s._pass(null).catch(() => null)
|
|
329
|
+
}
|
|
330
|
+
const owner = ix._backup._s
|
|
331
|
+
if (owner?.chatLockMarkPending && ix.chatLocks && !ix.chatLocks._remote) await ix.chatLocks._mark(owner).catch(() => {})
|
|
223
332
|
}
|
package/sdkBackup.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { associationTime } from './laneAssociation.js'
|
|
1
2
|
// spaces/public/sdkBackup.js — `wb.backup`: the ACCOUNT BACKUP for a builder's app, on the SAME vault our own app uses
|
|
2
3
|
// (2026-10-02, a builder: "a short recovery code instead of the restore link"; the owner: "why not use our account
|
|
3
4
|
// structure?"). Nothing new is invented here — it is the existing vault, reached from the SDK:
|
|
@@ -70,7 +71,7 @@ const notOnService = () => fail('not_on_service', 'this call is for an account o
|
|
|
70
71
|
|
|
71
72
|
/** One room as the backup records it. `link` carries the room key (the fragment), so the whole list is sealed. */
|
|
72
73
|
const roomOf = (r) => (r && typeof r === 'object' && typeof r.room === 'string' && r.room && typeof r.link === 'string' && r.link
|
|
73
|
-
? { room: r.room.slice(0, 120), ...roomPin(r), ...(typeof r.renamed === 'boolean' ? { renamed: r.renamed } : {}), ...(Number.isFinite(r.at) && r.at > 0 ? { at: r.at } : {}), ...(r.archived ? { archived: true } : {}), link: r.link.slice(0, 4000), kind: r.kind === 'lane' ? 'lane' : 'space', ...(r.label ? { label: String(r.label).slice(0, 120) } : {}), ...(r.kind === 'lane' && r.shared ? { shared: String(r.shared).slice(0, 120) } : {}), ...(typeof r.mk === 'string' && r.mk && r.mk.length <= 200 ? { mk: r.mk } : {}) }
|
|
74
|
+
? { room: r.room.slice(0, 120), ...roomPin(r), ...(typeof r.mintedFor === 'string' && r.mintedFor ? { mintedFor: r.mintedFor } : r.laneOrigin === 'minted' && r.shared ? { mintedFor: r.shared } : {}), ...(r.laneOrigin === 'minted' && !r.detachedLane ? { laneOrigin: 'minted' } : {}), ...(Number(r.associationAt) > 0 ? { associationAt: Number(r.associationAt) } : {}), ...(typeof r.renamed === 'boolean' ? { renamed: r.renamed } : {}), ...(Number.isFinite(r.at) && r.at > 0 ? { at: r.at } : {}), ...(r.archived ? { archived: true } : {}), ...(r.detachedLane ? { detachedLane: true } : {}), link: r.link.slice(0, 4000), kind: !r.detachedLane && r.kind === 'lane' ? 'lane' : 'space', ...(r.label ? { label: String(r.label).slice(0, 120) } : {}), ...(!r.detachedLane && r.kind === 'lane' && r.shared ? { shared: String(r.shared).slice(0, 120) } : {}), ...(typeof r.mk === 'string' && r.mk && r.mk.length <= 200 ? { mk: r.mk } : {}) }
|
|
74
75
|
: null)
|
|
75
76
|
|
|
76
77
|
function stateOf(x) {
|
|
@@ -83,7 +84,7 @@ function stateOf(x) {
|
|
|
83
84
|
const links = (Array.isArray(o.links) ? o.links : []).filter((l) => l && typeof l.a === 'string' && typeof l.b === 'string' && Number.isFinite(l.at)).map((l) => ({ a: l.a.slice(0, 120), b: l.b.slice(0, 120), at: l.at, ...(Number.isFinite(l.cap) ? { cap: l.cap } : {}), ...(l.removed ? { removed: true } : {}) })).slice(-200)
|
|
84
85
|
// `outs`: sign-outs of OTHER devices this device made, kept until the index carries them (sdkAccount.js signOut; pass 6, K#7)
|
|
85
86
|
const outs = o.outs && typeof o.outs === 'object' ? Object.fromEntries(Object.entries(o.outs).filter(([id, at]) => typeof id === 'string' && id.length <= 40 && Number.isFinite(at)).slice(-50)) : {}
|
|
86
|
-
return { v: 1, ...(o.format === 'account' ? { format: 'account' } : {}), ...(Object.keys(outs).length ? { outs } : {}), master: o.master, ...(typeof o.savedVersion === 'string' && o.savedVersion.length <= 200 ? { savedVersion: o.savedVersion } : {}), rooms: (Array.isArray(o.rooms) ? o.rooms : []).map(roomOf).filter(Boolean).slice(0, MAX_ROOMS), ...(tomb.length ? { tomb } : {}), ...(links.length ? { links } : {}), ...(device ? { device } : {}), ...(o.email ? { email: String(o.email) } : {}), ...(inviteOf(o.invite) ? { invite: inviteOf(o.invite) } : {}), ...(normUsageKey(o.usage) ? { usage: normUsageKey(o.usage) } : {}), ...(usageOldOf(o.usageOld).length ? { usageOld: usageOldOf(o.usageOld) } : {}), ...(o.erased ? { erased: true } : {}), ...(v2Of(o.v2) ? { v2: v2Of(o.v2) } : {}) }
|
|
87
|
+
return { v: 1, ...(Number.isSafeInteger(o.chatLockMarkPending) && o.chatLockMarkPending > 0 ? { chatLockMarkPending: o.chatLockMarkPending } : {}), ...(o.format === 'account' ? { format: 'account' } : {}), ...(Object.keys(outs).length ? { outs } : {}), master: o.master, ...(typeof o.savedVersion === 'string' && o.savedVersion.length <= 200 ? { savedVersion: o.savedVersion } : {}), rooms: (Array.isArray(o.rooms) ? o.rooms : []).map(roomOf).filter(Boolean).slice(0, MAX_ROOMS), ...(tomb.length ? { tomb } : {}), ...(links.length ? { links } : {}), ...(device ? { device } : {}), ...(o.email ? { email: String(o.email) } : {}), ...(inviteOf(o.invite) ? { invite: inviteOf(o.invite) } : {}), ...(normUsageKey(o.usage) ? { usage: normUsageKey(o.usage) } : {}), ...(usageOldOf(o.usageOld).length ? { usageOld: usageOldOf(o.usageOld) } : {}), ...(o.erased ? { erased: true } : {}), ...(v2Of(o.v2) ? { v2: v2Of(o.v2) } : {}) }
|
|
87
88
|
}
|
|
88
89
|
// the account's USAGE key (usageReceipts.js; the owner, 2026-10-23: a builder's app records the account's usage too) and the
|
|
89
90
|
// ones it replaced — kept in step between the devices by the live index (sdkAccount.js)
|
|
@@ -174,24 +175,43 @@ export class AccountBackup {
|
|
|
174
175
|
// a lane opened as a plain Space (wb.openSpace(laneLink)) knows nothing of its Space: the record it already has as a LANE
|
|
175
176
|
// stays one — a restore must not bring it back as a Space (sync sweep 2026-11-02 #5)
|
|
176
177
|
const had = this._s.rooms.find((x) => x.room === spaceOrLane.room)
|
|
177
|
-
|
|
178
|
-
const
|
|
178
|
+
if (lane && (had?.detachedLane || (had?.shared && had.shared !== spaceOrLane._sharedRoom))) return this
|
|
179
|
+
const wasLane = !lane && !spaceOrLane._detachedLane && had && had.kind === 'lane' && had.shared
|
|
180
|
+
const r = roomOf({ room: spaceOrLane.room, link: spaceOrLane.shareLink, mintedFor: had?.mintedFor || spaceOrLane._mintedFor, laneOrigin: spaceOrLane._laneOrigin || had?.laneOrigin, associationAt: spaceOrLane._associationAt || had?.associationAt, kind: lane || wasLane ? 'lane' : 'space', detachedLane: spaceOrLane._detachedLane || had?.detachedLane, label, shared: lane ? spaceOrLane._sharedRoom : wasLane ? had.shared : undefined, mk: spaceOrLane._split ? spaceOrLane._mk : undefined })
|
|
179
181
|
if (!r) return this
|
|
180
182
|
const i = this._s.rooms.findIndex((x) => x.room === r.room)
|
|
181
183
|
const prev = i >= 0 ? this._s.rooms[i] : null
|
|
182
|
-
if (prev && prev.link === r.link && prev.kind === r.kind && prev.mk === r.mk && (!label || prev.label === r.label)) return this
|
|
184
|
+
if (prev && prev.link === r.link && prev.kind === r.kind && prev.shared === r.shared && prev.laneOrigin === r.laneOrigin && prev.associationAt === r.associationAt && !!prev.detachedLane === !!r.detachedLane && prev.mk === r.mk && (!label || prev.label === r.label)) return this
|
|
183
185
|
const next = { ...(prev ? { ...prev, ...r, ...(label ? {} : prev.label ? { label: prev.label } : {}), ...(prev.archived ? { archived: true } : {}) } : r), at: Date.now() } // `at`: the live index keeps the newer of each entry
|
|
186
|
+
if (next.detachedLane) { delete next.shared; delete next.laneOrigin }
|
|
184
187
|
if (i >= 0) this._s.rooms[i] = next; else { if (this._s.rooms.length >= MAX_ROOMS) return this; this._s.rooms.push(next) }
|
|
185
188
|
this._schedule()
|
|
186
189
|
return this
|
|
187
190
|
}
|
|
188
191
|
|
|
192
|
+
_attachLane(room, parent) {
|
|
193
|
+
const entry = this._s?.rooms.find(r => r.room === room)
|
|
194
|
+
if (!entry) throw Object.assign(new Error('Add the private room to the account first.'), { code: 'not_in_account' })
|
|
195
|
+
if (entry.shared && entry.shared !== parent) throw Object.assign(new Error('Unlink this room from its current Space first.'), { code: 'already_linked' })
|
|
196
|
+
if (entry.laneOrigin === 'minted' && entry.shared) entry.mintedFor ||= entry.shared
|
|
197
|
+
if (entry.mintedFor === parent) entry.laneOrigin = 'minted'
|
|
198
|
+
else delete entry.laneOrigin
|
|
199
|
+
entry.kind = 'lane'
|
|
200
|
+
entry.shared = parent
|
|
201
|
+
delete entry.detachedLane
|
|
202
|
+
entry.at = entry.associationAt = associationTime(entry)
|
|
203
|
+
this._schedule()
|
|
204
|
+
}
|
|
205
|
+
|
|
189
206
|
_detachLane(room, shared) {
|
|
190
207
|
const entry = this._s?.rooms.find((r) => r.room === room && r.kind === 'lane' && r.shared === shared)
|
|
191
208
|
if (!entry) return
|
|
209
|
+
if (entry.laneOrigin === 'minted') entry.mintedFor ||= entry.shared
|
|
210
|
+
delete entry.laneOrigin
|
|
192
211
|
delete entry.shared
|
|
193
212
|
entry.kind = 'space'
|
|
194
|
-
entry.
|
|
213
|
+
entry.detachedLane = true
|
|
214
|
+
entry.at = entry.associationAt = associationTime(entry)
|
|
195
215
|
this._schedule()
|
|
196
216
|
}
|
|
197
217
|
|
|
@@ -301,6 +321,11 @@ export class AccountBackup {
|
|
|
301
321
|
* If the vault's gate requires the email, the first call mails a code and throws `code: 'email_code_required'` with
|
|
302
322
|
* a `ticket`; call again with `{ code, ticket, emailCode }`. `email` defaults to the signed-in address. */
|
|
303
323
|
async restore({ code, email, ticket, emailCode, getCode, askAddress } = {}) {
|
|
324
|
+
const epoch = this._restoreEpoch = (this._restoreEpoch || 0) + 1
|
|
325
|
+
const owner = this._restoreIdentity?.() ?? this._email(), original = this._s
|
|
326
|
+
const check = () => {
|
|
327
|
+
if (epoch !== this._restoreEpoch || original !== this._s || owner !== (this._restoreIdentity?.() ?? this._email())) throw fail('account_changed', 'The account changed during recovery.')
|
|
328
|
+
}
|
|
304
329
|
if (this._s?.v2?.resetDraft) throw fail('email_move_pending', 'finish or cancel this device’s email move first')
|
|
305
330
|
let cs
|
|
306
331
|
try { cs = codeSecret(code) } catch { throw fail('bad_code', 'that is not a recovery code') }
|
|
@@ -308,6 +333,7 @@ export class AccountBackup {
|
|
|
308
333
|
// there (or a service that could not say) goes on to the old store below. A ticket of the old store's gate goes straight there.
|
|
309
334
|
if (this._v2 && !(ticket && emailCode)) {
|
|
310
335
|
const d = await this._v2.restore(this, { code, email, getCode, askAddress })
|
|
336
|
+
check()
|
|
311
337
|
if (d) { clearTimeout(this._timer); this._timer = null; this._s = stateOf(d); this._changed(); this._started(); return { rooms: this.rooms } }
|
|
312
338
|
}
|
|
313
339
|
const w = await wrapperLocation(cs)
|
|
@@ -341,6 +367,7 @@ export class AccountBackup {
|
|
|
341
367
|
// is not in the account format: no plan, read as before.
|
|
342
368
|
const plan = applyPlan(doc, {}, { app: SDK_APP })
|
|
343
369
|
const invite = plan ? plan.inviteKey : doc.inviteKey
|
|
370
|
+
check()
|
|
344
371
|
this._s = stateOf({ master: b64(master), savedVersion: b.json.ver, rooms: roomsOfRecord(plan ? { ...doc, recents: plan.add } : doc), tomb: tombOfRecord(doc), ...(doc.email ? { email: doc.email } : {}), ...(invite ? { invite } : {}), ...(doc.kind === KIND ? {} : { format: 'account' }) })
|
|
345
372
|
this._changed(); this._started()
|
|
346
373
|
return { rooms: this.rooms }
|
|
@@ -370,9 +397,9 @@ export class AccountBackup {
|
|
|
370
397
|
/** Write the vault copy soon and hand the app the new state — without telling the live index (it is the caller). */
|
|
371
398
|
_persist() { if (this._isEnabling()) { this._enablingDirty = true; return } if (this._s && this._s.erased) { this._changed(); return } clearTimeout(this._timer); this._timer = setTimeout(() => { this._timer = null; if (this._s) this._write().catch((e) => { this.lastError = e }) }, 400); this._changed() }
|
|
372
399
|
/** This device was signed out of the account (wb.account): forget it here, and tell the app to persist that. */
|
|
373
|
-
_drop() { clearTimeout(this._timer); this._timer = null; this._s = null; this._changed() }
|
|
400
|
+
_drop() { this._restoreEpoch = (this._restoreEpoch || 0) + 1; clearTimeout(this._timer); this._timer = null; this._s = null; this._changed() }
|
|
374
401
|
/** @private take another persisted state in place (a vault switching accounts keeps one backup per account) */
|
|
375
|
-
_adopt(state) { clearTimeout(this._timer); this._timer = null; this._s = stateOf(state); this._changed() }
|
|
402
|
+
_adopt(state) { this._restoreEpoch = (this._restoreEpoch || 0) + 1; clearTimeout(this._timer); this._timer = null; this._s = stateOf(state); this._changed() }
|
|
376
403
|
_started() { if (typeof this._onStart === 'function') { try { this._onStart() } catch { /* the live index */ } } }
|
|
377
404
|
_changed() { if (this._isEnabling()) return; if (typeof this.onState === 'function') { try { this.onState(this.state) } catch { /* the app's callback must not break the backup */ } } }
|
|
378
405
|
async _write(verification) {
|
package/sdkCloudDevice.js
CHANGED
|
@@ -6,7 +6,13 @@ const current = (wb, session, state) => { if (wb._session !== session || wb.back
|
|
|
6
6
|
|
|
7
7
|
/** A kept Space remains solo and has no private lane of its own, on every SDK/vault device. */
|
|
8
8
|
export async function assertNotKept(space) {
|
|
9
|
-
|
|
9
|
+
// ⚑ A VAULT FROM BEFORE THIS CHECK (the 4.2.0 kit) answers `vault_refused` to the unknown call — a 4.3.0 page could then open
|
|
10
|
+
// no private lane and change no members against it (second review, 2026-11-27). No answer there = no check, as before 4.3.0;
|
|
11
|
+
// the cloud device drops a kept Space that gained people or lanes at its next tick either way (cloud-device/scope.mjs).
|
|
12
|
+
if (space._wb?.vault) {
|
|
13
|
+
try { return await space._wb.vault._c.roomAccount(space.room, 'alwaysOn', 'assertNotKept') }
|
|
14
|
+
catch (e) { if (e && e.code === 'vault_refused') return; throw e }
|
|
15
|
+
}
|
|
10
16
|
if (await isKeptSpace(space)) throw fail('kept_space', 'stop keeping this Space always on before adding people or private lanes')
|
|
11
17
|
}
|
|
12
18
|
|
|
@@ -16,7 +22,7 @@ export async function isKeptSpace(space) {
|
|
|
16
22
|
if (!w?._session?.email || space._sharedRoom) return false
|
|
17
23
|
if (!w.cloudDevice) throw fail('index_unavailable', 'the Space’s always-on status could not be checked')
|
|
18
24
|
try { return (await w.cloudDevice.status()).rooms.some((r) => r.room === space.room) }
|
|
19
|
-
catch (e) { if (['not_available', 'cloud_device_unavailable', 'not_enrolled', 'not_in_dev_server'].includes(e.code)) return false; throw e } // cloud_device_unavailable: this deployment runs no cloud device (agent/cloudDeviceRoute.mjs, 501), so nothing here is kept
|
|
25
|
+
catch (e) { if (['not_available', 'cloud_device_unavailable', 'not_enrolled', 'not_in_dev_server', 'sign_in_required'].includes(e.code)) return false; throw e } // sign_in_required: a lapsed sign-in cannot ask — and it blocked every lane and member change of an OPEN room, kept or not (second review, 2026-11-27); // cloud_device_unavailable: this deployment runs no cloud device (agent/cloudDeviceRoute.mjs, 501), so nothing here is kept
|
|
20
26
|
}
|
|
21
27
|
const session = w._session, state = w.backup._s, loc = await a._where()
|
|
22
28
|
current(w, session, state)
|