@jsb188/graphql 1.1.11 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/LICENSE +21 -0
  2. package/audience.d.ts +205 -0
  3. package/cache/config.ts +65 -28
  4. package/cache/index.helpers.ts +96 -0
  5. package/cache/index.ts +364 -808
  6. package/cache/mounted-queries.ts +33 -0
  7. package/cache/optimistic-ui-runtime.ts +46 -0
  8. package/cache/optimistic-ui.ts +401 -0
  9. package/cache/persist.ts +107 -22
  10. package/cache/realtime-fence.ts +47 -0
  11. package/cache/realtime-live.ts +17 -0
  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} +13 -39
  16. package/client/index.ts +4 -2
  17. package/client/request.helpers.ts +14 -0
  18. package/client/request.ts +122 -232
  19. package/client/storage-asset.ts +58 -0
  20. package/gql/fragments/accountAuthFragments.ts +0 -4
  21. package/gql/fragments/agentMemoryFragments.ts +5 -1
  22. package/gql/fragments/agentNoteFragments.ts +156 -0
  23. package/gql/fragments/aiChatFragments.ts +35 -11
  24. package/gql/fragments/aiChatLinkFragments.ts +8 -0
  25. package/gql/fragments/audienceFragments.ts +76 -0
  26. package/gql/fragments/dataTableFragments.ts +48 -80
  27. package/gql/fragments/emailFragments.ts +49 -21
  28. package/gql/fragments/emailOutreachFragments.ts +281 -0
  29. package/gql/fragments/fieldDocFragments.ts +222 -40
  30. package/gql/fragments/inboundContactFragments.ts +2 -0
  31. package/gql/fragments/libraryFragments.ts +120 -0
  32. package/gql/fragments/logFragments.ts +93 -2
  33. package/gql/fragments/organizationFragments.ts +12 -0
  34. package/gql/fragments/qrCodeFragments.ts +29 -0
  35. package/gql/fragments/scheduleFragments.ts +574 -145
  36. package/gql/fragments/sheetFragments.ts +86 -424
  37. package/gql/fragments/storageFragments.ts +25 -1
  38. package/gql/fragments/workWaitFragments.ts +13 -0
  39. package/gql/fragments/workflowFragments.ts +32 -4
  40. package/gql/mutations/agentMemoryMutations.ts +32 -0
  41. package/gql/mutations/agentNoteMutations.ts +64 -0
  42. package/gql/mutations/aiChatLinkMutations.ts +13 -0
  43. package/gql/mutations/aiChatMutations.ts +34 -4
  44. package/gql/mutations/audienceMutations.ts +58 -0
  45. package/gql/mutations/authMutations.ts +24 -28
  46. package/gql/mutations/billingMutations.ts +24 -0
  47. package/gql/mutations/contactMutations.ts +23 -0
  48. package/gql/mutations/dataTableMutations.ts +18 -75
  49. package/gql/mutations/emailMutations.ts +22 -0
  50. package/gql/mutations/emailOutreachMutations.ts +139 -0
  51. package/gql/mutations/fieldDocMutations.ts +162 -13
  52. package/gql/mutations/index.ts +10 -5
  53. package/gql/mutations/organizationMutations.ts +6 -0
  54. package/gql/mutations/qrCodeMutations.ts +20 -0
  55. package/gql/mutations/scheduleMutations.ts +389 -417
  56. package/gql/mutations/sheetMutations.ts +62 -118
  57. package/gql/mutations/storageMutations.ts +1 -1
  58. package/gql/mutations/workflowMutations.ts +94 -0
  59. package/gql/queries/agentMemoryQueries.ts +12 -2
  60. package/gql/queries/agentNoteQueries.ts +86 -0
  61. package/gql/queries/aiChatQueries.ts +63 -12
  62. package/gql/queries/audienceQueries.ts +104 -0
  63. package/gql/queries/authQueries.ts +20 -4
  64. package/gql/queries/billingQueries.ts +114 -9
  65. package/gql/queries/dataTableQueries.ts +43 -75
  66. package/gql/queries/emailOutreachQueries.ts +282 -0
  67. package/gql/queries/emailQueries.ts +48 -64
  68. package/gql/queries/emailReplyReportQueries.ts +127 -0
  69. package/gql/queries/fieldDocQueries.ts +128 -98
  70. package/gql/queries/inboundContactQueries.ts +15 -4
  71. package/gql/queries/index.ts +5 -3
  72. package/gql/queries/libraryQueries.ts +112 -0
  73. package/gql/queries/logQueries.ts +86 -12
  74. package/gql/queries/organizationQueries.ts +44 -12
  75. package/gql/queries/qrCodeQueries.ts +27 -0
  76. package/gql/queries/scheduleQueries.ts +401 -278
  77. package/gql/queries/sheetQueries.ts +94 -165
  78. package/gql/queries/storageQueries.ts +11 -4
  79. package/gql/queries/workflowQueries.ts +61 -12
  80. package/gql/reactivity.ts +98 -0
  81. package/gql/recordReads.ts +171 -0
  82. package/hooks/index.helpers.ts +52 -0
  83. package/hooks/index.ts +920 -715
  84. package/hooks/use-agentMemory-mtn.ts +29 -31
  85. package/hooks/use-agentMemory-qry.ts +15 -3
  86. package/hooks/use-agentNote-mtn.ts +89 -0
  87. package/hooks/use-agentNote-qry.ts +162 -0
  88. package/hooks/use-agentNote-recovery.helpers.ts +58 -0
  89. package/hooks/use-agentNote-recovery.ts +57 -0
  90. package/hooks/use-aiChat-mtn.ts +104 -115
  91. package/hooks/use-aiChat-qry.helpers.ts +124 -0
  92. package/hooks/use-aiChat-qry.ts +254 -387
  93. package/hooks/use-aiChat-stream-mtn.ts +14 -0
  94. package/hooks/use-audience-mtn.ts +170 -0
  95. package/hooks/use-audience-qry.helpers.ts +39 -0
  96. package/hooks/use-audience-qry.ts +245 -0
  97. package/hooks/use-auth-mtn.ts +30 -1
  98. package/hooks/use-billing-mtn.ts +31 -0
  99. package/hooks/use-billing-qry.ts +76 -0
  100. package/hooks/use-dataTable-mtn.ts +23 -115
  101. package/hooks/use-dataTable-qry.ts +69 -914
  102. package/hooks/use-email-mtn.ts +26 -0
  103. package/hooks/use-email-qry.helpers.ts +37 -0
  104. package/hooks/use-email-qry.ts +44 -174
  105. package/hooks/use-emailOutreach-mtn.ts +211 -0
  106. package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
  107. package/hooks/use-emailOutreach-qry.ts +367 -0
  108. package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
  109. package/hooks/use-fieldDoc-mtn.ts +244 -32
  110. package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
  111. package/hooks/use-fieldDoc-qry.ts +134 -102
  112. package/hooks/use-inboundContact-qry.ts +7 -9
  113. package/hooks/use-library-qry.ts +233 -0
  114. package/hooks/use-log-mtn.ts +25 -12
  115. package/hooks/use-log-qry.ts +99 -46
  116. package/hooks/use-organization-qry.ts +16 -60
  117. package/hooks/use-qrCode-mtn.ts +40 -0
  118. package/hooks/use-qrCode-qry.ts +78 -0
  119. package/hooks/use-schedule-mtn.ts +231 -348
  120. package/hooks/use-schedule-qry.ts +208 -139
  121. package/hooks/use-schedule-reactive.ts +218 -0
  122. package/hooks/use-sheet-mtn.ts +91 -199
  123. package/hooks/use-sheet-qry.ts +88 -237
  124. package/hooks/use-storage-qry.ts +84 -61
  125. package/hooks/use-workflow-mtn.ts +84 -23
  126. package/hooks/use-workflow-qry.ts +60 -61
  127. package/libs/ai-chat-link-events.ts +78 -0
  128. package/libs/ai-chat-outgoing.helpers.ts +153 -0
  129. package/libs/ai-chat-outgoing.ts +11 -0
  130. package/libs/ai-chat-outgoing.types.ts +25 -0
  131. package/libs/ai-chat-run-realtime.ts +20 -0
  132. package/libs/ai-chat-submission-realtime.ts +150 -0
  133. package/libs/data-changes.helpers.ts +161 -0
  134. package/libs/data-changes.ts +382 -0
  135. package/libs/fragment-realtime-sequence.ts +55 -0
  136. package/libs/open-sheet.ts +138 -0
  137. package/libs/record-read.ts +327 -0
  138. package/libs/sheet-command-batch.ts +45 -0
  139. package/libs/sheet-realtime-packet.ts +53 -0
  140. package/libs/sheet-view-realtime-router.ts +99 -0
  141. package/loaders/emailPreference.ts +69 -0
  142. package/loaders/rest.ts +12 -0
  143. package/package.json +77 -25
  144. package/schedule.d.ts +1183 -0
  145. package/sse.helpers.ts +19 -0
  146. package/sse.ts +26 -115
  147. package/types.d.ts +48 -25
  148. package/cache/index.test.ts +0 -881
  149. package/client/data-table-realtime-subscriptions.test.ts +0 -740
  150. package/client/data-table-realtime-subscriptions.ts +0 -955
  151. package/client/data-table-realtime.test.ts +0 -792
  152. package/client/data-table-realtime.ts +0 -1218
  153. package/client/fragment-realtime-sequence.ts +0 -52
  154. package/client/open-sheet.ts +0 -137
  155. package/client/request-managed-session.test.ts +0 -574
  156. package/client/request-no-store.test.ts +0 -157
  157. package/client/sse-ticket.test.ts +0 -26
  158. package/deno.lock +0 -170
  159. package/deno.test.json +0 -10
  160. package/gql/fragments/agentDocFragments.ts +0 -46
  161. package/gql/fragments/billingFragments.ts +0 -14
  162. package/gql/fragments/campaignFragments.ts +0 -277
  163. package/gql/mutations/agentDocMutations.ts +0 -177
  164. package/gql/mutations/campaignMutations.ts +0 -215
  165. package/gql/queries/agentDocQueries.ts +0 -120
  166. package/gql/queries/appQueries.ts +0 -14
  167. package/gql/queries/campaignQueries.ts +0 -127
  168. package/hooks/use-agentDoc-mtn.ts +0 -285
  169. package/hooks/use-agentDoc-qry.ts +0 -208
  170. package/hooks/use-app-qry.ts +0 -22
  171. package/hooks/use-campaign-mtn.ts +0 -377
  172. package/hooks/use-campaign-qry.ts +0 -257
  173. package/loaders/campaign.ts +0 -137
  174. package/tsconfig.json +0 -13
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jsb188
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/audience.d.ts ADDED
@@ -0,0 +1,205 @@
1
+ import type { AudienceEmailAddressGQL, AudienceSubscriptionStatus } from '@jsb188/mday/types/audience.d.ts';
2
+
3
+ export type {
4
+ AudienceAddressDetails,
5
+ AudienceDeliveryStatus,
6
+ AudienceEmailAddressGQL,
7
+ AudienceSubscriptionStatus,
8
+ } from '@jsb188/mday/types/audience.d.ts';
9
+
10
+ import type { PaginationArgs } from './types.d.ts';
11
+
12
+ export type AudienceListsSort = 'CREATED_ASC' | 'CREATED_DESC';
13
+ export type AudienceListMembersSort = AudienceListsSort;
14
+
15
+ export interface AudienceListsFilter {
16
+ ids?: readonly string[] | null;
17
+ includeArchived?: boolean;
18
+ search?: string | null;
19
+ }
20
+
21
+ export interface AudienceListMembersFilter {
22
+ audienceListId?: string | null;
23
+ subscriptionStatus?: AudienceSubscriptionStatus | null;
24
+ includeRemoved?: boolean;
25
+ search?: string | null;
26
+ }
27
+
28
+ export type AudienceListsArgs = {
29
+ organizationId?: string | null;
30
+ filter?: AudienceListsFilter | null;
31
+ sort?: AudienceListsSort | null;
32
+ } & PaginationArgs;
33
+
34
+ export type AudienceListMembersArgs = {
35
+ organizationId?: string | null;
36
+ filter: AudienceListMembersFilter;
37
+ sort?: AudienceListMembersSort | null;
38
+ } & PaginationArgs;
39
+
40
+ export type AudienceImportSource = 'MANUAL' | 'IMPORT' | 'INTEGRATION';
41
+ export type AudienceConsentSource = 'EXISTING_PERMISSION' | 'SIGNUP' | 'RECIPIENT_RESUBSCRIBE';
42
+ export type AudienceSuppressionKind = 'MANUAL' | 'COMPLAINT' | 'CLEANED' | 'PROVIDER';
43
+
44
+ export interface AudiencePageArgs {
45
+ afterId?: string | null;
46
+ limit?: number | null;
47
+ }
48
+
49
+ export interface AudienceListGQL {
50
+ id: string;
51
+ cursor: string;
52
+ organizationId: string;
53
+ name: string;
54
+ description: string | null;
55
+ archivedAt: string | null;
56
+ editVersion: string;
57
+ createdByAccountId: string | null;
58
+ createdAt: string;
59
+ updatedAt: string;
60
+ // Active member count; selected by `audienceLists` only, never by the shared fragment.
61
+ count?: number;
62
+ }
63
+
64
+ export interface AudienceConsentInput {
65
+ source: AudienceConsentSource;
66
+ recordedAt: string;
67
+ permissionSource: string;
68
+ }
69
+
70
+ export interface AudienceMemberDetails {
71
+ personName?: string | null;
72
+ provenance?: {
73
+ source?: AudienceImportSource;
74
+ actorAccountId?: string;
75
+ importRequestId?: string;
76
+ };
77
+ consent?: AudienceConsentInput & { actorAccountId?: string };
78
+ [key: string]: unknown;
79
+ }
80
+
81
+ export interface AudienceListMemberGQL {
82
+ __deleted?: boolean;
83
+
84
+ id: string;
85
+ cursor: string;
86
+ organizationId: string;
87
+ audienceListId: string;
88
+ emailAddressId: string;
89
+ subscriptionStatus: AudienceSubscriptionStatus;
90
+ subscriptionStatusAt: string;
91
+ subscriptionVersion: string;
92
+ removedAt: string | null;
93
+ details: AudienceMemberDetails;
94
+ address?: AudienceEmailAddressGQL | null;
95
+ createdAt: string;
96
+ updatedAt: string;
97
+ }
98
+
99
+ export interface AudienceListOverviewGQL {
100
+ total: number;
101
+ subscribed: number;
102
+ unsubscribed: number;
103
+ nonSubscribed: number;
104
+ pending: number;
105
+ cleaned: number;
106
+ eligible: number;
107
+ }
108
+
109
+ export interface AudienceEventGQL {
110
+ id: string;
111
+ organizationId: string;
112
+ normalizedEmail: string | null;
113
+ emailAddressId: string | null;
114
+ audienceListId: string | null;
115
+ audienceListMemberId: string | null;
116
+ eventType: string;
117
+ source: string;
118
+ actorAccountId: string | null;
119
+ emailOutreachId: string | null;
120
+ outboundEmailId: string | null;
121
+ metadata: Record<string, unknown>;
122
+ occurredAt: string;
123
+ createdAt: string;
124
+ }
125
+
126
+ export interface AudienceMemberImportResultGQL {
127
+ index: number;
128
+ emailAddress: string;
129
+ outcome:
130
+ | 'ADDED'
131
+ | 'RESTORED'
132
+ | 'UPDATED'
133
+ | 'ALREADY_PRESENT'
134
+ | 'PRESERVED_UNSUBSCRIBE'
135
+ | 'INVALID'
136
+ | 'CONSENT_MISSING'
137
+ | 'DUPLICATE';
138
+ memberId: string | null;
139
+ }
140
+
141
+ export interface AudienceMemberInput {
142
+ emailAddress: string;
143
+ personName?: string | null;
144
+ inboundContactId?: string | null;
145
+ // Imports intentionally cannot set pending or override an unsubscribe.
146
+ subscriptionStatus?: 'NON_SUBSCRIBED' | 'SUBSCRIBED';
147
+ consent?: AudienceConsentInput | null;
148
+ }
149
+
150
+ export interface CreateAudienceListInput {
151
+ organizationId: string;
152
+ name: string;
153
+ description?: string | null;
154
+ }
155
+
156
+ export interface EditAudienceListInput {
157
+ organizationId: string;
158
+ audienceListId: string;
159
+ expectedEditVersion: string;
160
+ name?: string;
161
+ description?: string | null;
162
+ archived?: boolean;
163
+ }
164
+
165
+ export interface AddAudienceListMembersInput {
166
+ organizationId: string;
167
+ audienceListId: string;
168
+ idempotencyKey: string;
169
+ source: AudienceImportSource;
170
+ members: AudienceMemberInput[];
171
+ }
172
+
173
+ export interface ChangeAudienceListSubscriptionInput {
174
+ organizationId: string;
175
+ audienceListId: string;
176
+ memberId: string;
177
+ expectedSubscriptionVersion: string;
178
+ subscribed: boolean;
179
+ consent?: AudienceConsentInput | null;
180
+ }
181
+
182
+ export interface EditAudienceListMemberInput {
183
+ organizationId: string;
184
+ audienceListId: string;
185
+ memberId: string;
186
+ expectedSubscriptionVersion: string;
187
+ personName?: string | null;
188
+ // Staff may only set NON_SUBSCRIBED or SUBSCRIBED; subscribing requires consent.
189
+ subscriptionStatus?: AudienceSubscriptionStatus | null;
190
+ consent?: AudienceConsentInput | null;
191
+ }
192
+
193
+ export interface RemoveAudienceListMembersInput {
194
+ organizationId: string;
195
+ audienceListId: string;
196
+ memberIds: string[];
197
+ }
198
+
199
+ export interface SetAudienceAddressSuppressionInput {
200
+ organizationId: string;
201
+ emailAddressId: string;
202
+ suppression: AudienceSuppressionKind;
203
+ suppressed: boolean;
204
+ reason: string;
205
+ }
package/cache/config.ts CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- FRAGMENT_NAMES,
3
- getFragmentBaseName,
4
- } from '@jsb188/mday/constants/graphqlReactivity.ts';
1
+ import { FRAGMENT_NAMES, getFragmentBaseName } from '@jsb188/mday/constants/graphqlReactivity.ts';
5
2
 
6
3
  /**
7
4
  * Rules for GraphQL server that's hard-coded to this package
@@ -13,32 +10,69 @@ import {
13
10
  * the cache stores changes incompatibly; a mismatch wipes the IndexedDB
14
11
  * snapshot on boot. (Stale-but-compatible data self-heals at read time via
15
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
+ * 12: email campaigns became email outreach. The email campaign, recipient and
22
+ * audience-selection records are dropped instead of lingering as orphans under
23
+ * fragment names the client no longer reads.
24
+ *
25
+ * 13: retire web-form campaign records and their linked agent notes.
26
+ *
27
+ * 14: staff schedules moved from occurrences to seats. The occurrence and
28
+ * series records are dropped, calendar, resource, request, violation and
29
+ * publication records changed shape, and the project-side rows that were
30
+ * inline (WBS nodes, assignments, baselines, code types, work-calendar
31
+ * exceptions, resource capacity) became fragment records.
32
+ *
33
+ * 15: schedule to-dos (ScheduleTask records, the scheduleTasks and
34
+ * scheduleMyTasks reads).
16
35
  */
17
36
 
18
- export const CACHE_SCHEMA_VERSION = 5;
37
+ export const CACHE_SCHEMA_VERSION = 15;
19
38
 
20
39
  export const QUERY_EXPIRE_TIMES = {
21
40
  __default: 1.08e7, // 3 hours
41
+ myOrganizations: 15 * 60 * 1000,
22
42
  // 5.4e+6, // 1.5 hours
23
43
  // 2.88e+7, // 8 hours
24
44
  // 6.48e+7, // 18 hours
25
45
 
46
+ // Email outreach metrics are live operational data. Realtime changes keep
47
+ // mounted lists current, and catch-up after a websocket gap is handled by
48
+ // realtimeLiveSince; this short window only bounds how old a revisited result may be.
49
+ emailMessage: 60 * 1000,
50
+ emailMessageConversationPage: 60 * 1000,
51
+ emailOutreachList: 60 * 1000,
52
+ emailOutreachFollowUps: 60 * 1000,
53
+ emailOutreachGroups: 60 * 1000,
54
+ emailOutreachReplyReport: 10 * 60 * 1000,
55
+
56
+ // Note edits arrive as record changes, and catch-up after a websocket gap is
57
+ // handled by realtimeLiveSince; short windows only bound how old a revisited result may be.
58
+ agentNote: 60 * 1000,
59
+ agentNotes: 60 * 1000,
60
+ searchAgentNotes: 60 * 1000,
61
+
26
62
  // Sheets
27
63
  sheets: 1.08e7,
28
64
  sheetAccess: 2.88e7,
29
- sheetRegionSourcePreviewRows: 2.88e7,
30
65
  sheetAccessGrants: 2.88e7,
31
66
  openSheet: 2.88e7,
32
- openSheetTab: 2.88e7,
33
- sheetTabChanges: 2.88e7,
34
- sheetOperationalHistory: 2.88e7,
35
67
 
36
- // Data tables
37
- dataTables: 1.08e7,
38
- dataTable: 2.88e7,
39
- dataTableMetadata: 2.88e7,
40
- dataTableRowsSnapshot: 2.88e7,
41
- dataTableChanges: 2.88e7,
68
+ // Data tables change through agents, workflows and source sync. Realtime
69
+ // changes keep mounted views current, and catch-up after a websocket gap is
70
+ // handled by realtimeLiveSince. Short windows refetch on focus or the next
71
+ // mount; a mounted rows list is rebuilt only through its declared notice.
72
+ dataTables: 60 * 1000,
73
+ dataTable: 60 * 1000,
74
+ dataTableRows: 60 * 1000,
75
+ dataTableRuns: 60 * 1000,
42
76
  } as {
43
77
  [key: string]: number;
44
78
  };
@@ -52,31 +86,34 @@ export const RULES = {
52
86
  // but if you want to skip some, add it here
53
87
  accountAuthFragment: false,
54
88
 
89
+ // Typeahead prefixes live only in the mounted hook; note fragments remain shared.
90
+ searchAgentNotes: false,
91
+ // Billing payment-form inputs: the Stripe key and tax previews must be
92
+ // fetched fresh for each payment form, never replayed from disk.
93
+ billingClientConfig: false,
94
+ billingPurchasePreview: false,
55
95
  // NOTE: ALL queries are cached by default,
56
96
  // but if you want to skip some, add it here
57
97
  // e.g.: someQueryName: false,
58
-
59
- // Respondent identity travels via header/cookie (not query variables), so
60
- // the cache key cannot distinguish viewers; never cache per-viewer results
61
98
  } as {
62
99
  __limit: number;
63
100
  [key: string]: boolean | number;
64
101
  };
65
102
 
103
+ // Reuse reply identities and captured answers within the open browser session.
104
+ export const MEMORY_ONLY_QUERY_NAMES = new Set(['emailOutreachReplyReport']);
105
+
66
106
  export const PARTIALS_MAP = {
67
107
  // Partial fragments are supported if you map them to its original fragment name
68
- dataTablePartialFragment: getFragmentBaseName(FRAGMENT_NAMES.dataTable),
69
108
  sheetViewPatchFragment: getFragmentBaseName(FRAGMENT_NAMES.sheetView),
70
- // List rows are a narrower projection of the same record. Without these the
71
- // server's $campaignTemplateFragment / $campaignFragment patches would only
72
- // reach a detail view, and a GENERATING card in a list would never settle to
73
- // ACTIVE.
74
- campaignTemplateSummaryFragment: getFragmentBaseName(
75
- FRAGMENT_NAMES.campaignTemplate,
76
- ),
77
- campaignSummaryFragment: getFragmentBaseName(FRAGMENT_NAMES.campaign),
109
+ // List rows are narrower projections of the same records. Map them to the
110
+ // canonical fragment keys so realtime core patches update both detail and
111
+ // summary consumers without duplicating fragment authorities.
112
+ emailOutreachSummaryFragment: getFragmentBaseName(FRAGMENT_NAMES.emailOutreach),
113
+ // The note detail projection shares the realtime agentNoteFragment identity
114
+ agentNoteDetailFragment: getFragmentBaseName(FRAGMENT_NAMES.agentNote),
78
115
  } as Record<string, string>;
79
116
 
80
117
  export const PARTIAL_NULL_PRESERVE_FIELDS = {
81
- sheetViewPatchFragment: ['ranges', 'sheetTab'],
118
+ sheetViewPatchFragment: ['sheetTab'],
82
119
  } as Record<string, string[]>;
@@ -0,0 +1,96 @@
1
+ import { FRAGMENT_NAMES, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
2
+ import { mergeAIChatRuns } from '@jsb188/mday/utils/aiChatWork.ts';
3
+ import { isOlderChatCheckpoint } from '../sse.helpers.ts';
4
+ import { graphQLValuesEqual } from './value.helpers.ts';
5
+
6
+ const FIELD_SELECTIONS = new WeakMap<any[], Map<string, any>>();
7
+
8
+ /* Reuse a fragment's field lookup instead of scanning its AST for every value. */
9
+ function getFieldSelections(selections: any[]) {
10
+ let fields = FIELD_SELECTIONS.get(selections);
11
+ if (!fields) {
12
+ fields = new Map(
13
+ selections
14
+ .filter((selection) => selection.kind === 'Field')
15
+ .map((selection) => [selection.alias?.value || selection.name.value, selection]),
16
+ );
17
+ FIELD_SELECTIONS.set(selections, fields);
18
+ }
19
+ return fields;
20
+ }
21
+
22
+ /*
23
+ * Merge partial GraphQL objects while replacing atomic JSON scalars, lists and
24
+ * nulls. Selected object fields may preserve unrequested children; a different
25
+ * entity id must never inherit the previous entity's fields. Equal values keep
26
+ * their references so downstream cache comparisons can stop immediately.
27
+ */
28
+ export function mergeGraphQLObjectData(current: any, incoming: any, selections?: any[]): any {
29
+ if (current === incoming || incoming === undefined) return current;
30
+ if (incoming === null || typeof incoming !== 'object') return incoming;
31
+ if (Array.isArray(incoming)) return graphQLValuesEqual(current, incoming) ? current : [...incoming];
32
+ const previous =
33
+ current &&
34
+ typeof current === 'object' &&
35
+ !Array.isArray(current) &&
36
+ !(current.id != null && incoming.id != null && current.id !== incoming.id)
37
+ ? current
38
+ : {};
39
+ const fields = selections ? getFieldSelections(selections) : null;
40
+ let result = previous;
41
+ for (const key of Object.keys(incoming)) {
42
+ if (incoming[key] === undefined) continue;
43
+ const field = fields?.get(key);
44
+ const value =
45
+ field && !field.selectionSet
46
+ ? graphQLValuesEqual(previous[key], incoming[key])
47
+ ? previous[key]
48
+ : incoming[key]
49
+ : mergeGraphQLObjectData(previous[key], incoming[key], field?.selectionSet?.selections);
50
+ if (!Object.hasOwn(previous, key) || value !== previous[key]) {
51
+ if (result === previous) result = { ...previous };
52
+ result[key] = value;
53
+ }
54
+ }
55
+ return result;
56
+ }
57
+
58
+ /*
59
+ * Chat snapshots race the durable SSE stream, so their versioned fields must
60
+ * merge monotonically at the shared normalization boundary. Other fragments
61
+ * retain the cache's existing merge behavior.
62
+ */
63
+ export function reconcileAIChatCacheSnapshot(fragmentKey: string, current: any, incoming: any, readFragment: (key: string) => any) {
64
+ if (incoming == null) return incoming;
65
+ if (fragmentKey.startsWith(FRAGMENT_NAMES.aiChat + ':')) {
66
+ // Preserve newer activity through delayed HTTP results, metadata edits and websocket echoes.
67
+ return current?.updatedAt && (!incoming.updatedAt || Date.parse(current.updatedAt) > Date.parse(incoming.updatedAt))
68
+ ? { ...incoming, updatedAt: current.updatedAt, activityOrder: current.activityOrder }
69
+ : incoming;
70
+ }
71
+ if (fragmentKey.startsWith(FRAGMENT_NAMES.aiChatRun + ':')) {
72
+ return mergeAIChatRuns(current ? { [current.id]: current } : {}, [incoming])[incoming.id];
73
+ }
74
+ if (!fragmentKey.startsWith(FRAGMENT_NAMES.aiChatMessage + ':')) return incoming;
75
+ const next = isOlderChatCheckpoint(current, incoming) ? { ...incoming, ...current } : incoming;
76
+ // Run settlement is versioned independently from the message text checkpoint.
77
+ let run = incoming.run;
78
+ if (current?.run && (!run || (current.run.id !== run.id && Date.parse(current.run.createdAt) > Date.parse(run.createdAt)))) {
79
+ run = current.run;
80
+ }
81
+ if (!run?.id) return next;
82
+ const canonical = readFragment(makeFragmentKey(FRAGMENT_NAMES.aiChatRun, run.id));
83
+ const previous = current?.run?.id === run.id ? current.run : null;
84
+ const received = incoming.run?.id === run.id ? incoming.run : null;
85
+ return { ...next, run: mergeAIChatRuns({}, [previous, received, canonical])[run.id] };
86
+ }
87
+
88
+ /*
89
+ * Read only references stored inside this query, never the global fragment
90
+ * cache. A cached document outside the list does not count as held by it.
91
+ */
92
+ export function queryReferencesFragment(value: unknown, fragmentKey: string): boolean {
93
+ if (!value || typeof value !== 'object') return false;
94
+ if (Array.isArray(value)) return value.some((item) => item === fragmentKey || queryReferencesFragment(item, fragmentKey));
95
+ return Object.values(value).some((item) => queryReferencesFragment(item, fragmentKey));
96
+ }