@sanity/sdk-react 3.1.0 → 3.3.0-rc.0

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 (63) hide show
  1. package/dist/_exports/dashboard-internal.d.ts +2 -0
  2. package/dist/_exports/dashboard-internal.js +2 -0
  3. package/dist/_exports/dashboard.d.ts +457 -7
  4. package/dist/_exports/dashboard.d.ts.map +1 -1
  5. package/dist/_exports/dashboard.js +623 -2
  6. package/dist/_exports/dashboard.js.map +1 -1
  7. package/dist/index.d.ts +227 -87
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +147 -30
  10. package/dist/index.js.map +1 -1
  11. package/dist/{useStudioWorkspacesByProjectIdDataset-DxUlukmF.js → useStudioWorkspacesByProjectIdDataset-BZ_Ud887.js} +53 -56
  12. package/dist/useStudioWorkspacesByProjectIdDataset-BZ_Ud887.js.map +1 -0
  13. package/package.json +34 -32
  14. package/src/_exports/dashboard-internal.ts +1 -0
  15. package/src/_exports/dashboard.test-d.ts +64 -0
  16. package/src/_exports/dashboard.ts +70 -0
  17. package/src/_exports/index.ts +1 -1
  18. package/src/_exports/sdk-react.ts +3 -0
  19. package/src/components/auth/AuthBoundary.test.tsx +115 -2
  20. package/src/components/auth/AuthBoundary.tsx +18 -5
  21. package/src/components/auth/LoginCallback.test.tsx +46 -7
  22. package/src/components/auth/LoginCallback.tsx +22 -4
  23. package/src/context/DashboardTokenRefresh.test.tsx +124 -22
  24. package/src/context/DashboardTokenRefresh.tsx +31 -15
  25. package/src/dashboard/createRemoteInstance.test.ts +168 -0
  26. package/src/dashboard/createRemoteInstance.ts +123 -0
  27. package/src/dashboard/module.ts +39 -0
  28. package/src/dashboard/remoteClientState.ts +27 -0
  29. package/src/dashboard/urlFor.test.ts +246 -0
  30. package/src/dashboard/urlFor.ts +462 -0
  31. package/src/hooks/applications/useApplication.test-d.ts +1 -1
  32. package/src/hooks/auth/useHandleOAuthCallback.test.tsx +16 -0
  33. package/src/hooks/auth/useHandleOAuthCallback.tsx +49 -0
  34. package/src/hooks/auth/useOAuthAuthorize.test.tsx +16 -0
  35. package/src/hooks/auth/useOAuthAuthorize.tsx +28 -0
  36. package/src/hooks/auth/useOAuthTokens.test.tsx +240 -0
  37. package/src/hooks/auth/useOAuthTokens.tsx +95 -0
  38. package/src/hooks/dashboard/useApplication.test.tsx +59 -0
  39. package/src/hooks/dashboard/useApplication.ts +22 -0
  40. package/src/hooks/dashboard/useApplicationConfig.test.tsx +106 -0
  41. package/src/hooks/dashboard/useApplicationConfig.ts +45 -0
  42. package/src/hooks/dashboard/useApplicationConfigs.test.tsx +89 -0
  43. package/src/hooks/dashboard/useApplicationConfigs.ts +26 -0
  44. package/src/hooks/dashboard/useApplicationForegroundId.test.tsx +54 -0
  45. package/src/hooks/dashboard/useApplicationForegroundId.ts +22 -0
  46. package/src/hooks/dashboard/useApplications.test.tsx +249 -0
  47. package/src/hooks/dashboard/useApplications.ts +128 -0
  48. package/src/hooks/dashboard/useEmit.test.tsx +124 -0
  49. package/src/hooks/dashboard/useEmit.ts +78 -0
  50. package/src/hooks/dashboard/useNavigate.ts +1 -3
  51. package/src/hooks/dashboard/useRemoteClient.test.tsx +88 -0
  52. package/src/hooks/dashboard/useRemoteClient.ts +10 -0
  53. package/src/hooks/dashboard/useTopic.test.tsx +200 -0
  54. package/src/hooks/dashboard/useTopic.ts +29 -0
  55. package/src/hooks/dashboard/useUpdateFavorite.test.tsx +8 -1
  56. package/src/hooks/document/useApplyDocumentActions.ts +3 -4
  57. package/src/hooks/document/useCreateDocument.ts +2 -3
  58. package/src/hooks/document/useDocument.ts +11 -6
  59. package/src/hooks/document/useEditDocument.ts +5 -5
  60. package/src/hooks/projection/useDocumentProjection.ts +6 -7
  61. package/src/hooks/query/useQuery.ts +3 -4
  62. package/dist/useStudioWorkspacesByProjectIdDataset-DxUlukmF.js.map +0 -1
  63. package/src/context/dashboardToken.ts +0 -63
@@ -1,63 +0,0 @@
1
- import {from, type Observable, of} from 'rxjs'
2
- import {catchError, switchMap} from 'rxjs/operators'
3
-
4
- // The dashboard host installs its shared message bus on this well-known global
5
- // symbol before it loads the apps it embeds in its own window. It must match
6
- // the key used by `@sanity/workbench` (`Symbol.for('sanity.os.bus')`).
7
- const OS_BUS_KEY = Symbol.for('sanity.os.bus')
8
-
9
- /**
10
- * Whether this app is running inside the dashboard, embedded in its window.
11
- *
12
- * Apps embedded this way share the dashboard's realm, so the bus it installs
13
- * is visible on `globalThis`. This is `false` in a standalone app, where we
14
- * must never import `@sanity/workbench` (it would install a bus and add bundle
15
- * weight for no reason). Note: this is a different embedding model to the Core
16
- * UI iframe, which is detected separately via the dashboard context — that
17
- * signal is not set for apps sharing the dashboard's window.
18
- *
19
- * @internal
20
- */
21
- export function isDashboardEnvironment(): boolean {
22
- return typeof globalThis === 'object' && OS_BUS_KEY in globalThis
23
- }
24
-
25
- /**
26
- * Observes the session token issued by the dashboard "OS", tracking the OS auth
27
- * state over time.
28
- *
29
- * Returns `undefined` when the app is not embedded in the dashboard, so the
30
- * caller uses its normal auth flow. Inside the dashboard, subscribes to the
31
- * `auth.token` state topic, emitting the current token — or `null` when the OS
32
- * is signed out — and re-emitting as the OS auth state changes, so sign-in/out
33
- * propagates instead of being captured once. Any bus error is treated as "no
34
- * token" (`null`). The token is used in-memory only and never persisted.
35
- *
36
- * @internal
37
- */
38
- export function observeDashboardToken(): Observable<string | null> | undefined {
39
- if (!isDashboardEnvironment()) return undefined
40
-
41
- return from(import('@sanity/workbench')).pipe(
42
- switchMap(({os}) => os.subscribe('auth.token')),
43
- // Any failure (importing the host bundle, or the subscription) means "no OS token".
44
- catchError(() => of(null)),
45
- )
46
- }
47
-
48
- /**
49
- * Asks the dashboard "OS" to reissue the session token, e.g. after its current
50
- * one was rejected with a 401. Fire-and-forget: the reissued token arrives via
51
- * the `auth.token` subscription in {@link observeDashboardToken}. No-op outside
52
- * the dashboard.
53
- *
54
- * @internal
55
- */
56
- export function refreshDashboardToken(): void {
57
- if (!isDashboardEnvironment()) return
58
-
59
- void import('@sanity/workbench').then(
60
- ({os}) => os.emit('auth.token.refresh', undefined),
61
- () => {},
62
- )
63
- }