@rubytech/create-maxy-code 0.1.459 → 0.1.461
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/cron-heartbeat-registration.test.js +57 -28
- package/dist/__tests__/launchd-plist.test.js +26 -0
- package/dist/cron-registration.js +30 -8
- package/dist/index.js +50 -9
- package/dist/launchd-plist.js +1 -1
- package/dist/uninstall.js +9 -3
- package/package.json +1 -1
- package/payload/platform/lib/storage-broker/dist/__tests__/cf-exec.test.js +116 -6
- package/payload/platform/lib/storage-broker/dist/__tests__/cf-exec.test.js.map +1 -1
- package/payload/platform/lib/storage-broker/dist/__tests__/object-limits.test.js +20 -0
- package/payload/platform/lib/storage-broker/dist/__tests__/object-limits.test.js.map +1 -1
- package/payload/platform/lib/storage-broker/dist/__tests__/resource-limits.test.d.ts +2 -0
- package/payload/platform/lib/storage-broker/dist/__tests__/resource-limits.test.d.ts.map +1 -0
- package/payload/platform/lib/storage-broker/dist/__tests__/resource-limits.test.js +41 -0
- package/payload/platform/lib/storage-broker/dist/__tests__/resource-limits.test.js.map +1 -0
- package/payload/platform/lib/storage-broker/dist/cf-exec.d.ts +1 -0
- package/payload/platform/lib/storage-broker/dist/cf-exec.d.ts.map +1 -1
- package/payload/platform/lib/storage-broker/dist/cf-exec.js +116 -48
- package/payload/platform/lib/storage-broker/dist/cf-exec.js.map +1 -1
- package/payload/platform/lib/storage-broker/dist/index.d.ts +1 -0
- package/payload/platform/lib/storage-broker/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/storage-broker/dist/index.js +1 -0
- package/payload/platform/lib/storage-broker/dist/index.js.map +1 -1
- package/payload/platform/lib/storage-broker/dist/object-limits.d.ts +27 -0
- package/payload/platform/lib/storage-broker/dist/object-limits.d.ts.map +1 -1
- package/payload/platform/lib/storage-broker/dist/object-limits.js +27 -7
- package/payload/platform/lib/storage-broker/dist/object-limits.js.map +1 -1
- package/payload/platform/lib/storage-broker/dist/resource-limits.d.ts +102 -0
- package/payload/platform/lib/storage-broker/dist/resource-limits.d.ts.map +1 -0
- package/payload/platform/lib/storage-broker/dist/resource-limits.js +105 -0
- package/payload/platform/lib/storage-broker/dist/resource-limits.js.map +1 -0
- package/payload/platform/lib/storage-broker/src/__tests__/cf-exec.test.ts +130 -7
- package/payload/platform/lib/storage-broker/src/__tests__/object-limits.test.ts +30 -0
- package/payload/platform/lib/storage-broker/src/__tests__/resource-limits.test.ts +49 -0
- package/payload/platform/lib/storage-broker/src/cf-exec.ts +129 -56
- package/payload/platform/lib/storage-broker/src/index.ts +1 -0
- package/payload/platform/lib/storage-broker/src/object-limits.ts +26 -6
- package/payload/platform/lib/storage-broker/src/resource-limits.ts +105 -0
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +5 -4
- package/payload/platform/plugins/cloudflare/PLUGIN.md +3 -1
- package/payload/platform/plugins/cloudflare/bin/portal-enrol.mjs +96 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/auth-route.test.ts +220 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/authorize.test.ts +201 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/file-routes.test.ts +178 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/harness.test.ts +32 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/passcode.test.ts +204 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-enrol.test.ts +207 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/ratelimit.test.ts +77 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/skill-contract.test.ts +46 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/template-config.test.ts +55 -0
- package/payload/platform/plugins/cloudflare/mcp/__tests__/upload-route.test.ts +255 -0
- package/payload/platform/plugins/cloudflare/mcp/package.json +5 -2
- package/payload/platform/plugins/cloudflare/references/r2-object-storage.md +46 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/SKILL.md +125 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/authorize.ts +32 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/log.ts +12 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/passcode.mjs +193 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/ratelimit.ts +55 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/session.ts +85 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/types.ts +44 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/auth.ts +119 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/delete.ts +89 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/download.ts +70 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/files.ts +41 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/upload.ts +151 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/public/index.html +42 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/public/portal.css +113 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/public/portal.js +155 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/schema.sql +73 -0
- package/payload/platform/plugins/cloudflare/skills/data-portal/template/wrangler.toml +21 -0
- package/payload/platform/plugins/cloudflare/skills/site-deploy/SKILL.md +8 -0
- package/payload/platform/plugins/docs/references/outlook-guide.md +3 -3
- package/payload/platform/plugins/docs/references/voice-mirror-guide.md +1 -0
- package/payload/platform/plugins/filesystem/PLUGIN.md +0 -1
- package/payload/platform/plugins/filesystem/mcp/dist/lib/scope.d.ts +14 -10
- package/payload/platform/plugins/filesystem/mcp/dist/lib/scope.d.ts.map +1 -1
- package/payload/platform/plugins/filesystem/mcp/dist/lib/scope.js +14 -10
- package/payload/platform/plugins/filesystem/mcp/dist/lib/scope.js.map +1 -1
- package/payload/platform/plugins/outlook/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/outlook/PLUGIN.md +3 -5
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/detach.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/detach.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/detach.test.js +75 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/detach.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit-removal.test.d.ts +2 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit-removal.test.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit-removal.test.js +187 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit-removal.test.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit.test.js +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/draft-edit.test.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/index.js +3 -2
- package/payload/platform/plugins/outlook/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/lib/attachment-list.d.ts +43 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/attachment-list.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/attachment-list.js +65 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/attachment-list.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/detach.d.ts +65 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/detach.d.ts.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/detach.js +99 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/detach.js.map +1 -0
- package/payload/platform/plugins/outlook/mcp/dist/lib/outbound-attachments.d.ts +6 -1
- package/payload/platform/plugins/outlook/mcp/dist/lib/outbound-attachments.d.ts.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/lib/outbound-attachments.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.d.ts +42 -22
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.d.ts.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.js +59 -23
- package/payload/platform/plugins/outlook/mcp/dist/tools/draft-edit.js.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-attachment.d.ts +15 -16
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-attachment.d.ts.map +1 -1
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-attachment.js +8 -41
- package/payload/platform/plugins/outlook/mcp/dist/tools/mail-attachment.js.map +1 -1
- package/payload/platform/plugins/outlook/references/auth.md +1 -1
- package/payload/platform/plugins/outlook/references/graph-surfaces.md +7 -3
- package/payload/platform/plugins/outlook/skills/outlook/SKILL.md +1 -1
- package/payload/platform/plugins/storage-broker/PLUGIN.md +1 -1
- package/payload/platform/plugins/voice-mirror/PLUGIN.md +19 -7
- package/payload/platform/plugins/voice-mirror/mcp/dist/index.d.ts.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/index.js +35 -16
- package/payload/platform/plugins/voice-mirror/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/lib/admin-user.d.ts +31 -0
- package/payload/platform/plugins/voice-mirror/mcp/dist/lib/admin-user.d.ts.map +1 -0
- package/payload/platform/plugins/voice-mirror/mcp/dist/lib/admin-user.js +87 -0
- package/payload/platform/plugins/voice-mirror/mcp/dist/lib/admin-user.js.map +1 -0
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-distil-profile.d.ts.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-distil-profile.js +111 -12
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-distil-profile.js.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-ingest-session-text.d.ts.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-ingest-session-text.js +2 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-ingest-session-text.js.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-record-feedback.d.ts.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-record-feedback.js +2 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-record-feedback.js.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-retrieve-conditioning.d.ts.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-retrieve-conditioning.js +54 -21
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-retrieve-conditioning.js.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-tag-content.d.ts +2 -2
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-tag-content.d.ts.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-tag-content.js +12 -3
- package/payload/platform/plugins/voice-mirror/mcp/dist/tools/voice-tag-content.js.map +1 -1
- package/payload/platform/plugins/voice-mirror/mcp/scripts/smoke.mjs +444 -0
- package/payload/platform/plugins/voice-mirror/skills/voice-mirror/SKILL.md +18 -2
- package/payload/platform/scripts/__tests__/logs-rotate.test.sh +256 -0
- package/payload/platform/scripts/__tests__/resume-tunnel.test.sh +79 -0
- package/payload/platform/scripts/logs-rotate.sh +204 -0
- package/payload/platform/scripts/resume-tunnel.sh +27 -0
- package/payload/platform/scripts/voice-author-key-audit.sh +155 -0
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +41 -5
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.d.ts +1 -0
- package/payload/platform/services/claude-session-manager/dist/index.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.js +22 -0
- package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/install-start-counter.d.ts +2 -0
- package/payload/platform/services/claude-session-manager/dist/install-start-counter.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/install-start-counter.js +12 -0
- package/payload/platform/services/claude-session-manager/dist/install-start-counter.js.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/mcp-descriptor-resolve.d.ts +17 -0
- package/payload/platform/services/claude-session-manager/dist/mcp-descriptor-resolve.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/mcp-descriptor-resolve.js +88 -0
- package/payload/platform/services/claude-session-manager/dist/mcp-descriptor-resolve.js.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/pty-census.d.ts +122 -9
- package/payload/platform/services/claude-session-manager/dist/pty-census.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-census.js +214 -29
- package/payload/platform/services/claude-session-manager/dist/pty-census.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts +0 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +36 -24
- package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +13 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/session-memory-cap.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/session-memory-cap.js +4 -2
- package/payload/platform/services/claude-session-manager/dist/session-memory-cap.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.d.ts +150 -0
- package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.js +333 -0
- package/payload/platform/services/claude-session-manager/dist/slice-memory-policy.js.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/start-counter.d.ts +10 -0
- package/payload/platform/services/claude-session-manager/dist/start-counter.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/start-counter.js +55 -0
- package/payload/platform/services/claude-session-manager/dist/start-counter.js.map +1 -0
- package/payload/server/{chunk-Q6W4U6HL.js → chunk-JXWFVE5X.js} +83 -39
- package/payload/server/server.js +268 -73
- package/payload/server/{src-3I2RYZFB.js → src-4F37OHLK.js} +11 -1
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/pkce-flow.test.d.ts +0 -2
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/pkce-flow.test.js +0 -215
- package/payload/platform/plugins/outlook/mcp/dist/__tests__/pkce-flow.test.js.map +0 -1
package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/files.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Handler, Logger, PortalEnv } from './_lib/types'
|
|
2
|
+
import { readSessionCookie, resolveSession } from './_lib/session'
|
|
3
|
+
import { q } from './_lib/log'
|
|
4
|
+
|
|
5
|
+
export async function processFiles(
|
|
6
|
+
sessionId: string,
|
|
7
|
+
env: PortalEnv,
|
|
8
|
+
log: Logger,
|
|
9
|
+
nowMs: number,
|
|
10
|
+
): Promise<Handler> {
|
|
11
|
+
const session = await resolveSession(env.DB, sessionId, nowMs)
|
|
12
|
+
if (!session) {
|
|
13
|
+
log('[data-portal] op=list owner=none result=denied')
|
|
14
|
+
return { status: 401, payload: { ok: false, error: 'denied' } }
|
|
15
|
+
}
|
|
16
|
+
// Scoped by ownerId, not by key prefix: the owner is the authority.
|
|
17
|
+
const rows = await env.DB.prepare(
|
|
18
|
+
'SELECT fileId, filename, objectKey, size, uploadedAt, ingested FROM manifest WHERE ownerId = ? ORDER BY uploadedAt DESC',
|
|
19
|
+
)
|
|
20
|
+
.bind(session.ownerId)
|
|
21
|
+
.all<Record<string, unknown>>()
|
|
22
|
+
const files = rows.results ?? []
|
|
23
|
+
log(`[data-portal] op=list owner=${q(session.ownerId)} result=ok files=${files.length}`)
|
|
24
|
+
return { status: 200, payload: { ok: true, files } }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface PagesContext {
|
|
28
|
+
request: Request
|
|
29
|
+
env: PortalEnv
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function onRequestGet(context: PagesContext): Promise<Response> {
|
|
33
|
+
const sessionId = readSessionCookie(context.request.headers.get('cookie')) ?? ''
|
|
34
|
+
const { status, payload } = await processFiles(
|
|
35
|
+
sessionId,
|
|
36
|
+
context.env,
|
|
37
|
+
(line) => console.log(line),
|
|
38
|
+
Date.now(),
|
|
39
|
+
)
|
|
40
|
+
return Response.json(payload, { status })
|
|
41
|
+
}
|
package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/upload.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { Handler, Logger, PortalEnv } from './_lib/types'
|
|
2
|
+
import { readSessionCookie, resolveSession } from './_lib/session'
|
|
3
|
+
import { q } from './_lib/log'
|
|
4
|
+
import { authorizeKey, ownerPrefix } from './_lib/authorize'
|
|
5
|
+
|
|
6
|
+
const MAX_FILENAME = 200
|
|
7
|
+
|
|
8
|
+
// An upload is read wholly into the Function's memory, so it needs a bound or a
|
|
9
|
+
// large one OOMs the isolate — and an OOM emits no [data-portal] line at all,
|
|
10
|
+
// making it exactly the unobservable failure this portal's lifeline exists to
|
|
11
|
+
// prevent. 25 MiB is chosen for the documents this portal is for (invoices,
|
|
12
|
+
// photos, spreadsheets) and is deliberately NOT the storage broker's 100 MiB
|
|
13
|
+
// (task 1695): that one bounds a house-process spike, this one bounds an edge
|
|
14
|
+
// isolate, and the two must move independently.
|
|
15
|
+
const MAX_UPLOAD_BYTES = 25 * 1024 * 1024
|
|
16
|
+
|
|
17
|
+
export async function processUpload(
|
|
18
|
+
sessionId: string,
|
|
19
|
+
filename: string,
|
|
20
|
+
bytes: Uint8Array,
|
|
21
|
+
env: PortalEnv,
|
|
22
|
+
log: Logger,
|
|
23
|
+
newId: () => string,
|
|
24
|
+
now: () => number,
|
|
25
|
+
): Promise<Handler> {
|
|
26
|
+
// `now` is a clock, not a scalar: op=complete reports elapsed time, and a
|
|
27
|
+
// single injected instant cannot measure elapsed anything. It previously
|
|
28
|
+
// printed a hardcoded ms=0, which an operator reads as "took no time" rather
|
|
29
|
+
// than "was never measured".
|
|
30
|
+
const startedMs = now()
|
|
31
|
+
const session = await resolveSession(env.DB, sessionId, startedMs)
|
|
32
|
+
if (!session) {
|
|
33
|
+
log('[data-portal] op=upload owner=none result=denied')
|
|
34
|
+
return { status: 401, payload: { ok: false, error: 'denied' } }
|
|
35
|
+
}
|
|
36
|
+
const owner = session.ownerId
|
|
37
|
+
const uploadId = newId()
|
|
38
|
+
|
|
39
|
+
if (!filename || filename.length > MAX_FILENAME) {
|
|
40
|
+
log(`[data-portal] op=request uploadId=${uploadId} owner=${q(owner)} result=bad-filename`)
|
|
41
|
+
return { status: 400, payload: { ok: false, error: 'filename required' } }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const key = `${ownerPrefix(owner)}${filename}`
|
|
45
|
+
// The key is derived from the session owner, then re-checked through the same
|
|
46
|
+
// gate the other routes use — a filename carrying '..' must not escape.
|
|
47
|
+
if (!authorizeKey(owner, key)) {
|
|
48
|
+
log(`[data-portal] op=request uploadId=${uploadId} owner=${q(owner)} result=bad-filename`)
|
|
49
|
+
return { status: 400, payload: { ok: false, error: 'invalid filename' } }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (bytes.byteLength > MAX_UPLOAD_BYTES) {
|
|
53
|
+
log(
|
|
54
|
+
`[data-portal] op=request uploadId=${uploadId} owner=${q(owner)} filename=${q(filename)} bytes=${bytes.byteLength} result=too-large limit=${MAX_UPLOAD_BYTES}`,
|
|
55
|
+
)
|
|
56
|
+
return {
|
|
57
|
+
status: 413,
|
|
58
|
+
payload: {
|
|
59
|
+
ok: false,
|
|
60
|
+
error: `file is ${bytes.byteLength} bytes, over the ${MAX_UPLOAD_BYTES}-byte limit`,
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
log(
|
|
66
|
+
`[data-portal] op=request uploadId=${uploadId} owner=${q(owner)} filename=${q(filename)} bytes=${bytes.byteLength}`,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
await env.BUCKET.put(key, bytes)
|
|
71
|
+
log(`[data-portal] op=r2-put uploadId=${uploadId} key=${q(key)} result=ok`)
|
|
72
|
+
} catch (err) {
|
|
73
|
+
log(
|
|
74
|
+
`[data-portal] op=r2-put uploadId=${uploadId} key=${q(key)} result=failed err="${(err as Error).message}"`,
|
|
75
|
+
)
|
|
76
|
+
return { status: 502, payload: { ok: false, error: 'store failed' } }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const fileId = newId()
|
|
80
|
+
try {
|
|
81
|
+
// Upsert, not insert. R2 overwrote the object above unconditionally, so a
|
|
82
|
+
// re-upload of the same filename has already replaced the file whatever the
|
|
83
|
+
// manifest does; a plain INSERT would hit `objectKey UNIQUE`, throw, and
|
|
84
|
+
// leave the row describing bytes that no longer exist while telling the
|
|
85
|
+
// person their upload failed. Resetting `ingested` is the load-bearing
|
|
86
|
+
// part: without it a replacement of an already-swept file would never be
|
|
87
|
+
// ingested, and nothing would ever say so.
|
|
88
|
+
await env.DB.prepare(
|
|
89
|
+
`INSERT INTO manifest (fileId, ownerId, filename, objectKey, size, uploadedAt, ingested)
|
|
90
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
91
|
+
ON CONFLICT (objectKey) DO UPDATE SET
|
|
92
|
+
fileId = excluded.fileId,
|
|
93
|
+
size = excluded.size,
|
|
94
|
+
uploadedAt = excluded.uploadedAt,
|
|
95
|
+
ingested = 0`,
|
|
96
|
+
)
|
|
97
|
+
.bind(fileId, owner, filename, key, bytes.byteLength, new Date(startedMs).toISOString(), 0)
|
|
98
|
+
.run()
|
|
99
|
+
log(`[data-portal] op=manifest-write uploadId=${uploadId} rowId=${fileId} result=ok`)
|
|
100
|
+
} catch (err) {
|
|
101
|
+
log(
|
|
102
|
+
`[data-portal] op=manifest-write uploadId=${uploadId} rowId=${fileId} result=failed err="${(err as Error).message}"`,
|
|
103
|
+
)
|
|
104
|
+
return { status: 502, payload: { ok: false, error: 'manifest failed' } }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// The verified post-condition: re-read both sides rather than assume the
|
|
108
|
+
// writes above landed. An orphan object or a phantom row emits no error at
|
|
109
|
+
// request time, which is why this line exists.
|
|
110
|
+
const objectPresent = (await env.BUCKET.head(key)) !== null
|
|
111
|
+
const rowPresent =
|
|
112
|
+
(await env.DB.prepare('SELECT fileId FROM manifest WHERE objectKey = ?').bind(key).first()) !==
|
|
113
|
+
null
|
|
114
|
+
log(
|
|
115
|
+
`[data-portal] op=complete uploadId=${uploadId} ms=${now() - startedMs} objectPresent=${objectPresent} rowPresent=${rowPresent}`,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return { status: 200, payload: { ok: true, fileId, objectPresent, rowPresent } }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface PagesContext {
|
|
122
|
+
request: Request
|
|
123
|
+
env: PortalEnv
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function onRequestPost(context: PagesContext): Promise<Response> {
|
|
127
|
+
const sessionId = readSessionCookie(context.request.headers.get('cookie')) ?? ''
|
|
128
|
+
let filename = ''
|
|
129
|
+
let bytes: Uint8Array
|
|
130
|
+
try {
|
|
131
|
+
const form = await context.request.formData()
|
|
132
|
+
const file = form.get('file')
|
|
133
|
+
if (!(file instanceof File)) {
|
|
134
|
+
return Response.json({ ok: false, error: 'file required' }, { status: 400 })
|
|
135
|
+
}
|
|
136
|
+
filename = file.name
|
|
137
|
+
bytes = new Uint8Array(await file.arrayBuffer())
|
|
138
|
+
} catch {
|
|
139
|
+
return Response.json({ ok: false, error: 'invalid form' }, { status: 400 })
|
|
140
|
+
}
|
|
141
|
+
const { status, payload } = await processUpload(
|
|
142
|
+
sessionId,
|
|
143
|
+
filename,
|
|
144
|
+
bytes,
|
|
145
|
+
context.env,
|
|
146
|
+
(line) => console.log(line),
|
|
147
|
+
() => crypto.randomUUID(),
|
|
148
|
+
() => Date.now(),
|
|
149
|
+
)
|
|
150
|
+
return Response.json(payload, { status })
|
|
151
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>File drop</title>
|
|
7
|
+
<!-- Same-origin: the API is served by this project's own Pages Functions,
|
|
8
|
+
so api-base is deliberately empty (Task 1307's convention). -->
|
|
9
|
+
<meta name="api-base" content="" />
|
|
10
|
+
<link rel="stylesheet" href="/portal.css" />
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<main class="dp-card">
|
|
14
|
+
<h1 class="dp-title">File drop</h1>
|
|
15
|
+
<p id="dp-status" class="dp-status" role="status"></p>
|
|
16
|
+
|
|
17
|
+
<form id="dp-login" class="dp-login">
|
|
18
|
+
<label class="dp-label" for="dp-owner">Your name</label>
|
|
19
|
+
<input class="dp-input" id="dp-owner" name="owner" autocomplete="username" required />
|
|
20
|
+
<label class="dp-label" for="dp-passcode">Passcode</label>
|
|
21
|
+
<input
|
|
22
|
+
class="dp-input"
|
|
23
|
+
id="dp-passcode"
|
|
24
|
+
name="passcode"
|
|
25
|
+
type="password"
|
|
26
|
+
autocomplete="current-password"
|
|
27
|
+
required
|
|
28
|
+
/>
|
|
29
|
+
<button class="dp-btn" type="submit">Sign in</button>
|
|
30
|
+
</form>
|
|
31
|
+
|
|
32
|
+
<section id="dp-panel" class="dp-panel" hidden>
|
|
33
|
+
<form id="dp-upload" class="dp-upload">
|
|
34
|
+
<input class="dp-file" id="dp-file" type="file" required />
|
|
35
|
+
<button class="dp-btn" type="submit">Upload</button>
|
|
36
|
+
</form>
|
|
37
|
+
<ul id="dp-files" class="dp-files"></ul>
|
|
38
|
+
</section>
|
|
39
|
+
</main>
|
|
40
|
+
<script src="/portal.js"></script>
|
|
41
|
+
</body>
|
|
42
|
+
</html>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/* Data portal styles. Plain CSS, dp- prefixed, themed off variables so a brand
|
|
2
|
+
can restyle without touching markup — the same shape as booking.css. */
|
|
3
|
+
:root {
|
|
4
|
+
--dp-ink: #14181f;
|
|
5
|
+
--dp-muted: #667085;
|
|
6
|
+
--dp-paper: #ffffff;
|
|
7
|
+
--dp-rule: #e4e7ec;
|
|
8
|
+
--dp-accent: #1f6feb;
|
|
9
|
+
--dp-accent-ink: #ffffff;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
* {
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
body {
|
|
17
|
+
margin: 0;
|
|
18
|
+
padding: 2rem 1rem;
|
|
19
|
+
background: var(--dp-paper);
|
|
20
|
+
color: var(--dp-ink);
|
|
21
|
+
font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.dp-card {
|
|
25
|
+
max-width: 34rem;
|
|
26
|
+
margin: 0 auto;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.dp-title {
|
|
30
|
+
margin: 0 0 1rem;
|
|
31
|
+
font-size: 1.5rem;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.dp-status {
|
|
35
|
+
min-height: 1.5rem;
|
|
36
|
+
margin: 0 0 1rem;
|
|
37
|
+
color: var(--dp-muted);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.dp-login,
|
|
41
|
+
.dp-upload {
|
|
42
|
+
display: flex;
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
gap: 0.5rem;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.dp-label {
|
|
48
|
+
font-size: 0.875rem;
|
|
49
|
+
color: var(--dp-muted);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.dp-input,
|
|
53
|
+
.dp-file {
|
|
54
|
+
padding: 0.625rem 0.75rem;
|
|
55
|
+
border: 1px solid var(--dp-rule);
|
|
56
|
+
border-radius: 0.375rem;
|
|
57
|
+
font: inherit;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.dp-btn {
|
|
61
|
+
margin-top: 0.5rem;
|
|
62
|
+
padding: 0.625rem 1rem;
|
|
63
|
+
border: 0;
|
|
64
|
+
border-radius: 0.375rem;
|
|
65
|
+
background: var(--dp-accent);
|
|
66
|
+
color: var(--dp-accent-ink);
|
|
67
|
+
font: inherit;
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.dp-upload {
|
|
72
|
+
margin-bottom: 1.5rem;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.dp-files {
|
|
76
|
+
list-style: none;
|
|
77
|
+
margin: 0;
|
|
78
|
+
padding: 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.dp-file-row {
|
|
82
|
+
display: flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
justify-content: space-between;
|
|
85
|
+
gap: 1rem;
|
|
86
|
+
padding: 0.75rem 0;
|
|
87
|
+
border-bottom: 1px solid var(--dp-rule);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.dp-file-name {
|
|
91
|
+
color: var(--dp-accent);
|
|
92
|
+
text-decoration: none;
|
|
93
|
+
word-break: break-all;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.dp-file-name:hover {
|
|
97
|
+
text-decoration: underline;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.dp-del {
|
|
101
|
+
border: 1px solid var(--dp-rule);
|
|
102
|
+
border-radius: 0.375rem;
|
|
103
|
+
background: transparent;
|
|
104
|
+
color: var(--dp-muted);
|
|
105
|
+
padding: 0.375rem 0.625rem;
|
|
106
|
+
font: inherit;
|
|
107
|
+
cursor: pointer;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.dp-empty {
|
|
111
|
+
color: var(--dp-muted);
|
|
112
|
+
padding: 0.75rem 0;
|
|
113
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/* Data portal client. Dependency-free, no bundler, no framework — the same
|
|
2
|
+
shape as the booking page's booking.js.
|
|
3
|
+
|
|
4
|
+
Three steps: sign in with a passcode, list your own files, upload/delete.
|
|
5
|
+
The session cookie is HttpOnly, so this script never sees or stores it. */
|
|
6
|
+
(function () {
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
function meta(name) {
|
|
10
|
+
var el = document.querySelector('meta[name="' + name + '"]');
|
|
11
|
+
return el ? el.getAttribute('content') || '' : '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var API = meta('api-base');
|
|
15
|
+
var statusEl = document.getElementById('dp-status');
|
|
16
|
+
var loginEl = document.getElementById('dp-login');
|
|
17
|
+
var panelEl = document.getElementById('dp-panel');
|
|
18
|
+
var filesEl = document.getElementById('dp-files');
|
|
19
|
+
|
|
20
|
+
function say(msg) {
|
|
21
|
+
statusEl.textContent = msg;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function api(path, opts) {
|
|
25
|
+
return fetch(API + path, Object.assign({ credentials: 'same-origin' }, opts || {}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function item(text) {
|
|
29
|
+
var li = document.createElement('li');
|
|
30
|
+
li.className = 'dp-empty';
|
|
31
|
+
li.textContent = text;
|
|
32
|
+
return li;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function render(files) {
|
|
36
|
+
// replaceChildren, not innerHTML: every filename below is set with
|
|
37
|
+
// textContent so a name like '<img onerror=…>' renders as text, and
|
|
38
|
+
// clearing the list should not go anywhere near HTML parsing either.
|
|
39
|
+
filesEl.replaceChildren();
|
|
40
|
+
if (!files.length) {
|
|
41
|
+
filesEl.appendChild(item('No files yet.'));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
files.forEach(function (f) {
|
|
45
|
+
var li = document.createElement('li');
|
|
46
|
+
li.className = 'dp-file-row';
|
|
47
|
+
|
|
48
|
+
var a = document.createElement('a');
|
|
49
|
+
a.className = 'dp-file-name';
|
|
50
|
+
a.href = API + '/api/download?key=' + encodeURIComponent(f.objectKey);
|
|
51
|
+
a.textContent = f.filename;
|
|
52
|
+
li.appendChild(a);
|
|
53
|
+
|
|
54
|
+
var del = document.createElement('button');
|
|
55
|
+
del.className = 'dp-del';
|
|
56
|
+
del.type = 'button';
|
|
57
|
+
del.textContent = 'Delete';
|
|
58
|
+
del.addEventListener('click', function () {
|
|
59
|
+
remove(f.objectKey);
|
|
60
|
+
});
|
|
61
|
+
li.appendChild(del);
|
|
62
|
+
|
|
63
|
+
filesEl.appendChild(li);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function refresh() {
|
|
68
|
+
return api('/api/files')
|
|
69
|
+
.then(function (r) {
|
|
70
|
+
return r.json();
|
|
71
|
+
})
|
|
72
|
+
.then(function (d) {
|
|
73
|
+
if (d.ok) render(d.files || []);
|
|
74
|
+
})
|
|
75
|
+
.catch(function () {
|
|
76
|
+
say('Could not load your files.');
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function remove(key) {
|
|
81
|
+
say('Deleting…');
|
|
82
|
+
api('/api/delete', {
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: { 'content-type': 'application/json' },
|
|
85
|
+
body: JSON.stringify({ key: key }),
|
|
86
|
+
})
|
|
87
|
+
.then(function (r) {
|
|
88
|
+
return r.json();
|
|
89
|
+
})
|
|
90
|
+
.then(function (d) {
|
|
91
|
+
say(d.ok ? 'Deleted.' : 'Could not delete that.');
|
|
92
|
+
return refresh();
|
|
93
|
+
})
|
|
94
|
+
.catch(function () {
|
|
95
|
+
say('Could not delete that.');
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
loginEl.addEventListener('submit', function (e) {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
say('Signing in…');
|
|
102
|
+
api('/api/auth', {
|
|
103
|
+
method: 'POST',
|
|
104
|
+
headers: { 'content-type': 'application/json' },
|
|
105
|
+
body: JSON.stringify({
|
|
106
|
+
ownerId: document.getElementById('dp-owner').value.trim(),
|
|
107
|
+
passcode: document.getElementById('dp-passcode').value,
|
|
108
|
+
}),
|
|
109
|
+
})
|
|
110
|
+
.then(function (r) {
|
|
111
|
+
return r.json().then(function (d) {
|
|
112
|
+
return { s: r.status, d: d };
|
|
113
|
+
});
|
|
114
|
+
})
|
|
115
|
+
.then(function (res) {
|
|
116
|
+
if (res.s === 429) {
|
|
117
|
+
say('Too many attempts. Try again later.');
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!res.d.ok) {
|
|
121
|
+
say('That did not work.');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
document.getElementById('dp-passcode').value = '';
|
|
125
|
+
loginEl.hidden = true;
|
|
126
|
+
panelEl.hidden = false;
|
|
127
|
+
say('');
|
|
128
|
+
return refresh();
|
|
129
|
+
})
|
|
130
|
+
.catch(function () {
|
|
131
|
+
say('That did not work.');
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
document.getElementById('dp-upload').addEventListener('submit', function (e) {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
var input = document.getElementById('dp-file');
|
|
138
|
+
if (!input.files || !input.files[0]) return;
|
|
139
|
+
var fd = new FormData();
|
|
140
|
+
fd.append('file', input.files[0]);
|
|
141
|
+
say('Uploading…');
|
|
142
|
+
api('/api/upload', { method: 'POST', body: fd })
|
|
143
|
+
.then(function (r) {
|
|
144
|
+
return r.json();
|
|
145
|
+
})
|
|
146
|
+
.then(function (d) {
|
|
147
|
+
say(d.ok ? 'Uploaded.' : 'Upload failed.');
|
|
148
|
+
input.value = '';
|
|
149
|
+
return refresh();
|
|
150
|
+
})
|
|
151
|
+
.catch(function () {
|
|
152
|
+
say('Upload failed.');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
})();
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
-- D1 schema for the data portal (data-portal skill).
|
|
2
|
+
--
|
|
3
|
+
-- Four tables: who may authenticate (people), who currently is (sessions),
|
|
4
|
+
-- what they have dropped (manifest), and how hard they have been trying
|
|
5
|
+
-- (auth_attempts). Everything is IF NOT EXISTS so re-applying is safe.
|
|
6
|
+
|
|
7
|
+
-- One row per enrolled person. No plaintext passcode is ever stored: the
|
|
8
|
+
-- enrolment script generates the passcode, prints it to the operator once, and
|
|
9
|
+
-- persists only the salt and a SHA-256 of salt || passcode.
|
|
10
|
+
--
|
|
11
|
+
-- There is no `iterations` column. Verification is a single fast hash, which is
|
|
12
|
+
-- safe only because passcodes are machine-generated at a pinned length — see the
|
|
13
|
+
-- note at hashPasscode in functions/api/_lib/passcode.mjs. A cost column here
|
|
14
|
+
-- would imply a tunable that does not exist.
|
|
15
|
+
--
|
|
16
|
+
-- `iterations` was dropped outright rather than migrated because no portal had
|
|
17
|
+
-- been deployed when it went (Task 1708). If you meet a `people` table that still
|
|
18
|
+
-- has the column, this file will NOT remove it — IF NOT EXISTS is a no-op on an
|
|
19
|
+
-- existing table — and enrolment's INSERT will fail on `iterations NOT NULL`.
|
|
20
|
+
-- Drop the column by hand in that case; do not add it back here.
|
|
21
|
+
CREATE TABLE IF NOT EXISTS people (
|
|
22
|
+
ownerId TEXT PRIMARY KEY,
|
|
23
|
+
name TEXT NOT NULL,
|
|
24
|
+
salt TEXT NOT NULL,
|
|
25
|
+
hash TEXT NOT NULL,
|
|
26
|
+
createdAt TEXT NOT NULL
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
-- `pcCheck` is a short digest of the person's passcode hash at mint time, and
|
|
30
|
+
-- resolveSession requires it to still match `people.hash`. It is what makes
|
|
31
|
+
-- revocation structural: rotating a passcode necessarily changes the hash, so
|
|
32
|
+
-- every session minted against the old one stops resolving immediately, with
|
|
33
|
+
-- no cleanup step for an operator to remember and no 12-hour window to wait
|
|
34
|
+
-- out. A leaked passcode is exactly the case where a procedural remedy fails.
|
|
35
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
36
|
+
sessionId TEXT PRIMARY KEY,
|
|
37
|
+
ownerId TEXT NOT NULL,
|
|
38
|
+
pcCheck TEXT NOT NULL,
|
|
39
|
+
expiresAt INTEGER NOT NULL,
|
|
40
|
+
createdAt TEXT NOT NULL
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
CREATE INDEX IF NOT EXISTS sessions_owner ON sessions (ownerId);
|
|
44
|
+
|
|
45
|
+
-- One row per stored object. `ingested` is the claim flag the device-side
|
|
46
|
+
-- sweep (a separate task) reads and sets; a row stays 0 until its file has
|
|
47
|
+
-- been pulled into the graph, so the backlog survives the device being offline.
|
|
48
|
+
CREATE TABLE IF NOT EXISTS manifest (
|
|
49
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
50
|
+
fileId TEXT UNIQUE NOT NULL,
|
|
51
|
+
ownerId TEXT NOT NULL,
|
|
52
|
+
filename TEXT NOT NULL,
|
|
53
|
+
objectKey TEXT UNIQUE NOT NULL,
|
|
54
|
+
size INTEGER NOT NULL,
|
|
55
|
+
uploadedAt TEXT NOT NULL,
|
|
56
|
+
ingested INTEGER NOT NULL DEFAULT 0
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
CREATE INDEX IF NOT EXISTS manifest_uningested ON manifest (ingested);
|
|
60
|
+
CREATE INDEX IF NOT EXISTS manifest_owner ON manifest (ownerId);
|
|
61
|
+
|
|
62
|
+
-- Fixed-window auth attempt counter. Pages Functions are stateless, so the
|
|
63
|
+
-- counter cannot live in process memory the way every other rate limiter in
|
|
64
|
+
-- this platform does. The unique index is what makes the upsert in
|
|
65
|
+
-- _lib/ratelimit.ts collapse onto one row per window.
|
|
66
|
+
CREATE TABLE IF NOT EXISTS auth_attempts (
|
|
67
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
68
|
+
scope TEXT NOT NULL,
|
|
69
|
+
windowStart INTEGER NOT NULL,
|
|
70
|
+
count INTEGER NOT NULL
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
CREATE UNIQUE INDEX IF NOT EXISTS auth_attempts_scope_window ON auth_attempts (scope, windowStart);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Cloudflare Pages config for the data portal (data-portal skill).
|
|
2
|
+
# The skill fills the placeholders at assemble time:
|
|
3
|
+
# __PROJECT_NAME__ the Pages project name
|
|
4
|
+
# __D1_DATABASE_NAME__ the D1 database name (<accountId>-<purpose>)
|
|
5
|
+
# __D1_DATABASE_ID__ the id printed by `wrangler d1 create`
|
|
6
|
+
# __R2_BUCKET_NAME__ the R2 bucket name (<accountId>-<purpose>)
|
|
7
|
+
name = "__PROJECT_NAME__"
|
|
8
|
+
pages_build_output_dir = "public"
|
|
9
|
+
compatibility_date = "2024-01-01"
|
|
10
|
+
compatibility_flags = ["nodejs_compat"]
|
|
11
|
+
|
|
12
|
+
[[d1_databases]]
|
|
13
|
+
binding = "DB"
|
|
14
|
+
database_name = "__D1_DATABASE_NAME__"
|
|
15
|
+
database_id = "__D1_DATABASE_ID__"
|
|
16
|
+
|
|
17
|
+
# R2 binds by NAME and has no database_id analogue — the one asymmetry with the
|
|
18
|
+
# D1 block above. `binding` is the name the Pages Function reads off env.
|
|
19
|
+
[[r2_buckets]]
|
|
20
|
+
binding = "BUCKET"
|
|
21
|
+
bucket_name = "__R2_BUCKET_NAME__"
|
|
@@ -61,6 +61,14 @@ When the canonical tree carries a contact or waitlist form, the deploy is not co
|
|
|
61
61
|
|
|
62
62
|
Name the database with the canonical `<accountId>-<purpose>` scheme from `bin/cf-store-name.sh`, and keep one store per capture purpose: a new capture kind is a discriminator column, not a second database. A document-acceptance form (works agreement, quote signing) uses the canonical `acceptances` shape declared in `references/d1-data-capture.md`, not a per-build table, so the watcher reads one known store.
|
|
63
63
|
|
|
64
|
+
## Bind the bucket when the tree binds one
|
|
65
|
+
|
|
66
|
+
When the canonical tree carries an `[[r2_buckets]]` block, the deploy is not complete until a Function can reach the bucket off `env`. Follow `references/r2-object-storage.md`: the bucket is created once by its owning account through the storage broker — not here, and not by this skill's token — the binding is added to `wrangler.toml`, and the Function reads `env.<binding>`.
|
|
67
|
+
|
|
68
|
+
The binding is declarative config carried in the deploy payload, so the Pages token from the auth step already covers it and no R2 scope is needed at deploy time. Only bucket *creation* needs `Workers R2 Storage Write`, which is the `storage` scope, and it happens outside this skill. An R2-bound Function that fails every store call with `result=failed` is the signature of a binding that did not deploy — check the block reached the tree with `bucket_name` filled, rather than reaching for a token the deploy never needed.
|
|
69
|
+
|
|
70
|
+
Name the bucket with the canonical `<accountId>-<purpose>` scheme from `bin/cf-store-name.sh`, and keep one bucket per purpose, exactly as the D1 section above requires for databases. A tree with no `[[r2_buckets]]` block skips this section.
|
|
71
|
+
|
|
64
72
|
## Open Graph correctness
|
|
65
73
|
|
|
66
74
|
The live page must carry brand-correct Open Graph metadata: `<meta property="og:title">`, `og:description`, `og:image`, and `og:url` reflecting this site and this brand, not a leftover from whatever the tree was cloned from. Stale OG (a live card still naming a previous brand) is a recorded failure mode of hand deployment. Confirm the `og:*` tags in the deployed HTML are correct before claiming done; if they are stale, fix them in the source tree, redeploy, and re-check.
|
|
@@ -19,7 +19,7 @@ The `outlook` plugin gives the admin agent access to Microsoft 365 / Outlook.com
|
|
|
19
19
|
| `outlook-mail-list` | Mail newest-first. Default top=25, folder=Inbox. `folder` takes a well-known name or alias (case/space-insensitive): Inbox, Sent Items/sent, Drafts, Deleted Items/trash, Junk Email/junk/spam, Archive, Outbox — or a raw folder id. Custom folder names are not resolved. `since`/`before` (ISO date-times) narrow by receipt date. The 250-per-page figure is not a ceiling: the reply carries `nextCursor` when older mail remains — pass it back as `cursor` to page further back. Filter by sender/subject via `outlook-mail-search`. |
|
|
20
20
|
| `outlook-mail-search` | Microsoft Graph `$search` (KQL) over the mailbox. Preview-only, like `outlook-mail-list`, and pages the same way via `nextCursor`/`cursor`. Put sender/subject/recipient/date filters in the query: `from:`, `to:`, `subject:`, `received>=`. Graph forbids `$search`+`$filter`, so a strict date window is on `outlook-mail-list`. |
|
|
21
21
|
| `outlook-mail-fetch-body` | Complete body of one message by id (`GET /me/messages/{id}?$select=body`). HTML decoded to text, no preview cap. The full-read path — list/search return Microsoft's ~255-char preview only. Returns the envelope plus the whole body. |
|
|
22
|
-
| `outlook-mail-attachment` | List or download
|
|
22
|
+
| `outlook-mail-attachment` | List or download any message's attachments — received or draft. With `messageId` alone, LISTS them (`id`, `name`, `contentType`, `size`, `isInline`, and a `kind` of file/item/reference) via `GET /me/messages/{id}/attachments` and `$select` (no bytes). A draft is a message in the same collection, so passing a draftId lists what that draft carries; the returned `name`/`id` is what `outlook-draft-edit`'s `removeAttachments` takes. With `messageId`+`attachmentId`, DOWNLOADS one file attachment: its bytes are written to `{accountDir}/uploads/outlook/<messageHash>/<bytesHash>-<name>` at `0o600` and the saved path is returned, ready for the Read tool, `SendUserFile`, or an `outlook-mail-reply` attachment. Only file attachments download — item/reference kinds, empty payloads, and anything over 25 MB are refused with nothing written. `outlook-mail-list` / `outlook-mail-search` / `outlook-mail-fetch-body` report `hasAttachments` so the agent knows when to call this. Needs `Mail.Read`. |
|
|
23
23
|
| `outlook-mail-reply` | Reply in-thread (`createReply` / `createReplyAll` + send). Threads natively via conversationId. `replyAll`, added cc/bcc, and account-scoped file attachments (up to 25 MB per file; files over Graph's ~3 MB inline limit use a chunked upload session). Body is plain text, prepended above the quote. Needs `Mail.ReadWrite` + `Mail.Send`. |
|
|
24
24
|
| `outlook-mail-delete` | Move messages to Deleted Items (`POST /me/messages/{id}/move`). Recoverable — never hard-deletes. An id already gone is counted not-moved. Needs `Mail.ReadWrite`. |
|
|
25
25
|
| `outlook-mail-otp-extract` | Poll the inbox for a one-time code from a sender (domain). Reads full bodies to extract it; optional subject regex and timeout (default 60 s). |
|
|
@@ -35,7 +35,7 @@ The `outlook` plugin gives the admin agent access to Microsoft 365 / Outlook.com
|
|
|
35
35
|
| `outlook-mailbox-list` | Every connected mailbox with its email, scopes, and token health. Local only — no network — so it also flags a mailbox whose stored credentials cannot be read. |
|
|
36
36
|
| `outlook-mail-send` | Send a message. No attachments → `POST /me/sendMail`; with attachments → draft, attach, send (`/me/sendMail` carries attachments inline and cannot fit a large file). to/cc/bcc arrays, subject, body, isHtml, attachments (account-dir paths, 25 MB/file). Success asserted on Graph 202; no message id on either route. Needs `Mail.Send` (+ `Mail.ReadWrite` to attach). |
|
|
37
37
|
| `outlook-draft` | Create a draft in Drafts (`POST /me/messages`). Same body model, including attachments — files are attached before the id is returned, so the draft is ready to send. Returns the draft id. Needs `Mail.ReadWrite`. |
|
|
38
|
-
| `outlook-draft-edit` | Update an existing draft in place (`PATCH /me/messages/{draftId}`) and/or add attachments. Graph drafts are mutable — pass draftId plus the fields to change (to/cc/bcc/subject/body/isHtml/attachments).
|
|
38
|
+
| `outlook-draft-edit` | Update an existing draft in place (`PATCH /me/messages/{draftId}`) and/or add and remove attachments. Graph drafts are mutable — pass draftId plus the fields to change (to/cc/bcc/subject/body/isHtml/attachments/removeAttachments). `attachments` adds; `removeAttachments` takes files off by name or attachment id; both together replace a file in one call. Sent messages cannot be edited. Needs `Mail.ReadWrite`. |
|
|
39
39
|
| `outlook-draft-send` | Send an existing draft by id (`POST /me/messages/{id}/send`). Graph consumes the draft, returns 202. Needs `Mail.Send`. |
|
|
40
40
|
|
|
41
41
|
## Observability
|
|
@@ -110,4 +110,4 @@ Latency triage: `mail-list count=0 elapsedMs<200` consistent → permissions iss
|
|
|
110
110
|
|
|
111
111
|
## Out of scope
|
|
112
112
|
|
|
113
|
-
Mail move to arbitrary folders / flag, hard (permanent) delete, removing
|
|
113
|
+
Mail move to arbitrary folders / flag, hard (permanent) delete, removing an attachment from a **sent** message (Graph forbids it), ingesting reviewed mail into the business graph (the `email-ingest` analogue), contacts write, recurring-series occurrence editing, the `scheduling` Neo4j calendar and any auto-sync with it, OneDrive / Files, push notifications, on-premises Exchange, M365 admin scopes (`User.Read.All`, `AuditLog.Read.All`), public-agent exposure, multi-tenant federation. Mail read, full-body read, inbound attachment list/download, reply, delete (to Deleted Items), and compose — all four outbound paths carrying attachments, with a draft's attachments editable in place (add, remove, replace) — are supported (`outlook-mail-fetch-body`, `outlook-mail-attachment`, `outlook-mail-reply`, `outlook-mail-delete`, `outlook-mail-otp-extract`, `outlook-mail-send`, `outlook-draft`, `outlook-draft-edit`, `outlook-draft-send`), and the calendar is read plus control. See `platform/plugins/outlook/PLUGIN.md` for the full out-of-scope list.
|
|
@@ -66,6 +66,7 @@ Voice mirror is on by default for every drafting skill. To opt out for one, set
|
|
|
66
66
|
- **Copy public figures** — voice mirror only learns from your own writing.
|
|
67
67
|
- **Clone audio** — text only, no speech synthesis.
|
|
68
68
|
- **Guess** — historical content stays `unknown` until you mark it. {{productName}} never auto-classifies your writing. (Automatic ingestion applies only to your live PTY sessions where authorship is certain.)
|
|
69
|
+
- **Invent an identity** — a voice belongs to a real admin user on the account. Attribution is refused outright if it names anyone else, and nothing is written. A person's name is not an identity, so tagging someone's writing on a shared account needs their actual admin id, not their name.
|
|
69
70
|
|
|
70
71
|
## Status
|
|
71
72
|
|