@fabrika/app 0.6.0 → 0.8.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 +10 -9
- package/skill/SKILL.md +29 -21
- package/skill/references/app-setup.md +58 -36
- package/skill/references/dev.md +11 -9
- package/skill/references/endpoint.md +154 -25
- package/skill/references/errors.md +26 -23
- package/skill/references/files.md +187 -137
- package/skill/references/jobs.md +82 -35
- package/skill/references/public-intake.md +450 -255
- package/skill/references/spa.md +6 -5
- package/skill/references/start.md +2 -1
- package/skill/references/table-and-migration.md +24 -2
- package/skill/references/tests.md +14 -8
- package/skill/references/webhooks-links-connectors.md +65 -12
- package/src/bun.ts +3 -2
- package/src/client/contract.ts +221 -79
- package/src/client/index.ts +3 -1
- package/src/client/transport.ts +7 -2
- package/src/cloudflare.ts +2 -0
- package/src/contract/artifact-schema.ts +168 -14
- package/src/contract/build.ts +1282 -619
- package/src/contract/compile.ts +44 -10
- package/src/contract/connect.ts +79 -5
- package/src/contract/context.ts +132 -23
- package/src/contract/declaration.ts +78 -63
- package/src/contract/defaults.ts +142 -60
- package/src/contract/define.ts +92 -121
- package/src/contract/file.ts +78 -0
- package/src/contract/group.ts +244 -37
- package/src/contract/index.ts +18 -0
- package/src/contract/kit.ts +206 -126
- package/src/contract/platform.ts +8 -9
- package/src/contract/redirect.ts +49 -0
- package/src/contract/schema-from-shape.ts +7 -0
- package/src/contract/schema-shape.ts +10 -0
- package/src/contract/snapshot-source.ts +5 -0
- package/src/contract/token.ts +89 -0
- package/src/contract/webhook-binding.ts +26 -0
- package/src/contract/webhook-scheme.ts +32 -0
- package/src/files/handle.ts +22 -0
- package/src/files/kinds.ts +454 -0
- package/src/files/scan.ts +15 -9
- package/src/files/streams.ts +111 -0
- package/src/honeypot.ts +7 -0
- package/src/implement/anonymous.ts +18 -42
- package/src/implement/boot.ts +210 -157
- package/src/implement/bounded.ts +23 -0
- package/src/implement/browser-config.ts +6 -5
- package/src/implement/capability.ts +78 -2
- package/src/implement/challenge.ts +203 -47
- package/src/implement/{form-admission.ts → client-address.ts} +3 -38
- package/src/implement/dispatch.ts +831 -409
- package/src/implement/egress.ts +84 -0
- package/src/implement/faults.ts +11 -1
- package/src/implement/index.ts +3 -2
- package/src/implement/invocation.ts +135 -35
- package/src/implement/params.ts +88 -0
- package/src/implement/principal.ts +7 -0
- package/src/implement/public.ts +167 -0
- package/src/implement/tokens.ts +219 -0
- package/src/implement/types.ts +24 -3
- package/src/implement/urls.ts +78 -0
- package/src/implement/verifiers.ts +299 -0
- package/src/implement/webhook.ts +136 -55
- package/src/implement/workload.ts +16 -14
- package/src/index.ts +3 -0
- package/src/jobs/mail.ts +98 -10
- package/src/jobs/runner.ts +103 -71
- package/src/jobs/scrub.ts +4 -1
- package/src/jobs/types.ts +19 -2
- package/src/react/hooks.ts +2 -2
- package/src/react/provider.tsx +2 -2
- package/src/testing/challenge.ts +35 -1
- package/src/testing/dev.ts +2 -2
- package/src/testing/endpoint-access.ts +168 -128
- package/src/testing/kit.ts +90 -25
- package/src/testing/policy-isolation.ts +55 -29
- package/src/testing/proxy.ts +6 -2
- package/src/testing/sample-file.ts +30 -0
- package/src/client/files.ts +0 -135
- package/src/contract/file-schemas.ts +0 -25
- package/src/files/collections.ts +0 -848
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
// What the anonymous kinds need beyond the request pipeline: a body read under its limit (the proxy never sees a
|
|
2
|
-
// body, so the framework enforces it)
|
|
3
|
-
//
|
|
2
|
+
// body, so the framework enforces it) and the share SPA's fragment bootstrap. A form's admission is
|
|
3
|
+
// `form-admission.ts`, a webhook's signature `verifiers.ts`.
|
|
4
4
|
|
|
5
5
|
import { LINK_BOOTSTRAP_FILE, SHARE_KEY_GLOBAL } from '../contract/defaults'
|
|
6
6
|
import { HttpError } from '../errors'
|
|
7
7
|
import { readBoundedBytes } from './bounded'
|
|
8
8
|
|
|
9
|
+
/** The slowest body a procedure waits for, in bytes per second: its deadline is `maxBytes` at this rate, 30 s at least. */
|
|
10
|
+
export const BODY_RATE_FLOOR = 16 * 1024
|
|
11
|
+
const MIN_BODY_DEADLINE_MS = 30_000
|
|
12
|
+
|
|
13
|
+
/** How long a body of at most `maxBytes` may take to arrive. */
|
|
14
|
+
export function bodyDeadlineMs(maxBytes: number): number {
|
|
15
|
+
return Math.max(MIN_BODY_DEADLINE_MS, Math.ceil((maxBytes / BODY_RATE_FLOOR) * 1000))
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
/**
|
|
10
19
|
* The body as bytes, read until `maxBytes`; a longer one stops the read and is a 413. A body whose stream fails before
|
|
11
20
|
* its end (the client closed the connection) is the sender's 400 `aborted`, never a failure of the application.
|
|
12
21
|
*/
|
|
13
|
-
export async function readBoundedBody(request: Request, maxBytes: number): Promise<Uint8Array<ArrayBuffer>> {
|
|
22
|
+
export async function readBoundedBody(request: Request, maxBytes: number, deadline?: AbortSignal): Promise<Uint8Array<ArrayBuffer>> {
|
|
14
23
|
let body: Uint8Array<ArrayBuffer> | null
|
|
15
24
|
try {
|
|
16
|
-
body = await readBoundedBytes(request.body, {
|
|
25
|
+
body = await readBoundedBytes(request.body, {
|
|
26
|
+
maxBytes,
|
|
27
|
+
declaredLength: request.headers.get('Content-Length'),
|
|
28
|
+
...(deadline === undefined ? {} : { signal: deadline }),
|
|
29
|
+
})
|
|
17
30
|
} catch {
|
|
18
|
-
throw abortedBody()
|
|
31
|
+
throw deadline?.aborted === true ? new HttpError(408, 'body_timeout', 'The body did not arrive within its deadline') : abortedBody()
|
|
19
32
|
}
|
|
20
33
|
if (body === null) {
|
|
21
34
|
throw new HttpError(413, 'too_large', `The body is larger than ${maxBytes} bytes`)
|
|
@@ -76,40 +89,3 @@ export async function withBootstrap(response: Response, prefix: string): Promise
|
|
|
76
89
|
headers.delete('Content-Length')
|
|
77
90
|
return new Response(injected, { status: response.status, statusText: response.statusText, headers })
|
|
78
91
|
}
|
|
79
|
-
|
|
80
|
-
const SIGNATURE_PREFIX = 'sha256='
|
|
81
|
-
const HEX = /^[0-9a-f]{64}$/
|
|
82
|
-
|
|
83
|
-
/** Whether `X-Hub-Signature-256` is GitHub's HMAC-SHA256 of the raw body under `secret`, compared in constant time. */
|
|
84
|
-
export async function verifyGithubSignature(header: string | null, secret: string, body: Uint8Array<ArrayBuffer>): Promise<boolean> {
|
|
85
|
-
if (header === null || !header.startsWith(SIGNATURE_PREFIX)) {
|
|
86
|
-
return false
|
|
87
|
-
}
|
|
88
|
-
const hex = header.slice(SIGNATURE_PREFIX.length).toLowerCase()
|
|
89
|
-
if (!HEX.test(hex)) {
|
|
90
|
-
return false
|
|
91
|
-
}
|
|
92
|
-
const signature = new Uint8Array(32)
|
|
93
|
-
for (let index = 0; index < 32; index++) {
|
|
94
|
-
signature[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16)
|
|
95
|
-
}
|
|
96
|
-
const key = await crypto.subtle.importKey('raw', new TextEncoder().encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['verify'])
|
|
97
|
-
return crypto.subtle.verify('HMAC', key, signature, body)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** The GitHub account a payload names, as a binding records it: `installation:<id>` or `repository:<id>`. */
|
|
101
|
-
export function githubAccounts(payload: unknown): readonly string[] {
|
|
102
|
-
const accounts: string[] = []
|
|
103
|
-
for (const kind of ['installation', 'repository'] as const) {
|
|
104
|
-
const holder = ownField(payload, kind)
|
|
105
|
-
const id = ownField(holder, 'id')
|
|
106
|
-
if (typeof id === 'number' && Number.isSafeInteger(id) && id > 0) {
|
|
107
|
-
accounts.push(`${kind}:${id}`)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return accounts
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function ownField(value: unknown, name: string): unknown {
|
|
114
|
-
return typeof value === 'object' && value !== null && Object.hasOwn(value, name) ? Reflect.get(value, name) : undefined
|
|
115
|
-
}
|