@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
package/audience.d.ts ADDED
@@ -0,0 +1,343 @@
1
+ import type { PaginationArgs } from './types.d.ts';
2
+
3
+ export type AudienceListsSort = 'CREATED_ASC' | 'CREATED_DESC';
4
+ export type AudienceListMembersSort = AudienceListsSort;
5
+
6
+ export interface AudienceListsFilter {
7
+ ids?: readonly string[] | null;
8
+ includeArchived?: boolean;
9
+ search?: string | null;
10
+ }
11
+
12
+ export interface AudienceListMembersFilter {
13
+ audienceListId?: string | null;
14
+ subscriptionStatus?: AudienceSubscriptionStatus | null;
15
+ includeRemoved?: boolean;
16
+ search?: string | null;
17
+ }
18
+
19
+ export type CampaignAudienceEligibility = 'ALL' | 'ELIGIBLE' | 'EXCLUDED';
20
+ export type CampaignAudienceMembersSort = 'EMAIL_ASC' | 'EMAIL_DESC';
21
+
22
+ export interface CampaignAudienceMembersFilter {
23
+ eligibility?: CampaignAudienceEligibility | null;
24
+ subscriptionStatus?: AudienceSubscriptionStatus | null;
25
+ audienceListId?: string | null;
26
+ search?: string | null;
27
+ }
28
+
29
+ export type CampaignAudienceMembersArgs = {
30
+ organizationId?: string | null;
31
+ campaignId?: string | null;
32
+ filter?: CampaignAudienceMembersFilter | null;
33
+ sort?: CampaignAudienceMembersSort | null;
34
+ } & PaginationArgs;
35
+
36
+ export type AudienceListsArgs = {
37
+ organizationId?: string | null;
38
+ filter?: AudienceListsFilter | null;
39
+ sort?: AudienceListsSort | null;
40
+ } & PaginationArgs;
41
+
42
+ export type AudienceListMembersArgs = {
43
+ organizationId?: string | null;
44
+ filter: AudienceListMembersFilter;
45
+ sort?: AudienceListMembersSort | null;
46
+ } & PaginationArgs;
47
+
48
+ export type AudienceSubscriptionStatus =
49
+ | 'NON_SUBSCRIBED'
50
+ | 'PENDING'
51
+ | 'SUBSCRIBED'
52
+ | 'UNSUBSCRIBED';
53
+ export type AudienceDeliveryStatus =
54
+ | 'UNKNOWN'
55
+ | 'DELIVERABLE'
56
+ | 'SOFT_BOUNCING'
57
+ | 'CLEANED';
58
+ export type AudienceImportSource = 'MANUAL' | 'IMPORT' | 'INTEGRATION';
59
+ export type AudienceConsentSource =
60
+ | 'EXISTING_PERMISSION'
61
+ | 'SIGNUP'
62
+ | 'RECIPIENT_RESUBSCRIBE';
63
+ export type AudienceSuppressionKind =
64
+ | 'MANUAL'
65
+ | 'COMPLAINT'
66
+ | 'CLEANED'
67
+ | 'PROVIDER';
68
+
69
+ export interface AudiencePageArgs {
70
+ afterId?: string | null;
71
+ limit?: number | null;
72
+ }
73
+
74
+ export interface AudienceListGQL {
75
+ id: string;
76
+ cursor: string;
77
+ organizationId: string;
78
+ name: string;
79
+ description: string | null;
80
+ archivedAt: string | null;
81
+ editVersion: string;
82
+ createdByAccountId: string | null;
83
+ createdAt: string;
84
+ updatedAt: string;
85
+ // Active member count; selected by `audienceLists` only, never by the shared fragment.
86
+ count?: number;
87
+ }
88
+
89
+ export interface AudienceConsentInput {
90
+ source: AudienceConsentSource;
91
+ recordedAt: string;
92
+ permissionSource: string;
93
+ }
94
+
95
+ export interface AudienceMemberDetails {
96
+ personName?: string | null;
97
+ provenance?: {
98
+ source?: AudienceImportSource;
99
+ actorAccountId?: string;
100
+ importRequestId?: string;
101
+ };
102
+ consent?: AudienceConsentInput & { actorAccountId?: string };
103
+ [key: string]: unknown;
104
+ }
105
+
106
+ export interface AudienceAddressDetails {
107
+ preferenceSource?: string;
108
+ lastBounce?: {
109
+ type?: string | null;
110
+ code?: string | number | null;
111
+ reason?: string | null;
112
+ };
113
+ manualSuppression?: {
114
+ reason?: string;
115
+ actorAccountId?: string;
116
+ active?: boolean;
117
+ };
118
+ [key: string]: unknown;
119
+ }
120
+
121
+ export interface AudienceEmailAddressGQL {
122
+ id: string;
123
+ organizationId: string;
124
+ normalizedEmail: string;
125
+ inboundContactId: string | null;
126
+ campaignStatus: 'OPTED_IN' | 'OPTED_OUT' | null;
127
+ campaignStatusAt: string | null;
128
+ deliveryStatus: AudienceDeliveryStatus;
129
+ deliveryStatusAt: string | null;
130
+ cleanedReason:
131
+ | 'HARD_BOUNCE'
132
+ | 'INVALID_ADDRESS'
133
+ | 'REPEATED_SOFT_BOUNCE'
134
+ | null;
135
+ lastDeliveredAt: string | null;
136
+ lastBounceAt: string | null;
137
+ consecutiveSoftBounceCount: number;
138
+ complaintSuppressedAt: string | null;
139
+ manuallySuppressedAt: string | null;
140
+ details: AudienceAddressDetails;
141
+ createdAt: string;
142
+ updatedAt: string;
143
+ }
144
+
145
+ export interface AudienceListMemberGQL {
146
+ id: string;
147
+ cursor: string;
148
+ organizationId: string;
149
+ audienceListId: string;
150
+ emailAddressId: string;
151
+ subscriptionStatus: AudienceSubscriptionStatus;
152
+ subscriptionStatusAt: string;
153
+ subscriptionVersion: string;
154
+ removedAt: string | null;
155
+ details: AudienceMemberDetails;
156
+ address?: AudienceEmailAddressGQL | null;
157
+ createdAt: string;
158
+ updatedAt: string;
159
+ }
160
+
161
+ export interface CampaignAudienceMembershipGQL {
162
+ memberId: string;
163
+ audienceListId: string;
164
+ listName: string;
165
+ personName: string | null;
166
+ subscriptionStatus: AudienceSubscriptionStatus;
167
+ subscriptionVersion: string;
168
+ removedAt: string | null;
169
+ }
170
+
171
+ export interface CampaignAudienceMemberGQL {
172
+ id: string;
173
+ cursor: string;
174
+ organizationId: string;
175
+ campaignId: string;
176
+ emailAddressId: string;
177
+ normalizedEmail: string;
178
+ personName: string | null;
179
+ inboundContactId: string | null;
180
+ reason: string | null;
181
+ memberships: CampaignAudienceMembershipGQL[];
182
+ address?: AudienceEmailAddressGQL | null;
183
+ }
184
+
185
+ export interface AudienceListOverviewGQL {
186
+ total: number;
187
+ subscribed: number;
188
+ unsubscribed: number;
189
+ nonSubscribed: number;
190
+ pending: number;
191
+ cleaned: number;
192
+ eligible: number;
193
+ }
194
+
195
+ export interface AudienceEventGQL {
196
+ id: string;
197
+ organizationId: string;
198
+ normalizedEmail: string | null;
199
+ emailAddressId: string | null;
200
+ audienceListId: string | null;
201
+ audienceListMemberId: string | null;
202
+ eventType: string;
203
+ source: string;
204
+ actorAccountId: string | null;
205
+ campaignId: string | null;
206
+ outboundEmailId: string | null;
207
+ metadata: Record<string, unknown>;
208
+ occurredAt: string;
209
+ createdAt: string;
210
+ }
211
+
212
+ export interface AudienceMemberImportResultGQL {
213
+ index: number;
214
+ emailAddress: string;
215
+ outcome:
216
+ | 'ADDED'
217
+ | 'RESTORED'
218
+ | 'UPDATED'
219
+ | 'ALREADY_PRESENT'
220
+ | 'PRESERVED_UNSUBSCRIBE'
221
+ | 'INVALID'
222
+ | 'CONSENT_MISSING'
223
+ | 'DUPLICATE';
224
+ memberId: string | null;
225
+ }
226
+
227
+ export interface AudienceMemberInput {
228
+ emailAddress: string;
229
+ personName?: string | null;
230
+ inboundContactId?: string | null;
231
+ // Imports intentionally cannot set pending or override an unsubscribe.
232
+ subscriptionStatus?: 'NON_SUBSCRIBED' | 'SUBSCRIBED';
233
+ consent?: AudienceConsentInput | null;
234
+ }
235
+
236
+ export interface CreateAudienceListInput {
237
+ organizationId: string;
238
+ name: string;
239
+ description?: string | null;
240
+ }
241
+
242
+ export interface EditAudienceListInput {
243
+ organizationId: string;
244
+ audienceListId: string;
245
+ expectedEditVersion: string;
246
+ name?: string;
247
+ description?: string | null;
248
+ archived?: boolean;
249
+ }
250
+
251
+ export interface AddAudienceListMembersInput {
252
+ organizationId: string;
253
+ audienceListId: string;
254
+ idempotencyKey: string;
255
+ source: AudienceImportSource;
256
+ members: AudienceMemberInput[];
257
+ }
258
+
259
+ export interface ChangeAudienceListSubscriptionInput {
260
+ organizationId: string;
261
+ audienceListId: string;
262
+ memberId: string;
263
+ expectedSubscriptionVersion: string;
264
+ subscribed: boolean;
265
+ consent?: AudienceConsentInput | null;
266
+ }
267
+
268
+ export interface EditAudienceListMemberInput {
269
+ organizationId: string;
270
+ audienceListId: string;
271
+ memberId: string;
272
+ expectedSubscriptionVersion: string;
273
+ personName?: string | null;
274
+ // Staff may only set NON_SUBSCRIBED or SUBSCRIBED; subscribing requires consent.
275
+ subscriptionStatus?: AudienceSubscriptionStatus | null;
276
+ consent?: AudienceConsentInput | null;
277
+ }
278
+
279
+ export interface RemoveAudienceListMembersInput {
280
+ organizationId: string;
281
+ audienceListId: string;
282
+ memberIds: string[];
283
+ }
284
+
285
+ export interface SetAudienceAddressSuppressionInput {
286
+ organizationId: string;
287
+ emailAddressId: string;
288
+ suppression: AudienceSuppressionKind;
289
+ suppressed: boolean;
290
+ reason: string;
291
+ }
292
+
293
+ export interface CampaignAudienceSessionGQL {
294
+ // Campaign id; keys the cached session fragment.
295
+ id: string;
296
+ campaignId: string;
297
+ organizationId: string;
298
+ editVersion: number;
299
+ editable: boolean;
300
+ selectedAudienceListIds: string[];
301
+ // Addresses skipped for this campaign only; they remain members of their lists.
302
+ excludedEmailAddressIds: string[];
303
+ }
304
+
305
+ // The limits the server enforces when a campaign is sent now.
306
+ export interface CampaignEmailSendLimitsGQL {
307
+ // Recipients one campaign may send to.
308
+ recipientLimit: number;
309
+ monthlyRecipientLimit: number;
310
+ // Recipients this campaign can still send to in the current UTC month.
311
+ monthlyRecipientsRemaining: number;
312
+ sendingPaused: boolean;
313
+ }
314
+
315
+ export interface CampaignAudiencePreviewGQL {
316
+ // Campaign id; keys the cached preview fragment.
317
+ id: string;
318
+ campaignId: string;
319
+ editVersion: number;
320
+ selectedCount: number;
321
+ eligibleCount: number;
322
+ duplicateCount: number;
323
+ excludedCount: number;
324
+ exclusions: Array<{ reason: string; count: number }>;
325
+ // Recipients frozen when the campaign was scheduled or sent; 0 for a draft.
326
+ frozenRecipientCount: number;
327
+ sendLimits: CampaignEmailSendLimitsGQL;
328
+ }
329
+
330
+ // Returned by both the campaignAudience query and the setCampaignAudience mutation.
331
+ export interface CampaignAudienceSelectionGQL {
332
+ session: CampaignAudienceSessionGQL;
333
+ preview: CampaignAudiencePreviewGQL;
334
+ }
335
+
336
+ // Each set replaces the whole server-side set when present and is left unchanged when omitted.
337
+ export interface SetCampaignAudienceInput {
338
+ organizationId: string;
339
+ campaignId: string;
340
+ expectedEditVersion: number;
341
+ audienceListIds?: string[];
342
+ excludedEmailAddressIds?: string[];
343
+ }
package/cache/config.ts CHANGED
@@ -1,68 +1,116 @@
1
+ import { FRAGMENT_NAMES, getFragmentBaseName } from '@jsb188/mday/constants/graphqlReactivity.ts';
1
2
 
2
3
  /**
3
4
  * Rules for GraphQL server that's hard-coded to this package
4
5
  * NOTE: Allow config setup for this later
5
6
  */
6
7
 
8
+ /**
9
+ * Version of the persisted cache record layout. Bump when the shape of what
10
+ * the cache stores changes incompatibly; a mismatch wipes the IndexedDB
11
+ * snapshot on boot. (Stale-but-compatible data self-heals at read time via
12
+ * fetchCachedData's selection completeness check.)
13
+ *
14
+ * 10: exact JSON variable keys replace lossy lowercased keys; nullable nested
15
+ * selections and lists preserve the server's null and empty values.
16
+ *
17
+ * 11: field doc programs. $fieldDocFragment now holds the form instead of a
18
+ * filled document, and submission, answer and edit-session ids changed, so
19
+ * the old field doc records are dropped instead of lingering as orphans.
20
+ */
21
+
22
+ export const CACHE_SCHEMA_VERSION = 11;
23
+
7
24
  export const QUERY_EXPIRE_TIMES = {
8
- __default: 5.4e+6, // 1.5 hours
9
- // 6.48e+7, // 18 hours
25
+ __default: 1.08e7, // 3 hours
26
+ myOrganizations: 15 * 60 * 1000,
27
+ // 5.4e+6, // 1.5 hours
28
+ // 2.88e+7, // 8 hours
29
+ // 6.48e+7, // 18 hours
30
+
31
+ // Campaign metrics are live operational data. Realtime resets keep mounted
32
+ // lists current, while this short fallback repairs missed websocket events.
33
+ campaigns: 60 * 1000,
34
+ emailCampaignReplyReport: 60 * 1000,
35
+
36
+ // Note edits use fragments; short freshness windows recover missed events on revisit.
37
+ agentNote: 60 * 1000,
38
+ agentNotes: 60 * 1000,
39
+ searchAgentNotes: 60 * 1000,
40
+
41
+ // Sheets
42
+ sheets: 1.08e7,
43
+ sheetAccess: 2.88e7,
44
+ // Form definitions should refresh quickly between modal sessions without
45
+ // becoming stale again during the same render pass.
46
+ sheetWebFormResultsSource: 1000,
47
+ sheetAccessGrants: 2.88e7,
48
+ openSheet: 2.88e7,
49
+
50
+ // Data tables change through agents, workflows and source sync. Fragments and
51
+ // resets keep mounted views current. After missed events, short freshness
52
+ // windows refetch on focus, reconnect or the next mount; a mounted rows list
53
+ // is rebuilt only by a reset or its RESET_ONLY notice.
54
+ dataTables: 60 * 1000,
55
+ dataTable: 60 * 1000,
56
+ dataTableRows: 60 * 1000,
57
+ dataTableRuns: 60 * 1000,
10
58
  } as {
11
- [key: string]: number;
59
+ [key: string]: number;
12
60
  };
13
61
 
14
62
  export const RULES = {
15
- // __limit: 8000, // 8000: approximately 5.15 MB; calculated at 644.666666668 bytes for 30 objects
16
- __limit: 100000, // 12000: approximately 7.725 MB; calculated at 644.666666668 bytes for 30 objects
17
- // __limit: 50, // 12000: approximately 7.725 MB; calculated at 644.666666668 bytes for 30 objects
63
+ // __limit: 8000, // 8000: approximately 5.15 MB; calculated at 644.666666668 bytes for 30 objects
64
+ __limit: 100000, // 12000: approximately 7.725 MB; calculated at 644.666666668 bytes for 30 objects
65
+ // __limit: 50, // 12000: approximately 7.725 MB; calculated at 644.666666668 bytes for 30 objects
18
66
 
19
- // List of queries that should be cached
20
- // NOTE: Fragments are always cached
21
- aiChat: true,
22
- aiChats: true,
23
- aiChatMessages: true,
24
- alerts: true,
25
- chat: true,
26
- chatsList: true,
27
- childOrganizations: true,
28
- eventsList: true,
29
- eventAttendanceList: true,
30
- integrationConnection: true,
31
- parentOrganization: true,
32
- logEntry: true,
33
- logEntries: true,
34
- logEntriesForReport: true,
35
- myChats: true,
36
- myOrganizations: true,
37
- organizationMembers: true,
38
- organizationRelationship: true,
39
- organizationSites: true,
40
- platformProducts: true,
41
- productsList: true,
42
- report: true,
43
- reportGroups: true,
44
- reports: true,
45
- reportSubmissions: true,
46
- dataTables: true,
47
- dataTableRows: true,
48
- sheets: true,
49
- sheet: true,
50
- sheetGrid: true,
51
- searchUsers: true,
52
- updateNote: true,
53
- userIdToChatId: true,
54
- workflows: true,
67
+ // NOTE: ALL fragments are cached by default,
68
+ // but if you want to skip some, add it here
69
+ accountAuthFragment: false,
55
70
 
56
- // All fragments are cached,
57
- // but if you want to skip some, add it here
58
- accountAuthFragment: false,
71
+ // Editor and access sessions contain heavy mutable trees or short-lived
72
+ // authorization state. Keep normalized core fragments, but never persist
73
+ // the root session response across unmounts.
74
+ campaignEditSession: false,
75
+ // Reply identities and captured answers live only in the mounted report hook.
76
+ emailCampaignReplyReport: false,
77
+ campaignFormAccessSession: false,
78
+ campaignTemplateEditSession: false,
79
+ // Typeahead prefixes live only in the mounted hook; note fragments remain shared.
80
+ searchAgentNotes: false,
81
+ // Billing payment-form inputs: the Stripe key and tax previews must be
82
+ // fetched fresh for each payment form, never replayed from disk.
83
+ billingClientConfig: false,
84
+ billingPurchasePreview: false,
85
+ // NOTE: ALL queries are cached by default,
86
+ // but if you want to skip some, add it here
87
+ // e.g.: someQueryName: false,
88
+
89
+ // Respondent identity travels via header/cookie (not query variables), so
90
+ // the cache key cannot distinguish viewers; never cache per-viewer results
59
91
  } as {
60
- __limit: number;
61
- [key: string]: boolean | number;
92
+ __limit: number;
93
+ [key: string]: boolean | number;
62
94
  };
63
95
 
64
96
  export const PARTIALS_MAP = {
65
- // Partial fragments are supported if you map them to its original fragment name
66
- chatPartial: 'chatFragment',
67
- chatStatusPartial: 'chatFragment',
97
+ // Partial fragments are supported if you map them to its original fragment name
98
+ sheetViewPatchFragment: getFragmentBaseName(FRAGMENT_NAMES.sheetView),
99
+ // List rows are narrower projections of the same records. Map them to the
100
+ // canonical fragment keys so realtime core patches update both detail and
101
+ // summary consumers without duplicating fragment authorities.
102
+ campaignTemplateSummaryFragment: getFragmentBaseName(FRAGMENT_NAMES.campaignTemplate),
103
+ campaignTemplateLifecycleFragment: getFragmentBaseName(FRAGMENT_NAMES.campaignTemplate),
104
+ campaignAccessFragment: getFragmentBaseName(FRAGMENT_NAMES.campaign),
105
+ campaignGenerationLifecycleFragment: getFragmentBaseName(FRAGMENT_NAMES.campaign),
106
+ campaignLifecycleFragment: getFragmentBaseName(FRAGMENT_NAMES.campaign),
107
+ campaignSettingsFragment: getFragmentBaseName(FRAGMENT_NAMES.campaign),
108
+ campaignSummaryFragment: getFragmentBaseName(FRAGMENT_NAMES.campaign),
109
+ // The note detail projection shares the realtime agentNoteFragment identity
110
+ agentNoteDetailFragment: getFragmentBaseName(FRAGMENT_NAMES.agentNote),
111
+ emailMessageDetailsFragment: getFragmentBaseName(FRAGMENT_NAMES.emailMessage),
68
112
  } as Record<string, string>;
113
+
114
+ export const PARTIAL_NULL_PRESERVE_FIELDS = {
115
+ sheetViewPatchFragment: ['sheetTab'],
116
+ } as Record<string, string[]>;
@@ -0,0 +1,119 @@
1
+ import { makeGraphQLVariablesKey } from '@jsb188/app/utils/logic.ts';
2
+ import { makeQueryResetTarget } from '@jsb188/app/utils/queryReset.ts';
3
+ import { getActiveAIChatsByActivity, getAIChatActivityOrder } from '@jsb188/mday/utils/aiChat.ts';
4
+ import { aiChatQry, aiChatsQry } from '../gql/queries/aiChatQueries.ts';
5
+ import {
6
+ clearGraphQLClientCache,
7
+ loadFragment,
8
+ loadQuery,
9
+ resetQueryByTargetIfFragmentsMissing,
10
+ setDataToCache,
11
+ updateFragment,
12
+ } from './index.ts';
13
+
14
+ if (typeof (console as any).dev !== 'function') (console as any).dev = () => {};
15
+
16
+ /* Fail with the actual value when cache behavior differs from the expected result. */
17
+ function assertEqual(actual: unknown, expected: unknown) {
18
+ if (JSON.stringify(actual) !== JSON.stringify(expected))
19
+ throw new Error(`Expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
20
+ }
21
+
22
+ /* Build the exact sidebar variables used by the mounted query. */
23
+ function sidebarVariables(organizationId = 'org') {
24
+ return { organizationId, filter: 'CHATS', cursor: null, after: false, limit: 70 };
25
+ }
26
+
27
+ /* Seed a small authoritative sidebar snapshot with opaque identifiers. */
28
+ function seedSidebar(organizationId = 'org') {
29
+ const chats = [
30
+ { id: 'opaque-a', updatedAt: '2026-10-04T12:00:00.000Z', activityOrder: getAIChatActivityOrder('2026-10-04T12:00:00.000Z', 9) },
31
+ { id: 'opaque-z', updatedAt: '2026-10-04T11:00:00.000Z', activityOrder: getAIChatActivityOrder('2026-10-04T11:00:00.000Z', 10) },
32
+ ];
33
+ setDataToCache({ aiChats: chats }, aiChatsQry, sidebarVariables(organizationId));
34
+ return chats;
35
+ }
36
+
37
+ Deno.test('listed chat activity reorders immediately without requesting any query reset', () => {
38
+ clearGraphQLClientCache();
39
+ seedSidebar();
40
+ const events: unknown[] = [];
41
+ resetQueryByTargetIfFragmentsMissing(
42
+ makeQueryResetTarget('aiChats', { organizationId: 'org', filter: 'CHATS' }),
43
+ ['$aiChatFragment:opaque-z'],
44
+ (event) => events.push(event),
45
+ );
46
+ assertEqual(events, []);
47
+ updateFragment('$aiChatFragment:opaque-z', {
48
+ updatedAt: '2026-10-04T13:00:00.000Z',
49
+ activityOrder: getAIChatActivityOrder('2026-10-04T13:00:00.000Z', 10),
50
+ });
51
+ const chats = loadQuery(`#aiChats:${makeGraphQLVariablesKey(sidebarVariables())}`);
52
+ assertEqual(
53
+ getActiveAIChatsByActivity(chats).map((chat: any) => chat.id),
54
+ ['opaque-z', 'opaque-a'],
55
+ );
56
+ assertEqual(
57
+ chats.map((chat: any) => chat.id),
58
+ ['opaque-a', 'opaque-z'],
59
+ );
60
+ });
61
+
62
+ Deno.test('a globally cached chat outside the sidebar resets only that organization list', () => {
63
+ clearGraphQLClientCache();
64
+ seedSidebar();
65
+ seedSidebar('other');
66
+ setDataToCache({ aiChat: { id: 'outside', updatedAt: '2026-10-04T13:00:00.000Z' } }, aiChatQry, { aiChatId: 'outside' });
67
+ const events: any[] = [];
68
+ resetQueryByTargetIfFragmentsMissing(
69
+ makeQueryResetTarget('aiChats', { organizationId: 'org', filter: 'CHATS' }),
70
+ ['$aiChatFragment:outside'],
71
+ (event) => events.push(event),
72
+ );
73
+ assertEqual(
74
+ events.map((event) => ({ queryId: event.queryId, forceRefetch: event.forceRefetch })),
75
+ [
76
+ {
77
+ queryId: `#aiChats:${makeGraphQLVariablesKey(sidebarVariables())}`,
78
+ forceRefetch: true,
79
+ },
80
+ ],
81
+ );
82
+ });
83
+
84
+ Deno.test('a missing chat and an in-flight initial sidebar snapshot both request recovery', () => {
85
+ clearGraphQLClientCache();
86
+ const target = makeQueryResetTarget('aiChats', { organizationId: 'org', filter: 'CHATS' });
87
+ const events: any[] = [];
88
+ resetQueryByTargetIfFragmentsMissing(target, ['$aiChatFragment:new'], (event) => events.push(event));
89
+ assertEqual(events[0]?.queryTarget, target);
90
+ seedSidebar();
91
+ resetQueryByTargetIfFragmentsMissing(target, ['$aiChatFragment:new'], (event) => events.push(event));
92
+ assertEqual(events.length, 2);
93
+ });
94
+
95
+ Deno.test('late queries and realtime metadata cannot move a chat back to older activity', () => {
96
+ clearGraphQLClientCache();
97
+ const stale = seedSidebar();
98
+ const fresh = { updatedAt: '2026-10-04T13:00:00.000Z', activityOrder: getAIChatActivityOrder('2026-10-04T13:00:00.000Z', 10) };
99
+ updateFragment('$aiChatFragment:opaque-z', fresh);
100
+ setDataToCache({ aiChats: stale }, aiChatsQry, sidebarVariables());
101
+ updateFragment('$aiChatFragment:opaque-z', { ...stale[1], summary: 'New title' });
102
+ const chat = loadFragment('$aiChatFragment:opaque-z');
103
+ assertEqual(
104
+ { updatedAt: chat.updatedAt, activityOrder: chat.activityOrder, summary: chat.summary },
105
+ { ...fresh, summary: 'New title' },
106
+ );
107
+ });
108
+
109
+ Deno.test('timestamp ties use database id order rather than scrambled GenericID order', () => {
110
+ const updatedAt = '2026-10-04T13:00:00.000Z';
111
+ assertEqual(
112
+ getActiveAIChatsByActivity([
113
+ { id: 'zzz', updatedAt, activityOrder: getAIChatActivityOrder(updatedAt, 9) },
114
+ { id: 'aaa', updatedAt, activityOrder: getAIChatActivityOrder(updatedAt, 10) },
115
+ { id: 'archived', updatedAt, archivedAt: updatedAt, activityOrder: getAIChatActivityOrder(updatedAt, 11) },
116
+ ]).map((chat) => chat.id),
117
+ ['aaa', 'zzz'],
118
+ );
119
+ });