CLAUDE.md
core-web/libs/sdk/client/CLAUDE.mdCLAUDE.md
Quality
97/100
Scores the file, not the repository.Length
1,090 words
41 headings · 8 code blocksRepository
950
— · pushed 1 days agoLast changed
3 days ago
First indexed 3 days ago.1# CLAUDE.md23This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.45## Project Overview67This is the **DotCMS Client SDK** (`@dotcms/client`) - a JavaScript/TypeScript library for interacting with DotCMS REST APIs. The SDK is part of a larger DotCMS monorepo and serves as the foundation for framework-specific integrations (React, Angular, etc.).89## Essential Commands1011### Development Commands12```bash13# Install dependencies (from monorepo root)14yarn install1516# Build library for distribution17nx run sdk-client:build # ESM/CJS dual package build18nx run sdk-client:build:js # Specialized esbuild for editor integration1920# Run tests21nx run sdk-client:test # Run Jest tests22nx run sdk-client:test:ci # Run tests with CI configuration and coverage2324# Code quality25nx run sdk-client:lint # ESLint code linting2627# Publishing28nx run sdk-client:publish --args.ver=1.0.0 --args.tag=latest29```3031### Testing Commands32```bash33# Run specific test file34nx test sdk-client --testNamePattern="specific test name"3536# Run tests in watch mode37nx test sdk-client --watch3839# Run tests with coverage40nx test sdk-client --coverage41```4243## Architecture Overview4445### Project Structure46```47libs/sdk/client/48├── src/49│ ├── index.ts # Main export (createDotCMSClient)50│ ├── internal.ts # Internal utilities for other SDKs51│ └── lib/52│ ├── client/53│ │ ├── client.ts # Main DotCMSClient class54│ │ ├── content/ # Content API with query builders55│ │ ├── navigation/ # Navigation API56│ │ ├── page/ # Page API with GraphQL support57│ │ └── models/ # TypeScript interfaces and types58│ └── utils/59│ └── graphql/ # GraphQL utilities60├── project.json # Nx project configuration61├── package.json # NPM package configuration62├── tsconfig.json # TypeScript configuration63└── jest.config.ts # Jest testing configuration64```6566### Key Components6768**Core API Pattern**: The SDK follows a client-builder pattern with three main APIs:69- `client.page.get()` - Fetches complete page content with layout and containers70- `client.content.getCollection()` - Builder pattern for querying content collections71- `client.navigation.get()` - Fetches site navigation structure7273**Build Targets**:74- `build` - Standard library build producing ESM/CJS dual packages75- `build:js` - Specialized esbuild for editor integration (outputs to `dotCMS/src/main/webapp/html/js/editor-js`)7677## Development Standards7879### TypeScript Configuration80- **Strict mode enabled**: Full TypeScript strict checking81- **Target**: ES2020 with lib support for ES2020, DOM, DOM.Iterable82- **Dual package support**: ESM and CJS through Rollup build83- **Type definitions**: `@dotcms/types` for comprehensive type safety8485### Code Patterns8687#### Client Builder Pattern88```typescript89// Main client initialization90const client = createDotCMSClient({91 dotcmsUrl: 'https://instance.com',92 authToken: 'token',93 siteId: 'site-id'94});9596// Page API - single request for complete page97const { pageAsset } = await client.page.get('/about-us');9899// Content API - fluent builder pattern100const blogs = await client.content101 .getCollection('Blog')102 .query((qb) => qb.field('title').equals('dotCMS*'))103 .limit(10)104 .sortBy([{ field: 'publishDate', direction: 'desc' }]);105```106107#### GraphQL Integration108```typescript109// Extend page requests with GraphQL for additional content110const { pageAsset, content } = await client.page.get('/about-us', {111 graphql: {112 page: `title vanityUrl { url }`,113 content: {114 blogs: `BlogCollection(limit: 3) { title urlTitle }`,115 navigation: `DotNavigation(uri: "/", depth: 2) { href title }`116 }117 }118});119```120121#### Query Builder Pattern122```typescript123// Fluent query building for content collections124const query = await client.content125 .getCollection('Product')126 .query((qb) => qb127 .field('category').equals('electronics')128 .and()129 .field('price').raw(':[100 TO 500]')130 .not()131 .field('discontinued').equals('true')132 )133 .limit(10)134 .page(1);135```136137### Testing Standards138139#### Jest Configuration140- **Framework**: Jest with TypeScript support141- **Coverage**: Outputs to `../../../coverage/libs/sdk/client`142- **File patterns**: `**/*.spec.ts` and `**/*.test.ts`143- **CI mode**: Supports CI configuration with coverage reporting144145#### Test Patterns146```typescript147// Use descriptive test names and group related tests148describe('DotCMSClient', () => {149 describe('page.get()', () => {150 it('should fetch page content with default options', async () => {151 // Test implementation152 });153154 it('should apply GraphQL extensions correctly', async () => {155 // Test implementation156 });157 });158});159160// Mock external dependencies161jest.mock('../utils/fetch', () => ({162 dotFetch: jest.fn()163}));164```165166### Build System Integration167168#### Nx Monorepo Integration169- **Executor**: `@nx/rollup:rollup` for main build, `@nx/esbuild:esbuild` for editor build170- **Outputs**: Dual package (ESM/CJS) with proper export maps171- **Dependencies**: Automatically managed through Nx dependency graph172173#### Export Configuration174```typescript175// Package exports support both named and default imports176export { createDotCMSClient } from './lib/client/client';177export type { DotCMSClient } from './lib/client/client';178179// Internal exports for framework SDKs180export { DotCMSClientImpl } from './lib/client/client-impl';181```182183## Key Configuration Files184185- **project.json**: Nx project configuration with build targets186- **package.json**: NPM package metadata with proper exports field187- **tsconfig.json**: TypeScript configuration with strict mode188- **tsconfig.lib.json**: Library-specific TypeScript settings189- **jest.config.ts**: Jest testing configuration190191## Development Workflow192193### Standard Development Flow1941. **Make changes** → Test locally with `nx test sdk-client`1952. **Lint code** → `nx lint sdk-client`1963. **Build library** → `nx build sdk-client`1974. **Integration testing** → Test with dependent SDKs or examples198199### Editor Integration Build200For changes affecting the editor integration:2011. **Build editor version** → `nx run sdk-client:build:js`2022. **Test in dotCMS editor** → Verify functionality in dotCMS admin2033. **Clean build artifacts** → Script automatically removes temporary files204205### Release Process2061. **Version bump** → Update version in `package.json`2072. **Build all targets** → `nx build sdk-client`2083. **Publish** → `nx run sdk-client:publish --args.ver=X.X.X --args.tag=latest`209210## Integration Context211212### Framework SDKs213This client SDK serves as the foundation for:214- `@dotcms/react` - React integration with UVE support215- `@dotcms/angular` - Angular integration with UVE support216- `@dotcms/uve` - Universal Visual Editor low-level integration217218### Dependencies219- **Runtime**: `consola` for logging220- **Development**: `@dotcms/types` for TypeScript definitions221- **Peer Dependencies**: Framework-specific SDKs extend this client222223## Common Development Tasks224225### Adding New API Methods2261. **Define interfaces** in `lib/client/models/`2272. **Implement method** in appropriate API class (`page/`, `content/`, `navigation/`)2283. **Export** from main `index.ts`2294. **Add tests** following existing patterns2305. **Update TypeScript types** if needed231232### Extending Query Builders2331. **Add method** to appropriate builder class2342. **Update builder interface** with new method signature2353. **Add tests** for new query capabilities2364. **Document** in README with examples237238### GraphQL Integration2391. **Define GraphQL fragments** in `utils/graphql/`2402. **Add to page API** GraphQL parameter types2413. **Test** with various GraphQL queries2424. **Update documentation** with new capabilities243244## Summary Checklist245- ✅ Use Nx commands for all build/test operations246- ✅ Follow client-builder pattern for new APIs247- ✅ Maintain TypeScript strict mode compliance248- ✅ Write comprehensive Jest tests for new features249- ✅ Use proper export patterns for dual package support250- ✅ Test both ESM and CJS builds251- ✅ Verify editor integration when making core changes252- ❌ Avoid breaking changes to public API without migration plan253- ❌ Don't add runtime dependencies without careful consideration
Also in dotCMS/core
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotCMS/core.cursor/rules/doc-updates.mdc · 950 | Cursor rules | docs | 30/100 | 3 days ago | |
| dotCMS/core.cursor/rules/dotcms-guide.mdc · 950 | Cursor rules | archdo-notdocs | 69/100 | 3 days ago | |
| dotCMS/core.cursor/rules/e2e-rules.mdc · 950 | Cursor rules | setupteststylearch+5 | 89/100 | 3 days ago | |
| dotCMS/core.cursor/rules/frontend-context.mdc · 950 | Cursor rules | teststyledocs | 78/100 | 3 days ago | |
| dotCMS/core.cursor/rules/java-context.mdc · 950 | Cursor rules | buildstyle | 44/100 | 3 days ago | |
| dotCMS/core.cursor/rules/test-context.mdc · 950 | Cursor rules | testtesting-strategy | 54/100 | 3 days ago | |
| dotCMS/core.github/copilot-instructions.md · 950 | Copilot instructions | setupbuildtestlint-format+11 | 84/100 | 3 days ago | |
| dotCMS/core.github/instructions/frontend.instructions.md · 950 | Copilot instructions | testlint-formatstylearch+3 | 69/100 | 3 days ago | |
| dotCMS/coreCLAUDE.md · 950 | CLAUDE.md | setupbuildteststyle+7 | 99/100 | 3 days ago | |
| dotCMS/corecore-web/AGENTS.md · 950 | AGENTS.md | style | 63/100 | 3 days ago | |
| dotCMS/corecore-web/CLAUDE.md · 950 | CLAUDE.md | teststylearchtesting-strategy+3 | 100/100 | 3 days ago | |
| dotCMS/corecore-web/apps/dotcms-ui-e2e/AGENTS.md · 950 | AGENTS.md | setupstylearchtesting-strategy+2 | 78/100 | 3 days ago | |
| dotCMS/corecore-web/apps/dotcms-ui/AGENTS.md · 950 | AGENTS.md | buildteststyledependencies+3 | 94/100 | 3 days ago | |
| dotCMS/corecore-web/apps/mcp-server/CLAUDE.md · 950 | CLAUDE.md | setupbuildtestlint-format+5 | 89/100 | 3 days ago | |
| dotCMS/corecore-web/libs/block-editor/CLAUDE.md · 950 | CLAUDE.md | archdo-not | 69/100 | 3 days ago | |
| dotCMS/corecore-web/libs/new-block-editor/CLAUDE.md · 950 | CLAUDE.md | lint-formatstyledo-notagent-behaviour | 61/100 | 3 days ago | |
| dotCMS/corecore-web/libs/portlets/CLAUDE.md · 950 | CLAUDE.md | setupteststyleui+1 | 77/100 | 3 days ago | |
| dotCMS/corecore-web/libs/portlets/edit-ema/portlet/src/lib/store/CLAUDE.md · 950 | CLAUDE.md | teststylearchtypes+2 | 65/100 | 3 days ago | |
| dotCMS/corecore-web/libs/sdk/react/CLAUDE.md · 950 | CLAUDE.md | setupbuildtestlint-format+9 | 97/100 | 3 days ago | |
| dotCMS/coredotCMS/src/main/java/com/dotcms/rest/CLAUDE.md · 950 | CLAUDE.md | typesdatabaseapido-not+1 | 57/100 | 3 days ago |
Diff against .cursor/rules/doc-updates.mdc Diff against .cursor/rules/dotcms-guide.mdc Diff against .cursor/rules/e2e-rules.mdc Diff against .cursor/rules/frontend-context.mdc Diff against .cursor/rules/java-context.mdc Diff against .cursor/rules/test-context.mdc Diff against .github/copilot-instructions.md Diff against .github/instructions/frontend.instructions.md Diff against CLAUDE.md Diff against core-web/AGENTS.md Diff against core-web/CLAUDE.md Diff against core-web/apps/dotcms-ui-e2e/AGENTS.md Diff against core-web/apps/dotcms-ui/AGENTS.md Diff against core-web/apps/mcp-server/CLAUDE.md Diff against core-web/libs/block-editor/CLAUDE.md Diff against core-web/libs/new-block-editor/CLAUDE.md Diff against core-web/libs/portlets/CLAUDE.md Diff against core-web/libs/portlets/edit-ema/portlet/src/lib/store/CLAUDE.md Diff against core-web/libs/sdk/react/CLAUDE.md Diff against dotCMS/src/main/java/com/dotcms/rest/CLAUDE.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotCMS/corecore-web/CLAUDE.md · 950 | CLAUDE.md | teststylearchtesting-strategy+3 | 100/100 | 3 days ago | |
| bagisto/bagistoCLAUDE.md · 28k | CLAUDE.md | setupbuildteststyle+5 | 100/100 | 3 days ago | |
| nimbalyst/nimbalystpackages/android/CLAUDE.md · 1.4k | CLAUDE.md | setupbuildstylearch+2 | 100/100 | 3 days ago | |
| microsoft/playwrightCLAUDE.md · 94k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| Adit-Jain-srm/NightmareNetCLAUDE.md · 45 | CLAUDE.md | buildtestlint-formatstyle+6 | 100/100 | 3 days ago | |
| filamentphp/filamentCLAUDE.md · 32k | CLAUDE.md | buildtestlint-formatstyle+7 | 100/100 | 3 days ago | |
| dotCMS/coreCLAUDE.md · 950 | CLAUDE.md | setupbuildteststyle+7 | 99/100 | 3 days ago | |
| lollipopkit/flutter_server_boxCLAUDE.md · 8.3k | CLAUDE.md | buildteststylearch+2 | 98/100 | 3 days ago |
