@trackunit/react-core-contexts 0.4.135 → 0.4.138

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 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 { publicUrl, graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders, } = reactCoreHooks.useEnvironment();
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
- const invalidToken = (_b = errorResponse.graphQLErrors) === null || _b === void 0 ? void 0 : _b.some(x => {
125
- var _a, _b, _c;
126
- return ((_a = x === null || x === void 0 ? void 0 : x.extensions) === null || _a === void 0 ? void 0 : _a.code) === "UNAUTHENTICATED" ||
127
- ((_b = x === null || x === void 0 ? void 0 : x.message) === null || _b === void 0 ? void 0 : _b.includes("Invalid token specified")) ||
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
- window.location.replace(`${publicUrl}logout`);
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 = new client.ApolloClient({
156
- name: "Manager",
157
- connectToDevTools: isDev,
158
- cache: new client.InMemoryCache(),
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
- 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
- });
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
 
@@ -175,6 +186,27 @@ const ToastProviderApp = ({ children }) => {
175
186
  return jsxRuntime.jsx(reactCoreHooks.ToastProvider, Object.assign({ value: value }, { children: children }));
176
187
  };
177
188
 
189
+ /**
190
+ * This is a provider for the AnalyticsProvider.
191
+ */
192
+ const AnalyticsProvider = ({ children }) => {
193
+ const contextValue = React.useMemo(() => ({
194
+ logPageView: details => {
195
+ irisAppRuntimeCore.AnalyticsContextRuntime.logPageView(details);
196
+ },
197
+ logEvent: (eventName, details, nameSupplement) => {
198
+ irisAppRuntimeCore.AnalyticsContextRuntime.logEvent(eventName, details, nameSupplement);
199
+ },
200
+ logError: details => {
201
+ irisAppRuntimeCore.AnalyticsContextRuntime.logError(details);
202
+ },
203
+ setUserProperty: (name, value) => {
204
+ irisAppRuntimeCore.AnalyticsContextRuntime.setUserProperty(name, value);
205
+ },
206
+ }), []);
207
+ return jsxRuntime.jsx(reactCoreHooks.AnalyticsContextProvider, Object.assign({ value: contextValue }, { children: children }));
208
+ };
209
+
178
210
  /**
179
211
  * Subscribe to methods initiated by changes in the host
180
212
  *
@@ -318,7 +350,7 @@ const UserSubscriptionProvider = ({ children }) => {
318
350
  /**
319
351
  * This is a provider for the TrackunitDataProviders.
320
352
  */
321
- const TrackunitDataProviders = ({ children }) => (jsxRuntime.jsx(TileEnvironmentProvider, { children: jsxRuntime.jsx(TileTokenProvider, { children: jsxRuntime.jsx(TileCurrentUserProvider, { children: jsxRuntime.jsx(UserSubscriptionProvider, { children: jsxRuntime.jsx(TileGlobalSelectionProvider, { children: jsxRuntime.jsx(TileAssetSortingProvider, { children: jsxRuntime.jsx(ManagerApolloProvider, Object.assign({ isIrisApp: true }, { children: children })) }) }) }) }) }) }));
353
+ const TrackunitDataProviders = ({ children }) => (jsxRuntime.jsx(TileEnvironmentProvider, { children: jsxRuntime.jsx(TileTokenProvider, { children: jsxRuntime.jsx(TileCurrentUserProvider, { children: jsxRuntime.jsx(UserSubscriptionProvider, { children: jsxRuntime.jsx(AnalyticsProvider, { children: jsxRuntime.jsx(TileGlobalSelectionProvider, { children: jsxRuntime.jsx(TileAssetSortingProvider, { children: jsxRuntime.jsx(ManagerApolloProvider, Object.assign({ isIrisApp: true }, { children: children })) }) }) }) }) }) }) }));
322
354
 
323
355
  const HostNavigator = ({ children }) => {
324
356
  reactCoreHooks.useURLSynchronization();
package/index.js CHANGED
@@ -3,11 +3,11 @@ import { ApolloClient, InMemoryCache, from, split, ApolloProvider } 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, useToken, ToastProvider, AssetSortingProvider, EnvironmentContextProvider, GlobalSelectionProvider, TokenProvider, CurrentUserProvider, UserSubscriptionProvider as UserSubscriptionProvider$1, useURLSynchronization } from '@trackunit/react-core-hooks';
6
+ import { useEnvironment, useToken, ToastProvider, AnalyticsContextProvider, 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, AnalyticsContextRuntime, 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 { publicUrl, graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders, } = useEnvironment();
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
- const invalidToken = (_b = errorResponse.graphQLErrors) === null || _b === void 0 ? void 0 : _b.some(x => {
101
- var _a, _b, _c;
102
- return ((_a = x === null || x === void 0 ? void 0 : x.extensions) === null || _a === void 0 ? void 0 : _a.code) === "UNAUTHENTICATED" ||
103
- ((_b = x === null || x === void 0 ? void 0 : x.message) === null || _b === void 0 ? void 0 : _b.includes("Invalid token specified")) ||
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
- window.location.replace(`${publicUrl}logout`);
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 = new ApolloClient({
132
- name: "Manager",
133
- connectToDevTools: isDev,
134
- cache: new InMemoryCache(),
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
- 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
- });
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
 
@@ -151,6 +162,27 @@ const ToastProviderApp = ({ children }) => {
151
162
  return jsx(ToastProvider, Object.assign({ value: value }, { children: children }));
152
163
  };
153
164
 
165
+ /**
166
+ * This is a provider for the AnalyticsProvider.
167
+ */
168
+ const AnalyticsProvider = ({ children }) => {
169
+ const contextValue = useMemo(() => ({
170
+ logPageView: details => {
171
+ AnalyticsContextRuntime.logPageView(details);
172
+ },
173
+ logEvent: (eventName, details, nameSupplement) => {
174
+ AnalyticsContextRuntime.logEvent(eventName, details, nameSupplement);
175
+ },
176
+ logError: details => {
177
+ AnalyticsContextRuntime.logError(details);
178
+ },
179
+ setUserProperty: (name, value) => {
180
+ AnalyticsContextRuntime.setUserProperty(name, value);
181
+ },
182
+ }), []);
183
+ return jsx(AnalyticsContextProvider, Object.assign({ value: contextValue }, { children: children }));
184
+ };
185
+
154
186
  /**
155
187
  * Subscribe to methods initiated by changes in the host
156
188
  *
@@ -294,7 +326,7 @@ const UserSubscriptionProvider = ({ children }) => {
294
326
  /**
295
327
  * This is a provider for the TrackunitDataProviders.
296
328
  */
297
- const TrackunitDataProviders = ({ children }) => (jsx(TileEnvironmentProvider, { children: jsx(TileTokenProvider, { children: jsx(TileCurrentUserProvider, { children: jsx(UserSubscriptionProvider, { children: jsx(TileGlobalSelectionProvider, { children: jsx(TileAssetSortingProvider, { children: jsx(ManagerApolloProvider, Object.assign({ isIrisApp: true }, { children: children })) }) }) }) }) }) }));
329
+ const TrackunitDataProviders = ({ children }) => (jsx(TileEnvironmentProvider, { children: jsx(TileTokenProvider, { children: jsx(TileCurrentUserProvider, { children: jsx(UserSubscriptionProvider, { children: jsx(AnalyticsProvider, { children: jsx(TileGlobalSelectionProvider, { children: jsx(TileAssetSortingProvider, { children: jsx(ManagerApolloProvider, Object.assign({ isIrisApp: true }, { children: children })) }) }) }) }) }) }) }));
298
330
 
299
331
  const HostNavigator = ({ children }) => {
300
332
  useURLSynchronization();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "0.4.135",
3
+ "version": "0.4.138",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
@@ -9,11 +9,11 @@
9
9
  "@js-temporal/polyfill": "0.4.3",
10
10
  "@sentry/browser": "7.50.0",
11
11
  "@trackunit/i18n-library-translation": "0.0.46",
12
- "@trackunit/iris-app-runtime-core": "0.3.38",
13
- "@trackunit/react-components": "0.1.87",
14
- "@trackunit/react-core-contexts-api": "0.2.29",
15
- "@trackunit/react-core-contexts-test": "0.1.56",
16
- "@trackunit/react-core-hooks": "0.2.51",
12
+ "@trackunit/iris-app-runtime-core": "0.3.39",
13
+ "@trackunit/react-components": "0.1.89",
14
+ "@trackunit/react-core-contexts-api": "0.2.30",
15
+ "@trackunit/react-core-contexts-test": "0.1.57",
16
+ "@trackunit/react-core-hooks": "0.2.52",
17
17
  "apollo-upload-client": "17.0.0",
18
18
  "react": "18.2.0",
19
19
  "react-router-dom": "6.4.5"
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from "react";
2
+ interface Props {
3
+ children: ReactNode;
4
+ allowAnalytics?: boolean;
5
+ }
6
+ /**
7
+ * This is a provider for the AnalyticsProvider.
8
+ */
9
+ declare const AnalyticsProvider: ({ children }: Props) => JSX.Element;
10
+ export default AnalyticsProvider;