@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,257 @@
1
+ import type {
2
+ DT_COLUMN_ORIGIN_ENUMS,
3
+ DT_COLUMN_TYPES,
4
+ DT_CONDITION_OPERATOR_ENUMS,
5
+ DT_COVERAGE_WARNING_CODE_ENUMS,
6
+ DT_DATE_BUCKET_ENUMS,
7
+ DT_DERIVE_PAUSE_REASON_ENUMS,
8
+ DT_DERIVED_BY_ENUMS,
9
+ DT_ENTITY_ENUMS,
10
+ DT_GRAIN_ENUMS,
11
+ DT_METRIC_FN_ENUMS,
12
+ DT_QUERY_DISPLAY_ENUMS,
13
+ DT_RELATIVE_DATE_ENUMS,
14
+ DT_RUN_CAUSE_ENUMS,
15
+ DT_SCOPE_TYPE_ENUMS,
16
+ DT_SORT_DIRECTION_ENUMS,
17
+ DT_SOURCE_ENUMS,
18
+ DT_SYNC_STATE_ENUMS,
19
+ DT_TABLE_KIND_ENUMS,
20
+ DT_VISIBILITY_ENUMS,
21
+ } from '../constants/dt.ts';
22
+
23
+ export type DtTableKindEnum = (typeof DT_TABLE_KIND_ENUMS)[number];
24
+ export type DtSourceEnum = (typeof DT_SOURCE_ENUMS)[number];
25
+ export type DtGrainEnum = (typeof DT_GRAIN_ENUMS)[number];
26
+ export type DtVisibilityEnum = (typeof DT_VISIBILITY_ENUMS)[number];
27
+ export type DtSyncStateEnum = (typeof DT_SYNC_STATE_ENUMS)[number];
28
+ export type DtColumnOriginEnum = (typeof DT_COLUMN_ORIGIN_ENUMS)[number];
29
+ export type DtRunCauseEnum = (typeof DT_RUN_CAUSE_ENUMS)[number];
30
+ export type DtDerivePauseReasonEnum = (typeof DT_DERIVE_PAUSE_REASON_ENUMS)[number];
31
+ export type DtCoverageWarningCodeEnum = (typeof DT_COVERAGE_WARNING_CODE_ENUMS)[number];
32
+ export type DtDerivedByEnum = (typeof DT_DERIVED_BY_ENUMS)[number];
33
+ export type DtQueryDisplayEnum = (typeof DT_QUERY_DISPLAY_ENUMS)[number];
34
+ export type DtEntityEnum = (typeof DT_ENTITY_ENUMS)[number];
35
+ export type DtScopeTypeEnum = (typeof DT_SCOPE_TYPE_ENUMS)[number];
36
+ export type DtConditionOperatorEnum = (typeof DT_CONDITION_OPERATOR_ENUMS)[number];
37
+ export type DtRelativeDateEnum = (typeof DT_RELATIVE_DATE_ENUMS)[number];
38
+ export type DtDateBucketEnum = (typeof DT_DATE_BUCKET_ENUMS)[number];
39
+ export type DtMetricFnEnum = (typeof DT_METRIC_FN_ENUMS)[number];
40
+ export type DtSortDirectionEnum = (typeof DT_SORT_DIRECTION_ENUMS)[number];
41
+ export type DtColumnType = (typeof DT_COLUMN_TYPES)[number];
42
+
43
+ /**
44
+ * Source path of a SOURCE column in a LOGS table: a log registry field, or a
45
+ * log metadata field.
46
+ */
47
+ export type DtLogColumnPath = { kind: 'LOG_FIELD'; field: string } | { kind: 'LOG_META'; field: string };
48
+
49
+ /**
50
+ * One campaign's question bound to a form answer column. Element keys are
51
+ * reused with different labels across campaigns, so a column binds per
52
+ * campaign, by key and label, and never merges answers by key alone.
53
+ */
54
+ export interface DtCampaignAnswerBinding {
55
+ campaignId: string;
56
+ elementKey: string;
57
+ label: string;
58
+ }
59
+
60
+ /**
61
+ * Source path of a SOURCE column in a CAMPAIGN_RESPONSES table: an answer with
62
+ * its per-campaign bindings, or a response metadata field.
63
+ */
64
+ export type DtCampaignResponseColumnPath =
65
+ | { kind: 'ANSWER'; bindings: DtCampaignAnswerBinding[] }
66
+ | { kind: 'RESPONSE_META'; field: string };
67
+
68
+ /**
69
+ * Source path of a SOURCE column in a CAMPAIGN_RECIPIENTS table.
70
+ */
71
+ export type DtCampaignRecipientColumnPath = { kind: 'RECIPIENT_META'; field: string };
72
+
73
+ /**
74
+ * Source path of a SOURCE column in a FIELD_DOC_SUBMISSIONS table: an answer
75
+ * (one column of a TABLE answer when "tableColumnKey" is set), or a submission
76
+ * metadata field.
77
+ */
78
+ export type DtFieldDocColumnPath =
79
+ | { kind: 'FIELD_DOC_ANSWER'; elementKey: string; tableColumnKey?: string }
80
+ | { kind: 'SUBMISSION_META'; field: string };
81
+
82
+ export type DtColumnPath = DtLogColumnPath | DtCampaignResponseColumnPath | DtCampaignRecipientColumnPath | DtFieldDocColumnPath;
83
+
84
+ /**
85
+ * One column definition in dt_tables.columns. "key" is an immutable slug and
86
+ * "label" is editable; retired columns keep their data. SOURCE columns carry
87
+ * "path"; DERIVED columns carry "instructions" and "inputKeys"; AGENT columns
88
+ * may carry "instructions" (how row writes fill them). "unit" is the
89
+ * key of the companion column holding each row's unit, "currency" an ISO 4217
90
+ * code, "options" the choices of a select column, and "entity" the kind of id
91
+ * an ENTITY column stores.
92
+ */
93
+ export interface DtColumnDef {
94
+ key: string;
95
+ label: string;
96
+ type: DtColumnType;
97
+ origin: DtColumnOriginEnum;
98
+ path?: DtColumnPath;
99
+ instructions?: string;
100
+ inputKeys?: string[];
101
+ unit?: string;
102
+ currency?: string;
103
+ options?: string[];
104
+ entity?: DtEntityEnum;
105
+ retiredAt?: string | null;
106
+ }
107
+
108
+ /**
109
+ * One source scope of a SOURCE table, or of a query on a source.
110
+ */
111
+ export interface DtScopeRef {
112
+ scopeType: DtScopeTypeEnum;
113
+ scopeId: string;
114
+ }
115
+
116
+ /**
117
+ * One canonical cell value: cells are {columnKey: canonical scalar}.
118
+ */
119
+ export type DtCellScalar = string | number | boolean | null;
120
+
121
+ /**
122
+ * A relative date window, resolved in the organization time zone when the
123
+ * query runs. "n" is the day count of LAST_N_DAYS.
124
+ */
125
+ export interface DtRelativeDate {
126
+ rel: DtRelativeDateEnum;
127
+ n?: number;
128
+ }
129
+
130
+ /**
131
+ * A condition value: one scalar or relative date, a list for IN and NOT_IN,
132
+ * or [from, to] for BETWEEN. IS_EMPTY and IS_NOT_EMPTY take none.
133
+ */
134
+ export type DtCondValue = string | number | boolean | DtRelativeDate | Array<string | number | boolean | DtRelativeDate>;
135
+
136
+ /**
137
+ * One query condition on a column.
138
+ */
139
+ export interface DtCond {
140
+ col: string;
141
+ op: DtConditionOperatorEnum;
142
+ value?: DtCondValue;
143
+ }
144
+
145
+ /**
146
+ * What a query reads: one table, or a source with scopes, which resolves to
147
+ * that source's INTERNAL table.
148
+ */
149
+ export type DtQueryFrom = { tableId: string } | { source: Exclude<DtSourceEnum, 'CAMPAIGN_RECIPIENTS'>; scopes: DtScopeRef[] };
150
+
151
+ /**
152
+ * The one query spec used by notes, chat, workflows and CSV export
153
+ * (DATA-TABLES.md §5). "latestBy" keeps the newest row per key set; list
154
+ * sizes and "limit" are capped by DT_LIMITS.
155
+ */
156
+ export interface DtQuerySpec {
157
+ v: 1;
158
+ from: DtQueryFrom;
159
+ where?: { all?: DtCond[]; any?: DtCond[] };
160
+ latestBy?: { keys: string[]; orderBy: string };
161
+ groupBy?: Array<{ col: string; bucket?: DtDateBucketEnum }>;
162
+ metrics?: Array<{ name: string; fn: DtMetricFnEnum; col?: string }>;
163
+ select?: string[];
164
+ sort?: Array<{ col: string; dir: DtSortDirectionEnum }>;
165
+ limit?: number;
166
+ cursor?: string;
167
+ }
168
+
169
+ /**
170
+ * One column of a query result: a table column, a group key or a metric.
171
+ * "origin" is null for metrics.
172
+ */
173
+ export interface DtResultColumn {
174
+ key: string;
175
+ label: string;
176
+ type: DtColumnType;
177
+ unit: string | null;
178
+ currency: string | null;
179
+ origin: DtColumnOriginEnum | null;
180
+ }
181
+
182
+ /**
183
+ * One result row, group or totals record, keyed by result column key. Row
184
+ * records also carry two reserved keys that are not in "columns": "$key" (the
185
+ * row key) and "$ref" (the readable id of the source record, or null).
186
+ */
187
+ export type DtResultRecord = Record<string, DtCellScalar>;
188
+
189
+ /**
190
+ * A query result at one table revision. Overflow sets "truncated" and keeps
191
+ * the full "matched" count. "nextBoundaryAt" is the next instant at which a
192
+ * relative date window moves.
193
+ */
194
+ export interface DtQueryResult {
195
+ revision: string;
196
+ columns: DtResultColumn[];
197
+ rows?: DtResultRecord[];
198
+ groups?: DtResultRecord[];
199
+ totals?: DtResultRecord;
200
+ matched: number;
201
+ truncated: boolean;
202
+ nextBoundaryAt: string | null;
203
+ }
204
+
205
+ /**
206
+ * One projection gap of a table (dt_tables."coverageWarnings"), shown by
207
+ * evidence and the viewer. "columnKey" is the affected column; "campaignId"
208
+ * names the campaign (CAMPAIGN_UNBOUND, or the binding whose question went
209
+ * away) and "fieldDocId" the field doc whose definition dropped the question.
210
+ * "at" is when the gap was first found.
211
+ */
212
+ export interface DtCoverageWarning {
213
+ code: DtCoverageWarningCodeEnum;
214
+ columnKey: string;
215
+ campaignId?: string;
216
+ fieldDocId?: string;
217
+ message: string;
218
+ at: string;
219
+ }
220
+
221
+ /**
222
+ * One dt_tables row.
223
+ */
224
+ export interface DtTableData {
225
+ __table?: 'dt_tables';
226
+ id: bigint;
227
+ organizationId: bigint;
228
+ kind: DtTableKindEnum;
229
+ source: DtSourceEnum | null;
230
+ grain: DtGrainEnum;
231
+ visibility: DtVisibilityEnum;
232
+ title: string;
233
+ description: string | null;
234
+ columns: DtColumnDef[];
235
+ keyColumns: string[];
236
+ ownerNoteId: bigint | null;
237
+ specFingerprint: Uint8Array | null;
238
+ schemaVersion: number;
239
+ revision: bigint;
240
+ rowCount: number;
241
+ coverageStartsAt: Date | null;
242
+ includeVoided: boolean;
243
+ syncState: DtSyncStateEnum;
244
+ syncError: string | null;
245
+ backfillCursor: string | null;
246
+ syncedAt: Date | null;
247
+ reprojectedAt: Date | null;
248
+ derivePausedAt: Date | null;
249
+ derivePauseReason: DtDerivePauseReasonEnum | null;
250
+ createdByAccountId: bigint | null;
251
+ coverageWarnings?: DtCoverageWarning[];
252
+ unreferencedAt?: Date | null;
253
+ archivedAt: Date | null;
254
+ archiveReason: string | null;
255
+ createdAt: Date;
256
+ updatedAt: Date;
257
+ }
@@ -1,8 +1,13 @@
1
1
  import type {
2
+ EMAIL_DIRECTION_ENUMS,
3
+ EMAIL_MESSAGE_KIND_ENUMS,
4
+ EMAIL_MESSAGE_SORT_ENUMS,
5
+ EMAIL_MESSAGE_STATUS_ENUMS,
2
6
  EMAIL_STATUS_ENUMS,
7
+ EMAIL_STATUS_GROUP_ENUMS,
3
8
  INBOUND_EMAIL_BODY_FORMAT_ENUMS,
4
- INBOUND_EMAIL_SORT_ENUMS,
5
- OUTBOUND_EMAIL_SORT_ENUMS,
9
+ INBOUND_EMAIL_KIND_ENUMS,
10
+ OUTBOUND_EMAIL_KIND_ENUMS,
6
11
  OUTBOUND_EMAIL_STATUS_ENUMS,
7
12
  } from '../constants/email.ts';
8
13
  import type { StorageGQL } from './storage.d.ts';
@@ -13,26 +18,89 @@ import type { StorageGQL } from './storage.d.ts';
13
18
  export type EmailStatusEnum = (typeof EMAIL_STATUS_ENUMS)[number];
14
19
 
15
20
  /**
16
- * Inbound email list sort.
21
+ * Outbound email delivery status.
17
22
  */
18
- export type InboundEmailsSortEnum = (typeof INBOUND_EMAIL_SORT_ENUMS)[number];
23
+ export type OutboundEmailStatusEnum = (typeof OUTBOUND_EMAIL_STATUS_ENUMS)[number];
19
24
 
20
25
  /**
21
- * Outbound email delivery status.
26
+ * Email message direction.
27
+ */
28
+ export type EmailDirectionEnum = (typeof EMAIL_DIRECTION_ENUMS)[number];
29
+
30
+ /**
31
+ * What sent one outbound email.
32
+ */
33
+ export type OutboundEmailKindEnum = (typeof OUTBOUND_EMAIL_KIND_ENUMS)[number];
34
+
35
+ /**
36
+ * What one inbound email is.
37
+ */
38
+ export type InboundEmailKindEnum = (typeof INBOUND_EMAIL_KIND_ENUMS)[number];
39
+
40
+ /**
41
+ * Email message kind across both directions.
42
+ */
43
+ export type EmailMessageKindEnum = (typeof EMAIL_MESSAGE_KIND_ENUMS)[number];
44
+
45
+ /**
46
+ * Email message status across both directions.
22
47
  */
23
- export type OutboundEmailStatusEnum =
24
- (typeof OUTBOUND_EMAIL_STATUS_ENUMS)[number];
48
+ export type EmailMessageStatusEnum = (typeof EMAIL_MESSAGE_STATUS_ENUMS)[number];
25
49
 
26
50
  /**
27
- * Outbound email list sort.
51
+ * Direction-neutral email status bucket.
28
52
  */
29
- export type OutboundEmailsSortEnum = (typeof OUTBOUND_EMAIL_SORT_ENUMS)[number];
53
+ export type EmailStatusGroupEnum = (typeof EMAIL_STATUS_GROUP_ENUMS)[number];
54
+
55
+ /**
56
+ * Email message list sort.
57
+ */
58
+ export type EmailMessagesSortEnum = (typeof EMAIL_MESSAGE_SORT_ENUMS)[number];
59
+
60
+ /*
61
+ * Shared email list input for GraphQL hooks and server filter normalization.
62
+ * Address filters are exact and case-insensitive; subject and query match text.
63
+ * Delivery and open observations apply only to outbound emails, even when false.
64
+ */
65
+ export interface EmailMessagesFilterInput {
66
+ startDate?: string | null;
67
+ endDate?: string | null;
68
+ query?: string | null;
69
+ directions?: EmailDirectionEnum[] | null;
70
+ kinds?: EmailMessageKindEnum[] | null;
71
+ statusGroups?: EmailStatusGroupEnum[] | null;
72
+ statuses?: EmailMessageStatusEnum[] | null;
73
+ campaignId?: string | null;
74
+ emailAddress?: string | null;
75
+ fromEmail?: string | null;
76
+ toEmail?: string | null;
77
+ subject?: string | null;
78
+ delivered?: boolean | null;
79
+ opened?: boolean | null;
80
+ }
30
81
 
31
82
  /**
32
83
  * Inbound email display body source.
33
84
  */
34
- export type InboundEmailBodyFormatEnum =
35
- (typeof INBOUND_EMAIL_BODY_FORMAT_ENUMS)[number];
85
+ export type InboundEmailBodyFormatEnum = (typeof INBOUND_EMAIL_BODY_FORMAT_ENUMS)[number];
86
+
87
+ /**
88
+ * One immutable PDF attachment rendered from a log before an outbound email is queued.
89
+ */
90
+ export interface OutboundEmailRenderedLogAttachment {
91
+ name: string;
92
+ contentType: 'application/pdf';
93
+ contentBase64: string;
94
+ }
95
+
96
+ /**
97
+ * Immutable log-derived email content saved before asynchronous delivery.
98
+ */
99
+ export interface OutboundEmailRenderedLogSnapshot {
100
+ version: 'outbound-email-rendered-log:v1';
101
+ contentHTML: string;
102
+ attachments: OutboundEmailRenderedLogAttachment[];
103
+ }
36
104
 
37
105
  /**
38
106
  * Saved inbound email database row.
@@ -55,26 +123,21 @@ export interface InboundEmailData {
55
123
  receivedAt: Date;
56
124
  }
57
125
 
58
- /**
59
- * GraphQL inbound email record.
126
+ /*
127
+ * Persisted outbound content, excluding regenerated campaign HTML.
60
128
  */
61
- export interface InboundEmailGQL {
62
- __deleted?: boolean;
63
- id: string;
64
- cursor: string;
65
- organizationId: string;
66
- recipientEmail: string;
67
- senderEmail: string | null;
68
- subject: string | null;
69
- postmarkMessageId: string | null;
70
- status: EmailStatusEnum;
71
- statusSummary: string | null;
72
- previewText: string;
73
- bodyFormat: InboundEmailBodyFormatEnum | null;
74
- bodyText: string;
75
- receivedAt: string;
76
- processingStartedAt: string | null;
77
- processingCompletedAt: string | null;
129
+ export interface OutboundEmailPayload {
130
+ cc?: string[];
131
+ fromEmail?: string | null;
132
+ fromName?: string | null;
133
+ toName?: string | null;
134
+ subject: string;
135
+ body: string;
136
+ replyTo: { email: string | null; name: string | null };
137
+ replyHeaders: { Name: string; Value: string }[];
138
+ renderedLogSnapshot?: OutboundEmailRenderedLogSnapshot | null;
139
+ trackOpens: boolean;
140
+ legacySpamScore?: number;
78
141
  }
79
142
 
80
143
  /**
@@ -84,21 +147,24 @@ export interface OutboundEmailData {
84
147
  __table?: 'emails_outbound';
85
148
  id: bigint;
86
149
  organizationId: bigint;
87
- campaignTemplateId: bigint | null;
150
+ workflowRunStateId?: bigint | null;
151
+ originatingWorkflowRunId?: bigint | null;
88
152
  campaignId: bigint | null;
89
153
  campaignRecipientId: bigint | null;
90
154
  sendBatchId: string | null;
91
155
  replyToken: string | null;
92
156
  sourceInboundEmailId: bigint | null;
93
157
  idempotencyKey: string;
158
+ kind: OutboundEmailKindEnum;
94
159
  toEmail: string;
95
- replyToEmail: string | null;
96
- replyToName: string | null;
97
- subject: string;
98
- body: string;
99
- bodyHTML: string | null;
100
- replyHeaders: { Name: string; Value: string }[] | null;
160
+ payload: OutboundEmailPayload;
101
161
  status: OutboundEmailStatusEnum;
162
+ deliveryRetryAfter?: Date | string | null;
163
+ deliveryLeaseId: string | null;
164
+ deliveryClaimedAt: Date | null;
165
+ postmarkAttemptId: string | null;
166
+ postmarkSubmissionStartedAt: Date | null;
167
+ postmarkReconcileAfter: Date | null;
102
168
  postmarkMessageId: string | null;
103
169
  errorMessage: string | null;
104
170
  sentAt: Date | null;
@@ -107,7 +173,7 @@ export interface OutboundEmailData {
107
173
  bouncedAt: Date | null;
108
174
  bounceType: string | null;
109
175
  spamComplaintAt: Date | null;
110
- spamScore: number | null;
176
+ suppressionReason: string | null;
111
177
  broadcast: boolean;
112
178
  createdAt: Date;
113
179
  updatedAt: Date;
@@ -116,27 +182,50 @@ export interface OutboundEmailData {
116
182
  }
117
183
 
118
184
  /**
119
- * GraphQL outbound email record.
185
+ * GraphQL email message record; one inbound or outbound email.
120
186
  */
121
- export interface OutboundEmailGQL {
187
+ export interface EmailMessageGQL {
122
188
  __deleted?: boolean;
123
189
  id: string;
124
190
  cursor: string;
125
191
  organizationId: string;
126
- sourceInboundEmailId: string | null;
127
- toEmail: string;
128
- replyToEmail: string | null;
129
- replyToName: string | null;
130
- subject: string;
131
- body: string;
132
- status: OutboundEmailStatusEnum;
192
+ direction: EmailDirectionEnum;
193
+ kind: EmailMessageKindEnum;
194
+ status: EmailMessageStatusEnum;
195
+ statusGroup: EmailStatusGroupEnum;
196
+ statusDetail: string | null;
197
+ fromEmail: string | null;
198
+ fromName: string | null;
199
+ toEmail: string | null;
200
+ toName: string | null;
201
+ subject: string | null;
202
+ previewText: string | null;
133
203
  postmarkMessageId: string | null;
134
- errorMessage: string | null;
135
- sentAt: string | null;
136
- bouncedAt: string | null;
137
- broadcast: boolean;
138
- createdAt: string;
139
- updatedAt: string;
140
- relatedLogIds: string[];
141
- files: StorageGQL[];
204
+ campaignId: string | null;
205
+ relatedEmailMessageId: string | null;
206
+ occurredAt: string;
207
+
208
+ // Details (email message modal)
209
+ cc?: string | null;
210
+ bodyText?: string | null;
211
+ files?: StorageGQL[];
212
+
213
+ // Inbound only
214
+ bodyFormat?: InboundEmailBodyFormatEnum | null;
215
+ processingStartedAt?: string | null;
216
+ processingCompletedAt?: string | null;
217
+
218
+ // Outbound only
219
+ replyToEmail?: string | null;
220
+ replyToName?: string | null;
221
+ suppressionReason?: string | null;
222
+ sentAt?: string | null;
223
+ deliveredAt?: string | null;
224
+ firstOpenedAt?: string | null;
225
+ bouncedAt?: string | null;
226
+ bounceType?: string | null;
227
+ spamComplaintAt?: string | null;
228
+ broadcast?: boolean | null;
229
+ relatedLogIds?: string[];
230
+ updatedAt?: string | null;
142
231
  }
@@ -0,0 +1,76 @@
1
+ export type EmailCampaignReplyAvailability = 'READY' | 'NO_DEFINITION' | 'TOO_LARGE';
2
+ export type EmailCampaignReplyAnswerStatus = 'ANSWERED' | 'UNCLEAR' | 'WITHDRAWN';
3
+ export type EmailCampaignReplyCaptureState = 'CAPTURED' | 'PROCESSING' | 'NOT_CAPTURED';
4
+
5
+ export interface EmailCampaignReplyCoverageGQL {
6
+ linkedReplyCount: number;
7
+ spamReplyCount: number;
8
+ nonRecipientReplyCount: number;
9
+ replyCount: number;
10
+ respondentCount: number;
11
+ capturedReplyCount: number;
12
+ capturedRespondentCount: number;
13
+ processingReplyCount: number;
14
+ notCapturedReplyCount: number;
15
+ }
16
+
17
+ export interface EmailCampaignReplyNumericGroupGQL {
18
+ unit: string | null;
19
+ count: number;
20
+ sum: number | null;
21
+ average: number | null;
22
+ min: number | null;
23
+ max: number | null;
24
+ overflow: boolean;
25
+ }
26
+
27
+ export interface EmailCampaignReplyFieldGQL {
28
+ key: string;
29
+ label: string;
30
+ type: 'NUMBER' | 'TEXT' | 'BOOLEAN';
31
+ answeredCount: number;
32
+ unclearCount: number;
33
+ withdrawnCount: number;
34
+ missingCount: number;
35
+ unitGroupCount: number;
36
+ omittedUnitGroups: number;
37
+ numeric: EmailCampaignReplyNumericGroupGQL[];
38
+ boolean: { trueCount: number; falseCount: number } | null;
39
+ }
40
+
41
+ export interface EmailCampaignReplyAnswerGQL {
42
+ fieldKey: string;
43
+ status: EmailCampaignReplyAnswerStatus;
44
+ numberValue: number | null;
45
+ textValue: string | null;
46
+ booleanValue: boolean | null;
47
+ unit: string | null;
48
+ receivedAt: string;
49
+ sourceEmailMessageId: string;
50
+ hasNewerUncapturedReply: boolean;
51
+ }
52
+
53
+ export interface EmailCampaignReplyRespondentGQL {
54
+ email: string;
55
+ displayName: string | null;
56
+ replyCount: number;
57
+ lastReplyAt: string;
58
+ lastReplyEmailMessageId: string;
59
+ captureState: EmailCampaignReplyCaptureState;
60
+ newerUncapturedReplyAt: string | null;
61
+ answers: EmailCampaignReplyAnswerGQL[];
62
+ }
63
+
64
+ export interface EmailCampaignReplyReportGQL {
65
+ organizationId: string;
66
+ campaignId: string;
67
+ campaignTitle: string | null;
68
+ readAt: string;
69
+ availability: EmailCampaignReplyAvailability;
70
+ definitionReason: 'ABSENT' | 'INVALID' | null;
71
+ limitReason: 'ROWS' | 'BYTES' | null;
72
+ instructions: string | null;
73
+ coverage: EmailCampaignReplyCoverageGQL;
74
+ fields: EmailCampaignReplyFieldGQL[];
75
+ respondents: EmailCampaignReplyRespondentGQL[];
76
+ }