@jsb188/graphql 1.1.10 → 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.
Files changed (176) hide show
  1. package/audience.d.ts +343 -0
  2. package/cache/config.ts +98 -50
  3. package/cache/index.chat-activity.test.ts +119 -0
  4. package/cache/index.chat.test.ts +92 -0
  5. package/cache/index.helpers.ts +96 -0
  6. package/cache/index.regression.test.ts +149 -0
  7. package/cache/index.test.ts +1017 -127
  8. package/cache/index.ts +1256 -1269
  9. package/cache/optimistic-ui-runtime.ts +46 -0
  10. package/cache/optimistic-ui.ts +401 -0
  11. package/cache/persist.ts +800 -0
  12. package/cache/store.ts +395 -0
  13. package/cache/value.helpers.ts +17 -0
  14. package/client/draft-persistence-indexed-db.ts +413 -0
  15. package/client/draft-persistence.ts +152 -0
  16. package/client/index.ts +3 -0
  17. package/client/request.helpers.ts +14 -0
  18. package/client/request.ts +870 -164
  19. package/deno.lock +187 -0
  20. package/deno.test.json +10 -4
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +0 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentMemoryFragments.ts +23 -0
  26. package/gql/fragments/agentNoteFragments.ts +150 -0
  27. package/gql/fragments/aiChatFragments.ts +42 -0
  28. package/gql/fragments/audienceFragments.ts +141 -0
  29. package/gql/fragments/campaignFragments.ts +566 -0
  30. package/gql/fragments/dataTableFragments.ts +50 -192
  31. package/gql/fragments/emailFragments.ts +32 -17
  32. package/gql/fragments/fieldDocFragments.ts +264 -0
  33. package/gql/fragments/inboundContactFragments.ts +2 -0
  34. package/gql/fragments/logFragments.ts +101 -69
  35. package/gql/fragments/organizationFragments.ts +53 -5
  36. package/gql/fragments/qrCodeFragments.ts +29 -0
  37. package/gql/fragments/scheduleFragments.ts +667 -0
  38. package/gql/fragments/sheetFragments.ts +304 -63
  39. package/gql/fragments/storageFragments.ts +45 -0
  40. package/gql/fragments/workflowFragments.ts +41 -5
  41. package/gql/mutations/accountMutations.ts +0 -2
  42. package/gql/mutations/agentMemoryMutations.ts +68 -0
  43. package/gql/mutations/agentNoteMutations.ts +62 -0
  44. package/gql/mutations/aiChatMutations.ts +49 -4
  45. package/gql/mutations/audienceMutations.ts +71 -0
  46. package/gql/mutations/authMutations.ts +203 -18
  47. package/gql/mutations/billingMutations.ts +17 -27
  48. package/gql/mutations/campaignMutations.ts +258 -0
  49. package/gql/mutations/contactMutations.ts +23 -0
  50. package/gql/mutations/dataTableMutations.ts +19 -54
  51. package/gql/mutations/fieldDocMutations.ts +173 -0
  52. package/gql/mutations/index.ts +10 -2
  53. package/gql/mutations/logMutations.ts +6 -29
  54. package/gql/mutations/organizationMutations.ts +19 -4
  55. package/gql/mutations/qrCodeMutations.ts +20 -0
  56. package/gql/mutations/scheduleMutations.ts +1121 -0
  57. package/gql/mutations/sheetMutations.ts +221 -60
  58. package/gql/mutations/storageMutations.ts +19 -0
  59. package/gql/mutations/workflowMutations.ts +60 -0
  60. package/gql/queries/agentMemoryQueries.ts +28 -0
  61. package/gql/queries/agentNoteQueries.ts +89 -0
  62. package/gql/queries/aiChatQueries.ts +70 -2
  63. package/gql/queries/audienceQueries.ts +128 -0
  64. package/gql/queries/authQueries.ts +47 -0
  65. package/gql/queries/billingQueries.ts +118 -6
  66. package/gql/queries/campaignQueries.ts +236 -0
  67. package/gql/queries/dataTableQueries.ts +61 -13
  68. package/gql/queries/emailQueries.ts +26 -17
  69. package/gql/queries/emailReplyReportQueries.ts +76 -0
  70. package/gql/queries/fieldDocQueries.ts +166 -0
  71. package/gql/queries/inboundContactQueries.ts +4 -0
  72. package/gql/queries/index.ts +10 -2
  73. package/gql/queries/logQueries.ts +68 -30
  74. package/gql/queries/organizationQueries.ts +65 -1
  75. package/gql/queries/qrCodeQueries.ts +20 -0
  76. package/gql/queries/scheduleQueries.ts +691 -0
  77. package/gql/queries/sheetQueries.ts +244 -26
  78. package/gql/queries/storageQueries.ts +38 -0
  79. package/gql/queries/workflowQueries.ts +77 -2
  80. package/hooks/index.helpers.test.ts +50 -0
  81. package/hooks/index.helpers.ts +52 -0
  82. package/hooks/index.ts +2254 -982
  83. package/hooks/use-account-mtn.ts +76 -81
  84. package/hooks/use-agentMemory-mtn.ts +71 -0
  85. package/hooks/use-agentMemory-qry.ts +56 -0
  86. package/hooks/use-agentNote-mtn.ts +82 -0
  87. package/hooks/use-agentNote-qry.ts +190 -0
  88. package/hooks/use-agentNote-recovery.helpers.test.ts +68 -0
  89. package/hooks/use-agentNote-recovery.helpers.ts +58 -0
  90. package/hooks/use-agentNote-recovery.ts +72 -0
  91. package/hooks/use-aiChat-mtn.ts +220 -141
  92. package/hooks/use-aiChat-qry.helpers.test.ts +63 -0
  93. package/hooks/use-aiChat-qry.helpers.ts +124 -0
  94. package/hooks/use-aiChat-qry.ts +341 -237
  95. package/hooks/use-aiChat-stream-mtn.ts +14 -0
  96. package/hooks/use-app-qry.ts +12 -9
  97. package/hooks/use-audience-mtn.ts +194 -0
  98. package/hooks/use-audience-qry.helpers.test.ts +80 -0
  99. package/hooks/use-audience-qry.helpers.ts +63 -0
  100. package/hooks/use-audience-qry.ts +330 -0
  101. package/hooks/use-auth-mtn.ts +435 -252
  102. package/hooks/use-auth-qry.ts +51 -0
  103. package/hooks/use-billing-mtn.ts +31 -0
  104. package/hooks/use-billing-qry.ts +76 -0
  105. package/hooks/use-campaign-generation-recovery.ts +53 -0
  106. package/hooks/use-campaign-mtn.ts +436 -0
  107. package/hooks/use-campaign-qry.helpers.ts +40 -0
  108. package/hooks/use-campaign-qry.ts +834 -0
  109. package/hooks/use-dataTable-mtn.ts +37 -46
  110. package/hooks/use-dataTable-qry.ts +102 -128
  111. package/hooks/use-email-qry.helpers.ts +37 -0
  112. package/hooks/use-email-qry.ts +56 -86
  113. package/hooks/use-emailCampaignReplyReport-qry.ts +27 -0
  114. package/hooks/use-fieldDoc-mtn.ts +262 -0
  115. package/hooks/use-fieldDoc-qry.helpers.test.ts +65 -0
  116. package/hooks/use-fieldDoc-qry.helpers.ts +49 -0
  117. package/hooks/use-fieldDoc-qry.ts +212 -0
  118. package/hooks/use-inboundContact-mtn.ts +19 -16
  119. package/hooks/use-inboundContact-qry.ts +62 -56
  120. package/hooks/use-integration-mtn.ts +56 -38
  121. package/hooks/use-integration-qry.ts +24 -9
  122. package/hooks/use-log-mtn.ts +88 -59
  123. package/hooks/use-log-qry.ts +150 -73
  124. package/hooks/use-organization-mtn.ts +334 -277
  125. package/hooks/use-organization-qry.ts +155 -129
  126. package/hooks/use-publicFormEmail-mtn.ts +27 -0
  127. package/hooks/use-qrCode-mtn.ts +40 -0
  128. package/hooks/use-qrCode-qry.ts +78 -0
  129. package/hooks/use-schedule-mtn.ts +589 -0
  130. package/hooks/use-schedule-qry.ts +738 -0
  131. package/hooks/use-schedule-reactive.ts +486 -0
  132. package/hooks/use-sheet-mtn.ts +157 -79
  133. package/hooks/use-sheet-qry.ts +221 -92
  134. package/hooks/use-storage-mtn.ts +81 -41
  135. package/hooks/use-storage-qry.ts +128 -14
  136. package/hooks/use-workflow-mtn.ts +72 -0
  137. package/hooks/use-workflow-qry.ts +184 -47
  138. package/libs/ai-chat-outgoing.helpers.ts +153 -0
  139. package/libs/ai-chat-outgoing.ts +11 -0
  140. package/libs/ai-chat-outgoing.types.ts +25 -0
  141. package/libs/ai-chat-run-realtime.ts +20 -0
  142. package/libs/ai-chat-submission-realtime.ts +150 -0
  143. package/libs/fragment-realtime-sequence.ts +55 -0
  144. package/libs/fragment-recovery.test.ts +326 -0
  145. package/libs/fragment-recovery.ts +325 -0
  146. package/libs/open-sheet.ts +138 -0
  147. package/libs/orchestrator-realtime.helpers.test.ts +229 -0
  148. package/libs/orchestrator-realtime.helpers.ts +317 -0
  149. package/libs/orchestrator-realtime.ts +433 -0
  150. package/libs/request-cache-regression.test.ts +122 -0
  151. package/libs/request-managed-session.test.ts +574 -0
  152. package/libs/request-no-store.test.ts +419 -0
  153. package/libs/sheet-command-batch.ts +44 -0
  154. package/libs/sheet-view-realtime-router.test.ts +214 -0
  155. package/libs/sheet-view-realtime-router.ts +99 -0
  156. package/libs/sse-ticket.test.ts +26 -0
  157. package/loaders/campaign.test.ts +186 -0
  158. package/loaders/campaign.ts +110 -0
  159. package/loaders/emailPreference.ts +75 -0
  160. package/loaders/rest.ts +12 -0
  161. package/package.json +119 -71
  162. package/schedule.d.ts +1790 -0
  163. package/sse.helpers.ts +19 -0
  164. package/sse.ts +70 -106
  165. package/tests/agent-note-detail-cache.test.ts +120 -0
  166. package/tests/agent-note-search.test.ts +444 -0
  167. package/tsconfig.json +11 -10
  168. package/types.d.ts +77 -26
  169. package/utils.ts +78 -49
  170. package/gql/fragments/billingFragments.ts +0 -25
  171. package/gql/fragments/productFragments.ts +0 -39
  172. package/gql/fragments/reportFragments.ts +0 -90
  173. package/gql/queries/productQueries.ts +0 -31
  174. package/gql/queries/reportQueries.ts +0 -134
  175. package/hooks/use-product-qry.ts +0 -67
  176. package/hooks/use-report-qry.ts +0 -153
@@ -1,7 +1,18 @@
1
1
  import { useQuery, useReactiveFragment } from '@jsb188/graphql/client';
2
2
  import type { ChildOrgsFilterArgs } from '@jsb188/mday/types/organization.d.ts';
3
- export { useInboundContact, useInboundContacts, useReactiveInboundContactFragment } from './use-inboundContact-qry.ts';
4
- import { childOrganizationsQry, myOrganizationsQry, organizationMembersQry, organizationSitesQry } from '../gql/queries/organizationQueries.ts';
3
+ import { FRAGMENT_NAMES, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
4
+ export {
5
+ useInboundContact,
6
+ useInboundContacts,
7
+ useReactiveInboundContactFragment,
8
+ } from './use-inboundContact-qry.ts';
9
+ import {
10
+ childOrganizationsQry,
11
+ myOrganizationsQry,
12
+ organizationMembersQry,
13
+ organizationSitesQry,
14
+ pageRoutesQry,
15
+ } from '../gql/queries/organizationQueries.ts';
5
16
  import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
6
17
 
7
18
  const ORG_CHILDREN_LIMIT = 250;
@@ -11,12 +22,17 @@ const ORG_CHILDREN_LIMIT = 250;
11
22
  */
12
23
 
13
24
  export function useMyOrganizations(params: UseQueryParams = {}) {
14
- const { data, ...rest } = useQuery(myOrganizationsQry, params);
15
-
16
- return {
17
- myOrganizations: data?.myOrganizations,
18
- ...rest
19
- };
25
+ const { data, ...rest } = useQuery(myOrganizationsQry, {
26
+ ...params,
27
+ // Reuse fresh organization data when another modal mounts; refresh once the freshness window expires.
28
+ revalidateOnMount: params.revalidateOnMount ?? false,
29
+ persistTime: params.persistTime ?? 15 * 60 * 1000,
30
+ });
31
+
32
+ return {
33
+ myOrganizations: data?.myOrganizations,
34
+ ...rest,
35
+ };
20
36
  }
21
37
 
22
38
  /**
@@ -24,72 +40,64 @@ export function useMyOrganizations(params: UseQueryParams = {}) {
24
40
  */
25
41
 
26
42
  export function useOrganizationMembers(
27
- organizationId: string | null,
28
- paramsOrShowGuests: UseQueryParams | boolean = {},
29
- showGuests_: boolean = false,
43
+ organizationId: string | null,
44
+ paramsOrShowGuests: UseQueryParams | boolean = {},
45
+ showGuests_: boolean = false,
30
46
  ) {
31
- const params = typeof paramsOrShowGuests === 'boolean' ? {} : paramsOrShowGuests;
32
- const showGuests = typeof paramsOrShowGuests === 'boolean' ? paramsOrShowGuests : showGuests_;
33
-
34
- const { data, ...rest } = useQuery(organizationMembersQry, {
35
- variables: {
36
- organizationId,
37
- showGuests,
38
- },
39
- skip: !organizationId || params.skip,
40
- ...params,
41
- });
42
-
43
- return {
44
- organizationMembers: data?.organizationMembers,
45
- ...rest
46
- };
47
+ const params = typeof paramsOrShowGuests === 'boolean' ? {} : paramsOrShowGuests;
48
+ const showGuests = typeof paramsOrShowGuests === 'boolean' ? paramsOrShowGuests : showGuests_;
49
+
50
+ const { data, ...rest } = useQuery(organizationMembersQry, {
51
+ variables: {
52
+ organizationId,
53
+ showGuests,
54
+ },
55
+ skip: !organizationId || params.skip,
56
+ ...params,
57
+ });
58
+
59
+ return {
60
+ organizationMembers: data?.organizationMembers,
61
+ ...rest,
62
+ };
47
63
  }
48
64
 
49
65
  /**
50
66
  * Fetch organization sites
51
67
  */
52
68
 
53
- export function useOrganizationSites(
54
- organizationId: string | null,
55
- parentId: string | null,
56
- params: UseQueryParams = {},
57
- ) {
58
- const { data, ...rest } = useQuery(organizationSitesQry, {
59
- variables: {
60
- organizationId,
61
- parentId,
62
- },
63
- skip: !organizationId || params.skip,
64
- ...params,
65
- });
66
-
67
- return {
68
- organizationSites: data?.organizationSites,
69
- ...rest
70
- };
69
+ export function useOrganizationSites(organizationId: string | null, parentId: string | null, params: UseQueryParams = {}) {
70
+ const { data, ...rest } = useQuery(organizationSitesQry, {
71
+ variables: {
72
+ organizationId,
73
+ parentId,
74
+ },
75
+ skip: !organizationId || params.skip,
76
+ ...params,
77
+ });
78
+
79
+ return {
80
+ organizationSites: data?.organizationSites,
81
+ ...rest,
82
+ };
71
83
  }
72
84
 
73
85
  export function useReactiveOrganization(orgId: string, currentData?: any, queryCount?: number) {
74
- return useReactiveFragment(
75
- currentData,
76
- [`$organizationFragment:${orgId}`],
77
- queryCount,
78
- );
86
+ return useReactiveFragment(currentData, [makeFragmentKey(FRAGMENT_NAMES.organization, orgId)], queryCount);
79
87
  }
80
88
 
81
89
  /*
82
90
  * Get reactive organization settings fragment data.
83
91
  */
84
92
  export function useReactiveOrganizationSettings(orgId: string | null | undefined, currentData?: any, queryCount?: number) {
85
- return useReactiveFragment(
86
- currentData,
87
- orgId ? [`$organizationSettingsFragment:${orgId}`] : [],
88
- queryCount,
89
- undefined,
90
- undefined,
91
- true,
92
- );
93
+ return useReactiveFragment(
94
+ currentData,
95
+ orgId ? [makeFragmentKey(FRAGMENT_NAMES.organizationSettings, orgId)] : [],
96
+ queryCount,
97
+ undefined,
98
+ undefined,
99
+ true,
100
+ );
93
101
  }
94
102
 
95
103
  /**
@@ -97,79 +105,86 @@ export function useReactiveOrganizationSettings(orgId: string | null | undefined
97
105
  */
98
106
 
99
107
  export function useOrgRelFromMyOrganizations(organizationId: string | null) {
100
- const { myOrganizations, ...rest } = useMyOrganizations({
101
- skip: !organizationId,
102
- });
103
-
104
- const orgRel = myOrganizations?.find((orgRel: any) => orgRel.organization?.id === organizationId) || null;
105
- const reactiveOrganization = useReactiveOrganization(orgRel?.organization?.id, orgRel?.organization);
106
- const reactiveSettings = useReactiveOrganizationSettings(reactiveOrganization?.id, reactiveOrganization?.settings);
107
- const organization = reactiveOrganization && reactiveSettings
108
- ? {
109
- ...reactiveOrganization,
110
- settings: reactiveSettings,
111
- }
112
- : reactiveOrganization;
113
- const organizationRelationship = orgRel && organization
114
- ? {
115
- ...orgRel,
116
- organization,
117
- }
118
- : orgRel;
119
-
120
- return {
121
- organizationRelationship,
122
- organization,
123
- myOrganizations,
124
- ...rest
125
- };
108
+ const { myOrganizations, ...rest } = useMyOrganizations({
109
+ skip: !organizationId,
110
+ });
111
+
112
+ const orgRel = myOrganizations?.find((orgRel: any) => orgRel.organization?.id === organizationId) || null;
113
+ const reactiveOrganization = useReactiveOrganization(orgRel?.organization?.id, orgRel?.organization);
114
+ const reactiveSettings = useReactiveOrganizationSettings(reactiveOrganization?.id, reactiveOrganization?.settings);
115
+ const organization =
116
+ reactiveOrganization && reactiveSettings
117
+ ? {
118
+ ...reactiveOrganization,
119
+ settings: reactiveSettings,
120
+ }
121
+ : reactiveOrganization;
122
+ const organizationRelationship =
123
+ orgRel && organization
124
+ ? {
125
+ ...orgRel,
126
+ organization,
127
+ }
128
+ : orgRel;
129
+
130
+ return {
131
+ organizationRelationship,
132
+ organization,
133
+ myOrganizations,
134
+ ...rest,
135
+ };
126
136
  }
127
137
 
128
138
  /**
129
139
  * Fetch child organizations
130
140
  */
131
141
 
132
- export function useChildOrganizations(variables: PaginationArgs & {
133
- organizationId?: string | null;
134
- filter?: ChildOrgsFilterArgs;
135
- }, params: UseQueryParams = {}) {
136
- const { data, ...rest } = useQuery(childOrganizationsQry, {
137
- variables: {
138
- ...variables,
139
- cursor: null,
140
- after: true,
141
- limit: ORG_CHILDREN_LIMIT
142
- },
143
- skip: !variables.organizationId,
144
- ...params,
145
- });
146
-
147
- return {
148
- childOrganizations: data?.childOrganizations,
149
- ...rest
150
- };
142
+ export function useChildOrganizations(
143
+ variables: PaginationArgs & {
144
+ organizationId?: string | null;
145
+ filter?: ChildOrgsFilterArgs;
146
+ },
147
+ params: UseQueryParams = {},
148
+ ) {
149
+ const { data, ...rest } = useQuery(childOrganizationsQry, {
150
+ variables: {
151
+ ...variables,
152
+ cursor: null,
153
+ after: true,
154
+ limit: ORG_CHILDREN_LIMIT,
155
+ },
156
+ skip: !variables.organizationId,
157
+ ...params,
158
+ });
159
+
160
+ return {
161
+ childOrganizations: data?.childOrganizations,
162
+ ...rest,
163
+ };
151
164
  }
152
165
 
153
166
  /**
154
167
  * Get reactive organization fragment
155
168
  */
156
169
 
157
- export function useReactiveOrganizationChildFragment(childId: string, currentData?: any, queryCount?: number, mainPrioritizedFields?: string[]) {
158
- const organizationId = currentData?.organization?.id;
159
-
160
- return useReactiveFragment(
161
- currentData,
162
- [
163
- `$organizationChildFragment:${childId}`,
164
- organizationId ? [`$organizationFragment:${organizationId}`, 'organization'] : null,
165
- // [`$organizationChildArableFragment:${childId}`, null],
166
- // By having the second paramter as null, we only observe the reactive changes without setting the data
167
- // [`$logArableFragment:${logEntryId}`, null],
168
- ].filter(Boolean) as Array<string | [string, string | null]>,
169
- queryCount,
170
- undefined,
171
- mainPrioritizedFields,
172
- );
170
+ export function useReactiveOrganizationChildFragment(
171
+ childId: string,
172
+ currentData?: any,
173
+ queryCount?: number,
174
+ mainPrioritizedFields?: string[],
175
+ ) {
176
+ const organizationId = currentData?.organization?.id;
177
+
178
+ return useReactiveFragment(
179
+ currentData,
180
+ [
181
+ makeFragmentKey(FRAGMENT_NAMES.organizationChild, childId),
182
+ organizationId ? [makeFragmentKey(FRAGMENT_NAMES.organization, organizationId), 'organization'] : null,
183
+ ].filter(Boolean) as Array<string | [string, string | null]>,
184
+ queryCount,
185
+ undefined,
186
+ mainPrioritizedFields,
187
+ );
173
188
  }
174
189
 
175
190
  /**
@@ -177,14 +192,25 @@ export function useReactiveOrganizationChildFragment(childId: string, currentDat
177
192
  */
178
193
 
179
194
  export function useReactiveOrganizationComplianceFragment(complianceId: string, currentData?: any, queryCount?: number) {
180
- return useReactiveFragment(
181
- currentData,
182
- [
183
- `$organizationComplianceFragment:${complianceId}`,
184
- // [`$organizationChildArableFragment:${organizationId}`, null],
185
- // By having the second paramter as null, we only observe the reactive changes without setting the data
186
- // [`$logArableFragment:${logEntryId}`, null],
187
- ],
188
- queryCount,
189
- );
195
+ return useReactiveFragment(currentData, [makeFragmentKey(FRAGMENT_NAMES.organizationCompliance, complianceId)], queryCount);
196
+ }
197
+
198
+ /**
199
+ * Fetch custom page routes for organization
200
+ */
201
+
202
+ export function usePageRoutes(organizationId: string | null, params: UseQueryParams = {}) {
203
+ const { skip, ...restParams } = params;
204
+ const { data, ...rest } = useQuery(pageRoutesQry, {
205
+ variables: {
206
+ organizationId,
207
+ },
208
+ skip: skip || !organizationId,
209
+ ...restParams,
210
+ });
211
+
212
+ return {
213
+ pageRoutes: data?.pageRoutes,
214
+ ...rest,
215
+ };
190
216
  }
@@ -0,0 +1,27 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import { confirmPublicFormEmailCodeMtn, sendPublicFormEmailCodeMtn } from '../gql/mutations/authMutations.ts';
3
+ import { useMutation } from './index.ts';
4
+
5
+ /*
6
+ * Request a numeric email code for temporary public-form respondent access.
7
+ */
8
+ export function useSendPublicFormEmailCode(params: UseMutationParams = {}) {
9
+ const [sendPublicFormEmailCode, mutation, handlers] = useMutation(sendPublicFormEmailCodeMtn, {
10
+ ...params,
11
+ checkMountedBeforeCallback: true,
12
+ });
13
+
14
+ return { sendPublicFormEmailCode, ...mutation, ...handlers };
15
+ }
16
+
17
+ /*
18
+ * Verify a public-form email code without adopting an account session.
19
+ */
20
+ export function useConfirmPublicFormEmailCode(params: UseMutationParams = {}) {
21
+ const [confirmPublicFormEmailCode, mutation, handlers] = useMutation(confirmPublicFormEmailCodeMtn, {
22
+ ...params,
23
+ checkMountedBeforeCallback: true,
24
+ });
25
+
26
+ return { confirmPublicFormEmailCode, ...mutation, ...handlers };
27
+ }
@@ -0,0 +1,40 @@
1
+ import type { UseMutationParams } from '@jsb188/graphql/types.d';
2
+ import type { OpenModalPopUpFn } from '@jsb188/react/states';
3
+ import { createQrCodeMtn, editQrCodeMtn } from '../gql/mutations/qrCodeMutations.ts';
4
+ import { useMutation } from './index.ts';
5
+
6
+ /*
7
+ * Issue a QR code and report its full saved record through the completion callback.
8
+ */
9
+ export function useCreateQrCode(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
10
+ const { onCompleted, ...rest } = params;
11
+ const [createQrCode, mtnValues, mtnHandlers] = useMutation(createQrCodeMtn, {
12
+ openModalPopUp,
13
+ /*
14
+ * Expose the created record while shared mutation handling caches its complete fragment.
15
+ */
16
+ onCompleted: (data, error, variables) => {
17
+ onCompleted?.(data?.createQrCode, error, variables);
18
+ },
19
+ ...rest,
20
+ });
21
+ return { createQrCode, ...mtnValues, ...mtnHandlers };
22
+ }
23
+
24
+ /*
25
+ * Rename, archive, or restore QR metadata; server events refresh affected lists.
26
+ */
27
+ export function useEditQrCode(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
28
+ const { onCompleted, ...rest } = params;
29
+ const [editQrCode, mtnValues, mtnHandlers] = useMutation(editQrCodeMtn, {
30
+ openModalPopUp,
31
+ /*
32
+ * Expose the updated record without manually mutating query or fragment caches.
33
+ */
34
+ onCompleted: (data, error, variables) => {
35
+ onCompleted?.(data?.editQrCode, error, variables);
36
+ },
37
+ ...rest,
38
+ });
39
+ return { editQrCode, ...mtnValues, ...mtnHandlers };
40
+ }
@@ -0,0 +1,78 @@
1
+ import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '@jsb188/graphql/client';
2
+ import { FRAGMENT_NAMES, getFragmentBaseName, makeFragmentKey } from '@jsb188/mday/constants/graphqlReactivity.ts';
3
+ import type { QrCodeGQL, QrCodesQueryArgs } from '@jsb188/mday/types/qrCode.d.ts';
4
+ import { qrCodeQry, qrCodesQry } from '../gql/queries/qrCodeQueries.ts';
5
+ import type { UseQueryParams } from '../types.d.ts';
6
+
7
+ /*
8
+ * Fetch one authorized code by exactly one identifier and observe metadata under its returned GraphQL identity.
9
+ */
10
+ export function useQrCode(
11
+ variables: { organizationId?: string | null; qrCodeId?: string | null; publicId?: string | null },
12
+ params: UseQueryParams = {},
13
+ ) {
14
+ const { organizationId = null, qrCodeId = null, publicId = null } = variables;
15
+ const skipped = !organizationId || (qrCodeId === null) === (publicId === null) || !!params.skip;
16
+ const { data, ...rest } = useQuery(qrCodeQry, {
17
+ ...params,
18
+ variables: { organizationId, qrCodeId, publicId },
19
+ skip: skipped,
20
+ });
21
+ const current = !skipped && rest.queryKey === `#${rest.queryName}:${rest.variablesKey}`;
22
+ const candidate = (current && !rest.error ? data?.qrCode : null) as QrCodeGQL | null;
23
+ const record =
24
+ candidate?.organizationId === organizationId && (qrCodeId !== null ? candidate?.id === qrCodeId : candidate?.publicId === publicId)
25
+ ? candidate
26
+ : null;
27
+ const reactive = useReactiveQrCodeFragment(record?.id, record, rest.updatedCount);
28
+ return {
29
+ ...rest,
30
+ qrCode:
31
+ record && reactive?.organizationId === organizationId && (publicId === null || reactive.publicId === publicId) ? reactive : null,
32
+ initialLoading: !skipped && !rest.error && !record,
33
+ };
34
+ }
35
+
36
+ /*
37
+ * Read newest-first QR pages; organization-scoped server resets refresh list membership.
38
+ */
39
+ export function useQrCodes(variables: QrCodesQueryArgs, params: UseQueryParams = {}) {
40
+ const skipped = !variables.organizationId || !!params.skip;
41
+ const { data, ...rest } = useQuery(qrCodesQry, {
42
+ ...params,
43
+ variables: {
44
+ ...variables,
45
+ filter: variables.filter ?? null,
46
+ cursor: variables.cursor ?? null,
47
+ limit: variables.limit ?? 100,
48
+ },
49
+ skip: skipped,
50
+ });
51
+ const current = !skipped && rest.queryKey === `#${rest.queryName}:${rest.variablesKey}`;
52
+ const records = (current ? (data?.qrCodes ?? null) : null) as QrCodeGQL[] | null;
53
+ const reactive = useReactiveQrCodeFragmentMap(records, rest.updatedCount);
54
+ return {
55
+ ...rest,
56
+ qrCodes: records ? reactive : null,
57
+ initialLoading: !skipped && !rest.error && !records,
58
+ };
59
+ }
60
+
61
+ /*
62
+ * Observe the full shared QR fragment without returning a previous record after an identity change.
63
+ */
64
+ export function useReactiveQrCodeFragment(
65
+ qrCodeId?: string | null,
66
+ currentData?: QrCodeGQL | null,
67
+ queryCount?: number,
68
+ ): QrCodeGQL | null {
69
+ const code = useReactiveFragment(currentData, qrCodeId ? [makeFragmentKey(FRAGMENT_NAMES.qrCode, qrCodeId)] : [], queryCount);
70
+ return code?.id === qrCodeId ? code : null;
71
+ }
72
+
73
+ /*
74
+ * Observe QR rows by their canonical fragment identity for lists and virtualized tables.
75
+ */
76
+ export function useReactiveQrCodeFragmentMap(codes?: QrCodeGQL[] | null, queryCount?: number): QrCodeGQL[] | null {
77
+ return useReactiveFragmentMap(codes || null, getFragmentBaseName(FRAGMENT_NAMES.qrCode), queryCount);
78
+ }