create-disposabl-app 0.3.3 → 0.3.4

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.
Files changed (40) hide show
  1. package/dist/index.js +31 -6
  2. package/dist/templates/default/apps/web/src/routeTree.gen.ts +49 -5
  3. package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.api-keys.tsx +154 -0
  4. package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.tsx +23 -5
  5. package/dist/templates/default/bun.lock +237 -39
  6. package/dist/templates/default/disposabl.json +3 -1
  7. package/dist/templates/default/package.json +4 -2
  8. package/dist/templates/default/packages/backend/generate.ts +9 -0
  9. package/dist/templates/default/packages/cli/README.md +17 -0
  10. package/dist/templates/default/packages/cli/auth.ts +301 -0
  11. package/dist/templates/default/packages/cli/build.ts +9 -0
  12. package/dist/templates/default/packages/cli/index.ts +146 -0
  13. package/dist/templates/default/packages/cli/package.json +35 -0
  14. package/dist/templates/default/packages/cli/tsconfig.json +15 -0
  15. package/dist/templates/default/packages/disposabl-kit/platforms.ts +4 -4
  16. package/dist/templates/default/packages/disposabl-kit/server/http.ts +24 -5
  17. package/dist/templates/default/packages/sdk/README.md +20 -0
  18. package/dist/templates/default/packages/sdk/openapi-ts.config.ts +10 -0
  19. package/dist/templates/default/packages/sdk/package.json +31 -0
  20. package/dist/templates/default/packages/sdk/src/config.ts +11 -0
  21. package/dist/templates/default/packages/sdk/src/generated/client/client.gen.ts +300 -0
  22. package/dist/templates/default/packages/sdk/src/generated/client/index.ts +27 -0
  23. package/dist/templates/default/packages/sdk/src/generated/client/types.gen.ts +238 -0
  24. package/dist/templates/default/packages/sdk/src/generated/client/utils.gen.ts +337 -0
  25. package/dist/templates/default/packages/sdk/src/generated/client.gen.ts +28 -0
  26. package/dist/templates/default/packages/sdk/src/generated/core/auth.gen.ts +49 -0
  27. package/dist/templates/default/packages/sdk/src/generated/core/bodySerializer.gen.ts +96 -0
  28. package/dist/templates/default/packages/sdk/src/generated/core/params.gen.ts +188 -0
  29. package/dist/templates/default/packages/sdk/src/generated/core/pathSerializer.gen.ts +186 -0
  30. package/dist/templates/default/packages/sdk/src/generated/core/queryKeySerializer.gen.ts +134 -0
  31. package/dist/templates/default/packages/sdk/src/generated/core/serverSentEvents.gen.ts +265 -0
  32. package/dist/templates/default/packages/sdk/src/generated/core/types.gen.ts +126 -0
  33. package/dist/templates/default/packages/sdk/src/generated/core/utils.gen.ts +146 -0
  34. package/dist/templates/default/packages/sdk/src/generated/index.ts +18 -0
  35. package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +82 -0
  36. package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +134 -0
  37. package/dist/templates/default/packages/sdk/src/index.ts +3 -0
  38. package/dist/templates/default/packages/sdk/tsconfig.build.json +10 -0
  39. package/dist/templates/default/packages/sdk/tsconfig.json +12 -0
  40. package/package.json +1 -1
@@ -8,7 +8,9 @@
8
8
  "macos",
9
9
  "linux",
10
10
  "api",
11
- "mcp"
11
+ "mcp",
12
+ "cli",
13
+ "typescript-sdk"
12
14
  ],
13
15
  "features": ["authentication"]
14
16
  }
@@ -2,12 +2,14 @@
2
2
  "name": "disposabl-dev",
3
3
  "private": true,
4
4
  "scripts": {
5
- "check": "turbo run typecheck lint && bun fmt --check && bun test --pass-with-no-tests",
5
+ "check": "bun run generate && turbo run typecheck lint && bun fmt --check && bun test --pass-with-no-tests",
6
6
  "build": "turbo build",
7
7
  "dev": "turbo dev",
8
8
  "lint": "turbo lint",
9
9
  "format": "turbo format",
10
- "typecheck": "turbo typecheck"
10
+ "typecheck": "turbo typecheck",
11
+ "generate": "bun run --cwd packages/backend generate",
12
+ "prebuild": "bun run generate"
11
13
  },
12
14
  "devDependencies": {
13
15
  "prettier": "^3.9.10",
@@ -8,6 +8,8 @@ import {
8
8
  createPlatforms,
9
9
  } from "../disposabl-kit/server/lib/platform-spec";
10
10
 
11
+ import config from "../../disposabl.json";
12
+
11
13
  const root = fileURLToPath(new URL(".", import.meta.url));
12
14
  const convex = join(root, "convex");
13
15
  const output = join(root, "generated");
@@ -92,6 +94,13 @@ export async function generate(acceptBreaking = false) {
92
94
  });
93
95
  if (formatted.status !== 0)
94
96
  throw new Error("Could not format generated contract");
97
+ if (config.platforms.includes("typescript-sdk")) {
98
+ const sdk = spawnSync(process.execPath, ["run", "generate"], {
99
+ cwd: join(root, "../sdk"),
100
+ stdio: "inherit",
101
+ });
102
+ if (sdk.status !== 0) throw new Error("SDK generation failed");
103
+ }
95
104
  console.log(
96
105
  `Generated ${Object.keys(next.paths).length} operations, contract ${next.info.version}.`,
97
106
  );
@@ -0,0 +1,17 @@
1
+ # Disposabl CLI
2
+
3
+ The CLI reads your app's `/openapi.json` and calls its API directly. It does not depend on the SDK.
4
+
5
+ ```sh
6
+ export DISPOSABL_API_URL=https://your-deployment.convex.site
7
+ npx @disposabl/cli login
8
+ npx @disposabl/cli todos create --title 'Ship the app'
9
+ npx @disposabl/cli todos list
10
+ npx @disposabl/cli logout
11
+ ```
12
+
13
+ `--url` overrides the environment. `login --no-browser` prints the authorization URL for manual opening. OAuth uses the app's existing MCP authorization server, PKCE S256, a random loopback callback port and state, rotating refresh tokens, and server-side revocation. Login requires the API platform; MCP tool exposure is optional.
14
+
15
+ Credentials are stored per API origin under `~/.config/disposabl` (directory mode 0700, files 0600). `DISPOSABL_CONFIG_DIR` overrides that directory. Credentials are not encrypted at rest; keep the account and disk protected. A lock serializes refreshes across processes. `DISPOSABL_API_KEY` supplies a dashboard-created key for automation and bypasses OAuth. Logout revokes stored OAuth credentials; revoke API keys from the dashboard.
16
+
17
+ Strings are plain option values. Other argument types use JSON, for example `--limit 10` or `--filters '{"done":false}'`. Use `todos --help` for commands exposed by your app.
@@ -0,0 +1,301 @@
1
+ import { lock } from "proper-lockfile";
2
+ import {
3
+ auth,
4
+ type OAuthClientProvider,
5
+ } from "@modelcontextprotocol/sdk/client/auth.js";
6
+ import type {
7
+ OAuthClientInformationMixed,
8
+ OAuthTokens,
9
+ } from "@modelcontextprotocol/sdk/shared/auth.js";
10
+ import { createServer } from "node:http";
11
+ import { randomBytes, createHash } from "node:crypto";
12
+ import {
13
+ mkdir,
14
+ readFile,
15
+ writeFile,
16
+ rename,
17
+ rm,
18
+ chmod,
19
+ } from "node:fs/promises";
20
+ import { homedir } from "node:os";
21
+ import { join } from "node:path";
22
+ import { spawn } from "node:child_process";
23
+
24
+ type Session = {
25
+ client?: OAuthClientInformationMixed;
26
+ tokens?: OAuthTokens;
27
+ expiresAt?: number;
28
+ redirectUrl?: string;
29
+ };
30
+ const directory = () =>
31
+ process.env.DISPOSABL_CONFIG_DIR || join(homedir(), ".config", "disposabl");
32
+ const sessionPath = (url: string) =>
33
+ join(directory(), `${createHash("sha256").update(url).digest("hex")}.json`);
34
+ export function apiUrl(value: string) {
35
+ const url = new URL(value);
36
+ if (
37
+ url.protocol !== "https:" &&
38
+ !(
39
+ url.protocol === "http:" &&
40
+ ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)
41
+ )
42
+ )
43
+ throw new Error("Use HTTPS, or HTTP on loopback for local development.");
44
+ if (
45
+ url.username ||
46
+ url.password ||
47
+ url.search ||
48
+ url.hash ||
49
+ url.pathname !== "/"
50
+ )
51
+ throw new Error("Use the API origin without a path or credentials.");
52
+ return url.origin;
53
+ }
54
+ const fetchFor = (origin: string): typeof fetch =>
55
+ Object.assign(
56
+ async (
57
+ input: Parameters<typeof fetch>[0],
58
+ init?: Parameters<typeof fetch>[1],
59
+ ) => {
60
+ const url = new URL(input instanceof Request ? input.url : input);
61
+ if (url.origin !== origin)
62
+ throw new Error(
63
+ "OAuth endpoint must belong to the configured API origin.",
64
+ );
65
+ return fetch(input, {
66
+ ...init,
67
+ redirect: "error",
68
+ signal: init?.signal ?? AbortSignal.timeout(30_000),
69
+ });
70
+ },
71
+ { preconnect: fetch.preconnect },
72
+ );
73
+ async function load(url: string): Promise<Session> {
74
+ try {
75
+ return JSON.parse(await readFile(sessionPath(url), "utf8"));
76
+ } catch (error) {
77
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return {};
78
+ throw error;
79
+ }
80
+ }
81
+ async function save(url: string, session: Session) {
82
+ await mkdir(directory(), { recursive: true, mode: 0o700 });
83
+ await chmod(directory(), 0o700);
84
+ const temporary = `${sessionPath(url)}.${randomBytes(8).toString("hex")}`;
85
+ try {
86
+ await writeFile(temporary, JSON.stringify(session), {
87
+ mode: 0o600,
88
+ flag: "wx",
89
+ });
90
+ await rename(temporary, sessionPath(url));
91
+ } finally {
92
+ await rm(temporary, { force: true });
93
+ }
94
+ }
95
+ function provider(
96
+ url: string,
97
+ session: Session,
98
+ redirect: (url: URL) => void,
99
+ state?: string,
100
+ ): OAuthClientProvider {
101
+ let verifier = "";
102
+ return {
103
+ redirectUrl: session.redirectUrl,
104
+ clientMetadata: {
105
+ client_name: "Disposabl CLI",
106
+ redirect_uris: session.redirectUrl ? [session.redirectUrl] : [],
107
+ grant_types: ["authorization_code", "refresh_token"],
108
+ response_types: ["code"],
109
+ token_endpoint_auth_method: "none",
110
+ },
111
+ state: () => state ?? "",
112
+ clientInformation: () => session.client,
113
+ saveClientInformation: (client) => {
114
+ session.client = client;
115
+ },
116
+ tokens: () => session.tokens,
117
+ saveTokens: async (tokens) => {
118
+ session.tokens = tokens;
119
+ session.expiresAt = tokens.expires_in
120
+ ? Date.now() + tokens.expires_in * 1000
121
+ : 0;
122
+ await save(url, session);
123
+ },
124
+ saveCodeVerifier: (value) => {
125
+ verifier = value;
126
+ },
127
+ codeVerifier: () => verifier,
128
+ redirectToAuthorization: redirect,
129
+ invalidateCredentials: async (scope) => {
130
+ if (scope === "all" || scope === "tokens") {
131
+ delete session.tokens;
132
+ delete session.expiresAt;
133
+ }
134
+ if (scope === "all" || scope === "client") delete session.client;
135
+ if (scope === "all" || scope === "verifier") verifier = "";
136
+ await save(url, session);
137
+ },
138
+ };
139
+ }
140
+ async function unlockedLogin(url: string, openBrowser = true) {
141
+ const state = randomBytes(32).toString("base64url");
142
+ const server = createServer();
143
+ await new Promise<void>((resolve, reject) => {
144
+ server.once("error", reject);
145
+ server.listen(0, "127.0.0.1", resolve);
146
+ });
147
+ const address = server.address();
148
+ if (!address || typeof address === "string")
149
+ throw new Error("Could not bind the login callback.");
150
+ const session: Session = {
151
+ redirectUrl: `http://127.0.0.1:${address.port}/callback`,
152
+ };
153
+ const oauth = provider(
154
+ url,
155
+ session,
156
+ (authorizationUrl) => {
157
+ if (authorizationUrl.origin !== url)
158
+ throw new Error("Unexpected authorization server.");
159
+ console.error(`Open this URL to sign in:\n${authorizationUrl.href}`);
160
+ if (openBrowser) {
161
+ const command =
162
+ process.platform === "darwin"
163
+ ? "open"
164
+ : process.platform === "win32"
165
+ ? "rundll32"
166
+ : "xdg-open";
167
+ const args =
168
+ process.platform === "win32"
169
+ ? ["url.dll,FileProtocolHandler", authorizationUrl.href]
170
+ : [authorizationUrl.href];
171
+ const child = spawn(command, args, { stdio: "ignore" });
172
+ child.on("error", () =>
173
+ console.error("Open the sign-in URL manually."),
174
+ );
175
+ child.unref();
176
+ }
177
+ },
178
+ state,
179
+ );
180
+ let timer: ReturnType<typeof setTimeout> | undefined;
181
+ try {
182
+ const callback = new Promise<void>((resolve, reject) => {
183
+ timer = setTimeout(
184
+ () => reject(new Error("Login timed out. Start login again.")),
185
+ 300_000,
186
+ );
187
+ server.on("request", async (request, response) => {
188
+ const callbackUrl = new URL(request.url ?? "/", session.redirectUrl);
189
+ const invalid =
190
+ request.method !== "GET" ||
191
+ request.headers.host !== `127.0.0.1:${address.port}` ||
192
+ callbackUrl.pathname !== "/callback" ||
193
+ callbackUrl.searchParams.getAll("state").length !== 1 ||
194
+ callbackUrl.searchParams.get("state") !== state;
195
+ if (invalid) {
196
+ response.writeHead(400).end("Invalid login callback.");
197
+ return;
198
+ }
199
+ try {
200
+ if (callbackUrl.searchParams.get("iss")?.replace(/\/$/, "") !== url)
201
+ throw new Error("Unexpected OAuth issuer.");
202
+ const code = callbackUrl.searchParams.get("code");
203
+ if (
204
+ !code ||
205
+ callbackUrl.searchParams.getAll("code").length !== 1 ||
206
+ callbackUrl.searchParams.has("error")
207
+ )
208
+ throw new Error("Login was not approved.");
209
+ const result = await auth(oauth, {
210
+ serverUrl: `${url}/mcp`,
211
+ authorizationCode: code,
212
+ fetchFn: fetchFor(url),
213
+ });
214
+ if (result !== "AUTHORIZED")
215
+ throw new Error("Login did not complete.");
216
+ response
217
+ .writeHead(200, {
218
+ "Content-Type": "text/plain",
219
+ "Cache-Control": "no-store",
220
+ })
221
+ .end("Signed in. You can close this tab.");
222
+ resolve();
223
+ } catch (error) {
224
+ response.writeHead(400).end("Login failed. Return to your terminal.");
225
+ reject(error);
226
+ }
227
+ });
228
+ });
229
+ // Attach a rejection handler before discovery can fail or the timer fires.
230
+ void callback.catch(() => {});
231
+ await auth(oauth, { serverUrl: `${url}/mcp`, fetchFn: fetchFor(url) });
232
+ await callback;
233
+ } finally {
234
+ clearTimeout(timer);
235
+ server.closeAllConnections();
236
+ server.close();
237
+ }
238
+ }
239
+ async function unlockedAccessToken(url: string, forceRefresh = false) {
240
+ if (process.env.DISPOSABL_API_KEY) return process.env.DISPOSABL_API_KEY;
241
+ const session = await load(url);
242
+ if (!session.tokens)
243
+ throw new Error("Run login first, or set DISPOSABL_API_KEY.");
244
+ if (
245
+ forceRefresh ||
246
+ !session.expiresAt ||
247
+ Date.now() >= session.expiresAt - 30_000
248
+ ) {
249
+ const oauth = provider(url, session, () => {
250
+ throw new Error("Session expired. Run login again.");
251
+ });
252
+ await auth(oauth, { serverUrl: `${url}/mcp`, fetchFn: fetchFor(url) });
253
+ }
254
+ if (!session.tokens) throw new Error("Session expired. Run login again.");
255
+ return session.tokens.access_token;
256
+ }
257
+ async function unlockedLogout(url: string) {
258
+ const session = await load(url);
259
+ if (session.tokens) {
260
+ for (const token of [
261
+ session.tokens.refresh_token,
262
+ session.tokens.access_token,
263
+ ].filter(Boolean)) {
264
+ const response = await fetchFor(url)(`${url}/mcp/oauth/revoke`, {
265
+ method: "POST",
266
+ body: new URLSearchParams({
267
+ token: token!,
268
+ client_id: session.client?.client_id ?? "",
269
+ }),
270
+ });
271
+ if (!response.ok)
272
+ throw new Error(
273
+ "Revocation failed; credentials retained so logout can be retried.",
274
+ );
275
+ }
276
+ }
277
+ await rm(sessionPath(url), { force: true });
278
+ }
279
+
280
+ async function withCredentials<T>(
281
+ url: string,
282
+ operation: () => Promise<T>,
283
+ ): Promise<T> {
284
+ await mkdir(directory(), { recursive: true, mode: 0o700 });
285
+ const release = await lock(sessionPath(url), {
286
+ realpath: false,
287
+ stale: 10000,
288
+ retries: { retries: 8, minTimeout: 100, maxTimeout: 1000 },
289
+ });
290
+ try {
291
+ return await operation();
292
+ } finally {
293
+ await release();
294
+ }
295
+ }
296
+ export const login = (url: string, browser = true) =>
297
+ withCredentials(url, () => unlockedLogin(url, browser));
298
+ export const accessToken = (url: string, refresh = false) =>
299
+ withCredentials(url, () => unlockedAccessToken(url, refresh));
300
+ export const logout = (url: string) =>
301
+ withCredentials(url, () => unlockedLogout(url));
@@ -0,0 +1,9 @@
1
+ const result = await Bun.build({
2
+ entrypoints: ["index.ts"],
3
+ outdir: "dist",
4
+ target: "node",
5
+ packages: "external",
6
+ });
7
+ if (!result.success) throw new AggregateError(result.logs, "CLI build failed");
8
+
9
+ export {};
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "commander";
3
+ import manifest from "./package.json";
4
+ import { accessToken, apiUrl, login, logout } from "./auth";
5
+
6
+ type Schema = {
7
+ type?: string;
8
+ properties?: Record<string, Schema>;
9
+ required?: string[];
10
+ };
11
+ type Operation = {
12
+ operationId: string;
13
+ parameters?: {
14
+ name: string;
15
+ required?: boolean;
16
+ content: { "application/json": { schema: Schema } };
17
+ }[];
18
+ requestBody?: { content: { "application/json": { schema: Schema } } };
19
+ };
20
+ const program = new Command()
21
+ .name(Object.keys(manifest.bin)[0])
22
+ .version(manifest.version)
23
+ .option(
24
+ "--url <origin>",
25
+ "Convex HTTP origin",
26
+ process.env.DISPOSABL_API_URL,
27
+ );
28
+ const origin = () => {
29
+ const value = program.opts().url;
30
+ if (!value)
31
+ throw new Error(
32
+ "Set --url https://your-app.convex.site or DISPOSABL_API_URL.",
33
+ );
34
+ return apiUrl(value);
35
+ };
36
+ program
37
+ .command("login")
38
+ .option("--no-browser", "Print the login URL without opening a browser")
39
+ .action(async (options) => {
40
+ await login(origin(), options.browser);
41
+ console.error("Signed in.");
42
+ });
43
+ program.command("logout").action(async () => {
44
+ await logout(origin());
45
+ console.error("Signed out.");
46
+ });
47
+
48
+ async function main() {
49
+ // Help, version and login work without fetching the application contract.
50
+ const args = process.argv.slice(2);
51
+ const global = program.parseOptions(args);
52
+ const commandName = global.operands[0];
53
+ if (commandName && !["login", "logout", "help"].includes(commandName)) {
54
+ const base = origin();
55
+ const response = await fetch(`${base}/openapi.json`, {
56
+ redirect: "error",
57
+ signal: AbortSignal.timeout(30_000),
58
+ });
59
+ if (!response.ok)
60
+ throw new Error(`Could not load OpenAPI (${response.status}).`);
61
+ const spec = (await response.json()) as {
62
+ paths: Record<string, Record<string, Operation>>;
63
+ };
64
+ for (const [path, methods] of Object.entries(spec.paths)) {
65
+ if (!path.startsWith("/api/") || path.includes("?") || path.includes("#"))
66
+ throw new Error("Invalid API path in contract.");
67
+ for (const [method, operation] of Object.entries(methods)) {
68
+ if (!["get", "post"].includes(method)) continue;
69
+ const parts = path.slice(5).split("/");
70
+ let parent = program;
71
+ for (const part of parts.slice(0, -1))
72
+ parent =
73
+ parent.commands.find((command) => command.name() === part) ??
74
+ parent.command(part);
75
+ const command = parent.command(parts.at(-1)!);
76
+ const schema =
77
+ operation.requestBody?.content["application/json"].schema;
78
+ const fields =
79
+ method === "get"
80
+ ? (operation.parameters ?? []).map((p) => ({
81
+ name: p.name,
82
+ required: p.required,
83
+ schema: p.content["application/json"].schema,
84
+ }))
85
+ : Object.entries(schema?.properties ?? {}).map(([name, value]) => ({
86
+ name,
87
+ required: schema?.required?.includes(name),
88
+ schema: value,
89
+ }));
90
+ for (const field of fields) {
91
+ const flag = `--${field.name} <value>`;
92
+ if (field.required)
93
+ command.requiredOption(
94
+ flag,
95
+ field.schema.type === "string"
96
+ ? field.name
97
+ : `${field.name} as JSON`,
98
+ );
99
+ else command.option(flag, field.name);
100
+ }
101
+ command.action(async (options) => {
102
+ const input = Object.fromEntries(
103
+ fields
104
+ .filter((field) => options[field.name] !== undefined)
105
+ .map((field) => [
106
+ field.name,
107
+ field.schema.type === "string"
108
+ ? options[field.name]
109
+ : JSON.parse(options[field.name]),
110
+ ]),
111
+ );
112
+ const target = new URL(path, base);
113
+ if (target.origin !== base || !target.pathname.startsWith("/api/"))
114
+ throw new Error("Invalid operation URL.");
115
+ if (method === "get")
116
+ for (const [name, value] of Object.entries(input))
117
+ target.searchParams.set(name, JSON.stringify(value));
118
+ const send = async (refresh = false) =>
119
+ fetch(target, {
120
+ method: method.toUpperCase(),
121
+ redirect: "error",
122
+ signal: AbortSignal.timeout(30_000),
123
+ headers: {
124
+ Authorization: `Bearer ${await accessToken(base, refresh)}`,
125
+ "Content-Type": "application/json",
126
+ },
127
+ body: method === "post" ? JSON.stringify(input) : undefined,
128
+ });
129
+ let result = await send();
130
+ if (result.status === 401 && !process.env.DISPOSABL_API_KEY)
131
+ result = await send(true);
132
+ if (!result.ok)
133
+ throw new Error(
134
+ `API request failed (${result.status}): ${await result.text()}`,
135
+ );
136
+ console.log(JSON.stringify(await result.json(), null, 2));
137
+ });
138
+ }
139
+ }
140
+ }
141
+ await program.parseAsync(process.argv);
142
+ }
143
+ main().catch((error) => {
144
+ console.error(error instanceof Error ? error.message : "Command failed.");
145
+ process.exitCode = 1;
146
+ });
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@disposabl/cli",
3
+ "version": "0.0.0-development",
4
+ "type": "module",
5
+ "description": "Command-line access to your Disposabl app",
6
+ "license": "MIT",
7
+ "bin": {
8
+ "disposabl": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "engines": {
15
+ "node": ">=22.12.0"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "scripts": {
21
+ "build": "bun build.ts",
22
+ "typecheck": "bun check",
23
+ "lint": "bun check"
24
+ },
25
+ "dependencies": {
26
+ "@modelcontextprotocol/sdk": "1.32.2",
27
+ "commander": "15.0.0",
28
+ "proper-lockfile": "4.1.2"
29
+ },
30
+ "devDependencies": {
31
+ "@types/bun": "1.4.4",
32
+ "typescript": "6.0.3",
33
+ "@types/proper-lockfile": "4.1.4"
34
+ }
35
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "Preserve",
5
+ "moduleResolution": "Bundler",
6
+ "types": ["bun"],
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "allowImportingTsExtensions": true,
10
+ "resolveJsonModule": true,
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["*.ts"],
14
+ "exclude": ["**/dist", "node_modules"]
15
+ }
@@ -26,8 +26,8 @@ export const platforms = [
26
26
  group: "MCP & plugins",
27
27
  status: "available",
28
28
  },
29
- { id: "api", label: "API", group: "Coming soon", status: "disabled" },
30
- { id: "cli", label: "CLI", group: "Coming soon", status: "disabled" },
29
+ { id: "api", label: "API", group: "Developer tools", status: "available" },
30
+ { id: "cli", label: "CLI", group: "Developer tools", status: "available" },
31
31
  {
32
32
  id: "python-sdk",
33
33
  label: "Python SDK",
@@ -37,8 +37,8 @@ export const platforms = [
37
37
  {
38
38
  id: "typescript-sdk",
39
39
  label: "TypeScript SDK",
40
- group: "Coming soon",
41
- status: "disabled",
40
+ group: "Developer tools",
41
+ status: "available",
42
42
  },
43
43
  ] as const;
44
44
 
@@ -51,20 +51,39 @@ export default function createHttpRouter() {
51
51
  }
52
52
  }
53
53
  if (mcp && enabled.includes("api")) {
54
+ const cors = {
55
+ "Access-Control-Allow-Origin": "*",
56
+ "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
57
+ "Access-Control-Allow-Headers": "Authorization, Content-Type",
58
+ "Cache-Control": "no-store",
59
+ };
54
60
  http.route({
55
61
  path: "/openapi.json",
56
62
  method: "GET",
57
63
  handler: httpActionGeneric(async () =>
58
- Response.json({ ...openapi, servers: [{ url: env.CONVEX_SITE_URL }] }),
64
+ Response.json(
65
+ { ...openapi, servers: [{ url: env.CONVEX_SITE_URL }] },
66
+ { headers: cors },
67
+ ),
59
68
  ),
60
69
  });
61
- for (const method of ["GET", "POST"] as const)
70
+ for (const method of ["GET", "POST", "OPTIONS"] as const)
62
71
  http.route({
63
72
  pathPrefix: "/api/",
64
73
  method,
65
- handler: httpActionGeneric((ctx, request) =>
66
- platforms.handleApi(ctx, request, mcp.authenticate.bind(mcp)),
67
- ),
74
+ handler: httpActionGeneric(async (ctx, request) => {
75
+ const response =
76
+ method === "OPTIONS"
77
+ ? new Response(null, { status: 204 })
78
+ : await platforms.handleApi(
79
+ ctx,
80
+ request,
81
+ mcp.authenticate.bind(mcp),
82
+ );
83
+ for (const [key, value] of Object.entries(cors))
84
+ response.headers.set(key, value);
85
+ return response;
86
+ }),
68
87
  });
69
88
  }
70
89
  registerStaticRoutes(http, components.staticHosting);
@@ -0,0 +1,20 @@
1
+ # Disposabl TypeScript SDK
2
+
3
+ Generated with the pinned Hey API generator from `packages/backend/generated/openapi.json`.
4
+
5
+ ```ts
6
+ import { client, todosCreate, todosList, todosGet } from "@disposabl/sdk";
7
+
8
+ client.setConfig({
9
+ baseUrl: "https://your-deployment.convex.site",
10
+ auth: process.env.DISPOSABL_API_KEY,
11
+ throwOnError: true,
12
+ });
13
+ const { data: id } = await todosCreate({ body: { title: "Ship the app" } });
14
+ const { data: todos } = await todosList();
15
+ const { data: todo } = await todosGet({ query: { id: id! } });
16
+ ```
17
+
18
+ Create API keys at `/dashboard/api-keys`. Keep server integration keys on the server. The API also accepts OAuth tokens issued through its MCP authorization server.
19
+
20
+ Run `bun run generate` in `packages/backend`, then `bun run generate` here to update the typed operations. Query parameters use JSON encoding. The backend refuses incompatible contract regeneration without `--accept-breaking`; review that diff before accepting a major contract version.
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from "@hey-api/openapi-ts";
2
+ export default defineConfig({
3
+ input: "../backend/generated/openapi.json",
4
+ output: { path: "src/generated", module: { extension: ".js" } },
5
+ plugins: [
6
+ "@hey-api/typescript",
7
+ "@hey-api/sdk",
8
+ { name: "@hey-api/client-fetch", runtimeConfigPath: "./src/config.js" },
9
+ ],
10
+ });