@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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SUPPORTED_LOG_LANGUAGES, type SupportedLogLanguage } from '../constants/app.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Resolve a supported log language to its canonical locale key without losing script subtags.
|
|
5
|
+
*/
|
|
6
|
+
export function normalizeLogLanguage(value: unknown): SupportedLogLanguage | null {
|
|
7
|
+
const normalized = typeof value === 'string' ? value.trim().toLowerCase() : '';
|
|
8
|
+
return SUPPORTED_LOG_LANGUAGES.find((language) => language.toLowerCase() === normalized) ?? null;
|
|
9
|
+
}
|
package/src/utils/logic.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d.ts';
|
|
2
|
-
import { isFutureCalDate, isValidCalDate } from './datetime.ts';
|
|
3
1
|
import { sortObjectByKeys, stringifyJSON } from './object.ts';
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -16,13 +14,6 @@ type DatabaseActionResult = {
|
|
|
16
14
|
const COMPACT_CACHE_KEY_SEGMENT_BYTE_LIMIT = 1800;
|
|
17
15
|
const UTF8_ENCODER = new TextEncoder();
|
|
18
16
|
|
|
19
|
-
export interface GetFiltersFromURLResult {
|
|
20
|
-
filter: Omit<Partial<FilterLogEntriesArgs>, 'operation'> | null;
|
|
21
|
-
sort: string | null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type FilterOptionURLMode = 'INDEXED' | 'KEYS';
|
|
25
|
-
|
|
26
17
|
/**
|
|
27
18
|
* Check if database document needs an update, insert, or do nothing based on the user API arguments
|
|
28
19
|
* NOTE: There is a copy paste of this function in @jsb188/react/utils/hooks.ts
|
|
@@ -176,159 +167,6 @@ export function createThrottledInvoke<T extends any[]>(
|
|
|
176
167
|
return { invoke, cancel };
|
|
177
168
|
}
|
|
178
169
|
|
|
179
|
-
/**
|
|
180
|
-
* Convert an indexed bit-string into a list of selected values.
|
|
181
|
-
*/
|
|
182
|
-
|
|
183
|
-
function getIndexedValues(value: string | null, options?: string[]) {
|
|
184
|
-
if (!value || !options?.length) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const selectedValues = options
|
|
189
|
-
.map((option, i) => {
|
|
190
|
-
return value.charAt(i) === '1' ? option : null;
|
|
191
|
-
})
|
|
192
|
-
.filter(Boolean) as string[];
|
|
193
|
-
|
|
194
|
-
return selectedValues.length ? selectedValues : null;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Convert a comma-separated filter value into validated stable option keys.
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
function getKeyValues(value: string | null, options?: string[]) {
|
|
202
|
-
if (!value || !options?.length) {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const optionSet = new Set(options);
|
|
207
|
-
const selectedValues = Array.from(
|
|
208
|
-
new Set(
|
|
209
|
-
value
|
|
210
|
-
.split(',')
|
|
211
|
-
.map((option) => option.trim())
|
|
212
|
-
.filter((option) => optionSet.has(option)),
|
|
213
|
-
),
|
|
214
|
-
).sort();
|
|
215
|
-
|
|
216
|
-
return selectedValues.length ? selectedValues : null;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Parse one filter search-param using either the legacy indexed encoding or
|
|
221
|
-
* stable literal registry keys.
|
|
222
|
-
*/
|
|
223
|
-
|
|
224
|
-
function getFilterOptionValues(
|
|
225
|
-
value: string | null,
|
|
226
|
-
options?: string[],
|
|
227
|
-
optionURLMode: FilterOptionURLMode = 'INDEXED',
|
|
228
|
-
) {
|
|
229
|
-
return optionURLMode === 'KEYS'
|
|
230
|
-
? getKeyValues(value, options)
|
|
231
|
-
: getIndexedValues(value, options);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Check whether a URL search-param value is a serialized generic ID.
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
export function isValidGenericIdSearchParam(
|
|
239
|
-
value?: string | number | bigint | null,
|
|
240
|
-
) {
|
|
241
|
-
if (!value) {
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const stringValue = String(value);
|
|
246
|
-
return stringValue !== '0' && /^\d+$/.test(stringValue);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Validate parsed URL filters using the same date and timezone rules as the logs filter schema.
|
|
251
|
-
*/
|
|
252
|
-
|
|
253
|
-
function parsedFilterIsValid(
|
|
254
|
-
filter: Omit<Partial<FilterLogEntriesArgs>, 'operation'>,
|
|
255
|
-
) {
|
|
256
|
-
if (!isValidGenericIdSearchParam(filter.siteId)) {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (filter.startDate) {
|
|
261
|
-
if (!isValidCalDate(filter.startDate)) {
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (filter.endDate && !isValidCalDate(filter.endDate)) {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (filter.endDate && !filter.startDate) {
|
|
271
|
-
return false;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Parse legacy indexed or registry-key filters and sort values from URL
|
|
279
|
-
* search params without including operation in the output.
|
|
280
|
-
*/
|
|
281
|
-
|
|
282
|
-
export function getFiltersFromURL(
|
|
283
|
-
searchQuery: string,
|
|
284
|
-
sortOptions?: string[],
|
|
285
|
-
types?: string[],
|
|
286
|
-
activities?: string[],
|
|
287
|
-
optionURLMode: FilterOptionURLMode = 'INDEXED',
|
|
288
|
-
): GetFiltersFromURLResult {
|
|
289
|
-
const urlParams = new URLSearchParams(searchQuery);
|
|
290
|
-
|
|
291
|
-
let startDate = urlParams.get('sd');
|
|
292
|
-
let endDate = urlParams.get('ed');
|
|
293
|
-
if (startDate && !endDate) {
|
|
294
|
-
endDate = startDate;
|
|
295
|
-
} else if (endDate && !startDate) {
|
|
296
|
-
startDate = endDate;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const filter: Omit<Partial<FilterLogEntriesArgs>, 'operation'> = {
|
|
300
|
-
siteId: urlParams.get('sid') || null,
|
|
301
|
-
types: getFilterOptionValues(
|
|
302
|
-
urlParams.get('t'),
|
|
303
|
-
types,
|
|
304
|
-
optionURLMode,
|
|
305
|
-
) as FilterLogEntriesArgs['types'],
|
|
306
|
-
activities: getFilterOptionValues(
|
|
307
|
-
urlParams.get('a'),
|
|
308
|
-
activities,
|
|
309
|
-
optionURLMode,
|
|
310
|
-
) as FilterLogEntriesArgs['activities'],
|
|
311
|
-
startDate,
|
|
312
|
-
endDate,
|
|
313
|
-
query: urlParams.get('q') || '',
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
const sortIndex = urlParams.get('s');
|
|
317
|
-
const sort = sortOptions?.[Number(sortIndex) - 1] || null;
|
|
318
|
-
|
|
319
|
-
if (!parsedFilterIsValid(filter)) {
|
|
320
|
-
return {
|
|
321
|
-
filter: null,
|
|
322
|
-
sort,
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return {
|
|
327
|
-
filter,
|
|
328
|
-
sort,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
|
|
332
170
|
/**
|
|
333
171
|
* Promise with timeout
|
|
334
172
|
*/
|
|
@@ -379,6 +217,15 @@ function getStableVariablesKeyValue(value: any): any {
|
|
|
379
217
|
return value;
|
|
380
218
|
}
|
|
381
219
|
|
|
220
|
+
/*
|
|
221
|
+
* Key GraphQL variables exactly as JSON sends them: preserve case, scalar
|
|
222
|
+
* types, null and empty strings, omit undefined, and sort object keys. The
|
|
223
|
+
* prefix distinguishes this format from legacy delimiter-based cache keys.
|
|
224
|
+
*/
|
|
225
|
+
export function makeGraphQLVariablesKey(variables?: Record<string, any> | null): string {
|
|
226
|
+
return '@' + JSON.stringify(getStableVariablesKeyValue(variables || {}));
|
|
227
|
+
}
|
|
228
|
+
|
|
382
229
|
/*
|
|
383
230
|
* Return a compact deterministic hash for a cache key segment.
|
|
384
231
|
*/
|
package/src/utils/number.ts
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
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
|
+
|
|
1
31
|
/**
|
|
2
32
|
* Convert string value to BigInt safely
|
|
3
33
|
*/
|
|
@@ -137,17 +167,6 @@ export function secondsToTime(secs: number) {
|
|
|
137
167
|
};
|
|
138
168
|
}
|
|
139
169
|
|
|
140
|
-
/**
|
|
141
|
-
* Get percentage between 2 values
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
export function calculateDiscount(
|
|
145
|
-
normalPrice: number,
|
|
146
|
-
discountedPrice: number,
|
|
147
|
-
) {
|
|
148
|
-
return Math.round(((normalPrice - discountedPrice) / normalPrice) * 100);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
170
|
/**
|
|
152
171
|
* Format decimal number to a string without decimal places or the first non-zero digit
|
|
153
172
|
*
|
package/src/utils/object.ts
CHANGED
|
@@ -192,6 +192,35 @@ export function stringifyJSON(
|
|
|
192
192
|
);
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Normalize a JSON-like value for order-insensitive serialization: object keys
|
|
197
|
+
* sorted by UTF-16 code unit (never by locale), array order kept, and BigInt
|
|
198
|
+
* and Date values converted to their JSON text forms.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
export function canonicalJSONValue(value: unknown): unknown {
|
|
202
|
+
if (typeof value === 'bigint') return String(value);
|
|
203
|
+
if (value instanceof Date) return value.toISOString();
|
|
204
|
+
if (Array.isArray(value)) return value.map(canonicalJSONValue);
|
|
205
|
+
if (value && typeof value === 'object') {
|
|
206
|
+
return Object.fromEntries(
|
|
207
|
+
Object.entries(value)
|
|
208
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
209
|
+
.map(([key, item]) => [key, canonicalJSONValue(item)]),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
return value;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Serialize JSON with sorted object keys (see canonicalJSONValue), so equal
|
|
217
|
+
* content always produces the same text regardless of property order.
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
export function stableJSONText(value: unknown): string {
|
|
221
|
+
return JSON.stringify(canonicalJSONValue(value));
|
|
222
|
+
}
|
|
223
|
+
|
|
195
224
|
/**
|
|
196
225
|
* Merge nested objects together
|
|
197
226
|
*/
|
package/src/utils/promise.ts
CHANGED
|
@@ -9,9 +9,7 @@ export type MaybePromise<T> = T | Promise<T>;
|
|
|
9
9
|
*/
|
|
10
10
|
export function isPromiseLike<T>(value: MaybePromise<T>): value is Promise<T> {
|
|
11
11
|
return Boolean(
|
|
12
|
-
value &&
|
|
13
|
-
(typeof value === 'object' || typeof value === 'function') &&
|
|
14
|
-
typeof (value as Promise<T>).then === 'function',
|
|
12
|
+
value && (typeof value === 'object' || typeof value === 'function') && typeof (value as Promise<T>).then === 'function',
|
|
15
13
|
);
|
|
16
14
|
}
|
|
17
15
|
|
|
@@ -19,9 +17,82 @@ export function isPromiseLike<T>(value: MaybePromise<T>): value is Promise<T> {
|
|
|
19
17
|
* Chain one continuation onto a maybe-promise without forcing async:
|
|
20
18
|
* plain values invoke the continuation synchronously.
|
|
21
19
|
*/
|
|
22
|
-
export function chainMaybePromise<T, R>(
|
|
23
|
-
value: MaybePromise<T>,
|
|
24
|
-
onValue: (value: T) => MaybePromise<R>,
|
|
25
|
-
): MaybePromise<R> {
|
|
20
|
+
export function chainMaybePromise<T, R>(value: MaybePromise<T>, onValue: (value: T) => MaybePromise<R>): MaybePromise<R> {
|
|
26
21
|
return isPromiseLike(value) ? value.then(onValue) : onValue(value);
|
|
27
22
|
}
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
* Run one async task per item with at most `limit` in flight, starting the next
|
|
26
|
+
* item as soon as any task finishes. Every item runs even when some fail; the
|
|
27
|
+
* first failure is rethrown once all tasks have settled.
|
|
28
|
+
*/
|
|
29
|
+
export async function runWithConcurrencyLimit<T>(items: readonly T[], limit: number, task: (item: T, index: number) => Promise<void>) {
|
|
30
|
+
let nextIndex = 0;
|
|
31
|
+
let failure: { error: unknown } | null = null;
|
|
32
|
+
const runWorker = async () => {
|
|
33
|
+
while (nextIndex < items.length) {
|
|
34
|
+
const index = nextIndex++;
|
|
35
|
+
try {
|
|
36
|
+
await task(items[index], index);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
failure = failure || { error };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const workerLimit = Number.isFinite(limit) ? Math.floor(limit) : 1;
|
|
44
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(workerLimit, items.length)) }, runWorker));
|
|
45
|
+
if (failure) {
|
|
46
|
+
throw (failure as { error: unknown }).error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ConcurrencyGate = {
|
|
51
|
+
run: <T>(task: () => Promise<T>) => Promise<T>;
|
|
52
|
+
tryRun: <T>(task: () => Promise<T>) => Promise<{ ran: true; value: T } | { ran: false }>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Create a gate that lets at most `getLimit()` tasks run at once across every
|
|
57
|
+
* caller that shares it. `run` waits for a slot in arrival order; `tryRun` runs
|
|
58
|
+
* only when a slot is free now and nobody is waiting, and otherwise returns
|
|
59
|
+
* ran=false at once. The limit is read at each admission, so it may come from
|
|
60
|
+
* configuration loaded after the gate was created.
|
|
61
|
+
*/
|
|
62
|
+
export function createConcurrencyGate(getLimit: () => number): ConcurrencyGate {
|
|
63
|
+
let active = 0;
|
|
64
|
+
const waiters: Array<() => void> = [];
|
|
65
|
+
const hasSlot = () => active < Math.max(1, Math.floor(getLimit()));
|
|
66
|
+
const release = () => {
|
|
67
|
+
active -= 1;
|
|
68
|
+
while (waiters.length && hasSlot()) {
|
|
69
|
+
active += 1;
|
|
70
|
+
waiters.shift()?.();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const runAdmitted = async <T>(task: () => Promise<T>) => {
|
|
74
|
+
try {
|
|
75
|
+
return await task();
|
|
76
|
+
} finally {
|
|
77
|
+
release();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
run: async (task) => {
|
|
83
|
+
if (hasSlot() && !waiters.length) {
|
|
84
|
+
active += 1;
|
|
85
|
+
} else {
|
|
86
|
+
await new Promise<void>((resolve) => waiters.push(resolve));
|
|
87
|
+
}
|
|
88
|
+
return await runAdmitted(task);
|
|
89
|
+
},
|
|
90
|
+
tryRun: async (task) => {
|
|
91
|
+
if (!hasSlot() || waiters.length) {
|
|
92
|
+
return { ran: false };
|
|
93
|
+
}
|
|
94
|
+
active += 1;
|
|
95
|
+
return { ran: true, value: await runAdmitted(task) };
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
package/src/utils/queryReset.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* optionally, the serialized variable values a cached page must carry to be
|
|
4
4
|
* reset by it without building or evaluating a regex.
|
|
5
5
|
*
|
|
6
|
-
* Cache keys are '#queryName:' +
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Cache keys are '#queryName:' + makeGraphQLVariablesKey(variables). Request
|
|
7
|
+
* identity preserves exact JSON values. Reset targets retain their existing
|
|
8
|
+
* case-insensitive variable matching 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 for compatibility with existing server reset payloads.
|
|
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
|
|
@@ -54,16 +54,52 @@ export function makeQueryResetTargets(...names: string[]) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
/*
|
|
57
|
-
* Parse
|
|
58
|
-
* pairs. Values are collected per name because a serialized JSON variable can
|
|
59
|
-
* itself contain '$' and split into extra segments; keeping every candidate
|
|
60
|
-
* prevents a structured target from missing a matching serialized variable.
|
|
57
|
+
* Parse serialized variables while preserving dollar signs inside JSON filter values.
|
|
61
58
|
*/
|
|
62
59
|
|
|
63
60
|
function parseVariablesKeySegments(variablesKey: string) {
|
|
64
61
|
const pairs: Record<string, string[]> = {};
|
|
62
|
+
const segments: string[] = [];
|
|
63
|
+
let start = 0;
|
|
64
|
+
let quoted = false;
|
|
65
|
+
let escaped = false;
|
|
66
|
+
let readingValue = false;
|
|
67
|
+
let jsonDepth = 0;
|
|
68
|
+
let jsonStart = -1;
|
|
69
|
+
for (let index = 0; index < variablesKey.length; index++) {
|
|
70
|
+
const character = variablesKey[index];
|
|
71
|
+
if (escaped) {
|
|
72
|
+
escaped = false;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!readingValue && character === ':') {
|
|
76
|
+
readingValue = true;
|
|
77
|
+
jsonStart = index + 1;
|
|
78
|
+
} else if (quoted && character === '\\') {
|
|
79
|
+
escaped = true;
|
|
80
|
+
} else if (jsonDepth && character === '"') {
|
|
81
|
+
quoted = !quoted;
|
|
82
|
+
} else if (
|
|
83
|
+
!quoted &&
|
|
84
|
+
jsonDepth &&
|
|
85
|
+
(character === '}' || character === ']')
|
|
86
|
+
) {
|
|
87
|
+
jsonDepth--;
|
|
88
|
+
} else if (
|
|
89
|
+
!quoted &&
|
|
90
|
+
(jsonDepth || index === jsonStart) &&
|
|
91
|
+
(character === '{' || character === '[')
|
|
92
|
+
) {
|
|
93
|
+
jsonDepth++;
|
|
94
|
+
} else if (!quoted && !jsonDepth && character === '$') {
|
|
95
|
+
segments.push(variablesKey.slice(start, index));
|
|
96
|
+
start = index + 1;
|
|
97
|
+
readingValue = false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
segments.push(variablesKey.slice(start));
|
|
65
101
|
|
|
66
|
-
for (const segment of
|
|
102
|
+
for (const segment of segments) {
|
|
67
103
|
const separatorIndex = segment.indexOf(':');
|
|
68
104
|
if (separatorIndex < 1) {
|
|
69
105
|
continue;
|
|
@@ -81,6 +117,37 @@ function parseVariablesKeySegments(variablesKey: string) {
|
|
|
81
117
|
return pairs;
|
|
82
118
|
}
|
|
83
119
|
|
|
120
|
+
/*
|
|
121
|
+
* Match a nested filter field without requiring every pagination and filter variable to be identical.
|
|
122
|
+
*/
|
|
123
|
+
function nestedVariableMatches(
|
|
124
|
+
pairs: Record<string, string[]>,
|
|
125
|
+
variableName: string,
|
|
126
|
+
expectedValue: string,
|
|
127
|
+
) {
|
|
128
|
+
const [root, ...path] = variableName.split('.');
|
|
129
|
+
if (
|
|
130
|
+
!path.length ||
|
|
131
|
+
path.some((key) => ['__proto__', 'constructor', 'prototype'].includes(key))
|
|
132
|
+
)
|
|
133
|
+
return false;
|
|
134
|
+
return (pairs[root] || []).some((serialized) => {
|
|
135
|
+
try {
|
|
136
|
+
let value: unknown = JSON.parse(serialized);
|
|
137
|
+
for (const key of path) {
|
|
138
|
+
if (!value || typeof value !== 'object' || !Object.hasOwn(value, key))
|
|
139
|
+
return false;
|
|
140
|
+
value = (value as Record<string, unknown>)[key];
|
|
141
|
+
}
|
|
142
|
+
return (
|
|
143
|
+
value !== null && value !== undefined && String(value) === expectedValue
|
|
144
|
+
);
|
|
145
|
+
} catch {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
84
151
|
/*
|
|
85
152
|
* Return whether one cached query key is covered by a structured reset target.
|
|
86
153
|
* A target with no match constraints covers every page of that query, which is
|
|
@@ -101,11 +168,31 @@ export function queryCacheKeyMatchesResetTarget(
|
|
|
101
168
|
return true;
|
|
102
169
|
}
|
|
103
170
|
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
171
|
+
const variablesKey = queryCacheKey.slice(queryPrefix.length);
|
|
172
|
+
// New keys preserve exact GraphQL values. Reset targets intentionally keep
|
|
173
|
+
// their legacy case-insensitive matching so existing server emits still work.
|
|
174
|
+
if (variablesKey.startsWith('@')) {
|
|
175
|
+
try {
|
|
176
|
+
const variables = JSON.parse(variablesKey.slice(1));
|
|
177
|
+
return matchEntries.every(([path, expected]) => {
|
|
178
|
+
let value = variables;
|
|
179
|
+
for (const part of path.split('.')) {
|
|
180
|
+
if (!value || typeof value !== 'object') return false;
|
|
181
|
+
const key = Object.keys(value).find((key) => key.toLowerCase() === part.toLowerCase());
|
|
182
|
+
if (!key || ['__proto__', 'constructor', 'prototype'].includes(key)) return false;
|
|
183
|
+
value = value[key];
|
|
184
|
+
}
|
|
185
|
+
return value != null && String(value).toLowerCase() === expected.toLowerCase();
|
|
186
|
+
});
|
|
187
|
+
} catch {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const pairs = parseVariablesKeySegments(variablesKey);
|
|
192
|
+
return matchEntries.every(
|
|
193
|
+
([variableName, value]) =>
|
|
194
|
+
Boolean(pairs[variableName]?.includes(value)) ||
|
|
195
|
+
nestedVariableMatches(pairs, variableName, value),
|
|
109
196
|
);
|
|
110
197
|
}
|
|
111
198
|
|
package/src/utils/string.test.ts
CHANGED
|
@@ -37,9 +37,7 @@ beforeAll(() => {
|
|
|
37
37
|
|
|
38
38
|
describe('cn', () => {
|
|
39
39
|
it('joins truthy class names with spaces', () => {
|
|
40
|
-
expect(cn('card', false, 'selected', undefined, null, '')).toBe(
|
|
41
|
-
'card selected',
|
|
42
|
-
);
|
|
40
|
+
expect(cn('card', false, 'selected', undefined, null, '')).toBe('card selected');
|
|
43
41
|
});
|
|
44
42
|
});
|
|
45
43
|
|
|
@@ -80,9 +78,7 @@ describe('isEmail', () => {
|
|
|
80
78
|
describe('convertToInternationalPhone and isPhone', () => {
|
|
81
79
|
it('normalizes North American and existing international numbers', () => {
|
|
82
80
|
expect(convertToInternationalPhone('(555) 123-4567')).toBe('+15551234567');
|
|
83
|
-
expect(convertToInternationalPhone('+44 20 1234 5678')).toBe(
|
|
84
|
-
'+442012345678',
|
|
85
|
-
);
|
|
81
|
+
expect(convertToInternationalPhone('+44 20 1234 5678')).toBe('+442012345678');
|
|
86
82
|
});
|
|
87
83
|
|
|
88
84
|
it('rejects invalid phone-like input', () => {
|
|
@@ -126,9 +122,7 @@ describe('getAlphanumeric and getSearchNames', () => {
|
|
|
126
122
|
});
|
|
127
123
|
|
|
128
124
|
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']);
|
|
125
|
+
expect(getSearchNames(['Alice, Bob and alice', 'Carol;\nBob', null])).toEqual(['Alice', 'Bob', 'Carol']);
|
|
132
126
|
});
|
|
133
127
|
});
|
|
134
128
|
|
|
@@ -171,6 +165,18 @@ describe('isInvisibleString', () => {
|
|
|
171
165
|
});
|
|
172
166
|
|
|
173
167
|
describe('buildSingleText', () => {
|
|
168
|
+
it('renders ternary arrays and nested sections with the selected delimiter', () => {
|
|
169
|
+
for (const preCheck of [true, false]) {
|
|
170
|
+
expect(
|
|
171
|
+
buildSingleText(
|
|
172
|
+
['Header', '', !preCheck ? ['Summary', '', ['Details', { extra: ['Extra details'] }]] : '', '', 'Footer'],
|
|
173
|
+
'|',
|
|
174
|
+
['extra'],
|
|
175
|
+
),
|
|
176
|
+
).toBe(preCheck ? 'Header||Footer' : 'Header||Summary||Details|Extra details||Footer');
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
174
180
|
it('supports feature maps, conditional lines, first-match groups, and blank line collapsing', () => {
|
|
175
181
|
expect(
|
|
176
182
|
buildSingleText(
|
|
@@ -196,23 +202,15 @@ describe('buildSingleText', () => {
|
|
|
196
202
|
|
|
197
203
|
describe('joinReadable and textWithBrackets', () => {
|
|
198
204
|
it('joins human-readable lists and appends bracket text when present', () => {
|
|
199
|
-
expect(joinReadable(['Alpha', 'Beta', 'Gamma'])).toBe(
|
|
200
|
-
|
|
201
|
-
);
|
|
202
|
-
expect(textWithBrackets('Status', ['draft', 'internal'], ['[', ']'])).toBe(
|
|
203
|
-
'Status [draft internal]',
|
|
204
|
-
);
|
|
205
|
-
expect(textWithBrackets('', ['draft', 'internal'], ['[', ']'])).toBe(
|
|
206
|
-
'draft internal',
|
|
207
|
-
);
|
|
205
|
+
expect(joinReadable(['Alpha', 'Beta', 'Gamma'])).toBe('Alpha, Beta and Gamma');
|
|
206
|
+
expect(textWithBrackets('Status', ['draft', 'internal'], ['[', ']'])).toBe('Status [draft internal]');
|
|
207
|
+
expect(textWithBrackets('', ['draft', 'internal'], ['[', ']'])).toBe('draft internal');
|
|
208
208
|
});
|
|
209
209
|
});
|
|
210
210
|
|
|
211
211
|
describe('removeGeneratedTextGarbage and escapeCSVValue', () => {
|
|
212
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
|
-
);
|
|
213
|
+
expect(removeGeneratedTextGarbage('Hello\n\n world\tfrom\r\nAI')).toBe('Hello world from AI');
|
|
216
214
|
expect(escapeCSVValue('plain')).toBe('plain');
|
|
217
215
|
expect(escapeCSVValue('a,"b"\nc')).toBe('"a,""b""\nc"');
|
|
218
216
|
});
|
|
@@ -220,9 +218,7 @@ describe('removeGeneratedTextGarbage and escapeCSVValue', () => {
|
|
|
220
218
|
|
|
221
219
|
describe('truncateFileName', () => {
|
|
222
220
|
it('preserves extensions while truncating long file names', () => {
|
|
223
|
-
expect(truncateFileName('very-long-document-name.pdf', 12)).toBe(
|
|
224
|
-
'very-....pdf',
|
|
225
|
-
);
|
|
221
|
+
expect(truncateFileName('very-long-document-name.pdf', 12)).toBe('very-....pdf');
|
|
226
222
|
expect(truncateFileName('short.txt', 20)).toBe('short.txt');
|
|
227
223
|
});
|
|
228
224
|
});
|
|
@@ -237,18 +233,11 @@ describe('formatPhoneNumber', () => {
|
|
|
237
233
|
|
|
238
234
|
describe('splitTextIntoChunks', () => {
|
|
239
235
|
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
|
-
]);
|
|
236
|
+
expect(splitTextIntoChunks('12345\n67890\nabcde', 10, 5)).toEqual(['12345', '67890', 'abcde']);
|
|
245
237
|
});
|
|
246
238
|
|
|
247
239
|
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
|
-
]);
|
|
240
|
+
expect(splitTextIntoChunks('alpha beta gamma delta', 12, 2)).toEqual(['alpha beta', 'gamma delta']);
|
|
252
241
|
});
|
|
253
242
|
});
|
|
254
243
|
|
|
@@ -276,12 +265,8 @@ describe('makeAddressText and getDisplayName', () => {
|
|
|
276
265
|
};
|
|
277
266
|
|
|
278
267
|
expect(makeAddressText(address, 'REGION_ONLY')).toBe('Toronto, ON, CA');
|
|
279
|
-
expect(makeAddressText(address, 'SINGLE_LINE', true)).toBe(
|
|
280
|
-
|
|
281
|
-
);
|
|
282
|
-
expect(makeAddressText(address)).toBe(
|
|
283
|
-
'1 Main St\nSuite 2\nToronto, ON A1A 1A1\nCA',
|
|
284
|
-
);
|
|
268
|
+
expect(makeAddressText(address, 'SINGLE_LINE', true)).toBe('1 Main St, Suite 2, Toronto, ON, A1A 1A1, Canada');
|
|
269
|
+
expect(makeAddressText(address)).toBe('1 Main St\nSuite 2\nToronto, ON A1A 1A1\nCA');
|
|
285
270
|
});
|
|
286
271
|
|
|
287
272
|
it('builds a full name and short display name together', () => {
|