@sanity/client 7.13.0 → 7.13.1
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/resolveEditInfo.cjs +11 -5
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaClean.cjs +2 -24
- package/dist/_chunks-cjs/stegaClean.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +67 -7
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +11 -5
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaClean.js +2 -24
- package/dist/_chunks-es/stegaClean.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +68 -8
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/csm/jsonPath.ts +26 -0
- package/src/csm/resolveMapping.ts +10 -10
- package/src/stega/stega.ts +163 -0
- package/src/stega/stegaEncodeSourceMap.ts +3 -4
- package/umd/sanityClient.js +72 -33
- package/umd/sanityClient.min.js +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jsonPath, jsonPathToMappingPath} from './jsonPath'
|
|
1
|
+
import {jsonPath, jsonPathArray, jsonPathToMappingPath} from './jsonPath'
|
|
2
2
|
import type {ContentSourceMap, ContentSourceMapMapping, ContentSourceMapParsedPath} from './types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -27,15 +27,15 @@ export function resolveMapping(
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const resultMappingPathArray = jsonPathArray(jsonPathToMappingPath(resultPath))
|
|
31
|
+
for (let i = resultMappingPathArray.length - 1; i > 0; i--) {
|
|
32
|
+
const key = `$${resultMappingPathArray.slice(0, i).join('')}`
|
|
33
|
+
const mappingFound = csm.mappings[key]
|
|
34
|
+
if (mappingFound) {
|
|
35
|
+
const pathSuffix = resultMappingPath.substring(key.length)
|
|
36
|
+
return {mapping: mappingFound, matchedPath: key, pathSuffix}
|
|
37
|
+
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
const pathSuffix = resultMappingPath.substring(matchedPath.length)
|
|
40
|
-
return {mapping, matchedPath, pathSuffix}
|
|
40
|
+
return undefined
|
|
41
41
|
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
// ---------- CONSTANTS ----------
|
|
3
|
+
const ZERO_WIDTHS = [
|
|
4
|
+
8203, // U+200B ZERO WIDTH SPACE
|
|
5
|
+
8204, // U+200C ZERO WIDTH NON-JOINER
|
|
6
|
+
8205, // U+200D ZERO WIDTH JOINER
|
|
7
|
+
65279, // U+FEFF ZERO WIDTH NO-BREAK SPACE
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
const ZERO_WIDTHS_CHAR_CODES = ZERO_WIDTHS.map((x) => String.fromCharCode(x))
|
|
11
|
+
|
|
12
|
+
const LEGACY_WIDTHS = [
|
|
13
|
+
8203, 8204, 8205, 8290, 8291, 8288, 65279, 8289, 119155, 119156, 119157, 119158, 119159, 119160,
|
|
14
|
+
119161, 119162,
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const ZERO_WIDTH_MAP = Object.fromEntries(ZERO_WIDTHS.map((cp, i) => [cp, i]))
|
|
18
|
+
const LEGACY_WIDTH_MAP = Object.fromEntries(LEGACY_WIDTHS.map((cp, i) => [cp, i.toString(16)]))
|
|
19
|
+
|
|
20
|
+
// Base prefix for new encoding — compression flag appended as 5th char
|
|
21
|
+
const PREFIX = String.fromCodePoint(ZERO_WIDTHS[0]).repeat(4)
|
|
22
|
+
|
|
23
|
+
const ALL_WIDTHS = [...ZERO_WIDTHS, ...LEGACY_WIDTHS]
|
|
24
|
+
const WIDTH_HEXES = ALL_WIDTHS.map((cp) => `\\u{${cp.toString(16)}}`).join('')
|
|
25
|
+
|
|
26
|
+
export const STEGA_REGEX = new RegExp(`[${WIDTH_HEXES}]{4,}`, 'gu')
|
|
27
|
+
|
|
28
|
+
// ---------- ENCODE ----------
|
|
29
|
+
export function stegaEncode(data: any) {
|
|
30
|
+
if (data === undefined) return ''
|
|
31
|
+
|
|
32
|
+
const json = typeof data === 'string' ? data : JSON.stringify(data)
|
|
33
|
+
// On nodejs we could use Buffer instead (it is faster) but we need to identify if we are running on node
|
|
34
|
+
const bytes = new TextEncoder().encode(json)
|
|
35
|
+
// Using a string and concatenating the result as we are looping is faster
|
|
36
|
+
// than creating an array and merging at the end
|
|
37
|
+
let out = ''
|
|
38
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
39
|
+
const b = bytes[i]
|
|
40
|
+
out +=
|
|
41
|
+
ZERO_WIDTHS_CHAR_CODES[(b >> 6) & 3] +
|
|
42
|
+
ZERO_WIDTHS_CHAR_CODES[(b >> 4) & 3] +
|
|
43
|
+
ZERO_WIDTHS_CHAR_CODES[(b >> 2) & 3] +
|
|
44
|
+
ZERO_WIDTHS_CHAR_CODES[b & 3]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return PREFIX + out
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ---------- DECODE ----------
|
|
51
|
+
export function stegaDecode(str: string) {
|
|
52
|
+
if (!str) return undefined
|
|
53
|
+
const match = str.match(STEGA_REGEX)
|
|
54
|
+
if (!match) return undefined
|
|
55
|
+
|
|
56
|
+
const encoded = match[0]
|
|
57
|
+
if (encoded.length % 2 === 0) {
|
|
58
|
+
if (encoded.length % 4 || !encoded.startsWith(PREFIX)) {
|
|
59
|
+
// Legacy hex-based encoding
|
|
60
|
+
return decodeLegacy(encoded)
|
|
61
|
+
}
|
|
62
|
+
} else throw new Error('Encoded data has invalid length')
|
|
63
|
+
const payload = encoded.slice(4)
|
|
64
|
+
const chars = Array.from(payload)
|
|
65
|
+
const bytes = new Uint8Array(chars.length / 4)
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
68
|
+
bytes[i] =
|
|
69
|
+
(ZERO_WIDTH_MAP[chars[i * 4].codePointAt(0) ?? 0] << 6) |
|
|
70
|
+
(ZERO_WIDTH_MAP[chars[i * 4 + 1].codePointAt(0) ?? 0] << 4) |
|
|
71
|
+
(ZERO_WIDTH_MAP[chars[i * 4 + 2].codePointAt(0) ?? 0] << 2) |
|
|
72
|
+
ZERO_WIDTH_MAP[chars[i * 4 + 3].codePointAt(0) ?? 0]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const json = new TextDecoder().decode(bytes)
|
|
77
|
+
return JSON.parse(json)
|
|
78
|
+
} catch {
|
|
79
|
+
return undefined
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ---------- LEGACY DECODER ----------
|
|
84
|
+
function decodeLegacy(chars: string, single = false) {
|
|
85
|
+
const bytes = []
|
|
86
|
+
|
|
87
|
+
for (let i = chars.length / 2; i-- > 0; ) {
|
|
88
|
+
const hexPair = `${LEGACY_WIDTH_MAP[chars[i * 2].codePointAt(0) ?? 0]}${LEGACY_WIDTH_MAP[chars[i * 2 + 1].codePointAt(0) ?? 0]}`
|
|
89
|
+
bytes.unshift(String.fromCharCode(parseInt(hexPair, 16)))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const decoded = []
|
|
93
|
+
const queue = [bytes.join('')]
|
|
94
|
+
let attempts = 10
|
|
95
|
+
|
|
96
|
+
while (queue.length) {
|
|
97
|
+
const chunk = queue.shift() ?? ''
|
|
98
|
+
try {
|
|
99
|
+
const parsed = JSON.parse(chunk)
|
|
100
|
+
decoded.push(parsed)
|
|
101
|
+
if (single) return decoded
|
|
102
|
+
} catch (err: any) {
|
|
103
|
+
if (!attempts--) throw err
|
|
104
|
+
const pos = err.message.match(/\sposition\s(\d+)$/)?.[1]
|
|
105
|
+
if (!pos) throw err
|
|
106
|
+
queue.unshift(chunk.substring(0, +pos), chunk.substring(+pos))
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return decoded
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ---------- UTILITIES ----------
|
|
114
|
+
export function stegaCombine(visible: any, metadata: any, skip: 'auto' | boolean = 'auto') {
|
|
115
|
+
if (skip === true || (skip === 'auto' && !isDateLike(visible) && !isUrlLike(visible))) {
|
|
116
|
+
return `${visible}${stegaEncode(metadata)}`
|
|
117
|
+
}
|
|
118
|
+
return visible
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function stegaClean(input: string) {
|
|
122
|
+
if (input == null) return input
|
|
123
|
+
const cleaned = JSON.stringify(input).replace(STEGA_REGEX, '')
|
|
124
|
+
return JSON.parse(cleaned)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function stegaSplit(str: string) {
|
|
128
|
+
const match = str.match(STEGA_REGEX)
|
|
129
|
+
return {
|
|
130
|
+
cleaned: str.replace(STEGA_REGEX, ''),
|
|
131
|
+
encoded: match ? match[0] : '',
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// ---------- HELPERS ----------
|
|
136
|
+
function isUrlLike(t: any) {
|
|
137
|
+
try {
|
|
138
|
+
new URL(t, t.startsWith('/') ? 'https://example.com' : undefined)
|
|
139
|
+
return true
|
|
140
|
+
} catch {
|
|
141
|
+
return false
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isDateLike(t: any) {
|
|
146
|
+
if (!t || typeof t !== 'string') return false
|
|
147
|
+
return Boolean(Date.parse(t))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function stegaDecodeAll(data: string): string[] {
|
|
151
|
+
const e = data.match(STEGA_REGEX)
|
|
152
|
+
if (e) return e.map((r) => stegaDecode(r)).flat()
|
|
153
|
+
return []
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default {
|
|
157
|
+
stegaEncode,
|
|
158
|
+
stegaDecode,
|
|
159
|
+
stegaCombine,
|
|
160
|
+
stegaClean,
|
|
161
|
+
stegaSplit,
|
|
162
|
+
stegaDecodeAll,
|
|
163
|
+
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {vercelStegaCombine} from '@vercel/stega'
|
|
2
|
-
|
|
3
1
|
import {createEditUrl} from '../csm/createEditUrl'
|
|
4
2
|
import {jsonPathToStudioPath} from '../csm/jsonPath'
|
|
5
3
|
import {resolveStudioBaseRoute} from '../csm/resolveEditInfo'
|
|
6
4
|
import {reKeySegment, toString as studioPathToString} from '../csm/studioPath'
|
|
7
5
|
import {encodeIntoResult} from './encodeIntoResult'
|
|
8
6
|
import {filterDefault} from './filterDefault'
|
|
7
|
+
import {stegaCombine} from './stega'
|
|
9
8
|
import {
|
|
10
9
|
type ContentSourceMap,
|
|
11
10
|
type ContentSourceMapParsedPath,
|
|
@@ -90,7 +89,7 @@ export function stegaEncodeSourceMap<Result = unknown>(
|
|
|
90
89
|
if (!baseUrl) return value
|
|
91
90
|
const {_id: id, _type: type, _projectId: projectId, _dataset: dataset} = sourceDocument
|
|
92
91
|
|
|
93
|
-
return
|
|
92
|
+
return stegaCombine(
|
|
94
93
|
value,
|
|
95
94
|
{
|
|
96
95
|
origin: 'sanity.io',
|
|
@@ -105,7 +104,7 @@ export function stegaEncodeSourceMap<Result = unknown>(
|
|
|
105
104
|
}),
|
|
106
105
|
},
|
|
107
106
|
// We use custom logic to determine if we should skip encoding
|
|
108
|
-
|
|
107
|
+
true,
|
|
109
108
|
)
|
|
110
109
|
},
|
|
111
110
|
)
|
package/umd/sanityClient.js
CHANGED
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
|
|
22
22
|
const e=!(typeof navigator>"u")&&"ReactNative"===navigator.product,t={timeout:e?6e4:12e4},r=function(r){const a={...t,..."string"==typeof r?{url:r}:r};if(a.timeout=n$1(a.timeout),a.query){const{url:t,searchParams:r}=function(t){const r=t.indexOf("?");if(-1===r)return {url:t,searchParams:new URLSearchParams};const n=t.slice(0,r),a=t.slice(r+1);if(!e)return {url:n,searchParams:new URLSearchParams(a)};if("function"!=typeof decodeURIComponent)throw new Error("Broken `URLSearchParams` implementation, and `decodeURIComponent` is not defined");const s=new URLSearchParams;for(const e of a.split("&")){const[t,r]=e.split("=");t&&s.append(o$1(t),o$1(r||""));}return {url:n,searchParams:s}}(a.url);for(const[e,o]of Object.entries(a.query)){if(void 0!==o)if(Array.isArray(o))for(const t of o)r.append(e,t);else r.append(e,o);const n=r.toString();n&&(a.url=`${t}?${n}`);}}return a.method=a.body&&!a.method?"POST":(a.method||"GET").toUpperCase(),a};function o$1(e){return decodeURIComponent(e.replace(/\+/g," "))}function n$1(e){if(false===e||0===e)return false;if(e.connect||e.socket)return e;const r=Number(e);return isNaN(r)?n$1(t.timeout):{connect:r,socket:r}}const a$2=/^https?:\/\//i,s$2=function(e){if(!a$2.test(e.url))throw new Error(`"${e.url}" is not a valid URL`)};function c$3(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}
|
|
23
23
|
|
|
24
|
-
const o=["request","response","progress","error","abort"],n=["processOptions","validateOptions","interceptRequest","finalizeOptions","onRequest","onResponse","onError","onReturn","onHeaders"];function s$1(r$1,a){const i=[],u=n.reduce(((e,t)=>(e[t]=e[t]||[],e)),{processOptions:[r],validateOptions:[s$2]});function l(e){const t=o.reduce(((e,t)=>(e[t]=function(){const e=/* @__PURE__ */Object.create(null);let t=0;return {publish:function(t){for(const r in e)e[r](t);},subscribe:function(r){const o=t++;return e[o]=r,function(){delete e[o];}}}}(),e)),{}),r=(e=>function(t,r,...o){const n="onError"===t;let s=r;for(let r=0;r<e[t].length&&(s=(0, e[t][r])(s,...o),!n||s);r++);return s})(u),n=r("processOptions",e);r("validateOptions",n);const s={options:n,channels:t,applyMiddleware:r};let i;const l=t.request.subscribe((e=>{i=a(e,((o,n)=>((e,o,n)=>{let s=e,a=o;if(!s)try{a=r("onResponse",o,n);}catch(e){a=null,s=e;}s=s&&r("onError",s,n),s?t.error.publish(s):a&&t.response.publish(a);})(o,n,e)));}));t.abort.subscribe((()=>{l(),i&&i.abort();}));const c=r("onReturn",t,s);return c===t&&t.request.publish(s),c}return l.use=function(e){if(!e)throw new Error("Tried to add middleware that resolved to falsey value");if("function"==typeof e)throw new Error("Tried to add middleware that was a function. It probably expects you to pass options to it.");if(e.onReturn&&u.onReturn.length>0)throw new Error("Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event");return n.forEach((t=>{e[t]&&u[t].push(e[t]);})),i.push(e),l},l.clone=()=>s$1(i,a),r$1.forEach(l.use),l}var a$1,i,u$
|
|
24
|
+
const o=["request","response","progress","error","abort"],n=["processOptions","validateOptions","interceptRequest","finalizeOptions","onRequest","onResponse","onError","onReturn","onHeaders"];function s$1(r$1,a){const i=[],u=n.reduce(((e,t)=>(e[t]=e[t]||[],e)),{processOptions:[r],validateOptions:[s$2]});function l(e){const t=o.reduce(((e,t)=>(e[t]=function(){const e=/* @__PURE__ */Object.create(null);let t=0;return {publish:function(t){for(const r in e)e[r](t);},subscribe:function(r){const o=t++;return e[o]=r,function(){delete e[o];}}}}(),e)),{}),r=(e=>function(t,r,...o){const n="onError"===t;let s=r;for(let r=0;r<e[t].length&&(s=(0, e[t][r])(s,...o),!n||s);r++);return s})(u),n=r("processOptions",e);r("validateOptions",n);const s={options:n,channels:t,applyMiddleware:r};let i;const l=t.request.subscribe((e=>{i=a(e,((o,n)=>((e,o,n)=>{let s=e,a=o;if(!s)try{a=r("onResponse",o,n);}catch(e){a=null,s=e;}s=s&&r("onError",s,n),s?t.error.publish(s):a&&t.response.publish(a);})(o,n,e)));}));t.abort.subscribe((()=>{l(),i&&i.abort();}));const c=r("onReturn",t,s);return c===t&&t.request.publish(s),c}return l.use=function(e){if(!e)throw new Error("Tried to add middleware that resolved to falsey value");if("function"==typeof e)throw new Error("Tried to add middleware that was a function. It probably expects you to pass options to it.");if(e.onReturn&&u.onReturn.length>0)throw new Error("Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event");return n.forEach((t=>{e[t]&&u[t].push(e[t]);})),i.push(e),l},l.clone=()=>s$1(i,a),r$1.forEach(l.use),l}var a$1,i,u$1=/* @__PURE__ */c$3(function(){if(i)return a$1;i=1;var e=function(e){return e.replace(/^\s+|\s+$/g,"")};return a$1=function(t){if(!t)return {};for(var r={},o=e(t).split("\n"),n=0;n<o.length;n++){var s=o[n],a=s.indexOf(":"),i=e(s.slice(0,a)).toLowerCase(),u=e(s.slice(a+1));typeof r[i]>"u"?r[i]=u:(l=r[i],"[object Array]"===Object.prototype.toString.call(l)?r[i].push(u):r[i]=[r[i],u]);}var l;return r}}());let l$1 = class l{onabort;onerror;onreadystatechange;ontimeout;readyState=0;response;responseText="";responseType="";status;statusText;withCredentials;#e;#t;#r;#o={};#n;#s={};#a;open(e,t,r){this.#e=e,this.#t=t,this.#r="",this.readyState=1,this.onreadystatechange?.(),this.#n=void 0;}abort(){this.#n&&this.#n.abort();}getAllResponseHeaders(){return this.#r}setRequestHeader(e,t){this.#o[e]=t;}setInit(e,t=true){this.#s=e,this.#a=t;}send(e){const t="arraybuffer"!==this.responseType,r={...this.#s,method:this.#e,headers:this.#o,body:e};"function"==typeof AbortController&&this.#a&&(this.#n=new AbortController,typeof EventTarget<"u"&&this.#n.signal instanceof EventTarget&&(r.signal=this.#n.signal)),typeof document<"u"&&(r.credentials=this.withCredentials?"include":"omit"),fetch(this.#t,r).then((e=>(e.headers.forEach(((e,t)=>{this.#r+=`${t}: ${e}\r\n`;})),this.status=e.status,this.statusText=e.statusText,this.readyState=3,this.onreadystatechange?.(),t?e.text():e.arrayBuffer()))).then((e=>{"string"==typeof e?this.responseText=e:this.response=e,this.readyState=4,this.onreadystatechange?.();})).catch((e=>{"AbortError"!==e.name?this.onerror?.(e):this.onabort?.();}));}};const c$2="function"==typeof XMLHttpRequest?"xhr":"fetch",h="xhr"===c$2?XMLHttpRequest:l$1,d$1=(e,t)=>{const r=e.options,o=e.applyMiddleware("finalizeOptions",r),n={},s=e.applyMiddleware("interceptRequest",void 0,{adapter:c$2,context:e});if(s){const e=setTimeout(t,0,null,s);return {abort:()=>clearTimeout(e)}}let a=new h;a instanceof l$1&&"object"==typeof o.fetch&&a.setInit(o.fetch,o.useAbortSignal??true);const i=o.headers,d=o.timeout;let p=false,f=false,b=false;if(a.onerror=e=>{m(a instanceof l$1?e instanceof Error?e:new Error(`Request error while attempting to reach is ${o.url}`,{cause:e}):new Error(`Request error while attempting to reach is ${o.url}${e.lengthComputable?`(${e.loaded} of ${e.total} bytes transferred)`:""}`));},a.ontimeout=e=>{m(new Error(`Request timeout while attempting to reach ${o.url}${e.lengthComputable?`(${e.loaded} of ${e.total} bytes transferred)`:""}`));},a.onabort=()=>{w(true),p=true;},a.onreadystatechange=function(){d&&(w(),n.socket=setTimeout((()=>y("ESOCKETTIMEDOUT")),d.socket)),!p&&a&&4===a.readyState&&0!==a.status&&function(){if(!(p||f||b)){if(0===a.status)return void m(new Error("Unknown XHR error"));w(),f=true,t(null,{body:a.response||(""===a.responseType||"text"===a.responseType?a.responseText:""),url:o.url,method:o.method,headers:u$1(a.getAllResponseHeaders()),statusCode:a.status,statusMessage:a.statusText});}}();},a.open(o.method,o.url,true),a.withCredentials=!!o.withCredentials,i&&a.setRequestHeader)for(const e in i)i.hasOwnProperty(e)&&a.setRequestHeader(e,i[e]);return o.rawBody&&(a.responseType="arraybuffer"),e.applyMiddleware("onRequest",{options:o,adapter:c$2,request:a,context:e}),a.send(o.body||null),d&&(n.connect=setTimeout((()=>y("ETIMEDOUT")),d.connect)),{abort:function(){p=true,a&&a.abort();}};function y(t){b=true,a.abort();const r=new Error("ESOCKETTIMEDOUT"===t?`Socket timed out on request to ${o.url}`:`Connection timed out on request to ${o.url}`);r.code=t,e.channels.error.publish(r);}function w(e){(e||p||a&&a.readyState>=2&&n.connect)&&clearTimeout(n.connect),n.socket&&clearTimeout(n.socket);}function m(e){if(f)return;w(true),f=true,a=null;const r=e||new Error(`Network error while attempting to reach ${o.url}`);r.isNetworkError=true,r.request=o,t(r);}},p$1=(e=[],t=d$1)=>s$1(e,t),f$1="browser";
|
|
25
25
|
|
|
26
|
-
var a,c$1,u
|
|
26
|
+
var a,c$1,u,l,p,d={exports:{}};/* @__PURE__ */c$3((p||(p=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const s="color: "+this.color;t.splice(1,0,s,"color: inherit");let n=0,r=0;t[0].replace(/%[a-zA-Z%]/g,(e=>{"%%"!==e&&(n++,"%c"===e&&(r=n));})),t.splice(r,0,s);},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug");}catch{}},t.load=function(){let e;try{e=t.storage.getItem("debug");}catch{}return !e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){if(typeof window<"u"&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return true;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return false;let e;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch{}}(),t.destroy=/* @__PURE__ */(()=>{let e=false;return ()=>{e||(e=true,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."));}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=(l?u:(l=1,u=function(e){function t(e){let n,r,o,i=null;function a(...e){if(!a.enabled)return;const s=a,r=Number(/* @__PURE__ */new Date),o=r-(n||r);s.diff=o,s.prev=n,s.curr=r,n=r,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let i=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,((n,r)=>{if("%%"===n)return "%";i++;const o=t.formatters[r];if("function"==typeof o){const t=e[i];n=o.call(s,t),e.splice(i,1),i--;}return n})),t.formatArgs.call(s,e),(s.log||t.log).apply(s,e);}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=s,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:true,configurable:false,get:()=>null!==i?i:(r!==t.namespaces&&(r=t.namespaces,o=t.enabled(e)),o),set:e=>{i=e;}}),"function"==typeof t.init&&t.init(a),a}function s(e,s){const n=t(this.namespace+(typeof s>"u"?":":s)+e);return n.log=this.log,n}function n(e,t){let s=0,n=0,r=-1,o=0;for(;s<e.length;)if(n<t.length&&(t[n]===e[s]||"*"===t[n]))"*"===t[n]?(r=n,o=s,n++):(s++,n++);else {if(-1===r)return false;n=r+1,o++,s=o;}for(;n<t.length&&"*"===t[n];)n++;return n===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map((e=>"-"+e))].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const s=("string"==typeof e?e:"").trim().replace(" ",",").split(",").filter(Boolean);for(const e of s)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e);},t.enabled=function(e){for(const s of t.skips)if(n(e,s))return false;for(const s of t.names)if(n(e,s))return true;return false},t.humanize=function(){if(c$1)return a;c$1=1;var e=1e3,t=60*e,s=60*t,n=24*s,r=7*n;function o(e,t,s,n){var r=t>=1.5*s;return Math.round(e/s)+" "+n+(r?"s":"")}return a=function(i,a){a=a||{};var c,u,l=typeof i;if("string"===l&&i.length>0)return function(o){if(!((o=String(o)).length>100)){var i=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(o);if(i){var a=parseFloat(i[1]);switch((i[2]||"ms").toLowerCase()){case "years":case "year":case "yrs":case "yr":case "y":return 315576e5*a;case "weeks":case "week":case "w":return a*r;case "days":case "day":case "d":return a*n;case "hours":case "hour":case "hrs":case "hr":case "h":return a*s;case "minutes":case "minute":case "mins":case "min":case "m":return a*t;case "seconds":case "second":case "secs":case "sec":case "s":return a*e;case "milliseconds":case "millisecond":case "msecs":case "msec":case "ms":return a;default:return}}}}(i);if("number"===l&&isFinite(i))return a.long?(c=i,(u=Math.abs(c))>=n?o(c,u,n,"day"):u>=s?o(c,u,s,"hour"):u>=t?o(c,u,t,"minute"):u>=e?o(c,u,e,"second"):c+" ms"):function(r){var o=Math.abs(r);return o>=n?Math.round(r/n)+"d":o>=s?Math.round(r/s)+"h":o>=t?Math.round(r/t)+"m":o>=e?Math.round(r/e)+"s":r+"ms"}(i);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(i))}}(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");},Object.keys(e).forEach((s=>{t[s]=e[s];})),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let s=0;for(let t=0;t<e.length;t++)s=(s<<5)-s+e.charCodeAt(t),s|=0;return t.colors[Math.abs(s)%t.colors.length]},t.enable(t.load()),t}))(t);const{formatters:s}=e.exports;s.j=function(e){try{return JSON.stringify(e)}catch(e){return "[UnexpectedJSONParseError]: "+e.message}};}(d,d.exports)),d.exports));const F=typeof Buffer>"u"?()=>false:e=>Buffer.isBuffer(e);function O$1(e){return "[object Object]"===Object.prototype.toString.call(e)}function j(e){if(false===O$1(e))return false;const t=e.constructor;if(void 0===t)return true;const s=t.prototype;return !(false===O$1(s)||false===s.hasOwnProperty("isPrototypeOf"))}const v=["boolean","string","number"];function x(){return {processOptions:e=>{const t=e.body;return !t||"function"==typeof t.pipe||F(t)||-1===v.indexOf(typeof t)&&!Array.isArray(t)&&!j(t)?e:Object.assign({},e,{body:JSON.stringify(e.body),headers:Object.assign({},e.headers,{"Content-Type":"application/json"})})}}}function E(e){return {onResponse:s=>{const n=s.headers["content-type"]||"",r=e&&e.force||-1!==n.indexOf("application/json");return s.body&&n&&r?Object.assign({},s,{body:t(s.body)}):s},processOptions:e=>Object.assign({},e,{headers:Object.assign({Accept:"application/json"},e.headers)})};function t(e){try{return JSON.parse(e)}catch(e){throw e.message=`Failed to parsed response body as JSON: ${e.message}`,e}}}let R={};typeof globalThis<"u"?R=globalThis:typeof window<"u"?R=window:typeof global<"u"?R=global:typeof self<"u"&&(R=self);var q=R;function A(e={}){const t=e.implementation||q.Observable;if(!t)throw new Error("`Observable` is not available in global scope, and no implementation was passed");return {onReturn:(e,s)=>new t((t=>(e.error.subscribe((e=>t.error(e))),e.progress.subscribe((e=>t.next(Object.assign({type:"progress"},e)))),e.response.subscribe((e=>{t.next(Object.assign({type:"response"},e)),t.complete();})),e.request.publish(s),()=>e.abort.publish())))}}function S$1(){return {onRequest:e=>{if("xhr"!==e.adapter)return;const t=e.request,s=e.context;function n(e){return t=>{const n=t.lengthComputable?t.loaded/t.total*100:-1;s.channels.progress.publish({stage:e,percent:n,total:t.total,loaded:t.loaded,lengthComputable:t.lengthComputable});}}"upload"in t&&"onprogress"in t.upload&&(t.upload.onprogress=n("upload")),"onprogress"in t&&(t.onprogress=n("download"));}}}var $=(e,t,s)=>("GET"===s.method||"HEAD"===s.method)&&(e.isNetworkError||false);function _$1(e){return 100*Math.pow(2,e)+100*Math.random()}const P=(e={})=>(e=>{const t=e.maxRetries||5,s=e.retryDelay||_$1,n=e.shouldRetry;return {onError:(e,r)=>{const o=r.options,i=o.maxRetries||t,a=o.retryDelay||s,c=o.shouldRetry||n,u=o.attemptNumber||0;if(null!==(l=o.body)&&"object"==typeof l&&"function"==typeof l.pipe||!c(e,u,o)||u>=i)return e;var l;const p=Object.assign({},r,{options:Object.assign({},o,{attemptNumber:u+1})});return setTimeout((()=>r.channels.request.publish(p)),a(u)),null}}})({shouldRetry:$,...e});P.shouldRetry=$;
|
|
27
27
|
|
|
28
28
|
/******************************************************************************
|
|
29
29
|
Copyright (c) Microsoft Corporation.
|
|
@@ -1896,29 +1896,8 @@
|
|
|
1896
1896
|
function isRecord(value) {
|
|
1897
1897
|
return typeof value == "object" && value !== null && !Array.isArray(value);
|
|
1898
1898
|
}
|
|
1899
|
-
var s = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, c = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 }
|
|
1900
|
-
|
|
1901
|
-
let e = JSON.stringify(t);
|
|
1902
|
-
return `${u}${Array.from(e).map((r) => {
|
|
1903
|
-
let n = r.charCodeAt(0);
|
|
1904
|
-
if (n > 255) throw new Error(`Only ASCII edit info can be encoded. Error attempting to encode ${e} on character ${r} (${n})`);
|
|
1905
|
-
return Array.from(n.toString(4).padStart(4, "0")).map((o) => String.fromCodePoint(c[o])).join("");
|
|
1906
|
-
}).join("")}`;
|
|
1907
|
-
}
|
|
1908
|
-
function I(t) {
|
|
1909
|
-
return !Number.isNaN(Number(t)) || /[a-z]/i.test(t) && !/\d+(?:[-:\/]\d+){2}(?:T\d+(?:[-:\/]\d+){1,2}(\.\d+)?Z?)?/.test(t) ? false : !!Date.parse(t);
|
|
1910
|
-
}
|
|
1911
|
-
function T(t) {
|
|
1912
|
-
try {
|
|
1913
|
-
new URL(t, t.startsWith("/") ? "https://acme.com" : void 0);
|
|
1914
|
-
} catch {
|
|
1915
|
-
return false;
|
|
1916
|
-
}
|
|
1917
|
-
return true;
|
|
1918
|
-
}
|
|
1919
|
-
function C(t, e, r = "auto") {
|
|
1920
|
-
return r === true || r === "auto" && (I(t) || T(t)) ? t : `${t}${E(e)}`;
|
|
1921
|
-
}
|
|
1899
|
+
var s = { 0: 8203, 1: 8204, 2: 8205, 3: 8290, 4: 8291, 5: 8288, 6: 65279, 7: 8289, 8: 119155, 9: 119156, a: 119157, b: 119158, c: 119159, d: 119160, e: 119161, f: 119162 }, c = { 0: 8203, 1: 8204, 2: 8205, 3: 65279 };
|
|
1900
|
+
new Array(4).fill(String.fromCodePoint(c[0])).join("");
|
|
1922
1901
|
Object.fromEntries(Object.entries(c).map((t) => t.reverse()));
|
|
1923
1902
|
Object.fromEntries(Object.entries(s).map((t) => t.reverse()));
|
|
1924
1903
|
var S = `${Object.values(s).map((t) => `\\u{${t.toString(16)}}`).join("")}`, f = new RegExp(`[${S}]{4,}`, "gu");
|
|
@@ -2172,7 +2151,7 @@ ${codeFrame(query, { start, end }, description)}${withTag}`;
|
|
|
2172
2151
|
...envMiddleware2,
|
|
2173
2152
|
printWarnings(config),
|
|
2174
2153
|
x(),
|
|
2175
|
-
E
|
|
2154
|
+
E(),
|
|
2176
2155
|
S$1(),
|
|
2177
2156
|
httpError,
|
|
2178
2157
|
A({ implementation: Observable })
|
|
@@ -4855,6 +4834,9 @@ ${selectionOpts}`);
|
|
|
4855
4834
|
function jsonPath(path) {
|
|
4856
4835
|
return `$${path.map((segment) => typeof segment == "string" ? `['${segment.replace(/[\f\n\r\t'\\]/g, (match) => ESCAPE[match])}']` : typeof segment == "number" ? `[${segment}]` : segment._key !== "" ? `[?(@._key=='${segment._key.replace(/['\\]/g, (match) => ESCAPE[match])}')]` : `[${segment._index}]`).join("")}`;
|
|
4857
4836
|
}
|
|
4837
|
+
function jsonPathArray(path) {
|
|
4838
|
+
return path.map((segment) => typeof segment == "string" ? `['${segment.replace(/[\f\n\r\t'\\]/g, (match) => ESCAPE[match])}']` : typeof segment == "number" ? `[${segment}]` : segment._key !== "" ? `[?(@._key=='${segment._key.replace(/['\\]/g, (match) => ESCAPE[match])}')]` : `[${segment._index}]`);
|
|
4839
|
+
}
|
|
4858
4840
|
function parseJsonPath(path) {
|
|
4859
4841
|
const parsed = [], parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
|
|
4860
4842
|
let match;
|
|
@@ -4909,11 +4891,14 @@ ${selectionOpts}`);
|
|
|
4909
4891
|
matchedPath: resultMappingPath,
|
|
4910
4892
|
pathSuffix: ""
|
|
4911
4893
|
};
|
|
4912
|
-
const
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4894
|
+
const resultMappingPathArray = jsonPathArray(jsonPathToMappingPath(resultPath));
|
|
4895
|
+
for (let i = resultMappingPathArray.length - 1; i > 0; i--) {
|
|
4896
|
+
const key = `$${resultMappingPathArray.slice(0, i).join("")}`, mappingFound = csm.mappings[key];
|
|
4897
|
+
if (mappingFound) {
|
|
4898
|
+
const pathSuffix = resultMappingPath.substring(key.length);
|
|
4899
|
+
return { mapping: mappingFound, matchedPath: key, pathSuffix };
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4917
4902
|
}
|
|
4918
4903
|
function isArray(value) {
|
|
4919
4904
|
return value !== null && Array.isArray(value);
|
|
@@ -5110,6 +5095,60 @@ ${selectionOpts}`);
|
|
|
5110
5095
|
function hasTypeLike(path) {
|
|
5111
5096
|
return path.some((segment) => typeof segment == "string" && segment.match(/type/i) !== null);
|
|
5112
5097
|
}
|
|
5098
|
+
const ZERO_WIDTHS = [
|
|
5099
|
+
8203,
|
|
5100
|
+
// U+200B ZERO WIDTH SPACE
|
|
5101
|
+
8204,
|
|
5102
|
+
// U+200C ZERO WIDTH NON-JOINER
|
|
5103
|
+
8205,
|
|
5104
|
+
// U+200D ZERO WIDTH JOINER
|
|
5105
|
+
65279
|
|
5106
|
+
// U+FEFF ZERO WIDTH NO-BREAK SPACE
|
|
5107
|
+
], ZERO_WIDTHS_CHAR_CODES = ZERO_WIDTHS.map((x) => String.fromCharCode(x)), LEGACY_WIDTHS = [
|
|
5108
|
+
8203,
|
|
5109
|
+
8204,
|
|
5110
|
+
8205,
|
|
5111
|
+
8290,
|
|
5112
|
+
8291,
|
|
5113
|
+
8288,
|
|
5114
|
+
65279,
|
|
5115
|
+
8289,
|
|
5116
|
+
119155,
|
|
5117
|
+
119156,
|
|
5118
|
+
119157,
|
|
5119
|
+
119158,
|
|
5120
|
+
119159,
|
|
5121
|
+
119160,
|
|
5122
|
+
119161,
|
|
5123
|
+
119162
|
|
5124
|
+
];
|
|
5125
|
+
Object.fromEntries(ZERO_WIDTHS.map((cp, i) => [cp, i]));
|
|
5126
|
+
Object.fromEntries(LEGACY_WIDTHS.map((cp, i) => [cp, i.toString(16)]));
|
|
5127
|
+
const PREFIX = String.fromCodePoint(ZERO_WIDTHS[0]).repeat(4), ALL_WIDTHS = [...ZERO_WIDTHS, ...LEGACY_WIDTHS];
|
|
5128
|
+
ALL_WIDTHS.map((cp) => `\\u{${cp.toString(16)}}`).join("");
|
|
5129
|
+
function stegaEncode(data) {
|
|
5130
|
+
if (data === void 0) return "";
|
|
5131
|
+
const json = typeof data == "string" ? data : JSON.stringify(data), bytes = new TextEncoder().encode(json);
|
|
5132
|
+
let out = "";
|
|
5133
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
5134
|
+
const b = bytes[i];
|
|
5135
|
+
out += ZERO_WIDTHS_CHAR_CODES[b >> 6 & 3] + ZERO_WIDTHS_CHAR_CODES[b >> 4 & 3] + ZERO_WIDTHS_CHAR_CODES[b >> 2 & 3] + ZERO_WIDTHS_CHAR_CODES[b & 3];
|
|
5136
|
+
}
|
|
5137
|
+
return PREFIX + out;
|
|
5138
|
+
}
|
|
5139
|
+
function stegaCombine(visible, metadata, skip = "auto") {
|
|
5140
|
+
return skip === true || skip === "auto" && !isDateLike(visible) && !isUrlLike(visible) ? `${visible}${stegaEncode(metadata)}` : visible;
|
|
5141
|
+
}
|
|
5142
|
+
function isUrlLike(t) {
|
|
5143
|
+
try {
|
|
5144
|
+
return new URL(t, t.startsWith("/") ? "https://example.com" : void 0), !0;
|
|
5145
|
+
} catch {
|
|
5146
|
+
return false;
|
|
5147
|
+
}
|
|
5148
|
+
}
|
|
5149
|
+
function isDateLike(t) {
|
|
5150
|
+
return !t || typeof t != "string" ? false : !!Date.parse(t);
|
|
5151
|
+
}
|
|
5113
5152
|
const TRUNCATE_LENGTH = 20;
|
|
5114
5153
|
function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
5115
5154
|
const { filter, logger, enabled } = config;
|
|
@@ -5150,7 +5189,7 @@ ${selectionOpts}`);
|
|
|
5150
5189
|
);
|
|
5151
5190
|
if (!baseUrl) return value;
|
|
5152
5191
|
const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
|
|
5153
|
-
return
|
|
5192
|
+
return stegaCombine(
|
|
5154
5193
|
value,
|
|
5155
5194
|
{
|
|
5156
5195
|
origin: "sanity.io",
|
|
@@ -5165,7 +5204,7 @@ ${selectionOpts}`);
|
|
|
5165
5204
|
})
|
|
5166
5205
|
},
|
|
5167
5206
|
// We use custom logic to determine if we should skip encoding
|
|
5168
|
-
|
|
5207
|
+
true
|
|
5169
5208
|
);
|
|
5170
5209
|
}
|
|
5171
5210
|
);
|