@dotcms/client 0.0.1-alpha.40 → 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/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 +16 -4
- package/src/index.d.ts +6 -0
- package/src/lib/client/content/builders/collection/{collection.ts → collection.d.ts} +19 -209
- package/src/lib/client/content/{content-api.ts → content-api.d.ts} +4 -14
- package/src/lib/client/content/shared/{const.ts → const.d.ts} +3 -5
- package/src/lib/client/content/shared/{types.ts → types.d.ts} +2 -19
- package/src/lib/client/content/shared/{utils.ts → utils.d.ts} +1 -9
- package/src/lib/client/models/{index.ts → index.d.ts} +1 -8
- package/src/lib/client/models/{types.ts → types.d.ts} +0 -1
- package/src/lib/client/{sdk-js-client.ts → sdk-js-client.d.ts} +15 -181
- package/src/lib/editor/listeners/listeners.d.ts +50 -0
- package/src/lib/editor/models/{client.model.ts → client.model.d.ts} +16 -19
- package/src/lib/editor/models/{editor.model.ts → editor.model.d.ts} +5 -9
- package/src/lib/editor/models/{listeners.model.ts → listeners.model.d.ts} +6 -9
- 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.ts → editor.utils.d.ts} +22 -121
- package/src/lib/query-builder/lucene-syntax/{Equals.ts → Equals.d.ts} +11 -45
- package/src/lib/query-builder/lucene-syntax/{Field.ts → Field.d.ts} +5 -13
- package/src/lib/query-builder/lucene-syntax/{NotOperand.ts → NotOperand.d.ts} +5 -13
- package/src/lib/query-builder/lucene-syntax/{Operand.ts → Operand.d.ts} +7 -21
- package/src/lib/query-builder/{sdk-query-builder.ts → sdk-query-builder.d.ts} +5 -16
- package/src/lib/query-builder/utils/{index.ts → index.d.ts} +12 -49
- package/src/lib/utils/graphql/transforms.d.ts +24 -0
- package/src/lib/utils/page/common-utils.d.ts +33 -0
- package/.eslintrc.json +0 -18
- package/jest.config.ts +0 -15
- package/project.json +0 -72
- package/src/index.ts +0 -30
- package/src/lib/client/content/builders/collection/collection.spec.ts +0 -515
- package/src/lib/client/sdk-js-client.spec.ts +0 -483
- package/src/lib/editor/listeners/listeners.spec.ts +0 -119
- package/src/lib/editor/listeners/listeners.ts +0 -223
- package/src/lib/editor/sdk-editor-vtl.ts +0 -31
- package/src/lib/editor/sdk-editor.spec.ts +0 -116
- package/src/lib/editor/sdk-editor.ts +0 -105
- package/src/lib/editor/utils/editor.utils.spec.ts +0 -206
- package/src/lib/query-builder/sdk-query-builder.spec.ts +0 -159
- package/src/lib/utils/graphql/transforms.spec.ts +0 -150
- package/src/lib/utils/graphql/transforms.ts +0 -99
- package/src/lib/utils/page/common-utils.spec.ts +0 -37
- package/src/lib/utils/page/common-utils.ts +0 -64
- package/tsconfig.json +0 -22
- package/tsconfig.lib.json +0 -13
- package/tsconfig.spec.json +0 -9
- /package/src/lib/query-builder/lucene-syntax/{index.ts → index.d.ts} +0 -0
- /package/src/lib/utils/{index.ts → index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotcms/client",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.41",
|
|
4
4
|
"description": "Official JavaScript library for interacting with DotCMS REST APIs.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/dotCMS/core.git#
|
|
7
|
+
"url": "git+https://github.com/dotCMS/core.git#main"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
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"
|
|
@@ -21,5 +21,17 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/dotCMS/core/issues"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://github.com/dotCMS/core/tree/
|
|
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
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
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 };
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import { Equals } from '../../../../query-builder/lucene-syntax';
|
|
2
|
-
import { QueryBuilder } from '../../../../query-builder/sdk-query-builder';
|
|
3
1
|
import { ClientOptions } from '../../../sdk-js-client';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
GetCollectionResponse,
|
|
7
|
-
BuildQuery,
|
|
8
|
-
SortBy,
|
|
9
|
-
GetCollectionRawResponse,
|
|
10
|
-
GetCollectionError,
|
|
11
|
-
OnFullfilled,
|
|
12
|
-
OnRejected
|
|
13
|
-
} from '../../shared/types';
|
|
14
|
-
import { sanitizeQueryForContentType } from '../../shared/utils';
|
|
15
|
-
|
|
2
|
+
import { GetCollectionResponse, BuildQuery, SortBy, GetCollectionError, OnFullfilled, OnRejected } from '../../shared/types';
|
|
16
3
|
/**
|
|
17
4
|
* Creates a Builder to filter and fetch content from the content API for a specific content type.
|
|
18
5
|
*
|
|
@@ -20,22 +7,8 @@ import { sanitizeQueryForContentType } from '../../shared/utils';
|
|
|
20
7
|
* @class CollectionBuilder
|
|
21
8
|
* @template T Represents the type of the content type to fetch. Defaults to unknown.
|
|
22
9
|
*/
|
|
23
|
-
export class CollectionBuilder<T = unknown> {
|
|
24
|
-
#
|
|
25
|
-
#limit = 10;
|
|
26
|
-
#depth = 0;
|
|
27
|
-
#render = false;
|
|
28
|
-
#sortBy?: SortBy[];
|
|
29
|
-
#contentType: string;
|
|
30
|
-
#defaultQuery: Equals;
|
|
31
|
-
#query?: Equals;
|
|
32
|
-
#rawQuery?: string;
|
|
33
|
-
#languageId: number | string = 1;
|
|
34
|
-
#draft = false;
|
|
35
|
-
|
|
36
|
-
#serverUrl: string;
|
|
37
|
-
#requestOptions: ClientOptions;
|
|
38
|
-
|
|
10
|
+
export declare class CollectionBuilder<T = unknown> {
|
|
11
|
+
#private;
|
|
39
12
|
/**
|
|
40
13
|
* Creates an instance of CollectionBuilder.
|
|
41
14
|
* @param {ClientOptions} requestOptions Options for the client request.
|
|
@@ -43,15 +16,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
43
16
|
* @param {string} contentType The content type to fetch.
|
|
44
17
|
* @memberof CollectionBuilder
|
|
45
18
|
*/
|
|
46
|
-
constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string)
|
|
47
|
-
this.#requestOptions = requestOptions;
|
|
48
|
-
this.#serverUrl = serverUrl;
|
|
49
|
-
this.#contentType = contentType;
|
|
50
|
-
|
|
51
|
-
// Build the default query with the contentType field
|
|
52
|
-
this.#defaultQuery = new QueryBuilder().field('contentType').equals(this.#contentType);
|
|
53
|
-
}
|
|
54
|
-
|
|
19
|
+
constructor(requestOptions: ClientOptions, serverUrl: string, contentType: string);
|
|
55
20
|
/**
|
|
56
21
|
* Returns the sort query in the format: field order, field order, ...
|
|
57
22
|
*
|
|
@@ -59,10 +24,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
59
24
|
* @private
|
|
60
25
|
* @memberof CollectionBuilder
|
|
61
26
|
*/
|
|
62
|
-
private get sort()
|
|
63
|
-
return this.#sortBy?.map((sort) => `${sort.field} ${sort.order}`).join(',');
|
|
64
|
-
}
|
|
65
|
-
|
|
27
|
+
private get sort();
|
|
66
28
|
/**
|
|
67
29
|
* Returns the offset for pagination.
|
|
68
30
|
*
|
|
@@ -70,10 +32,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
70
32
|
* @private
|
|
71
33
|
* @memberof CollectionBuilder
|
|
72
34
|
*/
|
|
73
|
-
private get offset()
|
|
74
|
-
return this.#limit * (this.#page - 1);
|
|
75
|
-
}
|
|
76
|
-
|
|
35
|
+
private get offset();
|
|
77
36
|
/**
|
|
78
37
|
* Returns the full URL for the content API.
|
|
79
38
|
*
|
|
@@ -81,10 +40,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
81
40
|
* @private
|
|
82
41
|
* @memberof CollectionBuilder
|
|
83
42
|
*/
|
|
84
|
-
private get url()
|
|
85
|
-
return `${this.#serverUrl}${CONTENT_API_URL}`;
|
|
86
|
-
}
|
|
87
|
-
|
|
43
|
+
private get url();
|
|
88
44
|
/**
|
|
89
45
|
* Returns the current query built.
|
|
90
46
|
*
|
|
@@ -92,10 +48,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
92
48
|
* @private
|
|
93
49
|
* @memberof CollectionBuilder
|
|
94
50
|
*/
|
|
95
|
-
private get currentQuery()
|
|
96
|
-
return this.#query ?? this.#defaultQuery;
|
|
97
|
-
}
|
|
98
|
-
|
|
51
|
+
private get currentQuery();
|
|
99
52
|
/**
|
|
100
53
|
* Filters the content by the specified language ID.
|
|
101
54
|
*
|
|
@@ -110,12 +63,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
110
63
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
111
64
|
* @memberof CollectionBuilder
|
|
112
65
|
*/
|
|
113
|
-
language(languageId: number | string): this
|
|
114
|
-
this.#languageId = languageId;
|
|
115
|
-
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
|
|
66
|
+
language(languageId: number | string): this;
|
|
119
67
|
/**
|
|
120
68
|
* Setting this to true will server side render (using velocity) any widgets that are returned by the content query.
|
|
121
69
|
*
|
|
@@ -124,12 +72,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
124
72
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
125
73
|
* @memberof CollectionBuilder
|
|
126
74
|
*/
|
|
127
|
-
render(): this
|
|
128
|
-
this.#render = true;
|
|
129
|
-
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
|
|
75
|
+
render(): this;
|
|
133
76
|
/**
|
|
134
77
|
* Sorts the content by the specified fields and orders.
|
|
135
78
|
*
|
|
@@ -145,12 +88,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
145
88
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
146
89
|
* @memberof CollectionBuilder
|
|
147
90
|
*/
|
|
148
|
-
sortBy(sortBy: SortBy[]): this
|
|
149
|
-
this.#sortBy = sortBy;
|
|
150
|
-
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
|
|
91
|
+
sortBy(sortBy: SortBy[]): this;
|
|
154
92
|
/**
|
|
155
93
|
* Sets the maximum amount of content to fetch.
|
|
156
94
|
*
|
|
@@ -158,12 +96,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
158
96
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
159
97
|
* @memberof CollectionBuilder
|
|
160
98
|
*/
|
|
161
|
-
limit(limit: number): this
|
|
162
|
-
this.#limit = limit;
|
|
163
|
-
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
|
|
99
|
+
limit(limit: number): this;
|
|
167
100
|
/**
|
|
168
101
|
* Sets the page number to fetch.
|
|
169
102
|
*
|
|
@@ -171,12 +104,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
171
104
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
172
105
|
* @memberof CollectionBuilder
|
|
173
106
|
*/
|
|
174
|
-
page(page: number): this
|
|
175
|
-
this.#page = page;
|
|
176
|
-
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
|
|
107
|
+
page(page: number): this;
|
|
180
108
|
/**
|
|
181
109
|
* Filters the content by a Lucene query string.
|
|
182
110
|
*
|
|
@@ -185,7 +113,6 @@ export class CollectionBuilder<T = unknown> {
|
|
|
185
113
|
* @memberof CollectionBuilder
|
|
186
114
|
*/
|
|
187
115
|
query(query: string): this;
|
|
188
|
-
|
|
189
116
|
/**
|
|
190
117
|
* Filters the content by building a query using a QueryBuilder function.
|
|
191
118
|
*
|
|
@@ -203,33 +130,6 @@ export class CollectionBuilder<T = unknown> {
|
|
|
203
130
|
* @memberof CollectionBuilder
|
|
204
131
|
*/
|
|
205
132
|
query(buildQuery: BuildQuery): this;
|
|
206
|
-
query(arg: unknown): this {
|
|
207
|
-
if (typeof arg === 'string') {
|
|
208
|
-
this.#rawQuery = arg;
|
|
209
|
-
|
|
210
|
-
return this;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (typeof arg !== 'function') {
|
|
214
|
-
throw new Error(
|
|
215
|
-
`Parameter for query method should be a buildQuery function or a string.\nExample:\nclient.content.getCollection('Activity').query((queryBuilder) => queryBuilder.field('title').equals('Hello World'))\nor\nclient.content.getCollection('Activity').query('+Activity.title:"Hello World"') \nSee documentation for more information.`
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const builtQuery = arg(new QueryBuilder());
|
|
220
|
-
|
|
221
|
-
// This can be use in Javascript so we cannot rely on the type checking
|
|
222
|
-
if (builtQuery instanceof Equals) {
|
|
223
|
-
this.#query = builtQuery.raw(this.currentQuery.build());
|
|
224
|
-
} else {
|
|
225
|
-
throw new Error(
|
|
226
|
-
'Provided query is not valid. A query should end in an equals method call.\nExample:\n(queryBuilder) => queryBuilder.field("title").equals("Hello World")\nSee documentation for more information.'
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
133
|
/**
|
|
234
134
|
* Retrieves draft content.
|
|
235
135
|
* @example
|
|
@@ -245,12 +145,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
245
145
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
246
146
|
* @memberof CollectionBuilder
|
|
247
147
|
*/
|
|
248
|
-
draft(): this
|
|
249
|
-
this.#draft = true;
|
|
250
|
-
|
|
251
|
-
return this;
|
|
252
|
-
}
|
|
253
|
-
|
|
148
|
+
draft(): this;
|
|
254
149
|
/**
|
|
255
150
|
* Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
|
|
256
151
|
*
|
|
@@ -270,12 +165,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
270
165
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
271
166
|
* @memberof CollectionBuilder
|
|
272
167
|
*/
|
|
273
|
-
variant(variantId: string): this
|
|
274
|
-
this.#query = this.currentQuery.field('variant').equals(variantId);
|
|
275
|
-
|
|
276
|
-
return this;
|
|
277
|
-
}
|
|
278
|
-
|
|
168
|
+
variant(variantId: string): this;
|
|
279
169
|
/**
|
|
280
170
|
* Sets the depth of the relationships of the content.
|
|
281
171
|
* Specifies the depth of related content to return in the results.
|
|
@@ -296,16 +186,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
296
186
|
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
297
187
|
* @memberof CollectionBuilder
|
|
298
188
|
*/
|
|
299
|
-
depth(depth: number): this
|
|
300
|
-
if (depth < 0 || depth > 3) {
|
|
301
|
-
throw new Error('Depth value must be between 0 and 3');
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
this.#depth = depth;
|
|
305
|
-
|
|
306
|
-
return this;
|
|
307
|
-
}
|
|
308
|
-
|
|
189
|
+
depth(depth: number): this;
|
|
309
190
|
/**
|
|
310
191
|
* Executes the fetch and returns a promise that resolves to the content or rejects with an error.
|
|
311
192
|
*
|
|
@@ -324,30 +205,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
324
205
|
* @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects with an error.
|
|
325
206
|
* @memberof CollectionBuilder
|
|
326
207
|
*/
|
|
327
|
-
then(
|
|
328
|
-
onfulfilled?: OnFullfilled<T>,
|
|
329
|
-
onrejected?: OnRejected
|
|
330
|
-
): Promise<GetCollectionResponse<T> | GetCollectionError> {
|
|
331
|
-
return this.fetch().then(async (response) => {
|
|
332
|
-
const data = await response.json();
|
|
333
|
-
if (response.ok) {
|
|
334
|
-
const formattedResponse = this.formatResponse<T>(data);
|
|
335
|
-
|
|
336
|
-
const finalResponse =
|
|
337
|
-
typeof onfulfilled === 'function'
|
|
338
|
-
? onfulfilled(formattedResponse)
|
|
339
|
-
: formattedResponse;
|
|
340
|
-
|
|
341
|
-
return finalResponse;
|
|
342
|
-
} else {
|
|
343
|
-
return {
|
|
344
|
-
status: response.status,
|
|
345
|
-
...data
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
}, onrejected);
|
|
349
|
-
}
|
|
350
|
-
|
|
208
|
+
then(onfulfilled?: OnFullfilled<T>, onrejected?: OnRejected): Promise<GetCollectionResponse<T> | GetCollectionError>;
|
|
351
209
|
/**
|
|
352
210
|
* Formats the response to the desired format.
|
|
353
211
|
*
|
|
@@ -356,25 +214,7 @@ export class CollectionBuilder<T = unknown> {
|
|
|
356
214
|
* @return {GetCollectionResponse<T>} The formatted response.
|
|
357
215
|
* @memberof CollectionBuilder
|
|
358
216
|
*/
|
|
359
|
-
private formatResponse
|
|
360
|
-
const contentlets = data.entity.jsonObjectView.contentlets;
|
|
361
|
-
const total = data.entity.resultsSize;
|
|
362
|
-
|
|
363
|
-
const mappedResponse: GetCollectionResponse<T> = {
|
|
364
|
-
contentlets,
|
|
365
|
-
total,
|
|
366
|
-
page: this.#page,
|
|
367
|
-
size: contentlets.length
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
return this.#sortBy
|
|
371
|
-
? {
|
|
372
|
-
...mappedResponse,
|
|
373
|
-
sortedBy: this.#sortBy
|
|
374
|
-
}
|
|
375
|
-
: mappedResponse;
|
|
376
|
-
}
|
|
377
|
-
|
|
217
|
+
private formatResponse;
|
|
378
218
|
/**
|
|
379
219
|
* Calls the content API to fetch the content.
|
|
380
220
|
*
|
|
@@ -382,35 +222,5 @@ export class CollectionBuilder<T = unknown> {
|
|
|
382
222
|
* @return {Promise<Response>} The fetch response.
|
|
383
223
|
* @memberof CollectionBuilder
|
|
384
224
|
*/
|
|
385
|
-
private fetch
|
|
386
|
-
const finalQuery = this.currentQuery
|
|
387
|
-
.field('languageId')
|
|
388
|
-
.equals(this.#languageId.toString())
|
|
389
|
-
.field('live')
|
|
390
|
-
.equals((!this.#draft).toString())
|
|
391
|
-
.build();
|
|
392
|
-
|
|
393
|
-
const sanitizedQuery = sanitizeQueryForContentType(finalQuery, this.#contentType);
|
|
394
|
-
|
|
395
|
-
const query = this.#rawQuery ? `${sanitizedQuery} ${this.#rawQuery}` : sanitizedQuery;
|
|
396
|
-
|
|
397
|
-
return fetch(this.url, {
|
|
398
|
-
...this.#requestOptions,
|
|
399
|
-
method: 'POST',
|
|
400
|
-
headers: {
|
|
401
|
-
...this.#requestOptions.headers,
|
|
402
|
-
'Content-Type': 'application/json'
|
|
403
|
-
},
|
|
404
|
-
body: JSON.stringify({
|
|
405
|
-
query,
|
|
406
|
-
render: this.#render,
|
|
407
|
-
sort: this.sort,
|
|
408
|
-
limit: this.#limit,
|
|
409
|
-
offset: this.offset,
|
|
410
|
-
depth: this.#depth
|
|
411
|
-
//userId: This exist but we currently don't use it
|
|
412
|
-
//allCategoriesInfo: This exist but we currently don't use it
|
|
413
|
-
})
|
|
414
|
-
});
|
|
415
|
-
}
|
|
225
|
+
private fetch;
|
|
416
226
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CollectionBuilder } from './builders/collection/collection';
|
|
2
|
-
|
|
3
2
|
import { ClientOptions } from '../sdk-js-client';
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Creates a builder to filter and fetch a collection of content items.
|
|
7
5
|
* @param contentType - The content type to retrieve.
|
|
@@ -54,20 +52,14 @@ import { ClientOptions } from '../sdk-js-client';
|
|
|
54
52
|
* });
|
|
55
53
|
* ```
|
|
56
54
|
*/
|
|
57
|
-
export class Content {
|
|
58
|
-
#
|
|
59
|
-
#serverUrl: string;
|
|
60
|
-
|
|
55
|
+
export declare class Content {
|
|
56
|
+
#private;
|
|
61
57
|
/**
|
|
62
58
|
* Creates an instance of Content.
|
|
63
59
|
* @param {ClientOptions} requestOptions - The options for the client request.
|
|
64
60
|
* @param {string} serverUrl - The server URL.
|
|
65
61
|
*/
|
|
66
|
-
constructor(requestOptions: ClientOptions, serverUrl: string)
|
|
67
|
-
this.#requestOptions = requestOptions;
|
|
68
|
-
this.#serverUrl = serverUrl;
|
|
69
|
-
}
|
|
70
|
-
|
|
62
|
+
constructor(requestOptions: ClientOptions, serverUrl: string);
|
|
71
63
|
/**
|
|
72
64
|
* Takes a content type and returns a builder to filter and fetch the collection.
|
|
73
65
|
* @param {string} contentType - The content type to get the collection.
|
|
@@ -133,7 +125,5 @@ export class Content {
|
|
|
133
125
|
* ```
|
|
134
126
|
*
|
|
135
127
|
*/
|
|
136
|
-
getCollection<T = unknown>(contentType: string): CollectionBuilder<T
|
|
137
|
-
return new CollectionBuilder<T>(this.#requestOptions, this.#serverUrl, contentType);
|
|
138
|
-
}
|
|
128
|
+
getCollection<T = unknown>(contentType: string): CollectionBuilder<T>;
|
|
139
129
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Default variant identifier used in the application.
|
|
3
3
|
*/
|
|
4
|
-
export const DEFAULT_VARIANT_ID =
|
|
5
|
-
|
|
4
|
+
export declare const DEFAULT_VARIANT_ID = "DEFAULT";
|
|
6
5
|
/**
|
|
7
6
|
* Fields that should not be formatted when sanitizing the query.
|
|
8
7
|
* These fields are essential for maintaining the integrity of the content type.
|
|
9
8
|
*/
|
|
10
|
-
export const CONTENT_TYPE_MAIN_FIELDS: string[]
|
|
11
|
-
|
|
9
|
+
export declare const CONTENT_TYPE_MAIN_FIELDS: string[];
|
|
12
10
|
/**
|
|
13
11
|
* URL endpoint for the content API search functionality.
|
|
14
12
|
*/
|
|
15
|
-
export const CONTENT_API_URL =
|
|
13
|
+
export declare const CONTENT_API_URL = "/api/content/_search";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Equals } from '../../../query-builder/lucene-syntax';
|
|
2
2
|
import { QueryBuilder } from '../../../query-builder/sdk-query-builder';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* Model to sort by fields.
|
|
6
5
|
*/
|
|
@@ -14,7 +13,6 @@ export type SortBy = {
|
|
|
14
13
|
*/
|
|
15
14
|
order: 'asc' | 'desc';
|
|
16
15
|
};
|
|
17
|
-
|
|
18
16
|
/**
|
|
19
17
|
* Callback to build a query.
|
|
20
18
|
*
|
|
@@ -23,7 +21,6 @@ export type SortBy = {
|
|
|
23
21
|
* @returns {Equals} The built query.
|
|
24
22
|
*/
|
|
25
23
|
export type BuildQuery = (qb: QueryBuilder) => Equals;
|
|
26
|
-
|
|
27
24
|
/**
|
|
28
25
|
* Main fields of a Contentlet (Inherited from the Content Type).
|
|
29
26
|
*/
|
|
@@ -60,14 +57,12 @@ export interface ContentTypeMainFields {
|
|
|
60
57
|
contentTypeIcon: string;
|
|
61
58
|
variant: string;
|
|
62
59
|
}
|
|
63
|
-
|
|
64
60
|
/**
|
|
65
61
|
* The contentlet has the main fields and the custom fields of the content type.
|
|
66
62
|
*
|
|
67
63
|
* @template T - The custom fields of the content type.
|
|
68
64
|
*/
|
|
69
65
|
export type Contentlet<T> = T & ContentTypeMainFields;
|
|
70
|
-
|
|
71
66
|
/**
|
|
72
67
|
* Callback for a fulfilled promise.
|
|
73
68
|
*
|
|
@@ -76,13 +71,7 @@ export type Contentlet<T> = T & ContentTypeMainFields;
|
|
|
76
71
|
* @param {GetCollectionResponse<T>} value - The response value.
|
|
77
72
|
* @returns {GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void} The processed response or a promise.
|
|
78
73
|
*/
|
|
79
|
-
export type OnFullfilled<T> =
|
|
80
|
-
| ((
|
|
81
|
-
value: GetCollectionResponse<T>
|
|
82
|
-
) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void)
|
|
83
|
-
| undefined
|
|
84
|
-
| null;
|
|
85
|
-
|
|
74
|
+
export type OnFullfilled<T> = ((value: GetCollectionResponse<T>) => GetCollectionResponse<T> | PromiseLike<GetCollectionResponse<T>> | void) | undefined | null;
|
|
86
75
|
/**
|
|
87
76
|
* Callback for a rejected promise.
|
|
88
77
|
*
|
|
@@ -90,11 +79,7 @@ export type OnFullfilled<T> =
|
|
|
90
79
|
* @param {GetCollectionError} error - The error object.
|
|
91
80
|
* @returns {GetCollectionError | PromiseLike<GetCollectionError> | void} The processed error or a promise.
|
|
92
81
|
*/
|
|
93
|
-
export type OnRejected =
|
|
94
|
-
| ((error: GetCollectionError) => GetCollectionError | PromiseLike<GetCollectionError> | void)
|
|
95
|
-
| undefined
|
|
96
|
-
| null;
|
|
97
|
-
|
|
82
|
+
export type OnRejected = ((error: GetCollectionError) => GetCollectionError | PromiseLike<GetCollectionError> | void) | undefined | null;
|
|
98
83
|
/**
|
|
99
84
|
* Response of the get collection method.
|
|
100
85
|
*
|
|
@@ -122,7 +107,6 @@ export interface GetCollectionResponse<T> {
|
|
|
122
107
|
*/
|
|
123
108
|
sortedBy?: SortBy[];
|
|
124
109
|
}
|
|
125
|
-
|
|
126
110
|
/**
|
|
127
111
|
* Raw response of the get collection method.
|
|
128
112
|
*
|
|
@@ -142,7 +126,6 @@ export interface GetCollectionRawResponse<T> {
|
|
|
142
126
|
resultsSize: number;
|
|
143
127
|
};
|
|
144
128
|
}
|
|
145
|
-
|
|
146
129
|
/**
|
|
147
130
|
* Error object for the get collection method.
|
|
148
131
|
*/
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { CONTENT_TYPE_MAIN_FIELDS } from './const';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @description
|
|
5
3
|
* Sanitizes the query for the given content type.
|
|
@@ -19,10 +17,4 @@ import { CONTENT_TYPE_MAIN_FIELDS } from './const';
|
|
|
19
17
|
* @param {string} contentType - The content type to be used for formatting the fields.
|
|
20
18
|
* @returns {string} The sanitized query string.
|
|
21
19
|
*/
|
|
22
|
-
export function sanitizeQueryForContentType(query: string, contentType: string): string
|
|
23
|
-
return query.replace(/\+([^+:]*?):/g, (original, field) => {
|
|
24
|
-
return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not content type fields
|
|
25
|
-
? `+${contentType}.${field}:` // Should have this format: +contentTypeVar.field:
|
|
26
|
-
: original; // Return the field if it is a content type field
|
|
27
|
-
});
|
|
28
|
-
}
|
|
20
|
+
export declare function sanitizeQueryForContentType(query: string, contentType: string): string;
|
|
@@ -9,11 +9,4 @@
|
|
|
9
9
|
* @property {string} 502 - Bad Gateway. Try again later.
|
|
10
10
|
* @property {string} 503 - Service Unavailable. Try again later.
|
|
11
11
|
*/
|
|
12
|
-
export const ErrorMessages: Record<number, string
|
|
13
|
-
401: 'Unauthorized. Check the token and try again.',
|
|
14
|
-
403: 'Forbidden. Check the permissions and try again.',
|
|
15
|
-
404: 'Not Found. Check the URL and try again.',
|
|
16
|
-
500: 'Internal Server Error. Try again later.',
|
|
17
|
-
502: 'Bad Gateway. Try again later.',
|
|
18
|
-
503: 'Service Unavailable. Try again later.'
|
|
19
|
-
};
|
|
12
|
+
export declare const ErrorMessages: Record<number, string>;
|