Skip to content

Commit 0a7a652

Browse files
authored
doc: debug
2 parents 3151d0d + f1cd792 commit 0a7a652

File tree

2 files changed

+53
-33
lines changed

2 files changed

+53
-33
lines changed

README.md

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p style="text-align: center">
1+
<p align="center">
22
<a href="https://strapi.io/#gh-light-mode-only">
33
<img src="https://strapi.io/assets/strapi-logo-dark.svg" width="318px" alt="Strapi logo" />
44
</a>
@@ -7,12 +7,12 @@
77
</a>
88
</p>
99

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>
1313
<br />
1414

15-
<p style="text-align: center">
15+
<p align="center">
1616
<a href="https://www.npmjs.org/package/@strapi/sdk-js">
1717
<img src="https://img.shields.io/npm/v/@strapi/sdk-js/latest.svg" alt="NPM Version" />
1818
</a>
@@ -42,7 +42,7 @@
4242
4. [Resource Managers](#-resource-managers)
4343
- [`.collection()`](#collectionresource)
4444
- [`.single()`](#singleresource)
45-
5. [Examples](#-examples)
45+
5. [Debug](#-debug)
4646

4747
## 🛠 Getting started
4848

@@ -94,7 +94,7 @@ Alternatively, use a `<script>` tag in a browser environment:
9494
<script src="https://cdn.jsdelivr.net/npm/@strapi/sdk-js"></script>
9595

9696
<script>
97-
const sdk = strapiSDK({ baseURL: 'http://localhost:1337/api' });
97+
const sdk = strapi.strapiSDK({ baseURL: 'http://localhost:1337/api' });
9898
</script>
9999
```
100100

@@ -199,36 +199,56 @@ const updatedHomepage = await homepage.update(
199199
await homepage.delete();
200200
```
201201

202-
## 💡 Examples
202+
## 🐛 Debug
203203

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/).
205206

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
214208

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.
220210

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:
223212

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=*
228216

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
232219

233-
main();
220+
# Turn off logs
221+
unset DEBUG
234222
```
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). |

rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const node_build = {
7171
/**
7272
* This configuration is designed to bundle the Strapi SDK for browser environments.
7373
*
74-
* It an output using the IIFE format, which is suitable for use in web browsers.
74+
* It outputs using the IIFE format, which is suitable for use in web browsers.
7575
*
7676
* The bundle provides a globally available `strapi` variable and includes source maps for debugging.
7777
*

0 commit comments

Comments
 (0)