robodev 0.2.0 → 0.2.2
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/package.json +1 -1
- package/src/api.ts +1 -0
- package/src/config.ts +5 -0
- package/src/index.ts +4 -0
- package/template/README.md +3 -1
- package/template/api/health.ts +2 -1
- package/template/api/launch.ts +2 -1
- package/template/api/planets.ts +2 -1
- package/template/api/rockets.ts +2 -1
- package/template/database.ts +5 -1
- package/template/package.json +1 -1
- package/template/src/main.tsx +1 -0
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -55,6 +55,7 @@ async function refresh(refreshToken: string): Promise<Credentials | null> {
|
|
|
55
55
|
return (await res.json()) as Credentials;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** Authenticated Starbase request. Reads `~/.robodev/credentials.json` and refreshes on 401. */
|
|
58
59
|
export async function authed<T>(path: string, init: RequestInit = {}): Promise<T> {
|
|
59
60
|
const credentials = await readCredentials();
|
|
60
61
|
if (!credentials) {
|
package/src/config.ts
CHANGED
|
@@ -15,18 +15,22 @@ export type ProjectLink = {
|
|
|
15
15
|
|
|
16
16
|
const PROD_URL = "https://robodev.povio.dev";
|
|
17
17
|
|
|
18
|
+
/** Control-plane API. Override with `STARBASE_URL` for local Starbase. */
|
|
18
19
|
export function starbaseUrl(): string {
|
|
19
20
|
return (process.env.STARBASE_URL ?? PROD_URL).replace(/\/$/, "");
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
/** Browser UI used for OAuth. Override with `STARBASE_FE_URL`. */
|
|
22
24
|
export function feUrl(): string {
|
|
23
25
|
return (process.env.STARBASE_FE_URL ?? process.env.STARBASE_URL ?? PROD_URL).replace(/\/$/, "");
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
/** `~/.robodev/credentials.json` — tokens from `robodev auth`. */
|
|
26
29
|
export function credentialsPath(): string {
|
|
27
30
|
return join(homedir(), ".robodev", "credentials.json");
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
/** Project link file written by `create` / `link`. */
|
|
30
34
|
export function linkPath(cwd = process.cwd()): string {
|
|
31
35
|
return join(cwd, ".robodev");
|
|
32
36
|
}
|
|
@@ -61,6 +65,7 @@ export async function writeLink(link: ProjectLink, cwd = process.cwd()): Promise
|
|
|
61
65
|
await writeFile(linkPath(cwd), `${JSON.stringify(link, null, 2)}\n`);
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
/** Sets `VITE_API_URL` so the starter UI talks to the deployed project host. */
|
|
64
69
|
export async function writeViteApiUrl(projectApiUrl: string, cwd = process.cwd()): Promise<void> {
|
|
65
70
|
const envPath = join(cwd, ".env");
|
|
66
71
|
let content = "";
|
package/src/index.ts
CHANGED
|
@@ -55,6 +55,7 @@ function prompt(question: string): Promise<string> {
|
|
|
55
55
|
return rl.question(question).finally(() => rl.close());
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** Local loopback server that completes the browser OAuth handshake for `robodev auth`. */
|
|
58
59
|
async function waitForOauthCode(): Promise<{ code: string; redirectUri: string }> {
|
|
59
60
|
const state = randomBytes(16).toString("hex");
|
|
60
61
|
return new Promise((resolve, reject) => {
|
|
@@ -184,6 +185,7 @@ async function runLink(projectId?: string): Promise<void> {
|
|
|
184
185
|
console.log(`Frontend API ${project.apiUrl}`);
|
|
185
186
|
}
|
|
186
187
|
|
|
188
|
+
/** Collects `database.ts` plus every TypeScript file under `api/` for a deploy upload. */
|
|
187
189
|
async function collectFiles(root: string): Promise<{ path: string; content: string }[]> {
|
|
188
190
|
const files: { path: string; content: string }[] = [];
|
|
189
191
|
const database = join(root, "database.ts");
|
|
@@ -220,6 +222,7 @@ async function collectFiles(root: string): Promise<{ path: string; content: stri
|
|
|
220
222
|
return files;
|
|
221
223
|
}
|
|
222
224
|
|
|
225
|
+
/** Uploads schema + APIs. Destructive schema changes need confirmation or `--force`. */
|
|
223
226
|
async function runDeploy(forceFlag: boolean, root = process.cwd()): Promise<void> {
|
|
224
227
|
const link = await readLink(root);
|
|
225
228
|
if (!link) {
|
|
@@ -356,6 +359,7 @@ async function npmInstall(root: string): Promise<void> {
|
|
|
356
359
|
});
|
|
357
360
|
}
|
|
358
361
|
|
|
362
|
+
/** Creates a Starbase project, copies the starter template, links, deploys, and installs deps. */
|
|
359
363
|
async function runCreate(pathArg?: string): Promise<void> {
|
|
360
364
|
const root = resolve(process.cwd(), pathArg ?? ".");
|
|
361
365
|
await mkdir(root, { recursive: true });
|
package/template/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# {{NAME}}
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Starter app from `robodev create`: a `space` database (`planets`, `rockets`), file-based APIs in `api/`, and a small React UI.
|
|
4
4
|
|
|
5
5
|
The backend is already on Starbase. Run the frontend:
|
|
6
6
|
|
|
@@ -10,6 +10,8 @@ npm run dev
|
|
|
10
10
|
|
|
11
11
|
It reads `VITE_API_URL` from `.env` (written by `robodev create` / `robodev link`).
|
|
12
12
|
|
|
13
|
+
Docs: https://robodev.povio.dev/docs
|
|
14
|
+
|
|
13
15
|
Add tables in `database.ts` and routes as `api/<name>.ts`, then:
|
|
14
16
|
|
|
15
17
|
```bash
|
package/template/api/health.ts
CHANGED
package/template/api/launch.ts
CHANGED
package/template/api/planets.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/** GET/POST /planets — list (seeds sample rows on first GET) and create planets. */
|
|
1
2
|
import { planets, rockets } from "../database";
|
|
2
|
-
import { defineApi, z } from "robodev-
|
|
3
|
+
import { defineApi, z } from "@robodev-ai/sdk";
|
|
3
4
|
|
|
4
5
|
const EARTH = "11111111-1111-1111-1111-111111111111";
|
|
5
6
|
const MARS = "22222222-2222-2222-2222-222222222222";
|
package/template/api/rockets.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/** GET/POST /rockets — list (optional `?destinationId=`) and create rockets. */
|
|
1
2
|
import { rockets } from "../database";
|
|
2
|
-
import { defineApi, eq, z } from "robodev-
|
|
3
|
+
import { defineApi, eq, z } from "@robodev-ai/sdk";
|
|
3
4
|
|
|
4
5
|
const Rocket = z.object({
|
|
5
6
|
id: z.string(),
|
package/template/database.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Starter schema. `robodev deploy` creates the `space` database and these tables
|
|
3
|
+
* (no migration files). Edit here and deploy again to sync.
|
|
4
|
+
*/
|
|
5
|
+
import { boolean, defineDatabase, integer, pgTable, text, timestamp, uuid } from "@robodev-ai/sdk";
|
|
2
6
|
|
|
3
7
|
export const planets = pgTable("planets", {
|
|
4
8
|
id: uuid("id").primaryKey().defaultRandom(),
|
package/template/package.json
CHANGED
package/template/src/main.tsx
CHANGED