Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ eslint.config.mjs
.husky/

.prettierignore
CONTRIBUTING.md
CONTRIBUTING.md
.fern/
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,100 @@ const response = await client.actions.create(
controller.abort(); // aborts the request
```

### Logging

The SDK provides built-in logging support to help with debugging and monitoring API requests. Logging is disabled by default to avoid noise in production environments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states logging is "disabled by default" but technically it's "silent by default" (silent: true). The logging infrastructure is always instantiated, it just doesn't output anything. Consider clarifying this distinction in the docs, as users might think there's zero performance overhead when disabled.

#### Enable Debug Logging

```typescript
import { ManagementClient, logging } from "auth0";

const management = new ManagementClient({
domain: "{YOUR_TENANT_AND REGION}.auth0.com",
clientId: "{YOUR_CLIENT_ID}",
clientSecret: "{YOUR_CLIENT_SECRET}",
logging: {
level: logging.LogLevel.Debug,
silent: false, // Enable logging output
},
});

// All API calls will now log request/response details
const users = await management.users.list();
```

#### Log Levels

The SDK supports four log levels:

- `logging.LogLevel.Debug` - Detailed debugging information
- `logging.LogLevel.Info` - General informational messages
- `logging.LogLevel.Warn` - Warning messages
- `logging.LogLevel.Error` - Error messages only

#### Custom Logger

You can provide your own logger implementation to integrate with your existing logging infrastructure:

```typescript
import { ManagementClient, logging } from "auth0";

class CustomLogger implements logging.ILogger {
debug(message: string, ...args: unknown[]) {
// Send to your logging service
console.debug(`[AUTH0]`, message, ...args);
}
info(message: string, ...args: unknown[]) {
console.info(`[AUTH0]`, message, ...args);
}
warn(message: string, ...args: unknown[]) {
console.warn(`[AUTH0]`, message, ...args);
}
error(message: string, ...args: unknown[]) {
console.error(`[AUTH0]`, message, ...args);
}
}

const management = new ManagementClient({
domain: "{YOUR_TENANT_AND REGION}.auth0.com",
clientId: "{YOUR_CLIENT_ID}",
clientSecret: "{YOUR_CLIENT_SECRET}",
logging: {
level: logging.LogLevel.Info,
logger: new CustomLogger(),
silent: false,
},
});
```

#### Using the Built-in ConsoleLogger

```typescript
import { ManagementClient, logging } from "auth0";

const management = new ManagementClient({
domain: "{YOUR_TENANT_AND REGION}.auth0.com",
clientId: "{YOUR_CLIENT_ID}",
clientSecret: "{YOUR_CLIENT_SECRET}",
logging: {
level: logging.LogLevel.Warn,
logger: new logging.ConsoleLogger(),
silent: false,
},
});
```

#### Security Note

The SDK automatically redacts sensitive information from logs, including:

- Authorization headers and tokens
- API keys and secrets
- Passwords and credentials in URLs
- Session identifiers
- Authentication tokens in query parameters

### Access Raw Response Data

The SDK provides access to raw response data, including headers, through the `.withRawResponse()` method.
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"precommit": "lint-staged",
"validate": "yarn lint:check && yarn format --check && yarn build && yarn test && yarn lint:package"
},
"dependencies": {
"uuid": "^11.1.0",
"jose": "^4.13.2",
"auth0-legacy": "npm:auth0@^4.27.0"
},
"devDependencies": {
"webpack": "^5.97.1",
"ts-loader": "^9.5.1",
Expand Down Expand Up @@ -130,10 +135,5 @@
"*.{json,md,yml,yaml}": [
"prettier --write"
]
},
"dependencies": {
"uuid": "^11.1.0",
"jose": "^4.13.2",
"auth0-legacy": "npm:auth0@^4.27.0"
}
}
2 changes: 2 additions & 0 deletions src/management/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export interface BaseClientOptions {
/** Provide a custom fetch implementation. Useful for platforms that don't have a built-in fetch or need a custom implementation. */
fetch?: typeof fetch;
fetcher?: core.FetchFunction;
/** Configure logging for the client. */
logging?: core.logging.LogConfig | core.logging.Logger;
}

export interface BaseRequestOptions {
Expand Down
7 changes: 7 additions & 0 deletions src/management/api/resources/actions/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class Actions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -223,6 +224,7 @@ export class Actions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -312,6 +314,7 @@ export class Actions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body as Management.GetActionResponseContent, rawResponse: _response.rawResponse };
Expand Down Expand Up @@ -411,6 +414,7 @@ export class Actions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: undefined, rawResponse: _response.rawResponse };
Expand Down Expand Up @@ -505,6 +509,7 @@ export class Actions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -595,6 +600,7 @@ export class Actions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -695,6 +701,7 @@ export class Actions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: _response.body as Management.TestActionResponseContent, rawResponse: _response.rawResponse };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class Executions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class Triggers {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class Bindings {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -191,6 +192,7 @@ export class Bindings {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class Versions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -189,6 +190,7 @@ export class Versions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -290,6 +292,7 @@ export class Versions {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class Blocks {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: undefined, rawResponse: _response.rawResponse };
Expand Down Expand Up @@ -152,6 +153,7 @@ export class Blocks {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return { data: undefined, rawResponse: _response.rawResponse };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class BotDetection {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -155,6 +156,7 @@ export class BotDetection {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class BreachedPasswordDetection {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -151,6 +152,7 @@ export class BreachedPasswordDetection {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class BruteForceProtection {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -151,6 +152,7 @@ export class BruteForceProtection {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class Captcha {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -154,6 +155,7 @@ export class Captcha {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class SuspiciousIpThrottling {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -151,6 +152,7 @@ export class SuspiciousIpThrottling {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
2 changes: 2 additions & 0 deletions src/management/api/resources/branding/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class Branding {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down Expand Up @@ -167,6 +168,7 @@ export class Branding {
maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
abortSignal: requestOptions?.abortSignal,
fetchFn: this._options?.fetch,
logging: this._options.logging,
});
if (_response.ok) {
return {
Expand Down
Loading
Loading