@jsb188/mday 1.1.2

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 (202) hide show
  1. package/package.json +142 -0
  2. package/src/constants/agentMemory.ts +166 -0
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +10 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +236 -0
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +22 -0
  10. package/src/constants/dataTableFieldTypes.generated.ts +59 -0
  11. package/src/constants/docAccess.ts +33 -0
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +146 -0
  14. package/src/constants/fieldDoc.ts +104 -0
  15. package/src/constants/graphqlReactivity.ts +196 -0
  16. package/src/constants/inboundContact.ts +8 -0
  17. package/src/constants/integration.ts +13 -0
  18. package/src/constants/log.ts +21 -0
  19. package/src/constants/logDisplay/README.md +88 -0
  20. package/src/constants/logDisplay/defaults.ts +39 -0
  21. package/src/constants/logDisplay/index.ts +27 -0
  22. package/src/constants/logDisplay/operations/arable.ts +16 -0
  23. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  24. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  25. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  26. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  27. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  28. package/src/constants/logTaxonomy.generated.ts +2199 -0
  29. package/src/constants/noteDoc.ts +77 -0
  30. package/src/constants/organization.ts +60 -0
  31. package/src/constants/pageRoute.ts +23 -0
  32. package/src/constants/qrCode.ts +30 -0
  33. package/src/constants/sheet.ts +132 -0
  34. package/src/constants/sms.ts +18 -0
  35. package/src/constants/square.ts +16 -0
  36. package/src/constants/storage.ts +85 -0
  37. package/src/constants/usage.ts +82 -0
  38. package/src/constants/workflowSteps.ts +60 -0
  39. package/src/schemas/editLogEntry.ts +879 -0
  40. package/src/schemas/inboundContact.ts +77 -0
  41. package/src/schemas/logsQuery.ts +93 -0
  42. package/src/types/account.d.ts +81 -0
  43. package/src/types/agentMemory.d.ts +100 -0
  44. package/src/types/agentNote.d.ts +441 -0
  45. package/src/types/billing.d.ts +537 -0
  46. package/src/types/campaign.d.ts +1533 -0
  47. package/src/types/contact.d.ts +15 -0
  48. package/src/types/csvExport.d.ts +213 -0
  49. package/src/types/dataAnalysis.d.ts +44 -0
  50. package/src/types/dataTable.d.ts +159 -0
  51. package/src/types/definitionElement.d.ts +35 -0
  52. package/src/types/docAccess.d.ts +96 -0
  53. package/src/types/dt.d.ts +257 -0
  54. package/src/types/email.d.ts +231 -0
  55. package/src/types/emailReplyReport.d.ts +76 -0
  56. package/src/types/fieldDoc.d.ts +702 -0
  57. package/src/types/fieldDocContract.d.ts +90 -0
  58. package/src/types/inboundContact.d.ts +65 -0
  59. package/src/types/integration.d.ts +42 -0
  60. package/src/types/log.d.ts +338 -0
  61. package/src/types/logDisplay.types.ts +85 -0
  62. package/src/types/organization.d.ts +350 -0
  63. package/src/types/pageRoute.d.ts +48 -0
  64. package/src/types/qrCode.d.ts +96 -0
  65. package/src/types/richText.d.ts +81 -0
  66. package/src/types/sheet.d.ts +847 -0
  67. package/src/types/sms.d.ts +38 -0
  68. package/src/types/storage.d.ts +481 -0
  69. package/src/types/usage.d.ts +106 -0
  70. package/src/types/workflow.d.ts +435 -0
  71. package/src/utils/agentMemory.ts +15 -0
  72. package/src/utils/agentNote.ts +850 -0
  73. package/src/utils/aiChat.ts +43 -0
  74. package/src/utils/aiChatWork.ts +64 -0
  75. package/src/utils/billing.ts +37 -0
  76. package/src/utils/campaign.ts +1173 -0
  77. package/src/utils/campaignAI.ts +72 -0
  78. package/src/utils/campaignAccess.ts +239 -0
  79. package/src/utils/campaignEmail.ts +601 -0
  80. package/src/utils/campaignEmailCompiler.ts +372 -0
  81. package/src/utils/campaignEmailImages.ts +60 -0
  82. package/src/utils/campaignEmailStyles.ts +544 -0
  83. package/src/utils/campaignLifecycle.ts +104 -0
  84. package/src/utils/campaignPreview.ts +285 -0
  85. package/src/utils/contact.ts +50 -0
  86. package/src/utils/csvExport.ts +19 -0
  87. package/src/utils/dataTable.ts +311 -0
  88. package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
  89. package/src/utils/dataTableRelativeDate.ts +447 -0
  90. package/src/utils/definitionElement.ts +84 -0
  91. package/src/utils/docAccess.ts +383 -0
  92. package/src/utils/documentName.ts +53 -0
  93. package/src/utils/email.ts +379 -0
  94. package/src/utils/emailReplyReport.test.ts +187 -0
  95. package/src/utils/emailReplyReport.ts +143 -0
  96. package/src/utils/fieldDoc.ts +157 -0
  97. package/src/utils/fieldDocAnswers.ts +128 -0
  98. package/src/utils/fieldDocDefaults.ts +36 -0
  99. package/src/utils/fieldDocProgram.ts +36 -0
  100. package/src/utils/fieldDocSummary.ts +30 -0
  101. package/src/utils/log.ts +357 -0
  102. package/src/utils/logDisplay.helpers.ts +177 -0
  103. package/src/utils/logDisplay.ts +87 -0
  104. package/src/utils/logRegistryValue.ts +90 -0
  105. package/src/utils/logStoreRead.ts +262 -0
  106. package/src/utils/logTaxonomy.helpers.ts +17 -0
  107. package/src/utils/logTaxonomy.ts +76 -0
  108. package/src/utils/logTaxonomyDisplay.ts +395 -0
  109. package/src/utils/noteDoc.ts +609 -0
  110. package/src/utils/organization.ts +669 -0
  111. package/src/utils/pageRoute.ts +71 -0
  112. package/src/utils/qrCode.helpers.ts +189 -0
  113. package/src/utils/qrCode.test.ts +519 -0
  114. package/src/utils/qrCode.ts +273 -0
  115. package/src/utils/richTextHTML.ts +385 -0
  116. package/src/utils/sheet.ts +262 -0
  117. package/src/utils/sheetAxisMove.ts +616 -0
  118. package/src/utils/sheetBootstrap.ts +1402 -0
  119. package/src/utils/sheetCellLiteral.ts +101 -0
  120. package/src/utils/sheetCommand.ts +358 -0
  121. package/src/utils/sheetDesign.ts +705 -0
  122. package/src/utils/sheetExport.ts +186 -0
  123. package/src/utils/sheetFeatureReference.ts +183 -0
  124. package/src/utils/sheetFormulaArgs.ts +168 -0
  125. package/src/utils/sheetFormulaCompile.ts +475 -0
  126. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  127. package/src/utils/sheetFormulaCriteria.ts +656 -0
  128. package/src/utils/sheetFormulaDate.ts +444 -0
  129. package/src/utils/sheetFormulaEvaluation.ts +899 -0
  130. package/src/utils/sheetFormulaEvaluator.ts +997 -0
  131. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  132. package/src/utils/sheetFormulaLogical.ts +116 -0
  133. package/src/utils/sheetFormulaLookup.ts +488 -0
  134. package/src/utils/sheetFormulaMath.ts +48 -0
  135. package/src/utils/sheetFormulaParser.ts +729 -0
  136. package/src/utils/sheetFormulaRange.ts +330 -0
  137. package/src/utils/sheetFormulaReference.ts +703 -0
  138. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  139. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  140. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  141. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  142. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  143. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  144. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  145. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  146. package/src/utils/sheetFormulaText.ts +430 -0
  147. package/src/utils/sheetJournal.ts +200 -0
  148. package/src/utils/sheetNumberFormat.ts +1012 -0
  149. package/src/utils/sheetPreview.ts +68 -0
  150. package/src/utils/sheetSequence.ts +118 -0
  151. package/src/utils/sheetSnapshot.ts +739 -0
  152. package/src/utils/sheetStructureEdit.ts +914 -0
  153. package/src/utils/sheetStructureReferences.ts +389 -0
  154. package/src/utils/square.ts +32 -0
  155. package/src/utils/storage.ts +198 -0
  156. package/src/utils/table-route.ts +262 -0
  157. package/src/utils/time.ts +12 -0
  158. package/src/utils/workflow.ts +506 -0
  159. package/src/utils/workflowLogFingerprint.ts +302 -0
  160. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  161. package/src/utils/workflowProgress.ts +280 -0
  162. package/src/utils/workflowTriggers.ts +61 -0
  163. package/tests/agentNote.test.ts +395 -0
  164. package/tests/campaignAI.test.ts +119 -0
  165. package/tests/campaignAccess.test.ts +239 -0
  166. package/tests/campaignEmail.test.ts +441 -0
  167. package/tests/campaignLifecycle.test.ts +134 -0
  168. package/tests/campaignPublication.test.ts +309 -0
  169. package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
  170. package/tests/dataTableRelativeDate.test.ts +412 -0
  171. package/tests/docAccess.test.ts +525 -0
  172. package/tests/editLogEntry.test.ts +112 -0
  173. package/tests/email.test.ts +39 -0
  174. package/tests/fieldDocProgram.test.ts +114 -0
  175. package/tests/logDisplay.fixtures.ts +67 -0
  176. package/tests/logDisplay.test.ts +227 -0
  177. package/tests/noteDoc.test.ts +514 -0
  178. package/tests/richTextHTML.test.ts +185 -0
  179. package/tests/sheetAxisMove.test.ts +352 -0
  180. package/tests/sheetBootstrap.test.ts +1967 -0
  181. package/tests/sheetFeatureReference.test.ts +22 -0
  182. package/tests/sheetFormulaCriteria.test.ts +269 -0
  183. package/tests/sheetFormulaEvaluator.test.ts +468 -0
  184. package/tests/sheetFormulaFunctions.test.ts +538 -0
  185. package/tests/sheetFormulaLanguage.test.ts +361 -0
  186. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  187. package/tests/sheetFormulaParity.test.ts +188 -0
  188. package/tests/sheetFormulaRange.test.ts +167 -0
  189. package/tests/sheetFormulaReference.test.ts +78 -0
  190. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  191. package/tests/sheetFormulaTextDate.test.ts +512 -0
  192. package/tests/sheetSequence.test.ts +22 -0
  193. package/tests/sheetSnapshot.test.ts +134 -0
  194. package/tests/sheetStructureEdit.test.ts +537 -0
  195. package/tests/sheetStructureReferences.test.ts +589 -0
  196. package/tests/workflowLifecycleStatus.test.ts +60 -0
  197. package/tests/workflowLogFingerprint.test.ts +203 -0
  198. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  199. package/tests/workflowProgress.test.ts +180 -0
  200. package/tests/workflowTriggers.test.ts +29 -0
  201. package/tsconfig.json +12 -0
  202. package/vitest.config.ts +8 -0
@@ -0,0 +1,702 @@
1
+ import {
2
+ FIELD_DOC_CATEGORIES,
3
+ FIELD_DOC_ELEMENT_KINDS,
4
+ FIELD_DOC_FREQUENCY_ENUMS,
5
+ FIELD_DOC_INSTANCE_STATUS_ENUMS,
6
+ FIELD_DOC_STATUS_ENUMS,
7
+ FIELD_DOC_SUBMISSION_FILTER_STATUS_ENUMS,
8
+ } from '../constants/fieldDoc.ts';
9
+ import type {
10
+ DefinitionElementBaseData,
11
+ DefinitionElementStorageRelBaseData,
12
+ DefinitionSectionWithElementsObj,
13
+ } from './definitionElement.d.ts';
14
+ import type { OrganizationData, OrganizationSiteData } from './organization.d.ts';
15
+ import type { StorageGQL } from './storage.d.ts';
16
+ import type {
17
+ FieldDocAnswerRules,
18
+ FieldDocAnswers,
19
+ FieldDocAnswerState,
20
+ FieldDocAnswerType,
21
+ FieldDocScalarAnswerType,
22
+ } from './fieldDocContract.d.ts';
23
+
24
+ /**
25
+ * Enums
26
+ */
27
+
28
+ export type FieldDocElementKindEnum = (typeof FIELD_DOC_ELEMENT_KINDS)[number];
29
+ export type FieldDocFrequencyEnum = (typeof FIELD_DOC_FREQUENCY_ENUMS)[number];
30
+ export type FieldDocSubmissionStatusEnum = (typeof FIELD_DOC_STATUS_ENUMS)[number];
31
+ export type FieldDocSubmissionFilterStatusEnum = (typeof FIELD_DOC_SUBMISSION_FILTER_STATUS_ENUMS)[number];
32
+ export type FieldDocInstanceStatusEnum = (typeof FIELD_DOC_INSTANCE_STATUS_ENUMS)[number];
33
+ export type FieldDocCategoryKey = (typeof FIELD_DOC_CATEGORIES)[number];
34
+
35
+ /**
36
+ * Filters
37
+ */
38
+
39
+ // fieldDocSubmissions list filter; the list is always scoped to one owner organization
40
+ export interface FieldDocSubmissionsFilterArgs {
41
+ fieldDocProgramId?: string | null;
42
+ fieldDocIds?: string[] | null;
43
+ siteId?: string | null;
44
+ statuses?: FieldDocSubmissionFilterStatusEnum[] | null; // OPEN represents an ungraded submission
45
+ startPeriod?: string | null; // YYYY-MM-DD
46
+ endPeriod?: string | null; // YYYY-MM-DD
47
+ }
48
+
49
+ /**
50
+ * FieldDoc; elements (the field_doc_elements table)
51
+ */
52
+
53
+ // Runtime values the template engine substitutes into a program layout aside (org name, timezone, etc.)
54
+ export interface FieldDocVariablesObj {
55
+ month?: number; // Used for {{month}} template expressions
56
+ [key: string]: any;
57
+ }
58
+
59
+ // Sparse behavior flags; absent means false
60
+ export interface FieldDocElementSettingsObj {
61
+ confirmationNeeded?: boolean; // AI must confirm the answer with the user before saving
62
+ allowCorrectiveActions?: boolean; // AI Agents may record corrective actions for this question
63
+ allowMultipleAnswers?: boolean;
64
+ doNotAllowNotes?: boolean; // If true, AI/respondents will NOT leave notes for this question
65
+ answer?: FieldDocAnswerRules;
66
+ allowNotApplicable?: boolean;
67
+ applicableWhen?: { questionKey: string; equals: string | number | boolean };
68
+ }
69
+
70
+ // "label" is the question label, title text or section title. If "options"
71
+ // is set, answers must match an option unless CHOICE explicitly allows Other. A "required" question must be
72
+ // answered or explicitly marked not applicable for document completion.
73
+ export interface FieldDocElementData
74
+ extends DefinitionElementBaseData<FieldDocElementKindEnum, string, FieldDocElementSettingsObj, FieldDocElementStorageRelData> {
75
+ __table: 'field_doc_elements';
76
+ fieldDocId: number | bigint;
77
+ hint?: string | null; // AI answering guidance; on overlaid docs, the program hint composed with the owner org's custom instructions
78
+ programHint?: string | null; // Overlaid docs only: the published hint before composition
79
+ customInstructions?: string | null; // Overlaid docs only: the owner org's custom instructions for this key
80
+ }
81
+
82
+ export interface FieldDocElementStorageRelData extends DefinitionElementStorageRelBaseData {
83
+ __table: 'field_doc_element_storage_rels';
84
+ fieldDocElementId: number | bigint;
85
+ }
86
+
87
+ export type FieldDocSectionWithElementsObj = DefinitionSectionWithElementsObj<FieldDocElementData>;
88
+
89
+ /**
90
+ * FieldDoc; program layout aside (field_doc_programs.layout.aside)
91
+ */
92
+
93
+ export interface FieldDocAsideBlockObj {
94
+ title: string;
95
+ nullText?: string;
96
+ items: FieldDocAsideItemObj[];
97
+ }
98
+
99
+ export interface FieldDocAsideItemObj {
100
+ className?: string;
101
+ label: string;
102
+ text: string;
103
+ // Omit the row when its resolved template text is empty.
104
+ hideIfEmpty?: boolean;
105
+ }
106
+
107
+ /**
108
+ * FieldDoc programs (field_doc_categories, field_doc_programs, field_doc_program_enrollments)
109
+ */
110
+
111
+ // field_doc_programs.layout; every key is optional (custom programs store '{}')
112
+ export interface FieldDocProgramLayoutObj {
113
+ columns?: string[];
114
+ headers?: string[];
115
+ gridLayoutStyle?: string;
116
+ aside?: FieldDocAsideBlockObj[]; // Rendered per submission on the document; never sent with the program
117
+ }
118
+
119
+ // A group belongs to its program; every enrolled organization sees the same groups.
120
+ export interface FieldDocProgramGroupData {
121
+ __table: 'field_doc_program_groups';
122
+ id: number | bigint;
123
+ programId: number;
124
+ catalogKey: string | null;
125
+ name: string;
126
+ order: number;
127
+ createdAt?: Date;
128
+ updatedAt?: Date;
129
+ }
130
+
131
+ // A catalog program (catalogKey set, organizationId null) or an organization's custom program (the reverse)
132
+ export interface FieldDocProgramData {
133
+ __table: 'field_doc_programs';
134
+ groups?: FieldDocProgramGroupData[];
135
+ id: number;
136
+ catalogKey: string | null;
137
+ organizationId: number | bigint | null; // Custom programs only: the owner organization
138
+ categoryKey: FieldDocCategoryKey;
139
+ name: string;
140
+ shortName?: string | null;
141
+ description?: string | null;
142
+ layout?: FieldDocProgramLayoutObj | null;
143
+ contentHash?: string | null; // Catalog sync hash of the program's catalog content
144
+ retiredAt?: Date | null; // Catalog programs removed from the catalog
145
+ operations?: string[]; // Attached from field_doc_program_operations (catalog programs only)
146
+ createdAt?: Date;
147
+ updatedAt?: Date;
148
+ }
149
+
150
+ // One organization's enrollment in one program; archived enrollments are restorable until purged
151
+ export interface FieldDocEnrollmentData {
152
+ __table: 'field_doc_program_enrollments';
153
+ organizationId: number | bigint;
154
+ programId: number;
155
+ enrolledByAccountId?: number | bigint | null;
156
+ archivedAt: Date | null; // Set by unenroll; purged after TRASH_BIN_RETENTION_DAYS
157
+ pausedWorkflowIds: (number | bigint)[]; // Managed workflows unenroll paused; restore resumes exactly these
158
+ createdAt: Date;
159
+ updatedAt: Date;
160
+ program?: FieldDocProgramData; // Attached by enrollment readers
161
+ forms?: FieldDocFormData[]; // Program docs plus this organization's custom docs in the program; retired and draft-only included
162
+ }
163
+
164
+ // One form of an enrollment, with the editor state the program page and pickers list
165
+ export interface FieldDocFormData extends FieldDocData {
166
+ // Present only on organization-scoped enrollment reads; excluded from the shared FieldDoc GraphQL type.
167
+ lastSubmissionUpdatedAt?: Date | null;
168
+ hasDraft: boolean;
169
+ draftTitle: string | null; // The draft's title when a draft exists
170
+ publishedRevisionNumber: number | null; // Null until the form's first publication
171
+ }
172
+
173
+ // Per-key custom instructions of one organization for one program doc (field_doc_custom_instructions)
174
+ export interface FieldDocCustomInstructionData {
175
+ __table: 'field_doc_custom_instructions';
176
+ organizationId: number | bigint;
177
+ fieldDocId: number | bigint;
178
+ elementKey: string; // An element key of the doc, or FIELD_DOC_DOCUMENT_INSTRUCTIONS_KEY for the doc-level agentHint
179
+ instructions: string;
180
+ updatedByAccountId?: number | bigint | null;
181
+ updatedAt: Date;
182
+ }
183
+
184
+ /**
185
+ * FieldDoc data
186
+ */
187
+
188
+ export interface FieldDocData {
189
+ __table: 'field_docs';
190
+ groupId?: number | bigint | null;
191
+ group?: FieldDocProgramGroupData | null;
192
+
193
+ id: number;
194
+ programId: number;
195
+ program?: FieldDocProgramData | null; // Attached when the reader joins field_doc_programs
196
+ // Custom docs: the owner organization. Null for program docs. Every field_docs field list selects it (isProgramFieldDoc).
197
+ organizationId: number | bigint | null;
198
+ catalogKey?: string | null; // Program docs only
199
+ catalogContentHash?: string | null; // Catalog sync hash of the doc's catalog content
200
+ documentName: string;
201
+ title: string;
202
+ description: string;
203
+ agentHint?: string | null; // On overlaid docs, the program agentHint composed with the owner org's custom instructions
204
+ programAgentHint?: string | null; // Overlaid docs only: the published agentHint before composition
205
+ agentHintCustomInstructions?: string | null; // Overlaid docs only: the owner org's doc-level custom instructions
206
+ frequency: FieldDocFrequencyEnum;
207
+ order: number;
208
+ publishedDefinitionRevisionId?: number | bigint | null;
209
+ definitionRevisionId?: number | bigint | null;
210
+ definitionRevisionNumber?: number;
211
+ retiredAt?: Date | null; // Program docs removed from the catalog; no new submissions
212
+ archivedAt?: Date | null; // Custom docs only; purged after TRASH_BIN_RETENTION_DAYS
213
+
214
+ elements?: FieldDocElementData[]; // Attached by attachFieldDocElements() after fetching
215
+ submission?: FieldDocSubmissionData | null; // Present when field_doc_submissions was joined onto the fieldDoc row.
216
+
217
+ site?: Pick<OrganizationSiteData, 'id' | 'name'> | null;
218
+ childOrg?: OrganizationData;
219
+ organization?: OrganizationData;
220
+ }
221
+
222
+ export interface FieldDocSubmissionData {
223
+ __table: 'field_doc_submissions';
224
+ id: number;
225
+ childOrgId?: number | bigint | null;
226
+ siteId?: number | bigint | null;
227
+ fieldDoc?: Pick<FieldDocData, 'id' | 'frequency'> | null;
228
+ site?: Pick<OrganizationSiteData, 'id' | 'name'> | null;
229
+ childOrg?: OrganizationData;
230
+ organization?: OrganizationData;
231
+ organizationId: number;
232
+ fieldDocId: number;
233
+ period: Date; // YYYY-MM-DD in database, Date object in server via ORM
234
+ summary?: string | null; // At most FIELD_DOC_SUMMARY_MAX characters; every writer stores clampFieldDocSummary()
235
+ answers: FieldDocAnswers;
236
+ evidenceLogIds?: (number | bigint)[]; // Every logId cited in answers; maintained by a database trigger
237
+ definitionRevisionId?: number | bigint | null;
238
+ answerVersion?: number; // Current concurrency counter only; no answer snapshots
239
+ status?: FieldDocSubmissionStatusEnum | null; // The displayed grade, persisted at write time
240
+ // An explicit user grade takes precedence over all automatic answer grading.
241
+ statusOverride?: FieldDocSubmissionStatusEnum | null;
242
+ statusOverrideAccountId?: number | bigint | null;
243
+ statusOverrideAt?: Date | null;
244
+ // PER_INSTANCE forms only: the external job key (e.g. "dispatch:371289") and its lifecycle; null on periodic rows
245
+ instanceKey?: string | null;
246
+ instanceStatus?: FieldDocInstanceStatusEnum | null;
247
+ instanceClosedAt?: Date | null;
248
+ // The person whose action created the row; a PER_INSTANCE job is edited only by them or an org manager
249
+ createdByAccountId?: number | bigint | null;
250
+ activityAt: Date;
251
+ createdAt: Date;
252
+ updatedAt: Date;
253
+ }
254
+
255
+ // One submission list row: the submission joined to its pinned revision, doc, program, organizations and site (no answers)
256
+ export interface FieldDocSubmissionRow {
257
+ id: number | bigint;
258
+ fieldDocId: number | bigint;
259
+ programId: number;
260
+ programName: string;
261
+ programShortName: string | null;
262
+ isProgramDoc: boolean;
263
+ definitionRevisionId: number | bigint;
264
+ organizationId: number | bigint;
265
+ organizationName: string | null;
266
+ childOrgId: number | bigint | null;
267
+ childOrgName: string | null;
268
+ siteId: number | bigint | null;
269
+ location: string | null;
270
+ documentName: string; // From the pinned revision
271
+ title: string; // From the pinned revision
272
+ frequency: FieldDocFrequencyEnum; // From the pinned revision
273
+ period: string; // period::text (YYYY-MM-DD); never a Date, because deno-postgres binds Dates in local time
274
+ status: FieldDocSubmissionStatusEnum | null;
275
+ statusOverridden: boolean;
276
+ summary: string | null;
277
+ identifierHint: string | null;
278
+ instanceKey: string | null;
279
+ instanceStatus: FieldDocInstanceStatusEnum | null;
280
+ instanceClosedAt: Date | null;
281
+ activityAt: Date;
282
+ createdAt: Date;
283
+ updatedAt: Date;
284
+ }
285
+
286
+ // One submission document: the list row, the pinned raw definition with the stored answers, and the rendered aside.
287
+ // Org-agnostic (no custom-instruction overlay); the caller authorizes.
288
+ export interface FieldDocDocumentData {
289
+ submission: FieldDocSubmissionRow;
290
+ fieldDoc: FieldDocData; // The pinned revision with raw elements attached; fieldDoc.submission holds the stored answers
291
+ aside: FieldDocAsideBlockObj[];
292
+ }
293
+
294
+ /**
295
+ * FieldDoc GraphQL data
296
+ */
297
+
298
+ // Each key is null when absent from the program layout
299
+ export interface FieldDocProgramLayoutGQL {
300
+ columns: string[] | null;
301
+ headers: (string | null)[] | null;
302
+ gridLayoutStyle: string | null;
303
+ }
304
+
305
+ export interface FieldDocProgramGroupGQL {
306
+ id: string;
307
+ fieldDocProgramId: string;
308
+ name: string;
309
+ order: number;
310
+ }
311
+
312
+ // Org-agnostic; id = programId
313
+ export interface FieldDocProgramGQL {
314
+ groups: FieldDocProgramGroupGQL[];
315
+ id: string;
316
+ isCatalog: boolean;
317
+ name: string;
318
+ shortName: string | null;
319
+ description: string | null;
320
+ categoryKey: FieldDocCategoryKey;
321
+ operations: string[];
322
+ layout: FieldDocProgramLayoutGQL;
323
+ retired: boolean;
324
+ }
325
+
326
+ // Enrollment-local activity; fieldDocId references the shared form without normalizing this value into it.
327
+ export interface FieldDocSubmissionUpdateGQL {
328
+ fieldDocId: string;
329
+ lastSubmissionUpdatedAt: string | null;
330
+ }
331
+
332
+ // Per organization; id = "<orgGenericId>:<programGenericId>"
333
+ export interface FieldDocProgramEnrollmentGQL {
334
+ id: string;
335
+ organizationId: string;
336
+ program: FieldDocProgramGQL;
337
+ archivedAt: string | null; // ISO date string
338
+ restorableUntil: string | null; // ISO date string
339
+ forms: FieldDocGQL[];
340
+ fieldDocSubmissionUpdates: FieldDocSubmissionUpdateGQL[];
341
+ }
342
+
343
+ // The form; org-agnostic; id = fieldDocId
344
+ export interface FieldDocGQL {
345
+ group: FieldDocProgramGroupGQL | null;
346
+ order: number;
347
+ id: string;
348
+ fieldDocProgramId: string;
349
+ documentName: string;
350
+ title: string;
351
+ draftTitle: string | null;
352
+ description: string | null;
353
+ frequency: FieldDocFrequencyEnum;
354
+ isProgramDoc: boolean;
355
+ retired: boolean;
356
+ published: boolean;
357
+ publishedRevisionNumber: number | null;
358
+ hasDraft: boolean;
359
+ }
360
+
361
+ // id = submissionId; the one shared fragment for list rows and the document header
362
+ export interface FieldDocSubmissionGQL {
363
+ __deleted?: boolean;
364
+
365
+ id: string;
366
+ cursor: string;
367
+ readableId: string;
368
+ fieldDocId: string;
369
+ fieldDocProgramId: string;
370
+ programName: string;
371
+ programShortName: string | null;
372
+ isProgramDoc: boolean;
373
+ definitionRevisionId: string;
374
+ organizationId: string;
375
+ organizationName: string | null;
376
+ childOrgId: string | null;
377
+ childOrgName: string | null;
378
+ siteId: string | null;
379
+ location: string | null;
380
+ documentName: string;
381
+ title: string;
382
+ frequency: FieldDocFrequencyEnum;
383
+ period: string; // YYYY-MM-DD
384
+ status: FieldDocSubmissionStatusEnum | null;
385
+ statusOverridden: boolean;
386
+ summary: string | null;
387
+ identifierHint: string | null;
388
+ instanceKey: string | null;
389
+ instanceStatus: FieldDocInstanceStatusEnum | null;
390
+ instanceClosedAt: string | null; // ISO date string
391
+ activityAt: string; // ISO date string
392
+ createdAt: string; // ISO date string
393
+ updatedAt: string; // ISO date string
394
+ }
395
+
396
+ export interface FieldDocSubmissionMetadataGQL {
397
+ id: string;
398
+ title: string;
399
+ description: string | null;
400
+ }
401
+
402
+ // id = submissionId
403
+ export interface FieldDocSubmissionDocumentGQL {
404
+ id: string;
405
+ submission: FieldDocSubmissionGQL;
406
+ description: string | null;
407
+ definition: FieldDocDefinitionGQL;
408
+ answers: FieldDocAnswerGQL[]; // One entry per answer-bearing key, UNANSWERED included
409
+ aside: FieldDocAsideBlockGQL[];
410
+ }
411
+
412
+ export interface FieldDocAsideBlockGQL {
413
+ title: string | null;
414
+ nullText: string | null;
415
+ items: FieldDocAsideItemGQL[];
416
+ }
417
+
418
+ export interface FieldDocAsideItemGQL {
419
+ className: string | null;
420
+ label: string | null;
421
+ text: string | null;
422
+ }
423
+
424
+ // id = revisionId; immutable and carries no hints
425
+ export interface FieldDocDefinitionGQL {
426
+ id: string;
427
+ fieldDocId: string;
428
+ revisionNumber: number;
429
+ title: string;
430
+ description: string | null;
431
+ sections: FieldDocDefinitionSectionGQL[];
432
+ }
433
+
434
+ // id = getFieldDocDefinitionElementId(revisionGenericId, sectionKey)
435
+ export interface FieldDocDefinitionSectionGQL {
436
+ id: string;
437
+ key: string;
438
+ title: string | null;
439
+ description: string | null;
440
+ elements: FieldDocDefinitionElementGQL[];
441
+ }
442
+
443
+ // id = getFieldDocDefinitionElementId(revisionGenericId, key)
444
+ export interface FieldDocDefinitionElementGQL {
445
+ id: string;
446
+ key: string;
447
+ kind: FieldDocElementKindEnum;
448
+ label: string | null;
449
+ description: string | null;
450
+ options: string[] | null;
451
+ required: boolean;
452
+ allowMultipleAnswers: boolean;
453
+ doNotAllowNotes: boolean;
454
+ answerType: FieldDocAnswerType | null;
455
+ tableColumns: FieldDocTableColumnGQL[] | null;
456
+ lineNumber: string | null;
457
+ files?: StorageGQL[]; // Element images; the document query selects them beside the element fragment
458
+ }
459
+
460
+ // id = getFieldDocAnswerId(submissionGenericId, key)
461
+ export interface FieldDocAnswerGQL {
462
+ id: string;
463
+ key: string;
464
+ text: string | null; // The formatted answer value
465
+ tableRows: FieldDocTableRowGQL[] | null; // Null when the answer is incompatible with the pinned columns (show text)
466
+ answerState: FieldDocAnswerState;
467
+ answerReason: string | null;
468
+ note: string | null;
469
+ warningNote: string | null;
470
+ referenceIds: string[];
471
+ }
472
+
473
+ export interface FieldDocTableColumnGQL {
474
+ key: string;
475
+ label: string;
476
+ type: FieldDocScalarAnswerType;
477
+ required?: boolean | null;
478
+ options?: string[] | null;
479
+ }
480
+
481
+ export interface FieldDocTableRowGQL {
482
+ id: string;
483
+ cells: FieldDocTableCellGQL[];
484
+ }
485
+
486
+ export interface FieldDocTableCellGQL {
487
+ key: string;
488
+ text: string | null;
489
+ isCustomBooleanLabel?: boolean | null; // Authored labels remain literal, including labels spelled Yes or No
490
+ }
491
+
492
+ /**
493
+ * FieldDoc program mutations (GraphQL input shapes)
494
+ */
495
+
496
+ export interface CreateFieldDocProgramInputObj {
497
+ organizationId: string;
498
+ name: string;
499
+ shortName?: string | null;
500
+ description?: string | null;
501
+ categoryKey: FieldDocCategoryKey;
502
+ }
503
+
504
+ // Custom programs only; omitted keys keep their values
505
+ export interface EditFieldDocProgramInputObj {
506
+ organizationId: string;
507
+ fieldDocProgramId: string;
508
+ name?: string | null;
509
+ shortName?: string | null;
510
+ description?: string | null;
511
+ categoryKey?: FieldDocCategoryKey | null;
512
+ }
513
+
514
+ // Null or blank instructions delete the key's instructions
515
+ export interface FieldDocCustomInstructionInputObj {
516
+ elementKey: string; // An element key, or FIELD_DOC_DOCUMENT_INSTRUCTIONS_KEY
517
+ instructions?: string | null;
518
+ }
519
+
520
+ export interface EditFieldDocCustomInstructionsInputObj {
521
+ organizationId: string;
522
+ fieldDocId: string;
523
+ items: FieldDocCustomInstructionInputObj[];
524
+ }
525
+
526
+ /**
527
+ * FieldDoc web editor (draft and publication)
528
+ */
529
+
530
+ // DEFINITION edits a custom doc's draft or publication; CUSTOM_INSTRUCTIONS edits an organization's instructions for a program doc
531
+ export type FieldDocEditSessionModeEnum = 'DEFINITION' | 'CUSTOM_INSTRUCTIONS';
532
+ export type FieldDocEditorElementKindEnum = Exclude<FieldDocElementKindEnum, 'SECTION'>;
533
+
534
+ // One question-side element of an editor definition; the same shape as the authoring draft contract
535
+ export interface FieldDocEditorElementObj {
536
+ key: string;
537
+ kind: FieldDocEditorElementKindEnum;
538
+ label?: string | null;
539
+ description?: string | null;
540
+ hint?: string | null;
541
+ options?: string[] | null;
542
+ required: boolean;
543
+ settings?: FieldDocElementSettingsObj | null;
544
+ }
545
+
546
+ export interface FieldDocEditorSectionObj {
547
+ key: string;
548
+ label?: string | null;
549
+ description?: string | null;
550
+ hint?: string | null;
551
+ elements: FieldDocEditorElementObj[];
552
+ }
553
+
554
+ // The editable definition: the draft snapshot when one exists, otherwise the current publication
555
+ export interface FieldDocEditorDefinitionObj {
556
+ // Tool-authored metadata stays in the shared draft until publication; frontend patches preserve it.
557
+ documentName?: string;
558
+ frequency?: FieldDocFrequencyEnum;
559
+ title: string;
560
+ description?: string | null;
561
+ agentHint?: string | null;
562
+ sections: FieldDocEditorSectionObj[];
563
+ }
564
+
565
+ // Stored in field_doc_drafts.snapshot
566
+ export interface FieldDocDraftSnapshotObj extends FieldDocEditorDefinitionObj {
567
+ schemaVersion: 1;
568
+ }
569
+
570
+ export interface FieldDocDraftData {
571
+ __table?: 'field_doc_drafts';
572
+ fieldDocId: number | bigint;
573
+ editVersion: number | bigint; // Database-allocated token; never repeats when a draft is discarded and recreated
574
+ baseRevisionId: number | bigint | null; // Null until the form's first publication
575
+ createKey?: string | null; // Retried tool creation keeps one form; transferred to its first publication
576
+ snapshot: FieldDocDraftSnapshotObj;
577
+ updatedByAccountId?: number | bigint | null;
578
+ updatedAt: Date;
579
+ }
580
+
581
+ // id = "<orgGenericId>:<fieldDocGenericId>"
582
+ export interface FieldDocEditorSourceGQL {
583
+ group: FieldDocProgramGroupGQL | null;
584
+ order: number;
585
+ id: string;
586
+ fieldDocId: string;
587
+ organizationId: string;
588
+ fieldDocProgramId: string;
589
+ isProgramDoc: boolean;
590
+ documentName: string;
591
+ frequency: FieldDocFrequencyEnum;
592
+ editVersion: number; // 0 when the form has no draft
593
+ hasDraft: boolean;
594
+ draftStale: boolean; // A newer definition was published after the draft started
595
+ publishedRevisionNumber?: number | null;
596
+ draftUpdatedAt?: string | null;
597
+ }
598
+
599
+ // DEFINITION: the draft or publication; CUSTOM_INSTRUCTIONS: the publication with raw program hints
600
+ export interface FieldDocEditorGQL {
601
+ definition: FieldDocEditorDefinitionObj;
602
+ }
603
+
604
+ export interface FieldDocCustomInstructionGQL {
605
+ elementKey: string; // An element key, or FIELD_DOC_DOCUMENT_INSTRUCTIONS_KEY
606
+ instructions: string;
607
+ updatedAt: string | null; // ISO date string
608
+ }
609
+
610
+ // id = "<orgGenericId>:<fieldDocGenericId>"
611
+ export interface FieldDocEditSessionGQL {
612
+ id: string;
613
+ organizationId: string;
614
+ mode: FieldDocEditSessionModeEnum;
615
+ fieldDoc: FieldDocEditorSourceGQL;
616
+ editor: FieldDocEditorGQL;
617
+ customInstructions: FieldDocCustomInstructionGQL[];
618
+ manageable: boolean;
619
+ }
620
+
621
+ export interface FieldDocDefinitionSectionInputObj {
622
+ key: string;
623
+ order: number;
624
+ label: string;
625
+ description?: string | null;
626
+ hint?: string | null;
627
+ }
628
+
629
+ export interface FieldDocDefinitionQuestionInputObj {
630
+ key: string;
631
+ parentKey: string;
632
+ order: number;
633
+ kind: FieldDocEditorElementKindEnum;
634
+ label?: string | null;
635
+ description?: string | null;
636
+ hint?: string | null;
637
+ options?: string[] | null;
638
+ required?: boolean | null;
639
+ settings?: FieldDocElementSettingsObj | null;
640
+ }
641
+
642
+ export type FieldDocDefinitionNodeInputObj =
643
+ | { section: FieldDocDefinitionSectionInputObj; question?: never }
644
+ | { question: FieldDocDefinitionQuestionInputObj; section?: never };
645
+
646
+ export interface FieldDocDefinitionPatchInputObj {
647
+ upsertNodes?: FieldDocDefinitionNodeInputObj[] | null;
648
+ deleteNodeKeys?: string[] | null;
649
+ }
650
+
651
+ export interface FieldDocEditorMetadataPatchInputObj {
652
+ title?: string | null;
653
+ description?: string | null;
654
+ agentHint?: string | null;
655
+ }
656
+
657
+ export interface FieldDocEditorPatchInputObj {
658
+ metadata?: FieldDocEditorMetadataPatchInputObj | null;
659
+ definition?: FieldDocDefinitionPatchInputObj | null;
660
+ }
661
+
662
+ export interface EditFieldDocInputObj {
663
+ organizationId: string;
664
+ fieldDocId: string;
665
+ expectedEditVersion: number; // 0 creates the draft from the current publication
666
+ patch: FieldDocEditorPatchInputObj;
667
+ }
668
+
669
+ export type FieldDocSettingsCommandInputObj =
670
+ | { publish: { expectedEditVersion: number }; resetDraft?: never }
671
+ | { resetDraft: { expectedEditVersion: number }; publish?: never };
672
+
673
+ export interface EditFieldDocSettingsInputObj {
674
+ organizationId: string;
675
+ fieldDocId: string;
676
+ command: FieldDocSettingsCommandInputObj;
677
+ }
678
+
679
+ /**
680
+ * Program grouping and form placement (independent of definition publication).
681
+ */
682
+ export interface CreateFieldDocProgramGroupInputObj {
683
+ organizationId: string;
684
+ fieldDocProgramId: string;
685
+ name: string;
686
+ order?: number | null;
687
+ }
688
+
689
+ export interface EditFieldDocProgramGroupInputObj {
690
+ organizationId: string;
691
+ groupId: string;
692
+ name?: string | null;
693
+ order?: number | null;
694
+ }
695
+
696
+ export interface EditFieldDocPlacementInputObj {
697
+ organizationId: string;
698
+ fieldDocId: string;
699
+ // Omitted preserves placement; explicit null ungroups the form.
700
+ groupId?: string | null;
701
+ order?: number | null;
702
+ }