@dotcms/client 0.0.1-alpha.4 → 0.0.1-alpha.41
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 +17 -6
- package/index.cjs.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +1953 -0
- package/index.cjs.mjs +2 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +1944 -0
- package/package.json +19 -7
- package/src/index.d.ts +6 -2
- package/src/lib/client/content/builders/collection/collection.d.ts +226 -0
- package/src/lib/client/content/content-api.d.ts +129 -0
- package/src/lib/client/content/shared/const.d.ts +13 -0
- package/src/lib/client/content/shared/types.d.ts +138 -0
- package/src/lib/client/content/shared/utils.d.ts +20 -0
- package/src/lib/client/models/index.d.ts +12 -0
- package/src/lib/client/models/types.d.ts +13 -0
- package/src/lib/client/sdk-js-client.d.ts +276 -0
- package/src/lib/editor/listeners/listeners.d.ts +50 -0
- package/src/lib/{postMessageToEditor.d.ts → editor/models/client.model.d.ts} +33 -2
- package/src/lib/editor/models/editor.model.d.ts +49 -0
- package/src/lib/editor/models/listeners.model.d.ts +47 -0
- package/src/lib/editor/sdk-editor-vtl.d.ts +6 -0
- package/src/lib/editor/sdk-editor.d.ts +54 -0
- package/src/lib/editor/utils/editor.utils.d.ts +159 -0
- package/src/lib/query-builder/lucene-syntax/Equals.d.ts +114 -0
- package/src/lib/query-builder/lucene-syntax/Field.d.ts +32 -0
- package/src/lib/query-builder/lucene-syntax/NotOperand.d.ts +26 -0
- package/src/lib/query-builder/lucene-syntax/Operand.d.ts +44 -0
- package/src/lib/query-builder/lucene-syntax/index.d.ts +4 -0
- package/src/lib/query-builder/sdk-query-builder.d.ts +76 -0
- package/src/lib/query-builder/utils/index.d.ts +142 -0
- package/src/lib/utils/graphql/transforms.d.ts +24 -0
- package/src/lib/utils/index.d.ts +2 -0
- package/src/lib/utils/page/common-utils.d.ts +33 -0
- package/src/index.js +0 -3
- package/src/index.js.map +0 -1
- package/src/lib/postMessageToEditor.js +0 -42
- package/src/lib/postMessageToEditor.js.map +0 -1
- package/src/lib/sdk-js-client.d.ts +0 -183
- package/src/lib/sdk-js-client.js +0 -145
- package/src/lib/sdk-js-client.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/client",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.0.1-alpha.41",
|
|
5
4
|
"description": "Official JavaScript library for interacting with DotCMS REST APIs.",
|
|
6
5
|
"repository": {
|
|
7
6
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/dotCMS/core.git#
|
|
7
|
+
"url": "git+https://github.com/dotCMS/core.git#main"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "nx run sdk-client:build:js; cd ../../../../dotCMS/src/main/webapp/html/js/editor-js; rm -rf src package.json *.esm.d.ts"
|
|
9
11
|
},
|
|
10
12
|
"keywords": [
|
|
11
13
|
"dotCMS",
|
|
@@ -19,7 +21,17 @@
|
|
|
19
21
|
"bugs": {
|
|
20
22
|
"url": "https://github.com/dotCMS/core/issues"
|
|
21
23
|
},
|
|
22
|
-
"homepage": "https://github.com/dotCMS/core/tree/
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
"homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/client/README.md",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
".": {
|
|
28
|
+
"module": "./index.esm.js",
|
|
29
|
+
"types": "./index.esm.d.ts",
|
|
30
|
+
"import": "./index.cjs.mjs",
|
|
31
|
+
"default": "./index.cjs.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"module": "./index.esm.js",
|
|
35
|
+
"main": "./index.cjs.js",
|
|
36
|
+
"types": "./index.esm.d.ts"
|
|
37
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { ClientConfig, DotCmsClient } from './lib/client/sdk-js-client';
|
|
2
|
+
import { CUSTOMER_ACTIONS, postMessageToEditor } from './lib/editor/models/client.model';
|
|
3
|
+
import { CustomClientParams, DotCMSPageEditorConfig, EditorConfig } from './lib/editor/models/editor.model';
|
|
4
|
+
import { destroyEditor, initEditor, isInsideEditor, updateNavigation } from './lib/editor/sdk-editor';
|
|
5
|
+
import { getPageRequestParams, graphqlToPageEntity } from './lib/utils';
|
|
6
|
+
export { graphqlToPageEntity, getPageRequestParams, isInsideEditor, DotCmsClient, DotCMSPageEditorConfig, CUSTOMER_ACTIONS, CustomClientParams, postMessageToEditor, EditorConfig, initEditor, updateNavigation, destroyEditor, ClientConfig };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { ClientOptions } from '../../../sdk-js-client';
|
|
2
|
+
import { GetCollectionResponse, BuildQuery, SortBy, GetCollectionError, OnFullfilled, OnRejected } from '../../shared/types';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Builder to filter and fetch content from the content API for a specific content type.
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class CollectionBuilder
|
|
8
|
+
* @template T Represents the type of the content type to fetch. Defaults to unknown.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CollectionBuilder<T = unknown> {
|
|
11
|
+
#private;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of CollectionBuilder.
|
|
14
|
+
* @param {ClientOptions} requestOptions Options for the client request.
|
|
15
|
+
* @param {string} serverUrl The server URL.
|
|
16
|
+
* @param {string} contentType The content type to fetch.
|
|
17
|
+
* @memberof CollectionBuilder
|
|
18
|
+
*/
|
|
19
|
+
constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string);
|
|
20
|
+
/**
|
|
21
|
+
* Returns the sort query in the format: field order, field order, ...
|
|
22
|
+
*
|
|
23
|
+
* @readonly
|
|
24
|
+
* @private
|
|
25
|
+
* @memberof CollectionBuilder
|
|
26
|
+
*/
|
|
27
|
+
private get sort();
|
|
28
|
+
/**
|
|
29
|
+
* Returns the offset for pagination.
|
|
30
|
+
*
|
|
31
|
+
* @readonly
|
|
32
|
+
* @private
|
|
33
|
+
* @memberof CollectionBuilder
|
|
34
|
+
*/
|
|
35
|
+
private get offset();
|
|
36
|
+
/**
|
|
37
|
+
* Returns the full URL for the content API.
|
|
38
|
+
*
|
|
39
|
+
* @readonly
|
|
40
|
+
* @private
|
|
41
|
+
* @memberof CollectionBuilder
|
|
42
|
+
*/
|
|
43
|
+
private get url();
|
|
44
|
+
/**
|
|
45
|
+
* Returns the current query built.
|
|
46
|
+
*
|
|
47
|
+
* @readonly
|
|
48
|
+
* @private
|
|
49
|
+
* @memberof CollectionBuilder
|
|
50
|
+
*/
|
|
51
|
+
private get currentQuery();
|
|
52
|
+
/**
|
|
53
|
+
* Filters the content by the specified language ID.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const client = new DotCMSClient(config);
|
|
58
|
+
* const collectionBuilder = client.content.getCollection("Blog");
|
|
59
|
+
* collectionBuilder.language(1);
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param {number | string} languageId The language ID to filter the content by.
|
|
63
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
64
|
+
* @memberof CollectionBuilder
|
|
65
|
+
*/
|
|
66
|
+
language(languageId: number | string): this;
|
|
67
|
+
/**
|
|
68
|
+
* Setting this to true will server side render (using velocity) any widgets that are returned by the content query.
|
|
69
|
+
*
|
|
70
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
|
|
71
|
+
*
|
|
72
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
73
|
+
* @memberof CollectionBuilder
|
|
74
|
+
*/
|
|
75
|
+
render(): this;
|
|
76
|
+
/**
|
|
77
|
+
* Sorts the content by the specified fields and orders.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const client = new DotCMSClient(config);
|
|
82
|
+
* const collectionBuilder = client.content.getCollection("Blog");
|
|
83
|
+
* const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }];
|
|
84
|
+
* collectionBuilder("Blog").sortBy(sortBy);
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @param {SortBy[]} sortBy Array of constraints to sort the content by.
|
|
88
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
89
|
+
* @memberof CollectionBuilder
|
|
90
|
+
*/
|
|
91
|
+
sortBy(sortBy: SortBy[]): this;
|
|
92
|
+
/**
|
|
93
|
+
* Sets the maximum amount of content to fetch.
|
|
94
|
+
*
|
|
95
|
+
* @param {number} limit The maximum amount of content to fetch.
|
|
96
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
97
|
+
* @memberof CollectionBuilder
|
|
98
|
+
*/
|
|
99
|
+
limit(limit: number): this;
|
|
100
|
+
/**
|
|
101
|
+
* Sets the page number to fetch.
|
|
102
|
+
*
|
|
103
|
+
* @param {number} page The page number to fetch.
|
|
104
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
105
|
+
* @memberof CollectionBuilder
|
|
106
|
+
*/
|
|
107
|
+
page(page: number): this;
|
|
108
|
+
/**
|
|
109
|
+
* Filters the content by a Lucene query string.
|
|
110
|
+
*
|
|
111
|
+
* @param {string} query A Lucene query string.
|
|
112
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
113
|
+
* @memberof CollectionBuilder
|
|
114
|
+
*/
|
|
115
|
+
query(query: string): this;
|
|
116
|
+
/**
|
|
117
|
+
* Filters the content by building a query using a QueryBuilder function.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const client = new DotCMSClient(config);
|
|
122
|
+
* const collectionBuilder = client.content.getCollection("Blog");
|
|
123
|
+
* collectionBuilder.query((queryBuilder) =>
|
|
124
|
+
* queryBuilder.field('title').equals('Hello World').or().equals('Hello World 2')
|
|
125
|
+
* );
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @param {BuildQuery} buildQuery A function that receives a QueryBuilder instance and returns a valid query.
|
|
129
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
130
|
+
* @memberof CollectionBuilder
|
|
131
|
+
*/
|
|
132
|
+
query(buildQuery: BuildQuery): this;
|
|
133
|
+
/**
|
|
134
|
+
* Retrieves draft content.
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const client = new DotCMSClient(config);
|
|
138
|
+
* const collectionBuilder = client.content.getCollection("Blog");
|
|
139
|
+
* collectionBuilder
|
|
140
|
+
* .draft() // This will retrieve draft/working content
|
|
141
|
+
* .then((response) => // Your code here })
|
|
142
|
+
* .catch((error) => // Your code here })
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
146
|
+
* @memberof CollectionBuilder
|
|
147
|
+
*/
|
|
148
|
+
draft(): this;
|
|
149
|
+
/**
|
|
150
|
+
* Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
|
|
151
|
+
*
|
|
152
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const client = new DotCMSClient(config);
|
|
157
|
+
* const collectionBuilder = client.content.getCollection("Blog");
|
|
158
|
+
* collectionBuilder
|
|
159
|
+
* .variant("YOUR_VARIANT_ID")
|
|
160
|
+
* .then((response) => // Your code here })
|
|
161
|
+
* .catch((error) => // Your code here })
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @param {string} variantId A string that represents a variant ID.
|
|
165
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
166
|
+
* @memberof CollectionBuilder
|
|
167
|
+
*/
|
|
168
|
+
variant(variantId: string): this;
|
|
169
|
+
/**
|
|
170
|
+
* Sets the depth of the relationships of the content.
|
|
171
|
+
* Specifies the depth of related content to return in the results.
|
|
172
|
+
*
|
|
173
|
+
* More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const client = new DotCMSClient(config);
|
|
178
|
+
* const collectionBuilder = client.content.getCollection("Blog");
|
|
179
|
+
* collectionBuilder
|
|
180
|
+
* .depth(1)
|
|
181
|
+
* .then((response) => // Your code here })
|
|
182
|
+
* .catch((error) => // Your code here })
|
|
183
|
+
* ```
|
|
184
|
+
*
|
|
185
|
+
* @param {number} depth The depth of the relationships of the content.
|
|
186
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
187
|
+
* @memberof CollectionBuilder
|
|
188
|
+
*/
|
|
189
|
+
depth(depth: number): this;
|
|
190
|
+
/**
|
|
191
|
+
* Executes the fetch and returns a promise that resolves to the content or rejects with an error.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const client = new DotCMSClient(config);
|
|
196
|
+
* const collectionBuilder = client.content.getCollection("Blog");
|
|
197
|
+
* collectionBuilder
|
|
198
|
+
* .limit(10)
|
|
199
|
+
* .then((response) => // Your code here })
|
|
200
|
+
* .catch((error) => // Your code here })
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful.
|
|
204
|
+
* @param {OnRejected} [onrejected] A callback that is called when the fetch fails.
|
|
205
|
+
* @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects with an error.
|
|
206
|
+
* @memberof CollectionBuilder
|
|
207
|
+
*/
|
|
208
|
+
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | GetCollectionError>;
|
|
209
|
+
/**
|
|
210
|
+
* Formats the response to the desired format.
|
|
211
|
+
*
|
|
212
|
+
* @private
|
|
213
|
+
* @param {GetCollectionRawResponse<T>} data The raw response data.
|
|
214
|
+
* @return {GetCollectionResponse<T>} The formatted response.
|
|
215
|
+
* @memberof CollectionBuilder
|
|
216
|
+
*/
|
|
217
|
+
private formatResponse;
|
|
218
|
+
/**
|
|
219
|
+
* Calls the content API to fetch the content.
|
|
220
|
+
*
|
|
221
|
+
* @private
|
|
222
|
+
* @return {Promise<Response>} The fetch response.
|
|
223
|
+
* @memberof CollectionBuilder
|
|
224
|
+
*/
|
|
225
|
+
private fetch;
|
|
226
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { CollectionBuilder } from './builders/collection/collection';
|
|
2
|
+
import { ClientOptions } from '../sdk-js-client';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a builder to filter and fetch a collection of content items.
|
|
5
|
+
* @param contentType - The content type to retrieve.
|
|
6
|
+
* @returns A CollectionBuilder instance for chaining filters and executing the query.
|
|
7
|
+
* @template T - The type of the content items (defaults to unknown).
|
|
8
|
+
*
|
|
9
|
+
* @example Fetch blog posts with async/await
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const response = await client.content
|
|
12
|
+
* .getCollection<BlogPost>('Blog')
|
|
13
|
+
* .limit(10)
|
|
14
|
+
* .page(2)
|
|
15
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
16
|
+
* .query(q => q.field('author').equals('John Doe'))
|
|
17
|
+
* .depth(1)
|
|
18
|
+
* .fetch();
|
|
19
|
+
*
|
|
20
|
+
* console.log(response.contentlets);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Fetch blog posts with Promise chain
|
|
24
|
+
* ```typescript
|
|
25
|
+
* client.content
|
|
26
|
+
* .getCollection<BlogPost>('Blog')
|
|
27
|
+
* .limit(10)
|
|
28
|
+
* .page(2)
|
|
29
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
30
|
+
* .query(q => q.field('author').equals('John Doe'))
|
|
31
|
+
* .depth(1)
|
|
32
|
+
* .fetch()
|
|
33
|
+
* .then(response => console.log(response.contentlets))
|
|
34
|
+
* .catch(error => console.error(error));
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Using a custom type
|
|
38
|
+
* ```typescript
|
|
39
|
+
* interface BlogPost {
|
|
40
|
+
* summary: string;
|
|
41
|
+
* author: string;
|
|
42
|
+
* title: string;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* const posts = await client.content
|
|
46
|
+
* .getCollection<BlogPost>('Blog')
|
|
47
|
+
* .limit(10)
|
|
48
|
+
* .fetch();
|
|
49
|
+
*
|
|
50
|
+
* posts.contentlets.forEach(post => {
|
|
51
|
+
* console.log(post.title, post.author, post.summary);
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare class Content {
|
|
56
|
+
#private;
|
|
57
|
+
/**
|
|
58
|
+
* Creates an instance of Content.
|
|
59
|
+
* @param {ClientOptions} requestOptions - The options for the client request.
|
|
60
|
+
* @param {string} serverUrl - The server URL.
|
|
61
|
+
*/
|
|
62
|
+
constructor(requestOptions: ClientOptions, serverUrl: string);
|
|
63
|
+
/**
|
|
64
|
+
* Takes a content type and returns a builder to filter and fetch the collection.
|
|
65
|
+
* @param {string} contentType - The content type to get the collection.
|
|
66
|
+
* @return {CollectionBuilder<T>} CollectionBuilder to filter and fetch the collection.
|
|
67
|
+
* @template T - Represents the type of the content type to fetch. Defaults to unknown.
|
|
68
|
+
* @memberof Content
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```javascript
|
|
72
|
+
* // Using await and async
|
|
73
|
+
* const collectionResponse = await client.content
|
|
74
|
+
* .getCollection('Blog')
|
|
75
|
+
* .limit(10)
|
|
76
|
+
* .page(2)
|
|
77
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
78
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
79
|
+
* .depth(1);
|
|
80
|
+
* ```
|
|
81
|
+
* @example
|
|
82
|
+
* ```javascript
|
|
83
|
+
* // Using then and catch
|
|
84
|
+
* client.content
|
|
85
|
+
* .getCollection('Blog')
|
|
86
|
+
* .limit(10)
|
|
87
|
+
* .page(2)
|
|
88
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
89
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
90
|
+
* .depth(1)
|
|
91
|
+
* .then((response) => {
|
|
92
|
+
* console.log(response.contentlets);
|
|
93
|
+
* })
|
|
94
|
+
* .catch((error) => {
|
|
95
|
+
* console.error(error);
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Using a specific type for your content
|
|
101
|
+
*
|
|
102
|
+
* type Blog = {
|
|
103
|
+
* summary: string;
|
|
104
|
+
* author: string;
|
|
105
|
+
* title: string;
|
|
106
|
+
* };
|
|
107
|
+
*
|
|
108
|
+
* client.content
|
|
109
|
+
* .getCollection<Blog>('Blog')
|
|
110
|
+
* .limit(10)
|
|
111
|
+
* .page(2)
|
|
112
|
+
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
113
|
+
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
114
|
+
* .depth(1)
|
|
115
|
+
* .then((response) => {
|
|
116
|
+
* response.contentlets.forEach((blog) => {
|
|
117
|
+
* console.log(blog.title);
|
|
118
|
+
* console.log(blog.author);
|
|
119
|
+
* console.log(blog.summary);
|
|
120
|
+
* });
|
|
121
|
+
* })
|
|
122
|
+
* .catch((error) => {
|
|
123
|
+
* console.error(error);
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
*/
|
|
128
|
+
getCollection<T = unknown>(contentType: string): CollectionBuilder<T>;
|
|
129
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default variant identifier used in the application.
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_VARIANT_ID = "DEFAULT";
|
|
5
|
+
/**
|
|
6
|
+
* Fields that should not be formatted when sanitizing the query.
|
|
7
|
+
* These fields are essential for maintaining the integrity of the content type.
|
|
8
|
+
*/
|
|
9
|
+
export declare const CONTENT_TYPE_MAIN_FIELDS: string[];
|
|
10
|
+
/**
|
|
11
|
+
* URL endpoint for the content API search functionality.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CONTENT_API_URL = "/api/content/_search";
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Equals } from '../../../query-builder/lucene-syntax';
|
|
2
|
+
import { QueryBuilder } from '../../../query-builder/sdk-query-builder';
|
|
3
|
+
/**
|
|
4
|
+
* Model to sort by fields.
|
|
5
|
+
*/
|
|
6
|
+
export type SortBy = {
|
|
7
|
+
/**
|
|
8
|
+
* The field to sort by.
|
|
9
|
+
*/
|
|
10
|
+
field: string;
|
|
11
|
+
/**
|
|
12
|
+
* The order of sorting: 'asc' for ascending, 'desc' for descending.
|
|
13
|
+
*/
|
|
14
|
+
order: 'asc' | 'desc';
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Callback to build a query.
|
|
18
|
+
*
|
|
19
|
+
* @callback BuildQuery
|
|
20
|
+
* @param {QueryBuilder} qb - The query builder instance.
|
|
21
|
+
* @returns {Equals} The built query.
|
|
22
|
+
*/
|
|
23
|
+
export type BuildQuery = (qb: QueryBuilder) => Equals;
|
|
24
|
+
/**
|
|
25
|
+
* Main fields of a Contentlet (Inherited from the Content Type).
|
|
26
|
+
*/
|
|
27
|
+
export interface ContentTypeMainFields {
|
|
28
|
+
hostName: string;
|
|
29
|
+
modDate: string;
|
|
30
|
+
publishDate: string;
|
|
31
|
+
title: string;
|
|
32
|
+
baseType: string;
|
|
33
|
+
inode: string;
|
|
34
|
+
archived: boolean;
|
|
35
|
+
ownerName: string;
|
|
36
|
+
host: string;
|
|
37
|
+
working: boolean;
|
|
38
|
+
locked: boolean;
|
|
39
|
+
stInode: string;
|
|
40
|
+
contentType: string;
|
|
41
|
+
live: boolean;
|
|
42
|
+
owner: string;
|
|
43
|
+
identifier: string;
|
|
44
|
+
publishUserName: string;
|
|
45
|
+
publishUser: string;
|
|
46
|
+
languageId: number;
|
|
47
|
+
creationDate: string;
|
|
48
|
+
url: string;
|
|
49
|
+
titleImage: string;
|
|
50
|
+
modUserName: string;
|
|
51
|
+
hasLiveVersion: boolean;
|
|
52
|
+
folder: string;
|
|
53
|
+
hasTitleImage: boolean;
|
|
54
|
+
sortOrder: number;
|
|
55
|
+
modUser: string;
|
|
56
|
+
__icon__: string;
|
|
57
|
+
contentTypeIcon: string;
|
|
58
|
+
variant: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The contentlet has the main fields and the custom fields of the content type.
|
|
62
|
+
*
|
|
63
|
+
* @template T - The custom fields of the content type.
|
|
64
|
+
*/
|
|
65
|
+
export type Contentlet<T> = T & ContentTypeMainFields;
|
|
66
|
+
/**
|
|
67
|
+
* Callback for a fulfilled promise.
|
|
68
|
+
*
|
|
69
|
+
* @template T - The type of the response.
|
|
70
|
+
* @callback OnFullfilled
|
|
71
|
+
* @param {GetCollectionResponse<T>} value - The response value.
|
|
72
|
+
* @returns {GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void} The processed response or a promise.
|
|
73
|
+
*/
|
|
74
|
+
export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void) | undefined | null;
|
|
75
|
+
/**
|
|
76
|
+
* Callback for a rejected promise.
|
|
77
|
+
*
|
|
78
|
+
* @callback OnRejected
|
|
79
|
+
* @param {GetCollectionError} error - The error object.
|
|
80
|
+
* @returns {GetCollectionError | PromiseLike<GetCollectionError> | void} The processed error or a promise.
|
|
81
|
+
*/
|
|
82
|
+
export type OnRejected = ((error: GetCollectionError) => GetCollectionError | PromiseLike<GetCollectionError> | void) | undefined | null;
|
|
83
|
+
/**
|
|
84
|
+
* Response of the get collection method.
|
|
85
|
+
*
|
|
86
|
+
* @template T - The type of the contentlet.
|
|
87
|
+
*/
|
|
88
|
+
export interface GetCollectionResponse<T> {
|
|
89
|
+
/**
|
|
90
|
+
* The list of contentlets.
|
|
91
|
+
*/
|
|
92
|
+
contentlets: Contentlet<T>[];
|
|
93
|
+
/**
|
|
94
|
+
* The current page number.
|
|
95
|
+
*/
|
|
96
|
+
page: number;
|
|
97
|
+
/**
|
|
98
|
+
* The size of the page.
|
|
99
|
+
*/
|
|
100
|
+
size: number;
|
|
101
|
+
/**
|
|
102
|
+
* The total number of contentlets.
|
|
103
|
+
*/
|
|
104
|
+
total: number;
|
|
105
|
+
/**
|
|
106
|
+
* The fields by which the contentlets are sorted.
|
|
107
|
+
*/
|
|
108
|
+
sortedBy?: SortBy[];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Raw response of the get collection method.
|
|
112
|
+
*
|
|
113
|
+
* @template T - The type of the contentlet.
|
|
114
|
+
*/
|
|
115
|
+
export interface GetCollectionRawResponse<T> {
|
|
116
|
+
entity: {
|
|
117
|
+
jsonObjectView: {
|
|
118
|
+
/**
|
|
119
|
+
* The list of contentlets.
|
|
120
|
+
*/
|
|
121
|
+
contentlets: Contentlet<T>[];
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* The size of the results.
|
|
125
|
+
*/
|
|
126
|
+
resultsSize: number;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Error object for the get collection method.
|
|
131
|
+
*/
|
|
132
|
+
export interface GetCollectionError {
|
|
133
|
+
/**
|
|
134
|
+
* The status code of the error.
|
|
135
|
+
*/
|
|
136
|
+
status: number;
|
|
137
|
+
[key: string]: unknown;
|
|
138
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* Sanitizes the query for the given content type.
|
|
4
|
+
* It replaces the fields that are not content type fields with the correct format.
|
|
5
|
+
* Example: +field: -> +contentTypeVar.field:
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const query = '+field: value';
|
|
11
|
+
* const contentType = 'contentTypeVar';
|
|
12
|
+
* const sanitizedQuery = sanitizeQueryForContentType(query, contentType); // Output: '+contentTypeVar.field: value'
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @export
|
|
16
|
+
* @param {string} query - The query string to be sanitized.
|
|
17
|
+
* @param {string} contentType - The content type to be used for formatting the fields.
|
|
18
|
+
* @returns {string} The sanitized query string.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sanitizeQueryForContentType(query: string, contentType: string): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A record of HTTP status codes and their corresponding error messages.
|
|
3
|
+
*
|
|
4
|
+
* @type {Record<number, string>}
|
|
5
|
+
* @property {string} 401 - Unauthorized. Check the token and try again.
|
|
6
|
+
* @property {string} 403 - Forbidden. Check the permissions and try again.
|
|
7
|
+
* @property {string} 404 - Not Found. Check the URL and try again.
|
|
8
|
+
* @property {string} 500 - Internal Server Error. Try again later.
|
|
9
|
+
* @property {string} 502 - Bad Gateway. Try again later.
|
|
10
|
+
* @property {string} 503 - Service Unavailable. Try again later.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ErrorMessages: Record<number, string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a listener for DotcmsClientListener.
|
|
3
|
+
*
|
|
4
|
+
* @typedef {Object} DotcmsClientListener
|
|
5
|
+
* @property {string} action - The action that triggers the event.
|
|
6
|
+
* @property {string} event - The name of the event.
|
|
7
|
+
* @property {function(...args: any[]): void} callback - The callback function to handle the event.
|
|
8
|
+
*/
|
|
9
|
+
export type DotcmsClientListener = {
|
|
10
|
+
action: string;
|
|
11
|
+
event: string;
|
|
12
|
+
callback: (...args: any[]) => void;
|
|
13
|
+
};
|