@sanity/client 6.26.1 → 6.27.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.
- package/dist/_chunks-cjs/config.cjs +163 -0
- package/dist/_chunks-cjs/config.cjs.map +1 -0
- package/dist/_chunks-es/config.js +164 -0
- package/dist/_chunks-es/config.js.map +1 -0
- package/dist/csm.cjs +40 -18
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.d.cts +6 -3
- package/dist/csm.d.ts +6 -3
- package/dist/csm.js +42 -19
- package/dist/csm.js.map +1 -1
- package/dist/index.cjs +54 -202
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -158
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/csm/applySourceDocuments.ts +10 -40
- package/src/csm/createSourceDocumentResolver.ts +54 -0
- package/src/csm/resolvePerspectives.ts +29 -0
package/dist/csm.js
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DRAFTS_FOLDER, VERSION_FOLDER, getVersionFromId,
|
|
3
|
-
|
|
4
|
-
function
|
|
1
|
+
import { getVersionId, getDraftId, getPublishedId, walkMap, resolveMapping, parseJsonPath, toString, get, jsonPath, studioPathToJsonPath, resolveEditInfo, createEditUrl } from "./_chunks-es/resolveEditInfo.js";
|
|
2
|
+
import { DRAFTS_FOLDER, VERSION_FOLDER, getVersionFromId, isDraftId, isPublishedId, isVersionId, jsonPathToStudioPath, studioPath } from "./_chunks-es/resolveEditInfo.js";
|
|
3
|
+
import { validateApiPerspective } from "./_chunks-es/config.js";
|
|
4
|
+
function resolvePerspectives(perspective) {
|
|
5
|
+
if (validateApiPerspective(perspective), Array.isArray(perspective))
|
|
6
|
+
return perspective.includes("published") ? perspective : [...perspective, "published"];
|
|
7
|
+
switch (perspective) {
|
|
8
|
+
case "previewDrafts":
|
|
9
|
+
case "drafts":
|
|
10
|
+
return ["drafts", "published"];
|
|
11
|
+
case "published":
|
|
12
|
+
default:
|
|
13
|
+
return ["published"];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function createSourceDocumentResolver(getCachedDocument, _perspective) {
|
|
17
|
+
const perspectives = resolvePerspectives(_perspective);
|
|
18
|
+
function findDocument(sourceDocument) {
|
|
19
|
+
for (const perspective of perspectives) {
|
|
20
|
+
let match = null;
|
|
21
|
+
if (perspective.startsWith("r") && (match = getCachedDocument({
|
|
22
|
+
...sourceDocument,
|
|
23
|
+
_id: getVersionId(sourceDocument._id, perspective)
|
|
24
|
+
})), perspective === "drafts" && (match = getCachedDocument({
|
|
25
|
+
...sourceDocument,
|
|
26
|
+
_id: getDraftId(sourceDocument._id)
|
|
27
|
+
})), perspective === "published" && (match = getCachedDocument({
|
|
28
|
+
...sourceDocument,
|
|
29
|
+
_id: getPublishedId(sourceDocument._id)
|
|
30
|
+
})), match)
|
|
31
|
+
return { ...match, _id: getPublishedId(match._id), _originalId: match._id };
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return function(sourceDocument) {
|
|
36
|
+
return findDocument(sourceDocument);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function applySourceDocuments(result, resultSourceMap, getCachedDocument, updateFn, perspective) {
|
|
5
40
|
if (!resultSourceMap) return result;
|
|
6
|
-
|
|
7
|
-
throw new Error(`Unknown perspective "${perspective}"`);
|
|
41
|
+
const resolveDocument = createSourceDocumentResolver(getCachedDocument, perspective), cachedDocuments = resultSourceMap.documents.map(resolveDocument);
|
|
8
42
|
return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {
|
|
9
43
|
const resolveMappingResult = resolveMapping(path, resultSourceMap);
|
|
10
44
|
if (!resolveMappingResult)
|
|
@@ -14,19 +48,8 @@ function applySourceDocuments(result, resultSourceMap, getCachedDocument, update
|
|
|
14
48
|
return value;
|
|
15
49
|
const sourceDocument = resultSourceMap.documents[mapping.source.document], sourcePath = resultSourceMap.paths[mapping.source.path];
|
|
16
50
|
if (sourceDocument) {
|
|
17
|
-
const parsedPath = parseJsonPath(sourcePath + pathSuffix), stringifiedPath = toString(parsedPath);
|
|
18
|
-
if (
|
|
19
|
-
return value;
|
|
20
|
-
let cachedDocument;
|
|
21
|
-
if (perspective === "previewDrafts" ? (cachedDocument = getCachedDocument(
|
|
22
|
-
isDraftId(sourceDocument._id) ? sourceDocument : { ...sourceDocument, _id: getDraftId(sourceDocument._id) }
|
|
23
|
-
), cachedDocument || (cachedDocument = getCachedDocument(
|
|
24
|
-
isDraftId(sourceDocument._id) ? { ...sourceDocument, _id: getPublishedId(sourceDocument._id) } : sourceDocument
|
|
25
|
-
)), cachedDocument && (cachedDocument = {
|
|
26
|
-
...cachedDocument,
|
|
27
|
-
_id: getPublishedId(sourceDocument._id),
|
|
28
|
-
_originalId: sourceDocument._id
|
|
29
|
-
})) : cachedDocument = getCachedDocument(sourceDocument), !cachedDocument)
|
|
51
|
+
const parsedPath = parseJsonPath(sourcePath + pathSuffix), stringifiedPath = toString(parsedPath), cachedDocument = cachedDocuments[mapping.source.document];
|
|
52
|
+
if (!cachedDocument)
|
|
30
53
|
return value;
|
|
31
54
|
const changedValue = cachedDocument ? get(cachedDocument, stringifiedPath, value) : value;
|
|
32
55
|
return value === changedValue ? value : updateFn(changedValue, {
|
package/dist/csm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"csm.js","sources":["../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {getDraftId, getPublishedId,
|
|
1
|
+
{"version":3,"file":"csm.js","sources":["../src/csm/resolvePerspectives.ts","../src/csm/createSourceDocumentResolver.ts","../src/csm/applySourceDocuments.ts","../src/csm/resolvedKeyedSourcePath.ts","../src/csm/resolveEditUrl.ts"],"sourcesContent":["import {validateApiPerspective} from '../config'\nimport type {ReleaseId} from '../types'\nimport type {ClientPerspective} from './types'\n\n/**\n * This resolves the perspectives to how documents should be resolved when applying optimistic updates,\n * like in `applySourceDocuments`.\n * @internal\n */\nexport function resolvePerspectives(\n perspective: Exclude<ClientPerspective, 'raw'>,\n): ('published' | 'drafts' | ReleaseId)[] {\n validateApiPerspective(perspective)\n\n if (Array.isArray(perspective)) {\n if (!perspective.includes('published')) {\n return [...perspective, 'published']\n }\n return perspective\n }\n switch (perspective) {\n case 'previewDrafts':\n case 'drafts':\n return ['drafts', 'published']\n case 'published':\n default:\n return ['published']\n }\n}\n","import {getDraftId, getPublishedId, getVersionId} from './draftUtils'\nimport {resolvePerspectives} from './resolvePerspectives'\nimport type {ClientPerspective, ContentSourceMapDocuments, SanityDocument} from './types'\n\n/** @internal */\nexport type ResolvedDocument = Partial<SanityDocument> &\n Required<Pick<SanityDocument, '_id' | '_type'>>\n\n/** @internal */\nexport type MatchedDocument = Partial<SanityDocument> &\n Required<Pick<SanityDocument, '_id' | '_type' | '_originalId'>>\n\n/** @internal */\nexport function createSourceDocumentResolver(\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) => ResolvedDocument | null | undefined,\n _perspective: Exclude<ClientPerspective, 'raw'>,\n) {\n const perspectives = resolvePerspectives(_perspective)\n function findDocument(sourceDocument: ContentSourceMapDocuments[number]) {\n for (const perspective of perspectives) {\n let match: ReturnType<typeof getCachedDocument> = null\n if (perspective.startsWith('r')) {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getVersionId(sourceDocument._id, perspective),\n })\n }\n if (perspective === 'drafts') {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getDraftId(sourceDocument._id),\n })\n }\n if (perspective === 'published') {\n match = getCachedDocument({\n ...sourceDocument,\n _id: getPublishedId(sourceDocument._id),\n })\n }\n if (match) {\n return {...match, _id: getPublishedId(match._id), _originalId: match._id}\n }\n }\n return null\n }\n // define resolver that loops over source documents and perspectives\n return function resolveSourceDocument(\n sourceDocument: ContentSourceMapDocuments[number],\n ): MatchedDocument | null {\n return findDocument(sourceDocument)\n }\n}\n","import {createSourceDocumentResolver} from './createSourceDocumentResolver'\nimport {parseJsonPath} from './jsonPath'\nimport {resolveMapping} from './resolveMapping'\nimport * as paths from './studioPath'\nimport type {\n Any,\n ApplySourceDocumentsUpdateFunction,\n ClientPerspective,\n ContentSourceMap,\n ContentSourceMapDocuments,\n Path,\n SanityDocument,\n} from './types'\nimport {walkMap} from './walkMap'\n\n/**\n * Optimistically applies source documents to a result, using the content source map to trace fields.\n * Can be used to apply mutations to documents being edited in a Studio, or any mutation on Content Lake, to a result with extremely low latency.\n * @alpha\n */\nexport function applySourceDocuments<Result = unknown>(\n result: Result,\n resultSourceMap: ContentSourceMap | undefined,\n getCachedDocument: (\n sourceDocument: ContentSourceMapDocuments[number],\n ) =>\n | (Partial<SanityDocument> & Required<Pick<SanityDocument, '_id' | '_type'>>)\n | null\n | undefined,\n updateFn: ApplySourceDocumentsUpdateFunction,\n perspective: Exclude<ClientPerspective, 'raw'>,\n): Result {\n if (!resultSourceMap) return result\n\n const resolveDocument = createSourceDocumentResolver(getCachedDocument, perspective)\n const cachedDocuments = resultSourceMap.documents.map(resolveDocument)\n\n return walkMap(JSON.parse(JSON.stringify(result)), (value, path) => {\n const resolveMappingResult = resolveMapping(path, resultSourceMap)\n if (!resolveMappingResult) {\n return value\n }\n\n const {mapping, pathSuffix} = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument = resultSourceMap.documents[mapping.source.document]\n const sourcePath = resultSourceMap.paths[mapping.source.path]\n\n if (sourceDocument) {\n const parsedPath = parseJsonPath(sourcePath + pathSuffix)\n const stringifiedPath = paths.toString(parsedPath as Path)\n const cachedDocument = cachedDocuments[mapping.source.document]\n\n if (!cachedDocument) {\n return value\n }\n\n const changedValue = cachedDocument\n ? paths.get<Result[keyof Result]>(cachedDocument, stringifiedPath, value)\n : value\n return value === changedValue\n ? value\n : updateFn<Result[keyof Result]>(changedValue as Any, {\n cachedDocument,\n previousValue: value as Result[keyof Result],\n sourceDocument,\n sourcePath: parsedPath,\n })\n }\n\n return value\n }) as Result\n}\n","import {jsonPath, parseJsonPath} from './jsonPath'\nimport type {ContentSourceMapParsedPath} from './types'\n\n/**\n * @internal\n */\nexport function resolvedKeyedSourcePath(options: {\n keyedResultPath: ContentSourceMapParsedPath\n pathSuffix?: string\n sourceBasePath: string\n}): ContentSourceMapParsedPath {\n const {keyedResultPath, pathSuffix, sourceBasePath} = options\n\n const inferredResultPath = pathSuffix === undefined ? [] : parseJsonPath(pathSuffix)\n\n const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length)\n\n const inferredPathSuffix = inferredPath.length ? jsonPath(inferredPath).slice(1) : ''\n\n return parseJsonPath(sourceBasePath + inferredPathSuffix)\n}\n","import {createEditUrl} from './createEditUrl'\nimport {studioPathToJsonPath} from './jsonPath'\nimport {resolveEditInfo} from './resolveEditInfo'\nimport type {ResolveEditUrlOptions} from './types'\n\n/** @alpha */\nexport function resolveEditUrl(\n options: ResolveEditUrlOptions,\n): ReturnType<typeof createEditUrl> | undefined {\n const {resultSourceMap, studioUrl} = options\n const resultPath = studioPathToJsonPath(options.resultPath)\n\n const editInfo = resolveEditInfo({\n resultPath,\n resultSourceMap,\n studioUrl,\n })\n if (!editInfo) {\n return undefined\n }\n\n return createEditUrl(editInfo)\n}\n"],"names":["paths.toString","paths.get"],"mappings":"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"}
|
package/dist/index.cjs
CHANGED
|
@@ -19,7 +19,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
19
19
|
mod
|
|
20
20
|
));
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
22
|
-
var getIt = require("get-it"), middleware$1 = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators");
|
|
22
|
+
var getIt = require("get-it"), middleware$1 = require("get-it/middleware"), rxjs = require("rxjs"), stegaClean = require("./_chunks-cjs/stegaClean.cjs"), operators = require("rxjs/operators"), config = require("./_chunks-cjs/config.cjs");
|
|
23
23
|
class ClientError extends Error {
|
|
24
24
|
response;
|
|
25
25
|
statusCode = 400;
|
|
@@ -79,9 +79,9 @@ function stringifyBody(body, res) {
|
|
|
79
79
|
class CorsOriginError extends Error {
|
|
80
80
|
projectId;
|
|
81
81
|
addOriginUrl;
|
|
82
|
-
constructor({ projectId
|
|
83
|
-
super("CorsOriginError"), this.name = "CorsOriginError", this.projectId =
|
|
84
|
-
const url = new URL(`https://sanity.io/manage/project/${
|
|
82
|
+
constructor({ projectId }) {
|
|
83
|
+
super("CorsOriginError"), this.name = "CorsOriginError", this.projectId = projectId;
|
|
84
|
+
const url = new URL(`https://sanity.io/manage/project/${projectId}/api`);
|
|
85
85
|
if (typeof location < "u") {
|
|
86
86
|
const { origin } = location;
|
|
87
87
|
url.searchParams.set("cors", "add"), url.searchParams.set("origin", origin), this.addOriginUrl = url, this.message = `The current origin is not allowed to connect to the Live Content API. Add it here: ${url}`;
|
|
@@ -126,154 +126,6 @@ function shouldRetry(err, attempt, options) {
|
|
|
126
126
|
const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
|
|
127
127
|
return (isSafe || isQuery) && isRetriableResponse ? !0 : middleware$1.retry.shouldRetry(err, attempt, options);
|
|
128
128
|
}
|
|
129
|
-
const BASE_URL = "https://www.sanity.io/help/";
|
|
130
|
-
function generateHelpUrl(slug) {
|
|
131
|
-
return BASE_URL + slug;
|
|
132
|
-
}
|
|
133
|
-
const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before", "after", "replace"], dataset = (name2) => {
|
|
134
|
-
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name2))
|
|
135
|
-
throw new Error(
|
|
136
|
-
"Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters"
|
|
137
|
-
);
|
|
138
|
-
}, projectId = (id) => {
|
|
139
|
-
if (!/^[-a-z0-9]+$/i.test(id))
|
|
140
|
-
throw new Error("`projectId` can only contain only a-z, 0-9 and dashes");
|
|
141
|
-
}, validateAssetType = (type) => {
|
|
142
|
-
if (VALID_ASSET_TYPES.indexOf(type) === -1)
|
|
143
|
-
throw new Error(`Invalid asset type: ${type}. Must be one of ${VALID_ASSET_TYPES.join(", ")}`);
|
|
144
|
-
}, validateObject = (op, val) => {
|
|
145
|
-
if (val === null || typeof val != "object" || Array.isArray(val))
|
|
146
|
-
throw new Error(`${op}() takes an object of properties`);
|
|
147
|
-
}, validateDocumentId = (op, id) => {
|
|
148
|
-
if (typeof id != "string" || !/^[a-z0-9_][a-z0-9_.-]{0,127}$/i.test(id) || id.includes(".."))
|
|
149
|
-
throw new Error(`${op}(): "${id}" is not a valid document ID`);
|
|
150
|
-
}, requireDocumentId = (op, doc) => {
|
|
151
|
-
if (!doc._id)
|
|
152
|
-
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
153
|
-
validateDocumentId(op, doc._id);
|
|
154
|
-
}, validateInsert = (at, selector, items) => {
|
|
155
|
-
const signature = "insert(at, selector, items)";
|
|
156
|
-
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
157
|
-
const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(", ");
|
|
158
|
-
throw new Error(`${signature} takes an "at"-argument which is one of: ${valid}`);
|
|
159
|
-
}
|
|
160
|
-
if (typeof selector != "string")
|
|
161
|
-
throw new Error(`${signature} takes a "selector"-argument which must be a string`);
|
|
162
|
-
if (!Array.isArray(items))
|
|
163
|
-
throw new Error(`${signature} takes an "items"-argument which must be an array`);
|
|
164
|
-
}, hasDataset = (config) => {
|
|
165
|
-
if (!config.dataset)
|
|
166
|
-
throw new Error("`dataset` must be provided to perform queries");
|
|
167
|
-
return config.dataset || "";
|
|
168
|
-
}, requestTag = (tag) => {
|
|
169
|
-
if (typeof tag != "string" || !/^[a-z0-9._-]{1,75}$/i.test(tag))
|
|
170
|
-
throw new Error(
|
|
171
|
-
"Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long."
|
|
172
|
-
);
|
|
173
|
-
return tag;
|
|
174
|
-
};
|
|
175
|
-
function once(fn) {
|
|
176
|
-
let didCall = !1, returnValue;
|
|
177
|
-
return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
|
|
178
|
-
}
|
|
179
|
-
const createWarningPrinter = (message) => (
|
|
180
|
-
// eslint-disable-next-line no-console
|
|
181
|
-
once((...args) => console.warn(message.join(" "), ...args))
|
|
182
|
-
), printCdnAndWithCredentialsWarning = createWarningPrinter([
|
|
183
|
-
"Because you set `withCredentials` to true, we will override your `useCdn`",
|
|
184
|
-
"setting to be false since (cookie-based) credentials are never set on the CDN"
|
|
185
|
-
]), printCdnWarning = createWarningPrinter([
|
|
186
|
-
"Since you haven't set a value for `useCdn`, we will deliver content using our",
|
|
187
|
-
"global, edge-cached API-CDN. If you wish to have content delivered faster, set",
|
|
188
|
-
"`useCdn: false` to use the Live API. Note: You may incur higher costs using the live API."
|
|
189
|
-
]), printCdnPreviewDraftsWarning = createWarningPrinter([
|
|
190
|
-
"The Sanity client is configured with the `perspective` set to `previewDrafts`, which doesn't support the API-CDN.",
|
|
191
|
-
"The Live API will be used instead. Set `useCdn: false` in your configuration to hide this warning."
|
|
192
|
-
]), printBrowserTokenWarning = createWarningPrinter([
|
|
193
|
-
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
194
|
-
`See ${generateHelpUrl(
|
|
195
|
-
"js-client-browser-token"
|
|
196
|
-
)} for more information and how to hide this warning.`
|
|
197
|
-
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
198
|
-
"Using the Sanity client without specifying an API version is deprecated.",
|
|
199
|
-
`See ${generateHelpUrl("js-client-api-version")}`
|
|
200
|
-
]), printNoDefaultExport = createWarningPrinter([
|
|
201
|
-
"The default export of @sanity/client has been deprecated. Use the named export `createClient` instead."
|
|
202
|
-
]), defaultCdnHost = "apicdn.sanity.io", defaultConfig = {
|
|
203
|
-
apiHost: "https://api.sanity.io",
|
|
204
|
-
apiVersion: "1",
|
|
205
|
-
useProjectHostname: !0,
|
|
206
|
-
stega: { enabled: !1 }
|
|
207
|
-
}, LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"], isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
208
|
-
function validateApiVersion(apiVersion) {
|
|
209
|
-
if (apiVersion === "1" || apiVersion === "X")
|
|
210
|
-
return;
|
|
211
|
-
const apiDate = new Date(apiVersion);
|
|
212
|
-
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
213
|
-
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
214
|
-
}
|
|
215
|
-
function validateApiPerspective(perspective) {
|
|
216
|
-
if (Array.isArray(perspective)) {
|
|
217
|
-
for (const perspectiveValue of perspective)
|
|
218
|
-
if (perspectiveValue !== "published" && perspectiveValue !== "drafts" && !(typeof perspectiveValue == "string" && perspectiveValue.startsWith("r") && perspectiveValue !== "raw"))
|
|
219
|
-
throw new TypeError(
|
|
220
|
-
"Invalid API perspective value, expected `published`, `drafts` or a valid release identifier string"
|
|
221
|
-
);
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
switch (perspective) {
|
|
225
|
-
case "previewDrafts":
|
|
226
|
-
case "drafts":
|
|
227
|
-
case "published":
|
|
228
|
-
case "raw":
|
|
229
|
-
return;
|
|
230
|
-
default:
|
|
231
|
-
throw new TypeError(
|
|
232
|
-
"Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const initConfig = (config, prevConfig) => {
|
|
237
|
-
const specifiedConfig = {
|
|
238
|
-
...prevConfig,
|
|
239
|
-
...config,
|
|
240
|
-
stega: {
|
|
241
|
-
...typeof prevConfig.stega == "boolean" ? { enabled: prevConfig.stega } : prevConfig.stega || defaultConfig.stega,
|
|
242
|
-
...typeof config.stega == "boolean" ? { enabled: config.stega } : config.stega || {}
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
specifiedConfig.apiVersion || printNoApiVersionSpecifiedWarning();
|
|
246
|
-
const newConfig = {
|
|
247
|
-
...defaultConfig,
|
|
248
|
-
...specifiedConfig
|
|
249
|
-
}, projectBased = newConfig.useProjectHostname;
|
|
250
|
-
if (typeof Promise > "u") {
|
|
251
|
-
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
252
|
-
throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
|
|
253
|
-
}
|
|
254
|
-
if (projectBased && !newConfig.projectId)
|
|
255
|
-
throw new Error("Configuration must contain `projectId`");
|
|
256
|
-
if (typeof newConfig.perspective < "u" && validateApiPerspective(newConfig.perspective), "encodeSourceMap" in newConfig)
|
|
257
|
-
throw new Error(
|
|
258
|
-
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client'. Did you mean 'stega.enabled'?"
|
|
259
|
-
);
|
|
260
|
-
if ("encodeSourceMapAtPath" in newConfig)
|
|
261
|
-
throw new Error(
|
|
262
|
-
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client'. Did you mean 'stega.filter'?"
|
|
263
|
-
);
|
|
264
|
-
if (typeof newConfig.stega.enabled != "boolean")
|
|
265
|
-
throw new Error(`stega.enabled must be a boolean, received ${newConfig.stega.enabled}`);
|
|
266
|
-
if (newConfig.stega.enabled && newConfig.stega.studioUrl === void 0)
|
|
267
|
-
throw new Error("stega.studioUrl must be defined when stega.enabled is true");
|
|
268
|
-
if (newConfig.stega.enabled && typeof newConfig.stega.studioUrl != "string" && typeof newConfig.stega.studioUrl != "function")
|
|
269
|
-
throw new Error(
|
|
270
|
-
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
271
|
-
);
|
|
272
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
273
|
-
isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== !0 ? printBrowserTokenWarning() : typeof newConfig.useCdn > "u" && printCdnWarning(), projectBased && projectId(newConfig.projectId), newConfig.dataset && dataset(newConfig.dataset), "requestTagPrefix" in newConfig && (newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0), newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, ""), newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost, newConfig.useCdn === !0 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
274
|
-
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
275
|
-
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;
|
|
276
|
-
};
|
|
277
129
|
class ConnectionFailedError extends Error {
|
|
278
130
|
name = "ConnectionFailedError";
|
|
279
131
|
}
|
|
@@ -428,7 +280,7 @@ class BasePatch {
|
|
|
428
280
|
* @param attrs - Attributes to perform operation on. To set a deep attribute, use JSONMatch, eg: \{"nested.prop": "dmp"\}
|
|
429
281
|
*/
|
|
430
282
|
diffMatchPatch(attrs) {
|
|
431
|
-
return validateObject("diffMatchPatch", attrs), this._assign("diffMatchPatch", attrs);
|
|
283
|
+
return config.validateObject("diffMatchPatch", attrs), this._assign("diffMatchPatch", attrs);
|
|
432
284
|
}
|
|
433
285
|
/**
|
|
434
286
|
* Unsets the attribute paths provided.
|
|
@@ -465,7 +317,7 @@ class BasePatch {
|
|
|
465
317
|
* @param items - Array of items to insert/replace
|
|
466
318
|
*/
|
|
467
319
|
insert(at, selector, items) {
|
|
468
|
-
return validateInsert(at, selector, items), this._assign("insert", { [at]: selector, items });
|
|
320
|
+
return config.validateInsert(at, selector, items), this._assign("insert", { [at]: selector, items });
|
|
469
321
|
}
|
|
470
322
|
/**
|
|
471
323
|
* Append the given items to the array at the given JSONPath
|
|
@@ -524,7 +376,7 @@ class BasePatch {
|
|
|
524
376
|
return this.operations = {}, this;
|
|
525
377
|
}
|
|
526
378
|
_assign(op, props, merge = !0) {
|
|
527
|
-
return validateObject(op, props), this.operations = Object.assign({}, this.operations, {
|
|
379
|
+
return config.validateObject(op, props), this.operations = Object.assign({}, this.operations, {
|
|
528
380
|
[op]: Object.assign({}, merge && this.operations[op] || {}, props)
|
|
529
381
|
}), this;
|
|
530
382
|
}
|
|
@@ -586,7 +438,7 @@ class BaseTransaction {
|
|
|
586
438
|
* @param doc - Document to create. Requires a `_type` property.
|
|
587
439
|
*/
|
|
588
440
|
create(doc) {
|
|
589
|
-
return validateObject("create", doc), this._add({ create: doc });
|
|
441
|
+
return config.validateObject("create", doc), this._add({ create: doc });
|
|
590
442
|
}
|
|
591
443
|
/**
|
|
592
444
|
* Creates a new Sanity document. If a document with the same `_id` already exists, the create operation will be ignored.
|
|
@@ -596,7 +448,7 @@ class BaseTransaction {
|
|
|
596
448
|
*/
|
|
597
449
|
createIfNotExists(doc) {
|
|
598
450
|
const op = "createIfNotExists";
|
|
599
|
-
return validateObject(op, doc), requireDocumentId(op, doc), this._add({ [op]: doc });
|
|
451
|
+
return config.validateObject(op, doc), config.requireDocumentId(op, doc), this._add({ [op]: doc });
|
|
600
452
|
}
|
|
601
453
|
/**
|
|
602
454
|
* Creates a new Sanity document, or replaces an existing one if the same `_id` is already used.
|
|
@@ -606,7 +458,7 @@ class BaseTransaction {
|
|
|
606
458
|
*/
|
|
607
459
|
createOrReplace(doc) {
|
|
608
460
|
const op = "createOrReplace";
|
|
609
|
-
return validateObject(op, doc), requireDocumentId(op, doc), this._add({ [op]: doc });
|
|
461
|
+
return config.validateObject(op, doc), config.requireDocumentId(op, doc), this._add({ [op]: doc });
|
|
610
462
|
}
|
|
611
463
|
/**
|
|
612
464
|
* Deletes the document with the given document ID
|
|
@@ -615,7 +467,7 @@ class BaseTransaction {
|
|
|
615
467
|
* @param documentId - Document ID to delete
|
|
616
468
|
*/
|
|
617
469
|
delete(documentId) {
|
|
618
|
-
return validateDocumentId("delete", documentId), this._add({ delete: { id: documentId } });
|
|
470
|
+
return config.validateDocumentId("delete", documentId), this._add({ delete: { id: documentId } });
|
|
619
471
|
}
|
|
620
472
|
transactionId(id) {
|
|
621
473
|
return id ? (this.trxId = id, this) : this.trxId;
|
|
@@ -715,17 +567,17 @@ class ObservableTransaction extends BaseTransaction {
|
|
|
715
567
|
}
|
|
716
568
|
}
|
|
717
569
|
const projectHeader = "X-Sanity-Project-ID";
|
|
718
|
-
function requestOptions(
|
|
719
|
-
const headers = {}, token = overrides.token ||
|
|
720
|
-
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !
|
|
721
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ?
|
|
570
|
+
function requestOptions(config2, overrides = {}) {
|
|
571
|
+
const headers = {}, token = overrides.token || config2.token;
|
|
572
|
+
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config2.useProjectHostname && config2.projectId && (headers[projectHeader] = config2.projectId);
|
|
573
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config2.token || config2.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config2.timeout : overrides.timeout;
|
|
722
574
|
return Object.assign({}, overrides, {
|
|
723
575
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
724
576
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
725
|
-
proxy: overrides.proxy ||
|
|
577
|
+
proxy: overrides.proxy || config2.proxy,
|
|
726
578
|
json: !0,
|
|
727
579
|
withCredentials,
|
|
728
|
-
fetch: typeof overrides.fetch == "object" && typeof
|
|
580
|
+
fetch: typeof overrides.fetch == "object" && typeof config2.fetch == "object" ? { ...config2.fetch, ...overrides.fetch } : overrides.fetch || config2.fetch
|
|
729
581
|
});
|
|
730
582
|
}
|
|
731
583
|
const encodeQueryString = ({
|
|
@@ -811,10 +663,10 @@ function _getDocuments(client, httpRequest, ids, opts = {}) {
|
|
|
811
663
|
);
|
|
812
664
|
}
|
|
813
665
|
function _createIfNotExists(client, httpRequest, doc, options) {
|
|
814
|
-
return requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
|
|
666
|
+
return config.requireDocumentId("createIfNotExists", doc), _create(client, httpRequest, doc, "createIfNotExists", options);
|
|
815
667
|
}
|
|
816
668
|
function _createOrReplace(client, httpRequest, doc, options) {
|
|
817
|
-
return requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
669
|
+
return config.requireDocumentId("createOrReplace", doc), _create(client, httpRequest, doc, "createOrReplace", options);
|
|
818
670
|
}
|
|
819
671
|
function _delete(client, httpRequest, selection, options) {
|
|
820
672
|
return _dataRequest(
|
|
@@ -886,25 +738,25 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
886
738
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
887
739
|
}
|
|
888
740
|
function _requestObservable(client, httpRequest, options) {
|
|
889
|
-
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;
|
|
890
|
-
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
891
|
-
const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
|
|
892
|
-
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) {
|
|
893
|
-
const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
|
|
741
|
+
const uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
|
|
742
|
+
let useCdn = (options.useCdn ?? config$1.useCdn) && canUseCdn;
|
|
743
|
+
const tag = options.tag && config$1.requestTagPrefix ? [config$1.requestTagPrefix, options.tag].join(".") : options.tag || config$1.requestTagPrefix;
|
|
744
|
+
if (tag && options.tag !== null && (options.query = { tag: config.requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
|
|
745
|
+
const resultSourceMap = options.resultSourceMap ?? config$1.resultSourceMap;
|
|
894
746
|
resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
|
|
895
|
-
const perspectiveOption = options.perspective || config.perspective;
|
|
896
|
-
typeof perspectiveOption < "u" && (validateApiPerspective(perspectiveOption), options.query = {
|
|
747
|
+
const perspectiveOption = options.perspective || config$1.perspective;
|
|
748
|
+
typeof perspectiveOption < "u" && (config.validateApiPerspective(perspectiveOption), options.query = {
|
|
897
749
|
perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
|
|
898
750
|
...options.query
|
|
899
|
-
}, perspectiveOption === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
751
|
+
}, perspectiveOption === "previewDrafts" && useCdn && (useCdn = !1, config.printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
|
|
900
752
|
}
|
|
901
753
|
const reqOptions = requestOptions(
|
|
902
|
-
config,
|
|
754
|
+
config$1,
|
|
903
755
|
Object.assign({}, options, {
|
|
904
756
|
url: _getUrl(client, uri, useCdn)
|
|
905
757
|
})
|
|
906
758
|
), request = new rxjs.Observable(
|
|
907
|
-
(subscriber) => httpRequest(reqOptions, config.requester).subscribe(subscriber)
|
|
759
|
+
(subscriber) => httpRequest(reqOptions, config$1.requester).subscribe(subscriber)
|
|
908
760
|
);
|
|
909
761
|
return options.signal ? request.pipe(_withAbortSignal(options.signal)) : request;
|
|
910
762
|
}
|
|
@@ -915,7 +767,7 @@ function _request(client, httpRequest, options) {
|
|
|
915
767
|
);
|
|
916
768
|
}
|
|
917
769
|
function _getDataUrl(client, operation, path) {
|
|
918
|
-
const config = client.config(), catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
|
|
770
|
+
const config$1 = client.config(), catalog = config.hasDataset(config$1), baseUri = `/${operation}/${catalog}`;
|
|
919
771
|
return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
|
|
920
772
|
}
|
|
921
773
|
function _getUrl(client, uri, canUseCdn = !1) {
|
|
@@ -971,10 +823,10 @@ class AssetsClient {
|
|
|
971
823
|
}
|
|
972
824
|
}
|
|
973
825
|
function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
974
|
-
validateAssetType(assetType);
|
|
826
|
+
config.validateAssetType(assetType);
|
|
975
827
|
let meta = opts.extract || void 0;
|
|
976
828
|
meta && !meta.length && (meta = ["none"]);
|
|
977
|
-
const
|
|
829
|
+
const dataset = config.hasDataset(client.config()), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
978
830
|
label,
|
|
979
831
|
title,
|
|
980
832
|
description,
|
|
@@ -986,7 +838,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
986
838
|
tag,
|
|
987
839
|
method: "POST",
|
|
988
840
|
timeout: options.timeout || 0,
|
|
989
|
-
uri: `/assets/${assetEndpoint}/${
|
|
841
|
+
uri: `/assets/${assetEndpoint}/${dataset}`,
|
|
990
842
|
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
991
843
|
query,
|
|
992
844
|
body
|
|
@@ -1058,7 +910,7 @@ class LiveClient {
|
|
|
1058
910
|
tag: _tag
|
|
1059
911
|
} = {}) {
|
|
1060
912
|
const {
|
|
1061
|
-
projectId
|
|
913
|
+
projectId,
|
|
1062
914
|
apiVersion: _apiVersion,
|
|
1063
915
|
token,
|
|
1064
916
|
withCredentials,
|
|
@@ -1107,7 +959,7 @@ class LiveClient {
|
|
|
1107
959
|
}).pipe(
|
|
1108
960
|
rxjs.mergeMap(() => rxjs.EMPTY),
|
|
1109
961
|
rxjs.catchError(() => {
|
|
1110
|
-
throw new CorsOriginError({ projectId
|
|
962
|
+
throw new CorsOriginError({ projectId });
|
|
1111
963
|
})
|
|
1112
964
|
);
|
|
1113
965
|
return rxjs.concat(checkCors, events);
|
|
@@ -1214,7 +1066,7 @@ class DatasetsClient {
|
|
|
1214
1066
|
}
|
|
1215
1067
|
}
|
|
1216
1068
|
function _modify(client, httpRequest, method, name2, options) {
|
|
1217
|
-
return dataset(name2), _request(client, httpRequest, {
|
|
1069
|
+
return config.dataset(name2), _request(client, httpRequest, {
|
|
1218
1070
|
method,
|
|
1219
1071
|
uri: `/datasets/${name2}`,
|
|
1220
1072
|
body: options,
|
|
@@ -1236,8 +1088,8 @@ class ObservableProjectsClient {
|
|
|
1236
1088
|
*
|
|
1237
1089
|
* @param projectId - ID of the project to fetch
|
|
1238
1090
|
*/
|
|
1239
|
-
getById(
|
|
1240
|
-
return _request(this.#client, this.#httpRequest, { uri: `/projects/${
|
|
1091
|
+
getById(projectId) {
|
|
1092
|
+
return _request(this.#client, this.#httpRequest, { uri: `/projects/${projectId}` });
|
|
1241
1093
|
}
|
|
1242
1094
|
}
|
|
1243
1095
|
class ProjectsClient {
|
|
@@ -1255,9 +1107,9 @@ class ProjectsClient {
|
|
|
1255
1107
|
*
|
|
1256
1108
|
* @param projectId - ID of the project to fetch
|
|
1257
1109
|
*/
|
|
1258
|
-
getById(
|
|
1110
|
+
getById(projectId) {
|
|
1259
1111
|
return rxjs.lastValueFrom(
|
|
1260
|
-
_request(this.#client, this.#httpRequest, { uri: `/projects/${
|
|
1112
|
+
_request(this.#client, this.#httpRequest, { uri: `/projects/${projectId}` })
|
|
1261
1113
|
);
|
|
1262
1114
|
}
|
|
1263
1115
|
}
|
|
@@ -1314,8 +1166,8 @@ class ObservableSanityClient {
|
|
|
1314
1166
|
* Instance properties
|
|
1315
1167
|
*/
|
|
1316
1168
|
listen = _listen;
|
|
1317
|
-
constructor(httpRequest, config = defaultConfig) {
|
|
1318
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest);
|
|
1169
|
+
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1170
|
+
this.config(config$1), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest);
|
|
1319
1171
|
}
|
|
1320
1172
|
/**
|
|
1321
1173
|
* Clone the client - returns a new instance
|
|
@@ -1330,7 +1182,7 @@ class ObservableSanityClient {
|
|
|
1330
1182
|
throw new Error(
|
|
1331
1183
|
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1332
1184
|
);
|
|
1333
|
-
return this.#clientConfig = initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1185
|
+
return this.#clientConfig = config.initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1334
1186
|
}
|
|
1335
1187
|
/**
|
|
1336
1188
|
* Clone the client with a new (partial) configuration.
|
|
@@ -1467,8 +1319,8 @@ class SanityClient {
|
|
|
1467
1319
|
* Instance properties
|
|
1468
1320
|
*/
|
|
1469
1321
|
listen = _listen;
|
|
1470
|
-
constructor(httpRequest, config = defaultConfig) {
|
|
1471
|
-
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);
|
|
1322
|
+
constructor(httpRequest, config$1 = config.defaultConfig) {
|
|
1323
|
+
this.config(config$1), 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$1);
|
|
1472
1324
|
}
|
|
1473
1325
|
/**
|
|
1474
1326
|
* Clone the client - returns a new instance
|
|
@@ -1483,7 +1335,7 @@ class SanityClient {
|
|
|
1483
1335
|
throw new Error(
|
|
1484
1336
|
"Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client"
|
|
1485
1337
|
);
|
|
1486
|
-
return this.observable && this.observable.config(newConfig), this.#clientConfig = initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1338
|
+
return this.observable && this.observable.config(newConfig), this.#clientConfig = config.initConfig(newConfig, this.#clientConfig || {}), this;
|
|
1487
1339
|
}
|
|
1488
1340
|
/**
|
|
1489
1341
|
* Clone the client with a new (partial) configuration.
|
|
@@ -1626,25 +1478,25 @@ class SanityClient {
|
|
|
1626
1478
|
}
|
|
1627
1479
|
}
|
|
1628
1480
|
function defineCreateClientExports(envMiddleware, ClassConstructor) {
|
|
1629
|
-
return { requester: defineHttpRequest(envMiddleware), createClient: (
|
|
1481
|
+
return { requester: defineHttpRequest(envMiddleware), createClient: (config2) => {
|
|
1630
1482
|
const clientRequester = defineHttpRequest(envMiddleware);
|
|
1631
1483
|
return new ClassConstructor(
|
|
1632
1484
|
(options, requester2) => (requester2 || clientRequester)({
|
|
1633
1485
|
maxRedirects: 0,
|
|
1634
|
-
maxRetries:
|
|
1635
|
-
retryDelay:
|
|
1486
|
+
maxRetries: config2.maxRetries,
|
|
1487
|
+
retryDelay: config2.retryDelay,
|
|
1636
1488
|
...options
|
|
1637
1489
|
}),
|
|
1638
|
-
|
|
1490
|
+
config2
|
|
1639
1491
|
);
|
|
1640
1492
|
} };
|
|
1641
1493
|
}
|
|
1642
1494
|
function defineDeprecatedCreateClient(createClient2) {
|
|
1643
|
-
return function(config) {
|
|
1644
|
-
return printNoDefaultExport(), createClient2(config);
|
|
1495
|
+
return function(config$1) {
|
|
1496
|
+
return config.printNoDefaultExport(), createClient2(config$1);
|
|
1645
1497
|
};
|
|
1646
1498
|
}
|
|
1647
|
-
var name = "@sanity/client", version = "6.
|
|
1499
|
+
var name = "@sanity/client", version = "6.27.0";
|
|
1648
1500
|
const middleware = [
|
|
1649
1501
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
1650
1502
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|
|
@@ -1674,6 +1526,7 @@ Object.defineProperty(exports, "unstable__environment", {
|
|
|
1674
1526
|
return getIt.environment;
|
|
1675
1527
|
}
|
|
1676
1528
|
});
|
|
1529
|
+
exports.validateApiPerspective = config.validateApiPerspective;
|
|
1677
1530
|
exports.BasePatch = BasePatch;
|
|
1678
1531
|
exports.BaseTransaction = BaseTransaction;
|
|
1679
1532
|
exports.ChannelError = ChannelError;
|
|
@@ -1694,5 +1547,4 @@ exports.connectEventSource = connectEventSource;
|
|
|
1694
1547
|
exports.createClient = createClient;
|
|
1695
1548
|
exports.default = deprecatedCreateClient;
|
|
1696
1549
|
exports.requester = requester;
|
|
1697
|
-
exports.validateApiPerspective = validateApiPerspective;
|
|
1698
1550
|
//# sourceMappingURL=index.cjs.map
|