@jsb188/mday 1.1.11 → 1.1.12

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 (210) hide show
  1. package/package.json +58 -23
  2. package/src/constants/agentMemory.ts +14 -45
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +156 -47
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +12 -38
  10. package/src/constants/dataTableFieldTypes.generated.ts +3 -7
  11. package/src/constants/docAccess.ts +3 -2
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +114 -12
  14. package/src/constants/fieldDoc.ts +74 -4
  15. package/src/constants/graphqlReactivity.ts +108 -25
  16. package/src/constants/log.ts +9 -0
  17. package/src/constants/logDisplay/README.md +88 -0
  18. package/src/constants/logDisplay/defaults.ts +39 -0
  19. package/src/constants/logDisplay/index.ts +27 -0
  20. package/src/constants/logDisplay/operations/arable.ts +16 -0
  21. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  22. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  23. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  24. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  25. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  26. package/src/constants/logTaxonomy.generated.ts +1834 -730
  27. package/src/constants/organization.ts +13 -14
  28. package/src/constants/qrCode.ts +30 -0
  29. package/src/constants/sheet.ts +65 -101
  30. package/src/constants/sms.ts +18 -0
  31. package/src/constants/storage.ts +33 -9
  32. package/src/constants/usage.ts +3 -0
  33. package/src/constants/workflowSteps.ts +60 -0
  34. package/src/schemas/editLogEntry.ts +106 -283
  35. package/src/schemas/inboundContact.ts +5 -5
  36. package/src/types/agentMemory.d.ts +38 -14
  37. package/src/types/agentNote.d.ts +443 -0
  38. package/src/types/billing.d.ts +537 -0
  39. package/src/types/campaign.d.ts +1043 -193
  40. package/src/types/contact.d.ts +15 -0
  41. package/src/types/csvExport.d.ts +213 -0
  42. package/src/types/dataAnalysis.d.ts +44 -0
  43. package/src/types/dataTable.d.ts +102 -309
  44. package/src/types/definitionElement.d.ts +35 -0
  45. package/src/types/dt.d.ts +257 -0
  46. package/src/types/email.d.ts +144 -55
  47. package/src/types/emailReplyReport.d.ts +76 -0
  48. package/src/types/fieldDoc.d.ts +579 -150
  49. package/src/types/fieldDocContract.d.ts +90 -0
  50. package/src/types/inboundContact.d.ts +8 -0
  51. package/src/types/log.d.ts +94 -3
  52. package/src/types/logDisplay.types.ts +85 -0
  53. package/src/types/organization.d.ts +8 -3
  54. package/src/types/qrCode.d.ts +96 -0
  55. package/src/types/richText.d.ts +81 -0
  56. package/src/types/sheet.d.ts +180 -463
  57. package/src/types/sms.d.ts +38 -0
  58. package/src/types/storage.d.ts +266 -27
  59. package/src/types/workflow.d.ts +196 -66
  60. package/src/utils/agentMemory.ts +15 -0
  61. package/src/utils/agentNote.ts +850 -0
  62. package/src/utils/aiChat.ts +31 -14
  63. package/src/utils/aiChatWork.ts +64 -0
  64. package/src/utils/billing.ts +37 -0
  65. package/src/utils/campaign.ts +642 -209
  66. package/src/utils/campaignAI.ts +72 -0
  67. package/src/utils/campaignAccess.ts +239 -0
  68. package/src/utils/campaignEmail.ts +601 -0
  69. package/src/utils/campaignEmailCompiler.ts +372 -0
  70. package/src/utils/campaignEmailImages.ts +60 -0
  71. package/src/utils/campaignEmailStyles.ts +544 -0
  72. package/src/utils/campaignLifecycle.ts +104 -0
  73. package/src/utils/campaignPreview.ts +285 -0
  74. package/src/utils/contact.ts +50 -0
  75. package/src/utils/csvExport.ts +19 -0
  76. package/src/utils/dataTable.ts +18 -556
  77. package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
  78. package/src/utils/dataTableRelativeDate.ts +447 -0
  79. package/src/utils/definitionElement.ts +84 -0
  80. package/src/utils/email.ts +208 -1
  81. package/src/utils/emailReplyReport.test.ts +187 -0
  82. package/src/utils/emailReplyReport.ts +143 -0
  83. package/src/utils/fieldDoc.ts +81 -37
  84. package/src/utils/fieldDocAnswers.ts +128 -0
  85. package/src/utils/fieldDocDefaults.ts +36 -0
  86. package/src/utils/fieldDocProgram.ts +36 -0
  87. package/src/utils/fieldDocSummary.ts +30 -0
  88. package/src/utils/log.ts +232 -141
  89. package/src/utils/logDisplay.helpers.ts +177 -0
  90. package/src/utils/logDisplay.ts +87 -0
  91. package/src/utils/logStoreRead.ts +9 -13
  92. package/src/utils/logTaxonomy.helpers.ts +17 -0
  93. package/src/utils/logTaxonomyDisplay.ts +80 -124
  94. package/src/utils/noteDoc.ts +66 -284
  95. package/src/utils/organization.ts +117 -283
  96. package/src/utils/qrCode.helpers.ts +189 -0
  97. package/src/utils/qrCode.test.ts +519 -0
  98. package/src/utils/qrCode.ts +273 -0
  99. package/src/utils/richTextHTML.ts +385 -0
  100. package/src/utils/sheet.ts +123 -4834
  101. package/src/utils/sheetAxisMove.ts +77 -291
  102. package/src/utils/sheetBootstrap.ts +771 -1138
  103. package/src/utils/sheetCellLiteral.ts +101 -0
  104. package/src/utils/sheetCommand.ts +23 -88
  105. package/src/utils/sheetDesign.ts +705 -0
  106. package/src/utils/sheetExport.ts +17 -69
  107. package/src/utils/sheetFeatureReference.ts +183 -0
  108. package/src/utils/sheetFormulaArgs.ts +168 -0
  109. package/src/utils/sheetFormulaCompile.ts +475 -0
  110. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  111. package/src/utils/sheetFormulaCriteria.ts +656 -0
  112. package/src/utils/sheetFormulaDate.ts +444 -0
  113. package/src/utils/sheetFormulaEvaluation.ts +388 -403
  114. package/src/utils/sheetFormulaEvaluator.ts +589 -444
  115. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  116. package/src/utils/sheetFormulaLogical.ts +116 -0
  117. package/src/utils/sheetFormulaLookup.ts +488 -0
  118. package/src/utils/sheetFormulaMath.ts +48 -0
  119. package/src/utils/sheetFormulaParser.ts +729 -0
  120. package/src/utils/sheetFormulaRange.ts +330 -0
  121. package/src/utils/sheetFormulaReference.ts +703 -0
  122. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  123. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  124. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  125. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  126. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  127. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  128. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  129. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  130. package/src/utils/sheetFormulaText.ts +430 -0
  131. package/src/utils/sheetJournal.ts +140 -18
  132. package/src/utils/sheetNumberFormat.ts +68 -267
  133. package/src/utils/sheetPreview.ts +68 -0
  134. package/src/utils/sheetSequence.ts +13 -43
  135. package/src/utils/sheetSnapshot.ts +176 -429
  136. package/src/utils/sheetStructureEdit.ts +537 -907
  137. package/src/utils/sheetStructureReferences.ts +389 -0
  138. package/src/utils/storage.ts +49 -3
  139. package/src/utils/time.ts +12 -0
  140. package/src/utils/workflow.ts +199 -73
  141. package/src/utils/workflowLogFingerprint.ts +302 -0
  142. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  143. package/src/utils/workflowProgress.ts +280 -0
  144. package/src/utils/workflowTriggers.ts +61 -0
  145. package/tests/agentNote.test.ts +395 -0
  146. package/tests/campaignAI.test.ts +119 -0
  147. package/tests/campaignAccess.test.ts +239 -0
  148. package/tests/campaignEmail.test.ts +441 -0
  149. package/tests/campaignLifecycle.test.ts +134 -0
  150. package/tests/campaignPublication.test.ts +309 -0
  151. package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
  152. package/tests/dataTableRelativeDate.test.ts +412 -0
  153. package/tests/email.test.ts +39 -0
  154. package/tests/fieldDocProgram.test.ts +114 -0
  155. package/tests/logDisplay.fixtures.ts +67 -0
  156. package/tests/logDisplay.test.ts +227 -0
  157. package/tests/noteDoc.test.ts +37 -192
  158. package/tests/richTextHTML.test.ts +185 -0
  159. package/tests/sheetAxisMove.test.ts +49 -40
  160. package/tests/sheetBootstrap.test.ts +1967 -0
  161. package/tests/sheetFeatureReference.test.ts +22 -0
  162. package/tests/sheetFormulaCriteria.test.ts +269 -0
  163. package/tests/sheetFormulaEvaluator.test.ts +93 -200
  164. package/tests/sheetFormulaFunctions.test.ts +538 -0
  165. package/tests/sheetFormulaLanguage.test.ts +361 -0
  166. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  167. package/tests/sheetFormulaParity.test.ts +188 -0
  168. package/tests/sheetFormulaRange.test.ts +167 -0
  169. package/tests/sheetFormulaReference.test.ts +78 -0
  170. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  171. package/tests/sheetFormulaTextDate.test.ts +512 -0
  172. package/tests/sheetSequence.test.ts +4 -23
  173. package/tests/sheetSnapshot.test.ts +134 -0
  174. package/tests/sheetStructureEdit.test.ts +492 -37
  175. package/tests/sheetStructureReferences.test.ts +589 -0
  176. package/tests/workflowLifecycleStatus.test.ts +60 -0
  177. package/tests/workflowLogFingerprint.test.ts +203 -0
  178. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  179. package/tests/workflowProgress.test.ts +180 -0
  180. package/tests/workflowTriggers.test.ts +29 -0
  181. package/src/constants/agentDoc.ts +0 -12
  182. package/src/constants/logActivityGroupColors.generated.ts +0 -19
  183. package/src/constants/schedule.ts +0 -220
  184. package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
  185. package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
  186. package/src/constants/sheetRegionSources.generated.ts +0 -578
  187. package/src/schemas/fieldDocsQuery.ts +0 -12
  188. package/src/schemas/organization.ts +0 -68
  189. package/src/types/agentDoc.d.ts +0 -64
  190. package/src/types/noteDoc.d.ts +0 -86
  191. package/src/types/schedule.d.ts +0 -391
  192. package/src/utils/agentDoc.ts +0 -109
  193. package/src/utils/campaignFormEditor.ts +0 -871
  194. package/src/utils/dataTableRealtimeAuthority.ts +0 -209
  195. package/src/utils/dataTableRealtimeSelection.ts +0 -134
  196. package/src/utils/dataTableRowDocument.ts +0 -508
  197. package/src/utils/dataTableSource.ts +0 -230
  198. package/src/utils/schedule.ts +0 -799
  199. package/src/utils/scheduleEvaluation.ts +0 -1994
  200. package/src/utils/scheduleICS.ts +0 -246
  201. package/src/utils/scheduleRuleTemplates.ts +0 -188
  202. package/src/utils/sheetRegion.ts +0 -374
  203. package/src/utils/sheetRegionFilter.ts +0 -1259
  204. package/src/utils/sheetRegionSourceRegistry.ts +0 -594
  205. package/tests/schedule.test.ts +0 -693
  206. package/tests/scheduleEvaluation.test.ts +0 -1970
  207. package/tests/scheduleICS.test.ts +0 -208
  208. package/tests/scheduleRuleTemplates.test.ts +0 -176
  209. package/tests/scheduleSweepInvariants.test.ts +0 -428
  210. package/tests/sheetRegionFilter.test.ts +0 -1135
@@ -0,0 +1,544 @@
1
+ import {
2
+ CAMPAIGN_EMAIL_CANVAS_VERTICAL_PADDING,
3
+ CAMPAIGN_EMAIL_DEFAULT_CANVAS_COLOR,
4
+ CAMPAIGN_EMAIL_DEFAULT_CONTENT_COLOR,
5
+ CAMPAIGN_EMAIL_DEFAULT_FONT_FAMILY,
6
+ CAMPAIGN_EMAIL_DEFAULT_LINK_COLOR,
7
+ CAMPAIGN_EMAIL_DEFAULT_TEXT_COLOR,
8
+ CAMPAIGN_EMAIL_EMPHASIS_FONT_WEIGHT,
9
+ CAMPAIGN_EMAIL_FONT_FACES,
10
+ CAMPAIGN_EMAIL_FONT_FAMILY_NAME,
11
+ CAMPAIGN_EMAIL_FONT_FILE_URL,
12
+ CAMPAIGN_EMAIL_FONT_FILE_VERSION,
13
+ CAMPAIGN_EMAIL_HEADING_FONT_WEIGHT,
14
+ CAMPAIGN_EMAIL_LEGACY_DEFAULT_FONT_FAMILIES,
15
+ CAMPAIGN_EMAIL_RESPONSIVE_CANVAS_BOTTOM_PADDING,
16
+ } from '../constants/campaign.ts';
17
+ import type {
18
+ CampaignEmailBlockSettingsObj,
19
+ CampaignEmailRowSettingsObj,
20
+ } from '../types/campaign.d.ts';
21
+ import {
22
+ getCampaignEmailDesignSettings,
23
+ isCampaignEmailFontFamilyValid,
24
+ } from './campaignEmail.ts';
25
+
26
+ /*
27
+ * Every visual declaration shared by the browser preview and the delivered
28
+ * email lives in this file. The React renderer spreads these objects into
29
+ * `style` props and the HTML compiler serializes them into inline styles, so
30
+ * the two surfaces cannot drift apart. Values mirror what the app's global
31
+ * stylesheet gave the preview (rem-based heading scale, list indents, tight
32
+ * heading tracking) because email clients have none of that cascade.
33
+ */
34
+
35
+ export type CampaignEmailHeadingLevel = 1 | 2 | 3;
36
+
37
+ export interface CampaignEmailStyleObj {
38
+ background?: string;
39
+ border?: string;
40
+ borderCollapse?: 'collapse';
41
+ borderLeft?: string;
42
+ borderRadius?: string;
43
+ borderTop?: string;
44
+ color?: string;
45
+ display?: 'block' | 'inline-block' | 'none';
46
+ fontFamily?: string;
47
+ fontSize?: string;
48
+ fontWeight?: 'normal' | '600' | '700';
49
+ height?: string;
50
+ letterSpacing?: string;
51
+ lineHeight?: string;
52
+ listStylePosition?: 'outside';
53
+ listStyleType?: 'disc' | 'decimal';
54
+ margin?: string;
55
+ maxHeight?: string;
56
+ maxWidth?: string;
57
+ opacity?: string;
58
+ overflow?: 'hidden';
59
+ padding?: string;
60
+ position?: 'static';
61
+ textAlign?: 'left' | 'center' | 'right';
62
+ textDecoration?: 'none' | 'underline';
63
+ verticalAlign?: 'top';
64
+ width?: string;
65
+ wordWrap?: 'break-word';
66
+ }
67
+
68
+ export interface CampaignEmailResolvedDesignObj {
69
+ canvasColor: string;
70
+ contentColor: string;
71
+ contentWidth: number;
72
+ fontFamily: string;
73
+ linkColor: string;
74
+ padding: string;
75
+ textColor: string;
76
+ }
77
+
78
+ const FILE_CONSTANTS = {
79
+ buttonTextColor: '#ffffff',
80
+ footerTextColor: '#71717a',
81
+ // The app renders HEADING blocks through its rem heading scale
82
+ // (2.4rem / 2.1rem / 1.7rem at a 16px root).
83
+ headingBlockFontSizes: { 1: '38.4px', 2: '33.6px', 3: '27.2px' },
84
+ richTextHeadingFontSize: '32px',
85
+ ruleColor: '#d4d4d8',
86
+ textFontSize: '16px',
87
+ };
88
+
89
+ /*
90
+ * Restrict configurable colors to hexadecimal CSS colors before placing them
91
+ * in inline email styles.
92
+ */
93
+ export function getCampaignEmailColor(
94
+ value: unknown,
95
+ fallback: string,
96
+ ): string {
97
+ const color = String(value || '').trim();
98
+ return /^#[0-9a-f]{3}([0-9a-f]{3})?$/i.test(color) ? color : fallback;
99
+ }
100
+
101
+ /*
102
+ * Resolve the authored font stack, treating earlier persisted defaults and
103
+ * unsafe values as the current default stack.
104
+ */
105
+ export function getCampaignEmailFontFamily(value: unknown): string {
106
+ const fontFamily = String(value || '').trim();
107
+ return fontFamily &&
108
+ !CAMPAIGN_EMAIL_LEGACY_DEFAULT_FONT_FAMILIES.some(
109
+ (legacy) => legacy === fontFamily,
110
+ ) &&
111
+ isCampaignEmailFontFamilyValid(fontFamily)
112
+ ? fontFamily
113
+ : CAMPAIGN_EMAIL_DEFAULT_FONT_FAMILY;
114
+ }
115
+
116
+ /*
117
+ * Resolve every design setting into the concrete colors, widths, and font
118
+ * stack used by both renderers.
119
+ */
120
+ export function getCampaignEmailResolvedDesign(
121
+ value: unknown,
122
+ ): CampaignEmailResolvedDesignObj {
123
+ const design = getCampaignEmailDesignSettings(value);
124
+ return {
125
+ canvasColor: getCampaignEmailColor(
126
+ design.canvasColor,
127
+ CAMPAIGN_EMAIL_DEFAULT_CANVAS_COLOR,
128
+ ),
129
+ contentColor: getCampaignEmailColor(
130
+ design.contentColor,
131
+ CAMPAIGN_EMAIL_DEFAULT_CONTENT_COLOR,
132
+ ),
133
+ contentWidth: design.contentWidth,
134
+ fontFamily: getCampaignEmailFontFamily(design.fontFamily),
135
+ linkColor: getCampaignEmailColor(
136
+ design.linkColor,
137
+ CAMPAIGN_EMAIL_DEFAULT_LINK_COLOR,
138
+ ),
139
+ padding: design.padding,
140
+ textColor: getCampaignEmailColor(
141
+ design.textColor,
142
+ CAMPAIGN_EMAIL_DEFAULT_TEXT_COLOR,
143
+ ),
144
+ };
145
+ }
146
+
147
+ /*
148
+ * Return the horizontal pixel total of one normalized CSS padding shorthand.
149
+ * Both renderers use it to size images to the slot their block occupies.
150
+ */
151
+ export function getCampaignEmailHorizontalPadding(padding: string): number {
152
+ const values = padding
153
+ .trim()
154
+ .split(/\s+/)
155
+ .map((value) => Number.parseInt(value, 10));
156
+ if (!values.length || values.some((value) => !Number.isFinite(value))) {
157
+ return 0;
158
+ }
159
+
160
+ if (values.length === 1) {
161
+ return values[0] * 2;
162
+ }
163
+ if (values.length === 2 || values.length === 3) {
164
+ return values[1] * 2;
165
+ }
166
+ return values[1] + values[3];
167
+ }
168
+
169
+ /*
170
+ * Serialize one style object into an inline CSS declaration list.
171
+ */
172
+ export function serializeCampaignEmailStyle(
173
+ style: CampaignEmailStyleObj,
174
+ ): string {
175
+ return Object.entries(style)
176
+ .filter(([, value]) => value != null && value !== '')
177
+ .map(
178
+ ([property, value]) =>
179
+ `${property.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}:${value}`,
180
+ )
181
+ .join(';');
182
+ }
183
+
184
+ /*
185
+ * Build the @font-face rules that let font-capable email clients and the app
186
+ * preview load the same weight-mapped family.
187
+ */
188
+ export function getCampaignEmailFontFaceCSS(): string {
189
+ return CAMPAIGN_EMAIL_FONT_FACES.map((face) => {
190
+ const url = `${CAMPAIGN_EMAIL_FONT_FILE_URL}${face.file}`;
191
+ const version = `?v=${CAMPAIGN_EMAIL_FONT_FILE_VERSION}`;
192
+ return `@font-face{font-family:'${CAMPAIGN_EMAIL_FONT_FAMILY_NAME}';font-style:${face.style};font-weight:${face.weight};font-display:swap;src:url(${url}.woff2${version}) format('woff2'),url(${url}.woff${version}) format('woff')}`;
193
+ }).join('');
194
+ }
195
+
196
+ /*
197
+ * Build the responsive rules that collapse the canvas padding and stack
198
+ * columns on narrow viewports. Class names are shared with the preview.
199
+ */
200
+ export function getCampaignEmailResponsiveCSS(
201
+ design: CampaignEmailResolvedDesignObj,
202
+ ): string {
203
+ return `@media(max-width:${design.contentWidth}px){.campaign-email-canvas-cell{padding-top:0!important;padding-bottom:${CAMPAIGN_EMAIL_RESPONSIVE_CANVAS_BOTTOM_PADDING}px!important}}@media(max-width:${design.contentWidth + 20}px){.campaign-email{width:100%!important}.campaign-email-column{display:block!important;width:100%!important}}`;
204
+ }
205
+
206
+ /*
207
+ * Base typography applied to the body and every layout cell so no email
208
+ * client can inject its own default font, size, or wrapping behavior.
209
+ */
210
+ export function getCampaignEmailTextStyle(
211
+ design: CampaignEmailResolvedDesignObj,
212
+ ): CampaignEmailStyleObj {
213
+ return {
214
+ color: design.textColor,
215
+ fontFamily: design.fontFamily,
216
+ fontSize: FILE_CONSTANTS.textFontSize,
217
+ letterSpacing: 'normal',
218
+ lineHeight: 'normal',
219
+ wordWrap: 'break-word',
220
+ };
221
+ }
222
+
223
+ /*
224
+ * Outer full-width canvas table behind the centered content column.
225
+ */
226
+ export function getCampaignEmailCanvasStyle(
227
+ design: CampaignEmailResolvedDesignObj,
228
+ ): CampaignEmailStyleObj {
229
+ return {
230
+ ...getCampaignEmailTextStyle(design),
231
+ background: design.canvasColor,
232
+ borderCollapse: 'collapse',
233
+ width: '100%',
234
+ };
235
+ }
236
+
237
+ /*
238
+ * Vertical breathing room around the content column on wide viewports.
239
+ */
240
+ export function getCampaignEmailCanvasCellStyle(
241
+ design: CampaignEmailResolvedDesignObj,
242
+ ): CampaignEmailStyleObj {
243
+ return {
244
+ ...getCampaignEmailTextStyle(design),
245
+ padding: `${CAMPAIGN_EMAIL_CANVAS_VERTICAL_PADDING}px 0`,
246
+ };
247
+ }
248
+
249
+ /*
250
+ * Centered content column; a stacked mobile preview stretches it to full width.
251
+ */
252
+ export function getCampaignEmailContentStyle(
253
+ design: CampaignEmailResolvedDesignObj,
254
+ fullWidth = false,
255
+ ): CampaignEmailStyleObj {
256
+ return {
257
+ ...getCampaignEmailTextStyle(design),
258
+ background: design.contentColor,
259
+ borderCollapse: 'collapse',
260
+ maxWidth: '100%',
261
+ width: fullWidth ? '100%' : `${design.contentWidth}px`,
262
+ };
263
+ }
264
+
265
+ /*
266
+ * Inner content cell carrying the design-level padding around every row.
267
+ */
268
+ export function getCampaignEmailContentCellStyle(
269
+ design: CampaignEmailResolvedDesignObj,
270
+ ): CampaignEmailStyleObj {
271
+ return { ...getCampaignEmailTextStyle(design), padding: design.padding };
272
+ }
273
+
274
+ /*
275
+ * One row band, including its optional background color.
276
+ */
277
+ export function getCampaignEmailRowStyle(
278
+ settings: CampaignEmailRowSettingsObj,
279
+ ): CampaignEmailStyleObj {
280
+ return {
281
+ background: getCampaignEmailColor(settings.backgroundColor, 'transparent'),
282
+ borderCollapse: 'collapse',
283
+ width: '100%',
284
+ };
285
+ }
286
+
287
+ /*
288
+ * The cell that applies one row's vertical padding around its columns.
289
+ */
290
+ export function getCampaignEmailRowCellStyle(
291
+ settings: CampaignEmailRowSettingsObj,
292
+ ): CampaignEmailStyleObj {
293
+ return { padding: settings.padding };
294
+ }
295
+
296
+ export const CAMPAIGN_EMAIL_COLUMNS_STYLE: CampaignEmailStyleObj = {
297
+ borderCollapse: 'collapse',
298
+ width: '100%',
299
+ };
300
+
301
+ /*
302
+ * One column cell; stacked columns become full-width blocks.
303
+ */
304
+ export function getCampaignEmailColumnStyle(
305
+ width: number,
306
+ stacked = false,
307
+ ): CampaignEmailStyleObj {
308
+ return {
309
+ display: stacked ? 'block' : undefined,
310
+ verticalAlign: 'top',
311
+ width: stacked ? '100%' : `${width}%`,
312
+ };
313
+ }
314
+
315
+ /*
316
+ * Shared container for one block: alignment, colors, and padding.
317
+ */
318
+ export function getCampaignEmailBlockStyle(
319
+ settings: CampaignEmailBlockSettingsObj,
320
+ design: CampaignEmailResolvedDesignObj,
321
+ ): CampaignEmailStyleObj {
322
+ return {
323
+ background: getCampaignEmailColor(settings.backgroundColor, 'transparent'),
324
+ color: getCampaignEmailColor(settings.textColor, design.textColor),
325
+ fontSize: settings.fontSize ? `${settings.fontSize}px` : undefined,
326
+ padding: settings.padding,
327
+ textAlign: settings.alignment.toLowerCase() as 'left' | 'center' | 'right',
328
+ };
329
+ }
330
+
331
+ /*
332
+ * Family, weight, and tracking shared by every heading of one level. The
333
+ * family is explicit because the app stylesheet and Outlook both override
334
+ * inherited heading fonts.
335
+ */
336
+ function getCampaignEmailHeadingTypography(
337
+ level: CampaignEmailHeadingLevel,
338
+ design: CampaignEmailResolvedDesignObj,
339
+ letterSpacing: string,
340
+ ): CampaignEmailStyleObj {
341
+ return {
342
+ fontFamily: design.fontFamily,
343
+ fontWeight:
344
+ level <= 2
345
+ ? `${CAMPAIGN_EMAIL_HEADING_FONT_WEIGHT}`
346
+ : `${CAMPAIGN_EMAIL_EMPHASIS_FONT_WEIGHT}`,
347
+ letterSpacing,
348
+ lineHeight: '1.3',
349
+ };
350
+ }
351
+
352
+ /*
353
+ * The heading element of one HEADING block. An authored font size wins over
354
+ * the level's default size.
355
+ */
356
+ export function getCampaignEmailHeadingStyle(
357
+ level: CampaignEmailHeadingLevel,
358
+ design: CampaignEmailResolvedDesignObj,
359
+ fontSize?: number | null,
360
+ ): CampaignEmailStyleObj {
361
+ return {
362
+ ...getCampaignEmailHeadingTypography(
363
+ level,
364
+ design,
365
+ level <= 2 ? '-0.04em' : '-0.0375em',
366
+ ),
367
+ fontSize: fontSize
368
+ ? `${fontSize}px`
369
+ : FILE_CONSTANTS.headingBlockFontSizes[level],
370
+ margin: '10px 0 0',
371
+ padding: '10px 0 0',
372
+ };
373
+ }
374
+
375
+ /*
376
+ * Headings inside rich text (and the HERO heading), which flow with paragraphs.
377
+ */
378
+ export function getCampaignEmailRichTextHeadingStyle(
379
+ level: CampaignEmailHeadingLevel,
380
+ design: CampaignEmailResolvedDesignObj,
381
+ ): CampaignEmailStyleObj {
382
+ return {
383
+ ...getCampaignEmailHeadingTypography(level, design, '-0.04em'),
384
+ fontSize: FILE_CONSTANTS.richTextHeadingFontSize,
385
+ margin: '0 0 12px',
386
+ padding: '16px 0 8px',
387
+ };
388
+ }
389
+
390
+ export const CAMPAIGN_EMAIL_PARAGRAPH_STYLE: CampaignEmailStyleObj = {
391
+ margin: '0 0 12px',
392
+ padding: '0',
393
+ };
394
+
395
+ export const CAMPAIGN_EMAIL_HERO_TEXT_STYLE: CampaignEmailStyleObj = {
396
+ margin: '0 0 16px',
397
+ padding: '0',
398
+ };
399
+
400
+ /*
401
+ * Bulleted or numbered list container.
402
+ */
403
+ export function getCampaignEmailListStyle(
404
+ ordered: boolean,
405
+ ): CampaignEmailStyleObj {
406
+ return {
407
+ listStylePosition: 'outside',
408
+ listStyleType: ordered ? 'decimal' : 'disc',
409
+ margin: '0',
410
+ padding: '8px 0',
411
+ };
412
+ }
413
+
414
+ export const CAMPAIGN_EMAIL_LIST_ITEM_STYLE: CampaignEmailStyleObj = {
415
+ margin: '0 14px 0 22px',
416
+ padding: '0 10px',
417
+ };
418
+
419
+ export const CAMPAIGN_EMAIL_BLOCKQUOTE_STYLE: CampaignEmailStyleObj = {
420
+ borderLeft: `3px solid ${FILE_CONSTANTS.ruleColor}`,
421
+ margin: '0 0 12px',
422
+ padding: '0 0 0 12px',
423
+ };
424
+
425
+ export const CAMPAIGN_EMAIL_RICH_TEXT_DIVIDER_STYLE: CampaignEmailStyleObj = {
426
+ border: '0',
427
+ borderTop: `1px solid ${FILE_CONSTANTS.ruleColor}`,
428
+ margin: '8px 0',
429
+ };
430
+
431
+ export const CAMPAIGN_EMAIL_DIVIDER_STYLE: CampaignEmailStyleObj = {
432
+ border: '0',
433
+ borderTop: `1px solid ${FILE_CONSTANTS.ruleColor}`,
434
+ margin: '0',
435
+ };
436
+
437
+ export const CAMPAIGN_EMAIL_RICH_TEXT_IMAGE_STYLE: CampaignEmailStyleObj = {
438
+ display: 'block',
439
+ height: 'auto',
440
+ maxWidth: '100%',
441
+ };
442
+
443
+ export const CAMPAIGN_EMAIL_IMAGE_STYLE: CampaignEmailStyleObj = {
444
+ display: 'block',
445
+ height: 'auto',
446
+ maxWidth: '100%',
447
+ width: '100%',
448
+ };
449
+
450
+ export const CAMPAIGN_EMAIL_HERO_IMAGE_STYLE: CampaignEmailStyleObj = {
451
+ ...CAMPAIGN_EMAIL_IMAGE_STYLE,
452
+ margin: '0 0 20px',
453
+ };
454
+
455
+ /*
456
+ * Bold runs map to the medium face; the tracking mirrors the app's `strong` rule.
457
+ */
458
+ export function getCampaignEmailEmphasisStyle(
459
+ design: CampaignEmailResolvedDesignObj,
460
+ ): CampaignEmailStyleObj {
461
+ return {
462
+ fontFamily: design.fontFamily,
463
+ fontWeight: `${CAMPAIGN_EMAIL_EMPHASIS_FONT_WEIGHT}`,
464
+ letterSpacing: '-0.0075em',
465
+ };
466
+ }
467
+
468
+ /*
469
+ * Ordinary text link. `position` counters the app's anchor reset in previews.
470
+ */
471
+ export function getCampaignEmailLinkStyle(
472
+ design: CampaignEmailResolvedDesignObj,
473
+ ): CampaignEmailStyleObj {
474
+ return {
475
+ color: design.linkColor,
476
+ position: 'static',
477
+ textDecoration: 'underline',
478
+ };
479
+ }
480
+
481
+ /*
482
+ * One SOCIAL or MENU link laid out in a horizontal run.
483
+ */
484
+ export function getCampaignEmailMenuLinkStyle(
485
+ design: CampaignEmailResolvedDesignObj,
486
+ ): CampaignEmailStyleObj {
487
+ return {
488
+ ...getCampaignEmailLinkStyle(design),
489
+ display: 'inline-block',
490
+ margin: '0 12px 0 0',
491
+ };
492
+ }
493
+
494
+ /*
495
+ * Call-to-action shared by BUTTON and HERO blocks; the block's background
496
+ * color doubles as the button color.
497
+ */
498
+ export function getCampaignEmailButtonStyle(
499
+ settings: CampaignEmailBlockSettingsObj,
500
+ ): CampaignEmailStyleObj {
501
+ const background = getCampaignEmailColor(
502
+ settings.backgroundColor,
503
+ CAMPAIGN_EMAIL_DEFAULT_TEXT_COLOR,
504
+ );
505
+ const outline = settings.buttonStyle === 'OUTLINE';
506
+ return {
507
+ background: outline ? 'transparent' : background,
508
+ border: `1px solid ${background}`,
509
+ borderRadius: '6px',
510
+ color: outline
511
+ ? background
512
+ : getCampaignEmailColor(
513
+ settings.textColor,
514
+ FILE_CONSTANTS.buttonTextColor,
515
+ ),
516
+ display: 'inline-block',
517
+ padding: '12px 20px',
518
+ position: 'static',
519
+ textDecoration: 'none',
520
+ };
521
+ }
522
+
523
+ /*
524
+ * Fixed-height vertical gap.
525
+ */
526
+ export function getCampaignEmailSpacerStyle(
527
+ height: number,
528
+ ): CampaignEmailStyleObj {
529
+ return { height: `${height}px`, lineHeight: `${height}px` };
530
+ }
531
+
532
+ export const CAMPAIGN_EMAIL_PREHEADER_STYLE: CampaignEmailStyleObj = {
533
+ display: 'none',
534
+ maxHeight: '0',
535
+ opacity: '0',
536
+ overflow: 'hidden',
537
+ };
538
+
539
+ export const CAMPAIGN_EMAIL_FOOTER_STYLE: CampaignEmailStyleObj = {
540
+ color: FILE_CONSTANTS.footerTextColor,
541
+ fontSize: '12px',
542
+ margin: '24px 0 0',
543
+ textAlign: 'center',
544
+ };
@@ -0,0 +1,104 @@
1
+ import type { CampaignData, CampaignStatusEnum } from '../types/campaign.d.ts';
2
+
3
+ export interface CampaignArchiveSource {
4
+ archivedAt?: Date | string | null;
5
+ }
6
+
7
+ export type CampaignLifecycleSource = Pick<
8
+ CampaignData,
9
+ 'kind' | 'status' | 'scheduledAt' | 'closesAt' | 'startedAt' | 'completedAt'
10
+ >;
11
+
12
+ export interface CampaignLifecycleProjection {
13
+ status: CampaignStatusEnum;
14
+ startedAt: Date | string | null;
15
+ completedAt: Date | string | null;
16
+ isOpen: boolean;
17
+ }
18
+
19
+ /*
20
+ * Return whether a campaign or template is archived. archivedAt is a
21
+ * presence-based marker, not a scheduled transition, so every non-null value
22
+ * means archived immediately even when its timestamp is in the future.
23
+ */
24
+ export function isCampaignArchived(
25
+ source?: CampaignArchiveSource | null,
26
+ ): boolean {
27
+ return source?.archivedAt !== null && source?.archivedAt !== undefined;
28
+ }
29
+
30
+ /*
31
+ * Overlay the archive marker on one campaign or template's operational status
32
+ * for presentation without changing the persisted status value.
33
+ */
34
+ export function getCampaignDisplayStatus<TStatus extends string>(
35
+ source: CampaignArchiveSource & { status: TStatus },
36
+ ): TStatus | 'ARCHIVED' {
37
+ return isCampaignArchived(source) ? 'ARCHIVED' : source.status;
38
+ }
39
+
40
+ /*
41
+ * Return whether one optional campaign timestamp is at or before the supplied
42
+ * lifecycle clock. Invalid stored values never become due implicitly.
43
+ */
44
+ function campaignTimestampIsDue(
45
+ value: Date | string | null | undefined,
46
+ now: Date,
47
+ ): boolean {
48
+ if (!value) {
49
+ return false;
50
+ }
51
+
52
+ const timestamp = new Date(value).getTime();
53
+ return Number.isFinite(timestamp) && timestamp <= now.getTime();
54
+ }
55
+
56
+ /*
57
+ * Project a public form through its time window without mutating persistence.
58
+ *
59
+ * The projection is intentionally exact at both boundaries: scheduledAt is
60
+ * the first open instant and closesAt is the first closed instant. Email and
61
+ * explicit terminal states are returned verbatim because their transitions
62
+ * are owned by workers or management commands rather than wall-clock reads.
63
+ */
64
+ export function getCampaignLifecycleProjection(
65
+ campaign: CampaignLifecycleSource,
66
+ now: Date = new Date(),
67
+ ): CampaignLifecycleProjection {
68
+ if (
69
+ campaign.kind !== 'PUBLIC_FORM' ||
70
+ !['SCHEDULED', 'ACTIVE'].includes(campaign.status)
71
+ ) {
72
+ return {
73
+ status: campaign.status,
74
+ startedAt: campaign.startedAt || null,
75
+ completedAt: campaign.completedAt || null,
76
+ isOpen: false,
77
+ };
78
+ }
79
+
80
+ if (campaignTimestampIsDue(campaign.closesAt, now)) {
81
+ return {
82
+ status: 'CLOSED',
83
+ startedAt: campaign.startedAt || campaign.scheduledAt || null,
84
+ completedAt: campaign.completedAt || campaign.closesAt || null,
85
+ isOpen: false,
86
+ };
87
+ }
88
+
89
+ if (campaignTimestampIsDue(campaign.scheduledAt, now)) {
90
+ return {
91
+ status: 'ACTIVE',
92
+ startedAt: campaign.startedAt || campaign.scheduledAt || null,
93
+ completedAt: null,
94
+ isOpen: true,
95
+ };
96
+ }
97
+
98
+ return {
99
+ status: 'SCHEDULED',
100
+ startedAt: null,
101
+ completedAt: null,
102
+ isOpen: false,
103
+ };
104
+ }