@jsonpages/cli 3.0.51 → 3.0.52

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.
@@ -53,6 +53,7 @@ import tenantCss from './index.css?inline';
53
53
  // Cloud Configuration (Injected by Vercel/Netlify Env Vars)
54
54
  const CLOUD_API_URL = import.meta.env.VITE_JSONPAGES_CLOUD_URL;
55
55
  const CLOUD_API_KEY = import.meta.env.VITE_JSONPAGES_API_KEY;
56
+ const CLOUD_SAVE_ENABLED = Boolean(CLOUD_API_URL && CLOUD_API_KEY);
56
57
 
57
58
  const themeConfig = themeData as unknown as ThemeConfig;
58
59
  const menuConfig = menuData as unknown as MenuConfig;
@@ -102,22 +103,33 @@ function App() {
102
103
  const body = (await res.json().catch(() => ({}))) as { error?: string };
103
104
  if (!res.ok) throw new Error(body.error ?? `Save to file failed: ${res.status}`);
104
105
  },
105
- ...(CLOUD_API_URL && CLOUD_API_KEY
106
+ ...(CLOUD_SAVE_ENABLED
106
107
  ? {
107
108
  saveToFileStream: async (state: ProjectState, slug: string): Promise<Response> => {
108
- const res = await fetch(`${CLOUD_API_URL}/save-stream`, {
109
- method: 'POST',
110
- headers: {
111
- 'Content-Type': 'application/json',
112
- Authorization: `Bearer ${CLOUD_API_KEY}`,
113
- },
114
- body: JSON.stringify({
115
- path: `src/data/pages/${slug}.json`,
116
- content: state.page,
117
- message: `Content update for ${slug} via Visual Editor`,
118
- }),
119
- });
120
- return res;
109
+ const url = `${CLOUD_API_URL}/save-stream`;
110
+ try {
111
+ const res = await fetch(url, {
112
+ method: 'POST',
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ Authorization: `Bearer ${CLOUD_API_KEY}`,
116
+ },
117
+ body: JSON.stringify({
118
+ path: `src/data/pages/${slug}.json`,
119
+ content: state.page,
120
+ message: `Content update for ${slug} via Visual Editor`,
121
+ }),
122
+ });
123
+ return res;
124
+ } catch (err) {
125
+ const msg = err instanceof Error ? err.message : String(err);
126
+ if (/fetch|network|Failed to fetch/i.test(msg)) {
127
+ throw new Error(
128
+ 'Impossibile contattare il server di salvataggio. Verifica che VITE_JSONPAGES_CLOUD_URL sia corretto (es. https://tua-piattaforma.vercel.app/api/v1) e che la piattaforma sia online, poi riprova.'
129
+ );
130
+ }
131
+ throw err;
132
+ }
121
133
  },
122
134
  }
123
135
  : {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonpages/cli",
3
- "version": "3.0.51",
3
+ "version": "3.0.52",
4
4
  "description": "The Sovereign CLI Engine for JsonPages.",
5
5
  "type": "module",
6
6
  "bin": {