@jsb188/app 1.1.11 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +17 -6
  3. package/src/constants/agent.ts +44 -57
  4. package/src/constants/app.ts +43 -0
  5. package/src/constants/wsActions.ts +1 -15
  6. package/src/i18n/account.ts +1 -1
  7. package/src/i18n/agent.ts +321 -96
  8. package/src/i18n/agentToolBusiness.ts +340 -0
  9. package/src/i18n/agentToolGrid.ts +121 -0
  10. package/src/i18n/agentToolWorkflow.ts +101 -0
  11. package/src/i18n/agent_note.ts +110 -0
  12. package/src/i18n/app.ts +23 -17
  13. package/src/i18n/auth.ts +25 -30
  14. package/src/i18n/billing.ts +3 -85
  15. package/src/i18n/c.ts +953 -0
  16. package/src/i18n/campaign.ts +164 -211
  17. package/src/i18n/datetime.ts +6 -0
  18. package/src/i18n/editor.ts +56 -0
  19. package/src/i18n/email_outreach_editor.ts +526 -0
  20. package/src/i18n/error.ts +430 -202
  21. package/src/i18n/field_doc_editor.ts +21 -0
  22. package/src/i18n/field_doc_programs.ts +51 -0
  23. package/src/i18n/field_docs.ts +171 -8
  24. package/src/i18n/form.ts +7 -491
  25. package/src/i18n/index.ts +23 -3
  26. package/src/i18n/log.ts +234 -39
  27. package/src/i18n/memory.ts +18 -5
  28. package/src/i18n/message.ts +1 -0
  29. package/src/i18n/note.ts +5 -3
  30. package/src/i18n/org.ts +97 -45
  31. package/src/i18n/schedule.ts +133 -0
  32. package/src/i18n/sheet.ts +105 -161
  33. package/src/i18n/sheet_formula.ts +165 -0
  34. package/src/i18n/workflow.ts +112 -11
  35. package/src/main.ts +2 -2
  36. package/src/platform.ts +89 -49
  37. package/src/types/ai.d.ts +16 -1
  38. package/src/types/app.d.ts +29 -73
  39. package/src/types/auth.d.ts +1 -1
  40. package/src/types/other.d.ts +8 -1
  41. package/src/utils/api.ts +60 -10
  42. package/src/utils/clientIP.ts +213 -0
  43. package/src/utils/color.ts +95 -0
  44. package/src/utils/csv.ts +19 -0
  45. package/src/utils/datetime.ts +207 -31
  46. package/src/utils/deferredSave.ts +89 -0
  47. package/src/utils/email.ts +50 -0
  48. package/src/utils/expression.helpers.ts +470 -0
  49. package/src/utils/expression.ts +1633 -239
  50. package/src/utils/language.ts +9 -0
  51. package/src/utils/logic.ts +9 -162
  52. package/src/utils/number.ts +30 -11
  53. package/src/utils/object.ts +69 -127
  54. package/src/utils/promise.ts +78 -7
  55. package/src/utils/queryReset.ts +110 -61
  56. package/src/utils/string.ts +80 -143
  57. package/src/utils/url_client.ts +115 -15
  58. package/src/constants/billing.ts +0 -146
  59. package/src/i18n/agentDoc.ts +0 -110
  60. package/src/types/form.d.ts +0 -101
  61. package/src/utils/billing.ts +0 -141
  62. package/src/utils/managedSessionBff.test.ts +0 -60
  63. package/src/utils/string.test.ts +0 -293
  64. package/tsconfig.json +0 -12
@@ -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
+ }
@@ -1,11 +1,11 @@
1
1
  /*
2
- * Structured query-reset targets. A target names one GraphQL query and,
3
- * optionally, the serialized variable values a cached page must carry to be
4
- * reset by it without building or evaluating a regex.
2
+ * Structured query-reset targets for the client's own cache. A target names
3
+ * one GraphQL query and, optionally, the serialized variable values a cached
4
+ * page must carry to be reset by it without building or evaluating a regex.
5
5
  *
6
- * Cache keys are '#queryName:' + makeVariablesKey(variables). The query name
7
- * keeps its GraphQL casing; only the variables segment is lowercased, so the
8
- * name is compared case-sensitively here and variables are compared lowercased.
6
+ * Cache keys are '#queryName:' + makeGraphQLVariablesKey(variables). Request
7
+ * identity preserves exact JSON values. Reset targets match variables
8
+ * case-insensitively and also understand legacy cache keys.
9
9
  */
10
10
 
11
11
  export interface QueryResetTarget {
@@ -15,7 +15,7 @@ export interface QueryResetTarget {
15
15
 
16
16
  /*
17
17
  * Build one structured query-reset target. Variable names and values are
18
- * lowercased to line up with makeVariablesKey().
18
+ * lowercased, because targets match cache keys case-insensitively.
19
19
  *
20
20
  * Callers decide which constraints apply: omit a key to widen the target (no
21
21
  * constraint on that variable), and pass an empty value only if the intent is
@@ -46,24 +46,52 @@ export function makeQueryResetTarget(
46
46
  }
47
47
 
48
48
  /*
49
- * Build unconstrained structured reset targets for a list of GraphQL queries.
50
- */
51
-
52
- export function makeQueryResetTargets(...names: string[]) {
53
- return names.map((name) => makeQueryResetTarget(name));
54
- }
55
-
56
- /*
57
- * Parse one serialized variables key ('$a:1$b:2') into its variable/value
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.
49
+ * Parse serialized variables while preserving dollar signs inside JSON filter values.
61
50
  */
62
51
 
63
52
  function parseVariablesKeySegments(variablesKey: string) {
64
53
  const pairs: Record<string, string[]> = {};
54
+ const segments: string[] = [];
55
+ let start = 0;
56
+ let quoted = false;
57
+ let escaped = false;
58
+ let readingValue = false;
59
+ let jsonDepth = 0;
60
+ let jsonStart = -1;
61
+ for (let index = 0; index < variablesKey.length; index++) {
62
+ const character = variablesKey[index];
63
+ if (escaped) {
64
+ escaped = false;
65
+ continue;
66
+ }
67
+ if (!readingValue && character === ':') {
68
+ readingValue = true;
69
+ jsonStart = index + 1;
70
+ } else if (quoted && character === '\\') {
71
+ escaped = true;
72
+ } else if (jsonDepth && character === '"') {
73
+ quoted = !quoted;
74
+ } else if (
75
+ !quoted &&
76
+ jsonDepth &&
77
+ (character === '}' || character === ']')
78
+ ) {
79
+ jsonDepth--;
80
+ } else if (
81
+ !quoted &&
82
+ (jsonDepth || index === jsonStart) &&
83
+ (character === '{' || character === '[')
84
+ ) {
85
+ jsonDepth++;
86
+ } else if (!quoted && !jsonDepth && character === '$') {
87
+ segments.push(variablesKey.slice(start, index));
88
+ start = index + 1;
89
+ readingValue = false;
90
+ }
91
+ }
92
+ segments.push(variablesKey.slice(start));
65
93
 
66
- for (const segment of variablesKey.split('$')) {
94
+ for (const segment of segments) {
67
95
  const separatorIndex = segment.indexOf(':');
68
96
  if (separatorIndex < 1) {
69
97
  continue;
@@ -81,6 +109,37 @@ function parseVariablesKeySegments(variablesKey: string) {
81
109
  return pairs;
82
110
  }
83
111
 
112
+ /*
113
+ * Match a nested filter field without requiring every pagination and filter variable to be identical.
114
+ */
115
+ function nestedVariableMatches(
116
+ pairs: Record<string, string[]>,
117
+ variableName: string,
118
+ expectedValue: string,
119
+ ) {
120
+ const [root, ...path] = variableName.split('.');
121
+ if (
122
+ !path.length ||
123
+ path.some((key) => ['__proto__', 'constructor', 'prototype'].includes(key))
124
+ )
125
+ return false;
126
+ return (pairs[root] || []).some((serialized) => {
127
+ try {
128
+ let value: unknown = JSON.parse(serialized);
129
+ for (const key of path) {
130
+ if (!value || typeof value !== 'object' || !Object.hasOwn(value, key))
131
+ return false;
132
+ value = (value as Record<string, unknown>)[key];
133
+ }
134
+ return (
135
+ value !== null && value !== undefined && String(value) === expectedValue
136
+ );
137
+ } catch {
138
+ return false;
139
+ }
140
+ });
141
+ }
142
+
84
143
  /*
85
144
  * Return whether one cached query key is covered by a structured reset target.
86
145
  * A target with no match constraints covers every page of that query, which is
@@ -101,11 +160,37 @@ export function queryCacheKeyMatchesResetTarget(
101
160
  return true;
102
161
  }
103
162
 
104
- const pairs = parseVariablesKeySegments(
105
- queryCacheKey.slice(queryPrefix.length),
106
- );
107
- return matchEntries.every(([variableName, value]) =>
108
- Boolean(pairs[variableName]?.includes(value)),
163
+ const variablesKey = queryCacheKey.slice(queryPrefix.length);
164
+ // New keys preserve exact GraphQL values. Reset targets intentionally keep
165
+ // matching them case-insensitively, like legacy keys.
166
+ if (variablesKey.startsWith('@')) {
167
+ try {
168
+ const variables = JSON.parse(variablesKey.slice(1));
169
+ return matchEntries.every(([path, expected]) => {
170
+ let value = variables;
171
+ for (const part of path.split('.')) {
172
+ if (!value || typeof value !== 'object') return false;
173
+ const key = Object.keys(value).find(
174
+ (key) => key.toLowerCase() === part.toLowerCase(),
175
+ );
176
+ if (!key || ['__proto__', 'constructor', 'prototype'].includes(key))
177
+ return false;
178
+ value = value[key];
179
+ }
180
+ return (
181
+ value != null &&
182
+ String(value).toLowerCase() === expected.toLowerCase()
183
+ );
184
+ });
185
+ } catch {
186
+ return false;
187
+ }
188
+ }
189
+ const pairs = parseVariablesKeySegments(variablesKey);
190
+ return matchEntries.every(
191
+ ([variableName, value]) =>
192
+ Boolean(pairs[variableName]?.includes(value)) ||
193
+ nestedVariableMatches(pairs, variableName, value),
109
194
  );
110
195
  }
111
196
 
@@ -122,42 +207,6 @@ export function queryCacheKeyMatchesAnyResetTarget(
122
207
  );
123
208
  }
124
209
 
125
- /*
126
- * Remove targets that duplicate an earlier one by value. Structured targets are
127
- * plain objects, so they need stable value identities for deduplication.
128
- */
129
-
130
- export function dedupeQueryResetTargets(targets: QueryResetTarget[]) {
131
- const seenIds = new Set<string>();
132
-
133
- return targets.filter((target) => {
134
- const targetId = getQueryResetTargetId(target);
135
- if (seenIds.has(targetId)) {
136
- return false;
137
- }
138
-
139
- seenIds.add(targetId);
140
- return true;
141
- });
142
- }
143
-
144
- /*
145
- * Build the structured reset field for websocket payload builders that measure
146
- * their complete packet before publishing.
147
- */
148
-
149
- export function buildResetQueryPayloadFields(
150
- targets?: QueryResetTarget[] | null,
151
- ) {
152
- if (!targets?.length) {
153
- return { resetQueries: undefined };
154
- }
155
-
156
- return {
157
- resetQueries: targets,
158
- };
159
- }
160
-
161
210
  /*
162
211
  * Return a stable identity string for one target. Used as the query observer
163
212
  * event name where a single string is required; the '~' prefix keeps it from