@jsb188/graphql 1.1.12 → 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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/audience.d.ts +14 -152
  3. package/cache/config.ts +35 -32
  4. package/cache/index.helpers.ts +1 -1
  5. package/cache/index.ts +73 -44
  6. package/cache/mounted-queries.ts +33 -0
  7. package/cache/persist.ts +10 -4
  8. package/cache/realtime-fence.ts +47 -0
  9. package/cache/realtime-live.ts +17 -0
  10. package/client/draft-persistence.ts +10 -39
  11. package/client/index.ts +2 -1
  12. package/client/request.ts +9 -34
  13. package/client/storage-asset.ts +58 -0
  14. package/gql/fragments/accountAuthFragments.ts +0 -4
  15. package/gql/fragments/agentNoteFragments.ts +8 -2
  16. package/gql/fragments/aiChatFragments.ts +0 -2
  17. package/gql/fragments/aiChatLinkFragments.ts +8 -0
  18. package/gql/fragments/audienceFragments.ts +1 -66
  19. package/gql/fragments/emailFragments.ts +27 -4
  20. package/gql/fragments/emailOutreachFragments.ts +281 -0
  21. package/gql/fragments/inboundContactFragments.ts +1 -1
  22. package/gql/fragments/libraryFragments.ts +120 -0
  23. package/gql/fragments/organizationFragments.ts +4 -2
  24. package/gql/fragments/scheduleFragments.ts +241 -324
  25. package/gql/fragments/sheetFragments.ts +4 -53
  26. package/gql/fragments/workWaitFragments.ts +13 -0
  27. package/gql/fragments/workflowFragments.ts +20 -4
  28. package/gql/mutations/agentNoteMutations.ts +2 -0
  29. package/gql/mutations/aiChatLinkMutations.ts +13 -0
  30. package/gql/mutations/aiChatMutations.ts +4 -6
  31. package/gql/mutations/audienceMutations.ts +0 -13
  32. package/gql/mutations/authMutations.ts +12 -60
  33. package/gql/mutations/emailMutations.ts +22 -0
  34. package/gql/mutations/emailOutreachMutations.ts +139 -0
  35. package/gql/mutations/index.ts +3 -1
  36. package/gql/mutations/organizationMutations.ts +2 -2
  37. package/gql/mutations/scheduleMutations.ts +61 -787
  38. package/gql/mutations/storageMutations.ts +1 -0
  39. package/gql/mutations/workflowMutations.ts +76 -0
  40. package/gql/queries/agentMemoryQueries.ts +6 -2
  41. package/gql/queries/agentNoteQueries.ts +26 -29
  42. package/gql/queries/aiChatQueries.ts +39 -40
  43. package/gql/queries/audienceQueries.ts +31 -55
  44. package/gql/queries/authQueries.ts +16 -6
  45. package/gql/queries/billingQueries.ts +26 -10
  46. package/gql/queries/dataTableQueries.ts +24 -15
  47. package/gql/queries/emailOutreachQueries.ts +282 -0
  48. package/gql/queries/emailQueries.ts +39 -12
  49. package/gql/queries/emailReplyReportQueries.ts +60 -9
  50. package/gql/queries/fieldDocQueries.ts +36 -14
  51. package/gql/queries/inboundContactQueries.ts +11 -4
  52. package/gql/queries/index.ts +2 -2
  53. package/gql/queries/libraryQueries.ts +112 -0
  54. package/gql/queries/logQueries.ts +31 -12
  55. package/gql/queries/organizationQueries.ts +31 -12
  56. package/gql/queries/qrCodeQueries.ts +11 -4
  57. package/gql/queries/scheduleQueries.ts +252 -505
  58. package/gql/queries/sheetQueries.ts +36 -14
  59. package/gql/queries/storageQueries.ts +11 -4
  60. package/gql/queries/workflowQueries.ts +53 -10
  61. package/gql/reactivity.ts +98 -0
  62. package/gql/recordReads.ts +171 -0
  63. package/hooks/index.ts +79 -52
  64. package/hooks/use-agentNote-mtn.ts +7 -0
  65. package/hooks/use-agentNote-qry.ts +30 -58
  66. package/hooks/use-agentNote-recovery.ts +6 -21
  67. package/hooks/use-aiChat-mtn.ts +9 -4
  68. package/hooks/use-aiChat-qry.ts +28 -7
  69. package/hooks/use-audience-mtn.ts +0 -24
  70. package/hooks/use-audience-qry.helpers.ts +0 -24
  71. package/hooks/use-audience-qry.ts +1 -86
  72. package/hooks/use-dataTable-mtn.ts +3 -3
  73. package/hooks/use-dataTable-qry.ts +7 -2
  74. package/hooks/use-email-mtn.ts +26 -0
  75. package/hooks/use-email-qry.helpers.ts +1 -1
  76. package/hooks/use-email-qry.ts +18 -3
  77. package/hooks/use-emailOutreach-mtn.ts +211 -0
  78. package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
  79. package/hooks/use-emailOutreach-qry.ts +367 -0
  80. package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
  81. package/hooks/use-fieldDoc-qry.ts +1 -1
  82. package/hooks/use-library-qry.ts +233 -0
  83. package/hooks/use-qrCode-qry.ts +1 -1
  84. package/hooks/use-schedule-mtn.ts +10 -300
  85. package/hooks/use-schedule-qry.ts +168 -680
  86. package/hooks/use-schedule-reactive.ts +71 -339
  87. package/hooks/use-sheet-qry.ts +6 -1
  88. package/hooks/use-workflow-mtn.ts +45 -1
  89. package/hooks/use-workflow-qry.ts +22 -2
  90. package/libs/ai-chat-link-events.ts +78 -0
  91. package/libs/data-changes.helpers.ts +161 -0
  92. package/libs/data-changes.ts +382 -0
  93. package/libs/fragment-realtime-sequence.ts +3 -3
  94. package/libs/record-read.ts +327 -0
  95. package/libs/sheet-command-batch.ts +3 -2
  96. package/libs/sheet-realtime-packet.ts +53 -0
  97. package/loaders/emailPreference.ts +18 -24
  98. package/package.json +44 -17
  99. package/schedule.d.ts +267 -874
  100. package/types.d.ts +3 -1
  101. package/cache/index.chat-activity.test.ts +0 -119
  102. package/cache/index.chat.test.ts +0 -92
  103. package/cache/index.regression.test.ts +0 -149
  104. package/cache/index.test.ts +0 -1209
  105. package/deno.lock +0 -187
  106. package/deno.test.json +0 -12
  107. package/gql/fragments/campaignFragments.ts +0 -566
  108. package/gql/mutations/campaignMutations.ts +0 -258
  109. package/gql/queries/appQueries.ts +0 -14
  110. package/gql/queries/campaignQueries.ts +0 -236
  111. package/hooks/index.helpers.test.ts +0 -50
  112. package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
  113. package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
  114. package/hooks/use-app-qry.ts +0 -22
  115. package/hooks/use-audience-qry.helpers.test.ts +0 -80
  116. package/hooks/use-campaign-generation-recovery.ts +0 -53
  117. package/hooks/use-campaign-mtn.ts +0 -436
  118. package/hooks/use-campaign-qry.helpers.ts +0 -40
  119. package/hooks/use-campaign-qry.ts +0 -834
  120. package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
  121. package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
  122. package/hooks/use-publicFormEmail-mtn.ts +0 -27
  123. package/libs/fragment-recovery.test.ts +0 -326
  124. package/libs/fragment-recovery.ts +0 -325
  125. package/libs/orchestrator-realtime.helpers.test.ts +0 -229
  126. package/libs/orchestrator-realtime.helpers.ts +0 -317
  127. package/libs/orchestrator-realtime.ts +0 -433
  128. package/libs/request-cache-regression.test.ts +0 -122
  129. package/libs/request-managed-session.test.ts +0 -574
  130. package/libs/request-no-store.test.ts +0 -419
  131. package/libs/sheet-view-realtime-router.test.ts +0 -214
  132. package/libs/sse-ticket.test.ts +0 -26
  133. package/loaders/campaign.test.ts +0 -186
  134. package/loaders/campaign.ts +0 -110
  135. package/tests/agent-note-detail-cache.test.ts +0 -120
  136. package/tests/agent-note-search.test.ts +0 -444
  137. package/tsconfig.json +0 -13
@@ -0,0 +1,47 @@
1
+ // Fragment key → the fields realtime changes wrote to that record, and when the last one arrived
2
+ const REALTIME_WRITES = new Map<string, { at: number; data: Record<string, unknown> }>();
3
+ const FILE_CONSTANTS = { keepMs: 120_000, pruneAbove: 2_000 };
4
+
5
+ /*
6
+ * Remember which fields a realtime change wrote to a record, and when. Also
7
+ * called for records that are not cached, so a deletion still reaches a
8
+ * response that was in flight when it arrived.
9
+ */
10
+ export function noteRealtimeWrite(fragmentKey: string, data: Record<string, unknown>, at = Date.now()) {
11
+ const previous = REALTIME_WRITES.get(fragmentKey);
12
+ REALTIME_WRITES.set(fragmentKey, {
13
+ at,
14
+ data: previous && at - previous.at < FILE_CONSTANTS.keepMs ? { ...previous.data, ...data } : data,
15
+ });
16
+ if (REALTIME_WRITES.size > FILE_CONSTANTS.pruneAbove) {
17
+ for (const [key, write] of REALTIME_WRITES) {
18
+ if (at - write.at > FILE_CONSTANTS.keepMs) REALTIME_WRITES.delete(key);
19
+ }
20
+ }
21
+ }
22
+
23
+ /*
24
+ * Keep the fields that a realtime change wrote after this response's request
25
+ * began; every other field comes from the response (design 8.3).
26
+ */
27
+ export function keepNewerRealtimeFields(fragmentKey: string, incoming: any, current: any, requestStartedAt: number) {
28
+ const write = REALTIME_WRITES.get(fragmentKey);
29
+ if (!write || !requestStartedAt || write.at < requestStartedAt || !incoming || typeof incoming !== 'object') return incoming;
30
+ let result = incoming;
31
+ for (const field of Object.keys(write.data)) {
32
+ // A response never selects __deleted, so the marker is always carried over; other fields only when the response has them
33
+ if (field !== '__deleted' && !Object.hasOwn(incoming, field)) continue;
34
+ const value = current && Object.hasOwn(current, field) ? current[field] : write.data[field];
35
+ if (incoming[field] === value) continue;
36
+ if (result === incoming) result = { ...incoming };
37
+ result[field] = value;
38
+ }
39
+ return result;
40
+ }
41
+
42
+ /*
43
+ * Forget every remembered realtime write (sign-out, cache reset).
44
+ */
45
+ export function clearRealtimeWrites() {
46
+ REALTIME_WRITES.clear();
47
+ }
@@ -0,0 +1,17 @@
1
+ // Page load: results restored from IndexedDB are older than this, so they refetch on their first mount
2
+ let realtimeLiveSince = Date.now();
3
+
4
+ /*
5
+ * Record that realtime delivery resumed after a gap; query results fetched
6
+ * before now are no longer trusted and refetch through the stale checks.
7
+ */
8
+ export function markRealtimeResumed() {
9
+ realtimeLiveSince = Date.now();
10
+ }
11
+
12
+ /*
13
+ * Return the time since which this tab's realtime delivery has been continuous.
14
+ */
15
+ export function getRealtimeLiveSince() {
16
+ return realtimeLiveSince;
17
+ }
@@ -1,8 +1,4 @@
1
- import {
2
- type DraftSchema,
3
- mergeSchemaDefaults,
4
- pruneToSchema,
5
- } from '@jsb188/app/utils/schema.ts';
1
+ import { type DraftSchema, mergeSchemaDefaults, pruneToSchema } from '@jsb188/app/utils/schema.ts';
6
2
  import {
7
3
  deleteAllDraftRecords,
8
4
  deleteDraftRecord,
@@ -20,7 +16,7 @@ import {
20
16
  * server-side entity: composer text, selected uploads, form-in-progress.
21
17
  *
22
18
  * Keys are namespaced by the caller. The convention is
23
- * "feature:version:scopeId", e.g. `createCampaign:v2:${orgId}` — the
19
+ * "feature:version:scopeId", e.g. `editDocument:v1:${documentId}` — the
24
20
  * scope segment keeps one organization's draft out of another's, and the
25
21
  * version segment is the escape hatch for a shape change the schema cannot
26
22
  * catch (a field that keeps its type but changes its meaning).
@@ -50,14 +46,9 @@ export const DRAFT_TTL_HOURS_DEFAULT = 24;
50
46
  * Apply the schema (when given) and merge the result over the default value.
51
47
  */
52
48
 
53
- function resolveDraftValue<T>(
54
- value: unknown,
55
- options?: DraftOptions<T>,
56
- ): T | null {
49
+ function resolveDraftValue<T>(value: unknown, options?: DraftOptions<T>): T | null {
57
50
  const defaultValue = options?.defaultValue ?? null;
58
- const prunedValue = options?.schema
59
- ? pruneToSchema(value, options.schema)
60
- : value;
51
+ const prunedValue = options?.schema ? pruneToSchema(value, options.schema) : value;
61
52
 
62
53
  if (prunedValue === null || prunedValue === undefined) {
63
54
  return defaultValue;
@@ -78,15 +69,8 @@ function resolveDraftValue<T>(
78
69
  * removed as part of the read.
79
70
  */
80
71
 
81
- export async function getDraft<T>(
82
- key: string,
83
- options?: DraftOptions<T>,
84
- ): Promise<T | null> {
85
- const record = await readDraftRecord(
86
- key,
87
- options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT,
88
- options?.fresh,
89
- );
72
+ export async function getDraft<T>(key: string, options?: DraftOptions<T>): Promise<T | null> {
73
+ const record = await readDraftRecord(key, options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT, options?.fresh);
90
74
  return resolveDraftValue<T>(record?.d, options);
91
75
  }
92
76
 
@@ -99,10 +83,7 @@ export async function getDraft<T>(
99
83
  */
100
84
 
101
85
  export function peekDraft<T>(key: string, options?: DraftOptions<T>): T | null {
102
- const record = peekDraftRecord(
103
- key,
104
- options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT,
105
- );
86
+ const record = peekDraftRecord(key, options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT);
106
87
  return resolveDraftValue<T>(record?.d, options);
107
88
  }
108
89
 
@@ -113,14 +94,8 @@ export function peekDraft<T>(key: string, options?: DraftOptions<T>): T | null {
113
94
  * immediate, so a caller writing on every keystroke should debounce.
114
95
  */
115
96
 
116
- export async function setDraft<T>(
117
- key: string,
118
- value: T,
119
- options?: DraftOptions<T>,
120
- ): Promise<void> {
121
- const prunedValue = options?.schema
122
- ? pruneToSchema(value, options.schema)
123
- : value;
97
+ export async function setDraft<T>(key: string, value: T, options?: DraftOptions<T>): Promise<void> {
98
+ const prunedValue = options?.schema ? pruneToSchema(value, options.schema) : value;
124
99
  if (prunedValue === null || prunedValue === undefined) {
125
100
  // Nothing survived the schema; a stored draft would only resurrect a
126
101
  // shape the caller no longer holds
@@ -128,11 +103,7 @@ export async function setDraft<T>(
128
103
  return;
129
104
  }
130
105
 
131
- await writeDraftRecord(
132
- key,
133
- prunedValue,
134
- options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT,
135
- );
106
+ await writeDraftRecord(key, prunedValue, options?.ttlHours ?? DRAFT_TTL_HOURS_DEFAULT);
136
107
  }
137
108
 
138
109
  /**
package/client/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from '../hooks/index.ts';
2
2
  export * from '../libs/fragment-realtime-sequence.ts';
3
- export * from '../libs/fragment-recovery.ts';
3
+ export * from '../libs/record-read.ts';
4
4
  export * from '../libs/open-sheet.ts';
5
5
  export * from './request.ts';
6
+ export * from './storage-asset.ts';
package/client/request.ts CHANGED
@@ -40,12 +40,10 @@ type GraphQLServerRequestCacheEntry = {
40
40
  };
41
41
 
42
42
  type GraphQLSocketIdGetter = () => string | null | undefined;
43
- type GraphQLFormRespondentTokenGetter = () => string | null | undefined;
44
- type GraphQLCampaignRespondentTokenGetter = () => string | null | undefined;
45
43
  export type GraphQLAccessTokenRefreshReason = 'PROACTIVE' | 'AUTH_FAILURE';
46
44
  export type GraphQLAccessTokenRefreshOutcome =
47
45
  | { status: 'CONTEXT_CHANGED' }
48
- | { status: 'REFRESHED'; accessToken: string }
46
+ | { status: 'REFRESHED'; accessToken: string; storageToken?: string }
49
47
  | { status: 'REJECTED' }
50
48
  | { status: 'UNAVAILABLE' };
51
49
  export type GraphQLAccessTokenRefreshHandler = (p: {
@@ -56,8 +54,6 @@ export type GraphQLAccessTokenRefreshHandler = (p: {
56
54
  export type GraphQLClientIPSigner = (ipAddress: string) => Promise<string | null>;
57
55
 
58
56
  let GRAPHQL_SOCKET_ID_GETTER: GraphQLSocketIdGetter | null = null;
59
- let GRAPHQL_FORM_RESPONDENT_TOKEN_GETTER: GraphQLFormRespondentTokenGetter | null = null;
60
- let GRAPHQL_CAMPAIGN_RESPONDENT_TOKEN_GETTER: GraphQLCampaignRespondentTokenGetter | null = null;
61
57
  let GRAPHQL_ACCESS_TOKEN_REFRESH_HANDLER: GraphQLAccessTokenRefreshHandler | null = null;
62
58
  let GRAPHQL_MANAGED_SESSION_VERSION: number | null = null;
63
59
  let GRAPHQL_CLIENT_IP_SIGNER: GraphQLClientIPSigner | null = null;
@@ -134,22 +130,6 @@ export function setGraphQLSocketIdGetter(socketIdGetter: GraphQLSocketIdGetter |
134
130
  GRAPHQL_SOCKET_ID_GETTER = socketIdGetter;
135
131
  }
136
132
 
137
- /**
138
- * Register a getter for the public web form respondent token (ANYONE-audience
139
- * forms authenticate with this verified-email token instead of an account).
140
- */
141
-
142
- export function setGraphQLFormRespondentTokenGetter(tokenGetter: GraphQLFormRespondentTokenGetter | null) {
143
- GRAPHQL_FORM_RESPONDENT_TOKEN_GETTER = tokenGetter;
144
- }
145
-
146
- /*
147
- * Register a getter for the campaign-scoped verified-email respondent token.
148
- */
149
- export function setGraphQLCampaignRespondentTokenGetter(tokenGetter: GraphQLCampaignRespondentTokenGetter | null) {
150
- GRAPHQL_CAMPAIGN_RESPONDENT_TOKEN_GETTER = tokenGetter;
151
- }
152
-
153
133
  /**
154
134
  * Register the application-owned callback that exchanges its HttpOnly refresh
155
135
  * credential for a new GraphQL access token.
@@ -218,16 +198,6 @@ function getGraphQLRequestHeaders(
218
198
  headers.set('x-ws-socket-id', socketId);
219
199
  }
220
200
 
221
- const formRespondentToken = GRAPHQL_FORM_RESPONDENT_TOKEN_GETTER?.();
222
- if (formRespondentToken) {
223
- headers.set('x-form-respondent', String(formRespondentToken));
224
- }
225
-
226
- const campaignRespondentToken = GRAPHQL_CAMPAIGN_RESPONDENT_TOKEN_GETTER?.();
227
- if (campaignRespondentToken) {
228
- headers.set('x-campaign-respondent', String(campaignRespondentToken));
229
- }
230
-
231
201
  const advertisedManagedSessionVersion =
232
202
  managedSessionVersion === undefined ? GRAPHQL_MANAGED_SESSION_VERSION : managedSessionVersion;
233
203
  if (advertisedManagedSessionVersion === 1) {
@@ -442,14 +412,16 @@ async function refreshAccessToken(
442
412
  }
443
413
 
444
414
  /**
445
- * Refresh the browser's current managed access token for a non-HTTP transport.
415
+ * Refresh the browser's current managed access token for a browser request or socket.
446
416
  * The registered application handler still owns cookie rotation and app-state
447
417
  * replacement, while the shared single-flight prevents GraphQL/socket races.
448
418
  */
449
- export function refreshGraphQLRealtimeAccessToken(accessToken: string) {
419
+ export function refreshBrowserAccessToken(accessToken: string) {
450
420
  return refreshAccessToken(accessToken, 'AUTH_FAILURE');
451
421
  }
452
422
 
423
+ export { refreshBrowserAccessToken as refreshGraphQLRealtimeAccessToken };
424
+
453
425
  /**
454
426
  * Apply one managed-session refresh outcome to the request authorization or
455
427
  * throw the matching recoverable or terminal control-flow error.
@@ -695,6 +667,9 @@ export async function graphqlRequest(
695
667
  // Use this to check queries that are getting double-requested
696
668
  // doLog(gqlQuery, 'QUERYING... $0');
697
669
 
670
+ // Realtime changes that arrive after this moment are newer than the response (cache/realtime-fence.ts)
671
+ const requestStartedAt = Date.now();
672
+
698
673
  return executeGraphQLFetchWithRefresh(
699
674
  gqlQuery,
700
675
  variables,
@@ -735,7 +710,7 @@ export async function graphqlRequest(
735
710
  if (!requestIsCurrent()) return { aborted: true };
736
711
 
737
712
  if (cachePolicy !== 'no-store') {
738
- setDataToCache(data.data, gqlQuery, variables, cacheMap, updateObservers, !gqlError);
713
+ setDataToCache(data.data, gqlQuery, variables, cacheMap, updateObservers, !gqlError, requestStartedAt);
739
714
  }
740
715
 
741
716
  if (onCompleted) {
@@ -0,0 +1,58 @@
1
+ import { makeSecureAssetsUrl } from '@jsb188/app/utils/url_client.ts';
2
+ import { getAuthToken, getStorageToken, managedAccessTokensShareBinding } from '@jsb188/app/utils/api.ts';
3
+ import { refreshBrowserAccessToken } from './request.ts';
4
+
5
+ /*
6
+ * Accept private library object URLs only on the configured assets origin.
7
+ * Cached signed URLs and redirects must never receive a managed storage credential.
8
+ */
9
+ export function isLibraryAssetUrl(value: string): boolean {
10
+ return Boolean(makeSecureAssetsUrl(value));
11
+ }
12
+
13
+ /*
14
+ * Fetch protected bytes with the current storage credential. Share a single session
15
+ * renewal with other images, GraphQL and sockets, and retry an expired bearer once.
16
+ */
17
+ export async function fetchLibraryAsset(path: string, signal: AbortSignal) {
18
+ const url = makeSecureAssetsUrl(path);
19
+ if (!url) throw new Error('Invalid library asset URL');
20
+ const accessToken = getAuthToken();
21
+ if (!accessToken) throw new Error('20900');
22
+ const storageToken = getStorageToken();
23
+ /* Send only the storage credential, including on the retry. */
24
+ const read = (token: string) =>
25
+ fetch(url, {
26
+ headers: { Authorization: 'Bearer ' + token },
27
+ cache: 'no-store',
28
+ credentials: 'omit',
29
+ redirect: 'error',
30
+ referrerPolicy: 'no-referrer',
31
+ signal,
32
+ });
33
+ let response = storageToken ? await read(storageToken) : null;
34
+ if (!response || response.status === 401) {
35
+ await response?.body?.cancel();
36
+ signal.throwIfAborted();
37
+ if (!managedAccessTokensShareBinding(accessToken, getAuthToken() || '')) throw new Error('Storage session changed');
38
+ // A delayed 401 may arrive after another thumbnail has already replaced this bearer.
39
+ if (!getStorageToken() || getStorageToken() === storageToken) {
40
+ const refresh = await refreshBrowserAccessToken(accessToken);
41
+ if (refresh.status !== 'REFRESHED') throw new Error('Storage session unavailable');
42
+ }
43
+ signal.throwIfAborted();
44
+ const renewed = getStorageToken();
45
+ if (!renewed || !managedAccessTokensShareBinding(accessToken, getAuthToken() || ''))
46
+ throw new Error('Storage session unavailable');
47
+ response = await read(renewed);
48
+ }
49
+ if (!response.ok) {
50
+ await response.body?.cancel();
51
+ throw new Error(response.status === 404 || response.status === 403 ? '20900' : 'Storage request failed');
52
+ }
53
+ const blob = await response.blob();
54
+ signal.throwIfAborted();
55
+ if (!managedAccessTokensShareBinding(accessToken, getAuthToken() || '')) throw new Error('Storage session changed');
56
+ const encodedName = response.headers.get('Content-Disposition')?.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
57
+ return { blob, filename: encodedName ? decodeURIComponent(encodedName) : undefined };
58
+ }
@@ -6,10 +6,6 @@ export const accountAuthFragment = `fragment accountAuthFragment on AccountAuth
6
6
  activated
7
7
  hasPassword
8
8
 
9
- alertUpdatesOnMount
10
9
  webVersion
11
10
  mobileVersion
12
-
13
- respondentToken
14
- respondentEmail
15
11
  }`;
@@ -1,3 +1,4 @@
1
+ import { linkedEntitySummaryFields } from './aiChatLinkFragments.ts';
1
2
  // The list and detail projections share this normalized cache identity.
2
3
  // Realtime fragments update shared note content and metadata; viewer-specific
3
4
  // canManage and canPin permissions remain supplied by authorized GraphQL reads.
@@ -12,11 +13,12 @@ export const agentNoteFragment = `fragment agentNoteFragment on AgentNote {
12
13
  canManage
13
14
  canRefreshWithoutCooldown
14
15
  canPin
15
- campaignId
16
+ emailOutreachId
16
17
  fieldDocId
17
18
  fieldDocProgramId
18
19
  reminderWorkflowId
19
20
  emoji
21
+ title
20
22
  headline
21
23
  focus
22
24
  needsAttention
@@ -79,11 +81,12 @@ export const agentNoteDetailFragment = `fragment agentNoteDetailFragment on Agen
79
81
  canManage
80
82
  canRefreshWithoutCooldown
81
83
  canPin
82
- campaignId
84
+ emailOutreachId
83
85
  fieldDocId
84
86
  fieldDocProgramId
85
87
  reminderWorkflowId
86
88
  emoji
89
+ title
87
90
  headline
88
91
  body
89
92
  focus
@@ -140,6 +143,9 @@ export const agentNoteDetailFragment = `fragment agentNoteDetailFragment on Agen
140
143
  createdAt
141
144
  updatedAt
142
145
  links {
146
+ linkedFrom
147
+ linkedFromAIChatId
148
+ entity { ${linkedEntitySummaryFields} }
143
149
  entityType
144
150
  entityId
145
151
  watch
@@ -1,12 +1,10 @@
1
1
  export const aiChatFragment = `fragment aiChatFragment on AIChat {
2
2
  id
3
- type
4
3
  organizationId
5
4
  agentNoteId
6
5
  accountId
7
6
  calDate
8
7
  summary
9
- userManagedSummary
10
8
  archivedAt
11
9
  createdAt
12
10
  updatedAt
@@ -0,0 +1,8 @@
1
+ // Summary values have no cache id; reuse the complete selection inline in each containing fragment.
2
+ export const linkedEntitySummaryFields = `
3
+ entityType entityId title archived deleted canEdit fieldDocProgramId workflowActive workflowKind workflowPublished hasDraft fileName fileContentType emailOutreachStatus logActivityKey logActivityGroupKey
4
+ `;
5
+ export const aiChatLinkFragment = `fragment aiChatLinkFragment on AIChatLink {
6
+ id aiChatId organizationId entityType entityId sheetTabId createdInChat lastAction touchCount firstRunId lastRunId lastTouchedAt hiddenAt noteLinkState
7
+ entity { ${linkedEntitySummaryFields} }
8
+ }`;
@@ -68,74 +68,9 @@ export const audienceEventFragment = `fragment audienceEventFragment on Audience
68
68
  eventType
69
69
  source
70
70
  actorAccountId
71
- campaignId
71
+ emailOutreachId
72
72
  outboundEmailId
73
73
  metadata
74
74
  occurredAt
75
75
  createdAt
76
76
  }`;
77
-
78
- /*
79
- * One unique address across every list a campaign selected. The id is campaign-scoped,
80
- * so normalized rows never leak between campaigns that share an address. Membership
81
- * details are inline (no id) and are only ever replaced by a RESET_ONLY query reset.
82
- */
83
- export const campaignAudienceMemberFragment = `fragment campaignAudienceMemberFragment on CampaignAudienceMember {
84
- id
85
- cursor
86
- organizationId
87
- campaignId
88
- emailAddressId
89
- normalizedEmail
90
- personName
91
- inboundContactId
92
- reason
93
- memberships {
94
- memberId
95
- audienceListId
96
- listName
97
- personName
98
- subscriptionStatus
99
- subscriptionVersion
100
- removedAt
101
- }
102
- }`;
103
-
104
- /*
105
- * One campaign's selected lists and edit version, keyed by the campaign id so the
106
- * setCampaignAudienceLists result updates the cached session in place.
107
- */
108
- export const campaignAudienceSessionFragment = `fragment campaignAudienceSessionFragment on CampaignAudienceSession {
109
- id
110
- campaignId
111
- organizationId
112
- editVersion
113
- editable
114
- selectedAudienceListIds
115
- excludedEmailAddressIds
116
- }`;
117
-
118
- /*
119
- * One campaign's deduplicated eligibility counts, keyed by the campaign id and
120
- * version-stamped so consumers can pair it with the matching session.
121
- */
122
- export const campaignAudiencePreviewFragment = `fragment campaignAudiencePreviewFragment on CampaignAudiencePreview {
123
- id
124
- campaignId
125
- editVersion
126
- selectedCount
127
- eligibleCount
128
- duplicateCount
129
- excludedCount
130
- exclusions {
131
- reason
132
- count
133
- }
134
- frozenRecipientCount
135
- sendLimits {
136
- recipientLimit
137
- monthlyRecipientLimit
138
- monthlyRecipientsRemaining
139
- sendingPaused
140
- }
141
- }`;
@@ -6,25 +6,27 @@ export const emailMessageFragment = `fragment emailMessageFragment on EmailMessa
6
6
  kind
7
7
  status
8
8
  statusGroup
9
- statusDetail
9
+ statusSummary
10
10
  fromEmail
11
11
  fromName
12
12
  toEmail
13
13
  toName
14
14
  subject
15
15
  previewText
16
- postmarkMessageId
17
- campaignId
16
+ providerMessageId
17
+ emailOutreachId
18
+ hasConversation
18
19
  relatedEmailMessageId
19
20
  occurredAt
20
21
  }`;
21
22
 
22
- export const emailMessageDetailsFragment = `fragment emailMessageDetailsFragment on EmailMessage {
23
+ export const emailMessageDetailsFragment = `fragment emailMessageDetailsFragment on EmailMessageDetails {
23
24
  id
24
25
  bodyText
25
26
  bodyFormat
26
27
  processingStartedAt
27
28
  processingCompletedAt
29
+ senderBlocked
28
30
  replyToEmail
29
31
  cc
30
32
  replyToName
@@ -39,3 +41,24 @@ export const emailMessageDetailsFragment = `fragment emailMessageDetailsFragment
39
41
  relatedLogIds
40
42
  updatedAt
41
43
  }`;
44
+
45
+ export const emailConversationMessageFragment = `fragment emailConversationMessageFragment on EmailConversationMessage {
46
+ status
47
+ statusSummary
48
+ fromName
49
+ toName
50
+ processingStartedAt
51
+ processingCompletedAt
52
+ sentAt
53
+ deliveredAt
54
+ firstOpenedAt
55
+ bouncedAt
56
+ spamComplaintAt
57
+ id
58
+ direction
59
+ fromEmail
60
+ toEmail
61
+ subject
62
+ occurredAt
63
+ bodyText
64
+ }`;