@evenicanpm/cms 1.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/dist/client.d.ts +3 -0
- package/dist/content/blogs/index.d.ts +11 -0
- package/dist/content/blogs/types.d.ts +20 -0
- package/dist/content/navigation/index.d.ts +8 -0
- package/dist/content/navigation/types.d.ts +45 -0
- package/dist/content/pages/index.d.ts +5 -0
- package/dist/content/pages/types.d.ts +32 -0
- package/dist/index.d.ts +12 -0
- package/dist/media/get-image-url.d.ts +7 -0
- package/dist/media/index.d.ts +1 -0
- package/dist/session/index.d.ts +2 -0
- package/package.json +20 -0
- package/src/README.md +22 -0
- package/src/client.ts +7 -0
- package/src/content/blogs/index.ts +18 -0
- package/src/content/blogs/types.ts +18 -0
- package/src/content/navigation/.keep +0 -0
- package/src/content/navigation/index.ts +26 -0
- package/src/content/navigation/types.ts +52 -0
- package/src/content/pages/index.ts +14 -0
- package/src/content/pages/types.ts +31 -0
- package/src/index.ts +13 -0
- package/src/media/get-image-url.ts +25 -0
- package/src/media/index.ts +1 -0
- package/src/session/index.ts +7 -0
- package/tsconfig.json +18 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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 };
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./get-image-url";
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@evenicanpm/cms",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Strapi 5 client and queries for e4 Headless.",
|
|
5
|
+
"author": "Evenica",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"exports": "./src/index.ts",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"strapi-sdk-js": "^3.0.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/node": "^24.0.13"
|
|
18
|
+
},
|
|
19
|
+
"gitHead": "074f33378006dfc21ceb49456806a18dbb6e91ad"
|
|
20
|
+
}
|
package/src/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# e4 CMS Module
|
|
2
|
+
|
|
3
|
+
## index
|
|
4
|
+
|
|
5
|
+
- should export all content-type queries to be accessed with:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { cms } from '@evenicanpm/common-core/src/cms';
|
|
9
|
+
|
|
10
|
+
const blogs = await cms.blogs.getBlogs()
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## content/
|
|
14
|
+
|
|
15
|
+
- Contains strapi-client queries for content-types
|
|
16
|
+
|
|
17
|
+
## media/
|
|
18
|
+
|
|
19
|
+
- Contains helpers and utilities related to media library
|
|
20
|
+
and CMS images.
|
|
21
|
+
|
|
22
|
+
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { strapi } from "../../client";
|
|
2
|
+
import type { Blog } from "./types";
|
|
3
|
+
|
|
4
|
+
// Queries
|
|
5
|
+
const getBlogs = async (options: {
|
|
6
|
+
pagination: { pageSize: number; page: number };
|
|
7
|
+
}) => {
|
|
8
|
+
return await strapi.find<Blog>("blogs", {
|
|
9
|
+
pagination: { ...options.pagination, withCount: true },
|
|
10
|
+
populate: "*",
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const getBlog = async (options: { id: string }) => {
|
|
15
|
+
return await strapi.findOne<Blog>("blogs", options.id, { populate: "*" });
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { getBlogs, getBlog };
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
|
|
8
|
+
export interface Blog {
|
|
9
|
+
title: string;
|
|
10
|
+
content: any;
|
|
11
|
+
image: any;
|
|
12
|
+
documentId: string;
|
|
13
|
+
id: number;
|
|
14
|
+
shortDescription: string;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
publishedAt: Date;
|
|
17
|
+
createdBy: { firstname: string; lastname: string };
|
|
18
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { strapi } from "../../client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetch main navigation TREE
|
|
5
|
+
*
|
|
6
|
+
* Not an actual content type and has a specific endpoint
|
|
7
|
+
* so must use axios.request api directly
|
|
8
|
+
*/
|
|
9
|
+
const getMainNavigation = async () => {
|
|
10
|
+
// GET /navigation/render/main-navigation?type=TREE
|
|
11
|
+
try {
|
|
12
|
+
const response = await strapi.request(
|
|
13
|
+
"get",
|
|
14
|
+
"/navigation/render/navigation",
|
|
15
|
+
{
|
|
16
|
+
params: { type: "TREE" },
|
|
17
|
+
headers: {},
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
return response;
|
|
21
|
+
} catch (_error) {
|
|
22
|
+
console.log("error fetching strapi navigation data");
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { getMainNavigation };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// cms internal interfaces
|
|
2
|
+
export interface CmsNavigation {
|
|
3
|
+
nodes: {
|
|
4
|
+
name: string;
|
|
5
|
+
id: number;
|
|
6
|
+
items: (CmsPage | CmsSubMenu)[];
|
|
7
|
+
}[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CmsPage {
|
|
11
|
+
type: string;
|
|
12
|
+
id: number;
|
|
13
|
+
name: string;
|
|
14
|
+
slug: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CmsSubMenu {
|
|
18
|
+
type: string;
|
|
19
|
+
name: string;
|
|
20
|
+
pages: CmsPage[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CmsNavRelated {
|
|
24
|
+
id: number;
|
|
25
|
+
title: string;
|
|
26
|
+
slug: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
updatedAt: string;
|
|
29
|
+
publishedAt?: string | null;
|
|
30
|
+
|
|
31
|
+
/** Optional content‑type hint Strapi adds when `populate=*` */
|
|
32
|
+
__contentType?: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Any other attributes your model exposes (e.g., SEO fields,
|
|
36
|
+
* coverImage, etc.). Keep this open so the type stays valid
|
|
37
|
+
* if the Strapi model grows.
|
|
38
|
+
*/
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface CmsNavItem {
|
|
43
|
+
title: string;
|
|
44
|
+
menuAttached: boolean;
|
|
45
|
+
path: string;
|
|
46
|
+
type: "INTERNAL" | "EXTERNAL" | "WRAPPER";
|
|
47
|
+
uiRouterKey: string;
|
|
48
|
+
slug: string;
|
|
49
|
+
related: CmsNavRelated | null;
|
|
50
|
+
external: boolean;
|
|
51
|
+
items: CmsNavItem[];
|
|
52
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { strapi } from "../../client";
|
|
2
|
+
import type { Page } from "./types";
|
|
3
|
+
|
|
4
|
+
const getPage = async (options: { slug: string }) => {
|
|
5
|
+
const { slug } = options;
|
|
6
|
+
|
|
7
|
+
// Equivalent of: pages.find({ filter: { slug }, populate: "*" })
|
|
8
|
+
return await strapi.find<Page>("pages", {
|
|
9
|
+
filters: { slug },
|
|
10
|
+
populate: "*",
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { getPage };
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
|
|
8
|
+
type MetaElement = {
|
|
9
|
+
name: string;
|
|
10
|
+
content: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export interface Page {
|
|
14
|
+
title: string;
|
|
15
|
+
slug: string;
|
|
16
|
+
seo: {
|
|
17
|
+
// blocks.seo component
|
|
18
|
+
metaTitle?: string;
|
|
19
|
+
metaDescription?: string;
|
|
20
|
+
shareImage?: any;
|
|
21
|
+
metaImage?: { media: { url: string } };
|
|
22
|
+
metaKeywords: Array<string>;
|
|
23
|
+
meta: Array<MetaElement>;
|
|
24
|
+
} | null;
|
|
25
|
+
|
|
26
|
+
block: Array<{
|
|
27
|
+
__component: "blocks.rich-text";
|
|
28
|
+
id: number;
|
|
29
|
+
content: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
|
|
7
|
+
export const cms = {
|
|
8
|
+
blogs,
|
|
9
|
+
pages,
|
|
10
|
+
navigation,
|
|
11
|
+
media,
|
|
12
|
+
session,
|
|
13
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type imageSizes = "small" | "medium" | "large" | "thumbnail";
|
|
2
|
+
// Media
|
|
3
|
+
/**
|
|
4
|
+
* @param formats formats array from CMS data
|
|
5
|
+
* @param size size of the image
|
|
6
|
+
* @returns largest available image url
|
|
7
|
+
*/
|
|
8
|
+
export const getImageUrl = (formats: any, size?: imageSizes) => {
|
|
9
|
+
if (size) {
|
|
10
|
+
return formats[size]?.url;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (formats?.large?.url) {
|
|
14
|
+
return formats.large.url;
|
|
15
|
+
}
|
|
16
|
+
if (formats?.medium?.url) {
|
|
17
|
+
return formats.medium.url;
|
|
18
|
+
}
|
|
19
|
+
if (formats?.small?.url) {
|
|
20
|
+
return formats.small.url;
|
|
21
|
+
}
|
|
22
|
+
if (formats?.thumbnail?.url) {
|
|
23
|
+
return formats.thumbnail.url;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./get-image-url";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES6",
|
|
4
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"sourceMap": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"moduleResolution": "node",
|
|
11
|
+
"resolveJsonModule": true,
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"baseUrl": "./",
|
|
14
|
+
"emitDeclarationOnly": true,
|
|
15
|
+
"jsx": "preserve"
|
|
16
|
+
},
|
|
17
|
+
"include": ["./"]
|
|
18
|
+
}
|