@sprintup-cms/sdk 1.9.0 → 1.9.2
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/client.cjs +34 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +13 -1
- package/dist/client.d.ts +13 -1
- package/dist/client.js +34 -7
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +34 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -7
- package/dist/index.js.map +1 -1
- package/dist/next/index.cjs +34 -7
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.js +34 -7
- package/dist/next/index.js.map +1 -1
- package/package.json +1 -1
package/dist/next/index.js
CHANGED
|
@@ -257,24 +257,51 @@ function createCMSClient(options) {
|
|
|
257
257
|
return null;
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
+
function resolveNavItems(items = []) {
|
|
261
|
+
return items.map((item) => {
|
|
262
|
+
let href = "#";
|
|
263
|
+
if (item.type === "anchor") {
|
|
264
|
+
const anchorId = item.anchorTarget || "";
|
|
265
|
+
const anchorPage = item.anchorPage || "";
|
|
266
|
+
if (anchorId) {
|
|
267
|
+
href = anchorPage ? `/${anchorPage}#${anchorId}` : `#${anchorId}`;
|
|
268
|
+
}
|
|
269
|
+
} else if (item.url) {
|
|
270
|
+
href = item.url;
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
id: item.id ?? "",
|
|
274
|
+
type: item.type ?? "link",
|
|
275
|
+
label: item.label ?? "",
|
|
276
|
+
url: item.url,
|
|
277
|
+
anchorTarget: item.anchorTarget,
|
|
278
|
+
anchorPage: item.anchorPage,
|
|
279
|
+
href,
|
|
280
|
+
locked: item.locked ?? false,
|
|
281
|
+
openInNewTab: item.openInNewTab ?? false,
|
|
282
|
+
children: resolveNavItems(item.children ?? [])
|
|
283
|
+
};
|
|
284
|
+
});
|
|
285
|
+
}
|
|
260
286
|
async function getGlobals() {
|
|
261
287
|
const { baseUrl, appId } = cfg();
|
|
262
|
-
if (!baseUrl || !appId) return { navigation: null, footer: null };
|
|
288
|
+
if (!baseUrl || !appId) return { navigation: null, footer: null, navItems: [] };
|
|
263
289
|
try {
|
|
264
290
|
const res = await fetch(`${baseUrl}/api/v1/${appId}/globals`, {
|
|
265
291
|
headers: headers(),
|
|
266
292
|
next: { revalidate: 60, tags: [`cms-globals-${appId}`] }
|
|
267
293
|
});
|
|
268
|
-
if (!res.ok) {
|
|
269
|
-
return { navigation: null, footer: null };
|
|
270
|
-
}
|
|
294
|
+
if (!res.ok) return { navigation: null, footer: null, navItems: [] };
|
|
271
295
|
const json = await res.json();
|
|
296
|
+
const navigation = json.data?.navigation ?? null;
|
|
297
|
+
const rawItems = navigation?.blocks?.[0]?.content?.items ?? navigation?.blocks?.[0]?.data?.items ?? [];
|
|
272
298
|
return {
|
|
273
|
-
navigation
|
|
274
|
-
footer: json.data?.footer ?? null
|
|
299
|
+
navigation,
|
|
300
|
+
footer: json.data?.footer ?? null,
|
|
301
|
+
navItems: resolveNavItems(rawItems)
|
|
275
302
|
};
|
|
276
303
|
} catch {
|
|
277
|
-
return { navigation: null, footer: null };
|
|
304
|
+
return { navigation: null, footer: null, navItems: [] };
|
|
278
305
|
}
|
|
279
306
|
}
|
|
280
307
|
return {
|