@malevich-studio/strapi-sdk-typescript 1.0.8 → 1.0.10

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