@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/object.ts DELETED
@@ -1,425 +0,0 @@
1
- /**
2
- * Filter array and return only unique values
3
- */
4
-
5
- export function uniq(arr: Array<any>, fn?: (value: any, index: number, self: Array<any>) => boolean) {
6
- return arr.filter((value, index, self) => {
7
- return self.indexOf(value) === index && (!fn || fn(value, index, self));
8
- });
9
- }
10
-
11
- /**
12
- * Freeze object
13
- * NOTE: This is useful for preventing Array from turning into Array-like Object
14
- */
15
-
16
- // export function freezeObject(obj: object) {
17
- // if (Array.isArray(obj)) {
18
- // Object.freeze(obj);
19
- // }
20
-
21
- // for (const key in obj) {
22
- // if (Object.prototype.hasOwnProperty.call(obj, key) && typeof obj[key] === 'object') {
23
- // freezeObject(obj[key]);
24
- // }
25
- // }
26
- // }
27
-
28
- /**
29
- * Remove undefined (and/or null) values from an object
30
- */
31
-
32
- export function removeUndefined(obj: Record<string, any>, removeNull?: boolean) {
33
- for (const key in obj) {
34
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
35
- if (
36
- obj[key] === undefined ||
37
- (removeNull && obj[key] === null)
38
- ) {
39
- delete obj[key];
40
- } else if (typeof obj[key] === 'object') {
41
- removeUndefined(obj[key], removeNull);
42
- }
43
- }
44
- }
45
- return obj;
46
- }
47
-
48
- /**
49
- * Force undefined values to be null instead
50
- * NOTE: This is useful for database bulkInserts where undefined values in Postgres ORM causes inconsistent queries
51
- */
52
-
53
- export function setUndefinedToNull<T>(obj: T, objMap?: Record<string, any>): T {
54
- for (const key in obj) {
55
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
56
- if (obj[key] === undefined) {
57
- obj[key] = objMap?.[key] ?? null;
58
- }
59
- }
60
- }
61
- return obj;
62
- }
63
-
64
- /**
65
- * Try/catch parse JSON object
66
- */
67
-
68
- export function parseJSON(jsonStr?: string) {
69
- if (jsonStr === undefined || jsonStr === null) {
70
- return null;
71
- }
72
-
73
- try {
74
- return JSON.parse(jsonStr);
75
- } catch (err) {
76
- console.warn(err);
77
- }
78
- return null;
79
- }
80
-
81
- /**
82
- * Merge nested objects together
83
- */
84
-
85
- export function mergeNestedObjects(obj1: any, obj2: any) {
86
- if (!obj1) {
87
- return { ...obj2 };
88
- }
89
-
90
- const newObj = { ...obj1 };
91
- for (const key in obj2) {
92
- if (Object.prototype.hasOwnProperty.call(obj2, key)) {
93
- if (typeof obj2[key] === 'object' && obj2[key] !== null) {
94
- newObj[key] = mergeNestedObjects(obj1[key], obj2[key]);
95
- } else {
96
- newObj[key] = obj2[key];
97
- }
98
- }
99
- }
100
-
101
- return newObj;
102
- }
103
-
104
- /**
105
- * Check if objects are equal
106
- */
107
-
108
- export function areObjectsEqual(
109
- obj1: any,
110
- obj2: any,
111
- isNested: boolean = false,
112
- ) {
113
- if (isNested) {
114
- return JSON.stringify(obj1) === JSON.stringify(obj2);
115
- } else if (obj1 && obj2) {
116
- return Object.keys(obj1).every((key: string) =>
117
- Object.prototype.hasOwnProperty.call(obj2, key) && obj1[key] === obj2[key]
118
- );
119
- }
120
- return obj1 === obj2;
121
- }
122
-
123
- /**
124
- * Order an array of objects by a key
125
- */
126
-
127
- export function orderBy(
128
- arr: Array<any>,
129
- key: ((obj: any) => any) | string,
130
- order: 'asc' | 'desc' = 'asc',
131
- ) {
132
- const compareFn = (a: any, b: any) => {
133
- const valueA = typeof key === 'function' ? key(a) : a[key];
134
- const valueB = typeof key === 'function' ? key(b) : b[key];
135
-
136
- if (valueA < valueB) {
137
- return order === 'asc' ? -1 : 1;
138
- }
139
- if (valueA > valueB) {
140
- return order === 'asc' ? 1 : -1;
141
- }
142
- return 0;
143
- };
144
-
145
- return arr.sort(compareFn);
146
- }
147
-
148
- /**
149
- * Group array by something
150
- */
151
-
152
- export function groupBy(arr: Array<any>, key: string) {
153
- return arr.reduce((acc, obj) => {
154
- const group = obj[key];
155
- acc[group] = acc[group] || [];
156
- acc[group].push(obj);
157
- return acc;
158
- }, {});
159
- }
160
-
161
- /**
162
- * Make sure each array item is unique by a key check
163
- */
164
-
165
- export function uniqBy(arr: any[], keys: ((obj: any) => any) | string) {
166
- let keyGetter;
167
- if (typeof keys === 'function') {
168
- keyGetter = keys;
169
- } else if (Array.isArray(keys)) {
170
- keyGetter = (o: any) => keys.map((k) => get(o, k)).join('');
171
- } else {
172
- keyGetter = (o: any) => get(o, keys);
173
- }
174
-
175
- return arr.filter((obj, index, self) => {
176
- const key = keyGetter(obj);
177
- return self.findIndex((obj2) => {
178
- const key2 = keyGetter(obj2);
179
- return key2 === key;
180
- }) === index;
181
- });
182
- }
183
-
184
- /**
185
- * Pick a random item from an array
186
- */
187
-
188
- export function randomItem(arr: Array<any>) {
189
- return arr[Math.floor(Math.random() * arr.length)];
190
- }
191
-
192
- /**
193
- * Rearrange an array left or right
194
- */
195
-
196
- export function rearrangeArray(arr: Array<any>, loop: number = 1, shiftRight?: boolean) {
197
- if (shiftRight) {
198
- for (let i = 0; i < loop; i++) {
199
- arr.unshift(arr.pop());
200
- }
201
- } else {
202
- for (let i = 0; i < loop; i++) {
203
- arr.push(arr.shift());
204
- }
205
- }
206
- }
207
-
208
- /**
209
- * Get the value in an object at path separted by dots
210
- */
211
-
212
- export function get(object: any, path: string) {
213
- return path.split('.').reduce((o, key) => o && o[key], object);
214
- }
215
-
216
- /**
217
- * Zip objects together from a list of alternating keys and values
218
- * NOTE: Use this after Redis.hgetall()
219
- */
220
-
221
- export function hgetZipObject(arr: Array<string>, mapperFn?: (value: string, index: number) => any) {
222
- const obj: Record<string, any> = {};
223
- for (let i = 0; i < arr.length; i += 2) {
224
- if (mapperFn) {
225
- obj[arr[i]] = mapperFn(arr[i + 1], i);
226
- } else {
227
- obj[arr[i]] = arr[i + 1];
228
- }
229
- }
230
- return obj;
231
- }
232
-
233
- /**
234
- * Zip objects from keys and values
235
- */
236
-
237
- export function zipObject(keys: Array<string>, values: Array<any>) {
238
- const obj: Record<string, any> = {};
239
- for (let i = 0; i < keys.length; i++) {
240
- obj[keys[i]] = values[i];
241
- }
242
- return obj;
243
- }
244
-
245
- /**
246
- * Find last index of an item in an array
247
- * NOTE: Use this for best NodeJS and browser compatibility
248
- */
249
-
250
- export function findLastIndex(arr: Array<any>, fn: (value: any, index: number, array: any[]) => boolean) {
251
- if (typeof arr.findLastIndex === 'function') {
252
- return arr.findLastIndex(fn);
253
- }
254
-
255
- for (let i = arr.length - 1; i >= 0; i--) {
256
- if (fn(arr[i], i, arr)) {
257
- return i;
258
- }
259
- }
260
- return -1;
261
- }
262
-
263
- /**
264
- * Array intersection
265
- */
266
-
267
- export function intersection(arr1: Array<any>, arr2: Array<any>) {
268
- return arr1.filter((value) => arr2.includes(value));
269
- }
270
-
271
- /**
272
- * Get a nested value of an object at a property path
273
- *
274
- * @param obj - The object to get the value from
275
- * @param path - The property path as a string, e.g. 'a.b.c'
276
- */
277
-
278
- export function getNestedValue(obj: any, path: string): any {
279
- if (!obj || !path) {
280
- return undefined;
281
- }
282
- return path.split('.').reduce((o, key) => {
283
- if (o && typeof o === 'object' && key in o) {
284
- return o[key];
285
- }
286
- return undefined;
287
- }, obj);
288
- }
289
-
290
- /**
291
- * Append value to a nested object
292
- *
293
- * @param obj - The object to append to
294
- * @param path - The property path as a string, e.g. 'a.b.c'
295
- * @param value - The value to append
296
- */
297
-
298
- export function assignToNestedObject(obj: any, path: string, value: any) {
299
- if (!obj || !path) {
300
- return;
301
- }
302
- const keys = path.split('.');
303
- const lastKey = keys.pop();
304
- const nestedObj = keys.reduce((o, key) => {
305
- if (!o[key]) {
306
- o[key] = {};
307
- }
308
- return o[key];
309
- }, obj);
310
-
311
- if (lastKey) {
312
- if (typeof nestedObj === 'object' && nestedObj !== null) {
313
- nestedObj[lastKey] = value;
314
- } else {
315
- console.warn(`(!1) Cannot assign value to ${lastKey} because its reference is not an object.`);
316
- }
317
- }
318
-
319
- return obj;
320
- }
321
-
322
- /**
323
- * Group a collection and merge array fields
324
- * NOTE: Use this after a findAll() query with inner collections
325
- *
326
- * @param collections
327
- * @param innerCollectionNames
328
- * @param primaryKeyName
329
- * @returns
330
- */
331
-
332
- export function groupCollections(collections: Array<any>, innerCollectionNames: string[], primaryKeyName = 'id'): any[] {
333
- return collections.reduce((acc, obj) => {
334
- const primaryKey = obj[primaryKeyName];
335
- const i = acc.findIndex((o: any) => o[primaryKeyName] === primaryKey);
336
-
337
- if (i === -1) {
338
- innerCollectionNames.forEach((name: string) => {
339
- const ref = getNestedValue(obj, name);
340
- if (!ref) {
341
- assignToNestedObject(obj, name, []);
342
- } else {
343
- assignToNestedObject(obj, name, [ref]);
344
- }
345
-
346
- // Old version, but this doesn't support merged array collections
347
- // if (!obj[name]) {
348
- // obj[name] = [];
349
- // } else {
350
- // obj[name] = [obj[name]];
351
- // }
352
- });
353
-
354
- acc.push(obj);
355
- } else {
356
- innerCollectionNames.forEach((name: string) => {
357
- const innerObj = getNestedValue(obj, name);
358
- const ref = getNestedValue(acc[i], name);
359
-
360
- if (!ref) {
361
- assignToNestedObject(acc[i], name, innerObj ? [innerObj] : []);
362
- } else if (innerObj && !ref.find((o: any) => o.id === innerObj.id)) {
363
- assignToNestedObject(acc[i], name, ref.concat(innerObj));
364
- }
365
-
366
- // Old version, but this doesn't support merged array collections
367
- // const innerObj = obj[name];
368
- // if (!acc[i][name]) {
369
- // acc[i][name] = innerObj ? [innerObj] : [];
370
- // } else if (innerObj && !acc[i][name].find((o: any) => o.id === innerObj.id)) {
371
- // acc[i][name].push(obj[name]);
372
- // }
373
- });
374
- }
375
-
376
- return acc;
377
- }, []);
378
- }
379
-
380
- /**
381
- * Check if Object is array-like, then convert to plain Object.
382
- * NOTE: This happens a lot when using JS Map()
383
- * NOTE: This assumes that the keys are ordered numbers
384
- * NOTE: This function always clones the object.
385
- */
386
-
387
- export function cloneArrayLike(obj: any) {
388
- if (
389
- !Array.isArray(obj) &&
390
- Object.keys(obj).every((key, i) => key === i.toString())
391
- ) {
392
- return Object.values(obj);
393
- }
394
- return { ...obj };
395
- }
396
-
397
- /**
398
- * Check if Object is iterable
399
- */
400
-
401
- export function isIterable(obj: any) {
402
- return obj != null && typeof obj[Symbol.iterator] === 'function';
403
- }
404
-
405
- /**
406
- * Get the last key from a JS Map
407
- */
408
-
409
- export function getLastMapKey(map: Map<any, any>) {
410
- if (!map || map.size === 0) {
411
- return undefined;
412
- }
413
- return Array.from(map.keys()).pop();
414
- }
415
-
416
- /**
417
- * Get the first key from a JS Map
418
- */
419
-
420
- export function getFirstMapKey(map: Map<any, any>) {
421
- if (!map || map.size === 0) {
422
- return undefined;
423
- }
424
- return Array.from(map.keys()).shift();
425
- }