create-disposabl-app 0.4.2 → 0.6.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 +18 -0
- package/dist/disposabl.js +541 -0
- package/dist/index.js +154 -61
- package/dist/templates/default/.github/scripts/android-build.sh +18 -0
- package/dist/templates/default/.github/scripts/disposabl.mjs +95 -0
- package/dist/templates/default/.github/scripts/expo-channel.sh +10 -0
- package/dist/templates/default/.github/scripts/expo-env.sh +17 -0
- package/dist/templates/default/.github/scripts/expo-fingerprint.sh +19 -0
- package/dist/templates/default/.github/scripts/expo-update.sh +11 -0
- package/dist/templates/default/.github/scripts/package-release.sh +23 -0
- package/dist/templates/default/.github/scripts/platforms.sh +37 -0
- package/dist/templates/default/.github/scripts/release-publish.sh +28 -0
- package/dist/templates/default/.github/scripts/release-source.sh +14 -0
- package/dist/templates/default/.github/scripts/verify-artifacts.sh +13 -0
- package/dist/templates/default/.github/scripts/web-deploy.sh +10 -0
- package/dist/templates/default/.github/workflows/pipeline.yml +299 -0
- package/dist/templates/default/apps/docs/README.md +37 -0
- package/dist/templates/default/apps/docs/content/guides/writing.mdx +15 -0
- package/dist/templates/default/apps/docs/content/index.mdx +10 -0
- package/dist/templates/default/apps/docs/package.json +29 -1
- package/dist/templates/default/apps/docs/press.config.ts +20 -0
- package/dist/templates/default/apps/docs/src/app.css +4 -0
- package/dist/templates/default/apps/docs/tsconfig.json +14 -0
- package/dist/templates/default/apps/docs/vite.config.ts +8 -0
- package/dist/templates/default/apps/mobile/.env.example +2 -0
- package/dist/templates/default/apps/mobile/AGENTS.md +2 -2
- package/dist/templates/default/apps/mobile/README.md +64 -4
- package/dist/templates/default/apps/mobile/app.json +5 -4
- package/dist/templates/default/apps/mobile/assets/images/android-icon-foreground.png +0 -0
- package/dist/templates/default/apps/mobile/assets/images/android-icon-monochrome.png +0 -0
- package/dist/templates/default/apps/mobile/assets/images/icon.png +0 -0
- package/dist/templates/default/apps/mobile/assets/images/splash-icon.png +0 -0
- package/dist/templates/default/apps/mobile/eas.json +5 -0
- package/dist/templates/default/apps/mobile/package.json +18 -4
- package/dist/templates/default/apps/mobile/src/app/(auth)/_layout.tsx +1 -0
- package/dist/templates/default/apps/mobile/src/app/(auth)/login.tsx +1 -0
- package/dist/templates/default/apps/mobile/src/app/(auth)/signup.tsx +1 -0
- package/dist/templates/default/apps/mobile/src/app/(authenticated)/_layout.tsx +1 -0
- package/dist/templates/default/apps/mobile/src/app/(authenticated)/account.tsx +1 -0
- package/dist/templates/default/apps/mobile/src/app/_layout.tsx +1 -5
- package/dist/templates/default/apps/mobile/src/app/index.tsx +1 -17
- package/dist/templates/default/apps/mobile/tsconfig.json +8 -1
- package/dist/templates/default/apps/web/package.json +3 -2
- package/dist/templates/default/apps/web/src/routeTree.gen.ts +0 -44
- package/dist/templates/default/apps/web/src/router/__root.tsx +1 -1
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.api-keys.tsx +1 -1
- package/dist/templates/default/apps/web/src/router/_authenticated/dashboard.tsx +2 -1
- package/dist/templates/default/apps/web/src/router/index.tsx +11 -3
- package/dist/templates/default/apps/web/tests/auth-branches.test.tsx +44 -0
- package/dist/templates/default/apps/web/vite.config.ts +15 -0
- package/dist/templates/default/bun.lock +583 -23
- package/dist/templates/default/bunfig.toml +0 -2
- package/dist/templates/default/disposabl.json +2 -13
- package/dist/templates/default/package.json +3 -3
- package/dist/templates/default/packages/backend/AGENTS.md +15 -13
- package/dist/templates/default/packages/backend/README.md +6 -28
- package/dist/templates/default/packages/backend/convex/_generated/ai/ai-files.state.json +1 -1
- package/dist/templates/default/packages/backend/convex/_generated/api.d.ts +32 -6
- package/dist/templates/default/packages/backend/convex/_generated/server.d.ts +8 -0
- package/dist/templates/default/packages/backend/convex/apps/actions/create.ts +19 -0
- package/dist/templates/default/packages/backend/convex/apps/internal.ts +197 -0
- package/dist/templates/default/packages/backend/convex/auth.ts +1 -1
- package/dist/templates/default/packages/backend/convex/convex.config.ts +8 -0
- package/dist/templates/default/packages/backend/convex/github/actions/http.ts +40 -0
- package/dist/templates/default/packages/backend/convex/github/actions/internal.ts +189 -0
- package/dist/templates/default/packages/backend/convex/github/actions/oidc.ts +75 -0
- package/dist/templates/default/packages/backend/convex/github/actions/provision.ts +80 -0
- package/dist/templates/default/packages/backend/convex/github/actions/tokens.ts +66 -0
- package/dist/templates/default/packages/backend/convex/github/internal.ts +34 -0
- package/dist/templates/default/packages/backend/convex/http.ts +3 -0
- package/dist/templates/default/packages/backend/convex/previews/internal.ts +270 -0
- package/dist/templates/default/packages/backend/convex/previews/token/actions/create.ts +69 -0
- package/dist/templates/default/packages/backend/convex/previews/token/actions/management.ts +133 -0
- package/dist/templates/default/packages/backend/convex/previews/token/internal.ts +1 -0
- package/dist/templates/default/packages/backend/convex/releases/internal.ts +28 -0
- package/dist/templates/default/packages/backend/convex/schema.ts +34 -4
- package/dist/templates/default/packages/backend/convex/users/index.ts +21 -0
- package/dist/templates/default/packages/backend/convex/users/internal.ts +44 -0
- package/dist/templates/default/packages/backend/convex/validator.ts +87 -0
- package/dist/templates/default/packages/backend/generate.ts +6 -1
- package/dist/templates/default/packages/backend/generated/openapi.json +961 -43
- package/dist/templates/default/packages/backend/generated/pages.json +0 -8
- package/dist/templates/default/packages/backend/generated/platforms.ts +14 -2
- package/dist/templates/default/packages/backend/package.json +1 -1
- package/dist/templates/default/packages/cli/README.md +15 -9
- package/dist/templates/default/packages/cli/auth.ts +11 -3
- package/dist/templates/default/packages/cli/commands.ts +236 -0
- package/dist/templates/default/packages/cli/index.ts +2 -142
- package/dist/templates/default/packages/cli/preview.ts +157 -0
- package/dist/templates/default/packages/disposabl-kit/client/components/ui/log-out.tsx +16 -0
- package/dist/templates/default/packages/disposabl-kit/client/lib/prerender.ts +6 -3
- package/dist/templates/default/packages/disposabl-kit/client/routes/_auth-pages/login.tsx +1 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/_auth-pages/signUp.tsx +1 -1
- package/dist/templates/default/packages/disposabl-kit/client/routes/_authenticated/route.tsx +25 -16
- package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +3 -2
- package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +57 -2
- package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +20 -9
- package/dist/templates/default/packages/disposabl-kit/eslint.config.js +1 -1
- package/dist/templates/default/packages/disposabl-kit/features.ts +4 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-form.tsx +125 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/components/auth-ui.tsx +107 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +26 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +10 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +101 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/lib/auth-errors.ts +40 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/lib/auth-storage.ts +9 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/lib/convex.ts +1 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/lib/logo.png +0 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/screens/account.tsx +67 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/screens/home.tsx +65 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/screens/login.tsx +5 -0
- package/dist/templates/default/packages/disposabl-kit/mobile/screens/signup.tsx +5 -0
- package/dist/templates/default/packages/disposabl-kit/package.json +24 -1
- package/dist/templates/default/packages/disposabl-kit/platforms.ts +1 -27
- package/dist/templates/default/packages/disposabl-kit/server/http.ts +6 -0
- package/dist/templates/default/packages/disposabl-kit/server/lib/docs.test.ts +111 -0
- package/dist/templates/default/packages/disposabl-kit/server/lib/docs.ts +62 -0
- package/dist/templates/default/packages/disposabl-kit/tsconfig.json +1 -1
- package/dist/templates/default/packages/sdk/README.md +8 -4
- package/dist/templates/default/packages/sdk/src/config.ts +14 -7
- package/dist/templates/default/packages/sdk/src/generated/index.ts +48 -13
- package/dist/templates/default/packages/sdk/src/generated/sdk.gen.ts +139 -27
- package/dist/templates/default/packages/sdk/src/generated/types.gen.ts +440 -37
- package/dist/templates/default/turbo.json +7 -0
- package/package.json +6 -3
- package/dist/templates/default/.github/README.md +0 -99
- package/dist/templates/default/.github/actionlint.yaml +0 -6
- package/dist/templates/default/.github/workflows/pipeline.yml.example +0 -546
- package/dist/templates/default/apps/blog/package.json +0 -1
- package/dist/templates/default/apps/changelog/package.json +0 -1
- package/dist/templates/default/apps/desktop/.oxfmtrc.json +0 -5
- package/dist/templates/default/apps/desktop/.oxlintrc.json +0 -6
- package/dist/templates/default/apps/desktop/README.md +0 -88
- package/dist/templates/default/apps/desktop/build-ci.mjs +0 -56
- package/dist/templates/default/apps/desktop/forge.config.mts +0 -109
- package/dist/templates/default/apps/desktop/index.html +0 -12
- package/dist/templates/default/apps/desktop/package.json +0 -55
- package/dist/templates/default/apps/desktop/src/declarations.d.ts +0 -2
- package/dist/templates/default/apps/desktop/src/index.css +0 -8
- package/dist/templates/default/apps/desktop/src/main.ts +0 -58
- package/dist/templates/default/apps/desktop/src/preload.ts +0 -3
- package/dist/templates/default/apps/desktop/src/renderer.ts +0 -19
- package/dist/templates/default/apps/desktop/tsconfig.json +0 -14
- package/dist/templates/default/apps/desktop/vite.main.config.mts +0 -4
- package/dist/templates/default/apps/desktop/vite.preload.config.mts +0 -4
- package/dist/templates/default/apps/desktop/vite.renderer.config.mts +0 -4
- package/dist/templates/default/apps/web/src/router/_authenticated/todos/$id.tsx +0 -27
- package/dist/templates/default/apps/web/src/router/_authenticated/todos/index.tsx +0 -33
- package/dist/templates/default/packages/backend/convex/todos/index.ts +0 -26
- package/dist/templates/default/packages/backend/convex/todos/internal.ts +0 -43
- package/dist/templates/default/packages/backend/convex/users.ts +0 -20
|
@@ -1,3 +1,15 @@
|
|
|
1
1
|
// Generated by bun run generate. Do not edit.
|
|
2
|
-
import * as m0 from "../convex/
|
|
3
|
-
|
|
2
|
+
import * as m0 from "../convex/apps/internal";
|
|
3
|
+
import * as m1 from "../convex/github/internal";
|
|
4
|
+
import * as m2 from "../convex/previews/internal";
|
|
5
|
+
import * as m3 from "../convex/previews/token/internal";
|
|
6
|
+
import * as m4 from "../convex/releases/internal";
|
|
7
|
+
import * as m5 from "../convex/users/internal";
|
|
8
|
+
export default {
|
|
9
|
+
"apps/internal": m0,
|
|
10
|
+
"github/internal": m1,
|
|
11
|
+
"previews/internal": m2,
|
|
12
|
+
"previews/token/internal": m3,
|
|
13
|
+
"releases/internal": m4,
|
|
14
|
+
"users/internal": m5,
|
|
15
|
+
};
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
# Disposabl CLI
|
|
2
2
|
|
|
3
|
-
The CLI
|
|
3
|
+
The CLI connects to `https://disposabl.dev`.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
disposabl login status
|
|
7
|
+
disposabl login
|
|
8
|
+
disposabl apps create --name my-app --platforms '["web","android","api","mcp","cli","typescript-sdk"]'
|
|
9
|
+
disposabl apps list --paginationOpts '{"numItems":20,"cursor":null}'
|
|
10
|
+
disposabl apps get --appId <uuid>
|
|
11
|
+
disposabl previews token create --reference main --configure .
|
|
12
|
+
disposabl previews get
|
|
13
|
+
disposabl apps delete --appId <uuid>
|
|
14
|
+
disposabl logout
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
Save the returned app UUID as `appId` in `disposabl.json`. Preview commands read it automatically. `previews get` also reads the current Git branch; use `--reference` for a detached checkout or a custom worktree name. Token creation requires an explicit reference, reuses that preview, and issues a fresh development key. `--configure .` writes ignored local environment files without printing the key.
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
`login status` returns `currentUser`. `login --no-browser` prints the OAuth URL. The CLI owns PKCE, the loopback callback, refresh, and logout. The generator only invokes these commands.
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
Credentials live under `~/.config/disposabl` with restricted file permissions. `DISPOSABL_CONFIG_DIR` changes the local credential directory. `DISPOSABL_API_KEY` provides an automation credential. The service origin has no public override.
|
|
22
|
+
|
|
23
|
+
Use `--json` for machine-readable preview output. Other commands return JSON; `--help` lists their arguments.
|
|
@@ -21,6 +21,8 @@ import { homedir } from "node:os";
|
|
|
21
21
|
import { join } from "node:path";
|
|
22
22
|
import { spawn } from "node:child_process";
|
|
23
23
|
|
|
24
|
+
export class NotAuthenticated extends Error {}
|
|
25
|
+
|
|
24
26
|
type Session = {
|
|
25
27
|
client?: OAuthClientInformationMixed;
|
|
26
28
|
tokens?: OAuthTokens;
|
|
@@ -240,18 +242,19 @@ async function unlockedAccessToken(url: string, forceRefresh = false) {
|
|
|
240
242
|
if (process.env.DISPOSABL_API_KEY) return process.env.DISPOSABL_API_KEY;
|
|
241
243
|
const session = await load(url);
|
|
242
244
|
if (!session.tokens)
|
|
243
|
-
throw new
|
|
245
|
+
throw new NotAuthenticated("Run login first, or set DISPOSABL_API_KEY.");
|
|
244
246
|
if (
|
|
245
247
|
forceRefresh ||
|
|
246
248
|
!session.expiresAt ||
|
|
247
249
|
Date.now() >= session.expiresAt - 30_000
|
|
248
250
|
) {
|
|
249
251
|
const oauth = provider(url, session, () => {
|
|
250
|
-
throw new
|
|
252
|
+
throw new NotAuthenticated("Session expired. Run login again.");
|
|
251
253
|
});
|
|
252
254
|
await auth(oauth, { serverUrl: `${url}/mcp`, fetchFn: fetchFor(url) });
|
|
253
255
|
}
|
|
254
|
-
if (!session.tokens)
|
|
256
|
+
if (!session.tokens)
|
|
257
|
+
throw new NotAuthenticated("Session expired. Run login again.");
|
|
255
258
|
return session.tokens.access_token;
|
|
256
259
|
}
|
|
257
260
|
async function unlockedLogout(url: string) {
|
|
@@ -299,3 +302,8 @@ export const accessToken = (url: string, refresh = false) =>
|
|
|
299
302
|
withCredentials(url, () => unlockedAccessToken(url, refresh));
|
|
300
303
|
export const logout = (url: string) =>
|
|
301
304
|
withCredentials(url, () => unlockedLogout(url));
|
|
305
|
+
|
|
306
|
+
export const hasCredentials = async (url: string) =>
|
|
307
|
+
Boolean(
|
|
308
|
+
process.env.DISPOSABL_API_KEY || (await load(url)).tokens?.access_token,
|
|
309
|
+
);
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import manifest from "./package.json";
|
|
3
|
+
import {
|
|
4
|
+
NotAuthenticated,
|
|
5
|
+
accessToken,
|
|
6
|
+
apiUrl,
|
|
7
|
+
hasCredentials,
|
|
8
|
+
login,
|
|
9
|
+
logout,
|
|
10
|
+
} from "./auth";
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { execFileSync } from "node:child_process";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { configureDevelopment, formatPreview } from "./preview";
|
|
15
|
+
|
|
16
|
+
export const SERVICE_ORIGIN = "https://disposabl.dev";
|
|
17
|
+
export async function runCli(
|
|
18
|
+
argv = process.argv,
|
|
19
|
+
serviceOrigin = SERVICE_ORIGIN,
|
|
20
|
+
) {
|
|
21
|
+
type Schema = {
|
|
22
|
+
type?: string;
|
|
23
|
+
properties?: Record<string, Schema>;
|
|
24
|
+
required?: string[];
|
|
25
|
+
};
|
|
26
|
+
type Operation = {
|
|
27
|
+
operationId: string;
|
|
28
|
+
parameters?: {
|
|
29
|
+
name: string;
|
|
30
|
+
required?: boolean;
|
|
31
|
+
content: { "application/json": { schema: Schema } };
|
|
32
|
+
}[];
|
|
33
|
+
requestBody?: { content: { "application/json": { schema: Schema } } };
|
|
34
|
+
};
|
|
35
|
+
const program = new Command()
|
|
36
|
+
.name(Object.keys(manifest.bin)[0])
|
|
37
|
+
.version(manifest.version);
|
|
38
|
+
const origin = () => apiUrl(serviceOrigin);
|
|
39
|
+
const loginCommand = program
|
|
40
|
+
.command("login")
|
|
41
|
+
.option("--no-browser", "Print the login URL without opening a browser")
|
|
42
|
+
.action(async (options) => {
|
|
43
|
+
await login(origin(), options.browser);
|
|
44
|
+
console.error("Signed in.");
|
|
45
|
+
});
|
|
46
|
+
loginCommand
|
|
47
|
+
.command("status")
|
|
48
|
+
.description("Return the server-verified current user")
|
|
49
|
+
.action(async () => {
|
|
50
|
+
const base = origin();
|
|
51
|
+
if (!(await hasCredentials(base))) {
|
|
52
|
+
console.log(JSON.stringify({ currentUser: null }));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const send = async (refresh = false) =>
|
|
56
|
+
fetch(`${base}/api/users/current`, {
|
|
57
|
+
headers: {
|
|
58
|
+
Authorization: `Bearer ${await accessToken(base, refresh)}`,
|
|
59
|
+
},
|
|
60
|
+
redirect: "error",
|
|
61
|
+
signal: AbortSignal.timeout(30_000),
|
|
62
|
+
});
|
|
63
|
+
let response: Response;
|
|
64
|
+
try {
|
|
65
|
+
response = await send();
|
|
66
|
+
if (response.status === 401 && !process.env.DISPOSABL_API_KEY)
|
|
67
|
+
response = await send(true);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (!(error instanceof NotAuthenticated)) throw error;
|
|
70
|
+
console.log(JSON.stringify({ currentUser: null }));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (response.status === 401) {
|
|
74
|
+
console.log(JSON.stringify({ currentUser: null }));
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!response.ok)
|
|
78
|
+
throw new Error(`Login status failed (${response.status}).`);
|
|
79
|
+
console.log(JSON.stringify({ currentUser: await response.json() }));
|
|
80
|
+
});
|
|
81
|
+
program.command("logout").action(async () => {
|
|
82
|
+
await logout(origin());
|
|
83
|
+
console.error("Signed out.");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
async function main() {
|
|
87
|
+
// Help, version and login work without fetching the application contract.
|
|
88
|
+
const args = argv.slice(2);
|
|
89
|
+
const global = program.parseOptions(args);
|
|
90
|
+
const commandName = global.operands[0];
|
|
91
|
+
if (commandName && !["login", "logout", "help"].includes(commandName)) {
|
|
92
|
+
const base = origin();
|
|
93
|
+
const response = await fetch(`${base}/openapi.json`, {
|
|
94
|
+
redirect: "error",
|
|
95
|
+
signal: AbortSignal.timeout(30_000),
|
|
96
|
+
});
|
|
97
|
+
if (!response.ok)
|
|
98
|
+
throw new Error(`Could not load OpenAPI (${response.status}).`);
|
|
99
|
+
const spec = (await response.json()) as {
|
|
100
|
+
paths: Record<string, Record<string, Operation>>;
|
|
101
|
+
};
|
|
102
|
+
for (const [path, methods] of Object.entries(spec.paths)) {
|
|
103
|
+
if (
|
|
104
|
+
!path.startsWith("/api/") ||
|
|
105
|
+
path.includes("?") ||
|
|
106
|
+
path.includes("#")
|
|
107
|
+
)
|
|
108
|
+
throw new Error("Invalid API path in contract.");
|
|
109
|
+
for (const [method, operation] of Object.entries(methods)) {
|
|
110
|
+
if (!["get", "post"].includes(method)) continue;
|
|
111
|
+
const parts = path.slice(5).split("/");
|
|
112
|
+
let parent = program;
|
|
113
|
+
for (const part of parts.slice(0, -1))
|
|
114
|
+
parent =
|
|
115
|
+
parent.commands.find((command) => command.name() === part) ??
|
|
116
|
+
parent.command(part);
|
|
117
|
+
const command = parent.command(parts.at(-1)!);
|
|
118
|
+
const previewGet = path === "/api/previews/get";
|
|
119
|
+
const tokenCreate = path === "/api/previews/token/create";
|
|
120
|
+
if (previewGet)
|
|
121
|
+
command.option("--json", "Print the full preview as JSON");
|
|
122
|
+
if (tokenCreate)
|
|
123
|
+
command.option(
|
|
124
|
+
"--configure <directory>",
|
|
125
|
+
"Write local development environment files",
|
|
126
|
+
);
|
|
127
|
+
const schema =
|
|
128
|
+
operation.requestBody?.content["application/json"].schema;
|
|
129
|
+
const fields =
|
|
130
|
+
method === "get"
|
|
131
|
+
? (operation.parameters ?? []).map((p) => ({
|
|
132
|
+
name: p.name,
|
|
133
|
+
required: p.required,
|
|
134
|
+
schema: p.content["application/json"].schema,
|
|
135
|
+
}))
|
|
136
|
+
: Object.entries(schema?.properties ?? {}).map(
|
|
137
|
+
([name, value]) => ({
|
|
138
|
+
name,
|
|
139
|
+
required: schema?.required?.includes(name),
|
|
140
|
+
schema: value,
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
for (const field of fields) {
|
|
144
|
+
const flag = `--${field.name} <value>`;
|
|
145
|
+
if (
|
|
146
|
+
field.required &&
|
|
147
|
+
!(field.name === "appId" && (previewGet || tokenCreate)) &&
|
|
148
|
+
!(field.name === "reference" && previewGet)
|
|
149
|
+
)
|
|
150
|
+
command.requiredOption(
|
|
151
|
+
flag,
|
|
152
|
+
field.schema.type === "string"
|
|
153
|
+
? field.name
|
|
154
|
+
: `${field.name} as JSON`,
|
|
155
|
+
);
|
|
156
|
+
else command.option(flag, field.name);
|
|
157
|
+
}
|
|
158
|
+
command.action(async (options) => {
|
|
159
|
+
if ((previewGet || tokenCreate) && !options.appId) {
|
|
160
|
+
const config = JSON.parse(
|
|
161
|
+
await readFile(
|
|
162
|
+
join(options.configure ?? process.cwd(), "disposabl.json"),
|
|
163
|
+
"utf8",
|
|
164
|
+
),
|
|
165
|
+
);
|
|
166
|
+
if (!config.appId)
|
|
167
|
+
throw new Error(
|
|
168
|
+
"No appId in disposabl.json. Run setup or pass --appId.",
|
|
169
|
+
);
|
|
170
|
+
options.appId = config.appId;
|
|
171
|
+
}
|
|
172
|
+
if (previewGet && !options.reference) {
|
|
173
|
+
try {
|
|
174
|
+
options.reference = execFileSync(
|
|
175
|
+
"git",
|
|
176
|
+
["symbolic-ref", "--short", "HEAD"],
|
|
177
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] },
|
|
178
|
+
).trim();
|
|
179
|
+
} catch {
|
|
180
|
+
throw new Error(
|
|
181
|
+
"Cannot determine the Git branch. Supply --reference with the worktree or preview name.",
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const input = Object.fromEntries(
|
|
186
|
+
fields
|
|
187
|
+
.filter((field) => options[field.name] !== undefined)
|
|
188
|
+
.map((field) => [
|
|
189
|
+
field.name,
|
|
190
|
+
field.schema.type === "string"
|
|
191
|
+
? options[field.name]
|
|
192
|
+
: JSON.parse(options[field.name]),
|
|
193
|
+
]),
|
|
194
|
+
);
|
|
195
|
+
const target = new URL(path, base);
|
|
196
|
+
if (target.origin !== base || !target.pathname.startsWith("/api/"))
|
|
197
|
+
throw new Error("Invalid operation URL.");
|
|
198
|
+
if (method === "get")
|
|
199
|
+
for (const [name, value] of Object.entries(input))
|
|
200
|
+
target.searchParams.set(name, JSON.stringify(value));
|
|
201
|
+
const send = async (refresh = false) =>
|
|
202
|
+
fetch(target, {
|
|
203
|
+
method: method.toUpperCase(),
|
|
204
|
+
redirect: "error",
|
|
205
|
+
signal: AbortSignal.timeout(30_000),
|
|
206
|
+
headers: {
|
|
207
|
+
Authorization: `Bearer ${await accessToken(base, refresh)}`,
|
|
208
|
+
"Content-Type": "application/json",
|
|
209
|
+
},
|
|
210
|
+
body: method === "post" ? JSON.stringify(input) : undefined,
|
|
211
|
+
});
|
|
212
|
+
let result = await send();
|
|
213
|
+
if (result.status === 401 && !process.env.DISPOSABL_API_KEY)
|
|
214
|
+
result = await send(true);
|
|
215
|
+
if (!result.ok)
|
|
216
|
+
throw new Error(
|
|
217
|
+
`API request failed (${result.status}): ${await result.text()}`,
|
|
218
|
+
);
|
|
219
|
+
const value = await result.json();
|
|
220
|
+
if (tokenCreate && options.configure) {
|
|
221
|
+
await configureDevelopment(options.configure, value);
|
|
222
|
+
const { deployKey: _secret, ...details } = value;
|
|
223
|
+
console.log(
|
|
224
|
+
JSON.stringify({ ...details, configured: true }, null, 2),
|
|
225
|
+
);
|
|
226
|
+
} else if (previewGet && !options.json)
|
|
227
|
+
console.log(formatPreview(value));
|
|
228
|
+
else console.log(JSON.stringify(value, null, 2));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
await program.parseAsync(argv);
|
|
234
|
+
}
|
|
235
|
+
await main();
|
|
236
|
+
}
|
|
@@ -1,146 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
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) => {
|
|
2
|
+
import { runCli } from "./commands";
|
|
3
|
+
runCli().catch((error) => {
|
|
144
4
|
console.error(error instanceof Error ? error.message : "Command failed.");
|
|
145
5
|
process.exitCode = 1;
|
|
146
6
|
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
chmod,
|
|
3
|
+
lstat,
|
|
4
|
+
readFile,
|
|
5
|
+
rename,
|
|
6
|
+
writeFile,
|
|
7
|
+
rm,
|
|
8
|
+
} from "node:fs/promises";
|
|
9
|
+
import { join, resolve } from "node:path";
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
|
|
13
|
+
type Development = {
|
|
14
|
+
appId: string;
|
|
15
|
+
name: string;
|
|
16
|
+
reference: string;
|
|
17
|
+
convexUrl: string;
|
|
18
|
+
convexSiteUrl: string;
|
|
19
|
+
deployKey: string;
|
|
20
|
+
};
|
|
21
|
+
async function updateEnv(
|
|
22
|
+
file: string,
|
|
23
|
+
values: Record<string, string>,
|
|
24
|
+
remove: string[] = [],
|
|
25
|
+
) {
|
|
26
|
+
const stat = await lstat(file).catch((error) => {
|
|
27
|
+
if (error.code !== "ENOENT") throw error;
|
|
28
|
+
return undefined;
|
|
29
|
+
});
|
|
30
|
+
if (stat && (!stat.isFile() || stat.isSymbolicLink()))
|
|
31
|
+
throw new Error(`Refusing to replace non-regular file ${file}.`);
|
|
32
|
+
const text = stat ? await readFile(file, "utf8") : "";
|
|
33
|
+
const keys = new Set([...Object.keys(values), ...remove]);
|
|
34
|
+
const lines = text
|
|
35
|
+
.split("\n")
|
|
36
|
+
.filter(
|
|
37
|
+
(line) =>
|
|
38
|
+
!keys.has(/^\s*(?:export\s+)?([A-Z0-9_]+)\s*=/.exec(line)?.[1] ?? ""),
|
|
39
|
+
);
|
|
40
|
+
const next =
|
|
41
|
+
lines.join("\n").trimEnd() +
|
|
42
|
+
"\n" +
|
|
43
|
+
Object.entries(values)
|
|
44
|
+
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
|
|
45
|
+
.join("\n") +
|
|
46
|
+
"\n";
|
|
47
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
48
|
+
try {
|
|
49
|
+
await writeFile(temporary, next, { flag: "wx", mode: 0o600 });
|
|
50
|
+
await rename(temporary, file);
|
|
51
|
+
await chmod(file, 0o600);
|
|
52
|
+
} finally {
|
|
53
|
+
await rm(temporary, { force: true });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export async function configureDevelopment(
|
|
57
|
+
directory: string,
|
|
58
|
+
value: Development,
|
|
59
|
+
) {
|
|
60
|
+
const root = resolve(directory);
|
|
61
|
+
const config = JSON.parse(
|
|
62
|
+
await readFile(join(root, "disposabl.json"), "utf8"),
|
|
63
|
+
);
|
|
64
|
+
if (
|
|
65
|
+
config.appId !== value.appId ||
|
|
66
|
+
!value.deployKey.startsWith(`dev:${value.name}|`)
|
|
67
|
+
)
|
|
68
|
+
throw new Error("Development credentials do not match this app.");
|
|
69
|
+
if (
|
|
70
|
+
!/^[a-z0-9-]+$/.test(value.name) ||
|
|
71
|
+
value.convexUrl !== `https://${value.name}.convex.cloud` ||
|
|
72
|
+
value.convexSiteUrl !== `https://${value.name}.convex.site`
|
|
73
|
+
)
|
|
74
|
+
throw new Error("Development URLs do not match the deployment.");
|
|
75
|
+
const files = ["packages/backend/.env.local", "apps/web/.env.local"];
|
|
76
|
+
if (config.platforms.some((p: string) => p === "android" || p === "ios"))
|
|
77
|
+
files.push("apps/mobile/.env.local");
|
|
78
|
+
for (const file of files) {
|
|
79
|
+
const ignored = spawnSync("git", ["check-ignore", "--quiet", file], {
|
|
80
|
+
cwd: root,
|
|
81
|
+
stdio: "ignore",
|
|
82
|
+
});
|
|
83
|
+
const tracked = spawnSync("git", ["ls-files", "--error-unmatch", file], {
|
|
84
|
+
cwd: root,
|
|
85
|
+
stdio: "ignore",
|
|
86
|
+
});
|
|
87
|
+
if (ignored.status !== 0 || tracked.status !== 1)
|
|
88
|
+
throw new Error(`${file} must be untracked and ignored by Git.`);
|
|
89
|
+
}
|
|
90
|
+
await updateEnv(
|
|
91
|
+
join(root, files[0]!),
|
|
92
|
+
{
|
|
93
|
+
CONVEX_DEPLOY_KEY: value.deployKey,
|
|
94
|
+
CONVEX_URL: value.convexUrl,
|
|
95
|
+
CONVEX_SITE_URL: value.convexSiteUrl,
|
|
96
|
+
},
|
|
97
|
+
["CONVEX_DEPLOYMENT"],
|
|
98
|
+
);
|
|
99
|
+
await updateEnv(join(root, files[1]!), {
|
|
100
|
+
VITE_CONVEX_URL: value.convexUrl,
|
|
101
|
+
VITE_CONVEX_SITE_URL: value.convexSiteUrl,
|
|
102
|
+
});
|
|
103
|
+
if (files[2])
|
|
104
|
+
await updateEnv(join(root, files[2]), {
|
|
105
|
+
EXPO_PUBLIC_CONVEX_URL: value.convexUrl,
|
|
106
|
+
EXPO_PUBLIC_CONVEX_SITE_URL: value.convexSiteUrl,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
type Preview = {
|
|
111
|
+
reference: string;
|
|
112
|
+
stage?: string;
|
|
113
|
+
appId: string;
|
|
114
|
+
platforms: Record<
|
|
115
|
+
string,
|
|
116
|
+
{
|
|
117
|
+
enabled: boolean;
|
|
118
|
+
url?: string;
|
|
119
|
+
latest?: {
|
|
120
|
+
version?: string;
|
|
121
|
+
status: string;
|
|
122
|
+
githubReleaseUrl?: string | null;
|
|
123
|
+
artifactUrl?: string | null;
|
|
124
|
+
updateUrl?: string | null;
|
|
125
|
+
url?: string | null;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
>;
|
|
129
|
+
};
|
|
130
|
+
export function formatPreview(preview: Preview | null) {
|
|
131
|
+
if (!preview)
|
|
132
|
+
return "Preview not found. Create it with disposabl previews token create --reference <branch-or-worktree>.";
|
|
133
|
+
const lines = [
|
|
134
|
+
`Preview: ${preview.reference}`,
|
|
135
|
+
`App: ${preview.appId}`,
|
|
136
|
+
`Stage: ${preview.stage ?? "building"}`,
|
|
137
|
+
];
|
|
138
|
+
for (const [name, state] of Object.entries(preview.platforms)) {
|
|
139
|
+
if (!state.enabled) {
|
|
140
|
+
lines.push(`${name}: disabled`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const latest = state.latest;
|
|
144
|
+
lines.push(
|
|
145
|
+
`${name}: ${latest?.status ?? "not built"}${latest?.version ? ` (${latest.version})` : ["cli", "sdk"].includes(name) ? " (not published)" : ""}`,
|
|
146
|
+
);
|
|
147
|
+
for (const [label, url] of Object.entries({
|
|
148
|
+
URL: state.url,
|
|
149
|
+
Preview: latest?.url,
|
|
150
|
+
Release: latest?.githubReleaseUrl,
|
|
151
|
+
Download: latest?.artifactUrl,
|
|
152
|
+
Update: latest?.updateUrl,
|
|
153
|
+
}))
|
|
154
|
+
if (url) lines.push(` ${label}: ${url}`);
|
|
155
|
+
}
|
|
156
|
+
return lines.join("\n");
|
|
157
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useAuthActions } from "@convex-dev/auth/react";
|
|
2
|
+
|
|
3
|
+
export function LogOut() {
|
|
4
|
+
const { signOut } = useAuthActions();
|
|
5
|
+
return (
|
|
6
|
+
<button
|
|
7
|
+
type="button"
|
|
8
|
+
onClick={async () => {
|
|
9
|
+
await signOut();
|
|
10
|
+
window.location.assign("/");
|
|
11
|
+
}}
|
|
12
|
+
>
|
|
13
|
+
Log out
|
|
14
|
+
</button>
|
|
15
|
+
);
|
|
16
|
+
}
|