@jsb188/mday 1.1.10 → 1.1.11

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 (119) hide show
  1. package/package.json +105 -54
  2. package/src/constants/agentDoc.ts +12 -0
  3. package/src/constants/agentMemory.ts +154 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/campaign.ts +127 -0
  6. package/src/constants/dataTable.ts +35 -9
  7. package/src/constants/dataTableFieldTypes.generated.ts +63 -0
  8. package/src/constants/docAccess.ts +32 -0
  9. package/src/constants/email.ts +20 -4
  10. package/src/constants/fieldDoc.ts +34 -0
  11. package/src/constants/graphqlReactivity.ts +113 -0
  12. package/src/constants/integration.ts +8 -9
  13. package/src/constants/log.ts +7 -410
  14. package/src/constants/logActivityGroupColors.generated.ts +19 -0
  15. package/src/constants/logTaxonomy.generated.ts +1103 -0
  16. package/src/constants/noteDoc.ts +77 -0
  17. package/src/constants/organization.ts +13 -15
  18. package/src/constants/pageRoute.ts +23 -0
  19. package/src/constants/schedule.ts +220 -0
  20. package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
  21. package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
  22. package/src/constants/sheet.ts +154 -6
  23. package/src/constants/sheetRegionSources.generated.ts +578 -0
  24. package/src/constants/square.ts +6 -6
  25. package/src/constants/storage.ts +56 -7
  26. package/src/constants/usage.ts +79 -0
  27. package/src/schemas/editLogEntry.ts +1010 -777
  28. package/src/schemas/fieldDocsQuery.ts +12 -0
  29. package/src/schemas/inboundContact.ts +60 -55
  30. package/src/schemas/logsQuery.ts +55 -49
  31. package/src/schemas/organization.ts +49 -46
  32. package/src/types/account.d.ts +4 -1
  33. package/src/types/agentDoc.d.ts +64 -0
  34. package/src/types/agentMemory.d.ts +74 -0
  35. package/src/types/campaign.d.ts +683 -0
  36. package/src/types/dataTable.d.ts +175 -256
  37. package/src/types/docAccess.d.ts +96 -0
  38. package/src/types/email.d.ts +83 -12
  39. package/src/types/fieldDoc.d.ts +273 -0
  40. package/src/types/inboundContact.d.ts +2 -1
  41. package/src/types/log.d.ts +209 -341
  42. package/src/types/noteDoc.d.ts +86 -0
  43. package/src/types/organization.d.ts +83 -40
  44. package/src/types/pageRoute.d.ts +48 -0
  45. package/src/types/schedule.d.ts +391 -0
  46. package/src/types/sheet.d.ts +862 -30
  47. package/src/types/storage.d.ts +206 -125
  48. package/src/types/usage.d.ts +106 -0
  49. package/src/types/workflow.d.ts +149 -18
  50. package/src/utils/agentDoc.ts +109 -0
  51. package/src/utils/aiChat.ts +26 -0
  52. package/src/utils/campaign.ts +741 -0
  53. package/src/utils/campaignFormEditor.ts +871 -0
  54. package/src/utils/dataTable.ts +425 -410
  55. package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
  56. package/src/utils/dataTableRealtimeAuthority.ts +209 -0
  57. package/src/utils/dataTableRealtimeSelection.ts +134 -0
  58. package/src/utils/dataTableRowDocument.ts +508 -0
  59. package/src/utils/dataTableSource.ts +230 -0
  60. package/src/utils/docAccess.ts +383 -0
  61. package/src/utils/documentName.ts +53 -0
  62. package/src/utils/email.ts +112 -53
  63. package/src/utils/fieldDoc.ts +113 -0
  64. package/src/utils/log.ts +169 -176
  65. package/src/utils/logRegistryValue.ts +90 -0
  66. package/src/utils/logStoreRead.ts +266 -0
  67. package/src/utils/logTaxonomy.ts +76 -0
  68. package/src/utils/logTaxonomyDisplay.ts +439 -0
  69. package/src/utils/noteDoc.ts +827 -0
  70. package/src/utils/organization.ts +510 -91
  71. package/src/utils/pageRoute.ts +71 -0
  72. package/src/utils/schedule.ts +799 -0
  73. package/src/utils/scheduleEvaluation.ts +1994 -0
  74. package/src/utils/scheduleICS.ts +246 -0
  75. package/src/utils/scheduleRuleTemplates.ts +188 -0
  76. package/src/utils/sheet.ts +4842 -39
  77. package/src/utils/sheetAxisMove.ts +830 -0
  78. package/src/utils/sheetBootstrap.ts +1769 -0
  79. package/src/utils/sheetCommand.ts +423 -0
  80. package/src/utils/sheetExport.ts +238 -0
  81. package/src/utils/sheetFormulaEvaluation.ts +914 -0
  82. package/src/utils/sheetFormulaEvaluator.ts +852 -0
  83. package/src/utils/sheetJournal.ts +78 -0
  84. package/src/utils/sheetNumberFormat.ts +1211 -0
  85. package/src/utils/sheetRegion.ts +374 -0
  86. package/src/utils/sheetRegionFilter.ts +1259 -0
  87. package/src/utils/sheetRegionSourceRegistry.ts +594 -0
  88. package/src/utils/sheetSequence.ts +148 -0
  89. package/src/utils/sheetSnapshot.ts +992 -0
  90. package/src/utils/sheetStructureEdit.ts +1284 -0
  91. package/src/utils/square.ts +22 -12
  92. package/src/utils/storage.ts +152 -0
  93. package/src/utils/table-route.ts +127 -11
  94. package/src/utils/workflow.ts +191 -23
  95. package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
  96. package/tests/docAccess.test.ts +525 -0
  97. package/tests/editLogEntry.test.ts +112 -0
  98. package/tests/noteDoc.test.ts +669 -0
  99. package/tests/schedule.test.ts +693 -0
  100. package/tests/scheduleEvaluation.test.ts +1970 -0
  101. package/tests/scheduleICS.test.ts +208 -0
  102. package/tests/scheduleRuleTemplates.test.ts +176 -0
  103. package/tests/scheduleSweepInvariants.test.ts +428 -0
  104. package/tests/sheetAxisMove.test.ts +343 -0
  105. package/tests/sheetFormulaEvaluator.test.ts +575 -0
  106. package/tests/sheetRegionFilter.test.ts +1135 -0
  107. package/tests/sheetSequence.test.ts +41 -0
  108. package/tests/sheetStructureEdit.test.ts +82 -0
  109. package/tsconfig.json +10 -10
  110. package/vitest.config.ts +8 -0
  111. package/src/constants/log-activityTexts.ts +0 -235
  112. package/src/constants/product.ts +0 -42
  113. package/src/constants/report.ts +0 -44
  114. package/src/schemas/productsQuery.ts +0 -53
  115. package/src/schemas/reportsQuery.ts +0 -20
  116. package/src/types/product.d.ts +0 -84
  117. package/src/types/report.d.ts +0 -290
  118. package/src/utils/product-calEvent.ts +0 -455
  119. package/src/utils/report.ts +0 -158
@@ -1,12 +1,6 @@
1
1
  import { REQUEST_SOURCE_ENUMS } from '@jsb188/app/constants/agent.ts';
2
2
  import type { LabelAndValue } from '@jsb188/app/types/other.d.ts';
3
- import {
4
- LOG_ARABLE_ACTIVITY_ENUMS,
5
- LOG_FARMERS_MARKET_ACTIVITY_ENUMS,
6
- LOG_GROWER_NETWORK_ACTIVITY_ENUMS,
7
- LOG_LIVESTOCK_ACTIVITY_ENUMS,
8
- LOG_SORT_ENUMS
9
- } from '../constants/log.ts';
3
+ import { LOG_SORT_ENUMS } from '../constants/log.ts';
10
4
  import type { OrganizationOperationEnum } from '../types/organization.d.ts';
11
5
  import type { AccountObj } from './account.d.ts';
12
6
  import type { StorageGQL } from './storage.d.ts';
@@ -16,351 +10,225 @@ import type { StorageGQL } from './storage.d.ts';
16
10
  */
17
11
 
18
12
  export type LogContentName = 'log' | 'invoice' | 'receipt'; // For UI visuals, client-side only
19
- export type LogSortEnum = typeof LOG_SORT_ENUMS[number];
20
- export type RequestSourceEnum = typeof REQUEST_SOURCE_ENUMS[number];
13
+ export type LogSortEnum = (typeof LOG_SORT_ENUMS)[number];
14
+ export type RequestSourceEnum = (typeof REQUEST_SOURCE_ENUMS)[number];
21
15
 
22
- /**
23
- * Arable
24
- */
25
-
26
- export type LogArableTypeEnum =
27
- | 'SEED'
28
- | 'PLANTING'
29
- | 'FIELD'
30
- | 'HARVEST'
31
- | 'POST_HARVEST'
32
- | 'SALES'
33
- | 'WATER'
34
- | 'HYGIENE'
35
- | 'SANITATION'
36
- | 'EQUIPMENT'
37
- | 'BIOSECURITY'
38
- | 'EMPLOYEE';
39
- export type LogArableActivityEnum = typeof LOG_ARABLE_ACTIVITY_ENUMS[number];
40
-
41
- /**
42
- * Farmers Market
43
- */
44
-
45
- export type LogFarmersMarketTypeEnum = 'MARKET_RECEIPT' | 'MARKET_OPERATION';
46
- export type LogFarmersMarketActivityEnum =
47
- typeof LOG_FARMERS_MARKET_ACTIVITY_ENUMS[number];
48
-
49
- /**
50
- * Grower Network
51
- */
52
-
53
- export type LogGrowerNetworkTypeEnum =
54
- | 'WORKER_PRACTICE'
55
- | 'EQUIPMENT'
56
- | 'FIELD'
57
- | 'PRODUCTION_INPUT'
58
- | 'OPERATION';
59
- export type LogGrowerNetworkActivityEnum =
60
- typeof LOG_GROWER_NETWORK_ACTIVITY_ENUMS[number];
61
-
62
- /**
63
- * Livestock
64
- */
65
-
66
- export type LogLivestockTypeEnum =
67
- | 'SUPPLY_PURCHASE'
68
- | 'LIVESTOCK_LIFE_CYCLE'
69
- | 'LIVESTOCK_TRACKING'
70
- | 'PASTURE_LAND_MANAGEMENT'
71
- | 'LIVESTOCK_HEALTHCARE'
72
- | 'LIVESTOCK_SALE';
73
- export type LogLivestockActivityEnum =
74
- typeof LOG_LIVESTOCK_ACTIVITY_ENUMS[number];
75
-
76
- /**
77
- * All log types/activities Union
78
- */
79
-
80
- export type LogTypeEnum =
81
- | LogArableTypeEnum
82
- | LogFarmersMarketTypeEnum
83
- | LogGrowerNetworkTypeEnum
84
- | LogLivestockTypeEnum;
85
-
86
- export type LogActivityEnum =
87
- | LogArableActivityEnum
88
- | LogFarmersMarketActivityEnum
89
- | LogGrowerNetworkActivityEnum
90
- | LogLivestockActivityEnum;
91
-
92
- /**
93
- * Log metadata
94
- */
95
-
96
- interface LogMetadataBase {
97
- __before: any;
98
- item: string;
99
- date: string;
100
- time: string;
101
- otherParty?: string;
102
- referenceNumber?: string;
103
-
104
- // Interface specific
105
- values?: LabelAndValue[];
106
- voided?: boolean;
107
-
108
- summary?: string;
109
- location?: string;
110
- tax?: number; // Need to be removed and replaced by values[#].tax -- but this will require some logic changes
111
- }
112
-
113
- export interface LogArableMetadata extends LogMetadataBase {
114
- fieldLocation?: string;
115
- quantity: number;
116
- unit: string;
117
- concentration: number;
118
- concentrationUnit: string;
119
- }
120
-
121
- export interface LogFarmersMarketMetadata extends LogMetadataBase {
122
- values: LabelAndValue[];
123
- }
124
-
125
- export interface LogGrowerNetworkMetadata extends LogMetadataBase {
126
- fieldLocation?: string;
127
- }
128
-
129
- export interface LogLivestockMetadata extends LogMetadataBase {
130
- fieldLocation?: string;
131
- }
16
+ // Activity and group keys are registry data and can be extended per organization.
17
+ export type LogTypeEnum = string;
18
+ export type LogActivityEnum = string;
132
19
 
133
20
  /**
134
- * Log *_details table
21
+ * Shared log details fields
135
22
  */
136
23
 
137
24
  export interface LogDetailsBase {
138
- id: number | bigint;
139
- childOrg?: {
140
- id: number | bigint;
141
- name: string;
142
- operation?: OrganizationOperationEnum | null;
143
- };
144
- childOrgId?: number | bigint | null;
145
- reportId?: number | bigint | null;
146
- reportSubmissionId?: number | bigint | null;
147
- siteId?: number | bigint | null;
148
- site?: {
149
- id: number | bigint;
150
- name: string;
151
- };
152
- location?: {
153
- name: string;
154
- } | null;
155
- notes: string | null;
156
- translation: string | null;
157
- }
158
-
159
- export interface LogArableDetailsData extends LogDetailsBase {
160
- __table: 'logs_arable';
161
- activity: LogArableActivityEnum;
162
- metadata?: Partial<LogArableMetadata> | null;
163
- }
164
-
165
- export interface LogFarmersMarketDetailsData extends LogDetailsBase {
166
- __table: 'logs_farmers_market';
167
- activity: LogFarmersMarketActivityEnum;
168
- metadata?: Partial<LogFarmersMarketMetadata> | null;
169
- }
170
-
171
- export interface LogGrowerNetworkDetailsData extends LogDetailsBase {
172
- __table: 'logs_grower_network';
173
- activity: LogGrowerNetworkActivityEnum;
174
- animalRisk: boolean;
175
- equipmentRisk: boolean;
176
- fieldRisk: boolean;
177
- contaminationRisk: boolean;
178
- hygieneRisk: boolean;
179
- pestsRisk: boolean;
180
- sanitationRisk: boolean;
181
- metadata?: Partial<LogGrowerNetworkMetadata> | null;
182
- }
183
-
184
- export interface LogLivestockDetailsData extends LogDetailsBase {
185
- __table: 'logs_livestock';
186
- activity: LogLivestockActivityEnum;
187
- metadata?: Partial<LogLivestockMetadata> | null;
188
- }
189
-
190
- /**
191
- * Log details union - GraphQL
192
- */
193
-
194
- interface LogDetailsBaseGQL {
195
- id: string;
196
- type: LogTypeEnum;
197
- activity: LogActivityEnum;
198
- summary: string | null;
199
- notes: string;
200
- }
201
-
202
- export interface LogArableDetailsGQL extends LogDetailsBaseGQL {
203
- __typename: 'LogArable';
204
-
205
- item: string | null;
206
- quantity: number | null;
207
- unit: string | null;
208
- concentration: number | null;
209
- concentrationUnit: string | null;
210
- fieldLocation: string | null;
211
- otherParty: string | null;
212
- referenceNumber: string | null;
213
- values: LabelAndValue[] | null;
214
- tax: number | null;
215
- voided: boolean | null;
216
- }
217
-
218
- export interface LogFarmersMarketDetailsGQL extends LogDetailsBaseGQL {
219
- __typename: 'LogFarmersMarket';
220
-
221
- item: string | null;
222
- otherParty: string | null;
223
- referenceNumber: string | null;
224
- values: LabelAndValue[] | null;
225
- tax: number | null;
226
- voided: boolean | null;
227
- }
228
-
229
- export interface LogGrowerNetworkDetailsGQL extends LogDetailsBaseGQL {
230
- __typename: 'LogGrowerNetwork';
231
-
232
- animalRisk: boolean;
233
- equipmentRisk: boolean;
234
- fieldRisk: boolean;
235
- contaminationRisk: boolean;
236
- hygieneRisk: boolean;
237
- pestsRisk: boolean;
238
- sanitationRisk: boolean;
239
- otherParty: string | null;
240
- item: string | null;
241
- fieldLocation: string | null;
242
- }
243
-
244
- export interface LogLivestockDetailsGQL extends LogDetailsBaseGQL {
245
- __typename: 'LogLivestock';
246
-
247
- livestock: string | null;
248
- livestockIdentifiers: string[] | null;
249
- livestockGroup: string | null;
250
- damIdentifier: string | null;
251
- otherParty: string | null;
252
- referenceNumber: string | null;
253
- values: LabelAndValue[] | null;
254
- tax: number | null;
255
- voided: boolean | null;
256
- item: string | null;
257
- quantity: number | null;
258
- unit: string | null;
259
- price: number | null;
260
- fieldLocation: string | null;
25
+ id: number | bigint;
26
+ childOrg?: {
27
+ id: number | bigint;
28
+ name: string;
29
+ operation?: OrganizationOperationEnum | null;
30
+ };
31
+ childOrgId?: number | bigint | null;
32
+ fieldDocId?: number | bigint | null;
33
+ fieldDocSubmissionId?: number | bigint | null;
34
+ siteId?: number | bigint | null;
35
+ site?: {
36
+ id: number | bigint;
37
+ name: string;
38
+ };
39
+ location?: {
40
+ name: string;
41
+ } | null;
42
+ notes: string | null;
43
+ translation: string | null;
44
+ }
45
+
46
+ // All operations use one registry-driven details shape.
47
+ export interface LogEntryDetailsData extends LogDetailsBase {
48
+ __table: 'log_entry_details';
49
+ activity: string;
50
+ logType?: string | null;
51
+ fields?: LogEntryDetailsFieldGQL[] | null;
52
+ metadata?: Record<string, any> | null;
53
+ }
54
+
55
+ // One typed field-def value on a registry-driven operation's log
56
+ export interface LogEntryDetailsFieldGQL {
57
+ key: string;
58
+ fieldType: string | null;
59
+ textValue: string | null;
60
+ numberValue: number | null;
61
+ booleanValue: boolean | null;
62
+ dateValue: string | null;
63
+ datetimeValue: string | null;
64
+ unit: string | null;
65
+ }
66
+
67
+ // One typed field-def value sent when editing a registry-driven log
68
+ export interface LogEntryDetailsFieldInput {
69
+ key: string;
70
+ textValue?: string | null;
71
+ numberValue?: number | null;
72
+ booleanValue?: boolean | null;
73
+ dateValue?: string | null;
74
+ datetimeValue?: string | null;
75
+ unit?: string | null;
76
+ clear?: boolean | null;
77
+ }
78
+
79
+ // Details for registry-driven operations; type/activity are registry keys
80
+ export interface LogEntryDetailsGQL {
81
+ __typename: 'LogEntryDetails';
82
+
83
+ id: string;
84
+ type: string | null;
85
+ activity: string;
86
+ notes: string;
87
+
88
+ item: string | null;
89
+ quantity: number | null;
90
+ unit: string | null;
91
+ price: number | null;
92
+ values: LabelAndValue[] | null;
93
+ fields: LogEntryDetailsFieldGQL[] | null;
94
+
95
+ otherParty: string | null;
96
+ referenceNumber: string | null;
97
+ fieldLocation: string | null;
98
+ voided: boolean | null;
99
+ }
100
+
101
+ // Log taxonomy carried by the existing organization bootstrap (registry rows)
102
+ export interface LogTaxonomyGroupGQL {
103
+ key: string;
104
+ label: string | null;
105
+ ordinal: number | null;
106
+ requiredFields: string[] | null;
107
+ orRequiredFields: string[] | null;
108
+ }
109
+
110
+ export interface LogTaxonomyActivityGQL {
111
+ key: string;
112
+ groupKey: string | null;
113
+ agentText: string | null;
114
+ ordinal: number | null;
115
+ requiredFields: string[] | null;
116
+ orRequiredFields: string[] | null;
117
+ }
118
+
119
+ export interface LogTaxonomyFieldDefGQL {
120
+ key: string;
121
+ fieldType: string;
122
+ required: boolean | null;
123
+ ordinal: number | null;
124
+ agentHint: string | null;
125
+ options: string[] | null;
126
+ allowedUnits: string[] | null;
127
+ groupKey: string | null;
128
+ activityKey: string | null;
129
+ }
130
+
131
+ export interface LogTaxonomyGQL {
132
+ operation: string;
133
+ groups: LogTaxonomyGroupGQL[];
134
+ activities: LogTaxonomyActivityGQL[];
135
+ fieldDefs: LogTaxonomyFieldDefGQL[];
261
136
  }
262
137
 
263
- /**
264
- * Union type for log details
265
- */
266
-
267
- export type LogMetadataGQL =
268
- | LogArableDetailsGQL
269
- | LogFarmersMarketDetailsGQL
270
- | LogGrowerNetworkDetailsGQL
271
- | LogLivestockDetailsGQL;
272
-
273
138
  /**
274
139
  * GQL data interfaces
275
140
  */
276
141
 
277
142
  export interface LogEntryGQL {
278
- __typename: string;
279
- __deleted?: boolean;
280
-
281
- id: string;
282
- accountId: string;
283
- organizationId: string;
284
- childOrgId: string | null;
285
- childOrgName: string | null;
286
- inboundContactId: string | null;
287
- inboundContactName: string | null;
288
- reportId: string | null;
289
- reportSubmissionId: string | null;
290
- siteId: string | null;
291
- location: string | null;
292
- details: LogMetadataGQL;
293
- summary: string;
294
- source?: RequestSourceEnum | null;
295
- confidence?: number | null;
296
- originalMessage?: string | null;
297
- flagColor?: string | null;
298
-
299
- account: any;
300
- files: StorageGQL[];
301
-
302
- date: string; // ISO date string
303
- createdAt: string; // ISO date string
304
- updatedAt: string; // ISO date string
143
+ __typename: string;
144
+ __deleted?: boolean;
145
+
146
+ id: string;
147
+ cursor?: string | null;
148
+ accountId: string;
149
+ organizationId: string;
150
+ childOrgId: string | null;
151
+ childOrgName: string | null;
152
+ inboundContactId: string | null;
153
+ inboundContactName: string | null;
154
+ inboundContactEmail?: string | null;
155
+ inboundContactPhone?: string | null;
156
+ fieldDocId: string | null;
157
+ fieldDocName?: string | null;
158
+ fieldDocSubmissionId: string | null;
159
+ fieldDocSubmissionPeriod?: string | null;
160
+ siteId: string | null;
161
+ siteName?: string | null;
162
+ location: string | null;
163
+ accountPersonName?: string | null;
164
+ details: LogEntryDetailsGQL;
165
+ summary: string;
166
+ source?: RequestSourceEnum | null;
167
+ confidence?: number | null;
168
+ originalMessage?: string | null;
169
+ flagColor?: string | null;
170
+
171
+ account: any;
172
+ files: StorageGQL[];
173
+
174
+ date: string; // ISO date string
175
+ createdAt: string; // ISO date string
176
+ updatedAt: string; // ISO date string
305
177
  }
306
178
 
307
179
  export interface LogEntryInsertObj {
308
- id?: number | bigint; // Only for edits
309
- accountId: number | bigint | null;
310
- organizationId: number | bigint;
311
- childOrgId?: number | bigint | null;
312
- inboundContactId?: number | bigint | null;
313
- emailId?: number | bigint | null;
314
- reportId?: number | bigint | null;
315
- reportSubmissionId?: number | bigint | null;
316
- siteId?: number | bigint | null;
317
- summary: string;
318
- source?: RequestSourceEnum | null;
319
- confidence?: number | null;
320
- originalMessage?: string | null;
321
- details: any;
322
- date: Date;
180
+ id?: number | bigint; // Only for edits
181
+ accountId: number | bigint | null;
182
+ organizationId: number | bigint;
183
+ childOrgId?: number | bigint | null;
184
+ inboundContactId?: number | bigint | null;
185
+ emailId?: number | bigint | null;
186
+ fieldDocId?: number | bigint | null;
187
+ fieldDocSubmissionId?: number | bigint | null;
188
+ siteId?: number | bigint | null;
189
+ summary: string;
190
+ source?: RequestSourceEnum | null;
191
+ confidence?: number | null;
192
+ originalMessage?: string | null;
193
+ details: any;
194
+ date: Date;
323
195
  }
324
196
 
325
197
  export interface LogEntryData {
326
- __table: 'logs';
327
- id: number | bigint;
328
- accountId: number | bigint;
329
- organizationId: number | bigint;
330
- childOrgId?: number | bigint | null;
331
- inboundContactId?: number | bigint | null;
332
- emailId?: number | bigint | null;
333
- inboundContact?: {
334
- id: number | bigint;
335
- personName?: string | null;
336
- } | null;
337
- childOrg?: {
338
- id: number | bigint;
339
- name: string;
340
- operation?: OrganizationOperationEnum | null;
341
- } | null;
342
- reportId?: number | bigint | null;
343
- reportSubmissionId?: number | bigint | null;
344
- siteId?: number | bigint | null;
345
- summary: string;
346
- source?: RequestSourceEnum | null;
347
- confidence?: number | null;
348
- originalMessage?: string | null;
349
- location?: {
350
- name: string;
351
- } | null;
352
- distance?: number; // For vector search
353
- details:
354
- | LogArableDetailsData
355
- | LogFarmersMarketDetailsData
356
- | LogGrowerNetworkDetailsData
357
- | LogLivestockDetailsData;
358
- date: Date;
359
- createdAt: Date;
360
- updatedAt: Date;
361
-
362
- // This is for outputs, but will never be set for inserts
363
- account?: AccountObj;
198
+ __table: 'logs';
199
+ id: number | bigint;
200
+ accountId: number | bigint;
201
+ organizationId: number | bigint;
202
+ childOrgId?: number | bigint | null;
203
+ inboundContactId?: number | bigint | null;
204
+ emailId?: number | bigint | null;
205
+ inboundContact?: {
206
+ id: number | bigint;
207
+ personName?: string | null;
208
+ } | null;
209
+ childOrg?: {
210
+ id: number | bigint;
211
+ name: string;
212
+ operation?: OrganizationOperationEnum | null;
213
+ } | null;
214
+ fieldDocId?: number | bigint | null;
215
+ fieldDocSubmissionId?: number | bigint | null;
216
+ siteId?: number | bigint | null;
217
+ summary: string;
218
+ source?: RequestSourceEnum | null;
219
+ confidence?: number | null;
220
+ originalMessage?: string | null;
221
+ location?: {
222
+ name: string;
223
+ } | null;
224
+ distance?: number; // For vector search
225
+ details: LogEntryDetailsData;
226
+ date: Date;
227
+ createdAt: Date;
228
+ updatedAt: Date;
229
+
230
+ // This is for outputs, but will never be set for inserts
231
+ account?: AccountObj;
364
232
  }
365
233
 
366
234
  /**
@@ -368,12 +236,12 @@ export interface LogEntryData {
368
236
  */
369
237
 
370
238
  export interface FilterLogEntriesArgs {
371
- accountId?: string | null; // Account ID to filter logs by account
372
- siteId?: string | number | bigint | null; // Site ID to filter logs by site
373
- preset?: 'WEEKS_5' | null;
374
- types?: LogTypeEnum[] | null;
375
- activities?: LogActivityEnum[] | null;
376
- startDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
377
- endDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
378
- query?: string | null;
239
+ accountId?: string | null; // Account ID to filter logs by account
240
+ siteId?: string | number | bigint | null; // Site ID to filter logs by site
241
+ preset?: 'WEEKS_5' | null;
242
+ types?: string[] | null;
243
+ activities?: string[] | null;
244
+ startDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
245
+ endDate?: string | null; // CalDate, with dashes (YYYY-MM-DD)
246
+ query?: string | null;
379
247
  }
@@ -0,0 +1,86 @@
1
+ import type {
2
+ NOTE_BLOCK_TYPES,
3
+ NOTE_INLINE_TYPES,
4
+ NOTE_MARK_TYPES,
5
+ } from '../constants/noteDoc.ts';
6
+
7
+ export type NoteBlockType = (typeof NOTE_BLOCK_TYPES)[number];
8
+ export type NoteInlineType = (typeof NOTE_INLINE_TYPES)[number];
9
+ export type NoteMarkType = (typeof NOTE_MARK_TYPES)[number];
10
+
11
+ // Heading depth; sanitizeNoteDoc clamps anything else into this range
12
+ export type NoteHeadingLevel = 1 | 2 | 3;
13
+
14
+ /**
15
+ * Attrs carried by one "image" void block. storageId is the string form of
16
+ * the storage row id and is the notes_storage_rels source-of-truth key:
17
+ * image blocks whose storageId has no surviving rel row are filtered out of
18
+ * the document on read. fileUri locates the GCS object for rendering.
19
+ */
20
+
21
+ export interface NoteImageAttrs {
22
+ storageId: string;
23
+ fileUri: string;
24
+ alt?: string;
25
+ width?: number;
26
+ }
27
+
28
+ /**
29
+ * One inline mark on a text run. color/highlight marks carry a palette
30
+ * token from NOTE_COLOR_TOKENS; link marks carry an http(s)/mailto href;
31
+ * every other mark type carries no attrs.
32
+ */
33
+
34
+ export interface NoteMark {
35
+ type: NoteMarkType;
36
+ attrs?: {
37
+ token?: string;
38
+ href?: string;
39
+ };
40
+ }
41
+
42
+ /**
43
+ * One inline node inside a text-bearing block: a styled text run, or a
44
+ * hard line break (which carries neither text nor marks).
45
+ */
46
+
47
+ export interface NoteInlineNode {
48
+ type: NoteInlineType;
49
+ text?: string;
50
+ marks?: NoteMark[];
51
+ }
52
+
53
+ /**
54
+ * Attrs a block node may carry: "level" on headings, image attrs on image
55
+ * blocks. Every other block type carries no attrs.
56
+ */
57
+
58
+ export interface NoteBlockAttrs extends Partial<NoteImageAttrs> {
59
+ level?: NoteHeadingLevel;
60
+ }
61
+
62
+ /**
63
+ * One block-level node. Containers (bulletList, orderedList, listItem,
64
+ * blockquote) hold block children; paragraph/heading hold inline children;
65
+ * divider/image hold none. _key and _uploading are client-editor-only
66
+ * fields, always stripped by sanitizeNoteDoc before persistence.
67
+ */
68
+
69
+ export interface NoteBlockNode {
70
+ type: NoteBlockType;
71
+ attrs?: NoteBlockAttrs;
72
+ content?: Array<NoteBlockNode | NoteInlineNode>;
73
+ _key?: string;
74
+ _uploading?: boolean;
75
+ }
76
+
77
+ /**
78
+ * The root note document stored in notes.content (JSONB). Always non-empty
79
+ * after sanitizing: at least one (possibly empty) paragraph.
80
+ */
81
+
82
+ export interface NoteDoc {
83
+ type: 'doc';
84
+ version: number;
85
+ content: NoteBlockNode[];
86
+ }