memory-anywhere-server 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +5 -2
- package/config/models.json +37 -0
- package/config/vendors.json +205 -0
- package/dist/server.mjs +12598 -0
- package/migrations/0001_init.mjs +41 -0
- package/migrations/0001_init.sql +551 -0
- package/migrations/0002_aws_mode.sql +31 -0
- package/migrations/0003_import.sql +12 -0
- package/migrations/0004_import_budget.sql +8 -0
- package/package.json +42 -4
- package/seed/attributes.json +574 -0
- package/seed/sections.json +65 -0
- package/web/assets/app.css +291 -0
- package/web/assets/app.js +322 -0
- package/web/templates/admin-apps.eta +43 -0
- package/web/templates/admin-changes.eta +10 -0
- package/web/templates/admin-empty.eta +3 -0
- package/web/templates/admin-exports.eta +15 -0
- package/web/templates/admin-home.eta +24 -0
- package/web/templates/admin-memories.eta +17 -0
- package/web/templates/admin-memory.eta +44 -0
- package/web/templates/admin-observations.eta +13 -0
- package/web/templates/admin-repos.eta +10 -0
- package/web/templates/admin-reviews.eta +31 -0
- package/web/templates/admin-sections.eta +22 -0
- package/web/templates/admin-system.eta +22 -0
- package/web/templates/admin.eta +6 -0
- package/web/templates/approve.eta +26 -0
- package/web/templates/consent-code.eta +8 -0
- package/web/templates/consent.eta +14 -0
- package/web/templates/error.eta +3 -0
- package/web/templates/layout.eta +16 -0
- package/web/templates/recover.eta +9 -0
- package/web/templates/setup.eta +20 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/* The server's pages: mobile-first, system fonts, light and dark (auth-and-security.md §8). */
|
|
2
|
+
:root {
|
|
3
|
+
--fg: #16181d;
|
|
4
|
+
--bg: #ffffff;
|
|
5
|
+
--muted: #5d6470;
|
|
6
|
+
--line: #d8dbe0;
|
|
7
|
+
--accent: #1f5fd6;
|
|
8
|
+
--accent-fg: #ffffff;
|
|
9
|
+
--danger: #b42318;
|
|
10
|
+
color-scheme: light dark;
|
|
11
|
+
}
|
|
12
|
+
@media (prefers-color-scheme: dark) {
|
|
13
|
+
:root {
|
|
14
|
+
--fg: #e9ebef;
|
|
15
|
+
--bg: #121417;
|
|
16
|
+
--muted: #a0a6b0;
|
|
17
|
+
--line: #2e3238;
|
|
18
|
+
--accent: #6d9cff;
|
|
19
|
+
--accent-fg: #0b0d10;
|
|
20
|
+
--danger: #ff7b6e;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
* {
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
}
|
|
26
|
+
body {
|
|
27
|
+
margin: 0;
|
|
28
|
+
background: var(--bg);
|
|
29
|
+
color: var(--fg);
|
|
30
|
+
font:
|
|
31
|
+
16px/1.5 system-ui,
|
|
32
|
+
-apple-system,
|
|
33
|
+
"Segoe UI",
|
|
34
|
+
sans-serif;
|
|
35
|
+
}
|
|
36
|
+
main {
|
|
37
|
+
max-width: 36rem;
|
|
38
|
+
margin: 0 auto;
|
|
39
|
+
padding: 2rem 1rem 4rem;
|
|
40
|
+
}
|
|
41
|
+
h1 {
|
|
42
|
+
font-size: 1.35rem;
|
|
43
|
+
line-height: 1.3;
|
|
44
|
+
margin: 1.5rem 0 1rem;
|
|
45
|
+
}
|
|
46
|
+
p {
|
|
47
|
+
margin: 0 0 0.75rem;
|
|
48
|
+
}
|
|
49
|
+
label {
|
|
50
|
+
display: block;
|
|
51
|
+
color: var(--muted);
|
|
52
|
+
font-size: 0.9rem;
|
|
53
|
+
margin-bottom: 0.25rem;
|
|
54
|
+
}
|
|
55
|
+
input,
|
|
56
|
+
select {
|
|
57
|
+
width: 100%;
|
|
58
|
+
font: inherit;
|
|
59
|
+
padding: 0.6rem 0.7rem;
|
|
60
|
+
margin-bottom: 1rem;
|
|
61
|
+
border: 1px solid var(--line);
|
|
62
|
+
border-radius: 0.4rem;
|
|
63
|
+
background: var(--bg);
|
|
64
|
+
color: var(--fg);
|
|
65
|
+
}
|
|
66
|
+
button {
|
|
67
|
+
font: inherit;
|
|
68
|
+
padding: 0.65rem 1.1rem;
|
|
69
|
+
border: 0;
|
|
70
|
+
border-radius: 0.4rem;
|
|
71
|
+
background: var(--accent);
|
|
72
|
+
color: var(--accent-fg);
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
}
|
|
75
|
+
button.secondary {
|
|
76
|
+
background: transparent;
|
|
77
|
+
color: var(--fg);
|
|
78
|
+
border: 1px solid var(--line);
|
|
79
|
+
}
|
|
80
|
+
button:disabled {
|
|
81
|
+
opacity: 0.5;
|
|
82
|
+
cursor: default;
|
|
83
|
+
}
|
|
84
|
+
.actions {
|
|
85
|
+
display: flex;
|
|
86
|
+
gap: 0.5rem;
|
|
87
|
+
flex-wrap: wrap;
|
|
88
|
+
}
|
|
89
|
+
.host {
|
|
90
|
+
font-size: 1.9rem;
|
|
91
|
+
font-weight: 700;
|
|
92
|
+
line-height: 1.2;
|
|
93
|
+
word-break: break-all;
|
|
94
|
+
}
|
|
95
|
+
.code {
|
|
96
|
+
font-family: ui-monospace, "Cascadia Mono", monospace;
|
|
97
|
+
letter-spacing: 0.12em;
|
|
98
|
+
}
|
|
99
|
+
.muted {
|
|
100
|
+
color: var(--muted);
|
|
101
|
+
font-size: 0.9rem;
|
|
102
|
+
}
|
|
103
|
+
.break {
|
|
104
|
+
word-break: break-all;
|
|
105
|
+
}
|
|
106
|
+
.danger {
|
|
107
|
+
color: var(--danger);
|
|
108
|
+
}
|
|
109
|
+
#msg {
|
|
110
|
+
min-height: 1.5em;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* Admin UI (auth-and-security.md §8.1) */
|
|
114
|
+
main:has(.nav) {
|
|
115
|
+
max-width: 52rem;
|
|
116
|
+
}
|
|
117
|
+
.nav {
|
|
118
|
+
display: flex;
|
|
119
|
+
flex-wrap: wrap;
|
|
120
|
+
gap: 0.25rem 0.9rem;
|
|
121
|
+
padding-bottom: 0.75rem;
|
|
122
|
+
margin-bottom: 1rem;
|
|
123
|
+
border-bottom: 1px solid var(--line);
|
|
124
|
+
}
|
|
125
|
+
.nav a {
|
|
126
|
+
color: var(--muted);
|
|
127
|
+
text-decoration: none;
|
|
128
|
+
padding: 0.2rem 0;
|
|
129
|
+
}
|
|
130
|
+
.nav a[aria-current="page"] {
|
|
131
|
+
color: var(--fg);
|
|
132
|
+
border-bottom: 2px solid var(--accent);
|
|
133
|
+
}
|
|
134
|
+
a {
|
|
135
|
+
color: var(--accent);
|
|
136
|
+
}
|
|
137
|
+
h2 {
|
|
138
|
+
font-size: 1.05rem;
|
|
139
|
+
margin: 1.25rem 0 0.5rem;
|
|
140
|
+
}
|
|
141
|
+
.lead {
|
|
142
|
+
font-size: 1.2rem;
|
|
143
|
+
}
|
|
144
|
+
.list {
|
|
145
|
+
list-style: none;
|
|
146
|
+
padding: 0;
|
|
147
|
+
margin: 0 0 1rem;
|
|
148
|
+
}
|
|
149
|
+
.list > li {
|
|
150
|
+
padding: 0.6rem 0;
|
|
151
|
+
border-bottom: 1px solid var(--line);
|
|
152
|
+
}
|
|
153
|
+
ol.list {
|
|
154
|
+
list-style: decimal inside;
|
|
155
|
+
}
|
|
156
|
+
.tiles {
|
|
157
|
+
display: grid;
|
|
158
|
+
grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
|
|
159
|
+
gap: 0.6rem;
|
|
160
|
+
margin: 1rem 0;
|
|
161
|
+
}
|
|
162
|
+
.tile {
|
|
163
|
+
display: block;
|
|
164
|
+
padding: 0.8rem;
|
|
165
|
+
border: 1px solid var(--line);
|
|
166
|
+
border-radius: 0.5rem;
|
|
167
|
+
color: var(--muted);
|
|
168
|
+
text-decoration: none;
|
|
169
|
+
font-size: 0.9rem;
|
|
170
|
+
}
|
|
171
|
+
.tile .n {
|
|
172
|
+
display: block;
|
|
173
|
+
color: var(--fg);
|
|
174
|
+
font-size: 1.5rem;
|
|
175
|
+
font-weight: 600;
|
|
176
|
+
}
|
|
177
|
+
.card {
|
|
178
|
+
border: 1px solid var(--line);
|
|
179
|
+
border-radius: 0.5rem;
|
|
180
|
+
padding: 0.8rem 1rem;
|
|
181
|
+
margin-bottom: 1rem;
|
|
182
|
+
}
|
|
183
|
+
.card h2 {
|
|
184
|
+
margin-top: 0;
|
|
185
|
+
}
|
|
186
|
+
.banner {
|
|
187
|
+
border: 2px solid var(--danger);
|
|
188
|
+
border-radius: 0.5rem;
|
|
189
|
+
padding: 0.8rem 1rem;
|
|
190
|
+
margin-bottom: 1rem;
|
|
191
|
+
}
|
|
192
|
+
form.alert {
|
|
193
|
+
display: flex;
|
|
194
|
+
justify-content: space-between;
|
|
195
|
+
align-items: center;
|
|
196
|
+
gap: 0.75rem;
|
|
197
|
+
padding: 0.5rem 0.75rem;
|
|
198
|
+
margin-bottom: 0.5rem;
|
|
199
|
+
border-left: 3px solid var(--danger);
|
|
200
|
+
background: color-mix(in srgb, var(--danger) 8%, transparent);
|
|
201
|
+
}
|
|
202
|
+
.filters {
|
|
203
|
+
display: flex;
|
|
204
|
+
flex-wrap: wrap;
|
|
205
|
+
gap: 0.5rem;
|
|
206
|
+
margin-bottom: 1rem;
|
|
207
|
+
}
|
|
208
|
+
.filters input,
|
|
209
|
+
.filters select {
|
|
210
|
+
width: auto;
|
|
211
|
+
flex: 1 1 10rem;
|
|
212
|
+
margin: 0;
|
|
213
|
+
}
|
|
214
|
+
.stack {
|
|
215
|
+
display: grid;
|
|
216
|
+
gap: 0.25rem;
|
|
217
|
+
margin: 0.75rem 0;
|
|
218
|
+
}
|
|
219
|
+
.stack input,
|
|
220
|
+
.stack select,
|
|
221
|
+
.stack textarea {
|
|
222
|
+
margin-bottom: 0.5rem;
|
|
223
|
+
}
|
|
224
|
+
textarea {
|
|
225
|
+
width: 100%;
|
|
226
|
+
font: inherit;
|
|
227
|
+
padding: 0.6rem 0.7rem;
|
|
228
|
+
border: 1px solid var(--line);
|
|
229
|
+
border-radius: 0.4rem;
|
|
230
|
+
background: var(--bg);
|
|
231
|
+
color: var(--fg);
|
|
232
|
+
}
|
|
233
|
+
form.inline {
|
|
234
|
+
display: inline-flex;
|
|
235
|
+
gap: 0.4rem;
|
|
236
|
+
align-items: center;
|
|
237
|
+
margin: 0.25rem 0.25rem 0 0;
|
|
238
|
+
}
|
|
239
|
+
form.inline input,
|
|
240
|
+
form.inline select {
|
|
241
|
+
width: auto;
|
|
242
|
+
margin: 0;
|
|
243
|
+
}
|
|
244
|
+
.actions form {
|
|
245
|
+
display: inline-block;
|
|
246
|
+
}
|
|
247
|
+
button.danger-button {
|
|
248
|
+
background: var(--danger);
|
|
249
|
+
color: var(--accent-fg);
|
|
250
|
+
}
|
|
251
|
+
input[type="checkbox"] {
|
|
252
|
+
width: auto;
|
|
253
|
+
margin: 0 0.4rem 0 0;
|
|
254
|
+
}
|
|
255
|
+
.table {
|
|
256
|
+
width: 100%;
|
|
257
|
+
border-collapse: collapse;
|
|
258
|
+
font-size: 0.9rem;
|
|
259
|
+
margin-bottom: 1rem;
|
|
260
|
+
}
|
|
261
|
+
.table th,
|
|
262
|
+
.table td {
|
|
263
|
+
text-align: left;
|
|
264
|
+
padding: 0.4rem 0.5rem;
|
|
265
|
+
border-bottom: 1px solid var(--line);
|
|
266
|
+
}
|
|
267
|
+
.result {
|
|
268
|
+
display: grid;
|
|
269
|
+
grid-template-columns: max-content 1fr;
|
|
270
|
+
gap: 0.3rem 0.8rem;
|
|
271
|
+
padding: 0.8rem;
|
|
272
|
+
border: 1px solid var(--line);
|
|
273
|
+
border-radius: 0.5rem;
|
|
274
|
+
word-break: break-all;
|
|
275
|
+
}
|
|
276
|
+
.result dt {
|
|
277
|
+
color: var(--muted);
|
|
278
|
+
}
|
|
279
|
+
.result dd {
|
|
280
|
+
margin: 0;
|
|
281
|
+
font-family: ui-monospace, "Cascadia Mono", monospace;
|
|
282
|
+
}
|
|
283
|
+
.choices {
|
|
284
|
+
border: 1px solid var(--line);
|
|
285
|
+
border-radius: 0.4rem;
|
|
286
|
+
padding: 0.4rem 0.6rem;
|
|
287
|
+
margin: 0.4rem 0;
|
|
288
|
+
display: flex;
|
|
289
|
+
flex-wrap: wrap;
|
|
290
|
+
gap: 0.3rem 0.9rem;
|
|
291
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// The one first-party script of the server's pages (auth-and-security.md §8). Each page names its
|
|
2
|
+
// behaviour in <body data-page>, and its CSRF token in data-csrf. No HTML is ever built from
|
|
3
|
+
// strings here: text goes in through textContent, which also satisfies Trusted Types.
|
|
4
|
+
|
|
5
|
+
const body = document.body;
|
|
6
|
+
const csrf = body.dataset.csrf ?? "";
|
|
7
|
+
const base = body.dataset.base ?? "";
|
|
8
|
+
// Where the admin UI lives: "" on admin.{host}, "/admin" on the local server (auth-and-security.md §8.1).
|
|
9
|
+
const root = body.dataset.root ?? "";
|
|
10
|
+
const $ = (id) => document.getElementById(id);
|
|
11
|
+
const say = (text) => {
|
|
12
|
+
const el = $("msg");
|
|
13
|
+
if (el) el.textContent = text;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
async function post(path, payload) {
|
|
17
|
+
const r = await fetch(path, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: { "content-type": "application/json", "x-ma-csrf": csrf },
|
|
20
|
+
body: JSON.stringify(payload ?? {}),
|
|
21
|
+
});
|
|
22
|
+
const data = await r.json().catch(() => ({}));
|
|
23
|
+
if (!r.ok) throw new Error(data.error ?? `HTTP ${r.status}`);
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A user-verified assertion over a challenge the server issued at `optionsPath`. */
|
|
28
|
+
async function assertion(optionsPath, extra) {
|
|
29
|
+
const options = await post(optionsPath, extra);
|
|
30
|
+
const credential = await navigator.credentials.get({
|
|
31
|
+
publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(options),
|
|
32
|
+
});
|
|
33
|
+
return credential.toJSON();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A new passkey over a challenge the server issued at `optionsPath`. */
|
|
37
|
+
async function registration(optionsPath, extra) {
|
|
38
|
+
const options = await post(optionsPath, extra);
|
|
39
|
+
const credential = await navigator.credentials.create({
|
|
40
|
+
publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(options),
|
|
41
|
+
});
|
|
42
|
+
return credential.toJSON();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A form's fields as JSON: data-type "bool", "datetime" and "list" (ticked boxes and hidden values) become booleans, ISO times and arrays. */
|
|
46
|
+
function fieldsOf(form) {
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const el of form.elements) {
|
|
49
|
+
if (!el.name) continue;
|
|
50
|
+
const type = el.dataset.type;
|
|
51
|
+
if (type === "list") {
|
|
52
|
+
out[el.name] ??= [];
|
|
53
|
+
if (el.type !== "checkbox" || el.checked) out[el.name].push(el.value);
|
|
54
|
+
} else if (type === "bool") out[el.name] = el.type === "checkbox" ? el.checked : el.value === "true";
|
|
55
|
+
else if (type === "datetime") out[el.name] = el.value ? new Date(el.value).toISOString() : "";
|
|
56
|
+
else if (el.value !== "") out[el.name] = el.value;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Runs a sessionStorage call; storage can be blocked (private modes, site settings), which is not fatal. */
|
|
62
|
+
function storage(call) {
|
|
63
|
+
try {
|
|
64
|
+
return call();
|
|
65
|
+
} catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Recovery codes are compared without dashes, spaces or case, as the server does. */
|
|
71
|
+
const normalizeCode = (code) => code.replace(/[\s-]/gu, "").toUpperCase();
|
|
72
|
+
|
|
73
|
+
/** Runs a request; if the server wants a fresh passkey (§3.4), asks for it once and retries. */
|
|
74
|
+
async function withStepUp(request) {
|
|
75
|
+
try {
|
|
76
|
+
return await request();
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if (e.message !== "step_up_required") throw e;
|
|
79
|
+
await post(`${root}/api/stepup/verify`, await assertion(`${root}/api/stepup/options`));
|
|
80
|
+
return request();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const pages = {
|
|
85
|
+
"consent-code": () => {
|
|
86
|
+
$("code-form").addEventListener("submit", async (event) => {
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
try {
|
|
89
|
+
await post(`${base}/code`, { code: $("code").value });
|
|
90
|
+
location.reload();
|
|
91
|
+
} catch {
|
|
92
|
+
say("That code is not right.");
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
consent: () => {
|
|
97
|
+
const approve = $("approve");
|
|
98
|
+
// A second of delay, so a click meant for the app's own button cannot land on Approve.
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
approve.disabled = false;
|
|
101
|
+
}, 1000);
|
|
102
|
+
approve.addEventListener("click", async () => {
|
|
103
|
+
try {
|
|
104
|
+
const r = await post(`${base}/approve`, await assertion(`${base}/options`));
|
|
105
|
+
location.assign(r.redirectTo);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
say(`Not approved: ${e.message}`);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
$("deny").addEventListener("click", async () => {
|
|
111
|
+
try {
|
|
112
|
+
const r = await post(`${base}/deny`);
|
|
113
|
+
location.assign(r.redirectTo);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
say(e.message);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
setup: () => {
|
|
120
|
+
// The token arrives in the fragment (never sent to the server in a URL), then leaves the address
|
|
121
|
+
// bar. This tab keeps it until setup ends, so a reload resumes instead of losing the link.
|
|
122
|
+
const token = location.hash.slice(1) || storage(() => sessionStorage.getItem("ma-setup")) || "";
|
|
123
|
+
storage(() => sessionStorage.setItem("ma-setup", token));
|
|
124
|
+
history.replaceState(null, "", location.pathname);
|
|
125
|
+
const show = (n) => {
|
|
126
|
+
for (const i of [1, 2, 3]) $(`step-${i}`).hidden = i !== n;
|
|
127
|
+
};
|
|
128
|
+
const add = async (extra) => {
|
|
129
|
+
const response = await registration("/setup/options", { token });
|
|
130
|
+
return post("/setup/verify", { token, response, ...extra });
|
|
131
|
+
};
|
|
132
|
+
$("add-1").addEventListener("click", async () => {
|
|
133
|
+
try {
|
|
134
|
+
await add({ label: "First passkey" });
|
|
135
|
+
show(2);
|
|
136
|
+
say("");
|
|
137
|
+
} catch (e) {
|
|
138
|
+
say(`Not added: ${e.message}`);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
$("add-2").addEventListener("click", async () => {
|
|
142
|
+
try {
|
|
143
|
+
const r = await add({ label: "Second passkey", differentProviders: $("different").checked });
|
|
144
|
+
const list = $("codes");
|
|
145
|
+
for (const code of r.codes) {
|
|
146
|
+
const li = document.createElement("li");
|
|
147
|
+
li.textContent = code;
|
|
148
|
+
list.append(li);
|
|
149
|
+
}
|
|
150
|
+
show(3);
|
|
151
|
+
say("");
|
|
152
|
+
} catch (e) {
|
|
153
|
+
say(
|
|
154
|
+
e.message === "same_provider"
|
|
155
|
+
? "This looks like the same provider as the first passkey. Use another one, or tick the box if they really differ."
|
|
156
|
+
: `Not added: ${e.message}`,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
$("confirm").addEventListener("click", async () => {
|
|
161
|
+
try {
|
|
162
|
+
await post("/setup/confirm", { token, code: $("confirm-code").value });
|
|
163
|
+
storage(() => sessionStorage.removeItem("ma-setup"));
|
|
164
|
+
location.assign("/");
|
|
165
|
+
} catch {
|
|
166
|
+
say("That is not one of the codes.");
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
signin: () => {
|
|
171
|
+
$("signin").addEventListener("click", async () => {
|
|
172
|
+
try {
|
|
173
|
+
await post(`${root}/api/login/verify`, await assertion(`${root}/api/login/options`));
|
|
174
|
+
location.reload();
|
|
175
|
+
} catch (e) {
|
|
176
|
+
say(`Not signed in: ${e.message}`);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
approve: () => {
|
|
181
|
+
const approve = $("approve");
|
|
182
|
+
if (!approve) return;
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
approve.disabled = false;
|
|
185
|
+
}, 1000);
|
|
186
|
+
const once = async (confirm) => {
|
|
187
|
+
const response = await assertion(`${base}/options`);
|
|
188
|
+
return post(`${base}/approve`, { response, confirm });
|
|
189
|
+
};
|
|
190
|
+
approve.addEventListener("click", async () => {
|
|
191
|
+
try {
|
|
192
|
+
let r = await once($("confirm")?.value);
|
|
193
|
+
// An export to an unregistered key needs a second, separate passkey approval.
|
|
194
|
+
if (r.result === "second") {
|
|
195
|
+
say("Approve once more to confirm the unregistered key.");
|
|
196
|
+
r = await once();
|
|
197
|
+
}
|
|
198
|
+
say("Approved. You can close this page; the command continues in your terminal.");
|
|
199
|
+
approve.disabled = true;
|
|
200
|
+
} catch (e) {
|
|
201
|
+
const why = {
|
|
202
|
+
wrong_suffix: "Those are not the key's last 8 characters.",
|
|
203
|
+
wrong_amount: "That is not the estimate rounded up to whole dollars.",
|
|
204
|
+
}[e.message];
|
|
205
|
+
say(why ?? `Not approved: ${e.message}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
$("deny").addEventListener("click", async () => {
|
|
209
|
+
try {
|
|
210
|
+
await post(`${base}/deny`);
|
|
211
|
+
say("Denied.");
|
|
212
|
+
approve.disabled = true;
|
|
213
|
+
} catch (e) {
|
|
214
|
+
say(e.message);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
admin: () => {
|
|
219
|
+
// Every <form class="act" data-action="…"> runs one owner action; actions that need a fresh
|
|
220
|
+
// passkey (§3.4) answer step_up_required, and the page asks for it once, then retries.
|
|
221
|
+
for (const form of document.querySelectorAll("form.act")) {
|
|
222
|
+
form.addEventListener("submit", async (event) => {
|
|
223
|
+
event.preventDefault();
|
|
224
|
+
if (form.dataset.confirm && !window.confirm(form.dataset.confirm)) return;
|
|
225
|
+
try {
|
|
226
|
+
const r = await withStepUp(() => post(`${root}/api/act/${form.dataset.action}`, { input: fieldsOf(form) }));
|
|
227
|
+
if (r.result && typeof r.result === "object" && "forgotten" in r.result)
|
|
228
|
+
say(
|
|
229
|
+
`Reverted: ${r.result.forgotten} forgotten, ${r.result.restored} restored, ${r.result.observations} observations closed.`,
|
|
230
|
+
);
|
|
231
|
+
else location.reload();
|
|
232
|
+
} catch (e) {
|
|
233
|
+
say(e.message);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const pair = $("pair-form");
|
|
238
|
+
pair?.addEventListener("submit", async (event) => {
|
|
239
|
+
event.preventDefault();
|
|
240
|
+
try {
|
|
241
|
+
const w = await withStepUp(() => post(`${root}/api/windows`, fieldsOf(pair)));
|
|
242
|
+
const out = $("pair-result");
|
|
243
|
+
out.replaceChildren();
|
|
244
|
+
const row = (label, value) => {
|
|
245
|
+
const dt = document.createElement("dt");
|
|
246
|
+
dt.textContent = label;
|
|
247
|
+
const dd = document.createElement("dd");
|
|
248
|
+
dd.textContent = value;
|
|
249
|
+
out.append(dt, dd);
|
|
250
|
+
};
|
|
251
|
+
row("Server URL", w.mcp_url);
|
|
252
|
+
row("Pairing code", w.pair_code);
|
|
253
|
+
row("Open this link in this browser first", w.pair_link);
|
|
254
|
+
if (w.credentials) {
|
|
255
|
+
row("Client ID", w.credentials.client_id);
|
|
256
|
+
row("Client secret (shown once)", w.credentials.client_secret);
|
|
257
|
+
}
|
|
258
|
+
row("Closes", new Date(w.expires_at).toLocaleTimeString());
|
|
259
|
+
out.hidden = false;
|
|
260
|
+
say("");
|
|
261
|
+
} catch (e) {
|
|
262
|
+
say(
|
|
263
|
+
e.message === "replace_required"
|
|
264
|
+
? "This app is already connected: tick Replace to connect it again."
|
|
265
|
+
: e.message,
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
// New recovery codes (§3.3): shown once; Done asks for one typed back, so they are not left unsaved.
|
|
270
|
+
let codes = [];
|
|
271
|
+
$("new-codes")?.addEventListener("click", async () => {
|
|
272
|
+
if (!window.confirm("Make 10 new recovery codes? The old ones stop working.")) return;
|
|
273
|
+
try {
|
|
274
|
+
({ codes } = await withStepUp(() => post(`${root}/api/recovery/codes`)));
|
|
275
|
+
$("codes").replaceChildren(
|
|
276
|
+
...codes.map((code) => Object.assign(document.createElement("li"), { textContent: code })),
|
|
277
|
+
);
|
|
278
|
+
$("codes-step").hidden = false;
|
|
279
|
+
$("new-codes").hidden = true;
|
|
280
|
+
say("");
|
|
281
|
+
} catch (e) {
|
|
282
|
+
say(e.message);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
$("confirm-codes")?.addEventListener("click", () => {
|
|
286
|
+
const typed = normalizeCode($("confirm-code").value);
|
|
287
|
+
if (!codes.some((c) => normalizeCode(c) === typed)) return say("That is not one of the codes.");
|
|
288
|
+
location.reload();
|
|
289
|
+
});
|
|
290
|
+
$("cancel-reset")?.addEventListener("click", async () => {
|
|
291
|
+
try {
|
|
292
|
+
await withStepUp(() => post(`${root}/api/reset/cancel`));
|
|
293
|
+
location.reload();
|
|
294
|
+
} catch (e) {
|
|
295
|
+
say(e.message);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
},
|
|
299
|
+
recover: () => {
|
|
300
|
+
$("recover-form").addEventListener("submit", async (event) => {
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
try {
|
|
303
|
+
const r = await post("/recover", { code: $("code").value });
|
|
304
|
+
location.assign(r.enroll);
|
|
305
|
+
location.reload();
|
|
306
|
+
} catch {
|
|
307
|
+
say("That code did not work.");
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
export { assertion, post, registration, say };
|
|
314
|
+
|
|
315
|
+
// Times arrive in UTC (the server does not know the viewer's zone); show each in the viewer's own.
|
|
316
|
+
for (const t of document.querySelectorAll("time[datetime]")) {
|
|
317
|
+
const d = new Date(t.dateTime);
|
|
318
|
+
if (!Number.isNaN(d.getTime()))
|
|
319
|
+
t.textContent = d.toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
pages[body.dataset.page]?.();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<% layout("./admin") %>
|
|
2
|
+
<% if (!it.local) { %>
|
|
3
|
+
<% if (it.approvals.length > 0) { %>
|
|
4
|
+
<h1>Waiting for your approval</h1>
|
|
5
|
+
<ul class="list"><% for (const a of it.approvals) { %><li><a href="<%= it.root ?? "" %>/approve/<%= a.id %>"><%= a.command %></a> <span class="muted"><%= a.client %> · code <%= a.user_code %></span></li><% } %></ul>
|
|
6
|
+
<% } %>
|
|
7
|
+
<h1>Connect an app</h1>
|
|
8
|
+
<form id="pair-form" class="stack">
|
|
9
|
+
<label for="vendor">App</label>
|
|
10
|
+
<select id="vendor" name="vendor"><% for (const v of it.vendors) { %><option value="<%= v.id %>"><%= v.label %></option><% } %></select>
|
|
11
|
+
<label for="method">How it registers</label>
|
|
12
|
+
<select id="method" name="method"><option value="static">Client id and secret</option><option value="dcr">The app registers itself</option><option value="cimd">The app's published client</option></select>
|
|
13
|
+
<label for="machineName">Computer name (PC only)</label><input id="machineName" name="machineName" maxlength="40">
|
|
14
|
+
<label for="otherHost">Its redirect host (Other only)</label><input id="otherHost" name="otherHost" placeholder="app.example.com">
|
|
15
|
+
<label for="redirectUri">Its redirect URL (Other, with client id and secret)</label><input id="redirectUri" name="redirectUri">
|
|
16
|
+
<label><input type="checkbox" name="write" checked data-type="bool"> Can save memories</label>
|
|
17
|
+
<label><input type="checkbox" name="replace" data-type="bool"> Replace its current connection</label>
|
|
18
|
+
<button type="submit">Open a 10-minute pairing window</button>
|
|
19
|
+
</form>
|
|
20
|
+
<dl id="pair-result" class="result" hidden></dl>
|
|
21
|
+
<% } %>
|
|
22
|
+
<h1>Connected apps</h1>
|
|
23
|
+
<% for (const c of it.rows) { %>
|
|
24
|
+
<section class="card">
|
|
25
|
+
<h2><%= c.display_name %> <span class="muted"><%= c.class %></span></h2>
|
|
26
|
+
<p class="muted"><%= c.grants %> connection<%= c.grants === 1 ? "" : "s" %><% if (c.lastUsed) { %> · last used <%= c.lastUsed %><% } %> · read <%= c.reads24 %> of <%= c.read_budget_24h %> today · <%= c.saves14 %> saves in 14 days, <%= c.badRate %>% undone by you</p>
|
|
27
|
+
<form class="act stack" data-action="client.policy">
|
|
28
|
+
<input type="hidden" name="client_id" value="<%= c.client_id %>">
|
|
29
|
+
<label><input type="checkbox" name="write" data-type="bool"<% if (c.write) { %> checked<% } %>> Can save</label>
|
|
30
|
+
<select name="sections" aria-label="Sections"><option value="all"<% if (!c.restricted) { %> selected<% } %>>Reads every section</option><option value="restricted"<% if (c.restricted) { %> selected<% } %>>Reads Profile, Preferences, Interests, Tools</option></select>
|
|
31
|
+
<select name="save_floor" aria-label="Saves"><option value="none"<% if (c.save_floor === "none") { %> selected<% } %>>Saves become memories</option><option value="observation"<% if (c.save_floor === "observation") { %> selected<% } %>>Saves start as observations</option></select>
|
|
32
|
+
<select name="elicitation" aria-label="Confirm saves"><option value="none"<% if (c.elicitation === "none") { %> selected<% } %>>No confirmation question</option><option value="verified"<% if (c.elicitation === "verified") { %> selected<% } %>>Confirm saves with a question (Claude)</option></select>
|
|
33
|
+
<button type="submit" class="secondary">Save policy</button>
|
|
34
|
+
</form>
|
|
35
|
+
<form class="act stack" data-action="client.revert" data-confirm="Undo everything this app did in that window?">
|
|
36
|
+
<input type="hidden" name="client_id" value="<%= c.client_id %>">
|
|
37
|
+
<label>Undo what it did from <input type="datetime-local" name="since" data-type="datetime" required></label>
|
|
38
|
+
<label>to <input type="datetime-local" name="until" data-type="datetime" required></label>
|
|
39
|
+
<button type="submit" class="secondary">Revert</button>
|
|
40
|
+
</form>
|
|
41
|
+
<form class="act" data-action="client.revoke" data-confirm="Disconnect this app?"><input type="hidden" name="client_id" value="<%= c.client_id %>"><button type="submit" class="danger-button">Disconnect</button></form>
|
|
42
|
+
</section>
|
|
43
|
+
<% } %>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<% layout("./admin") %>
|
|
2
|
+
<h1>Recent changes</h1>
|
|
3
|
+
<ul class="list">
|
|
4
|
+
<% for (const c of it.rows) { %>
|
|
5
|
+
<li><span class="muted"><%~ it.fmt.time(c.at) %> · <%= c.actor %> · <%= c.op %></span><% if (c.content) { %><br><a href="<%= it.root ?? "" %>/memories/<%= c.memory_id %>"><%= c.content %></a><% } %>
|
|
6
|
+
<% if (c.op === "memory.forget" && c.status === "forgotten") { %><form class="act inline" data-action="memory.undo"><input type="hidden" name="id" value="<%= c.memory_id %>"><button type="submit" class="secondary">Undo</button></form><% } %>
|
|
7
|
+
<% if (c.op === "memory.insert" && (c.status === "active" || c.status === "contested")) { %><form class="act inline" data-action="memory.forget"><input type="hidden" name="id" value="<%= c.memory_id %>"><button type="submit" class="secondary">Undo</button></form><% } %>
|
|
8
|
+
</li>
|
|
9
|
+
<% } %>
|
|
10
|
+
</ul>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% layout("./admin") %>
|
|
2
|
+
<h1>Export keys</h1>
|
|
3
|
+
<p class="muted">Exports are encrypted to one of these age keys. Keep the private key offline.</p>
|
|
4
|
+
<ul class="list">
|
|
5
|
+
<% for (const r of it.recipients) { %><li><strong><%= r.label %></strong> <span class="code"><%= r.fingerprint.replace(/(.{4})(?=.)/g, "$1 ") %></span>
|
|
6
|
+
<form class="act inline" data-action="recipient.revoke" data-confirm="Remove this key?"><input type="hidden" name="id" value="<%= r.id %>"><button type="submit" class="secondary">Remove</button></form></li><% } %>
|
|
7
|
+
</ul>
|
|
8
|
+
<form class="act stack" data-action="recipient.add">
|
|
9
|
+
<label>Public key <input name="recipient" placeholder="age1…" required spellcheck="false"></label>
|
|
10
|
+
<label>Label <input name="label" maxlength="64" required></label>
|
|
11
|
+
<button type="submit">Add key</button>
|
|
12
|
+
</form>
|
|
13
|
+
<h1>Exports made</h1>
|
|
14
|
+
<ul class="list"><% for (const l of it.log) { %><li><%= l.kind %> <span class="muted"><%~ it.fmt.time(l.at) %> · <%= l.client %><% if (l.recipient_fingerprint) { %> · <%= l.recipient_fingerprint %><% } %></span></li><% } %></ul>
|
|
15
|
+
<% if (it.log.length === 0) { %><p class="muted">None yet. Run <span class="code">mema export</span> on your computer.</p><% } %>
|