create-disposabl-app 0.3.2 → 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.
- package/dist/index.js +31 -6
- package/dist/templates/default/apps/web/src/routeTree.gen.ts +49 -5
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.api-keys.tsx +154 -0
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.tsx +23 -5
- package/dist/templates/default/bun.lock +237 -39
- package/dist/templates/default/disposabl.json +3 -1
- package/dist/templates/default/package.json +4 -2
- package/dist/templates/default/packages/backend/generate.ts +123 -0
- package/dist/templates/default/packages/backend/generated/openapi.json +190 -0
- package/dist/templates/default/packages/backend/generated/platforms.ts +3 -0
- package/dist/templates/default/packages/backend/package.json +3 -1
- package/dist/templates/default/packages/cli/README.md +17 -0
- package/dist/templates/default/packages/cli/auth.ts +301 -0
- package/dist/templates/default/packages/cli/build.ts +9 -0
- package/dist/templates/default/packages/cli/index.ts +146 -0
- package/dist/templates/default/packages/cli/package.json +35 -0
- package/dist/templates/default/packages/cli/tsconfig.json +15 -0
- package/dist/templates/default/packages/disposabl-kit/platforms.ts +4 -4
- package/dist/templates/default/packages/disposabl-kit/server/http.ts +44 -8
- package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +94 -5
- package/dist/templates/default/packages/sdk/README.md +20 -0
- package/dist/templates/default/packages/sdk/openapi-ts.config.ts +10 -0
- package/dist/templates/default/packages/sdk/package.json +31 -0
- package/dist/templates/default/packages/sdk/src/config.ts +11 -0
- package/dist/templates/default/packages/sdk/src/generated/client/client.gen.ts +300 -0
- package/dist/templates/default/packages/sdk/src/generated/client/index.ts +27 -0
- package/dist/templates/default/packages/sdk/src/generated/client/types.gen.ts +238 -0
- package/dist/templates/default/packages/sdk/src/generated/client/utils.gen.ts +337 -0
- package/dist/templates/default/packages/sdk/src/generated/client.gen.ts +28 -0
- package/dist/templates/default/packages/sdk/src/generated/core/auth.gen.ts +49 -0
- package/dist/templates/default/packages/sdk/src/generated/core/bodySerializer.gen.ts +96 -0
- package/dist/templates/default/packages/sdk/src/generated/core/params.gen.ts +188 -0
- package/dist/templates/default/packages/sdk/src/generated/core/pathSerializer.gen.ts +186 -0
- package/dist/templates/default/packages/sdk/src/generated/core/queryKeySerializer.gen.ts +134 -0
- package/dist/templates/default/packages/sdk/src/generated/core/serverSentEvents.gen.ts +265 -0
- package/dist/templates/default/packages/sdk/src/generated/core/types.gen.ts +126 -0
- package/dist/templates/default/packages/sdk/src/generated/core/utils.gen.ts +146 -0
- package/dist/templates/default/packages/sdk/src/generated/index.ts +18 -0
- package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +82 -0
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +134 -0
- package/dist/templates/default/packages/sdk/src/index.ts +3 -0
- package/dist/templates/default/packages/sdk/tsconfig.build.json +10 -0
- package/dist/templates/default/packages/sdk/tsconfig.json +12 -0
- package/dist/templates/default/turbo.json +9 -0
- package/package.json +1 -1
|
@@ -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: "
|
|
30
|
-
{ id: "cli", label: "CLI", group: "
|
|
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: "
|
|
41
|
-
status: "
|
|
40
|
+
group: "Developer tools",
|
|
41
|
+
status: "available",
|
|
42
42
|
},
|
|
43
43
|
] as const;
|
|
44
44
|
|
|
@@ -4,7 +4,8 @@ import { registerStaticRoutes } from "@convex-dev/static-hosting";
|
|
|
4
4
|
import { httpActionGeneric, httpRouter } from "convex/server";
|
|
5
5
|
import { components } from "../../backend/convex/_generated/api";
|
|
6
6
|
import { env } from "../../backend/convex/_generated/server";
|
|
7
|
-
import
|
|
7
|
+
import modules from "../../backend/generated/platforms";
|
|
8
|
+
import openapi from "../../backend/generated/openapi.json";
|
|
8
9
|
import config from "../../../disposabl.json";
|
|
9
10
|
import { validatePlatforms } from "../platforms";
|
|
10
11
|
import { createPlatforms } from "./lib/platform-spec";
|
|
@@ -12,7 +13,7 @@ import { createPlatforms } from "./lib/platform-spec";
|
|
|
12
13
|
export { tool } from "@convex-dev/mcp";
|
|
13
14
|
export type { McpServerOptions, McpUser, ToolCtx } from "@convex-dev/mcp";
|
|
14
15
|
|
|
15
|
-
const platforms = createPlatforms(
|
|
16
|
+
const platforms = createPlatforms(modules);
|
|
16
17
|
export const platformSpec = platforms.spec;
|
|
17
18
|
|
|
18
19
|
const enabled = validatePlatforms(config.platforms);
|
|
@@ -41,15 +42,50 @@ export const {
|
|
|
41
42
|
|
|
42
43
|
export default function createHttpRouter() {
|
|
43
44
|
const http = httpRouter();
|
|
44
|
-
if (mcp
|
|
45
|
-
|
|
45
|
+
if (mcp) {
|
|
46
|
+
const authRoutes = httpRouter();
|
|
47
|
+
mcp.registerRoutes(authRoutes);
|
|
48
|
+
for (const [path, method, handler] of authRoutes.getRoutes()) {
|
|
49
|
+
if (path !== "/mcp" || enabled.includes("mcp"))
|
|
50
|
+
http.route({ path, method, handler });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
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
|
+
};
|
|
46
60
|
http.route({
|
|
47
|
-
|
|
48
|
-
method: "
|
|
49
|
-
handler: httpActionGeneric((
|
|
50
|
-
|
|
61
|
+
path: "/openapi.json",
|
|
62
|
+
method: "GET",
|
|
63
|
+
handler: httpActionGeneric(async () =>
|
|
64
|
+
Response.json(
|
|
65
|
+
{ ...openapi, servers: [{ url: env.CONVEX_SITE_URL }] },
|
|
66
|
+
{ headers: cors },
|
|
67
|
+
),
|
|
51
68
|
),
|
|
52
69
|
});
|
|
70
|
+
for (const method of ["GET", "POST", "OPTIONS"] as const)
|
|
71
|
+
http.route({
|
|
72
|
+
pathPrefix: "/api/",
|
|
73
|
+
method,
|
|
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
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
53
89
|
registerStaticRoutes(http, components.staticHosting);
|
|
54
90
|
return http;
|
|
55
91
|
}
|
|
@@ -92,19 +92,37 @@ export function createPlatforms(
|
|
|
92
92
|
request: Request,
|
|
93
93
|
authenticate: McpServer["authenticate"],
|
|
94
94
|
) {
|
|
95
|
-
const
|
|
95
|
+
const url = new URL(request.url);
|
|
96
|
+
const definition = routes.get(url.pathname);
|
|
96
97
|
if (!definition)
|
|
97
98
|
return Response.json({ error: "not_found" }, { status: 404 });
|
|
99
|
+
const method =
|
|
100
|
+
spec.find((operation) => operation.path === url.pathname)?.type ===
|
|
101
|
+
"query"
|
|
102
|
+
? "GET"
|
|
103
|
+
: "POST";
|
|
104
|
+
if (request.method !== method)
|
|
105
|
+
return Response.json(
|
|
106
|
+
{ error: "method_not_allowed" },
|
|
107
|
+
{ status: 405, headers: { Allow: method } },
|
|
108
|
+
);
|
|
98
109
|
try {
|
|
99
110
|
const user = await authenticate(ctx, request);
|
|
100
111
|
if (!user)
|
|
101
112
|
return Response.json({ error: "unauthenticated" }, { status: 401 });
|
|
102
113
|
if (definition.scope && !user.scopes.includes(definition.scope))
|
|
103
114
|
return Response.json({ error: "forbidden" }, { status: 403 });
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
const raw =
|
|
116
|
+
request.method === "GET"
|
|
117
|
+
? Object.fromEntries(
|
|
118
|
+
[...url.searchParams].map(([key, value]) => {
|
|
119
|
+
if (url.searchParams.getAll(key).length !== 1)
|
|
120
|
+
throw new SyntaxError("Duplicate argument");
|
|
121
|
+
return [key, JSON.parse(value)];
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
124
|
+
: await request.json();
|
|
125
|
+
const input = checkValue(v.object(definition.args ?? {}), raw);
|
|
108
126
|
if (!input.ok)
|
|
109
127
|
return Response.json({ error: input.error }, { status: 400 });
|
|
110
128
|
const result = await definition.handler(
|
|
@@ -135,3 +153,74 @@ export function createPlatforms(
|
|
|
135
153
|
},
|
|
136
154
|
};
|
|
137
155
|
}
|
|
156
|
+
|
|
157
|
+
/** The same validator schemas describe the HTTP transport and generated clients. */
|
|
158
|
+
export function createOpenApi(spec: Operation[], version = "0.1.0") {
|
|
159
|
+
const ids = new Set<string>();
|
|
160
|
+
return {
|
|
161
|
+
openapi: "3.1.0",
|
|
162
|
+
info: { title: "Application API", version },
|
|
163
|
+
security: [{ bearerAuth: [] }],
|
|
164
|
+
components: {
|
|
165
|
+
securitySchemes: { bearerAuth: { type: "http", scheme: "bearer" } },
|
|
166
|
+
},
|
|
167
|
+
paths: Object.fromEntries(
|
|
168
|
+
spec.map((operation) => {
|
|
169
|
+
const parts = operation.path.slice(5).split("/");
|
|
170
|
+
const operationId = parts
|
|
171
|
+
.map((part, i) =>
|
|
172
|
+
i ? part.charAt(0).toUpperCase() + part.slice(1) : part,
|
|
173
|
+
)
|
|
174
|
+
.join("");
|
|
175
|
+
if (ids.has(operationId))
|
|
176
|
+
throw new Error(`Duplicate operation ID: ${operationId}`);
|
|
177
|
+
ids.add(operationId);
|
|
178
|
+
const query = operation.type === "query";
|
|
179
|
+
const args = operation.args as {
|
|
180
|
+
properties?: Record<string, unknown>;
|
|
181
|
+
required?: string[];
|
|
182
|
+
};
|
|
183
|
+
return [
|
|
184
|
+
operation.path,
|
|
185
|
+
{
|
|
186
|
+
[query ? "get" : "post"]: {
|
|
187
|
+
operationId,
|
|
188
|
+
"x-convex-function": operation.name,
|
|
189
|
+
...(query
|
|
190
|
+
? {
|
|
191
|
+
parameters: Object.entries(args.properties ?? {}).map(
|
|
192
|
+
([name, schema]) => ({
|
|
193
|
+
name,
|
|
194
|
+
in: "query",
|
|
195
|
+
required: args.required?.includes(name) ?? false,
|
|
196
|
+
content: { "application/json": { schema } },
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
}
|
|
200
|
+
: {
|
|
201
|
+
requestBody: {
|
|
202
|
+
required: true,
|
|
203
|
+
content: {
|
|
204
|
+
"application/json": { schema: operation.args },
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
}),
|
|
208
|
+
responses: {
|
|
209
|
+
"200": {
|
|
210
|
+
description: "Success",
|
|
211
|
+
content: {
|
|
212
|
+
"application/json": { schema: operation.returns },
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
"400": { description: "Invalid arguments" },
|
|
216
|
+
"401": { description: "Authentication required" },
|
|
217
|
+
"403": { description: "Insufficient scope" },
|
|
218
|
+
"500": { description: "Internal error" },
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
}),
|
|
224
|
+
),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@disposabl/sdk",
|
|
3
|
+
"version": "0.0.0-development",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Generated TypeScript SDK for your Disposabl API",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"generate": "openapi-ts && bun fmt src/generated",
|
|
22
|
+
"build": "bun run generate && tsc -p tsconfig.build.json",
|
|
23
|
+
"typecheck": "bun run generate && tsc --noEmit",
|
|
24
|
+
"lint": "bun check"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@hey-api/openapi-ts": "0.99.0",
|
|
28
|
+
"typescript": "6.0.3",
|
|
29
|
+
"@types/bun": "1.4.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CreateClientConfig } from "./generated/client.gen.js";
|
|
2
|
+
// JSON parameter encoding preserves Convex objects, arrays, booleans and strings.
|
|
3
|
+
export const createClientConfig: CreateClientConfig = (config) => ({
|
|
4
|
+
...config,
|
|
5
|
+
querySerializer: (query) =>
|
|
6
|
+
new URLSearchParams(
|
|
7
|
+
Object.entries(query)
|
|
8
|
+
.filter(([, value]) => value !== undefined)
|
|
9
|
+
.map(([name, value]) => [name, JSON.stringify(value)]),
|
|
10
|
+
).toString(),
|
|
11
|
+
});
|