@backifydev/cli 0.3.22 → 0.4.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 +38 -275
- package/dist/index.js +28023 -43589
- package/package.json +50 -51
- package/templates/api/backify.config.ts +10 -0
- package/templates/api/package.json +21 -0
- package/templates/common/AGENTS.md +11 -0
- package/templates/common/Dockerfile +20 -0
- package/templates/common/_dockerignore +7 -0
- package/templates/common/_gitignore +6 -0
- package/templates/common/db/migrations/0001_items.sql +8 -0
- package/templates/common/server/index.test.ts +27 -0
- package/templates/common/server/index.ts +46 -0
- package/templates/common/tsconfig.json +15 -0
- package/templates/web/backify.config.ts +11 -0
- package/templates/web/package.json +28 -0
- package/templates/web/vite.config.ts +10 -0
- package/templates/web/web/index.html +12 -0
- package/templates/web/web/src/main.tsx +63 -0
- package/templates/web/web/tsconfig.json +13 -0
- package/templates/worker/backify.config.ts +9 -0
- package/templates/worker/package.json +21 -0
- package/templates/worker/server/index.test.ts +9 -0
- package/templates/worker/server/index.ts +8 -0
package/package.json
CHANGED
|
@@ -1,51 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@backifydev/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Command-line setup and diagnostics for Backify applications",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"bin": {
|
|
7
|
-
"backify": "dist/index.js"
|
|
8
|
-
},
|
|
9
|
-
"files": [
|
|
10
|
-
"dist/index.js",
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@backifydev/cli",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Command-line setup and diagnostics for Backify applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"backify": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/index.js",
|
|
11
|
+
"templates",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"prebuild": "npm run build -w @backify/platform && npm run build -w @backifydev/sdk && npm run build -w @backify/analyzer",
|
|
16
|
+
"build": "esbuild src/index.ts --bundle --platform=node --format=esm --external:esbuild --external:typescript --outfile=dist/index.js --banner:js=\"import { createRequire as __backifyCreateRequire } from 'node:module'; var require = __backifyCreateRequire(import.meta.url);\"",
|
|
17
|
+
"prepack": "npm run build",
|
|
18
|
+
"pretypecheck": "npm run build -w @backify/platform && npm run build -w @backifydev/sdk && npm run build -w @backify/analyzer",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"pretest": "npm run build -w @backify/platform && npm run build -w @backifydev/sdk && npm run build -w @backify/analyzer",
|
|
21
|
+
"test": "vitest run"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/frejnorling/backify.git",
|
|
29
|
+
"directory": "packages/cli"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://agent.backify.dev/",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
38
|
+
"esbuild": "^0.25.10",
|
|
39
|
+
"typescript": "^5.9.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@backify/analyzer": "*",
|
|
43
|
+
"@backify/platform": "*",
|
|
44
|
+
"@backifydev/sdk": "*",
|
|
45
|
+
"@types/node": "^24.3.1",
|
|
46
|
+
"@types/pg": "8.20.0",
|
|
47
|
+
"pg": "8.23.1",
|
|
48
|
+
"vitest": "^4.1.11"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { defineConfig } from "@backifydev/sdk/config";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
instructionVersion: 18,
|
|
5
|
+
app: { name: "{{name}}" },
|
|
6
|
+
kind: "api",
|
|
7
|
+
server: { entry: "server/index.ts" },
|
|
8
|
+
auth: { providers: ["email"] },
|
|
9
|
+
database: { migrations: "db/migrations" }
|
|
10
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "backify dev",
|
|
7
|
+
"build": "npm run build:server",
|
|
8
|
+
"build:server": "tsc -p tsconfig.json",
|
|
9
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
10
|
+
"test": "vitest run"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@backifydev/sdk": "^{{sdkVersion}}"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@backifydev/cli": "^{{cliVersion}}",
|
|
17
|
+
"@types/node": "^24.3.1",
|
|
18
|
+
"typescript": "^5.9.2",
|
|
19
|
+
"vitest": "^4.1.11"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# {{name}}
|
|
2
|
+
|
|
3
|
+
This app runs on Backify. Keep to these rules when changing it.
|
|
4
|
+
|
|
5
|
+
- **Declare, don't wire.** Routes go on `api` in `server/index.ts` (`api.get/post/...`), background work uses `defineJob`, recurring work `schedule`, reactions `on("event", job)`. Declarations must be at module top level with literal names.
|
|
6
|
+
- **Every route states who may call it.** The default is a signed-in user; use `auth: "public"`, `{ role }` or `{ permission }` deliberately. Validate input with zod (`params`, `query`, `body`).
|
|
7
|
+
- **Data:** PostgreSQL through `database()` / `transaction()`. Change the schema only with a new file in `db/migrations` (never edit an applied one). Publish events inside the transaction that writes the data.
|
|
8
|
+
- **Platform services** come from `@backifydev/sdk/app`: `storage.bucket()`, `ai`, `mail`, `http.fetch` (allowed hosts in `backify.config.ts`), `secret()`, `config()`. Never import cloud SDKs or put credentials in code or config.
|
|
9
|
+
- **Config:** `backify.config.ts` holds buckets, auth providers, secret names, allowed hosts and literal `app.id` / `instructionVersion` metadata. Use init/sync deliberately to update agent instructions. Secret values are set per environment in the portal.
|
|
10
|
+
- **Before committing:** run `npx backify check` (typecheck, lint, tests, build, lockfile). Commit `backify.lock.json`.
|
|
11
|
+
- **Local development:** `npm run dev` (`backify dev`) needs PostgreSQL 16+ and starts PostgreSQL, the worker, the backend and the frontend behind a local gateway with sign-in.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Built by Backify CI. One image runs every process role:
|
|
2
|
+
# web (default), worker, migrate, describe -> docker run <image> worker
|
|
3
|
+
FROM node:22-alpine AS build
|
|
4
|
+
WORKDIR /app
|
|
5
|
+
COPY package.json package-lock.json ./
|
|
6
|
+
RUN npm ci
|
|
7
|
+
COPY . .
|
|
8
|
+
RUN npm run build:server && npm prune --omit=dev
|
|
9
|
+
|
|
10
|
+
FROM node:22-alpine
|
|
11
|
+
WORKDIR /app
|
|
12
|
+
ENV NODE_ENV=production PORT=8080 HOST=0.0.0.0 BACKIFY_ENTRY=dist/server/index.js BACKIFY_MIGRATIONS_DIR=db/migrations
|
|
13
|
+
COPY --from=build --chown=node:node /app/package.json ./
|
|
14
|
+
COPY --from=build --chown=node:node /app/node_modules ./node_modules
|
|
15
|
+
COPY --from=build --chown=node:node /app/dist ./dist
|
|
16
|
+
COPY --from=build --chown=node:node /app/db ./db
|
|
17
|
+
USER node
|
|
18
|
+
EXPOSE 8080
|
|
19
|
+
ENTRYPOINT ["node", "--enable-source-maps", "node_modules/@backifydev/sdk/dist/app/run.js"]
|
|
20
|
+
CMD ["web"]
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
CREATE TABLE items (
|
|
2
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
3
|
+
owner_id text NOT NULL,
|
|
4
|
+
title text NOT NULL CHECK (char_length(title) BETWEEN 1 AND 200),
|
|
5
|
+
done boolean NOT NULL DEFAULT false,
|
|
6
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
7
|
+
);
|
|
8
|
+
CREATE INDEX items_owner ON items (owner_id, created_at DESC);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { beforeAll, describe, expect, it } from "vitest";
|
|
2
|
+
import { createTestIdentity, useTestEnvironment } from "@backifydev/sdk/testing";
|
|
3
|
+
import { api } from "./index.js";
|
|
4
|
+
|
|
5
|
+
let token: string;
|
|
6
|
+
|
|
7
|
+
beforeAll(async () => {
|
|
8
|
+
const identity = await createTestIdentity();
|
|
9
|
+
useTestEnvironment({ userTrust: identity.trust });
|
|
10
|
+
token = await identity.sign({ id: "user-1", email: "ada@example.com" });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe("api", () => {
|
|
14
|
+
it("requires a signed-in user", async () => {
|
|
15
|
+
const response = await api.fetch(new Request("http://app/api/items"));
|
|
16
|
+
expect(response.status).toBe(401);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("validates input before touching the database", async () => {
|
|
20
|
+
const response = await api.fetch(new Request("http://app/api/items", { method: "POST", headers: { "x-backify-user": token, "content-type": "application/json" }, body: JSON.stringify({ title: "" }) }));
|
|
21
|
+
expect(response.status).toBe(400);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("answers the health check", async () => {
|
|
25
|
+
expect((await api.fetch(new Request("http://app/healthz"))).status).toBe(200);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { database, defineBackend, defineJob, events, HttpError, log, on, schedule, transaction, z } from "@backifydev/sdk/app";
|
|
2
|
+
|
|
3
|
+
/** Every route requires a signed-in user unless it says `auth: "public"`. */
|
|
4
|
+
export const api = defineBackend({ title: "{{name}}" });
|
|
5
|
+
|
|
6
|
+
const Item = z.object({ id: z.string().uuid(), title: z.string(), done: z.boolean(), createdAt: z.string() });
|
|
7
|
+
type ItemRow = { id: string; title: string; done: boolean; created_at: Date };
|
|
8
|
+
const toItem = (row: ItemRow) => ({ id: row.id, title: row.title, done: row.done, createdAt: row.created_at.toISOString() });
|
|
9
|
+
const ItemId = z.object({ id: z.string().uuid() });
|
|
10
|
+
|
|
11
|
+
api.get("/api/items", { summary: "List my items", response: z.array(Item) }, async ({ user }) => {
|
|
12
|
+
const { rows } = await database().query<ItemRow>("SELECT id, title, done, created_at FROM items WHERE owner_id = $1 ORDER BY created_at DESC", [user.id]);
|
|
13
|
+
return rows.map(toItem);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
api.post("/api/items", { summary: "Create an item", body: z.object({ title: z.string().trim().min(1).max(200) }), response: Item, status: 201 }, ({ user, body }) =>
|
|
17
|
+
transaction(async tx => {
|
|
18
|
+
const { rows } = await tx.query<ItemRow>("INSERT INTO items (owner_id, title) VALUES ($1, $2) RETURNING id, title, done, created_at", [user.id, body.title]);
|
|
19
|
+
// Published in the same transaction: delivered only if the insert commits.
|
|
20
|
+
await events.publish("item.created", { id: rows[0].id, ownerId: user.id }, { client: tx });
|
|
21
|
+
return toItem(rows[0]);
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
api.patch("/api/items/:id", { summary: "Mark an item done or not done", params: ItemId, body: z.object({ done: z.boolean() }), response: Item }, async ({ user, params, body }) => {
|
|
25
|
+
const { rows } = await database().query<ItemRow>("UPDATE items SET done = $3 WHERE id = $1 AND owner_id = $2 RETURNING id, title, done, created_at", [params.id, user.id, body.done]);
|
|
26
|
+
if (!rows[0]) throw new HttpError(404, "Item not found", "not_found");
|
|
27
|
+
return toItem(rows[0]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
api.delete("/api/items/:id", { summary: "Delete an item", params: ItemId }, async ({ user, params }) => {
|
|
31
|
+
const result = await database().query("DELETE FROM items WHERE id = $1 AND owner_id = $2", [params.id, user.id]);
|
|
32
|
+
if (!result.rowCount) throw new HttpError(404, "Item not found", "not_found");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/** Runs in the worker for every item.created event. */
|
|
36
|
+
export const recordCreated = defineJob<{ id: string; ownerId: string }>("record-created", async item => {
|
|
37
|
+
log.info("Item created", { id: item.id });
|
|
38
|
+
});
|
|
39
|
+
on("item.created", recordCreated);
|
|
40
|
+
|
|
41
|
+
/** Deletes finished items older than 30 days, every night at 03:00 UTC. */
|
|
42
|
+
export const cleanup = defineJob("cleanup-done-items", { retries: 2 }, async () => {
|
|
43
|
+
const result = await database().query("DELETE FROM items WHERE done AND created_at < now() - interval '30 days'");
|
|
44
|
+
log.info("Cleaned up items", { deleted: result.rowCount });
|
|
45
|
+
});
|
|
46
|
+
schedule("nightly-cleanup", { cron: "0 3 * * *" }, cleanup);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"rootDir": ".",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"types": ["node"]
|
|
12
|
+
},
|
|
13
|
+
"include": ["server", "backify.config.ts"],
|
|
14
|
+
"exclude": ["**/*.test.ts"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineConfig } from "@backifydev/sdk/config";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
instructionVersion: 18,
|
|
5
|
+
app: { name: "{{name}}" },
|
|
6
|
+
kind: "web",
|
|
7
|
+
server: { entry: "server/index.ts" },
|
|
8
|
+
frontend: { output: "web/dist" },
|
|
9
|
+
auth: { providers: ["email"] },
|
|
10
|
+
database: { migrations: "db/migrations" }
|
|
11
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "backify dev",
|
|
7
|
+
"dev:web": "vite",
|
|
8
|
+
"build": "npm run build:server && vite build",
|
|
9
|
+
"build:server": "tsc -p tsconfig.json",
|
|
10
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p web/tsconfig.json --noEmit",
|
|
11
|
+
"test": "vitest run"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@backifydev/sdk": "^{{sdkVersion}}"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@backifydev/cli": "^{{cliVersion}}",
|
|
18
|
+
"@types/node": "^24.3.1",
|
|
19
|
+
"@types/react": "^19.1.12",
|
|
20
|
+
"@types/react-dom": "^19.1.9",
|
|
21
|
+
"@vitejs/plugin-react": "^5.0.2",
|
|
22
|
+
"react": "^19.1.1",
|
|
23
|
+
"react-dom": "^19.1.1",
|
|
24
|
+
"typescript": "^5.9.2",
|
|
25
|
+
"vite": "^7.1.5",
|
|
26
|
+
"vitest": "^4.1.11"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import react from "@vitejs/plugin-react";
|
|
2
|
+
import { defineConfig } from "vite";
|
|
3
|
+
|
|
4
|
+
// `backify dev` serves this app behind a local gateway that also routes /api and sign-in,
|
|
5
|
+
// exactly like production, so no proxy is configured here.
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
root: "web",
|
|
8
|
+
plugins: [react()],
|
|
9
|
+
build: { outDir: "dist", emptyOutDir: true }
|
|
10
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>{{name}}</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { StrictMode, useEffect, useState, type FormEvent } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
|
|
4
|
+
type User = { id: string; email?: string; name?: string };
|
|
5
|
+
type Item = { id: string; title: string; done: boolean; createdAt: string };
|
|
6
|
+
|
|
7
|
+
async function api<T>(path: string, init?: RequestInit): Promise<T> {
|
|
8
|
+
const response = await fetch(path, { ...init, headers: { "content-type": "application/json", ...init?.headers } });
|
|
9
|
+
if (response.status === 401) { location.href = "/.backify/auth/login?returnTo=" + encodeURIComponent(location.pathname); throw new Error("Signing in"); }
|
|
10
|
+
if (!response.ok) throw new Error(((await response.json().catch(() => ({}))) as { error?: { message?: string } }).error?.message ?? response.statusText);
|
|
11
|
+
return (response.status === 204 ? undefined : await response.json()) as T;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function App() {
|
|
15
|
+
const [user, setUser] = useState<User | null>();
|
|
16
|
+
const [items, setItems] = useState<Item[]>([]);
|
|
17
|
+
const [title, setTitle] = useState("");
|
|
18
|
+
const [error, setError] = useState<string>();
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
fetch("/.backify/auth/me").then(r => r.ok ? r.json() as Promise<User> : null).then(setUser, () => setUser(null));
|
|
22
|
+
}, []);
|
|
23
|
+
useEffect(() => { if (user) api<Item[]>("/api/items").then(setItems, e => setError(String(e.message))); }, [user]);
|
|
24
|
+
|
|
25
|
+
async function add(event: FormEvent) {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
try {
|
|
28
|
+
const item = await api<Item>("/api/items", { method: "POST", body: JSON.stringify({ title }) });
|
|
29
|
+
setItems([item, ...items]);
|
|
30
|
+
setTitle("");
|
|
31
|
+
} catch (e) { setError((e as Error).message); }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function toggle(item: Item) {
|
|
35
|
+
const updated = await api<Item>(`/api/items/${item.id}`, { method: "PATCH", body: JSON.stringify({ done: !item.done }) });
|
|
36
|
+
setItems(items.map(i => i.id === item.id ? updated : i));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (user === undefined) return null;
|
|
40
|
+
if (user === null) return <main><h1>{"{{name}}"}</h1><a href="/.backify/auth/login?returnTo=/">Sign in</a></main>;
|
|
41
|
+
return (
|
|
42
|
+
<main style={{ maxWidth: 560, margin: "3rem auto", fontFamily: "system-ui" }}>
|
|
43
|
+
<header style={{ display: "flex", justifyContent: "space-between" }}>
|
|
44
|
+
<h1>{"{{name}}"}</h1>
|
|
45
|
+
<span>{user.email ?? user.id} · <a href="/.backify/auth/signout">Sign out</a></span>
|
|
46
|
+
</header>
|
|
47
|
+
<form onSubmit={add} style={{ display: "flex", gap: 8 }}>
|
|
48
|
+
<input value={title} onChange={e => setTitle(e.target.value)} placeholder="New item" aria-label="New item" style={{ flex: 1 }} />
|
|
49
|
+
<button disabled={!title.trim()}>Add</button>
|
|
50
|
+
</form>
|
|
51
|
+
{error && <p role="alert">{error}</p>}
|
|
52
|
+
<ul>
|
|
53
|
+
{items.map(item => (
|
|
54
|
+
<li key={item.id}>
|
|
55
|
+
<label><input type="checkbox" checked={item.done} onChange={() => toggle(item)} /> {item.title}</label>
|
|
56
|
+
</li>
|
|
57
|
+
))}
|
|
58
|
+
</ul>
|
|
59
|
+
</main>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
createRoot(document.getElementById("root")!).render(<StrictMode><App /></StrictMode>);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{name}}",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "backify dev",
|
|
7
|
+
"build": "npm run build:server",
|
|
8
|
+
"build:server": "tsc -p tsconfig.json",
|
|
9
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
10
|
+
"test": "vitest run"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@backifydev/sdk": "^{{sdkVersion}}"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@backifydev/cli": "^{{cliVersion}}",
|
|
17
|
+
"@types/node": "^24.3.1",
|
|
18
|
+
"typescript": "^5.9.2",
|
|
19
|
+
"vitest": "^4.1.11"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { declarationRegistry } from "@backifydev/sdk/testing";
|
|
3
|
+
import "./index.js";
|
|
4
|
+
|
|
5
|
+
describe("worker", () => {
|
|
6
|
+
it("declares the daily summary schedule", () => {
|
|
7
|
+
expect(declarationRegistry.schedules.get("daily-summary")).toMatchObject({ cron: "0 6 * * *", job: "daily-summary" });
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { database, defineJob, log, schedule } from "@backifydev/sdk/app";
|
|
2
|
+
|
|
3
|
+
/** Summarises yesterday's items every morning at 06:00 Stockholm time. */
|
|
4
|
+
export const dailySummary = defineJob("daily-summary", { retries: 3, timeoutSeconds: 600 }, async (_payload, context) => {
|
|
5
|
+
const { rows } = await database().query<{ total: string }>("SELECT count(*) AS total FROM items WHERE created_at >= now() - interval '1 day'");
|
|
6
|
+
log.info("Daily summary", { runId: context.runId, items: Number(rows[0].total) });
|
|
7
|
+
});
|
|
8
|
+
schedule("daily-summary", { cron: "0 6 * * *", timezone: "Europe/Stockholm" }, dailySummary);
|