@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.
- package/dist/_exports/dashboard-internal.d.ts +2 -0
- package/dist/_exports/dashboard-internal.js +2 -0
- package/dist/_exports/dashboard.d.ts +457 -7
- package/dist/_exports/dashboard.d.ts.map +1 -1
- package/dist/_exports/dashboard.js +623 -2
- package/dist/_exports/dashboard.js.map +1 -1
- package/dist/index.d.ts +227 -87
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +147 -30
- package/dist/index.js.map +1 -1
- package/dist/{useStudioWorkspacesByProjectIdDataset-DxUlukmF.js → useStudioWorkspacesByProjectIdDataset-BZ_Ud887.js} +53 -56
- package/dist/useStudioWorkspacesByProjectIdDataset-BZ_Ud887.js.map +1 -0
- package/package.json +34 -32
- package/src/_exports/dashboard-internal.ts +1 -0
- package/src/_exports/dashboard.test-d.ts +64 -0
- package/src/_exports/dashboard.ts +70 -0
- package/src/_exports/index.ts +1 -1
- package/src/_exports/sdk-react.ts +3 -0
- package/src/components/auth/AuthBoundary.test.tsx +115 -2
- package/src/components/auth/AuthBoundary.tsx +18 -5
- package/src/components/auth/LoginCallback.test.tsx +46 -7
- package/src/components/auth/LoginCallback.tsx +22 -4
- package/src/context/DashboardTokenRefresh.test.tsx +124 -22
- package/src/context/DashboardTokenRefresh.tsx +31 -15
- package/src/dashboard/createRemoteInstance.test.ts +168 -0
- package/src/dashboard/createRemoteInstance.ts +123 -0
- package/src/dashboard/module.ts +39 -0
- package/src/dashboard/remoteClientState.ts +27 -0
- package/src/dashboard/urlFor.test.ts +246 -0
- package/src/dashboard/urlFor.ts +462 -0
- package/src/hooks/applications/useApplication.test-d.ts +1 -1
- package/src/hooks/auth/useHandleOAuthCallback.test.tsx +16 -0
- package/src/hooks/auth/useHandleOAuthCallback.tsx +49 -0
- package/src/hooks/auth/useOAuthAuthorize.test.tsx +16 -0
- package/src/hooks/auth/useOAuthAuthorize.tsx +28 -0
- package/src/hooks/auth/useOAuthTokens.test.tsx +240 -0
- package/src/hooks/auth/useOAuthTokens.tsx +95 -0
- package/src/hooks/dashboard/useApplication.test.tsx +59 -0
- package/src/hooks/dashboard/useApplication.ts +22 -0
- package/src/hooks/dashboard/useApplicationConfig.test.tsx +106 -0
- package/src/hooks/dashboard/useApplicationConfig.ts +45 -0
- package/src/hooks/dashboard/useApplicationConfigs.test.tsx +89 -0
- package/src/hooks/dashboard/useApplicationConfigs.ts +26 -0
- package/src/hooks/dashboard/useApplicationForegroundId.test.tsx +54 -0
- package/src/hooks/dashboard/useApplicationForegroundId.ts +22 -0
- package/src/hooks/dashboard/useApplications.test.tsx +249 -0
- package/src/hooks/dashboard/useApplications.ts +128 -0
- package/src/hooks/dashboard/useEmit.test.tsx +124 -0
- package/src/hooks/dashboard/useEmit.ts +78 -0
- package/src/hooks/dashboard/useNavigate.ts +1 -3
- package/src/hooks/dashboard/useRemoteClient.test.tsx +88 -0
- package/src/hooks/dashboard/useRemoteClient.ts +10 -0
- package/src/hooks/dashboard/useTopic.test.tsx +200 -0
- package/src/hooks/dashboard/useTopic.ts +29 -0
- package/src/hooks/dashboard/useUpdateFavorite.test.tsx +8 -1
- package/src/hooks/document/useApplyDocumentActions.ts +3 -4
- package/src/hooks/document/useCreateDocument.ts +2 -3
- package/src/hooks/document/useDocument.ts +11 -6
- package/src/hooks/document/useEditDocument.ts +5 -5
- package/src/hooks/projection/useDocumentProjection.ts +6 -7
- package/src/hooks/query/useQuery.ts +3 -4
- package/dist/useStudioWorkspacesByProjectIdDataset-DxUlukmF.js.map +0 -1
- 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
|
-
}
|