@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.
package/dist/index.d.cts CHANGED
@@ -1715,7 +1715,7 @@ export declare type IdentifiedSanityDocumentStub<
1715
1715
  * @see #TransformOperation
1716
1716
  * @beta
1717
1717
  */
1718
- export declare interface ImageDescriptionOperation {
1718
+ export declare type ImageDescriptionOperation = {
1719
1719
  type: 'image-description'
1720
1720
  /**
1721
1721
  * When omitted, parent image value will be inferred from the arget path.
@@ -1726,7 +1726,32 @@ export declare interface ImageDescriptionOperation {
1726
1726
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1727
1727
  */
1728
1728
  sourcePath?: AgentActionPath
1729
- }
1729
+ } & (
1730
+ | {
1731
+ /**
1732
+ * When omitted, parent image value will be inferred from the target path.
1733
+ *
1734
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1735
+ * - `['image']`
1736
+ * - `['wrapper', 'mainImage']`
1737
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1738
+ *
1739
+ * Incompatible with `imageUrl`
1740
+ *
1741
+ */
1742
+ sourcePath?: AgentActionPath
1743
+ imageUrl?: never
1744
+ }
1745
+ | {
1746
+ /**
1747
+ * When specified, the image source to be described will be fetched from the URL.
1748
+ *
1749
+ * Incompatible with `sourcePath`
1750
+ */
1751
+ imageUrl?: `https://${string}`
1752
+ sourcePath?: never
1753
+ }
1754
+ )
1730
1755
 
1731
1756
  /** @public */
1732
1757
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5557,6 +5582,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5557
5582
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5558
5583
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5559
5584
  *
5585
+ * ### Targeting images outside the document (URL)
5586
+ * 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`.
5587
+ *
5588
+ * Example:
5589
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5560
5590
  * @beta
5561
5591
  */
5562
5592
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
package/dist/index.d.ts CHANGED
@@ -1715,7 +1715,7 @@ export declare type IdentifiedSanityDocumentStub<
1715
1715
  * @see #TransformOperation
1716
1716
  * @beta
1717
1717
  */
1718
- export declare interface ImageDescriptionOperation {
1718
+ export declare type ImageDescriptionOperation = {
1719
1719
  type: 'image-description'
1720
1720
  /**
1721
1721
  * When omitted, parent image value will be inferred from the arget path.
@@ -1726,7 +1726,32 @@ export declare interface ImageDescriptionOperation {
1726
1726
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1727
1727
  */
1728
1728
  sourcePath?: AgentActionPath
1729
- }
1729
+ } & (
1730
+ | {
1731
+ /**
1732
+ * When omitted, parent image value will be inferred from the target path.
1733
+ *
1734
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1735
+ * - `['image']`
1736
+ * - `['wrapper', 'mainImage']`
1737
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1738
+ *
1739
+ * Incompatible with `imageUrl`
1740
+ *
1741
+ */
1742
+ sourcePath?: AgentActionPath
1743
+ imageUrl?: never
1744
+ }
1745
+ | {
1746
+ /**
1747
+ * When specified, the image source to be described will be fetched from the URL.
1748
+ *
1749
+ * Incompatible with `sourcePath`
1750
+ */
1751
+ imageUrl?: `https://${string}`
1752
+ sourcePath?: never
1753
+ }
1754
+ )
1730
1755
 
1731
1756
  /** @public */
1732
1757
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5557,6 +5582,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5557
5582
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5558
5583
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5559
5584
  *
5585
+ * ### Targeting images outside the document (URL)
5586
+ * 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`.
5587
+ *
5588
+ * Example:
5589
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5560
5590
  * @beta
5561
5591
  */
5562
5592
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
package/dist/index.js CHANGED
@@ -1275,30 +1275,17 @@ class LiveClient {
1275
1275
  }
1276
1276
  return event;
1277
1277
  })
1278
- );
1279
- console.log("YES THIS IS THE CORS VERSION with the allowed origin check");
1280
- const isAllowedOrigin = (origin2) => [
1281
- /^http:\/\/localhost:/,
1282
- /^http:\/\/127\.0\.0\.1:/,
1283
- /^https:\/\/[^.]*\.sanity\.studio$/,
1284
- /^https:\/\/[^.]*\.studio\.sanity\.work$/,
1285
- /^https:\/\/[^.]*\.sanity\.work$/,
1286
- /^https:\/\/[^.]*\.sanity\.io$/
1287
- ].some((pattern) => pattern.test(origin2)), checkCors = fetchObservable(url, {
1278
+ ), checkCors = fetchObservable(url, {
1288
1279
  method: "OPTIONS",
1289
1280
  mode: "cors",
1290
1281
  credentials: esOptions.withCredentials ? "include" : "omit",
1291
- headers: {
1292
- ...esOptions.headers,
1293
- "Access-Control-Request-Headers": "authorization"
1294
- // for this preflight check, ensure we send what the browser would send if needed
1295
- }
1282
+ headers: esOptions.headers
1296
1283
  }).pipe(
1297
1284
  mergeMap(() => EMPTY),
1298
1285
  catchError(() => {
1299
1286
  throw new CorsOriginError({ projectId });
1300
1287
  })
1301
- ), origin = typeof location < "u" ? location.origin : "", observable2 = (isAllowedOrigin(origin) ? events : concat(checkCors, events)).pipe(
1288
+ ), observable2 = concat(checkCors, events).pipe(
1302
1289
  finalize$1(() => eventsCache.delete(key)),
1303
1290
  shareReplayLatest({
1304
1291
  predicate: (event) => event.type === "welcome"
@@ -2523,7 +2510,7 @@ function defineDeprecatedCreateClient(createClient2) {
2523
2510
  return printNoDefaultExport(), createClient2(config);
2524
2511
  };
2525
2512
  }
2526
- var name = "@sanity/client", version = "7.5.0-live-cors.3";
2513
+ var name = "@sanity/client", version = "7.6.0";
2527
2514
  const middleware = [
2528
2515
  debug({ verbose: !0, namespace: "sanity:client" }),
2529
2516
  headers({ "User-Agent": `${name} ${version}` }),