@minca/core 0.1.17 → 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/README.md +2 -1
- package/dist/files/space-files.d.ts +2 -2
- package/dist/files/space-files.d.ts.map +1 -1
- package/dist/files/space-files.js +7 -5
- package/dist/files/space-files.js.map +1 -1
- package/dist/inbox/names.d.ts +1 -1
- package/dist/inbox/names.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/node/actions.d.ts +3 -0
- package/dist/node/actions.d.ts.map +1 -1
- package/dist/node/actions.js.map +1 -1
- package/dist/node/api.d.ts +1 -0
- package/dist/node/api.d.ts.map +1 -1
- package/dist/node/api.js +1 -0
- package/dist/node/api.js.map +1 -1
- package/dist/node/carrier.js +1 -1
- package/dist/node/carrier.js.map +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/node-contacts.d.ts.map +1 -1
- package/dist/node/node-contacts.js +1 -0
- package/dist/node/node-contacts.js.map +1 -1
- package/dist/node/node-records.d.ts.map +1 -1
- package/dist/node/node-records.js +6 -1
- package/dist/node/node-records.js.map +1 -1
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +13 -1
- package/dist/node/node.js.map +1 -1
- package/dist/node/remote.d.ts.map +1 -1
- package/dist/node/remote.js +7 -1
- package/dist/node/remote.js.map +1 -1
- package/dist/node/space-runtime.d.ts +5 -3
- package/dist/node/space-runtime.d.ts.map +1 -1
- package/dist/node/space-runtime.js +3 -1
- package/dist/node/space-runtime.js.map +1 -1
- package/dist/node/types.d.ts +112 -36
- package/dist/node/types.d.ts.map +1 -1
- package/dist/node/watch-notifications.d.ts +6 -0
- package/dist/node/watch-notifications.d.ts.map +1 -1
- package/dist/node/watch-notifications.js +47 -9
- package/dist/node/watch-notifications.js.map +1 -1
- package/dist/query/types.d.ts +1 -0
- package/dist/query/types.d.ts.map +1 -1
- package/dist/query/types.js.map +1 -1
- package/dist/records/contract-builder.d.ts +22 -6
- package/dist/records/contract-builder.d.ts.map +1 -1
- package/dist/records/contract-builder.js.map +1 -1
- package/dist/schemas/automations.d.ts +6 -2
- package/dist/schemas/automations.d.ts.map +1 -1
- package/dist/schemas/automations.js.map +1 -1
- package/dist/schemas/connectors.d.ts +4 -3
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/connectors.js +4 -3
- package/dist/schemas/connectors.js.map +1 -1
- package/dist/schemas/library/media.js +1 -1
- package/dist/schemas/library/media.js.map +1 -1
- package/dist/session/account-hint.d.ts +2 -2
- package/dist/session/account-hint.d.ts.map +1 -1
- package/dist/session/account-hint.js +3 -3
- package/dist/session/account-hint.js.map +1 -1
- package/dist/session/auth.d.ts +7 -3
- package/dist/session/auth.d.ts.map +1 -1
- package/dist/session/auth.js.map +1 -1
- package/dist/session/connection.d.ts +18 -0
- package/dist/session/connection.d.ts.map +1 -1
- package/dist/session/connection.js +11 -0
- package/dist/session/connection.js.map +1 -1
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +2 -2
- package/dist/session/index.js.map +1 -1
- package/dist/storage/blob-store.d.ts +3 -0
- package/dist/storage/blob-store.d.ts.map +1 -1
- package/dist/types.d.ts +11 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/README.md +86 -93
- package/docs/actions.md +213 -152
- package/docs/agents.md +198 -167
- package/docs/automations.md +296 -204
- package/docs/blueprints-and-guides.md +405 -311
- package/docs/bots.md +208 -134
- package/docs/building-an-app.md +86 -159
- package/docs/collections.md +248 -328
- package/docs/computed.md +112 -89
- package/docs/contacts.md +151 -112
- package/docs/contracts.md +299 -120
- package/docs/direct-messages.md +80 -65
- package/docs/inbox.md +138 -93
- package/docs/node.md +1081 -996
- package/docs/permissions.md +142 -0
- package/docs/proposing-collections.md +74 -55
- package/docs/query-format.md +150 -126
- package/docs/records-and-queries.md +205 -126
- package/docs/sign-in.md +487 -416
- package/docs/spaces.md +261 -246
- package/docs/standard-library.md +487 -526
- package/docs/storage.md +325 -348
- package/docs/usernames.md +164 -97
- package/docs/warrants.md +100 -67
- package/package.json +1 -6
- package/dist/elements/auth-styles.d.ts +0 -18
- package/dist/elements/auth-styles.d.ts.map +0 -1
- package/dist/elements/auth-styles.js +0 -206
- package/dist/elements/auth-styles.js.map +0 -1
- package/dist/elements/dom.d.ts +0 -29
- package/dist/elements/dom.d.ts.map +0 -1
- package/dist/elements/dom.js +0 -91
- package/dist/elements/dom.js.map +0 -1
- package/dist/elements/index.d.ts +0 -13
- package/dist/elements/index.d.ts.map +0 -1
- package/dist/elements/index.js +0 -11
- package/dist/elements/index.js.map +0 -1
- package/dist/elements/minca-auth.d.ts +0 -55
- package/dist/elements/minca-auth.d.ts.map +0 -1
- package/dist/elements/minca-auth.js +0 -768
- package/dist/elements/minca-auth.js.map +0 -1
|
@@ -1,768 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module elements/minca-auth
|
|
3
|
-
* `<minca-auth>`: the whole sign-in flow as one element.
|
|
4
|
-
*
|
|
5
|
-
* ```html
|
|
6
|
-
* <minca-auth app-name="Todo" relays="wss://relay.example"></minca-auth>
|
|
7
|
-
* <script type="module">
|
|
8
|
-
* import '@minca/core/elements';
|
|
9
|
-
* document.querySelector('minca-auth').addEventListener('minca-session', (event) => {
|
|
10
|
-
* const session = event.detail.session; // null when signed out
|
|
11
|
-
* if (session) start(session.node);
|
|
12
|
-
* });
|
|
13
|
-
* </script>
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* Or hand it a flow you made yourself: `element.auth = createMincaAuth({ … })`.
|
|
17
|
-
* It draws into its light DOM, not a shadow root, because password managers
|
|
18
|
-
* fill forms there far more reliably; its styles are scoped to the element.
|
|
19
|
-
*/
|
|
20
|
-
import { createMincaAuth, } from '../session/auth.js';
|
|
21
|
-
import { accountCredentialName, offerToSave, recoveryKit } from '../session/credentials.js';
|
|
22
|
-
import { passwordStrength } from '../session/password-strength.js';
|
|
23
|
-
import { adHocName, formatUsername, nameFromUsername, parseUsername, usernameFree } from '../inbox/names.js';
|
|
24
|
-
import { adoptStyles, h, svg } from './dom.js';
|
|
25
|
-
import { AUTH_CSS } from './auth-styles.js';
|
|
26
|
-
/** How to give out Minca usernames at a domain of your own */
|
|
27
|
-
const OWN_DOMAIN_HELP = 'https://github.com/leifriksheim/minca/blob/main/packages/core/docs/usernames.md#running-one-for-your-domain';
|
|
28
|
-
// Where there is no DOM the module still loads; the element is only ever made where there is one.
|
|
29
|
-
const Base = globalThis.HTMLElement ?? class {
|
|
30
|
-
};
|
|
31
|
-
/** The mark and the name, above every step */
|
|
32
|
-
function wordmark() {
|
|
33
|
-
return h('div', { class: 'wa-wordmark' }, svg('<svg width="24" height="13" viewBox="0 0 24 13" aria-hidden="true"><path fill="#2340d6" d="M0.5 12.5A11.5 11.5 0 0 1 23.5 12.5H20.75A8.75 8.75 0 0 0 3.25 12.5Z"/><path fill="#ff6b4a" d="M3.25 12.5A8.75 8.75 0 0 1 20.75 12.5H18A6 6 0 0 0 6 12.5Z"/><path fill="#ffc46b" d="M6 12.5A6 6 0 0 1 18 12.5H15.25A3.25 3.25 0 0 0 8.75 12.5Z"/><path fill="#4e8f6c" d="M8.75 12.5A3.25 3.25 0 0 1 15.25 12.5Z"/></svg>'), 'minca');
|
|
34
|
-
}
|
|
35
|
-
/** A small deterministic hash, enough to seed a 5×5 pattern and a hue. */
|
|
36
|
-
function hash(text) {
|
|
37
|
-
let value = 2166136261;
|
|
38
|
-
for (let i = 0; i < text.length; i++) {
|
|
39
|
-
value ^= text.charCodeAt(i);
|
|
40
|
-
value = Math.imul(value, 16777619);
|
|
41
|
-
}
|
|
42
|
-
return value >>> 0;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* A visual fingerprint for an account, derived from its DID — the same
|
|
46
|
-
* everywhere it appears, so a wrong account is obvious before its name is read.
|
|
47
|
-
*/
|
|
48
|
-
function avatar(did, size = 32) {
|
|
49
|
-
const seed = hash(did);
|
|
50
|
-
const hue = seed % 360;
|
|
51
|
-
const cells = [];
|
|
52
|
-
for (let x = 0; x < 3; x++) {
|
|
53
|
-
for (let y = 0; y < 5; y++) {
|
|
54
|
-
if (((seed >> (x * 5 + y)) & 1) === 0)
|
|
55
|
-
continue;
|
|
56
|
-
cells.push(`<rect x="${x}" y="${y}" width="1" height="1"/>`);
|
|
57
|
-
if (x < 2)
|
|
58
|
-
cells.push(`<rect x="${4 - x}" y="${y}" width="1" height="1"/>`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return svg(`<svg class="wa-avatar" width="${size}" height="${size}" viewBox="0 0 5 5" role="img" aria-label="Account avatar" style="background:hsl(${hue} 46% 92%)"><g fill="hsl(${hue} 62% 48%)">${cells.join('')}</g></svg>`);
|
|
62
|
-
}
|
|
63
|
-
/** An explanation, folded away until asked for. */
|
|
64
|
-
function info(label, ...text) {
|
|
65
|
-
const popover = h('span', { class: 'wa-popover', role: 'note', hidden: true }, ...text);
|
|
66
|
-
const button = h('button', {
|
|
67
|
-
type: 'button',
|
|
68
|
-
class: 'wa-info-button',
|
|
69
|
-
'aria-label': label,
|
|
70
|
-
'aria-expanded': 'false',
|
|
71
|
-
onclick: () => {
|
|
72
|
-
popover.hidden = !popover.hidden;
|
|
73
|
-
button.setAttribute('aria-expanded', String(!popover.hidden));
|
|
74
|
-
},
|
|
75
|
-
onkeydown: (event) => {
|
|
76
|
-
if (event.key === 'Escape')
|
|
77
|
-
popover.hidden = true;
|
|
78
|
-
},
|
|
79
|
-
}, 'i');
|
|
80
|
-
return h('span', { class: 'wa-info' }, button, popover);
|
|
81
|
-
}
|
|
82
|
-
function errorBox(error) {
|
|
83
|
-
if (!error)
|
|
84
|
-
return null;
|
|
85
|
-
return h('div', { class: 'wa-error-box', role: 'alert' }, h('p', { class: 'wa-error' }, error.message), error.hint ? h('p', { class: 'wa-small' }, error.hint) : null);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* One choice in a list of them (`wa-options`). `name` marks it (`data-option`), so a page can give each
|
|
89
|
-
* kind its own icon in `.wa-option-icon`, which shows nothing unless the page draws one there.
|
|
90
|
-
*/
|
|
91
|
-
function option(name, title, text, onclick, disabled, recommended = false) {
|
|
92
|
-
return h('button', { type: 'button', class: 'wa-option', 'data-option': name, onclick, disabled }, h('span', { class: 'wa-option-icon', 'aria-hidden': 'true' }), h('span', { class: 'wa-option-body' }, h('span', { class: 'wa-option-title' }, title, recommended ? h('span', { class: 'wa-badge' }, 'Recommended') : null), h('span', { class: 'wa-option-text' }, text)));
|
|
93
|
-
}
|
|
94
|
-
function link(text, onclick, disabled = false) {
|
|
95
|
-
return h('button', { type: 'button', class: 'wa-link', onclick, disabled }, text);
|
|
96
|
-
}
|
|
97
|
-
function links(...children) {
|
|
98
|
-
return h('div', { class: 'wa-links' }, ...children);
|
|
99
|
-
}
|
|
100
|
-
/** A step: the mark, its title, and what goes under it */
|
|
101
|
-
function card(title, ...body) {
|
|
102
|
-
return h('div', { class: 'wa-card' }, wordmark(), h('h1', { class: 'wa-title' }, title), ...body);
|
|
103
|
-
}
|
|
104
|
-
function subtitle(...text) {
|
|
105
|
-
return h('p', { class: 'wa-subtitle' }, ...text);
|
|
106
|
-
}
|
|
107
|
-
/** How the username asked for at sign-up is going, above the setup screens that follow; at `domain`, by its name alone */
|
|
108
|
-
function claimLine({ username: claim }, domain) {
|
|
109
|
-
if (!claim)
|
|
110
|
-
return null;
|
|
111
|
-
const states = { claiming: 'checking', claimed: 'free', failed: 'taken' };
|
|
112
|
-
const shown = domain && claim.username.endsWith(`@${domain}`)
|
|
113
|
-
? claim.username.slice(0, -domain.length - 1)
|
|
114
|
-
: claim.username;
|
|
115
|
-
// The service's own words, without who refused what: the line says that already.
|
|
116
|
-
const why = (claim.error ?? 'the name service said no').replace(/^.* refused \S+: /, '');
|
|
117
|
-
return h('p', { class: 'wa-small', 'data-name': states[claim.status], 'aria-live': 'polite', style: 'margin:0 0 12px' }, claim.status === 'claiming'
|
|
118
|
-
? `Getting ${shown} for you…`
|
|
119
|
-
: claim.status === 'claimed'
|
|
120
|
-
? `${shown} is your username.`
|
|
121
|
-
: `${shown} couldn't be yours: ${why}. Pick another in any app, under Contacts.`);
|
|
122
|
-
}
|
|
123
|
-
/** A form that stays on the page when submitted */
|
|
124
|
-
function form(onSubmit, props, ...children) {
|
|
125
|
-
return h('form', {
|
|
126
|
-
class: 'wa-form',
|
|
127
|
-
...props,
|
|
128
|
-
onsubmit: (event) => {
|
|
129
|
-
event.preventDefault();
|
|
130
|
-
onSubmit();
|
|
131
|
-
},
|
|
132
|
-
}, ...children);
|
|
133
|
-
}
|
|
134
|
-
/** The step's one main button */
|
|
135
|
-
function button(label, onclick, disabled, key) {
|
|
136
|
-
return h('button', { type: 'button', class: 'wa-button', 'data-key': key, disabled, onclick }, label);
|
|
137
|
-
}
|
|
138
|
-
function submit(busy, label, busyLabel) {
|
|
139
|
-
return h('button', { type: 'submit', class: 'wa-button', disabled: busy }, busy ? busyLabel : label);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* The username a password manager files a credential under: off-screen but
|
|
143
|
-
* deliberately not `display: none`, which managers do not count as a username.
|
|
144
|
-
*/
|
|
145
|
-
function offscreenUsername(value, readonly) {
|
|
146
|
-
return h('input', {
|
|
147
|
-
type: 'text',
|
|
148
|
-
name: 'username',
|
|
149
|
-
autocomplete: 'username',
|
|
150
|
-
value,
|
|
151
|
-
readonly,
|
|
152
|
-
class: 'wa-offscreen',
|
|
153
|
-
tabindex: '-1',
|
|
154
|
-
'aria-hidden': 'true',
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
/** Hands the page a text file to save. */
|
|
158
|
-
function download({ filename, text }) {
|
|
159
|
-
const url = URL.createObjectURL(new Blob([text], { type: 'text/plain' }));
|
|
160
|
-
const anchor = h('a', { href: url, download: filename, style: 'display:none' });
|
|
161
|
-
globalThis.document.body.append(anchor);
|
|
162
|
-
anchor.click();
|
|
163
|
-
anchor.remove();
|
|
164
|
-
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
165
|
-
}
|
|
166
|
-
/** How a pairing is going, in a line: red once it failed */
|
|
167
|
-
function pairingLine(stage, quiet, style) {
|
|
168
|
-
return h('p', { class: stage.kind === 'failed' ? 'wa-error' : quiet, style }, describePairing(stage));
|
|
169
|
-
}
|
|
170
|
-
function describePairing(stage) {
|
|
171
|
-
switch (stage.kind) {
|
|
172
|
-
case 'waiting':
|
|
173
|
-
return 'Looking for your computer…';
|
|
174
|
-
case 'confirm':
|
|
175
|
-
case 'compare':
|
|
176
|
-
return 'Check your computer shows the same code, and confirm there.';
|
|
177
|
-
case 'sending':
|
|
178
|
-
return 'The codes matched. Setting up this phone…';
|
|
179
|
-
case 'joining':
|
|
180
|
-
return `Adding your spaces: ${stage.joined} of ${stage.total}…`;
|
|
181
|
-
case 'received':
|
|
182
|
-
return stage.spaces === 1 ? 'Added 1 space.' : `Added ${stage.spaces} spaces.`;
|
|
183
|
-
case 'sent':
|
|
184
|
-
return 'Done.';
|
|
185
|
-
case 'failed':
|
|
186
|
-
return stage.reason;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
export class MincaAuthElement extends Base {
|
|
190
|
-
#auth = null;
|
|
191
|
-
#unsubscribe = null;
|
|
192
|
-
#announced = undefined;
|
|
193
|
-
// What only this element cares about: which fold is open, what is typed.
|
|
194
|
-
#drafts = new Map();
|
|
195
|
-
#filledAs = '';
|
|
196
|
-
#copied = false;
|
|
197
|
-
#stored = false;
|
|
198
|
-
#choosingPassword = false;
|
|
199
|
-
#showPairHelp = false;
|
|
200
|
-
#mismatch = false;
|
|
201
|
-
/** With a passkey too, whether the password was asked for rather than the passkey */
|
|
202
|
-
#withPassword = false;
|
|
203
|
-
#lastSelected = null;
|
|
204
|
-
#lastStage = null;
|
|
205
|
-
/** The username on the create screen, and whether it is free */
|
|
206
|
-
#username = {
|
|
207
|
-
checked: '',
|
|
208
|
-
state: 'empty',
|
|
209
|
-
};
|
|
210
|
-
#usernameTimer;
|
|
211
|
-
/** The flow this element draws. Set it to share one with the rest of the page; otherwise one is made from the attributes. */
|
|
212
|
-
get auth() {
|
|
213
|
-
this.#auth ??= createMincaAuth({
|
|
214
|
-
...(this.getAttribute('app-name') ? { appName: this.getAttribute('app-name') } : {}),
|
|
215
|
-
network: { relays: this.#urls('relays'), nodes: this.#urls('nodes') },
|
|
216
|
-
});
|
|
217
|
-
return this.#auth;
|
|
218
|
-
}
|
|
219
|
-
/** A comma-separated attribute's addresses */
|
|
220
|
-
#urls(name) {
|
|
221
|
-
return (this.getAttribute(name) ?? '')
|
|
222
|
-
.split(',')
|
|
223
|
-
.map((url) => url.trim())
|
|
224
|
-
.filter(Boolean);
|
|
225
|
-
}
|
|
226
|
-
set auth(auth) {
|
|
227
|
-
if (auth === this.#auth)
|
|
228
|
-
return;
|
|
229
|
-
this.#auth = auth;
|
|
230
|
-
if (this.isConnected)
|
|
231
|
-
this.#follow();
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Draws an account's avatar from its DID, round or not. A page that shows
|
|
235
|
-
* accounts its own way sets this, so an account looks the same here as
|
|
236
|
-
* everywhere else on it; otherwise a simple one is drawn.
|
|
237
|
-
*/
|
|
238
|
-
get avatar() {
|
|
239
|
-
return this.#avatar;
|
|
240
|
-
}
|
|
241
|
-
set avatar(draw) {
|
|
242
|
-
this.#avatar = draw;
|
|
243
|
-
if (this.isConnected)
|
|
244
|
-
this.#redraw();
|
|
245
|
-
}
|
|
246
|
-
#avatar = null;
|
|
247
|
-
/** `round` inside something round already (a pill row), where corners would fight it */
|
|
248
|
-
#drawAvatar(did, size = 32, round = false) {
|
|
249
|
-
const drawn = this.#avatar?.(did, size, round) ?? avatar(did, size);
|
|
250
|
-
drawn.classList.add('wa-avatar');
|
|
251
|
-
if (round)
|
|
252
|
-
drawn.classList.add('wa-avatar-round');
|
|
253
|
-
return drawn;
|
|
254
|
-
}
|
|
255
|
-
connectedCallback() {
|
|
256
|
-
adoptStyles('minca-auth', AUTH_CSS);
|
|
257
|
-
if (this.#auth) {
|
|
258
|
-
this.#follow();
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
// A framework may set `auth` just after inserting the element; wait a
|
|
262
|
-
// moment before making one from the attributes instead.
|
|
263
|
-
queueMicrotask(() => {
|
|
264
|
-
if (this.isConnected && !this.#unsubscribe)
|
|
265
|
-
this.#follow();
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
disconnectedCallback() {
|
|
269
|
-
this.#unsubscribe?.();
|
|
270
|
-
this.#unsubscribe = null;
|
|
271
|
-
}
|
|
272
|
-
#follow() {
|
|
273
|
-
this.#unsubscribe?.();
|
|
274
|
-
const auth = this.auth;
|
|
275
|
-
this.#unsubscribe = auth.subscribe((state) => this.#changed(state));
|
|
276
|
-
this.#changed(auth.getState());
|
|
277
|
-
void auth.start();
|
|
278
|
-
}
|
|
279
|
-
#changed(state) {
|
|
280
|
-
// A new account row, or a new screen, starts with empty fields.
|
|
281
|
-
if (state.selectedId !== this.#lastSelected || state.stage !== this.#lastStage) {
|
|
282
|
-
this.#lastSelected = state.selectedId;
|
|
283
|
-
this.#lastStage = state.stage;
|
|
284
|
-
this.#reset();
|
|
285
|
-
}
|
|
286
|
-
this.#render(state);
|
|
287
|
-
const session = state.stage === 'ready' ? state.session : null;
|
|
288
|
-
if (session !== this.#announced) {
|
|
289
|
-
this.#announced = session;
|
|
290
|
-
this.dispatchEvent(new CustomEvent('minca-session', {
|
|
291
|
-
detail: { session },
|
|
292
|
-
bubbles: true,
|
|
293
|
-
composed: true,
|
|
294
|
-
}));
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
#reset() {
|
|
298
|
-
this.#drafts.clear();
|
|
299
|
-
clearTimeout(this.#usernameTimer);
|
|
300
|
-
this.#username = { checked: '', state: 'empty' };
|
|
301
|
-
this.#filledAs = '';
|
|
302
|
-
this.#copied = false;
|
|
303
|
-
this.#stored = false;
|
|
304
|
-
this.#choosingPassword = false;
|
|
305
|
-
this.#showPairHelp = false;
|
|
306
|
-
this.#mismatch = false;
|
|
307
|
-
this.#withPassword = false;
|
|
308
|
-
}
|
|
309
|
-
#redraw() {
|
|
310
|
-
this.#render(this.auth.getState());
|
|
311
|
-
}
|
|
312
|
-
/** Redraws, keeping focus and what was typed. */
|
|
313
|
-
#render(state) {
|
|
314
|
-
const active = globalThis.document.activeElement;
|
|
315
|
-
const focused = active instanceof HTMLElement && this.contains(active) ? active.dataset.key : undefined;
|
|
316
|
-
this.replaceChildren(...this.#screen(state));
|
|
317
|
-
const again = focused
|
|
318
|
-
? this.querySelector(`[data-key="${focused}"]`)
|
|
319
|
-
: this.querySelector('[autofocus]');
|
|
320
|
-
again?.focus();
|
|
321
|
-
}
|
|
322
|
-
/** An input that survives a redraw */
|
|
323
|
-
#input(key, props) {
|
|
324
|
-
const input = h('input', {
|
|
325
|
-
...props,
|
|
326
|
-
'data-key': key,
|
|
327
|
-
value: this.#drafts.get(key) ?? props.value ?? '',
|
|
328
|
-
oninput: () => this.#drafts.set(key, input.value),
|
|
329
|
-
});
|
|
330
|
-
return input;
|
|
331
|
-
}
|
|
332
|
-
#screen(state) {
|
|
333
|
-
switch (state.stage) {
|
|
334
|
-
case 'ready':
|
|
335
|
-
return [];
|
|
336
|
-
case 'starting':
|
|
337
|
-
return [
|
|
338
|
-
h('div', { class: 'wa-card' }, h('p', { class: 'wa-hint' }, state.signingOut ? 'Signing out…' : 'Looking for your accounts…')),
|
|
339
|
-
];
|
|
340
|
-
case 'pair':
|
|
341
|
-
return [this.#pair(state)];
|
|
342
|
-
case 'create':
|
|
343
|
-
return [this.#create(state)];
|
|
344
|
-
case 'recovery':
|
|
345
|
-
return [this.#recovery(state)];
|
|
346
|
-
case 'unlock':
|
|
347
|
-
return [this.#unlock(state)];
|
|
348
|
-
case 'pod':
|
|
349
|
-
return [this.#pod(state)];
|
|
350
|
-
case 'welcome':
|
|
351
|
-
return [this.#welcome(state)];
|
|
352
|
-
case 'existing':
|
|
353
|
-
return [this.#existing(state)];
|
|
354
|
-
case 'restore':
|
|
355
|
-
return [this.#restore(state)];
|
|
356
|
-
case 'signIn':
|
|
357
|
-
return [this.#signIn(state)];
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
/** Where accounts are read from, shown only when it is a pod — a new person should not have to think about it. */
|
|
361
|
-
#podLine(state) {
|
|
362
|
-
const place = state.place;
|
|
363
|
-
if (place?.kind !== 'folder')
|
|
364
|
-
return null;
|
|
365
|
-
return h('p', { class: 'wa-small', style: 'margin-top:24px' }, `Pod: ${place.directory?.name ?? 'your folder'} · `, link('Use this browser instead', () => void this.auth.useBrowser(), state.busy));
|
|
366
|
-
}
|
|
367
|
-
// ─── New here, or not ──────────────────────────────────────────────
|
|
368
|
-
#welcome(state) {
|
|
369
|
-
const auth = this.auth;
|
|
370
|
-
return card('Welcome to Minca', subtitle('One account for every Minca app.'), h('div', { class: 'wa-options' }, option('create', 'Create an account', 'Takes a minute.', () => auth.startCreating(), state.busy), option('existing', 'I already have one', 'Sign in, or bring it to this device.', () => auth.showExisting(), state.busy)), errorBox(state.error), this.#podLine(state));
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* "I already have an account", from a place that does not list it. Where the
|
|
374
|
-
* data lives comes up here and only here: someone with a pod has something to
|
|
375
|
-
* point at, and someone without one has other ways in. A pod opened here
|
|
376
|
-
* before is first, to open again.
|
|
377
|
-
*/
|
|
378
|
-
#existing(state) {
|
|
379
|
-
const auth = this.auth;
|
|
380
|
-
return card('Find your account', subtitle('Any of these gets you in.'), h('div', { class: 'wa-options' }, state.podToReopen && state.folderAvailable
|
|
381
|
-
? option('reopen', `Open “${state.podToReopen}” again`, 'The browser asks once more.', () => void auth.reopenPod(), state.busy)
|
|
382
|
-
: null, state.folderAvailable
|
|
383
|
-
? option('pod', 'Open your pod', 'The folder your account is kept in.', () => void auth.choosePod(), state.busy)
|
|
384
|
-
: null, option('pair', 'Add this device from another', 'Scan a code on a device you’re signed in on.', () => {
|
|
385
|
-
this.#showPairHelp = !this.#showPairHelp;
|
|
386
|
-
this.#redraw();
|
|
387
|
-
}, state.busy), this.#showPairHelp
|
|
388
|
-
? h('ol', { class: 'wa-steps' }, h('li', null, 'On the signed-in device, open your account page.'), h('li', null, 'Choose ', h('strong', null, 'Add your phone'), ' and show the pairing code.'), h('li', null, "Scan it with this device's camera and open the link."))
|
|
389
|
-
: null, option('code', 'Use your recovery code', 'The code you kept when you made it.', () => auth.showRestore(), state.busy)), errorBox(state.error), links(link('Back', () => (state.accounts.length > 0 ? auth.showSignIn() : auth.showWelcome()), state.busy), link('Create a new account instead', () => auth.startCreating(), state.busy)), this.#podLine(state));
|
|
390
|
-
}
|
|
391
|
-
// ─── Choosing an account, and getting in ───────────────────────────
|
|
392
|
-
/**
|
|
393
|
-
* The recovery-code form. A password form, because before passwords the
|
|
394
|
-
* recovery code was this site's login and many managers hold it that way.
|
|
395
|
-
* Its username is writable: a manager fills the whole credential at once,
|
|
396
|
-
* and letting it overwrite the name is what makes a mismatch detectable.
|
|
397
|
-
*/
|
|
398
|
-
#codeForm(state, selected) {
|
|
399
|
-
const username = offscreenUsername(accountCredentialName(selected?.name ?? 'My account'), false);
|
|
400
|
-
const code = this.#input('code', {
|
|
401
|
-
type: 'password',
|
|
402
|
-
name: 'password',
|
|
403
|
-
placeholder: 'XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XX',
|
|
404
|
-
autocomplete: 'current-password',
|
|
405
|
-
spellcheck: 'false',
|
|
406
|
-
autofocus: true,
|
|
407
|
-
'aria-label': 'Recovery code',
|
|
408
|
-
disabled: state.busy,
|
|
409
|
-
});
|
|
410
|
-
// Autofill sets the DOM value directly; read what it filled as well.
|
|
411
|
-
code.addEventListener('input', () => {
|
|
412
|
-
const filled = username.value.trim();
|
|
413
|
-
if (filled !== this.#filledAs) {
|
|
414
|
-
this.#filledAs = filled;
|
|
415
|
-
this.#redraw();
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
const wrong = selected !== null && this.#filledAs !== '' && this.#filledAs !== accountCredentialName(selected.name);
|
|
419
|
-
return [
|
|
420
|
-
form(() => {
|
|
421
|
-
const value = code.value.trim();
|
|
422
|
-
if (value)
|
|
423
|
-
void this.auth.signInWithCode(value);
|
|
424
|
-
}, {}, username, code, submit(state.busy, 'Continue', 'Opening…')),
|
|
425
|
-
wrong
|
|
426
|
-
? h('p', { class: 'wa-error', style: 'margin-top:10px' }, 'Your password manager filled ', h('strong', null, this.#filledAs), ', not ', h('strong', null, selected.name), '. Pick the entry named ', h('strong', null, selected.name), ', or open that account instead.')
|
|
427
|
-
: null,
|
|
428
|
-
].filter((node) => node !== null);
|
|
429
|
-
}
|
|
430
|
-
/** The everyday password, filed under the account's name so a manager fills the right one. */
|
|
431
|
-
#passwordForm(state, account) {
|
|
432
|
-
const password = this.#input('password', {
|
|
433
|
-
type: 'password',
|
|
434
|
-
name: 'password',
|
|
435
|
-
placeholder: 'Password',
|
|
436
|
-
autocomplete: 'current-password',
|
|
437
|
-
'aria-label': 'Password',
|
|
438
|
-
disabled: state.busy,
|
|
439
|
-
});
|
|
440
|
-
return form(() => {
|
|
441
|
-
if (password.value)
|
|
442
|
-
void this.auth.signInWithPassword(password.value);
|
|
443
|
-
}, {}, offscreenUsername(accountCredentialName(account.name), true), password, submit(state.busy, 'Sign in', 'Signing in…'));
|
|
444
|
-
}
|
|
445
|
-
#signIn(state) {
|
|
446
|
-
const auth = this.auth;
|
|
447
|
-
const { accounts, entry, place } = state;
|
|
448
|
-
const selected = accounts.find((account) => account.id === state.selectedId) ?? null;
|
|
449
|
-
/** The ways into the open account: one main button, the rest set back */
|
|
450
|
-
const waysIn = (account, open) => {
|
|
451
|
-
const hasPasskey = open.shortcuts.length > 0;
|
|
452
|
-
// An account with wraps, none of them usable here, has been used on
|
|
453
|
-
// another site — a passkey works on one web address only.
|
|
454
|
-
const seenElsewhere = open.vault.wraps.length > 0;
|
|
455
|
-
if (!hasPasskey && !open.hasPassword)
|
|
456
|
-
return [
|
|
457
|
-
h('p', { class: 'wa-small', style: 'margin:0 0 10px' }, 'No passkey or password here yet. Use your recovery code once, then choose one.', info('Why it is asking for the recovery code', seenElsewhere
|
|
458
|
-
? 'This account’s passkeys belong to the sites that made them — a passkey works on one web address only. The recovery code opens it anywhere.'
|
|
459
|
-
: 'The recovery code opens the account anywhere, with nothing stored. Next you set up a passkey or password so it stops asking.')),
|
|
460
|
-
...this.#codeForm(state, selected),
|
|
461
|
-
];
|
|
462
|
-
// One way in at a time: the passkey, with the password a tap away when there is one too.
|
|
463
|
-
const byPassword = open.hasPassword && (!hasPasskey || this.#withPassword);
|
|
464
|
-
const toggle = (to) => () => {
|
|
465
|
-
this.#withPassword = to;
|
|
466
|
-
this.#redraw();
|
|
467
|
-
};
|
|
468
|
-
return [
|
|
469
|
-
byPassword
|
|
470
|
-
? this.#passwordForm(state, account)
|
|
471
|
-
: button(state.busy ? 'Waiting…' : 'Sign in with passkey', () => void auth.signInWithPasskey(), state.busy, 'passkey'),
|
|
472
|
-
hasPasskey && open.hasPassword
|
|
473
|
-
? h('p', { class: 'wa-small', style: 'margin-top:12px' }, link(byPassword ? 'Use your passkey instead' : 'Use your password instead', toggle(!byPassword), state.busy))
|
|
474
|
-
: null,
|
|
475
|
-
h('p', { class: 'wa-small', style: hasPasskey && open.hasPassword ? 'margin-top:4px' : 'margin-top:12px' }, open.hasPassword ? 'Forgot it? ' : null, link(open.hasPassword ? 'Use your recovery code' : 'Use your recovery code instead', () => auth.showRestore(), state.busy)),
|
|
476
|
-
];
|
|
477
|
-
};
|
|
478
|
-
// The one being signed in to first, then the rest to switch to.
|
|
479
|
-
const ordered = [...accounts].sort((a, b) => Number(b.id === state.selectedId) - Number(a.id === state.selectedId));
|
|
480
|
-
const rows = ordered.map((account) => {
|
|
481
|
-
const isOpen = account.id === state.selectedId && entry !== null;
|
|
482
|
-
if (isOpen)
|
|
483
|
-
return h('div', { class: 'wa-account wa-account-open' }, h('div', { class: 'wa-account-head' }, this.#drawAvatar(account.did, 48, true), h('span', { class: 'wa-account-name' }, account.name)), ...waysIn(account, entry));
|
|
484
|
-
return h('button', {
|
|
485
|
-
type: 'button',
|
|
486
|
-
class: 'wa-account wa-account-row',
|
|
487
|
-
disabled: state.busy,
|
|
488
|
-
onclick: () => void auth.select(account.id),
|
|
489
|
-
}, this.#drawAvatar(account.did, 32, true), h('span', { class: 'wa-account-name', style: 'flex:1;min-width:0' }, account.name), h('span', { class: 'wa-chevron', 'aria-hidden': 'true' }, '›'));
|
|
490
|
-
});
|
|
491
|
-
const one = accounts.length === 1 ? accounts[0] : undefined;
|
|
492
|
-
return card('Welcome back',
|
|
493
|
-
// With one account its name is under its face already, so the line above it doesn't say it again.
|
|
494
|
-
subtitle(one
|
|
495
|
-
? 'Sign in to continue.'
|
|
496
|
-
: accounts.length > 0
|
|
497
|
-
? 'Choose your account.'
|
|
498
|
-
: 'There are no accounts here yet.'), h('div', { class: 'wa-accounts' }, ...rows), errorBox(state.error), h('div', { class: 'wa-footer' }, links(link('Another account', () => auth.showExisting(), state.busy), link('Create a new account', () => auth.startCreating(), state.busy)), place
|
|
499
|
-
? h('p', { class: 'wa-small', style: 'margin-top:4px' }, place.kind === 'folder'
|
|
500
|
-
? `Accounts in the folder “${place.directory?.name ?? 'your pod'}”`
|
|
501
|
-
: 'Accounts kept in this browser', state.folderAvailable ? ' · ' : null, state.folderAvailable
|
|
502
|
-
? link(place.kind === 'folder' ? 'Open another folder' : 'Open a folder', () => void auth.choosePod(), state.busy)
|
|
503
|
-
: null, state.folderAvailable && place.kind === 'folder'
|
|
504
|
-
? link('Use this browser', () => void auth.useBrowser(), state.busy)
|
|
505
|
-
: null)
|
|
506
|
-
: null));
|
|
507
|
-
}
|
|
508
|
-
/** The recovery code, typed in: on a new device, or when no everyday way in is to hand. */
|
|
509
|
-
#restore(state) {
|
|
510
|
-
const auth = this.auth;
|
|
511
|
-
const selected = state.accounts.find((account) => account.id === state.selectedId) ?? null;
|
|
512
|
-
// From the account list it restores that account; from "I already have one", any.
|
|
513
|
-
const forSelected = selected !== null && state.accounts.length > 0 && state.entry !== null;
|
|
514
|
-
return card('Use your recovery code', subtitle(forSelected ? `For ${selected.name}. ` : '', 'The 26-character code you kept when you made the account.'), ...this.#codeForm(state, forSelected ? selected : null), errorBox(state.error), links(link('Back', () => (state.accounts.length > 0 ? auth.showSignIn() : auth.showExisting()), state.busy)), h('p', { class: 'wa-small', style: 'margin-top:16px' }, "Lost it? If you're signed in on another device, add this one from there instead."));
|
|
515
|
-
}
|
|
516
|
-
// ─── Making an account ─────────────────────────────────────────────
|
|
517
|
-
#create(state) {
|
|
518
|
-
const auth = this.auth;
|
|
519
|
-
const domain = auth.usernames;
|
|
520
|
-
if (!domain) {
|
|
521
|
-
const name = this.#input('name', {
|
|
522
|
-
type: 'text',
|
|
523
|
-
placeholder: 'Your name',
|
|
524
|
-
autocomplete: 'off',
|
|
525
|
-
autofocus: true,
|
|
526
|
-
disabled: state.busy,
|
|
527
|
-
'aria-label': 'Your name',
|
|
528
|
-
});
|
|
529
|
-
return card('Create your account', subtitle('What should apps call you? You can change it later.'), form(() => {
|
|
530
|
-
if (name.value.trim())
|
|
531
|
-
void auth.createAccount(name.value.trim());
|
|
532
|
-
}, {}, name, submit(state.busy, 'Continue', 'Creating…')), errorBox(state.error), links(link('I already have an account', () => auth.showExisting(), state.busy)), this.#podLine(state));
|
|
533
|
-
}
|
|
534
|
-
const busy = state.busy;
|
|
535
|
-
const username = this.#input('username', {
|
|
536
|
-
type: 'text',
|
|
537
|
-
placeholder: 'yourname',
|
|
538
|
-
autocomplete: 'off',
|
|
539
|
-
autocapitalize: 'none',
|
|
540
|
-
spellcheck: 'false',
|
|
541
|
-
maxlength: '320',
|
|
542
|
-
autofocus: true,
|
|
543
|
-
disabled: busy,
|
|
544
|
-
'aria-label': 'Username',
|
|
545
|
-
});
|
|
546
|
-
// The whole username: as typed when it names a domain of its own, else at this home's.
|
|
547
|
-
const typedName = () => username.value.trim().toLowerCase();
|
|
548
|
-
const fullName = (typed) => (typed.includes('@') ? typed : `${typed}@${domain}`);
|
|
549
|
-
const status = h('p', { class: 'wa-small wa-under', 'aria-live': 'polite' });
|
|
550
|
-
// In the field: a tick once it is free, a cross once it is taken.
|
|
551
|
-
const mark = h('span', { class: 'wa-mark', 'aria-hidden': 'true' });
|
|
552
|
-
const show = () => {
|
|
553
|
-
const { state: now } = this.#username;
|
|
554
|
-
const typed = typedName();
|
|
555
|
-
const own = typed.includes('@') ? (parseUsername(typed)?.domain ?? null) : null;
|
|
556
|
-
mark.dataset.name = status.dataset.name = now;
|
|
557
|
-
mark.textContent = now === 'free' ? '✓' : now === 'taken' ? '✕' : '';
|
|
558
|
-
if (now === 'unknown' && own)
|
|
559
|
-
return status.replaceChildren(`${own} doesn't give out Minca usernames yet. `, h('a', { href: OWN_DOMAIN_HELP, target: '_blank', rel: 'noopener' }, 'Set it up'));
|
|
560
|
-
status.textContent =
|
|
561
|
-
now === 'taken'
|
|
562
|
-
? 'Someone has that one. Try another.'
|
|
563
|
-
: now === 'invalid'
|
|
564
|
-
? typed.endsWith('@')
|
|
565
|
-
? 'Your domain, like you@yourname.com.'
|
|
566
|
-
: 'Letters, numbers, dots, dashes and underscores.'
|
|
567
|
-
: now === 'unknown'
|
|
568
|
-
? "Couldn't check it just now. It's tried when you continue."
|
|
569
|
-
: own && now === 'free'
|
|
570
|
-
? `Free at ${own}.`
|
|
571
|
-
: 'How people find you and add you. You can change it later.';
|
|
572
|
-
};
|
|
573
|
-
// Looks the name up a moment after typing stops.
|
|
574
|
-
const check = () => {
|
|
575
|
-
clearTimeout(this.#usernameTimer);
|
|
576
|
-
const typed = typedName();
|
|
577
|
-
const parsed = typed ? parseUsername(fullName(typed)) : null;
|
|
578
|
-
this.#username = { checked: typed, state: !typed ? 'empty' : parsed ? 'checking' : 'invalid' };
|
|
579
|
-
show();
|
|
580
|
-
if (!parsed)
|
|
581
|
-
return;
|
|
582
|
-
this.#usernameTimer = setTimeout(() => {
|
|
583
|
-
void usernameFree(formatUsername(parsed)).then((free) => {
|
|
584
|
-
if (this.#username.checked !== typed)
|
|
585
|
-
return;
|
|
586
|
-
this.#username.state = free === null ? 'unknown' : free ? 'free' : 'taken';
|
|
587
|
-
show();
|
|
588
|
-
});
|
|
589
|
-
}, 300);
|
|
590
|
-
};
|
|
591
|
-
username.addEventListener('input', check);
|
|
592
|
-
show();
|
|
593
|
-
// No username, so nobody finds the account by one: a name to show until it is given its own.
|
|
594
|
-
const skip = () => void auth.createAccount(adHocName());
|
|
595
|
-
return card('Pick a username', subtitle('Free, and yours. No email or phone number needed.'), form(() => {
|
|
596
|
-
const typed = typedName();
|
|
597
|
-
const { state: now } = this.#username;
|
|
598
|
-
if (!typed || now === 'taken' || now === 'invalid' || now === 'checking')
|
|
599
|
-
return;
|
|
600
|
-
void auth.createAccount(nameFromUsername(typed.split('@')[0]), { username: fullName(typed) });
|
|
601
|
-
}, {}, h('div', { class: 'wa-username' }, username, mark), status, submit(busy, 'Continue', 'Creating…')), errorBox(state.error), links(link('Continue without a username', skip, busy), link('I already have an account', () => auth.showExisting(), busy)), this.#podLine(state));
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* The recovery code, to keep.
|
|
605
|
-
*
|
|
606
|
-
* Deliberately not a password form: saved as this site's login, a manager
|
|
607
|
-
* would later offer it in the everyday password field — and replace it with
|
|
608
|
-
* that password when one is set, losing the only copy. So it is copied or
|
|
609
|
-
* downloaded, and kept as a note or on paper.
|
|
610
|
-
*/
|
|
611
|
-
#recovery(state) {
|
|
612
|
-
const auth = this.auth;
|
|
613
|
-
const code = state.freshCode ?? '';
|
|
614
|
-
const account = state.session?.account;
|
|
615
|
-
return card('Your recovery code', claimLine(state, this.auth.usernames), h('p', { class: 'wa-hint' }, 'This code is your account. With it you can restore your account on any device, even if you lose everything else.', info('Why it matters', 'Nobody can reissue it: there is no server that knows your account. Anyone who has it can open your account, so keep it private. ', 'Save it as a secure note in your password manager, or print it and put it away — not as a login for this site, where a new password could replace it.')), h('code', { class: 'wa-code wa-code-large' }, code), h('div', { class: 'wa-row' }, h('button', {
|
|
616
|
-
type: 'button',
|
|
617
|
-
class: 'wa-secondary',
|
|
618
|
-
onclick: () => {
|
|
619
|
-
void globalThis.navigator.clipboard
|
|
620
|
-
?.writeText(code)
|
|
621
|
-
.then(() => {
|
|
622
|
-
this.#copied = true;
|
|
623
|
-
this.#redraw();
|
|
624
|
-
})
|
|
625
|
-
.catch(() => { });
|
|
626
|
-
},
|
|
627
|
-
}, this.#copied ? 'Copied' : 'Copy'), h('button', {
|
|
628
|
-
type: 'button',
|
|
629
|
-
class: 'wa-secondary',
|
|
630
|
-
onclick: () => download(recoveryKit({ code, name: account?.name ?? 'My account', did: state.session?.did ?? '' })),
|
|
631
|
-
}, 'Download')), h('label', { class: 'wa-check' }, h('input', {
|
|
632
|
-
type: 'checkbox',
|
|
633
|
-
checked: this.#stored,
|
|
634
|
-
onchange: (event) => {
|
|
635
|
-
if (event.target instanceof HTMLInputElement)
|
|
636
|
-
this.#stored = event.target.checked;
|
|
637
|
-
this.#redraw();
|
|
638
|
-
},
|
|
639
|
-
}), h('span', null, "I've stored my recovery code somewhere safe.")), button('Continue', () => auth.codeSaved(), !this.#stored));
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* How this account is opened every day. Not skippable: without one, every
|
|
643
|
-
* visit asks for the recovery code, and it ends up being used as a password
|
|
644
|
-
* after all.
|
|
645
|
-
*/
|
|
646
|
-
#unlock(state) {
|
|
647
|
-
const auth = this.auth;
|
|
648
|
-
const account = state.session?.account;
|
|
649
|
-
const passkeys = typeof globalThis.PublicKeyCredential !== 'undefined';
|
|
650
|
-
const choosing = this.#choosingPassword || !passkeys;
|
|
651
|
-
const passwordForm = () => {
|
|
652
|
-
const password = this.#input('new-password', {
|
|
653
|
-
type: 'password',
|
|
654
|
-
name: 'password',
|
|
655
|
-
placeholder: 'Password',
|
|
656
|
-
autocomplete: 'new-password',
|
|
657
|
-
autofocus: true,
|
|
658
|
-
'aria-label': 'Password',
|
|
659
|
-
'aria-describedby': 'wa-strength',
|
|
660
|
-
disabled: state.busy,
|
|
661
|
-
});
|
|
662
|
-
// How strong it is, as it is typed: a warning, never a refusal.
|
|
663
|
-
const meter = h('div', { class: 'wa-meter', 'aria-hidden': 'true' }, h('span'), h('span'), h('span'));
|
|
664
|
-
const strength = h('p', { id: 'wa-strength', class: 'wa-small', 'aria-live': 'polite' });
|
|
665
|
-
const measure = () => {
|
|
666
|
-
const check = passwordStrength(password.value);
|
|
667
|
-
meter.dataset.strength = password.value ? check.strength : '';
|
|
668
|
-
strength.dataset.strength = password.value ? check.strength : '';
|
|
669
|
-
strength.textContent = check.hint || 'Any password works. A password manager can make a strong one.';
|
|
670
|
-
};
|
|
671
|
-
password.addEventListener('input', measure);
|
|
672
|
-
measure();
|
|
673
|
-
const confirm = this.#input('confirm-password', {
|
|
674
|
-
type: 'password',
|
|
675
|
-
name: 'confirm-password',
|
|
676
|
-
placeholder: 'The same again',
|
|
677
|
-
autocomplete: 'new-password',
|
|
678
|
-
'aria-label': 'Confirm password',
|
|
679
|
-
disabled: state.busy,
|
|
680
|
-
});
|
|
681
|
-
return form(() => {
|
|
682
|
-
this.#mismatch = password.value !== confirm.value;
|
|
683
|
-
if (this.#mismatch) {
|
|
684
|
-
this.#redraw();
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
const chosen = password.value;
|
|
688
|
-
const filedAs = accountCredentialName(account?.name ?? 'My account');
|
|
689
|
-
void auth.setPassword(chosen).then((ok) => (ok ? offerToSave(filedAs, chosen, filedAs) : false));
|
|
690
|
-
}, { style: passkeys ? 'margin-top:12px' : '' },
|
|
691
|
-
// A visible username is what makes a manager file the password under the account's name.
|
|
692
|
-
h('input', {
|
|
693
|
-
type: 'text',
|
|
694
|
-
name: 'username',
|
|
695
|
-
autocomplete: 'username',
|
|
696
|
-
value: accountCredentialName(account?.name ?? 'My account'),
|
|
697
|
-
readonly: true,
|
|
698
|
-
'aria-label': 'Account',
|
|
699
|
-
}), password, meter, strength, confirm, this.#mismatch ? h('p', { class: 'wa-error' }, 'Those two do not match.') : null, submit(state.busy, 'Use this password', 'Saving…'));
|
|
700
|
-
};
|
|
701
|
-
return card('How do you want to sign in?', claimLine(state, this.auth.usernames), subtitle('This is what you will use every day.', info('Where it works', 'A passkey signs you in on this site, in this browser. A password works wherever your account is kept — this browser, or your pod in any app pointed at it. On a new device, add it from this one or use your recovery code.')), h('div', { class: 'wa-options' }, passkeys
|
|
702
|
-
? option('passkey', 'Passkey', 'Touch ID, Windows Hello, or your password manager. Nothing to type.', () => void auth.addPasskey(), state.busy, true)
|
|
703
|
-
: null, passkeys && !choosing
|
|
704
|
-
? option('password', 'Password', 'Saved in your password manager, like any other login.', () => {
|
|
705
|
-
this.#choosingPassword = true;
|
|
706
|
-
this.#redraw();
|
|
707
|
-
}, state.busy)
|
|
708
|
-
: null), choosing ? passwordForm() : null,
|
|
709
|
-
// The code was typed into a password field: saved as this site's login, the password set now would replace it.
|
|
710
|
-
state.setup === 'restored'
|
|
711
|
-
? h('p', { class: 'wa-small', style: 'margin-top:16px' }, 'If your browser offered to save the recovery code as a password, don’t — the password you set now would replace it. Keep the code where you had it.')
|
|
712
|
-
: null, state.setup === 'paired' && state.pairingStage
|
|
713
|
-
? pairingLine(state.pairingStage, 'wa-small', 'margin-top:16px')
|
|
714
|
-
: null,
|
|
715
|
-
// The app waits in the tab it opened; the camera opened this one.
|
|
716
|
-
state.setup === 'paired'
|
|
717
|
-
? h('p', { class: 'wa-small' }, 'If an app sent you to sign in, you can go back to it now.')
|
|
718
|
-
: null, errorBox(state.error));
|
|
719
|
-
}
|
|
720
|
-
/** Offered once, at the end of making an account in a browser that can open a folder. */
|
|
721
|
-
#pod(state) {
|
|
722
|
-
const auth = this.auth;
|
|
723
|
-
return card('Keep your data in a folder?', h('p', { class: 'wa-hint' }, 'A folder on your computer that keeps your account and spaces. Back it up, or keep it in iCloud or Dropbox.'), h('div', { class: 'wa-options' }, option('pod', 'Choose a folder', 'Your browser will ask to see it, then to save into it.', () => void auth.choosePod(), state.busy)), errorBox(state.error), links(link('Not now — keep it in this browser', () => auth.finishSetup(), state.busy)), h('p', { class: 'wa-small' }, 'You can move it to a pod any time from your account page.'));
|
|
724
|
-
}
|
|
725
|
-
// ─── Arriving from a phone-pairing QR code ─────────────────────────
|
|
726
|
-
/**
|
|
727
|
-
* One button. The link holds only where to meet, but meeting still takes a
|
|
728
|
-
* tap: a page that went looking the instant it loaded would pair from a link
|
|
729
|
-
* someone had merely opened by accident. Once the computer answers, both show
|
|
730
|
-
* the same code, and the account comes over only after the person confirms
|
|
731
|
-
* it there.
|
|
732
|
-
*/
|
|
733
|
-
#pair(state) {
|
|
734
|
-
const auth = this.auth;
|
|
735
|
-
const arrival = state.pairingArrival;
|
|
736
|
-
if (arrival && state.session)
|
|
737
|
-
return this.#pairArrived(state, arrival, state.session.account.name);
|
|
738
|
-
const stage = state.pairingStage;
|
|
739
|
-
const code = stage?.kind === 'confirm' ? stage.code : null;
|
|
740
|
-
// The codes matched and the account is here: nothing left to tap or warn about.
|
|
741
|
-
const arriving = stage?.kind === 'sending';
|
|
742
|
-
return card(state.session ? 'Add an account' : 'Add this phone', subtitle('You scanned a code from your computer.'), code
|
|
743
|
-
? h('code', { class: 'wa-code wa-code-large', style: 'font-size:28px' }, `${code.slice(0, 3)} ${code.slice(3)}`)
|
|
744
|
-
: h('p', { class: 'wa-hint' }, state.session
|
|
745
|
-
? `This phone is signed in as ${state.session.account.name}. Pairing brings the account on the computer showing the code; you choose whether to add it once it arrives.`
|
|
746
|
-
: 'This phone becomes the same account, with its own copy of your spaces.', info('What happens next', 'Your computer and this phone show the same six digits. When you confirm them on the computer, it sends the account here directly — the relay only introduces the two, and sees nothing it could use.')), state.accounts.length > 0 && !code && !arriving
|
|
747
|
-
? h('p', { class: 'wa-error' }, 'Only continue if the code is on your own screen, in front of you. A link someone sent you would put this phone in their account instead of yours.')
|
|
748
|
-
: null, state.pairing && !code && !arriving
|
|
749
|
-
? button(state.busy ? 'Looking…' : 'Continue', () => void auth.acceptPairing(), state.busy)
|
|
750
|
-
: null, stage ? pairingLine(stage, 'wa-hint', 'margin-top:12px') : null, errorBox(state.error), h('p', { class: 'wa-small' }, 'Keep the code showing on your computer until this finishes.'), links(link(state.pairing ? 'Not now' : 'Back', () => auth.dismissPairing(), state.busy && !code)));
|
|
751
|
-
}
|
|
752
|
-
/** The account a pairing brought, to a phone signed in to another: add it, or switch to it if it is already here */
|
|
753
|
-
#pairArrived(state, arrival, current) {
|
|
754
|
-
const auth = this.auth;
|
|
755
|
-
const known = arrival.account;
|
|
756
|
-
return card(known ? `Switch to ${known.name}?` : 'Add this account?', h('div', { class: 'wa-row', style: 'align-items:center;gap:12px' }, this.#drawAvatar(arrival.did, 40), h('p', { class: 'wa-hint', style: 'margin:0' }, known
|
|
757
|
-
? `The computer that showed the code sent ${known.name}, which is already on this phone. Switch to it? ${current} stays here, to switch back to.`
|
|
758
|
-
: `The computer that showed the code sent a different account from ${current}, one this phone doesn't have. Add it only if it is yours: if you meant to add this phone to ${current}, it already is, and this account is someone else's.`)), button(known ? `Switch to ${known.name}` : 'Add and switch', () => void auth.answerPairing(true), state.busy), errorBox(state.error), links(link(`Stay as ${current}`, () => void auth.answerPairing(false), state.busy)));
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
/** Registers `<minca-auth>`, once. Importing this module does it for you. */
|
|
762
|
-
export function defineMincaAuth(tag = 'minca-auth') {
|
|
763
|
-
const registry = globalThis.customElements;
|
|
764
|
-
if (registry && !registry.get(tag))
|
|
765
|
-
registry.define(tag, MincaAuthElement);
|
|
766
|
-
}
|
|
767
|
-
defineMincaAuth();
|
|
768
|
-
//# sourceMappingURL=minca-auth.js.map
|