Reorganize repo structure and standards references

This commit is contained in:
david committed 2026-06-29 05:03:42 +02:00
1 parent 3cb93a81be
commit be2054274d
5885 files changed
+2588 -195

No files matched your search

@@ -0,0 +1,47 @@
/**
* `forms create --tenant <id> --name <name> [--origin <url>]` — seed a
* minimal form definition (text + email + textarea + honeypot) and
* print the resulting public key for embed-snippet wiring.
*/
import { defineCommand } from "citty";
import consola from "consola";
import { FormDefinitionSchema, HONEYPOT_FIELD_KEY } from "@toolctrl/form-widget";
export const formsCreateCommand = defineCommand({
meta: { name: "create", description: "Seed a minimal form for a tenant." },
args: {
tenant: { type: "string", required: true, description: "Tenant ID." },
name: { type: "string", required: true, description: "Form display name." },
origin: { type: "string", required: false, description: "Allowed embedding origin (https://...)." },
},
async run({ args }) {
const tenantId = String(args.tenant);
const name = String(args.name);
const origin = args.origin ? String(args.origin) : undefined;
const definition = FormDefinitionSchema.parse({
title: name,
submitLabel: "Submit",
successMessage: "Thanks — we received your submission.",
fields: [
{ key: "full_name", type: "text", label: "Full name", required: true },
{ key: "email", type: "email", label: "Email", required: true },
{ key: "message", type: "textarea", label: "Message", required: false },
{ key: HONEYPOT_FIELD_KEY, type: "honeypot", label: "Leave empty" },
],
});
const { getDbClient } = await import("@toolctrl/db/client.server");
const prisma = getDbClient();
const created = await prisma.form.create({
data: {
tenantId,
name,
definition: definition as object,
allowedOrigins: origin ? [origin] : [],
config: { honeypotEnabled: true } as object,
},
select: { id: true, key: true },
});
consola.success(`Form created: id=${created.id} key=${created.key}`);
consola.log(`Embed: <script src="<host>/embed/widget.js" data-form-key="${created.key}" async></script>`);
},
});
@@ -0,0 +1,26 @@
/**
* `forms delete --id <formId>` — hard-delete a form and cascade
* its FormSubmission rows. No soft-delete in Phase-1.
*/
import { defineCommand } from "citty";
import consola from "consola";
export const formsDeleteCommand = defineCommand({
meta: { name: "delete", description: "Delete a form (cascade submissions)." },
args: {
id: { type: "string", required: true, description: "Form ID." },
},
async run({ args }) {
const { getDbClient } = await import("@toolctrl/db/client.server");
const prisma = getDbClient();
const id = String(args.id);
const existing = await prisma.form.findUnique({ where: { id }, select: { id: true, name: true } });
if (!existing) {
consola.error(`Form ${id} not found.`);
process.exitCode = 1;
return;
}
await prisma.form.delete({ where: { id } });
consola.success(`Form deleted: ${id} (${existing.name}).`);
},
});
@@ -0,0 +1,16 @@
import { defineCommand } from "citty";
import { formsListCommand } from "./list.js";
import { formsCreateCommand } from "./create.js";
import { formsDeleteCommand } from "./delete.js";
export const formsCommand = defineCommand({
meta: {
name: "forms",
description: "Embeddable form-widget admin commands (list, create, delete).",
},
subCommands: {
list: formsListCommand,
create: formsCreateCommand,
delete: formsDeleteCommand,
},
});
@@ -0,0 +1,37 @@
/**
* `forms list --tenant <tenantId>` — print every form with submission count.
*/
import { defineCommand } from "citty";
import consola from "consola";
export const formsListCommand = defineCommand({
meta: { name: "list", description: "List forms for a tenant." },
args: {
tenant: { type: "string", required: true, description: "Tenant ID." },
},
async run({ args }) {
const { getDbClient } = await import("@toolctrl/db/client.server");
const prisma = getDbClient();
const tenantId = String(args.tenant);
const forms = await prisma.form.findMany({
where: { tenantId },
orderBy: { createdAt: "desc" },
select: {
id: true,
key: true,
name: true,
isEnabled: true,
_count: { select: { submissions: true } },
},
});
if (forms.length === 0) {
consola.info(`No forms for tenant ${tenantId}.`);
return;
}
for (const f of forms) {
const state = f.isEnabled ? "ON " : "OFF";
consola.log(`${state} ${f.id.padEnd(28)} ${f.key.padEnd(28)} subs=${f._count.submissions} ${f.name}`);
}
consola.success(`${forms.length} forms listed.`);
},
});