@sanity/client 6.11.2 → 6.11.3
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-hi8PGbSU.cjs → browserMiddleware-1MULg59S.cjs} +377 -420
- package/dist/_chunks/{browserMiddleware-hi8PGbSU.cjs.map → browserMiddleware-1MULg59S.cjs.map} +1 -1
- package/dist/_chunks/{browserMiddleware-eLzHI4Fk.js → browserMiddleware-heyg-fDk.js} +377 -420
- package/dist/_chunks/{browserMiddleware-eLzHI4Fk.js.map → browserMiddleware-heyg-fDk.js.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-SFcV9llR.cjs → nodeMiddleware-CHxg1-zH.cjs} +396 -440
- package/dist/_chunks/{nodeMiddleware-SFcV9llR.cjs.map → nodeMiddleware-CHxg1-zH.cjs.map} +1 -1
- package/dist/_chunks/{nodeMiddleware-dn4ZacKV.js → nodeMiddleware-u_fUUnxa.js} +396 -440
- package/dist/_chunks/{nodeMiddleware-dn4ZacKV.js.map → nodeMiddleware-u_fUUnxa.js.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-TYjTkHKU.cjs → resolveEditInfo-dELeeJBE.cjs} +47 -70
- package/dist/_chunks/{resolveEditInfo-TYjTkHKU.cjs.map → resolveEditInfo-dELeeJBE.cjs.map} +1 -1
- package/dist/_chunks/{resolveEditInfo-FaeuCV4M.js → resolveEditInfo-uXvm6eWd.js} +47 -70
- package/dist/_chunks/{resolveEditInfo-FaeuCV4M.js.map → resolveEditInfo-uXvm6eWd.js.map} +1 -1
- package/dist/csm.cjs +20 -30
- package/dist/csm.cjs.map +1 -1
- package/dist/csm.js +19 -28
- package/dist/csm.js.map +1 -1
- package/dist/index.browser.cjs +8 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +5 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +8 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.cjs +224 -257
- package/dist/stega.browser.cjs.map +1 -1
- package/dist/stega.browser.js +221 -249
- package/dist/stega.browser.js.map +1 -1
- package/dist/stega.cjs +193 -217
- package/dist/stega.cjs.map +1 -1
- package/dist/stega.js +190 -209
- package/dist/stega.js.map +1 -1
- package/package.json +3 -3
- package/umd/sanityClient.js +494 -528
- package/umd/sanityClient.min.js +3 -3
package/dist/stega.browser.cjs
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var browserMiddleware = require('./_chunks/browserMiddleware-hi8PGbSU.cjs');
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var browserMiddleware = require('./_chunks/browserMiddleware-1MULg59S.cjs');
|
|
7
6
|
var operators = require('rxjs/operators');
|
|
8
7
|
var stega = require('@vercel/stega');
|
|
9
8
|
var getIt = require('get-it');
|
|
9
|
+
|
|
10
10
|
const defaultStegaConfig = {
|
|
11
11
|
enabled: false,
|
|
12
|
-
filter: props => props.filterDefault(props)
|
|
12
|
+
filter: (props) => props.filterDefault(props)
|
|
13
13
|
};
|
|
14
14
|
function splitConfig(config) {
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
...clientConfig
|
|
18
|
-
} = config;
|
|
19
|
-
return {
|
|
20
|
-
clientConfig,
|
|
21
|
-
stegaConfig: typeof stega === "boolean" ? {
|
|
22
|
-
enabled: stega
|
|
23
|
-
} : stega
|
|
24
|
-
};
|
|
15
|
+
const { stega = {}, ...clientConfig } = config;
|
|
16
|
+
return { clientConfig, stegaConfig: typeof stega === "boolean" ? { enabled: stega } : stega };
|
|
25
17
|
}
|
|
26
18
|
const initStegaConfig = (config, prevConfig) => {
|
|
27
19
|
const specifiedConfig = Object.assign({}, prevConfig, config);
|
|
28
20
|
const newConfig = Object.assign({}, defaultStegaConfig, specifiedConfig);
|
|
29
21
|
if ("encodeSourceMap" in newConfig) {
|
|
30
|
-
throw new Error(
|
|
22
|
+
throw new Error(
|
|
23
|
+
"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'?"
|
|
24
|
+
);
|
|
31
25
|
}
|
|
32
26
|
if ("encodeSourceMapAtPath" in newConfig) {
|
|
33
|
-
throw new Error(
|
|
27
|
+
throw new Error(
|
|
28
|
+
"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'?"
|
|
29
|
+
);
|
|
34
30
|
}
|
|
35
31
|
if (typeof newConfig.enabled !== "boolean") {
|
|
36
32
|
throw new Error("config.enabled must be a boolean, received ".concat(newConfig.enabled));
|
|
@@ -39,23 +35,21 @@ const initStegaConfig = (config, prevConfig) => {
|
|
|
39
35
|
throw new Error("config.studioUrl must be defined when config.enabled is true");
|
|
40
36
|
}
|
|
41
37
|
if (newConfig.enabled && typeof newConfig.studioUrl !== "string" && typeof newConfig.studioUrl !== "function") {
|
|
42
|
-
throw new Error(
|
|
38
|
+
throw new Error(
|
|
39
|
+
"config.studioUrl must be a string or a function, received ".concat(newConfig.studioUrl)
|
|
40
|
+
);
|
|
43
41
|
}
|
|
44
42
|
return newConfig;
|
|
45
43
|
};
|
|
46
44
|
function splitStegaConfigFromFetchOptions(options, initializedStegaConfig) {
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} : stega, initializedStegaConfig);
|
|
54
|
-
return {
|
|
55
|
-
fetchOptions,
|
|
56
|
-
stegaConfig
|
|
57
|
-
};
|
|
45
|
+
const { stega = {}, ...fetchOptions } = options;
|
|
46
|
+
const stegaConfig = initStegaConfig(
|
|
47
|
+
typeof stega === "boolean" ? { enabled: stega } : stega,
|
|
48
|
+
initializedStegaConfig
|
|
49
|
+
);
|
|
50
|
+
return { fetchOptions, stegaConfig };
|
|
58
51
|
}
|
|
52
|
+
|
|
59
53
|
const DRAFTS_PREFIX = "drafts.";
|
|
60
54
|
function getPublishedId(id) {
|
|
61
55
|
if (id.startsWith(DRAFTS_PREFIX)) {
|
|
@@ -63,6 +57,7 @@ function getPublishedId(id) {
|
|
|
63
57
|
}
|
|
64
58
|
return id;
|
|
65
59
|
}
|
|
60
|
+
|
|
66
61
|
const reKeySegment = /_key\s*==\s*['"](.*)['"]/;
|
|
67
62
|
function isKeySegment(segment) {
|
|
68
63
|
if (typeof segment === "string") {
|
|
@@ -93,6 +88,7 @@ function toString(path) {
|
|
|
93
88
|
throw new Error("Unsupported path segment `".concat(JSON.stringify(segment), "`"));
|
|
94
89
|
}, "");
|
|
95
90
|
}
|
|
91
|
+
|
|
96
92
|
const ESCAPE = {
|
|
97
93
|
"\f": "\\f",
|
|
98
94
|
"\n": "\\n",
|
|
@@ -110,9 +106,9 @@ const UNESCAPE = {
|
|
|
110
106
|
"\\\\": "\\"
|
|
111
107
|
};
|
|
112
108
|
function jsonPath(path) {
|
|
113
|
-
return "$".concat(path.map(segment => {
|
|
109
|
+
return "$".concat(path.map((segment) => {
|
|
114
110
|
if (typeof segment === "string") {
|
|
115
|
-
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, match => {
|
|
111
|
+
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, (match) => {
|
|
116
112
|
return ESCAPE[match];
|
|
117
113
|
});
|
|
118
114
|
return "['".concat(escapedKey, "']");
|
|
@@ -121,7 +117,7 @@ function jsonPath(path) {
|
|
|
121
117
|
return "[".concat(segment, "]");
|
|
122
118
|
}
|
|
123
119
|
if (segment._key !== "") {
|
|
124
|
-
const escapedKey = segment._key.replace(/['\\]/g, match => {
|
|
120
|
+
const escapedKey = segment._key.replace(/['\\]/g, (match) => {
|
|
125
121
|
return ESCAPE[match];
|
|
126
122
|
});
|
|
127
123
|
return "[?(@._key=='".concat(escapedKey, "')]");
|
|
@@ -135,7 +131,7 @@ function parseJsonPath(path) {
|
|
|
135
131
|
let match;
|
|
136
132
|
while ((match = parseRe.exec(path)) !== null) {
|
|
137
133
|
if (match[1] !== void 0) {
|
|
138
|
-
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, m => {
|
|
134
|
+
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, (m) => {
|
|
139
135
|
return UNESCAPE[m];
|
|
140
136
|
});
|
|
141
137
|
parsed.push(key);
|
|
@@ -146,7 +142,7 @@ function parseJsonPath(path) {
|
|
|
146
142
|
continue;
|
|
147
143
|
}
|
|
148
144
|
if (match[3] !== void 0) {
|
|
149
|
-
const _key = match[3].replace(/\\(\\')/g, m => {
|
|
145
|
+
const _key = match[3].replace(/\\(\\')/g, (m) => {
|
|
150
146
|
return UNESCAPE[m];
|
|
151
147
|
});
|
|
152
148
|
parsed.push({
|
|
@@ -159,7 +155,7 @@ function parseJsonPath(path) {
|
|
|
159
155
|
return parsed;
|
|
160
156
|
}
|
|
161
157
|
function jsonPathToStudioPath(path) {
|
|
162
|
-
return path.map(segment => {
|
|
158
|
+
return path.map((segment) => {
|
|
163
159
|
if (typeof segment === "string") {
|
|
164
160
|
return segment;
|
|
165
161
|
}
|
|
@@ -167,9 +163,7 @@ function jsonPathToStudioPath(path) {
|
|
|
167
163
|
return segment;
|
|
168
164
|
}
|
|
169
165
|
if (segment._key !== "") {
|
|
170
|
-
return {
|
|
171
|
-
_key: segment._key
|
|
172
|
-
};
|
|
166
|
+
return { _key: segment._key };
|
|
173
167
|
}
|
|
174
168
|
if (segment._index !== -1) {
|
|
175
169
|
return segment._index;
|
|
@@ -178,7 +172,7 @@ function jsonPathToStudioPath(path) {
|
|
|
178
172
|
});
|
|
179
173
|
}
|
|
180
174
|
function jsonPathToMappingPath(path) {
|
|
181
|
-
return path.map(segment => {
|
|
175
|
+
return path.map((segment) => {
|
|
182
176
|
if (typeof segment === "string") {
|
|
183
177
|
return segment;
|
|
184
178
|
}
|
|
@@ -191,6 +185,7 @@ function jsonPathToMappingPath(path) {
|
|
|
191
185
|
throw new Error("invalid segment:".concat(JSON.stringify(segment)));
|
|
192
186
|
});
|
|
193
187
|
}
|
|
188
|
+
|
|
194
189
|
function createEditUrl(options) {
|
|
195
190
|
const {
|
|
196
191
|
baseUrl,
|
|
@@ -232,13 +227,19 @@ function createEditUrl(options) {
|
|
|
232
227
|
if (workspace) {
|
|
233
228
|
segments.push(workspace);
|
|
234
229
|
}
|
|
235
|
-
const routerParams = [
|
|
230
|
+
const routerParams = [
|
|
231
|
+
"mode=presentation",
|
|
232
|
+
"id=".concat(id),
|
|
233
|
+
"type=".concat(type),
|
|
234
|
+
"path=".concat(encodeURIComponent(stringifiedPath))
|
|
235
|
+
];
|
|
236
236
|
if (tool) {
|
|
237
237
|
routerParams.push("tool=".concat(tool));
|
|
238
238
|
}
|
|
239
239
|
segments.push("intent", "edit", "".concat(routerParams.join(";"), "?").concat(searchParams));
|
|
240
240
|
return segments.join("/");
|
|
241
241
|
}
|
|
242
|
+
|
|
242
243
|
function resolveMapping(resultPath, csm) {
|
|
243
244
|
if (!(csm == null ? void 0 : csm.mappings)) {
|
|
244
245
|
return void 0;
|
|
@@ -251,70 +252,54 @@ function resolveMapping(resultPath, csm) {
|
|
|
251
252
|
pathSuffix: ""
|
|
252
253
|
};
|
|
253
254
|
}
|
|
254
|
-
const mappings = Object.entries(csm.mappings).filter(
|
|
255
|
-
let [key] = _ref;
|
|
256
|
-
return resultMappingPath.startsWith(key);
|
|
257
|
-
}).sort((_ref2, _ref3) => {
|
|
258
|
-
let [key1] = _ref2;
|
|
259
|
-
let [key2] = _ref3;
|
|
260
|
-
return key2.length - key1.length;
|
|
261
|
-
});
|
|
255
|
+
const mappings = Object.entries(csm.mappings).filter(([key]) => resultMappingPath.startsWith(key)).sort(([key1], [key2]) => key2.length - key1.length);
|
|
262
256
|
if (mappings.length == 0) {
|
|
263
257
|
return void 0;
|
|
264
258
|
}
|
|
265
259
|
const [matchedPath, mapping] = mappings[0];
|
|
266
260
|
const pathSuffix = resultMappingPath.substring(matchedPath.length);
|
|
267
|
-
return {
|
|
268
|
-
mapping,
|
|
269
|
-
matchedPath,
|
|
270
|
-
pathSuffix
|
|
271
|
-
};
|
|
261
|
+
return { mapping, matchedPath, pathSuffix };
|
|
272
262
|
}
|
|
263
|
+
|
|
273
264
|
function resolveStudioBaseRoute(studioUrl) {
|
|
274
265
|
let baseUrl = typeof studioUrl === "string" ? studioUrl : studioUrl.baseUrl;
|
|
275
266
|
if (baseUrl !== "/") {
|
|
276
267
|
baseUrl = baseUrl.replace(/\/$/, "");
|
|
277
268
|
}
|
|
278
269
|
if (typeof studioUrl === "string") {
|
|
279
|
-
return {
|
|
280
|
-
baseUrl
|
|
281
|
-
};
|
|
270
|
+
return { baseUrl };
|
|
282
271
|
}
|
|
283
|
-
return {
|
|
284
|
-
...studioUrl,
|
|
285
|
-
baseUrl
|
|
286
|
-
};
|
|
272
|
+
return { ...studioUrl, baseUrl };
|
|
287
273
|
}
|
|
274
|
+
|
|
288
275
|
function isArray(value) {
|
|
289
276
|
return value !== null && Array.isArray(value);
|
|
290
277
|
}
|
|
278
|
+
|
|
291
279
|
function isRecord(value) {
|
|
292
280
|
return typeof value === "object" && value !== null;
|
|
293
281
|
}
|
|
294
|
-
|
|
295
|
-
|
|
282
|
+
|
|
283
|
+
function walkMap(value, mappingFn, path = []) {
|
|
296
284
|
if (isArray(value)) {
|
|
297
285
|
return value.map((v, idx) => {
|
|
298
286
|
if (isRecord(v)) {
|
|
299
287
|
const _key = v["_key"];
|
|
300
288
|
if (typeof _key === "string") {
|
|
301
|
-
return walkMap(v, mappingFn, path.concat({
|
|
302
|
-
_key,
|
|
303
|
-
_index: idx
|
|
304
|
-
}));
|
|
289
|
+
return walkMap(v, mappingFn, path.concat({ _key, _index: idx }));
|
|
305
290
|
}
|
|
306
291
|
}
|
|
307
292
|
return walkMap(v, mappingFn, path.concat(idx));
|
|
308
293
|
});
|
|
309
294
|
}
|
|
310
295
|
if (isRecord(value)) {
|
|
311
|
-
return Object.fromEntries(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}));
|
|
296
|
+
return Object.fromEntries(
|
|
297
|
+
Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))])
|
|
298
|
+
);
|
|
315
299
|
}
|
|
316
300
|
return mappingFn(value, path);
|
|
317
301
|
}
|
|
302
|
+
|
|
318
303
|
function encodeIntoResult(result, csm, encoder) {
|
|
319
304
|
return walkMap(result, (value, path) => {
|
|
320
305
|
if (typeof value !== "string") {
|
|
@@ -324,10 +309,7 @@ function encodeIntoResult(result, csm, encoder) {
|
|
|
324
309
|
if (!resolveMappingResult) {
|
|
325
310
|
return value;
|
|
326
311
|
}
|
|
327
|
-
const {
|
|
328
|
-
mapping,
|
|
329
|
-
matchedPath
|
|
330
|
-
} = resolveMappingResult;
|
|
312
|
+
const { mapping, matchedPath } = resolveMappingResult;
|
|
331
313
|
if (mapping.type !== "value") {
|
|
332
314
|
return value;
|
|
333
315
|
}
|
|
@@ -347,11 +329,8 @@ function encodeIntoResult(result, csm, encoder) {
|
|
|
347
329
|
});
|
|
348
330
|
});
|
|
349
331
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
sourcePath,
|
|
353
|
-
value
|
|
354
|
-
} = _ref5;
|
|
332
|
+
|
|
333
|
+
const filterDefault = ({ sourcePath, value }) => {
|
|
355
334
|
if (isValidDate(value) || isValidURL(value)) {
|
|
356
335
|
return false;
|
|
357
336
|
}
|
|
@@ -371,7 +350,9 @@ const filterDefault = _ref5 => {
|
|
|
371
350
|
if (endPath === "style" || endPath === "listItem") {
|
|
372
351
|
return false;
|
|
373
352
|
}
|
|
374
|
-
if (sourcePath.some(
|
|
353
|
+
if (sourcePath.some(
|
|
354
|
+
(path) => path === "meta" || path === "metadata" || path === "openGraph" || path === "seo"
|
|
355
|
+
)) {
|
|
375
356
|
return false;
|
|
376
357
|
}
|
|
377
358
|
if (typeof endPath === "string" && denylist.has(endPath)) {
|
|
@@ -379,7 +360,46 @@ const filterDefault = _ref5 => {
|
|
|
379
360
|
}
|
|
380
361
|
return true;
|
|
381
362
|
};
|
|
382
|
-
const denylist = /* @__PURE__ */new Set([
|
|
363
|
+
const denylist = /* @__PURE__ */ new Set([
|
|
364
|
+
"color",
|
|
365
|
+
"colour",
|
|
366
|
+
"currency",
|
|
367
|
+
"email",
|
|
368
|
+
"format",
|
|
369
|
+
"gid",
|
|
370
|
+
"hex",
|
|
371
|
+
"href",
|
|
372
|
+
"hsl",
|
|
373
|
+
"hsla",
|
|
374
|
+
"icon",
|
|
375
|
+
"id",
|
|
376
|
+
"index",
|
|
377
|
+
"key",
|
|
378
|
+
"language",
|
|
379
|
+
"layout",
|
|
380
|
+
"link",
|
|
381
|
+
"linkAction",
|
|
382
|
+
"locale",
|
|
383
|
+
"lqip",
|
|
384
|
+
"page",
|
|
385
|
+
"path",
|
|
386
|
+
"ref",
|
|
387
|
+
"rgb",
|
|
388
|
+
"rgba",
|
|
389
|
+
"route",
|
|
390
|
+
"secret",
|
|
391
|
+
"slug",
|
|
392
|
+
"status",
|
|
393
|
+
"tag",
|
|
394
|
+
"template",
|
|
395
|
+
"theme",
|
|
396
|
+
"type",
|
|
397
|
+
"unit",
|
|
398
|
+
"url",
|
|
399
|
+
"username",
|
|
400
|
+
"variant",
|
|
401
|
+
"website"
|
|
402
|
+
]);
|
|
383
403
|
function isValidDate(dateString) {
|
|
384
404
|
return Number.isNaN(Number(dateString)) ? Boolean(Date.parse(dateString)) : false;
|
|
385
405
|
}
|
|
@@ -391,21 +411,14 @@ function isValidURL(url) {
|
|
|
391
411
|
}
|
|
392
412
|
return true;
|
|
393
413
|
}
|
|
414
|
+
|
|
394
415
|
const TRUNCATE_LENGTH = 20;
|
|
395
416
|
function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
396
417
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
397
|
-
const {
|
|
398
|
-
filter,
|
|
399
|
-
logger,
|
|
400
|
-
enabled
|
|
401
|
-
} = config;
|
|
418
|
+
const { filter, logger, enabled } = config;
|
|
402
419
|
if (!enabled) {
|
|
403
420
|
const msg = "config.enabled must be true, don't call this function otherwise";
|
|
404
|
-
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), {
|
|
405
|
-
result,
|
|
406
|
-
resultSourceMap,
|
|
407
|
-
config
|
|
408
|
-
});
|
|
421
|
+
(_a = logger == null ? void 0 : logger.error) == null ? void 0 : _a.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
|
|
409
422
|
throw new TypeError(msg);
|
|
410
423
|
}
|
|
411
424
|
if (!resultSourceMap) {
|
|
@@ -418,93 +431,77 @@ function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
|
418
431
|
}
|
|
419
432
|
if (!config.studioUrl) {
|
|
420
433
|
const msg = "config.studioUrl must be defined";
|
|
421
|
-
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), {
|
|
422
|
-
result,
|
|
423
|
-
resultSourceMap,
|
|
424
|
-
config
|
|
425
|
-
});
|
|
434
|
+
(_c = logger == null ? void 0 : logger.error) == null ? void 0 : _c.call(logger, "[@sanity/client/stega]: ".concat(msg), { result, resultSourceMap, config });
|
|
426
435
|
throw new TypeError(msg);
|
|
427
436
|
}
|
|
428
437
|
const report = {
|
|
429
438
|
encoded: [],
|
|
430
439
|
skipped: []
|
|
431
440
|
};
|
|
432
|
-
const resultWithStega = encodeIntoResult(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
resultPath,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
sourcePath,
|
|
447
|
-
resultPath,
|
|
448
|
-
filterDefault,
|
|
449
|
-
sourceDocument,
|
|
450
|
-
value
|
|
451
|
-
})) === false) {
|
|
441
|
+
const resultWithStega = encodeIntoResult(
|
|
442
|
+
result,
|
|
443
|
+
resultSourceMap,
|
|
444
|
+
({ sourcePath, sourceDocument, resultPath, value }) => {
|
|
445
|
+
if ((typeof filter === "function" ? filter({ sourcePath, resultPath, filterDefault, sourceDocument, value }) : filterDefault({ sourcePath, resultPath, filterDefault, sourceDocument, value })) === false) {
|
|
446
|
+
if (logger) {
|
|
447
|
+
report.skipped.push({
|
|
448
|
+
path: prettyPathForLogging(sourcePath),
|
|
449
|
+
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
|
|
450
|
+
length: value.length
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
return value;
|
|
454
|
+
}
|
|
452
455
|
if (logger) {
|
|
453
|
-
report.
|
|
456
|
+
report.encoded.push({
|
|
454
457
|
path: prettyPathForLogging(sourcePath),
|
|
455
458
|
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
|
|
456
459
|
length: value.length
|
|
457
460
|
});
|
|
458
461
|
}
|
|
459
|
-
|
|
462
|
+
const { baseUrl, workspace, tool } = resolveStudioBaseRoute(
|
|
463
|
+
typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl
|
|
464
|
+
);
|
|
465
|
+
if (!baseUrl)
|
|
466
|
+
return value;
|
|
467
|
+
const { _id: id, _type: type } = sourceDocument;
|
|
468
|
+
return stega.vercelStegaCombine(
|
|
469
|
+
value,
|
|
470
|
+
{
|
|
471
|
+
origin: "sanity.io",
|
|
472
|
+
href: createEditUrl({
|
|
473
|
+
baseUrl,
|
|
474
|
+
workspace,
|
|
475
|
+
tool,
|
|
476
|
+
id,
|
|
477
|
+
type,
|
|
478
|
+
path: sourcePath
|
|
479
|
+
})
|
|
480
|
+
},
|
|
481
|
+
// We use custom logic to determine if we should skip encoding
|
|
482
|
+
false
|
|
483
|
+
);
|
|
460
484
|
}
|
|
461
|
-
|
|
462
|
-
report.encoded.push({
|
|
463
|
-
path: prettyPathForLogging(sourcePath),
|
|
464
|
-
value: "".concat(value.slice(0, TRUNCATE_LENGTH)).concat(value.length > TRUNCATE_LENGTH ? "..." : ""),
|
|
465
|
-
length: value.length
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
const {
|
|
469
|
-
baseUrl,
|
|
470
|
-
workspace,
|
|
471
|
-
tool
|
|
472
|
-
} = resolveStudioBaseRoute(typeof config.studioUrl === "function" ? config.studioUrl(sourceDocument) : config.studioUrl);
|
|
473
|
-
if (!baseUrl) return value;
|
|
474
|
-
const {
|
|
475
|
-
_id: id,
|
|
476
|
-
_type: type
|
|
477
|
-
} = sourceDocument;
|
|
478
|
-
return stega.vercelStegaCombine(value, {
|
|
479
|
-
origin: "sanity.io",
|
|
480
|
-
href: createEditUrl({
|
|
481
|
-
baseUrl,
|
|
482
|
-
workspace,
|
|
483
|
-
tool,
|
|
484
|
-
id,
|
|
485
|
-
type,
|
|
486
|
-
path: sourcePath
|
|
487
|
-
})
|
|
488
|
-
},
|
|
489
|
-
// We use custom logic to determine if we should skip encoding
|
|
490
|
-
false);
|
|
491
|
-
});
|
|
485
|
+
);
|
|
492
486
|
if (logger) {
|
|
493
487
|
const isSkipping = report.skipped.length;
|
|
494
488
|
const isEncoding = report.encoded.length;
|
|
495
489
|
if (isSkipping || isEncoding) {
|
|
496
|
-
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d(
|
|
497
|
-
|
|
490
|
+
(_d = (logger == null ? void 0 : logger.groupCollapsed) || logger.log) == null ? void 0 : _d(
|
|
491
|
+
"[@sanity/client/stega]: Encoding source map into result"
|
|
492
|
+
);
|
|
493
|
+
(_e = logger.log) == null ? void 0 : _e.call(
|
|
494
|
+
logger,
|
|
495
|
+
"[@sanity/client/stega]: Paths encoded: ".concat(report.encoded.length, ", skipped: ").concat(report.skipped.length)
|
|
496
|
+
);
|
|
498
497
|
}
|
|
499
498
|
if (report.encoded.length > 0) {
|
|
500
499
|
(_f = logger == null ? void 0 : logger.log) == null ? void 0 : _f.call(logger, "[@sanity/client/stega]: Table of encoded paths");
|
|
501
500
|
(_g = (logger == null ? void 0 : logger.table) || logger.log) == null ? void 0 : _g(report.encoded);
|
|
502
501
|
}
|
|
503
502
|
if (report.skipped.length > 0) {
|
|
504
|
-
const skipped = /* @__PURE__ */new Set();
|
|
505
|
-
for (const {
|
|
506
|
-
path
|
|
507
|
-
} of report.skipped) {
|
|
503
|
+
const skipped = /* @__PURE__ */ new Set();
|
|
504
|
+
for (const { path } of report.skipped) {
|
|
508
505
|
skipped.add(path.replace(reKeySegment, "0").replace(/\[\d+\]/g, "[]"));
|
|
509
506
|
}
|
|
510
507
|
(_h = logger == null ? void 0 : logger.log) == null ? void 0 : _h.call(logger, "[@sanity/client/stega]: List of skipped paths", [...skipped.values()]);
|
|
@@ -518,25 +515,32 @@ function stegaEncodeSourceMap(result, resultSourceMap, config) {
|
|
|
518
515
|
function prettyPathForLogging(path) {
|
|
519
516
|
return toString(jsonPathToStudioPath(path));
|
|
520
517
|
}
|
|
518
|
+
|
|
521
519
|
function vercelStegaCleanAll(result) {
|
|
522
520
|
try {
|
|
523
|
-
return JSON.parse(
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
521
|
+
return JSON.parse(
|
|
522
|
+
JSON.stringify(result, (key, value) => {
|
|
523
|
+
if (typeof value !== "string")
|
|
524
|
+
return value;
|
|
525
|
+
return stega.vercelStegaSplit(value).cleaned;
|
|
526
|
+
})
|
|
527
|
+
);
|
|
527
528
|
} catch {
|
|
528
529
|
return result;
|
|
529
530
|
}
|
|
530
531
|
}
|
|
532
|
+
|
|
531
533
|
var __accessCheck = (obj, member, msg) => {
|
|
532
|
-
if (!member.has(obj))
|
|
534
|
+
if (!member.has(obj))
|
|
535
|
+
throw TypeError("Cannot " + msg);
|
|
533
536
|
};
|
|
534
537
|
var __privateGet = (obj, member, getter) => {
|
|
535
538
|
__accessCheck(obj, member, "read from private field");
|
|
536
539
|
return getter ? getter.call(obj) : member.get(obj);
|
|
537
540
|
};
|
|
538
541
|
var __privateAdd = (obj, member, value) => {
|
|
539
|
-
if (member.has(obj))
|
|
542
|
+
if (member.has(obj))
|
|
543
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
540
544
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
541
545
|
};
|
|
542
546
|
var __privateSet = (obj, member, value, setter) => {
|
|
@@ -546,12 +550,8 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
546
550
|
};
|
|
547
551
|
var _httpRequest, _httpRequest2;
|
|
548
552
|
const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends browserMiddleware.ObservableSanityClient {
|
|
549
|
-
constructor(httpRequest) {
|
|
550
|
-
|
|
551
|
-
const {
|
|
552
|
-
clientConfig,
|
|
553
|
-
stegaConfig
|
|
554
|
-
} = splitConfig(config);
|
|
553
|
+
constructor(httpRequest, config = browserMiddleware.defaultConfig) {
|
|
554
|
+
const { clientConfig, stegaConfig } = splitConfig(config);
|
|
555
555
|
super(httpRequest, clientConfig);
|
|
556
556
|
/**
|
|
557
557
|
* Private properties
|
|
@@ -568,17 +568,9 @@ const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends
|
|
|
568
568
|
}
|
|
569
569
|
config(newConfig) {
|
|
570
570
|
if (newConfig === void 0) {
|
|
571
|
-
return {
|
|
572
|
-
...super.config(),
|
|
573
|
-
stega: {
|
|
574
|
-
...this.stegaConfig
|
|
575
|
-
}
|
|
576
|
-
};
|
|
571
|
+
return { ...super.config(), stega: { ...this.stegaConfig } };
|
|
577
572
|
}
|
|
578
|
-
const {
|
|
579
|
-
clientConfig,
|
|
580
|
-
stegaConfig
|
|
581
|
-
} = splitConfig(newConfig);
|
|
573
|
+
const { clientConfig, stegaConfig } = splitConfig(newConfig);
|
|
582
574
|
super.config(clientConfig);
|
|
583
575
|
this.stegaConfig = initStegaConfig(stegaConfig, this.stegaConfig || {});
|
|
584
576
|
return this;
|
|
@@ -590,56 +582,47 @@ const _ObservableSanityStegaClient = class _ObservableSanityStegaClient extends
|
|
|
590
582
|
*/
|
|
591
583
|
withConfig(newConfig) {
|
|
592
584
|
const thisConfig = this.config();
|
|
593
|
-
const {
|
|
594
|
-
stegaConfig
|
|
595
|
-
} = splitConfig(newConfig || {});
|
|
585
|
+
const { stegaConfig } = splitConfig(newConfig || {});
|
|
596
586
|
return new _ObservableSanityStegaClient(__privateGet(this, _httpRequest), {
|
|
597
587
|
...thisConfig,
|
|
598
588
|
...newConfig,
|
|
599
589
|
stega: {
|
|
600
|
-
...
|
|
601
|
-
...
|
|
590
|
+
...thisConfig.stega || {},
|
|
591
|
+
...stegaConfig || {}
|
|
602
592
|
}
|
|
603
593
|
});
|
|
604
594
|
}
|
|
605
|
-
fetch(query, _params) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
stegaConfig
|
|
609
|
-
|
|
610
|
-
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig);
|
|
595
|
+
fetch(query, _params, _options = {}) {
|
|
596
|
+
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions(
|
|
597
|
+
_options,
|
|
598
|
+
this.stegaConfig
|
|
599
|
+
);
|
|
611
600
|
const params = _params ? vercelStegaCleanAll(_params) : _params;
|
|
612
601
|
if (!stegaConfig.enabled) {
|
|
613
602
|
return super.fetch(query, params, options);
|
|
614
603
|
}
|
|
615
|
-
const {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
};
|
|
631
|
-
}));
|
|
604
|
+
const { filterResponse: originalFilterResponse = true } = options;
|
|
605
|
+
return super.fetch(
|
|
606
|
+
query,
|
|
607
|
+
params,
|
|
608
|
+
Object.assign({}, options, {
|
|
609
|
+
filterResponse: false,
|
|
610
|
+
resultSourceMap: "withKeyArraySelector"
|
|
611
|
+
})
|
|
612
|
+
).pipe(
|
|
613
|
+
operators.map((res) => {
|
|
614
|
+
const { result: _result, resultSourceMap } = res;
|
|
615
|
+
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig);
|
|
616
|
+
return originalFilterResponse ? result : { ...res, result };
|
|
617
|
+
})
|
|
618
|
+
);
|
|
632
619
|
}
|
|
633
620
|
};
|
|
634
621
|
_httpRequest = new WeakMap();
|
|
635
622
|
let ObservableSanityStegaClient = _ObservableSanityStegaClient;
|
|
636
623
|
const _SanityStegaClient = class _SanityStegaClient extends browserMiddleware.SanityClient {
|
|
637
|
-
constructor(httpRequest) {
|
|
638
|
-
|
|
639
|
-
const {
|
|
640
|
-
clientConfig,
|
|
641
|
-
stegaConfig
|
|
642
|
-
} = splitConfig(config);
|
|
624
|
+
constructor(httpRequest, config = browserMiddleware.defaultConfig) {
|
|
625
|
+
const { clientConfig, stegaConfig } = splitConfig(config);
|
|
643
626
|
super(httpRequest, clientConfig);
|
|
644
627
|
/**
|
|
645
628
|
* Private properties
|
|
@@ -657,21 +640,11 @@ const _SanityStegaClient = class _SanityStegaClient extends browserMiddleware.Sa
|
|
|
657
640
|
}
|
|
658
641
|
config(newConfig) {
|
|
659
642
|
if (newConfig === void 0) {
|
|
660
|
-
return {
|
|
661
|
-
...super.config(),
|
|
662
|
-
stega: {
|
|
663
|
-
...this.stegaConfig
|
|
664
|
-
}
|
|
665
|
-
};
|
|
643
|
+
return { ...super.config(), stega: { ...this.stegaConfig } };
|
|
666
644
|
}
|
|
667
|
-
const {
|
|
668
|
-
clientConfig,
|
|
669
|
-
stegaConfig
|
|
670
|
-
} = splitConfig(newConfig);
|
|
645
|
+
const { clientConfig, stegaConfig } = splitConfig(newConfig);
|
|
671
646
|
super.config(clientConfig);
|
|
672
|
-
this.stegaConfig = initStegaConfig(stegaConfig, {
|
|
673
|
-
...(this.stegaConfig || {})
|
|
674
|
-
});
|
|
647
|
+
this.stegaConfig = initStegaConfig(stegaConfig, { ...this.stegaConfig || {} });
|
|
675
648
|
return this;
|
|
676
649
|
}
|
|
677
650
|
/**
|
|
@@ -681,52 +654,50 @@ const _SanityStegaClient = class _SanityStegaClient extends browserMiddleware.Sa
|
|
|
681
654
|
*/
|
|
682
655
|
withConfig(newConfig) {
|
|
683
656
|
const thisConfig = this.config();
|
|
684
|
-
const {
|
|
685
|
-
stegaConfig
|
|
686
|
-
} = splitConfig(newConfig || {});
|
|
657
|
+
const { stegaConfig } = splitConfig(newConfig || {});
|
|
687
658
|
return new _SanityStegaClient(__privateGet(this, _httpRequest2), {
|
|
688
659
|
...thisConfig,
|
|
689
660
|
...newConfig,
|
|
690
661
|
stega: {
|
|
691
|
-
...
|
|
692
|
-
...
|
|
662
|
+
...thisConfig.stega || {},
|
|
663
|
+
...stegaConfig || {}
|
|
693
664
|
}
|
|
694
665
|
});
|
|
695
666
|
}
|
|
696
|
-
fetch(query, _params) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
stegaConfig
|
|
700
|
-
|
|
701
|
-
} = splitStegaConfigFromFetchOptions(_options, this.stegaConfig);
|
|
667
|
+
fetch(query, _params, _options = {}) {
|
|
668
|
+
const { stegaConfig, fetchOptions: options } = splitStegaConfigFromFetchOptions(
|
|
669
|
+
_options,
|
|
670
|
+
this.stegaConfig
|
|
671
|
+
);
|
|
702
672
|
const params = _params ? vercelStegaCleanAll(_params) : _params;
|
|
703
673
|
if (!stegaConfig.enabled) {
|
|
704
674
|
return super.fetch(query, params, options);
|
|
705
675
|
}
|
|
706
|
-
const {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
} = res;
|
|
676
|
+
const { filterResponse: originalFilterResponse = true } = options;
|
|
677
|
+
return super.fetch(
|
|
678
|
+
query,
|
|
679
|
+
params,
|
|
680
|
+
Object.assign({}, options, {
|
|
681
|
+
filterResponse: false,
|
|
682
|
+
resultSourceMap: "withKeyArraySelector"
|
|
683
|
+
})
|
|
684
|
+
).then((res) => {
|
|
685
|
+
const { result: _result, resultSourceMap } = res;
|
|
717
686
|
const result = stegaEncodeSourceMap(_result, resultSourceMap, stegaConfig);
|
|
718
|
-
return originalFilterResponse ? result : {
|
|
719
|
-
...res,
|
|
720
|
-
result
|
|
721
|
-
};
|
|
687
|
+
return originalFilterResponse ? result : { ...res, result };
|
|
722
688
|
});
|
|
723
689
|
}
|
|
724
690
|
};
|
|
725
691
|
_httpRequest2 = new WeakMap();
|
|
726
692
|
let SanityStegaClient = _SanityStegaClient;
|
|
727
|
-
|
|
693
|
+
|
|
694
|
+
const exp = browserMiddleware.defineCreateClientExports(
|
|
695
|
+
browserMiddleware.envMiddleware,
|
|
696
|
+
SanityStegaClient
|
|
697
|
+
);
|
|
728
698
|
const requester = exp.requester;
|
|
729
699
|
const createClient = exp.createClient;
|
|
700
|
+
|
|
730
701
|
exports.BasePatch = browserMiddleware.BasePatch;
|
|
731
702
|
exports.BaseTransaction = browserMiddleware.BaseTransaction;
|
|
732
703
|
exports.ClientError = browserMiddleware.ClientError;
|
|
@@ -739,15 +710,11 @@ exports.ServerError = browserMiddleware.ServerError;
|
|
|
739
710
|
exports.Transaction = browserMiddleware.Transaction;
|
|
740
711
|
Object.defineProperty(exports, "unstable__adapter", {
|
|
741
712
|
enumerable: true,
|
|
742
|
-
get: function () {
|
|
743
|
-
return getIt.adapter;
|
|
744
|
-
}
|
|
713
|
+
get: function () { return getIt.adapter; }
|
|
745
714
|
});
|
|
746
715
|
Object.defineProperty(exports, "unstable__environment", {
|
|
747
716
|
enumerable: true,
|
|
748
|
-
get: function () {
|
|
749
|
-
return getIt.environment;
|
|
750
|
-
}
|
|
717
|
+
get: function () { return getIt.environment; }
|
|
751
718
|
});
|
|
752
719
|
exports.ObservableSanityStegaClient = ObservableSanityStegaClient;
|
|
753
720
|
exports.SanityStegaClient = SanityStegaClient;
|