@jsb188/graphql 1.1.8 → 1.1.11

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 (122) hide show
  1. package/cache/config.ts +66 -42
  2. package/cache/index.test.ts +881 -0
  3. package/cache/index.ts +1815 -979
  4. package/cache/persist.ts +721 -0
  5. package/cache/store.ts +437 -0
  6. package/client/data-table-realtime-subscriptions.test.ts +740 -0
  7. package/client/data-table-realtime-subscriptions.ts +955 -0
  8. package/client/data-table-realtime.test.ts +792 -0
  9. package/client/data-table-realtime.ts +1218 -0
  10. package/client/fragment-realtime-sequence.ts +52 -0
  11. package/client/index.ts +4 -2
  12. package/client/open-sheet.ts +137 -0
  13. package/client/request-managed-session.test.ts +574 -0
  14. package/client/request-no-store.test.ts +157 -0
  15. package/client/request.ts +973 -143
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +10 -0
  19. package/drafts/index.ts +149 -0
  20. package/drafts/store.ts +397 -0
  21. package/gql/eagerQueryMap.ts +12 -0
  22. package/gql/fragments/accountAuthFragments.ts +5 -0
  23. package/gql/fragments/accountFragments.ts +1 -3
  24. package/gql/fragments/accountSessionFragments.ts +16 -0
  25. package/gql/fragments/agentDocFragments.ts +46 -0
  26. package/gql/fragments/agentMemoryFragments.ts +19 -0
  27. package/gql/fragments/aiChatFragments.ts +17 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +102 -0
  31. package/gql/fragments/emailFragments.ts +36 -0
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/inboundContactFragments.ts +15 -0
  34. package/gql/fragments/integrationFragments.ts +22 -0
  35. package/gql/fragments/logFragments.ts +33 -64
  36. package/gql/fragments/organizationFragments.ts +94 -21
  37. package/gql/fragments/scheduleFragments.ts +155 -0
  38. package/gql/fragments/sheetFragments.ts +675 -0
  39. package/gql/fragments/storageFragments.ts +21 -1
  40. package/gql/fragments/workflowFragments.ts +67 -0
  41. package/gql/mutations/accountMutations.ts +24 -4
  42. package/gql/mutations/agentDocMutations.ts +177 -0
  43. package/gql/mutations/agentMemoryMutations.ts +36 -0
  44. package/gql/mutations/aiChatMutations.ts +43 -3
  45. package/gql/mutations/authMutations.ts +160 -19
  46. package/gql/mutations/campaignMutations.ts +215 -0
  47. package/gql/mutations/dataTableMutations.ts +106 -0
  48. package/gql/mutations/fieldDocMutations.ts +24 -0
  49. package/gql/mutations/inboundContactMutations.ts +24 -0
  50. package/gql/mutations/index.ts +17 -8
  51. package/gql/mutations/integrationMutations.ts +25 -0
  52. package/gql/mutations/logMutations.ts +10 -19
  53. package/gql/mutations/organizationMutations.ts +160 -2
  54. package/gql/mutations/scheduleMutations.ts +423 -0
  55. package/gql/mutations/sheetMutations.ts +385 -0
  56. package/gql/mutations/storageMutations.ts +21 -2
  57. package/gql/mutations/workflowMutations.ts +42 -0
  58. package/gql/queries/agentDocQueries.ts +120 -0
  59. package/gql/queries/agentMemoryQueries.ts +22 -0
  60. package/gql/queries/aiChatQueries.ts +18 -2
  61. package/gql/queries/authQueries.ts +41 -0
  62. package/gql/queries/billingQueries.ts +24 -1
  63. package/gql/queries/campaignQueries.ts +127 -0
  64. package/gql/queries/dataTableQueries.ts +134 -0
  65. package/gql/queries/emailQueries.ts +96 -0
  66. package/gql/queries/fieldDocQueries.ts +158 -0
  67. package/gql/queries/inboundContactQueries.ts +40 -0
  68. package/gql/queries/index.ts +17 -6
  69. package/gql/queries/logQueries.ts +42 -32
  70. package/gql/queries/organizationQueries.ts +113 -8
  71. package/gql/queries/scheduleQueries.ts +315 -0
  72. package/gql/queries/sheetQueries.ts +383 -0
  73. package/gql/queries/storageQueries.ts +38 -0
  74. package/gql/queries/workflowQueries.ts +99 -0
  75. package/hooks/index.ts +2104 -860
  76. package/hooks/use-account-mtn.ts +91 -48
  77. package/hooks/use-agentDoc-mtn.ts +285 -0
  78. package/hooks/use-agentDoc-qry.ts +208 -0
  79. package/hooks/use-agentMemory-mtn.ts +73 -0
  80. package/hooks/use-agentMemory-qry.ts +44 -0
  81. package/hooks/use-aiChat-mtn.ts +248 -97
  82. package/hooks/use-aiChat-qry.ts +501 -191
  83. package/hooks/use-app-qry.ts +14 -11
  84. package/hooks/use-auth-mtn.ts +410 -256
  85. package/hooks/use-auth-qry.ts +51 -0
  86. package/hooks/use-campaign-mtn.ts +377 -0
  87. package/hooks/use-campaign-qry.ts +257 -0
  88. package/hooks/use-dataTable-mtn.ts +170 -0
  89. package/hooks/use-dataTable-qry.ts +996 -0
  90. package/hooks/use-email-qry.ts +227 -0
  91. package/hooks/use-fieldDoc-mtn.ts +50 -0
  92. package/hooks/use-fieldDoc-qry.ts +180 -0
  93. package/hooks/use-inboundContact-mtn.ts +34 -0
  94. package/hooks/use-inboundContact-qry.ts +96 -0
  95. package/hooks/use-integration-mtn.ts +77 -0
  96. package/hooks/use-integration-qry.ts +30 -0
  97. package/hooks/use-log-mtn.ts +77 -61
  98. package/hooks/use-log-qry.ts +99 -72
  99. package/hooks/use-organization-mtn.ts +409 -80
  100. package/hooks/use-organization-qry.ts +211 -92
  101. package/hooks/use-schedule-mtn.ts +416 -0
  102. package/hooks/use-schedule-qry.ts +157 -0
  103. package/hooks/use-sheet-mtn.ts +367 -0
  104. package/hooks/use-sheet-qry.ts +440 -0
  105. package/hooks/use-storage-mtn.ts +83 -42
  106. package/hooks/use-storage-qry.ts +104 -13
  107. package/hooks/use-workflow-mtn.ts +55 -0
  108. package/hooks/use-workflow-qry.ts +230 -0
  109. package/loaders/campaign.ts +137 -0
  110. package/package.json +94 -52
  111. package/sse.ts +158 -105
  112. package/tsconfig.json +13 -0
  113. package/types.d.ts +60 -29
  114. package/utils.ts +77 -50
  115. package/gql/fragments/actionFragments.ts +0 -16
  116. package/gql/fragments/productFragments.ts +0 -63
  117. package/gql/fragments/reportFragments.ts +0 -48
  118. package/gql/mutations/billingMutations.ts +0 -34
  119. package/gql/queries/productQueries.ts +0 -70
  120. package/gql/queries/reportQueries.ts +0 -66
  121. package/hooks/use-product-qry.ts +0 -109
  122. package/hooks/use-report-qry.ts +0 -69
@@ -1,12 +1,19 @@
1
- import { checkACLPermission } from '@jsb188/mday/utils/organization';
1
+ import { checkACLPermission } from '@jsb188/mday/utils/organization.ts';
2
2
  import type { UseMutationParams } from '@jsb188/graphql/types.d';
3
3
  import { OpenModalPopUpFn } from '@jsb188/react/states';
4
+ import {
5
+ FRAGMENT_NAMES,
6
+ makeFragmentKey,
7
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
4
8
  import { useMemo } from 'react';
5
- import { updateFragment } from '../cache/index';
6
- import { deleteLogEntryMtn, editLogEntryMtn } from '../gql/mutations/logMutations';
7
- import { useMutation } from './index';
8
- import { useReactiveLogFragment } from './use-log-qry';
9
- import { useOrgRelFromMyOrganizations } from './use-organization-qry';
9
+ import { updateFragment } from '../cache/index.ts';
10
+ import {
11
+ deleteLogEntryMtn,
12
+ editLogEntryMtn,
13
+ } from '../gql/mutations/logMutations.ts';
14
+ import { useMutation } from './index.ts';
15
+ import { useReactiveLogFragment } from './use-log-qry.ts';
16
+ import { useOrgRelFromMyOrganizations } from './use-organization-qry.ts';
10
17
 
11
18
  /**
12
19
  * Fetch a single log entry,
@@ -14,45 +21,46 @@ import { useOrgRelFromMyOrganizations } from './use-organization-qry';
14
21
  */
15
22
 
16
23
  export function useEditLogEntry(
17
- viewerAccountId: string,
18
- logEntryId: string,
19
- organizationId: string,
20
- params: UseMutationParams = {},
21
- openModalPopUp?: OpenModalPopUpFn
24
+ viewerAccountId: string,
25
+ logEntryId: string,
26
+ organizationId: string,
27
+ params: UseMutationParams = {},
28
+ openModalPopUp?: OpenModalPopUpFn,
22
29
  ) {
30
+ const { organizationRelationship } =
31
+ useOrgRelFromMyOrganizations(organizationId);
32
+ const notReady = !organizationRelationship;
23
33
 
24
- const { organizationRelationship } = useOrgRelFromMyOrganizations(organizationId);
25
- const notReady = !organizationRelationship;
34
+ const [editLogEntry, mtnValues, mtnHandlers] = useMutation(editLogEntryMtn, {
35
+ // checkMountedBeforeCallback: true,
36
+ openModalPopUp,
37
+ ...params,
38
+ });
26
39
 
27
- const [editLogEntry, mtnValues, mtnHandlers] = useMutation(
28
- editLogEntryMtn,
29
- {
30
- // checkMountedBeforeCallback: true,
31
- openModalPopUp,
32
- ...params,
33
- },
34
- );
40
+ const logEntry = useReactiveLogFragment(
41
+ logEntryId,
42
+ null,
43
+ mtnValues.mutationCount,
44
+ );
35
45
 
36
- const logEntry = useReactiveLogFragment(logEntryId, null, mtnValues.mutationCount);
37
- // const logEntry = useReactiveFragment(
38
- // null,
39
- // [`$logEntryFragment:${logEntryId}`, [`$logArableFragment:${logEntryId}`, 'details']],
40
- // mtnValues.mutationCount,
41
- // );
46
+ const isMyDocument =
47
+ !!viewerAccountId && logEntry?.accountId === viewerAccountId;
48
+ const allowEdit = useMemo(() => {
49
+ return checkACLPermission(
50
+ organizationRelationship,
51
+ 'logs',
52
+ isMyDocument ? 'WRITE' : 'MANAGE',
53
+ );
54
+ }, [organizationRelationship?.acl, organizationRelationship?.role]);
42
55
 
43
- const isMyDocument = !!viewerAccountId && logEntry?.accountId === viewerAccountId;
44
- const allowEdit = useMemo(() => {
45
- return checkACLPermission(organizationRelationship, 'logs', isMyDocument ? 'WRITE' : 'MANAGE');
46
- }, [organizationRelationship?.acl, organizationRelationship?.role]);
47
-
48
- return {
49
- logEntry,
50
- editLogEntry,
51
- notReady,
52
- allowEdit,
53
- ...mtnValues,
54
- ...mtnHandlers,
55
- };
56
+ return {
57
+ logEntry,
58
+ editLogEntry,
59
+ notReady,
60
+ allowEdit,
61
+ ...mtnValues,
62
+ ...mtnHandlers,
63
+ };
56
64
  }
57
65
 
58
66
  /**
@@ -60,26 +68,34 @@ export function useEditLogEntry(
60
68
  * NOTE: Don't check ACL and allow server to handle it.
61
69
  */
62
70
 
63
- export function useDeleteLogEntry(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
64
-
65
- const { onCompleted, ...rest } = params;
66
- const [deleteLogEntry, mtnValues, mtnHandlers, updateObservers] = useMutation(
67
- deleteLogEntryMtn,
68
- {
69
- openModalPopUp,
70
- onCompleted: (data, dataMtnValues, variables) => {
71
- if (data?.deleteLogEntry) {
72
- updateFragment(`$logEntryFragment:${variables.logEntryId}`, { __deleted: true }, null, false, updateObservers);
73
- }
74
- onCompleted?.(data, dataMtnValues, variables);
75
- },
76
- ...rest,
77
- },
78
- );
71
+ export function useDeleteLogEntry(
72
+ params: UseMutationParams = {},
73
+ openModalPopUp?: OpenModalPopUpFn,
74
+ ) {
75
+ const { onCompleted, ...rest } = params;
76
+ const [deleteLogEntry, mtnValues, mtnHandlers, updateObservers] = useMutation(
77
+ deleteLogEntryMtn,
78
+ {
79
+ openModalPopUp,
80
+ onCompleted: (data, dataMtnValues, variables) => {
81
+ if (data?.deleteLogEntry) {
82
+ updateFragment(
83
+ makeFragmentKey(FRAGMENT_NAMES.logEntry, variables.logEntryId),
84
+ { __deleted: true },
85
+ null,
86
+ false,
87
+ updateObservers,
88
+ );
89
+ }
90
+ onCompleted?.(data, dataMtnValues, variables);
91
+ },
92
+ ...rest,
93
+ },
94
+ );
79
95
 
80
- return {
81
- deleteLogEntry,
82
- ...mtnValues,
83
- ...mtnHandlers,
84
- };
96
+ return {
97
+ deleteLogEntry,
98
+ ...mtnValues,
99
+ ...mtnHandlers,
100
+ };
85
101
  }
@@ -1,7 +1,18 @@
1
- import type { FilterLogEntriesArgs } from '@jsb188/mday/types/log.d';
2
- import { useQuery, useReactiveFragment } from '../client';
3
- import { logEntriesQry, logEvidencesQry } from '../gql/queries/logQueries';
4
- import type { PaginationArgs, UseQueryParams } from '../types';
1
+ import type {
2
+ FilterLogEntriesArgs,
3
+ LogSortEnum,
4
+ } from '@jsb188/mday/types/log.d.ts';
5
+ import {
6
+ FRAGMENT_NAMES,
7
+ makeFragmentKey,
8
+ } from '@jsb188/mday/constants/graphqlReactivity.ts';
9
+ import { useQuery, useReactiveFragment } from '../client/index.ts';
10
+ import {
11
+ logEntriesForFieldDocQry,
12
+ logEntriesQry,
13
+ logEntryQry,
14
+ } from '../gql/queries/logQueries.ts';
15
+ import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
5
16
 
6
17
  /**
7
18
  * Constants
@@ -13,17 +24,35 @@ import type { PaginationArgs, UseQueryParams } from '../types';
13
24
  const LOG_ENTRIES_LIMIT = 250;
14
25
 
15
26
  /**
16
- * Helper; use this to get/use same filter for logEntries() query everywhere
27
+ * Fetch one log entry.
17
28
  */
18
29
 
19
- export function getDefaultLogEntriesFilter(operation: FilterLogEntriesArgs['operation']): FilterLogEntriesArgs {
20
- return {
21
- operation,
22
- types: null,
23
- startDate: null,
24
- endDate: null,
25
- query: ''
26
- };
30
+ export function useLogEntry(
31
+ variables: {
32
+ organizationId?: string | null;
33
+ logEntryId?: string | null;
34
+ },
35
+ params: UseQueryParams = {},
36
+ ) {
37
+ const { logEntryId, organizationId } = variables;
38
+ const { data, ...rest } = useQuery(logEntryQry, {
39
+ ...params,
40
+ // A log can be changed outside the websocket mutation path, such as by a
41
+ // database repair. Revalidate it whenever the detail modal is opened.
42
+ persistTime: params.persistTime ?? 0,
43
+ variables,
44
+ skip: !organizationId || !logEntryId || params.skip,
45
+ });
46
+ const reactiveLogEntry = useReactiveLogFragment(
47
+ logEntryId || '',
48
+ data?.logEntry,
49
+ rest.updatedCount,
50
+ );
51
+
52
+ return {
53
+ logEntry: reactiveLogEntry || data?.logEntry,
54
+ ...rest,
55
+ };
27
56
  }
28
57
 
29
58
  /**
@@ -31,78 +60,76 @@ export function getDefaultLogEntriesFilter(operation: FilterLogEntriesArgs['oper
31
60
  */
32
61
 
33
62
  export function useLogEntries(
34
- variables: PaginationArgs & {
35
- organizationId?: string | null;
36
- accountId?: string;
37
- timeZone: string | null;
38
- filter: FilterLogEntriesArgs;
39
- },
40
- params: UseQueryParams = {}
63
+ variables: PaginationArgs & {
64
+ organizationId?: string | null;
65
+ accountId?: string;
66
+ filter: FilterLogEntriesArgs;
67
+ sort?: LogSortEnum;
68
+ },
69
+ params: UseQueryParams = {},
41
70
  ) {
42
- const { data, ...rest } = useQuery(logEntriesQry, {
43
- ...params,
44
- variables: {
45
- ...variables,
46
- cursor: null,
47
- after: true,
48
- limit: LOG_ENTRIES_LIMIT
49
- },
50
- // If this query is used for virtualized list pagination, set {params.skip=true}
51
- skip: !variables.organizationId || !variables.filter?.operation || params.skip,
52
- });
71
+ const { data, ...rest } = useQuery(logEntriesQry, {
72
+ ...params,
73
+ variables: {
74
+ ...variables,
75
+ cursor: null,
76
+ after: true,
77
+ limit: variables.limit ?? LOG_ENTRIES_LIMIT,
78
+ },
79
+ // If this query is used for virtualized list pagination, set {params.skip=true}
80
+ skip: !variables.organizationId || params.skip,
81
+ });
53
82
 
54
- return {
55
- logEntries: data?.logEntries,
56
- ...rest
57
- };
83
+ return {
84
+ logEntries: data?.logEntries,
85
+ ...rest,
86
+ };
58
87
  }
59
88
 
60
89
  /**
61
- * Fetch logs as evidences for a specific report
90
+ * Fetch all log entries for one fieldDoc source.
62
91
  */
63
92
 
64
- export function useLogEvidences(
65
- variables: {
66
- organizationId: string,
67
- reportId: string,
68
- cursor?: string | null,
69
- after?: boolean,
70
- limit?: number,
71
- },
72
- params: UseQueryParams = {}
93
+ export function useLogEntriesForFieldDoc(
94
+ variables: {
95
+ organizationId?: string | null;
96
+ fieldDocSourceId?: string | null;
97
+ fieldDocSubmissionId: string | null;
98
+ },
99
+ params: UseQueryParams = {},
73
100
  ) {
74
- const { data, ...rest } = useQuery(logEvidencesQry, {
75
- ...params,
76
- variables: {
77
- ...variables,
78
- after: variables.after ?? true,
79
- limit: variables.limit ?? 1000, // Change this when we have pagination support
80
- },
81
- skip: !variables.organizationId || !variables.reportId || params.skip,
82
- });
101
+ const { organizationId, fieldDocSourceId, fieldDocSubmissionId } = variables;
102
+ const { data, ...rest } = useQuery(logEntriesForFieldDocQry, {
103
+ ...params,
104
+ variables,
105
+ skip:
106
+ !organizationId ||
107
+ !fieldDocSourceId ||
108
+ !fieldDocSubmissionId ||
109
+ params.skip,
110
+ });
83
111
 
84
- return {
85
- logEvidences: data?.logEvidences,
86
- ...rest
87
- };
112
+ return {
113
+ logEntriesForFieldDoc: data?.logEntriesForFieldDoc,
114
+ ...rest,
115
+ };
88
116
  }
89
117
 
90
118
  /**
91
119
  * Get reactive log fragment
92
120
  */
93
121
 
94
- export function useReactiveLogFragment(logEntryId: string, currentData?: any, queryCount?: number) {
95
- return useReactiveFragment(
96
- currentData,
97
- [
98
- `$logEntryFragment:${logEntryId}`,
99
-
100
- // By having the second paramter as null, we only observe the reactive changes without setting the data
101
- // [`$logArableFragment:${logEntryId}`, null],
102
-
103
- // This is not needed because $logEntryFragment has spread data
104
- // [`$accountFragment:${logEntryId}`, 'account']
105
- ],
106
- queryCount,
107
- );
122
+ export function useReactiveLogFragment(
123
+ logEntryId: string,
124
+ currentData?: any,
125
+ queryCount?: number,
126
+ ) {
127
+ return useReactiveFragment(
128
+ currentData,
129
+ [
130
+ makeFragmentKey(FRAGMENT_NAMES.logEntry, logEntryId),
131
+ [makeFragmentKey(FRAGMENT_NAMES.logEntryDetails, logEntryId), 'details'],
132
+ ],
133
+ queryCount,
134
+ );
108
135
  }