@lit-pigeon/ssr 0.1.4 → 0.2.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/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @lit-pigeon/ssr
2
+
3
+ Server-side rendering API for [Lit Pigeon](https://github.com/snxstudio/lit-pigeon).
4
+ Render, parse, validate, and merge-tag-substitute `PigeonDocument`s from Node
5
+ with **zero DOM dependencies** — built for transactional email pipelines and
6
+ edge/worker runtimes.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @lit-pigeon/ssr
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import {
18
+ renderDocument,
19
+ parseMjml,
20
+ validateDocumentSafe,
21
+ applyMergeTags,
22
+ } from '@lit-pigeon/ssr';
23
+
24
+ // Validate, then render to email-safe HTML — with merge tags substituted.
25
+ const check = validateDocumentSafe(doc);
26
+ if (!check.valid) throw new Error(JSON.stringify(check.errors));
27
+
28
+ const { html, mjml, errors } = await renderDocument(doc, {
29
+ // {{firstName}} and {{user.plan}}; dotted paths read nested objects.
30
+ mergeTags: { firstName: 'Ada', user: { plan: 'Pro' } },
31
+ outlookWorkarounds: true,
32
+ });
33
+
34
+ // Import an existing MJML template into a document.
35
+ const { document, warnings } = parseMjml(existingMjml);
36
+
37
+ // Or substitute {{key}} placeholders into already-rendered HTML.
38
+ const personalised = applyMergeTags(html, { firstName: 'Grace' });
39
+ ```
40
+
41
+ Also exported: `renderDocumentToMjml`, `renderTemplate` (render a stored
42
+ `Template` from `@lit-pigeon/core`), and `extractMergeTags`. Every function is
43
+ stateless — no globals, no editor instance. To serve these over HTTP, use
44
+ [`@lit-pigeon/rest`](../rest).
45
+
46
+ Merge-tag values are HTML-escaped by default (`applyMergeTags(html, values,
47
+ { escape: false })` turns that off), and placeholders without a value are left
48
+ in place unless you set `mergeTagFallback`. `{{#if …}}` blocks from row
49
+ conditions are not evaluated. `validateDocumentSafe` accepts only the built-in
50
+ block types. The `mjml` returned by `renderDocument` does not include
51
+ `<mj-font>` tags even when `fonts` is passed (the `html` does). See
52
+ [Server-side](../../docs/guide/server-side.md) for a render-and-send example.
53
+
54
+ Part of [Lit Pigeon](https://github.com/snxstudio/lit-pigeon) — open-source drag-and-drop email editor.
55
+
56
+ ## License
57
+
58
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { renderDocument, renderDocumentToMjml } from './render.js';
1
+ export { renderDocument, renderDocumentToMjml, renderDocumentToText } from './render.js';
2
2
  export type { RenderDocumentOptions, RenderDocumentResult } from './render.js';
3
3
  export { renderTemplate } from './template.js';
4
4
  export type { RenderTemplateOptions } from './template.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnE,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzF,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnE,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { renderDocument, renderDocumentToMjml } from './render.js';
1
+ export { renderDocument, renderDocumentToMjml, renderDocumentToText } from './render.js';
2
2
  export { renderTemplate } from './template.js';
3
3
  export { parseMjml } from './parse.js';
4
4
  export { validateDocumentSafe } from './validate.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGnE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGzF,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/render.d.ts CHANGED
@@ -29,4 +29,9 @@ export interface RenderDocumentResult {
29
29
  export declare function renderDocument(doc: PigeonDocument, options?: RenderDocumentOptions): Promise<RenderDocumentResult>;
30
30
  /** Render a document straight to MJML markup (no `mjml2html` pass). */
31
31
  export declare function renderDocumentToMjml(doc: PigeonDocument, options?: Pick<RenderOptions, 'outlookWorkarounds'>): string;
32
+ /**
33
+ * Render a document to the `text/plain` alternative part. Merge-tag values
34
+ * are substituted verbatim (no HTML escaping) when supplied.
35
+ */
36
+ export declare function renderDocumentToText(doc: PigeonDocument, options?: Pick<RenderDocumentOptions, 'mergeTags' | 'mergeTagFallback'>): string;
32
37
  //# sourceMappingURL=render.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC1D;;;;OAIG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,qFAAqF;IACrF,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAID;;;GAGG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,oBAAoB,CAAC,CAQ/B;AAED,uEAAuE;AACvE,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAM,GACtD,MAAM,CAER"}
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtE,MAAM,WAAW,qBAAsB,SAAQ,aAAa;IAC1D;;;;OAIG;IACH,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,oBAAoB;IACnC,qFAAqF;IACrF,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAID;;;GAGG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,oBAAoB,CAAC,CAQ/B;AAED,uEAAuE;AACvE,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAM,GACtD,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,cAAc,EACnB,OAAO,GAAE,IAAI,CAAC,qBAAqB,EAAE,WAAW,GAAG,kBAAkB,CAAM,GAC1E,MAAM,CAKR"}
package/dist/render.js CHANGED
@@ -1,4 +1,4 @@
1
- import { documentToMjml, MjmlRenderer } from '@lit-pigeon/renderer-mjml';
1
+ import { documentToMjml, documentToPlainText, MjmlRenderer } from '@lit-pigeon/renderer-mjml';
2
2
  import { applyMergeTags } from './merge-tags.js';
3
3
  const renderer = new MjmlRenderer();
4
4
  /**
@@ -17,4 +17,14 @@ export async function renderDocument(doc, options = {}) {
17
17
  export function renderDocumentToMjml(doc, options = {}) {
18
18
  return documentToMjml(doc, { outlookWorkarounds: options.outlookWorkarounds });
19
19
  }
20
+ /**
21
+ * Render a document to the `text/plain` alternative part. Merge-tag values
22
+ * are substituted verbatim (no HTML escaping) when supplied.
23
+ */
24
+ export function renderDocumentToText(doc, options = {}) {
25
+ const text = documentToPlainText(doc);
26
+ return options.mergeTags && Object.keys(options.mergeTags).length > 0
27
+ ? applyMergeTags(text, options.mergeTags, { fallback: options.mergeTagFallback, escape: false })
28
+ : text;
29
+ }
20
30
  //# sourceMappingURL=render.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAuB,MAAM,iBAAiB,CAAC;AA0BtE,MAAM,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAmB,EACnB,UAAiC,EAAE;IAEnC,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,EAAE,EAAE,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACrF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,IAAI,GACR,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC;QAC5D,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,EA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AAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;AAC/C,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,oBAAoB,CAClC,GAAmB,EACnB,UAAqD,EAAE;IAEvD,OAAO,cAAc,CAAC,GAAG,EAAE,EAAE,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;AACjF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,GAAmB,EACnB,UAAyE,EAAE;IAE3E,MAAM,IAAI,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,GAAG,CAAC;QACnE,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,gBAAgB,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QAChG,CAAC,CAAC,IAAI,CAAC;AACX,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lit-pigeon/ssr",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Server-side rendering API for Lit Pigeon — render, parse, validate, and merge-tag-substitute documents from Node with zero DOM dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,16 +13,18 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE"
17
19
  ],
18
20
  "dependencies": {
19
- "@lit-pigeon/core": "^0.3.0",
20
- "@lit-pigeon/parser-mjml": "^0.1.4",
21
- "@lit-pigeon/renderer-mjml": "^0.2.1"
21
+ "@lit-pigeon/core": "^0.4.0",
22
+ "@lit-pigeon/parser-mjml": "^0.2.0",
23
+ "@lit-pigeon/renderer-mjml": "^0.3.0"
22
24
  },
23
25
  "devDependencies": {
24
26
  "typescript": "^5.5.0",
25
- "vitest": "^2.0.0"
27
+ "vitest": "^4.1.12"
26
28
  },
27
29
  "publishConfig": {
28
30
  "access": "public"
@@ -33,6 +35,20 @@
33
35
  "directory": "packages/ssr"
34
36
  },
35
37
  "license": "MIT",
38
+ "homepage": "https://github.com/snxstudio/lit-pigeon/tree/main/packages/ssr#readme",
39
+ "bugs": "https://github.com/snxstudio/lit-pigeon/issues",
40
+ "author": "Lit Pigeon Contributors",
41
+ "keywords": [
42
+ "email",
43
+ "email-template",
44
+ "email-editor",
45
+ "mjml",
46
+ "html-email",
47
+ "lit",
48
+ "web-components",
49
+ "ssr",
50
+ "server-side-rendering"
51
+ ],
36
52
  "scripts": {
37
53
  "build": "tsc",
38
54
  "dev": "tsc -w",