@jsb188/graphql 1.1.10 → 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 (176) hide show
  1. package/audience.d.ts +343 -0
  2. package/cache/config.ts +98 -50
  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 +1017 -127
  8. package/cache/index.ts +1256 -1269
  9. package/cache/optimistic-ui-runtime.ts +46 -0
  10. package/cache/optimistic-ui.ts +401 -0
  11. package/cache/persist.ts +800 -0
  12. package/cache/store.ts +395 -0
  13. package/cache/value.helpers.ts +17 -0
  14. package/client/draft-persistence-indexed-db.ts +413 -0
  15. package/client/draft-persistence.ts +152 -0
  16. package/client/index.ts +3 -0
  17. package/client/request.helpers.ts +14 -0
  18. package/client/request.ts +870 -164
  19. package/deno.lock +187 -0
  20. package/deno.test.json +10 -4
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +0 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentMemoryFragments.ts +23 -0
  26. package/gql/fragments/agentNoteFragments.ts +150 -0
  27. package/gql/fragments/aiChatFragments.ts +42 -0
  28. package/gql/fragments/audienceFragments.ts +141 -0
  29. package/gql/fragments/campaignFragments.ts +566 -0
  30. package/gql/fragments/dataTableFragments.ts +50 -192
  31. package/gql/fragments/emailFragments.ts +32 -17
  32. package/gql/fragments/fieldDocFragments.ts +264 -0
  33. package/gql/fragments/inboundContactFragments.ts +2 -0
  34. package/gql/fragments/logFragments.ts +101 -69
  35. package/gql/fragments/organizationFragments.ts +53 -5
  36. package/gql/fragments/qrCodeFragments.ts +29 -0
  37. package/gql/fragments/scheduleFragments.ts +667 -0
  38. package/gql/fragments/sheetFragments.ts +304 -63
  39. package/gql/fragments/storageFragments.ts +45 -0
  40. package/gql/fragments/workflowFragments.ts +41 -5
  41. package/gql/mutations/accountMutations.ts +0 -2
  42. package/gql/mutations/agentMemoryMutations.ts +68 -0
  43. package/gql/mutations/agentNoteMutations.ts +62 -0
  44. package/gql/mutations/aiChatMutations.ts +49 -4
  45. package/gql/mutations/audienceMutations.ts +71 -0
  46. package/gql/mutations/authMutations.ts +203 -18
  47. package/gql/mutations/billingMutations.ts +17 -27
  48. package/gql/mutations/campaignMutations.ts +258 -0
  49. package/gql/mutations/contactMutations.ts +23 -0
  50. package/gql/mutations/dataTableMutations.ts +19 -54
  51. package/gql/mutations/fieldDocMutations.ts +173 -0
  52. package/gql/mutations/index.ts +10 -2
  53. package/gql/mutations/logMutations.ts +6 -29
  54. package/gql/mutations/organizationMutations.ts +19 -4
  55. package/gql/mutations/qrCodeMutations.ts +20 -0
  56. package/gql/mutations/scheduleMutations.ts +1121 -0
  57. package/gql/mutations/sheetMutations.ts +221 -60
  58. package/gql/mutations/storageMutations.ts +19 -0
  59. package/gql/mutations/workflowMutations.ts +60 -0
  60. package/gql/queries/agentMemoryQueries.ts +28 -0
  61. package/gql/queries/agentNoteQueries.ts +89 -0
  62. package/gql/queries/aiChatQueries.ts +70 -2
  63. package/gql/queries/audienceQueries.ts +128 -0
  64. package/gql/queries/authQueries.ts +47 -0
  65. package/gql/queries/billingQueries.ts +118 -6
  66. package/gql/queries/campaignQueries.ts +236 -0
  67. package/gql/queries/dataTableQueries.ts +61 -13
  68. package/gql/queries/emailQueries.ts +26 -17
  69. package/gql/queries/emailReplyReportQueries.ts +76 -0
  70. package/gql/queries/fieldDocQueries.ts +166 -0
  71. package/gql/queries/inboundContactQueries.ts +4 -0
  72. package/gql/queries/index.ts +10 -2
  73. package/gql/queries/logQueries.ts +68 -30
  74. package/gql/queries/organizationQueries.ts +65 -1
  75. package/gql/queries/qrCodeQueries.ts +20 -0
  76. package/gql/queries/scheduleQueries.ts +691 -0
  77. package/gql/queries/sheetQueries.ts +244 -26
  78. package/gql/queries/storageQueries.ts +38 -0
  79. package/gql/queries/workflowQueries.ts +77 -2
  80. package/hooks/index.helpers.test.ts +50 -0
  81. package/hooks/index.helpers.ts +52 -0
  82. package/hooks/index.ts +2254 -982
  83. package/hooks/use-account-mtn.ts +76 -81
  84. package/hooks/use-agentMemory-mtn.ts +71 -0
  85. package/hooks/use-agentMemory-qry.ts +56 -0
  86. package/hooks/use-agentNote-mtn.ts +82 -0
  87. package/hooks/use-agentNote-qry.ts +190 -0
  88. package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
  89. package/hooks/use-agentNote-recovery.helpers.ts +58 -0
  90. package/hooks/use-agentNote-recovery.ts +72 -0
  91. package/hooks/use-aiChat-mtn.ts +220 -141
  92. package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
  93. package/hooks/use-aiChat-qry.helpers.ts +124 -0
  94. package/hooks/use-aiChat-qry.ts +341 -237
  95. package/hooks/use-aiChat-stream-mtn.ts +14 -0
  96. package/hooks/use-app-qry.ts +12 -9
  97. package/hooks/use-audience-mtn.ts +194 -0
  98. package/hooks/use-audience-qry.helpers.test.ts +80 -0
  99. package/hooks/use-audience-qry.helpers.ts +63 -0
  100. package/hooks/use-audience-qry.ts +330 -0
  101. package/hooks/use-auth-mtn.ts +435 -252
  102. package/hooks/use-auth-qry.ts +51 -0
  103. package/hooks/use-billing-mtn.ts +31 -0
  104. package/hooks/use-billing-qry.ts +76 -0
  105. package/hooks/use-campaign-generation-recovery.ts +53 -0
  106. package/hooks/use-campaign-mtn.ts +436 -0
  107. package/hooks/use-campaign-qry.helpers.ts +40 -0
  108. package/hooks/use-campaign-qry.ts +834 -0
  109. package/hooks/use-dataTable-mtn.ts +37 -46
  110. package/hooks/use-dataTable-qry.ts +102 -128
  111. package/hooks/use-email-qry.helpers.ts +37 -0
  112. package/hooks/use-email-qry.ts +56 -86
  113. package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
  114. package/hooks/use-fieldDoc-mtn.ts +262 -0
  115. package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
  116. package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
  117. package/hooks/use-fieldDoc-qry.ts +212 -0
  118. package/hooks/use-inboundContact-mtn.ts +19 -16
  119. package/hooks/use-inboundContact-qry.ts +62 -56
  120. package/hooks/use-integration-mtn.ts +56 -38
  121. package/hooks/use-integration-qry.ts +24 -9
  122. package/hooks/use-log-mtn.ts +88 -59
  123. package/hooks/use-log-qry.ts +150 -73
  124. package/hooks/use-organization-mtn.ts +334 -277
  125. package/hooks/use-organization-qry.ts +155 -129
  126. package/hooks/use-publicFormEmail-mtn.ts +27 -0
  127. package/hooks/use-qrCode-mtn.ts +40 -0
  128. package/hooks/use-qrCode-qry.ts +78 -0
  129. package/hooks/use-schedule-mtn.ts +589 -0
  130. package/hooks/use-schedule-qry.ts +738 -0
  131. package/hooks/use-schedule-reactive.ts +486 -0
  132. package/hooks/use-sheet-mtn.ts +157 -79
  133. package/hooks/use-sheet-qry.ts +221 -92
  134. package/hooks/use-storage-mtn.ts +81 -41
  135. package/hooks/use-storage-qry.ts +128 -14
  136. package/hooks/use-workflow-mtn.ts +72 -0
  137. package/hooks/use-workflow-qry.ts +184 -47
  138. package/libs/ai-chat-outgoing.helpers.ts +153 -0
  139. package/libs/ai-chat-outgoing.ts +11 -0
  140. package/libs/ai-chat-outgoing.types.ts +25 -0
  141. package/libs/ai-chat-run-realtime.ts +20 -0
  142. package/libs/ai-chat-submission-realtime.ts +150 -0
  143. package/libs/fragment-realtime-sequence.ts +55 -0
  144. package/libs/fragment-recovery.test.ts +326 -0
  145. package/libs/fragment-recovery.ts +325 -0
  146. package/libs/open-sheet.ts +138 -0
  147. package/libs/orchestrator-realtime.helpers.test.ts +229 -0
  148. package/libs/orchestrator-realtime.helpers.ts +317 -0
  149. package/libs/orchestrator-realtime.ts +433 -0
  150. package/libs/request-cache-regression.test.ts +122 -0
  151. package/libs/request-managed-session.test.ts +574 -0
  152. package/libs/request-no-store.test.ts +419 -0
  153. package/libs/sheet-command-batch.ts +44 -0
  154. package/libs/sheet-view-realtime-router.test.ts +214 -0
  155. package/libs/sheet-view-realtime-router.ts +99 -0
  156. package/libs/sse-ticket.test.ts +26 -0
  157. package/loaders/campaign.test.ts +186 -0
  158. package/loaders/campaign.ts +110 -0
  159. package/loaders/emailPreference.ts +75 -0
  160. package/loaders/rest.ts +12 -0
  161. package/package.json +119 -71
  162. package/schedule.d.ts +1790 -0
  163. package/sse.helpers.ts +19 -0
  164. package/sse.ts +70 -106
  165. package/tests/agent-note-detail-cache.test.ts +120 -0
  166. package/tests/agent-note-search.test.ts +444 -0
  167. package/tsconfig.json +11 -10
  168. package/types.d.ts +77 -26
  169. package/utils.ts +78 -49
  170. package/gql/fragments/billingFragments.ts +0 -25
  171. package/gql/fragments/productFragments.ts +0 -39
  172. package/gql/fragments/reportFragments.ts +0 -90
  173. package/gql/queries/productQueries.ts +0 -31
  174. package/gql/queries/reportQueries.ts +0 -134
  175. package/hooks/use-product-qry.ts +0 -67
  176. package/hooks/use-report-qry.ts +0 -153
@@ -0,0 +1,262 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import {
4
+ archiveFieldDocMtn,
5
+ createFieldDocProgramGroupMtn,
6
+ editFieldDocProgramGroupMtn,
7
+ deleteFieldDocProgramGroupMtn,
8
+ editFieldDocPlacementMtn,
9
+ createFieldDocProgramMtn,
10
+ deleteFieldDocSubmissionMtn,
11
+ editFieldDocCustomInstructionsMtn,
12
+ editFieldDocMtn,
13
+ editFieldDocProgramMtn,
14
+ editFieldDocSettingsMtn,
15
+ enrollFieldDocProgramMtn,
16
+ restoreFieldDocProgramEnrollmentMtn,
17
+ unenrollFieldDocProgramMtn,
18
+ } from '../gql/mutations/fieldDocMutations.ts';
19
+ import { useMutation } from './index.ts';
20
+
21
+ /**
22
+ * Enroll the organization in a catalog program (idempotent; an archived enrollment must be restored instead). The
23
+ * enrollment list updates through the server's fieldDocProgramEnrollments reset.
24
+ */
25
+
26
+ export function useEnrollFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
27
+ const [enrollFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(enrollFieldDocProgramMtn, {
28
+ openModalPopUp,
29
+ ...params,
30
+ });
31
+
32
+ return {
33
+ enrollFieldDocProgram,
34
+ updateObservers,
35
+ ...mtnValues,
36
+ ...mtnHandlers,
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Unenroll the organization from a program. The enrollment is archived and can be restored until the retention
42
+ * window purges it; the lists update through the server's resets.
43
+ */
44
+
45
+ export function useUnenrollFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
46
+ const [unenrollFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(unenrollFieldDocProgramMtn, {
47
+ openModalPopUp,
48
+ ...params,
49
+ });
50
+
51
+ return {
52
+ unenrollFieldDocProgram,
53
+ updateObservers,
54
+ ...mtnValues,
55
+ ...mtnHandlers,
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Restore an archived enrollment before the retention window purges it, resuming the workflows its unenroll paused.
61
+ */
62
+
63
+ export function useRestoreFieldDocProgramEnrollment(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
64
+ const [restoreFieldDocProgramEnrollment, mtnValues, mtnHandlers, updateObservers] = useMutation(
65
+ restoreFieldDocProgramEnrollmentMtn,
66
+ {
67
+ openModalPopUp,
68
+ ...params,
69
+ },
70
+ );
71
+
72
+ return {
73
+ restoreFieldDocProgramEnrollment,
74
+ updateObservers,
75
+ ...mtnValues,
76
+ ...mtnHandlers,
77
+ };
78
+ }
79
+
80
+ /**
81
+ * Create a custom program in the organization; the result is the new enrollment.
82
+ */
83
+
84
+ export function useCreateFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
85
+ const [createFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(createFieldDocProgramMtn, {
86
+ openModalPopUp,
87
+ ...params,
88
+ });
89
+
90
+ return {
91
+ createFieldDocProgram,
92
+ updateObservers,
93
+ ...mtnValues,
94
+ ...mtnHandlers,
95
+ };
96
+ }
97
+
98
+ /**
99
+ * Edit one of the organization's custom programs (catalog programs are read-only).
100
+ */
101
+
102
+ export function useEditFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
103
+ const [editFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocProgramMtn, {
104
+ openModalPopUp,
105
+ ...params,
106
+ });
107
+
108
+ return {
109
+ editFieldDocProgram,
110
+ updateObservers,
111
+ ...mtnValues,
112
+ ...mtnHandlers,
113
+ };
114
+ }
115
+
116
+ /**
117
+ * Save the organization's custom instructions for a program doc (last writer wins per key). The result is the edit
118
+ * session with the same selection and id, so it updates the cached session that useFieldDocEditSession reads.
119
+ */
120
+
121
+ export function useEditFieldDocCustomInstructions(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
122
+ const { onCompleted, ...rest } = params;
123
+ const [editFieldDocCustomInstructions, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocCustomInstructionsMtn, {
124
+ openModalPopUp,
125
+ onCompleted: (data: any, error: any, variables: any) => {
126
+ onCompleted?.(data?.editFieldDocCustomInstructions, error, variables);
127
+ },
128
+ ...rest,
129
+ });
130
+
131
+ return {
132
+ editFieldDocCustomInstructions,
133
+ updateObservers,
134
+ ...mtnValues,
135
+ ...mtnHandlers,
136
+ };
137
+ }
138
+
139
+ /**
140
+ * Archive a custom fieldDoc; it and its submissions leave every list, and the server deletes them permanently after
141
+ * the retention window. There is no restore.
142
+ */
143
+
144
+ export function useArchiveFieldDoc(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
145
+ const [archiveFieldDoc, mtnValues, mtnHandlers, updateObservers] = useMutation(archiveFieldDocMtn, {
146
+ openModalPopUp,
147
+ ...params,
148
+ });
149
+
150
+ return {
151
+ archiveFieldDoc,
152
+ updateObservers,
153
+ ...mtnValues,
154
+ ...mtnHandlers,
155
+ };
156
+ }
157
+
158
+ /**
159
+ * Permanently delete one fieldDoc submission.
160
+ */
161
+
162
+ export function useDeleteFieldDocSubmission(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
163
+ const [deleteFieldDocSubmission, mtnValues, mtnHandlers, updateObservers] = useMutation(deleteFieldDocSubmissionMtn, {
164
+ openModalPopUp,
165
+ ...params,
166
+ });
167
+
168
+ return {
169
+ deleteFieldDocSubmission,
170
+ updateObservers,
171
+ ...mtnValues,
172
+ ...mtnHandlers,
173
+ };
174
+ }
175
+
176
+ /**
177
+ * Apply a versioned editor patch to one form's unpublished draft.
178
+ */
179
+
180
+ export function useEditFieldDoc(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
181
+ const { onCompleted, ...rest } = params;
182
+ const [editFieldDoc, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocMtn, {
183
+ openModalPopUp,
184
+ onCompleted: (data: any, error: any, variables: any) => {
185
+ onCompleted?.(data?.editFieldDoc, error, variables);
186
+ },
187
+ ...rest,
188
+ });
189
+
190
+ return {
191
+ editFieldDoc,
192
+ updateObservers,
193
+ ...mtnValues,
194
+ ...mtnHandlers,
195
+ };
196
+ }
197
+
198
+ /**
199
+ * Publish or discard one form's editor draft.
200
+ */
201
+
202
+ export function useEditFieldDocSettings(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
203
+ const { onCompleted, ...rest } = params;
204
+ const [editFieldDocSettings, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocSettingsMtn, {
205
+ openModalPopUp,
206
+ onCompleted: (data: any, error: any, variables: any) => {
207
+ onCompleted?.(data?.editFieldDocSettings, error, variables);
208
+ },
209
+ ...rest,
210
+ });
211
+
212
+ return {
213
+ editFieldDocSettings,
214
+ updateObservers,
215
+ ...mtnValues,
216
+ ...mtnHandlers,
217
+ };
218
+ }
219
+
220
+ /*
221
+ * Create one group in an organization-owned program.
222
+ */
223
+ export function useCreateFieldDocProgramGroup(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
224
+ const [createFieldDocProgramGroup, mtnValues, mtnHandlers, updateObservers] = useMutation(createFieldDocProgramGroupMtn, {
225
+ openModalPopUp,
226
+ ...params,
227
+ });
228
+ return { createFieldDocProgramGroup, updateObservers, ...mtnValues, ...mtnHandlers };
229
+ }
230
+
231
+ /*
232
+ * Rename or reorder one group in an organization-owned program.
233
+ */
234
+ export function useEditFieldDocProgramGroup(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
235
+ const [editFieldDocProgramGroup, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocProgramGroupMtn, {
236
+ openModalPopUp,
237
+ ...params,
238
+ });
239
+ return { editFieldDocProgramGroup, updateObservers, ...mtnValues, ...mtnHandlers };
240
+ }
241
+
242
+ /*
243
+ * Delete a group and move its forms to ungrouped.
244
+ */
245
+ export function useDeleteFieldDocProgramGroup(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
246
+ const [deleteFieldDocProgramGroup, mtnValues, mtnHandlers, updateObservers] = useMutation(deleteFieldDocProgramGroupMtn, {
247
+ openModalPopUp,
248
+ ...params,
249
+ });
250
+ return { deleteFieldDocProgramGroup, updateObservers, ...mtnValues, ...mtnHandlers };
251
+ }
252
+
253
+ /*
254
+ * Change form placement without editing its published definition.
255
+ */
256
+ export function useEditFieldDocPlacement(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
257
+ const [editFieldDocPlacement, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocPlacementMtn, {
258
+ openModalPopUp,
259
+ ...params,
260
+ });
261
+ return { editFieldDocPlacement, updateObservers, ...mtnValues, ...mtnHandlers };
262
+ }
@@ -0,0 +1,65 @@
1
+ import { getFieldDocSubmissionsVariables, normalizeFieldDocSubmissionsFilter } from './use-fieldDoc-qry.helpers.ts';
2
+
3
+ /*
4
+ * Throw one readable test failure when a condition is false.
5
+ */
6
+ function expect(value: unknown, message: string) {
7
+ if (!value) {
8
+ throw new Error(message);
9
+ }
10
+ }
11
+
12
+ Deno.test('the submissions filter keeps only FieldDocSubmissionsFilter fields', () => {
13
+ const filter = normalizeFieldDocSubmissionsFilter({
14
+ fieldDocProgramId: 'P1',
15
+ fieldDocIds: ['D1', 'D2'],
16
+ statuses: ['OPEN'],
17
+ startPeriod: '2026-10-01',
18
+ siteId: '',
19
+ sort: 'PERIOD_DESC',
20
+ startDate: '2026-10-01',
21
+ });
22
+
23
+ expect(
24
+ JSON.stringify(filter) ===
25
+ JSON.stringify({
26
+ fieldDocProgramId: 'P1',
27
+ fieldDocIds: ['D1', 'D2'],
28
+ siteId: null,
29
+ statuses: ['OPEN'],
30
+ startPeriod: '2026-10-01',
31
+ endPeriod: null,
32
+ }),
33
+ 'URL-only keys are dropped and every input field is present in one fixed order.',
34
+ );
35
+ expect(
36
+ JSON.stringify(normalizeFieldDocSubmissionsFilter({ fieldDocProgramId: 'P1' })) ===
37
+ JSON.stringify(normalizeFieldDocSubmissionsFilter({ fieldDocProgramId: 'P1', preset: 'x' })),
38
+ 'Equal filters build equal variables, so every consumer shares one cache entry.',
39
+ );
40
+ });
41
+
42
+ Deno.test('the first page and fetchMore follow the logEntries cursor contract', () => {
43
+ const first = getFieldDocSubmissionsVariables({ organizationId: 'O1', filter: { fieldDocProgramId: 'P1' } });
44
+ expect(
45
+ first.cursor === null && first.after === true && first.limit === 100 && first.organizationId === 'O1',
46
+ 'The first page has no cursor, after true and the fixed limit.',
47
+ );
48
+
49
+ const next = getFieldDocSubmissionsVariables({
50
+ organizationId: 'O1',
51
+ filter: { fieldDocProgramId: 'P1' },
52
+ cursor: 'C1',
53
+ after: false,
54
+ limit: 40,
55
+ sort: 'PERIOD_DESC',
56
+ } as any);
57
+ expect(
58
+ next.cursor === 'C1' && next.after === false && next.limit === 40,
59
+ 'fetchMore keeps the row cursor, the direction and the requested page size.',
60
+ );
61
+ expect(
62
+ JSON.stringify(Object.keys(next)) === JSON.stringify(['organizationId', 'filter', 'cursor', 'after', 'limit']),
63
+ 'Only the declared query variables are sent; the route table sort is dropped.',
64
+ );
65
+ });
@@ -0,0 +1,49 @@
1
+ import type { FieldDocSubmissionsFilterArgs } from '@jsb188/mday/types/fieldDoc.d.ts';
2
+
3
+ /**
4
+ * Types
5
+ */
6
+
7
+ export interface FieldDocSubmissionsVariables {
8
+ organizationId: string | null;
9
+ filter: FieldDocSubmissionsFilterArgs;
10
+ cursor: string | null;
11
+ after: boolean;
12
+ limit: number;
13
+ }
14
+
15
+ /*
16
+ * Keep a list filter aligned with the FieldDocSubmissionsFilter input shape. Route table filters can carry
17
+ * URL-only keys, and one unknown input field fails the whole query.
18
+ */
19
+ export function normalizeFieldDocSubmissionsFilter(filter?: Record<string, any> | null): FieldDocSubmissionsFilterArgs {
20
+ return {
21
+ fieldDocProgramId: filter?.fieldDocProgramId || null,
22
+ fieldDocIds: filter?.fieldDocIds || null,
23
+ siteId: filter?.siteId || null,
24
+ statuses: filter?.statuses || null,
25
+ startPeriod: filter?.startPeriod || null,
26
+ endPeriod: filter?.endPeriod || null,
27
+ };
28
+ }
29
+
30
+ /*
31
+ * Build the fieldDocSubmissions variables with the logEntries cursor contract: the first page has no cursor and
32
+ * after true, and fetchMore sends the last row's cursor with after false for the next older page. The first page
33
+ * limit is fixed at 100 because the limit is part of the query cache key, so every consumer shares one cache entry.
34
+ */
35
+ export function getFieldDocSubmissionsVariables(p: {
36
+ organizationId?: string | null;
37
+ filter?: Record<string, any> | null;
38
+ cursor?: string | null;
39
+ after?: boolean;
40
+ limit?: number;
41
+ }): FieldDocSubmissionsVariables {
42
+ return {
43
+ organizationId: p.organizationId || null,
44
+ filter: normalizeFieldDocSubmissionsFilter(p.filter),
45
+ cursor: p.cursor ?? null,
46
+ after: p.after ?? true,
47
+ limit: p.limit ?? 100,
48
+ };
49
+ }
@@ -0,0 +1,212 @@
1
+ import type {
2
+ FieldDocEditSessionGQL,
3
+ FieldDocProgramEnrollmentGQL,
4
+ FieldDocProgramGQL,
5
+ FieldDocSubmissionDocumentGQL,
6
+ FieldDocSubmissionGQL,
7
+ FieldDocSubmissionsFilterArgs,
8
+ } from '@jsb188/mday/types/fieldDoc.d.ts';
9
+ import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
10
+ import { getFieldDocOrganizationScopedId } from '@jsb188/mday/utils/fieldDoc.ts';
11
+ import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '../client/index.ts';
12
+ import {
13
+ fieldDocEditSessionQry,
14
+ fieldDocProgramCatalogQry,
15
+ fieldDocProgramEnrollmentsQry,
16
+ fieldDocSubmissionDocumentQry,
17
+ fieldDocSubmissionsQry,
18
+ } from '../gql/queries/fieldDocQueries.ts';
19
+ import type { UseQueryParams } from '../types.d.ts';
20
+ import { useCallback, useEffect, useRef } from 'react';
21
+ import { getFieldDocSubmissionsVariables } from './use-fieldDoc-qry.helpers.ts';
22
+
23
+ /**
24
+ * Get reactive fieldDoc program fragment (org-agnostic program fields)
25
+ */
26
+
27
+ export function useReactiveFieldDocProgramFragment(fieldDocProgramId: string, currentData?: any, queryCount?: number) {
28
+ return useReactiveFragment(currentData, [makeFragmentKey(FRAGMENT_NAMES.fieldDocProgram, fieldDocProgramId)], queryCount);
29
+ }
30
+
31
+ /**
32
+ * Get reactive fieldDoc submission fragment; list rows and the document header share it
33
+ */
34
+
35
+ export function useReactiveFieldDocSubmissionFragment(fieldDocSubmissionId: string, currentData?: any, queryCount?: number) {
36
+ return useReactiveFragment(currentData, [makeFragmentKey(FRAGMENT_NAMES.fieldDocSubmission, fieldDocSubmissionId)], queryCount);
37
+ }
38
+
39
+ /**
40
+ * Get reactive answer fragments for a document's answers. The document returns one answer for every answer-bearing
41
+ * key (UNANSWERED included), so every key of the definition is observed.
42
+ */
43
+
44
+ export function useReactiveFieldDocAnswerFragmentMap(currentData?: any[] | null) {
45
+ return useReactiveFragmentMap(currentData || null, getFragmentBaseName(FRAGMENT_NAMES.fieldDocAnswer));
46
+ }
47
+
48
+ /**
49
+ * Fetch the organization's program enrollments: active ones plus archived ones that can still be restored, each with
50
+ * its program and forms. An optional program scope avoids loading unrelated enrollments. Uses the shared query
51
+ * freshness window; database notifications refresh active queries.
52
+ */
53
+
54
+ export function useFieldDocProgramEnrollments(
55
+ organizationId: string | null | undefined,
56
+ params: UseQueryParams & { fieldDocProgramId?: string | null } = {},
57
+ ) {
58
+ const { skip, fieldDocProgramId, ...restParams } = params;
59
+ const { data, ...rest } = useQuery(fieldDocProgramEnrollmentsQry, {
60
+ ...restParams,
61
+ variables: {
62
+ organizationId,
63
+ ...(fieldDocProgramId ? { fieldDocProgramId } : {}),
64
+ },
65
+ skip: skip || !organizationId,
66
+ });
67
+
68
+ return {
69
+ fieldDocProgramEnrollments: data?.fieldDocProgramEnrollments as FieldDocProgramEnrollmentGQL[] | null | undefined,
70
+ ...rest,
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Fetch the catalog programs offered to the organization's operation. Enrolled state comes from
76
+ * useFieldDocProgramEnrollments. Revalidates on entry to recover changes missed while disconnected.
77
+ */
78
+
79
+ export function useFieldDocProgramCatalog(organizationId: string | null | undefined, params: UseQueryParams = {}) {
80
+ const { skip, ...restParams } = params;
81
+ const { data, ...rest } = useQuery(fieldDocProgramCatalogQry, {
82
+ ...restParams,
83
+ persistTime: params.persistTime ?? 0,
84
+ variables: {
85
+ organizationId,
86
+ },
87
+ skip: skip || !organizationId,
88
+ });
89
+
90
+ return {
91
+ fieldDocProgramCatalog: data?.fieldDocProgramCatalog as FieldDocProgramGQL[] | null | undefined,
92
+ ...rest,
93
+ };
94
+ }
95
+
96
+ /**
97
+ * Fetch one owner organization's submissions, newest period first, with the logEntries cursor contract
98
+ * (getFieldDocSubmissionsVariables). fetchMore rebuilds its variables the same way, so route table extras
99
+ * (sort, URL-only filter keys) never reach the query.
100
+ */
101
+
102
+ export function useFieldDocSubmissions(
103
+ variables: {
104
+ organizationId?: string | null;
105
+ filter?: FieldDocSubmissionsFilterArgs | Record<string, any> | null;
106
+ },
107
+ params: UseQueryParams = {},
108
+ ) {
109
+ const { organizationId, filter } = variables;
110
+ const { skip, ...restParams } = params;
111
+ const { data, fetchMore, ...rest } = useQuery(fieldDocSubmissionsQry, {
112
+ ...restParams,
113
+ variables: getFieldDocSubmissionsVariables({ organizationId, filter }),
114
+ skip: skip || !organizationId || !filter,
115
+ });
116
+
117
+ /*
118
+ * Request one more page with the same declared variables as the first page; omitted ones keep the hook's values.
119
+ */
120
+ const fetchMoreSubmissions = useCallback(
121
+ (options: any) => {
122
+ return fetchMore({
123
+ ...options,
124
+ variables: getFieldDocSubmissionsVariables({ organizationId, filter, ...options?.variables }),
125
+ });
126
+ },
127
+ [fetchMore, filter, organizationId],
128
+ );
129
+
130
+ return {
131
+ fieldDocSubmissions: data?.fieldDocSubmissions as FieldDocSubmissionGQL[] | null | undefined,
132
+ fetchMore: fetchMoreSubmissions,
133
+ ...rest,
134
+ };
135
+ }
136
+
137
+ /**
138
+ * Fetch one submission's document: the submission, its pinned definition, every answer and the aside
139
+ */
140
+
141
+ export function useFieldDocSubmissionDocument(fieldDocSubmissionId: string | null | undefined, params: UseQueryParams = {}) {
142
+ const { skip, ...restParams } = params;
143
+ const { data, ...rest } = useQuery(fieldDocSubmissionDocumentQry, {
144
+ ...restParams,
145
+ variables: {
146
+ fieldDocSubmissionId,
147
+ },
148
+ skip: skip || !fieldDocSubmissionId,
149
+ });
150
+
151
+ return {
152
+ fieldDocSubmissionDocument: data?.fieldDocSubmissionDocument as FieldDocSubmissionDocumentGQL | null | undefined,
153
+ ...rest,
154
+ };
155
+ }
156
+
157
+ /**
158
+ * Fetch one form's web editor session for an organization. The session is read through its fragment, so an
159
+ * editFieldDocCustomInstructions result (same selection, same id) updates it without a refetch. Reconnects refetch
160
+ * it, since realtime resets sent while offline are lost. editable means the viewer can change the form's structure:
161
+ * a custom doc and an organization manager.
162
+ */
163
+
164
+ export function useFieldDocEditSession(
165
+ variables: {
166
+ organizationId?: string | null;
167
+ fieldDocId?: string | null;
168
+ },
169
+ params: UseQueryParams = {},
170
+ ) {
171
+ const { organizationId, fieldDocId } = variables;
172
+ const enabled = !params.skip && !!organizationId && !!fieldDocId;
173
+ const { data, refetch, ...rest } = useQuery(fieldDocEditSessionQry, {
174
+ retryTransientErrors: true,
175
+ ...params,
176
+ variables: {
177
+ organizationId,
178
+ fieldDocId,
179
+ },
180
+ skip: !enabled,
181
+ });
182
+ const wasConnected = useRef(rest.connectedToServer);
183
+ const sessionId = organizationId && fieldDocId ? getFieldDocOrganizationScopedId(organizationId, fieldDocId) : '';
184
+ const fieldDocEditSession = useReactiveFragment(
185
+ data?.fieldDocEditSession || null,
186
+ sessionId ? [makeFragmentKey(FRAGMENT_NAMES.fieldDocEditSession, sessionId)] : [],
187
+ rest.updatedCount,
188
+ ) as FieldDocEditSessionGQL | null;
189
+
190
+ /*
191
+ * Refetch once after the realtime connection comes back.
192
+ */
193
+ useEffect(() => {
194
+ const reconnected = rest.connectedToServer && !wasConnected.current;
195
+ wasConnected.current = rest.connectedToServer;
196
+ if (enabled && reconnected) {
197
+ void refetch().catch(() => {
198
+ // Query state owns the load error; do not create an unhandled reconnect rejection.
199
+ });
200
+ }
201
+ }, [enabled, refetch, rest.connectedToServer]);
202
+
203
+ const manageable = Boolean(fieldDocEditSession?.manageable);
204
+
205
+ return {
206
+ fieldDocEditSession,
207
+ editable: manageable && fieldDocEditSession?.fieldDoc?.isProgramDoc === false,
208
+ manageable,
209
+ refetch,
210
+ ...rest,
211
+ };
212
+ }
@@ -8,24 +8,27 @@ import { useMutation } from './index.ts';
8
8
  */
9
9
 
10
10
  export function useEditInboundContact(
11
- params: UseMutationParams = {},
12
- openModalPopUp?: OpenModalPopUpFn,
11
+ params: UseMutationParams = {},
12
+ openModalPopUp?: OpenModalPopUpFn,
13
13
  ) {
14
- const { onCompleted, ...rest } = params;
14
+ const { onCompleted, ...rest } = params;
15
15
 
16
- const [editInboundContact, mtnValues, mtnHandlers] = useMutation(editInboundContactMtn, {
17
- openModalPopUp,
18
- onCompleted: (data, error, variables) => {
19
- const updatedInboundContact = data?.editInboundContact;
16
+ const [editInboundContact, mtnValues, mtnHandlers] = useMutation(
17
+ editInboundContactMtn,
18
+ {
19
+ openModalPopUp,
20
+ onCompleted: (data, error, variables) => {
21
+ const updatedInboundContact = data?.editInboundContact;
20
22
 
21
- onCompleted?.(updatedInboundContact, error, variables);
22
- },
23
- ...rest,
24
- });
23
+ onCompleted?.(updatedInboundContact, error, variables);
24
+ },
25
+ ...rest,
26
+ },
27
+ );
25
28
 
26
- return {
27
- editInboundContact,
28
- ...mtnValues,
29
- ...mtnHandlers,
30
- };
29
+ return {
30
+ editInboundContact,
31
+ ...mtnValues,
32
+ ...mtnHandlers,
33
+ };
31
34
  }