@sanity/client
Advanced tools
Comparing version 6.11.3-canary.0 to 6.11.3
@@ -1,8 +0,8 @@ | ||
import { walkMap, resolveMapping, parseJsonPath, toString, DRAFTS_PREFIX, getPublishedId, get, jsonPath, studioPathToJsonPath, resolveEditInfo, createEditUrl } from './_chunks/resolveEditInfo-FaeuCV4M.js'; | ||
export { jsonPathToStudioPath, studioPath } from './_chunks/resolveEditInfo-FaeuCV4M.js'; | ||
const defaultUpdateFunction = changed => changed; | ||
function applySourceDocuments(result, resultSourceMap, getCachedDocument) { | ||
let updateFn = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : defaultUpdateFunction; | ||
let perspective = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "raw"; | ||
if (!resultSourceMap) return result; | ||
import { walkMap, resolveMapping, parseJsonPath, toString, DRAFTS_PREFIX, getPublishedId, get, jsonPath, studioPathToJsonPath, resolveEditInfo, createEditUrl } from './_chunks/resolveEditInfo-uXvm6eWd.js'; | ||
export { jsonPathToStudioPath, studioPath } from './_chunks/resolveEditInfo-uXvm6eWd.js'; | ||
const defaultUpdateFunction = (changed) => changed; | ||
function applySourceDocuments(result, resultSourceMap, getCachedDocument, updateFn = defaultUpdateFunction, perspective = "raw") { | ||
if (!resultSourceMap) | ||
return result; | ||
if (perspective !== "published" && perspective !== "raw" && perspective !== "previewDrafts") { | ||
@@ -16,6 +16,3 @@ throw new Error('Unknown perspective "'.concat(perspective, '"')); | ||
} | ||
const { | ||
mapping, | ||
pathSuffix | ||
} = resolveMappingResult; | ||
const { mapping, pathSuffix } = resolveMappingResult; | ||
if (mapping.type !== "value") { | ||
@@ -37,11 +34,9 @@ return value; | ||
if (perspective === "previewDrafts") { | ||
cachedDocument = getCachedDocument(sourceDocument._id.startsWith(DRAFTS_PREFIX) ? sourceDocument : { | ||
...sourceDocument, | ||
_id: "".concat(DRAFTS_PREFIX, ".").concat(sourceDocument._id, "}") | ||
}); | ||
cachedDocument = getCachedDocument( | ||
sourceDocument._id.startsWith(DRAFTS_PREFIX) ? sourceDocument : { ...sourceDocument, _id: "".concat(DRAFTS_PREFIX, ".").concat(sourceDocument._id, "}") } | ||
); | ||
if (!cachedDocument) { | ||
cachedDocument = getCachedDocument(sourceDocument._id.startsWith(DRAFTS_PREFIX) ? { | ||
...sourceDocument, | ||
_id: getPublishedId(sourceDocument._id) | ||
} : sourceDocument); | ||
cachedDocument = getCachedDocument( | ||
sourceDocument._id.startsWith(DRAFTS_PREFIX) ? { ...sourceDocument, _id: getPublishedId(sourceDocument._id) } : sourceDocument | ||
); | ||
} | ||
@@ -72,8 +67,5 @@ if (cachedDocument) { | ||
} | ||
function resolvedKeyedSourcePath(options) { | ||
const { | ||
keyedResultPath, | ||
pathSuffix, | ||
sourceBasePath | ||
} = options; | ||
const { keyedResultPath, pathSuffix, sourceBasePath } = options; | ||
const inferredResultPath = pathSuffix === void 0 ? [] : parseJsonPath(pathSuffix); | ||
@@ -84,7 +76,5 @@ const inferredPath = keyedResultPath.slice(keyedResultPath.length - inferredResultPath.length); | ||
} | ||
function resolveEditUrl(options) { | ||
const { | ||
resultSourceMap, | ||
studioUrl | ||
} = options; | ||
const { resultSourceMap, studioUrl } = options; | ||
const resultPath = studioPathToJsonPath(options.resultPath); | ||
@@ -101,3 +91,4 @@ const editInfo = resolveEditInfo({ | ||
} | ||
export { applySourceDocuments, createEditUrl, getPublishedId, jsonPath, parseJsonPath, resolveEditInfo, resolveEditUrl, resolveMapping, resolvedKeyedSourcePath, studioPathToJsonPath, walkMap }; | ||
//# sourceMappingURL=csm.js.map |
@@ -1,4 +0,5 @@ | ||
import { printNoDefaultExport, defineCreateClientExports, SanityClient, envMiddleware } from './_chunks/browserMiddleware-eLzHI4Fk.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/browserMiddleware-eLzHI4Fk.js'; | ||
import { printNoDefaultExport, defineCreateClientExports, SanityClient, envMiddleware } from './_chunks/browserMiddleware-heyg-fDk.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/browserMiddleware-heyg-fDk.js'; | ||
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it'; | ||
function defineDeprecatedCreateClient(createClient) { | ||
@@ -10,2 +11,3 @@ return function deprecatedCreateClient(config) { | ||
} | ||
const exp = defineCreateClientExports(envMiddleware, SanityClient); | ||
@@ -15,3 +17,4 @@ const requester = exp.requester; | ||
const deprecatedCreateClient = defineDeprecatedCreateClient(createClient); | ||
export { SanityClient, createClient, deprecatedCreateClient as default, requester }; | ||
//# sourceMappingURL=index.browser.js.map |
@@ -1,4 +0,5 @@ | ||
import { printNoDefaultExport, defineCreateClientExports, SanityClient, middleware } from './_chunks/nodeMiddleware-9L9Lk6DW.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-9L9Lk6DW.js'; | ||
import { printNoDefaultExport, defineCreateClientExports, SanityClient, middleware } from './_chunks/nodeMiddleware-u_fUUnxa.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-u_fUUnxa.js'; | ||
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it'; | ||
function defineDeprecatedCreateClient(createClient) { | ||
@@ -10,2 +11,3 @@ return function deprecatedCreateClient(config) { | ||
} | ||
const exp = defineCreateClientExports(middleware, SanityClient); | ||
@@ -15,3 +17,4 @@ const requester = exp.requester; | ||
const deprecatedCreateClient = defineDeprecatedCreateClient(createClient); | ||
export { SanityClient, createClient, deprecatedCreateClient as default, requester }; | ||
//# sourceMappingURL=index.js.map |
@@ -1,21 +0,14 @@ | ||
import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, envMiddleware } from './_chunks/browserMiddleware-eLzHI4Fk.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/browserMiddleware-eLzHI4Fk.js'; | ||
import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, envMiddleware } from './_chunks/browserMiddleware-heyg-fDk.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/browserMiddleware-heyg-fDk.js'; | ||
import { map } from 'rxjs/operators'; | ||
import { vercelStegaCombine, vercelStegaSplit } from '@vercel/stega'; | ||
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it'; | ||
const defaultStegaConfig = { | ||
enabled: false, | ||
filter: props => props.filterDefault(props) | ||
filter: (props) => props.filterDefault(props) | ||
}; | ||
function splitConfig(config) { | ||
const { | ||
stega = {}, | ||
...clientConfig | ||
} = config; | ||
return { | ||
clientConfig, | ||
stegaConfig: typeof stega === "boolean" ? { | ||
enabled: stega | ||
} : stega | ||
}; | ||
const { stega = {}, ...clientConfig } = config; | ||
return { clientConfig, stegaConfig: typeof stega === "boolean" ? { enabled: stega } : stega }; | ||
} | ||
@@ -26,6 +19,10 @@ const initStegaConfig = (config, prevConfig) => { | ||
if ("encodeSourceMap" in newConfig) { | ||
throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client/stega'. Did you mean 'enabled'?"); | ||
throw new Error( | ||
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client/stega'. Did you mean 'enabled'?" | ||
); | ||
} | ||
if ("encodeSourceMapAtPath" in newConfig) { | ||
throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client/stega'. Did you mean 'filter'?"); | ||
throw new Error( | ||
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client/stega'. Did you mean 'filter'?" | ||
); | ||
} | ||
@@ -39,3 +36,5 @@ if (typeof newConfig.enabled !== "boolean") { | ||
if (newConfig.enabled && typeof newConfig.studioUrl !== "string" && typeof newConfig.studioUrl !== "function") { | ||
throw new Error("config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl)); | ||
throw new Error( | ||
"config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl) | ||
); | ||
} | ||
@@ -45,14 +44,10 @@ return newConfig; | ||
function splitStegaConfigFromFetchOptions(options, initializedStegaConfig) { | ||
const { | ||
stega = {}, | ||
...fetchOptions | ||
} = options; | ||
const stegaConfig = initStegaConfig(typeof stega === "boolean" ? { | ||
enabled: stega | ||
} : stega, initializedStegaConfig); | ||
return { | ||
fetchOptions, | ||
stegaConfig | ||
}; | ||
const { stega = {}, ...fetchOptions } = options; | ||
const stegaConfig = initStegaConfig( | ||
typeof stega === "boolean" ? { enabled: stega } : stega, | ||
initializedStegaConfig | ||
); | ||
return { fetchOptions, stegaConfig }; | ||
} | ||
const DRAFTS_PREFIX = "drafts."; | ||
@@ -65,2 +60,3 @@ function getPublishedId(id) { | ||
} | ||
const reKeySegment = /_key\s*==\s*['"](.*)['"]/; | ||
@@ -96,2 +92,3 @@ function isKeySegment(segment) { | ||
} | ||
const ESCAPE = { | ||
@@ -114,5 +111,5 @@ "\f": "\\f", | ||
function jsonPath(path) { | ||
return "$".concat(path.map(segment => { | ||
return "$".concat(path.map((segment) => { | ||
if (typeof segment === "string") { | ||
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, match => { | ||
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, (match) => { | ||
return ESCAPE[match]; | ||
@@ -126,3 +123,3 @@ }); | ||
if (segment._key !== "") { | ||
const escapedKey = segment._key.replace(/['\\]/g, match => { | ||
const escapedKey = segment._key.replace(/['\\]/g, (match) => { | ||
return ESCAPE[match]; | ||
@@ -141,3 +138,3 @@ }); | ||
if (match[1] !== void 0) { | ||
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, m => { | ||
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, (m) => { | ||
return UNESCAPE[m]; | ||
@@ -153,3 +150,3 @@ }); | ||
if (match[3] !== void 0) { | ||
const _key = match[3].replace(/\\(\\')/g, m => { | ||
const _key = match[3].replace(/\\(\\')/g, (m) => { | ||
return UNESCAPE[m]; | ||
@@ -167,3 +164,3 @@ }); | ||
function jsonPathToStudioPath(path) { | ||
return path.map(segment => { | ||
return path.map((segment) => { | ||
if (typeof segment === "string") { | ||
@@ -176,5 +173,3 @@ return segment; | ||
if (segment._key !== "") { | ||
return { | ||
_key: segment._key | ||
}; | ||
return { _key: segment._key }; | ||
} | ||
@@ -188,3 +183,3 @@ if (segment._index !== -1) { | ||
function jsonPathToMappingPath(path) { | ||
return path.map(segment => { | ||
return path.map((segment) => { | ||
if (typeof segment === "string") { | ||
@@ -202,2 +197,3 @@ return segment; | ||
} | ||
function createEditUrl(options) { | ||
@@ -244,3 +240,8 @@ const { | ||
} | ||
const routerParams = ["mode=presentation", "id=".concat(id), "type=".concat(type), "path=".concat(encodeURIComponent(stringifiedPath))]; | ||
const routerParams = [ | ||
"mode=presentation", | ||
"id=".concat(id), | ||
"type=".concat(type), | ||
"path=".concat(encodeURIComponent(stringifiedPath)) | ||
]; | ||
if (tool) { | ||
@@ -252,2 +253,3 @@ routerParams.push("tool=".concat(tool)); | ||
} | ||
function resolveMapping(resultPath, csm) { | ||
@@ -265,10 +267,3 @@ if (!(csm == null ? void 0 : csm.mappings)) { | ||
} | ||
const mappings = Object.entries(csm.mappings).filter(_ref => { | ||
let [key] = _ref; | ||
return resultMappingPath.startsWith(key); | ||
}).sort((_ref2, _ref3) => { | ||
let [key1] = _ref2; | ||
let [key2] = _ref3; | ||
return key2.length - key1.length; | ||
}); | ||
const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length); | ||
if (mappings.length == 0) { | ||
@@ -279,8 +274,5 @@ return void 0; | ||
const pathSuffix = resultMappingPath.substring(matchedPath.length); | ||
return { | ||
mapping, | ||
matchedPath, | ||
pathSuffix | ||
}; | ||
return { mapping, matchedPath, pathSuffix }; | ||
} | ||
function resolveStudioBaseRoute(studioUrl) { | ||
@@ -292,19 +284,16 @@ let baseUrl = typeof studioUrl === "string" ? studioUrl : studioUrl.baseUrl; | ||
if (typeof studioUrl === "string") { | ||
return { | ||
baseUrl | ||
}; | ||
return { baseUrl }; | ||
} | ||
return { | ||
...studioUrl, | ||
baseUrl | ||
}; | ||
return { ...studioUrl, baseUrl }; | ||
} | ||
function isArray(value) { | ||
return value !== null && Array.isArray(value); | ||
} | ||
function isRecord(value) { | ||
return typeof value === "object" && value !== null; | ||
} | ||
function walkMap(value, mappingFn) { | ||
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
function walkMap(value, mappingFn, path = []) { | ||
if (isArray(value)) { | ||
@@ -315,6 +304,3 @@ return value.map((v, idx) => { | ||
if (typeof _key === "string") { | ||
return walkMap(v, mappingFn, path.concat({ | ||
_key, | ||
_index: idx | ||
})); | ||
return walkMap(v, mappingFn, path.concat({ _key, _index: idx })); | ||
} | ||
@@ -326,9 +312,9 @@ } | ||
if (isRecord(value)) { | ||
return Object.fromEntries(Object.entries(value).map(_ref4 => { | ||
let [k, v] = _ref4; | ||
return [k, walkMap(v, mappingFn, path.concat(k))]; | ||
})); | ||
return Object.fromEntries( | ||
Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))]) | ||
); | ||
} | ||
return mappingFn(value, path); | ||
} | ||
function encodeIntoResult(result, csm, encoder) { | ||
@@ -343,6 +329,3 @@ return walkMap(result, (value, path) => { | ||
} | ||
const { | ||
mapping, | ||
matchedPath | ||
} = resolveMappingResult; | ||
const { mapping, matchedPath } = resolveMappingResult; | ||
if (mapping.type !== "value") { | ||
@@ -367,7 +350,4 @@ return value; | ||
} | ||
const filterDefault = _ref5 => { | ||
let { | ||
sourcePath, | ||
value | ||
} = _ref5; | ||
const filterDefault = ({ sourcePath, value }) => { | ||
if (isValidDate(value) || isValidURL(value)) { | ||
@@ -392,3 +372,5 @@ return false; | ||
} | ||
if (sourcePath.some(path => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo")) { | ||
if (sourcePath.some( | ||
(path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo" | ||
)) { | ||
return false; | ||
@@ -401,3 +383,42 @@ } | ||
}; | ||
const denylist = /* @__PURE__ */new Set(["color", "colour", "currency", "email", "format", "gid", "hex", "href", "hsl", "hsla", "icon", "id", "index", "key", "language", "layout", "link", "linkAction", "locale", "lqip", "page", "path", "ref", "rgb", "rgba", "route", "secret", "slug", "status", "tag", "template", "theme", "type", "unit", "url", "username", "variant", "website"]); | ||
const denylist = /* @__PURE__ */ new Set([ | ||
"color", | ||
"colour", | ||
"currency", | ||
"email", | ||
"format", | ||
"gid", | ||
"hex", | ||
"href", | ||
"hsl", | ||
"hsla", | ||
"icon", | ||
"id", | ||
"index", | ||
"key", | ||
"language", | ||
"layout", | ||
"link", | ||
"linkAction", | ||
"locale", | ||
"lqip", | ||
"page", | ||
"path", | ||
"ref", | ||
"rgb", | ||
"rgba", | ||
"route", | ||
"secret", | ||
"slug", | ||
"status", | ||
"tag", | ||
"template", | ||
"theme", | ||
"type", | ||
"unit", | ||
"url", | ||
"username", | ||
"variant", | ||
"website" | ||
]); | ||
function isValidDate(dateString) { | ||
@@ -414,17 +435,10 @@ return Number.isNaN(Number(dateString)) ? Boolean(Date.parse(dateString)) : false; | ||
} | ||
const TRUNCATE_LENGTH = 20; | ||
function stegaEncodeSourceMap(result, resultSourceMap, config) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i; | ||
const { | ||
filter, | ||
logger, | ||
enabled | ||
} = config; | ||
const { filter, logger, enabled } = config; | ||
if (!enabled) { | ||
const msg = "config.enabled must be true, don't call this function otherwise"; | ||
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { | ||
result, | ||
resultSourceMap, | ||
config | ||
}); | ||
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config }); | ||
throw new TypeError(msg); | ||
@@ -442,7 +456,3 @@ } | ||
const msg = "config.studioUrl must be defined"; | ||
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { | ||
result, | ||
resultSourceMap, | ||
config | ||
}); | ||
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config }); | ||
throw new TypeError(msg); | ||
@@ -454,24 +464,18 @@ } | ||
}; | ||
const resultWithStega = encodeIntoResult(result, resultSourceMap, _ref6 => { | ||
let { | ||
sourcePath, | ||
sourceDocument, | ||
resultPath, | ||
value | ||
} = _ref6; | ||
if ((typeof filter === "function" ? filter({ | ||
sourcePath, | ||
resultPath, | ||
filterDefault, | ||
sourceDocument, | ||
value | ||
}) : filterDefault({ | ||
sourcePath, | ||
resultPath, | ||
filterDefault, | ||
sourceDocument, | ||
value | ||
})) === false) { | ||
const resultWithStega = encodeIntoResult( | ||
result, | ||
resultSourceMap, | ||
({ sourcePath, sourceDocument, resultPath, value }) => { | ||
if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) { | ||
if (logger) { | ||
report.skipped.push({ | ||
path: prettyPathForLogging(sourcePath), | ||
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""), | ||
length: value.length | ||
}); | ||
} | ||
return value; | ||
} | ||
if (logger) { | ||
report.skipped.push({ | ||
report.encoded.push({ | ||
path: prettyPathForLogging(sourcePath), | ||
@@ -482,35 +486,26 @@ value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""), | ||
} | ||
return value; | ||
const { baseUrl, workspace, tool } = resolveStudioBaseRoute( | ||
typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl | ||
); | ||
if (!baseUrl) | ||
return value; | ||
const { _id: id, _type: type } = sourceDocument; | ||
return vercelStegaCombine( | ||
value, | ||
{ | ||
origin: "sanity.io", | ||
href: createEditUrl({ | ||
baseUrl, | ||
workspace, | ||
tool, | ||
id, | ||
type, | ||
path: sourcePath | ||
}) | ||
}, | ||
// We use custom logic to determine if we should skip encoding | ||
false | ||
); | ||
} | ||
if (logger) { | ||
report.encoded.push({ | ||
path: prettyPathForLogging(sourcePath), | ||
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""), | ||
length: value.length | ||
}); | ||
} | ||
const { | ||
baseUrl, | ||
workspace, | ||
tool | ||
} = resolveStudioBaseRoute(typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl); | ||
if (!baseUrl) return value; | ||
const { | ||
_id: id, | ||
_type: type | ||
} = sourceDocument; | ||
return vercelStegaCombine(value, { | ||
origin: "sanity.io", | ||
href: createEditUrl({ | ||
baseUrl, | ||
workspace, | ||
tool, | ||
id, | ||
type, | ||
path: sourcePath | ||
}) | ||
}, | ||
// We use custom logic to determine if we should skip encoding | ||
false); | ||
}); | ||
); | ||
if (logger) { | ||
@@ -520,4 +515,9 @@ const isSkipping = report.skipped.length; | ||
if (isSkipping || isEncoding) { | ||
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d("[@sanity/client/stega]: Encoding source map into result"); | ||
(_e = logger.log) == null ? void 0 : _e.call(logger, "[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length)); | ||
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d( | ||
"[@sanity/client/stega]: Encoding source map into result" | ||
); | ||
(_e = logger.log) == null ? void 0 : _e.call( | ||
logger, | ||
"[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length) | ||
); | ||
} | ||
@@ -529,6 +529,4 @@ if (report.encoded.length > 0) { | ||
if (report.skipped.length > 0) { | ||
const skipped = /* @__PURE__ */new Set(); | ||
for (const { | ||
path | ||
} of report.skipped) { | ||
const skipped = /* @__PURE__ */ new Set(); | ||
for (const { path } of report.skipped) { | ||
skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]")); | ||
@@ -547,8 +545,12 @@ } | ||
} | ||
function vercelStegaCleanAll(result) { | ||
try { | ||
return JSON.parse(JSON.stringify(result, (key, value) => { | ||
if (typeof value !== "string") return value; | ||
return vercelStegaSplit(value).cleaned; | ||
})); | ||
return JSON.parse( | ||
JSON.stringify(result, (key, value) => { | ||
if (typeof value !== "string") | ||
return value; | ||
return vercelStegaSplit(value).cleaned; | ||
}) | ||
); | ||
} catch { | ||
@@ -558,4 +560,6 @@ return result; | ||
} | ||
var __accessCheck = (obj, member, msg) => { | ||
if (!member.has(obj)) throw TypeError("Cannot " + msg); | ||
if (!member.has(obj)) | ||
throw TypeError("Cannot " + msg); | ||
}; | ||
@@ -567,3 +571,4 @@ var __privateGet = (obj, member, getter) => { | ||
var __privateAdd = (obj, member, value) => { | ||
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); | ||
if (member.has(obj)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
@@ -578,8 +583,4 @@ }; | ||
const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends ObservableSanityClient { | ||
constructor(httpRequest) { | ||
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig; | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(config); | ||
constructor(httpRequest, config = defaultConfig) { | ||
const { clientConfig, stegaConfig } = splitConfig(config); | ||
super(httpRequest, clientConfig); | ||
@@ -601,13 +602,5 @@ /** | ||
if (newConfig === void 0) { | ||
return { | ||
...super.config(), | ||
stega: { | ||
...this.stegaConfig | ||
} | ||
}; | ||
return { ...super.config(), stega: { ...this.stegaConfig } }; | ||
} | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(newConfig); | ||
const { clientConfig, stegaConfig } = splitConfig(newConfig); | ||
super.config(clientConfig); | ||
@@ -624,5 +617,3 @@ this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {}); | ||
const thisConfig = this.config(); | ||
const { | ||
stegaConfig | ||
} = splitConfig(newConfig || {}); | ||
const { stegaConfig } = splitConfig(newConfig || {}); | ||
return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), { | ||
@@ -632,13 +623,12 @@ ...thisConfig, | ||
stega: { | ||
...(thisConfig.stega || {}), | ||
...(stegaConfig || {}) | ||
...thisConfig.stega || {}, | ||
...stegaConfig || {} | ||
} | ||
}); | ||
} | ||
fetch(query, _params) { | ||
let _options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const { | ||
stegaConfig, | ||
fetchOptions: options | ||
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig); | ||
fetch(query, _params, _options = {}) { | ||
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions( | ||
_options, | ||
this.stegaConfig | ||
); | ||
const params = _params ? vercelStegaCleanAll(_params) : _params; | ||
@@ -648,19 +638,17 @@ if (!stegaConfig.enabled) { | ||
} | ||
const { | ||
filterResponse: originalFilterResponse = true | ||
} = options; | ||
return super.fetch(query, params, Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
})).pipe(map(res => { | ||
const { | ||
result: _result, | ||
resultSourceMap | ||
} = res; | ||
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig); | ||
return originalFilterResponse ? result : { | ||
...res, | ||
result | ||
}; | ||
})); | ||
const { filterResponse: originalFilterResponse = true } = options; | ||
return super.fetch( | ||
query, | ||
params, | ||
Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
}) | ||
).pipe( | ||
map((res) => { | ||
const { result: _result, resultSourceMap } = res; | ||
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig); | ||
return originalFilterResponse ? result : { ...res, result }; | ||
}) | ||
); | ||
} | ||
@@ -671,8 +659,4 @@ }; | ||
const _SanityStegaClient = class _SanityStegaClient extends SanityClient { | ||
constructor(httpRequest) { | ||
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig; | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(config); | ||
constructor(httpRequest, config = defaultConfig) { | ||
const { clientConfig, stegaConfig } = splitConfig(config); | ||
super(httpRequest, clientConfig); | ||
@@ -695,17 +679,7 @@ /** | ||
if (newConfig === void 0) { | ||
return { | ||
...super.config(), | ||
stega: { | ||
...this.stegaConfig | ||
} | ||
}; | ||
return { ...super.config(), stega: { ...this.stegaConfig } }; | ||
} | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(newConfig); | ||
const { clientConfig, stegaConfig } = splitConfig(newConfig); | ||
super.config(clientConfig); | ||
this.stegaConfig = initStegaConfig(stegaConfig, { | ||
...(this.stegaConfig || {}) | ||
}); | ||
this.stegaConfig = initStegaConfig(stegaConfig, { ...this.stegaConfig || {} }); | ||
return this; | ||
@@ -720,5 +694,3 @@ } | ||
const thisConfig = this.config(); | ||
const { | ||
stegaConfig | ||
} = splitConfig(newConfig || {}); | ||
const { stegaConfig } = splitConfig(newConfig || {}); | ||
return new _SanityStegaClient(__privateGet(this, _httpRequest2), { | ||
@@ -728,13 +700,12 @@ ...thisConfig, | ||
stega: { | ||
...(thisConfig.stega || {}), | ||
...(stegaConfig || {}) | ||
...thisConfig.stega || {}, | ||
...stegaConfig || {} | ||
} | ||
}); | ||
} | ||
fetch(query, _params) { | ||
let _options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const { | ||
stegaConfig, | ||
fetchOptions: options | ||
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig); | ||
fetch(query, _params, _options = {}) { | ||
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions( | ||
_options, | ||
this.stegaConfig | ||
); | ||
const params = _params ? vercelStegaCleanAll(_params) : _params; | ||
@@ -744,18 +715,14 @@ if (!stegaConfig.enabled) { | ||
} | ||
const { | ||
filterResponse: originalFilterResponse = true | ||
} = options; | ||
return super.fetch(query, params, Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
})).then(res => { | ||
const { | ||
result: _result, | ||
resultSourceMap | ||
} = res; | ||
const { filterResponse: originalFilterResponse = true } = options; | ||
return super.fetch( | ||
query, | ||
params, | ||
Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
}) | ||
).then((res) => { | ||
const { result: _result, resultSourceMap } = res; | ||
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig); | ||
return originalFilterResponse ? result : { | ||
...res, | ||
result | ||
}; | ||
return originalFilterResponse ? result : { ...res, result }; | ||
}); | ||
@@ -766,6 +733,11 @@ } | ||
let SanityStegaClient = _SanityStegaClient; | ||
const exp = defineCreateClientExports(envMiddleware, SanityStegaClient); | ||
const exp = defineCreateClientExports( | ||
envMiddleware, | ||
SanityStegaClient | ||
); | ||
const requester = exp.requester; | ||
const createClient = exp.createClient; | ||
export { ObservableSanityClient, ObservableSanityStegaClient, SanityClient, SanityStegaClient, createClient, encodeIntoResult, requester, stegaEncodeSourceMap, vercelStegaCleanAll }; | ||
//# sourceMappingURL=stega.browser.js.map |
@@ -1,22 +0,15 @@ | ||
import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, middleware } from './_chunks/nodeMiddleware-9L9Lk6DW.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-9L9Lk6DW.js'; | ||
import { ObservableSanityClient, defaultConfig, SanityClient, defineCreateClientExports, middleware } from './_chunks/nodeMiddleware-u_fUUnxa.js'; | ||
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableTransaction, Patch, ServerError, Transaction } from './_chunks/nodeMiddleware-u_fUUnxa.js'; | ||
import { map } from 'rxjs/operators'; | ||
import { vercelStegaCombine, vercelStegaSplit } from '@vercel/stega'; | ||
import { walkMap, resolveMapping, parseJsonPath, resolveStudioBaseRoute, createEditUrl, reKeySegment, toString, jsonPathToStudioPath } from './_chunks/resolveEditInfo-FaeuCV4M.js'; | ||
import { walkMap, resolveMapping, parseJsonPath, resolveStudioBaseRoute, createEditUrl, reKeySegment, toString, jsonPathToStudioPath } from './_chunks/resolveEditInfo-uXvm6eWd.js'; | ||
export { adapter as unstable__adapter, environment as unstable__environment } from 'get-it'; | ||
const defaultStegaConfig = { | ||
enabled: false, | ||
filter: props => props.filterDefault(props) | ||
filter: (props) => props.filterDefault(props) | ||
}; | ||
function splitConfig(config) { | ||
const { | ||
stega = {}, | ||
...clientConfig | ||
} = config; | ||
return { | ||
clientConfig, | ||
stegaConfig: typeof stega === "boolean" ? { | ||
enabled: stega | ||
} : stega | ||
}; | ||
const { stega = {}, ...clientConfig } = config; | ||
return { clientConfig, stegaConfig: typeof stega === "boolean" ? { enabled: stega } : stega }; | ||
} | ||
@@ -27,6 +20,10 @@ const initStegaConfig = (config, prevConfig) => { | ||
if ("encodeSourceMap" in newConfig) { | ||
throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client/stega'. Did you mean 'enabled'?"); | ||
throw new Error( | ||
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMap' is not supported in '@sanity/client/stega'. Did you mean 'enabled'?" | ||
); | ||
} | ||
if ("encodeSourceMapAtPath" in newConfig) { | ||
throw new Error("It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client/stega'. Did you mean 'filter'?"); | ||
throw new Error( | ||
"It looks like you're using options meant for '@sanity/preview-kit/client'. 'encodeSourceMapAtPath' is not supported in '@sanity/client/stega'. Did you mean 'filter'?" | ||
); | ||
} | ||
@@ -40,3 +37,5 @@ if (typeof newConfig.enabled !== "boolean") { | ||
if (newConfig.enabled && typeof newConfig.studioUrl !== "string" && typeof newConfig.studioUrl !== "function") { | ||
throw new Error("config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl)); | ||
throw new Error( | ||
"config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl) | ||
); | ||
} | ||
@@ -46,14 +45,10 @@ return newConfig; | ||
function splitStegaConfigFromFetchOptions(options, initializedStegaConfig) { | ||
const { | ||
stega = {}, | ||
...fetchOptions | ||
} = options; | ||
const stegaConfig = initStegaConfig(typeof stega === "boolean" ? { | ||
enabled: stega | ||
} : stega, initializedStegaConfig); | ||
return { | ||
fetchOptions, | ||
stegaConfig | ||
}; | ||
const { stega = {}, ...fetchOptions } = options; | ||
const stegaConfig = initStegaConfig( | ||
typeof stega === "boolean" ? { enabled: stega } : stega, | ||
initializedStegaConfig | ||
); | ||
return { fetchOptions, stegaConfig }; | ||
} | ||
function encodeIntoResult(result, csm, encoder) { | ||
@@ -68,6 +63,3 @@ return walkMap(result, (value, path) => { | ||
} | ||
const { | ||
mapping, | ||
matchedPath | ||
} = resolveMappingResult; | ||
const { mapping, matchedPath } = resolveMappingResult; | ||
if (mapping.type !== "value") { | ||
@@ -92,7 +84,4 @@ return value; | ||
} | ||
const filterDefault = _ref => { | ||
let { | ||
sourcePath, | ||
value | ||
} = _ref; | ||
const filterDefault = ({ sourcePath, value }) => { | ||
if (isValidDate(value) || isValidURL(value)) { | ||
@@ -117,3 +106,5 @@ return false; | ||
} | ||
if (sourcePath.some(path => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo")) { | ||
if (sourcePath.some( | ||
(path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo" | ||
)) { | ||
return false; | ||
@@ -126,3 +117,42 @@ } | ||
}; | ||
const denylist = /* @__PURE__ */new Set(["color", "colour", "currency", "email", "format", "gid", "hex", "href", "hsl", "hsla", "icon", "id", "index", "key", "language", "layout", "link", "linkAction", "locale", "lqip", "page", "path", "ref", "rgb", "rgba", "route", "secret", "slug", "status", "tag", "template", "theme", "type", "unit", "url", "username", "variant", "website"]); | ||
const denylist = /* @__PURE__ */ new Set([ | ||
"color", | ||
"colour", | ||
"currency", | ||
"email", | ||
"format", | ||
"gid", | ||
"hex", | ||
"href", | ||
"hsl", | ||
"hsla", | ||
"icon", | ||
"id", | ||
"index", | ||
"key", | ||
"language", | ||
"layout", | ||
"link", | ||
"linkAction", | ||
"locale", | ||
"lqip", | ||
"page", | ||
"path", | ||
"ref", | ||
"rgb", | ||
"rgba", | ||
"route", | ||
"secret", | ||
"slug", | ||
"status", | ||
"tag", | ||
"template", | ||
"theme", | ||
"type", | ||
"unit", | ||
"url", | ||
"username", | ||
"variant", | ||
"website" | ||
]); | ||
function isValidDate(dateString) { | ||
@@ -139,17 +169,10 @@ return Number.isNaN(Number(dateString)) ? Boolean(Date.parse(dateString)) : false; | ||
} | ||
const TRUNCATE_LENGTH = 20; | ||
function stegaEncodeSourceMap(result, resultSourceMap, config) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i; | ||
const { | ||
filter, | ||
logger, | ||
enabled | ||
} = config; | ||
const { filter, logger, enabled } = config; | ||
if (!enabled) { | ||
const msg = "config.enabled must be true, don't call this function otherwise"; | ||
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { | ||
result, | ||
resultSourceMap, | ||
config | ||
}); | ||
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config }); | ||
throw new TypeError(msg); | ||
@@ -167,7 +190,3 @@ } | ||
const msg = "config.studioUrl must be defined"; | ||
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { | ||
result, | ||
resultSourceMap, | ||
config | ||
}); | ||
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config }); | ||
throw new TypeError(msg); | ||
@@ -179,24 +198,18 @@ } | ||
}; | ||
const resultWithStega = encodeIntoResult(result, resultSourceMap, _ref2 => { | ||
let { | ||
sourcePath, | ||
sourceDocument, | ||
resultPath, | ||
value | ||
} = _ref2; | ||
if ((typeof filter === "function" ? filter({ | ||
sourcePath, | ||
resultPath, | ||
filterDefault, | ||
sourceDocument, | ||
value | ||
}) : filterDefault({ | ||
sourcePath, | ||
resultPath, | ||
filterDefault, | ||
sourceDocument, | ||
value | ||
})) === false) { | ||
const resultWithStega = encodeIntoResult( | ||
result, | ||
resultSourceMap, | ||
({ sourcePath, sourceDocument, resultPath, value }) => { | ||
if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) { | ||
if (logger) { | ||
report.skipped.push({ | ||
path: prettyPathForLogging(sourcePath), | ||
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""), | ||
length: value.length | ||
}); | ||
} | ||
return value; | ||
} | ||
if (logger) { | ||
report.skipped.push({ | ||
report.encoded.push({ | ||
path: prettyPathForLogging(sourcePath), | ||
@@ -207,35 +220,26 @@ value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""), | ||
} | ||
return value; | ||
const { baseUrl, workspace, tool } = resolveStudioBaseRoute( | ||
typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl | ||
); | ||
if (!baseUrl) | ||
return value; | ||
const { _id: id, _type: type } = sourceDocument; | ||
return vercelStegaCombine( | ||
value, | ||
{ | ||
origin: "sanity.io", | ||
href: createEditUrl({ | ||
baseUrl, | ||
workspace, | ||
tool, | ||
id, | ||
type, | ||
path: sourcePath | ||
}) | ||
}, | ||
// We use custom logic to determine if we should skip encoding | ||
false | ||
); | ||
} | ||
if (logger) { | ||
report.encoded.push({ | ||
path: prettyPathForLogging(sourcePath), | ||
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""), | ||
length: value.length | ||
}); | ||
} | ||
const { | ||
baseUrl, | ||
workspace, | ||
tool | ||
} = resolveStudioBaseRoute(typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl); | ||
if (!baseUrl) return value; | ||
const { | ||
_id: id, | ||
_type: type | ||
} = sourceDocument; | ||
return vercelStegaCombine(value, { | ||
origin: "sanity.io", | ||
href: createEditUrl({ | ||
baseUrl, | ||
workspace, | ||
tool, | ||
id, | ||
type, | ||
path: sourcePath | ||
}) | ||
}, | ||
// We use custom logic to determine if we should skip encoding | ||
false); | ||
}); | ||
); | ||
if (logger) { | ||
@@ -245,4 +249,9 @@ const isSkipping = report.skipped.length; | ||
if (isSkipping || isEncoding) { | ||
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d("[@sanity/client/stega]: Encoding source map into result"); | ||
(_e = logger.log) == null ? void 0 : _e.call(logger, "[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length)); | ||
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d( | ||
"[@sanity/client/stega]: Encoding source map into result" | ||
); | ||
(_e = logger.log) == null ? void 0 : _e.call( | ||
logger, | ||
"[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length) | ||
); | ||
} | ||
@@ -254,6 +263,4 @@ if (report.encoded.length > 0) { | ||
if (report.skipped.length > 0) { | ||
const skipped = /* @__PURE__ */new Set(); | ||
for (const { | ||
path | ||
} of report.skipped) { | ||
const skipped = /* @__PURE__ */ new Set(); | ||
for (const { path } of report.skipped) { | ||
skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]")); | ||
@@ -272,8 +279,12 @@ } | ||
} | ||
function vercelStegaCleanAll(result) { | ||
try { | ||
return JSON.parse(JSON.stringify(result, (key, value) => { | ||
if (typeof value !== "string") return value; | ||
return vercelStegaSplit(value).cleaned; | ||
})); | ||
return JSON.parse( | ||
JSON.stringify(result, (key, value) => { | ||
if (typeof value !== "string") | ||
return value; | ||
return vercelStegaSplit(value).cleaned; | ||
}) | ||
); | ||
} catch { | ||
@@ -283,4 +294,6 @@ return result; | ||
} | ||
var __accessCheck = (obj, member, msg) => { | ||
if (!member.has(obj)) throw TypeError("Cannot " + msg); | ||
if (!member.has(obj)) | ||
throw TypeError("Cannot " + msg); | ||
}; | ||
@@ -292,3 +305,4 @@ var __privateGet = (obj, member, getter) => { | ||
var __privateAdd = (obj, member, value) => { | ||
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); | ||
if (member.has(obj)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
@@ -303,8 +317,4 @@ }; | ||
const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends ObservableSanityClient { | ||
constructor(httpRequest) { | ||
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig; | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(config); | ||
constructor(httpRequest, config = defaultConfig) { | ||
const { clientConfig, stegaConfig } = splitConfig(config); | ||
super(httpRequest, clientConfig); | ||
@@ -326,13 +336,5 @@ /** | ||
if (newConfig === void 0) { | ||
return { | ||
...super.config(), | ||
stega: { | ||
...this.stegaConfig | ||
} | ||
}; | ||
return { ...super.config(), stega: { ...this.stegaConfig } }; | ||
} | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(newConfig); | ||
const { clientConfig, stegaConfig } = splitConfig(newConfig); | ||
super.config(clientConfig); | ||
@@ -349,5 +351,3 @@ this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {}); | ||
const thisConfig = this.config(); | ||
const { | ||
stegaConfig | ||
} = splitConfig(newConfig || {}); | ||
const { stegaConfig } = splitConfig(newConfig || {}); | ||
return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), { | ||
@@ -357,13 +357,12 @@ ...thisConfig, | ||
stega: { | ||
...(thisConfig.stega || {}), | ||
...(stegaConfig || {}) | ||
...thisConfig.stega || {}, | ||
...stegaConfig || {} | ||
} | ||
}); | ||
} | ||
fetch(query, _params) { | ||
let _options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const { | ||
stegaConfig, | ||
fetchOptions: options | ||
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig); | ||
fetch(query, _params, _options = {}) { | ||
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions( | ||
_options, | ||
this.stegaConfig | ||
); | ||
const params = _params ? vercelStegaCleanAll(_params) : _params; | ||
@@ -373,19 +372,17 @@ if (!stegaConfig.enabled) { | ||
} | ||
const { | ||
filterResponse: originalFilterResponse = true | ||
} = options; | ||
return super.fetch(query, params, Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
})).pipe(map(res => { | ||
const { | ||
result: _result, | ||
resultSourceMap | ||
} = res; | ||
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig); | ||
return originalFilterResponse ? result : { | ||
...res, | ||
result | ||
}; | ||
})); | ||
const { filterResponse: originalFilterResponse = true } = options; | ||
return super.fetch( | ||
query, | ||
params, | ||
Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
}) | ||
).pipe( | ||
map((res) => { | ||
const { result: _result, resultSourceMap } = res; | ||
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig); | ||
return originalFilterResponse ? result : { ...res, result }; | ||
}) | ||
); | ||
} | ||
@@ -396,8 +393,4 @@ }; | ||
const _SanityStegaClient = class _SanityStegaClient extends SanityClient { | ||
constructor(httpRequest) { | ||
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig; | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(config); | ||
constructor(httpRequest, config = defaultConfig) { | ||
const { clientConfig, stegaConfig } = splitConfig(config); | ||
super(httpRequest, clientConfig); | ||
@@ -420,17 +413,7 @@ /** | ||
if (newConfig === void 0) { | ||
return { | ||
...super.config(), | ||
stega: { | ||
...this.stegaConfig | ||
} | ||
}; | ||
return { ...super.config(), stega: { ...this.stegaConfig } }; | ||
} | ||
const { | ||
clientConfig, | ||
stegaConfig | ||
} = splitConfig(newConfig); | ||
const { clientConfig, stegaConfig } = splitConfig(newConfig); | ||
super.config(clientConfig); | ||
this.stegaConfig = initStegaConfig(stegaConfig, { | ||
...(this.stegaConfig || {}) | ||
}); | ||
this.stegaConfig = initStegaConfig(stegaConfig, { ...this.stegaConfig || {} }); | ||
return this; | ||
@@ -445,5 +428,3 @@ } | ||
const thisConfig = this.config(); | ||
const { | ||
stegaConfig | ||
} = splitConfig(newConfig || {}); | ||
const { stegaConfig } = splitConfig(newConfig || {}); | ||
return new _SanityStegaClient(__privateGet(this, _httpRequest2), { | ||
@@ -453,13 +434,12 @@ ...thisConfig, | ||
stega: { | ||
...(thisConfig.stega || {}), | ||
...(stegaConfig || {}) | ||
...thisConfig.stega || {}, | ||
...stegaConfig || {} | ||
} | ||
}); | ||
} | ||
fetch(query, _params) { | ||
let _options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
const { | ||
stegaConfig, | ||
fetchOptions: options | ||
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig); | ||
fetch(query, _params, _options = {}) { | ||
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions( | ||
_options, | ||
this.stegaConfig | ||
); | ||
const params = _params ? vercelStegaCleanAll(_params) : _params; | ||
@@ -469,18 +449,14 @@ if (!stegaConfig.enabled) { | ||
} | ||
const { | ||
filterResponse: originalFilterResponse = true | ||
} = options; | ||
return super.fetch(query, params, Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
})).then(res => { | ||
const { | ||
result: _result, | ||
resultSourceMap | ||
} = res; | ||
const { filterResponse: originalFilterResponse = true } = options; | ||
return super.fetch( | ||
query, | ||
params, | ||
Object.assign({}, options, { | ||
filterResponse: false, | ||
resultSourceMap: "withKeyArraySelector" | ||
}) | ||
).then((res) => { | ||
const { result: _result, resultSourceMap } = res; | ||
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig); | ||
return originalFilterResponse ? result : { | ||
...res, | ||
result | ||
}; | ||
return originalFilterResponse ? result : { ...res, result }; | ||
}); | ||
@@ -491,6 +467,11 @@ } | ||
let SanityStegaClient = _SanityStegaClient; | ||
const exp = defineCreateClientExports(middleware, SanityStegaClient); | ||
const exp = defineCreateClientExports( | ||
middleware, | ||
SanityStegaClient | ||
); | ||
const requester = exp.requester; | ||
const createClient = exp.createClient; | ||
export { ObservableSanityClient, ObservableSanityStegaClient, SanityClient, SanityStegaClient, createClient, encodeIntoResult, requester, stegaEncodeSourceMap, vercelStegaCleanAll }; | ||
//# sourceMappingURL=stega.js.map |
{ | ||
"name": "@sanity/client", | ||
"version": "6.11.3-canary.0", | ||
"version": "6.11.3", | ||
"description": "Client for retrieving, creating and patching data from Sanity.io", | ||
@@ -133,3 +133,3 @@ "keywords": [ | ||
"@vercel/stega": "0.1.0", | ||
"get-it": "^8.4.5", | ||
"get-it": "^8.4.6", | ||
"rxjs": "^7.0.0" | ||
@@ -142,3 +142,3 @@ }, | ||
"@rollup/plugin-node-resolve": "^15.2.3", | ||
"@sanity/pkg-utils": "^3.3.8", | ||
"@sanity/pkg-utils": "^4.0.0", | ||
"@types/json-diff": "^1.0.3", | ||
@@ -145,0 +145,0 @@ "@types/node": "^20.8.8", |
@@ -139,8 +139,8 @@ import type { | ||
// Extends the `client.fetch` call with a `stega` option | ||
declare module '@sanity/client' { | ||
declare module '../types' { | ||
/** @public */ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export interface ResponseQueryOptions { | ||
export interface ResponseQueryOptions<T = 'next'> extends RequestOptions { | ||
stega?: boolean | StegaConfig | ||
} | ||
} |
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 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 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
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
0
2119174
26999
Updatedget-it@^8.4.6