@sanity/client
Advanced tools
Comparing version 6.27.2-canary.0 to 6.27.2-resources.0
@@ -121,3 +121,5 @@ const BASE_URL = "https://www.sanity.io/help/"; | ||
...specifiedConfig | ||
}, projectBased = newConfig.useProjectHostname; | ||
}, experimentalResource = newConfig.experimental_resource; | ||
experimentalResource && (newConfig.useProjectHostname = !1); | ||
const projectBased = newConfig.useProjectHostname; | ||
if (typeof Promise > "u") { | ||
@@ -148,3 +150,7 @@ const helpUrl = generateHelpUrl("js-client-promise-polyfill"); | ||
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host; | ||
return newConfig.useProjectHostname ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), newConfig; | ||
if (newConfig.useProjectHostname ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), experimentalResource) { | ||
const resourceSuffix = `${experimentalResource.type}/${experimentalResource.id}`; | ||
newConfig.url = `${newConfig.url}/${resourceSuffix}`, newConfig.cdnUrl = `${newConfig.cdnUrl}/${resourceSuffix}`; | ||
} | ||
return newConfig; | ||
}; | ||
@@ -151,0 +157,0 @@ export { |
@@ -723,7 +723,16 @@ import { getIt } from "get-it"; | ||
} | ||
function _resourceBase(resource) { | ||
return `/${resource.type}/${resource.id}`; | ||
} | ||
function isDataRequestUri(uri, resource) { | ||
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0 : uri.indexOf("/data/") === 0; | ||
} | ||
function isDataQueryRequestUri(uri, resource) { | ||
return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0 : uri.indexOf("/data/query") === 0; | ||
} | ||
function _requestObservable(client, httpRequest, options) { | ||
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn; | ||
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isDataRequestUri(uri, config.experimental_resource) : options.canUseCdn; | ||
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn; | ||
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix; | ||
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) { | ||
if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isDataQueryRequestUri(uri, config.experimental_resource)) { | ||
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap; | ||
@@ -754,8 +763,14 @@ resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query }); | ||
function _getDataUrl(client, operation, path) { | ||
const config = client.config(), catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`; | ||
const config = client.config(); | ||
if (config.experimental_resource) { | ||
const baseUri2 = `/${operation}`; | ||
return (path ? `${baseUri2}/${path}` : baseUri2).replace(/\/($|\?)/, "$1"); | ||
} | ||
const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`; | ||
return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1"); | ||
} | ||
function _getUrl(client, uri, canUseCdn = !1) { | ||
const { url, cdnUrl } = client.config(); | ||
return `${canUseCdn ? cdnUrl : url}/${uri.replace(/^\//, "")}`; | ||
const { url, cdnUrl, experimental_resource } = client.config(); | ||
let base = canUseCdn ? cdnUrl : url; | ||
return experimental_resource && uri.indexOf("/users") !== -1 && (base = base.replace(_resourceBase(experimental_resource), "")), `${base}/${uri.replace(/^\//, "")}`; | ||
} | ||
@@ -814,3 +829,3 @@ function _withAbortSignal(signal) { | ||
meta && !meta.length && (meta = ["none"]); | ||
const dataset2 = hasDataset(client.config()), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = { | ||
const config = client.config(), dataset2 = config.experimental_resource ? void 0 : hasDataset(config), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = { | ||
label, | ||
@@ -827,3 +842,3 @@ title, | ||
timeout: options.timeout || 0, | ||
uri: `/assets/${assetEndpoint}/${dataset2}`, | ||
uri: dataset2 ? `/assets/${assetEndpoint}/${dataset2}` : `/assets/${assetEndpoint}`, | ||
headers: options.contentType ? { "Content-Type": options.contentType } : {}, | ||
@@ -1051,2 +1066,19 @@ query, | ||
} | ||
class ThrowingDatasetsClient extends DatasetsClient { | ||
constructor(client, httpRequest) { | ||
super(client, httpRequest); | ||
} | ||
create() { | ||
throw new Error("cannot create dataset with the current client configuration"); | ||
} | ||
edit() { | ||
throw new Error("cannot edit dataset with the current client configuration"); | ||
} | ||
delete() { | ||
throw new Error("cannot delete dataset with the current client configuration"); | ||
} | ||
list() { | ||
throw new Error("cannot list dataset with the current client configuration"); | ||
} | ||
} | ||
function _modify(client, httpRequest, method, name2, options) { | ||
@@ -1307,3 +1339,3 @@ return dataset(name2), _request(client, httpRequest, { | ||
constructor(httpRequest, config = defaultConfig) { | ||
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config); | ||
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = this.#clientConfig.experimental_resource ? new ThrowingDatasetsClient(this, this.#httpRequest) : new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config); | ||
} | ||
@@ -1484,3 +1516,3 @@ /** | ||
} | ||
var name = "@sanity/client", version = "6.27.2-canary.0"; | ||
var name = "@sanity/client", version = "6.27.2-resources.0"; | ||
const middleware = [ | ||
@@ -1487,0 +1519,0 @@ debug({ verbose: !0, namespace: "sanity:client" }), |
{ | ||
"name": "@sanity/client", | ||
"version": "6.27.2-canary.0", | ||
"version": "6.27.2-resources.0", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -122,3 +122,3 @@ "keywords": [ | ||
"@sanity/eventsource": "^5.0.2", | ||
"get-it": "^8.6.6", | ||
"get-it": "^8.6.7", | ||
"rxjs": "^7.0.0" | ||
@@ -125,0 +125,0 @@ }, |
@@ -152,3 +152,4 @@ import {lastValueFrom, type Observable} from 'rxjs' | ||
const dataset = validators.hasDataset(client.config()) | ||
const config = client.config() | ||
const dataset = config.experimental_resource ? undefined : validators.hasDataset(config) | ||
const assetEndpoint = assetType === 'image' ? 'images' : 'files' | ||
@@ -174,3 +175,3 @@ const options = optionsFromFile(opts, body) | ||
timeout: options.timeout || 0, | ||
uri: `/assets/${assetEndpoint}/${dataset}`, | ||
uri: dataset ? `/assets/${assetEndpoint}/${dataset}` : `/assets/${assetEndpoint}`, | ||
headers: options.contentType ? {'Content-Type': options.contentType} : {}, | ||
@@ -177,0 +178,0 @@ query, |
@@ -93,2 +93,9 @@ import {generateHelpUrl} from './generateHelpUrl' | ||
} as InitializedClientConfig | ||
// resource oriented clients should not use project hostname in base url | ||
const experimentalResource = newConfig.experimental_resource | ||
if (experimentalResource) { | ||
newConfig.useProjectHostname = false | ||
} | ||
const projectBased = newConfig.useProjectHostname | ||
@@ -184,3 +191,9 @@ | ||
if (experimentalResource) { | ||
const resourceSuffix = `${experimentalResource.type}/${experimentalResource.id}` | ||
newConfig.url = `${newConfig.url}/${resourceSuffix}` | ||
newConfig.cdnUrl = `${newConfig.cdnUrl}/${resourceSuffix}` | ||
} | ||
return newConfig | ||
} |
@@ -15,2 +15,3 @@ import {from, type MonoTypeOperatorFunction, Observable} from 'rxjs' | ||
BaseMutationOptions, | ||
ClientConfig, | ||
FirstDocumentIdMutationOptions, | ||
@@ -42,2 +43,4 @@ FirstDocumentMutationOptions, | ||
type ExperimentalResourceConfig = Exclude<ClientConfig['experimental_resource'], undefined> | ||
const excludeFalsey = (param: Any, defValue: Any) => { | ||
@@ -372,2 +375,20 @@ const value = typeof param === 'undefined' ? defValue : param | ||
function _resourceBase(resource: ExperimentalResourceConfig) { | ||
return `/${resource.type}/${resource.id}` | ||
} | ||
function isDataRequestUri(uri: string, resource?: ExperimentalResourceConfig) { | ||
if (resource) { | ||
return uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0 | ||
} | ||
return uri.indexOf('/data/') === 0 | ||
} | ||
function isDataQueryRequestUri(uri: string, resource?: ExperimentalResourceConfig) { | ||
if (resource) { | ||
return uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0 | ||
} | ||
return uri.indexOf('/data/query') === 0 | ||
} | ||
/** | ||
@@ -388,3 +409,4 @@ * @internal | ||
typeof options.canUseCdn === 'undefined' | ||
? ['GET', 'HEAD'].indexOf(options.method || 'GET') >= 0 && uri.indexOf('/data/') === 0 | ||
? ['GET', 'HEAD'].indexOf(options.method || 'GET') >= 0 && | ||
isDataRequestUri(uri, config.experimental_resource) | ||
: options.canUseCdn | ||
@@ -406,3 +428,3 @@ | ||
['GET', 'HEAD', 'POST'].indexOf(options.method || 'GET') >= 0 && | ||
uri.indexOf('/data/query/') === 0 | ||
isDataQueryRequestUri(uri, config.experimental_resource) | ||
) { | ||
@@ -481,2 +503,8 @@ const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap | ||
const config = client.config() | ||
if (config.experimental_resource) { | ||
const baseUri = `/${operation}` | ||
const uri = path ? `${baseUri}/${path}` : baseUri | ||
return uri.replace(/\/($|\?)/, '$1') | ||
} | ||
const catalog = validators.hasDataset(config) | ||
@@ -496,4 +524,11 @@ const baseUri = `/${operation}/${catalog}` | ||
): string { | ||
const {url, cdnUrl} = client.config() | ||
const base = canUseCdn ? cdnUrl : url | ||
const {url, cdnUrl, experimental_resource} = client.config() | ||
let base = canUseCdn ? cdnUrl : url | ||
if (experimental_resource) { | ||
if (uri.indexOf('/users') !== -1) { | ||
base = base.replace(_resourceBase(experimental_resource), '') | ||
} | ||
} | ||
return `${base}/${uri.replace(/^\//, '')}` | ||
@@ -500,0 +535,0 @@ } |
@@ -109,2 +109,24 @@ import {lastValueFrom, type Observable} from 'rxjs' | ||
export class ThrowingDatasetsClient extends DatasetsClient { | ||
constructor(client: SanityClient, httpRequest: HttpRequest) { | ||
super(client, httpRequest) | ||
} | ||
create(): Promise<DatasetResponse> { | ||
throw new Error('cannot create dataset with the current client configuration') | ||
} | ||
edit(): Promise<DatasetResponse> { | ||
throw new Error('cannot edit dataset with the current client configuration') | ||
} | ||
delete(): Promise<{deleted: true}> { | ||
throw new Error('cannot delete dataset with the current client configuration') | ||
} | ||
list(): Promise<DatasetsResponse> { | ||
throw new Error('cannot list dataset with the current client configuration') | ||
} | ||
} | ||
function _modify<R = unknown>( | ||
@@ -111,0 +133,0 @@ client: SanityClient | ObservableSanityClient, |
@@ -10,3 +10,7 @@ import {lastValueFrom, Observable} from 'rxjs' | ||
import {ObservableTransaction, Transaction} from './data/transaction' | ||
import {DatasetsClient, ObservableDatasetsClient} from './datasets/DatasetsClient' | ||
import { | ||
DatasetsClient, | ||
ObservableDatasetsClient, | ||
ThrowingDatasetsClient, | ||
} from './datasets/DatasetsClient' | ||
import {ObservableProjectsClient, ProjectsClient} from './projects/ProjectsClient' | ||
@@ -760,3 +764,6 @@ import type { | ||
this.assets = new AssetsClient(this, this.#httpRequest) | ||
this.datasets = new DatasetsClient(this, this.#httpRequest) | ||
this.datasets = this.#clientConfig.experimental_resource | ||
? new ThrowingDatasetsClient(this, this.#httpRequest) | ||
: new DatasetsClient(this, this.#httpRequest) | ||
this.live = new LiveClient(this) | ||
@@ -763,0 +770,0 @@ this.projects = new ProjectsClient(this, this.#httpRequest) |
@@ -107,2 +107,10 @@ // deno-lint-ignore-file no-empty-interface | ||
stega?: StegaConfig | boolean | ||
/** | ||
* @deprecated Don't use | ||
*/ | ||
experimental_resource?: { | ||
id: string | ||
type: string | ||
} | ||
} | ||
@@ -109,0 +117,0 @@ |
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 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 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 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
Sorry, the diff of this file is too big to display
Unstable ownership
Supply chain riskA new collaborator has begun publishing package versions. Package stability and security risk may be elevated.
Found 1 instance in 1 package
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
2804538
33795
1
12
Updatedget-it@^8.6.7