@burdenoff/microfe-sandbox 2026.601.2 → 2026.601.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxProvider.js","names":[],"sources":["../../../src/sandbox/providers/SandboxProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport { createContext, use, useMemo } from 'react';\nimport { MemoryRouter } from 'react-router-dom';\nimport { MutationCache, QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ApolloClient, InMemoryCache, HttpLink, from } from '@apollo/client';\nimport { onError } from '@apollo/client/link/error';\nimport { ApolloProvider } from '@apollo/client/react';\nimport { isAuthNetworkError, redirectToLogin } from '@burdenoff/fe-libs/shared/utils';\nimport { PermissionProvider } from '@burdenoff/fe-libs/shared/providers/shell';\nimport type { SandboxRootProps } from '../types';\n\nfunction hasSessionAuthErrors(\n errors: ReadonlyArray<{ message?: string; extensions?: Record<string, unknown> }> = []\n): boolean {\n return errors.some((error) => {\n const code = typeof error.extensions?.code === 'string' ? error.extensions.code : '';\n const errorCode =\n typeof error.extensions?.errorCode === 'string' ? error.extensions.errorCode : '';\n const message = (error.message ?? '').toLowerCase();\n\n return (\n code === 'UNAUTHENTICATED' ||\n errorCode === 'TOKEN_EXPIRED' ||\n message.includes('token_expired') ||\n message.includes('token expired') ||\n message.includes('session expired') ||\n message.includes('unauthorized') ||\n message.includes('unauthenticated') ||\n message.includes('authentication required') ||\n message.includes('workspace context missing')\n );\n });\n}\n\n/**\n * Context value for Sandbox microfrontend\n */\ntype SandboxContextValue = SandboxRootProps;\n\nconst SandboxContext = createContext<SandboxContextValue | null>(null);\n\n/**\n * Hook to access Sandbox context\n */\nexport const useSandbox = () => {\n const context = use(SandboxContext);\n if (!context) {\n throw new Error('useSandbox must be used within SandboxProvider');\n }\n return context;\n};\n\n/**\n * Provider component for Sandbox microfrontend\n * Sets up routing, context, Apollo Client, and React Query client\n */\nexport const SandboxProvider: FC<PropsWithChildren<SandboxRootProps>> = ({\n children,\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n authToken,\n workspaceToken,\n}) => {\n const contextValue: SandboxContextValue = {\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n authToken,\n workspaceToken,\n };\n\n // Create QueryClient instance (memoized to avoid recreation on re-renders)\n const queryClient = useMemo(\n () => {\n const client = new QueryClient({\n mutationCache: new MutationCache({\n onSuccess: () => {\n void client.invalidateQueries();\n },\n }),\n defaultOptions: {\n queries: {\n retry: 1,\n refetchOnWindowFocus: false,\n staleTime: 5 * 60 * 1000, // 5 minutes\n },\n },\n });\n return client;\n },\n []\n );\n\n // Create ApolloClient instance (memoized, recreated when context changes)\n // Auth tokens are sent to the PUBLIC GATEWAY only (never to downstream services).\n // The gateway validates tokens, strips them, and injects context headers\n // (x-actor-id, x-workspace-id, etc.) for downstream subgraph services.\n const apolloClient = useMemo(() => {\n const headers: Record<string, string> = {};\n\n // Auth tokens — consumed by the gateway, never forwarded to subgraphs\n if (authToken) headers['Authorization'] = `Bearer ${authToken}`;\n if (workspaceToken) headers['X-Workspace-Authorization'] = `Bearer ${workspaceToken}`;\n\n // Context headers — forwarded by the gateway to downstream subgraphs.\n // X-Workspace-ID is the primary workspace context and is always sent.\n // This ensures workspace isolation works even when the workspace token\n // issuance fails (gateway uses this header as fallback context).\n if (workspaceId) headers['X-Workspace-ID'] = workspaceId;\n\n const httpLink = new HttpLink({\n uri: apiGatewayUrl ? `${apiGatewayUrl}/workspaces/graphql` : '/workspaces/graphql',\n headers: Object.keys(headers).length > 0 ? headers : undefined,\n });\n\n const errorLink = onError(({ error }) => {\n if (!error) return;\n\n const graphQLErrors = 'errors' in error && Array.isArray(error.errors) ? error.errors : [];\n\n if (hasSessionAuthErrors(graphQLErrors)) {\n redirectToLogin();\n return;\n }\n\n if (error instanceof Error && isAuthNetworkError(error)) {\n redirectToLogin();\n }\n });\n\n return new ApolloClient({\n link: from([errorLink, httpLink]),\n cache: new InMemoryCache(),\n defaultOptions: {\n watchQuery: {\n fetchPolicy: 'cache-and-network',\n },\n },\n });\n }, [apiGatewayUrl, authToken, workspaceToken, workspaceId]);\n\n // Wrap content with QueryClientProvider and Context.Provider\n const content = (\n <QueryClientProvider client={queryClient}>\n <SandboxContext.Provider value={contextValue}>\n <PermissionProvider scopeId={workspaceId ?? null} gateway=\"workspace\">\n {children}\n </PermissionProvider>\n </SandboxContext.Provider>\n </QueryClientProvider>\n );\n\n // When integrated into a shell (basePath provided), the shell already has a router\n // and ApolloProvider so we don't create another one. When standalone (no basePath),\n // use MemoryRouter and ApolloProvider.\n if (basePath) {\n // Integrated mode: shell already has BrowserRouter and ApolloProvider, don't create nested ones\n return content;\n }\n\n // Standalone mode: create MemoryRouter and ApolloProvider for independent operation\n return (\n <ApolloProvider client={apolloClient}>\n <MemoryRouter>{content}</MemoryRouter>\n </ApolloProvider>\n );\n};\n"],"mappings":";;;;;;;;;;AAWA,SAAS,EACP,IAAoF,EAAE,EAC7E;AACT,QAAO,EAAO,MAAM,MAAU;EAC5B,IAAM,IAAO,OAAO,EAAM,YAAY,QAAS,WAAW,EAAM,WAAW,OAAO,IAC5E,IACJ,OAAO,EAAM,YAAY,aAAc,WAAW,EAAM,WAAW,YAAY,IAC3E,KAAW,EAAM,WAAW,IAAI,aAAa;AAEnD,SACE,MAAS,qBACT,MAAc,mBACd,EAAQ,SAAS,gBAAgB,IACjC,EAAQ,SAAS,gBAAgB,IACjC,EAAQ,SAAS,kBAAkB,IACnC,EAAQ,SAAS,eAAe,IAChC,EAAQ,SAAS,kBAAkB,IACnC,EAAQ,SAAS,0BAA0B,IAC3C,EAAQ,SAAS,4BAA4B;GAE/C;;AAQJ,IAAM,IAAiB,EAA0C,KAAK,EAKzD,UAAmB;CAC9B,IAAM,IAAU,EAAI,EAAe;AACnC,KAAI,CAAC,EACH,OAAU,MAAM,iDAAiD;AAEnE,QAAO;GAOI,KAA4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kBAAC,GAAD;EAAgB,QAAQ;YACtB,kBAAC,GAAD,EAAA,UAAe,GAAuB,CAAA;EACvB,CAAA"}
1
+ {"version":3,"file":"SandboxProvider.js","names":[],"sources":["../../../src/sandbox/providers/SandboxProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport { createContext, use, useMemo } from 'react';\nimport { MemoryRouter } from 'react-router-dom';\nimport { MutationCache, QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { ApolloClient, InMemoryCache, HttpLink, from } from '@apollo/client';\nimport { onError } from '@apollo/client/link/error';\nimport { ApolloProvider } from '@apollo/client/react';\nimport { isAuthNetworkError, redirectToLogin } from '@burdenoff/fe-libs/shared/utils';\nimport { PermissionProvider } from '@burdenoff/fe-libs/shared/providers/shell';\nimport type { SandboxRootProps } from '../types';\n\nfunction hasSessionAuthErrors(\n errors: ReadonlyArray<{ message?: string; extensions?: Record<string, unknown> }> = []\n): boolean {\n return errors.some((error) => {\n const code = typeof error.extensions?.code === 'string' ? error.extensions.code : '';\n const errorCode =\n typeof error.extensions?.errorCode === 'string' ? error.extensions.errorCode : '';\n const message = (error.message ?? '').toLowerCase();\n\n return (\n code === 'UNAUTHENTICATED' ||\n errorCode === 'TOKEN_EXPIRED' ||\n message.includes('token_expired') ||\n message.includes('token expired') ||\n message.includes('session expired') ||\n message.includes('unauthorized') ||\n message.includes('unauthenticated') ||\n message.includes('authentication required') ||\n message.includes('workspace context missing')\n );\n });\n}\n\n/**\n * Context value for Sandbox microfrontend\n */\ntype SandboxContextValue = SandboxRootProps;\n\nconst SandboxContext = createContext<SandboxContextValue | null>(null);\n\n/**\n * Hook to access Sandbox context\n */\nexport const useSandbox = () => {\n const context = use(SandboxContext);\n if (!context) {\n throw new Error('useSandbox must be used within SandboxProvider');\n }\n return context;\n};\n\n/**\n * Provider component for Sandbox microfrontend\n * Sets up routing, context, Apollo Client, and React Query client\n */\nexport const SandboxProvider: FC<PropsWithChildren<SandboxRootProps>> = ({\n children,\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n authToken,\n workspaceToken,\n}) => {\n const contextValue: SandboxContextValue = {\n basePath,\n navigate,\n currentUser,\n workspaceId,\n apiGatewayUrl,\n authToken,\n workspaceToken,\n };\n\n // Create QueryClient instance (memoized to avoid recreation on re-renders)\n const queryClient = useMemo(() => {\n const client = new QueryClient({\n mutationCache: new MutationCache({\n onSuccess: () => {\n void client.invalidateQueries();\n },\n }),\n defaultOptions: {\n queries: {\n retry: 1,\n refetchOnWindowFocus: false,\n staleTime: 5 * 60 * 1000, // 5 minutes\n },\n },\n });\n return client;\n }, []);\n\n // Create ApolloClient instance (memoized, recreated when context changes)\n // Auth tokens are sent to the PUBLIC GATEWAY only (never to downstream services).\n // The gateway validates tokens, strips them, and injects context headers\n // (x-actor-id, x-workspace-id, etc.) for downstream subgraph services.\n const apolloClient = useMemo(() => {\n const headers: Record<string, string> = {};\n\n // Auth tokens — consumed by the gateway, never forwarded to subgraphs\n if (authToken) headers['Authorization'] = `Bearer ${authToken}`;\n if (workspaceToken) headers['X-Workspace-Authorization'] = `Bearer ${workspaceToken}`;\n\n // Context headers — forwarded by the gateway to downstream subgraphs.\n // X-Workspace-ID is the primary workspace context and is always sent.\n // This ensures workspace isolation works even when the workspace token\n // issuance fails (gateway uses this header as fallback context).\n if (workspaceId) headers['X-Workspace-ID'] = workspaceId;\n\n const httpLink = new HttpLink({\n uri: apiGatewayUrl ? `${apiGatewayUrl}/workspaces/graphql` : '/workspaces/graphql',\n headers: Object.keys(headers).length > 0 ? headers : undefined,\n });\n\n const errorLink = onError(({ error }) => {\n if (!error) return;\n\n const graphQLErrors = 'errors' in error && Array.isArray(error.errors) ? error.errors : [];\n\n if (hasSessionAuthErrors(graphQLErrors)) {\n redirectToLogin();\n return;\n }\n\n if (error instanceof Error && isAuthNetworkError(error)) {\n redirectToLogin();\n }\n });\n\n return new ApolloClient({\n link: from([errorLink, httpLink]),\n cache: new InMemoryCache(),\n defaultOptions: {\n watchQuery: {\n fetchPolicy: 'cache-and-network',\n },\n },\n });\n }, [apiGatewayUrl, authToken, workspaceToken, workspaceId]);\n\n // Wrap content with QueryClientProvider and Context.Provider\n const content = (\n <QueryClientProvider client={queryClient}>\n <SandboxContext.Provider value={contextValue}>\n <PermissionProvider scopeId={workspaceId ?? null} gateway=\"workspace\">\n {children}\n </PermissionProvider>\n </SandboxContext.Provider>\n </QueryClientProvider>\n );\n\n // When integrated into a shell (basePath provided), the shell already has a router\n // and ApolloProvider so we don't create another one. When standalone (no basePath),\n // use MemoryRouter and ApolloProvider.\n if (basePath) {\n // Integrated mode: shell already has BrowserRouter and ApolloProvider, don't create nested ones\n return content;\n }\n\n // Standalone mode: create MemoryRouter and ApolloProvider for independent operation\n return (\n <ApolloProvider client={apolloClient}>\n <MemoryRouter>{content}</MemoryRouter>\n </ApolloProvider>\n );\n};\n"],"mappings":";;;;;;;;;;AAWA,SAAS,EACP,IAAoF,EAAE,EAC7E;AACT,QAAO,EAAO,MAAM,MAAU;EAC5B,IAAM,IAAO,OAAO,EAAM,YAAY,QAAS,WAAW,EAAM,WAAW,OAAO,IAC5E,IACJ,OAAO,EAAM,YAAY,aAAc,WAAW,EAAM,WAAW,YAAY,IAC3E,KAAW,EAAM,WAAW,IAAI,aAAa;AAEnD,SACE,MAAS,qBACT,MAAc,mBACd,EAAQ,SAAS,gBAAgB,IACjC,EAAQ,SAAS,gBAAgB,IACjC,EAAQ,SAAS,kBAAkB,IACnC,EAAQ,SAAS,eAAe,IAChC,EAAQ,SAAS,kBAAkB,IACnC,EAAQ,SAAS,0BAA0B,IAC3C,EAAQ,SAAS,4BAA4B;GAE/C;;AAQJ,IAAM,IAAiB,EAA0C,KAAK,EAKzD,UAAmB;CAC9B,IAAM,IAAU,EAAI,EAAe;AACnC,KAAI,CAAC,EACH,OAAU,MAAM,iDAAiD;AAEnE,QAAO;GAOI,KAA4D,EACvE,aACA,aACA,aACA,gBACA,gBACA,kBACA,cACA,wBACI;CAC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UAAe,GAAuB,CAAA;EACvB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-sandbox",
3
- "version": "2026.601.2",
3
+ "version": "2026.601.3",
4
4
  "description": "Burdenoff Sandbox Microfrontend - Manage ephemeral sandbox environments",
5
5
  "type": "module",
6
6
  "files": [