easy-cms 0.63.0 → 0.65.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.
package/dist/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  run
4
- } from "./chunk-GX6RYPUR.js";
4
+ } from "./chunk-WCISVCEZ.js";
5
5
 
6
6
  // src/bin.ts
7
7
  process.exitCode = await run(process.argv.slice(2));
@@ -13,7 +13,12 @@ import {
13
13
  ValidationError,
14
14
  warnDeprecated
15
15
  } from "@easy-cms/core";
16
- import { copyDatabase, generateTypes, writeBackupFile } from "@easy-cms/core/internal";
16
+ import {
17
+ copyDatabase,
18
+ decryptBackup,
19
+ generateTypes,
20
+ writeBackupFile
21
+ } from "@easy-cms/core/internal";
17
22
 
18
23
  // src/serve.ts
19
24
  import { watch } from "fs";
@@ -26,12 +31,12 @@ import {
26
31
  createRestHandler
27
32
  } from "@easy-cms/core";
28
33
  import { createRootEndpointHandler, forwardedClientIp } from "@easy-cms/core/internal";
29
- function createStandaloneHandler(cms) {
34
+ function createStandaloneHandler(cms, options = {}) {
30
35
  const config = cms.config;
31
36
  const adminPath = `/${config.admin.path.replace(/^\/+|\/+$/g, "")}`;
32
37
  const clientIps = /* @__PURE__ */ new WeakMap();
33
38
  const getClientIp = (request) => clientIps.get(request);
34
- const api = createRestHandler(cms, { getClientIp });
39
+ const api = createRestHandler(cms, { getClientIp, trustProxy: options.trustProxy === true });
35
40
  const rootEndpoints = createRootEndpointHandler(cms, { getClientIp });
36
41
  const admin = adminHandlerFor(config, {});
37
42
  const under = (path, base) => path === base || path.startsWith(`${base}/`);
@@ -100,7 +105,7 @@ async function startServer(options) {
100
105
  const { logger, cwd } = options;
101
106
  const trustProxy = options.trustProxy ?? false;
102
107
  let cms = await createEasyCMS(await options.loadConfig(), { cwd, logger });
103
- let handler = createStandaloneHandler(cms);
108
+ let handler = createStandaloneHandler(cms, { trustProxy });
104
109
  const server = createServer(async (req, res) => {
105
110
  try {
106
111
  await sendWebResponse(
@@ -126,7 +131,7 @@ async function startServer(options) {
126
131
  const next = await createEasyCMS(await options.loadConfig(), { cwd, logger });
127
132
  const previous = cms;
128
133
  cms = next;
129
- handler = createStandaloneHandler(next);
134
+ handler = createStandaloneHandler(next, { trustProxy });
130
135
  await previous.destroy();
131
136
  logger.info("Config reloaded.");
132
137
  } catch (error) {
@@ -200,6 +205,7 @@ Commands:
200
205
  serve Run the CMS as its own server (admin + REST API)
201
206
  jobs:run Run due scheduled publishes, jobs, webhook and email retries (also: run-scheduled)
202
207
  backup <file> Copy the database to a SQLite file while the CMS runs
208
+ backup:decrypt <file> Decrypt a backup made with backups.encryptionKey
203
209
  copy --from <config> Copy all content from another config's database into this one
204
210
  <plugin command> Commands from your config's plugins, e.g. nested:rebuild
205
211
 
@@ -242,6 +248,11 @@ yet. Postgres needs backups: { sqlite } in the config. Uploads are not included:
242
248
  uploads folder or bucket separately.
243
249
 
244
250
  Postgres: use pg_dump, e.g. pg_dump --format=custom --file=cms.dump "$DATABASE_URL".
251
+ `,
252
+ "backup:decrypt": `Usage: easy-cms backup:decrypt <file> [--out <file>] [options]
253
+
254
+ Decrypts a backup the admin made with backups.encryptionKey (a .db.gz.enc file, e.g. copied from
255
+ the backup bucket) into a .db.gz file, with the key from the config. The database isn't opened.
245
256
  `,
246
257
  copy: `Usage: easy-cms copy --from <config> [options]
247
258
 
@@ -322,6 +333,25 @@ async function run(argv, io = defaultIO) {
322
333
  return 0;
323
334
  }
324
335
  if (command === "copy") return await copy(values.from, config, cwd, logger, io);
336
+ if (command === "backup:decrypt") {
337
+ const source = rest.join(" ").trim();
338
+ const key = config.backups?.encryptionKey;
339
+ if (!source || !key) {
340
+ io.err(source ? "Set backups.encryptionKey in the config.\n" : "Missing backup file.\n");
341
+ io.err(COMMAND_HELP["backup:decrypt"]);
342
+ return 1;
343
+ }
344
+ const input = isAbsolute(source) ? source : resolve(cwd, source);
345
+ const target = values.out ?? input.replace(/\.enc$/, "");
346
+ const out = isAbsolute(target) ? target : resolve(cwd, target);
347
+ if (out === input || existsSync(out)) {
348
+ io.err(`${out} already exists; choose another name with --out.`);
349
+ return 1;
350
+ }
351
+ await writeFile(out, decryptBackup(await readFile(input), key));
352
+ io.out(`Decrypted ${input} to ${out}`);
353
+ return 0;
354
+ }
325
355
  const schema = command === "admin:create" && process.env.NODE_ENV !== "production" ? "push" : "skip";
326
356
  const cms = await createEasyCMS2(config, {
327
357
  cwd,
package/dist/index.d.ts CHANGED
@@ -11,7 +11,9 @@ type Handler = (request: Request, clientIp?: string) => Promise<Response>;
11
11
  * admin at `admin.path`, `/healthz` for load balancers, and endpoints marked `root` (such as a
12
12
  * plugin's `/robots.txt`). `/` redirects to the admin.
13
13
  */
14
- declare function createStandaloneHandler<C extends Config>(cms: EasyCMS<C>): Handler;
14
+ declare function createStandaloneHandler<C extends Config>(cms: EasyCMS<C>, options?: {
15
+ trustProxy?: boolean;
16
+ }): Handler;
15
17
  interface StartOptions extends StandaloneOptions {
16
18
  readonly port: number;
17
19
  readonly host?: string;
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  createStandaloneHandler,
3
3
  run,
4
4
  startServer
5
- } from "./chunk-GX6RYPUR.js";
5
+ } from "./chunk-WCISVCEZ.js";
6
6
  export {
7
7
  createStandaloneHandler,
8
8
  run,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy-cms",
3
- "version": "0.63.0",
3
+ "version": "0.65.0",
4
4
  "description": "Command line tool for Easy CMS",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,11 +21,11 @@
21
21
  "node": ">=22.12"
22
22
  },
23
23
  "dependencies": {
24
- "@easy-cms/core": "^0.63.0",
25
- "@easy-cms/admin": "^0.63.0"
24
+ "@easy-cms/core": "^0.65.0",
25
+ "@easy-cms/admin": "^0.65.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@easy-cms/db-sqlite": "^0.63.0"
28
+ "@easy-cms/db-sqlite": "^0.65.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"