@jsb188/mday 1.1.11 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/package.json +58 -23
  2. package/src/constants/agentMemory.ts +14 -45
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +156 -47
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +12 -38
  10. package/src/constants/dataTableFieldTypes.generated.ts +3 -7
  11. package/src/constants/docAccess.ts +3 -2
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +114 -12
  14. package/src/constants/fieldDoc.ts +74 -4
  15. package/src/constants/graphqlReactivity.ts +108 -25
  16. package/src/constants/log.ts +9 -0
  17. package/src/constants/logDisplay/README.md +88 -0
  18. package/src/constants/logDisplay/defaults.ts +39 -0
  19. package/src/constants/logDisplay/index.ts +27 -0
  20. package/src/constants/logDisplay/operations/arable.ts +16 -0
  21. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  22. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  23. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  24. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  25. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  26. package/src/constants/logTaxonomy.generated.ts +1834 -730
  27. package/src/constants/organization.ts +13 -14
  28. package/src/constants/qrCode.ts +30 -0
  29. package/src/constants/sheet.ts +65 -101
  30. package/src/constants/sms.ts +18 -0
  31. package/src/constants/storage.ts +33 -9
  32. package/src/constants/usage.ts +3 -0
  33. package/src/constants/workflowSteps.ts +60 -0
  34. package/src/schemas/editLogEntry.ts +106 -283
  35. package/src/schemas/inboundContact.ts +5 -5
  36. package/src/types/agentMemory.d.ts +38 -14
  37. package/src/types/agentNote.d.ts +443 -0
  38. package/src/types/billing.d.ts +537 -0
  39. package/src/types/campaign.d.ts +1043 -193
  40. package/src/types/contact.d.ts +15 -0
  41. package/src/types/csvExport.d.ts +213 -0
  42. package/src/types/dataAnalysis.d.ts +44 -0
  43. package/src/types/dataTable.d.ts +102 -309
  44. package/src/types/definitionElement.d.ts +35 -0
  45. package/src/types/dt.d.ts +257 -0
  46. package/src/types/email.d.ts +144 -55
  47. package/src/types/emailReplyReport.d.ts +76 -0
  48. package/src/types/fieldDoc.d.ts +579 -150
  49. package/src/types/fieldDocContract.d.ts +90 -0
  50. package/src/types/inboundContact.d.ts +8 -0
  51. package/src/types/log.d.ts +94 -3
  52. package/src/types/logDisplay.types.ts +85 -0
  53. package/src/types/organization.d.ts +8 -3
  54. package/src/types/qrCode.d.ts +96 -0
  55. package/src/types/richText.d.ts +81 -0
  56. package/src/types/sheet.d.ts +180 -463
  57. package/src/types/sms.d.ts +38 -0
  58. package/src/types/storage.d.ts +266 -27
  59. package/src/types/workflow.d.ts +196 -66
  60. package/src/utils/agentMemory.ts +15 -0
  61. package/src/utils/agentNote.ts +850 -0
  62. package/src/utils/aiChat.ts +31 -14
  63. package/src/utils/aiChatWork.ts +64 -0
  64. package/src/utils/billing.ts +37 -0
  65. package/src/utils/campaign.ts +642 -209
  66. package/src/utils/campaignAI.ts +72 -0
  67. package/src/utils/campaignAccess.ts +239 -0
  68. package/src/utils/campaignEmail.ts +601 -0
  69. package/src/utils/campaignEmailCompiler.ts +372 -0
  70. package/src/utils/campaignEmailImages.ts +60 -0
  71. package/src/utils/campaignEmailStyles.ts +544 -0
  72. package/src/utils/campaignLifecycle.ts +104 -0
  73. package/src/utils/campaignPreview.ts +285 -0
  74. package/src/utils/contact.ts +50 -0
  75. package/src/utils/csvExport.ts +19 -0
  76. package/src/utils/dataTable.ts +18 -556
  77. package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
  78. package/src/utils/dataTableRelativeDate.ts +447 -0
  79. package/src/utils/definitionElement.ts +84 -0
  80. package/src/utils/email.ts +208 -1
  81. package/src/utils/emailReplyReport.test.ts +187 -0
  82. package/src/utils/emailReplyReport.ts +143 -0
  83. package/src/utils/fieldDoc.ts +81 -37
  84. package/src/utils/fieldDocAnswers.ts +128 -0
  85. package/src/utils/fieldDocDefaults.ts +36 -0
  86. package/src/utils/fieldDocProgram.ts +36 -0
  87. package/src/utils/fieldDocSummary.ts +30 -0
  88. package/src/utils/log.ts +232 -141
  89. package/src/utils/logDisplay.helpers.ts +177 -0
  90. package/src/utils/logDisplay.ts +87 -0
  91. package/src/utils/logStoreRead.ts +9 -13
  92. package/src/utils/logTaxonomy.helpers.ts +17 -0
  93. package/src/utils/logTaxonomyDisplay.ts +80 -124
  94. package/src/utils/noteDoc.ts +66 -284
  95. package/src/utils/organization.ts +117 -283
  96. package/src/utils/qrCode.helpers.ts +189 -0
  97. package/src/utils/qrCode.test.ts +519 -0
  98. package/src/utils/qrCode.ts +273 -0
  99. package/src/utils/richTextHTML.ts +385 -0
  100. package/src/utils/sheet.ts +123 -4834
  101. package/src/utils/sheetAxisMove.ts +77 -291
  102. package/src/utils/sheetBootstrap.ts +771 -1138
  103. package/src/utils/sheetCellLiteral.ts +101 -0
  104. package/src/utils/sheetCommand.ts +23 -88
  105. package/src/utils/sheetDesign.ts +705 -0
  106. package/src/utils/sheetExport.ts +17 -69
  107. package/src/utils/sheetFeatureReference.ts +183 -0
  108. package/src/utils/sheetFormulaArgs.ts +168 -0
  109. package/src/utils/sheetFormulaCompile.ts +475 -0
  110. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  111. package/src/utils/sheetFormulaCriteria.ts +656 -0
  112. package/src/utils/sheetFormulaDate.ts +444 -0
  113. package/src/utils/sheetFormulaEvaluation.ts +388 -403
  114. package/src/utils/sheetFormulaEvaluator.ts +589 -444
  115. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  116. package/src/utils/sheetFormulaLogical.ts +116 -0
  117. package/src/utils/sheetFormulaLookup.ts +488 -0
  118. package/src/utils/sheetFormulaMath.ts +48 -0
  119. package/src/utils/sheetFormulaParser.ts +729 -0
  120. package/src/utils/sheetFormulaRange.ts +330 -0
  121. package/src/utils/sheetFormulaReference.ts +703 -0
  122. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  123. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  124. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  125. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  126. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  127. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  128. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  129. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  130. package/src/utils/sheetFormulaText.ts +430 -0
  131. package/src/utils/sheetJournal.ts +140 -18
  132. package/src/utils/sheetNumberFormat.ts +68 -267
  133. package/src/utils/sheetPreview.ts +68 -0
  134. package/src/utils/sheetSequence.ts +13 -43
  135. package/src/utils/sheetSnapshot.ts +176 -429
  136. package/src/utils/sheetStructureEdit.ts +537 -907
  137. package/src/utils/sheetStructureReferences.ts +389 -0
  138. package/src/utils/storage.ts +49 -3
  139. package/src/utils/time.ts +12 -0
  140. package/src/utils/workflow.ts +199 -73
  141. package/src/utils/workflowLogFingerprint.ts +302 -0
  142. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  143. package/src/utils/workflowProgress.ts +280 -0
  144. package/src/utils/workflowTriggers.ts +61 -0
  145. package/tests/agentNote.test.ts +395 -0
  146. package/tests/campaignAI.test.ts +119 -0
  147. package/tests/campaignAccess.test.ts +239 -0
  148. package/tests/campaignEmail.test.ts +441 -0
  149. package/tests/campaignLifecycle.test.ts +134 -0
  150. package/tests/campaignPublication.test.ts +309 -0
  151. package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
  152. package/tests/dataTableRelativeDate.test.ts +412 -0
  153. package/tests/email.test.ts +39 -0
  154. package/tests/fieldDocProgram.test.ts +114 -0
  155. package/tests/logDisplay.fixtures.ts +67 -0
  156. package/tests/logDisplay.test.ts +227 -0
  157. package/tests/noteDoc.test.ts +37 -192
  158. package/tests/richTextHTML.test.ts +185 -0
  159. package/tests/sheetAxisMove.test.ts +49 -40
  160. package/tests/sheetBootstrap.test.ts +1967 -0
  161. package/tests/sheetFeatureReference.test.ts +22 -0
  162. package/tests/sheetFormulaCriteria.test.ts +269 -0
  163. package/tests/sheetFormulaEvaluator.test.ts +93 -200
  164. package/tests/sheetFormulaFunctions.test.ts +538 -0
  165. package/tests/sheetFormulaLanguage.test.ts +361 -0
  166. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  167. package/tests/sheetFormulaParity.test.ts +188 -0
  168. package/tests/sheetFormulaRange.test.ts +167 -0
  169. package/tests/sheetFormulaReference.test.ts +78 -0
  170. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  171. package/tests/sheetFormulaTextDate.test.ts +512 -0
  172. package/tests/sheetSequence.test.ts +4 -23
  173. package/tests/sheetSnapshot.test.ts +134 -0
  174. package/tests/sheetStructureEdit.test.ts +492 -37
  175. package/tests/sheetStructureReferences.test.ts +589 -0
  176. package/tests/workflowLifecycleStatus.test.ts +60 -0
  177. package/tests/workflowLogFingerprint.test.ts +203 -0
  178. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  179. package/tests/workflowProgress.test.ts +180 -0
  180. package/tests/workflowTriggers.test.ts +29 -0
  181. package/src/constants/agentDoc.ts +0 -12
  182. package/src/constants/logActivityGroupColors.generated.ts +0 -19
  183. package/src/constants/schedule.ts +0 -220
  184. package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
  185. package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
  186. package/src/constants/sheetRegionSources.generated.ts +0 -578
  187. package/src/schemas/fieldDocsQuery.ts +0 -12
  188. package/src/schemas/organization.ts +0 -68
  189. package/src/types/agentDoc.d.ts +0 -64
  190. package/src/types/noteDoc.d.ts +0 -86
  191. package/src/types/schedule.d.ts +0 -391
  192. package/src/utils/agentDoc.ts +0 -109
  193. package/src/utils/campaignFormEditor.ts +0 -871
  194. package/src/utils/dataTableRealtimeAuthority.ts +0 -209
  195. package/src/utils/dataTableRealtimeSelection.ts +0 -134
  196. package/src/utils/dataTableRowDocument.ts +0 -508
  197. package/src/utils/dataTableSource.ts +0 -230
  198. package/src/utils/schedule.ts +0 -799
  199. package/src/utils/scheduleEvaluation.ts +0 -1994
  200. package/src/utils/scheduleICS.ts +0 -246
  201. package/src/utils/scheduleRuleTemplates.ts +0 -188
  202. package/src/utils/sheetRegion.ts +0 -374
  203. package/src/utils/sheetRegionFilter.ts +0 -1259
  204. package/src/utils/sheetRegionSourceRegistry.ts +0 -594
  205. package/tests/schedule.test.ts +0 -693
  206. package/tests/scheduleEvaluation.test.ts +0 -1970
  207. package/tests/scheduleICS.test.ts +0 -208
  208. package/tests/scheduleRuleTemplates.test.ts +0 -176
  209. package/tests/scheduleSweepInvariants.test.ts +0 -428
  210. package/tests/sheetRegionFilter.test.ts +0 -1135
@@ -0,0 +1,227 @@
1
+ import { beforeEach, expect, it } from 'vitest';
2
+ import i18n, { i18nTranslations } from '@jsb188/app/i18n/index.ts';
3
+ import type { LogDisplayRegistry } from '../src/types/logDisplay.types.ts';
4
+ import type { LogTaxonomyGQL } from '../src/types/log.d.ts';
5
+ import { buildLogEntryDisplay, resolveLogDisplayDefinition } from '../src/utils/logDisplay.ts';
6
+ import { makeDisplayField, makeDisplayLog } from './logDisplay.fixtures.ts';
7
+ import { LOG_DISPLAY_REGISTRY } from '../src/constants/logDisplay/index.ts';
8
+
9
+ /*
10
+ * Load the real English catalog so assertions check displayed labels rather than missing keys.
11
+ */
12
+
13
+ beforeEach(() => {
14
+ i18n.replace(Object.fromEntries(Object.entries(i18nTranslations).map(([name, translations]) => [name, translations.en])));
15
+ });
16
+
17
+ it('keeps every registered profile reference and translation valid', () => {
18
+ const registry: LogDisplayRegistry = LOG_DISPLAY_REGISTRY;
19
+ const definitions = [registry.defaults, ...Object.values(registry.shared)];
20
+ for (const operation of Object.values(registry.operations)) {
21
+ for (const scope of [operation.defaults, ...Object.values(operation.groups || {}), ...Object.values(operation.activities || {})]) {
22
+ if (!scope) continue;
23
+ definitions.push(scope);
24
+ for (const name of scope.profiles || []) expect(registry.shared[name], name).toBeDefined();
25
+ }
26
+ }
27
+ for (const definition of definitions) {
28
+ for (const field of Object.values(definition.fields || {})) {
29
+ if (field?.labelKey) expect(i18n.has(field.labelKey), field.labelKey).toBe(true);
30
+ }
31
+ }
32
+ });
33
+
34
+ it.each(['COOKING_TEMPERATURE', 'COOLING_TEMPERATURE'])(
35
+ 'preserves the agreed %s layout with degree units and full rows',
36
+ (activity) => {
37
+ const logEntry = makeDisplayLog(activity, [
38
+ makeDisplayField('bottomTemperature', -2.5),
39
+ makeDisplayField('temperatureUnit', 'C'),
40
+ makeDisplayField('rackNumber', '003'),
41
+ makeDisplayField('middleTemperature', 0),
42
+ makeDisplayField('topTemperature', 74.5),
43
+ makeDisplayField('batchCode', 'B9'),
44
+ ]);
45
+ const display = buildLogEntryDisplay({ logEntry, operation: 'FOOD_MANUFACTURING', timeZone: 'UTC' });
46
+ expect(display.rows.map((row) => row.key)).toEqual([
47
+ 'date',
48
+ 'logType',
49
+ 'activity',
50
+ 'item',
51
+ 'field:rackNumber',
52
+ 'field:topTemperature',
53
+ 'field:middleTemperature',
54
+ 'field:bottomTemperature',
55
+ 'field:batchCode',
56
+ 'location',
57
+ ]);
58
+ expect(display.rows[0]?.value).toBe(new Date().getUTCFullYear() === 2026 ? '10/09, 12:00 PM' : '10/09/2026, 12:00 PM');
59
+ expect(display.rows.find((row) => row.key === 'item')?.label).toBe(i18n.t('c.product'));
60
+ expect(
61
+ display.rows.filter((row) => row.key.endsWith('Temperature')).map(({ label, value, span }) => ({ label, value, span })),
62
+ ).toEqual([
63
+ { label: i18n.t('log.rack_position.top'), value: '74.5 °C', span: 'full' },
64
+ { label: i18n.t('log.rack_position.middle'), value: '0 °C', span: 'full' },
65
+ { label: i18n.t('log.rack_position.bottom'), value: '-2.5 °C', span: 'full' },
66
+ ]);
67
+ expect(display.rows.at(-1)?.span).toBe('full');
68
+ },
69
+ );
70
+
71
+ it('uses Product, Crop, and Item without leaking shared activity rules between operations', () => {
72
+ const logEntry = makeDisplayLog('COOKING_TEMPERATURE', [
73
+ makeDisplayField('topTemperature', 74),
74
+ makeDisplayField('temperatureUnit', 'F'),
75
+ ]);
76
+ for (const [operation, labelKey] of [
77
+ ['FOOD_MANUFACTURING', 'c.product'],
78
+ ['ARABLE', 'c.crop'],
79
+ ['FUTURE_OPERATION', 'c.item'],
80
+ ]) {
81
+ const display = buildLogEntryDisplay({ logEntry, operation, timeZone: null });
82
+ expect(display.rows.find((row) => row.key === 'item')?.label).toBe(i18n.t(labelKey));
83
+ if (operation !== 'FOOD_MANUFACTURING') {
84
+ expect(display.rows.find((row) => row.key === 'field:temperatureUnit')?.value).toBe('F');
85
+ expect(display.rows.find((row) => row.key === 'field:topTemperature')?.span).toBe('half');
86
+ }
87
+ }
88
+ });
89
+
90
+ it('resolves shared profiles before scoped overrides with explicit reset and no mutation', () => {
91
+ const registry: LogDisplayRegistry = {
92
+ defaults: { fields: { item: { labelKey: 'c.item', span: 'half' } } },
93
+ shared: { sharedReading: { fields: { item: { labelKey: 'c.quantity', hidden: true, span: 'full' } } } },
94
+ operations: {
95
+ ONE: {
96
+ defaults: { fields: { item: { labelKey: 'c.product' } } },
97
+ groups: { GROUP: { order: ['item', '*'], fields: { item: { labelKey: 'c.crop' } } } },
98
+ activities: {
99
+ SHARED_ACTIVITY: {
100
+ profiles: ['sharedReading'],
101
+ order: ['*', 'item'],
102
+ fields: { item: { labelKey: null, hidden: false, span: undefined } },
103
+ },
104
+ },
105
+ },
106
+ TWO: { activities: { SHARED_ACTIVITY: { profiles: ['sharedReading'], fields: { item: { labelKey: 'c.product' } } } } },
107
+ },
108
+ };
109
+ const before = structuredClone(registry);
110
+ const one = resolveLogDisplayDefinition({ operation: 'ONE', groupKey: 'GROUP', activityKey: 'SHARED_ACTIVITY' }, registry);
111
+ expect(one.fields.item).toEqual({ labelKey: null, hidden: false, span: 'full' });
112
+ expect(one.order).toEqual(['*', 'item']);
113
+ expect(resolveLogDisplayDefinition({ operation: 'ONE', groupKey: 'GROUP' }, registry).fields.item?.labelKey).toBe('c.crop');
114
+ expect(resolveLogDisplayDefinition({ operation: 'ONE' }, registry).fields.item?.labelKey).toBe('c.product');
115
+ expect(resolveLogDisplayDefinition({ operation: 'TWO', activityKey: 'SHARED_ACTIVITY' }, registry).fields.item).toMatchObject({
116
+ hidden: true,
117
+ labelKey: 'c.product',
118
+ });
119
+ expect(registry).toEqual(before);
120
+ });
121
+
122
+ it('keeps historical custom fields, including colliding names, with one wildcard insertion', () => {
123
+ const logEntry = makeDisplayLog('FUTURE_ACTIVITY', [
124
+ makeDisplayField('item', 'Custom item'),
125
+ makeDisplayField('location', 'Custom location'),
126
+ makeDisplayField('retiredField', false),
127
+ makeDisplayField('flagColor', 'red'),
128
+ ]);
129
+ const registry: LogDisplayRegistry = { defaults: { order: ['item', '*', '*', 'item', 'location'] }, shared: {}, operations: {} };
130
+ const display = buildLogEntryDisplay({ logEntry, operation: 'FUTURE_OPERATION', timeZone: null }, registry);
131
+ expect(display.rows.filter((row) => row.key === 'item')).toHaveLength(1);
132
+ expect(display.rows.find((row) => row.key === 'field:item')?.value).toBe('Custom item');
133
+ expect(display.rows.find((row) => row.key === 'field:location')?.value).toBe('Custom location');
134
+ expect(display.rows.find((row) => row.key === 'field:retiredField')?.value).toBe(i18n.t('c.no'));
135
+ expect(display.rows.at(-1)?.key).toBe('location');
136
+ const standard = buildLogEntryDisplay({ logEntry, timeZone: null });
137
+ expect(standard.rows.some((row) => row.key === 'field:flagColor')).toBe(false);
138
+ });
139
+
140
+ it('retains unlisted fields without a wildcard and resets inherited labels to the generic label', () => {
141
+ const logEntry = makeDisplayLog('FUTURE_ACTIVITY', [makeDisplayField('newField', 'Saved')]);
142
+ const registry: LogDisplayRegistry = {
143
+ defaults: { order: ['item'], fields: { item: { labelKey: 'c.product' } } },
144
+ shared: {},
145
+ operations: { FUTURE: { defaults: { fields: { item: { labelKey: null } } } } },
146
+ };
147
+ const rows = buildLogEntryDisplay({ logEntry, operation: 'FUTURE', timeZone: null }, registry).rows;
148
+ expect(rows[0].label).toBe(i18n.t('c.item'));
149
+ expect(rows.find((row) => row.key === 'field:newField')?.value).toBe('Saved');
150
+ });
151
+
152
+ it('keeps placeholders for missing readings and supports Fahrenheit without guessing a missing unit', () => {
153
+ const logEntry = makeDisplayLog('COOKING_TEMPERATURE', [
154
+ makeDisplayField('topTemperature', 165),
155
+ makeDisplayField('temperatureUnit', 'F'),
156
+ ]);
157
+ const input = { logEntry, operation: 'FOOD_MANUFACTURING', timeZone: null };
158
+ expect(buildLogEntryDisplay(input).rows.find((row) => row.key === 'field:topTemperature')?.value).toBe('165 °F');
159
+ expect(buildLogEntryDisplay(input).rows.find((row) => row.key === 'field:middleTemperature')?.value).toBe('');
160
+ logEntry.details.fields = [makeDisplayField('topTemperature', 0)];
161
+ expect(buildLogEntryDisplay(input).rows.find((row) => row.key === 'field:topTemperature')?.value).toBe('0');
162
+ });
163
+
164
+ it.each([
165
+ ['ARABLE', 'SEED_PURCHASE_INFO', 'purchaseInvoice'],
166
+ ['ARABLE', 'OTHER_SUPPLY_PURCHASE_ACTIVITY', 'purchaseInvoice'],
167
+ ['ARABLE', 'SALE_PRODUCE_ORDER', 'saleInvoice'],
168
+ ['ARABLE', 'OTHER_SALE_ORDER', 'saleInvoice'],
169
+ ['FARMERS_MARKET', 'MARKET_CREDIT_RECEIPT', 'receipt'],
170
+ ['FOOD_MANUFACTURING', 'SALE_PRODUCE_ORDER', 'metadata'],
171
+ ])('selects %s/%s as %s', (operation, activityKey, layout) => {
172
+ expect(resolveLogDisplayDefinition({ operation, activityKey }).layout).toBe(layout);
173
+ });
174
+
175
+ it('uses matching taxonomy labels and ordering without hiding fields outside the current taxonomy', () => {
176
+ const taxonomy: LogTaxonomyGQL = {
177
+ operation: 'FUTURE',
178
+ groups: [{ key: 'CUSTOM_GROUP', label: 'Custom group label', ordinal: 0, requiredFields: null, orRequiredFields: null }],
179
+ activities: [
180
+ {
181
+ key: 'CUSTOM_ACTIVITY',
182
+ groupKey: 'CUSTOM_GROUP',
183
+ agentText: 'Custom activity label',
184
+ ordinal: 0,
185
+ requiredFields: null,
186
+ orRequiredFields: null,
187
+ },
188
+ ],
189
+ fieldDefs: [
190
+ {
191
+ key: 'orderedFirst',
192
+ fieldType: 'TEXT',
193
+ ordinal: 0,
194
+ required: false,
195
+ agentHint: null,
196
+ options: null,
197
+ allowedUnits: null,
198
+ groupKey: null,
199
+ activityKey: null,
200
+ },
201
+ ],
202
+ };
203
+ const logEntry = makeDisplayLog('CUSTOM_ACTIVITY', [
204
+ makeDisplayField('historicalField', 'Old'),
205
+ makeDisplayField('orderedFirst', 'First'),
206
+ ]);
207
+ logEntry.details.type = null;
208
+ const rows = buildLogEntryDisplay({ logEntry, operation: 'FUTURE', taxonomy, timeZone: null }).rows;
209
+ expect(rows.find((row) => row.key === 'logType')?.value).toBe('Custom group label');
210
+ expect(rows.find((row) => row.key === 'activity')?.value).toBe('Custom activity label');
211
+ expect(rows.filter((row) => row.key.startsWith('field:')).map((row) => row.key)).toEqual([
212
+ 'field:orderedFirst',
213
+ 'field:historicalField',
214
+ ]);
215
+ const other = buildLogEntryDisplay({ logEntry, operation: 'OTHER', taxonomy, timeZone: null });
216
+ expect(other.rows.find((row) => row.key === 'activity')?.value).toBe('Custom activity');
217
+ logEntry.details.type = 'HISTORICAL_GROUP';
218
+ expect(
219
+ buildLogEntryDisplay({ logEntry, operation: 'FUTURE', taxonomy, timeZone: null }).rows.find((row) => row.key === 'logType')
220
+ ?.badgeGroupKey,
221
+ ).toBe('HISTORICAL_GROUP');
222
+ });
223
+
224
+ it('reports misspelled shared profile references instead of silently using the wrong layout', () => {
225
+ const registry: LogDisplayRegistry = { defaults: {}, shared: {}, operations: { ONE: { defaults: { profiles: ['missing'] } } } };
226
+ expect(() => resolveLogDisplayDefinition({ operation: 'ONE' }, registry)).toThrow('Unknown log display profile: missing');
227
+ });
@@ -1,20 +1,6 @@
1
- import {
2
- NOTE_DOC_VERSION,
3
- NOTE_MAX_BLOCKS,
4
- NOTE_MAX_TEXT_CHARS,
5
- } from '@jsb188/mday/constants/noteDoc.ts';
6
- import type {
7
- NoteBlockNode,
8
- NoteDoc,
9
- NoteInlineNode,
10
- } from '@jsb188/mday/types/noteDoc.d.ts';
11
- import {
12
- collectNoteImageStorageIds,
13
- createEmptyNoteDoc,
14
- filterImageNodesByStorageRels,
15
- noteDocToPlainText,
16
- sanitizeNoteDoc,
17
- } from '@jsb188/mday/utils/noteDoc.ts';
1
+ import { NOTE_DOC_VERSION, NOTE_MAX_BLOCKS, NOTE_MAX_TEXT_CHARS } from '@jsb188/mday/constants/noteDoc.ts';
2
+ import type { RichTextContent, RichTextInlineContent } from '@jsb188/mday/types/richText.d.ts';
3
+ import { createEmptyNoteDoc, noteDocToPlainText, sanitizeNoteDoc } from '@jsb188/mday/utils/noteDoc.ts';
18
4
  import { describe, expect, it } from 'vitest';
19
5
 
20
6
  /*
@@ -41,15 +27,12 @@ function buildParagraph(text: string): any {
41
27
  /*
42
28
  * Build one image block with valid attrs.
43
29
  */
44
- function buildImage(
45
- storageId: string | number,
46
- extraAttrs: Record<string, any> = {},
47
- ): any {
30
+ function buildImage(storageId: string | number, extraAttrs: Record<string, any> = {}): any {
48
31
  return {
49
32
  type: 'image',
50
33
  attrs: {
51
34
  storageId,
52
- fileUri: 'uploads/img-' + storageId + '.png',
35
+ fileUri: `uploads/img-${storageId}.png`,
53
36
  ...extraAttrs,
54
37
  },
55
38
  };
@@ -67,15 +50,7 @@ describe('createEmptyNoteDoc', () => {
67
50
 
68
51
  describe('sanitizeNoteDoc', () => {
69
52
  it('coerces unknown roots to an empty doc', () => {
70
- for (const input of [
71
- null,
72
- undefined,
73
- 'hello',
74
- 42,
75
- [],
76
- { type: 'paragraph' },
77
- { content: [] },
78
- ]) {
53
+ for (const input of [null, undefined, 'hello', 42, [], { type: 'paragraph' }, { content: [] }]) {
79
54
  expect(sanitizeNoteDoc(input)).toEqual(createEmptyNoteDoc());
80
55
  }
81
56
  });
@@ -124,12 +99,10 @@ describe('sanitizeNoteDoc', () => {
124
99
  },
125
100
  ]),
126
101
  );
127
- expect(output.content).toEqual([
128
- { type: 'paragraph', content: [{ type: 'text', text: 'ok' }] },
129
- ]);
102
+ expect(output.content).toEqual([{ type: 'paragraph', content: [{ type: 'text', text: 'ok' }] }]);
130
103
  });
131
104
 
132
- it('strips client-only and unknown fields from nodes', () => {
105
+ it('strips client-only fields and omits unfinished image uploads', () => {
133
106
  const output = sanitizeNoteDoc(
134
107
  buildDoc([
135
108
  {
@@ -146,10 +119,7 @@ describe('sanitizeNoteDoc', () => {
146
119
  type: 'paragraph',
147
120
  content: [{ type: 'text', text: 'a' }],
148
121
  });
149
- expect(output.content[1]).toEqual({
150
- type: 'image',
151
- attrs: { storageId: '9', fileUri: 'uploads/img-9.png' },
152
- });
122
+ expect(output.content).toHaveLength(1);
153
123
  });
154
124
 
155
125
  it('clamps heading levels into 1-3', () => {
@@ -161,9 +131,7 @@ describe('sanitizeNoteDoc', () => {
161
131
  { type: 'heading', content: [] },
162
132
  ]),
163
133
  );
164
- expect(
165
- output.content.map((block: NoteBlockNode) => block.attrs?.level),
166
- ).toEqual([1, 3, 2, 1]);
134
+ expect(output.content.map((block: RichTextContent) => block.attrs?.level)).toEqual([1, 3, 2, 1]);
167
135
  });
168
136
 
169
137
  it('whitelists mark types and drops duplicates', () => {
@@ -175,21 +143,13 @@ describe('sanitizeNoteDoc', () => {
175
143
  {
176
144
  type: 'text',
177
145
  text: 'x',
178
- marks: [
179
- { type: 'bold' },
180
- { type: 'bold' },
181
- { type: 'blink' },
182
- { type: 'italic', attrs: { junk: 1 } },
183
- ],
146
+ marks: [{ type: 'bold' }, { type: 'bold' }, { type: 'blink' }, { type: 'italic', attrs: { junk: 1 } }],
184
147
  },
185
148
  ],
186
149
  },
187
150
  ]),
188
151
  );
189
- expect((output.content[0].content?.[0] as NoteInlineNode).marks).toEqual([
190
- { type: 'bold' },
191
- { type: 'italic' },
192
- ]);
152
+ expect((output.content[0].content![0] as RichTextInlineContent).marks).toEqual([{ type: 'bold' }, { type: 'italic' }]);
193
153
  });
194
154
 
195
155
  it('validates color/highlight tokens against the palette', () => {
@@ -210,9 +170,7 @@ describe('sanitizeNoteDoc', () => {
210
170
  },
211
171
  ]),
212
172
  );
213
- expect((output.content[0].content?.[0] as NoteInlineNode).marks).toEqual([
214
- { type: 'color', attrs: { token: 'red' } },
215
- ]);
173
+ expect((output.content[0].content![0] as RichTextInlineContent).marks).toEqual([{ type: 'color', attrs: { token: 'red' } }]);
216
174
  });
217
175
 
218
176
  it('keeps http(s)/mailto links and kills javascript: URLs', () => {
@@ -234,9 +192,7 @@ describe('sanitizeNoteDoc', () => {
234
192
  {
235
193
  type: 'text',
236
194
  text: 'c',
237
- marks: [
238
- { type: 'link', attrs: { href: ' HTTP://example.com ' } },
239
- ],
195
+ marks: [{ type: 'link', attrs: { href: ' HTTP://example.com ' } }],
240
196
  },
241
197
  {
242
198
  type: 'text',
@@ -246,9 +202,7 @@ describe('sanitizeNoteDoc', () => {
246
202
  {
247
203
  type: 'text',
248
204
  text: 'e',
249
- marks: [
250
- { type: 'link', attrs: { href: ' JaVaScRiPt:alert(1)' } },
251
- ],
205
+ marks: [{ type: 'link', attrs: { href: ' JaVaScRiPt:alert(1)' } }],
252
206
  },
253
207
  {
254
208
  type: 'text',
@@ -259,16 +213,10 @@ describe('sanitizeNoteDoc', () => {
259
213
  },
260
214
  ]),
261
215
  );
262
- const runs = output.content[0].content as NoteInlineNode[];
263
- expect(runs[0].marks).toEqual([
264
- { type: 'link', attrs: { href: 'https://example.com' } },
265
- ]);
266
- expect(runs[1].marks).toEqual([
267
- { type: 'link', attrs: { href: 'mailto:x@y.com' } },
268
- ]);
269
- expect(runs[2].marks).toEqual([
270
- { type: 'link', attrs: { href: 'HTTP://example.com' } },
271
- ]);
216
+ const runs = output.content[0].content as RichTextInlineContent[];
217
+ expect(runs[0].marks).toEqual([{ type: 'link', attrs: { href: 'https://example.com' } }]);
218
+ expect(runs[1].marks).toEqual([{ type: 'link', attrs: { href: 'mailto:x@y.com' } }]);
219
+ expect(runs[2].marks).toEqual([{ type: 'link', attrs: { href: 'HTTP://example.com' } }]);
272
220
  // The three unsafe runs lose their link mark and merge into one run
273
221
  expect(runs[3]).toEqual({ type: 'text', text: 'def' });
274
222
  expect(runs).toHaveLength(4);
@@ -310,18 +258,19 @@ describe('sanitizeNoteDoc', () => {
310
258
  ]);
311
259
  });
312
260
 
313
- it('drops image blocks missing storageId or fileUri and coerces numeric ids', () => {
261
+ it('drops image blocks with missing or non-string storage ids', () => {
314
262
  const output = sanitizeNoteDoc(
315
263
  buildDoc([
316
264
  { type: 'image', attrs: { fileUri: 'uploads/no-id.png' } },
317
265
  { type: 'image', attrs: { storageId: '3' } },
318
266
  buildImage(7, { width: '300', alt: '' }),
267
+ buildImage('8', { width: '300', alt: '' }),
319
268
  ]),
320
269
  );
321
270
  expect(output.content).toEqual([
322
271
  {
323
272
  type: 'image',
324
- attrs: { storageId: '7', fileUri: 'uploads/img-7.png' },
273
+ attrs: { storageId: '8', fileUri: 'uploads/img-8.png' },
325
274
  },
326
275
  ]);
327
276
  });
@@ -350,15 +299,11 @@ describe('sanitizeNoteDoc', () => {
350
299
  content: [
351
300
  {
352
301
  type: 'listItem',
353
- content: [
354
- { type: 'paragraph', content: [{ type: 'text', text: 'loose' }] },
355
- ],
302
+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'loose' }] }],
356
303
  },
357
304
  {
358
305
  type: 'listItem',
359
- content: [
360
- { type: 'paragraph', content: [{ type: 'text', text: 'head' }] },
361
- ],
306
+ content: [{ type: 'paragraph', content: [{ type: 'text', text: 'head' }] }],
362
307
  },
363
308
  ],
364
309
  },
@@ -401,14 +346,9 @@ describe('sanitizeNoteDoc', () => {
401
346
 
402
347
  it('drops void leaves with no legal spot and lists left without items', () => {
403
348
  const output = sanitizeNoteDoc(
404
- buildDoc([
405
- { type: 'bulletList', content: [{ type: 'divider' }, buildImage('4')] },
406
- buildParagraph('kept'),
407
- ]),
349
+ buildDoc([{ type: 'bulletList', content: [{ type: 'divider' }, buildImage('4')] }, buildParagraph('kept')]),
408
350
  );
409
- expect(output.content).toEqual([
410
- { type: 'paragraph', content: [{ type: 'text', text: 'kept' }] },
411
- ]);
351
+ expect(output.content).toEqual([{ type: 'paragraph', content: [{ type: 'text', text: 'kept' }] }]);
412
352
  });
413
353
 
414
354
  it('fills emptied listItems and blockquotes with one empty paragraph', () => {
@@ -424,9 +364,7 @@ describe('sanitizeNoteDoc', () => {
424
364
  expect(output.content).toEqual([
425
365
  {
426
366
  type: 'bulletList',
427
- content: [
428
- { type: 'listItem', content: [{ type: 'paragraph', content: [] }] },
429
- ],
367
+ content: [{ type: 'listItem', content: [{ type: 'paragraph', content: [] }] }],
430
368
  },
431
369
  { type: 'blockquote', content: [{ type: 'paragraph', content: [] }] },
432
370
  ]);
@@ -459,9 +397,7 @@ describe('sanitizeNoteDoc', () => {
459
397
  content: [
460
398
  {
461
399
  type: 'listItem',
462
- content: [
463
- { type: 'bulletList', content: [overDeepItem] },
464
- ],
400
+ content: [{ type: 'bulletList', content: [overDeepItem] }],
465
401
  },
466
402
  ],
467
403
  },
@@ -472,8 +408,7 @@ describe('sanitizeNoteDoc', () => {
472
408
  ]),
473
409
  );
474
410
 
475
- const level3List = (output.content[0] as any).content[0].content[0]
476
- .content[0].content[0] as NoteBlockNode;
411
+ const level3List = (output.content[0] as any).content[0].content[0].content[0].content[0] as RichTextContent;
477
412
  expect(level3List.type).toBe('bulletList');
478
413
  expect(level3List.content).toEqual([
479
414
  {
@@ -481,11 +416,7 @@ describe('sanitizeNoteDoc', () => {
481
416
  content: [
482
417
  {
483
418
  type: 'paragraph',
484
- content: [
485
- { type: 'text', text: 'a' },
486
- { type: 'hardBreak' },
487
- { type: 'text', text: 'b' },
488
- ],
419
+ content: [{ type: 'text', text: 'a' }, { type: 'hardBreak' }, { type: 'text', text: 'b' }],
489
420
  },
490
421
  ],
491
422
  },
@@ -493,34 +424,18 @@ describe('sanitizeNoteDoc', () => {
493
424
  });
494
425
 
495
426
  it('truncates the tail past NOTE_MAX_BLOCKS', () => {
496
- const output = sanitizeNoteDoc(
497
- buildDoc(
498
- Array.from({ length: NOTE_MAX_BLOCKS + 50 }, (_, i) =>
499
- buildParagraph('p' + i),
500
- ),
501
- ),
502
- );
427
+ const output = sanitizeNoteDoc(buildDoc(Array.from({ length: NOTE_MAX_BLOCKS + 50 }, (_, i) => buildParagraph(`p${i}`))));
503
428
  expect(output.content).toHaveLength(NOTE_MAX_BLOCKS);
504
- expect(
505
- (output.content[NOTE_MAX_BLOCKS - 1].content?.[0] as NoteInlineNode).text,
506
- ).toBe('p' + (NOTE_MAX_BLOCKS - 1));
429
+ expect((output.content[NOTE_MAX_BLOCKS - 1].content![0] as RichTextInlineContent).text).toBe(`p${NOTE_MAX_BLOCKS - 1}`);
507
430
  });
508
431
 
509
432
  it('truncates text past NOTE_MAX_TEXT_CHARS', () => {
510
433
  const output = sanitizeNoteDoc(
511
- buildDoc([
512
- buildParagraph('x'.repeat(NOTE_MAX_TEXT_CHARS - 5)),
513
- buildParagraph('y'.repeat(50)),
514
- buildParagraph('z'),
515
- ]),
434
+ buildDoc([buildParagraph('x'.repeat(NOTE_MAX_TEXT_CHARS - 5)), buildParagraph('y'.repeat(50)), buildParagraph('z')]),
516
435
  );
517
- expect(
518
- (output.content[0].content?.[0] as NoteInlineNode).text,
519
- ).toHaveLength(NOTE_MAX_TEXT_CHARS - 5);
436
+ expect((output.content[0].content![0] as RichTextInlineContent).text).toHaveLength(NOTE_MAX_TEXT_CHARS - 5);
520
437
  // Second paragraph keeps only the 5 chars left in the budget
521
- expect((output.content[1].content?.[0] as NoteInlineNode).text).toBe(
522
- 'yyyyy',
523
- );
438
+ expect((output.content[1].content![0] as RichTextInlineContent).text).toBe('yyyyy');
524
439
  // Later blocks survive with their text dropped
525
440
  expect(output.content[2]).toEqual({ type: 'paragraph', content: [] });
526
441
  });
@@ -565,70 +480,6 @@ describe('sanitizeNoteDoc', () => {
565
480
  });
566
481
  });
567
482
 
568
- describe('filterImageNodesByStorageRels', () => {
569
- it('keeps only image blocks whose storageId has a rel row', () => {
570
- const doc = sanitizeNoteDoc(
571
- buildDoc([buildParagraph('text'), buildImage('1'), buildImage('2')]),
572
- );
573
- const output = filterImageNodesByStorageRels(doc, new Set(['2']));
574
- expect(output.content).toEqual([
575
- { type: 'paragraph', content: [{ type: 'text', text: 'text' }] },
576
- {
577
- type: 'image',
578
- attrs: { storageId: '2', fileUri: 'uploads/img-2.png' },
579
- },
580
- ]);
581
- // Pure: the input doc is untouched
582
- expect(doc.content).toHaveLength(3);
583
- });
584
-
585
- it('never leaves the doc empty', () => {
586
- const doc = sanitizeNoteDoc(buildDoc([buildImage('1')]));
587
- const output = filterImageNodesByStorageRels(doc, new Set());
588
- expect(output.content).toEqual([{ type: 'paragraph', content: [] }]);
589
- });
590
-
591
- it('string-compares storageIds', () => {
592
- const doc: NoteDoc = {
593
- type: 'doc',
594
- version: NOTE_DOC_VERSION,
595
- // Bypass sanitize to simulate a legacy numeric storageId
596
- content: [
597
- {
598
- type: 'image',
599
- attrs: { storageId: 7 as any, fileUri: 'uploads/x.png' },
600
- },
601
- ],
602
- };
603
- expect(
604
- filterImageNodesByStorageRels(doc, new Set(['7'])).content[0].type,
605
- ).toBe('image');
606
- expect(
607
- filterImageNodesByStorageRels(doc, new Set(['8'])).content[0].type,
608
- ).toBe('paragraph');
609
- });
610
- });
611
-
612
- describe('collectNoteImageStorageIds', () => {
613
- it('collects image storage ids in document order, deduped and stringified', () => {
614
- const doc: NoteDoc = {
615
- type: 'doc',
616
- version: NOTE_DOC_VERSION,
617
- content: [
618
- buildImage('5'),
619
- buildParagraph('x'),
620
- buildImage(3),
621
- buildImage('5'),
622
- ],
623
- };
624
- expect(collectNoteImageStorageIds(doc)).toEqual(['5', '3']);
625
- });
626
-
627
- it('returns an empty list for docs without images', () => {
628
- expect(collectNoteImageStorageIds(createEmptyNoteDoc())).toEqual([]);
629
- });
630
- });
631
-
632
483
  describe('noteDocToPlainText', () => {
633
484
  it('renders one line per text-bearing block, with hardBreaks as newlines', () => {
634
485
  const doc = sanitizeNoteDoc(
@@ -640,11 +491,7 @@ describe('noteDocToPlainText', () => {
640
491
  },
641
492
  {
642
493
  type: 'paragraph',
643
- content: [
644
- { type: 'text', text: 'line one' },
645
- { type: 'hardBreak' },
646
- { type: 'text', text: 'line two' },
647
- ],
494
+ content: [{ type: 'text', text: 'line one' }, { type: 'hardBreak' }, { type: 'text', text: 'line two' }],
648
495
  },
649
496
  { type: 'divider' },
650
497
  buildImage('1'),
@@ -658,9 +505,7 @@ describe('noteDocToPlainText', () => {
658
505
  { type: 'paragraph', content: [] },
659
506
  ]),
660
507
  );
661
- expect(noteDocToPlainText(doc)).toBe(
662
- 'Title\nline one\nline two\nitem a\nitem b',
663
- );
508
+ expect(noteDocToPlainText(doc)).toBe('Title\nline one\nline two\nitem a\nitem b');
664
509
  });
665
510
 
666
511
  it('returns an empty string for an empty doc', () => {