@jsb188/app 1.1.10 → 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
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { MaybePromise } from './promise.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Run one asynchronous task on a recurring start-to-start cadence without
|
|
5
|
+
* allowing executions to overlap. Errors are delegated safely and never stop
|
|
6
|
+
* future attempts; the returned idempotent function cancels the next attempt.
|
|
7
|
+
*/
|
|
8
|
+
export function startAsyncRecurringTask(
|
|
9
|
+
task: () => MaybePromise<unknown>,
|
|
10
|
+
intervalMs: number,
|
|
11
|
+
onError: (error: unknown) => MaybePromise<unknown>,
|
|
12
|
+
): () => void {
|
|
13
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0) {
|
|
14
|
+
throw new TypeError('Recurring task interval must be a positive number.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let stopped = false;
|
|
18
|
+
let timeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
* Schedule the next attempt only while this recurring task remains active.
|
|
22
|
+
*/
|
|
23
|
+
const schedule = (delayMs: number) => {
|
|
24
|
+
if (!stopped) {
|
|
25
|
+
timeoutId = setTimeout(run, delayMs);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Settle one attempt before scheduling the next start on the same cadence.
|
|
31
|
+
*/
|
|
32
|
+
const run = async () => {
|
|
33
|
+
timeoutId = null;
|
|
34
|
+
const startedAt = performance.now();
|
|
35
|
+
try {
|
|
36
|
+
await task();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
try {
|
|
39
|
+
void Promise.resolve(onError(error)).catch(() => {});
|
|
40
|
+
} catch {
|
|
41
|
+
// Diagnostics must never break task scheduling.
|
|
42
|
+
}
|
|
43
|
+
} finally {
|
|
44
|
+
schedule(Math.max(0, intervalMs - (performance.now() - startedAt)));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
schedule(intervalMs);
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Stop future attempts without interrupting an already-running task.
|
|
52
|
+
*/
|
|
53
|
+
return () => {
|
|
54
|
+
stopped = true;
|
|
55
|
+
if (timeoutId !== null) {
|
|
56
|
+
clearTimeout(timeoutId);
|
|
57
|
+
timeoutId = null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pruning-only object schemas.
|
|
3
|
+
*
|
|
4
|
+
* A schema describes the shape a plain object is expected to have, and
|
|
5
|
+
* pruneToSchema() removes everything that does not match it. Nothing is ever
|
|
6
|
+
* rejected wholesale and nothing ever throws: a value that fails its node is
|
|
7
|
+
* dropped, and the surrounding object survives without that key. The worst
|
|
8
|
+
* outcome for a completely foreign value is an empty object.
|
|
9
|
+
*
|
|
10
|
+
* This exists for data that crosses a version boundary the code cannot
|
|
11
|
+
* control (persisted drafts, restored local state, third-party payloads),
|
|
12
|
+
* where an old shape reaching React is a crash and dropping it is not.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export type DraftSchemaPrimitive = 'any' | 'boolean' | 'number' | 'string';
|
|
16
|
+
|
|
17
|
+
export type DraftSchemaExplicitNode =
|
|
18
|
+
| { type: 'any' }
|
|
19
|
+
| { type: 'array'; maxLength?: number; of: DraftSchemaNode }
|
|
20
|
+
| { type: 'boolean' }
|
|
21
|
+
| { type: 'number'; integer?: boolean; max?: number; min?: number }
|
|
22
|
+
| { type: 'object'; shape: DraftSchema }
|
|
23
|
+
| { type: 'string'; maxLength?: number; oneOf?: readonly string[] };
|
|
24
|
+
|
|
25
|
+
export type DraftSchemaNode =
|
|
26
|
+
| DraftSchemaPrimitive
|
|
27
|
+
| DraftSchemaExplicitNode
|
|
28
|
+
// Shorthand for { type: 'object', shape }
|
|
29
|
+
| DraftSchema
|
|
30
|
+
// Shorthand for { type: 'array', of }
|
|
31
|
+
| [DraftSchemaNode];
|
|
32
|
+
|
|
33
|
+
export interface DraftSchema {
|
|
34
|
+
[key: string]: DraftSchemaNode;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const SCHEMA_CONSTANTS = {
|
|
38
|
+
nodeTypes: ['any', 'array', 'boolean', 'number', 'object', 'string'],
|
|
39
|
+
// Keys an explicit node is allowed to carry; a foreign key means the object
|
|
40
|
+
// is a nested shape that happens to have a "type" field of its own
|
|
41
|
+
nodeOptionKeys: [
|
|
42
|
+
'type',
|
|
43
|
+
'integer',
|
|
44
|
+
'max',
|
|
45
|
+
'maxLength',
|
|
46
|
+
'min',
|
|
47
|
+
'of',
|
|
48
|
+
'oneOf',
|
|
49
|
+
'shape',
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check whether a value is a plain object (excludes arrays, Date, Map, class
|
|
55
|
+
* instances, and null), which is the only thing an object node accepts.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
59
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const prototype = Object.getPrototypeOf(value);
|
|
64
|
+
return prototype === Object.prototype || prototype === null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolve one schema node to its explicit form, expanding the nested-shape and
|
|
69
|
+
* array shorthands.
|
|
70
|
+
*
|
|
71
|
+
* An object is read as an explicit node only when its "type" names a known
|
|
72
|
+
* node type and every other key is a valid option for a node; anything else is
|
|
73
|
+
* a nested shape. That keeps a shape like { type: 'string', name: 'string' }
|
|
74
|
+
* readable as a shape. The one shorthand this cannot express is a shape whose
|
|
75
|
+
* only key is "type" — write { type: 'object', shape: { type: 'string' } } for
|
|
76
|
+
* that case.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
function normalizeSchemaNode(
|
|
80
|
+
node: DraftSchemaNode,
|
|
81
|
+
): DraftSchemaExplicitNode | null {
|
|
82
|
+
if (typeof node === 'string') {
|
|
83
|
+
return SCHEMA_CONSTANTS.nodeTypes.includes(node)
|
|
84
|
+
? ({ type: node } as DraftSchemaExplicitNode)
|
|
85
|
+
: null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (Array.isArray(node)) {
|
|
89
|
+
return node.length ? { type: 'array', of: node[0] } : null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!isPlainObject(node)) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const nodeType = (node as any).type;
|
|
97
|
+
if (
|
|
98
|
+
typeof nodeType === 'string' &&
|
|
99
|
+
SCHEMA_CONSTANTS.nodeTypes.includes(nodeType)
|
|
100
|
+
) {
|
|
101
|
+
const hasForeignKey = Object.keys(node).some(
|
|
102
|
+
(key) => !SCHEMA_CONSTANTS.nodeOptionKeys.includes(key),
|
|
103
|
+
);
|
|
104
|
+
if (!hasForeignKey) {
|
|
105
|
+
return node as DraftSchemaExplicitNode;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return { type: 'object', shape: node as DraftSchema };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Prune one value against one schema node.
|
|
114
|
+
*
|
|
115
|
+
* Returns whether the value survives, plus the (possibly rewritten) value.
|
|
116
|
+
* null passes every node as an explicit "no value"; undefined never survives.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
function pruneSchemaValue(
|
|
120
|
+
value: unknown,
|
|
121
|
+
node: DraftSchemaNode,
|
|
122
|
+
): { keep: boolean; value: unknown } {
|
|
123
|
+
if (value === undefined) {
|
|
124
|
+
return { keep: false, value: undefined };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const explicitNode = normalizeSchemaNode(node);
|
|
128
|
+
if (!explicitNode) {
|
|
129
|
+
return { keep: false, value: undefined };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (value === null) {
|
|
133
|
+
return { keep: true, value: null };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
switch (explicitNode.type) {
|
|
137
|
+
case 'any':
|
|
138
|
+
return { keep: true, value };
|
|
139
|
+
|
|
140
|
+
case 'string': {
|
|
141
|
+
if (typeof value !== 'string') {
|
|
142
|
+
return { keep: false, value: undefined };
|
|
143
|
+
}
|
|
144
|
+
if (explicitNode.oneOf && !explicitNode.oneOf.includes(value)) {
|
|
145
|
+
return { keep: false, value: undefined };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const maxLength = explicitNode.maxLength;
|
|
149
|
+
return {
|
|
150
|
+
keep: true,
|
|
151
|
+
value:
|
|
152
|
+
typeof maxLength === 'number' && value.length > maxLength
|
|
153
|
+
? value.substring(0, maxLength)
|
|
154
|
+
: value,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
case 'number': {
|
|
159
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
160
|
+
return { keep: false, value: undefined };
|
|
161
|
+
}
|
|
162
|
+
if (explicitNode.integer && !Number.isInteger(value)) {
|
|
163
|
+
return { keep: false, value: undefined };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Out-of-range numbers are dropped rather than clamped; clamping
|
|
167
|
+
// would invent a value the writer never had
|
|
168
|
+
if (typeof explicitNode.min === 'number' && value < explicitNode.min) {
|
|
169
|
+
return { keep: false, value: undefined };
|
|
170
|
+
}
|
|
171
|
+
if (typeof explicitNode.max === 'number' && value > explicitNode.max) {
|
|
172
|
+
return { keep: false, value: undefined };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return { keep: true, value };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
case 'boolean':
|
|
179
|
+
return typeof value === 'boolean'
|
|
180
|
+
? { keep: true, value }
|
|
181
|
+
: { keep: false, value: undefined };
|
|
182
|
+
|
|
183
|
+
case 'object': {
|
|
184
|
+
if (!isPlainObject(value)) {
|
|
185
|
+
return { keep: false, value: undefined };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// An object whose keys all fail still survives as {}; merging with a
|
|
189
|
+
// default value fills it back in at read time
|
|
190
|
+
return { keep: true, value: pruneSchemaShape(value, explicitNode.shape) };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
case 'array': {
|
|
194
|
+
if (!Array.isArray(value)) {
|
|
195
|
+
return { keep: false, value: undefined };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const prunedItems: unknown[] = [];
|
|
199
|
+
for (const item of value) {
|
|
200
|
+
const prunedItem = pruneSchemaValue(item, explicitNode.of);
|
|
201
|
+
if (prunedItem.keep) {
|
|
202
|
+
prunedItems.push(prunedItem.value);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (
|
|
206
|
+
typeof explicitNode.maxLength === 'number' &&
|
|
207
|
+
prunedItems.length >= explicitNode.maxLength
|
|
208
|
+
) {
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return { keep: true, value: prunedItems };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
default:
|
|
217
|
+
return { keep: false, value: undefined };
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Prune every key of one plain object against one schema shape. Keys absent
|
|
223
|
+
* from the schema are dropped.
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
function pruneSchemaShape(
|
|
227
|
+
value: Record<string, unknown>,
|
|
228
|
+
schema: DraftSchema,
|
|
229
|
+
): Record<string, unknown> {
|
|
230
|
+
const pruned: Record<string, unknown> = {};
|
|
231
|
+
|
|
232
|
+
for (const key in schema) {
|
|
233
|
+
if (!Object.hasOwn(schema, key) || !Object.hasOwn(value, key)) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const prunedValue = pruneSchemaValue(value[key], schema[key]);
|
|
238
|
+
if (prunedValue.keep) {
|
|
239
|
+
pruned[key] = prunedValue.value;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return pruned;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Prune one value against one schema, keeping only what matches.
|
|
248
|
+
*
|
|
249
|
+
* Returns null when the value is not a plain object, since a schema describes
|
|
250
|
+
* a shape and there is nothing to keep from a value that has none.
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
export function pruneToSchema<T = Record<string, unknown>>(
|
|
254
|
+
value: unknown,
|
|
255
|
+
schema: DraftSchema,
|
|
256
|
+
): T | null {
|
|
257
|
+
if (!isPlainObject(value)) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return pruneSchemaShape(value, schema) as T;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Merge a pruned value over its default value.
|
|
266
|
+
*
|
|
267
|
+
* Plain objects merge key by key so a field dropped during pruning falls back
|
|
268
|
+
* to its default instead of arriving undefined. Arrays and every other value
|
|
269
|
+
* replace the default outright: a persisted list is authoritative, including
|
|
270
|
+
* when it is empty.
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
export function mergeSchemaDefaults<T>(value: unknown, defaultValue: T): T {
|
|
274
|
+
if (value === undefined) {
|
|
275
|
+
return defaultValue;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (!isPlainObject(value) || !isPlainObject(defaultValue)) {
|
|
279
|
+
return value as T;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const merged: Record<string, unknown> = { ...defaultValue };
|
|
283
|
+
for (const key in value) {
|
|
284
|
+
if (Object.hasOwn(value, key)) {
|
|
285
|
+
merged[key] = mergeSchemaDefaults(
|
|
286
|
+
value[key],
|
|
287
|
+
(defaultValue as Record<string, unknown>)[key],
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return merged as T;
|
|
293
|
+
}
|