@sanity/sdk 3.0.0-rc.0 → 3.0.0-rc.2
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 +12 -0
- package/dist/_exports/_internal.d.ts +163 -0
- package/dist/_exports/_internal.d.ts.map +1 -0
- package/dist/_exports/_internal.js +332 -0
- package/dist/_exports/_internal.js.map +1 -0
- package/dist/_exports/agent.d.ts +65 -0
- package/dist/_exports/agent.d.ts.map +1 -0
- package/dist/_exports/agent.js +71 -0
- package/dist/_exports/agent.js.map +1 -0
- package/dist/_exports/comlink.d.ts +118 -0
- package/dist/_exports/comlink.d.ts.map +1 -0
- package/dist/_exports/comlink.js +69 -0
- package/dist/_exports/comlink.js.map +1 -0
- package/dist/authStore-CtE9bLHW.js +754 -0
- package/dist/authStore-CtE9bLHW.js.map +1 -0
- package/dist/authStore-DKFX8fn7.d.ts +3179 -0
- package/dist/authStore-DKFX8fn7.d.ts.map +1 -0
- package/dist/clientStore-BtE2-q2i.js +90 -0
- package/dist/clientStore-BtE2-q2i.js.map +1 -0
- package/dist/createSanityInstance-DUI1bGIg.d.ts +278 -0
- package/dist/createSanityInstance-DUI1bGIg.d.ts.map +1 -0
- package/dist/createStateSourceAction-BOKtqFNm.js +300 -0
- package/dist/createStateSourceAction-BOKtqFNm.js.map +1 -0
- package/dist/getEnv-D5RGkQLu.js +8 -0
- package/dist/getEnv-D5RGkQLu.js.map +1 -0
- package/dist/getNodeState-CR3__B2D.js +67 -0
- package/dist/getNodeState-CR3__B2D.js.map +1 -0
- package/dist/index.d.ts +3 -2332
- package/dist/index.js +4171 -4332
- package/dist/index.js.map +1 -1
- package/dist/logger-DAtJb5RQ.js +173 -0
- package/dist/logger-DAtJb5RQ.js.map +1 -0
- package/dist/object-CxXlSVg7.js +83 -0
- package/dist/object-CxXlSVg7.js.map +1 -0
- package/dist/queryStore-DPf9sN3V.js +1346 -0
- package/dist/queryStore-DPf9sN3V.js.map +1 -0
- package/dist/rolldown-runtime-vyAXikos.js +9 -0
- package/dist/setCleanupTimeout-BiM6q1KF.js +31 -0
- package/dist/setCleanupTimeout-BiM6q1KF.js.map +1 -0
- package/dist/telemetryManager-Dq_qCkeI.js +127 -0
- package/dist/telemetryManager-Dq_qCkeI.js.map +1 -0
- package/dist/version-BChjsi4u.js +9 -0
- package/dist/version-BChjsi4u.js.map +1 -0
- package/package.json +47 -52
- package/src/_exports/_internal.ts +27 -0
- package/src/_exports/agent.ts +19 -0
- package/src/_exports/comlink.ts +16 -0
- package/src/_exports/index.ts +125 -64
- 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 +88 -0
- package/src/applications/applications.test.ts +130 -0
- package/src/applications/applications.ts +367 -0
- package/src/auth/authLogger.ts +30 -0
- package/src/auth/authStore.test.ts +194 -13
- package/src/auth/authStore.ts +58 -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/comments/addonDatasetStore.test.ts +215 -0
- package/src/comments/addonDatasetStore.ts +249 -0
- package/src/comments/buildCommentThreads.test.ts +83 -0
- package/src/comments/buildCommentThreads.ts +54 -0
- package/src/comments/commentActions.test.ts +540 -0
- package/src/comments/commentActions.ts +555 -0
- package/src/comments/commentFieldPath.test.ts +40 -0
- package/src/comments/commentFieldPath.ts +44 -0
- package/src/comments/commentsConstants.ts +80 -0
- package/src/comments/commentsStore.test.ts +419 -0
- package/src/comments/commentsStore.ts +483 -0
- package/src/comments/normalizeComment.test.ts +116 -0
- package/src/comments/normalizeComment.ts +45 -0
- package/src/comments/observeComments.test.ts +193 -0
- package/src/comments/observeComments.ts +113 -0
- package/src/comments/reducers.test.ts +277 -0
- package/src/comments/reducers.ts +316 -0
- package/src/comments/types.ts +249 -0
- package/src/comments/weakenReferences.test.ts +47 -0
- package/src/comments/weakenReferences.ts +29 -0
- package/src/config/__tests__/handles.test.ts +18 -12
- package/src/config/handles.ts +25 -7
- package/src/config/sanityConfig.ts +40 -82
- 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 +35 -13
- package/src/document/applyDocumentActions.ts +30 -9
- package/src/document/documentConstants.ts +15 -0
- package/src/document/documentStore.concurrency.test.ts +1306 -0
- package/src/document/documentStore.test.ts +753 -273
- package/src/document/documentStore.ts +197 -75
- 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 +76 -2
- package/src/document/patchOperations.ts +60 -1
- package/src/document/permissions.test.ts +107 -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 +772 -64
- package/src/document/reducers.ts +205 -51
- 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.test.ts +46 -0
- package/src/document/util.ts +50 -0
- package/src/favorites/favorites.test.ts +5 -6
- package/src/installations/installations.test-d.ts +73 -0
- package/src/installations/installations.test.ts +62 -0
- package/src/installations/installations.ts +206 -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 +201 -9
- package/src/presence/bifurTransport.ts +98 -14
- package/src/presence/paths.test.ts +70 -0
- package/src/presence/paths.ts +41 -0
- package/src/presence/presenceStore.test.ts +915 -24
- package/src/presence/presenceStore.ts +576 -104
- package/src/presence/types.ts +175 -3
- package/src/preview/previewProjectionUtils.test.ts +9 -22
- package/src/preview/previewProjectionUtils.ts +7 -3
- package/src/preview/types.ts +0 -15
- 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 -9
- 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/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 +85 -69
- 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 +109 -90
- package/src/store/createActionBinder.ts +36 -28
- package/src/store/createSanityInstance.test.ts +15 -13
- package/src/store/createSanityInstance.ts +14 -2
- package/src/store/createStateSourceAction.test.ts +64 -2
- package/src/store/createStateSourceAction.ts +38 -43
- 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 +3 -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
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import {switchMap} from 'rxjs'
|
|
2
|
+
|
|
3
|
+
import {getClientState} from '../client/clientStore'
|
|
4
|
+
import {defineFetcher, defineMutation} from '../store/fetcherStore'
|
|
5
|
+
import {buildQuery} from '../utils/buildQuery'
|
|
6
|
+
import {type Included, type IncludesAny} from '../utils/includeShape'
|
|
7
|
+
|
|
8
|
+
// The Applications API is currently only available on vX.
|
|
9
|
+
const API_VERSION = 'vX'
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Related data the Applications API can embed in a response. `interfaces`,
|
|
13
|
+
* `workspaces` and `access` are children of the active deployment and are
|
|
14
|
+
* embedded under {@link Application.activeDeployment}; `config.studio` and
|
|
15
|
+
* `config.mfManifest` are embedded under {@link Application.config}.
|
|
16
|
+
*
|
|
17
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export type ApplicationInclude =
|
|
21
|
+
| 'interfaces'
|
|
22
|
+
| 'workspaces'
|
|
23
|
+
| 'access'
|
|
24
|
+
| 'config.studio'
|
|
25
|
+
| 'config.mfManifest'
|
|
26
|
+
| 'activeDeployment'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An interface exposed by a deployment, embedded when `interfaces` is included.
|
|
30
|
+
*
|
|
31
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export interface ApplicationInterface {
|
|
35
|
+
id: string
|
|
36
|
+
type: 'app' | 'worker' | 'asset_source' | 'panel'
|
|
37
|
+
name: string
|
|
38
|
+
title: string
|
|
39
|
+
version: string
|
|
40
|
+
/** Module federation module ID; resolved from the host mf-manifest at runtime */
|
|
41
|
+
moduleId: string
|
|
42
|
+
metadata: {group?: string; priority?: number} | null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A studio workspace of a deployment, embedded when `workspaces` is included.
|
|
47
|
+
* Studio applications only.
|
|
48
|
+
*
|
|
49
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export interface ApplicationWorkspace {
|
|
53
|
+
id: string
|
|
54
|
+
name: string
|
|
55
|
+
title: string | null
|
|
56
|
+
subtitle: string | null
|
|
57
|
+
projectId: string
|
|
58
|
+
dataset: string
|
|
59
|
+
schemaDescriptorId: string | null
|
|
60
|
+
basePath: string | null
|
|
61
|
+
/** Sanitized SVG icon markup */
|
|
62
|
+
icon: string | null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A resource an application accesses, embedded when `access` is included.
|
|
67
|
+
*
|
|
68
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export interface ApplicationAccess {
|
|
72
|
+
id: string
|
|
73
|
+
resourceType: 'datasets' | 'canvases' | 'dashboards' | 'media-libraries'
|
|
74
|
+
resourceId: string
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Studio configuration, embedded under `config` when `config.studio` is included.
|
|
79
|
+
*
|
|
80
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
export interface ApplicationStudioConfig {
|
|
84
|
+
projectId: string
|
|
85
|
+
/** Release channel (`next`, `stable`, `latest`) or a pinned semver; null if unset */
|
|
86
|
+
autoUpdatingVersion: string | null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The active deployment as embedded under {@link Application.activeDeployment}.
|
|
91
|
+
* Its `interfaces`, `workspaces` and `access` children are each present only
|
|
92
|
+
* when the matching {@link ApplicationInclude} token was requested. `workspaces`
|
|
93
|
+
* is omitted (not `null`) for non-studio applications even when requested.
|
|
94
|
+
*
|
|
95
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export type ApplicationDeployment<Include extends ApplicationInclude = never> = {
|
|
99
|
+
id: string
|
|
100
|
+
applicationId: string
|
|
101
|
+
size: number | null
|
|
102
|
+
version: string | null
|
|
103
|
+
isAutoUpdating: boolean | null
|
|
104
|
+
isActiveDeployment: boolean
|
|
105
|
+
deployedBy: string | null
|
|
106
|
+
createdAt: string
|
|
107
|
+
updatedAt: string
|
|
108
|
+
} & Included<ApplicationInclude, 'interfaces', Include, {interfaces: ApplicationInterface[]}> &
|
|
109
|
+
Included<ApplicationInclude, 'workspaces', Include, {workspaces?: ApplicationWorkspace[]}> &
|
|
110
|
+
Included<ApplicationInclude, 'access', Include, {access: ApplicationAccess[]}>
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The always-present fields of an org-owned application returned by the
|
|
114
|
+
* Applications API (`/applications`), before any {@link ApplicationInclude}.
|
|
115
|
+
*
|
|
116
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export interface ApplicationBase {
|
|
120
|
+
id: string
|
|
121
|
+
type: 'studio' | 'coreApp'
|
|
122
|
+
title: string
|
|
123
|
+
/** Stable, immutable identity, distinct from the mutable `slug` address. */
|
|
124
|
+
name: string
|
|
125
|
+
/** Qualified, globally-unique handle: `sanity/<name>` for singletons, `<organizationId>/<name>` otherwise. */
|
|
126
|
+
reference: string
|
|
127
|
+
icon: string | null
|
|
128
|
+
isSingleton: boolean
|
|
129
|
+
visibility: 'default' | 'unlisted' | 'disabled'
|
|
130
|
+
slug: string | null
|
|
131
|
+
externalUrl: string | null
|
|
132
|
+
organizationId: string
|
|
133
|
+
createdAt: string
|
|
134
|
+
updatedAt: string
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Requesting any of these tokens forces the deployment summary into the response.
|
|
138
|
+
type DeploymentToken = 'activeDeployment' | 'interfaces' | 'workspaces' | 'access'
|
|
139
|
+
|
|
140
|
+
// `config` is present when either config child was requested; each child is
|
|
141
|
+
// gated on its own token.
|
|
142
|
+
type ApplicationConfigShape<Include extends ApplicationInclude> = Included<
|
|
143
|
+
ApplicationInclude,
|
|
144
|
+
'config.studio',
|
|
145
|
+
Include,
|
|
146
|
+
{config: {studio: ApplicationStudioConfig}}
|
|
147
|
+
> &
|
|
148
|
+
Included<ApplicationInclude, 'config.mfManifest', Include, {config: {mfManifest: unknown}}>
|
|
149
|
+
|
|
150
|
+
// `activeDeployment` is present when any deployment-related token was requested;
|
|
151
|
+
// a wide include array makes it optional.
|
|
152
|
+
type ApplicationDeploymentShape<Include extends ApplicationInclude> = [ApplicationInclude] extends [
|
|
153
|
+
Include,
|
|
154
|
+
]
|
|
155
|
+
? {activeDeployment?: ApplicationDeployment<Include> | null}
|
|
156
|
+
: IncludesAny<Include, DeploymentToken> extends true
|
|
157
|
+
? {activeDeployment: ApplicationDeployment<Include> | null}
|
|
158
|
+
: unknown
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* An org-owned application as returned by the Applications API
|
|
162
|
+
* (`/applications`). `config` and `activeDeployment` (with its
|
|
163
|
+
* `interfaces`/`workspaces`/`access` children) are present only when the
|
|
164
|
+
* corresponding {@link ApplicationInclude} tokens were requested.
|
|
165
|
+
*
|
|
166
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
167
|
+
* @public
|
|
168
|
+
*/
|
|
169
|
+
export type Application<Include extends ApplicationInclude = never> = ApplicationBase &
|
|
170
|
+
ApplicationConfigShape<Include> &
|
|
171
|
+
ApplicationDeploymentShape<Include>
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Options for listing an organization's applications.
|
|
175
|
+
*
|
|
176
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
177
|
+
* @public
|
|
178
|
+
*/
|
|
179
|
+
export interface ApplicationsOptions<Include extends ApplicationInclude = ApplicationInclude> {
|
|
180
|
+
organizationId: string
|
|
181
|
+
/** Filter by application type */
|
|
182
|
+
type?: string
|
|
183
|
+
include?: Include[]
|
|
184
|
+
/** Page size (1-100, default 50), or `'none'` to disable pagination */
|
|
185
|
+
limit?: number | 'none'
|
|
186
|
+
/** Cursor from a previous response's `nextCursor` */
|
|
187
|
+
cursor?: string
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The cursor-paginated envelope returned by `GET /applications`.
|
|
192
|
+
*
|
|
193
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
196
|
+
export interface ApplicationsResponse<Include extends ApplicationInclude = never> {
|
|
197
|
+
nextCursor: string | null
|
|
198
|
+
data: Application<Include>[]
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** The API takes `include` as a comma-separated list; sorted so key and query agree */
|
|
202
|
+
function serializeInclude(include: ApplicationInclude[] | undefined): string | undefined {
|
|
203
|
+
return include?.length ? [...include].sort().join(',') : undefined
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Fetcher for an organization's applications (`GET /applications`), on the
|
|
208
|
+
* shared fetcher cache.
|
|
209
|
+
*
|
|
210
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
211
|
+
* @internal
|
|
212
|
+
*/
|
|
213
|
+
export const applications = defineFetcher<
|
|
214
|
+
[options: ApplicationsOptions],
|
|
215
|
+
ApplicationsResponse<ApplicationInclude>
|
|
216
|
+
>({
|
|
217
|
+
name: 'applications',
|
|
218
|
+
getKey: (_instance, options) =>
|
|
219
|
+
[
|
|
220
|
+
options.organizationId,
|
|
221
|
+
options.type ?? '',
|
|
222
|
+
serializeInclude(options.include) ?? '',
|
|
223
|
+
options.limit ?? '',
|
|
224
|
+
options.cursor ?? '',
|
|
225
|
+
].join(':'),
|
|
226
|
+
fetch: (instance) => (options) =>
|
|
227
|
+
getClientState(instance, {apiVersion: API_VERSION, scope: 'global'}).observable.pipe(
|
|
228
|
+
switchMap((client) =>
|
|
229
|
+
client.observable.request<ApplicationsResponse<ApplicationInclude>>({
|
|
230
|
+
uri: '/applications',
|
|
231
|
+
query: buildQuery({
|
|
232
|
+
organizationId: options.organizationId,
|
|
233
|
+
type: options.type,
|
|
234
|
+
include: serializeInclude(options.include),
|
|
235
|
+
limit: options.limit,
|
|
236
|
+
cursor: options.cursor,
|
|
237
|
+
}),
|
|
238
|
+
tag: 'applications.list',
|
|
239
|
+
}),
|
|
240
|
+
),
|
|
241
|
+
),
|
|
242
|
+
tags: (data) => [
|
|
243
|
+
{type: 'application', id: 'LIST'},
|
|
244
|
+
...data.data.map((app) => ({type: 'application', id: app.id})),
|
|
245
|
+
],
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Fetcher for a single application (`GET /applications/:id`), on the shared
|
|
250
|
+
* fetcher cache. No pre-seeding from {@link applications}: its list keys
|
|
251
|
+
* include the organization, which this fetcher's params can't reconstruct.
|
|
252
|
+
*
|
|
253
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
254
|
+
* @internal
|
|
255
|
+
*/
|
|
256
|
+
export const application = defineFetcher<
|
|
257
|
+
[applicationId: string, options?: {include?: ApplicationInclude[]}],
|
|
258
|
+
Application<ApplicationInclude>
|
|
259
|
+
>({
|
|
260
|
+
name: 'application',
|
|
261
|
+
getKey: (_instance, applicationId, options) =>
|
|
262
|
+
`${applicationId}:${serializeInclude(options?.include) ?? ''}`,
|
|
263
|
+
fetch: (instance) => (applicationId, options) =>
|
|
264
|
+
getClientState(instance, {apiVersion: API_VERSION, scope: 'global'}).observable.pipe(
|
|
265
|
+
switchMap((client) =>
|
|
266
|
+
client.observable.request<Application<ApplicationInclude>>({
|
|
267
|
+
uri: `/applications/${applicationId}`,
|
|
268
|
+
query: buildQuery({include: serializeInclude(options?.include)}),
|
|
269
|
+
tag: 'applications.get',
|
|
270
|
+
}),
|
|
271
|
+
),
|
|
272
|
+
),
|
|
273
|
+
tags: (data) => [{type: 'application', id: data.id}],
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Confirmation returned by the API's soft-delete endpoints.
|
|
278
|
+
*
|
|
279
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
280
|
+
* @internal
|
|
281
|
+
*/
|
|
282
|
+
export interface DeletedResult {
|
|
283
|
+
deleted: boolean
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Dashboard visibility for an application.
|
|
288
|
+
*
|
|
289
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
290
|
+
* @internal
|
|
291
|
+
*/
|
|
292
|
+
export type ApplicationVisibility = ApplicationBase['visibility']
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Mutable properties of an application (`PATCH /applications/:id`) — the
|
|
296
|
+
* writable subset of {@link ApplicationBase}, each optional, keyed by id.
|
|
297
|
+
*
|
|
298
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
299
|
+
* @internal
|
|
300
|
+
*/
|
|
301
|
+
export type UpdateApplicationInput = {applicationId: string} & Partial<
|
|
302
|
+
Pick<ApplicationBase, 'title' | 'icon' | 'visibility'>
|
|
303
|
+
>
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Mutation to update an application (`PATCH /applications/:id`). Invalidates the
|
|
307
|
+
* updated application and the list so active entries reconverge on server truth.
|
|
308
|
+
*
|
|
309
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
310
|
+
* @internal
|
|
311
|
+
*/
|
|
312
|
+
export const updateApplication = defineMutation<UpdateApplicationInput, Application>({
|
|
313
|
+
name: 'updateApplication',
|
|
314
|
+
mutationFn:
|
|
315
|
+
(instance) =>
|
|
316
|
+
({applicationId, ...body}) =>
|
|
317
|
+
getClientState(instance, {apiVersion: API_VERSION, scope: 'global'}).observable.pipe(
|
|
318
|
+
switchMap((client) =>
|
|
319
|
+
client.observable.request<Application>({
|
|
320
|
+
uri: `/applications/${applicationId}`,
|
|
321
|
+
method: 'PATCH',
|
|
322
|
+
body,
|
|
323
|
+
tag: 'applications.update',
|
|
324
|
+
}),
|
|
325
|
+
),
|
|
326
|
+
),
|
|
327
|
+
invalidates: (_result, {applicationId}) => [
|
|
328
|
+
{type: 'application', id: 'LIST'},
|
|
329
|
+
{type: 'application', id: applicationId},
|
|
330
|
+
],
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Input for {@link deleteApplication}.
|
|
335
|
+
*
|
|
336
|
+
* @internal
|
|
337
|
+
*/
|
|
338
|
+
export interface DeleteApplicationInput {
|
|
339
|
+
applicationId: string
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Mutation to soft-delete an application (`DELETE /applications/:id`).
|
|
344
|
+
* Invalidates the deleted application and the list.
|
|
345
|
+
*
|
|
346
|
+
* @see https://www.sanity.io/docs/http-reference/applications-api
|
|
347
|
+
* @internal
|
|
348
|
+
*/
|
|
349
|
+
export const deleteApplication = defineMutation<DeleteApplicationInput, DeletedResult>({
|
|
350
|
+
name: 'deleteApplication',
|
|
351
|
+
mutationFn:
|
|
352
|
+
(instance) =>
|
|
353
|
+
({applicationId}) =>
|
|
354
|
+
getClientState(instance, {apiVersion: API_VERSION, scope: 'global'}).observable.pipe(
|
|
355
|
+
switchMap((client) =>
|
|
356
|
+
client.observable.request<DeletedResult>({
|
|
357
|
+
uri: `/applications/${applicationId}`,
|
|
358
|
+
method: 'DELETE',
|
|
359
|
+
tag: 'applications.delete',
|
|
360
|
+
}),
|
|
361
|
+
),
|
|
362
|
+
),
|
|
363
|
+
invalidates: (_result, {applicationId}) => [
|
|
364
|
+
{type: 'application', id: 'LIST'},
|
|
365
|
+
{type: 'application', id: applicationId},
|
|
366
|
+
],
|
|
367
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {type SanityInstance} from '../store/createSanityInstance'
|
|
2
|
+
import {createLogger, type Logger} from '../utils/logger'
|
|
3
|
+
|
|
4
|
+
const loggers = new WeakMap<SanityInstance, Logger>()
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the auth logger for a Sanity instance, creating it on first use.
|
|
8
|
+
*
|
|
9
|
+
* The logger is cached per instance so repeated action calls (logout,
|
|
10
|
+
* setAuthToken, handleAuthCallback) reuse the same logger instead of
|
|
11
|
+
* rebuilding it. The instance details are nested under `instanceContext`,
|
|
12
|
+
* which is what the logger's formatter reads to render the
|
|
13
|
+
* `[project:x] [dataset:y] [instance:z]` prefix.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export function getAuthLogger(instance: SanityInstance): Logger {
|
|
18
|
+
let logger = loggers.get(instance)
|
|
19
|
+
if (!logger) {
|
|
20
|
+
logger = createLogger('auth', {
|
|
21
|
+
instanceContext: {
|
|
22
|
+
instanceId: instance.instanceId,
|
|
23
|
+
projectId: instance.config.projectId,
|
|
24
|
+
dataset: instance.config.dataset,
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
loggers.set(instance, logger)
|
|
28
|
+
}
|
|
29
|
+
return logger
|
|
30
|
+
}
|