@nocode-factory/sanity-kit 2.1.0 → 2.2.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/dist/index.d.ts +13 -1
- package/dist/index.js +67 -10
- package/dist/index.js.map +1 -1
- package/dist/web-server.d.ts +11 -0
- package/dist/web-server.js +25 -5
- package/dist/web-server.js.map +1 -1
- package/package.json +1 -1
- package/src/config/resolve.ts +43 -2
- package/src/config/types.ts +5 -0
- package/src/hooks/usePreviewTarget.ts +12 -0
- package/src/tools/pages/PagesTool.tsx +1 -0
- package/src/tools/pages/PreviewTarget.tsx +8 -2
- package/src/tools/pages/SharePreview.tsx +24 -1
- package/src/version.ts +1 -1
- package/src/web/previewGrant.ts +27 -4
- package/src/web/server.ts +8 -1
package/dist/index.d.ts
CHANGED
|
@@ -158,6 +158,11 @@ interface NcfKitConfig {
|
|
|
158
158
|
* `ncfAllowedOrigins(config)` les produit.
|
|
159
159
|
*/
|
|
160
160
|
environments?: NcfEnvironment[];
|
|
161
|
+
/**
|
|
162
|
+
* `false` retire la préproduction déduite par convention
|
|
163
|
+
* (`preview-<projet>.vercel.app`). Utile pour un projet qui n'en a pas.
|
|
164
|
+
*/
|
|
165
|
+
preprodUrl?: false;
|
|
161
166
|
/**
|
|
162
167
|
* Gabarit d'URL de la capture d'une page, pour afficher la page entière dans
|
|
163
168
|
* le board plutôt qu'une iframe tronquée. Variables : {slug} (chemin sans
|
|
@@ -1030,6 +1035,13 @@ interface PreviewTargetState {
|
|
|
1030
1035
|
pathFor: (url: string | null) => string | null;
|
|
1031
1036
|
/** URL de la page sur l'environnement choisi, pour l'ouvrir hors du Studio. */
|
|
1032
1037
|
siteUrlFor: (url: string | null) => string | null;
|
|
1038
|
+
/**
|
|
1039
|
+
* L'environnement choisi est-il le site public ?
|
|
1040
|
+
*
|
|
1041
|
+
* Il n'y a rien à y prévisualiser : le bandeau s'y masque et le mode
|
|
1042
|
+
* brouillon y est refusé. Partager un lien vers lui ne montrerait rien.
|
|
1043
|
+
*/
|
|
1044
|
+
isProduction: boolean;
|
|
1033
1045
|
}
|
|
1034
1046
|
export declare function usePreviewTarget(): PreviewTargetState;
|
|
1035
1047
|
/**
|
|
@@ -1191,7 +1203,7 @@ export declare function ActorName(props: {
|
|
|
1191
1203
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1192
1204
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1193
1205
|
*/
|
|
1194
|
-
export declare const KIT_VERSION = "2.
|
|
1206
|
+
export declare const KIT_VERSION = "2.2.0";
|
|
1195
1207
|
/**
|
|
1196
1208
|
* Données de la page proposées comme colonnes.
|
|
1197
1209
|
*
|
package/dist/index.js
CHANGED
|
@@ -147,6 +147,27 @@ function resolveConfig(input) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
+
* Préproduction déduite de la production, par convention.
|
|
151
|
+
*
|
|
152
|
+
* NoCode Factory assigne à chaque projet un domaine Vercel **fixe** pour la
|
|
153
|
+
* branche `preprod`, de la forme `preview-<projet>.vercel.app`. Fixe parce
|
|
154
|
+
* qu'un lien de partage doit survivre au commit suivant : une URL de
|
|
155
|
+
* déploiement change à chaque poussée, un domaine assigné non.
|
|
156
|
+
*
|
|
157
|
+
* La déduire évite de la déclarer neuf fois. Elle n'est proposée que pour un
|
|
158
|
+
* hôte Vercel — ailleurs la convention ne s'applique pas — et `environments`
|
|
159
|
+
* la remplace dès qu'on la déclare explicitement.
|
|
160
|
+
*/
|
|
161
|
+
function conventionalPreprodUrl(previewUrl) {
|
|
162
|
+
if (!previewUrl) return null;
|
|
163
|
+
try {
|
|
164
|
+
let url = new URL(previewUrl);
|
|
165
|
+
return !url.hostname.endsWith(".vercel.app") || url.hostname.startsWith("preview-") ? null : `${url.protocol}//preview-${url.hostname}`;
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
150
171
|
* Environnements d'aperçu.
|
|
151
172
|
*
|
|
152
173
|
* `previewUrl` en fournit toujours un, nommé « Production » : un projet qui
|
|
@@ -161,11 +182,21 @@ function resolveEnvironments(input) {
|
|
|
161
182
|
label: environment.label?.trim() || environment.id.trim(),
|
|
162
183
|
url: trimTrailingSlash((environment.url ?? "").trim())
|
|
163
184
|
})).filter((environment) => environment.id && environment.url), preview = input.previewUrl ? trimTrailingSlash(input.previewUrl.trim()) : null;
|
|
164
|
-
|
|
185
|
+
if (!preview) return declared;
|
|
186
|
+
let production = declared.some((environment) => environment.url === preview) ? [] : [{
|
|
165
187
|
id: "production",
|
|
166
188
|
label: "Production",
|
|
167
189
|
url: preview
|
|
168
|
-
},
|
|
190
|
+
}], conventional = conventionalPreprodUrl(preview), hasPreprod = declared.some((environment) => environment.url === conventional) || input.preprodUrl === !1, preprod = conventional && !hasPreprod ? [{
|
|
191
|
+
id: "preprod",
|
|
192
|
+
label: "Préproduction",
|
|
193
|
+
url: conventional
|
|
194
|
+
}] : [];
|
|
195
|
+
return [
|
|
196
|
+
...production,
|
|
197
|
+
...preprod,
|
|
198
|
+
...declared
|
|
199
|
+
];
|
|
169
200
|
}
|
|
170
201
|
const isAbsoluteHttpUrl = (value) => {
|
|
171
202
|
try {
|
|
@@ -1081,6 +1112,7 @@ function usePreviewTargetState() {
|
|
|
1081
1112
|
}
|
|
1082
1113
|
}, [environment]);
|
|
1083
1114
|
return {
|
|
1115
|
+
isProduction: !!(environment && config.previewUrl && environment.url === config.previewUrl),
|
|
1084
1116
|
environments: allEnvironments,
|
|
1085
1117
|
customUrl,
|
|
1086
1118
|
setCustomUrl,
|
|
@@ -1239,7 +1271,7 @@ function explainGrantError(error) {
|
|
|
1239
1271
|
* Version du kit, rapportée au service pour savoir quels projets tournent sur
|
|
1240
1272
|
* quelle version. Tenue à jour avec `package.json`.
|
|
1241
1273
|
*/
|
|
1242
|
-
const KIT_VERSION = "2.
|
|
1274
|
+
const KIT_VERSION = "2.2.0";
|
|
1243
1275
|
/**
|
|
1244
1276
|
* Signale ce Studio au service du kit, une fois par montage.
|
|
1245
1277
|
*
|
|
@@ -1908,7 +1940,7 @@ const TABULAR = { fontVariantNumeric: "tabular-nums" }, MONO = {
|
|
|
1908
1940
|
* menu à une entrée occupe la place sans rien offrir.
|
|
1909
1941
|
*/
|
|
1910
1942
|
function PreviewTarget(props) {
|
|
1911
|
-
let { environments, environmentId, perspective, onEnvironment, onPerspective } = props, { onCustomUrl, customUrl } = props, current = environments.find((environment) => environment.id === environmentId);
|
|
1943
|
+
let { environments, environmentId, perspective, onEnvironment, onPerspective } = props, { onCustomUrl, customUrl, productionUrl } = props, current = environments.find((environment) => environment.id === environmentId);
|
|
1912
1944
|
return /* @__PURE__ */ jsxs(Box, {
|
|
1913
1945
|
style: { flex: "none" },
|
|
1914
1946
|
children: [/* @__PURE__ */ jsx(FieldLabel, { children: "Aperçu" }), /* @__PURE__ */ jsxs(Flex, {
|
|
@@ -1953,6 +1985,7 @@ function PreviewTarget(props) {
|
|
|
1953
1985
|
environments.map((environment) => /* @__PURE__ */ jsx(EnvironmentRow, {
|
|
1954
1986
|
environment,
|
|
1955
1987
|
selected: environment.id === environmentId,
|
|
1988
|
+
isProduction: !!productionUrl && environment.url === productionUrl,
|
|
1956
1989
|
onSelect: () => {
|
|
1957
1990
|
onEnvironment(environment.id), close();
|
|
1958
1991
|
},
|
|
@@ -2011,7 +2044,7 @@ function EnvironmentRow(props) {
|
|
|
2011
2044
|
size: 0,
|
|
2012
2045
|
muted: !0,
|
|
2013
2046
|
textOverflow: "ellipsis",
|
|
2014
|
-
children: hostOf(props.environment.url)
|
|
2047
|
+
children: props.isProduction ? "site public — pas de préversion" : hostOf(props.environment.url)
|
|
2015
2048
|
})]
|
|
2016
2049
|
}),
|
|
2017
2050
|
props.onForget && /* @__PURE__ */ jsx(Button, {
|
|
@@ -2105,7 +2138,7 @@ const hostOf = (url) => {
|
|
|
2105
2138
|
* vérifie auprès de Sanity, il ne croit pas le Studio sur parole.
|
|
2106
2139
|
*/
|
|
2107
2140
|
function SharePreview() {
|
|
2108
|
-
let config = useKitConfig(), client = useKitClient(), { environment } = usePreviewTarget(), [link, setLink] = useState(null), [expiresAt, setExpiresAt] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null), [copied, setCopied] = useState(!1), [label, setLabel] = useState(""), endpoint = config.serviceEndpoint, { projectId, dataset, token } = client.config(), issue = useCallback(async (days) => {
|
|
2141
|
+
let config = useKitConfig(), client = useKitClient(), { environment, isProduction } = usePreviewTarget(), [link, setLink] = useState(null), [expiresAt, setExpiresAt] = useState(null), [busy, setBusy] = useState(!1), [error, setError] = useState(null), [copied, setCopied] = useState(!1), [label, setLabel] = useState(""), endpoint = config.serviceEndpoint, { projectId, dataset, token } = client.config(), issue = useCallback(async (days) => {
|
|
2109
2142
|
if (endpoint && projectId && dataset && environment) {
|
|
2110
2143
|
setBusy(!0), setError(null), setCopied(!1);
|
|
2111
2144
|
try {
|
|
@@ -2148,10 +2181,33 @@ function SharePreview() {
|
|
|
2148
2181
|
title: "Créer un lien que n'importe qui peut ouvrir, sans compte",
|
|
2149
2182
|
onClick: toggle
|
|
2150
2183
|
}),
|
|
2151
|
-
children: () => /* @__PURE__ */
|
|
2184
|
+
children: () => /* @__PURE__ */ jsx(Stack, {
|
|
2152
2185
|
gap: 3,
|
|
2153
2186
|
padding: 2,
|
|
2154
|
-
children:
|
|
2187
|
+
children: isProduction ? /* @__PURE__ */ jsxs(Stack, {
|
|
2188
|
+
gap: 3,
|
|
2189
|
+
children: [
|
|
2190
|
+
/* @__PURE__ */ jsx(Text, {
|
|
2191
|
+
size: 1,
|
|
2192
|
+
weight: "semibold",
|
|
2193
|
+
children: "Rien à partager sur le site public"
|
|
2194
|
+
}),
|
|
2195
|
+
/* @__PURE__ */ jsx(Text, {
|
|
2196
|
+
size: 0,
|
|
2197
|
+
muted: !0,
|
|
2198
|
+
children: "La production n'affiche jamais les brouillons — c'est ce qui protège votre contenu non publié. Un lien vers elle ne montrerait rien de plus qu'une visite ordinaire."
|
|
2199
|
+
}),
|
|
2200
|
+
/* @__PURE__ */ jsxs(Text, {
|
|
2201
|
+
size: 0,
|
|
2202
|
+
muted: !0,
|
|
2203
|
+
children: [
|
|
2204
|
+
"Choisissez d'abord une ",
|
|
2205
|
+
/* @__PURE__ */ jsx("b", { children: "préversion" }),
|
|
2206
|
+
" dans le sélecteur d'environnement, à gauche : une préproduction déclarée, ou l'adresse d'un déploiement de branche que vous y collez."
|
|
2207
|
+
]
|
|
2208
|
+
})
|
|
2209
|
+
]
|
|
2210
|
+
}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2155
2211
|
/* @__PURE__ */ jsxs(Text, {
|
|
2156
2212
|
size: 0,
|
|
2157
2213
|
muted: !0,
|
|
@@ -2248,7 +2304,7 @@ function SharePreview() {
|
|
|
2248
2304
|
})
|
|
2249
2305
|
]
|
|
2250
2306
|
})
|
|
2251
|
-
]
|
|
2307
|
+
] })
|
|
2252
2308
|
})
|
|
2253
2309
|
}) : null;
|
|
2254
2310
|
}
|
|
@@ -4843,7 +4899,8 @@ function PagesTool() {
|
|
|
4843
4899
|
onEnvironment: preview.setEnvironment,
|
|
4844
4900
|
onPerspective: preview.setPerspective,
|
|
4845
4901
|
onCustomUrl: preview.setCustomUrl,
|
|
4846
|
-
customUrl: preview.customUrl
|
|
4902
|
+
customUrl: preview.customUrl,
|
|
4903
|
+
productionUrl: config.previewUrl
|
|
4847
4904
|
}),
|
|
4848
4905
|
/* @__PURE__ */ jsx(Box, {
|
|
4849
4906
|
style: {
|