@sanity/sdk 2.8.0 → 3.0.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/index.d.ts +228 -239
- package/dist/index.js +287 -454
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/_exports/index.ts +16 -17
- package/src/agent/agentActions.test.ts +60 -16
- package/src/agent/agentActions.ts +29 -20
- package/src/auth/authMode.test.ts +0 -25
- package/src/auth/authMode.ts +3 -6
- package/src/auth/authStore.test.ts +129 -66
- package/src/auth/authStore.ts +9 -11
- package/src/auth/dashboardAuth.ts +2 -2
- package/src/auth/getOrganizationVerificationState.test.ts +10 -11
- package/src/auth/handleAuthCallback.test.ts +0 -12
- package/src/auth/handleAuthCallback.ts +9 -3
- package/src/auth/logout.test.ts +0 -6
- package/src/auth/refreshStampedToken.test.ts +121 -17
- package/src/auth/standaloneAuth.ts +9 -3
- package/src/auth/studioAuth.ts +35 -8
- package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +9 -3
- package/src/auth/subscribeToStateAndFetchCurrentUser.ts +1 -1
- package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +0 -2
- package/src/auth/subscribeToStorageEventsAndSetToken.ts +2 -2
- package/src/auth/utils.ts +33 -0
- package/src/client/clientStore.test.ts +14 -61
- package/src/client/clientStore.ts +52 -28
- package/src/comlink/controller/actions/destroyController.test.ts +1 -4
- package/src/comlink/controller/actions/getOrCreateChannel.test.ts +1 -4
- package/src/comlink/controller/actions/getOrCreateController.test.ts +1 -4
- package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
- package/src/comlink/controller/comlinkControllerStore.test.ts +1 -4
- package/src/comlink/node/actions/getOrCreateNode.test.ts +1 -4
- package/src/comlink/node/actions/releaseNode.test.ts +1 -4
- package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
- package/src/comlink/node/getNodeState.test.ts +1 -1
- package/src/config/__tests__/handles.test.ts +12 -18
- package/src/config/handles.ts +7 -25
- package/src/config/sanityConfig.ts +99 -52
- package/src/datasets/datasets.test.ts +2 -2
- package/src/datasets/datasets.ts +4 -10
- package/src/document/actions.test.ts +33 -4
- package/src/document/actions.ts +3 -10
- package/src/document/applyDocumentActions.test.ts +17 -18
- package/src/document/applyDocumentActions.ts +9 -12
- package/src/document/documentStore.test.ts +303 -133
- package/src/document/documentStore.ts +70 -61
- package/src/document/permissions.test.ts +44 -8
- package/src/document/processActions.test.ts +77 -7
- package/src/document/reducers.test.ts +35 -3
- package/src/document/sharedListener.test.ts +13 -13
- package/src/document/sharedListener.ts +8 -3
- package/src/favorites/favorites.test.ts +10 -2
- package/src/presence/presenceStore.test.ts +34 -9
- package/src/presence/presenceStore.ts +29 -13
- package/src/preview/previewProjectionUtils.test.ts +192 -0
- package/src/preview/previewProjectionUtils.ts +88 -0
- package/src/preview/{previewStore.ts → types.ts} +6 -25
- package/src/project/project.test.ts +1 -1
- package/src/project/project.ts +14 -20
- package/src/projection/getProjectionState.test.ts +4 -2
- package/src/projection/getProjectionState.ts +2 -21
- package/src/projection/projectionQuery.ts +2 -3
- package/src/projection/projectionStore.test.ts +3 -3
- package/src/projection/resolveProjection.test.ts +2 -1
- package/src/projection/resolveProjection.ts +2 -18
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +2 -2
- package/src/projection/subscribeToStateAndFetchBatches.ts +23 -36
- package/src/projection/types.ts +1 -9
- package/src/projects/projects.test.ts +1 -1
- package/src/query/queryStore.test.ts +86 -28
- package/src/query/queryStore.ts +23 -38
- package/src/releases/getPerspectiveState.test.ts +14 -13
- package/src/releases/getPerspectiveState.ts +6 -6
- package/src/releases/releasesStore.test.ts +21 -6
- package/src/releases/releasesStore.ts +18 -8
- package/src/store/createActionBinder.test.ts +114 -111
- package/src/store/createActionBinder.ts +52 -101
- package/src/store/createSanityInstance.test.ts +13 -83
- package/src/store/createSanityInstance.ts +2 -78
- package/src/store/createStateSourceAction.test.ts +2 -2
- package/src/store/createStateSourceAction.ts +5 -5
- package/src/store/createStoreInstance.test.ts +2 -4
- package/src/users/reducers.test.ts +1 -6
- package/src/users/reducers.ts +2 -2
- package/src/users/types.ts +4 -4
- package/src/users/usersStore.test.ts +12 -15
- package/src/utils/createFetcherStore.test.ts +1 -1
- package/src/utils/logger.test.ts +0 -12
- package/src/utils/logger.ts +3 -8
- package/src/preview/getPreviewState.test.ts +0 -120
- package/src/preview/getPreviewState.ts +0 -91
- package/src/preview/previewQuery.test.ts +0 -236
- package/src/preview/previewQuery.ts +0 -153
- package/src/preview/previewStore.test.ts +0 -36
- package/src/preview/resolvePreview.test.ts +0 -47
- package/src/preview/resolvePreview.ts +0 -20
- package/src/preview/subscribeToStateAndFetchBatches.test.ts +0 -221
- package/src/preview/subscribeToStateAndFetchBatches.ts +0 -112
- package/src/preview/util.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sanity SDK",
|
|
6
6
|
"keywords": [
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
50
50
|
"@sanity/diff-patch": "^6.0.0",
|
|
51
51
|
"@sanity/id-utils": "^1.0.0",
|
|
52
|
+
"@sanity/image-url": "^2.0.3",
|
|
52
53
|
"@sanity/json-match": "^1.0.5",
|
|
53
54
|
"@sanity/message-protocol": "^0.18.0",
|
|
54
55
|
"@sanity/mutate": "^0.12.4",
|
|
55
56
|
"@sanity/types": "^5.2.0",
|
|
56
|
-
"groq": "3.88.1-typegen-experimental.0",
|
|
57
57
|
"groq-js": "^1.19.0",
|
|
58
58
|
"lodash-es": "^4.17.21",
|
|
59
59
|
"reselect": "^5.1.1",
|
|
@@ -75,8 +75,8 @@
|
|
|
75
75
|
"@repo/config-eslint": "0.0.0",
|
|
76
76
|
"@repo/config-test": "0.0.1",
|
|
77
77
|
"@repo/package.bundle": "3.82.0",
|
|
78
|
-
"@repo/
|
|
79
|
-
"@repo/
|
|
78
|
+
"@repo/tsconfig": "0.0.1",
|
|
79
|
+
"@repo/package.config": "0.0.1"
|
|
80
80
|
},
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=20.19"
|
package/src/_exports/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type {
|
|
|
12
12
|
AgentPatchResult,
|
|
13
13
|
AgentPromptOptions,
|
|
14
14
|
AgentPromptResult,
|
|
15
|
+
AgentResourceOptions,
|
|
15
16
|
AgentTransformOptions,
|
|
16
17
|
AgentTransformResult,
|
|
17
18
|
AgentTranslateOptions,
|
|
@@ -71,10 +72,9 @@ export {
|
|
|
71
72
|
} from '../comlink/types'
|
|
72
73
|
export {type AuthConfig, type AuthProvider} from '../config/authConfig'
|
|
73
74
|
export {
|
|
74
|
-
createDatasetHandle,
|
|
75
75
|
createDocumentHandle,
|
|
76
76
|
createDocumentTypeHandle,
|
|
77
|
-
|
|
77
|
+
createResourceHandle,
|
|
78
78
|
} from '../config/handles'
|
|
79
79
|
export {
|
|
80
80
|
configureLogging,
|
|
@@ -86,19 +86,19 @@ export {
|
|
|
86
86
|
type LogNamespace,
|
|
87
87
|
} from '../config/loggingConfig'
|
|
88
88
|
export {
|
|
89
|
-
type
|
|
90
|
-
type
|
|
91
|
-
|
|
89
|
+
type CanvasResource,
|
|
90
|
+
type DatasetResource,
|
|
91
|
+
DEFAULT_RESOURCE_NAME,
|
|
92
92
|
type DocumentHandle,
|
|
93
|
-
type
|
|
93
|
+
type DocumentResource,
|
|
94
94
|
type DocumentTypeHandle,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
type
|
|
95
|
+
isCanvasResource,
|
|
96
|
+
isDatasetResource,
|
|
97
|
+
isMediaLibraryResource,
|
|
98
|
+
type MediaLibraryResource,
|
|
99
99
|
type PerspectiveHandle,
|
|
100
|
-
type ProjectHandle,
|
|
101
100
|
type ReleasePerspective,
|
|
101
|
+
type ResourceHandle,
|
|
102
102
|
type SanityConfig,
|
|
103
103
|
type StudioConfig,
|
|
104
104
|
type TokenSource,
|
|
@@ -145,7 +145,6 @@ export {
|
|
|
145
145
|
type TransactionAcceptedEvent,
|
|
146
146
|
type TransactionRevertedEvent,
|
|
147
147
|
} from '../document/events'
|
|
148
|
-
export {type JsonMatch} from '../document/patchOperations'
|
|
149
148
|
export {type DocumentPermissionsResult, type PermissionDeniedReason} from '../document/permissions'
|
|
150
149
|
export type {FavoriteStatusResponse} from '../favorites/favorites'
|
|
151
150
|
export {getFavoritesState, resolveFavoritesState} from '../favorites/favorites'
|
|
@@ -158,14 +157,14 @@ export type {
|
|
|
158
157
|
TransportEvent,
|
|
159
158
|
UserPresence,
|
|
160
159
|
} from '../presence/types'
|
|
161
|
-
export {
|
|
162
|
-
export
|
|
163
|
-
export {
|
|
160
|
+
export {PREVIEW_PROJECTION} from '../preview/previewConstants'
|
|
161
|
+
export {transformProjectionToPreview} from '../preview/previewProjectionUtils'
|
|
162
|
+
export type {PreviewMedia, PreviewQueryResult, PreviewValue, ValuePending} from '../preview/types'
|
|
164
163
|
export {type OrgVerificationResult} from '../project/organizationVerification'
|
|
165
|
-
export {getProjectState, resolveProject} from '../project/project'
|
|
164
|
+
export {getProjectState, type ProjectHandle, resolveProject} from '../project/project'
|
|
166
165
|
export {getProjectionState} from '../projection/getProjectionState'
|
|
167
166
|
export {resolveProjection} from '../projection/resolveProjection'
|
|
168
|
-
export {type ProjectionValuePending
|
|
167
|
+
export {type ProjectionValuePending} from '../projection/types'
|
|
169
168
|
export {getProjectsState, resolveProjects} from '../projects/projects'
|
|
170
169
|
export {
|
|
171
170
|
getQueryKey,
|
|
@@ -11,13 +11,16 @@ import {
|
|
|
11
11
|
} from './agentActions'
|
|
12
12
|
|
|
13
13
|
let mockClient: any
|
|
14
|
+
const mockGetClientState = vi.fn()
|
|
14
15
|
|
|
15
16
|
vi.mock('../client/clientStore', () => {
|
|
16
17
|
return {
|
|
17
|
-
getClientState: () => (
|
|
18
|
+
getClientState: (...args: unknown[]) => mockGetClientState(...args),
|
|
18
19
|
}
|
|
19
20
|
})
|
|
20
21
|
|
|
22
|
+
const testResource = {projectId: 'p', dataset: 'd'}
|
|
23
|
+
|
|
21
24
|
describe('agent actions', () => {
|
|
22
25
|
beforeEach(() => {
|
|
23
26
|
mockClient = {
|
|
@@ -37,45 +40,86 @@ describe('agent actions', () => {
|
|
|
37
40
|
},
|
|
38
41
|
},
|
|
39
42
|
}
|
|
43
|
+
mockGetClientState.mockReturnValue({observable: of(mockClient)})
|
|
40
44
|
})
|
|
41
45
|
|
|
42
|
-
it('agentGenerate
|
|
46
|
+
it('agentGenerate passes resource to getClientState and strips it from agent options', async () => {
|
|
43
47
|
mockClient.observable.agent.action.generate.mockReturnValue(of('gen'))
|
|
44
|
-
const instance = {config: {
|
|
45
|
-
const value = await firstValueFrom(
|
|
48
|
+
const instance = {config: {}} as any
|
|
49
|
+
const value = await firstValueFrom(
|
|
50
|
+
agentGenerate(instance, {foo: 'bar', resource: testResource} as any),
|
|
51
|
+
)
|
|
46
52
|
expect(value).toBe('gen')
|
|
53
|
+
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
54
|
+
apiVersion: 'vX',
|
|
55
|
+
resource: testResource,
|
|
56
|
+
})
|
|
47
57
|
expect(mockClient.observable.agent.action.generate).toHaveBeenCalledWith({foo: 'bar'})
|
|
48
58
|
})
|
|
49
59
|
|
|
50
|
-
it('agentTransform
|
|
60
|
+
it('agentTransform passes resource to getClientState and strips it from agent options', async () => {
|
|
51
61
|
mockClient.observable.agent.action.transform.mockReturnValue(of('xform'))
|
|
52
|
-
const instance = {config: {
|
|
53
|
-
const value = await firstValueFrom(
|
|
62
|
+
const instance = {config: {}} as any
|
|
63
|
+
const value = await firstValueFrom(
|
|
64
|
+
agentTransform(instance, {a: 1, resource: testResource} as any),
|
|
65
|
+
)
|
|
54
66
|
expect(value).toBe('xform')
|
|
67
|
+
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
68
|
+
apiVersion: 'vX',
|
|
69
|
+
resource: testResource,
|
|
70
|
+
})
|
|
55
71
|
expect(mockClient.observable.agent.action.transform).toHaveBeenCalledWith({a: 1})
|
|
56
72
|
})
|
|
57
73
|
|
|
58
|
-
it('agentTranslate
|
|
74
|
+
it('agentTranslate passes resource to getClientState and strips it from agent options', async () => {
|
|
59
75
|
mockClient.observable.agent.action.translate.mockReturnValue(of('xlate'))
|
|
60
|
-
const instance = {config: {
|
|
61
|
-
const value = await firstValueFrom(
|
|
76
|
+
const instance = {config: {}} as any
|
|
77
|
+
const value = await firstValueFrom(
|
|
78
|
+
agentTranslate(instance, {b: 2, resource: testResource} as any),
|
|
79
|
+
)
|
|
62
80
|
expect(value).toBe('xlate')
|
|
81
|
+
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
82
|
+
apiVersion: 'vX',
|
|
83
|
+
resource: testResource,
|
|
84
|
+
})
|
|
63
85
|
expect(mockClient.observable.agent.action.translate).toHaveBeenCalledWith({b: 2})
|
|
64
86
|
})
|
|
65
87
|
|
|
66
|
-
it('agentPrompt
|
|
88
|
+
it('agentPrompt passes resource to getClientState and strips it from agent options', async () => {
|
|
67
89
|
mockClient.agent.action.prompt.mockResolvedValue('prompted')
|
|
68
|
-
const instance = {config: {
|
|
69
|
-
const value = await firstValueFrom(
|
|
90
|
+
const instance = {config: {}} as any
|
|
91
|
+
const value = await firstValueFrom(
|
|
92
|
+
agentPrompt(instance, {p: true, resource: testResource} as any),
|
|
93
|
+
)
|
|
70
94
|
expect(value).toBe('prompted')
|
|
95
|
+
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
96
|
+
apiVersion: 'vX',
|
|
97
|
+
resource: testResource,
|
|
98
|
+
})
|
|
71
99
|
expect(mockClient.agent.action.prompt).toHaveBeenCalledWith({p: true})
|
|
72
100
|
})
|
|
73
101
|
|
|
74
|
-
it('agentPatch
|
|
102
|
+
it('agentPatch passes resource to getClientState and strips it from agent options', async () => {
|
|
75
103
|
mockClient.agent.action.patch.mockResolvedValue('patched')
|
|
76
|
-
const instance = {config: {
|
|
77
|
-
const value = await firstValueFrom(
|
|
104
|
+
const instance = {config: {}} as any
|
|
105
|
+
const value = await firstValueFrom(
|
|
106
|
+
agentPatch(instance, {q: false, resource: testResource} as any),
|
|
107
|
+
)
|
|
78
108
|
expect(value).toBe('patched')
|
|
109
|
+
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
110
|
+
apiVersion: 'vX',
|
|
111
|
+
resource: testResource,
|
|
112
|
+
})
|
|
79
113
|
expect(mockClient.agent.action.patch).toHaveBeenCalledWith({q: false})
|
|
80
114
|
})
|
|
115
|
+
|
|
116
|
+
it('works without an explicit resource (falls back via getClientState)', async () => {
|
|
117
|
+
mockClient.observable.agent.action.generate.mockReturnValue(of('gen'))
|
|
118
|
+
const instance = {config: {}} as any
|
|
119
|
+
await firstValueFrom(agentGenerate(instance, {foo: 'bar'} as any))
|
|
120
|
+
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
121
|
+
apiVersion: 'vX',
|
|
122
|
+
resource: undefined,
|
|
123
|
+
})
|
|
124
|
+
})
|
|
81
125
|
})
|
|
@@ -2,10 +2,19 @@ import {type SanityClient} from '@sanity/client'
|
|
|
2
2
|
import {from, Observable, switchMap} from 'rxjs'
|
|
3
3
|
|
|
4
4
|
import {getClientState} from '../client/clientStore'
|
|
5
|
+
import {type DocumentResource} from '../config/sanityConfig'
|
|
5
6
|
import {type SanityInstance} from '../store/createSanityInstance'
|
|
6
7
|
|
|
7
8
|
const API_VERSION = 'vX'
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Options that all agent actions accept for targeting a specific resource.
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export interface AgentResourceOptions {
|
|
15
|
+
resource: DocumentResource
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
/** @alpha */
|
|
10
19
|
export type AgentGenerateOptions = Parameters<
|
|
11
20
|
SanityClient['observable']['agent']['action']['generate']
|
|
@@ -57,13 +66,13 @@ export type AgentPatchResult = Awaited<ReturnType<SanityClient['agent']['action'
|
|
|
57
66
|
*/
|
|
58
67
|
export function agentGenerate(
|
|
59
68
|
instance: SanityInstance,
|
|
60
|
-
options: AgentGenerateOptions,
|
|
69
|
+
options: AgentGenerateOptions & AgentResourceOptions,
|
|
61
70
|
): AgentGenerateResult {
|
|
71
|
+
const {resource, ...agentOptions} = options
|
|
62
72
|
return getClientState(instance, {
|
|
63
73
|
apiVersion: API_VERSION,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}).observable.pipe(switchMap((client) => client.observable.agent.action.generate(options)))
|
|
74
|
+
resource,
|
|
75
|
+
}).observable.pipe(switchMap((client) => client.observable.agent.action.generate(agentOptions)))
|
|
67
76
|
}
|
|
68
77
|
|
|
69
78
|
/**
|
|
@@ -75,13 +84,13 @@ export function agentGenerate(
|
|
|
75
84
|
*/
|
|
76
85
|
export function agentTransform(
|
|
77
86
|
instance: SanityInstance,
|
|
78
|
-
options: AgentTransformOptions,
|
|
87
|
+
options: AgentTransformOptions & AgentResourceOptions,
|
|
79
88
|
): AgentTransformResult {
|
|
89
|
+
const {resource, ...agentOptions} = options
|
|
80
90
|
return getClientState(instance, {
|
|
81
91
|
apiVersion: API_VERSION,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}).observable.pipe(switchMap((client) => client.observable.agent.action.transform(options)))
|
|
92
|
+
resource,
|
|
93
|
+
}).observable.pipe(switchMap((client) => client.observable.agent.action.transform(agentOptions)))
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
/**
|
|
@@ -93,13 +102,13 @@ export function agentTransform(
|
|
|
93
102
|
*/
|
|
94
103
|
export function agentTranslate(
|
|
95
104
|
instance: SanityInstance,
|
|
96
|
-
options: AgentTranslateOptions,
|
|
105
|
+
options: AgentTranslateOptions & AgentResourceOptions,
|
|
97
106
|
): AgentTranslateResult {
|
|
107
|
+
const {resource, ...agentOptions} = options
|
|
98
108
|
return getClientState(instance, {
|
|
99
109
|
apiVersion: API_VERSION,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}).observable.pipe(switchMap((client) => client.observable.agent.action.translate(options)))
|
|
110
|
+
resource,
|
|
111
|
+
}).observable.pipe(switchMap((client) => client.observable.agent.action.translate(agentOptions)))
|
|
103
112
|
}
|
|
104
113
|
|
|
105
114
|
/**
|
|
@@ -111,13 +120,13 @@ export function agentTranslate(
|
|
|
111
120
|
*/
|
|
112
121
|
export function agentPrompt(
|
|
113
122
|
instance: SanityInstance,
|
|
114
|
-
options: AgentPromptOptions,
|
|
123
|
+
options: AgentPromptOptions & AgentResourceOptions,
|
|
115
124
|
): Observable<AgentPromptResult> {
|
|
125
|
+
const {resource, ...agentOptions} = options
|
|
116
126
|
return getClientState(instance, {
|
|
117
127
|
apiVersion: API_VERSION,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}).observable.pipe(switchMap((client) => from(client.agent.action.prompt(options))))
|
|
128
|
+
resource,
|
|
129
|
+
}).observable.pipe(switchMap((client) => from(client.agent.action.prompt(agentOptions))))
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
/**
|
|
@@ -129,11 +138,11 @@ export function agentPrompt(
|
|
|
129
138
|
*/
|
|
130
139
|
export function agentPatch(
|
|
131
140
|
instance: SanityInstance,
|
|
132
|
-
options: AgentPatchOptions,
|
|
141
|
+
options: AgentPatchOptions & AgentResourceOptions,
|
|
133
142
|
): Observable<AgentPatchResult> {
|
|
143
|
+
const {resource, ...agentOptions} = options
|
|
134
144
|
return getClientState(instance, {
|
|
135
145
|
apiVersion: API_VERSION,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}).observable.pipe(switchMap((client) => from(client.agent.action.patch(options))))
|
|
146
|
+
resource,
|
|
147
|
+
}).observable.pipe(switchMap((client) => from(client.agent.action.patch(agentOptions))))
|
|
139
148
|
}
|
|
@@ -9,11 +9,6 @@ describe('resolveAuthMode', () => {
|
|
|
9
9
|
expect(resolveAuthMode(config, 'https://example.com')).toBe('studio')
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
-
it('returns "studio" when deprecated studioMode.enabled is true', () => {
|
|
13
|
-
const config: SanityConfig = {studioMode: {enabled: true}}
|
|
14
|
-
expect(resolveAuthMode(config, 'https://example.com')).toBe('studio')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
12
|
it('returns "dashboard" when _context URL param has a non-empty JSON object', () => {
|
|
18
13
|
const context = encodeURIComponent(JSON.stringify({orgId: '123'}))
|
|
19
14
|
const href = `https://example.com?_context=${context}`
|
|
@@ -23,14 +18,6 @@ describe('resolveAuthMode', () => {
|
|
|
23
18
|
it('returns "standalone" by default', () => {
|
|
24
19
|
expect(resolveAuthMode({}, 'https://example.com')).toBe('standalone')
|
|
25
20
|
})
|
|
26
|
-
|
|
27
|
-
it('prefers studio config over studioMode', () => {
|
|
28
|
-
const config: SanityConfig = {
|
|
29
|
-
studio: {},
|
|
30
|
-
studioMode: {enabled: true},
|
|
31
|
-
}
|
|
32
|
-
expect(resolveAuthMode(config, 'https://example.com')).toBe('studio')
|
|
33
|
-
})
|
|
34
21
|
})
|
|
35
22
|
|
|
36
23
|
describe('isStudioConfig', () => {
|
|
@@ -38,19 +25,7 @@ describe('isStudioConfig', () => {
|
|
|
38
25
|
expect(isStudioConfig({studio: {}})).toBe(true)
|
|
39
26
|
})
|
|
40
27
|
|
|
41
|
-
it('returns true when deprecated studioMode.enabled is true', () => {
|
|
42
|
-
expect(isStudioConfig({studioMode: {enabled: true}})).toBe(true)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
it('returns false when studioMode.enabled is false', () => {
|
|
46
|
-
expect(isStudioConfig({studioMode: {enabled: false}})).toBe(false)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
28
|
it('returns false for empty config', () => {
|
|
50
29
|
expect(isStudioConfig({})).toBe(false)
|
|
51
30
|
})
|
|
52
|
-
|
|
53
|
-
it('returns true when both studio and studioMode are present', () => {
|
|
54
|
-
expect(isStudioConfig({studio: {}, studioMode: {enabled: true}})).toBe(true)
|
|
55
|
-
})
|
|
56
31
|
})
|
package/src/auth/authMode.ts
CHANGED
|
@@ -20,9 +20,8 @@ type AuthMode = 'studio' | 'dashboard' | 'standalone'
|
|
|
20
20
|
*
|
|
21
21
|
* Priority:
|
|
22
22
|
* 1. `studio` config provided → `'studio'`
|
|
23
|
-
* 2. `
|
|
24
|
-
* 3.
|
|
25
|
-
* 4. Otherwise → `'standalone'`
|
|
23
|
+
* 2. Dashboard context detected (`_context` URL param with content) → `'dashboard'`
|
|
24
|
+
* 3. Otherwise → `'standalone'`
|
|
26
25
|
*
|
|
27
26
|
* @internal
|
|
28
27
|
*/
|
|
@@ -34,13 +33,11 @@ export function resolveAuthMode(config: SanityConfig, locationHref: string): Aut
|
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* Returns `true` when the config indicates the SDK is running inside a Studio.
|
|
37
|
-
* Checks the new `studio` field first, then falls back to the deprecated
|
|
38
|
-
* `studioMode.enabled` for backwards compatibility.
|
|
39
36
|
*
|
|
40
37
|
* @internal
|
|
41
38
|
*/
|
|
42
39
|
export function isStudioConfig(config: SanityConfig): boolean {
|
|
43
|
-
return !!config.studio
|
|
40
|
+
return !!config.studio
|
|
44
41
|
}
|
|
45
42
|
|
|
46
43
|
/**
|