@trackunit/react-core-contexts 0.4.526 → 0.4.529
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
|
@@ -6,7 +6,6 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
var client = require('@apollo/client');
|
|
7
7
|
var context = require('@apollo/client/link/context');
|
|
8
8
|
var error = require('@apollo/client/link/error');
|
|
9
|
-
var Sentry = require('@sentry/browser');
|
|
10
9
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
11
10
|
var apolloUploadClient = require('apollo-upload-client');
|
|
12
11
|
var React = require('react');
|
|
@@ -33,7 +32,6 @@ function _interopNamespace(e) {
|
|
|
33
32
|
return Object.freeze(n);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
var Sentry__namespace = /*#__PURE__*/_interopNamespace(Sentry);
|
|
37
35
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
38
36
|
|
|
39
37
|
/******************************************************************************
|
|
@@ -66,7 +64,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
66
64
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
67
65
|
};
|
|
68
66
|
|
|
69
|
-
const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, }) => {
|
|
67
|
+
const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, errorHandler, }) => {
|
|
70
68
|
let token;
|
|
71
69
|
if (!token) {
|
|
72
70
|
token = firstToken;
|
|
@@ -129,9 +127,9 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
129
127
|
* name.
|
|
130
128
|
*/
|
|
131
129
|
if (traceIds.length) {
|
|
132
|
-
|
|
130
|
+
errorHandler.setTag("traceIds", traceIds.join(", "));
|
|
133
131
|
}
|
|
134
|
-
|
|
132
|
+
errorHandler.addBreadcrumb({
|
|
135
133
|
category: "GraphQL",
|
|
136
134
|
message: "GraphQL Error",
|
|
137
135
|
level: "error",
|
|
@@ -145,7 +143,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
145
143
|
x.message.includes("Access denied! You need to be authorized to perform this action!"));
|
|
146
144
|
});
|
|
147
145
|
if (invalidToken && token) {
|
|
148
|
-
|
|
146
|
+
errorHandler.captureException(new Error(JSON.stringify({
|
|
149
147
|
category: "GraphQL",
|
|
150
148
|
info: "GraphQL Error - invalidToken",
|
|
151
149
|
level: "warning",
|
|
@@ -201,6 +199,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
201
199
|
const useApolloClient = () => {
|
|
202
200
|
const { graphqlManagerUrl, graphqlPublicUrl, graphqlInternalUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, environment, tracingHeaders, } = reactCoreHooks.useEnvironment();
|
|
203
201
|
const { token } = reactCoreHooks.useToken();
|
|
202
|
+
const errorHandler = reactCoreHooks.useErrorHandler();
|
|
204
203
|
const clientRef = React.useRef(null);
|
|
205
204
|
/* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
|
|
206
205
|
the token will then be set on the instance without react reporting a new client
|
|
@@ -215,6 +214,7 @@ const useApolloClient = () => {
|
|
|
215
214
|
isDev: environment === "dev",
|
|
216
215
|
tracingHeaders,
|
|
217
216
|
firstToken: token,
|
|
217
|
+
errorHandler,
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
220
|
if (clientRef.current.getToken() !== token) {
|
|
@@ -325,6 +325,25 @@ const EnvironmentProviderIrisApp = ({ children }) => {
|
|
|
325
325
|
return jsxRuntime.jsx(reactCoreHooks.EnvironmentContextProvider, { value: environment, children: children });
|
|
326
326
|
};
|
|
327
327
|
|
|
328
|
+
/**
|
|
329
|
+
* This is a provider for the ErrorHandlingProvider.
|
|
330
|
+
*/
|
|
331
|
+
const ErrorHandlingProviderIrisApp = ({ children, errorHandler }) => {
|
|
332
|
+
const defaultContextValue = React.useMemo(() => ({
|
|
333
|
+
captureException: details => {
|
|
334
|
+
// eslint-disable-next-line no-console
|
|
335
|
+
console.error(details);
|
|
336
|
+
},
|
|
337
|
+
addBreadcrumb: breadcrumb => {
|
|
338
|
+
// do nothing
|
|
339
|
+
},
|
|
340
|
+
setTag: (key, value) => {
|
|
341
|
+
// do nothing
|
|
342
|
+
},
|
|
343
|
+
}), []);
|
|
344
|
+
return (jsxRuntime.jsx(reactCoreHooks.ErrorHandlingContextProvider, { value: errorHandler || defaultContextValue, children: children }));
|
|
345
|
+
};
|
|
346
|
+
|
|
328
347
|
/**
|
|
329
348
|
* This is a provider for the FilterBarContext.
|
|
330
349
|
*/
|
|
@@ -507,12 +526,12 @@ const UserSubscriptionProviderIrisApp = ({ children }) => {
|
|
|
507
526
|
/**
|
|
508
527
|
* This is a provider for the TrackunitDataProviders.
|
|
509
528
|
*/
|
|
510
|
-
const TrackunitProviders = ({ translations, children }) => {
|
|
529
|
+
const TrackunitProviders = ({ translations, children, errorHandler }) => {
|
|
511
530
|
if (translations) {
|
|
512
531
|
i18nLibraryTranslation.registerTranslations(translations); // Register the apps translations if passed.
|
|
513
532
|
}
|
|
514
533
|
i18nLibraryTranslation.initializeTranslationsForApp(); // Initialize all registered translations
|
|
515
|
-
return (jsxRuntime.jsx(EnvironmentProviderIrisApp, { children: jsxRuntime.jsx(ThemeCssProviderIrisApp, { 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(ModalDialogContextProviderIrisApp, { children: jsxRuntime.jsx(ConfirmationDialogProviderIrisApp, { children: jsxRuntime.jsx(FilterBarProviderIrisApp, { children: jsxRuntime.jsx(React__namespace.Suspense, { fallback: jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
534
|
+
return (jsxRuntime.jsx(EnvironmentProviderIrisApp, { children: jsxRuntime.jsx(ErrorHandlingProviderIrisApp, { errorHandler: errorHandler, children: jsxRuntime.jsx(ThemeCssProviderIrisApp, { 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(ModalDialogContextProviderIrisApp, { children: jsxRuntime.jsx(ConfirmationDialogProviderIrisApp, { children: jsxRuntime.jsx(FilterBarProviderIrisApp, { children: jsxRuntime.jsx(React__namespace.Suspense, { fallback: jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
516
535
|
};
|
|
517
536
|
|
|
518
537
|
exports.ManagerApolloProvider = ManagerApolloProvider;
|
package/index.esm.js
CHANGED
|
@@ -2,8 +2,7 @@ import { jsx, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { ApolloProvider, ApolloClient, InMemoryCache, from, split } from '@apollo/client';
|
|
3
3
|
import { setContext } from '@apollo/client/link/context';
|
|
4
4
|
import { onError } from '@apollo/client/link/error';
|
|
5
|
-
import
|
|
6
|
-
import { useEnvironment, useToken, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider } from '@trackunit/react-core-hooks';
|
|
5
|
+
import { useEnvironment, useToken, useErrorHandler, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider } from '@trackunit/react-core-hooks';
|
|
7
6
|
import { createUploadLink } from 'apollo-upload-client';
|
|
8
7
|
import * as React from 'react';
|
|
9
8
|
import { useRef, useMemo, useEffect, useState } from 'react';
|
|
@@ -42,7 +41,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
42
41
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
43
42
|
};
|
|
44
43
|
|
|
45
|
-
const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, }) => {
|
|
44
|
+
const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, errorHandler, }) => {
|
|
46
45
|
let token;
|
|
47
46
|
if (!token) {
|
|
48
47
|
token = firstToken;
|
|
@@ -105,9 +104,9 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
105
104
|
* name.
|
|
106
105
|
*/
|
|
107
106
|
if (traceIds.length) {
|
|
108
|
-
|
|
107
|
+
errorHandler.setTag("traceIds", traceIds.join(", "));
|
|
109
108
|
}
|
|
110
|
-
|
|
109
|
+
errorHandler.addBreadcrumb({
|
|
111
110
|
category: "GraphQL",
|
|
112
111
|
message: "GraphQL Error",
|
|
113
112
|
level: "error",
|
|
@@ -121,7 +120,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
121
120
|
x.message.includes("Access denied! You need to be authorized to perform this action!"));
|
|
122
121
|
});
|
|
123
122
|
if (invalidToken && token) {
|
|
124
|
-
|
|
123
|
+
errorHandler.captureException(new Error(JSON.stringify({
|
|
125
124
|
category: "GraphQL",
|
|
126
125
|
info: "GraphQL Error - invalidToken",
|
|
127
126
|
level: "warning",
|
|
@@ -177,6 +176,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
|
|
|
177
176
|
const useApolloClient = () => {
|
|
178
177
|
const { graphqlManagerUrl, graphqlPublicUrl, graphqlInternalUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, environment, tracingHeaders, } = useEnvironment();
|
|
179
178
|
const { token } = useToken();
|
|
179
|
+
const errorHandler = useErrorHandler();
|
|
180
180
|
const clientRef = useRef(null);
|
|
181
181
|
/* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
|
|
182
182
|
the token will then be set on the instance without react reporting a new client
|
|
@@ -191,6 +191,7 @@ const useApolloClient = () => {
|
|
|
191
191
|
isDev: environment === "dev",
|
|
192
192
|
tracingHeaders,
|
|
193
193
|
firstToken: token,
|
|
194
|
+
errorHandler,
|
|
194
195
|
});
|
|
195
196
|
}
|
|
196
197
|
if (clientRef.current.getToken() !== token) {
|
|
@@ -301,6 +302,25 @@ const EnvironmentProviderIrisApp = ({ children }) => {
|
|
|
301
302
|
return jsx(EnvironmentContextProvider, { value: environment, children: children });
|
|
302
303
|
};
|
|
303
304
|
|
|
305
|
+
/**
|
|
306
|
+
* This is a provider for the ErrorHandlingProvider.
|
|
307
|
+
*/
|
|
308
|
+
const ErrorHandlingProviderIrisApp = ({ children, errorHandler }) => {
|
|
309
|
+
const defaultContextValue = useMemo(() => ({
|
|
310
|
+
captureException: details => {
|
|
311
|
+
// eslint-disable-next-line no-console
|
|
312
|
+
console.error(details);
|
|
313
|
+
},
|
|
314
|
+
addBreadcrumb: breadcrumb => {
|
|
315
|
+
// do nothing
|
|
316
|
+
},
|
|
317
|
+
setTag: (key, value) => {
|
|
318
|
+
// do nothing
|
|
319
|
+
},
|
|
320
|
+
}), []);
|
|
321
|
+
return (jsx(ErrorHandlingContextProvider, { value: errorHandler || defaultContextValue, children: children }));
|
|
322
|
+
};
|
|
323
|
+
|
|
304
324
|
/**
|
|
305
325
|
* This is a provider for the FilterBarContext.
|
|
306
326
|
*/
|
|
@@ -483,12 +503,12 @@ const UserSubscriptionProviderIrisApp = ({ children }) => {
|
|
|
483
503
|
/**
|
|
484
504
|
* This is a provider for the TrackunitDataProviders.
|
|
485
505
|
*/
|
|
486
|
-
const TrackunitProviders = ({ translations, children }) => {
|
|
506
|
+
const TrackunitProviders = ({ translations, children, errorHandler }) => {
|
|
487
507
|
if (translations) {
|
|
488
508
|
registerTranslations(translations); // Register the apps translations if passed.
|
|
489
509
|
}
|
|
490
510
|
initializeTranslationsForApp(); // Initialize all registered translations
|
|
491
|
-
return (jsx(EnvironmentProviderIrisApp, { children: jsx(ThemeCssProviderIrisApp, { 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(ModalDialogContextProviderIrisApp, { children: jsx(ConfirmationDialogProviderIrisApp, { children: jsx(FilterBarProviderIrisApp, { children: jsx(React.Suspense, { fallback: jsx(Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
511
|
+
return (jsx(EnvironmentProviderIrisApp, { children: jsx(ErrorHandlingProviderIrisApp, { errorHandler: errorHandler, children: jsx(ThemeCssProviderIrisApp, { 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(ModalDialogContextProviderIrisApp, { children: jsx(ConfirmationDialogProviderIrisApp, { children: jsx(FilterBarProviderIrisApp, { children: jsx(React.Suspense, { fallback: jsx(Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
|
|
492
512
|
};
|
|
493
513
|
|
|
494
514
|
export { ManagerApolloProvider, ToastProviderIrisApp, TrackunitProviders };
|
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.529",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@apollo/client": "3.10.4",
|
|
11
|
-
"@sentry/browser": "^7.113.0",
|
|
12
11
|
"@trackunit/react-core-contexts-api": "*",
|
|
13
12
|
"@trackunit/react-core-hooks": "*",
|
|
14
13
|
"apollo-upload-client": "^17.0.0",
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import { TranslationResource } from "@trackunit/i18n-library-translation";
|
|
3
|
+
import { ErrorHandlingContextValue } from "@trackunit/react-core-contexts-api";
|
|
3
4
|
import * as React from "react";
|
|
4
5
|
export interface TrackunitProvidersProps {
|
|
5
6
|
/** A translation resource for the App extensions to be registered before initialization */
|
|
6
7
|
translations?: TranslationResource<string>;
|
|
8
|
+
errorHandler?: ErrorHandlingContextValue;
|
|
7
9
|
children: React.ReactNode;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* This is a provider for the TrackunitDataProviders.
|
|
11
13
|
*/
|
|
12
|
-
export declare const TrackunitProviders: ({ translations, children }: TrackunitProvidersProps) => JSX.Element;
|
|
14
|
+
export declare const TrackunitProviders: ({ translations, children, errorHandler }: TrackunitProvidersProps) => JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ErrorHandlingContextValue } from "@trackunit/react-core-contexts-api";
|
|
2
|
+
import { type PropsWithChildren } from "react";
|
|
3
|
+
interface ErrorHandlingProviderIrisAppProps extends PropsWithChildren {
|
|
4
|
+
errorHandler?: ErrorHandlingContextValue;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This is a provider for the ErrorHandlingProvider.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ErrorHandlingProviderIrisApp: ({ children, errorHandler }: ErrorHandlingProviderIrisAppProps) => JSX.Element;
|
|
10
|
+
export {};
|