@sanity/client 6.22.3-canary.0 → 6.22.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.22.3-canary.0",
3
+ "version": "6.22.3",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -104,7 +104,7 @@
104
104
  "test:deno:update_import_map": "deno run --allow-read --allow-write runtimes/deno/update_import_map.ts",
105
105
  "test:edge-runtime": "npm test -- --config vitest.edge.config.ts",
106
106
  "test:next": "npm test -- --config ./vitest.next.config.ts",
107
- "test:node-runtimes": "node --test runtimes/node | npx faucet"
107
+ "test:node-runtimes": "(cd runtimes/node && node --test | npx faucet)"
108
108
  },
109
109
  "browserslist": "extends @sanity/browserslist-config",
110
110
  "prettier": {
@@ -124,13 +124,13 @@
124
124
  "devDependencies": {
125
125
  "@edge-runtime/types": "^3.0.2",
126
126
  "@edge-runtime/vm": "^4.0.3",
127
- "@rollup/plugin-commonjs": "^26.0.3",
127
+ "@rollup/plugin-commonjs": "^28.0.1",
128
128
  "@rollup/plugin-node-resolve": "^15.3.0",
129
129
  "@sanity/pkg-utils": "^6.11.8",
130
130
  "@types/json-diff": "^1.0.3",
131
131
  "@types/node": "^22.9.0",
132
- "@typescript-eslint/eslint-plugin": "^7.18.0",
133
- "@typescript-eslint/parser": "^7.18.0",
132
+ "@typescript-eslint/eslint-plugin": "^8.13.0",
133
+ "@typescript-eslint/parser": "^8.13.0",
134
134
  "@vercel/stega": "0.1.2",
135
135
  "@vitest/coverage-v8": "2.1.4",
136
136
  "eslint": "^8.57.1",
@@ -141,7 +141,8 @@
141
141
  "happy-dom": "^12.10.3",
142
142
  "json-diff": "^1.0.6",
143
143
  "ls-engines": "^0.9.3",
144
- "next": "^14.2.16",
144
+ "msw": "^2.6.0",
145
+ "next": "^15.0.2",
145
146
  "nock": "^13.5.5",
146
147
  "prettier": "^3.3.3",
147
148
  "prettier-plugin-packagejson": "^2.5.3",
@@ -153,6 +154,7 @@
153
154
  "vitest": "2.1.4",
154
155
  "vitest-github-actions-reporter": "0.11.1"
155
156
  },
157
+ "packageManager": "npm@10.5.2",
156
158
  "engines": {
157
159
  "node": ">=14.18"
158
160
  }
package/src/data/live.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {Observable} from 'rxjs'
2
2
 
3
+ import {CorsOriginError} from '../http/errors'
3
4
  import type {ObservableSanityClient, SanityClient} from '../SanityClient'
4
5
  import type {
5
6
  Any,
@@ -38,6 +39,7 @@ export class LiveClient {
38
39
  tag?: string
39
40
  } = {}): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome> {
40
41
  const {
42
+ projectId,
41
43
  apiVersion: _apiVersion,
42
44
  token,
43
45
  withCredentials,
@@ -143,6 +145,22 @@ export class LiveClient {
143
145
  return
144
146
  }
145
147
 
148
+ // 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
149
+ try {
150
+ await fetch(url, {
151
+ method: 'OPTIONS',
152
+ mode: 'cors',
153
+ credentials: esOptions.withCredentials ? 'include' : 'omit',
154
+ headers: esOptions.headers,
155
+ })
156
+ if (unsubscribed) {
157
+ return
158
+ }
159
+ } catch {
160
+ // If the request fails, then we assume it was due to CORS, and we rethrow a special error that allows special handling in userland
161
+ throw new CorsOriginError({projectId: projectId!})
162
+ }
163
+
146
164
  const evs = new EventSourceImplementation(url.toString(), esOptions)
147
165
  evs.addEventListener('error', onError)
148
166
  for (const type of listenFor) {
@@ -5,7 +5,7 @@ import type {Any, ClientConfig, HttpRequest} from './types'
5
5
 
6
6
  export * from './data/patch'
7
7
  export * from './data/transaction'
8
- export {ClientError, ServerError} from './http/errors'
8
+ export {ClientError, CorsOriginError, ServerError} from './http/errors'
9
9
  export * from './SanityClient'
10
10
  export * from './types'
11
11
 
@@ -106,3 +106,26 @@ function stringifyBody(body: Any, res: Any) {
106
106
  const isJson = contentType.indexOf('application/json') !== -1
107
107
  return isJson ? JSON.stringify(body, null, 2) : body
108
108
  }
109
+
110
+ /** @public */
111
+ export class CorsOriginError extends Error {
112
+ projectId: string
113
+ addOriginUrl?: URL
114
+
115
+ constructor({projectId}: {projectId: string}) {
116
+ super('CorsOriginError')
117
+ this.name = 'CorsOriginError'
118
+ this.projectId = projectId
119
+
120
+ const url = new URL(`https://sanity.io/manage/project/${projectId}/api`)
121
+ if (typeof location !== 'undefined') {
122
+ const {origin} = location
123
+ url.searchParams.set('cors', 'add')
124
+ url.searchParams.set('origin', origin)
125
+ this.addOriginUrl = url
126
+ this.message = `The current origin is not allowed to connect to the Live Content API. Add it here: ${url}`
127
+ } else {
128
+ this.message = `The current origin is not allowed to connect to the Live Content API. Change your configuration here: ${url}`
129
+ }
130
+ }
131
+ }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
1
2
  import type {ClientConfig, InitializedClientConfig, RawQueryResponse} from '@sanity/client'
2
3
  import type {
3
4
  ContentSourceMap,
package/src/types.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  // deno-lint-ignore-file no-empty-interface
2
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
2
3
 
3
4
  import type {Requester} from 'get-it'
4
5