@jsb188/app 1.1.9 → 1.1.11
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 +54 -45
- package/src/constants/agent.ts +58 -25
- package/src/constants/app.ts +18 -14
- package/src/constants/billing.ts +92 -92
- package/src/constants/emoji.ts +9144 -8936
- package/src/constants/other.ts +1 -5
- package/src/constants/user.ts +16 -25
- package/src/constants/wsActions.ts +35 -0
- package/src/i18n/account.ts +129 -107
- package/src/i18n/agent.ts +63 -43
- package/src/i18n/agentDoc.ts +110 -0
- package/src/i18n/app.ts +101 -91
- package/src/i18n/auth.ts +119 -102
- package/src/i18n/billing.ts +73 -78
- package/src/i18n/campaign.ts +217 -0
- package/src/i18n/country.ts +248 -248
- package/src/i18n/datetime.ts +26 -26
- package/src/i18n/error.ts +428 -182
- package/src/i18n/field_docs.ts +28 -0
- package/src/i18n/form.ts +464 -344
- package/src/i18n/index.ts +25 -18
- package/src/i18n/log.ts +53 -213
- package/src/i18n/memory.ts +39 -0
- package/src/i18n/message.ts +3 -4
- package/src/i18n/note.ts +17 -0
- package/src/i18n/org.ts +115 -109
- package/src/i18n/sheet.ts +376 -4
- package/src/i18n/workflow.ts +70 -23
- package/src/main.ts +66 -62
- package/src/platform.ts +25 -24
- package/src/types/ai.d.ts +33 -23
- package/src/types/app.d.ts +95 -37
- package/src/types/auth.d.ts +66 -40
- package/src/types/console.d.ts +3 -0
- package/src/types/form.d.ts +65 -61
- package/src/types/other.d.ts +6 -6
- package/src/types.d.ts +12 -14
- package/src/utils/account.ts +64 -58
- package/src/utils/api.ts +280 -77
- package/src/utils/authSession.ts +24 -0
- package/src/utils/billing.ts +110 -103
- package/src/utils/color.ts +202 -0
- package/src/utils/cron.ts +49 -18
- package/src/utils/datetime.ts +255 -103
- package/src/utils/emoji.ts +107 -84
- package/src/utils/expression.ts +867 -0
- package/src/utils/interval.ts +80 -0
- package/src/utils/logic.ts +209 -36
- package/src/utils/managedSession.ts +34 -0
- package/src/utils/managedSessionBff.test.ts +60 -0
- package/src/utils/managedSessionBff.ts +117 -0
- package/src/utils/number.ts +60 -32
- package/src/utils/object.ts +198 -30
- package/src/utils/promise.ts +27 -0
- package/src/utils/queryReset.ts +179 -0
- package/src/utils/recurringTask.ts +60 -0
- package/src/utils/schema.ts +293 -0
- package/src/utils/string.test.ts +220 -208
- package/src/utils/string.ts +471 -438
- package/src/utils/timeZone.ts +309 -851
- package/src/utils/url_client.ts +73 -69
- package/tsconfig.json +10 -10
- package/src/i18n/product.ts +0 -76
package/src/utils/string.test.ts
CHANGED
|
@@ -2,280 +2,292 @@ import { beforeAll, describe, expect, it } from 'vitest';
|
|
|
2
2
|
|
|
3
3
|
import { configI18n } from '../main.ts';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
addIndefiniteArticle,
|
|
6
|
+
buildSingleText,
|
|
7
|
+
camelCaseToDash,
|
|
8
|
+
cn,
|
|
9
|
+
convertToInternationalPhone,
|
|
10
|
+
escapeCSVValue,
|
|
11
|
+
formatPhoneNumber,
|
|
12
|
+
formatReferenceNumber,
|
|
13
|
+
getAlphanumeric,
|
|
14
|
+
getDisplayName,
|
|
15
|
+
getNthString,
|
|
16
|
+
getSearchNames,
|
|
17
|
+
guessFirstName,
|
|
18
|
+
isEmail,
|
|
19
|
+
isInvisibleString,
|
|
20
|
+
isPhone,
|
|
21
|
+
joinReadable,
|
|
22
|
+
makeAddressText,
|
|
23
|
+
passwordStrength,
|
|
24
|
+
regexFromText,
|
|
25
|
+
removeGeneratedTextGarbage,
|
|
26
|
+
shortenToParagraph,
|
|
27
|
+
shortenToSpace,
|
|
28
|
+
splitTextIntoChunks,
|
|
29
|
+
textWithBrackets,
|
|
30
|
+
truncateFileName,
|
|
31
|
+
ucFirst,
|
|
32
32
|
} from './string.ts';
|
|
33
33
|
|
|
34
34
|
beforeAll(() => {
|
|
35
|
-
|
|
35
|
+
configI18n();
|
|
36
36
|
});
|
|
37
37
|
|
|
38
38
|
describe('cn', () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
it('joins truthy class names with spaces', () => {
|
|
40
|
+
expect(cn('card', false, 'selected', undefined, null, '')).toBe(
|
|
41
|
+
'card selected',
|
|
42
|
+
);
|
|
43
|
+
});
|
|
42
44
|
});
|
|
43
45
|
|
|
44
46
|
describe('shortenToSpace', () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
it('shortens at the last available space before the limit', () => {
|
|
48
|
+
expect(shortenToSpace('alpha beta gamma', 12)).toBe('alpha beta...');
|
|
49
|
+
});
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
it('falls back to a hard cut when no spaces exist', () => {
|
|
52
|
+
expect(shortenToSpace('alphabetagamma', 5)).toBe('alpha...');
|
|
53
|
+
});
|
|
52
54
|
});
|
|
53
55
|
|
|
54
56
|
describe('guessFirstName', () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
it('drops leading articles and returns the first meaningful word', () => {
|
|
58
|
+
expect(guessFirstName('the quick brown fox')).toBe('quick');
|
|
59
|
+
});
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
it('keeps short names instead of stripping the full word as an article suffix', () => {
|
|
62
|
+
expect(guessFirstName('An Lee')).toBe('Lee');
|
|
63
|
+
});
|
|
62
64
|
});
|
|
63
65
|
|
|
64
66
|
describe('addIndefiniteArticle', () => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
it('handles silent-h and consonant-sounding vowel exceptions', () => {
|
|
68
|
+
expect(addIndefiniteArticle('honest answer')).toBe('an honest answer');
|
|
69
|
+
expect(addIndefiniteArticle('user')).toBe('a user');
|
|
70
|
+
});
|
|
69
71
|
});
|
|
70
72
|
|
|
71
73
|
describe('isEmail', () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
it('accepts trimmed valid emails and rejects malformed values', () => {
|
|
75
|
+
expect(isEmail(' hello@example.com ')).toBe(true);
|
|
76
|
+
expect(isEmail('hello@example')).toBe(false);
|
|
77
|
+
});
|
|
76
78
|
});
|
|
77
79
|
|
|
78
80
|
describe('convertToInternationalPhone and isPhone', () => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
it('normalizes North American and existing international numbers', () => {
|
|
82
|
+
expect(convertToInternationalPhone('(555) 123-4567')).toBe('+15551234567');
|
|
83
|
+
expect(convertToInternationalPhone('+44 20 1234 5678')).toBe(
|
|
84
|
+
'+442012345678',
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('rejects invalid phone-like input', () => {
|
|
89
|
+
expect(convertToInternationalPhone('05551234567')).toBeNull();
|
|
90
|
+
expect(convertToInternationalPhone('555-abc-1234')).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('supports optional conversion when validating phone numbers', () => {
|
|
94
|
+
expect(isPhone('5551234567')).toBe(true);
|
|
95
|
+
expect(isPhone('5551234567', true)).toBe(false);
|
|
96
|
+
expect(isPhone('+442012345678', true)).toBe(true);
|
|
97
|
+
});
|
|
94
98
|
});
|
|
95
99
|
|
|
96
100
|
describe('passwordStrength', () => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
101
|
+
it('reports rule-by-rule password strength details', () => {
|
|
102
|
+
expect(passwordStrength('Abcdef1!')).toEqual({
|
|
103
|
+
valid: true,
|
|
104
|
+
isLongEnough: true,
|
|
105
|
+
hasLowercase: true,
|
|
106
|
+
hasUppercase: true,
|
|
107
|
+
hasDigit: true,
|
|
108
|
+
hasSpecial: true,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
expect(passwordStrength('abcdefg')).toMatchObject({
|
|
112
|
+
valid: false,
|
|
113
|
+
isLongEnough: false,
|
|
114
|
+
hasLowercase: true,
|
|
115
|
+
hasUppercase: false,
|
|
116
|
+
hasDigit: false,
|
|
117
|
+
hasSpecial: false,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
116
120
|
});
|
|
117
121
|
|
|
118
122
|
describe('getAlphanumeric and getSearchNames', () => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
]);
|
|
130
|
-
});
|
|
123
|
+
it('removes punctuation while optionally preserving spaces', () => {
|
|
124
|
+
expect(getAlphanumeric('A-B_C!', false)).toBe('ABC');
|
|
125
|
+
expect(getAlphanumeric('A-B_C!', true)).toBe('ABC');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('splits mixed delimiters and keeps case-insensitive unique names', () => {
|
|
129
|
+
expect(
|
|
130
|
+
getSearchNames(['Alice, Bob and alice', 'Carol;\nBob', null]),
|
|
131
|
+
).toEqual(['Alice', 'Bob', 'Carol']);
|
|
132
|
+
});
|
|
131
133
|
});
|
|
132
134
|
|
|
133
135
|
describe('regexFromText', () => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
it('builds a case-insensitive regex from cleaned words', () => {
|
|
137
|
+
const regex = regexFromText('Hello, world!');
|
|
136
138
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
expect(regex).not.toBeNull();
|
|
140
|
+
expect('say hello there'.match(regex!)).toEqual(['hello']);
|
|
141
|
+
expect('WORLD tour'.match(regex!)).toEqual(['WORLD']);
|
|
142
|
+
});
|
|
141
143
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
it('returns null when no searchable words remain', () => {
|
|
145
|
+
expect(regexFromText('a !')).toBeNull();
|
|
146
|
+
});
|
|
145
147
|
});
|
|
146
148
|
|
|
147
149
|
describe('ucFirst and camelCaseToDash', () => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
it('formats capitalization and dash-separated names', () => {
|
|
151
|
+
expect(ucFirst('marketday')).toBe('Marketday');
|
|
152
|
+
expect(camelCaseToDash('camelCase2Value')).toBe('camel-case-2-value');
|
|
153
|
+
expect(camelCaseToDash('API')).toBe('api');
|
|
154
|
+
});
|
|
153
155
|
});
|
|
154
156
|
|
|
155
157
|
describe('shortenToParagraph', () => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
it('uses paragraph boundaries before falling back to word trimming', () => {
|
|
159
|
+
const text = 'First line\nSecond line\nThird line';
|
|
158
160
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
expect(shortenToParagraph(text, 18)).toBe('First line');
|
|
162
|
+
expect(shortenToParagraph('Alpha beta gamma', 10)).toBe('Alpha...');
|
|
163
|
+
});
|
|
162
164
|
});
|
|
163
165
|
|
|
164
166
|
describe('isInvisibleString', () => {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
it('detects strings made only from whitespace-like invisible characters', () => {
|
|
168
|
+
expect(isInvisibleString('ㅤ️⠀')).toBe(true);
|
|
169
|
+
expect(isInvisibleString(' visible ')).toBe(false);
|
|
170
|
+
});
|
|
169
171
|
});
|
|
170
172
|
|
|
171
173
|
describe('buildSingleText', () => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
174
|
+
it('supports feature maps, conditional lines, first-match groups, and blank line collapsing', () => {
|
|
175
|
+
expect(
|
|
176
|
+
buildSingleText(
|
|
177
|
+
[
|
|
178
|
+
'Header',
|
|
179
|
+
'',
|
|
180
|
+
'',
|
|
181
|
+
{ advanced: ['Advanced section'] },
|
|
182
|
+
[['beta', '!legacy'], ['Beta only']],
|
|
183
|
+
[
|
|
184
|
+
[['admin'], ['Admin choice']],
|
|
185
|
+
[['member'], [' Member choice']],
|
|
186
|
+
[['!member'], ['Fallback choice']],
|
|
187
|
+
],
|
|
188
|
+
'Footer',
|
|
189
|
+
],
|
|
190
|
+
'\n',
|
|
191
|
+
['advanced', 'beta', 'member'],
|
|
192
|
+
),
|
|
193
|
+
).toBe('Header\n\nAdvanced section\nBeta only\nMember choice\nFooter');
|
|
194
|
+
});
|
|
193
195
|
});
|
|
194
196
|
|
|
195
197
|
describe('joinReadable and textWithBrackets', () => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
it('joins human-readable lists and appends bracket text when present', () => {
|
|
199
|
+
expect(joinReadable(['Alpha', 'Beta', 'Gamma'])).toBe(
|
|
200
|
+
'Alpha, Beta and Gamma',
|
|
201
|
+
);
|
|
202
|
+
expect(textWithBrackets('Status', ['draft', 'internal'], ['[', ']'])).toBe(
|
|
203
|
+
'Status [draft internal]',
|
|
204
|
+
);
|
|
205
|
+
expect(textWithBrackets('', ['draft', 'internal'], ['[', ']'])).toBe(
|
|
206
|
+
'draft internal',
|
|
207
|
+
);
|
|
208
|
+
});
|
|
201
209
|
});
|
|
202
210
|
|
|
203
211
|
describe('removeGeneratedTextGarbage and escapeCSVValue', () => {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
212
|
+
it('normalizes generated whitespace and escapes CSV-sensitive values', () => {
|
|
213
|
+
expect(removeGeneratedTextGarbage('Hello\n\n world\tfrom\r\nAI')).toBe(
|
|
214
|
+
'Hello world from AI',
|
|
215
|
+
);
|
|
216
|
+
expect(escapeCSVValue('plain')).toBe('plain');
|
|
217
|
+
expect(escapeCSVValue('a,"b"\nc')).toBe('"a,""b""\nc"');
|
|
218
|
+
});
|
|
209
219
|
});
|
|
210
220
|
|
|
211
221
|
describe('truncateFileName', () => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
222
|
+
it('preserves extensions while truncating long file names', () => {
|
|
223
|
+
expect(truncateFileName('very-long-document-name.pdf', 12)).toBe(
|
|
224
|
+
'very-....pdf',
|
|
225
|
+
);
|
|
226
|
+
expect(truncateFileName('short.txt', 20)).toBe('short.txt');
|
|
227
|
+
});
|
|
216
228
|
});
|
|
217
229
|
|
|
218
230
|
describe('formatPhoneNumber', () => {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
231
|
+
it('formats trailing 10 digits into a readable North American phone number', () => {
|
|
232
|
+
expect(formatPhoneNumber('+15551234567')).toBe('+1 (555) 123-4567');
|
|
233
|
+
expect(formatPhoneNumber('5551234567')).toBe('(555) 123-4567');
|
|
234
|
+
expect(formatPhoneNumber('not-a-phone')).toBe('not-a-phone');
|
|
235
|
+
});
|
|
224
236
|
});
|
|
225
237
|
|
|
226
238
|
describe('splitTextIntoChunks', () => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
it('prefers nearby line breaks when splitting long text', () => {
|
|
240
|
+
expect(splitTextIntoChunks('12345\n67890\nabcde', 10, 5)).toEqual([
|
|
241
|
+
'12345',
|
|
242
|
+
'67890',
|
|
243
|
+
'abcde',
|
|
244
|
+
]);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('falls back to whitespace boundaries when no line break is nearby', () => {
|
|
248
|
+
expect(splitTextIntoChunks('alpha beta gamma delta', 12, 2)).toEqual([
|
|
249
|
+
'alpha beta',
|
|
250
|
+
'gamma delta',
|
|
251
|
+
]);
|
|
252
|
+
});
|
|
241
253
|
});
|
|
242
254
|
|
|
243
255
|
describe('formatReferenceNumber and getNthString', () => {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
256
|
+
it('formats numeric references and ordinal suffixes', () => {
|
|
257
|
+
expect(formatReferenceNumber('42')).toBe('#42');
|
|
258
|
+
expect(formatReferenceNumber('abc')).toBe('abc');
|
|
259
|
+
expect(getNthString(1)).toBe('1st');
|
|
260
|
+
expect(getNthString(2)).toBe('2nd');
|
|
261
|
+
expect(getNthString(3)).toBe('3rd');
|
|
262
|
+
expect(getNthString(11)).toBe('11th');
|
|
263
|
+
expect(getNthString(23)).toBe('23rd');
|
|
264
|
+
});
|
|
253
265
|
});
|
|
254
266
|
|
|
255
267
|
describe('makeAddressText and getDisplayName', () => {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
268
|
+
it('formats addresses in each supported display mode', () => {
|
|
269
|
+
const address = {
|
|
270
|
+
line1: '1 Main St',
|
|
271
|
+
line2: 'Suite 2',
|
|
272
|
+
city: 'Toronto',
|
|
273
|
+
state: 'ON',
|
|
274
|
+
postalCode: 'A1A 1A1',
|
|
275
|
+
country: 'CA',
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
expect(makeAddressText(address, 'REGION_ONLY')).toBe('Toronto, ON, CA');
|
|
279
|
+
expect(makeAddressText(address, 'SINGLE_LINE', true)).toBe(
|
|
280
|
+
'1 Main St, Suite 2, Toronto, ON, A1A 1A1, Canada',
|
|
281
|
+
);
|
|
282
|
+
expect(makeAddressText(address)).toBe(
|
|
283
|
+
'1 Main St\nSuite 2\nToronto, ON A1A 1A1\nCA',
|
|
284
|
+
);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('builds a full name and short display name together', () => {
|
|
288
|
+
expect(getDisplayName('John', 'Smith')).toEqual({
|
|
289
|
+
fullName: 'John Smith',
|
|
290
|
+
displayName: 'John',
|
|
291
|
+
});
|
|
292
|
+
});
|
|
281
293
|
});
|