@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/README.md CHANGED
@@ -2138,6 +2138,13 @@ For example:
2138
2138
  - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
2139
2139
  - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
2140
2140
 
2141
+
2142
+ ###### Targeting images outside the document (URL)
2143
+ 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`.
2144
+
2145
+ Example:
2146
+ - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
2147
+
2141
2148
  ##### Example: Field-based transformation
2142
2149
 
2143
2150
  ```ts
@@ -1459,30 +1459,17 @@ class LiveClient {
1459
1459
  }
1460
1460
  return event;
1461
1461
  })
1462
- );
1463
- console.log("YES THIS IS THE CORS VERSION with the allowed origin check");
1464
- const isAllowedOrigin = (origin2) => [
1465
- /^http:\/\/localhost:/,
1466
- /^http:\/\/127\.0\.0\.1:/,
1467
- /^https:\/\/[^.]*\.sanity\.studio$/,
1468
- /^https:\/\/[^.]*\.studio\.sanity\.work$/,
1469
- /^https:\/\/[^.]*\.sanity\.work$/,
1470
- /^https:\/\/[^.]*\.sanity\.io$/
1471
- ].some((pattern) => pattern.test(origin2)), checkCors = fetchObservable(url, {
1462
+ ), checkCors = fetchObservable(url, {
1472
1463
  method: "OPTIONS",
1473
1464
  mode: "cors",
1474
1465
  credentials: esOptions.withCredentials ? "include" : "omit",
1475
- headers: {
1476
- ...esOptions.headers,
1477
- "Access-Control-Request-Headers": "authorization"
1478
- // for this preflight check, ensure we send what the browser would send if needed
1479
- }
1466
+ headers: esOptions.headers
1480
1467
  }).pipe(
1481
1468
  rxjs.mergeMap(() => rxjs.EMPTY),
1482
1469
  rxjs.catchError(() => {
1483
1470
  throw new CorsOriginError({ projectId: projectId2 });
1484
1471
  })
1485
- ), origin = typeof location < "u" ? location.origin : "", observable = (isAllowedOrigin(origin) ? events : rxjs.concat(checkCors, events)).pipe(
1472
+ ), observable = rxjs.concat(checkCors, events).pipe(
1486
1473
  operators.finalize(() => eventsCache.delete(key)),
1487
1474
  shareReplayLatest({
1488
1475
  predicate: (event) => event.type === "welcome"