@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.
@@ -1871,7 +1871,7 @@ export declare type IdentifiedSanityDocumentStub<
1871
1871
  * @see #TransformOperation
1872
1872
  * @beta
1873
1873
  */
1874
- export declare interface ImageDescriptionOperation {
1874
+ export declare type ImageDescriptionOperation = {
1875
1875
  type: 'image-description'
1876
1876
  /**
1877
1877
  * When omitted, parent image value will be inferred from the arget path.
@@ -1882,7 +1882,32 @@ export declare interface ImageDescriptionOperation {
1882
1882
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1883
1883
  */
1884
1884
  sourcePath?: AgentActionPath
1885
- }
1885
+ } & (
1886
+ | {
1887
+ /**
1888
+ * When omitted, parent image value will be inferred from the target path.
1889
+ *
1890
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1891
+ * - `['image']`
1892
+ * - `['wrapper', 'mainImage']`
1893
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1894
+ *
1895
+ * Incompatible with `imageUrl`
1896
+ *
1897
+ */
1898
+ sourcePath?: AgentActionPath
1899
+ imageUrl?: never
1900
+ }
1901
+ | {
1902
+ /**
1903
+ * When specified, the image source to be described will be fetched from the URL.
1904
+ *
1905
+ * Incompatible with `sourcePath`
1906
+ */
1907
+ imageUrl?: `https://${string}`
1908
+ sourcePath?: never
1909
+ }
1910
+ )
1886
1911
 
1887
1912
  /** @public */
1888
1913
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5811,6 +5836,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5811
5836
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5812
5837
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5813
5838
  *
5839
+ * ### Targeting images outside the document (URL)
5840
+ * 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`.
5841
+ *
5842
+ * Example:
5843
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5814
5844
  * @beta
5815
5845
  */
5816
5846
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
@@ -1871,7 +1871,7 @@ export declare type IdentifiedSanityDocumentStub<
1871
1871
  * @see #TransformOperation
1872
1872
  * @beta
1873
1873
  */
1874
- export declare interface ImageDescriptionOperation {
1874
+ export declare type ImageDescriptionOperation = {
1875
1875
  type: 'image-description'
1876
1876
  /**
1877
1877
  * When omitted, parent image value will be inferred from the arget path.
@@ -1882,7 +1882,32 @@ export declare interface ImageDescriptionOperation {
1882
1882
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1883
1883
  */
1884
1884
  sourcePath?: AgentActionPath
1885
- }
1885
+ } & (
1886
+ | {
1887
+ /**
1888
+ * When omitted, parent image value will be inferred from the target path.
1889
+ *
1890
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1891
+ * - `['image']`
1892
+ * - `['wrapper', 'mainImage']`
1893
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1894
+ *
1895
+ * Incompatible with `imageUrl`
1896
+ *
1897
+ */
1898
+ sourcePath?: AgentActionPath
1899
+ imageUrl?: never
1900
+ }
1901
+ | {
1902
+ /**
1903
+ * When specified, the image source to be described will be fetched from the URL.
1904
+ *
1905
+ * Incompatible with `sourcePath`
1906
+ */
1907
+ imageUrl?: `https://${string}`
1908
+ sourcePath?: never
1909
+ }
1910
+ )
1886
1911
 
1887
1912
  /** @public */
1888
1913
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5811,6 +5836,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5811
5836
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5812
5837
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5813
5838
  *
5839
+ * ### Targeting images outside the document (URL)
5840
+ * 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`.
5841
+ *
5842
+ * Example:
5843
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5814
5844
  * @beta
5815
5845
  */
5816
5846
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
package/dist/stega.d.cts CHANGED
@@ -1871,7 +1871,7 @@ export declare type IdentifiedSanityDocumentStub<
1871
1871
  * @see #TransformOperation
1872
1872
  * @beta
1873
1873
  */
1874
- export declare interface ImageDescriptionOperation {
1874
+ export declare type ImageDescriptionOperation = {
1875
1875
  type: 'image-description'
1876
1876
  /**
1877
1877
  * When omitted, parent image value will be inferred from the arget path.
@@ -1882,7 +1882,32 @@ export declare interface ImageDescriptionOperation {
1882
1882
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1883
1883
  */
1884
1884
  sourcePath?: AgentActionPath
1885
- }
1885
+ } & (
1886
+ | {
1887
+ /**
1888
+ * When omitted, parent image value will be inferred from the target path.
1889
+ *
1890
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1891
+ * - `['image']`
1892
+ * - `['wrapper', 'mainImage']`
1893
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1894
+ *
1895
+ * Incompatible with `imageUrl`
1896
+ *
1897
+ */
1898
+ sourcePath?: AgentActionPath
1899
+ imageUrl?: never
1900
+ }
1901
+ | {
1902
+ /**
1903
+ * When specified, the image source to be described will be fetched from the URL.
1904
+ *
1905
+ * Incompatible with `sourcePath`
1906
+ */
1907
+ imageUrl?: `https://${string}`
1908
+ sourcePath?: never
1909
+ }
1910
+ )
1886
1911
 
1887
1912
  /** @public */
1888
1913
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5811,6 +5836,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5811
5836
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5812
5837
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5813
5838
  *
5839
+ * ### Targeting images outside the document (URL)
5840
+ * 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`.
5841
+ *
5842
+ * Example:
5843
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5814
5844
  * @beta
5815
5845
  */
5816
5846
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
package/dist/stega.d.ts CHANGED
@@ -1871,7 +1871,7 @@ export declare type IdentifiedSanityDocumentStub<
1871
1871
  * @see #TransformOperation
1872
1872
  * @beta
1873
1873
  */
1874
- export declare interface ImageDescriptionOperation {
1874
+ export declare type ImageDescriptionOperation = {
1875
1875
  type: 'image-description'
1876
1876
  /**
1877
1877
  * When omitted, parent image value will be inferred from the arget path.
@@ -1882,7 +1882,32 @@ export declare interface ImageDescriptionOperation {
1882
1882
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1883
1883
  */
1884
1884
  sourcePath?: AgentActionPath
1885
- }
1885
+ } & (
1886
+ | {
1887
+ /**
1888
+ * When omitted, parent image value will be inferred from the target path.
1889
+ *
1890
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1891
+ * - `['image']`
1892
+ * - `['wrapper', 'mainImage']`
1893
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1894
+ *
1895
+ * Incompatible with `imageUrl`
1896
+ *
1897
+ */
1898
+ sourcePath?: AgentActionPath
1899
+ imageUrl?: never
1900
+ }
1901
+ | {
1902
+ /**
1903
+ * When specified, the image source to be described will be fetched from the URL.
1904
+ *
1905
+ * Incompatible with `sourcePath`
1906
+ */
1907
+ imageUrl?: `https://${string}`
1908
+ sourcePath?: never
1909
+ }
1910
+ )
1886
1911
 
1887
1912
  /** @public */
1888
1913
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -5811,6 +5836,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5811
5836
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5812
5837
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5813
5838
  *
5839
+ * ### Targeting images outside the document (URL)
5840
+ * 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`.
5841
+ *
5842
+ * Example:
5843
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5814
5844
  * @beta
5815
5845
  */
5816
5846
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.5.0-live-cors.3",
3
+ "version": "7.6.0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -180,7 +180,7 @@ export type TransformTargetDocument =
180
180
  * @see #TransformOperation
181
181
  * @beta
182
182
  */
183
- export interface ImageDescriptionOperation {
183
+ export type ImageDescriptionOperation = {
184
184
  type: 'image-description'
185
185
  /**
186
186
  * When omitted, parent image value will be inferred from the arget path.
@@ -191,7 +191,32 @@ export interface ImageDescriptionOperation {
191
191
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
192
192
  */
193
193
  sourcePath?: AgentActionPath
194
- }
194
+ } & (
195
+ | {
196
+ /**
197
+ * When omitted, parent image value will be inferred from the target path.
198
+ *
199
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
200
+ * - `['image']`
201
+ * - `['wrapper', 'mainImage']`
202
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
203
+ *
204
+ * Incompatible with `imageUrl`
205
+ *
206
+ */
207
+ sourcePath?: AgentActionPath
208
+ imageUrl?: never
209
+ }
210
+ | {
211
+ /**
212
+ * When specified, the image source to be described will be fetched from the URL.
213
+ *
214
+ * Incompatible with `sourcePath`
215
+ */
216
+ imageUrl?: `https://${string}`
217
+ sourcePath?: never
218
+ }
219
+ )
195
220
 
196
221
  /**
197
222
  *
@@ -222,6 +247,11 @@ export interface ImageDescriptionOperation {
222
247
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
223
248
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
224
249
  *
250
+ * ### Targeting images outside the document (URL)
251
+ * 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`.
252
+ *
253
+ * Example:
254
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
225
255
  * @beta
226
256
  */
227
257
  export type TransformOperation = 'set' | ImageDescriptionOperation
package/src/data/live.ts CHANGED
@@ -125,40 +125,20 @@ export class LiveClient {
125
125
  }),
126
126
  )
127
127
 
128
- console.log("YES THIS IS THE CORS VERSION with the allowed origin check")
129
- // Check if origin matches Kong's allowed patterns
130
- const isAllowedOrigin = (origin: string): boolean => {
131
- const patterns = [
132
- /^http:\/\/localhost:/,
133
- /^http:\/\/127\.0\.0\.1:/,
134
- /^https:\/\/[^.]*\.sanity\.studio$/,
135
- /^https:\/\/[^.]*\.studio\.sanity\.work$/,
136
- /^https:\/\/[^.]*\.sanity\.work$/,
137
- /^https:\/\/[^.]*\.sanity\.io$/
138
- ]
139
- return patterns.some(pattern => pattern.test(origin))
140
- }
141
-
142
128
  // Detect if CORS is allowed, the way the CORS is checked supports preflight caching, so when the EventSource boots up it knows it sees the preflight was already made and we're good to go
143
129
  const checkCors = fetchObservable(url, {
144
130
  method: 'OPTIONS',
145
131
  mode: 'cors',
146
132
  credentials: esOptions.withCredentials ? 'include' : 'omit',
147
- headers: {
148
- ...esOptions.headers,
149
- 'Access-Control-Request-Headers': 'authorization',
150
- // for this preflight check, ensure we send what the browser would send if needed
151
- },
133
+ headers: esOptions.headers,
152
134
  }).pipe(
153
135
  mergeMap(() => EMPTY),
154
136
  catchError(() => {
137
+ // If the request fails, then we assume it was due to CORS, and we rethrow a special error that allows special handling in userland
155
138
  throw new CorsOriginError({projectId: projectId!})
156
139
  }),
157
140
  )
158
-
159
- // Only run CORS check if origin is not in allowed patterns
160
- const origin = typeof location !== 'undefined' ? location.origin : ''
161
- const observable = (isAllowedOrigin(origin) ? events : concat(checkCors, events)).pipe(
141
+ const observable = concat(checkCors, events).pipe(
162
142
  finalize(() => eventsCache.delete(key)),
163
143
  shareReplayLatest({
164
144
  predicate: (event) => event.type === 'welcome',
@@ -3417,30 +3417,17 @@ ${selectionOpts}`);
3417
3417
  }
3418
3418
  return event;
3419
3419
  })
3420
- );
3421
- console.log("YES THIS IS THE CORS VERSION with the allowed origin check");
3422
- const isAllowedOrigin = (origin2) => [
3423
- /^http:\/\/localhost:/,
3424
- /^http:\/\/127\.0\.0\.1:/,
3425
- /^https:\/\/[^.]*\.sanity\.studio$/,
3426
- /^https:\/\/[^.]*\.studio\.sanity\.work$/,
3427
- /^https:\/\/[^.]*\.sanity\.work$/,
3428
- /^https:\/\/[^.]*\.sanity\.io$/
3429
- ].some((pattern) => pattern.test(origin2)), checkCors = fetchObservable(url, {
3420
+ ), checkCors = fetchObservable(url, {
3430
3421
  method: "OPTIONS",
3431
3422
  mode: "cors",
3432
3423
  credentials: esOptions.withCredentials ? "include" : "omit",
3433
- headers: {
3434
- ...esOptions.headers,
3435
- "Access-Control-Request-Headers": "authorization"
3436
- // for this preflight check, ensure we send what the browser would send if needed
3437
- }
3424
+ headers: esOptions.headers
3438
3425
  }).pipe(
3439
3426
  mergeMap(() => EMPTY),
3440
3427
  catchError(() => {
3441
3428
  throw new CorsOriginError({ projectId: projectId2 });
3442
3429
  })
3443
- ), origin = typeof location < "u" ? location.origin : "", observable2 = (isAllowedOrigin(origin) ? events : concat(checkCors, events)).pipe(
3430
+ ), observable2 = concat(checkCors, events).pipe(
3444
3431
  finalize(() => eventsCache.delete(key)),
3445
3432
  shareReplayLatest({
3446
3433
  predicate: (event) => event.type === "welcome"