@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.
Files changed (241) hide show
  1. package/README.md +12 -0
  2. package/dist/_exports/_internal.d.ts +163 -0
  3. package/dist/_exports/_internal.d.ts.map +1 -0
  4. package/dist/_exports/_internal.js +332 -0
  5. package/dist/_exports/_internal.js.map +1 -0
  6. package/dist/_exports/agent.d.ts +65 -0
  7. package/dist/_exports/agent.d.ts.map +1 -0
  8. package/dist/_exports/agent.js +71 -0
  9. package/dist/_exports/agent.js.map +1 -0
  10. package/dist/_exports/comlink.d.ts +118 -0
  11. package/dist/_exports/comlink.d.ts.map +1 -0
  12. package/dist/_exports/comlink.js +69 -0
  13. package/dist/_exports/comlink.js.map +1 -0
  14. package/dist/authStore-CtE9bLHW.js +754 -0
  15. package/dist/authStore-CtE9bLHW.js.map +1 -0
  16. package/dist/authStore-DKFX8fn7.d.ts +3179 -0
  17. package/dist/authStore-DKFX8fn7.d.ts.map +1 -0
  18. package/dist/clientStore-BtE2-q2i.js +90 -0
  19. package/dist/clientStore-BtE2-q2i.js.map +1 -0
  20. package/dist/createSanityInstance-DUI1bGIg.d.ts +278 -0
  21. package/dist/createSanityInstance-DUI1bGIg.d.ts.map +1 -0
  22. package/dist/createStateSourceAction-BOKtqFNm.js +300 -0
  23. package/dist/createStateSourceAction-BOKtqFNm.js.map +1 -0
  24. package/dist/getEnv-D5RGkQLu.js +8 -0
  25. package/dist/getEnv-D5RGkQLu.js.map +1 -0
  26. package/dist/getNodeState-CR3__B2D.js +67 -0
  27. package/dist/getNodeState-CR3__B2D.js.map +1 -0
  28. package/dist/index.d.ts +3 -2332
  29. package/dist/index.js +4171 -4332
  30. package/dist/index.js.map +1 -1
  31. package/dist/logger-DAtJb5RQ.js +173 -0
  32. package/dist/logger-DAtJb5RQ.js.map +1 -0
  33. package/dist/object-CxXlSVg7.js +83 -0
  34. package/dist/object-CxXlSVg7.js.map +1 -0
  35. package/dist/queryStore-DPf9sN3V.js +1346 -0
  36. package/dist/queryStore-DPf9sN3V.js.map +1 -0
  37. package/dist/rolldown-runtime-vyAXikos.js +9 -0
  38. package/dist/setCleanupTimeout-BiM6q1KF.js +31 -0
  39. package/dist/setCleanupTimeout-BiM6q1KF.js.map +1 -0
  40. package/dist/telemetryManager-Dq_qCkeI.js +127 -0
  41. package/dist/telemetryManager-Dq_qCkeI.js.map +1 -0
  42. package/dist/version-BChjsi4u.js +9 -0
  43. package/dist/version-BChjsi4u.js.map +1 -0
  44. package/package.json +47 -52
  45. package/src/_exports/_internal.ts +27 -0
  46. package/src/_exports/agent.ts +19 -0
  47. package/src/_exports/comlink.ts +16 -0
  48. package/src/_exports/index.ts +125 -64
  49. package/src/access/checkPermissions.test.ts +55 -0
  50. package/src/access/checkPermissions.ts +54 -0
  51. package/src/agent/agentActions.test.ts +16 -60
  52. package/src/agent/agentActions.ts +25 -38
  53. package/src/applications/applications.test-d.ts +88 -0
  54. package/src/applications/applications.test.ts +130 -0
  55. package/src/applications/applications.ts +367 -0
  56. package/src/auth/authLogger.ts +30 -0
  57. package/src/auth/authStore.test.ts +194 -13
  58. package/src/auth/authStore.ts +58 -26
  59. package/src/auth/getOrganizationVerificationState.test.ts +18 -17
  60. package/src/auth/getOrganizationVerificationState.ts +4 -4
  61. package/src/auth/handleAuthCallback.test.ts +35 -1
  62. package/src/auth/handleAuthCallback.ts +25 -6
  63. package/src/auth/logout.test.ts +75 -2
  64. package/src/auth/logout.ts +23 -4
  65. package/src/auth/refreshStampedToken.test.ts +219 -469
  66. package/src/auth/refreshStampedToken.ts +79 -195
  67. package/src/auth/studioAuth.ts +1 -1
  68. package/src/auth/studioModeAuth.ts +2 -1
  69. package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +146 -13
  70. package/src/auth/subscribeToStateAndFetchCurrentUser.ts +37 -6
  71. package/src/auth/subscribeToStorageEventsAndSetToken.test.ts +2 -0
  72. package/src/client/clientStore.test.ts +62 -37
  73. package/src/client/clientStore.ts +45 -75
  74. package/src/client/liveEvents.test.ts +151 -0
  75. package/src/client/liveEvents.ts +107 -0
  76. package/src/comlink/controller/actions/destroyController.test.ts +4 -1
  77. package/src/comlink/controller/actions/getOrCreateChannel.test.ts +4 -1
  78. package/src/comlink/controller/actions/getOrCreateChannel.ts +2 -2
  79. package/src/comlink/controller/actions/getOrCreateController.test.ts +4 -1
  80. package/src/comlink/controller/actions/releaseChannel.test.ts +1 -1
  81. package/src/comlink/controller/comlinkControllerStore.test.ts +4 -1
  82. package/src/comlink/node/actions/getOrCreateNode.test.ts +9 -3
  83. package/src/comlink/node/actions/getOrCreateNode.ts +2 -2
  84. package/src/comlink/node/actions/releaseNode.test.ts +7 -4
  85. package/src/comlink/node/comlinkNodeStore.test.ts +2 -2
  86. package/src/comlink/node/getNodeState.test.ts +1 -1
  87. package/src/comlink/node/getNodeState.ts +2 -1
  88. package/src/comments/addonDatasetStore.test.ts +215 -0
  89. package/src/comments/addonDatasetStore.ts +249 -0
  90. package/src/comments/buildCommentThreads.test.ts +83 -0
  91. package/src/comments/buildCommentThreads.ts +54 -0
  92. package/src/comments/commentActions.test.ts +540 -0
  93. package/src/comments/commentActions.ts +555 -0
  94. package/src/comments/commentFieldPath.test.ts +40 -0
  95. package/src/comments/commentFieldPath.ts +44 -0
  96. package/src/comments/commentsConstants.ts +80 -0
  97. package/src/comments/commentsStore.test.ts +419 -0
  98. package/src/comments/commentsStore.ts +483 -0
  99. package/src/comments/normalizeComment.test.ts +116 -0
  100. package/src/comments/normalizeComment.ts +45 -0
  101. package/src/comments/observeComments.test.ts +193 -0
  102. package/src/comments/observeComments.ts +113 -0
  103. package/src/comments/reducers.test.ts +277 -0
  104. package/src/comments/reducers.ts +316 -0
  105. package/src/comments/types.ts +249 -0
  106. package/src/comments/weakenReferences.test.ts +47 -0
  107. package/src/comments/weakenReferences.ts +29 -0
  108. package/src/config/__tests__/handles.test.ts +18 -12
  109. package/src/config/handles.ts +25 -7
  110. package/src/config/sanityConfig.ts +40 -82
  111. package/src/datasets/datasets.test.ts +2 -2
  112. package/src/datasets/datasets.ts +10 -4
  113. package/src/document/actions.test.ts +115 -33
  114. package/src/document/actions.ts +212 -15
  115. package/src/document/applyDocumentActions.test.ts +35 -13
  116. package/src/document/applyDocumentActions.ts +30 -9
  117. package/src/document/documentConstants.ts +15 -0
  118. package/src/document/documentStore.concurrency.test.ts +1306 -0
  119. package/src/document/documentStore.test.ts +753 -273
  120. package/src/document/documentStore.ts +197 -75
  121. package/src/document/events.test.ts +57 -2
  122. package/src/document/events.ts +82 -26
  123. package/src/document/listen.test.ts +56 -0
  124. package/src/document/listen.ts +74 -21
  125. package/src/document/listenerEventOperators.test.ts +311 -0
  126. package/src/document/listenerEventOperators.ts +217 -0
  127. package/src/document/patchOperations.test.ts +76 -2
  128. package/src/document/patchOperations.ts +60 -1
  129. package/src/document/permissions.test.ts +107 -60
  130. package/src/document/permissions.ts +44 -19
  131. package/src/document/processActions/create.ts +138 -0
  132. package/src/document/processActions/delete.ts +100 -0
  133. package/src/document/processActions/discard.ts +63 -0
  134. package/src/document/processActions/edit.ts +154 -0
  135. package/src/document/processActions/processActions.ts +218 -0
  136. package/src/document/processActions/publish.ts +120 -0
  137. package/src/document/processActions/releaseArchive.ts +77 -0
  138. package/src/document/processActions/releaseCreate.ts +59 -0
  139. package/src/document/processActions/releaseDelete.ts +65 -0
  140. package/src/document/processActions/releaseEdit.ts +37 -0
  141. package/src/document/processActions/releasePublish.ts +45 -0
  142. package/src/document/processActions/releaseSchedule.ts +87 -0
  143. package/src/document/processActions/releaseUtil.ts +31 -0
  144. package/src/document/processActions/shared.ts +308 -0
  145. package/src/document/processActions/unpublish.ts +85 -0
  146. package/src/document/processActions.test.ts +1129 -121
  147. package/src/document/reducers.test.ts +772 -64
  148. package/src/document/reducers.ts +205 -51
  149. package/src/document/resourceRules.test.ts +178 -0
  150. package/src/document/resourceRules.ts +117 -0
  151. package/src/document/sharedListener.test.ts +16 -14
  152. package/src/document/sharedListener.ts +24 -8
  153. package/src/document/util.test.ts +46 -0
  154. package/src/document/util.ts +50 -0
  155. package/src/favorites/favorites.test.ts +5 -6
  156. package/src/installations/installations.test-d.ts +73 -0
  157. package/src/installations/installations.test.ts +62 -0
  158. package/src/installations/installations.ts +206 -0
  159. package/src/organization/organization.test-d.ts +36 -0
  160. package/src/organization/organization.test.ts +138 -0
  161. package/src/organization/organization.ts +138 -0
  162. package/src/organizations/organizations.test-d.ts +56 -0
  163. package/src/organizations/organizations.test.ts +150 -0
  164. package/src/organizations/organizations.ts +107 -0
  165. package/src/presence/bifurTransport.test.ts +201 -9
  166. package/src/presence/bifurTransport.ts +98 -14
  167. package/src/presence/paths.test.ts +70 -0
  168. package/src/presence/paths.ts +41 -0
  169. package/src/presence/presenceStore.test.ts +915 -24
  170. package/src/presence/presenceStore.ts +576 -104
  171. package/src/presence/types.ts +175 -3
  172. package/src/preview/previewProjectionUtils.test.ts +9 -22
  173. package/src/preview/previewProjectionUtils.ts +7 -3
  174. package/src/preview/types.ts +0 -15
  175. package/src/project/project.test-d.ts +37 -0
  176. package/src/project/project.test.ts +157 -12
  177. package/src/project/project.ts +138 -25
  178. package/src/projection/getProjectionState.test.ts +18 -20
  179. package/src/projection/getProjectionState.ts +23 -3
  180. package/src/projection/projectionQuery.ts +5 -5
  181. package/src/projection/projectionStore.test.ts +1 -9
  182. package/src/projection/resolveProjection.test.ts +1 -2
  183. package/src/projection/resolveProjection.ts +16 -0
  184. package/src/projection/subscribeToStateAndFetchBatches.test.ts +1 -1
  185. package/src/projection/subscribeToStateAndFetchBatches.ts +32 -23
  186. package/src/projects/projects.test-d.ts +32 -0
  187. package/src/projects/projects.test.ts +108 -42
  188. package/src/projects/projects.ts +63 -27
  189. package/src/query/queryStore.test.ts +259 -123
  190. package/src/query/queryStore.ts +85 -69
  191. package/src/query/reducers.test.ts +0 -42
  192. package/src/query/reducers.ts +2 -18
  193. package/src/releases/getPerspectiveState.test.ts +17 -23
  194. package/src/releases/getPerspectiveState.ts +8 -20
  195. package/src/releases/observeReleases.test.ts +127 -0
  196. package/src/releases/observeReleases.ts +102 -0
  197. package/src/releases/releasesStore.test.ts +100 -53
  198. package/src/releases/releasesStore.ts +69 -44
  199. package/src/releases/utils/sortReleases.test.ts +38 -2
  200. package/src/releases/utils/sortReleases.ts +15 -10
  201. package/src/store/createActionBinder.test.ts +109 -90
  202. package/src/store/createActionBinder.ts +36 -28
  203. package/src/store/createSanityInstance.test.ts +15 -13
  204. package/src/store/createSanityInstance.ts +14 -2
  205. package/src/store/createStateSourceAction.test.ts +64 -2
  206. package/src/store/createStateSourceAction.ts +38 -43
  207. package/src/store/createStoreInstance.test.ts +4 -2
  208. package/src/store/fetcherStore.test-d.ts +121 -0
  209. package/src/store/fetcherStore.test.ts +299 -0
  210. package/src/store/fetcherStore.ts +801 -0
  211. package/src/telemetry/environment.test.ts +119 -0
  212. package/src/telemetry/environment.ts +92 -0
  213. package/src/telemetry/events.ts +42 -0
  214. package/src/telemetry/initTelemetry.test.ts +432 -0
  215. package/src/telemetry/initTelemetry.ts +218 -0
  216. package/src/telemetry/telemetryManager.test.ts +327 -0
  217. package/src/telemetry/telemetryManager.ts +199 -0
  218. package/src/users/reducers.test.ts +3 -1
  219. package/src/users/reducers.ts +5 -6
  220. package/src/users/types.ts +4 -4
  221. package/src/users/usersStore.test.ts +16 -12
  222. package/src/users/usersStore.ts +5 -1
  223. package/src/utils/buildQuery.test.ts +14 -0
  224. package/src/utils/buildQuery.ts +17 -0
  225. package/src/utils/createFetcherStore.test.ts +7 -5
  226. package/src/utils/createFetcherStore.ts +8 -5
  227. package/src/utils/getStagingApiHost.test.ts +21 -0
  228. package/src/utils/getStagingApiHost.ts +14 -0
  229. package/src/utils/ids.test.ts +1 -29
  230. package/src/utils/ids.ts +0 -10
  231. package/src/utils/includeShape.ts +36 -0
  232. package/src/utils/isImportError.test.ts +72 -0
  233. package/src/utils/isImportError.ts +34 -0
  234. package/src/utils/logger.test.ts +12 -0
  235. package/src/utils/logger.ts +8 -3
  236. package/src/utils/object.test.ts +95 -0
  237. package/src/utils/object.ts +142 -0
  238. package/src/utils/setCleanupTimeout.ts +37 -0
  239. package/src/document/processActions.ts +0 -707
  240. package/src/utils/defineIntent.test.ts +0 -477
  241. 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
+ }