@jsb188/mday 1.1.2
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/package.json +142 -0
- package/src/constants/agentMemory.ts +166 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +22 -0
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +146 -0
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +21 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2199 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +60 -0
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +132 -0
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +85 -0
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +879 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +93 -0
- package/src/types/account.d.ts +81 -0
- package/src/types/agentMemory.d.ts +100 -0
- package/src/types/agentNote.d.ts +441 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +159 -0
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +231 -0
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +65 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +338 -0
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +350 -0
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +847 -0
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +481 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +435 -0
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1173 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +311 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +379 -0
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +357 -0
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +669 -0
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +262 -0
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +506 -0
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import type { RichTextContent, RichTextInlineContent, RichTextMark } from '@jsb188/mday/types/richText.d.ts';
|
|
2
|
+
import { CAMPAIGN_EMAIL_FONT_FAMILY_NAME, CAMPAIGN_EMAIL_UNSUBSCRIBE_URL_PLACEHOLDER } from '../constants/campaign.ts';
|
|
3
|
+
import type {
|
|
4
|
+
CampaignEmailBlockObj,
|
|
5
|
+
CampaignEmailBlockSettingsObj,
|
|
6
|
+
CampaignEmailDefinitionObj,
|
|
7
|
+
CampaignEmailRowObj,
|
|
8
|
+
EmailCampaignPreviewGQL,
|
|
9
|
+
EmailCampaignSettingsObj,
|
|
10
|
+
} from '../types/campaign.d.ts';
|
|
11
|
+
import {
|
|
12
|
+
getCampaignEmailBlockContent,
|
|
13
|
+
getCampaignEmailBlockFileURI,
|
|
14
|
+
getCampaignEmailBlockSettings,
|
|
15
|
+
getCampaignEmailBlockText,
|
|
16
|
+
getCampaignEmailHeadingLevel,
|
|
17
|
+
getCampaignEmailRichTextNoteDoc,
|
|
18
|
+
getCampaignEmailRowSettings,
|
|
19
|
+
isCampaignEmailImageURL,
|
|
20
|
+
isCampaignEmailLink,
|
|
21
|
+
} from './campaignEmail.ts';
|
|
22
|
+
import { getCampaignEmailImageSource } from './campaignEmailImages.ts';
|
|
23
|
+
import {
|
|
24
|
+
CAMPAIGN_EMAIL_BLOCKQUOTE_STYLE,
|
|
25
|
+
CAMPAIGN_EMAIL_COLUMNS_STYLE,
|
|
26
|
+
CAMPAIGN_EMAIL_DIVIDER_STYLE,
|
|
27
|
+
CAMPAIGN_EMAIL_FOOTER_STYLE,
|
|
28
|
+
CAMPAIGN_EMAIL_HERO_IMAGE_STYLE,
|
|
29
|
+
CAMPAIGN_EMAIL_HERO_TEXT_STYLE,
|
|
30
|
+
CAMPAIGN_EMAIL_IMAGE_STYLE,
|
|
31
|
+
CAMPAIGN_EMAIL_LIST_ITEM_STYLE,
|
|
32
|
+
CAMPAIGN_EMAIL_PARAGRAPH_STYLE,
|
|
33
|
+
CAMPAIGN_EMAIL_PREHEADER_STYLE,
|
|
34
|
+
CAMPAIGN_EMAIL_RICH_TEXT_DIVIDER_STYLE,
|
|
35
|
+
CAMPAIGN_EMAIL_RICH_TEXT_IMAGE_STYLE,
|
|
36
|
+
type CampaignEmailResolvedDesignObj,
|
|
37
|
+
type CampaignEmailStyleObj,
|
|
38
|
+
getCampaignEmailBlockStyle,
|
|
39
|
+
getCampaignEmailButtonStyle,
|
|
40
|
+
getCampaignEmailCanvasCellStyle,
|
|
41
|
+
getCampaignEmailCanvasStyle,
|
|
42
|
+
getCampaignEmailColumnStyle,
|
|
43
|
+
getCampaignEmailContentCellStyle,
|
|
44
|
+
getCampaignEmailContentStyle,
|
|
45
|
+
getCampaignEmailEmphasisStyle,
|
|
46
|
+
getCampaignEmailFontFaceCSS,
|
|
47
|
+
getCampaignEmailHeadingStyle,
|
|
48
|
+
getCampaignEmailHorizontalPadding,
|
|
49
|
+
getCampaignEmailLinkStyle,
|
|
50
|
+
getCampaignEmailListStyle,
|
|
51
|
+
getCampaignEmailMenuLinkStyle,
|
|
52
|
+
getCampaignEmailResolvedDesign,
|
|
53
|
+
getCampaignEmailResponsiveCSS,
|
|
54
|
+
getCampaignEmailRichTextHeadingStyle,
|
|
55
|
+
getCampaignEmailRowCellStyle,
|
|
56
|
+
getCampaignEmailRowStyle,
|
|
57
|
+
getCampaignEmailSpacerStyle,
|
|
58
|
+
getCampaignEmailTextStyle,
|
|
59
|
+
serializeCampaignEmailStyle,
|
|
60
|
+
} from './campaignEmailStyles.ts';
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* Compile one normalized email definition into the delivered HTML document and
|
|
64
|
+
* its plain-text alternative. The browser preview uses the same shared styles
|
|
65
|
+
* so recipients see the authored design with email-compatible markup.
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
const FILE_CONSTANTS = {
|
|
69
|
+
defaultSenderName: 'this organization',
|
|
70
|
+
defaultVideoLabel: 'Watch video',
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* Escape one string for safe use as HTML text or an attribute value.
|
|
75
|
+
*/
|
|
76
|
+
export function escapeCampaignEmailHTML(value: unknown): string {
|
|
77
|
+
return String(value ?? '')
|
|
78
|
+
.replaceAll('&', '&')
|
|
79
|
+
.replaceAll('<', '<')
|
|
80
|
+
.replaceAll('>', '>')
|
|
81
|
+
.replaceAll('"', '"')
|
|
82
|
+
.replaceAll("'", ''');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/*
|
|
86
|
+
* Serialize one shared style object as an escaped inline style attribute.
|
|
87
|
+
*/
|
|
88
|
+
function getStyleAttribute(style: CampaignEmailStyleObj): string {
|
|
89
|
+
return ` style="${escapeCampaignEmailHTML(serializeCampaignEmailStyle(style))}"`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Render one escaped anchor with a safe destination.
|
|
94
|
+
*/
|
|
95
|
+
function renderLink(url: string, style: CampaignEmailStyleObj, innerHTML: string): string {
|
|
96
|
+
return `<a href="${escapeCampaignEmailHTML(url)}"${getStyleAttribute(style)}>${innerHTML}</a>`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
* Render one escaped image with a safe absolute source. A known slot width is
|
|
101
|
+
* also written as the HTML width attribute, because Outlook ignores CSS widths
|
|
102
|
+
* and would otherwise show the full-size image.
|
|
103
|
+
*/
|
|
104
|
+
function renderImage(uri: string, altText: string | null | undefined, style: CampaignEmailStyleObj, width?: number): string {
|
|
105
|
+
const widthAttribute = width && Number.isFinite(width) ? ` width="${Math.max(1, Math.floor(width))}"` : '';
|
|
106
|
+
return `<img src="${escapeCampaignEmailHTML(uri)}" alt="${escapeCampaignEmailHTML(altText)}"${widthAttribute}${getStyleAttribute(style)}>`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
* Wrap one escaped rich-text run in its supported semantic email-safe marks.
|
|
111
|
+
*/
|
|
112
|
+
function renderInlineMarks(html: string, design: CampaignEmailResolvedDesignObj, marks?: RichTextMark[]): string {
|
|
113
|
+
let output = html;
|
|
114
|
+
|
|
115
|
+
for (const mark of marks || []) {
|
|
116
|
+
switch (mark.type) {
|
|
117
|
+
case 'bold':
|
|
118
|
+
output = `<strong${getStyleAttribute(getCampaignEmailEmphasisStyle(design))}>${output}</strong>`;
|
|
119
|
+
break;
|
|
120
|
+
case 'italic':
|
|
121
|
+
output = `<em>${output}</em>`;
|
|
122
|
+
break;
|
|
123
|
+
case 'underline':
|
|
124
|
+
output = `<u>${output}</u>`;
|
|
125
|
+
break;
|
|
126
|
+
case 'strike':
|
|
127
|
+
output = `<s>${output}</s>`;
|
|
128
|
+
break;
|
|
129
|
+
case 'code':
|
|
130
|
+
output = `<code>${output}</code>`;
|
|
131
|
+
break;
|
|
132
|
+
case 'link': {
|
|
133
|
+
const href = mark.attrs?.href;
|
|
134
|
+
if (isCampaignEmailLink(href)) {
|
|
135
|
+
output = renderLink(String(href), getCampaignEmailLinkStyle(design), output);
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return output;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
* Render one sanitized inline rich-text list to email-safe HTML.
|
|
147
|
+
*/
|
|
148
|
+
function renderInlineNodes(nodes: RichTextInlineContent[] | undefined, design: CampaignEmailResolvedDesignObj): string {
|
|
149
|
+
return (nodes || [])
|
|
150
|
+
.map((node) => (node.type === 'hardBreak' ? '<br>' : renderInlineMarks(escapeCampaignEmailHTML(node.text), design, node.marks)))
|
|
151
|
+
.join('');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/*
|
|
155
|
+
* Render sanitized rich-text blocks recursively without browser-only DOM APIs.
|
|
156
|
+
* The slot width sizes inline images served by the asset server.
|
|
157
|
+
*/
|
|
158
|
+
function renderRichTextBlocks(
|
|
159
|
+
blocks: RichTextContent[] | undefined,
|
|
160
|
+
design: CampaignEmailResolvedDesignObj,
|
|
161
|
+
slotWidth?: number,
|
|
162
|
+
): string {
|
|
163
|
+
return (blocks || [])
|
|
164
|
+
.map((block) => {
|
|
165
|
+
const children = Array.isArray(block.content) ? (block.content as RichTextContent[]) : [];
|
|
166
|
+
const inline = block.content as RichTextInlineContent[] | undefined;
|
|
167
|
+
|
|
168
|
+
switch (block.type) {
|
|
169
|
+
case 'paragraph':
|
|
170
|
+
return `<p${getStyleAttribute(CAMPAIGN_EMAIL_PARAGRAPH_STYLE)}>${renderInlineNodes(inline, design)}</p>`;
|
|
171
|
+
case 'heading': {
|
|
172
|
+
const level = getCampaignEmailHeadingLevel(block.attrs?.level);
|
|
173
|
+
return `<h${level}${getStyleAttribute(getCampaignEmailRichTextHeadingStyle(level, design))}>${renderInlineNodes(inline, design)}</h${level}>`;
|
|
174
|
+
}
|
|
175
|
+
case 'bulletList':
|
|
176
|
+
return `<ul${getStyleAttribute(getCampaignEmailListStyle(false))}>${renderRichTextBlocks(children, design, slotWidth)}</ul>`;
|
|
177
|
+
case 'orderedList':
|
|
178
|
+
return `<ol${getStyleAttribute(getCampaignEmailListStyle(true))}>${renderRichTextBlocks(children, design, slotWidth)}</ol>`;
|
|
179
|
+
case 'listItem':
|
|
180
|
+
return `<li${getStyleAttribute(CAMPAIGN_EMAIL_LIST_ITEM_STYLE)}>${renderRichTextBlocks(children, design, slotWidth)}</li>`;
|
|
181
|
+
case 'blockquote':
|
|
182
|
+
return `<blockquote${getStyleAttribute(CAMPAIGN_EMAIL_BLOCKQUOTE_STYLE)}>${renderRichTextBlocks(children, design, slotWidth)}</blockquote>`;
|
|
183
|
+
case 'divider':
|
|
184
|
+
return `<hr${getStyleAttribute(CAMPAIGN_EMAIL_RICH_TEXT_DIVIDER_STYLE)}>`;
|
|
185
|
+
case 'image': {
|
|
186
|
+
const uri = getCampaignEmailImageSource(block.attrs?.fileUri, slotWidth);
|
|
187
|
+
return isCampaignEmailImageURL(uri) ? renderImage(uri, block.attrs?.alt, CAMPAIGN_EMAIL_RICH_TEXT_IMAGE_STYLE) : '';
|
|
188
|
+
}
|
|
189
|
+
default:
|
|
190
|
+
return '';
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
.join('');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/*
|
|
197
|
+
* Render one email-safe call-to-action shared by BUTTON and HERO blocks.
|
|
198
|
+
*/
|
|
199
|
+
function renderButton(
|
|
200
|
+
label: string | null | undefined,
|
|
201
|
+
url: string | null | undefined,
|
|
202
|
+
settings: CampaignEmailBlockSettingsObj,
|
|
203
|
+
): string {
|
|
204
|
+
if (!label?.trim() || !isCampaignEmailLink(url)) {
|
|
205
|
+
return '';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return renderLink(String(url), getCampaignEmailButtonStyle(settings), escapeCampaignEmailHTML(label));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/*
|
|
212
|
+
* Render the inner HTML of one block, or an empty string when it has nothing
|
|
213
|
+
* to show.
|
|
214
|
+
*/
|
|
215
|
+
function renderBlockBody(block: CampaignEmailBlockObj, design: CampaignEmailResolvedDesignObj, slotWidth: number): string {
|
|
216
|
+
const content = getCampaignEmailBlockContent(block.content);
|
|
217
|
+
const settings = getCampaignEmailBlockSettings(block.settings);
|
|
218
|
+
const imageWidth = slotWidth - getCampaignEmailHorizontalPadding(settings.padding);
|
|
219
|
+
|
|
220
|
+
switch (block.type) {
|
|
221
|
+
case 'HEADING': {
|
|
222
|
+
const heading = String(content.heading || content.text || '').trim();
|
|
223
|
+
if (!heading) {
|
|
224
|
+
return '';
|
|
225
|
+
}
|
|
226
|
+
const level = getCampaignEmailHeadingLevel(content.headingLevel);
|
|
227
|
+
return `<h${level}${getStyleAttribute(getCampaignEmailHeadingStyle(level, design, settings.fontSize))}>${escapeCampaignEmailHTML(heading)}</h${level}>`;
|
|
228
|
+
}
|
|
229
|
+
case 'RICH_TEXT':
|
|
230
|
+
return renderRichTextBlocks(getCampaignEmailRichTextNoteDoc(content.richText).content, design, imageWidth);
|
|
231
|
+
case 'IMAGE': {
|
|
232
|
+
const uri = getCampaignEmailImageSource(getCampaignEmailBlockFileURI(block) || content.url, imageWidth);
|
|
233
|
+
return isCampaignEmailImageURL(uri) ? renderImage(uri, content.altText, CAMPAIGN_EMAIL_IMAGE_STYLE, imageWidth) : '';
|
|
234
|
+
}
|
|
235
|
+
case 'HERO': {
|
|
236
|
+
const uri = getCampaignEmailImageSource(getCampaignEmailBlockFileURI(block) || content.url, imageWidth);
|
|
237
|
+
const image = isCampaignEmailImageURL(uri) ? renderImage(uri, content.altText, CAMPAIGN_EMAIL_HERO_IMAGE_STYLE, imageWidth) : '';
|
|
238
|
+
const heading = content.heading?.trim()
|
|
239
|
+
? `<h2${getStyleAttribute(getCampaignEmailRichTextHeadingStyle(2, design))}>${escapeCampaignEmailHTML(content.heading)}</h2>`
|
|
240
|
+
: '';
|
|
241
|
+
const text = content.text?.trim()
|
|
242
|
+
? `<p${getStyleAttribute(CAMPAIGN_EMAIL_HERO_TEXT_STYLE)}>${escapeCampaignEmailHTML(content.text)}</p>`
|
|
243
|
+
: '';
|
|
244
|
+
return `${image}${heading}${text}${renderButton(content.buttonLabel, content.buttonUrl, settings)}`;
|
|
245
|
+
}
|
|
246
|
+
case 'VIDEO': {
|
|
247
|
+
if (!isCampaignEmailImageURL(content.url)) {
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
250
|
+
const thumbnail = getCampaignEmailImageSource(getCampaignEmailBlockFileURI(block), imageWidth);
|
|
251
|
+
return renderLink(
|
|
252
|
+
String(content.url),
|
|
253
|
+
getCampaignEmailLinkStyle(design),
|
|
254
|
+
isCampaignEmailImageURL(thumbnail)
|
|
255
|
+
? renderImage(thumbnail, content.altText, CAMPAIGN_EMAIL_IMAGE_STYLE, imageWidth)
|
|
256
|
+
: escapeCampaignEmailHTML(content.altText || FILE_CONSTANTS.defaultVideoLabel),
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
case 'BUTTON':
|
|
260
|
+
return renderButton(content.buttonLabel, content.buttonUrl, settings);
|
|
261
|
+
case 'DIVIDER':
|
|
262
|
+
return `<hr${getStyleAttribute(CAMPAIGN_EMAIL_DIVIDER_STYLE)}>`;
|
|
263
|
+
case 'SPACER':
|
|
264
|
+
return `<div${getStyleAttribute(getCampaignEmailSpacerStyle(settings.height || 24))}> </div>`;
|
|
265
|
+
case 'SOCIAL':
|
|
266
|
+
case 'MENU':
|
|
267
|
+
return content.links
|
|
268
|
+
.filter((link) => isCampaignEmailLink(link.url))
|
|
269
|
+
.map((link) => renderLink(link.url, getCampaignEmailMenuLinkStyle(design), escapeCampaignEmailHTML(link.label)))
|
|
270
|
+
.join('');
|
|
271
|
+
default:
|
|
272
|
+
return '';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/*
|
|
277
|
+
* Compile one email block to safe, table-compatible HTML. A block with
|
|
278
|
+
* nothing to show is omitted entirely rather than sent as empty padding.
|
|
279
|
+
*/
|
|
280
|
+
function renderBlock(block: CampaignEmailBlockObj, design: CampaignEmailResolvedDesignObj, slotWidth: number): string {
|
|
281
|
+
const body = renderBlockBody(block, design, slotWidth);
|
|
282
|
+
if (!body) {
|
|
283
|
+
return '';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const style = getCampaignEmailBlockStyle(getCampaignEmailBlockSettings(block.settings), design);
|
|
287
|
+
return `<div${getStyleAttribute(style)}>${body}</div>`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/*
|
|
291
|
+
* Compile one normalized row into presentation tables, nesting a column table
|
|
292
|
+
* only for multi-column layouts. Omit rows whose blocks all rendered empty.
|
|
293
|
+
*/
|
|
294
|
+
function renderRow(row: CampaignEmailRowObj, design: CampaignEmailResolvedDesignObj, contentSlotWidth: number): string {
|
|
295
|
+
const settings = getCampaignEmailRowSettings(row.settings);
|
|
296
|
+
const textStyle = getCampaignEmailTextStyle(design);
|
|
297
|
+
const rowSlotWidth = contentSlotWidth - getCampaignEmailHorizontalPadding(settings.padding);
|
|
298
|
+
const columns = [...row.columns]
|
|
299
|
+
.sort((a, b) => a.order - b.order)
|
|
300
|
+
.map((column) => ({
|
|
301
|
+
column,
|
|
302
|
+
blocks: [...column.blocks]
|
|
303
|
+
.sort((a, b) => a.order - b.order)
|
|
304
|
+
.map((block) => renderBlock(block, design, (rowSlotWidth * column.width) / 100))
|
|
305
|
+
.join(''),
|
|
306
|
+
}));
|
|
307
|
+
if (columns.every((rendered) => !rendered.blocks)) {
|
|
308
|
+
return '';
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (columns.length === 1 && columns[0].column.width === 100) {
|
|
312
|
+
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0"${getStyleAttribute({ ...textStyle, ...getCampaignEmailRowStyle(settings) })}><tr><td valign="top"${getStyleAttribute({ ...textStyle, ...getCampaignEmailRowCellStyle(settings) })}>${columns[0].blocks}</td></tr></table>`;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const cells = columns
|
|
316
|
+
.map(
|
|
317
|
+
({ column, blocks }) =>
|
|
318
|
+
`<td class="campaign-email-column" width="${column.width}%" valign="top"${getStyleAttribute({ ...textStyle, ...getCampaignEmailColumnStyle(column.width) })}>${blocks}</td>`,
|
|
319
|
+
)
|
|
320
|
+
.join('');
|
|
321
|
+
return `<table role="presentation" width="100%" cellpadding="0" cellspacing="0"${getStyleAttribute({ ...textStyle, ...getCampaignEmailRowStyle(settings) })}><tr><td${getStyleAttribute({ ...textStyle, ...getCampaignEmailRowCellStyle(settings) })}><table role="presentation" width="100%" cellpadding="0" cellspacing="0"${getStyleAttribute({ ...textStyle, ...CAMPAIGN_EMAIL_COLUMNS_STYLE })}><tr>${cells}</tr></table></td></tr></table>`;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/*
|
|
325
|
+
* Compile one email definition into the canonical delivery HTML and plain-text
|
|
326
|
+
* pair. Uploaded images link to the asset server at a size that fits their
|
|
327
|
+
* slot. The server replaces the unsubscribe placeholder per recipient after
|
|
328
|
+
* this deterministic base compilation.
|
|
329
|
+
*/
|
|
330
|
+
export function compileCampaignEmailDefinition(input: {
|
|
331
|
+
definition: CampaignEmailDefinitionObj;
|
|
332
|
+
settings: EmailCampaignSettingsObj;
|
|
333
|
+
organizationName?: string | null;
|
|
334
|
+
unsubscribeUrl?: string | null;
|
|
335
|
+
}): EmailCampaignPreviewGQL {
|
|
336
|
+
const design = getCampaignEmailResolvedDesign(input.settings.design);
|
|
337
|
+
// The same slot arithmetic as the preview renderer, starting from the content column.
|
|
338
|
+
const contentSlotWidth = design.contentWidth - getCampaignEmailHorizontalPadding(design.padding);
|
|
339
|
+
const rows = [...input.definition.rows]
|
|
340
|
+
.sort((a, b) => a.order - b.order)
|
|
341
|
+
.map((row) => renderRow(row, design, contentSlotWidth))
|
|
342
|
+
.join('');
|
|
343
|
+
const unsubscribeUrl =
|
|
344
|
+
input.unsubscribeUrl && isCampaignEmailLink(input.unsubscribeUrl)
|
|
345
|
+
? input.unsubscribeUrl
|
|
346
|
+
: CAMPAIGN_EMAIL_UNSUBSCRIBE_URL_PLACEHOLDER;
|
|
347
|
+
const sender = input.organizationName || FILE_CONSTANTS.defaultSenderName;
|
|
348
|
+
const footer = `<p${getStyleAttribute(CAMPAIGN_EMAIL_FOOTER_STYLE)}>Sent by ${escapeCampaignEmailHTML(sender)}. ${renderLink(unsubscribeUrl, getCampaignEmailLinkStyle(design), 'Unsubscribe')}</p>`;
|
|
349
|
+
const usesCustomFont = design.fontFamily.split(',').some(
|
|
350
|
+
(family) =>
|
|
351
|
+
family
|
|
352
|
+
.trim()
|
|
353
|
+
.replace(/^['"]|['"]$/g, '')
|
|
354
|
+
.toLowerCase() === CAMPAIGN_EMAIL_FONT_FAMILY_NAME,
|
|
355
|
+
);
|
|
356
|
+
const head = `<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>${usesCustomFont ? getCampaignEmailFontFaceCSS() : ''}${getCampaignEmailResponsiveCSS(design)}</style>`;
|
|
357
|
+
const preheader = input.settings.preheader?.trim()
|
|
358
|
+
? `<div${getStyleAttribute(CAMPAIGN_EMAIL_PREHEADER_STYLE)}>${escapeCampaignEmailHTML(input.settings.preheader)}</div>`
|
|
359
|
+
: '';
|
|
360
|
+
const body = `${preheader}<table role="presentation" width="100%" cellpadding="0" cellspacing="0"${getStyleAttribute(getCampaignEmailCanvasStyle(design))}><tr><td align="center" class="campaign-email-canvas-cell"${getStyleAttribute(getCampaignEmailCanvasCellStyle(design))}><table role="presentation" class="campaign-email" width="${design.contentWidth}" cellpadding="0" cellspacing="0"${getStyleAttribute(getCampaignEmailContentStyle(design))}><tr><td${getStyleAttribute(getCampaignEmailContentCellStyle(design))}>${rows}</td></tr></table>${footer}</td></tr></table>`;
|
|
361
|
+
const html = `<!doctype html><html><head>${head}</head><body${getStyleAttribute({ ...getCampaignEmailTextStyle(design), background: design.canvasColor, margin: '0', padding: '0' })}>${body}</body></html>`;
|
|
362
|
+
|
|
363
|
+
const blockText = input.definition.rows
|
|
364
|
+
.flatMap((row) => row.columns)
|
|
365
|
+
.flatMap((column) => column.blocks)
|
|
366
|
+
.map(getCampaignEmailBlockText)
|
|
367
|
+
.filter(Boolean)
|
|
368
|
+
.join('\n\n');
|
|
369
|
+
const text = [blockText, `Sent by ${sender}. Unsubscribe: ${unsubscribeUrl}`].filter(Boolean).join('\n\n');
|
|
370
|
+
|
|
371
|
+
return { html, text };
|
|
372
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { makeUploadsUrl } from '@jsb188/app/utils/url_client.ts';
|
|
2
|
+
|
|
3
|
+
export type CampaignEmailImageAssetSize = 'small' | 'medium';
|
|
4
|
+
|
|
5
|
+
const FILE_CONSTANTS = {
|
|
6
|
+
// The asset server fits its small variant inside a 640px box and its medium variant inside 2048px.
|
|
7
|
+
smallAssetWidth: 640,
|
|
8
|
+
// Email is mostly read on 2x screens, so a delivered image needs twice its slot width to stay sharp.
|
|
9
|
+
emailPixelRatio: 2,
|
|
10
|
+
// Uploads are stored as "<folder>/<file>", the only shape the asset server's public route serves.
|
|
11
|
+
storageURIPattern: /^[A-Za-z0-9_-]+\/[A-Za-z0-9._-]+$/,
|
|
12
|
+
// Derived from the shared URL builder so owned upload URLs are recognized wherever the asset host is configured.
|
|
13
|
+
uploadsURLPrefix: makeUploadsUrl('-').slice(0, -1),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* Return the asset-server variant that covers one displayed image width at a
|
|
18
|
+
* pixel ratio: small while it fits the 640px box, otherwise medium.
|
|
19
|
+
*/
|
|
20
|
+
export function getCampaignEmailImageAssetSize(displayWidth?: number | null, pixelRatio = 1): CampaignEmailImageAssetSize {
|
|
21
|
+
const width = typeof displayWidth === 'number' && Number.isFinite(displayWidth) ? Math.max(1, Math.ceil(displayWidth)) : null;
|
|
22
|
+
const ratio = Number.isFinite(pixelRatio) ? Math.max(1, pixelRatio) : 1;
|
|
23
|
+
|
|
24
|
+
return width !== null && width * ratio <= FILE_CONSTANTS.smallAssetWidth ? 'small' : 'medium';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Resolve one owned image, either a storage URI or an asset-server upload URL,
|
|
29
|
+
* to the requested asset-server variant. Returns null for anything else, so
|
|
30
|
+
* callers keep third-party URLs unchanged.
|
|
31
|
+
*/
|
|
32
|
+
export function getCampaignEmailImageAssetURL(uri: string | null | undefined, size: CampaignEmailImageAssetSize): string | null {
|
|
33
|
+
const source = String(uri || '').trim();
|
|
34
|
+
const storageURI = source.replace(/^\/+/, '');
|
|
35
|
+
if (FILE_CONSTANTS.storageURIPattern.test(storageURI)) {
|
|
36
|
+
return makeUploadsUrl(storageURI, size);
|
|
37
|
+
}
|
|
38
|
+
if (!source.startsWith(FILE_CONSTANTS.uploadsURLPrefix)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const assetURL = new URL(source);
|
|
44
|
+
assetURL.searchParams.set('size', size);
|
|
45
|
+
assetURL.searchParams.delete('download');
|
|
46
|
+
return assetURL.toString();
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
* Return the source of one delivered email image. Owned files are served by
|
|
54
|
+
* the asset server at the variant that keeps them sharp in their slot on a 2x
|
|
55
|
+
* screen; any other value is returned as given.
|
|
56
|
+
*/
|
|
57
|
+
export function getCampaignEmailImageSource(uri: string | null | undefined, displayWidth?: number | null): string {
|
|
58
|
+
const size = getCampaignEmailImageAssetSize(displayWidth, FILE_CONSTANTS.emailPixelRatio);
|
|
59
|
+
return getCampaignEmailImageAssetURL(uri, size) || String(uri || '').trim();
|
|
60
|
+
}
|