@jsb188/mday 1.1.10 → 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 +140 -54
  2. package/src/constants/agentMemory.ts +123 -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 +21 -21
  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 +125 -7
  14. package/src/constants/fieldDoc.ts +104 -0
  15. package/src/constants/graphqlReactivity.ts +196 -0
  16. package/src/constants/integration.ts +8 -9
  17. package/src/constants/log.ts +14 -408
  18. package/src/constants/logDisplay/README.md +88 -0
  19. package/src/constants/logDisplay/defaults.ts +39 -0
  20. package/src/constants/logDisplay/index.ts +27 -0
  21. package/src/constants/logDisplay/operations/arable.ts +16 -0
  22. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  23. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  24. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  25. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  26. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  27. package/src/constants/logTaxonomy.generated.ts +2207 -0
  28. package/src/constants/noteDoc.ts +77 -0
  29. package/src/constants/organization.ts +18 -21
  30. package/src/constants/pageRoute.ts +23 -0
  31. package/src/constants/qrCode.ts +30 -0
  32. package/src/constants/sheet.ts +126 -14
  33. package/src/constants/sms.ts +18 -0
  34. package/src/constants/square.ts +6 -6
  35. package/src/constants/storage.ts +80 -7
  36. package/src/constants/usage.ts +82 -0
  37. package/src/constants/workflowSteps.ts +60 -0
  38. package/src/schemas/editLogEntry.ts +836 -780
  39. package/src/schemas/inboundContact.ts +60 -55
  40. package/src/schemas/logsQuery.ts +55 -49
  41. package/src/types/account.d.ts +4 -1
  42. package/src/types/agentMemory.d.ts +98 -0
  43. package/src/types/agentNote.d.ts +443 -0
  44. package/src/types/billing.d.ts +537 -0
  45. package/src/types/campaign.d.ts +1533 -0
  46. package/src/types/contact.d.ts +15 -0
  47. package/src/types/csvExport.d.ts +213 -0
  48. package/src/types/dataAnalysis.d.ts +44 -0
  49. package/src/types/dataTable.d.ts +115 -403
  50. package/src/types/definitionElement.d.ts +35 -0
  51. package/src/types/docAccess.d.ts +96 -0
  52. package/src/types/dt.d.ts +257 -0
  53. package/src/types/email.d.ts +184 -24
  54. package/src/types/emailReplyReport.d.ts +76 -0
  55. package/src/types/fieldDoc.d.ts +702 -0
  56. package/src/types/fieldDocContract.d.ts +90 -0
  57. package/src/types/inboundContact.d.ts +10 -1
  58. package/src/types/log.d.ts +254 -295
  59. package/src/types/logDisplay.types.ts +85 -0
  60. package/src/types/organization.d.ts +91 -43
  61. package/src/types/pageRoute.d.ts +48 -0
  62. package/src/types/qrCode.d.ts +96 -0
  63. package/src/types/richText.d.ts +81 -0
  64. package/src/types/sheet.d.ts +678 -129
  65. package/src/types/sms.d.ts +38 -0
  66. package/src/types/storage.d.ts +449 -129
  67. package/src/types/usage.d.ts +106 -0
  68. package/src/types/workflow.d.ts +315 -54
  69. package/src/utils/agentMemory.ts +15 -0
  70. package/src/utils/agentNote.ts +850 -0
  71. package/src/utils/aiChat.ts +43 -0
  72. package/src/utils/aiChatWork.ts +64 -0
  73. package/src/utils/billing.ts +37 -0
  74. package/src/utils/campaign.ts +1174 -0
  75. package/src/utils/campaignAI.ts +72 -0
  76. package/src/utils/campaignAccess.ts +239 -0
  77. package/src/utils/campaignEmail.ts +601 -0
  78. package/src/utils/campaignEmailCompiler.ts +372 -0
  79. package/src/utils/campaignEmailImages.ts +60 -0
  80. package/src/utils/campaignEmailStyles.ts +544 -0
  81. package/src/utils/campaignLifecycle.ts +104 -0
  82. package/src/utils/campaignPreview.ts +285 -0
  83. package/src/utils/contact.ts +50 -0
  84. package/src/utils/csvExport.ts +19 -0
  85. package/src/utils/dataTable.ts +95 -618
  86. package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
  87. package/src/utils/dataTableRelativeDate.ts +447 -0
  88. package/src/utils/definitionElement.ts +84 -0
  89. package/src/utils/docAccess.ts +383 -0
  90. package/src/utils/documentName.ts +53 -0
  91. package/src/utils/email.ts +317 -51
  92. package/src/utils/emailReplyReport.test.ts +187 -0
  93. package/src/utils/emailReplyReport.ts +143 -0
  94. package/src/utils/fieldDoc.ts +157 -0
  95. package/src/utils/fieldDocAnswers.ts +128 -0
  96. package/src/utils/fieldDocDefaults.ts +36 -0
  97. package/src/utils/fieldDocProgram.ts +36 -0
  98. package/src/utils/fieldDocSummary.ts +30 -0
  99. package/src/utils/log.ts +276 -192
  100. package/src/utils/logDisplay.helpers.ts +177 -0
  101. package/src/utils/logDisplay.ts +87 -0
  102. package/src/utils/logRegistryValue.ts +90 -0
  103. package/src/utils/logStoreRead.ts +262 -0
  104. package/src/utils/logTaxonomy.helpers.ts +17 -0
  105. package/src/utils/logTaxonomy.ts +76 -0
  106. package/src/utils/logTaxonomyDisplay.ts +395 -0
  107. package/src/utils/noteDoc.ts +609 -0
  108. package/src/utils/organization.ts +337 -84
  109. package/src/utils/pageRoute.ts +71 -0
  110. package/src/utils/qrCode.helpers.ts +189 -0
  111. package/src/utils/qrCode.test.ts +519 -0
  112. package/src/utils/qrCode.ts +273 -0
  113. package/src/utils/richTextHTML.ts +385 -0
  114. package/src/utils/sheet.ts +199 -107
  115. package/src/utils/sheetAxisMove.ts +616 -0
  116. package/src/utils/sheetBootstrap.ts +1402 -0
  117. package/src/utils/sheetCellLiteral.ts +101 -0
  118. package/src/utils/sheetCommand.ts +358 -0
  119. package/src/utils/sheetDesign.ts +705 -0
  120. package/src/utils/sheetExport.ts +186 -0
  121. package/src/utils/sheetFeatureReference.ts +183 -0
  122. package/src/utils/sheetFormulaArgs.ts +168 -0
  123. package/src/utils/sheetFormulaCompile.ts +475 -0
  124. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  125. package/src/utils/sheetFormulaCriteria.ts +656 -0
  126. package/src/utils/sheetFormulaDate.ts +444 -0
  127. package/src/utils/sheetFormulaEvaluation.ts +899 -0
  128. package/src/utils/sheetFormulaEvaluator.ts +997 -0
  129. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  130. package/src/utils/sheetFormulaLogical.ts +116 -0
  131. package/src/utils/sheetFormulaLookup.ts +488 -0
  132. package/src/utils/sheetFormulaMath.ts +48 -0
  133. package/src/utils/sheetFormulaParser.ts +729 -0
  134. package/src/utils/sheetFormulaRange.ts +330 -0
  135. package/src/utils/sheetFormulaReference.ts +703 -0
  136. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  137. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  138. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  139. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  140. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  141. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  142. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  143. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  144. package/src/utils/sheetFormulaText.ts +430 -0
  145. package/src/utils/sheetJournal.ts +200 -0
  146. package/src/utils/sheetNumberFormat.ts +1012 -0
  147. package/src/utils/sheetPreview.ts +68 -0
  148. package/src/utils/sheetSequence.ts +118 -0
  149. package/src/utils/sheetSnapshot.ts +739 -0
  150. package/src/utils/sheetStructureEdit.ts +914 -0
  151. package/src/utils/sheetStructureReferences.ts +389 -0
  152. package/src/utils/square.ts +22 -12
  153. package/src/utils/storage.ts +198 -0
  154. package/src/utils/table-route.ts +127 -11
  155. package/src/utils/time.ts +12 -0
  156. package/src/utils/workflow.ts +334 -40
  157. package/src/utils/workflowLogFingerprint.ts +302 -0
  158. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  159. package/src/utils/workflowProgress.ts +280 -0
  160. package/src/utils/workflowTriggers.ts +61 -0
  161. package/tests/agentNote.test.ts +395 -0
  162. package/tests/campaignAI.test.ts +119 -0
  163. package/tests/campaignAccess.test.ts +239 -0
  164. package/tests/campaignEmail.test.ts +441 -0
  165. package/tests/campaignLifecycle.test.ts +134 -0
  166. package/tests/campaignPublication.test.ts +309 -0
  167. package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
  168. package/tests/dataTableRelativeDate.test.ts +412 -0
  169. package/tests/docAccess.test.ts +525 -0
  170. package/tests/editLogEntry.test.ts +112 -0
  171. package/tests/email.test.ts +39 -0
  172. package/tests/fieldDocProgram.test.ts +114 -0
  173. package/tests/logDisplay.fixtures.ts +67 -0
  174. package/tests/logDisplay.test.ts +227 -0
  175. package/tests/noteDoc.test.ts +514 -0
  176. package/tests/richTextHTML.test.ts +185 -0
  177. package/tests/sheetAxisMove.test.ts +352 -0
  178. package/tests/sheetBootstrap.test.ts +1967 -0
  179. package/tests/sheetFeatureReference.test.ts +22 -0
  180. package/tests/sheetFormulaCriteria.test.ts +269 -0
  181. package/tests/sheetFormulaEvaluator.test.ts +468 -0
  182. package/tests/sheetFormulaFunctions.test.ts +538 -0
  183. package/tests/sheetFormulaLanguage.test.ts +361 -0
  184. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  185. package/tests/sheetFormulaParity.test.ts +188 -0
  186. package/tests/sheetFormulaRange.test.ts +167 -0
  187. package/tests/sheetFormulaReference.test.ts +78 -0
  188. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  189. package/tests/sheetFormulaTextDate.test.ts +512 -0
  190. package/tests/sheetSequence.test.ts +22 -0
  191. package/tests/sheetSnapshot.test.ts +134 -0
  192. package/tests/sheetStructureEdit.test.ts +537 -0
  193. package/tests/sheetStructureReferences.test.ts +589 -0
  194. package/tests/workflowLifecycleStatus.test.ts +60 -0
  195. package/tests/workflowLogFingerprint.test.ts +203 -0
  196. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  197. package/tests/workflowProgress.test.ts +180 -0
  198. package/tests/workflowTriggers.test.ts +29 -0
  199. package/tsconfig.json +10 -10
  200. package/vitest.config.ts +8 -0
  201. package/src/constants/log-activityTexts.ts +0 -235
  202. package/src/constants/product.ts +0 -42
  203. package/src/constants/report.ts +0 -44
  204. package/src/schemas/organization.ts +0 -65
  205. package/src/schemas/productsQuery.ts +0 -53
  206. package/src/schemas/reportsQuery.ts +0 -20
  207. package/src/types/product.d.ts +0 -84
  208. package/src/types/report.d.ts +0 -290
  209. package/src/utils/product-calEvent.ts +0 -455
  210. package/src/utils/report.ts +0 -158
@@ -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,40 +1,115 @@
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,
9
+ INBOUND_EMAIL_KIND_ENUMS,
10
+ OUTBOUND_EMAIL_KIND_ENUMS,
11
+ OUTBOUND_EMAIL_STATUS_ENUMS,
5
12
  } from '../constants/email.ts';
13
+ import type { StorageGQL } from './storage.d.ts';
6
14
 
7
15
  /**
8
16
  * Email handling lifecycle status.
9
17
  */
10
- export type EmailStatusEnum = typeof EMAIL_STATUS_ENUMS[number];
18
+ export type EmailStatusEnum = (typeof EMAIL_STATUS_ENUMS)[number];
11
19
 
12
20
  /**
13
- * Inbound email list sort.
21
+ * Outbound email delivery status.
14
22
  */
15
- export type InboundEmailsSortEnum = typeof INBOUND_EMAIL_SORT_ENUMS[number];
23
+ export type OutboundEmailStatusEnum = (typeof OUTBOUND_EMAIL_STATUS_ENUMS)[number];
24
+
25
+ /**
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.
47
+ */
48
+ export type EmailMessageStatusEnum = (typeof EMAIL_MESSAGE_STATUS_ENUMS)[number];
49
+
50
+ /**
51
+ * Direction-neutral email status bucket.
52
+ */
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
+ }
16
81
 
17
82
  /**
18
83
  * Inbound email display body source.
19
84
  */
20
- export type InboundEmailBodyFormatEnum = 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
+ }
21
95
 
22
96
  /**
23
- * Safe attachment metadata from one inbound email payload.
97
+ * Immutable log-derived email content saved before asynchronous delivery.
24
98
  */
25
- export interface InboundEmailAttachmentGQL {
26
- name: string | null;
27
- contentType: string | null;
28
- contentLength: number | null;
99
+ export interface OutboundEmailRenderedLogSnapshot {
100
+ version: 'outbound-email-rendered-log:v1';
101
+ contentHTML: string;
102
+ attachments: OutboundEmailRenderedLogAttachment[];
29
103
  }
30
104
 
31
105
  /**
32
106
  * Saved inbound email database row.
33
107
  */
34
108
  export interface InboundEmailData {
35
- __table?: 'emails';
109
+ __table?: 'emails_inbound';
36
110
  id: bigint;
37
111
  organizationId: bigint;
112
+ sourceOutboundEmailId: bigint | null;
38
113
  recipientEmail: string;
39
114
  senderEmail: string | null;
40
115
  subject: string | null;
@@ -42,30 +117,115 @@ export interface InboundEmailData {
42
117
  payload: Record<string, any>;
43
118
  status: EmailStatusEnum;
44
119
  statusSummary: string | null;
120
+ processingLeaseId: string | null;
45
121
  processingStartedAt: Date | null;
46
122
  processingCompletedAt: Date | null;
47
123
  receivedAt: Date;
48
124
  }
49
125
 
126
+ /*
127
+ * Persisted outbound content, excluding regenerated campaign HTML.
128
+ */
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;
141
+ }
142
+
143
+ /**
144
+ * Saved outbound email database row.
145
+ */
146
+ export interface OutboundEmailData {
147
+ __table?: 'emails_outbound';
148
+ id: bigint;
149
+ organizationId: bigint;
150
+ workflowRunStateId?: bigint | null;
151
+ originatingWorkflowRunId?: bigint | null;
152
+ campaignId: bigint | null;
153
+ campaignRecipientId: bigint | null;
154
+ sendBatchId: string | null;
155
+ replyToken: string | null;
156
+ sourceInboundEmailId: bigint | null;
157
+ idempotencyKey: string;
158
+ kind: OutboundEmailKindEnum;
159
+ toEmail: string;
160
+ payload: OutboundEmailPayload;
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;
168
+ postmarkMessageId: string | null;
169
+ errorMessage: string | null;
170
+ sentAt: Date | null;
171
+ deliveredAt: Date | null;
172
+ firstOpenedAt: Date | null;
173
+ bouncedAt: Date | null;
174
+ bounceType: string | null;
175
+ spamComplaintAt: Date | null;
176
+ suppressionReason: string | null;
177
+ broadcast: boolean;
178
+ createdAt: Date;
179
+ updatedAt: Date;
180
+ relatedLogIds?: Array<number | bigint>;
181
+ files?: StorageGQL[];
182
+ }
183
+
50
184
  /**
51
- * GraphQL inbound email record.
185
+ * GraphQL email message record; one inbound or outbound email.
52
186
  */
53
- export interface InboundEmailGQL {
187
+ export interface EmailMessageGQL {
54
188
  __deleted?: boolean;
55
189
  id: string;
56
190
  cursor: string;
57
191
  organizationId: string;
58
- recipientEmail: string;
59
- senderEmail: string | null;
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;
60
201
  subject: string | null;
202
+ previewText: string | null;
61
203
  postmarkMessageId: string | null;
62
- status: EmailStatusEnum;
63
- statusSummary: string | null;
64
- previewText: string;
65
- bodyFormat: InboundEmailBodyFormatEnum | null;
66
- bodyText: string;
67
- attachments: InboundEmailAttachmentGQL[];
68
- receivedAt: string;
69
- processingStartedAt: string | null;
70
- processingCompletedAt: string | null;
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;
71
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
+ }