@evenicanpm/cms 2.0.1 → 2.3.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/package.json +6 -4
- package/src/content/blogs/index.ts +17 -5
- package/src/content/blogs/types.ts +17 -2
- package/src/content/header/index.ts +26 -0
- package/src/content/header/types.ts +19 -0
- package/src/content/navigation/index.ts +2 -1
- package/src/content/pages/index.ts +20 -5
- package/src/content/pages/types.ts +3 -5
- package/src/index.ts +4 -0
- package/src/locales/index.ts +15 -0
- package/src/locales/types.ts +10 -0
- package/tsconfig.json +2 -4
- package/dist/client.d.ts +0 -3
- package/dist/content/blogs/index.d.ts +0 -11
- package/dist/content/blogs/types.d.ts +0 -20
- package/dist/content/navigation/index.d.ts +0 -8
- package/dist/content/navigation/types.d.ts +0 -45
- package/dist/content/pages/index.d.ts +0 -5
- package/dist/content/pages/types.d.ts +0 -32
- package/dist/index.d.ts +0 -12
- package/dist/media/get-image-url.d.ts +0 -7
- package/dist/media/index.d.ts +0 -1
- package/dist/session/index.d.ts +0 -2
package/package.json
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evenicanpm/cms",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Strapi 5 client and queries for e4 Headless.",
|
|
5
5
|
"author": "Evenica",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"exports": "./src/index.ts",
|
|
9
|
-
"types": "./
|
|
9
|
+
"types": "./src/index.ts",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
12
|
},
|
|
13
|
-
"dependencies": {
|
|
13
|
+
"dependencies": {},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"@strapi/blocks-react-renderer": "^1.0.1",
|
|
14
16
|
"strapi-sdk-js": "^3.0.0"
|
|
15
17
|
},
|
|
16
18
|
"devDependencies": {
|
|
17
19
|
"@types/node": "^24.0.13"
|
|
18
20
|
},
|
|
19
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "72bf1aeb02a3d96c587706c0d91606698e38ff6a"
|
|
20
22
|
}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
import type { StrapiResponse } from "strapi-sdk-js";
|
|
1
2
|
import { strapi } from "../../client";
|
|
2
3
|
import type { Blog } from "./types";
|
|
3
4
|
|
|
5
|
+
const getLocaleOption = (options: { locale?: string }) =>
|
|
6
|
+
options.locale ? { locale: options.locale } : {};
|
|
7
|
+
|
|
4
8
|
// Queries
|
|
5
9
|
const getBlogs = async (options: {
|
|
6
10
|
pagination: { pageSize: number; page: number };
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
locale?: string;
|
|
12
|
+
}): Promise<StrapiResponse<Blog[]>> => {
|
|
13
|
+
return strapi.find<Blog>("blogs", {
|
|
9
14
|
pagination: { ...options.pagination, withCount: true },
|
|
10
15
|
populate: "*",
|
|
11
|
-
|
|
16
|
+
...getLocaleOption(options),
|
|
17
|
+
} as Parameters<typeof strapi.find>[1]);
|
|
12
18
|
};
|
|
13
19
|
|
|
14
|
-
const getBlog = async (options: {
|
|
15
|
-
|
|
20
|
+
const getBlog = async (options: {
|
|
21
|
+
id: string;
|
|
22
|
+
locale?: string;
|
|
23
|
+
}): Promise<StrapiResponse<Blog>> => {
|
|
24
|
+
return strapi.findOne<Blog>("blogs", options.id, {
|
|
25
|
+
populate: "*",
|
|
26
|
+
...getLocaleOption(options),
|
|
27
|
+
} as Parameters<typeof strapi.findOne>[2]);
|
|
16
28
|
};
|
|
17
29
|
|
|
18
30
|
export { getBlog, getBlogs };
|
|
@@ -5,12 +5,27 @@
|
|
|
5
5
|
* TODO: Auto-generated interfaces from Strapi
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export interface BlogImage {
|
|
9
|
+
id: number;
|
|
10
|
+
url: string;
|
|
11
|
+
alternativeText: string | null;
|
|
12
|
+
caption: string | null;
|
|
13
|
+
formats: {
|
|
14
|
+
large?: { url: string };
|
|
15
|
+
medium?: { url: string };
|
|
16
|
+
small?: { url: string };
|
|
17
|
+
thumbnail?: { url: string };
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
8
21
|
export interface Blog {
|
|
9
22
|
title: string;
|
|
10
|
-
content: unknown;
|
|
11
|
-
image:
|
|
23
|
+
content: unknown[];
|
|
24
|
+
image: BlogImage | null;
|
|
25
|
+
author?: string;
|
|
12
26
|
documentId: string;
|
|
13
27
|
id: number;
|
|
28
|
+
locale?: string;
|
|
14
29
|
shortDescription: string;
|
|
15
30
|
createdAt: Date;
|
|
16
31
|
publishedAt: Date;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { strapi } from "../../client";
|
|
2
|
+
import type { HeaderConfig } from "./types";
|
|
3
|
+
|
|
4
|
+
type HeaderApiResponse = {
|
|
5
|
+
data?: (HeaderConfig & { attributes?: HeaderConfig }) | null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export async function getHeader(): Promise<HeaderConfig | null> {
|
|
9
|
+
try {
|
|
10
|
+
const params = {
|
|
11
|
+
populate: "announcementBanner",
|
|
12
|
+
};
|
|
13
|
+
const res = await strapi.request<HeaderApiResponse>("get", "/header", {
|
|
14
|
+
params,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const payload = res?.data;
|
|
18
|
+
if (!payload) return null;
|
|
19
|
+
|
|
20
|
+
const config = payload.attributes ?? payload;
|
|
21
|
+
return config as HeaderConfig;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
console.warn("header unavailable from Strapi, falling back to null", error);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface AnnouncementBanner {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
text?: string;
|
|
4
|
+
backgroundColor?: string;
|
|
5
|
+
textColor?: string;
|
|
6
|
+
link?: string;
|
|
7
|
+
linkText?: string;
|
|
8
|
+
dismissible?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface HeaderConfig {
|
|
12
|
+
showSearch: boolean;
|
|
13
|
+
showCart: boolean;
|
|
14
|
+
showUserMenu: boolean;
|
|
15
|
+
showWishlist: boolean;
|
|
16
|
+
showLocaleSwitcher: boolean;
|
|
17
|
+
showLogo: boolean;
|
|
18
|
+
announcementBanner?: AnnouncementBanner;
|
|
19
|
+
}
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { strapi } from "../../client";
|
|
2
2
|
import type { Page } from "./types";
|
|
3
3
|
|
|
4
|
-
const getPage = async (options: {
|
|
5
|
-
|
|
4
|
+
const getPage = async (options: {
|
|
5
|
+
slug: string;
|
|
6
|
+
status?: "draft" | "published";
|
|
7
|
+
locale?: string;
|
|
8
|
+
}) => {
|
|
9
|
+
const { slug, status, locale } = options;
|
|
6
10
|
|
|
7
|
-
// Equivalent of: pages.find({ filter: { slug }, populate: "*" })
|
|
8
11
|
return await strapi.find<Page>("pages", {
|
|
9
12
|
filters: { slug },
|
|
10
|
-
populate:
|
|
11
|
-
|
|
13
|
+
populate: {
|
|
14
|
+
seo: true,
|
|
15
|
+
block: {
|
|
16
|
+
on: {
|
|
17
|
+
"blocks.hero-image": {
|
|
18
|
+
populate: { image: true },
|
|
19
|
+
},
|
|
20
|
+
"blocks.rich-text": true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
...((status ? { status } : {}) as object),
|
|
25
|
+
...(locale ? { locale } : {}),
|
|
26
|
+
} as Parameters<typeof strapi.find>[1]);
|
|
12
27
|
};
|
|
13
28
|
|
|
14
29
|
export { getPage };
|
|
@@ -11,6 +11,8 @@ type MetaElement = {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export interface Page {
|
|
14
|
+
id: number;
|
|
15
|
+
documentId: string;
|
|
14
16
|
title: string;
|
|
15
17
|
slug: string;
|
|
16
18
|
seo: {
|
|
@@ -23,9 +25,5 @@ export interface Page {
|
|
|
23
25
|
meta: Array<MetaElement>;
|
|
24
26
|
} | null;
|
|
25
27
|
|
|
26
|
-
block: Array<{
|
|
27
|
-
__component: "blocks.rich-text";
|
|
28
|
-
id: number;
|
|
29
|
-
content: string;
|
|
30
|
-
}>;
|
|
28
|
+
block: Array<{ __component: string; id: number; [key: string]: unknown }>;
|
|
31
29
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as blogs from "./content/blogs";
|
|
2
|
+
import * as header from "./content/header";
|
|
2
3
|
import * as navigation from "./content/navigation";
|
|
3
4
|
import * as pages from "./content/pages";
|
|
5
|
+
import * as locales from "./locales";
|
|
4
6
|
import * as media from "./media";
|
|
5
7
|
import * as session from "./session";
|
|
6
8
|
|
|
@@ -8,6 +10,8 @@ export const cms = {
|
|
|
8
10
|
blogs,
|
|
9
11
|
pages,
|
|
10
12
|
navigation,
|
|
13
|
+
locales,
|
|
11
14
|
media,
|
|
12
15
|
session,
|
|
16
|
+
header,
|
|
13
17
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { strapi } from "../client";
|
|
2
|
+
import type { CmsLocale } from "./types";
|
|
3
|
+
|
|
4
|
+
const getLocales = async () => {
|
|
5
|
+
try {
|
|
6
|
+
return await strapi.request<CmsLocale[]>("get", "/i18n/locales", {
|
|
7
|
+
headers: {},
|
|
8
|
+
});
|
|
9
|
+
} catch (error) {
|
|
10
|
+
console.log("error fetching strapi locale data", error);
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { getLocales };
|
package/tsconfig.json
CHANGED
|
@@ -6,13 +6,11 @@
|
|
|
6
6
|
"sourceMap": true,
|
|
7
7
|
"esModuleInterop": true,
|
|
8
8
|
"skipLibCheck": true,
|
|
9
|
-
"declaration": true,
|
|
10
9
|
"moduleResolution": "node",
|
|
11
10
|
"resolveJsonModule": true,
|
|
12
|
-
"outDir": "./dist",
|
|
13
11
|
"baseUrl": "./",
|
|
14
|
-
"
|
|
12
|
+
"noEmit": true,
|
|
15
13
|
"jsx": "preserve"
|
|
16
14
|
},
|
|
17
|
-
"include": ["./"]
|
|
15
|
+
"include": ["./src"]
|
|
18
16
|
}
|
package/dist/client.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Blog } from "./types";
|
|
2
|
-
declare const getBlogs: (options: {
|
|
3
|
-
pagination: {
|
|
4
|
-
pageSize: number;
|
|
5
|
-
page: number;
|
|
6
|
-
};
|
|
7
|
-
}) => Promise<import("strapi-sdk-js").StrapiResponse<Blog[]>>;
|
|
8
|
-
declare const getBlog: (options: {
|
|
9
|
-
id: string;
|
|
10
|
-
}) => Promise<import("strapi-sdk-js").StrapiResponse<Blog>>;
|
|
11
|
-
export { getBlogs, getBlog };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface is not auto-generated and needs to be updated
|
|
3
|
-
* whenever Strapi Content-Type is modified.
|
|
4
|
-
*
|
|
5
|
-
* TODO: Auto-generated interfaces from Strapi
|
|
6
|
-
*/
|
|
7
|
-
export interface Blog {
|
|
8
|
-
title: string;
|
|
9
|
-
content: any;
|
|
10
|
-
image: any;
|
|
11
|
-
documentId: string;
|
|
12
|
-
id: number;
|
|
13
|
-
shortDescription: string;
|
|
14
|
-
createdAt: Date;
|
|
15
|
-
publishedAt: Date;
|
|
16
|
-
createdBy: {
|
|
17
|
-
firstname: string;
|
|
18
|
-
lastname: string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export interface CmsNavigation {
|
|
2
|
-
nodes: {
|
|
3
|
-
name: string;
|
|
4
|
-
id: number;
|
|
5
|
-
items: (CmsPage | CmsSubMenu)[];
|
|
6
|
-
}[];
|
|
7
|
-
}
|
|
8
|
-
export interface CmsPage {
|
|
9
|
-
type: string;
|
|
10
|
-
id: number;
|
|
11
|
-
name: string;
|
|
12
|
-
slug: string;
|
|
13
|
-
}
|
|
14
|
-
export interface CmsSubMenu {
|
|
15
|
-
type: string;
|
|
16
|
-
name: string;
|
|
17
|
-
pages: CmsPage[];
|
|
18
|
-
}
|
|
19
|
-
export interface CmsNavRelated {
|
|
20
|
-
id: number;
|
|
21
|
-
title: string;
|
|
22
|
-
slug: string;
|
|
23
|
-
createdAt: string;
|
|
24
|
-
updatedAt: string;
|
|
25
|
-
publishedAt?: string | null;
|
|
26
|
-
/** Optional content‑type hint Strapi adds when `populate=*` */
|
|
27
|
-
__contentType?: string;
|
|
28
|
-
/**
|
|
29
|
-
* Any other attributes your model exposes (e.g., SEO fields,
|
|
30
|
-
* coverImage, etc.). Keep this open so the type stays valid
|
|
31
|
-
* if the Strapi model grows.
|
|
32
|
-
*/
|
|
33
|
-
[key: string]: unknown;
|
|
34
|
-
}
|
|
35
|
-
export interface CmsNavItem {
|
|
36
|
-
title: string;
|
|
37
|
-
menuAttached: boolean;
|
|
38
|
-
path: string;
|
|
39
|
-
type: "INTERNAL" | "EXTERNAL" | "WRAPPER";
|
|
40
|
-
uiRouterKey: string;
|
|
41
|
-
slug: string;
|
|
42
|
-
related: CmsNavRelated | null;
|
|
43
|
-
external: boolean;
|
|
44
|
-
items: CmsNavItem[];
|
|
45
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interface is not auto-generated and needs to be updated
|
|
3
|
-
* whenever Strapi Content-Type is modified.
|
|
4
|
-
*
|
|
5
|
-
* TODO: Auto-generated interfaces from Strapi
|
|
6
|
-
*/
|
|
7
|
-
type MetaElement = {
|
|
8
|
-
name: string;
|
|
9
|
-
content: string;
|
|
10
|
-
};
|
|
11
|
-
export interface Page {
|
|
12
|
-
title: string;
|
|
13
|
-
slug: string;
|
|
14
|
-
seo: {
|
|
15
|
-
metaTitle?: string;
|
|
16
|
-
metaDescription?: string;
|
|
17
|
-
shareImage?: any;
|
|
18
|
-
metaImage?: {
|
|
19
|
-
media: {
|
|
20
|
-
url: string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
metaKeywords: Array<string>;
|
|
24
|
-
meta: Array<MetaElement>;
|
|
25
|
-
} | null;
|
|
26
|
-
block: Array<{
|
|
27
|
-
__component: "blocks.rich-text";
|
|
28
|
-
id: number;
|
|
29
|
-
content: string;
|
|
30
|
-
}>;
|
|
31
|
-
}
|
|
32
|
-
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as blogs from "./content/blogs";
|
|
2
|
-
import * as navigation from "./content/navigation";
|
|
3
|
-
import * as pages from "./content/pages";
|
|
4
|
-
import * as media from "./media";
|
|
5
|
-
import * as session from "./session";
|
|
6
|
-
export declare const cms: {
|
|
7
|
-
blogs: typeof blogs;
|
|
8
|
-
pages: typeof pages;
|
|
9
|
-
navigation: typeof navigation;
|
|
10
|
-
media: typeof media;
|
|
11
|
-
session: typeof session;
|
|
12
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type imageSizes = "small" | "medium" | "large" | "thumbnail";
|
|
2
|
-
/**
|
|
3
|
-
* @param formats formats array from CMS data
|
|
4
|
-
* @param size size of the image
|
|
5
|
-
* @returns largest available image url
|
|
6
|
-
*/
|
|
7
|
-
export declare const getImageUrl: (formats: any, size?: imageSizes) => any;
|
package/dist/media/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./get-image-url";
|
package/dist/session/index.d.ts
DELETED