wpheadless-lib 1.1.4 → 1.1.5

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.
@@ -6,24 +6,24 @@ export type CategoryClientConfig = {
6
6
  appPassword?: string;
7
7
  };
8
8
  export declare function listCategoryStaticParams({ baseApiUrl, lang, }: CategoryClientConfig & {
9
- lang: string;
9
+ lang?: string;
10
10
  }): Promise<ApiResult<Array<{
11
11
  category: string;
12
12
  }>>>;
13
13
  export declare function getCategoryBySlug({ baseApiUrl, slug, lang, }: CategoryClientConfig & {
14
14
  slug: string;
15
- lang: string;
15
+ lang?: string;
16
16
  }): Promise<ApiResult<WPCategory | null>>;
17
17
  export declare function listCategoryPosts({ baseApiUrl, categoryId, perPage, langId, }: CategoryClientConfig & {
18
18
  categoryId: number;
19
19
  perPage: number;
20
- langId: string;
20
+ langId?: string;
21
21
  }): Promise<ApiResult<{
22
22
  posts: WPPost[];
23
23
  totalPages: number;
24
24
  }>>;
25
25
  export declare function getCategoryByTranslationKey({ baseApiUrl, translationKey, lang, perPage, }: CategoryClientConfig & {
26
26
  translationKey: string;
27
- lang: string;
27
+ lang?: string;
28
28
  perPage?: number;
29
29
  }): Promise<ApiResult<WPCategory | null>>;
@@ -5,7 +5,7 @@ export async function listCategoryStaticParams({ baseApiUrl, lang, }) {
5
5
  const { categoriesApi } = createWpClient({
6
6
  baseUrl: baseApiUrl,
7
7
  });
8
- const categories = await categoriesApi.listAll({ lang });
8
+ const categories = await categoriesApi.listAll(lang ? { lang } : undefined);
9
9
  return {
10
10
  ok: true,
11
11
  data: categories.map((category) => ({ category: category.slug })),
@@ -28,7 +28,7 @@ export async function getCategoryBySlug({ baseApiUrl, slug, lang, }) {
28
28
  const response = await categoriesApi.list({
29
29
  slug,
30
30
  per_page: 1,
31
- lang,
31
+ ...(lang ? { lang } : {}),
32
32
  _fields: ["id", "slug", "name", "description", "yoast_head_json", "meta"],
33
33
  });
34
34
  return { ok: true, data: response.items[0] ?? null, error: null };
@@ -46,13 +46,16 @@ export async function listCategoryPosts({ baseApiUrl, categoryId, perPage, langI
46
46
  const { postsApi } = createWpClient({
47
47
  baseUrl: baseApiUrl,
48
48
  });
49
+ const languageFilter = langId
50
+ ? { taxonomies: { language: [langId] } }
51
+ : {};
49
52
  const response = await postsApi.list({
50
53
  categories: [categoryId],
51
54
  per_page: perPage,
52
55
  orderby: "date",
53
56
  order: "desc",
54
57
  _embed: true,
55
- taxonomies: { language: [langId] },
58
+ ...languageFilter,
56
59
  });
57
60
  return {
58
61
  ok: true,
@@ -11,11 +11,11 @@ export type ClientConfig = {
11
11
  };
12
12
  export declare function getPostBySlug({ baseApiUrl, slug, langId, username, appPassword, }: ClientConfig & {
13
13
  slug: string;
14
- langId: string;
14
+ langId?: string;
15
15
  }): Promise<ApiResult<WPPost | null>>;
16
16
  export declare function listPostStaticParams({ baseApiUrl, lang, langId, }: ClientConfig & {
17
- lang: string;
18
- langId: string;
17
+ lang?: string;
18
+ langId?: string;
19
19
  }): Promise<ApiResult<Array<{
20
20
  category: string;
21
21
  post: string;
@@ -27,7 +27,7 @@ export declare function listPostsByTranslationKey({ baseApiUrl, translationKey,
27
27
  type ListPostsParams = ClientConfig & {
28
28
  perPage: number;
29
29
  page?: number;
30
- langId: string;
30
+ langId?: string;
31
31
  categories?: number[];
32
32
  embed?: boolean;
33
33
  fields?: string[];
@@ -38,7 +38,7 @@ export declare function listPosts({ baseApiUrl, perPage, page, langId, categorie
38
38
  export declare function listPostsWithEmbeds(params: Omit<ListPostsParams, "embed">): Promise<ApiResult<WPPaginatedResponse<WPPost>>>;
39
39
  export declare function getPostsTotalPages({ baseApiUrl, perPage, langId, categories, }: ClientConfig & {
40
40
  perPage: number;
41
- langId: string;
41
+ langId?: string;
42
42
  categories?: number[];
43
43
  }): Promise<ApiResult<number>>;
44
44
  export {};
package/dist/api/posts.js CHANGED
@@ -8,11 +8,14 @@ export async function getPostBySlug({ baseApiUrl, slug, langId, username, appPas
8
8
  username,
9
9
  appPassword,
10
10
  });
11
+ const languageFilter = langId
12
+ ? { taxonomies: { language: [langId] } }
13
+ : {};
11
14
  const response = await postsApi.list({
12
15
  slug,
13
16
  per_page: 1,
14
17
  _embed: true,
15
- taxonomies: { language: [langId] },
18
+ ...languageFilter,
16
19
  });
17
20
  return { ok: true, data: response.items[0] ?? null, error: null };
18
21
  }
@@ -23,11 +26,14 @@ export async function getPostBySlug({ baseApiUrl, slug, langId, username, appPas
23
26
  export async function listPostStaticParams({ baseApiUrl, lang, langId, }) {
24
27
  try {
25
28
  const { postsApi, categoriesApi } = createWpClient({ baseUrl: baseApiUrl });
26
- const categories = await categoriesApi.listAll({ lang });
29
+ const categories = await categoriesApi.listAll(lang ? { lang } : undefined);
30
+ const languageFilter = langId
31
+ ? { taxonomies: { language: [langId] } }
32
+ : {};
27
33
  const response = await postsApi.list({
28
34
  per_page: 100,
29
35
  _fields: ["slug", "categories"],
30
- taxonomies: { language: [langId] },
36
+ ...languageFilter,
31
37
  });
32
38
  const paths = [];
33
39
  for (const post of response.items) {
@@ -67,6 +73,9 @@ export async function listPosts({ baseApiUrl, perPage, page, langId, categories,
67
73
  const { postsApi } = createWpClient({
68
74
  baseUrl: baseApiUrl,
69
75
  });
76
+ const languageFilter = langId
77
+ ? { taxonomies: { language: [langId] } }
78
+ : {};
70
79
  const response = await postsApi.list({
71
80
  per_page: perPage,
72
81
  page,
@@ -75,7 +84,7 @@ export async function listPosts({ baseApiUrl, perPage, page, langId, categories,
75
84
  ...(categories ? { categories } : {}),
76
85
  ...(embed ? { _embed: true } : {}),
77
86
  ...(fields ? { _fields: fields } : {}),
78
- taxonomies: { language: [langId] },
87
+ ...languageFilter,
79
88
  });
80
89
  return { ok: true, data: response, error: null };
81
90
  }
@@ -21,7 +21,7 @@ export async function fetchCategoriesByTranslationKey({ baseApiUrl, translationK
21
21
  const response = await categoriesApi.list({
22
22
  translation_key_v2: translationKey,
23
23
  per_page: perPage,
24
- lang,
24
+ ...(lang ? { lang } : {}),
25
25
  _fields: ["id", "slug", "name", "description", "yoast_head_json", "meta"],
26
26
  });
27
27
  return response.items;
@@ -16,7 +16,7 @@ export declare function fetchCategoryPosts({ baseApiUrl, categoryId, perPage, la
16
16
  baseApiUrl: string;
17
17
  categoryId: number;
18
18
  perPage: number;
19
- langId: string;
19
+ langId?: string;
20
20
  }): Promise<{
21
21
  posts: WPPost[];
22
22
  totalPages: number;
@@ -4,7 +4,7 @@ type CategoryStaticParamsInput = {
4
4
  baseApiUrl: string;
5
5
  perPage: number;
6
6
  lang: string;
7
- langId: string;
7
+ langId?: string;
8
8
  };
9
9
  type CategoryStaticParam = {
10
10
  category: string;
@@ -21,7 +21,7 @@ export declare function fetchCategoryPaginatedPosts({ baseApiUrl, categoryId, pa
21
21
  categoryId: number;
22
22
  page: number;
23
23
  perPage: number;
24
- langId: string;
24
+ langId?: string;
25
25
  }): Promise<{
26
26
  posts: WPPost[];
27
27
  totalPages: number;
@@ -31,7 +31,7 @@ export declare function getCategoryTotalPages({ baseApiUrl, categoryId, perPage,
31
31
  baseApiUrl: string;
32
32
  categoryId: number;
33
33
  perPage: number;
34
- langId: string;
34
+ langId?: string;
35
35
  }): Promise<number>;
36
36
  export declare function buildCategoryPaginationMetadata({ category, canonicalBaseUrl, currentPage, useYoast, siteName, languages, }: {
37
37
  category: WPCategory;
@@ -2,7 +2,7 @@ import { type WPPost } from "wpjsapi-lib";
2
2
  type FetchHomePostsParams = {
3
3
  baseApiUrl: string;
4
4
  perPage: number;
5
- langId: string;
5
+ langId?: string;
6
6
  };
7
7
  type FetchHomePostsResult = {
8
8
  posts: WPPost[];
@@ -3,7 +3,7 @@ import type { Metadata } from "next";
3
3
  type StaticParamsInput = {
4
4
  baseApiUrl: string;
5
5
  perPage: number;
6
- langId: string;
6
+ langId?: string;
7
7
  };
8
8
  export declare function getHomePaginationStaticParams({ baseApiUrl, perPage, langId, }: StaticParamsInput): Promise<Array<{
9
9
  page: string;
@@ -11,13 +11,13 @@ export declare function getHomePaginationStaticParams({ baseApiUrl, perPage, lan
11
11
  export declare function getHomeTotalPages({ baseApiUrl, perPage, langId, }: {
12
12
  baseApiUrl: string;
13
13
  perPage: number;
14
- langId: string;
14
+ langId?: string;
15
15
  }): Promise<number>;
16
16
  type FetchPaginatedPostsInput = {
17
17
  baseApiUrl: string;
18
18
  perPage: number;
19
19
  page: number;
20
- langId: string;
20
+ langId?: string;
21
21
  };
22
22
  type FetchPaginatedPostsResult = {
23
23
  posts: WPPost[];
@@ -3,7 +3,7 @@ import type { Metadata } from "next";
3
3
  type PostStaticParamsInput = {
4
4
  baseApiUrl: string;
5
5
  lang: string;
6
- langId: string;
6
+ langId?: string;
7
7
  };
8
8
  type PostStaticParam = {
9
9
  category: string;
@@ -13,7 +13,7 @@ export declare function getPostStaticParams({ baseApiUrl, lang, langId, }: PostS
13
13
  export declare function fetchPostBySlug({ baseApiUrl, slug, langId, }: {
14
14
  baseApiUrl: string;
15
15
  slug: string;
16
- langId: string;
16
+ langId?: string;
17
17
  }): Promise<WPPost | null>;
18
18
  export declare function fetchPostsByTranslateKey({ baseApiUrl, translationKey, }: {
19
19
  baseApiUrl: string;
@@ -107,7 +107,7 @@ export async function getCategoryEntries(cfg) {
107
107
  for (const langCfg of languages) {
108
108
  const { categoriesApi } = createWpClient({ baseUrl: wpApiUrl });
109
109
  const categories = await categoriesApi.listAll({
110
- lang: langCfg.code,
110
+ ...(langCfg.langId ? { lang: langCfg.code } : {}),
111
111
  _fields: ["id", "slug", "name", "description", "meta"],
112
112
  });
113
113
  categoriesPerLang[langCfg.code] = categories;
@@ -133,7 +133,7 @@ export async function getCategoryEntries(cfg) {
133
133
  categories: [cat.id],
134
134
  perPage: runtimeConfig.postsPerPagePagination,
135
135
  page: 1,
136
- langId: langCfg.langId || "",
136
+ langId: langCfg.langId,
137
137
  orderby: "date",
138
138
  order: "desc",
139
139
  });
@@ -175,7 +175,7 @@ export async function getCategoryPaginationEntries(cfg) {
175
175
  baseApiUrl: wpApiUrl,
176
176
  perPage: runtimeConfig.postsPerPagePagination,
177
177
  lang: langCfg.code,
178
- langId: langCfg.langId || "",
178
+ langId: langCfg.langId,
179
179
  });
180
180
  const basePath = ensureTrailingSlash(langCfg.basePath || "/");
181
181
  for (const page of catPages) {
@@ -188,7 +188,7 @@ export async function getCategoryPaginationEntries(cfg) {
188
188
  categories: [catId],
189
189
  perPage: runtimeConfig.postsPerPagePagination,
190
190
  page: Number(page.page),
191
- langId: langCfg.langId || "",
191
+ langId: langCfg.langId,
192
192
  orderby: "date",
193
193
  order: "desc",
194
194
  });
@@ -213,10 +213,13 @@ export async function getPostEntriesForLang(langCode, cfg) {
213
213
  const wpApiUrl = resolveWpApiUrl(cfg);
214
214
  const siteUrl = resolveSiteUrl(cfg);
215
215
  const postsApi = createPostsEndpoints({ baseUrl: wpApiUrl });
216
+ const languageFilter = langCfg.langId
217
+ ? { taxonomies: { language: [langCfg.langId] } }
218
+ : {};
216
219
  const posts = await postsApi.listAll({
217
220
  per_page: 100,
218
221
  _embed: true,
219
- taxonomies: { language: [Number(langCfg.langId)] },
222
+ ...languageFilter,
220
223
  });
221
224
  const postAlternates = {};
222
225
  for (const l of languages) {
@@ -226,7 +229,7 @@ export async function getPostEntriesForLang(langCode, cfg) {
226
229
  : await postsApi.listAll({
227
230
  per_page: 100,
228
231
  _embed: true,
229
- taxonomies: { language: [Number(l.langId)] },
232
+ ...(l.langId ? { taxonomies: { language: [l.langId] } } : {}),
230
233
  });
231
234
  for (const p of langPosts) {
232
235
  const translationKey = getTranslationKey(p);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wpheadless-lib",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",