@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.
Files changed (59) hide show
  1. package/package.json +7 -4
  2. package/src/constants/agent.ts +39 -62
  3. package/src/constants/app.ts +17 -0
  4. package/src/constants/wsActions.ts +7 -15
  5. package/src/i18n/account.ts +1 -1
  6. package/src/i18n/agent.ts +326 -88
  7. package/src/i18n/agentToolBusiness.ts +196 -0
  8. package/src/i18n/agentToolGrid.ts +137 -0
  9. package/src/i18n/agentToolWorkflow.ts +101 -0
  10. package/src/i18n/agent_note.ts +109 -0
  11. package/src/i18n/app.ts +23 -17
  12. package/src/i18n/auth.ts +28 -30
  13. package/src/i18n/billing.ts +3 -85
  14. package/src/i18n/c.ts +907 -0
  15. package/src/i18n/campaign.ts +842 -140
  16. package/src/i18n/datetime.ts +6 -0
  17. package/src/i18n/editor.ts +58 -0
  18. package/src/i18n/error.ts +307 -168
  19. package/src/i18n/field_doc_editor.ts +21 -0
  20. package/src/i18n/field_doc_programs.ts +52 -0
  21. package/src/i18n/field_docs.ts +170 -8
  22. package/src/i18n/index.ts +21 -5
  23. package/src/i18n/log.ts +232 -38
  24. package/src/i18n/memory.ts +18 -4
  25. package/src/i18n/note.ts +5 -3
  26. package/src/i18n/org.ts +93 -44
  27. package/src/i18n/schedule.ts +209 -0
  28. package/src/i18n/sheet.ts +102 -145
  29. package/src/i18n/sheet_formula.ts +165 -0
  30. package/src/i18n/workflow.ts +48 -9
  31. package/src/main.ts +2 -2
  32. package/src/platform.ts +89 -49
  33. package/src/types/ai.d.ts +19 -0
  34. package/src/types/app.d.ts +50 -57
  35. package/src/types/other.d.ts +8 -1
  36. package/src/utils/api.ts +46 -0
  37. package/src/utils/clientIP.ts +213 -0
  38. package/src/utils/color.ts +77 -0
  39. package/src/utils/csv.ts +19 -0
  40. package/src/utils/datetime.ts +207 -31
  41. package/src/utils/deferredSave.ts +89 -0
  42. package/src/utils/email.ts +50 -0
  43. package/src/utils/expression.helpers.ts +470 -0
  44. package/src/utils/expression.test.ts +793 -0
  45. package/src/utils/expression.ts +1633 -239
  46. package/src/utils/language.ts +9 -0
  47. package/src/utils/logic.ts +9 -162
  48. package/src/utils/number.ts +30 -11
  49. package/src/utils/object.ts +29 -0
  50. package/src/utils/promise.ts +78 -7
  51. package/src/utils/queryReset.ts +101 -14
  52. package/src/utils/string.test.ts +24 -39
  53. package/src/utils/string.ts +73 -143
  54. package/src/utils/url_client.ts +83 -14
  55. package/src/constants/billing.ts +0 -146
  56. package/src/i18n/agentDoc.ts +0 -110
  57. package/src/i18n/form.ts +0 -496
  58. package/src/types/form.d.ts +0 -101
  59. package/src/utils/billing.ts +0 -141
package/src/main.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  import i18n, { i18nTranslations } from './i18n/index.ts';
4
4
 
5
5
  // Get the correct type for ENV
6
- let ENV: Map<string, string | boolean | number> = new Map();
6
+ const ENV = new Map<string, string | boolean | number>();
7
7
 
8
8
  /**
9
9
  * Extend i18n with app specific texts
@@ -41,7 +41,7 @@ export function configI18n(texts?: Record<string, any>) {
41
41
  * Register environment variables so the package may use it
42
42
  */
43
43
 
44
- export function registerENV(env: Record<string, string>) {
44
+ export function registerENV(env: Record<string, string | boolean | number>) {
45
45
  // Do not use process.env; because this package is used in client + server
46
46
 
47
47
  for (const key in env) {
package/src/platform.ts CHANGED
@@ -1,65 +1,102 @@
1
- const PLATFORM_HANDLERS: Record<string, any> = {};
1
+ import { STORAGE_KEYS } from './constants/app.ts';
2
+
3
+ interface PlatformOptions {
4
+ defaultTheme: string;
5
+ clearAppCache?: () => void;
6
+ }
7
+
8
+ let platformOptions: PlatformOptions = { defaultTheme: '' };
9
+
10
+ /*
11
+ * Configure app-owned theme and cache behavior without replacing browser defaults.
12
+ */
13
+ export function configurePlatform(options: PlatformOptions): void {
14
+ platformOptions = { ...options };
15
+ }
16
+
17
+ /*
18
+ * Read the system dark-mode preference when the runtime supports it.
19
+ */
20
+ export function isSystemDarkMode(): boolean {
21
+ return !!globalThis.matchMedia?.('(prefers-color-scheme: dark)').matches;
22
+ }
2
23
 
3
24
  /**
4
25
  * Get current platform
5
26
  */
6
27
 
7
28
  export function getPlatform(): 'WEB' | 'MOBILE' | 'UNKNOWN' {
8
- return PLATFORM_HANDLERS?.getPlatform?.() || 'UNKNOWN';
29
+ return 'WEB';
9
30
  }
10
31
 
11
32
  /**
12
33
  * Fetch last used login token
13
34
  */
14
35
 
15
- export const fetchAuthToken = (cb: (token: string | null) => void): void => {
16
- return PLATFORM_HANDLERS?.fetchAuthToken?.(cb) || cb(null);
17
- };
36
+ export function fetchAuthToken(cb: (token: string | null) => void): void {
37
+ if (typeof document !== 'undefined') {
38
+ const authToken: string =
39
+ localStorage.getItem(STORAGE_KEYS.AUTH_TOKEN) ?? '';
40
+ cb(authToken);
41
+ } else {
42
+ cb(null);
43
+ }
44
+ }
18
45
 
19
46
  /**
20
47
  * Delete auth token
21
48
  */
22
49
 
23
- export const deleteAuthToken = (): void => {
24
- return PLATFORM_HANDLERS?.deleteAuthToken?.();
25
- };
50
+ export function deleteAuthToken(): void {
51
+ if (typeof document !== 'undefined') {
52
+ localStorage.removeItem(STORAGE_KEYS.AUTH_TOKEN);
53
+ }
54
+ }
26
55
 
27
56
  /**
28
57
  * Save token after login
29
58
  */
30
59
 
31
- export function saveAuthTokenToPlatform(token: string, cb: () => void) {
32
- return PLATFORM_HANDLERS?.saveAuthTokenToPlatform?.(token, cb) || cb();
60
+ export function saveAuthTokenToPlatform(_token: string, cb: () => void) {
61
+ // In Web, there is nothing saved to local storage because we use SSR
62
+ cb();
33
63
  }
34
64
 
35
65
  /**
36
- * Clear platform and app specific (local API) cache
37
- * Change this based on what the app uses
66
+ * Clear app-owned caches using the callback configured at startup.
38
67
  */
39
68
 
40
69
  export function clearAppCache() {
41
- return PLATFORM_HANDLERS?.clearAppCache?.();
70
+ platformOptions.clearAppCache?.();
42
71
  }
43
72
 
44
73
  /**
45
74
  * Fetch last used light mode setting
46
75
  */
47
76
 
48
- export const fetchLightModeSetting = (
77
+ export function fetchLightModeSetting(
49
78
  accountId: number | null,
50
79
  cb: (lightMode: string) => void,
51
- ): void => {
52
- return (
53
- PLATFORM_HANDLERS?.fetchLightModeSetting?.(accountId, cb) || cb('SYSTEM')
54
- );
55
- };
80
+ ): void {
81
+ if (typeof document === 'undefined') {
82
+ cb('');
83
+ return;
84
+ }
85
+
86
+ const key = `${STORAGE_KEYS.LIGHT_MODE}${accountId || 'guest'}`;
87
+ const lightModeSetting = localStorage.getItem(key) || '';
88
+ cb(lightModeSetting);
89
+ }
56
90
 
57
91
  /**
58
92
  * Get correct platform
59
93
  */
60
94
 
61
95
  export function getOS() {
62
- return PLATFORM_HANDLERS?.getOS?.();
96
+ const isApple = /(Mac|iPhone|iPod|iPad)/i.test(
97
+ globalThis.navigator?.platform || '',
98
+ );
99
+ return isApple ? 'mac_os' : 'windows';
63
100
  }
64
101
 
65
102
  /**
@@ -67,7 +104,23 @@ export function getOS() {
67
104
  */
68
105
 
69
106
  export function updateAppTheme(lightMode: string, theme: string) {
70
- return PLATFORM_HANDLERS?.updateAppTheme?.(lightMode, theme);
107
+ if (typeof document === 'undefined') {
108
+ return;
109
+ }
110
+
111
+ const lightModeVal =
112
+ lightMode === 'SYSTEM'
113
+ ? isSystemDarkMode()
114
+ ? 'dark'
115
+ : 'light'
116
+ : lightMode === 'DARK'
117
+ ? 'dark'
118
+ : 'light';
119
+
120
+ const fullThemeName = `${theme || platformOptions.defaultTheme}_${lightModeVal}`;
121
+
122
+ document.body.setAttribute('data-mode', lightModeVal);
123
+ document.body.setAttribute('data-theme', fullThemeName);
71
124
  }
72
125
 
73
126
  /**
@@ -75,7 +128,13 @@ export function updateAppTheme(lightMode: string, theme: string) {
75
128
  */
76
129
 
77
130
  export function getLocalLastVersion(accountId: string) {
78
- return PLATFORM_HANDLERS?.getLocalLastVersion?.(accountId);
131
+ if (typeof document === 'undefined') {
132
+ return '';
133
+ }
134
+
135
+ const lastVersion: string =
136
+ localStorage.getItem(STORAGE_KEYS.LAST_VERSION + accountId) ?? '';
137
+ return lastVersion;
79
138
  }
80
139
 
81
140
  /**
@@ -83,7 +142,11 @@ export function getLocalLastVersion(accountId: string) {
83
142
  */
84
143
 
85
144
  export function saveLocalLastVersion(accountId: string, version: string) {
86
- return PLATFORM_HANDLERS?.saveLocalLastVersion?.(accountId, version);
145
+ if (typeof document === 'undefined') {
146
+ return;
147
+ }
148
+
149
+ localStorage.setItem(STORAGE_KEYS.LAST_VERSION + accountId, version);
87
150
  }
88
151
 
89
152
  /**
@@ -91,36 +154,13 @@ export function saveLocalLastVersion(accountId: string, version: string) {
91
154
  */
92
155
 
93
156
  export function getFileInputObject(fileInput: File) {
94
- return PLATFORM_HANDLERS?.getFileInputObject?.(fileInput) || fileInput;
157
+ return fileInput;
95
158
  }
96
159
 
97
160
  /**
98
161
  * Get buffer data from file
99
162
  */
100
163
 
101
- export function getBufferDataFromFile(file: any) {
102
- return PLATFORM_HANDLERS?.getBufferDataFromFile?.(file) || file;
103
- }
104
-
105
- /**
106
- * Check if system is dark mode
107
- */
108
-
109
- export function isSystemDarkMode() {
110
- return PLATFORM_HANDLERS?.isSystemDarkMode?.();
111
- }
112
-
113
- /**
114
- * Register platform specific handlers
115
- */
116
-
117
- export function registerPlatformHandlers(handlers: Record<string, any>) {
118
- for (const key in handlers) {
119
- if (
120
- Object.prototype.hasOwnProperty.call(handlers, key) &&
121
- typeof handlers[key] === 'function'
122
- ) {
123
- PLATFORM_HANDLERS[key] = handlers[key];
124
- }
125
- }
164
+ export function getBufferDataFromFile<T>(file: T) {
165
+ return file;
126
166
  }
package/src/types/ai.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // AI chat types
2
2
 
3
+ export type AIChatType = 'ORCHESTRATOR';
4
+
3
5
  export type AIChatMessageType =
4
6
  | 'MESSAGE'
5
7
  | 'SMS'
@@ -19,6 +21,8 @@ export type AIEventErrorName =
19
21
  | 'AI_EVENT_NO_ACCESS'
20
22
  | 'AI_COULD_NOT_RESOLVE'
21
23
  | 'AI_CONTEXT_ERR'
24
+ | 'AI_CONTEXT_MANAGEMENT_ERR'
25
+ | 'AI_TOOL_EXECUTION_ERR'
22
26
  | 'AI_ORG_ACL_FAILED'
23
27
  | 'SETUP_INCOMPLETE_ORG'
24
28
  | 'MISSING_API_KEY'
@@ -33,8 +37,11 @@ export type AIEventErrorName =
33
37
  // AI chat
34
38
 
35
39
  export interface AIChatData {
40
+ activityOrder?: string;
36
41
  id: string;
42
+ type: AIChatType | null;
37
43
  organizationId: string | null;
44
+ agentNoteId?: string | null;
38
45
  calDate: string | null;
39
46
  summary: string;
40
47
  userManagedSummary: boolean;
@@ -42,3 +49,15 @@ export interface AIChatData {
42
49
  createdAt: string;
43
50
  updatedAt: string;
44
51
  }
52
+
53
+ // Public execution metadata shared by GraphQL responses and CHAT_RUN_UPDATE SSE events.
54
+ export interface AIChatRunData {
55
+ id: string;
56
+ sourceMessageIds: string[];
57
+ status: 'QUEUED' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'DELIVERY_UNKNOWN';
58
+ inProgress: boolean;
59
+ createdAt: string | null;
60
+ claimedAt: string | null;
61
+ finishedAt: string | null;
62
+ updatedAt: string | null;
63
+ }
@@ -17,21 +17,12 @@ export interface EditUserModalProps extends EditIfaceModalProps {
17
17
  editUser: (obj: object) => void;
18
18
  }
19
19
 
20
- export interface EditUserPlusModalProps extends EditIfaceModalProps {
21
- user: any;
22
- editUserPlus: (obj: object) => void;
23
- }
24
-
25
20
  // App types
26
21
 
27
22
  export type DarkOrLightEnum = 'light' | 'dark';
28
23
 
29
24
  export type ColorEnum = (typeof COLORS)[number];
30
25
 
31
- // Stripe types
32
-
33
- export type PlatformProductGroupEnum = 'PERKS' | 'PLUS' | 'PRO' | 'COINS';
34
-
35
26
  // Server/API related types
36
27
 
37
28
  export interface ServerErrorObj {
@@ -54,67 +45,35 @@ export interface SimpleErrorType {
54
45
  export type ResetQueryRuleEnum =
55
46
  | 'ALWAYS'
56
47
  | 'IF_FRAGMENT_NOT_FOUND'
48
+ | 'IF_FRAGMENT_NOT_IN_QUERY'
57
49
  | 'IF_FRAGMENT_FOUND'
58
50
  | 'NEVER'
59
51
  | 'RESET_ONLY';
60
52
  export type AppendRuleEnum = 'APPEND_NEW' | 'APPEND_AT_END' | 'APPEND_AT_FRONT';
61
53
 
62
- export interface DataTableChangeWSMeta {
63
- batchId: string;
64
- organizationId: string;
65
- dataTableId: string;
66
- fromSeq: string;
67
- toSeq: string;
68
- chunkIndex: number;
69
- chunkCount: number;
54
+ export type ReactiveMessageKindEnum = 'DATA_TABLE' | 'FIELD_DOC' | 'LOG' | 'ORGANIZATION' | 'SHEET';
55
+
56
+ export interface ReactiveMessageObj {
57
+ kind: ReactiveMessageKindEnum;
58
+ identifier?: string;
59
+ label?: string;
60
+ text: string;
70
61
  }
71
62
 
72
- export type DataTableWriteOrderWS =
73
- | {
74
- kind: 'CELL';
75
- dataTableRowId: string;
76
- cellKey: string;
77
- serverSeq: string;
78
- tombstone: boolean;
79
- }
80
- | {
81
- kind: 'DESIGN';
82
- property:
83
- | 'CELLS_ORDER'
84
- | 'FORMAT'
85
- | 'HUMAN_LABEL'
86
- | 'ROW_IDENTIFIER'
87
- | 'WIDTH';
88
- targetKey: string;
89
- targetType: 'CELL' | 'TABLE';
90
- serverSeq: string;
91
- tombstone: boolean;
92
- }
93
- | {
94
- kind: 'ROW';
95
- dataTableRowId: string;
96
- serverSeq: string;
97
- tombstone: boolean;
98
- };
63
+ /* Explicit single-record reads supported by oversized fragment recovery. */
64
+ export interface WSFragmentRecoveryTarget {
65
+ kind: 'AGENT_NOTE' | 'LOG_ENTRY';
66
+ organizationId: string;
67
+ }
99
68
 
100
69
  export interface WSDataUpdateObj {
101
70
  id: string;
102
- route: string[]; // First items in the array have priority (Different org operations may not allow the actions handled by other org operations)
103
- message?: string | null; // If null, nothing will be visible to the client.
104
- messageType: 'NORMAL' | 'SUCCESS' | 'ERROR';
71
+ aiChatSubmission?: AIChatSubmissionWSObj;
72
+ orchestratorArtifact?: OrchestratorArtifactWSObj; // Sheet, tab, table, form or workflow the orchestrator just changed
73
+ messages?: ReactiveMessageObj[];
105
74
  resetQueries?: QueryResetTarget[]; // Structured query reset targets
106
75
  resetQueryRule?: ResetQueryRuleEnum; // Defaults to "IF_FRAGMENT_FOUND"
107
76
  reactiveFragmentKeys?: string[]; // Fragment keys that are used to trigger reactivity
108
- dataTableChange?: DataTableChangeWSMeta; // Exact journal range/chunk contract
109
- dataTableSnapshotRequired?: boolean; // Full snapshot must be awaited before this range is considered converged
110
- dataTableWriteOrders?: DataTableWriteOrderWS[]; // Committed per-target realtime authority
111
- // Committed DataTable authority delivered to a Sheet data room so bridged
112
- // region previews settle without the client joining the DataTable's room
113
- sheetDataTableWriteOrders?: {
114
- dataTableId: string;
115
- organizationId: string;
116
- orders: DataTableWriteOrderWS[];
117
- };
118
77
  authorizationContextChanged?: boolean; // Private memory/disk cache must be discarded and auth reloaded
119
78
  fragments?:
120
79
  | null
@@ -122,12 +81,46 @@ export interface WSDataUpdateObj {
122
81
  name: string;
123
82
  dataId: string;
124
83
  sequence?: string;
84
+ sequenceKey?: string;
85
+ recovery?: WSFragmentRecoveryTarget; // Fetch this record before applying; data is only an identity placeholder.
125
86
  replaceId?: string; // Use this where client has a temporary ID that will be replaced by the server-side ID later
126
87
  appendRule?: AppendRuleEnum | null;
127
88
  data: any;
128
89
  } | null)[];
129
90
  }
130
91
 
92
+ export interface AIChatSubmissionWSObj {
93
+ aiChatId: string;
94
+ clientRequestId: string;
95
+ phase: 'RECEIVED';
96
+ }
97
+
98
+ export type OrchestratorArtifactKind = 'SHEET' | 'SHEET_TAB' | 'DATA_TABLE' | 'FIELD_DOC' | 'WORKFLOW';
99
+ export type OrchestratorArtifactAction = 'CREATED' | 'UPDATED' | 'DELETED';
100
+
101
+ /* One sheet, tab, table, form or workflow a Orchestrator tool call committed, sent to the account's watching tabs */
102
+ export interface OrchestratorArtifactWSObj {
103
+ aiChatId: string; // Serialized generic id
104
+ runId: string; // Durable ai_chat_runs id
105
+ callId: string; // Tool call id; the client's idempotency key
106
+ organizationId: string | null; // Serialized controller organization at tool time
107
+ toolName: string;
108
+ kind: OrchestratorArtifactKind;
109
+ action: OrchestratorArtifactAction;
110
+ sheetId?: string | null; // Serialized; SHEET and SHEET_TAB
111
+ sheetTabId?: string | null; // Serialized; SHEET_TAB, and SHEET when one tab is known (e.g. the first tab on create)
112
+ dataTableId?: string | null; // Serialized; DATA_TABLE
113
+ fieldDocId?: string | null; // Serialized; FIELD_DOC
114
+ fieldDocProgramId?: string | null; // Serialized; FIELD_DOC, the program whose page lists the form's documents
115
+ hasDraft?: boolean | null; // FIELD_DOC: whether the form currently has unpublished changes
116
+ draftStateAt?: string | null; // FIELD_DOC: when the server observed hasDraft, independent of the historical tool call time
117
+ workflowId?: string | null; // Serialized; WORKFLOW
118
+ active?: boolean | null; // WORKFLOW: whether new matching logs run it, when known
119
+ title?: string | null; // Sheet title, tab name, table, form or workflow title as stored when the event was built, else the call's
120
+ replayed?: boolean; // The tool result came from a durable receipt replay
121
+ at: string; // ISO timestamp of emission
122
+ }
123
+
131
124
  export interface WSAppContextUpdateObj {
132
125
  accountId: string;
133
126
  updates: [any, any][];
@@ -7,6 +7,13 @@ import { DAY_OF_WEEK, SCHEDULE_FREQUENCY } from '../constants/other.ts';
7
7
  export type DayOfWeekEnum = (typeof DAY_OF_WEEK)[number];
8
8
  export type ScheduleFrequencyEnum = (typeof SCHEDULE_FREQUENCY)[number];
9
9
 
10
+ /**
11
+ * Shared acknowledgment returned by optimistic editor mutations.
12
+ */
13
+ export interface EditVersionPayloadGQL {
14
+ editVersion: number;
15
+ }
16
+
10
17
  /**
11
18
  * Address
12
19
  */
@@ -39,7 +46,7 @@ export interface ScheduleObj {
39
46
  */
40
47
 
41
48
  export interface LabelAndValue {
42
- iconName?: String;
49
+ iconName?: string;
43
50
  label: string;
44
51
  value: string;
45
52
  quantity?: number;
package/src/utils/api.ts CHANGED
@@ -202,6 +202,52 @@ export function getRealtimeCapabilityOwnerKey(
202
202
  return binding ? JSON.stringify([binding.accountId, binding.sessionId]) : '';
203
203
  }
204
204
 
205
+ /**
206
+ * Return the candidate realtime capability only when it provably renews the
207
+ * current one: same resource instance, organization, and owner, with a strictly
208
+ * later server issue time. Otherwise the current token stays. This only picks
209
+ * which signed token to present; the server still verifies everything.
210
+ */
211
+ export function getNewerRealtimeCapability(
212
+ current: string | null | undefined,
213
+ candidate: string | null | undefined,
214
+ expectedResource: RealtimeCapabilityResource,
215
+ ): string | null {
216
+ const currentToken = current || null;
217
+ if (!currentToken || !candidate || candidate === currentToken) {
218
+ return currentToken;
219
+ }
220
+
221
+ const resourceIdKey = {
222
+ DATA_TABLE: 'dataTableId',
223
+ SHEET: 'sheetId',
224
+ }[expectedResource];
225
+ const [currentPayload, candidatePayload] = [currentToken, candidate].map(
226
+ (token) => {
227
+ const payload = getUnverifiedJWTPayload(token);
228
+ return payload?.__name === 'type:RealtimeCapability' &&
229
+ Number(payload.realtimeCapabilityVersion || 0) === 2 &&
230
+ payload.resource === expectedResource &&
231
+ Number.isSafeInteger(payload.issuedAtMs)
232
+ ? payload
233
+ : null;
234
+ },
235
+ );
236
+ const sameIdentity = Boolean(
237
+ currentPayload &&
238
+ candidatePayload &&
239
+ ['organizationId', resourceIdKey, 'accountId', 'sessionId'].every(
240
+ (key) =>
241
+ String(currentPayload[key] ?? '') ===
242
+ String(candidatePayload[key] ?? ''),
243
+ ),
244
+ );
245
+ return sameIdentity &&
246
+ candidatePayload!.issuedAtMs > currentPayload!.issuedAtMs
247
+ ? candidate
248
+ : currentToken;
249
+ }
250
+
205
251
  /**
206
252
  * Global; save auth token to memory
207
253
  */