@jsb188/graphql 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 (165) hide show
  1. package/audience.d.ts +343 -0
  2. package/cache/config.ts +58 -24
  3. package/cache/index.chat-activity.test.ts +119 -0
  4. package/cache/index.chat.test.ts +92 -0
  5. package/cache/index.helpers.ts +96 -0
  6. package/cache/index.regression.test.ts +149 -0
  7. package/cache/index.test.ts +370 -42
  8. package/cache/index.ts +326 -799
  9. package/cache/optimistic-ui-runtime.ts +46 -0
  10. package/cache/optimistic-ui.ts +401 -0
  11. package/cache/persist.ts +98 -19
  12. package/cache/store.ts +22 -64
  13. package/cache/value.helpers.ts +17 -0
  14. package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
  15. package/{drafts/index.ts → client/draft-persistence.ts} +5 -2
  16. package/client/index.ts +3 -2
  17. package/client/request.helpers.ts +14 -0
  18. package/client/request.ts +130 -215
  19. package/deno.lock +17 -0
  20. package/deno.test.json +2 -0
  21. package/gql/fragments/agentMemoryFragments.ts +5 -1
  22. package/gql/fragments/agentNoteFragments.ts +150 -0
  23. package/gql/fragments/aiChatFragments.ts +36 -10
  24. package/gql/fragments/audienceFragments.ts +141 -0
  25. package/gql/fragments/campaignFragments.ts +415 -126
  26. package/gql/fragments/dataTableFragments.ts +48 -80
  27. package/gql/fragments/emailFragments.ts +28 -23
  28. package/gql/fragments/fieldDocFragments.ts +222 -40
  29. package/gql/fragments/inboundContactFragments.ts +2 -0
  30. package/gql/fragments/logFragments.ts +93 -2
  31. package/gql/fragments/organizationFragments.ts +10 -0
  32. package/gql/fragments/qrCodeFragments.ts +29 -0
  33. package/gql/fragments/scheduleFragments.ts +652 -140
  34. package/gql/fragments/sheetFragments.ts +84 -373
  35. package/gql/fragments/storageFragments.ts +25 -1
  36. package/gql/fragments/workflowFragments.ts +13 -1
  37. package/gql/mutations/agentMemoryMutations.ts +32 -0
  38. package/gql/mutations/agentNoteMutations.ts +62 -0
  39. package/gql/mutations/aiChatMutations.ts +36 -4
  40. package/gql/mutations/audienceMutations.ts +71 -0
  41. package/gql/mutations/authMutations.ts +45 -1
  42. package/gql/mutations/billingMutations.ts +24 -0
  43. package/gql/mutations/campaignMutations.ts +170 -127
  44. package/gql/mutations/contactMutations.ts +23 -0
  45. package/gql/mutations/dataTableMutations.ts +18 -75
  46. package/gql/mutations/fieldDocMutations.ts +162 -13
  47. package/gql/mutations/index.ts +8 -5
  48. package/gql/mutations/organizationMutations.ts +6 -0
  49. package/gql/mutations/qrCodeMutations.ts +20 -0
  50. package/gql/mutations/scheduleMutations.ts +1052 -354
  51. package/gql/mutations/sheetMutations.ts +62 -118
  52. package/gql/mutations/storageMutations.ts +0 -1
  53. package/gql/mutations/workflowMutations.ts +18 -0
  54. package/gql/queries/agentMemoryQueries.ts +6 -0
  55. package/gql/queries/agentNoteQueries.ts +89 -0
  56. package/gql/queries/aiChatQueries.ts +56 -4
  57. package/gql/queries/audienceQueries.ts +128 -0
  58. package/gql/queries/authQueries.ts +6 -0
  59. package/gql/queries/billingQueries.ts +95 -6
  60. package/gql/queries/campaignQueries.ts +132 -23
  61. package/gql/queries/dataTableQueries.ts +24 -65
  62. package/gql/queries/emailQueries.ts +18 -61
  63. package/gql/queries/emailReplyReportQueries.ts +76 -0
  64. package/gql/queries/fieldDocQueries.ts +100 -92
  65. package/gql/queries/inboundContactQueries.ts +4 -0
  66. package/gql/queries/index.ts +3 -1
  67. package/gql/queries/logQueries.ts +62 -7
  68. package/gql/queries/organizationQueries.ts +13 -0
  69. package/gql/queries/qrCodeQueries.ts +20 -0
  70. package/gql/queries/scheduleQueries.ts +633 -257
  71. package/gql/queries/sheetQueries.ts +59 -152
  72. package/gql/queries/workflowQueries.ts +10 -4
  73. package/hooks/index.helpers.test.ts +50 -0
  74. package/hooks/index.helpers.ts +52 -0
  75. package/hooks/index.ts +863 -685
  76. package/hooks/use-agentMemory-mtn.ts +29 -31
  77. package/hooks/use-agentMemory-qry.ts +15 -3
  78. package/hooks/use-agentNote-mtn.ts +82 -0
  79. package/hooks/use-agentNote-qry.ts +190 -0
  80. package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
  81. package/hooks/use-agentNote-recovery.helpers.ts +58 -0
  82. package/hooks/use-agentNote-recovery.ts +72 -0
  83. package/hooks/use-aiChat-mtn.ts +96 -112
  84. package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
  85. package/hooks/use-aiChat-qry.helpers.ts +124 -0
  86. package/hooks/use-aiChat-qry.ts +229 -383
  87. package/hooks/use-aiChat-stream-mtn.ts +14 -0
  88. package/hooks/use-audience-mtn.ts +194 -0
  89. package/hooks/use-audience-qry.helpers.test.ts +80 -0
  90. package/hooks/use-audience-qry.helpers.ts +63 -0
  91. package/hooks/use-audience-qry.ts +330 -0
  92. package/hooks/use-auth-mtn.ts +30 -1
  93. package/hooks/use-billing-mtn.ts +31 -0
  94. package/hooks/use-billing-qry.ts +76 -0
  95. package/hooks/use-campaign-generation-recovery.ts +53 -0
  96. package/hooks/use-campaign-mtn.ts +224 -165
  97. package/hooks/use-campaign-qry.helpers.ts +40 -0
  98. package/hooks/use-campaign-qry.ts +631 -54
  99. package/hooks/use-dataTable-mtn.ts +23 -115
  100. package/hooks/use-dataTable-qry.ts +66 -916
  101. package/hooks/use-email-qry.helpers.ts +37 -0
  102. package/hooks/use-email-qry.ts +33 -178
  103. package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
  104. package/hooks/use-fieldDoc-mtn.ts +244 -32
  105. package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
  106. package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
  107. package/hooks/use-fieldDoc-qry.ts +134 -102
  108. package/hooks/use-inboundContact-qry.ts +7 -9
  109. package/hooks/use-log-mtn.ts +25 -12
  110. package/hooks/use-log-qry.ts +99 -46
  111. package/hooks/use-organization-qry.ts +16 -60
  112. package/hooks/use-publicFormEmail-mtn.ts +27 -0
  113. package/hooks/use-qrCode-mtn.ts +40 -0
  114. package/hooks/use-qrCode-qry.ts +78 -0
  115. package/hooks/use-schedule-mtn.ts +506 -333
  116. package/hooks/use-schedule-qry.ts +682 -101
  117. package/hooks/use-schedule-reactive.ts +486 -0
  118. package/hooks/use-sheet-mtn.ts +91 -199
  119. package/hooks/use-sheet-qry.ts +84 -238
  120. package/hooks/use-storage-qry.ts +84 -61
  121. package/hooks/use-workflow-mtn.ts +39 -22
  122. package/hooks/use-workflow-qry.ts +40 -61
  123. package/libs/ai-chat-outgoing.helpers.ts +153 -0
  124. package/libs/ai-chat-outgoing.ts +11 -0
  125. package/libs/ai-chat-outgoing.types.ts +25 -0
  126. package/libs/ai-chat-run-realtime.ts +20 -0
  127. package/libs/ai-chat-submission-realtime.ts +150 -0
  128. package/libs/fragment-realtime-sequence.ts +55 -0
  129. package/libs/fragment-recovery.test.ts +326 -0
  130. package/libs/fragment-recovery.ts +325 -0
  131. package/libs/open-sheet.ts +138 -0
  132. package/libs/orchestrator-realtime.helpers.test.ts +229 -0
  133. package/libs/orchestrator-realtime.helpers.ts +317 -0
  134. package/libs/orchestrator-realtime.ts +433 -0
  135. package/libs/request-cache-regression.test.ts +122 -0
  136. package/{client → libs}/request-managed-session.test.ts +1 -1
  137. package/libs/request-no-store.test.ts +419 -0
  138. package/libs/sheet-command-batch.ts +44 -0
  139. package/libs/sheet-view-realtime-router.test.ts +214 -0
  140. package/libs/sheet-view-realtime-router.ts +99 -0
  141. package/loaders/campaign.test.ts +186 -0
  142. package/loaders/campaign.ts +56 -83
  143. package/loaders/emailPreference.ts +75 -0
  144. package/loaders/rest.ts +12 -0
  145. package/package.json +42 -17
  146. package/schedule.d.ts +1790 -0
  147. package/sse.helpers.ts +19 -0
  148. package/sse.ts +26 -115
  149. package/tests/agent-note-detail-cache.test.ts +120 -0
  150. package/tests/agent-note-search.test.ts +444 -0
  151. package/types.d.ts +46 -25
  152. package/client/data-table-realtime-subscriptions.test.ts +0 -740
  153. package/client/data-table-realtime-subscriptions.ts +0 -955
  154. package/client/data-table-realtime.test.ts +0 -792
  155. package/client/data-table-realtime.ts +0 -1218
  156. package/client/fragment-realtime-sequence.ts +0 -52
  157. package/client/open-sheet.ts +0 -137
  158. package/client/request-no-store.test.ts +0 -157
  159. package/gql/fragments/agentDocFragments.ts +0 -46
  160. package/gql/fragments/billingFragments.ts +0 -14
  161. package/gql/mutations/agentDocMutations.ts +0 -177
  162. package/gql/queries/agentDocQueries.ts +0 -120
  163. package/hooks/use-agentDoc-mtn.ts +0 -285
  164. package/hooks/use-agentDoc-qry.ts +0 -208
  165. /package/{client → libs}/sse-ticket.test.ts +0 -0
@@ -1,39 +1,15 @@
1
- import {
2
- graphqlRequestNoStore,
3
- useQuery,
4
- useReactiveFragment,
5
- useReactiveFragmentMap,
6
- } from '@jsb188/graphql/client';
1
+ import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '@jsb188/graphql/client';
2
+ import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
7
3
  import { GRID_ITEM_LIST_LIMIT } from '@jsb188/mday/constants/sheet.ts';
8
- import type { DataTableRowGQL } from '@jsb188/mday/types/dataTable.d.ts';
9
- import type {
10
- GridItemSortEnum,
11
- SheetGridViewportObj,
12
- SheetJournalSeqInput,
13
- SheetOperationalHistoryGQL,
14
- } from '@jsb188/mday/types/sheet.d.ts';
15
- import { normalizeSheetJournalSeq } from '@jsb188/mday/utils/sheetSequence.ts';
16
- import {
17
- FRAGMENT_NAMES,
18
- getFragmentBaseName,
19
- makeFragmentKey,
20
- } from '@jsb188/mday/constants/graphqlReactivity.ts';
4
+ import type { GridItemSortEnum, SheetTabGQL } from '@jsb188/mday/types/sheet.d.ts';
21
5
  import { useEffect, useMemo, useRef, useState } from 'react';
22
- import { fetchOpenSheetOnce } from '../client/open-sheet.ts';
23
- import {
24
- sheetAccessGrantsQry,
25
- sheetAccessQry,
26
- sheetOperationalHistoryQry,
27
- sheetRegionSourcePreviewRowsQry,
28
- sheetsQry,
29
- sheetTabChangesQry,
30
- } from '../gql/queries/sheetQueries.ts';
6
+ import { sheetAccessGrantsQry, sheetAccessQry, sheetsQry } from '../gql/queries/sheetQueries.ts';
31
7
  import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
32
8
 
33
9
  export {
34
10
  fetchOpenSheetOnce,
35
11
  getOpenSheetQueryVariables,
36
- } from '../client/open-sheet.ts';
12
+ } from '../libs/open-sheet.ts';
37
13
 
38
14
  export type SheetsVariables = PaginationArgs & {
39
15
  organizationId?: string | null;
@@ -58,18 +34,14 @@ function mapSheetDeletedStatus(sheet: any) {
58
34
  /*
59
35
  * Return whether one useSheets input is the paginated variables object.
60
36
  */
61
- function isSheetsVariables(
62
- value: string | null | undefined | SheetsVariables,
63
- ): value is SheetsVariables {
37
+ function isSheetsVariables(value: string | null | undefined | SheetsVariables): value is SheetsVariables {
64
38
  return !!value && typeof value === 'object';
65
39
  }
66
40
 
67
41
  /*
68
42
  * Return GraphQL variables for the paginated sheets query.
69
43
  */
70
- function getSheetsQueryVariables(
71
- organizationIdOrVariables?: string | null | SheetsVariables,
72
- ): SheetsVariables {
44
+ function getSheetsQueryVariables(organizationIdOrVariables?: string | null | SheetsVariables): SheetsVariables {
73
45
  if (isSheetsVariables(organizationIdOrVariables)) {
74
46
  return {
75
47
  ...organizationIdOrVariables,
@@ -93,24 +65,15 @@ function getSheetsQueryVariables(
93
65
  * Fetch sheets for an organization.
94
66
  */
95
67
 
96
- export function useSheets(
97
- organizationId?: string | null | SheetsVariables,
98
- params: UseQueryParams = {},
99
- ) {
68
+ export function useSheets(organizationId?: string | null | SheetsVariables, params: UseQueryParams = {}) {
100
69
  const variables = getSheetsQueryVariables(organizationId);
101
70
  const { data, ...rest } = useQuery(sheetsQry, {
102
71
  variables,
103
72
  skip: !variables.organizationId,
104
73
  ...params,
105
74
  });
106
- const sheets = useReactiveFragmentMap(
107
- data?.sheets || null,
108
- getFragmentBaseName(FRAGMENT_NAMES.sheet),
109
- );
110
- const sheetsWithDeletedStatus = useMemo(
111
- () => sheets?.map(mapSheetDeletedStatus) || sheets,
112
- [sheets],
113
- );
75
+ const sheets = useReactiveFragmentMap(data?.sheets || null, getFragmentBaseName(FRAGMENT_NAMES.sheet));
76
+ const sheetsWithDeletedStatus = useMemo(() => sheets?.map(mapSheetDeletedStatus) || sheets, [sheets]);
114
77
 
115
78
  return {
116
79
  sheets: sheetsWithDeletedStatus,
@@ -118,42 +81,11 @@ export function useSheets(
118
81
  };
119
82
  }
120
83
 
121
- /*
122
- * Fetch source rows for an unsaved generated Sheet region preview.
123
- */
124
- export function useSheetRegionSourcePreviewRows(
125
- organizationId?: string | null,
126
- region?: Record<string, any> | null,
127
- limit?: number | null,
128
- params: UseQueryParams = {},
129
- ) {
130
- const variables = {
131
- organizationId,
132
- region,
133
- limit,
134
- };
135
- const { data, ...rest } = useQuery(sheetRegionSourcePreviewRowsQry, {
136
- variables,
137
- ...params,
138
- skip: !organizationId || !region || !limit || Boolean(params.skip),
139
- });
140
-
141
- return {
142
- sheetRegionSourcePreviewRows:
143
- (data?.sheetRegionSourcePreviewRows as DataTableRowGQL[] | null) || null,
144
- ...rest,
145
- };
146
- }
147
-
148
84
  /*
149
85
  * Fetch one sheet's viewer-specific access facts (works signed out).
150
86
  */
151
87
 
152
- export function useSheetAccess(
153
- sheetId?: string | null,
154
- params: UseQueryParams = {},
155
- authorizationScopeId?: string | null,
156
- ) {
88
+ export function useSheetAccess(sheetId?: string | null, params: UseQueryParams = {}, authorizationScopeId?: string | null) {
157
89
  const { data, ...rest } = useQuery(sheetAccessQry, {
158
90
  variables: {
159
91
  // Not consumed by GraphQL; it isolates viewer-specific client cache and
@@ -176,15 +108,9 @@ export function useSheetAccess(
176
108
  * initial refetch is intentionally effect-driven so it never blocks bootstrap
177
109
  * paint; subsequent server RESET_ONLY events are handled by useQuery.
178
110
  */
179
- export function useSheetAccessMonitor(
180
- sheetId?: string | null,
181
- enabled: boolean = true,
182
- monitorScopeId: string = '',
183
- ) {
111
+ export function useSheetAccessMonitor(sheetId?: string | null, enabled: boolean = true, monitorScopeId: string = '') {
184
112
  const activeSheetId = enabled ? String(sheetId || '') : '';
185
- const refreshKey = activeSheetId
186
- ? JSON.stringify([activeSheetId, monitorScopeId])
187
- : '';
113
+ const refreshKey = activeSheetId ? JSON.stringify([activeSheetId, monitorScopeId]) : '';
188
114
  const [monitorState, setMonitorState] = useState<{
189
115
  key: string;
190
116
  status: 'READY' | 'ERROR';
@@ -192,6 +118,8 @@ export function useSheetAccessMonitor(
192
118
  const query = useSheetAccess(
193
119
  sheetId,
194
120
  {
121
+ // This monitor explicitly refetches once per access scope below.
122
+ revalidateOnMount: false,
195
123
  skip: !enabled,
196
124
  onCompleted: () => {
197
125
  setMonitorState({ key: refreshKey, status: 'READY' });
@@ -235,10 +163,7 @@ export function useSheetAccessMonitor(
235
163
  return {
236
164
  ...query,
237
165
  loading: enabled && !monitorSettled ? true : query.loading,
238
- sheetAccess:
239
- monitorSettled && monitorState.status === 'READY'
240
- ? query.sheetAccess
241
- : null,
166
+ sheetAccess: monitorSettled && monitorState.status === 'READY' ? query.sheetAccess : null,
242
167
  };
243
168
  }
244
169
 
@@ -247,11 +172,7 @@ export function useSheetAccessMonitor(
247
172
  * the access settings screen alongside the Sheet fragment's base policy.
248
173
  */
249
174
 
250
- export function useSheetAccessGrants(
251
- organizationId?: string | null,
252
- sheetId?: string | null,
253
- params: UseQueryParams = {},
254
- ) {
175
+ export function useSheetAccessGrants(organizationId?: string | null, sheetId?: string | null, params: UseQueryParams = {}) {
255
176
  const { data, ...rest } = useQuery(sheetAccessGrantsQry, {
256
177
  variables: {
257
178
  organizationId,
@@ -268,92 +189,92 @@ export function useSheetAccessGrants(
268
189
  }
269
190
 
270
191
  /*
271
- * Prefetch one authoritative openSheet payload without storing the raw
272
- * transport response in the normalized query cache.
192
+ * Preserve versioned-manifest membership and tab-strip metadata while applying
193
+ * reactive design/content fields. Legacy SheetTab fragments have no manifest
194
+ * ordering fence and therefore cannot add, remove, rename, reorder, or hide a
195
+ * tab once openSheet supplies a manifest revision.
273
196
  */
274
- export function prefetchOpenSheet(
275
- sheetId: string,
276
- params: {
277
- authToken?: string | null;
278
- selectedTabId: string;
279
- sinceSeq?: string | null;
280
- baseSnapshotSeq?: string | null;
281
- baseSnapshotEncodingVersion?: number | null;
282
- baseSnapshotChecksum?: string | null;
283
- viewport?: SheetGridViewportObj | null;
284
- },
285
- ) {
286
- return fetchOpenSheetOnce(sheetId, {
287
- selectedTabId: params.selectedTabId,
288
- sinceSeq: params.sinceSeq,
289
- baseSnapshotSeq: params.baseSnapshotSeq,
290
- baseSnapshotEncodingVersion: params.baseSnapshotEncodingVersion,
291
- baseSnapshotChecksum: params.baseSnapshotChecksum,
292
- viewport: params.viewport,
293
- authToken: params.authToken,
197
+ function getSheetTabsWithAuthoritativeManifestState(reactiveTabs?: SheetTabGQL[] | null, authoritativeTabs?: SheetTabGQL[] | null) {
198
+ if (!reactiveTabs || !authoritativeTabs) {
199
+ return reactiveTabs;
200
+ }
201
+
202
+ const authoritativeTabsById = new Map(authoritativeTabs.map((tab) => [String(tab.id || ''), tab]));
203
+ let changed = false;
204
+
205
+ const projectedTabs = reactiveTabs.map((tab) => {
206
+ const sheetTabId = String(tab.id || '');
207
+ const authoritativeTab = authoritativeTabsById.get(sheetTabId);
208
+ const reactiveDeleted = Boolean((tab as SheetTabGQL & { __deleted?: boolean }).__deleted);
209
+ if (!authoritativeTab) {
210
+ return tab;
211
+ }
212
+
213
+ const hidden = Boolean(authoritativeTab.hidden);
214
+ if (
215
+ String(tab.id || '') === String(authoritativeTab.id || '') &&
216
+ tab.name === authoritativeTab.name &&
217
+ tab.position === authoritativeTab.position &&
218
+ Boolean(tab.hidden) === hidden &&
219
+ !reactiveDeleted
220
+ ) {
221
+ return tab;
222
+ }
223
+
224
+ changed = true;
225
+ return {
226
+ ...tab,
227
+ __deleted: undefined,
228
+ hidden,
229
+ id: authoritativeTab.id,
230
+ name: authoritativeTab.name,
231
+ position: authoritativeTab.position,
232
+ };
294
233
  });
234
+
235
+ return changed ? projectedTabs : reactiveTabs;
295
236
  }
296
237
 
297
238
  /*
298
- * Get reactive Sheet fragment.
239
+ * Get a Sheet fragment whose versioned tab catalog comes from openSheet while
240
+ * ordinary Sheet and SheetTab reactive fields continue to merge independently.
299
241
  */
300
-
301
- export function useReactiveSheetFragment(
302
- sheetId: string,
303
- currentData?: any,
304
- queryCount?: number,
305
- ) {
306
- const sheet = useReactiveFragment(
307
- currentData,
308
- sheetId ? [makeFragmentKey(FRAGMENT_NAMES.sheet, sheetId)] : [],
309
- queryCount,
310
- );
242
+ export function useReactiveSheetFragment(sheetId: string, currentData?: any, queryCount?: number) {
243
+ const sheet = useReactiveFragment(currentData, sheetId ? [makeFragmentKey(FRAGMENT_NAMES.sheet, sheetId)] : [], queryCount);
244
+ const authoritativeManifestTabs =
245
+ currentData?.manifestRevision !== undefined && Array.isArray(currentData?.tabs) ? currentData.tabs : null;
311
246
  const reactiveTabs = useReactiveFragmentMap(
312
- Array.isArray(sheet?.tabs) ? sheet.tabs : null,
247
+ authoritativeManifestTabs || (Array.isArray(sheet?.tabs) ? sheet.tabs : null),
313
248
  getFragmentBaseName(FRAGMENT_NAMES.sheetTab),
314
249
  queryCount,
315
250
  );
316
- const sheetWithDeletedStatus = useMemo(
317
- () =>
318
- mapSheetDeletedStatus(
319
- sheet && reactiveTabs
320
- ? {
321
- ...sheet,
322
- tabs: reactiveTabs.filter((tab: any) => !tab?.__deleted),
323
- }
324
- : sheet,
325
- ),
326
- [reactiveTabs, sheet],
327
- );
251
+ const sheetWithDeletedStatus = useMemo(() => {
252
+ const projectedTabs = getSheetTabsWithAuthoritativeManifestState(
253
+ reactiveTabs,
254
+ authoritativeManifestTabs || (Array.isArray(currentData?.tabs) ? currentData.tabs : null),
255
+ );
256
+
257
+ return mapSheetDeletedStatus(
258
+ sheet && projectedTabs
259
+ ? {
260
+ ...sheet,
261
+ ...(authoritativeManifestTabs ? { manifestRevision: currentData.manifestRevision } : {}),
262
+ tabs: projectedTabs.filter((tab: any) => !tab?.__deleted),
263
+ }
264
+ : sheet,
265
+ );
266
+ }, [authoritativeManifestTabs, currentData?.manifestRevision, currentData?.tabs, reactiveTabs, sheet]);
328
267
 
329
268
  return sheetWithDeletedStatus;
330
269
  }
331
270
 
332
- /*
333
- * Get reactive SheetCell fragments.
334
- */
335
- export function useReactiveSheetCells(cells?: any[] | null) {
336
- return useReactiveFragmentMap(
337
- cells || null,
338
- getFragmentBaseName(FRAGMENT_NAMES.sheetCell),
339
- );
340
- }
341
-
342
271
  /*
343
272
  * Get one background sheet import job's reactive status fragment. The server
344
273
  * emits $sheetImportJobFragment updates to the requesting account as the
345
274
  * import job progresses and finishes.
346
275
  */
347
- export function useReactiveSheetImportJobFragment(
348
- importJobId: string,
349
- currentData?: any,
350
- ) {
351
- return useReactiveFragment(
352
- currentData,
353
- importJobId
354
- ? [makeFragmentKey(FRAGMENT_NAMES.sheetImportJob, importJobId)]
355
- : [],
356
- );
276
+ export function useReactiveSheetImportJobFragment(importJobId: string, currentData?: any) {
277
+ return useReactiveFragment(currentData, importJobId ? [makeFragmentKey(FRAGMENT_NAMES.sheetImportJob, importJobId)] : []);
357
278
  }
358
279
 
359
280
  /*
@@ -363,78 +284,3 @@ export function useReactiveSheetImportJobFragment(
363
284
  export function getSheetViewFragmentKey(sheetViewId: string) {
364
285
  return makeFragmentKey(FRAGMENT_NAMES.sheetView, sheetViewId);
365
286
  }
366
-
367
- /*
368
- * Imperatively fetch one Sheet tab's journal tail (every change after the
369
- * client's last-seen seq) to close a detected realtime seq gap without a full
370
- * authoritative tab snapshot. Returns the raw sheetTabChanges result or null;
371
- * tailAvailable: false means the caller must request a new snapshot.
372
- *
373
- * This path deliberately bypasses query/fragment caches and the shared
374
- * in-flight request map. Recovery cursors are one-shot values, and requests
375
- * carrying distinct auth tokens must never share a promise.
376
- */
377
-
378
- export async function fetchSheetTabChangesTail(
379
- organizationId: string,
380
- sheetId: string,
381
- sheetTabId: string,
382
- afterSeq: SheetJournalSeqInput,
383
- params: {
384
- authToken?: string | null;
385
- } = {},
386
- ): Promise<any> {
387
- const variables = {
388
- organizationId,
389
- sheetId,
390
- sheetTabId,
391
- afterSeq: normalizeSheetJournalSeq(afterSeq),
392
- };
393
-
394
- const result = (await graphqlRequestNoStore(sheetTabChangesQry, variables, {
395
- authToken: params.authToken,
396
- })) as { sheetTabChanges?: any; error?: unknown } | null;
397
- if (result?.error) {
398
- return null;
399
- }
400
-
401
- return result?.sheetTabChanges || null;
402
- }
403
-
404
- /*
405
- * Read one browser-tab session's payload-free durable undo/redo stacks.
406
- */
407
- export function useSheetOperationalHistoryQuery(
408
- params: {
409
- organizationId?: string | null;
410
- sessionId?: string | null;
411
- sheetId?: string | null;
412
- sheetTabId?: string | null;
413
- },
414
- queryParams: UseQueryParams = {},
415
- ) {
416
- const variables = {
417
- organizationId: params.organizationId,
418
- sessionId: params.sessionId,
419
- sheetId: params.sheetId,
420
- sheetTabId: params.sheetTabId,
421
- };
422
- const skip =
423
- !variables.organizationId ||
424
- !variables.sessionId ||
425
- !variables.sheetId ||
426
- !variables.sheetTabId ||
427
- Boolean(queryParams.skip);
428
- const { data, ...rest } = useQuery(sheetOperationalHistoryQry, {
429
- ...queryParams,
430
- variables,
431
- skip,
432
- });
433
-
434
- return {
435
- sheetOperationalHistory:
436
- (data?.sheetOperationalHistory as SheetOperationalHistoryGQL | null) ||
437
- null,
438
- ...rest,
439
- };
440
- }
@@ -1,51 +1,26 @@
1
+ import { FRAGMENT_NAMES, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
1
3
  import type { GeneratedFileGQL } from '@jsb188/mday/types/storage.d.ts';
2
- import {
3
- FRAGMENT_NAMES,
4
- makeFragmentKey,
5
- } from '@jsb188/mday/constants/graphqlReactivity.ts';
6
- import {
7
- generatedFileQry,
8
- generatedFilesQry,
9
- } from '../gql/queries/storageQueries.ts';
10
4
  import { useQuery, useReactiveFragment } from '../client/index.ts';
5
+ import { generatedFileQry, generatedFilesQry } from '../gql/queries/storageQueries.ts';
11
6
  import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
12
7
 
13
8
  /**
14
9
  * Constants
15
10
  */
16
11
 
17
- const GENERATED_FILES_LIST_LIMIT = 100;
18
-
19
- /**
20
- * Get reactive log fragment
21
- */
22
-
23
- export function useReactiveStorageFragment(
24
- storageId: string,
25
- currentData?: any,
26
- queryCount?: number,
27
- ) {
28
- return useReactiveFragment(
29
- currentData,
30
- [makeFragmentKey(FRAGMENT_NAMES.storageFile, storageId)],
31
- queryCount,
32
- );
33
- }
12
+ const FILE_CONSTANTS = {
13
+ listLimit: 100,
14
+ pollIntervalMS: 10000,
15
+ maxPollAttempts: 30,
16
+ };
34
17
 
35
18
  /**
36
19
  * Get reactive generated file fragment (AI CSV exports).
37
20
  */
38
21
 
39
- export function useReactiveGeneratedFileFragment(
40
- code: string,
41
- currentData?: any,
42
- queryCount?: number,
43
- ) {
44
- return useReactiveFragment(
45
- currentData,
46
- [makeFragmentKey(FRAGMENT_NAMES.generatedFile, code)],
47
- queryCount,
48
- );
22
+ export function useReactiveGeneratedFileFragment(code: string, currentData?: any, queryCount?: number) {
23
+ return useReactiveFragment(currentData, [makeFragmentKey(FRAGMENT_NAMES.generatedFile, code)], queryCount);
49
24
  }
50
25
 
51
26
  /**
@@ -64,7 +39,7 @@ export function useGeneratedFiles(
64
39
  ...variables,
65
40
  cursor: null,
66
41
  after: true,
67
- limit: GENERATED_FILES_LIST_LIMIT,
42
+ limit: FILE_CONSTANTS.listLimit,
68
43
  },
69
44
  skip: !variables.organizationId || params.skip,
70
45
  });
@@ -75,38 +50,86 @@ export function useGeneratedFiles(
75
50
  };
76
51
  }
77
52
 
78
- /**
79
- * Fetch one generated file; serves reactive cache data first so a deep link
80
- * that arrives after the list loaded does not refetch.
53
+ /*
54
+ * Reauthorize one generated-file detail whenever it opens, then observe its
55
+ * fragment. Requester-only events may not reach other authorized viewers, so
56
+ * pending details also refresh at a bounded rate while mounted.
81
57
  */
82
-
83
- export function useGeneratedFile(
84
- variables: {
85
- organizationId?: string | null;
86
- code?: string | null;
87
- },
88
- params: UseQueryParams = {},
89
- ) {
90
- const cachedGeneratedFile = useReactiveGeneratedFileFragment(
91
- variables.code || '',
92
- null,
93
- );
94
- const shouldFetchGeneratedFile =
95
- !!variables.organizationId &&
96
- !!variables.code &&
97
- !cachedGeneratedFile &&
98
- !params.skip;
58
+ export function useGeneratedFile(variables: { organizationId?: string | null; code?: string | null }, params: UseQueryParams = {}) {
59
+ const detailKey = `${variables.organizationId || ''}:${variables.code || ''}`;
60
+ const [pollAttempt, setPollAttempt] = useState(0);
61
+ const shouldFetch = !!variables.organizationId && !!variables.code && !params.skip;
62
+ const activation = useRef({
63
+ detailKey,
64
+ shouldFetch,
65
+ requested: false,
66
+ refreshed: false,
67
+ });
68
+ if (activation.current.detailKey !== detailKey || activation.current.shouldFetch !== shouldFetch) {
69
+ activation.current = {
70
+ detailKey,
71
+ shouldFetch,
72
+ requested: false,
73
+ refreshed: false,
74
+ };
75
+ }
99
76
  const { data, ...rest } = useQuery(generatedFileQry, {
100
77
  ...params,
78
+ persistTime: 0,
101
79
  variables,
102
- skip: !shouldFetchGeneratedFile,
80
+ skip: !shouldFetch,
103
81
  });
82
+ const reactiveFile = useReactiveGeneratedFileFragment(variables.code || '', data?.generatedFile, rest.updatedCount);
83
+ const matchesVariables = rest.variables?.organizationId === variables.organizationId && rest.variables?.code === variables.code;
84
+ if (shouldFetch && rest.loading === true) activation.current.requested = true;
85
+ if (activation.current.requested && matchesVariables && rest.loading === false) activation.current.refreshed = true;
86
+ const refreshed = shouldFetch && activation.current.refreshed;
87
+ // A stale fragment never overrides an authorization error or a fresh null lookup.
88
+ const generatedFile =
89
+ refreshed && matchesVariables && !rest.error && data?.generatedFile
90
+ ? ((reactiveFile || data.generatedFile) as GeneratedFileGQL)
91
+ : undefined;
92
+ const pending = generatedFile?.status === 'PENDING' || generatedFile?.status === 'PROCESSING';
93
+ const shouldPoll = shouldFetch && pending && !rest.error && !rest.loading && rest.screenIsFocused && rest.connectedToServer;
94
+
95
+ useEffect(() => {
96
+ setPollAttempt(0);
97
+ }, [detailKey, shouldFetch]);
98
+
99
+ /*
100
+ * A just-fetched query can have age zero and skip automatic revalidation.
101
+ * Refresh it on activation unless useQuery has already started a request.
102
+ */
103
+ useEffect(() => {
104
+ if (!shouldFetch || refreshed || rest.loading) return;
105
+ const timeoutId = globalThis.setTimeout(() => {
106
+ void rest.refetch();
107
+ }, 0);
108
+ return () => globalThis.clearTimeout(timeoutId);
109
+ }, [detailKey, shouldFetch, refreshed, rest.loading, rest.refetch]);
110
+
111
+ useEffect(() => {
112
+ if (!shouldPoll || pollAttempt >= FILE_CONSTANTS.maxPollAttempts) return;
113
+ const timeoutId = globalThis.setTimeout(() => {
114
+ setPollAttempt((attempt) => attempt + 1);
115
+ void rest.refetch();
116
+ }, FILE_CONSTANTS.pollIntervalMS);
117
+ return () => globalThis.clearTimeout(timeoutId);
118
+ }, [shouldPoll, pollAttempt, rest.refetch]);
119
+
120
+ /*
121
+ * A user-requested refresh starts a new bounded polling window.
122
+ */
123
+ const refetch = useCallback(() => {
124
+ setPollAttempt(0);
125
+ return rest.refetch();
126
+ }, [rest.refetch]);
104
127
 
105
128
  return {
106
- generatedFile: (cachedGeneratedFile || data?.generatedFile) as
107
- | GeneratedFileGQL
108
- | undefined,
109
- initialLoading: shouldFetchGeneratedFile && !data,
110
129
  ...rest,
130
+ generatedFile,
131
+ initialLoading: shouldFetch && !refreshed && !rest.error,
132
+ pollingExhausted: pending && pollAttempt >= FILE_CONSTANTS.maxPollAttempts,
133
+ refetch,
111
134
  };
112
135
  }
@@ -2,6 +2,8 @@ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
2
  import { OpenModalPopUpFn } from '@jsb188/react/states';
3
3
  import {
4
4
  cancelReminderMtn,
5
+ deleteWorkflowMtn,
6
+ editProgramWorkflowMtn,
5
7
  updateReminderMtn,
6
8
  } from '../gql/mutations/workflowMutations.ts';
7
9
  import { useMutation } from './index.ts';
@@ -11,17 +13,11 @@ import { useMutation } from './index.ts';
11
13
  * cache updates arrive via the server's realtime fragment emit
12
14
  */
13
15
 
14
- export function useCancelReminder(
15
- params: UseMutationParams = {},
16
- openModalPopUp?: OpenModalPopUpFn,
17
- ) {
18
- const [cancelReminder, mtnValues, mtnHandlers] = useMutation(
19
- cancelReminderMtn,
20
- {
21
- openModalPopUp,
22
- ...params,
23
- },
24
- );
16
+ export function useCancelReminder(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
17
+ const [cancelReminder, mtnValues, mtnHandlers] = useMutation(cancelReminderMtn, {
18
+ openModalPopUp,
19
+ ...params,
20
+ });
25
21
 
26
22
  return {
27
23
  cancelReminder,
@@ -35,17 +31,11 @@ export function useCancelReminder(
35
31
  * cache updates arrive via the server's realtime fragment emit
36
32
  */
37
33
 
38
- export function useUpdateReminder(
39
- params: UseMutationParams = {},
40
- openModalPopUp?: OpenModalPopUpFn,
41
- ) {
42
- const [updateReminder, mtnValues, mtnHandlers] = useMutation(
43
- updateReminderMtn,
44
- {
45
- openModalPopUp,
46
- ...params,
47
- },
48
- );
34
+ export function useUpdateReminder(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
35
+ const [updateReminder, mtnValues, mtnHandlers] = useMutation(updateReminderMtn, {
36
+ openModalPopUp,
37
+ ...params,
38
+ });
49
39
 
50
40
  return {
51
41
  updateReminder,
@@ -53,3 +43,30 @@ export function useUpdateReminder(
53
43
  ...mtnHandlers,
54
44
  };
55
45
  }
46
+
47
+ /**
48
+ * Pause, resume or set the user instructions of one program-managed
49
+ * workflow; the result is the catalog-merged workflow, which updates its
50
+ * cached fragment
51
+ */
52
+
53
+ export function useEditProgramWorkflow(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
54
+ const [editProgramWorkflow, mtnValues, mtnHandlers] = useMutation(editProgramWorkflowMtn, {
55
+ openModalPopUp,
56
+ ...params,
57
+ });
58
+
59
+ return {
60
+ editProgramWorkflow,
61
+ ...mtnValues,
62
+ ...mtnHandlers,
63
+ };
64
+ }
65
+
66
+ /*
67
+ * Permanently delete an eligible workflow; server events remove it from cached lists.
68
+ */
69
+ export function useDeleteWorkflow(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
70
+ const [deleteWorkflow, mtnValues, mtnHandlers] = useMutation(deleteWorkflowMtn, { openModalPopUp, ...params });
71
+ return { deleteWorkflow, ...mtnValues, ...mtnHandlers };
72
+ }