@dotcms/client 0.0.1-alpha.37 → 0.0.1-alpha.38

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.esm.js CHANGED
@@ -35,25 +35,34 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
35
35
 
36
36
  var _Field_query;
37
37
  /**
38
- * 'Field' class is used to build a query with a field.
38
+ * The `Field` class is used to build a query with a specific field.
39
39
  * A Lucene Field is a key used to search for a specific value in a document.
40
40
  *
41
41
  * @export
42
42
  * @class Field
43
43
  */
44
44
  class Field {
45
+ /**
46
+ * Creates an instance of the `Field` class.
47
+ *
48
+ * @param {string} query - The initial query string.
49
+ */
45
50
  constructor(query) {
46
51
  this.query = query;
47
52
  _Field_query.set(this, '');
48
53
  __classPrivateFieldSet(this, _Field_query, this.query, "f");
49
54
  }
50
55
  /**
51
- * This method appends to the query a term that should be included in the search..
56
+ * Appends a term to the query that should be included in the search.
52
57
  *
53
- * Ex: myValue or "My value"
58
+ * @example
59
+ * ```typescript
60
+ * const field = new Field("+myField");
61
+ * field.equals("myValue");
62
+ * ```
54
63
  *
55
64
  * @param {string} term - The term that should be included in the search.
56
- * @return {*} {Equals} - An instance of Equals.
65
+ * @return {Equals} - An instance of `Equals`.
57
66
  * @memberof Field
58
67
  */
59
68
  equals(term) {
@@ -78,7 +87,11 @@ class NotOperand {
78
87
  /**
79
88
  * This method appends to the query a term that should be included in the search.
80
89
  *
81
- * Ex: myValue or "My value"
90
+ * @example
91
+ * ```typescript
92
+ * const notOperand = new NotOperand("+myField");
93
+ * notOperand.equals("myValue");
94
+ * ```
82
95
  *
83
96
  * @param {string} term - The term that should be included in the search.
84
97
  * @return {*} {Equals} - An instance of Equals.
@@ -158,6 +171,11 @@ var OPERAND;
158
171
  /**
159
172
  * This function removes extra spaces from a string.
160
173
  *
174
+ * @example
175
+ * ```ts
176
+ * sanitizeQuery(" my query "); // Output: "my query"
177
+ * ```
178
+ *
161
179
  * @export
162
180
  * @param {string} str
163
181
  * @return {*} {string}
@@ -169,6 +187,12 @@ function sanitizeQuery(str) {
169
187
  * This function sanitizes a term by adding quotes if it contains spaces.
170
188
  * In lucene, a term with spaces should be enclosed in quotes.
171
189
  *
190
+ * @example
191
+ * ```ts
192
+ * sanitizePhrases(`my term`); // Output: `"my term"`
193
+ * sanitizePhrases(`myterm`); // Output: `myterm`
194
+ * ```
195
+ *
172
196
  * @export
173
197
  * @param {string} term
174
198
  * @return {*} {string}
@@ -180,6 +204,11 @@ function sanitizePhrases(term) {
180
204
  * This function builds a term to be used in a lucene query.
181
205
  * We need to sanitize the term before adding it to the query.
182
206
  *
207
+ * @example
208
+ * ```ts
209
+ * const equals = buildEquals("+myField: ", "myValue"); // Current query: "+myField: myValue"
210
+ * ```
211
+ *
183
212
  * @export
184
213
  * @param {string} query
185
214
  * @param {string} term
@@ -193,6 +222,12 @@ function buildEquals(query, term) {
193
222
  * This function builds a term to be used in a lucene query.
194
223
  * We need to sanitize the raw query before adding it to the query.
195
224
  *
225
+ * @example
226
+ * ```ts
227
+ * const query = "+myField: myValue";
228
+ * const field = buildRawEquals(query, "-myField2: myValue2"); // Current query: "+myField: myValue -myField2: myValue"
229
+ * ```
230
+ *
196
231
  * @export
197
232
  * @param {string} query
198
233
  * @param {string} raw
@@ -206,6 +241,11 @@ function buildRawEquals(query, raw) {
206
241
  * This function builds a field to be used in a lucene query.
207
242
  * We need to format the field before adding it to the query.
208
243
  *
244
+ * @example
245
+ * ```ts
246
+ * const field = buildField("+myField: ", "myValue"); // Current query: "+myField: myValue"
247
+ * ```
248
+ *
209
249
  * @export
210
250
  * @param {string} query
211
251
  * @param {string} field
@@ -219,6 +259,12 @@ function buildField(query, field) {
219
259
  * This function builds an exclude field to be used in a lucene query.
220
260
  * We need to format the field before adding it to the query.
221
261
  *
262
+ * @example
263
+ * ```ts
264
+ * const query = "+myField: myValue";
265
+ * const field = buildExcludeField(query, "myField2"); // Current query: "+myField: myValue -myField2:"
266
+ * ```
267
+ *
222
268
  * @export
223
269
  * @param {string} query
224
270
  * @param {string} field
@@ -232,6 +278,18 @@ function buildExcludeField(query, field) {
232
278
  * This function builds an operand to be used in a lucene query.
233
279
  * We need to format the operand before adding it to the query.
234
280
  *
281
+ * @example
282
+ * <caption>E.g. Using the AND operand</caption>
283
+ * ```ts
284
+ * const query = "+myField: myValue";
285
+ * const field = buildOperand(query, OPERAND.AND); // Current query: "+myField: myValue AND"
286
+ * ```
287
+ * @example
288
+ * <caption>E.g. Using the OR operand</caption>
289
+ * ```ts
290
+ * const query = "+myField: myValue";
291
+ * const field = buildOperand(query, OPERAND.OR); // Current query: "+myField: myValue OR"
292
+ * ```
235
293
  * @export
236
294
  * @param {string} query
237
295
  * @param {OPERAND} operand
@@ -245,6 +303,12 @@ function buildOperand(query, operand) {
245
303
  * This function builds a NOT operand to be used in a lucene query.
246
304
  * We need to format the operand before adding it to the query.
247
305
  *
306
+ * @example
307
+ * ```ts
308
+ * const query = "+myField: myValue";
309
+ * const field = buildNotOperand(query); // Current query: "+myField: myValue NOT"
310
+ * ```
311
+ *
248
312
  * @export
249
313
  * @param {string} query
250
314
  * @return {*} {NotOperand}
@@ -273,7 +337,11 @@ class Equals {
273
337
  /**
274
338
  * This method appends to the query a term that should be excluded in the search.
275
339
  *
276
- * Ex: "-myValue"
340
+ * @example
341
+ * ```ts
342
+ * const equals = new Equals("+myField: myValue");
343
+ * equals.excludeField("myField2").equals("myValue2"); // Current query: "+myField: myValue -myField2: myValue2"
344
+ * ```
277
345
  *
278
346
  * @param {string} field - The field that should be excluded in the search.
279
347
  * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
@@ -285,8 +353,11 @@ class Equals {
285
353
  /**
286
354
  * This method appends to the query a field that should be included in the search.
287
355
  *
288
- * Ex: "+myField:"
289
- *
356
+ * @example
357
+ * ```ts
358
+ * const equals = new Equals("+myField: myValue");
359
+ * equals.field("myField2").equals("myValue2"); // Current query: "+myField: myValue +myField2: myValue2"
360
+ *```
290
361
  * @param {string} field - The field that should be included in the search.
291
362
  * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
292
363
  * @memberof Equal
@@ -297,7 +368,12 @@ class Equals {
297
368
  /**
298
369
  * This method appends to the query an operand to use logic operators in the query.
299
370
  *
300
- * Ex: "OR"
371
+ * @example
372
+ * @example
373
+ * ```ts
374
+ * const equals = new Equals("+myField: myValue");
375
+ * equals.or().field("myField2").equals("myValue2"); // Current query: "+myField: myValue OR +myField2: myValue2"
376
+ * ```
301
377
  *
302
378
  * @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
303
379
  * @memberof Equal
@@ -308,7 +384,11 @@ class Equals {
308
384
  /**
309
385
  * This method appends to the query an operand to use logic operators in the query.
310
386
  *
311
- * Ex: "AND"
387
+ * @example
388
+ * ```ts
389
+ * const equals = new Equals("+myField: myValue");
390
+ * equals.and().field("myField2").equals("myValue2"); // Current query: "+myField: myValue AND +myField2: myValue2"
391
+ * ```
312
392
  *
313
393
  * @return {*} {Operand} - An instance of a Lucene Operand. An operand is a logical operator used to combine terms or phrases in a query.
314
394
  * @memberof Equal
@@ -319,7 +399,11 @@ class Equals {
319
399
  /**
320
400
  * This method appends to the query an operand to use logic operators in the query.
321
401
  *
322
- * Ex: "NOT"
402
+ * @example
403
+ * ```ts
404
+ * const equals = new Equals("+myField: myValue");
405
+ * equals.not().field("myField").equals("myValue2"); // Current query: "+myField: myValue NOT +myField: myValue2"
406
+ * ```
323
407
  *
324
408
  * @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.
325
409
  * @memberof Equal
@@ -332,7 +416,12 @@ class Equals {
332
416
  * This raw query should end in a Lucene Equal.
333
417
  * This method is useful when you want to append a complex query or an already written query to the query builder.
334
418
  *
335
- * Ex: "+myField: value AND (someOtherValue OR anotherValue)"
419
+ * @example
420
+ * ```ts
421
+ * // This builds the follow raw query "+myField: value AND (someOtherValue OR anotherValue)"
422
+ * const equals = new Equals("+myField: value");
423
+ * equals.raw("+myField2: value2"); // Current query: "+myField: value +myField2: anotherValue"
424
+ * ```
336
425
  *
337
426
  * @param {string} query - A raw query string.
338
427
  * @return {*} {Equal} - An instance of a Lucene Equal. A term is a value used to search for a specific value in a document.
@@ -344,6 +433,12 @@ class Equals {
344
433
  /**
345
434
  * This method returns the final query string.
346
435
  *
436
+ * @example
437
+ * ```ts
438
+ * const equals = new Equals("+myField: myValue");
439
+ * equals.field("myField2").equals("myValue2").build(); // Returns "+myField: myValue +myField2: myValue2"
440
+ * ```
441
+ *
347
442
  * @return {*} {string} - The final query string.
348
443
  * @memberof Equal
349
444
  */
@@ -356,7 +451,29 @@ _Equals_query = new WeakMap();
356
451
  var _QueryBuilder_query;
357
452
  /**
358
453
  * 'QueryBuilder' Is a Typescript class that provides the ability to build a query string using the Lucene syntax in a more readable way.
454
+ * @example
455
+ * ```ts
456
+ * const qb = new QueryBuilder();
457
+ * const query = qb
458
+ * .field('contentType')
459
+ * .equals('Blog')
460
+ * .field('conhost')
461
+ * .equals('my-super-cool-site')
462
+ * .build(); // Output: `+contentType:Blog +conhost:my-super-cool-site"`
463
+ * ```
359
464
  *
465
+ * @example
466
+ * ```ts
467
+ * const qb = new QueryBuilder();
468
+ * const query = qb
469
+ * .field('contentType')
470
+ * .equals('Blog')
471
+ * .field('title')
472
+ * .equals('Football')
473
+ * .excludeField('summary')
474
+ * .equals('Lionel Messi')
475
+ * .build(); // Output: `+contentType:Blog +title:Football -summary:"Lionel Messi"`
476
+ * ```
360
477
  * @export
361
478
  * @class QueryBuilder
362
479
  */
@@ -367,7 +484,11 @@ class QueryBuilder {
367
484
  /**
368
485
  * This method appends to the query a field that should be included in the search.
369
486
  *
370
- * Ex: "+myField:"
487
+ * @example
488
+ * ```ts
489
+ * const qb = new QueryBuilder();
490
+ * qb.field("+myField: ", "myValue"); // Current query: "+myField: myValue"
491
+ * ```
371
492
  *
372
493
  * @param {string} field - The field that should be included in the search.
373
494
  * @return {*} {Field} - An instance of a Lucene Field. A field is a key used to search for a specific value in a document.
@@ -379,7 +500,11 @@ class QueryBuilder {
379
500
  /**
380
501
  * This method appends to the query a field that should be excluded from the search.
381
502
  *
382
- * Ex: "-myField:"
503
+ * @example
504
+ * ```ts
505
+ * const qb = new QueryBuilder();
506
+ * qb.excludeField("myField").equals("myValue"); // Current query: "-myField: myValue"
507
+ * ```
383
508
  *
384
509
  * @param {string} field - The field that should be excluded from the search.
385
510
  * @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.
@@ -393,7 +518,11 @@ class QueryBuilder {
393
518
  * This raw query should end in Equals.
394
519
  * This method is useful when you want to append a complex query or an already written query to the query builder.
395
520
  *
396
- * Ex: "+myField: value AND (someOtherValue OR anotherValue)"
521
+ * @example
522
+ * ```ts
523
+ * const qb = new QueryBuilder();
524
+ * qb.raw("+myField: value AND (someOtherValue OR anotherValue)"); // Current query: "+myField: value AND (someOtherValue OR anotherValue)"
525
+ * ```
397
526
  *
398
527
  * @param {string} query - A raw query string.
399
528
  * @return {*} {Equals} - An instance of Equals. A term is a value used to search for a specific value in a document.
@@ -405,38 +534,62 @@ class QueryBuilder {
405
534
  }
406
535
  _QueryBuilder_query = new WeakMap();
407
536
 
408
- // Fields that we don't want to format when sanitizing the query
537
+ /**
538
+ * Default variant identifier used in the application.
539
+ */
540
+ /**
541
+ * Fields that should not be formatted when sanitizing the query.
542
+ * These fields are essential for maintaining the integrity of the content type.
543
+ */
409
544
  const CONTENT_TYPE_MAIN_FIELDS = ['live', 'variant', 'contentType', 'languageId'];
545
+ /**
546
+ * URL endpoint for the content API search functionality.
547
+ */
410
548
  const CONTENT_API_URL = '/api/content/_search';
411
549
 
412
550
  /**
551
+ * @description
413
552
  * Sanitizes the query for the given content type.
414
- * It replaces the fields that are not contentType fields with the correct format.
553
+ * It replaces the fields that are not content type fields with the correct format.
415
554
  * Example: +field: -> +contentTypeVar.field:
416
555
  *
556
+ * @example
557
+ *
558
+ * ```ts
559
+ * const query = '+field: value';
560
+ * const contentType = 'contentTypeVar';
561
+ * const sanitizedQuery = sanitizeQueryForContentType(query, contentType); // Output: '+contentTypeVar.field: value'
562
+ * ```
417
563
  *
418
564
  * @export
419
- * @param {string} query
420
- * @param {string} contentType
421
- * @return {*} {string}
565
+ * @param {string} query - The query string to be sanitized.
566
+ * @param {string} contentType - The content type to be used for formatting the fields.
567
+ * @returns {string} The sanitized query string.
422
568
  */
423
569
  function sanitizeQueryForContentType(query, contentType) {
424
570
  return query.replace(/\+([^+:]*?):/g, (original, field) => {
425
- return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not contentType fields
571
+ return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not content type fields
426
572
  ? `+${contentType}.${field}:` // Should have this format: +contentTypeVar.field:
427
- : original; // Return the field if it is a contentType field
573
+ : original; // Return the field if it is a content type field
428
574
  });
429
575
  }
430
576
 
431
577
  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;
432
578
  /**
433
- * Creates a Builder to filter and fetch content from the content API for an specific content type
579
+ * Creates a Builder to filter and fetch content from the content API for a specific content type.
434
580
  *
435
581
  * @export
436
582
  * @class CollectionBuilder
437
- * @template T Represents the type of the content type to fetch. Defaults to unknown
583
+ * @template T Represents the type of the content type to fetch. Defaults to unknown.
438
584
  */
439
585
  class CollectionBuilder {
586
+ /**
587
+ * Creates an instance of CollectionBuilder.
588
+ * @param {ClientOptions} requestOptions Options for the client request.
589
+ * @param {string} serverUrl The server URL.
590
+ * @param {string} contentType The content type to fetch.
591
+ * @memberof CollectionBuilder
592
+ */
440
593
  constructor(requestOptions, serverUrl, contentType) {
441
594
  _CollectionBuilder_page.set(this, 1);
442
595
  _CollectionBuilder_limit.set(this, 10);
@@ -454,11 +607,11 @@ class CollectionBuilder {
454
607
  __classPrivateFieldSet(this, _CollectionBuilder_requestOptions, requestOptions, "f");
455
608
  __classPrivateFieldSet(this, _CollectionBuilder_serverUrl, serverUrl, "f");
456
609
  __classPrivateFieldSet(this, _CollectionBuilder_contentType, contentType, "f");
457
- // We need to build the default query with the contentType field
610
+ // Build the default query with the contentType field
458
611
  __classPrivateFieldSet(this, _CollectionBuilder_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _CollectionBuilder_contentType, "f")), "f");
459
612
  }
460
613
  /**
461
- * This method returns the sort query in this format: field order, field order, ...
614
+ * Returns the sort query in the format: field order, field order, ...
462
615
  *
463
616
  * @readonly
464
617
  * @private
@@ -467,15 +620,28 @@ class CollectionBuilder {
467
620
  get sort() {
468
621
  return __classPrivateFieldGet(this, _CollectionBuilder_sortBy, "f")?.map((sort) => `${sort.field} ${sort.order}`).join(',');
469
622
  }
623
+ /**
624
+ * Returns the offset for pagination.
625
+ *
626
+ * @readonly
627
+ * @private
628
+ * @memberof CollectionBuilder
629
+ */
470
630
  get offset() {
471
- // This could end in an empty response
472
631
  return __classPrivateFieldGet(this, _CollectionBuilder_limit, "f") * (__classPrivateFieldGet(this, _CollectionBuilder_page, "f") - 1);
473
632
  }
633
+ /**
634
+ * Returns the full URL for the content API.
635
+ *
636
+ * @readonly
637
+ * @private
638
+ * @memberof CollectionBuilder
639
+ */
474
640
  get url() {
475
641
  return `${__classPrivateFieldGet(this, _CollectionBuilder_serverUrl, "f")}${CONTENT_API_URL}`;
476
642
  }
477
643
  /**
478
- * This method returns the current query built
644
+ * Returns the current query built.
479
645
  *
480
646
  * @readonly
481
647
  * @private
@@ -485,13 +651,17 @@ class CollectionBuilder {
485
651
  return __classPrivateFieldGet(this, _CollectionBuilder_query, "f") ?? __classPrivateFieldGet(this, _CollectionBuilder_defaultQuery, "f");
486
652
  }
487
653
  /**
488
- * Takes a language id and filters the content by that language.
489
- *
490
- * The language id defaults to 1
654
+ * Filters the content by the specified language ID.
491
655
  *
656
+ * @example
657
+ * ```typescript
658
+ * const client = new DotCMSClient(config);
659
+ * const collectionBuilder = client.content.getCollection("Blog");
660
+ * collectionBuilder.language(1);
661
+ * ```
492
662
  *
493
- * @param {number | string} languageId The language id to filter the content by
494
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
663
+ * @param {number | string} languageId The language ID to filter the content by.
664
+ * @return {CollectionBuilder} A CollectionBuilder instance.
495
665
  * @memberof CollectionBuilder
496
666
  */
497
667
  language(languageId) {
@@ -499,9 +669,11 @@ class CollectionBuilder {
499
669
  return this;
500
670
  }
501
671
  /**
502
- * The retrieved content will have the rendered HTML
672
+ * Setting this to true will server side render (using velocity) any widgets that are returned by the content query.
503
673
  *
504
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
674
+ * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
675
+ *
676
+ * @return {CollectionBuilder} A CollectionBuilder instance.
505
677
  * @memberof CollectionBuilder
506
678
  */
507
679
  render() {
@@ -509,19 +681,18 @@ class CollectionBuilder {
509
681
  return this;
510
682
  }
511
683
  /**
512
- * Takes an array of constrains to sort the content by field an specific order
684
+ * Sorts the content by the specified fields and orders.
513
685
  *
514
686
  * @example
515
- * ```javascript
516
- * // This will sort the content by title in ascending order
517
- * // and by modDate in descending order
518
- * const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }]
519
- *
520
- * client.content.getCollection("Blog").sortBy(sortBy)
521
- *```
687
+ * ```typescript
688
+ * const client = new DotCMSClient(config);
689
+ * const collectionBuilder = client.content.getCollection("Blog");
690
+ * const sortBy = [{ field: 'title', order: 'asc' }, { field: 'modDate', order: 'desc' }];
691
+ * collectionBuilder("Blog").sortBy(sortBy);
692
+ * ```
522
693
  *
523
- * @param {SortBy[]} sortBy Array of constrains to sort the content by
524
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
694
+ * @param {SortBy[]} sortBy Array of constraints to sort the content by.
695
+ * @return {CollectionBuilder} A CollectionBuilder instance.
525
696
  * @memberof CollectionBuilder
526
697
  */
527
698
  sortBy(sortBy) {
@@ -529,12 +700,10 @@ class CollectionBuilder {
529
700
  return this;
530
701
  }
531
702
  /**
532
- * Takes a number that represents the max amount of content to fetch
533
- *
534
- * `limit` is set to 10 by default
703
+ * Sets the maximum amount of content to fetch.
535
704
  *
536
- * @param {number} limit The max amount of content to fetch
537
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
705
+ * @param {number} limit The maximum amount of content to fetch.
706
+ * @return {CollectionBuilder} A CollectionBuilder instance.
538
707
  * @memberof CollectionBuilder
539
708
  */
540
709
  limit(limit) {
@@ -542,10 +711,10 @@ class CollectionBuilder {
542
711
  return this;
543
712
  }
544
713
  /**
545
- * Takes a number that represents the page to fetch
714
+ * Sets the page number to fetch.
546
715
  *
547
- * @param {number} page The page to fetch
548
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
716
+ * @param {number} page The page number to fetch.
717
+ * @return {CollectionBuilder} A CollectionBuilder instance.
549
718
  * @memberof CollectionBuilder
550
719
  */
551
720
  page(page) {
@@ -571,11 +740,18 @@ class CollectionBuilder {
571
740
  return this;
572
741
  }
573
742
  /**
574
- * The retrieved content will be draft content
575
- *
576
- * The default value is false to fetch content that is not on draft
743
+ * Retrieves draft content.
744
+ * @example
745
+ * ```ts
746
+ * const client = new DotCMSClient(config);
747
+ * const collectionBuilder = client.content.getCollection("Blog");
748
+ * collectionBuilder
749
+ * .draft() // This will retrieve draft/working content
750
+ * .then((response) => // Your code here })
751
+ * .catch((error) => // Your code here })
752
+ * ```
577
753
  *
578
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
754
+ * @return {CollectionBuilder} A CollectionBuilder instance.
579
755
  * @memberof CollectionBuilder
580
756
  */
581
757
  draft() {
@@ -583,12 +759,22 @@ class CollectionBuilder {
583
759
  return this;
584
760
  }
585
761
  /**
586
- * Takes a string that represents a variant ID of content created with the {@link https://www.dotcms.com/docs/latest/experiments-and-a-b-testing A/B Testing} feature
762
+ * Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
587
763
  *
588
- * `variantId` defaults to "DEFAULT" to fetch content that is not part of an A/B test
764
+ * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
589
765
  *
590
- * @param {string} variantId A string that represents a variant ID
591
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
766
+ * @example
767
+ * ```ts
768
+ * const client = new DotCMSClient(config);
769
+ * const collectionBuilder = client.content.getCollection("Blog");
770
+ * collectionBuilder
771
+ * .variant("YOUR_VARIANT_ID")
772
+ * .then((response) => // Your code here })
773
+ * .catch((error) => // Your code here })
774
+ * ```
775
+ *
776
+ * @param {string} variantId A string that represents a variant ID.
777
+ * @return {CollectionBuilder} A CollectionBuilder instance.
592
778
  * @memberof CollectionBuilder
593
779
  */
594
780
  variant(variantId) {
@@ -596,12 +782,23 @@ class CollectionBuilder {
596
782
  return this;
597
783
  }
598
784
  /**
599
- * Takes a number that represents the depth of the relationships of a content
785
+ * Sets the depth of the relationships of the content.
786
+ * Specifies the depth of related content to return in the results.
600
787
  *
601
- * The `depth` is set to 0 by default and the max supported value is 3.
788
+ * More information here: {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying#ParamsOptional}
602
789
  *
603
- * @param {number} depth The depth of the relationships of a content
604
- * @return {CollectionBuilder} CollectionBuilder - A CollectionBuilder instance
790
+ * @example
791
+ * ```ts
792
+ * const client = new DotCMSClient(config);
793
+ * const collectionBuilder = client.content.getCollection("Blog");
794
+ * collectionBuilder
795
+ * .depth(1)
796
+ * .then((response) => // Your code here })
797
+ * .catch((error) => // Your code here })
798
+ * ```
799
+ *
800
+ * @param {number} depth The depth of the relationships of the content.
801
+ * @return {CollectionBuilder} A CollectionBuilder instance.
605
802
  * @memberof CollectionBuilder
606
803
  */
607
804
  depth(depth) {
@@ -612,11 +809,21 @@ class CollectionBuilder {
612
809
  return this;
613
810
  }
614
811
  /**
615
- * Executes the fetch and returns a promise that resolves to the content or rejects to an error
812
+ * Executes the fetch and returns a promise that resolves to the content or rejects with an error.
813
+ *
814
+ * @example
815
+ * ```ts
816
+ * const client = new DotCMSClient(config);
817
+ * const collectionBuilder = client.content.getCollection("Blog");
818
+ * collectionBuilder
819
+ * .limit(10)
820
+ * .then((response) => // Your code here })
821
+ * .catch((error) => // Your code here })
822
+ * ```
616
823
  *
617
- * @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful
618
- * @param {OnRejected} [onrejected] A callback that is called when the fetch fails
619
- * @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects to an error
824
+ * @param {OnFullfilled} [onfulfilled] A callback that is called when the fetch is successful.
825
+ * @param {OnRejected} [onrejected] A callback that is called when the fetch fails.
826
+ * @return {Promise<GetCollectionResponse<T> | GetCollectionError>} A promise that resolves to the content or rejects with an error.
620
827
  * @memberof CollectionBuilder
621
828
  */
622
829
  then(onfulfilled, onrejected) {
@@ -630,7 +837,6 @@ class CollectionBuilder {
630
837
  return finalResponse;
631
838
  }
632
839
  else {
633
- // Fetch does not reject on server errors, so we only have to bubble up the error as a normal fetch
634
840
  return {
635
841
  status: response.status,
636
842
  ...data
@@ -638,7 +844,14 @@ class CollectionBuilder {
638
844
  }
639
845
  }, onrejected);
640
846
  }
641
- // Formats the response to the desired format
847
+ /**
848
+ * Formats the response to the desired format.
849
+ *
850
+ * @private
851
+ * @param {GetCollectionRawResponse<T>} data The raw response data.
852
+ * @return {GetCollectionResponse<T>} The formatted response.
853
+ * @memberof CollectionBuilder
854
+ */
642
855
  formatResponse(data) {
643
856
  const contentlets = data.entity.jsonObjectView.contentlets;
644
857
  const total = data.entity.resultsSize;
@@ -655,7 +868,13 @@ class CollectionBuilder {
655
868
  }
656
869
  : mappedResponse;
657
870
  }
658
- // Calls the content API to fetch the content
871
+ /**
872
+ * Calls the content API to fetch the content.
873
+ *
874
+ * @private
875
+ * @return {Promise<Response>} The fetch response.
876
+ * @memberof CollectionBuilder
877
+ */
659
878
  fetch() {
660
879
  const finalQuery = this.currentQuery
661
880
  .field('languageId')
@@ -689,12 +908,63 @@ _CollectionBuilder_page = new WeakMap(), _CollectionBuilder_limit = new WeakMap(
689
908
 
690
909
  var _Content_requestOptions, _Content_serverUrl;
691
910
  /**
692
- * Content classs exposes the content api methods
911
+ * Creates a builder to filter and fetch a collection of content items.
912
+ * @param contentType - The content type to retrieve.
913
+ * @returns A CollectionBuilder instance for chaining filters and executing the query.
914
+ * @template T - The type of the content items (defaults to unknown).
693
915
  *
694
- * @export
695
- * @class Content
916
+ * @example Fetch blog posts with async/await
917
+ * ```typescript
918
+ * const response = await client.content
919
+ * .getCollection<BlogPost>('Blog')
920
+ * .limit(10)
921
+ * .page(2)
922
+ * .sortBy([{ field: 'title', order: 'asc' }])
923
+ * .query(q => q.field('author').equals('John Doe'))
924
+ * .depth(1)
925
+ * .fetch();
926
+ *
927
+ * console.log(response.contentlets);
928
+ * ```
929
+ *
930
+ * @example Fetch blog posts with Promise chain
931
+ * ```typescript
932
+ * client.content
933
+ * .getCollection<BlogPost>('Blog')
934
+ * .limit(10)
935
+ * .page(2)
936
+ * .sortBy([{ field: 'title', order: 'asc' }])
937
+ * .query(q => q.field('author').equals('John Doe'))
938
+ * .depth(1)
939
+ * .fetch()
940
+ * .then(response => console.log(response.contentlets))
941
+ * .catch(error => console.error(error));
942
+ * ```
943
+ *
944
+ * @example Using a custom type
945
+ * ```typescript
946
+ * interface BlogPost {
947
+ * summary: string;
948
+ * author: string;
949
+ * title: string;
950
+ * }
951
+ *
952
+ * const posts = await client.content
953
+ * .getCollection<BlogPost>('Blog')
954
+ * .limit(10)
955
+ * .fetch();
956
+ *
957
+ * posts.contentlets.forEach(post => {
958
+ * console.log(post.title, post.author, post.summary);
959
+ * });
960
+ * ```
696
961
  */
697
962
  class Content {
963
+ /**
964
+ * Creates an instance of Content.
965
+ * @param {ClientOptions} requestOptions - The options for the client request.
966
+ * @param {string} serverUrl - The server URL.
967
+ */
698
968
  constructor(requestOptions, serverUrl) {
699
969
  _Content_requestOptions.set(this, void 0);
700
970
  _Content_serverUrl.set(this, void 0);
@@ -702,7 +972,11 @@ class Content {
702
972
  __classPrivateFieldSet(this, _Content_serverUrl, serverUrl, "f");
703
973
  }
704
974
  /**
705
- * Takes a content type and returns a builder to filter and fetch the collection
975
+ * Takes a content type and returns a builder to filter and fetch the collection.
976
+ * @param {string} contentType - The content type to get the collection.
977
+ * @return {CollectionBuilder<T>} CollectionBuilder to filter and fetch the collection.
978
+ * @template T - Represents the type of the content type to fetch. Defaults to unknown.
979
+ * @memberof Content
706
980
  *
707
981
  * @example
708
982
  * ```javascript
@@ -734,7 +1008,7 @@ class Content {
734
1008
  * ```
735
1009
  * @example
736
1010
  * ```typescript
737
- * // Using an specific type for your content
1011
+ * // Using a specific type for your content
738
1012
  *
739
1013
  * type Blog = {
740
1014
  * summary: string;
@@ -761,10 +1035,6 @@ class Content {
761
1035
  * });
762
1036
  * ```
763
1037
  *
764
- * @param {string} contentType The content type to get the collection
765
- * @return {CollectionBuilder} CollectionBuilder to filter and fetch the collection
766
- * @template T Represents the type of the content type to fetch. Defaults to unknown
767
- * @memberof Content
768
1038
  */
769
1039
  getCollection(contentType) {
770
1040
  return new CollectionBuilder(__classPrivateFieldGet(this, _Content_requestOptions, "f"), __classPrivateFieldGet(this, _Content_serverUrl, "f"), contentType);
@@ -772,6 +1042,17 @@ class Content {
772
1042
  }
773
1043
  _Content_requestOptions = new WeakMap(), _Content_serverUrl = new WeakMap();
774
1044
 
1045
+ /**
1046
+ * A record of HTTP status codes and their corresponding error messages.
1047
+ *
1048
+ * @type {Record<number, string>}
1049
+ * @property {string} 401 - Unauthorized. Check the token and try again.
1050
+ * @property {string} 403 - Forbidden. Check the permissions and try again.
1051
+ * @property {string} 404 - Not Found. Check the URL and try again.
1052
+ * @property {string} 500 - Internal Server Error. Try again later.
1053
+ * @property {string} 502 - Bad Gateway. Try again later.
1054
+ * @property {string} 503 - Service Unavailable. Try again later.
1055
+ */
775
1056
  const ErrorMessages = {
776
1057
  401: 'Unauthorized. Check the token and try again.',
777
1058
  403: 'Forbidden. Check the permissions and try again.',
@@ -884,8 +1165,14 @@ var NOTIFY_CUSTOMER;
884
1165
  * Calculates the bounding information for each page element within the given containers.
885
1166
  *
886
1167
  * @export
887
- * @param {HTMLDivElement[]} containers
888
- * @return {*} An array of objects containing the bounding information for each page element.
1168
+ * @param {HTMLDivElement[]} containers - An array of HTMLDivElement representing the containers.
1169
+ * @return {ContainerBound[]} An array of objects containing the bounding information for each page element.
1170
+ * @example
1171
+ * ```ts
1172
+ * const containers = document.querySelectorAll('.container');
1173
+ * const bounds = getPageElementBound(containers);
1174
+ * console.log(bounds);
1175
+ * ```
889
1176
  */
890
1177
  function getPageElementBound(containers) {
891
1178
  return containers.map((container) => {
@@ -904,12 +1191,19 @@ function getPageElementBound(containers) {
904
1191
  });
905
1192
  }
906
1193
  /**
907
- * An array of objects containing the bounding information for each contentlet inside a container.
1194
+ * Calculates the bounding information for each contentlet inside a container.
908
1195
  *
909
1196
  * @export
910
- * @param {DOMRect} containerRect
911
- * @param {HTMLDivElement[]} contentlets
912
- * @return {*}
1197
+ * @param {DOMRect} containerRect - The bounding rectangle of the container.
1198
+ * @param {HTMLDivElement[]} contentlets - An array of HTMLDivElement representing the contentlets.
1199
+ * @return {ContentletBound[]} An array of objects containing the bounding information for each contentlet.
1200
+ * @example
1201
+ * ```ts
1202
+ * const containerRect = container.getBoundingClientRect();
1203
+ * const contentlets = container.querySelectorAll('.contentlet');
1204
+ * const bounds = getContentletsBound(containerRect, contentlets);
1205
+ * console.log(bounds); // Element bounds within the container
1206
+ * ```
913
1207
  */
914
1208
  function getContentletsBound(containerRect, contentlets) {
915
1209
  return contentlets.map((contentlet) => {
@@ -937,8 +1231,14 @@ function getContentletsBound(containerRect, contentlets) {
937
1231
  * Get container data from VTLS.
938
1232
  *
939
1233
  * @export
940
- * @param {HTMLElement} container
941
- * @return {*}
1234
+ * @param {HTMLElement} container - The container element.
1235
+ * @return {object} An object containing the container data.
1236
+ * @example
1237
+ * ```ts
1238
+ * const container = document.querySelector('.container');
1239
+ * const data = getContainerData(container);
1240
+ * console.log(data);
1241
+ * ```
942
1242
  */
943
1243
  function getContainerData(container) {
944
1244
  return {
@@ -952,8 +1252,14 @@ function getContainerData(container) {
952
1252
  * Get the closest container data from the contentlet.
953
1253
  *
954
1254
  * @export
955
- * @param {Element} element
956
- * @return {*}
1255
+ * @param {Element} element - The contentlet element.
1256
+ * @return {object | null} An object containing the closest container data or null if no container is found.
1257
+ * @example
1258
+ * ```ts
1259
+ * const contentlet = document.querySelector('.contentlet');
1260
+ * const data = getClosestContainerData(contentlet);
1261
+ * console.log(data);
1262
+ * ```
957
1263
  */
958
1264
  function getClosestContainerData(element) {
959
1265
  // Find the closest ancestor element with data-dot-object="container" attribute
@@ -973,8 +1279,12 @@ function getClosestContainerData(element) {
973
1279
  * Find the closest contentlet element based on HTMLElement.
974
1280
  *
975
1281
  * @export
976
- * @param {(HTMLElement | null)} element
977
- * @return {*}
1282
+ * @param {HTMLElement | null} element - The starting element.
1283
+ * @return {HTMLElement | null} The closest contentlet element or null if not found.
1284
+ * @example
1285
+ * const element = document.querySelector('.some-element');
1286
+ * const contentlet = findDotElement(element);
1287
+ * console.log(contentlet);
978
1288
  */
979
1289
  function findDotElement(element) {
980
1290
  if (!element)
@@ -985,6 +1295,19 @@ function findDotElement(element) {
985
1295
  }
986
1296
  return findDotElement(element?.['parentElement']);
987
1297
  }
1298
+ /**
1299
+ * Find VTL data within a target element.
1300
+ *
1301
+ * @export
1302
+ * @param {HTMLElement} target - The target element to search within.
1303
+ * @return {Array<{ inode: string, name: string }> | null} An array of objects containing VTL data or null if none found.
1304
+ * @example
1305
+ * ```ts
1306
+ * const target = document.querySelector('.target-element');
1307
+ * const vtlData = findVTLData(target);
1308
+ * console.log(vtlData);
1309
+ * ```
1310
+ */
988
1311
  function findVTLData(target) {
989
1312
  const vltElements = target.querySelectorAll('[data-dot-object="vtl-file"]');
990
1313
  if (!vltElements.length) {
@@ -997,6 +1320,18 @@ function findVTLData(target) {
997
1320
  };
998
1321
  });
999
1322
  }
1323
+ /**
1324
+ * Check if the scroll position is at the bottom of the page.
1325
+ *
1326
+ * @export
1327
+ * @return {boolean} True if the scroll position is at the bottom, otherwise false.
1328
+ * @example
1329
+ * ```ts
1330
+ * if (scrollIsInBottom()) {
1331
+ * console.log('Scrolled to the bottom');
1332
+ * }
1333
+ * ```
1334
+ */
1000
1335
  function scrollIsInBottom() {
1001
1336
  const documentHeight = document.documentElement.scrollHeight;
1002
1337
  const viewportHeight = window.innerHeight;
@@ -1024,7 +1359,7 @@ function setBounds() {
1024
1359
  });
1025
1360
  }
1026
1361
  /**
1027
- * Listens for editor messages and performs corresding actions based on the received message.
1362
+ * Listens for editor messages and performs corresponding actions based on the received message.
1028
1363
  *
1029
1364
  * @private
1030
1365
  * @memberof DotCMSPageEditor
@@ -1041,10 +1376,8 @@ function listenEditorMessages() {
1041
1376
  const direction = event.data.direction;
1042
1377
  if ((window.scrollY === 0 && direction === 'up') ||
1043
1378
  (scrollIsInBottom() && direction === 'down')) {
1044
- /**
1045
- * If the iframe scroll is in the top of bottom, we dont send anything.
1046
- * This to avoid the lost of scrollend event
1047
- **/
1379
+ // If the iframe scroll is at the top or bottom, do not send anything.
1380
+ // This avoids losing the scrollend event.
1048
1381
  return;
1049
1382
  }
1050
1383
  const scrollY = direction === 'up' ? -120 : 120;
@@ -1092,8 +1425,8 @@ function listenHoveredContentlet() {
1092
1425
  const vtlFiles = findVTLData(foundElement);
1093
1426
  const contentletPayload = {
1094
1427
  container:
1095
- // Here extract dot-container from contentlet if is Headless
1096
- // or search in parent container if is VTL
1428
+ // Here extract dot-container from contentlet if it is Headless
1429
+ // or search in parent container if it is VTL
1097
1430
  foundElement.dataset?.['dotContainer']
1098
1431
  ? JSON.parse(foundElement.dataset?.['dotContainer'])
1099
1432
  : getClosestContainerData(foundElement),
@@ -1166,10 +1499,12 @@ function fetchPageDataFromInsideUVE(pathname) {
1166
1499
  }
1167
1500
 
1168
1501
  /**
1169
- *
1170
1502
  * Updates the navigation in the editor.
1503
+ *
1171
1504
  * @param {string} pathname - The pathname to update the navigation with.
1172
1505
  * @memberof DotCMSPageEditor
1506
+ * @example
1507
+ * updateNavigation('/home'); // Sends a message to the editor to update the navigation to '/home'
1173
1508
  */
1174
1509
  function updateNavigation(pathname) {
1175
1510
  postMessageToEditor({
@@ -1181,7 +1516,16 @@ function updateNavigation(pathname) {
1181
1516
  }
1182
1517
  /**
1183
1518
  * Checks if the code is running inside an editor.
1519
+ *
1184
1520
  * @returns {boolean} Returns true if the code is running inside an editor, otherwise false.
1521
+ * @example
1522
+ * ```ts
1523
+ * if (isInsideEditor()) {
1524
+ * console.log('Running inside the editor');
1525
+ * } else {
1526
+ * console.log('Running outside the editor');
1527
+ * }
1528
+ * ```
1185
1529
  */
1186
1530
  function isInsideEditor() {
1187
1531
  if (typeof window === 'undefined') {
@@ -1192,7 +1536,12 @@ function isInsideEditor() {
1192
1536
  /**
1193
1537
  * Initializes the DotCMS page editor.
1194
1538
  *
1195
- * @param conf - Optional configuration for the editor.
1539
+ * @param {DotCMSPageEditorConfig} config - Optional configuration for the editor.
1540
+ * @example
1541
+ * ```ts
1542
+ * const config = { pathname: '/home' };
1543
+ * initEditor(config); // Initializes the editor with the provided configuration
1544
+ * ```
1196
1545
  */
1197
1546
  function initEditor(config) {
1198
1547
  fetchPageDataFromInsideUVE(config.pathname);
@@ -1202,6 +1551,11 @@ function initEditor(config) {
1202
1551
  }
1203
1552
  /**
1204
1553
  * Destroys the editor by removing event listeners and disconnecting observers.
1554
+ *
1555
+ * @example
1556
+ * ```ts
1557
+ * destroyEditor(); // Cleans up the editor by removing all event listeners and disconnecting observers
1558
+ * ```
1205
1559
  */
1206
1560
  function destroyEditor() {
1207
1561
  subscriptions.forEach((subscription) => {
@@ -1225,18 +1579,49 @@ function getHostURL(url) {
1225
1579
  }
1226
1580
  /**
1227
1581
  * `DotCmsClient` is a TypeScript class that provides methods to interact with the DotCMS REST API.
1228
- * It requires a configuration object on instantiation, which includes the DotCMS URL, site ID, and authentication token.
1582
+ * DotCMS is a hybrid-headless CMS and digital experience platform.
1229
1583
  *
1230
1584
  * @class DotCmsClient
1231
- *
1232
1585
  * @property {ClientConfig} config - The configuration object for the DotCMS client.
1586
+ * @property {Content} content - Provides methods to interact with content in DotCMS.
1233
1587
  *
1234
1588
  * @method constructor(config: ClientConfig) - Constructs a new instance of the DotCmsClient class.
1235
1589
  *
1236
- * @method page.get(options: PageApiOptions): Promise<unknown> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
1590
+ * @method page.get(options: PageApiOptions): Promise<PageApiResponse> - Retrieves all the elements of any Page in your dotCMS system in JSON format.
1591
+ * The Page API enables you to retrieve page information, layout, template, content blocks, and more.
1592
+ * @see {@link https://www.dotcms.com/docs/latest/page-rest-api-layout-as-a-service-laas}
1593
+ *
1594
+ * @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<NavApiResponse> - Retrieves information about the dotCMS file and folder tree.
1595
+ * The Navigation API allows you to fetch the site structure and menu items.
1596
+ * @see {@link https://www.dotcms.com/docs/latest/navigation-rest-api}
1597
+ *
1598
+ * @method content.get(options: ContentApiOptions): Promise<ContentApiResponse> - Retrieves content items based on specified criteria.
1599
+ * The Content API allows you to query and retrieve content by ID, inode, or using Lucene queries.
1600
+ * @see {@link https://www.dotcms.com/docs/latest/content-api-retrieval-and-querying}
1601
+ *
1602
+ * @method editor.on(action: string, callbackFn: (payload: unknown) => void) - Allows you to react to actions issued by the Universal Visual Editor (UVE).
1603
+ * @method editor.off(action: string) - Stops listening to an action issued by UVE.
1604
+ *
1605
+ * @static
1606
+ * @method init(config: ClientConfig): DotCmsClient - Initializes and returns a DotCmsClient instance.
1607
+ * @method dotcmsUrl: string - Retrieves the DotCMS URL from the instance configuration.
1608
+ *
1609
+ * @example <caption>Basic usage</caption>
1610
+ * ```javascript
1611
+ * const client = DotCmsClient.init({ dotcmsUrl: 'https://demo.dotcms.com', authToken: 'your-auth-token' });
1237
1612
  *
1238
- * @method nav.get(options: NavApiOptions = { depth: 0, path: '/', languageId: 1 }): Promise<unknown> - Retrieves information about the dotCMS file and folder tree.
1613
+ * // Get a page
1614
+ * client.page.get({ path: '/about-us' }).then(response => console.log(response));
1239
1615
  *
1616
+ * // Get navigation
1617
+ * client.nav.get({ path: '/about-us', depth: 2 }).then(response => console.log(response));
1618
+ *
1619
+ * // Get content
1620
+ * client.content.get({ query: '+contentType:Blog +languageId:1', limit: 10 }).then(response => console.log(response));
1621
+ *
1622
+ * // Listen to editor changes
1623
+ * client.editor.on('changes', (payload) => console.log('Changes detected:', payload));
1624
+ * ```
1240
1625
  */
1241
1626
  class DotCmsClient {
1242
1627
  constructor(config = { dotcmsUrl: '', authToken: '', requestOptions: {}, siteId: '' }) {
@@ -1256,6 +1641,11 @@ class DotCmsClient {
1256
1641
  * @param {PageApiOptions} options - The options for the Page API call.
1257
1642
  * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
1258
1643
  * @throws {Error} - Throws an error if the options are not valid.
1644
+ * @example
1645
+ * ```ts
1646
+ * const client = new DotCmsClient({ dotcmsUrl: 'https://your.dotcms.com', authToken: 'your-auth-token', siteId: 'your-site-id' });
1647
+ * client.page.get({ path: '/about-us' }).then(response => console.log(response));
1648
+ * ```
1259
1649
  */
1260
1650
  get: async (options) => {
1261
1651
  this.validatePageOptions(options);
@@ -1297,8 +1687,14 @@ class DotCmsClient {
1297
1687
  * `editor.on` is an asynchronous method of the `DotCmsClient` class that allows you to react to actions issued by the UVE.
1298
1688
  *
1299
1689
  * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
1300
- * @param action - The name of the name emitted by UVE
1301
- * @param callbackFn - The function to execute when the UVE emits the action
1690
+ * @param {string} action - The name of the action emitted by UVE.
1691
+ * @param {function} callbackFn - The function to execute when the UVE emits the action.
1692
+ * @example
1693
+ * ```ts
1694
+ * client.editor.on('changes', (payload) => {
1695
+ * console.log('Changes detected:', payload);
1696
+ * });
1697
+ * ```
1302
1698
  */
1303
1699
  on: (action, callbackFn) => {
1304
1700
  if (!isInsideEditor()) {
@@ -1315,10 +1711,14 @@ class DotCmsClient {
1315
1711
  }
1316
1712
  },
1317
1713
  /**
1318
- * `editor.off` is an synchronous method of the `DotCmsClient` class that allows you to stop listening and reacting to an action issued by UVE.
1714
+ * `editor.off` is a synchronous method of the `DotCmsClient` class that allows you to stop listening and reacting to an action issued by UVE.
1319
1715
  *
1320
- * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
1321
- * @param action
1716
+ * NOTE: This is being used by the development team - This logic is probably varied or moved to another function/object.
1717
+ * @param {string} action - The name of the action to stop listening to.
1718
+ * @example
1719
+ * ```ts
1720
+ * client.editor.off('changes');
1721
+ * ```
1322
1722
  */
1323
1723
  off: (action) => {
1324
1724
  const listenerIndex = __classPrivateFieldGet(this, _DotCmsClient_listeners, "f").findIndex((listener) => listener.action === action);
@@ -1340,6 +1740,11 @@ class DotCmsClient {
1340
1740
  * @param {NavApiOptions} options - The options for the Nav API call. Defaults to `{ depth: 0, path: '/', languageId: 1 }`.
1341
1741
  * @returns {Promise<unknown>} - A Promise that resolves to the response from the DotCMS API.
1342
1742
  * @throws {Error} - Throws an error if the options are not valid.
1743
+ * @example
1744
+ * ```ts
1745
+ * const client = new DotCmsClient({ dotcmsUrl: 'https://your.dotcms.com', authToken: 'your-auth-token', siteId: 'your-site-id' }});
1746
+ * client.nav.get({ path: '/about-us', depth: 2 }).then(response => console.log(response));
1747
+ * ```
1343
1748
  */
1344
1749
  get: async (options = { depth: 0, path: '/', languageId: 1 }) => {
1345
1750
  this.validateNavOptions(options);
@@ -1382,20 +1787,46 @@ class DotCmsClient {
1382
1787
  }, "f");
1383
1788
  this.content = new Content(__classPrivateFieldGet(this, _DotCmsClient_requestOptions, "f"), __classPrivateFieldGet(this, _DotCmsClient_config, "f").dotcmsUrl);
1384
1789
  }
1790
+ /**
1791
+ * Initializes the DotCmsClient instance with the provided configuration.
1792
+ * If an instance already exists, it returns the existing instance.
1793
+ *
1794
+ * @param {ClientConfig} config - The configuration object for the DotCMS client.
1795
+ * @returns {DotCmsClient} - The initialized DotCmsClient instance.
1796
+ * @example
1797
+ * ```ts
1798
+ * const client = DotCmsClient.init({ dotcmsUrl: 'https://demo.dotcms.com', authToken: 'your-auth-token' });
1799
+ * ```
1800
+ */
1385
1801
  static init(config) {
1386
1802
  if (this.instance) {
1387
1803
  console.warn('DotCmsClient has already been initialized. Please use the instance to interact with the DotCMS API.');
1388
1804
  }
1389
1805
  return this.instance ?? (this.instance = new DotCmsClient(config));
1390
1806
  }
1807
+ /**
1808
+ * Retrieves the DotCMS URL from the instance configuration.
1809
+ *
1810
+ * @returns {string} - The DotCMS URL.
1811
+ */
1391
1812
  static get dotcmsUrl() {
1392
1813
  return (this.instance && __classPrivateFieldGet(this.instance, _DotCmsClient_config, "f").dotcmsUrl) || '';
1393
1814
  }
1815
+ /**
1816
+ * Throws an error if the path is not valid.
1817
+ *
1818
+ * @returns {string} - The authentication token.
1819
+ */
1394
1820
  validatePageOptions(options) {
1395
1821
  if (!options.path) {
1396
1822
  throw new Error("The 'path' parameter is required for the Page API");
1397
1823
  }
1398
1824
  }
1825
+ /**
1826
+ * Throws an error if the path is not valid.
1827
+ *
1828
+ * @returns {string} - The authentication token.
1829
+ */
1399
1830
  validateNavOptions(options) {
1400
1831
  if (!options.path) {
1401
1832
  throw new Error("The 'path' parameter is required for the Nav API");
@@ -1404,15 +1835,25 @@ class DotCmsClient {
1404
1835
  }
1405
1836
  _DotCmsClient_config = new WeakMap(), _DotCmsClient_requestOptions = new WeakMap(), _DotCmsClient_listeners = new WeakMap();
1406
1837
 
1407
- // For now, we are not typing the functions in this file
1408
- /* eslint-disable @typescript-eslint/no-explicit-any */
1409
- const graphqlToPageEntity = ({ page }) => {
1838
+ /**
1839
+ * Transforms a GraphQL Page response to a Page Entity.
1840
+ *
1841
+ * @param {GraphQLPageResponse} graphQLPageResponse - The GraphQL Page response object.
1842
+ * @returns {object|null} The transformed Page Entity or null if the page is not present.
1843
+ *
1844
+ * @example
1845
+ * ```ts
1846
+ * const pageEntity = graphqlToPageEntity(graphQLPageResponse);
1847
+ * ```
1848
+ */
1849
+ const graphqlToPageEntity = (graphQLPageResponse) => {
1850
+ const { page } = graphQLPageResponse;
1410
1851
  // If there is no page, return null
1411
1852
  if (!page) {
1412
1853
  return null;
1413
1854
  }
1414
1855
  const { layout, template, containers, urlContentMap, viewAs, site, _map, ...pageAsset } = page;
1415
- const data = _map || {};
1856
+ const data = (_map || {});
1416
1857
  return {
1417
1858
  layout,
1418
1859
  template,
@@ -1426,6 +1867,12 @@ const graphqlToPageEntity = ({ page }) => {
1426
1867
  containers: parseContainers(containers)
1427
1868
  };
1428
1869
  };
1870
+ /**
1871
+ * Parses the containers from the GraphQL response.
1872
+ *
1873
+ * @param {Array<Record<string, unknown>>} [containers=[]] - The containers array from the GraphQL response.
1874
+ * @returns {Record<string, unknown>} The parsed containers.
1875
+ */
1429
1876
  const parseContainers = (containers = []) => {
1430
1877
  return containers.reduce((acc, container) => {
1431
1878
  const { path, identifier, containerStructures, containerContentlets, ...rest } = container;
@@ -1442,7 +1889,13 @@ const parseContainers = (containers = []) => {
1442
1889
  return acc;
1443
1890
  }, {});
1444
1891
  };
1445
- const parseContentletsToUuidMap = (containerContentlets) => {
1892
+ /**
1893
+ * Parses the contentlets from the GraphQL response.
1894
+ *
1895
+ * @param {Array<Record<string, unknown>>} containerContentlets - The contentlets array from the GraphQL response.
1896
+ * @returns {Record<string, Array<Record<string, unknown>>>} The parsed contentlets mapped by UUID.
1897
+ */
1898
+ const parseContentletsToUuidMap = (containerContentlets = []) => {
1446
1899
  return containerContentlets.reduce((acc, containerContentlet) => {
1447
1900
  const { uuid, contentlets } = containerContentlet;
1448
1901
  // TODO: This is a temporary solution, we need to find a better way to handle this.
@@ -1456,6 +1909,16 @@ const parseContentletsToUuidMap = (containerContentlets) => {
1456
1909
  }, {});
1457
1910
  };
1458
1911
 
1912
+ /**
1913
+ * Generates the page request parameters to be used in the API call.
1914
+ *
1915
+ * @param {PageRequestParamsProps} PageRequestParamsProps - The properties for the page request.
1916
+ * @returns {PageApiOptions} The options for the page API.
1917
+ * @example
1918
+ * ```ts
1919
+ * const pageApiOptions = getPageRequestParams({ path: '/api/v1/page', params: queryParams });
1920
+ * ```
1921
+ */
1459
1922
  const getPageRequestParams = ({ path = '', params = {} }) => {
1460
1923
  const copiedParams = params instanceof URLSearchParams ? Object.fromEntries(params.entries()) : { ...params };
1461
1924
  const finalParams = {};