@jsb188/app 1.1.11 → 1.1.13
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/LICENSE +21 -0
- package/package.json +17 -6
- package/src/constants/agent.ts +44 -57
- package/src/constants/app.ts +43 -0
- package/src/constants/wsActions.ts +1 -15
- package/src/i18n/account.ts +1 -1
- package/src/i18n/agent.ts +321 -96
- package/src/i18n/agentToolBusiness.ts +340 -0
- package/src/i18n/agentToolGrid.ts +121 -0
- package/src/i18n/agentToolWorkflow.ts +101 -0
- package/src/i18n/agent_note.ts +110 -0
- package/src/i18n/app.ts +23 -17
- package/src/i18n/auth.ts +25 -30
- package/src/i18n/billing.ts +3 -85
- package/src/i18n/c.ts +953 -0
- package/src/i18n/campaign.ts +164 -211
- package/src/i18n/datetime.ts +6 -0
- package/src/i18n/editor.ts +56 -0
- package/src/i18n/email_outreach_editor.ts +526 -0
- package/src/i18n/error.ts +430 -202
- package/src/i18n/field_doc_editor.ts +21 -0
- package/src/i18n/field_doc_programs.ts +51 -0
- package/src/i18n/field_docs.ts +171 -8
- package/src/i18n/form.ts +7 -491
- package/src/i18n/index.ts +23 -3
- package/src/i18n/log.ts +234 -39
- package/src/i18n/memory.ts +18 -5
- package/src/i18n/message.ts +1 -0
- package/src/i18n/note.ts +5 -3
- package/src/i18n/org.ts +97 -45
- package/src/i18n/schedule.ts +133 -0
- package/src/i18n/sheet.ts +105 -161
- package/src/i18n/sheet_formula.ts +165 -0
- package/src/i18n/workflow.ts +112 -11
- package/src/main.ts +2 -2
- package/src/platform.ts +89 -49
- package/src/types/ai.d.ts +16 -1
- package/src/types/app.d.ts +29 -73
- package/src/types/auth.d.ts +1 -1
- package/src/types/other.d.ts +8 -1
- package/src/utils/api.ts +60 -10
- package/src/utils/clientIP.ts +213 -0
- package/src/utils/color.ts +95 -0
- package/src/utils/csv.ts +19 -0
- package/src/utils/datetime.ts +207 -31
- package/src/utils/deferredSave.ts +89 -0
- package/src/utils/email.ts +50 -0
- package/src/utils/expression.helpers.ts +470 -0
- package/src/utils/expression.ts +1633 -239
- package/src/utils/language.ts +9 -0
- package/src/utils/logic.ts +9 -162
- package/src/utils/number.ts +30 -11
- package/src/utils/object.ts +69 -127
- package/src/utils/promise.ts +78 -7
- package/src/utils/queryReset.ts +110 -61
- package/src/utils/string.ts +80 -143
- package/src/utils/url_client.ts +115 -15
- package/src/constants/billing.ts +0 -146
- package/src/i18n/agentDoc.ts +0 -110
- package/src/types/form.d.ts +0 -101
- package/src/utils/billing.ts +0 -141
- package/src/utils/managedSessionBff.test.ts +0 -60
- package/src/utils/string.test.ts +0 -293
- package/tsconfig.json +0 -12
package/src/utils/datetime.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
2
|
import i18n from '../i18n/index.ts';
|
|
3
3
|
import { getObject } from './object.ts';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DEFAULT_TIMEZONE,
|
|
6
|
+
isValidTimeZone,
|
|
7
|
+
parseDateInTimezone,
|
|
8
|
+
} from './timeZone.ts';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Types
|
|
@@ -175,6 +179,27 @@ export function getDatePeriod(d1: Date, d2: Date): DatePeriodEnum {
|
|
|
175
179
|
return 'OLDER';
|
|
176
180
|
}
|
|
177
181
|
|
|
182
|
+
/*
|
|
183
|
+
* Format compact display dates consistently, showing the year only outside the current year.
|
|
184
|
+
* Calendar dates use UTC so timezone conversion cannot change their day.
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
export function formatDisplayDate(value: string | Date, timeZone?: string | null): string {
|
|
188
|
+
const dateOnly = typeof value === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
189
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
190
|
+
const zone = dateOnly ? 'UTC' : timeZone || undefined;
|
|
191
|
+
const yearFormat = new Intl.DateTimeFormat('en-US', { timeZone: zone, year: 'numeric' });
|
|
192
|
+
return new Intl.DateTimeFormat('en-US', {
|
|
193
|
+
timeZone: zone,
|
|
194
|
+
month: 'numeric',
|
|
195
|
+
day: '2-digit',
|
|
196
|
+
year: yearFormat.format(date) === yearFormat.format(new Date()) ? undefined : 'numeric',
|
|
197
|
+
hour: dateOnly ? undefined : 'numeric',
|
|
198
|
+
minute: dateOnly ? undefined : '2-digit',
|
|
199
|
+
hour12: true,
|
|
200
|
+
}).format(date);
|
|
201
|
+
}
|
|
202
|
+
|
|
178
203
|
/**
|
|
179
204
|
* Get full date with time
|
|
180
205
|
*/
|
|
@@ -256,6 +281,60 @@ export function getFullDateTime(
|
|
|
256
281
|
});
|
|
257
282
|
}
|
|
258
283
|
|
|
284
|
+
/*
|
|
285
|
+
* Convert one canonical instant into the local value required by a
|
|
286
|
+
* datetime-local input in the requested scheduling timezone.
|
|
287
|
+
*/
|
|
288
|
+
export function getDateTimeLocalInputValue(
|
|
289
|
+
value?: Date | string | number | null,
|
|
290
|
+
timeZone?: string | null,
|
|
291
|
+
): string | null {
|
|
292
|
+
const date = value ? new Date(value) : null;
|
|
293
|
+
if (!date || !Number.isFinite(date.getTime())) {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const inputTimeZone =
|
|
298
|
+
timeZone && isValidTimeZone(timeZone) ? timeZone : DEFAULT_TIMEZONE;
|
|
299
|
+
const { calDate, time } = getCalDate(date, inputTimeZone);
|
|
300
|
+
return `${calDate}T${time.slice(0, 5)}`;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/*
|
|
304
|
+
* Convert a datetime-local input value into its canonical ISO instant in the
|
|
305
|
+
* requested scheduling timezone.
|
|
306
|
+
*/
|
|
307
|
+
export function normalizeDateTimeLocalInputValue(
|
|
308
|
+
value?: string | null,
|
|
309
|
+
timeZone?: string | null,
|
|
310
|
+
): string | null {
|
|
311
|
+
const trimmedValue = String(value || '').trim();
|
|
312
|
+
if (
|
|
313
|
+
!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?$/.test(
|
|
314
|
+
trimmedValue,
|
|
315
|
+
)
|
|
316
|
+
) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const inputTimeZone =
|
|
321
|
+
timeZone && isValidTimeZone(timeZone) ? timeZone : DEFAULT_TIMEZONE;
|
|
322
|
+
const parsedDate = parseDateInTimezone(trimmedValue, inputTimeZone, 0, true);
|
|
323
|
+
if (!Number.isFinite(parsedDate.getTime())) {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Luxon advances nonexistent wall-clock times through daylight-saving gaps.
|
|
328
|
+
// A scheduler must reject that silent time change rather than save a
|
|
329
|
+
// different local time from the one the user entered.
|
|
330
|
+
const { calDate, time } = getCalDate(parsedDate, inputTimeZone);
|
|
331
|
+
if (`${calDate}T${time.slice(0, 5)}` !== trimmedValue.slice(0, 16)) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return parsedDate.toISOString();
|
|
336
|
+
}
|
|
337
|
+
|
|
259
338
|
/**
|
|
260
339
|
* Check if date is same day
|
|
261
340
|
*/
|
|
@@ -704,39 +783,145 @@ function getDateTimeWithTimeZone(date: string | Date, timeZone: string | null) {
|
|
|
704
783
|
}
|
|
705
784
|
|
|
706
785
|
/**
|
|
707
|
-
* Convert today/yesterday date time into a label with time
|
|
786
|
+
* Convert today/yesterday date time into a label, with the time unless hidden
|
|
708
787
|
* @param dt - Parsed Luxon date time
|
|
709
788
|
* @param timeZone - Optional timezone for time formatting
|
|
789
|
+
* @param hideTime - Return only the day label
|
|
710
790
|
*/
|
|
711
791
|
|
|
712
|
-
function getTodayYesterdayTime(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
792
|
+
function getTodayYesterdayTime(
|
|
793
|
+
dt: DateTime,
|
|
794
|
+
now: DateTime,
|
|
795
|
+
timeZone: string | null,
|
|
796
|
+
hideTime?: boolean,
|
|
797
|
+
) {
|
|
798
|
+
const dayKey = dt.hasSame(now, 'day')
|
|
799
|
+
? 'datetime.period_TODAY'
|
|
800
|
+
: dt.hasSame(now.minus({ days: 1 }), 'day')
|
|
801
|
+
? 'datetime.period_YESTERDAY'
|
|
802
|
+
: null;
|
|
803
|
+
|
|
804
|
+
if (!dayKey) {
|
|
805
|
+
return null;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
if (hideTime) {
|
|
809
|
+
return i18n.t(dayKey);
|
|
810
|
+
}
|
|
811
|
+
|
|
717
812
|
const timeText = getFullDateTime(dt.toJSDate(), {
|
|
718
813
|
timeZone,
|
|
719
814
|
hideDate: true,
|
|
720
815
|
});
|
|
816
|
+
return `${i18n.t(dayKey)}, ${timeText}`;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Format a date time with a numeric month and day, adding a two-digit year only when it differs from the reference year.
|
|
821
|
+
* @param dt - Parsed Luxon date time
|
|
822
|
+
* @param now - Reference date time used to decide whether to show the year
|
|
823
|
+
* @param timeZone - Optional timezone for date and time formatting
|
|
824
|
+
* @param hideTime - Omit the hour and minute
|
|
825
|
+
*/
|
|
826
|
+
|
|
827
|
+
function getCompactDateTime(
|
|
828
|
+
dt: DateTime,
|
|
829
|
+
now: DateTime,
|
|
830
|
+
timeZone: string | null,
|
|
831
|
+
hideTime?: boolean,
|
|
832
|
+
) {
|
|
833
|
+
return new Intl.DateTimeFormat('en-US', {
|
|
834
|
+
day: 'numeric',
|
|
835
|
+
month: 'numeric',
|
|
836
|
+
timeZone: timeZone && isValidTimeZone(timeZone) ? timeZone : undefined,
|
|
837
|
+
year: dt.year === now.year ? undefined : '2-digit',
|
|
838
|
+
...(hideTime ? {} : { hour: 'numeric', hour12: true, minute: '2-digit' }),
|
|
839
|
+
}).format(dt.toJSDate());
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Format an edited timestamp as a compact or expanded relative label, falling back to YYYY/MM/DD.
|
|
844
|
+
* @param date - Date to format
|
|
845
|
+
* @param timeZone - Optional timezone for calendar-day comparisons
|
|
846
|
+
* @param longer - Return expanded relative units when true
|
|
847
|
+
*/
|
|
848
|
+
|
|
849
|
+
export function getEditedTimeAgo(
|
|
850
|
+
date: string | Date,
|
|
851
|
+
timeZone?: string | null,
|
|
852
|
+
longer?: boolean,
|
|
853
|
+
) {
|
|
854
|
+
const dt = getDateTimeWithTimeZone(date, timeZone || null);
|
|
855
|
+
if (!dt) {
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
const now =
|
|
860
|
+
timeZone && isValidTimeZone(timeZone)
|
|
861
|
+
? DateTime.now().setZone(timeZone)
|
|
862
|
+
: DateTime.now();
|
|
863
|
+
const diffMinutes = now.diff(dt, 'minutes').minutes;
|
|
864
|
+
|
|
865
|
+
if (diffMinutes < 0) {
|
|
866
|
+
return dt.toFormat('yyyy/MM/dd');
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if (diffMinutes <= 4) {
|
|
870
|
+
return i18n.t('datetime.just_now');
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
if (diffMinutes < 60) {
|
|
874
|
+
return i18n.t(
|
|
875
|
+
longer ? 'datetime.minutes_ago_ct' : 'datetime.minutes_ago_short_ct',
|
|
876
|
+
{
|
|
877
|
+
smart_count: Math.floor(diffMinutes),
|
|
878
|
+
},
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
const diffHours = diffMinutes / 60;
|
|
883
|
+
if (diffHours < 9) {
|
|
884
|
+
return i18n.t(
|
|
885
|
+
longer ? 'datetime.hours_ago_ct' : 'datetime.hours_ago_short_ct',
|
|
886
|
+
{
|
|
887
|
+
smart_count: Math.floor(diffHours),
|
|
888
|
+
},
|
|
889
|
+
);
|
|
890
|
+
}
|
|
721
891
|
|
|
722
892
|
if (dt.hasSame(now, 'day')) {
|
|
723
|
-
return
|
|
893
|
+
return i18n.t('datetime.today');
|
|
724
894
|
}
|
|
725
895
|
|
|
726
896
|
if (dt.hasSame(now.minus({ days: 1 }), 'day')) {
|
|
727
|
-
return
|
|
897
|
+
return i18n.t('datetime.yesterday');
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
const diffDays = now.startOf('day').diff(dt.startOf('day'), 'days').days;
|
|
901
|
+
if (diffDays < 7) {
|
|
902
|
+
return i18n.t(
|
|
903
|
+
longer ? 'datetime.days_ago_ct' : 'datetime.days_ago_short_ct',
|
|
904
|
+
{
|
|
905
|
+
smart_count: Math.floor(diffDays),
|
|
906
|
+
},
|
|
907
|
+
);
|
|
728
908
|
}
|
|
729
909
|
|
|
730
|
-
return
|
|
910
|
+
return dt.toFormat('yyyy/MM/dd');
|
|
731
911
|
}
|
|
732
912
|
|
|
733
913
|
/**
|
|
734
|
-
* Convert date time "time" ago
|
|
914
|
+
* Convert date time "time" ago: "Today, 10:21 PM", "Yesterday, 10:21 PM", or "9/14, 10:21 PM"
|
|
735
915
|
* @param date - Date to convert
|
|
736
916
|
* @param timeZone - Optional timezone for day boundary checks
|
|
917
|
+
* @param hideTime - Return only the day part ("Today", "Yesterday", "9/14") for narrow table cells
|
|
737
918
|
*/
|
|
738
919
|
|
|
739
|
-
export function getTimeAgo(
|
|
920
|
+
export function getTimeAgo(
|
|
921
|
+
date: string | Date,
|
|
922
|
+
timeZone: string | null,
|
|
923
|
+
hideTime?: boolean,
|
|
924
|
+
) {
|
|
740
925
|
const dt = getDateTimeWithTimeZone(date, timeZone);
|
|
741
926
|
if (!dt) {
|
|
742
927
|
return null;
|
|
@@ -746,27 +931,13 @@ export function getTimeAgo(date: string | Date, timeZone: string | null) {
|
|
|
746
931
|
timeZone && isValidTimeZone(timeZone)
|
|
747
932
|
? DateTime.now().setZone(timeZone)
|
|
748
933
|
: DateTime.now();
|
|
749
|
-
const todayYesterdayTime = getTodayYesterdayTime(dt, timeZone);
|
|
934
|
+
const todayYesterdayTime = getTodayYesterdayTime(dt, now, timeZone, hideTime);
|
|
750
935
|
|
|
751
936
|
if (todayYesterdayTime) {
|
|
752
937
|
return todayYesterdayTime;
|
|
753
938
|
}
|
|
754
939
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
if (diffMs < 0) {
|
|
758
|
-
return getFullDateTime(dt.toJSDate(), {
|
|
759
|
-
timeZone,
|
|
760
|
-
alwaysShowYear: true,
|
|
761
|
-
textDateStyle: 'short',
|
|
762
|
-
});
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
return getFullDateTime(dt.toJSDate(), {
|
|
766
|
-
timeZone,
|
|
767
|
-
alwaysShowYear: true,
|
|
768
|
-
textDateStyle: 'short',
|
|
769
|
-
});
|
|
940
|
+
return getCompactDateTime(dt, now, timeZone, hideTime);
|
|
770
941
|
}
|
|
771
942
|
|
|
772
943
|
/**
|
|
@@ -779,6 +950,7 @@ export function getFullDate(
|
|
|
779
950
|
outputStyle_:
|
|
780
951
|
| 'NUMERIC'
|
|
781
952
|
| 'NUMERIC_TIME'
|
|
953
|
+
| 'NUMERIC_TIME_COMPACT'
|
|
782
954
|
| 'DATE_ONLY_SHORT'
|
|
783
955
|
| 'DAY_IF_WEEK'
|
|
784
956
|
| 'TOMORROW_OR_NUMERIC'
|
|
@@ -828,10 +1000,13 @@ export function getFullDate(
|
|
|
828
1000
|
return new Intl.DateTimeFormat(locales, {
|
|
829
1001
|
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
830
1002
|
}).format(d);
|
|
831
|
-
case 'NUMERIC_TIME':
|
|
832
|
-
|
|
1003
|
+
case 'NUMERIC_TIME':
|
|
1004
|
+
case 'NUMERIC_TIME_COMPACT': {
|
|
1005
|
+
// Compact output: "9/01/2024, 8:30 PM"; default output: "9/1/2024, 8:30 PM".
|
|
1006
|
+
const compact = outputStyle === 'NUMERIC_TIME_COMPACT';
|
|
833
1007
|
const numericDate = new Intl.DateTimeFormat(locales, {
|
|
834
1008
|
timeZone: timeZone || undefined, // null is not allowed, it will throw error
|
|
1009
|
+
...(compact ? ({ month: 'numeric', day: '2-digit', year: 'numeric' } as const) : {}),
|
|
835
1010
|
}).format(d);
|
|
836
1011
|
|
|
837
1012
|
const numericTime = new Intl.DateTimeFormat(locales, {
|
|
@@ -841,7 +1016,8 @@ export function getFullDate(
|
|
|
841
1016
|
hour12: true,
|
|
842
1017
|
}).format(d);
|
|
843
1018
|
|
|
844
|
-
|
|
1019
|
+
const numericDateTime = `${numericDate}, ${numericTime}`;
|
|
1020
|
+
return compact ? numericDateTime.toUpperCase() : numericDateTime;
|
|
845
1021
|
|
|
846
1022
|
// return new Intl.DateTimeFormat(locales, {
|
|
847
1023
|
// month: '2-digit',
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Debounce immutable snapshots and serialize saves, keeping only the latest pending
|
|
3
|
+
* value. A failed value remains queued for the next edit, resume, or explicit flush.
|
|
4
|
+
*/
|
|
5
|
+
export function createDeferredSaveQueue<T>(p: { delayMs: number; onError: (error: unknown) => void; onIdle?: () => void }) {
|
|
6
|
+
let pending: { value: T; save: (value: T) => Promise<void> } | null = null;
|
|
7
|
+
let inFlight = false;
|
|
8
|
+
let paused = false;
|
|
9
|
+
let ready = false;
|
|
10
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Clear the debounce without dropping the latest unsaved snapshot.
|
|
14
|
+
*/
|
|
15
|
+
function clearTimer() {
|
|
16
|
+
if (timer !== null) clearTimeout(timer);
|
|
17
|
+
timer = null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Start a ready snapshot only after the previous request has fully settled.
|
|
22
|
+
*/
|
|
23
|
+
async function drain() {
|
|
24
|
+
if (inFlight || paused || !ready || !pending) return;
|
|
25
|
+
const request = pending;
|
|
26
|
+
pending = null;
|
|
27
|
+
ready = false;
|
|
28
|
+
inFlight = true;
|
|
29
|
+
try {
|
|
30
|
+
await request.save(request.value);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (!pending) {
|
|
33
|
+
pending = request;
|
|
34
|
+
ready = false;
|
|
35
|
+
}
|
|
36
|
+
p.onError(error);
|
|
37
|
+
} finally {
|
|
38
|
+
inFlight = false;
|
|
39
|
+
if (pending) void drain();
|
|
40
|
+
else p.onIdle?.();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Require a full quiet period after every edit or completed interaction.
|
|
46
|
+
*/
|
|
47
|
+
function schedule() {
|
|
48
|
+
clearTimer();
|
|
49
|
+
ready = false;
|
|
50
|
+
if (!pending || paused) return;
|
|
51
|
+
timer = setTimeout(() => {
|
|
52
|
+
timer = null;
|
|
53
|
+
ready = true;
|
|
54
|
+
void drain();
|
|
55
|
+
}, p.delayMs);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
/*
|
|
60
|
+
* Replace intermediate edits with the newest complete snapshot and its owner-bound saver.
|
|
61
|
+
*/
|
|
62
|
+
queue(value: T, save: (value: T) => Promise<void>) {
|
|
63
|
+
pending = { value, save };
|
|
64
|
+
schedule();
|
|
65
|
+
},
|
|
66
|
+
/*
|
|
67
|
+
* Pause during a gesture, then restart the quiet period when it ends.
|
|
68
|
+
*/
|
|
69
|
+
setPaused(value: boolean) {
|
|
70
|
+
if (paused === value) return;
|
|
71
|
+
paused = value;
|
|
72
|
+
schedule();
|
|
73
|
+
},
|
|
74
|
+
/*
|
|
75
|
+
* Flush committed work on navigation, without overlapping an earlier request.
|
|
76
|
+
*/
|
|
77
|
+
flush() {
|
|
78
|
+
clearTimer();
|
|
79
|
+
ready = true;
|
|
80
|
+
void drain();
|
|
81
|
+
},
|
|
82
|
+
/*
|
|
83
|
+
* Retain the owner while a request or an unsaved snapshot still exists.
|
|
84
|
+
*/
|
|
85
|
+
hasPending() {
|
|
86
|
+
return inFlight || pending !== null;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DO_NOT_REPLY_EMAIL_DOMAINS, DOMAIN_TO_INBOX, EMAIL_BASE_DOMAINS, OUTBOUND_EMAIL_DOMAINS } from '../constants/agent.ts';
|
|
2
|
+
import { APP_EMAILS } from '../constants/app.ts';
|
|
3
|
+
|
|
4
|
+
export type AgentEmailKind = 'ASSISTANT' | 'OUTBOUND' | 'SYSTEM';
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Permit replies only from a supported receiving inbox, including the existing outbound campaign reply channel.
|
|
8
|
+
*/
|
|
9
|
+
export function isSupportedEmailReplyAddress(email?: string | null): boolean {
|
|
10
|
+
const mailbox = email?.trim().toLowerCase();
|
|
11
|
+
if (!mailbox || !/^[^\s<>@,;]+@[^\s<>@,;]+$/.test(mailbox)) return false;
|
|
12
|
+
const domain = mailbox.slice(mailbox.lastIndexOf('@') + 1);
|
|
13
|
+
return Object.hasOwn(DOMAIN_TO_INBOX, domain) || OUTBOUND_EMAIL_DOMAINS.includes(domain);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* Return which of our own mailboxes (agent inboxes, campaign sender, or platform address) an email belongs to.
|
|
18
|
+
*/
|
|
19
|
+
export function getAgentEmailKind(email?: string | null): AgentEmailKind | null {
|
|
20
|
+
const mailbox = email?.trim().toLowerCase();
|
|
21
|
+
if (!mailbox || !/^[^\s<>@,;]+@[^\s<>@,;]+$/.test(mailbox)) return null;
|
|
22
|
+
const domain = mailbox.slice(mailbox.lastIndexOf('@') + 1);
|
|
23
|
+
if (OUTBOUND_EMAIL_DOMAINS.includes(domain)) return 'OUTBOUND';
|
|
24
|
+
if (DO_NOT_REPLY_EMAIL_DOMAINS.includes(domain) || Object.values(APP_EMAILS).includes(mailbox)) return 'SYSTEM';
|
|
25
|
+
if (DOMAIN_TO_INBOX[domain]) return DOMAIN_TO_INBOX[domain];
|
|
26
|
+
if (
|
|
27
|
+
EMAIL_BASE_DOMAINS.some((baseDomain) => {
|
|
28
|
+
const suffix = `.${baseDomain}`;
|
|
29
|
+
return domain.endsWith(suffix) && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(domain.slice(0, -suffix.length));
|
|
30
|
+
})
|
|
31
|
+
) {
|
|
32
|
+
return 'SYSTEM';
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/*
|
|
38
|
+
* Return a default display name only for mailboxes on our configured agent domains.
|
|
39
|
+
*/
|
|
40
|
+
export function getAgentEmailDisplayName(email?: string | null): string | null {
|
|
41
|
+
const kind = getAgentEmailKind(email);
|
|
42
|
+
return kind === 'OUTBOUND' ? 'Email campaign' : kind === 'ASSISTANT' ? 'Agent' : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/*
|
|
46
|
+
* Display a saved mailbox name, then a known domain name, then its address.
|
|
47
|
+
*/
|
|
48
|
+
export function getEmailMailboxDisplayName(email?: string | null, name?: string | null): string | null {
|
|
49
|
+
return name?.trim() || getAgentEmailDisplayName(email) || email || null;
|
|
50
|
+
}
|