@jsb188/mday 1.1.8 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/package.json +105 -35
  2. package/src/constants/agentDoc.ts +12 -0
  3. package/src/constants/agentMemory.ts +154 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/campaign.ts +127 -0
  6. package/src/constants/dataTable.ts +48 -0
  7. package/src/constants/dataTableFieldTypes.generated.ts +63 -0
  8. package/src/constants/docAccess.ts +32 -0
  9. package/src/constants/email.ts +44 -0
  10. package/src/constants/fieldDoc.ts +34 -0
  11. package/src/constants/graphqlReactivity.ts +113 -0
  12. package/src/constants/inboundContact.ts +8 -0
  13. package/src/constants/integration.ts +13 -0
  14. package/src/constants/log.ts +7 -366
  15. package/src/constants/logActivityGroupColors.generated.ts +19 -0
  16. package/src/constants/logTaxonomy.generated.ts +1103 -0
  17. package/src/constants/noteDoc.ts +77 -0
  18. package/src/constants/organization.ts +18 -11
  19. package/src/constants/pageRoute.ts +23 -0
  20. package/src/constants/schedule.ts +220 -0
  21. package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
  22. package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
  23. package/src/constants/sheet.ts +168 -0
  24. package/src/constants/sheetRegionSources.generated.ts +578 -0
  25. package/src/constants/square.ts +16 -0
  26. package/src/constants/storage.ts +61 -0
  27. package/src/constants/usage.ts +79 -0
  28. package/src/schemas/editLogEntry.ts +1017 -738
  29. package/src/schemas/fieldDocsQuery.ts +12 -0
  30. package/src/schemas/inboundContact.ts +77 -0
  31. package/src/schemas/logsQuery.ts +57 -316
  32. package/src/schemas/organization.ts +53 -213
  33. package/src/types/account.d.ts +81 -0
  34. package/src/types/agentDoc.d.ts +64 -0
  35. package/src/types/agentMemory.d.ts +74 -0
  36. package/src/types/campaign.d.ts +683 -0
  37. package/src/types/dataTable.d.ts +366 -0
  38. package/src/types/docAccess.d.ts +96 -0
  39. package/src/types/email.d.ts +142 -0
  40. package/src/types/fieldDoc.d.ts +273 -0
  41. package/src/types/inboundContact.d.ts +57 -0
  42. package/src/types/integration.d.ts +42 -0
  43. package/src/types/log.d.ts +169 -190
  44. package/src/types/noteDoc.d.ts +86 -0
  45. package/src/types/organization.d.ts +175 -76
  46. package/src/types/pageRoute.d.ts +48 -0
  47. package/src/types/schedule.d.ts +391 -0
  48. package/src/types/sheet.d.ts +1130 -0
  49. package/src/types/storage.d.ts +242 -0
  50. package/src/types/usage.d.ts +106 -0
  51. package/src/types/workflow.d.ts +305 -0
  52. package/src/utils/agentDoc.ts +109 -0
  53. package/src/utils/aiChat.ts +26 -0
  54. package/src/utils/campaign.ts +741 -0
  55. package/src/utils/campaignFormEditor.ts +871 -0
  56. package/src/utils/dataTable.ts +849 -0
  57. package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
  58. package/src/utils/dataTableRealtimeAuthority.ts +209 -0
  59. package/src/utils/dataTableRealtimeSelection.ts +134 -0
  60. package/src/utils/dataTableRowDocument.ts +508 -0
  61. package/src/utils/dataTableSource.ts +230 -0
  62. package/src/utils/docAccess.ts +383 -0
  63. package/src/utils/documentName.ts +53 -0
  64. package/src/utils/email.ts +172 -0
  65. package/src/utils/fieldDoc.ts +113 -0
  66. package/src/utils/log.ts +173 -778
  67. package/src/utils/logRegistryValue.ts +90 -0
  68. package/src/utils/logStoreRead.ts +266 -0
  69. package/src/utils/logTaxonomy.ts +76 -0
  70. package/src/utils/logTaxonomyDisplay.ts +439 -0
  71. package/src/utils/noteDoc.ts +827 -0
  72. package/src/utils/organization.ts +683 -81
  73. package/src/utils/pageRoute.ts +71 -0
  74. package/src/utils/schedule.ts +799 -0
  75. package/src/utils/scheduleEvaluation.ts +1994 -0
  76. package/src/utils/scheduleICS.ts +246 -0
  77. package/src/utils/scheduleRuleTemplates.ts +188 -0
  78. package/src/utils/sheet.ts +4973 -0
  79. package/src/utils/sheetAxisMove.ts +830 -0
  80. package/src/utils/sheetBootstrap.ts +1769 -0
  81. package/src/utils/sheetCommand.ts +423 -0
  82. package/src/utils/sheetExport.ts +238 -0
  83. package/src/utils/sheetFormulaEvaluation.ts +914 -0
  84. package/src/utils/sheetFormulaEvaluator.ts +852 -0
  85. package/src/utils/sheetJournal.ts +78 -0
  86. package/src/utils/sheetNumberFormat.ts +1211 -0
  87. package/src/utils/sheetRegion.ts +374 -0
  88. package/src/utils/sheetRegionFilter.ts +1259 -0
  89. package/src/utils/sheetRegionSourceRegistry.ts +594 -0
  90. package/src/utils/sheetSequence.ts +148 -0
  91. package/src/utils/sheetSnapshot.ts +992 -0
  92. package/src/utils/sheetStructureEdit.ts +1284 -0
  93. package/src/utils/square.ts +32 -0
  94. package/src/utils/storage.ts +152 -0
  95. package/src/utils/table-route.ts +262 -0
  96. package/src/utils/workflow.ts +380 -0
  97. package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
  98. package/tests/docAccess.test.ts +525 -0
  99. package/tests/editLogEntry.test.ts +112 -0
  100. package/tests/noteDoc.test.ts +669 -0
  101. package/tests/schedule.test.ts +693 -0
  102. package/tests/scheduleEvaluation.test.ts +1970 -0
  103. package/tests/scheduleICS.test.ts +208 -0
  104. package/tests/scheduleRuleTemplates.test.ts +176 -0
  105. package/tests/scheduleSweepInvariants.test.ts +428 -0
  106. package/tests/sheetAxisMove.test.ts +343 -0
  107. package/tests/sheetFormulaEvaluator.test.ts +575 -0
  108. package/tests/sheetRegionFilter.test.ts +1135 -0
  109. package/tests/sheetSequence.test.ts +41 -0
  110. package/tests/sheetStructureEdit.test.ts +82 -0
  111. package/tsconfig.json +12 -0
  112. package/vitest.config.ts +8 -0
  113. package/src/constants/log-activityTexts.ts +0 -209
  114. package/src/constants/product.ts +0 -66
  115. package/src/constants/report.ts +0 -25
  116. package/src/schemas/childOrganizationsQuery.ts +0 -44
  117. package/src/schemas/productsQuery.ts +0 -145
  118. package/src/schemas/reportsQuery.ts +0 -107
  119. package/src/types/action.d.ts +0 -42
  120. package/src/types/product.d.ts +0 -173
  121. package/src/types/report.d.ts +0 -203
  122. package/src/utils/product-calEvent.ts +0 -508
  123. package/src/utils/route-helpers.ts +0 -583
@@ -0,0 +1,242 @@
1
+ import {
2
+ FILE_STATUS_ENUMS,
3
+ STORAGE_INTENT_ENUMS,
4
+ } from '../constants/storage.ts';
5
+ import type { OrganizationData } from './organization.d.ts';
6
+
7
+ /**
8
+ * Enums
9
+ */
10
+
11
+ export type StorageIntentEnum = (typeof STORAGE_INTENT_ENUMS)[number];
12
+ export type FileStatusEnum = (typeof FILE_STATUS_ENUMS)[number];
13
+
14
+ export type CSVColumnFormat =
15
+ | 'NUMBER'
16
+ | 'NUMBER_ROUND'
17
+ | 'DECIMAL_1'
18
+ | 'DECIMAL_2'
19
+ | 'CURRENCY'
20
+ | 'PERCENT'
21
+ | 'STRING';
22
+
23
+ export type CSVFooterFn = 'SUM' | 'AVG' | 'MIN' | 'MAX' | 'COUNT' | 'TEXT';
24
+
25
+ export type CSVExportVisibility = 'PRIVATE' | 'PUBLIC';
26
+
27
+ export type CSVExportSource = 'SMS' | 'WEB';
28
+
29
+ export type GeneratedFileDeliveredVia = 'SMS' | 'EMAIL' | 'NONE';
30
+
31
+ export interface CSVExportColumnSpec {
32
+ label: string; // CSV header
33
+ format: CSVColumnFormat;
34
+ hint: string; // How to source/derive the value
35
+ }
36
+
37
+ export interface CSVExportFooterSpec {
38
+ label: string;
39
+ fn: CSVFooterFn;
40
+ of?: string | null; // Column label the fn applies to (not for TEXT)
41
+ value?: string | null; // Literal text when fn === "TEXT"
42
+ }
43
+
44
+ export interface CSVExportFileSpec {
45
+ fileName: string; // <= 70
46
+ fileDescription: string; // <= 100
47
+ dataStartDate: string; // YYYY-MM-DD
48
+ dataEndDate: string; // YYYY-MM-DD
49
+ descriptionOfDataToSearch: string;
50
+ analysisGoal?: string | null;
51
+ maxRows?: number | null;
52
+ columns: CSVExportColumnSpec[];
53
+ footerRows?: CSVExportFooterSpec[] | null;
54
+ }
55
+
56
+ export interface CSVExportRecipient {
57
+ channel: 'SMS' | 'EMAIL';
58
+ address: string;
59
+ }
60
+
61
+ /**
62
+ * storage_generated.payload for one AI CSV export file row
63
+ */
64
+
65
+ export interface CSVExportGeneratedPayload {
66
+ kind: 'CSV_EXPORT_FILE';
67
+ batchId: string; // uuid shared by all files of one request
68
+ spec: CSVExportFileSpec;
69
+ visibility: CSVExportVisibility;
70
+ requestSource: CSVExportSource;
71
+
72
+ // Set on completion by the create_csv_file tool
73
+ rowCount?: number | null;
74
+ columnCount?: number | null;
75
+ csvBytes?: number | null;
76
+ truncated?: boolean | null;
77
+ }
78
+
79
+ /**
80
+ * Storage
81
+ */
82
+
83
+ export interface StorageData {
84
+ __table: 'storage';
85
+ id: number;
86
+ oaiFileId: string | null;
87
+ organizationId: number | null;
88
+ accountId: number | null;
89
+ uri: string;
90
+ size: number;
91
+ checked: boolean;
92
+ at: Date;
93
+ contentType: string;
94
+ intent: StorageIntentEnum | null;
95
+ values: Record<string, any> | null;
96
+ }
97
+
98
+ export interface StorageGeneratedData {
99
+ __table: 'storage_generated';
100
+
101
+ code: string;
102
+ fileName: string;
103
+ fileDescription: string;
104
+ summaryReport: string | null;
105
+ payload: CSVExportGeneratedPayload | Record<string, any>;
106
+ accountId: number | bigint;
107
+ organizationId: number | bigint;
108
+ organization?: OrganizationData;
109
+ account?: {
110
+ id: number | bigint;
111
+ profile?: {
112
+ id: number | bigint;
113
+ firstName: string | null;
114
+ lastName: string | null;
115
+ } | null;
116
+ email?: {
117
+ id: number | bigint;
118
+ address: string | null;
119
+ } | null;
120
+ phone?: {
121
+ id: number | bigint;
122
+ number: string | null;
123
+ } | null;
124
+ };
125
+ storageId: number | bigint | null;
126
+ status: FileStatusEnum;
127
+ generatedAt: Date | null;
128
+ isPublic: boolean;
129
+ downloadKey: string | null;
130
+ downloadKeyExpiresAt: Date | null;
131
+ downloadCount: number;
132
+ lastDownloadedAt: Date | null;
133
+ deliveredVia: GeneratedFileDeliveredVia | null;
134
+ expiresAt: Date | null;
135
+ createdAt: Date;
136
+ updatedAt: Date;
137
+ }
138
+
139
+ /**
140
+ * GraphQL shape for the /app/downloads list ("GeneratedFile" type)
141
+ */
142
+
143
+ export interface GeneratedFileGQL {
144
+ __deleted?: boolean;
145
+
146
+ id: string; // storage_generated.code
147
+ cursor?: string | null;
148
+ fileName: string;
149
+ fileDescription: string;
150
+ summaryReport: string | null;
151
+ status: FileStatusEnum;
152
+ isPublic: boolean;
153
+ deliveredVia: GeneratedFileDeliveredVia;
154
+ downloadCount: number;
155
+ lastDownloadedAt: string | null; // ISO Date string
156
+ activeLinkExpiresAt: string | null; // ISO Date string (downloadKeyExpiresAt)
157
+ expiresAt: string | null; // ISO Date string (file retention deadline)
158
+ generatedAt: string | null; // ISO Date string
159
+ createdAt: string; // ISO Date string
160
+ createdByName: string | null;
161
+ hasFile: boolean;
162
+ }
163
+
164
+ export interface StorageGQL {
165
+ __deleted?: boolean;
166
+
167
+ id: string;
168
+ organizationId: string | null;
169
+ accountId: string | null;
170
+ uri: string;
171
+ size: number;
172
+ checked: boolean;
173
+ at: string; // ISO Date string
174
+ contentType: string;
175
+ intent: StorageIntentEnum | null;
176
+
177
+ // client-side only
178
+ uploadStatus?: 'ERROR' | 'UPLOADING' | null;
179
+
180
+ // metadata
181
+ name: string | null;
182
+ description?: string | null;
183
+ aiNote?: string | null;
184
+ }
185
+
186
+ export type StorageUploadEvent = Partial<{
187
+ oaiFileId: string;
188
+ uploaderAccountId: number | bigint | string;
189
+
190
+ // What the file was uploaded for; promoted to the storage.intent column by
191
+ // the GCS finalize webhook (upsertFileToStorage)
192
+ intent: StorageIntentEnum;
193
+
194
+ values: Partial<{
195
+ name: string;
196
+ description: string;
197
+ aiNote: string;
198
+ cacheDuration: number;
199
+
200
+ // Chat channel the file came from (set for AI chat files; web composer
201
+ // uploads carry it from their initial "UNUSED" upload)
202
+ source: 'SMS' | 'WEB' | 'EMAIL';
203
+
204
+ // Provenance for files received through a Postmark inbound webhook.
205
+ inboundEmailId: string;
206
+ postmarkMessageId: string;
207
+ attachmentIndex: number;
208
+ contentHash: string;
209
+ contentId: string | null;
210
+ recipientEmail: string;
211
+
212
+ // Original intent retained while a log relationship owns the file.
213
+ intentBeforeLog: StorageIntentEnum;
214
+
215
+ // Marks a temporary intent upload as claimed so cleanup crons keep it
216
+ consumedAt: string;
217
+
218
+ // Marks a stale upload as reserved by cleanup so consumers stop claiming it
219
+ cleanupStartedAt: string;
220
+
221
+ // For PDF only
222
+ pageCount: number;
223
+ isEncrypted: boolean;
224
+ pdfVersion: string;
225
+ }>;
226
+ uploadIntent: {
227
+ intent: StorageIntentEnum;
228
+ entries: [string, string][];
229
+ };
230
+ upsertQuery?: RelatedDocumentUpsertQuery;
231
+ realTimeUpdate?: string; // JSON.stringified object; "{{storageId}}" will be replaced with actual storage ID after upload
232
+ }>;
233
+
234
+ /**
235
+ * Post-upload related document query execution object
236
+ */
237
+
238
+ export interface RelatedDocumentUpsertQuery {
239
+ __table: string;
240
+ conflictKeys: string[];
241
+ data: Record<string, any>;
242
+ }
@@ -0,0 +1,106 @@
1
+ import type {
2
+ USAGE_EXCLUSION_REASONS,
3
+ USAGE_METERS,
4
+ USAGE_OPERATIONS,
5
+ USAGE_ORIGINS,
6
+ USAGE_PROVIDERS,
7
+ USAGE_SCHEMA_VERSION,
8
+ USAGE_SOURCE_TYPES,
9
+ } from '../constants/usage.ts';
10
+
11
+ export type UsageSchemaVersion = typeof USAGE_SCHEMA_VERSION;
12
+ export type UsageMeterEnum = (typeof USAGE_METERS)[number];
13
+ export type UsageOriginEnum = (typeof USAGE_ORIGINS)[number];
14
+ export type UsageExclusionReasonEnum = (typeof USAGE_EXCLUSION_REASONS)[number];
15
+ export type UsageProviderEnum = (typeof USAGE_PROVIDERS)[number];
16
+ export type UsageOperationEnum = (typeof USAGE_OPERATIONS)[number];
17
+ export type UsageSourceTypeEnum = (typeof USAGE_SOURCE_TYPES)[number];
18
+
19
+ /*
20
+ * Organization attribution supplied by the product path that caused usage.
21
+ */
22
+ export interface OrganizationUsageAttribution {
23
+ tracking: 'ORGANIZATION';
24
+ organizationId: number | bigint;
25
+ accountId?: number | bigint | null;
26
+ origin: UsageOriginEnum;
27
+ }
28
+
29
+ /*
30
+ * Deliberate exclusion supplied for platform-owned or non-production work.
31
+ */
32
+ export interface ExcludedUsageAttribution {
33
+ tracking: 'EXCLUDED';
34
+ reason: UsageExclusionReasonEnum;
35
+ }
36
+
37
+ export type UsageAttribution =
38
+ | OrganizationUsageAttribution
39
+ | ExcludedUsageAttribution;
40
+
41
+ /*
42
+ * One positive integer measurement within a provider usage envelope.
43
+ */
44
+ export interface UsageQuantityInput {
45
+ meter: UsageMeterEnum;
46
+ quantity: number;
47
+ }
48
+
49
+ /*
50
+ * Provider result normalized before it enters the durable usage outbox.
51
+ */
52
+ export interface UsageEnvelopeInput {
53
+ schemaVersion?: UsageSchemaVersion;
54
+ sourceType: UsageSourceTypeEnum;
55
+ sourceId: string;
56
+ provider: UsageProviderEnum;
57
+ operation: UsageOperationEnum;
58
+ model?: string | null;
59
+ occurredAt?: Date | string;
60
+ quantities: UsageQuantityInput[];
61
+ metadata?: Record<string, unknown>;
62
+ }
63
+
64
+ /*
65
+ * Fully attributed schema-versioned payload stored in the durable outbox.
66
+ */
67
+ export interface UsageEnvelopeJobPayload
68
+ extends Omit<UsageEnvelopeInput, 'occurredAt' | 'schemaVersion'> {
69
+ schemaVersion: UsageSchemaVersion;
70
+ organizationId: string;
71
+ accountId: string | null;
72
+ origin: UsageOriginEnum;
73
+ occurredAt: string;
74
+ }
75
+
76
+ /*
77
+ * Append-only usage ledger row returned by server-side reads.
78
+ */
79
+ export interface UsageEventData {
80
+ __table?: 'usage_events';
81
+ id: number | bigint;
82
+ schemaVersion: UsageSchemaVersion;
83
+ organizationId: number | bigint;
84
+ accountId: number | bigint | null;
85
+ meter: UsageMeterEnum;
86
+ quantity: number | bigint;
87
+ origin: UsageOriginEnum;
88
+ sourceType: UsageSourceTypeEnum;
89
+ sourceId: string;
90
+ provider: UsageProviderEnum;
91
+ operation: UsageOperationEnum;
92
+ model: string | null;
93
+ metadata: Record<string, unknown>;
94
+ occurredAt: Date;
95
+ createdAt: Date;
96
+ }
97
+
98
+ /*
99
+ * Bigint-safe meter and origin aggregate used by billing-facing queries.
100
+ */
101
+ export interface OrganizationUsageSummaryData {
102
+ meter: UsageMeterEnum;
103
+ origin: UsageOriginEnum;
104
+ quantity: string;
105
+ eventCount: string;
106
+ }
@@ -0,0 +1,305 @@
1
+ import type { LabelAndValue } from '@jsb188/app/types/other.d.ts';
2
+ import type { BuildSingleTextLine } from '@jsb188/app/utils/string.ts';
3
+ import type { DataTableData, DataTableGQL } from '../types/dataTable.d.ts';
4
+ import type { OrganizationData } from '../types/organization.d.ts';
5
+ import type {
6
+ WORKFLOW_KIND_ENUMS,
7
+ WORKFLOW_LIFECYCLE_STATUS_ENUMS,
8
+ WORKFLOW_RUN_STATUS_ENUMS,
9
+ WORKFLOW_TRIGGER_TYPE_ENUMS,
10
+ WORKFLOW_WAIT_CHANNEL_ENUMS,
11
+ } from '@jsb188/app/constants/agent.ts';
12
+
13
+ /**
14
+ * Enums
15
+ */
16
+
17
+ export type WorkflowStatusEnum = (typeof WORKFLOW_RUN_STATUS_ENUMS)[number];
18
+ export type WorkflowLifecycleStatusEnum =
19
+ (typeof WORKFLOW_LIFECYCLE_STATUS_ENUMS)[number];
20
+ export type WorkflowKindEnum = (typeof WORKFLOW_KIND_ENUMS)[number];
21
+ export type WorkflowTriggerTypeEnum =
22
+ (typeof WORKFLOW_TRIGGER_TYPE_ENUMS)[number];
23
+ export type WorkflowWaitChannelEnum =
24
+ (typeof WORKFLOW_WAIT_CHANNEL_ENUMS)[number];
25
+
26
+ /**
27
+ * Workflow/reminder recipient; accountId for system users,
28
+ * raw phone/email only for external one-time reminders
29
+ */
30
+
31
+ export interface WorkflowRecipient {
32
+ accountId?: number | bigint | string | null;
33
+ name?: string | null; // Display name; attached from account profiles, never stored
34
+ phone?: string | null;
35
+ email?: string | null;
36
+ channels: WorkflowWaitChannelEnum[];
37
+ }
38
+ /**
39
+ * Workflow prompt instructions
40
+ */
41
+
42
+ export interface WorkflowPrompts {
43
+ main: BuildSingleTextLine[];
44
+ identity?: BuildSingleTextLine[];
45
+ progressReport?: BuildSingleTextLine[];
46
+ dataTable?: BuildSingleTextLine[];
47
+ summary?: BuildSingleTextLine[];
48
+ }
49
+
50
+ /**
51
+ * Workflow data; each step object
52
+ */
53
+
54
+ export interface WorkflowStep extends LabelAndValue {
55
+ conditional?: Partial<LabelAndValue> & {
56
+ required?: string[]; // If this value doesn't exist or is not an array, that's a data error, and this object should be ignored
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Workflow data object
62
+ */
63
+
64
+ export interface WorkflowData {
65
+ __table: 'workflows';
66
+
67
+ id: number | bigint;
68
+ organizationId: number | bigint;
69
+ org?: OrganizationData; // Included if query joined with organization table
70
+ fieldDocId: number | bigint | null;
71
+ dataTables?: Array<
72
+ Pick<DataTableData, 'id' | 'name' | 'title' | 'description' | 'deletedAt'>
73
+ >;
74
+
75
+ kind: WorkflowKindEnum;
76
+ triggerType: WorkflowTriggerTypeEnum;
77
+ logTypes: string[] | null; // Registry group keys; any matching key triggers the workflow
78
+
79
+ accountId: number | bigint | null; // Creator; set for reminders
80
+ recipients: WorkflowRecipient[] | null;
81
+
82
+ title: string;
83
+ instructions?: null | WorkflowPrompts;
84
+
85
+ schedule: string | null;
86
+ scheduleInterval: number;
87
+ active: boolean;
88
+ values: Partial<{
89
+ model: 'advanced' | 'standard' | 'basic' | 'lesser' | 'smallest';
90
+ effort: 'none' | 'low' | 'medium' | 'high';
91
+ verbosity: 'low' | 'medium' | 'high';
92
+ steps: WorkflowStep[];
93
+ requireDataTables?: boolean;
94
+ deliveryMode: 'SIMPLE' | 'AGENTIC'; // Reminders only; SIMPLE sends without an agentic run
95
+ config: Record<string, string | number | boolean | null> & {
96
+ endTime: string; // HHMM format
97
+ };
98
+ }>;
99
+
100
+ startedAt: Date | null;
101
+ nextAt: Date | null;
102
+ createdAt: Date;
103
+ updatedAt: Date;
104
+
105
+ latestRun?: WorkflowRunData | null; // Attached from workflow_runs by list/emit helpers, never stored
106
+ }
107
+
108
+ /**
109
+ * Workflow template data object (visibility defaults for org workflows)
110
+ */
111
+
112
+ export interface WorkflowTemplateData {
113
+ __table: 'workflow_templates';
114
+
115
+ id: number | bigint;
116
+ fieldDocId: number | bigint | null;
117
+ visibleForLogTypes: string[] | null; // Registry group keys; NULL = retired, offered to no one
118
+ title: string;
119
+ instructions?: null | WorkflowPrompts;
120
+ schedule: string | null;
121
+ scheduleInterval: number;
122
+ active: boolean;
123
+ defaults: WorkflowData['values'] | null;
124
+ createdAt: Date;
125
+ updatedAt: Date;
126
+ }
127
+
128
+ /**
129
+ * Workflow run wait data object; a paused run waiting for a person's reply
130
+ */
131
+
132
+ export interface WorkflowRunWaitData {
133
+ __table: 'workflow_run_waits';
134
+
135
+ id: number | bigint;
136
+ workflowRunId: number | bigint;
137
+ channel: WorkflowWaitChannelEnum;
138
+ address: string; // Normalized international phone or lowercased email
139
+ accountId: number | bigint | null;
140
+ question: string | null;
141
+ expiresAt: Date | null;
142
+ resolvedAt: Date | null;
143
+ replyText: string | null;
144
+ createdAt: Date;
145
+ }
146
+
147
+ /**
148
+ * Workflow instance data object
149
+ */
150
+
151
+ export interface WorkflowRunData {
152
+ __table: 'workflow_runs';
153
+
154
+ id: number | bigint;
155
+ workflowId: number | bigint;
156
+ logId: number | bigint | null;
157
+ fieldDocSubmissionId?: number | bigint | null;
158
+ runKey: string;
159
+ iterations: number;
160
+ values: null | Partial<{
161
+ progressReport: string;
162
+ eventInput: string;
163
+ }>;
164
+ message: string | null;
165
+ status: WorkflowStatusEnum;
166
+ scheduledDate: Date | null;
167
+ followUpAt: Date | null;
168
+ activityAt: Date;
169
+ claimToken?: string | null; // atomic consumer-claim token; see claimWorkflowRun()
170
+ claimedAt?: Date | null; // atomic consumer-claim token; see claimWorkflowRun()
171
+ activeWait?: WorkflowRunWaitData | null; // Attached from workflow_run_waits, never stored
172
+ }
173
+
174
+ /**
175
+ * Workflow dataTable target data object
176
+ */
177
+
178
+ export interface WorkflowDataTableTargetData {
179
+ __table: 'workflow_data_table_targets';
180
+
181
+ id: number | bigint;
182
+ workflowId: number | bigint;
183
+ dataTableId: number | bigint;
184
+ }
185
+
186
+ /**
187
+ * Workflow dataTable write receipt data object
188
+ */
189
+
190
+ export interface WorkflowDataTableRecordWriteData {
191
+ __table: 'workflow_data_table_record_writes';
192
+
193
+ id: number | bigint;
194
+ organizationId: number | bigint;
195
+ workflowId: number | bigint;
196
+ workflowRunId?: number | bigint | null;
197
+ logId?: number | bigint | null;
198
+ fieldDocSubmissionId?: number | bigint | null;
199
+ dataTableId: number | bigint;
200
+ dataTableRowId?: number | bigint | null;
201
+ status: 'CREATED' | 'UPDATED' | 'SKIPPED' | 'FAILED';
202
+ error?: string | null;
203
+ metadata: Record<string, any>;
204
+ createdAt: Date;
205
+ updatedAt: Date;
206
+ }
207
+
208
+ /**
209
+ * Workflow run wait GraphQL data
210
+ */
211
+
212
+ export interface WorkflowRunWaitGQL {
213
+ id: string;
214
+ workflowRunId: string;
215
+ name: string | null;
216
+ phone: string | null;
217
+ email: string | null;
218
+ channel: WorkflowWaitChannelEnum;
219
+ expiresAt: string | null;
220
+ resolvedAt: string | null;
221
+ createdAt: string;
222
+ }
223
+
224
+ /**
225
+ * Workflow recipient GraphQL data
226
+ */
227
+
228
+ export interface WorkflowRecipientGQL {
229
+ accountId: string | null;
230
+ name: string | null;
231
+ phone: string | null;
232
+ email: string | null;
233
+ channels: WorkflowWaitChannelEnum[];
234
+ }
235
+
236
+ export interface WorkflowRunGQL {
237
+ __deleted?: boolean;
238
+
239
+ id: string;
240
+ workflowId: string;
241
+ logId: string | null;
242
+ runKey: string;
243
+ iterations: number;
244
+ progressReport: string | null;
245
+ message: string | null;
246
+ status: WorkflowStatusEnum;
247
+ scheduledDate: string | null;
248
+ followUpAt: string | null;
249
+ activityAt: string;
250
+ activeWait?: WorkflowRunWaitGQL | null;
251
+ workflow?: Pick<WorkflowGQL, 'id' | 'kind' | 'title'> | null;
252
+ cursor?: string;
253
+ }
254
+
255
+ /**
256
+ * Workflow list query filters (GraphQL input shapes)
257
+ */
258
+
259
+ export interface WorkflowsFilterGQL {
260
+ kind?: WorkflowKindEnum | null;
261
+ startDate?: number | string | null;
262
+ endDate?: number | string | null;
263
+ }
264
+
265
+ export interface WorkflowRunsFilterGQL extends WorkflowsFilterGQL {
266
+ workflowId?: string | null;
267
+ statuses?: WorkflowStatusEnum[] | null;
268
+ }
269
+
270
+ /**
271
+ * Workflow GraphQL data
272
+ */
273
+
274
+ export interface WorkflowGQL {
275
+ __deleted?: boolean;
276
+
277
+ id: string;
278
+ organizationId: string;
279
+ fieldDocId: string | null;
280
+ dataTables?: Array<
281
+ Pick<DataTableGQL, 'id' | 'name' | 'title' | 'description' | 'deletedAt'>
282
+ >;
283
+
284
+ kind: WorkflowKindEnum;
285
+ triggerType: WorkflowTriggerTypeEnum;
286
+ logTypes: string[] | null;
287
+
288
+ accountId: string | null;
289
+ recipients: WorkflowRecipientGQL[] | null;
290
+ latestRun?: WorkflowRunGQL | null;
291
+ cursor?: string;
292
+
293
+ title: string;
294
+ steps: LabelAndValue[];
295
+
296
+ schedule: string | null;
297
+ scheduleInterval: number;
298
+ active: boolean;
299
+ status?: WorkflowLifecycleStatusEnum | null; // Derived on the server; never stored
300
+
301
+ startedAt: string | null;
302
+ nextAt: string | null;
303
+ createdAt: string;
304
+ updatedAt: string;
305
+ }