@blogmcp/community 0.4.1 → 0.5.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/dist/blogmcp-community-private.global.js +4 -0
- package/dist/blogmcp-community.global.js +3 -3
- package/dist/chunks/{mount-Ts_r2fwt.js → mount-SKmc4NgD.js} +39 -9
- package/dist/chunks/private-mount-bhCQeScD.js +5397 -0
- package/dist/core/attrs.d.ts +15 -0
- package/dist/core/settings.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/private/core/dock.d.ts +38 -0
- package/dist/private/core/push.d.ts +49 -0
- package/dist/private/core/realtime.d.ts +57 -0
- package/dist/private/core/setup.d.ts +43 -0
- package/dist/private/core/view.d.ts +179 -0
- package/dist/private/dm/composer.d.ts +34 -0
- package/dist/private/dm/controller.d.ts +162 -0
- package/dist/private/dm/index.d.ts +14 -0
- package/dist/private/dm/links.d.ts +33 -0
- package/dist/private/dm/muted.d.ts +37 -0
- package/dist/private/dm/search.d.ts +7 -0
- package/dist/private/dm/text.d.ts +27 -0
- package/dist/private/dm/ui/DmBlocks.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmCases.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmComposer.vue.d.ts +20 -0
- package/dist/private/dm/ui/DmInbox.vue.d.ts +12 -0
- package/dist/private/dm/ui/DmLinkWarning.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmLocalAids.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmMessageText.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmNew.vue.d.ts +12 -0
- package/dist/private/dm/ui/DmReport.vue.d.ts +8 -0
- package/dist/private/dm/ui/DmRequests.vue.d.ts +12 -0
- package/dist/private/dm/ui/DmScreens.vue.d.ts +9 -0
- package/dist/private/dm/ui/DmThread.vue.d.ts +9 -0
- package/dist/private/element.d.ts +23 -0
- package/dist/private/global.d.ts +10 -0
- package/dist/private/i18n.d.ts +41 -0
- package/dist/private/index.d.ts +32 -0
- package/dist/private/index.js +57 -0
- package/dist/private/mount.d.ts +55 -0
- package/dist/private/pages/api.d.ts +44 -0
- package/dist/private/pages/element.d.ts +6 -0
- package/dist/private/pages/fragment.d.ts +43 -0
- package/dist/private/pages/i18n.d.ts +25 -0
- package/dist/private/pages/index.d.ts +1 -0
- package/dist/private/pages/pages.d.ts +276 -0
- package/dist/private/pages/proof.d.ts +36 -0
- package/dist/private/pages/provider-view.d.ts +33 -0
- package/dist/private/pages/setup.d.ts +42 -0
- package/dist/private/pages/ui/AccountPageRoot.vue.d.ts +9 -0
- package/dist/private/pages/ui/PageActivation.vue.d.ts +9 -0
- package/dist/private/pages/ui/PageAddress.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageDeviceApprove.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageDevices.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageExport.vue.d.ts +8 -0
- package/dist/private/pages/ui/PageMessages.vue.d.ts +9 -0
- package/dist/private/react.d.ts +12 -0
- package/dist/private/react.js +36 -0
- package/dist/private/ui/ChatDockRoot.vue.d.ts +20 -0
- package/dist/private/ui/LegalText.vue.d.ts +13 -0
- package/dist/private/ui/PrivateScreens.vue.d.ts +14 -0
- package/dist/private/ui/PrivateViewRoot.vue.d.ts +23 -0
- package/dist/private/ui/PromiseBlock.vue.d.ts +9 -0
- package/dist/private/ui/ProviderLine.vue.d.ts +8 -0
- package/dist/private/ui/ScreenActivation.vue.d.ts +8 -0
- package/dist/private/ui/ScreenAddress.vue.d.ts +8 -0
- package/dist/private/ui/ScreenApproval.vue.d.ts +8 -0
- package/dist/private/ui/ScreenDevices.vue.d.ts +8 -0
- package/dist/private/ui/ScreenHome.vue.d.ts +12 -0
- package/dist/private/ui/ScreenNotifications.vue.d.ts +8 -0
- package/dist/private/ui/ScreenReads.vue.d.ts +8 -0
- package/dist/private/ui/ScreenSettings.vue.d.ts +8 -0
- package/dist/private/ui/root.d.ts +35 -0
- package/dist/private/ui/text.d.ts +22 -0
- package/dist/private/vue.d.ts +88 -0
- package/dist/private/vue.js +72 -0
- package/dist/react.js +14 -14
- package/dist/vue.js +14 -14
- package/package.json +23 -6
- package/src/core/attrs.ts +19 -0
- package/src/core/settings.ts +55 -12
- package/src/private/core/dock.ts +105 -0
- package/src/private/core/push.ts +166 -0
- package/src/private/core/realtime.ts +109 -0
- package/src/private/core/setup.ts +75 -0
- package/src/private/core/view.ts +920 -0
- package/src/private/dm/composer.ts +74 -0
- package/src/private/dm/controller.ts +636 -0
- package/src/private/dm/index.ts +14 -0
- package/src/private/dm/links.ts +55 -0
- package/src/private/dm/muted.ts +160 -0
- package/src/private/dm/search.ts +18 -0
- package/src/private/dm/text.ts +60 -0
- package/src/private/dm/ui/DmBlocks.vue +27 -0
- package/src/private/dm/ui/DmCases.vue +58 -0
- package/src/private/dm/ui/DmComposer.vue +68 -0
- package/src/private/dm/ui/DmInbox.vue +34 -0
- package/src/private/dm/ui/DmLinkWarning.vue +27 -0
- package/src/private/dm/ui/DmLocalAids.vue +43 -0
- package/src/private/dm/ui/DmMessageText.vue +16 -0
- package/src/private/dm/ui/DmNew.vue +46 -0
- package/src/private/dm/ui/DmReport.vue +93 -0
- package/src/private/dm/ui/DmRequests.vue +50 -0
- package/src/private/dm/ui/DmScreens.vue +66 -0
- package/src/private/dm/ui/DmThread.vue +235 -0
- package/src/private/element.ts +90 -0
- package/src/private/global.ts +14 -0
- package/src/private/i18n.ts +127 -0
- package/src/private/index.ts +68 -0
- package/src/private/messages/cs.json +311 -0
- package/src/private/messages/en.json +319 -0
- package/src/private/mount.ts +103 -0
- package/src/private/pages/api.ts +96 -0
- package/src/private/pages/build.d.mts +2 -0
- package/src/private/pages/build.mjs +72 -0
- package/src/private/pages/element.ts +49 -0
- package/src/private/pages/fragment.ts +63 -0
- package/src/private/pages/i18n.ts +82 -0
- package/src/private/pages/index.ts +10 -0
- package/src/private/pages/messages/cs.json +97 -0
- package/src/private/pages/messages/en.json +97 -0
- package/src/private/pages/pages.ts +410 -0
- package/src/private/pages/proof.ts +110 -0
- package/src/private/pages/provider-view.ts +121 -0
- package/src/private/pages/setup.ts +79 -0
- package/src/private/pages/ui/AccountPageRoot.vue +45 -0
- package/src/private/pages/ui/PageActivation.vue +42 -0
- package/src/private/pages/ui/PageAddress.vue +39 -0
- package/src/private/pages/ui/PageDeviceApprove.vue +62 -0
- package/src/private/pages/ui/PageDevices.vue +84 -0
- package/src/private/pages/ui/PageExport.vue +35 -0
- package/src/private/pages/ui/PageMessages.vue +39 -0
- package/src/private/pages/ui/account.css +6 -0
- package/src/private/react.ts +49 -0
- package/src/private/shims.d.ts +6 -0
- package/src/private/ui/ChatDockRoot.vue +119 -0
- package/src/private/ui/LegalText.vue +18 -0
- package/src/private/ui/PrivateScreens.vue +61 -0
- package/src/private/ui/PrivateViewRoot.vue +70 -0
- package/src/private/ui/PromiseBlock.vue +18 -0
- package/src/private/ui/ProviderLine.vue +20 -0
- package/src/private/ui/ScreenActivation.vue +82 -0
- package/src/private/ui/ScreenAddress.vue +37 -0
- package/src/private/ui/ScreenApproval.vue +71 -0
- package/src/private/ui/ScreenDevices.vue +42 -0
- package/src/private/ui/ScreenHome.vue +29 -0
- package/src/private/ui/ScreenNotifications.vue +44 -0
- package/src/private/ui/ScreenReads.vue +23 -0
- package/src/private/ui/ScreenSettings.vue +44 -0
- package/src/private/ui/private.css +81 -0
- package/src/private/ui/root.ts +89 -0
- package/src/private/ui/text.ts +40 -0
- package/src/private/vue.ts +87 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The account pages' controllers (m4-contracts.md §6.4, §5.10, §5.11): one per page, framework-free but for Vue's
|
|
3
|
+
* reactivity, over the account client (api.ts) and the capability the page was opened with (fragment.ts). The Vue
|
|
4
|
+
* files only render a controller's state and call its actions; the specs drive the controllers directly.
|
|
5
|
+
*
|
|
6
|
+
* What every page holds to: it acts only on the member's click (a mail scanner that opens the link runs no script,
|
|
7
|
+
* and a page that ran one would still act on nothing), it shows what it is about to do before the button that does
|
|
8
|
+
* it, and an irreversible act — the dispute, the end of the contract, a sign-out, the export — takes a second,
|
|
9
|
+
* explicit confirmation (`armed`). A refusal is said by its code (i18n.ts `accountErrorKey`), never a raw message.
|
|
10
|
+
*/
|
|
11
|
+
import { reactive } from 'vue'
|
|
12
|
+
import { accountOperationUrl, type AccountApi, type AccountOutcome } from './api'
|
|
13
|
+
import type { Capability, CapabilityPurpose } from './fragment'
|
|
14
|
+
import { signApproveProof, type DeviceKey } from './proof'
|
|
15
|
+
|
|
16
|
+
/** A refusal on screen: its code (worded by i18n.ts). */
|
|
17
|
+
export interface PageFailure {
|
|
18
|
+
readonly code: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Base {
|
|
22
|
+
/** `noToken`: opened without a usable capability of this page's kind. */
|
|
23
|
+
phase: string
|
|
24
|
+
failure: PageFailure | null
|
|
25
|
+
busy: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const failureOf = (out: AccountOutcome<unknown>): PageFailure | null => (out.ok ? null : { code: out.code })
|
|
29
|
+
|
|
30
|
+
/** Run one call while nothing else runs; the refusal lands in `failure`. */
|
|
31
|
+
async function run<T>(s: Base, call: () => Promise<AccountOutcome<T>>): Promise<T | null> {
|
|
32
|
+
if (s.busy) return null
|
|
33
|
+
s.busy = true
|
|
34
|
+
s.failure = null
|
|
35
|
+
try {
|
|
36
|
+
const out = await call()
|
|
37
|
+
s.failure = failureOf(out)
|
|
38
|
+
return out.ok ? out.value : null
|
|
39
|
+
} finally {
|
|
40
|
+
s.busy = false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ofPurpose = (c: Capability | null, purposes: readonly CapabilityPurpose[]): Capability | null => (c && purposes.includes(c.purpose) ? c : null)
|
|
45
|
+
|
|
46
|
+
// ───────────────────────── /adresa ─────────────────────────
|
|
47
|
+
|
|
48
|
+
export type AddressMode = 'set' | 'verify' | 'confirm'
|
|
49
|
+
|
|
50
|
+
export interface AddressPageState extends Base {
|
|
51
|
+
phase: 'noToken' | 'ready' | 'done'
|
|
52
|
+
mode: AddressMode | null
|
|
53
|
+
/** `set`: where the verification link went and until when. */
|
|
54
|
+
sent: { email: string; expiresAt: string | null } | null
|
|
55
|
+
/** `verify`: kb-api's result; `confirm`: 'confirmed'. */
|
|
56
|
+
result: 'verified' | 'changed' | 'confirmed' | null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* `/adresa`: set the approval address (`kbas_`, from the private view's address step), verify it (`kbav_`, `kbaw_`,
|
|
61
|
+
* from the verification e-mail) or confirm a change from the old address (`kbax_`). The address is typed here, on a
|
|
62
|
+
* blogmcp page, and never on the tenant's site (§6.2).
|
|
63
|
+
*/
|
|
64
|
+
export function createAddressPage(o: { api: AccountApi; capability: Capability | null }) {
|
|
65
|
+
const c = o.capability
|
|
66
|
+
const mode: AddressMode | null = ofPurpose(c, ['address_set'])
|
|
67
|
+
? 'set'
|
|
68
|
+
: ofPurpose(c, ['address_verify', 'address_change_verify'])
|
|
69
|
+
? 'verify'
|
|
70
|
+
: ofPurpose(c, ['address_change_confirm'])
|
|
71
|
+
? 'confirm'
|
|
72
|
+
: null
|
|
73
|
+
const state = reactive<AddressPageState>({ phase: mode ? 'ready' : 'noToken', mode, failure: null, busy: false, sent: null, result: null })
|
|
74
|
+
return {
|
|
75
|
+
state,
|
|
76
|
+
async submit(email: string): Promise<void> {
|
|
77
|
+
const value = email.trim()
|
|
78
|
+
if (mode !== 'set' || value === '' || state.phase !== 'ready') return
|
|
79
|
+
const out = await run(state, () => o.api.call<{ expiresAt?: string }>('address/set', { token: c!.token, email: value }))
|
|
80
|
+
if (!out) return
|
|
81
|
+
state.sent = { email: value, expiresAt: typeof out.expiresAt === 'string' ? out.expiresAt : null }
|
|
82
|
+
state.phase = 'done'
|
|
83
|
+
},
|
|
84
|
+
async verify(): Promise<void> {
|
|
85
|
+
if (mode !== 'verify' || state.phase !== 'ready') return
|
|
86
|
+
const out = await run(state, () => o.api.call<{ result?: string }>('address/verify', { token: c!.token }))
|
|
87
|
+
if (!out) return
|
|
88
|
+
state.result = out.result === 'changed' ? 'changed' : 'verified'
|
|
89
|
+
state.phase = 'done'
|
|
90
|
+
},
|
|
91
|
+
async confirm(): Promise<void> {
|
|
92
|
+
if (mode !== 'confirm' || state.phase !== 'ready') return
|
|
93
|
+
const out = await run(state, () => o.api.call('address/change/confirm', { token: c!.token }))
|
|
94
|
+
if (!out) return
|
|
95
|
+
state.result = 'confirmed'
|
|
96
|
+
state.phase = 'done'
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ───────────────────────── /zarizeni ─────────────────────────
|
|
102
|
+
|
|
103
|
+
/** `account/device/approval/get`'s answer (kb-api's EmailApprovalView). */
|
|
104
|
+
export interface ApprovalView {
|
|
105
|
+
label: string
|
|
106
|
+
origin: string | null
|
|
107
|
+
createdAt: string
|
|
108
|
+
mintKeyId: string | null
|
|
109
|
+
ipPrefix: string | null
|
|
110
|
+
jkt: string
|
|
111
|
+
sameNetwork: boolean
|
|
112
|
+
binding: 'code' | 'key'
|
|
113
|
+
expiresAt: string
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface DeviceApprovePageState extends Base {
|
|
117
|
+
phase: 'noToken' | 'loading' | 'ready' | 'approved' | 'failed'
|
|
118
|
+
view: ApprovalView | null
|
|
119
|
+
/** Under `binding: 'key'`: whether this browser holds the pending device's key (null before it is looked up). */
|
|
120
|
+
keyHere: boolean | null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const isApprovalView = (v: unknown): v is ApprovalView => {
|
|
124
|
+
const r = v as Partial<ApprovalView> | null
|
|
125
|
+
return !!r && typeof r.label === 'string' && typeof r.jkt === 'string' && (r.binding === 'code' || r.binding === 'key') && typeof r.sameNetwork === 'boolean'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* `/zarizeni` (`kbda_`, from the e-mail approval, B-57 and B-66): first the device that asks — its label, the website
|
|
130
|
+
* it claims, when and from which network it signed in, the website's key — and the network warning when that network
|
|
131
|
+
* is not this page's (advisory); then the approval, bound as kb-api says:
|
|
132
|
+
* - `code` (tenant rendering): only with the code the new device shows, typed here; a wrong code leaves the link
|
|
133
|
+
* usable for the next attempt, the fifth ends the request;
|
|
134
|
+
* - `key` (`provider_page`): only with a proof signed by the pending device's key from this origin's IndexedDB;
|
|
135
|
+
* without that key here the page says to open the link on that device, and offers no code instead.
|
|
136
|
+
*/
|
|
137
|
+
export function createDeviceApprovePage(o: {
|
|
138
|
+
api: AccountApi
|
|
139
|
+
capability: Capability | null
|
|
140
|
+
/** This page's origin (the account host): the proof's `htu`. */
|
|
141
|
+
origin: string
|
|
142
|
+
findKey: (jkt: string) => Promise<DeviceKey | null>
|
|
143
|
+
sign?: typeof signApproveProof
|
|
144
|
+
now?: () => number
|
|
145
|
+
}) {
|
|
146
|
+
const c = ofPurpose(o.capability, ['device_approve'])
|
|
147
|
+
const state = reactive<DeviceApprovePageState>({ phase: c ? 'loading' : 'noToken', failure: null, busy: false, view: null, keyHere: null })
|
|
148
|
+
let key: DeviceKey | null = null
|
|
149
|
+
|
|
150
|
+
const settle = (out: unknown): void => {
|
|
151
|
+
if (out === null) {
|
|
152
|
+
// The request ended (exhausted, expired, approved elsewhere): this link takes nothing more.
|
|
153
|
+
if (state.failure && state.failure.code !== 'APPROVAL_INVALID' && state.failure.code !== 'NETWORK' && state.failure.code !== 'TOO_FAST') state.phase = 'failed'
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
state.phase = 'approved'
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
state,
|
|
161
|
+
async load(): Promise<void> {
|
|
162
|
+
if (!c) return
|
|
163
|
+
state.phase = 'loading'
|
|
164
|
+
const out = await run(state, () => o.api.call('device/approval/get', { token: c.token }))
|
|
165
|
+
if (!out || !isApprovalView(out)) {
|
|
166
|
+
if (out && !state.failure) state.failure = { code: 'BAD_ANSWER' }
|
|
167
|
+
state.phase = 'failed'
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
state.view = out
|
|
171
|
+
if (out.binding === 'key') {
|
|
172
|
+
key = await o.findKey(out.jkt).catch(() => null)
|
|
173
|
+
state.keyHere = key !== null
|
|
174
|
+
}
|
|
175
|
+
state.phase = 'ready'
|
|
176
|
+
},
|
|
177
|
+
async approveWithCode(code: string): Promise<void> {
|
|
178
|
+
const value = code.trim()
|
|
179
|
+
if (!c || state.phase !== 'ready' || state.view?.binding !== 'code' || value === '') return
|
|
180
|
+
settle(await run(state, () => o.api.call('device/approve', { token: c.token, code: value })))
|
|
181
|
+
},
|
|
182
|
+
async approveWithKey(): Promise<void> {
|
|
183
|
+
if (!c || state.phase !== 'ready' || state.view?.binding !== 'key' || key === null) return
|
|
184
|
+
const htu = accountOperationUrl(o.origin, 'device/approve')
|
|
185
|
+
if (htu === null) return
|
|
186
|
+
const k = key
|
|
187
|
+
settle(
|
|
188
|
+
await run(state, async () => {
|
|
189
|
+
let proof: string
|
|
190
|
+
try {
|
|
191
|
+
proof = await (o.sign ?? signApproveProof)({ key: k, htu, token: c.token, now: o.now?.() })
|
|
192
|
+
} catch {
|
|
193
|
+
return { ok: false, code: 'APPROVAL_INVALID', status: null }
|
|
194
|
+
}
|
|
195
|
+
return o.api.call('device/approve', { token: c.token, proof })
|
|
196
|
+
}),
|
|
197
|
+
)
|
|
198
|
+
},
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ───────────────────────── /zarizeni/seznam ─────────────────────────
|
|
203
|
+
|
|
204
|
+
/** One of the member's devices as `account/device/list` answers it (kb-api's DeviceView). */
|
|
205
|
+
export interface AccountDevice {
|
|
206
|
+
id: string
|
|
207
|
+
label: string
|
|
208
|
+
origin: string | null
|
|
209
|
+
mintKeyId: string | null
|
|
210
|
+
signIn: { ipPrefix: string | null; at: string | null }
|
|
211
|
+
createdAt: string
|
|
212
|
+
lastSeenAt: string
|
|
213
|
+
state: 'first' | 'approved' | 'pending'
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface AccountReadHour {
|
|
217
|
+
deviceId: string
|
|
218
|
+
hour: string
|
|
219
|
+
reads: number
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** A sign-out waiting for its second confirmation. */
|
|
223
|
+
export type PendingSignOut = { kind: 'one'; deviceId: string; label: string } | { kind: 'all' }
|
|
224
|
+
|
|
225
|
+
export interface DevicesPageState extends Base {
|
|
226
|
+
phase: 'noToken' | 'loading' | 'ready' | 'failed'
|
|
227
|
+
devices: AccountDevice[] | null
|
|
228
|
+
reads: AccountReadHour[] | null
|
|
229
|
+
armed: PendingSignOut | null
|
|
230
|
+
/** The last sign-out's result, for the announcement. */
|
|
231
|
+
signedOut: { kind: 'one' } | { kind: 'all'; count: number } | null
|
|
232
|
+
change: { expiresAt: string | null } | null
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const DEVICE_STATES = ['first', 'approved', 'pending'] as const
|
|
236
|
+
|
|
237
|
+
function devicesOf(value: unknown): AccountDevice[] | null {
|
|
238
|
+
const list = (value as { devices?: unknown } | null)?.devices
|
|
239
|
+
if (!Array.isArray(list)) return null
|
|
240
|
+
return list.filter(
|
|
241
|
+
(d): d is AccountDevice =>
|
|
242
|
+
!!d && typeof (d as AccountDevice).id === 'string' && typeof (d as AccountDevice).label === 'string' && (DEVICE_STATES as readonly unknown[]).includes((d as AccountDevice).state),
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* `/zarizeni/seznam` (`kbdl_`, from a sign-in e-mail: 24 hours, at most 20 uses, every list and sign-out spends one):
|
|
248
|
+
* the member's devices, their sign-out (which removes a device for good, §5.10) one by one or all at once, the read log
|
|
249
|
+
* on request, and the change of the approval address, confirmed from the old address.
|
|
250
|
+
*/
|
|
251
|
+
export function createDevicesPage(o: { api: AccountApi; capability: Capability | null }) {
|
|
252
|
+
const c = ofPurpose(o.capability, ['device_list'])
|
|
253
|
+
const state = reactive<DevicesPageState>({ phase: c ? 'loading' : 'noToken', failure: null, busy: false, devices: null, reads: null, armed: null, signedOut: null, change: null })
|
|
254
|
+
|
|
255
|
+
async function list(): Promise<void> {
|
|
256
|
+
const out = await run(state, () => o.api.call('device/list', { token: c!.token }))
|
|
257
|
+
const devices = out ? devicesOf(out) : null
|
|
258
|
+
if (devices === null) {
|
|
259
|
+
if (out && !state.failure) state.failure = { code: 'BAD_ANSWER' }
|
|
260
|
+
if (state.devices === null) state.phase = 'failed'
|
|
261
|
+
return
|
|
262
|
+
}
|
|
263
|
+
state.devices = devices
|
|
264
|
+
state.phase = 'ready'
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return {
|
|
268
|
+
state,
|
|
269
|
+
async load(): Promise<void> {
|
|
270
|
+
if (!c) return
|
|
271
|
+
state.phase = 'loading'
|
|
272
|
+
await list()
|
|
273
|
+
},
|
|
274
|
+
async showReads(): Promise<void> {
|
|
275
|
+
if (!c || state.phase !== 'ready') return
|
|
276
|
+
const out = await run(state, () => o.api.call<{ reads?: unknown }>('reads/list', { token: c.token }))
|
|
277
|
+
if (!out) return
|
|
278
|
+
const rows = Array.isArray(out.reads) ? out.reads : []
|
|
279
|
+
state.reads = rows.filter((r): r is AccountReadHour => !!r && typeof (r as AccountReadHour).deviceId === 'string' && typeof (r as AccountReadHour).hour === 'string' && typeof (r as AccountReadHour).reads === 'number')
|
|
280
|
+
},
|
|
281
|
+
armSignOut(device: AccountDevice): void {
|
|
282
|
+
if (state.phase === 'ready') state.armed = { kind: 'one', deviceId: device.id, label: device.label }
|
|
283
|
+
},
|
|
284
|
+
armSignOutAll(): void {
|
|
285
|
+
if (state.phase === 'ready') state.armed = { kind: 'all' }
|
|
286
|
+
},
|
|
287
|
+
cancel(): void {
|
|
288
|
+
state.armed = null
|
|
289
|
+
},
|
|
290
|
+
/** The second confirmation: only now is a sign-out sent. */
|
|
291
|
+
async confirmSignOut(): Promise<void> {
|
|
292
|
+
const armed = state.armed
|
|
293
|
+
if (!c || !armed || state.phase !== 'ready') return
|
|
294
|
+
if (armed.kind === 'one') {
|
|
295
|
+
const out = await run(state, () => o.api.call('device/sign-out', { token: c.token, deviceId: armed.deviceId }))
|
|
296
|
+
state.armed = null
|
|
297
|
+
if (!out) return
|
|
298
|
+
state.devices = (state.devices ?? []).filter((d) => d.id !== armed.deviceId)
|
|
299
|
+
state.signedOut = { kind: 'one' }
|
|
300
|
+
return
|
|
301
|
+
}
|
|
302
|
+
const out = await run(state, () => o.api.call<{ removed?: number }>('device/sign-out-all', { token: c.token }))
|
|
303
|
+
state.armed = null
|
|
304
|
+
if (!out) return
|
|
305
|
+
state.devices = []
|
|
306
|
+
state.signedOut = { kind: 'all', count: typeof out.removed === 'number' ? out.removed : 0 }
|
|
307
|
+
},
|
|
308
|
+
async requestChange(newEmail: string): Promise<void> {
|
|
309
|
+
const value = newEmail.trim()
|
|
310
|
+
if (!c || state.phase !== 'ready' || value === '') return
|
|
311
|
+
const out = await run(state, () => o.api.call<{ expiresAt?: string }>('address/change/request', { token: c.token, newEmail: value }))
|
|
312
|
+
if (out) state.change = { expiresAt: typeof out.expiresAt === 'string' ? out.expiresAt : null }
|
|
313
|
+
},
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ───────────────────────── /export ─────────────────────────
|
|
318
|
+
|
|
319
|
+
export interface ExportPageState extends Base {
|
|
320
|
+
phase: 'noToken' | 'ready' | 'confirmed' | 'downloaded'
|
|
321
|
+
armed: boolean
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Save a JSON value as a file on this device (the browser's download). */
|
|
325
|
+
export function saveJsonFile(name: string, value: unknown): void {
|
|
326
|
+
const url = URL.createObjectURL(new Blob([JSON.stringify(value, null, 2)], { type: 'application/json' }))
|
|
327
|
+
const a = document.createElement('a')
|
|
328
|
+
a.href = url
|
|
329
|
+
a.download = name
|
|
330
|
+
a.rel = 'noopener'
|
|
331
|
+
document.body.appendChild(a)
|
|
332
|
+
a.click()
|
|
333
|
+
a.remove()
|
|
334
|
+
setTimeout(() => URL.revokeObjectURL(url), 60_000)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
export const EXPORT_FILE_NAME = 'blogmcp-private-messages.json'
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* `/export` (`kbae_`, from the export confirmation e-mail, B-3, DM7b): the confirmation, then the download — on this
|
|
341
|
+
* origin, so that on a headless site the export never passes through the tenant's (§6.4). The operations are DM7b's
|
|
342
|
+
* (`account/export/confirm`, `account/export/download`); until kb-api serves them the page says the export is not
|
|
343
|
+
* available, without asking anything.
|
|
344
|
+
*/
|
|
345
|
+
export function createExportPage(o: { api: AccountApi; capability: Capability | null; save?: (name: string, value: unknown) => void }) {
|
|
346
|
+
const c = ofPurpose(o.capability, ['export_confirm'])
|
|
347
|
+
const state = reactive<ExportPageState>({ phase: c ? 'ready' : 'noToken', failure: null, busy: false, armed: false })
|
|
348
|
+
return {
|
|
349
|
+
state,
|
|
350
|
+
arm(): void {
|
|
351
|
+
if (state.phase === 'ready') state.armed = true
|
|
352
|
+
},
|
|
353
|
+
cancel(): void {
|
|
354
|
+
state.armed = false
|
|
355
|
+
},
|
|
356
|
+
async confirm(): Promise<void> {
|
|
357
|
+
if (!c || state.phase !== 'ready' || !state.armed) return
|
|
358
|
+
const out = await run(state, () => o.api.call('export/confirm', { token: c.token }))
|
|
359
|
+
state.armed = false
|
|
360
|
+
if (out) state.phase = 'confirmed'
|
|
361
|
+
},
|
|
362
|
+
async download(): Promise<void> {
|
|
363
|
+
if (!c || state.phase !== 'confirmed') return
|
|
364
|
+
const out = await run(state, () => o.api.call('export/download', { token: c.token }))
|
|
365
|
+
if (!out) return
|
|
366
|
+
;(o.save ?? saveJsonFile)(EXPORT_FILE_NAME, out)
|
|
367
|
+
state.phase = 'downloaded'
|
|
368
|
+
},
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// ───────────────────────── /aktivace/spor, /aktivace/konec ─────────────────────────
|
|
373
|
+
|
|
374
|
+
export interface ActivationPageState extends Base {
|
|
375
|
+
phase: 'noToken' | 'ready' | 'done'
|
|
376
|
+
armed: boolean
|
|
377
|
+
/** The dispute: how many devices it removed. */
|
|
378
|
+
devicesRemoved: number | null
|
|
379
|
+
/** The end: the kind the activation's time allowed. */
|
|
380
|
+
kind: 'withdrawal' | 'termination' | null
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* `/aktivace/spor` (`kbad_`, „Nebyli jste to vy?“ from the activation's confirmation e-mail) and `/aktivace/konec`
|
|
385
|
+
* (`kbac_`, the end of the contract confirmed from its e-mail on a headless site, B-58): each says what it does, and
|
|
386
|
+
* calls its operation only after the page's own second confirmation (PS4).
|
|
387
|
+
*/
|
|
388
|
+
export function createActivationPage(o: { api: AccountApi; capability: Capability | null; act: 'dispute' | 'end' }) {
|
|
389
|
+
const c = ofPurpose(o.capability, [o.act === 'dispute' ? 'activation_dispute' : 'contract_end_confirm'])
|
|
390
|
+
const state = reactive<ActivationPageState>({ phase: c ? 'ready' : 'noToken', failure: null, busy: false, armed: false, devicesRemoved: null, kind: null })
|
|
391
|
+
return {
|
|
392
|
+
state,
|
|
393
|
+
arm(): void {
|
|
394
|
+
if (state.phase === 'ready') state.armed = true
|
|
395
|
+
},
|
|
396
|
+
cancel(): void {
|
|
397
|
+
state.armed = false
|
|
398
|
+
},
|
|
399
|
+
async confirm(): Promise<void> {
|
|
400
|
+
if (!c || state.phase !== 'ready' || !state.armed) return
|
|
401
|
+
const op = o.act === 'dispute' ? 'activation/dispute' : 'activation/end'
|
|
402
|
+
const out = await run(state, () => o.api.call<{ devicesRemoved?: number; kind?: string }>(op, { token: c.token }))
|
|
403
|
+
state.armed = false
|
|
404
|
+
if (!out) return
|
|
405
|
+
state.devicesRemoved = typeof out.devicesRemoved === 'number' ? out.devicesRemoved : null
|
|
406
|
+
state.kind = out.kind === 'withdrawal' || out.kind === 'termination' ? out.kind : null
|
|
407
|
+
state.phase = 'done'
|
|
408
|
+
},
|
|
409
|
+
}
|
|
410
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key-bound approval under `provider_page` (m4-contracts.md §5.10, `[OWNER]` B-66): `/zarizeni` approves a pending
|
|
3
|
+
* device only with a proof signed by that device's own key, which lives in this origin's IndexedDB — the account
|
|
4
|
+
* host's, where `/zpravy` made it (the SDK's keystore, database `blogmcp-private`, store `keys`). A key outside this
|
|
5
|
+
* origin (the tenant's server's, a tenant-origin page's) can never produce the proof in the member's browser, so a
|
|
6
|
+
* code shown on the tenant's site cannot be turned into an approval here.
|
|
7
|
+
*
|
|
8
|
+
* The proof is a compact JWS of PS1's shape (kb-api's `checkApproveProof`, services/community/private/approval.ts):
|
|
9
|
+
* header `{ typ: 'blogmcp-approve+jwt', alg: 'ES256', jwk }`, claims `{ jti, htm: 'POST', htu, iat, ath }`, where
|
|
10
|
+
* `htu` is the approve operation's URL on this origin and `ath` the capability's SHA-256 — so the proof is good for
|
|
11
|
+
* this one capability, once (kb-api spends the `jti`), for a few minutes.
|
|
12
|
+
*
|
|
13
|
+
* Reading the keystore never creates it: a browser that never opened `/zpravy` on this origin has no database, and
|
|
14
|
+
* opening one here would leave an empty database the SDK then could not upgrade; the creation is aborted instead.
|
|
15
|
+
*/
|
|
16
|
+
import { PRIVATE_DB_NAME, PRIVATE_DB_STORE, type DevicePublicJwk } from '@blogmcp/sdk/community/private'
|
|
17
|
+
|
|
18
|
+
export const APPROVE_PROOF_TYP = 'blogmcp-approve+jwt'
|
|
19
|
+
|
|
20
|
+
/** The part of a keystore record a proof needs. */
|
|
21
|
+
export interface DeviceKey {
|
|
22
|
+
readonly jkt: string
|
|
23
|
+
readonly publicJwk: DevicePublicJwk
|
|
24
|
+
readonly privateKey: CryptoKey
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The records of the SDK's keystore in this origin, or [] when it does not exist (never creating it). */
|
|
28
|
+
async function keystoreRecords(factory: IDBFactory): Promise<unknown[]> {
|
|
29
|
+
const db = await new Promise<IDBDatabase | null>((resolve) => {
|
|
30
|
+
let creating = false
|
|
31
|
+
let request: IDBOpenDBRequest
|
|
32
|
+
try {
|
|
33
|
+
request = factory.open(PRIVATE_DB_NAME)
|
|
34
|
+
} catch {
|
|
35
|
+
resolve(null)
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
request.onupgradeneeded = () => {
|
|
39
|
+
// The database did not exist: abort its creation (the SDK creates it, with its store, when it needs one).
|
|
40
|
+
creating = true
|
|
41
|
+
request.transaction?.abort()
|
|
42
|
+
}
|
|
43
|
+
request.onsuccess = () => {
|
|
44
|
+
if (creating) {
|
|
45
|
+
request.result.close()
|
|
46
|
+
resolve(null)
|
|
47
|
+
} else resolve(request.result)
|
|
48
|
+
}
|
|
49
|
+
request.onerror = () => resolve(null)
|
|
50
|
+
request.onblocked = () => resolve(null)
|
|
51
|
+
})
|
|
52
|
+
if (db === null) return []
|
|
53
|
+
try {
|
|
54
|
+
if (!db.objectStoreNames.contains(PRIVATE_DB_STORE)) return []
|
|
55
|
+
return await new Promise<unknown[]>((resolve) => {
|
|
56
|
+
const req = db.transaction(PRIVATE_DB_STORE, 'readonly').objectStore(PRIVATE_DB_STORE).getAll()
|
|
57
|
+
req.onsuccess = () => resolve(Array.isArray(req.result) ? (req.result as unknown[]) : [])
|
|
58
|
+
req.onerror = () => resolve([])
|
|
59
|
+
})
|
|
60
|
+
} catch {
|
|
61
|
+
return []
|
|
62
|
+
} finally {
|
|
63
|
+
db.close()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The key whose thumbprint is `jkt` in this origin's keystore, or null when this browser does not hold it. */
|
|
68
|
+
export async function findDeviceKey(jkt: string, factory: IDBFactory = indexedDB): Promise<DeviceKey | null> {
|
|
69
|
+
for (const value of await keystoreRecords(factory)) {
|
|
70
|
+
const r = value as { jkt?: unknown; publicJwk?: DevicePublicJwk; keyPair?: CryptoKeyPair } | null
|
|
71
|
+
if (r && r.jkt === jkt && r.publicJwk && r.keyPair?.privateKey) return { jkt, publicJwk: r.publicJwk, privateKey: r.keyPair.privateKey }
|
|
72
|
+
}
|
|
73
|
+
return null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function base64url(bytes: Uint8Array): string {
|
|
77
|
+
let s = ''
|
|
78
|
+
for (const b of bytes) s += String.fromCharCode(b)
|
|
79
|
+
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const utf8 = (s: string) => new TextEncoder().encode(s)
|
|
83
|
+
|
|
84
|
+
export interface ApproveProofInput {
|
|
85
|
+
key: DeviceKey
|
|
86
|
+
/** The approve operation's URL on this origin. */
|
|
87
|
+
htu: string
|
|
88
|
+
/** The `kbda_` capability the request carries. */
|
|
89
|
+
token: string
|
|
90
|
+
/** Epoch milliseconds (default now). */
|
|
91
|
+
now?: number
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The proof for one `account/device/approve` request. */
|
|
95
|
+
export async function signApproveProof(input: ApproveProofInput): Promise<string> {
|
|
96
|
+
const subtle = crypto.subtle
|
|
97
|
+
const jwk = input.key.publicJwk
|
|
98
|
+
const header = { typ: APPROVE_PROOF_TYP, alg: 'ES256', jwk: { kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y } }
|
|
99
|
+
const claims = {
|
|
100
|
+
jti: base64url(crypto.getRandomValues(new Uint8Array(16))),
|
|
101
|
+
htm: 'POST',
|
|
102
|
+
htu: input.htu,
|
|
103
|
+
iat: Math.floor((input.now ?? Date.now()) / 1000),
|
|
104
|
+
ath: base64url(new Uint8Array(await subtle.digest('SHA-256', utf8(input.token)))),
|
|
105
|
+
}
|
|
106
|
+
const signingInput = `${base64url(utf8(JSON.stringify(header)))}.${base64url(utf8(JSON.stringify(claims)))}`
|
|
107
|
+
// WebCrypto's ECDSA signature is the raw r ‖ s that JWS ES256 wants.
|
|
108
|
+
const signature = await subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, input.key.privateKey, utf8(signingInput))
|
|
109
|
+
return `${signingInput}.${base64url(new Uint8Array(signature))}`
|
|
110
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/zpravy`, the private view under `provider_page` (m4-contracts.md §6.4, §9.8's fallback): the reference UI on the
|
|
3
|
+
* account host, its DPoP key in this origin's IndexedDB (a third origin, so the member's device here is its own), and a
|
|
4
|
+
* private session that only this origin's CORS admits (§5.8).
|
|
5
|
+
*
|
|
6
|
+
* **The grant comes by a top-level round trip, on every load.** Without the hand-off's fragment the page navigates to
|
|
7
|
+
* the site's hand-off route — `https://<site>/komunita/grant/handoff?jkt=…&state=…` (a managed blog's
|
|
8
|
+
* `/blog/community/grant/handoff`), which kb-api's template names from configuration, never from the request — with
|
|
9
|
+
* this browser's key and a random `state` kept in the tab's sessionStorage. The site's `createPrivateGrantHandoff`
|
|
10
|
+
* asks for a grant with its own member session and answers `303` to the fixed `/zpravy#grant=…&state=…`; the page
|
|
11
|
+
* checks `state`, takes the first nonce, the clock and `memberRef`, selects (or makes) that member's key and repeats
|
|
12
|
+
* the hand-off once if the key it sent was another member's (the SDK's `completeHandoff`). The refresh token stays in
|
|
13
|
+
* the tab, so a sign-out on the site — which this origin never sees — ends the private view at the next load, and a
|
|
14
|
+
* second member on the same browser never reaches the first one's session. A fragment whose `state` this tab did not
|
|
15
|
+
* make is discarded: a page that navigates a member to the hand-off with its own `jkt` gets nothing.
|
|
16
|
+
*
|
|
17
|
+
* **The view** is the private elements' controller (`../core/view`) and screens, over this origin's private client. The
|
|
18
|
+
* controller asks its host's `me/get` first; the account host has none, so it is given one that states what the
|
|
19
|
+
* hand-off already proved: a member is signed in and the private view renders here (`rendering: 'tenant'` in the
|
|
20
|
+
* controller's words, because its `provider_page` means "only a link to this page"). The promise still reads
|
|
21
|
+
* `provider_page`: kb-api applies the `rendering_provider_page` variant to the texts it serves this session, and the
|
|
22
|
+
* controller takes the rendering from those variants. No private push here (B-30): no worker on this origin.
|
|
23
|
+
*
|
|
24
|
+
* **The live inbox** (C.9's carry): the view runs the SDK's private realtime client (`createPrivateRealtime`) over this
|
|
25
|
+
* origin's private client, so the connection's tokens are DPoP-bound to this page's device; the account pages' CSP
|
|
26
|
+
* admits its `wss://` origin on `/zpravy` (routes/account-pages.ts).
|
|
27
|
+
*/
|
|
28
|
+
import { reactive } from 'vue'
|
|
29
|
+
import type { CommunityClient } from '@blogmcp/sdk/community'
|
|
30
|
+
import { createPrivateClient, createPrivateRealtime, type PrivateClient, type PrivateSession } from '@blogmcp/sdk/community/private'
|
|
31
|
+
import type { PrivateRealtimeInput } from '../core/realtime'
|
|
32
|
+
import { createPrivateView, type PrivateViewController } from '../core/view'
|
|
33
|
+
|
|
34
|
+
export type MessagesPhase = 'starting' | 'redirecting' | 'open' | 'signIn' | 'invalid' | 'failed'
|
|
35
|
+
|
|
36
|
+
export interface MessagesPageState {
|
|
37
|
+
phase: MessagesPhase
|
|
38
|
+
/** The refusal's code under `failed`. */
|
|
39
|
+
code: string | null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The host the controller asks first: the hand-off proved a member and a live session (see the module comment). */
|
|
43
|
+
function handedOffHost(): CommunityClient {
|
|
44
|
+
const me = Object.freeze({
|
|
45
|
+
ok: true,
|
|
46
|
+
value: Object.freeze({ needs: Object.freeze([]), member: Object.freeze({ memberId: '' }), module: Object.freeze({ private: Object.freeze({ state: 'live', rendering: 'tenant' }) }) }),
|
|
47
|
+
})
|
|
48
|
+
return { me: { get: async () => me } } as unknown as CommunityClient
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The hand-off's codes that mean "no member session on the site" (the SDK's route answers UNAUTHORIZED then). */
|
|
52
|
+
const SIGN_IN_CODES = new Set(['UNAUTHORIZED', 'NO_MEMBER', 'HANDOFF_REQUIRED'])
|
|
53
|
+
|
|
54
|
+
export interface MessagesPageOptions {
|
|
55
|
+
/** kb-api's main origin, the private session's (the template's `kb-origin`). */
|
|
56
|
+
kbOrigin: string
|
|
57
|
+
/** The site's hand-off route (the template's `handoff-url`). */
|
|
58
|
+
handoffUrl: string
|
|
59
|
+
/** The website's name for the promise. */
|
|
60
|
+
siteName: string
|
|
61
|
+
/** The location's fragment at load (default the page's). */
|
|
62
|
+
hash?: () => string
|
|
63
|
+
/** A private client made elsewhere (specs). */
|
|
64
|
+
client?: PrivateClient
|
|
65
|
+
/** The live inbox (default the SDK's `createPrivateRealtime`; specs pass a stub, null turns it off). */
|
|
66
|
+
realtime?: PrivateRealtimeInput | null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function createMessagesPage(o: MessagesPageOptions) {
|
|
70
|
+
const state = reactive<MessagesPageState>({ phase: 'starting', code: null })
|
|
71
|
+
const client = o.client ?? createPrivateClient({ kbOrigin: o.kbOrigin, rendering: 'provider_page' })
|
|
72
|
+
const session: PrivateSession = client.session
|
|
73
|
+
let view: PrivateViewController | null = null
|
|
74
|
+
|
|
75
|
+
/** Start the hand-off from scratch (a load without its fragment, or the member's "open again"). */
|
|
76
|
+
async function begin(): Promise<void> {
|
|
77
|
+
const out = await session.beginHandoff(o.handoffUrl)
|
|
78
|
+
if (out.ok) state.phase = 'redirecting'
|
|
79
|
+
else {
|
|
80
|
+
state.phase = 'failed'
|
|
81
|
+
state.code = out.code
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
state,
|
|
87
|
+
get view(): PrivateViewController | null {
|
|
88
|
+
return view
|
|
89
|
+
},
|
|
90
|
+
async load(): Promise<void> {
|
|
91
|
+
const hash = (o.hash ?? (() => location.hash))()
|
|
92
|
+
// A fragment that names a `state` is the hand-off coming back; anything else starts one.
|
|
93
|
+
if (!new URLSearchParams(hash.replace(/^#/, '')).has('state')) return begin()
|
|
94
|
+
const out = await session.completeHandoff(hash, o.handoffUrl)
|
|
95
|
+
if (out.ok) {
|
|
96
|
+
view = createPrivateView({
|
|
97
|
+
host: handedOffHost(),
|
|
98
|
+
client: () => client,
|
|
99
|
+
push: null,
|
|
100
|
+
siteName: o.siteName,
|
|
101
|
+
realtime: o.realtime === undefined ? createPrivateRealtime : o.realtime,
|
|
102
|
+
})
|
|
103
|
+
state.phase = 'open'
|
|
104
|
+
await view.load()
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
if (out.code === 'HANDOFF_REPEATED') state.phase = 'redirecting'
|
|
108
|
+
else if (out.code === 'HANDOFF_INVALID') state.phase = 'invalid'
|
|
109
|
+
else if (SIGN_IN_CODES.has(out.code)) state.phase = 'signIn'
|
|
110
|
+
else {
|
|
111
|
+
state.phase = 'failed'
|
|
112
|
+
state.code = out.code
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
reopen: begin,
|
|
116
|
+
dispose(): void {
|
|
117
|
+
view?.dispose()
|
|
118
|
+
session.close()
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
}
|