@lit-pigeon/ssr 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/merge-tags.d.ts +36 -0
- package/dist/merge-tags.d.ts.map +1 -0
- package/dist/merge-tags.js +62 -0
- package/dist/merge-tags.js.map +1 -0
- package/dist/parse.d.ts +13 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +10 -0
- package/dist/parse.js.map +1 -0
- package/dist/render.d.ts +32 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +20 -0
- package/dist/render.js.map +1 -0
- package/dist/template.d.ts +10 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +10 -0
- package/dist/template.js.map +1 -0
- package/dist/validate.d.ts +12 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +11 -0
- package/dist/validate.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lit Pigeon Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { renderDocument, renderDocumentToMjml } from './render.js';
|
|
2
|
+
export type { RenderDocumentOptions, RenderDocumentResult } from './render.js';
|
|
3
|
+
export { renderTemplate } from './template.js';
|
|
4
|
+
export type { RenderTemplateOptions } from './template.js';
|
|
5
|
+
export { parseMjml } from './parse.js';
|
|
6
|
+
export type { ParseMjmlOptions, ParseMjmlResult } from './parse.js';
|
|
7
|
+
export { validateDocumentSafe } from './validate.js';
|
|
8
|
+
export type { ValidateResult } from './validate.js';
|
|
9
|
+
export { applyMergeTags, extractMergeTags } from './merge-tags.js';
|
|
10
|
+
export type { MergeTagValues, ApplyMergeTagsOptions } from './merge-tags.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { renderDocument, renderDocumentToMjml } from './render.js';
|
|
2
|
+
export { renderTemplate } from './template.js';
|
|
3
|
+
export { parseMjml } from './parse.js';
|
|
4
|
+
export { validateDocumentSafe } from './validate.js';
|
|
5
|
+
export { applyMergeTags, extractMergeTags } from './merge-tags.js';
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merge-tag values passed to {@link applyMergeTags}. Nested objects are
|
|
3
|
+
* resolved via dot-path (`user.name` reads `values.user.name`).
|
|
4
|
+
*/
|
|
5
|
+
export type MergeTagValues = Record<string, unknown>;
|
|
6
|
+
export interface ApplyMergeTagsOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Replacement when a placeholder has no matching entry in `values`. If
|
|
9
|
+
* omitted, the original `{{path}}` placeholder is left in place — handy
|
|
10
|
+
* when a downstream ESP performs final substitution.
|
|
11
|
+
*/
|
|
12
|
+
fallback?: string;
|
|
13
|
+
/**
|
|
14
|
+
* When `false`, replacement values are inserted verbatim. Default `true`:
|
|
15
|
+
* `<`, `>`, `&`, `"`, `'` in replacement strings are HTML-escaped so user
|
|
16
|
+
* data can't inject markup.
|
|
17
|
+
*/
|
|
18
|
+
escape?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Replace `{{key}}` placeholders in `html` with values from `values`. Dotted
|
|
22
|
+
* keys (`user.name`) traverse nested objects. By default, replacements are
|
|
23
|
+
* HTML-escaped — disable via `{ escape: false }` if you trust the data.
|
|
24
|
+
*
|
|
25
|
+
* Unknown placeholders are left untouched unless `fallback` is set, so the
|
|
26
|
+
* function is safe to call multiple times in a pipeline (e.g. once on the
|
|
27
|
+
* server, once at send time).
|
|
28
|
+
*/
|
|
29
|
+
export declare function applyMergeTags(html: string, values: MergeTagValues, options?: ApplyMergeTagsOptions): string;
|
|
30
|
+
/**
|
|
31
|
+
* Return the set of distinct merge-tag paths referenced by `html`, sorted
|
|
32
|
+
* alphabetically. Useful for surfacing required template variables to the
|
|
33
|
+
* caller before sending.
|
|
34
|
+
*/
|
|
35
|
+
export declare function extractMergeTags(html: string): string[];
|
|
36
|
+
//# sourceMappingURL=merge-tags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-tags.d.ts","sourceRoot":"","sources":["../src/merge-tags.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAErD,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAID;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,qBAA0B,GAClC,MAAM,CAUR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMvD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const PLACEHOLDER = /\{\{\s*([\w.-]+)\s*\}\}/g;
|
|
2
|
+
/**
|
|
3
|
+
* Replace `{{key}}` placeholders in `html` with values from `values`. Dotted
|
|
4
|
+
* keys (`user.name`) traverse nested objects. By default, replacements are
|
|
5
|
+
* HTML-escaped — disable via `{ escape: false }` if you trust the data.
|
|
6
|
+
*
|
|
7
|
+
* Unknown placeholders are left untouched unless `fallback` is set, so the
|
|
8
|
+
* function is safe to call multiple times in a pipeline (e.g. once on the
|
|
9
|
+
* server, once at send time).
|
|
10
|
+
*/
|
|
11
|
+
export function applyMergeTags(html, values, options = {}) {
|
|
12
|
+
const { fallback, escape = true } = options;
|
|
13
|
+
return html.replace(PLACEHOLDER, (match, path) => {
|
|
14
|
+
const resolved = resolvePath(values, path);
|
|
15
|
+
if (resolved === undefined) {
|
|
16
|
+
return fallback ?? match;
|
|
17
|
+
}
|
|
18
|
+
const str = stringify(resolved);
|
|
19
|
+
return escape ? escapeHtml(str) : str;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Return the set of distinct merge-tag paths referenced by `html`, sorted
|
|
24
|
+
* alphabetically. Useful for surfacing required template variables to the
|
|
25
|
+
* caller before sending.
|
|
26
|
+
*/
|
|
27
|
+
export function extractMergeTags(html) {
|
|
28
|
+
const found = new Set();
|
|
29
|
+
for (const match of html.matchAll(PLACEHOLDER)) {
|
|
30
|
+
found.add(match[1]);
|
|
31
|
+
}
|
|
32
|
+
return Array.from(found).sort();
|
|
33
|
+
}
|
|
34
|
+
function resolvePath(values, path) {
|
|
35
|
+
let current = values;
|
|
36
|
+
for (const part of path.split('.')) {
|
|
37
|
+
if (current === null || typeof current !== 'object')
|
|
38
|
+
return undefined;
|
|
39
|
+
current = current[part];
|
|
40
|
+
if (current === undefined)
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
function stringify(value) {
|
|
46
|
+
if (value === null || value === undefined)
|
|
47
|
+
return '';
|
|
48
|
+
if (typeof value === 'string')
|
|
49
|
+
return value;
|
|
50
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
51
|
+
return String(value);
|
|
52
|
+
return JSON.stringify(value);
|
|
53
|
+
}
|
|
54
|
+
function escapeHtml(input) {
|
|
55
|
+
return input
|
|
56
|
+
.replace(/&/g, '&')
|
|
57
|
+
.replace(/</g, '<')
|
|
58
|
+
.replace(/>/g, '>')
|
|
59
|
+
.replace(/"/g, '"')
|
|
60
|
+
.replace(/'/g, ''');
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=merge-tags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-tags.js","sourceRoot":"","sources":["../src/merge-tags.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAE/C;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,MAAsB,EACtB,UAAiC,EAAE;IAEnC,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC;IAC5C,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,IAAY,EAAE,EAAE;QACvD,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,OAAO,QAAQ,IAAI,KAAK,CAAC;QAC3B,CAAC;QACD,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QAChC,OAAO,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/C,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,WAAW,CAAC,MAAsB,EAAE,IAAY;IACvD,IAAI,OAAO,GAAY,MAAM,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACnC,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACtE,OAAO,GAAI,OAAmC,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,SAAS,CAAC;IAC9C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAClF,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK;SACT,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PigeonDocument } from '@lit-pigeon/core';
|
|
2
|
+
import { type ParseOptions, type ParseWarning } from '@lit-pigeon/parser-mjml';
|
|
3
|
+
export type ParseMjmlOptions = ParseOptions;
|
|
4
|
+
export interface ParseMjmlResult {
|
|
5
|
+
document: PigeonDocument;
|
|
6
|
+
warnings: ParseWarning[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Parse MJML markup into a `PigeonDocument`. Mirrors `@lit-pigeon/parser-mjml`
|
|
10
|
+
* but is re-exported here so an SSR consumer only needs one dependency.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseMjml(mjml: string, options?: ParseMjmlOptions): ParseMjmlResult;
|
|
13
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAkB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE/F,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,eAAe,CAGnF"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { mjmlToDocument } from '@lit-pigeon/parser-mjml';
|
|
2
|
+
/**
|
|
3
|
+
* Parse MJML markup into a `PigeonDocument`. Mirrors `@lit-pigeon/parser-mjml`
|
|
4
|
+
* but is re-exported here so an SSR consumer only needs one dependency.
|
|
5
|
+
*/
|
|
6
|
+
export function parseMjml(mjml, options) {
|
|
7
|
+
const result = mjmlToDocument(mjml, options);
|
|
8
|
+
return { document: result.document, warnings: result.warnings };
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAwC,MAAM,yBAAyB,CAAC;AAS/F;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,OAA0B;IAChE,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;AAClE,CAAC"}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { PigeonDocument, RenderError, RenderOptions } from '@lit-pigeon/core';
|
|
2
|
+
import { type MergeTagValues } from './merge-tags.js';
|
|
3
|
+
export interface RenderDocumentOptions extends RenderOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Merge-tag values to substitute into the rendered HTML.
|
|
6
|
+
* Keys map `{{key}}` placeholders; missing keys are left intact (or replaced
|
|
7
|
+
* via `mergeTagFallback`).
|
|
8
|
+
*/
|
|
9
|
+
mergeTags?: MergeTagValues;
|
|
10
|
+
/**
|
|
11
|
+
* Value used when a placeholder has no entry in `mergeTags`. Default: leave
|
|
12
|
+
* the `{{key}}` placeholder untouched, which is useful for downstream ESP
|
|
13
|
+
* substitution.
|
|
14
|
+
*/
|
|
15
|
+
mergeTagFallback?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RenderDocumentResult {
|
|
18
|
+
/** Email-client-safe HTML, already merge-tag substituted if values were supplied. */
|
|
19
|
+
html: string;
|
|
20
|
+
/** The intermediate MJML markup, exposed for debugging and snapshot tests. */
|
|
21
|
+
mjml: string;
|
|
22
|
+
/** Renderer errors (empty array on success). */
|
|
23
|
+
errors: RenderError[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Render a `PigeonDocument` to email HTML. Stateless and safe to call from
|
|
27
|
+
* any server context — no DOM, no globals, no editor instance required.
|
|
28
|
+
*/
|
|
29
|
+
export declare function renderDocument(doc: PigeonDocument, options?: RenderDocumentOptions): Promise<RenderDocumentResult>;
|
|
30
|
+
/** Render a document straight to MJML markup (no `mjml2html` pass). */
|
|
31
|
+
export declare function renderDocumentToMjml(doc: PigeonDocument, options?: Pick<RenderOptions, 'outlookWorkarounds'>): string;
|
|
32
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { documentToMjml, MjmlRenderer } from '@lit-pigeon/renderer-mjml';
|
|
2
|
+
import { applyMergeTags } from './merge-tags.js';
|
|
3
|
+
const renderer = new MjmlRenderer();
|
|
4
|
+
/**
|
|
5
|
+
* Render a `PigeonDocument` to email HTML. Stateless and safe to call from
|
|
6
|
+
* any server context — no DOM, no globals, no editor instance required.
|
|
7
|
+
*/
|
|
8
|
+
export async function renderDocument(doc, options = {}) {
|
|
9
|
+
const mjml = documentToMjml(doc, { outlookWorkarounds: options.outlookWorkarounds });
|
|
10
|
+
const result = await renderer.render(doc, options);
|
|
11
|
+
const html = options.mergeTags && Object.keys(options.mergeTags).length > 0
|
|
12
|
+
? applyMergeTags(result.html, options.mergeTags, { fallback: options.mergeTagFallback })
|
|
13
|
+
: result.html;
|
|
14
|
+
return { html, mjml, errors: result.errors };
|
|
15
|
+
}
|
|
16
|
+
/** Render a document straight to MJML markup (no `mjml2html` pass). */
|
|
17
|
+
export function renderDocumentToMjml(doc, options = {}) {
|
|
18
|
+
return documentToMjml(doc, { outlookWorkarounds: options.outlookWorkarounds });
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +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,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC;QACxF,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;IAClB,OAAO,EAAE,IAAI,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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Template } from '@lit-pigeon/core';
|
|
2
|
+
import { type RenderDocumentOptions, type RenderDocumentResult } from './render.js';
|
|
3
|
+
export type RenderTemplateOptions = RenderDocumentOptions;
|
|
4
|
+
/**
|
|
5
|
+
* Render a stored `Template` to HTML. Useful when a transactional service
|
|
6
|
+
* loads a template by id from its database and needs to ship the rendered
|
|
7
|
+
* email immediately.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderTemplate(template: Template, options?: RenderTemplateOptions): Promise<RenderDocumentResult>;
|
|
10
|
+
//# sourceMappingURL=template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAkB,KAAK,qBAAqB,EAAE,KAAK,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEpG,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,oBAAoB,CAAC,CAE/B"}
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { renderDocument } from './render.js';
|
|
2
|
+
/**
|
|
3
|
+
* Render a stored `Template` to HTML. Useful when a transactional service
|
|
4
|
+
* loads a template by id from its database and needs to ship the rendered
|
|
5
|
+
* email immediately.
|
|
6
|
+
*/
|
|
7
|
+
export function renderTemplate(template, options = {}) {
|
|
8
|
+
return renderDocument(template.document, options);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAyD,MAAM,aAAa,CAAC;AAIpG;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAkB,EAClB,UAAiC,EAAE;IAEnC,OAAO,cAAc,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ValidationError } from '@lit-pigeon/core';
|
|
2
|
+
export interface ValidateResult {
|
|
3
|
+
valid: boolean;
|
|
4
|
+
errors: ValidationError[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Validate an untrusted document and return both the verdict and the list
|
|
8
|
+
* of errors in one call. `validateDocument` from core already tolerates
|
|
9
|
+
* non-object input — this wrapper just packages the result for REST callers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateDocumentSafe(doc: unknown): ValidateResult;
|
|
12
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAGjE"}
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { validateDocument } from '@lit-pigeon/core';
|
|
2
|
+
/**
|
|
3
|
+
* Validate an untrusted document and return both the verdict and the list
|
|
4
|
+
* of errors in one call. `validateDocument` from core already tolerates
|
|
5
|
+
* non-object input — this wrapper just packages the result for REST callers.
|
|
6
|
+
*/
|
|
7
|
+
export function validateDocumentSafe(doc) {
|
|
8
|
+
const errors = validateDocument(doc);
|
|
9
|
+
return { valid: errors.length === 0, errors };
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAOpD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAY;IAC/C,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lit-pigeon/ssr",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Server-side rendering API for Lit Pigeon — render, parse, validate, and merge-tag-substitute documents from Node with zero DOM dependencies.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@lit-pigeon/core": "0.1.0",
|
|
20
|
+
"@lit-pigeon/parser-mjml": "0.1.0",
|
|
21
|
+
"@lit-pigeon/renderer-mjml": "0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5.5.0",
|
|
25
|
+
"vitest": "^2.0.0"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/snxstudio/lit-pigeon.git",
|
|
33
|
+
"directory": "packages/ssr"
|
|
34
|
+
},
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"dev": "tsc -w",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:watch": "vitest",
|
|
41
|
+
"clean": "rm -rf dist"
|
|
42
|
+
}
|
|
43
|
+
}
|