@weft-framework/server 0.0.0-stage → 0.0.3
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 +4 -2
- package/dist/account.d.ts +124 -0
- package/dist/account.js +344 -0
- package/dist/action.d.ts +43 -0
- package/dist/action.js +135 -0
- package/dist/admin.d.ts +99 -0
- package/dist/admin.js +431 -0
- package/dist/api.d.ts +21 -0
- package/dist/api.js +72 -0
- package/dist/app.d.ts +202 -0
- package/dist/app.js +3692 -0
- package/dist/assets.d.ts +4 -0
- package/dist/assets.js +91 -0
- package/dist/auth.d.ts +150 -0
- package/dist/auth.js +215 -0
- package/dist/backup.d.ts +46 -0
- package/dist/backup.js +345 -0
- package/dist/build.d.ts +33 -0
- package/dist/build.js +274 -0
- package/dist/bun.d.ts +30 -0
- package/dist/bun.js +53 -0
- package/dist/calendar.d.ts +161 -0
- package/dist/calendar.js +690 -0
- package/dist/compiler.d.ts +13 -0
- package/dist/compiler.js +58 -0
- package/dist/compress.d.ts +6 -0
- package/dist/compress.js +78 -0
- package/dist/config.d.ts +26 -0
- package/dist/config.js +317 -0
- package/dist/context.d.ts +9 -0
- package/dist/context.js +1 -0
- package/dist/contract.d.ts +18 -0
- package/dist/contract.js +171 -0
- package/dist/datamap.d.ts +24 -0
- package/dist/datamap.js +365 -0
- package/dist/db-backup.d.ts +27 -0
- package/dist/db-backup.js +115 -0
- package/dist/dev-events.d.ts +14 -0
- package/dist/dev-events.js +135 -0
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +240 -0
- package/dist/devtools-client.d.ts +1 -0
- package/dist/devtools-client.js +362 -0
- package/dist/devtools.d.ts +87 -0
- package/dist/devtools.js +68 -0
- package/dist/edge.d.ts +3 -0
- package/dist/edge.js +7 -0
- package/dist/email-signin.d.ts +92 -0
- package/dist/email-signin.js +259 -0
- package/dist/env.d.ts +1 -0
- package/dist/env.js +15 -0
- package/dist/explain.d.ts +12 -0
- package/dist/explain.js +217 -0
- package/dist/files.d.ts +6 -0
- package/dist/files.js +170 -0
- package/dist/grants.d.ts +69 -0
- package/dist/grants.js +206 -0
- package/dist/image/bitmap.d.ts +11 -0
- package/dist/image/bitmap.js +172 -0
- package/dist/image/jpeg.d.ts +10 -0
- package/dist/image/jpeg.js +697 -0
- package/dist/image/png.d.ts +8 -0
- package/dist/image/png.js +282 -0
- package/dist/image/transform.d.ts +20 -0
- package/dist/image/transform.js +52 -0
- package/dist/image/worker.d.ts +1 -0
- package/dist/image/worker.js +11 -0
- package/dist/images.d.ts +39 -0
- package/dist/images.js +283 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +31 -0
- package/dist/inspect-hub.d.ts +42 -0
- package/dist/inspect-hub.js +14 -0
- package/dist/inspector.d.ts +51 -0
- package/dist/inspector.js +193 -0
- package/dist/job-admin.d.ts +55 -0
- package/dist/job-admin.js +89 -0
- package/dist/jobs.d.ts +222 -0
- package/dist/jobs.js +789 -0
- package/dist/live.d.ts +72 -0
- package/dist/live.js +481 -0
- package/dist/load-config.d.ts +2 -0
- package/dist/load-config.js +41 -0
- package/dist/log.d.ts +20 -0
- package/dist/log.js +143 -0
- package/dist/mail.d.ts +189 -0
- package/dist/mail.js +999 -0
- package/dist/media.d.ts +129 -0
- package/dist/media.js +470 -0
- package/dist/meta.d.ts +54 -0
- package/dist/meta.js +146 -0
- package/dist/middleware.d.ts +20 -0
- package/dist/middleware.js +101 -0
- package/dist/migrate.d.ts +12 -0
- package/dist/migrate.js +88 -0
- package/dist/node.d.ts +26 -0
- package/dist/node.js +96 -0
- package/dist/notice.d.ts +21 -0
- package/dist/notice.js +48 -0
- package/dist/npm.d.ts +16 -0
- package/dist/npm.js +347 -0
- package/dist/oauth.d.ts +76 -0
- package/dist/oauth.js +408 -0
- package/dist/otel.d.ts +57 -0
- package/dist/otel.js +293 -0
- package/dist/passkey.d.ts +99 -0
- package/dist/passkey.js +572 -0
- package/dist/password.d.ts +8 -0
- package/dist/password.js +65 -0
- package/dist/pdf.d.ts +46 -0
- package/dist/pdf.js +332 -0
- package/dist/personal-data.d.ts +22 -0
- package/dist/personal-data.js +148 -0
- package/dist/pointers.d.ts +9 -0
- package/dist/pointers.js +148 -0
- package/dist/postcss.d.ts +3 -0
- package/dist/postcss.js +89 -0
- package/dist/presence.d.ts +27 -0
- package/dist/presence.js +161 -0
- package/dist/preview.d.ts +25 -0
- package/dist/preview.js +353 -0
- package/dist/production.d.ts +16 -0
- package/dist/production.js +119 -0
- package/dist/project.d.ts +23 -0
- package/dist/project.js +536 -0
- package/dist/regions.d.ts +47 -0
- package/dist/regions.js +511 -0
- package/dist/replay.d.ts +44 -0
- package/dist/replay.js +259 -0
- package/dist/router.d.ts +29 -0
- package/dist/router.js +146 -0
- package/dist/rules-diff.d.ts +18 -0
- package/dist/rules-diff.js +165 -0
- package/dist/rules-test.d.ts +17 -0
- package/dist/rules-test.js +108 -0
- package/dist/saml.d.ts +160 -0
- package/dist/saml.js +959 -0
- package/dist/seal.d.ts +35 -0
- package/dist/seal.js +107 -0
- package/dist/secret.d.ts +14 -0
- package/dist/secret.js +110 -0
- package/dist/security.d.ts +53 -0
- package/dist/security.js +250 -0
- package/dist/seed.d.ts +16 -0
- package/dist/seed.js +94 -0
- package/dist/seo.d.ts +42 -0
- package/dist/seo.js +175 -0
- package/dist/settings.d.ts +79 -0
- package/dist/settings.js +212 -0
- package/dist/shared.d.ts +15 -0
- package/dist/shared.js +283 -0
- package/dist/shell.d.ts +12 -0
- package/dist/shell.js +118 -0
- package/dist/storage.d.ts +13 -0
- package/dist/storage.js +55 -0
- package/dist/support.d.ts +83 -0
- package/dist/support.js +236 -0
- package/dist/sync.d.ts +35 -0
- package/dist/sync.js +167 -0
- package/dist/tailwind.d.ts +14 -0
- package/dist/tailwind.js +117 -0
- package/dist/two-factor.d.ts +103 -0
- package/dist/two-factor.js +435 -0
- package/dist/uploads.d.ts +185 -0
- package/dist/uploads.js +991 -0
- package/dist/webhooks.d.ts +169 -0
- package/dist/webhooks.js +758 -0
- package/dist/webpush.d.ts +97 -0
- package/dist/webpush.js +372 -0
- package/dist/wizard.d.ts +141 -0
- package/dist/wizard.js +410 -0
- package/dist/workflows.d.ts +134 -0
- package/dist/workflows.js +511 -0
- package/package.json +186 -4
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
export const DEV_PANEL_JS = `
|
|
2
|
+
const PANEL = "weft-dev-panel";
|
|
3
|
+
const INK = "#1a1a1a", MUTED = "#6b6b6b", RULE = "#d4d4d4", BG = "#fbfbf9", WARN = "#b00020", OK = "#1d6b3a";
|
|
4
|
+
let panel = null, view = "tree", timer = null, last = null, viewForm = null, viewNote = "";
|
|
5
|
+
// Time travel: the step shown in place of the page (null: live).
|
|
6
|
+
let shown = null, shownBox = null, shownRoot = null, shownLid = "", shownNote = "";
|
|
7
|
+
|
|
8
|
+
function el(tag, props, text) {
|
|
9
|
+
const n = css(document.createElement(tag), props || {});
|
|
10
|
+
if (text !== undefined) n.textContent = text;
|
|
11
|
+
return n;
|
|
12
|
+
}
|
|
13
|
+
function lid() {
|
|
14
|
+
return document.querySelector('meta[name="weft-live"]')?.getAttribute("content") || "";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let toggle = null;
|
|
18
|
+
if (typeof document.querySelector === "function" && document.body) installPanel();
|
|
19
|
+
function installPanel() {
|
|
20
|
+
toggle = el("button", {
|
|
21
|
+
position: "fixed", right: "8px", bottom: "8px", "z-index": "2147483646",
|
|
22
|
+
font: "11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
23
|
+
background: BG, color: MUTED, border: "1px solid " + RULE, padding: "4px 6px", cursor: "pointer", opacity: "0.8",
|
|
24
|
+
}, "weft");
|
|
25
|
+
toggle.type = "button";
|
|
26
|
+
toggle.title = "Weft dev overlay (Alt+Shift+D)";
|
|
27
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
28
|
+
toggle.addEventListener("click", () => (panel ? closePanel() : openPanel()));
|
|
29
|
+
document.body.append(toggle);
|
|
30
|
+
document.addEventListener("keydown", (e) => {
|
|
31
|
+
if (e.altKey && e.shiftKey && (e.key === "D" || e.key === "d" || e.code === "KeyD")) {
|
|
32
|
+
e.preventDefault();
|
|
33
|
+
panel ? closePanel() : openPanel();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
document.addEventListener("visibilitychange", () => {
|
|
37
|
+
if (!panel) return;
|
|
38
|
+
if (document.visibilityState === "hidden") stop(); else poll();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function openPanel() {
|
|
43
|
+
panel = el("section", {
|
|
44
|
+
position: "fixed", left: "0", right: "0", bottom: "0", height: "38vh", "z-index": "2147483646",
|
|
45
|
+
display: "flex", "flex-direction": "column", background: BG, color: INK, "border-top": "1px solid " + RULE,
|
|
46
|
+
font: "12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
|
|
47
|
+
});
|
|
48
|
+
panel.id = PANEL;
|
|
49
|
+
panel.setAttribute("aria-label", "Weft dev overlay");
|
|
50
|
+
const bar = el("div", { display: "flex", gap: "16px", "align-items": "baseline", padding: "6px 12px", "border-bottom": "1px solid " + RULE });
|
|
51
|
+
bar.append(el("strong", {}, "weft dev"));
|
|
52
|
+
for (const [key, label] of [["tree", "Tree"], ["messages", "Messages"], ["data", "Data"], ["access", "Access"], ["time", "Time"], ["viewas", "View as"]]) {
|
|
53
|
+
const b = el("button", { font: "inherit", background: "none", border: "0", padding: "0", cursor: "pointer", color: MUTED }, label);
|
|
54
|
+
b.type = "button";
|
|
55
|
+
b.dataset.view = key;
|
|
56
|
+
b.addEventListener("click", () => { view = key; draw(); });
|
|
57
|
+
bar.append(b);
|
|
58
|
+
}
|
|
59
|
+
const status = el("span", { "margin-left": "auto", color: MUTED });
|
|
60
|
+
status.dataset.role = "status";
|
|
61
|
+
const close = el("button", { font: "inherit", background: "none", border: "1px solid " + RULE, padding: "0 8px", cursor: "pointer" }, "Close");
|
|
62
|
+
close.type = "button";
|
|
63
|
+
close.addEventListener("click", closePanel);
|
|
64
|
+
bar.append(status, close);
|
|
65
|
+
const body = el("div", { flex: "1", overflow: "auto", padding: "8px 12px" });
|
|
66
|
+
body.dataset.role = "body";
|
|
67
|
+
panel.append(bar, body);
|
|
68
|
+
document.body.append(panel);
|
|
69
|
+
toggle.setAttribute("aria-expanded", "true");
|
|
70
|
+
toggle.style.setProperty("display", "none");
|
|
71
|
+
poll();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function closePanel() {
|
|
75
|
+
stop();
|
|
76
|
+
live();
|
|
77
|
+
panel?.remove();
|
|
78
|
+
panel = null;
|
|
79
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
80
|
+
toggle.style.removeProperty("display");
|
|
81
|
+
toggle.focus();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function stop() {
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
timer = null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function poll() {
|
|
90
|
+
stop();
|
|
91
|
+
if (!panel) return;
|
|
92
|
+
const id = lid();
|
|
93
|
+
// Another page now (client navigation): its own states, from live.
|
|
94
|
+
if (shown !== null && (id !== shownLid || !document.contains(shownRoot))) live();
|
|
95
|
+
if (!id) {
|
|
96
|
+
last = null;
|
|
97
|
+
draw("This page is inert: it sends no live page, so there is nothing to inspect.");
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
const res = await fetch("/_weft/dev/inspect?lid=" + encodeURIComponent(id), { credentials: "same-origin", cache: "no-store" });
|
|
102
|
+
if (res.ok) { last = await res.json(); draw(); }
|
|
103
|
+
else { last = null; draw(res.status === 404 ? "The live page expired or belongs to another session." : "Inspect failed: HTTP " + res.status); }
|
|
104
|
+
} catch {
|
|
105
|
+
last = null;
|
|
106
|
+
draw("The dev server is not answering.");
|
|
107
|
+
}
|
|
108
|
+
if (panel) timer = setTimeout(poll, 1000);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function table(head, rows) {
|
|
112
|
+
const t = el("table", { "border-collapse": "collapse", width: "100%" });
|
|
113
|
+
const tr = el("tr", {});
|
|
114
|
+
for (const h of head) tr.append(el("th", { "text-align": "left", color: MUTED, "font-weight": "normal", "border-bottom": "1px solid " + RULE, padding: "2px 12px 2px 0" }, h));
|
|
115
|
+
t.append(tr);
|
|
116
|
+
for (const row of rows) {
|
|
117
|
+
const r = el("tr", {});
|
|
118
|
+
for (const cell of row) {
|
|
119
|
+
const td = el("td", { padding: "2px 12px 2px 0", "vertical-align": "top", "border-bottom": "1px solid #ececea" });
|
|
120
|
+
if (cell && typeof cell === "object") { td.textContent = cell.text; css(td, { color: cell.color }); }
|
|
121
|
+
else td.textContent = String(cell);
|
|
122
|
+
r.append(td);
|
|
123
|
+
}
|
|
124
|
+
t.append(r);
|
|
125
|
+
}
|
|
126
|
+
return t;
|
|
127
|
+
}
|
|
128
|
+
function empty(text) {
|
|
129
|
+
return el("p", { color: MUTED, margin: "0" }, text);
|
|
130
|
+
}
|
|
131
|
+
function clock(ms) {
|
|
132
|
+
const d = new Date(ms);
|
|
133
|
+
return d.toLocaleTimeString(undefined, { hour12: false }) + "." + String(d.getMilliseconds()).padStart(3, "0");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The "View as" form, built once so a refresh keeps what is typed in it.
|
|
137
|
+
function viewAsForm() {
|
|
138
|
+
if (viewForm) return viewForm;
|
|
139
|
+
viewForm = el("form", { display: "flex", "flex-wrap": "wrap", gap: "8px", "align-items": "baseline", margin: "0 0 8px" });
|
|
140
|
+
const field = (label, name) => {
|
|
141
|
+
const l = el("label", { display: "flex", gap: "4px", "align-items": "baseline" }, label);
|
|
142
|
+
const i = el("input", { font: "inherit", border: "1px solid " + RULE, padding: "1px 4px", background: "#fff", color: INK });
|
|
143
|
+
i.name = name;
|
|
144
|
+
i.autocomplete = "off";
|
|
145
|
+
i.spellcheck = false;
|
|
146
|
+
l.append(i);
|
|
147
|
+
return l;
|
|
148
|
+
};
|
|
149
|
+
const go = el("button", { font: "inherit", border: "1px solid " + RULE, background: "#fff", padding: "0 8px", cursor: "pointer" }, "View as");
|
|
150
|
+
go.type = "submit";
|
|
151
|
+
const back = el("button", { font: "inherit", border: "1px solid " + RULE, background: "#fff", padding: "0 8px", cursor: "pointer" }, "Back to me");
|
|
152
|
+
back.type = "button";
|
|
153
|
+
back.dataset.role = "stop";
|
|
154
|
+
const said = el("p", { margin: "0", width: "100%", color: MUTED });
|
|
155
|
+
said.dataset.role = "viewing";
|
|
156
|
+
viewForm.append(field("User id", "user"), field("Tenant (optional)", "tenant"), go, back, said);
|
|
157
|
+
viewForm.addEventListener("submit", (e) => {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
const user = viewForm.elements.user.value.trim();
|
|
160
|
+
const tenant = viewForm.elements.tenant.value.trim();
|
|
161
|
+
sendViewAs(tenant ? { user, tenant } : { user });
|
|
162
|
+
});
|
|
163
|
+
back.addEventListener("click", () => sendViewAs({ user: null }));
|
|
164
|
+
return viewForm;
|
|
165
|
+
}
|
|
166
|
+
async function sendViewAs(body) {
|
|
167
|
+
viewNote = "...";
|
|
168
|
+
draw();
|
|
169
|
+
try {
|
|
170
|
+
const res = await fetch("/_weft/dev/view-as", {
|
|
171
|
+
method: "POST", credentials: "same-origin", cache: "no-store",
|
|
172
|
+
headers: { "content-type": "application/json" }, body: JSON.stringify(body),
|
|
173
|
+
});
|
|
174
|
+
const out = await res.json().catch(() => ({}));
|
|
175
|
+
viewNote = out.ok ? (out.viewing ? "Now viewing as " + out.viewing.user + "." : "Back to your own view.")
|
|
176
|
+
: (out.reason || "View as failed: HTTP " + res.status);
|
|
177
|
+
} catch {
|
|
178
|
+
viewNote = "The dev server is not answering.";
|
|
179
|
+
}
|
|
180
|
+
poll();
|
|
181
|
+
}
|
|
182
|
+
function drawViewAs(body) {
|
|
183
|
+
const form = viewAsForm();
|
|
184
|
+
if (!body.contains(form)) {
|
|
185
|
+
body.append(form, empty("Pages load and render as that user, read-only: every write rule refuses, and the reads are "
|
|
186
|
+
+ "audited as that user via you. It lasts an hour or until Back to me. Sign in first."));
|
|
187
|
+
}
|
|
188
|
+
const v = last && last.viewing;
|
|
189
|
+
form.querySelector('[data-role="viewing"]').textContent = (viewNote ? viewNote + " " : "")
|
|
190
|
+
+ (v ? "This session sees the app as id " + v.user + (v.tenant ? " in " + v.tenant : "") + " until " + clock(v.until) + "."
|
|
191
|
+
: "This session sees the app as you.");
|
|
192
|
+
form.querySelector('[data-role="stop"]').disabled = !v;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// The live page's root instance (the body's first data-weft-c).
|
|
196
|
+
function liveRoot() {
|
|
197
|
+
return document.querySelector("body [data-weft-c]");
|
|
198
|
+
}
|
|
199
|
+
// Show step n in place of the page: its HTML with every runtime hook
|
|
200
|
+
// (data-weft-* attributes, scripts, inline handlers) taken out, inert, after the live
|
|
201
|
+
// root, which is hidden and keeps receiving its patches.
|
|
202
|
+
async function showStep(n) {
|
|
203
|
+
const id = lid();
|
|
204
|
+
try {
|
|
205
|
+
const res = await fetch("/_weft/dev/frame?lid=" + encodeURIComponent(id) + "&n=" + n, { credentials: "same-origin", cache: "no-store" });
|
|
206
|
+
if (!res.ok) { shownNote = res.status === 404 ? "That step is no longer kept." : "HTTP " + res.status; draw(); return; }
|
|
207
|
+
const f = await res.json();
|
|
208
|
+
const doc = new DOMParser().parseFromString("<body>" + f.html + "</body>", "text/html");
|
|
209
|
+
for (const s of doc.querySelectorAll("script")) s.remove();
|
|
210
|
+
for (const node of doc.body.querySelectorAll("*")) {
|
|
211
|
+
for (const a of [...node.attributes]) {
|
|
212
|
+
if (a.name.startsWith("data-weft-") || a.name.startsWith("on")) node.removeAttribute(a.name);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const rootEl = liveRoot();
|
|
216
|
+
if (!rootEl) return;
|
|
217
|
+
if (!shownBox) {
|
|
218
|
+
shownBox = document.createElement("div");
|
|
219
|
+
shownBox.id = "weft-dev-step";
|
|
220
|
+
shownBox.inert = true;
|
|
221
|
+
shownBox.setAttribute("aria-label", "An earlier state of this page (read-only)");
|
|
222
|
+
rootEl.after(shownBox);
|
|
223
|
+
}
|
|
224
|
+
shownBox.replaceChildren(...doc.body.childNodes);
|
|
225
|
+
rootEl.style.setProperty("display", "none", "important");
|
|
226
|
+
shownRoot = rootEl;
|
|
227
|
+
shownLid = id;
|
|
228
|
+
shown = f.n;
|
|
229
|
+
shownNote = "";
|
|
230
|
+
} catch {
|
|
231
|
+
shownNote = "The dev server is not answering.";
|
|
232
|
+
}
|
|
233
|
+
draw();
|
|
234
|
+
}
|
|
235
|
+
// Save the page's events (values redacted) as a file for weft replay.
|
|
236
|
+
async function download() {
|
|
237
|
+
try {
|
|
238
|
+
const res = await fetch("/_weft/dev/recording?lid=" + encodeURIComponent(lid()), { credentials: "same-origin", cache: "no-store" });
|
|
239
|
+
if (!res.ok) { shownNote = "Recording failed: HTTP " + res.status; draw(); return; }
|
|
240
|
+
const url = URL.createObjectURL(await res.blob());
|
|
241
|
+
const a = document.createElement("a");
|
|
242
|
+
a.href = url;
|
|
243
|
+
a.download = (location.pathname.replace(/[^A-Za-z0-9]+/g, "-").replace(/^-|-$/g, "") || "index") + ".weft-recording.json";
|
|
244
|
+
document.body.append(a);
|
|
245
|
+
a.click();
|
|
246
|
+
a.remove();
|
|
247
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
248
|
+
shownNote = "Saved. Replay it with: weft replay " + a.download;
|
|
249
|
+
} catch {
|
|
250
|
+
shownNote = "The dev server is not answering.";
|
|
251
|
+
}
|
|
252
|
+
draw();
|
|
253
|
+
}
|
|
254
|
+
// Back to the live page.
|
|
255
|
+
function live() {
|
|
256
|
+
shownBox?.remove();
|
|
257
|
+
shownRoot?.style.removeProperty("display");
|
|
258
|
+
shownBox = null;
|
|
259
|
+
shownRoot = null;
|
|
260
|
+
shown = null;
|
|
261
|
+
}
|
|
262
|
+
function button(label, onClick, disabled) {
|
|
263
|
+
const b = el("button", { font: "inherit", border: "1px solid " + RULE, background: "#fff", padding: "0 8px", cursor: disabled ? "default" : "pointer" }, label);
|
|
264
|
+
b.type = "button";
|
|
265
|
+
b.disabled = !!disabled;
|
|
266
|
+
b.addEventListener("click", onClick);
|
|
267
|
+
return b;
|
|
268
|
+
}
|
|
269
|
+
function drawTime(body) {
|
|
270
|
+
const frames = last.frames || [];
|
|
271
|
+
if (frames.length === 0) { body.append(empty("No states kept yet.")); return; }
|
|
272
|
+
const at = shown === null ? frames.length - 1 : frames.findIndex((f) => f.n === shown);
|
|
273
|
+
const bar = el("div", { display: "flex", gap: "8px", "align-items": "baseline", margin: "0 0 8px" });
|
|
274
|
+
bar.dataset.role = "time";
|
|
275
|
+
bar.append(
|
|
276
|
+
button("Back", () => showStep(frames[Math.max(0, at - 1)].n), at <= 0),
|
|
277
|
+
button("Forward", () => (at + 1 >= frames.length - 1 && shown !== null ? (live(), draw()) : showStep(frames[at + 1].n)), shown === null),
|
|
278
|
+
button("Live", () => { live(); draw(); }, shown === null),
|
|
279
|
+
button("Download recording", download),
|
|
280
|
+
el("span", { color: shown === null ? MUTED : WARN },
|
|
281
|
+
shown === null ? "Showing the live page." : "Showing step " + shown + ", read-only: the live page goes on behind it."),
|
|
282
|
+
);
|
|
283
|
+
body.append(bar);
|
|
284
|
+
if (shownNote) body.append(empty(shownNote));
|
|
285
|
+
body.append(table(["Step", "Time", "After", "Size"], frames.slice().reverse().map((f) => [
|
|
286
|
+
{ text: (f.n === shown || (shown === null && f === frames[frames.length - 1]) ? "> " : " ") + f.n, color: f.n === shown ? WARN : INK },
|
|
287
|
+
clock(f.at), f.what, (f.bytes / 1024).toFixed(1) + " KB",
|
|
288
|
+
])));
|
|
289
|
+
for (const [i, row] of [...body.querySelectorAll("tr")].slice(1).entries()) {
|
|
290
|
+
const f = frames[frames.length - 1 - i];
|
|
291
|
+
css(row, { cursor: "pointer" });
|
|
292
|
+
row.addEventListener("click", () => (f === frames[frames.length - 1] ? (live(), draw()) : showStep(f.n)));
|
|
293
|
+
}
|
|
294
|
+
body.append(empty("The page's HTML after each event and refresh (the last " + frames.length + " kept). Island and client-drawn state is not part of it."));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function draw(notice) {
|
|
298
|
+
if (!panel) return;
|
|
299
|
+
for (const b of panel.querySelectorAll("button[data-view]")) {
|
|
300
|
+
const on = b.dataset.view === view;
|
|
301
|
+
css(b, { color: on ? INK : MUTED, "text-decoration": on ? "underline" : "none" });
|
|
302
|
+
b.setAttribute("aria-pressed", String(on));
|
|
303
|
+
}
|
|
304
|
+
if (view === "viewas") {
|
|
305
|
+
const status = panel.querySelector('[data-role="status"]');
|
|
306
|
+
const body = panel.querySelector('[data-role="body"]');
|
|
307
|
+
status.textContent = last ? last.path + " page " + last.lid.slice(0, 8) : "";
|
|
308
|
+
if (!body.contains(viewForm)) body.replaceChildren();
|
|
309
|
+
drawViewAs(body);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
const status = panel.querySelector('[data-role="status"]');
|
|
313
|
+
const body = panel.querySelector('[data-role="body"]');
|
|
314
|
+
const top = body.scrollTop;
|
|
315
|
+
body.replaceChildren();
|
|
316
|
+
if (!last) {
|
|
317
|
+
status.textContent = "";
|
|
318
|
+
body.append(empty(notice || "Loading..."));
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
status.textContent = last.path + " page " + last.lid.slice(0, 8);
|
|
322
|
+
if (view === "tree") {
|
|
323
|
+
const rows = [];
|
|
324
|
+
const walk = (n, depth) => {
|
|
325
|
+
rows.push([" ".repeat(depth) + n.name + (n.island ? " (island)" : ""), n.id, n.renders, n.ms.toFixed(2) + " ms"]);
|
|
326
|
+
for (const c of n.children) walk(c, depth + 1);
|
|
327
|
+
};
|
|
328
|
+
walk(last.tree, 0);
|
|
329
|
+
body.append(table(["Component", "Instance", "Renders", "Last render"], rows));
|
|
330
|
+
body.append(empty("Inert components are drawn inline into their parent and do not appear as instances."));
|
|
331
|
+
} else if (view === "messages") {
|
|
332
|
+
if (last.messages.length === 0) body.append(empty("No live messages yet. Interact with the page."));
|
|
333
|
+
else body.append(table(["Time", "", "Message", "Handled in", "Sent"], last.messages.slice().reverse().map((m) => [
|
|
334
|
+
clock(m.at), m.dir === "in" ? "event" : m.dir === "warn" ? "warning" : "push", m.what, m.ms === undefined ? "" : m.ms.toFixed(1) + " ms", m.out.join(", ") || "nothing",
|
|
335
|
+
])));
|
|
336
|
+
} else if (view === "data") {
|
|
337
|
+
const rows = [];
|
|
338
|
+
for (const [pass, list] of [["load", last.reads.load], ["render", last.reads.render]]) {
|
|
339
|
+
for (const r of list) rows.push([pass, r.model, r.scope.join(", ")]);
|
|
340
|
+
}
|
|
341
|
+
if (rows.length === 0) body.append(empty("The last load and render read no models."));
|
|
342
|
+
else body.append(table(["Pass", "Model", "Read as"], rows));
|
|
343
|
+
body.append(empty("Built-in sync refreshes this page when a change to one of these models is visible to one of these actors."
|
|
344
|
+
+ (last.stores ? " Its load also read " + last.stores + " store(s)." : "")));
|
|
345
|
+
const k = last.cost;
|
|
346
|
+
body.append(empty("Since it opened, this page handled " + k.events + " event(s) and " + k.refreshes + " refresh(es) in "
|
|
347
|
+
+ k.ms.toFixed(1) + " ms of server time, and was sent " + (k.bytes / 1024).toFixed(1) + " KB."));
|
|
348
|
+
const cap = last.capacity;
|
|
349
|
+
body.append(empty("It holds about " + (k.heldBytes / 1024).toFixed(1) + " KB (estimate: its HTML and load data)."
|
|
350
|
+
+ (cap ? " At " + (cap.perPage / 1024).toFixed(1) + " KB a page, about " + cap.pages + " more pages of " + cap.route
|
|
351
|
+
+ " fit in the " + ((cap.heapLimit - cap.heapUsed) / 1048576).toFixed(0) + " MB of heap left (estimate)." : "")));
|
|
352
|
+
} else if (view === "time") {
|
|
353
|
+
drawTime(body);
|
|
354
|
+
} else {
|
|
355
|
+
if (last.decisions.length === 0) body.append(empty("No data-rule decisions recorded for this session yet."));
|
|
356
|
+
else body.append(table(["Time", "Model", "Action", "Outcome", "Rows", "Actor", "Reason"], last.decisions.slice().reverse().map((d) => [
|
|
357
|
+
clock(d.at), d.model, d.action, { text: d.outcome, color: d.outcome === "denied" ? WARN : OK }, d.count, d.actor, d.reason || "",
|
|
358
|
+
])));
|
|
359
|
+
}
|
|
360
|
+
body.scrollTop = top;
|
|
361
|
+
}
|
|
362
|
+
`;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type AuditEvent } from "@weft-framework/data";
|
|
2
|
+
import type { ServerMessage } from "@weft-framework/runtime";
|
|
3
|
+
import type { InspectNode } from "./live.js";
|
|
4
|
+
import type { Deps } from "./sync.js";
|
|
5
|
+
import type { RecordedStep } from "./replay.js";
|
|
6
|
+
export declare const DEV_LOG_MAX = 100;
|
|
7
|
+
export interface DevMessage {
|
|
8
|
+
at: number;
|
|
9
|
+
dir: "in" | "push" | "warn";
|
|
10
|
+
what: string;
|
|
11
|
+
ms?: number;
|
|
12
|
+
out: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface DevDecision {
|
|
15
|
+
at: number;
|
|
16
|
+
model: string;
|
|
17
|
+
action: string;
|
|
18
|
+
outcome: "allowed" | "denied";
|
|
19
|
+
count: number;
|
|
20
|
+
actor: string;
|
|
21
|
+
reason?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const DEV_FRAMES_MAX = 50;
|
|
24
|
+
export declare const DEV_FRAMES_BYTES: number;
|
|
25
|
+
export interface DevFrame {
|
|
26
|
+
n: number;
|
|
27
|
+
at: number;
|
|
28
|
+
what: string;
|
|
29
|
+
html: string;
|
|
30
|
+
}
|
|
31
|
+
export interface DevLog {
|
|
32
|
+
messages: DevMessage[];
|
|
33
|
+
frames: DevFrame[];
|
|
34
|
+
step: number;
|
|
35
|
+
opened: number;
|
|
36
|
+
steps: RecordedStep[];
|
|
37
|
+
}
|
|
38
|
+
export interface DevRead {
|
|
39
|
+
model: string;
|
|
40
|
+
scope: string[];
|
|
41
|
+
}
|
|
42
|
+
export interface DevSnapshot {
|
|
43
|
+
viewing: {
|
|
44
|
+
user: string;
|
|
45
|
+
operator: string;
|
|
46
|
+
until: number;
|
|
47
|
+
tenant?: string;
|
|
48
|
+
} | null;
|
|
49
|
+
lid: string;
|
|
50
|
+
path: string;
|
|
51
|
+
tree: InspectNode;
|
|
52
|
+
messages: DevMessage[];
|
|
53
|
+
frames: {
|
|
54
|
+
n: number;
|
|
55
|
+
at: number;
|
|
56
|
+
what: string;
|
|
57
|
+
bytes: number;
|
|
58
|
+
}[];
|
|
59
|
+
decisions: DevDecision[];
|
|
60
|
+
reads: {
|
|
61
|
+
load: DevRead[];
|
|
62
|
+
render: DevRead[];
|
|
63
|
+
};
|
|
64
|
+
stores: number;
|
|
65
|
+
cost: {
|
|
66
|
+
events: number;
|
|
67
|
+
refreshes: number;
|
|
68
|
+
ms: number;
|
|
69
|
+
bytes: number;
|
|
70
|
+
heldBytes: number;
|
|
71
|
+
};
|
|
72
|
+
capacity: {
|
|
73
|
+
route: string;
|
|
74
|
+
heapLimit: number;
|
|
75
|
+
heapUsed: number;
|
|
76
|
+
perPage: number;
|
|
77
|
+
pages: number;
|
|
78
|
+
} | null;
|
|
79
|
+
}
|
|
80
|
+
export declare function devLog(): DevLog;
|
|
81
|
+
export declare function frame(log: DevLog, what: string, html: string, at?: number): void;
|
|
82
|
+
export declare function frameList(log: DevLog | undefined): DevSnapshot["frames"];
|
|
83
|
+
export declare function note<T>(list: T[], item: T): void;
|
|
84
|
+
export declare function describe(msg: ServerMessage): string;
|
|
85
|
+
export declare function actorLabel(actor: unknown): string;
|
|
86
|
+
export declare function decision(ev: AuditEvent): DevDecision;
|
|
87
|
+
export declare function readsOf(deps: Deps<unknown>): DevRead[];
|
package/dist/devtools.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { UNSCOPED } from "@weft-framework/data";
|
|
2
|
+
export const DEV_LOG_MAX = 100;
|
|
3
|
+
export const DEV_FRAMES_MAX = 50;
|
|
4
|
+
export const DEV_FRAMES_BYTES = 2 * 1024 * 1024;
|
|
5
|
+
export function devLog() {
|
|
6
|
+
return { messages: [], frames: [], step: 0, opened: Date.now(), steps: [] };
|
|
7
|
+
}
|
|
8
|
+
export function frame(log, what, html, at = Date.now()) {
|
|
9
|
+
if (log.frames.at(-1)?.html === html)
|
|
10
|
+
return;
|
|
11
|
+
log.frames.push({ n: log.step++, at, what, html });
|
|
12
|
+
let bytes = log.frames.reduce((sum, f) => sum + f.html.length, 0);
|
|
13
|
+
while (log.frames.length > 1 && (log.frames.length > DEV_FRAMES_MAX || bytes > DEV_FRAMES_BYTES)) {
|
|
14
|
+
bytes -= log.frames.shift().html.length;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function frameList(log) {
|
|
18
|
+
return (log?.frames ?? []).map((f) => ({ n: f.n, at: f.at, what: f.what, bytes: enc.encode(f.html).length }));
|
|
19
|
+
}
|
|
20
|
+
const enc = new TextEncoder();
|
|
21
|
+
export function note(list, item) {
|
|
22
|
+
list.push(item);
|
|
23
|
+
if (list.length > DEV_LOG_MAX)
|
|
24
|
+
list.splice(0, list.length - DEV_LOG_MAX);
|
|
25
|
+
}
|
|
26
|
+
export function describe(msg) {
|
|
27
|
+
switch (msg.t) {
|
|
28
|
+
case "patch":
|
|
29
|
+
return `patch ${msg.id} (${new TextEncoder().encode(msg.html).length} B)`;
|
|
30
|
+
case "redirect":
|
|
31
|
+
return `redirect ${msg.to}`;
|
|
32
|
+
case "error":
|
|
33
|
+
return `error: ${msg.message}`;
|
|
34
|
+
case "ack":
|
|
35
|
+
return "ack";
|
|
36
|
+
case "head":
|
|
37
|
+
return `head "${msg.title}"`;
|
|
38
|
+
default:
|
|
39
|
+
return msg.t;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function actorLabel(actor) {
|
|
43
|
+
if (actor === UNSCOPED)
|
|
44
|
+
return "unscoped";
|
|
45
|
+
if (actor === null || actor === undefined)
|
|
46
|
+
return "anonymous";
|
|
47
|
+
if (typeof actor === "object" && "id" in actor)
|
|
48
|
+
return `id ${String(actor.id)}`;
|
|
49
|
+
if (typeof actor === "string" || typeof actor === "number")
|
|
50
|
+
return `id ${actor}`;
|
|
51
|
+
return "actor";
|
|
52
|
+
}
|
|
53
|
+
export function decision(ev) {
|
|
54
|
+
const d = {
|
|
55
|
+
at: ev.at.getTime(),
|
|
56
|
+
model: ev.model,
|
|
57
|
+
action: ev.action,
|
|
58
|
+
outcome: ev.outcome,
|
|
59
|
+
count: ev.count,
|
|
60
|
+
actor: actorLabel(ev.actor) + (ev.via !== undefined ? ` (via id ${ev.via})` : ""),
|
|
61
|
+
};
|
|
62
|
+
if (ev.reason !== undefined)
|
|
63
|
+
d.reason = ev.reason;
|
|
64
|
+
return d;
|
|
65
|
+
}
|
|
66
|
+
export function readsOf(deps) {
|
|
67
|
+
return [...deps.reads].map(([model, r]) => ({ model, scope: [...r.actors].map(actorLabel) }));
|
|
68
|
+
}
|
package/dist/edge.d.ts
ADDED
package/dist/edge.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { SqlDatabase } from "@weft-framework/data";
|
|
2
|
+
import type { PageContext } from "./context.js";
|
|
3
|
+
import type { Identity } from "./oauth.js";
|
|
4
|
+
type Maybe<T> = T | Promise<T>;
|
|
5
|
+
export interface EmailToken {
|
|
6
|
+
id: string;
|
|
7
|
+
email: string;
|
|
8
|
+
code: string;
|
|
9
|
+
session: string;
|
|
10
|
+
next: string;
|
|
11
|
+
expires: number;
|
|
12
|
+
attempts: number;
|
|
13
|
+
}
|
|
14
|
+
export interface EmailTokenStore {
|
|
15
|
+
add(token: EmailToken): Maybe<void>;
|
|
16
|
+
get(id: string): Maybe<EmailToken | null | undefined>;
|
|
17
|
+
find(session: string, email: string): Maybe<EmailToken | null | undefined>;
|
|
18
|
+
attempt(id: string): Maybe<number>;
|
|
19
|
+
take(id: string): Maybe<boolean>;
|
|
20
|
+
clear(session: string, email: string): Maybe<void>;
|
|
21
|
+
sweep(now: number): Maybe<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare class MemoryEmailTokenStore implements EmailTokenStore {
|
|
24
|
+
#private;
|
|
25
|
+
add(t: EmailToken): void;
|
|
26
|
+
get(id: string): EmailToken | null;
|
|
27
|
+
find(session: string, email: string): EmailToken | null;
|
|
28
|
+
attempt(id: string): number;
|
|
29
|
+
take(id: string): boolean;
|
|
30
|
+
clear(session: string, email: string): void;
|
|
31
|
+
sweep(now: number): void;
|
|
32
|
+
}
|
|
33
|
+
export declare class SqlEmailTokenStore implements EmailTokenStore {
|
|
34
|
+
private readonly db;
|
|
35
|
+
private readonly table;
|
|
36
|
+
constructor(db: SqlDatabase, table?: string);
|
|
37
|
+
private row;
|
|
38
|
+
add(t: EmailToken): void;
|
|
39
|
+
get(id: string): EmailToken | null;
|
|
40
|
+
find(session: string, email: string): EmailToken | null;
|
|
41
|
+
attempt(id: string): number;
|
|
42
|
+
take(id: string): boolean;
|
|
43
|
+
clear(session: string, email: string): void;
|
|
44
|
+
sweep(now: number): void;
|
|
45
|
+
}
|
|
46
|
+
export interface EmailSignInMessage {
|
|
47
|
+
email: string;
|
|
48
|
+
link: string;
|
|
49
|
+
code: string;
|
|
50
|
+
expires: Date;
|
|
51
|
+
}
|
|
52
|
+
export interface EmailSignInOptions {
|
|
53
|
+
url: string;
|
|
54
|
+
page: string;
|
|
55
|
+
send(message: EmailSignInMessage): Maybe<void>;
|
|
56
|
+
allow?(email: string): Maybe<boolean>;
|
|
57
|
+
ttlMs?: number;
|
|
58
|
+
codeLength?: number;
|
|
59
|
+
maxAttempts?: number;
|
|
60
|
+
perEmail?: number;
|
|
61
|
+
perSession?: number;
|
|
62
|
+
store?: EmailTokenStore;
|
|
63
|
+
now?(): number;
|
|
64
|
+
}
|
|
65
|
+
export declare class EmailSignInError extends Error {
|
|
66
|
+
readonly code: "invalid" | "limit";
|
|
67
|
+
constructor(code: "invalid" | "limit", message: string);
|
|
68
|
+
}
|
|
69
|
+
export declare const EMAIL_PATH = "/_weft/auth/email";
|
|
70
|
+
export interface EmailPending {
|
|
71
|
+
email: string;
|
|
72
|
+
token: string;
|
|
73
|
+
action: string;
|
|
74
|
+
}
|
|
75
|
+
export declare function normalizeEmail(raw: unknown): string | null;
|
|
76
|
+
export declare class EmailSignIn {
|
|
77
|
+
#private;
|
|
78
|
+
readonly page: string;
|
|
79
|
+
constructor(o: EmailSignInOptions);
|
|
80
|
+
request(ctx: PageContext, email: string, opts?: {
|
|
81
|
+
next?: string;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
verify(ctx: PageContext, email: string, code: string): Promise<boolean>;
|
|
84
|
+
pending(ctx: PageContext): Promise<EmailPending | null>;
|
|
85
|
+
consume(token: string): Promise<{
|
|
86
|
+
email: string;
|
|
87
|
+
next: string;
|
|
88
|
+
} | null>;
|
|
89
|
+
}
|
|
90
|
+
export declare function identityFor(email: string): Identity;
|
|
91
|
+
export declare function emailSignIn(o: EmailSignInOptions): EmailSignIn;
|
|
92
|
+
export {};
|