@dads-framework/toolbox 0.2.0 → 0.3.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/README.md +85 -21
- package/bin/dad-dev.js +12 -0
- package/bin/usage.js +34 -4
- package/dist/access-diff-format.d.ts +16 -0
- package/dist/access-diff-format.d.ts.map +1 -0
- package/dist/access-diff-format.js +119 -0
- package/dist/access-diff-format.js.map +1 -0
- package/dist/access-diff-types.d.ts +79 -0
- package/dist/access-diff-types.d.ts.map +1 -0
- package/dist/access-diff-types.js +3 -0
- package/dist/access-diff-types.js.map +1 -0
- package/dist/access-diff.d.ts +21 -0
- package/dist/access-diff.d.ts.map +1 -0
- package/dist/access-diff.js +226 -0
- package/dist/access-diff.js.map +1 -0
- package/dist/access-import.d.ts +22 -0
- package/dist/access-import.d.ts.map +1 -0
- package/dist/access-import.js +30 -0
- package/dist/access-import.js.map +1 -0
- package/dist/access-migrate.d.ts +37 -0
- package/dist/access-migrate.d.ts.map +1 -0
- package/dist/access-migrate.js +250 -0
- package/dist/access-migrate.js.map +1 -0
- package/dist/access-source-loader.d.ts +16 -0
- package/dist/access-source-loader.d.ts.map +1 -0
- package/dist/access-source-loader.js +171 -0
- package/dist/access-source-loader.js.map +1 -0
- package/dist/access-tree.d.ts +23 -0
- package/dist/access-tree.d.ts.map +1 -0
- package/dist/access-tree.js +39 -0
- package/dist/access-tree.js.map +1 -0
- package/dist/access-zed-io.d.ts +6 -0
- package/dist/access-zed-io.d.ts.map +1 -0
- package/dist/access-zed-io.js +31 -0
- package/dist/access-zed-io.js.map +1 -0
- package/dist/cli-access-args.d.ts +25 -0
- package/dist/cli-access-args.d.ts.map +1 -0
- package/dist/cli-access-args.js +168 -0
- package/dist/cli-access-args.js.map +1 -0
- package/dist/cli-access-commands.d.ts +3 -0
- package/dist/cli-access-commands.d.ts.map +1 -0
- package/dist/cli-access-commands.js +120 -0
- package/dist/cli-access-commands.js.map +1 -0
- package/dist/cli-io.d.ts +6 -0
- package/dist/cli-io.d.ts.map +1 -1
- package/dist/cli-io.js +14 -0
- package/dist/cli-io.js.map +1 -1
- package/dist/cli-migrate-commands.d.ts +2 -0
- package/dist/cli-migrate-commands.d.ts.map +1 -0
- package/dist/cli-migrate-commands.js +59 -0
- package/dist/cli-migrate-commands.js.map +1 -0
- package/dist/cli-project-commands.d.ts.map +1 -1
- package/dist/cli-project-commands.js +1 -0
- package/dist/cli-project-commands.js.map +1 -1
- package/dist/cli.js +20 -5
- package/dist/cli.js.map +1 -1
- package/dist/dads-initialization-arguments.d.ts +2 -0
- package/dist/dads-initialization-arguments.d.ts.map +1 -1
- package/dist/dads-initialization-arguments.js +15 -3
- package/dist/dads-initialization-arguments.js.map +1 -1
- package/dist/dev/cli.d.ts +2 -0
- package/dist/dev/cli.d.ts.map +1 -0
- package/dist/dev/cli.js +123 -0
- package/dist/dev/cli.js.map +1 -0
- package/dist/dev/dev-config.d.ts +20 -0
- package/dist/dev/dev-config.d.ts.map +1 -0
- package/dist/dev/dev-config.js +36 -0
- package/dist/dev/dev-config.js.map +1 -0
- package/dist/dev/git-worktrees.d.ts +14 -0
- package/dist/dev/git-worktrees.d.ts.map +1 -0
- package/dist/dev/git-worktrees.js +41 -0
- package/dist/dev/git-worktrees.js.map +1 -0
- package/dist/dev/index.d.ts +2 -0
- package/dist/dev/index.d.ts.map +1 -0
- package/dist/dev/index.js +2 -0
- package/dist/dev/index.js.map +1 -0
- package/dist/dev/managed-processes.d.ts +6 -0
- package/dist/dev/managed-processes.d.ts.map +1 -0
- package/dist/dev/managed-processes.js +57 -0
- package/dist/dev/managed-processes.js.map +1 -0
- package/dist/dev/process-inspection.d.ts +5 -0
- package/dist/dev/process-inspection.d.ts.map +1 -0
- package/dist/dev/process-inspection.js +68 -0
- package/dist/dev/process-inspection.js.map +1 -0
- package/dist/dev/slot-environment.d.ts +6 -0
- package/dist/dev/slot-environment.d.ts.map +1 -0
- package/dist/dev/slot-environment.js +117 -0
- package/dist/dev/slot-environment.js.map +1 -0
- package/dist/dev/slot-run.d.ts +16 -0
- package/dist/dev/slot-run.d.ts.map +1 -0
- package/dist/dev/slot-run.js +90 -0
- package/dist/dev/slot-run.js.map +1 -0
- package/dist/dev/slot-state.d.ts +16 -0
- package/dist/dev/slot-state.d.ts.map +1 -0
- package/dist/dev/slot-state.js +66 -0
- package/dist/dev/slot-state.js.map +1 -0
- package/dist/dev/slot-supervisor.d.ts +2 -0
- package/dist/dev/slot-supervisor.d.ts.map +1 -0
- package/dist/dev/slot-supervisor.js +103 -0
- package/dist/dev/slot-supervisor.js.map +1 -0
- package/dist/dev/worktree-decision.d.ts +23 -0
- package/dist/dev/worktree-decision.d.ts.map +1 -0
- package/dist/dev/worktree-decision.js +21 -0
- package/dist/dev/worktree-decision.js.map +1 -0
- package/dist/dev/worktree-lifecycle.d.ts +8 -0
- package/dist/dev/worktree-lifecycle.d.ts.map +1 -0
- package/dist/dev/worktree-lifecycle.js +174 -0
- package/dist/dev/worktree-lifecycle.js.map +1 -0
- package/dist/doctor/signals/anxious-attachment/kind-inversions.d.ts.map +1 -1
- package/dist/doctor/signals/anxious-attachment/kind-inversions.js +19 -10
- package/dist/doctor/signals/anxious-attachment/kind-inversions.js.map +1 -1
- package/dist/doctor/signals/commitment-issues/test-count.d.ts +3 -3
- package/dist/doctor/signals/commitment-issues/test-count.d.ts.map +1 -1
- package/dist/doctor/signals/commitment-issues/test-count.js +9 -7
- package/dist/doctor/signals/commitment-issues/test-count.js.map +1 -1
- package/dist/doctor/signals/its-not-you-its-my-boundaries/lint-rules.d.ts.map +1 -1
- package/dist/doctor/signals/its-not-you-its-my-boundaries/lint-rules.js +5 -1
- package/dist/doctor/signals/its-not-you-its-my-boundaries/lint-rules.js.map +1 -1
- package/dist/doctor/signals/people-pleasing/forbidden-403.d.ts +5 -5
- package/dist/doctor/signals/people-pleasing/forbidden-403.d.ts.map +1 -1
- package/dist/doctor/signals/people-pleasing/forbidden-403.js +57 -17
- package/dist/doctor/signals/people-pleasing/forbidden-403.js.map +1 -1
- package/dist/doctor/signals/scanners/lint-configuration.d.ts.map +1 -1
- package/dist/doctor/signals/scanners/lint-configuration.js +17 -5
- package/dist/doctor/signals/scanners/lint-configuration.js.map +1 -1
- package/dist/doctor/signals/scanners/package-graph.d.ts +1 -0
- package/dist/doctor/signals/scanners/package-graph.d.ts.map +1 -1
- package/dist/doctor/signals/scanners/package-graph.js +8 -0
- package/dist/doctor/signals/scanners/package-graph.js.map +1 -1
- package/dist/doctor/signals/scanners/source-bindings.d.ts +16 -0
- package/dist/doctor/signals/scanners/source-bindings.d.ts.map +1 -0
- package/dist/doctor/signals/scanners/source-bindings.js +57 -0
- package/dist/doctor/signals/scanners/source-bindings.js.map +1 -0
- package/dist/doctor/signals/scanners/web-renderers.js +2 -2
- package/dist/doctor/signals/scanners/web-renderers.js.map +1 -1
- package/dist/doctor/signals/the-paper-wall/explicit-wrapper-conformance.d.ts.map +1 -1
- package/dist/doctor/signals/the-paper-wall/explicit-wrapper-conformance.js +26 -64
- package/dist/doctor/signals/the-paper-wall/explicit-wrapper-conformance.js.map +1 -1
- package/dist/doctor/signals/the-paper-wall/table-wrapper-conformance.d.ts +6 -0
- package/dist/doctor/signals/the-paper-wall/table-wrapper-conformance.d.ts.map +1 -0
- package/dist/doctor/signals/the-paper-wall/table-wrapper-conformance.js +212 -0
- package/dist/doctor/signals/the-paper-wall/table-wrapper-conformance.js.map +1 -0
- package/dist/doctor/signals/the-paper-wall/wrapper-conformance-provider.d.ts +10 -0
- package/dist/doctor/signals/the-paper-wall/wrapper-conformance-provider.d.ts.map +1 -0
- package/dist/doctor/signals/the-paper-wall/wrapper-conformance-provider.js +71 -0
- package/dist/doctor/signals/the-paper-wall/wrapper-conformance-provider.js.map +1 -0
- package/dist/doctor/signals/you-are-looking-for-a-father-figure/framework-in-core.d.ts.map +1 -1
- package/dist/doctor/signals/you-are-looking-for-a-father-figure/framework-in-core.js +5 -1
- package/dist/doctor/signals/you-are-looking-for-a-father-figure/framework-in-core.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/initialize-dads-project.d.ts +2 -0
- package/dist/initialize-dads-project.d.ts.map +1 -1
- package/dist/initialize-dads-project.js +4 -1
- package/dist/initialize-dads-project.js.map +1 -1
- package/dist/migrate-v03-map.d.ts +11 -0
- package/dist/migrate-v03-map.d.ts.map +1 -0
- package/dist/migrate-v03-map.js +204 -0
- package/dist/migrate-v03-map.js.map +1 -0
- package/dist/migrate-v03.d.ts +20 -0
- package/dist/migrate-v03.d.ts.map +1 -0
- package/dist/migrate-v03.js +280 -0
- package/dist/migrate-v03.js.map +1 -0
- package/dist/resource-generators/access-generator.d.ts.map +1 -1
- package/dist/resource-generators/access-generator.js +17 -26
- package/dist/resource-generators/access-generator.js.map +1 -1
- package/dist/resource-generators/domain-generator.d.ts.map +1 -1
- package/dist/resource-generators/domain-generator.js +9 -2
- package/dist/resource-generators/domain-generator.js.map +1 -1
- package/dist/resource-generators/email-generator.js +2 -2
- package/dist/resource-generators/endpoint-generator.js +2 -2
- package/dist/resource-generators/generator-dependencies.js +7 -11
- package/dist/resource-generators/generator-dependencies.js.map +1 -1
- package/dist/resource-generators/resource-contract.js +2 -2
- package/dist/resource-generators/resource-pages.js +1 -1
- package/dist/resource-generators/resource-proof.d.ts.map +1 -1
- package/dist/resource-generators/resource-proof.js +10 -17
- package/dist/resource-generators/resource-proof.js.map +1 -1
- package/dist/resource-generators/resource-routes.js +1 -1
- package/dist/resource-generators/table-generator.js +1 -1
- package/dist/starter-project/kit-starter.generated.d.ts.map +1 -1
- package/dist/starter-project/kit-starter.generated.js +85 -79
- package/dist/starter-project/kit-starter.generated.js.map +1 -1
- package/dist/starter-project/minimal-project-assembly.d.ts +4 -0
- package/dist/starter-project/minimal-project-assembly.d.ts.map +1 -0
- package/dist/starter-project/minimal-project-assembly.js +363 -0
- package/dist/starter-project/minimal-project-assembly.js.map +1 -0
- package/dist/starter-project/minimal-project-docs-and-tests.d.ts +4 -0
- package/dist/starter-project/minimal-project-docs-and-tests.d.ts.map +1 -0
- package/dist/starter-project/minimal-project-docs-and-tests.js +309 -0
- package/dist/starter-project/minimal-project-docs-and-tests.js.map +1 -0
- package/dist/starter-project/minimal-project-server.d.ts +4 -0
- package/dist/starter-project/minimal-project-server.d.ts.map +1 -0
- package/dist/starter-project/minimal-project-server.js +120 -0
- package/dist/starter-project/minimal-project-server.js.map +1 -0
- package/dist/starter-project/minimal-project-web.d.ts +4 -0
- package/dist/starter-project/minimal-project-web.d.ts.map +1 -0
- package/dist/starter-project/minimal-project-web.js +344 -0
- package/dist/starter-project/minimal-project-web.js.map +1 -0
- package/dist/starter-project/minimal-project-workbench.d.ts +4 -0
- package/dist/starter-project/minimal-project-workbench.d.ts.map +1 -0
- package/dist/starter-project/minimal-project-workbench.js +371 -0
- package/dist/starter-project/minimal-project-workbench.js.map +1 -0
- package/dist/starter-project/render-minimal-project.d.ts +6 -0
- package/dist/starter-project/render-minimal-project.d.ts.map +1 -0
- package/dist/starter-project/render-minimal-project.js +162 -0
- package/dist/starter-project/render-minimal-project.js.map +1 -0
- package/dist/starter-project/render-starter-project.d.ts +2 -0
- package/dist/starter-project/render-starter-project.d.ts.map +1 -1
- package/dist/starter-project/render-starter-project.js +4 -0
- package/dist/starter-project/render-starter-project.js.map +1 -1
- package/dist/toolbox.tsbuildinfo +1 -1
- package/package.json +11 -4
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/** Minimal documentation and starter test suite without example domains. */
|
|
2
|
+
export function renderMinimalDocsAndTestFiles() {
|
|
3
|
+
return [
|
|
4
|
+
minimalReadmeFile(),
|
|
5
|
+
minimalDeployFile(),
|
|
6
|
+
sessionSubjectsTestFile(),
|
|
7
|
+
starterIntegrationTestFile(),
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
function minimalReadmeFile() {
|
|
11
|
+
return {
|
|
12
|
+
path: "README.md",
|
|
13
|
+
content: `# Dads app
|
|
14
|
+
|
|
15
|
+
This project runs a React browser shell, named customer and staff Fastify APIs,
|
|
16
|
+
Better Auth identity, multi-tenant workspaces, and PostgreSQL migrations.
|
|
17
|
+
|
|
18
|
+
## Start
|
|
19
|
+
|
|
20
|
+
With Node 24, npm, and Docker running, execute \`npm start\` from the generated
|
|
21
|
+
project. Open the browser URL printed by the command. Use \`npm run dev:status\`
|
|
22
|
+
to look up the URL and \`npm run dev:down\` to stop the stack. See
|
|
23
|
+
[local development](./assembly/LOCAL-DEV.md) for ports, logs, and restart commands.
|
|
24
|
+
|
|
25
|
+
In the browser, select **Create an account**. Run \`npm run dev:mail\` in a second
|
|
26
|
+
terminal and open the verification link, then sign in and create a workspace.
|
|
27
|
+
|
|
28
|
+
## Add your first domain
|
|
29
|
+
|
|
30
|
+
Generate a relationship-guarded resource and mount it on the customer API:
|
|
31
|
+
|
|
32
|
+
\`\`\`sh
|
|
33
|
+
npx dad add resource products --api customer
|
|
34
|
+
\`\`\`
|
|
35
|
+
|
|
36
|
+
Keep contracts, access rules, and storage inside \`domains/<name>/\`. Register
|
|
37
|
+
each domain plugin explicitly in \`apps/<api>/app.ts\` and register migration
|
|
38
|
+
sources in \`assembly/migrations.ts\`.
|
|
39
|
+
|
|
40
|
+
## Test and verify
|
|
41
|
+
|
|
42
|
+
From the generated project, run the integration test with Docker running:
|
|
43
|
+
|
|
44
|
+
\`\`\`sh
|
|
45
|
+
npm test -- tests/starter.integration.test.ts
|
|
46
|
+
\`\`\`
|
|
47
|
+
|
|
48
|
+
Run \`npm run verify\` to check domain boundaries, TypeScript types, the web
|
|
49
|
+
build, and the test suite.
|
|
50
|
+
|
|
51
|
+
## Deploy
|
|
52
|
+
|
|
53
|
+
Follow [run outside development](./DEPLOY.md) for migrations, runtime settings,
|
|
54
|
+
and smoke checks. Set \`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT\` to export traces.
|
|
55
|
+
`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function minimalDeployFile() {
|
|
59
|
+
return {
|
|
60
|
+
path: "DEPLOY.md",
|
|
61
|
+
content: `# Run outside development
|
|
62
|
+
|
|
63
|
+
For local development, use \`npm start\` to run the Compose stack and print its
|
|
64
|
+
assigned URLs. The [app README](./README.md#start) covers that workflow.
|
|
65
|
+
|
|
66
|
+
The API needs Node 24, a reachable PostgreSQL database, and a process supervisor
|
|
67
|
+
that sends a termination signal on shutdown.
|
|
68
|
+
|
|
69
|
+
## Prepare the release
|
|
70
|
+
|
|
71
|
+
1. Install from the committed lockfile with \`npm ci\` and run \`npm run verify\`.
|
|
72
|
+
2. Run \`npm run build:web\`. Serve the entire \`dist/\` directory, configure a
|
|
73
|
+
fallback to \`index.html\` for browser routes, and forward same-origin \`/api\`
|
|
74
|
+
requests to the customer API.
|
|
75
|
+
3. Configure \`DATABASE_URL\` and \`DADS_IDENTITY_SECRET\` in the runtime secret
|
|
76
|
+
store. Set \`DADS_BASE_URL\` to the public HTTPS origin for sign-in.
|
|
77
|
+
4. Connect email delivery to a real provider and configure durable file storage
|
|
78
|
+
for features that write files.
|
|
79
|
+
5. Run \`npm run migrate\` once against the target database before starting the
|
|
80
|
+
new API processes.
|
|
81
|
+
|
|
82
|
+
## Start and check
|
|
83
|
+
|
|
84
|
+
Set \`NODE_ENV=production\` and run \`npm run start:api\`. Select \`DADS_API=customer\`
|
|
85
|
+
for the customer routes or \`DADS_API=staff\` for the staff routes. Set \`PORT\` for
|
|
86
|
+
each process and \`HOST\` to the interface reached by your ingress.
|
|
87
|
+
|
|
88
|
+
\`\`\`sh
|
|
89
|
+
NODE_ENV=production DADS_API=customer HOST=127.0.0.1 PORT=3000 npm run start:api
|
|
90
|
+
\`\`\`
|
|
91
|
+
|
|
92
|
+
Check liveness from a second terminal:
|
|
93
|
+
|
|
94
|
+
\`\`\`sh
|
|
95
|
+
curl -fsS http://127.0.0.1:3000/api/health
|
|
96
|
+
\`\`\`
|
|
97
|
+
|
|
98
|
+
A healthy API returns HTTP 200 with \`{ "data": { "status": "ok" } }\`.
|
|
99
|
+
`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function sessionSubjectsTestFile() {
|
|
103
|
+
return {
|
|
104
|
+
path: "tests/session-subjects.test.ts",
|
|
105
|
+
content: `import type { IdentitySession } from "@dads-framework/identity";
|
|
106
|
+
import { expect, it, vi } from "vitest";
|
|
107
|
+
|
|
108
|
+
import { sessionSubjects } from "../assembly/session-subjects.js";
|
|
109
|
+
|
|
110
|
+
it("resolves valid sessions and rejects malformed tenant parameters", async () => {
|
|
111
|
+
const tenantId = "c56a4180-65aa-4a42-80d3-f8e3159b9966";
|
|
112
|
+
const session: IdentitySession = {
|
|
113
|
+
account: {
|
|
114
|
+
id: "user-1",
|
|
115
|
+
email: "member@example.test",
|
|
116
|
+
emailVerified: true,
|
|
117
|
+
},
|
|
118
|
+
expiresAt: new Date(),
|
|
119
|
+
};
|
|
120
|
+
const readSession = vi.fn(() => Promise.resolve(session));
|
|
121
|
+
const identity = {
|
|
122
|
+
handle: () => Promise.resolve(new Response(null)),
|
|
123
|
+
readSession,
|
|
124
|
+
};
|
|
125
|
+
const subjects = sessionSubjects(identity);
|
|
126
|
+
const headers = { cookie: "fixture" };
|
|
127
|
+
|
|
128
|
+
expect(
|
|
129
|
+
await subjects.resolve({ headers, params: { tenantId: "invalid" } }),
|
|
130
|
+
).toBeNull();
|
|
131
|
+
expect(readSession).not.toHaveBeenCalled();
|
|
132
|
+
|
|
133
|
+
expect(
|
|
134
|
+
await subjects.resolve({ headers, params: { tenantId } }),
|
|
135
|
+
).toMatchObject({ id: session.account.id });
|
|
136
|
+
expect(await subjects.resolve({ headers, url: "/api/tenants" })).toMatchObject(
|
|
137
|
+
{ id: session.account.id },
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function starterIntegrationTestFile() {
|
|
144
|
+
return {
|
|
145
|
+
path: "tests/starter.integration.test.ts",
|
|
146
|
+
content: `import { mkdtemp, rm } from "node:fs/promises";
|
|
147
|
+
import { tmpdir } from "node:os";
|
|
148
|
+
import { join } from "node:path";
|
|
149
|
+
import { PostgreSqlContainer } from "@testcontainers/postgresql";
|
|
150
|
+
import { expect, it } from "vitest";
|
|
151
|
+
import { z } from "zod";
|
|
152
|
+
|
|
153
|
+
import { migrate } from "../assembly/migrations.js";
|
|
154
|
+
import { startApp } from "../assembly/start-app.js";
|
|
155
|
+
import type { StarterEmail } from "../libraries/app-runtime/index.js";
|
|
156
|
+
|
|
157
|
+
const origin = "http://127.0.0.1:3000";
|
|
158
|
+
const secret = "fixture-signing-key-with-forty-characters";
|
|
159
|
+
const password = "starter-test-password-1";
|
|
160
|
+
const responseId = z.object({ data: z.object({ id: z.uuid() }) });
|
|
161
|
+
type Http = Awaited<ReturnType<typeof startApp>>;
|
|
162
|
+
|
|
163
|
+
function requestHeaders(cookie?: string) {
|
|
164
|
+
return {
|
|
165
|
+
origin,
|
|
166
|
+
host: new URL(origin).host,
|
|
167
|
+
...(cookie === undefined ? {} : { cookie }),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function createAccount(
|
|
172
|
+
http: Http,
|
|
173
|
+
emails: StarterEmail[],
|
|
174
|
+
email: string,
|
|
175
|
+
) {
|
|
176
|
+
const signUp = await http.inject({
|
|
177
|
+
method: "POST",
|
|
178
|
+
url: "/api/auth/sign-up/email",
|
|
179
|
+
headers: requestHeaders(),
|
|
180
|
+
payload: { email, password, name: email },
|
|
181
|
+
});
|
|
182
|
+
expect(signUp.statusCode).toBe(200);
|
|
183
|
+
const mail = emails.find(
|
|
184
|
+
(message) => message.to === email && message.kind === "verify-email",
|
|
185
|
+
);
|
|
186
|
+
if (mail === undefined)
|
|
187
|
+
throw new Error("Verification email was not enqueued.");
|
|
188
|
+
const link = new URL(mail.url);
|
|
189
|
+
const verified = await http.inject({
|
|
190
|
+
method: "GET",
|
|
191
|
+
url: link.pathname + link.search,
|
|
192
|
+
headers: requestHeaders(),
|
|
193
|
+
});
|
|
194
|
+
expect([200, 302]).toContain(verified.statusCode);
|
|
195
|
+
const session = await http.inject({
|
|
196
|
+
method: "POST",
|
|
197
|
+
url: "/api/auth/sign-in/email",
|
|
198
|
+
headers: requestHeaders(),
|
|
199
|
+
payload: { email, password },
|
|
200
|
+
});
|
|
201
|
+
expect(session.statusCode).toBe(200);
|
|
202
|
+
const header = session.headers["set-cookie"];
|
|
203
|
+
const cookies = Array.isArray(header) ? header : [header];
|
|
204
|
+
const cookie = cookies
|
|
205
|
+
.map((value) => value?.split(";")[0])
|
|
206
|
+
.filter(Boolean)
|
|
207
|
+
.join("; ");
|
|
208
|
+
expect(cookie.length).toBeGreaterThan(0);
|
|
209
|
+
return cookie;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function createTenant(http: Http, cookie: string, name: string) {
|
|
213
|
+
const response = await http.inject({
|
|
214
|
+
method: "POST",
|
|
215
|
+
url: "/api/tenants",
|
|
216
|
+
headers: requestHeaders(cookie),
|
|
217
|
+
payload: { name },
|
|
218
|
+
});
|
|
219
|
+
expect(response.statusCode).toBe(201);
|
|
220
|
+
const parsed: unknown = JSON.parse(response.body);
|
|
221
|
+
return responseId.parse(parsed).data.id;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
it(
|
|
225
|
+
"migrates Postgres, serves health, isolates tenants, and denies cross-tenant writes",
|
|
226
|
+
{ timeout: 90_000 },
|
|
227
|
+
async () => {
|
|
228
|
+
const postgres = await new PostgreSqlContainer(
|
|
229
|
+
"postgres:16-alpine",
|
|
230
|
+
).start();
|
|
231
|
+
const state = await mkdtemp(join(tmpdir(), "dads-minimal-services-"));
|
|
232
|
+
try {
|
|
233
|
+
const databaseUrl = postgres.getConnectionUri();
|
|
234
|
+
await migrate(databaseUrl);
|
|
235
|
+
await migrate(databaseUrl);
|
|
236
|
+
const emails: StarterEmail[] = [];
|
|
237
|
+
const config = {
|
|
238
|
+
databaseUrl,
|
|
239
|
+
baseUrl: origin,
|
|
240
|
+
fileStorageDirectory: join(state, "files"),
|
|
241
|
+
secret,
|
|
242
|
+
enqueueEmail: (message: StarterEmail) => {
|
|
243
|
+
emails.push(message);
|
|
244
|
+
return Promise.resolve();
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
const customer = await startApp("customer", config);
|
|
248
|
+
const staff = await startApp("staff", config);
|
|
249
|
+
try {
|
|
250
|
+
expect(
|
|
251
|
+
(await customer.inject({ method: "GET", url: "/api/health" }))
|
|
252
|
+
.statusCode,
|
|
253
|
+
).toBe(200);
|
|
254
|
+
expect(
|
|
255
|
+
(await staff.inject({ method: "GET", url: "/api/health" }))
|
|
256
|
+
.statusCode,
|
|
257
|
+
).toBe(200);
|
|
258
|
+
|
|
259
|
+
const alpha = await createAccount(
|
|
260
|
+
customer,
|
|
261
|
+
emails,
|
|
262
|
+
"alpha@example.test",
|
|
263
|
+
);
|
|
264
|
+
const beta = await createAccount(customer, emails, "beta@example.test");
|
|
265
|
+
const alphaTenant = await createTenant(customer, alpha, "Alpha");
|
|
266
|
+
await createTenant(customer, beta, "Beta");
|
|
267
|
+
|
|
268
|
+
const alphaList = await customer.inject({
|
|
269
|
+
method: "GET",
|
|
270
|
+
url: "/api/tenants",
|
|
271
|
+
headers: requestHeaders(alpha),
|
|
272
|
+
});
|
|
273
|
+
expect(alphaList.statusCode).toBe(200);
|
|
274
|
+
expect(alphaList.body).toContain("Alpha");
|
|
275
|
+
expect(alphaList.body).not.toContain("Beta");
|
|
276
|
+
|
|
277
|
+
expect(
|
|
278
|
+
(
|
|
279
|
+
await customer.inject({
|
|
280
|
+
method: "POST",
|
|
281
|
+
url: \`/api/tenants/\${alphaTenant}/invitations\`,
|
|
282
|
+
headers: requestHeaders(beta),
|
|
283
|
+
payload: { email: "outsider@example.test" },
|
|
284
|
+
})
|
|
285
|
+
).statusCode,
|
|
286
|
+
).toBe(404);
|
|
287
|
+
expect(
|
|
288
|
+
(
|
|
289
|
+
await customer.inject({
|
|
290
|
+
method: "POST",
|
|
291
|
+
url: \`/api/tenants/\${alphaTenant}/invitations\`,
|
|
292
|
+
headers: requestHeaders(),
|
|
293
|
+
payload: { email: "outsider@example.test" },
|
|
294
|
+
})
|
|
295
|
+
).statusCode,
|
|
296
|
+
).toBe(401);
|
|
297
|
+
} finally {
|
|
298
|
+
await Promise.all([customer.close(), staff.close()]);
|
|
299
|
+
}
|
|
300
|
+
} finally {
|
|
301
|
+
await rm(state, { recursive: true, force: true });
|
|
302
|
+
await postgres.stop();
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
);
|
|
306
|
+
`,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//# sourceMappingURL=minimal-project-docs-and-tests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimal-project-docs-and-tests.js","sourceRoot":"","sources":["../../src/starter-project/minimal-project-docs-and-tests.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,MAAM,UAAU,6BAA6B;IAC3C,OAAO;QACL,iBAAiB,EAAE;QACnB,iBAAiB,EAAE;QACnB,uBAAuB,EAAE;QACzB,0BAA0B,EAAE;KAC7B,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CZ;KACE,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCZ;KACE,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB;IAC9B,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmCZ;KACE,CAAC;AACJ,CAAC;AAED,SAAS,0BAA0B;IACjC,OAAO;QACL,IAAI,EAAE,mCAAmC;QACzC,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgKZ;KACE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { StarterProjectFile } from "./render-starter-project.js";
|
|
2
|
+
/** Core server, domain, and bootstrap migration files for the minimal app. */
|
|
3
|
+
export declare function renderMinimalServerFiles(): readonly StarterProjectFile[];
|
|
4
|
+
//# sourceMappingURL=minimal-project-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimal-project-server.d.ts","sourceRoot":"","sources":["../../src/starter-project/minimal-project-server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,8EAA8E;AAC9E,wBAAgB,wBAAwB,IAAI,SAAS,kBAAkB,EAAE,CASxE"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { renderMinimalAssemblyFiles } from "./minimal-project-assembly.js";
|
|
2
|
+
/** Core server, domain, and bootstrap migration files for the minimal app. */
|
|
3
|
+
export function renderMinimalServerFiles() {
|
|
4
|
+
return [
|
|
5
|
+
customerEntrypointFile(),
|
|
6
|
+
staffEntrypointFile(),
|
|
7
|
+
...renderMinimalAssemblyFiles(),
|
|
8
|
+
tenantsIndexFile(),
|
|
9
|
+
tenantsPluginFile(),
|
|
10
|
+
starterMigrationFile(),
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
function customerEntrypointFile() {
|
|
14
|
+
return {
|
|
15
|
+
path: "apps/customer/app.ts",
|
|
16
|
+
content: `import { composeApi } from "@dads-framework/core/plugin";
|
|
17
|
+
|
|
18
|
+
import { starterAccess } from "../../assembly/model.js";
|
|
19
|
+
import type { ServiceProvider } from "../../assembly/services.js";
|
|
20
|
+
import { tenantsPlugin } from "../../domains/tenants/index.js";
|
|
21
|
+
// dad:add imports
|
|
22
|
+
|
|
23
|
+
export function customerApp(provider: ServiceProvider) {
|
|
24
|
+
return composeApi("customer", {
|
|
25
|
+
services: [provider, starterAccess],
|
|
26
|
+
routes: [
|
|
27
|
+
tenantsPlugin,
|
|
28
|
+
// dad:add domains
|
|
29
|
+
],
|
|
30
|
+
jobs: [],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
`,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function staffEntrypointFile() {
|
|
37
|
+
return {
|
|
38
|
+
path: "apps/staff/app.ts",
|
|
39
|
+
content: `import { composeApi } from "@dads-framework/core/plugin";
|
|
40
|
+
|
|
41
|
+
import { starterAccess } from "../../assembly/model.js";
|
|
42
|
+
import type { ServiceProvider } from "../../assembly/services.js";
|
|
43
|
+
import { tenantsPlugin } from "../../domains/tenants/index.js";
|
|
44
|
+
// dad:add imports
|
|
45
|
+
|
|
46
|
+
export function staffApp(provider: ServiceProvider) {
|
|
47
|
+
return composeApi("staff", {
|
|
48
|
+
services: [provider, starterAccess],
|
|
49
|
+
routes: [
|
|
50
|
+
tenantsPlugin,
|
|
51
|
+
// dad:add domains
|
|
52
|
+
],
|
|
53
|
+
jobs: [],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function tenantsIndexFile() {
|
|
60
|
+
return {
|
|
61
|
+
path: "domains/tenants/index.ts",
|
|
62
|
+
content: `export { tenantsPlugin } from "./server/plugin.js";
|
|
63
|
+
`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function tenantsPluginFile() {
|
|
67
|
+
return {
|
|
68
|
+
path: "domains/tenants/server/plugin.ts",
|
|
69
|
+
content: `import { definePlugin } from "@dads-framework/core/plugin";
|
|
70
|
+
import { starterServices } from "../../../libraries/app-runtime/index.js";
|
|
71
|
+
import { tenantInvitationRoutes } from "./invitation-routes.js";
|
|
72
|
+
import { tenantRoutes } from "./routes.js";
|
|
73
|
+
|
|
74
|
+
export const tenantsPlugin = definePlugin({
|
|
75
|
+
name: "tenant-routes",
|
|
76
|
+
requires: [starterServices],
|
|
77
|
+
setup: ({ use }) => {
|
|
78
|
+
const services = use(starterServices);
|
|
79
|
+
return {
|
|
80
|
+
routes: [
|
|
81
|
+
...tenantRoutes(services.tenants),
|
|
82
|
+
...tenantInvitationRoutes(services),
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function starterMigrationFile() {
|
|
91
|
+
return {
|
|
92
|
+
path: "migrations/20261120080000_starter.migration.ts",
|
|
93
|
+
content: `import {
|
|
94
|
+
configureAuditTriggers,
|
|
95
|
+
installAuditSchemaV1,
|
|
96
|
+
} from "@dads-framework/audit";
|
|
97
|
+
import { installFeatureFlagSchemaV1 } from "@dads-framework/feature-flags-postgres";
|
|
98
|
+
import { installIdentitySchemaV1 } from "@dads-framework/identity/better-auth";
|
|
99
|
+
import { relationshipSchemaMigration } from "@dads-framework/postgres-access";
|
|
100
|
+
import {
|
|
101
|
+
installTenantSchemaV1,
|
|
102
|
+
tenantAuditConfiguration,
|
|
103
|
+
} from "@dads-framework/identity/tenants";
|
|
104
|
+
import type { MigrationBuilder } from "node-pg-migrate";
|
|
105
|
+
|
|
106
|
+
export function up(pgm: MigrationBuilder): void {
|
|
107
|
+
pgm.sql(relationshipSchemaMigration.sql);
|
|
108
|
+
installIdentitySchemaV1(pgm);
|
|
109
|
+
installTenantSchemaV1(pgm);
|
|
110
|
+
installFeatureFlagSchemaV1(pgm);
|
|
111
|
+
installAuditSchemaV1(pgm);
|
|
112
|
+
configureAuditTriggers(pgm, tenantAuditConfiguration);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Bootstrap migrations only move forward. */
|
|
116
|
+
export const down = false;
|
|
117
|
+
`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=minimal-project-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimal-project-server.js","sourceRoot":"","sources":["../../src/starter-project/minimal-project-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAG3E,8EAA8E;AAC9E,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,sBAAsB,EAAE;QACxB,mBAAmB,EAAE;QACrB,GAAG,0BAA0B,EAAE;QAC/B,gBAAgB,EAAE;QAClB,iBAAiB,EAAE;QACnB,oBAAoB,EAAE;KACvB,CAAC;AACJ,CAAC;AAED,SAAS,sBAAsB;IAC7B,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE;;;;;;;;;;;;;;;;;CAiBZ;KACE,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB;IAC1B,OAAO;QACL,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE;;;;;;;;;;;;;;;;;CAiBZ;KACE,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB;IACvB,OAAO;QACL,IAAI,EAAE,0BAA0B;QAChC,OAAO,EAAE;CACZ;KACE,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO;QACL,IAAI,EAAE,kCAAkC;QACxC,OAAO,EAAE;;;;;;;;;;;;;;;;;;CAkBZ;KACE,CAAC;AACJ,CAAC;AAED,SAAS,oBAAoB;IAC3B,OAAO;QACL,IAAI,EAAE,gDAAgD;QACtD,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;CAwBZ;KACE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { StarterProjectFile } from "./render-starter-project.js";
|
|
2
|
+
/** Minimal React web shell: sign-in form, copy table, and browser entrypoint. */
|
|
3
|
+
export declare function renderMinimalWebFiles(): readonly StarterProjectFile[];
|
|
4
|
+
//# sourceMappingURL=minimal-project-web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minimal-project-web.d.ts","sourceRoot":"","sources":["../../src/starter-project/minimal-project-web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,iFAAiF;AACjF,wBAAgB,qBAAqB,IAAI,SAAS,kBAAkB,EAAE,CAErE"}
|