@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,14 @@
1
+ import { useMutation } from '../client/index.ts';
2
+ import { resumeAIChatStreamMtn } from '../gql/mutations/aiChatMutations.ts';
3
+ import type { UseMutationParams } from '../types.d.ts';
4
+
5
+ /*
6
+ * Request a fresh authenticated subscription to an existing durable chat run.
7
+ */
8
+ export function useResumeAIChatStream(params: UseMutationParams = {}) {
9
+ const [resumeAIChatStream, values] = useMutation(
10
+ resumeAIChatStreamMtn,
11
+ params,
12
+ );
13
+ return { resumeAIChatStream, ...values };
14
+ }
@@ -0,0 +1,170 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import * as documents from '../gql/mutations/audienceMutations.ts';
4
+ import { useMutation } from './index.ts';
5
+
6
+ /*
7
+ * Create an organization-owned reusable list.
8
+ */
9
+ export function useCreateAudienceList(
10
+ params: UseMutationParams = {},
11
+ openModalPopUp?: OpenModalPopUpFn,
12
+ ) {
13
+ const { onCompleted, ...rest } = params;
14
+ const [createAudienceList, mtnValues, mtnHandlers, updateObservers] =
15
+ useMutation(documents.createAudienceListMtn, {
16
+ openModalPopUp,
17
+ onCompleted: (data, error, variables) => {
18
+ onCompleted?.(data?.createAudienceList, error, variables);
19
+ },
20
+ ...rest,
21
+ });
22
+ return { createAudienceList, updateObservers, ...mtnValues, ...mtnHandlers };
23
+ }
24
+
25
+ /*
26
+ * Edit, archive, or restore a list using its expected edit version.
27
+ */
28
+ export function useEditAudienceList(
29
+ params: UseMutationParams = {},
30
+ openModalPopUp?: OpenModalPopUpFn,
31
+ ) {
32
+ const { onCompleted, ...rest } = params;
33
+ const [editAudienceList, mtnValues, mtnHandlers, updateObservers] =
34
+ useMutation(documents.editAudienceListMtn, {
35
+ openModalPopUp,
36
+ onCompleted: (data, error, variables) => {
37
+ onCompleted?.(data?.editAudienceList, error, variables);
38
+ },
39
+ ...rest,
40
+ });
41
+ return { editAudienceList, updateObservers, ...mtnValues, ...mtnHandlers };
42
+ }
43
+
44
+ /*
45
+ * Edit one list recipient's profile using its expected membership version.
46
+ */
47
+ export function useEditAudienceListMember(
48
+ params: UseMutationParams = {},
49
+ openModalPopUp?: OpenModalPopUpFn,
50
+ ) {
51
+ const { onCompleted, ...rest } = params;
52
+ const [editAudienceListMember, mtnValues, mtnHandlers, updateObservers] =
53
+ useMutation(documents.editAudienceListMemberMtn, {
54
+ openModalPopUp,
55
+ onCompleted: (data, error, variables) => {
56
+ onCompleted?.(data?.editAudienceListMember, error, variables);
57
+ },
58
+ ...rest,
59
+ });
60
+ return {
61
+ editAudienceListMember,
62
+ updateObservers,
63
+ ...mtnValues,
64
+ ...mtnHandlers,
65
+ };
66
+ }
67
+
68
+ /*
69
+ * Import a bounded batch while preserving subscription preferences and retry identity.
70
+ */
71
+ export function useAddAudienceListMembers(
72
+ params: UseMutationParams = {},
73
+ openModalPopUp?: OpenModalPopUpFn,
74
+ ) {
75
+ const { onCompleted, ...rest } = params;
76
+ const [addAudienceListMembers, mtnValues, mtnHandlers, updateObservers] =
77
+ useMutation(documents.addAudienceListMembersMtn, {
78
+ openModalPopUp,
79
+ onCompleted: (data, error, variables) => {
80
+ onCompleted?.(data?.addAudienceListMembers, error, variables);
81
+ },
82
+ ...rest,
83
+ });
84
+ return {
85
+ addAudienceListMembers,
86
+ updateObservers,
87
+ ...mtnValues,
88
+ ...mtnHandlers,
89
+ };
90
+ }
91
+
92
+ /*
93
+ * Apply an explicit consent-aware subscription transition.
94
+ */
95
+ export function useChangeAudienceListSubscription(
96
+ params: UseMutationParams = {},
97
+ openModalPopUp?: OpenModalPopUpFn,
98
+ ) {
99
+ const { onCompleted, ...rest } = params;
100
+ const [
101
+ changeAudienceListSubscription,
102
+ mtnValues,
103
+ mtnHandlers,
104
+ updateObservers,
105
+ ] = useMutation(documents.changeAudienceListSubscriptionMtn, {
106
+ openModalPopUp,
107
+ onCompleted: (data, error, variables) => {
108
+ onCompleted?.(data?.changeAudienceListSubscription, error, variables);
109
+ },
110
+ ...rest,
111
+ });
112
+ return {
113
+ changeAudienceListSubscription,
114
+ updateObservers,
115
+ ...mtnValues,
116
+ ...mtnHandlers,
117
+ };
118
+ }
119
+
120
+ /*
121
+ * Remove list membership while preserving its durable subscription history.
122
+ */
123
+ export function useRemoveAudienceListMembers(
124
+ params: UseMutationParams = {},
125
+ openModalPopUp?: OpenModalPopUpFn,
126
+ ) {
127
+ const { onCompleted, ...rest } = params;
128
+ const [removeAudienceListMembers, mtnValues, mtnHandlers, updateObservers] =
129
+ useMutation(documents.removeAudienceListMembersMtn, {
130
+ openModalPopUp,
131
+ onCompleted: (data, error, variables) => {
132
+ onCompleted?.(data?.removeAudienceListMembers, error, variables);
133
+ },
134
+ ...rest,
135
+ });
136
+ return {
137
+ removeAudienceListMembers,
138
+ updateObservers,
139
+ ...mtnValues,
140
+ ...mtnHandlers,
141
+ };
142
+ }
143
+
144
+ /*
145
+ * Apply or clear exactly one address suppression with a recorded reason.
146
+ */
147
+ export function useSetAudienceAddressSuppression(
148
+ params: UseMutationParams = {},
149
+ openModalPopUp?: OpenModalPopUpFn,
150
+ ) {
151
+ const { onCompleted, ...rest } = params;
152
+ const [
153
+ setAudienceAddressSuppression,
154
+ mtnValues,
155
+ mtnHandlers,
156
+ updateObservers,
157
+ ] = useMutation(documents.setAudienceAddressSuppressionMtn, {
158
+ openModalPopUp,
159
+ onCompleted: (data, error, variables) => {
160
+ onCompleted?.(data?.setAudienceAddressSuppression, error, variables);
161
+ },
162
+ ...rest,
163
+ });
164
+ return {
165
+ setAudienceAddressSuppression,
166
+ updateObservers,
167
+ ...mtnValues,
168
+ ...mtnHandlers,
169
+ };
170
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Reject the query client's retained output while organization or page variables change.
3
+ */
4
+ export function isAudienceQueryCurrent(
5
+ queryName: string,
6
+ queryKey: string | null | undefined,
7
+ variablesKey: string,
8
+ ): boolean {
9
+ return queryKey === `#${queryName}:${variablesKey}`;
10
+ }
11
+
12
+ /*
13
+ * Hide retained responses while a new scope loads, including explicitly skipped queries.
14
+ */
15
+ export function getAudienceQueryOutput<T extends Record<string, unknown>>(
16
+ result: {
17
+ data: T | null | undefined;
18
+ queryName: string;
19
+ queryKey: string | null | undefined;
20
+ variablesKey: string;
21
+ error?: unknown;
22
+ },
23
+ skipped: boolean,
24
+ ) {
25
+ const current =
26
+ !skipped &&
27
+ isAudienceQueryCurrent(
28
+ result.queryName,
29
+ result.queryKey,
30
+ result.variablesKey,
31
+ );
32
+ return {
33
+ data: current ? (result.data ?? null) : null,
34
+ initialLoading:
35
+ !skipped &&
36
+ !result.error &&
37
+ (!current || result.data?.[result.queryName] === undefined),
38
+ };
39
+ }
@@ -0,0 +1,245 @@
1
+ import {
2
+ useQuery,
3
+ useReactiveFragment,
4
+ useReactiveFragmentMap,
5
+ } from '@jsb188/graphql/client';
6
+ import {
7
+ FRAGMENT_NAMES,
8
+ getFragmentBaseName,
9
+ makeFragmentKey,
10
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
11
+ import type { DocumentNode } from 'graphql';
12
+ import type * as Audience from '../audience.d.ts';
13
+ import * as documents from '../gql/queries/audienceQueries.ts';
14
+ import type { UseQueryParams } from '../types.d.ts';
15
+ import { getAudienceQueryOutput } from './use-audience-qry.helpers.ts';
16
+
17
+ /*
18
+ * Keep audience results tied to their current organization and page variables.
19
+ * Server changes refresh them through each query's declaration in the shared client.
20
+ */
21
+ function useAudienceQuery(
22
+ query: DocumentNode,
23
+ variables: Record<string, unknown>,
24
+ skip: boolean,
25
+ params: UseQueryParams,
26
+ ) {
27
+ const { data, ...rest } = useQuery(query, {
28
+ ...params,
29
+ variables,
30
+ skip: skip || params.skip,
31
+ });
32
+ return {
33
+ ...rest,
34
+ ...getAudienceQueryOutput({ data, ...rest }, skip || !!params.skip),
35
+ };
36
+ }
37
+
38
+ /*
39
+ * Read organization-owned lists with bounded keyset pagination.
40
+ */
41
+ export function useAudienceLists(
42
+ variables: Audience.AudienceListsArgs,
43
+ params: UseQueryParams = {},
44
+ ) {
45
+ const { data, ...rest } = useAudienceQuery(
46
+ documents.audienceListsQry,
47
+ {
48
+ ...variables,
49
+ filter: variables.filter ?? null,
50
+ sort: variables.sort ?? 'CREATED_DESC',
51
+ cursor: variables.cursor ?? null,
52
+ after: variables.after ?? true,
53
+ limit: variables.limit ?? 50,
54
+ },
55
+ !variables.organizationId,
56
+ params,
57
+ );
58
+ const audienceLists = (data?.audienceLists ?? null) as
59
+ | Audience.AudienceListGQL[]
60
+ | null;
61
+ const reactiveLists = useReactiveAudienceListFragmentMap(
62
+ audienceLists,
63
+ rest.updatedCount,
64
+ );
65
+ return {
66
+ audienceLists: audienceLists ? reactiveLists : null,
67
+ ...rest,
68
+ };
69
+ }
70
+
71
+ /*
72
+ * Read the current metadata and concurrency version for one list.
73
+ */
74
+ export function useAudienceList(
75
+ variables: { organizationId?: string | null; audienceListId?: string | null },
76
+ params: UseQueryParams = {},
77
+ ) {
78
+ const { data, ...rest } = useAudienceQuery(
79
+ documents.audienceListQry,
80
+ variables,
81
+ !variables.organizationId || !variables.audienceListId,
82
+ params,
83
+ );
84
+ const audienceList = (data?.audienceList ??
85
+ null) as Audience.AudienceListGQL | null;
86
+ const reactiveList = useReactiveAudienceListFragment(
87
+ variables.audienceListId,
88
+ audienceList,
89
+ rest.updatedCount,
90
+ );
91
+ return {
92
+ audienceList: audienceList ? reactiveList : null,
93
+ ...rest,
94
+ };
95
+ }
96
+
97
+ /*
98
+ * Read membership preferences with their current shared address health.
99
+ */
100
+ export function useAudienceListMembers(
101
+ variables: Audience.AudienceListMembersArgs,
102
+ params: UseQueryParams = {},
103
+ ) {
104
+ const { data, ...rest } = useAudienceQuery(
105
+ documents.audienceListMembersQry,
106
+ {
107
+ ...variables,
108
+ sort: variables.sort ?? 'CREATED_DESC',
109
+ cursor: variables.cursor ?? null,
110
+ after: variables.after ?? true,
111
+ limit: variables.limit ?? 200,
112
+ },
113
+ !variables.organizationId || !variables.filter.audienceListId,
114
+ params,
115
+ );
116
+ return {
117
+ audienceListMembers: (data?.audienceListMembers ?? null) as
118
+ | Audience.AudienceListMemberGQL[]
119
+ | null,
120
+ ...rest,
121
+ };
122
+ }
123
+
124
+ /*
125
+ * Observe one reusable audience's current metadata after queries or mutations update its fragment.
126
+ */
127
+ export function useReactiveAudienceListFragment(
128
+ audienceListId?: string | null,
129
+ currentData?: Audience.AudienceListGQL | null,
130
+ queryCount?: number,
131
+ ): Audience.AudienceListGQL | null | undefined {
132
+ const list = useReactiveFragment(
133
+ currentData,
134
+ audienceListId
135
+ ? [makeFragmentKey(FRAGMENT_NAMES.audienceList, audienceListId)]
136
+ : [],
137
+ queryCount,
138
+ );
139
+ return list?.id === audienceListId ? list : null;
140
+ }
141
+
142
+ /*
143
+ * Observe list metadata in a picker through each reusable audience's fragment identity.
144
+ */
145
+ export function useReactiveAudienceListFragmentMap(
146
+ lists?: Audience.AudienceListGQL[] | null,
147
+ queryCount?: number,
148
+ ): Audience.AudienceListGQL[] | null {
149
+ return useReactiveFragmentMap(
150
+ lists || null,
151
+ getFragmentBaseName(FRAGMENT_NAMES.audienceList),
152
+ queryCount,
153
+ );
154
+ }
155
+
156
+ /*
157
+ * Observe recipient preferences and the nested shared mailbox health through their own fragment identities.
158
+ */
159
+ export function useReactiveAudienceListMemberFragment(
160
+ memberId: string,
161
+ currentData?: Audience.AudienceListMemberGQL | null,
162
+ queryCount?: number,
163
+ ): Audience.AudienceListMemberGQL | null | undefined {
164
+ const observe: Array<string | [string, string | null]> = [
165
+ makeFragmentKey(FRAGMENT_NAMES.audienceListMember, memberId),
166
+ ];
167
+ if (currentData?.emailAddressId)
168
+ observe.push([
169
+ makeFragmentKey(
170
+ FRAGMENT_NAMES.audienceEmailAddress,
171
+ currentData.emailAddressId,
172
+ ),
173
+ 'address',
174
+ ]);
175
+ const member = useReactiveFragment(currentData, observe, queryCount);
176
+ return member?.id === memberId ? member : null;
177
+ }
178
+
179
+ /*
180
+ * Read calculated subscription and sending-eligibility counts.
181
+ */
182
+ export function useAudienceListOverview(
183
+ variables: { organizationId?: string | null; audienceListId?: string | null },
184
+ params: UseQueryParams = {},
185
+ ) {
186
+ const { data, ...rest } = useAudienceQuery(
187
+ documents.audienceListOverviewQry,
188
+ variables,
189
+ !variables.organizationId || !variables.audienceListId,
190
+ params,
191
+ );
192
+ return {
193
+ audienceListOverview: (data?.audienceListOverview ??
194
+ null) as Audience.AudienceListOverviewGQL | null,
195
+ ...rest,
196
+ };
197
+ }
198
+
199
+ /*
200
+ * Read one address without retaining another organization’s result during navigation.
201
+ */
202
+ export function useAudienceEmailAddress(
203
+ variables: { organizationId?: string | null; emailAddressId?: string | null },
204
+ params: UseQueryParams = {},
205
+ ) {
206
+ const { data, ...rest } = useAudienceQuery(
207
+ documents.audienceEmailAddressQry,
208
+ variables,
209
+ !variables.organizationId || !variables.emailAddressId,
210
+ params,
211
+ );
212
+ return {
213
+ audienceEmailAddress: (data?.audienceEmailAddress ??
214
+ null) as Audience.AudienceEmailAddressGQL | null,
215
+ ...rest,
216
+ };
217
+ }
218
+
219
+ /*
220
+ * Read address history with stable event-id pagination.
221
+ */
222
+ export function useAudienceAddressHistory(
223
+ variables: {
224
+ organizationId?: string | null;
225
+ emailAddressId?: string | null;
226
+ } & Audience.AudiencePageArgs,
227
+ params: UseQueryParams = {},
228
+ ) {
229
+ const { data, ...rest } = useAudienceQuery(
230
+ documents.audienceAddressHistoryQry,
231
+ {
232
+ ...variables,
233
+ afterId: variables.afterId ?? null,
234
+ limit: variables.limit ?? 50,
235
+ },
236
+ !variables.organizationId || !variables.emailAddressId,
237
+ params,
238
+ );
239
+ return {
240
+ audienceAddressHistory: (data?.audienceAddressHistory ?? null) as
241
+ | Audience.AudienceEventGQL[]
242
+ | null,
243
+ ...rest,
244
+ };
245
+ }
@@ -9,6 +9,7 @@ import {
9
9
  } from '@jsb188/react/states';
10
10
  import React, { useContext, useEffect, useState } from 'react';
11
11
  import {
12
+ authenticateAsAgentMtn,
12
13
  changeAccountPasswordMtn,
13
14
  checkUsernameOrEmailMtn,
14
15
  confirmPasswordMtn,
@@ -158,7 +159,7 @@ export function useChangeAccountPassword(
158
159
  openModalPopUp?.({
159
160
  name: 'password_changed',
160
161
  props: {
161
- title: i18n.t('form.success'),
162
+ title: i18n.t('c.success'),
162
163
  message: i18n.t('auth.password_changed_msg'),
163
164
  iconName: 'lock-password-filled',
164
165
  },
@@ -320,6 +321,34 @@ export function useConfirmPhoneVerificationCode(
320
321
  };
321
322
  }
322
323
 
324
+ /**
325
+ * Development-only: sign in as any account without a password. The server
326
+ * mutation is inert outside a local development database.
327
+ */
328
+
329
+ export function useAuthenticateAsAgent(
330
+ params: UseMutationParams = {},
331
+ openModalPopUp?: OpenModalPopUpFn,
332
+ ) {
333
+ const { onCompleted, onError } = params;
334
+
335
+ const [authenticateAsAgent, mtnValues, mtnHandlers] = useMutation(
336
+ authenticateAsAgentMtn,
337
+ {
338
+ checkMountedBeforeCallback: true,
339
+ openModalPopUp,
340
+ onCompleted,
341
+ onError,
342
+ },
343
+ );
344
+
345
+ return {
346
+ authenticateAsAgent,
347
+ ...mtnValues,
348
+ ...mtnHandlers,
349
+ };
350
+ }
351
+
323
352
  /**
324
353
  * Sign in
325
354
  */
@@ -0,0 +1,31 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import { startBillingSubscriptionMtn } from '../gql/mutations/billingMutations.ts';
3
+ import { useMutation } from './index.ts';
4
+
5
+ /*
6
+ * Start a self-serve subscription for an organization. The response carries a
7
+ * Stripe client secret, so it is never cached (no-store) and never retried.
8
+ * There is deliberately no openModalPopUp option: the payment pop-up renders
9
+ * errors inline, and opening another pop-up would replace it.
10
+ */
11
+ export function useStartBillingSubscription(params: UseMutationParams = {}) {
12
+ const { onCompleted, onError } = params;
13
+
14
+ const [startBillingSubscription, mtnValues, mtnHandlers] = useMutation(
15
+ startBillingSubscriptionMtn,
16
+ {
17
+ cachePolicy: 'no-store',
18
+ retryCount: 0,
19
+ onCompleted: (data, error, variables) => {
20
+ onCompleted?.(data?.startBillingSubscription, error, variables);
21
+ },
22
+ onError,
23
+ },
24
+ );
25
+
26
+ return {
27
+ startBillingSubscription,
28
+ ...mtnValues,
29
+ ...mtnHandlers,
30
+ };
31
+ }
@@ -0,0 +1,76 @@
1
+ import { useQuery } from '@jsb188/graphql/client';
2
+ import type { BillingAddressInputGQL } from '@jsb188/mday/types/billing.d.ts';
3
+ import {
4
+ billingClientConfigQry,
5
+ billingPlansQry,
6
+ billingPurchasePreviewQry,
7
+ organizationBillingQry,
8
+ } from '../gql/queries/billingQueries.ts';
9
+ import type { UseQueryParams } from '../types.d.ts';
10
+
11
+ export type BillingPurchasePreviewVariables = {
12
+ organizationId?: string | null;
13
+ priceId?: string | null;
14
+ address?: BillingAddressInputGQL | null;
15
+ };
16
+
17
+ /*
18
+ * Fetch the self-serve plans: Basic and Business with their public prices,
19
+ * and Enterprise as a contact-sales plan without prices.
20
+ */
21
+ export function useBillingPlans(params: UseQueryParams = {}) {
22
+ // The public plan catalog can reuse fresh data; billing state still revalidates on entry.
23
+ const { data, ...rest } = useQuery(billingPlansQry, { revalidateOnMount: false, ...params });
24
+
25
+ return {
26
+ billingPlans: data?.billingPlans,
27
+ ...rest,
28
+ };
29
+ }
30
+
31
+ /*
32
+ * Fetch the Stripe publishable key and payment method types the payment form
33
+ * must use. The server picks the key, so its mode always matches the secret key.
34
+ */
35
+ export function useBillingClientConfig(params: UseQueryParams = {}) {
36
+ const { data, ...rest } = useQuery(billingClientConfigQry, params);
37
+
38
+ return {
39
+ billingClientConfig: data?.billingClientConfig,
40
+ ...rest,
41
+ };
42
+ }
43
+
44
+ /*
45
+ * Fetch an organization's billing status: access state, current subscription
46
+ * and recent invoices. Skipped until an organization id is known.
47
+ */
48
+ export function useOrganizationBilling(organizationId: string | null | undefined, params: UseQueryParams = {}) {
49
+ const { data, ...rest } = useQuery(organizationBillingQry, {
50
+ ...params,
51
+ variables: { organizationId },
52
+ skip: !organizationId || !!params.skip,
53
+ });
54
+
55
+ return {
56
+ organizationBilling: data?.organizationBilling,
57
+ ...rest,
58
+ };
59
+ }
60
+
61
+ /*
62
+ * Preview the subtotal, tax and total of one plan price for a billing address.
63
+ * Skipped until the organization, price and address are all set.
64
+ */
65
+ export function useBillingPurchasePreview(variables: BillingPurchasePreviewVariables, params: UseQueryParams = {}) {
66
+ const { data, ...rest } = useQuery(billingPurchasePreviewQry, {
67
+ ...params,
68
+ variables,
69
+ skip: !variables.organizationId || !variables.priceId || !variables.address || !!params.skip,
70
+ });
71
+
72
+ return {
73
+ billingPurchasePreview: data?.billingPurchasePreview,
74
+ ...rest,
75
+ };
76
+ }