@maker-or/opencms 0.1.4 → 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 CHANGED
@@ -19,6 +19,8 @@ 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).
package/dist/index.js CHANGED
@@ -321,6 +321,9 @@ async function ensureToken(config) {
321
321
  return loggedInToken;
322
322
  }
323
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
+ }
324
327
  console.log("Your OpenCMS session has expired. Opening browser login…");
325
328
  const loggedInToken = await browserLogin();
326
329
  await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
@@ -333,7 +336,8 @@ async function login() {
333
336
  console.log("Saved OPENCMS_CLERK_TOKEN for local CLI use.");
334
337
  return;
335
338
  }
336
- await ensureToken(config);
339
+ const loggedInToken = await browserLogin();
340
+ await writeConfig({ ...config, token: loggedInToken, apiUrl: config.apiUrl ?? apiUrl });
337
341
  console.log("Logged in to OpenCMS.");
338
342
  }
339
343
  async function logout() {
@@ -449,7 +453,14 @@ Next steps:
449
453
  async function runDev() {
450
454
  const config = await readConfig();
451
455
  await ensureToken(config);
452
- await syncLocalSchema(await projectIdFromEnv(), await readConfig());
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
+ }
453
464
  const manager = await packageManager(process.cwd());
454
465
  const command = manager[0] === "npm" ? ["npm", "run", "dev"] : manager[0] === "pnpm" ? ["pnpm", "dev"] : manager[0] === "yarn" ? ["yarn", "dev"] : ["bun", "run", "dev"];
455
466
  process.exit(await runCommand(command[0], command.slice(1), { cwd: process.cwd(), env: { ...process.env, OPENCMS_ENVIRONMENT: "development" }, inherit: true }));
@@ -484,8 +495,17 @@ async function deploy() {
484
495
  const projectId = await projectIdFromEnv() ?? config.projectId;
485
496
  if (!projectId)
486
497
  throw new Error("No OpenCMS project is configured in this directory.");
487
- await syncLocalSchema(projectId, await readConfig());
488
- const deployment = await sdk(await readConfig()).deploy(projectId);
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
+ }
489
509
  console.log(`Deployed ${deployment.sourceEnvironment} content to ${deployment.targetEnvironment}.`);
490
510
  if (process.env.VERCEL_TOKEN) {
491
511
  console.log("Deploying the application to Vercel…");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maker-or/opencms",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "The developer-first CLI for OpenCMS",
5
5
  "type": "module",
6
6
  "repository": {