@sanity/sdk-react 1.0.0 → 2.0.1
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/README.md +1 -1
- package/dist/index.d.ts +60 -9
- package/dist/index.js +145 -77
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/_exports/sdk-react.ts +2 -0
- package/src/components/auth/AuthBoundary.test.tsx +30 -19
- package/src/components/auth/AuthBoundary.tsx +6 -3
- package/src/components/auth/LoginError.tsx +13 -5
- package/src/context/ComlinkTokenRefresh.test.tsx +221 -0
- package/src/context/ComlinkTokenRefresh.tsx +125 -0
- package/src/hooks/dashboard/useDashboardNavigate.test.ts +44 -0
- package/src/hooks/dashboard/useDashboardNavigate.ts +60 -0
- package/src/hooks/dashboard/useManageFavorite.ts +1 -3
- package/src/hooks/dashboard/useNavigateToStudioDocument.ts +1 -3
- package/src/hooks/dashboard/useRecordDocumentHistoryEvent.ts +1 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://sanity.io">
|
|
3
|
-
<img src="https://cdn.sanity.io/images/3do82whm/next/
|
|
3
|
+
<img src="https://cdn.sanity.io/images/3do82whm/next/d6cf401d52c33b7a5a354a14ab7de94dea2f0c02-192x192.svg" />
|
|
4
4
|
</a>
|
|
5
5
|
<h1 align="center">Sanity App SDK (React)</h1>
|
|
6
6
|
</p>
|
package/dist/index.d.ts
CHANGED
|
@@ -17,10 +17,13 @@ import {FrameMessage} from '@sanity/sdk'
|
|
|
17
17
|
import {GetUsersOptions} from '@sanity/sdk'
|
|
18
18
|
import {JsonMatch} from '@sanity/sdk'
|
|
19
19
|
import {MediaResource} from '@sanity/message-protocol'
|
|
20
|
+
import {PathChangeMessage} from '@sanity/message-protocol'
|
|
20
21
|
import {PerspectiveHandle} from '@sanity/sdk'
|
|
21
22
|
import {PreviewValue} from '@sanity/sdk'
|
|
22
23
|
import {ProjectHandle} from '@sanity/sdk'
|
|
24
|
+
import {PropsWithChildren} from 'react'
|
|
23
25
|
import {QueryOptions} from '@sanity/sdk'
|
|
26
|
+
import {default as React_2} from 'react'
|
|
24
27
|
import {ReactElement} from 'react'
|
|
25
28
|
import {ReactNode} from 'react'
|
|
26
29
|
import {ReleaseDocument} from '@sanity/sdk'
|
|
@@ -117,6 +120,13 @@ export declare interface AuthBoundaryProps {
|
|
|
117
120
|
*/
|
|
118
121
|
export declare type ComlinkStatus = 'idle' | 'handshaking' | 'connected' | 'disconnected'
|
|
119
122
|
|
|
123
|
+
/**
|
|
124
|
+
* This provider is used to provide the Comlink token refresh feature.
|
|
125
|
+
* It is used to automatically request a new token on 401 error if enabled.
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export declare const ComlinkTokenRefreshProvider: React_2.FC<PropsWithChildren>
|
|
129
|
+
|
|
120
130
|
declare interface DashboardResource {
|
|
121
131
|
id: string
|
|
122
132
|
name: string
|
|
@@ -784,6 +794,53 @@ declare type UseCurrentUser = {
|
|
|
784
794
|
*/
|
|
785
795
|
export declare const useCurrentUser: UseCurrentUser
|
|
786
796
|
|
|
797
|
+
/**
|
|
798
|
+
* @public
|
|
799
|
+
*
|
|
800
|
+
* A helper hook designed to be injected into routing components for apps within the Dashboard.
|
|
801
|
+
* While the Dashboard can usually handle navigation, there are special cases when you
|
|
802
|
+
* are already within a target app, and need to navigate to another route inside of that app.
|
|
803
|
+
*
|
|
804
|
+
* For example, your user might "favorite" a document inside of your application.
|
|
805
|
+
* If they click on the Dashboard favorites item in the sidebar, and are already within your application,
|
|
806
|
+
* there needs to be some way for the dashboard to signal to your application to reroute to where that document was favorited.
|
|
807
|
+
*
|
|
808
|
+
* This hook is intended to receive those messages, and takes a function to route to the correct path.
|
|
809
|
+
*
|
|
810
|
+
* @param navigateFn - Function to handle navigation; should accept:
|
|
811
|
+
* - `path`: a string, which will be a relative path (for example, 'my-route')
|
|
812
|
+
* - `type`: 'push', 'replace', or 'pop', which will be the type of navigation to perform
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```tsx
|
|
816
|
+
* import {useDashboardNavigate} from '@sanity/sdk-react'
|
|
817
|
+
* import {BrowserRouter, useNavigate} from 'react-router'
|
|
818
|
+
* import {Suspense} from 'react'
|
|
819
|
+
*
|
|
820
|
+
* function DashboardNavigationHandler() {
|
|
821
|
+
* const navigate = useNavigate()
|
|
822
|
+
* useDashboardNavigate(({path, type}) => {
|
|
823
|
+
* navigate(path, {replace: type === 'replace'})
|
|
824
|
+
* })
|
|
825
|
+
* return null
|
|
826
|
+
* }
|
|
827
|
+
*
|
|
828
|
+
* // Wrap the component with Suspense since the hook may suspend
|
|
829
|
+
* function MyApp() {
|
|
830
|
+
* return (
|
|
831
|
+
* <BrowserRouter>
|
|
832
|
+
* <Suspense>
|
|
833
|
+
* <DashboardNavigationHandler />
|
|
834
|
+
* </Suspense>
|
|
835
|
+
* </BrowserRouter>
|
|
836
|
+
* )
|
|
837
|
+
* }
|
|
838
|
+
* ```
|
|
839
|
+
*/
|
|
840
|
+
export declare function useDashboardNavigate(
|
|
841
|
+
navigateFn: (options: PathChangeMessage['data']) => void,
|
|
842
|
+
): void
|
|
843
|
+
|
|
787
844
|
/**
|
|
788
845
|
* @public
|
|
789
846
|
*
|
|
@@ -1754,20 +1811,18 @@ export declare const useLogOut: () => () => Promise<void>
|
|
|
1754
1811
|
* - `favorite` - Function to add document to favorites
|
|
1755
1812
|
* - `unfavorite` - Function to remove document from favorites
|
|
1756
1813
|
* - `isFavorited` - Boolean indicating if document is currently favorited
|
|
1757
|
-
* - `isConnected` - Boolean indicating if connection to Dashboard UI is established
|
|
1758
1814
|
*
|
|
1759
1815
|
* @example
|
|
1760
1816
|
* ```tsx
|
|
1761
1817
|
* function FavoriteButton(props: DocumentActionProps) {
|
|
1762
1818
|
* const {documentId, documentType} = props
|
|
1763
|
-
* const {favorite, unfavorite, isFavorited
|
|
1819
|
+
* const {favorite, unfavorite, isFavorited} = useManageFavorite({
|
|
1764
1820
|
* documentId,
|
|
1765
1821
|
* documentType
|
|
1766
1822
|
* })
|
|
1767
1823
|
*
|
|
1768
1824
|
* return (
|
|
1769
1825
|
* <Button
|
|
1770
|
-
* disabled={!isConnected}
|
|
1771
1826
|
* onClick={() => isFavorited ? unfavorite() : favorite()}
|
|
1772
1827
|
* text={isFavorited ? 'Remove from favorites' : 'Add to favorites'}
|
|
1773
1828
|
* />
|
|
@@ -1828,7 +1883,6 @@ declare interface UseManageFavoriteProps extends DocumentHandle {
|
|
|
1828
1883
|
* studios with the same projectId and dataset
|
|
1829
1884
|
* @returns An object containing:
|
|
1830
1885
|
* - `navigateToStudioDocument` - Function that when called will navigate to the studio document
|
|
1831
|
-
* - `isConnected` - Boolean indicating if connection to Dashboard is established
|
|
1832
1886
|
*
|
|
1833
1887
|
* @example
|
|
1834
1888
|
* ```tsx
|
|
@@ -1837,10 +1891,9 @@ declare interface UseManageFavoriteProps extends DocumentHandle {
|
|
|
1837
1891
|
* import {Suspense} from 'react'
|
|
1838
1892
|
*
|
|
1839
1893
|
* function NavigateButton({documentHandle}: {documentHandle: DocumentHandle}) {
|
|
1840
|
-
* const {navigateToStudioDocument
|
|
1894
|
+
* const {navigateToStudioDocument} = useNavigateToStudioDocument(documentHandle)
|
|
1841
1895
|
* return (
|
|
1842
1896
|
* <Button
|
|
1843
|
-
* disabled={!isConnected}
|
|
1844
1897
|
* onClick={navigateToStudioDocument}
|
|
1845
1898
|
* text="Navigate to Studio Document"
|
|
1846
1899
|
* />
|
|
@@ -2176,7 +2229,6 @@ export declare function useQuery<TData>(options: QueryOptions): {
|
|
|
2176
2229
|
* @param documentHandle - The document handle containing document ID and type, like `{_id: '123', _type: 'book'}`
|
|
2177
2230
|
* @returns An object containing:
|
|
2178
2231
|
* - `recordEvent` - Function to record document interactions
|
|
2179
|
-
* - `isConnected` - Boolean indicating if connection to Studio is established
|
|
2180
2232
|
*
|
|
2181
2233
|
* @example
|
|
2182
2234
|
* ```tsx
|
|
@@ -2186,7 +2238,7 @@ export declare function useQuery<TData>(options: QueryOptions): {
|
|
|
2186
2238
|
*
|
|
2187
2239
|
* function RecordEventButton(props: DocumentActionProps) {
|
|
2188
2240
|
* const {documentId, documentType, resourceType, resourceId} = props
|
|
2189
|
-
* const {recordEvent
|
|
2241
|
+
* const {recordEvent} = useRecordDocumentHistoryEvent({
|
|
2190
2242
|
* documentId,
|
|
2191
2243
|
* documentType,
|
|
2192
2244
|
* resourceType,
|
|
@@ -2194,7 +2246,6 @@ export declare function useQuery<TData>(options: QueryOptions): {
|
|
|
2194
2246
|
* })
|
|
2195
2247
|
* return (
|
|
2196
2248
|
* <Button
|
|
2197
|
-
* disabled={!isConnected}
|
|
2198
2249
|
* onClick={() => recordEvent('viewed')}
|
|
2199
2250
|
* text="Viewed"
|
|
2200
2251
|
* />
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
|
-
import { getAuthState, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout,
|
|
3
|
+
import { getAuthState, getNodeState, getIsInDashboardState, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
|
|
4
4
|
export * from "@sanity/sdk";
|
|
5
|
-
import { createContext, useContext, useSyncExternalStore,
|
|
5
|
+
import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useState, Suspense, useMemo, useCallback, useInsertionEffect, useTransition } from "react";
|
|
6
6
|
import { ErrorBoundary } from "react-error-boundary";
|
|
7
|
-
import { ClientError } from "@sanity/client";
|
|
8
|
-
import { identity, firstValueFrom, filter, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
|
|
9
7
|
import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
|
|
8
|
+
import { firstValueFrom, filter, identity, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
|
|
9
|
+
import { ClientError } from "@sanity/client";
|
|
10
10
|
import { pick } from "lodash-es";
|
|
11
11
|
const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
|
|
12
12
|
const $ = c(3), instance = useContext(SanityInstanceContext);
|
|
@@ -38,7 +38,108 @@ function createStateSourceHook(options) {
|
|
|
38
38
|
}
|
|
39
39
|
return useHook;
|
|
40
40
|
}
|
|
41
|
-
const useAuthState = createStateSourceHook(getAuthState)
|
|
41
|
+
const useAuthState = createStateSourceHook(getAuthState), useNodeState = createStateSourceHook({
|
|
42
|
+
getState: getNodeState,
|
|
43
|
+
shouldSuspend: (instance, nodeInput) => getNodeState(instance, nodeInput).getCurrent() === void 0,
|
|
44
|
+
suspender: (instance, nodeInput) => firstValueFrom(getNodeState(instance, nodeInput).observable.pipe(filter(Boolean)))
|
|
45
|
+
});
|
|
46
|
+
function useWindowConnection(t0) {
|
|
47
|
+
const $ = c(19), {
|
|
48
|
+
name,
|
|
49
|
+
connectTo,
|
|
50
|
+
onMessage
|
|
51
|
+
} = t0;
|
|
52
|
+
let t1;
|
|
53
|
+
$[0] !== connectTo || $[1] !== name ? (t1 = {
|
|
54
|
+
name,
|
|
55
|
+
connectTo
|
|
56
|
+
}, $[0] = connectTo, $[1] = name, $[2] = t1) : t1 = $[2];
|
|
57
|
+
const {
|
|
58
|
+
node
|
|
59
|
+
} = useNodeState(t1);
|
|
60
|
+
let t2;
|
|
61
|
+
$[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[3] = t2) : t2 = $[3];
|
|
62
|
+
const messageUnsubscribers = useRef(t2), instance = useSanityInstance();
|
|
63
|
+
let t3;
|
|
64
|
+
$[4] !== node || $[5] !== onMessage ? (t3 = () => (onMessage && Object.entries(onMessage).forEach((t42) => {
|
|
65
|
+
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
66
|
+
messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
|
|
67
|
+
}), () => {
|
|
68
|
+
messageUnsubscribers.current.forEach(_temp$6), messageUnsubscribers.current = [];
|
|
69
|
+
}), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
|
|
70
|
+
let t4;
|
|
71
|
+
$[7] !== instance || $[8] !== name || $[9] !== node || $[10] !== onMessage ? (t4 = [instance, name, onMessage, node], $[7] = instance, $[8] = name, $[9] = node, $[10] = onMessage, $[11] = t4) : t4 = $[11], useEffect(t3, t4);
|
|
72
|
+
let t5;
|
|
73
|
+
$[12] !== node ? (t5 = (type_0, data) => {
|
|
74
|
+
node.post(type_0, data);
|
|
75
|
+
}, $[12] = node, $[13] = t5) : t5 = $[13];
|
|
76
|
+
const sendMessage = t5;
|
|
77
|
+
let t6;
|
|
78
|
+
$[14] !== node ? (t6 = (type_1, data_0, fetchOptions) => node.fetch(type_1, data_0, fetchOptions ?? {}), $[14] = node, $[15] = t6) : t6 = $[15];
|
|
79
|
+
const fetch = t6;
|
|
80
|
+
let t7;
|
|
81
|
+
return $[16] !== fetch || $[17] !== sendMessage ? (t7 = {
|
|
82
|
+
sendMessage,
|
|
83
|
+
fetch
|
|
84
|
+
}, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
|
|
85
|
+
}
|
|
86
|
+
function _temp$6(unsubscribe) {
|
|
87
|
+
return unsubscribe();
|
|
88
|
+
}
|
|
89
|
+
const DEFAULT_RESPONSE_TIMEOUT = 1e4;
|
|
90
|
+
function DashboardTokenRefresh(t0) {
|
|
91
|
+
const $ = c(14), {
|
|
92
|
+
children
|
|
93
|
+
} = t0, instance = useSanityInstance(), isTokenRefreshInProgress = useRef(!1), timeoutRef = useRef(null), processed401ErrorRef = useRef(null), authState = useAuthState();
|
|
94
|
+
let t1;
|
|
95
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => {
|
|
96
|
+
timeoutRef.current && (clearTimeout(timeoutRef.current), timeoutRef.current = null);
|
|
97
|
+
}, $[0] = t1) : t1 = $[0];
|
|
98
|
+
const clearRefreshTimeout = t1;
|
|
99
|
+
let t2;
|
|
100
|
+
$[1] === Symbol.for("react.memo_cache_sentinel") ? (t2 = {
|
|
101
|
+
name: SDK_NODE_NAME,
|
|
102
|
+
connectTo: SDK_CHANNEL_NAME
|
|
103
|
+
}, $[1] = t2) : t2 = $[1];
|
|
104
|
+
const windowConnection = useWindowConnection(t2);
|
|
105
|
+
let t3;
|
|
106
|
+
$[2] !== instance || $[3] !== windowConnection ? (t3 = async () => {
|
|
107
|
+
if (!isTokenRefreshInProgress.current) {
|
|
108
|
+
isTokenRefreshInProgress.current = !0, clearRefreshTimeout(), timeoutRef.current = setTimeout(() => {
|
|
109
|
+
isTokenRefreshInProgress.current && (isTokenRefreshInProgress.current = !1), timeoutRef.current = null;
|
|
110
|
+
}, DEFAULT_RESPONSE_TIMEOUT);
|
|
111
|
+
try {
|
|
112
|
+
const res = await windowConnection.fetch("dashboard/v1/auth/tokens/create");
|
|
113
|
+
clearRefreshTimeout(), res.token && setAuthToken(instance, res.token), isTokenRefreshInProgress.current = !1;
|
|
114
|
+
} catch {
|
|
115
|
+
isTokenRefreshInProgress.current = !1, clearRefreshTimeout();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}, $[2] = instance, $[3] = windowConnection, $[4] = t3) : t3 = $[4];
|
|
119
|
+
const requestNewToken = t3;
|
|
120
|
+
let t4, t5;
|
|
121
|
+
$[5] === Symbol.for("react.memo_cache_sentinel") ? (t4 = () => () => {
|
|
122
|
+
clearRefreshTimeout();
|
|
123
|
+
}, t5 = [clearRefreshTimeout], $[5] = t4, $[6] = t5) : (t4 = $[5], t5 = $[6]), useEffect(t4, t5);
|
|
124
|
+
let t6;
|
|
125
|
+
$[7] !== authState.error || $[8] !== authState.type || $[9] !== requestNewToken ? (t6 = () => {
|
|
126
|
+
const has401Error = authState.type === AuthStateType.ERROR && authState.error && authState.error?.statusCode === 401 && !isTokenRefreshInProgress.current && processed401ErrorRef.current !== authState.error, isLoggedOut = authState.type === AuthStateType.LOGGED_OUT && !isTokenRefreshInProgress.current;
|
|
127
|
+
has401Error || isLoggedOut ? (processed401ErrorRef.current = authState.type === AuthStateType.ERROR ? authState.error : void 0, requestNewToken()) : (authState.type !== AuthStateType.ERROR || processed401ErrorRef.current !== (authState.type === AuthStateType.ERROR ? authState.error : void 0)) && (processed401ErrorRef.current = null);
|
|
128
|
+
}, $[7] = authState.error, $[8] = authState.type, $[9] = requestNewToken, $[10] = t6) : t6 = $[10];
|
|
129
|
+
let t7;
|
|
130
|
+
return $[11] !== authState || $[12] !== requestNewToken ? (t7 = [authState, requestNewToken], $[11] = authState, $[12] = requestNewToken, $[13] = t7) : t7 = $[13], useEffect(t6, t7), children;
|
|
131
|
+
}
|
|
132
|
+
const ComlinkTokenRefreshProvider = (t0) => {
|
|
133
|
+
const $ = c(2), {
|
|
134
|
+
children
|
|
135
|
+
} = t0, instance = useSanityInstance();
|
|
136
|
+
let t1;
|
|
137
|
+
if (t1 = getIsInDashboardState(instance).getCurrent(), t1) {
|
|
138
|
+
let t2;
|
|
139
|
+
return $[0] !== children ? (t2 = /* @__PURE__ */ jsx(DashboardTokenRefresh, { children }), $[0] = children, $[1] = t2) : t2 = $[1], t2;
|
|
140
|
+
}
|
|
141
|
+
return children;
|
|
142
|
+
};
|
|
42
143
|
function useLoginUrl() {
|
|
43
144
|
const $ = c(2), instance = useSanityInstance();
|
|
44
145
|
let t0, t1;
|
|
@@ -96,19 +197,19 @@ function LoginCallback() {
|
|
|
96
197
|
let t0, t1;
|
|
97
198
|
return $[0] !== handleAuthCallback2 ? (t0 = () => {
|
|
98
199
|
const url = new URL(location.href);
|
|
99
|
-
handleAuthCallback2(url.toString()).then(_temp$
|
|
200
|
+
handleAuthCallback2(url.toString()).then(_temp$5);
|
|
100
201
|
}, t1 = [handleAuthCallback2], $[0] = handleAuthCallback2, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1), null;
|
|
101
202
|
}
|
|
102
|
-
function _temp$
|
|
203
|
+
function _temp$5(replacementLocation) {
|
|
103
204
|
replacementLocation && history.replaceState(null, "", replacementLocation);
|
|
104
205
|
}
|
|
105
206
|
const useLogOut = createCallbackHook(logout);
|
|
106
207
|
function LoginError(t0) {
|
|
107
|
-
const $ = c(
|
|
208
|
+
const $ = c(23), {
|
|
108
209
|
error,
|
|
109
210
|
resetErrorBoundary
|
|
110
211
|
} = t0;
|
|
111
|
-
if (!(error instanceof AuthError || error instanceof ConfigurationError))
|
|
212
|
+
if (!(error instanceof AuthError || error instanceof ConfigurationError || error instanceof ClientError))
|
|
112
213
|
throw error;
|
|
113
214
|
const logout2 = useLogOut(), authState = useAuthState(), [authErrorMessage, setAuthErrorMessage] = useState("Please try again or contact support if the problem persists.");
|
|
114
215
|
let t1;
|
|
@@ -117,36 +218,36 @@ function LoginError(t0) {
|
|
|
117
218
|
}, $[0] = logout2, $[1] = resetErrorBoundary, $[2] = t1) : t1 = $[2];
|
|
118
219
|
const handleRetry = t1;
|
|
119
220
|
let t2;
|
|
120
|
-
$[3] !== authState.
|
|
121
|
-
if (
|
|
122
|
-
if (
|
|
221
|
+
$[3] !== authState.type || $[4] !== error || $[5] !== handleRetry ? (t2 = () => {
|
|
222
|
+
if (error instanceof ClientError) {
|
|
223
|
+
if (error.statusCode === 401)
|
|
123
224
|
handleRetry();
|
|
124
|
-
else if (
|
|
125
|
-
const errorMessage =
|
|
225
|
+
else if (error.statusCode === 404) {
|
|
226
|
+
const errorMessage = error.response.body.message || "";
|
|
126
227
|
errorMessage.startsWith("Session with sid") && errorMessage.endsWith("not found") ? setAuthErrorMessage("The session ID is invalid or expired.") : setAuthErrorMessage("The login link is invalid or expired. Please try again.");
|
|
127
228
|
}
|
|
128
229
|
}
|
|
129
230
|
authState.type !== AuthStateType.ERROR && error instanceof ConfigurationError && setAuthErrorMessage(error.message);
|
|
130
|
-
}, $[3] = authState.
|
|
231
|
+
}, $[3] = authState.type, $[4] = error, $[5] = handleRetry, $[6] = t2) : t2 = $[6];
|
|
131
232
|
let t3;
|
|
132
|
-
$[
|
|
233
|
+
$[7] !== authState || $[8] !== error || $[9] !== handleRetry ? (t3 = [authState, handleRetry, error], $[7] = authState, $[8] = error, $[9] = handleRetry, $[10] = t3) : t3 = $[10], useEffect(t2, t3);
|
|
133
234
|
const t4 = error instanceof AuthError ? "Authentication Error" : "Configuration Error";
|
|
134
235
|
let t5;
|
|
135
|
-
$[
|
|
236
|
+
$[11] !== t4 ? (t5 = /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: t4 }), $[11] = t4, $[12] = t5) : t5 = $[12];
|
|
136
237
|
let t6;
|
|
137
|
-
$[
|
|
238
|
+
$[13] !== authErrorMessage ? (t6 = /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: authErrorMessage }), $[13] = authErrorMessage, $[14] = t6) : t6 = $[14];
|
|
138
239
|
let t7;
|
|
139
|
-
$[
|
|
240
|
+
$[15] !== t5 || $[16] !== t6 ? (t7 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
|
|
140
241
|
t5,
|
|
141
242
|
t6
|
|
142
|
-
] }), $[
|
|
243
|
+
] }), $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17];
|
|
143
244
|
let t8;
|
|
144
|
-
$[
|
|
245
|
+
$[18] !== handleRetry ? (t8 = /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" }), $[18] = handleRetry, $[19] = t8) : t8 = $[19];
|
|
145
246
|
let t9;
|
|
146
|
-
return $[
|
|
247
|
+
return $[20] !== t7 || $[21] !== t8 ? (t9 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
|
|
147
248
|
t7,
|
|
148
249
|
t8
|
|
149
|
-
] }), $[
|
|
250
|
+
] }), $[20] = t7, $[21] = t8, $[22] = t9) : t9 = $[22], t9;
|
|
150
251
|
}
|
|
151
252
|
if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
|
|
152
253
|
const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
|
|
@@ -168,7 +269,7 @@ function AuthBoundary(t0) {
|
|
|
168
269
|
let t4;
|
|
169
270
|
$[5] !== props ? (t4 = /* @__PURE__ */ jsx(AuthSwitch, { ...props }), $[5] = props, $[6] = t4) : t4 = $[6];
|
|
170
271
|
let t5;
|
|
171
|
-
return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
|
|
272
|
+
return $[7] !== FallbackComponent || $[8] !== t4 ? (t5 = /* @__PURE__ */ jsx(ComlinkTokenRefreshProvider, { children: /* @__PURE__ */ jsx(ErrorBoundary, { FallbackComponent, children: t4 }) }), $[7] = FallbackComponent, $[8] = t4, $[9] = t5) : t5 = $[9], t5;
|
|
172
273
|
}
|
|
173
274
|
function AuthSwitch(t0) {
|
|
174
275
|
const $ = c(13);
|
|
@@ -260,9 +361,9 @@ function SanityApp(t0) {
|
|
|
260
361
|
}
|
|
261
362
|
function _temp2$1() {
|
|
262
363
|
let timeout;
|
|
263
|
-
return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$
|
|
364
|
+
return !isInIframe() && !isLocalUrl(window) && (timeout = setTimeout(_temp$4, 1e3)), () => clearTimeout(timeout);
|
|
264
365
|
}
|
|
265
|
-
function _temp$
|
|
366
|
+
function _temp$4() {
|
|
266
367
|
console.warn("Redirecting to core", REDIRECT_URL), window.location.replace(REDIRECT_URL);
|
|
267
368
|
}
|
|
268
369
|
const useAuthToken = createStateSourceHook(getTokenState), useCurrentUser = createStateSourceHook(getCurrentUserState);
|
|
@@ -304,7 +405,7 @@ function useFrameConnection(options) {
|
|
|
304
405
|
const [type, handler] = t22, unsubscribe = channel.on(type, handler);
|
|
305
406
|
messageUnsubscribers.push(unsubscribe);
|
|
306
407
|
}), () => {
|
|
307
|
-
messageUnsubscribers.forEach(_temp$
|
|
408
|
+
messageUnsubscribers.forEach(_temp$3), releaseChannel(instance, name), channelRef.current = null, controllerRef.current = null;
|
|
308
409
|
};
|
|
309
410
|
}, t1 = [targetOrigin, name, connectTo, heartbeat, onMessage, instance, onStatus], $[0] = connectTo, $[1] = heartbeat, $[2] = instance, $[3] = name, $[4] = onMessage, $[5] = onStatus, $[6] = targetOrigin, $[7] = t0, $[8] = t1) : (t0 = $[7], t1 = $[8]), useEffect(t0, t1);
|
|
310
411
|
let t2;
|
|
@@ -326,56 +427,21 @@ function useFrameConnection(options) {
|
|
|
326
427
|
sendMessage
|
|
327
428
|
}, $[11] = t4) : t4 = $[11], t4;
|
|
328
429
|
}
|
|
329
|
-
function _temp$
|
|
430
|
+
function _temp$3(unsub) {
|
|
330
431
|
return unsub();
|
|
331
432
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
$[0] !== connectTo || $[1] !== name ? (t1 = {
|
|
345
|
-
name,
|
|
346
|
-
connectTo
|
|
347
|
-
}, $[0] = connectTo, $[1] = name, $[2] = t1) : t1 = $[2];
|
|
348
|
-
const {
|
|
349
|
-
node
|
|
350
|
-
} = useNodeState(t1);
|
|
351
|
-
let t2;
|
|
352
|
-
$[3] === Symbol.for("react.memo_cache_sentinel") ? (t2 = [], $[3] = t2) : t2 = $[3];
|
|
353
|
-
const messageUnsubscribers = useRef(t2), instance = useSanityInstance();
|
|
354
|
-
let t3;
|
|
355
|
-
$[4] !== node || $[5] !== onMessage ? (t3 = () => (onMessage && Object.entries(onMessage).forEach((t42) => {
|
|
356
|
-
const [type, handler] = t42, messageUnsubscribe = node.on(type, handler);
|
|
357
|
-
messageUnsubscribe && messageUnsubscribers.current.push(messageUnsubscribe);
|
|
358
|
-
}), () => {
|
|
359
|
-
messageUnsubscribers.current.forEach(_temp$3), messageUnsubscribers.current = [];
|
|
360
|
-
}), $[4] = node, $[5] = onMessage, $[6] = t3) : t3 = $[6];
|
|
361
|
-
let t4;
|
|
362
|
-
$[7] !== instance || $[8] !== name || $[9] !== node || $[10] !== onMessage ? (t4 = [instance, name, onMessage, node], $[7] = instance, $[8] = name, $[9] = node, $[10] = onMessage, $[11] = t4) : t4 = $[11], useEffect(t3, t4);
|
|
363
|
-
let t5;
|
|
364
|
-
$[12] !== node ? (t5 = (type_0, data) => {
|
|
365
|
-
node.post(type_0, data);
|
|
366
|
-
}, $[12] = node, $[13] = t5) : t5 = $[13];
|
|
367
|
-
const sendMessage = t5;
|
|
368
|
-
let t6;
|
|
369
|
-
$[14] !== node ? (t6 = (type_1, data_0, fetchOptions) => node.fetch(type_1, data_0, fetchOptions ?? {}), $[14] = node, $[15] = t6) : t6 = $[15];
|
|
370
|
-
const fetch = t6;
|
|
371
|
-
let t7;
|
|
372
|
-
return $[16] !== fetch || $[17] !== sendMessage ? (t7 = {
|
|
373
|
-
sendMessage,
|
|
374
|
-
fetch
|
|
375
|
-
}, $[16] = fetch, $[17] = sendMessage, $[18] = t7) : t7 = $[18], t7;
|
|
376
|
-
}
|
|
377
|
-
function _temp$3(unsubscribe) {
|
|
378
|
-
return unsubscribe();
|
|
433
|
+
function useDashboardNavigate(navigateFn) {
|
|
434
|
+
const $ = c(2);
|
|
435
|
+
let t0;
|
|
436
|
+
$[0] !== navigateFn ? (t0 = {
|
|
437
|
+
name: SDK_NODE_NAME,
|
|
438
|
+
connectTo: SDK_CHANNEL_NAME,
|
|
439
|
+
onMessage: {
|
|
440
|
+
"dashboard/v1/history/change-path": (data) => {
|
|
441
|
+
navigateFn(data);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}, $[0] = navigateFn, $[1] = t0) : t0 = $[1], useWindowConnection(t0);
|
|
379
445
|
}
|
|
380
446
|
function useManageFavorite({
|
|
381
447
|
documentId,
|
|
@@ -1046,7 +1112,7 @@ function useUsers(options) {
|
|
|
1046
1112
|
loadMore
|
|
1047
1113
|
};
|
|
1048
1114
|
}
|
|
1049
|
-
var version = "
|
|
1115
|
+
var version = "2.0.1";
|
|
1050
1116
|
function getEnv(key) {
|
|
1051
1117
|
if (typeof import.meta < "u" && import.meta.env)
|
|
1052
1118
|
return import.meta.env[key];
|
|
@@ -1058,6 +1124,7 @@ function getEnv(key) {
|
|
|
1058
1124
|
const REACT_SDK_VERSION = getEnv("PKG_VERSION") || `${version}-development`;
|
|
1059
1125
|
export {
|
|
1060
1126
|
AuthBoundary,
|
|
1127
|
+
ComlinkTokenRefreshProvider,
|
|
1061
1128
|
REACT_SDK_VERSION,
|
|
1062
1129
|
ResourceProvider,
|
|
1063
1130
|
SDKProvider,
|
|
@@ -1068,6 +1135,7 @@ export {
|
|
|
1068
1135
|
useAuthToken,
|
|
1069
1136
|
useClient,
|
|
1070
1137
|
useCurrentUser,
|
|
1138
|
+
useDashboardNavigate,
|
|
1071
1139
|
useDashboardOrganizationId,
|
|
1072
1140
|
useDatasets,
|
|
1073
1141
|
useDocument,
|