@trackunit/react-core-contexts 1.30.5-alpha-d37885bfce4.0 → 1.30.6
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 +17 -94
- package/index.esm.js +20 -97
- package/package.json +8 -8
- package/src/errorLink/errorLink.d.ts +2 -2
- package/src/createApolloClient.d.ts +0 -19
- package/src/errorLink/subscriptionErrorLink.d.ts +0 -11
package/index.cjs.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var client = require('@apollo/client');
|
|
5
|
-
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
6
|
-
var react = require('react');
|
|
7
5
|
var context = require('@apollo/client/link/context');
|
|
8
6
|
var removeTypename = require('@apollo/client/link/remove-typename');
|
|
9
7
|
var utilities = require('@apollo/client/utilities');
|
|
8
|
+
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
10
9
|
var graphql = require('graphql');
|
|
11
10
|
var graphqlSse = require('graphql-sse');
|
|
11
|
+
var react = require('react');
|
|
12
12
|
var error = require('@apollo/client/link/error');
|
|
13
13
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
14
14
|
var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
@@ -19,7 +19,7 @@ var irisAppRuntimeCoreApi = require('@trackunit/iris-app-runtime-core-api');
|
|
|
19
19
|
/**
|
|
20
20
|
* This error link is used to capture error information, i. e. traceId, graphQL errors, network errors, etc.
|
|
21
21
|
*/
|
|
22
|
-
const createErrorLink = ({ errorHandler,
|
|
22
|
+
const createErrorLink = ({ errorHandler, token, }) => {
|
|
23
23
|
return error.onError(({ graphQLErrors, networkError, operation, forward }) => {
|
|
24
24
|
if (networkError) {
|
|
25
25
|
// We skip the error logging if the error is an AbortError
|
|
@@ -67,7 +67,7 @@ const createErrorLink = ({ errorHandler, getToken, }) => {
|
|
|
67
67
|
x.message.includes("Invalid token specified") ||
|
|
68
68
|
x.message.includes("Access denied! You need to be authorized to perform this action!"));
|
|
69
69
|
});
|
|
70
|
-
if (invalidToken &&
|
|
70
|
+
if (invalidToken && token) {
|
|
71
71
|
errorHandler.captureException(new Error(JSON.stringify({
|
|
72
72
|
category: "GraphQL",
|
|
73
73
|
info: "GraphQL Error - invalidToken",
|
|
@@ -103,69 +103,6 @@ const createErrorLink = ({ errorHandler, getToken, }) => {
|
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
/**
|
|
107
|
-
* Wraps an SSE subscription link and provides the same error monitoring as the
|
|
108
|
-
* HTTP error link — capturing GraphQL errors, traceIds, FORCE_RELOAD_BROWSER,
|
|
109
|
-
* and UNAUTHENTICATED codes — for long-lived subscription Observables.
|
|
110
|
-
*/
|
|
111
|
-
const createSubscriptionErrorLink = ({ errorHandler, getToken, }) => {
|
|
112
|
-
return new client.ApolloLink((operation, forward) => {
|
|
113
|
-
return new client.Observable(observer => {
|
|
114
|
-
const subscription = forward(operation).subscribe({
|
|
115
|
-
next: response => {
|
|
116
|
-
const { errors } = response;
|
|
117
|
-
if (errors) {
|
|
118
|
-
const code = errors[0]?.extensions?.code;
|
|
119
|
-
if (code === "FORCE_RELOAD_BROWSER") {
|
|
120
|
-
window.location.reload();
|
|
121
|
-
}
|
|
122
|
-
const traceIds = [];
|
|
123
|
-
errors.forEach(error => {
|
|
124
|
-
if ("extensions" in error && error.extensions && typeof error.extensions.traceId === "string") {
|
|
125
|
-
traceIds.push(error.extensions.traceId);
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
if (traceIds.length) {
|
|
129
|
-
errorHandler.setTag("traceIds", traceIds.join(", "));
|
|
130
|
-
}
|
|
131
|
-
errorHandler.addBreadcrumb({
|
|
132
|
-
category: "GraphQL",
|
|
133
|
-
message: "GraphQL Subscription Error",
|
|
134
|
-
level: "error",
|
|
135
|
-
data: { log: JSON.stringify(errors) },
|
|
136
|
-
});
|
|
137
|
-
const invalidToken = errors.some(x => x.extensions?.code === "UNAUTHENTICATED" ||
|
|
138
|
-
x.message.includes("Invalid token specified") ||
|
|
139
|
-
x.message.includes("Access denied! You need to be authorized to perform this action!"));
|
|
140
|
-
if (invalidToken && getToken()) {
|
|
141
|
-
errorHandler.captureException(new Error(JSON.stringify({
|
|
142
|
-
category: "GraphQL",
|
|
143
|
-
info: "GraphQL Subscription Error - invalidToken",
|
|
144
|
-
level: "warning",
|
|
145
|
-
data: { log: JSON.stringify(errors) },
|
|
146
|
-
})), { level: "warning", fingerprint: ["GraphQL Subscription Error - invalidToken"] });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
observer.next(response);
|
|
150
|
-
},
|
|
151
|
-
error: err => {
|
|
152
|
-
// eslint-disable-next-line no-console
|
|
153
|
-
console.error(err);
|
|
154
|
-
errorHandler.addBreadcrumb({
|
|
155
|
-
category: "GraphQL",
|
|
156
|
-
message: "GraphQL Subscription Network Error",
|
|
157
|
-
level: "error",
|
|
158
|
-
data: { log: String(err) },
|
|
159
|
-
});
|
|
160
|
-
observer.error(err);
|
|
161
|
-
},
|
|
162
|
-
complete: () => observer.complete(),
|
|
163
|
-
});
|
|
164
|
-
return () => subscription.unsubscribe();
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
|
|
169
106
|
// Use a widened `string` key so TypeScript picks the `unknown` overload of
|
|
170
107
|
// `Reflect.get` instead of the typed one — otherwise reads like `module`
|
|
171
108
|
// resolve to `NodeModule` from @types/node.
|
|
@@ -233,12 +170,11 @@ const isInternalGqlContext = () => {
|
|
|
233
170
|
return Reflect.get(globalThis, "gql") === "internal";
|
|
234
171
|
};
|
|
235
172
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
let tracingHeaders = initialTracingHeaders;
|
|
173
|
+
const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, errorHandler, }) => {
|
|
174
|
+
let token;
|
|
175
|
+
if (!token) {
|
|
176
|
+
token = firstToken;
|
|
177
|
+
}
|
|
242
178
|
const publicGraphQLLink = client.createHttpLink({
|
|
243
179
|
uri: request => graphqlPublicUrl + "/" + request.operationName,
|
|
244
180
|
});
|
|
@@ -248,7 +184,7 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
248
184
|
const reportGraphQLLink = client.createHttpLink({
|
|
249
185
|
uri: request => graphqlReportUrl + "/" + request.operationName,
|
|
250
186
|
});
|
|
251
|
-
const authLink = context.setContext((_, { headers: existingHeaders }) => {
|
|
187
|
+
const authLink = context.setContext(async (_, { headers: existingHeaders }) => {
|
|
252
188
|
return {
|
|
253
189
|
headers: {
|
|
254
190
|
...existingHeaders,
|
|
@@ -256,7 +192,7 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
256
192
|
},
|
|
257
193
|
};
|
|
258
194
|
});
|
|
259
|
-
const errorLink = createErrorLink({ errorHandler,
|
|
195
|
+
const errorLink = createErrorLink({ errorHandler, token });
|
|
260
196
|
const defaultOptions = {
|
|
261
197
|
watchQuery: {
|
|
262
198
|
fetchPolicy: "no-cache",
|
|
@@ -273,12 +209,10 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
273
209
|
};
|
|
274
210
|
const removeTypenameLink = removeTypename.removeTypenameFromVariables();
|
|
275
211
|
class SSELink extends client.ApolloLink {
|
|
276
|
-
/** @inheritdoc */
|
|
277
212
|
constructor(options) {
|
|
278
213
|
super();
|
|
279
214
|
this.client = graphqlSse.createClient(options);
|
|
280
215
|
}
|
|
281
|
-
/** @inheritdoc */
|
|
282
216
|
request(operation) {
|
|
283
217
|
return new utilities.Observable(sink => {
|
|
284
218
|
return this.client.subscribe({ ...operation, query: graphql.print(operation.query) }, {
|
|
@@ -294,13 +228,12 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
294
228
|
headers: () => generateHeaders(token, tracingHeaders),
|
|
295
229
|
});
|
|
296
230
|
// Split links based on operation type
|
|
297
|
-
const subscriptionErrorLink = createSubscriptionErrorLink({ errorHandler, getToken: () => token });
|
|
298
231
|
const splitLink = client.from([
|
|
299
232
|
authLink,
|
|
300
233
|
client.split(({ query }) => {
|
|
301
234
|
const definition = utilities.getMainDefinition(query);
|
|
302
235
|
return definition.kind === "OperationDefinition" && definition.operation === "subscription";
|
|
303
|
-
},
|
|
236
|
+
}, sseLink, client.from([
|
|
304
237
|
errorLink,
|
|
305
238
|
removeTypenameLink,
|
|
306
239
|
client.split(operation => operation.getContext().clientName === "report", reportGraphQLLink, client.split(() => isInternalGqlContext(), internalGraphQLLink, publicGraphQLLink)),
|
|
@@ -328,12 +261,8 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
328
261
|
getToken: () => {
|
|
329
262
|
return token;
|
|
330
263
|
},
|
|
331
|
-
setTracingHeaders: (newHeaders) => {
|
|
332
|
-
tracingHeaders = newHeaders;
|
|
333
|
-
},
|
|
334
264
|
};
|
|
335
265
|
};
|
|
336
|
-
|
|
337
266
|
const useApolloClient = () => {
|
|
338
267
|
const { graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, environment, tracingHeaders } = reactCoreHooks.useEnvironment();
|
|
339
268
|
const { token: currentToken } = reactCoreHooks.useToken();
|
|
@@ -352,17 +281,11 @@ const useApolloClient = () => {
|
|
|
352
281
|
errorHandler,
|
|
353
282
|
});
|
|
354
283
|
});
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
if (client.getToken() !== currentToken) {
|
|
361
|
-
client.setToken(currentToken);
|
|
362
|
-
}
|
|
363
|
-
react.useEffect(() => {
|
|
364
|
-
client.setTracingHeaders(tracingHeaders);
|
|
365
|
-
}, [client, tracingHeaders]);
|
|
284
|
+
react.useMemo(() => {
|
|
285
|
+
if (client.getToken() !== currentToken) {
|
|
286
|
+
client.setToken(currentToken);
|
|
287
|
+
}
|
|
288
|
+
}, [client, currentToken]);
|
|
366
289
|
return client;
|
|
367
290
|
};
|
|
368
291
|
/**
|
package/index.esm.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
3
|
-
import { useEnvironment, useToken, useErrorHandler } from '@trackunit/react-core-hooks';
|
|
4
|
-
import { useState, useEffect, useMemo, useCallback, useReducer, Suspense } from 'react';
|
|
2
|
+
import { ApolloProvider, createHttpLink, from, split, ApolloClient, InMemoryCache, ApolloLink } from '@apollo/client';
|
|
5
3
|
import { setContext } from '@apollo/client/link/context';
|
|
6
4
|
import { removeTypenameFromVariables } from '@apollo/client/link/remove-typename';
|
|
7
|
-
import { getMainDefinition, Observable
|
|
5
|
+
import { getMainDefinition, Observable } from '@apollo/client/utilities';
|
|
6
|
+
import { useEnvironment, useToken, useErrorHandler } from '@trackunit/react-core-hooks';
|
|
8
7
|
import { print } from 'graphql';
|
|
9
8
|
import { createClient } from 'graphql-sse';
|
|
9
|
+
import { useState, useMemo, useEffect, useCallback, useReducer, Suspense } from 'react';
|
|
10
10
|
import { onError } from '@apollo/client/link/error';
|
|
11
11
|
import { ToastRuntime, AnalyticsRuntime, registerHostChangeHandler, AssetSortingRuntime, ConfirmationDialogRuntime, EnvironmentRuntime, ExportDataRuntime, AssetsFilterBarRuntime, CustomersFilterBarRuntime, SitesFilterBarRuntime, GeolocationRuntime, ModalDialogRuntime, NavigationRuntime, OemBrandingRuntime, ThemeCssRuntime, TimeRangeRuntime, TokenRuntime, CurrentUserRuntime, CurrentUserPreferenceRuntime, UserSubscriptionRuntime, WidgetConfigRuntime } from '@trackunit/iris-app-runtime-core';
|
|
12
12
|
import { ToastProvider, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, ExportDataContext, FilterBarProvider, GeolocationProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider, WidgetConfigProvider } from '@trackunit/react-core-contexts-api';
|
|
@@ -17,7 +17,7 @@ import { Channels, SortOrder, AssetSortByProperty } from '@trackunit/iris-app-ru
|
|
|
17
17
|
/**
|
|
18
18
|
* This error link is used to capture error information, i. e. traceId, graphQL errors, network errors, etc.
|
|
19
19
|
*/
|
|
20
|
-
const createErrorLink = ({ errorHandler,
|
|
20
|
+
const createErrorLink = ({ errorHandler, token, }) => {
|
|
21
21
|
return onError(({ graphQLErrors, networkError, operation, forward }) => {
|
|
22
22
|
if (networkError) {
|
|
23
23
|
// We skip the error logging if the error is an AbortError
|
|
@@ -65,7 +65,7 @@ const createErrorLink = ({ errorHandler, getToken, }) => {
|
|
|
65
65
|
x.message.includes("Invalid token specified") ||
|
|
66
66
|
x.message.includes("Access denied! You need to be authorized to perform this action!"));
|
|
67
67
|
});
|
|
68
|
-
if (invalidToken &&
|
|
68
|
+
if (invalidToken && token) {
|
|
69
69
|
errorHandler.captureException(new Error(JSON.stringify({
|
|
70
70
|
category: "GraphQL",
|
|
71
71
|
info: "GraphQL Error - invalidToken",
|
|
@@ -101,69 +101,6 @@ const createErrorLink = ({ errorHandler, getToken, }) => {
|
|
|
101
101
|
});
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Wraps an SSE subscription link and provides the same error monitoring as the
|
|
106
|
-
* HTTP error link — capturing GraphQL errors, traceIds, FORCE_RELOAD_BROWSER,
|
|
107
|
-
* and UNAUTHENTICATED codes — for long-lived subscription Observables.
|
|
108
|
-
*/
|
|
109
|
-
const createSubscriptionErrorLink = ({ errorHandler, getToken, }) => {
|
|
110
|
-
return new ApolloLink((operation, forward) => {
|
|
111
|
-
return new Observable(observer => {
|
|
112
|
-
const subscription = forward(operation).subscribe({
|
|
113
|
-
next: response => {
|
|
114
|
-
const { errors } = response;
|
|
115
|
-
if (errors) {
|
|
116
|
-
const code = errors[0]?.extensions?.code;
|
|
117
|
-
if (code === "FORCE_RELOAD_BROWSER") {
|
|
118
|
-
window.location.reload();
|
|
119
|
-
}
|
|
120
|
-
const traceIds = [];
|
|
121
|
-
errors.forEach(error => {
|
|
122
|
-
if ("extensions" in error && error.extensions && typeof error.extensions.traceId === "string") {
|
|
123
|
-
traceIds.push(error.extensions.traceId);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
if (traceIds.length) {
|
|
127
|
-
errorHandler.setTag("traceIds", traceIds.join(", "));
|
|
128
|
-
}
|
|
129
|
-
errorHandler.addBreadcrumb({
|
|
130
|
-
category: "GraphQL",
|
|
131
|
-
message: "GraphQL Subscription Error",
|
|
132
|
-
level: "error",
|
|
133
|
-
data: { log: JSON.stringify(errors) },
|
|
134
|
-
});
|
|
135
|
-
const invalidToken = errors.some(x => x.extensions?.code === "UNAUTHENTICATED" ||
|
|
136
|
-
x.message.includes("Invalid token specified") ||
|
|
137
|
-
x.message.includes("Access denied! You need to be authorized to perform this action!"));
|
|
138
|
-
if (invalidToken && getToken()) {
|
|
139
|
-
errorHandler.captureException(new Error(JSON.stringify({
|
|
140
|
-
category: "GraphQL",
|
|
141
|
-
info: "GraphQL Subscription Error - invalidToken",
|
|
142
|
-
level: "warning",
|
|
143
|
-
data: { log: JSON.stringify(errors) },
|
|
144
|
-
})), { level: "warning", fingerprint: ["GraphQL Subscription Error - invalidToken"] });
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
observer.next(response);
|
|
148
|
-
},
|
|
149
|
-
error: err => {
|
|
150
|
-
// eslint-disable-next-line no-console
|
|
151
|
-
console.error(err);
|
|
152
|
-
errorHandler.addBreadcrumb({
|
|
153
|
-
category: "GraphQL",
|
|
154
|
-
message: "GraphQL Subscription Network Error",
|
|
155
|
-
level: "error",
|
|
156
|
-
data: { log: String(err) },
|
|
157
|
-
});
|
|
158
|
-
observer.error(err);
|
|
159
|
-
},
|
|
160
|
-
complete: () => observer.complete(),
|
|
161
|
-
});
|
|
162
|
-
return () => subscription.unsubscribe();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
|
|
167
104
|
// Use a widened `string` key so TypeScript picks the `unknown` overload of
|
|
168
105
|
// `Reflect.get` instead of the typed one — otherwise reads like `module`
|
|
169
106
|
// resolve to `NodeModule` from @types/node.
|
|
@@ -231,12 +168,11 @@ const isInternalGqlContext = () => {
|
|
|
231
168
|
return Reflect.get(globalThis, "gql") === "internal";
|
|
232
169
|
};
|
|
233
170
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
let tracingHeaders = initialTracingHeaders;
|
|
171
|
+
const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, errorHandler, }) => {
|
|
172
|
+
let token;
|
|
173
|
+
if (!token) {
|
|
174
|
+
token = firstToken;
|
|
175
|
+
}
|
|
240
176
|
const publicGraphQLLink = createHttpLink({
|
|
241
177
|
uri: request => graphqlPublicUrl + "/" + request.operationName,
|
|
242
178
|
});
|
|
@@ -246,7 +182,7 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
246
182
|
const reportGraphQLLink = createHttpLink({
|
|
247
183
|
uri: request => graphqlReportUrl + "/" + request.operationName,
|
|
248
184
|
});
|
|
249
|
-
const authLink = setContext((_, { headers: existingHeaders }) => {
|
|
185
|
+
const authLink = setContext(async (_, { headers: existingHeaders }) => {
|
|
250
186
|
return {
|
|
251
187
|
headers: {
|
|
252
188
|
...existingHeaders,
|
|
@@ -254,7 +190,7 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
254
190
|
},
|
|
255
191
|
};
|
|
256
192
|
});
|
|
257
|
-
const errorLink = createErrorLink({ errorHandler,
|
|
193
|
+
const errorLink = createErrorLink({ errorHandler, token });
|
|
258
194
|
const defaultOptions = {
|
|
259
195
|
watchQuery: {
|
|
260
196
|
fetchPolicy: "no-cache",
|
|
@@ -271,14 +207,12 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
271
207
|
};
|
|
272
208
|
const removeTypenameLink = removeTypenameFromVariables();
|
|
273
209
|
class SSELink extends ApolloLink {
|
|
274
|
-
/** @inheritdoc */
|
|
275
210
|
constructor(options) {
|
|
276
211
|
super();
|
|
277
212
|
this.client = createClient(options);
|
|
278
213
|
}
|
|
279
|
-
/** @inheritdoc */
|
|
280
214
|
request(operation) {
|
|
281
|
-
return new Observable
|
|
215
|
+
return new Observable(sink => {
|
|
282
216
|
return this.client.subscribe({ ...operation, query: print(operation.query) }, {
|
|
283
217
|
next: value => sink.next(value),
|
|
284
218
|
complete: sink.complete.bind(sink),
|
|
@@ -292,13 +226,12 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
292
226
|
headers: () => generateHeaders(token, tracingHeaders),
|
|
293
227
|
});
|
|
294
228
|
// Split links based on operation type
|
|
295
|
-
const subscriptionErrorLink = createSubscriptionErrorLink({ errorHandler, getToken: () => token });
|
|
296
229
|
const splitLink = from([
|
|
297
230
|
authLink,
|
|
298
231
|
split(({ query }) => {
|
|
299
232
|
const definition = getMainDefinition(query);
|
|
300
233
|
return definition.kind === "OperationDefinition" && definition.operation === "subscription";
|
|
301
|
-
},
|
|
234
|
+
}, sseLink, from([
|
|
302
235
|
errorLink,
|
|
303
236
|
removeTypenameLink,
|
|
304
237
|
split(operation => operation.getContext().clientName === "report", reportGraphQLLink, split(() => isInternalGqlContext(), internalGraphQLLink, publicGraphQLLink)),
|
|
@@ -326,12 +259,8 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
|
|
|
326
259
|
getToken: () => {
|
|
327
260
|
return token;
|
|
328
261
|
},
|
|
329
|
-
setTracingHeaders: (newHeaders) => {
|
|
330
|
-
tracingHeaders = newHeaders;
|
|
331
|
-
},
|
|
332
262
|
};
|
|
333
263
|
};
|
|
334
|
-
|
|
335
264
|
const useApolloClient = () => {
|
|
336
265
|
const { graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, environment, tracingHeaders } = useEnvironment();
|
|
337
266
|
const { token: currentToken } = useToken();
|
|
@@ -350,17 +279,11 @@ const useApolloClient = () => {
|
|
|
350
279
|
errorHandler,
|
|
351
280
|
});
|
|
352
281
|
});
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
if (client.getToken() !== currentToken) {
|
|
359
|
-
client.setToken(currentToken);
|
|
360
|
-
}
|
|
361
|
-
useEffect(() => {
|
|
362
|
-
client.setTracingHeaders(tracingHeaders);
|
|
363
|
-
}, [client, tracingHeaders]);
|
|
282
|
+
useMemo(() => {
|
|
283
|
+
if (client.getToken() !== currentToken) {
|
|
284
|
+
client.setToken(currentToken);
|
|
285
|
+
}
|
|
286
|
+
}, [client, currentToken]);
|
|
364
287
|
return client;
|
|
365
288
|
};
|
|
366
289
|
/**
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-contexts",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.6",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/iris-app-api": "1.20.
|
|
11
|
-
"@trackunit/iris-app-runtime-core-api": "1.16.
|
|
12
|
-
"@trackunit/react-core-hooks": "1.17.
|
|
13
|
-
"@trackunit/i18n-library-translation": "1.22.
|
|
14
|
-
"@trackunit/react-components": "1.26.
|
|
15
|
-
"@trackunit/iris-app-runtime-core": "1.17.
|
|
10
|
+
"@trackunit/iris-app-api": "1.20.8",
|
|
11
|
+
"@trackunit/iris-app-runtime-core-api": "1.16.7",
|
|
12
|
+
"@trackunit/react-core-hooks": "1.17.11",
|
|
13
|
+
"@trackunit/i18n-library-translation": "1.22.2",
|
|
14
|
+
"@trackunit/react-components": "1.26.6",
|
|
15
|
+
"@trackunit/iris-app-runtime-core": "1.17.7",
|
|
16
16
|
"graphql-sse": "^2.5.4",
|
|
17
|
-
"@trackunit/react-core-contexts-api": "1.17.
|
|
17
|
+
"@trackunit/react-core-contexts-api": "1.17.7"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@apollo/client": "^3.13.8",
|
|
@@ -3,7 +3,7 @@ import { ErrorHandlingContextValue } from "@trackunit/iris-app-runtime-core-api"
|
|
|
3
3
|
/**
|
|
4
4
|
* This error link is used to capture error information, i. e. traceId, graphQL errors, network errors, etc.
|
|
5
5
|
*/
|
|
6
|
-
export declare const createErrorLink: ({ errorHandler,
|
|
6
|
+
export declare const createErrorLink: ({ errorHandler, token, }: {
|
|
7
7
|
errorHandler: ErrorHandlingContextValue;
|
|
8
|
-
|
|
8
|
+
token: string | undefined;
|
|
9
9
|
}) => ApolloLink;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ApolloClient } from "@apollo/client";
|
|
2
|
-
import { ErrorHandlingContextValue, TracingHeaders } from "@trackunit/iris-app-runtime-core-api";
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export declare const createApolloClient: ({ graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders: initialTracingHeaders, firstToken, errorHandler, }: {
|
|
7
|
-
graphqlPublicUrl: string;
|
|
8
|
-
graphqlInternalUrl: string;
|
|
9
|
-
graphqlReportUrl: string;
|
|
10
|
-
tracingHeaders: TracingHeaders;
|
|
11
|
-
isDev: boolean;
|
|
12
|
-
firstToken?: string;
|
|
13
|
-
errorHandler: ErrorHandlingContextValue;
|
|
14
|
-
}) => {
|
|
15
|
-
client: ApolloClient<import("@apollo/client").NormalizedCacheObject>;
|
|
16
|
-
setToken: (newToken: string | undefined) => void;
|
|
17
|
-
getToken: () => string | undefined;
|
|
18
|
-
setTracingHeaders: (newHeaders: TracingHeaders) => void;
|
|
19
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ApolloLink } from "@apollo/client";
|
|
2
|
-
import { ErrorHandlingContextValue } from "@trackunit/iris-app-runtime-core-api";
|
|
3
|
-
/**
|
|
4
|
-
* Wraps an SSE subscription link and provides the same error monitoring as the
|
|
5
|
-
* HTTP error link — capturing GraphQL errors, traceIds, FORCE_RELOAD_BROWSER,
|
|
6
|
-
* and UNAUTHENTICATED codes — for long-lived subscription Observables.
|
|
7
|
-
*/
|
|
8
|
-
export declare const createSubscriptionErrorLink: ({ errorHandler, getToken, }: {
|
|
9
|
-
errorHandler: ErrorHandlingContextValue;
|
|
10
|
-
getToken: () => string | undefined;
|
|
11
|
-
}) => ApolloLink;
|