@sanity/client 8.0.0 → 8.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.
Files changed (54) hide show
  1. package/README.md +94 -0
  2. package/dist/{browserUpload-CQgx9YYo.js → browserUpload-2tz6Sdqp.js} +4 -3
  3. package/dist/browserUpload-2tz6Sdqp.js.map +1 -0
  4. package/dist/{browserUpload-icWlVP15.js → browserUpload-CwpNx7Vl.js} +4 -3
  5. package/dist/browserUpload-CwpNx7Vl.js.map +1 -0
  6. package/dist/{config-a8VajuEY.js → config-3wiPP-sZ.js} +2 -2
  7. package/dist/config-3wiPP-sZ.js.map +1 -0
  8. package/dist/csm.js +2 -2
  9. package/dist/csm.js.map +1 -1
  10. package/dist/index.d.ts +17 -11
  11. package/dist/index.js +247 -120
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.node.d.ts +270 -26
  14. package/dist/index.node.js +183 -50
  15. package/dist/index.node.js.map +1 -1
  16. package/dist/media-library.d.ts +1 -1
  17. package/dist/{request-CJxcN16k.js → request-BhMuKj0D.js} +10 -9
  18. package/dist/request-BhMuKj0D.js.map +1 -0
  19. package/dist/{request-k7VS_NnC.js → request-SnMg7nUX.js} +10 -9
  20. package/dist/request-SnMg7nUX.js.map +1 -0
  21. package/dist/{resolveEditInfo-sq7yF78q.js → resolveEditInfo-Cz-smq3a.js} +17 -3
  22. package/dist/resolveEditInfo-Cz-smq3a.js.map +1 -0
  23. package/dist/stega.js +1 -1
  24. package/dist/{stegaEncodeSourceMap-DkoIlutY.js → stegaEncodeSourceMap-DbM2fTN4.js} +8 -2
  25. package/dist/stegaEncodeSourceMap-DbM2fTN4.js.map +1 -0
  26. package/dist/{stegaEncodeSourceMap-B2fGArSf.js → stegaEncodeSourceMap-YR3NQ3iz.js} +2 -2
  27. package/dist/{stegaEncodeSourceMap-B2fGArSf.js.map → stegaEncodeSourceMap-YR3NQ3iz.js.map} +1 -1
  28. package/dist/{types-CUxZSgB2.d.ts → types-BODIEY7F.d.ts} +262 -24
  29. package/package.json +26 -11
  30. package/src/SanityClient.ts +19 -20
  31. package/src/assets/AssetsClient.ts +54 -5
  32. package/src/csm/applySourceDocuments.ts +2 -4
  33. package/src/csm/draftUtils.ts +23 -4
  34. package/src/data/dataMethods.ts +2 -19
  35. package/src/data/eventsource.ts +71 -41
  36. package/src/data/live.ts +17 -9
  37. package/src/data/resolveEventSourceFetch.ts +9 -1
  38. package/src/defineCreateClient.ts +5 -1
  39. package/src/functions/FunctionsClient.ts +66 -0
  40. package/src/functions/invoke.ts +176 -0
  41. package/src/http/browserUpload.ts +1 -0
  42. package/src/http/errors.ts +2 -1
  43. package/src/http/request.ts +8 -14
  44. package/src/mediaLibrary/MediaLibraryVideoClient.ts +1 -1
  45. package/src/types.ts +186 -4
  46. package/src/validators.ts +1 -1
  47. package/src/warnings.ts +7 -1
  48. package/dist/browserUpload-CQgx9YYo.js.map +0 -1
  49. package/dist/browserUpload-icWlVP15.js.map +0 -1
  50. package/dist/config-a8VajuEY.js.map +0 -1
  51. package/dist/request-CJxcN16k.js.map +0 -1
  52. package/dist/request-k7VS_NnC.js.map +0 -1
  53. package/dist/resolveEditInfo-sq7yF78q.js.map +0 -1
  54. package/dist/stegaEncodeSourceMap-DkoIlutY.js.map +0 -1
package/README.md CHANGED
@@ -145,6 +145,10 @@ export async function updateDocumentTitle(_id, title) {
145
145
  - [Getting video playback information](#getting-video-playback-information)
146
146
  - [Working with signed playback information](#working-with-signed-playback-information)
147
147
  - [Downloading MP4 renditions](#downloading-mp4-renditions)
148
+ - [Invoking functions](#invoking-functions)
149
+ - [Choosing a stack](#choosing-a-stack)
150
+ - [Scoping to an organization](#scoping-to-an-organization)
151
+ - [Return values and timeouts](#return-values-and-timeouts)
148
152
  - [License](#license)
149
153
  - [Migrate](#migrate)
150
154
 
@@ -930,6 +934,8 @@ Likewise, you can also have the client return the document _before_ the mutation
930
934
 
931
935
  If it's not relevant to know what mutations that was applied, you can also set `includeMutation` to `false` in the options, which will save some additional bandwidth by omitting the `mutation` property from the received events.
932
936
 
937
+ On Cloudflare Workers, `client.listen()` and `client.live.events()` need a [`compatibility_date`](https://developers.cloudflare.com/workers/configuration/compatibility-dates/) of `2024-11-11` or later (or the `cache_option_enabled` compatibility flag). Both open a server-sent events connection, which sets the `cache` field on the request; earlier compatibility dates throw rather than ignore it. Other runtimes are unaffected.
938
+
933
939
  ### Fetch a single document
934
940
 
935
941
  This will fetch a document from the [Doc endpoint](https://www.sanity.io/docs/http-doc). This endpoint cuts through any caching/indexing middleware that may involve delayed processing. As it is less scalable/performant than the other query mechanisms, it should be used sparingly. Performing a query is usually a better option.
@@ -2447,6 +2453,94 @@ if (playbackInfo.renditions?.length) {
2447
2453
 
2448
2454
  Available resolutions depend on the source video but typically include `1080p`, `480p`, and `270p`.
2449
2455
 
2456
+ ### Invoking functions
2457
+
2458
+ Call a Sanity Pubsub Function on demand. These APIs are available on the `client.functions` namespace.
2459
+
2460
+ Only `sanity.function.pubsub` functions can be invoked this way. Every other type is driven by its own trigger.
2461
+
2462
+ Functions are addressed by the `name` they are declared with in your blueprint. Names are unique within a stack. The client needs a `stackId` in order to resolve. Configure it once on the client, or pass it per call.
2463
+
2464
+ ```js
2465
+ import {createClient} from '@sanity/client'
2466
+
2467
+ const client = createClient({
2468
+ projectId: 'your-project-id',
2469
+ apiVersion: '2025-02-19',
2470
+ token: 'valid-token',
2471
+ stackId: 'your-stack-id',
2472
+ })
2473
+
2474
+ const result = await client.functions.invoke('my-function', {
2475
+ event: {data: {hello: 'world'}},
2476
+ })
2477
+ ```
2478
+
2479
+ The payload given as `event.data` is what the function receives as `event.data`. It defaults to `{}` when omitted.
2480
+
2481
+ Both Promise and Observable forms are available:
2482
+
2483
+ - `client.functions.invoke(name, request)` resolves with the function's return value
2484
+ - `client.observable.functions.invoke(name, request)` emits it and completes
2485
+
2486
+ ```ts
2487
+ // The return value is typed through the generic; it is not validated at runtime
2488
+ const summary = await client.functions.invoke<{words: number}>('summarize', {
2489
+ event: {data: {documentId: 'abc123'}},
2490
+ })
2491
+ ```
2492
+
2493
+ #### Choosing a stack
2494
+
2495
+ `stackId` on the request wins over `stackId` in the client config, which lets one client reach functions in more than one stack:
2496
+
2497
+ ```js
2498
+ await client.functions.invoke('my-function', {stackId: 'another-stack-id'})
2499
+ ```
2500
+
2501
+ Resolving the name takes one extra request per call: the client reads the stack to find the function, then invokes it. If neither the request nor the config supplies a `stackId`, the call rejects without touching the network.
2502
+
2503
+ Invoking a name the stack doesn't declare or a non-pubsub function rejects.
2504
+
2505
+ #### Scoping to an organization
2506
+
2507
+ Project scope is the default. For an organization-scoped stack, set `organizationId`:
2508
+
2509
+ ```js
2510
+ const client = createClient({
2511
+ projectId: 'your-project-id',
2512
+ apiVersion: '2025-02-19',
2513
+ token: 'valid-token',
2514
+ stackId: 'your-stack-id',
2515
+ organizationId: 'your-organization-id',
2516
+ })
2517
+ ```
2518
+
2519
+ It can also be passed per call, and wins over the client config:
2520
+
2521
+ ```js
2522
+ await client.functions.invoke('my-function', {organizationId: 'another-organization-id'})
2523
+ ```
2524
+
2525
+ An `organizationId` takes precedence over `projectId`, since a stack is only ever resolvable at one scope. `projectId` becomes optional in that case, provided the client is also configured with `useProjectHostname: false`.
2526
+
2527
+ Scope has to match the token. A project-scoped token gets `403` on an organization-scoped stack; mint one that matches with `sanity blueprints mint-deploy-token --organization-id <id>`.
2528
+
2529
+ #### Return values and timeouts
2530
+
2531
+ The request stays open until the function finishes, and resolves with whatever it returned. A function that returns nothing resolves to `undefined`.
2532
+
2533
+ Requests time out after five minutes by default, so a longer-running function needs an explicit `timeout` (in milliseconds, `0` to disable it). A call can be aborted with an `AbortSignal` like any other request:
2534
+
2535
+ ```js
2536
+ const controller = new AbortController()
2537
+
2538
+ const result = await client.functions.invoke('slow-function', {
2539
+ timeout: 0, // or e.g. 600000 for a ten minute deadline
2540
+ signal: controller.signal,
2541
+ })
2542
+ ```
2543
+
2450
2544
  ## License
2451
2545
 
2452
2546
  MIT © [Sanity.io](https://www.sanity.io/)
@@ -1,4 +1,4 @@
1
- import { a as ServerError, n as parseJsonText, r as ClientError, s as httpResponseFromFetch } from "./request-CJxcN16k.js";
1
+ import { a as ServerError, n as parseJsonText, r as ClientError, s as httpResponseFromFetch } from "./request-SnMg7nUX.js";
2
2
  import { Observable } from "rxjs";
3
3
  import { createDebug } from "obug";
4
4
  const log = createDebug("sanity:client");
@@ -31,7 +31,8 @@ function uploadWithProgress(options) {
31
31
  status: xhr.status,
32
32
  statusText: xhr.statusText,
33
33
  headers: errorHeaders,
34
- body: parseJsonText(xhr.responseText, errorHeaders)
34
+ body: parseJsonText(xhr.responseText, errorHeaders),
35
+ url: xhr.responseURL
35
36
  }, url, method);
36
37
  subscriber.error(xhr.status >= 500 ? new ServerError(canonical) : new ClientError(canonical));
37
38
  return;
@@ -83,4 +84,4 @@ function parseXhrResponseHeaders(raw) {
83
84
  }
84
85
  export { uploadWithProgress };
85
86
 
86
- //# sourceMappingURL=browserUpload-CQgx9YYo.js.map
87
+ //# sourceMappingURL=browserUpload-2tz6Sdqp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserUpload-2tz6Sdqp.js","names":[],"sources":["../src/http/browserUpload.ts"],"sourcesContent":["import {createDebug} from 'obug'\nimport {Observable} from 'rxjs'\n\nimport type {UploadEvent} from '../types'\nimport {ClientError, httpResponseFromFetch, ServerError} from './errors'\nimport {parseJsonText} from './request'\n\nconst log = createDebug('sanity:client')\n\nlet nextRequestId = 1\n\n/**\n * Options for a browser-side asset upload that needs progress events.\n *\n * @internal\n */\nexport interface BrowserUploadOptions {\n url: string\n method: string\n headers: Record<string, string>\n body: unknown\n withCredentials: boolean\n /** Milliseconds before the upload is aborted; `false` and `0` both disable the timeout. */\n timeout?: number | false\n signal?: AbortSignal\n}\n\n/**\n * Run an asset upload through `XMLHttpRequest` so we can surface per-chunk\n * upload progress events. get-it v9 / fetch has no equivalent hook in the\n * browser, so the observable asset-upload API falls back to this path when\n * `XMLHttpRequest` is available.\n *\n * @internal\n */\nexport function uploadWithProgress<T>(options: BrowserUploadOptions): Observable<UploadEvent<T>> {\n return new Observable<UploadEvent<T>>((subscriber) => {\n const xhr = new XMLHttpRequest()\n const requestId = nextRequestId++\n const {url, method, headers, body, withCredentials, timeout, signal} = options\n\n log('[%d] %s %s (XHR upload with progress)', requestId, method, url)\n\n xhr.open(method, url)\n xhr.withCredentials = withCredentials\n if (typeof timeout === 'number' && timeout > 0) {\n xhr.timeout = timeout\n }\n\n for (const [key, value] of Object.entries(headers)) {\n xhr.setRequestHeader(key, value)\n }\n\n xhr.upload.onprogress = (e) => {\n subscriber.next({\n type: 'progress',\n stage: 'upload',\n percent: e.lengthComputable ? Math.round((e.loaded / e.total) * 100) : 0,\n total: e.total || undefined,\n loaded: e.loaded,\n lengthComputable: e.lengthComputable,\n })\n }\n\n xhr.onload = () => {\n log('[%d] %s %s — %d', requestId, method, url, xhr.status)\n\n if (xhr.status >= 400) {\n // Same typed errors as the fetch transport, so consumers can keep\n // detecting `ClientError`/`ServerError` and reading `statusCode`,\n // `responseBody` and the structured API `details` on failed uploads.\n const errorHeaders = parseXhrResponseHeaders(xhr.getAllResponseHeaders())\n const canonical = httpResponseFromFetch(\n {\n status: xhr.status,\n statusText: xhr.statusText,\n headers: errorHeaders,\n body: parseJsonText(xhr.responseText, errorHeaders),\n url: xhr.responseURL,\n },\n url,\n method,\n )\n subscriber.error(\n xhr.status >= 500 ? new ServerError(canonical) : new ClientError(canonical),\n )\n return\n }\n\n let responseBody: T\n try {\n responseBody = JSON.parse(xhr.responseText) as T\n } catch {\n subscriber.error(new Error('Failed to parse upload response as JSON'))\n return\n }\n\n subscriber.next({type: 'response', body: responseBody})\n subscriber.complete()\n }\n\n xhr.onerror = () => {\n log('[%d] %s %s — network error', requestId, method, url)\n subscriber.error(new Error('XHR upload network error'))\n }\n\n xhr.ontimeout = () => {\n log('[%d] %s %s — timed out after %dms', requestId, method, url, timeout)\n // Same error shape as the fetch transport's timeout rejection.\n subscriber.error(\n new DOMException(\n `The operation timed out after ${timeout}ms while attempting to reach ${url}`,\n 'TimeoutError',\n ),\n )\n }\n\n xhr.onabort = () => {\n subscriber.error(new DOMException('Upload aborted', 'AbortError'))\n }\n\n const onSignalAbort = () => xhr.abort()\n if (signal) {\n if (signal.aborted) {\n // `xhr.abort()` before `send()` fires no `abort` event per spec, so\n // error out directly instead of relying on `onabort`.\n subscriber.error(new DOMException('Upload aborted', 'AbortError'))\n return undefined\n }\n signal.addEventListener('abort', onSignalAbort, {once: true})\n }\n\n xhr.send(body as XMLHttpRequestBodyInit)\n\n // Unsubscribing cancels the in-flight upload, mirroring how the fetch\n // path aborts its request (`_observe`). After settle this is a no-op —\n // except for detaching from the caller's signal, which may be long-lived\n // and must not accumulate a listener per upload.\n return () => {\n signal?.removeEventListener('abort', onSignalAbort)\n xhr.abort()\n }\n })\n}\n\n/**\n * Parse `XMLHttpRequest.getAllResponseHeaders()` output (CRLF-separated\n * `name: value` lines) into a `Headers` instance.\n */\nfunction parseXhrResponseHeaders(raw: string): Headers {\n const headers = new Headers()\n for (const line of raw.split('\\r\\n')) {\n const separator = line.indexOf(':')\n if (separator <= 0) continue\n try {\n headers.append(line.slice(0, separator).trim(), line.slice(separator + 1).trim())\n } catch {\n // Skip header lines the Headers constructor rejects — better a partial\n // header record on the error than no error details at all.\n }\n }\n return headers\n}\n"],"mappings":";;;AAOA,MAAM,MAAM,YAAY,eAAe;AAEvC,IAAI,gBAAgB;;;;;;;;;AA0BpB,SAAgB,mBAAsB,SAA2D;CAC/F,OAAO,IAAI,YAA4B,eAAe;EACpD,IAAM,MAAM,IAAI,eAAe,GACzB,YAAY,iBACZ,EAAC,KAAK,QAAQ,SAAS,MAAM,iBAAiB,SAAS,WAAU;EAMvE,AAJA,IAAI,yCAAyC,WAAW,QAAQ,GAAG,GAEnE,IAAI,KAAK,QAAQ,GAAG,GACpB,IAAI,kBAAkB,iBAClB,OAAO,WAAY,YAAY,UAAU,MA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W,MAAM,IAAI,aAAa,kBAAkB,YAAY,CAAC;EACnE;EAEA,IAAM,sBAAsB,IAAI,MAAM;EACtC,IAAI,QAAQ;GACV,IAAI,OAAO,SAAS;IAGlB,WAAW,MAAM,IAAI,aAAa,kBAAkB,YAAY,CAAC;IACjE;GACF;GACA,OAAO,iBAAiB,SAAS,eAAe,EAAC,MAAM,GAAI,CAAC;EAC9D;EAQA,OANA,IAAI,KAAK,IAA8B,SAM1B;GAEX,AADA,QAAQ,oBAAoB,SAAS,aAAa,GAClD,IAAI,MAAM;EACZ;CACF,CAAC;AACH;;;;;AAMA,SAAS,wBAAwB,KAAsB;CACrD,IAAM,UAAU,IAAI,QAAQ;CAC5B,KAAK,IAAM,QAAQ,IAAI,MAAM,MAAM,GAAG;EACpC,IAAM,YAAY,KAAK,QAAQ,GAAG;EAC9B,mBAAa,IACjB,IAAI;GACF,QAAQ,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC,CAAC,KAAK,GAAG,KAAK,MAAM,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;EAClF,QAAQ,CAGR;CACF;CACA,OAAO;AACT"}
@@ -1,4 +1,4 @@
1
- import { a as ServerError, n as parseJsonText, r as ClientError, s as httpResponseFromFetch } from "./request-k7VS_NnC.js";
1
+ import { a as ServerError, n as parseJsonText, r as ClientError, s as httpResponseFromFetch } from "./request-BhMuKj0D.js";
2
2
  import { Observable } from "rxjs";
3
3
  import { createDebug } from "obug";
4
4
  const log = createDebug("sanity:client");
@@ -31,7 +31,8 @@ function uploadWithProgress(options) {
31
31
  status: xhr.status,
32
32
  statusText: xhr.statusText,
33
33
  headers: errorHeaders,
34
- body: parseJsonText(xhr.responseText, errorHeaders)
34
+ body: parseJsonText(xhr.responseText, errorHeaders),
35
+ url: xhr.responseURL
35
36
  }, url, method);
36
37
  subscriber.error(xhr.status >= 500 ? new ServerError(canonical) : new ClientError(canonical));
37
38
  return;
@@ -83,4 +84,4 @@ function parseXhrResponseHeaders(raw) {
83
84
  }
84
85
  export { uploadWithProgress };
85
86
 
86
- //# sourceMappingURL=browserUpload-icWlVP15.js.map
87
+ //# sourceMappingURL=browserUpload-CwpNx7Vl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserUpload-CwpNx7Vl.js","names":[],"sources":["../src/http/browserUpload.ts"],"sourcesContent":["import {createDebug} from 'obug'\nimport {Observable} from 'rxjs'\n\nimport type {UploadEvent} from '../types'\nimport {ClientError, httpResponseFromFetch, ServerError} from './errors'\nimport {parseJsonText} from './request'\n\nconst log = createDebug('sanity:client')\n\nlet nextRequestId = 1\n\n/**\n * Options for a browser-side asset upload that needs progress events.\n *\n * @internal\n */\nexport interface BrowserUploadOptions {\n url: string\n method: string\n headers: Record<string, string>\n body: unknown\n withCredentials: boolean\n /** Milliseconds before the upload is aborted; `false` and `0` both disable the timeout. */\n timeout?: number | false\n signal?: AbortSignal\n}\n\n/**\n * Run an asset upload through `XMLHttpRequest` so we can surface per-chunk\n * upload progress events. get-it v9 / fetch has no equivalent hook in the\n * browser, so the observable asset-upload API falls back to this path when\n * `XMLHttpRequest` is available.\n *\n * @internal\n */\nexport function uploadWithProgress<T>(options: BrowserUploadOptions): Observable<UploadEvent<T>> {\n return new Observable<UploadEvent<T>>((subscriber) => {\n const xhr = new XMLHttpRequest()\n const requestId = nextRequestId++\n const {url, method, headers, body, withCredentials, timeout, signal} = options\n\n log('[%d] %s %s (XHR upload with progress)', requestId, method, url)\n\n xhr.open(method, url)\n xhr.withCredentials = withCredentials\n if (typeof timeout === 'number' && timeout > 0) {\n xhr.timeout = timeout\n }\n\n for (const [key, value] of Object.entries(headers)) {\n xhr.setRequestHeader(key, value)\n }\n\n xhr.upload.onprogress = (e) => {\n subscriber.next({\n type: 'progress',\n stage: 'upload',\n percent: e.lengthComputable ? Math.round((e.loaded / e.total) * 100) : 0,\n total: e.total || undefined,\n loaded: e.loaded,\n lengthComputable: e.lengthComputable,\n })\n }\n\n xhr.onload = () => {\n log('[%d] %s %s — %d', requestId, method, url, xhr.status)\n\n if (xhr.status >= 400) {\n // Same typed errors as the fetch transport, so consumers can keep\n // detecting `ClientError`/`ServerError` and reading `statusCode`,\n // `responseBody` and the structured API `details` on failed uploads.\n const errorHeaders = parseXhrResponseHeaders(xhr.getAllResponseHeaders())\n const canonical = httpResponseFromFetch(\n {\n status: xhr.status,\n statusText: xhr.statusText,\n headers: errorHeaders,\n body: parseJsonText(xhr.responseText, errorHeaders),\n url: xhr.responseURL,\n },\n url,\n method,\n )\n subscriber.error(\n xhr.status >= 500 ? new ServerError(canonical) : new ClientError(canonical),\n )\n return\n }\n\n let responseBody: T\n try {\n responseBody = JSON.parse(xhr.responseText) as T\n } catch {\n subscriber.error(new Error('Failed to parse upload response as JSON'))\n return\n }\n\n subscriber.next({type: 'response', body: responseBody})\n subscriber.complete()\n }\n\n xhr.onerror = () => {\n log('[%d] %s %s — network error', requestId, method, url)\n subscriber.error(new Error('XHR upload network error'))\n }\n\n xhr.ontimeout = () => {\n log('[%d] %s %s — timed out after %dms', requestId, method, url, timeout)\n // Same error shape as the fetch transport's timeout rejection.\n subscriber.error(\n new DOMException(\n `The operation timed out after ${timeout}ms while attempting to reach ${url}`,\n 'TimeoutError',\n ),\n )\n }\n\n xhr.onabort = () => {\n subscriber.error(new DOMException('Upload aborted', 'AbortError'))\n }\n\n const onSignalAbort = () => xhr.abort()\n if (signal) {\n if (signal.aborted) {\n // `xhr.abort()` before `send()` fires no `abort` event per spec, so\n // error out directly instead of relying on `onabort`.\n subscriber.error(new DOMException('Upload aborted', 'AbortError'))\n return undefined\n }\n signal.addEventListener('abort', onSignalAbort, {once: true})\n }\n\n xhr.send(body as XMLHttpRequestBodyInit)\n\n // Unsubscribing cancels the in-flight upload, mirroring how the fetch\n // path aborts its request (`_observe`). After settle this is a no-op —\n // except for detaching from the caller's signal, which may be long-lived\n // and must not accumulate a listener per upload.\n return () => {\n signal?.removeEventListener('abort', onSignalAbort)\n xhr.abort()\n }\n })\n}\n\n/**\n * Parse `XMLHttpRequest.getAllResponseHeaders()` output (CRLF-separated\n * `name: value` lines) into a `Headers` instance.\n */\nfunction parseXhrResponseHeaders(raw: string): Headers {\n const headers = new Headers()\n for (const line of raw.split('\\r\\n')) {\n const separator = line.indexOf(':')\n if (separator <= 0) continue\n try {\n headers.append(line.slice(0, separator).trim(), line.slice(separator + 1).trim())\n } catch {\n // Skip header lines the Headers constructor rejects — better a partial\n // header record on the error than no error details at all.\n }\n }\n return headers\n}\n"],"mappings":";;;AAOA,MAAM,MAAM,YAAY,eAAe;AAEvC,IAAI,gBAAgB;;;;;;;;;AA0BpB,SAAgB,mBAAsB,SAA2D;CAC/F,OAAO,IAAI,YAA4B,eAAe;EACpD,IAAM,MAAM,IAAI,eAAe,GACzB,YAAY,iBACZ,EAAC,KAAK,QAAQ,SAAS,MAAM,iBAAiB,SAAS,WAAU;EAMvE,AAJA,IAAI,yCAAyC,WAAW,QAAQ,GAAG,GAEnE,IAAI,KAAK,QAAQ,GAAG,GACpB,IAAI,kBAAkB,iBAClB,OAAO,WAAY,YAAY,UAAU,MAC3C,IAAI,UAAU;EAGhB,KAAK,IAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,OAAO,GAC/C,IAAI,iBAAiB,KAAK,KAAK;EAmEjC,AAhEA,IAAI,OAAO,cAAc,MAAM;GAC7B,WAAW,KAAK;IACd,MAAM;IACN,OAAO;IACP,SAAS,EAAE,mBAAmB,KAAK,MAAO,EAAE,SAAS,EAAE,QAAS,GAAG,IAAI;IACvE,OAAO,EAAE,SAAS,KAAA;IAClB,QAAQ,EAAE;IACV,kBAAkB,EAAE;GACtB,CAAC;EACH,GAEA,IAAI,eAAe;GAGjB,IAFA,IAAI,mBAAmB,WAAW,QAAQ,KAAK,IAAI,MAAM,GAErD,IAAI,UAAU,KAAK;IAIrB,IAAM,eAAe,wBAAwB,IAAI,sBAAsB,CAAC,GAClE,YAAY,sBAChB;KACE,QAAQ,IAAI;KACZ,YAAY,IAAI;KAChB,SAAS;KACT,M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,GAAG,SAAS,CAAC,CAAC,KAAK,GAAG,KAAK,MAAM,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;EAClF,QAAQ,CAGR;CACF;CACA,OAAO;AACT"}
@@ -69,7 +69,7 @@ const createWarningPrinter = (message) => once((...args) => console.warn(message
69
69
  "Since you haven't set a value for `useCdn`, we will deliver content using our",
70
70
  "global, edge-cached API-CDN. If you wish to have content delivered faster, set",
71
71
  "`useCdn: false` to use the Live API. Note: You may incur higher costs using the live API."
72
- ]), printCdnPreviewDraftsWarning = createWarningPrinter(["The Sanity client is configured with the `perspective` set to `drafts` or `previewDrafts`, which doesn't support the API-CDN.", "The Live API will be used instead. Set `useCdn: false` in your configuration to hide this warning."]), printPreviewDraftsDeprecationWarning = createWarningPrinter(["The `previewDrafts` perspective has been renamed to `drafts` and will be removed in a future API version"]), printBrowserTokenWarning = createWarningPrinter(["You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.", `See ${generateHelpUrl("js-client-browser-token")} for more information and how to hide this warning.`]), printCredentialedTokenWarning = createWarningPrinter(["You have configured Sanity client to use a token, but also provided `withCredentials: true`.", "This is no longer supported - only token will be used - remove `withCredentials: true`."]), printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", `See ${generateHelpUrl("js-client-api-version")}`]), printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."]), printCreateVersionWithBaseIdWarning = createWarningPrinter(["You have called `createVersion()` with a defined `document`. The recommended approach is to provide a `baseId` and `releaseId` instead."]), printDeprecatedUriOptionWarning = createWarningPrinter(["The `uri` request option has been renamed to `url`.", "Please update your code to use `url` instead. Support for `uri` will be removed in a future version."]), printDeprecatedResourceConfigWarning = createWarningPrinter(["The `~experimental_resource` configuration property has been renamed to `resource`.", "Please update your client configuration to use `resource` instead. Support for `~experimental_resource` will be removed in a future version."]), defaultConfig = {
72
+ ]), printCdnPreviewDraftsWarning = createWarningPrinter(["The Sanity client is configured with the `perspective` set to `drafts` or `previewDrafts`, which doesn't support the API-CDN.", "The Live API will be used instead. Set `useCdn: false` in your configuration to hide this warning."]), printPreviewDraftsDeprecationWarning = createWarningPrinter(["The `previewDrafts` perspective has been renamed to `drafts` and will be removed in a future API version"]), printBrowserTokenWarning = createWarningPrinter(["You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.", `See ${generateHelpUrl("js-client-browser-token")} for more information and how to hide this warning.`]), printCredentialedTokenWarning = createWarningPrinter(["You have configured Sanity client to use a token, but also provided `withCredentials: true`.", "This is no longer supported - only token will be used - remove `withCredentials: true`."]), printNoApiVersionSpecifiedWarning = createWarningPrinter(["Using the Sanity client without specifying an API version is deprecated.", `See ${generateHelpUrl("js-client-api-version")}`]), printNoDefaultExport = createWarningPrinter(["The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."]), printCreateVersionWithBaseIdWarning = createWarningPrinter(["You have called `createVersion()` with a defined `document`.", "If you are creating a version of a document that already exists, prefer providing `baseId` and `releaseId` instead."]), printDeprecatedUriOptionWarning = createWarningPrinter(["The `uri` request option has been renamed to `url`.", "Please update your code to use `url` instead. Support for `uri` will be removed in a future version."]), printDeprecatedResourceConfigWarning = createWarningPrinter(["The `~experimental_resource` configuration property has been renamed to `resource`.", "Please update your client configuration to use `resource` instead. Support for `~experimental_resource` will be removed in a future version."]), defaultConfig = {
73
73
  apiHost: "https://api.sanity.io",
74
74
  apiVersion: "1",
75
75
  useProjectHostname: !0,
@@ -123,4 +123,4 @@ const initConfig = (config, prevConfig) => {
123
123
  };
124
124
  export { validateDocumentId as _, printCreateVersionWithBaseIdWarning as a, validateVersionIdMatch as b, printPreviewDraftsDeprecationWarning as c, requestTag as d, requireDocumentId as f, validateAssetType as g, resourceGuard as h, printCdnPreviewDraftsWarning as i, dataset as l, resourceConfig as m, initConfig as n, printDeprecatedUriOptionWarning as o, requireDocumentType as p, validateApiPerspective as r, printNoDefaultExport as s, defaultConfig as t, hasDataset as u, validateInsert as v, validateObject as y };
125
125
 
126
- //# sourceMappingURL=config-a8VajuEY.js.map
126
+ //# sourceMappingURL=config-3wiPP-sZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-3wiPP-sZ.js","names":["resourceConfig","validate.requestTag"],"sources":["../src/generateHelpUrl.ts","../src/validators.ts","../src/util/once.ts","../src/warnings.ts","../src/config.ts"],"sourcesContent":["const BASE_URL = 'https://www.sanity.io/help/'\n\nexport function generateHelpUrl(slug: string) {\n return BASE_URL + slug\n}\n","import type {Any, InitializedClientConfig, SanityDocumentStub} from './types'\n\nconst VALID_ASSET_TYPES = ['image', 'file']\nconst VALID_INSERT_LOCATIONS = ['before', 'after', 'replace']\n\nexport const dataset = (name: string) => {\n if (!/^(~[a-z0-9]{1}[-\\w]{0,63}|[a-z0-9]{1}[-\\w]{0,63})$/.test(name)) {\n throw new Error(\n 'Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters',\n )\n }\n}\n\nexport const projectId = (id: string) => {\n if (!/^[-a-z0-9]+$/i.test(id)) {\n throw new Error('`projectId` can only contain only a-z, 0-9 and dashes')\n }\n}\n\nexport const validateAssetType = (type: string) => {\n if (VALID_ASSET_TYPES.indexOf(type) === -1) {\n throw new Error(`Invalid asset type: ${type}. Must be one of ${VALID_ASSET_TYPES.join(', ')}`)\n }\n}\n\nexport const validateObject = (op: string, val: Any) => {\n if (val === null || typeof val !== 'object' || Array.isArray(val)) {\n throw new Error(`${op}() takes an object of properties`)\n }\n}\n\nexport const validateDocumentId = (op: string, id: string) => {\n if (typeof id !== 'string' || !/^[a-z0-9_][a-z0-9_.-]{0,127}$/i.test(id) || id.includes('..')) {\n throw new Error(`${op}(): \"${id}\" is not a valid document ID`)\n }\n}\n\nexport const requireDocumentId = (op: string, doc: Record<string, Any>) => {\n if (!doc._id) {\n throw new Error(`${op}() requires that the document contains an ID (\"_id\" property)`)\n }\n\n validateDocumentId(op, doc._id)\n}\n\nconst validateDocumentType = (op: string, type: string) => {\n if (typeof type !== 'string') {\n throw new Error(`\\`${op}()\\`: \\`${type}\\` is not a valid document type`)\n }\n}\n\nexport const requireDocumentType = (op: string, doc: Record<string, Any>) => {\n if (!doc._type) {\n throw new Error(`\\`${op}()\\` requires that the document contains a type (\\`_type\\` property)`)\n }\n\n validateDocumentType(op, doc._type)\n}\n\nexport const validateVersionIdMatch = (builtVersionId: string, document: SanityDocumentStub) => {\n if (document._id && document._id !== builtVersionId) {\n throw new Error(\n `The provided document ID (\\`${document._id}\\`) does not match the generated version ID (\\`${builtVersionId}\\`)`,\n )\n }\n}\n\nexport const validateInsert = (at: string, selector: string, items: Any[]) => {\n const signature = 'insert(at, selector, items)'\n if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {\n const valid = VALID_INSERT_LOCATIONS.map((loc) => `\"${loc}\"`).join(', ')\n throw new Error(`${signature} takes an \"at\"-argument which is one of: ${valid}`)\n }\n\n if (typeof selector !== 'string') {\n throw new Error(`${signature} takes a \"selector\"-argument which must be a string`)\n }\n\n if (!Array.isArray(items)) {\n throw new Error(`${signature} takes an \"items\"-argument which must be an array`)\n }\n}\n\nexport const hasDataset = (config: InitializedClientConfig): string => {\n // Check if dataset is directly on the config\n if (config.dataset) {\n return config.dataset\n }\n\n // Check if dataset is in resource configuration\n // Note: ~experimental_resource is normalized to resource during client initialization\n const resource = config.resource\n if (resource && resource.type === 'dataset') {\n const segments = resource.id.split('.')\n if (segments.length !== 2) {\n throw new Error('Dataset resource ID must be in the format \"project.dataset\"')\n }\n return segments[1]\n }\n\n throw new Error('`dataset` must be provided to perform queries')\n}\n\nexport const requestTag = (tag: string) => {\n if (typeof tag !== 'string' || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {\n throw new Error(\n `Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.`,\n )\n }\n\n return tag\n}\n\nexport const resourceConfig = (config: InitializedClientConfig): void => {\n // Note: ~experimental_resource is normalized to resource during client initialization\n const resource = config.resource\n if (!resource) {\n throw new Error('`resource` must be provided to perform resource queries')\n }\n const {type, id} = resource\n\n switch (type) {\n case 'dataset': {\n const segments = id.split('.')\n if (segments.length !== 2) {\n throw new Error('Dataset resource ID must be in the format \"project.dataset\"')\n }\n return\n }\n case 'dashboard':\n case 'media-library':\n case 'canvas': {\n return\n }\n default:\n // @ts-expect-error - handle all supported resource types\n throw new Error(`Unsupported resource type: ${type.toString()}`)\n }\n}\n\nexport const resourceGuard = (service: string, config: InitializedClientConfig): void => {\n // Note: ~experimental_resource is normalized to resource during client initialization\n const resource = config.resource\n if (resource) {\n throw new Error(`\\`${service}\\` does not support resource-based operations`)\n }\n}\n","import type {Any} from '../types'\n\nexport function once(fn: Any) {\n let didCall = false\n let returnValue: Any\n return (...args: Any[]) => {\n if (didCall) {\n return returnValue\n }\n returnValue = fn(...args)\n didCall = true\n return returnValue\n }\n}\n","import {generateHelpUrl} from './generateHelpUrl'\nimport {type Any} from './types'\nimport {once} from './util/once'\n\nconst createWarningPrinter = (message: string[]) =>\n // oxlint-disable-next-line no-console\n once((...args: Any[]) => console.warn(message.join(' '), ...args))\n\nexport const printCdnAndWithCredentialsWarning = createWarningPrinter([\n `Because you set \\`withCredentials\\` to true, we will override your \\`useCdn\\``,\n `setting to be false since (cookie-based) credentials are never set on the CDN`,\n])\n\nexport const printCdnWarning = createWarningPrinter([\n `Since you haven't set a value for \\`useCdn\\`, we will deliver content using our`,\n `global, edge-cached API-CDN. If you wish to have content delivered faster, set`,\n `\\`useCdn: false\\` to use the Live API. Note: You may incur higher costs using the live API.`,\n])\n\nexport const printCdnPreviewDraftsWarning = createWarningPrinter([\n `The Sanity client is configured with the \\`perspective\\` set to \\`drafts\\` or \\`previewDrafts\\`, which doesn't support the API-CDN.`,\n `The Live API will be used instead. Set \\`useCdn: false\\` in your configuration to hide this warning.`,\n])\n\nexport const printPreviewDraftsDeprecationWarning = createWarningPrinter([\n `The \\`previewDrafts\\` perspective has been renamed to \\`drafts\\` and will be removed in a future API version`,\n])\n\nexport const printBrowserTokenWarning = createWarningPrinter([\n 'You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.',\n `See ${generateHelpUrl(\n 'js-client-browser-token',\n )} for more information and how to hide this warning.`,\n])\n\nexport const printCredentialedTokenWarning = createWarningPrinter([\n 'You have configured Sanity client to use a token, but also provided `withCredentials: true`.',\n 'This is no longer supported - only token will be used - remove `withCredentials: true`.',\n])\n\nexport const printNoApiVersionSpecifiedWarning = createWarningPrinter([\n 'Using the Sanity client without specifying an API version is deprecated.',\n `See ${generateHelpUrl('js-client-api-version')}`,\n])\n\nexport const printNoDefaultExport = createWarningPrinter([\n 'The default export of @sanity/client has been deprecated. Use the named export `createClient` instead.',\n])\n\n// Phrased as a condition rather than as a correction, because the client cannot\n// tell the two cases apart. `baseId` creates a version of a document that\n// already exists, so a caller creating a genuinely new document inside a release\n// has no alternative to `document` - and the previous wording told them they had\n// picked the wrong approach when they had not.\nexport const printCreateVersionWithBaseIdWarning = createWarningPrinter([\n 'You have called `createVersion()` with a defined `document`.',\n 'If you are creating a version of a document that already exists, prefer providing `baseId` and `releaseId` instead.',\n])\n\nexport const printDeprecatedUriOptionWarning = createWarningPrinter([\n 'The `uri` request option has been renamed to `url`.',\n 'Please update your code to use `url` instead. Support for `uri` will be removed in a future version.',\n])\n\nexport const printDeprecatedResourceConfigWarning = createWarningPrinter([\n 'The `~experimental_resource` configuration property has been renamed to `resource`.',\n 'Please update your client configuration to use `resource` instead. Support for `~experimental_resource` will be removed in a future version.',\n])\n","import {generateHelpUrl} from './generateHelpUrl'\nimport type {ClientConfig, ClientPerspective, InitializedClientConfig} from './types'\nimport * as validate from './validators'\nimport * as warnings from './warnings'\n\nconst defaultCdnHost = 'apicdn.sanity.io'\nexport const defaultConfig = {\n apiHost: 'https://api.sanity.io',\n apiVersion: '1',\n useProjectHostname: true,\n stega: {enabled: false},\n} satisfies ClientConfig\n\nconst LOCALHOSTS = ['localhost', '127.0.0.1', '0.0.0.0']\nconst isLocal = (host: string) => LOCALHOSTS.indexOf(host) !== -1\n\nfunction validateApiVersion(apiVersion: string) {\n if (apiVersion === '1' || apiVersion === 'X') {\n return\n }\n\n const apiDate = new Date(apiVersion)\n const apiVersionValid =\n /^\\d{4}-\\d{2}-\\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0\n\n if (!apiVersionValid) {\n throw new Error('Invalid API version string, expected `1` or date in format `YYYY-MM-DD`')\n }\n}\n\n/**\n * @internal - it may have breaking changes in any release\n */\nexport function validateApiPerspective(\n perspective: unknown,\n): asserts perspective is ClientPerspective {\n if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes('raw')) {\n throw new TypeError(\n `Invalid API perspective value: \"raw\". The raw-perspective can not be combined with other perspectives`,\n )\n }\n}\n\nexport const initConfig = (\n config: Partial<ClientConfig>,\n prevConfig: Partial<ClientConfig>,\n): InitializedClientConfig => {\n const specifiedConfig = {\n ...prevConfig,\n ...config,\n stega: {\n ...(typeof prevConfig.stega === 'boolean'\n ? {enabled: prevConfig.stega}\n : prevConfig.stega || defaultConfig.stega),\n ...(typeof config.stega === 'boolean' ? {enabled: config.stega} : config.stega || {}),\n },\n }\n if (!specifiedConfig.apiVersion) {\n warnings.printNoApiVersionSpecifiedWarning()\n }\n\n const newConfig = {\n ...defaultConfig,\n ...specifiedConfig,\n } as InitializedClientConfig\n\n // Normalize resource configuration - prefer `resource` over deprecated `~experimental_resource`\n if (newConfig['~experimental_resource'] && !newConfig.resource) {\n warnings.printDeprecatedResourceConfigWarning()\n newConfig.resource = newConfig['~experimental_resource']\n }\n\n const resourceConfig = newConfig.resource\n const projectBased = newConfig.useProjectHostname && !resourceConfig\n\n if (typeof Promise === 'undefined') {\n const helpUrl = generateHelpUrl('js-client-promise-polyfill')\n throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`)\n }\n\n if (projectBased && !newConfig.projectId) {\n throw new Error('Configuration must contain `projectId`')\n }\n\n if (resourceConfig) {\n validate.resourceConfig(newConfig)\n }\n\n if (typeof newConfig.perspective !== 'undefined') {\n validateApiPerspective(newConfig.perspective)\n }\n\n if ('encodeSourceMap' in newConfig) {\n throw new Error(\n `It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?`,\n )\n }\n if ('encodeSourceMapAtPath' in newConfig) {\n throw new Error(\n `It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?`,\n )\n }\n if (typeof newConfig.stega.enabled !== 'boolean') {\n throw new Error(`stega.enabled must be a boolean, received ${newConfig.stega.enabled}`)\n }\n if (newConfig.stega.enabled && newConfig.stega.studioUrl === undefined) {\n throw new Error(`stega.studioUrl must be defined when stega.enabled is true`)\n }\n if (\n newConfig.stega.enabled &&\n typeof newConfig.stega.studioUrl !== 'string' &&\n typeof newConfig.stega.studioUrl !== 'function'\n ) {\n throw new Error(\n `stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`,\n )\n }\n\n const isBrowser = typeof window !== 'undefined' && window.location && window.location.hostname\n const isLocalhost = isBrowser && isLocal(window.location.hostname)\n\n const hasToken = Boolean(newConfig.token)\n if (newConfig.withCredentials && hasToken) {\n warnings.printCredentialedTokenWarning()\n newConfig.withCredentials = false\n }\n\n if (isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== true) {\n warnings.printBrowserTokenWarning()\n } else if (typeof newConfig.useCdn === 'undefined') {\n warnings.printCdnWarning()\n }\n\n if (projectBased) {\n validate.projectId(newConfig.projectId!)\n }\n\n if (newConfig.dataset) {\n validate.dataset(newConfig.dataset)\n }\n\n if ('requestTagPrefix' in newConfig) {\n // Allow setting and unsetting request tag prefix\n newConfig.requestTagPrefix = newConfig.requestTagPrefix\n ? validate.requestTag(newConfig.requestTagPrefix).replace(/\\.+$/, '')\n : undefined\n }\n\n newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, '')\n newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost\n\n if (newConfig.useCdn === true && newConfig.withCredentials) {\n warnings.printCdnAndWithCredentialsWarning()\n }\n\n // If `useCdn` is undefined, we treat it as `true`\n newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials\n\n validateApiVersion(newConfig.apiVersion)\n\n const hostParts = newConfig.apiHost.split('://', 2)\n const protocol = hostParts[0]\n const host = hostParts[1]\n const cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host\n\n if (projectBased) {\n newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`\n newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`\n } else {\n newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`\n newConfig.cdnUrl = newConfig.url\n }\n\n return newConfig\n}\n"],"mappings":"AAEA,SAAgB,gBAAgB,MAAc;CAC5C,OAAO,gCAAW;AACpB;ACFA,MAAM,oBAAoB,CAAC,SAAS,MAAM,GACpC,yBAAyB;CAAC;CAAU;CAAS;AAAS,GAE/C,WAAW,SAAiB;CACvC,IAAI,CAAC,qDAAqD,KAAK,IAAI,GACjE,MAAU,MACR,qIACF;AAEJ,GAEa,aAAa,OAAe;CACvC,IAAI,CAAC,gBAAgB,KAAK,EAAE,GAC1B,MAAU,MAAM,uDAAuD;AAE3E,GAEa,qBAAqB,SAAiB;CACjD,IAAI,kBAAkB,QAAQ,IAAI,MAAM,IACtC,MAAU,MAAM,uBAAuB,KAAK,mBAAmB,kBAAkB,KAAK,IAAI,GAAG;AAEjG,GAEa,kBAAkB,IAAY,QAAa;CACtD,IAAoB,OAAO,OAAQ,aAA/B,OAA2C,MAAM,QAAQ,GAAG,GAC9D,MAAU,MAAM,GAAG,GAAG,iCAAiC;AAE3D,GAEa,sBAAsB,IAAY,OAAe;CAC5D,IAAI,OAAO,MAAO,YAAY,CAAC,iCAAiC,KAAK,EAAE,KAAK,GAAG,SAAS,IAAI,GAC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W,UAAU,IACrB,OAAO,UAAU,IACjB,UAAU,UAAU,eAAe,qBAAiB;CAU1D,OARI,gBACF,UAAU,MAAM,GAAG,SAAS,KAAK,UAAU,UAAU,GAAG,KAAK,IAAI,UAAU,cAC3E,UAAU,SAAS,GAAG,SAAS,KAAK,UAAU,UAAU,GAAG,QAAQ,IAAI,UAAU,iBAEjF,UAAU,MAAM,GAAG,UAAU,QAAQ,IAAI,UAAU,cACnD,UAAU,SAAS,UAAU,MAGxB;AACT"}
package/dist/csm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { r as validateApiPerspective } from "./config-a8VajuEY.js";
2
- import { S as toString, _ as isPublishedId, a as resolveMapping, c as parseJsonPath, d as VERSION_FOLDER, f as getDraftId, g as isDraftId, h as getVersionId, i as walkMap, l as studioPathToJsonPath, m as getVersionFromId, o as jsonPath, p as getPublishedId, r as createEditUrl, s as jsonPathToStudioPath, t as resolveEditInfo, u as DRAFTS_FOLDER, v as isVersionId, x as studioPath_exports, y as get } from "./resolveEditInfo-sq7yF78q.js";
1
+ import { r as validateApiPerspective } from "./config-3wiPP-sZ.js";
2
+ import { S as toString, _ as isPublishedId, a as resolveMapping, c as parseJsonPath, d as VERSION_FOLDER, f as getDraftId, g as isDraftId, h as getVersionId, i as walkMap, l as studioPathToJsonPath, m as getVersionFromId, o as jsonPath, p as getPublishedId, r as createEditUrl, s as jsonPathToStudioPath, t as resolveEditInfo, u as DRAFTS_FOLDER, v as isVersionId, x as studioPath_exports, y as get } from "./resolveEditInfo-Cz-smq3a.js";
3
3
  /**
4
4
  * This resolves the perspectives to how documents should be resolved when applying optimistic updates,
5
5
  * like in `applySourceDocuments`.
package/dist/csm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"csm.js","names":["paths.toString","paths.get"],"sources":["../src/csm/resolvePerspectives.ts","../src/csm/createSourceDocumentResolver.ts","../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {validateApiPerspective} from '../config'\nimport type {StackablePerspective} from '../types'\nimport type {ClientPerspective} from './types'\n\n/**\n * This resolves the perspectives to how documents should be resolved when applying optimistic updates,\n * like in `applySourceDocuments`.\n * @internal\n */\nexport function resolvePerspectives(\n perspective: Exclude<ClientPerspective, 'raw'>,\n): ('published' | 'drafts' | StackablePerspective)[] {\n validateApiPerspective(perspective)\n\n if (Array.isArray(perspective)) {\n if (!perspective.includes('published')) {\n return [...perspective, 'published']\n }\n return perspective\n }\n switch (perspective) {\n case 'previewDrafts':\n case 'drafts':\n return ['drafts', 'published']\n case 'published':\n default:\n return ['published']\n }\n}\n","import {getDraftId, getPublishedId, getVersionId} from './draftUtils'\nimport {resolvePerspectives} from './resolvePerspectives'\nimport type {ClientPerspective, ContentSourceMapDocuments, SanityDocument} from './types'\n\n/** @internal */\nexport type ResolvedDocument = Partial<SanityDocument> &\n Required<Pick<SanityDocument, '_id' | '_type'>>\n\n/** @internal */\nexport type MatchedDocument = Partial<SanityDocument> &\n Required<Pick<SanityDocument, '_id' | '_type' | '_originalId'>>\n\n/** @internal */\nexport function createSourceDocumentResolver(\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) => ResolvedDocument | null | undefined,\n _perspective: Exclude<ClientPerspective, 'raw'>,\n) {\n const perspectives = resolvePerspectives(_perspective)\n function findDocument(sourceDocument: ContentSourceMapDocuments[number]) {\n for (const perspective of perspectives) {\n let match: ReturnType<typeof getCachedDocument> = null\n if (perspective.startsWith('r')) {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getVersionId(sourceDocument._id, perspective),\n })\n }\n if (perspective === 'drafts') {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getDraftId(sourceDocument._id),\n })\n }\n if (perspective === 'published') {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getPublishedId(sourceDocument._id),\n })\n }\n if (match) {\n return {...match, _id: getPublishedId(match._id), _originalId: match._id}\n }\n }\n return null\n }\n // define resolver that loops over source documents and perspectives\n return function resolveSourceDocument(\n sourceDocument: ContentSourceMapDocuments[number],\n ): MatchedDocument | null {\n return findDocument(sourceDocument)\n }\n}\n","import {createSourceDocumentResolver} from './createSourceDocumentResolver'\nimport {parseJsonPath} from './jsonPath'\nimport {resolveMapping} from './resolveMapping'\nimport * as paths from './studioPath'\nimport type {\n Any,\n ApplySourceDocumentsUpdateFunction,\n ClientPerspective,\n ContentSourceMap,\n ContentSourceMapDocuments,\n Path,\n SanityDocument,\n} from './types'\nimport {walkMap} from './walkMap'\n\n/**\n * Optimistically applies source documents to a result, using the content source map to trace fields.\n * Can be used to apply mutations to documents being edited in a Studio, or any mutation on Content Lake, to a result with extremely low latency.\n * @alpha\n */\nexport function applySourceDocuments<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) =>\n | (Partial<SanityDocument> & Required<Pick<SanityDocument, '_id' | '_type'>>)\n | null\n | undefined,\n updateFn: ApplySourceDocumentsUpdateFunction,\n perspective: Exclude<ClientPerspective, 'raw'>,\n): Result {\n if (!resultSourceMap) return result\n\n const resolveDocument = createSourceDocumentResolver(getCachedDocument, perspective)\n const cachedDocuments = resultSourceMap.documents?.map?.(resolveDocument) || []\n\n return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {\n const resolveMappingResult = resolveMapping(path, resultSourceMap)\n if (!resolveMappingResult) {\n return value\n }\n\n const {mapping, pathSuffix} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = resultSourceMap.documents[mapping.source.document]\n const sourcePath = resultSourceMap.paths[mapping.source.path]\n\n if (sourceDocument) {\n const parsedPath = parseJsonPath(sourcePath + pathSuffix)\n const stringifiedPath = paths.toString(parsedPath as Path)\n const cachedDocument = cachedDocuments[mapping.source.document]\n\n if (!cachedDocument) {\n return value\n }\n\n const changedValue = cachedDocument\n ? paths.get<Result[keyof Result]>(cachedDocument, stringifiedPath, value)\n : value\n return value === changedValue\n ? value\n : updateFn<Result[keyof Result]>(changedValue as Any, {\n cachedDocument,\n previousValue: value as Result[keyof Result],\n sourceDocument,\n sourcePath: parsedPath,\n })\n }\n\n return value\n }) as Result\n}\n","import {jsonPath, parseJsonPath} from './jsonPath'\nimport type {ContentSourceMapParsedPath} from './types'\n\n/**\n * @internal\n */\nexport function resolvedKeyedSourcePath(options: {\n keyedResultPath: ContentSourceMapParsedPath\n pathSuffix?: string\n sourceBasePath: string\n}): ContentSourceMapParsedPath {\n const {keyedResultPath, pathSuffix, sourceBasePath} = options\n\n const inferredResultPath = pathSuffix === undefined ? [] : parseJsonPath(pathSuffix)\n\n const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length)\n\n const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath).slice(1) : ''\n\n return parseJsonPath(sourceBasePath + inferredPathSuffix)\n}\n","import {createEditUrl} from './createEditUrl'\nimport {studioPathToJsonPath} from './jsonPath'\nimport {resolveEditInfo} from './resolveEditInfo'\nimport type {ResolveEditUrlOptions} from './types'\n\n/** @alpha */\nexport function resolveEditUrl(\n options: ResolveEditUrlOptions,\n): ReturnType<typeof createEditUrl> | undefined {\n const {resultSourceMap, studioUrl} = options\n const resultPath = studioPathToJsonPath(options.resultPath)\n\n const editInfo = resolveEditInfo({\n resultPath,\n resultSourceMap,\n studioUrl,\n })\n if (!editInfo) {\n return undefined\n }\n\n return createEditUrl(editInfo)\n}\n"],"mappings":";;;;;;;AASA,SAAgB,oBACd,aACmD;CAGnD,IAFA,uBAAuB,WAAW,GAE9B,MAAM,QAAQ,WAAW,GAI3B,OAHK,YAAY,SAAS,WAAW,IAG9B,cAFE,CAAC,GAAG,aAAa,WAAW;CAIvC,QAAQ,aAAR;EACE,KAAK;EACL,KAAK,UACH,OAAO,CAAC,UAAU,WAAW;EAE/B,SACE,OAAO,CAAC,WAAW;CACvB;AACF;;ACfA,SAAgB,6BACd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AAI,CAAC,gBACH,OAAO;GAGT,IAAM,eAAe,iBACjBC,IAAgC,gBAAgB,iBAAiB,KAAK,IACtE;GACJ,OAAO,UAAU,eACb,QACA,SAA+B,cAAqB;IAClD;IACA,eAAe;IACf;IACA,YAAY;GACd,CAAC;EACP;EAEA,OAAO;CACT,CAAC;AACH;;;;ACzEA,SAAgB,wBAAwB,SAIT;CAC7B,IAAM,EAAC,iBAAiB,YAAY,mBAAkB,SAEhD,qBAAqB,eAAe,KAAA,IAAY,CAAC,IAAI,cAAc,UAAU,GAE7E,eAAe,gBAAgB,MAAM,gBAAgB,SAAS,mBAAmB,MAAM,GAEvF,qBAAqB,aAAa,SAAS,SAAS,YAAY,CAAC,CAAC,MAAM,CAAC,IAAI;CAEnF,OAAO,cAAc,iBAAiB,kBAAkB;AAC1D;;ACdA,SAAgB,eACd,SAC8C;CAC9C,IAAM,EAAC,iBAAiB,cAAa,SAC/B,aAAa,qBAAqB,QAAQ,UAAU,GAEpD,WAAW,gBAAgB;EAC/B;EACA;EACA;CACF,CAAC;CACI,cAIL,OAAO,cAAc,QAAQ;AAC/B"}
1
+ {"version":3,"file":"csm.js","names":["paths.toString","paths.get"],"sources":["../src/csm/resolvePerspectives.ts","../src/csm/createSourceDocumentResolver.ts","../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {validateApiPerspective} from '../config'\nimport type {StackablePerspective} from '../types'\nimport type {ClientPerspective} from './types'\n\n/**\n * This resolves the perspectives to how documents should be resolved when applying optimistic updates,\n * like in `applySourceDocuments`.\n * @internal\n */\nexport function resolvePerspectives(\n perspective: Exclude<ClientPerspective, 'raw'>,\n): ('published' | 'drafts' | StackablePerspective)[] {\n validateApiPerspective(perspective)\n\n if (Array.isArray(perspective)) {\n if (!perspective.includes('published')) {\n return [...perspective, 'published']\n }\n return perspective\n }\n switch (perspective) {\n case 'previewDrafts':\n case 'drafts':\n return ['drafts', 'published']\n case 'published':\n default:\n return ['published']\n }\n}\n","import {getDraftId, getPublishedId, getVersionId} from './draftUtils'\nimport {resolvePerspectives} from './resolvePerspectives'\nimport type {ClientPerspective, ContentSourceMapDocuments, SanityDocument} from './types'\n\n/** @internal */\nexport type ResolvedDocument = Partial<SanityDocument> &\n Required<Pick<SanityDocument, '_id' | '_type'>>\n\n/** @internal */\nexport type MatchedDocument = Partial<SanityDocument> &\n Required<Pick<SanityDocument, '_id' | '_type' | '_originalId'>>\n\n/** @internal */\nexport function createSourceDocumentResolver(\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) => ResolvedDocument | null | undefined,\n _perspective: Exclude<ClientPerspective, 'raw'>,\n) {\n const perspectives = resolvePerspectives(_perspective)\n function findDocument(sourceDocument: ContentSourceMapDocuments[number]) {\n for (const perspective of perspectives) {\n let match: ReturnType<typeof getCachedDocument> = null\n if (perspective.startsWith('r')) {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getVersionId(sourceDocument._id, perspective),\n })\n }\n if (perspective === 'drafts') {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getDraftId(sourceDocument._id),\n })\n }\n if (perspective === 'published') {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getPublishedId(sourceDocument._id),\n })\n }\n if (match) {\n return {...match, _id: getPublishedId(match._id), _originalId: match._id}\n }\n }\n return null\n }\n // define resolver that loops over source documents and perspectives\n return function resolveSourceDocument(\n sourceDocument: ContentSourceMapDocuments[number],\n ): MatchedDocument | null {\n return findDocument(sourceDocument)\n }\n}\n","import {createSourceDocumentResolver} from './createSourceDocumentResolver'\nimport {parseJsonPath} from './jsonPath'\nimport {resolveMapping} from './resolveMapping'\nimport * as paths from './studioPath'\nimport type {\n ApplySourceDocumentsUpdateFunction,\n ClientPerspective,\n ContentSourceMap,\n ContentSourceMapDocuments,\n SanityDocument,\n} from './types'\nimport {walkMap} from './walkMap'\n\n/**\n * Optimistically applies source documents to a result, using the content source map to trace fields.\n * Can be used to apply mutations to documents being edited in a Studio, or any mutation on Content Lake, to a result with extremely low latency.\n * @alpha\n */\nexport function applySourceDocuments<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) =>\n | (Partial<SanityDocument> & Required<Pick<SanityDocument, '_id' | '_type'>>)\n | null\n | undefined,\n updateFn: ApplySourceDocumentsUpdateFunction,\n perspective: Exclude<ClientPerspective, 'raw'>,\n): Result {\n if (!resultSourceMap) return result\n\n const resolveDocument = createSourceDocumentResolver(getCachedDocument, perspective)\n const cachedDocuments = resultSourceMap.documents?.map?.(resolveDocument) || []\n\n return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {\n const resolveMappingResult = resolveMapping(path, resultSourceMap)\n if (!resolveMappingResult) {\n return value\n }\n\n const {mapping, pathSuffix} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = resultSourceMap.documents[mapping.source.document]\n const sourcePath = resultSourceMap.paths[mapping.source.path]\n\n if (sourceDocument) {\n const parsedPath = parseJsonPath(sourcePath + pathSuffix)\n const stringifiedPath = paths.toString(parsedPath)\n const cachedDocument = cachedDocuments[mapping.source.document]\n\n if (!cachedDocument) {\n return value\n }\n\n const changedValue = cachedDocument\n ? paths.get<Result[keyof Result]>(cachedDocument, stringifiedPath, value)\n : value\n return value === changedValue\n ? value\n : updateFn<Result[keyof Result]>(changedValue as Result[keyof Result], {\n cachedDocument,\n previousValue: value as Result[keyof Result],\n sourceDocument,\n sourcePath: parsedPath,\n })\n }\n\n return value\n }) as Result\n}\n","import {jsonPath, parseJsonPath} from './jsonPath'\nimport type {ContentSourceMapParsedPath} from './types'\n\n/**\n * @internal\n */\nexport function resolvedKeyedSourcePath(options: {\n keyedResultPath: ContentSourceMapParsedPath\n pathSuffix?: string\n sourceBasePath: string\n}): ContentSourceMapParsedPath {\n const {keyedResultPath, pathSuffix, sourceBasePath} = options\n\n const inferredResultPath = pathSuffix === undefined ? [] : parseJsonPath(pathSuffix)\n\n const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length)\n\n const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath).slice(1) : ''\n\n return parseJsonPath(sourceBasePath + inferredPathSuffix)\n}\n","import {createEditUrl} from './createEditUrl'\nimport {studioPathToJsonPath} from './jsonPath'\nimport {resolveEditInfo} from './resolveEditInfo'\nimport type {ResolveEditUrlOptions} from './types'\n\n/** @alpha */\nexport function resolveEditUrl(\n options: ResolveEditUrlOptions,\n): ReturnType<typeof createEditUrl> | undefined {\n const {resultSourceMap, studioUrl} = options\n const resultPath = studioPathToJsonPath(options.resultPath)\n\n const editInfo = resolveEditInfo({\n resultPath,\n resultSourceMap,\n studioUrl,\n })\n if (!editInfo) {\n return undefined\n }\n\n return createEditUrl(editInfo)\n}\n"],"mappings":";;;;;;;AASA,SAAgB,oBACd,aACmD;CAGnD,IAFA,uBAAuB,WAAW,GAE9B,MAAM,QAAQ,WAAW,GAI3B,OAHK,YAAY,SAAS,WAAW,IAG9B,cAFE,CAAC,GAAG,aAAa,WAAW;CAIvC,QAAQ,aAAR;EACE,KAAK;EACL,KAAK,UACH,OAAO,CAAC,UAAU,WAAW;EAE/B,SACE,OAAO,CAAC,WAAW;CACvB;AACF;;ACfA,SAAgB,6BACd,mBAGA,cACA;CACA,IAAM,eAAe,oBAAoB,YAAY;CACrD,SAAS,aAAa,gBAAmD;EACvE,KAAK,IAAM,eAAe,cAAc;GACtC,IAAI,QAA8C;GAmBlD,IAlBI,YAAY,WAAW,GAAG,MAC5B,QAAQ,kBAAkB;IACxB,GAAG;IACH,KAAK,aAAa,eAAe,KAAK,WAAW;GACnD,CAAC,IAEC,gBAAgB,aAClB,QAAQ,kBAAkB;IACxB,GAAG;IACH,KAAK,WAAW,eAAe,GAAG;GACpC,CAAC,IAEC,gBAAgB,gBAClB,QAAQ,kBAAkB;IACxB,GAAG;IACH,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BAAmB,MAAM,GAEvF,qBAAqB,aAAa,SAAS,SAAS,YAAY,CAAC,CAAC,MAAM,CAAC,IAAI;CAEnF,OAAO,cAAc,iBAAiB,kBAAkB;AAC1D;;ACdA,SAAgB,eACd,SAC8C;CAC9C,IAAM,EAAC,iBAAiB,cAAa,SAC/B,aAAa,qBAAqB,QAAQ,UAAU,GAEpD,WAAW,gBAAgB;EAC/B;EACA;EACA;CACF,CAAC;CACI,cAIL,OAAO,cAAc,QAAQ;AAC/B"}
package/dist/index.d.ts CHANGED
@@ -1,17 +1,19 @@
1
1
  import { d as ResolveStudioUrl, f as StegaConfig, g as StudioUrl, h as StudioBaseUrl, i as ContentSourceMapParsedPathKeyedSegment, l as InitializedStegaConfig, m as StudioBaseRoute, p as StegaConfigRequiredKeys, r as ContentSourceMapParsedPath, s as FilterDefault, u as Logger } from "./types-CfGzbXrl.js";
2
- import { $ as EditableReleaseDocument, $n as VideoRenditionInfo, $r as DocumentAgentActionParam, $t as ReleaseState, A as ContentSourceMapMappings, An as TransactionAllDocumentsMutationOptions, Ar as LiveClient, At as MutationEvent, B as DatasetAclMode, Bn as UploadBody, Br as TransformTarget, Bt as PublishReleaseAction, C as ContentSourceMap, Cn as SingleMutationResult, Cr as ObservablePatchBuilder, Ct as MediaLibraryPlaybackInfoOptions, D as ContentSourceMapDocuments, Dn as SyncTag, Dr as BasePatch, Dt as Mutation, E as ContentSourceMapDocumentValueSource, En as StoryboardTransformOptions, Er as Transaction, Et as MultipleMutationResult, F as ContentSourceMapValueMapping, Fn as UnfilteredResponseQueryOptions, Fr as TranslateTarget, Ft as PartialExcept, G as DeleteAction, Gn as VersionAction, Gr as PatchOperation, Gt as RawQueryResponse, H as DatasetEditOptions, Hn as UploadEvent, Hr as TransformTargetInclude, Ht as QueryParams, I as CreateAction, In as UnfilteredResponseWithoutQuery, Ir as TranslateTargetInclude, It as PatchMutationOperation, J as DiscardVersionAction, Jn as VideoPlaybackInfoItemPublic, Jr as AgentActionParams, Jt as ReconnectEvent, K as DeleteReleaseAction, Kn as VideoPlaybackInfo, Kr as PatchTarget, Kt as RawQuerylessQueryResponse, L as CreateReleaseAction, Ln as UnpublishAction, Lr as ImageDescriptionOperation, Lt as PatchOperations, M as ContentSourceMapRemoteDocument, Mn as TransactionFirstDocumentMutationOptions, Mr as AssetsClient, Mt as MutationSelection, N as ContentSourceMapSource, Nn as TransactionMutationOptions, Nr as ObservableAssetsClient, Nt as MutationSelectionQueryParams, O as ContentSourceMapLiteralSource, On as ThumbnailTransformOptions, Or as ObservablePatch, Ot as MutationError, P as ContentSourceMapUnknownSource, Pn as UnarchiveReleaseAction, Pr as TranslateDocument, Pt as OpenEvent, Q as EditReleaseAction, Qn as VideoPlaybackTokens, Qr as ConstantAgentActionParam, Qt as ReleaseId, R as CreateVersionAction, Rn as UnpublishVersionAction, Rr as TransformDocument, Rt as PatchSelection, S as ClientVariantConditions, Sn as SingleActionResult, Sr as BaseTransaction, St as MediaLibraryAssetInstanceIdentifier, T as ContentSourceMapDocumentBase, Tn as StillImageFormat, Tr as PatchBuilder, Tt as MultipleActionResult, U as DatasetResponse, Un as UploadProgressEvent, Ur as PromptRequest, Ut as QueryParseError, V as DatasetCreateOptions, Vn as UploadClientConfig, Vr as TransformTargetDocument, Vt as QueryOptions, W as DatasetsResponse, Wn as UploadResponseEvent, Wr as PatchDocument, Wt as QueryWithoutParams, X as EXPERIMENTAL_API_WARNING, Xn as VideoPlaybackInfoPublic, Xr as AgentActionPathSegment, Xt as ReleaseCardinality, Y as DisconnectEvent, Yn as VideoPlaybackInfoItemSigned, Yr as AgentActionPath, Yt as ReleaseAction, Z as EditAction, Zn as VideoPlaybackInfoSigned, Zr as AgentActionTarget, Zt as ReleaseDocument, _ as ChannelErrorEvent, _n as SanityProjectMember, _r as ProjectsClient, _t as LiveEventGoAway, a as AllDocumentsMutationOptions, an as RequestUrlOptions, ar as WelcomeBackEvent, at as FirstDocumentMutationOptions, b as ClientReturn, bn as SanityUser, br as DatasetsClient, bt as LiveEventRestart, c as Any, cn as ResponseQueryOptions, cr as GenerateOperation, ct as IdentifiedSanityDocumentStub, d as AssetMetadataType, dn as SanityAssetDocument, dr as GenerateTargetInclude, dt as InsertPatch, ei as FieldAgentActionParam, en as ReleaseType, er as VideoRenditionInfoPublic, et as EmbeddingsSettings, f as AttributeSet, fn as SanityDocument, fr as ObservableSanityClient, ft as ListenEvent, g as BaseMutationOptions, gn as SanityProject, gr as ObservableProjectsClient, gt as LiveEvent, h as BaseActionOptions, hn as SanityImagePalette, hr as UsersClient, ht as ListenParams, i as AllDocumentIdsMutationOptions, in as RequestOptions, ir as VideoSubtitleInfoSigned, it as FirstDocumentIdMutationOptions, j as ContentSourceMapPaths, jn as TransactionFirstDocumentIdMutationOptions, jr as _listen, jt as MutationOperation, k as ContentSourceMapMapping, kn as TransactionAllDocumentIdsMutationOptions, kr as Patch, kt as MutationErrorItem, l as ApiError, ln as ResumableListenEventNames, lr as GenerateTarget, lt as ImportReleaseAction, m as AuthProviderResponse, mn as SanityImageAssetDocument, mr as ObservableUsersClient, mt as ListenOptions, n as ActionError, nn as ReplaceVersionAction, nr as VideoSubtitleInfo, nt as ErrorProps, o as AnimatedImageFormat, on as Requester, or as WelcomeEvent, ot as FitMode, p as AuthProvider, pn as SanityDocumentStub, pr as SanityClient, pt as ListenEventName, q as DiscardAction, qn as VideoPlaybackInfoItem, qr as AgentActionParam, qt as RawRequestOptions, r as ActionErrorItem, rn as RequestObservableOptions, rr as VideoSubtitleInfoPublic, rt as FilteredResponseQueryOptions, s as AnimatedTransformOptions, sn as ResetEvent, sr as GenerateInstruction, st as HttpRequest, t as Action, ti as GroqAgentActionParam, tn as ReplaceDraftAction, tr as VideoRenditionInfoSigned, tt as EmbeddingsSettingsBody, u as ArchiveReleaseAction, un as ResumableListenOptions, ur as GenerateTargetDocument, ut as InitializedClientConfig, v as ClientConfig, vn as SanityQueries, vr as MediaLibraryVideoClient, vt as LiveEventMessage, w as ContentSourceMapDocument, wn as StackablePerspective, wr as ObservableTransaction, wt as MediaLibraryVideoPlaybackTransformations, x as ClientVariant, xn as ScheduleReleaseAction, xr as ObservableDatasetsClient, xt as LiveEventWelcome, y as ClientPerspective, yn as SanityReference, yr as ObservableMediaLibraryVideoClient, yt as LiveEventReconnect, z as CurrentSanityUser, zn as UnscheduleReleaseAction, zr as TransformOperation, zt as PublishAction } from "./types-CUxZSgB2.js";
3
- import { FetchFunction } from "get-it";
2
+ import { $ as EditAction, $n as VersionAction, $r as PromptRequest, $t as ReconnectEvent, A as ContentSourceMapMappings, An as SingleMutationResult, Ar as DatasetsClient, At as MultipleActionResult, B as CurrentSanityUser, Bn as TransactionMutationOptions, Br as LiveClient, Bt as PartialExcept, C as ContentSourceMap, Cn as SanityProject, Cr as UsersClient, Ct as LiveEventRestart, D as ContentSourceMapDocuments, Dn as SanityUser, Dr as ObservableMediaLibraryVideoClient, Dt as MediaLibraryAssetVersion, E as ContentSourceMapDocumentValueSource, En as SanityReference, Er as MediaLibraryVideoClient, Et as MediaLibraryAssetInstanceIdentifier, F as ContentSourceMapValueMapping, Fn as ThumbnailTransformOptions, Fr as PatchBuilder, Ft as MutationEvent, G as DatasetsResponse, Gn as UnpublishVersionAction, Gr as TranslateTarget, Gt as PublishReleaseAction, H as DatasetCreateOptions, Hn as UnfilteredResponseQueryOptions, Hr as AssetsClient, Ht as PatchOperations, I as CreateAction, In as TransactionAllDocumentIdsMutationOptions, Ir as Transaction, It as MutationOperation, J as DeleteVariantDefinitionAction, Jn as UploadClientConfig, Jr as TransformDocument, Jt as QueryParseError, K as DeleteAction, Kn as UnscheduleReleaseAction, Kr as TranslateTargetInclude, Kt as QueryOptions, L as CreateReleaseAction, Ln as TransactionAllDocumentsMutationOptions, Lr as BasePatch, Lt as MutationSelection, M as ContentSourceMapRemoteDocument, Mn as StillImageFormat, Mr as BaseTransaction, Mt as Mutation, N as ContentSourceMapSource, Nn as StoryboardTransformOptions, Nr as ObservablePatchBuilder, Nt as MutationError, O as ContentSourceMapLiteralSource, On as ScheduleReleaseAction, Or as InvokeFunctionEvent, Ot as MediaLibraryPlaybackInfoOptions, P as ContentSourceMapUnknownSource, Pn as SyncTag, Pr as ObservableTransaction, Pt as MutationErrorItem, Q as EXPERIMENTAL_API_WARNING, Qn as VariantDefinitionAction, Qr as TransformTargetInclude, Qt as RawRequestOptions, R as CreateVariantDefinitionAction, Rn as TransactionFirstDocumentIdMutationOptions, Rr as ObservablePatch, Rt as MutationSelectionQueryParams, S as ClientVariantConditions, Sn as SanityImagePalette, Sr as ObservableUsersClient, St as LiveEventReconnect, T as ContentSourceMapDocumentBase, Tn as SanityQueries, Tr as ProjectsClient, Tt as MediaLibraryAssetDocument, U as DatasetEditOptions, Un as UnfilteredResponseWithoutQuery, Ur as ObservableAssetsClient, Ut as PatchSelection, V as DatasetAclMode, Vn as UnarchiveReleaseAction, Vr as _listen, Vt as PatchMutationOperation, W as DatasetResponse, Wn as UnpublishAction, Wr as TranslateDocument, Wt as PublishAction, X as DiscardVersionAction, Xn as UploadProgressEvent, Xr as TransformTarget, Xt as RawQueryResponse, Y as DiscardAction, Yn as UploadEvent, Yr as TransformOperation, Yt as QueryWithoutParams, Z as DisconnectEvent, Zn as UploadResponseEvent, Zr as TransformTargetDocument, Zt as RawQuerylessQueryResponse, _ as ChannelErrorEvent, _n as ResumableListenOptions, _r as GenerateTarget, _t as ListenOptions, a as AllDocumentsMutationOptions, ai as AgentActionPath, an as ReleaseType, ar as VideoPlaybackInfoSigned, at as ErrorProps, b as ClientReturn, bn as SanityDocumentStub, br as ObservableSanityClient, bt as LiveEventGoAway, c as Any, ci as ConstantAgentActionParam, cn as RequestHandler, cr as VideoRenditionInfoPublic, ct as FirstDocumentMutationOptions, d as AssetMetadataType, di as GroqAgentActionParam, dn as RequestOptions, dr as VideoSubtitleInfoPublic, dt as IdentifiedSanityDocumentStub, ei as PatchDocument, en as ReleaseAction, er as VideoPlaybackInfo, et as EditReleaseAction, f as AttributeSet, fn as RequestUrlOptions, fr as VideoSubtitleInfoSigned, ft as ImportReleaseAction, g as BaseMutationOptions, gn as ResumableListenEventNames, gr as GenerateOperation, gt as ListenEventName, h as BaseActionOptions, hn as ResponseQueryOptions, hr as GenerateInstruction, ht as ListenEvent, i as AllDocumentIdsMutationOptions, ii as AgentActionParams, in as ReleaseState, ir as VideoPlaybackInfoPublic, it as EmbeddingsSettingsBody, j as ContentSourceMapPaths, jn as StackablePerspective, jr as ObservableDatasetsClient, jt as MultipleMutationResult, k as ContentSourceMapMapping, kn as SingleActionResult, kr as InvokeFunctionRequest, kt as MediaLibraryVideoPlaybackTransformations, l as ApiError, li as DocumentAgentActionParam, ln as RequestHandlerOptions, lr as VideoRenditionInfoSigned, lt as FitMode, m as AuthProviderResponse, mn as ResetEvent, mr as WelcomeEvent, mt as InsertPatch, n as ActionError, ni as PatchTarget, nn as ReleaseDocument, nr as VideoPlaybackInfoItemPublic, nt as EditableReleaseDocument, o as AnimatedImageFormat, oi as AgentActionPathSegment, on as ReplaceDraftAction, or as VideoPlaybackTokens, ot as FilteredResponseQueryOptions, p as AuthProvider, pn as Requester, pr as WelcomeBackEvent, pt as InitializedClientConfig, q as DeleteReleaseAction, qn as UploadBody, qr as ImageDescriptionOperation, qt as QueryParams, r as ActionErrorItem, ri as AgentActionParam, rn as ReleaseId, rr as VideoPlaybackInfoItemSigned, rt as EmbeddingsSettings, s as AnimatedTransformOptions, si as AgentActionTarget, sn as ReplaceVersionAction, sr as VideoRenditionInfo, st as FirstDocumentIdMutationOptions, t as Action, ti as PatchOperation, tn as ReleaseCardinality, tr as VideoPlaybackInfoItem, tt as EditVariantDefinitionAction, u as ArchiveReleaseAction, ui as FieldAgentActionParam, un as RequestObservableOptions, ur as VideoSubtitleInfo, ut as HttpRequest, v as ClientConfig, vn as SanityAssetDocument, vr as GenerateTargetDocument, vt as ListenParams, w as ContentSourceMapDocument, wn as SanityProjectMember, wr as ObservableProjectsClient, wt as LiveEventWelcome, x as ClientVariant, xn as SanityImageAssetDocument, xr as SanityClient, xt as LiveEventMessage, y as ClientPerspective, yn as SanityDocument, yr as GenerateTargetInclude, yt as LiveEvent, z as CreateVersionAction, zn as TransactionFirstDocumentMutationOptions, zr as Patch, zt as OpenEvent } from "./types-BODIEY7F.js";
3
+ import { FetchFunction, RequestOptions as RequestOptions$1, TimeoutErrorLike, isTimeoutError } from "get-it";
4
4
  import { Observable } from "rxjs";
5
+ import { EventSourceConstructor } from "eventsource";
5
6
  /**
6
7
  * @internal - it may have breaking changes in any release
7
8
  */
8
9
  declare function validateApiPerspective(perspective: unknown): asserts perspective is ClientPerspective;
9
10
  /**
10
- * @public
11
11
  * Thrown when the EventSource connection could not be established, or was rejected by the server.
12
12
  * Transient failures (network drops, 5xx, 408, 429) are reconnected internally and emitted as
13
13
  * `reconnect` events; a permanent rejection (any other 4xx, eg an expired token) errors the
14
14
  * stream with this class so consumers can react — check `status` for the rejection code.
15
+ *
16
+ * @public
15
17
  */
16
18
  declare class ConnectionFailedError extends Error {
17
19
  readonly name = "ConnectionFailedError";
@@ -28,8 +30,9 @@ declare class ConnectionFailedError extends Error {
28
30
  }
29
31
  /**
30
32
  * The listener has been told to explicitly disconnect.
31
- * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
32
- * eg in the case of a deleted dataset, a blocked project or similar events.
33
+ * This is a rare situation, but may occur if the API knows reconnect attempts will fail,
34
+ * eg in the case of a deleted dataset, a blocked project or similar events.
35
+ *
33
36
  * @public
34
37
  */
35
38
  declare class DisconnectError extends Error {
@@ -38,8 +41,9 @@ declare class DisconnectError extends Error {
38
41
  constructor(message: string, reason?: string, options?: ErrorOptions);
39
42
  }
40
43
  /**
41
- * @public
42
44
  * The server sent a `channelError` message. Usually indicative of a bad or malformed request
45
+ *
46
+ * @public
43
47
  */
44
48
  declare class ChannelError extends Error {
45
49
  readonly name = "ChannelError";
@@ -47,8 +51,9 @@ declare class ChannelError extends Error {
47
51
  constructor(message: string, data: unknown);
48
52
  }
49
53
  /**
50
- * @public
51
54
  * The server sent an `error`-event to tell the client that an unexpected error has happened.
55
+ *
56
+ * @public
52
57
  */
53
58
  declare class MessageError extends Error {
54
59
  readonly name = "MessageError";
@@ -56,8 +61,9 @@ declare class MessageError extends Error {
56
61
  constructor(message: string, data: unknown, options?: ErrorOptions);
57
62
  }
58
63
  /**
59
- * @public
60
64
  * An error occurred while parsing the message sent by the server as JSON. Should normally not happen.
65
+ *
66
+ * @public
61
67
  */
62
68
  declare class MessageParseError extends Error {
63
69
  readonly name = "MessageParseError";
@@ -77,7 +83,7 @@ type EventSourceEvent<Name extends string> = ServerSentEvent<Name>;
77
83
  /**
78
84
  * @internal
79
85
  */
80
- type EventSourceInstance = InstanceType<typeof globalThis.EventSource>;
86
+ type EventSourceInstance = InstanceType<EventSourceConstructor>;
81
87
  /**
82
88
  * Sanity API specific EventSource handler shared between the listen and live APIs
83
89
  *
@@ -97,7 +103,7 @@ type EventSourceInstance = InstanceType<typeof globalThis.EventSource>;
97
103
  *
98
104
  * @internal
99
105
  */
100
- declare function connectEventSource<EventName extends string>(initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>, events: EventName[]): Observable<ServerSentEvent<EventName>>;
106
+ declare function connectEventSource<EventName extends string>(initEventSource: () => EventSourceInstance | Observable<EventSourceInstance>, events: EventName[]): Observable<EventSourceEvent<EventName>>;
101
107
  /**
102
108
  * Shared properties for HTTP errors (eg both ClientError and ServerError)
103
109
  * Use `isHttpError` for type narrowing and accessing response properties.
@@ -175,5 +181,5 @@ declare const createClient: (config: ClientConfig) => SanityClient;
175
181
  * @deprecated Use the named export `createClient` instead of the `default` export
176
182
  */
177
183
  declare const deprecatedCreateClient: (config: ClientConfig) => SanityClient;
178
- export { Action, ActionError, ActionErrorItem, type AgentActionParam, type AgentActionParams, type AgentActionPath, type AgentActionPathSegment, type AgentActionTarget, AllDocumentIdsMutationOptions, AllDocumentsMutationOptions, AnimatedImageFormat, AnimatedTransformOptions, Any, ApiError, ArchiveReleaseAction, AssetMetadataType, type AssetsClient, AttributeSet, AuthProvider, AuthProviderResponse, BaseActionOptions, BaseMutationOptions, BasePatch, BaseTransaction, ChannelError, ChannelErrorEvent, ClientConfig, ClientError, ClientPerspective, ClientReturn, ClientVariant, ClientVariantConditions, ConnectionFailedError, type ConstantAgentActionParam, ContentSourceMap, ContentSourceMapDocument, ContentSourceMapDocumentBase, ContentSourceMapDocumentValueSource, ContentSourceMapDocuments, ContentSourceMapLiteralSource, ContentSourceMapMapping, ContentSourceMapMappings, type ContentSourceMapParsedPath, type ContentSourceMapParsedPathKeyedSegment, ContentSourceMapPaths, ContentSourceMapRemoteDocument, ContentSourceMapSource, ContentSourceMapUnknownSource, ContentSourceMapValueMapping, CorsOriginError, CreateAction, CreateReleaseAction, CreateVersionAction, CurrentSanityUser, DatasetAclMode, DatasetCreateOptions, DatasetEditOptions, DatasetResponse, type DatasetsClient, DatasetsResponse, DeleteAction, DeleteReleaseAction, DiscardAction, DiscardVersionAction, DisconnectError, DisconnectEvent, type DocumentAgentActionParam, EXPERIMENTAL_API_WARNING, EditAction, EditReleaseAction, EditableReleaseDocument, EmbeddingsSettings, EmbeddingsSettingsBody, ErrorProps, type EventSourceEvent, type EventSourceInstance, type FieldAgentActionParam, type FilterDefault, FilteredResponseQueryOptions, FirstDocumentIdMutationOptions, FirstDocumentMutationOptions, FitMode, type GenerateInstruction, type GenerateOperation, type GenerateTarget, type GenerateTargetDocument, type GenerateTargetInclude, type GroqAgentActionParam, type HttpError, HttpRequest, IdentifiedSanityDocumentStub, type ImageDescriptionOperation, ImportReleaseAction, InitializedClientConfig, type InitializedStegaConfig, InsertPatch, ListenEvent, ListenEventName, ListenOptions, ListenParams, type LiveClient, LiveEvent, LiveEventGoAway, LiveEventMessage, LiveEventReconnect, LiveEventRestart, LiveEventWelcome, type Logger, MediaLibraryAssetInstanceIdentifier, MediaLibraryPlaybackInfoOptions, type MediaLibraryVideoClient, MediaLibraryVideoPlaybackTransformations, MessageError, MessageParseError, MultipleActionResult, MultipleMutationResult, Mutation, MutationError, MutationErrorItem, MutationEvent, MutationOperation, MutationSelection, MutationSelectionQueryParams, type ObservableAssetsClient, type ObservableDatasetsClient, type ObservableMediaLibraryVideoClient, ObservablePatch, ObservablePatchBuilder, type ObservableProjectsClient, ObservableSanityClient, ObservableTransaction, type ObservableUsersClient, OpenEvent, PartialExcept, Patch, PatchBuilder, type PatchDocument, PatchMutationOperation, type PatchOperation, PatchOperations, PatchSelection, type PatchTarget, type ProjectsClient, type PromptRequest, PublishAction, PublishReleaseAction, QueryOptions, QueryParams, QueryParseError, QueryWithoutParams, RawQueryResponse, RawQuerylessQueryResponse, RawRequestOptions, ReconnectEvent, ReleaseAction, ReleaseCardinality, ReleaseDocument, ReleaseId, ReleaseState, ReleaseType, ReplaceDraftAction, ReplaceVersionAction, RequestObservableOptions, RequestOptions, RequestUrlOptions, Requester, ResetEvent, type ResolveStudioUrl, ResponseQueryOptions, ResumableListenEventNames, ResumableListenOptions, SanityAssetDocument, SanityClient, SanityDocument, SanityDocumentStub, SanityImageAssetDocument, SanityImagePalette, SanityProject, SanityProjectMember, SanityQueries, SanityReference, SanityUser, ScheduleReleaseAction, ServerError, type ServerSentEvent, SingleActionResult, SingleMutationResult, StackablePerspective, type StegaConfig, type StegaConfigRequiredKeys, StillImageFormat, StoryboardTransformOptions, type StudioBaseRoute, type StudioBaseUrl, type StudioUrl, SyncTag, ThumbnailTransformOptions, Transaction, TransactionAllDocumentIdsMutationOptions, TransactionAllDocumentsMutationOptions, TransactionFirstDocumentIdMutationOptions, TransactionFirstDocumentMutationOptions, TransactionMutationOptions, type TransformDocument, type TransformOperation, type TransformTarget, type TransformTargetDocument, type TransformTargetInclude, type TranslateDocument, type TranslateTarget, type TranslateTargetInclude, UnarchiveReleaseAction, UnfilteredResponseQueryOptions, UnfilteredResponseWithoutQuery, UnpublishAction, UnpublishVersionAction, UnscheduleReleaseAction, UploadBody, UploadClientConfig, UploadEvent, UploadProgressEvent, UploadResponseEvent, type UsersClient, VersionAction, VideoPlaybackInfo, VideoPlaybackInfoItem, VideoPlaybackInfoItemPublic, VideoPlaybackInfoItemSigned, VideoPlaybackInfoPublic, VideoPlaybackInfoSigned, VideoPlaybackTokens, VideoRenditionInfo, VideoRenditionInfoPublic, VideoRenditionInfoSigned, VideoSubtitleInfo, VideoSubtitleInfoPublic, VideoSubtitleInfoSigned, WelcomeBackEvent, WelcomeEvent, type _listen, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, requester, validateApiPerspective };
184
+ export { Action, ActionError, ActionErrorItem, type AgentActionParam, type AgentActionParams, type AgentActionPath, type AgentActionPathSegment, type AgentActionTarget, AllDocumentIdsMutationOptions, AllDocumentsMutationOptions, AnimatedImageFormat, AnimatedTransformOptions, Any, ApiError, ArchiveReleaseAction, AssetMetadataType, type AssetsClient, AttributeSet, AuthProvider, AuthProviderResponse, BaseActionOptions, BaseMutationOptions, BasePatch, BaseTransaction, ChannelError, ChannelErrorEvent, ClientConfig, ClientError, ClientPerspective, ClientReturn, ClientVariant, ClientVariantConditions, ConnectionFailedError, type ConstantAgentActionParam, ContentSourceMap, ContentSourceMapDocument, ContentSourceMapDocumentBase, ContentSourceMapDocumentValueSource, ContentSourceMapDocuments, ContentSourceMapLiteralSource, ContentSourceMapMapping, ContentSourceMapMappings, type ContentSourceMapParsedPath, type ContentSourceMapParsedPathKeyedSegment, ContentSourceMapPaths, ContentSourceMapRemoteDocument, ContentSourceMapSource, ContentSourceMapUnknownSource, ContentSourceMapValueMapping, CorsOriginError, CreateAction, CreateReleaseAction, CreateVariantDefinitionAction, CreateVersionAction, CurrentSanityUser, DatasetAclMode, DatasetCreateOptions, DatasetEditOptions, DatasetResponse, type DatasetsClient, DatasetsResponse, DeleteAction, DeleteReleaseAction, DeleteVariantDefinitionAction, DiscardAction, DiscardVersionAction, DisconnectError, DisconnectEvent, type DocumentAgentActionParam, EXPERIMENTAL_API_WARNING, EditAction, EditReleaseAction, EditVariantDefinitionAction, EditableReleaseDocument, EmbeddingsSettings, EmbeddingsSettingsBody, ErrorProps, type EventSourceEvent, type EventSourceInstance, type FieldAgentActionParam, type FilterDefault, FilteredResponseQueryOptions, FirstDocumentIdMutationOptions, FirstDocumentMutationOptions, FitMode, type GenerateInstruction, type GenerateOperation, type GenerateTarget, type GenerateTargetDocument, type GenerateTargetInclude, type GroqAgentActionParam, type HttpError, HttpRequest, IdentifiedSanityDocumentStub, type ImageDescriptionOperation, ImportReleaseAction, InitializedClientConfig, type InitializedStegaConfig, InsertPatch, type InvokeFunctionEvent, type InvokeFunctionRequest, ListenEvent, ListenEventName, ListenOptions, ListenParams, type LiveClient, LiveEvent, LiveEventGoAway, LiveEventMessage, LiveEventReconnect, LiveEventRestart, LiveEventWelcome, type Logger, MediaLibraryAssetDocument, MediaLibraryAssetInstanceIdentifier, MediaLibraryAssetVersion, MediaLibraryPlaybackInfoOptions, type MediaLibraryVideoClient, MediaLibraryVideoPlaybackTransformations, MessageError, MessageParseError, MultipleActionResult, MultipleMutationResult, Mutation, MutationError, MutationErrorItem, MutationEvent, MutationOperation, MutationSelection, MutationSelectionQueryParams, type ObservableAssetsClient, type ObservableDatasetsClient, type ObservableMediaLibraryVideoClient, ObservablePatch, ObservablePatchBuilder, type ObservableProjectsClient, ObservableSanityClient, ObservableTransaction, type ObservableUsersClient, OpenEvent, PartialExcept, Patch, PatchBuilder, type PatchDocument, PatchMutationOperation, type PatchOperation, PatchOperations, PatchSelection, type PatchTarget, type ProjectsClient, type PromptRequest, PublishAction, PublishReleaseAction, QueryOptions, QueryParams, QueryParseError, QueryWithoutParams, RawQueryResponse, RawQuerylessQueryResponse, RawRequestOptions, ReconnectEvent, ReleaseAction, ReleaseCardinality, ReleaseDocument, ReleaseId, ReleaseState, ReleaseType, ReplaceDraftAction, ReplaceVersionAction, RequestHandler, RequestHandlerOptions, RequestObservableOptions, RequestOptions, RequestUrlOptions, Requester, ResetEvent, type ResolveStudioUrl, ResponseQueryOptions, ResumableListenEventNames, ResumableListenOptions, SanityAssetDocument, SanityClient, SanityDocument, SanityDocumentStub, SanityImageAssetDocument, SanityImagePalette, SanityProject, SanityProjectMember, SanityQueries, SanityReference, SanityUser, ScheduleReleaseAction, ServerError, type ServerSentEvent, SingleActionResult, SingleMutationResult, StackablePerspective, type StegaConfig, type StegaConfigRequiredKeys, StillImageFormat, StoryboardTransformOptions, type StudioBaseRoute, type StudioBaseUrl, type StudioUrl, SyncTag, ThumbnailTransformOptions, type TimeoutErrorLike, Transaction, TransactionAllDocumentIdsMutationOptions, TransactionAllDocumentsMutationOptions, TransactionFirstDocumentIdMutationOptions, TransactionFirstDocumentMutationOptions, TransactionMutationOptions, type TransformDocument, type TransformOperation, type TransformTarget, type TransformTargetDocument, type TransformTargetInclude, type TranslateDocument, type TranslateTarget, type TranslateTargetInclude, UnarchiveReleaseAction, UnfilteredResponseQueryOptions, UnfilteredResponseWithoutQuery, UnpublishAction, UnpublishVersionAction, UnscheduleReleaseAction, UploadBody, UploadClientConfig, UploadEvent, UploadProgressEvent, UploadResponseEvent, type UsersClient, VariantDefinitionAction, VersionAction, VideoPlaybackInfo, VideoPlaybackInfoItem, VideoPlaybackInfoItemPublic, VideoPlaybackInfoItemSigned, VideoPlaybackInfoPublic, VideoPlaybackInfoSigned, VideoPlaybackTokens, VideoRenditionInfo, VideoRenditionInfoPublic, VideoRenditionInfoSigned, VideoSubtitleInfo, VideoSubtitleInfoPublic, VideoSubtitleInfoSigned, WelcomeBackEvent, WelcomeEvent, type _listen, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, isTimeoutError, requester, validateApiPerspective };
179
185
  //# sourceMappingURL=index.d.ts.map