@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.
Files changed (202) hide show
  1. package/package.json +142 -0
  2. package/src/constants/agentMemory.ts +166 -0
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +10 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +236 -0
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +22 -0
  10. package/src/constants/dataTableFieldTypes.generated.ts +59 -0
  11. package/src/constants/docAccess.ts +33 -0
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +146 -0
  14. package/src/constants/fieldDoc.ts +104 -0
  15. package/src/constants/graphqlReactivity.ts +196 -0
  16. package/src/constants/inboundContact.ts +8 -0
  17. package/src/constants/integration.ts +13 -0
  18. package/src/constants/log.ts +21 -0
  19. package/src/constants/logDisplay/README.md +88 -0
  20. package/src/constants/logDisplay/defaults.ts +39 -0
  21. package/src/constants/logDisplay/index.ts +27 -0
  22. package/src/constants/logDisplay/operations/arable.ts +16 -0
  23. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  24. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  25. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  26. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  27. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  28. package/src/constants/logTaxonomy.generated.ts +2199 -0
  29. package/src/constants/noteDoc.ts +77 -0
  30. package/src/constants/organization.ts +60 -0
  31. package/src/constants/pageRoute.ts +23 -0
  32. package/src/constants/qrCode.ts +30 -0
  33. package/src/constants/sheet.ts +132 -0
  34. package/src/constants/sms.ts +18 -0
  35. package/src/constants/square.ts +16 -0
  36. package/src/constants/storage.ts +85 -0
  37. package/src/constants/usage.ts +82 -0
  38. package/src/constants/workflowSteps.ts +60 -0
  39. package/src/schemas/editLogEntry.ts +879 -0
  40. package/src/schemas/inboundContact.ts +77 -0
  41. package/src/schemas/logsQuery.ts +93 -0
  42. package/src/types/account.d.ts +81 -0
  43. package/src/types/agentMemory.d.ts +100 -0
  44. package/src/types/agentNote.d.ts +441 -0
  45. package/src/types/billing.d.ts +537 -0
  46. package/src/types/campaign.d.ts +1533 -0
  47. package/src/types/contact.d.ts +15 -0
  48. package/src/types/csvExport.d.ts +213 -0
  49. package/src/types/dataAnalysis.d.ts +44 -0
  50. package/src/types/dataTable.d.ts +159 -0
  51. package/src/types/definitionElement.d.ts +35 -0
  52. package/src/types/docAccess.d.ts +96 -0
  53. package/src/types/dt.d.ts +257 -0
  54. package/src/types/email.d.ts +231 -0
  55. package/src/types/emailReplyReport.d.ts +76 -0
  56. package/src/types/fieldDoc.d.ts +702 -0
  57. package/src/types/fieldDocContract.d.ts +90 -0
  58. package/src/types/inboundContact.d.ts +65 -0
  59. package/src/types/integration.d.ts +42 -0
  60. package/src/types/log.d.ts +338 -0
  61. package/src/types/logDisplay.types.ts +85 -0
  62. package/src/types/organization.d.ts +350 -0
  63. package/src/types/pageRoute.d.ts +48 -0
  64. package/src/types/qrCode.d.ts +96 -0
  65. package/src/types/richText.d.ts +81 -0
  66. package/src/types/sheet.d.ts +847 -0
  67. package/src/types/sms.d.ts +38 -0
  68. package/src/types/storage.d.ts +481 -0
  69. package/src/types/usage.d.ts +106 -0
  70. package/src/types/workflow.d.ts +435 -0
  71. package/src/utils/agentMemory.ts +15 -0
  72. package/src/utils/agentNote.ts +850 -0
  73. package/src/utils/aiChat.ts +43 -0
  74. package/src/utils/aiChatWork.ts +64 -0
  75. package/src/utils/billing.ts +37 -0
  76. package/src/utils/campaign.ts +1173 -0
  77. package/src/utils/campaignAI.ts +72 -0
  78. package/src/utils/campaignAccess.ts +239 -0
  79. package/src/utils/campaignEmail.ts +601 -0
  80. package/src/utils/campaignEmailCompiler.ts +372 -0
  81. package/src/utils/campaignEmailImages.ts +60 -0
  82. package/src/utils/campaignEmailStyles.ts +544 -0
  83. package/src/utils/campaignLifecycle.ts +104 -0
  84. package/src/utils/campaignPreview.ts +285 -0
  85. package/src/utils/contact.ts +50 -0
  86. package/src/utils/csvExport.ts +19 -0
  87. package/src/utils/dataTable.ts +311 -0
  88. package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
  89. package/src/utils/dataTableRelativeDate.ts +447 -0
  90. package/src/utils/definitionElement.ts +84 -0
  91. package/src/utils/docAccess.ts +383 -0
  92. package/src/utils/documentName.ts +53 -0
  93. package/src/utils/email.ts +379 -0
  94. package/src/utils/emailReplyReport.test.ts +187 -0
  95. package/src/utils/emailReplyReport.ts +143 -0
  96. package/src/utils/fieldDoc.ts +157 -0
  97. package/src/utils/fieldDocAnswers.ts +128 -0
  98. package/src/utils/fieldDocDefaults.ts +36 -0
  99. package/src/utils/fieldDocProgram.ts +36 -0
  100. package/src/utils/fieldDocSummary.ts +30 -0
  101. package/src/utils/log.ts +357 -0
  102. package/src/utils/logDisplay.helpers.ts +177 -0
  103. package/src/utils/logDisplay.ts +87 -0
  104. package/src/utils/logRegistryValue.ts +90 -0
  105. package/src/utils/logStoreRead.ts +262 -0
  106. package/src/utils/logTaxonomy.helpers.ts +17 -0
  107. package/src/utils/logTaxonomy.ts +76 -0
  108. package/src/utils/logTaxonomyDisplay.ts +395 -0
  109. package/src/utils/noteDoc.ts +609 -0
  110. package/src/utils/organization.ts +669 -0
  111. package/src/utils/pageRoute.ts +71 -0
  112. package/src/utils/qrCode.helpers.ts +189 -0
  113. package/src/utils/qrCode.test.ts +519 -0
  114. package/src/utils/qrCode.ts +273 -0
  115. package/src/utils/richTextHTML.ts +385 -0
  116. package/src/utils/sheet.ts +262 -0
  117. package/src/utils/sheetAxisMove.ts +616 -0
  118. package/src/utils/sheetBootstrap.ts +1402 -0
  119. package/src/utils/sheetCellLiteral.ts +101 -0
  120. package/src/utils/sheetCommand.ts +358 -0
  121. package/src/utils/sheetDesign.ts +705 -0
  122. package/src/utils/sheetExport.ts +186 -0
  123. package/src/utils/sheetFeatureReference.ts +183 -0
  124. package/src/utils/sheetFormulaArgs.ts +168 -0
  125. package/src/utils/sheetFormulaCompile.ts +475 -0
  126. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  127. package/src/utils/sheetFormulaCriteria.ts +656 -0
  128. package/src/utils/sheetFormulaDate.ts +444 -0
  129. package/src/utils/sheetFormulaEvaluation.ts +899 -0
  130. package/src/utils/sheetFormulaEvaluator.ts +997 -0
  131. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  132. package/src/utils/sheetFormulaLogical.ts +116 -0
  133. package/src/utils/sheetFormulaLookup.ts +488 -0
  134. package/src/utils/sheetFormulaMath.ts +48 -0
  135. package/src/utils/sheetFormulaParser.ts +729 -0
  136. package/src/utils/sheetFormulaRange.ts +330 -0
  137. package/src/utils/sheetFormulaReference.ts +703 -0
  138. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  139. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  140. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  141. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  142. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  143. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  144. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  145. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  146. package/src/utils/sheetFormulaText.ts +430 -0
  147. package/src/utils/sheetJournal.ts +200 -0
  148. package/src/utils/sheetNumberFormat.ts +1012 -0
  149. package/src/utils/sheetPreview.ts +68 -0
  150. package/src/utils/sheetSequence.ts +118 -0
  151. package/src/utils/sheetSnapshot.ts +739 -0
  152. package/src/utils/sheetStructureEdit.ts +914 -0
  153. package/src/utils/sheetStructureReferences.ts +389 -0
  154. package/src/utils/square.ts +32 -0
  155. package/src/utils/storage.ts +198 -0
  156. package/src/utils/table-route.ts +262 -0
  157. package/src/utils/time.ts +12 -0
  158. package/src/utils/workflow.ts +506 -0
  159. package/src/utils/workflowLogFingerprint.ts +302 -0
  160. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  161. package/src/utils/workflowProgress.ts +280 -0
  162. package/src/utils/workflowTriggers.ts +61 -0
  163. package/tests/agentNote.test.ts +395 -0
  164. package/tests/campaignAI.test.ts +119 -0
  165. package/tests/campaignAccess.test.ts +239 -0
  166. package/tests/campaignEmail.test.ts +441 -0
  167. package/tests/campaignLifecycle.test.ts +134 -0
  168. package/tests/campaignPublication.test.ts +309 -0
  169. package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
  170. package/tests/dataTableRelativeDate.test.ts +412 -0
  171. package/tests/docAccess.test.ts +525 -0
  172. package/tests/editLogEntry.test.ts +112 -0
  173. package/tests/email.test.ts +39 -0
  174. package/tests/fieldDocProgram.test.ts +114 -0
  175. package/tests/logDisplay.fixtures.ts +67 -0
  176. package/tests/logDisplay.test.ts +227 -0
  177. package/tests/noteDoc.test.ts +514 -0
  178. package/tests/richTextHTML.test.ts +185 -0
  179. package/tests/sheetAxisMove.test.ts +352 -0
  180. package/tests/sheetBootstrap.test.ts +1967 -0
  181. package/tests/sheetFeatureReference.test.ts +22 -0
  182. package/tests/sheetFormulaCriteria.test.ts +269 -0
  183. package/tests/sheetFormulaEvaluator.test.ts +468 -0
  184. package/tests/sheetFormulaFunctions.test.ts +538 -0
  185. package/tests/sheetFormulaLanguage.test.ts +361 -0
  186. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  187. package/tests/sheetFormulaParity.test.ts +188 -0
  188. package/tests/sheetFormulaRange.test.ts +167 -0
  189. package/tests/sheetFormulaReference.test.ts +78 -0
  190. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  191. package/tests/sheetFormulaTextDate.test.ts +512 -0
  192. package/tests/sheetSequence.test.ts +22 -0
  193. package/tests/sheetSnapshot.test.ts +134 -0
  194. package/tests/sheetStructureEdit.test.ts +537 -0
  195. package/tests/sheetStructureReferences.test.ts +589 -0
  196. package/tests/workflowLifecycleStatus.test.ts +60 -0
  197. package/tests/workflowLogFingerprint.test.ts +203 -0
  198. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  199. package/tests/workflowProgress.test.ts +180 -0
  200. package/tests/workflowTriggers.test.ts +29 -0
  201. package/tsconfig.json +12 -0
  202. package/vitest.config.ts +8 -0
@@ -0,0 +1,239 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import {
3
+ areCampaignFormAccessPoliciesEqual,
4
+ buildCampaignFormAccessPolicy,
5
+ getCampaignFormAccessibleOrganizationIds,
6
+ normalizeCampaignFormAccessGrants,
7
+ } from '../src/utils/campaignAccess.ts';
8
+
9
+ /*
10
+ * Cover campaign-form grant normalization at the access_grants boundary.
11
+ */
12
+ describe('normalizeCampaignFormAccessGrants', () => {
13
+ /*
14
+ * Normalize ids, sort grants, and resolve duplicate organization rows using
15
+ * the final permission supplied by the database snapshot.
16
+ */
17
+ it('normalizes valid organization grants deterministically', () => {
18
+ expect(
19
+ normalizeCampaignFormAccessGrants([
20
+ {
21
+ granteeType: 'ORGANIZATION',
22
+ granteeId: 2,
23
+ permission: 'VIEW',
24
+ },
25
+ {
26
+ granteeType: 'ORGANIZATION',
27
+ granteeId: '1',
28
+ permission: 'VIEW',
29
+ },
30
+ {
31
+ granteeType: 'ORGANIZATION',
32
+ granteeId: 2n,
33
+ permission: 'NONE',
34
+ },
35
+ ]),
36
+ ).toEqual([
37
+ {
38
+ granteeType: 'ORGANIZATION',
39
+ granteeId: '1',
40
+ permission: 'VIEW',
41
+ },
42
+ {
43
+ granteeType: 'ORGANIZATION',
44
+ granteeId: '2',
45
+ permission: 'NONE',
46
+ },
47
+ ]);
48
+ });
49
+
50
+ /*
51
+ * Reject grant shapes that the campaign-form policy and database constraint
52
+ * do not support.
53
+ */
54
+ it('filters account grants and EDIT organization grants', () => {
55
+ expect(
56
+ normalizeCampaignFormAccessGrants([
57
+ {
58
+ granteeType: 'ACCOUNT',
59
+ granteeId: '10',
60
+ permission: 'VIEW',
61
+ },
62
+ {
63
+ granteeType: 'ORGANIZATION',
64
+ granteeId: '20',
65
+ permission: 'EDIT',
66
+ },
67
+ {
68
+ granteeType: 'ORGANIZATION',
69
+ granteeId: '30',
70
+ permission: 'VIEW',
71
+ },
72
+ ]),
73
+ ).toEqual([
74
+ {
75
+ granteeType: 'ORGANIZATION',
76
+ granteeId: '30',
77
+ permission: 'VIEW',
78
+ },
79
+ ]);
80
+ });
81
+ });
82
+
83
+ /*
84
+ * Cover effective organization access derived from a CHILD_ORGS policy.
85
+ */
86
+ describe('getCampaignFormAccessibleOrganizationIds', () => {
87
+ /*
88
+ * Apply NONE exclusions to child organizations and VIEW additions to
89
+ * organizations outside the campaign owner's network.
90
+ */
91
+ it('excludes blocked children and includes explicitly granted external organizations', () => {
92
+ expect(
93
+ getCampaignFormAccessibleOrganizationIds(
94
+ 'CHILD_ORGS',
95
+ ['10', 20, 30n],
96
+ [
97
+ {
98
+ granteeType: 'ORGANIZATION',
99
+ granteeId: '20',
100
+ permission: 'NONE',
101
+ },
102
+ {
103
+ granteeType: 'ORGANIZATION',
104
+ granteeId: 40,
105
+ permission: 'VIEW',
106
+ },
107
+ ],
108
+ ),
109
+ ).toEqual(['10', '30', '40']);
110
+ });
111
+ });
112
+
113
+ /*
114
+ * Cover construction of the complete access_grants replacement policy.
115
+ */
116
+ describe('buildCampaignFormAccessPolicy', () => {
117
+ /*
118
+ * Ensure the open-link audience cannot retain stale organization overrides.
119
+ */
120
+ it('clears every grant when the audience is ANYONE', () => {
121
+ expect(
122
+ buildCampaignFormAccessPolicy({
123
+ audience: 'ANYONE',
124
+ currentGrants: [
125
+ {
126
+ granteeType: 'ORGANIZATION',
127
+ granteeId: '10',
128
+ permission: 'NONE',
129
+ },
130
+ ],
131
+ organizations: [{ id: '10', available: true, inNetwork: true }],
132
+ selectedPermissions: { 20: 'VIEW' },
133
+ }),
134
+ ).toEqual({ audience: 'ANYONE', grants: [] });
135
+ });
136
+
137
+ /*
138
+ * Preserve untouched grants from the authoritative snapshot while applying
139
+ * current selections and removing selections restored to their base policy.
140
+ */
141
+ it('rebases selected permissions onto the current access grants', () => {
142
+ expect(
143
+ buildCampaignFormAccessPolicy({
144
+ audience: 'CHILD_ORGS',
145
+ currentGrants: [
146
+ {
147
+ granteeType: 'ORGANIZATION',
148
+ granteeId: '10',
149
+ permission: 'NONE',
150
+ },
151
+ {
152
+ granteeType: 'ORGANIZATION',
153
+ granteeId: '20',
154
+ permission: 'VIEW',
155
+ },
156
+ {
157
+ granteeType: 'ORGANIZATION',
158
+ granteeId: '30',
159
+ permission: 'NONE',
160
+ },
161
+ ],
162
+ organizations: [
163
+ { id: '10', available: true, inNetwork: true },
164
+ { id: '20', available: true, inNetwork: false },
165
+ { id: '30', available: true, inNetwork: true },
166
+ { id: '40', available: true, inNetwork: false },
167
+ ],
168
+ selectedPermissions: {
169
+ 10: 'VIEW',
170
+ 40: 'VIEW',
171
+ },
172
+ }),
173
+ ).toEqual({
174
+ audience: 'CHILD_ORGS',
175
+ grants: [
176
+ {
177
+ granteeType: 'ORGANIZATION',
178
+ granteeId: '20',
179
+ permission: 'VIEW',
180
+ },
181
+ {
182
+ granteeType: 'ORGANIZATION',
183
+ granteeId: '30',
184
+ permission: 'NONE',
185
+ },
186
+ {
187
+ granteeType: 'ORGANIZATION',
188
+ granteeId: '40',
189
+ permission: 'VIEW',
190
+ },
191
+ ],
192
+ });
193
+ });
194
+ });
195
+
196
+ /*
197
+ * Cover semantic comparison of complete campaign-form access policies.
198
+ */
199
+ describe('areCampaignFormAccessPoliciesEqual', () => {
200
+ /*
201
+ * Treat row order and transport-level id representations as irrelevant.
202
+ */
203
+ it('normalizes grant order and ids before comparing policies', () => {
204
+ expect(
205
+ areCampaignFormAccessPoliciesEqual(
206
+ {
207
+ audience: 'CHILD_ORGS',
208
+ grants: [
209
+ {
210
+ granteeType: 'ORGANIZATION',
211
+ granteeId: 20,
212
+ permission: 'NONE',
213
+ },
214
+ {
215
+ granteeType: 'ORGANIZATION',
216
+ granteeId: 10n,
217
+ permission: 'VIEW',
218
+ },
219
+ ],
220
+ },
221
+ {
222
+ audience: 'CHILD_ORGS',
223
+ grants: [
224
+ {
225
+ granteeType: 'ORGANIZATION',
226
+ granteeId: '10',
227
+ permission: 'VIEW',
228
+ },
229
+ {
230
+ granteeType: 'ORGANIZATION',
231
+ granteeId: '20',
232
+ permission: 'NONE',
233
+ },
234
+ ],
235
+ },
236
+ ),
237
+ ).toBe(true);
238
+ });
239
+ });
@@ -0,0 +1,441 @@
1
+ import { expect, it } from 'vitest';
2
+ import { CAMPAIGN_EMAIL_MAX_INLINE_IMAGE_BYTES, CAMPAIGN_EMAIL_UNSUBSCRIBE_URL_PLACEHOLDER } from '../src/constants/campaign.ts';
3
+ import type { CampaignEmailBlockObj, CampaignEmailDefinitionObj } from '../src/types/campaign.d.ts';
4
+ import {
5
+ getCampaignEmailBlockStorageSettings,
6
+ getCampaignEmailRichTextNoteDoc,
7
+ getCampaignEmailValidationErrors,
8
+ serializeCampaignEmailRichText,
9
+ } from '../src/utils/campaignEmail.ts';
10
+ import { compileCampaignEmailDefinition } from '../src/utils/campaignEmailCompiler.ts';
11
+ import {
12
+ getCampaignEmailImageAssetSize,
13
+ getCampaignEmailImageAssetURL,
14
+ getCampaignEmailImageSource,
15
+ } from '../src/utils/campaignEmailImages.ts';
16
+
17
+ /*
18
+ * Build one normalized rich-text block for compiler and validation tests.
19
+ */
20
+ function createRichTextBlock(overrides: Partial<CampaignEmailBlockObj> = {}): CampaignEmailBlockObj {
21
+ return {
22
+ key: 'block-1',
23
+ order: 0,
24
+ type: 'RICH_TEXT',
25
+ content: {
26
+ richText: serializeCampaignEmailRichText({
27
+ type: 'doc',
28
+ version: 1,
29
+ content: [
30
+ {
31
+ type: 'paragraph',
32
+ content: [{ type: 'text', text: 'Hello <team>' }],
33
+ },
34
+ ],
35
+ }),
36
+ links: [],
37
+ },
38
+ settings: {
39
+ alignment: 'LEFT',
40
+ padding: '16px',
41
+ },
42
+ ...overrides,
43
+ };
44
+ }
45
+
46
+ /*
47
+ * Build one minimal valid single-column email document.
48
+ */
49
+ function createEmailDefinition(): CampaignEmailDefinitionObj {
50
+ return {
51
+ schemaVersion: 1,
52
+ rows: [
53
+ {
54
+ key: 'row-1',
55
+ order: 0,
56
+ settings: { padding: '0px' },
57
+ columns: [
58
+ {
59
+ key: 'column-1',
60
+ order: 0,
61
+ width: 100,
62
+ blocks: [createRichTextBlock()],
63
+ },
64
+ ],
65
+ },
66
+ ],
67
+ };
68
+ }
69
+
70
+ it('normalizes persisted block settings and sanitized rich text', () => {
71
+ const normalized = getCampaignEmailBlockStorageSettings({
72
+ columnKey: ' column-1 ',
73
+ type: 'RICH_TEXT',
74
+ content: {
75
+ richText: JSON.stringify({
76
+ type: 'doc',
77
+ content: [
78
+ {
79
+ type: 'paragraph',
80
+ content: [
81
+ {
82
+ type: 'text',
83
+ text: 'Safe',
84
+ marks: [{ type: 'link', attrs: { href: 'javascript:alert(1)' } }],
85
+ },
86
+ ],
87
+ },
88
+ ],
89
+ }),
90
+ },
91
+ });
92
+
93
+ expect(normalized?.columnKey).toBe('column-1');
94
+ expect(normalized?.settings.alignment).toBe('LEFT');
95
+ expect(normalized?.content.richText).not.toContain('javascript:');
96
+ });
97
+
98
+ it('round-trips one canonical local RichTextDocument by identity without persisting editor keys', () => {
99
+ const localDoc = {
100
+ type: 'doc' as const,
101
+ version: 1,
102
+ content: [
103
+ {
104
+ type: 'paragraph' as const,
105
+ _key: 'client-block-key',
106
+ content: [{ type: 'text' as const, text: 'Stable caret' }],
107
+ },
108
+ ],
109
+ };
110
+ const serialized = serializeCampaignEmailRichText(localDoc);
111
+
112
+ expect(serialized).not.toContain('_key');
113
+ expect(getCampaignEmailRichTextNoteDoc(serialized)).toBe(localDoc);
114
+ });
115
+
116
+ it('compiles one escaped responsive HTML and plain-text pair', () => {
117
+ const compiled = compileCampaignEmailDefinition({
118
+ definition: createEmailDefinition(),
119
+ settings: {
120
+ subject: 'Update',
121
+ preheader: 'A <safe> preview',
122
+ aiAgentDomain: 'orders.marketday.ai',
123
+ design: {
124
+ contentWidth: 600,
125
+ fontFamily: 'Georgia, serif',
126
+ linkColor: '#123456',
127
+ padding: '24px 20px',
128
+ },
129
+ trackOpens: true,
130
+ },
131
+ organizationName: 'Market <Day>',
132
+ unsubscribeUrl: 'https://example.test/unsubscribe',
133
+ });
134
+
135
+ expect(compiled.text).toContain('Hello <team>');
136
+ expect(compiled.text).toContain('https://example.test/unsubscribe');
137
+ expect(compiled.html).toContain('Hello &lt;team&gt;');
138
+ expect(compiled.html).toContain('A &lt;safe&gt; preview');
139
+ expect(compiled.html).toContain('color:#123456;position:static;text-decoration:underline');
140
+ expect(compiled.html).not.toContain('@font-face');
141
+ expect(compiled.html).toContain('font-family:Georgia, serif');
142
+ expect(compiled.html).toContain('padding:24px 20px');
143
+ expect(compiled.html).toContain('https://example.test/unsubscribe');
144
+ expect(compiled.html).not.toContain('Market <Day>');
145
+ });
146
+
147
+ it('reports invalid column widths and broken links, but tolerates empty blocks', () => {
148
+ const definition = createEmailDefinition();
149
+ definition.rows[0].columns[0].width = 60;
150
+ definition.rows[0].columns[0].blocks = [
151
+ createRichTextBlock({
152
+ key: 'empty_button',
153
+ type: 'BUTTON',
154
+ content: { links: [] },
155
+ }),
156
+ createRichTextBlock({
157
+ key: 'empty_heading',
158
+ type: 'HEADING',
159
+ content: { links: [] },
160
+ }),
161
+ createRichTextBlock({
162
+ key: 'empty_image',
163
+ type: 'IMAGE',
164
+ content: { links: [] },
165
+ }),
166
+ createRichTextBlock({
167
+ key: 'broken_button',
168
+ type: 'BUTTON',
169
+ content: { buttonLabel: 'Go', buttonUrl: 'example.com', links: [] },
170
+ }),
171
+ ];
172
+
173
+ expect(getCampaignEmailValidationErrors(definition)).toEqual([
174
+ { code: 'INVALID_COLUMN_WIDTH', rowKey: definition.rows[0].key },
175
+ { code: 'INVALID_LINK', blockKey: 'broken_button' },
176
+ ]);
177
+ });
178
+
179
+ it('omits empty blocks and empty rows from the compiled email', () => {
180
+ const definition = createEmailDefinition();
181
+ definition.rows[0].columns[0].blocks = [
182
+ createRichTextBlock({
183
+ key: 'empty_heading',
184
+ type: 'HEADING',
185
+ content: { links: [] },
186
+ }),
187
+ createRichTextBlock({
188
+ key: 'empty_image',
189
+ type: 'IMAGE',
190
+ content: { links: [] },
191
+ }),
192
+ createRichTextBlock({
193
+ key: 'empty_button',
194
+ type: 'BUTTON',
195
+ content: { links: [] },
196
+ }),
197
+ ];
198
+ definition.rows.push({
199
+ ...definition.rows[0],
200
+ key: 'row_with_text',
201
+ order: 1,
202
+ columns: [
203
+ {
204
+ ...definition.rows[0].columns[0],
205
+ key: 'column_with_text',
206
+ blocks: [
207
+ createRichTextBlock({
208
+ key: 'heading_with_text',
209
+ type: 'HEADING',
210
+ content: {
211
+ heading: 'Visible heading',
212
+ headingLevel: 'H2',
213
+ links: [],
214
+ },
215
+ }),
216
+ ],
217
+ },
218
+ ],
219
+ });
220
+
221
+ const compiled = compileCampaignEmailDefinition({
222
+ definition,
223
+ settings: {
224
+ subject: 'Update',
225
+ aiAgentDomain: 'orders.marketday.ai',
226
+ design: { contentWidth: 600, padding: '0px' },
227
+ trackOpens: true,
228
+ },
229
+ });
230
+
231
+ expect(compiled.html).not.toContain('<h1');
232
+ expect(compiled.html).not.toContain('<img');
233
+ expect(compiled.html).not.toContain('display:inline-block;padding:12px 20px');
234
+ expect(compiled.html).toContain('<h2');
235
+ expect(compiled.html).toContain('Visible heading');
236
+ expect(compiled.html.match(/<table /g)?.length).toBe(3);
237
+ expect(compiled.html).toContain("@font-face{font-family:'ttnp'");
238
+ expect(compiled.html).not.toContain('max-height:0');
239
+ });
240
+
241
+ it('keeps row padding, backgrounds and typography when flattening a full-width column', () => {
242
+ const definition = createEmailDefinition();
243
+ definition.rows[0].settings = { padding: '12px 20px', backgroundColor: '#abcdef' };
244
+ const compiled = compileCampaignEmailDefinition({
245
+ definition,
246
+ settings: {
247
+ design: { contentWidth: 600, fontFamily: 'Georgia, serif', padding: '0px', textColor: '#123456' },
248
+ trackOpens: false,
249
+ },
250
+ });
251
+
252
+ expect(compiled.html.match(/<table /g)?.length).toBe(3);
253
+ expect(compiled.html).toContain('background:#abcdef;border-collapse:collapse;width:100%');
254
+ expect(compiled.html).toContain('<td valign="top" style="color:#123456;font-family:Georgia, serif;');
255
+ expect(compiled.html).toContain('padding:12px 20px');
256
+ expect(compiled.html).toContain('Hello &lt;team&gt;');
257
+ expect(compiled.html).not.toContain('<td class="campaign-email-column"');
258
+ });
259
+
260
+ it('rejects unsafe or oversized inline email images before send', () => {
261
+ const definition = createEmailDefinition();
262
+ definition.rows[0].columns[0].blocks = [
263
+ createRichTextBlock({
264
+ content: { altText: 'Unsafe image', links: [] },
265
+ files: [
266
+ {
267
+ contentType: 'image/svg+xml',
268
+ id: 'unsafe-image',
269
+ order: 0,
270
+ size: CAMPAIGN_EMAIL_MAX_INLINE_IMAGE_BYTES + 1,
271
+ uri: 'campaign/unsafe.svg',
272
+ },
273
+ ],
274
+ type: 'IMAGE',
275
+ }),
276
+ ];
277
+
278
+ expect(getCampaignEmailValidationErrors(definition).map((error) => error.code)).toEqual([
279
+ 'INVALID_IMAGE_TYPE',
280
+ 'INLINE_IMAGES_TOO_LARGE',
281
+ ]);
282
+ });
283
+
284
+ it('renders composite heroes and a linked video fallback without thumbnails', () => {
285
+ const definition = createEmailDefinition();
286
+ definition.rows[0].columns[0].blocks = [
287
+ createRichTextBlock({
288
+ key: 'hero',
289
+ type: 'HERO',
290
+ content: {
291
+ altText: 'Harvest update',
292
+ buttonLabel: 'Read more',
293
+ buttonUrl: 'https://example.test/story',
294
+ heading: 'Fresh this week',
295
+ links: [],
296
+ text: 'A short market update.',
297
+ url: 'https://example.test/hero.jpg',
298
+ },
299
+ }),
300
+ createRichTextBlock({
301
+ key: 'video',
302
+ order: 1,
303
+ type: 'VIDEO',
304
+ content: {
305
+ altText: 'Watch the update',
306
+ links: [],
307
+ url: 'https://example.test/video',
308
+ },
309
+ }),
310
+ ];
311
+
312
+ const compiled = compileCampaignEmailDefinition({
313
+ definition,
314
+ settings: {
315
+ design: { contentWidth: 600, padding: '0px' },
316
+ aiAgentDomain: 'orders.marketday.ai',
317
+ trackOpens: true,
318
+ },
319
+ });
320
+
321
+ expect(getCampaignEmailValidationErrors(definition)).toEqual([]);
322
+ expect(compiled.html).toContain('Fresh this week');
323
+ expect(compiled.html).toContain('A short market update.');
324
+ expect(compiled.html).toContain('Read more');
325
+ expect(compiled.html).toContain('Watch the update');
326
+ expect(compiled.text).toContain('Read more: https://example.test/story');
327
+ expect(compiled.text).toContain('Watch the update: https://example.test/video');
328
+ expect(compiled.html).toContain(CAMPAIGN_EMAIL_UNSUBSCRIBE_URL_PLACEHOLDER);
329
+ expect(compiled.text).toContain(CAMPAIGN_EMAIL_UNSUBSCRIBE_URL_PLACEHOLDER);
330
+ });
331
+
332
+ it('sizes block images to their slot with an HTML width attribute for clients that ignore CSS', () => {
333
+ const definition = createEmailDefinition();
334
+ definition.rows[0].settings = { padding: '0px 10px' };
335
+ definition.rows[0].columns = [
336
+ {
337
+ key: 'left',
338
+ order: 0,
339
+ width: 50,
340
+ blocks: [
341
+ createRichTextBlock({
342
+ key: 'image',
343
+ type: 'IMAGE',
344
+ content: { altText: 'Photo', links: [], url: 'https://example.test/photo.jpg' },
345
+ }),
346
+ ],
347
+ },
348
+ { key: 'right', order: 1, width: 50, blocks: [createRichTextBlock({ key: 'text' })] },
349
+ ];
350
+
351
+ const compiled = compileCampaignEmailDefinition({
352
+ definition,
353
+ settings: {
354
+ design: { contentWidth: 720, padding: '0px' },
355
+ aiAgentDomain: 'orders.marketday.ai',
356
+ trackOpens: true,
357
+ },
358
+ });
359
+
360
+ // (720px content - 20px row padding) * 50% column - 32px block padding.
361
+ expect(compiled.html).toContain('<img src="https://example.test/photo.jpg" alt="Photo" width="318" style=');
362
+ expect(compiled.html).toContain('width:100%');
363
+ expect(compiled.html.match(/<table /g)?.length).toBe(4);
364
+ expect(compiled.html.match(/<td class="campaign-email-column" width="50%"/g)?.length).toBe(2);
365
+ });
366
+
367
+ it('resolves owned uploads to asset-server variants and keeps other images unchanged', () => {
368
+ expect(getCampaignEmailImageAssetSize(320, 2)).toBe('small');
369
+ expect(getCampaignEmailImageAssetSize(321, 2)).toBe('medium');
370
+ expect(getCampaignEmailImageAssetSize(undefined)).toBe('medium');
371
+ expect(getCampaignEmailImageAssetURL('12/photo.jpg', 'small')).toBe(
372
+ 'https://assets.chiefhappiness.co/marketday/12/photo.jpg?size=small',
373
+ );
374
+ expect(
375
+ getCampaignEmailImageAssetURL('https://assets.chiefhappiness.co/marketday/12/photo.jpg?size=small&download=1', 'medium'),
376
+ ).toBe('https://assets.chiefhappiness.co/marketday/12/photo.jpg?size=medium');
377
+ expect(getCampaignEmailImageAssetURL('https://example.test/photo.jpg', 'small')).toBeNull();
378
+ expect(getCampaignEmailImageAssetURL('blob:https://app.test/1', 'small')).toBeNull();
379
+ expect(getCampaignEmailImageSource('https://example.test/photo.jpg', 100)).toBe('https://example.test/photo.jpg');
380
+ });
381
+
382
+ it('links uploaded images from the asset server at the variant that stays sharp in their slot', () => {
383
+ const definition = createEmailDefinition();
384
+ definition.rows = [
385
+ {
386
+ key: 'wide-row',
387
+ order: 0,
388
+ settings: { padding: '0px' },
389
+ columns: [
390
+ {
391
+ key: 'wide',
392
+ order: 0,
393
+ width: 100,
394
+ blocks: [
395
+ createRichTextBlock({
396
+ key: 'hero',
397
+ type: 'HERO',
398
+ content: { altText: 'Hero', links: [] },
399
+ files: [{ id: 'hero-file', order: 0, uri: '12/hero.jpg' }],
400
+ }),
401
+ ],
402
+ },
403
+ ],
404
+ },
405
+ {
406
+ key: 'narrow-row',
407
+ order: 1,
408
+ settings: { padding: '0px' },
409
+ columns: [
410
+ {
411
+ key: 'left',
412
+ order: 0,
413
+ width: 50,
414
+ blocks: [
415
+ createRichTextBlock({
416
+ key: 'photo',
417
+ type: 'IMAGE',
418
+ content: { altText: 'Photo', links: [] },
419
+ files: [{ id: 'photo-file', order: 0, uri: '12/photo.jpg' }],
420
+ }),
421
+ ],
422
+ },
423
+ { key: 'right', order: 1, width: 50, blocks: [createRichTextBlock({ key: 'text' })] },
424
+ ],
425
+ },
426
+ ];
427
+
428
+ const compiled = compileCampaignEmailDefinition({
429
+ definition,
430
+ settings: {
431
+ design: { contentWidth: 600, padding: '0px' },
432
+ aiAgentDomain: 'orders.marketday.ai',
433
+ trackOpens: true,
434
+ },
435
+ });
436
+
437
+ // A 568px hero needs 1136px on a 2x screen (medium); a 268px half-column image fits the 640px small variant.
438
+ expect(compiled.html).toContain('src="https://assets.chiefhappiness.co/marketday/12/hero.jpg?size=medium"');
439
+ expect(compiled.html).toContain('src="https://assets.chiefhappiness.co/marketday/12/photo.jpg?size=small"');
440
+ expect(compiled.html).not.toContain('cid:');
441
+ });