@maker-or/opencms 0.1.3 → 0.1.5
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 +4 -0
- package/dist/index.js +33 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,10 @@ npx @maker-or/opencms deploy
|
|
|
19
19
|
|
|
20
20
|
`opencms create` authenticates you, creates an OpenCMS project, pulls the Next.js template, writes the project configuration, and installs dependencies.
|
|
21
21
|
|
|
22
|
+
`opencms login` refreshes the saved browser session. The CLI also retries a management request once with a fresh browser session when the saved session has expired.
|
|
23
|
+
|
|
22
24
|
The generated `cms/schema.json` file defines the project's content types and allowed blocks. The CLI syncs it to the development environment when `dev` or `deploy` runs.
|
|
23
25
|
|
|
24
26
|
The CLI stores its local login configuration in `~/.config/opencms/config.json` (or `$XDG_CONFIG_HOME/opencms/config.json` when configured).
|
|
27
|
+
|
|
28
|
+
The CLI defaults to the hosted OpenCMS dashboard and API. Use `OPENCMS_DASHBOARD_URL` and `OPENCMS_API_URL` to target a local or self-hosted instance.
|
package/dist/index.js
CHANGED
|
@@ -65,7 +65,12 @@ class OpenCmsApiError extends Error {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
function createSdk(options = {}) {
|
|
68
|
-
const
|
|
68
|
+
const defaultBaseUrl = typeof window === "undefined" ? undefined : window.location.origin;
|
|
69
|
+
const configuredBaseUrl = options.baseUrl ?? defaultBaseUrl;
|
|
70
|
+
if (!configuredBaseUrl) {
|
|
71
|
+
throw new Error("baseUrl is required when using the OpenCMS SDK outside a browser.");
|
|
72
|
+
}
|
|
73
|
+
const baseUrl = configuredBaseUrl.replace(/\/$/, "");
|
|
69
74
|
const fetcher = options.fetch ?? globalThis.fetch;
|
|
70
75
|
const projectId = options.projectId;
|
|
71
76
|
const environment = options.environment ?? "development";
|
|
@@ -201,8 +206,9 @@ function createSdk(options = {}) {
|
|
|
201
206
|
}
|
|
202
207
|
|
|
203
208
|
// src/index.ts
|
|
204
|
-
var
|
|
205
|
-
var
|
|
209
|
+
var hostedUrl = "https://web-eta-ten-16.vercel.app";
|
|
210
|
+
var dashboardUrl = process.env.OPENCMS_DASHBOARD_URL ?? hostedUrl;
|
|
211
|
+
var apiUrl = process.env.OPENCMS_API_URL ?? hostedUrl;
|
|
206
212
|
var configRoot = process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
|
|
207
213
|
var configPath = join(configRoot, "opencms", "config.json");
|
|
208
214
|
async function readConfig() {
|
|
@@ -315,6 +321,9 @@ async function ensureToken(config) {
|
|
|
315
321
|
return loggedInToken;
|
|
316
322
|
}
|
|
317
323
|
async function reauthenticate(config) {
|
|
324
|
+
if (process.env.OPENCMS_CLERK_TOKEN) {
|
|
325
|
+
throw new Error("OPENCMS_CLERK_TOKEN was rejected or expired. Provide a fresh token or unset the variable to use browser login.");
|
|
326
|
+
}
|
|
318
327
|
console.log("Your OpenCMS session has expired. Opening browser login…");
|
|
319
328
|
const loggedInToken = await browserLogin();
|
|
320
329
|
await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
|
|
@@ -327,7 +336,8 @@ async function login() {
|
|
|
327
336
|
console.log("Saved OPENCMS_CLERK_TOKEN for local CLI use.");
|
|
328
337
|
return;
|
|
329
338
|
}
|
|
330
|
-
await
|
|
339
|
+
const loggedInToken = await browserLogin();
|
|
340
|
+
await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
|
|
331
341
|
console.log("Logged in to OpenCMS.");
|
|
332
342
|
}
|
|
333
343
|
async function logout() {
|
|
@@ -443,7 +453,14 @@ Next steps:
|
|
|
443
453
|
async function runDev() {
|
|
444
454
|
const config = await readConfig();
|
|
445
455
|
await ensureToken(config);
|
|
446
|
-
|
|
456
|
+
try {
|
|
457
|
+
await syncLocalSchema(await projectIdFromEnv(), await readConfig());
|
|
458
|
+
} catch (error) {
|
|
459
|
+
if (!(error instanceof OpenCmsApiError) || error.status !== 401)
|
|
460
|
+
throw error;
|
|
461
|
+
await reauthenticate(await readConfig());
|
|
462
|
+
await syncLocalSchema(await projectIdFromEnv(), await readConfig());
|
|
463
|
+
}
|
|
447
464
|
const manager = await packageManager(process.cwd());
|
|
448
465
|
const command = manager[0] === "npm" ? ["npm", "run", "dev"] : manager[0] === "pnpm" ? ["pnpm", "dev"] : manager[0] === "yarn" ? ["yarn", "dev"] : ["bun", "run", "dev"];
|
|
449
466
|
process.exit(await runCommand(command[0], command.slice(1), { cwd: process.cwd(), env: { ...process.env, OPENCMS_ENVIRONMENT: "development" }, inherit: true }));
|
|
@@ -478,8 +495,17 @@ async function deploy() {
|
|
|
478
495
|
const projectId = await projectIdFromEnv() ?? config.projectId;
|
|
479
496
|
if (!projectId)
|
|
480
497
|
throw new Error("No OpenCMS project is configured in this directory.");
|
|
481
|
-
|
|
482
|
-
|
|
498
|
+
let deployment;
|
|
499
|
+
try {
|
|
500
|
+
await syncLocalSchema(projectId, await readConfig());
|
|
501
|
+
deployment = await sdk(await readConfig()).deploy(projectId);
|
|
502
|
+
} catch (error) {
|
|
503
|
+
if (!(error instanceof OpenCmsApiError) || error.status !== 401)
|
|
504
|
+
throw error;
|
|
505
|
+
await reauthenticate(await readConfig());
|
|
506
|
+
await syncLocalSchema(projectId, await readConfig());
|
|
507
|
+
deployment = await sdk(await readConfig()).deploy(projectId);
|
|
508
|
+
}
|
|
483
509
|
console.log(`Deployed ${deployment.sourceEnvironment} content to ${deployment.targetEnvironment}.`);
|
|
484
510
|
if (process.env.VERCEL_TOKEN) {
|
|
485
511
|
console.log("Deploying the application to Vercel…");
|