@jsb188/graphql 1.1.11 → 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.
- package/audience.d.ts +343 -0
- package/cache/config.ts +58 -24
- package/cache/index.chat-activity.test.ts +119 -0
- package/cache/index.chat.test.ts +92 -0
- package/cache/index.helpers.ts +96 -0
- package/cache/index.regression.test.ts +149 -0
- package/cache/index.test.ts +370 -42
- package/cache/index.ts +326 -799
- package/cache/optimistic-ui-runtime.ts +46 -0
- package/cache/optimistic-ui.ts +401 -0
- package/cache/persist.ts +98 -19
- package/cache/store.ts +22 -64
- package/cache/value.helpers.ts +17 -0
- package/{drafts/store.ts → client/draft-persistence-indexed-db.ts} +19 -3
- package/{drafts/index.ts → client/draft-persistence.ts} +5 -2
- package/client/index.ts +3 -2
- package/client/request.helpers.ts +14 -0
- package/client/request.ts +130 -215
- package/deno.lock +17 -0
- package/deno.test.json +2 -0
- package/gql/fragments/agentMemoryFragments.ts +5 -1
- package/gql/fragments/agentNoteFragments.ts +150 -0
- package/gql/fragments/aiChatFragments.ts +36 -10
- package/gql/fragments/audienceFragments.ts +141 -0
- package/gql/fragments/campaignFragments.ts +415 -126
- package/gql/fragments/dataTableFragments.ts +48 -80
- package/gql/fragments/emailFragments.ts +28 -23
- package/gql/fragments/fieldDocFragments.ts +222 -40
- package/gql/fragments/inboundContactFragments.ts +2 -0
- package/gql/fragments/logFragments.ts +93 -2
- package/gql/fragments/organizationFragments.ts +10 -0
- package/gql/fragments/qrCodeFragments.ts +29 -0
- package/gql/fragments/scheduleFragments.ts +652 -140
- package/gql/fragments/sheetFragments.ts +84 -373
- package/gql/fragments/storageFragments.ts +25 -1
- package/gql/fragments/workflowFragments.ts +13 -1
- package/gql/mutations/agentMemoryMutations.ts +32 -0
- package/gql/mutations/agentNoteMutations.ts +62 -0
- package/gql/mutations/aiChatMutations.ts +36 -4
- package/gql/mutations/audienceMutations.ts +71 -0
- package/gql/mutations/authMutations.ts +45 -1
- package/gql/mutations/billingMutations.ts +24 -0
- package/gql/mutations/campaignMutations.ts +170 -127
- package/gql/mutations/contactMutations.ts +23 -0
- package/gql/mutations/dataTableMutations.ts +18 -75
- package/gql/mutations/fieldDocMutations.ts +162 -13
- package/gql/mutations/index.ts +8 -5
- package/gql/mutations/organizationMutations.ts +6 -0
- package/gql/mutations/qrCodeMutations.ts +20 -0
- package/gql/mutations/scheduleMutations.ts +1052 -354
- package/gql/mutations/sheetMutations.ts +62 -118
- package/gql/mutations/storageMutations.ts +0 -1
- package/gql/mutations/workflowMutations.ts +18 -0
- package/gql/queries/agentMemoryQueries.ts +6 -0
- package/gql/queries/agentNoteQueries.ts +89 -0
- package/gql/queries/aiChatQueries.ts +56 -4
- package/gql/queries/audienceQueries.ts +128 -0
- package/gql/queries/authQueries.ts +6 -0
- package/gql/queries/billingQueries.ts +95 -6
- package/gql/queries/campaignQueries.ts +132 -23
- package/gql/queries/dataTableQueries.ts +24 -65
- package/gql/queries/emailQueries.ts +18 -61
- package/gql/queries/emailReplyReportQueries.ts +76 -0
- package/gql/queries/fieldDocQueries.ts +100 -92
- package/gql/queries/inboundContactQueries.ts +4 -0
- package/gql/queries/index.ts +3 -1
- package/gql/queries/logQueries.ts +62 -7
- package/gql/queries/organizationQueries.ts +13 -0
- package/gql/queries/qrCodeQueries.ts +20 -0
- package/gql/queries/scheduleQueries.ts +633 -257
- package/gql/queries/sheetQueries.ts +59 -152
- package/gql/queries/workflowQueries.ts +10 -4
- package/hooks/index.helpers.test.ts +50 -0
- package/hooks/index.helpers.ts +52 -0
- package/hooks/index.ts +863 -685
- package/hooks/use-agentMemory-mtn.ts +29 -31
- package/hooks/use-agentMemory-qry.ts +15 -3
- package/hooks/use-agentNote-mtn.ts +82 -0
- package/hooks/use-agentNote-qry.ts +190 -0
- package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
- package/hooks/use-agentNote-recovery.helpers.ts +58 -0
- package/hooks/use-agentNote-recovery.ts +72 -0
- package/hooks/use-aiChat-mtn.ts +96 -112
- package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
- package/hooks/use-aiChat-qry.helpers.ts +124 -0
- package/hooks/use-aiChat-qry.ts +229 -383
- package/hooks/use-aiChat-stream-mtn.ts +14 -0
- package/hooks/use-audience-mtn.ts +194 -0
- package/hooks/use-audience-qry.helpers.test.ts +80 -0
- package/hooks/use-audience-qry.helpers.ts +63 -0
- package/hooks/use-audience-qry.ts +330 -0
- package/hooks/use-auth-mtn.ts +30 -1
- package/hooks/use-billing-mtn.ts +31 -0
- package/hooks/use-billing-qry.ts +76 -0
- package/hooks/use-campaign-generation-recovery.ts +53 -0
- package/hooks/use-campaign-mtn.ts +224 -165
- package/hooks/use-campaign-qry.helpers.ts +40 -0
- package/hooks/use-campaign-qry.ts +631 -54
- package/hooks/use-dataTable-mtn.ts +23 -115
- package/hooks/use-dataTable-qry.ts +66 -916
- package/hooks/use-email-qry.helpers.ts +37 -0
- package/hooks/use-email-qry.ts +33 -178
- package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
- package/hooks/use-fieldDoc-mtn.ts +244 -32
- package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
- package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
- package/hooks/use-fieldDoc-qry.ts +134 -102
- package/hooks/use-inboundContact-qry.ts +7 -9
- package/hooks/use-log-mtn.ts +25 -12
- package/hooks/use-log-qry.ts +99 -46
- package/hooks/use-organization-qry.ts +16 -60
- package/hooks/use-publicFormEmail-mtn.ts +27 -0
- package/hooks/use-qrCode-mtn.ts +40 -0
- package/hooks/use-qrCode-qry.ts +78 -0
- package/hooks/use-schedule-mtn.ts +506 -333
- package/hooks/use-schedule-qry.ts +682 -101
- package/hooks/use-schedule-reactive.ts +486 -0
- package/hooks/use-sheet-mtn.ts +91 -199
- package/hooks/use-sheet-qry.ts +84 -238
- package/hooks/use-storage-qry.ts +84 -61
- package/hooks/use-workflow-mtn.ts +39 -22
- package/hooks/use-workflow-qry.ts +40 -61
- package/libs/ai-chat-outgoing.helpers.ts +153 -0
- package/libs/ai-chat-outgoing.ts +11 -0
- package/libs/ai-chat-outgoing.types.ts +25 -0
- package/libs/ai-chat-run-realtime.ts +20 -0
- package/libs/ai-chat-submission-realtime.ts +150 -0
- package/libs/fragment-realtime-sequence.ts +55 -0
- package/libs/fragment-recovery.test.ts +326 -0
- package/libs/fragment-recovery.ts +325 -0
- package/libs/open-sheet.ts +138 -0
- package/libs/orchestrator-realtime.helpers.test.ts +229 -0
- package/libs/orchestrator-realtime.helpers.ts +317 -0
- package/libs/orchestrator-realtime.ts +433 -0
- package/libs/request-cache-regression.test.ts +122 -0
- package/{client → libs}/request-managed-session.test.ts +1 -1
- package/libs/request-no-store.test.ts +419 -0
- package/libs/sheet-command-batch.ts +44 -0
- package/libs/sheet-view-realtime-router.test.ts +214 -0
- package/libs/sheet-view-realtime-router.ts +99 -0
- package/loaders/campaign.test.ts +186 -0
- package/loaders/campaign.ts +56 -83
- package/loaders/emailPreference.ts +75 -0
- package/loaders/rest.ts +12 -0
- package/package.json +42 -17
- package/schedule.d.ts +1790 -0
- package/sse.helpers.ts +19 -0
- package/sse.ts +26 -115
- package/tests/agent-note-detail-cache.test.ts +120 -0
- package/tests/agent-note-search.test.ts +444 -0
- package/types.d.ts +46 -25
- package/client/data-table-realtime-subscriptions.test.ts +0 -740
- package/client/data-table-realtime-subscriptions.ts +0 -955
- package/client/data-table-realtime.test.ts +0 -792
- package/client/data-table-realtime.ts +0 -1218
- package/client/fragment-realtime-sequence.ts +0 -52
- package/client/open-sheet.ts +0 -137
- package/client/request-no-store.test.ts +0 -157
- package/gql/fragments/agentDocFragments.ts +0 -46
- package/gql/fragments/billingFragments.ts +0 -14
- package/gql/mutations/agentDocMutations.ts +0 -177
- package/gql/queries/agentDocQueries.ts +0 -120
- package/hooks/use-agentDoc-mtn.ts +0 -285
- package/hooks/use-agentDoc-qry.ts +0 -208
- /package/{client → libs}/sse-ticket.test.ts +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EmailMessagesFilterInput } from '@jsb188/mday/types/email.d.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Whitelist GraphQL input fields, trim searches, and preserve false observation filters.
|
|
5
|
+
*/
|
|
6
|
+
export function normalizeEmailMessagesFilter(filter?: EmailMessagesFilterInput | null): EmailMessagesFilterInput | null {
|
|
7
|
+
return filter
|
|
8
|
+
? {
|
|
9
|
+
startDate: filter.startDate || null,
|
|
10
|
+
endDate: filter.endDate || null,
|
|
11
|
+
query: filter.query?.trim() || null,
|
|
12
|
+
directions: filter.directions?.length ? filter.directions : null,
|
|
13
|
+
kinds: filter.kinds?.length ? filter.kinds : null,
|
|
14
|
+
statusGroups: filter.statusGroups?.length ? filter.statusGroups : null,
|
|
15
|
+
statuses: filter.statuses?.length ? filter.statuses : null,
|
|
16
|
+
campaignId: filter.campaignId || null,
|
|
17
|
+
emailAddress: filter.emailAddress?.trim() || null,
|
|
18
|
+
fromEmail: filter.fromEmail?.trim() || null,
|
|
19
|
+
toEmail: filter.toEmail?.trim() || null,
|
|
20
|
+
subject: filter.subject?.trim() || null,
|
|
21
|
+
delivered: filter.delivered ?? null,
|
|
22
|
+
opened: filter.opened ?? null,
|
|
23
|
+
}
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* Keep detail cache records inside the currently requested organization and email.
|
|
29
|
+
*/
|
|
30
|
+
export function getScopedEmailRecord<T extends { id: string; organizationId: string }>(
|
|
31
|
+
email: T | null | undefined,
|
|
32
|
+
organizationId: string | null | undefined,
|
|
33
|
+
emailId: string | null | undefined,
|
|
34
|
+
skip: boolean,
|
|
35
|
+
): T | null {
|
|
36
|
+
return !skip && organizationId && emailId && email?.organizationId === organizationId && email.id === emailId ? email : null;
|
|
37
|
+
}
|
package/hooks/use-email-qry.ts
CHANGED
|
@@ -1,227 +1,82 @@
|
|
|
1
1
|
import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
InboundEmailsSortEnum,
|
|
5
|
-
OutboundEmailGQL,
|
|
6
|
-
OutboundEmailsSortEnum,
|
|
7
|
-
} from '@jsb188/mday/types/email.d.ts';
|
|
8
|
-
import {
|
|
9
|
-
inboundEmailQry,
|
|
10
|
-
inboundEmailsQry,
|
|
11
|
-
outboundEmailQry,
|
|
12
|
-
outboundEmailsQry,
|
|
13
|
-
} from '../gql/queries/emailQueries.ts';
|
|
2
|
+
import type { EmailMessageGQL, EmailMessagesFilterInput, EmailMessagesSortEnum } from '@jsb188/mday/types/email.d.ts';
|
|
3
|
+
import { emailMessageQry, emailMessagesQry } from '../gql/queries/emailQueries.ts';
|
|
14
4
|
import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
|
|
5
|
+
import { getScopedEmailRecord, normalizeEmailMessagesFilter } from './use-email-qry.helpers.ts';
|
|
15
6
|
|
|
16
7
|
/**
|
|
17
8
|
* Constants
|
|
18
9
|
*/
|
|
19
10
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
type EmailListFilter =
|
|
23
|
-
| {
|
|
24
|
-
startDate?: string | null;
|
|
25
|
-
endDate?: string | null;
|
|
26
|
-
query?: string | null;
|
|
27
|
-
statuses?: string[] | null;
|
|
28
|
-
}
|
|
29
|
-
| null
|
|
30
|
-
| undefined;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Keep email list filters aligned with the GraphQL input shape.
|
|
34
|
-
*/
|
|
35
|
-
function normalizeEmailsFilter(filter?: EmailListFilter) {
|
|
36
|
-
return filter
|
|
37
|
-
? {
|
|
38
|
-
startDate: filter.startDate || null,
|
|
39
|
-
endDate: filter.endDate || null,
|
|
40
|
-
query: filter.query || null,
|
|
41
|
-
statuses: filter.statuses || null,
|
|
42
|
-
}
|
|
43
|
-
: null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Return true when one email record should be fetched from the server.
|
|
48
|
-
*/
|
|
49
|
-
function shouldFetchEmailRecord(
|
|
50
|
-
variables: {
|
|
51
|
-
organizationId?: string | null;
|
|
52
|
-
},
|
|
53
|
-
emailId?: string | null,
|
|
54
|
-
cachedEmail?: InboundEmailGQL | OutboundEmailGQL | null,
|
|
55
|
-
params: UseQueryParams = {},
|
|
56
|
-
) {
|
|
57
|
-
return (
|
|
58
|
-
!!variables.organizationId && !!emailId && !cachedEmail && !params.skip
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Return one email fragment cache key.
|
|
64
|
-
*/
|
|
65
|
-
function getEmailFragmentKey(fragmentName: string, emailId: string) {
|
|
66
|
-
return `$${fragmentName}:${emailId}`;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/*
|
|
70
|
-
* Fetch one inbound email.
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
export function useInboundEmail(
|
|
74
|
-
variables: {
|
|
75
|
-
organizationId?: string | null;
|
|
76
|
-
inboundEmailId?: string | null;
|
|
77
|
-
},
|
|
78
|
-
params: UseQueryParams = {},
|
|
79
|
-
) {
|
|
80
|
-
const cachedInboundEmail = useReactiveInboundEmailFragment(
|
|
81
|
-
variables.inboundEmailId || '',
|
|
82
|
-
null,
|
|
83
|
-
);
|
|
84
|
-
const shouldFetchInboundEmail = shouldFetchEmailRecord(
|
|
85
|
-
variables,
|
|
86
|
-
variables.inboundEmailId,
|
|
87
|
-
cachedInboundEmail,
|
|
88
|
-
params,
|
|
89
|
-
);
|
|
90
|
-
const { data, ...rest } = useQuery(inboundEmailQry, {
|
|
91
|
-
...params,
|
|
92
|
-
variables,
|
|
93
|
-
skip: !shouldFetchInboundEmail,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
inboundEmail: cachedInboundEmail || data?.inboundEmail,
|
|
98
|
-
initialLoading: shouldFetchInboundEmail && !data,
|
|
99
|
-
...rest,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Fetch inbound emails.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
export function useInboundEmails(
|
|
108
|
-
variables: PaginationArgs & {
|
|
109
|
-
organizationId?: string | null;
|
|
110
|
-
filter?: EmailListFilter;
|
|
111
|
-
sort?: InboundEmailsSortEnum | null;
|
|
112
|
-
},
|
|
113
|
-
params: UseQueryParams = {},
|
|
114
|
-
) {
|
|
115
|
-
const { data, ...rest } = useQuery(inboundEmailsQry, {
|
|
116
|
-
...params,
|
|
117
|
-
variables: {
|
|
118
|
-
...variables,
|
|
119
|
-
filter: normalizeEmailsFilter(variables.filter),
|
|
120
|
-
cursor: null,
|
|
121
|
-
after: true,
|
|
122
|
-
limit: EMAILS_LIST_LIMIT,
|
|
123
|
-
},
|
|
124
|
-
skip: !variables.organizationId || params.skip,
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
inboundEmails: data?.inboundEmails,
|
|
129
|
-
...rest,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
11
|
+
const EMAIL_MESSAGES_LIST_LIMIT = 250;
|
|
132
12
|
|
|
133
13
|
/*
|
|
134
|
-
* Fetch one outbound email.
|
|
14
|
+
* Fetch one inbound or outbound email message.
|
|
135
15
|
*/
|
|
136
16
|
|
|
137
|
-
export function
|
|
17
|
+
export function useEmailMessage(
|
|
138
18
|
variables: {
|
|
139
19
|
organizationId?: string | null;
|
|
140
|
-
|
|
20
|
+
emailMessageId?: string | null;
|
|
141
21
|
},
|
|
142
22
|
params: UseQueryParams = {},
|
|
143
23
|
) {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const shouldFetchOutboundEmail = shouldFetchEmailRecord(
|
|
149
|
-
variables,
|
|
150
|
-
variables.outboundEmailId,
|
|
151
|
-
cachedOutboundEmail,
|
|
152
|
-
params,
|
|
153
|
-
);
|
|
154
|
-
const { data, ...rest } = useQuery(outboundEmailQry, {
|
|
24
|
+
const skip = !variables.organizationId || !variables.emailMessageId || !!params.skip;
|
|
25
|
+
const cachedEmailMessage = useReactiveEmailMessageFragment(variables.emailMessageId || '', null);
|
|
26
|
+
// Keep the query active so list-row fragments cannot hide the detail fields.
|
|
27
|
+
const { data, ...rest } = useQuery(emailMessageQry, {
|
|
155
28
|
...params,
|
|
156
29
|
variables,
|
|
157
|
-
skip
|
|
30
|
+
skip,
|
|
158
31
|
});
|
|
32
|
+
const currentData = rest.queryKey === `#${rest.queryName}:${rest.variablesKey}` ? data : null;
|
|
33
|
+
const emailMessage =
|
|
34
|
+
currentData?.emailMessage === null
|
|
35
|
+
? null
|
|
36
|
+
: getScopedEmailRecord<EmailMessageGQL>(currentData?.emailMessage, variables.organizationId, variables.emailMessageId, skip) ||
|
|
37
|
+
getScopedEmailRecord<EmailMessageGQL>(cachedEmailMessage, variables.organizationId, variables.emailMessageId, skip);
|
|
159
38
|
|
|
160
39
|
return {
|
|
161
|
-
|
|
162
|
-
initialLoading:
|
|
40
|
+
emailMessage,
|
|
41
|
+
initialLoading: !skip && !emailMessage && !rest.error && currentData?.emailMessage === undefined,
|
|
163
42
|
...rest,
|
|
164
43
|
};
|
|
165
44
|
}
|
|
166
45
|
|
|
167
46
|
/**
|
|
168
|
-
* Fetch outbound
|
|
47
|
+
* Fetch inbound and outbound email messages as one list.
|
|
169
48
|
*/
|
|
170
49
|
|
|
171
|
-
export function
|
|
50
|
+
export function useEmailMessages(
|
|
172
51
|
variables: PaginationArgs & {
|
|
173
52
|
organizationId?: string | null;
|
|
174
|
-
filter?:
|
|
175
|
-
sort?:
|
|
53
|
+
filter?: EmailMessagesFilterInput | null;
|
|
54
|
+
sort?: EmailMessagesSortEnum | null;
|
|
176
55
|
},
|
|
177
56
|
params: UseQueryParams = {},
|
|
178
57
|
) {
|
|
179
|
-
const { data, ...rest } = useQuery(
|
|
58
|
+
const { data, ...rest } = useQuery(emailMessagesQry, {
|
|
180
59
|
...params,
|
|
181
60
|
variables: {
|
|
182
61
|
...variables,
|
|
183
|
-
filter:
|
|
184
|
-
cursor: null,
|
|
185
|
-
after: true,
|
|
186
|
-
limit:
|
|
62
|
+
filter: normalizeEmailMessagesFilter(variables.filter),
|
|
63
|
+
cursor: variables.cursor ?? null,
|
|
64
|
+
after: variables.after ?? true,
|
|
65
|
+
limit: variables.limit ?? EMAIL_MESSAGES_LIST_LIMIT,
|
|
187
66
|
},
|
|
188
67
|
skip: !variables.organizationId || params.skip,
|
|
189
68
|
});
|
|
190
69
|
|
|
191
70
|
return {
|
|
192
|
-
|
|
71
|
+
emailMessages: data?.emailMessages,
|
|
193
72
|
...rest,
|
|
194
73
|
};
|
|
195
74
|
}
|
|
196
75
|
|
|
197
76
|
/**
|
|
198
|
-
* Get reactive
|
|
199
|
-
*/
|
|
200
|
-
|
|
201
|
-
export function useReactiveInboundEmailFragment(
|
|
202
|
-
inboundEmailId: string,
|
|
203
|
-
currentData?: any,
|
|
204
|
-
queryCount?: number,
|
|
205
|
-
) {
|
|
206
|
-
return useReactiveFragment(
|
|
207
|
-
currentData,
|
|
208
|
-
[getEmailFragmentKey('inboundEmailFragment', inboundEmailId)],
|
|
209
|
-
queryCount,
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Get reactive outbound email fragment.
|
|
77
|
+
* Get reactive email message fragment.
|
|
215
78
|
*/
|
|
216
79
|
|
|
217
|
-
export function
|
|
218
|
-
|
|
219
|
-
currentData?: any,
|
|
220
|
-
queryCount?: number,
|
|
221
|
-
) {
|
|
222
|
-
return useReactiveFragment(
|
|
223
|
-
currentData,
|
|
224
|
-
[getEmailFragmentKey('outboundEmailFragment', outboundEmailId)],
|
|
225
|
-
queryCount,
|
|
226
|
-
);
|
|
80
|
+
export function useReactiveEmailMessageFragment(emailMessageId: string, currentData?: any, queryCount?: number) {
|
|
81
|
+
return useReactiveFragment(currentData, [`$emailMessageFragment:${emailMessageId}`], queryCount);
|
|
227
82
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { EmailCampaignReplyReportGQL } from '@jsb188/mday/types/emailReplyReport.d.ts';
|
|
2
|
+
import { useQuery } from '../client/index.ts';
|
|
3
|
+
import { emailCampaignReplyReportQry } from '../gql/queries/emailReplyReportQueries.ts';
|
|
4
|
+
import type { UseQueryParams } from '../types.d.ts';
|
|
5
|
+
import { getCampaignQueryData } from './use-campaign-qry.helpers.ts';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Read one complete campaign report into mounted query state, hiding retained
|
|
9
|
+
* output after scope changes or read errors. RESET_ONLY preserves the displayed
|
|
10
|
+
* snapshot until the ordinary query refresh action is acknowledged.
|
|
11
|
+
*/
|
|
12
|
+
export function useEmailCampaignReplyReport(
|
|
13
|
+
variables: { organizationId?: string | null; campaignId?: string | null },
|
|
14
|
+
params: UseQueryParams = {},
|
|
15
|
+
) {
|
|
16
|
+
const skipped = !variables.organizationId || !variables.campaignId || !!params.skip;
|
|
17
|
+
const { data, ...rest } = useQuery(emailCampaignReplyReportQry, {
|
|
18
|
+
...params,
|
|
19
|
+
variables,
|
|
20
|
+
skip: skipped,
|
|
21
|
+
});
|
|
22
|
+
const currentData = getCampaignQueryData({ data, ...rest }, skipped || !!rest.error);
|
|
23
|
+
return {
|
|
24
|
+
...rest,
|
|
25
|
+
report: (currentData?.emailCampaignReplyReport ?? null) as EmailCampaignReplyReportGQL | null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -1,50 +1,262 @@
|
|
|
1
1
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
2
|
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
archiveFieldDocMtn,
|
|
5
|
+
createFieldDocProgramGroupMtn,
|
|
6
|
+
editFieldDocProgramGroupMtn,
|
|
7
|
+
deleteFieldDocProgramGroupMtn,
|
|
8
|
+
editFieldDocPlacementMtn,
|
|
9
|
+
createFieldDocProgramMtn,
|
|
10
|
+
deleteFieldDocSubmissionMtn,
|
|
11
|
+
editFieldDocCustomInstructionsMtn,
|
|
12
|
+
editFieldDocMtn,
|
|
13
|
+
editFieldDocProgramMtn,
|
|
14
|
+
editFieldDocSettingsMtn,
|
|
15
|
+
enrollFieldDocProgramMtn,
|
|
16
|
+
restoreFieldDocProgramEnrollmentMtn,
|
|
17
|
+
unenrollFieldDocProgramMtn,
|
|
18
|
+
} from '../gql/mutations/fieldDocMutations.ts';
|
|
9
19
|
import { useMutation } from './index.ts';
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
*
|
|
21
|
+
/**
|
|
22
|
+
* Enroll the organization in a catalog program (idempotent; an archived enrollment must be restored instead). The
|
|
23
|
+
* enrollment list updates through the server's fieldDocProgramEnrollments reset.
|
|
13
24
|
*/
|
|
14
25
|
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
export function useEnrollFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
27
|
+
const [enrollFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(enrollFieldDocProgramMtn, {
|
|
28
|
+
openModalPopUp,
|
|
29
|
+
...params,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
enrollFieldDocProgram,
|
|
34
|
+
updateObservers,
|
|
35
|
+
...mtnValues,
|
|
36
|
+
...mtnHandlers,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Unenroll the organization from a program. The enrollment is archived and can be restored until the retention
|
|
42
|
+
* window purges it; the lists update through the server's resets.
|
|
43
|
+
*/
|
|
20
44
|
|
|
21
|
-
|
|
22
|
-
|
|
45
|
+
export function useUnenrollFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
46
|
+
const [unenrollFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(unenrollFieldDocProgramMtn, {
|
|
47
|
+
openModalPopUp,
|
|
48
|
+
...params,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
unenrollFieldDocProgram,
|
|
53
|
+
updateObservers,
|
|
54
|
+
...mtnValues,
|
|
55
|
+
...mtnHandlers,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Restore an archived enrollment before the retention window purges it, resuming the workflows its unenroll paused.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export function useRestoreFieldDocProgramEnrollment(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
64
|
+
const [restoreFieldDocProgramEnrollment, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
65
|
+
restoreFieldDocProgramEnrollmentMtn,
|
|
66
|
+
{
|
|
23
67
|
openModalPopUp,
|
|
24
|
-
|
|
25
|
-
|
|
68
|
+
...params,
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
restoreFieldDocProgramEnrollment,
|
|
74
|
+
updateObservers,
|
|
75
|
+
...mtnValues,
|
|
76
|
+
...mtnHandlers,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Create a custom program in the organization; the result is the new enrollment.
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
export function useCreateFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
85
|
+
const [createFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(createFieldDocProgramMtn, {
|
|
86
|
+
openModalPopUp,
|
|
87
|
+
...params,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
createFieldDocProgram,
|
|
92
|
+
updateObservers,
|
|
93
|
+
...mtnValues,
|
|
94
|
+
...mtnHandlers,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Edit one of the organization's custom programs (catalog programs are read-only).
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
export function useEditFieldDocProgram(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
103
|
+
const [editFieldDocProgram, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocProgramMtn, {
|
|
104
|
+
openModalPopUp,
|
|
105
|
+
...params,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
editFieldDocProgram,
|
|
110
|
+
updateObservers,
|
|
111
|
+
...mtnValues,
|
|
112
|
+
...mtnHandlers,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Save the organization's custom instructions for a program doc (last writer wins per key). The result is the edit
|
|
118
|
+
* session with the same selection and id, so it updates the cached session that useFieldDocEditSession reads.
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
export function useEditFieldDocCustomInstructions(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
122
|
+
const { onCompleted, ...rest } = params;
|
|
123
|
+
const [editFieldDocCustomInstructions, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocCustomInstructionsMtn, {
|
|
124
|
+
openModalPopUp,
|
|
125
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
126
|
+
onCompleted?.(data?.editFieldDocCustomInstructions, error, variables);
|
|
127
|
+
},
|
|
128
|
+
...rest,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
editFieldDocCustomInstructions,
|
|
133
|
+
updateObservers,
|
|
134
|
+
...mtnValues,
|
|
135
|
+
...mtnHandlers,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Archive a custom fieldDoc; it and its submissions leave every list, and the server deletes them permanently after
|
|
141
|
+
* the retention window. There is no restore.
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
export function useArchiveFieldDoc(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
145
|
+
const [archiveFieldDoc, mtnValues, mtnHandlers, updateObservers] = useMutation(archiveFieldDocMtn, {
|
|
146
|
+
openModalPopUp,
|
|
147
|
+
...params,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
archiveFieldDoc,
|
|
152
|
+
updateObservers,
|
|
153
|
+
...mtnValues,
|
|
154
|
+
...mtnHandlers,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Permanently delete one fieldDoc submission.
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
export function useDeleteFieldDocSubmission(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
163
|
+
const [deleteFieldDocSubmission, mtnValues, mtnHandlers, updateObservers] = useMutation(deleteFieldDocSubmissionMtn, {
|
|
164
|
+
openModalPopUp,
|
|
165
|
+
...params,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
deleteFieldDocSubmission,
|
|
170
|
+
updateObservers,
|
|
171
|
+
...mtnValues,
|
|
172
|
+
...mtnHandlers,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Apply a versioned editor patch to one form's unpublished draft.
|
|
178
|
+
*/
|
|
26
179
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
180
|
+
export function useEditFieldDoc(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
181
|
+
const { onCompleted, ...rest } = params;
|
|
182
|
+
const [editFieldDoc, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocMtn, {
|
|
183
|
+
openModalPopUp,
|
|
184
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
185
|
+
onCompleted?.(data?.editFieldDoc, error, variables);
|
|
186
|
+
},
|
|
187
|
+
...rest,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
editFieldDoc,
|
|
192
|
+
updateObservers,
|
|
193
|
+
...mtnValues,
|
|
194
|
+
...mtnHandlers,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Publish or discard one form's editor draft.
|
|
200
|
+
*/
|
|
38
201
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
202
|
+
export function useEditFieldDocSettings(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
203
|
+
const { onCompleted, ...rest } = params;
|
|
204
|
+
const [editFieldDocSettings, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocSettingsMtn, {
|
|
205
|
+
openModalPopUp,
|
|
206
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
207
|
+
onCompleted?.(data?.editFieldDocSettings, error, variables);
|
|
208
|
+
},
|
|
209
|
+
...rest,
|
|
210
|
+
});
|
|
43
211
|
|
|
44
212
|
return {
|
|
45
|
-
|
|
213
|
+
editFieldDocSettings,
|
|
46
214
|
updateObservers,
|
|
47
215
|
...mtnValues,
|
|
48
216
|
...mtnHandlers,
|
|
49
217
|
};
|
|
50
218
|
}
|
|
219
|
+
|
|
220
|
+
/*
|
|
221
|
+
* Create one group in an organization-owned program.
|
|
222
|
+
*/
|
|
223
|
+
export function useCreateFieldDocProgramGroup(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
224
|
+
const [createFieldDocProgramGroup, mtnValues, mtnHandlers, updateObservers] = useMutation(createFieldDocProgramGroupMtn, {
|
|
225
|
+
openModalPopUp,
|
|
226
|
+
...params,
|
|
227
|
+
});
|
|
228
|
+
return { createFieldDocProgramGroup, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/*
|
|
232
|
+
* Rename or reorder one group in an organization-owned program.
|
|
233
|
+
*/
|
|
234
|
+
export function useEditFieldDocProgramGroup(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
235
|
+
const [editFieldDocProgramGroup, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocProgramGroupMtn, {
|
|
236
|
+
openModalPopUp,
|
|
237
|
+
...params,
|
|
238
|
+
});
|
|
239
|
+
return { editFieldDocProgramGroup, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/*
|
|
243
|
+
* Delete a group and move its forms to ungrouped.
|
|
244
|
+
*/
|
|
245
|
+
export function useDeleteFieldDocProgramGroup(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
246
|
+
const [deleteFieldDocProgramGroup, mtnValues, mtnHandlers, updateObservers] = useMutation(deleteFieldDocProgramGroupMtn, {
|
|
247
|
+
openModalPopUp,
|
|
248
|
+
...params,
|
|
249
|
+
});
|
|
250
|
+
return { deleteFieldDocProgramGroup, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/*
|
|
254
|
+
* Change form placement without editing its published definition.
|
|
255
|
+
*/
|
|
256
|
+
export function useEditFieldDocPlacement(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
257
|
+
const [editFieldDocPlacement, mtnValues, mtnHandlers, updateObservers] = useMutation(editFieldDocPlacementMtn, {
|
|
258
|
+
openModalPopUp,
|
|
259
|
+
...params,
|
|
260
|
+
});
|
|
261
|
+
return { editFieldDocPlacement, updateObservers, ...mtnValues, ...mtnHandlers };
|
|
262
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getFieldDocSubmissionsVariables, normalizeFieldDocSubmissionsFilter } from './use-fieldDoc-qry.helpers.ts';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Throw one readable test failure when a condition is false.
|
|
5
|
+
*/
|
|
6
|
+
function expect(value: unknown, message: string) {
|
|
7
|
+
if (!value) {
|
|
8
|
+
throw new Error(message);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Deno.test('the submissions filter keeps only FieldDocSubmissionsFilter fields', () => {
|
|
13
|
+
const filter = normalizeFieldDocSubmissionsFilter({
|
|
14
|
+
fieldDocProgramId: 'P1',
|
|
15
|
+
fieldDocIds: ['D1', 'D2'],
|
|
16
|
+
statuses: ['OPEN'],
|
|
17
|
+
startPeriod: '2026-10-01',
|
|
18
|
+
siteId: '',
|
|
19
|
+
sort: 'PERIOD_DESC',
|
|
20
|
+
startDate: '2026-10-01',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(
|
|
24
|
+
JSON.stringify(filter) ===
|
|
25
|
+
JSON.stringify({
|
|
26
|
+
fieldDocProgramId: 'P1',
|
|
27
|
+
fieldDocIds: ['D1', 'D2'],
|
|
28
|
+
siteId: null,
|
|
29
|
+
statuses: ['OPEN'],
|
|
30
|
+
startPeriod: '2026-10-01',
|
|
31
|
+
endPeriod: null,
|
|
32
|
+
}),
|
|
33
|
+
'URL-only keys are dropped and every input field is present in one fixed order.',
|
|
34
|
+
);
|
|
35
|
+
expect(
|
|
36
|
+
JSON.stringify(normalizeFieldDocSubmissionsFilter({ fieldDocProgramId: 'P1' })) ===
|
|
37
|
+
JSON.stringify(normalizeFieldDocSubmissionsFilter({ fieldDocProgramId: 'P1', preset: 'x' })),
|
|
38
|
+
'Equal filters build equal variables, so every consumer shares one cache entry.',
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
Deno.test('the first page and fetchMore follow the logEntries cursor contract', () => {
|
|
43
|
+
const first = getFieldDocSubmissionsVariables({ organizationId: 'O1', filter: { fieldDocProgramId: 'P1' } });
|
|
44
|
+
expect(
|
|
45
|
+
first.cursor === null && first.after === true && first.limit === 100 && first.organizationId === 'O1',
|
|
46
|
+
'The first page has no cursor, after true and the fixed limit.',
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const next = getFieldDocSubmissionsVariables({
|
|
50
|
+
organizationId: 'O1',
|
|
51
|
+
filter: { fieldDocProgramId: 'P1' },
|
|
52
|
+
cursor: 'C1',
|
|
53
|
+
after: false,
|
|
54
|
+
limit: 40,
|
|
55
|
+
sort: 'PERIOD_DESC',
|
|
56
|
+
} as any);
|
|
57
|
+
expect(
|
|
58
|
+
next.cursor === 'C1' && next.after === false && next.limit === 40,
|
|
59
|
+
'fetchMore keeps the row cursor, the direction and the requested page size.',
|
|
60
|
+
);
|
|
61
|
+
expect(
|
|
62
|
+
JSON.stringify(Object.keys(next)) === JSON.stringify(['organizationId', 'filter', 'cursor', 'after', 'limit']),
|
|
63
|
+
'Only the declared query variables are sent; the route table sort is dropped.',
|
|
64
|
+
);
|
|
65
|
+
});
|