@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,203 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
canonicalizeWorkflowFingerprintValue,
|
|
4
|
+
getWorkflowLogFingerprintProjections,
|
|
5
|
+
serializeWorkflowFingerprintProjection,
|
|
6
|
+
} from '../src/utils/workflowLogFingerprint.ts';
|
|
7
|
+
|
|
8
|
+
const BASE_LOG = {
|
|
9
|
+
id: 19006n,
|
|
10
|
+
organizationId: 28,
|
|
11
|
+
childOrgId: '47',
|
|
12
|
+
siteId: null,
|
|
13
|
+
date: new Date('2026-08-11T16:00:00.000-04:00'),
|
|
14
|
+
summary: 'Market credits',
|
|
15
|
+
details: {
|
|
16
|
+
activity: 'MARKET_CREDIT_RECEIPT',
|
|
17
|
+
logType: 'MARKET_RECEIPT',
|
|
18
|
+
notes: 'August redemption',
|
|
19
|
+
metadata: {
|
|
20
|
+
flagColor: 'green',
|
|
21
|
+
item: 'Market credits',
|
|
22
|
+
quantity: 3,
|
|
23
|
+
unit: 'bundles',
|
|
24
|
+
price: 12.5,
|
|
25
|
+
otherParty: 'Bruno Arable',
|
|
26
|
+
referenceNumber: 'BM-77',
|
|
27
|
+
tax: 1.25,
|
|
28
|
+
voided: false,
|
|
29
|
+
values: [
|
|
30
|
+
{ label: 'Market Coin', quantity: 2, unit: 'coins', value: 20 },
|
|
31
|
+
{ label: 'Voucher', quantity: 1, value: 5 },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* Build canonical projections with stable presentation dependencies for tests.
|
|
39
|
+
*/
|
|
40
|
+
function getBaseProjections(flagColor?: string) {
|
|
41
|
+
return getWorkflowLogFingerprintProjections(BASE_LOG, {
|
|
42
|
+
...(flagColor === undefined ? {} : { flagColor }),
|
|
43
|
+
presentation: {
|
|
44
|
+
payee: { email: 'ar@bruno.example', name: 'Bruno Arable' },
|
|
45
|
+
issuer: { name: 'Marketday' },
|
|
46
|
+
timeZone: 'America/Toronto',
|
|
47
|
+
},
|
|
48
|
+
attachmentManifest: [{ name: 'terms.pdf', contentHash: 'sha256:abc' }],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe('workflow log fingerprint projections', () => {
|
|
53
|
+
it('normalizes recursive values with stable keys, IDs, dates, and explicit nulls', () => {
|
|
54
|
+
const left = {
|
|
55
|
+
z: undefined,
|
|
56
|
+
id: 22n,
|
|
57
|
+
when: new Date('2026-08-11T20:00:00.000Z'),
|
|
58
|
+
nested: { b: -0, a: null },
|
|
59
|
+
rows: [{ y: 2, x: 1 }, undefined],
|
|
60
|
+
};
|
|
61
|
+
const right = {
|
|
62
|
+
rows: [{ x: 1, y: 2 }, null],
|
|
63
|
+
nested: { a: null, b: 0 },
|
|
64
|
+
when: '2026-08-11T20:00:00.000Z',
|
|
65
|
+
id: '22',
|
|
66
|
+
z: null,
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
expect(canonicalizeWorkflowFingerprintValue(left)).toEqual({
|
|
70
|
+
id: '22',
|
|
71
|
+
nested: { a: null, b: 0 },
|
|
72
|
+
rows: [{ x: 1, y: 2 }, null],
|
|
73
|
+
when: '2026-08-11T20:00:00.000Z',
|
|
74
|
+
z: null,
|
|
75
|
+
});
|
|
76
|
+
expect(serializeWorkflowFingerprintProjection(left)).toBe(
|
|
77
|
+
serializeWorkflowFingerprintProjection(right),
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('keeps flag color out of receipt content but includes it in workflow state', () => {
|
|
82
|
+
const green = getBaseProjections('green');
|
|
83
|
+
const red = getBaseProjections('RED');
|
|
84
|
+
|
|
85
|
+
expect(serializeWorkflowFingerprintProjection(green.receiptContent)).toBe(
|
|
86
|
+
serializeWorkflowFingerprintProjection(red.receiptContent),
|
|
87
|
+
);
|
|
88
|
+
expect(
|
|
89
|
+
serializeWorkflowFingerprintProjection(green.workflowState),
|
|
90
|
+
).not.toBe(serializeWorkflowFingerprintProjection(red.workflowState));
|
|
91
|
+
expect(green.workflowState.flagColor).toBe('GREEN');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('ignores volatile log fields that are outside delivered receipt semantics', () => {
|
|
95
|
+
const baseline = getBaseProjections();
|
|
96
|
+
const volatileEdit = getWorkflowLogFingerprintProjections(
|
|
97
|
+
{
|
|
98
|
+
...BASE_LOG,
|
|
99
|
+
createdAt: new Date('2020-01-01T00:00:00.000Z'),
|
|
100
|
+
updatedAt: new Date('2030-01-01T00:00:00.000Z'),
|
|
101
|
+
source: 'WEB',
|
|
102
|
+
confidence: 0.2,
|
|
103
|
+
originalMessage: 'raw source',
|
|
104
|
+
details: {
|
|
105
|
+
...BASE_LOG.details,
|
|
106
|
+
translation: 'translated',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
presentation: {
|
|
111
|
+
payee: { name: 'Bruno Arable', email: 'ar@bruno.example' },
|
|
112
|
+
issuer: { name: 'Marketday' },
|
|
113
|
+
timeZone: 'America/Toronto',
|
|
114
|
+
},
|
|
115
|
+
attachmentManifest: [{ contentHash: 'sha256:abc', name: 'terms.pdf' }],
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
expect(
|
|
120
|
+
serializeWorkflowFingerprintProjection(volatileEdit.receiptContent),
|
|
121
|
+
).toBe(serializeWorkflowFingerprintProjection(baseline.receiptContent));
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('changes canonical receipt content for rendered edits and line-item order', () => {
|
|
125
|
+
const baseline = getBaseProjections();
|
|
126
|
+
const edited = getWorkflowLogFingerprintProjections(
|
|
127
|
+
{
|
|
128
|
+
...BASE_LOG,
|
|
129
|
+
details: {
|
|
130
|
+
...BASE_LOG.details,
|
|
131
|
+
metadata: {
|
|
132
|
+
...BASE_LOG.details.metadata,
|
|
133
|
+
values: [...BASE_LOG.details.metadata.values].reverse(),
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
presentation: {
|
|
139
|
+
payee: { email: 'ar@bruno.example', name: 'Bruno Arable' },
|
|
140
|
+
issuer: { name: 'Marketday' },
|
|
141
|
+
timeZone: 'America/Toronto',
|
|
142
|
+
},
|
|
143
|
+
attachmentManifest: [{ name: 'terms.pdf', contentHash: 'sha256:abc' }],
|
|
144
|
+
},
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
expect(
|
|
148
|
+
serializeWorkflowFingerprintProjection(edited.receiptContent),
|
|
149
|
+
).not.toBe(serializeWorkflowFingerprintProjection(baseline.receiptContent));
|
|
150
|
+
expect(baseline.receiptContent).toMatchObject({
|
|
151
|
+
logId: '19006',
|
|
152
|
+
organizationId: '28',
|
|
153
|
+
vendorId: '47',
|
|
154
|
+
date: '2026-08-11T20:00:00.000Z',
|
|
155
|
+
quantity: 3,
|
|
156
|
+
unit: 'bundles',
|
|
157
|
+
price: 12.5,
|
|
158
|
+
voided: false,
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it.each([
|
|
163
|
+
['quantity', 4],
|
|
164
|
+
['unit', 'cases'],
|
|
165
|
+
['price', 14.75],
|
|
166
|
+
] as const)(
|
|
167
|
+
'changes receipt content when scalar transaction %s changes',
|
|
168
|
+
(field, value) => {
|
|
169
|
+
const baseline = getBaseProjections();
|
|
170
|
+
const edited = getWorkflowLogFingerprintProjections(
|
|
171
|
+
{
|
|
172
|
+
...BASE_LOG,
|
|
173
|
+
details: {
|
|
174
|
+
...BASE_LOG.details,
|
|
175
|
+
metadata: {
|
|
176
|
+
...BASE_LOG.details.metadata,
|
|
177
|
+
[field]: value,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
presentation: {
|
|
183
|
+
payee: { email: 'ar@bruno.example', name: 'Bruno Arable' },
|
|
184
|
+
issuer: { name: 'Marketday' },
|
|
185
|
+
timeZone: 'America/Toronto',
|
|
186
|
+
},
|
|
187
|
+
attachmentManifest: [
|
|
188
|
+
{
|
|
189
|
+
name: 'terms.pdf',
|
|
190
|
+
contentHash: 'sha256:abc',
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
expect(
|
|
197
|
+
serializeWorkflowFingerprintProjection(edited.receiptContent),
|
|
198
|
+
).not.toBe(
|
|
199
|
+
serializeWorkflowFingerprintProjection(baseline.receiptContent),
|
|
200
|
+
);
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { LogEntryData } from '../src/types/log.d.ts';
|
|
3
|
+
import {
|
|
4
|
+
makeWorkflowLogRevisionSnapshot,
|
|
5
|
+
parseWorkflowLogRevisionSnapshot,
|
|
6
|
+
} from '../src/utils/workflowLogRevisionSnapshot.ts';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Build one hydrated receipt log at a requested flag color.
|
|
10
|
+
*/
|
|
11
|
+
function makeReceiptLog(flagColor: string): LogEntryData {
|
|
12
|
+
return {
|
|
13
|
+
__table: 'logs',
|
|
14
|
+
id: 19006n,
|
|
15
|
+
organizationId: 28n,
|
|
16
|
+
accountId: 7n,
|
|
17
|
+
childOrgId: 47n,
|
|
18
|
+
inboundContactId: null,
|
|
19
|
+
emailId: null,
|
|
20
|
+
fieldDocId: null,
|
|
21
|
+
fieldDocSubmissionId: null,
|
|
22
|
+
siteId: null,
|
|
23
|
+
summary: 'Market credits',
|
|
24
|
+
source: 'WEB',
|
|
25
|
+
confidence: null,
|
|
26
|
+
originalMessage: null,
|
|
27
|
+
date: new Date('2026-08-11T20:00:00.000Z'),
|
|
28
|
+
createdAt: new Date('2026-08-11T20:00:00.000Z'),
|
|
29
|
+
updatedAt: new Date('2026-08-11T20:01:00.000Z'),
|
|
30
|
+
childOrg: {
|
|
31
|
+
id: 47n,
|
|
32
|
+
name: 'Bruno Market',
|
|
33
|
+
},
|
|
34
|
+
location: null,
|
|
35
|
+
account: {
|
|
36
|
+
id: 7n,
|
|
37
|
+
settings: {},
|
|
38
|
+
profile: {
|
|
39
|
+
firstName: 'Bruno',
|
|
40
|
+
lastName: 'Owner',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
details: {
|
|
44
|
+
__table: 'log_entry_details',
|
|
45
|
+
id: 19006n,
|
|
46
|
+
activity: 'MARKET_CREDIT_RECEIPT',
|
|
47
|
+
logType: 'MARKET_RECEIPT',
|
|
48
|
+
notes: 'August redemption',
|
|
49
|
+
translation: null,
|
|
50
|
+
fields: null,
|
|
51
|
+
metadata: {
|
|
52
|
+
flagColor,
|
|
53
|
+
referenceNumber: 'BM-77',
|
|
54
|
+
otherParty: 'Bruno Market',
|
|
55
|
+
values: [{ label: 'Market Coin', quantity: 2, value: 20 }],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('workflow log revision snapshots', () => {
|
|
62
|
+
it('preserves every rapid flag transition as an independent JSON-safe revision', () => {
|
|
63
|
+
const greenBefore = makeWorkflowLogRevisionSnapshot(
|
|
64
|
+
makeReceiptLog('green'),
|
|
65
|
+
);
|
|
66
|
+
const red = makeWorkflowLogRevisionSnapshot(makeReceiptLog('red'));
|
|
67
|
+
const greenAfter = makeWorkflowLogRevisionSnapshot(makeReceiptLog('green'));
|
|
68
|
+
|
|
69
|
+
expect(() => JSON.stringify([greenBefore, red, greenAfter])).not.toThrow();
|
|
70
|
+
expect([
|
|
71
|
+
parseWorkflowLogRevisionSnapshot(greenBefore).projections.workflowState
|
|
72
|
+
.flagColor,
|
|
73
|
+
parseWorkflowLogRevisionSnapshot(red).projections.workflowState.flagColor,
|
|
74
|
+
parseWorkflowLogRevisionSnapshot(greenAfter).projections.workflowState
|
|
75
|
+
.flagColor,
|
|
76
|
+
]).toEqual(['GREEN', 'RED', 'GREEN']);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('fails closed when stored projections no longer match the captured log', () => {
|
|
80
|
+
const snapshot = makeWorkflowLogRevisionSnapshot(makeReceiptLog('green'));
|
|
81
|
+
const malformed = {
|
|
82
|
+
...snapshot,
|
|
83
|
+
projections: {
|
|
84
|
+
...snapshot.projections,
|
|
85
|
+
workflowState: {
|
|
86
|
+
...snapshot.projections.workflowState,
|
|
87
|
+
flagColor: 'RED',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
expect(() => parseWorkflowLogRevisionSnapshot(malformed)).toThrow(
|
|
93
|
+
'projections do not match',
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
compactWorkflowProgressValues,
|
|
4
|
+
replaceWorkflowProgressAsyncOutcomeSection,
|
|
5
|
+
serializeWorkflowAsyncOutcomeSection,
|
|
6
|
+
updateWorkflowProgressAsyncOutcome,
|
|
7
|
+
WORKFLOW_PROGRESS_ASYNC_OUTCOMES_END,
|
|
8
|
+
WORKFLOW_PROGRESS_ASYNC_OUTCOMES_START,
|
|
9
|
+
WORKFLOW_SENT_EMAIL_STATUS_ENUMS,
|
|
10
|
+
WORKFLOW_SENT_FOLLOW_UP_STATUS_ENUMS,
|
|
11
|
+
WORKFLOW_SENT_REMINDER_STATUS_ENUMS,
|
|
12
|
+
WORKFLOW_SENT_SMS_STATUS_ENUMS,
|
|
13
|
+
WORKFLOW_SENT_WAIT_STATUS_ENUMS,
|
|
14
|
+
} from '../src/utils/workflowProgress.ts';
|
|
15
|
+
|
|
16
|
+
describe('workflow progress async outcomes', () => {
|
|
17
|
+
it('exposes normalized statuses independent of source-specific lifecycle names', () => {
|
|
18
|
+
expect(WORKFLOW_SENT_EMAIL_STATUS_ENUMS).toEqual([
|
|
19
|
+
'QUEUED',
|
|
20
|
+
'SENT',
|
|
21
|
+
'DELIVERED',
|
|
22
|
+
'FAILED',
|
|
23
|
+
'DELIVERY_UNKNOWN',
|
|
24
|
+
'BOUNCED',
|
|
25
|
+
'BLOCKED',
|
|
26
|
+
]);
|
|
27
|
+
expect(WORKFLOW_SENT_SMS_STATUS_ENUMS).toEqual(
|
|
28
|
+
WORKFLOW_SENT_EMAIL_STATUS_ENUMS,
|
|
29
|
+
);
|
|
30
|
+
expect(WORKFLOW_SENT_REMINDER_STATUS_ENUMS).toEqual([
|
|
31
|
+
'SCHEDULED',
|
|
32
|
+
'IN_PROGRESS',
|
|
33
|
+
'COMPLETED',
|
|
34
|
+
'FAILED',
|
|
35
|
+
'CANCELED',
|
|
36
|
+
]);
|
|
37
|
+
expect(WORKFLOW_SENT_FOLLOW_UP_STATUS_ENUMS).toEqual([
|
|
38
|
+
'SCHEDULED',
|
|
39
|
+
'FIRED',
|
|
40
|
+
'REPLACED',
|
|
41
|
+
'CANCELED',
|
|
42
|
+
]);
|
|
43
|
+
expect(WORKFLOW_SENT_WAIT_STATUS_ENUMS).toEqual([
|
|
44
|
+
'WAITING',
|
|
45
|
+
'REPLIED',
|
|
46
|
+
'EXPIRED',
|
|
47
|
+
'CANCELED',
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('serializes one deterministic line per source kind and ID', () => {
|
|
52
|
+
const section = serializeWorkflowAsyncOutcomeSection({
|
|
53
|
+
sentEmails: {
|
|
54
|
+
10: { status: 'BOUNCED', recipient: 'sarah@example.com' },
|
|
55
|
+
2: {
|
|
56
|
+
status: 'DELIVERED',
|
|
57
|
+
recipient: 'john@example.com',
|
|
58
|
+
occurredAt: new Date('2026-07-01T12:00:00.000Z'),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
sentWaits: {
|
|
62
|
+
7: { status: 'WAITING', detail: 'Waiting for a reply' },
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(section.split('\n')).toEqual([
|
|
67
|
+
WORKFLOW_PROGRESS_ASYNC_OUTCOMES_START,
|
|
68
|
+
'sentEmails:2\t{"occurredAt":"2026-07-01T12:00:00.000Z","recipient":"john@example.com","status":"DELIVERED"}',
|
|
69
|
+
'sentEmails:10\t{"recipient":"sarah@example.com","status":"BOUNCED"}',
|
|
70
|
+
'sentWaits:7\t{"detail":"Waiting for a reply","status":"WAITING"}',
|
|
71
|
+
WORKFLOW_PROGRESS_ASYNC_OUTCOMES_END,
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('replaces server outcomes without changing AI-authored narrative', () => {
|
|
76
|
+
const narrative = 'Sent the receipt to John.\nSarah still needs delivery.';
|
|
77
|
+
const first = replaceWorkflowProgressAsyncOutcomeSection(narrative, {
|
|
78
|
+
sentEmails: { 2: { status: 'SENT', recipient: 'john@example.com' } },
|
|
79
|
+
});
|
|
80
|
+
const next = replaceWorkflowProgressAsyncOutcomeSection(first, {
|
|
81
|
+
sentEmails: { 2: { status: 'DELIVERED', recipient: 'john@example.com' } },
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(next.startsWith(`${narrative}\n\n`)).toBe(true);
|
|
85
|
+
expect(
|
|
86
|
+
next.match(new RegExp(WORKFLOW_PROGRESS_ASYNC_OUTCOMES_START, 'g')),
|
|
87
|
+
).toHaveLength(1);
|
|
88
|
+
expect(next).toContain(
|
|
89
|
+
'sentEmails:2\t{"recipient":"john@example.com","status":"DELIVERED"}',
|
|
90
|
+
);
|
|
91
|
+
expect(next).not.toContain('"status":"SENT"');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('escapes sentinel-like provider text so every outcome remains one safe line', () => {
|
|
95
|
+
const section = serializeWorkflowAsyncOutcomeSection({
|
|
96
|
+
sentSMS: {
|
|
97
|
+
5: {
|
|
98
|
+
status: 'FAILED',
|
|
99
|
+
detail: `${WORKFLOW_PROGRESS_ASYNC_OUTCOMES_END}\nprovider failure`,
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(section.split('\n')).toHaveLength(3);
|
|
105
|
+
expect(section).toContain(
|
|
106
|
+
'\\u003c\\u003c\\u003cEND_SERVER_WORKFLOW_ASYNC_OUTCOMES_V1\\u003e\\u003e\\u003e',
|
|
107
|
+
);
|
|
108
|
+
expect(
|
|
109
|
+
section.match(new RegExp(WORKFLOW_PROGRESS_ASYNC_OUTCOMES_END, 'g')),
|
|
110
|
+
).toHaveLength(1);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('upserts one outcome while preserving unrelated values and map entries', () => {
|
|
114
|
+
const values = updateWorkflowProgressAsyncOutcome(
|
|
115
|
+
{
|
|
116
|
+
progressReport: 'AI narrative',
|
|
117
|
+
customValue: 'keep me',
|
|
118
|
+
sentEmails: {
|
|
119
|
+
4: { status: 'DELIVERED', recipient: 'john@example.com' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
'sentEmails',
|
|
123
|
+
9n,
|
|
124
|
+
{
|
|
125
|
+
status: 'BOUNCED',
|
|
126
|
+
recipient: 'sarah@example.com',
|
|
127
|
+
occurredAt: new Date('2026-07-02T13:00:00.000Z'),
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(values.customValue).toBe('keep me');
|
|
132
|
+
expect(values.sentEmails).toEqual({
|
|
133
|
+
4: { status: 'DELIVERED', recipient: 'john@example.com' },
|
|
134
|
+
9: {
|
|
135
|
+
status: 'BOUNCED',
|
|
136
|
+
recipient: 'sarah@example.com',
|
|
137
|
+
occurredAt: '2026-07-02T13:00:00.000Z',
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
expect(values.sentSMS).toBeUndefined();
|
|
141
|
+
expect(values.progressReport).toContain('AI narrative');
|
|
142
|
+
expect(values.progressReport).toContain('sentEmails:4');
|
|
143
|
+
expect(values.progressReport).toContain('sentEmails:9');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('treats missing outcome maps as empty without persisting unrelated empty maps', () => {
|
|
147
|
+
const values = updateWorkflowProgressAsyncOutcome({}, 'sentEmails', 1, {
|
|
148
|
+
status: 'QUEUED',
|
|
149
|
+
recipient: 'john@example.com',
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
expect(values.sentEmails?.['1']).toEqual({
|
|
153
|
+
status: 'QUEUED',
|
|
154
|
+
recipient: 'john@example.com',
|
|
155
|
+
});
|
|
156
|
+
expect(values.sentSMS).toBeUndefined();
|
|
157
|
+
expect(values.sentReminders).toBeUndefined();
|
|
158
|
+
expect(values.sentFollowUps).toBeUndefined();
|
|
159
|
+
expect(values.sentWaits).toBeUndefined();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('compacts legacy empty maps without removing populated or unrelated values', () => {
|
|
163
|
+
expect(
|
|
164
|
+
compactWorkflowProgressValues({
|
|
165
|
+
progressReport: 'Keep this',
|
|
166
|
+
customValue: true,
|
|
167
|
+
sentEmails: {},
|
|
168
|
+
sentSMS: {
|
|
169
|
+
2: { status: 'DELIVERED', recipient: '+14165550100' },
|
|
170
|
+
},
|
|
171
|
+
}),
|
|
172
|
+
).toEqual({
|
|
173
|
+
progressReport: 'Keep this',
|
|
174
|
+
customValue: true,
|
|
175
|
+
sentSMS: {
|
|
176
|
+
2: { status: 'DELIVERED', recipient: '+14165550100' },
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { hasWorkflowActiveTarget } from '../src/utils/workflow.ts';
|
|
3
|
+
import { canLogTriggerWorkflows, isWorkflowTriggerKeyAllowed } from '../src/utils/workflowTriggers.ts';
|
|
4
|
+
|
|
5
|
+
describe('app interaction logs never trigger log workflows', () => {
|
|
6
|
+
it('excludes the APP_INTERACTIONS group and its system-only activities, and nothing else', () => {
|
|
7
|
+
expect(canLogTriggerWorkflows('APP_INTERACTIONS', 'CAMPAIGN_FORM_SUBMISSION')).toBe(false);
|
|
8
|
+
expect(canLogTriggerWorkflows('APP_INTERACTIONS')).toBe(false);
|
|
9
|
+
expect(canLogTriggerWorkflows(null, 'CAMPAIGN_FORM_SUBMISSION')).toBe(false);
|
|
10
|
+
expect(canLogTriggerWorkflows('SEED', 'SEED_PURCHASE_INFO')).toBe(true);
|
|
11
|
+
expect(canLogTriggerWorkflows('FIELD')).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('never allows an interaction group or activity as a trigger key', () => {
|
|
15
|
+
expect(isWorkflowTriggerKeyAllowed('APP_INTERACTIONS')).toBe(false);
|
|
16
|
+
expect(isWorkflowTriggerKeyAllowed('activity:CAMPAIGN_FORM_SUBMISSION')).toBe(false);
|
|
17
|
+
expect(isWorkflowTriggerKeyAllowed('SEED')).toBe(true);
|
|
18
|
+
expect(isWorkflowTriggerKeyAllowed('activity:SEED_PURCHASE_INFO')).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('does not count interaction-only subscriptions as an active trigger target', () => {
|
|
22
|
+
expect(hasWorkflowActiveTarget({ logTypes: ['APP_INTERACTIONS'], fieldDocId: null, nextAt: null })).toBe(false);
|
|
23
|
+
expect(hasWorkflowActiveTarget({ logTypes: ['APP_INTERACTIONS', 'SEED'], fieldDocId: null, nextAt: null })).toBe(true);
|
|
24
|
+
expect(hasWorkflowActiveTarget({ logTypes: null, fieldDocId: '7', nextAt: null })).toBe(true);
|
|
25
|
+
// A web form tracker's managed workflow has no log trigger; its campaign bindings start it
|
|
26
|
+
expect(hasWorkflowActiveTarget({ logTypes: [], fieldDocId: null, nextAt: null, agentNoteId: '41' })).toBe(true);
|
|
27
|
+
expect(hasWorkflowActiveTarget({ logTypes: [], fieldDocId: null, nextAt: null, agentNoteId: null })).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Agent surfaces that can read agent docs. Maps from the server AI
|
|
3
|
-
* controller __type; per-document "settings.hiddenSurfaces" is a deny-list
|
|
4
|
-
* of these values, so a future surface added here is visible by default and
|
|
5
|
-
* stored settings never need a migration.
|
|
6
|
-
*/
|
|
7
|
-
export const AGENT_DOC_SURFACE_ENUMS = [
|
|
8
|
-
'CHAT',
|
|
9
|
-
'RUNNER',
|
|
10
|
-
'POSTMASTER',
|
|
11
|
-
'ANALYST',
|
|
12
|
-
] as const;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// GENERATED FILE — DO NOT EDIT BY HAND.
|
|
2
|
-
// Regenerate with: deno task generate:log-tools (reads the log taxonomy registry).
|
|
3
|
-
|
|
4
|
-
export const LOG_ACTIVITY_GROUP_COLORS: Readonly<Record<string, string>> = {
|
|
5
|
-
CLEANING_AND_SANITATION: 'teal',
|
|
6
|
-
EQUIPMENT: 'indigo',
|
|
7
|
-
FIELD: 'lime',
|
|
8
|
-
HARVEST: 'emerald',
|
|
9
|
-
MARKET_OPERATION: 'rose',
|
|
10
|
-
MARKET_RECEIPT: 'blue',
|
|
11
|
-
OPERATION: 'yellow',
|
|
12
|
-
PLANTING: 'amber',
|
|
13
|
-
POST_HARVEST: 'cyan',
|
|
14
|
-
PRODUCTION_INPUT: 'sky',
|
|
15
|
-
SALES: 'blue',
|
|
16
|
-
SEED: 'brown',
|
|
17
|
-
WATER: 'violet',
|
|
18
|
-
WORKER_PRACTICE: 'purple',
|
|
19
|
-
};
|