@tik-choco/mistvault 0.0.0-stage → 0.2.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/LICENSE +373 -0
- package/README.ja.md +126 -0
- package/README.md +183 -2
- package/README.zh.md +126 -0
- package/dist/appState.d.ts +24 -0
- package/dist/appState.js +20 -0
- package/dist/code.d.ts +7 -0
- package/dist/code.js +49 -0
- package/dist/controller.d.ts +55 -0
- package/dist/controller.js +74 -0
- package/dist/core/client.d.ts +112 -0
- package/dist/core/client.js +536 -0
- package/dist/core/crypto.d.ts +24 -0
- package/dist/core/crypto.js +185 -0
- package/dist/core/head.d.ts +54 -0
- package/dist/core/head.js +123 -0
- package/dist/core/parse.d.ts +1 -0
- package/dist/core/parse.js +1 -0
- package/dist/core/protocol.d.ts +74 -0
- package/dist/core/protocol.js +93 -0
- package/dist/i18n.d.ts +132 -0
- package/dist/i18n.js +96 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/parts.d.ts +42 -0
- package/dist/parts.js +267 -0
- package/dist/preact/RoomControls.d.ts +13 -0
- package/dist/preact/RoomControls.js +12 -0
- package/dist/preact/ScopeVaultPanel.d.ts +6 -0
- package/dist/preact/ScopeVaultPanel.js +20 -0
- package/dist/preact/VaultPanel.d.ts +12 -0
- package/dist/preact/VaultPanel.js +111 -0
- package/dist/preact/index.d.ts +5 -0
- package/dist/preact/index.js +3 -0
- package/dist/preact/ui.css +131 -0
- package/dist/preact/useVault.d.ts +6 -0
- package/dist/preact/useVault.js +13 -0
- package/dist/scopeKey.d.ts +1 -0
- package/dist/scopeKey.js +49 -0
- package/dist/scopeManager.d.ts +14 -0
- package/dist/scopeManager.js +110 -0
- package/dist/scopeVault.d.ts +39 -0
- package/dist/scopeVault.js +212 -0
- package/dist/session.d.ts +44 -0
- package/dist/session.js +736 -0
- package/dist/settings.d.ts +21 -0
- package/dist/settings.js +59 -0
- package/dist/stored.d.ts +4 -0
- package/dist/stored.js +27 -0
- package/dist/transport.d.ts +20 -0
- package/dist/transport.js +117 -0
- package/package.json +52 -4
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export const en = {
|
|
2
|
+
title: 'Distributed vault',
|
|
3
|
+
scopeRoomHint: 'Add this room to mistl (Storage → Escrow).', extraRooms: 'Additional mistl rooms', copyAll: 'Copy all rooms', invalidRoom: 'Invalid mistl room.',
|
|
4
|
+
explanation: 'Your data is encrypted in this browser and stored on your mistl node. mistl cannot read it. Keep your vault code secret: anyone with it can read and write your vault.',
|
|
5
|
+
master: 'Enable personal vault', app: 'Back up {app} data', appFallback: 'this app',
|
|
6
|
+
turnOn: 'Turn on the distributed vault', useCode: 'Use a code from another device',
|
|
7
|
+
save: 'Save now', restore: 'Restore now', room: 'mistl room',
|
|
8
|
+
hint: 'Add in mistl: Storage → Distributed vault', roomPending: 'Preparing room…', roomUnavailable: 'Available when backup is on', advanced: 'Advanced',
|
|
9
|
+
mode: 'Mode', auto: 'Automatic', custom: 'Custom', off: 'Off', apply: 'Apply',
|
|
10
|
+
code: 'Vault code', codeHint: 'Keep this code private. Anyone with it can read and write your vault.', reveal: 'Reveal', hide: 'Hide', copy: 'Copy', copied: 'Copied',
|
|
11
|
+
link: 'Copy link for another device', import: 'Import code', importAnother: 'Import another code', importLabel: 'Code from another device',
|
|
12
|
+
pendingTitle: 'Use a code from another device?',
|
|
13
|
+
confirmation: 'Your local data stays on this device. If you already use a vault, this switches it to the new code.',
|
|
14
|
+
confirm: 'Confirm import', cancel: 'Cancel', invalid: 'Invalid vault code or room.', copyError: 'Copy failed. Select and copy the value manually.',
|
|
15
|
+
invalidCode: 'Invalid vault code.', importError: 'Could not import this vault code.',
|
|
16
|
+
savedNow: 'Saved just now', savedAgo: 'Saved {minutes} min ago', savedHoursAgo: 'Saved {hours} hr ago', savedDayAgo: 'Saved 1 day ago', savedDaysAgo: 'Saved {days} days ago',
|
|
17
|
+
parts: 'Attachments: {stored} stored, {pending} pending, {omitted} omitted',
|
|
18
|
+
status_off: 'Vault is off', status_appOff: 'Backup is off for this app', status_searching: 'Searching for mistl…', status_noProvider: 'No provider found; still listening',
|
|
19
|
+
status_restoring: 'Restoring…', status_saving: 'Saving…', status_saved: 'Saved', status_restored: 'Restored',
|
|
20
|
+
status_upToDate: 'Up to date', status_error: 'Vault operation failed',
|
|
21
|
+
};
|
|
22
|
+
export const ja = {
|
|
23
|
+
title: '分散保管庫',
|
|
24
|
+
scopeRoomHint: 'このルームを mistl の「ストレージ → エスクロー」に追加してください。', extraRooms: '追加の mistl ルーム', copyAll: 'すべてのルームをコピー', invalidRoom: 'mistl ルームが無効です。',
|
|
25
|
+
explanation: 'データはこのブラウザーで暗号化され、あなたの mistl ノードに保存されます。mistl は内容を読めません。保管庫コードを知る人は読み書きできるため、秘密にしてください。',
|
|
26
|
+
master: '個人保管庫を有効にする', app: '{app} のデータをバックアップ', appFallback: 'このアプリ',
|
|
27
|
+
turnOn: '分散保管庫を有効にする', useCode: '別の端末のコードを使う',
|
|
28
|
+
save: '今すぐ保存', restore: '今すぐ復元', room: 'mistl ルーム',
|
|
29
|
+
hint: 'mistl の「ストレージ → 分散保管庫」に追加', roomPending: 'ルームを準備中…', roomUnavailable: 'バックアップを有効にすると表示', advanced: '詳細設定',
|
|
30
|
+
mode: 'モード', auto: '自動', custom: 'カスタム', off: '無効', apply: '適用',
|
|
31
|
+
code: '保管庫コード', codeHint: 'このコードは秘密にしてください。知っている人は保管庫を読み書きできます。', reveal: '表示', hide: '隠す', copy: 'コピー', copied: 'コピーしました',
|
|
32
|
+
link: '別の端末用リンクをコピー', import: 'コードを読み込む', importAnother: '別のコードを読み込む', importLabel: '別の端末のコード',
|
|
33
|
+
pendingTitle: '別の端末のコードを使いますか?',
|
|
34
|
+
confirmation: 'ローカルデータはこの端末に残ります。すでに保管庫を使用している場合は、新しいコードに切り替わります。',
|
|
35
|
+
confirm: '読み込みを確認', cancel: 'キャンセル', invalid: '保管庫コードまたはルームが無効です。', copyError: 'コピーできませんでした。値を選択して手動でコピーしてください。',
|
|
36
|
+
invalidCode: '保管庫コードが無効です。', importError: '保管庫コードを読み込めませんでした。',
|
|
37
|
+
savedNow: 'たった今保存', savedAgo: '{minutes} 分前に保存', savedHoursAgo: '{hours} 時間前に保存', savedDayAgo: '1 日前に保存', savedDaysAgo: '{days} 日前に保存',
|
|
38
|
+
parts: '添付ファイル:保存済み {stored}、待機中 {pending}、省略 {omitted}',
|
|
39
|
+
status_off: '保管庫は無効です', status_appOff: 'このアプリのバックアップは無効です', status_searching: 'mistl を検索中…', status_noProvider: 'プロバイダーが見つかりません。引き続き待機中',
|
|
40
|
+
status_restoring: '復元中…', status_saving: '保存中…', status_saved: '保存しました', status_restored: '復元しました',
|
|
41
|
+
status_upToDate: '最新です', status_error: '保管庫の操作に失敗しました',
|
|
42
|
+
};
|
|
43
|
+
export const zhCN = {
|
|
44
|
+
title: '分布式保管库',
|
|
45
|
+
scopeRoomHint: '请将此房间添加到 mistl 的“存储 → 托管”中。', extraRooms: '其他 mistl 房间', copyAll: '复制所有房间', invalidRoom: 'mistl 房间无效。',
|
|
46
|
+
explanation: '数据在此浏览器中加密,并存储在您的 mistl 节点上。mistl 无法读取内容。持有保管库代码的人可以读写数据,请妥善保密。',
|
|
47
|
+
master: '启用个人保管库', app: '备份{app}的数据', appFallback: '此应用',
|
|
48
|
+
turnOn: '启用分布式保管库', useCode: '使用其他设备的代码',
|
|
49
|
+
save: '立即保存', restore: '立即恢复', room: 'mistl 房间',
|
|
50
|
+
hint: '在 mistl 的“存储 → 分布式保管库”中添加', roomPending: '正在准备房间…', roomUnavailable: '启用备份后显示', advanced: '高级设置',
|
|
51
|
+
mode: '模式', auto: '自动', custom: '自定义', off: '关闭', apply: '应用',
|
|
52
|
+
code: '保管库代码', codeHint: '请妥善保密此代码。持有者可以读写您的保管库。', reveal: '显示', hide: '隐藏', copy: '复制', copied: '已复制',
|
|
53
|
+
link: '复制其他设备的链接', import: '导入代码', importAnother: '导入其他代码', importLabel: '其他设备的代码',
|
|
54
|
+
pendingTitle: '使用其他设备的代码?',
|
|
55
|
+
confirmation: '本地数据会保留在此设备上。如果您已使用保管库,此操作会切换到新代码。',
|
|
56
|
+
confirm: '确认导入', cancel: '取消', invalid: '保管库代码或房间无效。', copyError: '复制失败。请选中该值并手动复制。',
|
|
57
|
+
invalidCode: '保管库代码无效。', importError: '无法导入此保管库代码。',
|
|
58
|
+
savedNow: '刚刚保存', savedAgo: '{minutes} 分钟前保存', savedHoursAgo: '{hours} 小时前保存', savedDayAgo: '1 天前保存', savedDaysAgo: '{days} 天前保存',
|
|
59
|
+
parts: '附件:已存储 {stored},待处理 {pending},已省略 {omitted}',
|
|
60
|
+
status_off: '保管库已关闭', status_appOff: '此应用的备份已关闭', status_searching: '正在查找 mistl…', status_noProvider: '未找到提供者,继续等待',
|
|
61
|
+
status_restoring: '正在恢复…', status_saving: '正在保存…', status_saved: '已保存', status_restored: '已恢复',
|
|
62
|
+
status_upToDate: '已是最新', status_error: '保管库操作失败',
|
|
63
|
+
};
|
|
64
|
+
export const zhTW = {
|
|
65
|
+
title: '分散式保管庫',
|
|
66
|
+
scopeRoomHint: '請將此房間新增至 mistl 的「儲存空間 → 託管」。', extraRooms: '其他 mistl 房間', copyAll: '複製所有房間', invalidRoom: 'mistl 房間無效。',
|
|
67
|
+
explanation: '資料在此瀏覽器中加密,並儲存在您的 mistl 節點上。mistl 無法讀取內容。持有保管庫代碼的人可以讀寫資料,請妥善保密。',
|
|
68
|
+
master: '啟用個人保管庫', app: '備份{app}的資料', appFallback: '此應用程式',
|
|
69
|
+
turnOn: '啟用分散式保管庫', useCode: '使用其他裝置的代碼',
|
|
70
|
+
save: '立即儲存', restore: '立即還原', room: 'mistl 房間',
|
|
71
|
+
hint: '在 mistl 的「儲存空間 → 分散式保管庫」中新增', roomPending: '正在準備房間…', roomUnavailable: '啟用備份後顯示', advanced: '進階設定',
|
|
72
|
+
mode: '模式', auto: '自動', custom: '自訂', off: '關閉', apply: '套用',
|
|
73
|
+
code: '保管庫代碼', codeHint: '請妥善保密此代碼。持有者可以讀寫您的保管庫。', reveal: '顯示', hide: '隱藏', copy: '複製', copied: '已複製',
|
|
74
|
+
link: '複製其他裝置的連結', import: '匯入代碼', importAnother: '匯入其他代碼', importLabel: '其他裝置的代碼',
|
|
75
|
+
pendingTitle: '使用其他裝置的代碼?',
|
|
76
|
+
confirmation: '本機資料會保留在此裝置上。如果您已使用保管庫,此操作會切換到新代碼。',
|
|
77
|
+
confirm: '確認匯入', cancel: '取消', invalid: '保管庫代碼或房間無效。', copyError: '複製失敗。請選取該值並手動複製。',
|
|
78
|
+
invalidCode: '保管庫代碼無效。', importError: '無法匯入此保管庫代碼。',
|
|
79
|
+
savedNow: '剛剛儲存', savedAgo: '{minutes} 分鐘前儲存', savedHoursAgo: '{hours} 小時前儲存', savedDayAgo: '1 天前儲存', savedDaysAgo: '{days} 天前儲存',
|
|
80
|
+
parts: '附件:已儲存 {stored},待處理 {pending},已省略 {omitted}',
|
|
81
|
+
status_off: '保管庫已關閉', status_appOff: '此應用程式的備份已關閉', status_searching: '正在尋找 mistl…', status_noProvider: '未找到提供者,繼續等待',
|
|
82
|
+
status_restoring: '正在還原…', status_saving: '正在儲存…', status_saved: '已儲存', status_restored: '已還原',
|
|
83
|
+
status_upToDate: '已是最新', status_error: '保管庫操作失敗',
|
|
84
|
+
};
|
|
85
|
+
export const messages = { en, ja, 'zh-CN': zhCN, 'zh-TW': zhTW };
|
|
86
|
+
export function resolveLocale(locale = globalThis.navigator?.language ?? 'en') {
|
|
87
|
+
const language = locale.toLowerCase();
|
|
88
|
+
if (language.startsWith('ja'))
|
|
89
|
+
return 'ja';
|
|
90
|
+
if (language.startsWith('zh'))
|
|
91
|
+
return /(?:tw|hk|mo|hant)/.test(language) ? 'zh-TW' : 'zh-CN';
|
|
92
|
+
return 'en';
|
|
93
|
+
}
|
|
94
|
+
export function vaultMessage(locale, key, values = {}) {
|
|
95
|
+
return (messages[resolveLocale(locale)][key] ?? en[key]).replace(/\{(\w+)\}/g, (match, name) => String(values[name] ?? match));
|
|
96
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './core/crypto.js';
|
|
2
|
+
export * from './core/head.js';
|
|
3
|
+
export * from './core/protocol.js';
|
|
4
|
+
export * from './core/client.js';
|
|
5
|
+
export * from './code.js';
|
|
6
|
+
export * from './settings.js';
|
|
7
|
+
export * from './transport.js';
|
|
8
|
+
export * from './controller.js';
|
|
9
|
+
export { createScopeVault, defaultScopeConfig, scopeInviteParam, parseScopeInviteParam } from './scopeVault.js';
|
|
10
|
+
export type { ScopeConfig, ScopeVaultOptions, ScopeVaultView, ScopeVault } from './scopeVault.js';
|
|
11
|
+
export * from './scopeManager.js';
|
|
12
|
+
export * from './parts.js';
|
|
13
|
+
export * from './i18n.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './core/crypto.js';
|
|
2
|
+
export * from './core/head.js';
|
|
3
|
+
export * from './core/protocol.js';
|
|
4
|
+
export * from './core/client.js';
|
|
5
|
+
export * from './code.js';
|
|
6
|
+
export * from './settings.js';
|
|
7
|
+
export * from './transport.js';
|
|
8
|
+
export * from './controller.js';
|
|
9
|
+
export { createScopeVault, defaultScopeConfig, scopeInviteParam, parseScopeInviteParam } from './scopeVault.js';
|
|
10
|
+
export * from './scopeManager.js';
|
|
11
|
+
export * from './parts.js';
|
|
12
|
+
export * from './i18n.js';
|
package/dist/parts.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { EscrowHead } from './core/head.js';
|
|
2
|
+
import type { EscrowClient } from './core/client.js';
|
|
3
|
+
import type { VaultAppState } from './settings.js';
|
|
4
|
+
export interface VaultParts<S> {
|
|
5
|
+
list(state: S): {
|
|
6
|
+
id: string;
|
|
7
|
+
size: number;
|
|
8
|
+
}[];
|
|
9
|
+
read(id: string): Promise<Uint8Array | null>;
|
|
10
|
+
has(id: string): Promise<boolean>;
|
|
11
|
+
write(id: string, bytes: Uint8Array): Promise<void>;
|
|
12
|
+
maxBytes?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const DEFAULT_MAX_PART_BYTES: number;
|
|
15
|
+
export declare const DEFAULT_PART_GC_GRACE_MS: number;
|
|
16
|
+
export declare const PART_SCHEMA = "tc-vault/part/1";
|
|
17
|
+
/** Runs at most two attachment operations at a time. */
|
|
18
|
+
export declare function mapParts<T>(items: readonly T[], work: (item: T) => Promise<void>): Promise<void>;
|
|
19
|
+
export declare function listedParts<S>(adapter: VaultParts<S>, state: S): {
|
|
20
|
+
id: string;
|
|
21
|
+
size: number;
|
|
22
|
+
}[];
|
|
23
|
+
export interface PartContext<S> {
|
|
24
|
+
adapter: VaultParts<S>;
|
|
25
|
+
app: string;
|
|
26
|
+
code: string;
|
|
27
|
+
client: EscrowClient;
|
|
28
|
+
state: VaultAppState;
|
|
29
|
+
active(): boolean;
|
|
30
|
+
persist(): void;
|
|
31
|
+
collecting?: Set<string>;
|
|
32
|
+
canUpload?(): boolean;
|
|
33
|
+
canCollect?(): boolean;
|
|
34
|
+
now?(): number;
|
|
35
|
+
partGcGraceMs?: number;
|
|
36
|
+
}
|
|
37
|
+
/** Record references only from an acknowledged or observed current main snapshot. */
|
|
38
|
+
export declare function observePartReferences<S>(ctx: PartContext<S>, snapshot: S, main: EscrowHead): boolean;
|
|
39
|
+
export declare function uploadParts<S>(ctx: PartContext<S>, snapshot: S): Promise<void>;
|
|
40
|
+
export declare function fetchParts<S>(ctx: PartContext<S>, snapshot: S): Promise<number>;
|
|
41
|
+
/** Validate the exact part generation, then re-check the main head immediately before deletion. */
|
|
42
|
+
export declare function collectParts<S>(ctx: PartContext<S>, snapshot: S, main: EscrowHead): Promise<void>;
|
package/dist/parts.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { derivePartKeys, PART_ID_RE, sha256 } from './core/crypto.js';
|
|
2
|
+
import { DEFAULT_MAX_BLOB, headHash, verifyHead } from './core/head.js';
|
|
3
|
+
import { EscrowRequestError } from './core/client.js';
|
|
4
|
+
export const DEFAULT_MAX_PART_BYTES = DEFAULT_MAX_BLOB - 64 * 1024;
|
|
5
|
+
export const DEFAULT_PART_GC_GRACE_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
export const PART_SCHEMA = 'tc-vault/part/1';
|
|
7
|
+
/** Runs at most two attachment operations at a time. */
|
|
8
|
+
export async function mapParts(items, work) {
|
|
9
|
+
let index = 0;
|
|
10
|
+
const run = async () => { while (index < items.length)
|
|
11
|
+
await work(items[index++]); };
|
|
12
|
+
const outcomes = await Promise.allSettled([run(), run()]);
|
|
13
|
+
const failed = outcomes.find(result => result.status === 'rejected');
|
|
14
|
+
if (failed?.status === 'rejected')
|
|
15
|
+
throw failed.reason;
|
|
16
|
+
}
|
|
17
|
+
export function listedParts(adapter, state) {
|
|
18
|
+
const parts = adapter.list(state), ids = new Set();
|
|
19
|
+
for (const p of parts) {
|
|
20
|
+
if (typeof p.id !== 'string' || !PART_ID_RE.test(p.id) || !Number.isSafeInteger(p.size) || p.size < 0 || ids.has(p.id))
|
|
21
|
+
throw new Error('Invalid vault part list');
|
|
22
|
+
ids.add(p.id);
|
|
23
|
+
}
|
|
24
|
+
return parts;
|
|
25
|
+
}
|
|
26
|
+
/** Record references only from an acknowledged or observed current main snapshot. */
|
|
27
|
+
export function observePartReferences(ctx, snapshot, main) {
|
|
28
|
+
if (!ctx.active() || main.seq < (ctx.state.partsObservedSeq ?? 0))
|
|
29
|
+
return false;
|
|
30
|
+
const keep = new Set(listedParts(ctx.adapter, snapshot).map(p => p.id)), now = (ctx.now ?? Date.now)();
|
|
31
|
+
let changed = ctx.state.partsObservedSeq !== main.seq;
|
|
32
|
+
ctx.state.partsObservedSeq = main.seq;
|
|
33
|
+
for (const inventory of [ctx.state.parts, ctx.state.pendingDeletes]) {
|
|
34
|
+
for (const [id, entry] of Object.entries(inventory ?? {})) {
|
|
35
|
+
if (keep.has(id)) {
|
|
36
|
+
if (entry.unreferencedSince !== undefined) {
|
|
37
|
+
const { unreferencedSince: _, ...referenced } = entry;
|
|
38
|
+
inventory[id] = referenced;
|
|
39
|
+
changed = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else if (entry.unreferencedSince === undefined) {
|
|
43
|
+
inventory[id] = { ...entry, unreferencedSince: now };
|
|
44
|
+
changed = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (changed)
|
|
49
|
+
ctx.persist();
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
function invalidatePart(ctx, id) {
|
|
53
|
+
if (ctx.state.parts[id]) {
|
|
54
|
+
delete ctx.state.parts[id];
|
|
55
|
+
ctx.persist();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export async function uploadParts(ctx, snapshot) {
|
|
59
|
+
await uploadListedParts(ctx, listedParts(ctx.adapter, snapshot));
|
|
60
|
+
}
|
|
61
|
+
async function uploadListedParts(ctx, parts, recordOmissions = true) {
|
|
62
|
+
const { adapter, client, app, code, state } = ctx;
|
|
63
|
+
const omitted = new Set();
|
|
64
|
+
await mapParts(parts, async ({ id, size }) => {
|
|
65
|
+
if (!ctx.active() || ctx.canUpload?.() === false)
|
|
66
|
+
return;
|
|
67
|
+
const max = adapter.maxBytes ?? DEFAULT_MAX_PART_BYTES;
|
|
68
|
+
if (size > max) {
|
|
69
|
+
omitted.add(id);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const bytes = await adapter.read(id);
|
|
73
|
+
if (!ctx.active())
|
|
74
|
+
return;
|
|
75
|
+
if (!bytes || bytes.byteLength > max) {
|
|
76
|
+
omitted.add(id);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const hash = await sha256(bytes);
|
|
80
|
+
if (!ctx.active())
|
|
81
|
+
return;
|
|
82
|
+
const keys = await derivePartKeys(app, code, id);
|
|
83
|
+
for (let attempt = 0; attempt < 3 && ctx.active(); attempt++) {
|
|
84
|
+
const head = await client.getHead(keys.slot);
|
|
85
|
+
if (!ctx.active())
|
|
86
|
+
return;
|
|
87
|
+
if (head && !await verifyHead(head, { slot: keys.slot, writer: keys.writer }))
|
|
88
|
+
throw new Error('Invalid part head');
|
|
89
|
+
if (!head)
|
|
90
|
+
invalidatePart(ctx, id);
|
|
91
|
+
const tracked = state.parts[id];
|
|
92
|
+
if (head && tracked?.hash === hash && tracked.seq === head.seq && !ctx.collecting?.has(id)) {
|
|
93
|
+
const generation = await headHash(head);
|
|
94
|
+
if (tracked.headHash === generation)
|
|
95
|
+
return;
|
|
96
|
+
if (!tracked.headHash) {
|
|
97
|
+
const latest = await client.fetchLatestWithKeys(keys);
|
|
98
|
+
if (!ctx.active())
|
|
99
|
+
return;
|
|
100
|
+
if (latest && await headHash(latest.head) === generation && await sha256(latest.plaintext) === hash) {
|
|
101
|
+
state.parts = { ...state.parts, [id]: { ...tracked, headHash: generation } };
|
|
102
|
+
ctx.persist();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const parent = head ? await headHash(head) : null;
|
|
108
|
+
if (!ctx.active() || ctx.canUpload?.() === false)
|
|
109
|
+
return;
|
|
110
|
+
const result = await client.saveWithKeys(keys, bytes, { schema: PART_SCHEMA, comp: 'none',
|
|
111
|
+
seq: (head?.seq ?? 0) + 1, parent });
|
|
112
|
+
if (!ctx.active())
|
|
113
|
+
return;
|
|
114
|
+
if (result.type === 'ack') {
|
|
115
|
+
state.parts = { ...state.parts, [id]: { seq: result.seq, hash, headHash: result.hash } };
|
|
116
|
+
delete state.pendingDeletes?.[id];
|
|
117
|
+
ctx.persist();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (result.type === 'error') {
|
|
121
|
+
if (result.code === 'deleted')
|
|
122
|
+
invalidatePart(ctx, id);
|
|
123
|
+
if (result.code === 'quota' || result.code === 'too_large') {
|
|
124
|
+
omitted.add(id);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// Deleted slots retain their sequence and parent on supporting providers.
|
|
128
|
+
if (result.code === 'deleted' && result.head) {
|
|
129
|
+
const deletedParent = await headHash(result.head);
|
|
130
|
+
if (!ctx.active() || ctx.canUpload?.() === false)
|
|
131
|
+
return;
|
|
132
|
+
const retry = await client.saveWithKeys(keys, bytes, { schema: PART_SCHEMA, comp: 'none', seq: result.head.seq + 1, parent: deletedParent });
|
|
133
|
+
if (!ctx.active())
|
|
134
|
+
return;
|
|
135
|
+
if (retry.type === 'error' && retry.code === 'not_writer')
|
|
136
|
+
throw new EscrowRequestError(retry.code, retry.message);
|
|
137
|
+
if (retry.type === 'ack') {
|
|
138
|
+
state.parts = { ...state.parts, [id]: { seq: retry.seq, hash, headHash: retry.hash } };
|
|
139
|
+
delete state.pendingDeletes?.[id];
|
|
140
|
+
ctx.persist();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
throw new EscrowRequestError(result.code, result.code + ': ' + result.message);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (ctx.active())
|
|
148
|
+
throw new Error('Part conflict retry limit reached');
|
|
149
|
+
});
|
|
150
|
+
if (ctx.active() && ctx.canUpload?.() !== false && recordOmissions) {
|
|
151
|
+
state.omitted = [...omitted].sort();
|
|
152
|
+
ctx.persist();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export async function fetchParts(ctx, snapshot) {
|
|
156
|
+
let pending = 0;
|
|
157
|
+
await mapParts(listedParts(ctx.adapter, snapshot), async (part) => {
|
|
158
|
+
const { id } = part;
|
|
159
|
+
if (!ctx.active())
|
|
160
|
+
return;
|
|
161
|
+
const keys = await derivePartKeys(ctx.app, ctx.code, id);
|
|
162
|
+
if (!ctx.active())
|
|
163
|
+
return;
|
|
164
|
+
try {
|
|
165
|
+
const head = await ctx.client.getHead(keys.slot);
|
|
166
|
+
if (!ctx.active())
|
|
167
|
+
return;
|
|
168
|
+
if (head && !await verifyHead(head, { slot: keys.slot, writer: keys.writer }))
|
|
169
|
+
throw new Error('Invalid part head');
|
|
170
|
+
if (!head) {
|
|
171
|
+
invalidatePart(ctx, id);
|
|
172
|
+
// Local bytes can repair a deletion even when has() still reports a local copy.
|
|
173
|
+
await uploadListedParts(ctx, [part], false);
|
|
174
|
+
if (ctx.active() && !ctx.state.parts[id])
|
|
175
|
+
pending++;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (await ctx.adapter.has(id))
|
|
179
|
+
return;
|
|
180
|
+
const latest = await ctx.client.fetchLatestWithKeys(keys);
|
|
181
|
+
if (!ctx.active())
|
|
182
|
+
return;
|
|
183
|
+
if (!latest) {
|
|
184
|
+
invalidatePart(ctx, id);
|
|
185
|
+
await uploadListedParts(ctx, [part], false);
|
|
186
|
+
if (ctx.active() && !ctx.state.parts[id])
|
|
187
|
+
pending++;
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (latest.head.schema !== PART_SCHEMA)
|
|
191
|
+
throw new Error('Unsupported part schema');
|
|
192
|
+
await ctx.adapter.write(id, latest.plaintext);
|
|
193
|
+
const hash = await sha256(latest.plaintext);
|
|
194
|
+
const generation = await headHash(latest.head);
|
|
195
|
+
if (ctx.active()) {
|
|
196
|
+
ctx.state.parts = { ...ctx.state.parts, [id]: { seq: latest.head.seq, hash, headHash: generation } };
|
|
197
|
+
ctx.persist();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// Keep unavailable bytes pending; later restores retry without writing a placeholder.
|
|
202
|
+
if (ctx.active())
|
|
203
|
+
pending++;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
return pending;
|
|
207
|
+
}
|
|
208
|
+
/** Validate the exact part generation, then re-check the main head immediately before deletion. */
|
|
209
|
+
export async function collectParts(ctx, snapshot, main) {
|
|
210
|
+
const keep = new Set(listedParts(ctx.adapter, snapshot).map(p => p.id)), expected = await headHash(main);
|
|
211
|
+
const observed = await ctx.client.getHead(main.slot);
|
|
212
|
+
if (!ctx.active() || !observed || await headHash(observed) !== expected || ctx.canCollect && !ctx.canCollect())
|
|
213
|
+
return;
|
|
214
|
+
if (!observePartReferences(ctx, snapshot, main))
|
|
215
|
+
return;
|
|
216
|
+
for (const id of new Set([...Object.keys(ctx.state.parts), ...Object.keys(ctx.state.pendingDeletes ?? {})])) {
|
|
217
|
+
if (!ctx.active() || keep.has(id))
|
|
218
|
+
continue;
|
|
219
|
+
if (ctx.canCollect && !ctx.canCollect())
|
|
220
|
+
return;
|
|
221
|
+
const entry = ctx.state.parts[id] ?? ctx.state.pendingDeletes?.[id];
|
|
222
|
+
if (!entry)
|
|
223
|
+
continue;
|
|
224
|
+
if (entry.unreferencedSince === undefined ||
|
|
225
|
+
(ctx.now ?? Date.now)() - entry.unreferencedSince < (ctx.partGcGraceMs ?? DEFAULT_PART_GC_GRACE_MS))
|
|
226
|
+
continue;
|
|
227
|
+
ctx.collecting?.add(id);
|
|
228
|
+
try {
|
|
229
|
+
const keys = await derivePartKeys(ctx.app, ctx.code, id), head = await ctx.client.getHead(keys.slot);
|
|
230
|
+
if (!ctx.active() || ctx.canCollect && !ctx.canCollect())
|
|
231
|
+
return;
|
|
232
|
+
if (head) {
|
|
233
|
+
if (head.seq !== entry.seq || !await verifyHead(head, { slot: keys.slot, writer: keys.writer }))
|
|
234
|
+
continue;
|
|
235
|
+
if (entry.headHash) {
|
|
236
|
+
if (await headHash(head) !== entry.headHash)
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// Older inventories recorded only a plaintext hash.
|
|
241
|
+
const latest = await ctx.client.fetchLatestWithKeys(keys);
|
|
242
|
+
if (!latest || await headHash(latest.head) !== await headHash(head) || await sha256(latest.plaintext) !== entry.hash)
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const current = await ctx.client.getHead(main.slot);
|
|
247
|
+
// Only the acknowledged, parsed snapshot is trusted to describe references.
|
|
248
|
+
// A different head defers collection until its references have been observed.
|
|
249
|
+
if (!ctx.active() || !current || await headHash(current) !== expected ||
|
|
250
|
+
ctx.canCollect && !ctx.canCollect() || (ctx.state.parts[id] ?? ctx.state.pendingDeletes?.[id]) !== entry)
|
|
251
|
+
return;
|
|
252
|
+
ctx.state.pendingDeletes = { ...ctx.state.pendingDeletes, [id]: entry };
|
|
253
|
+
delete ctx.state.parts[id];
|
|
254
|
+
ctx.persist();
|
|
255
|
+
if (!head || (await ctx.client.deleteWithKeys(keys, head)).type === 'deleted') {
|
|
256
|
+
if (ctx.active() && ctx.state.pendingDeletes?.[id] === entry) {
|
|
257
|
+
delete ctx.state.pendingDeletes[id];
|
|
258
|
+
ctx.persist();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
catch { /* Retry uncertain deletions without trusting the uploaded inventory. */ }
|
|
263
|
+
finally {
|
|
264
|
+
ctx.collecting?.delete(id);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { VaultMode } from '../settings.js';
|
|
2
|
+
interface RoomControlsProps {
|
|
3
|
+
locale?: string;
|
|
4
|
+
mode: VaultMode;
|
|
5
|
+
room: string;
|
|
6
|
+
controller: {
|
|
7
|
+
configure(mode: VaultMode, room: string): boolean;
|
|
8
|
+
};
|
|
9
|
+
disableUnchanged?: boolean;
|
|
10
|
+
onInvalid(): void;
|
|
11
|
+
}
|
|
12
|
+
export declare function RoomControls(props: RoomControlsProps): import("preact").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
+
import { useLayoutEffect, useState } from 'preact/hooks';
|
|
3
|
+
import { vaultMessage } from '../i18n.js';
|
|
4
|
+
import { validVaultRoom } from '../settings.js';
|
|
5
|
+
export function RoomControls(props) {
|
|
6
|
+
const [mode, setMode] = useState(props.mode), [room, setRoom] = useState(props.room);
|
|
7
|
+
useLayoutEffect(() => { setMode(props.mode); setRoom(props.room); }, [props.mode, props.room, props.controller]);
|
|
8
|
+
const t = (key) => vaultMessage(props.locale, key);
|
|
9
|
+
return _jsxs(_Fragment, { children: [_jsxs("label", { children: [t('mode'), _jsxs("select", { value: mode, onChange: e => setMode(e.currentTarget.value), children: [_jsx("option", { value: "auto", children: t('auto') }), _jsx("option", { value: "custom", children: t('custom') }), _jsx("option", { value: "off", children: t('off') })] })] }), mode === 'custom' && _jsxs("label", { children: [t('room'), _jsx("input", { value: room, maxLength: 96, "aria-invalid": !validVaultRoom(room), onInput: e => setRoom(e.currentTarget.value) })] }), _jsx("button", { type: "button", disabled: mode === 'custom' && !validVaultRoom(room) ||
|
|
10
|
+
props.disableUnchanged && mode === props.mode && (mode !== 'custom' || room === props.room), onClick: () => { if (!props.controller.configure(mode, room))
|
|
11
|
+
props.onInvalid(); }, children: t('apply') })] });
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useState } from 'preact/hooks';
|
|
3
|
+
import { vaultMessage } from '../i18n.js';
|
|
4
|
+
import { RoomControls } from './RoomControls.js';
|
|
5
|
+
import { useVaultView } from './useVault.js';
|
|
6
|
+
export function ScopeVaultPanel({ vault, locale }) {
|
|
7
|
+
const view = useVaultView(vault), [notice, setNotice] = useState('');
|
|
8
|
+
const t = (key) => vaultMessage(locale, key);
|
|
9
|
+
const busy = view.mode === 'off' || view.status === 'saving' || view.status === 'restoring';
|
|
10
|
+
async function copyRoom() {
|
|
11
|
+
try {
|
|
12
|
+
await navigator.clipboard.writeText(view.room);
|
|
13
|
+
setNotice(t('copied'));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
setNotice(t('copyError'));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return _jsxs("section", { class: "mv-panel mv-stack", "aria-label": t('title'), children: [_jsx("h2", { children: t('title') }), _jsxs("div", { class: "mv-status-card", children: [_jsxs("div", { class: "mv-status-text", role: "status", "data-state": view.status, children: [_jsx("strong", { children: t(`status_${view.status}`) }), view.error && _jsx("span", { class: "mv-error", children: view.error })] }), _jsxs("div", { class: "mv-actions", children: [_jsx("button", { type: "button", disabled: busy, onClick: () => { void vault.saveNow(); }, children: t('save') }), _jsx("button", { type: "button", disabled: busy, onClick: () => { void vault.restoreNow(); }, children: t('restore') })] })] }), _jsx("div", { class: "mv-stack", children: _jsx(RoomControls, { locale: locale, mode: view.mode, room: view.config.room, controller: vault, disableUnchanged: !!view.config.by, onInvalid: () => setNotice(t('invalidRoom')) }) }), view.mode !== 'off' && _jsxs("div", { class: "mv-room", children: [_jsxs("div", { class: "mv-room-row", children: [_jsxs("label", { children: [t('room'), _jsx("input", { readOnly: true, value: view.room, placeholder: t('roomPending'), onFocus: e => e.currentTarget.select() })] }), _jsx("button", { type: "button", disabled: !view.room, onClick: () => { void copyRoom(); }, children: t('copy') })] }), _jsx("p", { class: "mv-muted mv-hint", children: t('scopeRoomHint') })] }), notice && _jsx("p", { class: "mv-notice", role: "status", children: notice })] });
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { VaultController } from '../controller.js';
|
|
2
|
+
export interface VaultPanelProps {
|
|
3
|
+
controller: VaultController;
|
|
4
|
+
locale?: string;
|
|
5
|
+
appName?: string;
|
|
6
|
+
extraRooms?: string[];
|
|
7
|
+
/** A device-link code consumed by the application before the panel was mounted. */
|
|
8
|
+
pendingCode?: string | null;
|
|
9
|
+
/** Called after a supplied pending code is imported or dismissed. Clear pendingCode in the caller. */
|
|
10
|
+
onPendingHandled?: (result: 'imported' | 'cancelled') => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function VaultPanel({ controller, locale, appName, pendingCode, onPendingHandled, extraRooms }: VaultPanelProps): import("preact").JSX.Element;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
+
import { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';
|
|
3
|
+
import { RoomControls } from './RoomControls.js';
|
|
4
|
+
import { consumeVaultLink, parseVaultCode, vaultLink } from '../code.js';
|
|
5
|
+
import { vaultMessage } from '../i18n.js';
|
|
6
|
+
import { useVault } from './useVault.js';
|
|
7
|
+
export function VaultPanel({ controller, locale, appName, pendingCode, onPendingHandled, extraRooms }) {
|
|
8
|
+
const view = useVault(controller);
|
|
9
|
+
const t = (key, values) => vaultMessage(locale, key, values);
|
|
10
|
+
const additional = [...new Set(extraRooms)].filter(room => room && room !== view.room);
|
|
11
|
+
const [visible, setVisible] = useState(false), [input, setInput] = useState('');
|
|
12
|
+
const [importing, setImporting] = useState(false), [inputError, setInputError] = useState('');
|
|
13
|
+
const [propPending, setPropPending] = useState(pendingCode || null);
|
|
14
|
+
const [localPending, setLocalPending] = useState(() => {
|
|
15
|
+
try {
|
|
16
|
+
return typeof window === 'undefined' ? null : consumeVaultLink();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const [confirmError, setConfirmError] = useState('');
|
|
23
|
+
const [notice, setNotice] = useState(''), [time, setTime] = useState(Date.now());
|
|
24
|
+
const confirmRef = useRef(null), importRef = useRef(null);
|
|
25
|
+
const importButtonRef = useRef(null), titleRef = useRef(null);
|
|
26
|
+
const pending = propPending ?? localPending;
|
|
27
|
+
const parsedPending = pending === null ? null : parseVaultCode(pending);
|
|
28
|
+
useLayoutEffect(() => { setPropPending(pendingCode || null); }, [pendingCode]);
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
setConfirmError('');
|
|
31
|
+
if (pending !== null)
|
|
32
|
+
confirmRef.current?.focus();
|
|
33
|
+
}, [pending]);
|
|
34
|
+
useLayoutEffect(() => { if (importing)
|
|
35
|
+
importRef.current?.focus(); }, [importing]);
|
|
36
|
+
useLayoutEffect(() => { setVisible(false); }, [view.mode, view.room, controller]);
|
|
37
|
+
useLayoutEffect(() => { setImporting(false); setInput(''); setInputError(''); setNotice(''); }, [view.mode, controller]);
|
|
38
|
+
useEffect(() => { const timer = setInterval(() => setTime(Date.now()), 60000); return () => clearInterval(timer); }, []);
|
|
39
|
+
const copy = async (value) => {
|
|
40
|
+
try {
|
|
41
|
+
await navigator.clipboard.writeText(value);
|
|
42
|
+
setNotice(t('copied'));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
setNotice(t('copyError'));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const closeImport = () => {
|
|
49
|
+
setImporting(false);
|
|
50
|
+
setInput('');
|
|
51
|
+
setInputError('');
|
|
52
|
+
importButtonRef.current?.focus();
|
|
53
|
+
};
|
|
54
|
+
const prepareImport = () => {
|
|
55
|
+
const code = parseVaultCode(input);
|
|
56
|
+
if (!code) {
|
|
57
|
+
setInputError(t('invalidCode'));
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
setInputError('');
|
|
61
|
+
setNotice('');
|
|
62
|
+
setLocalPending(code);
|
|
63
|
+
};
|
|
64
|
+
const finishPending = (result) => {
|
|
65
|
+
if (propPending !== null) {
|
|
66
|
+
setPropPending(null);
|
|
67
|
+
onPendingHandled?.(result);
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
setLocalPending(null);
|
|
71
|
+
setInput('');
|
|
72
|
+
setInputError('');
|
|
73
|
+
setImporting(false);
|
|
74
|
+
setVisible(false);
|
|
75
|
+
setConfirmError('');
|
|
76
|
+
requestAnimationFrame(() => {
|
|
77
|
+
if (confirmRef.current)
|
|
78
|
+
return;
|
|
79
|
+
const button = importButtonRef.current;
|
|
80
|
+
if (button?.isConnected && !button.closest('details:not([open])'))
|
|
81
|
+
button.focus();
|
|
82
|
+
else
|
|
83
|
+
titleRef.current?.focus();
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const confirmImport = () => {
|
|
87
|
+
if (!parsedPending || !controller.importCode(parsedPending)) {
|
|
88
|
+
setConfirmError(t('importError'));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (view.mode === 'off')
|
|
92
|
+
controller.enable();
|
|
93
|
+
finishPending('imported');
|
|
94
|
+
};
|
|
95
|
+
const importForm = importing && _jsxs("div", { class: "mv-import", children: [_jsxs("label", { children: [t('importLabel'), _jsx("input", { ref: importRef, type: "password", value: input, autoComplete: "off", "aria-invalid": !!inputError, onInput: e => { setInput(e.currentTarget.value); setInputError(''); }, onKeyDown: e => { if (e.key === 'Enter') {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
prepareImport();
|
|
98
|
+
}
|
|
99
|
+
else if (e.key === 'Escape')
|
|
100
|
+
closeImport(); } })] }), inputError && _jsx("p", { class: "mv-error", role: "alert", children: inputError }), _jsxs("div", { class: "mv-actions", children: [_jsx("button", { type: "button", class: "mv-primary", onClick: prepareImport, children: t('import') }), _jsx("button", { type: "button", onClick: closeImport, children: t('cancel') })] })] });
|
|
101
|
+
const busy = view.status === 'saving' || view.status === 'restoring';
|
|
102
|
+
const enabled = view.appEnabled && view.hasCode;
|
|
103
|
+
const minutes = Math.max(0, Math.floor((Math.max(time, Date.now()) - view.savedAt) / 60000));
|
|
104
|
+
const savedTime = minutes < 1 ? t('savedNow') : minutes < 60 ? t('savedAgo', { minutes }) :
|
|
105
|
+
minutes < 1440 ? t('savedHoursAgo', { hours: Math.floor(minutes / 60) }) :
|
|
106
|
+
minutes < 2880 ? t('savedDayAgo') : t('savedDaysAgo', { days: Math.floor(minutes / 1440) });
|
|
107
|
+
return _jsxs("section", { class: "mv-panel", "aria-label": t('title'), children: [pending !== null && _jsxs("div", { ref: confirmRef, class: "mv-confirm", role: "group", "aria-label": t('pendingTitle') + ' ' + t(parsedPending ? 'confirmation' : 'invalidCode'), tabIndex: -1, children: [_jsx("h3", { children: t('pendingTitle') }), _jsx("p", { children: parsedPending ? t('confirmation') : t('invalidCode') }), confirmError && _jsx("p", { class: "mv-error", role: "alert", children: confirmError }), _jsxs("div", { class: "mv-actions", children: [parsedPending && _jsx("button", { type: "button", class: "mv-primary", onClick: confirmImport, children: t('confirm') }), _jsx("button", { type: "button", onClick: () => finishPending('cancelled'), children: t('cancel') })] })] }), _jsx("h2", { ref: titleRef, tabIndex: -1, children: t('title') }), view.mode === 'off' ? _jsxs("div", { class: "mv-welcome", children: [_jsx("p", { class: "mv-muted", children: t('explanation') }), _jsxs("div", { class: "mv-stack", children: [_jsx("button", { type: "button", class: "mv-primary", onClick: () => controller.enable(), children: t('turnOn') }), _jsx("button", { ref: importButtonRef, type: "button", "aria-expanded": importing, onClick: () => importing ? closeImport() : setImporting(true), children: t('useCode') })] }), importForm] }) : _jsxs(_Fragment, { children: [_jsxs("div", { class: "mv-status-card", children: [_jsxs("div", { class: "mv-status-text", role: "status", "aria-live": "polite", "data-state": !view.appEnabled ? 'off' : view.status, children: [_jsx("strong", { children: !view.appEnabled && view.status === 'off' ? t('status_appOff') : t(`status_${view.status}`) }), view.savedAt > 0 && _jsxs("span", { class: "mv-muted", children: [' ', savedTime] }), view.error && _jsxs("span", { class: "mv-error", children: [' ', view.error] })] }), _jsxs("div", { class: "mv-actions", children: [_jsx("button", { type: "button", disabled: !enabled || busy, onClick: () => { void controller.saveNow(); }, children: t('save') }), _jsx("button", { type: "button", disabled: !enabled || busy, onClick: () => { void controller.restoreNow(); }, children: t('restore') })] })] }), _jsxs("label", { class: "mv-switch", children: [_jsx("span", { children: t('app', { app: appName || t('appFallback') }) }), _jsx("input", { type: "checkbox", role: "switch", checked: view.appEnabled, onChange: e => controller.setAppEnabled(e.currentTarget.checked) })] }), _jsxs("div", { class: "mv-room", children: [_jsxs("div", { class: "mv-room-row", children: [_jsxs("label", { children: [t('room'), _jsx("input", { readOnly: true, value: view.room, placeholder: t(view.appEnabled ? 'roomPending' : 'roomUnavailable'), onFocus: e => e.currentTarget.select() })] }), _jsx("button", { type: "button", disabled: !view.room, onClick: () => { void copy(view.room); }, children: t('copy') })] }), _jsx("p", { class: "mv-muted mv-hint", children: t('hint') })] }), _jsxs("details", { class: "mv-disclosure", onToggle: e => { if (!e.currentTarget.open)
|
|
108
|
+
setVisible(false); }, children: [_jsx("summary", { children: t('code') }), _jsxs("div", { class: "mv-disclosure-body", children: [_jsx("p", { class: "mv-muted", children: t('codeHint') }), _jsx("input", { class: "mv-code", "aria-label": t('code'), readOnly: true, type: visible ? 'text' : 'password', value: visible ? controller.revealCode() ?? '' : view.hasCode ? '0000000000000000' : '', autoComplete: "off", onFocus: e => e.currentTarget.select() }), _jsxs("div", { class: "mv-actions", children: [_jsx("button", { type: "button", disabled: !view.hasCode, onClick: () => setVisible(!visible), children: t(visible ? 'hide' : 'reveal') }), _jsx("button", { type: "button", disabled: !view.hasCode, onClick: () => { const code = controller.revealCode(); if (code)
|
|
109
|
+
void copy(code); }, children: t('copy') })] }), _jsxs("div", { class: "mv-stack", children: [_jsx("button", { type: "button", disabled: !view.hasCode, onClick: () => { const code = controller.revealCode(); if (code)
|
|
110
|
+
void copy(vaultLink(window.location.href, code)); }, children: t('link') }), _jsx("button", { ref: importButtonRef, type: "button", "aria-expanded": importing, onClick: () => importing ? closeImport() : setImporting(true), children: t('importAnother') })] }), importForm] })] }), _jsxs("details", { class: "mv-disclosure", children: [_jsx("summary", { children: t('advanced') }), _jsx("div", { class: "mv-disclosure-body", children: _jsx(RoomControls, { locale: locale, mode: view.mode, room: view.room, controller: controller, onInvalid: () => setNotice(t('invalid')) }) })] }), view.hasParts && _jsx("p", { class: "mv-parts mv-muted", children: t('parts', view.parts) })] }), additional.length > 0 && _jsxs("div", { class: "mv-stack", children: [_jsx("h3", { children: t('extraRooms') }), _jsx("ul", { children: additional.map(room => _jsx("li", { children: room }, room)) }), _jsx("button", { type: "button", onClick: () => { void copy(additional.join('\n')); }, children: t('copyAll') })] }), notice && _jsx("p", { class: "mv-notice", role: "status", children: notice })] });
|
|
111
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { VaultPanel } from './VaultPanel.js';
|
|
2
|
+
export type { VaultPanelProps } from './VaultPanel.js';
|
|
3
|
+
export { useVault } from './useVault.js';
|
|
4
|
+
export { ScopeVaultPanel } from './ScopeVaultPanel.js';
|
|
5
|
+
export type { ScopeVaultPanelProps } from './ScopeVaultPanel.js';
|