@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.
- package/package.json +140 -54
- package/src/constants/agentMemory.ts +123 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +21 -21
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +125 -7
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +14 -408
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2207 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -21
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +126 -14
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +80 -7
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +836 -780
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/types/account.d.ts +4 -1
- package/src/types/agentMemory.d.ts +98 -0
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +115 -403
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +184 -24
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +10 -1
- package/src/types/log.d.ts +254 -295
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +91 -43
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +678 -129
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +449 -129
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +315 -54
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1174 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +95 -618
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +317 -51
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +276 -192
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +337 -84
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +199 -107
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +22 -12
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +334 -40
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/organization.ts +0 -65
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
package/src/utils/table-route.ts
CHANGED
|
@@ -2,36 +2,48 @@ export const TABLE_ROUTE_COLUMN_MIN_WIDTH = 50;
|
|
|
2
2
|
export const TABLE_ROUTE_COLUMN_MAX_WIDTH = 800;
|
|
3
3
|
|
|
4
4
|
export type TableRouteColumnWidths = Record<string, number>;
|
|
5
|
+
export type TableRouteColumnOrder = string[];
|
|
5
6
|
|
|
6
7
|
export interface OrganizationRouteSettingsObj {
|
|
7
8
|
columnWidths?: TableRouteColumnWidths | null;
|
|
9
|
+
columnOrder?: TableRouteColumnOrder | null;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
/*
|
|
11
13
|
* Keep a user-resized route table column width inside a practical range.
|
|
12
14
|
*/
|
|
13
15
|
export function clampTableRouteColumnWidth(width: number) {
|
|
14
|
-
return Math.min(
|
|
16
|
+
return Math.min(
|
|
17
|
+
TABLE_ROUTE_COLUMN_MAX_WIDTH,
|
|
18
|
+
Math.max(TABLE_ROUTE_COLUMN_MIN_WIDTH, Math.round(width)),
|
|
19
|
+
);
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
/*
|
|
18
23
|
* Return whether a route table column key can be safely stored in settings JSONB.
|
|
19
24
|
*/
|
|
20
|
-
export function isValidTableRouteColumnSettingsKey(
|
|
25
|
+
export function isValidTableRouteColumnSettingsKey(
|
|
26
|
+
value: string | null | undefined,
|
|
27
|
+
) {
|
|
21
28
|
return !!value && /^[A-Za-z0-9_-]+$/.test(value);
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
/*
|
|
25
32
|
* Return whether a table route id can be safely stored in settings JSONB.
|
|
26
33
|
*/
|
|
27
|
-
export function isValidTableRouteIdSettingsKey(
|
|
34
|
+
export function isValidTableRouteIdSettingsKey(
|
|
35
|
+
value: string | null | undefined,
|
|
36
|
+
) {
|
|
28
37
|
return !!value && /^[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/.test(value);
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
/*
|
|
32
41
|
* Return the app route id used for organization table settings.
|
|
33
42
|
*/
|
|
34
|
-
export function getTableRouteIdFromPathname(
|
|
43
|
+
export function getTableRouteIdFromPathname(
|
|
44
|
+
pathname: string,
|
|
45
|
+
fallbackRouteId = 'table',
|
|
46
|
+
) {
|
|
35
47
|
const segments = pathname.split('/').filter(Boolean);
|
|
36
48
|
const routeSegments = segments[0] === 'app' ? segments.slice(1) : segments;
|
|
37
49
|
const routeId = routeSegments.join('/');
|
|
@@ -42,7 +54,9 @@ export function getTableRouteIdFromPathname(pathname: string, fallbackRouteId =
|
|
|
42
54
|
/*
|
|
43
55
|
* Return the route id from an OrgRoute cursor shaped as [organizationId, 0, routeId].
|
|
44
56
|
*/
|
|
45
|
-
export function getTableRouteIdFromOrgRouteCursor(
|
|
57
|
+
export function getTableRouteIdFromOrgRouteCursor(
|
|
58
|
+
cursor: string | null | undefined,
|
|
59
|
+
) {
|
|
46
60
|
const routeId = String(cursor || '').split(':')[2];
|
|
47
61
|
|
|
48
62
|
return isValidTableRouteIdSettingsKey(routeId) ? routeId : null;
|
|
@@ -51,7 +65,9 @@ export function getTableRouteIdFromOrgRouteCursor(cursor: string | null | undefi
|
|
|
51
65
|
/*
|
|
52
66
|
* Convert GraphQL OrgRoute column width strings into a keyed width object.
|
|
53
67
|
*/
|
|
54
|
-
export function getTableRouteColumnWidthsFromStrings(
|
|
68
|
+
export function getTableRouteColumnWidthsFromStrings(
|
|
69
|
+
values: string[] | null | undefined,
|
|
70
|
+
) {
|
|
55
71
|
if (!Array.isArray(values)) {
|
|
56
72
|
return {};
|
|
57
73
|
}
|
|
@@ -63,7 +79,11 @@ export function getTableRouteColumnWidthsFromStrings(values: string[] | null | u
|
|
|
63
79
|
const [columnKey, widthValue] = parts;
|
|
64
80
|
const width = Number(widthValue);
|
|
65
81
|
|
|
66
|
-
if (
|
|
82
|
+
if (
|
|
83
|
+
parts.length !== 2 ||
|
|
84
|
+
!isValidTableRouteColumnSettingsKey(columnKey) ||
|
|
85
|
+
!Number.isFinite(width)
|
|
86
|
+
) {
|
|
67
87
|
continue;
|
|
68
88
|
}
|
|
69
89
|
|
|
@@ -76,13 +96,18 @@ export function getTableRouteColumnWidthsFromStrings(values: string[] | null | u
|
|
|
76
96
|
/*
|
|
77
97
|
* Convert a keyed column width object into GraphQL OrgRoute width strings.
|
|
78
98
|
*/
|
|
79
|
-
export function getTableRouteColumnWidthStrings(
|
|
99
|
+
export function getTableRouteColumnWidthStrings(
|
|
100
|
+
widths: TableRouteColumnWidths | null | undefined,
|
|
101
|
+
) {
|
|
80
102
|
if (!widths) {
|
|
81
103
|
return [];
|
|
82
104
|
}
|
|
83
105
|
|
|
84
106
|
return Object.entries(widths).reduce((acc, [columnKey, width]) => {
|
|
85
|
-
if (
|
|
107
|
+
if (
|
|
108
|
+
!isValidTableRouteColumnSettingsKey(columnKey) ||
|
|
109
|
+
!Number.isFinite(width)
|
|
110
|
+
) {
|
|
86
111
|
return acc;
|
|
87
112
|
}
|
|
88
113
|
|
|
@@ -91,6 +116,74 @@ export function getTableRouteColumnWidthStrings(widths: TableRouteColumnWidths |
|
|
|
91
116
|
}, [] as string[]);
|
|
92
117
|
}
|
|
93
118
|
|
|
119
|
+
/*
|
|
120
|
+
* Return a unique ordered column key list from GraphQL route settings values.
|
|
121
|
+
*/
|
|
122
|
+
export function getTableRouteColumnOrderFromStrings(
|
|
123
|
+
values: string[] | null | undefined,
|
|
124
|
+
) {
|
|
125
|
+
if (!Array.isArray(values)) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const seenColumnKeys = new Set<string>();
|
|
130
|
+
|
|
131
|
+
return values.reduce((acc, value) => {
|
|
132
|
+
const columnKey = String(value || '');
|
|
133
|
+
|
|
134
|
+
if (
|
|
135
|
+
!isValidTableRouteColumnSettingsKey(columnKey) ||
|
|
136
|
+
seenColumnKeys.has(columnKey)
|
|
137
|
+
) {
|
|
138
|
+
return acc;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
seenColumnKeys.add(columnKey);
|
|
142
|
+
acc.push(columnKey);
|
|
143
|
+
return acc;
|
|
144
|
+
}, [] as TableRouteColumnOrder);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
* Convert an ordered column key list into GraphQL OrgRoute order strings.
|
|
149
|
+
*/
|
|
150
|
+
export function getTableRouteColumnOrderStrings(
|
|
151
|
+
columnOrder: TableRouteColumnOrder | null | undefined,
|
|
152
|
+
) {
|
|
153
|
+
return getTableRouteColumnOrderFromStrings(columnOrder);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/*
|
|
157
|
+
* Return a complete column order from saved keys and the current table design keys.
|
|
158
|
+
*/
|
|
159
|
+
export function getTableRouteColumnOrderFromColumnKeys(
|
|
160
|
+
columnKeys: string[],
|
|
161
|
+
columnOrder: TableRouteColumnOrder | null | undefined,
|
|
162
|
+
) {
|
|
163
|
+
const validColumnKeys = columnKeys.filter(isValidTableRouteColumnSettingsKey);
|
|
164
|
+
const validColumnKeySet = new Set(validColumnKeys);
|
|
165
|
+
const seenColumnKeys = new Set<string>();
|
|
166
|
+
const orderedColumnKeys = getTableRouteColumnOrderFromStrings(
|
|
167
|
+
columnOrder,
|
|
168
|
+
).reduce((acc, columnKey) => {
|
|
169
|
+
if (!validColumnKeySet.has(columnKey) || seenColumnKeys.has(columnKey)) {
|
|
170
|
+
return acc;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
seenColumnKeys.add(columnKey);
|
|
174
|
+
acc.push(columnKey);
|
|
175
|
+
return acc;
|
|
176
|
+
}, [] as TableRouteColumnOrder);
|
|
177
|
+
|
|
178
|
+
validColumnKeys.forEach((columnKey) => {
|
|
179
|
+
if (!seenColumnKeys.has(columnKey)) {
|
|
180
|
+
orderedColumnKeys.push(columnKey);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return orderedColumnKeys;
|
|
185
|
+
}
|
|
186
|
+
|
|
94
187
|
/*
|
|
95
188
|
* Convert a settings routes object into one GraphQL-friendly route settings list.
|
|
96
189
|
*/
|
|
@@ -106,6 +199,7 @@ export function getOrganizationSettingsRoutesList(
|
|
|
106
199
|
.map(([routeId, route]) => ({
|
|
107
200
|
routeId,
|
|
108
201
|
columnWidths: route?.columnWidths || {},
|
|
202
|
+
columnOrder: getTableRouteColumnOrderStrings(route?.columnOrder),
|
|
109
203
|
}));
|
|
110
204
|
}
|
|
111
205
|
|
|
@@ -113,14 +207,36 @@ export function getOrganizationSettingsRoutesList(
|
|
|
113
207
|
* Return route column widths from GraphQL OrganizationSettings.routes data.
|
|
114
208
|
*/
|
|
115
209
|
export function getTableRouteColumnWidthsFromSettingsRoutes(
|
|
116
|
-
routes:
|
|
210
|
+
routes:
|
|
211
|
+
| { id?: string | null; columnWidths?: string[] | null }[]
|
|
212
|
+
| null
|
|
213
|
+
| undefined,
|
|
117
214
|
routeId: string,
|
|
118
215
|
) {
|
|
119
|
-
const route = routes?.find(
|
|
216
|
+
const route = routes?.find(
|
|
217
|
+
(item) => getTableRouteIdFromOrgRouteCursor(item?.id) === routeId,
|
|
218
|
+
);
|
|
120
219
|
|
|
121
220
|
return getTableRouteColumnWidthsFromStrings(route?.columnWidths);
|
|
122
221
|
}
|
|
123
222
|
|
|
223
|
+
/*
|
|
224
|
+
* Return route column order from GraphQL OrganizationSettings.routes data.
|
|
225
|
+
*/
|
|
226
|
+
export function getTableRouteColumnOrderFromSettingsRoutes(
|
|
227
|
+
routes:
|
|
228
|
+
| { id?: string | null; columnOrder?: string[] | null }[]
|
|
229
|
+
| null
|
|
230
|
+
| undefined,
|
|
231
|
+
routeId: string,
|
|
232
|
+
) {
|
|
233
|
+
const route = routes?.find(
|
|
234
|
+
(item) => getTableRouteIdFromOrgRouteCursor(item?.id) === routeId,
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
return getTableRouteColumnOrderFromStrings(route?.columnOrder);
|
|
238
|
+
}
|
|
239
|
+
|
|
124
240
|
/*
|
|
125
241
|
* Keep only local width patches that have not been confirmed by server settings.
|
|
126
242
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* Recognize a minute-precision local clock time without introducing a date or timezone. */
|
|
2
|
+
export function isCanonicalClockTime(value: unknown): value is string {
|
|
3
|
+
return typeof value === 'string' && value.length === 5 && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/* Format canonical clock times while retaining invalid historical input visibly for review. */
|
|
7
|
+
export function formatClockTime(value: string, militaryTime = false): string {
|
|
8
|
+
if (!isCanonicalClockTime(value) || militaryTime) return value;
|
|
9
|
+
const [hours, minutes] = value.split(':');
|
|
10
|
+
const hour = Number(hours);
|
|
11
|
+
return `${hour % 12 || 12}:${minutes} ${hour < 12 ? 'AM' : 'PM'}`;
|
|
12
|
+
}
|
package/src/utils/workflow.ts
CHANGED
|
@@ -1,43 +1,191 @@
|
|
|
1
|
-
import { hhmmFromDateOrTime } from '@jsb188/app/utils/timeZone.ts';
|
|
2
1
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
+
import { normalizeArrayLikeValue } from '@jsb188/app/utils/object.ts';
|
|
3
|
+
import { buildSingleText, type BuildSingleTextLine } from '@jsb188/app/utils/string.ts';
|
|
4
|
+
import { hhmmFromDateOrTime } from '@jsb188/app/utils/timeZone.ts';
|
|
3
5
|
import { CronExpressionParser } from 'cron-parser';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
import type {
|
|
7
|
+
WorkflowData,
|
|
8
|
+
WorkflowGQL,
|
|
9
|
+
WorkflowLifecycleStatusEnum,
|
|
10
|
+
WorkflowRunData,
|
|
11
|
+
WorkflowStatusEnum,
|
|
12
|
+
} from '../types/workflow.d.ts';
|
|
13
|
+
import { getTaxonomyActivityLabel, getTaxonomyGroupLabel, humanizeRegistryKey } from './logTaxonomyDisplay.ts';
|
|
14
|
+
import { getWorkflowTriggerActivity, isWorkflowTriggerKeyAllowed } from './workflowTriggers.ts';
|
|
7
15
|
|
|
8
16
|
const DEFAULT_SCHEDULE_WINDOW_MS = 24 * 60 * 60 * 1000; // once per day
|
|
9
17
|
|
|
10
18
|
/**
|
|
11
|
-
*
|
|
19
|
+
* Normalize workflow log types from database, cache, or API-shaped values.
|
|
12
20
|
*/
|
|
13
21
|
|
|
14
|
-
export function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
22
|
+
export function normalizeWorkflowLogTypes(logTypes: unknown): string[] | null {
|
|
23
|
+
const rawLogTypes = normalizeArrayLikeValue(logTypes);
|
|
24
|
+
|
|
25
|
+
const normalizedLogTypes = (rawLogTypes || [])
|
|
26
|
+
.map((logType) => (typeof logType === 'string' ? logType.trim() : ''))
|
|
27
|
+
.filter((logType) => !!logType && logType.toUpperCase() !== 'NULL');
|
|
28
|
+
|
|
29
|
+
return normalizedLogTypes.length ? normalizedLogTypes : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Resolve a workflow group or activity label with a registry-key fallback.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export function getWorkflowLogTypeLabel(logType: string, short: boolean = false, operation?: string | null): string {
|
|
37
|
+
const activity = getWorkflowTriggerActivity(logType);
|
|
38
|
+
if (activity !== null)
|
|
39
|
+
return short && i18n.has(`log.activity_short.${activity}`)
|
|
40
|
+
? i18n.t(`log.activity_short.${activity}`)
|
|
41
|
+
: getTaxonomyActivityLabel(null, activity);
|
|
42
|
+
if (logType === 'MARKET_OPERATION' || (logType === 'OPERATION' && operation === 'FARMERS_MARKET'))
|
|
43
|
+
return getTaxonomyGroupLabel(null, logType, operation, short);
|
|
44
|
+
const i18nKey = `log.type${short ? '_short' : ''}.${logType}`;
|
|
45
|
+
if (i18n.has(i18nKey)) {
|
|
46
|
+
return i18n.t(i18nKey);
|
|
47
|
+
}
|
|
48
|
+
if (!short && i18n.has(`log.type_short.${logType}`)) {
|
|
49
|
+
return i18n.t(`log.type_short.${logType}`);
|
|
50
|
+
}
|
|
51
|
+
return humanizeRegistryKey(logType);
|
|
18
52
|
}
|
|
19
53
|
|
|
20
54
|
/**
|
|
21
55
|
* Get the short workflow label used in cards and headers.
|
|
22
56
|
*/
|
|
23
57
|
|
|
24
|
-
export function getWorkflowShortLabel(workflow: Pick<WorkflowGQL, '
|
|
25
|
-
const
|
|
58
|
+
export function getWorkflowShortLabel(workflow: Pick<WorkflowGQL, 'logTypes'>, operation?: string | null) {
|
|
59
|
+
const firstLogType = workflow.logTypes?.[0];
|
|
26
60
|
|
|
27
|
-
return
|
|
28
|
-
? i18n.t(`log.type_short.${logType}`)
|
|
29
|
-
: i18n.t(feature ? `product.feature_short.${feature}` : 'product.workflow');
|
|
61
|
+
return firstLogType ? getWorkflowLogTypeLabel(firstLogType, true, operation) : i18n.t('c.workflow');
|
|
30
62
|
}
|
|
31
63
|
|
|
32
64
|
/**
|
|
33
|
-
*
|
|
65
|
+
* Check whether a workflow has an active trigger target. App interaction
|
|
66
|
+
* subscriptions never match a log, so they are not a target. A workflow an
|
|
67
|
+
* agent note manages (an insight tracker) always has one: its log triggers,
|
|
68
|
+
* or the web form campaigns it is bound to.
|
|
34
69
|
*/
|
|
35
70
|
|
|
36
|
-
export function
|
|
37
|
-
|
|
38
|
-
values?: Record<string, any> | null,
|
|
39
|
-
timeZone: string | null = null,
|
|
71
|
+
export function hasWorkflowActiveTarget(
|
|
72
|
+
workflow: Pick<WorkflowGQL, 'logTypes' | 'fieldDocId' | 'nextAt'> & Partial<Pick<WorkflowGQL, 'agentNoteId'>>,
|
|
40
73
|
) {
|
|
74
|
+
return (
|
|
75
|
+
!!workflow.nextAt || !!workflow.logTypes?.some(isWorkflowTriggerKeyAllowed) || !!workflow.fieldDocId || !!workflow.agentNoteId
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Check whether a workflow should display as active.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
export function isWorkflowActive(
|
|
84
|
+
workflow: Pick<WorkflowGQL, 'active' | 'logTypes' | 'fieldDocId' | 'nextAt'> & Partial<Pick<WorkflowGQL, 'agentNoteId'>>,
|
|
85
|
+
) {
|
|
86
|
+
return !!workflow.active && hasWorkflowActiveTarget(workflow);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Check whether a workflow row is a reminder (kind=REMINDER).
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
export function isReminder(workflow: Pick<WorkflowGQL, 'kind'>) {
|
|
94
|
+
return workflow.kind === 'REMINDER';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Check whether a reminder is still actionable (cancelable): scheduled to
|
|
99
|
+
* fire, or already fired with its run still ongoing. Completed and canceled
|
|
100
|
+
* reminders are not active.
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
export function isReminderActive(reminder: Pick<WorkflowGQL, 'status'>) {
|
|
104
|
+
return reminder.status === 'SCHEDULED' || reminder.status === 'IN_PROGRESS';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Derive the lifecycle status for a workflow or reminder.
|
|
109
|
+
* `active` is pure user intent (enabled vs canceled/paused); everything
|
|
110
|
+
* time- or run-dependent is derived at read time so it can never go stale.
|
|
111
|
+
* An inactive reminder whose terminal record (values.reminderEnd) says
|
|
112
|
+
* COMPLETED is COMPLETED; every other inactive reminder is INACTIVE.
|
|
113
|
+
* For a fired one-time reminder the latest run decides ongoing vs completed;
|
|
114
|
+
* pass `latestRun` as undefined when the run state is unknown, and the
|
|
115
|
+
* result is undefined too (callers omit the field instead of guessing).
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
export function getWorkflowLifecycleStatus(
|
|
119
|
+
workflow: Pick<WorkflowGQL, 'kind' | 'active' | 'logTypes' | 'fieldDocId' | 'nextAt'> &
|
|
120
|
+
Partial<Pick<WorkflowGQL, 'agentNoteId'>> &
|
|
121
|
+
Partial<Pick<WorkflowData, 'values'>>,
|
|
122
|
+
latestRun?: {
|
|
123
|
+
status: WorkflowStatusEnum;
|
|
124
|
+
followUpAt: Date | string | null;
|
|
125
|
+
} | null,
|
|
126
|
+
now = new Date(),
|
|
127
|
+
): WorkflowLifecycleStatusEnum | undefined {
|
|
128
|
+
if (!isReminder(workflow)) {
|
|
129
|
+
return isWorkflowActive(workflow) ? 'ACTIVE' : 'INACTIVE';
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!workflow.active) {
|
|
133
|
+
return workflow.values?.reminderEnd?.outcome === 'COMPLETED' ? 'COMPLETED' : 'INACTIVE';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (workflow.nextAt || workflow.values?.agentTask?.trigger === 'SOURCE_CHANGE') {
|
|
137
|
+
return 'SCHEDULED';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Fired one-time reminder; the latest run decides ongoing vs completed
|
|
141
|
+
|
|
142
|
+
if (latestRun === undefined) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return isWorkflowRunSettled(latestRun, now) ? 'COMPLETED' : 'IN_PROGRESS';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Check whether a workflow run is settled (no further automatic action will occur).
|
|
151
|
+
* An open run counts as ongoing only while it has a future resume point;
|
|
152
|
+
* both reply waits and scheduled follow-ups set followUpAt on the run.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
export function isWorkflowRunSettled(
|
|
156
|
+
workflowRun:
|
|
157
|
+
| {
|
|
158
|
+
status: WorkflowStatusEnum;
|
|
159
|
+
followUpAt: Date | string | null;
|
|
160
|
+
}
|
|
161
|
+
| null
|
|
162
|
+
| undefined,
|
|
163
|
+
now = new Date(),
|
|
164
|
+
) {
|
|
165
|
+
if (!workflowRun) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!['QUEUED', 'STARTED'].includes(workflowRun.status)) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return !workflowRun.followUpAt || new Date(workflowRun.followUpAt) <= now;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Check whether a reminder repeats on a cron schedule.
|
|
178
|
+
*/
|
|
179
|
+
|
|
180
|
+
export function isRecurringReminder(workflow: Pick<WorkflowGQL, 'triggerType'>) {
|
|
181
|
+
return workflow.triggerType === 'SCHEDULE';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Replace workflow template values in text using {{key}} placeholders
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
export function replaceWorkflowTemplateValues(text: string, values?: Record<string, any> | null, timeZone: string | null = null) {
|
|
41
189
|
if (!text || !values || typeof values !== 'object' || Array.isArray(values)) {
|
|
42
190
|
return text;
|
|
43
191
|
}
|
|
@@ -69,6 +217,165 @@ export function replaceWorkflowTemplateValues(
|
|
|
69
217
|
});
|
|
70
218
|
}
|
|
71
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Render one workflow instruction section with the same truthy config and placeholder rules.
|
|
222
|
+
* A null config enables no conditional keys and leaves every placeholder unchanged.
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
export function renderWorkflowInstruction(
|
|
226
|
+
instruction: string | BuildSingleTextLine[] | null | undefined,
|
|
227
|
+
config: Record<string, any> | null = {},
|
|
228
|
+
timeZone: string | null = null,
|
|
229
|
+
) {
|
|
230
|
+
const text =
|
|
231
|
+
typeof instruction === 'string'
|
|
232
|
+
? instruction
|
|
233
|
+
: buildSingleText(
|
|
234
|
+
instruction || [],
|
|
235
|
+
' ',
|
|
236
|
+
Object.keys(config || {}).filter((key) => config?.[key]),
|
|
237
|
+
);
|
|
238
|
+
return replaceWorkflowTemplateValues(text, config, timeZone);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/*
|
|
242
|
+
* Render a reminder's main content, omitting unread columns from partial realtime updates.
|
|
243
|
+
*/
|
|
244
|
+
export function getReminderContent(workflow: Pick<WorkflowData, 'kind' | 'instructions' | 'values'>, timeZone: string | null = null) {
|
|
245
|
+
if (workflow.kind === undefined || workflow.instructions === undefined) return undefined;
|
|
246
|
+
if (workflow.kind !== 'REMINDER') return null;
|
|
247
|
+
return renderWorkflowInstruction(workflow.instructions?.main, workflow.values?.config, timeZone).trim() || null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Compose a program-managed workflow's catalog instructions with the organization's user instructions.
|
|
252
|
+
* Blank user instructions leave the catalog text unchanged; otherwise they follow it under a "User instructions:" heading.
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
export function composeWorkflowUserInstructions(catalogText: string, userInstructions: string | null | undefined): string {
|
|
256
|
+
const user = userInstructions?.trim();
|
|
257
|
+
if (!user) return catalogText;
|
|
258
|
+
return [catalogText.trim(), `User instructions:\n${user}`].filter(Boolean).join('\n');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Return the first plain-text line of a workflow instruction (e.g. a reminder task).
|
|
263
|
+
* A string instruction is returned whole instead of its first character.
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
export function getWorkflowInstructionFirstLine(instruction: string | BuildSingleTextLine[] | null | undefined) {
|
|
267
|
+
if (typeof instruction === 'string') {
|
|
268
|
+
return instruction;
|
|
269
|
+
}
|
|
270
|
+
return Array.isArray(instruction) && typeof instruction[0] === 'string' ? instruction[0] : null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Build special step template values that are not stored in workflow config.
|
|
275
|
+
*/
|
|
276
|
+
|
|
277
|
+
export function makeWorkflowDataTableVariableValues(dataTableNames: string[] | null | undefined) {
|
|
278
|
+
return dataTableNames?.length ? { data_table_names: dataTableNames.join(', ') } : null;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Resolve required config keys for one conditional step override.
|
|
283
|
+
* Without an explicit list, placeholders in the override value are required.
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
function getRequiredWorkflowConfigKeys(required: unknown, value: unknown) {
|
|
287
|
+
if (Array.isArray(required)) {
|
|
288
|
+
return required as unknown[];
|
|
289
|
+
} else if (typeof value !== 'string' || !value) {
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const templateKeys = new Set<string>();
|
|
294
|
+
for (const match of value.matchAll(/{{(.*?)}}/g)) {
|
|
295
|
+
const key = String(match[1] || '').trim();
|
|
296
|
+
if (key) {
|
|
297
|
+
templateKeys.add(key);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return Array.from(templateKeys);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Check whether all required config keys exist and are non-falsy (the string '0' counts as falsy).
|
|
306
|
+
*/
|
|
307
|
+
|
|
308
|
+
function hasRequiredWorkflowConfigValues(config: unknown, required: unknown, value: unknown) {
|
|
309
|
+
const requiredKeys = getRequiredWorkflowConfigKeys(required, value);
|
|
310
|
+
if (!requiredKeys.length) {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (!config || typeof config !== 'object' || Array.isArray(config)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const values = config as Record<string, unknown>;
|
|
319
|
+
return requiredKeys.every((key) => typeof key === 'string' && key in values && !!values[key] && values[key] !== '0');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Find the first conditional step override whose required config values are satisfied.
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
function findWorkflowConditionalStep(step: any, config: unknown) {
|
|
327
|
+
if (!step || typeof step !== 'object' || !Array.isArray(step.conditional)) {
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
step.conditional.find(
|
|
333
|
+
(conditionalStep: any) =>
|
|
334
|
+
conditionalStep &&
|
|
335
|
+
typeof conditionalStep === 'object' &&
|
|
336
|
+
hasRequiredWorkflowConfigValues(config, conditionalStep.required, conditionalStep.value),
|
|
337
|
+
) || null
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Merge one workflow step with its first matching conditional override and render its value.
|
|
343
|
+
*/
|
|
344
|
+
|
|
345
|
+
function resolveWorkflowStep(step: any, config: Record<string, any> | null, timeZone: string | null = null) {
|
|
346
|
+
if (!step || typeof step !== 'object') {
|
|
347
|
+
return step;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const conditionalStep = findWorkflowConditionalStep(step, config);
|
|
351
|
+
const { required: _required, ...conditionalStepValues } = conditionalStep || {};
|
|
352
|
+
const mappedStep = conditionalStep ? { ...step, ...conditionalStepValues } : step;
|
|
353
|
+
|
|
354
|
+
return {
|
|
355
|
+
label: mappedStep.label,
|
|
356
|
+
value: typeof mappedStep.value === 'string' ? replaceWorkflowTemplateValues(mappedStep.value, config, timeZone) : undefined,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Check whether one resolved workflow step has visible text.
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
function hasWorkflowStepValue(step: any) {
|
|
365
|
+
return !!step && typeof step.value === 'string' && step.value.trim() !== '';
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Resolve ordered conditional overrides and placeholders for every workflow step.
|
|
370
|
+
* Steps left without visible text are dropped. Runtime reads and authoring previews share this.
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
export function resolveWorkflowSteps(steps: unknown, config: Record<string, any> | null, timeZone: string | null = null): any[] {
|
|
374
|
+
return (Array.isArray(steps) ? steps : [])
|
|
375
|
+
.map((step) => resolveWorkflowStep(step, config, timeZone))
|
|
376
|
+
.filter((step) => hasWorkflowStepValue(step));
|
|
377
|
+
}
|
|
378
|
+
|
|
72
379
|
/**
|
|
73
380
|
* Get window for workflow schedule
|
|
74
381
|
*/
|
|
@@ -79,16 +386,10 @@ function getScheduleWindowMs(schedule: string | null | undefined, nextAt: Date)
|
|
|
79
386
|
}
|
|
80
387
|
|
|
81
388
|
try {
|
|
82
|
-
const nextMs = CronExpressionParser
|
|
83
|
-
.parse(schedule, { currentDate: nextAt })
|
|
84
|
-
.next()
|
|
85
|
-
.toDate()
|
|
86
|
-
.getTime();
|
|
389
|
+
const nextMs = CronExpressionParser.parse(schedule, { currentDate: nextAt }).next().toDate().getTime();
|
|
87
390
|
const diffMs = nextMs - nextAt.getTime();
|
|
88
391
|
|
|
89
|
-
return Number.isFinite(diffMs) && diffMs > 0
|
|
90
|
-
? diffMs
|
|
91
|
-
: DEFAULT_SCHEDULE_WINDOW_MS;
|
|
392
|
+
return Number.isFinite(diffMs) && diffMs > 0 ? diffMs : DEFAULT_SCHEDULE_WINDOW_MS;
|
|
92
393
|
} catch {
|
|
93
394
|
return DEFAULT_SCHEDULE_WINDOW_MS;
|
|
94
395
|
}
|
|
@@ -98,11 +399,7 @@ function getScheduleWindowMs(schedule: string | null | undefined, nextAt: Date)
|
|
|
98
399
|
* Check if current date is within workflow's schedule window
|
|
99
400
|
*/
|
|
100
401
|
|
|
101
|
-
export function isWithinScheduleWindow(
|
|
102
|
-
nextAt: Date | string | null | undefined,
|
|
103
|
-
schedule?: string | null,
|
|
104
|
-
now = new Date(),
|
|
105
|
-
) {
|
|
402
|
+
export function isWithinScheduleWindow(nextAt: Date | string | null | undefined, schedule?: string | null, now = new Date()) {
|
|
106
403
|
const nextAtDate = nextAt ? new Date(nextAt) : null;
|
|
107
404
|
if (!nextAtDate) {
|
|
108
405
|
return false;
|
|
@@ -182,20 +479,17 @@ export function getNextWorkflowScheduleDate(
|
|
|
182
479
|
* Helper; check if workflow run is still active based on next follow-up time.
|
|
183
480
|
*/
|
|
184
481
|
|
|
185
|
-
export function isWorkflowRunActive(
|
|
186
|
-
workflowRun: WorkflowRunData | null,
|
|
187
|
-
isFollowUp: boolean = false,
|
|
188
|
-
) {
|
|
482
|
+
export function isWorkflowRunActive(workflowRun: WorkflowRunData | null, isFollowUp: boolean = false) {
|
|
189
483
|
if (!workflowRun) {
|
|
190
484
|
return false;
|
|
191
485
|
}
|
|
192
486
|
|
|
193
487
|
const nextFollowUpAt = workflowRun.followUpAt;
|
|
194
488
|
if (!nextFollowUpAt) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
489
|
+
if (['COMPLETED', 'ERRORED', 'CANCELED'].includes(workflowRun.status)) {
|
|
490
|
+
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
491
|
+
return workflowRun.activityAt > oneDayAgo;
|
|
492
|
+
}
|
|
199
493
|
|
|
200
494
|
return true;
|
|
201
495
|
}
|