@sprintup-cms/sdk 1.9.1 → 1.9.3

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.
@@ -96,6 +96,32 @@ async function previewEntryGET(request) {
96
96
  }
97
97
 
98
98
  // src/client.ts
99
+ function resolveNavItems(items = []) {
100
+ return items.map((item) => {
101
+ let href = "#";
102
+ if (item.type === "anchor") {
103
+ const anchorId = item.anchorTarget || "";
104
+ const anchorPage = item.anchorPage || "";
105
+ if (anchorId) {
106
+ href = anchorPage ? `/${anchorPage}#${anchorId}` : `#${anchorId}`;
107
+ }
108
+ } else if (item.url) {
109
+ href = item.url;
110
+ }
111
+ return {
112
+ id: item.id ?? "",
113
+ type: item.type ?? "link",
114
+ label: item.label ?? "",
115
+ url: item.url,
116
+ anchorTarget: item.anchorTarget,
117
+ anchorPage: item.anchorPage,
118
+ href,
119
+ locked: item.locked ?? false,
120
+ openInNewTab: item.openInNewTab ?? false,
121
+ children: resolveNavItems(item.children ?? [])
122
+ };
123
+ });
124
+ }
99
125
  function createCMSClient(options) {
100
126
  function cfg() {
101
127
  return {
@@ -259,22 +285,23 @@ function createCMSClient(options) {
259
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: json.data?.navigation ?? null,
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 {