@trackunit/react-core-contexts 1.3.102 → 1.3.106

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
@@ -5,7 +5,10 @@ var client = require('@apollo/client');
5
5
  var context = require('@apollo/client/link/context');
6
6
  var error = require('@apollo/client/link/error');
7
7
  var removeTypename = require('@apollo/client/link/remove-typename');
8
+ var utilities = require('@apollo/client/utilities');
8
9
  var reactCoreHooks = require('@trackunit/react-core-hooks');
10
+ var graphql = require('graphql');
11
+ var graphqlSse = require('graphql-sse');
9
12
  var React = require('react');
10
13
  require('@js-temporal/polyfill');
11
14
  var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
@@ -152,11 +155,46 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlIntern
152
155
  },
153
156
  };
154
157
  const removeTypenameLink = removeTypename.removeTypenameFromVariables();
158
+ class SSELink extends client.ApolloLink {
159
+ constructor(options) {
160
+ super();
161
+ this.client = graphqlSse.createClient(options);
162
+ }
163
+ request(operation) {
164
+ return new utilities.Observable(sink => {
165
+ return this.client.subscribe({ ...operation, query: graphql.print(operation.query) }, {
166
+ next: sink.next.bind(sink),
167
+ complete: sink.complete.bind(sink),
168
+ error: sink.error.bind(sink),
169
+ });
170
+ });
171
+ }
172
+ }
173
+ const sseLink = new SSELink({
174
+ url: `${graphqlInternalUrl}/stream`,
175
+ headers: () => {
176
+ return {
177
+ Authorization: `Bearer ${token}`,
178
+ };
179
+ },
180
+ });
181
+ // Split links based on operation type
182
+ const splitLink = client.from([
183
+ authLink,
184
+ client.split(({ query }) => {
185
+ const definition = utilities.getMainDefinition(query);
186
+ return definition.kind === "OperationDefinition" && definition.operation === "subscription";
187
+ }, sseLink, client.from([
188
+ errorLink,
189
+ removeTypenameLink,
190
+ client.split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, client.split(operation => operation.getContext().clientName === "report", reportGraphQLLink, client.split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
191
+ ])),
192
+ ]);
155
193
  return {
156
194
  client: new client.ApolloClient({
157
195
  name: "Manager",
158
196
  connectToDevTools: isDev,
159
- // LegacyServicePlan added by team SPIEX, now owned by team Luna, so Apollo Client doesn't merge service plans simply because they have the same id
197
+ // LegacyServicePlan added by team SPIEX so Apollo Client doesn't merge service plans simply because they have the same id
160
198
  // See more here: https://stackoverflow.com/questions/78189868/apollo-is-returning-data-wrong-but-is-correct-in-network-inspector
161
199
  cache: new client.InMemoryCache({
162
200
  typePolicies: {
@@ -166,12 +204,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlIntern
166
204
  },
167
205
  }),
168
206
  defaultOptions,
169
- link: client.from([
170
- errorLink,
171
- authLink,
172
- removeTypenameLink,
173
- client.split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, client.split(operation => operation.getContext().clientName === "report", reportGraphQLLink, client.split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
174
- ]),
207
+ link: splitLink,
175
208
  }),
176
209
  setToken: (newToken) => {
177
210
  token = newToken;
@@ -629,6 +662,13 @@ const UserSubscriptionProviderIrisApp = ({ children }) => {
629
662
  return jsxRuntime.jsx(reactCoreHooks.UserSubscriptionProvider, { value: subscription, children: children });
630
663
  };
631
664
 
665
+ /**
666
+ * This is a provider for the WidgetConfigContext.
667
+ */
668
+ const WidgetConfigProviderIrisApp = ({ children }) => {
669
+ return jsxRuntime.jsx(reactCoreHooks.WidgetConfigProvider, { value: irisAppRuntimeCore.WidgetConfigRuntime, children: children });
670
+ };
671
+
632
672
  /**
633
673
  * This is a provider for the TrackunitDataProviders.
634
674
  */
@@ -637,7 +677,7 @@ const TrackunitProviders = ({ translations, children, errorHandler }) => {
637
677
  i18nLibraryTranslation.registerTranslations(translations); // Register the apps translations if passed.
638
678
  }
639
679
  i18nLibraryTranslation.initializeTranslationsForApp(); // Initialize all registered translations
640
- 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(TimeRangeProviderIrisApp, { children: jsxRuntime.jsx(React.Suspense, { fallback: jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
680
+ 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(TimeRangeProviderIrisApp, { children: jsxRuntime.jsx(WidgetConfigProviderIrisApp, { children: jsxRuntime.jsx(React.Suspense, { fallback: jsxRuntime.jsx(reactComponents.Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
641
681
  };
642
682
 
643
683
  exports.ManagerApolloProvider = ManagerApolloProvider;
package/index.esm.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { jsx, Fragment } from 'react/jsx-runtime';
2
- import { ApolloProvider, createHttpLink, ApolloClient, InMemoryCache, from, split } from '@apollo/client';
2
+ import { ApolloProvider, createHttpLink, from, split, ApolloClient, InMemoryCache, ApolloLink } from '@apollo/client';
3
3
  import { setContext } from '@apollo/client/link/context';
4
4
  import { onError } from '@apollo/client/link/error';
5
5
  import { removeTypenameFromVariables } from '@apollo/client/link/remove-typename';
6
- import { useEnvironment, useToken, useErrorHandler, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, ToastProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider } from '@trackunit/react-core-hooks';
6
+ import { getMainDefinition, Observable } from '@apollo/client/utilities';
7
+ import { useEnvironment, useToken, useErrorHandler, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, FilterBarProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, ToastProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider, WidgetConfigProvider } from '@trackunit/react-core-hooks';
8
+ import { print } from 'graphql';
9
+ import { createClient } from 'graphql-sse';
7
10
  import * as React from 'react';
8
11
  import { useState, useMemo, useEffect, Suspense } from 'react';
9
12
  import '@js-temporal/polyfill';
10
13
  import { registerTranslations, initializeTranslationsForApp } from '@trackunit/i18n-library-translation';
11
14
  import { Spinner } from '@trackunit/react-components';
12
- import { AnalyticsContextRuntime, setupHostConnector, AssetSortingRuntime, ConfirmationDialogRuntime, EnvironmentRuntime, FilterBarRuntime, AssetsFilterBarRuntime, CustomersFilterBarRuntime, SitesFilterBarRuntime, ModalDialogRuntime, NavigationRuntime, OemBrandingContextRuntime, ThemeCssRuntime, TimeRangeRuntime, ToastRuntime, TokenRuntime, CurrentUserRuntime, CurrentUserPreferenceRuntime, UserSubscriptionRuntime } from '@trackunit/iris-app-runtime-core';
15
+ import { AnalyticsContextRuntime, setupHostConnector, AssetSortingRuntime, ConfirmationDialogRuntime, EnvironmentRuntime, FilterBarRuntime, AssetsFilterBarRuntime, CustomersFilterBarRuntime, SitesFilterBarRuntime, ModalDialogRuntime, NavigationRuntime, OemBrandingContextRuntime, ThemeCssRuntime, TimeRangeRuntime, ToastRuntime, TokenRuntime, CurrentUserRuntime, CurrentUserPreferenceRuntime, UserSubscriptionRuntime, WidgetConfigRuntime } from '@trackunit/iris-app-runtime-core';
13
16
 
14
17
  const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, isDev, tracingHeaders, firstToken, errorHandler, }) => {
15
18
  let token;
@@ -132,11 +135,46 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlIntern
132
135
  },
133
136
  };
134
137
  const removeTypenameLink = removeTypenameFromVariables();
138
+ class SSELink extends ApolloLink {
139
+ constructor(options) {
140
+ super();
141
+ this.client = createClient(options);
142
+ }
143
+ request(operation) {
144
+ return new Observable(sink => {
145
+ return this.client.subscribe({ ...operation, query: print(operation.query) }, {
146
+ next: sink.next.bind(sink),
147
+ complete: sink.complete.bind(sink),
148
+ error: sink.error.bind(sink),
149
+ });
150
+ });
151
+ }
152
+ }
153
+ const sseLink = new SSELink({
154
+ url: `${graphqlInternalUrl}/stream`,
155
+ headers: () => {
156
+ return {
157
+ Authorization: `Bearer ${token}`,
158
+ };
159
+ },
160
+ });
161
+ // Split links based on operation type
162
+ const splitLink = from([
163
+ authLink,
164
+ split(({ query }) => {
165
+ const definition = getMainDefinition(query);
166
+ return definition.kind === "OperationDefinition" && definition.operation === "subscription";
167
+ }, sseLink, from([
168
+ errorLink,
169
+ removeTypenameLink,
170
+ split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, split(operation => operation.getContext().clientName === "report", reportGraphQLLink, split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
171
+ ])),
172
+ ]);
135
173
  return {
136
174
  client: new ApolloClient({
137
175
  name: "Manager",
138
176
  connectToDevTools: isDev,
139
- // LegacyServicePlan added by team SPIEX, now owned by team Luna, so Apollo Client doesn't merge service plans simply because they have the same id
177
+ // LegacyServicePlan added by team SPIEX so Apollo Client doesn't merge service plans simply because they have the same id
140
178
  // See more here: https://stackoverflow.com/questions/78189868/apollo-is-returning-data-wrong-but-is-correct-in-network-inspector
141
179
  cache: new InMemoryCache({
142
180
  typePolicies: {
@@ -146,12 +184,7 @@ const createApolloClient = ({ graphqlManagerUrl, graphqlPublicUrl, graphqlIntern
146
184
  },
147
185
  }),
148
186
  defaultOptions,
149
- link: from([
150
- errorLink,
151
- authLink,
152
- removeTypenameLink,
153
- split(operation => operation.getContext().clientName === "manager", managerGraphQLLink, split(operation => operation.getContext().clientName === "report", reportGraphQLLink, split(() => global.gql === "internal", internalGraphQLLink, publicGraphQLLink))),
154
- ]),
187
+ link: splitLink,
155
188
  }),
156
189
  setToken: (newToken) => {
157
190
  token = newToken;
@@ -609,6 +642,13 @@ const UserSubscriptionProviderIrisApp = ({ children }) => {
609
642
  return jsx(UserSubscriptionProvider, { value: subscription, children: children });
610
643
  };
611
644
 
645
+ /**
646
+ * This is a provider for the WidgetConfigContext.
647
+ */
648
+ const WidgetConfigProviderIrisApp = ({ children }) => {
649
+ return jsx(WidgetConfigProvider, { value: WidgetConfigRuntime, children: children });
650
+ };
651
+
612
652
  /**
613
653
  * This is a provider for the TrackunitDataProviders.
614
654
  */
@@ -617,7 +657,7 @@ const TrackunitProviders = ({ translations, children, errorHandler }) => {
617
657
  registerTranslations(translations); // Register the apps translations if passed.
618
658
  }
619
659
  initializeTranslationsForApp(); // Initialize all registered translations
620
- 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(TimeRangeProviderIrisApp, { children: jsx(Suspense, { fallback: jsx(Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
660
+ 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(TimeRangeProviderIrisApp, { children: jsx(WidgetConfigProviderIrisApp, { children: jsx(Suspense, { fallback: jsx(Spinner, { centering: "centered", dataTestId: "trackunit-providers" }), children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
621
661
  };
622
662
 
623
663
  export { ManagerApolloProvider, ToastProviderIrisApp, TrackunitProviders };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "1.3.102",
3
+ "version": "1.3.106",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -11,12 +11,14 @@
11
11
  "react": "19.0.0",
12
12
  "@js-temporal/polyfill": "^0.4.4",
13
13
  "jest-fetch-mock": "^3.0.3",
14
- "@trackunit/iris-app-api": "1.3.79",
15
- "@trackunit/react-core-contexts-api": "1.4.78",
16
- "@trackunit/react-core-hooks": "1.3.80",
17
- "@trackunit/i18n-library-translation": "1.3.83",
18
- "@trackunit/react-components": "1.4.92",
19
- "@trackunit/iris-app-runtime-core": "1.4.79"
14
+ "@trackunit/iris-app-api": "1.3.80",
15
+ "@trackunit/react-core-contexts-api": "1.4.80",
16
+ "@trackunit/react-core-hooks": "1.3.82",
17
+ "@trackunit/i18n-library-translation": "1.3.85",
18
+ "@trackunit/react-components": "1.4.93",
19
+ "@trackunit/iris-app-runtime-core": "1.4.81",
20
+ "graphql": "^16.10.0",
21
+ "graphql-sse": "^2.5.4"
20
22
  },
21
23
  "module": "./index.esm.js",
22
24
  "main": "./index.cjs.js",
@@ -0,0 +1,5 @@
1
+ import { type PropsWithChildren } from "react";
2
+ /**
3
+ * This is a provider for the WidgetConfigContext.
4
+ */
5
+ export declare const WidgetConfigProviderIrisApp: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element;