@trackunit/react-core-contexts 0.4.382 → 0.4.387
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.js
CHANGED
|
@@ -63,7 +63,10 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, }) => {
|
|
66
|
-
let token
|
|
66
|
+
let token;
|
|
67
|
+
if (!token) {
|
|
68
|
+
token = firstToken;
|
|
69
|
+
}
|
|
67
70
|
const managerGraphQLLink = apolloUploadClient.createUploadLink({
|
|
68
71
|
uri: request => graphqlManagerUrl + "/" + request.operationName,
|
|
69
72
|
});
|
|
@@ -129,7 +132,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
129
132
|
((_b = x === null || x === void 0 ? void 0 : x.message) === null || _b === void 0 ? void 0 : _b.includes("Invalid token specified")) ||
|
|
130
133
|
((_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!")));
|
|
131
134
|
});
|
|
132
|
-
if (invalidToken) {
|
|
135
|
+
if (invalidToken && token) {
|
|
133
136
|
Sentry__namespace.captureException(new Error(JSON.stringify({
|
|
134
137
|
category: "GraphQL",
|
|
135
138
|
info: "GraphQL Error - invalidToken",
|
|
@@ -186,18 +189,12 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
186
189
|
const useApolloClient = () => {
|
|
187
190
|
var _a;
|
|
188
191
|
const { graphqlManagerUrl, graphqlPublicUrl, graphqlInternalUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders, } = reactCoreHooks.useEnvironment();
|
|
189
|
-
const { isAssuming } = reactCoreHooks.useCurrentUser();
|
|
190
192
|
const { token } = reactCoreHooks.useToken();
|
|
191
|
-
const isAssumingRef = React__namespace.useRef(null);
|
|
192
193
|
const clientRef = React__namespace.useRef(null);
|
|
193
|
-
if (isAssumingRef.current === null) {
|
|
194
|
-
isAssumingRef.current = isAssuming;
|
|
195
|
-
}
|
|
196
194
|
/* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
|
|
197
195
|
the token will then be set on the instance without react reporting a new client
|
|
198
196
|
and recreating if token change from null to something*/
|
|
199
|
-
if (!clientRef.current || !clientRef.current.getToken()
|
|
200
|
-
isAssumingRef.current = !isAssumingRef.current;
|
|
197
|
+
if (!clientRef.current || !clientRef.current.getToken()) {
|
|
201
198
|
clientRef.current = createApolloClient({
|
|
202
199
|
graphqlManagerUrl,
|
|
203
200
|
graphqlPublicUrl,
|
|
@@ -209,7 +206,7 @@ const useApolloClient = () => {
|
|
|
209
206
|
firstToken: token,
|
|
210
207
|
});
|
|
211
208
|
}
|
|
212
|
-
|
|
209
|
+
if (clientRef.current.getToken() !== token) {
|
|
213
210
|
clientRef.current.setToken(token);
|
|
214
211
|
}
|
|
215
212
|
return (_a = clientRef.current) === null || _a === void 0 ? void 0 : _a.client;
|
|
@@ -285,6 +282,14 @@ const AssetSortingProviderIrisApp = ({ children }) => {
|
|
|
285
282
|
return jsxRuntime.jsx(reactCoreHooks.AssetSortingProvider, { value: contextValue, children: children });
|
|
286
283
|
};
|
|
287
284
|
|
|
285
|
+
/**
|
|
286
|
+
* This is a provider for the ConfirmationDialogContext.
|
|
287
|
+
*/
|
|
288
|
+
const ConfirmationDialogProviderIrisApp = ({ children }) => {
|
|
289
|
+
const value = React.useMemo(() => ({ confirm: irisAppRuntimeCore.ConfirmationDialogRuntime.confirm }), []);
|
|
290
|
+
return jsxRuntime.jsx(reactCoreHooks.ConfirmationDialogProvider, { value: value, children: children });
|
|
291
|
+
};
|
|
292
|
+
|
|
288
293
|
/**
|
|
289
294
|
* This is a provider for the EnvironmentContext.
|
|
290
295
|
*/
|
|
@@ -485,7 +490,7 @@ const TrackunitProviders = ({ translations, children }) => {
|
|
|
485
490
|
i18nLibraryTranslation.registerTranslations(translations); // Register the apps translations if passed.
|
|
486
491
|
}
|
|
487
492
|
i18nLibraryTranslation.initializeTranslationsForApp(); // Initialize all registered translations
|
|
488
|
-
return (jsxRuntime.jsx(EnvironmentProviderIrisApp, { children: jsxRuntime.jsx(TokenProviderIrisApp, { children: jsxRuntime.jsx(CurrentUserPreferenceProviderIrisApp, { children: jsxRuntime.jsx(CurrentUserProviderIrisApp, { children: jsxRuntime.jsx(UserSubscriptionProviderIrisApp, { children: jsxRuntime.jsx(AnalyticsProviderIrisApp, { children: jsxRuntime.jsx(OemBrandingContextProviderIrisApp, { children: jsxRuntime.jsx(AssetSortingProviderIrisApp, { children: jsxRuntime.jsx(ManagerApolloProvider, { children: jsxRuntime.jsx(NavigationProviderIrisApp, { children: jsxRuntime.jsx(ToastProviderIrisApp, { children: jsxRuntime.jsx(FilterBarProviderIrisApp, { children: jsxRuntime.jsx(React__namespace.Suspense, { fallback: jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered" }), children: jsxRuntime.jsx(TrackunitRouterIrisApp, { children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
493
|
+
return (jsxRuntime.jsx(EnvironmentProviderIrisApp, { children: jsxRuntime.jsx(TokenProviderIrisApp, { children: jsxRuntime.jsx(CurrentUserPreferenceProviderIrisApp, { children: jsxRuntime.jsx(CurrentUserProviderIrisApp, { children: jsxRuntime.jsx(UserSubscriptionProviderIrisApp, { children: jsxRuntime.jsx(AnalyticsProviderIrisApp, { children: jsxRuntime.jsx(OemBrandingContextProviderIrisApp, { children: jsxRuntime.jsx(AssetSortingProviderIrisApp, { children: jsxRuntime.jsx(ManagerApolloProvider, { children: jsxRuntime.jsx(NavigationProviderIrisApp, { children: jsxRuntime.jsx(ToastProviderIrisApp, { children: jsxRuntime.jsx(ConfirmationDialogProviderIrisApp, { children: jsxRuntime.jsx(FilterBarProviderIrisApp, { children: jsxRuntime.jsx(React__namespace.Suspense, { fallback: jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered" }), children: jsxRuntime.jsx(TrackunitRouterIrisApp, { children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
489
494
|
};
|
|
490
495
|
|
|
491
496
|
exports.ManagerApolloProvider = ManagerApolloProvider;
|
package/index.esm.js
CHANGED
|
@@ -3,14 +3,14 @@ import { ApolloProvider, ApolloClient, InMemoryCache, from, split } from '@apoll
|
|
|
3
3
|
import { setContext } from '@apollo/client/link/context';
|
|
4
4
|
import { onError } from '@apollo/client/link/error';
|
|
5
5
|
import * as Sentry from '@sentry/browser';
|
|
6
|
-
import { useEnvironment,
|
|
6
|
+
import { useEnvironment, useToken, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, FilterBarProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, useURLSynchronization, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider } from '@trackunit/react-core-hooks';
|
|
7
7
|
import { createUploadLink } from 'apollo-upload-client';
|
|
8
8
|
import * as React from 'react';
|
|
9
9
|
import { useMemo, useEffect, useState } from 'react';
|
|
10
10
|
import '@js-temporal/polyfill';
|
|
11
11
|
import { registerTranslations, initializeTranslationsForApp } from '@trackunit/i18n-library-translation';
|
|
12
12
|
import { Spinner } from '@trackunit/react-components';
|
|
13
|
-
import { AnalyticsContextRuntime, setupHostConnector, AssetSortingRuntime, EnvironmentRuntime, FilterBarRuntime, NavigationRuntime, OemBrandingContextRuntime, ToastRuntime, TokenRuntime, CurrentUserRuntime, CurrentUserPreferenceRuntime, UserSubscriptionRuntime } from '@trackunit/iris-app-runtime-core';
|
|
13
|
+
import { AnalyticsContextRuntime, setupHostConnector, AssetSortingRuntime, ConfirmationDialogRuntime, EnvironmentRuntime, FilterBarRuntime, NavigationRuntime, OemBrandingContextRuntime, ToastRuntime, TokenRuntime, CurrentUserRuntime, CurrentUserPreferenceRuntime, UserSubscriptionRuntime } from '@trackunit/iris-app-runtime-core';
|
|
14
14
|
import { BrowserRouter } from 'react-router-dom';
|
|
15
15
|
|
|
16
16
|
/******************************************************************************
|
|
@@ -39,7 +39,10 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, }) => {
|
|
42
|
-
let token
|
|
42
|
+
let token;
|
|
43
|
+
if (!token) {
|
|
44
|
+
token = firstToken;
|
|
45
|
+
}
|
|
43
46
|
const managerGraphQLLink = createUploadLink({
|
|
44
47
|
uri: request => graphqlManagerUrl + "/" + request.operationName,
|
|
45
48
|
});
|
|
@@ -105,7 +108,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
105
108
|
((_b = x === null || x === void 0 ? void 0 : x.message) === null || _b === void 0 ? void 0 : _b.includes("Invalid token specified")) ||
|
|
106
109
|
((_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!")));
|
|
107
110
|
});
|
|
108
|
-
if (invalidToken) {
|
|
111
|
+
if (invalidToken && token) {
|
|
109
112
|
Sentry.captureException(new Error(JSON.stringify({
|
|
110
113
|
category: "GraphQL",
|
|
111
114
|
info: "GraphQL Error - invalidToken",
|
|
@@ -162,18 +165,12 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
162
165
|
const useApolloClient = () => {
|
|
163
166
|
var _a;
|
|
164
167
|
const { graphqlManagerUrl, graphqlPublicUrl, graphqlInternalUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders, } = useEnvironment();
|
|
165
|
-
const { isAssuming } = useCurrentUser();
|
|
166
168
|
const { token } = useToken();
|
|
167
|
-
const isAssumingRef = React.useRef(null);
|
|
168
169
|
const clientRef = React.useRef(null);
|
|
169
|
-
if (isAssumingRef.current === null) {
|
|
170
|
-
isAssumingRef.current = isAssuming;
|
|
171
|
-
}
|
|
172
170
|
/* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
|
|
173
171
|
the token will then be set on the instance without react reporting a new client
|
|
174
172
|
and recreating if token change from null to something*/
|
|
175
|
-
if (!clientRef.current || !clientRef.current.getToken()
|
|
176
|
-
isAssumingRef.current = !isAssumingRef.current;
|
|
173
|
+
if (!clientRef.current || !clientRef.current.getToken()) {
|
|
177
174
|
clientRef.current = createApolloClient({
|
|
178
175
|
graphqlManagerUrl,
|
|
179
176
|
graphqlPublicUrl,
|
|
@@ -185,7 +182,7 @@ const useApolloClient = () => {
|
|
|
185
182
|
firstToken: token,
|
|
186
183
|
});
|
|
187
184
|
}
|
|
188
|
-
|
|
185
|
+
if (clientRef.current.getToken() !== token) {
|
|
189
186
|
clientRef.current.setToken(token);
|
|
190
187
|
}
|
|
191
188
|
return (_a = clientRef.current) === null || _a === void 0 ? void 0 : _a.client;
|
|
@@ -261,6 +258,14 @@ const AssetSortingProviderIrisApp = ({ children }) => {
|
|
|
261
258
|
return jsx(AssetSortingProvider, { value: contextValue, children: children });
|
|
262
259
|
};
|
|
263
260
|
|
|
261
|
+
/**
|
|
262
|
+
* This is a provider for the ConfirmationDialogContext.
|
|
263
|
+
*/
|
|
264
|
+
const ConfirmationDialogProviderIrisApp = ({ children }) => {
|
|
265
|
+
const value = useMemo(() => ({ confirm: ConfirmationDialogRuntime.confirm }), []);
|
|
266
|
+
return jsx(ConfirmationDialogProvider, { value: value, children: children });
|
|
267
|
+
};
|
|
268
|
+
|
|
264
269
|
/**
|
|
265
270
|
* This is a provider for the EnvironmentContext.
|
|
266
271
|
*/
|
|
@@ -461,7 +466,7 @@ const TrackunitProviders = ({ translations, children }) => {
|
|
|
461
466
|
registerTranslations(translations); // Register the apps translations if passed.
|
|
462
467
|
}
|
|
463
468
|
initializeTranslationsForApp(); // Initialize all registered translations
|
|
464
|
-
return (jsx(EnvironmentProviderIrisApp, { children: jsx(TokenProviderIrisApp, { children: jsx(CurrentUserPreferenceProviderIrisApp, { children: jsx(CurrentUserProviderIrisApp, { children: jsx(UserSubscriptionProviderIrisApp, { children: jsx(AnalyticsProviderIrisApp, { children: jsx(OemBrandingContextProviderIrisApp, { children: jsx(AssetSortingProviderIrisApp, { children: jsx(ManagerApolloProvider, { children: jsx(NavigationProviderIrisApp, { children: jsx(ToastProviderIrisApp, { children: jsx(FilterBarProviderIrisApp, { children: jsx(React.Suspense, { fallback: jsx(Spinner, { centering: "centered" }), children: jsx(TrackunitRouterIrisApp, { children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
469
|
+
return (jsx(EnvironmentProviderIrisApp, { children: jsx(TokenProviderIrisApp, { children: jsx(CurrentUserPreferenceProviderIrisApp, { children: jsx(CurrentUserProviderIrisApp, { children: jsx(UserSubscriptionProviderIrisApp, { children: jsx(AnalyticsProviderIrisApp, { children: jsx(OemBrandingContextProviderIrisApp, { children: jsx(AssetSortingProviderIrisApp, { children: jsx(ManagerApolloProvider, { children: jsx(NavigationProviderIrisApp, { children: jsx(ToastProviderIrisApp, { children: jsx(ConfirmationDialogProviderIrisApp, { children: jsx(FilterBarProviderIrisApp, { children: jsx(React.Suspense, { fallback: jsx(Spinner, { centering: "centered" }), children: jsx(TrackunitRouterIrisApp, { children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
465
470
|
};
|
|
466
471
|
|
|
467
472
|
export { ManagerApolloProvider, ToastProviderIrisApp, TrackunitProviders };
|
package/package.json
CHANGED