@trackunit/react-core-contexts 0.4.164 → 0.4.166

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 (3) hide show
  1. package/index.cjs +20 -13
  2. package/index.js +17 -13
  3. package/package.json +2 -1
package/index.cjs CHANGED
@@ -8,6 +8,7 @@ var context = require('@apollo/client/link/context');
8
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
+ var amplitude = require('amplitude-js');
11
12
  var apolloUploadClient = require('apollo-upload-client');
12
13
  var React = require('react');
13
14
  var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
@@ -16,6 +17,8 @@ var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
16
17
  var reactComponents = require('@trackunit/react-components');
17
18
  var reactRouterDom = require('react-router-dom');
18
19
 
20
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
21
+
19
22
  function _interopNamespace(e) {
20
23
  if (e && e.__esModule) return e;
21
24
  var n = Object.create(null);
@@ -35,6 +38,7 @@ function _interopNamespace(e) {
35
38
  }
36
39
 
37
40
  var Sentry__namespace = /*#__PURE__*/_interopNamespace(Sentry);
41
+ var amplitude__default = /*#__PURE__*/_interopDefaultLegacy(amplitude);
38
42
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
39
43
 
40
44
  /******************************************************************************
@@ -119,14 +123,16 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
119
123
  ((_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!")));
120
124
  });
121
125
  if (invalidToken) {
122
- Sentry__namespace.captureException({
123
- category: "GraphQL",
124
- message: "GraphQL Error - invalidToken",
125
- level: "warning",
126
- data: {
127
- log: JSON.stringify(errorResponse.graphQLErrors),
128
- },
129
- });
126
+ amplitude__default["default"].getInstance().logEvent("ManagerApolloProviderError", errorResponse.graphQLErrors);
127
+ //Temp fix for Sentry overload
128
+ // Sentry.captureException({
129
+ // category: "GraphQL",
130
+ // message: "GraphQL Error - invalidToken",
131
+ // level: "warning",
132
+ // data: {
133
+ // log: JSON.stringify(errorResponse.graphQLErrors),
134
+ // },
135
+ // });
130
136
  }
131
137
  }
132
138
  if (errorResponse.networkError) {
@@ -167,17 +173,18 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
167
173
  const useApolloClient = (isIrisApp) => {
168
174
  var _a;
169
175
  const { graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders } = reactCoreHooks.useEnvironment();
170
- const { tasUserId } = reactCoreHooks.useCurrentUser();
176
+ const { isAssuming } = reactCoreHooks.useCurrentUser();
171
177
  const { token } = reactCoreHooks.useToken();
172
- const tasUserIdRef = React__namespace.useRef();
178
+ const isAssumingRef = React__namespace.useRef();
173
179
  const clientRef = React__namespace.useRef(null);
174
- if (!tasUserIdRef.current) {
175
- tasUserIdRef.current = tasUserId;
180
+ if (isAssumingRef.current === null) {
181
+ isAssumingRef.current = isAssuming;
176
182
  }
177
183
  /* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
178
184
  the token will then be set on the instance without react reporting a new client
179
185
  and recreating if token change from null to something*/
180
- if (!clientRef.current || !clientRef.current.getToken() || tasUserIdRef.current !== tasUserId) {
186
+ if (!clientRef.current || !clientRef.current.getToken() || isAssumingRef.current !== isAssuming) {
187
+ isAssumingRef.current = !isAssumingRef.current;
181
188
  clientRef.current = createApolloClient({
182
189
  graphqlManagerUrl,
183
190
  graphqlPublicUrl,
package/index.js CHANGED
@@ -4,6 +4,7 @@ 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
6
  import { useEnvironment, useCurrentUser, useToken, ToastProvider, AnalyticsContextProvider, AssetSortingProvider, EnvironmentContextProvider, GlobalSelectionProvider, OemBrandingContextProvider as OemBrandingContextProvider$1, TokenProvider, CurrentUserProvider, UserSubscriptionProvider as UserSubscriptionProvider$1, useURLSynchronization } from '@trackunit/react-core-hooks';
7
+ import amplitude from 'amplitude-js';
7
8
  import { createUploadLink } from 'apollo-upload-client';
8
9
  import * as React from 'react';
9
10
  import { useMemo, useEffect, useState } from 'react';
@@ -95,14 +96,16 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
95
96
  ((_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!")));
96
97
  });
97
98
  if (invalidToken) {
98
- Sentry.captureException({
99
- category: "GraphQL",
100
- message: "GraphQL Error - invalidToken",
101
- level: "warning",
102
- data: {
103
- log: JSON.stringify(errorResponse.graphQLErrors),
104
- },
105
- });
99
+ amplitude.getInstance().logEvent("ManagerApolloProviderError", errorResponse.graphQLErrors);
100
+ //Temp fix for Sentry overload
101
+ // Sentry.captureException({
102
+ // category: "GraphQL",
103
+ // message: "GraphQL Error - invalidToken",
104
+ // level: "warning",
105
+ // data: {
106
+ // log: JSON.stringify(errorResponse.graphQLErrors),
107
+ // },
108
+ // });
106
109
  }
107
110
  }
108
111
  if (errorResponse.networkError) {
@@ -143,17 +146,18 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlManage
143
146
  const useApolloClient = (isIrisApp) => {
144
147
  var _a;
145
148
  const { graphqlManagerUrl, graphqlPublicUrl, graphqlManagerImageUploadUrl, graphqlReportUrl, isDev, tracingHeaders } = useEnvironment();
146
- const { tasUserId } = useCurrentUser();
149
+ const { isAssuming } = useCurrentUser();
147
150
  const { token } = useToken();
148
- const tasUserIdRef = React.useRef();
151
+ const isAssumingRef = React.useRef();
149
152
  const clientRef = React.useRef(null);
150
- if (!tasUserIdRef.current) {
151
- tasUserIdRef.current = tasUserId;
153
+ if (isAssumingRef.current === null) {
154
+ isAssumingRef.current = isAssuming;
152
155
  }
153
156
  /* DONT CHANGE THIS ! its there to ensure we dont recreate apollo client just because the token changes,
154
157
  the token will then be set on the instance without react reporting a new client
155
158
  and recreating if token change from null to something*/
156
- if (!clientRef.current || !clientRef.current.getToken() || tasUserIdRef.current !== tasUserId) {
159
+ if (!clientRef.current || !clientRef.current.getToken() || isAssumingRef.current !== isAssuming) {
160
+ isAssumingRef.current = !isAssumingRef.current;
157
161
  clientRef.current = createApolloClient({
158
162
  graphqlManagerUrl,
159
163
  graphqlPublicUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "0.4.164",
3
+ "version": "0.4.166",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
@@ -14,6 +14,7 @@
14
14
  "@trackunit/react-core-contexts-api": "0.2.37",
15
15
  "@trackunit/react-core-contexts-test": "0.1.69",
16
16
  "@trackunit/react-core-hooks": "0.2.60",
17
+ "amplitude-js": "7.4.4",
17
18
  "apollo-upload-client": "17.0.0",
18
19
  "react": "18.2.0",
19
20
  "react-router-dom": "6.4.5"