@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.
- package/package.json +58 -23
- package/src/constants/agentMemory.ts +14 -45
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +156 -47
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +12 -38
- package/src/constants/dataTableFieldTypes.generated.ts +3 -7
- package/src/constants/docAccess.ts +3 -2
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +114 -12
- package/src/constants/fieldDoc.ts +74 -4
- package/src/constants/graphqlReactivity.ts +108 -25
- package/src/constants/log.ts +9 -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 +1834 -730
- package/src/constants/organization.ts +13 -14
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +65 -101
- package/src/constants/sms.ts +18 -0
- package/src/constants/storage.ts +33 -9
- package/src/constants/usage.ts +3 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +106 -283
- package/src/schemas/inboundContact.ts +5 -5
- package/src/types/agentMemory.d.ts +38 -14
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1043 -193
- 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 +102 -309
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +144 -55
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +579 -150
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +8 -0
- package/src/types/log.d.ts +94 -3
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +8 -3
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +180 -463
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +266 -27
- package/src/types/workflow.d.ts +196 -66
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +31 -14
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +642 -209
- 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 +18 -556
- package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/email.ts +208 -1
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +81 -37
- 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 +232 -141
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logStoreRead.ts +9 -13
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomyDisplay.ts +80 -124
- package/src/utils/noteDoc.ts +66 -284
- package/src/utils/organization.ts +117 -283
- 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 +123 -4834
- package/src/utils/sheetAxisMove.ts +77 -291
- package/src/utils/sheetBootstrap.ts +771 -1138
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +23 -88
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +17 -69
- 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 +388 -403
- package/src/utils/sheetFormulaEvaluator.ts +589 -444
- 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 +140 -18
- package/src/utils/sheetNumberFormat.ts +68 -267
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +13 -43
- package/src/utils/sheetSnapshot.ts +176 -429
- package/src/utils/sheetStructureEdit.ts +537 -907
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/storage.ts +49 -3
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +199 -73
- 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 +2 -1
- package/tests/dataTableRelativeDate.test.ts +412 -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 +37 -192
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +49 -40
- 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 +93 -200
- 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 +4 -23
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +492 -37
- 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/src/constants/agentDoc.ts +0 -12
- package/src/constants/logActivityGroupColors.generated.ts +0 -19
- package/src/constants/schedule.ts +0 -220
- package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
- package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
- package/src/constants/sheetRegionSources.generated.ts +0 -578
- package/src/schemas/fieldDocsQuery.ts +0 -12
- package/src/schemas/organization.ts +0 -68
- package/src/types/agentDoc.d.ts +0 -64
- package/src/types/noteDoc.d.ts +0 -86
- package/src/types/schedule.d.ts +0 -391
- package/src/utils/agentDoc.ts +0 -109
- package/src/utils/campaignFormEditor.ts +0 -871
- package/src/utils/dataTableRealtimeAuthority.ts +0 -209
- package/src/utils/dataTableRealtimeSelection.ts +0 -134
- package/src/utils/dataTableRowDocument.ts +0 -508
- package/src/utils/dataTableSource.ts +0 -230
- package/src/utils/schedule.ts +0 -799
- package/src/utils/scheduleEvaluation.ts +0 -1994
- package/src/utils/scheduleICS.ts +0 -246
- package/src/utils/scheduleRuleTemplates.ts +0 -188
- package/src/utils/sheetRegion.ts +0 -374
- package/src/utils/sheetRegionFilter.ts +0 -1259
- package/src/utils/sheetRegionSourceRegistry.ts +0 -594
- package/tests/schedule.test.ts +0 -693
- package/tests/scheduleEvaluation.test.ts +0 -1970
- package/tests/scheduleICS.test.ts +0 -208
- package/tests/scheduleRuleTemplates.test.ts +0 -176
- package/tests/scheduleSweepInvariants.test.ts +0 -428
- package/tests/sheetRegionFilter.test.ts +0 -1135
|
@@ -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 <team>');
|
|
138
|
+
expect(compiled.html).toContain('A <safe> 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 <team>');
|
|
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
|
+
});
|