@sanity/sdk 3.0.0-rc.0 → 3.0.0-rc.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/dist/_chunks-dts/createGroqSearchFilter.d.ts +1147 -0
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +1 -0
- package/dist/_chunks-es/_internal.js +134 -0
- package/dist/_chunks-es/_internal.js.map +1 -0
- package/dist/_chunks-es/createGroqSearchFilter.js +1864 -0
- package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -0
- package/dist/_chunks-es/telemetryManager.js +93 -0
- package/dist/_chunks-es/telemetryManager.js.map +1 -0
- package/dist/_exports/_internal.d.ts +95 -0
- package/dist/_exports/_internal.d.ts.map +1 -0
- package/dist/_exports/_internal.js +24 -0
- package/dist/_exports/_internal.js.map +1 -0
- package/dist/index.d.ts +1079 -1076
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1967 -2302
- package/dist/index.js.map +1 -1
- package/package.json +48 -47
- package/src/_exports/_internal.ts +26 -0
- package/src/_exports/index.ts +120 -11
- package/src/access/checkPermissions.test.ts +55 -0
- package/src/access/checkPermissions.ts +54 -0
- package/src/agent/agentActions.test.ts +16 -60
- package/src/agent/agentActions.ts +25 -38
- package/src/applications/applications.test-d.ts +83 -0
- package/src/applications/applications.test.ts +130 -0
- package/src/applications/applications.ts +364 -0
- package/src/applications/userApplications.test.ts +126 -0
- package/src/applications/userApplications.ts +261 -0
- package/src/auth/authLogger.ts +30 -0
- package/src/auth/authMode.test.ts +25 -0
- package/src/auth/authMode.ts +6 -3
- package/src/auth/authStore.test.ts +194 -13
- package/src/auth/authStore.ts +59 -26
- package/src/auth/getOrganizationVerificationState.test.ts +18 -17
- package/src/auth/getOrganizationVerificationState.ts +4 -4
- package/src/auth/handleAuthCallback.test.ts +35 -1
- package/src/auth/handleAuthCallback.ts +25 -6
- package/src/auth/logout.test.ts +75 -2
- package/src/auth/logout.ts +23 -4
- package/src/auth/refreshStampedToken.test.ts +219 -469
- package/src/auth/refreshStampedToken.ts +79 -195
- package/src/auth/studioAuth.ts +1 -1
- package/src/auth/studioModeAuth.ts +2 -1
- package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +146 -13
- package/src/auth/subscribeToStateAndFetchCurrentUser.ts +37 -6
- package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +2 -0
- package/src/client/clientStore.test.ts +62 -37
- package/src/client/clientStore.ts +45 -75
- package/src/client/liveEvents.test.ts +151 -0
- package/src/client/liveEvents.ts +107 -0
- package/src/comlink/controller/actions/destroyController.test.ts +4 -1
- package/src/comlink/controller/actions/getOrCreateChannel.test.ts +4 -1
- package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
- package/src/comlink/controller/actions/getOrCreateController.test.ts +4 -1
- package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
- package/src/comlink/controller/comlinkControllerStore.test.ts +4 -1
- package/src/comlink/node/actions/getOrCreateNode.test.ts +9 -3
- package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
- package/src/comlink/node/actions/releaseNode.test.ts +7 -4
- package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
- package/src/comlink/node/getNodeState.test.ts +1 -1
- package/src/comlink/node/getNodeState.ts +2 -1
- package/src/config/__tests__/handles.test.ts +18 -12
- package/src/config/handles.ts +25 -7
- package/src/config/sanityConfig.ts +109 -79
- package/src/datasets/datasets.test.ts +2 -2
- package/src/datasets/datasets.ts +10 -4
- package/src/document/actions.test.ts +115 -33
- package/src/document/actions.ts +212 -15
- package/src/document/applyDocumentActions.test.ts +38 -12
- package/src/document/applyDocumentActions.ts +30 -9
- package/src/document/documentConstants.ts +7 -0
- package/src/document/documentStore.concurrency.test.ts +1306 -0
- package/src/document/documentStore.test.ts +673 -278
- package/src/document/documentStore.ts +162 -71
- package/src/document/events.test.ts +57 -2
- package/src/document/events.ts +82 -26
- package/src/document/listen.test.ts +56 -0
- package/src/document/listen.ts +74 -21
- package/src/document/listenerEventOperators.test.ts +311 -0
- package/src/document/listenerEventOperators.ts +217 -0
- package/src/document/patchOperations.test.ts +49 -2
- package/src/document/patchOperations.ts +50 -0
- package/src/document/permissions.test.ts +105 -60
- package/src/document/permissions.ts +44 -19
- package/src/document/processActions/create.ts +138 -0
- package/src/document/processActions/delete.ts +100 -0
- package/src/document/processActions/discard.ts +63 -0
- package/src/document/processActions/edit.ts +154 -0
- package/src/document/processActions/processActions.ts +218 -0
- package/src/document/processActions/publish.ts +120 -0
- package/src/document/processActions/releaseArchive.ts +77 -0
- package/src/document/processActions/releaseCreate.ts +59 -0
- package/src/document/processActions/releaseDelete.ts +65 -0
- package/src/document/processActions/releaseEdit.ts +37 -0
- package/src/document/processActions/releasePublish.ts +45 -0
- package/src/document/processActions/releaseSchedule.ts +87 -0
- package/src/document/processActions/releaseUtil.ts +31 -0
- package/src/document/processActions/shared.ts +308 -0
- package/src/document/processActions/unpublish.ts +85 -0
- package/src/document/processActions.test.ts +1129 -121
- package/src/document/reducers.test.ts +639 -64
- package/src/document/reducers.ts +187 -48
- package/src/document/resourceRules.test.ts +178 -0
- package/src/document/resourceRules.ts +117 -0
- package/src/document/sharedListener.test.ts +16 -14
- package/src/document/sharedListener.ts +24 -8
- package/src/document/util.ts +14 -0
- package/src/favorites/favorites.test.ts +5 -6
- package/src/installations/installations.test-d.ts +68 -0
- package/src/installations/installations.test.ts +62 -0
- package/src/installations/installations.ts +202 -0
- package/src/organization/organization.test-d.ts +36 -0
- package/src/organization/organization.test.ts +138 -0
- package/src/organization/organization.ts +138 -0
- package/src/organizations/organizations.test-d.ts +56 -0
- package/src/organizations/organizations.test.ts +150 -0
- package/src/organizations/organizations.ts +107 -0
- package/src/presence/bifurTransport.test.ts +46 -6
- package/src/presence/bifurTransport.ts +19 -2
- package/src/presence/presenceStore.test.ts +94 -23
- package/src/presence/presenceStore.ts +85 -29
- package/src/preview/getPreviewState.test.ts +137 -0
- package/src/preview/getPreviewState.ts +69 -0
- package/src/preview/previewProjectionUtils.test.ts +9 -22
- package/src/preview/previewProjectionUtils.ts +7 -3
- package/src/preview/resolvePreview.test.ts +64 -0
- package/src/preview/resolvePreview.ts +43 -0
- package/src/preview/types.ts +10 -0
- package/src/project/project.test-d.ts +37 -0
- package/src/project/project.test.ts +157 -12
- package/src/project/project.ts +138 -25
- package/src/projection/getProjectionState.test.ts +18 -20
- package/src/projection/getProjectionState.ts +23 -3
- package/src/projection/projectionQuery.ts +5 -5
- package/src/projection/projectionStore.test.ts +1 -1
- package/src/projection/resolveProjection.test.ts +1 -2
- package/src/projection/resolveProjection.ts +16 -0
- package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
- package/src/projection/subscribeToStateAndFetchBatches.ts +32 -23
- package/src/projection/types.ts +8 -0
- package/src/projects/projects.test-d.ts +32 -0
- package/src/projects/projects.test.ts +108 -42
- package/src/projects/projects.ts +63 -27
- package/src/query/queryStore.test.ts +259 -123
- package/src/query/queryStore.ts +78 -63
- package/src/query/reducers.test.ts +0 -42
- package/src/query/reducers.ts +2 -18
- package/src/releases/getPerspectiveState.test.ts +17 -23
- package/src/releases/getPerspectiveState.ts +8 -20
- package/src/releases/observeReleases.test.ts +127 -0
- package/src/releases/observeReleases.ts +102 -0
- package/src/releases/releasesStore.test.ts +100 -53
- package/src/releases/releasesStore.ts +69 -44
- package/src/releases/utils/sortReleases.test.ts +38 -2
- package/src/releases/utils/sortReleases.ts +15 -10
- package/src/store/createActionBinder.test.ts +87 -90
- package/src/store/createActionBinder.ts +79 -25
- package/src/store/createSanityInstance.test.ts +83 -13
- package/src/store/createSanityInstance.ts +77 -2
- package/src/store/createStateSourceAction.test.ts +64 -2
- package/src/store/createStateSourceAction.ts +39 -44
- package/src/store/createStoreInstance.test.ts +4 -2
- package/src/store/fetcherStore.test-d.ts +121 -0
- package/src/store/fetcherStore.test.ts +299 -0
- package/src/store/fetcherStore.ts +801 -0
- package/src/telemetry/environment.test.ts +119 -0
- package/src/telemetry/environment.ts +92 -0
- package/src/telemetry/events.ts +42 -0
- package/src/telemetry/initTelemetry.test.ts +432 -0
- package/src/telemetry/initTelemetry.ts +218 -0
- package/src/telemetry/telemetryManager.test.ts +327 -0
- package/src/telemetry/telemetryManager.ts +199 -0
- package/src/users/reducers.test.ts +6 -1
- package/src/users/reducers.ts +5 -6
- package/src/users/types.ts +4 -4
- package/src/users/usersStore.test.ts +16 -12
- package/src/users/usersStore.ts +5 -1
- package/src/utils/buildQuery.test.ts +14 -0
- package/src/utils/buildQuery.ts +17 -0
- package/src/utils/createFetcherStore.test.ts +7 -5
- package/src/utils/createFetcherStore.ts +8 -5
- package/src/utils/getStagingApiHost.test.ts +21 -0
- package/src/utils/getStagingApiHost.ts +14 -0
- package/src/utils/ids.test.ts +1 -29
- package/src/utils/ids.ts +0 -10
- package/src/utils/includeShape.ts +36 -0
- package/src/utils/isImportError.test.ts +72 -0
- package/src/utils/isImportError.ts +34 -0
- package/src/utils/logger.test.ts +12 -0
- package/src/utils/logger.ts +8 -3
- package/src/utils/object.test.ts +95 -0
- package/src/utils/object.ts +142 -0
- package/src/utils/setCleanupTimeout.ts +37 -0
- package/src/document/processActions.ts +0 -707
- package/src/utils/defineIntent.test.ts +0 -477
- package/src/utils/defineIntent.ts +0 -244
package/package.json
CHANGED
|
@@ -1,96 +1,97 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/sdk",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sanity SDK",
|
|
6
6
|
"keywords": [
|
|
7
|
-
"sanity",
|
|
8
|
-
"sdk",
|
|
9
|
-
"content operating system",
|
|
10
7
|
"cms",
|
|
8
|
+
"content",
|
|
9
|
+
"content operating system",
|
|
11
10
|
"headless",
|
|
12
11
|
"realtime",
|
|
13
|
-
"
|
|
12
|
+
"sanity",
|
|
13
|
+
"sdk"
|
|
14
14
|
],
|
|
15
15
|
"homepage": "https://github.com/sanity-io/sdk/tree/main/packages/core/README.md",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/sanity-io/sdk/issues"
|
|
18
18
|
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Sanity <developers@sanity.io>",
|
|
19
21
|
"repository": {
|
|
20
22
|
"type": "git",
|
|
21
23
|
"url": "git+https://github.com/sanity-io/sdk.git",
|
|
22
24
|
"directory": "packages/core"
|
|
23
25
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
27
30
|
"type": "module",
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"main": "./dist/index.js",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
28
35
|
"exports": {
|
|
29
36
|
".": {
|
|
30
37
|
"source": "./src/_exports/index.ts",
|
|
31
38
|
"import": "./dist/index.js",
|
|
32
39
|
"default": "./dist/index.js"
|
|
33
40
|
},
|
|
34
|
-
"./package.json": "./package.json"
|
|
41
|
+
"./package.json": "./package.json",
|
|
42
|
+
"./_internal": {
|
|
43
|
+
"source": "./src/_exports/_internal.ts",
|
|
44
|
+
"import": "./dist/_exports/_internal.js",
|
|
45
|
+
"default": "./dist/_exports/_internal.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
35
50
|
},
|
|
36
|
-
"main": "./dist/index.js",
|
|
37
|
-
"module": "./dist/index.js",
|
|
38
|
-
"types": "./dist/index.d.ts",
|
|
39
|
-
"files": [
|
|
40
|
-
"dist",
|
|
41
|
-
"src"
|
|
42
|
-
],
|
|
43
|
-
"browserslist": "extends @sanity/browserslist-config",
|
|
44
|
-
"prettier": "@sanity/prettier-config",
|
|
45
51
|
"dependencies": {
|
|
46
|
-
"@sanity/bifur-client": "^0.
|
|
47
|
-
"@sanity/client": "^7.
|
|
48
|
-
"@sanity/comlink": "^
|
|
52
|
+
"@sanity/bifur-client": "^1.0.0",
|
|
53
|
+
"@sanity/client": "^7.23.2",
|
|
54
|
+
"@sanity/comlink": "^4.0.1",
|
|
49
55
|
"@sanity/diff-match-patch": "^3.2.0",
|
|
50
56
|
"@sanity/diff-patch": "^6.0.0",
|
|
51
57
|
"@sanity/id-utils": "^1.0.0",
|
|
52
|
-
"@sanity/image-url": "^2.
|
|
58
|
+
"@sanity/image-url": "^2.1.1",
|
|
53
59
|
"@sanity/json-match": "^1.0.5",
|
|
54
|
-
"@sanity/message-protocol": "^0.
|
|
55
|
-
"@sanity/mutate": "^0.
|
|
56
|
-
"@sanity/
|
|
57
|
-
"
|
|
58
|
-
"
|
|
60
|
+
"@sanity/message-protocol": "^0.23.0",
|
|
61
|
+
"@sanity/mutate": "^0.18.1",
|
|
62
|
+
"@sanity/telemetry": "^1.1.0",
|
|
63
|
+
"@sanity/types": "^6.5.0",
|
|
64
|
+
"groq": "3.88.1-typegen-experimental.0",
|
|
65
|
+
"groq-js": "^2.0.0",
|
|
59
66
|
"reselect": "^5.1.1",
|
|
60
67
|
"rxjs": "^7.8.2",
|
|
61
|
-
"zustand": "^5.0.
|
|
68
|
+
"zustand": "^5.0.13"
|
|
62
69
|
},
|
|
63
70
|
"devDependencies": {
|
|
64
71
|
"@sanity/browserslist-config": "^1.0.5",
|
|
65
|
-
"@sanity/pkg-utils": "^
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"vitest": "^3.2.4",
|
|
72
|
+
"@sanity/pkg-utils": "^10.9.2",
|
|
73
|
+
"@types/node": "^24.13.3",
|
|
74
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
75
|
+
"eslint": "^10.6.0",
|
|
76
|
+
"oxfmt": "^0.58.0",
|
|
77
|
+
"rollup-plugin-visualizer": "^7.0.1",
|
|
78
|
+
"typescript": "^6.0.3",
|
|
79
|
+
"vite": "^8.1.5",
|
|
80
|
+
"vitest": "^4.1.10",
|
|
75
81
|
"@repo/config-eslint": "0.0.0",
|
|
76
82
|
"@repo/config-test": "0.0.1",
|
|
77
|
-
"@repo/package.
|
|
83
|
+
"@repo/package.config": "0.0.1",
|
|
78
84
|
"@repo/tsconfig": "0.0.1",
|
|
79
|
-
"@repo/package.
|
|
80
|
-
},
|
|
81
|
-
"engines": {
|
|
82
|
-
"node": ">=20.19"
|
|
83
|
-
},
|
|
84
|
-
"publishConfig": {
|
|
85
|
-
"access": "public"
|
|
85
|
+
"@repo/package.bundle": "3.82.0"
|
|
86
86
|
},
|
|
87
|
+
"browserslist": "extends @sanity/browserslist-config",
|
|
87
88
|
"scripts": {
|
|
88
89
|
"build": "pkg build --strict --clean --check",
|
|
89
90
|
"build:bundle": "vite build --configLoader runner --config package.bundle.ts",
|
|
90
91
|
"clean": "rimraf dist",
|
|
91
92
|
"dev": "pkg watch",
|
|
92
93
|
"docs": "typedoc --json docs/typedoc.json --tsconfig ./tsconfig.dist.json",
|
|
93
|
-
"format": "
|
|
94
|
+
"format": "oxfmt",
|
|
94
95
|
"lint": "eslint .",
|
|
95
96
|
"test": "vitest run",
|
|
96
97
|
"test:coverage": "vitest run --coverage",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export {isStudioConfig} from '../auth/authMode'
|
|
2
|
+
export {
|
|
3
|
+
type ApiErrorBody,
|
|
4
|
+
getClientErrorApiBody,
|
|
5
|
+
getClientErrorApiDescription,
|
|
6
|
+
getClientErrorApiType,
|
|
7
|
+
isProjectUserNotFoundClientError,
|
|
8
|
+
} from '../auth/utils'
|
|
9
|
+
export {PREVIEW_PROJECTION} from '../preview/previewConstants'
|
|
10
|
+
export {transformProjectionToPreview} from '../preview/previewProjectionUtils'
|
|
11
|
+
export {getQueryKey, parseQueryKey} from '../query/queryStore' // only used for memoizing in React, not needed for actual functionality
|
|
12
|
+
export {
|
|
13
|
+
type CacheTag,
|
|
14
|
+
type CacheWriter,
|
|
15
|
+
defineFetcher,
|
|
16
|
+
defineMutation,
|
|
17
|
+
type Fetcher,
|
|
18
|
+
type FetcherDefinition,
|
|
19
|
+
type FetcherSnapshot,
|
|
20
|
+
type MutationDefinition,
|
|
21
|
+
type MutationResult,
|
|
22
|
+
} from '../store/fetcherStore'
|
|
23
|
+
export {getTelemetryManager, initTelemetry, trackHookMounted} from '../telemetry/initTelemetry'
|
|
24
|
+
export {getUsersKey, parseUsersKey} from '../users/reducers' // only used for memoizing in React, not needed for actual functionality
|
|
25
|
+
export {createGroqSearchFilter} from '../utils/createGroqSearchFilter'
|
|
26
|
+
export {isDeepEqual, pickProperties} from '../utils/object'
|
package/src/_exports/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {type SanityProject as _SanityProject} from '@sanity/client'
|
|
|
5
5
|
*/
|
|
6
6
|
export type SanityProject = _SanityProject
|
|
7
7
|
|
|
8
|
+
export {checkPermissions} from '../access/checkPermissions'
|
|
9
|
+
export {type AccessResourceType} from '../access/checkPermissions'
|
|
8
10
|
export type {
|
|
9
11
|
AgentGenerateOptions,
|
|
10
12
|
AgentGenerateResult,
|
|
@@ -12,7 +14,6 @@ export type {
|
|
|
12
14
|
AgentPatchResult,
|
|
13
15
|
AgentPromptOptions,
|
|
14
16
|
AgentPromptResult,
|
|
15
|
-
AgentResourceOptions,
|
|
16
17
|
AgentTransformOptions,
|
|
17
18
|
AgentTransformResult,
|
|
18
19
|
AgentTranslateOptions,
|
|
@@ -25,6 +26,44 @@ export {
|
|
|
25
26
|
agentTransform,
|
|
26
27
|
agentTranslate,
|
|
27
28
|
} from '../agent/agentActions'
|
|
29
|
+
export {
|
|
30
|
+
application,
|
|
31
|
+
applications,
|
|
32
|
+
deleteApplication,
|
|
33
|
+
updateApplication,
|
|
34
|
+
} from '../applications/applications'
|
|
35
|
+
export {
|
|
36
|
+
type Application,
|
|
37
|
+
type ApplicationAccess,
|
|
38
|
+
type ApplicationBase,
|
|
39
|
+
type ApplicationDeployment,
|
|
40
|
+
type ApplicationInclude,
|
|
41
|
+
type ApplicationInterface,
|
|
42
|
+
type ApplicationsOptions,
|
|
43
|
+
type ApplicationsResponse,
|
|
44
|
+
type ApplicationStudioConfig,
|
|
45
|
+
type ApplicationVisibility,
|
|
46
|
+
type ApplicationWorkspace,
|
|
47
|
+
type DeleteApplicationInput,
|
|
48
|
+
type DeletedResult,
|
|
49
|
+
type UpdateApplicationInput,
|
|
50
|
+
} from '../applications/applications'
|
|
51
|
+
export {
|
|
52
|
+
createUserApplication,
|
|
53
|
+
deleteUserApplication,
|
|
54
|
+
updateUserApplication,
|
|
55
|
+
userApplication,
|
|
56
|
+
userApplications,
|
|
57
|
+
} from '../applications/userApplications'
|
|
58
|
+
export {
|
|
59
|
+
type CreateUserApplicationInput,
|
|
60
|
+
type DeleteUserApplicationInput,
|
|
61
|
+
type UpdateUserApplicationInput,
|
|
62
|
+
type UserApplication,
|
|
63
|
+
type UserApplicationDeployment,
|
|
64
|
+
type UserApplicationsOptions,
|
|
65
|
+
type UserApplicationWriteFields,
|
|
66
|
+
} from '../applications/userApplications'
|
|
28
67
|
export {isStudioConfig} from '../auth/authMode'
|
|
29
68
|
export {AuthStateType} from '../auth/authStateType'
|
|
30
69
|
export {
|
|
@@ -72,9 +111,10 @@ export {
|
|
|
72
111
|
} from '../comlink/types'
|
|
73
112
|
export {type AuthConfig, type AuthProvider} from '../config/authConfig'
|
|
74
113
|
export {
|
|
114
|
+
createDatasetHandle,
|
|
75
115
|
createDocumentHandle,
|
|
76
116
|
createDocumentTypeHandle,
|
|
77
|
-
|
|
117
|
+
createProjectHandle,
|
|
78
118
|
} from '../config/handles'
|
|
79
119
|
export {
|
|
80
120
|
configureLogging,
|
|
@@ -87,37 +127,64 @@ export {
|
|
|
87
127
|
} from '../config/loggingConfig'
|
|
88
128
|
export {
|
|
89
129
|
type CanvasResource,
|
|
130
|
+
type CanvasSource,
|
|
131
|
+
type DatasetHandle,
|
|
90
132
|
type DatasetResource,
|
|
91
|
-
|
|
133
|
+
type DatasetSource,
|
|
92
134
|
type DocumentHandle,
|
|
93
135
|
type DocumentResource,
|
|
136
|
+
type DocumentSource,
|
|
94
137
|
type DocumentTypeHandle,
|
|
95
138
|
isCanvasResource,
|
|
139
|
+
isCanvasSource,
|
|
96
140
|
isDatasetResource,
|
|
141
|
+
isDatasetSource,
|
|
97
142
|
isMediaLibraryResource,
|
|
143
|
+
isMediaLibrarySource,
|
|
98
144
|
type MediaLibraryResource,
|
|
145
|
+
type MediaLibrarySource,
|
|
99
146
|
type PerspectiveHandle,
|
|
147
|
+
type ProjectHandle,
|
|
148
|
+
type ReleaseHandle,
|
|
100
149
|
type ReleasePerspective,
|
|
101
|
-
type ResourceHandle,
|
|
102
150
|
type SanityConfig,
|
|
103
151
|
type StudioConfig,
|
|
104
152
|
type TokenSource,
|
|
105
153
|
} from '../config/sanityConfig'
|
|
106
154
|
export {getDatasetsState, resolveDatasets} from '../datasets/datasets'
|
|
107
155
|
export {
|
|
156
|
+
type Action,
|
|
157
|
+
archiveRelease,
|
|
158
|
+
type ArchiveReleaseAction,
|
|
108
159
|
createDocument,
|
|
109
160
|
type CreateDocumentAction,
|
|
161
|
+
createRelease,
|
|
162
|
+
type CreateReleaseAction,
|
|
110
163
|
deleteDocument,
|
|
111
164
|
type DeleteDocumentAction,
|
|
165
|
+
deleteRelease,
|
|
166
|
+
type DeleteReleaseAction,
|
|
112
167
|
discardDocument,
|
|
113
168
|
type DiscardDocumentAction,
|
|
114
169
|
type DocumentAction,
|
|
115
170
|
editDocument,
|
|
116
171
|
type EditDocumentAction,
|
|
172
|
+
type EditDocumentOptions,
|
|
173
|
+
editRelease,
|
|
174
|
+
type EditReleaseAction,
|
|
117
175
|
publishDocument,
|
|
118
176
|
type PublishDocumentAction,
|
|
177
|
+
publishRelease,
|
|
178
|
+
type PublishReleaseAction,
|
|
179
|
+
type ReleaseAction,
|
|
180
|
+
scheduleRelease,
|
|
181
|
+
type ScheduleReleaseAction,
|
|
182
|
+
unarchiveRelease,
|
|
183
|
+
type UnarchiveReleaseAction,
|
|
119
184
|
unpublishDocument,
|
|
120
185
|
type UnpublishDocumentAction,
|
|
186
|
+
unscheduleRelease,
|
|
187
|
+
type UnscheduleReleaseAction,
|
|
121
188
|
} from '../document/actions'
|
|
122
189
|
export {
|
|
123
190
|
type ActionsResult,
|
|
@@ -141,13 +208,37 @@ export {
|
|
|
141
208
|
type DocumentEditedEvent,
|
|
142
209
|
type DocumentEvent,
|
|
143
210
|
type DocumentPublishedEvent,
|
|
211
|
+
type DocumentRemotePatchesEvent,
|
|
212
|
+
type DocumentTransactionSubmissionResult,
|
|
144
213
|
type DocumentUnpublishedEvent,
|
|
145
214
|
type TransactionAcceptedEvent,
|
|
146
215
|
type TransactionRevertedEvent,
|
|
147
216
|
} from '../document/events'
|
|
217
|
+
export {type JsonMatch} from '../document/patchOperations'
|
|
148
218
|
export {type DocumentPermissionsResult, type PermissionDeniedReason} from '../document/permissions'
|
|
219
|
+
export {getReleaseDocumentId} from '../document/processActions/releaseUtil'
|
|
149
220
|
export type {FavoriteStatusResponse} from '../favorites/favorites'
|
|
150
221
|
export {getFavoritesState, resolveFavoritesState} from '../favorites/favorites'
|
|
222
|
+
export {installation, installations} from '../installations/installations'
|
|
223
|
+
export {
|
|
224
|
+
type Installation,
|
|
225
|
+
type InstallationAccess,
|
|
226
|
+
type InstallationActiveConfig,
|
|
227
|
+
type InstallationBase,
|
|
228
|
+
type InstallationInclude,
|
|
229
|
+
type InstallationInterface,
|
|
230
|
+
type InstallationsOptions,
|
|
231
|
+
type InstallationsResponse,
|
|
232
|
+
} from '../installations/installations'
|
|
233
|
+
export {organization} from '../organization/organization'
|
|
234
|
+
export {
|
|
235
|
+
type Organization,
|
|
236
|
+
type OrganizationBase,
|
|
237
|
+
type OrganizationMember,
|
|
238
|
+
type OrganizationOptions,
|
|
239
|
+
} from '../organization/organization'
|
|
240
|
+
export {organizations} from '../organizations/organizations'
|
|
241
|
+
export {type Organizations, type OrganizationsOptions} from '../organizations/organizations'
|
|
151
242
|
export {getPresence} from '../presence/presenceStore'
|
|
152
243
|
export type {
|
|
153
244
|
DisconnectEvent,
|
|
@@ -157,15 +248,32 @@ export type {
|
|
|
157
248
|
TransportEvent,
|
|
158
249
|
UserPresence,
|
|
159
250
|
} from '../presence/types'
|
|
251
|
+
export {getPreviewState, type GetPreviewStateOptions} from '../preview/getPreviewState'
|
|
160
252
|
export {PREVIEW_PROJECTION} from '../preview/previewConstants'
|
|
161
253
|
export {transformProjectionToPreview} from '../preview/previewProjectionUtils'
|
|
162
|
-
export
|
|
254
|
+
export {resolvePreview, type ResolvePreviewOptions} from '../preview/resolvePreview'
|
|
255
|
+
export type {
|
|
256
|
+
PreviewMedia,
|
|
257
|
+
PreviewQueryResult,
|
|
258
|
+
PreviewStoreState,
|
|
259
|
+
PreviewValue,
|
|
260
|
+
ValuePending,
|
|
261
|
+
} from '../preview/types'
|
|
163
262
|
export {type OrgVerificationResult} from '../project/organizationVerification'
|
|
164
|
-
export {
|
|
263
|
+
export {project} from '../project/project'
|
|
264
|
+
export {
|
|
265
|
+
type Project,
|
|
266
|
+
type ProjectBase,
|
|
267
|
+
type ProjectMember,
|
|
268
|
+
type ProjectMemberRole,
|
|
269
|
+
type ProjectMetadata,
|
|
270
|
+
type ProjectOptions,
|
|
271
|
+
} from '../project/project'
|
|
165
272
|
export {getProjectionState} from '../projection/getProjectionState'
|
|
166
273
|
export {resolveProjection} from '../projection/resolveProjection'
|
|
167
|
-
export {type ProjectionValuePending} from '../projection/types'
|
|
168
|
-
export {
|
|
274
|
+
export {type ProjectionValuePending, type ValidProjection} from '../projection/types'
|
|
275
|
+
export {projects} from '../projects/projects'
|
|
276
|
+
export {type ProjectsOptions} from '../projects/projects'
|
|
169
277
|
export {
|
|
170
278
|
getQueryKey,
|
|
171
279
|
getQueryState,
|
|
@@ -174,8 +282,8 @@ export {
|
|
|
174
282
|
resolveQuery,
|
|
175
283
|
} from '../query/queryStore'
|
|
176
284
|
export {getPerspectiveState} from '../releases/getPerspectiveState'
|
|
177
|
-
export type {
|
|
178
|
-
export {getActiveReleasesState} from '../releases/releasesStore'
|
|
285
|
+
export type {ReleaseState} from '../releases/releasesStore'
|
|
286
|
+
export {getActiveReleasesState, getAllReleasesState} from '../releases/releasesStore'
|
|
179
287
|
export {createSanityInstance, type SanityInstance} from '../store/createSanityInstance'
|
|
180
288
|
export {type Selector, type StateSource} from '../store/createStateSourceAction'
|
|
181
289
|
export {getUsersKey, parseUsersKey} from '../users/reducers'
|
|
@@ -200,9 +308,10 @@ export {
|
|
|
200
308
|
} from '../users/usersStore'
|
|
201
309
|
export {type FetcherStore, type FetcherStoreState} from '../utils/createFetcherStore'
|
|
202
310
|
export {createGroqSearchFilter} from '../utils/createGroqSearchFilter'
|
|
203
|
-
export {defineIntent, type Intent, type IntentFilter} from '../utils/defineIntent'
|
|
204
311
|
export {getCorsErrorProjectId} from '../utils/getCorsErrorProjectId'
|
|
312
|
+
export {isImportError} from '../utils/isImportError'
|
|
205
313
|
export {CORE_SDK_VERSION} from '../version'
|
|
314
|
+
export type {ReleaseDocument} from '@sanity/client'
|
|
206
315
|
export {
|
|
207
316
|
getIndexForKey,
|
|
208
317
|
getPathDepth,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {type SanityClient} from '@sanity/client'
|
|
2
|
+
import {of} from 'rxjs'
|
|
3
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'
|
|
4
|
+
|
|
5
|
+
import {getClientState} from '../client/clientStore'
|
|
6
|
+
import {createSanityInstance, type SanityInstance} from '../store/createSanityInstance'
|
|
7
|
+
import {type StateSource} from '../store/createStateSourceAction'
|
|
8
|
+
import {checkPermissions} from './checkPermissions'
|
|
9
|
+
|
|
10
|
+
vi.mock('../client/clientStore')
|
|
11
|
+
|
|
12
|
+
describe('checkPermissions', () => {
|
|
13
|
+
let instance: SanityInstance
|
|
14
|
+
const request = vi.fn()
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
instance = createSanityInstance({projectId: 'p', dataset: 'd'})
|
|
18
|
+
request.mockReset()
|
|
19
|
+
vi.mocked(getClientState).mockReturnValue({
|
|
20
|
+
observable: of({observable: {request}} as unknown as SanityClient),
|
|
21
|
+
} as StateSource<SanityClient>)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
instance.dispose()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('checks permissions on the global client and unwraps the data envelope', async () => {
|
|
29
|
+
request.mockReturnValue(of({data: {'sanity.project.read': true}}))
|
|
30
|
+
|
|
31
|
+
const result = await checkPermissions.resolveState(instance, 'project', 'p1', [
|
|
32
|
+
'sanity.project.read',
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
expect(result).toEqual({'sanity.project.read': true})
|
|
36
|
+
expect(getClientState).toHaveBeenCalledWith(instance, {
|
|
37
|
+
apiVersion: 'v2025-07-11',
|
|
38
|
+
scope: 'global',
|
|
39
|
+
})
|
|
40
|
+
expect(request).toHaveBeenCalledWith({
|
|
41
|
+
uri: '/access/project/p1/user-permissions/me/check',
|
|
42
|
+
query: {permissions: ['sanity.project.read']},
|
|
43
|
+
tag: 'access.check',
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('does not create distinct cache entries for different permission orderings', async () => {
|
|
48
|
+
request.mockReturnValue(of({data: {a: true, b: false}}))
|
|
49
|
+
|
|
50
|
+
await checkPermissions.resolveState(instance, 'organization', 'org1', ['b', 'a'])
|
|
51
|
+
await checkPermissions.resolveState(instance, 'organization', 'org1', ['a', 'b'])
|
|
52
|
+
|
|
53
|
+
expect(request).toHaveBeenCalledTimes(1)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {map, switchMap} from 'rxjs'
|
|
2
|
+
|
|
3
|
+
import {getClientState} from '../client/clientStore'
|
|
4
|
+
import {defineFetcher} from '../store/fetcherStore'
|
|
5
|
+
|
|
6
|
+
const API_VERSION = 'v2025-07-11'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The resource types the Access API can scope a permission check to.
|
|
10
|
+
*
|
|
11
|
+
* @see https://www.sanity.io/docs/http-reference/access-api
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export type AccessResourceType =
|
|
15
|
+
| 'organization'
|
|
16
|
+
| 'project'
|
|
17
|
+
| 'media-library'
|
|
18
|
+
| 'canvas'
|
|
19
|
+
| 'dashboard'
|
|
20
|
+
| 'view'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fetcher checking whether the current user holds the given permissions on a
|
|
24
|
+
* resource (`GET /access/:resourceType/:resourceId/user-permissions/me/check`),
|
|
25
|
+
* on the shared fetcher cache. Resolves to a map of each requested permission
|
|
26
|
+
* to whether the user has it. The key sorts the permission list, so permission
|
|
27
|
+
* order doesn't create distinct cache entries.
|
|
28
|
+
*
|
|
29
|
+
* @see https://www.sanity.io/docs/http-reference/access-api
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export const checkPermissions = defineFetcher<
|
|
33
|
+
[resourceType: AccessResourceType, resourceId: string, permissions: string[]],
|
|
34
|
+
Record<string, boolean>
|
|
35
|
+
>({
|
|
36
|
+
name: 'checkPermissions',
|
|
37
|
+
getKey: (_instance, resourceType, resourceId, permissions) =>
|
|
38
|
+
`${resourceType}:${resourceId}:${[...permissions].sort().join(',')}`,
|
|
39
|
+
fetch: (instance) => (resourceType, resourceId, permissions) =>
|
|
40
|
+
getClientState(instance, {apiVersion: API_VERSION, scope: 'global'}).observable.pipe(
|
|
41
|
+
switchMap((client) =>
|
|
42
|
+
client.observable
|
|
43
|
+
.request<{data: Record<string, boolean>}>({
|
|
44
|
+
uri: `/access/${resourceType}/${resourceId}/user-permissions/me/check`,
|
|
45
|
+
query: {permissions},
|
|
46
|
+
tag: 'access.check',
|
|
47
|
+
})
|
|
48
|
+
.pipe(map((response) => response.data)),
|
|
49
|
+
),
|
|
50
|
+
),
|
|
51
|
+
tags: (_data, resourceType, resourceId) => [
|
|
52
|
+
{type: 'access', id: `${resourceType}:${resourceId}`},
|
|
53
|
+
],
|
|
54
|
+
})
|
|
@@ -11,16 +11,13 @@ import {
|
|
|
11
11
|
} from './agentActions'
|
|
12
12
|
|
|
13
13
|
let mockClient: any
|
|
14
|
-
const mockGetClientState = vi.fn()
|
|
15
14
|
|
|
16
15
|
vi.mock('../client/clientStore', () => {
|
|
17
16
|
return {
|
|
18
|
-
getClientState: (
|
|
17
|
+
getClientState: () => ({observable: of(mockClient)}),
|
|
19
18
|
}
|
|
20
19
|
})
|
|
21
20
|
|
|
22
|
-
const testResource = {projectId: 'p', dataset: 'd'}
|
|
23
|
-
|
|
24
21
|
describe('agent actions', () => {
|
|
25
22
|
beforeEach(() => {
|
|
26
23
|
mockClient = {
|
|
@@ -40,86 +37,45 @@ describe('agent actions', () => {
|
|
|
40
37
|
},
|
|
41
38
|
},
|
|
42
39
|
}
|
|
43
|
-
mockGetClientState.mockReturnValue({observable: of(mockClient)})
|
|
44
40
|
})
|
|
45
41
|
|
|
46
|
-
it('agentGenerate
|
|
42
|
+
it('agentGenerate returns observable from client', async () => {
|
|
47
43
|
mockClient.observable.agent.action.generate.mockReturnValue(of('gen'))
|
|
48
|
-
const instance = {config: {}} as any
|
|
49
|
-
const value = await firstValueFrom(
|
|
50
|
-
agentGenerate(instance, {foo: 'bar', resource: testResource} as any),
|
|
51
|
-
)
|
|
44
|
+
const instance = {config: {projectId: 'p', dataset: 'd'}} as any
|
|
45
|
+
const value = await firstValueFrom(agentGenerate(instance, {foo: 'bar'} as any))
|
|
52
46
|
expect(value).toBe('gen')
|
|
53
|
-
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
54
|
-
apiVersion: 'vX',
|
|
55
|
-
resource: testResource,
|
|
56
|
-
})
|
|
57
47
|
expect(mockClient.observable.agent.action.generate).toHaveBeenCalledWith({foo: 'bar'})
|
|
58
48
|
})
|
|
59
49
|
|
|
60
|
-
it('agentTransform
|
|
50
|
+
it('agentTransform returns observable from client', async () => {
|
|
61
51
|
mockClient.observable.agent.action.transform.mockReturnValue(of('xform'))
|
|
62
|
-
const instance = {config: {}} as any
|
|
63
|
-
const value = await firstValueFrom(
|
|
64
|
-
agentTransform(instance, {a: 1, resource: testResource} as any),
|
|
65
|
-
)
|
|
52
|
+
const instance = {config: {projectId: 'p', dataset: 'd'}} as any
|
|
53
|
+
const value = await firstValueFrom(agentTransform(instance, {a: 1} as any))
|
|
66
54
|
expect(value).toBe('xform')
|
|
67
|
-
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
68
|
-
apiVersion: 'vX',
|
|
69
|
-
resource: testResource,
|
|
70
|
-
})
|
|
71
55
|
expect(mockClient.observable.agent.action.transform).toHaveBeenCalledWith({a: 1})
|
|
72
56
|
})
|
|
73
57
|
|
|
74
|
-
it('agentTranslate
|
|
58
|
+
it('agentTranslate returns observable from client', async () => {
|
|
75
59
|
mockClient.observable.agent.action.translate.mockReturnValue(of('xlate'))
|
|
76
|
-
const instance = {config: {}} as any
|
|
77
|
-
const value = await firstValueFrom(
|
|
78
|
-
agentTranslate(instance, {b: 2, resource: testResource} as any),
|
|
79
|
-
)
|
|
60
|
+
const instance = {config: {projectId: 'p', dataset: 'd'}} as any
|
|
61
|
+
const value = await firstValueFrom(agentTranslate(instance, {b: 2} as any))
|
|
80
62
|
expect(value).toBe('xlate')
|
|
81
|
-
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
82
|
-
apiVersion: 'vX',
|
|
83
|
-
resource: testResource,
|
|
84
|
-
})
|
|
85
63
|
expect(mockClient.observable.agent.action.translate).toHaveBeenCalledWith({b: 2})
|
|
86
64
|
})
|
|
87
65
|
|
|
88
|
-
it('agentPrompt
|
|
66
|
+
it('agentPrompt wraps promise into observable', async () => {
|
|
89
67
|
mockClient.agent.action.prompt.mockResolvedValue('prompted')
|
|
90
|
-
const instance = {config: {}} as any
|
|
91
|
-
const value = await firstValueFrom(
|
|
92
|
-
agentPrompt(instance, {p: true, resource: testResource} as any),
|
|
93
|
-
)
|
|
68
|
+
const instance = {config: {projectId: 'p', dataset: 'd'}} as any
|
|
69
|
+
const value = await firstValueFrom(agentPrompt(instance, {p: true} as any))
|
|
94
70
|
expect(value).toBe('prompted')
|
|
95
|
-
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
96
|
-
apiVersion: 'vX',
|
|
97
|
-
resource: testResource,
|
|
98
|
-
})
|
|
99
71
|
expect(mockClient.agent.action.prompt).toHaveBeenCalledWith({p: true})
|
|
100
72
|
})
|
|
101
73
|
|
|
102
|
-
it('agentPatch
|
|
74
|
+
it('agentPatch wraps promise into observable', async () => {
|
|
103
75
|
mockClient.agent.action.patch.mockResolvedValue('patched')
|
|
104
|
-
const instance = {config: {}} as any
|
|
105
|
-
const value = await firstValueFrom(
|
|
106
|
-
agentPatch(instance, {q: false, resource: testResource} as any),
|
|
107
|
-
)
|
|
76
|
+
const instance = {config: {projectId: 'p', dataset: 'd'}} as any
|
|
77
|
+
const value = await firstValueFrom(agentPatch(instance, {q: false} as any))
|
|
108
78
|
expect(value).toBe('patched')
|
|
109
|
-
expect(mockGetClientState).toHaveBeenCalledWith(instance, {
|
|
110
|
-
apiVersion: 'vX',
|
|
111
|
-
resource: testResource,
|
|
112
|
-
})
|
|
113
79
|
expect(mockClient.agent.action.patch).toHaveBeenCalledWith({q: false})
|
|
114
80
|
})
|
|
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
|
-
})
|
|
125
81
|
})
|