@jsb188/graphql 1.1.8 → 1.1.10

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 (73) hide show
  1. package/cache/config.ts +14 -4
  2. package/cache/index.test.ts +319 -0
  3. package/cache/index.ts +478 -102
  4. package/client/index.ts +2 -2
  5. package/client/request.ts +48 -9
  6. package/deno.test.json +6 -0
  7. package/gql/fragments/accountFragments.ts +1 -0
  8. package/gql/fragments/aiChatFragments.ts +1 -0
  9. package/gql/fragments/dataTableFragments.ts +212 -0
  10. package/gql/fragments/emailFragments.ts +26 -0
  11. package/gql/fragments/inboundContactFragments.ts +15 -0
  12. package/gql/fragments/integrationFragments.ts +22 -0
  13. package/gql/fragments/logFragments.ts +40 -12
  14. package/gql/fragments/organizationFragments.ts +59 -24
  15. package/gql/fragments/productFragments.ts +0 -24
  16. package/gql/fragments/reportFragments.ts +52 -10
  17. package/gql/fragments/sheetFragments.ts +145 -0
  18. package/gql/fragments/storageFragments.ts +0 -1
  19. package/gql/fragments/workflowFragments.ts +43 -0
  20. package/gql/mutations/accountMutations.ts +24 -2
  21. package/gql/mutations/aiChatMutations.ts +28 -1
  22. package/gql/mutations/authMutations.ts +3 -3
  23. package/gql/mutations/billingMutations.ts +1 -1
  24. package/gql/mutations/dataTableMutations.ts +84 -0
  25. package/gql/mutations/inboundContactMutations.ts +24 -0
  26. package/gql/mutations/index.ts +12 -8
  27. package/gql/mutations/integrationMutations.ts +25 -0
  28. package/gql/mutations/logMutations.ts +15 -1
  29. package/gql/mutations/organizationMutations.ts +151 -2
  30. package/gql/mutations/sheetMutations.ts +168 -0
  31. package/gql/mutations/storageMutations.ts +1 -2
  32. package/gql/queries/aiChatQueries.ts +1 -1
  33. package/gql/queries/billingQueries.ts +1 -1
  34. package/gql/queries/dataTableQueries.ts +45 -0
  35. package/gql/queries/emailQueries.ts +44 -0
  36. package/gql/queries/inboundContactQueries.ts +40 -0
  37. package/gql/queries/index.ts +11 -6
  38. package/gql/queries/logQueries.ts +47 -20
  39. package/gql/queries/organizationQueries.ts +62 -8
  40. package/gql/queries/productQueries.ts +1 -40
  41. package/gql/queries/reportQueries.ts +81 -13
  42. package/gql/queries/sheetQueries.ts +72 -0
  43. package/gql/queries/workflowQueries.ts +30 -0
  44. package/hooks/index.ts +208 -58
  45. package/hooks/use-account-mtn.ts +52 -4
  46. package/hooks/use-aiChat-mtn.ts +62 -6
  47. package/hooks/use-aiChat-qry.ts +76 -24
  48. package/hooks/use-app-qry.ts +2 -2
  49. package/hooks/use-auth-mtn.ts +5 -5
  50. package/hooks/use-dataTable-mtn.ts +87 -0
  51. package/hooks/use-dataTable-qry.ts +172 -0
  52. package/hooks/use-email-qry.ts +112 -0
  53. package/hooks/use-inboundContact-mtn.ts +31 -0
  54. package/hooks/use-inboundContact-qry.ts +88 -0
  55. package/hooks/use-integration-mtn.ts +59 -0
  56. package/hooks/use-integration-qry.ts +15 -0
  57. package/hooks/use-log-mtn.ts +6 -6
  58. package/hooks/use-log-qry.ts +38 -35
  59. package/hooks/use-organization-mtn.ts +288 -16
  60. package/hooks/use-organization-qry.ts +71 -22
  61. package/hooks/use-product-qry.ts +4 -46
  62. package/hooks/use-report-qry.ts +93 -9
  63. package/hooks/use-sheet-mtn.ts +181 -0
  64. package/hooks/use-sheet-qry.ts +157 -0
  65. package/hooks/use-storage-mtn.ts +6 -5
  66. package/hooks/use-storage-qry.ts +1 -1
  67. package/hooks/use-workflow-qry.ts +72 -0
  68. package/package.json +23 -4
  69. package/sse.ts +2 -2
  70. package/tsconfig.json +12 -0
  71. package/types.d.ts +2 -1
  72. package/utils.ts +2 -4
  73. package/gql/fragments/actionFragments.ts +0 -16
package/client/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from '../hooks/index';
2
- export * from './request';
1
+ export * from '../hooks/index.ts';
2
+ export * from './request.ts';
package/client/request.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { getENVVariable } from '@jsb188/app';
2
- import type { ServerErrorObj } from '@jsb188/app/types/app.d';
3
- import { getAuthToken, normalizeServerError } from '@jsb188/app/utils/api';
4
- import { delay } from '@jsb188/app/utils/logic';
5
- import { setDataToCache } from '../cache/';
6
- import type { OnCompletedGQLFn, OnErrorGQLFn, UpdateObserversFn } from '../types.d';
7
- import { apiRequestHeaders, isServerErrorGQL } from '../utils';
2
+ import type { ServerErrorObj } from '@jsb188/app/types/app.d.ts';
3
+ import { getAuthToken, normalizeServerError } from '@jsb188/app/utils/api.ts';
4
+ import { delay } from '@jsb188/app/utils/logic.ts';
5
+ import { setDataToCache } from '../cache/index.ts';
6
+ import type { OnCompletedGQLFn, OnErrorGQLFn, UpdateObserversFn } from '../types.d.ts';
7
+ import { apiRequestHeaders, isServerErrorGQL } from '../utils.ts';
8
8
 
9
9
  /**
10
10
  * Types
@@ -58,6 +58,44 @@ const defaultRequestParams = {
58
58
  },
59
59
  };
60
60
 
61
+ /**
62
+ * Pick the client error code that best represents a failed HTTP response.
63
+ */
64
+
65
+ function getHTTPErrorCode(statusCode: number): string {
66
+ switch (statusCode) {
67
+ case 401:
68
+ case 403:
69
+ return '30043';
70
+ case 429:
71
+ return '20055';
72
+ default:
73
+ return '30000';
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Parse a fetch response without assuming the server always returned JSON.
79
+ */
80
+
81
+ async function parseGraphQLResponse(response: Response): Promise<any> {
82
+ const contentType = response.headers.get('content-type') || '';
83
+ const isJSON = contentType.includes('application/json');
84
+ const data = isJSON ? await response.json() : {
85
+ errors: [{
86
+ errorCode: getHTTPErrorCode(response.status),
87
+ statusCode: response.status,
88
+ message: await response.text(),
89
+ }],
90
+ };
91
+
92
+ if (!response.ok) {
93
+ throw data;
94
+ }
95
+
96
+ return data;
97
+ }
98
+
61
99
  /**
62
100
  * GraphQL request with retry support
63
101
  */
@@ -125,6 +163,7 @@ export async function graphqlRequest(
125
163
  const { openModalPopUp, onCompleted, onError, authToken, cacheMap, ipAddress } = params || {};
126
164
 
127
165
  if (!gqlQuery?.definitions) {
166
+ console.log('GraphQL definitions is nullish. This likely means there is an issue with the gql parsing of the query/mutation. Check the query/mutation syntax and ensure it is being parsed correctly.');
128
167
  console.log(gqlQuery);
129
168
  }
130
169
 
@@ -147,7 +186,7 @@ export async function graphqlRequest(
147
186
  operationName,
148
187
  }),
149
188
  })
150
- .then((response) => response.json())
189
+ .then(parseGraphQLResponse)
151
190
  .then((data) => {
152
191
  let gqlError: ServerErrorObj | null = null;
153
192
  if (data.errors?.length) {
@@ -162,12 +201,12 @@ export async function graphqlRequest(
162
201
  }
163
202
  }
164
203
 
204
+ setDataToCache(data.data, gqlQuery, variables, cacheMap, updateObservers);
205
+
165
206
  if (onCompleted) {
166
207
  onCompleted(data, gqlError, variables);
167
208
  }
168
209
 
169
- setDataToCache(data.data, gqlQuery, variables, cacheMap, updateObservers);
170
-
171
210
  return {
172
211
  ...data.data,
173
212
  error: gqlError,
package/deno.test.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "imports": {
3
+ "@jsb188/app/": "../@jsb188:app/src/",
4
+ "@jsb188/react/": "../@jsb188:react/src/"
5
+ }
6
+ }
@@ -1,5 +1,6 @@
1
1
  export const accountFragment = `fragment accountFragment on Account {
2
2
  id
3
+ readableId
3
4
  deleted
4
5
  color
5
6
 
@@ -4,6 +4,7 @@ export const aiChatFragment = `fragment aiChatFragment on AIChat {
4
4
  accountId
5
5
  calDate
6
6
  summary
7
+ archivedAt
7
8
  createdAt
8
9
  updatedAt
9
10
  }`;
@@ -0,0 +1,212 @@
1
+ export const dataTableFragment = `fragment dataTableFragment on DataTable {
2
+ id
3
+ organizationId
4
+
5
+ name
6
+ title
7
+ description
8
+ active
9
+
10
+ design {
11
+ id
12
+ instructions
13
+ cellsOrder
14
+ viewsOrder
15
+ defaultViewId
16
+ humansCannotEdit
17
+ stickyTop
18
+ stickyLeft
19
+
20
+ cells {
21
+ key
22
+ label
23
+ humanLabel
24
+ iconName
25
+ fieldType
26
+ humanFieldType
27
+ format
28
+ instructions
29
+ openLink
30
+ humansOnly
31
+ humansCannotEdit
32
+ hidden
33
+ indexed
34
+ width
35
+
36
+ source {
37
+ path
38
+ table
39
+ }
40
+
41
+ options {
42
+ label
43
+ value
44
+ color
45
+ }
46
+ }
47
+
48
+ views {
49
+ id
50
+ name
51
+ layout
52
+ iconName
53
+ color
54
+ description
55
+ columnsOrder
56
+ stickyTop
57
+ stickyLeft
58
+ humansCannotEdit
59
+
60
+ rowModel {
61
+ type
62
+
63
+ dimensions {
64
+ key
65
+ label
66
+
67
+ source {
68
+ type
69
+ cellKey
70
+ formulaKey
71
+ dimensionKey
72
+ table
73
+ path
74
+ sourceCellKey
75
+ sourceCellKeys
76
+ operation
77
+ }
78
+ }
79
+
80
+ generator {
81
+ keyPrefix
82
+
83
+ dateSeries {
84
+ key
85
+ label
86
+ sourceCellKey
87
+ grain
88
+ weekStart
89
+
90
+ range {
91
+ type
92
+ start
93
+ end
94
+ }
95
+ }
96
+
97
+ dimensions {
98
+ key
99
+ label
100
+
101
+ source {
102
+ type
103
+ cellKey
104
+
105
+ values {
106
+ value
107
+ label
108
+ }
109
+ }
110
+ }
111
+
112
+ measures {
113
+ key
114
+ label
115
+ operation
116
+ sourceCellKey
117
+ }
118
+ }
119
+ }
120
+
121
+ columns {
122
+ key
123
+ label
124
+ humanLabel
125
+ iconName
126
+ fieldType
127
+ humanFieldType
128
+ openLink
129
+ humansCannotEdit
130
+ width
131
+
132
+ source {
133
+ type
134
+ cellKey
135
+ formulaKey
136
+ dimensionKey
137
+ table
138
+ path
139
+ sourceCellKey
140
+ sourceCellKeys
141
+ operation
142
+ }
143
+
144
+ options {
145
+ label
146
+ value
147
+ color
148
+ }
149
+ }
150
+
151
+ filters {
152
+ id
153
+ columnKey
154
+ operator
155
+ value
156
+ enabled
157
+ }
158
+
159
+ sorts {
160
+ columnKey
161
+ direction
162
+ }
163
+
164
+ groups {
165
+ columnKey
166
+ direction
167
+ }
168
+ }
169
+ }
170
+
171
+ createdAt
172
+ updatedAt
173
+ }`;
174
+
175
+ export const dataTableRowFragment = `fragment dataTableRowFragment on DataTableRow {
176
+ id
177
+ cursor
178
+ organizationId
179
+ dataTableId
180
+
181
+ identifier
182
+ viewId
183
+ viewRowKey
184
+ position
185
+ metadata
186
+ }`;
187
+
188
+ export const dataTableCellFragment = `fragment dataTableCellFragment on DataTableCell {
189
+ id
190
+ dataTableId
191
+ dataTableRowId
192
+
193
+ cellKey
194
+ iconName
195
+ value
196
+ textValue
197
+ numberValue
198
+ booleanValue
199
+ dateValue
200
+ datetimeValue
201
+ relatedTable
202
+ relatedId
203
+ reference {
204
+ dataTableId
205
+ dataTableRowId
206
+ cellKey
207
+ }
208
+ referenceStatus
209
+
210
+ createdAt
211
+ updatedAt
212
+ }`;
@@ -0,0 +1,26 @@
1
+ export const inboundEmailAttachmentFragment = `fragment inboundEmailAttachmentFragment on InboundEmailAttachment {
2
+ name
3
+ contentType
4
+ contentLength
5
+ }`;
6
+
7
+ export const inboundEmailFragment = `fragment inboundEmailFragment on InboundEmail {
8
+ id
9
+ cursor
10
+ organizationId
11
+ recipientEmail
12
+ senderEmail
13
+ subject
14
+ postmarkMessageId
15
+ status
16
+ statusSummary
17
+ previewText
18
+ bodyFormat
19
+ bodyText
20
+ attachments {
21
+ ...inboundEmailAttachmentFragment
22
+ }
23
+ receivedAt
24
+ processingStartedAt
25
+ processingCompletedAt
26
+ }`;
@@ -0,0 +1,15 @@
1
+ export const inboundContactFragment = `fragment inboundContactFragment on InboundContact {
2
+ id
3
+ organizationId
4
+ cursor
5
+ personName
6
+ email
7
+ phone
8
+ memory
9
+ associated {
10
+ organizationId
11
+ name
12
+ }
13
+ createdAt
14
+ updatedAt
15
+ }`;
@@ -0,0 +1,22 @@
1
+ export const integrationConnectionFragment = `fragment integrationConnectionFragment on IntegrationConnection {
2
+ id
3
+ organizationId
4
+ provider
5
+ externalAccountId
6
+ scopes
7
+ status
8
+ expiresAt
9
+ refreshTokenExpiresAt
10
+ lastSyncedAt
11
+ lastTokenRefreshAt
12
+ lastError
13
+ createdAt
14
+ updatedAt
15
+
16
+ capabilities {
17
+ canReadMerchant
18
+ canReadLocations
19
+ canViewSalesData
20
+ canCreatePaymentRequests
21
+ }
22
+ }`;
@@ -1,10 +1,22 @@
1
1
 
2
2
  export const logEntryFragment = `fragment logEntryFragment on LogEntry {
3
3
  id
4
+ cursor
4
5
  accountId
5
6
  organizationId
6
- cursor
7
- status
7
+ childOrgId
8
+ childOrgName
9
+ inboundContactId
10
+ inboundContactName
11
+ reportId
12
+ reportSubmissionId
13
+ siteId
14
+ location
15
+ summary
16
+ source
17
+ confidence
18
+ originalMessage
19
+ flagColor
8
20
  date
9
21
  createdAt
10
22
  updatedAt
@@ -18,23 +30,22 @@ export const logArableFragment = `fragment logArableFragment on LogArable {
18
30
  activity
19
31
  concentration
20
32
  concentrationUnit
33
+ fieldLocation
21
34
 
22
35
  item
23
36
  quantity
24
37
  unit
25
- location
26
- fieldLocation
27
38
 
28
- otherParty
29
39
  referenceNumber
30
40
  values {
31
41
  label
32
42
  value
33
43
  quantity
44
+ unit
34
45
  }
35
46
  tax
47
+ voided
36
48
 
37
- summary
38
49
  notes
39
50
  }`;
40
51
 
@@ -45,20 +56,39 @@ export const logFarmersMarketFragment = `fragment logFarmersMarketFragment on Lo
45
56
  type
46
57
  activity
47
58
 
48
- childOrgId
49
59
  item
50
60
 
51
- otherParty
52
61
  referenceNumber
53
62
  values {
54
63
  label
55
64
  value
56
65
  quantity
66
+ unit
57
67
  }
58
68
  tax
59
69
  voided
60
70
 
61
- summary
71
+ notes
72
+ }`;
73
+
74
+ export const logGrowerNetworkFragment = `fragment logGrowerNetworkFragment on LogGrowerNetwork {
75
+ __typename
76
+
77
+ id
78
+ type
79
+ activity
80
+
81
+ animalRisk
82
+ equipmentRisk
83
+ fieldRisk
84
+ contaminationRisk
85
+ hygieneRisk
86
+ pestsRisk
87
+ sanitationRisk
88
+
89
+ item
90
+ fieldLocation
91
+
62
92
  notes
63
93
  }`;
64
94
 
@@ -74,12 +104,12 @@ export const logLivestockFragment = `fragment logLivestockFragment on LogLivesto
74
104
  livestockGroup
75
105
  damIdentifier
76
106
 
77
- otherParty
78
107
  referenceNumber
79
108
  values {
80
109
  label
81
110
  value
82
111
  quantity
112
+ unit
83
113
  }
84
114
  tax
85
115
 
@@ -87,9 +117,7 @@ export const logLivestockFragment = `fragment logLivestockFragment on LogLivesto
87
117
  quantity
88
118
  unit
89
119
  price
90
- location
91
120
  fieldLocation
92
121
 
93
- summary
94
122
  notes
95
123
  }`;
@@ -2,11 +2,10 @@
2
2
  export const organizationFragment = `fragment organizationFragment on Organization {
3
3
  id
4
4
  stripeCustomerId
5
+ inboundEmail
5
6
  name
6
7
  commodities
7
8
  operation
8
-
9
- dailyDigestTime
10
9
  activated
11
10
 
12
11
  address {
@@ -23,40 +22,63 @@ export const organizationFragment = `fragment organizationFragment on Organizati
23
22
  timeZone
24
23
  language
25
24
  color
25
+ priorityService
26
+ routes {
27
+ id
28
+ columnWidths
29
+ }
30
+ sidebar {
31
+ title
32
+ items {
33
+ slug
34
+ label
35
+ iconName
36
+ }
37
+ }
26
38
  }
27
39
 
28
40
  directory {
29
- department
30
41
  name
42
+ department
31
43
  emailAddress
32
44
  phoneNumber
33
45
  }
34
46
  }`;
35
47
 
48
+ export const organizationSettingsFragment = `fragment organizationSettingsFragment on OrganizationSettings {
49
+ timeZone
50
+ language
51
+ color
52
+ priorityService
53
+ routes {
54
+ id
55
+ columnWidths
56
+ }
57
+ sidebar {
58
+ title
59
+ items {
60
+ slug
61
+ label
62
+ iconName
63
+ }
64
+ }
65
+ }`;
66
+
36
67
  export const organizationComplianceFragment = `fragment organizationComplianceFragment on OrganizationCompliance {
37
68
  id
38
- number
39
- name
69
+ documentName
40
70
  type
41
71
  expirationDate
42
- notes
43
72
  createdAt
44
73
  updatedAt
45
-
46
- files {
47
- id
48
- complianceId
49
- storageId
50
- order
51
- uri
52
- contentType
53
- }
54
74
  }`;
55
75
 
56
76
  export const organizationRelationshipFragment = `fragment organizationRelationshipFragment on OrganizationRelationship {
57
77
  id
78
+ organizationId
58
79
  primary
59
80
  role
81
+ notes
60
82
 
61
83
  acl {
62
84
  id
@@ -74,18 +96,31 @@ export const organizationRelationshipFragment = `fragment organizationRelationsh
74
96
  }
75
97
  }`;
76
98
 
99
+ export const organizationSiteFragment = `fragment organizationSiteFragment on OrganizationSite {
100
+ id
101
+ readableId
102
+ organizationId
103
+ parentId
104
+ name
105
+ region
106
+ note
107
+ createdAt
108
+ organizationName
109
+ parentName
110
+ }`;
111
+
77
112
  export const organizationChildFragment = `fragment organizationChildFragment on OrganizationChild {
78
113
  id
114
+ parentId
79
115
  cursor
80
116
  addedAt
81
- }`;
117
+ affiliated
118
+ memory
82
119
 
83
- export const organizationInstructionsFragment = `fragment organizationInstructionsFragment on OrganizationInstructions {
84
- id
85
- organizationId
86
- logType
87
- summary
88
- instructions
89
- createdAt
90
- updatedAt
120
+ preferredContacts {
121
+ department
122
+ name
123
+ emailAddress
124
+ phoneNumber
125
+ }
91
126
  }`;
@@ -37,27 +37,3 @@ export const productCalEventFragment = `fragment productCalEventFragment on Prod
37
37
  startAt
38
38
  endAt
39
39
  }`;
40
-
41
- export const productAttendanceFragment = `fragment productAttendanceFragment on ProductAttendance {
42
- id
43
- productId
44
- organizationId
45
- calDate
46
- attended
47
- }`;
48
-
49
- export const productLivestockFragment = `fragment productLivestockFragment on ProductLivestock {
50
- __typename
51
-
52
- id
53
- damIdentifier
54
- livestockIdentifier
55
- livestockGroup
56
-
57
- type
58
- status
59
- livestockClass
60
-
61
- birthDate
62
- deathDate
63
- }`;