@cms-lab/strapi 1.0.9 → 1.1.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/README.md CHANGED
@@ -15,14 +15,24 @@ cms: {
15
15
  urlField: "routing.url",
16
16
  },
17
17
  ],
18
+ singleTypes: [
19
+ {
20
+ type: "navbar",
21
+ endpoint: "navbar",
22
+ },
23
+ ],
18
24
  }
19
25
  ```
20
26
 
21
- The adapter reads Strapi REST collection responses and normalizes them into
22
- cms-lab `CMSDocument` objects. It supports Strapi v4 `attributes` payloads and
23
- newer flat REST payloads, keeps native SEO/media fields in `document.data`, uses
24
- `documentId`, `slug`, or numeric `id` as stable identity values, and treats
25
- non-published statuses as `draft`.
27
+ The adapter reads Strapi REST collection and single-type responses and
28
+ normalizes them into cms-lab `CMSDocument` objects. It supports Strapi v4
29
+ `attributes` payloads and newer flat REST payloads, keeps native SEO/media
30
+ fields in `document.data`, uses `documentId`, `slug`, or numeric `id` as stable
31
+ identity values, and treats non-published statuses as `draft`.
32
+
33
+ Single types are marked as non-routable by default. cms-lab still runs field,
34
+ SEO, and image-alt checks on them, but it does not report missing route mappings
35
+ for layout or site-wide content such as navbars, footers, and homepage sections.
26
36
 
27
37
  Use `uidField` or `urlField` when your project stores route values in custom
28
38
  fields. Both options read dotted paths from `document.data`.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,12 @@
1
- import { FetchLike, StrapiCmsProviderConfig, CMSDocument, StrapiCollectionConfig } from '@cms-lab/core';
1
+ import { FetchLike, StrapiCmsProviderConfig, CMSDocument, StrapiCollectionConfig, StrapiSingleTypeConfig } from '@cms-lab/core';
2
2
 
3
3
  type FetchStrapiDocumentsOptions = {
4
4
  fetch?: FetchLike;
5
5
  };
6
6
  declare function fetchStrapiDocuments(config: StrapiCmsProviderConfig, options?: FetchStrapiDocumentsOptions): Promise<CMSDocument[]>;
7
- declare function normalizeStrapiItem(collection: string | StrapiCollectionConfig, item: unknown): CMSDocument;
7
+ declare function normalizeStrapiItem(collection: string | StrapiCollectionConfig | StrapiSingleTypeConfig, item: unknown, options?: {
8
+ fallbackUid?: boolean;
9
+ routable?: boolean;
10
+ }): CMSDocument;
8
11
 
9
12
  export { type FetchStrapiDocumentsOptions, fetchStrapiDocuments, normalizeStrapiItem };
package/dist/index.js CHANGED
@@ -6,13 +6,10 @@ import {
6
6
  async function fetchStrapiDocuments(config, options = {}) {
7
7
  const fetchImpl = options.fetch ?? fetch;
8
8
  const documents = [];
9
- for (const collection of config.collections) {
9
+ for (const collection of config.collections ?? []) {
10
10
  let page = 1;
11
11
  while (true) {
12
- const url = new URL(
13
- `/api/${trimSlashes(collection.endpoint)}`,
14
- config.url
15
- );
12
+ const url = strapiEndpointUrl(config.url, collection.endpoint);
16
13
  url.searchParams.set("pagination[pageSize]", "100");
17
14
  url.searchParams.set("pagination[page]", String(page));
18
15
  url.searchParams.set("populate", "*");
@@ -33,9 +30,26 @@ async function fetchStrapiDocuments(config, options = {}) {
33
30
  page += 1;
34
31
  }
35
32
  }
33
+ for (const singleType of config.singleTypes ?? []) {
34
+ const url = strapiEndpointUrl(config.url, singleType.endpoint);
35
+ url.searchParams.set("populate", "*");
36
+ const response = await fetchJson(
37
+ fetchImpl,
38
+ url,
39
+ authHeaders(config.token)
40
+ );
41
+ if (response.data != null) {
42
+ documents.push(
43
+ normalizeStrapiItem(singleType, response.data, {
44
+ fallbackUid: false,
45
+ routable: false
46
+ })
47
+ );
48
+ }
49
+ }
36
50
  return documents;
37
51
  }
38
- function normalizeStrapiItem(collection, item) {
52
+ function normalizeStrapiItem(collection, item, options = {}) {
39
53
  const config = collectionConfig(collection);
40
54
  const record = asRecord(item);
41
55
  const attributes = optionalRecord(record.attributes);
@@ -44,16 +58,26 @@ function normalizeStrapiItem(collection, item) {
44
58
  record.documentId ?? record.id ?? data.id,
45
59
  "Strapi item is missing id"
46
60
  );
47
- return {
61
+ const document = {
48
62
  id,
49
63
  type: config.type,
50
- uid: optionalString(
51
- mappedValue(data, config.uidField) ?? data.uid ?? data.slug ?? record.documentId ?? record.id
52
- ),
53
- url: optionalString(mappedValue(data, config.urlField)),
54
64
  status: normalizeStatus(data),
55
65
  data
56
66
  };
67
+ const uid = optionalString(
68
+ mappedValue(data, config.uidField) ?? data.uid ?? data.slug ?? (options.fallbackUid === false ? void 0 : record.documentId) ?? (options.fallbackUid === false ? void 0 : record.id)
69
+ );
70
+ const url = optionalString(mappedValue(data, config.urlField));
71
+ if (uid) {
72
+ document.uid = uid;
73
+ }
74
+ if (url) {
75
+ document.url = url;
76
+ }
77
+ if (options.routable !== void 0) {
78
+ document.routable = options.routable;
79
+ }
80
+ return document;
57
81
  }
58
82
  async function fetchJson(fetchImpl, url, headers) {
59
83
  let response;
@@ -85,6 +109,9 @@ function trimSlashes(value) {
85
109
  }
86
110
  return value.slice(start, end);
87
111
  }
112
+ function strapiEndpointUrl(baseUrl, endpoint) {
113
+ return new URL(`/api/${trimSlashes(endpoint)}`, baseUrl);
114
+ }
88
115
  function asRecord(value) {
89
116
  return value && typeof value === "object" ? value : {};
90
117
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cms-lab/strapi",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "Strapi document adapter for cms-lab.",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@cms-lab/core": "1.0.9"
38
+ "@cms-lab/core": "1.1.0"
39
39
  },
40
40
  "author": "Afaq Rashid",
41
41
  "scripts": {