diff --git a/README.md b/README.md index 6264a7f..9cdf1b4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+

Strapi logo @@ -7,12 +7,12 @@

-

Manage Your Strapi Content From Anywhere πŸš€

-

Connect your JavaScript/TypeScript apps to a flexible and fully customizable Strapi backend with ease.

-

CMS Repository - Website

+

Manage Your Strapi Content From Anywhere πŸš€

+

Connect your JavaScript/TypeScript apps to a flexible and fully customizable Strapi backend with ease.

+

CMS Repository - Website


-

+

NPM Version @@ -42,7 +42,7 @@ 4. [Resource Managers](#-resource-managers) - [`.collection()`](#collectionresource) - [`.single()`](#singleresource) -5. [Examples](#-examples) +5. [Debug](#-debug) ## πŸ›  Getting started @@ -94,7 +94,7 @@ Alternatively, use a ` ``` @@ -199,36 +199,56 @@ const updatedHomepage = await homepage.update( await homepage.delete(); ``` -## πŸ’‘ Examples +## πŸ› Debug -Here’s how to combine `.collection()` and `.single()` methods in a real-world scenario: +This section provides guidance on enabling and managing debug logs for the SDK, +powered by [debug](https://github.com/debug-js/debug/). -```typescript -const sdk = strapiSDK({ - baseURL: 'http://localhost:1337/api', - auth: { - strategy: 'api-token', - options: { token: 'your-api-token-here' }, - }, -}); +### Node.js Debugging -async function main() { - // Work with collections - const articles = sdk.collection('articles'); - const newArticle = await articles.create({ title: 'Hello World', content: '...' }); - console.log('Created Article:', newArticle); +In **Node.js bundles** (`cjs`, `esm`), debugging capabilities are always available to use. - const allArticles = await articles.find({ sort: 'createdAt:desc' }); - console.log('All Articles:', allArticles); +You can turn on or off debug logs using the `DEBUG` environment variable: - // Work with single types - const homepage = sdk.single('homepage'); - const homepageContent = await homepage.find(); - console.log('Homepage Content:', homepageContent); +```bash +# Enable logs for all namespaces +DEBUG=* - const updatedHomepage = await homepage.update({ title: 'Welcome to the New Homepage' }); - console.log('Updated Homepage:', updatedHomepage); -} +# Enable logs for a specific namespace +DEBUG=sdk:http -main(); +# Turn off logs +unset DEBUG ``` + +### Browser Debugging + +For **browser environments**, debug capabilities are intentionally turned off to optimize the bundle size. + +### Usage Overview + +The `debug` tool allows you to control logs using wildcard patterns (`*`): + +- `*`: enable all logs. +- `sdk:module`: enable logs for a specific module. +- `sdk:module1,sdk:module2`: enable logs for multiple modules. +- `sdk:*`: match all namespaces under `sdk`. +- `sdk:*,-sdk:module2`: enable all logs except those from `sdk:module2`. + +### Namespaces + +Below is a list of available namespaces to use: + +| Namespace | Description | +|---------------------------------------|-------------------------------------------------------------------------------------------| +| `sdk:core` | Logs SDK initialization, configuration validation, and HTTP client setup. | +| `sdk:validators:sdk` | Logs details related to SDK configuration validation. | +| `sdk:validators:url` | Logs URL validation processes. | +| `sdk:http` | Logs HTTP client setup, request processing, and response/error handling. | +| `sdk:auth:factory` | Logs the registration and creation of authentication providers. | +| `sdk:auth:manager` | Logs authentication lifecycle management. | +| `sdk:auth:provider:api-token` | Logs operations related to API token authentication. | +| `sdk:auth:provider:users-permissions` | Logs operations related to user and permissions-based authentication. | +| `sdk:ct:collection` | Logs interactions with collection-type content managers. | +| `sdk:ct:single` | Logs interactions with single-type content managers. | +| `sdk:utils:url-helper` | Logs URL helper utility operations (e.g., appending query parameters or formatting URLs). | diff --git a/rollup.config.mjs b/rollup.config.mjs index fd755f1..a058b89 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -71,7 +71,7 @@ const node_build = { /** * This configuration is designed to bundle the Strapi SDK for browser environments. * - * It an output using the IIFE format, which is suitable for use in web browsers. + * It outputs using the IIFE format, which is suitable for use in web browsers. * * The bundle provides a globally available `strapi` variable and includes source maps for debugging. *