@dotcms/client 0.0.1-beta.2 → 0.0.1-beta.4
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.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 +553 -0
- package/next.cjs.mjs +2 -0
- package/next.esm.d.ts +1 -0
- package/next.esm.js +551 -0
- package/package.json +32 -7
- package/src/index.d.ts +6 -6
- package/src/lib/client/client.d.ts +84 -0
- package/src/lib/client/content/builders/collection/collection.d.ts +1 -1
- package/src/lib/client/content/content-api.d.ts +1 -1
- package/src/lib/client/content/shared/types.d.ts +2 -2
- package/src/lib/client/models/types.d.ts +513 -10
- package/src/lib/client/navigation/navigation-api.d.ts +31 -0
- package/src/lib/client/page/page-api.d.ts +165 -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/page/common-utils.d.ts +1 -1
- package/src/next.d.ts +1 -0
- package/src/types.d.ts +2 -0
- package/transforms.cjs.js +1145 -0
- package/transforms.esm.js +1139 -0
- package/types.cjs.d.ts +1 -0
- package/types.cjs.default.js +1 -0
- package/types.cjs.js +2 -0
- package/types.cjs.mjs +2 -0
- package/types.esm.d.ts +1 -0
- package/types.esm.js +1 -0
- /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/index.cjs.js
CHANGED
|
@@ -1,1068 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Copyright (c) Microsoft Corporation.
|
|
5
|
-
|
|
6
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
7
|
-
purpose with or without fee is hereby granted.
|
|
8
|
-
|
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
***************************************************************************** */
|
|
17
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
21
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
23
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
27
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
30
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
34
|
-
var e = new Error(message);
|
|
35
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
var _Field_query;
|
|
39
|
-
/**
|
|
40
|
-
* The `Field` class is used to build a query with a specific field.
|
|
41
|
-
* A Lucene Field is a key used to search for a specific value in a document.
|
|
42
|
-
*
|
|
43
|
-
* @export
|
|
44
|
-
* @class Field
|
|
45
|
-
*/
|
|
46
|
-
class Field {
|
|
47
|
-
/**
|
|
48
|
-
* Creates an instance of the `Field` class.
|
|
49
|
-
*
|
|
50
|
-
* @param {string} query - The initial query string.
|
|
51
|
-
*/
|
|
52
|
-
constructor(query) {
|
|
53
|
-
this.query = query;
|
|
54
|
-
_Field_query.set(this, '');
|
|
55
|
-
__classPrivateFieldSet(this, _Field_query, this.query, "f");
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Appends a term to the query that should be included in the search.
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* const field = new Field("+myField");
|
|
63
|
-
* field.equals("myValue");
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @param {string} term - The term that should be included in the search.
|
|
67
|
-
* @return {Equals} - An instance of `Equals`.
|
|
68
|
-
* @memberof Field
|
|
69
|
-
*/
|
|
70
|
-
equals(term) {
|
|
71
|
-
return buildEquals(__classPrivateFieldGet(this, _Field_query, "f"), term);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
_Field_query = new WeakMap();
|
|
75
|
-
|
|
76
|
-
var _NotOperand_query;
|
|
77
|
-
/**
|
|
78
|
-
* 'NotOperand' Is a Typescript class that provides the ability to use the NOT operand in the lucene query string.
|
|
79
|
-
*
|
|
80
|
-
* @export
|
|
81
|
-
* @class NotOperand
|
|
82
|
-
*/
|
|
83
|
-
class NotOperand {
|
|
84
|
-
constructor(query) {
|
|
85
|
-
this.query = query;
|
|
86
|
-
_NotOperand_query.set(this, '');
|
|
87
|
-
__classPrivateFieldSet(this, _NotOperand_query, this.query, "f");
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* This method appends to the query a term that should be included in the search.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* const notOperand = new NotOperand("+myField");
|
|
95
|
-
* notOperand.equals("myValue");
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @param {string} term - The term that should be included in the search.
|
|
99
|
-
* @return {*} {Equals} - An instance of Equals.
|
|
100
|
-
* @memberof NotOperand
|
|
101
|
-
*/
|
|
102
|
-
equals(term) {
|
|
103
|
-
return buildEquals(__classPrivateFieldGet(this, _NotOperand_query, "f"), term);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
_NotOperand_query = new WeakMap();
|
|
107
|
-
|
|
108
|
-
var _Operand_query;
|
|
109
|
-
/**
|
|
110
|
-
* 'Operand' Is a Typescript class that provides the ability to use operands in the lucene query string.}
|
|
111
|
-
* An operand is a logical operator used to join two or more conditions in a query.
|
|
112
|
-
*
|
|
113
|
-
* @export
|
|
114
|
-
* @class Operand
|
|
115
|
-
*/
|
|
116
|
-
class Operand {
|
|
117
|
-
constructor(query) {
|
|
118
|
-
this.query = query;
|
|
119
|
-
_Operand_query.set(this, '');
|
|
120
|
-
__classPrivateFieldSet(this, _Operand_query, this.query, "f");
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* This method appends to the query a term that should be excluded in the search.
|
|
124
|
-
*
|
|
125
|
-
* Ex: "-myValue"
|
|
126
|
-
*
|
|
127
|
-
* @param {string} field - The field that should be excluded in the search.
|
|
128
|
-
* @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
|
|
129
|
-
* @memberof Operand
|
|
130
|
-
*/
|
|
131
|
-
excludeField(field) {
|
|
132
|
-
return buildExcludeField(__classPrivateFieldGet(this, _Operand_query, "f"), field);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* This method appends to the query a field that should be included in the search.
|
|
136
|
-
*
|
|
137
|
-
* Ex: "+myField:"
|
|
138
|
-
*
|
|
139
|
-
* @param {string} field - The field that should be included in the search.
|
|
140
|
-
* @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
|
|
141
|
-
* @memberof Operand
|
|
142
|
-
*/
|
|
143
|
-
field(field) {
|
|
144
|
-
return buildField(__classPrivateFieldGet(this, _Operand_query, "f"), field);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* This method appends to the query a term that should be included in the search.
|
|
148
|
-
*
|
|
149
|
-
* Ex: myValue or "My value"
|
|
150
|
-
*
|
|
151
|
-
* @param {string} term - The term that should be included in the search.
|
|
152
|
-
* @return {*} {Equals} - An instance of Equals.
|
|
153
|
-
* @memberof Operand
|
|
154
|
-
*/
|
|
155
|
-
equals(term) {
|
|
156
|
-
return buildEquals(__classPrivateFieldGet(this, _Operand_query, "f"), term);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
_Operand_query = new WeakMap();
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Enum for common Operands
|
|
163
|
-
*
|
|
164
|
-
* @export
|
|
165
|
-
* @enum {number}
|
|
166
|
-
*/
|
|
167
|
-
var OPERAND;
|
|
168
|
-
(function (OPERAND) {
|
|
169
|
-
OPERAND["OR"] = "OR";
|
|
170
|
-
OPERAND["AND"] = "AND";
|
|
171
|
-
OPERAND["NOT"] = "NOT";
|
|
172
|
-
})(OPERAND || (OPERAND = {}));
|
|
173
|
-
/**
|
|
174
|
-
* This function removes extra spaces from a string.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```ts
|
|
178
|
-
* sanitizeQuery(" my query "); // Output: "my query"
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* @export
|
|
182
|
-
* @param {string} str
|
|
183
|
-
* @return {*} {string}
|
|
184
|
-
*/
|
|
185
|
-
function sanitizeQuery(str) {
|
|
186
|
-
return str.replace(/\s{2,}/g, ' ').trim();
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* This function sanitizes a term by adding quotes if it contains spaces.
|
|
190
|
-
* In lucene, a term with spaces should be enclosed in quotes.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```ts
|
|
194
|
-
* sanitizePhrases(`my term`); // Output: `"my term"`
|
|
195
|
-
* sanitizePhrases(`myterm`); // Output: `myterm`
|
|
196
|
-
* ```
|
|
197
|
-
*
|
|
198
|
-
* @export
|
|
199
|
-
* @param {string} term
|
|
200
|
-
* @return {*} {string}
|
|
201
|
-
*/
|
|
202
|
-
function sanitizePhrases(term) {
|
|
203
|
-
return term.includes(' ') ? `'${term}'` : term;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* This function builds a term to be used in a lucene query.
|
|
207
|
-
* We need to sanitize the term before adding it to the query.
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```ts
|
|
211
|
-
* const equals = buildEquals("+myField: ", "myValue"); // Current query: "+myField: myValue"
|
|
212
|
-
* ```
|
|
213
|
-
*
|
|
214
|
-
* @export
|
|
215
|
-
* @param {string} query
|
|
216
|
-
* @param {string} term
|
|
217
|
-
* @return {*} {Equals}
|
|
218
|
-
*/
|
|
219
|
-
function buildEquals(query, term) {
|
|
220
|
-
const newQuery = query + sanitizePhrases(term);
|
|
221
|
-
return new Equals(newQuery);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* This function builds a term to be used in a lucene query.
|
|
225
|
-
* We need to sanitize the raw query before adding it to the query.
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* ```ts
|
|
229
|
-
* const query = "+myField: myValue";
|
|
230
|
-
* const field = buildRawEquals(query, "-myField2: myValue2"); // Current query: "+myField: myValue -myField2: myValue"
|
|
231
|
-
* ```
|
|
232
|
-
*
|
|
233
|
-
* @export
|
|
234
|
-
* @param {string} query
|
|
235
|
-
* @param {string} raw
|
|
236
|
-
* @return {*} {Equals}
|
|
237
|
-
*/
|
|
238
|
-
function buildRawEquals(query, raw) {
|
|
239
|
-
const newQuery = query + ` ${raw}`;
|
|
240
|
-
return new Equals(sanitizeQuery(newQuery));
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* This function builds a field to be used in a lucene query.
|
|
244
|
-
* We need to format the field before adding it to the query.
|
|
245
|
-
*
|
|
246
|
-
* @example
|
|
247
|
-
* ```ts
|
|
248
|
-
* const field = buildField("+myField: ", "myValue"); // Current query: "+myField: myValue"
|
|
249
|
-
* ```
|
|
250
|
-
*
|
|
251
|
-
* @export
|
|
252
|
-
* @param {string} query
|
|
253
|
-
* @param {string} field
|
|
254
|
-
* @return {*} {Field}
|
|
255
|
-
*/
|
|
256
|
-
function buildField(query, field) {
|
|
257
|
-
const newQuery = query + ` +${field}:`;
|
|
258
|
-
return new Field(newQuery);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* This function builds an exclude field to be used in a lucene query.
|
|
262
|
-
* We need to format the field before adding it to the query.
|
|
263
|
-
*
|
|
264
|
-
* @example
|
|
265
|
-
* ```ts
|
|
266
|
-
* const query = "+myField: myValue";
|
|
267
|
-
* const field = buildExcludeField(query, "myField2"); // Current query: "+myField: myValue -myField2:"
|
|
268
|
-
* ```
|
|
269
|
-
*
|
|
270
|
-
* @export
|
|
271
|
-
* @param {string} query
|
|
272
|
-
* @param {string} field
|
|
273
|
-
* @return {*} {Field}
|
|
274
|
-
*/
|
|
275
|
-
function buildExcludeField(query, field) {
|
|
276
|
-
const newQuery = query + ` -${field}:`;
|
|
277
|
-
return new Field(newQuery);
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* This function builds an operand to be used in a lucene query.
|
|
281
|
-
* We need to format the operand before adding it to the query.
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* <caption>E.g. Using the AND operand</caption>
|
|
285
|
-
* ```ts
|
|
286
|
-
* const query = "+myField: myValue";
|
|
287
|
-
* const field = buildOperand(query, OPERAND.AND); // Current query: "+myField: myValue AND"
|
|
288
|
-
* ```
|
|
289
|
-
* @example
|
|
290
|
-
* <caption>E.g. Using the OR operand</caption>
|
|
291
|
-
* ```ts
|
|
292
|
-
* const query = "+myField: myValue";
|
|
293
|
-
* const field = buildOperand(query, OPERAND.OR); // Current query: "+myField: myValue OR"
|
|
294
|
-
* ```
|
|
295
|
-
* @export
|
|
296
|
-
* @param {string} query
|
|
297
|
-
* @param {OPERAND} operand
|
|
298
|
-
* @return {*} {Operand}
|
|
299
|
-
*/
|
|
300
|
-
function buildOperand(query, operand) {
|
|
301
|
-
const newQuery = query + ` ${operand} `;
|
|
302
|
-
return new Operand(newQuery);
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* This function builds a NOT operand to be used in a lucene query.
|
|
306
|
-
* We need to format the operand before adding it to the query.
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```ts
|
|
310
|
-
* const query = "+myField: myValue";
|
|
311
|
-
* const field = buildNotOperand(query); // Current query: "+myField: myValue NOT"
|
|
312
|
-
* ```
|
|
313
|
-
*
|
|
314
|
-
* @export
|
|
315
|
-
* @param {string} query
|
|
316
|
-
* @return {*} {NotOperand}
|
|
317
|
-
*/
|
|
318
|
-
function buildNotOperand(query) {
|
|
319
|
-
const newQuery = query + ` ${OPERAND.NOT} `;
|
|
320
|
-
return new NotOperand(newQuery);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
var _Equals_query;
|
|
324
|
-
/**
|
|
325
|
-
* 'Equal' Is a Typescript class that provides the ability to use terms in the lucene query string.
|
|
326
|
-
* A term is a value used to search for a specific value in a document. It can be a word or a phrase.
|
|
327
|
-
*
|
|
328
|
-
* Ex: myValue or "My Value"
|
|
329
|
-
*
|
|
330
|
-
* @export
|
|
331
|
-
* @class Equal
|
|
332
|
-
*/
|
|
333
|
-
class Equals {
|
|
334
|
-
constructor(query) {
|
|
335
|
-
this.query = query;
|
|
336
|
-
_Equals_query.set(this, '');
|
|
337
|
-
__classPrivateFieldSet(this, _Equals_query, this.query, "f");
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* This method appends to the query a term that should be excluded in the search.
|
|
341
|
-
*
|
|
342
|
-
* @example
|
|
343
|
-
* ```ts
|
|
344
|
-
* const equals = new Equals("+myField: myValue");
|
|
345
|
-
* equals.excludeField("myField2").equals("myValue2"); // Current query: "+myField: myValue -myField2: myValue2"
|
|
346
|
-
* ```
|
|
347
|
-
*
|
|
348
|
-
* @param {string} field - The field that should be excluded in the search.
|
|
349
|
-
* @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
|
|
350
|
-
* @memberof Equal
|
|
351
|
-
*/
|
|
352
|
-
excludeField(field) {
|
|
353
|
-
return buildExcludeField(__classPrivateFieldGet(this, _Equals_query, "f"), field);
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* This method appends to the query a field that should be included in the search.
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
* ```ts
|
|
360
|
-
* const equals = new Equals("+myField: myValue");
|
|
361
|
-
* equals.field("myField2").equals("myValue2"); // Current query: "+myField: myValue +myField2: myValue2"
|
|
362
|
-
*```
|
|
363
|
-
* @param {string} field - The field that should be included in the search.
|
|
364
|
-
* @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
|
|
365
|
-
* @memberof Equal
|
|
366
|
-
*/
|
|
367
|
-
field(field) {
|
|
368
|
-
return buildField(__classPrivateFieldGet(this, _Equals_query, "f"), field);
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* This method appends to the query an operand to use logic operators in the query.
|
|
372
|
-
*
|
|
373
|
-
* @example
|
|
374
|
-
* @example
|
|
375
|
-
* ```ts
|
|
376
|
-
* const equals = new Equals("+myField: myValue");
|
|
377
|
-
* equals.or().field("myField2").equals("myValue2"); // Current query: "+myField: myValue OR +myField2: myValue2"
|
|
378
|
-
* ```
|
|
379
|
-
*
|
|
380
|
-
* @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
|
|
381
|
-
* @memberof Equal
|
|
382
|
-
*/
|
|
383
|
-
or() {
|
|
384
|
-
return buildOperand(__classPrivateFieldGet(this, _Equals_query, "f"), OPERAND.OR);
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* This method appends to the query an operand to use logic operators in the query.
|
|
388
|
-
*
|
|
389
|
-
* @example
|
|
390
|
-
* ```ts
|
|
391
|
-
* const equals = new Equals("+myField: myValue");
|
|
392
|
-
* equals.and().field("myField2").equals("myValue2"); // Current query: "+myField: myValue AND +myField2: myValue2"
|
|
393
|
-
* ```
|
|
394
|
-
*
|
|
395
|
-
* @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
|
|
396
|
-
* @memberof Equal
|
|
397
|
-
*/
|
|
398
|
-
and() {
|
|
399
|
-
return buildOperand(__classPrivateFieldGet(this, _Equals_query, "f"), OPERAND.AND);
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* This method appends to the query an operand to use logic operators in the query.
|
|
403
|
-
*
|
|
404
|
-
* @example
|
|
405
|
-
* ```ts
|
|
406
|
-
* const equals = new Equals("+myField: myValue");
|
|
407
|
-
* equals.not().field("myField").equals("myValue2"); // Current query: "+myField: myValue NOT +myField: myValue2"
|
|
408
|
-
* ```
|
|
409
|
-
*
|
|
410
|
-
* @return {*} {NotOperand} - An instance of a Lucene Not Operand. A not operand is a logical operator used to exclude terms or phrases in a query.
|
|
411
|
-
* @memberof Equal
|
|
412
|
-
*/
|
|
413
|
-
not() {
|
|
414
|
-
return buildNotOperand(__classPrivateFieldGet(this, _Equals_query, "f"));
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* This method allows to pass a raw query string to the query builder.
|
|
418
|
-
* This raw query should end in a Lucene Equal.
|
|
419
|
-
* This method is useful when you want to append a complex query or an already written query to the query builder.
|
|
420
|
-
*
|
|
421
|
-
* @example
|
|
422
|
-
* ```ts
|
|
423
|
-
* // This builds the follow raw query "+myField: value AND (someOtherValue OR anotherValue)"
|
|
424
|
-
* const equals = new Equals("+myField: value");
|
|
425
|
-
* equals.raw("+myField2: value2"); // Current query: "+myField: value +myField2: anotherValue"
|
|
426
|
-
* ```
|
|
427
|
-
*
|
|
428
|
-
* @param {string} query - A raw query string.
|
|
429
|
-
* @return {*} {Equal} - An instance of a Lucene Equal. A term is a value used to search for a specific value in a document.
|
|
430
|
-
* @memberof QueryBuilder
|
|
431
|
-
*/
|
|
432
|
-
raw(query) {
|
|
433
|
-
return buildRawEquals(__classPrivateFieldGet(this, _Equals_query, "f"), query);
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* This method returns the final query string.
|
|
437
|
-
*
|
|
438
|
-
* @example
|
|
439
|
-
* ```ts
|
|
440
|
-
* const equals = new Equals("+myField: myValue");
|
|
441
|
-
* equals.field("myField2").equals("myValue2").build(); // Returns "+myField: myValue +myField2: myValue2"
|
|
442
|
-
* ```
|
|
443
|
-
*
|
|
444
|
-
* @return {*} {string} - The final query string.
|
|
445
|
-
* @memberof Equal
|
|
446
|
-
*/
|
|
447
|
-
build() {
|
|
448
|
-
return sanitizeQuery(__classPrivateFieldGet(this, _Equals_query, "f"));
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
_Equals_query = new WeakMap();
|
|
452
|
-
|
|
453
|
-
var _QueryBuilder_query;
|
|
454
|
-
/**
|
|
455
|
-
* 'QueryBuilder' Is a Typescript class that provides the ability to build a query string using the Lucene syntax in a more readable way.
|
|
456
|
-
* @example
|
|
457
|
-
* ```ts
|
|
458
|
-
* const qb = new QueryBuilder();
|
|
459
|
-
* const query = qb
|
|
460
|
-
* .field('contentType')
|
|
461
|
-
* .equals('Blog')
|
|
462
|
-
* .field('conhost')
|
|
463
|
-
* .equals('my-super-cool-site')
|
|
464
|
-
* .build(); // Output: `+contentType:Blog +conhost:my-super-cool-site"`
|
|
465
|
-
* ```
|
|
466
|
-
*
|
|
467
|
-
* @example
|
|
468
|
-
* ```ts
|
|
469
|
-
* const qb = new QueryBuilder();
|
|
470
|
-
* const query = qb
|
|
471
|
-
* .field('contentType')
|
|
472
|
-
* .equals('Blog')
|
|
473
|
-
* .field('title')
|
|
474
|
-
* .equals('Football')
|
|
475
|
-
* .excludeField('summary')
|
|
476
|
-
* .equals('Lionel Messi')
|
|
477
|
-
* .build(); // Output: `+contentType:Blog +title:Football -summary:"Lionel Messi"`
|
|
478
|
-
* ```
|
|
479
|
-
* @export
|
|
480
|
-
* @class QueryBuilder
|
|
481
|
-
*/
|
|
482
|
-
class QueryBuilder {
|
|
483
|
-
constructor() {
|
|
484
|
-
_QueryBuilder_query.set(this, '');
|
|
485
|
-
}
|
|
486
|
-
/**
|
|
487
|
-
* This method appends to the query a field that should be included in the search.
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```ts
|
|
491
|
-
* const qb = new QueryBuilder();
|
|
492
|
-
* qb.field("+myField: ", "myValue"); // Current query: "+myField: myValue"
|
|
493
|
-
* ```
|
|
494
|
-
*
|
|
495
|
-
* @param {string} field - The field that should be included in the search.
|
|
496
|
-
* @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
|
|
497
|
-
* @memberof QueryBuilder
|
|
498
|
-
*/
|
|
499
|
-
field(field) {
|
|
500
|
-
return buildField(__classPrivateFieldGet(this, _QueryBuilder_query, "f"), field);
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* This method appends to the query a field that should be excluded from the search.
|
|
504
|
-
*
|
|
505
|
-
* @example
|
|
506
|
-
* ```ts
|
|
507
|
-
* const qb = new QueryBuilder();
|
|
508
|
-
* qb.excludeField("myField").equals("myValue"); // Current query: "-myField: myValue"
|
|
509
|
-
* ```
|
|
510
|
-
*
|
|
511
|
-
* @param {string} field - The field that should be excluded from the search.
|
|
512
|
-
* @return {*} {Field} - An instance of a Lucene Exclude Field. An exclude field is a key used to exclude for a specific value in a document.
|
|
513
|
-
* @memberof QueryBuilder
|
|
514
|
-
*/
|
|
515
|
-
excludeField(field) {
|
|
516
|
-
return buildExcludeField(__classPrivateFieldGet(this, _QueryBuilder_query, "f"), field);
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* This method allows to pass a raw query string to the query builder.
|
|
520
|
-
* This raw query should end in Equals.
|
|
521
|
-
* This method is useful when you want to append a complex query or an already written query to the query builder.
|
|
522
|
-
*
|
|
523
|
-
* @example
|
|
524
|
-
* ```ts
|
|
525
|
-
* const qb = new QueryBuilder();
|
|
526
|
-
* qb.raw("+myField: value AND (someOtherValue OR anotherValue)"); // Current query: "+myField: value AND (someOtherValue OR anotherValue)"
|
|
527
|
-
* ```
|
|
528
|
-
*
|
|
529
|
-
* @param {string} query - A raw query string.
|
|
530
|
-
* @return {*} {Equals} - An instance of Equals. A term is a value used to search for a specific value in a document.
|
|
531
|
-
* @memberof QueryBuilder
|
|
532
|
-
*/
|
|
533
|
-
raw(query) {
|
|
534
|
-
return buildRawEquals(__classPrivateFieldGet(this, _QueryBuilder_query, "f"), query);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
_QueryBuilder_query = new WeakMap();
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* Default variant identifier used in the application.
|
|
541
|
-
*/
|
|
542
|
-
/**
|
|
543
|
-
* Fields that should not be formatted when sanitizing the query.
|
|
544
|
-
* These fields are essential for maintaining the integrity of the content type.
|
|
545
|
-
*/
|
|
546
|
-
const CONTENT_TYPE_MAIN_FIELDS = ['live', 'variant', 'contentType', 'languageId'];
|
|
547
|
-
/**
|
|
548
|
-
* URL endpoint for the content API search functionality.
|
|
549
|
-
*/
|
|
550
|
-
const CONTENT_API_URL = '/api/content/_search';
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* @description
|
|
554
|
-
* Sanitizes the query for the given content type.
|
|
555
|
-
* It replaces the fields that are not content type fields with the correct format.
|
|
556
|
-
* Example: +field: -> +contentTypeVar.field:
|
|
557
|
-
*
|
|
558
|
-
* @example
|
|
559
|
-
*
|
|
560
|
-
* ```ts
|
|
561
|
-
* const query = '+field: value';
|
|
562
|
-
* const contentType = 'contentTypeVar';
|
|
563
|
-
* const sanitizedQuery = sanitizeQueryForContentType(query, contentType); // Output: '+contentTypeVar.field: value'
|
|
564
|
-
* ```
|
|
565
|
-
*
|
|
566
|
-
* @export
|
|
567
|
-
* @param {string} query - The query string to be sanitized.
|
|
568
|
-
* @param {string} contentType - The content type to be used for formatting the fields.
|
|
569
|
-
* @returns {string} The sanitized query string.
|
|
570
|
-
*/
|
|
571
|
-
function sanitizeQueryForContentType(query, contentType) {
|
|
572
|
-
return query.replace(/\+([^+:]*?):/g, (original, field) => {
|
|
573
|
-
return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not content type fields
|
|
574
|
-
? `+${contentType}.${field}:` // Should have this format: +contentTypeVar.field:
|
|
575
|
-
: original; // Return the field if it is a content type field
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
var _CollectionBuilder_page, _CollectionBuilder_limit, _CollectionBuilder_depth, _CollectionBuilder_render, _CollectionBuilder_sortBy, _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_languageId, _CollectionBuilder_draft, _CollectionBuilder_serverUrl, _CollectionBuilder_requestOptions;
|
|
580
|
-
/**
|
|
581
|
-
* Creates a Builder to filter and fetch content from the content API for a specific content type.
|
|
582
|
-
*
|
|
583
|
-
* @export
|
|
584
|
-
* @class CollectionBuilder
|
|
585
|
-
* @template T Represents the type of the content type to fetch. Defaults to unknown.
|
|
586
|
-
*/
|
|
587
|
-
class CollectionBuilder {
|
|
588
|
-
/**
|
|
589
|
-
* Creates an instance of CollectionBuilder.
|
|
590
|
-
* @param {ClientOptions} requestOptions Options for the client request.
|
|
591
|
-
* @param {string} serverUrl The server URL.
|
|
592
|
-
* @param {string} contentType The content type to fetch.
|
|
593
|
-
* @memberof CollectionBuilder
|
|
594
|
-
*/
|
|
595
|
-
constructor(requestOptions, serverUrl, contentType) {
|
|
596
|
-
_CollectionBuilder_page.set(this, 1);
|
|
597
|
-
_CollectionBuilder_limit.set(this, 10);
|
|
598
|
-
_CollectionBuilder_depth.set(this, 0);
|
|
599
|
-
_CollectionBuilder_render.set(this, false);
|
|
600
|
-
_CollectionBuilder_sortBy.set(this, void 0);
|
|
601
|
-
_CollectionBuilder_contentType.set(this, void 0);
|
|
602
|
-
_CollectionBuilder_defaultQuery.set(this, void 0);
|
|
603
|
-
_CollectionBuilder_query.set(this, void 0);
|
|
604
|
-
_CollectionBuilder_rawQuery.set(this, void 0);
|
|
605
|
-
_CollectionBuilder_languageId.set(this, 1);
|
|
606
|
-
_CollectionBuilder_draft.set(this, false);
|
|
607
|
-
_CollectionBuilder_serverUrl.set(this, void 0);
|
|
608
|
-
_CollectionBuilder_requestOptions.set(this, void 0);
|
|
609
|
-
__classPrivateFieldSet(this, _CollectionBuilder_requestOptions, requestOptions, "f");
|
|
610
|
-
__classPrivateFieldSet(this, _CollectionBuilder_serverUrl, serverUrl, "f");
|
|
611
|
-
__classPrivateFieldSet(this, _CollectionBuilder_contentType, contentType, "f");
|
|
612
|
-
// Build the default query with the contentType field
|
|
613
|
-
__classPrivateFieldSet(this, _CollectionBuilder_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _CollectionBuilder_contentType, "f")), "f");
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Returns the sort query in the format: field order, field order, ...
|
|
617
|
-
*
|
|
618
|
-
* @readonly
|
|
619
|
-
* @private
|
|
620
|
-
* @memberof CollectionBuilder
|
|
621
|
-
*/
|
|
622
|
-
get sort() {
|
|
623
|
-
return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")?.map((sort) => `${sort.field} ${sort.order}`).join(',');
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Returns the offset for pagination.
|
|
627
|
-
*
|
|
628
|
-
* @readonly
|
|
629
|
-
* @private
|
|
630
|
-
* @memberof CollectionBuilder
|
|
631
|
-
*/
|
|
632
|
-
get offset() {
|
|
633
|
-
return __classPrivateFieldGet(this, _CollectionBuilder_limit, "f") * (__classPrivateFieldGet(this, _CollectionBuilder_page, "f") - 1);
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Returns the full URL for the content API.
|
|
637
|
-
*
|
|
638
|
-
* @readonly
|
|
639
|
-
* @private
|
|
640
|
-
* @memberof CollectionBuilder
|
|
641
|
-
*/
|
|
642
|
-
get url() {
|
|
643
|
-
return `${__classPrivateFieldGet(this, _CollectionBuilder_serverUrl, "f")}${CONTENT_API_URL}`;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Returns the current query built.
|
|
647
|
-
*
|
|
648
|
-
* @readonly
|
|
649
|
-
* @private
|
|
650
|
-
* @memberof CollectionBuilder
|
|
651
|
-
*/
|
|
652
|
-
get currentQuery() {
|
|
653
|
-
return __classPrivateFieldGet(this, _CollectionBuilder_query, "f") ?? __classPrivateFieldGet(this, _CollectionBuilder_defaultQuery, "f");
|
|
654
|
-
}
|
|
655
|
-
/**
|
|
656
|
-
* Filters the content by the specified language ID.
|
|
657
|
-
*
|
|
658
|
-
* @example
|
|
659
|
-
* ```typescript
|
|
660
|
-
* const client = new DotCMSClient(config);
|
|
661
|
-
* const collectionBuilder = client.content.getCollection("Blog");
|
|
662
|
-
* collectionBuilder.language(1);
|
|
663
|
-
* ```
|
|
664
|
-
*
|
|
665
|
-
* @param {number | string} languageId The language ID to filter the content by.
|
|
666
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
667
|
-
* @memberof CollectionBuilder
|
|
668
|
-
*/
|
|
669
|
-
language(languageId) {
|
|
670
|
-
__classPrivateFieldSet(this, _CollectionBuilder_languageId, languageId, "f");
|
|
671
|
-
return this;
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Setting this to true will server side render (using velocity) any widgets that are returned by the content query.
|
|
675
|
-
*
|
|
676
|
-
* More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
|
|
677
|
-
*
|
|
678
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
679
|
-
* @memberof CollectionBuilder
|
|
680
|
-
*/
|
|
681
|
-
render() {
|
|
682
|
-
__classPrivateFieldSet(this, _CollectionBuilder_render, true, "f");
|
|
683
|
-
return this;
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Sorts the content by the specified fields and orders.
|
|
687
|
-
*
|
|
688
|
-
* @example
|
|
689
|
-
* ```typescript
|
|
690
|
-
* const client = new DotCMSClient(config);
|
|
691
|
-
* const collectionBuilder = client.content.getCollection("Blog");
|
|
692
|
-
* const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }];
|
|
693
|
-
* collectionBuilder("Blog").sortBy(sortBy);
|
|
694
|
-
* ```
|
|
695
|
-
*
|
|
696
|
-
* @param {SortBy[]} sortBy Array of constraints to sort the content by.
|
|
697
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
698
|
-
* @memberof CollectionBuilder
|
|
699
|
-
*/
|
|
700
|
-
sortBy(sortBy) {
|
|
701
|
-
__classPrivateFieldSet(this, _CollectionBuilder_sortBy, sortBy, "f");
|
|
702
|
-
return this;
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Sets the maximum amount of content to fetch.
|
|
706
|
-
*
|
|
707
|
-
* @param {number} limit The maximum amount of content to fetch.
|
|
708
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
709
|
-
* @memberof CollectionBuilder
|
|
710
|
-
*/
|
|
711
|
-
limit(limit) {
|
|
712
|
-
__classPrivateFieldSet(this, _CollectionBuilder_limit, limit, "f");
|
|
713
|
-
return this;
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Sets the page number to fetch.
|
|
717
|
-
*
|
|
718
|
-
* @param {number} page The page number to fetch.
|
|
719
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
720
|
-
* @memberof CollectionBuilder
|
|
721
|
-
*/
|
|
722
|
-
page(page) {
|
|
723
|
-
__classPrivateFieldSet(this, _CollectionBuilder_page, page, "f");
|
|
724
|
-
return this;
|
|
725
|
-
}
|
|
726
|
-
query(arg) {
|
|
727
|
-
if (typeof arg === 'string') {
|
|
728
|
-
__classPrivateFieldSet(this, _CollectionBuilder_rawQuery, arg, "f");
|
|
729
|
-
return this;
|
|
730
|
-
}
|
|
731
|
-
if (typeof arg !== 'function') {
|
|
732
|
-
throw new Error(`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.`);
|
|
733
|
-
}
|
|
734
|
-
const builtQuery = arg(new QueryBuilder());
|
|
735
|
-
// This can be use in Javascript so we cannot rely on the type checking
|
|
736
|
-
if (builtQuery instanceof Equals) {
|
|
737
|
-
__classPrivateFieldSet(this, _CollectionBuilder_query, builtQuery.raw(this.currentQuery.build()), "f");
|
|
738
|
-
}
|
|
739
|
-
else {
|
|
740
|
-
throw new Error('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.');
|
|
741
|
-
}
|
|
742
|
-
return this;
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Retrieves draft content.
|
|
746
|
-
* @example
|
|
747
|
-
* ```ts
|
|
748
|
-
* const client = new DotCMSClient(config);
|
|
749
|
-
* const collectionBuilder = client.content.getCollection("Blog");
|
|
750
|
-
* collectionBuilder
|
|
751
|
-
* .draft() // This will retrieve draft/working content
|
|
752
|
-
* .then((response) => // Your code here })
|
|
753
|
-
* .catch((error) => // Your code here })
|
|
754
|
-
* ```
|
|
755
|
-
*
|
|
756
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
757
|
-
* @memberof CollectionBuilder
|
|
758
|
-
*/
|
|
759
|
-
draft() {
|
|
760
|
-
__classPrivateFieldSet(this, _CollectionBuilder_draft, true, "f");
|
|
761
|
-
return this;
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
|
|
765
|
-
*
|
|
766
|
-
* More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
|
|
767
|
-
*
|
|
768
|
-
* @example
|
|
769
|
-
* ```ts
|
|
770
|
-
* const client = new DotCMSClient(config);
|
|
771
|
-
* const collectionBuilder = client.content.getCollection("Blog");
|
|
772
|
-
* collectionBuilder
|
|
773
|
-
* .variant("YOUR_VARIANT_ID")
|
|
774
|
-
* .then((response) => // Your code here })
|
|
775
|
-
* .catch((error) => // Your code here })
|
|
776
|
-
* ```
|
|
777
|
-
*
|
|
778
|
-
* @param {string} variantId A string that represents a variant ID.
|
|
779
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
780
|
-
* @memberof CollectionBuilder
|
|
781
|
-
*/
|
|
782
|
-
variant(variantId) {
|
|
783
|
-
__classPrivateFieldSet(this, _CollectionBuilder_query, this.currentQuery.field('variant').equals(variantId), "f");
|
|
784
|
-
return this;
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* Sets the depth of the relationships of the content.
|
|
788
|
-
* Specifies the depth of related content to return in the results.
|
|
789
|
-
*
|
|
790
|
-
* More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
|
|
791
|
-
*
|
|
792
|
-
* @example
|
|
793
|
-
* ```ts
|
|
794
|
-
* const client = new DotCMSClient(config);
|
|
795
|
-
* const collectionBuilder = client.content.getCollection("Blog");
|
|
796
|
-
* collectionBuilder
|
|
797
|
-
* .depth(1)
|
|
798
|
-
* .then((response) => // Your code here })
|
|
799
|
-
* .catch((error) => // Your code here })
|
|
800
|
-
* ```
|
|
801
|
-
*
|
|
802
|
-
* @param {number} depth The depth of the relationships of the content.
|
|
803
|
-
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
804
|
-
* @memberof CollectionBuilder
|
|
805
|
-
*/
|
|
806
|
-
depth(depth) {
|
|
807
|
-
if (depth < 0 || depth > 3) {
|
|
808
|
-
throw new Error('Depth value must be between 0 and 3');
|
|
809
|
-
}
|
|
810
|
-
__classPrivateFieldSet(this, _CollectionBuilder_depth, depth, "f");
|
|
811
|
-
return this;
|
|
812
|
-
}
|
|
813
|
-
/**
|
|
814
|
-
* Executes the fetch and returns a promise that resolves to the content or rejects with an error.
|
|
815
|
-
*
|
|
816
|
-
* @example
|
|
817
|
-
* ```ts
|
|
818
|
-
* const client = new DotCMSClient(config);
|
|
819
|
-
* const collectionBuilder = client.content.getCollection("Blog");
|
|
820
|
-
* collectionBuilder
|
|
821
|
-
* .limit(10)
|
|
822
|
-
* .then((response) => // Your code here })
|
|
823
|
-
* .catch((error) => // Your code here })
|
|
824
|
-
* ```
|
|
825
|
-
*
|
|
826
|
-
* @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful.
|
|
827
|
-
* @param {OnRejected} [onrejected] A callback that is called when the fetch fails.
|
|
828
|
-
* @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects with an error.
|
|
829
|
-
* @memberof CollectionBuilder
|
|
830
|
-
*/
|
|
831
|
-
then(onfulfilled, onrejected) {
|
|
832
|
-
return this.fetch().then(async (response) => {
|
|
833
|
-
const data = await response.json();
|
|
834
|
-
if (response.ok) {
|
|
835
|
-
const formattedResponse = this.formatResponse(data);
|
|
836
|
-
const finalResponse = typeof onfulfilled === 'function'
|
|
837
|
-
? onfulfilled(formattedResponse)
|
|
838
|
-
: formattedResponse;
|
|
839
|
-
return finalResponse;
|
|
840
|
-
}
|
|
841
|
-
else {
|
|
842
|
-
return {
|
|
843
|
-
status: response.status,
|
|
844
|
-
...data
|
|
845
|
-
};
|
|
846
|
-
}
|
|
847
|
-
}, onrejected);
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Formats the response to the desired format.
|
|
851
|
-
*
|
|
852
|
-
* @private
|
|
853
|
-
* @param {GetCollectionRawResponse<T>} data The raw response data.
|
|
854
|
-
* @return {GetCollectionResponse<T>} The formatted response.
|
|
855
|
-
* @memberof CollectionBuilder
|
|
856
|
-
*/
|
|
857
|
-
formatResponse(data) {
|
|
858
|
-
const contentlets = data.entity.jsonObjectView.contentlets;
|
|
859
|
-
const total = data.entity.resultsSize;
|
|
860
|
-
const mappedResponse = {
|
|
861
|
-
contentlets,
|
|
862
|
-
total,
|
|
863
|
-
page: __classPrivateFieldGet(this, _CollectionBuilder_page, "f"),
|
|
864
|
-
size: contentlets.length
|
|
865
|
-
};
|
|
866
|
-
return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
|
|
867
|
-
? {
|
|
868
|
-
...mappedResponse,
|
|
869
|
-
sortedBy: __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")
|
|
870
|
-
}
|
|
871
|
-
: mappedResponse;
|
|
872
|
-
}
|
|
873
|
-
/**
|
|
874
|
-
* Calls the content API to fetch the content.
|
|
875
|
-
*
|
|
876
|
-
* @private
|
|
877
|
-
* @return {Promise<Response>} The fetch response.
|
|
878
|
-
* @memberof CollectionBuilder
|
|
879
|
-
*/
|
|
880
|
-
fetch() {
|
|
881
|
-
const finalQuery = this.currentQuery
|
|
882
|
-
.field('languageId')
|
|
883
|
-
.equals(__classPrivateFieldGet(this, _CollectionBuilder_languageId, "f").toString())
|
|
884
|
-
.field('live')
|
|
885
|
-
.equals((!__classPrivateFieldGet(this, _CollectionBuilder_draft, "f")).toString())
|
|
886
|
-
.build();
|
|
887
|
-
const sanitizedQuery = sanitizeQueryForContentType(finalQuery, __classPrivateFieldGet(this, _CollectionBuilder_contentType, "f"));
|
|
888
|
-
const query = __classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f") ? `${sanitizedQuery} ${__classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f")}` : sanitizedQuery;
|
|
889
|
-
return fetch(this.url, {
|
|
890
|
-
...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f"),
|
|
891
|
-
method: 'POST',
|
|
892
|
-
headers: {
|
|
893
|
-
...__classPrivateFieldGet(this, _CollectionBuilder_requestOptions, "f").headers,
|
|
894
|
-
'Content-Type': 'application/json'
|
|
895
|
-
},
|
|
896
|
-
body: JSON.stringify({
|
|
897
|
-
query,
|
|
898
|
-
render: __classPrivateFieldGet(this, _CollectionBuilder_render, "f"),
|
|
899
|
-
sort: this.sort,
|
|
900
|
-
limit: __classPrivateFieldGet(this, _CollectionBuilder_limit, "f"),
|
|
901
|
-
offset: this.offset,
|
|
902
|
-
depth: __classPrivateFieldGet(this, _CollectionBuilder_depth, "f")
|
|
903
|
-
//userId: This exist but we currently don't use it
|
|
904
|
-
//allCategoriesInfo: This exist but we currently don't use it
|
|
905
|
-
})
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
_CollectionBuilder_page = new WeakMap(), _CollectionBuilder_limit = new WeakMap(), _CollectionBuilder_depth = new WeakMap(), _CollectionBuilder_render = new WeakMap(), _CollectionBuilder_sortBy = new WeakMap(), _CollectionBuilder_contentType = new WeakMap(), _CollectionBuilder_defaultQuery = new WeakMap(), _CollectionBuilder_query = new WeakMap(), _CollectionBuilder_rawQuery = new WeakMap(), _CollectionBuilder_languageId = new WeakMap(), _CollectionBuilder_draft = new WeakMap(), _CollectionBuilder_serverUrl = new WeakMap(), _CollectionBuilder_requestOptions = new WeakMap();
|
|
910
|
-
|
|
911
|
-
var _Content_requestOptions, _Content_serverUrl;
|
|
912
|
-
/**
|
|
913
|
-
* Creates a builder to filter and fetch a collection of content items.
|
|
914
|
-
* @param contentType - The content type to retrieve.
|
|
915
|
-
* @returns A CollectionBuilder instance for chaining filters and executing the query.
|
|
916
|
-
* @template T - The type of the content items (defaults to unknown).
|
|
917
|
-
*
|
|
918
|
-
* @example Fetch blog posts with async/await
|
|
919
|
-
* ```typescript
|
|
920
|
-
* const response = await client.content
|
|
921
|
-
* .getCollection<BlogPost>('Blog')
|
|
922
|
-
* .limit(10)
|
|
923
|
-
* .page(2)
|
|
924
|
-
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
925
|
-
* .query(q => q.field('author').equals('John Doe'))
|
|
926
|
-
* .depth(1)
|
|
927
|
-
* .fetch();
|
|
928
|
-
*
|
|
929
|
-
* console.log(response.contentlets);
|
|
930
|
-
* ```
|
|
931
|
-
*
|
|
932
|
-
* @example Fetch blog posts with Promise chain
|
|
933
|
-
* ```typescript
|
|
934
|
-
* client.content
|
|
935
|
-
* .getCollection<BlogPost>('Blog')
|
|
936
|
-
* .limit(10)
|
|
937
|
-
* .page(2)
|
|
938
|
-
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
939
|
-
* .query(q => q.field('author').equals('John Doe'))
|
|
940
|
-
* .depth(1)
|
|
941
|
-
* .fetch()
|
|
942
|
-
* .then(response => console.log(response.contentlets))
|
|
943
|
-
* .catch(error => console.error(error));
|
|
944
|
-
* ```
|
|
945
|
-
*
|
|
946
|
-
* @example Using a custom type
|
|
947
|
-
* ```typescript
|
|
948
|
-
* interface BlogPost {
|
|
949
|
-
* summary: string;
|
|
950
|
-
* author: string;
|
|
951
|
-
* title: string;
|
|
952
|
-
* }
|
|
953
|
-
*
|
|
954
|
-
* const posts = await client.content
|
|
955
|
-
* .getCollection<BlogPost>('Blog')
|
|
956
|
-
* .limit(10)
|
|
957
|
-
* .fetch();
|
|
958
|
-
*
|
|
959
|
-
* posts.contentlets.forEach(post => {
|
|
960
|
-
* console.log(post.title, post.author, post.summary);
|
|
961
|
-
* });
|
|
962
|
-
* ```
|
|
963
|
-
*/
|
|
964
|
-
class Content {
|
|
965
|
-
/**
|
|
966
|
-
* Creates an instance of Content.
|
|
967
|
-
* @param {ClientOptions} requestOptions - The options for the client request.
|
|
968
|
-
* @param {string} serverUrl - The server URL.
|
|
969
|
-
*/
|
|
970
|
-
constructor(requestOptions, serverUrl) {
|
|
971
|
-
_Content_requestOptions.set(this, void 0);
|
|
972
|
-
_Content_serverUrl.set(this, void 0);
|
|
973
|
-
__classPrivateFieldSet(this, _Content_requestOptions, requestOptions, "f");
|
|
974
|
-
__classPrivateFieldSet(this, _Content_serverUrl, serverUrl, "f");
|
|
975
|
-
}
|
|
976
|
-
/**
|
|
977
|
-
* Takes a content type and returns a builder to filter and fetch the collection.
|
|
978
|
-
* @param {string} contentType - The content type to get the collection.
|
|
979
|
-
* @return {CollectionBuilder<T>} CollectionBuilder to filter and fetch the collection.
|
|
980
|
-
* @template T - Represents the type of the content type to fetch. Defaults to unknown.
|
|
981
|
-
* @memberof Content
|
|
982
|
-
*
|
|
983
|
-
* @example
|
|
984
|
-
* ```javascript
|
|
985
|
-
* // Using await and async
|
|
986
|
-
* const collectionResponse = await client.content
|
|
987
|
-
* .getCollection('Blog')
|
|
988
|
-
* .limit(10)
|
|
989
|
-
* .page(2)
|
|
990
|
-
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
991
|
-
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
992
|
-
* .depth(1);
|
|
993
|
-
* ```
|
|
994
|
-
* @example
|
|
995
|
-
* ```javascript
|
|
996
|
-
* // Using then and catch
|
|
997
|
-
* client.content
|
|
998
|
-
* .getCollection('Blog')
|
|
999
|
-
* .limit(10)
|
|
1000
|
-
* .page(2)
|
|
1001
|
-
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
1002
|
-
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
1003
|
-
* .depth(1)
|
|
1004
|
-
* .then((response) => {
|
|
1005
|
-
* console.log(response.contentlets);
|
|
1006
|
-
* })
|
|
1007
|
-
* .catch((error) => {
|
|
1008
|
-
* console.error(error);
|
|
1009
|
-
* });
|
|
1010
|
-
* ```
|
|
1011
|
-
* @example
|
|
1012
|
-
* ```typescript
|
|
1013
|
-
* // Using a specific type for your content
|
|
1014
|
-
*
|
|
1015
|
-
* type Blog = {
|
|
1016
|
-
* summary: string;
|
|
1017
|
-
* author: string;
|
|
1018
|
-
* title: string;
|
|
1019
|
-
* };
|
|
1020
|
-
*
|
|
1021
|
-
* client.content
|
|
1022
|
-
* .getCollection<Blog>('Blog')
|
|
1023
|
-
* .limit(10)
|
|
1024
|
-
* .page(2)
|
|
1025
|
-
* .sortBy([{ field: 'title', order: 'asc' }])
|
|
1026
|
-
* .query((queryBuilder) => queryBuilder.field('author').equals('John Doe'))
|
|
1027
|
-
* .depth(1)
|
|
1028
|
-
* .then((response) => {
|
|
1029
|
-
* response.contentlets.forEach((blog) => {
|
|
1030
|
-
* console.log(blog.title);
|
|
1031
|
-
* console.log(blog.author);
|
|
1032
|
-
* console.log(blog.summary);
|
|
1033
|
-
* });
|
|
1034
|
-
* })
|
|
1035
|
-
* .catch((error) => {
|
|
1036
|
-
* console.error(error);
|
|
1037
|
-
* });
|
|
1038
|
-
* ```
|
|
1039
|
-
*
|
|
1040
|
-
*/
|
|
1041
|
-
getCollection(contentType) {
|
|
1042
|
-
return new CollectionBuilder(__classPrivateFieldGet(this, _Content_requestOptions, "f"), __classPrivateFieldGet(this, _Content_serverUrl, "f"), contentType);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
_Content_requestOptions = new WeakMap(), _Content_serverUrl = new WeakMap();
|
|
1046
|
-
|
|
1047
|
-
/**
|
|
1048
|
-
* A record of HTTP status codes and their corresponding error messages.
|
|
1049
|
-
*
|
|
1050
|
-
* @type {Record<number, string>}
|
|
1051
|
-
* @property {string} 401 - Unauthorized. Check the token and try again.
|
|
1052
|
-
* @property {string} 403 - Forbidden. Check the permissions and try again.
|
|
1053
|
-
* @property {string} 404 - Not Found. Check the URL and try again.
|
|
1054
|
-
* @property {string} 500 - Internal Server Error. Try again later.
|
|
1055
|
-
* @property {string} 502 - Bad Gateway. Try again later.
|
|
1056
|
-
* @property {string} 503 - Service Unavailable. Try again later.
|
|
1057
|
-
*/
|
|
1058
|
-
const ErrorMessages = {
|
|
1059
|
-
401: 'Unauthorized. Check the token and try again.',
|
|
1060
|
-
403: 'Forbidden. Check the permissions and try again.',
|
|
1061
|
-
404: 'Not Found. Check the URL and try again.',
|
|
1062
|
-
500: 'Internal Server Error. Try again later.',
|
|
1063
|
-
502: 'Bad Gateway. Try again later.',
|
|
1064
|
-
503: 'Service Unavailable. Try again later.'
|
|
1065
|
-
};
|
|
3
|
+
var transforms = require('./transforms.cjs.js');
|
|
1066
4
|
|
|
1067
5
|
/**
|
|
1068
6
|
* Actions received from the dotcms editor
|
|
@@ -1098,89 +36,6 @@ exports.NOTIFY_CLIENT = void 0;
|
|
|
1098
36
|
NOTIFY_CLIENT["UVE_COPY_CONTENTLET_INLINE_EDITING_SUCCESS"] = "uve-copy-contentlet-inline-editing-success";
|
|
1099
37
|
})(exports.NOTIFY_CLIENT || (exports.NOTIFY_CLIENT = {}));
|
|
1100
38
|
|
|
1101
|
-
const INITIAL_DOT_UVE = {
|
|
1102
|
-
editContentlet,
|
|
1103
|
-
initInlineEditing,
|
|
1104
|
-
reorderMenu,
|
|
1105
|
-
lastScrollYPosition: 0
|
|
1106
|
-
};
|
|
1107
|
-
/**
|
|
1108
|
-
* Actions send to the dotcms editor
|
|
1109
|
-
*
|
|
1110
|
-
* @export
|
|
1111
|
-
* @enum {number}
|
|
1112
|
-
*/
|
|
1113
|
-
exports.CLIENT_ACTIONS = void 0;
|
|
1114
|
-
(function (CLIENT_ACTIONS) {
|
|
1115
|
-
/**
|
|
1116
|
-
* Tell the dotcms editor that page change
|
|
1117
|
-
*/
|
|
1118
|
-
CLIENT_ACTIONS["NAVIGATION_UPDATE"] = "set-url";
|
|
1119
|
-
/**
|
|
1120
|
-
* Send the element position of the rows, columnsm containers and contentlets
|
|
1121
|
-
*/
|
|
1122
|
-
CLIENT_ACTIONS["SET_BOUNDS"] = "set-bounds";
|
|
1123
|
-
/**
|
|
1124
|
-
* Send the information of the hovered contentlet
|
|
1125
|
-
*/
|
|
1126
|
-
CLIENT_ACTIONS["SET_CONTENTLET"] = "set-contentlet";
|
|
1127
|
-
/**
|
|
1128
|
-
* Tell the editor that the page is being scrolled
|
|
1129
|
-
*/
|
|
1130
|
-
CLIENT_ACTIONS["IFRAME_SCROLL"] = "scroll";
|
|
1131
|
-
/**
|
|
1132
|
-
* Tell the editor that the page has stopped scrolling
|
|
1133
|
-
*/
|
|
1134
|
-
CLIENT_ACTIONS["IFRAME_SCROLL_END"] = "scroll-end";
|
|
1135
|
-
/**
|
|
1136
|
-
* Ping the editor to see if the page is inside the editor
|
|
1137
|
-
*/
|
|
1138
|
-
CLIENT_ACTIONS["PING_EDITOR"] = "ping-editor";
|
|
1139
|
-
/**
|
|
1140
|
-
* Tell the editor to init the inline editing editor.
|
|
1141
|
-
*/
|
|
1142
|
-
CLIENT_ACTIONS["INIT_INLINE_EDITING"] = "init-inline-editing";
|
|
1143
|
-
/**
|
|
1144
|
-
* Tell the editor to open the Copy-contentlet dialog
|
|
1145
|
-
* To copy a content and then edit it inline.
|
|
1146
|
-
*/
|
|
1147
|
-
CLIENT_ACTIONS["COPY_CONTENTLET_INLINE_EDITING"] = "copy-contentlet-inline-editing";
|
|
1148
|
-
/**
|
|
1149
|
-
* Tell the editor to save inline edited contentlet
|
|
1150
|
-
*/
|
|
1151
|
-
CLIENT_ACTIONS["UPDATE_CONTENTLET_INLINE_EDITING"] = "update-contentlet-inline-editing";
|
|
1152
|
-
/**
|
|
1153
|
-
* Tell the editor to trigger a menu reorder
|
|
1154
|
-
*/
|
|
1155
|
-
CLIENT_ACTIONS["REORDER_MENU"] = "reorder-menu";
|
|
1156
|
-
/**
|
|
1157
|
-
* Tell the editor to send the page info to iframe
|
|
1158
|
-
*/
|
|
1159
|
-
CLIENT_ACTIONS["GET_PAGE_DATA"] = "get-page-data";
|
|
1160
|
-
/**
|
|
1161
|
-
* Tell the editor an user send a graphql query
|
|
1162
|
-
*/
|
|
1163
|
-
CLIENT_ACTIONS["CLIENT_READY"] = "client-ready";
|
|
1164
|
-
/**
|
|
1165
|
-
* Tell the editor to edit a contentlet
|
|
1166
|
-
*/
|
|
1167
|
-
CLIENT_ACTIONS["EDIT_CONTENTLET"] = "edit-contentlet";
|
|
1168
|
-
/**
|
|
1169
|
-
* Tell the editor to do nothing
|
|
1170
|
-
*/
|
|
1171
|
-
CLIENT_ACTIONS["NOOP"] = "noop";
|
|
1172
|
-
})(exports.CLIENT_ACTIONS || (exports.CLIENT_ACTIONS = {}));
|
|
1173
|
-
/**
|
|
1174
|
-
* Post message to dotcms page editor
|
|
1175
|
-
*
|
|
1176
|
-
* @export
|
|
1177
|
-
* @template T
|
|
1178
|
-
* @param {PostMessageProps<T>} message
|
|
1179
|
-
*/
|
|
1180
|
-
function postMessageToEditor(message) {
|
|
1181
|
-
window.parent.postMessage(message, '*');
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
39
|
/**
|
|
1185
40
|
* Calculates the bounding information for each page element within the given containers.
|
|
1186
41
|
*
|
|
@@ -1663,6 +518,89 @@ function destroyEditor() {
|
|
|
1663
518
|
});
|
|
1664
519
|
}
|
|
1665
520
|
|
|
521
|
+
const INITIAL_DOT_UVE = {
|
|
522
|
+
editContentlet,
|
|
523
|
+
initInlineEditing,
|
|
524
|
+
reorderMenu,
|
|
525
|
+
lastScrollYPosition: 0
|
|
526
|
+
};
|
|
527
|
+
/**
|
|
528
|
+
* Actions send to the dotcms editor
|
|
529
|
+
*
|
|
530
|
+
* @export
|
|
531
|
+
* @enum {number}
|
|
532
|
+
*/
|
|
533
|
+
exports.CLIENT_ACTIONS = void 0;
|
|
534
|
+
(function (CLIENT_ACTIONS) {
|
|
535
|
+
/**
|
|
536
|
+
* Tell the dotcms editor that page change
|
|
537
|
+
*/
|
|
538
|
+
CLIENT_ACTIONS["NAVIGATION_UPDATE"] = "set-url";
|
|
539
|
+
/**
|
|
540
|
+
* Send the element position of the rows, columnsm containers and contentlets
|
|
541
|
+
*/
|
|
542
|
+
CLIENT_ACTIONS["SET_BOUNDS"] = "set-bounds";
|
|
543
|
+
/**
|
|
544
|
+
* Send the information of the hovered contentlet
|
|
545
|
+
*/
|
|
546
|
+
CLIENT_ACTIONS["SET_CONTENTLET"] = "set-contentlet";
|
|
547
|
+
/**
|
|
548
|
+
* Tell the editor that the page is being scrolled
|
|
549
|
+
*/
|
|
550
|
+
CLIENT_ACTIONS["IFRAME_SCROLL"] = "scroll";
|
|
551
|
+
/**
|
|
552
|
+
* Tell the editor that the page has stopped scrolling
|
|
553
|
+
*/
|
|
554
|
+
CLIENT_ACTIONS["IFRAME_SCROLL_END"] = "scroll-end";
|
|
555
|
+
/**
|
|
556
|
+
* Ping the editor to see if the page is inside the editor
|
|
557
|
+
*/
|
|
558
|
+
CLIENT_ACTIONS["PING_EDITOR"] = "ping-editor";
|
|
559
|
+
/**
|
|
560
|
+
* Tell the editor to init the inline editing editor.
|
|
561
|
+
*/
|
|
562
|
+
CLIENT_ACTIONS["INIT_INLINE_EDITING"] = "init-inline-editing";
|
|
563
|
+
/**
|
|
564
|
+
* Tell the editor to open the Copy-contentlet dialog
|
|
565
|
+
* To copy a content and then edit it inline.
|
|
566
|
+
*/
|
|
567
|
+
CLIENT_ACTIONS["COPY_CONTENTLET_INLINE_EDITING"] = "copy-contentlet-inline-editing";
|
|
568
|
+
/**
|
|
569
|
+
* Tell the editor to save inline edited contentlet
|
|
570
|
+
*/
|
|
571
|
+
CLIENT_ACTIONS["UPDATE_CONTENTLET_INLINE_EDITING"] = "update-contentlet-inline-editing";
|
|
572
|
+
/**
|
|
573
|
+
* Tell the editor to trigger a menu reorder
|
|
574
|
+
*/
|
|
575
|
+
CLIENT_ACTIONS["REORDER_MENU"] = "reorder-menu";
|
|
576
|
+
/**
|
|
577
|
+
* Tell the editor to send the page info to iframe
|
|
578
|
+
*/
|
|
579
|
+
CLIENT_ACTIONS["GET_PAGE_DATA"] = "get-page-data";
|
|
580
|
+
/**
|
|
581
|
+
* Tell the editor an user send a graphql query
|
|
582
|
+
*/
|
|
583
|
+
CLIENT_ACTIONS["CLIENT_READY"] = "client-ready";
|
|
584
|
+
/**
|
|
585
|
+
* Tell the editor to edit a contentlet
|
|
586
|
+
*/
|
|
587
|
+
CLIENT_ACTIONS["EDIT_CONTENTLET"] = "edit-contentlet";
|
|
588
|
+
/**
|
|
589
|
+
* Tell the editor to do nothing
|
|
590
|
+
*/
|
|
591
|
+
CLIENT_ACTIONS["NOOP"] = "noop";
|
|
592
|
+
})(exports.CLIENT_ACTIONS || (exports.CLIENT_ACTIONS = {}));
|
|
593
|
+
/**
|
|
594
|
+
* Post message to dotcms page editor
|
|
595
|
+
*
|
|
596
|
+
* @export
|
|
597
|
+
* @template T
|
|
598
|
+
* @param {PostMessageProps<T>} message
|
|
599
|
+
*/
|
|
600
|
+
function postMessageToEditor(message) {
|
|
601
|
+
window.parent.postMessage(message, '*');
|
|
602
|
+
}
|
|
603
|
+
|
|
1666
604
|
var _DotCmsClient_config, _DotCmsClient_requestOptions, _DotCmsClient_listeners;
|
|
1667
605
|
function getHostURL(url) {
|
|
1668
606
|
try {
|
|
@@ -1758,18 +696,18 @@ class DotCmsClient {
|
|
|
1758
696
|
queryParamsObj[key] = String(value);
|
|
1759
697
|
}
|
|
1760
698
|
}
|
|
1761
|
-
const queryHostId = options.siteId ?? __classPrivateFieldGet(this, _DotCmsClient_config, "f").siteId ?? '';
|
|
699
|
+
const queryHostId = options.siteId ?? transforms.__classPrivateFieldGet(this, _DotCmsClient_config, "f").siteId ?? '';
|
|
1762
700
|
if (queryHostId) {
|
|
1763
701
|
queryParamsObj['host_id'] = queryHostId;
|
|
1764
702
|
}
|
|
1765
703
|
const queryParams = new URLSearchParams(queryParamsObj).toString();
|
|
1766
704
|
const formattedPath = options.path.startsWith('/') ? options.path : `/${options.path}`;
|
|
1767
|
-
const url = `${__classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl}/api/v1/page/json${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
|
|
1768
|
-
const response = await fetch(url, __classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"));
|
|
705
|
+
const url = `${transforms.__classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl}/api/v1/page/json${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
|
|
706
|
+
const response = await fetch(url, transforms.__classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"));
|
|
1769
707
|
if (!response.ok) {
|
|
1770
708
|
const error = {
|
|
1771
709
|
status: response.status,
|
|
1772
|
-
message: ErrorMessages[response.status] || response.statusText
|
|
710
|
+
message: transforms.ErrorMessages[response.status] || response.statusText
|
|
1773
711
|
};
|
|
1774
712
|
console.error(error);
|
|
1775
713
|
throw error;
|
|
@@ -1802,7 +740,7 @@ class DotCmsClient {
|
|
|
1802
740
|
}
|
|
1803
741
|
};
|
|
1804
742
|
window.addEventListener('message', messageCallback);
|
|
1805
|
-
__classPrivateFieldGet(this, _DotCmsClient_listeners, "f").push({ event: 'message', callback: messageCallback, action });
|
|
743
|
+
transforms.__classPrivateFieldGet(this, _DotCmsClient_listeners, "f").push({ event: 'message', callback: messageCallback, action });
|
|
1806
744
|
}
|
|
1807
745
|
},
|
|
1808
746
|
/**
|
|
@@ -1816,11 +754,11 @@ class DotCmsClient {
|
|
|
1816
754
|
* ```
|
|
1817
755
|
*/
|
|
1818
756
|
off: (action) => {
|
|
1819
|
-
const listenerIndex = __classPrivateFieldGet(this, _DotCmsClient_listeners, "f").findIndex((listener) => listener.action === action);
|
|
757
|
+
const listenerIndex = transforms.__classPrivateFieldGet(this, _DotCmsClient_listeners, "f").findIndex((listener) => listener.action === action);
|
|
1820
758
|
if (listenerIndex !== -1) {
|
|
1821
|
-
const listener = __classPrivateFieldGet(this, _DotCmsClient_listeners, "f")[listenerIndex];
|
|
759
|
+
const listener = transforms.__classPrivateFieldGet(this, _DotCmsClient_listeners, "f")[listenerIndex];
|
|
1822
760
|
window.removeEventListener(listener.event, listener.callback);
|
|
1823
|
-
__classPrivateFieldGet(this, _DotCmsClient_listeners, "f").splice(listenerIndex, 1);
|
|
761
|
+
transforms.__classPrivateFieldGet(this, _DotCmsClient_listeners, "f").splice(listenerIndex, 1);
|
|
1824
762
|
}
|
|
1825
763
|
}
|
|
1826
764
|
};
|
|
@@ -1854,8 +792,8 @@ class DotCmsClient {
|
|
|
1854
792
|
const queryParams = new URLSearchParams(queryParamsObj).toString();
|
|
1855
793
|
// Format the URL correctly depending on the 'path' value
|
|
1856
794
|
const formattedPath = path === '/' ? '/' : `/${path}`;
|
|
1857
|
-
const url = `${__classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl}/api/v1/nav${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
|
|
1858
|
-
const response = await fetch(url, __classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"));
|
|
795
|
+
const url = `${transforms.__classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl}/api/v1/nav${formattedPath}${queryParams ? `?${queryParams}` : ''}`;
|
|
796
|
+
const response = await fetch(url, transforms.__classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"));
|
|
1859
797
|
return response.json();
|
|
1860
798
|
}
|
|
1861
799
|
};
|
|
@@ -1869,18 +807,18 @@ class DotCmsClient {
|
|
|
1869
807
|
if (!config.authToken) {
|
|
1870
808
|
throw new Error("Invalid configuration - 'authToken' is required");
|
|
1871
809
|
}
|
|
1872
|
-
__classPrivateFieldSet(this, _DotCmsClient_config, {
|
|
810
|
+
transforms.__classPrivateFieldSet(this, _DotCmsClient_config, {
|
|
1873
811
|
...config,
|
|
1874
812
|
dotcmsUrl: this.dotcmsUrl
|
|
1875
813
|
}, "f");
|
|
1876
|
-
__classPrivateFieldSet(this, _DotCmsClient_requestOptions, {
|
|
1877
|
-
...__classPrivateFieldGet(this, _DotCmsClient_config, "f").requestOptions,
|
|
814
|
+
transforms.__classPrivateFieldSet(this, _DotCmsClient_requestOptions, {
|
|
815
|
+
...transforms.__classPrivateFieldGet(this, _DotCmsClient_config, "f").requestOptions,
|
|
1878
816
|
headers: {
|
|
1879
|
-
Authorization: `Bearer ${__classPrivateFieldGet(this, _DotCmsClient_config, "f").authToken}`,
|
|
1880
|
-
...__classPrivateFieldGet(this, _DotCmsClient_config, "f").requestOptions?.headers
|
|
817
|
+
Authorization: `Bearer ${transforms.__classPrivateFieldGet(this, _DotCmsClient_config, "f").authToken}`,
|
|
818
|
+
...transforms.__classPrivateFieldGet(this, _DotCmsClient_config, "f").requestOptions?.headers
|
|
1881
819
|
}
|
|
1882
820
|
}, "f");
|
|
1883
|
-
this.content = new Content(__classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"), __classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl);
|
|
821
|
+
this.content = new transforms.Content(transforms.__classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"), transforms.__classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl);
|
|
1884
822
|
}
|
|
1885
823
|
/**
|
|
1886
824
|
* Initializes the DotCmsClient instance with the provided configuration.
|
|
@@ -1905,7 +843,7 @@ class DotCmsClient {
|
|
|
1905
843
|
* @returns {string} - The DotCMS URL.
|
|
1906
844
|
*/
|
|
1907
845
|
static get dotcmsUrl() {
|
|
1908
|
-
return (this.instance && __classPrivateFieldGet(this.instance, _DotCmsClient_config, "f").dotcmsUrl) || '';
|
|
846
|
+
return (this.instance && transforms.__classPrivateFieldGet(this.instance, _DotCmsClient_config, "f").dotcmsUrl) || '';
|
|
1909
847
|
}
|
|
1910
848
|
/**
|
|
1911
849
|
* Throws an error if the path is not valid.
|
|
@@ -1930,80 +868,6 @@ class DotCmsClient {
|
|
|
1930
868
|
}
|
|
1931
869
|
_DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
|
|
1932
870
|
|
|
1933
|
-
/**
|
|
1934
|
-
* Transforms a GraphQL Page response to a Page Entity.
|
|
1935
|
-
*
|
|
1936
|
-
* @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
|
|
1937
|
-
* @returns {object|null} The transformed Page Entity or null if the page is not present.
|
|
1938
|
-
*
|
|
1939
|
-
* @example
|
|
1940
|
-
* ```ts
|
|
1941
|
-
* const pageEntity = graphqlToPageEntity(graphQLPageResponse);
|
|
1942
|
-
* ```
|
|
1943
|
-
*/
|
|
1944
|
-
const graphqlToPageEntity = (graphQLPageResponse) => {
|
|
1945
|
-
const { page } = graphQLPageResponse;
|
|
1946
|
-
// If there is no page, return null
|
|
1947
|
-
if (!page) {
|
|
1948
|
-
return null;
|
|
1949
|
-
}
|
|
1950
|
-
const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
|
|
1951
|
-
const data = (_map || {});
|
|
1952
|
-
return {
|
|
1953
|
-
layout,
|
|
1954
|
-
template,
|
|
1955
|
-
viewAs,
|
|
1956
|
-
urlContentMap,
|
|
1957
|
-
site,
|
|
1958
|
-
page: {
|
|
1959
|
-
...data,
|
|
1960
|
-
...pageAsset
|
|
1961
|
-
},
|
|
1962
|
-
containers: parseContainers(containers)
|
|
1963
|
-
};
|
|
1964
|
-
};
|
|
1965
|
-
/**
|
|
1966
|
-
* Parses the containers from the GraphQL response.
|
|
1967
|
-
*
|
|
1968
|
-
* @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
|
|
1969
|
-
* @returns {Record<string, unknown>} The parsed containers.
|
|
1970
|
-
*/
|
|
1971
|
-
const parseContainers = (containers = []) => {
|
|
1972
|
-
return containers.reduce((acc, container) => {
|
|
1973
|
-
const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
|
|
1974
|
-
const key = (path || identifier);
|
|
1975
|
-
acc[key] = {
|
|
1976
|
-
containerStructures,
|
|
1977
|
-
container: {
|
|
1978
|
-
path,
|
|
1979
|
-
identifier,
|
|
1980
|
-
...rest
|
|
1981
|
-
},
|
|
1982
|
-
contentlets: parseContentletsToUuidMap(containerContentlets)
|
|
1983
|
-
};
|
|
1984
|
-
return acc;
|
|
1985
|
-
}, {});
|
|
1986
|
-
};
|
|
1987
|
-
/**
|
|
1988
|
-
* Parses the contentlets from the GraphQL response.
|
|
1989
|
-
*
|
|
1990
|
-
* @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
|
|
1991
|
-
* @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
|
|
1992
|
-
*/
|
|
1993
|
-
const parseContentletsToUuidMap = (containerContentlets = []) => {
|
|
1994
|
-
return containerContentlets.reduce((acc, containerContentlet) => {
|
|
1995
|
-
const { uuid, contentlets } = containerContentlet;
|
|
1996
|
-
// TODO: This is a temporary solution, we need to find a better way to handle this.
|
|
1997
|
-
acc[uuid] = contentlets.map(({ _map = {}, ...rest }) => {
|
|
1998
|
-
return {
|
|
1999
|
-
..._map,
|
|
2000
|
-
...rest
|
|
2001
|
-
};
|
|
2002
|
-
});
|
|
2003
|
-
return acc;
|
|
2004
|
-
}, {});
|
|
2005
|
-
};
|
|
2006
|
-
|
|
2007
871
|
/**
|
|
2008
872
|
* Generates the page request parameters to be used in the API call.
|
|
2009
873
|
*
|
|
@@ -2037,11 +901,11 @@ const getPageRequestParams = ({ path = '', params = {} }) => {
|
|
|
2037
901
|
};
|
|
2038
902
|
};
|
|
2039
903
|
|
|
904
|
+
exports.graphqlToPageEntity = transforms.graphqlToPageEntity;
|
|
2040
905
|
exports.DotCmsClient = DotCmsClient;
|
|
2041
906
|
exports.destroyEditor = destroyEditor;
|
|
2042
907
|
exports.editContentlet = editContentlet;
|
|
2043
908
|
exports.getPageRequestParams = getPageRequestParams;
|
|
2044
|
-
exports.graphqlToPageEntity = graphqlToPageEntity;
|
|
2045
909
|
exports.initEditor = initEditor;
|
|
2046
910
|
exports.initInlineEditing = initInlineEditing;
|
|
2047
911
|
exports.isInsideEditor = isInsideEditor;
|