@jsb188/app 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/package.json +57 -42
  2. package/src/constants/agent.ts +74 -0
  3. package/src/constants/app.ts +389 -0
  4. package/src/constants/emoji.ts +9153 -0
  5. package/src/constants/other.ts +13 -0
  6. package/src/constants/user.ts +27 -0
  7. package/src/constants/wsActions.ts +49 -0
  8. package/src/i18n/account.ts +139 -0
  9. package/src/i18n/agent.ts +397 -0
  10. package/src/i18n/agentToolBusiness.ts +196 -0
  11. package/src/i18n/agentToolGrid.ts +137 -0
  12. package/src/i18n/agentToolWorkflow.ts +101 -0
  13. package/src/i18n/agent_note.ts +109 -0
  14. package/src/i18n/app.ts +124 -0
  15. package/src/i18n/auth.ts +128 -0
  16. package/src/i18n/billing.ts +7 -0
  17. package/src/i18n/c.ts +907 -0
  18. package/src/i18n/campaign.ts +919 -0
  19. package/src/i18n/country.ts +249 -0
  20. package/src/i18n/datetime.ts +66 -0
  21. package/src/i18n/editor.ts +58 -0
  22. package/src/i18n/error.ts +579 -0
  23. package/src/i18n/field_doc_editor.ts +21 -0
  24. package/src/i18n/field_doc_programs.ts +52 -0
  25. package/src/i18n/field_docs.ts +190 -0
  26. package/src/i18n/index.ts +64 -0
  27. package/src/i18n/log.ts +566 -0
  28. package/src/i18n/memory.ts +59 -0
  29. package/src/i18n/message.ts +13 -0
  30. package/src/i18n/note.ts +19 -0
  31. package/src/i18n/org.ts +306 -0
  32. package/src/i18n/schedule.ts +209 -0
  33. package/src/i18n/sheet.ts +339 -0
  34. package/src/i18n/sheet_formula.ts +165 -0
  35. package/src/i18n/workflow.ts +111 -0
  36. package/src/main.ts +89 -0
  37. package/src/platform.ts +166 -0
  38. package/src/types/ai.d.ts +63 -0
  39. package/src/types/app.d.ts +127 -0
  40. package/src/types/auth.d.ts +94 -0
  41. package/src/types/console.d.ts +3 -0
  42. package/src/types/node-polyglot.d.ts +23 -0
  43. package/src/types/other.d.ts +66 -0
  44. package/src/types.d.ts +29 -0
  45. package/src/utils/account.ts +97 -0
  46. package/src/utils/api.ts +358 -0
  47. package/src/utils/authSession.ts +24 -0
  48. package/src/utils/clientIP.ts +213 -0
  49. package/src/utils/color.ts +279 -0
  50. package/src/utils/cron.ts +310 -0
  51. package/src/utils/csv.ts +19 -0
  52. package/src/utils/datetime.ts +1394 -0
  53. package/src/utils/deferredSave.ts +89 -0
  54. package/src/utils/email.ts +39 -0
  55. package/src/utils/emoji.ts +174 -0
  56. package/src/utils/expression.helpers.ts +470 -0
  57. package/src/utils/expression.test.ts +793 -0
  58. package/src/utils/expression.ts +2261 -0
  59. package/src/utils/interval.ts +80 -0
  60. package/src/utils/language.ts +9 -0
  61. package/src/utils/logic.ts +299 -0
  62. package/src/utils/managedSession.ts +34 -0
  63. package/src/utils/managedSessionBff.test.ts +60 -0
  64. package/src/utils/managedSessionBff.ts +117 -0
  65. package/src/utils/number.ts +338 -0
  66. package/src/utils/object.ts +916 -0
  67. package/src/utils/promise.ts +98 -0
  68. package/src/utils/queryReset.ts +266 -0
  69. package/src/utils/recurringTask.ts +60 -0
  70. package/src/utils/schema.ts +293 -0
  71. package/src/utils/string.test.ts +278 -0
  72. package/src/utils/string.ts +709 -0
  73. package/{utils → src/utils}/timeZone.ts +531 -852
  74. package/src/utils/url_client.ts +206 -0
  75. package/tsconfig.json +12 -0
  76. package/constants/app.ts +0 -47
  77. package/constants/billing.ts +0 -146
  78. package/constants/emoji.ts +0 -8945
  79. package/constants/journal.ts +0 -74
  80. package/constants/user.ts +0 -36
  81. package/constants/ws.ts +0 -47
  82. package/i18n/app.ts +0 -101
  83. package/i18n/auth.ts +0 -63
  84. package/i18n/billing.ts +0 -94
  85. package/i18n/datetime.ts +0 -21
  86. package/i18n/error.ts +0 -143
  87. package/i18n/form.ts +0 -74
  88. package/i18n/index.ts +0 -5
  89. package/i18n/user.ts +0 -101
  90. package/main.ts +0 -94
  91. package/platform.ts +0 -125
  92. package/types/ai.d.ts +0 -30
  93. package/types/app.d.ts +0 -48
  94. package/types/auth.d.ts +0 -63
  95. package/types/form.d.ts +0 -56
  96. package/types/journal.d.ts +0 -24
  97. package/types/organization.d.ts +0 -38
  98. package/types/user.d.ts +0 -52
  99. package/types.d.ts +0 -31
  100. package/utils/api.ts +0 -99
  101. package/utils/billing.ts +0 -134
  102. package/utils/datetime.ts +0 -542
  103. package/utils/emoji.ts +0 -151
  104. package/utils/journal.ts +0 -17
  105. package/utils/logic.ts +0 -118
  106. package/utils/number.ts +0 -139
  107. package/utils/object.ts +0 -425
  108. package/utils/string.ts +0 -323
  109. package/utils/url_client.ts +0 -138
  110. package/utils/user.ts +0 -273
package/utils/datetime.ts DELETED
@@ -1,542 +0,0 @@
1
- import i18n from '../i18n';
2
- import { isValidTimeZone, parseDateInTimezone } from './timeZone';
3
-
4
- /**
5
- * Types
6
- */
7
-
8
- export type DatePeriodEnum =
9
- | 'UPCOMING'
10
- | 'TOMORROW'
11
- | 'TODAY'
12
- | 'YESTERDAY'
13
- | 'THIS_WEEK'
14
- | 'THIS_MONTH'
15
- | 'LAST_WEEK'
16
- | 'LAST_MONTH'
17
- | 'OLDER';
18
-
19
- export interface DatePeriodObj {
20
- datePeriod: DatePeriodEnum | string; // 'YYYY-MM-DD' (string) if groupByDate is true
21
- date: Date;
22
- item: any;
23
- }
24
-
25
- interface TimeAgoParams {
26
- locales: string;
27
- justNowThresh: number;
28
- nowThresh: number;
29
- disableFuture: boolean;
30
- isToday: boolean;
31
- skipTodayCheck: boolean;
32
- }
33
-
34
- interface FullTimeParams {
35
- timeZone: string | null;
36
- locales: string;
37
- hideYear: boolean;
38
- hideDate: boolean;
39
- hideTime: boolean;
40
- textDateStyle: 'long' | 'short' | null;
41
- alwaysShowYear: boolean;
42
- includeWeekday: boolean;
43
- }
44
-
45
- /**
46
- * Get start of day
47
- */
48
-
49
- function getStartOfDay(date: Date) {
50
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
51
- }
52
-
53
- /**
54
- * Get difference in days
55
- */
56
-
57
- function getDaysDiff(date1: Date, date2: Date) {
58
- return Math.floor((getStartOfDay(date1).getTime() - getStartOfDay(date2).getTime()) / (1000 * 60 * 60 * 24));
59
- }
60
-
61
- /**
62
- * Get date period from date
63
- */
64
-
65
- export function getDatePeriod(d1: Date, d2: Date): DatePeriodEnum {
66
- const diffDays = getDaysDiff(d1, d2);
67
-
68
- switch (diffDays) {
69
- case 0:
70
- return 'TODAY';
71
- case 1:
72
- return 'TOMORROW';
73
- case -1:
74
- return 'YESTERDAY';
75
- case -7:
76
- return 'LAST_WEEK';
77
- case -30:
78
- return 'LAST_MONTH';
79
- default:
80
- if (diffDays > 1) {
81
- return 'UPCOMING';
82
- }
83
- }
84
-
85
- const diffInWeeks = Math.ceil(diffDays / 7);
86
- if (diffInWeeks === 0) {
87
- return 'THIS_WEEK';
88
- } else if (diffInWeeks === -1) {
89
- return 'LAST_WEEK';
90
- }
91
-
92
- const diffInMonths = (d2.getFullYear() - d1.getFullYear()) * 12 + (d2.getMonth() - d1.getMonth());
93
- if (diffInMonths === 0) {
94
- return 'THIS_MONTH';
95
- } else if (diffInMonths === -1) {
96
- return 'LAST_MONTH';
97
- }
98
-
99
- return 'OLDER';
100
- }
101
-
102
- /**
103
- * Get full date with time
104
- */
105
-
106
- export function getFullDateTime(
107
- _d: Date | string | number | null,
108
- params?: Partial<FullTimeParams>,
109
- ) {
110
- const {
111
- locales = 'en-US',
112
- timeZone: timeZone_,
113
- hideYear,
114
- hideDate,
115
- hideTime,
116
- textDateStyle,
117
- alwaysShowYear,
118
- includeWeekday,
119
- } = params || {};
120
-
121
- let d;
122
- if (_d instanceof Date) {
123
- d = _d;
124
- } else {
125
- // Make sure _d is not null, before using this function
126
- d = _d ? new Date(_d) : new Date(-1);
127
- }
128
-
129
- let timeZone = timeZone_ || undefined; // cannot be null, else it will throw error
130
- if (timeZone && !isValidTimeZone(timeZone)) {
131
- timeZone = undefined;
132
- }
133
-
134
- if (hideDate) {
135
- return d.toLocaleTimeString(locales, {
136
- timeZone,
137
- hour: 'numeric',
138
- minute: '2-digit',
139
- });
140
- }
141
-
142
- // If year is same year, then don't show year
143
- let hideYear_;
144
- if (!hideYear && !alwaysShowYear) {
145
- const dateYear = d.getFullYear();
146
- const currentYear = new Date().getFullYear();
147
- hideYear_ = dateYear === currentYear;
148
- } else if (hideYear || hideDate) {
149
- hideYear_ = true;
150
- }
151
-
152
- return d.toLocaleDateString(locales, {
153
- timeZone,
154
- day: 'numeric',
155
- weekday: includeWeekday && textDateStyle === 'long' ? 'long' : includeWeekday ? 'short' : undefined,
156
- month: textDateStyle || 'numeric',
157
- year: hideYear_ ? undefined : 'numeric',
158
- hour: hideTime ? undefined : 'numeric',
159
- minute: hideTime ? undefined : '2-digit',
160
- });
161
- }
162
-
163
- /**
164
- * Check if date is same day
165
- */
166
-
167
- export function checkIfSameDay(d1: Date, d2: Date, checkTime: boolean = false) {
168
- let date1, date2;
169
- if (checkTime) {
170
- date1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate(), d1.getHours(), d1.getMinutes());
171
- date2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate(), d2.getHours(), d2.getMinutes());
172
- } else {
173
- date1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate());
174
- date2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate());
175
- }
176
-
177
- return date1.getTime() === date2.getTime();
178
- }
179
-
180
- /**
181
- * Get today at start of day
182
- */
183
-
184
- export function getTodayStartOfDay(timeZone?: string | null) {
185
- const startDate = getFullDateTime(new Date(), {
186
- locales: 'en-US',
187
- alwaysShowYear: true,
188
- hideTime: true,
189
- });
190
-
191
- const today = parseDateInTimezone(startDate, timeZone);
192
- return today;
193
- }
194
-
195
- /**
196
- * Get timezone enforced date
197
- */
198
-
199
- export function getCalDate(d: Date, timeZone_?: string | null) {
200
- let timeZone = timeZone_ || undefined; // cannot be null, else it will throw error
201
- if (timeZone && !isValidTimeZone(timeZone)) {
202
- timeZone = undefined;
203
- }
204
-
205
- const usCalDate = d.toLocaleString('en-US', {
206
- timeZone,
207
- year: 'numeric',
208
- month: '2-digit',
209
- day: '2-digit',
210
- });
211
-
212
- // Get date in format YYYY-MM-DD
213
- const [month, day, year] = usCalDate.split('/');
214
- const calDate = `${year}-${month}-${day}`;
215
- const calDateInt = Number(`${year}${month}${day}`);
216
-
217
- const time = d.toLocaleString('en-US', {
218
- timeZone,
219
- hour: '2-digit',
220
- minute: '2-digit',
221
- second: '2-digit',
222
- hour12: false,
223
- });
224
-
225
- return {
226
- calDate,
227
- calDateInt,
228
- time,
229
- };
230
- }
231
-
232
- /**
233
- * Convert date time "time" ago
234
- */
235
-
236
- export function getTimeAgo(
237
- _d: Date | string | number | null,
238
- params?: Partial<TimeAgoParams>,
239
- ) {
240
- const {
241
- locales = 'en-US',
242
- justNowThresh = 300000, // 5 minutes
243
- nowThresh = 8.64e+7,
244
- disableFuture = false,
245
- isToday,
246
- skipTodayCheck,
247
- } = params || {};
248
-
249
- let d;
250
- if (_d instanceof Date) {
251
- d = _d;
252
- } else if (!isNaN(Number(_d))) {
253
- d = new Date(Number(_d));
254
- } else {
255
- // Make sure date is not null, before using this function
256
- d = _d ? new Date(_d) : new Date(-1);
257
- }
258
-
259
- const ts = d.getTime();
260
- const now = Date.now();
261
- const diff = now - ts;
262
- const isFuture = diff < 0;
263
-
264
- if (isFuture && !disableFuture) {
265
- // Future date
266
-
267
- const minutesFromNow = Math.round(diff / 60000 * -1);
268
- if (minutesFromNow < 60) {
269
- return i18n.t('datetime.in_minutes_ct', { smart_count: minutesFromNow });
270
- }
271
-
272
- const fromIsToday = isToday || (!skipTodayCheck && getDatePeriod(d, new Date()) === 'TODAY');
273
- if (fromIsToday) {
274
- const hoursFromNow = Math.round(diff / 3600000 * -1);
275
- if (hoursFromNow <= 8) {
276
- return i18n.t('datetime.in_hours_ct', { smart_count: hoursFromNow });
277
- }
278
-
279
- return getFullDateTime(d, {
280
- locales,
281
- hideDate: true,
282
- });
283
- }
284
- }
285
-
286
- if (!isFuture && diff < nowThresh) {
287
- if (diff < justNowThresh) {
288
- return i18n.t('datetime.just_now');
289
- }
290
-
291
- const minutesAgo = Math.round(diff / 60000);
292
- if (minutesAgo < 60) {
293
- return i18n.t('datetime.minutes_ago_ct', { smart_count: minutesAgo });
294
- }
295
-
296
- const agoIsToday = isToday || (!skipTodayCheck && getDatePeriod(d, new Date()) === 'TODAY');
297
- if (agoIsToday) {
298
- const hoursAgo = Math.round(diff / 3600000);
299
- if (hoursAgo <= 8) {
300
- return i18n.t('datetime.hours_ago_ct', { smart_count: hoursAgo });
301
- }
302
-
303
- return getFullDateTime(d, {
304
- locales,
305
- hideDate: true,
306
- });
307
- }
308
- }
309
-
310
- return getFullDateTime(d, {
311
- locales,
312
- });
313
- }
314
-
315
- /**
316
- * Convert date to full date (readable string)
317
- * type locales = 'en-US' | 'en-GB' | 'en-AU' | 'en-CA' | 'en-IN' | 'en-NZ' | 'en-ZA';
318
- */
319
-
320
- export function getFullDate(
321
- _d: Date | string | number | null,
322
- outputStyle: 'DATE_ONLY' | 'DATE_TEXT' | 'MINIMAL' | 'DETAILED' = 'DATE_ONLY',
323
- locales: string = 'en-US',
324
- ) {
325
- let d;
326
- if (_d instanceof Date) {
327
- d = _d;
328
- } else {
329
- // Make sure _d is not null, before using this function
330
- d = _d ? new Date(_d) : new Date(-1);
331
- }
332
-
333
- switch (outputStyle) {
334
- case 'DATE_ONLY':
335
- // Expected output: "9/1/2024"
336
- return new Intl.DateTimeFormat(locales).format(d);
337
- case 'MINIMAL':
338
- // Expected output: "Sep 1, 2024, 6:54 PM"
339
- return new Intl.DateTimeFormat(locales, {
340
- dateStyle: 'medium', // 'full', 'long', 'medium', 'short'
341
- timeStyle: 'short', // 'full', 'long', 'medium', 'short'
342
- // timeZone: 'Australia/Sydney',
343
- }).format(d);
344
- case 'DATE_TEXT':
345
- // Expected output: "September 1, 2024"
346
- return new Intl.DateTimeFormat(locales, {
347
- dateStyle: 'long',
348
- // timeZone: 'Australia/Sydney',
349
- }).format(d);
350
- case 'DETAILED':
351
- default:
352
- }
353
-
354
- // Expected output: "Sep 1, 2024 at 6:54 PM"
355
- const date = new Intl.DateTimeFormat(locales, {
356
- dateStyle: 'long', // 'full', 'long', 'medium', 'short'
357
- timeStyle: 'short', // 'full', 'long', 'medium', 'short'
358
- // timeZone: 'Australia/Sydney',
359
- }).format(d);
360
-
361
- const parts = new Intl.DateTimeFormat(locales, {
362
- dateStyle: 'long',
363
- timeStyle: 'long',
364
- }).formatToParts(d);
365
-
366
- const timezoneName = parts.find((part) => part.type === 'timeZoneName')?.value;
367
- if (timezoneName) {
368
- // Doing this will make sure {date} does not include [seconds] in the time format
369
- return date + ' ' + timezoneName;
370
- }
371
-
372
- return date;
373
- }
374
-
375
- /**
376
- * Get morning, afternoon, evening, or night
377
- */
378
-
379
- export function getDayPeriod(): 'MORNING' | 'AFTERNOON' | 'EVENING' | 'NIGHT' {
380
- const d = new Date();
381
- const h = d.getHours();
382
- if (h >= 5 && h < 12) {
383
- return 'MORNING';
384
- } else if (h >= 12 && h < 17) {
385
- return 'AFTERNOON';
386
- } else if (h >= 17 && h < 20) {
387
- return 'EVENING';
388
- }
389
- return 'NIGHT';
390
- }
391
-
392
- /**
393
- * Convert YYYY-MM-DD to Date
394
- */
395
-
396
- export function getDateFromCalDate(calDate: string) {
397
- const [year, month, day] = calDate.split('-');
398
- return new Date(Number(year), Number(month) - 1, Number(day));
399
- }
400
-
401
- /**
402
- * Group by time period
403
- *
404
- * @param items - Array of items to group
405
- * @param dateKey - Key in each item that contains the date
406
- * @param mapFn - Optional function to map each item before grouping
407
- *
408
- * @returns Array of grouped items, each group contains items for a specific date period
409
- */
410
-
411
- export function groupByDatePeriod<T>(
412
- items: T[],
413
- dateKey: string,
414
- groupByDate?: boolean,
415
- timeZone?: string | null,
416
- mapFn?: (item: any) => any
417
- ): DatePeriodObj[][] {
418
- const ordered = items.sort((a: any, b: any) => {
419
- const valueA = a[dateKey];
420
- const valueB = b[dateKey];
421
-
422
- if (valueA < valueB) {
423
- return 1;
424
- }
425
- if (valueA > valueB) {
426
- return -1;
427
- }
428
- return 0;
429
- });
430
-
431
- const output = [];
432
- const d = new Date();
433
- // const timeZone = timeZone_; // || Intl.DateTimeFormat().resolvedOptions().timeZone;
434
-
435
- let group: any[] | null = [];
436
- for (const item of ordered) {
437
- // Each group is grouped in date periods,
438
- // e.g. "Tomorrow", "Today", "Yesterday", "Last Week", "Last Month", "Older"
439
- // Group the ordered list by date period and push item to output
440
-
441
- const lastItem = group[group.length - 1];
442
- const lastDatePeriod: any = lastItem?.datePeriod;
443
- const date = new Date((item as any)[dateKey]);
444
- const datePeriod = groupByDate ? getCalDate(date, timeZone).calDate : getDatePeriod(date, d);
445
-
446
- const dateObj = {
447
- datePeriod,
448
- date,
449
- item: mapFn ? mapFn(item) : item,
450
- };
451
-
452
- if (lastDatePeriod && lastDatePeriod !== datePeriod && group.length) {
453
- output.push(group);
454
- group = [];
455
- }
456
-
457
- group.push(dateObj);
458
- }
459
-
460
- if (group.length) {
461
- output.push(group);
462
- }
463
-
464
- return output;
465
- }
466
-
467
- /**
468
- * Sort and label by date period
469
- *
470
- * @param items - Array of items to sort and label
471
- * @param dateKey - Key in each item that contains the date
472
- * @param mapFn - Optional function to map each item before grouping
473
- *
474
- * @returns Array of items sorted by date period, with labels for each period
475
- */
476
-
477
- export function labelSortByDatePeriod<T>(
478
- items: T[],
479
- dateKey: string,
480
- groupByDate?: boolean,
481
- timeZone?: string | null,
482
- mapFn?: (item: any) => any
483
- ): DatePeriodObj[] {
484
- const ordered = items.sort((a: any, b: any) => {
485
- const valueA = a[dateKey];
486
- const valueB = b[dateKey];
487
-
488
- if (valueA < valueB) {
489
- return 1;
490
- }
491
- if (valueA > valueB) {
492
- return -1;
493
- }
494
- return 0;
495
- });
496
-
497
- const output = [];
498
- const d = new Date();
499
-
500
- for (const item of ordered) {
501
- const lastItem = output[output.length - 1];
502
- const lastDatePeriod: any = lastItem?.datePeriod;
503
- const date = new Date((item as any)[dateKey]);
504
- const datePeriod = groupByDate ? getCalDate(date, timeZone).calDate : getDatePeriod(date, d);
505
-
506
- const dateObj = {
507
- datePeriod,
508
- date,
509
- item: mapFn ? mapFn(item) : item,
510
- };
511
-
512
- if (
513
- (!output.length) ||
514
- (lastDatePeriod && lastDatePeriod !== datePeriod)
515
- ) {
516
- output.push({
517
- datePeriod,
518
- date,
519
- item: null,
520
- });
521
- }
522
-
523
- output.push(dateObj);
524
- }
525
-
526
- return output;
527
- }
528
-
529
- /**
530
- * Check if date is valid
531
- */
532
-
533
- export function isValidDate(d?: Date | string | number | null) {
534
- if (d instanceof Date) {
535
- return !isNaN(d.getTime());
536
- }
537
- if (typeof d === 'string' || typeof d === 'number') {
538
- const date = new Date(d);
539
- return !isNaN(date.getTime());
540
- }
541
- return false;
542
- }