@fabrika/app 0.9.0-dev.13 → 0.9.0-dev.15
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 +14 -9
- package/skill/SKILL.md +3 -2
- package/skill/references/app-setup.md +17 -9
- package/skill/references/endpoint.md +15 -2
- package/skill/references/errors.md +7 -6
- package/skill/references/jobs.md +10 -0
- package/skill/references/relations.md +145 -21
- package/skill/references/table-and-migration.md +4 -1
- package/skill/references/webhooks-links-connectors.md +2 -1
- package/src/build-contract-child.ts +16 -0
- package/src/build.ts +48 -2
- package/src/bun.ts +10 -0
- package/src/client/contract.ts +6 -4
- package/src/cloudflare/application.ts +3 -0
- package/src/contract/artifact-schema.ts +367 -299
- package/src/contract/attachment.ts +4 -3
- package/src/contract/build.ts +76 -18
- package/src/contract/compile.ts +3 -2
- package/src/contract/context.ts +2 -3
- package/src/contract/define.ts +19 -6
- package/src/contract/group.ts +18 -8
- package/src/contract/index.ts +1 -1
- package/src/contract/kit.ts +4 -3
- package/src/contract/problems.ts +4 -0
- package/src/contract/schema-shape.ts +14 -2
- package/src/contract/token.ts +4 -3
- package/src/disk-assets.ts +15 -3
- package/src/from-row.ts +12 -6
- package/src/implement/approved.ts +57 -0
- package/src/implement/attachment.ts +2 -1
- package/src/implement/boot.ts +118 -17
- package/src/implement/capability.ts +82 -12
- package/src/implement/dispatch.ts +265 -45
- package/src/implement/egress.ts +410 -9
- package/src/implement/faults.ts +1 -0
- package/src/implement/implement.ts +23 -3
- package/src/implement/invocation.ts +10 -9
- package/src/implement/project.ts +3 -1
- package/src/implement/tokens.ts +3 -2
- package/src/implement/types.ts +33 -10
- package/src/implement/webhook.ts +8 -0
- package/src/jobs/runner.ts +7 -2
- package/src/react/hooks.ts +12 -11
- package/src/react/provider.tsx +2 -1
- package/src/react/types.ts +2 -2
- package/src/schema/builder.ts +146 -0
- package/src/schema/data-schema.ts +365 -0
- package/src/schema/index.ts +18 -0
- package/src/schema/replay.ts +623 -0
- package/src/source-map-path.ts +21 -0
- package/src/testing/caller.ts +20 -9
- package/src/testing/kit.ts +3 -3
- package/src/testing/membership.ts +9 -5
- package/types/src/build-contract-child.d.ts +1 -0
- package/types/src/build.d.ts +16 -1
- package/types/src/client/contract.d.ts +3 -4
- package/types/src/cloudflare/application.d.ts +2 -0
- package/types/src/contract/artifact-schema.d.ts +8 -0
- package/types/src/contract/attachment.d.ts +3 -2
- package/types/src/contract/context.d.ts +2 -3
- package/types/src/contract/define.d.ts +16 -6
- package/types/src/contract/group.d.ts +14 -7
- package/types/src/contract/index.d.ts +1 -1
- package/types/src/contract/kit.d.ts +4 -5
- package/types/src/contract/problems.d.ts +1 -0
- package/types/src/contract/schema-shape.d.ts +3 -2
- package/types/src/contract/token.d.ts +3 -3
- package/types/src/from-row.d.ts +9 -5
- package/types/src/implement/approved.d.ts +11 -0
- package/types/src/implement/boot.d.ts +12 -0
- package/types/src/implement/capability.d.ts +14 -5
- package/types/src/implement/dispatch.d.ts +9 -1
- package/types/src/implement/egress.d.ts +36 -1
- package/types/src/implement/faults.d.ts +1 -0
- package/types/src/implement/implement.d.ts +19 -3
- package/types/src/implement/invocation.d.ts +3 -3
- package/types/src/implement/project.d.ts +2 -1
- package/types/src/implement/types.d.ts +17 -8
- package/types/src/jobs/runner.d.ts +3 -0
- package/types/src/react/hooks.d.ts +4 -5
- package/types/src/react/types.d.ts +2 -2
- package/types/src/schema/builder.d.ts +45 -0
- package/types/src/schema/data-schema.d.ts +124 -0
- package/types/src/schema/index.d.ts +3 -0
- package/types/src/schema/replay.d.ts +27 -0
- package/types/src/source-map-path.d.ts +4 -0
- package/types/src/testing/caller.d.ts +6 -1
- package/types/src/testing/kit.d.ts +2 -3
- package/types/src/testing/membership.d.ts +1 -1
package/src/bun.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { directoryEmailProvider } from '@fabrika/email/directory'
|
|
|
14
14
|
import { parseJwks } from '@fabrika/jwks'
|
|
15
15
|
import type { FileObjectStore } from '@fabrika/platform'
|
|
16
16
|
import { applicationRuntimeUrl, S3BlobStore } from '@fabrika/platform-node'
|
|
17
|
+
import { lookup } from 'node:dns/promises'
|
|
17
18
|
import { diskAssets } from './disk-assets.js'
|
|
18
19
|
import type { FetchService, RequestExecutionContext } from './fetch.js'
|
|
19
20
|
import { clamscanScanner } from './files/clamscan.js'
|
|
@@ -550,6 +551,7 @@ async function startContractServer(
|
|
|
550
551
|
membership,
|
|
551
552
|
terminals,
|
|
552
553
|
workloadTokens,
|
|
554
|
+
resolveHost,
|
|
553
555
|
requireProxySecret: true,
|
|
554
556
|
localEmailProviders: LOCAL_EMAIL_PROVIDERS,
|
|
555
557
|
connections: databaseConnections(environment.framework[DATABASE_CONNECTIONS]) ?? DEFAULT_DATABASE_CONNECTIONS,
|
|
@@ -585,6 +587,13 @@ async function startContractServer(
|
|
|
585
587
|
return { port: server.port ?? port, stop }
|
|
586
588
|
}
|
|
587
589
|
|
|
590
|
+
/**
|
|
591
|
+
* Every address `hostname` resolves to, as the operating system's resolver answers Bun's own `fetch`: a cron job's public
|
|
592
|
+
* egress refuses a hop whose name resolves to any private one, and connects to an address it checked (ADR-0075).
|
|
593
|
+
*/
|
|
594
|
+
const resolveHost = async (hostname: string): Promise<readonly string[]> =>
|
|
595
|
+
(await lookup(hostname, { all: true, verbatim: true })).map((entry) => entry.address)
|
|
596
|
+
|
|
588
597
|
/** The application module at `path`, imported when the loader runs; its default export must be what `serve` returned. */
|
|
589
598
|
export function implementationAt(path: string): ImplementationLoader {
|
|
590
599
|
return async () => {
|
|
@@ -631,6 +640,7 @@ export async function runContractJob(
|
|
|
631
640
|
membership,
|
|
632
641
|
terminals,
|
|
633
642
|
workloadTokens,
|
|
643
|
+
resolveHost,
|
|
634
644
|
requireProxySecret: true,
|
|
635
645
|
localEmailProviders: LOCAL_EMAIL_PROVIDERS,
|
|
636
646
|
// ClamAV on PATH, as the provider's build installs it for a `scan: true` file kind; missing, the scan fails closed.
|
package/src/client/contract.ts
CHANGED
|
@@ -10,8 +10,9 @@ import { type AttachmentBrand, attachmentOf } from '../contract/attachment'
|
|
|
10
10
|
import { isProcedure, type ProcedureTreeDeclaration, type ProcedureType, SURFACE_SECTIONS } from '../contract/declaration'
|
|
11
11
|
import { FILE_INPUT_PART } from '../contract/defaults'
|
|
12
12
|
import { challengePath, declaredChallengeAction, joinPath, LINK_API_SEGMENT, procedurePath } from '../contract/defaults'
|
|
13
|
-
import type { AnyContract, InputSchema, Procedure, Schema, Surface } from '../contract/define'
|
|
13
|
+
import type { AnyContract, InputSchema, Procedure, Schema, SchemaInput, SchemaOutput, Surface } from '../contract/define'
|
|
14
14
|
import { type ClientInput, type FileBrand, fileOf } from '../contract/file'
|
|
15
|
+
import { zodSchemaOf } from '../schema/data-schema'
|
|
15
16
|
import { type BounceConfig, type BounceOption, exchange, exchangeFile, resolveBounce, RpcError, type RpcFetch } from './transport'
|
|
16
17
|
|
|
17
18
|
type SurfaceOf<C> = C extends { readonly surface: infer S } ? S : never
|
|
@@ -26,7 +27,8 @@ export type ClientMount<C> =
|
|
|
26
27
|
* it parses with (`@fabrika/app/react` reads a cached answer back through it).
|
|
27
28
|
*/
|
|
28
29
|
export type ProcedureCall<I, O extends Schema> =
|
|
29
|
-
& ([I] extends [InputSchema] ? (input: ClientInput<
|
|
30
|
+
& ([I] extends [InputSchema] ? (input: ClientInput<SchemaInput<I>>) => Promise<SchemaOutput<O>>
|
|
31
|
+
: (input?: Record<never, never>) => Promise<SchemaOutput<O>>)
|
|
30
32
|
& { readonly output: O }
|
|
31
33
|
|
|
32
34
|
export type ClientTree<T> = {
|
|
@@ -170,7 +172,7 @@ function caller(target: CallTarget, at: TreeAt, options: ClientOptions, bounce:
|
|
|
170
172
|
const result = target.method === 'GET'
|
|
171
173
|
? await exchange(options.fetch ?? fetch, withParams(target.url, input), getRequestOf(options), bounce)
|
|
172
174
|
: await exchange(options.fetch ?? fetch, target.url, requestOf(options, input), bounce)
|
|
173
|
-
const parsed = z.safeParse(target.output, result)
|
|
175
|
+
const parsed = z.safeParse(zodSchemaOf(target.output), result)
|
|
174
176
|
if (!parsed.success) {
|
|
175
177
|
throw new RpcError({ type: 'invalid-response', message: `'${target.id}' answered a value its output schema refuses`, httpStatus: 200 })
|
|
176
178
|
}
|
|
@@ -364,7 +366,7 @@ export function attachmentAt(value: unknown): { readonly mount: string; readonly
|
|
|
364
366
|
}
|
|
365
367
|
|
|
366
368
|
/** The input `download` takes: the procedure's, or none. */
|
|
367
|
-
export type DownloadInput<I> = [I] extends [InputSchema] ? [input:
|
|
369
|
+
export type DownloadInput<I> = [I] extends [InputSchema] ? [input: SchemaInput<I>] : [input?: Record<never, never>]
|
|
368
370
|
|
|
369
371
|
/**
|
|
370
372
|
* Calls a procedure that answers a file (an attachment, or a `file('<kind>')` output) with the caller's credential, and
|
|
@@ -49,6 +49,8 @@ export interface ApplicationMigration {
|
|
|
49
49
|
export interface ContractWorkerOptions {
|
|
50
50
|
/** The application's own SQLite migrations, applied as the bundle `app` after the framework's `fabrika`. */
|
|
51
51
|
readonly migrations?: readonly ApplicationMigration[]
|
|
52
|
+
/** The contract artifact the build compiled, in its shared encoding, which boot reads instead of compiling (`BootOptions`). */
|
|
53
|
+
readonly approvedContract?: string
|
|
52
54
|
/** Where the isolate hears of an unhandled rejection; the global `unhandledrejection` event by default. */
|
|
53
55
|
readonly rejections?: CrashEvents
|
|
54
56
|
/** What posts a report to Operations' ingest; `fetch` by default. */
|
|
@@ -329,6 +331,7 @@ async function bootApplication(
|
|
|
329
331
|
// The proxy Worker sets `X-Fabrika-Client-Ip` from `CF-Connecting-IP`, the visitor Cloudflare saw.
|
|
330
332
|
clientAddress: 'vouched',
|
|
331
333
|
projectWakes: (transaction) => projectWakes(setup, transaction),
|
|
334
|
+
...(setup.options.approvedContract === undefined ? {} : { approvedContract: setup.options.approvedContract }),
|
|
332
335
|
...(setup.options.operationsFetch === undefined ? {} : { operationsFetch: setup.options.operationsFetch }),
|
|
333
336
|
})
|
|
334
337
|
const booted: Booted = { app, migrates }
|