@jsb188/mday 1.1.7 → 1.1.10
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 +39 -20
- package/src/constants/dataTable.ts +22 -0
- package/src/constants/email.ts +28 -0
- package/src/constants/inboundContact.ts +8 -0
- package/src/constants/integration.ts +14 -0
- package/src/constants/log-activityTexts.ts +54 -28
- package/src/constants/log.ts +82 -38
- package/src/constants/organization.ts +11 -2
- package/src/constants/product.ts +9 -33
- package/src/constants/report.ts +29 -10
- package/src/constants/sheet.ts +20 -0
- package/src/constants/square.ts +16 -0
- package/src/constants/storage.ts +12 -0
- package/src/schemas/editLogEntry.ts +90 -44
- package/src/schemas/inboundContact.ts +72 -0
- package/src/schemas/logsQuery.ts +7 -272
- package/src/schemas/organization.ts +11 -174
- package/src/schemas/productsQuery.ts +2 -94
- package/src/schemas/reportsQuery.ts +8 -95
- package/src/types/account.d.ts +78 -0
- package/src/types/dataTable.d.ts +447 -0
- package/src/types/email.d.ts +71 -0
- package/src/types/inboundContact.d.ts +56 -0
- package/src/types/integration.d.ts +42 -0
- package/src/types/log.d.ts +289 -178
- package/src/types/organization.d.ts +106 -50
- package/src/types/product.d.ts +7 -96
- package/src/types/report.d.ts +239 -152
- package/src/types/sheet.d.ts +298 -0
- package/src/types/storage.d.ts +161 -0
- package/src/types/workflow.d.ts +174 -0
- package/src/utils/dataTable.ts +834 -0
- package/src/utils/email.ts +113 -0
- package/src/utils/log.ts +30 -628
- package/src/utils/organization.ts +227 -44
- package/src/utils/product-calEvent.ts +7 -60
- package/src/utils/report.ts +158 -0
- package/src/utils/sheet.ts +170 -0
- package/src/utils/square.ts +22 -0
- package/src/utils/table-route.ts +146 -0
- package/src/utils/workflow.ts +212 -0
- package/tsconfig.json +12 -0
- package/src/schemas/childOrganizationsQuery.ts +0 -44
- package/src/types/action.d.ts +0 -42
- package/src/utils/route-helpers.ts +0 -583
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SHEET_CELL_SOURCE_TYPE_ENUMS,
|
|
3
|
+
SHEET_DEFAULT_COLUMN_COUNT,
|
|
4
|
+
SHEET_DEFAULT_ROW_COUNT,
|
|
5
|
+
SHEET_REGION_CONFLICT_POLICY_ENUMS,
|
|
6
|
+
SHEET_REGION_TYPE_ENUMS,
|
|
7
|
+
SHEET_VIEWPORT_MAX_COLUMNS,
|
|
8
|
+
SHEET_VIEWPORT_MAX_ROWS,
|
|
9
|
+
} from '../constants/sheet.ts';
|
|
10
|
+
import type {
|
|
11
|
+
SheetAxisDesignObj,
|
|
12
|
+
SheetCellSourceTypeEnum,
|
|
13
|
+
SheetDesignObj,
|
|
14
|
+
SheetGridViewportObj,
|
|
15
|
+
SheetRangeData,
|
|
16
|
+
SheetRegionConflictPolicyEnum,
|
|
17
|
+
SheetRegionTypeEnum,
|
|
18
|
+
} from '../types/sheet.d.ts';
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Return a fresh default sheet design object.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function getDefaultSheetDesign(): SheetDesignObj {
|
|
25
|
+
return {
|
|
26
|
+
version: 1,
|
|
27
|
+
grid: {
|
|
28
|
+
rowCount: SHEET_DEFAULT_ROW_COUNT,
|
|
29
|
+
columnCount: SHEET_DEFAULT_COLUMN_COUNT,
|
|
30
|
+
frozenRows: 0,
|
|
31
|
+
frozenColumns: 0,
|
|
32
|
+
},
|
|
33
|
+
columns: {},
|
|
34
|
+
rows: {},
|
|
35
|
+
defaultCellStyle: {},
|
|
36
|
+
defaultCellFormat: {},
|
|
37
|
+
namedRanges: [],
|
|
38
|
+
metadata: {},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Return a sheet design object with all top-level defaults filled in.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export function normalizeSheetDesign(design?: Partial<SheetDesignObj> | null): SheetDesignObj {
|
|
47
|
+
const baseDesign = getDefaultSheetDesign();
|
|
48
|
+
const grid: Partial<SheetDesignObj['grid']> = design?.grid || {};
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...baseDesign,
|
|
52
|
+
...(design || {}),
|
|
53
|
+
version: Number(design?.version || baseDesign.version),
|
|
54
|
+
grid: {
|
|
55
|
+
rowCount: Math.max(1, Math.floor(Number(grid.rowCount || baseDesign.grid.rowCount))),
|
|
56
|
+
columnCount: Math.max(1, Math.floor(Number(grid.columnCount || baseDesign.grid.columnCount))),
|
|
57
|
+
frozenRows: Math.max(0, Math.floor(Number(grid.frozenRows || 0))),
|
|
58
|
+
frozenColumns: Math.max(0, Math.floor(Number(grid.frozenColumns || 0))),
|
|
59
|
+
},
|
|
60
|
+
columns: design?.columns || {},
|
|
61
|
+
rows: design?.rows || {},
|
|
62
|
+
defaultCellStyle: design?.defaultCellStyle || {},
|
|
63
|
+
defaultCellFormat: design?.defaultCellFormat || {},
|
|
64
|
+
namedRanges: Array.isArray(design?.namedRanges) ? design.namedRanges : [],
|
|
65
|
+
metadata: design?.metadata || {},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
* Return a viewport bounded to positive indexes and backend query limits.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
export function normalizeSheetViewport(viewport: Partial<SheetGridViewportObj>): SheetGridViewportObj {
|
|
74
|
+
return {
|
|
75
|
+
startRowIndex: Math.max(1, Math.floor(Number(viewport.startRowIndex || 1))),
|
|
76
|
+
startColumnIndex: Math.max(1, Math.floor(Number(viewport.startColumnIndex || 1))),
|
|
77
|
+
rowCount: Math.min(SHEET_VIEWPORT_MAX_ROWS, Math.max(1, Math.floor(Number(viewport.rowCount || 1)))),
|
|
78
|
+
columnCount: Math.min(SHEET_VIEWPORT_MAX_COLUMNS, Math.max(1, Math.floor(Number(viewport.columnCount || 1)))),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* Return whether one value is a known stored sheet cell source type.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
export function isSheetCellSourceType(value: unknown): value is SheetCellSourceTypeEnum {
|
|
87
|
+
return SHEET_CELL_SOURCE_TYPE_ENUMS.includes(value as SheetCellSourceTypeEnum);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
* Return whether one value is a known sheet region type.
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
export function isSheetRegionType(value: unknown): value is SheetRegionTypeEnum {
|
|
95
|
+
return SHEET_REGION_TYPE_ENUMS.includes(value as SheetRegionTypeEnum);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* Return whether one value is a known sheet region conflict policy.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
export function isSheetRegionConflictPolicy(value: unknown): value is SheetRegionConflictPolicyEnum {
|
|
103
|
+
return SHEET_REGION_CONFLICT_POLICY_ENUMS.includes(value as SheetRegionConflictPolicyEnum);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* Return a shallow merged JSON object, ignoring non-object values.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
export function mergeSheetJSONObjects(...values: Array<Record<string, any> | null | undefined>) {
|
|
111
|
+
return values.reduce<Record<string, any>>((merged, value) => {
|
|
112
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
113
|
+
return merged;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
...merged,
|
|
118
|
+
...value,
|
|
119
|
+
};
|
|
120
|
+
}, {});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/*
|
|
124
|
+
* Return the string key used by sheet design JSON for one column index.
|
|
125
|
+
*/
|
|
126
|
+
|
|
127
|
+
export function getSheetColumnDesignKey(columnIndex: number) {
|
|
128
|
+
return String(Math.max(1, Math.floor(Number(columnIndex) || 1)));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/*
|
|
132
|
+
* Return the string key used by sheet design JSON for one row index.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
export function getSheetRowDesignKey(rowIndex: number) {
|
|
136
|
+
return String(Math.max(1, Math.floor(Number(rowIndex) || 1)));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/*
|
|
140
|
+
* Return whether one row design object represents meaningful row-level content.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
export function sheetAxisDesignHasContent(design?: SheetAxisDesignObj | null) {
|
|
144
|
+
if (!design) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return Object.values(design).some((value) => {
|
|
149
|
+
if (value === null || value === undefined || value === false) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (typeof value === 'object') {
|
|
154
|
+
return Object.keys(value).length > 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return true;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/*
|
|
162
|
+
* Return whether one grid coordinate is inside a saved sheet range.
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
export function isSheetCellInRange(rowIndex: number, columnIndex: number, range: Pick<SheetRangeData, 'startRowIndex' | 'startColumnIndex' | 'endRowIndex' | 'endColumnIndex'>) {
|
|
166
|
+
return rowIndex >= range.startRowIndex &&
|
|
167
|
+
rowIndex <= range.endRowIndex &&
|
|
168
|
+
columnIndex >= range.startColumnIndex &&
|
|
169
|
+
columnIndex <= range.endColumnIndex;
|
|
170
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SquareOAuthScope } from '../constants/square.ts';
|
|
2
|
+
|
|
3
|
+
export type SquareConnectionCapabilities = {
|
|
4
|
+
canReadMerchant: boolean;
|
|
5
|
+
canReadLocations: boolean;
|
|
6
|
+
canViewSalesData: boolean;
|
|
7
|
+
canCreatePaymentRequests: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Convert Square OAuth scopes into app-level capabilities used by UI and agents.
|
|
12
|
+
*/
|
|
13
|
+
export function getSquareConnectionCapabilities(scopes?: string[] | null): SquareConnectionCapabilities {
|
|
14
|
+
const grantedScopes = new Set(scopes || []);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
canReadMerchant: grantedScopes.has('MERCHANT_PROFILE_READ' satisfies SquareOAuthScope),
|
|
18
|
+
canReadLocations: grantedScopes.has('MERCHANT_PROFILE_READ' satisfies SquareOAuthScope),
|
|
19
|
+
canViewSalesData: grantedScopes.has('PAYMENTS_READ' satisfies SquareOAuthScope) || grantedScopes.has('ORDERS_READ' satisfies SquareOAuthScope),
|
|
20
|
+
canCreatePaymentRequests: grantedScopes.has('ORDERS_WRITE' satisfies SquareOAuthScope) && grantedScopes.has('PAYMENTS_WRITE' satisfies SquareOAuthScope),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
export const TABLE_ROUTE_COLUMN_MIN_WIDTH = 50;
|
|
2
|
+
export const TABLE_ROUTE_COLUMN_MAX_WIDTH = 800;
|
|
3
|
+
|
|
4
|
+
export type TableRouteColumnWidths = Record<string, number>;
|
|
5
|
+
|
|
6
|
+
export interface OrganizationRouteSettingsObj {
|
|
7
|
+
columnWidths?: TableRouteColumnWidths | null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Keep a user-resized route table column width inside a practical range.
|
|
12
|
+
*/
|
|
13
|
+
export function clampTableRouteColumnWidth(width: number) {
|
|
14
|
+
return Math.min(TABLE_ROUTE_COLUMN_MAX_WIDTH, Math.max(TABLE_ROUTE_COLUMN_MIN_WIDTH, Math.round(width)));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Return whether a route table column key can be safely stored in settings JSONB.
|
|
19
|
+
*/
|
|
20
|
+
export function isValidTableRouteColumnSettingsKey(value: string | null | undefined) {
|
|
21
|
+
return !!value && /^[A-Za-z0-9_-]+$/.test(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Return whether a table route id can be safely stored in settings JSONB.
|
|
26
|
+
*/
|
|
27
|
+
export function isValidTableRouteIdSettingsKey(value: string | null | undefined) {
|
|
28
|
+
return !!value && /^[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/.test(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* Return the app route id used for organization table settings.
|
|
33
|
+
*/
|
|
34
|
+
export function getTableRouteIdFromPathname(pathname: string, fallbackRouteId = 'table') {
|
|
35
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
36
|
+
const routeSegments = segments[0] === 'app' ? segments.slice(1) : segments;
|
|
37
|
+
const routeId = routeSegments.join('/');
|
|
38
|
+
|
|
39
|
+
return isValidTableRouteIdSettingsKey(routeId) ? routeId : fallbackRouteId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Return the route id from an OrgRoute cursor shaped as [organizationId, 0, routeId].
|
|
44
|
+
*/
|
|
45
|
+
export function getTableRouteIdFromOrgRouteCursor(cursor: string | null | undefined) {
|
|
46
|
+
const routeId = String(cursor || '').split(':')[2];
|
|
47
|
+
|
|
48
|
+
return isValidTableRouteIdSettingsKey(routeId) ? routeId : null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
* Convert GraphQL OrgRoute column width strings into a keyed width object.
|
|
53
|
+
*/
|
|
54
|
+
export function getTableRouteColumnWidthsFromStrings(values: string[] | null | undefined) {
|
|
55
|
+
if (!Array.isArray(values)) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const widths: TableRouteColumnWidths = {};
|
|
60
|
+
|
|
61
|
+
for (const value of values) {
|
|
62
|
+
const parts = String(value || '').split(':');
|
|
63
|
+
const [columnKey, widthValue] = parts;
|
|
64
|
+
const width = Number(widthValue);
|
|
65
|
+
|
|
66
|
+
if (parts.length !== 2 || !isValidTableRouteColumnSettingsKey(columnKey) || !Number.isFinite(width)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
widths[columnKey] = clampTableRouteColumnWidth(width);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return widths;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/*
|
|
77
|
+
* Convert a keyed column width object into GraphQL OrgRoute width strings.
|
|
78
|
+
*/
|
|
79
|
+
export function getTableRouteColumnWidthStrings(widths: TableRouteColumnWidths | null | undefined) {
|
|
80
|
+
if (!widths) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return Object.entries(widths).reduce((acc, [columnKey, width]) => {
|
|
85
|
+
if (!isValidTableRouteColumnSettingsKey(columnKey) || !Number.isFinite(width)) {
|
|
86
|
+
return acc;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
acc.push(`${columnKey}:${clampTableRouteColumnWidth(width)}`);
|
|
90
|
+
return acc;
|
|
91
|
+
}, [] as string[]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* Convert a settings routes object into one GraphQL-friendly route settings list.
|
|
96
|
+
*/
|
|
97
|
+
export function getOrganizationSettingsRoutesList(
|
|
98
|
+
routes: Record<string, OrganizationRouteSettingsObj> | null | undefined,
|
|
99
|
+
) {
|
|
100
|
+
if (!routes) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return Object.entries(routes)
|
|
105
|
+
.filter(([routeId]) => isValidTableRouteIdSettingsKey(routeId))
|
|
106
|
+
.map(([routeId, route]) => ({
|
|
107
|
+
routeId,
|
|
108
|
+
columnWidths: route?.columnWidths || {},
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
* Return route column widths from GraphQL OrganizationSettings.routes data.
|
|
114
|
+
*/
|
|
115
|
+
export function getTableRouteColumnWidthsFromSettingsRoutes(
|
|
116
|
+
routes: { id?: string | null; columnWidths?: string[] | null }[] | null | undefined,
|
|
117
|
+
routeId: string,
|
|
118
|
+
) {
|
|
119
|
+
const route = routes?.find((item) => getTableRouteIdFromOrgRouteCursor(item?.id) === routeId);
|
|
120
|
+
|
|
121
|
+
return getTableRouteColumnWidthsFromStrings(route?.columnWidths);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/*
|
|
125
|
+
* Keep only local width patches that have not been confirmed by server settings.
|
|
126
|
+
*/
|
|
127
|
+
export function removeConfirmedTableRouteColumnWidthPatches(
|
|
128
|
+
localWidths: TableRouteColumnWidths,
|
|
129
|
+
serverWidths: TableRouteColumnWidths,
|
|
130
|
+
) {
|
|
131
|
+
let nextWidths = localWidths;
|
|
132
|
+
|
|
133
|
+
Object.entries(localWidths).forEach(([columnKey, width]) => {
|
|
134
|
+
if (serverWidths[columnKey] !== width) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (nextWidths === localWidths) {
|
|
139
|
+
nextWidths = { ...localWidths };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
delete nextWidths[columnKey];
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return nextWidths;
|
|
146
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { hhmmFromDateOrTime } from '@jsb188/app/utils/timeZone.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import { CronExpressionParser } from 'cron-parser';
|
|
4
|
+
import type { WorkflowGQL, WorkflowRunData } from '../types/workflow';
|
|
5
|
+
import { getLogCategoryColor } from './log.ts';
|
|
6
|
+
import { getOrganizationFeatureColor } from './organization.ts';
|
|
7
|
+
|
|
8
|
+
const DEFAULT_SCHEDULE_WINDOW_MS = 24 * 60 * 60 * 1000; // once per day
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get the workflow display color from its trigger or feature.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export function getWorkflowColor(workflow: Pick<WorkflowGQL, 'logType' | 'feature'>) {
|
|
15
|
+
return workflow.logType
|
|
16
|
+
? getLogCategoryColor(workflow.logType)
|
|
17
|
+
: getOrganizationFeatureColor(workflow.feature);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get the short workflow label used in cards and headers.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function getWorkflowShortLabel(workflow: Pick<WorkflowGQL, 'logType' | 'feature'>) {
|
|
25
|
+
const { logType, feature } = workflow;
|
|
26
|
+
|
|
27
|
+
return logType
|
|
28
|
+
? i18n.t(`log.type_short.${logType}`)
|
|
29
|
+
: i18n.t(feature ? `product.feature_short.${feature}` : 'product.workflow');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Replace workflow template values in text using {{key}} placeholders
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export function replaceWorkflowTemplateValues(
|
|
37
|
+
text: string,
|
|
38
|
+
values?: Record<string, any> | null,
|
|
39
|
+
timeZone: string | null = null,
|
|
40
|
+
) {
|
|
41
|
+
if (!text || !values || typeof values !== 'object' || Array.isArray(values)) {
|
|
42
|
+
return text;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return text.replace(/{{(.*?)}}/g, (_match, rawKey) => {
|
|
46
|
+
const key = String(rawKey).trim();
|
|
47
|
+
const value = values[key];
|
|
48
|
+
|
|
49
|
+
switch (key) {
|
|
50
|
+
case 'endTime': {
|
|
51
|
+
if (!value) {
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const normalized = String(value).replace(':', '');
|
|
56
|
+
if (!/^[0-9]{3,4}$/.test(normalized)) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return hhmmFromDateOrTime(normalized, null, true, timeZone, true) || String(value);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (value === undefined || value === null || String(value) === '') {
|
|
65
|
+
return `{{${key}}}`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return String(value);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Get window for workflow schedule
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
function getScheduleWindowMs(schedule: string | null | undefined, nextAt: Date) {
|
|
77
|
+
if (!schedule) {
|
|
78
|
+
return DEFAULT_SCHEDULE_WINDOW_MS;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const nextMs = CronExpressionParser
|
|
83
|
+
.parse(schedule, { currentDate: nextAt })
|
|
84
|
+
.next()
|
|
85
|
+
.toDate()
|
|
86
|
+
.getTime();
|
|
87
|
+
const diffMs = nextMs - nextAt.getTime();
|
|
88
|
+
|
|
89
|
+
return Number.isFinite(diffMs) && diffMs > 0
|
|
90
|
+
? diffMs
|
|
91
|
+
: DEFAULT_SCHEDULE_WINDOW_MS;
|
|
92
|
+
} catch {
|
|
93
|
+
return DEFAULT_SCHEDULE_WINDOW_MS;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Check if current date is within workflow's schedule window
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
export function isWithinScheduleWindow(
|
|
102
|
+
nextAt: Date | string | null | undefined,
|
|
103
|
+
schedule?: string | null,
|
|
104
|
+
now = new Date(),
|
|
105
|
+
) {
|
|
106
|
+
const nextAtDate = nextAt ? new Date(nextAt) : null;
|
|
107
|
+
if (!nextAtDate) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const nextAtMs = nextAtDate.getTime();
|
|
112
|
+
if (!Number.isFinite(nextAtMs)) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const nowMs = now.getTime();
|
|
117
|
+
if (!Number.isFinite(nowMs)) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const windowMs = getScheduleWindowMs(schedule, nextAtDate);
|
|
122
|
+
const windowEndMs = nextAtMs + windowMs;
|
|
123
|
+
|
|
124
|
+
return nowMs >= nextAtMs && nowMs <= windowEndMs;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get next workflow schedule date from cron expression.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Normalize workflow schedule interval into a valid positive integer.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
function normalizeScheduleInterval(scheduleInterval: number | null | undefined) {
|
|
136
|
+
if (!Number.isFinite(scheduleInterval)) {
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const normalized = Math.floor(Number(scheduleInterval));
|
|
141
|
+
return normalized > 0 ? normalized : 1;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Get next workflow schedule date from cron expression and interval.
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
export function getNextWorkflowScheduleDate(
|
|
149
|
+
schedule: string | null | undefined,
|
|
150
|
+
scheduleInterval: number | null | undefined = 1,
|
|
151
|
+
currentDate: Date | string = new Date(),
|
|
152
|
+
timeZone: string | null = null,
|
|
153
|
+
) {
|
|
154
|
+
if (!schedule) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const current = new Date(currentDate);
|
|
159
|
+
if (!Number.isFinite(current.getTime())) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
const interval = normalizeScheduleInterval(scheduleInterval);
|
|
165
|
+
const parsed = CronExpressionParser.parse(schedule, {
|
|
166
|
+
currentDate: current,
|
|
167
|
+
...(timeZone ? { tz: timeZone } : {}),
|
|
168
|
+
});
|
|
169
|
+
let nextDate: Date | null = null;
|
|
170
|
+
|
|
171
|
+
for (let i = 0; i < interval; i += 1) {
|
|
172
|
+
nextDate = parsed.next().toDate();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return nextDate;
|
|
176
|
+
} catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Helper; check if workflow run is still active based on next follow-up time.
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
export function isWorkflowRunActive(
|
|
186
|
+
workflowRun: WorkflowRunData | null,
|
|
187
|
+
isFollowUp: boolean = false,
|
|
188
|
+
) {
|
|
189
|
+
if (!workflowRun) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const nextFollowUpAt = workflowRun.followUpAt;
|
|
194
|
+
if (!nextFollowUpAt) {
|
|
195
|
+
if (['COMPLETED', 'ERRORED', 'CANCELED'].includes(workflowRun.status)) {
|
|
196
|
+
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
|
197
|
+
return workflowRun.activityAt > oneDayAgo;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (isFollowUp) {
|
|
204
|
+
const now = new Date();
|
|
205
|
+
const followUpWindowStart = new Date(nextFollowUpAt.getTime() - 10 * 60 * 1000);
|
|
206
|
+
|
|
207
|
+
// Allow follow-up run only after entering the 10-minute pre-follow-up window.
|
|
208
|
+
return now >= followUpWindowStart;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return nextFollowUpAt > new Date();
|
|
212
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { ChildOrgsFilterArgs, OrganizationOperationEnum } from '../types/organization.d';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Create a filter object for productsList() query from the URL search query.
|
|
5
|
-
* @param operationType - The organization operation type
|
|
6
|
-
* @param searchQuery - The search query string from the URL
|
|
7
|
-
* @param otherFiltersObj - Additional filter properties to merge into the result
|
|
8
|
-
* @returns ProductsFilterArgs - The filter object to be used in the productsList() query
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export function getChildOrgsFilterFromURL(
|
|
12
|
-
_operationType: OrganizationOperationEnum | null,
|
|
13
|
-
searchQuery: string,
|
|
14
|
-
otherFiltersObj?: {
|
|
15
|
-
withoutPreset?: Partial<ChildOrgsFilterArgs>;
|
|
16
|
-
withPreset?: Partial<ChildOrgsFilterArgs>;
|
|
17
|
-
}
|
|
18
|
-
) {
|
|
19
|
-
if (!searchQuery && otherFiltersObj?.withPreset) {
|
|
20
|
-
return otherFiltersObj.withPreset;
|
|
21
|
-
} else if (searchQuery === '?preset=none' && otherFiltersObj?.withoutPreset) {
|
|
22
|
-
return otherFiltersObj.withoutPreset;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
26
|
-
|
|
27
|
-
// let startDate = urlParams.get('sd');
|
|
28
|
-
// let endDate = urlParams.get('ed');
|
|
29
|
-
// if (startDate && !endDate) {
|
|
30
|
-
// endDate = startDate;
|
|
31
|
-
// } else if (endDate && !startDate) {
|
|
32
|
-
// startDate = endDate;
|
|
33
|
-
// }
|
|
34
|
-
|
|
35
|
-
const filter: ChildOrgsFilterArgs = {
|
|
36
|
-
// startDate,
|
|
37
|
-
// endDate,
|
|
38
|
-
// timeZone: indexToTimeZone(urlParams.get('z')),
|
|
39
|
-
// query: urlParams.get('q') || '',
|
|
40
|
-
...otherFiltersObj?.withoutPreset,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return filter;
|
|
44
|
-
}
|
package/src/types/action.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Actions data object
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export interface ActionTaskObj {
|
|
6
|
-
id?: number | bigint; // Optional for updates/inserts
|
|
7
|
-
logId: number | bigint;
|
|
8
|
-
queue?: string | null;
|
|
9
|
-
|
|
10
|
-
title: string;
|
|
11
|
-
instruction: string;
|
|
12
|
-
message?: string | null;
|
|
13
|
-
|
|
14
|
-
scheduledAt: Date | null;
|
|
15
|
-
delay: number | null; // seconds
|
|
16
|
-
completed: boolean;
|
|
17
|
-
|
|
18
|
-
createdAt?: Date;
|
|
19
|
-
updatedAt?: Date;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Actions GraphQL data
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export interface ActionTaskGQL {
|
|
27
|
-
__deleted?: boolean;
|
|
28
|
-
|
|
29
|
-
id: string;
|
|
30
|
-
logId: string;
|
|
31
|
-
|
|
32
|
-
title: string;
|
|
33
|
-
instruction: string;
|
|
34
|
-
message: string | null;
|
|
35
|
-
|
|
36
|
-
scheduledAt: string; // ISO date string
|
|
37
|
-
delay: number; // seconds
|
|
38
|
-
completed: boolean;
|
|
39
|
-
|
|
40
|
-
createdAt?: string; // ISO date string
|
|
41
|
-
updatedAt?: string; // ISO date string
|
|
42
|
-
}
|