@trackunit/react-core-contexts 2.7.13-alpha-8d616e052bd.0 → 2.7.13

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
@@ -422,23 +422,31 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
422
422
  };
423
423
  };
424
424
 
425
+ // `location.hostname` carries no port, serializes IPv6 loopback with brackets, and can be
426
+ // `0.0.0.0` when the Iris App dev server is started with `--host`. Mirrors the host-side check
427
+ // in iris-app-sdk/components IrisAppIframe.tsx.
428
+ const LOOPBACK_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]", "0.0.0.0"];
425
429
  const useApolloClient = () => {
426
430
  const { graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, environment, tracingHeaders } = reactCoreHooks.useEnvironment();
427
431
  const { token: currentToken } = reactCoreHooks.useToken();
428
432
  const errorHandler = reactCoreHooks.useErrorHandler();
429
433
  const { addToast } = reactCoreHooks.useToast();
430
- const { permissions } = reactCoreHooks.useCurrentUser();
431
434
  const showErrorToast = react.useCallback((error) => {
432
435
  // Only a developer running an Iris App locally can act on a missing scope, since only
433
436
  // they can edit the manifest. The server throws the same message for real customer
434
437
  // sessions and for token clients that have no manifest at all, so surfacing it outside
435
438
  // local mode tells users to fix something they cannot reach.
436
439
  //
437
- // Read from storage rather than through useIrisAppsSDK().developerMode: that context is
438
- // created below this provider (it queries GraphQL, so it needs this Apollo client) and
439
- // lives in a visibility:host library this one cannot import.
440
- const isDeveloper = permissions?.some(permission => permission === "FAKE_PERMISSION");
441
- if (!isDeveloper) {
440
+ // Every Iris App mounts this provider inside its own iframe via TrackunitProviders, so a
441
+ // loopback hostname means *this app* is being served by a local dev server precisely the
442
+ // person who owns the manifest. useIrisAppsSDK().developerMode cannot be used instead:
443
+ // useDeveloperMode lives in core-contexts-host (visibility:host) and this library is
444
+ // visibility:shared, so nx blocks the import.
445
+ //
446
+ // Read inside the callback rather than at module scope so nothing touches `window` at
447
+ // import time and tests can stub the hostname per case.
448
+ const isServedLocally = LOOPBACK_HOSTNAMES.includes(window.location.hostname);
449
+ if (!isServedLocally) {
442
450
  return;
443
451
  }
444
452
  void addToast({
@@ -453,7 +461,7 @@ const useApolloClient = () => {
453
461
  behavior: "persistent",
454
462
  description: `${error.message} - you must add the scope to your iris app manifest`,
455
463
  });
456
- }, [addToast, permissions]);
464
+ }, [addToast]);
457
465
  const [client] = react.useState(() => {
458
466
  return createApolloClient({
459
467
  /* DON'T CHANGE THIS ! its there to ensure we don't recreate apollo client just because the token changes,
package/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { FeatureFlagRuntime, ToastRuntime, AnalyticsRuntime, registerHostChangeH
3
3
  import { FeatureFlagContextProvider, ToastProvider, AnalyticsContextProvider, AssetSortingProvider, ConfirmationDialogProvider, EnvironmentContextProvider, ErrorHandlingContextProvider, ExportDataContext, FilterBarProvider, GeolocationProvider, ModalDialogContextProvider, NavigationContextProvider, OemBrandingContextProvider, TimeRangeProvider, TokenProvider, CurrentUserProvider, CurrentUserPreferenceProvider, UserSubscriptionProvider, WidgetConfigProvider } from '@trackunit/react-core-contexts-api';
4
4
  import { useState, useEffect, useCallback, useMemo, useReducer, Suspense } from 'react';
5
5
  import { ApolloLink, Observable, createHttpLink, from, split, ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
6
- import { useEnvironment, useToken, useErrorHandler, useToast, useCurrentUser } from '@trackunit/react-core-hooks';
6
+ import { useEnvironment, useToken, useErrorHandler, useToast } from '@trackunit/react-core-hooks';
7
7
  import { setContext } from '@apollo/client/link/context';
8
8
  import { removeTypenameFromVariables } from '@apollo/client/link/remove-typename';
9
9
  import { getMainDefinition, Observable as Observable$1 } from '@apollo/client/utilities';
@@ -420,23 +420,31 @@ const createApolloClient = ({ graphqlPublicUrl, graphqlInternalUrl, graphqlRepor
420
420
  };
421
421
  };
422
422
 
423
+ // `location.hostname` carries no port, serializes IPv6 loopback with brackets, and can be
424
+ // `0.0.0.0` when the Iris App dev server is started with `--host`. Mirrors the host-side check
425
+ // in iris-app-sdk/components IrisAppIframe.tsx.
426
+ const LOOPBACK_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]", "0.0.0.0"];
423
427
  const useApolloClient = () => {
424
428
  const { graphqlPublicUrl, graphqlInternalUrl, graphqlReportUrl, environment, tracingHeaders } = useEnvironment();
425
429
  const { token: currentToken } = useToken();
426
430
  const errorHandler = useErrorHandler();
427
431
  const { addToast } = useToast();
428
- const { permissions } = useCurrentUser();
429
432
  const showErrorToast = useCallback((error) => {
430
433
  // Only a developer running an Iris App locally can act on a missing scope, since only
431
434
  // they can edit the manifest. The server throws the same message for real customer
432
435
  // sessions and for token clients that have no manifest at all, so surfacing it outside
433
436
  // local mode tells users to fix something they cannot reach.
434
437
  //
435
- // Read from storage rather than through useIrisAppsSDK().developerMode: that context is
436
- // created below this provider (it queries GraphQL, so it needs this Apollo client) and
437
- // lives in a visibility:host library this one cannot import.
438
- const isDeveloper = permissions?.some(permission => permission === "FAKE_PERMISSION");
439
- if (!isDeveloper) {
438
+ // Every Iris App mounts this provider inside its own iframe via TrackunitProviders, so a
439
+ // loopback hostname means *this app* is being served by a local dev server precisely the
440
+ // person who owns the manifest. useIrisAppsSDK().developerMode cannot be used instead:
441
+ // useDeveloperMode lives in core-contexts-host (visibility:host) and this library is
442
+ // visibility:shared, so nx blocks the import.
443
+ //
444
+ // Read inside the callback rather than at module scope so nothing touches `window` at
445
+ // import time and tests can stub the hostname per case.
446
+ const isServedLocally = LOOPBACK_HOSTNAMES.includes(window.location.hostname);
447
+ if (!isServedLocally) {
440
448
  return;
441
449
  }
442
450
  void addToast({
@@ -451,7 +459,7 @@ const useApolloClient = () => {
451
459
  behavior: "persistent",
452
460
  description: `${error.message} - you must add the scope to your iris app manifest`,
453
461
  });
454
- }, [addToast, permissions]);
462
+ }, [addToast]);
455
463
  const [client] = useState(() => {
456
464
  return createApolloClient({
457
465
  /* DON'T CHANGE THIS ! its there to ensure we don't recreate apollo client just because the token changes,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/core-contexts/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@trackunit/react-core-contexts",
3
- "version": "2.7.13-alpha-8d616e052bd.0",
3
+ "version": "2.7.13",
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": "2.4.21-alpha-8d616e052bd.0",
11
- "@trackunit/iris-app-runtime-core-api": "1.17.30-alpha-8d616e052bd.0",
12
- "@trackunit/react-core-hooks": "1.21.29-alpha-8d616e052bd.0",
13
- "@trackunit/i18n-library-translation": "2.4.29-alpha-8d616e052bd.0",
14
- "@trackunit/react-components": "2.10.24-alpha-8d616e052bd.0",
15
- "@trackunit/iris-app-runtime-core": "1.18.30-alpha-8d616e052bd.0",
10
+ "@trackunit/iris-app-api": "2.4.20",
11
+ "@trackunit/iris-app-runtime-core-api": "1.17.29",
12
+ "@trackunit/react-core-hooks": "1.21.28",
13
+ "@trackunit/i18n-library-translation": "2.4.28",
14
+ "@trackunit/react-components": "2.10.23",
15
+ "@trackunit/iris-app-runtime-core": "1.18.29",
16
16
  "graphql-sse": "^2.5.4",
17
- "@trackunit/react-core-contexts-api": "1.18.30-alpha-8d616e052bd.0"
17
+ "@trackunit/react-core-contexts-api": "1.18.29"
18
18
  },
19
19
  "peerDependencies": {
20
20
  "@apollo/client": "^3.13.8",