|
1 | | -<p style="text-align: center"> |
| 1 | +<p align="center"> |
2 | 2 | <a href="https://strapi.io/#gh-light-mode-only"> |
3 | 3 | <img src="https://strapi.io/assets/strapi-logo-dark.svg" width="318px" alt="Strapi logo" /> |
4 | 4 | </a> |
|
7 | 7 | </a> |
8 | 8 | </p> |
9 | 9 |
|
10 | | -<h2 style="text-align: center">Manage Your Strapi Content From Anywhere 🚀</h2> |
11 | | -<p style="text-align: center">Connect your JavaScript/TypeScript apps to a flexible and fully customizable Strapi backend with ease.</p> |
12 | | -<p style="text-align: center"><a href="https://github.com/strapi/strapi">CMS Repository</a> - <a href="https://strapi.io">Website</a></p> |
| 10 | +<h2 align="center">Manage Your Strapi Content From Anywhere 🚀</h2> |
| 11 | +<p align="center">Connect your JavaScript/TypeScript apps to a flexible and fully customizable Strapi backend with ease.</p> |
| 12 | +<p align="center"><a href="https://github.com/strapi/strapi">CMS Repository</a> - <a href="https://strapi.io">Website</a></p> |
13 | 13 | <br /> |
14 | 14 |
|
15 | | -<p style="text-align: center"> |
| 15 | +<p align="center"> |
16 | 16 | <a href="https://www.npmjs.org/package/@strapi/sdk-js"> |
17 | 17 | <img src="https://img.shields.io/npm/v/@strapi/sdk-js/latest.svg" alt="NPM Version" /> |
18 | 18 | </a> |
|
42 | 42 | 4. [Resource Managers](#-resource-managers) |
43 | 43 | - [`.collection()`](#collectionresource) |
44 | 44 | - [`.single()`](#singleresource) |
45 | | -5. [Examples](#-examples) |
| 45 | +5. [Debug](#-debug) |
46 | 46 |
|
47 | 47 | ## 🛠 Getting started |
48 | 48 |
|
@@ -94,7 +94,7 @@ Alternatively, use a `<script>` tag in a browser environment: |
94 | 94 | <script src="https://cdn.jsdelivr.net/npm/@strapi/sdk-js"></script> |
95 | 95 |
|
96 | 96 | <script> |
97 | | - const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' }); |
| 97 | + const sdk = strapi.strapiSDK({ baseURL: 'http://localhost:1337/api' }); |
98 | 98 | </script> |
99 | 99 | ``` |
100 | 100 |
|
@@ -199,36 +199,56 @@ const updatedHomepage = await homepage.update( |
199 | 199 | await homepage.delete(); |
200 | 200 | ``` |
201 | 201 |
|
202 | | -## 💡 Examples |
| 202 | +## 🐛 Debug |
203 | 203 |
|
204 | | -Here’s how to combine `.collection()` and `.single()` methods in a real-world scenario: |
| 204 | +This section provides guidance on enabling and managing debug logs for the SDK, |
| 205 | +powered by [debug](https://github.com/debug-js/debug/). |
205 | 206 |
|
206 | | -```typescript |
207 | | -const sdk = strapiSDK({ |
208 | | - baseURL: 'http://localhost:1337/api', |
209 | | - auth: { |
210 | | - strategy: 'api-token', |
211 | | - options: { token: 'your-api-token-here' }, |
212 | | - }, |
213 | | -}); |
| 207 | +### Node.js Debugging |
214 | 208 |
|
215 | | -async function main() { |
216 | | - // Work with collections |
217 | | - const articles = sdk.collection('articles'); |
218 | | - const newArticle = await articles.create({ title: 'Hello World', content: '...' }); |
219 | | - console.log('Created Article:', newArticle); |
| 209 | +In **Node.js bundles** (`cjs`, `esm`), debugging capabilities are always available to use. |
220 | 210 |
|
221 | | - const allArticles = await articles.find({ sort: 'createdAt:desc' }); |
222 | | - console.log('All Articles:', allArticles); |
| 211 | +You can turn on or off debug logs using the `DEBUG` environment variable: |
223 | 212 |
|
224 | | - // Work with single types |
225 | | - const homepage = sdk.single('homepage'); |
226 | | - const homepageContent = await homepage.find(); |
227 | | - console.log('Homepage Content:', homepageContent); |
| 213 | +```bash |
| 214 | +# Enable logs for all namespaces |
| 215 | +DEBUG=* |
228 | 216 |
|
229 | | - const updatedHomepage = await homepage.update({ title: 'Welcome to the New Homepage' }); |
230 | | - console.log('Updated Homepage:', updatedHomepage); |
231 | | -} |
| 217 | +# Enable logs for a specific namespace |
| 218 | +DEBUG=sdk:http |
232 | 219 |
|
233 | | -main(); |
| 220 | +# Turn off logs |
| 221 | +unset DEBUG |
234 | 222 | ``` |
| 223 | + |
| 224 | +### Browser Debugging |
| 225 | + |
| 226 | +For **browser environments**, debug capabilities are intentionally turned off to optimize the bundle size. |
| 227 | + |
| 228 | +### Usage Overview |
| 229 | + |
| 230 | +The `debug` tool allows you to control logs using wildcard patterns (`*`): |
| 231 | + |
| 232 | +- `*`: enable all logs. |
| 233 | +- `sdk:module`: enable logs for a specific module. |
| 234 | +- `sdk:module1,sdk:module2`: enable logs for multiple modules. |
| 235 | +- `sdk:*`: match all namespaces under `sdk`. |
| 236 | +- `sdk:*,-sdk:module2`: enable all logs except those from `sdk:module2`. |
| 237 | + |
| 238 | +### Namespaces |
| 239 | + |
| 240 | +Below is a list of available namespaces to use: |
| 241 | + |
| 242 | +| Namespace | Description | |
| 243 | +|---------------------------------------|-------------------------------------------------------------------------------------------| |
| 244 | +| `sdk:core` | Logs SDK initialization, configuration validation, and HTTP client setup. | |
| 245 | +| `sdk:validators:sdk` | Logs details related to SDK configuration validation. | |
| 246 | +| `sdk:validators:url` | Logs URL validation processes. | |
| 247 | +| `sdk:http` | Logs HTTP client setup, request processing, and response/error handling. | |
| 248 | +| `sdk:auth:factory` | Logs the registration and creation of authentication providers. | |
| 249 | +| `sdk:auth:manager` | Logs authentication lifecycle management. | |
| 250 | +| `sdk:auth:provider:api-token` | Logs operations related to API token authentication. | |
| 251 | +| `sdk:auth:provider:users-permissions` | Logs operations related to user and permissions-based authentication. | |
| 252 | +| `sdk:ct:collection` | Logs interactions with collection-type content managers. | |
| 253 | +| `sdk:ct:single` | Logs interactions with single-type content managers. | |
| 254 | +| `sdk:utils:url-helper` | Logs URL helper utility operations (e.g., appending query parameters or formatting URLs). | |
0 commit comments