create-ailk 0.19.1 → 0.20.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 +64 -7
- package/dist/cli.js +35 -0
- package/dist/copy.d.ts +41 -0
- package/dist/copy.js +87 -21
- package/dist/lib/fetch-template-snapshot.d.ts +21 -0
- package/dist/lib/fetch-template-snapshot.js +205 -0
- package/dist/lib/merge-three-way.d.ts +31 -0
- package/dist/lib/merge-three-way.js +65 -0
- package/dist/module-architecture.js +55 -2
- package/dist/programmatic.d.ts +7 -1
- package/dist/programmatic.js +32 -2
- package/dist/spoke-checkout.d.ts +7 -0
- package/dist/spoke-checkout.js +8 -1
- package/dist/surfaces.js +67 -2
- package/dist/template-record.d.ts +59 -0
- package/dist/template-record.js +183 -0
- package/dist/update.d.ts +48 -0
- package/dist/update.js +504 -0
- package/package.json +3 -3
- package/templates/.claude/cloudparity-repo-hooks.json +9 -0
- package/templates/.claude/hooks/architecture-check.sh +8 -0
- package/templates/.claude/rules/loop-contract.md +129 -0
- package/templates/.claude/settings.json +3 -2
- package/templates/.env.example +13 -0
- package/templates/CLAUDE.md +1 -1
- package/templates/CONVENTIONS.md +3 -2
- package/templates/_gitignore +162 -0
- package/templates/apps/api/CLAUDE.md +14 -10
- package/templates/apps/api/package.json +2 -1
- package/templates/apps/api/src/__tests__/factories/in-memory-prisma.ts +22 -2
- package/templates/apps/api/src/__tests__/setup.ts +7 -0
- package/templates/apps/api/src/bin/__tests__/rate-limit-probe.test.ts +184 -0
- package/templates/apps/api/src/bin/rate-limit-probe.ts +53 -0
- package/templates/apps/api/src/lib/proposal-paid-store.ts +49 -0
- package/templates/apps/api/src/lib/rate-limit-probe.ts +165 -0
- package/templates/apps/api/src/lib/rate-limit-store.ts +142 -0
- package/templates/apps/api/src/middleware/__tests__/auth.hub-session-path.test.ts +5 -2
- package/templates/apps/api/src/middleware/__tests__/default-tenant.test.ts +2 -0
- package/templates/apps/api/src/middleware/__tests__/rate-limit-cross-isolate.db.test.ts +220 -0
- package/templates/apps/api/src/middleware/__tests__/rate-limit-store.test.ts +430 -0
- package/templates/apps/api/src/middleware/__tests__/rate-limit.test.ts +21 -14
- package/templates/apps/api/src/middleware/auth.ts +8 -4
- package/templates/apps/api/src/middleware/default-tenant.ts +9 -0
- package/templates/apps/api/src/middleware/rate-limit.ts +290 -82
- package/templates/apps/api/src/routes/webhooks/README.md +33 -5
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-proposal-paid.test.ts +369 -0
- package/templates/apps/api/src/routes/webhooks/__tests__/stripe-site-filter.test.ts +442 -0
- package/templates/apps/api/src/routes/webhooks/stripe.ts +184 -6
- package/templates/apps/api/src/server.ts +14 -2
- package/templates/apps/api/src/services/__tests__/audit-log.test.ts +91 -0
- package/templates/apps/api/src/services/audit-log.ts +72 -10
- package/templates/apps/api/src/services/default-tenant.ts +12 -3
- package/templates/apps/api/src/services/hub-sign-in.ts +2 -1
- package/templates/apps/api/src/services/public-site-resolver.ts +21 -2
- package/templates/apps/api/vercel.json +1 -1
- package/templates/apps/mcp/CLAUDE.md +19 -7
- package/templates/apps/mcp/__tests__/catalog-drift.test.ts +95 -8
- package/templates/apps/mcp/src/tools/person_notes.ts +25 -0
- package/templates/apps/mcp/src/tools/proposals.ts +27 -0
- package/templates/apps/mcp/src/workspace-server.ts +16 -0
- package/templates/apps/web/_gitignore +6 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-up/__tests__/sign-up-card.test.tsx +165 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-up/page.tsx +19 -0
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up-card.tsx +106 -23
- package/templates/apps/web/app/[locale]/(auth)/sign-up/sign-up.actions.ts +125 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +281 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +28 -83
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +27 -13
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +57 -2
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +2 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +102 -18
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +323 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +365 -0
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +3 -2
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +8 -0
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +170 -0
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +181 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +88 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +65 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +27 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +176 -3
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +193 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +188 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +65 -4
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +17 -0
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +11 -2
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +5 -24
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +64 -18
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +120 -0
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +322 -0
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +126 -0
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +43 -1
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +65 -0
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +226 -0
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +5 -3
- package/templates/apps/web/app/[locale]/consent-banner.tsx +32 -0
- package/templates/apps/web/app/[locale]/consent.actions.ts +71 -0
- package/templates/apps/web/app/[locale]/contact/contact.actions.ts +13 -1
- package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +25 -3
- package/templates/apps/web/app/[locale]/layout.tsx +23 -2
- package/templates/apps/web/app/[locale]/newsletter/newsletter.actions.ts +12 -1
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe-rsc-boundary.test.tsx +209 -0
- package/templates/apps/web/app/[locale]/unsubscribe/__tests__/unsubscribe.test.tsx +158 -0
- package/templates/apps/web/app/[locale]/unsubscribe/page.tsx +54 -0
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe-button.tsx +73 -0
- package/templates/apps/web/app/[locale]/unsubscribe/unsubscribe.actions.ts +55 -0
- package/templates/apps/web/app/robots.txt/route.ts +13 -10
- package/templates/apps/web/jest.config.cjs +3 -0
- package/templates/apps/web/lib/__tests__/consent-visitor.test.ts +163 -0
- package/templates/apps/web/lib/__tests__/relay.test.ts +49 -0
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +96 -7
- package/templates/apps/web/lib/account-config.ts +31 -16
- package/templates/apps/web/lib/consent-visitor.ts +103 -0
- package/templates/apps/web/lib/relay.ts +20 -0
- package/templates/apps/web/messages/en.json +67 -4
- package/templates/apps/web/next.config.mjs +8 -2
- package/templates/database/CHANGELOG.md +39 -0
- package/templates/database/__tests__/outbound-message-action.db.test.ts +80 -0
- package/templates/database/__tests__/person-notes.db.test.ts +249 -0
- package/templates/database/__tests__/piece-kind-migration.test.ts +67 -0
- package/templates/database/__tests__/piece-kind.db.test.ts +208 -0
- package/templates/database/_gitignore +8 -0
- package/templates/database/inbox/schema.prisma +38 -12
- package/templates/database/migrations/20261015120000_person_notes/migration.sql +77 -0
- package/templates/database/migrations/20261015120000_rate_limit_counters/migration.sql +43 -0
- package/templates/database/migrations/20261016120000_piece_kind/migration.sql +95 -0
- package/templates/database/migrations/20261017120000_outbound_message_action/migration.sql +30 -0
- package/templates/database/ops/schema.prisma +16 -0
- package/templates/database/package.json +1 -1
- package/templates/project.yaml +6 -3
- package/versions.json +35 -35
- package/templates/.claude/rules/preserve-existing-style.md +0 -51
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file piece-kind.db.test.ts
|
|
3
|
+
*
|
|
4
|
+
* LIVE-DATABASE proof of the piece kind and a proposal's price and payment
|
|
5
|
+
* columns (#8516, spec docs/specs/8516-proposals-as-an-artifact-kind-spec.md
|
|
6
|
+
* D1, D2, AC-1). Requires DATABASE_URL pointing at a Postgres with the
|
|
7
|
+
* migrations applied — SKIPS when DATABASE_URL is unset (the repo convention;
|
|
8
|
+
* the `apps/api Route Tests (Postgres)` workflow exercises it).
|
|
9
|
+
*
|
|
10
|
+
* Uses the `pg` driver directly, in ONE transaction that is rolled back, so
|
|
11
|
+
* dropping and re-adding the columns never outlives the suite. What it proves
|
|
12
|
+
* that a mock cannot:
|
|
13
|
+
* 1. Re-running the migration's own text over a piece written with the
|
|
14
|
+
* pre-#8516 column set reads it back as a `deliverable`, the seven other
|
|
15
|
+
* columns NULL and every pre-existing column (`updated_at` included)
|
|
16
|
+
* byte-equal — no row is rewritten.
|
|
17
|
+
* 2. Each CHECK and the unique index refuse what they name.
|
|
18
|
+
*/
|
|
19
|
+
import { readFileSync } from "node:fs";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
|
|
22
|
+
import { Client } from "pg";
|
|
23
|
+
|
|
24
|
+
const describeDb = process.env.DATABASE_URL ? describe : describe.skip;
|
|
25
|
+
|
|
26
|
+
const MIGRATION = join(__dirname, "..", "migrations", "20261016120000_piece_kind", "migration.sql");
|
|
27
|
+
|
|
28
|
+
const WS = "wksp_01920000-8516-7000-8000-0000000000c1";
|
|
29
|
+
const USER = "user_01920000-8516-7000-8000-0000000000a1";
|
|
30
|
+
const NEW_COLUMNS = [
|
|
31
|
+
"kind",
|
|
32
|
+
"price_amount",
|
|
33
|
+
"price_currency",
|
|
34
|
+
"checkout_session_id",
|
|
35
|
+
"checkout_url",
|
|
36
|
+
"checkout_expires_at",
|
|
37
|
+
"paid_at",
|
|
38
|
+
"paid_session_id",
|
|
39
|
+
] as const;
|
|
40
|
+
|
|
41
|
+
describeDb("the piece kind columns (#8516 D1, D2, AC-1, live DB)", () => {
|
|
42
|
+
let db: Client;
|
|
43
|
+
let personId: string;
|
|
44
|
+
|
|
45
|
+
beforeAll(async () => {
|
|
46
|
+
db = new Client({ connectionString: process.env.DATABASE_URL });
|
|
47
|
+
await db.connect();
|
|
48
|
+
await db.query("BEGIN");
|
|
49
|
+
personId = (
|
|
50
|
+
await db.query<{ id: string }>(
|
|
51
|
+
`INSERT INTO "people" ("workspace_id", "email", "updated_at") VALUES ($1, $2, now()) RETURNING "id"`,
|
|
52
|
+
[WS, "p8516@example.com"],
|
|
53
|
+
)
|
|
54
|
+
).rows[0]!.id;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
afterAll(async () => {
|
|
58
|
+
await db.query("ROLLBACK");
|
|
59
|
+
await db.end();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** Insert one piece with the pre-#8516 column set plus any of the new ones. */
|
|
63
|
+
const insertPiece = (cols: Record<string, unknown> = {}) => {
|
|
64
|
+
const all: Record<string, unknown> = {
|
|
65
|
+
workspace_id: WS,
|
|
66
|
+
person_id: personId,
|
|
67
|
+
title: "Site redesign",
|
|
68
|
+
stage: "requested",
|
|
69
|
+
updated_by: USER,
|
|
70
|
+
updated_at: new Date("2026-10-01T09:00:00.000Z"),
|
|
71
|
+
...cols,
|
|
72
|
+
};
|
|
73
|
+
const names = Object.keys(all);
|
|
74
|
+
return db.query<{ id: string }>(
|
|
75
|
+
`INSERT INTO "pieces" (${names.map((n) => `"${n}"`).join(", ")})
|
|
76
|
+
VALUES (${names.map((_, i) => `$${i + 1}`).join(", ")}) RETURNING "id"`,
|
|
77
|
+
names.map((n) => all[n]),
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/** Run `sql` inside a savepoint; resolve to the violated constraint's name, or null. */
|
|
82
|
+
const violation = async (run: () => Promise<unknown>): Promise<string | null> => {
|
|
83
|
+
await db.query("SAVEPOINT attempt");
|
|
84
|
+
try {
|
|
85
|
+
await run();
|
|
86
|
+
await db.query("RELEASE SAVEPOINT attempt");
|
|
87
|
+
return null;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
await db.query("ROLLBACK TO SAVEPOINT attempt");
|
|
90
|
+
return (err as { constraint?: string }).constraint ?? String(err);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
it("re-running the migration over a pre-#8516 row reads it as a deliverable, nothing else changed", async () => {
|
|
95
|
+
await db.query(
|
|
96
|
+
`ALTER TABLE "pieces" ${NEW_COLUMNS.map((c) => `DROP COLUMN "${c}"`).join(", ")}`,
|
|
97
|
+
);
|
|
98
|
+
const pieceId = (await insertPiece()).rows[0]!.id;
|
|
99
|
+
await db.query(
|
|
100
|
+
`INSERT INTO "piece_versions" ("workspace_id", "person_id", "piece_id", "version", "link", "delivered_by")
|
|
101
|
+
VALUES ($1, $2, $3, 1, 'https://example.com/v1.pdf', $4)`,
|
|
102
|
+
[WS, personId, pieceId, USER],
|
|
103
|
+
);
|
|
104
|
+
const before = (
|
|
105
|
+
await db.query<{ row: Record<string, unknown> }>(
|
|
106
|
+
`SELECT row_to_json(p) AS row FROM "pieces" p WHERE "id" = $1`,
|
|
107
|
+
[pieceId],
|
|
108
|
+
)
|
|
109
|
+
).rows[0]!.row;
|
|
110
|
+
|
|
111
|
+
await db.query(readFileSync(MIGRATION, "utf8"));
|
|
112
|
+
|
|
113
|
+
const after = (
|
|
114
|
+
await db.query<{ row: Record<string, unknown> }>(
|
|
115
|
+
`SELECT row_to_json(p) AS row FROM "pieces" p WHERE "id" = $1`,
|
|
116
|
+
[pieceId],
|
|
117
|
+
)
|
|
118
|
+
).rows[0]!.row;
|
|
119
|
+
expect(after.kind).toBe("deliverable");
|
|
120
|
+
for (const column of NEW_COLUMNS.slice(1)) expect(after[column]).toBeNull();
|
|
121
|
+
const kept = Object.fromEntries(
|
|
122
|
+
Object.entries(after).filter(([key]) => !(NEW_COLUMNS as readonly string[]).includes(key)),
|
|
123
|
+
);
|
|
124
|
+
expect(kept).toEqual(before);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("refuses a kind outside the two", async () => {
|
|
128
|
+
expect(await violation(() => insertPiece({ kind: "other" }))).toBe("pieces_kind_allowed");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("refuses a price on a deliverable, half a price, and an amount out of range", async () => {
|
|
132
|
+
expect(
|
|
133
|
+
await violation(() => insertPiece({ price_amount: 1000, price_currency: "usd" })),
|
|
134
|
+
).toBe("pieces_price_proposal_only");
|
|
135
|
+
expect(await violation(() => insertPiece({ kind: "proposal", price_amount: 1000 }))).toBe(
|
|
136
|
+
"pieces_price_pair",
|
|
137
|
+
);
|
|
138
|
+
for (const amount of [0, 100000001]) {
|
|
139
|
+
expect(
|
|
140
|
+
await violation(() =>
|
|
141
|
+
insertPiece({ kind: "proposal", price_amount: amount, price_currency: "usd" }),
|
|
142
|
+
),
|
|
143
|
+
).toBe("pieces_price_range");
|
|
144
|
+
}
|
|
145
|
+
expect(
|
|
146
|
+
await violation(() =>
|
|
147
|
+
insertPiece({ kind: "proposal", price_amount: 1, price_currency: "usd" }),
|
|
148
|
+
),
|
|
149
|
+
).toBeNull();
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const SESSION = {
|
|
153
|
+
checkout_session_id: "cs_test_a1",
|
|
154
|
+
checkout_url: "https://checkout.stripe.com/c/pay/cs_test_a1",
|
|
155
|
+
checkout_expires_at: new Date("2026-10-16T13:00:00.000Z"),
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
it("refuses a checkout session on an unapproved or unpriced piece, and a partial session", async () => {
|
|
159
|
+
expect(
|
|
160
|
+
await violation(() =>
|
|
161
|
+
insertPiece({ kind: "proposal", price_amount: 5000, price_currency: "usd", ...SESSION }),
|
|
162
|
+
),
|
|
163
|
+
).toBe("pieces_checkout_needs_approved_price");
|
|
164
|
+
expect(
|
|
165
|
+
await violation(() => insertPiece({ kind: "proposal", approved_at: new Date(), ...SESSION })),
|
|
166
|
+
).toBe("pieces_checkout_needs_approved_price");
|
|
167
|
+
expect(
|
|
168
|
+
await violation(() =>
|
|
169
|
+
insertPiece({
|
|
170
|
+
kind: "proposal",
|
|
171
|
+
price_amount: 5000,
|
|
172
|
+
price_currency: "usd",
|
|
173
|
+
approved_at: new Date(),
|
|
174
|
+
checkout_session_id: "cs_test_a2",
|
|
175
|
+
}),
|
|
176
|
+
),
|
|
177
|
+
).toBe("pieces_checkout_triple");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("refuses paid_at without the session that paid it", async () => {
|
|
181
|
+
expect(
|
|
182
|
+
await violation(() =>
|
|
183
|
+
insertPiece({
|
|
184
|
+
kind: "proposal",
|
|
185
|
+
price_amount: 5000,
|
|
186
|
+
price_currency: "usd",
|
|
187
|
+
approved_at: new Date(),
|
|
188
|
+
paid_at: new Date(),
|
|
189
|
+
}),
|
|
190
|
+
),
|
|
191
|
+
).toBe("pieces_paid_pair");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("refuses two pieces holding one checkout session", async () => {
|
|
195
|
+
const approvedPriced = {
|
|
196
|
+
kind: "proposal",
|
|
197
|
+
price_amount: 5000,
|
|
198
|
+
price_currency: "usd",
|
|
199
|
+
approved_at: new Date(),
|
|
200
|
+
...SESSION,
|
|
201
|
+
checkout_session_id: "cs_test_dup",
|
|
202
|
+
};
|
|
203
|
+
expect(await violation(() => insertPiece(approvedPriced))).toBeNull();
|
|
204
|
+
expect(await violation(() => insertPiece(approvedPriced))).toBe(
|
|
205
|
+
"pieces_checkout_session_id_key",
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -155,6 +155,14 @@ model Person {
|
|
|
155
155
|
// NULL and `userId` is NULL, a capture may fill a blank field (D4).
|
|
156
156
|
contactConfirmedAt DateTime? @map("contact_confirmed_at")
|
|
157
157
|
contactConfirmedBy String? @map("contact_confirmed_by") @db.VarChar(16)
|
|
158
|
+
// #8514 D1 — the team's private note on this client: one per Person, never
|
|
159
|
+
// served to the client. Who last saved it (a user id of the auth namespace,
|
|
160
|
+
// no foreign key — ADR 0009) and when; both NULL until the first save.
|
|
161
|
+
// When an agent saved it, which agent (its person is notesUpdatedBy).
|
|
162
|
+
notes String? @db.VarChar(5000)
|
|
163
|
+
notesUpdatedAt DateTime? @map("notes_updated_at")
|
|
164
|
+
notesUpdatedBy String? @map("notes_updated_by")
|
|
165
|
+
notesUpdatedByAgent String? @map("notes_updated_by_agent")
|
|
158
166
|
createdAt DateTime @default(now()) @map("created_at")
|
|
159
167
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
160
168
|
|
|
@@ -174,7 +182,7 @@ model Person {
|
|
|
174
182
|
@@map("people")
|
|
175
183
|
}
|
|
176
184
|
|
|
177
|
-
/// Piece — one deliverable for one client (#7877). Written only through
|
|
185
|
+
/// Piece — one deliverable or proposal for one client (#7877, #8516). Written only through
|
|
178
186
|
/// tenantDb(tenant).memberArea; read by a client only through
|
|
179
187
|
/// lib/member-store.ts. `stage` is one of the workspace's declared stages
|
|
180
188
|
/// (WorkspacePieceStages), checked at write time, never an enum.
|
|
@@ -184,16 +192,32 @@ model Person {
|
|
|
184
192
|
/// review lands. Approval is a piece-level fact; the version's own `review`
|
|
185
193
|
/// records which version was approved.
|
|
186
194
|
model Piece {
|
|
187
|
-
id
|
|
188
|
-
workspaceId
|
|
189
|
-
personId
|
|
190
|
-
title
|
|
191
|
-
stage
|
|
192
|
-
needsClient
|
|
193
|
-
updatedBy
|
|
194
|
-
approvedAt
|
|
195
|
-
|
|
196
|
-
|
|
195
|
+
id String @id @default(dbgenerated("('piece_'::text || (uuidv7())::text)")) @db.Text
|
|
196
|
+
workspaceId String @map("workspace_id")
|
|
197
|
+
personId String @map("person_id")
|
|
198
|
+
title String @db.VarChar(200)
|
|
199
|
+
stage String @db.VarChar(40)
|
|
200
|
+
needsClient Boolean @default(false) @map("needs_client")
|
|
201
|
+
updatedBy String @map("updated_by")
|
|
202
|
+
approvedAt DateTime? @map("approved_at")
|
|
203
|
+
// #8516 D1 — what the piece is: a `deliverable` (every row before #8516) or a
|
|
204
|
+
// `proposal` the client approves or sends back. Never changes after create.
|
|
205
|
+
kind String @default("deliverable") @db.VarChar(16)
|
|
206
|
+
// A proposal's price, in minor units of a two-decimal currency; both or
|
|
207
|
+
// neither, and only on a proposal.
|
|
208
|
+
priceAmount Int? @map("price_amount")
|
|
209
|
+
priceCurrency String? @map("price_currency") @db.Char(3)
|
|
210
|
+
// The client's current Stripe Checkout Session (#8516 D11) — its id, URL and
|
|
211
|
+
// expiry. Never served to the operator. Replaced once five minutes or less
|
|
212
|
+
// remain; the replaced session is expired at Stripe.
|
|
213
|
+
checkoutSessionId String? @unique @map("checkout_session_id")
|
|
214
|
+
checkoutUrl String? @map("checkout_url") @db.VarChar(2048)
|
|
215
|
+
checkoutExpiresAt DateTime? @map("checkout_expires_at")
|
|
216
|
+
// When Stripe reported the proposal paid, and the session that paid it (D13).
|
|
217
|
+
paidAt DateTime? @map("paid_at")
|
|
218
|
+
paidSessionId String? @map("paid_session_id")
|
|
219
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
220
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
197
221
|
|
|
198
222
|
person Person @relation(fields: [personId, workspaceId], references: [id, workspaceId], onDelete: Restrict, map: "pieces_person_fk")
|
|
199
223
|
versions PieceVersion[]
|
|
@@ -249,7 +273,9 @@ model PieceVersion {
|
|
|
249
273
|
///
|
|
250
274
|
/// #8168 D3/D4 — `direction` is `outbound` (an operator's message, #7877) or
|
|
251
275
|
/// `inbound` (a client's own write); `kind` is `message`, `quote` or
|
|
252
|
-
/// `review`. An outbound row is always a `message`
|
|
276
|
+
/// `review`. An outbound row is always a `message` whose `payload` is null
|
|
277
|
+
/// or, since #8515 D6, exactly `{ "action": "onboarding" }` — the one outbound
|
|
278
|
+
/// action, rendered by the client's site as a link to `/account/onboarding`
|
|
253
279
|
/// (`interactions_outbound_shape`); a `quote` or `review` row carries the
|
|
254
280
|
/// stored payload `packages/validation`'s member.ts types. Every existing
|
|
255
281
|
/// reader filters to `direction: "outbound"`, so an inbound row is invisible
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
-- #8514 — the client record's private notes (spec
|
|
2
|
+
-- docs/specs/8514-redesign-the-person-record-page-spec.md D1, D2).
|
|
3
|
+
--
|
|
4
|
+
-- people (4 columns) — the team's one note on a client (never served to the
|
|
5
|
+
-- client), who last saved it (a user id of the auth
|
|
6
|
+
-- namespace, no foreign key — ADR 0009, the
|
|
7
|
+
-- piece_versions.delivered_by precedent), when, and which
|
|
8
|
+
-- agent when an agent saved it. Every column is nullable
|
|
9
|
+
-- and has no default, so Postgres changes only the catalog.
|
|
10
|
+
--
|
|
11
|
+
-- DDL first, then one data statement (D2b, below the marker): the DDL adds
|
|
12
|
+
-- columns and CHECKs only; the data half removes inert client grants from
|
|
13
|
+
-- agents of members. One directory, per the one-migration-per-milestone
|
|
14
|
+
-- check (the #8435 person_contact shape). Prisma runs this file as one
|
|
15
|
+
-- transaction; each CHECK below is added NOT VALID and then VALIDATEd over an
|
|
16
|
+
-- all-NULL column, and the data half touches "agents" alone.
|
|
17
|
+
--
|
|
18
|
+
-- Rollout: deploy this migration BEFORE the API code that reads and writes the
|
|
19
|
+
-- notes and gives members the client rows; code without the columns fails
|
|
20
|
+
-- every notes read, and code before the grant reset would switch the inert
|
|
21
|
+
-- grants on (SEC-8514-B).
|
|
22
|
+
--
|
|
23
|
+
-- Rollback: ALTER TABLE "people" DROP COLUMN "notes", DROP COLUMN
|
|
24
|
+
-- "notes_updated_at", DROP COLUMN "notes_updated_by", DROP COLUMN
|
|
25
|
+
-- "notes_updated_by_agent"; (the CHECKs go with them). The grant reset needs
|
|
26
|
+
-- none: every grant it removes was inert.
|
|
27
|
+
|
|
28
|
+
-- AlterTable
|
|
29
|
+
ALTER TABLE "people" ADD COLUMN "notes" VARCHAR(5000),
|
|
30
|
+
ADD COLUMN "notes_updated_at" TIMESTAMP(3),
|
|
31
|
+
ADD COLUMN "notes_updated_by" TEXT,
|
|
32
|
+
ADD COLUMN "notes_updated_by_agent" TEXT;
|
|
33
|
+
|
|
34
|
+
-- The editor is a user id of the auth namespace (the delivered_by shape).
|
|
35
|
+
ALTER TABLE "people" ADD CONSTRAINT "people_notes_updated_by_format"
|
|
36
|
+
CHECK ("notes_updated_by" IS NULL OR "notes_updated_by" ~ '^user_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$') NOT VALID;
|
|
37
|
+
ALTER TABLE "people" VALIDATE CONSTRAINT "people_notes_updated_by_format";
|
|
38
|
+
|
|
39
|
+
-- The agent, when one saved it, is an agent id (the agents_id_format shape).
|
|
40
|
+
ALTER TABLE "people" ADD CONSTRAINT "people_notes_updated_by_agent_format"
|
|
41
|
+
CHECK ("notes_updated_by_agent" IS NULL OR "notes_updated_by_agent" ~ '^agent_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$') NOT VALID;
|
|
42
|
+
ALTER TABLE "people" VALIDATE CONSTRAINT "people_notes_updated_by_agent_format";
|
|
43
|
+
|
|
44
|
+
-- Who and when are written together.
|
|
45
|
+
ALTER TABLE "people" ADD CONSTRAINT "people_notes_edit_pair"
|
|
46
|
+
CHECK (("notes_updated_at" IS NULL) = ("notes_updated_by" IS NULL)) NOT VALID;
|
|
47
|
+
ALTER TABLE "people" VALIDATE CONSTRAINT "people_notes_edit_pair";
|
|
48
|
+
|
|
49
|
+
-- An agent's save always names the agent's person.
|
|
50
|
+
ALTER TABLE "people" ADD CONSTRAINT "people_notes_agent_has_person"
|
|
51
|
+
CHECK ("notes_updated_by_agent" IS NULL OR "notes_updated_by" IS NOT NULL) NOT VALID;
|
|
52
|
+
ALTER TABLE "people" VALIDATE CONSTRAINT "people_notes_agent_has_person";
|
|
53
|
+
|
|
54
|
+
-- ===== #8514 D2b member agent grant reset (data only; runs after the DDL above) =====
|
|
55
|
+
-- #8514 — dormant client grants cleared from agents of members (spec
|
|
56
|
+
-- docs/specs/8514-redesign-the-person-record-page-spec.md D2b, SEC-8514-B).
|
|
57
|
+
--
|
|
58
|
+
-- Until #8514 a member held neither people-read nor member-pieces-manage, so
|
|
59
|
+
-- the agent clamp (`can(personTenant.role, p)`) dropped either grant stored on
|
|
60
|
+
-- a member's agent: it was inert. #8514 gives members both by role, and the
|
|
61
|
+
-- clamp would then switch those stored grants on with no admin action. This
|
|
62
|
+
-- removes them first, so a member's agent holds either only once an owner or
|
|
63
|
+
-- admin grants it after the deploy.
|
|
64
|
+
--
|
|
65
|
+
-- DATA ONLY. Changes no effective permission at the time it runs (every grant
|
|
66
|
+
-- it removes is inert). Idempotent: a second run matches no row.
|
|
67
|
+
--
|
|
68
|
+
-- Rollout: in the same deploy as, and BEFORE, the #8514 API code.
|
|
69
|
+
--
|
|
70
|
+
-- Rollback: none needed — every removed grant was inert.
|
|
71
|
+
|
|
72
|
+
UPDATE "agents" a
|
|
73
|
+
SET "grants" = array_remove(array_remove(a."grants", 'people-read'), 'member-pieces-manage')
|
|
74
|
+
FROM "memberships" m
|
|
75
|
+
WHERE m."id" = a."responsible_membership_id"
|
|
76
|
+
AND m."role" = 'member'
|
|
77
|
+
AND a."grants" && ARRAY['people-read', 'member-pieces-manage']::text[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
-- #5040 — the rate limiter's shared database store (spec
|
|
2
|
+
-- docs/specs/5040-the-api-s-rate-limiter-spec.md D2/D3). One row per bucket
|
|
3
|
+
-- key hash; the middleware's database store (`apps/api/src/lib/rate-limit-store.ts`)
|
|
4
|
+
-- is the only reader or writer. Belongs to the deployment, not a tenant: no
|
|
5
|
+
-- workspace_id, no tenancy fence. Rows are disposable — a lost counter only
|
|
6
|
+
-- resets a window.
|
|
7
|
+
--
|
|
8
|
+
-- Rollback (safe while no code selects the database store, i.e. deploy this
|
|
9
|
+
-- migration before the code that reads AILK_RATE_LIMIT_STORE=database or
|
|
10
|
+
-- defaults to it with DATABASE_URL set):
|
|
11
|
+
-- DROP TABLE "rate_limit_counters";
|
|
12
|
+
|
|
13
|
+
-- CreateTable
|
|
14
|
+
CREATE TABLE "rate_limit_counters" (
|
|
15
|
+
"id" TEXT NOT NULL DEFAULT ('rlc_'::text || (uuidv7())::text),
|
|
16
|
+
"key_hash" TEXT NOT NULL,
|
|
17
|
+
"window_start_ms" BIGINT NOT NULL,
|
|
18
|
+
"window_ms" INTEGER NOT NULL,
|
|
19
|
+
"count" INTEGER NOT NULL,
|
|
20
|
+
"created_at" TIMESTAMPTZ NOT NULL DEFAULT now(),
|
|
21
|
+
|
|
22
|
+
CONSTRAINT "rate_limit_counters_pkey" PRIMARY KEY ("id")
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
-- CreateIndex
|
|
26
|
+
CREATE UNIQUE INDEX "rate_limit_counters_key_hash_key" ON "rate_limit_counters"("key_hash");
|
|
27
|
+
|
|
28
|
+
-- CreateIndex
|
|
29
|
+
-- The sweep: DELETE WHERE window_start_ms + window_ms <= now.
|
|
30
|
+
CREATE INDEX "rate_limit_counters_window_start_ms_idx" ON "rate_limit_counters"("window_start_ms");
|
|
31
|
+
|
|
32
|
+
-- ADR-0031 rule 3 — rate_limit_counters: rlc_ (registered in
|
|
33
|
+
-- packages/ids/src/registry.ts; this migration's path is added to
|
|
34
|
+
-- migration-sync.test.ts's PK_CHECK_MIGRATIONS).
|
|
35
|
+
ALTER TABLE "rate_limit_counters" ALTER COLUMN "id" SET DEFAULT ('rlc_'::text || (uuidv7())::text);
|
|
36
|
+
ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_id_format" CHECK ("id" ~ '^rlc_[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$');
|
|
37
|
+
|
|
38
|
+
-- D2 — key_hash is always a sha256 hex digest, never the raw bucket key.
|
|
39
|
+
ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_key_hash_hex" CHECK ("key_hash" ~ '^[0-9a-f]{64}$');
|
|
40
|
+
|
|
41
|
+
-- D2 — window_ms > 0, count >= 1.
|
|
42
|
+
ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_window_ms_positive" CHECK ("window_ms" > 0);
|
|
43
|
+
ALTER TABLE "rate_limit_counters" ADD CONSTRAINT "rate_limit_counters_count_positive" CHECK ("count" >= 1);
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
-- #8516 — proposals as an artifact kind (spec
|
|
2
|
+
-- docs/specs/8516-proposals-as-an-artifact-kind-spec.md D1, D2).
|
|
3
|
+
--
|
|
4
|
+
-- pieces (8 columns) — what a piece is (`kind`: `deliverable` or
|
|
5
|
+
-- `proposal`), a proposal's optional price (minor units
|
|
6
|
+
-- of a two-decimal currency), the client's current Stripe
|
|
7
|
+
-- Checkout Session (id, URL, expiry) and when Stripe
|
|
8
|
+
-- reported the proposal paid, with the session that paid
|
|
9
|
+
-- it. Stripe objects are named by plain columns with a
|
|
10
|
+
-- format CHECK and no foreign key (ADR 0009).
|
|
11
|
+
--
|
|
12
|
+
-- DDL only. Every existing row reads `kind = 'deliverable'` from the constant
|
|
13
|
+
-- default — Postgres stores the default in the catalog and rewrites no row, so
|
|
14
|
+
-- `updated_at` and every other column of an existing piece are unchanged. The
|
|
15
|
+
-- seven other columns are nullable with no default. Each CHECK below is added
|
|
16
|
+
-- NOT VALID and then VALIDATEd; every existing row passes each one (a
|
|
17
|
+
-- deliverable with every new column NULL).
|
|
18
|
+
--
|
|
19
|
+
-- Rollout: deploy this migration BEFORE the API code that reads and writes the
|
|
20
|
+
-- columns; code without them fails every piece read.
|
|
21
|
+
--
|
|
22
|
+
-- Rollback: DROP INDEX "pieces_checkout_session_id_key"; ALTER TABLE "pieces"
|
|
23
|
+
-- DROP COLUMN "kind", DROP COLUMN "price_amount", DROP COLUMN
|
|
24
|
+
-- "price_currency", DROP COLUMN "checkout_session_id", DROP COLUMN
|
|
25
|
+
-- "checkout_url", DROP COLUMN "checkout_expires_at", DROP COLUMN "paid_at",
|
|
26
|
+
-- DROP COLUMN "paid_session_id"; (the CHECKs go with them).
|
|
27
|
+
|
|
28
|
+
-- AlterTable
|
|
29
|
+
ALTER TABLE "pieces" ADD COLUMN "kind" VARCHAR(16) NOT NULL DEFAULT 'deliverable',
|
|
30
|
+
ADD COLUMN "price_amount" INTEGER,
|
|
31
|
+
ADD COLUMN "price_currency" CHAR(3),
|
|
32
|
+
ADD COLUMN "checkout_session_id" TEXT,
|
|
33
|
+
ADD COLUMN "checkout_url" VARCHAR(2048),
|
|
34
|
+
ADD COLUMN "checkout_expires_at" TIMESTAMP(3),
|
|
35
|
+
ADD COLUMN "paid_at" TIMESTAMP(3),
|
|
36
|
+
ADD COLUMN "paid_session_id" TEXT;
|
|
37
|
+
|
|
38
|
+
-- CreateIndex
|
|
39
|
+
CREATE UNIQUE INDEX "pieces_checkout_session_id_key" ON "pieces"("checkout_session_id");
|
|
40
|
+
|
|
41
|
+
-- A piece is a deliverable or a proposal, nothing else.
|
|
42
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_kind_allowed"
|
|
43
|
+
CHECK ("kind" IN ('deliverable', 'proposal')) NOT VALID;
|
|
44
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_kind_allowed";
|
|
45
|
+
|
|
46
|
+
-- An amount and its currency are written together.
|
|
47
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_pair"
|
|
48
|
+
CHECK (("price_amount" IS NULL) = ("price_currency" IS NULL)) NOT VALID;
|
|
49
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_pair";
|
|
50
|
+
|
|
51
|
+
-- 1 to 100,000,000 minor units (PROPOSAL_PRICE_MAX_MINOR).
|
|
52
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_range"
|
|
53
|
+
CHECK ("price_amount" IS NULL OR "price_amount" BETWEEN 1 AND 100000000) NOT VALID;
|
|
54
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_range";
|
|
55
|
+
|
|
56
|
+
-- A lower-case ISO-4217 code.
|
|
57
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_currency_format"
|
|
58
|
+
CHECK ("price_currency" IS NULL OR "price_currency" ~ '^[a-z]{3}$') NOT VALID;
|
|
59
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_currency_format";
|
|
60
|
+
|
|
61
|
+
-- Only a proposal carries a price.
|
|
62
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_price_proposal_only"
|
|
63
|
+
CHECK ("price_amount" IS NULL OR "kind" = 'proposal') NOT VALID;
|
|
64
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_price_proposal_only";
|
|
65
|
+
|
|
66
|
+
-- A Checkout Session's id, URL and expiry are written together.
|
|
67
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_triple"
|
|
68
|
+
CHECK (("checkout_session_id" IS NULL) = ("checkout_url" IS NULL)
|
|
69
|
+
AND ("checkout_session_id" IS NULL) = ("checkout_expires_at" IS NULL)) NOT VALID;
|
|
70
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_triple";
|
|
71
|
+
|
|
72
|
+
-- A Stripe Checkout Session id.
|
|
73
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_session_format"
|
|
74
|
+
CHECK ("checkout_session_id" IS NULL OR "checkout_session_id" ~ '^cs_(test|live)_[A-Za-z0-9]{1,250}$') NOT VALID;
|
|
75
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_session_format";
|
|
76
|
+
|
|
77
|
+
-- A Checkout URL is https.
|
|
78
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_url_https"
|
|
79
|
+
CHECK ("checkout_url" IS NULL OR "checkout_url" ~ '^https://') NOT VALID;
|
|
80
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_url_https";
|
|
81
|
+
|
|
82
|
+
-- A Checkout Session opens only for an approved, priced proposal.
|
|
83
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_checkout_needs_approved_price"
|
|
84
|
+
CHECK ("checkout_session_id" IS NULL OR ("price_amount" IS NOT NULL AND "approved_at" IS NOT NULL)) NOT VALID;
|
|
85
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_checkout_needs_approved_price";
|
|
86
|
+
|
|
87
|
+
-- When paid and the session that paid are written together.
|
|
88
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_paid_pair"
|
|
89
|
+
CHECK (("paid_at" IS NULL) = ("paid_session_id" IS NULL)) NOT VALID;
|
|
90
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_paid_pair";
|
|
91
|
+
|
|
92
|
+
-- Only a priced proposal is paid.
|
|
93
|
+
ALTER TABLE "pieces" ADD CONSTRAINT "pieces_paid_needs_price"
|
|
94
|
+
CHECK ("paid_at" IS NULL OR "price_amount" IS NOT NULL) NOT VALID;
|
|
95
|
+
ALTER TABLE "pieces" VALIDATE CONSTRAINT "pieces_paid_needs_price";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- #8515 — an outbound message may carry the onboarding action (spec
|
|
2
|
+
-- docs/specs/8515-standard-client-onboarding-diagnostic-and-spec.md D6).
|
|
3
|
+
--
|
|
4
|
+
-- `interactions_outbound_shape` (20261012120000_member_contract) admitted an
|
|
5
|
+
-- outbound row only as a payload-free `message`. Start onboarding writes an
|
|
6
|
+
-- outbound `message` whose `payload` is exactly `{"action": "onboarding"}`,
|
|
7
|
+
-- which the client's own site renders as a link to its `/account/onboarding`.
|
|
8
|
+
-- The CHECK is replaced in place, under the same name, admitting that one
|
|
9
|
+
-- payload and nothing else; no other constraint changes and no row is
|
|
10
|
+
-- rewritten. The new CHECK is added NOT VALID and then VALIDATEd (the #8516
|
|
11
|
+
-- piece_kind shape). The DROP takes ACCESS EXCLUSIVE and, in the migration's
|
|
12
|
+
-- one transaction, holds it through the VALIDATE scan, so the table is locked
|
|
13
|
+
-- for that scan; in exchange there is no moment without the constraint. Every
|
|
14
|
+
-- existing outbound row is payload-free and passes.
|
|
15
|
+
--
|
|
16
|
+
-- Folder name: the spec named 20261016120000; #8516's 20261016120000_piece_kind
|
|
17
|
+
-- landed first at that timestamp, so this sorts after it (spec §5.3).
|
|
18
|
+
--
|
|
19
|
+
-- Rollback — only AFTER the code is rolled back (running code would write
|
|
20
|
+
-- rows the old CHECK refuses):
|
|
21
|
+
-- UPDATE "interactions" SET "payload" = NULL WHERE "direction" = 'outbound';
|
|
22
|
+
-- ALTER TABLE "interactions" DROP CONSTRAINT "interactions_outbound_shape";
|
|
23
|
+
-- ALTER TABLE "interactions" ADD CONSTRAINT "interactions_outbound_shape"
|
|
24
|
+
-- CHECK ("direction" <> 'outbound' OR ("kind" = 'message' AND "payload" IS NULL));
|
|
25
|
+
-- Clients then lose the Open onboarding link on those messages; the body stays.
|
|
26
|
+
|
|
27
|
+
ALTER TABLE "interactions" DROP CONSTRAINT "interactions_outbound_shape";
|
|
28
|
+
ALTER TABLE "interactions" ADD CONSTRAINT "interactions_outbound_shape"
|
|
29
|
+
CHECK ("direction" <> 'outbound' OR ("kind" = 'message' AND ("payload" IS NULL OR "payload" = '{"action": "onboarding"}'::jsonb))) NOT VALID;
|
|
30
|
+
ALTER TABLE "interactions" VALIDATE CONSTRAINT "interactions_outbound_shape";
|
|
@@ -25,3 +25,19 @@ model AuditLog {
|
|
|
25
25
|
@@index([workspaceId, targetType, targetId])
|
|
26
26
|
@@map("audit_logs")
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
/// RateLimitCounter — the shared per-bucket counter for `rateLimitMiddleware`'s
|
|
30
|
+
/// database store (#5040 D2). Belongs to the deployment, not a tenant: no
|
|
31
|
+
/// workspaceId, no tenancy fence. Rows are disposable — a lost counter only
|
|
32
|
+
/// resets a window. `key_hash` is sha256(bucketKey) hex, never the raw key.
|
|
33
|
+
model RateLimitCounter {
|
|
34
|
+
id String @id @default(dbgenerated("('rlc_'::text || (uuidv7())::text)")) @db.Text
|
|
35
|
+
keyHash String @unique @map("key_hash") @db.Text // sha256(bucketKey) hex
|
|
36
|
+
windowStartMs BigInt @map("window_start_ms")
|
|
37
|
+
windowMs Int @map("window_ms")
|
|
38
|
+
count Int
|
|
39
|
+
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz
|
|
40
|
+
|
|
41
|
+
@@index([windowStartMs], map: "rate_limit_counters_window_start_ms_idx")
|
|
42
|
+
@@map("rate_limit_counters")
|
|
43
|
+
}
|
package/templates/project.yaml
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
schema_version: 1
|
|
2
2
|
|
|
3
3
|
# project.yaml — per-repo configuration consumed by Claude Code skills and
|
|
4
|
-
# global rules. Replace REPLACE_ME
|
|
4
|
+
# global rules. Replace every REPLACE_ME value with your repo's own: its
|
|
5
|
+
# identity and its Slack channel.
|
|
5
6
|
#
|
|
6
7
|
# See https://github.com/working-theory-labs/ai-launch-kit/blob/main/project.yaml
|
|
7
8
|
# for AI Launch Kit's own canonical example.
|
|
@@ -10,10 +11,13 @@ identity:
|
|
|
10
11
|
name: REPLACE_ME # your repo slug, kebab-case
|
|
11
12
|
github_repo: REPLACE_ME/REPLACE_ME # owner/repo on GitHub
|
|
12
13
|
npm_scope: "@REPLACE_ME" # e.g. "@yourorg" — replace with your npm scope
|
|
13
|
-
visibility: private # "
|
|
14
|
+
visibility: private # "public" | "private" | "internal"
|
|
14
15
|
default_branch: main
|
|
15
16
|
branching_model: single_trunk
|
|
16
17
|
|
|
18
|
+
slack:
|
|
19
|
+
primary_channel: REPLACE_ME # channel name without "#", where this repo's CI and agent reports land
|
|
20
|
+
|
|
17
21
|
product:
|
|
18
22
|
identity_mode: organization # "organization" | "person" | null
|
|
19
23
|
default_locale: en
|
|
@@ -27,7 +31,6 @@ labels:
|
|
|
27
31
|
blocked: status/blocked
|
|
28
32
|
done: status/done
|
|
29
33
|
needs_spec: status/needs-spec
|
|
30
|
-
auto_merge: auto-merge-eligible
|
|
31
34
|
|
|
32
35
|
verification:
|
|
33
36
|
preflight: pnpm preflight
|