@jsb188/app 1.0.4 → 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 (104) hide show
  1. package/package.json +57 -37
  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/src/utils/timeZone.ts +2048 -0
  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/user.ts +0 -36
  80. package/constants/ws.ts +0 -47
  81. package/i18n/app.ts +0 -99
  82. package/i18n/auth.ts +0 -57
  83. package/i18n/billing.ts +0 -94
  84. package/i18n/datetime.ts +0 -22
  85. package/i18n/error.ts +0 -138
  86. package/i18n/form.ts +0 -73
  87. package/i18n/index.ts +0 -6
  88. package/i18n/user.ts +0 -98
  89. package/main.ts +0 -62
  90. package/types/app.d.ts +0 -46
  91. package/types/datetime.d.ts +0 -10
  92. package/types/form.d.ts +0 -56
  93. package/types/user.d.ts +0 -52
  94. package/types.d.ts +0 -23
  95. package/utils/api.ts +0 -99
  96. package/utils/billing.ts +0 -134
  97. package/utils/datetime.ts +0 -358
  98. package/utils/emoji.ts +0 -151
  99. package/utils/logic.ts +0 -115
  100. package/utils/number.ts +0 -115
  101. package/utils/object.ts +0 -367
  102. package/utils/string.ts +0 -211
  103. package/utils/url_client.ts +0 -138
  104. package/utils/user.ts +0 -273
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Scale dimensions proportionally to fit inside the provided bounds.
3
+ */
4
+ export function getContainedDimensions(
5
+ width: number,
6
+ height: number,
7
+ maxWidth: number,
8
+ maxHeight: number,
9
+ ) {
10
+ if (
11
+ !Number.isFinite(width) ||
12
+ !Number.isFinite(height) ||
13
+ !Number.isFinite(maxWidth) ||
14
+ !Number.isFinite(maxHeight) ||
15
+ width <= 0 ||
16
+ height <= 0 ||
17
+ maxWidth <= 0 ||
18
+ maxHeight <= 0
19
+ ) {
20
+ return null;
21
+ }
22
+
23
+ const scale = Math.min(maxWidth / width, maxHeight / height);
24
+
25
+ return {
26
+ width: Math.round(width * scale),
27
+ height: Math.round(height * scale),
28
+ };
29
+ }
30
+
31
+ /**
32
+ * Convert string value to BigInt safely
33
+ */
34
+
35
+ export function toBigInt(value: string | number | bigint): bigint | null {
36
+ try {
37
+ if (typeof value === 'bigint') {
38
+ return value;
39
+ } else if (typeof value === 'number') {
40
+ return BigInt(value);
41
+ } else if (typeof value === 'string') {
42
+ const trimmed = value.trim();
43
+ if (trimmed === '') {
44
+ return null;
45
+ }
46
+ return BigInt(trimmed);
47
+ }
48
+ return null;
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Check if number
56
+ */
57
+
58
+ export function isNumber(input: unknown): input is number | string {
59
+ switch (typeof input) {
60
+ case 'number':
61
+ return input - input === 0;
62
+ case 'bigint':
63
+ return true;
64
+ case 'string':
65
+ return input.trim() !== '' && !Number.isNaN(Number(input));
66
+ }
67
+ return false;
68
+ }
69
+
70
+ /**
71
+ * Allow double digit numbers to be represented by a letter
72
+ */
73
+
74
+ export function numberToLetter(
75
+ num: number,
76
+ alphabet: string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
77
+ ) {
78
+ return alphabet.charAt(num);
79
+ }
80
+
81
+ /**
82
+ * Convert the letter (from above fn()) back to a number;
83
+ */
84
+
85
+ export function letterToNumber(
86
+ letter: string,
87
+ alphabet: string = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
88
+ ) {
89
+ return alphabet.indexOf(letter);
90
+ }
91
+
92
+ /**
93
+ * Get number representation of version number
94
+ */
95
+
96
+ export function versionToNumber(version: string) {
97
+ const arr = String(version).split('.');
98
+ return arr.reduce((acc: number, num: string, n) => {
99
+ let val;
100
+ let minorVal;
101
+ if (!isNaN(Number(num))) {
102
+ val = Number(num);
103
+ minorVal = 0;
104
+ } else {
105
+ // NOTE: Use this to make minor version same as without the letter
106
+ val = Number(num.replace(/\D/g, ''));
107
+ minorVal = letterToNumber(num.replace(/[0-9]/g, ''));
108
+ // console.log('->', num, val, minorVal);
109
+ }
110
+ // console.log(acc + Math.pow(100, 4 - n) * val);
111
+
112
+ return acc + Math.pow(100, 4 - n) * val + minorVal;
113
+ }, 0);
114
+ }
115
+
116
+ /**
117
+ * Format Bytes
118
+ */
119
+
120
+ export function formatBytes(bytes: number, decimals: number = 0) {
121
+ if (!+bytes) {
122
+ return '0 Bytes';
123
+ }
124
+
125
+ const k = 1024;
126
+ const dm = decimals < 0 ? 0 : decimals;
127
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
128
+
129
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
130
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
131
+ }
132
+
133
+ /**
134
+ * Convert number (seconds) to human-friendly time
135
+ */
136
+
137
+ export function secondsToTime(secs: number) {
138
+ if (secs < 60) {
139
+ return {
140
+ value: secs,
141
+ unit: 's',
142
+ };
143
+ } else if (secs >= 604800) {
144
+ const weeks = Math.floor(secs / 604800);
145
+ return {
146
+ value: weeks,
147
+ unit: 'w',
148
+ };
149
+ } else if (secs >= 86400) {
150
+ const days = Math.floor(secs / 86400);
151
+ return {
152
+ value: days,
153
+ unit: 'd',
154
+ };
155
+ } else if (secs >= 3600) {
156
+ const hours = Math.floor(secs / 3600);
157
+ return {
158
+ value: hours,
159
+ unit: 'h',
160
+ };
161
+ }
162
+
163
+ const minutes = Math.floor((secs % 3600) / 60);
164
+ return {
165
+ value: minutes,
166
+ unit: 'm',
167
+ };
168
+ }
169
+
170
+ /**
171
+ * Format decimal number to a string without decimal places or the first non-zero digit
172
+ *
173
+ * @param value - The number to format
174
+ * @param trimDecimals - If true, trims the decimal places to the first non-zero digit
175
+ * @param doNotAllowNaN - If true, returns empty string "" if the value is NaN
176
+ * @returns Formatted string representation of the number
177
+ */
178
+
179
+ export function formatDecimal(
180
+ value_: string | number,
181
+ trimDecimals: boolean = false,
182
+ doNotAllowNaN: boolean = false,
183
+ ): string {
184
+ const value = String(value_);
185
+
186
+ let formattedStr;
187
+ if (Number(value) % 1 === 0) {
188
+ formattedStr = Number(value).toString(); // Whole number
189
+ } else if (trimDecimals) {
190
+ formattedStr = parseFloat(value.toString()).toString(); // Trims to first non-zero decimal
191
+ } else {
192
+ formattedStr = String(value); // Keep existing decimal places
193
+ }
194
+ return doNotAllowNaN && isNaN(Number(formattedStr)) ? '' : formattedStr;
195
+ }
196
+
197
+ /**
198
+ * Get quantity text by combining quantity and unit together
199
+ *
200
+ * @param quantity - The quantity value
201
+ * @param unit - The unit string
202
+ * @returns Combined quantity and unit string
203
+ */
204
+
205
+ export function getQuantityText(
206
+ quantity: string | number,
207
+ unit?: string,
208
+ ): string {
209
+ const value = formatDecimal(quantity, true, true);
210
+ return [value + (value && unit && /^[0-9]/.test(unit) ? ', ' : ''), unit]
211
+ .filter(Boolean)
212
+ .join(' ');
213
+ }
214
+
215
+ /**
216
+ * Get currency symbol from settings
217
+ * Example 1: getCurrencySymbol('en-US', 'USD'); // "$"
218
+ * Example 2: getCurrencySymbol('fr-FR', 'EUR'); // "€"
219
+ * Example 3: getCurrencySymbol('ja-JP', 'JPY'); // "¥"
220
+ * Example 4: getCurrencySymbol('en-GB', 'GBP'); // "£"
221
+ *
222
+ * @param locale - The locale to use for formatting
223
+ * @param currency - The currency code (e.g., 'USD', 'EUR')
224
+ * @returns currency symbol as a string
225
+ */
226
+
227
+ export function getCurrencySymbol(locale: string, currency: string): string {
228
+ const parts = new Intl.NumberFormat(locale, {
229
+ style: 'currency',
230
+ currency,
231
+ minimumFractionDigits: 0,
232
+ maximumFractionDigits: 0,
233
+ }).formatToParts(1);
234
+
235
+ const symbolPart = parts.find((part) => part.type === 'currency');
236
+ return symbolPart?.value || '';
237
+ }
238
+
239
+ /**
240
+ * Format number to currency format
241
+ */
242
+
243
+ export function formatCurrency(
244
+ amount: string | number,
245
+ trailZeros: boolean = true,
246
+ locale: string = 'en-US',
247
+ currency: string = 'USD',
248
+ ): string {
249
+ const num = typeof amount === 'string' ? parseFloat(amount) : amount;
250
+ if (!num && num !== 0) {
251
+ return '';
252
+ }
253
+
254
+ if (isNaN(num)) {
255
+ return trailZeros ? '$0.00' : '$0';
256
+ }
257
+
258
+ const hasDecimals = num % 1 !== 0;
259
+ const symbol = getCurrencySymbol(locale, currency);
260
+
261
+ return (
262
+ symbol +
263
+ num.toLocaleString(locale, {
264
+ minimumFractionDigits: hasDecimals || trailZeros ? 2 : 0,
265
+ maximumFractionDigits: hasDecimals || trailZeros ? 2 : 0,
266
+ })
267
+ );
268
+ }
269
+
270
+ /**
271
+ * Format number to have "," between every thousands
272
+ */
273
+
274
+ export function kFormat(
275
+ num: string | number,
276
+ locale: string = 'en-US',
277
+ ): string {
278
+ const number = typeof num === 'string' ? parseFloat(num) : num;
279
+ if (isNaN(number)) {
280
+ return String(num);
281
+ }
282
+
283
+ return number.toLocaleString(locale, {
284
+ minimumFractionDigits: 0,
285
+ maximumFractionDigits: 0,
286
+ });
287
+ }
288
+
289
+ /**
290
+ * Convert number based time to military time format (e.g., 1300 to 13:00)
291
+ */
292
+
293
+ export function convertToMilitaryTime(
294
+ time?: number | string | null,
295
+ ): string | null {
296
+ if (time) {
297
+ const timeString = String(time).padStart(4, '0');
298
+ return `${timeString.slice(0, 2)}:${timeString.slice(2)}`;
299
+ }
300
+ return null;
301
+ }
302
+
303
+ /**
304
+ * Return the stored total amount from a label/value line item
305
+ */
306
+
307
+ export function getLabelAndValueTotalAmount(
308
+ item?: { value?: string | number | null } | null,
309
+ ): number {
310
+ const val = parseFloat(String(item?.value ?? ''));
311
+ return isNaN(val) ? 0 : val;
312
+ }
313
+
314
+ /**
315
+ * Return the unit amount from a label/value line item whose value stores the line total
316
+ */
317
+
318
+ export function getLabelAndValueUnitAmount(
319
+ item?: {
320
+ value?: string | number | null;
321
+ quantity?: string | number | null;
322
+ } | null,
323
+ ): number {
324
+ const totalAmount = getLabelAndValueTotalAmount(item);
325
+ const quantity = Number(item?.quantity || 1);
326
+ return !quantity || isNaN(quantity) ? totalAmount : totalAmount / quantity;
327
+ }
328
+
329
+ /**
330
+ * Calculate totals from LabelAndValueObj[]
331
+ */
332
+
333
+ export function calculateTotalAmount(values: any[], tax: number = 0): number {
334
+ return (values || []).reduce((acc, obj) => {
335
+ // NOTE: obj.value is the total, so obj.quantity can be ignored
336
+ return acc + getLabelAndValueTotalAmount(obj);
337
+ }, tax || 0);
338
+ }