@jsb188/app 1.1.11 → 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.
- package/package.json +7 -4
- package/src/constants/agent.ts +39 -62
- package/src/constants/app.ts +17 -0
- package/src/constants/wsActions.ts +7 -15
- package/src/i18n/account.ts +1 -1
- package/src/i18n/agent.ts +326 -88
- package/src/i18n/agentToolBusiness.ts +196 -0
- package/src/i18n/agentToolGrid.ts +137 -0
- package/src/i18n/agentToolWorkflow.ts +101 -0
- package/src/i18n/agent_note.ts +109 -0
- package/src/i18n/app.ts +23 -17
- package/src/i18n/auth.ts +28 -30
- package/src/i18n/billing.ts +3 -85
- package/src/i18n/c.ts +907 -0
- package/src/i18n/campaign.ts +842 -140
- package/src/i18n/datetime.ts +6 -0
- package/src/i18n/editor.ts +58 -0
- package/src/i18n/error.ts +307 -168
- package/src/i18n/field_doc_editor.ts +21 -0
- package/src/i18n/field_doc_programs.ts +52 -0
- package/src/i18n/field_docs.ts +170 -8
- package/src/i18n/index.ts +21 -5
- package/src/i18n/log.ts +232 -38
- package/src/i18n/memory.ts +18 -4
- package/src/i18n/note.ts +5 -3
- package/src/i18n/org.ts +93 -44
- package/src/i18n/schedule.ts +209 -0
- package/src/i18n/sheet.ts +102 -145
- package/src/i18n/sheet_formula.ts +165 -0
- package/src/i18n/workflow.ts +48 -9
- package/src/main.ts +2 -2
- package/src/platform.ts +89 -49
- package/src/types/ai.d.ts +19 -0
- package/src/types/app.d.ts +50 -57
- package/src/types/other.d.ts +8 -1
- package/src/utils/api.ts +46 -0
- package/src/utils/clientIP.ts +213 -0
- package/src/utils/color.ts +77 -0
- package/src/utils/csv.ts +19 -0
- package/src/utils/datetime.ts +207 -31
- package/src/utils/deferredSave.ts +89 -0
- package/src/utils/email.ts +50 -0
- package/src/utils/expression.helpers.ts +470 -0
- package/src/utils/expression.test.ts +793 -0
- package/src/utils/expression.ts +1633 -239
- package/src/utils/language.ts +9 -0
- package/src/utils/logic.ts +9 -162
- package/src/utils/number.ts +30 -11
- package/src/utils/object.ts +29 -0
- package/src/utils/promise.ts +78 -7
- package/src/utils/queryReset.ts +101 -14
- package/src/utils/string.test.ts +24 -39
- package/src/utils/string.ts +73 -143
- package/src/utils/url_client.ts +83 -14
- package/src/constants/billing.ts +0 -146
- package/src/i18n/agentDoc.ts +0 -110
- package/src/i18n/form.ts +0 -496
- package/src/types/form.d.ts +0 -101
- package/src/utils/billing.ts +0 -141
package/src/utils/string.ts
CHANGED
|
@@ -9,15 +9,19 @@ export function cn(...classNames: (string | boolean | undefined | null)[]) {
|
|
|
9
9
|
return classNames.filter(Boolean).join(' ');
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Escape user-controlled text before inserting it into an HTML string.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export function escapeHTML(value: string): string {
|
|
17
|
+
return value.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`);
|
|
18
|
+
}
|
|
19
|
+
|
|
12
20
|
/**
|
|
13
21
|
* Shorten text to space with length limit
|
|
14
22
|
*/
|
|
15
23
|
|
|
16
|
-
export function shortenToSpace(
|
|
17
|
-
str: string,
|
|
18
|
-
len: number = 100,
|
|
19
|
-
ellipsis: string = '...',
|
|
20
|
-
): string {
|
|
24
|
+
export function shortenToSpace(str: string, len: number = 100, ellipsis: string = '...'): string {
|
|
21
25
|
if (!str || str.length < len) {
|
|
22
26
|
return str;
|
|
23
27
|
}
|
|
@@ -37,10 +41,7 @@ export function shortenToSpace(
|
|
|
37
41
|
*/
|
|
38
42
|
|
|
39
43
|
export function guessFirstName(str: string, len: number = 40): string {
|
|
40
|
-
let shortened =
|
|
41
|
-
str
|
|
42
|
-
?.replace(/^(a|an|the|da|de|that|there|this|than|then)\b/i, '')
|
|
43
|
-
?.trim() || '';
|
|
44
|
+
let shortened = str?.replace(/^(a|an|the|da|de|that|there|this|than|then)\b/i, '')?.trim() || '';
|
|
44
45
|
const spaceIx = shortened.indexOf(' ');
|
|
45
46
|
|
|
46
47
|
if (spaceIx >= 0) {
|
|
@@ -51,10 +52,7 @@ export function guessFirstName(str: string, len: number = 40): string {
|
|
|
51
52
|
shortened = shortened.substring(0, len);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
const articleReplacedEnd = shortened.replace(
|
|
55
|
-
/\b(a|an|the|da|de|that|there|this|than|then)$/i,
|
|
56
|
-
'',
|
|
57
|
-
);
|
|
55
|
+
const articleReplacedEnd = shortened.replace(/\b(a|an|the|da|de|that|there|this|than|then)$/i, '');
|
|
58
56
|
|
|
59
57
|
if (articleReplacedEnd.length < 5) {
|
|
60
58
|
return shortened.trim();
|
|
@@ -76,9 +74,7 @@ export function addIndefiniteArticle(word: string) {
|
|
|
76
74
|
} else if (/^(honest|honor|hour|heir)\b/.test(raw)) {
|
|
77
75
|
// Common silent-h words use "an"
|
|
78
76
|
article = 'an';
|
|
79
|
-
} else if (
|
|
80
|
-
/^(uni([^nmd]|$)|use|user|euro|one|once|ubiquit|ufo|ukulele)\b/.test(raw)
|
|
81
|
-
) {
|
|
77
|
+
} else if (/^(uni([^nmd]|$)|use|user|euro|one|once|ubiquit|ufo|ukulele)\b/.test(raw)) {
|
|
82
78
|
// Common "you"/"w" sound starts use "a"
|
|
83
79
|
article = 'a';
|
|
84
80
|
} else {
|
|
@@ -129,10 +125,7 @@ export function convertToInternationalPhone(str: string) {
|
|
|
129
125
|
* NOTE: This will convert phone-like strings to international format
|
|
130
126
|
*/
|
|
131
127
|
|
|
132
|
-
export function isPhone(
|
|
133
|
-
str: string,
|
|
134
|
-
doNotConvertInternational: boolean = false,
|
|
135
|
-
) {
|
|
128
|
+
export function isPhone(str: string, doNotConvertInternational: boolean = false) {
|
|
136
129
|
let phoneNumber: string | null = str.trim();
|
|
137
130
|
if (!doNotConvertInternational) {
|
|
138
131
|
phoneNumber = convertToInternationalPhone(phoneNumber);
|
|
@@ -158,8 +151,7 @@ export function passwordStrength(str: string, minLength: number = 8) {
|
|
|
158
151
|
const hasUppercase = /[A-Z]/.test(str);
|
|
159
152
|
const hasDigit = /\d/.test(str);
|
|
160
153
|
const hasSpecial = /\W/.test(str);
|
|
161
|
-
const valid =
|
|
162
|
-
isLongEnough && hasLowercase && hasUppercase && hasDigit && hasSpecial;
|
|
154
|
+
const valid = isLongEnough && hasLowercase && hasUppercase && hasDigit && hasSpecial;
|
|
163
155
|
// return /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\W)[a-zA-Z\d\W]{8,}$/.test(str);
|
|
164
156
|
return {
|
|
165
157
|
valid,
|
|
@@ -191,9 +183,7 @@ export function getAlphanumeric(str: string, space: boolean = false) {
|
|
|
191
183
|
* Build normalized unique list of names from raw search inputs
|
|
192
184
|
*/
|
|
193
185
|
|
|
194
|
-
export function getSearchNames(
|
|
195
|
-
namesList: (string | null | undefined)[] = [],
|
|
196
|
-
): string[] {
|
|
186
|
+
export function getSearchNames(namesList: (string | null | undefined)[] = []): string[] {
|
|
197
187
|
const parsedNames = (namesList || [])
|
|
198
188
|
.flatMap((s) => (s || '').split(/\s*(?:,|;|\n|\band\b)\s*/i))
|
|
199
189
|
.map((s) => s.trim())
|
|
@@ -225,10 +215,7 @@ export function regexFromText(text: string) {
|
|
|
225
215
|
return null;
|
|
226
216
|
}
|
|
227
217
|
|
|
228
|
-
return new RegExp(
|
|
229
|
-
'\\b' + (words.length === 1 ? words[0] : '(?:' + words.join('|') + ')'),
|
|
230
|
-
'gi',
|
|
231
|
-
);
|
|
218
|
+
return new RegExp('\\b' + (words.length === 1 ? words[0] : '(?:' + words.join('|') + ')'), 'gi');
|
|
232
219
|
}
|
|
233
220
|
|
|
234
221
|
/**
|
|
@@ -259,11 +246,7 @@ export function camelCaseToDash(str: string) {
|
|
|
259
246
|
* Shorten text to a paragraph length
|
|
260
247
|
*/
|
|
261
248
|
|
|
262
|
-
export function shortenToParagraph(
|
|
263
|
-
str: string,
|
|
264
|
-
len: number,
|
|
265
|
-
replaceDoubleLineBreaks?: boolean,
|
|
266
|
-
) {
|
|
249
|
+
export function shortenToParagraph(str: string, len: number, replaceDoubleLineBreaks?: boolean) {
|
|
267
250
|
let trimedToParagraph = str || '';
|
|
268
251
|
if (replaceDoubleLineBreaks) {
|
|
269
252
|
trimedToParagraph = trimedToParagraph.replace(/\n\s*\n/g, '\n');
|
|
@@ -317,10 +300,7 @@ export function isInvisibleString(str: string) {
|
|
|
317
300
|
*/
|
|
318
301
|
|
|
319
302
|
type AnyLineItem = string | undefined | false | null;
|
|
320
|
-
type BuildSingleTextConditionalLine = [
|
|
321
|
-
string[],
|
|
322
|
-
BuildSingleTextLine | BuildSingleTextLine[],
|
|
323
|
-
];
|
|
303
|
+
type BuildSingleTextConditionalLine = [string[], BuildSingleTextLine | BuildSingleTextLine[]];
|
|
324
304
|
type BuildSingleTextConditionalLineGroup = BuildSingleTextConditionalLine[];
|
|
325
305
|
interface BuildSingleTextFeatureMap {
|
|
326
306
|
[key: string]: BuildSingleTextLine | BuildSingleTextLine[];
|
|
@@ -330,21 +310,15 @@ export type BuildSingleTextLine =
|
|
|
330
310
|
| AnyLineItem
|
|
331
311
|
| BuildSingleTextFeatureMap
|
|
332
312
|
| BuildSingleTextConditionalLine
|
|
333
|
-
| BuildSingleTextConditionalLineGroup
|
|
313
|
+
| BuildSingleTextConditionalLineGroup
|
|
314
|
+
| BuildSingleTextLine[];
|
|
334
315
|
|
|
335
316
|
/*
|
|
336
317
|
* Check whether a buildSingleText line uses the all-features conditional tuple syntax.
|
|
337
318
|
*/
|
|
338
319
|
|
|
339
|
-
function isBuildSingleTextConditionalLine(
|
|
340
|
-
line
|
|
341
|
-
): line is BuildSingleTextConditionalLine {
|
|
342
|
-
return (
|
|
343
|
-
Array.isArray(line) &&
|
|
344
|
-
line.length === 2 &&
|
|
345
|
-
Array.isArray(line[0]) &&
|
|
346
|
-
line[0].every((feature) => typeof feature === 'string')
|
|
347
|
-
);
|
|
320
|
+
function isBuildSingleTextConditionalLine(line: BuildSingleTextLine | BuildSingleTextLine[]): line is BuildSingleTextConditionalLine {
|
|
321
|
+
return Array.isArray(line) && line.length === 2 && Array.isArray(line[0]) && line[0].every((feature) => typeof feature === 'string');
|
|
348
322
|
}
|
|
349
323
|
|
|
350
324
|
/*
|
|
@@ -354,21 +328,14 @@ function isBuildSingleTextConditionalLine(
|
|
|
354
328
|
function isBuildSingleTextConditionalLineGroup(
|
|
355
329
|
line: BuildSingleTextLine | BuildSingleTextLine[],
|
|
356
330
|
): line is BuildSingleTextConditionalLineGroup {
|
|
357
|
-
return (
|
|
358
|
-
Array.isArray(line) &&
|
|
359
|
-
line.length > 0 &&
|
|
360
|
-
line.every((lineItem) => isBuildSingleTextConditionalLine(lineItem))
|
|
361
|
-
);
|
|
331
|
+
return Array.isArray(line) && line.length > 0 && line.every((lineItem) => isBuildSingleTextConditionalLine(lineItem));
|
|
362
332
|
}
|
|
363
333
|
|
|
364
334
|
/*
|
|
365
335
|
* Check whether a buildSingleText requirement matches the enabled features.
|
|
366
336
|
*/
|
|
367
337
|
|
|
368
|
-
function doesBuildSingleTextRequirementMatch(
|
|
369
|
-
requirement: string,
|
|
370
|
-
features: string[],
|
|
371
|
-
) {
|
|
338
|
+
function doesBuildSingleTextRequirementMatch(requirement: string, features: string[]) {
|
|
372
339
|
const isNegatedRequirement = requirement.startsWith('!');
|
|
373
340
|
const feature = isNegatedRequirement ? requirement.slice(1) : requirement;
|
|
374
341
|
|
|
@@ -384,13 +351,8 @@ function doesBuildSingleTextRequirementMatch(
|
|
|
384
351
|
* Check whether a buildSingleText conditional line matches the enabled features.
|
|
385
352
|
*/
|
|
386
353
|
|
|
387
|
-
function doesBuildSingleTextConditionalLineMatch(
|
|
388
|
-
conditionalLine
|
|
389
|
-
features: string[],
|
|
390
|
-
) {
|
|
391
|
-
return conditionalLine[0].every((feature) =>
|
|
392
|
-
doesBuildSingleTextRequirementMatch(feature, features),
|
|
393
|
-
);
|
|
354
|
+
function doesBuildSingleTextConditionalLineMatch(conditionalLine: BuildSingleTextConditionalLine, features: string[]) {
|
|
355
|
+
return conditionalLine[0].every((feature) => doesBuildSingleTextRequirementMatch(feature, features));
|
|
394
356
|
}
|
|
395
357
|
|
|
396
358
|
/*
|
|
@@ -403,22 +365,16 @@ function getBuildSingleTextConditionalText(
|
|
|
403
365
|
features: string[],
|
|
404
366
|
) {
|
|
405
367
|
return buildSingleText(
|
|
406
|
-
Array.isArray(conditionalLines) &&
|
|
407
|
-
!isBuildSingleTextConditionalLine(conditionalLines)
|
|
408
|
-
? conditionalLines
|
|
409
|
-
: [conditionalLines],
|
|
368
|
+
Array.isArray(conditionalLines) && !isBuildSingleTextConditionalLine(conditionalLines) ? conditionalLines : [conditionalLines],
|
|
410
369
|
delemiter,
|
|
411
370
|
features,
|
|
412
371
|
);
|
|
413
372
|
}
|
|
414
373
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
delemiter: string = '\n',
|
|
418
|
-
features: string[] = [],
|
|
419
|
-
) {
|
|
374
|
+
/* Build prompt text from nested sections, feature conditions, and explicit blank lines. */
|
|
375
|
+
export function buildSingleText(lines: BuildSingleTextLine[], delemiter: string = '\n', features: string[] = []) {
|
|
420
376
|
return lines
|
|
421
|
-
.reduce((acc, line_) => {
|
|
377
|
+
.reduce<string[]>((acc, line_) => {
|
|
422
378
|
const line = line_ || '';
|
|
423
379
|
if (isBuildSingleTextConditionalLineGroup(line)) {
|
|
424
380
|
const matchedConditionalLine = line.find((conditionalLine) =>
|
|
@@ -429,11 +385,7 @@ export function buildSingleText(
|
|
|
429
385
|
return acc;
|
|
430
386
|
}
|
|
431
387
|
|
|
432
|
-
const conditionalText = getBuildSingleTextConditionalText(
|
|
433
|
-
matchedConditionalLine[1],
|
|
434
|
-
delemiter,
|
|
435
|
-
features,
|
|
436
|
-
);
|
|
388
|
+
const conditionalText = getBuildSingleTextConditionalText(matchedConditionalLine[1], delemiter, features);
|
|
437
389
|
|
|
438
390
|
if (conditionalText || acc[acc.length - 1] !== '') {
|
|
439
391
|
acc.push(conditionalText);
|
|
@@ -446,11 +398,7 @@ export function buildSingleText(
|
|
|
446
398
|
const [, conditionalLines] = line;
|
|
447
399
|
|
|
448
400
|
if (doesBuildSingleTextConditionalLineMatch(line, features)) {
|
|
449
|
-
const conditionalText = getBuildSingleTextConditionalText(
|
|
450
|
-
conditionalLines,
|
|
451
|
-
delemiter,
|
|
452
|
-
features,
|
|
453
|
-
);
|
|
401
|
+
const conditionalText = getBuildSingleTextConditionalText(conditionalLines, delemiter, features);
|
|
454
402
|
|
|
455
403
|
if (conditionalText || acc[acc.length - 1] !== '') {
|
|
456
404
|
acc.push(conditionalText);
|
|
@@ -459,15 +407,18 @@ export function buildSingleText(
|
|
|
459
407
|
|
|
460
408
|
return acc;
|
|
461
409
|
}
|
|
410
|
+
if (Array.isArray(line)) {
|
|
411
|
+
const nestedText = buildSingleText(line, delemiter, features);
|
|
412
|
+
if (nestedText || acc[acc.length - 1] !== '') {
|
|
413
|
+
acc.push(nestedText);
|
|
414
|
+
}
|
|
415
|
+
return acc;
|
|
416
|
+
}
|
|
462
417
|
if (line && typeof line === 'object') {
|
|
463
418
|
for (const key in line) {
|
|
464
419
|
const lineItem = line[key];
|
|
465
420
|
if (features.includes(key)) {
|
|
466
|
-
const nextLines =
|
|
467
|
-
Array.isArray(lineItem) &&
|
|
468
|
-
!isBuildSingleTextConditionalLine(lineItem)
|
|
469
|
-
? lineItem
|
|
470
|
-
: [lineItem];
|
|
421
|
+
const nextLines = Array.isArray(lineItem) && !isBuildSingleTextConditionalLine(lineItem) ? lineItem : [lineItem];
|
|
471
422
|
acc.push(buildSingleText(nextLines, delemiter, features));
|
|
472
423
|
}
|
|
473
424
|
}
|
|
@@ -477,7 +428,7 @@ export function buildSingleText(
|
|
|
477
428
|
acc.push(line);
|
|
478
429
|
}
|
|
479
430
|
return acc;
|
|
480
|
-
}, []
|
|
431
|
+
}, [])
|
|
481
432
|
.join(delemiter)
|
|
482
433
|
.trim()
|
|
483
434
|
.replace(/^[ \t]+(?=[A-Za-z0-9])/gm, '');
|
|
@@ -492,11 +443,7 @@ export function buildSingleText(
|
|
|
492
443
|
* @returns Joined string with special last separator
|
|
493
444
|
*/
|
|
494
445
|
|
|
495
|
-
export function joinReadable(
|
|
496
|
-
texts: (string | null | undefined)[],
|
|
497
|
-
separator: string = ', ',
|
|
498
|
-
lastSeparator: string = ' and ',
|
|
499
|
-
): string {
|
|
446
|
+
export function joinReadable(texts: (string | null | undefined)[], separator: string = ', ', lastSeparator: string = ' and '): string {
|
|
500
447
|
const lastIx = texts.length - 1;
|
|
501
448
|
return texts.filter(Boolean).reduce<string>((acc, text, i) => {
|
|
502
449
|
return acc + (!acc ? '' : i === lastIx ? lastSeparator : separator) + text;
|
|
@@ -512,11 +459,7 @@ export function joinReadable(
|
|
|
512
459
|
* @returns Formatted text with optional brackets
|
|
513
460
|
*/
|
|
514
461
|
|
|
515
|
-
export function textWithBrackets(
|
|
516
|
-
text: string,
|
|
517
|
-
bracketsText?: string | string[],
|
|
518
|
-
brackets: [string, string] = ['(', ')'],
|
|
519
|
-
) {
|
|
462
|
+
export function textWithBrackets(text: string, bracketsText?: string | string[], brackets: [string, string] = ['(', ')']) {
|
|
520
463
|
let bText;
|
|
521
464
|
if (Array.isArray(bracketsText)) {
|
|
522
465
|
bText = bracketsText.filter(Boolean).join(' ').trim();
|
|
@@ -554,7 +497,7 @@ export function removeGeneratedTextGarbage(str: string) {
|
|
|
554
497
|
*/
|
|
555
498
|
|
|
556
499
|
export function escapeCSVValue(value: string): string {
|
|
557
|
-
if (/[",\n]/.test(value)) {
|
|
500
|
+
if (/[",\r\n]/.test(value)) {
|
|
558
501
|
return `"${value.replace(/"/g, '""')}"`;
|
|
559
502
|
}
|
|
560
503
|
return value;
|
|
@@ -584,18 +527,10 @@ export function formatPhoneNumber(phone?: string | null) {
|
|
|
584
527
|
const match = phone?.match(/(\d{3})(\d{3})(\d{4})$/);
|
|
585
528
|
if (match) {
|
|
586
529
|
const [, area, first, second] = match;
|
|
587
|
-
const countryCode = phone
|
|
588
|
-
|
|
589
|
-
.trim();
|
|
590
|
-
const normalizedCountryCode = countryCode
|
|
591
|
-
? countryCode.startsWith('+')
|
|
592
|
-
? countryCode
|
|
593
|
-
: `+${countryCode}`
|
|
594
|
-
: '';
|
|
530
|
+
const countryCode = phone!.substring(0, phone!.length - area.length - first.length - second.length).trim();
|
|
531
|
+
const normalizedCountryCode = countryCode ? (countryCode.startsWith('+') ? countryCode : `+${countryCode}`) : '';
|
|
595
532
|
// NOTE: This does not account for non North American (+1) phone numbers
|
|
596
|
-
return `${normalizedCountryCode}${
|
|
597
|
-
normalizedCountryCode ? ' ' : ''
|
|
598
|
-
}(${area}) ${first}-${second}`;
|
|
533
|
+
return `${normalizedCountryCode}${normalizedCountryCode ? ' ' : ''}(${area}) ${first}-${second}`;
|
|
599
534
|
}
|
|
600
535
|
|
|
601
536
|
return phone;
|
|
@@ -609,11 +544,7 @@ export function formatPhoneNumber(phone?: string | null) {
|
|
|
609
544
|
* @returns An array of text chunks.
|
|
610
545
|
*/
|
|
611
546
|
|
|
612
|
-
export function splitTextIntoChunks(
|
|
613
|
-
text: string,
|
|
614
|
-
chunkSize: number,
|
|
615
|
-
linebreakDistance: number = 50,
|
|
616
|
-
): string[] {
|
|
547
|
+
export function splitTextIntoChunks(text: string, chunkSize: number, linebreakDistance: number = 50): string[] {
|
|
617
548
|
if (!text || chunkSize <= 0 || text.length < chunkSize) {
|
|
618
549
|
return [text || ''];
|
|
619
550
|
}
|
|
@@ -629,11 +560,7 @@ export function splitTextIntoChunks(
|
|
|
629
560
|
const beforeBreak = text.lastIndexOf('\n', end);
|
|
630
561
|
|
|
631
562
|
let chosenBreak = -1;
|
|
632
|
-
if (
|
|
633
|
-
beforeBreak !== -1 &&
|
|
634
|
-
end - beforeBreak <= linebreakDistance &&
|
|
635
|
-
beforeBreak > start
|
|
636
|
-
) {
|
|
563
|
+
if (beforeBreak !== -1 && end - beforeBreak <= linebreakDistance && beforeBreak > start) {
|
|
637
564
|
chosenBreak = beforeBreak + 1;
|
|
638
565
|
}
|
|
639
566
|
|
|
@@ -712,18 +639,9 @@ export function makeAddressText(
|
|
|
712
639
|
: address.country;
|
|
713
640
|
|
|
714
641
|
if (format === 'REGION_ONLY') {
|
|
715
|
-
return [address.city, address.state, countryName]
|
|
716
|
-
.filter(Boolean)
|
|
717
|
-
.join(delimiter);
|
|
642
|
+
return [address.city, address.state, countryName].filter(Boolean).join(delimiter);
|
|
718
643
|
} else if (format === 'SINGLE_LINE') {
|
|
719
|
-
return [
|
|
720
|
-
address.line1,
|
|
721
|
-
address.line2,
|
|
722
|
-
address.city,
|
|
723
|
-
address.state,
|
|
724
|
-
address.postalCode,
|
|
725
|
-
countryName,
|
|
726
|
-
]
|
|
644
|
+
return [address.line1, address.line2, address.city, address.state, address.postalCode, countryName]
|
|
727
645
|
.filter(Boolean)
|
|
728
646
|
.join(delimiter);
|
|
729
647
|
}
|
|
@@ -732,12 +650,7 @@ export function makeAddressText(
|
|
|
732
650
|
return [
|
|
733
651
|
address.line1,
|
|
734
652
|
address.line2,
|
|
735
|
-
[
|
|
736
|
-
[address.city, address.state].filter(Boolean).join(', '),
|
|
737
|
-
address.postalCode,
|
|
738
|
-
]
|
|
739
|
-
.filter(Boolean)
|
|
740
|
-
.join(' '),
|
|
653
|
+
[[address.city, address.state].filter(Boolean).join(', '), address.postalCode].filter(Boolean).join(' '),
|
|
741
654
|
countryName,
|
|
742
655
|
]
|
|
743
656
|
.filter(Boolean)
|
|
@@ -749,10 +662,7 @@ export function makeAddressText(
|
|
|
749
662
|
* @returns Formatted display name
|
|
750
663
|
*/
|
|
751
664
|
|
|
752
|
-
export function getDisplayName(
|
|
753
|
-
firstName?: string | null,
|
|
754
|
-
lastName?: string | null,
|
|
755
|
-
) {
|
|
665
|
+
export function getDisplayName(firstName?: string | null, lastName?: string | null) {
|
|
756
666
|
const fullName = buildSingleText([firstName, lastName], ' ');
|
|
757
667
|
const displayName = guessFirstName(fullName, 8) || '?';
|
|
758
668
|
|
|
@@ -777,3 +687,23 @@ export function hashStringFNV1a(value: string) {
|
|
|
777
687
|
|
|
778
688
|
return (hash >>> 0).toString(16).padStart(8, '0');
|
|
779
689
|
}
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Remove markdown from text, so you can send it to SMS
|
|
693
|
+
* @param text - Text to remove markdown from
|
|
694
|
+
* @returns - Text without markdown
|
|
695
|
+
*/
|
|
696
|
+
|
|
697
|
+
export function removeMarkdownForSMS(text: string) {
|
|
698
|
+
return (
|
|
699
|
+
text
|
|
700
|
+
// 4. Drop leading `#`‑style headings (handles up to ######).
|
|
701
|
+
.replace(/^[ \t]*#{1,6}[ \t]+/gm, '')
|
|
702
|
+
// 1. Bold: **text** (no line‑breaks inside)
|
|
703
|
+
.replace(/\*\*([^\n*]+?)\*\*/g, '$1')
|
|
704
|
+
// 2. Italic: *text* (single asterisks only, not part of **)
|
|
705
|
+
.replace(/(?<!\*)\*([^\n*]+?)\*(?!\*)/g, '$1')
|
|
706
|
+
// 3. Italic: _text_ (underscores)
|
|
707
|
+
.replace(/_([^\n_]+?)_/g, '$1')
|
|
708
|
+
);
|
|
709
|
+
}
|
package/src/utils/url_client.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { getENVVariable } from '../main.ts';
|
|
2
|
+
|
|
3
|
+
type LinkType = 'USER' | 'KAJI' | 'DATASET' | 'VOICE' | 'FEED' | 'ROOM' | 'THREAD' | 'OTHER';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Format a keyboard shortcut with the command modifier used by the current
|
|
7
|
+
* client platform.
|
|
8
|
+
*/
|
|
9
|
+
export function getClientShortcutText(key: string, shiftKey: boolean = false): string {
|
|
10
|
+
const platform = globalThis.navigator?.platform || globalThis.navigator?.userAgent || '';
|
|
11
|
+
return [/Mac|iPhone|iPod|iPad/i.test(platform) ? 'cmd' : 'ctrl', shiftKey ? 'shift' : null, key.toLowerCase()]
|
|
12
|
+
.filter(Boolean)
|
|
13
|
+
.join('+');
|
|
14
|
+
}
|
|
10
15
|
|
|
11
16
|
// links to consider for User cards
|
|
12
17
|
// instagram
|
|
@@ -22,11 +27,7 @@ type LinkType =
|
|
|
22
27
|
* Uploaded assets
|
|
23
28
|
*/
|
|
24
29
|
|
|
25
|
-
export function makeUploadsUrl(
|
|
26
|
-
urlPath?: string | null,
|
|
27
|
-
size?: 'small' | 'medium' | 'original',
|
|
28
|
-
download?: boolean,
|
|
29
|
-
): string {
|
|
30
|
+
export function makeUploadsUrl(urlPath?: string | null, size?: 'small' | 'medium' | 'original', download?: boolean): string {
|
|
30
31
|
if (!urlPath) {
|
|
31
32
|
return '';
|
|
32
33
|
}
|
|
@@ -44,6 +45,60 @@ export function makeUploadsUrl(
|
|
|
44
45
|
return 'https://assets.chiefhappiness.co/marketday/' + urlPath + searchPath;
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Local object URLs
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
// Hold counts and pending revocations of object URLs shared between components
|
|
53
|
+
const objectUrlHolds = new Map<string, number>();
|
|
54
|
+
const objectUrlRevokeTimers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* Add one hold on a local object URL (e.g. an image preview from
|
|
58
|
+
* URL.createObjectURL()) and cancel a revocation scheduled by a holder that
|
|
59
|
+
* just released it.
|
|
60
|
+
*/
|
|
61
|
+
export function retainObjectUrl(url: string) {
|
|
62
|
+
clearTimeout(objectUrlRevokeTimers.get(url));
|
|
63
|
+
objectUrlRevokeTimers.delete(url);
|
|
64
|
+
objectUrlHolds.set(url, (objectUrlHolds.get(url) || 0) + 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Release one hold on a local object URL and revoke it shortly after its last
|
|
69
|
+
* holder lets go, so a holder that unmounts in the same render as the one
|
|
70
|
+
* taking over (e.g. a page handing a preview to the next page) never breaks it.
|
|
71
|
+
*/
|
|
72
|
+
export function releaseObjectUrl(url: string) {
|
|
73
|
+
const holds = (objectUrlHolds.get(url) || 0) - 1;
|
|
74
|
+
if (holds > 0) {
|
|
75
|
+
objectUrlHolds.set(url, holds);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
objectUrlHolds.delete(url);
|
|
80
|
+
clearTimeout(objectUrlRevokeTimers.get(url));
|
|
81
|
+
objectUrlRevokeTimers.set(
|
|
82
|
+
url,
|
|
83
|
+
setTimeout(() => {
|
|
84
|
+
objectUrlRevokeTimers.delete(url);
|
|
85
|
+
URL.revokeObjectURL(url);
|
|
86
|
+
}, 1000),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
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
|
+
|
|
47
102
|
/**
|
|
48
103
|
* Make url for static assets
|
|
49
104
|
*/
|
|
@@ -135,3 +190,17 @@ export function isChatPage() {
|
|
|
135
190
|
}
|
|
136
191
|
return false;
|
|
137
192
|
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Check if a pathname falls under any of the given route prefixes.
|
|
196
|
+
* Matching is segment-aware: '/app/s' or '/app/s/' matches '/app/s' and '/app/s/12345', but not '/app/sheets'.
|
|
197
|
+
* Only the pathname is compared, so query strings and hashes never affect the result.
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
export function isPathnameUnderRoutes(pathname: string, routes: string[]) {
|
|
201
|
+
const [path] = pathname.split(/[?#]/);
|
|
202
|
+
return routes.some((route) => {
|
|
203
|
+
const prefix = route.replace(/\/+$/, '');
|
|
204
|
+
return prefix === '' || path === prefix || path.startsWith(prefix + '/');
|
|
205
|
+
});
|
|
206
|
+
}
|
package/src/constants/billing.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
export const PLATFORM_PRODUCT_ENUMS = [
|
|
2
|
-
// Subscriptions
|
|
3
|
-
'perks',
|
|
4
|
-
'kajiwoto_plus',
|
|
5
|
-
'kajiwoto_plus_yearly',
|
|
6
|
-
'kajiwoto_pro',
|
|
7
|
-
'kajiwoto_pro_yearly',
|
|
8
|
-
|
|
9
|
-
// These are for future proofing; don't use these until they're in the database
|
|
10
|
-
'big_planet_plus',
|
|
11
|
-
'big_planet_plus_yearly',
|
|
12
|
-
'big_planet_pro',
|
|
13
|
-
'big_planet_pro_yearly',
|
|
14
|
-
|
|
15
|
-
// Consumables
|
|
16
|
-
'coins_10',
|
|
17
|
-
'coins_20',
|
|
18
|
-
'coins_100',
|
|
19
|
-
|
|
20
|
-
// Expired
|
|
21
|
-
'kajiwoto_creator',
|
|
22
|
-
'creator_dataset_sub',
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
export const SUBSCRIPTION_CATALOG = [
|
|
26
|
-
// [groupName, stripeProductId, stripePriceId]
|
|
27
|
-
['PLUS', 'prod_H0WgTKq5qiK51Q', 'plan_H0WhZdwYcq9Fn7'],
|
|
28
|
-
['PRO', 'prod_H0WgTKq5qiK51Q', 'price_1MkLqjJI6Kvu2OvUPzFwwncH'],
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
export const SUBSCRIPTION_CATALOG_TEST = [
|
|
32
|
-
// [groupName, stripeProductId, stripePriceId]
|
|
33
|
-
['PLUS', 'prod_O2uOYfarTaRqJX', 'price_1QBox9JI6Kvu2OvUoy9vBmKL'],
|
|
34
|
-
['PRO', 'prod_O2uOYfarTaRqJX', 'price_1QBox9JI6Kvu2OvUQ86KgX5C'],
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
export const PRICE_ID_TO_PRODUCT = {
|
|
38
|
-
plan_H0WhZdwYcq9Fn7: {
|
|
39
|
-
name: 'kajiwoto_plus',
|
|
40
|
-
group: 'PLUS',
|
|
41
|
-
},
|
|
42
|
-
price_1HmqX5JI6Kvu2OvUM1edHUMw: {
|
|
43
|
-
name: 'kajiwoto_plus_yearly',
|
|
44
|
-
group: 'PLUS',
|
|
45
|
-
},
|
|
46
|
-
price_1MkLqjJI6Kvu2OvUPzFwwncH: {
|
|
47
|
-
name: 'kajiwoto_pro',
|
|
48
|
-
group: 'PRO',
|
|
49
|
-
},
|
|
50
|
-
price_1MkLrzJI6Kvu2OvUMPyWvKdt: {
|
|
51
|
-
name: 'kajiwoto_pro_yearly',
|
|
52
|
-
group: 'PRO',
|
|
53
|
-
},
|
|
54
|
-
price_1IOudjJI6Kvu2OvU6znCc2oZ: {
|
|
55
|
-
name: 'coins_10',
|
|
56
|
-
group: 'COINS',
|
|
57
|
-
},
|
|
58
|
-
price_1IOudjJI6Kvu2OvUnRFoUQUm: {
|
|
59
|
-
name: 'coins_20',
|
|
60
|
-
group: 'COINS',
|
|
61
|
-
},
|
|
62
|
-
price_1K3y6EJI6Kvu2OvUYUDJgMy6: {
|
|
63
|
-
name: 'coins_100',
|
|
64
|
-
group: 'COINS',
|
|
65
|
-
},
|
|
66
|
-
// price_HNzF3cC8hMxs0Q: 'kajiwoto_creator',
|
|
67
|
-
// plan_HIXtNYWIEx9eST: 'creator_dataset_sub',
|
|
68
|
-
} as {
|
|
69
|
-
[key: string]: {
|
|
70
|
-
name: string;
|
|
71
|
-
group: string;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const PRICE_ID_TO_PRODUCT_TEST = {
|
|
76
|
-
price_1QBox9JI6Kvu2OvUoy9vBmKL: {
|
|
77
|
-
name: 'kajiwoto_plus',
|
|
78
|
-
group: 'PLUS',
|
|
79
|
-
},
|
|
80
|
-
price_1QBox9JI6Kvu2OvU7bKCLUYq: {
|
|
81
|
-
name: 'kajiwoto_plus_yearly',
|
|
82
|
-
group: 'PLUS',
|
|
83
|
-
},
|
|
84
|
-
price_1QBox9JI6Kvu2OvUQ86KgX5C: {
|
|
85
|
-
name: 'kajiwoto_pro',
|
|
86
|
-
group: 'PRO',
|
|
87
|
-
},
|
|
88
|
-
price_1QBox9JI6Kvu2OvU8Fn4ftXb: {
|
|
89
|
-
name: 'kajiwoto_pro_yearly',
|
|
90
|
-
group: 'PRO',
|
|
91
|
-
},
|
|
92
|
-
price_1NGnmKJI6Kvu2OvUx3bykj0F: {
|
|
93
|
-
name: 'coins_10',
|
|
94
|
-
group: 'COINS',
|
|
95
|
-
},
|
|
96
|
-
price_1NGoBHJI6Kvu2OvUONbOujKG: {
|
|
97
|
-
name: 'coins_20',
|
|
98
|
-
group: 'COINS',
|
|
99
|
-
},
|
|
100
|
-
price_1NGoAjJI6Kvu2OvUSRWartW3: {
|
|
101
|
-
name: 'coins_100',
|
|
102
|
-
group: 'COINS',
|
|
103
|
-
},
|
|
104
|
-
// price_HNzJjKRMAhEakr: 'kajiwoto_creator',
|
|
105
|
-
// plan_HIYFVZvX8lLTol: 'creator_dataset_sub',
|
|
106
|
-
} as {
|
|
107
|
-
[key: string]: {
|
|
108
|
-
name: string;
|
|
109
|
-
group: string;
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// Products
|
|
114
|
-
// export const PRICES = {
|
|
115
|
-
// kajiwoto_plus: 7.99,
|
|
116
|
-
// kajiwoto_plus_yearly: 87.89,
|
|
117
|
-
// kajiwoto_pro: 29.99,
|
|
118
|
-
// kajiwoto_pro_yearly: 299.99,
|
|
119
|
-
// coins_10: 9.99,
|
|
120
|
-
// coins_20: 19.98,
|
|
121
|
-
// coins_100: 99.90,
|
|
122
|
-
|
|
123
|
-
// // Skin Prices
|
|
124
|
-
// SKIN_PRICE_1: 2.99,
|
|
125
|
-
// SKIN_PRICE_2: 4.99,
|
|
126
|
-
// SKIN_PRICE_3: 9.99,
|
|
127
|
-
// SKIN_PRICE_4: 19.99
|
|
128
|
-
// };
|
|
129
|
-
|
|
130
|
-
// export const SUBSCRIPTION_PRODUCTS = [
|
|
131
|
-
// 'kajiwoto_plus',
|
|
132
|
-
// 'kajiwoto_plus_yearly',
|
|
133
|
-
// 'kajiwoto_pro',
|
|
134
|
-
// 'kajiwoto_pro_yearly',
|
|
135
|
-
// 'kajiwoto_creator',
|
|
136
|
-
// 'kplus_test'
|
|
137
|
-
// ];
|
|
138
|
-
|
|
139
|
-
// export const HAS_PLUS_SUB_TYPES = [
|
|
140
|
-
// 'plus',
|
|
141
|
-
// 'pro'
|
|
142
|
-
// ];
|
|
143
|
-
|
|
144
|
-
// export const HAS_PRO_SUB_TYPES = [
|
|
145
|
-
// 'pro'
|
|
146
|
-
// ];
|