create-pmos 0.381.0 → 0.383.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/package.json +30 -40
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/REMOTE.md +39 -0
- package/workspace/briefing-premium-calendar-test.js +1 -1
- package/workspace/briefing-premium-initiative-test.js +2 -2
- package/workspace/briefing-premium-test.js +1 -1
- package/workspace/changelog.json +29 -0
- package/workspace/guide/briefing-premium.md +5 -1
- package/workspace/lib/briefing-premium-agent.js +19 -9
- package/workspace/lib/routes-briefing-premium.js +1 -1
- package/workspace/lib/share-store.js +150 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-viewer-download-test.js +179 -0
- package/workspace/premium-viewer-share-test.js +208 -0
- package/workspace/premium-work-depth-test.js +1 -1
- package/workspace/public/pm/premium-acts.js +3 -4
- package/workspace/public/pm/premium-initiative.js +6 -8
- package/workspace/public/pm/premium-insights.js +5 -7
- package/workspace/public/pm/premium-meeting.js +1 -2
- package/workspace/public/pm/premium-report-read.js +4 -3
- package/workspace/public/pm/premium-shell.js +16 -7
- package/workspace/public/pm/premium-vw-doc.css +44 -0
- package/workspace/public/pm/premium-vw-file.js +95 -6
- package/workspace/public/pm/premium-vw-share.js +112 -0
- package/workspace/public/pm/premium-work.js +4 -4
- package/workspace/public/pm/premium.css +1 -1
- package/workspace/public/pm/premium.js +7 -7
- package/workspace/server.js +82 -0
- package/workspace/share-server.js +135 -0
- package/workspace/test-lists/premium-viewer-share.json +11 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* share-server.js — the one PMOS server that answers someone with no PMOS login (premium-viewer-share slice 2, D97).
|
|
4
|
+
*
|
|
5
|
+
* It is a separate process from the workspace server, on its own loopback port, and it knows nothing of the workspace: no terminal, no
|
|
6
|
+
* API, no WebSocket, no repository, no token, no settings. It reads only the share copies folder (lib/share-store.js) and writes only a
|
|
7
|
+
* link's view count and wrong-password count there. The workspace server starts it and stops it. The PM's Cloudflare tunnel sends the
|
|
8
|
+
* share hostname (share.pm-os.app) here, with no Access application in front; the workspace hostname keeps its Access check.
|
|
9
|
+
*
|
|
10
|
+
* GET /robots.txt Disallow: /
|
|
11
|
+
* GET /s/<id> the password page, or the copy in a sandboxed frame with Download
|
|
12
|
+
* POST /s/<id> the password form (pw=…): a right password sets a cookie for this link only, for 12 hours
|
|
13
|
+
* GET /s/<id>/view the copy itself, under a sandbox CSP (only with a valid cookie when the link has a password)
|
|
14
|
+
* GET /s/<id>/file the file's own text as an attachment (the same rule)
|
|
15
|
+
* anything else 404
|
|
16
|
+
*
|
|
17
|
+
* Every answer: X-Robots-Tag noindex, Cache-Control no-store, Referrer-Policy no-referrer, nosniff, frame-ancestors limited. An unknown,
|
|
18
|
+
* ended or turned-off link reads "This link is no longer active" and names nothing. Nothing is logged (D08).
|
|
19
|
+
*
|
|
20
|
+
* PMOS_SHARE_PORT the port (required) PMOS_STATE_DIR the runtime state folder that holds shares/
|
|
21
|
+
* PMOS_SHARE_PARENT the workspace server's pid: the share server exits when that process is gone
|
|
22
|
+
*/
|
|
23
|
+
const http = require('http');
|
|
24
|
+
const store = require('./lib/share-store');
|
|
25
|
+
|
|
26
|
+
const DIR = process.env.PMOS_STATE_DIR;
|
|
27
|
+
const PORT = Number(process.env.PMOS_SHARE_PORT);
|
|
28
|
+
const HOST = '127.0.0.1';
|
|
29
|
+
|
|
30
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
31
|
+
const BASE_HEADERS = {
|
|
32
|
+
'X-Robots-Tag': 'noindex, nofollow, noarchive', 'Cache-Control': 'no-store, private', 'Referrer-Policy': 'no-referrer',
|
|
33
|
+
'X-Content-Type-Options': 'nosniff', 'Cross-Origin-Opener-Policy': 'same-origin', 'Permissions-Policy': 'camera=(), microphone=(), geolocation=()',
|
|
34
|
+
};
|
|
35
|
+
const PAGE_CSP = "default-src 'none'; style-src 'unsafe-inline'; frame-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'";
|
|
36
|
+
// the copy itself: the viewer's own sandbox (premium-vw-file.js FRAME_CSP), shown only inside its own page
|
|
37
|
+
const VIEW_CSP = (scripts) => `sandbox${scripts ? ' allow-scripts' : ''}; default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:; script-src ${scripts ? "'unsafe-inline'" : "'none'"}; frame-ancestors 'self'; base-uri 'none'; form-action 'none'`;
|
|
38
|
+
|
|
39
|
+
function send(res, status, body, headers = {}) {
|
|
40
|
+
res.writeHead(status, { ...BASE_HEADERS, 'Content-Type': 'text/html; charset=utf-8', 'Content-Security-Policy': PAGE_CSP, 'X-Frame-Options': 'DENY', ...headers });
|
|
41
|
+
res.end(body);
|
|
42
|
+
}
|
|
43
|
+
const STYLE = `<style>:root{color-scheme:light dark;--bg:#f6f6f4;--card:#fff;--ink:#14161f;--mut:#6e7486;--hair:rgba(20,24,40,.12);--solid:#14161f;--on:#fff;--bad:#be3434}
|
|
44
|
+
@media (prefers-color-scheme:dark){:root{--bg:#0e1016;--card:#171a23;--ink:#f3f4f8;--mut:#9aa0b4;--hair:rgba(255,255,255,.12);--solid:#f3f4f8;--on:#14161f;--bad:#f06e6e}}
|
|
45
|
+
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.5 -apple-system,"Segoe UI",system-ui,sans-serif}
|
|
46
|
+
.box{max-width:340px;margin:18vh auto 0;padding:0 16px;text-align:center}h1{font-size:20px;margin:0 0 6px}p{color:var(--mut);margin:0 0 16px}
|
|
47
|
+
input{width:100%;font:inherit;padding:11px 12px;border-radius:12px;border:1px solid var(--hair);background:var(--card);color:var(--ink);margin:0 0 10px}
|
|
48
|
+
button,.btn{display:inline-block;width:100%;font:600 15px/1 inherit;padding:12px;border:0;border-radius:99px;background:var(--solid);color:var(--on);cursor:pointer;text-decoration:none}
|
|
49
|
+
.bad{color:var(--bad)}.wrap{display:flex;flex-direction:column;height:100vh;height:100dvh}iframe{flex:1;width:100%;border:0;background:#fff}
|
|
50
|
+
.bar{display:flex;gap:12px;align-items:center;padding:10px max(16px,env(safe-area-inset-left));border-top:1px solid var(--hair);font-size:13px;color:var(--mut);background:var(--card)}
|
|
51
|
+
.bar span{flex:1;min-width:0}.bar .btn{width:auto;padding:9px 16px;font-size:13px}</style>`;
|
|
52
|
+
const doc = (title, body) => `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="robots" content="noindex,nofollow,noarchive"><title>${esc(title)}</title>${STYLE}</head><body>${body}</body></html>`;
|
|
53
|
+
const gone = (res) => send(res, 404, doc('Link not active', '<div class="box"><h1>This link is no longer active</h1><p>Ask the person who sent it for a new one.</p></div>'));
|
|
54
|
+
const day = (iso) => new Date(iso).toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' });
|
|
55
|
+
function lockPage(res, id, note, status = 200) {
|
|
56
|
+
// the password page names neither PMOS nor the file, so a link preview or a stranger learns nothing from it
|
|
57
|
+
send(res, status, doc('Protected page', `<div class="box"><h1>This page is protected</h1><p${note ? ' class="bad"' : ''}>${esc(note || 'Enter the password you were given.')}</p>`
|
|
58
|
+
+ `<form method="post" action="/s/${esc(id)}"><input type="password" name="pw" autocomplete="current-password" aria-label="Password" placeholder="Password" required autofocus><button type="submit">Open</button></form></div>`));
|
|
59
|
+
}
|
|
60
|
+
function cookieOf(req) {
|
|
61
|
+
const m = /(?:^|;\s*)s=([^;]+)/.exec(String(req.headers.cookie || ''));
|
|
62
|
+
return m ? decodeURIComponent(m[1]) : '';
|
|
63
|
+
}
|
|
64
|
+
function readForm(req) {
|
|
65
|
+
return new Promise((resolve) => {
|
|
66
|
+
let n = 0; const parts = [];
|
|
67
|
+
req.on('data', (c) => { n += c.length; if (n > 2048) { req.destroy(); resolve(null); } else parts.push(c); });
|
|
68
|
+
req.on('end', () => { try { resolve(new URLSearchParams(Buffer.concat(parts).toString('utf8'))); } catch { resolve(null); } });
|
|
69
|
+
req.on('error', () => resolve(null));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function handle(req, res) {
|
|
74
|
+
let url;
|
|
75
|
+
try { url = new URL(req.url, 'http://share.invalid'); } catch { return send(res, 400, doc('Bad request', '')); }
|
|
76
|
+
const p = url.pathname;
|
|
77
|
+
if (req.method !== 'GET' && req.method !== 'HEAD' && req.method !== 'POST') return send(res, 405, doc('Not allowed', ''), { Allow: 'GET, POST' });
|
|
78
|
+
if (p === '/robots.txt' && req.method !== 'POST') { res.writeHead(200, { ...BASE_HEADERS, 'Content-Type': 'text/plain; charset=utf-8' }); return res.end('User-agent: *\nDisallow: /\n'); }
|
|
79
|
+
const m = /^\/s\/([A-Za-z0-9_-]{22})(\/view|\/file)?$/.exec(p);
|
|
80
|
+
if (!m) return send(res, 404, doc('Not found', '<div class="box"><h1>Not found</h1></div>'));
|
|
81
|
+
const id = m[1], part = m[2] || '';
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
const meta = store.get(DIR, id, now);
|
|
84
|
+
if (!meta) return gone(res);
|
|
85
|
+
const open = !meta.pw || store.verifyCookie(meta, cookieOf(req), now);
|
|
86
|
+
|
|
87
|
+
if (req.method === 'POST') {
|
|
88
|
+
if (part) return send(res, 405, doc('Not allowed', ''));
|
|
89
|
+
if (!meta.pw) { res.writeHead(303, { ...BASE_HEADERS, Location: '/s/' + id }); return res.end(); }
|
|
90
|
+
const form = await readForm(req);
|
|
91
|
+
const r = store.checkPassword(DIR, id, form ? form.get('pw') : '', now);
|
|
92
|
+
if (r.ok) {
|
|
93
|
+
const until = now + store.COOKIE_MS;
|
|
94
|
+
res.writeHead(303, { ...BASE_HEADERS, Location: '/s/' + id,
|
|
95
|
+
'Set-Cookie': `s=${encodeURIComponent(store.sign(meta, until))}; Path=/s/${id}; Max-Age=${store.COOKIE_MS / 1000}; HttpOnly; Secure; SameSite=Lax` });
|
|
96
|
+
return res.end();
|
|
97
|
+
}
|
|
98
|
+
if (r.locked) return lockPage(res, id, 'Too many wrong tries. Try again in 15 minutes.', 429);
|
|
99
|
+
return lockPage(res, id, `That password is not right. ${r.left} ${r.left === 1 ? 'try' : 'tries'} left before a 15-minute wait.`, 401);
|
|
100
|
+
}
|
|
101
|
+
if (!open) return part ? gone(res) : lockPage(res, id);
|
|
102
|
+
if (part === '/view') {
|
|
103
|
+
const page = store.readPart(DIR, id, 'page.html');
|
|
104
|
+
if (page == null) return gone(res);
|
|
105
|
+
res.writeHead(200, { ...BASE_HEADERS, 'Content-Type': 'text/html; charset=utf-8', 'Content-Security-Policy': VIEW_CSP(meta.kind === 'html'), 'X-Frame-Options': 'SAMEORIGIN' });
|
|
106
|
+
return res.end(req.method === 'HEAD' ? undefined : page);
|
|
107
|
+
}
|
|
108
|
+
if (part === '/file') {
|
|
109
|
+
const text = store.readPart(DIR, id, 'file');
|
|
110
|
+
if (text == null) return gone(res);
|
|
111
|
+
const name = meta.name.replace(/[^A-Za-z0-9._-]+/g, '-').slice(0, 120) || 'file.txt';
|
|
112
|
+
res.writeHead(200, { ...BASE_HEADERS, 'Content-Type': 'application/octet-stream', 'Content-Disposition': `attachment; filename="${name}"`, 'Content-Security-Policy': "default-src 'none'; sandbox" });
|
|
113
|
+
return res.end(req.method === 'HEAD' ? undefined : text);
|
|
114
|
+
}
|
|
115
|
+
if (req.method === 'GET') store.view(DIR, id, now);
|
|
116
|
+
return send(res, 200, doc(meta.name, `<div class="wrap"><iframe src="/s/${esc(id)}/view" title="${esc(meta.name)}" sandbox="${meta.kind === 'html' ? 'allow-scripts' : ''}" referrerpolicy="no-referrer"></iframe>`
|
|
117
|
+
+ `<div class="bar"><span>A shared copy, made ${esc(day(meta.made))}. The link ends ${esc(day(meta.ends))}.</span><a class="btn" href="/s/${esc(id)}/file" download>Download</a></div></div>`));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function start({ port = PORT, host = HOST } = {}) {
|
|
121
|
+
const server = http.createServer((req, res) => { handle(req, res).catch(() => { try { send(res, 500, doc('Error', '')); } catch { /* the socket is gone */ } }); });
|
|
122
|
+
server.listen(port, host);
|
|
123
|
+
return server;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (require.main === module) {
|
|
127
|
+
if (!DIR || !(PORT > 0)) { console.error('share-server: PMOS_STATE_DIR and PMOS_SHARE_PORT are required'); process.exit(2); }
|
|
128
|
+
const s = start();
|
|
129
|
+
s.on('error', (e) => { console.error('share-server: ' + (e.code === 'EADDRINUSE' ? `port ${PORT} is in use` : 'could not listen')); process.exit(1); });
|
|
130
|
+
process.on('SIGTERM', () => { s.close(); process.exit(0); });
|
|
131
|
+
// it lives only as long as the workspace server that started it: a parent killed without a goodbye leaves no share server behind
|
|
132
|
+
const parent = Number(process.env.PMOS_SHARE_PARENT);
|
|
133
|
+
if (parent > 0) setInterval(() => { try { process.kill(parent, 0); } catch { process.exit(0); } }, 5000).unref();
|
|
134
|
+
}
|
|
135
|
+
module.exports = { start, handle, VIEW_CSP, PAGE_CSP };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Download and share a file from the viewer (premium-viewer-share): the download icon and GET /api/doc/export; share links through lib/share-store.js, POST /api/shares and share-server.js (D97), with the guest's password page. Real server, 390 and 1280 wide.",
|
|
3
|
+
"seconds": {
|
|
4
|
+
"premium-viewer-download-test.js": 30,
|
|
5
|
+
"premium-viewer-share-test.js": 40
|
|
6
|
+
},
|
|
7
|
+
"panels": [
|
|
8
|
+
"premium-viewer-download-test.js",
|
|
9
|
+
"premium-viewer-share-test.js"
|
|
10
|
+
]
|
|
11
|
+
}
|