@sanity/client 6.14.1 → 6.14.2
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/browserMiddleware-BHXO2Lcy.cjs +1491 -0
- package/dist/_chunks/{browserMiddleware-FpdqDQ1o.cjs.map → browserMiddleware-BHXO2Lcy.cjs.map} +1 -1
- package/dist/_chunks/browserMiddleware-jPnXCUlp.js +1474 -0
- package/dist/_chunks/{browserMiddleware-DhUBf_19.js.map → browserMiddleware-jPnXCUlp.js.map} +1 -1
- package/dist/_chunks/nodeMiddleware-CrO2pNEp.js +1491 -0
- package/dist/_chunks/{nodeMiddleware-BSZoKrW0.js.map → nodeMiddleware-CrO2pNEp.js.map} +1 -1
- package/dist/_chunks/nodeMiddleware-JJNfI4Rf.cjs +1508 -0
- package/dist/_chunks/{nodeMiddleware-DmcqX3kz.cjs.map → nodeMiddleware-JJNfI4Rf.cjs.map} +1 -1
- package/dist/_chunks/resolveEditInfo-BNCwZySb.cjs +284 -0
- package/dist/_chunks/{resolveEditInfo-BB1WiUDY.cjs.map → resolveEditInfo-BNCwZySb.cjs.map} +1 -1
- package/dist/_chunks/resolveEditInfo-qA5twkfC.js +285 -0
- package/dist/_chunks/{resolveEditInfo-Cf8D1Agp.js.map → resolveEditInfo-qA5twkfC.js.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-B9_uz7Zb.cjs +166 -0
- package/dist/_chunks/{stegaEncodeSourceMap-8TjLXjYU.cjs.map → stegaEncodeSourceMap-B9_uz7Zb.cjs.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-BvBJpbrr.cjs +329 -0
- package/dist/_chunks/{stegaEncodeSourceMap-DIcuvN0P.cjs.map → stegaEncodeSourceMap-BvBJpbrr.cjs.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-De3F_oJN.js +330 -0
- package/dist/_chunks/{stegaEncodeSourceMap-DLon0Yls.js.map → stegaEncodeSourceMap-De3F_oJN.js.map} +1 -1
- package/dist/_chunks/stegaEncodeSourceMap-bRxIGJ-b.js +168 -0
- package/dist/_chunks/{stegaEncodeSourceMap-DU95idpa.js.map → stegaEncodeSourceMap-bRxIGJ-b.js.map} +1 -1
- package/dist/csm.cjs +22 -56
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +36 -54
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +15 -21
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +24 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +15 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -15
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +12 -17
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +26 -11
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +12 -17
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.js +26 -11
- package/dist/stega.js.map +1 -1
- package/package.json +3 -3
- package/umd/sanityClient.js +2670 -3360
- package/umd/sanityClient.min.js +3 -3
- package/dist/_chunks/browserMiddleware-DhUBf_19.js +0 -1761
- package/dist/_chunks/browserMiddleware-FpdqDQ1o.cjs +0 -1777
- package/dist/_chunks/nodeMiddleware-BSZoKrW0.js +0 -1780
- package/dist/_chunks/nodeMiddleware-DmcqX3kz.cjs +0 -1796
- package/dist/_chunks/resolveEditInfo-BB1WiUDY.cjs +0 -422
- package/dist/_chunks/resolveEditInfo-Cf8D1Agp.js +0 -406
- package/dist/_chunks/stegaEncodeSourceMap-8TjLXjYU.cjs +0 -229
- package/dist/_chunks/stegaEncodeSourceMap-DIcuvN0P.cjs +0 -486
- package/dist/_chunks/stegaEncodeSourceMap-DLon0Yls.js +0 -482
- package/dist/_chunks/stegaEncodeSourceMap-DU95idpa.js +0 -225
|
@@ -1,482 +0,0 @@
|
|
|
1
|
-
import { b } from './browserMiddleware-DhUBf_19.js';
|
|
2
|
-
|
|
3
|
-
const reKeySegment = /_key\s*==\s*['"](.*)['"]/;
|
|
4
|
-
function isKeySegment(segment) {
|
|
5
|
-
if (typeof segment === "string") {
|
|
6
|
-
return reKeySegment.test(segment.trim());
|
|
7
|
-
}
|
|
8
|
-
return typeof segment === "object" && "_key" in segment;
|
|
9
|
-
}
|
|
10
|
-
function toString(path) {
|
|
11
|
-
if (!Array.isArray(path)) {
|
|
12
|
-
throw new Error("Path is not an array");
|
|
13
|
-
}
|
|
14
|
-
return path.reduce((target, segment, i) => {
|
|
15
|
-
const segmentType = typeof segment;
|
|
16
|
-
if (segmentType === "number") {
|
|
17
|
-
return `${target}[${segment}]`;
|
|
18
|
-
}
|
|
19
|
-
if (segmentType === "string") {
|
|
20
|
-
const separator = i === 0 ? "" : ".";
|
|
21
|
-
return `${target}${separator}${segment}`;
|
|
22
|
-
}
|
|
23
|
-
if (isKeySegment(segment) && segment._key) {
|
|
24
|
-
return `${target}[_key=="${segment._key}"]`;
|
|
25
|
-
}
|
|
26
|
-
if (Array.isArray(segment)) {
|
|
27
|
-
const [from, to] = segment;
|
|
28
|
-
return `${target}[${from}:${to}]`;
|
|
29
|
-
}
|
|
30
|
-
throw new Error(`Unsupported path segment \`${JSON.stringify(segment)}\``);
|
|
31
|
-
}, "");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const ESCAPE = {
|
|
35
|
-
"\f": "\\f",
|
|
36
|
-
"\n": "\\n",
|
|
37
|
-
"\r": "\\r",
|
|
38
|
-
" ": "\\t",
|
|
39
|
-
"'": "\\'",
|
|
40
|
-
"\\": "\\\\"
|
|
41
|
-
};
|
|
42
|
-
const UNESCAPE = {
|
|
43
|
-
"\\f": "\f",
|
|
44
|
-
"\\n": "\n",
|
|
45
|
-
"\\r": "\r",
|
|
46
|
-
"\\t": " ",
|
|
47
|
-
"\\'": "'",
|
|
48
|
-
"\\\\": "\\"
|
|
49
|
-
};
|
|
50
|
-
function jsonPath(path) {
|
|
51
|
-
return `$${path.map((segment) => {
|
|
52
|
-
if (typeof segment === "string") {
|
|
53
|
-
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, (match) => {
|
|
54
|
-
return ESCAPE[match];
|
|
55
|
-
});
|
|
56
|
-
return `['${escapedKey}']`;
|
|
57
|
-
}
|
|
58
|
-
if (typeof segment === "number") {
|
|
59
|
-
return `[${segment}]`;
|
|
60
|
-
}
|
|
61
|
-
if (segment._key !== "") {
|
|
62
|
-
const escapedKey = segment._key.replace(/['\\]/g, (match) => {
|
|
63
|
-
return ESCAPE[match];
|
|
64
|
-
});
|
|
65
|
-
return `[?(@._key=='${escapedKey}')]`;
|
|
66
|
-
}
|
|
67
|
-
return `[${segment._index}]`;
|
|
68
|
-
}).join("")}`;
|
|
69
|
-
}
|
|
70
|
-
function parseJsonPath(path) {
|
|
71
|
-
const parsed = [];
|
|
72
|
-
const parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
|
|
73
|
-
let match;
|
|
74
|
-
while ((match = parseRe.exec(path)) !== null) {
|
|
75
|
-
if (match[1] !== void 0) {
|
|
76
|
-
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, (m) => {
|
|
77
|
-
return UNESCAPE[m];
|
|
78
|
-
});
|
|
79
|
-
parsed.push(key);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (match[2] !== void 0) {
|
|
83
|
-
parsed.push(parseInt(match[2], 10));
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (match[3] !== void 0) {
|
|
87
|
-
const _key = match[3].replace(/\\(\\')/g, (m) => {
|
|
88
|
-
return UNESCAPE[m];
|
|
89
|
-
});
|
|
90
|
-
parsed.push({
|
|
91
|
-
_key,
|
|
92
|
-
_index: -1
|
|
93
|
-
});
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return parsed;
|
|
98
|
-
}
|
|
99
|
-
function jsonPathToStudioPath(path) {
|
|
100
|
-
return path.map((segment) => {
|
|
101
|
-
if (typeof segment === "string") {
|
|
102
|
-
return segment;
|
|
103
|
-
}
|
|
104
|
-
if (typeof segment === "number") {
|
|
105
|
-
return segment;
|
|
106
|
-
}
|
|
107
|
-
if (segment._key !== "") {
|
|
108
|
-
return { _key: segment._key };
|
|
109
|
-
}
|
|
110
|
-
if (segment._index !== -1) {
|
|
111
|
-
return segment._index;
|
|
112
|
-
}
|
|
113
|
-
throw new Error(`invalid segment:${JSON.stringify(segment)}`);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function jsonPathToMappingPath(path) {
|
|
117
|
-
return path.map((segment) => {
|
|
118
|
-
if (typeof segment === "string") {
|
|
119
|
-
return segment;
|
|
120
|
-
}
|
|
121
|
-
if (typeof segment === "number") {
|
|
122
|
-
return segment;
|
|
123
|
-
}
|
|
124
|
-
if (segment._index !== -1) {
|
|
125
|
-
return segment._index;
|
|
126
|
-
}
|
|
127
|
-
throw new Error(`invalid segment:${JSON.stringify(segment)}`);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function resolveMapping(resultPath, csm) {
|
|
132
|
-
if (!(csm == null ? void 0 : csm.mappings)) {
|
|
133
|
-
return void 0;
|
|
134
|
-
}
|
|
135
|
-
const resultMappingPath = jsonPath(jsonPathToMappingPath(resultPath));
|
|
136
|
-
if (csm.mappings[resultMappingPath] !== void 0) {
|
|
137
|
-
return {
|
|
138
|
-
mapping: csm.mappings[resultMappingPath],
|
|
139
|
-
matchedPath: resultMappingPath,
|
|
140
|
-
pathSuffix: ""
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length);
|
|
144
|
-
if (mappings.length == 0) {
|
|
145
|
-
return void 0;
|
|
146
|
-
}
|
|
147
|
-
const [matchedPath, mapping] = mappings[0];
|
|
148
|
-
const pathSuffix = resultMappingPath.substring(matchedPath.length);
|
|
149
|
-
return { mapping, matchedPath, pathSuffix };
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function isArray(value) {
|
|
153
|
-
return value !== null && Array.isArray(value);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function isRecord(value) {
|
|
157
|
-
return typeof value === "object" && value !== null;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function walkMap(value, mappingFn, path = []) {
|
|
161
|
-
if (isArray(value)) {
|
|
162
|
-
return value.map((v, idx) => {
|
|
163
|
-
if (isRecord(v)) {
|
|
164
|
-
const _key = v["_key"];
|
|
165
|
-
if (typeof _key === "string") {
|
|
166
|
-
return walkMap(v, mappingFn, path.concat({ _key, _index: idx }));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return walkMap(v, mappingFn, path.concat(idx));
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
if (isRecord(value)) {
|
|
173
|
-
return Object.fromEntries(
|
|
174
|
-
Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))])
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
return mappingFn(value, path);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function encodeIntoResult(result, csm, encoder) {
|
|
181
|
-
return walkMap(result, (value, path) => {
|
|
182
|
-
if (typeof value !== "string") {
|
|
183
|
-
return value;
|
|
184
|
-
}
|
|
185
|
-
const resolveMappingResult = resolveMapping(path, csm);
|
|
186
|
-
if (!resolveMappingResult) {
|
|
187
|
-
return value;
|
|
188
|
-
}
|
|
189
|
-
const { mapping, matchedPath } = resolveMappingResult;
|
|
190
|
-
if (mapping.type !== "value") {
|
|
191
|
-
return value;
|
|
192
|
-
}
|
|
193
|
-
if (mapping.source.type !== "documentValue") {
|
|
194
|
-
return value;
|
|
195
|
-
}
|
|
196
|
-
const sourceDocument = csm.documents[mapping.source.document];
|
|
197
|
-
const sourcePath = csm.paths[mapping.source.path];
|
|
198
|
-
const matchPathSegments = parseJsonPath(matchedPath);
|
|
199
|
-
const sourcePathSegments = parseJsonPath(sourcePath);
|
|
200
|
-
const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
|
|
201
|
-
return encoder({
|
|
202
|
-
sourcePath: fullSourceSegments,
|
|
203
|
-
sourceDocument,
|
|
204
|
-
resultPath: path,
|
|
205
|
-
value
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const DRAFTS_PREFIX = "drafts.";
|
|
211
|
-
function getPublishedId(id) {
|
|
212
|
-
if (id.startsWith(DRAFTS_PREFIX)) {
|
|
213
|
-
return id.slice(DRAFTS_PREFIX.length);
|
|
214
|
-
}
|
|
215
|
-
return id;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function createEditUrl(options) {
|
|
219
|
-
const {
|
|
220
|
-
baseUrl,
|
|
221
|
-
workspace: _workspace = "default",
|
|
222
|
-
tool: _tool = "default",
|
|
223
|
-
id: _id,
|
|
224
|
-
type,
|
|
225
|
-
path,
|
|
226
|
-
projectId,
|
|
227
|
-
dataset
|
|
228
|
-
} = options;
|
|
229
|
-
if (!baseUrl) {
|
|
230
|
-
throw new Error("baseUrl is required");
|
|
231
|
-
}
|
|
232
|
-
if (!path) {
|
|
233
|
-
throw new Error("path is required");
|
|
234
|
-
}
|
|
235
|
-
if (!_id) {
|
|
236
|
-
throw new Error("id is required");
|
|
237
|
-
}
|
|
238
|
-
if (baseUrl !== "/" && baseUrl.endsWith("/")) {
|
|
239
|
-
throw new Error("baseUrl must not end with a slash");
|
|
240
|
-
}
|
|
241
|
-
const workspace = _workspace === "default" ? void 0 : _workspace;
|
|
242
|
-
const tool = _tool === "default" ? void 0 : _tool;
|
|
243
|
-
const id = getPublishedId(_id);
|
|
244
|
-
const stringifiedPath = Array.isArray(path) ? toString(jsonPathToStudioPath(path)) : path;
|
|
245
|
-
const searchParams = new URLSearchParams({
|
|
246
|
-
baseUrl,
|
|
247
|
-
id,
|
|
248
|
-
type,
|
|
249
|
-
path: stringifiedPath
|
|
250
|
-
});
|
|
251
|
-
if (workspace) {
|
|
252
|
-
searchParams.set("workspace", workspace);
|
|
253
|
-
}
|
|
254
|
-
if (tool) {
|
|
255
|
-
searchParams.set("tool", tool);
|
|
256
|
-
}
|
|
257
|
-
if (projectId) {
|
|
258
|
-
searchParams.set("projectId", projectId);
|
|
259
|
-
}
|
|
260
|
-
if (dataset) {
|
|
261
|
-
searchParams.set("dataset", dataset);
|
|
262
|
-
}
|
|
263
|
-
const segments = [baseUrl === "/" ? "" : baseUrl];
|
|
264
|
-
if (workspace) {
|
|
265
|
-
segments.push(workspace);
|
|
266
|
-
}
|
|
267
|
-
const routerParams = [
|
|
268
|
-
"mode=presentation",
|
|
269
|
-
`id=${id}`,
|
|
270
|
-
`type=${type}`,
|
|
271
|
-
`path=${encodeURIComponent(stringifiedPath)}`
|
|
272
|
-
];
|
|
273
|
-
if (tool) {
|
|
274
|
-
routerParams.push(`tool=${tool}`);
|
|
275
|
-
}
|
|
276
|
-
segments.push("intent", "edit", `${routerParams.join(";")}?${searchParams}`);
|
|
277
|
-
return segments.join("/");
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function resolveStudioBaseRoute(studioUrl) {
|
|
281
|
-
let baseUrl = typeof studioUrl === "string" ? studioUrl : studioUrl.baseUrl;
|
|
282
|
-
if (baseUrl !== "/") {
|
|
283
|
-
baseUrl = baseUrl.replace(/\/$/, "");
|
|
284
|
-
}
|
|
285
|
-
if (typeof studioUrl === "string") {
|
|
286
|
-
return { baseUrl };
|
|
287
|
-
}
|
|
288
|
-
return { ...studioUrl, baseUrl };
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const filterDefault = ({ sourcePath, value }) => {
|
|
292
|
-
if (isValidDate(value) || isValidURL(value)) {
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
const endPath = sourcePath.at(-1);
|
|
296
|
-
if (sourcePath.at(-2) === "slug" && endPath === "current") {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
if (typeof endPath === "string" && endPath.startsWith("_")) {
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
if (typeof endPath === "number" && sourcePath.at(-2) === "marks") {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
if (endPath === "href" && typeof sourcePath.at(-2) === "number" && sourcePath.at(-3) === "markDefs") {
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
if (endPath === "style" || endPath === "listItem") {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
if (sourcePath.some(
|
|
312
|
-
(path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
|
|
313
|
-
)) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
if (typeof endPath === "string" && denylist.has(endPath)) {
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
return true;
|
|
320
|
-
};
|
|
321
|
-
const denylist = /* @__PURE__ */ new Set([
|
|
322
|
-
"color",
|
|
323
|
-
"colour",
|
|
324
|
-
"currency",
|
|
325
|
-
"email",
|
|
326
|
-
"format",
|
|
327
|
-
"gid",
|
|
328
|
-
"hex",
|
|
329
|
-
"href",
|
|
330
|
-
"hsl",
|
|
331
|
-
"hsla",
|
|
332
|
-
"icon",
|
|
333
|
-
"id",
|
|
334
|
-
"index",
|
|
335
|
-
"key",
|
|
336
|
-
"language",
|
|
337
|
-
"layout",
|
|
338
|
-
"link",
|
|
339
|
-
"linkAction",
|
|
340
|
-
"locale",
|
|
341
|
-
"lqip",
|
|
342
|
-
"page",
|
|
343
|
-
"path",
|
|
344
|
-
"ref",
|
|
345
|
-
"rgb",
|
|
346
|
-
"rgba",
|
|
347
|
-
"route",
|
|
348
|
-
"secret",
|
|
349
|
-
"slug",
|
|
350
|
-
"status",
|
|
351
|
-
"tag",
|
|
352
|
-
"template",
|
|
353
|
-
"theme",
|
|
354
|
-
"type",
|
|
355
|
-
"unit",
|
|
356
|
-
"url",
|
|
357
|
-
"username",
|
|
358
|
-
"variant",
|
|
359
|
-
"website"
|
|
360
|
-
]);
|
|
361
|
-
function isValidDate(dateString) {
|
|
362
|
-
return /^\d{4}-\d{2}-\d{2}/.test(dateString) ? Boolean(Date.parse(dateString)) : false;
|
|
363
|
-
}
|
|
364
|
-
function isValidURL(url) {
|
|
365
|
-
try {
|
|
366
|
-
new URL(url, url.startsWith("/") ? "https://acme.com" : void 0);
|
|
367
|
-
} catch {
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
return true;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const TRUNCATE_LENGTH = 20;
|
|
374
|
-
function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
375
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
376
|
-
const { filter, logger, enabled } = config;
|
|
377
|
-
if (!enabled) {
|
|
378
|
-
const msg = "config.enabled must be true, don't call this function otherwise";
|
|
379
|
-
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config });
|
|
380
|
-
throw new TypeError(msg);
|
|
381
|
-
}
|
|
382
|
-
if (!resultSourceMap) {
|
|
383
|
-
(_b = logger == null ? void 0 : logger.error) == null ? void 0 : _b.call(logger, "[@sanity/client]: Missing Content Source Map from response body", {
|
|
384
|
-
result,
|
|
385
|
-
resultSourceMap,
|
|
386
|
-
config
|
|
387
|
-
});
|
|
388
|
-
return result;
|
|
389
|
-
}
|
|
390
|
-
if (!config.studioUrl) {
|
|
391
|
-
const msg = "config.studioUrl must be defined";
|
|
392
|
-
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config });
|
|
393
|
-
throw new TypeError(msg);
|
|
394
|
-
}
|
|
395
|
-
const report = {
|
|
396
|
-
encoded: [],
|
|
397
|
-
skipped: []
|
|
398
|
-
};
|
|
399
|
-
const resultWithStega = encodeIntoResult(
|
|
400
|
-
result,
|
|
401
|
-
resultSourceMap,
|
|
402
|
-
({ sourcePath, sourceDocument, resultPath, value }) => {
|
|
403
|
-
if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) {
|
|
404
|
-
if (logger) {
|
|
405
|
-
report.skipped.push({
|
|
406
|
-
path: prettyPathForLogging(sourcePath),
|
|
407
|
-
value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
|
|
408
|
-
length: value.length
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
return value;
|
|
412
|
-
}
|
|
413
|
-
if (logger) {
|
|
414
|
-
report.encoded.push({
|
|
415
|
-
path: prettyPathForLogging(sourcePath),
|
|
416
|
-
value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
|
|
417
|
-
length: value.length
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
|
|
421
|
-
typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl
|
|
422
|
-
);
|
|
423
|
-
if (!baseUrl)
|
|
424
|
-
return value;
|
|
425
|
-
const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
|
|
426
|
-
return b(
|
|
427
|
-
value,
|
|
428
|
-
{
|
|
429
|
-
origin: "sanity.io",
|
|
430
|
-
href: createEditUrl({
|
|
431
|
-
baseUrl,
|
|
432
|
-
workspace,
|
|
433
|
-
tool,
|
|
434
|
-
id,
|
|
435
|
-
type,
|
|
436
|
-
path: sourcePath,
|
|
437
|
-
...!config.omitCrossDatasetReferenceData && { dataset, projectId }
|
|
438
|
-
})
|
|
439
|
-
},
|
|
440
|
-
// We use custom logic to determine if we should skip encoding
|
|
441
|
-
false
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
);
|
|
445
|
-
if (logger) {
|
|
446
|
-
const isSkipping = report.skipped.length;
|
|
447
|
-
const isEncoding = report.encoded.length;
|
|
448
|
-
if (isSkipping || isEncoding) {
|
|
449
|
-
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d("[@sanity/client]: Encoding source map into result");
|
|
450
|
-
(_e = logger.log) == null ? void 0 : _e.call(
|
|
451
|
-
logger,
|
|
452
|
-
`[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
if (report.encoded.length > 0) {
|
|
456
|
-
(_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, `[@sanity/client]: Table of encoded paths`);
|
|
457
|
-
(_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
|
|
458
|
-
}
|
|
459
|
-
if (report.skipped.length > 0) {
|
|
460
|
-
const skipped = /* @__PURE__ */ new Set();
|
|
461
|
-
for (const { path } of report.skipped) {
|
|
462
|
-
skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
|
|
463
|
-
}
|
|
464
|
-
(_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, `[@sanity/client]: List of skipped paths`, [...skipped.values()]);
|
|
465
|
-
}
|
|
466
|
-
if (isSkipping || isEncoding) {
|
|
467
|
-
(_i = logger == null ? void 0 : logger.groupEnd) == null ? void 0 : _i.call(logger);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
return resultWithStega;
|
|
471
|
-
}
|
|
472
|
-
function prettyPathForLogging(path) {
|
|
473
|
-
return toString(jsonPathToStudioPath(path));
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
var stegaEncodeSourceMap$1 = /*#__PURE__*/Object.freeze({
|
|
477
|
-
__proto__: null,
|
|
478
|
-
stegaEncodeSourceMap: stegaEncodeSourceMap
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
export { encodeIntoResult, stegaEncodeSourceMap, stegaEncodeSourceMap$1 };
|
|
482
|
-
//# sourceMappingURL=stegaEncodeSourceMap-DLon0Yls.js.map
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { b } from './nodeMiddleware-BSZoKrW0.js';
|
|
2
|
-
import { walkMap, resolveMapping, parseJsonPath, resolveStudioBaseRoute, createEditUrl, reKeySegment, toString, jsonPathToStudioPath } from './resolveEditInfo-Cf8D1Agp.js';
|
|
3
|
-
|
|
4
|
-
function encodeIntoResult(result, csm, encoder) {
|
|
5
|
-
return walkMap(result, (value, path) => {
|
|
6
|
-
if (typeof value !== "string") {
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
const resolveMappingResult = resolveMapping(path, csm);
|
|
10
|
-
if (!resolveMappingResult) {
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
const { mapping, matchedPath } = resolveMappingResult;
|
|
14
|
-
if (mapping.type !== "value") {
|
|
15
|
-
return value;
|
|
16
|
-
}
|
|
17
|
-
if (mapping.source.type !== "documentValue") {
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
const sourceDocument = csm.documents[mapping.source.document];
|
|
21
|
-
const sourcePath = csm.paths[mapping.source.path];
|
|
22
|
-
const matchPathSegments = parseJsonPath(matchedPath);
|
|
23
|
-
const sourcePathSegments = parseJsonPath(sourcePath);
|
|
24
|
-
const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
|
|
25
|
-
return encoder({
|
|
26
|
-
sourcePath: fullSourceSegments,
|
|
27
|
-
sourceDocument,
|
|
28
|
-
resultPath: path,
|
|
29
|
-
value
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const filterDefault = ({ sourcePath, value }) => {
|
|
35
|
-
if (isValidDate(value) || isValidURL(value)) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
const endPath = sourcePath.at(-1);
|
|
39
|
-
if (sourcePath.at(-2) === "slug" && endPath === "current") {
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
if (typeof endPath === "string" && endPath.startsWith("_")) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
if (typeof endPath === "number" && sourcePath.at(-2) === "marks") {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
if (endPath === "href" && typeof sourcePath.at(-2) === "number" && sourcePath.at(-3) === "markDefs") {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
if (endPath === "style" || endPath === "listItem") {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
if (sourcePath.some(
|
|
55
|
-
(path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
|
|
56
|
-
)) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
if (typeof endPath === "string" && denylist.has(endPath)) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return true;
|
|
63
|
-
};
|
|
64
|
-
const denylist = /* @__PURE__ */ new Set([
|
|
65
|
-
"color",
|
|
66
|
-
"colour",
|
|
67
|
-
"currency",
|
|
68
|
-
"email",
|
|
69
|
-
"format",
|
|
70
|
-
"gid",
|
|
71
|
-
"hex",
|
|
72
|
-
"href",
|
|
73
|
-
"hsl",
|
|
74
|
-
"hsla",
|
|
75
|
-
"icon",
|
|
76
|
-
"id",
|
|
77
|
-
"index",
|
|
78
|
-
"key",
|
|
79
|
-
"language",
|
|
80
|
-
"layout",
|
|
81
|
-
"link",
|
|
82
|
-
"linkAction",
|
|
83
|
-
"locale",
|
|
84
|
-
"lqip",
|
|
85
|
-
"page",
|
|
86
|
-
"path",
|
|
87
|
-
"ref",
|
|
88
|
-
"rgb",
|
|
89
|
-
"rgba",
|
|
90
|
-
"route",
|
|
91
|
-
"secret",
|
|
92
|
-
"slug",
|
|
93
|
-
"status",
|
|
94
|
-
"tag",
|
|
95
|
-
"template",
|
|
96
|
-
"theme",
|
|
97
|
-
"type",
|
|
98
|
-
"unit",
|
|
99
|
-
"url",
|
|
100
|
-
"username",
|
|
101
|
-
"variant",
|
|
102
|
-
"website"
|
|
103
|
-
]);
|
|
104
|
-
function isValidDate(dateString) {
|
|
105
|
-
return /^\d{4}-\d{2}-\d{2}/.test(dateString) ? Boolean(Date.parse(dateString)) : false;
|
|
106
|
-
}
|
|
107
|
-
function isValidURL(url) {
|
|
108
|
-
try {
|
|
109
|
-
new URL(url, url.startsWith("/") ? "https://acme.com" : void 0);
|
|
110
|
-
} catch {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const TRUNCATE_LENGTH = 20;
|
|
117
|
-
function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
118
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
119
|
-
const { filter, logger, enabled } = config;
|
|
120
|
-
if (!enabled) {
|
|
121
|
-
const msg = "config.enabled must be true, don't call this function otherwise";
|
|
122
|
-
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config });
|
|
123
|
-
throw new TypeError(msg);
|
|
124
|
-
}
|
|
125
|
-
if (!resultSourceMap) {
|
|
126
|
-
(_b = logger == null ? void 0 : logger.error) == null ? void 0 : _b.call(logger, "[@sanity/client]: Missing Content Source Map from response body", {
|
|
127
|
-
result,
|
|
128
|
-
resultSourceMap,
|
|
129
|
-
config
|
|
130
|
-
});
|
|
131
|
-
return result;
|
|
132
|
-
}
|
|
133
|
-
if (!config.studioUrl) {
|
|
134
|
-
const msg = "config.studioUrl must be defined";
|
|
135
|
-
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, `[@sanity/client]: ${msg}`, { result, resultSourceMap, config });
|
|
136
|
-
throw new TypeError(msg);
|
|
137
|
-
}
|
|
138
|
-
const report = {
|
|
139
|
-
encoded: [],
|
|
140
|
-
skipped: []
|
|
141
|
-
};
|
|
142
|
-
const resultWithStega = encodeIntoResult(
|
|
143
|
-
result,
|
|
144
|
-
resultSourceMap,
|
|
145
|
-
({ sourcePath, sourceDocument, resultPath, value }) => {
|
|
146
|
-
if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) {
|
|
147
|
-
if (logger) {
|
|
148
|
-
report.skipped.push({
|
|
149
|
-
path: prettyPathForLogging(sourcePath),
|
|
150
|
-
value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
|
|
151
|
-
length: value.length
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
return value;
|
|
155
|
-
}
|
|
156
|
-
if (logger) {
|
|
157
|
-
report.encoded.push({
|
|
158
|
-
path: prettyPathForLogging(sourcePath),
|
|
159
|
-
value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? "..." : ""}`,
|
|
160
|
-
length: value.length
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
|
|
164
|
-
typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl
|
|
165
|
-
);
|
|
166
|
-
if (!baseUrl)
|
|
167
|
-
return value;
|
|
168
|
-
const { _id: id, _type: type, _projectId: projectId, _dataset: dataset } = sourceDocument;
|
|
169
|
-
return b(
|
|
170
|
-
value,
|
|
171
|
-
{
|
|
172
|
-
origin: "sanity.io",
|
|
173
|
-
href: createEditUrl({
|
|
174
|
-
baseUrl,
|
|
175
|
-
workspace,
|
|
176
|
-
tool,
|
|
177
|
-
id,
|
|
178
|
-
type,
|
|
179
|
-
path: sourcePath,
|
|
180
|
-
...!config.omitCrossDatasetReferenceData && { dataset, projectId }
|
|
181
|
-
})
|
|
182
|
-
},
|
|
183
|
-
// We use custom logic to determine if we should skip encoding
|
|
184
|
-
false
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
if (logger) {
|
|
189
|
-
const isSkipping = report.skipped.length;
|
|
190
|
-
const isEncoding = report.encoded.length;
|
|
191
|
-
if (isSkipping || isEncoding) {
|
|
192
|
-
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d("[@sanity/client]: Encoding source map into result");
|
|
193
|
-
(_e = logger.log) == null ? void 0 : _e.call(
|
|
194
|
-
logger,
|
|
195
|
-
`[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
if (report.encoded.length > 0) {
|
|
199
|
-
(_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, `[@sanity/client]: Table of encoded paths`);
|
|
200
|
-
(_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
|
|
201
|
-
}
|
|
202
|
-
if (report.skipped.length > 0) {
|
|
203
|
-
const skipped = /* @__PURE__ */ new Set();
|
|
204
|
-
for (const { path } of report.skipped) {
|
|
205
|
-
skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
|
|
206
|
-
}
|
|
207
|
-
(_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, `[@sanity/client]: List of skipped paths`, [...skipped.values()]);
|
|
208
|
-
}
|
|
209
|
-
if (isSkipping || isEncoding) {
|
|
210
|
-
(_i = logger == null ? void 0 : logger.groupEnd) == null ? void 0 : _i.call(logger);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return resultWithStega;
|
|
214
|
-
}
|
|
215
|
-
function prettyPathForLogging(path) {
|
|
216
|
-
return toString(jsonPathToStudioPath(path));
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
var stegaEncodeSourceMap$1 = /*#__PURE__*/Object.freeze({
|
|
220
|
-
__proto__: null,
|
|
221
|
-
stegaEncodeSourceMap: stegaEncodeSourceMap
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
export { encodeIntoResult, stegaEncodeSourceMap, stegaEncodeSourceMap$1 };
|
|
225
|
-
//# sourceMappingURL=stegaEncodeSourceMap-DU95idpa.js.map
|