@sanity/cli 3.70.1-export-comments.10 → 3.70.1-export-comments.43
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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sanity/cli",
|
3
|
-
"version": "3.70.1-export-comments.
|
3
|
+
"version": "3.70.1-export-comments.43+6788f5af58",
|
4
4
|
"description": "Sanity CLI tool for managing Sanity installations, managing plugins, schemas and datasets",
|
5
5
|
"keywords": [
|
6
6
|
"sanity",
|
@@ -57,11 +57,11 @@
|
|
57
57
|
},
|
58
58
|
"dependencies": {
|
59
59
|
"@babel/traverse": "^7.23.5",
|
60
|
-
"@sanity/client": "^6.
|
61
|
-
"@sanity/codegen": "3.70.1-export-comments.
|
60
|
+
"@sanity/client": "^6.25.0",
|
61
|
+
"@sanity/codegen": "3.70.1-export-comments.43+6788f5af58",
|
62
62
|
"@sanity/telemetry": "^0.7.7",
|
63
63
|
"@sanity/template-validator": "^2.3.2",
|
64
|
-
"@sanity/util": "3.70.1-export-comments.
|
64
|
+
"@sanity/util": "3.70.1-export-comments.43+6788f5af58",
|
65
65
|
"chalk": "^4.1.2",
|
66
66
|
"debug": "^4.3.4",
|
67
67
|
"decompress": "^4.2.0",
|
@@ -81,7 +81,7 @@
|
|
81
81
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
82
82
|
"@sanity/eslint-config-studio": "^4.0.0",
|
83
83
|
"@sanity/generate-help-url": "^3.0.0",
|
84
|
-
"@sanity/types": "3.70.1-export-comments.
|
84
|
+
"@sanity/types": "3.70.1-export-comments.43+6788f5af58",
|
85
85
|
"@types/babel__traverse": "^7.20.5",
|
86
86
|
"@types/configstore": "^5.0.1",
|
87
87
|
"@types/cpx": "^1.5.2",
|
@@ -125,7 +125,7 @@
|
|
125
125
|
"semver": "^7.3.5",
|
126
126
|
"semver-compare": "^1.0.0",
|
127
127
|
"tar": "^6.1.11",
|
128
|
-
"vite": "^
|
128
|
+
"vite": "^6.0.7",
|
129
129
|
"vitest": "^2.1.8",
|
130
130
|
"which": "^2.0.2",
|
131
131
|
"xdg-basedir": "^4.0.0"
|
@@ -133,5 +133,5 @@
|
|
133
133
|
"engines": {
|
134
134
|
"node": ">=18"
|
135
135
|
},
|
136
|
-
"gitHead": "
|
136
|
+
"gitHead": "6788f5af58847b7a108d0597676df494a706826c"
|
137
137
|
}
|
@@ -10,9 +10,9 @@ import {type CliCommandContext} from '../../types'
|
|
10
10
|
import {getDefaultPortForFramework} from '../../util/frameworkPort'
|
11
11
|
import {
|
12
12
|
applyEnvVariables,
|
13
|
-
|
13
|
+
checkIfNeedsApiToken,
|
14
14
|
downloadAndExtractRepo,
|
15
|
-
|
15
|
+
generateSanityApiToken,
|
16
16
|
getGitHubRawContentUrl,
|
17
17
|
type RepoInfo,
|
18
18
|
setCorsOrigin,
|
@@ -32,6 +32,7 @@ export interface BootstrapRemoteOptions {
|
|
32
32
|
|
33
33
|
const SANITY_DEFAULT_PORT = 3333
|
34
34
|
const READ_TOKEN_LABEL = 'Live Preview API'
|
35
|
+
const WRITE_TOKEN_LABEL = 'App Write Token'
|
35
36
|
const INITIAL_COMMIT_MESSAGE = 'Initial commit from Sanity CLI'
|
36
37
|
|
37
38
|
export async function bootstrapRemoteTemplate(
|
@@ -65,12 +66,18 @@ export async function bootstrapRemoteTemplate(
|
|
65
66
|
|
66
67
|
debug('Checking if template needs read token')
|
67
68
|
const needsReadToken = await Promise.all(
|
68
|
-
(packages ?? ['']).map((pkg) =>
|
69
|
+
(packages ?? ['']).map((pkg) => checkIfNeedsApiToken(join(outputPath, pkg), 'read')),
|
70
|
+
).then((results) => results.some(Boolean))
|
71
|
+
const needsWriteToken = await Promise.all(
|
72
|
+
(packages ?? ['']).map((pkg) => checkIfNeedsApiToken(join(outputPath, pkg), 'write')),
|
69
73
|
).then((results) => results.some(Boolean))
|
70
74
|
|
71
75
|
debug('Applying environment variables')
|
72
76
|
const readToken = needsReadToken
|
73
|
-
? await
|
77
|
+
? await generateSanityApiToken(READ_TOKEN_LABEL, 'read', variables.projectId, apiClient)
|
78
|
+
: undefined
|
79
|
+
const writeToken = needsWriteToken
|
80
|
+
? await generateSanityApiToken(WRITE_TOKEN_LABEL, 'write', variables.projectId, apiClient)
|
74
81
|
: undefined
|
75
82
|
|
76
83
|
for (const pkg of packages ?? ['']) {
|
@@ -106,7 +113,6 @@ export async function bootstrapRemoteTemplate(
|
|
106
113
|
if (corsAdded.length) {
|
107
114
|
output.success(`CORS origins added (${corsAdded.map((p) => `localhost:${p}`).join(', ')})`)
|
108
115
|
}
|
109
|
-
if (readToken) {
|
110
|
-
|
111
|
-
}
|
116
|
+
if (readToken) output.success(`API token generated (${READ_TOKEN_LABEL})`)
|
117
|
+
if (writeToken) output.success(`API token generated (${WRITE_TOKEN_LABEL})`)
|
112
118
|
}
|
@@ -18,12 +18,17 @@ const DISALLOWED_PATHS = [
|
|
18
18
|
const ENV_VAR = {
|
19
19
|
...REQUIRED_ENV_VAR,
|
20
20
|
READ_TOKEN: 'SANITY_API_READ_TOKEN',
|
21
|
+
WRITE_TOKEN: 'SANITY_API_WRITE_TOKEN',
|
21
22
|
} as const
|
22
23
|
|
24
|
+
const API_READ_TOKEN_ROLE = 'viewer'
|
25
|
+
const API_WRITE_TOKEN_ROLE = 'editor'
|
26
|
+
|
23
27
|
type EnvData = {
|
24
28
|
projectId: string
|
25
29
|
dataset: string
|
26
30
|
readToken?: string
|
31
|
+
writeToken?: string
|
27
32
|
}
|
28
33
|
|
29
34
|
type GithubUrlString =
|
@@ -191,7 +196,7 @@ export async function downloadAndExtractRepo(
|
|
191
196
|
)
|
192
197
|
}
|
193
198
|
|
194
|
-
export async function
|
199
|
+
export async function checkIfNeedsApiToken(root: string, type: 'read' | 'write'): Promise<boolean> {
|
195
200
|
try {
|
196
201
|
const templatePath = await Promise.any(
|
197
202
|
ENV_TEMPLATE_FILES.map(async (file) => {
|
@@ -199,9 +204,8 @@ export async function checkNeedsReadToken(root: string): Promise<boolean> {
|
|
199
204
|
return file
|
200
205
|
}),
|
201
206
|
)
|
202
|
-
|
203
207
|
const templateContent = await readFile(join(root, templatePath), 'utf8')
|
204
|
-
return templateContent.includes(ENV_VAR.READ_TOKEN)
|
208
|
+
return templateContent.includes(type === 'read' ? ENV_VAR.READ_TOKEN : ENV_VAR.WRITE_TOKEN)
|
205
209
|
} catch {
|
206
210
|
return false
|
207
211
|
}
|
@@ -278,8 +282,9 @@ export async function tryApplyPackageName(root: string, name: string): Promise<v
|
|
278
282
|
}
|
279
283
|
}
|
280
284
|
|
281
|
-
export async function
|
285
|
+
export async function generateSanityApiToken(
|
282
286
|
label: string,
|
287
|
+
type: 'read' | 'write',
|
283
288
|
projectId: string,
|
284
289
|
apiClient: CliApiClient,
|
285
290
|
): Promise<string> {
|
@@ -289,8 +294,8 @@ export async function generateSanityApiReadToken(
|
|
289
294
|
uri: `/projects/${projectId}/tokens`,
|
290
295
|
method: 'POST',
|
291
296
|
body: {
|
292
|
-
label: `${label} (${Date.now()})`,
|
293
|
-
roleName: '
|
297
|
+
label: `${label} (${Date.now()})`,
|
298
|
+
roleName: type === 'read' ? API_READ_TOKEN_ROLE : API_WRITE_TOKEN_ROLE,
|
294
299
|
},
|
295
300
|
})
|
296
301
|
return response.key
|