@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,87 @@
1
+ import { LOG_DISPLAY_REGISTRY } from '../constants/logDisplay/index.ts';
2
+ import type {
3
+ LogDisplayContext,
4
+ LogDisplayFieldKey,
5
+ LogDisplayInput,
6
+ LogDisplayRegistry,
7
+ LogEntryDisplay,
8
+ ResolvedLogDisplayDefinition,
9
+ } from '../types/logDisplay.types.ts';
10
+ import {
11
+ formatLogDisplayValue,
12
+ getLogDisplayContext,
13
+ getLogDisplayFieldLabel,
14
+ getLogDisplayValues,
15
+ mergeLogDisplayDefinition,
16
+ orderLogDisplayFields,
17
+ } from './logDisplay.helpers.ts';
18
+
19
+ export { getLogDisplayFieldLabel } from './logDisplay.helpers.ts';
20
+
21
+ /*
22
+ * Resolve generic -> explicitly shared -> operation -> group -> activity.
23
+ * Shared profiles are deliberately non-recursive and never match by activity
24
+ * name alone. Inputs are not mutated, so resolutions cannot leak across orgs.
25
+ */
26
+
27
+ export function resolveLogDisplayDefinition(
28
+ context: LogDisplayContext,
29
+ registry: LogDisplayRegistry = LOG_DISPLAY_REGISTRY,
30
+ ): ResolvedLogDisplayDefinition {
31
+ const scope = getLogDisplayContext(context);
32
+ const operation = scope.operation ? registry.operations[scope.operation] : undefined;
33
+ const layers = [
34
+ operation?.defaults,
35
+ scope.groupKey ? operation?.groups?.[scope.groupKey] : undefined,
36
+ scope.activityKey ? operation?.activities?.[scope.activityKey] : undefined,
37
+ ];
38
+ const resolved: ResolvedLogDisplayDefinition = { layout: 'metadata', order: ['*'], fields: {} };
39
+ mergeLogDisplayDefinition(resolved, registry.defaults);
40
+ const appliedProfiles = new Set<string>();
41
+ for (const layer of layers) {
42
+ for (const name of layer?.profiles || []) {
43
+ if (appliedProfiles.has(name)) continue;
44
+ const profile = registry.shared[name];
45
+ if (!profile) throw new Error(`Unknown log display profile: ${name}`);
46
+ mergeLogDisplayDefinition(resolved, profile);
47
+ appliedProfiles.add(name);
48
+ }
49
+ }
50
+ for (const layer of layers) mergeLogDisplayDefinition(resolved, layer);
51
+ return resolved;
52
+ }
53
+
54
+ /*
55
+ * Prepare renderer-independent rows from saved data and a resolved profile.
56
+ * Saved custom fields survive taxonomy changes; absent fields appear only when
57
+ * explicitly configured to show a placeholder. Visibility never validates data.
58
+ */
59
+
60
+ export function buildLogEntryDisplay(input: LogDisplayInput, registry: LogDisplayRegistry = LOG_DISPLAY_REGISTRY): LogEntryDisplay {
61
+ const context = getLogDisplayContext({
62
+ operation: input.operation,
63
+ taxonomy: input.taxonomy,
64
+ groupKey: input.logEntry.details.type,
65
+ activityKey: input.logEntry.details.activity,
66
+ });
67
+ const definition = resolveLogDisplayDefinition(context, registry);
68
+ const values = getLogDisplayValues(input, context);
69
+ const keys = [...new Set([...values.keys(), ...(Object.keys(definition.fields) as LogDisplayFieldKey[])])];
70
+ const rows = orderLogDisplayFields(keys, definition.order).flatMap((key) => {
71
+ const field = definition.fields[key] || {};
72
+ if (field.hidden) return [];
73
+ const source = values.get(key);
74
+ const empty = source?.raw === null || source?.raw === undefined || source.raw === '';
75
+ if (empty && field.empty !== 'show' && !(source?.field && field.empty !== 'hide')) return [];
76
+ return [
77
+ {
78
+ key,
79
+ label: getLogDisplayFieldLabel(key, field),
80
+ value: formatLogDisplayValue(source, field, values),
81
+ span: field.span || ('half' as const),
82
+ ...(key === 'logType' && context.groupKey ? { badgeGroupKey: context.groupKey } : {}),
83
+ },
84
+ ];
85
+ });
86
+ return { layout: definition.layout, rows };
87
+ }
@@ -1,3 +1,4 @@
1
+ import type { LogTranslationBundle } from '../types/log.d.ts';
1
2
  import type { OrganizationOperationEnum } from '../types/organization.d.ts';
2
3
 
3
4
  /**
@@ -7,9 +8,11 @@ import type { OrganizationOperationEnum } from '../types/organization.d.ts';
7
8
  * dollars (the store keeps BIGINT cents).
8
9
  *
9
10
  * Inverse of the server-side materializer (server logOps-store.ts): scalar
10
- * item facts come back from the ordinal-0 ITEM row, values[] from remaining
11
- * ITEM or historical MARKET_CREDIT rows, field-def-keyed scalars from
12
- * log_values, and otherParty from an EXTERNAL counterparty.
11
+ * item facts come back from the ordinal-0 item row, values[] from the rows
12
+ * with ordinal 1 and up, field-def-keyed scalars from log_values, and
13
+ * otherParty from an EXTERNAL counterparty. Item rows are read by ordinal
14
+ * alone: every row is an ITEM (a legacy MARKET_CREDIT row still reads as an
15
+ * ordinary line).
13
16
  */
14
17
 
15
18
  export interface LogStoreValueInput {
@@ -24,7 +27,6 @@ export interface LogStoreValueInput {
24
27
  }
25
28
 
26
29
  export interface LogStoreItemInput {
27
- kind: 'ITEM' | 'MARKET_CREDIT';
28
30
  ordinal: number;
29
31
  label: string;
30
32
  quantity?: number | null;
@@ -40,7 +42,7 @@ export interface LogStoreDetailsInput {
40
42
  activityKey: string;
41
43
  logTypeKey?: string | null;
42
44
  notes?: string | null;
43
- translation?: string | null;
45
+ translation?: LogTranslationBundle | null;
44
46
  voided?: boolean | null;
45
47
  referenceNumber?: string | null;
46
48
  fieldLocation?: string | null;
@@ -98,9 +100,7 @@ function buildMetadataFromStore(
98
100
  ): Record<string, any> | null {
99
101
  const metadata: Record<string, any> = {};
100
102
 
101
- const scalarItem = input.items.find(
102
- (item) => item.kind === 'ITEM' && item.ordinal === 0,
103
- );
103
+ const scalarItem = input.items.find((item) => item.ordinal === 0);
104
104
  if (scalarItem) {
105
105
  if (scalarItem.label) {
106
106
  metadata.item = scalarItem.label;
@@ -119,11 +119,7 @@ function buildMetadataFromStore(
119
119
  }
120
120
 
121
121
  const valueLines = input.items
122
- .filter(
123
- (item) =>
124
- (item.kind === 'ITEM' && item.ordinal >= 1) ||
125
- item.kind === 'MARKET_CREDIT',
126
- )
122
+ .filter((item) => item.ordinal >= 1)
127
123
  .sort((a, b) => a.ordinal - b.ordinal)
128
124
  .map((item) => {
129
125
  const line: Record<string, any> = { label: item.label };
@@ -0,0 +1,17 @@
1
+ export interface LogFieldScope {
2
+ groupKey?: string | null;
3
+ activityKey?: string | null;
4
+ config?: { includedActivityKeys?: string[]; excludedActivityKeys?: string[] } | null;
5
+ }
6
+
7
+ /*
8
+ * Match a field's activity/group scope and explicit activity exclusions.
9
+ */
10
+ export function isLogFieldApplicableToActivity(scope: LogFieldScope, activityKey?: string | null, groupKey?: string | null): boolean {
11
+ return (
12
+ (!scope.activityKey || scope.activityKey === activityKey) &&
13
+ (!scope.groupKey || scope.groupKey === groupKey) &&
14
+ (!scope.config?.includedActivityKeys || (!!activityKey && scope.config.includedActivityKeys.includes(activityKey))) &&
15
+ !(activityKey && scope.config?.excludedActivityKeys?.includes(activityKey))
16
+ );
17
+ }
@@ -1,14 +1,12 @@
1
+ import { isLogFieldApplicableToActivity } from './logTaxonomy.helpers.ts';
1
2
  import i18n from '@jsb188/app/i18n/index.ts';
2
- import {
3
- getCalDate,
4
- getFullDateTime,
5
- getReadableCalDate,
6
- } from '@jsb188/app/utils/datetime.ts';
3
+ import { formatDisplayDate, getCalDate } from '@jsb188/app/utils/datetime.ts';
7
4
  import { formatCurrency } from '@jsb188/app/utils/number.ts';
8
5
  import { ucFirst } from '@jsb188/app/utils/string.ts';
9
6
  import { parseDateInTimezone } from '@jsb188/app/utils/timeZone.ts';
10
7
  import type {
11
8
  LogEntryDetailsFieldGQL,
9
+ LogEntryDetailsGQL,
12
10
  LogTaxonomyActivityGQL,
13
11
  LogTaxonomyFieldDefGQL,
14
12
  LogTaxonomyGQL,
@@ -45,19 +43,14 @@ export function humanizeRegistryKey(key?: string | null): string {
45
43
  * agentText, then the humanized key
46
44
  */
47
45
 
48
- export function getTaxonomyActivityLabel(
49
- taxonomy: LogTaxonomyGQL | null | undefined,
50
- activityKey?: string | null,
51
- ): string {
46
+ export function getTaxonomyActivityLabel(taxonomy: LogTaxonomyGQL | null | undefined, activityKey?: string | null): string {
52
47
  if (!activityKey) {
53
48
  return '';
54
49
  }
55
50
  if (i18n.has(`log.activity.${activityKey}`)) {
56
51
  return i18n.t(`log.activity.${activityKey}`);
57
52
  }
58
- const agentText = taxonomy?.activities?.find(
59
- (activity) => activity.key === activityKey,
60
- )?.agentText;
53
+ const agentText = taxonomy?.activities?.find((activity) => activity.key === activityKey)?.agentText;
61
54
  return agentText ? ucFirst(agentText) : humanizeRegistryKey(activityKey);
62
55
  }
63
56
 
@@ -73,12 +66,7 @@ export function getTaxonomyGroupKey(
73
66
  if (!activityKey) {
74
67
  return fallbackGroupKey ?? null;
75
68
  }
76
- return (
77
- taxonomy?.activities?.find((activity) => activity.key === activityKey)
78
- ?.groupKey ??
79
- fallbackGroupKey ??
80
- null
81
- );
69
+ return taxonomy?.activities?.find((activity) => activity.key === activityKey)?.groupKey ?? fallbackGroupKey ?? null;
82
70
  }
83
71
 
84
72
  /*
@@ -92,16 +80,10 @@ export function getTaxonomyFieldRequirement(
92
80
  fieldKey: string,
93
81
  fallbackGroupKey?: string | null,
94
82
  ): LogTaxonomyFieldRequirement {
95
- const activity = taxonomy?.activities.find(
96
- (candidate) => candidate.key === activityKey,
97
- );
98
- const group = taxonomy?.groups.find(
99
- (candidate) => candidate.key === (activity?.groupKey ?? fallbackGroupKey),
100
- );
101
- const requiredFields =
102
- activity?.requiredFields ?? group?.requiredFields ?? [];
103
- const orRequiredFields =
104
- activity?.orRequiredFields ?? group?.orRequiredFields ?? [];
83
+ const activity = taxonomy?.activities.find((candidate) => candidate.key === activityKey);
84
+ const group = taxonomy?.groups.find((candidate) => candidate.key === (activity?.groupKey ?? fallbackGroupKey));
85
+ const requiredFields = activity?.requiredFields ?? group?.requiredFields ?? [];
86
+ const orRequiredFields = activity?.orRequiredFields ?? group?.orRequiredFields ?? [];
105
87
 
106
88
  if (requiredFields.includes(fieldKey)) {
107
89
  return 'REQUIRED';
@@ -115,17 +97,12 @@ export function getTaxonomyFieldRequirement(
115
97
  * labels without assuming the label itself came from i18n.
116
98
  */
117
99
 
118
- export function formatLogTaxonomyFieldLabel(
119
- label: string,
120
- requirement: LogTaxonomyFieldRequirement,
121
- ): string {
100
+ export function formatLogTaxonomyFieldLabel(label: string, requirement: LogTaxonomyFieldRequirement): string {
122
101
  if (requirement === 'REQUIRED') {
123
102
  return `${label} *`;
124
103
  }
125
104
 
126
- return requirement === 'OR_REQUIRED'
127
- ? `${label} (${i18n.t('form.one_of_these_required')})`
128
- : label;
105
+ return requirement === 'OR_REQUIRED' ? `${label} (${i18n.t('c.one_of_these_required')})` : label;
129
106
  }
130
107
 
131
108
  /*
@@ -136,16 +113,18 @@ export function formatLogTaxonomyFieldLabel(
136
113
  export function getTaxonomyGroupLabel(
137
114
  taxonomy: LogTaxonomyGQL | null | undefined,
138
115
  groupKey?: string | null,
116
+ operation?: string | null,
117
+ short = true,
139
118
  ): string {
140
119
  if (!groupKey) {
141
120
  return '';
142
121
  }
143
- if (i18n.has(`log.type_short.${groupKey}`)) {
144
- return i18n.t(`log.type_short.${groupKey}`);
122
+ if (groupKey === 'MARKET_OPERATION' || (groupKey === 'OPERATION' && (operation || taxonomy?.operation) === 'FARMERS_MARKET')) {
123
+ return i18n.t(short ? 'log.type_short.MARKET_OPERATION' : 'log.market_operations');
145
124
  }
146
- const label = taxonomy?.groups?.find(
147
- (group) => group.key === groupKey,
148
- )?.label;
125
+ const labelKey = `log.${short ? 'type_short' : 'type'}.${groupKey}`;
126
+ if (i18n.has(labelKey)) return i18n.t(labelKey);
127
+ const label = taxonomy?.groups?.find((group) => group.key === groupKey)?.label;
149
128
  return label || humanizeRegistryKey(groupKey);
150
129
  }
151
130
 
@@ -153,9 +132,7 @@ export function getTaxonomyGroupLabel(
153
132
  * Group taxonomy activities in the taxonomy group's display order
154
133
  */
155
134
 
156
- export function getTaxonomyActivitiesGrouped(
157
- taxonomy: LogTaxonomyGQL,
158
- ): [string, LogTaxonomyActivityGQL[]][] {
135
+ export function getTaxonomyActivitiesGrouped(taxonomy: LogTaxonomyGQL): [string, LogTaxonomyActivityGQL[]][] {
159
136
  const activitiesByGroup = new Map<string, LogTaxonomyActivityGQL[]>();
160
137
  for (const activity of taxonomy.activities) {
161
138
  if (!activity.groupKey) {
@@ -167,10 +144,7 @@ export function getTaxonomyActivitiesGrouped(
167
144
  activitiesByGroup.set(activity.groupKey, activities);
168
145
  }
169
146
 
170
- return taxonomy.groups.map((group) => [
171
- group.key,
172
- activitiesByGroup.get(group.key) || [],
173
- ]);
147
+ return taxonomy.groups.map((group) => [group.key, activitiesByGroup.get(group.key) || []]);
174
148
  }
175
149
 
176
150
  /*
@@ -185,15 +159,19 @@ export function getTaxonomyFieldDefsForActivity(
185
159
  fallbackGroupKey?: string | null,
186
160
  ): LogTaxonomyFieldDefGQL[] {
187
161
  const groupKey = getTaxonomyGroupKey(taxonomy, activityKey, fallbackGroupKey);
188
- return (taxonomy?.fieldDefs || []).filter((def) => {
189
- if (def.activityKey) {
190
- return def.activityKey === activityKey;
191
- }
192
- if (def.groupKey) {
193
- return !!groupKey && def.groupKey === groupKey;
194
- }
195
- return true;
196
- });
162
+ return (taxonomy?.fieldDefs || []).filter((def) =>
163
+ isLogFieldApplicableToActivity(
164
+ {
165
+ ...def,
166
+ config: {
167
+ includedActivityKeys: def.includedActivityKeys ?? undefined,
168
+ excludedActivityKeys: def.excludedActivityKeys ?? undefined,
169
+ },
170
+ },
171
+ activityKey,
172
+ groupKey,
173
+ ),
174
+ );
197
175
  }
198
176
 
199
177
  /*
@@ -204,11 +182,14 @@ export function getLogEntryDetailsFieldLabel(key?: string | null): string {
204
182
  if (!key) {
205
183
  return '';
206
184
  }
185
+ if (key === 'rackNumber') {
186
+ return i18n.t('c.rack');
187
+ }
207
188
  if (i18n.has(`log.${key}`)) {
208
189
  return i18n.t(`log.${key}`);
209
190
  }
210
- if (i18n.has(`form.${key}`)) {
211
- return i18n.t(`form.${key}`);
191
+ if (i18n.has(`c.${key}`)) {
192
+ return i18n.t(`c.${key}`);
212
193
  }
213
194
  return humanizeRegistryKey(key);
214
195
  }
@@ -218,16 +199,12 @@ export function getLogEntryDetailsFieldLabel(key?: string | null): string {
218
199
  * the selected registry activity or group.
219
200
  */
220
201
 
221
- export function getLogEntryDetailsEnvelopeFieldLabel(
222
- key: string,
223
- activityKey?: string | null,
224
- groupKey?: string | null,
225
- ): string {
202
+ export function getLogEntryDetailsEnvelopeFieldLabel(key: string, activityKey?: string | null, groupKey?: string | null): string {
226
203
  if (key === 'quantity' && activityKey === 'COLD_STORAGE_TEMPERATURE') {
227
- return i18n.t('form.temperature');
204
+ return i18n.t('c.temperature');
228
205
  }
229
206
  if (key === 'quantity' && groupKey === 'WATER') {
230
- return i18n.t('form.water_quantity');
207
+ return i18n.t('c.water_quantity');
231
208
  }
232
209
 
233
210
  return getLogEntryDetailsFieldLabel(key);
@@ -237,19 +214,14 @@ export function getLogEntryDetailsEnvelopeFieldLabel(
237
214
  * Return a canonical calendar-date value or null for an invalid value.
238
215
  */
239
216
 
240
- export function normalizeLogEntryDetailsDateValue(
241
- value?: string | null,
242
- ): string | null {
217
+ export function normalizeLogEntryDetailsDateValue(value?: string | null): string | null {
243
218
  const trimmedValue = String(value || '').trim();
244
219
  if (!/^\d{4}-\d{2}-\d{2}$/.test(trimmedValue)) {
245
220
  return null;
246
221
  }
247
222
 
248
223
  const parsedDate = new Date(`${trimmedValue}T00:00:00.000Z`);
249
- return Number.isFinite(parsedDate.getTime()) &&
250
- parsedDate.toISOString().slice(0, 10) === trimmedValue
251
- ? trimmedValue
252
- : null;
224
+ return Number.isFinite(parsedDate.getTime()) && parsedDate.toISOString().slice(0, 10) === trimmedValue ? trimmedValue : null;
253
225
  }
254
226
 
255
227
  /*
@@ -257,10 +229,7 @@ export function normalizeLogEntryDetailsDateValue(
257
229
  * datetime-local input, honoring the organization timezone when available.
258
230
  */
259
231
 
260
- export function getLogEntryDetailsDateTimeInputValue(
261
- value?: string | null,
262
- timeZone?: string | null,
263
- ): string | null {
232
+ export function getLogEntryDetailsDateTimeInputValue(value?: string | null, timeZone?: string | null): string | null {
264
233
  const date = value ? new Date(value) : null;
265
234
  if (!date || !Number.isFinite(date.getTime())) {
266
235
  return null;
@@ -275,23 +244,14 @@ export function getLogEntryDetailsDateTimeInputValue(
275
244
  * the GraphQL mutation contract.
276
245
  */
277
246
 
278
- export function normalizeLogEntryDetailsDateTimeValue(
279
- value?: string | null,
280
- timeZone?: string | null,
281
- ): string | null {
247
+ export function normalizeLogEntryDetailsDateTimeValue(value?: string | null, timeZone?: string | null): string | null {
282
248
  const trimmedValue = String(value || '').trim();
283
- if (
284
- !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/.test(
285
- trimmedValue,
286
- )
287
- ) {
249
+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/.test(trimmedValue)) {
288
250
  return null;
289
251
  }
290
252
 
291
253
  const parsedDate = parseDateInTimezone(trimmedValue, timeZone, 0, true);
292
- return Number.isFinite(parsedDate.getTime())
293
- ? parsedDate.toISOString()
294
- : null;
254
+ return Number.isFinite(parsedDate.getTime()) ? parsedDate.toISOString() : null;
295
255
  }
296
256
 
297
257
  /*
@@ -304,15 +264,10 @@ export function getLogEntryDetailsFieldValue(
304
264
  timeZone?: string | null,
305
265
  ): string | number | boolean | null {
306
266
  if (field.fieldType === 'DATE') {
307
- return normalizeLogEntryDetailsDateValue(
308
- field.dateValue ?? field.textValue,
309
- );
267
+ return normalizeLogEntryDetailsDateValue(field.dateValue ?? field.textValue);
310
268
  }
311
269
  if (field.fieldType === 'DATETIME') {
312
- return getLogEntryDetailsDateTimeInputValue(
313
- field.datetimeValue ?? field.textValue,
314
- timeZone,
315
- );
270
+ return getLogEntryDetailsDateTimeInputValue(field.datetimeValue ?? field.textValue, timeZone);
316
271
  }
317
272
  return field.textValue ?? field.numberValue ?? field.booleanValue ?? null;
318
273
  }
@@ -350,10 +305,7 @@ export function getLogEntryDetailsFieldValueByKey(
350
305
  * invalid value into zero.
351
306
  */
352
307
 
353
- export function getLogEntryDetailsNumberFieldValue(
354
- details: Record<string, any> | null | undefined,
355
- key: string,
356
- ): number | null {
308
+ export function getLogEntryDetailsNumberFieldValue(details: Record<string, any> | null | undefined, key: string): number | null {
357
309
  const value = getLogEntryDetailsFieldValueByKey(details, key);
358
310
  if (value === '' || value === null || value === undefined) {
359
311
  return null;
@@ -363,15 +315,34 @@ export function getLogEntryDetailsNumberFieldValue(
363
315
  return Number.isFinite(numberValue) ? numberValue : null;
364
316
  }
365
317
 
318
+ /*
319
+ * Format one rack position's temperature reading, preserving zero and negative values.
320
+ */
321
+
322
+ export function getLogTemperatureText(details: LogEntryDetailsGQL, position: 'top' | 'middle' | 'bottom'): string {
323
+ const unit = getLogEntryDetailsFieldValueByKey(details, 'temperatureUnit');
324
+ return formatLogTemperatureValue(
325
+ getLogEntryDetailsNumberFieldValue(details, `${position}Temperature`),
326
+ unit == null ? null : String(unit),
327
+ );
328
+ }
329
+
330
+ /*
331
+ * Format a measured temperature consistently across metadata and tables without
332
+ * inventing a missing unit or discarding an unfamiliar saved unit.
333
+ */
334
+
335
+ export function formatLogTemperatureValue(temperature: number | null, unit?: string | null): string {
336
+ if (temperature === null) return '';
337
+ return `${temperature}${unit === 'C' || unit === 'F' ? ` °${unit}` : unit ? ` ${unit}` : ''}`;
338
+ }
339
+
366
340
  /*
367
341
  * Read one QUANTITY registry field's unit from either GraphQL, editor, or
368
342
  * materialized metadata details.
369
343
  */
370
344
 
371
- export function getLogEntryDetailsFieldUnitByKey(
372
- details: Record<string, any> | null | undefined,
373
- key: string,
374
- ): string | null {
345
+ export function getLogEntryDetailsFieldUnitByKey(details: Record<string, any> | null | undefined, key: string): string | null {
375
346
  const directUnit = details?.[`${key}Unit`];
376
347
  if (directUnit !== null && directUnit !== undefined) {
377
348
  return String(directUnit);
@@ -384,19 +355,14 @@ export function getLogEntryDetailsFieldUnitByKey(
384
355
  }
385
356
 
386
357
  const mappedUnit = details?.fieldUnits?.[key];
387
- return mappedUnit === null || mappedUnit === undefined
388
- ? null
389
- : String(mappedUnit);
358
+ return mappedUnit === null || mappedUnit === undefined ? null : String(mappedUnit);
390
359
  }
391
360
 
392
361
  /*
393
362
  * Format one typed field value for read-only display
394
363
  */
395
364
 
396
- export function formatLogEntryDetailsFieldValue(
397
- field: LogEntryDetailsFieldGQL,
398
- timeZone?: string | null,
399
- ): string {
365
+ export function formatLogEntryDetailsFieldValue(field: LogEntryDetailsFieldGQL, timeZone?: string | null): string {
400
366
  const value = getLogEntryDetailsFieldValue(field, timeZone);
401
367
  if (value === null || value === undefined) {
402
368
  return '';
@@ -405,23 +371,15 @@ export function formatLogEntryDetailsFieldValue(
405
371
  return formatCurrency(value as number, false);
406
372
  }
407
373
  if (field.fieldType === 'BOOLEAN') {
408
- return i18n.t(value ? 'form.yes' : 'form.no');
374
+ return i18n.t(value ? 'c.yes' : 'c.no');
409
375
  }
410
376
  if (field.fieldType === 'DATE') {
411
- return (
412
- getReadableCalDate(String(value), timeZone || undefined) || String(value)
413
- );
377
+ return formatDisplayDate(String(value), timeZone);
414
378
  }
415
379
  if (field.fieldType === 'DATETIME') {
416
380
  const datetimeValue = field.datetimeValue ?? field.textValue;
417
381
  const parsedDate = datetimeValue ? new Date(datetimeValue) : null;
418
- return parsedDate && Number.isFinite(parsedDate.getTime())
419
- ? getFullDateTime(parsedDate, {
420
- alwaysShowYear: true,
421
- textDateStyle: 'short',
422
- timeZone: timeZone || null,
423
- })
424
- : String(value);
382
+ return parsedDate && Number.isFinite(parsedDate.getTime()) ? formatDisplayDate(parsedDate, timeZone) : String(value);
425
383
  }
426
384
  const unitText = field.unit ? ` ${field.unit}` : '';
427
385
  return `${value}${unitText}`;
@@ -432,8 +390,6 @@ export function formatLogEntryDetailsFieldValue(
432
390
  * generic details list. flagColor is a storage slot rendered elsewhere.
433
391
  */
434
392
 
435
- export function isLogEntryDetailsCustomField(
436
- field: LogEntryDetailsFieldGQL,
437
- ): boolean {
393
+ export function isLogEntryDetailsCustomField(field: LogEntryDetailsFieldGQL): boolean {
438
394
  return !!field.key && field.key !== 'flagColor';
439
395
  }