@sanity/sdk 3.0.0-rc.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_exports/_internal.d.ts +25 -3
- package/dist/_exports/_internal.d.ts.map +1 -1
- package/dist/_exports/_internal.js +127 -9
- package/dist/_exports/_internal.js.map +1 -1
- package/dist/_exports/agent.d.ts +1 -1
- package/dist/_exports/agent.js +1 -1
- package/dist/_exports/comlink.d.ts +1 -1
- package/dist/_exports/comlink.js +2 -3
- package/dist/_exports/comlink.js.map +1 -1
- package/dist/{authStore-DKFX8fn7.d.ts → authStore-C-OEkGaM.d.ts} +30 -44
- package/dist/authStore-C-OEkGaM.d.ts.map +1 -0
- package/dist/{authStore-CtE9bLHW.js → clientStore-gUALQ0qW.js} +269 -11
- package/dist/{authStore-CtE9bLHW.js.map → clientStore-gUALQ0qW.js.map} +1 -1
- package/dist/{createSanityInstance-DUI1bGIg.d.ts → createSanityInstance-DCePpBYW.d.ts} +2 -2
- package/dist/{createSanityInstance-DUI1bGIg.d.ts.map → createSanityInstance-DCePpBYW.d.ts.map} +1 -1
- package/dist/{getNodeState-CR3__B2D.js → getNodeState-E0hjqFOo.js} +2 -3
- package/dist/{getNodeState-CR3__B2D.js.map → getNodeState-E0hjqFOo.js.map} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +168 -176
- package/dist/index.js.map +1 -1
- package/dist/{createStateSourceAction-BOKtqFNm.js → object-BwynGPRZ.js} +87 -3
- package/dist/object-BwynGPRZ.js.map +1 -0
- package/dist/{queryStore-DPf9sN3V.js → version-C90rNWaX.js} +48 -16
- package/dist/version-C90rNWaX.js.map +1 -0
- package/package.json +4 -4
- package/src/_exports/_internal.ts +1 -0
- package/src/_exports/index.ts +7 -4
- package/src/access/checkPermissions.test.ts +1 -1
- package/src/access/checkPermissions.ts +1 -1
- package/src/applications/applications.test.ts +4 -4
- package/src/applications/applications.ts +4 -4
- package/src/auth/handleAuthCallback.test.ts +2 -2
- package/src/auth/handleAuthCallback.ts +1 -1
- package/src/auth/logout.test.ts +1 -1
- package/src/auth/logout.ts +1 -1
- package/src/auth/refreshStampedToken.ts +1 -1
- package/src/auth/studioModeAuth.test.ts +1 -1
- package/src/auth/studioModeAuth.ts +1 -1
- package/src/auth/subscribeToStateAndFetchCurrentUser.test.ts +2 -2
- package/src/auth/subscribeToStateAndFetchCurrentUser.ts +1 -1
- package/src/comments/addonDatasetStore.test.ts +2 -2
- package/src/comments/addonDatasetStore.ts +2 -2
- package/src/comments/commentActions.ts +6 -5
- package/src/comments/commentsStore.ts +4 -4
- package/src/datasets/datasets.test.ts +44 -9
- package/src/datasets/datasets.ts +24 -23
- package/src/document/applyDocumentActions.ts +2 -6
- package/src/document/documentConstants.ts +9 -0
- package/src/document/documentStore.concurrency.test.ts +2 -1
- package/src/document/documentStore.test.ts +87 -17
- package/src/document/documentStore.ts +5 -5
- package/src/document/permissions.ts +2 -1
- package/src/document/processActions.test.ts +2 -1
- package/src/document/processMutations.ts +3 -2
- package/src/document/reducers.test.ts +224 -0
- package/src/document/reducers.ts +110 -27
- package/src/favorites/favorites.test.ts +64 -24
- package/src/favorites/favorites.ts +73 -22
- package/src/installations/installations.test.ts +2 -2
- package/src/installations/installations.ts +2 -2
- package/src/organization/organization.test.ts +2 -2
- package/src/organization/organization.ts +1 -1
- package/src/organizations/organizations.test.ts +2 -2
- package/src/organizations/organizations.ts +1 -1
- package/src/presence/presenceStore.test.ts +15 -22
- package/src/presence/presenceStore.ts +3 -2
- package/src/project/project.test.ts +3 -3
- package/src/project/project.ts +1 -1
- package/src/projection/getProjectionState.test.ts +6 -4
- package/src/projection/getProjectionState.ts +2 -2
- package/src/projects/projects.test.ts +2 -2
- package/src/projects/projects.ts +1 -1
- package/src/query/queryStore.ts +3 -3
- package/src/store/createSanityInstance.test.ts +1 -1
- package/src/store/createSanityInstance.ts +4 -4
- package/src/store/createStoreInstance.test.ts +0 -5
- package/src/store/fetcherStore.test.ts +23 -1
- package/src/store/fetcherStore.ts +3 -3
- package/src/telemetry/telemetryManager.test.ts +1 -1
- package/src/telemetry/telemetryManager.ts +2 -2
- package/src/users/usersStore.test.ts +1 -1
- package/src/users/usersStore.ts +5 -5
- package/src/utils/ids.test.ts +40 -15
- package/src/utils/ids.ts +47 -2
- package/dist/authStore-DKFX8fn7.d.ts.map +0 -1
- package/dist/clientStore-BtE2-q2i.js +0 -90
- package/dist/clientStore-BtE2-q2i.js.map +0 -1
- package/dist/createStateSourceAction-BOKtqFNm.js.map +0 -1
- package/dist/getEnv-D5RGkQLu.js +0 -8
- package/dist/getEnv-D5RGkQLu.js.map +0 -1
- package/dist/logger-DAtJb5RQ.js +0 -173
- package/dist/logger-DAtJb5RQ.js.map +0 -1
- package/dist/object-CxXlSVg7.js +0 -83
- package/dist/object-CxXlSVg7.js.map +0 -1
- package/dist/queryStore-DPf9sN3V.js.map +0 -1
- package/dist/rolldown-runtime-vyAXikos.js +0 -9
- package/dist/telemetryManager-Dq_qCkeI.js +0 -127
- package/dist/telemetryManager-Dq_qCkeI.js.map +0 -1
- package/dist/version-BChjsi4u.js +0 -9
- package/dist/version-BChjsi4u.js.map +0 -1
- package/src/utils/createFetcherStore.test.ts +0 -171
- package/src/utils/createFetcherStore.ts +0 -284
package/dist/index.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { C as REQUEST_TAG_PREFIX, S as DEFAULT_API_VERSION, _ as getDefaultLocation, a as getCurrentUserState, b as AuthStateType, c as getLoginUrlState, d as createLoggedInAuthState, f as getAuthCode, i as getAuthState, l as getTokenState, o as getDashboardOrganizationId, p as getCleanedUrl, s as getIsInDashboardState, t as authStore, u as setAuthToken, v as getTokenFromLocation, w as getAuthLogger } from "./authStore-CtE9bLHW.js";
|
|
5
|
-
import { r as omitProperty, t as isDeepEqual } from "./object-CxXlSVg7.js";
|
|
6
|
-
import { n as getClient, r as getClientState } from "./clientStore-BtE2-q2i.js";
|
|
1
|
+
import { D as configureLogging$1, E as getAuthLogger, O as createLogger, S as AuthStateType, T as REQUEST_TAG_PREFIX, b as getTokenFromLocation, c as getDashboardOrganizationId, d as getTokenState, f as setAuthToken, h as getCleanedUrl, i as authStore, l as getIsInDashboardState, m as getAuthCode, n as getClient, o as getAuthState, p as createLoggedInAuthState, r as getClientState, s as getCurrentUserState, u as getLoginUrlState, w as DEFAULT_API_VERSION, y as getDefaultLocation } from "./clientStore-gUALQ0qW.js";
|
|
2
|
+
import { a as createStateSourceAction, c as bindActionGlobally, d as isReleasePerspective, f as isCanvasResource, l as defineStore, m as isMediaLibraryResource, o as bindActionByResource, p as isDatasetResource, r as omitProperty, s as bindActionByResourceAndPerspective, t as isDeepEqual } from "./object-BwynGPRZ.js";
|
|
3
|
+
import { A as clearPendingTransaction, B as assertDatasetResource, C as getCommentsState, D as toCommentsKeyParts, E as resolveComments, F as rollbackCommentUpdate, G as defineMutation, H as provisionAddonDataset, I as setCommentCreateError, K as randomId, L as setPendingTransaction, M as receiveComment, N as removeCommentById, O as addComment, P as restoreComments, R as normalizeComment, T as resolveCommentThreads, U as COMMENTS_API_VERSION, V as getAddonDatasetState, W as defineFetcher, _ as updateLastLoadMoreRequest, a as resolveQuery, b as commentsStore, c as getAllReleasesState, d as getUsersKey, f as initializeRequest, g as setUsersError, h as setUsersData, j as getCommentsKey, k as applyCommentUpdate, l as addSubscription, m as removeSubscription, o as getPerspectiveState, p as parseUsersKey, q as randomUuid, r as getQueryState, s as getActiveReleasesState, t as CORE_SDK_VERSION, u as cancelRequest, v as PROJECT_API_VERSION, x as getCommentThreadsState, y as USERS_STATE_CLEAR_DELAY, z as toCommentFieldPath } from "./version-C90rNWaX.js";
|
|
7
4
|
import { n as setCleanupTimeout } from "./setCleanupTimeout-BiM6q1KF.js";
|
|
8
|
-
import { t as getNodeState } from "./getNodeState-
|
|
9
|
-
import { t as CORE_SDK_VERSION } from "./version-BChjsi4u.js";
|
|
5
|
+
import { t as getNodeState } from "./getNodeState-E0hjqFOo.js";
|
|
10
6
|
import { ClientError, CorsOriginError } from "@sanity/client";
|
|
11
|
-
import { EMPTY, NEVER, Observable, Subject, Subscription,
|
|
7
|
+
import { EMPTY, NEVER, Observable, Subject, Subscription, auditTime, catchError, combineLatest, concat, concatMap, debounceTime, defer, distinctUntilChanged, filter, first, firstValueFrom, from, fromEvent, groupBy, map, merge, mergeMap, of, pairwise, partition, race, retry, share, shareReplay, skip, startWith, switchMap, take, takeUntil, tap, throttle, throwError, timer, withLatestFrom } from "rxjs";
|
|
12
8
|
import { isKeySegment, isKeyedObject } from "@sanity/types";
|
|
13
9
|
import { DocumentId, getDraftId, getPublishedId, getVersionId, isDraftId, isPublishedId, isVersionId } from "@sanity/id-utils";
|
|
14
10
|
import { getIndexForKey, getIndexForKey as getIndexForKey$1, getPathDepth, joinPaths, jsonMatch, jsonMatch as jsonMatch$1, slicePath, slicePath as slicePath$1, stringifyPath, stringifyPath as stringifyPath$1 } from "@sanity/json-match";
|
|
15
|
-
import { catchError as catchError$1, delay, distinctUntilChanged as distinctUntilChanged$1, filter as filter$1, first as first$1, groupBy as groupBy$1, map as map$1, mergeMap as mergeMap$1, pairwise as pairwise$1, retry as retry$1, scan, share as share$1, startWith as startWith$1, switchMap as switchMap$1, tap as tap$1 } from "rxjs/operators";
|
|
16
11
|
import { SanityEncoder } from "@sanity/mutate";
|
|
17
12
|
import { createDocumentLoaderFromClient } from "@sanity/mutate/_unstable_store";
|
|
18
13
|
import "groq";
|
|
19
14
|
import { evaluateSync, parse } from "groq-js";
|
|
15
|
+
import { catchError as catchError$1, distinctUntilChanged as distinctUntilChanged$1, map as map$1, mergeMap as mergeMap$1, retry as retry$1, scan, share as share$1, switchMap as switchMap$1 } from "rxjs/operators";
|
|
20
16
|
import { applyPatches, parsePatch } from "@sanity/diff-match-patch";
|
|
21
17
|
import { createSelector } from "reselect";
|
|
22
18
|
import { diffValue } from "@sanity/diff-patch";
|
|
@@ -30,7 +26,7 @@ import { fromUrl } from "@sanity/bifur-client";
|
|
|
30
26
|
* @public
|
|
31
27
|
*/
|
|
32
28
|
function createSanityInstance(config = {}) {
|
|
33
|
-
let instanceId =
|
|
29
|
+
let instanceId = randomId(16), disposeListeners = /* @__PURE__ */ new Map(), disposed = { current: !1 }, instanceContext = {
|
|
34
30
|
instanceId,
|
|
35
31
|
projectId: config.projectId,
|
|
36
32
|
dataset: config.dataset
|
|
@@ -63,7 +59,7 @@ function createSanityInstance(config = {}) {
|
|
|
63
59
|
}), disposed.current = !0, disposeListeners.forEach((listener) => listener()), disposeListeners.clear(), logger.info("Instance disposed");
|
|
64
60
|
},
|
|
65
61
|
onDispose: (cb) => {
|
|
66
|
-
let listenerId =
|
|
62
|
+
let listenerId = randomId(16);
|
|
67
63
|
return disposeListeners.set(listenerId, cb), () => {
|
|
68
64
|
disposeListeners.delete(listenerId);
|
|
69
65
|
};
|
|
@@ -77,7 +73,7 @@ const checkPermissions = defineFetcher({
|
|
|
77
73
|
apiVersion: "v2025-07-11",
|
|
78
74
|
scope: "global"
|
|
79
75
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
80
|
-
|
|
76
|
+
url: `/access/${resourceType}/${resourceId}/user-permissions/me/check`,
|
|
81
77
|
query: { permissions },
|
|
82
78
|
tag: "access.check"
|
|
83
79
|
}).pipe(map((response) => response.data)))),
|
|
@@ -121,7 +117,7 @@ const applications = defineFetcher({
|
|
|
121
117
|
apiVersion: "vX",
|
|
122
118
|
scope: "global"
|
|
123
119
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
124
|
-
|
|
120
|
+
url: "/applications",
|
|
125
121
|
query: buildQuery({
|
|
126
122
|
organizationId: options.organizationId,
|
|
127
123
|
type: options.type,
|
|
@@ -145,7 +141,7 @@ const applications = defineFetcher({
|
|
|
145
141
|
apiVersion: "vX",
|
|
146
142
|
scope: "global"
|
|
147
143
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
148
|
-
|
|
144
|
+
url: `/applications/${applicationId}`,
|
|
149
145
|
query: buildQuery({ include: serializeInclude$1(options?.include) }),
|
|
150
146
|
tag: "applications.get"
|
|
151
147
|
}))),
|
|
@@ -159,7 +155,7 @@ const applications = defineFetcher({
|
|
|
159
155
|
apiVersion: "vX",
|
|
160
156
|
scope: "global"
|
|
161
157
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
162
|
-
|
|
158
|
+
url: `/applications/${applicationId}`,
|
|
163
159
|
method: "PATCH",
|
|
164
160
|
body,
|
|
165
161
|
tag: "applications.update"
|
|
@@ -177,7 +173,7 @@ const applications = defineFetcher({
|
|
|
177
173
|
apiVersion: "vX",
|
|
178
174
|
scope: "global"
|
|
179
175
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
180
|
-
|
|
176
|
+
url: `/applications/${applicationId}`,
|
|
181
177
|
method: "DELETE",
|
|
182
178
|
tag: "applications.delete"
|
|
183
179
|
}))),
|
|
@@ -222,7 +218,7 @@ const projects = defineFetcher({
|
|
|
222
218
|
apiVersion: "v2025-02-19",
|
|
223
219
|
scope: "global"
|
|
224
220
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
225
|
-
|
|
221
|
+
url: "/projects",
|
|
226
222
|
query: buildQuery(normalizeProjectsOptions(options)),
|
|
227
223
|
tag: "projects.list"
|
|
228
224
|
}))),
|
|
@@ -240,14 +236,14 @@ function normalizeProjectOptions(options) {
|
|
|
240
236
|
includeFeatures: options?.includeFeatures ?? !0
|
|
241
237
|
};
|
|
242
238
|
}
|
|
243
|
-
function resolveProjectId(instance, options) {
|
|
239
|
+
function resolveProjectId$1(instance, options) {
|
|
244
240
|
let projectId = options?.projectId ?? instance.config.projectId;
|
|
245
241
|
if (!projectId) throw Error("A projectId is required to use the project API.");
|
|
246
242
|
return projectId;
|
|
247
243
|
}
|
|
248
244
|
/** @internal */
|
|
249
245
|
function getProjectCacheKey(instance, options) {
|
|
250
|
-
let projectId = resolveProjectId(instance, options), { includeMembers, includeFeatures } = normalizeProjectOptions(options);
|
|
246
|
+
let projectId = resolveProjectId$1(instance, options), { includeMembers, includeFeatures } = normalizeProjectOptions(options);
|
|
251
247
|
return `project:${projectId}${includeMembers ? ":members" : ""}${includeFeatures ? ":features" : ""}`;
|
|
252
248
|
}
|
|
253
249
|
/**
|
|
@@ -265,7 +261,7 @@ const project = defineFetcher({
|
|
|
265
261
|
apiVersion: "v2025-02-19",
|
|
266
262
|
scope: "global"
|
|
267
263
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
268
|
-
|
|
264
|
+
url: `/projects/${resolveProjectId$1(instance, options)}`,
|
|
269
265
|
query: buildQuery(normalizeProjectOptions(options)),
|
|
270
266
|
tag: "projects.get"
|
|
271
267
|
}))),
|
|
@@ -277,7 +273,7 @@ const project = defineFetcher({
|
|
|
277
273
|
if (normalizeProjectOptions(options).includeMembers) return;
|
|
278
274
|
let snapshot = projects.getState(instance).getCurrent();
|
|
279
275
|
if (snapshot.status !== "success") return;
|
|
280
|
-
let projectId = resolveProjectId(instance, options), match = snapshot.data.find((item) => item.id === projectId);
|
|
276
|
+
let projectId = resolveProjectId$1(instance, options), match = snapshot.data.find((item) => item.id === projectId);
|
|
281
277
|
return match && {
|
|
282
278
|
data: match,
|
|
283
279
|
dataUpdatedAt: snapshot.dataUpdatedAt
|
|
@@ -345,7 +341,7 @@ const handleAuthCallback = bindActionGlobally(authStore, async ({ state, instanc
|
|
|
345
341
|
logger.debug("Fetching token from auth endpoint");
|
|
346
342
|
let { token } = await client.request({
|
|
347
343
|
method: "GET",
|
|
348
|
-
|
|
344
|
+
url: "/auth/fetch",
|
|
349
345
|
query: { sid: authCode },
|
|
350
346
|
tag: "fetch-token"
|
|
351
347
|
});
|
|
@@ -383,7 +379,7 @@ const handleAuthCallback = bindActionGlobally(authStore, async ({ state, instanc
|
|
|
383
379
|
useCdn: !1
|
|
384
380
|
});
|
|
385
381
|
logger.debug("Calling logout endpoint"), await client.request({
|
|
386
|
-
|
|
382
|
+
url: "/auth/logout",
|
|
387
383
|
method: "POST",
|
|
388
384
|
tag: "logout"
|
|
389
385
|
});
|
|
@@ -517,7 +513,7 @@ const createComment = bindActionByResource(commentsStore, async (context, option
|
|
|
517
513
|
let { instance, key } = context, perspective = options.perspective ?? instance.config.perspective, fieldPath = requireFieldPath(options.fieldPath);
|
|
518
514
|
return postComment(context, options, buildCommentPayload({
|
|
519
515
|
authorId: requireCurrentUserId(instance),
|
|
520
|
-
commentId: options.commentId ??
|
|
516
|
+
commentId: options.commentId ?? randomUuid(),
|
|
521
517
|
contentSnapshot: options.contentSnapshot,
|
|
522
518
|
context: options.context,
|
|
523
519
|
documentRevisionId: options.documentRevisionId,
|
|
@@ -527,7 +523,7 @@ const createComment = bindActionByResource(commentsStore, async (context, option
|
|
|
527
523
|
fieldPath,
|
|
528
524
|
selection: options.selection,
|
|
529
525
|
status: options.status ?? "open",
|
|
530
|
-
threadId: options.threadId ??
|
|
526
|
+
threadId: options.threadId ?? randomUuid(),
|
|
531
527
|
...isReleasePerspective(perspective) ? { documentVersionId: perspective.releaseName } : {}
|
|
532
528
|
}));
|
|
533
529
|
}), replyToComment = bindActionByResource(commentsStore, async (context, options) => {
|
|
@@ -538,7 +534,7 @@ const createComment = bindActionByResource(commentsStore, async (context, option
|
|
|
538
534
|
let perspective = options.perspective ?? instance.config.perspective;
|
|
539
535
|
return postComment(context, options, buildCommentPayload({
|
|
540
536
|
authorId: requireCurrentUserId(instance),
|
|
541
|
-
commentId: options.commentId ??
|
|
537
|
+
commentId: options.commentId ?? randomUuid(),
|
|
542
538
|
handle: options,
|
|
543
539
|
message: options.message,
|
|
544
540
|
parentCommentId: parent?.parentCommentId ?? options.parentCommentId,
|
|
@@ -549,7 +545,7 @@ const createComment = bindActionByResource(commentsStore, async (context, option
|
|
|
549
545
|
...isReleasePerspective(perspective) ? { documentVersionId: perspective.releaseName } : {}
|
|
550
546
|
}));
|
|
551
547
|
}), updateComment = bindActionByResource(commentsStore, async ({ state, instance, key }, { commentId, message }) => {
|
|
552
|
-
let lastEditedAt = (/* @__PURE__ */ new Date()).toISOString(), transactionId =
|
|
548
|
+
let lastEditedAt = (/* @__PURE__ */ new Date()).toISOString(), transactionId = randomUuid(), previous = findCommentById(state, commentId);
|
|
553
549
|
previous && (state.set("setPendingTransaction", setPendingTransaction(commentId, transactionId)), state.set("updateComment", applyCommentUpdate(commentId, {
|
|
554
550
|
message,
|
|
555
551
|
lastEditedAt
|
|
@@ -564,7 +560,7 @@ const createComment = bindActionByResource(commentsStore, async (context, option
|
|
|
564
560
|
throw previous && state.set("rollbackCommentUpdate", rollbackCommentUpdate(commentId, transactionId, previous)), error;
|
|
565
561
|
}
|
|
566
562
|
}), setCommentStatus = bindActionByResource(commentsStore, async ({ state, instance, key }, { commentId, status }) => {
|
|
567
|
-
let transactionId =
|
|
563
|
+
let transactionId = randomUuid(), previousComments = [];
|
|
568
564
|
for (let entry of Object.values(state.get().entries)) for (let candidate of Object.values(entry?.comments ?? {})) (candidate._id === commentId || candidate.parentCommentId === commentId) && (previousComments.push(candidate), state.set("setPendingTransaction", setPendingTransaction(candidate._id, transactionId)), state.set("updateCommentStatus", applyCommentUpdate(candidate._id, { status })));
|
|
569
565
|
try {
|
|
570
566
|
await (await getWritableClient(instance, key.resource, { createIfMissing: !1 })).mutate([{ patch: {
|
|
@@ -768,117 +764,26 @@ function configureLogging(config) {
|
|
|
768
764
|
source: "programmatic"
|
|
769
765
|
});
|
|
770
766
|
}
|
|
767
|
+
function resolveProjectId(instance, options) {
|
|
768
|
+
let projectId = options?.projectId ?? instance.config.projectId;
|
|
769
|
+
if (!projectId) throw Error("A projectId is required to use the datasets API.");
|
|
770
|
+
return projectId;
|
|
771
|
+
}
|
|
771
772
|
/**
|
|
772
|
-
*
|
|
773
|
-
*
|
|
773
|
+
* Fetcher for a project's datasets (`GET /datasets`), on the shared fetcher
|
|
774
|
+
* cache.
|
|
774
775
|
*
|
|
775
|
-
*
|
|
776
|
-
* provided `getKey` function) and returns a state source (via `getState`)
|
|
777
|
-
* that components can subscribe to. When a new subscription is added, and if
|
|
778
|
-
* enough time has passed since the last fetch (controlled by
|
|
779
|
-
* `fetchThrottleInternal`), it invokes the observable factory (via
|
|
780
|
-
* `getObservable`) to fetch fresh data. The data is stored in state and can be
|
|
781
|
-
* accessed reactively.
|
|
782
|
-
*
|
|
783
|
-
* Additionally, the store provides a `resolveState` function that returns a
|
|
784
|
-
* Promise resolving with the next non-undefined value from the state source.
|
|
785
|
-
*
|
|
786
|
-
* State expiration is implemented: after the last subscription for a key is
|
|
787
|
-
* removed, its state is cleared after `stateExpirationDelay` ms, causing
|
|
788
|
-
* components to suspend until fresh data is fetched.
|
|
776
|
+
* @internal
|
|
789
777
|
*/
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
initialize: (context) => {
|
|
795
|
-
let subscription = subscribeToSubscriptionsAndFetch(context);
|
|
796
|
-
return () => subscription.unsubscribe();
|
|
797
|
-
}
|
|
798
|
-
}), subscribeToSubscriptionsAndFetch = ({ state }) => state.observable.pipe(switchMap$1((s) => {
|
|
799
|
-
let entries = Object.entries(s.stateByParams);
|
|
800
|
-
return entries.length > 0 ? from(entries) : EMPTY;
|
|
801
|
-
}), groupBy$1(([key]) => key), mergeMap$1((group$) => group$.pipe(startWith$1([group$.key, void 0]), pairwise$1(), filter$1(([[, prevEntry], [, currEntry]]) => {
|
|
802
|
-
let prevSubs = prevEntry?.subscriptions ?? [];
|
|
803
|
-
return (currEntry?.subscriptions ?? []).length > prevSubs.length;
|
|
804
|
-
}), map$1(([, [, currEntry]]) => currEntry), filter$1((entry) => {
|
|
805
|
-
let lastFetch = entry?.lastFetchInitiatedAt;
|
|
806
|
-
return !lastFetch || Date.now() - new Date(lastFetch).getTime() >= fetchThrottleInternal;
|
|
807
|
-
}), switchMap$1((entry) => entry ? (state.set("setLastFetchInitiatedAt", (prev) => ({ stateByParams: {
|
|
808
|
-
...prev.stateByParams,
|
|
809
|
-
[entry.key]: {
|
|
810
|
-
...entry,
|
|
811
|
-
...prev.stateByParams[entry.key],
|
|
812
|
-
lastFetchInitiatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
813
|
-
}
|
|
814
|
-
} })), getObservable(entry.instance)(...entry.params).pipe(delay(0, asapScheduler), tap$1((data) => state.set("setData", (prev) => ({ stateByParams: {
|
|
815
|
-
...prev.stateByParams,
|
|
816
|
-
[entry.key]: {
|
|
817
|
-
...omitProperty(entry, "error"),
|
|
818
|
-
...prev.stateByParams[entry.key] ? omitProperty(prev.stateByParams[entry.key], "error") : {},
|
|
819
|
-
data
|
|
820
|
-
}
|
|
821
|
-
} }))), catchError$1((error) => (state.set("setError", (prev) => ({ stateByParams: {
|
|
822
|
-
...prev.stateByParams,
|
|
823
|
-
[entry.key]: {
|
|
824
|
-
...entry,
|
|
825
|
-
...prev.stateByParams[entry.key],
|
|
826
|
-
error
|
|
827
|
-
}
|
|
828
|
-
} })), EMPTY)))) : EMPTY)))).subscribe({ error: (error) => state.set("setError", { error }) }), getState = bindActionGlobally(store, createStateSourceAction({
|
|
829
|
-
selector: ({ instance, state: { stateByParams, error } }, ...params) => {
|
|
830
|
-
if (error) throw error;
|
|
831
|
-
let entry = stateByParams[getKey(instance, ...params)];
|
|
832
|
-
if (entry?.error) throw entry.error;
|
|
833
|
-
return entry?.data;
|
|
834
|
-
},
|
|
835
|
-
onSubscribe: ({ instance, state }, ...params) => {
|
|
836
|
-
let subscriptionId = insecureRandomId(), key = getKey(instance, ...params);
|
|
837
|
-
return state.set("addSubscription", (prev) => ({ stateByParams: {
|
|
838
|
-
...prev.stateByParams,
|
|
839
|
-
[key]: {
|
|
840
|
-
...prev.stateByParams[key],
|
|
841
|
-
instance,
|
|
842
|
-
key,
|
|
843
|
-
params: prev.stateByParams[key]?.params || params,
|
|
844
|
-
subscriptions: [...prev.stateByParams[key]?.subscriptions || [], subscriptionId]
|
|
845
|
-
}
|
|
846
|
-
} })), () => {
|
|
847
|
-
setCleanupTimeout(() => {
|
|
848
|
-
state.set("removeSubscription", (prev) => {
|
|
849
|
-
let entry = prev.stateByParams[key];
|
|
850
|
-
if (!entry) return prev;
|
|
851
|
-
let newSubs = (entry.subscriptions || []).filter((id) => id !== subscriptionId);
|
|
852
|
-
return newSubs.length === 0 ? { stateByParams: omitProperty(prev.stateByParams, key) } : { stateByParams: {
|
|
853
|
-
...prev.stateByParams,
|
|
854
|
-
[key]: {
|
|
855
|
-
...entry,
|
|
856
|
-
subscriptions: newSubs
|
|
857
|
-
}
|
|
858
|
-
} };
|
|
859
|
-
});
|
|
860
|
-
}, stateExpirationDelay);
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
}));
|
|
864
|
-
return {
|
|
865
|
-
getState,
|
|
866
|
-
resolveState: bindActionGlobally(store, ({ instance }, ...params) => firstValueFrom(getState(instance, ...params).observable.pipe(first$1((i) => i !== void 0))))
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
const datasets = createFetcherStore({
|
|
870
|
-
name: "Datasets",
|
|
871
|
-
getKey: (instance, options) => {
|
|
872
|
-
let projectId = options?.projectId ?? instance.config.projectId;
|
|
873
|
-
if (!projectId) throw Error("A projectId is required to use the project API.");
|
|
874
|
-
return projectId;
|
|
875
|
-
},
|
|
876
|
-
fetcher: (instance) => (options) => getClientState(instance, {
|
|
778
|
+
const datasets = defineFetcher({
|
|
779
|
+
name: "datasets",
|
|
780
|
+
getKey: resolveProjectId,
|
|
781
|
+
fetch: (instance) => (options) => getClientState(instance, {
|
|
877
782
|
apiVersion: "v2025-02-19",
|
|
878
|
-
projectId:
|
|
783
|
+
projectId: resolveProjectId(instance, options),
|
|
879
784
|
useProjectHostname: !0
|
|
880
785
|
}).observable.pipe(switchMap((client) => client.observable.datasets.list()))
|
|
881
|
-
})
|
|
786
|
+
});
|
|
882
787
|
/**
|
|
883
788
|
* The id of the specific document a user is editing under a given perspective:
|
|
884
789
|
* the draft, the published document, or a release version.
|
|
@@ -1349,7 +1254,7 @@ const patchOperations = {
|
|
|
1349
1254
|
* [- source](https://www.sanity.io/docs/http-mutations#c732f27330a4)
|
|
1350
1255
|
*/
|
|
1351
1256
|
function getId(id) {
|
|
1352
|
-
return !id || typeof id != "string" ?
|
|
1257
|
+
return !id || typeof id != "string" ? randomUuid() : id.endsWith(".") ? `${id}${randomUuid()}` : id;
|
|
1353
1258
|
}
|
|
1354
1259
|
function getDocumentIds(selection) {
|
|
1355
1260
|
if ("id" in selection) {
|
|
@@ -1881,7 +1786,7 @@ const _calculatePermissions = createSelector([
|
|
|
1881
1786
|
try {
|
|
1882
1787
|
processActions({
|
|
1883
1788
|
actions,
|
|
1884
|
-
transactionId:
|
|
1789
|
+
transactionId: randomId(16),
|
|
1885
1790
|
working: documents,
|
|
1886
1791
|
base: documents,
|
|
1887
1792
|
timestamp,
|
|
@@ -2717,7 +2622,8 @@ function cleanupOutgoingTransaction(prev) {
|
|
|
2717
2622
|
for (let transactionId of outgoing.batchedTransactionIds) for (let documentId of ids) next = removeSubscriptionIdFromDocument(next, documentId, transactionId);
|
|
2718
2623
|
return {
|
|
2719
2624
|
...next,
|
|
2720
|
-
outgoing: void 0
|
|
2625
|
+
outgoing: void 0,
|
|
2626
|
+
documentStates: evictOrphanedDocumentStates(next.documentStates)
|
|
2721
2627
|
};
|
|
2722
2628
|
}
|
|
2723
2629
|
function revertOutgoingTransaction(prev) {
|
|
@@ -2747,11 +2653,16 @@ function revertOutgoingTransaction(prev) {
|
|
|
2747
2653
|
...base,
|
|
2748
2654
|
applied: nextApplied,
|
|
2749
2655
|
outgoing: void 0,
|
|
2750
|
-
documentStates: Object.fromEntries(Object.entries(base.documentStates).filter((e) => !!e[1]).map(([documentId,
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2656
|
+
documentStates: evictOrphanedDocumentStates(Object.fromEntries(Object.entries(base.documentStates).filter((e) => !!e[1]).map(([documentId, documentState]) => {
|
|
2657
|
+
let { unverifiedRevisions = {} } = documentState, next = {
|
|
2658
|
+
...documentState,
|
|
2659
|
+
unverifiedRevisions: prev.outgoing && prev.outgoing.transactionId in unverifiedRevisions ? omitProperty(unverifiedRevisions, prev.outgoing.transactionId) : unverifiedRevisions
|
|
2660
|
+
};
|
|
2661
|
+
return !next.subscriptions.length && isAwaitingOwnEcho(next) ? [documentId, next] : [documentId, {
|
|
2662
|
+
...next,
|
|
2663
|
+
local: documentId in working ? working[documentId] : next.local
|
|
2664
|
+
}];
|
|
2665
|
+
})))
|
|
2755
2666
|
};
|
|
2756
2667
|
}
|
|
2757
2668
|
/**
|
|
@@ -2792,7 +2703,7 @@ function applyRemoteDocument(prev, { document, documentId, previousRev, revision
|
|
|
2792
2703
|
let modifiesDocument = (transaction) => transaction.working[documentId]?._rev !== transaction.previousRevs[documentId], local = !prev.applied.some(modifiesDocument) && (!prev.outgoing || prev.outgoing.transactionId === revision || !modifiesDocument(prev.outgoing)) && !isDeepEqual(prevDocState.local, document) ? document : prevDocState.local;
|
|
2793
2704
|
return {
|
|
2794
2705
|
...prev,
|
|
2795
|
-
documentStates: {
|
|
2706
|
+
documentStates: evictOrphanedDocumentStates({
|
|
2796
2707
|
...prev.documentStates,
|
|
2797
2708
|
[documentId]: {
|
|
2798
2709
|
...prevDocState,
|
|
@@ -2801,7 +2712,7 @@ function applyRemoteDocument(prev, { document, documentId, previousRev, revision
|
|
|
2801
2712
|
local,
|
|
2802
2713
|
unverifiedRevisions
|
|
2803
2714
|
}
|
|
2804
|
-
}
|
|
2715
|
+
})
|
|
2805
2716
|
};
|
|
2806
2717
|
}
|
|
2807
2718
|
let working = {
|
|
@@ -2836,7 +2747,7 @@ function applyRemoteDocument(prev, { document, documentId, previousRev, revision
|
|
|
2836
2747
|
return {
|
|
2837
2748
|
...prev,
|
|
2838
2749
|
applied: nextApplied,
|
|
2839
|
-
documentStates: {
|
|
2750
|
+
documentStates: evictOrphanedDocumentStates({
|
|
2840
2751
|
...prev.documentStates,
|
|
2841
2752
|
[documentId]: {
|
|
2842
2753
|
...prevDocState,
|
|
@@ -2845,7 +2756,7 @@ function applyRemoteDocument(prev, { document, documentId, previousRev, revision
|
|
|
2845
2756
|
local,
|
|
2846
2757
|
unverifiedRevisions
|
|
2847
2758
|
}
|
|
2848
|
-
}
|
|
2759
|
+
})
|
|
2849
2760
|
};
|
|
2850
2761
|
}
|
|
2851
2762
|
function addSubscriptionIdToDocument(prev, documentId, subscriptionId) {
|
|
@@ -2863,8 +2774,13 @@ function addSubscriptionIdToDocument(prev, documentId, subscriptionId) {
|
|
|
2863
2774
|
};
|
|
2864
2775
|
}
|
|
2865
2776
|
function removeSubscriptionIdFromDocument(prev, documentId, subscriptionId) {
|
|
2866
|
-
let prevDocState = prev.documentStates?.[documentId]
|
|
2867
|
-
|
|
2777
|
+
let prevDocState = prev.documentStates?.[documentId];
|
|
2778
|
+
if (!prevDocState) return prev;
|
|
2779
|
+
let subscriptions = prevDocState.subscriptions.filter((id) => id !== subscriptionId);
|
|
2780
|
+
return !subscriptions.length && !isAwaitingOwnEcho(prevDocState) ? {
|
|
2781
|
+
...prev,
|
|
2782
|
+
documentStates: omitProperty(prev.documentStates, documentId)
|
|
2783
|
+
} : {
|
|
2868
2784
|
...prev,
|
|
2869
2785
|
documentStates: {
|
|
2870
2786
|
...prev.documentStates,
|
|
@@ -2873,13 +2789,49 @@ function removeSubscriptionIdFromDocument(prev, documentId, subscriptionId) {
|
|
|
2873
2789
|
subscriptions
|
|
2874
2790
|
}
|
|
2875
2791
|
}
|
|
2876
|
-
}
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2792
|
+
};
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
* Whether this document still expects the listener echo of one of its own
|
|
2796
|
+
* submitted transactions. That expectation is the only reason a document state
|
|
2797
|
+
* with no subscribers is kept around.
|
|
2798
|
+
*
|
|
2799
|
+
* Revisions stop counting after `UNVERIFIED_REVISION_RETENTION_TIME` because an
|
|
2800
|
+
* echo is not guaranteed to arrive at all: Content Lake records no transaction
|
|
2801
|
+
* when every operation resolves to a no-op (e.g. a keyed path that no longer
|
|
2802
|
+
* exists), while the client bumps `_rev` regardless and so tracks a revision
|
|
2803
|
+
* for it. Without the expiry, such a document (and the listener keyed off its
|
|
2804
|
+
* state) would be pinned for the lifetime of the store.
|
|
2805
|
+
*
|
|
2806
|
+
* `recentOwnTransactionIds` deliberately does not extend the wait: it is capped
|
|
2807
|
+
* rather than drained, so honoring it would keep every edited document alive.
|
|
2808
|
+
*/
|
|
2809
|
+
function isAwaitingOwnEcho(documentState) {
|
|
2810
|
+
let expiresAfter = Date.now() - 3e4;
|
|
2811
|
+
return Object.values(documentState.unverifiedRevisions ?? {}).some((revision) => !!revision && new Date(revision.timestamp).getTime() > expiresAfter);
|
|
2812
|
+
}
|
|
2813
|
+
/**
|
|
2814
|
+
* Removes every document state that has no subscribers left and no own
|
|
2815
|
+
* transaction still awaiting its echo.
|
|
2816
|
+
*
|
|
2817
|
+
* This is a sweep rather than a decision made where the last subscriber leaves
|
|
2818
|
+
* because `removeSubscriptionIdFromDocument` defers that eviction while an echo
|
|
2819
|
+
* is in flight, and both halves of the condition can change without a
|
|
2820
|
+
* subscriber going anywhere: the echo can verify, be dropped by a sync, be
|
|
2821
|
+
* discarded by a revert, or simply never arrive. Every reducer that can settle
|
|
2822
|
+
* an in-flight transaction sweeps, so the deferred decision is always re-made.
|
|
2823
|
+
*
|
|
2824
|
+
* Note this can evict the very document whose remote event is being processed,
|
|
2825
|
+
* which synchronously unsubscribes that document's listener from inside its own
|
|
2826
|
+
* emission (see `subscribeToSubscriptionsAndListenToDocuments`).
|
|
2827
|
+
*/
|
|
2828
|
+
function evictOrphanedDocumentStates(documentStates) {
|
|
2829
|
+
let next = documentStates;
|
|
2830
|
+
for (let [documentId, documentState] of Object.entries(documentStates)) documentState && (documentState.subscriptions.length || isAwaitingOwnEcho(documentState) || (next = omitProperty(next, documentId)));
|
|
2831
|
+
return next;
|
|
2880
2832
|
}
|
|
2881
2833
|
function manageSubscriberIds({ state }, handles) {
|
|
2882
|
-
let documentIds = getDocumentIdsFromHandleLikes(handles), subscriptionId =
|
|
2834
|
+
let documentIds = getDocumentIdsFromHandleLikes(handles), subscriptionId = randomId(16);
|
|
2883
2835
|
return state.set("addSubscribers", (prev) => documentIds.reduce((acc, id) => addSubscriptionIdToDocument(acc, id, subscriptionId), prev)), () => {
|
|
2884
2836
|
setCleanupTimeout(() => {
|
|
2885
2837
|
state.set("removeSubscribers", (prev) => documentIds.reduce((acc, id) => removeSubscriptionIdFromDocument(acc, id, subscriptionId), prev));
|
|
@@ -3229,13 +3181,13 @@ const _resolveDocument = bindActionByResource(documentStore, ({ instance }, docH
|
|
|
3229
3181
|
let clientOptions = {
|
|
3230
3182
|
apiVersion: API_VERSION$4,
|
|
3231
3183
|
resource
|
|
3232
|
-
},
|
|
3233
|
-
if (resource && isDatasetResource(resource))
|
|
3234
|
-
else if (resource && isMediaLibraryResource(resource))
|
|
3235
|
-
else if (resource && isCanvasResource(resource))
|
|
3184
|
+
}, url;
|
|
3185
|
+
if (resource && isDatasetResource(resource)) url = `/projects/${resource.projectId}/datasets/${resource.dataset}/acl`;
|
|
3186
|
+
else if (resource && isMediaLibraryResource(resource)) url = `/media-libraries/${resource.mediaLibraryId}/acl`;
|
|
3187
|
+
else if (resource && isCanvasResource(resource)) url = `/canvases/${resource.canvasId}/acl`;
|
|
3236
3188
|
else throw Error(`Received invalid resource: ${JSON.stringify(resource)}`);
|
|
3237
3189
|
return getClientState(instance, clientOptions).observable.pipe(switchMap((client) => client.observable.request({
|
|
3238
|
-
|
|
3190
|
+
url,
|
|
3239
3191
|
tag: "acl.get"
|
|
3240
3192
|
}).pipe(retry({ delay: (error, retryCount) => {
|
|
3241
3193
|
let isTransientClientError = error instanceof ClientError && (error.statusCode === 408 || error.statusCode === 429);
|
|
@@ -3313,7 +3265,7 @@ function applyDocumentActions(...args) {
|
|
|
3313
3265
|
}
|
|
3314
3266
|
const boundApplyDocumentActions = bindActionByResource(documentStore, _applyDocumentActions);
|
|
3315
3267
|
/** @internal */
|
|
3316
|
-
async function _applyDocumentActions({ state }, { actions, resource, transactionId =
|
|
3268
|
+
async function _applyDocumentActions({ state }, { actions, resource, transactionId = randomUuid(), disableBatching }) {
|
|
3317
3269
|
let { events } = state.get(), transaction = {
|
|
3318
3270
|
transactionId,
|
|
3319
3271
|
actions: normalizeActionsForResource(actions, resource),
|
|
@@ -3354,10 +3306,20 @@ async function _applyDocumentActions({ state }, { actions, resource, transaction
|
|
|
3354
3306
|
function createFavoriteKey(context) {
|
|
3355
3307
|
return `${context.documentId}:${context.documentType}:${context.resourceId}:${context.resourceType}${context.schemaName ? `:${context.schemaName}` : ""}`;
|
|
3356
3308
|
}
|
|
3357
|
-
|
|
3358
|
-
|
|
3309
|
+
/**
|
|
3310
|
+
* Fetcher for a document's favorite status, read from the dashboard over
|
|
3311
|
+
* comlink, on the shared fetcher cache.
|
|
3312
|
+
*
|
|
3313
|
+
* @internal
|
|
3314
|
+
*/
|
|
3315
|
+
const favorites = defineFetcher({
|
|
3316
|
+
name: "favorites",
|
|
3359
3317
|
getKey: (_instance, context) => createFavoriteKey(context),
|
|
3360
|
-
|
|
3318
|
+
tags: (_data, context) => [{
|
|
3319
|
+
type: "favorite",
|
|
3320
|
+
id: createFavoriteKey(context)
|
|
3321
|
+
}],
|
|
3322
|
+
fetch: (instance) => (context) => {
|
|
3361
3323
|
let nodeStateSource = getNodeState(instance, {
|
|
3362
3324
|
name: SDK_NODE_NAME,
|
|
3363
3325
|
connectTo: SDK_CHANNEL_NAME
|
|
@@ -3370,12 +3332,42 @@ const favorites = createFetcherStore({
|
|
|
3370
3332
|
schemaName: context.schemaName
|
|
3371
3333
|
}
|
|
3372
3334
|
} };
|
|
3373
|
-
return nodeStateSource.observable.pipe(
|
|
3335
|
+
return nodeStateSource.observable.pipe(first((nodeState) => !!nodeState), switchMap((nodeState) => {
|
|
3374
3336
|
let node = nodeState.node;
|
|
3375
3337
|
return from(node.fetch("dashboard/v1/events/favorite/query", payload)).pipe(map((response) => ({ isFavorited: response.isFavorited })), catchError((err) => (console.error("Favorites service connection error", err), of({ isFavorited: !1 }))));
|
|
3376
3338
|
}));
|
|
3377
3339
|
}
|
|
3378
|
-
}),
|
|
3340
|
+
}), setFavorite = defineMutation({
|
|
3341
|
+
name: "setFavorite",
|
|
3342
|
+
mutationFn: (instance) => ({ isFavorited, ...context }) => {
|
|
3343
|
+
let nodeStateSource = getNodeState(instance, {
|
|
3344
|
+
name: SDK_NODE_NAME,
|
|
3345
|
+
connectTo: SDK_CHANNEL_NAME
|
|
3346
|
+
}), payload = {
|
|
3347
|
+
eventType: isFavorited ? "added" : "removed",
|
|
3348
|
+
document: {
|
|
3349
|
+
id: context.documentId,
|
|
3350
|
+
type: context.documentType,
|
|
3351
|
+
resource: {
|
|
3352
|
+
id: context.resourceId,
|
|
3353
|
+
type: context.resourceType,
|
|
3354
|
+
...context.schemaName ? { schemaName: context.schemaName } : {}
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
};
|
|
3358
|
+
return nodeStateSource.observable.pipe(first((nodeState) => !!nodeState), switchMap((nodeState) => {
|
|
3359
|
+
let node = nodeState.node;
|
|
3360
|
+
return from(node.fetch("dashboard/v1/events/favorite/mutate", payload)).pipe(map((response) => {
|
|
3361
|
+
if (!response.success) throw Error("Failed to update favorite status");
|
|
3362
|
+
return { isFavorited };
|
|
3363
|
+
}));
|
|
3364
|
+
}));
|
|
3365
|
+
},
|
|
3366
|
+
invalidates: (_result, input) => [{
|
|
3367
|
+
type: "favorite",
|
|
3368
|
+
id: createFavoriteKey(input)
|
|
3369
|
+
}]
|
|
3370
|
+
});
|
|
3379
3371
|
/** The API takes `include` as a comma-separated list; sorted so key and query agree */
|
|
3380
3372
|
function serializeInclude(include) {
|
|
3381
3373
|
return include?.length ? [...include].sort().join(",") : void 0;
|
|
@@ -3399,7 +3391,7 @@ const installations = defineFetcher({
|
|
|
3399
3391
|
apiVersion: "vX",
|
|
3400
3392
|
scope: "global"
|
|
3401
3393
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
3402
|
-
|
|
3394
|
+
url: "/installations",
|
|
3403
3395
|
query: buildQuery({
|
|
3404
3396
|
organizationId: options.organizationId,
|
|
3405
3397
|
include: serializeInclude(options.include),
|
|
@@ -3422,7 +3414,7 @@ const installations = defineFetcher({
|
|
|
3422
3414
|
apiVersion: "vX",
|
|
3423
3415
|
scope: "global"
|
|
3424
3416
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
3425
|
-
|
|
3417
|
+
url: `/installations/${installationId}`,
|
|
3426
3418
|
query: buildQuery({ include: serializeInclude(options?.include) }),
|
|
3427
3419
|
tag: "installations.get"
|
|
3428
3420
|
}))),
|
|
@@ -3462,7 +3454,7 @@ const organization = defineFetcher({
|
|
|
3462
3454
|
apiVersion: "v2025-02-19",
|
|
3463
3455
|
scope: "global"
|
|
3464
3456
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
3465
|
-
|
|
3457
|
+
url: `/organizations/${resolveOrganizationId(options)}`,
|
|
3466
3458
|
query: buildQuery(normalizeOrganizationOptions(options)),
|
|
3467
3459
|
tag: "organizations.get"
|
|
3468
3460
|
}))),
|
|
@@ -3496,7 +3488,7 @@ const organizations = defineFetcher({
|
|
|
3496
3488
|
apiVersion: "v2025-02-19",
|
|
3497
3489
|
scope: "global"
|
|
3498
3490
|
}).observable.pipe(switchMap((client) => client.observable.request({
|
|
3499
|
-
|
|
3491
|
+
url: "/organizations",
|
|
3500
3492
|
query: buildQuery(normalizeOrganizationsOptions(options)),
|
|
3501
3493
|
tag: "organizations.list"
|
|
3502
3494
|
}))),
|
|
@@ -3533,7 +3525,7 @@ const organizations = defineFetcher({
|
|
|
3533
3525
|
useProjectHostname: !0
|
|
3534
3526
|
}).observable.request({
|
|
3535
3527
|
method: "GET",
|
|
3536
|
-
|
|
3528
|
+
url: `/users/${userId}`,
|
|
3537
3529
|
tag: "users.get"
|
|
3538
3530
|
}).pipe(map((user) => ({
|
|
3539
3531
|
data: [{
|
|
@@ -3562,7 +3554,7 @@ const organizations = defineFetcher({
|
|
|
3562
3554
|
}), resourceType = options.resourceType || "project", resourceId = resourceType === "organization" ? options.organizationId : options.projectId;
|
|
3563
3555
|
return resourceId ? client.observable.request({
|
|
3564
3556
|
method: "GET",
|
|
3565
|
-
|
|
3557
|
+
url: `access/${resourceType}/${resourceId}/users/${userId}`,
|
|
3566
3558
|
tag: "users.get"
|
|
3567
3559
|
}).pipe(map((response) => "sanityUserId" in response ? {
|
|
3568
3560
|
data: [response],
|
|
@@ -3586,7 +3578,7 @@ const organizations = defineFetcher({
|
|
|
3586
3578
|
loadMore$
|
|
3587
3579
|
]).pipe(withLatestFrom(cursor$), switchMap(([[resource, client], cursor]) => client.observable.request({
|
|
3588
3580
|
method: "GET",
|
|
3589
|
-
|
|
3581
|
+
url: `access/${resource.type}/${resource.id}/users`,
|
|
3590
3582
|
tag: "users.list",
|
|
3591
3583
|
query: cursor ? {
|
|
3592
3584
|
nextCursor: cursor,
|
|
@@ -3608,7 +3600,7 @@ const organizations = defineFetcher({
|
|
|
3608
3600
|
};
|
|
3609
3601
|
}),
|
|
3610
3602
|
onSubscribe: ({ instance, state }, options) => {
|
|
3611
|
-
let subscriptionId =
|
|
3603
|
+
let subscriptionId = randomId(16), key = getUsersKey(instance, options);
|
|
3612
3604
|
return state.set("addSubscription", addSubscription(subscriptionId, key)), () => {
|
|
3613
3605
|
setCleanupTimeout(() => state.set("removeSubscription", removeSubscription(subscriptionId, key)), USERS_STATE_CLEAR_DELAY);
|
|
3614
3606
|
};
|
|
@@ -3760,7 +3752,7 @@ const presenceStore = defineStore({
|
|
|
3760
3752
|
initialize: (context) => {
|
|
3761
3753
|
let { instance, state, key: { resource } } = context;
|
|
3762
3754
|
if (isMediaLibraryResource(resource)) throw Error("Presence is not supported for media library resources.");
|
|
3763
|
-
let sessionId =
|
|
3755
|
+
let sessionId = randomId(16), client = isDatasetResource(resource) ? getClient(instance, {
|
|
3764
3756
|
apiVersion: PRESENCE_API_VERSION,
|
|
3765
3757
|
projectId: resource.projectId,
|
|
3766
3758
|
dataset: resource.dataset,
|
|
@@ -3843,7 +3835,7 @@ const presenceStore = defineStore({
|
|
|
3843
3835
|
})), isCanvasResource(resource)) {
|
|
3844
3836
|
let globalClient = getClient(instance, { apiVersion: PRESENCE_API_VERSION });
|
|
3845
3837
|
subscription.add(globalClient.observable.request({
|
|
3846
|
-
|
|
3838
|
+
url: `/canvases/${resource.canvasId}`,
|
|
3847
3839
|
tag: "canvases.get"
|
|
3848
3840
|
}).subscribe({
|
|
3849
3841
|
next: ({ organizationId }) => {
|
|
@@ -4185,7 +4177,7 @@ const _getProjectionState = bindActionByResourceAndPerspective(projectionStore,
|
|
|
4185
4177
|
return state.values[documentId]?.[projectionHash] ?? STABLE_EMPTY_PROJECTION;
|
|
4186
4178
|
},
|
|
4187
4179
|
onSubscribe: ({ state }, options) => {
|
|
4188
|
-
let { projection, ...docHandle } = options, subscriptionId =
|
|
4180
|
+
let { projection, ...docHandle } = options, subscriptionId = randomId(16), documentId = getPublishedId(DocumentId(docHandle.documentId)), validProjection = validateProjection(projection), projectionHash = hashString(validProjection);
|
|
4189
4181
|
return state.set("addSubscription", (prev) => ({
|
|
4190
4182
|
documentProjections: {
|
|
4191
4183
|
...prev.documentProjections,
|
|
@@ -4273,6 +4265,6 @@ function isImportError(error) {
|
|
|
4273
4265
|
let message = error.message || "";
|
|
4274
4266
|
return /Loading chunk [\w-]+ failed/i.test(message) || /Failed to fetch dynamically imported module/i.test(message) || /error loading dynamically imported module/i.test(message) || /Import(?:ing)? a module script failed/i.test(message) || /Unable to preload CSS/i.test(message);
|
|
4275
4267
|
}
|
|
4276
|
-
export { AuthStateType, CORE_SDK_VERSION, application, applications, applyDocumentActions, archiveRelease, checkPermissions, configureLogging, createComment, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createProjectHandle, createRelease, createSanityInstance, deleteApplication, deleteDocument, deleteRelease, discardDocument, editDocument, editRelease, getActiveReleasesState, getAllReleasesState, getAuthState, getClient, getClientState, getCommentThreadsState, getCommentsState, getCorsErrorProjectId, getCurrentUserState, getDashboardOrganizationId,
|
|
4268
|
+
export { AuthStateType, CORE_SDK_VERSION, application, applications, applyDocumentActions, archiveRelease, checkPermissions, configureLogging, createComment, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createProjectHandle, createRelease, createSanityInstance, datasets, deleteApplication, deleteDocument, deleteRelease, discardDocument, editDocument, editRelease, favorites, getActiveReleasesState, getAllReleasesState, getAuthState, getClient, getClientState, getCommentThreadsState, getCommentsState, getCorsErrorProjectId, getCurrentUserState, getDashboardOrganizationId, getDocumentPresence, getDocumentState, getDocumentSyncStatus, getIndexForKey, getIsInDashboardState, getLoginUrlState, getPathDepth, getPermissionsState, getPerspectiveState, getPresence, getProjectionState, getQueryState, getReleaseDocumentId, getTokenState, getUserState, getUsersState, handleAuthCallback, installation, installations, isCanvasResource, isDatasetResource, isImportError, isMediaLibraryResource, joinPaths, jsonMatch, loadMoreUsers, logout, observeOrganizationVerificationState, organization, organizations, project, projects, publishDocument, publishRelease, removeComment, replyToComment, reportPresence, resolveCommentThreads, resolveComments, resolveDocument, resolvePermissions, resolveProjection, resolveQuery, resolveUser, resolveUsers, scheduleRelease, setAuthToken, setCommentStatus, setFavorite, slicePath, stringifyPath, subscribeDocumentEvents, unarchiveRelease, unpublishDocument, unscheduleRelease, updateApplication, updateComment };
|
|
4277
4269
|
|
|
4278
4270
|
//# sourceMappingURL=index.js.map
|