@dotcms/client 0.0.1-beta.3 → 0.0.1-beta.31
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 +183 -36
- package/index.cjs.js +102 -1238
- package/index.esm.js +86 -1221
- package/next.cjs.d.ts +1 -0
- package/next.cjs.default.js +1 -0
- package/next.cjs.js +526 -0
- package/next.cjs.mjs +2 -0
- package/next.esm.d.ts +1 -0
- package/next.esm.js +524 -0
- package/package.json +26 -7
- package/src/index.d.ts +6 -6
- package/src/lib/client/client.d.ts +56 -0
- package/src/lib/client/content/builders/collection/collection.d.ts +1 -1
- package/src/lib/client/content/content-api.d.ts +3 -3
- package/src/lib/client/content/shared/types.d.ts +3 -44
- package/src/lib/client/navigation/navigation-api.d.ts +14 -0
- package/src/lib/client/page/page-api.d.ts +96 -0
- package/src/lib/client/page/utils.d.ts +41 -0
- package/src/lib/{editor → deprecated/editor}/models/client.model.d.ts +13 -0
- package/src/lib/{editor → deprecated/editor}/sdk-editor.d.ts +1 -1
- package/src/lib/{client → deprecated}/sdk-js-client.d.ts +1 -1
- package/src/lib/utils/graphql/transforms.d.ts +2 -13
- package/src/lib/utils/page/common-utils.d.ts +1 -1
- package/src/next.d.ts +1 -0
- package/transforms.cjs.js +1150 -0
- package/transforms.esm.js +1144 -0
- package/src/lib/client/models/types.d.ts +0 -13
- /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Equals.d.ts +0 -0
- /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Field.d.ts +0 -0
- /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/NotOperand.d.ts +0 -0
- /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/Operand.d.ts +0 -0
- /package/src/lib/{query-builder → client/content/builders/query}/lucene-syntax/index.d.ts +0 -0
- /package/src/lib/{query-builder/sdk-query-builder.d.ts → client/content/builders/query/query.d.ts} +0 -0
- /package/src/lib/{query-builder → client/content/builders/query}/utils/index.d.ts +0 -0
- /package/src/lib/{editor → deprecated/editor}/listeners/listeners.d.ts +0 -0
- /package/src/lib/{editor → deprecated/editor}/models/editor.model.d.ts +0 -0
- /package/src/lib/{editor → deprecated/editor}/models/inline-event.model.d.ts +0 -0
- /package/src/lib/{editor → deprecated/editor}/models/listeners.model.d.ts +0 -0
- /package/src/lib/{editor → deprecated/editor}/sdk-editor-vtl.d.ts +0 -0
- /package/src/lib/{editor → deprecated/editor}/utils/editor.utils.d.ts +0 -0
- /package/src/lib/{editor → deprecated/editor}/utils/traditional-vtl.utils.d.ts +0 -0
package/README.md
CHANGED
|
@@ -2,15 +2,67 @@
|
|
|
2
2
|
|
|
3
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.
|
|
4
4
|
|
|
5
|
+
> **⚠️ IMPORTANT:** Versions published under the `next` tag (`npm install @dotcms/client@next`) are experimental, in beta, and not code complete. For the current stable and functional version, please use `latest` (`npm install @dotcms/client@latest`). Once we release the stable version, we will provide a migration guide from the alpha to stable version. The current alpha version (under `latest`) will continue to work, allowing you to migrate progressively at your own pace.
|
|
6
|
+
|
|
5
7
|
This client library provides a streamlined, promise-based interface to fetch pages and navigation API.
|
|
6
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Features](#features)
|
|
12
|
+
- [What's New](#whats-new)
|
|
13
|
+
- [What's Being Deprecated](#whats-being-deprecated)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [ES Modules](#es-modules)
|
|
18
|
+
- [CommonJS](#commonjs)
|
|
19
|
+
- [Initialization](#initialization)
|
|
20
|
+
- [Fetching a Page](#fetching-a-page)
|
|
21
|
+
- [Example with all options](#example-with-all-options)
|
|
22
|
+
- [Fetching Navigation](#fetching-navigation)
|
|
23
|
+
- [Legacy Navigation Example](#legacy-navigation-example)
|
|
24
|
+
- [Fetching a Collection of Content](#fetching-a-collection-of-content)
|
|
25
|
+
- [Basic Usage](#basic-usage)
|
|
26
|
+
- [Sorting Content](#sorting-content)
|
|
27
|
+
- [Filtering by Language](#filtering-by-language)
|
|
28
|
+
- [Using Complex Queries](#using-complex-queries)
|
|
29
|
+
- [Fetching Draft Content](#fetching-draft-content)
|
|
30
|
+
- [Setting Depth for Relationships](#setting-depth-for-relationships)
|
|
31
|
+
- [Combining Multiple Methods](#combining-multiple-methods)
|
|
32
|
+
- [Error Handling Example](#error-handling-example)
|
|
33
|
+
- [Pagination](#pagination)
|
|
34
|
+
- [API Reference](#api-reference)
|
|
35
|
+
- [Contributing](#contributing)
|
|
36
|
+
- [Licensing](#licensing)
|
|
37
|
+
- [Support](#support)
|
|
38
|
+
- [Documentation](#documentation)
|
|
39
|
+
- [Getting Help](#getting-help)
|
|
40
|
+
|
|
7
41
|
## Features
|
|
8
42
|
|
|
9
43
|
- 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
44
|
- Support for custom actions to communicate with the dotCMS page editor.
|
|
11
45
|
- Comprehensive TypeScript typings for better development experience.
|
|
12
46
|
|
|
13
|
-
|
|
47
|
+
## What's New
|
|
48
|
+
|
|
49
|
+
- **Improved Collection Builder API:** Enhanced content fetching with a fluent builder pattern
|
|
50
|
+
- **TypeScript Support:** Comprehensive type definitions for better developer experience
|
|
51
|
+
- **Promise-based API:** Modern, async/await compatible interface for all API calls
|
|
52
|
+
- **Performance Optimizations:** Faster response times and reduced memory footprint
|
|
53
|
+
- **New Client Creation:** The `dotCMSCreateClient()` function replaces `DotCmsClient.init()` for better functional programming
|
|
54
|
+
|
|
55
|
+
> **Note:** Some deprecated features are being phased out. See [API Reference](#api-reference) for details.
|
|
56
|
+
|
|
57
|
+
## What's Being Deprecated
|
|
58
|
+
|
|
59
|
+
- **Legacy Editor APIs:** The `postMessageToEditor`, `initEditor`, and related functions are being phased out
|
|
60
|
+
- **Direct Content API:** The `content.get()` method is being replaced by the more powerful `content.getCollection()`
|
|
61
|
+
- **Callback-based APIs:** All callback-based methods are being replaced with Promise-based alternatives
|
|
62
|
+
- **DotCmsClient.init:** The static `DotCmsClient.init()` method is replaced by the `dotCMSCreateClient()` function
|
|
63
|
+
- **client.editor:** The editor functionality has been completely moved to the `@dotcms/uve` package
|
|
64
|
+
|
|
65
|
+
> **Note:** Deprecated items will continue to work for backward compatibility but will be removed in future major versions.
|
|
14
66
|
|
|
15
67
|
## Installation
|
|
16
68
|
|
|
@@ -24,7 +76,17 @@ Or using Yarn:
|
|
|
24
76
|
|
|
25
77
|
```bash
|
|
26
78
|
yarn add @dotcms/client
|
|
27
|
-
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
## Browser Compatibility
|
|
82
|
+
|
|
83
|
+
The @dotcms/client package is compatible with the following browsers:
|
|
84
|
+
|
|
85
|
+
| Browser | Minimum Version | TLS Version |
|
|
86
|
+
|---------|----------------|-------------|
|
|
87
|
+
| Chrome | Latest 2 versions | TLS 1.2+ |
|
|
88
|
+
| Edge | Latest 2 versions | TLS 1.2+ |
|
|
89
|
+
| Firefox | Latest 2 versions | TLS 1.2+ |
|
|
28
90
|
|
|
29
91
|
## Usage
|
|
30
92
|
|
|
@@ -33,13 +95,13 @@ yarn add @dotcms/client
|
|
|
33
95
|
### ES Modules
|
|
34
96
|
|
|
35
97
|
```javascript
|
|
36
|
-
import {
|
|
98
|
+
import { createDotCMSClient } from '@dotcms/client/next';
|
|
37
99
|
```
|
|
38
100
|
|
|
39
101
|
### CommonJS
|
|
40
102
|
|
|
41
103
|
```javascript
|
|
42
|
-
const {
|
|
104
|
+
const { createDotCMSClient } = require('@dotcms/client/next');
|
|
43
105
|
```
|
|
44
106
|
|
|
45
107
|
### Initialization
|
|
@@ -47,7 +109,7 @@ const { DotCmsClient } = require('@dotcms/client');
|
|
|
47
109
|
First, initialize the client with your dotCMS instance details.
|
|
48
110
|
|
|
49
111
|
```javascript
|
|
50
|
-
const client =
|
|
112
|
+
const client = createDotCMSClient({
|
|
51
113
|
dotcmsUrl: 'https://your-dotcms-instance.com',
|
|
52
114
|
authToken: 'your-auth-token',
|
|
53
115
|
siteId: 'your-site-id'
|
|
@@ -59,18 +121,120 @@ const client = DotCmsClient.init({
|
|
|
59
121
|
You can retrieve the elements of any page in your dotCMS system in JSON format using the `client.page.get()` method.
|
|
60
122
|
|
|
61
123
|
```javascript
|
|
62
|
-
const pageData = await client.page.get({
|
|
63
|
-
|
|
64
|
-
language_id: 1,
|
|
124
|
+
const pageData = await client.page.get('/your-page-path', {
|
|
125
|
+
languageId: '1',
|
|
65
126
|
personaId: 'optional-persona-id'
|
|
66
127
|
});
|
|
67
128
|
```
|
|
68
129
|
|
|
130
|
+
|
|
131
|
+
### Warning
|
|
132
|
+
|
|
133
|
+
If you are updating from a version that is lower than `0.0.1-beta.29`, be aware that the response from the `client.page.get` method changed the access to the page value from `page` to `pageAsset`.
|
|
134
|
+
This change was made to avoid redundancy on access inside of `page` object.
|
|
135
|
+
|
|
136
|
+
#### Before
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
const { page } = await client.page.get("/")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### After
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
const { pageAsset } = await client.page.get("/")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
#### Example with all options
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
// Fetching a page with all available options
|
|
153
|
+
const { pageAsset, content } = await client.page.get('/about-us', {
|
|
154
|
+
languageId: '1', // Language ID (optional)
|
|
155
|
+
siteId: 'demo.dotcms.com', // Site ID (optional, defaults to the one provided during initialization)
|
|
156
|
+
mode: 'PREVIEW_MODE', // ADMIN_MODE, PREVIEW_MODE, or LIVE_MODE (optional)
|
|
157
|
+
personaId: '123', // Persona ID for personalization (optional)
|
|
158
|
+
device: 'smartphone', // Device for responsive rendering (optional)
|
|
159
|
+
graphql: { // Extend page and/or content response (optional)
|
|
160
|
+
page: `
|
|
161
|
+
containers {
|
|
162
|
+
containerContentlets {
|
|
163
|
+
uuid
|
|
164
|
+
contentlets {
|
|
165
|
+
title
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
`,
|
|
170
|
+
content: {
|
|
171
|
+
blogPosts: `
|
|
172
|
+
search(query: "+contentType:Blog", limit: 3) {
|
|
173
|
+
title
|
|
174
|
+
identifier
|
|
175
|
+
...blogFragment
|
|
176
|
+
}
|
|
177
|
+
`,
|
|
178
|
+
},
|
|
179
|
+
fragments: [
|
|
180
|
+
`
|
|
181
|
+
fragment blogFragment on Blog {
|
|
182
|
+
urlTitle
|
|
183
|
+
blogContent {
|
|
184
|
+
json
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
`
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// Access page data
|
|
194
|
+
console.log(pageAsset.containers);
|
|
195
|
+
|
|
196
|
+
// Access content data
|
|
197
|
+
console.log(content.blogPosts);
|
|
198
|
+
```
|
|
199
|
+
|
|
69
200
|
### Fetching Navigation
|
|
70
201
|
|
|
71
|
-
|
|
202
|
+
The new API allows you to fetch navigation data using GraphQL through the page.get method:
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
// Fetch navigation using the page.get method with GraphQL
|
|
206
|
+
const { content } = await client.page.get('/', {
|
|
207
|
+
languageId: '1',
|
|
208
|
+
graphql: {
|
|
209
|
+
content: {
|
|
210
|
+
nav: `
|
|
211
|
+
query {
|
|
212
|
+
nav {
|
|
213
|
+
identifier
|
|
214
|
+
path
|
|
215
|
+
label
|
|
216
|
+
children {
|
|
217
|
+
identifier
|
|
218
|
+
path
|
|
219
|
+
label
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
`
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Access navigation data
|
|
229
|
+
console.log(content.nav);
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
> **Note:** The legacy `client.nav.get()` method is still available but deprecated.
|
|
233
|
+
|
|
234
|
+
#### Legacy Navigation Example
|
|
72
235
|
|
|
73
236
|
```javascript
|
|
237
|
+
// Legacy approach - still works but is deprecated
|
|
74
238
|
const navData = await client.nav.get({
|
|
75
239
|
path: '/',
|
|
76
240
|
depth: 2,
|
|
@@ -84,12 +248,12 @@ The `getCollection` method allows you to fetch a collection of content items (so
|
|
|
84
248
|
|
|
85
249
|
#### Basic Usage
|
|
86
250
|
|
|
87
|
-
Here
|
|
251
|
+
Here's a simple example to fetch content from a collection:
|
|
88
252
|
|
|
89
253
|
```typescript
|
|
90
|
-
import {
|
|
254
|
+
import { dotCMSCreateClient } from '@dotcms/client';
|
|
91
255
|
|
|
92
|
-
const client =
|
|
256
|
+
const client = dotCMSCreateClient({
|
|
93
257
|
dotcmsUrl: 'https://your-dotcms-instance.com',
|
|
94
258
|
authToken: 'your-auth-token'
|
|
95
259
|
});
|
|
@@ -175,7 +339,7 @@ const combinedResponse = await client.content
|
|
|
175
339
|
|
|
176
340
|
## Error Handling Example
|
|
177
341
|
|
|
178
|
-
To handle errors gracefully, you can use a `try-catch` block around your API calls. Here
|
|
342
|
+
To handle errors gracefully, you can use a `try-catch` block around your API calls. Here's an example:
|
|
179
343
|
|
|
180
344
|
```typescript
|
|
181
345
|
try {
|
|
@@ -206,29 +370,12 @@ const paginatedResponse = await client.content
|
|
|
206
370
|
|
|
207
371
|
Detailed documentation of the `@dotcms/client` methods, parameters, and types can be found below:
|
|
208
372
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
Initializes the dotCMS client
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
Retrieves the specified page's elements from your dotCMS system in JSON format.
|
|
216
|
-
|
|
217
|
-
### `DotCmsClient.nav.get(options: NavApiOptions): Promise<unknown>`
|
|
218
|
-
|
|
219
|
-
Retrieves information about the dotCMS file and folder tree.
|
|
220
|
-
|
|
221
|
-
### `DotCmsClient.content.getCollection(contentType: string): CollectionBuilder<T>`
|
|
222
|
-
|
|
223
|
-
Creates a builder to filter and fetches a collection of content items for a specific content type.
|
|
224
|
-
|
|
225
|
-
#### Parameters
|
|
226
|
-
|
|
227
|
-
`contentType` (string): The content type to retrieve.
|
|
228
|
-
|
|
229
|
-
#### Returns
|
|
230
|
-
|
|
231
|
-
`CollectionBuilder<T>`: A builder instance for chaining filters and executing the query.
|
|
373
|
+
| Method | Description | Parameters | Returns |
|
|
374
|
+
|--------|-------------|------------|---------|
|
|
375
|
+
| `dotCMSCreateClient(config)` | Initializes the dotCMS client | `config: DotCMSClientConfig` | `DotCMSClient` |
|
|
376
|
+
| `client.page.get(path, options)` | Retrieves page elements | `path: string, options: PageApiOptions` | `Promise<{page: any, content: any}>` |
|
|
377
|
+
| `client.nav.get(options)` | Retrieves navigation structure | `options: NavApiOptions` | `Promise<unknown>` |
|
|
378
|
+
| `client.content.getCollection(contentType)` | Builds a query for content | `contentType: string` | `CollectionBuilder<T>` |
|
|
232
379
|
|
|
233
380
|
## Contributing
|
|
234
381
|
|