clefbase 1.1.6 → 1.2.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.
Files changed (43) hide show
  1. package/README.md +169 -103
  2. package/bin/clefbase.js +15 -0
  3. package/dist/app.d.ts +16 -32
  4. package/dist/app.d.ts.map +1 -1
  5. package/dist/app.js +29 -44
  6. package/dist/app.js.map +1 -1
  7. package/dist/auth/index.d.ts +16 -44
  8. package/dist/auth/index.d.ts.map +1 -1
  9. package/dist/auth/index.js +40 -95
  10. package/dist/auth/index.js.map +1 -1
  11. package/dist/cli-src/cli/api.js +170 -0
  12. package/dist/cli-src/cli/commands/deploy.js +285 -0
  13. package/dist/cli-src/cli/commands/info.js +67 -0
  14. package/dist/cli-src/cli/commands/init.js +226 -0
  15. package/dist/cli-src/cli/config.js +82 -0
  16. package/dist/cli-src/cli/index.js +110 -0
  17. package/dist/cli-src/types.js +17 -0
  18. package/dist/cli.js +34375 -0
  19. package/dist/db/index.d.ts +26 -62
  20. package/dist/db/index.d.ts.map +1 -1
  21. package/dist/db/index.js +34 -70
  22. package/dist/db/index.js.map +1 -1
  23. package/dist/hosting/index.d.ts +123 -0
  24. package/dist/hosting/index.d.ts.map +1 -0
  25. package/dist/hosting/index.js +202 -0
  26. package/dist/hosting/index.js.map +1 -0
  27. package/dist/http.d.ts +2 -4
  28. package/dist/http.d.ts.map +1 -1
  29. package/dist/http.js +8 -22
  30. package/dist/http.js.map +1 -1
  31. package/dist/index.d.ts +11 -7
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +13 -6
  34. package/dist/index.js.map +1 -1
  35. package/dist/storage/index.d.ts +8 -50
  36. package/dist/storage/index.d.ts.map +1 -1
  37. package/dist/storage/index.js +9 -59
  38. package/dist/storage/index.js.map +1 -1
  39. package/dist/types.d.ts +10 -4
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/types.js +0 -1
  42. package/dist/types.js.map +1 -1
  43. package/package.json +21 -5
@@ -5,17 +5,10 @@ type AuthStateCallback = (user: AuthUser | null) => void;
5
5
  * Authentication service. Obtain via `getAuth(app)`.
6
6
  *
7
7
  * @example
8
- * import { initClefbase, getAuth } from "clefbase";
9
- * const app = initClefbase({ serverUrl, projectId, apiKey });
10
8
  * const auth = getAuth(app);
11
- *
12
- * const { user } = await auth.signUp("alice@example.com", "secret123");
13
- * const { user } = await auth.signIn("alice@example.com", "secret123");
14
- * console.log(auth.currentUser);
15
- * await auth.signOut();
16
- *
17
- * const unsub = auth.onAuthStateChanged((u) => console.log(u));
18
- * unsub(); // stop listening
9
+ * const { user } = await auth.signIn("alice@example.com", "pass");
10
+ * const unsub = auth.onAuthStateChanged(u => console.log(u));
11
+ * unsub();
19
12
  */
20
13
  export declare class Auth {
21
14
  private readonly http;
@@ -24,14 +17,14 @@ export declare class Auth {
24
17
  constructor(http: HttpClient);
25
18
  private notify;
26
19
  private handleResult;
27
- /** @internal Used by Storage to attach the auth token to upload requests. */
20
+ /** @internal used by Storage to attach the bearer token to upload requests */
28
21
  getAuthHeaders(): Record<string, string>;
29
- /** The currently signed-in user, or null if no session exists. */
22
+ /** The currently signed-in user, or null. */
30
23
  get currentUser(): AuthUser | null;
31
24
  /** The raw bearer token for the active session, or null. */
32
25
  get currentToken(): string | null;
33
26
  /**
34
- * Create a new account with email + password.
27
+ * Create a new account.
35
28
  *
36
29
  * @example
37
30
  * const { user } = await auth.signUp("alice@example.com", "pass123", {
@@ -48,17 +41,12 @@ export declare class Auth {
48
41
  * Sign in with email + password.
49
42
  *
50
43
  * @example
51
- * const { user, token } = await auth.signIn("alice@example.com", "pass123");
44
+ * const { user, token } = await auth.signIn("alice@example.com", "pass");
52
45
  */
53
46
  signIn(email: string, password: string): Promise<AuthResult>;
54
- /**
55
- * Sign out the current user and clear the local session.
56
- */
47
+ /** Sign out and clear the local session. */
57
48
  signOut(): Promise<void>;
58
- /**
59
- * Re-fetch the current user's profile from the server and update the cache.
60
- * Useful after an admin changes the user's data server-side.
61
- */
49
+ /** Re-fetch the current user's profile from the server and update the cache. */
62
50
  refreshCurrentUser(): Promise<AuthUser | null>;
63
51
  /**
64
52
  * Update the signed-in user's profile.
@@ -71,42 +59,26 @@ export declare class Auth {
71
59
  photoUrl?: string;
72
60
  metadata?: Record<string, unknown>;
73
61
  }): Promise<AuthUser>;
74
- /**
75
- * Change the signed-in user's password.
76
- * All other active sessions are invalidated on the server.
77
- */
62
+ /** Change password. All other sessions are invalidated server-side. */
78
63
  changePassword(currentPassword: string, newPassword: string): Promise<void>;
79
- /**
80
- * Request a password-reset email. Safe to call even if the address
81
- * is not registered (server returns the same response either way).
82
- */
64
+ /** Request a password-reset email. Safe to call even for unregistered addresses. */
83
65
  sendPasswordResetEmail(email: string): Promise<void>;
84
- /**
85
- * Complete a password reset with the token from the reset email.
86
- */
66
+ /** Complete a password reset with the token from the reset email. */
87
67
  confirmPasswordReset(resetToken: string, newPassword: string): Promise<void>;
88
- /**
89
- * Send an email verification code to the currently signed-in user.
90
- */
68
+ /** Send an email verification code to the currently signed-in user. */
91
69
  sendEmailVerification(): Promise<void>;
92
- /**
93
- * Verify the current user's email with the code they received.
94
- *
95
- * @example
96
- * const user = await auth.verifyEmail("ABC123");
97
- */
70
+ /** Verify email with the code the user received. */
98
71
  verifyEmail(code: string): Promise<AuthUser>;
99
72
  /**
100
73
  * Subscribe to auth state changes.
101
- * The callback fires immediately with the current user, then on every change.
74
+ * Fires immediately with the current user, then on every change.
102
75
  * Returns an unsubscribe function.
103
76
  *
104
77
  * @example
105
- * const unsubscribe = auth.onAuthStateChanged((user) => {
78
+ * const unsubscribe = auth.onAuthStateChanged(user => {
106
79
  * if (user) console.log("signed in:", user.email);
107
80
  * else console.log("signed out");
108
81
  * });
109
- * // Later:
110
82
  * unsubscribe();
111
83
  */
112
84
  onAuthStateChanged(callback: AuthStateCallback): () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AA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O,CAAC,IAAI,CAAC;IAM5C,oDAAoD;IAC9C,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIlD;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,IAAI;CAO5D"}
@@ -1,14 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Auth = void 0;
4
- /**
5
- * Stores the session in memory and optionally in localStorage (browser).
6
- * On Node.js localStorage is not available so only in-memory is used.
7
- */
8
4
  class SessionStore {
9
5
  constructor() {
10
6
  this.session = null;
11
- this.STORAGE_KEY = "cfb_session";
7
+ this.KEY = "cfb_session";
12
8
  }
13
9
  get ls() {
14
10
  try {
@@ -21,32 +17,31 @@ class SessionStore {
21
17
  save(s) {
22
18
  this.session = s;
23
19
  try {
24
- this.ls?.setItem(this.STORAGE_KEY, JSON.stringify(s));
20
+ this.ls?.setItem(this.KEY, JSON.stringify(s));
25
21
  }
26
- catch { /* quota exceeded or private mode */ }
22
+ catch { /* quota / private mode */ }
27
23
  }
28
24
  load() {
29
25
  if (this.session)
30
26
  return this.session;
31
27
  try {
32
- const raw = this.ls?.getItem(this.STORAGE_KEY);
28
+ const raw = this.ls?.getItem(this.KEY);
33
29
  if (raw) {
34
30
  const parsed = JSON.parse(raw);
35
31
  if (new Date(parsed.expiresAt) > new Date()) {
36
32
  this.session = parsed;
37
33
  return this.session;
38
34
  }
39
- // Expired — clean up
40
- this.ls?.removeItem(this.STORAGE_KEY);
35
+ this.ls?.removeItem(this.KEY);
41
36
  }
42
37
  }
43
- catch { /* corrupted data */ }
38
+ catch { /* corrupted */ }
44
39
  return null;
45
40
  }
46
41
  clear() {
47
42
  this.session = null;
48
43
  try {
49
- this.ls?.removeItem(this.STORAGE_KEY);
44
+ this.ls?.removeItem(this.KEY);
50
45
  }
51
46
  catch { /* ignore */ }
52
47
  }
@@ -55,33 +50,26 @@ class SessionStore {
55
50
  * Authentication service. Obtain via `getAuth(app)`.
56
51
  *
57
52
  * @example
58
- * import { initClefbase, getAuth } from "clefbase";
59
- * const app = initClefbase({ serverUrl, projectId, apiKey });
60
53
  * const auth = getAuth(app);
61
- *
62
- * const { user } = await auth.signUp("alice@example.com", "secret123");
63
- * const { user } = await auth.signIn("alice@example.com", "secret123");
64
- * console.log(auth.currentUser);
65
- * await auth.signOut();
66
- *
67
- * const unsub = auth.onAuthStateChanged((u) => console.log(u));
68
- * unsub(); // stop listening
54
+ * const { user } = await auth.signIn("alice@example.com", "pass");
55
+ * const unsub = auth.onAuthStateChanged(u => console.log(u));
56
+ * unsub();
69
57
  */
70
58
  class Auth {
71
59
  constructor(http) {
72
60
  this.http = http;
73
61
  this.store = new SessionStore();
74
62
  this.listeners = [];
75
- // Attempt to restore a persisted session on startup
63
+ // Restore any persisted session on startup
76
64
  this.store.load();
77
65
  }
78
- // ─── Internal ──────────────────────────────────────────────────────────────
66
+ // ── Internals ─────────────────────────────────────────────────────────────
79
67
  notify(user) {
80
68
  for (const cb of this.listeners) {
81
69
  try {
82
70
  cb(user);
83
71
  }
84
- catch { /* don't let a listener crash the SDK */ }
72
+ catch { /* never let a listener crash the SDK */ }
85
73
  }
86
74
  }
87
75
  handleResult(result) {
@@ -93,22 +81,18 @@ class Auth {
93
81
  this.notify(result.user);
94
82
  return result;
95
83
  }
96
- /** @internal Used by Storage to attach the auth token to upload requests. */
84
+ /** @internal used by Storage to attach the bearer token to upload requests */
97
85
  getAuthHeaders() {
98
- const session = this.store.load();
99
- return session ? { Authorization: `Bearer ${session.token}` } : {};
100
- }
101
- // ─── Public API ─────────────────────────────────────────────────────────────
102
- /** The currently signed-in user, or null if no session exists. */
103
- get currentUser() {
104
- return this.store.load()?.user ?? null;
86
+ const s = this.store.load();
87
+ return s ? { Authorization: `Bearer ${s.token}` } : {};
105
88
  }
89
+ // ── Public API ────────────────────────────────────────────────────────────
90
+ /** The currently signed-in user, or null. */
91
+ get currentUser() { return this.store.load()?.user ?? null; }
106
92
  /** The raw bearer token for the active session, or null. */
107
- get currentToken() {
108
- return this.store.load()?.token ?? null;
109
- }
93
+ get currentToken() { return this.store.load()?.token ?? null; }
110
94
  /**
111
- * Create a new account with email + password.
95
+ * Create a new account.
112
96
  *
113
97
  * @example
114
98
  * const { user } = await auth.signUp("alice@example.com", "pass123", {
@@ -117,11 +101,8 @@ class Auth {
117
101
  * });
118
102
  */
119
103
  async signUp(email, password, profile) {
120
- // base is serverUrl/auth → path is /signup → full: serverUrl/auth/signup
121
104
  const result = await this.http.post("/signup", {
122
- email,
123
- password,
124
- ...profile,
105
+ email, password, ...profile,
125
106
  });
126
107
  return this.handleResult(result);
127
108
  }
@@ -129,45 +110,31 @@ class Auth {
129
110
  * Sign in with email + password.
130
111
  *
131
112
  * @example
132
- * const { user, token } = await auth.signIn("alice@example.com", "pass123");
113
+ * const { user, token } = await auth.signIn("alice@example.com", "pass");
133
114
  */
134
115
  async signIn(email, password) {
135
- const result = await this.http.post("/signin", {
136
- email,
137
- password,
138
- });
116
+ const result = await this.http.post("/signin", { email, password });
139
117
  return this.handleResult(result);
140
118
  }
141
- /**
142
- * Sign out the current user and clear the local session.
143
- */
119
+ /** Sign out and clear the local session. */
144
120
  async signOut() {
145
121
  const token = this.currentToken;
146
122
  if (token) {
147
123
  try {
148
- await this.http.post("/signout", undefined, {
149
- Authorization: `Bearer ${token}`,
150
- });
151
- }
152
- catch {
153
- // Always clear locally even if the server call fails
124
+ await this.http.post("/signout", undefined, { Authorization: `Bearer ${token}` });
154
125
  }
126
+ catch { /* always clear locally */ }
155
127
  }
156
128
  this.store.clear();
157
129
  this.notify(null);
158
130
  }
159
- /**
160
- * Re-fetch the current user's profile from the server and update the cache.
161
- * Useful after an admin changes the user's data server-side.
162
- */
131
+ /** Re-fetch the current user's profile from the server and update the cache. */
163
132
  async refreshCurrentUser() {
164
133
  const token = this.currentToken;
165
134
  if (!token)
166
135
  return null;
167
136
  try {
168
- const user = await this.http.get("/me", {
169
- Authorization: `Bearer ${token}`,
170
- });
137
+ const user = await this.http.get("/me", { Authorization: `Bearer ${token}` });
171
138
  const session = this.store.load();
172
139
  if (session)
173
140
  this.store.save({ ...session, user });
@@ -197,74 +164,52 @@ class Auth {
197
164
  this.notify(user);
198
165
  return user;
199
166
  }
200
- /**
201
- * Change the signed-in user's password.
202
- * All other active sessions are invalidated on the server.
203
- */
167
+ /** Change password. All other sessions are invalidated server-side. */
204
168
  async changePassword(currentPassword, newPassword) {
205
169
  const token = this.currentToken;
206
170
  if (!token)
207
171
  throw new Error("No user is currently signed in.");
208
172
  await this.http.post("/change-password", { currentPassword, newPassword }, { Authorization: `Bearer ${token}` });
209
173
  }
210
- /**
211
- * Request a password-reset email. Safe to call even if the address
212
- * is not registered (server returns the same response either way).
213
- */
174
+ /** Request a password-reset email. Safe to call even for unregistered addresses. */
214
175
  async sendPasswordResetEmail(email) {
215
176
  await this.http.post("/forgot-password", { email });
216
177
  }
217
- /**
218
- * Complete a password reset with the token from the reset email.
219
- */
178
+ /** Complete a password reset with the token from the reset email. */
220
179
  async confirmPasswordReset(resetToken, newPassword) {
221
- await this.http.post("/reset-password", {
222
- token: resetToken,
223
- newPassword,
224
- });
180
+ await this.http.post("/reset-password", { token: resetToken, newPassword });
225
181
  }
226
- /**
227
- * Send an email verification code to the currently signed-in user.
228
- */
182
+ /** Send an email verification code to the currently signed-in user. */
229
183
  async sendEmailVerification() {
230
184
  const token = this.currentToken;
231
185
  if (!token)
232
186
  throw new Error("No user is currently signed in.");
233
- await this.http.post("/send-verification", undefined, {
234
- Authorization: `Bearer ${token}`,
235
- });
187
+ await this.http.post("/send-verification", undefined, { Authorization: `Bearer ${token}` });
236
188
  }
237
- /**
238
- * Verify the current user's email with the code they received.
239
- *
240
- * @example
241
- * const user = await auth.verifyEmail("ABC123");
242
- */
189
+ /** Verify email with the code the user received. */
243
190
  async verifyEmail(code) {
244
191
  return this.http.post("/verify-email", { code });
245
192
  }
246
193
  /**
247
194
  * Subscribe to auth state changes.
248
- * The callback fires immediately with the current user, then on every change.
195
+ * Fires immediately with the current user, then on every change.
249
196
  * Returns an unsubscribe function.
250
197
  *
251
198
  * @example
252
- * const unsubscribe = auth.onAuthStateChanged((user) => {
199
+ * const unsubscribe = auth.onAuthStateChanged(user => {
253
200
  * if (user) console.log("signed in:", user.email);
254
201
  * else console.log("signed out");
255
202
  * });
256
- * // Later:
257
203
  * unsubscribe();
258
204
  */
259
205
  onAuthStateChanged(callback) {
260
206
  this.listeners.push(callback);
261
- // Emit the current state immediately
262
207
  try {
263
208
  callback(this.currentUser);
264
209
  }
265
- catch { /* don't crash on listener error */ }
210
+ catch { /* ignore */ }
266
211
  return () => {
267
- this.listeners = this.listeners.filter((cb) => cb !== callback);
212
+ this.listeners = this.listeners.filter(cb => cb !== callback);
268
213
  };
269
214
  }
270
215
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;AAWA;;;GAGG;AACH,MAAM,YAAY;IAAlB;QACU,YAAO,GAA4B,IAAI,CAAC;QAC/B,gBAAW,GAAG,aAAa,CAAC;IAwC/C,CAAC;IAtCC,IAAY,EAAE;QACZ,IAAI,CAAC;YACH,OAAO,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;QACnE,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,IAAI,CAAC,CAAmB;QACtB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACxD,CAAC;QAAC,MAAM,CAAC,CAAC,oCAAoC,CAAC,CAAC;IAClD,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC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Q,CAAC,CAAC;QAChE,CAAC,CAAC;IACJ,CAAC;CACF;AA/KD,oBA+KC"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /**
3
+ * Raw API calls used by the CLI.
4
+ * Written as plain fetch calls (not using HttpClient) so the CLI can be
5
+ * bundled independently and doesn't pull in the full SDK at runtime.
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.CliApiError = void 0;
42
+ exports.listSites = listSites;
43
+ exports.createSite = createSite;
44
+ exports.createDeploy = createDeploy;
45
+ exports.uploadFileBatch = uploadFileBatch;
46
+ exports.finalizeDeploy = finalizeDeploy;
47
+ exports.getActiveDeploy = getActiveDeploy;
48
+ exports.testConnection = testConnection;
49
+ // ─── Error ────────────────────────────────────────────────────────────────────
50
+ class CliApiError extends Error {
51
+ constructor(message, status) {
52
+ super(message);
53
+ this.status = status;
54
+ this.name = "CliApiError";
55
+ }
56
+ }
57
+ exports.CliApiError = CliApiError;
58
+ // ─── Fetch helper ─────────────────────────────────────────────────────────────
59
+ async function getFetch() {
60
+ if (typeof globalThis.fetch === "function")
61
+ return globalThis.fetch.bind(globalThis);
62
+ const mod = await Promise.resolve().then(() => __importStar(require("node-fetch")));
63
+ return mod.default;
64
+ }
65
+ async function apiFetch(url, opts) {
66
+ const fetchFn = await getFetch();
67
+ const res = await fetchFn(url, { method: opts.method ?? "GET", headers: opts.headers, body: opts.body });
68
+ if (!res.ok) {
69
+ let msg = `${res.status} ${res.statusText}`;
70
+ try {
71
+ const b = (await res.json());
72
+ if (b.error)
73
+ msg = b.error;
74
+ }
75
+ catch { /* keep default */ }
76
+ throw new CliApiError(msg, res.status);
77
+ }
78
+ if (res.status === 204)
79
+ return undefined;
80
+ return res.json();
81
+ }
82
+ function base(cfg) {
83
+ return cfg.serverUrl.replace(/\/+$/, "");
84
+ }
85
+ function adminHeaders(cfg) {
86
+ return { "Content-Type": "application/json", "x-admin-secret": cfg.adminSecret };
87
+ }
88
+ // ─── Hosting API ──────────────────────────────────────────────────────────────
89
+ async function listSites(cfg) {
90
+ return apiFetch(`${base(cfg)}/api/hosting/databases/${cfg.projectId}/sites`, { headers: adminHeaders(cfg) });
91
+ }
92
+ async function createSite(cfg, name, description) {
93
+ return apiFetch(`${base(cfg)}/api/hosting/databases/${cfg.projectId}/sites`, {
94
+ method: "POST",
95
+ headers: adminHeaders(cfg),
96
+ body: JSON.stringify({ name, description }),
97
+ });
98
+ }
99
+ async function createDeploy(cfg, siteId, entrypoint = "index.html") {
100
+ return apiFetch(`${base(cfg)}/api/hosting/databases/${cfg.projectId}/sites/${siteId}/deploys`, {
101
+ method: "POST",
102
+ headers: adminHeaders(cfg),
103
+ body: JSON.stringify({ entrypoint, deployedBy: "clefbase-cli" }),
104
+ });
105
+ }
106
+ async function uploadFileBatch(cfg, deployId, files) {
107
+ const fetchFn = await getFetch();
108
+ // Use native FormData (Node 18+) or form-data package
109
+ let FormDataImpl;
110
+ if (typeof FormData !== "undefined") {
111
+ FormDataImpl = FormData;
112
+ }
113
+ else {
114
+ const mod = await Promise.resolve().then(() => __importStar(require("form-data")));
115
+ FormDataImpl = mod.default;
116
+ }
117
+ const form = new FormDataImpl();
118
+ for (const f of files) {
119
+ form.append("files[]", f.buffer, {
120
+ filename: f.path.split("/").pop() ?? f.path,
121
+ contentType: "application/octet-stream",
122
+ });
123
+ form.append("filePaths", f.path);
124
+ }
125
+ const url = `${base(cfg)}/api/hosting/databases/${cfg.projectId}/deploys/${deployId}/files/batch`;
126
+ const res = await fetchFn(url, {
127
+ method: "POST",
128
+ headers: { "x-admin-secret": cfg.adminSecret },
129
+ body: form,
130
+ });
131
+ if (!res.ok) {
132
+ let msg = `${res.status} ${res.statusText}`;
133
+ try {
134
+ const b = (await res.json());
135
+ if (b.error)
136
+ msg = b.error;
137
+ }
138
+ catch { /* keep */ }
139
+ throw new CliApiError(msg, res.status);
140
+ }
141
+ return res.json();
142
+ }
143
+ async function finalizeDeploy(cfg, deployId, message) {
144
+ return apiFetch(`${base(cfg)}/api/hosting/databases/${cfg.projectId}/deploys/${deployId}/finalize`, {
145
+ method: "POST",
146
+ headers: adminHeaders(cfg),
147
+ body: JSON.stringify({ message: message ?? "Deployed via clefbase CLI" }),
148
+ });
149
+ }
150
+ async function getActiveDeploy(cfg, siteId) {
151
+ try {
152
+ return await apiFetch(`${base(cfg)}/api/hosting/databases/${cfg.projectId}/sites/${siteId}/active`, { headers: adminHeaders(cfg) });
153
+ }
154
+ catch (err) {
155
+ if (err.status === 404)
156
+ return null;
157
+ throw err;
158
+ }
159
+ }
160
+ // ─── Connectivity ─────────────────────────────────────────────────────────────
161
+ async function testConnection(cfg) {
162
+ try {
163
+ const fetchFn = await getFetch();
164
+ const res = await fetchFn(`${base(cfg)}/health`, {});
165
+ return res.ok;
166
+ }
167
+ catch {
168
+ return false;
169
+ }
170
+ }