Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
130 changes: 130 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Auth0 Node.js SDK - GitHub Copilot Instructions

## Architecture Overview

This is the **Auth0 Node.js SDK v5** - a TypeScript SDK providing Auth0 Authentication and Management API clients. The codebase uses **Fern-generated code** for the Management API with custom wrappers.

### Key Components

- **`src/management/`** - Fern-generated Management API client (auto-generated, don't edit directly)
- **`src/management/wrapper/`** - Custom wrappers around Fern client for enhanced DX
- **`src/auth/`** - Hand-written Authentication API client
- **`src/userinfo/`** - UserInfo API client
- **`legacy/`** - v4 compatibility layer for migration

### Dual Module System

- **CJS build**: `dist/cjs/` (main entry)
- **ESM build**: `dist/esm/` (with `.mjs` extensions via `scripts/rename-to-esm-files.js`)
- **Legacy exports**: `auth0/legacy` path for v4 compatibility

## Development Patterns

### Code Generation Awareness

- Files with `* This file was auto-generated by Fern from our API Definition.` are **READ-ONLY**
- Use wrapper classes in `src/management/wrapper/` for customizations
- Authentication API (`src/auth/`) is hand-written - safe to edit

### Testing Strategy

Jest config has **4 separate projects**:

```bash
yarn test:unit # Unit tests (src/management/tests)
yarn test:browser # Browser environment tests
yarn test:wire # Integration tests with mock server
yarn test # Root-level tests (tests/ directory)
```

### Build System

```bash
yarn build # Both CJS and ESM builds
yarn build:cjs # CommonJS build
yarn build:esm # ESM build + rename to .mjs files
```

### TypeScript Configuration

- **`tsconfig.base.json`** - Base config targeting Management API
- **`tsconfig.cjs.json`** - CommonJS build
- **`tsconfig.esm.json`** - ESM build
- Uses `baseUrl: "src/management"` for Management API focus

## API Client Patterns

### Management Client Wrapper Pattern

```typescript
// Don't edit src/management/Client.ts (Fern-generated)
// Use src/management/wrapper/ManagementClient.ts instead
export class ManagementClient {
private _client: FernClient;
// Custom logic, token handling, telemetry
}
```

### Request Options Pattern

Use helper functions from `src/management/request-options.js`:

```typescript
import { withTimeout, withRetries, withHeaders, CustomDomainHeader } from "auth0";

const options = {
...withTimeout(30),
...withRetries(3),
...CustomDomainHeader("auth.example.com"),
};
```

### Error Handling

- **ManagementError** - For Management API errors
- **AuthApiError** - For Authentication API errors
- Use `.withRawResponse()` for accessing raw HTTP response data

## File Organization Rules

### DO NOT EDIT

- `src/management/Client.ts` and `src/management/api/` (Fern-generated)
- Anything with "auto-generated by Fern" comment

### SAFE TO EDIT

- `src/management/wrapper/` - Custom wrapper logic
- `src/auth/` - Authentication API implementation
- `src/userinfo/` - UserInfo API implementation
- `tests/` and `src/management/tests/` - Test files

### Legacy Support

- `legacy/exports/` contains v4 API compatibility
- Use `import { ... } from 'auth0/legacy'` for v4 migration
- See `v5_MIGRATION_GUIDE.md` for breaking changes

## Common Tasks

### Adding Management API Features

1. Extend `src/management/wrapper/ManagementClient.ts`
2. Add types to `src/management/wrapper/` if needed
3. Add tests to `src/management/tests/`

### Testing Integration Points

```bash
yarn test:wire # Tests with mock server setup
```

Mock server setup in `src/management/tests/mock-server/setup.ts`

### Module Resolution

- Uses `.js` extensions in imports (TS will resolve to `.ts`)
- ESM build renames `.js` → `.mjs` and `.d.ts` → `.d.mts`
- Browser field in `package.json` excludes Node.js modules

Remember: This SDK prioritizes backward compatibility through the legacy export while modernizing the core API with Fern generation.
16 changes: 16 additions & 0 deletions .github/workflows/claude-code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Claude Code PR Review

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]

jobs:
claude-review:
permissions:
contents: write
issues: write
pull-requests: write
id-token: write
uses: auth0/auth0-ai-pr-analyzer-gh-action/.github/workflows/claude-code-review.yml@main
Loading
Loading