@sanity/client
Advanced tools
Comparing version 6.22.1 to 6.22.2-bundle-perspective
@@ -522,2 +522,7 @@ import { getIt } from "get-it"; | ||
} | ||
}, validateApiBundlePerspective = function(perspective, bundlePerspective) { | ||
if (perspective !== "raw" && bundlePerspective) | ||
throw new TypeError( | ||
"Invalid, perspective and bundlePerspective parameters are mutually exclusive" | ||
); | ||
}, initConfig = (config, prevConfig) => { | ||
@@ -701,2 +706,3 @@ const specifiedConfig = { | ||
perspective: options.perspective, | ||
bundlePerspective: options.bundlePerspective, | ||
resultSourceMap: options.resultSourceMap, | ||
@@ -740,3 +746,5 @@ lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId, | ||
const perspective = options.perspective || config.perspective; | ||
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }); | ||
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())); | ||
const bundlePerspective = options.bundlePerspective || config.bundlePerspective; | ||
Array.isArray(bundlePerspective) && bundlePerspective.length > 0 && (validateApiBundlePerspective(perspective, bundlePerspective), options.query = { perspective: void 0, bundlePerspective, ...options.query }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }); | ||
} | ||
@@ -933,5 +941,11 @@ const reqOptions = requestOptions( | ||
events({ | ||
includeDrafts = !1 | ||
includeDrafts = !1, | ||
tag: _tag | ||
} = {}) { | ||
const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
const { | ||
apiVersion: _apiVersion, | ||
token, | ||
withCredentials, | ||
requestTagPrefix | ||
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
if (apiVersion !== "X" && apiVersion < requiredApiVersion) | ||
@@ -941,5 +955,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." | ||
); | ||
@@ -950,8 +964,8 @@ if (includeDrafts && apiVersion !== "X") | ||
); | ||
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)); | ||
includeDrafts && url.searchParams.set("includeDrafts", "true"); | ||
const listenFor = ["restart", "message"], esOptions = {}; | ||
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag; | ||
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true"); | ||
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; | ||
@@ -981,3 +995,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) | ||
@@ -984,0 +998,0 @@ return; |
@@ -522,2 +522,7 @@ import { getIt } from "get-it"; | ||
} | ||
}, validateApiBundlePerspective = function(perspective, bundlePerspective) { | ||
if (perspective !== "raw" && bundlePerspective) | ||
throw new TypeError( | ||
"Invalid, perspective and bundlePerspective parameters are mutually exclusive" | ||
); | ||
}, initConfig = (config, prevConfig) => { | ||
@@ -701,2 +706,3 @@ const specifiedConfig = { | ||
perspective: options.perspective, | ||
bundlePerspective: options.bundlePerspective, | ||
resultSourceMap: options.resultSourceMap, | ||
@@ -740,3 +746,5 @@ lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId, | ||
const perspective = options.perspective || config.perspective; | ||
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }); | ||
typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())); | ||
const bundlePerspective = options.bundlePerspective || config.bundlePerspective; | ||
Array.isArray(bundlePerspective) && bundlePerspective.length > 0 && (validateApiBundlePerspective(perspective, bundlePerspective), options.query = { perspective: void 0, bundlePerspective, ...options.query }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }); | ||
} | ||
@@ -933,5 +941,11 @@ const reqOptions = requestOptions( | ||
events({ | ||
includeDrafts = !1 | ||
includeDrafts = !1, | ||
tag: _tag | ||
} = {}) { | ||
const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
const { | ||
apiVersion: _apiVersion, | ||
token, | ||
withCredentials, | ||
requestTagPrefix | ||
} = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, ""); | ||
if (apiVersion !== "X" && apiVersion < requiredApiVersion) | ||
@@ -941,5 +955,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." | ||
); | ||
@@ -950,8 +964,8 @@ if (includeDrafts && apiVersion !== "X") | ||
); | ||
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)); | ||
includeDrafts && url.searchParams.set("includeDrafts", "true"); | ||
const listenFor = ["restart", "message"], esOptions = {}; | ||
const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag; | ||
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true"); | ||
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; | ||
@@ -981,3 +995,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) | ||
@@ -1529,3 +1543,3 @@ return; | ||
} | ||
var name = "@sanity/client", version = "6.22.1"; | ||
var name = "@sanity/client", version = "6.22.2-bundle-perspective"; | ||
const middleware = [ | ||
@@ -1532,0 +1546,0 @@ debug({ verbose: !0, namespace: "sanity:client" }), |
{ | ||
"name": "@sanity/client", | ||
"version": "6.22.1", | ||
"version": "6.22.2-bundle-perspective", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -44,2 +44,12 @@ import {generateHelpUrl} from './generateHelpUrl' | ||
export const validateApiBundlePerspective = function validateApiBundlePerspective( | ||
perspective?: string, | ||
bundlePerspective?: string[], | ||
) { | ||
if (perspective !== 'raw' && bundlePerspective) { | ||
throw new TypeError( | ||
'Invalid, perspective and bundlePerspective parameters are mutually exclusive', | ||
) | ||
} | ||
} | ||
export const initConfig = ( | ||
@@ -46,0 +56,0 @@ config: Partial<ClientConfig>, |
import {from, type MonoTypeOperatorFunction, Observable} from 'rxjs' | ||
import {combineLatestWith, filter, map} from 'rxjs/operators' | ||
import {validateApiPerspective} from '../config' | ||
import {validateApiBundlePerspective, validateApiPerspective} from '../config' | ||
import {requestOptions} from '../http/requestOptions' | ||
@@ -315,2 +315,3 @@ import type {ObservableSanityClient, SanityClient} from '../SanityClient' | ||
perspective: options.perspective, | ||
bundlePerspective: options.bundlePerspective, | ||
resultSourceMap: options.resultSourceMap, | ||
@@ -419,2 +420,8 @@ lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId, | ||
const bundlePerspective = options.bundlePerspective || config.bundlePerspective | ||
if (Array.isArray(bundlePerspective) && bundlePerspective.length > 0) { | ||
validateApiBundlePerspective(perspective, bundlePerspective) | ||
options.query = {perspective: undefined, bundlePerspective, ...options.query} | ||
} | ||
if (options.lastLiveEventId) { | ||
@@ -421,0 +428,0 @@ options.query = {...options.query, lastLiveEventId: options.lastLiveEventId} |
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' | ||
@@ -23,7 +29,19 @@ | ||
includeDrafts = false, | ||
tag: _tag, | ||
}: { | ||
/** @alpha this API is experimental and may change or even be removed */ | ||
includeDrafts?: boolean | ||
} = {}): Observable<LiveEventMessage | LiveEventRestart> { | ||
const {apiVersion: _apiVersion, token} = this.#client.config() | ||
/** | ||
* Optional request tag for the listener. Use to identify the request in logs. | ||
* | ||
* @defaultValue `undefined` | ||
*/ | ||
tag?: string | ||
} = {}): Observable<LiveEventMessage | LiveEventRestart | LiveEventReconnect | LiveEventWelcome> { | ||
const { | ||
apiVersion: _apiVersion, | ||
token, | ||
withCredentials, | ||
requestTagPrefix, | ||
} = this.#client.config() | ||
const apiVersion = _apiVersion.replace(/^v/, '') | ||
@@ -37,5 +55,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.`, | ||
) | ||
@@ -50,2 +68,6 @@ } | ||
const url = new URL(this.#client.getUrl(path, false)) | ||
const tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join('.') : _tag | ||
if (tag) { | ||
url.searchParams.set('tag', tag) | ||
} | ||
if (includeDrafts) { | ||
@@ -55,3 +77,3 @@ url.searchParams.set('includeDrafts', 'true') | ||
const listenFor = ['restart', 'message'] as const | ||
const listenFor = ['restart', 'message', 'welcome', 'reconnect'] as const | ||
const esOptions: EventSourceInit & {headers?: Record<string, string>} = {} | ||
@@ -63,2 +85,5 @@ if (includeDrafts && token) { | ||
} | ||
if (includeDrafts && withCredentials) { | ||
esOptions.withCredentials = true | ||
} | ||
@@ -116,3 +141,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) | ||
@@ -119,0 +144,0 @@ : EventSource |
@@ -45,2 +45,4 @@ // deno-lint-ignore-file no-empty-interface | ||
perspective?: ClientPerspective | ||
/** @defaultValue 'raw' */ | ||
bundlePerspective?: string[] | ||
apiHost?: string | ||
@@ -310,2 +312,3 @@ apiVersion?: string | ||
perspective?: ClientPerspective | ||
bundlePerspective?: string[] | ||
lastLiveEventId?: string | ||
@@ -476,2 +479,4 @@ } | ||
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */ | ||
bundlePerspective?: never | ||
/** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */ | ||
query?: never | ||
@@ -943,2 +948,3 @@ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */ | ||
perspective?: ClientPerspective | ||
bundlePerspective?: string[] | ||
resultSourceMap?: boolean | 'withKeyArraySelector' | ||
@@ -1251,4 +1257,9 @@ returnQuery?: boolean | ||
type: 'restart' | ||
id: string | ||
} | ||
/** @public */ | ||
export interface LiveEventReconnect { | ||
type: 'reconnect' | ||
} | ||
/** @public */ | ||
export interface LiveEventMessage { | ||
@@ -1259,2 +1270,6 @@ type: 'message' | ||
} | ||
/** @public */ | ||
export interface LiveEventWelcome { | ||
type: 'welcome' | ||
} | ||
@@ -1261,0 +1276,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
2188680
24910
1
6