@sanity/sdk-react 2.2.0 → 2.3.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.
Files changed (32) hide show
  1. package/dist/index.d.ts +2 -3
  2. package/dist/index.js +92 -19
  3. package/dist/index.js.map +1 -1
  4. package/package.json +6 -5
  5. package/src/components/auth/AuthBoundary.test.tsx +33 -20
  6. package/src/components/auth/AuthBoundary.tsx +11 -1
  7. package/src/components/auth/LoginError.tsx +9 -12
  8. package/src/components/errors/CorsErrorComponent.test.tsx +48 -0
  9. package/src/components/errors/CorsErrorComponent.tsx +37 -0
  10. package/src/components/errors/Error.styles.ts +35 -0
  11. package/src/components/errors/Error.tsx +40 -0
  12. package/src/context/ComlinkTokenRefresh.test.tsx +53 -40
  13. package/src/hooks/auth/useDashboardOrganizationId.test.tsx +16 -7
  14. package/src/hooks/auth/useVerifyOrgProjects.test.tsx +56 -14
  15. package/src/hooks/dashboard/{useManageFavorite.test.ts → useManageFavorite.test.tsx} +99 -44
  16. package/src/hooks/document/{useDocument.test.ts → useDocument.test.tsx} +25 -22
  17. package/src/hooks/document/{useDocumentEvent.test.ts → useDocumentEvent.test.tsx} +17 -16
  18. package/src/hooks/document/{useDocumentPermissions.test.ts → useDocumentPermissions.test.tsx} +101 -40
  19. package/src/hooks/document/{useEditDocument.test.ts → useEditDocument.test.tsx} +52 -22
  20. package/src/hooks/documents/useDocuments.test.tsx +63 -25
  21. package/src/hooks/helpers/createCallbackHook.test.tsx +41 -37
  22. package/src/hooks/paginatedDocuments/usePaginatedDocuments.test.tsx +2 -2
  23. package/src/hooks/presence/usePresence.test.tsx +9 -6
  24. package/src/hooks/preview/useDocumentPreview.test.tsx +15 -16
  25. package/src/hooks/projection/useDocumentProjection.test.tsx +23 -38
  26. package/src/hooks/projection/useDocumentProjection.ts +3 -8
  27. package/src/hooks/query/useQuery.test.tsx +18 -10
  28. package/src/hooks/releases/useActiveReleases.test.tsx +25 -21
  29. package/src/hooks/releases/usePerspective.test.tsx +16 -22
  30. package/src/hooks/users/useUser.test.tsx +32 -15
  31. package/src/hooks/users/useUsers.test.tsx +19 -11
  32. package/src/hooks/_synchronous-groq-js.mjs +0 -4
package/dist/index.d.ts CHANGED
@@ -42,7 +42,6 @@ import {SanityUser} from '@sanity/sdk'
42
42
  import {SortOrderingItem} from '@sanity/types'
43
43
  import {StudioResource} from '@sanity/message-protocol'
44
44
  import {UserPresence} from '@sanity/sdk'
45
- import {ValidProjection} from '@sanity/sdk'
46
45
  import {WindowMessage} from '@sanity/sdk'
47
46
 
48
47
  /**
@@ -1406,7 +1405,7 @@ export declare interface useDocumentPreviewResults {
1406
1405
  * ```
1407
1406
  */
1408
1407
  export declare function useDocumentProjection<
1409
- TProjection extends ValidProjection = ValidProjection,
1408
+ TProjection extends string = string,
1410
1409
  TDocumentType extends string = string,
1411
1410
  TDataset extends string = string,
1412
1411
  TProjectId extends string = string,
@@ -1470,7 +1469,7 @@ export declare function useDocumentProjection<TData extends object>(
1470
1469
  * @category Types
1471
1470
  */
1472
1471
  export declare interface useDocumentProjectionOptions<
1473
- TProjection extends ValidProjection = ValidProjection,
1472
+ TProjection extends string = string,
1474
1473
  TDocumentType extends string = string,
1475
1474
  TDataset extends string = string,
1476
1475
  TProjectId extends string = string,
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
2
  import { c } from "react-compiler-runtime";
3
- import { getAuthState, getNodeState, getIsInDashboardState, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPresence, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
3
+ import { ClientError, CorsOriginError } from "@sanity/client";
4
+ import { getAuthState, getNodeState, getIsInDashboardState, setAuthToken, AuthStateType, getLoginUrlState, observeOrganizationVerificationState, handleAuthCallback, logout, getCorsErrorProjectId, createSanityInstance, getTokenState, getCurrentUserState, getDashboardOrganizationId, getClientState, getOrCreateController, getOrCreateChannel, releaseChannel, getFavoritesState, resolveFavoritesState, resolveDatasets, getDatasetsState, applyDocumentActions, resolveDocument, getDocumentState, subscribeDocumentEvents, getPermissionsState, getDocumentSyncStatus, editDocument, getQueryKey, parseQueryKey, getQueryState, resolveQuery, createGroqSearchFilter, getPresence, getPreviewState, resolvePreview, getProjectionState, resolveProjection, resolveProject, getProjectState, resolveProjects, getProjectsState, getActiveReleasesState, getPerspectiveState, getUsersKey, parseUsersKey, getUsersState, resolveUsers, loadMoreUsers } from "@sanity/sdk";
4
5
  export * from "@sanity/sdk";
5
6
  import { createContext, useContext, useSyncExternalStore, useRef, useEffect, useState, Suspense, useMemo, useCallback, useInsertionEffect, useTransition } from "react";
6
7
  import { ErrorBoundary } from "react-error-boundary";
7
8
  import { SDK_CHANNEL_NAME, SDK_NODE_NAME } from "@sanity/message-protocol";
8
9
  import { firstValueFrom, filter, identity, Observable, startWith, distinctUntilChanged, switchMap, EMPTY } from "rxjs";
9
- import { ClientError } from "@sanity/client";
10
10
  import { pick } from "lodash-es";
11
11
  const SanityInstanceContext = createContext(null), useSanityInstance = (config) => {
12
12
  const $ = c(3), instance = useContext(SanityInstanceContext);
@@ -174,6 +174,88 @@ function useVerifyOrgProjects(t0, projectIds) {
174
174
  };
175
175
  }, t2 = [instance, disabled, error, projectIds], $[0] = disabled, $[1] = error, $[2] = instance, $[3] = projectIds, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), useEffect(t1, t2), error;
176
176
  }
177
+ const FONT_SANS_SERIF = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, system-ui, sans-serif", FONT_MONOSPACE = "-apple-system-ui-monospace, 'SF Mono', Menlo, Monaco, Consolas, monospace", styles = {
178
+ container: {
179
+ padding: "28px",
180
+ fontFamily: FONT_SANS_SERIF,
181
+ display: "flex",
182
+ flexDirection: "column",
183
+ gap: "21px",
184
+ fontSize: "14px"
185
+ },
186
+ heading: {
187
+ margin: 0,
188
+ fontSize: "28px",
189
+ fontWeight: 700
190
+ },
191
+ paragraph: {
192
+ margin: 0
193
+ },
194
+ link: {
195
+ appearance: "none",
196
+ background: "transparent",
197
+ border: 0,
198
+ padding: 0,
199
+ font: "inherit",
200
+ textDecoration: "underline",
201
+ cursor: "pointer"
202
+ },
203
+ code: {
204
+ fontFamily: FONT_MONOSPACE
205
+ }
206
+ };
207
+ function Error$1(t0) {
208
+ const $ = c(13), {
209
+ heading,
210
+ description,
211
+ code,
212
+ cta
213
+ } = t0;
214
+ let t1;
215
+ $[0] !== heading ? (t1 = /* @__PURE__ */ jsx("h1", { style: styles.heading, children: heading }), $[0] = heading, $[1] = t1) : t1 = $[1];
216
+ let t2;
217
+ $[2] !== description ? (t2 = description && /* @__PURE__ */ jsx("p", { style: styles.paragraph, dangerouslySetInnerHTML: {
218
+ __html: description
219
+ } }), $[2] = description, $[3] = t2) : t2 = $[3];
220
+ let t3;
221
+ $[4] !== code ? (t3 = code && /* @__PURE__ */ jsx("code", { style: styles.code, children: code }), $[4] = code, $[5] = t3) : t3 = $[5];
222
+ let t4;
223
+ $[6] !== cta ? (t4 = cta && (cta.href || cta.onClick) && /* @__PURE__ */ jsx("p", { style: styles.paragraph, children: cta.href ? /* @__PURE__ */ jsx("a", { style: styles.link, href: cta.href, target: "_blank", rel: "noopener noreferrer", children: cta.text }) : /* @__PURE__ */ jsx("button", { style: styles.link, onClick: cta.onClick, children: cta.text }) }), $[6] = cta, $[7] = t4) : t4 = $[7];
224
+ let t5;
225
+ return $[8] !== t1 || $[9] !== t2 || $[10] !== t3 || $[11] !== t4 ? (t5 = /* @__PURE__ */ jsxs("div", { style: styles.container, children: [
226
+ t1,
227
+ t2,
228
+ t3,
229
+ t4
230
+ ] }), $[8] = t1, $[9] = t2, $[10] = t3, $[11] = t4, $[12] = t5) : t5 = $[12], t5;
231
+ }
232
+ function CorsErrorComponent(t0) {
233
+ const $ = c(6), {
234
+ projectId,
235
+ error
236
+ } = t0, origin = window.location.origin;
237
+ let t1;
238
+ const t2 = `https://sanity.io/manage/project/${projectId}/api`;
239
+ let t3;
240
+ if ($[0] !== t2) {
241
+ const url = new URL(t2);
242
+ url.searchParams.set("cors", "add"), url.searchParams.set("origin", origin), url.searchParams.set("credentials", "include"), t3 = url.toString(), $[0] = t2, $[1] = t3;
243
+ } else
244
+ t3 = $[1];
245
+ t1 = t3;
246
+ const corsUrl = t1;
247
+ let t4;
248
+ return $[2] !== corsUrl || $[3] !== error?.message || $[4] !== projectId ? (t4 = /* @__PURE__ */ jsx(Error$1, { heading: "Before you continue\u2026", ...projectId ? {
249
+ description: "To access your content, you need to <strong>add the following URL as a CORS origin</strong> to your Sanity project.",
250
+ code: origin,
251
+ cta: {
252
+ text: "Manage CORS configuration",
253
+ href: corsUrl
254
+ }
255
+ } : {
256
+ description: error?.message
257
+ } }), $[2] = corsUrl, $[3] = error?.message, $[4] = projectId, $[5] = t4) : t4 = $[5], t4;
258
+ }
177
259
  function isInIframe() {
178
260
  return typeof window < "u" && window.self !== window.top;
179
261
  }
@@ -213,7 +295,7 @@ function _temp$5(replacementLocation) {
213
295
  }
214
296
  const useLogOut = createCallbackHook(logout);
215
297
  function LoginError(t0) {
216
- const $ = c(23), {
298
+ const $ = c(17), {
217
299
  error,
218
300
  resetErrorBoundary
219
301
  } = t0;
@@ -241,21 +323,12 @@ function LoginError(t0) {
241
323
  $[7] !== authState || $[8] !== error || $[9] !== handleRetry ? (t3 = [authState, handleRetry, error], $[7] = authState, $[8] = error, $[9] = handleRetry, $[10] = t3) : t3 = $[10], useEffect(t2, t3);
242
324
  const t4 = error instanceof AuthError ? "Authentication Error" : "Configuration Error";
243
325
  let t5;
244
- $[11] !== t4 ? (t5 = /* @__PURE__ */ jsx("h2", { className: "sc-login-error__title", children: t4 }), $[11] = t4, $[12] = t5) : t5 = $[12];
326
+ $[11] !== handleRetry ? (t5 = {
327
+ text: "Retry",
328
+ onClick: handleRetry
329
+ }, $[11] = handleRetry, $[12] = t5) : t5 = $[12];
245
330
  let t6;
246
- $[13] !== authErrorMessage ? (t6 = /* @__PURE__ */ jsx("p", { className: "sc-login-error__description", children: authErrorMessage }), $[13] = authErrorMessage, $[14] = t6) : t6 = $[14];
247
- let t7;
248
- $[15] !== t5 || $[16] !== t6 ? (t7 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error__content", children: [
249
- t5,
250
- t6
251
- ] }), $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17];
252
- let t8;
253
- $[18] !== handleRetry ? (t8 = /* @__PURE__ */ jsx("button", { className: "sc-login-error__button", onClick: handleRetry, children: "Retry" }), $[18] = handleRetry, $[19] = t8) : t8 = $[19];
254
- let t9;
255
- return $[20] !== t7 || $[21] !== t8 ? (t9 = /* @__PURE__ */ jsxs("div", { className: "sc-login-error", children: [
256
- t7,
257
- t8
258
- ] }), $[20] = t7, $[21] = t8, $[22] = t9) : t9 = $[22], t9;
331
+ return $[13] !== authErrorMessage || $[14] !== t4 || $[15] !== t5 ? (t6 = /* @__PURE__ */ jsx(Error$1, { heading: t4, description: authErrorMessage, cta: t5 }), $[13] = authErrorMessage, $[14] = t4, $[15] = t5, $[16] = t6) : t6 = $[16], t6;
259
332
  }
260
333
  if (isInIframe() && !document.querySelector("[data-sanity-core]")) {
261
334
  const parsedUrl = new URL(window.location.href), mode = new URLSearchParams(parsedUrl.hash.slice(1)).get("mode"), script = document.createElement("script");
@@ -271,7 +344,7 @@ function AuthBoundary(t0) {
271
344
  const LoginErrorComponent = t1 === void 0 ? LoginError : t1;
272
345
  let t2, t3;
273
346
  $[3] !== LoginErrorComponent ? (t3 = function(fallbackProps) {
274
- return /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps });
347
+ return fallbackProps.error instanceof CorsOriginError ? /* @__PURE__ */ jsx(CorsErrorComponent, { ...fallbackProps, projectId: getCorsErrorProjectId(fallbackProps.error) }) : /* @__PURE__ */ jsx(LoginErrorComponent, { ...fallbackProps });
275
348
  }, $[3] = LoginErrorComponent, $[4] = t3) : t3 = $[4], t2 = t3;
276
349
  const FallbackComponent = t2;
277
350
  let t4;
@@ -1158,7 +1231,7 @@ function useUsers(options) {
1158
1231
  loadMore
1159
1232
  };
1160
1233
  }
1161
- var version = "2.2.0";
1234
+ var version = "2.3.0";
1162
1235
  function getEnv(key) {
1163
1236
  if (typeof import.meta < "u" && import.meta.env)
1164
1237
  return import.meta.env[key];