@jsb188/graphql 1.1.10 → 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 (116) hide show
  1. package/cache/config.ts +64 -50
  2. package/cache/index.test.ts +671 -109
  3. package/cache/index.ts +1700 -1240
  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 +2 -0
  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 +954 -163
  16. package/client/sse-ticket.test.ts +26 -0
  17. package/deno.lock +170 -0
  18. package/deno.test.json +8 -4
  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 +0 -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 +16 -0
  28. package/gql/fragments/billingFragments.ts +0 -11
  29. package/gql/fragments/campaignFragments.ts +277 -0
  30. package/gql/fragments/dataTableFragments.ts +18 -128
  31. package/gql/fragments/emailFragments.ts +19 -9
  32. package/gql/fragments/fieldDocFragments.ts +82 -0
  33. package/gql/fragments/logFragments.ts +20 -79
  34. package/gql/fragments/organizationFragments.ts +43 -5
  35. package/gql/fragments/scheduleFragments.ts +155 -0
  36. package/gql/fragments/sheetFragments.ts +552 -22
  37. package/gql/fragments/storageFragments.ts +21 -0
  38. package/gql/fragments/workflowFragments.ts +28 -4
  39. package/gql/mutations/accountMutations.ts +0 -2
  40. package/gql/mutations/agentDocMutations.ts +177 -0
  41. package/gql/mutations/agentMemoryMutations.ts +36 -0
  42. package/gql/mutations/aiChatMutations.ts +17 -4
  43. package/gql/mutations/authMutations.ts +158 -17
  44. package/gql/mutations/campaignMutations.ts +215 -0
  45. package/gql/mutations/dataTableMutations.ts +48 -26
  46. package/gql/mutations/fieldDocMutations.ts +24 -0
  47. package/gql/mutations/index.ts +6 -1
  48. package/gql/mutations/logMutations.ts +6 -29
  49. package/gql/mutations/organizationMutations.ts +13 -4
  50. package/gql/mutations/scheduleMutations.ts +423 -0
  51. package/gql/mutations/sheetMutations.ts +273 -56
  52. package/gql/mutations/storageMutations.ts +20 -0
  53. package/gql/mutations/workflowMutations.ts +42 -0
  54. package/gql/queries/agentDocQueries.ts +120 -0
  55. package/gql/queries/agentMemoryQueries.ts +22 -0
  56. package/gql/queries/aiChatQueries.ts +18 -2
  57. package/gql/queries/authQueries.ts +41 -0
  58. package/gql/queries/billingQueries.ts +23 -0
  59. package/gql/queries/campaignQueries.ts +127 -0
  60. package/gql/queries/dataTableQueries.ts +100 -11
  61. package/gql/queries/emailQueries.ts +55 -3
  62. package/gql/queries/fieldDocQueries.ts +158 -0
  63. package/gql/queries/index.ts +8 -2
  64. package/gql/queries/logQueries.ts +11 -28
  65. package/gql/queries/organizationQueries.ts +52 -1
  66. package/gql/queries/scheduleQueries.ts +315 -0
  67. package/gql/queries/sheetQueries.ts +336 -25
  68. package/gql/queries/storageQueries.ts +38 -0
  69. package/gql/queries/workflowQueries.ts +72 -3
  70. package/hooks/index.ts +2065 -971
  71. package/hooks/use-account-mtn.ts +76 -81
  72. package/hooks/use-agentDoc-mtn.ts +285 -0
  73. package/hooks/use-agentDoc-qry.ts +208 -0
  74. package/hooks/use-agentMemory-mtn.ts +73 -0
  75. package/hooks/use-agentMemory-qry.ts +44 -0
  76. package/hooks/use-aiChat-mtn.ts +232 -137
  77. package/hooks/use-aiChat-qry.ts +480 -222
  78. package/hooks/use-app-qry.ts +12 -9
  79. package/hooks/use-auth-mtn.ts +406 -252
  80. package/hooks/use-auth-qry.ts +51 -0
  81. package/hooks/use-campaign-mtn.ts +377 -0
  82. package/hooks/use-campaign-qry.ts +257 -0
  83. package/hooks/use-dataTable-mtn.ts +116 -33
  84. package/hooks/use-dataTable-qry.ts +859 -35
  85. package/hooks/use-email-qry.ts +194 -79
  86. package/hooks/use-fieldDoc-mtn.ts +50 -0
  87. package/hooks/use-fieldDoc-qry.ts +180 -0
  88. package/hooks/use-inboundContact-mtn.ts +19 -16
  89. package/hooks/use-inboundContact-qry.ts +63 -55
  90. package/hooks/use-integration-mtn.ts +56 -38
  91. package/hooks/use-integration-qry.ts +24 -9
  92. package/hooks/use-log-mtn.ts +72 -56
  93. package/hooks/use-log-qry.ts +93 -69
  94. package/hooks/use-organization-mtn.ts +334 -277
  95. package/hooks/use-organization-qry.ts +199 -129
  96. package/hooks/use-schedule-mtn.ts +416 -0
  97. package/hooks/use-schedule-qry.ts +157 -0
  98. package/hooks/use-sheet-mtn.ts +233 -47
  99. package/hooks/use-sheet-qry.ts +353 -70
  100. package/hooks/use-storage-mtn.ts +81 -41
  101. package/hooks/use-storage-qry.ts +104 -13
  102. package/hooks/use-workflow-mtn.ts +55 -0
  103. package/hooks/use-workflow-qry.ts +206 -48
  104. package/loaders/campaign.ts +137 -0
  105. package/package.json +94 -71
  106. package/sse.ts +157 -104
  107. package/tsconfig.json +11 -10
  108. package/types.d.ts +60 -30
  109. package/utils.ts +78 -49
  110. package/gql/fragments/productFragments.ts +0 -39
  111. package/gql/fragments/reportFragments.ts +0 -90
  112. package/gql/mutations/billingMutations.ts +0 -34
  113. package/gql/queries/productQueries.ts +0 -31
  114. package/gql/queries/reportQueries.ts +0 -134
  115. package/hooks/use-product-qry.ts +0 -67
  116. package/hooks/use-report-qry.ts +0 -153
package/utils.ts CHANGED
@@ -7,30 +7,35 @@ const TIME_TRACKER = new Map();
7
7
  * Check if data should be refetched based on time
8
8
  */
9
9
 
10
- export function checkIfNeedsRefetch(qryName: string, id: string, threshold: number = 3.6e+6): boolean {
11
- const lastFetched = TIME_TRACKER.get(`${qryName}_${id}`);
12
- if (!lastFetched) {
13
- return true;
14
- }
15
-
16
- const now = Date.now();
17
- const diff = now - lastFetched;
18
-
19
- return diff > threshold;
10
+ export function checkIfNeedsRefetch(
11
+ qryName: string,
12
+ id: string,
13
+ threshold: number = 3.6e6,
14
+ ): boolean {
15
+ const lastFetched = TIME_TRACKER.get(`${qryName}_${id}`);
16
+ if (!lastFetched) {
17
+ return true;
18
+ }
19
+
20
+ const now = Date.now();
21
+ const diff = now - lastFetched;
22
+
23
+ return diff > threshold;
20
24
  }
21
25
 
22
26
  /**
23
27
  * Set fetched time
24
28
  */
25
29
 
26
- export function setFetchedTime(qryName: string, id: string, setOnlyIfUndefined: boolean = false) {
27
- const key = `${qryName}_${id}`;
28
- if (
29
- !setOnlyIfUndefined ||
30
- !TIME_TRACKER.get(key)
31
- ) {
32
- TIME_TRACKER.set(key, Date.now());
33
- }
30
+ export function setFetchedTime(
31
+ qryName: string,
32
+ id: string,
33
+ setOnlyIfUndefined: boolean = false,
34
+ ) {
35
+ const key = `${qryName}_${id}`;
36
+ if (!setOnlyIfUndefined || !TIME_TRACKER.get(key)) {
37
+ TIME_TRACKER.set(key, Date.now());
38
+ }
34
39
  }
35
40
 
36
41
  /**
@@ -38,11 +43,27 @@ export function setFetchedTime(qryName: string, id: string, setOnlyIfUndefined:
38
43
  */
39
44
 
40
45
  export function isServerError(error: ServerErrorObj): boolean {
41
- return !!error && (
42
- error.statusCode === 500 ||
43
- error.errorCode === '30000' ||
44
- error.errorCode === 'network_error'
45
- );
46
+ return (
47
+ !!error &&
48
+ (error.statusCode === 500 ||
49
+ error.errorCode === '30000' ||
50
+ error.errorCode === 'network_error')
51
+ );
52
+ }
53
+
54
+ /**
55
+ * Return whether a request failed for a temporary transport or server reason
56
+ * that can be retried without changing the user's authentication context.
57
+ */
58
+ export function isTransientServerError(error?: ServerErrorObj | null): boolean {
59
+ const statusCode = Number(error?.statusCode || 0);
60
+ const errorCode = String(error?.errorCode || '');
61
+
62
+ return (
63
+ errorCode === 'network_error' ||
64
+ errorCode === '30000' ||
65
+ [500, 502, 503, 504].includes(statusCode)
66
+ );
46
67
  }
47
68
 
48
69
  /**
@@ -50,36 +71,44 @@ export function isServerError(error: ServerErrorObj): boolean {
50
71
  */
51
72
 
52
73
  export function isServerErrorGQL(apiResult: any): boolean {
53
- return (
54
- apiResult?.errors?.find((e: ServerErrorObj) => e.errorCode === '30000') ||
55
- apiResult?.error?.errorCode === 'network_error'
56
- );
74
+ return (
75
+ apiResult?.errors?.find((e: ServerErrorObj) => e.errorCode === '30000') ||
76
+ apiResult?.error?.errorCode === 'network_error'
77
+ );
57
78
  }
58
79
 
59
80
  /**
60
81
  * Headers for all network requests
61
82
  */
62
83
 
63
- export function apiRequestHeaders(authorization?: string | null, ipAddress?: string | null): Headers {
64
- const headers: Record<string, string> = {
65
- 'Content-Type': 'application/json; charset=utf-8',
66
- 'x-api-key': String(getENVVariable('GQL_API_KEY') || ''),
67
- // recaptcha: ? // Not sure if we're going to do this later any more
68
- };
69
-
70
- if (!getENVVariable('IS_BROWSER')) {
71
- headers.ssr = '1';
72
-
73
- if (ipAddress) {
74
- // Do not allow undefined or null, it becomes a String type
75
- headers['x-ssr-ip'] = ipAddress;
76
- }
77
- }
78
-
79
- if (authorization) {
80
- // Do not send undefined or null, it becomes a String type
81
- headers.authorization = authorization;
82
- }
83
-
84
- return new Headers(headers);
84
+ export function apiRequestHeaders(
85
+ authorization?: string | null,
86
+ ipAddress?: string | null,
87
+ userAgent?: string | null,
88
+ ): Headers {
89
+ const headers: Record<string, string> = {
90
+ 'Content-Type': 'application/json; charset=utf-8',
91
+ 'x-api-key': String(getENVVariable('GQL_API_KEY') || ''),
92
+ // recaptcha: ? // Not sure if we're going to do this later any more
93
+ };
94
+
95
+ if (!getENVVariable('IS_BROWSER')) {
96
+ headers.ssr = '1';
97
+
98
+ if (ipAddress) {
99
+ // Do not allow undefined or null, it becomes a String type
100
+ headers['x-ssr-ip'] = ipAddress;
101
+ }
102
+
103
+ if (userAgent) {
104
+ headers['x-client-user-agent'] = userAgent;
105
+ }
106
+ }
107
+
108
+ if (authorization) {
109
+ // Do not send undefined or null, it becomes a String type
110
+ headers.authorization = authorization;
111
+ }
112
+
113
+ return new Headers(headers);
85
114
  }
@@ -1,39 +0,0 @@
1
-
2
- export const productFragment = `fragment productFragment on Product {
3
- id
4
- organizationId
5
- cursor
6
-
7
- metadata {
8
- overview
9
- }
10
-
11
- createdAt
12
- updatedAt
13
- }`;
14
-
15
- export const productCalEventFragment = `fragment productCalEventFragment on ProductCalEvent {
16
- __typename
17
-
18
- id
19
- name
20
-
21
- schedule {
22
- frequency
23
- weeksOfMonth
24
- daysOfWeek
25
- time
26
- }
27
-
28
- address {
29
- line1
30
- line2
31
- city
32
- state
33
- postalCode
34
- country
35
- }
36
-
37
- startAt
38
- endAt
39
- }`;
@@ -1,90 +0,0 @@
1
- export const reportFragment = `fragment reportFragment on Report {
2
- id
3
- organizationId
4
-
5
- documentName
6
- title
7
- description
8
- frequency
9
- reportGroupId
10
- groupName
11
- groupShortName
12
- period
13
- summary
14
- gridLayoutStyle
15
- }`;
16
-
17
- export const reportSectionFragment = `fragment reportSectionFragment on ReportSection {
18
- id
19
- isGroupTitle
20
- title
21
- description
22
- requireFileUploads
23
- }`;
24
-
25
- export const reportRowDataFragment = `fragment reportRowDataFragment on ReportRowData {
26
- id
27
- preset
28
- className
29
- isHeader
30
- }`;
31
-
32
- export const reportColumnDataFragment = `fragment reportColumnDataFragment on ReportColumnData {
33
- id
34
- entityId
35
- referenceIds
36
- lineNumber
37
- className
38
- iconName
39
- label
40
- answer
41
- text
42
- shortText
43
- note
44
- warningIfNotChecked
45
- warningNote
46
- placeholder
47
- checked
48
- }`;
49
-
50
- export const reportGroupFragment = `fragment reportGroupFragment on ReportGroup {
51
- id
52
- name
53
- shortName
54
- layout {
55
- columns
56
- headers
57
- gridLayoutStyle
58
- }
59
- lastSubmissionPeriod
60
- lastSubmissionReportId
61
- }`;
62
-
63
- export const reportSubmissionFragment = `fragment reportSubmissionFragment on ReportSubmission {
64
- id
65
- reportSubmissionId
66
- reportId
67
- value
68
- frequency
69
- reportSubmissionIdEnc
70
-
71
- organizationId
72
- organizationIdEnc
73
- organizationName
74
- organizationOperation
75
-
76
- childOrgId
77
- childOrgIdEnc
78
- childOrgName
79
- childOrgOperation
80
-
81
- location
82
- period
83
- status
84
- reportGroupId
85
- groupName
86
- groupShortName
87
- activityAt
88
- createdAt
89
- updatedAt
90
- }`;
@@ -1,34 +0,0 @@
1
- import { gql } from 'graphql-tag';
2
- import { platformProductPurchaseResultFragment } from '../fragments/billingFragments.ts';
3
-
4
- export const purchasePlatformProductMtn = gql`
5
- mutation purchasePlatformProduct (
6
- $paymentId: String!
7
- $paymentMethodId: String!
8
- $productGroup: PlatformProductGroup!
9
- $email: String!
10
- $name: String
11
- ) {
12
- purchasePlatformProduct (
13
- paymentId: $paymentId
14
- paymentMethodId: $paymentMethodId
15
- productGroup: $productGroup
16
- email: $email
17
- name: $name
18
- ) {
19
- ...platformProductPurchaseResultFragment
20
- }
21
- }
22
-
23
- ${platformProductPurchaseResultFragment}
24
- `;
25
-
26
- export const cancelPlatformSubscriptionMtn = gql`
27
- mutation cancelPlatformSubscription {
28
- cancelPlatformSubscription {
29
- ...platformProductPurchaseResultFragment
30
- }
31
- }
32
-
33
- ${platformProductPurchaseResultFragment}
34
- `;
@@ -1,31 +0,0 @@
1
- import { gql } from 'graphql-tag';
2
- import { productCalEventFragment, productFragment } from '../fragments/productFragments.ts';
3
-
4
- export const productsListQry = gql`
5
- query productsList (
6
- $organizationId: GenericID!
7
- $filter: ProductsFilter!
8
- $cursor: Cursor
9
- $after: Boolean!
10
- $limit: Int!
11
- ) {
12
- productsList (
13
- organizationId: $organizationId
14
- filter: $filter
15
- cursor: $cursor
16
- after: $after
17
- limit: $limit
18
- ) {
19
- ...productFragment
20
-
21
- details {
22
- ...on ProductCalEvent {
23
- ...productCalEventFragment
24
- }
25
- }
26
- }
27
- }
28
-
29
- ${productFragment}
30
- ${productCalEventFragment}
31
- `;
@@ -1,134 +0,0 @@
1
- import { gql } from 'graphql-tag';
2
- import { reportColumnDataFragment, reportFragment, reportGroupFragment, reportRowDataFragment, reportSectionFragment, reportSubmissionFragment } from '../fragments/reportFragments.ts';
3
- import { storageFileFragment } from '../fragments/storageFragments.ts';
4
-
5
- export const reportsQry = gql`
6
- query reports (
7
- $organizationId: GenericID!
8
- $filter: ReportsFilter!
9
- $sort: ReportsSort
10
- ) {
11
- reports (
12
- organizationId: $organizationId
13
- filter: $filter
14
- sort: $sort
15
- ) {
16
- ...reportFragment
17
-
18
- submission {
19
- ...reportSubmissionFragment
20
- }
21
-
22
- sections {
23
- ...reportSectionFragment
24
-
25
- files {
26
- ...storageFileFragment
27
- }
28
-
29
- rows {
30
- ...reportRowDataFragment
31
-
32
- columns {
33
- ...reportColumnDataFragment
34
- }
35
- }
36
- }
37
-
38
- }
39
- }
40
-
41
- ${reportFragment}
42
- ${reportSubmissionFragment}
43
- ${reportSectionFragment}
44
- ${storageFileFragment}
45
- ${reportRowDataFragment}
46
- ${reportColumnDataFragment}
47
- `;
48
-
49
- export const reportQry = gql`
50
- query report (
51
- $organizationId: GenericID!
52
- $reportSourceId: CursorToIDs!
53
- ) {
54
- report (
55
- organizationId: $organizationId
56
- reportSourceId: $reportSourceId
57
- ) {
58
- ...reportFragment
59
-
60
- aside {
61
- title
62
- nullText
63
-
64
- items {
65
- className
66
- label
67
- text
68
- }
69
- }
70
-
71
- submission {
72
- ...reportSubmissionFragment
73
- }
74
-
75
- sections {
76
- ...reportSectionFragment
77
-
78
- files {
79
- ...storageFileFragment
80
- }
81
-
82
- rows {
83
- ...reportRowDataFragment
84
-
85
- columns {
86
- ...reportColumnDataFragment
87
- }
88
- }
89
- }
90
-
91
- }
92
- }
93
-
94
- ${reportFragment}
95
- ${reportSubmissionFragment}
96
- ${reportSectionFragment}
97
- ${storageFileFragment}
98
- ${reportRowDataFragment}
99
- ${reportColumnDataFragment}
100
- `;
101
-
102
- export const reportGroupsQry = gql`
103
- query reportGroups (
104
- $organizationId: GenericID!
105
- ) {
106
- reportGroups (
107
- organizationId: $organizationId
108
- ) {
109
- ...reportGroupFragment
110
- }
111
- }
112
-
113
- ${reportGroupFragment}
114
- `;
115
-
116
- export const reportSubmissionsQry = gql`
117
- query reportSubmissions (
118
- $organizationId: GenericID!
119
- $filter: ReportsFilter!
120
- $sort: ReportsSort
121
- $limit: Int!
122
- ) {
123
- reportSubmissions (
124
- organizationId: $organizationId
125
- filter: $filter
126
- sort: $sort
127
- limit: $limit
128
- ) {
129
- ...reportSubmissionFragment
130
- }
131
- }
132
-
133
- ${reportSubmissionFragment}
134
- `;
@@ -1,67 +0,0 @@
1
- import type { ProductsFilterArgs } from '@jsb188/mday/types/product.d.ts';
2
- import { useQuery, useReactiveFragment } from '../client/index.ts';
3
- import { productsListQry } from '../gql/queries/productQueries.ts';
4
- import type { PaginationArgs, UseQueryParams } from '../types.d.ts';
5
-
6
- /**
7
- * Constants
8
- */
9
-
10
- const PRODUCTS_LIST_LIMIT = 200;
11
-
12
- /**
13
- * Helper; use this to get/use same filter for productsList() query everywhere
14
- */
15
-
16
- // export function getDefaultProductsListFilter(operation: FilterProductsListArgs['operation']): FilterProductsListArgs {
17
- // return {
18
- // operation,
19
- // types: null,
20
- // startDate: null,
21
- // endDate: null,
22
- // query: ''
23
- // };
24
- // }
25
-
26
- /**
27
- * Fetch log entries
28
- */
29
-
30
- export function useProductsList(
31
- variables: PaginationArgs & {
32
- organizationId?: string | null;
33
- filter: ProductsFilterArgs;
34
- },
35
- params: UseQueryParams = {}
36
- ) {
37
- const { data, ...rest } = useQuery(productsListQry, {
38
- variables: {
39
- ...variables,
40
- cursor: null,
41
- after: false,
42
- limit: PRODUCTS_LIST_LIMIT
43
- },
44
- // If this query is used for virtualized list pagination, set {params.skip=true}
45
- skip: !variables.organizationId,
46
- ...params,
47
- });
48
-
49
- return {
50
- productsList: data?.productsList,
51
- ...rest
52
- };
53
- }
54
-
55
- /**
56
- * Get reactive log fragment
57
- */
58
-
59
- export function useReactiveProductFragment(productId: string, currentData?: any, queryCount?: number) {
60
- return useReactiveFragment(
61
- currentData,
62
- [
63
- `$productFragment:${productId}`,
64
- ],
65
- queryCount,
66
- );
67
- }
@@ -1,153 +0,0 @@
1
- import type { ReportsFilterArgs, ReportsSortEnum } from '@jsb188/mday/types/report.d.ts';
2
- import { useQuery, useReactiveFragment, useReactiveFragmentMap } from '../client/index.ts';
3
- import { reportGroupsQry, reportQry, reportsQry, reportSubmissionsQry } from '../gql/queries/reportQueries.ts';
4
- import type { UseQueryParams } from '../types.d.ts';
5
-
6
- /**
7
- * Get reactive report fragment
8
- */
9
-
10
- export function useReactiveReportFragment(reportId: string, currentData?: any, queryCount?: number) {
11
- return useReactiveFragment(
12
- currentData,
13
- [
14
- `$reportFragment:${reportId}`,
15
- ],
16
- queryCount,
17
- );
18
- }
19
-
20
- /**
21
- * Get reactive report submission fragment
22
- */
23
-
24
- export function useReactiveReportSubmissionFragment(reportSubmissionId: string, currentData?: any, queryCount?: number) {
25
- return useReactiveFragment(
26
- currentData,
27
- [
28
- `$reportSubmissionFragment:${reportSubmissionId}`,
29
- ],
30
- queryCount,
31
- );
32
- }
33
-
34
- /**
35
- * Get reactive report column fragments for a row of report columns.
36
- */
37
-
38
- export function useReactiveReportColumnFragmentMap(currentData?: any[] | null) {
39
- return useReactiveFragmentMap(currentData || null, 'reportColumnDataFragment');
40
- }
41
-
42
- /**
43
- * Fetch list of reports by type and period
44
- */
45
-
46
- export function useReports(
47
- variables: {
48
- organizationId: string;
49
- filter: ReportsFilterArgs;
50
- sort?: ReportsSortEnum;
51
- },
52
- params: UseQueryParams = {},
53
- ) {
54
-
55
- const { organizationId, filter } = variables;
56
- const { skip, ...restParams } = params;
57
- const { data, ...rest } = useQuery(reportsQry, {
58
- variables,
59
- skip: skip || !organizationId || !filter?.reportGroupId || !(filter?.startPeriod || filter?.endPeriod),
60
- ...restParams,
61
- });
62
-
63
- return {
64
- reports: data?.reports,
65
- ...rest
66
- };
67
- }
68
-
69
- /**
70
- * Fetch one report by report source id
71
- */
72
-
73
- export function useReport(
74
- organizationId: string | null,
75
- reportSourceId: string | null,
76
- params: UseQueryParams = {},
77
- ) {
78
- const { skip, ...restParams } = params;
79
- const { data, ...rest } = useQuery(reportQry, {
80
- variables: {
81
- organizationId,
82
- reportSourceId,
83
- },
84
- skip: skip || !organizationId || !reportSourceId,
85
- ...restParams,
86
- });
87
-
88
- return {
89
- report: data?.report,
90
- ...rest
91
- };
92
- }
93
-
94
- /**
95
- * Fetch list of report groups for organization
96
- */
97
-
98
- export function useReportGroups(
99
- organizationId: string | null,
100
- params: UseQueryParams = {},
101
- ) {
102
-
103
- const { skip, ...restParams } = params;
104
- const { data, ...rest } = useQuery(reportGroupsQry, {
105
- variables: {
106
- organizationId,
107
- },
108
- skip: skip || !organizationId,
109
- ...restParams,
110
- });
111
-
112
- return {
113
- reportGroups: data?.reportGroups,
114
- ...rest
115
- };
116
- }
117
-
118
- /**
119
- * Fetch list of report submissions for organization
120
- */
121
-
122
- export function useReportSubmissions(
123
- variables: {
124
- organizationId: string | null;
125
- filter: ReportsFilterArgs;
126
- sort?: ReportsSortEnum;
127
- limit?: number;
128
- },
129
- params: UseQueryParams = {},
130
- ) {
131
-
132
- const {
133
- organizationId,
134
- filter,
135
- sort = 'PERIOD_DESC',
136
- limit = 100,
137
- } = variables;
138
- const { skip, ...restParams } = params;
139
- const { data, ...rest } = useQuery(reportSubmissionsQry, {
140
- variables: {
141
- ...variables,
142
- sort,
143
- limit,
144
- },
145
- skip: skip || !organizationId || !filter,
146
- ...restParams,
147
- });
148
-
149
- return {
150
- reportSubmissions: data?.reportSubmissions,
151
- ...rest
152
- };
153
- }