@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.
- package/package.json +105 -35
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +48 -0
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +44 -0
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +13 -0
- package/src/constants/log.ts +7 -366
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -11
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +168 -0
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +61 -0
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1017 -738
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +77 -0
- package/src/schemas/logsQuery.ts +57 -316
- package/src/schemas/organization.ts +53 -213
- package/src/types/account.d.ts +81 -0
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +366 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +142 -0
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +57 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +169 -190
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +175 -76
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +1130 -0
- package/src/types/storage.d.ts +242 -0
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +305 -0
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +849 -0
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +172 -0
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +173 -778
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +683 -81
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4973 -0
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +32 -0
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +262 -0
- package/src/utils/workflow.ts +380 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +12 -0
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -209
- package/src/constants/product.ts +0 -66
- package/src/constants/report.ts +0 -25
- package/src/schemas/childOrganizationsQuery.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -145
- package/src/schemas/reportsQuery.ts +0 -107
- package/src/types/action.d.ts +0 -42
- package/src/types/product.d.ts +0 -173
- package/src/types/report.d.ts +0 -203
- package/src/utils/product-calEvent.ts +0 -508
- package/src/utils/route-helpers.ts +0 -583
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { normalizeArrayLikeValue } from '@jsb188/app/utils/object.ts';
|
|
2
|
+
import { hhmmFromDateOrTime } from '@jsb188/app/utils/timeZone.ts';
|
|
3
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
4
|
+
import { CronExpressionParser } from 'cron-parser';
|
|
5
|
+
import type { LogTypeEnum } from '../types/log.d.ts';
|
|
6
|
+
import type {
|
|
7
|
+
WorkflowGQL,
|
|
8
|
+
WorkflowLifecycleStatusEnum,
|
|
9
|
+
WorkflowRunData,
|
|
10
|
+
WorkflowStatusEnum,
|
|
11
|
+
} from '../types/workflow.d.ts';
|
|
12
|
+
import { getLogCategoryColor } from './log.ts';
|
|
13
|
+
import { humanizeRegistryKey } from './logTaxonomyDisplay.ts';
|
|
14
|
+
|
|
15
|
+
const DEFAULT_SCHEDULE_WINDOW_MS = 24 * 60 * 60 * 1000; // once per day
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Normalize workflow log types from database, cache, or API-shaped values.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export function normalizeWorkflowLogTypes(logTypes: unknown): string[] | null {
|
|
22
|
+
const rawLogTypes = normalizeArrayLikeValue(logTypes);
|
|
23
|
+
|
|
24
|
+
const normalizedLogTypes = (rawLogTypes || [])
|
|
25
|
+
.map((logType) => (typeof logType === 'string' ? logType.trim() : ''))
|
|
26
|
+
.filter((logType) => !!logType && logType.toUpperCase() !== 'NULL');
|
|
27
|
+
|
|
28
|
+
return normalizedLogTypes.length ? normalizedLogTypes : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the workflow display color from its trigger log types.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export function getWorkflowColor(workflow: Pick<WorkflowGQL, 'logTypes'>) {
|
|
36
|
+
const firstLogType = workflow.logTypes?.[0];
|
|
37
|
+
|
|
38
|
+
return firstLogType
|
|
39
|
+
? getLogCategoryColor(firstLogType as LogTypeEnum)
|
|
40
|
+
: 'stone';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a workflow log-group label with a registry-key fallback.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export function getWorkflowLogTypeLabel(
|
|
48
|
+
logType: string,
|
|
49
|
+
short: boolean = false,
|
|
50
|
+
): string {
|
|
51
|
+
const i18nKey = `log.type${short ? '_short' : ''}.${logType}`;
|
|
52
|
+
if (i18n.has(i18nKey)) {
|
|
53
|
+
return i18n.t(i18nKey);
|
|
54
|
+
}
|
|
55
|
+
if (!short && i18n.has(`log.type_short.${logType}`)) {
|
|
56
|
+
return i18n.t(`log.type_short.${logType}`);
|
|
57
|
+
}
|
|
58
|
+
return humanizeRegistryKey(logType);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get the short workflow label used in cards and headers.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
export function getWorkflowShortLabel(workflow: Pick<WorkflowGQL, 'logTypes'>) {
|
|
66
|
+
const firstLogType = workflow.logTypes?.[0];
|
|
67
|
+
|
|
68
|
+
return firstLogType
|
|
69
|
+
? getWorkflowLogTypeLabel(firstLogType, true)
|
|
70
|
+
: i18n.t('form.workflow');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Check whether a workflow has an active trigger target.
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export function hasWorkflowActiveTarget(
|
|
78
|
+
workflow: Pick<WorkflowGQL, 'logTypes' | 'fieldDocId' | 'nextAt'>,
|
|
79
|
+
) {
|
|
80
|
+
return (
|
|
81
|
+
!!workflow.nextAt || !!workflow.logTypes?.length || !!workflow.fieldDocId
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Check whether a workflow should display as active.
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
export function isWorkflowActive(
|
|
90
|
+
workflow: Pick<WorkflowGQL, 'active' | 'logTypes' | 'fieldDocId' | 'nextAt'>,
|
|
91
|
+
) {
|
|
92
|
+
return !!workflow.active && hasWorkflowActiveTarget(workflow);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Check whether a workflow row is a reminder (kind=REMINDER).
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
export function isReminder(workflow: Pick<WorkflowGQL, 'kind'>) {
|
|
100
|
+
return workflow.kind === 'REMINDER';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Check whether a reminder is still actionable (cancelable): scheduled to
|
|
105
|
+
* fire, or already fired with its run still ongoing. Completed and canceled
|
|
106
|
+
* reminders are not active.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
export function isReminderActive(reminder: Pick<WorkflowGQL, 'status'>) {
|
|
110
|
+
return reminder.status === 'SCHEDULED' || reminder.status === 'IN_PROGRESS';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Derive the lifecycle status for a workflow or reminder.
|
|
115
|
+
* `active` is pure user intent (enabled vs canceled/paused); everything
|
|
116
|
+
* time- or run-dependent is derived at read time so it can never go stale.
|
|
117
|
+
* For a fired one-time reminder the latest run decides ongoing vs completed;
|
|
118
|
+
* pass `latestRun` as undefined when the run state is unknown, and the
|
|
119
|
+
* result is undefined too (callers omit the field instead of guessing).
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
export function getWorkflowLifecycleStatus(
|
|
123
|
+
workflow: Pick<
|
|
124
|
+
WorkflowGQL,
|
|
125
|
+
'kind' | 'active' | 'logTypes' | 'fieldDocId' | 'nextAt'
|
|
126
|
+
>,
|
|
127
|
+
latestRun?: {
|
|
128
|
+
status: WorkflowStatusEnum;
|
|
129
|
+
followUpAt: Date | string | null;
|
|
130
|
+
} | null,
|
|
131
|
+
now = new Date(),
|
|
132
|
+
): WorkflowLifecycleStatusEnum | undefined {
|
|
133
|
+
if (!isReminder(workflow)) {
|
|
134
|
+
return isWorkflowActive(workflow) ? 'ACTIVE' : 'INACTIVE';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!workflow.active) {
|
|
138
|
+
return 'INACTIVE';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (workflow.nextAt) {
|
|
142
|
+
return 'SCHEDULED';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Fired one-time reminder; the latest run decides ongoing vs completed
|
|
146
|
+
|
|
147
|
+
if (latestRun === undefined) {
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return isWorkflowRunSettled(latestRun, now) ? 'COMPLETED' : 'IN_PROGRESS';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Check whether a workflow run is settled (no further automatic action will occur).
|
|
156
|
+
* An open run counts as ongoing only while it has a future resume point;
|
|
157
|
+
* both reply waits and scheduled follow-ups set followUpAt on the run.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
export function isWorkflowRunSettled(
|
|
161
|
+
workflowRun:
|
|
162
|
+
| {
|
|
163
|
+
status: WorkflowStatusEnum;
|
|
164
|
+
followUpAt: Date | string | null;
|
|
165
|
+
}
|
|
166
|
+
| null
|
|
167
|
+
| undefined,
|
|
168
|
+
now = new Date(),
|
|
169
|
+
) {
|
|
170
|
+
if (!workflowRun) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!['QUEUED', 'STARTED'].includes(workflowRun.status)) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return !workflowRun.followUpAt || new Date(workflowRun.followUpAt) <= now;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Check whether a reminder repeats on a cron schedule.
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
export function isRecurringReminder(
|
|
186
|
+
workflow: Pick<WorkflowGQL, 'triggerType'>,
|
|
187
|
+
) {
|
|
188
|
+
return workflow.triggerType === 'SCHEDULE';
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Replace workflow template values in text using {{key}} placeholders
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
export function replaceWorkflowTemplateValues(
|
|
196
|
+
text: string,
|
|
197
|
+
values?: Record<string, any> | null,
|
|
198
|
+
timeZone: string | null = null,
|
|
199
|
+
) {
|
|
200
|
+
if (!text || !values || typeof values !== 'object' || Array.isArray(values)) {
|
|
201
|
+
return text;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return text.replace(/{{(.*?)}}/g, (_match, rawKey) => {
|
|
205
|
+
const key = String(rawKey).trim();
|
|
206
|
+
const value = values[key];
|
|
207
|
+
|
|
208
|
+
switch (key) {
|
|
209
|
+
case 'endTime': {
|
|
210
|
+
if (!value) {
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const normalized = String(value).replace(':', '');
|
|
215
|
+
if (!/^[0-9]{3,4}$/.test(normalized)) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
hhmmFromDateOrTime(normalized, null, true, timeZone, true) ||
|
|
221
|
+
String(value)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (value === undefined || value === null || String(value) === '') {
|
|
227
|
+
return `{{${key}}}`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return String(value);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Get window for workflow schedule
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
function getScheduleWindowMs(
|
|
239
|
+
schedule: string | null | undefined,
|
|
240
|
+
nextAt: Date,
|
|
241
|
+
) {
|
|
242
|
+
if (!schedule) {
|
|
243
|
+
return DEFAULT_SCHEDULE_WINDOW_MS;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
const nextMs = CronExpressionParser.parse(schedule, { currentDate: nextAt })
|
|
248
|
+
.next()
|
|
249
|
+
.toDate()
|
|
250
|
+
.getTime();
|
|
251
|
+
const diffMs = nextMs - nextAt.getTime();
|
|
252
|
+
|
|
253
|
+
return Number.isFinite(diffMs) && diffMs > 0
|
|
254
|
+
? diffMs
|
|
255
|
+
: DEFAULT_SCHEDULE_WINDOW_MS;
|
|
256
|
+
} catch {
|
|
257
|
+
return DEFAULT_SCHEDULE_WINDOW_MS;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Check if current date is within workflow's schedule window
|
|
263
|
+
*/
|
|
264
|
+
|
|
265
|
+
export function isWithinScheduleWindow(
|
|
266
|
+
nextAt: Date | string | null | undefined,
|
|
267
|
+
schedule?: string | null,
|
|
268
|
+
now = new Date(),
|
|
269
|
+
) {
|
|
270
|
+
const nextAtDate = nextAt ? new Date(nextAt) : null;
|
|
271
|
+
if (!nextAtDate) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const nextAtMs = nextAtDate.getTime();
|
|
276
|
+
if (!Number.isFinite(nextAtMs)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const nowMs = now.getTime();
|
|
281
|
+
if (!Number.isFinite(nowMs)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const windowMs = getScheduleWindowMs(schedule, nextAtDate);
|
|
286
|
+
const windowEndMs = nextAtMs + windowMs;
|
|
287
|
+
|
|
288
|
+
return nowMs >= nextAtMs && nowMs <= windowEndMs;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Get next workflow schedule date from cron expression.
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Normalize workflow schedule interval into a valid positive integer.
|
|
297
|
+
*/
|
|
298
|
+
|
|
299
|
+
function normalizeScheduleInterval(
|
|
300
|
+
scheduleInterval: number | null | undefined,
|
|
301
|
+
) {
|
|
302
|
+
if (!Number.isFinite(scheduleInterval)) {
|
|
303
|
+
return 1;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const normalized = Math.floor(Number(scheduleInterval));
|
|
307
|
+
return normalized > 0 ? normalized : 1;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Get next workflow schedule date from cron expression and interval.
|
|
312
|
+
*/
|
|
313
|
+
|
|
314
|
+
export function getNextWorkflowScheduleDate(
|
|
315
|
+
schedule: string | null | undefined,
|
|
316
|
+
scheduleInterval: number | null | undefined = 1,
|
|
317
|
+
currentDate: Date | string = new Date(),
|
|
318
|
+
timeZone: string | null = null,
|
|
319
|
+
) {
|
|
320
|
+
if (!schedule) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const current = new Date(currentDate);
|
|
325
|
+
if (!Number.isFinite(current.getTime())) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
const interval = normalizeScheduleInterval(scheduleInterval);
|
|
331
|
+
const parsed = CronExpressionParser.parse(schedule, {
|
|
332
|
+
currentDate: current,
|
|
333
|
+
...(timeZone ? { tz: timeZone } : {}),
|
|
334
|
+
});
|
|
335
|
+
let nextDate: Date | null = null;
|
|
336
|
+
|
|
337
|
+
for (let i = 0; i < interval; i += 1) {
|
|
338
|
+
nextDate = parsed.next().toDate();
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return nextDate;
|
|
342
|
+
} catch {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Helper; check if workflow run is still active based on next follow-up time.
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
export function isWorkflowRunActive(
|
|
352
|
+
workflowRun: WorkflowRunData | null,
|
|
353
|
+
isFollowUp: boolean = false,
|
|
354
|
+
) {
|
|
355
|
+
if (!workflowRun) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const nextFollowUpAt = workflowRun.followUpAt;
|
|
360
|
+
if (!nextFollowUpAt) {
|
|
361
|
+
if (['COMPLETED', 'ERRORED', 'CANCELED'].includes(workflowRun.status)) {
|
|
362
|
+
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
363
|
+
return workflowRun.activityAt > oneDayAgo;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (isFollowUp) {
|
|
370
|
+
const now = new Date();
|
|
371
|
+
const followUpWindowStart = new Date(
|
|
372
|
+
nextFollowUpAt.getTime() - 10 * 60 * 1000,
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
// Allow follow-up run only after entering the 10-minute pre-follow-up window.
|
|
376
|
+
return now >= followUpWindowStart;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return nextFollowUpAt > new Date();
|
|
380
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { DATA_TABLE_FIELD_TYPE_ENUMS } from '@jsb188/mday/constants/dataTable.ts';
|
|
2
|
+
import {
|
|
3
|
+
isDataTableDateLikeFieldType,
|
|
4
|
+
isDataTableNumberLikeFieldType,
|
|
5
|
+
isDataTableWeekFieldType,
|
|
6
|
+
} from '@jsb188/mday/utils/dataTable.ts';
|
|
7
|
+
import {
|
|
8
|
+
buildDataTableFieldTypeDescriptorsFromConstants,
|
|
9
|
+
collectDataTableFieldTypeDescriptorIssues,
|
|
10
|
+
} from '@jsb188/mday/utils/dataTableFieldTypeRegistry.ts';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
|
|
13
|
+
// Pre-registry hardcoded helper results (the historical literals the
|
|
14
|
+
// semantics lookups replaced); every key × helper cell is asserted so a
|
|
15
|
+
// registry row change can never silently flip helper behavior.
|
|
16
|
+
const SEMANTICS_TRUTH_TABLE: Record<
|
|
17
|
+
string,
|
|
18
|
+
{ numberLike: boolean; dateLike: boolean; week: boolean }
|
|
19
|
+
> = {
|
|
20
|
+
TEXT: { numberLike: false, dateLike: false, week: false },
|
|
21
|
+
ID: { numberLike: false, dateLike: false, week: false },
|
|
22
|
+
ID_OR_TEXT: { numberLike: false, dateLike: false, week: false },
|
|
23
|
+
NUMBER: { numberLike: true, dateLike: false, week: false },
|
|
24
|
+
PRICE: { numberLike: true, dateLike: false, week: false },
|
|
25
|
+
BOOLEAN: { numberLike: false, dateLike: false, week: false },
|
|
26
|
+
DATE: { numberLike: false, dateLike: true, week: false },
|
|
27
|
+
WEEK_OF_MON: { numberLike: false, dateLike: true, week: true },
|
|
28
|
+
WEEK_OF_SUN: { numberLike: false, dateLike: true, week: true },
|
|
29
|
+
DATETIME: { numberLike: false, dateLike: false, week: false },
|
|
30
|
+
SELECT: { numberLike: false, dateLike: false, week: false },
|
|
31
|
+
SELECT_OR_TEXT: { numberLike: false, dateLike: false, week: false },
|
|
32
|
+
MULTI_SELECT: { numberLike: false, dateLike: false, week: false },
|
|
33
|
+
JSON: { numberLike: false, dateLike: false, week: false },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe('dataTable field type semantics lookups', () => {
|
|
37
|
+
it('covers exactly the registry enum keys', () => {
|
|
38
|
+
expect(Object.keys(SEMANTICS_TRUTH_TABLE).sort()).toEqual(
|
|
39
|
+
[...DATA_TABLE_FIELD_TYPE_ENUMS].sort(),
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('matches the pre-registry hardcoded results for all 14 keys × 3 helpers', () => {
|
|
44
|
+
for (const fieldType of DATA_TABLE_FIELD_TYPE_ENUMS) {
|
|
45
|
+
const expected = SEMANTICS_TRUTH_TABLE[fieldType];
|
|
46
|
+
expect(
|
|
47
|
+
isDataTableNumberLikeFieldType(fieldType),
|
|
48
|
+
`${fieldType} numberLike`,
|
|
49
|
+
).toBe(expected.numberLike);
|
|
50
|
+
expect(
|
|
51
|
+
isDataTableDateLikeFieldType(fieldType),
|
|
52
|
+
`${fieldType} dateLike`,
|
|
53
|
+
).toBe(expected.dateLike);
|
|
54
|
+
expect(isDataTableWeekFieldType(fieldType), `${fieldType} week`).toBe(
|
|
55
|
+
expected.week,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('returns false for missing and unknown field types', () => {
|
|
61
|
+
for (const fieldType of [null, undefined, 'NOT_A_TYPE' as never]) {
|
|
62
|
+
expect(isDataTableNumberLikeFieldType(fieldType)).toBe(false);
|
|
63
|
+
expect(isDataTableDateLikeFieldType(fieldType)).toBe(false);
|
|
64
|
+
expect(isDataTableWeekFieldType(fieldType)).toBe(false);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('buildDataTableFieldTypeDescriptorsFromConstants', () => {
|
|
70
|
+
it('derives a valid descriptor set in enum order with the seed semantics mapping', () => {
|
|
71
|
+
const descriptors = buildDataTableFieldTypeDescriptorsFromConstants();
|
|
72
|
+
|
|
73
|
+
expect(collectDataTableFieldTypeDescriptorIssues(descriptors)).toEqual([]);
|
|
74
|
+
expect(descriptors.map((descriptor) => descriptor.key)).toEqual([
|
|
75
|
+
...DATA_TABLE_FIELD_TYPE_ENUMS,
|
|
76
|
+
]);
|
|
77
|
+
expect(descriptors.map((descriptor) => descriptor.ordinal)).toEqual(
|
|
78
|
+
DATA_TABLE_FIELD_TYPE_ENUMS.map((_, index) => index),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const semanticsByKey = Object.fromEntries(
|
|
82
|
+
descriptors.map((descriptor) => [
|
|
83
|
+
descriptor.key,
|
|
84
|
+
descriptor.semanticsKey,
|
|
85
|
+
]),
|
|
86
|
+
);
|
|
87
|
+
expect(semanticsByKey.PRICE).toBe('NUMBER');
|
|
88
|
+
expect(semanticsByKey.WEEK_OF_MON).toBe('WEEK');
|
|
89
|
+
expect(semanticsByKey.WEEK_OF_SUN).toBe('WEEK');
|
|
90
|
+
expect(semanticsByKey.TEXT).toBe('TEXT');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('collectDataTableFieldTypeDescriptorIssues', () => {
|
|
95
|
+
it('flags empty sets, duplicates, bad keys, and unknown semantics', () => {
|
|
96
|
+
expect(collectDataTableFieldTypeDescriptorIssues([])).toEqual([
|
|
97
|
+
'registry has no field type rows',
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
const issues = collectDataTableFieldTypeDescriptorIssues([
|
|
101
|
+
{ key: 'TEXT', semanticsKey: 'TEXT', ordinal: 0 },
|
|
102
|
+
{ key: 'TEXT', semanticsKey: 'TEXT', ordinal: 0 },
|
|
103
|
+
{ key: 'bad key', semanticsKey: 'NOPE' as never, ordinal: 1 },
|
|
104
|
+
]);
|
|
105
|
+
expect(issues).toContain('duplicate field type key TEXT');
|
|
106
|
+
expect(issues).toContain('TEXT: duplicate ordinal 0');
|
|
107
|
+
expect(issues).toContain('bad key: invalid field type key');
|
|
108
|
+
expect(issues).toContain('bad key: unknown semanticsKey NOPE');
|
|
109
|
+
});
|
|
110
|
+
});
|