@jsb188/app 1.1.12 → 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 +11 -3
- package/src/constants/agent.ts +17 -7
- package/src/constants/app.ts +26 -0
- package/src/constants/wsActions.ts +0 -6
- package/src/i18n/agent.ts +65 -78
- package/src/i18n/agentToolBusiness.ts +149 -5
- package/src/i18n/agentToolGrid.ts +0 -16
- package/src/i18n/agent_note.ts +7 -6
- package/src/i18n/auth.ts +0 -3
- package/src/i18n/c.ts +58 -12
- package/src/i18n/campaign.ts +81 -830
- package/src/i18n/editor.ts +3 -5
- package/src/i18n/email_outreach_editor.ts +526 -0
- package/src/i18n/error.ts +174 -85
- package/src/i18n/field_doc_programs.ts +2 -3
- package/src/i18n/field_docs.ts +1 -0
- package/src/i18n/form.ts +12 -0
- package/src/i18n/index.ts +5 -1
- package/src/i18n/log.ts +2 -1
- package/src/i18n/memory.ts +2 -3
- package/src/i18n/message.ts +1 -0
- package/src/i18n/org.ts +4 -1
- package/src/i18n/schedule.ts +46 -122
- package/src/i18n/sheet.ts +20 -33
- package/src/i18n/workflow.ts +66 -4
- package/src/types/ai.d.ts +0 -4
- package/src/types/app.d.ts +22 -59
- package/src/types/auth.d.ts +1 -1
- package/src/utils/api.ts +14 -10
- package/src/utils/color.ts +18 -0
- package/src/utils/object.ts +41 -128
- package/src/utils/queryReset.ts +16 -54
- package/src/utils/string.ts +7 -0
- package/src/utils/url_client.ts +46 -15
- package/src/utils/expression.test.ts +0 -793
- package/src/utils/managedSessionBff.test.ts +0 -60
- package/src/utils/string.test.ts +0 -278
- package/tsconfig.json +0 -12
package/src/utils/color.ts
CHANGED
|
@@ -89,6 +89,24 @@ export function getValidColor(
|
|
|
89
89
|
return COLORS[(colorIndexHash >>> 0) % COLORS.length] as ColorEnum;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Return one hex color in the six-digit form a native color input accepts, expanding #rgb, or the fallback.
|
|
94
|
+
*/
|
|
95
|
+
export function getSixDigitHexColor(
|
|
96
|
+
value: string | null | undefined,
|
|
97
|
+
fallback: string,
|
|
98
|
+
): string {
|
|
99
|
+
const hex = String(value || '')
|
|
100
|
+
.trim()
|
|
101
|
+
.toLowerCase();
|
|
102
|
+
if (/^#[0-9a-f]{6}$/.test(hex)) {
|
|
103
|
+
return hex;
|
|
104
|
+
}
|
|
105
|
+
return /^#[0-9a-f]{3}$/.test(hex)
|
|
106
|
+
? `#${hex[1]}${hex[1]}${hex[2]}${hex[2]}${hex[3]}${hex[3]}`
|
|
107
|
+
: fallback;
|
|
108
|
+
}
|
|
109
|
+
|
|
92
110
|
const RGB_COLOR_REGEX = /^rgba?\(([^)]+)\)$/i;
|
|
93
111
|
const HEX_COLOR_VALUE_REGEX = /^#[0-9a-f]{6}$/i;
|
|
94
112
|
const HEX_COLOR_DRAFT_VALUE_REGEX = /^#[0-9a-f]{0,6}$/i;
|
package/src/utils/object.ts
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* Filter array and return only unique values
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
export function uniq(
|
|
6
|
-
arr: Array<any>,
|
|
7
|
-
fn?: (value: any, index: number, self: Array<any>) => boolean,
|
|
8
|
-
) {
|
|
5
|
+
export function uniq(arr: Array<any>, fn?: (value: any, index: number, self: Array<any>) => boolean) {
|
|
9
6
|
return arr.filter((value, index, self) => {
|
|
10
7
|
return self.indexOf(value) === index && (!fn || fn(value, index, self));
|
|
11
8
|
});
|
|
@@ -32,18 +29,10 @@ export function uniq(
|
|
|
32
29
|
* Remove undefined (and/or null) values from an object
|
|
33
30
|
*/
|
|
34
31
|
|
|
35
|
-
export function removeUndefined<T>(
|
|
36
|
-
obj: T,
|
|
37
|
-
removeNull?: boolean,
|
|
38
|
-
removeFalsy?: boolean,
|
|
39
|
-
): T {
|
|
32
|
+
export function removeUndefined<T>(obj: T, removeNull?: boolean, removeFalsy?: boolean): T {
|
|
40
33
|
for (const key in obj) {
|
|
41
34
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
42
|
-
if (
|
|
43
|
-
obj[key] === undefined ||
|
|
44
|
-
(removeNull && obj[key] === null) ||
|
|
45
|
-
(removeFalsy && !obj[key])
|
|
46
|
-
) {
|
|
35
|
+
if (obj[key] === undefined || (removeNull && obj[key] === null) || (removeFalsy && !obj[key])) {
|
|
47
36
|
delete obj[key];
|
|
48
37
|
} else if (obj[key] && typeof obj[key] === 'object') {
|
|
49
38
|
removeUndefined(obj[key], removeNull, removeFalsy);
|
|
@@ -163,11 +152,7 @@ export function normalizeArrayLikeValue<T = any>(value: unknown): T[] | null {
|
|
|
163
152
|
}
|
|
164
153
|
}
|
|
165
154
|
|
|
166
|
-
if (
|
|
167
|
-
arrayValue &&
|
|
168
|
-
typeof arrayValue === 'object' &&
|
|
169
|
-
!Array.isArray(arrayValue)
|
|
170
|
-
) {
|
|
155
|
+
if (arrayValue && typeof arrayValue === 'object' && !Array.isArray(arrayValue)) {
|
|
171
156
|
arrayValue = mapArrayLikeObjects(arrayValue);
|
|
172
157
|
}
|
|
173
158
|
|
|
@@ -179,16 +164,9 @@ export function normalizeArrayLikeValue<T = any>(value: unknown): T[] | null {
|
|
|
179
164
|
* conversion is the default; callers must opt into lossy number conversion.
|
|
180
165
|
*/
|
|
181
166
|
|
|
182
|
-
export function stringifyJSON(
|
|
183
|
-
obj: any,
|
|
184
|
-
preserveBigIntPrecision: boolean = true,
|
|
185
|
-
): string {
|
|
167
|
+
export function stringifyJSON(obj: any, preserveBigIntPrecision: boolean = true): string {
|
|
186
168
|
return JSON.stringify(obj, (_key, value) =>
|
|
187
|
-
typeof value === 'bigint'
|
|
188
|
-
? preserveBigIntPrecision
|
|
189
|
-
? value.toString()
|
|
190
|
-
: Number(value)
|
|
191
|
-
: value,
|
|
169
|
+
typeof value === 'bigint' ? (preserveBigIntPrecision ? value.toString() : Number(value)) : value,
|
|
192
170
|
);
|
|
193
171
|
}
|
|
194
172
|
|
|
@@ -222,22 +200,24 @@ export function stableJSONText(value: unknown): string {
|
|
|
222
200
|
}
|
|
223
201
|
|
|
224
202
|
/**
|
|
225
|
-
* Merge
|
|
203
|
+
* Merge own object properties while excluding prototype-related keys at every merged level.
|
|
226
204
|
*/
|
|
227
205
|
|
|
228
206
|
export function mergeNestedObjects(obj1: any, obj2: any) {
|
|
229
|
-
if (!obj1) {
|
|
230
|
-
return { ...obj2 };
|
|
231
|
-
}
|
|
232
|
-
|
|
233
207
|
const newObj = { ...obj1 };
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
208
|
+
delete newObj.__proto__;
|
|
209
|
+
delete newObj.constructor;
|
|
210
|
+
delete newObj.prototype;
|
|
211
|
+
|
|
212
|
+
for (const key of Object.keys(obj2 ?? {})) {
|
|
213
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (typeof obj2[key] === 'object' && obj2[key] !== null) {
|
|
217
|
+
const previousValue = obj1 && Object.prototype.hasOwnProperty.call(obj1, key) ? obj1[key] : undefined;
|
|
218
|
+
newObj[key] = mergeNestedObjects(previousValue, obj2[key]);
|
|
219
|
+
} else {
|
|
220
|
+
newObj[key] = obj2[key];
|
|
241
221
|
}
|
|
242
222
|
}
|
|
243
223
|
|
|
@@ -248,19 +228,11 @@ export function mergeNestedObjects(obj1: any, obj2: any) {
|
|
|
248
228
|
* Check if objects are equal
|
|
249
229
|
*/
|
|
250
230
|
|
|
251
|
-
export function areObjectsEqual(
|
|
252
|
-
obj1: any,
|
|
253
|
-
obj2: any,
|
|
254
|
-
isNested: boolean = false,
|
|
255
|
-
) {
|
|
231
|
+
export function areObjectsEqual(obj1: any, obj2: any, isNested: boolean = false) {
|
|
256
232
|
if (isNested) {
|
|
257
233
|
return JSON.stringify(obj1) === JSON.stringify(obj2);
|
|
258
234
|
} else if (obj1 && obj2) {
|
|
259
|
-
return Object.keys(obj1).every(
|
|
260
|
-
(key: string) =>
|
|
261
|
-
Object.prototype.hasOwnProperty.call(obj2, key) &&
|
|
262
|
-
obj1[key] === obj2[key],
|
|
263
|
-
);
|
|
235
|
+
return Object.keys(obj1).every((key: string) => Object.prototype.hasOwnProperty.call(obj2, key) && obj1[key] === obj2[key]);
|
|
264
236
|
}
|
|
265
237
|
return obj1 === obj2;
|
|
266
238
|
}
|
|
@@ -269,11 +241,7 @@ export function areObjectsEqual(
|
|
|
269
241
|
* Order an array of objects by a key
|
|
270
242
|
*/
|
|
271
243
|
|
|
272
|
-
export function orderBy(
|
|
273
|
-
arr: Array<any>,
|
|
274
|
-
key: ((obj: any) => any) | string,
|
|
275
|
-
order: 'asc' | 'desc' = 'asc',
|
|
276
|
-
) {
|
|
244
|
+
export function orderBy(arr: Array<any>, key: ((obj: any) => any) | string, order: 'asc' | 'desc' = 'asc') {
|
|
277
245
|
const compareFn = (a: any, b: any) => {
|
|
278
246
|
const valueA = typeof key === 'function' ? key(a) : a[key];
|
|
279
247
|
const valueB = typeof key === 'function' ? key(b) : b[key];
|
|
@@ -340,11 +308,7 @@ export function randomItem(arr: Array<any>) {
|
|
|
340
308
|
* Rearrange an array left or right
|
|
341
309
|
*/
|
|
342
310
|
|
|
343
|
-
export function rearrangeArray(
|
|
344
|
-
arr: Array<any>,
|
|
345
|
-
loop: number = 1,
|
|
346
|
-
shiftRight?: boolean,
|
|
347
|
-
) {
|
|
311
|
+
export function rearrangeArray(arr: Array<any>, loop: number = 1, shiftRight?: boolean) {
|
|
348
312
|
if (shiftRight) {
|
|
349
313
|
for (let i = 0; i < loop; i++) {
|
|
350
314
|
arr.unshift(arr.pop());
|
|
@@ -369,10 +333,7 @@ export function get(object: any, path: string) {
|
|
|
369
333
|
* NOTE: Use this after Redis.hgetall()
|
|
370
334
|
*/
|
|
371
335
|
|
|
372
|
-
export function hgetZipObject(
|
|
373
|
-
arr: Array<string>,
|
|
374
|
-
mapperFn?: (value: string, index: number) => any,
|
|
375
|
-
) {
|
|
336
|
+
export function hgetZipObject(arr: Array<string>, mapperFn?: (value: string, index: number) => any) {
|
|
376
337
|
const obj: Record<string, any> = {};
|
|
377
338
|
for (let i = 0; i < arr.length; i += 2) {
|
|
378
339
|
if (mapperFn) {
|
|
@@ -401,10 +362,7 @@ export function zipObject(keys: Array<string>, values: Array<any>) {
|
|
|
401
362
|
* NOTE: Use this for best NodeJS and browser compatibility
|
|
402
363
|
*/
|
|
403
364
|
|
|
404
|
-
export function findLastIndex(
|
|
405
|
-
arr: Array<any>,
|
|
406
|
-
fn: (value: any, index: number, array: any[]) => boolean,
|
|
407
|
-
) {
|
|
365
|
+
export function findLastIndex(arr: Array<any>, fn: (value: any, index: number, array: any[]) => boolean) {
|
|
408
366
|
if (typeof arr.findLastIndex === 'function') {
|
|
409
367
|
return arr.findLastIndex(fn);
|
|
410
368
|
}
|
|
@@ -433,9 +391,7 @@ export function intersection(arr1: unknown, arr2: unknown) {
|
|
|
433
391
|
*/
|
|
434
392
|
|
|
435
393
|
export function toggleArrayValue<T>(arr: Array<T>, value: T): Array<T> {
|
|
436
|
-
return arr.includes(value)
|
|
437
|
-
? arr.filter((currentValue) => currentValue !== value)
|
|
438
|
-
: [...arr, value];
|
|
394
|
+
return arr.includes(value) ? arr.filter((currentValue) => currentValue !== value) : [...arr, value];
|
|
439
395
|
}
|
|
440
396
|
|
|
441
397
|
/**
|
|
@@ -480,10 +436,7 @@ export function groupCollections(
|
|
|
480
436
|
}
|
|
481
437
|
|
|
482
438
|
for (const key in obj) {
|
|
483
|
-
if (
|
|
484
|
-
!Object.prototype.hasOwnProperty.call(obj, key) ||
|
|
485
|
-
key.startsWith('__')
|
|
486
|
-
) {
|
|
439
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key) || key.startsWith('__')) {
|
|
487
440
|
continue;
|
|
488
441
|
}
|
|
489
442
|
|
|
@@ -499,11 +452,7 @@ export function groupCollections(
|
|
|
499
452
|
* Build a stable key for dedupe checks.
|
|
500
453
|
*/
|
|
501
454
|
|
|
502
|
-
function makeMergeKey(
|
|
503
|
-
obj: any,
|
|
504
|
-
pkFn?: (obj: any) => string,
|
|
505
|
-
pkName?: string,
|
|
506
|
-
): string | number | undefined {
|
|
455
|
+
function makeMergeKey(obj: any, pkFn?: (obj: any) => string, pkName?: string): string | number | undefined {
|
|
507
456
|
if (!obj) {
|
|
508
457
|
return undefined;
|
|
509
458
|
}
|
|
@@ -615,17 +564,11 @@ export function groupCollections(
|
|
|
615
564
|
}
|
|
616
565
|
return (
|
|
617
566
|
(o.id && o.id === innerObj.id) ||
|
|
618
|
-
(!o.id &&
|
|
619
|
-
Object.entries(o).flat().join('|') ===
|
|
620
|
-
Object.entries(innerObj).flat().join('|'))
|
|
567
|
+
(!o.id && Object.entries(o).flat().join('|') === Object.entries(innerObj).flat().join('|'))
|
|
621
568
|
);
|
|
622
569
|
})
|
|
623
570
|
) {
|
|
624
|
-
setObject(
|
|
625
|
-
acc[i],
|
|
626
|
-
name,
|
|
627
|
-
Array.isArray(ref) ? ref.concat(innerObj) : innerObj,
|
|
628
|
-
);
|
|
571
|
+
setObject(acc[i], name, Array.isArray(ref) ? ref.concat(innerObj) : innerObj);
|
|
629
572
|
}
|
|
630
573
|
|
|
631
574
|
// Old version, but this doesn't support merged array collections
|
|
@@ -658,15 +601,9 @@ export function groupCollections(
|
|
|
658
601
|
collections.forEach((obj) => {
|
|
659
602
|
const innerObj = getObject(obj, flatName);
|
|
660
603
|
const primaryKey = obj[primaryKeyName];
|
|
661
|
-
const i = groupedCollections.findIndex(
|
|
662
|
-
(o: any) => o[primaryKeyName] === primaryKey,
|
|
663
|
-
);
|
|
604
|
+
const i = groupedCollections.findIndex((o: any) => o[primaryKeyName] === primaryKey);
|
|
664
605
|
const innerParent = getObject(obj, beforeHash);
|
|
665
|
-
const innerParentId = makeMergeKey(
|
|
666
|
-
innerParent,
|
|
667
|
-
parentPKFn,
|
|
668
|
-
primaryKeyName,
|
|
669
|
-
);
|
|
606
|
+
const innerParentId = makeMergeKey(innerParent, parentPKFn, primaryKeyName);
|
|
670
607
|
|
|
671
608
|
if (!innerObj || !hasMeaningfulValue(innerObj)) {
|
|
672
609
|
return;
|
|
@@ -674,10 +611,7 @@ export function groupCollections(
|
|
|
674
611
|
|
|
675
612
|
if (innerParentId && i >= 0) {
|
|
676
613
|
const innerArr = getObject(groupedCollections[i], beforeHash) || [];
|
|
677
|
-
const j = innerArr.findIndex(
|
|
678
|
-
(o: any) =>
|
|
679
|
-
makeMergeKey(o, parentPKFn, primaryKeyName) === innerParentId,
|
|
680
|
-
);
|
|
614
|
+
const j = innerArr.findIndex((o: any) => makeMergeKey(o, parentPKFn, primaryKeyName) === innerParentId);
|
|
681
615
|
|
|
682
616
|
if (j >= 0) {
|
|
683
617
|
const currentValue = innerArr[j][afterHash];
|
|
@@ -687,17 +621,10 @@ export function groupCollections(
|
|
|
687
621
|
|
|
688
622
|
let newValue;
|
|
689
623
|
if (currentValueIsArray) {
|
|
690
|
-
if (
|
|
691
|
-
!currentValue.find(
|
|
692
|
-
(o) => makeMergeKey(o, childPKFn) === nextInnerObjKey,
|
|
693
|
-
)
|
|
694
|
-
) {
|
|
624
|
+
if (!currentValue.find((o) => makeMergeKey(o, childPKFn) === nextInnerObjKey)) {
|
|
695
625
|
newValue = currentValue.concat(innerObj);
|
|
696
626
|
}
|
|
697
|
-
} else if (
|
|
698
|
-
currentValue &&
|
|
699
|
-
makeMergeKey(currentValue, childPKFn) !== nextInnerObjKey
|
|
700
|
-
) {
|
|
627
|
+
} else if (currentValue && makeMergeKey(currentValue, childPKFn) !== nextInnerObjKey) {
|
|
701
628
|
newValue = [currentValue].concat(innerObj);
|
|
702
629
|
} else if (!currentValue) {
|
|
703
630
|
newValue = [innerObj];
|
|
@@ -751,10 +678,7 @@ export function groupCollections(
|
|
|
751
678
|
*/
|
|
752
679
|
|
|
753
680
|
export function cloneArrayLike(obj: any) {
|
|
754
|
-
if (
|
|
755
|
-
!Array.isArray(obj) &&
|
|
756
|
-
Object.keys(obj).every((key, i) => key === i.toString())
|
|
757
|
-
) {
|
|
681
|
+
if (!Array.isArray(obj) && Object.keys(obj).every((key, i) => key === i.toString())) {
|
|
758
682
|
return Object.values(obj);
|
|
759
683
|
}
|
|
760
684
|
return { ...obj };
|
|
@@ -769,12 +693,7 @@ export function cloneArrayLike(obj: any) {
|
|
|
769
693
|
*/
|
|
770
694
|
|
|
771
695
|
export function mapArrayLikeObjects(obj: any) {
|
|
772
|
-
if (
|
|
773
|
-
!Array.isArray(obj) &&
|
|
774
|
-
obj !== null &&
|
|
775
|
-
typeof obj === 'object' &&
|
|
776
|
-
Object.keys(obj).every((key, i) => key === i.toString())
|
|
777
|
-
) {
|
|
696
|
+
if (!Array.isArray(obj) && obj !== null && typeof obj === 'object' && Object.keys(obj).every((key, i) => key === i.toString())) {
|
|
778
697
|
return Object.values(obj);
|
|
779
698
|
}
|
|
780
699
|
return obj;
|
|
@@ -848,9 +767,7 @@ export function setObject(obj: any, path: string, value: any): any {
|
|
|
848
767
|
return obj;
|
|
849
768
|
}
|
|
850
769
|
const keys = path.split('.');
|
|
851
|
-
if (
|
|
852
|
-
keys.some((key) => ['__proto__', 'constructor', 'prototype'].includes(key))
|
|
853
|
-
) {
|
|
770
|
+
if (keys.some((key) => ['__proto__', 'constructor', 'prototype'].includes(key))) {
|
|
854
771
|
return obj;
|
|
855
772
|
}
|
|
856
773
|
const lastKey = keys.pop();
|
|
@@ -865,9 +782,7 @@ export function setObject(obj: any, path: string, value: any): any {
|
|
|
865
782
|
if (typeof nestedObj === 'object' && nestedObj !== null) {
|
|
866
783
|
nestedObj[lastKey] = value;
|
|
867
784
|
} else {
|
|
868
|
-
console.warn(
|
|
869
|
-
`(!1) Cannot assign value to ${lastKey} because its reference is not an object.`,
|
|
870
|
-
);
|
|
785
|
+
console.warn(`(!1) Cannot assign value to ${lastKey} because its reference is not an object.`);
|
|
871
786
|
}
|
|
872
787
|
}
|
|
873
788
|
|
|
@@ -900,9 +815,7 @@ export function hasObject(obj: any, namespace: string): boolean {
|
|
|
900
815
|
* @returns - Returns a new object with keys sorted alphabetically
|
|
901
816
|
*/
|
|
902
817
|
|
|
903
|
-
export function sortObjectByKeys(
|
|
904
|
-
obj: Record<string, any>,
|
|
905
|
-
): Record<string, any> {
|
|
818
|
+
export function sortObjectByKeys(obj: Record<string, any>): Record<string, any> {
|
|
906
819
|
if (!obj || typeof obj !== 'object') {
|
|
907
820
|
return obj;
|
|
908
821
|
}
|
package/src/utils/queryReset.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Structured query-reset targets. A target names
|
|
3
|
-
* optionally, the serialized variable values a cached
|
|
4
|
-
* reset by it without building or evaluating a regex.
|
|
2
|
+
* Structured query-reset targets for the client's own cache. A target names
|
|
3
|
+
* one GraphQL query and, optionally, the serialized variable values a cached
|
|
4
|
+
* page must carry to be reset by it without building or evaluating a regex.
|
|
5
5
|
*
|
|
6
6
|
* Cache keys are '#queryName:' + makeGraphQLVariablesKey(variables). Request
|
|
7
|
-
* identity preserves exact JSON values. Reset targets
|
|
8
|
-
* case-
|
|
7
|
+
* identity preserves exact JSON values. Reset targets match variables
|
|
8
|
+
* case-insensitively and also understand legacy cache keys.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
export interface QueryResetTarget {
|
|
@@ -15,7 +15,7 @@ export interface QueryResetTarget {
|
|
|
15
15
|
|
|
16
16
|
/*
|
|
17
17
|
* Build one structured query-reset target. Variable names and values are
|
|
18
|
-
* lowercased
|
|
18
|
+
* lowercased, because targets match cache keys case-insensitively.
|
|
19
19
|
*
|
|
20
20
|
* Callers decide which constraints apply: omit a key to widen the target (no
|
|
21
21
|
* constraint on that variable), and pass an empty value only if the intent is
|
|
@@ -45,14 +45,6 @@ export function makeQueryResetTarget(
|
|
|
45
45
|
: { name };
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/*
|
|
49
|
-
* Build unconstrained structured reset targets for a list of GraphQL queries.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
export function makeQueryResetTargets(...names: string[]) {
|
|
53
|
-
return names.map((name) => makeQueryResetTarget(name));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
48
|
/*
|
|
57
49
|
* Parse serialized variables while preserving dollar signs inside JSON filter values.
|
|
58
50
|
*/
|
|
@@ -170,7 +162,7 @@ export function queryCacheKeyMatchesResetTarget(
|
|
|
170
162
|
|
|
171
163
|
const variablesKey = queryCacheKey.slice(queryPrefix.length);
|
|
172
164
|
// New keys preserve exact GraphQL values. Reset targets intentionally keep
|
|
173
|
-
//
|
|
165
|
+
// matching them case-insensitively, like legacy keys.
|
|
174
166
|
if (variablesKey.startsWith('@')) {
|
|
175
167
|
try {
|
|
176
168
|
const variables = JSON.parse(variablesKey.slice(1));
|
|
@@ -178,11 +170,17 @@ export function queryCacheKeyMatchesResetTarget(
|
|
|
178
170
|
let value = variables;
|
|
179
171
|
for (const part of path.split('.')) {
|
|
180
172
|
if (!value || typeof value !== 'object') return false;
|
|
181
|
-
const key = Object.keys(value).find(
|
|
182
|
-
|
|
173
|
+
const key = Object.keys(value).find(
|
|
174
|
+
(key) => key.toLowerCase() === part.toLowerCase(),
|
|
175
|
+
);
|
|
176
|
+
if (!key || ['__proto__', 'constructor', 'prototype'].includes(key))
|
|
177
|
+
return false;
|
|
183
178
|
value = value[key];
|
|
184
179
|
}
|
|
185
|
-
return
|
|
180
|
+
return (
|
|
181
|
+
value != null &&
|
|
182
|
+
String(value).toLowerCase() === expected.toLowerCase()
|
|
183
|
+
);
|
|
186
184
|
});
|
|
187
185
|
} catch {
|
|
188
186
|
return false;
|
|
@@ -209,42 +207,6 @@ export function queryCacheKeyMatchesAnyResetTarget(
|
|
|
209
207
|
);
|
|
210
208
|
}
|
|
211
209
|
|
|
212
|
-
/*
|
|
213
|
-
* Remove targets that duplicate an earlier one by value. Structured targets are
|
|
214
|
-
* plain objects, so they need stable value identities for deduplication.
|
|
215
|
-
*/
|
|
216
|
-
|
|
217
|
-
export function dedupeQueryResetTargets(targets: QueryResetTarget[]) {
|
|
218
|
-
const seenIds = new Set<string>();
|
|
219
|
-
|
|
220
|
-
return targets.filter((target) => {
|
|
221
|
-
const targetId = getQueryResetTargetId(target);
|
|
222
|
-
if (seenIds.has(targetId)) {
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
seenIds.add(targetId);
|
|
227
|
-
return true;
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/*
|
|
232
|
-
* Build the structured reset field for websocket payload builders that measure
|
|
233
|
-
* their complete packet before publishing.
|
|
234
|
-
*/
|
|
235
|
-
|
|
236
|
-
export function buildResetQueryPayloadFields(
|
|
237
|
-
targets?: QueryResetTarget[] | null,
|
|
238
|
-
) {
|
|
239
|
-
if (!targets?.length) {
|
|
240
|
-
return { resetQueries: undefined };
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
resetQueries: targets,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
|
|
248
210
|
/*
|
|
249
211
|
* Return a stable identity string for one target. Used as the query observer
|
|
250
212
|
* event name where a single string is required; the '~' prefix keeps it from
|
package/src/utils/string.ts
CHANGED
|
@@ -615,6 +615,13 @@ export function getNthString(num: number): string {
|
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
+
/*
|
|
619
|
+
* Check whether an optional address contains details beyond the country selection.
|
|
620
|
+
*/
|
|
621
|
+
export function hasAddressDetails(address: Partial<AddressObj>) {
|
|
622
|
+
return [address.line1, address.line2, address.city, address.state, address.postalCode].some((value) => value?.trim());
|
|
623
|
+
}
|
|
624
|
+
|
|
618
625
|
/**
|
|
619
626
|
* Make address text
|
|
620
627
|
* @param address - Address object
|
package/src/utils/url_client.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { getENVVariable } from '../main.ts';
|
|
2
|
-
|
|
3
1
|
type LinkType = 'USER' | 'KAJI' | 'DATASET' | 'VOICE' | 'FEED' | 'ROOM' | 'THREAD' | 'OTHER';
|
|
4
2
|
|
|
5
3
|
/*
|
|
@@ -42,9 +40,25 @@ export function makeUploadsUrl(urlPath?: string | null, size?: 'small' | 'medium
|
|
|
42
40
|
|
|
43
41
|
const searchPath = searchParams.length ? `?${searchParams.join('&')}` : '';
|
|
44
42
|
|
|
43
|
+
// This is suppose to point to prod or dev assets server url.
|
|
44
|
+
// But for testing and easier-dev purposes, we're going to always point to prod.
|
|
45
45
|
return 'https://assets.chiefhappiness.co/marketday/' + urlPath + searchPath;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/*
|
|
49
|
+
* Resolve a private file on the production assets server.
|
|
50
|
+
*/
|
|
51
|
+
export function makeSecureAssetsUrl(path?: string | null): string {
|
|
52
|
+
// This is suppose to point to prod or dev assets server url.
|
|
53
|
+
// But for testing and easier-dev purposes, we're going to always point to prod.
|
|
54
|
+
const base = 'https://assets.chiefhappiness.co/';
|
|
55
|
+
if (!path || !URL.canParse(path, base)) return '';
|
|
56
|
+
const url = new URL(path, base);
|
|
57
|
+
if (!/^https?:$/.test(url.protocol) || url.origin !== new URL(base).origin || url.username || url.password) return '';
|
|
58
|
+
if (!/^\/files\/\d+\/\d+\/\d+$/.test(url.pathname)) return '';
|
|
59
|
+
return url.href;
|
|
60
|
+
}
|
|
61
|
+
|
|
48
62
|
/**
|
|
49
63
|
* Local object URLs
|
|
50
64
|
*/
|
|
@@ -87,18 +101,6 @@ export function releaseObjectUrl(url: string) {
|
|
|
87
101
|
);
|
|
88
102
|
}
|
|
89
103
|
|
|
90
|
-
/**
|
|
91
|
-
* Make a campaign-template preview asset URL, preserving older non-campaign paths.
|
|
92
|
-
*/
|
|
93
|
-
export function makePreviewAssetUrl(uri?: string | null): string {
|
|
94
|
-
const assetsUrl = String(getENVVariable('ASSETS_URL') || 'https://assets.chiefhappiness.co').replace(/\/+$/, '');
|
|
95
|
-
const campaignPath = uri?.match(/^(\d+)\/previews\/(campaigns|campaign-instances)\/([^/]+)\.webp$/);
|
|
96
|
-
if (campaignPath) {
|
|
97
|
-
return `${assetsUrl}/previews/${campaignPath[2]}/${campaignPath[1]}/${campaignPath[3]}.webp`;
|
|
98
|
-
}
|
|
99
|
-
return uri ? `${assetsUrl}/preview/${uri}` : '';
|
|
100
|
-
}
|
|
101
|
-
|
|
102
104
|
/**
|
|
103
105
|
* Make url for static assets
|
|
104
106
|
*/
|
|
@@ -184,7 +186,8 @@ export function locationSearchToObject(searchParams?: string) {
|
|
|
184
186
|
*/
|
|
185
187
|
|
|
186
188
|
export function isChatPage() {
|
|
187
|
-
|
|
189
|
+
// Servers have no location; the cast keeps this type-safe without the DOM library
|
|
190
|
+
const pathname = (globalThis as { location?: { pathname?: string } }).location?.pathname?.toLowerCase();
|
|
188
191
|
if (pathname) {
|
|
189
192
|
return /^\/(?:chat|dm)\//i.test(pathname);
|
|
190
193
|
}
|
|
@@ -204,3 +207,31 @@ export function isPathnameUnderRoutes(pathname: string, routes: string[]) {
|
|
|
204
207
|
return prefix === '' || path === prefix || path.startsWith(prefix + '/');
|
|
205
208
|
});
|
|
206
209
|
}
|
|
210
|
+
|
|
211
|
+
/*
|
|
212
|
+
* Accept explicit web/contact links and relative destinations without permitting browser scheme normalization bypasses.
|
|
213
|
+
*/
|
|
214
|
+
export function getSafeLinkDestination(destination: string): string | null {
|
|
215
|
+
if (!destination || /[\s\u0000-\u001f\u007f-\u009f\\]/u.test(destination) || /&(?:#(?:x[\da-f]+|\d+)|[a-z]+);/i.test(destination)) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const scheme = /^([a-z][a-z0-9+.-]*):/i.exec(destination)?.[1]?.toLowerCase();
|
|
220
|
+
if (scheme) {
|
|
221
|
+
if (!['http', 'https', 'mailto', 'tel'].includes(scheme)) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
if (scheme === 'http' || scheme === 'https') {
|
|
225
|
+
try {
|
|
226
|
+
const url = new URL(destination);
|
|
227
|
+
return url.hostname ? destination : null;
|
|
228
|
+
} catch {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return destination.length > scheme.length + 1 ? destination : null;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// A colon before a path/query/fragment boundary is never a relative path.
|
|
236
|
+
return /^[^/?#]*:/.test(destination) ? null : destination;
|
|
237
|
+
}
|