@malevich-studio/strapi-sdk-typescript 1.0.8 → 1.0.9
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 +125 -0
- package/package.json +16 -2
package/README.md
CHANGED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Strapi SDK for TypeScript
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with Strapi APIs.
|
|
4
|
+
|
|
5
|
+
## 🚀 Installation
|
|
6
|
+
|
|
7
|
+
To install the SDK, run:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @malevich-studio/strapi-sdk-typescript
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## 🛠 Configuration
|
|
14
|
+
|
|
15
|
+
Create a `.env` file with your Strapi base URL and API token:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
STRAPI_URL=http://localhost:1337
|
|
19
|
+
STRAPI_TOKEN=<your_strapi_token>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Generating API Token
|
|
23
|
+
|
|
24
|
+
To interact with the Strapi API, you need to create an API token with at least `Content-Type Builder` permissions.
|
|
25
|
+
Navigate to:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
<your_strapi_base_url>/admin/settings/api-tokens/create
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Generating API Class
|
|
32
|
+
|
|
33
|
+
Run the following command to generate TypeScript types based on your Strapi schema:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npx generate-strapi-types
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 📌 Usage
|
|
40
|
+
|
|
41
|
+
### Basic Example
|
|
42
|
+
|
|
43
|
+
Create `strapi.ts` to initialize the API class:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import Strapi from "./strapi"; // strapi.ts file
|
|
47
|
+
|
|
48
|
+
const api = new Strapi(process.env.STRAPI_URL || '', process.env.STRAPI_TOKEN || '');
|
|
49
|
+
|
|
50
|
+
const articles = api.articles({
|
|
51
|
+
fields: ["documentId", "title", "text"],
|
|
52
|
+
populate: {
|
|
53
|
+
seo: {
|
|
54
|
+
fields: ["slug", "metaTitle", "metaDescription"],
|
|
55
|
+
populate: {
|
|
56
|
+
openGraph: {
|
|
57
|
+
fields: ["title", "description", "url", "type"],
|
|
58
|
+
populate: {
|
|
59
|
+
image: {
|
|
60
|
+
fields: ["url", "width", "height"]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Using in Next.js with Caching
|
|
71
|
+
|
|
72
|
+
If using Next.js, you can integrate caching for better performance:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import Strapi from "@/strapi"; // strapi.ts file
|
|
76
|
+
|
|
77
|
+
const api = new Strapi(process.env.STRAPI_URL || '', process.env.STRAPI_TOKEN || '');
|
|
78
|
+
|
|
79
|
+
const articles = api.articles(
|
|
80
|
+
{
|
|
81
|
+
fields: ["documentId", "title", "text"],
|
|
82
|
+
populate: {
|
|
83
|
+
seo: {
|
|
84
|
+
fields: ["slug", "metaTitle", "metaDescription"],
|
|
85
|
+
populate: {
|
|
86
|
+
openGraph: {
|
|
87
|
+
fields: ["title", "description", "url", "type"],
|
|
88
|
+
populate: {
|
|
89
|
+
image: {
|
|
90
|
+
fields: ["url", "width", "height"]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
// Cache Options
|
|
99
|
+
{
|
|
100
|
+
cache: "force-cache",
|
|
101
|
+
next: {
|
|
102
|
+
revalidate: 24 * 3600, // Revalidate every 24 hours
|
|
103
|
+
tags: ["contact", "regions"]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## 📌 TODO List
|
|
110
|
+
|
|
111
|
+
- [ ] Add authentication features:
|
|
112
|
+
- [ ] Log In functionality
|
|
113
|
+
- [ ] User Registration
|
|
114
|
+
- [ ] User privileges check
|
|
115
|
+
- [ ] Refactor `src/generator/index.ts` for better maintainability
|
|
116
|
+
- [ ] Enable passing Strapi credentials via CLI parameters
|
|
117
|
+
- [ ] Allow customization of API class path
|
|
118
|
+
- [ ] Resolve naming conflicts between Components and Content Types
|
|
119
|
+
- [ ] Support custom attributes in `src/generator/attributes/index.ts:15`:
|
|
120
|
+
- [ ] Define attributes by project code
|
|
121
|
+
- [ ] Auto-load attributes from other npm packages by scanning `node_modules`
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
📌 **Contributions are welcome!** If you encounter issues or have feature requests, feel free to open a pull request or an issue. 🚀
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malevich-studio/strapi-sdk-typescript",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"bin": {
|
|
6
6
|
"generate-strapi-types": "./dist/cli.mjs"
|
|
@@ -31,7 +31,21 @@
|
|
|
31
31
|
"mime": "^4.0.6"
|
|
32
32
|
},
|
|
33
33
|
"type": "module",
|
|
34
|
-
"author":
|
|
34
|
+
"author": {
|
|
35
|
+
"name": "Malevich Studio",
|
|
36
|
+
"email": "info@malevichstudio.com",
|
|
37
|
+
"url": "https://malevichstudio.com/"
|
|
38
|
+
},
|
|
39
|
+
"contributors": [
|
|
40
|
+
{
|
|
41
|
+
"name": "Gregory Peretyaka",
|
|
42
|
+
"email": "peretyaka@gmail.com"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/malevich-studio/strapi-sdk-typescript"
|
|
48
|
+
},
|
|
35
49
|
"license": "ISC",
|
|
36
50
|
"description": "",
|
|
37
51
|
"devDependencies": {
|