@dotcms/client 0.0.1-beta.4 → 0.0.1-beta.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,258 +1,621 @@
1
- # dotCMS API Client - `@dotcms/client`
1
+ # dotCMS Client SDK
2
2
 
3
- The `@dotcms/client` is a JavaScript/TypeScript library for interacting with a dotCMS instance. It allows you to easily fetch pages, content, and navigation information in JSON format, as well as to make complex queries on content collections.
3
+ The `@dotcms/client` is a powerful JavaScript/TypeScript SDK designed to simplify the integration of dotCMS content into your applications. Whether building dynamic websites or content-driven apps, this SDK offers an intuitive API for seamless and type-safe content retrieval, enabling you to create engaging experiences effortlessly by accessing and displaying content from dotCMS.
4
4
 
5
- This client library provides a streamlined, promise-based interface to fetch pages and navigation API.
5
+ ### When to Use It:
6
6
 
7
- ## Features
7
+ - Building headless frontends that need dotCMS content
8
+ - Building content-driven apps that need to access dotCMS content
9
+ - Developing multi-language or personalized experiences
10
+ - Implementing dynamic navigation and page structures
8
11
 
9
- - Easy-to-use methods to interact with [dotCMS pages](https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas) and the [Navigation API](https://www.dotcms.com/docs/latest/navigation-rest-api).
10
- - Support for custom actions to communicate with the dotCMS page editor.
11
- - Comprehensive TypeScript typings for better development experience.
12
+ ### Key Benefits:
12
13
 
13
- # dotCMS API Client
14
+ - **Simplified Development**: Write less code with intuitive methods and builders
15
+ - **Type Safety**: Built-in TypeScript definitions prevent runtime errors
16
+ - **Universal Compatibility**: Works in both browser and Node.js environments
17
+ - **Security First**: Handles authentication and requests securely
18
+ - **Developer Experience**: Rich autocompletion and documentation
14
19
 
15
- ## Installation
20
+ ## Table of Contents
16
21
 
17
- To get started, install the client via npm or yarn:
22
+ - [Prerequisites & Setup](#prerequisites--setup)
23
+ - [Get a dotCMS Environment](#get-a-dotcms-environment)
24
+ - [Create a dotCMS API Key](#create-a-dotcms-api-key)
25
+ - [Installation](#installation)
26
+ - [Quickstart](#quickstart)
27
+ - [Example Projects](#example-projects)
28
+ - [Key Concepts](#key-concepts)
29
+ - [Choosing the Right Method](#choosing-the-right-method)
30
+ - [Start with `page.get()`: The One-Request Solution](#start-with-pageget-the-one-request-solution)
31
+ - [API Reference](#api-reference)
32
+ - [Client Initialization](#client-initialization)
33
+ - [client.page.get(): Fetching Page Content](#clientpageget-fetching-page-content)
34
+ - [client.navigation.get(): Fetching Navigation Structure](#clientnavigationget-fetching-navigation-structure)
35
+ - [client.content.getCollection(): Fetching Content Collections](#clientcontentgetcollection-fetching-content-collections)
36
+ - [Using the SDK with TypeScript](#using-the-sdk-with-typescript)
37
+ - [Usage Example](#usage-example)
38
+ - [How to Enable Page Editing in dotCMS](#how-to-enable-page-editing-in-dotcms)
39
+ - [Use an Official SDK](#use-an-official-sdk)
40
+ - [⚠️ Advanced Only: Custom UVE Integration](#advanced-only-custom-uve-integration)
41
+ - [dotCMS Support](#dotcms-support)
42
+ - [How To Contribute](#how-to-contribute)
43
+ - [Licensing Information](#licensing-information)
18
44
 
19
- ```bash
20
- npm install @dotcms/client
21
- ```
45
+ ## Prerequisites & Setup
46
+
47
+ ### Get a dotCMS Environment
48
+
49
+ #### Version Compatibility
50
+
51
+ - **Recommended**: dotCMS Evergreen
52
+ - **Minimum**: dotCMS v25.05
53
+ - **Best Experience**: Latest Evergreen release
54
+
55
+ #### Environment Setup
56
+
57
+ **For Production Use:**
58
+
59
+ - ☁️ [Cloud hosting options](https://www.dotcms.com/pricing) - managed solutions with SLA
60
+ - 🛠️ [Self-hosted options](https://dev.dotcms.com/docs/current-releases) - deploy on your infrastructure
61
+
62
+ **For Testing & Development:**
63
+
64
+ - 🧑🏻‍💻 [dotCMS demo site](https://demo.dotcms.com/dotAdmin/#/public/login) - perfect for trying out the SDK
65
+ - 📘 [Learn how to use the demo site](https://dev.dotcms.com/docs/demo-site)
66
+ - 📝 Read-only access, ideal for building proof-of-concepts
67
+
68
+ **For Local Development:**
69
+
70
+ - 🐳 [Docker setup guide](https://github.com/dotCMS/core/tree/main/docker/docker-compose-examples/single-node-demo-site)
71
+ - 💻 [Local installation guide](https://dev.dotcms.com/docs/quick-start-guide)
72
+
73
+ ### Create a dotCMS API Key
74
+
75
+ > [!TIP]
76
+ > Make sure your API Token has read-only permissions for Pages, Folders, Assets, and Content. Using a key with minimal permissions follows security best practices.
77
+
78
+ This integration requires an API Key with read-only permissions for security best practices:
22
79
 
23
- Or using Yarn:
80
+ 1. Go to the **dotCMS admin panel**.
81
+ 2. Click on **System** > **Users**.
82
+ 3. Select the user you want to create the API Key for.
83
+ 4. Go to **API Access Key** and generate a new key.
84
+
85
+ For detailed instructions, please refer to the [dotCMS API Documentation - Read-only token](https://dev.dotcms.com/docs/rest-api-authentication#ReadOnlyToken).
86
+
87
+ ### Installation
88
+
89
+ Install the SDK and required dependencies:
24
90
 
25
91
  ```bash
26
- yarn add @dotcms/client
92
+ npm install @dotcms/client@next @dotcms/types@next
27
93
  ```
28
94
 
29
- ## Usage
95
+ > [!TIP]
96
+ > If you are working with pure JavaScript, you can avoid installing the `@dotcms/types` package.
30
97
 
31
- `@dotcms/client` supports both ES modules and CommonJS. You can import it using either syntax:
98
+ ## Quickstart: Basic Setup Example
32
99
 
33
- ### ES Modules
100
+ Here's a basic setup of the dotCMS Client SDK to help you get started:
34
101
 
35
- ```javascript
36
- import { DotCmsClient } from '@dotcms/client';
37
- ```
102
+ ```typescript
103
+ import { createDotCMSClient } from '@dotcms/client/next';
38
104
 
39
- ### CommonJS
105
+ // Create a client instance
106
+ const client = createDotCMSClient({
107
+ dotcmsUrl: 'https://your-dotcms-instance.com',
108
+ authToken: 'your-auth-token', // Optional for public content
109
+ siteId: 'your-site-id' // Optional site identifier
110
+ });
40
111
 
41
- ```javascript
42
- const { DotCmsClient } = require('@dotcms/client');
112
+ // Start using the client!
113
+ const { pageAsset } = await client.page.get('/about-us');
114
+ console.log(pageAsset.page.title);
43
115
  ```
44
116
 
45
- ### Initialization
117
+ ### Full-Stack Example Projects Using the SDK
118
+
119
+ While there isn't a dedicated example project specifically for the client SDK, you can see it in action within these full-stack examples:
120
+
121
+ - [Next.js Example](https://github.com/dotCMS/core/tree/main/examples/nextjs) - Modern React-based SSR implementation
122
+ - [Angular Example](https://github.com/dotCMS/core/tree/main/examples/angular) - Enterprise Angular implementation
123
+ - [Astro Example](https://github.com/dotCMS/core/tree/main/examples/astro) - Astro implementation
124
+
125
+ These examples demonstrate how to use the client SDK as part of a complete web application.
126
+
127
+ ## Key Concepts
128
+
129
+ | Term | Description | Documentation |
130
+ | ------------ | ----------------------------------------------------- | ------------------------------------------------------------------------------ |
131
+ | `pageAsset` | The page data structure containing layout and content | [Page API](https://dev.dotcms.com/docs/page-rest-api-layout-as-a-service-laas) |
132
+ | `contentlet` | A single piece of content in dotCMS | [Content API](https://dev.dotcms.com/docs/content) |
133
+ | `collection` | A group of contentlets of the same type | [Content API](https://dev.dotcms.com/docs/search) |
134
+ | `graphql` | Query language used to extend API responses | [GraphQL](https://dev.dotcms.com/docs/graphql) |
135
+
136
+ ## Choosing the Right Method
137
+
138
+ The dotCMS Client SDK provides three core methods for fetching data. Use this quick guide to decide which one is best for your use case:
46
139
 
47
- First, initialize the client with your dotCMS instance details.
140
+ | Method | Use When You Need... | Best For |
141
+ | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
142
+ | [`client.page.get()`](#clientpageget-fetching-page-content) | A full page with layout, containers, and related content | **Rendering entire pages** with a single request. Ideal for headless setups, SSR/SSG frameworks, and cases where you want everything—page structure, content, and navigation—tied to a URL path. |
143
+ | [`client.content.getCollection()`](#clientcontentgetcollection-fetching-content-collections) | A filtered list of content items from a specific content type | Populating dynamic blocks, lists, search results, widgets, or reusable components. |
144
+ | [`client.navigation.get()`](#clientnavigationget-fetching-navigation-structure) | Only the site's navigation structure (folders and links) | Standalone menus or use cases where navigation is needed outside of page context. |
48
145
 
49
- ```javascript
50
- const client = DotCmsClient.init({
146
+ ### Start with `page.get()`: The One-Request Solution
147
+
148
+ For most use cases, `client.page.get()` is all you need. It lets you retrieve:
149
+
150
+ - The full page layout
151
+ - Related content
152
+ - Navigation structure
153
+
154
+ All in a single request using GraphQL.
155
+
156
+ Only use `content.getCollection()` or `navigation.get()` if you have advanced needs, like real-time data fetching or building custom dynamic components.
157
+
158
+ > 🔍 **For an example of how to bundle content and navigation in one `page.get()` call,** see the [advanced usage](#fetching-additional-content-with-graphql) section under `client.page.get()`.
159
+
160
+ ## API Reference
161
+
162
+ ### createDotCMSClient: Client Initialization
163
+
164
+ The `createDotCMSClient` function is the first step in using the dotCMS Client SDK. It allows you to create a new client instance with your dotCMS configuration.
165
+
166
+ | Option | Type | Required | Description |
167
+ | ---------------- | -------------- | -------- | ------------------------------------------------------------- |
168
+ | `dotcmsUrl` | string | ✅ | Your dotCMS instance URL |
169
+ | `authToken` | string | ✅ | Authentication token |
170
+ | `siteId` | string | ❌ | Site identifier (falls back to default site if not specified) |
171
+ | `requestOptions` | RequestOptions | ❌ | Additional fetch options |
172
+
173
+ #### Initialization Example
174
+
175
+ ```typescript
176
+ import { createDotCMSClient } from '@dotcms/client/next';
177
+
178
+ const client = createDotCMSClient({
51
179
  dotcmsUrl: 'https://your-dotcms-instance.com',
52
180
  authToken: 'your-auth-token',
53
- siteId: 'your-site-id'
181
+ siteId: 'your-site-id',
182
+ requestOptions: {
183
+ headers: { 'Custom-Header': 'value' },
184
+ cache: 'default'
185
+ }
54
186
  });
55
187
  ```
56
188
 
57
- ### Fetching a Page
189
+ ### client.page.get(): Fetching Page Content
58
190
 
59
- You can retrieve the elements of any page in your dotCMS system in JSON format using the `client.page.get()` method.
191
+ The `client.page.get()` method is your primary way to retrieve page content from dotCMS using the SDK. It abstracts away the complexity of raw REST or GraphQL calls, letting you fetch structured page data with just a single method.
60
192
 
61
- ```javascript
62
- const pageData = await client.page.get({
63
- path: '/your-page-path',
64
- language_id: 1,
65
- personaId: 'optional-persona-id'
66
- });
193
+ #### Why Use `page.get()`?
194
+
195
+ - Fetch everything needed to render a page with one call
196
+ - Avoid building multiple API queries manually
197
+ - Type-safe, customizable, and extensible with GraphQL
198
+ - Works with dotCMS content localization and personalization out of the box
199
+
200
+ #### Basic Usage
201
+
202
+ Here's the simplest way to fetch a page by its URL:
203
+
204
+ ```ts
205
+ const { pageAsset } = await client.page.get('/about-us');
206
+ console.log(pageAsset.page.title);
67
207
  ```
68
208
 
69
- ### Fetching Navigation
209
+ You can now render this content or pass it to your components.
70
210
 
71
- Retrieve the dotCMS file and folder tree to get information about the navigation structure.
211
+ #### Customizing the Request
72
212
 
73
- ```javascript
74
- const navData = await client.nav.get({
75
- path: '/',
76
- depth: 2,
77
- languageId: 1
213
+ You can customize the request to fetch different languages, rendering modes, or user personas:
214
+
215
+ ```ts
216
+ const { pageAsset } = await client.page.get('/about-us', {
217
+ languageId: '2',
218
+ fireRules: true,
219
+ personaId: '1234'
78
220
  });
79
221
  ```
80
222
 
81
- ### Fetching a Collection of Content
223
+ #### Bundling Content and Navigation in One Request
224
+
225
+ You can also pull in related content, like blog posts or navigation menus, using the `graphql` option:
226
+
227
+ ```ts
228
+ const { pageAsset, content } = await client.page.get('/about-us', {
229
+ graphql: {
230
+ page: `
231
+ title
232
+ vanityUrl {
233
+ url
234
+ }
235
+ `,
236
+ content: {
237
+ blogPosts: `
238
+ BlogCollection(limit: 3) {
239
+ title
240
+ urlTitle
241
+ }
242
+ `,
243
+ navigation: `
244
+ DotNavigation(uri: "/", depth: 2) {
245
+ href
246
+ title
247
+ children {
248
+ href
249
+ title
250
+ }
251
+ }
252
+ `
253
+ }
254
+ }
255
+ });
256
+ ```
257
+
258
+ #### Request Options
259
+
260
+ The `page.get()` method accepts an optional second argument of type [`DotCMSPageRequestParams`](https://github.com/dotCMS/core/blob/6e003eb697554ea9636a1fec59bc0fa020b84390/core-web/libs/sdk/types/src/lib/client/public.ts#L5-L54). This lets you customize how the page is fetched. Common options include:
261
+
262
+ | Option | Type | Description |
263
+ | ------------ | ---------------- | ------------------------------------------------ |
264
+ | `languageId` | string \| number | Language version of the page |
265
+ | `mode` | string | Rendering mode: `LIVE`, `PREVIEW_MODE`, etc. |
266
+ | `personaId` | string | Personalize content based on persona ID |
267
+ | `graphql` | object | Extend the response with additional content/data |
268
+ | `fireRules` | boolean | Whether to trigger page rules |
269
+
270
+ > 💡 See [`DotCMSPageRequestParams`](https://github.com/dotCMS/core/blob/6e003eb697554ea9636a1fec59bc0fa020b84390/core-web/libs/sdk/types/src/lib/client/public.ts#L5-L54) for a full list of supported options.
271
+
272
+ #### Method Signature
273
+
274
+ ```ts
275
+ get<T extends DotCMSExtendedPageResponse = DotCMSPageResponse>(
276
+ url: string,
277
+ options?: DotCMSPageRequestParams
278
+ ): Promise<DotCMSComposedPageResponse<T>>;
279
+ ```
280
+
281
+ ### client.navigation.get(): Fetching Navigation Structure
82
282
 
83
- The `getCollection` method allows you to fetch a collection of content items (sometimes called "contentlets") using a builder pattern for complex queries.
283
+ The `client.navigation.get()` method fetches a structured view of a site's file and folder hierarchy from dotCMS. It's useful for building menus and navigation UIs.
84
284
 
85
285
  #### Basic Usage
86
286
 
87
- Heres a simple example to fetch content from a collection:
287
+ Here's the simplest way to fetch the root-level navigation:
88
288
 
89
- ```typescript
90
- import { DotCmsClient } from '@dotcms/client';
289
+ ```ts
290
+ const nav = await client.navigation.get('/');
291
+ console.log(nav);
292
+ ```
91
293
 
92
- const client = DotCmsClient.init({
93
- dotcmsUrl: 'https://your-dotcms-instance.com',
94
- authToken: 'your-auth-token'
95
- });
294
+ #### Customizing the Request
96
295
 
97
- const collectionResponse = await client.content
98
- .getCollection('Blog') // Collection name
99
- .limit(10) // Limit results to 10 items
100
- .page(1) // Fetch the first page
101
- .fetch(); // Execute the query
296
+ You can tailor the navigation structure using optional parameters:
102
297
 
103
- console.log(collectionResponse.contentlets);
298
+ ```ts
299
+ const nav = await client.navigation.get('/', {
300
+ depth: 2,
301
+ languageId: 1
302
+ });
104
303
  ```
105
304
 
106
- #### Sorting Content
305
+ #### Request Options
107
306
 
108
- You can sort the content by any field in ascending or descending order:
307
+ The `navigation.get()` method accepts an optional second argument with the following parameters:
109
308
 
110
- ```typescript
111
- const sortedResponse = await client.content
112
- .getCollection('Blog')
113
- .sortBy([{ field: 'title', order: 'asc' }]) // Sort by title in ascending order
114
- .fetch();
309
+ | Option | Type | Description |
310
+ | ------------ | ------ | ------------------------------------------ |
311
+ | `depth` | number | Number of child levels to include |
312
+ | `languageId` | number | Language ID for localized navigation names |
313
+
314
+ > 💡 For typical use cases, setting `depth: 2` will include top-level navigation and one level of children.
315
+
316
+ #### Method Signature
317
+
318
+ ```ts
319
+ get(
320
+ uri: string,
321
+ options?: {
322
+ depth?: number;
323
+ languageId?: number;
324
+ }
325
+ ): Promise<DotCMSNavigationItem[]>;
115
326
  ```
116
327
 
117
- #### Filtering by Language
328
+ #### Why Use `navigation.get()`?
118
329
 
119
- If you need to filter content by language, you can specify the `language` parameter:
330
+ - Build dynamic menus and site trees with minimal configuration
331
+ - Avoid manual parsing or custom REST calls
332
+ - Support localized navigation out of the box
333
+ - Easily control navigation depth for responsive and nested UIs
120
334
 
121
- ```typescript
122
- const languageFilteredResponse = await client.content
123
- .getCollection('Blog')
124
- .language(2) // Filter by language ID (e.g., 2)
125
- .fetch();
335
+ ### client.content.getCollection(): Fetching Content Collections
336
+
337
+ The `client.content.getCollection()` method allows you to query and retrieve a collection of content items of a specific type from dotCMS. It uses a builder pattern so you can fluently compose queries with filters, pagination, sorting, and more.
338
+
339
+ #### Why Use `getCollection()`?
340
+
341
+ - Query exactly the content you need
342
+ - Chain filters, sorting, and pagination cleanly
343
+ - Works great for lists, search results, or dynamic components
344
+ - Fully type-safe when used with TypeScript interfaces
345
+
346
+ #### Basic Usage
347
+
348
+ Here's how to fetch the first 10 items from the "Blog" content type:
349
+
350
+ ```ts
351
+ const blogs = await client.content.getCollection('Blog').limit(10).page(1);
126
352
  ```
127
353
 
128
- #### Using Complex Queries
354
+ #### Filtering and Querying Content
129
355
 
130
- You can build more complex queries using the query builder. For example, filter by `author` and `title`:
356
+ You can apply query filters using a fluent builder pattern:
131
357
 
132
- ```typescript
133
- const complexQueryResponse = await client.content
358
+ ```ts
359
+ const filtered = await client.content
134
360
  .getCollection('Blog')
135
- .query((qb) => qb.field('author').equals('John Doe').and().field('title').equals('Hello World'))
136
- .fetch();
361
+ .query((qb) => qb.field('title').equals('dotCMS*'))
362
+ .limit(5)
363
+ .sortBy([{ field: 'publishDate', direction: 'desc' }]);
137
364
  ```
138
365
 
139
- #### Fetching Draft Content
366
+ #### Search and Paginate Product Results by Title and Price
140
367
 
141
- To only fetch draft content, use the `draft()` method:
368
+ ```ts
369
+ const searchResults = await client.content
370
+ .getCollection('Product')
371
+ .query((qb) => qb.field('title').equals('Book*'))
372
+ .sortBy([{ field: 'price', order: 'asc' }])
373
+ .limit(10)
374
+ .page(2);
142
375
 
143
- ```typescript
144
- const draftContentResponse = await client.content
145
- .getCollection('Blog')
146
- .draft() // Fetch only drafts content
147
- .fetch();
376
+ console.log(searchResults);
148
377
  ```
149
378
 
150
- #### Setting Depth for Relationships
379
+ #### Localized Query with Conditional Status Filtering
151
380
 
152
- To fetch content with a specific relationship depth, use the `depth()` method:
381
+ ```ts
382
+ const events = await client.content
383
+ .getCollection('Event')
384
+ .query((qb) => qb.field('status').equals('Live').or().equals('Scheduled').build())
385
+ .language(2) // e.g., French
386
+ .limit(5);
153
387
 
154
- ```typescript
155
- const depthResponse = await client.content
156
- .getCollection('Blog')
157
- .depth(2) // Fetch related content up to depth 2
158
- .fetch();
388
+ console.log(events);
159
389
  ```
160
390
 
161
- #### Combining Multiple Methods
391
+ #### Raw Search + Sorting + Pagination
162
392
 
163
- You can combine multiple methods to build more complex queries. For example, limit results, sort them, and filter by author:
393
+ ```ts
394
+ const images = await client.content
395
+ .getCollection('Image')
396
+ .query('+title:vacation*')
397
+ .sortBy([{ field: 'publishDate', order: 'desc' }])
398
+ .limit(10)
399
+ .page(1);
164
400
 
165
- ```typescript
166
- const combinedResponse = await client.content
167
- .getCollection('Blog')
168
- .limit(5)
169
- .page(2)
170
- .sortBy([{ field: 'title', order: 'asc' }])
171
- .query((qb) => qb.field('author').equals('John Doe'))
172
- .depth(1)
173
- .fetch();
401
+ console.log(images);
402
+ ```
403
+
404
+ #### Available Builder Methods
405
+
406
+ The builder returned by `getCollection()` supports the following methods:
407
+
408
+ | Method | Arguments | Description |
409
+ | ------------ | ----------------------------- | ------------------------------------------------------------------------- |
410
+ | `query()` | `string` \| `BuildQuery` | Filter content using query builder or raw query |
411
+ | `limit()` | `number` | Set number of items to return |
412
+ | `page()` | `number` | Set which page of results to fetch |
413
+ | `sortBy()` | `SortBy[]` | Sort by one or more fields |
414
+ | `render()` | None | Enable server-side rendering of widgets |
415
+ | `draft()` | None | Retrieve draft content |
416
+ | `variant()` | `string` | Filter content by variant ID |
417
+ | `depth()` | `number` | Set depth of related content |
418
+ | `language()` | `number \| string` | Set content language |
419
+ | `then()` | `OnFullfilled<T>, OnRejected` | Handle promise fulfillment or rejection. Not needed if using async/await. |
420
+
421
+ #### Method Signature
422
+
423
+ ```ts
424
+ getCollection<T = DotCMSBasicContentlet>(
425
+ contentType: string
426
+ ): CollectionBuilder<T>;
174
427
  ```
175
428
 
176
- ## Error Handling Example
429
+ ## Using the SDK with TypeScript
430
+
431
+ As mentioned earlier, dotCMS provides a rich set of types provided by the `@dotcms/types@next` package. These types can be leveraged to ensure proper typing for your page and content data, enhancing type safety and developer experience.
177
432
 
178
- To handle errors gracefully, you can use a `try-catch` block around your API calls. Here’s an example:
433
+ ### Defining Page Response Types
434
+
435
+ You can use these types to define interfaces for your content and page structures, ensuring that your application benefits from TypeScript's type-checking capabilities:
179
436
 
180
437
  ```typescript
181
- try {
182
- const pageData = await client.page.get({
183
- path: '/your-page-path',
184
- languageId: 1
185
- });
186
- } catch (error) {
187
- console.error('Failed to fetch page data:', error);
438
+ // Import the base DotCMS types
439
+ import { DotCMSPageAsset, DotCMSBasicContentlet } from '@dotcms/types';
440
+
441
+ // Define the page structure by extending the base DotCMSPageAsset
442
+ interface AboutUsPage extends DotCMSPageAsset {
443
+ vanityUrl: {
444
+ url: string;
445
+ };
446
+ }
447
+
448
+ // Define interfaces for your content types
449
+ interface BlogPost extends DotCMSBasicContentlet {
450
+ title: string;
451
+ identifier: string;
452
+ urlTitle: string;
453
+ blogContent: {
454
+ json: string;
455
+ };
456
+ }
457
+
458
+ interface TeamMember {
459
+ name: string;
460
+ position: string;
461
+ bio?: string;
188
462
  }
463
+
464
+ // Define the content response structure
465
+ interface AboutUsContent {
466
+ blogPosts: BlogPost[];
467
+ teamMembers: TeamMember[];
468
+ }
469
+
470
+ // Use the type parameters to get fully typed responses
471
+ const response = await client.page.get<{ pageAsset: AboutUsPage; content: AboutUsContent }>(
472
+ '/about-us',
473
+ {
474
+ languageId: '1',
475
+ fireRules: true,
476
+ graphql: {
477
+ page: `
478
+ title
479
+ pageId
480
+ vanityUrl {
481
+ url
482
+ }
483
+ `,
484
+ content: {
485
+ blogPosts: `
486
+ BlogCollection(limit: 3) {
487
+ title
488
+ identifier
489
+ ...blogFragment
490
+ }
491
+ `,
492
+ teamMembers: `
493
+ TeamMemberCollection(limit: 5) {
494
+ name
495
+ position
496
+ bio
497
+ }
498
+ `
499
+ },
500
+ fragments: [
501
+ `
502
+ fragment blogFragment on Blog {
503
+ urlTitle
504
+ blogContent {
505
+ json
506
+ }
507
+ }
508
+ `
509
+ ]
510
+ }
511
+ }
512
+ );
513
+
514
+ const { pageAsset, content } = response;
515
+
516
+ // Now you get full TypeScript support
517
+ console.log(pageAsset.vanityUrl.url); // TypeScript knows this exists
518
+ console.log(content.blogPosts[0].title); // TypeScript knows this exists
519
+ console.log(content.teamMembers[0].position); // TypeScript knows this exists
189
520
  ```
190
521
 
191
- This ensures that any errors that occur during the fetch (e.g., network issues, invalid paths, etc.) are caught and logged properly.
522
+ ### Defining Content Response Types
192
523
 
193
- ## Pagination
524
+ You can define interfaces for your content types to get full type safety:
194
525
 
195
- When fetching large collections of content, pagination is key to managing the number of results returned:
526
+ ```ts
527
+ import { DotCMSBasicContentlet } from '@dotcms/types';
196
528
 
197
- ```typescript
198
- const paginatedResponse = await client.content
199
- .getCollection('Blog')
200
- .limit(10) // Limit to 10 items per page
201
- .page(2) // Get the second page of results
202
- .fetch();
529
+ interface BlogPost extends DotCMSBasicContentlet {
530
+ title: string;
531
+ publishDate: string;
532
+ author: string;
533
+ blogContent: {
534
+ json: string;
535
+ };
536
+ urlTitle: string;
537
+ tags: string[];
538
+ }
539
+
540
+ const response = await client.content.getCollection<BlogPost>('Blog');
541
+
542
+ response.contentlets.forEach((post) => {
543
+ console.log(post.title); // Type-safe access
544
+ console.log(post.author);
545
+ console.log(post.tags.join(', '));
546
+ });
203
547
  ```
204
548
 
205
- ## API Reference
549
+ ## How to Enable Page Editing in dotCMS
550
+
551
+ By default, the `@dotcms/client` SDK is **read-only**. It's designed to fetch content from dotCMS—pages, navigation, and collections—but it doesn't make pages editable in the dotCMS backend.
552
+
553
+ To make your pages editable using the dotCMS **Universal Visual Editor (UVE)**, you'll need to pair this SDK with one of our supported front-end integrations.
554
+
555
+ ### Use an Official SDK:
556
+
557
+ If you're using a modern JavaScript framework like React or Angular, we strongly recommend starting with one of our official UVE integrations. These pair the `@dotcms/client` SDK with framework-specific tooling for the Universal Visual Editor:
206
558
 
207
- Detailed documentation of the `@dotcms/client` methods, parameters, and types can be found below:
559
+ * 🧩 **React SDK**: [`@dotcms/react`](https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/react)
560
+ * 🧩 **Angular SDK**: [`@dotcms/angular`](https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/angular)
208
561
 
209
- ### `DotCmsClient.init(config: ClientConfig): DotCmsClient`
562
+ You can also see them in action within our full-stack examples:
210
563
 
211
- Initializes the dotCMS client with the specified configuration.
564
+ * [Next.js Example](https://github.com/dotCMS/core/tree/main/examples/nextjs)
565
+ * [Angular Example](https://github.com/dotCMS/core/tree/main/examples/angular)
566
+ * [Astro Example](https://github.com/dotCMS/core/tree/main/examples/astro)
212
567
 
213
- ### `DotCmsClient.page.get(options: PageApiOptions): Promise<unknown>`
568
+ These integrations come pre-wired with everything you need to:
214
569
 
215
- Retrieves the specified page's elements from your dotCMS system in JSON format.
570
+ * Enable editable pages inside dotCMS using the UVE
571
+ * Render layouts and content containers
572
+ * Fetch page and content data using `@dotcms/client`
216
573
 
217
- ### `DotCmsClient.nav.get(options: NavApiOptions): Promise<unknown>`
574
+ ### ⚠️ Advanced Only: Custom UVE Integration
218
575
 
219
- Retrieves information about the dotCMS file and folder tree.
576
+ If you’re building with a framework we don’t yet support, you can build your own UVE integration using the low-level [`@dotcms/uve`](https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/uve) package.
220
577
 
221
- ### `DotCmsClient.content.getCollection(contentType: string): CollectionBuilder<T>`
578
+ > **This is not a recommended path.**
579
+ >
580
+ > Custom UVE implementations are complex, require a deep understanding of dotCMS internals, and are not actively supported.
581
+ >
582
+ > This route is intended only for advanced use cases, such as wiring up layout rendering, editable regions, and UVE behavior manually.
222
583
 
223
- Creates a builder to filter and fetches a collection of content items for a specific content type.
584
+ That said, if you’re experienced and want to explore it, you can [review the `@dotcms/uve` source and docs here](https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/uve).
224
585
 
225
- #### Parameters
586
+ ## dotCMS Support
226
587
 
227
- `contentType` (string): The content type to retrieve.
588
+ We offer multiple channels to get help with the dotCMS Client SDK:
228
589
 
229
- #### Returns
590
+ - **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
591
+ - **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
592
+ - **Stack Overflow**: Use the tag `dotcms-client` when posting questions.
230
593
 
231
- `CollectionBuilder<T>`: A builder instance for chaining filters and executing the query.
594
+ When reporting issues, please include:
232
595
 
233
- ## Contributing
596
+ - SDK version you're using
597
+ - dotCMS version
598
+ - Minimal reproduction steps
599
+ - Expected vs. actual behavior
234
600
 
235
- GitHub pull requests are the preferred method to contribute code to dotCMS. Before any pull requests can be accepted, an automated tool will ask you to agree to the [dotCMS Contributor's Agreement](https://gist.github.com/wezell/85ef45298c48494b90d92755b583acb3).
601
+ Enterprise customers can access premium support through the [dotCMS Support Portal](https://dev.dotcms.com/docs/help).
236
602
 
237
- ## Licensing
603
+ ## How To Contribute
238
604
 
239
- dotCMS comes in multiple editions and as such is dual licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds a number of enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://dotcms.com/cms-platform/features).
605
+ GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the DotCMS UVE SDK! If you'd like to contribute, please follow these steps:
240
606
 
241
- ## Support
607
+ 1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
608
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
609
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
610
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
611
+ 5. Open a Pull Request
242
612
 
243
- If you need help or have any questions, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
613
+ Please ensure your code follows the existing style and includes appropriate tests.
244
614
 
245
- ## Documentation
615
+ ## Licensing Information
246
616
 
247
- Always refer to the official [dotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
617
+ dotCMS comes in multiple editions and as such is dual-licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization, and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds several enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://www.dotcms.com/cms-platform/features).
248
618
 
249
- ## Getting Help
619
+ This SDK is part of dotCMS's dual-licensed platform (GPL 3.0 for Community, commercial license for Enterprise).
250
620
 
251
- | Source | Location |
252
- | --------------- | ------------------------------------------------------------------- |
253
- | Installation | [Installation](https://dotcms.com/docs/latest/installation) |
254
- | Documentation | [Documentation](https://dotcms.com/docs/latest/table-of-contents) |
255
- | Videos | [Helpful Videos](http://dotcms.com/videos/) |
256
- | Forums/Listserv | [via Google Groups](https://groups.google.com/forum/#!forum/dotCMS) |
257
- | Twitter | @dotCMS |
258
- | Main Site | [dotCMS.com](https://dotcms.com/) |
621
+ [Learn more ](https://www.dotcms.com)at [dotcms.com](https://www.dotcms.com).