@dotcms/client 1.2.5-next.2 → 1.2.5-next.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/README.md
CHANGED
|
@@ -32,6 +32,7 @@ The `@dotcms/client` is a powerful JavaScript/TypeScript SDK designed to simplif
|
|
|
32
32
|
- [How-to Guides](#how-to-guides)
|
|
33
33
|
- [How to Fetch Complete Pages](#how-to-fetch-complete-pages)
|
|
34
34
|
- [How to Query Content Collections](#how-to-query-content-collections)
|
|
35
|
+
- [Including System Host Content](#including-system-host-content)
|
|
35
36
|
- [How to Run Raw Lucene Content Queries](#how-to-run-raw-lucene-content-queries)
|
|
36
37
|
- [How to Use AI-Powered Search](#how-to-use-ai-powered-search)
|
|
37
38
|
- [How to Work with GraphQL](#how-to-work-with-graphql)
|
|
@@ -220,6 +221,33 @@ const products = await client.content
|
|
|
220
221
|
.limit(10);
|
|
221
222
|
```
|
|
222
223
|
|
|
224
|
+
#### Including System Host Content
|
|
225
|
+
|
|
226
|
+
By default, `getCollection()` scopes queries to the configured `siteId`. Call `.includeSystemHost()` to also return content that belongs to the dotCMS **System Host** — shared content available across all sites.
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
// Return content from both the configured site AND the System Host
|
|
230
|
+
const blogs = await client.content
|
|
231
|
+
.getCollection('Blog')
|
|
232
|
+
.includeSystemHost()
|
|
233
|
+
.limit(10);
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Under the hood, all positive `+conhost:` constraints in the assembled query are collected and grouped into a single `+(conhost:<siteId> conhost:SYSTEM_HOST)` OR group, so dotCMS returns content from any of the matched hosts.
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
// Multiple sites + System Host (multisite scenario)
|
|
240
|
+
const blogs = await client.content
|
|
241
|
+
.getCollection('Blog')
|
|
242
|
+
.query('+conhost:site-a')
|
|
243
|
+
.includeSystemHost()
|
|
244
|
+
.limit(10);
|
|
245
|
+
// Resulting conhost constraint: +(conhost:site-a conhost:<configured-siteId> conhost:SYSTEM_HOST)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
> [!NOTE]
|
|
249
|
+
> Negative conhost exclusions (`-conhost:excluded-site`) in raw queries are preserved as-is and are not affected by `includeSystemHost()`.
|
|
250
|
+
|
|
223
251
|
### How to Run Raw Lucene Content Queries
|
|
224
252
|
|
|
225
253
|
Use `client.content.query()` when you want to execute a **raw Lucene query string** (without the query-builder DSL), and you want full control over constraints like `contentType`, `live`, `languageId`, `conhost`, etc.
|
package/index.cjs.js
CHANGED
|
@@ -510,6 +510,11 @@ class AIClient extends BaseApiClient {
|
|
|
510
510
|
/**
|
|
511
511
|
* Default variant identifier used in the application.
|
|
512
512
|
*/
|
|
513
|
+
/**
|
|
514
|
+
* Identifier for the dotCMS System Host.
|
|
515
|
+
* Used when building queries that should include content from the System Host.
|
|
516
|
+
*/
|
|
517
|
+
const SYSTEM_HOST = 'SYSTEM_HOST';
|
|
513
518
|
/**
|
|
514
519
|
* Fields that should not be formatted when sanitizing the query.
|
|
515
520
|
* These fields are essential for maintaining the integrity of the content type.
|
|
@@ -879,6 +884,68 @@ function shouldAddSiteIdConstraint(query, siteId) {
|
|
|
879
884
|
}
|
|
880
885
|
return true;
|
|
881
886
|
}
|
|
887
|
+
/**
|
|
888
|
+
* @description
|
|
889
|
+
* Collects all positive `+conhost:` values from a fully assembled Lucene query,
|
|
890
|
+
* removes them from their original positions, adds SYSTEM_HOST to the set,
|
|
891
|
+
* and rebuilds a single grouped constraint at the end of the query.
|
|
892
|
+
*
|
|
893
|
+
* This function is designed to be called on the final assembled query string
|
|
894
|
+
* (after raw query has been appended) so that conhosts from all sources —
|
|
895
|
+
* auto-injected siteId, builder-path conhost, and raw-path conhost — are
|
|
896
|
+
* all visible and handled uniformly.
|
|
897
|
+
*
|
|
898
|
+
* @example
|
|
899
|
+
* ```ts
|
|
900
|
+
* // Single siteId + SYSTEM_HOST
|
|
901
|
+
* buildConhostWithSystemHost('+contentType:Blog +languageId:1 +live:true +conhost:site-123')
|
|
902
|
+
* // → '+contentType:Blog +languageId:1 +live:true +(conhost:site-123 conhost:SYSTEM_HOST)'
|
|
903
|
+
* ```
|
|
904
|
+
*
|
|
905
|
+
* @example
|
|
906
|
+
* ```ts
|
|
907
|
+
* // Multiple conhosts (multisite) + SYSTEM_HOST
|
|
908
|
+
* buildConhostWithSystemHost('+contentType:Blog +live:true +conhost:site-a +conhost:site-b')
|
|
909
|
+
* // → '+contentType:Blog +live:true +(conhost:site-a conhost:site-b conhost:SYSTEM_HOST)'
|
|
910
|
+
* ```
|
|
911
|
+
*
|
|
912
|
+
* @example
|
|
913
|
+
* ```ts
|
|
914
|
+
* // No conhost in query (no siteId configured)
|
|
915
|
+
* buildConhostWithSystemHost('+contentType:Blog +languageId:1 +live:true')
|
|
916
|
+
* // → '+contentType:Blog +languageId:1 +live:true +conhost:SYSTEM_HOST'
|
|
917
|
+
* ```
|
|
918
|
+
*
|
|
919
|
+
* @export
|
|
920
|
+
* @param {string} query - The fully assembled Lucene query string to process.
|
|
921
|
+
* @returns {string} The query with all positive conhost constraints replaced by a single grouped constraint.
|
|
922
|
+
*/
|
|
923
|
+
function buildConhostWithSystemHost(query) {
|
|
924
|
+
// Collect all unique positive conhost values, excluding SYSTEM_HOST (we'll add it explicitly)
|
|
925
|
+
const conhostRegex = /\+conhost:([^\s)]+)/gi;
|
|
926
|
+
const values = [];
|
|
927
|
+
let match;
|
|
928
|
+
while ((match = conhostRegex.exec(query)) !== null) {
|
|
929
|
+
const value = match[1];
|
|
930
|
+
if (value.toUpperCase() !== SYSTEM_HOST && !values.includes(value)) {
|
|
931
|
+
values.push(value);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
// Always include SYSTEM_HOST at the end
|
|
935
|
+
values.push(SYSTEM_HOST);
|
|
936
|
+
// Remove all existing +conhost: constraints from the query
|
|
937
|
+
const queryWithoutConhost = query
|
|
938
|
+
.replace(/\s*\+conhost:[^\s)]+/gi, '')
|
|
939
|
+
.replace(/\s+/g, ' ')
|
|
940
|
+
.trim();
|
|
941
|
+
// Build the final constraint:
|
|
942
|
+
// - Single value (only SYSTEM_HOST, no other conhost was present): simple form
|
|
943
|
+
// - Multiple values: grouped form so dotCMS treats them as OR
|
|
944
|
+
const conhostConstraint = values.length === 1
|
|
945
|
+
? `+conhost:${values[0]}`
|
|
946
|
+
: `+(${values.map((v) => `conhost:${v}`).join(' ')})`;
|
|
947
|
+
return `${queryWithoutConhost} ${conhostConstraint}`.trim();
|
|
948
|
+
}
|
|
882
949
|
|
|
883
950
|
var _Field_query;
|
|
884
951
|
/**
|
|
@@ -1381,7 +1448,7 @@ class QueryBuilder {
|
|
|
1381
1448
|
}
|
|
1382
1449
|
_QueryBuilder_query = new WeakMap();
|
|
1383
1450
|
|
|
1384
|
-
var _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_languageId, _CollectionBuilder_draft;
|
|
1451
|
+
var _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_languageId, _CollectionBuilder_draft, _CollectionBuilder_includeSystemHost;
|
|
1385
1452
|
/**
|
|
1386
1453
|
* Creates a Builder to filter and fetch content from the content API for a specific content type.
|
|
1387
1454
|
*
|
|
@@ -1407,6 +1474,7 @@ class CollectionBuilder extends BaseBuilder {
|
|
|
1407
1474
|
_CollectionBuilder_rawQuery.set(this, void 0);
|
|
1408
1475
|
_CollectionBuilder_languageId.set(this, 1);
|
|
1409
1476
|
_CollectionBuilder_draft.set(this, false);
|
|
1477
|
+
_CollectionBuilder_includeSystemHost.set(this, false);
|
|
1410
1478
|
__classPrivateFieldSet(this, _CollectionBuilder_contentType, params.contentType, "f");
|
|
1411
1479
|
// Build the default query with the contentType field
|
|
1412
1480
|
__classPrivateFieldSet(this, _CollectionBuilder_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _CollectionBuilder_contentType, "f")), "f");
|
|
@@ -1476,6 +1544,32 @@ class CollectionBuilder extends BaseBuilder {
|
|
|
1476
1544
|
__classPrivateFieldSet(this, _CollectionBuilder_draft, true, "f");
|
|
1477
1545
|
return this;
|
|
1478
1546
|
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Includes content from the dotCMS System Host in the query results.
|
|
1549
|
+
*
|
|
1550
|
+
* When enabled, content from the System Host is returned alongside content from
|
|
1551
|
+
* the configured site. All positive `+conhost:` constraints present in the
|
|
1552
|
+
* assembled query are collected and grouped into a single `+(conhost:X conhost:SYSTEM_HOST)`
|
|
1553
|
+
* constraint, so dotCMS returns content from any of those hosts.
|
|
1554
|
+
*
|
|
1555
|
+
* Calling this method multiple times is idempotent — the constraint is only added once.
|
|
1556
|
+
*
|
|
1557
|
+
* @example
|
|
1558
|
+
* ```ts
|
|
1559
|
+
* client.content
|
|
1560
|
+
* .getCollection<Blog>('Blog')
|
|
1561
|
+
* .includeSystemHost()
|
|
1562
|
+
* .limit(10)
|
|
1563
|
+
* .then(({ contentlets }) => console.log(contentlets));
|
|
1564
|
+
* ```
|
|
1565
|
+
*
|
|
1566
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
1567
|
+
* @memberof CollectionBuilder
|
|
1568
|
+
*/
|
|
1569
|
+
includeSystemHost() {
|
|
1570
|
+
__classPrivateFieldSet(this, _CollectionBuilder_includeSystemHost, true, "f");
|
|
1571
|
+
return this;
|
|
1572
|
+
}
|
|
1479
1573
|
/**
|
|
1480
1574
|
* Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
|
|
1481
1575
|
*
|
|
@@ -1587,10 +1681,17 @@ class CollectionBuilder extends BaseBuilder {
|
|
|
1587
1681
|
const sanitizedQuery = sanitizeQueryForContentType(finalQuery, __classPrivateFieldGet(this, _CollectionBuilder_contentType, "f"));
|
|
1588
1682
|
// Append raw query if provided (raw query is NOT sanitized for content type)
|
|
1589
1683
|
const query = __classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f") ? `${sanitizedQuery} ${__classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f")}` : sanitizedQuery;
|
|
1590
|
-
|
|
1684
|
+
const assembled = sanitizeQuery(query);
|
|
1685
|
+
// If includeSystemHost is active, collect all +conhost: values from the fully
|
|
1686
|
+
// assembled query (including those from the raw path), group them, and append
|
|
1687
|
+
// SYSTEM_HOST so dotCMS returns content from any of the matched hosts.
|
|
1688
|
+
if (__classPrivateFieldGet(this, _CollectionBuilder_includeSystemHost, "f")) {
|
|
1689
|
+
return buildConhostWithSystemHost(assembled);
|
|
1690
|
+
}
|
|
1691
|
+
return assembled;
|
|
1591
1692
|
}
|
|
1592
1693
|
}
|
|
1593
|
-
_CollectionBuilder_contentType = new WeakMap(), _CollectionBuilder_defaultQuery = new WeakMap(), _CollectionBuilder_query = new WeakMap(), _CollectionBuilder_rawQuery = new WeakMap(), _CollectionBuilder_languageId = new WeakMap(), _CollectionBuilder_draft = new WeakMap();
|
|
1694
|
+
_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_includeSystemHost = new WeakMap();
|
|
1594
1695
|
|
|
1595
1696
|
var _RawQueryBuilder_rawQuery, _RawQueryBuilder_languageId;
|
|
1596
1697
|
/**
|
package/index.esm.js
CHANGED
|
@@ -508,6 +508,11 @@ class AIClient extends BaseApiClient {
|
|
|
508
508
|
/**
|
|
509
509
|
* Default variant identifier used in the application.
|
|
510
510
|
*/
|
|
511
|
+
/**
|
|
512
|
+
* Identifier for the dotCMS System Host.
|
|
513
|
+
* Used when building queries that should include content from the System Host.
|
|
514
|
+
*/
|
|
515
|
+
const SYSTEM_HOST = 'SYSTEM_HOST';
|
|
511
516
|
/**
|
|
512
517
|
* Fields that should not be formatted when sanitizing the query.
|
|
513
518
|
* These fields are essential for maintaining the integrity of the content type.
|
|
@@ -877,6 +882,68 @@ function shouldAddSiteIdConstraint(query, siteId) {
|
|
|
877
882
|
}
|
|
878
883
|
return true;
|
|
879
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* @description
|
|
887
|
+
* Collects all positive `+conhost:` values from a fully assembled Lucene query,
|
|
888
|
+
* removes them from their original positions, adds SYSTEM_HOST to the set,
|
|
889
|
+
* and rebuilds a single grouped constraint at the end of the query.
|
|
890
|
+
*
|
|
891
|
+
* This function is designed to be called on the final assembled query string
|
|
892
|
+
* (after raw query has been appended) so that conhosts from all sources —
|
|
893
|
+
* auto-injected siteId, builder-path conhost, and raw-path conhost — are
|
|
894
|
+
* all visible and handled uniformly.
|
|
895
|
+
*
|
|
896
|
+
* @example
|
|
897
|
+
* ```ts
|
|
898
|
+
* // Single siteId + SYSTEM_HOST
|
|
899
|
+
* buildConhostWithSystemHost('+contentType:Blog +languageId:1 +live:true +conhost:site-123')
|
|
900
|
+
* // → '+contentType:Blog +languageId:1 +live:true +(conhost:site-123 conhost:SYSTEM_HOST)'
|
|
901
|
+
* ```
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```ts
|
|
905
|
+
* // Multiple conhosts (multisite) + SYSTEM_HOST
|
|
906
|
+
* buildConhostWithSystemHost('+contentType:Blog +live:true +conhost:site-a +conhost:site-b')
|
|
907
|
+
* // → '+contentType:Blog +live:true +(conhost:site-a conhost:site-b conhost:SYSTEM_HOST)'
|
|
908
|
+
* ```
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```ts
|
|
912
|
+
* // No conhost in query (no siteId configured)
|
|
913
|
+
* buildConhostWithSystemHost('+contentType:Blog +languageId:1 +live:true')
|
|
914
|
+
* // → '+contentType:Blog +languageId:1 +live:true +conhost:SYSTEM_HOST'
|
|
915
|
+
* ```
|
|
916
|
+
*
|
|
917
|
+
* @export
|
|
918
|
+
* @param {string} query - The fully assembled Lucene query string to process.
|
|
919
|
+
* @returns {string} The query with all positive conhost constraints replaced by a single grouped constraint.
|
|
920
|
+
*/
|
|
921
|
+
function buildConhostWithSystemHost(query) {
|
|
922
|
+
// Collect all unique positive conhost values, excluding SYSTEM_HOST (we'll add it explicitly)
|
|
923
|
+
const conhostRegex = /\+conhost:([^\s)]+)/gi;
|
|
924
|
+
const values = [];
|
|
925
|
+
let match;
|
|
926
|
+
while ((match = conhostRegex.exec(query)) !== null) {
|
|
927
|
+
const value = match[1];
|
|
928
|
+
if (value.toUpperCase() !== SYSTEM_HOST && !values.includes(value)) {
|
|
929
|
+
values.push(value);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
// Always include SYSTEM_HOST at the end
|
|
933
|
+
values.push(SYSTEM_HOST);
|
|
934
|
+
// Remove all existing +conhost: constraints from the query
|
|
935
|
+
const queryWithoutConhost = query
|
|
936
|
+
.replace(/\s*\+conhost:[^\s)]+/gi, '')
|
|
937
|
+
.replace(/\s+/g, ' ')
|
|
938
|
+
.trim();
|
|
939
|
+
// Build the final constraint:
|
|
940
|
+
// - Single value (only SYSTEM_HOST, no other conhost was present): simple form
|
|
941
|
+
// - Multiple values: grouped form so dotCMS treats them as OR
|
|
942
|
+
const conhostConstraint = values.length === 1
|
|
943
|
+
? `+conhost:${values[0]}`
|
|
944
|
+
: `+(${values.map((v) => `conhost:${v}`).join(' ')})`;
|
|
945
|
+
return `${queryWithoutConhost} ${conhostConstraint}`.trim();
|
|
946
|
+
}
|
|
880
947
|
|
|
881
948
|
var _Field_query;
|
|
882
949
|
/**
|
|
@@ -1379,7 +1446,7 @@ class QueryBuilder {
|
|
|
1379
1446
|
}
|
|
1380
1447
|
_QueryBuilder_query = new WeakMap();
|
|
1381
1448
|
|
|
1382
|
-
var _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_languageId, _CollectionBuilder_draft;
|
|
1449
|
+
var _CollectionBuilder_contentType, _CollectionBuilder_defaultQuery, _CollectionBuilder_query, _CollectionBuilder_rawQuery, _CollectionBuilder_languageId, _CollectionBuilder_draft, _CollectionBuilder_includeSystemHost;
|
|
1383
1450
|
/**
|
|
1384
1451
|
* Creates a Builder to filter and fetch content from the content API for a specific content type.
|
|
1385
1452
|
*
|
|
@@ -1405,6 +1472,7 @@ class CollectionBuilder extends BaseBuilder {
|
|
|
1405
1472
|
_CollectionBuilder_rawQuery.set(this, void 0);
|
|
1406
1473
|
_CollectionBuilder_languageId.set(this, 1);
|
|
1407
1474
|
_CollectionBuilder_draft.set(this, false);
|
|
1475
|
+
_CollectionBuilder_includeSystemHost.set(this, false);
|
|
1408
1476
|
__classPrivateFieldSet(this, _CollectionBuilder_contentType, params.contentType, "f");
|
|
1409
1477
|
// Build the default query with the contentType field
|
|
1410
1478
|
__classPrivateFieldSet(this, _CollectionBuilder_defaultQuery, new QueryBuilder().field('contentType').equals(__classPrivateFieldGet(this, _CollectionBuilder_contentType, "f")), "f");
|
|
@@ -1474,6 +1542,32 @@ class CollectionBuilder extends BaseBuilder {
|
|
|
1474
1542
|
__classPrivateFieldSet(this, _CollectionBuilder_draft, true, "f");
|
|
1475
1543
|
return this;
|
|
1476
1544
|
}
|
|
1545
|
+
/**
|
|
1546
|
+
* Includes content from the dotCMS System Host in the query results.
|
|
1547
|
+
*
|
|
1548
|
+
* When enabled, content from the System Host is returned alongside content from
|
|
1549
|
+
* the configured site. All positive `+conhost:` constraints present in the
|
|
1550
|
+
* assembled query are collected and grouped into a single `+(conhost:X conhost:SYSTEM_HOST)`
|
|
1551
|
+
* constraint, so dotCMS returns content from any of those hosts.
|
|
1552
|
+
*
|
|
1553
|
+
* Calling this method multiple times is idempotent — the constraint is only added once.
|
|
1554
|
+
*
|
|
1555
|
+
* @example
|
|
1556
|
+
* ```ts
|
|
1557
|
+
* client.content
|
|
1558
|
+
* .getCollection<Blog>('Blog')
|
|
1559
|
+
* .includeSystemHost()
|
|
1560
|
+
* .limit(10)
|
|
1561
|
+
* .then(({ contentlets }) => console.log(contentlets));
|
|
1562
|
+
* ```
|
|
1563
|
+
*
|
|
1564
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
1565
|
+
* @memberof CollectionBuilder
|
|
1566
|
+
*/
|
|
1567
|
+
includeSystemHost() {
|
|
1568
|
+
__classPrivateFieldSet(this, _CollectionBuilder_includeSystemHost, true, "f");
|
|
1569
|
+
return this;
|
|
1570
|
+
}
|
|
1477
1571
|
/**
|
|
1478
1572
|
* Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
|
|
1479
1573
|
*
|
|
@@ -1585,10 +1679,17 @@ class CollectionBuilder extends BaseBuilder {
|
|
|
1585
1679
|
const sanitizedQuery = sanitizeQueryForContentType(finalQuery, __classPrivateFieldGet(this, _CollectionBuilder_contentType, "f"));
|
|
1586
1680
|
// Append raw query if provided (raw query is NOT sanitized for content type)
|
|
1587
1681
|
const query = __classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f") ? `${sanitizedQuery} ${__classPrivateFieldGet(this, _CollectionBuilder_rawQuery, "f")}` : sanitizedQuery;
|
|
1588
|
-
|
|
1682
|
+
const assembled = sanitizeQuery(query);
|
|
1683
|
+
// If includeSystemHost is active, collect all +conhost: values from the fully
|
|
1684
|
+
// assembled query (including those from the raw path), group them, and append
|
|
1685
|
+
// SYSTEM_HOST so dotCMS returns content from any of the matched hosts.
|
|
1686
|
+
if (__classPrivateFieldGet(this, _CollectionBuilder_includeSystemHost, "f")) {
|
|
1687
|
+
return buildConhostWithSystemHost(assembled);
|
|
1688
|
+
}
|
|
1689
|
+
return assembled;
|
|
1589
1690
|
}
|
|
1590
1691
|
}
|
|
1591
|
-
_CollectionBuilder_contentType = new WeakMap(), _CollectionBuilder_defaultQuery = new WeakMap(), _CollectionBuilder_query = new WeakMap(), _CollectionBuilder_rawQuery = new WeakMap(), _CollectionBuilder_languageId = new WeakMap(), _CollectionBuilder_draft = new WeakMap();
|
|
1692
|
+
_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_includeSystemHost = new WeakMap();
|
|
1592
1693
|
|
|
1593
1694
|
var _RawQueryBuilder_rawQuery, _RawQueryBuilder_languageId;
|
|
1594
1695
|
/**
|
package/package.json
CHANGED
|
@@ -89,6 +89,29 @@ export declare class CollectionBuilder<T = unknown> extends BaseBuilder<T> {
|
|
|
89
89
|
* @memberof CollectionBuilder
|
|
90
90
|
*/
|
|
91
91
|
draft(): this;
|
|
92
|
+
/**
|
|
93
|
+
* Includes content from the dotCMS System Host in the query results.
|
|
94
|
+
*
|
|
95
|
+
* When enabled, content from the System Host is returned alongside content from
|
|
96
|
+
* the configured site. All positive `+conhost:` constraints present in the
|
|
97
|
+
* assembled query are collected and grouped into a single `+(conhost:X conhost:SYSTEM_HOST)`
|
|
98
|
+
* constraint, so dotCMS returns content from any of those hosts.
|
|
99
|
+
*
|
|
100
|
+
* Calling this method multiple times is idempotent — the constraint is only added once.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* client.content
|
|
105
|
+
* .getCollection<Blog>('Blog')
|
|
106
|
+
* .includeSystemHost()
|
|
107
|
+
* .limit(10)
|
|
108
|
+
* .then(({ contentlets }) => console.log(contentlets));
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @return {CollectionBuilder} A CollectionBuilder instance.
|
|
112
|
+
* @memberof CollectionBuilder
|
|
113
|
+
*/
|
|
114
|
+
includeSystemHost(): this;
|
|
92
115
|
/**
|
|
93
116
|
* Filters the content by a variant ID for [Experiments](https://www.dotcms.com/docs/latest/experiments-and-a-b-testing)
|
|
94
117
|
*
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
* Default variant identifier used in the application.
|
|
3
3
|
*/
|
|
4
4
|
export declare const DEFAULT_VARIANT_ID = "DEFAULT";
|
|
5
|
+
/**
|
|
6
|
+
* Identifier for the dotCMS System Host.
|
|
7
|
+
* Used when building queries that should include content from the System Host.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SYSTEM_HOST = "SYSTEM_HOST";
|
|
5
10
|
/**
|
|
6
11
|
* Fields that should not be formatted when sanitizing the query.
|
|
7
12
|
* These fields are essential for maintaining the integrity of the content type.
|
|
@@ -54,3 +54,40 @@ export declare function sanitizeQueryForContentType(query: string, contentType:
|
|
|
54
54
|
* @returns {boolean} True if site ID constraint should be added, false otherwise
|
|
55
55
|
*/
|
|
56
56
|
export declare function shouldAddSiteIdConstraint(query: string, siteId: string | number | null | undefined): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* @description
|
|
59
|
+
* Collects all positive `+conhost:` values from a fully assembled Lucene query,
|
|
60
|
+
* removes them from their original positions, adds SYSTEM_HOST to the set,
|
|
61
|
+
* and rebuilds a single grouped constraint at the end of the query.
|
|
62
|
+
*
|
|
63
|
+
* This function is designed to be called on the final assembled query string
|
|
64
|
+
* (after raw query has been appended) so that conhosts from all sources —
|
|
65
|
+
* auto-injected siteId, builder-path conhost, and raw-path conhost — are
|
|
66
|
+
* all visible and handled uniformly.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* // Single siteId + SYSTEM_HOST
|
|
71
|
+
* buildConhostWithSystemHost('+contentType:Blog +languageId:1 +live:true +conhost:site-123')
|
|
72
|
+
* // → '+contentType:Blog +languageId:1 +live:true +(conhost:site-123 conhost:SYSTEM_HOST)'
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* // Multiple conhosts (multisite) + SYSTEM_HOST
|
|
78
|
+
* buildConhostWithSystemHost('+contentType:Blog +live:true +conhost:site-a +conhost:site-b')
|
|
79
|
+
* // → '+contentType:Blog +live:true +(conhost:site-a conhost:site-b conhost:SYSTEM_HOST)'
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* // No conhost in query (no siteId configured)
|
|
85
|
+
* buildConhostWithSystemHost('+contentType:Blog +languageId:1 +live:true')
|
|
86
|
+
* // → '+contentType:Blog +languageId:1 +live:true +conhost:SYSTEM_HOST'
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @export
|
|
90
|
+
* @param {string} query - The fully assembled Lucene query string to process.
|
|
91
|
+
* @returns {string} The query with all positive conhost constraints replaced by a single grouped constraint.
|
|
92
|
+
*/
|
|
93
|
+
export declare function buildConhostWithSystemHost(query: string): string;
|