@sanity/sdk 2.20.2 → 2.21.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 +1 -1
- package/dist/_exports/_internal.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +74 -29
- package/dist/index.js.map +1 -1
- package/dist/{telemetryManager-BmGqzj0b.js → telemetryManager-BKcXNRX_.js} +2 -2
- package/dist/{telemetryManager-BmGqzj0b.js.map → telemetryManager-BKcXNRX_.js.map} +1 -1
- package/dist/{utils-BMwA8Kg9.d.ts → utils-E9GB-6Gs.d.ts} +19 -3
- package/dist/{utils-BMwA8Kg9.d.ts.map → utils-E9GB-6Gs.d.ts.map} +1 -1
- package/dist/{version-CPumgx0u.js → version-BAVcaHtM.js} +2 -2
- package/dist/{version-CPumgx0u.js.map → version-BAVcaHtM.js.map} +1 -1
- package/package.json +4 -4
- package/src/_exports/index.ts +1 -0
- package/src/auth/authStore.test.ts +32 -0
- package/src/document/documentConstants.ts +11 -0
- package/src/document/documentStore.test.ts +294 -2
- package/src/document/documentStore.ts +89 -43
- package/src/document/events.ts +17 -0
- package/src/document/submissionErrors.test.ts +63 -0
- package/src/document/submissionErrors.ts +51 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as parseQueryKey,
|
|
1
|
+
import { $ as parseQueryKey, G as parseUsersKey, I as createGroqSearchFilter, Mr as getCommentsOptionsKey, Pr as parseCommentsOptionsKey, Ui as isStudioConfig, Vi as SanityInstance, W as getUsersKey, Z as getQueryKey, _t as PREVIEW_PROJECTION, a as isProjectUserNotFoundClientError, gt as transformProjectionToPreview, i as getClientErrorApiType, n as getClientErrorApiBody, r as getClientErrorApiDescription, t as ApiErrorBody } from "../utils-E9GB-6Gs.js";
|
|
2
2
|
import { SanityClient } from "@sanity/client";
|
|
3
3
|
/**
|
|
4
4
|
* Manages telemetry for a single SDK instance.
|
|
@@ -95,7 +95,7 @@ function initTelemetry(instance, projectId) {
|
|
|
95
95
|
projectId,
|
|
96
96
|
environment
|
|
97
97
|
}), Promise.all([
|
|
98
|
-
import("../telemetryManager-
|
|
98
|
+
import("../telemetryManager-BKcXNRX_.js").then((n) => n.t),
|
|
99
99
|
import("../clientStore-CMzJ7XhZ.js").then((n) => n.t),
|
|
100
100
|
import("../authStore-CWTAuieY.js").then((n) => n.n)
|
|
101
101
|
]).then(async ([{ createTelemetryManager }, { getClient }, { getTokenState }]) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { $ as parseQueryKey, $i as
|
|
2
|
-
export { type Action, type ActionErrorEvent, type ActionsResult, type AgentGenerateOptions, type AgentGenerateResult, type AgentPatchOptions, type AgentPatchResult, type AgentPromptOptions, type AgentPromptResult, type AgentTransformOptions, type AgentTransformResult, type AgentTranslateOptions, type AgentTranslateResult, type ApiErrorBody, type ApplyDocumentActionsOptions, type ArchiveReleaseAction, type AuthConfig, type AuthProvider, type AuthState, AuthStateType, type AuthStoreState, CORE_SDK_VERSION, type CanvasResource, type CanvasSource, type ClientOptions, type ClientStoreState as ClientState, type ComlinkControllerState, type ComlinkNodeState, type Comment, type CommentLocalState, type CommentMessage, type CommentReaction, type CommentStatus, type CommentTextSelection, type CommentTextSelectionItem, type CommentThread, type CommentsOptions, type CreateCommentOptions, type CreateDocumentAction, type CreateReleaseAction, type CurrentUser, type DatasetHandle, type DatasetResource, type DatasetSource, type DeleteDocumentAction, type DeleteReleaseAction, type DiscardDocumentAction, type DisconnectEvent, type DocumentAction, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentDiscardedEvent, type DocumentEditedEvent, type DocumentEvent, type DocumentHandle, type DocumentOptions, type DocumentPermissionsResult, type DocumentPresence, type DocumentPresenceOptions, type DocumentPublishedEvent, type DocumentRemotePatchesEvent, type DocumentResource, type DocumentSource, type DocumentTransactionSubmissionResult, type DocumentTypeHandle, type DocumentUnpublishedEvent, type EditDocumentAction, type EditDocumentOptions, type EditReleaseAction, type ErrorAuthState, type FavoriteStatusResponse, type FetcherStore, type FetcherStoreState, type FrameMessage, type GetPreviewStateOptions, type GetUserOptions, type GetUsersOptions, type InstanceContext, type Intent, type IntentFilter, type JsonMatch, type LogContext, type LogLevel, type LogNamespace, type LoggedInAuthState, type LoggedOutAuthState, type Logger, type LoggerConfig, type LoggingInAuthState, type MediaLibraryResource, type MediaLibrarySource, type Membership, type NewTokenResponseMessage, type NodeState, type OrgVerificationResult, type Organization, type OrganizationBase, type OrganizationMember, type OrganizationOptions, type Organizations, type OrganizationsOptions, PREVIEW_PROJECTION, type PermissionDeniedReason, type PerspectiveHandle, type PresenceLocation, type PresencePerspectiveOptions, type PresenceSelection, type PresenceSelectionPoint, type PreviewMedia, type PreviewQueryResult, type PreviewStoreState, type PreviewValue, type Project, type ProjectBase, type ProjectHandle, type ProjectMember, type ProjectMemberRole, type ProjectMetadata, type ProjectOptions, type ProjectionValuePending, type ProjectsOptions, type PublishDocumentAction, type PublishReleaseAction, type QueryOptions, type ReleaseAction, type ReleaseDocument, type ReleaseHandle, type ReleasePerspective, type ReleaseState, type RemoveCommentOptions, type ReplyToCommentOptions, type ReportPresenceOptions, type RequestNewTokenMessage, type ResolveCommentsOptions, type ResolvePreviewOptions, type ResolveUserOptions, type ResolveUsersOptions, type Role, type RollCallEvent, type SanityConfig, type SanityDocument, type SanityInstance, SanityProject, type SanityUser, type SanityUserResponse, type ScheduleReleaseAction, type Selector, type SetCommentStatusOptions, type StateEvent, type StateSource, type StudioConfig, type TokenSource, type TransactionAcceptedEvent, type TransactionRevertedEvent, type TransportEvent, type UnarchiveReleaseAction, type UnpublishDocumentAction, type UnscheduleReleaseAction, type UpdateCommentOptions, type UserPresence, type UserProfile, type UsersGroupState, type UsersStoreState, type ValidProjection, type ValuePending, type WindowMessage, agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate, applyDocumentActions, archiveRelease, configureLogging, createComment, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createRelease, createSanityInstance, defineIntent, deleteDocument, deleteRelease, destroyController, discardDocument, editDocument, editRelease, getActiveReleasesState, getAllReleasesState, getAuthState, getClient, getClientErrorApiBody, getClientErrorApiDescription, getClientErrorApiType, getClientState, getCommentThreadsState, getCommentsState, getCorsErrorProjectId, getCurrentUserState, getDashboardOrganizationId, getDatasetsState, getDocumentPresence, getDocumentState, getDocumentSyncStatus, getFavoritesState, getIndexForKey, getIsInDashboardState, getLoginUrlState, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, getOrganizationState, getOrganizationsState, getPathDepth, getPermissionsState, getPerspectiveState, getPresence, getPreviewState, getProjectState, getProjectionState, getProjectsState, getQueryKey, getQueryState, getReleaseDocumentId, getTokenState, getUserState, getUsersKey, getUsersState, handleAuthCallback, isCanvasResource, isCanvasSource, isDatasetResource, isDatasetSource, isImportError, isMediaLibraryResource, isMediaLibrarySource, isProjectUserNotFoundClientError, isStudioConfig, joinPaths, jsonMatch, loadMoreUsers, logout, observeOrganizationVerificationState, parseQueryKey, parseUsersKey, publishDocument, publishRelease, releaseChannel, releaseNode, removeComment, replyToComment, reportPresence, resolveCommentThreads, resolveComments, resolveDatasets, resolveDocument, resolveFavoritesState, resolveOrganization, resolveOrganizations, resolvePermissions, resolvePreview, resolveProject, resolveProjection, resolveProjects, resolveQuery, resolveUser, resolveUsers, scheduleRelease, setAuthToken, setCommentStatus, slicePath, stringifyPath, subscribeDocumentEvents, transformProjectionToPreview, unarchiveRelease, unpublishDocument, unscheduleRelease, updateComment };
|
|
1
|
+
import { $ as parseQueryKey, $i as MediaLibraryResource, $n as UnarchiveReleaseAction, $r as CommentStatus, $t as OrganizationsOptions, A as CORE_SDK_VERSION, Ai as AgentPromptOptions, An as getDocumentSyncStatus, Ar as ResolveCommentsOptions, At as DisconnectEvent, B as getUsersState, Bi as agentTranslate, Bn as CreateDocumentAction, Br as RemoveCommentOptions, Bt as TransportEvent, C as SanityProject, Ci as observeOrganizationVerificationState, Cn as DocumentTransactionSubmissionResult, Cr as Logger, Ct as PreviewValue, D as jsonMatch, Di as AgentGenerateResult, Dn as TransactionSubmissionFailedEvent, Dr as createDocumentTypeHandle, Dt as getDocumentPresence, E as joinPaths, Ei as AgentGenerateOptions, En as TransactionRevertedEvent, Er as createDocumentHandle, Et as ValidProjection, F as defineIntent, Fi as AgentTranslateResult, Fn as DocumentPermissionsResult, Fr as resolveCommentThreads, Ft as PresenceSelection, G as parseUsersKey, Gi as CanvasSource, Gn as DocumentAction, Gr as removeComment, Gt as ResolveUserOptions, H as resolveUser, Hi as createSanityInstance, Hn as DeleteDocumentAction, Hr as SetCommentStatusOptions, Ht as GetUserOptions, I as createGroqSearchFilter, Ii as agentGenerate, In as PermissionDeniedReason, Ir as resolveComments, It as PresenceSelectionPoint, J as getActiveReleasesState, Ji as DatasetSource, Jn as EditReleaseAction, Jr as updateComment, Jt as SanityUserResponse, K as getPerspectiveState, Ki as DatasetHandle, Kn as EditDocumentAction, Kr as replyToComment, Kt as ResolveUsersOptions, L as FetcherStore, Li as agentPatch, Ln as JsonMatch, Lr as Selector, Lt as ReportPresenceOptions, M as getCorsErrorProjectId, Mi as AgentTransformOptions, Mn as resolveDocument, Mt as DocumentPresenceOptions, N as Intent, Ni as AgentTransformResult, Nn as resolvePermissions, Nr as getCommentsState, Nt as PresenceLocation, O as slicePath, Oi as AgentPatchOptions, On as DocumentOptions, Or as createProjectHandle, Ot as getPresence, P as IntentFilter, Pi as AgentTranslateOptions, Pn as subscribeDocumentEvents, Pt as PresencePerspectiveOptions, Q as getQueryState, Qi as DocumentTypeHandle, Qn as ScheduleReleaseAction, Qr as CommentReaction, Qt as Organizations, R as FetcherStoreState, Ri as agentPrompt, Rn as Action, Rr as StateSource, Rt as RollCallEvent, S as SanityDocument, Si as handleAuthCallback, Sn as DocumentRemotePatchesEvent, Sr as LogNamespace, St as PreviewStoreState, T as getPathDepth, Ti as AuthStateType, Tn as TransactionAcceptedEvent, Tr as createDatasetHandle, Tt as ProjectionValuePending, U as resolveUsers, Ui as isStudioConfig, Un as DeleteReleaseAction, Ur as UpdateCommentOptions, Ut as GetUsersOptions, V as loadMoreUsers, Vi as SanityInstance, Vn as CreateReleaseAction, Vr as ReplyToCommentOptions, Vt as UserPresence, W as getUsersKey, Wi as CanvasResource, Wn as DiscardDocumentAction, Wr as createComment, Wt as Membership, X as QueryOptions, Xi as DocumentResource, Xn as PublishReleaseAction, Xr as CommentLocalState, Xt as UsersGroupState, Y as getAllReleasesState, Yi as DocumentHandle, Yn as PublishDocumentAction, Yr as Comment, Yt as UserProfile, Z as getQueryKey, Zi as DocumentSource, Zn as ReleaseAction, Zr as CommentMessage, Zt as UsersStoreState, _ as getTokenState, _i as ClientOptions, _n as DocumentDeletedEvent, _r as resolveDatasets, _t as PREVIEW_PROJECTION, a as isProjectUserNotFoundClientError, aa as SanityConfig, ai as ComlinkNodeState, an as OrganizationOptions, ar as deleteDocument, at as getProjectionState, b as ReleaseDocument, bi as getClientState, bn as DocumentEvent, br as LogContext, bt as PreviewMedia, c as ErrorAuthState, ca as isCanvasResource, ci as ComlinkControllerState, cn as FavoriteStatusResponse, cr as editDocument, ct as ProjectMember, d as LoggingInAuthState, da as isDatasetSource, di as getOrCreateController, dn as getReleaseDocumentId, dr as publishRelease, dt as ProjectOptions, ea as MediaLibrarySource, ei as CommentTextSelection, en as getOrganizationsState, er as UnpublishDocumentAction, et as resolveQuery, f as getAuthState, fa as isMediaLibraryResource, fi as releaseChannel, fn as ActionsResult, fr as scheduleRelease, ft as getProjectState, g as getLoginUrlState, gi as WindowMessage, gn as DocumentCreatedEvent, gr as getDatasetsState, gt as transformProjectionToPreview, h as getIsInDashboardState, ha as AuthProvider, hi as RequestNewTokenMessage, hn as ActionErrorEvent, hr as unscheduleRelease, ht as resolvePreview, i as getClientErrorApiType, ia as ReleasePerspective, ii as getNodeState, in as OrganizationMember, ir as createRelease, it as resolveProjection, j as isImportError, ji as AgentPromptResult, jn as getPermissionsState, jr as getCommentThreadsState, jt as DocumentPresence, k as stringifyPath, ki as AgentPatchResult, kn as getDocumentState, kr as CommentsOptions, kt as reportPresence, l as LoggedInAuthState, la as isCanvasSource, li as destroyController, ln as getFavoritesState, lr as editRelease, lt as ProjectMemberRole, m as getDashboardOrganizationId, ma as AuthConfig, mi as NewTokenResponseMessage, mn as applyDocumentActions, mr as unpublishDocument, mt as ResolvePreviewOptions, n as getClientErrorApiBody, na as ProjectHandle, ni as CommentThread, nn as Organization, nr as archiveRelease, nt as getProjectsState, o as AuthState, oa as StudioConfig, oi as getOrCreateNode, on as getOrganizationState, or as deleteRelease, ot as Project, p as getCurrentUserState, pa as isMediaLibrarySource, pi as FrameMessage, pn as ApplyDocumentActionsOptions, pr as unarchiveRelease, pt as resolveProject, q as ReleaseState, qi as DatasetResource, qn as EditDocumentOptions, qr as setCommentStatus, qt as SanityUser, r as getClientErrorApiDescription, ra as ReleaseHandle, ri as NodeState, rn as OrganizationBase, rr as createDocument, rt as resolveProjects, s as AuthStoreState, sa as TokenSource, si as releaseNode, sn as resolveOrganization, sr as discardDocument, st as ProjectBase, t as ApiErrorBody, ta as PerspectiveHandle, ti as CommentTextSelectionItem, tn as resolveOrganizations, tr as UnscheduleReleaseAction, tt as ProjectsOptions, u as LoggedOutAuthState, ua as isDatasetResource, ui as getOrCreateChannel, un as resolveFavoritesState, ur as publishDocument, ut as ProjectMetadata, v as setAuthToken, vi as ClientStoreState, vn as DocumentDiscardedEvent, vr as configureLogging, vt as GetPreviewStateOptions, w as getIndexForKey, wi as OrgVerificationResult, wn as DocumentUnpublishedEvent, wr as LoggerConfig, wt as ValuePending, x as Role, xi as logout, xn as DocumentPublishedEvent, xr as LogLevel, xt as PreviewQueryResult, y as CurrentUser, yi as getClient, yn as DocumentEditedEvent, yr as InstanceContext, yt as getPreviewState, z as getUserState, zi as agentTransform, zn as ArchiveReleaseAction, zr as CreateCommentOptions, zt as StateEvent } from "./utils-E9GB-6Gs.js";
|
|
2
|
+
export { type Action, type ActionErrorEvent, type ActionsResult, type AgentGenerateOptions, type AgentGenerateResult, type AgentPatchOptions, type AgentPatchResult, type AgentPromptOptions, type AgentPromptResult, type AgentTransformOptions, type AgentTransformResult, type AgentTranslateOptions, type AgentTranslateResult, type ApiErrorBody, type ApplyDocumentActionsOptions, type ArchiveReleaseAction, type AuthConfig, type AuthProvider, type AuthState, AuthStateType, type AuthStoreState, CORE_SDK_VERSION, type CanvasResource, type CanvasSource, type ClientOptions, type ClientStoreState as ClientState, type ComlinkControllerState, type ComlinkNodeState, type Comment, type CommentLocalState, type CommentMessage, type CommentReaction, type CommentStatus, type CommentTextSelection, type CommentTextSelectionItem, type CommentThread, type CommentsOptions, type CreateCommentOptions, type CreateDocumentAction, type CreateReleaseAction, type CurrentUser, type DatasetHandle, type DatasetResource, type DatasetSource, type DeleteDocumentAction, type DeleteReleaseAction, type DiscardDocumentAction, type DisconnectEvent, type DocumentAction, type DocumentCreatedEvent, type DocumentDeletedEvent, type DocumentDiscardedEvent, type DocumentEditedEvent, type DocumentEvent, type DocumentHandle, type DocumentOptions, type DocumentPermissionsResult, type DocumentPresence, type DocumentPresenceOptions, type DocumentPublishedEvent, type DocumentRemotePatchesEvent, type DocumentResource, type DocumentSource, type DocumentTransactionSubmissionResult, type DocumentTypeHandle, type DocumentUnpublishedEvent, type EditDocumentAction, type EditDocumentOptions, type EditReleaseAction, type ErrorAuthState, type FavoriteStatusResponse, type FetcherStore, type FetcherStoreState, type FrameMessage, type GetPreviewStateOptions, type GetUserOptions, type GetUsersOptions, type InstanceContext, type Intent, type IntentFilter, type JsonMatch, type LogContext, type LogLevel, type LogNamespace, type LoggedInAuthState, type LoggedOutAuthState, type Logger, type LoggerConfig, type LoggingInAuthState, type MediaLibraryResource, type MediaLibrarySource, type Membership, type NewTokenResponseMessage, type NodeState, type OrgVerificationResult, type Organization, type OrganizationBase, type OrganizationMember, type OrganizationOptions, type Organizations, type OrganizationsOptions, PREVIEW_PROJECTION, type PermissionDeniedReason, type PerspectiveHandle, type PresenceLocation, type PresencePerspectiveOptions, type PresenceSelection, type PresenceSelectionPoint, type PreviewMedia, type PreviewQueryResult, type PreviewStoreState, type PreviewValue, type Project, type ProjectBase, type ProjectHandle, type ProjectMember, type ProjectMemberRole, type ProjectMetadata, type ProjectOptions, type ProjectionValuePending, type ProjectsOptions, type PublishDocumentAction, type PublishReleaseAction, type QueryOptions, type ReleaseAction, type ReleaseDocument, type ReleaseHandle, type ReleasePerspective, type ReleaseState, type RemoveCommentOptions, type ReplyToCommentOptions, type ReportPresenceOptions, type RequestNewTokenMessage, type ResolveCommentsOptions, type ResolvePreviewOptions, type ResolveUserOptions, type ResolveUsersOptions, type Role, type RollCallEvent, type SanityConfig, type SanityDocument, type SanityInstance, SanityProject, type SanityUser, type SanityUserResponse, type ScheduleReleaseAction, type Selector, type SetCommentStatusOptions, type StateEvent, type StateSource, type StudioConfig, type TokenSource, type TransactionAcceptedEvent, type TransactionRevertedEvent, type TransactionSubmissionFailedEvent, type TransportEvent, type UnarchiveReleaseAction, type UnpublishDocumentAction, type UnscheduleReleaseAction, type UpdateCommentOptions, type UserPresence, type UserProfile, type UsersGroupState, type UsersStoreState, type ValidProjection, type ValuePending, type WindowMessage, agentGenerate, agentPatch, agentPrompt, agentTransform, agentTranslate, applyDocumentActions, archiveRelease, configureLogging, createComment, createDatasetHandle, createDocument, createDocumentHandle, createDocumentTypeHandle, createGroqSearchFilter, createProjectHandle, createRelease, createSanityInstance, defineIntent, deleteDocument, deleteRelease, destroyController, discardDocument, editDocument, editRelease, getActiveReleasesState, getAllReleasesState, getAuthState, getClient, getClientErrorApiBody, getClientErrorApiDescription, getClientErrorApiType, getClientState, getCommentThreadsState, getCommentsState, getCorsErrorProjectId, getCurrentUserState, getDashboardOrganizationId, getDatasetsState, getDocumentPresence, getDocumentState, getDocumentSyncStatus, getFavoritesState, getIndexForKey, getIsInDashboardState, getLoginUrlState, getNodeState, getOrCreateChannel, getOrCreateController, getOrCreateNode, getOrganizationState, getOrganizationsState, getPathDepth, getPermissionsState, getPerspectiveState, getPresence, getPreviewState, getProjectState, getProjectionState, getProjectsState, getQueryKey, getQueryState, getReleaseDocumentId, getTokenState, getUserState, getUsersKey, getUsersState, handleAuthCallback, isCanvasResource, isCanvasSource, isDatasetResource, isDatasetSource, isImportError, isMediaLibraryResource, isMediaLibrarySource, isProjectUserNotFoundClientError, isStudioConfig, joinPaths, jsonMatch, loadMoreUsers, logout, observeOrganizationVerificationState, parseQueryKey, parseUsersKey, publishDocument, publishRelease, releaseChannel, releaseNode, removeComment, replyToComment, reportPresence, resolveCommentThreads, resolveComments, resolveDatasets, resolveDocument, resolveFavoritesState, resolveOrganization, resolveOrganizations, resolvePermissions, resolvePreview, resolveProject, resolveProjection, resolveProjects, resolveQuery, resolveUser, resolveUsers, scheduleRelease, setAuthToken, setCommentStatus, slicePath, stringifyPath, subscribeDocumentEvents, transformProjectionToPreview, unarchiveRelease, unpublishDocument, unscheduleRelease, updateComment };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { A as defineStore, C as REQUEST_TAG_PREFIX, D as bindActionByResource, E
|
|
|
2
2
|
import { A as addComment, B as normalizeComment, C as getCommentThreadsState, D as resolveCommentThreads, F as removeCommentById, G as COMMENTS_API_VERSION, H as assertDatasetResource, I as restoreComments, K as setCleanupTimeout, L as rollbackCommentUpdate, M as clearPendingTransaction, N as getCommentsKey, O as resolveComments, P as receiveComment, R as setCommentCreateError, S as commentsStore, T as getCommentsState, U as getAddonDatasetState, V as toCommentFieldPath, W as provisionAddonDataset, _ as setUsersData, a as getQueryState, b as PROJECT_API_VERSION, c as getPerspectiveState, d as addSubscription, f as cancelRequest, g as removeSubscription, h as parseUsersKey, i as getQueryKey, j as applyCommentUpdate, k as toCommentsKeyParts, l as getActiveReleasesState, m as initializeRequest, n as transformProjectionToPreview, o as parseQueryKey, p as getUsersKey, q as insecureRandomId, r as PREVIEW_PROJECTION, s as resolveQuery, t as createGroqSearchFilter, u as getAllReleasesState, v as setUsersError, x as USERS_STATE_CLEAR_DELAY, y as updateLastLoadMoreRequest, z as setPendingTransaction } from "./createGroqSearchFilter-B0NdA-EP.js";
|
|
3
3
|
import { n as configureLogging$1, r as createLogger } from "./getEnv-76AjZd_f.js";
|
|
4
4
|
import { i as isDeepEqual, n as getClient, o as omitProperty, r as getClientState, s as pickProperties } from "./clientStore-CMzJ7XhZ.js";
|
|
5
|
-
import { t as CORE_SDK_VERSION } from "./version-
|
|
5
|
+
import { t as CORE_SDK_VERSION } from "./version-BAVcaHtM.js";
|
|
6
6
|
import { ClientError, CorsOriginError } from "@sanity/client";
|
|
7
7
|
import { EMPTY, NEVER, Observable, Subject, Subscription, asapScheduler, 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";
|
|
8
8
|
import { isKeySegment, isKeyedObject } from "@sanity/types";
|
|
@@ -3153,6 +3153,40 @@ function createFetchDocument(instance, resource) {
|
|
|
3153
3153
|
}), first());
|
|
3154
3154
|
};
|
|
3155
3155
|
}
|
|
3156
|
+
const REJECTED_TRANSACTION_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
3157
|
+
400,
|
|
3158
|
+
402,
|
|
3159
|
+
403,
|
|
3160
|
+
404,
|
|
3161
|
+
409,
|
|
3162
|
+
410,
|
|
3163
|
+
412,
|
|
3164
|
+
413,
|
|
3165
|
+
422
|
|
3166
|
+
]);
|
|
3167
|
+
function getErrorType(error) {
|
|
3168
|
+
let details = error.details;
|
|
3169
|
+
if (details && typeof details == "object" && "type" in details) return details.type;
|
|
3170
|
+
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Classifies a failed transaction submission. Unknown failures (network
|
|
3173
|
+
* errors, timeouts, 5xx and 429 responses, and anything that is not a
|
|
3174
|
+
* `ClientError`) default to `retry`: wrongly retrying a rejected transaction
|
|
3175
|
+
* leaves the document visibly unsynced with the edits still on screen, while
|
|
3176
|
+
* wrongly reverting a transient failure silently discards the user's work.
|
|
3177
|
+
*
|
|
3178
|
+
* @internal
|
|
3179
|
+
*/
|
|
3180
|
+
function classifySubmissionError(error) {
|
|
3181
|
+
if (error instanceof CorsOriginError) return "revert";
|
|
3182
|
+
if (!(error instanceof ClientError)) return "retry";
|
|
3183
|
+
if (error.statusCode === 409) {
|
|
3184
|
+
let errorType = getErrorType(error);
|
|
3185
|
+
if (errorType === "transactionAlreadyExistsError") return "accepted";
|
|
3186
|
+
if (errorType === "transactionConflictError") return "retry";
|
|
3187
|
+
}
|
|
3188
|
+
return REJECTED_TRANSACTION_STATUS_CODES.has(error.statusCode) ? "revert" : "retry";
|
|
3189
|
+
}
|
|
3156
3190
|
const documentStore = defineStore({
|
|
3157
3191
|
name: "Document",
|
|
3158
3192
|
getInitialState: (instance, { resource }) => ({
|
|
@@ -3243,41 +3277,52 @@ const _resolveDocument = bindActionByResource(documentStore, ({ instance }, docH
|
|
|
3243
3277
|
}), caught;
|
|
3244
3278
|
throw error;
|
|
3245
3279
|
})).subscribe({ error: (error) => state.set("setError", { error }) });
|
|
3246
|
-
},
|
|
3247
|
-
|
|
3280
|
+
}, getErrorMessage = (error) => error instanceof Error ? error.message : "Request failed", submitOutgoingTransaction = (client, outgoing) => outgoing.actions.some((action) => !isReleaseAction(action) && action.liveEdit) ? client.observable.mutate(outgoing.outgoingMutations, {
|
|
3281
|
+
transactionId: outgoing.transactionId,
|
|
3282
|
+
visibility: "async",
|
|
3283
|
+
returnDocuments: !1,
|
|
3284
|
+
returnFirst: !1,
|
|
3285
|
+
tag: "document.mutate",
|
|
3286
|
+
skipCrossDatasetReferenceValidation: !0
|
|
3287
|
+
}) : client.observable.action(outgoing.outgoingActions, {
|
|
3288
|
+
transactionId: outgoing.transactionId,
|
|
3289
|
+
skipCrossDatasetReferenceValidation: !0,
|
|
3290
|
+
tag: "document.action"
|
|
3291
|
+
}), subscribeToAppliedAndSubmitNextTransaction = ({ state, instance, key: { resource } }) => {
|
|
3292
|
+
let { events } = state.get(), clients$ = getClientState(instance, {
|
|
3293
|
+
apiVersion: API_VERSION$4,
|
|
3294
|
+
resource
|
|
3295
|
+
}).observable;
|
|
3248
3296
|
return state.observable.pipe(throttle((s) => s.outgoing ? state.observable.pipe(first(({ outgoing }) => !outgoing)) : timer(1e3), {
|
|
3249
3297
|
leading: !1,
|
|
3250
3298
|
trailing: !0
|
|
3251
|
-
}), map(transitionAppliedTransactionsToOutgoing), distinctUntilChanged((a, b) => a.outgoing?.transactionId === b.outgoing?.transactionId), tap((next) => state.set("transitionAppliedTransactionsToOutgoing", next)), map((s) => s.outgoing), distinctUntilChanged(), withLatestFrom(
|
|
3252
|
-
apiVersion: API_VERSION$4,
|
|
3253
|
-
resource
|
|
3254
|
-
}).observable), concatMap(([outgoing, client]) => {
|
|
3299
|
+
}), map(transitionAppliedTransactionsToOutgoing), distinctUntilChanged((a, b) => a.outgoing?.transactionId === b.outgoing?.transactionId), tap((next) => state.set("transitionAppliedTransactionsToOutgoing", next)), map((s) => s.outgoing), distinctUntilChanged(), withLatestFrom(clients$), concatMap(([outgoing, initialClient]) => {
|
|
3255
3300
|
if (!outgoing) return EMPTY;
|
|
3256
|
-
let
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
type: "
|
|
3261
|
-
message,
|
|
3301
|
+
let attemptClient;
|
|
3302
|
+
return defer(() => attemptClient ? clients$.pipe(first()) : of(initialClient)).pipe(concatMap((client) => (attemptClient = client, submitOutgoingTransaction(client, outgoing))), retry({ delay: (error, retryCount) => {
|
|
3303
|
+
if (classifySubmissionError(error) !== "retry") return throwError(() => error);
|
|
3304
|
+
events.next({
|
|
3305
|
+
type: "submission-failed",
|
|
3306
|
+
message: getErrorMessage(error),
|
|
3307
|
+
error,
|
|
3262
3308
|
outgoing,
|
|
3263
|
-
|
|
3264
|
-
})
|
|
3265
|
-
|
|
3309
|
+
attempt: retryCount
|
|
3310
|
+
});
|
|
3311
|
+
let backoff = Math.min(1e3 * 2 ** (retryCount - 1), 1e4);
|
|
3312
|
+
return race(timer(backoff), clients$.pipe(first((client) => client !== attemptClient)));
|
|
3313
|
+
} }), catchError((error) => classifySubmissionError(error) === "accepted" ? of({
|
|
3314
|
+
transactionId: outgoing.transactionId,
|
|
3315
|
+
documentIds: [],
|
|
3316
|
+
results: []
|
|
3317
|
+
}) : (state.set("revertOutgoingTransaction", revertOutgoingTransaction), events.next({
|
|
3318
|
+
type: "reverted",
|
|
3319
|
+
message: getErrorMessage(error),
|
|
3320
|
+
outgoing,
|
|
3321
|
+
error
|
|
3322
|
+
}), EMPTY)), map((result) => ({
|
|
3266
3323
|
result,
|
|
3267
3324
|
outgoing
|
|
3268
|
-
}));
|
|
3269
|
-
return outgoing.actions.some((action) => !isReleaseAction(action) && action.liveEdit) ? client.observable.mutate(outgoing.outgoingMutations, {
|
|
3270
|
-
transactionId: outgoing.transactionId,
|
|
3271
|
-
visibility: "async",
|
|
3272
|
-
returnDocuments: !1,
|
|
3273
|
-
returnFirst: !1,
|
|
3274
|
-
tag: "document.mutate",
|
|
3275
|
-
skipCrossDatasetReferenceValidation: !0
|
|
3276
|
-
}).pipe(revertOnError, toResult) : client.observable.action(outgoing.outgoingActions, {
|
|
3277
|
-
transactionId: outgoing.transactionId,
|
|
3278
|
-
skipCrossDatasetReferenceValidation: !0,
|
|
3279
|
-
tag: "document.action"
|
|
3280
|
-
}).pipe(revertOnError, toResult);
|
|
3325
|
+
})));
|
|
3281
3326
|
}), tap(({ outgoing, result }) => {
|
|
3282
3327
|
state.set("cleanupOutgoingTransaction", cleanupOutgoingTransaction);
|
|
3283
3328
|
for (let e of getDocumentEvents(outgoing)) events.next(e);
|