create-donghanh 0.1.0 → 0.2.1
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/{src/index.ts → dist/index.js} +19 -49
- package/package.json +6 -3
- package/templates/kanban-gpt/README.md +45 -0
- package/templates/kanban-gpt/auth.ts +28 -0
- package/templates/kanban-gpt/db/index.ts +16 -0
- package/templates/kanban-gpt/db/queries.ts +119 -0
- package/templates/kanban-gpt/db/schema.ts +52 -0
- package/templates/kanban-gpt/drizzle.config.ts +10 -0
- package/templates/kanban-gpt/env.ts +18 -0
- package/templates/kanban-gpt/executor.ts +24 -0
- package/templates/kanban-gpt/oauth/authorize.ts +24 -0
- package/templates/kanban-gpt/oauth/code.ts +28 -0
- package/templates/kanban-gpt/oauth/token.ts +79 -0
- package/templates/{trello → kanban-gpt}/package.json +8 -4
- package/templates/kanban-gpt/worker.ts +61 -0
- package/templates/kanban-gpt/wrangler.toml +16 -0
- package/templates/minimal/README.md +26 -0
- package/templates/trello/db.ts +0 -78
- package/templates/trello/executor.ts +0 -19
- package/templates/trello/schema.sql +0 -30
- package/templates/trello/worker.ts +0 -36
- package/templates/trello/wrangler.toml +0 -9
- /package/templates/{trello → kanban-gpt}/biome.json +0 -0
- /package/templates/{trello → kanban-gpt}/operations/add-card.tsx +0 -0
- /package/templates/{trello → kanban-gpt}/operations/add-member.tsx +0 -0
- /package/templates/{trello → kanban-gpt}/operations/board-detail.tsx +0 -0
- /package/templates/{trello → kanban-gpt}/operations/create-board.tsx +0 -0
- /package/templates/{trello → kanban-gpt}/operations/index.ts +0 -0
- /package/templates/{trello → kanban-gpt}/operations/list-boards.tsx +0 -0
- /package/templates/{trello → kanban-gpt}/operations/move-card.tsx +0 -0
- /package/templates/{trello → kanban-gpt}/tsconfig.json +0 -0
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
2
4
|
import fs from "node:fs";
|
|
3
5
|
import path from "node:path";
|
|
4
6
|
import readline from "node:readline";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type Template = (typeof TEMPLATES)[number];
|
|
8
|
-
|
|
9
|
-
const DESCRIPTIONS: Record<Template, string> = {
|
|
7
|
+
var TEMPLATES = ["minimal", "kanban-gpt"];
|
|
8
|
+
var DESCRIPTIONS = {
|
|
10
9
|
minimal: "Hello world with D1 SQLite — 2 operations",
|
|
11
|
-
|
|
10
|
+
"kanban-gpt": "Kanban board with Better Auth + Drizzle + GPT Store OAuth — 6 operations"
|
|
12
11
|
};
|
|
13
|
-
|
|
14
|
-
async function prompt(question: string): Promise<string> {
|
|
12
|
+
async function prompt(question) {
|
|
15
13
|
const rl = readline.createInterface({
|
|
16
14
|
input: process.stdin,
|
|
17
|
-
output: process.stdout
|
|
15
|
+
output: process.stdout
|
|
18
16
|
});
|
|
19
17
|
return new Promise((resolve) => {
|
|
20
18
|
rl.question(question, (answer) => {
|
|
@@ -23,8 +21,7 @@ async function prompt(question: string): Promise<string> {
|
|
|
23
21
|
});
|
|
24
22
|
});
|
|
25
23
|
}
|
|
26
|
-
|
|
27
|
-
function copyDir(src: string, dest: string, replacements: [string, string][]) {
|
|
24
|
+
function copyDir(src, dest, replacements) {
|
|
28
25
|
fs.mkdirSync(dest, { recursive: true });
|
|
29
26
|
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
30
27
|
const srcPath = path.join(src, entry.name);
|
|
@@ -40,29 +37,22 @@ function copyDir(src: string, dest: string, replacements: [string, string][]) {
|
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
|
-
|
|
44
40
|
async function main() {
|
|
45
41
|
const args = process.argv.slice(2);
|
|
46
42
|
let target = args[0];
|
|
47
|
-
let template
|
|
48
|
-
|
|
49
|
-
// Parse --template / -t flag
|
|
43
|
+
let template;
|
|
50
44
|
const tIdx = args.indexOf("--template");
|
|
51
45
|
const tShortIdx = args.indexOf("-t");
|
|
52
46
|
const flagIdx = tIdx !== -1 ? tIdx : tShortIdx;
|
|
53
47
|
if (flagIdx !== -1 && args[flagIdx + 1]) {
|
|
54
|
-
template = args[flagIdx + 1]
|
|
55
|
-
// Remove flag and value from args
|
|
48
|
+
template = args[flagIdx + 1];
|
|
56
49
|
if (!target || target.startsWith("-")) {
|
|
57
50
|
target = undefined;
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
|
-
|
|
61
53
|
console.log();
|
|
62
|
-
console.log(" \
|
|
54
|
+
console.log(" \x1B[1m@donghanh\x1B[0m — Conversational UI Framework");
|
|
63
55
|
console.log();
|
|
64
|
-
|
|
65
|
-
// Prompt for target if not given
|
|
66
56
|
if (!target || target.startsWith("-")) {
|
|
67
57
|
target = await prompt(" Project name: ");
|
|
68
58
|
if (!target) {
|
|
@@ -70,56 +60,37 @@ async function main() {
|
|
|
70
60
|
process.exit(0);
|
|
71
61
|
}
|
|
72
62
|
}
|
|
73
|
-
|
|
74
|
-
// Prompt for template if not given
|
|
75
63
|
if (!template || !TEMPLATES.includes(template)) {
|
|
76
64
|
console.log();
|
|
77
65
|
console.log(" Templates:");
|
|
78
|
-
for (let i = 0;
|
|
79
|
-
console.log(
|
|
80
|
-
` \x1b[1m${i + 1}\x1b[0m) ${TEMPLATES[i]} — ${DESCRIPTIONS[TEMPLATES[i]]}`,
|
|
81
|
-
);
|
|
66
|
+
for (let i = 0;i < TEMPLATES.length; i++) {
|
|
67
|
+
console.log(` \x1B[1m${i + 1}\x1B[0m) ${TEMPLATES[i]} — ${DESCRIPTIONS[TEMPLATES[i]]}`);
|
|
82
68
|
}
|
|
83
69
|
console.log();
|
|
84
70
|
const choice = await prompt(" Select template (1-2): ");
|
|
85
71
|
const idx = Number.parseInt(choice, 10) - 1;
|
|
86
72
|
template = TEMPLATES[idx] ?? "minimal";
|
|
87
73
|
}
|
|
88
|
-
|
|
89
74
|
const destDir = path.resolve(target);
|
|
90
75
|
if (fs.existsSync(destDir)) {
|
|
91
|
-
console.log(
|
|
92
|
-
` \x1b[31mError:\x1b[0m Directory "${target}" already exists.`,
|
|
93
|
-
);
|
|
76
|
+
console.log(` \x1B[31mError:\x1B[0m Directory "${target}" already exists.`);
|
|
94
77
|
process.exit(1);
|
|
95
78
|
}
|
|
96
|
-
|
|
97
|
-
// Find templates directory
|
|
98
|
-
const templatesDir = path.join(
|
|
99
|
-
path.dirname(new URL(import.meta.url).pathname),
|
|
100
|
-
"..",
|
|
101
|
-
"templates",
|
|
102
|
-
);
|
|
79
|
+
const templatesDir = path.join(path.dirname(new URL(import.meta.url).pathname), "..", "templates");
|
|
103
80
|
const srcDir = path.join(templatesDir, template);
|
|
104
|
-
|
|
105
81
|
if (!fs.existsSync(srcDir)) {
|
|
106
|
-
console.log(` \
|
|
82
|
+
console.log(` \x1B[31mError:\x1B[0m Template "${template}" not found.`);
|
|
107
83
|
process.exit(1);
|
|
108
84
|
}
|
|
109
|
-
|
|
110
|
-
// Copy template with name replacement
|
|
111
85
|
const appName = path.basename(target);
|
|
112
86
|
copyDir(srcDir, destDir, [
|
|
113
87
|
["my-donghanh-app", appName],
|
|
114
|
-
["my-
|
|
88
|
+
["my-kanban-app", appName],
|
|
115
89
|
["my-donghanh-app-db", `${appName}-db`],
|
|
116
|
-
["my-
|
|
90
|
+
["my-kanban-db", `${appName}-db`]
|
|
117
91
|
]);
|
|
118
|
-
|
|
119
92
|
console.log();
|
|
120
|
-
console.log(
|
|
121
|
-
` \x1b[32m✓\x1b[0m Created \x1b[1m${appName}\x1b[0m from \x1b[1m${template}\x1b[0m template`,
|
|
122
|
-
);
|
|
93
|
+
console.log(` \x1B[32m✓\x1B[0m Created \x1B[1m${appName}\x1B[0m from \x1B[1m${template}\x1B[0m template`);
|
|
123
94
|
console.log();
|
|
124
95
|
console.log(" Next steps:");
|
|
125
96
|
console.log(` cd ${target}`);
|
|
@@ -128,5 +99,4 @@ async function main() {
|
|
|
128
99
|
console.log(" bun run dev # start dev server");
|
|
129
100
|
console.log();
|
|
130
101
|
}
|
|
131
|
-
|
|
132
102
|
main().catch(console.error);
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-donghanh",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Scaffold a donghanh project — conversational UI with JSX",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"create-donghanh": "
|
|
8
|
+
"create-donghanh": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "bun build src/index.ts --outdir dist --target node"
|
|
9
12
|
},
|
|
10
13
|
"files": [
|
|
11
|
-
"
|
|
14
|
+
"dist",
|
|
12
15
|
"templates"
|
|
13
16
|
],
|
|
14
17
|
"repository": {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Kanban GPT
|
|
2
|
+
|
|
3
|
+
A kanban board powered by [@donghanh](https://github.com/rezzahub/donghanh) with GPT Store integration.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
npx wrangler d1 create my-kanban-db
|
|
10
|
+
# Copy the database_id into wrangler.toml
|
|
11
|
+
npx drizzle-kit push
|
|
12
|
+
npx wrangler secret put BETTER_AUTH_SECRET
|
|
13
|
+
bun run dev
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Operations
|
|
17
|
+
|
|
18
|
+
| Operation | Type | Description |
|
|
19
|
+
|-----------|------|-------------|
|
|
20
|
+
| `list-boards` | query | List all boards |
|
|
21
|
+
| `board-detail` | query | Board with columns, cards, members |
|
|
22
|
+
| `create-board` | mutation | Create board with default columns |
|
|
23
|
+
| `add-card` | mutation | Add card to a column |
|
|
24
|
+
| `move-card` | mutation | Move card between columns |
|
|
25
|
+
| `add-member` | mutation | Add member to board |
|
|
26
|
+
|
|
27
|
+
## GPT Store Setup
|
|
28
|
+
|
|
29
|
+
1. Create a GPT Action in the [ChatGPT GPT Store editor](https://chatgpt.com/gpts/editor)
|
|
30
|
+
2. Set the API server URL to your deployed worker URL
|
|
31
|
+
3. Configure OAuth:
|
|
32
|
+
- Authorization URL: `https://your-worker.dev/oauth/authorize`
|
|
33
|
+
- Token URL: `https://your-worker.dev/oauth/token`
|
|
34
|
+
- Set client_id and client_secret
|
|
35
|
+
4. Add secrets to your worker:
|
|
36
|
+
```bash
|
|
37
|
+
npx wrangler secret put GPT_OAUTH_CLIENT_ID
|
|
38
|
+
npx wrangler secret put GPT_OAUTH_CLIENT_SECRET
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Deploy
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx wrangler deploy
|
|
45
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { betterAuth } from "better-auth";
|
|
2
|
+
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
3
|
+
import { bearer } from "better-auth/plugins";
|
|
4
|
+
import { db } from "./db";
|
|
5
|
+
import { getEnv } from "./env";
|
|
6
|
+
|
|
7
|
+
function createAuth() {
|
|
8
|
+
const env = getEnv();
|
|
9
|
+
return betterAuth({
|
|
10
|
+
database: drizzleAdapter(db, { provider: "sqlite", usePlural: true }),
|
|
11
|
+
plugins: [bearer()],
|
|
12
|
+
emailAndPassword: {
|
|
13
|
+
enabled: true,
|
|
14
|
+
requireEmailVerification: false,
|
|
15
|
+
},
|
|
16
|
+
secret: env.BETTER_AUTH_SECRET,
|
|
17
|
+
baseURL: env.BETTER_AUTH_URL,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let _auth: ReturnType<typeof createAuth> | null = null;
|
|
22
|
+
|
|
23
|
+
export const auth = new Proxy({} as ReturnType<typeof createAuth>, {
|
|
24
|
+
get(_, prop) {
|
|
25
|
+
if (!_auth) _auth = createAuth();
|
|
26
|
+
return (_auth as unknown as Record<string | symbol, unknown>)[prop];
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { drizzle } from "drizzle-orm/d1";
|
|
2
|
+
import { getEnv } from "../env";
|
|
3
|
+
import * as schema from "./schema";
|
|
4
|
+
|
|
5
|
+
let _db: ReturnType<typeof createDb> | null = null;
|
|
6
|
+
|
|
7
|
+
function createDb() {
|
|
8
|
+
return drizzle(getEnv().DB, { schema });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const db = new Proxy({} as ReturnType<typeof createDb>, {
|
|
12
|
+
get(_, prop) {
|
|
13
|
+
if (!_db) _db = createDb();
|
|
14
|
+
return (_db as unknown as Record<string | symbol, unknown>)[prop];
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { eq, sql } from "drizzle-orm";
|
|
2
|
+
import { db } from ".";
|
|
3
|
+
import { boards, cards, columns, members } from "./schema";
|
|
4
|
+
|
|
5
|
+
function uid() {
|
|
6
|
+
return crypto.randomUUID().slice(0, 8);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function listBoards(userId: string) {
|
|
10
|
+
const rows = await db
|
|
11
|
+
.select({
|
|
12
|
+
id: boards.id,
|
|
13
|
+
name: boards.name,
|
|
14
|
+
createdAt: boards.createdAt,
|
|
15
|
+
cardCount: sql<number>`(SELECT COUNT(*) FROM cards WHERE cards.board_id = boards.id)`,
|
|
16
|
+
memberCount: sql<number>`(SELECT COUNT(*) FROM members WHERE members.board_id = boards.id)`,
|
|
17
|
+
})
|
|
18
|
+
.from(boards)
|
|
19
|
+
.innerJoin(members, eq(members.boardId, boards.id))
|
|
20
|
+
.where(eq(members.userId, userId))
|
|
21
|
+
.groupBy(boards.id);
|
|
22
|
+
return { boards: rows };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function boardDetail(boardId: string) {
|
|
26
|
+
const board = await db
|
|
27
|
+
.select()
|
|
28
|
+
.from(boards)
|
|
29
|
+
.where(eq(boards.id, boardId))
|
|
30
|
+
.get();
|
|
31
|
+
if (!board) throw new Error("Board not found");
|
|
32
|
+
|
|
33
|
+
const cols = await db
|
|
34
|
+
.select()
|
|
35
|
+
.from(columns)
|
|
36
|
+
.where(eq(columns.boardId, boardId))
|
|
37
|
+
.orderBy(columns.position);
|
|
38
|
+
|
|
39
|
+
const allCards = await db
|
|
40
|
+
.select()
|
|
41
|
+
.from(cards)
|
|
42
|
+
.where(eq(cards.boardId, boardId))
|
|
43
|
+
.orderBy(cards.position);
|
|
44
|
+
|
|
45
|
+
const mems = await db
|
|
46
|
+
.select()
|
|
47
|
+
.from(members)
|
|
48
|
+
.where(eq(members.boardId, boardId));
|
|
49
|
+
|
|
50
|
+
const columnData = cols.map((col) => ({
|
|
51
|
+
...col,
|
|
52
|
+
cards: allCards.filter((c) => c.columnId === col.id),
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
return { board, columns: columnData, members: mems };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function createBoard(name: string, userId: string) {
|
|
59
|
+
const id = uid();
|
|
60
|
+
await db.insert(boards).values({ id, name, createdBy: userId });
|
|
61
|
+
|
|
62
|
+
const defaultCols = ["To Do", "In Progress", "Done"];
|
|
63
|
+
for (let i = 0; i < defaultCols.length; i++) {
|
|
64
|
+
await db
|
|
65
|
+
.insert(columns)
|
|
66
|
+
.values({ id: uid(), boardId: id, name: defaultCols[i], position: i });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
await db
|
|
70
|
+
.insert(members)
|
|
71
|
+
.values({ id: uid(), boardId: id, name: "You", userId });
|
|
72
|
+
|
|
73
|
+
return boardDetail(id);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function addCard(
|
|
77
|
+
boardId: string,
|
|
78
|
+
columnId: string,
|
|
79
|
+
title: string,
|
|
80
|
+
) {
|
|
81
|
+
const id = uid();
|
|
82
|
+
const count = await db
|
|
83
|
+
.select({ c: sql<number>`COUNT(*)` })
|
|
84
|
+
.from(cards)
|
|
85
|
+
.where(eq(cards.columnId, columnId))
|
|
86
|
+
.get();
|
|
87
|
+
await db
|
|
88
|
+
.insert(cards)
|
|
89
|
+
.values({ id, columnId, boardId, title, position: count?.c ?? 0 });
|
|
90
|
+
return boardDetail(boardId);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function moveCard(cardId: string, toColumnId: string) {
|
|
94
|
+
const card = await db
|
|
95
|
+
.select()
|
|
96
|
+
.from(cards)
|
|
97
|
+
.where(eq(cards.id, cardId))
|
|
98
|
+
.get();
|
|
99
|
+
if (!card) throw new Error("Card not found");
|
|
100
|
+
|
|
101
|
+
const count = await db
|
|
102
|
+
.select({ c: sql<number>`COUNT(*)` })
|
|
103
|
+
.from(cards)
|
|
104
|
+
.where(eq(cards.columnId, toColumnId))
|
|
105
|
+
.get();
|
|
106
|
+
|
|
107
|
+
await db
|
|
108
|
+
.update(cards)
|
|
109
|
+
.set({ columnId: toColumnId, position: count?.c ?? 0 })
|
|
110
|
+
.where(eq(cards.id, cardId));
|
|
111
|
+
|
|
112
|
+
return boardDetail(card.boardId);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function addMember(boardId: string, name: string) {
|
|
116
|
+
const id = uid();
|
|
117
|
+
await db.insert(members).values({ id, boardId, name });
|
|
118
|
+
return boardDetail(boardId);
|
|
119
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
|
2
|
+
|
|
3
|
+
// ── App tables ──
|
|
4
|
+
|
|
5
|
+
export const boards = sqliteTable("boards", {
|
|
6
|
+
id: text("id").primaryKey(),
|
|
7
|
+
name: text("name").notNull(),
|
|
8
|
+
createdBy: text("created_by").notNull(),
|
|
9
|
+
createdAt: text("created_at").default("(datetime('now'))"),
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const columns = sqliteTable("columns", {
|
|
13
|
+
id: text("id").primaryKey(),
|
|
14
|
+
boardId: text("board_id")
|
|
15
|
+
.notNull()
|
|
16
|
+
.references(() => boards.id),
|
|
17
|
+
name: text("name").notNull(),
|
|
18
|
+
position: integer("position").notNull().default(0),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const cards = sqliteTable("cards", {
|
|
22
|
+
id: text("id").primaryKey(),
|
|
23
|
+
columnId: text("column_id")
|
|
24
|
+
.notNull()
|
|
25
|
+
.references(() => columns.id),
|
|
26
|
+
boardId: text("board_id")
|
|
27
|
+
.notNull()
|
|
28
|
+
.references(() => boards.id),
|
|
29
|
+
title: text("title").notNull(),
|
|
30
|
+
position: integer("position").notNull().default(0),
|
|
31
|
+
createdAt: text("created_at").default("(datetime('now'))"),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const members = sqliteTable("members", {
|
|
35
|
+
id: text("id").primaryKey(),
|
|
36
|
+
boardId: text("board_id")
|
|
37
|
+
.notNull()
|
|
38
|
+
.references(() => boards.id),
|
|
39
|
+
name: text("name").notNull(),
|
|
40
|
+
userId: text("user_id"),
|
|
41
|
+
addedAt: text("added_at").default("(datetime('now'))"),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// ── OAuth codes ──
|
|
45
|
+
|
|
46
|
+
export const oauthCodes = sqliteTable("oauth_codes", {
|
|
47
|
+
code: text("code").primaryKey(),
|
|
48
|
+
userId: text("user_id").notNull(),
|
|
49
|
+
sessionToken: text("session_token").notNull(),
|
|
50
|
+
redirectUri: text("redirect_uri").notNull(),
|
|
51
|
+
expiresAt: integer("expires_at").notNull(),
|
|
52
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface Env {
|
|
2
|
+
DB: D1Database;
|
|
3
|
+
BETTER_AUTH_SECRET: string;
|
|
4
|
+
BETTER_AUTH_URL: string;
|
|
5
|
+
GPT_OAUTH_CLIENT_ID?: string;
|
|
6
|
+
GPT_OAUTH_CLIENT_SECRET?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let _env: Env | null = null;
|
|
10
|
+
|
|
11
|
+
export function setEnv(env: Env) {
|
|
12
|
+
_env = env;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getEnv(): Env {
|
|
16
|
+
if (_env) return _env;
|
|
17
|
+
return process.env as unknown as Env;
|
|
18
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Executor } from "@donghanh/core";
|
|
2
|
+
import * as queries from "./db/queries";
|
|
3
|
+
|
|
4
|
+
export const executor: Executor = async (operationId, variables, context) => {
|
|
5
|
+
const v = variables as Record<string, string>;
|
|
6
|
+
const userId = context.userId;
|
|
7
|
+
|
|
8
|
+
switch (operationId) {
|
|
9
|
+
case "list-boards":
|
|
10
|
+
return queries.listBoards(userId);
|
|
11
|
+
case "board-detail":
|
|
12
|
+
return queries.boardDetail(v.boardId);
|
|
13
|
+
case "create-board":
|
|
14
|
+
return queries.createBoard(v.name, userId);
|
|
15
|
+
case "add-card":
|
|
16
|
+
return queries.addCard(v.boardId, v.columnId, v.title);
|
|
17
|
+
case "move-card":
|
|
18
|
+
return queries.moveCard(v.cardId, v.toColumnId);
|
|
19
|
+
case "add-member":
|
|
20
|
+
return queries.addMember(v.boardId, v.name);
|
|
21
|
+
default:
|
|
22
|
+
throw new Error(`Unknown operation: ${operationId}`);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Context } from "hono";
|
|
2
|
+
import { getEnv } from "../env";
|
|
3
|
+
|
|
4
|
+
export function oauthAuthorize(c: Context) {
|
|
5
|
+
const url = new URL(c.req.url);
|
|
6
|
+
const redirectUri = url.searchParams.get("redirect_uri");
|
|
7
|
+
const state = url.searchParams.get("state");
|
|
8
|
+
const clientId = url.searchParams.get("client_id");
|
|
9
|
+
const responseType = url.searchParams.get("response_type");
|
|
10
|
+
|
|
11
|
+
if (responseType !== "code") return c.text("Unsupported response_type", 400);
|
|
12
|
+
if (!redirectUri || !state) return c.text("Missing required parameters", 400);
|
|
13
|
+
|
|
14
|
+
const env = getEnv();
|
|
15
|
+
if (env.GPT_OAUTH_CLIENT_ID && clientId !== env.GPT_OAUTH_CLIENT_ID) {
|
|
16
|
+
return c.text("Invalid client_id", 403);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// TODO: replace with your login page URL
|
|
20
|
+
const loginUrl = new URL("/login", c.req.url);
|
|
21
|
+
loginUrl.searchParams.set("redirect_uri", redirectUri);
|
|
22
|
+
loginUrl.searchParams.set("state", state);
|
|
23
|
+
return c.redirect(loginUrl.toString());
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Context } from "hono";
|
|
2
|
+
import { auth } from "../auth";
|
|
3
|
+
import { db } from "../db";
|
|
4
|
+
import { oauthCodes } from "../db/schema";
|
|
5
|
+
|
|
6
|
+
export async function oauthCode(c: Context) {
|
|
7
|
+
const session = await auth.api.getSession({ headers: c.req.raw.headers });
|
|
8
|
+
if (!session) return c.json({ error: "Not authenticated" }, 401);
|
|
9
|
+
|
|
10
|
+
const { redirect_uri, state } = await c.req.json();
|
|
11
|
+
if (!redirect_uri || !state) {
|
|
12
|
+
return c.json({ error: "Missing redirect_uri or state" }, 400);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const code = crypto.randomUUID();
|
|
16
|
+
await db.insert(oauthCodes).values({
|
|
17
|
+
code,
|
|
18
|
+
userId: session.user.id,
|
|
19
|
+
sessionToken: session.session.token,
|
|
20
|
+
redirectUri: redirect_uri,
|
|
21
|
+
expiresAt: Date.now() + 5 * 60 * 1000, // 5 minutes
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const url = new URL(redirect_uri);
|
|
25
|
+
url.searchParams.set("code", code);
|
|
26
|
+
url.searchParams.set("state", state);
|
|
27
|
+
return c.json({ url: url.toString() });
|
|
28
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { and, eq, gt } from "drizzle-orm";
|
|
2
|
+
import type { Context } from "hono";
|
|
3
|
+
import { db } from "../db";
|
|
4
|
+
import { oauthCodes } from "../db/schema";
|
|
5
|
+
import { getEnv } from "../env";
|
|
6
|
+
|
|
7
|
+
export async function oauthToken(c: Context) {
|
|
8
|
+
const contentType = c.req.header("content-type") || "";
|
|
9
|
+
let body: Record<string, string>;
|
|
10
|
+
if (contentType.includes("application/x-www-form-urlencoded")) {
|
|
11
|
+
body = Object.fromEntries(new URLSearchParams(await c.req.text()));
|
|
12
|
+
} else {
|
|
13
|
+
body = await c.req.json();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { client_id, client_secret, grant_type } = body;
|
|
17
|
+
const env = getEnv();
|
|
18
|
+
|
|
19
|
+
if (
|
|
20
|
+
(env.GPT_OAUTH_CLIENT_ID && client_id !== env.GPT_OAUTH_CLIENT_ID) ||
|
|
21
|
+
(env.GPT_OAUTH_CLIENT_SECRET &&
|
|
22
|
+
client_secret !== env.GPT_OAUTH_CLIENT_SECRET)
|
|
23
|
+
) {
|
|
24
|
+
return c.json({ error: "invalid_client" }, 403);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (grant_type === "authorization_code") {
|
|
28
|
+
const { code, redirect_uri } = body;
|
|
29
|
+
const result = await db
|
|
30
|
+
.select()
|
|
31
|
+
.from(oauthCodes)
|
|
32
|
+
.where(
|
|
33
|
+
and(
|
|
34
|
+
eq(oauthCodes.code, code),
|
|
35
|
+
eq(oauthCodes.redirectUri, redirect_uri),
|
|
36
|
+
gt(oauthCodes.expiresAt, Date.now()),
|
|
37
|
+
),
|
|
38
|
+
)
|
|
39
|
+
.get();
|
|
40
|
+
|
|
41
|
+
if (!result) {
|
|
42
|
+
return c.json(
|
|
43
|
+
{
|
|
44
|
+
error: "invalid_grant",
|
|
45
|
+
error_description: "Code is invalid or expired",
|
|
46
|
+
},
|
|
47
|
+
400,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Delete used code
|
|
52
|
+
await db.delete(oauthCodes).where(eq(oauthCodes.code, code));
|
|
53
|
+
|
|
54
|
+
return c.json({
|
|
55
|
+
access_token: result.sessionToken,
|
|
56
|
+
token_type: "bearer",
|
|
57
|
+
refresh_token: result.sessionToken,
|
|
58
|
+
expires_in: 3600,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (grant_type === "refresh_token") {
|
|
63
|
+
const { refresh_token } = body;
|
|
64
|
+
if (!refresh_token) {
|
|
65
|
+
return c.json(
|
|
66
|
+
{ error: "invalid_grant", error_description: "Missing refresh_token" },
|
|
67
|
+
400,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return c.json({
|
|
71
|
+
access_token: refresh_token,
|
|
72
|
+
token_type: "bearer",
|
|
73
|
+
refresh_token,
|
|
74
|
+
expires_in: 3600,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return c.json({ error: "unsupported_grant_type" }, 400);
|
|
79
|
+
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "my-
|
|
2
|
+
"name": "my-kanban-app",
|
|
3
3
|
"version": "0.1.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "wrangler dev",
|
|
8
8
|
"deploy": "wrangler deploy",
|
|
9
|
-
"db:
|
|
9
|
+
"db:push": "drizzle-kit push",
|
|
10
|
+
"db:generate": "drizzle-kit generate"
|
|
10
11
|
},
|
|
11
12
|
"dependencies": {
|
|
12
|
-
"@donghanh/core": "^0.1.
|
|
13
|
-
"@donghanh/hono": "^0.1.
|
|
13
|
+
"@donghanh/core": "^0.1.1",
|
|
14
|
+
"@donghanh/hono": "^0.1.1",
|
|
15
|
+
"better-auth": "^1.4.0",
|
|
16
|
+
"drizzle-orm": "^0.45.0",
|
|
14
17
|
"hono": "^4.7.0"
|
|
15
18
|
},
|
|
16
19
|
"devDependencies": {
|
|
20
|
+
"drizzle-kit": "^0.31.0",
|
|
17
21
|
"wrangler": "^4.0.0",
|
|
18
22
|
"typescript": "^5.8.0"
|
|
19
23
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { App, buildRegistry } from "@donghanh/core";
|
|
2
|
+
import { gptRoutes } from "@donghanh/hono";
|
|
3
|
+
import { Hono } from "hono";
|
|
4
|
+
import { auth } from "./auth";
|
|
5
|
+
import { type Env, setEnv } from "./env";
|
|
6
|
+
import { executor } from "./executor";
|
|
7
|
+
import { oauthAuthorize } from "./oauth/authorize";
|
|
8
|
+
import { oauthCode } from "./oauth/code";
|
|
9
|
+
import { oauthToken } from "./oauth/token";
|
|
10
|
+
import { operations } from "./operations";
|
|
11
|
+
|
|
12
|
+
const appNode = App({ operations });
|
|
13
|
+
const registry = buildRegistry(appNode);
|
|
14
|
+
|
|
15
|
+
const app = new Hono<{ Bindings: Env }>();
|
|
16
|
+
|
|
17
|
+
// Inject env bindings on each request
|
|
18
|
+
app.use("/*", async (c, next) => {
|
|
19
|
+
setEnv(c.env);
|
|
20
|
+
await next();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// GPT Store operations
|
|
24
|
+
app.route(
|
|
25
|
+
"/api",
|
|
26
|
+
gptRoutes({
|
|
27
|
+
registry,
|
|
28
|
+
executor,
|
|
29
|
+
authenticate: async (request) => {
|
|
30
|
+
const authHeader = request.headers.get("Authorization");
|
|
31
|
+
if (!authHeader?.startsWith("Bearer ")) {
|
|
32
|
+
return {
|
|
33
|
+
error: Response.json({ error: "Unauthorized" }, { status: 401 }),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const token = authHeader.slice(7);
|
|
37
|
+
const ctx = await auth.$context;
|
|
38
|
+
const result = await ctx.internalAdapter.findSession(token);
|
|
39
|
+
if (!result) {
|
|
40
|
+
return {
|
|
41
|
+
error: Response.json({ error: "Session expired" }, { status: 401 }),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return { userId: result.user.id };
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// Better Auth
|
|
50
|
+
app.on(["GET", "POST"], "/api/auth/*", (c) => auth.handler(c.req.raw));
|
|
51
|
+
|
|
52
|
+
// GPT Store OAuth
|
|
53
|
+
app.get("/oauth/authorize", (c) => oauthAuthorize(c));
|
|
54
|
+
app.post("/oauth/code", (c) => oauthCode(c));
|
|
55
|
+
app.post("/oauth/token", (c) => oauthToken(c));
|
|
56
|
+
|
|
57
|
+
app.get("/", (c) =>
|
|
58
|
+
c.text("Kanban GPT running. Try GET /api/operations"),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export default app;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name = "my-kanban-app"
|
|
2
|
+
main = "worker.ts"
|
|
3
|
+
compatibility_date = "2024-12-01"
|
|
4
|
+
compatibility_flags = ["nodejs_compat"]
|
|
5
|
+
|
|
6
|
+
[[d1_databases]]
|
|
7
|
+
binding = "DB"
|
|
8
|
+
database_name = "my-kanban-db"
|
|
9
|
+
database_id = "local"
|
|
10
|
+
|
|
11
|
+
[vars]
|
|
12
|
+
BETTER_AUTH_URL = "http://localhost:8787"
|
|
13
|
+
|
|
14
|
+
# Set via: npx wrangler secret put BETTER_AUTH_SECRET
|
|
15
|
+
# Set via: npx wrangler secret put GPT_OAUTH_CLIENT_ID
|
|
16
|
+
# Set via: npx wrangler secret put GPT_OAUTH_CLIENT_SECRET
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Minimal donghanh App
|
|
2
|
+
|
|
3
|
+
A hello-world [@donghanh](https://github.com/rezzahub/donghanh) app with 2 operations and D1 SQLite.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
bun run db:init
|
|
10
|
+
bun run dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Try it
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
curl localhost:8787/api/operations
|
|
17
|
+
curl localhost:8787/api/query/list-items
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Deploy
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx wrangler d1 create my-donghanh-app-db
|
|
24
|
+
# Copy the database_id into wrangler.toml
|
|
25
|
+
npx wrangler deploy
|
|
26
|
+
```
|
package/templates/trello/db.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
function uid() {
|
|
2
|
-
return crypto.randomUUID().slice(0, 8);
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export async function listBoards(db: D1Database, userId: string) {
|
|
6
|
-
const { results } = await db
|
|
7
|
-
.prepare(
|
|
8
|
-
`SELECT b.*, COUNT(DISTINCT c.id) as card_count, COUNT(DISTINCT m.id) as member_count
|
|
9
|
-
FROM boards b
|
|
10
|
-
LEFT JOIN cards c ON c.board_id = b.id
|
|
11
|
-
LEFT JOIN members m ON m.board_id = b.id
|
|
12
|
-
GROUP BY b.id ORDER BY b.created_at DESC`,
|
|
13
|
-
)
|
|
14
|
-
.all();
|
|
15
|
-
return { boards: results };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function boardDetail(db: D1Database, boardId: string) {
|
|
19
|
-
const board = await db.prepare("SELECT * FROM boards WHERE id = ?").bind(boardId).first();
|
|
20
|
-
if (!board) throw new Error("Board not found");
|
|
21
|
-
|
|
22
|
-
const { results: columns } = await db
|
|
23
|
-
.prepare("SELECT * FROM columns WHERE board_id = ? ORDER BY position")
|
|
24
|
-
.bind(boardId)
|
|
25
|
-
.all();
|
|
26
|
-
|
|
27
|
-
const { results: cards } = await db
|
|
28
|
-
.prepare("SELECT * FROM cards WHERE board_id = ? ORDER BY position")
|
|
29
|
-
.bind(boardId)
|
|
30
|
-
.all();
|
|
31
|
-
|
|
32
|
-
const { results: members } = await db
|
|
33
|
-
.prepare("SELECT * FROM members WHERE board_id = ? ORDER BY added_at")
|
|
34
|
-
.bind(boardId)
|
|
35
|
-
.all();
|
|
36
|
-
|
|
37
|
-
// Group cards by column
|
|
38
|
-
const columnMap = columns.map((col: any) => ({
|
|
39
|
-
...col,
|
|
40
|
-
cards: cards.filter((c: any) => c.column_id === col.id),
|
|
41
|
-
}));
|
|
42
|
-
|
|
43
|
-
return { board, columns: columnMap, members };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function createBoard(db: D1Database, name: string, userId: string) {
|
|
47
|
-
const id = uid();
|
|
48
|
-
await db.prepare("INSERT INTO boards (id, name, created_by) VALUES (?, ?, ?)").bind(id, name, userId).run();
|
|
49
|
-
// Default columns
|
|
50
|
-
const cols = ["To Do", "In Progress", "Done"];
|
|
51
|
-
for (let i = 0; i < cols.length; i++) {
|
|
52
|
-
await db.prepare("INSERT INTO columns (id, board_id, name, position) VALUES (?, ?, ?, ?)").bind(uid(), id, cols[i], i).run();
|
|
53
|
-
}
|
|
54
|
-
// Add creator as member
|
|
55
|
-
await db.prepare("INSERT INTO members (id, board_id, name, user_id) VALUES (?, ?, ?, ?)").bind(uid(), id, "You", userId).run();
|
|
56
|
-
return boardDetail(db, id);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function addCard(db: D1Database, boardId: string, columnId: string, title: string) {
|
|
60
|
-
const id = uid();
|
|
61
|
-
const pos = await db.prepare("SELECT COUNT(*) as c FROM cards WHERE column_id = ?").bind(columnId).first<{ c: number }>();
|
|
62
|
-
await db.prepare("INSERT INTO cards (id, column_id, board_id, title, position) VALUES (?, ?, ?, ?, ?)").bind(id, columnId, boardId, title, pos?.c ?? 0).run();
|
|
63
|
-
return boardDetail(db, boardId);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export async function moveCard(db: D1Database, cardId: string, toColumnId: string) {
|
|
67
|
-
const card = await db.prepare("SELECT board_id FROM cards WHERE id = ?").bind(cardId).first<{ board_id: string }>();
|
|
68
|
-
if (!card) throw new Error("Card not found");
|
|
69
|
-
const pos = await db.prepare("SELECT COUNT(*) as c FROM cards WHERE column_id = ?").bind(toColumnId).first<{ c: number }>();
|
|
70
|
-
await db.prepare("UPDATE cards SET column_id = ?, position = ? WHERE id = ?").bind(toColumnId, pos?.c ?? 0, cardId).run();
|
|
71
|
-
return boardDetail(db, card.board_id);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export async function addMember(db: D1Database, boardId: string, name: string) {
|
|
75
|
-
const id = uid();
|
|
76
|
-
await db.prepare("INSERT INTO members (id, board_id, name) VALUES (?, ?, ?)").bind(id, boardId, name).run();
|
|
77
|
-
return boardDetail(db, boardId);
|
|
78
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Executor } from "@donghanh/core";
|
|
2
|
-
import * as queries from "./db";
|
|
3
|
-
|
|
4
|
-
export function createExecutor(db: D1Database): Executor {
|
|
5
|
-
const ops: Record<string, (vars: Record<string, unknown>, userId: string) => Promise<unknown>> = {
|
|
6
|
-
"list-boards": (_, userId) => queries.listBoards(db, userId),
|
|
7
|
-
"board-detail": (v) => queries.boardDetail(db, v.boardId as string),
|
|
8
|
-
"create-board": (v, userId) => queries.createBoard(db, v.name as string, userId),
|
|
9
|
-
"add-card": (v) => queries.addCard(db, v.boardId as string, v.columnId as string, v.title as string),
|
|
10
|
-
"move-card": (v) => queries.moveCard(db, v.cardId as string, v.toColumnId as string),
|
|
11
|
-
"add-member": (v) => queries.addMember(db, v.boardId as string, v.name as string),
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return async (operationId, variables, context) => {
|
|
15
|
-
const op = ops[operationId];
|
|
16
|
-
if (!op) throw new Error(`Unknown operation: ${operationId}`);
|
|
17
|
-
return op(variables, context.userId);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
CREATE TABLE IF NOT EXISTS boards (
|
|
2
|
-
id TEXT PRIMARY KEY,
|
|
3
|
-
name TEXT NOT NULL,
|
|
4
|
-
created_by TEXT NOT NULL,
|
|
5
|
-
created_at TEXT DEFAULT (datetime('now'))
|
|
6
|
-
);
|
|
7
|
-
|
|
8
|
-
CREATE TABLE IF NOT EXISTS columns (
|
|
9
|
-
id TEXT PRIMARY KEY,
|
|
10
|
-
board_id TEXT NOT NULL REFERENCES boards(id),
|
|
11
|
-
name TEXT NOT NULL,
|
|
12
|
-
position INTEGER NOT NULL DEFAULT 0
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
CREATE TABLE IF NOT EXISTS cards (
|
|
16
|
-
id TEXT PRIMARY KEY,
|
|
17
|
-
column_id TEXT NOT NULL REFERENCES columns(id),
|
|
18
|
-
board_id TEXT NOT NULL REFERENCES boards(id),
|
|
19
|
-
title TEXT NOT NULL,
|
|
20
|
-
position INTEGER NOT NULL DEFAULT 0,
|
|
21
|
-
created_at TEXT DEFAULT (datetime('now'))
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
CREATE TABLE IF NOT EXISTS members (
|
|
25
|
-
id TEXT PRIMARY KEY,
|
|
26
|
-
board_id TEXT NOT NULL REFERENCES boards(id),
|
|
27
|
-
name TEXT NOT NULL,
|
|
28
|
-
user_id TEXT,
|
|
29
|
-
added_at TEXT DEFAULT (datetime('now'))
|
|
30
|
-
);
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { App, buildRegistry } from "@donghanh/core";
|
|
2
|
-
import { gptRoutes } from "@donghanh/hono";
|
|
3
|
-
import { Hono } from "hono";
|
|
4
|
-
import { createExecutor } from "./executor";
|
|
5
|
-
import { operations } from "./operations";
|
|
6
|
-
|
|
7
|
-
type Env = { Bindings: { DB: D1Database } };
|
|
8
|
-
|
|
9
|
-
const appNode = App({ operations });
|
|
10
|
-
const registry = buildRegistry(appNode);
|
|
11
|
-
|
|
12
|
-
const app = new Hono<Env>();
|
|
13
|
-
|
|
14
|
-
app.route(
|
|
15
|
-
"/api",
|
|
16
|
-
gptRoutes({
|
|
17
|
-
registry,
|
|
18
|
-
executor: async (opId, vars, ctx) => {
|
|
19
|
-
const db = (ctx as any).db as D1Database;
|
|
20
|
-
return createExecutor(db)(opId, vars, ctx);
|
|
21
|
-
},
|
|
22
|
-
authenticate: async () => ({ userId: "anonymous" }),
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
// Middleware to pass D1 to executor context
|
|
27
|
-
app.use("/api/*", async (c, next) => {
|
|
28
|
-
(c as any).db = c.env.DB;
|
|
29
|
-
await next();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
app.get("/", (c) =>
|
|
33
|
-
c.text("Mini Trello running. Try GET /api/operations"),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
export default app;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|