@sanity/client 7.5.0-live-cors.3 → 7.6.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.
@@ -1711,7 +1711,7 @@ export declare type IdentifiedSanityDocumentStub<
1711
1711
  * @see #TransformOperation
1712
1712
  * @beta
1713
1713
  */
1714
- export declare interface ImageDescriptionOperation {
1714
+ export declare type ImageDescriptionOperation = {
1715
1715
  type: 'image-description'
1716
1716
  /**
1717
1717
  * When omitted, parent image value will be inferred from the arget path.
@@ -1722,7 +1722,32 @@ export declare interface ImageDescriptionOperation {
1722
1722
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1723
1723
  */
1724
1724
  sourcePath?: AgentActionPath
1725
- }
1725
+ } & (
1726
+ | {
1727
+ /**
1728
+ * When omitted, parent image value will be inferred from the target path.
1729
+ *
1730
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1731
+ * - `['image']`
1732
+ * - `['wrapper', 'mainImage']`
1733
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1734
+ *
1735
+ * Incompatible with `imageUrl`
1736
+ *
1737
+ */
1738
+ sourcePath?: AgentActionPath
1739
+ imageUrl?: never
1740
+ }
1741
+ | {
1742
+ /**
1743
+ * When specified, the image source to be described will be fetched from the URL.
1744
+ *
1745
+ * Incompatible with `sourcePath`
1746
+ */
1747
+ imageUrl?: `https://${string}`
1748
+ sourcePath?: never
1749
+ }
1750
+ )
1726
1751
 
1727
1752
  /** @public */
1728
1753
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5553,6 +5578,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5553
5578
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5554
5579
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5555
5580
  *
5581
+ * ### Targeting images outside the document (URL)
5582
+ * If the source image is available on a https URL outside the target document, it is possible to get a description for it using `imageUrl`.
5583
+ *
5584
+ * Example:
5585
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5556
5586
  * @beta
5557
5587
  */
5558
5588
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
@@ -1711,7 +1711,7 @@ export declare type IdentifiedSanityDocumentStub<
1711
1711
  * @see #TransformOperation
1712
1712
  * @beta
1713
1713
  */
1714
- export declare interface ImageDescriptionOperation {
1714
+ export declare type ImageDescriptionOperation = {
1715
1715
  type: 'image-description'
1716
1716
  /**
1717
1717
  * When omitted, parent image value will be inferred from the arget path.
@@ -1722,7 +1722,32 @@ export declare interface ImageDescriptionOperation {
1722
1722
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1723
1723
  */
1724
1724
  sourcePath?: AgentActionPath
1725
- }
1725
+ } & (
1726
+ | {
1727
+ /**
1728
+ * When omitted, parent image value will be inferred from the target path.
1729
+ *
1730
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1731
+ * - `['image']`
1732
+ * - `['wrapper', 'mainImage']`
1733
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1734
+ *
1735
+ * Incompatible with `imageUrl`
1736
+ *
1737
+ */
1738
+ sourcePath?: AgentActionPath
1739
+ imageUrl?: never
1740
+ }
1741
+ | {
1742
+ /**
1743
+ * When specified, the image source to be described will be fetched from the URL.
1744
+ *
1745
+ * Incompatible with `sourcePath`
1746
+ */
1747
+ imageUrl?: `https://${string}`
1748
+ sourcePath?: never
1749
+ }
1750
+ )
1726
1751
 
1727
1752
  /** @public */
1728
1753
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5553,6 +5578,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5553
5578
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5554
5579
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5555
5580
  *
5581
+ * ### Targeting images outside the document (URL)
5582
+ * If the source image is available on a https URL outside the target document, it is possible to get a description for it using `imageUrl`.
5583
+ *
5584
+ * Example:
5585
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5556
5586
  * @beta
5557
5587
  */
5558
5588
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
@@ -1443,30 +1443,17 @@ class LiveClient {
1443
1443
  }
1444
1444
  return event;
1445
1445
  })
1446
- );
1447
- console.log("YES THIS IS THE CORS VERSION with the allowed origin check");
1448
- const isAllowedOrigin = (origin2) => [
1449
- /^http:\/\/localhost:/,
1450
- /^http:\/\/127\.0\.0\.1:/,
1451
- /^https:\/\/[^.]*\.sanity\.studio$/,
1452
- /^https:\/\/[^.]*\.studio\.sanity\.work$/,
1453
- /^https:\/\/[^.]*\.sanity\.work$/,
1454
- /^https:\/\/[^.]*\.sanity\.io$/
1455
- ].some((pattern) => pattern.test(origin2)), checkCors = fetchObservable(url, {
1446
+ ), checkCors = fetchObservable(url, {
1456
1447
  method: "OPTIONS",
1457
1448
  mode: "cors",
1458
1449
  credentials: esOptions.withCredentials ? "include" : "omit",
1459
- headers: {
1460
- ...esOptions.headers,
1461
- "Access-Control-Request-Headers": "authorization"
1462
- // for this preflight check, ensure we send what the browser would send if needed
1463
- }
1450
+ headers: esOptions.headers
1464
1451
  }).pipe(
1465
1452
  mergeMap(() => EMPTY),
1466
1453
  catchError(() => {
1467
1454
  throw new CorsOriginError({ projectId: projectId2 });
1468
1455
  })
1469
- ), origin = typeof location < "u" ? location.origin : "", observable2 = (isAllowedOrigin(origin) ? events : concat(checkCors, events)).pipe(
1456
+ ), observable2 = concat(checkCors, events).pipe(
1470
1457
  finalize$1(() => eventsCache.delete(key)),
1471
1458
  shareReplayLatest({
1472
1459
  predicate: (event) => event.type === "welcome"