@trackunit/react-core-contexts 0.4.135 → 0.4.137
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.
- package/index.cjs +46 -35
- package/index.js +46 -35
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -9,8 +9,8 @@ var error = require('@apollo/client/link/error');
|
|
|
9
9
|
var Sentry = require('@sentry/browser');
|
|
10
10
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
11
11
|
var apolloUploadClient = require('apollo-upload-client');
|
|
12
|
-
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
13
12
|
var React = require('react');
|
|
13
|
+
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
14
14
|
require('@js-temporal/polyfill');
|
|
15
15
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
16
16
|
var reactComponents = require('@trackunit/react-components');
|
|
@@ -70,7 +70,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
70
70
|
* @returns {JSX.Element} The provider.
|
|
71
71
|
*/
|
|
72
72
|
const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
73
|
-
const {
|
|
73
|
+
const { graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders } = reactCoreHooks.useEnvironment();
|
|
74
74
|
const { token } = reactCoreHooks.useToken();
|
|
75
75
|
const managerGraphQLLink = apolloUploadClient.createUploadLink({
|
|
76
76
|
uri: request => graphqlManagerUrl + "/" + request.operationName,
|
|
@@ -84,12 +84,12 @@ const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
|
84
84
|
const reportGraphQLLink = apolloUploadClient.createUploadLink({
|
|
85
85
|
uri: request => graphqlReportUrl + "/" + request.operationName,
|
|
86
86
|
});
|
|
87
|
-
const authLink = context.setContext((_, { headers }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
+
const authLink = React.useMemo(() => context.setContext((_, { headers }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
88
|
return {
|
|
89
89
|
headers: Object.assign(Object.assign(Object.assign({}, headers), tracingHeaders), { Authorization: token ? `Bearer ${token}` : null }),
|
|
90
90
|
};
|
|
91
|
-
}));
|
|
92
|
-
const errorLink = error.onError((errorResponse) => {
|
|
91
|
+
})), [token, tracingHeaders]);
|
|
92
|
+
const errorLink = React.useMemo(() => error.onError((errorResponse) => {
|
|
93
93
|
var _a, _b;
|
|
94
94
|
const traceIds = []; // Used to hold id's for use in Sentry
|
|
95
95
|
if (errorResponse.graphQLErrors) {
|
|
@@ -120,30 +120,29 @@ const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
|
120
120
|
},
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
((_c = x === null || x === void 0 ? void 0 : x.message) === null || _c === void 0 ? void 0 : _c.includes("Access denied! You need to be authorized to perform this action!"));
|
|
129
|
-
});
|
|
130
|
-
if (invalidToken) {
|
|
131
|
-
Sentry__namespace.captureException({
|
|
132
|
-
category: "GraphQL",
|
|
133
|
-
message: "GraphQL Error - invalidToken",
|
|
134
|
-
level: "warning",
|
|
135
|
-
data: {
|
|
136
|
-
log: JSON.stringify(errorResponse.graphQLErrors),
|
|
137
|
-
},
|
|
123
|
+
const invalidToken = (_b = errorResponse.graphQLErrors) === null || _b === void 0 ? void 0 : _b.some(x => {
|
|
124
|
+
var _a, _b, _c;
|
|
125
|
+
return (((_a = x === null || x === void 0 ? void 0 : x.extensions) === null || _a === void 0 ? void 0 : _a.code) === "UNAUTHENTICATED" ||
|
|
126
|
+
((_b = x === null || x === void 0 ? void 0 : x.message) === null || _b === void 0 ? void 0 : _b.includes("Invalid token specified")) ||
|
|
127
|
+
((_c = x === null || x === void 0 ? void 0 : x.message) === null || _c === void 0 ? void 0 : _c.includes("Access denied! You need to be authorized to perform this action!")));
|
|
138
128
|
});
|
|
139
|
-
|
|
129
|
+
if (invalidToken) {
|
|
130
|
+
Sentry__namespace.captureException({
|
|
131
|
+
category: "GraphQL",
|
|
132
|
+
message: "GraphQL Error - invalidToken",
|
|
133
|
+
level: "warning",
|
|
134
|
+
data: {
|
|
135
|
+
log: JSON.stringify(errorResponse.graphQLErrors),
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
140
139
|
}
|
|
141
140
|
if (errorResponse.networkError) {
|
|
142
141
|
// eslint-disable-next-line no-console
|
|
143
142
|
console.error(errorResponse.networkError);
|
|
144
143
|
}
|
|
145
|
-
});
|
|
146
|
-
const defaultOptions = {
|
|
144
|
+
}), []);
|
|
145
|
+
const defaultOptions = React.useMemo(() => ({
|
|
147
146
|
watchQuery: {
|
|
148
147
|
fetchPolicy: "no-cache",
|
|
149
148
|
errorPolicy: "all",
|
|
@@ -151,19 +150,31 @@ const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
|
151
150
|
query: {
|
|
152
151
|
fetchPolicy: "no-cache",
|
|
153
152
|
},
|
|
154
|
-
};
|
|
155
|
-
const client$1 =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
153
|
+
}), []);
|
|
154
|
+
const client$1 = React.useMemo(() => {
|
|
155
|
+
return new client.ApolloClient({
|
|
156
|
+
name: "Manager",
|
|
157
|
+
connectToDevTools: isDev,
|
|
158
|
+
cache: new client.InMemoryCache(),
|
|
159
|
+
defaultOptions,
|
|
160
|
+
link: client.from([
|
|
161
|
+
errorLink,
|
|
162
|
+
authLink,
|
|
163
|
+
client.split(operation => operation.getContext().clientName === "imageupload", imageUploadGraphQLLink),
|
|
164
|
+
client.split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, client.split(operation => operation.getContext().clientName === "report", reportGraphQLLink, isIrisApp ? publicGraphQLLink : managerGraphQLLink)),
|
|
165
|
+
]),
|
|
166
|
+
});
|
|
167
|
+
}, [
|
|
168
|
+
authLink,
|
|
159
169
|
defaultOptions,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
170
|
+
errorLink,
|
|
171
|
+
imageUploadGraphQLLink,
|
|
172
|
+
isDev,
|
|
173
|
+
isIrisApp,
|
|
174
|
+
managerGraphQLLink,
|
|
175
|
+
publicGraphQLLink,
|
|
176
|
+
reportGraphQLLink,
|
|
177
|
+
]);
|
|
167
178
|
return jsxRuntime.jsx(client.ApolloProvider, Object.assign({ client: client$1 }, { children: children }));
|
|
168
179
|
};
|
|
169
180
|
|
package/index.js
CHANGED
|
@@ -5,9 +5,9 @@ import { onError } from '@apollo/client/link/error';
|
|
|
5
5
|
import * as Sentry from '@sentry/browser';
|
|
6
6
|
import { useEnvironment, useToken, ToastProvider, AssetSortingProvider, EnvironmentContextProvider, GlobalSelectionProvider, TokenProvider, CurrentUserProvider, UserSubscriptionProvider as UserSubscriptionProvider$1, useURLSynchronization } from '@trackunit/react-core-hooks';
|
|
7
7
|
import { createUploadLink } from 'apollo-upload-client';
|
|
8
|
-
import { ToastRuntime, setupHostConnector, AssetSortingRuntime, EnvironmentRuntime, GlobalSelectionRuntime, TokenRuntime, CurrentUserRuntime, UserSubscriptionRuntime } from '@trackunit/iris-app-runtime-core';
|
|
9
8
|
import * as React from 'react';
|
|
10
9
|
import { useMemo, useEffect, useState } from 'react';
|
|
10
|
+
import { ToastRuntime, setupHostConnector, AssetSortingRuntime, EnvironmentRuntime, GlobalSelectionRuntime, TokenRuntime, CurrentUserRuntime, UserSubscriptionRuntime } from '@trackunit/iris-app-runtime-core';
|
|
11
11
|
import '@js-temporal/polyfill';
|
|
12
12
|
import { registerTranslations, initializeTranslationsForApp } from '@trackunit/i18n-library-translation';
|
|
13
13
|
import { Spinner } from '@trackunit/react-components';
|
|
@@ -46,7 +46,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
46
46
|
* @returns {JSX.Element} The provider.
|
|
47
47
|
*/
|
|
48
48
|
const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
49
|
-
const {
|
|
49
|
+
const { graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders } = useEnvironment();
|
|
50
50
|
const { token } = useToken();
|
|
51
51
|
const managerGraphQLLink = createUploadLink({
|
|
52
52
|
uri: request => graphqlManagerUrl + "/" + request.operationName,
|
|
@@ -60,12 +60,12 @@ const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
|
60
60
|
const reportGraphQLLink = createUploadLink({
|
|
61
61
|
uri: request => graphqlReportUrl + "/" + request.operationName,
|
|
62
62
|
});
|
|
63
|
-
const authLink = setContext((_, { headers }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
const authLink = useMemo(() => setContext((_, { headers }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
64
|
return {
|
|
65
65
|
headers: Object.assign(Object.assign(Object.assign({}, headers), tracingHeaders), { Authorization: token ? `Bearer ${token}` : null }),
|
|
66
66
|
};
|
|
67
|
-
}));
|
|
68
|
-
const errorLink = onError((errorResponse) => {
|
|
67
|
+
})), [token, tracingHeaders]);
|
|
68
|
+
const errorLink = useMemo(() => onError((errorResponse) => {
|
|
69
69
|
var _a, _b;
|
|
70
70
|
const traceIds = []; // Used to hold id's for use in Sentry
|
|
71
71
|
if (errorResponse.graphQLErrors) {
|
|
@@ -96,30 +96,29 @@ const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
|
96
96
|
},
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
((_c = x === null || x === void 0 ? void 0 : x.message) === null || _c === void 0 ? void 0 : _c.includes("Access denied! You need to be authorized to perform this action!"));
|
|
105
|
-
});
|
|
106
|
-
if (invalidToken) {
|
|
107
|
-
Sentry.captureException({
|
|
108
|
-
category: "GraphQL",
|
|
109
|
-
message: "GraphQL Error - invalidToken",
|
|
110
|
-
level: "warning",
|
|
111
|
-
data: {
|
|
112
|
-
log: JSON.stringify(errorResponse.graphQLErrors),
|
|
113
|
-
},
|
|
99
|
+
const invalidToken = (_b = errorResponse.graphQLErrors) === null || _b === void 0 ? void 0 : _b.some(x => {
|
|
100
|
+
var _a, _b, _c;
|
|
101
|
+
return (((_a = x === null || x === void 0 ? void 0 : x.extensions) === null || _a === void 0 ? void 0 : _a.code) === "UNAUTHENTICATED" ||
|
|
102
|
+
((_b = x === null || x === void 0 ? void 0 : x.message) === null || _b === void 0 ? void 0 : _b.includes("Invalid token specified")) ||
|
|
103
|
+
((_c = x === null || x === void 0 ? void 0 : x.message) === null || _c === void 0 ? void 0 : _c.includes("Access denied! You need to be authorized to perform this action!")));
|
|
114
104
|
});
|
|
115
|
-
|
|
105
|
+
if (invalidToken) {
|
|
106
|
+
Sentry.captureException({
|
|
107
|
+
category: "GraphQL",
|
|
108
|
+
message: "GraphQL Error - invalidToken",
|
|
109
|
+
level: "warning",
|
|
110
|
+
data: {
|
|
111
|
+
log: JSON.stringify(errorResponse.graphQLErrors),
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
116
115
|
}
|
|
117
116
|
if (errorResponse.networkError) {
|
|
118
117
|
// eslint-disable-next-line no-console
|
|
119
118
|
console.error(errorResponse.networkError);
|
|
120
119
|
}
|
|
121
|
-
});
|
|
122
|
-
const defaultOptions = {
|
|
120
|
+
}), []);
|
|
121
|
+
const defaultOptions = useMemo(() => ({
|
|
123
122
|
watchQuery: {
|
|
124
123
|
fetchPolicy: "no-cache",
|
|
125
124
|
errorPolicy: "all",
|
|
@@ -127,19 +126,31 @@ const ManagerApolloProvider = ({ children, isIrisApp }) => {
|
|
|
127
126
|
query: {
|
|
128
127
|
fetchPolicy: "no-cache",
|
|
129
128
|
},
|
|
130
|
-
};
|
|
131
|
-
const client =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
}), []);
|
|
130
|
+
const client = useMemo(() => {
|
|
131
|
+
return new ApolloClient({
|
|
132
|
+
name: "Manager",
|
|
133
|
+
connectToDevTools: isDev,
|
|
134
|
+
cache: new InMemoryCache(),
|
|
135
|
+
defaultOptions,
|
|
136
|
+
link: from([
|
|
137
|
+
errorLink,
|
|
138
|
+
authLink,
|
|
139
|
+
split(operation => operation.getContext().clientName === "imageupload", imageUploadGraphQLLink),
|
|
140
|
+
split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, split(operation => operation.getContext().clientName === "report", reportGraphQLLink, isIrisApp ? publicGraphQLLink : managerGraphQLLink)),
|
|
141
|
+
]),
|
|
142
|
+
});
|
|
143
|
+
}, [
|
|
144
|
+
authLink,
|
|
135
145
|
defaultOptions,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
146
|
+
errorLink,
|
|
147
|
+
imageUploadGraphQLLink,
|
|
148
|
+
isDev,
|
|
149
|
+
isIrisApp,
|
|
150
|
+
managerGraphQLLink,
|
|
151
|
+
publicGraphQLLink,
|
|
152
|
+
reportGraphQLLink,
|
|
153
|
+
]);
|
|
143
154
|
return jsx(ApolloProvider, Object.assign({ client: client }, { children: children }));
|
|
144
155
|
};
|
|
145
156
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.137",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@sentry/browser": "7.50.0",
|
|
11
11
|
"@trackunit/i18n-library-translation": "0.0.46",
|
|
12
12
|
"@trackunit/iris-app-runtime-core": "0.3.38",
|
|
13
|
-
"@trackunit/react-components": "0.1.
|
|
13
|
+
"@trackunit/react-components": "0.1.89",
|
|
14
14
|
"@trackunit/react-core-contexts-api": "0.2.29",
|
|
15
15
|
"@trackunit/react-core-contexts-test": "0.1.56",
|
|
16
16
|
"@trackunit/react-core-hooks": "0.2.51",
|