@sanity/client 6.7.1-pink-lizard.4 → 6.7.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/README.md +2 -79
- package/dist/index.browser.cjs +1868 -13
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +1858 -3
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +1888 -13
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1878 -3
- package/dist/index.js.map +1 -1
- package/package.json +8 -48
- package/src/config.ts +0 -6
- package/umd/sanityClient.js +1 -5
- package/umd/sanityClient.min.js +1 -1
- package/dist/_chunks/browserMiddleware-Oa7zKwEN.js +0 -1862
- package/dist/_chunks/browserMiddleware-Oa7zKwEN.js.map +0 -1
- package/dist/_chunks/browserMiddleware-zle5A-pb.cjs +0 -1877
- package/dist/_chunks/browserMiddleware-zle5A-pb.cjs.map +0 -1
- package/dist/_chunks/createEditLink-_BA4GZaY.cjs +0 -222
- package/dist/_chunks/createEditLink-_BA4GZaY.cjs.map +0 -1
- package/dist/_chunks/createEditLink-tWkBWOk4.js +0 -212
- package/dist/_chunks/createEditLink-tWkBWOk4.js.map +0 -1
- package/dist/_chunks/nodeMiddleware-_lHo6xcC.js +0 -1882
- package/dist/_chunks/nodeMiddleware-_lHo6xcC.js.map +0 -1
- package/dist/_chunks/nodeMiddleware-qVoQZE_z.cjs +0 -1897
- package/dist/_chunks/nodeMiddleware-qVoQZE_z.cjs.map +0 -1
- package/dist/csm.cjs +0 -71
- package/dist/csm.cjs.map +0 -1
- package/dist/csm.d.ts +0 -248
- package/dist/csm.js +0 -58
- package/dist/csm.js.map +0 -1
- package/dist/stega.browser.cjs +0 -629
- package/dist/stega.browser.cjs.map +0 -1
- package/dist/stega.browser.js +0 -598
- package/dist/stega.browser.js.map +0 -1
- package/dist/stega.cjs +0 -424
- package/dist/stega.cjs.js +0 -21
- package/dist/stega.cjs.map +0 -1
- package/dist/stega.d.ts +0 -2872
- package/dist/stega.js +0 -393
- package/dist/stega.js.map +0 -1
- package/src/csm/applySourceDocuments.test.ts +0 -820
- package/src/csm/applySourceDocuments.ts +0 -87
- package/src/csm/createEditLink.ts +0 -75
- package/src/csm/getPublishedId.ts +0 -12
- package/src/csm/index.ts +0 -9
- package/src/csm/isArray.ts +0 -3
- package/src/csm/isRecord.ts +0 -3
- package/src/csm/jsonpath.test.ts +0 -33
- package/src/csm/jsonpath.ts +0 -93
- package/src/csm/resolveMapping.ts +0 -41
- package/src/csm/resolvedKeyedSourcePath.ts +0 -23
- package/src/csm/simplifyPath.ts +0 -20
- package/src/csm/types.ts +0 -72
- package/src/csm/walkMap.ts +0 -30
- package/src/stega/SanityStegaClient.ts +0 -244
- package/src/stega/config.ts +0 -56
- package/src/stega/encodeIntoResult.test.ts +0 -268
- package/src/stega/encodeIntoResult.ts +0 -59
- package/src/stega/filterDefault.ts +0 -49
- package/src/stega/index.browser.ts +0 -19
- package/src/stega/index.ts +0 -19
- package/src/stega/shared.ts +0 -4
- package/src/stega/stegaEncodeSourceMap.ts +0 -128
- package/src/stega/types.ts +0 -139
package/src/stega/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from '../defineCreateClient'
|
|
2
|
-
|
|
3
|
-
import defineCreateClientExports from '../defineCreateClient'
|
|
4
|
-
import envMiddleware from '../http/nodeMiddleware'
|
|
5
|
-
import {SanityStegaClient} from './SanityStegaClient'
|
|
6
|
-
import type {ClientStegaConfig} from './types'
|
|
7
|
-
|
|
8
|
-
const exp = defineCreateClientExports<SanityStegaClient, ClientStegaConfig>(
|
|
9
|
-
envMiddleware,
|
|
10
|
-
SanityStegaClient,
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
export * from './shared'
|
|
14
|
-
|
|
15
|
-
/** @public */
|
|
16
|
-
export const requester = exp.requester
|
|
17
|
-
|
|
18
|
-
/** @public */
|
|
19
|
-
export const createClient = exp.createClient
|
package/src/stega/shared.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {vercelStegaCombine} from '@vercel/stega'
|
|
2
|
-
|
|
3
|
-
import type {PathSegment} from '../csm'
|
|
4
|
-
import {createEditLink} from '../csm/createEditLink'
|
|
5
|
-
import {encodeIntoResult} from './encodeIntoResult'
|
|
6
|
-
import {filterDefault} from './filterDefault'
|
|
7
|
-
import {ContentSourceMap, InitializedStegaConfig} from './types'
|
|
8
|
-
|
|
9
|
-
const TRUNCATE_LENGTH = 20
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Uses `@vercel/stega` to embed edit info JSON into strings in your query result.
|
|
13
|
-
* The JSON payloads are added using invisible characters so they don't show up visually.
|
|
14
|
-
* The edit info is generated from the Content Source Map (CSM) that is returned from Sanity for the query.
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export function stegaEncodeSourceMap<Result = unknown>(
|
|
18
|
-
result: Result,
|
|
19
|
-
resultSourceMap: ContentSourceMap | undefined,
|
|
20
|
-
config: InitializedStegaConfig,
|
|
21
|
-
): Result {
|
|
22
|
-
const {filter, vercelStegaCombineSkip, logger, studioUrl, enabled} = config
|
|
23
|
-
if (!enabled) {
|
|
24
|
-
const msg = "config.enabled must be true, don't call this function otherwise"
|
|
25
|
-
logger?.error?.(`[@sanity/client/stega]: ${msg}`, {result, resultSourceMap, config})
|
|
26
|
-
throw new TypeError(msg)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!resultSourceMap) {
|
|
30
|
-
logger?.error?.('[@sanity/client/stega]: Missing Content Source Map from response body', {
|
|
31
|
-
result,
|
|
32
|
-
resultSourceMap,
|
|
33
|
-
config,
|
|
34
|
-
})
|
|
35
|
-
return result
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!studioUrl) {
|
|
39
|
-
const msg = 'config.studioUrl must be defined'
|
|
40
|
-
logger?.error?.(`[@sanity/client/stega]: ${msg}`, {result, resultSourceMap, config})
|
|
41
|
-
throw new TypeError(msg)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const report: Record<'encoded' | 'skipped', {path: string; length: number; value: string}[]> = {
|
|
45
|
-
encoded: [],
|
|
46
|
-
skipped: [],
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const resultWithStega = encodeIntoResult(
|
|
50
|
-
result,
|
|
51
|
-
resultSourceMap,
|
|
52
|
-
({sourcePath, sourceDocument, resultPath, value}) => {
|
|
53
|
-
// Allow userland to control when to opt-out of encoding
|
|
54
|
-
if (
|
|
55
|
-
(typeof filter === 'function'
|
|
56
|
-
? filter({sourcePath, resultPath, filterDefault, sourceDocument, value})
|
|
57
|
-
: filterDefault({sourcePath, resultPath, filterDefault, sourceDocument, value})) === false
|
|
58
|
-
) {
|
|
59
|
-
if (logger) {
|
|
60
|
-
report.skipped.push({
|
|
61
|
-
path: prettyPathForLogging(sourcePath),
|
|
62
|
-
value: `${value.slice(0, TRUNCATE_LENGTH)}${
|
|
63
|
-
value.length > TRUNCATE_LENGTH ? '...' : ''
|
|
64
|
-
}`,
|
|
65
|
-
length: value.length,
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
return value
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (logger) {
|
|
72
|
-
report.encoded.push({
|
|
73
|
-
path: prettyPathForLogging(sourcePath),
|
|
74
|
-
value: `${value.slice(0, TRUNCATE_LENGTH)}${value.length > TRUNCATE_LENGTH ? '...' : ''}`,
|
|
75
|
-
length: value.length,
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return vercelStegaCombine(
|
|
80
|
-
value,
|
|
81
|
-
{
|
|
82
|
-
origin: 'sanity.io',
|
|
83
|
-
href: createEditLink({studioUrl, resultSourceMap, resultPath}),
|
|
84
|
-
},
|
|
85
|
-
vercelStegaCombineSkip,
|
|
86
|
-
)
|
|
87
|
-
},
|
|
88
|
-
{keyArraySelectors: true},
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
if (logger) {
|
|
92
|
-
const isSkipping = report.skipped.length
|
|
93
|
-
const isEncoding = report.encoded.length
|
|
94
|
-
if (isSkipping || isEncoding) {
|
|
95
|
-
;(logger?.groupCollapsed || logger.log)?.(
|
|
96
|
-
'[@sanity/client/stega]: Encoding source map into result',
|
|
97
|
-
)
|
|
98
|
-
logger.log?.(
|
|
99
|
-
`[@sanity/client/stega]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`,
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
if (report.encoded.length > 0) {
|
|
103
|
-
logger?.log?.(`[@sanity/client/stega]: Table of encoded paths`)
|
|
104
|
-
;(logger?.table || logger.log)?.(report.encoded)
|
|
105
|
-
}
|
|
106
|
-
if (report.skipped.length > 0) {
|
|
107
|
-
const skipped = new Set<string>()
|
|
108
|
-
for (const {path} of report.skipped) {
|
|
109
|
-
skipped.add(path.replace(/\[\d+\]/g, '[]'))
|
|
110
|
-
}
|
|
111
|
-
logger?.log?.(`[@sanity/client/stega]: List of skipped paths`, [...skipped.values()])
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (isSkipping || isEncoding) {
|
|
115
|
-
logger?.groupEnd?.()
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return resultWithStega
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function prettyPathForLogging(path: PathSegment[]): string {
|
|
123
|
-
return path
|
|
124
|
-
.map((segment, index) =>
|
|
125
|
-
typeof segment === 'number' ? `[${segment}]` : index > 0 ? `.${segment}` : segment,
|
|
126
|
-
)
|
|
127
|
-
.join('')
|
|
128
|
-
}
|
package/src/stega/types.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ContentSourceMap,
|
|
3
|
-
ContentSourceMapDocuments,
|
|
4
|
-
Path,
|
|
5
|
-
ResolveStudioUrl,
|
|
6
|
-
StudioUrl,
|
|
7
|
-
} from '../csm'
|
|
8
|
-
import {ClientConfig, InitializedClientConfig, RawQueryResponse} from '../types'
|
|
9
|
-
|
|
10
|
-
export type {KeyedSegment, PathSegment, StudioUrl} from '../csm/types'
|
|
11
|
-
export type * from '../types'
|
|
12
|
-
|
|
13
|
-
export type {ContentSourceMap, Path, ResolveStudioUrl}
|
|
14
|
-
|
|
15
|
-
/** @public */
|
|
16
|
-
export type ContentSourceMapQueryResponse =
|
|
17
|
-
| RawQueryResponse<unknown>
|
|
18
|
-
| Pick<RawQueryResponse<unknown>, 'result' | 'resultSourceMap'>
|
|
19
|
-
|
|
20
|
-
/** @public */
|
|
21
|
-
export interface StegaConfig {
|
|
22
|
-
/**
|
|
23
|
-
* Enable or disable stega encoded strings in query results
|
|
24
|
-
* ```ts
|
|
25
|
-
{
|
|
26
|
-
enabled: process.env.VERCEL_ENV !== 'production'
|
|
27
|
-
}
|
|
28
|
-
* ```
|
|
29
|
-
* @defaultValue `false`
|
|
30
|
-
*/
|
|
31
|
-
enabled?: boolean
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Where the Studio is hosted.
|
|
35
|
-
* If it's embedded in the app, use the base path for example `/studio`.
|
|
36
|
-
* Otherwise provide the full URL to where the Studio is hosted, for example: `https://blog.sanity.studio`.
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
studioUrl?: StudioUrl | ResolveStudioUrl
|
|
40
|
-
|
|
41
|
-
filter?: FilterDefault
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Specify a `console.log` compatible logger to see debug logs, which keys are encoded and which are not.
|
|
45
|
-
*/
|
|
46
|
-
logger?: Logger
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Override the `skip` parameter in `vercelStegaCombine`
|
|
50
|
-
* @defaultValue `'auto'`
|
|
51
|
-
*/
|
|
52
|
-
vercelStegaCombineSkip?: 'auto' | boolean
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** @public */
|
|
56
|
-
export type StegaConfigRequiredKeys = Extract<
|
|
57
|
-
keyof StegaConfig,
|
|
58
|
-
'enabled' | 'filter' | 'vercelStegaCombineSkip'
|
|
59
|
-
>
|
|
60
|
-
|
|
61
|
-
/** @public */
|
|
62
|
-
export type InitializedStegaConfig = Omit<StegaConfig, StegaConfigRequiredKeys> &
|
|
63
|
-
Required<Pick<StegaConfig, StegaConfigRequiredKeys>>
|
|
64
|
-
|
|
65
|
-
/** @public */
|
|
66
|
-
export interface ClientStegaConfig extends ClientConfig {
|
|
67
|
-
stega?: StegaConfig
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** @public */
|
|
71
|
-
export interface InitializedClientStegaConfig extends InitializedClientConfig {
|
|
72
|
-
stega: InitializedStegaConfig
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** @public */
|
|
76
|
-
export type FilterDefault = (props: {
|
|
77
|
-
/**
|
|
78
|
-
* The path to the value in the source document, for example if you queried for a document like this:
|
|
79
|
-
* `*[_type == "author"][0]{"slug": slug.current}`
|
|
80
|
-
* Then the `sourcePath` for `result.slug` would be `['slug', 'current']`.
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
sourcePath: Path
|
|
84
|
-
/**
|
|
85
|
-
* If `sourcePath` alone isn't enough to tell you if it's safe to contain stega strings, then you can use `sourceDocument`
|
|
86
|
-
* for additional metadata.
|
|
87
|
-
* It'll always have a `_type` property, which can be used to trace it to the Studio Schema that were used initially.
|
|
88
|
-
* It also has `_id` to help you debug and look at the whole document when troubleshooting.
|
|
89
|
-
* Finally, if the document origins in a Cross Dataset Reference you'll also have `_projectId` and `_dataset` properties to help you trace it.
|
|
90
|
-
*/
|
|
91
|
-
sourceDocument: ContentSourceMapDocuments[number]
|
|
92
|
-
/**
|
|
93
|
-
* If you don't colocate your Studio Schemas with your GROQ queries it might be hard to make sense of `sourcePath`,
|
|
94
|
-
* as it operates on the original shape of a document.
|
|
95
|
-
* In that case `resultPath` can be used, as it mirrors the path to the value in the result.
|
|
96
|
-
* For example in a query like this:
|
|
97
|
-
* `*[_type == "author"][0]{"slug": slug.current}`
|
|
98
|
-
* The `resultPath` for `result.slug` would be `['slug']`, while `sourcePath` will be `['slug', 'current']`.
|
|
99
|
-
*/
|
|
100
|
-
resultPath: Path
|
|
101
|
-
/**
|
|
102
|
-
* You can also use your own string validation logic to determine if it's safe.
|
|
103
|
-
*/
|
|
104
|
-
value: string
|
|
105
|
-
/**
|
|
106
|
-
* If you want to keep the default filtering behavior, but only override it for a specific path, you can use `filterDefault` to do that.
|
|
107
|
-
* For example, here all "icon" documents in a Page Builder skips encoding:
|
|
108
|
-
* ```ts
|
|
109
|
-
{
|
|
110
|
-
filter: (props) => {
|
|
111
|
-
switch (props.sourceDocument._type) {
|
|
112
|
-
case 'icon':
|
|
113
|
-
return false
|
|
114
|
-
default:
|
|
115
|
-
return props.filterDefault(props)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
filterDefault: FilterDefault
|
|
122
|
-
}) => boolean
|
|
123
|
-
|
|
124
|
-
/** @public */
|
|
125
|
-
export type Logger =
|
|
126
|
-
| typeof console
|
|
127
|
-
| Partial<
|
|
128
|
-
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
129
|
-
>
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @internal
|
|
133
|
-
*/
|
|
134
|
-
export type Encoder = (context: {
|
|
135
|
-
sourcePath: Path
|
|
136
|
-
sourceDocument: ContentSourceMapDocuments[number]
|
|
137
|
-
resultPath: Path
|
|
138
|
-
value: string
|
|
139
|
-
}) => string
|