@sanity/sdk-react 2.7.0 → 2.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/sdk-react",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "private": false,
5
5
  "description": "Sanity SDK React toolkit for Content OS",
6
6
  "keywords": [
@@ -52,7 +52,7 @@
52
52
  "react-compiler-runtime": "19.1.0-rc.2",
53
53
  "react-error-boundary": "^5.0.0",
54
54
  "rxjs": "^7.8.2",
55
- "@sanity/sdk": "2.7.0"
55
+ "@sanity/sdk": "2.8.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@sanity/browserslist-config": "^1.0.5",
@@ -77,10 +77,10 @@
77
77
  "typescript": "^5.8.3",
78
78
  "vite": "^6.3.4",
79
79
  "vitest": "^3.2.4",
80
- "@repo/package.config": "0.0.1",
80
+ "@repo/package.bundle": "3.82.0",
81
81
  "@repo/config-eslint": "0.0.0",
82
82
  "@repo/config-test": "0.0.1",
83
- "@repo/package.bundle": "3.82.0",
83
+ "@repo/package.config": "0.0.1",
84
84
  "@repo/tsconfig": "0.0.1"
85
85
  },
86
86
  "peerDependencies": {
@@ -22,6 +22,9 @@ vi.mock('../../hooks/auth/useHandleAuthCallback', () => ({
22
22
  vi.mock('../../hooks/auth/useLogOut', () => ({
23
23
  useLogOut: vi.fn(() => async () => {}),
24
24
  }))
25
+ vi.mock('../../hooks/comlink/useWindowConnection', () => ({
26
+ useWindowConnection: vi.fn(() => ({fetch: vi.fn()})),
27
+ }))
25
28
 
26
29
  // Mock AuthError throwing scenario
27
30
  vi.mock('./AuthError', async (importOriginal) => {
@@ -9,6 +9,10 @@ vi.mock('../../hooks/auth/useLogOut', () => ({
9
9
  useLogOut: vi.fn(() => async () => {}),
10
10
  }))
11
11
 
12
+ vi.mock('../../hooks/comlink/useWindowConnection', () => ({
13
+ useWindowConnection: vi.fn(() => ({fetch: vi.fn()})),
14
+ }))
15
+
12
16
  describe('LoginError', () => {
13
17
  it('shows authentication error and retry button', async () => {
14
18
  const mockReset = vi.fn()
@@ -21,6 +25,7 @@ describe('LoginError', () => {
21
25
  )
22
26
 
23
27
  expect(screen.getByText('Authentication Error')).toBeInTheDocument()
28
+
24
29
  const retryButton = screen.getByRole('button', {name: 'Retry'})
25
30
  fireEvent.click(retryButton)
26
31
 
@@ -1,4 +1,5 @@
1
1
  import {ClientError} from '@sanity/client'
2
+ import {SDK_CHANNEL_NAME, SDK_NODE_NAME} from '@sanity/message-protocol'
2
3
  import {
3
4
  AuthStateType,
4
5
  getClientErrorApiBody,
@@ -10,6 +11,8 @@ import {type FallbackProps} from 'react-error-boundary'
10
11
 
11
12
  import {useAuthState} from '../../hooks/auth/useAuthState'
12
13
  import {useLogOut} from '../../hooks/auth/useLogOut'
14
+ import {useWindowConnection} from '../../hooks/comlink/useWindowConnection'
15
+ import {useSanityInstance} from '../../hooks/context/useSanityInstance'
13
16
  import {Error} from '../errors/Error'
14
17
  import {AuthError} from './AuthError'
15
18
  import {ConfigurationError} from './ConfigurationError'
@@ -36,12 +39,23 @@ export function LoginError({error, resetErrorBoundary}: LoginErrorProps): React.
36
39
 
37
40
  const logout = useLogOut()
38
41
  const authState = useAuthState()
42
+ const {
43
+ config: {projectId},
44
+ } = useSanityInstance()
39
45
 
40
46
  const [authErrorMessage, setAuthErrorMessage] = useState(
41
47
  'Please try again or contact support if the problem persists.',
42
48
  )
43
49
  const [showRetryCta, setShowRetryCta] = useState(true)
44
50
 
51
+ /**
52
+ * TODO: before merge update message-protocol package to include the new message type
53
+ */
54
+ const {fetch} = useWindowConnection({
55
+ name: SDK_NODE_NAME,
56
+ connectTo: SDK_CHANNEL_NAME,
57
+ })
58
+
45
59
  const handleRetry = useCallback(async () => {
46
60
  await logout()
47
61
  resetErrorBoundary()
@@ -55,6 +69,13 @@ export function LoginError({error, resetErrorBoundary}: LoginErrorProps): React.
55
69
  const description = getClientErrorApiDescription(error)
56
70
  if (description) setAuthErrorMessage(description)
57
71
  setShowRetryCta(false)
72
+ /**
73
+ * Handoff to dashboard to enable the request access flow for the project.
74
+ */
75
+ fetch('dashboard/v1/auth/access/request', {
76
+ resourceType: 'project',
77
+ resourceId: projectId,
78
+ })
58
79
  } else {
59
80
  setShowRetryCta(true)
60
81
  handleRetry()
@@ -73,7 +94,7 @@ export function LoginError({error, resetErrorBoundary}: LoginErrorProps): React.
73
94
  setAuthErrorMessage(error.message)
74
95
  setShowRetryCta(true)
75
96
  }
76
- }, [authState, handleRetry, error])
97
+ }, [authState, handleRetry, error, fetch, projectId])
77
98
 
78
99
  return (
79
100
  <Error