@rebasepro/cli 0.0.1-canary.4d4fb3e → 0.0.1-canary.ca2cb6e

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 (35) hide show
  1. package/dist/commands/cli.test.d.ts +1 -0
  2. package/dist/commands/dev.test.d.ts +1 -0
  3. package/dist/commands/doctor.d.ts +1 -0
  4. package/dist/commands/generate_sdk.d.ts +1 -1
  5. package/dist/commands/init.test.d.ts +1 -0
  6. package/dist/index.cjs +188 -62
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.es.js +188 -62
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/utils/project.test.d.ts +1 -0
  11. package/package.json +67 -66
  12. package/templates/template/.env.template +22 -1
  13. package/templates/template/README.md +2 -2
  14. package/templates/template/backend/Dockerfile +6 -6
  15. package/templates/template/backend/functions/hello.ts +24 -6
  16. package/templates/template/backend/package.json +2 -2
  17. package/templates/template/backend/src/env.ts +52 -0
  18. package/templates/template/backend/src/index.ts +86 -34
  19. package/templates/template/backend/tsconfig.json +1 -1
  20. package/templates/template/config/collections/authors.ts +45 -0
  21. package/templates/template/config/collections/index.ts +5 -0
  22. package/templates/template/{shared → config}/collections/posts.ts +39 -1
  23. package/templates/template/config/collections/tags.ts +27 -0
  24. package/templates/template/{shared → config}/package.json +1 -1
  25. package/templates/template/docker-compose.yml +12 -0
  26. package/templates/template/frontend/Dockerfile +3 -3
  27. package/templates/template/frontend/package.json +2 -2
  28. package/templates/template/frontend/src/App.tsx +11 -12
  29. package/templates/template/frontend/src/main.tsx +2 -2
  30. package/templates/template/frontend/vite.config.ts +1 -1
  31. package/templates/template/pnpm-workspace.yaml +1 -1
  32. package/templates/template/scripts/example.ts +91 -0
  33. package/templates/template/shared/collections/index.ts +0 -3
  34. /package/templates/template/{shared → config}/index.ts +0 -0
  35. /package/templates/template/{shared → config}/tsconfig.json +0 -0
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Example Rebase Script
3
+ *
4
+ * Scripts run OUTSIDE the server and need explicit authentication.
5
+ * Use a Service Key (set in .env as REBASE_SERVICE_KEY) to get admin
6
+ * access — similar to a Firebase Service Account credential.
7
+ *
8
+ * Usage:
9
+ * # With local dev server running (`pnpm dev` in another terminal):
10
+ * npx tsx scripts/example.ts
11
+ *
12
+ * # With remote backend:
13
+ * REBASE_URL=https://api.yourdomain.com npx tsx scripts/example.ts
14
+ *
15
+ * # Service key can also be passed as env var:
16
+ * REBASE_SERVICE_KEY=<key> REBASE_URL=https://api.yourdomain.com npx tsx scripts/example.ts
17
+ *
18
+ * Generate a service key:
19
+ * node -e "console.log(require('crypto').randomBytes(48).toString('base64'))"
20
+ */
21
+
22
+ import fs from "node:fs";
23
+ import path from "node:path";
24
+ import * as dotenv from "dotenv";
25
+ import { createRebaseClient } from "@rebasepro/client";
26
+ // import type { Database } from "../config/database.types"; // Optional: For fully typed collections
27
+
28
+ // Load .env from project root (same file the backend uses)
29
+ dotenv.config({ path: path.resolve(process.cwd(), ".env") });
30
+
31
+ // ─── Resolve Backend URL ─────────────────────────────────────────────
32
+ let baseUrl = process.env.REBASE_URL;
33
+
34
+ if (!baseUrl) {
35
+ try {
36
+ // Try to read the URL from the local dev server
37
+ const urlFile = path.join(process.cwd(), ".rebase-dev-url");
38
+ if (fs.existsSync(urlFile)) {
39
+ baseUrl = fs.readFileSync(urlFile, "utf-8").trim();
40
+ console.log(`Found local dev server running at: ${baseUrl}`);
41
+ }
42
+ } catch (e) {
43
+ // Ignore errors reading the file
44
+ }
45
+ }
46
+
47
+ if (!baseUrl) {
48
+ console.error("❌ No backend URL found!");
49
+ console.error("");
50
+ console.error("Please make sure you have either:");
51
+ console.error("1. Started the local dev server in another terminal (`pnpm dev`)");
52
+ console.error("2. Set the REBASE_URL environment variable (e.g. `REBASE_URL=https://api.yourdomain.com npx tsx scripts/example.ts`)");
53
+ process.exit(1);
54
+ }
55
+
56
+ // ─── Resolve Service Key ─────────────────────────────────────────────
57
+ const serviceKey = process.env.REBASE_SERVICE_KEY;
58
+
59
+ if (!serviceKey) {
60
+ console.warn("⚠️ No REBASE_SERVICE_KEY found — requests will be unauthenticated.");
61
+ console.warn(" Set REBASE_SERVICE_KEY in your .env to get admin access.");
62
+ console.warn(" Generate one with: node -e \"console.log(require('crypto').randomBytes(48).toString('base64'))\"");
63
+ console.warn("");
64
+ }
65
+
66
+ // ─── Initialize the SDK client ───────────────────────────────────────
67
+ const rebase = createRebaseClient({
68
+ baseUrl,
69
+ // The service key is sent as a Bearer token for admin access
70
+ token: serviceKey
71
+ });
72
+
73
+ async function run() {
74
+ console.log("🚀 Starting script...");
75
+
76
+ try {
77
+ // Example: Check backend health
78
+ const health = await fetch(`${baseUrl}/api/health`).then(res => res.json());
79
+ console.log("✅ Backend health:", health);
80
+
81
+ // Example: Fetch some data (requires auth if backend is secure-by-default)
82
+ // const items = await rebase.data.collection("users").find({ limit: 5 });
83
+ // console.log("Items:", items);
84
+
85
+ console.log("✨ Script finished successfully.");
86
+ } catch (error) {
87
+ console.error("❌ Script failed:", error);
88
+ }
89
+ }
90
+
91
+ run();
@@ -1,3 +0,0 @@
1
- import postsCollection from "./posts";
2
-
3
- export const collections = [postsCollection];
File without changes