@nocode-factory/sanity-kit 2.27.0 → 2.28.0
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/bin/check-environments.mjs +4 -2
- package/bin/ncf-kit.mjs +43 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +73 -41
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +38 -1
- package/dist/schema.js +77 -1
- package/dist/schema.js.map +1 -0
- package/dist/web.js +1 -0
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
- package/src/form/TranslationTodoInput.tsx +25 -2
- package/src/schema/formTabs.ts +53 -0
- package/src/schema/index.ts +2 -0
- package/src/version.ts +1 -1
- package/src/web/PreviewBanner.tsx +3 -1
|
@@ -18,6 +18,8 @@ import { createServer } from "node:net";
|
|
|
18
18
|
import { existsSync, readFileSync } from "node:fs";
|
|
19
19
|
import { webcrypto as crypto } from "node:crypto";
|
|
20
20
|
|
|
21
|
+
// Bandeau de préversion : repère technique, puis anciens libellés (kits < 2.27.1).
|
|
22
|
+
const BANNER = /data-ncf-preview-banner|aria-label="(?:Données affichées|Displayed data)"/;
|
|
21
23
|
const args = process.argv.slice(2);
|
|
22
24
|
const flag = (name) => {
|
|
23
25
|
const i = args.indexOf(`--${name}`);
|
|
@@ -144,7 +146,7 @@ try {
|
|
|
144
146
|
check("prod : données en ligne", /<meta name="ncf-data" content="published"/.test(html));
|
|
145
147
|
// Le bandeau est figé au build dans les pages statiques : vérifiable seulement quand
|
|
146
148
|
// CE build est celui de la production (postbuild sur Vercel, VERCEL_ENV=production).
|
|
147
|
-
if (process.env.VERCEL_ENV === "production") check("prod : pas de bandeau de préversion",
|
|
149
|
+
if (process.env.VERCEL_ENV === "production") check("prod : pas de bandeau de préversion", !BANNER.test(html));
|
|
148
150
|
|
|
149
151
|
const forged = await get(base, PAGE, { __prerender_bypass: previewModeId, "sanity-preview-perspective": "drafts" });
|
|
150
152
|
check("prod : cookie de mode brouillon VALIDE ignoré (données en ligne)", (await dataOf(forged)) === "published", `HTTP ${forged.status}`);
|
|
@@ -188,7 +190,7 @@ try {
|
|
|
188
190
|
check("préprod : par défaut, données en ligne", /<meta name="ncf-data" content="published"/.test(liveHtml));
|
|
189
191
|
// Même raison que pour la prod : le bandeau est figé au build ; un build de
|
|
190
192
|
// production (VERCEL_ENV=production) n'en contient pas, même servi en préprod simulée.
|
|
191
|
-
if (process.env.VERCEL_ENV !== "production") check("préprod : bandeau de préversion présent",
|
|
193
|
+
if (process.env.VERCEL_ENV !== "production") check("préprod : bandeau de préversion présent", BANNER.test(liveHtml));
|
|
192
194
|
|
|
193
195
|
const on = await get(base, `/api/draft-mode/toggle?enable=true&redirect=${encodeURIComponent(PAGE)}`, jar);
|
|
194
196
|
check("préprod : bascule « Brouillons » redirige vers la page", on.status >= 300 && on.status < 400 && sameOrigin(base, on), `HTTP ${on.status}`);
|
package/bin/ncf-kit.mjs
CHANGED
|
@@ -34,6 +34,7 @@ function usage(code = 0) {
|
|
|
34
34
|
npx ncf-kit setup --types page,homePage [options] active le projet, clé du journal, webhook
|
|
35
35
|
npx ncf-kit doctor [--web <dossier>] [--offline] vérifie que le projet est complet
|
|
36
36
|
npx ncf-kit check-environments [--page <chemin>] test prod / préprod, BLOQUANT (postbuild du site)
|
|
37
|
+
npx ncf-kit check-deploy avant sanity deploy : l'appId est bien le Studio de CE projet
|
|
37
38
|
npx ncf-kit translations [export] [--out <fichier>] champs « À traduire » → JSON (texte source et actuel)
|
|
38
39
|
npx ncf-kit translations apply <fichier> écrit les traductions dans les brouillons
|
|
39
40
|
|
|
@@ -422,6 +423,13 @@ async function doctor() {
|
|
|
422
423
|
|
|
423
424
|
/* En ligne */
|
|
424
425
|
if (!offline) {
|
|
426
|
+
{
|
|
427
|
+
const r = await checkDeploy({quiet: true})
|
|
428
|
+
const msg = r.level === 'ko' ? `${r.detail} Le kit a besoin que chaque projet déploie SON Studio ; le projet ne le garantit pas : corriger studio/.env, et \"deploy\": \"ncf-kit check-deploy && sanity deploy\" dans studio/package.json.` : r.detail
|
|
429
|
+
;({ok, warn, ko})[r.level]('Studio à déployer', msg)
|
|
430
|
+
const studioPkg = read(join(studio, 'package.json'))
|
|
431
|
+
if (studioPkg && !/ncf-kit check-deploy/.test(studioPkg)) warn('Studio à déployer', "le kit a besoin d'un contrôle avant chaque déploiement du Studio ; le projet ne l'a pas : \"deploy\": \"ncf-kit check-deploy && sanity deploy\" dans studio/package.json, et toujours `npm run deploy`.")
|
|
432
|
+
}
|
|
425
433
|
// Purge du cache à la publication : webhook Sanity vers la PRODUCTION
|
|
426
434
|
// (/api/revalidate), qui relaie à la préprod. Sans lui, rien ne se met à jour
|
|
427
435
|
// sur le site avant le prochain build.
|
|
@@ -608,10 +616,45 @@ async function translations() {
|
|
|
608
616
|
fail(`translations : sous-commande inconnue « ${sub} » (export | apply <fichier>)`)
|
|
609
617
|
}
|
|
610
618
|
|
|
619
|
+
// ─── check-deploy : ne jamais écraser le Studio d'un autre projet ───
|
|
620
|
+
// `sanity deploy` publie sur le Studio désigné par SANITY_STUDIO_APP_ID. Un dépôt
|
|
621
|
+
// dupliqué qui garde l'appId d'origine écrase le Studio de l'autre projet (vécu :
|
|
622
|
+
// Studio Circet France remplacé par celui d'un pays). Vérifie, avant de déployer,
|
|
623
|
+
// que l'appId est un Studio de CE projet Sanity et qu'il porte le nom d'hôte du .env.
|
|
624
|
+
async function checkDeploy({quiet = false} = {}) {
|
|
625
|
+
const dir = resolve(flag('dir') ?? process.cwd())
|
|
626
|
+
const env = {
|
|
627
|
+
...parseEnv(read(join(dir, '.env'))),
|
|
628
|
+
...parseEnv(read(join(dir, '.env.production.local'))),
|
|
629
|
+
}
|
|
630
|
+
const projectId = env.SANITY_STUDIO_PROJECT_ID
|
|
631
|
+
const appId = env.SANITY_STUDIO_APP_ID
|
|
632
|
+
const hostname = env.SANITY_STUDIO_HOSTNAME
|
|
633
|
+
if (!projectId) return {level: 'ko', detail: 'SANITY_STUDIO_PROJECT_ID absent du .env du studio.'}
|
|
634
|
+
if (!appId) return {level: 'ok', detail: `pas d'appId : premier déploiement (${hostname ?? 'nom choisi au déploiement'})`}
|
|
635
|
+
const token = sanityToken()
|
|
636
|
+
if (!token) return {level: 'warn', detail: 'non vérifié : aucun jeton Sanity (npx sanity login).'}
|
|
637
|
+
const r = await request(`${SANITY_API}/v2024-08-01/projects/${projectId}/user-applications`, {headers: {authorization: `Bearer ${token}`}})
|
|
638
|
+
if (!r.ok) return {level: 'warn', detail: `Studios du projet illisibles (${r.status}).`}
|
|
639
|
+
const apps = Array.isArray(r.body) ? r.body : []
|
|
640
|
+
const app = apps.find((a) => a.id === appId)
|
|
641
|
+
if (!app) return {level: 'ko', detail: `SANITY_STUDIO_APP_ID=${appId} n'est pas un Studio du projet ${projectId} : il vient sans doute d'un autre projet (dépôt dupliqué). Le vider pour créer le Studio de ce projet au déploiement.`}
|
|
642
|
+
if (hostname && app.appHost && app.appHost !== hostname) return {level: 'ko', detail: `SANITY_STUDIO_APP_ID=${appId} est le Studio « ${app.appHost} », pas « ${hostname} » : déployer l'écraserait. Mettre l'appId de ${hostname} (ou le vider).`}
|
|
643
|
+
return {level: 'ok', detail: `${app.appHost ?? appId}.sanity.studio`}
|
|
644
|
+
}
|
|
645
|
+
|
|
611
646
|
if (command === 'setup') {
|
|
612
647
|
setup().catch((error) => fail(error?.message ?? String(error)))
|
|
613
648
|
} else if (command === 'doctor') {
|
|
614
649
|
doctor().catch((error) => fail(error?.message ?? String(error)))
|
|
650
|
+
} else if (command === 'check-deploy') {
|
|
651
|
+
checkDeploy()
|
|
652
|
+
.then((r) => {
|
|
653
|
+
const icon = {ok: '✔', warn: '⚠', ko: '✖'}[r.level]
|
|
654
|
+
console.log(`${icon} Studio à déployer : ${r.detail}`)
|
|
655
|
+
if (r.level === 'ko') process.exit(1)
|
|
656
|
+
})
|
|
657
|
+
.catch((error) => fail(error?.message ?? String(error)))
|
|
615
658
|
} else if (command === 'translations') {
|
|
616
659
|
translations().catch((error) => fail(error?.message ?? String(error)))
|
|
617
660
|
} else if (command === 'check-environments') {
|
package/dist/index.d.ts
CHANGED
|
@@ -1348,7 +1348,7 @@ export declare function ActorName(props: {
|
|
|
1348
1348
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1349
1349
|
* le vérifie.
|
|
1350
1350
|
*/
|
|
1351
|
-
export declare const KIT_VERSION = "2.
|
|
1351
|
+
export declare const KIT_VERSION = "2.28.0";
|
|
1352
1352
|
/**
|
|
1353
1353
|
* Données de la page proposées comme colonnes.
|
|
1354
1354
|
*
|
package/dist/index.js
CHANGED
|
@@ -1420,7 +1420,7 @@ function explainGrantError(error) {
|
|
|
1420
1420
|
* quelle version. Recopiée de `package.json` par `npm version` (scripts/sync-version.mjs) ; un test
|
|
1421
1421
|
* le vérifie.
|
|
1422
1422
|
*/
|
|
1423
|
-
const KIT_VERSION = "2.
|
|
1423
|
+
const KIT_VERSION = "2.28.0";
|
|
1424
1424
|
/**
|
|
1425
1425
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1426
1426
|
*
|
|
@@ -1763,7 +1763,7 @@ function useKitUpdate() {
|
|
|
1763
1763
|
!controller.signal.aborted && body?.version && setLatest(body.version);
|
|
1764
1764
|
}).catch(() => {}), () => controller.abort();
|
|
1765
1765
|
}, []);
|
|
1766
|
-
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.
|
|
1766
|
+
let available = !!(latest && !isPrerelease(latest) && compareVersions(latest, "2.28.0") > 0);
|
|
1767
1767
|
return {
|
|
1768
1768
|
current: KIT_VERSION,
|
|
1769
1769
|
latest,
|
|
@@ -8243,7 +8243,23 @@ function fieldPathKey(path) {
|
|
|
8243
8243
|
*/
|
|
8244
8244
|
function withTranslationTodo(Inner, config) {
|
|
8245
8245
|
function TranslationTodoInput(props) {
|
|
8246
|
-
let id = useFormValue(["_id"]), client = useKitClient(), todo = useTranslationTodo(client, config.i18n ? id : void 0), [busy, setBusy] = useState(!1), [error, setError] = useState(null), language = useFormValue([config.i18n?.field ?? "language"]), key = fieldPathKey(props.path), inner = createElement(Inner, props), show = !!todo?.paths?.includes(key),
|
|
8246
|
+
let id = useFormValue(["_id"]), client = useKitClient(), todo = useTranslationTodo(client, config.i18n ? id : void 0), [busy, setBusy] = useState(!1), [error, setError] = useState(null), language = useFormValue([config.i18n?.field ?? "language"]), key = fieldPathKey(props.path), inner = createElement(Inner, props), show = !!todo?.paths?.includes(key), [master, setMaster] = useState(null), sourceId = show ? todo?.sourceId : void 0;
|
|
8247
|
+
useEffect(() => {
|
|
8248
|
+
if (!sourceId) return;
|
|
8249
|
+
let alive = !0;
|
|
8250
|
+
return client.getDocument(sourceId).then((doc) => {
|
|
8251
|
+
if (!alive) return;
|
|
8252
|
+
let text = collectTexts$1(valueAtKey(doc, key)).join("").trim();
|
|
8253
|
+
setMaster(text || null);
|
|
8254
|
+
}).catch(() => alive && setMaster(null)), () => {
|
|
8255
|
+
alive = !1;
|
|
8256
|
+
};
|
|
8257
|
+
}, [
|
|
8258
|
+
client,
|
|
8259
|
+
sourceId,
|
|
8260
|
+
key
|
|
8261
|
+
]);
|
|
8262
|
+
let done = () => {
|
|
8247
8263
|
todo && (setBusy(!0), client.patch(todo._id).set({ paths: (todo.paths ?? []).filter((p) => p !== key) }).commit().finally(() => setBusy(!1)));
|
|
8248
8264
|
}, translate = async () => {
|
|
8249
8265
|
if (todo?.sourceId && todo.sourceLanguage && language && config.history) {
|
|
@@ -8267,44 +8283,60 @@ function withTranslationTodo(Inner, config) {
|
|
|
8267
8283
|
padding: 2,
|
|
8268
8284
|
radius: 2,
|
|
8269
8285
|
border: !0,
|
|
8270
|
-
children: [
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8282
|
-
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8286
|
+
children: [
|
|
8287
|
+
/* @__PURE__ */ jsxs(Flex, {
|
|
8288
|
+
align: "center",
|
|
8289
|
+
gap: 2,
|
|
8290
|
+
children: [
|
|
8291
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
8292
|
+
size: 1,
|
|
8293
|
+
style: { flex: 1 },
|
|
8294
|
+
children: [
|
|
8295
|
+
"To translate: changed in the ",
|
|
8296
|
+
(todo?.sourceLanguage ?? "").toUpperCase(),
|
|
8297
|
+
" version."
|
|
8298
|
+
]
|
|
8299
|
+
}),
|
|
8300
|
+
config.history && !props.readOnly && /* @__PURE__ */ jsx(Button, {
|
|
8301
|
+
tone: "primary",
|
|
8302
|
+
fontSize: 1,
|
|
8303
|
+
padding: 2,
|
|
8304
|
+
text: busy ? "Translating…" : "Translate with AI",
|
|
8305
|
+
disabled: busy,
|
|
8306
|
+
onClick: () => void translate()
|
|
8307
|
+
}),
|
|
8308
|
+
/* @__PURE__ */ jsx(Button, {
|
|
8309
|
+
mode: "ghost",
|
|
8310
|
+
fontSize: 1,
|
|
8311
|
+
padding: 2,
|
|
8312
|
+
text: "Mark as translated",
|
|
8313
|
+
disabled: busy,
|
|
8314
|
+
onClick: done
|
|
8315
|
+
})
|
|
8316
|
+
]
|
|
8317
|
+
}),
|
|
8318
|
+
master && /* @__PURE__ */ jsxs(Text, {
|
|
8319
|
+
size: 1,
|
|
8320
|
+
muted: !0,
|
|
8321
|
+
style: {
|
|
8322
|
+
marginTop: 8,
|
|
8323
|
+
whiteSpace: "pre-wrap"
|
|
8324
|
+
},
|
|
8325
|
+
children: [
|
|
8326
|
+
(todo?.sourceLanguage ?? "").toUpperCase(),
|
|
8327
|
+
": ",
|
|
8328
|
+
master.length > 600 ? `${master.slice(0, 600)}…` : master
|
|
8329
|
+
]
|
|
8330
|
+
}),
|
|
8331
|
+
error && /* @__PURE__ */ jsx(Text, {
|
|
8332
|
+
size: 1,
|
|
8333
|
+
style: {
|
|
8334
|
+
marginTop: 8,
|
|
8335
|
+
color: "var(--card-badge-critical-fg-color, #c00)"
|
|
8336
|
+
},
|
|
8337
|
+
children: error
|
|
8338
|
+
})
|
|
8339
|
+
]
|
|
8308
8340
|
})]
|
|
8309
8341
|
});
|
|
8310
8342
|
}
|