@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.
- package/LICENSE +21 -0
- package/audience.d.ts +14 -152
- package/cache/config.ts +35 -32
- package/cache/index.helpers.ts +1 -1
- package/cache/index.ts +73 -44
- package/cache/mounted-queries.ts +33 -0
- package/cache/persist.ts +10 -4
- package/cache/realtime-fence.ts +47 -0
- package/cache/realtime-live.ts +17 -0
- package/client/draft-persistence.ts +10 -39
- package/client/index.ts +2 -1
- package/client/request.ts +9 -34
- package/client/storage-asset.ts +58 -0
- package/gql/fragments/accountAuthFragments.ts +0 -4
- package/gql/fragments/agentNoteFragments.ts +8 -2
- package/gql/fragments/aiChatFragments.ts +0 -2
- package/gql/fragments/aiChatLinkFragments.ts +8 -0
- package/gql/fragments/audienceFragments.ts +1 -66
- package/gql/fragments/emailFragments.ts +27 -4
- package/gql/fragments/emailOutreachFragments.ts +281 -0
- package/gql/fragments/inboundContactFragments.ts +1 -1
- package/gql/fragments/libraryFragments.ts +120 -0
- package/gql/fragments/organizationFragments.ts +4 -2
- package/gql/fragments/scheduleFragments.ts +241 -324
- package/gql/fragments/sheetFragments.ts +4 -53
- package/gql/fragments/workWaitFragments.ts +13 -0
- package/gql/fragments/workflowFragments.ts +20 -4
- package/gql/mutations/agentNoteMutations.ts +2 -0
- package/gql/mutations/aiChatLinkMutations.ts +13 -0
- package/gql/mutations/aiChatMutations.ts +4 -6
- package/gql/mutations/audienceMutations.ts +0 -13
- package/gql/mutations/authMutations.ts +12 -60
- package/gql/mutations/emailMutations.ts +22 -0
- package/gql/mutations/emailOutreachMutations.ts +139 -0
- package/gql/mutations/index.ts +3 -1
- package/gql/mutations/organizationMutations.ts +2 -2
- package/gql/mutations/scheduleMutations.ts +61 -787
- package/gql/mutations/storageMutations.ts +1 -0
- package/gql/mutations/workflowMutations.ts +76 -0
- package/gql/queries/agentMemoryQueries.ts +6 -2
- package/gql/queries/agentNoteQueries.ts +26 -29
- package/gql/queries/aiChatQueries.ts +39 -40
- package/gql/queries/audienceQueries.ts +31 -55
- package/gql/queries/authQueries.ts +16 -6
- package/gql/queries/billingQueries.ts +26 -10
- package/gql/queries/dataTableQueries.ts +24 -15
- package/gql/queries/emailOutreachQueries.ts +282 -0
- package/gql/queries/emailQueries.ts +39 -12
- package/gql/queries/emailReplyReportQueries.ts +60 -9
- package/gql/queries/fieldDocQueries.ts +36 -14
- package/gql/queries/inboundContactQueries.ts +11 -4
- package/gql/queries/index.ts +2 -2
- package/gql/queries/libraryQueries.ts +112 -0
- package/gql/queries/logQueries.ts +31 -12
- package/gql/queries/organizationQueries.ts +31 -12
- package/gql/queries/qrCodeQueries.ts +11 -4
- package/gql/queries/scheduleQueries.ts +252 -505
- package/gql/queries/sheetQueries.ts +36 -14
- package/gql/queries/storageQueries.ts +11 -4
- package/gql/queries/workflowQueries.ts +53 -10
- package/gql/reactivity.ts +98 -0
- package/gql/recordReads.ts +171 -0
- package/hooks/index.ts +79 -52
- package/hooks/use-agentNote-mtn.ts +7 -0
- package/hooks/use-agentNote-qry.ts +30 -58
- package/hooks/use-agentNote-recovery.ts +6 -21
- package/hooks/use-aiChat-mtn.ts +9 -4
- package/hooks/use-aiChat-qry.ts +28 -7
- package/hooks/use-audience-mtn.ts +0 -24
- package/hooks/use-audience-qry.helpers.ts +0 -24
- package/hooks/use-audience-qry.ts +1 -86
- package/hooks/use-dataTable-mtn.ts +3 -3
- package/hooks/use-dataTable-qry.ts +7 -2
- package/hooks/use-email-mtn.ts +26 -0
- package/hooks/use-email-qry.helpers.ts +1 -1
- package/hooks/use-email-qry.ts +18 -3
- package/hooks/use-emailOutreach-mtn.ts +211 -0
- package/hooks/use-emailOutreach-qry.helpers.ts +25 -0
- package/hooks/use-emailOutreach-qry.ts +367 -0
- package/hooks/use-emailOutreachReplyReport-qry.ts +46 -0
- package/hooks/use-fieldDoc-qry.ts +1 -1
- package/hooks/use-library-qry.ts +233 -0
- package/hooks/use-qrCode-qry.ts +1 -1
- package/hooks/use-schedule-mtn.ts +10 -300
- package/hooks/use-schedule-qry.ts +168 -680
- package/hooks/use-schedule-reactive.ts +71 -339
- package/hooks/use-sheet-qry.ts +6 -1
- package/hooks/use-workflow-mtn.ts +45 -1
- package/hooks/use-workflow-qry.ts +22 -2
- package/libs/ai-chat-link-events.ts +78 -0
- package/libs/data-changes.helpers.ts +161 -0
- package/libs/data-changes.ts +382 -0
- package/libs/fragment-realtime-sequence.ts +3 -3
- package/libs/record-read.ts +327 -0
- package/libs/sheet-command-batch.ts +3 -2
- package/libs/sheet-realtime-packet.ts +53 -0
- package/loaders/emailPreference.ts +18 -24
- package/package.json +44 -17
- package/schedule.d.ts +267 -874
- package/types.d.ts +3 -1
- package/cache/index.chat-activity.test.ts +0 -119
- package/cache/index.chat.test.ts +0 -92
- package/cache/index.regression.test.ts +0 -149
- package/cache/index.test.ts +0 -1209
- package/deno.lock +0 -187
- package/deno.test.json +0 -12
- package/gql/fragments/campaignFragments.ts +0 -566
- package/gql/mutations/campaignMutations.ts +0 -258
- package/gql/queries/appQueries.ts +0 -14
- package/gql/queries/campaignQueries.ts +0 -236
- package/hooks/index.helpers.test.ts +0 -50
- package/hooks/use-agentNote-recovery.helpers.test.ts +0 -68
- package/hooks/use-aiChat-qry.helpers.test.ts +0 -63
- package/hooks/use-app-qry.ts +0 -22
- package/hooks/use-audience-qry.helpers.test.ts +0 -80
- package/hooks/use-campaign-generation-recovery.ts +0 -53
- package/hooks/use-campaign-mtn.ts +0 -436
- package/hooks/use-campaign-qry.helpers.ts +0 -40
- package/hooks/use-campaign-qry.ts +0 -834
- package/hooks/use-emailCampaignReplyReport-qry.ts +0 -27
- package/hooks/use-fieldDoc-qry.helpers.test.ts +0 -65
- package/hooks/use-publicFormEmail-mtn.ts +0 -27
- package/libs/fragment-recovery.test.ts +0 -326
- package/libs/fragment-recovery.ts +0 -325
- package/libs/orchestrator-realtime.helpers.test.ts +0 -229
- package/libs/orchestrator-realtime.helpers.ts +0 -317
- package/libs/orchestrator-realtime.ts +0 -433
- package/libs/request-cache-regression.test.ts +0 -122
- package/libs/request-managed-session.test.ts +0 -574
- package/libs/request-no-store.test.ts +0 -419
- package/libs/sheet-view-realtime-router.test.ts +0 -214
- package/libs/sse-ticket.test.ts +0 -26
- package/loaders/campaign.test.ts +0 -186
- package/loaders/campaign.ts +0 -110
- package/tests/agent-note-detail-cache.test.ts +0 -120
- package/tests/agent-note-search.test.ts +0 -444
- package/tsconfig.json +0 -13
package/loaders/campaign.test.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { registerENV } from '@jsb188/app';
|
|
2
|
-
import { fetchPublicCampaignSession } from './campaign.ts';
|
|
3
|
-
|
|
4
|
-
registerENV({
|
|
5
|
-
GQL_API_KEY: 'test-key',
|
|
6
|
-
GQL_SERVER: 'https://api.example.test/graphql',
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
function expectEqual(actual: unknown, expected: unknown, message: string) {
|
|
10
|
-
if (actual !== expected) {
|
|
11
|
-
throw new Error(
|
|
12
|
-
`${message}\nExpected: ${String(expected)}\nReceived: ${String(actual)}`,
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function makeReadyResponse() {
|
|
18
|
-
return new Response(
|
|
19
|
-
JSON.stringify({
|
|
20
|
-
data: {
|
|
21
|
-
state: 'READY',
|
|
22
|
-
campaign: {
|
|
23
|
-
publicId: 'form/id',
|
|
24
|
-
publicationVersion: 1,
|
|
25
|
-
audience: 'ANYONE',
|
|
26
|
-
backgroundFillStyle: 'MEDIUM',
|
|
27
|
-
sections: [],
|
|
28
|
-
},
|
|
29
|
-
organizations: [],
|
|
30
|
-
organization: null,
|
|
31
|
-
response: null,
|
|
32
|
-
},
|
|
33
|
-
}),
|
|
34
|
-
{
|
|
35
|
-
status: 200,
|
|
36
|
-
headers: { 'content-type': 'application/json' },
|
|
37
|
-
},
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
Deno.test('public campaign session loader uses one encoded atomic route', async () => {
|
|
42
|
-
const originalFetch = globalThis.fetch;
|
|
43
|
-
let requestURL = '';
|
|
44
|
-
let requestHeaders: Headers | null = null;
|
|
45
|
-
let requestCache: RequestCache | null = null;
|
|
46
|
-
|
|
47
|
-
globalThis.fetch = (input, init) => {
|
|
48
|
-
requestURL = String(input);
|
|
49
|
-
requestHeaders = new Headers(init?.headers);
|
|
50
|
-
requestCache = init?.cache || null;
|
|
51
|
-
return Promise.resolve(makeReadyResponse());
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const session = await fetchPublicCampaignSession('form/id', {
|
|
56
|
-
authToken: 'account-token',
|
|
57
|
-
childOrgId: 'org/id',
|
|
58
|
-
});
|
|
59
|
-
const persistedHeaders = requestHeaders as Headers | null;
|
|
60
|
-
expectEqual(
|
|
61
|
-
session?.state,
|
|
62
|
-
'READY',
|
|
63
|
-
'The loader must return the atomic session payload.',
|
|
64
|
-
);
|
|
65
|
-
expectEqual(
|
|
66
|
-
requestURL,
|
|
67
|
-
'https://api.example.test/api/campaigns/form%2Fid/session/org%2Fid',
|
|
68
|
-
'Both public and organization ids must be encoded as path segments.',
|
|
69
|
-
);
|
|
70
|
-
expectEqual(
|
|
71
|
-
persistedHeaders?.get('authorization'),
|
|
72
|
-
'account-token',
|
|
73
|
-
'The account credential must be forwarded.',
|
|
74
|
-
);
|
|
75
|
-
expectEqual(
|
|
76
|
-
persistedHeaders?.get('x-api-key'),
|
|
77
|
-
'test-key',
|
|
78
|
-
'The application API key must be forwarded.',
|
|
79
|
-
);
|
|
80
|
-
expectEqual(
|
|
81
|
-
requestCache,
|
|
82
|
-
'no-store',
|
|
83
|
-
'Public campaign sessions must bypass stale browser response caches.',
|
|
84
|
-
);
|
|
85
|
-
} finally {
|
|
86
|
-
globalThis.fetch = originalFetch;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
Deno.test('public campaign session loader retries only optional account bootstrap', async () => {
|
|
91
|
-
const originalFetch = globalThis.fetch;
|
|
92
|
-
let calls = 0;
|
|
93
|
-
const authorizations: Array<string | null> = [];
|
|
94
|
-
|
|
95
|
-
globalThis.fetch = (_input, init) => {
|
|
96
|
-
calls += 1;
|
|
97
|
-
authorizations.push(new Headers(init?.headers).get('authorization'));
|
|
98
|
-
return Promise.resolve(
|
|
99
|
-
calls === 1 ? new Response(null, { status: 403 }) : makeReadyResponse(),
|
|
100
|
-
);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
await fetchPublicCampaignSession('form', { authToken: 'expired' });
|
|
105
|
-
expectEqual(
|
|
106
|
-
calls,
|
|
107
|
-
2,
|
|
108
|
-
'An expired optional account bootstrap must retry once as a guest.',
|
|
109
|
-
);
|
|
110
|
-
expectEqual(
|
|
111
|
-
authorizations[0],
|
|
112
|
-
'expired',
|
|
113
|
-
'The first bootstrap uses the optional account token.',
|
|
114
|
-
);
|
|
115
|
-
expectEqual(
|
|
116
|
-
authorizations[1],
|
|
117
|
-
null,
|
|
118
|
-
'The fallback bootstrap must not forward the expired token.',
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
calls = 0;
|
|
122
|
-
let selectionStatus = 0;
|
|
123
|
-
try {
|
|
124
|
-
await fetchPublicCampaignSession('form', {
|
|
125
|
-
authToken: 'expired',
|
|
126
|
-
childOrgId: 'selected-org',
|
|
127
|
-
});
|
|
128
|
-
} catch (error) {
|
|
129
|
-
selectionStatus = error instanceof Response ? error.status : 0;
|
|
130
|
-
}
|
|
131
|
-
expectEqual(
|
|
132
|
-
selectionStatus,
|
|
133
|
-
403,
|
|
134
|
-
'An explicit organization failure must preserve its authorization status.',
|
|
135
|
-
);
|
|
136
|
-
expectEqual(
|
|
137
|
-
calls,
|
|
138
|
-
1,
|
|
139
|
-
'An explicit organization selection must never retry as an unrelated guest.',
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
calls = 0;
|
|
143
|
-
let requiredAccountStatus = 0;
|
|
144
|
-
try {
|
|
145
|
-
await fetchPublicCampaignSession('form', {
|
|
146
|
-
authToken: 'expired',
|
|
147
|
-
requireAccount: true,
|
|
148
|
-
});
|
|
149
|
-
} catch (error) {
|
|
150
|
-
requiredAccountStatus = error instanceof Response ? error.status : 0;
|
|
151
|
-
}
|
|
152
|
-
expectEqual(
|
|
153
|
-
requiredAccountStatus,
|
|
154
|
-
403,
|
|
155
|
-
'An account-required refresh must preserve its authorization failure.',
|
|
156
|
-
);
|
|
157
|
-
expectEqual(
|
|
158
|
-
calls,
|
|
159
|
-
1,
|
|
160
|
-
'An account-required refresh must not replace account state with guest data.',
|
|
161
|
-
);
|
|
162
|
-
} finally {
|
|
163
|
-
globalThis.fetch = originalFetch;
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
Deno.test('public campaign session loader preserves respondent-token failures', async () => {
|
|
168
|
-
const originalFetch = globalThis.fetch;
|
|
169
|
-
globalThis.fetch = () => Promise.resolve(new Response(null, { status: 403 }));
|
|
170
|
-
|
|
171
|
-
try {
|
|
172
|
-
let status = 0;
|
|
173
|
-
try {
|
|
174
|
-
await fetchPublicCampaignSession('form', { respondentToken: 'expired' });
|
|
175
|
-
} catch (error) {
|
|
176
|
-
status = error instanceof Response ? error.status : 0;
|
|
177
|
-
}
|
|
178
|
-
expectEqual(
|
|
179
|
-
status,
|
|
180
|
-
403,
|
|
181
|
-
'The browser must be able to recognize and clear an invalid respondent token.',
|
|
182
|
-
);
|
|
183
|
-
} finally {
|
|
184
|
-
globalThis.fetch = originalFetch;
|
|
185
|
-
}
|
|
186
|
-
});
|
package/loaders/campaign.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { getENVVariable } from '@jsb188/app';
|
|
2
|
-
import type { PublicCampaignSessionObj } from '@jsb188/mday/types/campaign.d.ts';
|
|
3
|
-
import { getRESTServer } from './rest.ts';
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Read one campaign REST payload and preserve authorization status when the
|
|
7
|
-
* caller needs to distinguish an expired browser-held credential.
|
|
8
|
-
*/
|
|
9
|
-
async function fetchCampaignREST<T>(
|
|
10
|
-
path: string,
|
|
11
|
-
headers?: Record<string, string>,
|
|
12
|
-
preserveErrorStatus = false,
|
|
13
|
-
): Promise<T | null> {
|
|
14
|
-
const restServer = getRESTServer();
|
|
15
|
-
if (!restServer) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
let response: Response;
|
|
20
|
-
try {
|
|
21
|
-
response = await fetch(`${restServer}${path}`, {
|
|
22
|
-
method: 'GET',
|
|
23
|
-
cache: 'no-store',
|
|
24
|
-
headers: {
|
|
25
|
-
'x-api-key': String(getENVVariable('GQL_API_KEY') || ''),
|
|
26
|
-
...(headers || {}),
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
} catch {
|
|
30
|
-
throw new Response(null, { status: 500 });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (response.status === 404) {
|
|
34
|
-
throw new Response(null, { status: 404 });
|
|
35
|
-
}
|
|
36
|
-
if (!response.ok) {
|
|
37
|
-
throw new Response(null, {
|
|
38
|
-
status: preserveErrorStatus ? response.status : 500,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const json = await response.json();
|
|
44
|
-
return (json?.data as T) ?? null;
|
|
45
|
-
} catch {
|
|
46
|
-
throw new Response(null, { status: 500 });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface FetchPublicCampaignSessionOptions {
|
|
51
|
-
authToken?: string | null;
|
|
52
|
-
childOrgId?: string | null;
|
|
53
|
-
requireAccount?: boolean;
|
|
54
|
-
respondentToken?: string | null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Fetch one atomic public-form session: campaign, access state, organization
|
|
59
|
-
* choice, and the matching saved response all come from one database snapshot.
|
|
60
|
-
*
|
|
61
|
-
* An invalid optional account session retries as a guest so an expired cookie
|
|
62
|
-
* cannot block an ANYONE form. Account-required refreshes and respondent-token
|
|
63
|
-
* failures preserve authorization status for their owning UI flows.
|
|
64
|
-
*/
|
|
65
|
-
export async function fetchPublicCampaignSession(
|
|
66
|
-
publicId: string,
|
|
67
|
-
options: FetchPublicCampaignSessionOptions = {},
|
|
68
|
-
): Promise<PublicCampaignSessionObj | null> {
|
|
69
|
-
if (!publicId) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const organizationPath = options.childOrgId
|
|
74
|
-
? `/${encodeURIComponent(options.childOrgId)}`
|
|
75
|
-
: '';
|
|
76
|
-
const path = `/api/campaigns/${encodeURIComponent(publicId)}/session${organizationPath}`;
|
|
77
|
-
const headers = {
|
|
78
|
-
...(options.authToken ? { authorization: options.authToken } : {}),
|
|
79
|
-
...(options.respondentToken
|
|
80
|
-
? { 'x-campaign-respondent': options.respondentToken }
|
|
81
|
-
: {}),
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
let session: PublicCampaignSessionObj | null;
|
|
85
|
-
try {
|
|
86
|
-
session = await fetchCampaignREST<PublicCampaignSessionObj>(
|
|
87
|
-
path,
|
|
88
|
-
headers,
|
|
89
|
-
!!options.authToken || !!options.respondentToken,
|
|
90
|
-
);
|
|
91
|
-
} catch (error) {
|
|
92
|
-
const canRetryAsGuest =
|
|
93
|
-
!!options.authToken &&
|
|
94
|
-
!options.requireAccount &&
|
|
95
|
-
!options.respondentToken &&
|
|
96
|
-
!options.childOrgId &&
|
|
97
|
-
error instanceof Response &&
|
|
98
|
-
(error.status === 401 || error.status === 403);
|
|
99
|
-
if (!canRetryAsGuest) {
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
session = await fetchCampaignREST<PublicCampaignSessionObj>(path);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (!session) {
|
|
107
|
-
throw new Response(null, { status: 404 });
|
|
108
|
-
}
|
|
109
|
-
return session;
|
|
110
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// @vitest-environment jsdom
|
|
2
|
-
import { act, createElement } from 'react';
|
|
3
|
-
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
-
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
5
|
-
import { clearGraphQLClientCache, setDataToCache, updateFragment } from '../cache/index.ts';
|
|
6
|
-
import { agentNoteQry, agentNotesQry } from '../gql/queries/agentNoteQueries.ts';
|
|
7
|
-
import { updateDataObservers } from '../hooks/index.ts';
|
|
8
|
-
import { useAgentNote } from '../hooks/use-agentNote-qry.ts';
|
|
9
|
-
|
|
10
|
-
const STATE = vi.hoisted(() => ({
|
|
11
|
-
requests: [] as { variables: any; complete: (note: any) => void }[],
|
|
12
|
-
value: null as any,
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
vi.mock('@jsb188/app/utils/api.ts', async (original) => ({
|
|
16
|
-
...(await original<Record<string, unknown>>()),
|
|
17
|
-
getAuthToken: () => 'token-1',
|
|
18
|
-
}));
|
|
19
|
-
vi.mock('@jsb188/react/states', () => ({
|
|
20
|
-
useConnectedToServerValue: () => true,
|
|
21
|
-
useOptimisticConnectedToServerValue: () => true,
|
|
22
|
-
useScreenIsFocusedValue: () => true,
|
|
23
|
-
useCurrentAccount: () => ({ account: { id: 'account-1' } }),
|
|
24
|
-
useRealtimeConnectionGenerationValue: () => 0,
|
|
25
|
-
}));
|
|
26
|
-
vi.mock('../hooks/use-agentNote-mtn.ts', () => ({ useMarkAgentNoteRead: () => undefined }));
|
|
27
|
-
vi.mock('../client/request.ts', () => ({
|
|
28
|
-
/* Complete the same guarded and normalized request path used by the real client. */
|
|
29
|
-
graphqlRequest: (query: any, variables: any, options: any, _signal: any, observers: any) =>
|
|
30
|
-
new Promise((resolve) => {
|
|
31
|
-
STATE.requests.push({
|
|
32
|
-
variables,
|
|
33
|
-
complete: (note) => {
|
|
34
|
-
const data = { agentNote: note };
|
|
35
|
-
if (options.shouldAcceptResult?.(data, variables) === false) {
|
|
36
|
-
resolve({ __clientResultRejected: true });
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
setDataToCache(data, query, variables, undefined, observers);
|
|
40
|
-
options.onCompleted?.({ data }, null);
|
|
41
|
-
resolve(data);
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}),
|
|
45
|
-
}));
|
|
46
|
-
|
|
47
|
-
let root: Root;
|
|
48
|
-
|
|
49
|
-
/* Render the real cache-first detail hook that both the menu and drawer use. */
|
|
50
|
-
const Reader = (p: { organizationId?: string; agentNoteId?: string } = {}) => {
|
|
51
|
-
STATE.value = useAgentNote(
|
|
52
|
-
{ organizationId: p.organizationId || 'org-1', agentNoteId: p.agentNoteId || 'note-1' },
|
|
53
|
-
{ cacheFirst: true, markRead: false },
|
|
54
|
-
);
|
|
55
|
-
return createElement('span', null, STATE.value.agentNote?.body);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/* Supply the detail fields whose absence distinguishes a homepage summary from a full note. */
|
|
59
|
-
function note(extra: Record<string, unknown> = {}) {
|
|
60
|
-
return { id: 'note-1', organizationId: 'org-1', headline: 'Tracker', body: 'Cached body', links: [], ...extra };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
(console as any).dev ||= () => undefined;
|
|
65
|
-
vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true);
|
|
66
|
-
clearGraphQLClientCache();
|
|
67
|
-
STATE.requests = [];
|
|
68
|
-
document.body.innerHTML = '<div id="root"></div>';
|
|
69
|
-
root = createRoot(document.getElementById('root')!);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
afterEach(async () => {
|
|
73
|
-
act(() => root.unmount());
|
|
74
|
-
await act(async () => {
|
|
75
|
-
for (const request of STATE.requests) request.complete(null);
|
|
76
|
-
});
|
|
77
|
-
clearGraphQLClientCache();
|
|
78
|
-
vi.unstubAllGlobals();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('renders full normalized details without a detail request and observes live changes', async () => {
|
|
82
|
-
setDataToCache({ agentNote: note() }, agentNoteQry, { organizationId: 'org-1', agentNoteId: 'note-1' });
|
|
83
|
-
await act(async () => root.render(createElement(Reader)));
|
|
84
|
-
expect(STATE.requests).toHaveLength(0);
|
|
85
|
-
expect(STATE.value.agentNote.body).toBe('Cached body');
|
|
86
|
-
expect(STATE.value.loading).toBe(false);
|
|
87
|
-
await act(async () => {
|
|
88
|
-
updateFragment('$agentNoteFragment:note-1', { body: 'Live body' }, null, false, updateDataObservers);
|
|
89
|
-
});
|
|
90
|
-
expect(STATE.value.agentNote.body).toBe('Live body');
|
|
91
|
-
expect(STATE.requests).toHaveLength(0);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('loads details once when only a summary is cached, then reuses them after remount', async () => {
|
|
95
|
-
setDataToCache({ agentNotes: [{ id: 'note-1', organizationId: 'org-1', headline: 'Tracker' }] }, agentNotesQry, {
|
|
96
|
-
organizationId: 'org-1',
|
|
97
|
-
});
|
|
98
|
-
await act(async () => root.render(createElement(Reader)));
|
|
99
|
-
expect(STATE.requests).toHaveLength(1);
|
|
100
|
-
await act(async () => STATE.requests[0].complete(note()));
|
|
101
|
-
expect(STATE.value.agentNote.body).toBe('Cached body');
|
|
102
|
-
await act(async () => root.render(null));
|
|
103
|
-
await act(async () => root.render(createElement(Reader)));
|
|
104
|
-
expect(STATE.requests).toHaveLength(1);
|
|
105
|
-
expect(STATE.value.agentNote.body).toBe('Cached body');
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('does not reuse a cached note from another organization', async () => {
|
|
109
|
-
setDataToCache({ agentNote: note() }, agentNoteQry, { organizationId: 'org-1', agentNoteId: 'note-1' });
|
|
110
|
-
await act(async () => root.render(createElement(Reader, { organizationId: 'org-2' })));
|
|
111
|
-
expect(STATE.requests).toHaveLength(1);
|
|
112
|
-
expect(STATE.value.agentNote).toBeNull();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('keeps deleted cached notes unavailable without a request', async () => {
|
|
116
|
-
setDataToCache({ agentNote: note({ __deleted: true }) }, agentNoteQry, { organizationId: 'org-1', agentNoteId: 'note-1' });
|
|
117
|
-
await act(async () => root.render(createElement(Reader)));
|
|
118
|
-
expect(STATE.requests).toHaveLength(0);
|
|
119
|
-
expect(STATE.value.agentNote).toBeNull();
|
|
120
|
-
});
|