@sanity/client
Advanced tools
Comparing version 6.22.1 to 6.22.2-canary.0
@@ -932,3 +932,3 @@ import { getIt } from "get-it"; | ||
} = {}) { | ||
const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
const { apiVersion: _apiVersion, token, withCredentials } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
if (apiVersion !== "X" && apiVersion < requiredApiVersion) | ||
@@ -938,5 +938,5 @@ throw new Error( | ||
); | ||
if (includeDrafts && !token) | ||
if (includeDrafts && !token && !withCredentials) | ||
throw new Error( | ||
"The live events API requires a token when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role." | ||
"The live events API requires a token or withCredentials when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role." | ||
); | ||
@@ -949,6 +949,6 @@ if (includeDrafts && apiVersion !== "X") | ||
includeDrafts && url.searchParams.set("includeDrafts", "true"); | ||
const listenFor = ["restart", "message"], esOptions = {}; | ||
const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {}; | ||
return includeDrafts && token && (esOptions.headers = { | ||
Authorization: `Bearer ${token}` | ||
}), new Observable((observer) => { | ||
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new Observable((observer) => { | ||
let es, reconnectTimer, stopped = !1, unsubscribed = !1; | ||
@@ -978,3 +978,3 @@ open(); | ||
async function getEventSource() { | ||
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource; | ||
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource; | ||
if (unsubscribed) | ||
@@ -981,0 +981,0 @@ return; |
@@ -932,3 +932,3 @@ import { getIt } from "get-it"; | ||
} = {}) { | ||
const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
const { apiVersion: _apiVersion, token, withCredentials } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
if (apiVersion !== "X" && apiVersion < requiredApiVersion) | ||
@@ -938,5 +938,5 @@ throw new Error( | ||
); | ||
if (includeDrafts && !token) | ||
if (includeDrafts && !token && !withCredentials) | ||
throw new Error( | ||
"The live events API requires a token when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role." | ||
"The live events API requires a token or withCredentials when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role." | ||
); | ||
@@ -949,6 +949,6 @@ if (includeDrafts && apiVersion !== "X") | ||
includeDrafts && url.searchParams.set("includeDrafts", "true"); | ||
const listenFor = ["restart", "message"], esOptions = {}; | ||
const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {}; | ||
return includeDrafts && token && (esOptions.headers = { | ||
Authorization: `Bearer ${token}` | ||
}), new Observable((observer) => { | ||
}), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new Observable((observer) => { | ||
let es, reconnectTimer, stopped = !1, unsubscribed = !1; | ||
@@ -978,3 +978,3 @@ open(); | ||
async function getEventSource() { | ||
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource; | ||
const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource; | ||
if (unsubscribed) | ||
@@ -1526,3 +1526,3 @@ return; | ||
} | ||
var name = "@sanity/client", version = "6.22.1"; | ||
var name = "@sanity/client", version = "6.22.2-canary.0"; | ||
const middleware = [ | ||
@@ -1529,0 +1529,0 @@ debug({ verbose: !0, namespace: "sanity:client" }), |
{ | ||
"name": "@sanity/client", | ||
"version": "6.22.1", | ||
"version": "6.22.2-canary.0", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
import {Observable} from 'rxjs' | ||
import type {ObservableSanityClient, SanityClient} from '../SanityClient' | ||
import type {Any, LiveEventMessage, LiveEventRestart} from '../types' | ||
import type { | ||
Any, | ||
LiveEventMessage, | ||
LiveEventReconnect, | ||
LiveEventRestart, | ||
LiveEventWelcome, | ||
} from '../types' | ||
import {_getDataUrl} from './dataMethods' | ||
@@ -26,4 +32,4 @@ | ||
includeDrafts?: boolean | ||
} = {}): Observable<LiveEventMessage | LiveEventRestart> { | ||
const {apiVersion: _apiVersion, token} = this.#client.config() | ||
} = {}): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome> { | ||
const {apiVersion: _apiVersion, token, withCredentials} = this.#client.config() | ||
const apiVersion = _apiVersion.replace(/^v/, '') | ||
@@ -37,5 +43,5 @@ if (apiVersion !== 'X' && apiVersion < requiredApiVersion) { | ||
} | ||
if (includeDrafts && !token) { | ||
if (includeDrafts && !token && !withCredentials) { | ||
throw new Error( | ||
`The live events API requires a token when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role.`, | ||
`The live events API requires a token or withCredentials when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role.`, | ||
) | ||
@@ -54,3 +60,3 @@ } | ||
const listenFor = ['restart', 'message'] as const | ||
const listenFor = ['restart', 'message', 'welcome', 'reconnect'] as const | ||
const esOptions: EventSourceInit & {headers?: Record<string, string>} = {} | ||
@@ -62,2 +68,5 @@ if (includeDrafts && token) { | ||
} | ||
if (includeDrafts && withCredentials) { | ||
esOptions.withCredentials = true | ||
} | ||
@@ -115,3 +124,3 @@ return new Observable((observer) => { | ||
const EventSourceImplementation: typeof EventSource = | ||
typeof EventSource === 'undefined' || esOptions.headers | ||
typeof EventSource === 'undefined' || esOptions.headers || esOptions.withCredentials | ||
? ((await import('@sanity/eventsource')).default as unknown as typeof EventSource) | ||
@@ -118,0 +127,0 @@ : EventSource |
@@ -1247,4 +1247,9 @@ // deno-lint-ignore-file no-empty-interface | ||
type: 'restart' | ||
id: string | ||
} | ||
/** @public */ | ||
export interface LiveEventReconnect { | ||
type: 'reconnect' | ||
} | ||
/** @public */ | ||
export interface LiveEventMessage { | ||
@@ -1255,2 +1260,6 @@ type: 'message' | ||
} | ||
/** @public */ | ||
export interface LiveEventWelcome { | ||
type: 'welcome' | ||
} | ||
@@ -1257,0 +1266,0 @@ /** @public */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2175263
24774
1