@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/sdkDictation.js
CHANGED
|
@@ -51,9 +51,11 @@ export class Dictation {
|
|
|
51
51
|
|
|
52
52
|
/** @private the page's key (op:'stt'). */
|
|
53
53
|
async _key() {
|
|
54
|
-
const
|
|
54
|
+
const epoch = this._payerEpoch
|
|
55
|
+
const { idToken, userToken } = this._cloudRun?.auth || await this._who()
|
|
55
56
|
const wb = this._wb
|
|
56
57
|
const r = await wb._client.stt(idToken, userToken)
|
|
58
|
+
if (epoch !== this._payerEpoch) throw err('account_changed', 'the voice payer changed')
|
|
57
59
|
if (r && r.status === 200 && r.key) {
|
|
58
60
|
this._stt = r.cert?.bundle ? { model: r.model, cert: structuredClone(r.cert), bundleGz: r.bundleGz } : null
|
|
59
61
|
return r
|
|
@@ -73,46 +75,126 @@ export class Dictation {
|
|
|
73
75
|
|
|
74
76
|
/** Begin a press. Resolves once the microphone is live and the connection is up (audio said meanwhile is queued).
|
|
75
77
|
* @param {{ onPartial?: (text:string)=>void, onLevel?: (rms:number)=>void }} [opts] */
|
|
76
|
-
async start({ onPartial, onLevel, room } = {}) {
|
|
78
|
+
async start({ onPartial, onLevel, room, engine: choice = 'cloud' } = {}) {
|
|
77
79
|
if (this._live) throw err('already_listening', 'dictation is already listening — stop() or cancel() first')
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
if (choice === 'device') return this._startDevice(room, onPartial, onLevel)
|
|
81
|
+
if (choice !== 'cloud') throw err('invalid_argument', 'choose cloud or device dictation')
|
|
82
|
+
const run = { partial: '', error: null }
|
|
83
|
+
this._cloudRun = run
|
|
84
|
+
this._interrupted = null
|
|
80
85
|
this._live = true
|
|
81
86
|
this._room = typeof room === 'string' ? room : null
|
|
87
|
+
const current = () => this._cloudRun === run
|
|
88
|
+
const interrupted = error => {
|
|
89
|
+
if (!current()) return
|
|
90
|
+
run.error = error
|
|
91
|
+
this.cancel()
|
|
92
|
+
this._interrupted = { text: run.partial, room: this._room, stt: this._stt }
|
|
93
|
+
}
|
|
82
94
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
|
|
95
|
+
run.auth = await this._who()
|
|
96
|
+
if (!current()) return
|
|
97
|
+
const payer = run.auth.userToken || this._wb._session?.email || ''
|
|
98
|
+
if (this._payer !== undefined && payer !== this._payer) {
|
|
99
|
+
this._engine?.close(); this._engine = null; this._stt = null
|
|
100
|
+
}
|
|
101
|
+
this._payer = payer
|
|
102
|
+
const engine = await this._load()
|
|
103
|
+
if (!current()) return
|
|
104
|
+
let stream
|
|
105
|
+
try { stream = await this._gum({ audio: { channelCount: 1, echoCancellation: true, autoGainControl: true, noiseSuppression: true } }) }
|
|
106
|
+
catch (e) { throw err('mic_denied', String(e?.message || e)) }
|
|
107
|
+
if (!current()) { stream.getTracks().forEach(t => t.stop()); return }
|
|
108
|
+
this._stream = stream
|
|
109
|
+
const ready = engine.begin({ onPartial: text => {
|
|
110
|
+
if (current()) { run.partial = text; try { onPartial?.(text) } catch {} }
|
|
111
|
+
}, onError: interrupted })
|
|
112
|
+
await Promise.all([ready, (async () => {
|
|
113
|
+
const capture = await this._mod.startCapture(stream, ({ pcm, rms }) => {
|
|
114
|
+
if (!current()) return
|
|
115
|
+
engine.append(pcm)
|
|
116
|
+
try { onLevel?.(rms) } catch {}
|
|
117
|
+
}, { onError: interrupted })
|
|
118
|
+
if (current()) this._capture = capture
|
|
119
|
+
else capture.stop()
|
|
120
|
+
})()])
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (!current() && !run.error) return
|
|
123
|
+
if (current()) this.cancel()
|
|
124
|
+
throw error?.code ? error : err('stt_unavailable', String(error?.message || error))
|
|
87
125
|
}
|
|
88
|
-
|
|
89
|
-
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async _startDevice(room, onPartial, onLevel) {
|
|
129
|
+
const run = { committed: '', partial: '', transcriber: null }
|
|
130
|
+
this._deviceRun = run; this._interrupted = null; this._live = true; this._room = room || null
|
|
131
|
+
const text = () => [run.committed, run.partial].filter(Boolean).join(' ').trim()
|
|
132
|
+
const update = () => { if (this._deviceRun === run) { try { onPartial?.(text()) } catch {} } }
|
|
90
133
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
134
|
+
const M = await (this._deviceSdk ? this._deviceSdk() : import(new URL('/vendor/moonshine.web.mjs', globalThis.location.href).href))
|
|
135
|
+
if (this._deviceRun !== run) return
|
|
136
|
+
Object.assign(M.Settings.BASE_ASSET_PATH, { MOONSHINE: '/vendor/ms/', ONNX_RUNTIME: '/vendor/ms/ort/', SILERO_VAD: '/vendor/ms/vad/' })
|
|
137
|
+
const t = new M.Transcriber('model/tiny', {
|
|
138
|
+
onSpeechStart: () => { if (run.partial) { run.committed = text(); run.partial = '' } },
|
|
139
|
+
onTranscriptionUpdated: value => { run.partial = value || ''; update() },
|
|
140
|
+
onTranscriptionCommitted: value => { run.committed = [run.committed, value].filter(Boolean).join(' '); run.partial = ''; update() },
|
|
141
|
+
onError: e => { run.error = e || new Error('voice model failed') },
|
|
142
|
+
}, false)
|
|
143
|
+
run.transcriber = t
|
|
144
|
+
const stream = await this._gum({ audio: { channelCount: 1, echoCancellation: true, sampleRate: 16000 } })
|
|
145
|
+
if (this._deviceRun !== run) { for (const track of stream.getTracks()) track.stop(); return }
|
|
146
|
+
this._stream = stream
|
|
147
|
+
t.attachStream(stream)
|
|
148
|
+
await t.start()
|
|
149
|
+
if (this._deviceRun !== run) { this._endDevice(run); return }
|
|
150
|
+
if (onLevel && t.audioContext) {
|
|
151
|
+
const ctx = t.audioContext
|
|
152
|
+
const meter = ctx.createAnalyser()
|
|
153
|
+
meter.fftSize = 256
|
|
154
|
+
run.source = ctx.createMediaStreamSource(stream)
|
|
155
|
+
run.source.connect(meter)
|
|
156
|
+
const samples = new Float32Array(meter.fftSize)
|
|
157
|
+
run.timer = setInterval(() => {
|
|
158
|
+
meter.getFloatTimeDomainData(samples)
|
|
159
|
+
let square = 0
|
|
160
|
+
for (const sample of samples) square += sample * sample
|
|
161
|
+
try { onLevel(Math.sqrt(square / samples.length)) } catch {}
|
|
162
|
+
}, 50)
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (this._deviceRun !== run) return
|
|
166
|
+
this.cancel()
|
|
167
|
+
throw err(/permission|denied|notallowed/i.test(String(error)) ? 'mic_denied' : 'stt_unavailable', String(error?.message || error))
|
|
101
168
|
}
|
|
102
169
|
}
|
|
103
170
|
|
|
171
|
+
_endDevice(run) {
|
|
172
|
+
const t = run.transcriber
|
|
173
|
+
clearInterval(run.timer)
|
|
174
|
+
try { run.source?.disconnect() } catch {}
|
|
175
|
+
try { t?.stop() } catch {}
|
|
176
|
+
try { const context = t?.audioContext; if (context && context.state !== 'closed') context.close().catch(() => {}) } catch {}
|
|
177
|
+
}
|
|
178
|
+
|
|
104
179
|
/** End the press. → the final text ('' if nothing was said). */
|
|
105
180
|
async stop() {
|
|
106
|
-
if (!this._live) return ''
|
|
181
|
+
if (!this._live) { const interrupted = this._interrupted; this._interrupted = null; return interrupted?.text || '' }
|
|
107
182
|
this._live = false
|
|
183
|
+
this._cloudRun = null
|
|
108
184
|
this._release()
|
|
109
|
-
|
|
185
|
+
if (this._deviceRun) {
|
|
186
|
+
const run = this._deviceRun; this._deviceRun = null
|
|
187
|
+
this._endDevice(run)
|
|
188
|
+
if (run.error) throw err('stt_unavailable', String(run.error.message || run.error))
|
|
189
|
+
return [run.committed, run.partial].filter(Boolean).join(' ').trim()
|
|
190
|
+
}
|
|
191
|
+
return this._engine?.commit() || ''
|
|
110
192
|
}
|
|
111
193
|
|
|
112
194
|
/** Finish room-bound dictation and return the public certificate alongside the transcript. */
|
|
113
195
|
async stopCertified() {
|
|
114
|
-
if (!this._live || !this._room) throw err('dictation_room_required', 'start dictation with the destination room')
|
|
115
|
-
const room = this._room, stt = this._stt
|
|
196
|
+
if ((!this._live && !this._interrupted) || !this._room) throw err('dictation_room_required', 'start dictation with the destination room')
|
|
197
|
+
const room = this._room, stt = this._deviceRun ? null : (this._interrupted?.stt || this._stt)
|
|
116
198
|
const text = await this.stop()
|
|
117
199
|
const result = Object.freeze({ text, room, certificate: stt?.cert ? structuredClone(stt.cert) : null })
|
|
118
200
|
certifications.set(result, { room, stt })
|
|
@@ -123,7 +205,9 @@ export class Dictation {
|
|
|
123
205
|
cancel() {
|
|
124
206
|
if (!this._live) return
|
|
125
207
|
this._live = false
|
|
208
|
+
this._cloudRun = null
|
|
126
209
|
this._release()
|
|
210
|
+
if (this._deviceRun) { const run = this._deviceRun; this._deviceRun = null; this._endDevice(run); return }
|
|
127
211
|
try { this._engine.cancel() } catch { /* */ }
|
|
128
212
|
}
|
|
129
213
|
|
|
@@ -133,6 +217,12 @@ export class Dictation {
|
|
|
133
217
|
try { this._engine && this._engine.close() } catch { /* */ }
|
|
134
218
|
}
|
|
135
219
|
|
|
220
|
+
_resetPayer() {
|
|
221
|
+
this._payerEpoch = (this._payerEpoch || 0) + 1
|
|
222
|
+
this.close()
|
|
223
|
+
this._engine = null; this._stt = null; this._payer = undefined; this._interrupted = null
|
|
224
|
+
}
|
|
225
|
+
|
|
136
226
|
_release() {
|
|
137
227
|
try { this._capture && this._capture.stop() } catch { /* */ }
|
|
138
228
|
this._capture = null
|
package/sdkErase.js
CHANGED
|
@@ -177,6 +177,7 @@ export class Erasure {
|
|
|
177
177
|
try { if (wb.account && wb.account.enabled && typeof wb.account._where === 'function') indexRoom = (await wb.account._where()).room } catch { indexRoom = null }
|
|
178
178
|
const d = this._deleteDeps || {}
|
|
179
179
|
const client = wb._client
|
|
180
|
+
const temporaryScope = wb.temporaryRooms?._scope()
|
|
180
181
|
const rep = await eraseAccount({
|
|
181
182
|
me: { email: this._account(), names: (Array.isArray(names) ? names : []).map((n) => String(n || '').trim()).filter(Boolean).slice(0, 20) },
|
|
182
183
|
indexRoom,
|
|
@@ -224,10 +225,14 @@ export class Erasure {
|
|
|
224
225
|
backupGone: () => { if (backup._s) { clearTimeout(backup._timer); backup._timer = null; backup._s.erased = true; backup._changed() } }, // pass 7, F#2: no write re-creates it, even if a later step fails
|
|
225
226
|
withdrawFiled: d.withdrawFiled || (this._tenant() ? async () => { const dd = this._d(); const r = await fileEraseList({ tenant: this._tenant(), account: this._account(), rooms: [], keys: [key], dropKeys, post: dd.post, auth: dd.auth, attest: dd.attest, seal: dd.seal, ls: this._ls, force: true }).catch(() => null); return { ok: !!(r && r.filed) } } : null),
|
|
226
227
|
wipe: async () => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
try {
|
|
229
|
+
if (temporaryScope) wb.temporaryRooms._erase(temporaryScope)
|
|
230
|
+
} finally {
|
|
231
|
+
this._opened = []; this._marked.clear(); this._k = { master: null, key: null }
|
|
232
|
+
try { if (wb.account && typeof wb.account.stop === 'function') wb.account.stop() } catch { /* */ }
|
|
233
|
+
backup._drop() // onState(null): the builder persists that this client holds no account any more
|
|
234
|
+
wb.signOut()
|
|
235
|
+
}
|
|
231
236
|
},
|
|
232
237
|
onStep,
|
|
233
238
|
})
|
package/sdkExports.js
CHANGED
|
@@ -49,7 +49,8 @@ export async function recreateExport(wb, bundle, { tier = bundle?.tier || (bundl
|
|
|
49
49
|
return { space, carried: result.carried, total: result.total, ...(titleWarning ? { titleWarning } : {}) }
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export async function saveAccountArchive(rooms, resolveRoom, recoveryKeys, current) {
|
|
52
|
+
export async function saveAccountArchive(rooms, resolveRoom, recoveryKeys, current, destination = 'download') {
|
|
53
|
+
if (!['download', 'clipboard'].includes(destination) || (destination === 'clipboard' && !recoveryKeys)) throw Object.assign(new Error('Invalid archive destination'), { code: 'invalid_argument' })
|
|
53
54
|
const spaces = [], keys = [], unavailable = []
|
|
54
55
|
for (const r of rooms) {
|
|
55
56
|
if (!current()) throw new Error('account_changed')
|
|
@@ -63,7 +64,8 @@ export async function saveAccountArchive(rooms, resolveRoom, recoveryKeys, curre
|
|
|
63
64
|
if (!current()) throw new Error('account_changed')
|
|
64
65
|
const saved = recoveryKeys ? keys.length : spaces.length
|
|
65
66
|
if (!saved) throw Object.assign(new Error('No rooms could be exported.'), { code: 'archive_empty', unavailable })
|
|
66
|
-
if (
|
|
67
|
+
if (destination === 'clipboard') await navigator.clipboard.writeText(keysFileText(keys))
|
|
68
|
+
else if (recoveryKeys) saveExport('witbitz-room-keys.txt', keysFileText(keys), 'text/plain')
|
|
67
69
|
else saveExport('witbitz-spaces.json', JSON.stringify(makeBundle(spaces)), 'application/json')
|
|
68
70
|
return { saved, unavailable }
|
|
69
71
|
}
|
package/sdkLaneLink.js
CHANGED
|
@@ -74,13 +74,13 @@ export function laneLinkTool(lane) {
|
|
|
74
74
|
async function postAndWake(lane, text, from, { ask = false } = {}) {
|
|
75
75
|
// Given up = given up (sync sweep, 2026-10-10): a pass's send still held for "busy" is not resent after the wait (the
|
|
76
76
|
// pass retries it, and a second copy would forward twice); and `from` is the LINK's label, never the member's name.
|
|
77
|
-
let timedOut = false
|
|
77
|
+
let timedOut = false, timer
|
|
78
78
|
try {
|
|
79
79
|
const sent = lane.send(text, { from, mode: 'always', ...(ask ? { _noHold: true } : { _aborted: () => timedOut }), _linkPost: true })
|
|
80
|
-
const r = await Promise.race([sent, new Promise((res) => setTimeout(() => { timedOut = true; res(null) }, ask ? ASK_WAIT_MS : WAKE_WAIT_MS))])
|
|
80
|
+
const r = await Promise.race([sent, new Promise((res) => { timer = setTimeout(() => { timedOut = true; res(null) }, ask ? ASK_WAIT_MS : WAKE_WAIT_MS) })])
|
|
81
81
|
if (r === null && ask) { sent.catch(() => {}); return true } // still running: the question is in, the turn is answering it
|
|
82
82
|
return !!(r && r.status === 200 && !r.busy && r.ok !== false)
|
|
83
|
-
} catch { return false }
|
|
83
|
+
} catch { return false } finally { clearTimeout(timer) }
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export class LaneLink {
|
package/sdkPlan.js
CHANGED
|
@@ -21,7 +21,7 @@ const RANK = { none: 0, in_place: 1, fork: 2, new_room: 3 }
|
|
|
21
21
|
* @param room { cfg (the room's sealed config, or null), me (the signed-in email, or ''), lane (bool), checkData?(data) }
|
|
22
22
|
* → { how: 'none'|'in_place'|'new_room'|'refused', history: 'kept'|'not_carried'|null, call, steps, reason? }
|
|
23
23
|
*/
|
|
24
|
-
export function planChange (change = {}, { cfg = null, me = '', lane = false, checkData = null, gatedUnread = false, signIn = 'wb.signIn' } = {}) { // signIn: the call that signs in here ('wb.vault.signIn' in a vault) // gatedUnread: a gated room answered only its stub (not signed in)
|
|
24
|
+
export function planChange (change = {}, { cfg = null, me = '', lane = false, activeLane = lane, checkData = null, gatedUnread = false, signIn = 'wb.signIn' } = {}) { // signIn: the call that signs in here ('wb.vault.signIn' in a vault) // gatedUnread: a gated room answered only its stub (not signed in)
|
|
25
25
|
const steps = []
|
|
26
26
|
let members = false // the change includes a member list (in place: space.changeMembers)
|
|
27
27
|
let how = 'none', refusal = null
|
|
@@ -29,7 +29,9 @@ export function planChange (change = {}, { cfg = null, me = '', lane = false, ch
|
|
|
29
29
|
const refuse = (code, reason) => { if (!refusal) refusal = { code, reason } }
|
|
30
30
|
// a private lane follows its Space's Safe media — refused as configure() refuses it (sync sweep 2026-11-02 #2), and FIRST, as
|
|
31
31
|
// configure() checks it first: after the admin/sign-in checks a lane read signed out planned sign_in_required (2026-11-03 #6)
|
|
32
|
-
if (
|
|
32
|
+
if (change.lanes !== undefined && typeof change.lanes !== 'boolean') refuse('invalid_argument', 'lanes takes true or false')
|
|
33
|
+
if (lane && change.lanes !== undefined) refuse('lane', 'a private lane has no private assistants of its own')
|
|
34
|
+
if (activeLane && change.safeMedia !== undefined) refuse('lane_follows_space', 'a private lane follows its Space’s Safe media — set it on the Space')
|
|
33
35
|
|
|
34
36
|
const agent = change.agent && typeof change.agent === 'object' ? change.agent : {}
|
|
35
37
|
for (const k of Object.keys(agent)) {
|
package/sdkRekey.js
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
import { enroll, resolveHandle } from './inviteEnroll.js'
|
|
13
13
|
import { genRecipientKey, openBox, commit, combineShares } from './e2ee.js'
|
|
14
14
|
import { tokenApp, tokenClaims } from './accountScope.js'
|
|
15
|
-
import {
|
|
15
|
+
import { GATE_DOMAIN } from './emailFork.js'
|
|
16
|
+
import { EMAIL, normalizeDomains, lc, recipientsFor, membersAfter, unseenHidden, stillOnList, dropsForUsers } from './memberChange.js'
|
|
16
17
|
import { ROSTER_DOC } from './roomRoster.js'
|
|
17
18
|
import { hide } from './sdkRedact.js'
|
|
18
19
|
import { assertNotKept } from './sdkCloudDevice.js'
|
|
@@ -169,26 +170,27 @@ async function currentMembers (space, cfg) {
|
|
|
169
170
|
const onList = await stillOnList(cfg, space.room, Object.values(book.seen || {}).filter((x) => x && x.email && !x.left)).catch(() => null) // the records: a person in by @username is on by the entry they came in by (sync sweep 11-23 #2)
|
|
170
171
|
const seen = onList ? seen0.filter((e) => onList(e, '')) : seen0
|
|
171
172
|
const emails = [...new Set([...(Array.isArray(al.emails) ? al.emails : []), ...seen].map(lc))]
|
|
172
|
-
return { emails, owners: ((cfg.owners && cfg.owners.emails) || []).map(lc), admins: ((cfg.admins && cfg.admins.emails) || []).map(lc) }
|
|
173
|
+
return { book, emails, owners: ((cfg.owners && cfg.owners.emails) || []).map(lc), admins: ((cfg.admins && cfg.admins.emails) || []).map(lc) }
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
const epochOf = (cfg) => (Array.isArray(cfg && cfg.keyChain) ? cfg.keyChain.length : 0) // the epoch a config was read at (= the app's rekeyToWant)
|
|
176
|
-
async function rekeyNow (space, { members, stay, allowAfter, expectEpoch = null }) {
|
|
177
|
+
async function rekeyNow (space, { members, stay, allowAfter, expectEpoch = null, book }) {
|
|
177
178
|
const me = lc(space._wb && space._wb._session && space._wb._session.email)
|
|
178
179
|
const wb = space._wb
|
|
179
180
|
const scope = inviteScope(wb._session.idToken)
|
|
180
181
|
if (!wb.invite._key()) await wb.invite.enroll()
|
|
181
|
-
const book = await space._client.state(space.room, space._mk, ROSTER_DOC).catch(() => null)
|
|
182
|
-
if (!book || (book.status !== undefined && book.status !== 200)) throw sdkError('witbitz: the member list could not be read — nothing changed', 'book_unavailable')
|
|
183
182
|
const people = Object.values(book.seen || {})
|
|
184
183
|
const retained = await stillOnList({ keyChain: [{ epoch: expectEpoch }], allow: allowAfter }, space.room, people)
|
|
185
|
-
const
|
|
186
|
-
const
|
|
184
|
+
const domains = new Set(normalizeDomains(allowAfter?.domains))
|
|
185
|
+
const joined = people.filter(p => p && !p.left && p.email && retained(p.email) &&
|
|
186
|
+
(domains.has(lc(p.email).split('@')[1]) || p.entries?.some(e => typeof e === 'string' && e.startsWith('u:')))).map(p => lc(p.email))
|
|
187
|
+
const { recipients, unreachable, pending } = await recipientsFor(space.room, [...stay, ...joined], wb._client || space._client, { scope, allow: allowAfter, people }) // include observed retained legacy handles, never arbitrary roster emails
|
|
187
188
|
if (!recipients.some((x) => x.email === me)) throw sdkError('witbitz: this account has no invite key for this app yet (wb.invite.status: ' + wb.invite.status + ') — restore wb.invite.state from the device that has it', 'no_invite_key')
|
|
188
189
|
const split = space._split ? { userShare: fragParam(space.shareLink, 'us') } : null
|
|
189
190
|
if (space._split && !split.userShare) throw sdkError('witbitz: this split Space was not opened from its link — its user half is unknown here', 'invalid_argument')
|
|
190
|
-
const r = await space._client.rekey(space.room, space._mk, { ...(members ? { members } : {}), recipients: recipients.map(({ mh, boxPub }) => ({ mh, boxPub })), pending: [...pending, ...unseenHidden(allowAfter, recipients, pending)], by: me, ...(split ? { split } : {}), ...(Number.isInteger(expectEpoch) ? { expectEpoch } : {}) }) // ONE SNAPSHOT (docs/state-machines.md V#5, the SDK's twin K#1): the change was planned at this epoch — a key adopted on the way (the healing client's retry) must not apply it to another
|
|
191
|
+
const r = await space._client.rekey(space.room, space._mk, { ...(members ? { members } : {}), recipients: recipients.map(({ mh, boxPub }) => ({ mh, boxPub })), pending: [...pending, ...unseenHidden(allowAfter, recipients, pending)], by: me, ...(split ? { split } : {}), ...(Number.isInteger(expectEpoch) ? { expectEpoch } : {}) }).catch(() => null) // ONE SNAPSHOT (docs/state-machines.md V#5, the SDK's twin K#1): the change was planned at this epoch — a key adopted on the way (the healing client's retry) must not apply it to another
|
|
191
192
|
if (!r || r.status !== 200 || !(r.newMk || r.newShare)) { // a split room in a vault: the worker keeps the key and answers only the new share (sweep 10-23 #3; the app's rekeyMembers takes it too)
|
|
193
|
+
if (!r || !r.status || r.status >= 500 || r.status === 200) throw sdkError('The service did not confirm the new key. Refresh this Space to check its current membership before trying again.', 'rekey_unknown')
|
|
192
194
|
const code = r && r.error === 'stale_epoch' ? 'changed_meanwhile' : (r && r.error) || 'rekey_failed'
|
|
193
195
|
throw Object.assign(new Error('witbitz: the key was not changed — nothing has changed' + (r && r.reason ? ` (${r.reason})` : '')), { code, status: r && r.status })
|
|
194
196
|
}
|
|
@@ -253,42 +255,73 @@ export async function listAfter (cfg, room, want, { book, tagOf } = {}) {
|
|
|
253
255
|
* when nobody's access changes (only who manages it; the key stays). One rule for the SDK's change and the vault's question
|
|
254
256
|
* (sync sweep 10-26 #3: the vault compared only the shown addresses). `cfg`: the config changeable() read, else it is read. */
|
|
255
257
|
export async function planMembers (space, admission = {}, cfg = null) {
|
|
258
|
+
if (admission.domains !== undefined && (!Array.isArray(admission.domains) || admission.domains.some(d => typeof d !== 'string' || !GATE_DOMAIN.test(lc(d).replace(/^@/, ''))))) throw sdkError('witbitz: invalid admission domain', 'invalid_argument')
|
|
256
259
|
if (!cfg) cfg = (await changeable(space, 'changeMembers')).cfg
|
|
257
260
|
const emails = [...new Set((Array.isArray(admission.emails) ? admission.emails : []).map(lc).filter(Boolean))]
|
|
258
261
|
if (!emails.length) throw sdkError('witbitz: changeMembers needs admission.emails (the whole list)', 'invalid_argument')
|
|
259
262
|
// An @username is not an email: the SDK cannot add one (intended.md) — say so instead of reporting it unreachable (sync sweep 2026-11-23)
|
|
260
|
-
const handle = emails.
|
|
261
|
-
if (handle) throw sdkError(`witbitz: changeMembers takes email addresses only (${handle})`, 'invalid_argument')
|
|
263
|
+
const handle = [...emails, ...(Array.isArray(admission.owners) ? admission.owners : []), ...(Array.isArray(admission.admins) ? admission.admins : [])].find(e => !EMAIL.test(lc(e)))
|
|
264
|
+
if (handle !== undefined) throw sdkError(`witbitz: changeMembers takes email addresses only (${handle})`, 'invalid_argument')
|
|
262
265
|
const cur = await currentMembers(space, cfg)
|
|
263
266
|
const want = {
|
|
264
267
|
emails,
|
|
265
268
|
...(Array.isArray(admission.domains) ? { domains: admission.domains } : {}),
|
|
266
269
|
owners: Array.isArray(admission.owners) ? admission.owners.map(lc) : cur.owners,
|
|
267
270
|
admins: Array.isArray(admission.admins) ? admission.admins.map(lc) : cur.admins,
|
|
268
|
-
shown: admission.advertise === true ? emails : Array.isArray(admission.advertise) ? admission.advertise : ((cfg.allow && cfg.allow.emails) || []).map(lc).filter((e) => emails.includes(e)),
|
|
271
|
+
shown: admission.advertise === true ? emails : admission.advertise === false ? [] : Array.isArray(admission.advertise) ? admission.advertise : ((cfg.allow && cfg.allow.emails) || []).map(lc).filter((e) => emails.includes(e)),
|
|
269
272
|
}
|
|
270
273
|
const c = (space._wb && space._wb._client) || space._client
|
|
271
274
|
const tagOf = async (u) => { const t = typeof c.userTag === 'function' ? await c.userTag(u, space.room).catch(() => null) : null; return t && t.status === 200 ? t.tag : '' }
|
|
272
|
-
const
|
|
273
|
-
|
|
275
|
+
const domains = normalizeDomains(want.domains ?? cfg.allow?.domains)
|
|
276
|
+
const admitted = address => emails.includes(address) || domains.includes(address.split('@')[1])
|
|
277
|
+
for (const role of ['owners', 'admins']) {
|
|
278
|
+
if (Array.isArray(admission[role])) {
|
|
279
|
+
const outside = want[role].find(address => !admitted(address))
|
|
280
|
+
if (outside) throw sdkError('A manager must already be admitted by email or domain: ' + outside, 'invalid_argument')
|
|
281
|
+
} else {
|
|
282
|
+
const retained = []
|
|
283
|
+
for (const address of want[role]) {
|
|
284
|
+
if (admitted(address) || (!cur.emails.includes(address) && cfg.allow?.mh?.includes(await memberHash(address, space.room)))) retained.push(address)
|
|
285
|
+
}
|
|
286
|
+
want[role] = retained
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const m = await listAfter(cfg, space.room, { ...want, known: cur.emails }, { book: () => cur.book, tagOf })
|
|
290
|
+
// ⛔ NOT YOURSELF, SILENTLY (second review, 2026-11-27): a manager the new list does not admit is dropped (545f3a97f, so a role cannot
|
|
291
|
+
// admit anyone) — a manager who leaves THEIR OWN address off the whole list would lose the Space with no word. Refused by name
|
|
292
|
+
// instead: they add it, or leave the Space. Asked of the change itself (`m.removed`), so a manager who stays by a domain, a
|
|
293
|
+
// hidden-member hash or an @username tag is not refused.
|
|
294
|
+
const actor = lc(space._wb?._session?.email)
|
|
295
|
+
if (actor && (cur.owners.includes(actor) || cur.admins.includes(actor)) && (m.removed || []).map(lc).includes(actor)) {
|
|
296
|
+
throw sdkError('witbitz: your own address is not on the new list — add it, or leave the Space instead', 'invalid_argument')
|
|
297
|
+
}
|
|
298
|
+
return { emails, cur, want, m, epoch: epochOf(cfg), actor: lc(space._wb?._session?.email), roles: !m.removed.length && sameList(cfg.allow, m.allow) }
|
|
274
299
|
}
|
|
275
300
|
|
|
276
301
|
/** space.changeMembers(admission) — `admission`: { emails, domains?, admins?, owners?, advertise? }, the list stated in FULL,
|
|
277
302
|
* as fork() takes it. → { inPlace:true, epoch, link, removed, added, unreachable } */
|
|
278
|
-
export async function changeMembers (space, admission = {}) {
|
|
303
|
+
export async function changeMembers (space, admission = {}, approved = null) {
|
|
279
304
|
await assertNotKept(space)
|
|
280
305
|
const { cfg, me } = await changeable(space, 'changeMembers')
|
|
281
|
-
const
|
|
306
|
+
const plan = await planMembers(space, admission, cfg)
|
|
307
|
+
const approvalFields = p => {
|
|
308
|
+
const { book, ...cur } = p.cur
|
|
309
|
+
const admissions = Object.values(book?.seen || {}).filter(x => x && !x.left).map(x => JSON.stringify([lc(x.email), x.user || '', [...(x.entries || [])].sort()])).sort()
|
|
310
|
+
return JSON.stringify({ ...p, cur, admissions })
|
|
311
|
+
}
|
|
312
|
+
if (approved && approvalFields(plan) !== approvalFields(approved)) throw sdkError('Space membership changed during confirmation. Review it again.', 'config_changed')
|
|
313
|
+
const { emails, cur, want, m, roles } = plan
|
|
282
314
|
// A ROLE CHANGE NEEDS NO NEW KEY (the app's decision 4, verifiedMove.js; sweep 10-23 #16): nobody's access changes, so the
|
|
283
315
|
// room keeps its key and the config changes in place (op 'config'). A server that does not take it yet answers
|
|
284
316
|
// config_immutable / not_enabled: then the change is made as before, by a re-key.
|
|
285
317
|
if (roles && typeof space._client.setConfig === 'function') {
|
|
286
318
|
const r = await space._client.setConfig(space.room, space._mk, { admins: m.admins, owners: m.owners }, space._who ? space._who() : 'An admin').catch(() => null)
|
|
287
319
|
if (r && r.status === 200) return { inPlace: true, roles: true, epoch: space.epoch, link: space.shareLink, removed: [], added: [], unreachable: [] }
|
|
320
|
+
if (!r || !r.status || r.status >= 500) throw sdkError('The service did not confirm the role change. Refresh the membership list before trying again.', 'config_unknown')
|
|
288
321
|
if (!(r && (r.error === 'config_immutable' || r.error === 'not_enabled'))) throw Object.assign(new Error('witbitz: the roles were not changed — nothing has changed' + (r && r.reason ? ` (${r.reason})` : '')), { code: (r && r.error) || 'config_failed', status: r && r.status })
|
|
289
322
|
}
|
|
290
323
|
const stay = [...new Set([...want.emails, ...want.owners, ...want.admins, me])]
|
|
291
|
-
const { epoch, unreachable } = await rekeyNow(space, { members: { allow: m.allow, owners: m.owners, admins: m.admins }, stay, allowAfter: m.allow, expectEpoch: epochOf(cfg) })
|
|
324
|
+
const { epoch, unreachable } = await rekeyNow(space, { members: { allow: m.allow, owners: m.owners, admins: m.admins }, stay, allowAfter: m.allow, expectEpoch: epochOf(cfg), book: cur.book })
|
|
292
325
|
// added = on neither list before: not an address the room showed or its book knew, and not a hidden address's hash
|
|
293
326
|
const hidden = new Set(Array.isArray(cfg.allow && cfg.allow.mh) ? cfg.allow.mh : [])
|
|
294
327
|
const before = new Set(cur.emails)
|
|
@@ -302,6 +335,6 @@ export async function rotateKey (space) {
|
|
|
302
335
|
const { cfg, me } = await changeable(space, 'rotateKey')
|
|
303
336
|
const cur = await currentMembers(space, cfg)
|
|
304
337
|
const stay = [...new Set([...cur.emails, ...cur.owners, ...cur.admins, me])]
|
|
305
|
-
const { epoch, unreachable } = await rekeyNow(space, { members: null, stay, allowAfter: cfg.allow || {}, expectEpoch: epochOf(cfg) })
|
|
338
|
+
const { epoch, unreachable } = await rekeyNow(space, { members: null, stay, allowAfter: cfg.allow || {}, expectEpoch: epochOf(cfg), book: cur.book })
|
|
306
339
|
return { inPlace: true, rotated: true, epoch, link: space.shareLink, unreachable }
|
|
307
340
|
}
|
package/sdkReport.js
CHANGED
|
@@ -41,7 +41,7 @@ export function reportBody (space, message, { reason, note = '', context = false
|
|
|
41
41
|
const before = []
|
|
42
42
|
if (context === true) {
|
|
43
43
|
const list = space.messages || [], at = list.findIndex((m) => m && m.id === message.id)
|
|
44
|
-
for (let i =
|
|
44
|
+
for (let i = at - 1; i >= 0 && before.length < CONTEXT; i--) if (isPerson(list[i])) before.unshift(reportEntry(list[i], who(list[i])))
|
|
45
45
|
}
|
|
46
46
|
return { room: space.room, reason, note: String(note || '').slice(0, 500), entry: reportEntry(message, who(message), { proof: true }), context: before, ...(space._isEnclave() ? { confidential: true } : {}) }
|
|
47
47
|
}
|
package/sdkSafeMedia.js
CHANGED
|
@@ -80,7 +80,7 @@ export class SpaceSafeMedia {
|
|
|
80
80
|
// a SLEEPING confidential Space reads nothing: wake it and read once more, as the vault does (sweep P2: a lane's refresh,
|
|
81
81
|
// which reads its Space's, failed until something else woke it)
|
|
82
82
|
const wb = this._s._wb
|
|
83
|
-
if (!cfg && wb && typeof wb._encWake === 'function' && typeof this._s._isEnclave === 'function' && this._s._isEnclave()) {
|
|
83
|
+
if (!cfg && !c.keyless && !c.vault && wb && typeof wb._encWake === 'function' && typeof this._s._isEnclave === 'function' && this._s._isEnclave()) {
|
|
84
84
|
try { await wb._encWake(this._s.room, { tries: 8 }); cfg = await c.getConfig(this._s.room, this._s._mk) } catch { /* said below */ }
|
|
85
85
|
}
|
|
86
86
|
// "sign in" only where it is the reason — a gated room's settings before sign-in; a sleeping enclave or a failed read is not
|
package/sdkSpeech.js
CHANGED
|
@@ -25,12 +25,17 @@ export class Speech {
|
|
|
25
25
|
get playing () { return this._player.playing }
|
|
26
26
|
|
|
27
27
|
/** @private the page's key (op:'tts'): a signed-in session first (the person), else the tenant's user token. */
|
|
28
|
-
async
|
|
28
|
+
async _who () {
|
|
29
29
|
const wb = this._wb, sess = wb._session
|
|
30
30
|
const idToken = sess && sess.idToken && !(sess.exp && sess.exp <= Date.now()) ? sess.idToken : ''
|
|
31
31
|
let userToken = ''
|
|
32
32
|
try { const t = typeof wb._userToken === 'function' ? await wb._userToken() : wb._userToken; userToken = typeof t === 'string' ? t : '' } catch { userToken = '' }
|
|
33
33
|
if (!idToken && !userToken && !wb.vault) throw err('sign_in_required', 'speak needs a signed-in user (wb.signIn) or a user token (wb.useUserToken)') // in a vault, the vault's sign-in mints the key
|
|
34
|
+
return { idToken, userToken, payer: userToken || sess?.email || '' }
|
|
35
|
+
}
|
|
36
|
+
async _key () {
|
|
37
|
+
const { idToken, userToken } = this._playAuth || await this._who()
|
|
38
|
+
const wb = this._wb
|
|
34
39
|
const r = await wb._client.tts(idToken, userToken)
|
|
35
40
|
if (!r || r.status !== 200 || !r.key) {
|
|
36
41
|
const code = (r && r.error === 'signin_required') ? 'sign_in_required' : (r && r.status === 429) ? 'tts_rate_limited' : 'tts_unavailable'
|
|
@@ -42,7 +47,19 @@ export class Speech {
|
|
|
42
47
|
/** Read `text` aloud → resolves when it has played. Rejects with `code`: `no_hebrew`, `empty`, `sign_in_required`,
|
|
43
48
|
* `tts_rate_limited`, `tts_unavailable`, `http_<status>`, `audio` / `play` (the browser would not play it). A new call
|
|
44
49
|
* stops the one playing. */
|
|
50
|
+
_resetPayer () {
|
|
51
|
+
this._epoch = (this._epoch || 0) + 1
|
|
52
|
+
this._playAuth = null
|
|
53
|
+
this._player.resetKey()
|
|
54
|
+
}
|
|
45
55
|
async play (text) {
|
|
56
|
+
const seq = this._sequence = (this._sequence || 0) + 1
|
|
57
|
+
const epoch = this._epoch
|
|
58
|
+
const auth = await this._who()
|
|
59
|
+
if (seq !== this._sequence) return
|
|
60
|
+
if (epoch !== this._epoch) throw err('account_changed', 'the voice payer changed')
|
|
61
|
+
if (this._playAuth && this._playAuth.payer !== auth.payer) this._player.resetKey()
|
|
62
|
+
this._playAuth = auth
|
|
46
63
|
try { await this._player.play(String(text == null ? '' : text)) } catch (e) {
|
|
47
64
|
if (e && e.code && !String(e.message || '').startsWith('witbitz:')) e.message = 'witbitz: ' + e.message
|
|
48
65
|
throw e
|
|
@@ -50,5 +67,5 @@ export class Speech {
|
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
/** Stop what is playing (its promise resolves). */
|
|
53
|
-
stop () { this._player.stop() }
|
|
70
|
+
stop () { this._sequence = (this._sequence || 0) + 1; this._player.stop() }
|
|
54
71
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { deviceWrapKey } from './vaultAtRest.js'
|
|
2
|
+
import { seal, open } from './deviceSeal.js'
|
|
3
|
+
|
|
4
|
+
const fail = (code, message) => Object.assign(new Error('witbitz: ' + message), { code })
|
|
5
|
+
const pendingScope = wb => JSON.stringify([wb._endpoint, wb._tenant, wb._clientOpts.app || '', wb._session?.email || ''])
|
|
6
|
+
const storagePrefix = scope => 'wb-sdk:temporary:' + encodeURIComponent(scope) + ':'
|
|
7
|
+
|
|
8
|
+
export class TemporaryRooms {
|
|
9
|
+
constructor(wb, persist) {
|
|
10
|
+
this._wb = wb
|
|
11
|
+
this._persist = persist === true
|
|
12
|
+
this._memory = new Map()
|
|
13
|
+
this._generation = 0
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
_scope() {
|
|
17
|
+
if (this._wb.vault) throw fail('vault_unsupported', 'temporary rooms are unavailable in vault mode')
|
|
18
|
+
return pendingScope(this._wb)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async _remember(sp, scope, { days, title } = {}) {
|
|
22
|
+
if (scope !== this._scope()) return
|
|
23
|
+
const generation = this._generation, name = storagePrefix(scope) + sp.room
|
|
24
|
+
const previous = this._memory.get(name) || (await this._records(scope, sp.room)).get(name)
|
|
25
|
+
if (scope !== this._scope() || generation !== this._generation) return
|
|
26
|
+
const record = { ...previous, room: sp.room, link: sp.shareLink, at: previous?.at || Date.now() }
|
|
27
|
+
if (days) record.days = days
|
|
28
|
+
const label = sp.title || title
|
|
29
|
+
if (label) record.title = String(label).slice(0, 200)
|
|
30
|
+
sp._temporaryScope = scope
|
|
31
|
+
this._memory.set(name, record)
|
|
32
|
+
if (!this._persist) return
|
|
33
|
+
try {
|
|
34
|
+
const key = await deviceWrapKey({ name: 'witbitz-sdk-temporary' })
|
|
35
|
+
if (!key) return
|
|
36
|
+
const blob = await seal(key, { scope, ...record })
|
|
37
|
+
if (pendingScope(this._wb) === scope && this._generation === generation && this._memory.get(name) === record) globalThis.localStorage.setItem(name, JSON.stringify(blob))
|
|
38
|
+
} catch { /* still available in this SDK instance */ }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async _records(scope, onlyRoom) {
|
|
42
|
+
const prefix = storagePrefix(scope)
|
|
43
|
+
const wanted = onlyRoom ? prefix + onlyRoom : null
|
|
44
|
+
const rows = new Map([...this._memory].filter(([k]) => wanted ? k === wanted : k.startsWith(prefix)))
|
|
45
|
+
if (!this._persist) return rows
|
|
46
|
+
let key, storage
|
|
47
|
+
try {
|
|
48
|
+
storage = globalThis.localStorage
|
|
49
|
+
if (!storage) return rows
|
|
50
|
+
key = await deviceWrapKey({ name: 'witbitz-sdk-temporary' })
|
|
51
|
+
} catch { return rows }
|
|
52
|
+
if (!key) return rows
|
|
53
|
+
const names = wanted ? [wanted] : Array.from({ length: storage.length }, (_, i) => storage.key(i))
|
|
54
|
+
for (const name of names) {
|
|
55
|
+
if (!name?.startsWith(prefix) || rows.has(name)) continue
|
|
56
|
+
try {
|
|
57
|
+
const blob = storage.getItem(name)
|
|
58
|
+
if (!blob) continue
|
|
59
|
+
const row = await open(key, JSON.parse(blob))
|
|
60
|
+
if (row?.scope === scope && row.room?.startsWith('tmp-') && name === prefix + row.room) rows.set(name, row)
|
|
61
|
+
} catch { /* leave unreadable records in place and continue with the others */ }
|
|
62
|
+
}
|
|
63
|
+
return rows
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async _status(row) {
|
|
67
|
+
if (Date.now() - row.at < (row.days ? row.days * 86_400_000 : 30 * 60_000)) return 'recent'
|
|
68
|
+
try {
|
|
69
|
+
const k = await this._wb._openLink(row.link)
|
|
70
|
+
if (k.room !== row.room) return 'unknown'
|
|
71
|
+
const r = await this._wb._client.pollSealed(k.room, k.mk, '', 0)
|
|
72
|
+
if (r?.status === 410) return 'expired'
|
|
73
|
+
if (r?.status === 200 && !r.changed && !r.entries?.length) return 'unknown'
|
|
74
|
+
return r?.status === 200 ? 'live' : 'unknown'
|
|
75
|
+
} catch { return 'unknown' }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_drop(name) {
|
|
79
|
+
this._memory.delete(name)
|
|
80
|
+
if (this._persist) globalThis.localStorage?.removeItem(name)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_title(sp) {
|
|
84
|
+
if (sp._temporaryScope !== this._scope()) return
|
|
85
|
+
const row = this._memory.get(storagePrefix(sp._temporaryScope) + sp.room)
|
|
86
|
+
if (row && row.title !== sp.title) this._remember(sp, sp._temporaryScope).catch(() => {})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_erase(scope) {
|
|
90
|
+
this._generation++
|
|
91
|
+
const prefix = storagePrefix(scope)
|
|
92
|
+
for (const name of this._memory.keys()) if (name.startsWith(prefix)) this._memory.delete(name)
|
|
93
|
+
let storage
|
|
94
|
+
try { storage = globalThis.localStorage } catch { return }
|
|
95
|
+
if (!storage) return
|
|
96
|
+
for (let i = storage.length - 1; i >= 0; i--) {
|
|
97
|
+
const name = storage.key(i)
|
|
98
|
+
if (name?.startsWith(prefix)) storage.removeItem(name)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async list() {
|
|
103
|
+
const scope = this._scope(), rows = await this._records(scope), result = []
|
|
104
|
+
for (const [name, row] of rows) {
|
|
105
|
+
const status = await this._status(row)
|
|
106
|
+
if (scope !== this._scope()) throw fail('account_changed', 'the account changed')
|
|
107
|
+
if (status === 'expired') this._drop(name)
|
|
108
|
+
else result.push({ room: row.room, at: row.at, title: row.title || '', status })
|
|
109
|
+
}
|
|
110
|
+
if (scope !== this._scope()) throw fail('account_changed', 'the account changed')
|
|
111
|
+
return result.sort((a, b) => b.at - a.at)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async open(room, options) {
|
|
115
|
+
const scope = this._scope(), name = storagePrefix(scope) + room
|
|
116
|
+
const row = (await this._records(scope, room)).get(name)
|
|
117
|
+
if (!row) throw fail('not_found', 'this device has no such temporary room')
|
|
118
|
+
const status = await this._status(row)
|
|
119
|
+
if (scope !== this._scope()) throw fail('account_changed', 'the account changed')
|
|
120
|
+
if (status === 'expired') { this._drop(name); throw fail('expired', 'this temporary room has expired') }
|
|
121
|
+
return this._wb.openSpace(row.link, options)
|
|
122
|
+
}
|
|
123
|
+
}
|