@nakedcreativity/cee-ms-node 1.0.121 → 2.0.0-beta.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 (55) hide show
  1. package/README.md +81 -0
  2. package/lib/draft.d.ts +20 -0
  3. package/lib/draft.js +109 -0
  4. package/lib/draft.js.map +1 -0
  5. package/lib/filters/active.js +1 -2
  6. package/lib/filters/active.js.map +1 -1
  7. package/lib/filters/index.js +5 -1
  8. package/lib/filters/index.js.map +1 -1
  9. package/lib/filters/slugify.js +3 -4
  10. package/lib/filters/slugify.js.map +1 -1
  11. package/lib/index.d.ts +51 -10
  12. package/lib/index.js +262 -323
  13. package/lib/index.js.map +1 -1
  14. package/lib/interfaces.d.ts +55 -16
  15. package/lib/interfaces.js +1 -1
  16. package/lib/interfaces.js.map +1 -1
  17. package/lib/preview-token.d.ts +21 -0
  18. package/lib/preview-token.js +37 -0
  19. package/lib/preview-token.js.map +1 -0
  20. package/lib/state.d.ts +17 -0
  21. package/lib/state.js +44 -0
  22. package/lib/state.js.map +1 -0
  23. package/lib/storage.d.ts +6 -0
  24. package/lib/storage.js +24 -0
  25. package/lib/storage.js.map +1 -0
  26. package/lib/tags/blog.d.ts +5 -2
  27. package/lib/tags/blog.js +25 -41
  28. package/lib/tags/blog.js.map +1 -1
  29. package/lib/tags/breadcrumb.d.ts +2 -1
  30. package/lib/tags/breadcrumb.js +13 -15
  31. package/lib/tags/breadcrumb.js.map +1 -1
  32. package/lib/tags/image.d.ts +2 -0
  33. package/lib/tags/image.js +25 -68
  34. package/lib/tags/image.js.map +1 -1
  35. package/lib/tags/index.js +5 -1
  36. package/lib/tags/index.js.map +1 -1
  37. package/lib/tags/module.d.ts +1 -0
  38. package/lib/tags/module.js +6 -6
  39. package/lib/tags/module.js.map +1 -1
  40. package/lib/tags/navigation.d.ts +5 -2
  41. package/lib/tags/navigation.js +14 -217
  42. package/lib/tags/navigation.js.map +1 -1
  43. package/lib/tags/page.d.ts +5 -2
  44. package/lib/tags/page.js +9 -21
  45. package/lib/tags/page.js.map +1 -1
  46. package/lib/tags/region.d.ts +1 -0
  47. package/lib/tags/region.js +6 -7
  48. package/lib/tags/region.js.map +1 -1
  49. package/package.json +25 -26
  50. package/lib/test-tags.d.ts +0 -3
  51. package/lib/test-tags.js +0 -125
  52. package/lib/test-tags.js.map +0 -1
  53. package/lib/test.d.ts +0 -1
  54. package/lib/test.js +0 -52
  55. package/lib/test.js.map +0 -1
package/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # @nakedcreativity/cee-ms-node
2
+
3
+ Renders a Cee.ms site from its published files (`pages/site.json`, `pages/{id}.json`, `data/{id}.json`) with the
4
+ site's Liquid templates, and serves verified editor drafts to the Cee.ms editor.
5
+
6
+ ```ts
7
+ import { CacheSource, Ceems } from '@nakedcreativity/cee-ms-node';
8
+
9
+ const ceems = new Ceems({
10
+ assets: './src',
11
+ cacheSource: CacheSource.S3,
12
+ cacheBucket: 'my-site',
13
+ viewsPath: './views/',
14
+ customHandler: true,
15
+ tags: [],
16
+ filters: [],
17
+ });
18
+
19
+ ceems.app.get(/(.*)/, async (req, res) => {
20
+ const page = await ceems.load(req, res, true);
21
+ ceems.render(page, req, res);
22
+ });
23
+ ```
24
+
25
+ ## Draft previews
26
+
27
+ The editor loads `GET /draft/{pageId}?token=…` in an iframe. The renderer verifies the token, fetches the draft from
28
+ the Cee.ms API, and renders it with module markers and the editor bridge. `&module={id}` renders one module and
29
+ `&region={key}` one region, so the editor can refresh just what changed.
30
+
31
+ Set these in the site's environment (or `config.preview`). Without the first three, `/draft` returns 404.
32
+
33
+ | Variable | Purpose |
34
+ | ------------------------ | ------------------------------------------------------------- |
35
+ | `CEEMS_PREVIEW_SECRET` | The site's preview secret. Signs and verifies preview tokens. |
36
+ | `CEEMS_API_URL` | The Cee.ms API, e.g. `https://api.cee.ms`. |
37
+ | `CEEMS_EDITOR_ORIGIN` | The editor's origin; the only page allowed to frame drafts. |
38
+ | `CEEMS_BRIDGE_SRC` | URL of the versioned editor bridge script. |
39
+ | `CEEMS_BRIDGE_INTEGRITY` | Its Subresource Integrity hash. |
40
+
41
+ Draft responses send `Cache-Control: no-store`, `X-Robots-Tag: noindex`, `frame-ancestors <editor origin>` and
42
+ `Referrer-Policy: no-referrer` (the token is in the URL).
43
+
44
+ ## Upgrading a site from 1.x
45
+
46
+ 2.0 ships with Cee.ms v2. Upgrade a site when it moves to v2: the 1.x `POST /draft` that the old editor uses is gone.
47
+
48
+ - **Node 22 or later.** Update the Lambda runtime.
49
+ - **Set the preview variables** above.
50
+ - **No code changes are needed for the common pattern** (`ceems.load(req, res, true)` then `ceems.render(page, …)`,
51
+ `ceems.site`, `ceems.loadS3File`, `ceems.loadLocalFile`, `context.globals` in custom tags). `ceems.site` is now
52
+ always the published site; it never holds draft data.
53
+ - **`ceems.engine.options.globals.metadata = …` still works.** It can move to the new `globals` config option.
54
+ - **Custom tags that call `engine.renderFile(file, scope)`** should pass `{ globals: context.globals }` as the third
55
+ argument (or use `context.getAll()` as the scope, as most do), so partials see the site data.
56
+ - **`?edit` on a public URL no longer adds edit markup.** Only verified drafts do.
57
+ - **`aws-sdk` v2 is no longer a dependency.** A site that imports it directly must add it itself, or move to v3.
58
+ - **Edit mode no longer injects jQuery.**
59
+
60
+ ## What changed in 2.0
61
+
62
+ - **Requests no longer share state.** 1.x kept the current page, site and pagination on the shared `Ceems` instance
63
+ and re-registered the navigation, blog and breadcrumb tags on every request with that request's page. When requests
64
+ overlapped, one could render with another's page or navigation, and a public visitor could be served draft
65
+ content. Each render now carries its own state, passed to templates and tags as render-time globals, and tags are
66
+ registered once.
67
+ - **Drafts are authenticated** (above). The unauthenticated `POST /draft` is removed.
68
+ - **The `{% image %}` tag** kept its arguments on the module, so every `image` tag in a site used the arguments of
69
+ whichever one was parsed last. Fixed.
70
+ - **A blog page past the last article** is a 404, not a 500.
71
+ - **Errors** return a generic message instead of `error.message`, and page data is no longer logged.
72
+ - **Dependencies:** AWS SDK v3, cheerio 1.x, liquidjs 10.30, Express's own body parsers; underscore removed.
73
+
74
+ ## Development
75
+
76
+ ```sh
77
+ npm install
78
+ npm test # Vitest
79
+ npm run dev # local server over test/fixtures/site on http://localhost:3030/
80
+ npm run build # lib/
81
+ ```
package/lib/draft.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type express from 'express';
2
+ import type { CeemsPage, CeemsSite, PreviewConfig } from './interfaces';
3
+ export type DraftResult = {
4
+ ok: true;
5
+ page: CeemsPage;
6
+ site: CeemsSite;
7
+ } | {
8
+ ok: false;
9
+ status: 401 | 404 | 502;
10
+ };
11
+ export interface DraftService {
12
+ fetch(pageId: string, token: string): Promise<DraftResult>;
13
+ setHeaders(res: express.Response): void;
14
+ injectBridge(html: string): string;
15
+ }
16
+ /**
17
+ * Draft previews, or `null` when this site is not configured for them (they then 404). Needs the site's
18
+ * preview secret, the API URL and the editor origin.
19
+ */
20
+ export declare function draftServiceFor(config?: PreviewConfig): DraftService | null;
package/lib/draft.js ADDED
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.draftServiceFor = draftServiceFor;
37
+ const cheerio = __importStar(require("cheerio"));
38
+ const preview_token_1 = require("./preview-token");
39
+ const DRAFT_QUERY = 'query Draft($token: String!) { draftRenderPayload(token: $token) { page site } }';
40
+ /**
41
+ * Draft previews, or `null` when this site is not configured for them (they then 404). Needs the site's
42
+ * preview secret, the API URL and the editor origin.
43
+ */
44
+ function draftServiceFor(config = {}) {
45
+ const secret = config.secret || process.env.CEEMS_PREVIEW_SECRET;
46
+ const apiUrl = config.apiUrl || process.env.CEEMS_API_URL;
47
+ const editorOrigin = config.editorOrigin || process.env.CEEMS_EDITOR_ORIGIN;
48
+ const bridge = config.bridge ||
49
+ (process.env.CEEMS_BRIDGE_SRC
50
+ ? { src: process.env.CEEMS_BRIDGE_SRC, integrity: process.env.CEEMS_BRIDGE_INTEGRITY }
51
+ : undefined);
52
+ if (!secret || !apiUrl || !editorOrigin)
53
+ return null;
54
+ const graphqlUrl = apiUrl.replace(/\/$/, '') + '/graphql';
55
+ return {
56
+ async fetch(pageId, token) {
57
+ if (!(0, preview_token_1.verifyPreviewToken)(secret, token, pageId).ok)
58
+ return { ok: false, status: 401 };
59
+ let body;
60
+ try {
61
+ const response = await fetch(graphqlUrl, {
62
+ method: 'POST',
63
+ headers: { 'content-type': 'application/json' },
64
+ body: JSON.stringify({ query: DRAFT_QUERY, variables: { token } }),
65
+ signal: AbortSignal.timeout(10_000),
66
+ });
67
+ body = await response.json();
68
+ }
69
+ catch (error) {
70
+ console.error('[ceems] draft fetch failed', error instanceof Error ? error.message : error);
71
+ return { ok: false, status: 502 };
72
+ }
73
+ const payload = body?.data?.draftRenderPayload;
74
+ if (!payload) {
75
+ const code = body?.errors?.[0]?.extensions?.code;
76
+ if (code === 'UNAUTHENTICATED' || code === 'FORBIDDEN')
77
+ return { ok: false, status: 401 };
78
+ if (code === 'NOT_FOUND')
79
+ return { ok: false, status: 404 };
80
+ return { ok: false, status: 502 };
81
+ }
82
+ return { ok: true, page: JSON.parse(payload.page), site: JSON.parse(payload.site) };
83
+ },
84
+ setHeaders(res) {
85
+ res.set({
86
+ 'Cache-Control': 'no-store',
87
+ 'X-Robots-Tag': 'noindex, nofollow',
88
+ 'Content-Security-Policy': `frame-ancestors ${editorOrigin}`,
89
+ // The token is in the URL: never send it on to the page's assets and links.
90
+ 'Referrer-Policy': 'no-referrer',
91
+ 'X-Content-Type-Options': 'nosniff',
92
+ });
93
+ },
94
+ injectBridge(html) {
95
+ const $ = cheerio.load(html);
96
+ $('body').addClass('cee-ms-edit');
97
+ if (bridge) {
98
+ const script = $('<script defer></script>')
99
+ .attr('src', bridge.src)
100
+ .attr('data-editor-origin', editorOrigin);
101
+ if (bridge.integrity)
102
+ script.attr('integrity', bridge.integrity).attr('crossorigin', 'anonymous');
103
+ $('body').append(script);
104
+ }
105
+ return $.html();
106
+ },
107
+ };
108
+ }
109
+ //# sourceMappingURL=draft.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft.js","sourceRoot":"","sources":["../src/draft.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,0CAiEC;AAnFD,iDAAmC;AAEnC,mDAAqD;AAUrD,MAAM,WAAW,GAAG,kFAAkF,CAAC;AAEvG;;;GAGG;AACH,SAAgB,eAAe,CAAC,SAAwB,EAAE;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IACjE,MAAM,MAAM,GAAG,MAAM,C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GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7B,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAClC,IAAI,MAAM,EAAE,CAAC;gBACT,MAAM,MAAM,GAAG,CAAC,CAAC,yBAAyB,CAAC;qBACtC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;qBACvB,IAAI,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;gBAC9C,IAAI,MAAM,CAAC,SAAS;oBAAE,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;gBAClG,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YACD,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC;KACJ,CAAC;AACN,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerActiveFilter = void 0;
3
+ exports.registerActiveFilter = registerActiveFilter;
4
4
  function registerActiveFilter(engine) {
5
5
  engine.registerFilter('active', (path, match, cssClass) => {
6
6
  const regex = new RegExp('^' + match + '(?!([a-z0-9-_]+))');
@@ -12,5 +12,4 @@ function registerActiveFilter(engine) {
12
12
  }
13
13
  });
14
14
  }
15
- exports.registerActiveFilter = registerActiveFilter;
16
15
  //# sourceMappingURL=active.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"active.js","sourceRoot":"","sources":["../../src/filters/active.ts"],"names":[],"mappings":";;;AAEA,SAAgB,oBAAoB,CAAC,MAAc;IAC/C,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QACtD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,KAAK,GAAG,mBAAmB,CAAC,CAAC;QAE5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YAClB,OAAO,QAAQ,CAAC;SACnB;aAAM;YACH,OAAO,EAAE,CAAC;SACb;IACL,CAAC,CAAC,CAAC;AACP,CAAC;AAVD,oDAUC"}
1
+ {"version":3,"file":"active.js","sourceRoot":"","sources":["../../src/filters/active.ts"],"names":[],"mappings":";;AAEA,oDAUC;AAVD,SAAgB,oBAAoB,CAAC,MAAc;IAC/C,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;QACtD,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,GAAG,KAAK,GAAG,mBAAmB,CAAC,CAAC;QAE5D,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACnB,OAAO,QAAQ,CAAC;QACpB,CAAC;aAAM,CAAC;YACJ,OAAO,EAAE,CAAC;QACd,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/filters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B"}
@@ -3,16 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerSlugifyFilter = void 0;
6
+ exports.registerSlugifyFilter = registerSlugifyFilter;
7
7
  const slugify_1 = __importDefault(require("slugify"));
8
8
  function registerSlugifyFilter(engine) {
9
9
  engine.registerFilter('slugify', (string, replacement) => {
10
- return slugify_1.default(string, {
10
+ return (0, slugify_1.default)(string, {
11
11
  lower: true,
12
12
  strict: true,
13
- replacement: replacement || '-'
13
+ replacement: replacement || '-',
14
14
  });
15
15
  });
16
16
  }
17
- exports.registerSlugifyFilter = registerSlugifyFilter;
18
17
  //# sourceMappingURL=slugify.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"slugify.js","sourceRoot":"","sources":["../../src/filters/slugify.ts"],"names":[],"mappings":";;;;;;AACA,sDAA6B;AAE7B,SAAgB,qBAAqB,CAAC,MAAc;IAChD,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,MAAc,EAAE,WAAoB,EAAE,EAAE;QACtE,OAAO,iBAAO,CAAC,MAAM,EAAE;YACnB,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI;YACZ,WAAW,EAAE,WAAW,IAAI,GAAG;SAClC,CAAC,CAAA;IACN,CAAC,CAAC,CAAC;AACP,CAAC;AARD,sDAQC"}
1
+ {"version":3,"file":"slugify.js","sourceRoot":"","sources":["../../src/filters/slugify.ts"],"names":[],"mappings":";;;;;AAGA,sDAQC;AAVD,sDAA8B;AAE9B,SAAgB,qBAAqB,CAAC,MAAc;IAChD,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE;QACrD,OAAO,IAAA,iBAAO,EAAC,MAAM,EAAE;YACnB,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI;YACZ,WAAW,EAAE,WAAW,IAAI,GAAG;SAClC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,20 +1,61 @@
1
1
  import express from 'express';
2
2
  import { Liquid } from 'liquidjs';
3
- import { S3 } from 'aws-sdk';
4
- import { CeemsConfig, CeemsPage, CeemsRequest } from './interfaces';
3
+ import { CeemsConfig, CeemsPage, CeemsRequest, CeemsSite, RenderState } from './interfaces';
4
+ import { Storage } from './storage';
5
+ export * from './interfaces';
6
+ export { signPreviewToken, verifyPreviewToken } from './preview-token';
7
+ export { renderState } from './state';
8
+ /**
9
+ * A Cee.ms site renderer: an Express app that renders published pages, and verified editor drafts, with the
10
+ * site's Liquid templates.
11
+ *
12
+ * One instance serves every request, so nothing about a request is stored on it. Each render carries its own
13
+ * `RenderState` (site, page, edit mode), passed to templates and tags as render-time globals.
14
+ */
5
15
  export declare class Ceems {
6
- app: express.Server;
16
+ app: express.Express;
7
17
  engine: Liquid;
8
- site: any;
9
- pagination: number;
10
18
  config: CeemsConfig;
11
- s3: S3;
19
+ /** The latest published `site.json`, refreshed on every public request. Never holds draft data. */
20
+ site: CeemsSite | undefined;
21
+ storage: Storage;
22
+ private drafts;
12
23
  constructor(config: CeemsConfig);
13
- loadSite(draft?: any): Promise<void>;
24
+ private registerTags;
25
+ /** Loads the published `site.json`, remembers it as `this.site`, and returns it. */
26
+ loadSite(): Promise<CeemsSite>;
27
+ /**
28
+ * Loads the published page for the request's path (or the `404` page), ready for `render`. With
29
+ * `loadPage` false, returns `page` as given (for custom routes that build their own page object).
30
+ */
14
31
  load(req: CeemsRequest, res: express.Response, loadPage?: boolean, page?: CeemsPage): Promise<CeemsPage>;
15
- loadLocalFile(filename: any): any;
16
- loadS3File(filename: any): Promise<any>;
32
+ /** Reads `pages/<id>.json`. */
33
+ loadPageFile(id: string): Promise<CeemsPage>;
34
+ /** Synchronous local read, kept for custom tags. `filename` is a full path. */
35
+ loadLocalFile(filename: string): any;
36
+ /** Reads and parses a published JSON file, kept for custom tags. `filename` is relative to the bucket. */
37
+ loadS3File(filename: string): Promise<any>;
38
+ /** The site path for a request (`home` for `/`), and the blog page number if the URL ends in one. */
39
+ parsePath(req: CeemsRequest): {
40
+ path: string;
41
+ pagination: number | null;
42
+ };
43
+ /** @deprecated Use `parsePath`. */
17
44
  getPath(req: CeemsRequest): string;
45
+ /** The Liquid globals for one render: the site data, static globals, and the render state. */
46
+ private globalsFor;
47
+ private renderModule;
48
+ private renderRegion;
49
+ /** Renders a full page with its layout template. */
50
+ renderPage(state: RenderState): Promise<string>;
51
+ /**
52
+ * Renders a page from `load`. Sends the HTML, or returns it when `send` is false. On failure, sends a
53
+ * generic error (404 for a blog page past the last article) and resolves to undefined.
54
+ */
18
55
  render(page: CeemsPage, req: CeemsRequest, res: express.Response, send?: boolean): Promise<string | void>;
19
- postDraft(req: CeemsRequest, res: express.Response): Promise<void>;
56
+ /**
57
+ * `GET /draft/:pageId?token=…[&module=<id>|&region=<key>]`: a verified editor draft, as a full page, one
58
+ * module, or one region. The token is checked here, then used to fetch the draft from the Cee.ms API.
59
+ */
60
+ handleDraft(req: CeemsRequest, res: express.Response): Promise<void>;
20
61
  }