@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
@@ -0,0 +1,26 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import { setInboundEmailSenderBlockedMtn } from '../gql/mutations/emailMutations.ts';
4
+ import { useMutation } from './index.ts';
5
+
6
+ /**
7
+ * Block or unblock the sender of one inbound email for the organization's agent inbox.
8
+ */
9
+
10
+ export function useSetInboundEmailSenderBlocked(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
11
+ const { onCompleted, ...rest } = params;
12
+
13
+ const [setInboundEmailSenderBlocked, mtnValues, mtnHandlers] = useMutation(setInboundEmailSenderBlockedMtn, {
14
+ openModalPopUp,
15
+ onCompleted: (data, error, variables) => {
16
+ onCompleted?.(data?.setInboundEmailSenderBlocked, error, variables);
17
+ },
18
+ ...rest,
19
+ });
20
+
21
+ return {
22
+ setInboundEmailSenderBlocked,
23
+ ...mtnValues,
24
+ ...mtnHandlers,
25
+ };
26
+ }
@@ -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
+ emailOutreachId: filter.emailOutreachId || 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
+ }
@@ -1,227 +1,97 @@
1
1
  import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
2
- import type {
3
- InboundEmailGQL,
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 { emailMessageConversationPageQry, 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 EMAILS_LIST_LIMIT = 250;
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
- }
11
+ const EMAIL_MESSAGES_LIST_LIMIT = 250;
68
12
 
69
13
  /*
70
- * Fetch one inbound email.
14
+ * Fetch one inbound or outbound email message.
71
15
  */
72
16
 
73
- export function useInboundEmail(
17
+ export function useEmailMessage(
74
18
  variables: {
75
19
  organizationId?: string | null;
76
- inboundEmailId?: string | null;
20
+ emailMessageId?: string | null;
77
21
  },
78
22
  params: UseQueryParams = {},
79
23
  ) {
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, {
24
+ const skip = !variables.organizationId || !variables.emailMessageId || !!params.skip;
25
+ const cachedEmailMessage = useReactiveEmailMessageFragment(variables.emailMessageId || '', null);
26
+ // Reuse the cached modal request; a list fragment alone still needs its details and conversation.
27
+ const { data, ...rest } = useQuery(emailMessageQry, {
91
28
  ...params,
29
+ revalidateOnMount: params.revalidateOnMount ?? false,
92
30
  variables,
93
- skip: !shouldFetchInboundEmail,
31
+ skip,
94
32
  });
95
-
33
+ const currentData = rest.queryKey === `#${rest.queryName}:${rest.variablesKey}` ? data : null;
34
+ const record =
35
+ currentData?.emailMessage === null
36
+ ? null
37
+ : getScopedEmailRecord<EmailMessageGQL>(currentData?.emailMessage, variables.organizationId, variables.emailMessageId, skip) ||
38
+ getScopedEmailRecord<EmailMessageGQL>(cachedEmailMessage, variables.organizationId, variables.emailMessageId, skip);
39
+
40
+ const emailMessage = record && { ...record, ...record.details };
96
41
  return {
97
- inboundEmail: cachedInboundEmail || data?.inboundEmail,
98
- initialLoading: shouldFetchInboundEmail && !data,
42
+ emailMessage,
43
+ initialLoading: !skip && !emailMessage && !rest.error && currentData?.emailMessage === undefined,
99
44
  ...rest,
100
45
  };
101
46
  }
102
47
 
103
48
  /**
104
- * Fetch inbound emails.
49
+ * Fetch inbound and outbound email messages as one list.
105
50
  */
106
51
 
107
- export function useInboundEmails(
52
+ export function useEmailMessages(
108
53
  variables: PaginationArgs & {
109
54
  organizationId?: string | null;
110
- filter?: EmailListFilter;
111
- sort?: InboundEmailsSortEnum | null;
55
+ filter?: EmailMessagesFilterInput | null;
56
+ sort?: EmailMessagesSortEnum | null;
112
57
  },
113
58
  params: UseQueryParams = {},
114
59
  ) {
115
- const { data, ...rest } = useQuery(inboundEmailsQry, {
60
+ const { data, ...rest } = useQuery(emailMessagesQry, {
116
61
  ...params,
117
62
  variables: {
118
63
  ...variables,
119
- filter: normalizeEmailsFilter(variables.filter),
120
- cursor: null,
121
- after: true,
122
- limit: EMAILS_LIST_LIMIT,
64
+ filter: normalizeEmailMessagesFilter(variables.filter),
65
+ cursor: variables.cursor ?? null,
66
+ after: variables.after ?? true,
67
+ limit: variables.limit ?? EMAIL_MESSAGES_LIST_LIMIT,
123
68
  },
124
69
  skip: !variables.organizationId || params.skip,
125
70
  });
126
71
 
127
72
  return {
128
- inboundEmails: data?.inboundEmails,
73
+ emailMessages: data?.emailMessages,
129
74
  ...rest,
130
75
  };
131
76
  }
132
77
 
133
- /*
134
- * Fetch one outbound email.
78
+ /**
79
+ * Get reactive email message fragment.
135
80
  */
136
81
 
137
- export function useOutboundEmail(
138
- variables: {
139
- organizationId?: string | null;
140
- outboundEmailId?: string | null;
141
- },
142
- params: UseQueryParams = {},
143
- ) {
144
- const cachedOutboundEmail = useReactiveOutboundEmailFragment(
145
- variables.outboundEmailId || '',
146
- null,
147
- );
148
- const shouldFetchOutboundEmail = shouldFetchEmailRecord(
149
- variables,
150
- variables.outboundEmailId,
151
- cachedOutboundEmail,
152
- params,
153
- );
154
- const { data, ...rest } = useQuery(outboundEmailQry, {
155
- ...params,
156
- variables,
157
- skip: !shouldFetchOutboundEmail,
158
- });
159
-
160
- return {
161
- outboundEmail: cachedOutboundEmail || data?.outboundEmail,
162
- initialLoading: shouldFetchOutboundEmail && !data,
163
- ...rest,
164
- };
82
+ export function useReactiveEmailMessageFragment(emailMessageId: string, currentData?: any, queryCount?: number) {
83
+ return useReactiveFragment(currentData, [`$emailMessageFragment:${emailMessageId}`], queryCount);
165
84
  }
166
85
 
167
- /**
168
- * Fetch outbound emails.
86
+ /*
87
+ * Read a continuation of the open conversation without fetching the selected message's details again.
169
88
  */
170
-
171
- export function useOutboundEmails(
172
- variables: PaginationArgs & {
173
- organizationId?: string | null;
174
- filter?: EmailListFilter;
175
- sort?: OutboundEmailsSortEnum | null;
176
- },
177
- params: UseQueryParams = {},
178
- ) {
179
- const { data, ...rest } = useQuery(outboundEmailsQry, {
180
- ...params,
181
- variables: {
182
- ...variables,
183
- filter: normalizeEmailsFilter(variables.filter),
184
- cursor: null,
185
- after: true,
186
- limit: EMAILS_LIST_LIMIT,
187
- },
188
- skip: !variables.organizationId || params.skip,
189
- });
190
-
89
+ export function useEmailMessageConversationPage(variables: { organizationId: string; emailMessageId: string; cursor: string }) {
90
+ const { data, ...rest } = useQuery(emailMessageConversationPageQry, { variables, revalidateOnMount: false });
91
+ const current = rest.queryKey === `#${rest.queryName}:${rest.variablesKey}` ? data?.emailMessageConversationPage : null;
191
92
  return {
192
- outboundEmails: data?.outboundEmails,
93
+ conversation: getScopedEmailRecord<EmailMessageGQL>(current, variables.organizationId, variables.emailMessageId, false)
94
+ ?.conversation,
193
95
  ...rest,
194
96
  };
195
97
  }
196
-
197
- /**
198
- * Get reactive inbound email fragment.
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.
215
- */
216
-
217
- export function useReactiveOutboundEmailFragment(
218
- outboundEmailId: string,
219
- currentData?: any,
220
- queryCount?: number,
221
- ) {
222
- return useReactiveFragment(
223
- currentData,
224
- [getEmailFragmentKey('outboundEmailFragment', outboundEmailId)],
225
- queryCount,
226
- );
227
- }
@@ -0,0 +1,211 @@
1
+ import {
2
+ createEmailOutreachDraftMtn,
3
+ editEmailOutreachDraftMtn,
4
+ sendEmailOutreachMtn,
5
+ rescheduleEmailOutreachMtn,
6
+ sendEmailOutreachTestMtn,
7
+ updateEmailOutreachReplyInstructionsMtn,
8
+ duplicateEmailOutreachMtn,
9
+ finalizeEmailOutreachImageUploadMtn,
10
+ } from '../gql/mutations/emailOutreachMutations.ts';
11
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
12
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
13
+ import {
14
+ archiveEmailOutreachMtn,
15
+ cancelEmailOutreachMtn,
16
+ retryEmailOutreachMtn,
17
+ unarchiveEmailOutreachMtn,
18
+ } from '../gql/mutations/emailOutreachMutations.ts';
19
+ import { useMutation } from './index.ts';
20
+
21
+ /*
22
+ * Cancel a SCHEDULED outreach. The input echoes the outreach's deliveryVersion as
23
+ * expectedDeliveryVersion; the full returned record updates the shared fragment.
24
+ */
25
+ export function useCancelEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
26
+ const { onCompleted, ...rest } = params;
27
+ const [cancelEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(cancelEmailOutreachMtn, {
28
+ openModalPopUp,
29
+ /*
30
+ * Unwrap the cancelled outreach for hook consumers.
31
+ */
32
+ onCompleted: (data, error, variables) => {
33
+ onCompleted?.(data?.cancelEmailOutreach, error, variables);
34
+ },
35
+ ...rest,
36
+ });
37
+ return { cancelEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
38
+ }
39
+
40
+ /*
41
+ * Re-send the definitely failed deliveries of an outreach. The input echoes the
42
+ * outreach's deliveryVersion as expectedDeliveryVersion.
43
+ */
44
+ export function useRetryEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
45
+ const { onCompleted, ...rest } = params;
46
+ const [retryEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(retryEmailOutreachMtn, {
47
+ openModalPopUp,
48
+ /*
49
+ * Unwrap the retried outreach for hook consumers.
50
+ */
51
+ onCompleted: (data, error, variables) => {
52
+ onCompleted?.(data?.retryEmailOutreach, error, variables);
53
+ },
54
+ ...rest,
55
+ });
56
+ return { retryEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
57
+ }
58
+
59
+ /*
60
+ * Archive one outreach that is not scheduled or sending; archiving twice changes nothing.
61
+ */
62
+ export function useArchiveEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
63
+ const { onCompleted, ...rest } = params;
64
+ const [archiveEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(archiveEmailOutreachMtn, {
65
+ openModalPopUp,
66
+ /*
67
+ * Unwrap the archived outreach for hook consumers.
68
+ */
69
+ onCompleted: (data, error, variables) => {
70
+ onCompleted?.(data?.archiveEmailOutreach, error, variables);
71
+ },
72
+ ...rest,
73
+ });
74
+ return { archiveEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
75
+ }
76
+
77
+ /*
78
+ * Restore one archived outreach; restoring a current outreach changes nothing.
79
+ */
80
+ export function useUnarchiveEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
81
+ const { onCompleted, ...rest } = params;
82
+ const [unarchiveEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(unarchiveEmailOutreachMtn, {
83
+ openModalPopUp,
84
+ /*
85
+ * Unwrap the restored outreach for hook consumers.
86
+ */
87
+ onCompleted: (data, error, variables) => {
88
+ onCompleted?.(data?.unarchiveEmailOutreach, error, variables);
89
+ },
90
+ ...rest,
91
+ });
92
+ return { unarchiveEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
93
+ }
94
+
95
+ /* Create an incomplete editor draft. */
96
+ export function useCreateEmailOutreachDraft(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
97
+ const { onCompleted, ...rest } = params;
98
+ const [createEmailOutreachDraft, mtnValues, mtnHandlers, updateObservers] = useMutation(createEmailOutreachDraftMtn, {
99
+ openModalPopUp,
100
+ /* Return the shared record from the mutation response. */
101
+ onCompleted: (data, error, variables) => {
102
+ onCompleted?.(data?.createEmailOutreachDraft, error, variables);
103
+ },
104
+ ...rest,
105
+ });
106
+ return { createEmailOutreachDraft, updateObservers, ...mtnValues, ...mtnHandlers };
107
+ }
108
+
109
+ /* Save the whole document under its acknowledged edit version. */
110
+ export function useEditEmailOutreachDraft(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
111
+ const { onCompleted, ...rest } = params;
112
+ const [editEmailOutreachDraft, mtnValues, mtnHandlers, updateObservers] = useMutation(editEmailOutreachDraftMtn, {
113
+ openModalPopUp,
114
+ /* Return the shared record from the mutation response. */
115
+ onCompleted: (data, error, variables) => {
116
+ onCompleted?.(data?.editEmailOutreachDraft, error, variables);
117
+ },
118
+ ...rest,
119
+ });
120
+ return { editEmailOutreachDraft, updateObservers, ...mtnValues, ...mtnHandlers };
121
+ }
122
+
123
+ /* Approve and send the exact draft version shown in the editor. */
124
+ export function useSendEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
125
+ const { onCompleted, ...rest } = params;
126
+ const [sendEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(sendEmailOutreachMtn, {
127
+ openModalPopUp,
128
+ /* Return the shared record from the mutation response. */
129
+ onCompleted: (data, error, variables) => {
130
+ onCompleted?.(data?.sendEmailOutreach, error, variables);
131
+ },
132
+ ...rest,
133
+ });
134
+ return { sendEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
135
+ }
136
+
137
+ /* Move a scheduled send under its delivery version fence. */
138
+ export function useRescheduleEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
139
+ const { onCompleted, ...rest } = params;
140
+ const [rescheduleEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(rescheduleEmailOutreachMtn, {
141
+ openModalPopUp,
142
+ /* Return the shared record from the mutation response. */
143
+ onCompleted: (data, error, variables) => {
144
+ onCompleted?.(data?.rescheduleEmailOutreach, error, variables);
145
+ },
146
+ ...rest,
147
+ });
148
+ return { rescheduleEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
149
+ }
150
+
151
+ /* Send a saved preview to the verified requester or an authorized organization member. */
152
+ export function useSendEmailOutreachTest(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
153
+ const { onCompleted, ...rest } = params;
154
+ const [sendEmailOutreachTest, mtnValues, mtnHandlers, updateObservers] = useMutation(sendEmailOutreachTestMtn, {
155
+ openModalPopUp,
156
+ /* Return the shared record from the mutation response. */
157
+ onCompleted: (data, error, variables) => {
158
+ onCompleted?.(data?.sendEmailOutreachTest, error, variables);
159
+ },
160
+ ...rest,
161
+ });
162
+ return { sendEmailOutreachTest, updateObservers, ...mtnValues, ...mtnHandlers };
163
+ }
164
+
165
+ /* Update reply handling while preserving sent content. */
166
+ export function useUpdateEmailOutreachReplyInstructions(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
167
+ const { onCompleted, ...rest } = params;
168
+ const [updateEmailOutreachReplyInstructions, mtnValues, mtnHandlers, updateObservers] = useMutation(
169
+ updateEmailOutreachReplyInstructionsMtn,
170
+ {
171
+ openModalPopUp,
172
+ /* Return the shared record from the mutation response. */
173
+ onCompleted: (data, error, variables) => {
174
+ onCompleted?.(data?.updateEmailOutreachReplyInstructions, error, variables);
175
+ },
176
+ ...rest,
177
+ },
178
+ );
179
+ return { updateEmailOutreachReplyInstructions, updateObservers, ...mtnValues, ...mtnHandlers };
180
+ }
181
+
182
+ /* Copy an outreach into a new unscheduled draft. */
183
+ export function useDuplicateEmailOutreach(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
184
+ const { onCompleted, ...rest } = params;
185
+ const [duplicateEmailOutreach, mtnValues, mtnHandlers, updateObservers] = useMutation(duplicateEmailOutreachMtn, {
186
+ openModalPopUp,
187
+ /* Return the shared record from the mutation response. */
188
+ onCompleted: (data, error, variables) => {
189
+ onCompleted?.(data?.duplicateEmailOutreach, error, variables);
190
+ },
191
+ ...rest,
192
+ });
193
+ return { duplicateEmailOutreach, updateObservers, ...mtnValues, ...mtnHandlers };
194
+ }
195
+
196
+ /* Finalize a browser image upload before attaching it to the editor. */
197
+ export function useFinalizeEmailOutreachImageUpload(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
198
+ const { onCompleted, ...rest } = params;
199
+ const [finalizeEmailOutreachImageUpload, mtnValues, mtnHandlers, updateObservers] = useMutation(
200
+ finalizeEmailOutreachImageUploadMtn,
201
+ {
202
+ openModalPopUp,
203
+ /* Return the shared record from the mutation response. */
204
+ onCompleted: (data, error, variables) => {
205
+ onCompleted?.(data?.finalizeEmailOutreachImageUpload, error, variables);
206
+ },
207
+ ...rest,
208
+ },
209
+ );
210
+ return { finalizeEmailOutreachImageUpload, updateObservers, ...mtnValues, ...mtnHandlers };
211
+ }
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Keep outreach data scoped to the active organization, outreach and filters while
3
+ * the shared query client retains an earlier response during navigation.
4
+ */
5
+ export function getEmailOutreachQueryData<T>(
6
+ result: {
7
+ data?: T | null;
8
+ queryKey: string;
9
+ queryName: string;
10
+ variablesKey: string;
11
+ },
12
+ skipped: boolean,
13
+ ): T | null {
14
+ return !skipped && result.queryKey === `#${result.queryName}:${result.variablesKey}` ? (result.data ?? null) : null;
15
+ }
16
+
17
+ /*
18
+ * Return only the requested outreach; its owning organization remains available to the page's login guard.
19
+ */
20
+ export function getScopedEmailOutreach<T extends { id: string }>(
21
+ outreach: T | null | undefined,
22
+ emailOutreachId: string | null | undefined,
23
+ ): T | null {
24
+ return emailOutreachId && outreach?.id === emailOutreachId ? outreach : null;
25
+ }