@cms-lab/strapi 1.1.0 → 1.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/README.md CHANGED
@@ -7,6 +7,7 @@ cms: {
7
7
  provider: "strapi",
8
8
  url: "http://localhost:1337",
9
9
  token: process.env.STRAPI_TOKEN,
10
+ locale: "en",
10
11
  collections: [
11
12
  {
12
13
  type: "page",
@@ -37,6 +38,19 @@ for layout or site-wide content such as navbars, footers, and homepage sections.
37
38
  Use `uidField` or `urlField` when your project stores route values in custom
38
39
  fields. Both options read dotted paths from `document.data`.
39
40
 
41
+ Set `cms.locale` to fetch all configured collections and single types for a
42
+ locale. Individual collection or single-type entries can override it with their
43
+ own `locale` value.
44
+
45
+ For Next.js Pages Router projects, start with:
46
+
47
+ ```sh
48
+ cms-lab init --cms strapi --router pages
49
+ ```
50
+
51
+ The generated config includes collection routes, single types, and
52
+ `strapiRelationSlug` for relation-based URL segments.
53
+
40
54
  ## Release History
41
55
 
42
56
  See the repository [changelog](https://github.com/i-afaqrashid/cms-lab/blob/main/CHANGELOG.md)
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ declare function fetchStrapiDocuments(config: StrapiCmsProviderConfig, options?:
7
7
  declare function normalizeStrapiItem(collection: string | StrapiCollectionConfig | StrapiSingleTypeConfig, item: unknown, options?: {
8
8
  fallbackUid?: boolean;
9
9
  routable?: boolean;
10
+ entryKind?: CMSDocument["entryKind"];
10
11
  }): CMSDocument;
11
12
 
12
13
  export { type FetchStrapiDocumentsOptions, fetchStrapiDocuments, normalizeStrapiItem };
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@ async function fetchStrapiDocuments(config, options = {}) {
13
13
  url.searchParams.set("pagination[pageSize]", "100");
14
14
  url.searchParams.set("pagination[page]", String(page));
15
15
  url.searchParams.set("populate", "*");
16
+ applyLocale(url, collection.locale ?? config.locale);
16
17
  const response = await fetchJson(
17
18
  fetchImpl,
18
19
  url,
@@ -20,7 +21,7 @@ async function fetchStrapiDocuments(config, options = {}) {
20
21
  );
21
22
  documents.push(
22
23
  ...(response.data ?? []).map(
23
- (item) => normalizeStrapiItem(collection, item)
24
+ (item) => normalizeStrapiItem(collection, item, { entryKind: "collection" })
24
25
  )
25
26
  );
26
27
  const pageCount = response.meta?.pagination?.pageCount ?? page;
@@ -33,6 +34,7 @@ async function fetchStrapiDocuments(config, options = {}) {
33
34
  for (const singleType of config.singleTypes ?? []) {
34
35
  const url = strapiEndpointUrl(config.url, singleType.endpoint);
35
36
  url.searchParams.set("populate", "*");
37
+ applyLocale(url, singleType.locale ?? config.locale);
36
38
  const response = await fetchJson(
37
39
  fetchImpl,
38
40
  url,
@@ -42,7 +44,8 @@ async function fetchStrapiDocuments(config, options = {}) {
42
44
  documents.push(
43
45
  normalizeStrapiItem(singleType, response.data, {
44
46
  fallbackUid: false,
45
- routable: false
47
+ routable: false,
48
+ entryKind: "single"
46
49
  })
47
50
  );
48
51
  }
@@ -77,6 +80,9 @@ function normalizeStrapiItem(collection, item, options = {}) {
77
80
  if (options.routable !== void 0) {
78
81
  document.routable = options.routable;
79
82
  }
83
+ if (options.entryKind) {
84
+ document.entryKind = options.entryKind;
85
+ }
80
86
  return document;
81
87
  }
82
88
  async function fetchJson(fetchImpl, url, headers) {
@@ -112,6 +118,11 @@ function trimSlashes(value) {
112
118
  function strapiEndpointUrl(baseUrl, endpoint) {
113
119
  return new URL(`/api/${trimSlashes(endpoint)}`, baseUrl);
114
120
  }
121
+ function applyLocale(url, locale) {
122
+ if (locale) {
123
+ url.searchParams.set("locale", locale);
124
+ }
125
+ }
115
126
  function asRecord(value) {
116
127
  return value && typeof value === "object" ? value : {};
117
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cms-lab/strapi",
3
- "version": "1.1.0",
3
+ "version": "1.2.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.1.0"
38
+ "@cms-lab/core": "1.2.0"
39
39
  },
40
40
  "author": "Afaq Rashid",
41
41
  "scripts": {