@jsb188/app 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.
Files changed (79) hide show
  1. package/package.json +57 -45
  2. package/src/constants/agent.ts +51 -41
  3. package/src/constants/app.ts +34 -13
  4. package/src/constants/emoji.ts +9144 -8936
  5. package/src/constants/other.ts +1 -5
  6. package/src/constants/user.ts +16 -25
  7. package/src/constants/wsActions.ts +27 -0
  8. package/src/i18n/account.ts +129 -107
  9. package/src/i18n/agent.ts +331 -73
  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 +107 -91
  15. package/src/i18n/auth.ts +117 -102
  16. package/src/i18n/billing.ts +5 -92
  17. package/src/i18n/c.ts +907 -0
  18. package/src/i18n/campaign.ts +919 -0
  19. package/src/i18n/country.ts +248 -248
  20. package/src/i18n/datetime.ts +32 -26
  21. package/src/i18n/editor.ts +58 -0
  22. package/src/i18n/error.ts +577 -192
  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 +42 -19
  27. package/src/i18n/log.ts +272 -238
  28. package/src/i18n/memory.ts +53 -0
  29. package/src/i18n/message.ts +3 -4
  30. package/src/i18n/note.ts +19 -0
  31. package/src/i18n/org.ts +164 -109
  32. package/src/i18n/schedule.ts +209 -0
  33. package/src/i18n/sheet.ts +333 -4
  34. package/src/i18n/sheet_formula.ts +165 -0
  35. package/src/i18n/workflow.ts +109 -23
  36. package/src/main.ts +68 -64
  37. package/src/platform.ts +90 -49
  38. package/src/types/ai.d.ts +52 -23
  39. package/src/types/app.d.ts +95 -44
  40. package/src/types/auth.d.ts +66 -40
  41. package/src/types/console.d.ts +3 -0
  42. package/src/types/other.d.ts +13 -6
  43. package/src/types.d.ts +12 -14
  44. package/src/utils/account.ts +64 -58
  45. package/src/utils/api.ts +326 -77
  46. package/src/utils/authSession.ts +24 -0
  47. package/src/utils/clientIP.ts +213 -0
  48. package/src/utils/color.ts +279 -0
  49. package/src/utils/cron.ts +49 -18
  50. package/src/utils/csv.ts +19 -0
  51. package/src/utils/datetime.ts +445 -117
  52. package/src/utils/deferredSave.ts +89 -0
  53. package/src/utils/email.ts +50 -0
  54. package/src/utils/emoji.ts +107 -84
  55. package/src/utils/expression.helpers.ts +470 -0
  56. package/src/utils/expression.test.ts +793 -0
  57. package/src/utils/expression.ts +2261 -0
  58. package/src/utils/interval.ts +80 -0
  59. package/src/utils/language.ts +9 -0
  60. package/src/utils/logic.ts +141 -121
  61. package/src/utils/managedSession.ts +34 -0
  62. package/src/utils/managedSessionBff.test.ts +60 -0
  63. package/src/utils/managedSessionBff.ts +117 -0
  64. package/src/utils/number.ts +85 -38
  65. package/src/utils/object.ts +227 -30
  66. package/src/utils/promise.ts +98 -0
  67. package/src/utils/queryReset.ts +266 -0
  68. package/src/utils/recurringTask.ts +60 -0
  69. package/src/utils/schema.ts +293 -0
  70. package/src/utils/string.test.ts +205 -208
  71. package/src/utils/string.ts +426 -463
  72. package/src/utils/timeZone.ts +309 -851
  73. package/src/utils/url_client.ts +145 -72
  74. package/tsconfig.json +10 -10
  75. package/src/constants/billing.ts +0 -146
  76. package/src/i18n/form.ts +0 -376
  77. package/src/i18n/product.ts +0 -76
  78. package/src/types/form.d.ts +0 -97
  79. package/src/utils/billing.ts +0 -134
@@ -0,0 +1,279 @@
1
+ import { COLORS } from '../constants/app.ts';
2
+ import type { ColorEnum } from '../types/app.d.ts';
3
+ import { hashStringFNV1a } from './string.ts';
4
+
5
+ type RGBColorObj = {
6
+ blue: number;
7
+ green: number;
8
+ red: number;
9
+ };
10
+
11
+ const APP_COLOR_HEX_VALUES: Record<ColorEnum, string> = {
12
+ amber: '#f59e0b',
13
+ blue: '#3b82f6',
14
+ brown: '#a16207',
15
+ cyan: '#06b6d4',
16
+ emerald: '#10b981',
17
+ fuchsia: '#d946ef',
18
+ green: '#22c55e',
19
+ indigo: '#6366f1',
20
+ lime: '#84cc16',
21
+ orange: '#f97316',
22
+ pink: '#ec4899',
23
+ purple: '#a855f7',
24
+ red: '#ef4444',
25
+ rose: '#f43f5e',
26
+ sky: '#0ea5e9',
27
+ slate: '#64748b',
28
+ stone: '#78716c',
29
+ teal: '#14b8a6',
30
+ violet: '#8b5cf6',
31
+ yellow: '#eab308',
32
+ zinc: '#71717a',
33
+ };
34
+
35
+ /**
36
+ * Return an app palette name only when the supplied value belongs to the palette.
37
+ */
38
+ export function getAppColorName(
39
+ color: string | null | undefined,
40
+ ): ColorEnum | undefined {
41
+ if (!color || !Object.hasOwn(APP_COLOR_HEX_VALUES, color)) {
42
+ return undefined;
43
+ }
44
+
45
+ return color as ColorEnum;
46
+ }
47
+
48
+ /**
49
+ * Resolve an app palette name to its CSS hex value while preserving custom colors.
50
+ */
51
+ export function getAppColorValue(
52
+ color: string | null | undefined,
53
+ ): string | undefined {
54
+ return color && Object.hasOwn(APP_COLOR_HEX_VALUES, color)
55
+ ? APP_COLOR_HEX_VALUES[color as ColorEnum]
56
+ : color || undefined;
57
+ }
58
+
59
+ /**
60
+ * Return one app palette hex color picked deterministically by index.
61
+ */
62
+ export function getAppColorHexByIndex(index: number): string {
63
+ const hexValues = Object.values(APP_COLOR_HEX_VALUES);
64
+ return hexValues[Math.abs(Math.floor(index)) % hexValues.length];
65
+ }
66
+
67
+ /**
68
+ * Return a valid app color name, falling back to a stable color selected from the fully mixed id string.
69
+ */
70
+ export function getValidColor(
71
+ color: string | null | undefined,
72
+ id: string | number | null | undefined,
73
+ ): ColorEnum {
74
+ const normalizedColor = String(color || '')
75
+ .trim()
76
+ .toLowerCase();
77
+
78
+ if (COLORS.includes(normalizedColor as ColorEnum)) {
79
+ return normalizedColor as ColorEnum;
80
+ }
81
+
82
+ let colorIndexHash = parseInt(hashStringFNV1a(String(id)), 16);
83
+ colorIndexHash ^= colorIndexHash >>> 16;
84
+ colorIndexHash = Math.imul(colorIndexHash, 0x85ebca6b);
85
+ colorIndexHash ^= colorIndexHash >>> 13;
86
+ colorIndexHash = Math.imul(colorIndexHash, 0xc2b2ae35);
87
+ colorIndexHash ^= colorIndexHash >>> 16;
88
+
89
+ return COLORS[(colorIndexHash >>> 0) % COLORS.length] as ColorEnum;
90
+ }
91
+
92
+ const RGB_COLOR_REGEX = /^rgba?\(([^)]+)\)$/i;
93
+ const HEX_COLOR_VALUE_REGEX = /^#[0-9a-f]{6}$/i;
94
+ const HEX_COLOR_DRAFT_VALUE_REGEX = /^#[0-9a-f]{0,6}$/i;
95
+
96
+ /**
97
+ * Return whether one value is a valid hex color value or editable hex draft.
98
+ */
99
+ export function isHexColorValue(
100
+ value: string | null | undefined,
101
+ allowDraft: boolean = false,
102
+ ): boolean {
103
+ const normalized = String(value || '').trim();
104
+
105
+ if (allowDraft && !normalized) {
106
+ return true;
107
+ }
108
+
109
+ return allowDraft
110
+ ? HEX_COLOR_DRAFT_VALUE_REGEX.test(normalized)
111
+ : HEX_COLOR_VALUE_REGEX.test(normalized);
112
+ }
113
+
114
+ /**
115
+ * Convert a CSS hex color into RGB channel values.
116
+ */
117
+ function getRGBColorFromHex(color: string): RGBColorObj | null {
118
+ const normalized = color.trim().replace('#', '');
119
+ const isShortHex = normalized.length === 3;
120
+ const isLongHex = normalized.length === 6;
121
+
122
+ if ((!isShortHex && !isLongHex) || /[^0-9a-f]/i.test(normalized)) {
123
+ return null;
124
+ }
125
+
126
+ const fullHex = isShortHex
127
+ ? normalized
128
+ .split('')
129
+ .map((char) => char + char)
130
+ .join('')
131
+ : normalized;
132
+
133
+ return {
134
+ red: parseInt(fullHex.slice(0, 2), 16),
135
+ green: parseInt(fullHex.slice(2, 4), 16),
136
+ blue: parseInt(fullHex.slice(4, 6), 16),
137
+ };
138
+ }
139
+
140
+ /**
141
+ * Convert a CSS rgb() or rgba() color into RGB channel values.
142
+ */
143
+ function getRGBColorFromRGBFunction(color: string): RGBColorObj | null {
144
+ const match = color.trim().match(RGB_COLOR_REGEX);
145
+ if (!match) {
146
+ return null;
147
+ }
148
+
149
+ const channels = match[1]
150
+ .split(',')
151
+ .slice(0, 3)
152
+ .map((channel) => Number(channel.trim()));
153
+ if (
154
+ channels.length < 3 ||
155
+ channels.some((channel) => Number.isNaN(channel))
156
+ ) {
157
+ return null;
158
+ }
159
+
160
+ return {
161
+ red: channels[0],
162
+ green: channels[1],
163
+ blue: channels[2],
164
+ };
165
+ }
166
+
167
+ /**
168
+ * Convert a supported color value into RGB channel values.
169
+ */
170
+ export function getRGBColor(
171
+ color: string | null | undefined,
172
+ ): RGBColorObj | null {
173
+ if (!color) {
174
+ return null;
175
+ }
176
+
177
+ const normalized = color.trim().toLowerCase();
178
+ const appColorHex = APP_COLOR_HEX_VALUES[normalized as ColorEnum];
179
+
180
+ if (appColorHex) {
181
+ return getRGBColorFromHex(appColorHex);
182
+ } else if (normalized.startsWith('#')) {
183
+ return getRGBColorFromHex(normalized);
184
+ }
185
+
186
+ return getRGBColorFromRGBFunction(normalized);
187
+ }
188
+
189
+ /**
190
+ * Return a darker hex color derived from any supported color value, scaling
191
+ * every RGB channel toward black by the given factor (0-1). Useful for
192
+ * deriving an accent tone from a soft pastel background color.
193
+ */
194
+ export function getDarkerHexColor(
195
+ color: string | null | undefined,
196
+ factor: number = 0.5,
197
+ ): string | null {
198
+ const rgb = getRGBColor(color);
199
+ if (!rgb) {
200
+ return null;
201
+ }
202
+
203
+ const channel = (value: number) =>
204
+ Math.max(0, Math.min(255, Math.round(value * factor)))
205
+ .toString(16)
206
+ .padStart(2, '0');
207
+
208
+ return `#${channel(rgb.red)}${channel(rgb.green)}${channel(rgb.blue)}`;
209
+ }
210
+
211
+ /**
212
+ * Return whether a color should be treated as dark based on perceived brightness.
213
+ */
214
+ export function isDarkColor(
215
+ color: string | null | undefined,
216
+ fallback: boolean = false,
217
+ ): boolean {
218
+ const rgb = getRGBColor(color);
219
+ if (!rgb) {
220
+ return fallback;
221
+ }
222
+
223
+ const brightness = (rgb.red * 299 + rgb.green * 587 + rgb.blue * 114) / 1000;
224
+
225
+ return brightness < 128;
226
+ }
227
+
228
+ /**
229
+ * Normalize one numeric RGB channel to an integer within the supported range.
230
+ */
231
+ function getNormalizedRGBChannel(channel: number): number {
232
+ return Math.max(0, Math.min(255, Math.round(channel)));
233
+ }
234
+
235
+ /**
236
+ * Convert one numeric RGB channel into a two-digit hex value.
237
+ */
238
+ function getHexColorChannel(channel: number): string {
239
+ return getNormalizedRGBChannel(channel).toString(16).padStart(2, '0');
240
+ }
241
+
242
+ /**
243
+ * Convert numeric RGB channels into a six-digit CSS hex color.
244
+ */
245
+ export function getHexColorFromRGB(
246
+ red: number,
247
+ green: number,
248
+ blue: number,
249
+ ): string {
250
+ return `#${getHexColorChannel(red)}${getHexColorChannel(green)}${getHexColorChannel(blue)}`;
251
+ }
252
+
253
+ /**
254
+ * Convert one sRGB channel into its linear-light value.
255
+ */
256
+ function getLinearRGBChannel(channel: number): number {
257
+ const normalizedChannel = channel / 255;
258
+ return normalizedChannel <= 0.04045
259
+ ? normalizedChannel / 12.92
260
+ : Math.pow((normalizedChannel + 0.055) / 1.055, 2.4);
261
+ }
262
+
263
+ /**
264
+ * Calculate WCAG relative luminance for a supported sRGB color.
265
+ */
266
+ export function getRelativeLuminance(
267
+ color: string | null | undefined,
268
+ ): number | null {
269
+ const rgb = getRGBColor(color);
270
+ if (!rgb) {
271
+ return null;
272
+ }
273
+
274
+ return (
275
+ 0.2126 * getLinearRGBChannel(rgb.red) +
276
+ 0.7152 * getLinearRGBChannel(rgb.green) +
277
+ 0.0722 * getLinearRGBChannel(rgb.blue)
278
+ );
279
+ }
package/src/utils/cron.ts CHANGED
@@ -7,7 +7,8 @@ import { CronExpressionParser } from 'cron-parser';
7
7
  export function getCronDescription(schedule: string, verbose = false): string {
8
8
  try {
9
9
  const parsed = CronExpressionParser.parse(schedule);
10
- const { second, minute, hour, dayOfMonth, month, dayOfWeek } = parsed.fields;
10
+ const { second, minute, hour, dayOfMonth, month, dayOfWeek } =
11
+ parsed.fields;
11
12
  const secondRawValues = second.values as Array<number | string>;
12
13
  const minuteRawValues = minute.values as Array<number | string>;
13
14
  const hourRawValues = hour.values as Array<number | string>;
@@ -33,12 +34,11 @@ export function getCronDescription(schedule: string, verbose = false): string {
33
34
  const monthValues = normalizeValues(monthRawValues);
34
35
  const dayOfWeekValues = normalizeDayOfWeekValues(dayOfWeekRawValues);
35
36
 
36
- const hasSimpleTimeNoSeconds = (
37
+ const hasSimpleTimeNoSeconds =
37
38
  secondValues.length === 1 &&
38
39
  secondValues[0] === 0 &&
39
40
  minuteValues.length === 1 &&
40
- hourValues.length === 1
41
- );
41
+ hourValues.length === 1;
42
42
 
43
43
  if (hasSimpleTimeNoSeconds) {
44
44
  const timeText = formatCronTime(hourValues[0], minuteValues[0]);
@@ -51,11 +51,19 @@ export function getCronDescription(schedule: string, verbose = false): string {
51
51
  return `Every day${timeJoinText}${timeText}`;
52
52
  }
53
53
 
54
- if (isEveryMonth && isEveryDayOfMonth && isExactValues(dayOfWeekValues, [1, 2, 3, 4, 5])) {
54
+ if (
55
+ isEveryMonth &&
56
+ isEveryDayOfMonth &&
57
+ isExactValues(dayOfWeekValues, [1, 2, 3, 4, 5])
58
+ ) {
55
59
  return `Mon-Fri${timeJoinText}${timeText}`;
56
60
  }
57
61
 
58
- if (isEveryMonth && isEveryDayOfMonth && isExactValues(dayOfWeekValues, [1, 3, 5])) {
62
+ if (
63
+ isEveryMonth &&
64
+ isEveryDayOfMonth &&
65
+ isExactValues(dayOfWeekValues, [1, 3, 5])
66
+ ) {
59
67
  return `Every other Mon-Fri${timeJoinText}${timeText}`;
60
68
  }
61
69
 
@@ -86,7 +94,11 @@ function formatCronTime(hour24: number, minute: number): string {
86
94
  return `${hour12}:${minuteText} ${amPm}`;
87
95
  }
88
96
 
89
- function formatCronTimeWithSeconds(hour24: number, minute: number, second: number): string {
97
+ function formatCronTimeWithSeconds(
98
+ hour24: number,
99
+ minute: number,
100
+ second: number,
101
+ ): string {
90
102
  const amPm = hour24 >= 12 ? 'PM' : 'AM';
91
103
  const hour12 = hour24 % 12 || 12;
92
104
  const minuteText = String(minute).padStart(2, '0');
@@ -130,14 +142,22 @@ function normalizeDayOfWeekValues(values: number[]): number[] {
130
142
  return normalizeValues(values.map((v) => (v === 7 ? 0 : v)));
131
143
  }
132
144
 
133
- function describeCalendar(dayOfMonthValues: number[], monthValues: number[], dayOfWeekValues: number[]): string {
145
+ function describeCalendar(
146
+ dayOfMonthValues: number[],
147
+ monthValues: number[],
148
+ dayOfWeekValues: number[],
149
+ ): string {
134
150
  const dom = describeDayOfMonth(dayOfMonthValues);
135
151
  const mon = describeMonth(monthValues);
136
152
  const dow = describeDayOfWeek(dayOfWeekValues);
137
153
  return `${dom}, ${mon}, ${dow}`;
138
154
  }
139
155
 
140
- function describeTime(secondValues: number[], minuteValues: number[], hourValues: number[]): string {
156
+ function describeTime(
157
+ secondValues: number[],
158
+ minuteValues: number[],
159
+ hourValues: number[],
160
+ ): string {
141
161
  const singleHour = hourValues.length === 1;
142
162
  const singleMinute = minuteValues.length === 1;
143
163
  const singleSecond = secondValues.length === 1;
@@ -195,7 +215,11 @@ function describeDayOfWeek(values: number[]): string {
195
215
  return formatRanges(normalized, (v) => DAY_LABELS[v]);
196
216
  }
197
217
 
198
- function describeNumericValues(values: number[], min: number, max: number): string {
218
+ function describeNumericValues(
219
+ values: number[],
220
+ min: number,
221
+ max: number,
222
+ ): string {
199
223
  const normalized = normalizeValues(values);
200
224
  if (isRangeFull(normalized, min, max)) {
201
225
  return 'every value';
@@ -209,7 +233,9 @@ function describeNumericValues(values: number[], min: number, max: number): stri
209
233
  return formatRanges(normalized);
210
234
  }
211
235
 
212
- function detectStep(values: number[]): { value: number; start: number; end: number } | null {
236
+ function detectStep(
237
+ values: number[],
238
+ ): { value: number; start: number; end: number } | null {
213
239
  if (values.length < 3) {
214
240
  return null;
215
241
  }
@@ -218,14 +244,17 @@ function detectStep(values: number[]): { value: number; start: number; end: numb
218
244
  return null;
219
245
  }
220
246
  for (let i = 2; i < values.length; i += 1) {
221
- if ((values[i] - values[i - 1]) !== diff) {
247
+ if (values[i] - values[i - 1] !== diff) {
222
248
  return null;
223
249
  }
224
250
  }
225
251
  return { value: diff, start: values[0], end: values[values.length - 1] };
226
252
  }
227
253
 
228
- function formatRanges(values: number[], labeler?: (v: number) => string): string {
254
+ function formatRanges(
255
+ values: number[],
256
+ labeler?: (v: number) => string,
257
+ ): string {
229
258
  if (values.length === 0) {
230
259
  return '';
231
260
  }
@@ -246,11 +275,13 @@ function formatRanges(values: number[], labeler?: (v: number) => string): string
246
275
  }
247
276
  segments.push({ start, end: prev });
248
277
 
249
- return segments.map(({ start: s, end: e }) => {
250
- const a = labeler ? labeler(s) : String(s);
251
- const b = labeler ? labeler(e) : String(e);
252
- return s === e ? a : `${a}-${b}`;
253
- }).join(', ');
278
+ return segments
279
+ .map(({ start: s, end: e }) => {
280
+ const a = labeler ? labeler(s) : String(s);
281
+ const b = labeler ? labeler(e) : String(e);
282
+ return s === e ? a : `${a}-${b}`;
283
+ })
284
+ .join(', ');
254
285
  }
255
286
 
256
287
  const DAY_LABELS: Record<number, string> = {
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Identify spreadsheet formulas while preserving plain signed numbers and
3
+ * phone-like text. CSV quoting alone does not prevent formula execution.
4
+ */
5
+ export function isCSVFormulaLikeValue(text: string) {
6
+ if (/^[=@\t\r\n]/.test(text)) {
7
+ return true;
8
+ }
9
+ return /^[+-]/.test(text) && !/^[+-]?[\d\s().-]+$/.test(text) && !/^[+-]?(?:\d+\.?\d*|\.\d+)[eE][+-]?\d+$/.test(text);
10
+ }
11
+
12
+ /* Escape one CSV cell and neutralize spreadsheet formulas with an apostrophe. */
13
+ export function escapeCSVValue(value: unknown) {
14
+ let text = String(value ?? '');
15
+ if (isCSVFormulaLikeValue(text)) {
16
+ text = `'${text}`;
17
+ }
18
+ return /[",\n\r]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
19
+ }