@sanity/cli 3.70.1-export-comments.11 → 3.70.1-export-comments.45
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/lib/_chunks-cjs/cli.js
CHANGED
@@ -26600,8 +26600,9 @@ const DISALLOWED_PATHS = [
|
|
26600
26600
|
"/.github/"
|
26601
26601
|
], ENV_VAR = {
|
26602
26602
|
...templateValidator.REQUIRED_ENV_VAR,
|
26603
|
-
READ_TOKEN: "SANITY_API_READ_TOKEN"
|
26604
|
-
|
26603
|
+
READ_TOKEN: "SANITY_API_READ_TOKEN",
|
26604
|
+
WRITE_TOKEN: "SANITY_API_WRITE_TOKEN"
|
26605
|
+
}, API_READ_TOKEN_ROLE = "viewer", API_WRITE_TOKEN_ROLE = "editor";
|
26605
26606
|
function getGitHubRawContentUrl(repoInfo) {
|
26606
26607
|
const { username, name, branch, filePath } = repoInfo;
|
26607
26608
|
return `https://raw.githubusercontent.com/${username}/${name}/${branch}/${filePath}`;
|
@@ -26688,12 +26689,12 @@ async function downloadAndExtractRepo(root2, { username, name, branch, filePath
|
|
26688
26689
|
})
|
26689
26690
|
);
|
26690
26691
|
}
|
26691
|
-
async function
|
26692
|
+
async function checkIfNeedsApiToken(root2, type2) {
|
26692
26693
|
try {
|
26693
26694
|
const templatePath = await Promise.any(
|
26694
26695
|
templateValidator.ENV_TEMPLATE_FILES.map(async (file) => (await fs.access(path$3.join(root2, file)), file))
|
26695
26696
|
);
|
26696
|
-
return (await fs.readFile(path$3.join(root2, templatePath), "utf8")).includes(ENV_VAR.READ_TOKEN);
|
26697
|
+
return (await fs.readFile(path$3.join(root2, templatePath), "utf8")).includes(type2 === "read" ? ENV_VAR.READ_TOKEN : ENV_VAR.WRITE_TOKEN);
|
26697
26698
|
} catch {
|
26698
26699
|
return !1;
|
26699
26700
|
}
|
@@ -26738,14 +26739,13 @@ async function tryApplyPackageName(root2, name) {
|
|
26738
26739
|
} catch {
|
26739
26740
|
}
|
26740
26741
|
}
|
26741
|
-
async function
|
26742
|
+
async function generateSanityApiToken(label, type2, projectId, apiClient) {
|
26742
26743
|
return (await apiClient({ requireProject: !1, requireUser: !0 }).config({ apiVersion: "v2021-06-07" }).request({
|
26743
26744
|
uri: `/projects/${projectId}/tokens`,
|
26744
26745
|
method: "POST",
|
26745
26746
|
body: {
|
26746
26747
|
label: `${label} (${Date.now()})`,
|
26747
|
-
|
26748
|
-
roleName: "viewer"
|
26748
|
+
roleName: type2 === "read" ? API_READ_TOKEN_ROLE : API_WRITE_TOKEN_ROLE
|
26749
26749
|
}
|
26750
26750
|
})).key;
|
26751
26751
|
}
|
@@ -51892,7 +51892,7 @@ function isInMercurialRepository(rootDir) {
|
|
51892
51892
|
}
|
51893
51893
|
return !1;
|
51894
51894
|
}
|
51895
|
-
const SANITY_DEFAULT_PORT = 3333, READ_TOKEN_LABEL = "Live Preview API", INITIAL_COMMIT_MESSAGE = "Initial commit from Sanity CLI";
|
51895
|
+
const SANITY_DEFAULT_PORT = 3333, READ_TOKEN_LABEL = "Live Preview API", WRITE_TOKEN_LABEL = "App Write Token", INITIAL_COMMIT_MESSAGE = "Initial commit from Sanity CLI";
|
51896
51896
|
async function bootstrapRemoteTemplate(opts, context) {
|
51897
51897
|
const { outputPath, repoInfo, bearerToken, variables, packageName } = opts, { output, apiClient } = context, name = [repoInfo.username, repoInfo.name, repoInfo.filePath].filter(Boolean).join("/"), contentsUrl = getGitHubRawContentUrl(repoInfo), headers = {};
|
51898
51898
|
bearerToken && (headers.Authorization = `Bearer ${bearerToken}`);
|
@@ -51904,10 +51904,12 @@ async function bootstrapRemoteTemplate(opts, context) {
|
|
51904
51904
|
`));
|
51905
51905
|
loadEnv.debug('Create new directory "%s"', outputPath), await fs.mkdir(outputPath, { recursive: !0 }), loadEnv.debug("Downloading and extracting repo to %s", outputPath), await downloadAndExtractRepo(outputPath, repoInfo, bearerToken), loadEnv.debug("Checking if template needs read token");
|
51906
51906
|
const needsReadToken = await Promise.all(
|
51907
|
-
(packages ?? [""]).map((pkg) =>
|
51907
|
+
(packages ?? [""]).map((pkg) => checkIfNeedsApiToken(path$3.join(outputPath, pkg), "read"))
|
51908
|
+
).then((results) => results.some(Boolean)), needsWriteToken = await Promise.all(
|
51909
|
+
(packages ?? [""]).map((pkg) => checkIfNeedsApiToken(path$3.join(outputPath, pkg), "write"))
|
51908
51910
|
).then((results) => results.some(Boolean));
|
51909
51911
|
loadEnv.debug("Applying environment variables");
|
51910
|
-
const readToken = needsReadToken ? await
|
51912
|
+
const readToken = needsReadToken ? await generateSanityApiToken(READ_TOKEN_LABEL, "read", variables.projectId, apiClient) : void 0, writeToken = needsWriteToken ? await generateSanityApiToken(WRITE_TOKEN_LABEL, "write", variables.projectId, apiClient) : void 0;
|
51911
51913
|
for (const pkg of packages ?? [""]) {
|
51912
51914
|
const packagePath = path$3.join(outputPath, pkg), packageFramework = await distExports.detectFrameworkRecord({
|
51913
51915
|
fs: new distExports.LocalFileSystemDetector(packagePath),
|
@@ -51917,7 +51919,7 @@ async function bootstrapRemoteTemplate(opts, context) {
|
|
51917
51919
|
const envName = packageFramework?.slug === "nextjs" ? ".env.local" : ".env";
|
51918
51920
|
await applyEnvVariables(packagePath, { ...variables, readToken }, envName);
|
51919
51921
|
}
|
51920
|
-
loadEnv.debug("Setting package name to %s", packageName), await tryApplyPackageName(outputPath, packageName), loadEnv.debug("Initializing git repository"), tryGitInit(outputPath, INITIAL_COMMIT_MESSAGE), loadEnv.debug("Updating initial template metadata"), await updateInitialTemplateMetadata(apiClient, variables.projectId, `external-${name}`), spinner.succeed(), corsAdded.length && output.success(`CORS origins added (${corsAdded.map((p) => `localhost:${p}`).join(", ")})`), readToken && output.success(`API token generated (${READ_TOKEN_LABEL})`);
|
51922
|
+
loadEnv.debug("Setting package name to %s", packageName), await tryApplyPackageName(outputPath, packageName), loadEnv.debug("Initializing git repository"), tryGitInit(outputPath, INITIAL_COMMIT_MESSAGE), loadEnv.debug("Updating initial template metadata"), await updateInitialTemplateMetadata(apiClient, variables.projectId, `external-${name}`), spinner.succeed(), corsAdded.length && output.success(`CORS origins added (${corsAdded.map((p) => `localhost:${p}`).join(", ")})`), readToken && output.success(`API token generated (${READ_TOKEN_LABEL})`), writeToken && output.success(`API token generated (${WRITE_TOKEN_LABEL})`);
|
51921
51923
|
}
|
51922
51924
|
function validateEmptyPath(dir) {
|
51923
51925
|
const checkPath = absolutify(dir);
|