clefbase 2.0.0 → 2.0.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/dist/app.d.ts +6 -26
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +12 -31
- package/dist/app.js.map +1 -1
- package/dist/auth/index.d.ts +63 -114
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +97 -176
- package/dist/auth/index.js.map +1 -1
- package/dist/cli-src/cli/api.js +14 -14
- package/dist/cli-src/cli/commands/deploy.js +84 -16
- package/dist/cli-src/cli/commands/init.js +644 -19
- package/dist/cli-src/cli/config.js +0 -1
- package/dist/cli-src/cli/index.js +48 -9
- package/dist/cli.js +756 -58
- package/dist/hosting/index.d.ts +8 -98
- package/dist/hosting/index.d.ts.map +1 -1
- package/dist/hosting/index.js +37 -95
- package/dist/hosting/index.js.map +1 -1
- package/dist/index.d.ts +14 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -65
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +0 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/auth/index.js
CHANGED
|
@@ -47,60 +47,29 @@ class SessionStore {
|
|
|
47
47
|
catch { /* ignore */ }
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
// ─── GIS script loader ────────────────────────────────────────────────────────
|
|
51
|
-
const GIS_SCRIPT_URL = "https://accounts.google.com/gsi/client";
|
|
52
|
-
let _gisLoading = null;
|
|
53
|
-
function loadGisScript() {
|
|
54
|
-
if (typeof window === "undefined") {
|
|
55
|
-
return Promise.reject(new types_1.ClefbaseError("signInWithGoogle() requires a browser environment. " +
|
|
56
|
-
"Use signInWithGoogleToken(idToken) for server/Node.js contexts.", "UNSUPPORTED_ENVIRONMENT"));
|
|
57
|
-
}
|
|
58
|
-
if (window.google?.accounts?.id)
|
|
59
|
-
return Promise.resolve();
|
|
60
|
-
if (_gisLoading)
|
|
61
|
-
return _gisLoading;
|
|
62
|
-
_gisLoading = new Promise((resolve, reject) => {
|
|
63
|
-
if (window.google?.accounts?.id) {
|
|
64
|
-
resolve();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const existing = document.querySelector(`script[src="${GIS_SCRIPT_URL}"]`);
|
|
68
|
-
const onLoad = () => resolve();
|
|
69
|
-
const onError = () => {
|
|
70
|
-
_gisLoading = null;
|
|
71
|
-
reject(new types_1.ClefbaseError("Failed to load the Google Identity Services script. Check your internet connection and Content Security Policy.", "GOOGLE_SCRIPT_LOAD_ERROR"));
|
|
72
|
-
};
|
|
73
|
-
if (existing) {
|
|
74
|
-
existing.addEventListener("load", onLoad, { once: true });
|
|
75
|
-
existing.addEventListener("error", onError, { once: true });
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const script = document.createElement("script");
|
|
79
|
-
script.src = GIS_SCRIPT_URL;
|
|
80
|
-
script.async = true;
|
|
81
|
-
script.defer = true;
|
|
82
|
-
script.addEventListener("load", onLoad, { once: true });
|
|
83
|
-
script.addEventListener("error", onError, { once: true });
|
|
84
|
-
document.head.appendChild(script);
|
|
85
|
-
});
|
|
86
|
-
return _gisLoading;
|
|
87
|
-
}
|
|
88
50
|
/**
|
|
89
51
|
* Authentication service. Obtain via `getAuth(app)`.
|
|
90
52
|
*
|
|
91
53
|
* @example
|
|
92
54
|
* const auth = getAuth(app);
|
|
55
|
+
*
|
|
56
|
+
* // Email / password
|
|
93
57
|
* const { user } = await auth.signIn("alice@example.com", "pass");
|
|
94
|
-
*
|
|
95
|
-
*
|
|
58
|
+
*
|
|
59
|
+
* // Google — redirect to gateway, come back signed in
|
|
60
|
+
* await auth.signInWithGateway("google");
|
|
61
|
+
*
|
|
62
|
+
* // On every page load, handle the gateway callback:
|
|
63
|
+
* const result = await auth.handleGatewayCallback();
|
|
64
|
+
* if (result) console.log("Signed in via gateway:", result.user.email);
|
|
96
65
|
*/
|
|
97
66
|
class Auth {
|
|
98
|
-
constructor(http) {
|
|
67
|
+
constructor(http, gatewayUrl, projectId) {
|
|
99
68
|
this.http = http;
|
|
100
69
|
this.store = new SessionStore();
|
|
101
70
|
this.listeners = [];
|
|
102
|
-
|
|
103
|
-
this.
|
|
71
|
+
this.gatewayUrl = gatewayUrl.replace(/\/+$/, "");
|
|
72
|
+
this.projectId = projectId;
|
|
104
73
|
this.store.load();
|
|
105
74
|
}
|
|
106
75
|
// ── Internals ─────────────────────────────────────────────────────────────
|
|
@@ -121,23 +90,6 @@ class Auth {
|
|
|
121
90
|
this.notify(result.user);
|
|
122
91
|
return result;
|
|
123
92
|
}
|
|
124
|
-
async resolveGoogleClientId() {
|
|
125
|
-
if (this._googleClientId !== undefined) {
|
|
126
|
-
if (!this._googleClientId) {
|
|
127
|
-
throw new types_1.ClefbaseError("Google Sign-In is not enabled for this project. " +
|
|
128
|
-
"Add a Google Client ID in your Clefbase auth settings.", "GOOGLE_NOT_CONFIGURED");
|
|
129
|
-
}
|
|
130
|
-
return this._googleClientId;
|
|
131
|
-
}
|
|
132
|
-
const cfg = await this.http.get("/google/config");
|
|
133
|
-
if (!cfg.enabled || !cfg.clientId) {
|
|
134
|
-
this._googleClientId = null;
|
|
135
|
-
throw new types_1.ClefbaseError("Google Sign-In is not enabled for this project. " +
|
|
136
|
-
"Add a Google Client ID in your Clefbase auth settings.", "GOOGLE_NOT_CONFIGURED");
|
|
137
|
-
}
|
|
138
|
-
this._googleClientId = cfg.clientId;
|
|
139
|
-
return this._googleClientId;
|
|
140
|
-
}
|
|
141
93
|
/** @internal — used by Storage to attach the bearer token to upload requests */
|
|
142
94
|
getAuthHeaders() {
|
|
143
95
|
const s = this.store.load();
|
|
@@ -148,8 +100,9 @@ class Auth {
|
|
|
148
100
|
get currentUser() { return this.store.load()?.user ?? null; }
|
|
149
101
|
/** The raw bearer token for the active session, or null. */
|
|
150
102
|
get currentToken() { return this.store.load()?.token ?? null; }
|
|
103
|
+
// ── Email / password ──────────────────────────────────────────────────────
|
|
151
104
|
/**
|
|
152
|
-
* Create a new account.
|
|
105
|
+
* Create a new account with email + password.
|
|
153
106
|
*
|
|
154
107
|
* @example
|
|
155
108
|
* const { user } = await auth.signUp("alice@example.com", "pass123", {
|
|
@@ -158,9 +111,7 @@ class Auth {
|
|
|
158
111
|
* });
|
|
159
112
|
*/
|
|
160
113
|
async signUp(email, password, profile) {
|
|
161
|
-
const result = await this.http.post("/signup", {
|
|
162
|
-
email, password, ...profile,
|
|
163
|
-
});
|
|
114
|
+
const result = await this.http.post("/signup", { email, password, ...profile });
|
|
164
115
|
return this.handleResult(result);
|
|
165
116
|
}
|
|
166
117
|
/**
|
|
@@ -173,133 +124,110 @@ class Auth {
|
|
|
173
124
|
const result = await this.http.post("/signin", { email, password });
|
|
174
125
|
return this.handleResult(result);
|
|
175
126
|
}
|
|
127
|
+
// ── Gateway OAuth (redirect flow) ─────────────────────────────────────────
|
|
176
128
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* Browser-only. The GIS script (`accounts.google.com/gsi/client`) is loaded
|
|
180
|
-
* automatically — no manual `<script>` tag needed.
|
|
181
|
-
*
|
|
182
|
-
* Without `buttonOptions`, the Google One Tap prompt is shown.
|
|
183
|
-
* Pass `{ container }` to render a fully styled Google button instead —
|
|
184
|
-
* which is more reliable since One Tap can be suppressed by the browser.
|
|
129
|
+
* Redirect the user to the Cleforyx auth gateway to sign in with an
|
|
130
|
+
* OAuth provider (currently `"google"`).
|
|
185
131
|
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
132
|
+
* The gateway handles the OAuth flow and redirects back to your app with
|
|
133
|
+
* `?cfx_token=<token>&cfx_project=<projectId>` in the URL.
|
|
134
|
+
* Call `auth.handleGatewayCallback()` on page load to complete sign-in.
|
|
188
135
|
*
|
|
189
|
-
*
|
|
190
|
-
* has been set in the project's auth settings.
|
|
191
|
-
* @throws `ClefbaseError` with code `GOOGLE_PROMPT_SUPPRESSED` if One Tap
|
|
192
|
-
* could not be displayed (switch to button mode in that case).
|
|
193
|
-
* @throws `ClefbaseError` with code `GOOGLE_SIGN_IN_CANCELLED` if the user
|
|
194
|
-
* dismissed the popup.
|
|
136
|
+
* **This method never returns** — it calls `window.location.href`.
|
|
195
137
|
*
|
|
196
138
|
* @example
|
|
197
|
-
* //
|
|
198
|
-
*
|
|
139
|
+
* // On button click:
|
|
140
|
+
* await auth.signInWithGateway("google");
|
|
199
141
|
*
|
|
200
|
-
* //
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* theme: "filled_blue",
|
|
204
|
-
* size: "large",
|
|
205
|
-
* text: "continue_with",
|
|
142
|
+
* // With a custom return URL:
|
|
143
|
+
* await auth.signInWithGateway("google", {
|
|
144
|
+
* redirectUrl: "https://myapp.cleforyx.com/dashboard",
|
|
206
145
|
* });
|
|
207
|
-
*
|
|
208
|
-
* // React example
|
|
209
|
-
* const btnRef = useRef<HTMLDivElement>(null);
|
|
210
|
-
* await auth.signInWithGoogle({ container: btnRef.current! });
|
|
211
146
|
*/
|
|
212
|
-
async
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
cancel_on_tap_outside: true,
|
|
221
|
-
callback: async ({ credential }) => {
|
|
222
|
-
try {
|
|
223
|
-
resolve(await this.signInWithGoogleToken(credential));
|
|
224
|
-
}
|
|
225
|
-
catch (err) {
|
|
226
|
-
reject(err);
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
if (buttonOptions?.container) {
|
|
231
|
-
const { container, theme, size, text, shape, width, locale } = buttonOptions;
|
|
232
|
-
gis.renderButton(container, {
|
|
233
|
-
type: "standard",
|
|
234
|
-
theme: theme ?? "outline",
|
|
235
|
-
size: size ?? "large",
|
|
236
|
-
text: text ?? "signin_with",
|
|
237
|
-
shape: shape ?? "rectangular",
|
|
238
|
-
logo_alignment: "left",
|
|
239
|
-
width,
|
|
240
|
-
locale,
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
gis.prompt((n) => {
|
|
245
|
-
if (n.isNotDisplayed()) {
|
|
246
|
-
reject(new types_1.ClefbaseError(`Google One Tap could not be displayed (${n.getNotDisplayedReason()}). ` +
|
|
247
|
-
"Pass a { container } element to render a sign-in button instead.", "GOOGLE_PROMPT_SUPPRESSED"));
|
|
248
|
-
}
|
|
249
|
-
else if (n.isSkippedMoment() || n.isDismissedMoment()) {
|
|
250
|
-
reject(new types_1.ClefbaseError("Google Sign-In was cancelled by the user.", "GOOGLE_SIGN_IN_CANCELLED"));
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
}
|
|
147
|
+
async signInWithGateway(provider, options) {
|
|
148
|
+
if (typeof window === "undefined") {
|
|
149
|
+
throw new types_1.ClefbaseError("signInWithGateway() requires a browser environment.", "UNSUPPORTED_ENVIRONMENT");
|
|
150
|
+
}
|
|
151
|
+
const redirectUrl = options?.redirectUrl ?? window.location.origin;
|
|
152
|
+
const params = new URLSearchParams({
|
|
153
|
+
project: this.projectId,
|
|
154
|
+
redirect: redirectUrl,
|
|
254
155
|
});
|
|
156
|
+
window.location.href = `${this.gatewayUrl}/${provider}?${params.toString()}`;
|
|
157
|
+
// This line is unreachable but TypeScript needs it for `never` return type
|
|
158
|
+
return new Promise(() => { });
|
|
255
159
|
}
|
|
256
160
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* for example with a custom button implementation, React Native Google
|
|
261
|
-
* Sign-In, or any other flow that gives you an ID token directly.
|
|
262
|
-
*
|
|
263
|
-
* Works in both browser and Node.js environments.
|
|
161
|
+
* Check if the current URL contains a gateway callback (`?cfx_token=`).
|
|
162
|
+
* Useful for rendering a "Finishing sign-in…" loading state before calling
|
|
163
|
+
* `handleGatewayCallback()`.
|
|
264
164
|
*
|
|
265
165
|
* @example
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* callback: async ({ credential }) => {
|
|
270
|
-
* const { user } = await auth.signInWithGoogleToken(credential);
|
|
271
|
-
* },
|
|
272
|
-
* });
|
|
273
|
-
*
|
|
274
|
-
* // React Native
|
|
275
|
-
* const { idToken } = await GoogleSignin.signIn();
|
|
276
|
-
* const { user } = await auth.signInWithGoogleToken(idToken);
|
|
166
|
+
* if (auth.isGatewayCallbackPending()) {
|
|
167
|
+
* showLoadingSpinner();
|
|
168
|
+
* }
|
|
277
169
|
*/
|
|
278
|
-
|
|
279
|
-
if (
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const result = await this.http.post("/google", { idToken });
|
|
283
|
-
return this.handleResult(result);
|
|
170
|
+
isGatewayCallbackPending() {
|
|
171
|
+
if (typeof window === "undefined")
|
|
172
|
+
return false;
|
|
173
|
+
return new URLSearchParams(window.location.search).has("cfx_token");
|
|
284
174
|
}
|
|
285
175
|
/**
|
|
286
|
-
*
|
|
287
|
-
*
|
|
176
|
+
* Call this on every page load (ideally before rendering your app).
|
|
177
|
+
* If the URL contains `?cfx_token=`, the token is validated against
|
|
178
|
+
* the server, the session is saved, and the signed-in `AuthResult` is
|
|
179
|
+
* returned. The query params are cleaned from the URL automatically.
|
|
180
|
+
*
|
|
181
|
+
* Returns `null` if there is no pending callback.
|
|
288
182
|
*
|
|
289
183
|
* @example
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
184
|
+
* // In your app's root component or entry point:
|
|
185
|
+
* useEffect(() => {
|
|
186
|
+
* auth.handleGatewayCallback().then(result => {
|
|
187
|
+
* if (result) {
|
|
188
|
+
* console.log("Signed in:", result.user.email);
|
|
189
|
+
* navigate("/dashboard");
|
|
190
|
+
* }
|
|
191
|
+
* });
|
|
192
|
+
* }, []);
|
|
193
|
+
*
|
|
194
|
+
* // Or outside React:
|
|
195
|
+
* const result = await auth.handleGatewayCallback();
|
|
196
|
+
* if (result) showDashboard(result.user);
|
|
293
197
|
*/
|
|
294
|
-
async
|
|
198
|
+
async handleGatewayCallback() {
|
|
199
|
+
if (typeof window === "undefined")
|
|
200
|
+
return null;
|
|
201
|
+
const params = new URLSearchParams(window.location.search);
|
|
202
|
+
const token = params.get("cfx_token");
|
|
203
|
+
if (!token)
|
|
204
|
+
return null;
|
|
205
|
+
// Clean the token + project params from the URL immediately so they
|
|
206
|
+
// aren't reprocessed on refresh or shared in links
|
|
207
|
+
params.delete("cfx_token");
|
|
208
|
+
params.delete("cfx_project");
|
|
209
|
+
const cleanSearch = params.toString();
|
|
210
|
+
const cleanUrl = window.location.pathname + (cleanSearch ? `?${cleanSearch}` : "");
|
|
211
|
+
window.history.replaceState({}, "", cleanUrl);
|
|
212
|
+
// Validate the token against the server and fetch the full user object
|
|
295
213
|
try {
|
|
296
|
-
const
|
|
297
|
-
|
|
214
|
+
const user = await this.http.get("/me", { Authorization: `Bearer ${token}` });
|
|
215
|
+
// We don't have an expiresAt from the URL — fetch it from /me is enough
|
|
216
|
+
// for the session; use a generous 30-day default matching server config
|
|
217
|
+
const expiresAt = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString();
|
|
218
|
+
const result = {
|
|
219
|
+
user,
|
|
220
|
+
token,
|
|
221
|
+
session: { token, expiresAt },
|
|
222
|
+
};
|
|
223
|
+
return this.handleResult(result);
|
|
298
224
|
}
|
|
299
|
-
catch {
|
|
300
|
-
|
|
225
|
+
catch (err) {
|
|
226
|
+
// Token was invalid or expired — don't sign in
|
|
227
|
+
throw new types_1.ClefbaseError(`Gateway callback failed: ${err.message}`, "GATEWAY_CALLBACK_ERROR");
|
|
301
228
|
}
|
|
302
229
|
}
|
|
230
|
+
// ── Session management ────────────────────────────────────────────────────
|
|
303
231
|
/** Sign out and clear the local session. */
|
|
304
232
|
async signOut() {
|
|
305
233
|
const token = this.currentToken;
|
|
@@ -311,13 +239,6 @@ class Auth {
|
|
|
311
239
|
}
|
|
312
240
|
this.store.clear();
|
|
313
241
|
this.notify(null);
|
|
314
|
-
// Tell GIS to disable auto-select so the user isn't silently re-signed in
|
|
315
|
-
if (typeof window !== "undefined" && window.google?.accounts?.id) {
|
|
316
|
-
try {
|
|
317
|
-
window.google.accounts.id.disableAutoSelect();
|
|
318
|
-
}
|
|
319
|
-
catch { /* ignore */ }
|
|
320
|
-
}
|
|
321
242
|
}
|
|
322
243
|
/** Re-fetch the current user's profile from the server and update the cache. */
|
|
323
244
|
async refreshCurrentUser() {
|
|
@@ -383,7 +304,7 @@ class Auth {
|
|
|
383
304
|
}
|
|
384
305
|
/**
|
|
385
306
|
* Subscribe to auth state changes.
|
|
386
|
-
* Fires immediately with the current user, then on every
|
|
307
|
+
* Fires immediately with the current user, then on every sign-in or sign-out.
|
|
387
308
|
* Returns an unsubscribe function.
|
|
388
309
|
*
|
|
389
310
|
* @example
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":";;;AAEA,oCAAyC;AAUzC,MAAM,YAAY;IAAlB;QACU,YAAO,GAA4B,IAAI,CAAC;QAC/B,QAAG,GAAG,aAAa,CAAC;IAiCvC,CAAC;IA/BC,IAAY,EAAE;QACZ,IAAI,CAAC;YAAC,OAAO,OAAO,YAAY,KAAK,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;QAAC,CAAC;QACzE,MAAM,CAAC;YAAC,OAAO,IAAI,CAAC;QAAC,CAAC;IACxB,CAAC;IAED,IAAI,CAAC,CAAmB;QACtB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACjB,IAAI,CAAC;YAAC,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QAAC,CAAC;QACtD,MAAM,CAAC,CAAC,0BAA0B,CAAC,CAAC;IACtC,CAAC;IAED,IAAI;QACF,IAAI,IAAI,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li/api.js
CHANGED
|
@@ -91,17 +91,17 @@ function base(cfg) {
|
|
|
91
91
|
return cfg.serverUrl.replace(/\/+$/, "");
|
|
92
92
|
}
|
|
93
93
|
function adminHeaders(cfg) {
|
|
94
|
-
return { "Content-Type": "application/json", "x-
|
|
94
|
+
return { "Content-Type": "application/json", "x-cfx-key": cfg.apiKey };
|
|
95
95
|
}
|
|
96
96
|
function cfxHeaders(cfg) {
|
|
97
97
|
return { "Content-Type": "application/json", "x-cfx-key": cfg.apiKey };
|
|
98
98
|
}
|
|
99
99
|
// ─── Hosting API ──────────────────────────────────────────────────────────────
|
|
100
100
|
async function listSites(cfg) {
|
|
101
|
-
return apiFetch(`${base(cfg)}/
|
|
101
|
+
return apiFetch(`${base(cfg)}/hosting/sites`, { headers: cfxHeaders(cfg) });
|
|
102
102
|
}
|
|
103
103
|
async function createSite(cfg, name, description) {
|
|
104
|
-
return apiFetch(`${base(cfg)}/
|
|
104
|
+
return apiFetch(`${base(cfg)}/hosting/sites`, { method: "POST", headers: cfxHeaders(cfg), body: JSON.stringify({ name, description }) });
|
|
105
105
|
}
|
|
106
106
|
async function deleteSite(cfg, siteId, opts = {}) {
|
|
107
107
|
const params = new URLSearchParams();
|
|
@@ -110,24 +110,24 @@ async function deleteSite(cfg, siteId, opts = {}) {
|
|
|
110
110
|
if (opts.deleteDns)
|
|
111
111
|
params.set("deleteDns", "true");
|
|
112
112
|
const qs = params.toString() ? `?${params}` : "";
|
|
113
|
-
return apiFetch(`${base(cfg)}/
|
|
113
|
+
return apiFetch(`${base(cfg)}/hosting/sites/${siteId}${qs}`, { method: "DELETE", headers: cfxHeaders(cfg) });
|
|
114
114
|
}
|
|
115
115
|
async function getDnsStatus(cfg, siteId) {
|
|
116
|
-
return apiFetch(`${base(cfg)}/
|
|
116
|
+
return apiFetch(`${base(cfg)}/hosting/sites/${siteId}/dns`, { headers: cfxHeaders(cfg) });
|
|
117
117
|
}
|
|
118
118
|
async function reprovisionDns(cfg, siteId) {
|
|
119
|
-
return apiFetch(`${base(cfg)}/
|
|
119
|
+
return apiFetch(`${base(cfg)}/hosting/sites/${siteId}/dns/reprovision`, { method: "POST", headers: cfxHeaders(cfg), body: JSON.stringify({}) });
|
|
120
120
|
}
|
|
121
121
|
async function createDeploy(cfg, siteId, entrypoint = "index.html") {
|
|
122
|
-
return apiFetch(`${base(cfg)}/
|
|
122
|
+
return apiFetch(`${base(cfg)}/hosting/sites/${siteId}/deploys`, {
|
|
123
123
|
method: "POST",
|
|
124
|
-
headers:
|
|
124
|
+
headers: cfxHeaders(cfg),
|
|
125
125
|
body: JSON.stringify({ entrypoint, deployedBy: "clefbase-cli" }),
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
128
|
async function uploadFileBatch(cfg, deployId, files) {
|
|
129
129
|
const fetchFn = await getFetch();
|
|
130
|
-
const url = `${base(cfg)}/
|
|
130
|
+
const url = `${base(cfg)}/hosting/deploys/${deployId}/files/batch`;
|
|
131
131
|
let res;
|
|
132
132
|
if (typeof FormData !== "undefined") {
|
|
133
133
|
const form = new FormData();
|
|
@@ -140,7 +140,7 @@ async function uploadFileBatch(cfg, deployId, files) {
|
|
|
140
140
|
}
|
|
141
141
|
res = await fetchFn(url, {
|
|
142
142
|
method: "POST",
|
|
143
|
-
headers: { "x-
|
|
143
|
+
headers: { "x-cfx-key": cfg.apiKey },
|
|
144
144
|
body: form,
|
|
145
145
|
});
|
|
146
146
|
}
|
|
@@ -157,7 +157,7 @@ async function uploadFileBatch(cfg, deployId, files) {
|
|
|
157
157
|
}
|
|
158
158
|
res = await fetchFn(url, {
|
|
159
159
|
method: "POST",
|
|
160
|
-
headers: { "x-
|
|
160
|
+
headers: { "x-cfx-key": cfg.apiKey, ...form.getHeaders() },
|
|
161
161
|
body: form,
|
|
162
162
|
});
|
|
163
163
|
}
|
|
@@ -174,15 +174,15 @@ async function uploadFileBatch(cfg, deployId, files) {
|
|
|
174
174
|
return res.json();
|
|
175
175
|
}
|
|
176
176
|
async function finalizeDeploy(cfg, deployId, message) {
|
|
177
|
-
return apiFetch(`${base(cfg)}/
|
|
177
|
+
return apiFetch(`${base(cfg)}/hosting/deploys/${deployId}/finalize`, {
|
|
178
178
|
method: "POST",
|
|
179
|
-
headers:
|
|
179
|
+
headers: cfxHeaders(cfg),
|
|
180
180
|
body: JSON.stringify({ message: message ?? "Deployed via clefbase CLI" }),
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
async function getActiveDeploy(cfg, siteId) {
|
|
184
184
|
try {
|
|
185
|
-
return await apiFetch(`${base(cfg)}/
|
|
185
|
+
return await apiFetch(`${base(cfg)}/hosting/sites/${siteId}/active`, { headers: cfxHeaders(cfg) });
|
|
186
186
|
}
|
|
187
187
|
catch (err) {
|
|
188
188
|
if (err.status === 404)
|