@dotcms/client 1.2.0-next.6 → 1.2.0-next.8
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
CHANGED
|
@@ -546,7 +546,9 @@ const CONTENT_API_URL = '/api/content/_search';
|
|
|
546
546
|
* @returns {string} The sanitized query string.
|
|
547
547
|
*/
|
|
548
548
|
function sanitizeQueryForContentType(query, contentType) {
|
|
549
|
-
|
|
549
|
+
// Match field names that start with letter/underscore, followed by alphanumeric/underscore/dot
|
|
550
|
+
// This excludes Lucene grouping operators like +(...)
|
|
551
|
+
return query.replace(/\+([a-zA-Z_][a-zA-Z0-9_.]*):/g, (original, field) => {
|
|
550
552
|
return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not content type fields
|
|
551
553
|
? `+${contentType}.${field}:` // Should have this format: +contentTypeVar.field:
|
|
552
554
|
: original; // Return the field if it is a content type field
|
|
@@ -1462,7 +1464,7 @@ class CollectionBuilder extends BaseApiClient {
|
|
|
1462
1464
|
*
|
|
1463
1465
|
* @example
|
|
1464
1466
|
* // For draft content without site constraint:
|
|
1465
|
-
* // Returns: "+contentType:Blog +languageId:1 +live:false"
|
|
1467
|
+
* // Returns: "+contentType:Blog +languageId:1 +(live:false AND working:true AND deleted:false)"
|
|
1466
1468
|
*
|
|
1467
1469
|
* @example
|
|
1468
1470
|
* // For content with explicit exclusion of current site (site ID 123):
|
|
@@ -1476,20 +1478,22 @@ class CollectionBuilder extends BaseApiClient {
|
|
|
1476
1478
|
*/
|
|
1477
1479
|
getFinalQuery() {
|
|
1478
1480
|
// Build base query with language and live/draft constraints
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
.
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
.
|
|
1481
|
+
let baseQuery = this.currentQuery.field('languageId').equals(__classPrivateFieldGet(this, _CollectionBuilder_languageId, "f").toString());
|
|
1482
|
+
if (__classPrivateFieldGet(this, _CollectionBuilder_draft, "f")) {
|
|
1483
|
+
baseQuery = baseQuery.raw('+(live:false AND working:true AND deleted:false)');
|
|
1484
|
+
}
|
|
1485
|
+
else {
|
|
1486
|
+
baseQuery = baseQuery.field('live').equals('true');
|
|
1487
|
+
}
|
|
1488
|
+
const builtQuery = baseQuery.build();
|
|
1485
1489
|
// Check if site ID constraint should be added using utility function
|
|
1486
|
-
const shouldAddSiteId = shouldAddSiteIdConstraint(
|
|
1490
|
+
const shouldAddSiteId = shouldAddSiteIdConstraint(builtQuery, this.siteId);
|
|
1487
1491
|
// Add site ID constraint if needed
|
|
1488
1492
|
if (shouldAddSiteId) {
|
|
1489
|
-
const queryWithSiteId = `${
|
|
1493
|
+
const queryWithSiteId = `${builtQuery} +conhost:${this.siteId}`;
|
|
1490
1494
|
return sanitizeQuery(queryWithSiteId);
|
|
1491
1495
|
}
|
|
1492
|
-
return
|
|
1496
|
+
return builtQuery;
|
|
1493
1497
|
}
|
|
1494
1498
|
}
|
|
1495
1499
|
_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();
|
|
@@ -2043,12 +2047,25 @@ class PageClient extends BaseApiClient {
|
|
|
2043
2047
|
response.errors.forEach((error) => {
|
|
2044
2048
|
consola.consola.error('[DotCMS GraphQL Error]: ', error.message);
|
|
2045
2049
|
});
|
|
2050
|
+
const pageError = response.errors.find((error) => error.message.includes('DotPage'));
|
|
2051
|
+
if (pageError) {
|
|
2052
|
+
// Throw HTTP error - will be caught and wrapped in DotErrorPage below
|
|
2053
|
+
throw new types.DotHttpError({
|
|
2054
|
+
status: 400,
|
|
2055
|
+
statusText: 'Bad Request',
|
|
2056
|
+
message: `GraphQL query failed for URL '${url}': ${pageError.message}`,
|
|
2057
|
+
data: response.errors
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
2046
2060
|
}
|
|
2047
2061
|
const pageResponse = internal.graphqlToPageEntity(response.data.page);
|
|
2048
2062
|
if (!pageResponse) {
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2063
|
+
// Throw HTTP error - will be caught and wrapped in DotErrorPage below
|
|
2064
|
+
throw new types.DotHttpError({
|
|
2065
|
+
status: 404,
|
|
2066
|
+
statusText: 'Not Found',
|
|
2067
|
+
message: `Page ${url} not found. Check the page URL and permissions.`,
|
|
2068
|
+
data: response.errors
|
|
2052
2069
|
});
|
|
2053
2070
|
}
|
|
2054
2071
|
const contentResponse = mapContentResponse(response.data, Object.keys(content));
|
|
@@ -2062,7 +2079,7 @@ class PageClient extends BaseApiClient {
|
|
|
2062
2079
|
};
|
|
2063
2080
|
}
|
|
2064
2081
|
catch (error) {
|
|
2065
|
-
// Handle DotHttpError instances
|
|
2082
|
+
// Handle DotHttpError instances
|
|
2066
2083
|
if (error instanceof types.DotHttpError) {
|
|
2067
2084
|
throw new types.DotErrorPage(`Page request failed for URL '${url}': ${error.message}`, error, {
|
|
2068
2085
|
query: completeQuery,
|
package/index.esm.js
CHANGED
|
@@ -544,7 +544,9 @@ const CONTENT_API_URL = '/api/content/_search';
|
|
|
544
544
|
* @returns {string} The sanitized query string.
|
|
545
545
|
*/
|
|
546
546
|
function sanitizeQueryForContentType(query, contentType) {
|
|
547
|
-
|
|
547
|
+
// Match field names that start with letter/underscore, followed by alphanumeric/underscore/dot
|
|
548
|
+
// This excludes Lucene grouping operators like +(...)
|
|
549
|
+
return query.replace(/\+([a-zA-Z_][a-zA-Z0-9_.]*):/g, (original, field) => {
|
|
548
550
|
return !CONTENT_TYPE_MAIN_FIELDS.includes(field) // Fields that are not content type fields
|
|
549
551
|
? `+${contentType}.${field}:` // Should have this format: +contentTypeVar.field:
|
|
550
552
|
: original; // Return the field if it is a content type field
|
|
@@ -1460,7 +1462,7 @@ class CollectionBuilder extends BaseApiClient {
|
|
|
1460
1462
|
*
|
|
1461
1463
|
* @example
|
|
1462
1464
|
* // For draft content without site constraint:
|
|
1463
|
-
* // Returns: "+contentType:Blog +languageId:1 +live:false"
|
|
1465
|
+
* // Returns: "+contentType:Blog +languageId:1 +(live:false AND working:true AND deleted:false)"
|
|
1464
1466
|
*
|
|
1465
1467
|
* @example
|
|
1466
1468
|
* // For content with explicit exclusion of current site (site ID 123):
|
|
@@ -1474,20 +1476,22 @@ class CollectionBuilder extends BaseApiClient {
|
|
|
1474
1476
|
*/
|
|
1475
1477
|
getFinalQuery() {
|
|
1476
1478
|
// Build base query with language and live/draft constraints
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
.
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
.
|
|
1479
|
+
let baseQuery = this.currentQuery.field('languageId').equals(__classPrivateFieldGet(this, _CollectionBuilder_languageId, "f").toString());
|
|
1480
|
+
if (__classPrivateFieldGet(this, _CollectionBuilder_draft, "f")) {
|
|
1481
|
+
baseQuery = baseQuery.raw('+(live:false AND working:true AND deleted:false)');
|
|
1482
|
+
}
|
|
1483
|
+
else {
|
|
1484
|
+
baseQuery = baseQuery.field('live').equals('true');
|
|
1485
|
+
}
|
|
1486
|
+
const builtQuery = baseQuery.build();
|
|
1483
1487
|
// Check if site ID constraint should be added using utility function
|
|
1484
|
-
const shouldAddSiteId = shouldAddSiteIdConstraint(
|
|
1488
|
+
const shouldAddSiteId = shouldAddSiteIdConstraint(builtQuery, this.siteId);
|
|
1485
1489
|
// Add site ID constraint if needed
|
|
1486
1490
|
if (shouldAddSiteId) {
|
|
1487
|
-
const queryWithSiteId = `${
|
|
1491
|
+
const queryWithSiteId = `${builtQuery} +conhost:${this.siteId}`;
|
|
1488
1492
|
return sanitizeQuery(queryWithSiteId);
|
|
1489
1493
|
}
|
|
1490
|
-
return
|
|
1494
|
+
return builtQuery;
|
|
1491
1495
|
}
|
|
1492
1496
|
}
|
|
1493
1497
|
_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();
|
|
@@ -2041,12 +2045,25 @@ class PageClient extends BaseApiClient {
|
|
|
2041
2045
|
response.errors.forEach((error) => {
|
|
2042
2046
|
consola.error('[DotCMS GraphQL Error]: ', error.message);
|
|
2043
2047
|
});
|
|
2048
|
+
const pageError = response.errors.find((error) => error.message.includes('DotPage'));
|
|
2049
|
+
if (pageError) {
|
|
2050
|
+
// Throw HTTP error - will be caught and wrapped in DotErrorPage below
|
|
2051
|
+
throw new DotHttpError({
|
|
2052
|
+
status: 400,
|
|
2053
|
+
statusText: 'Bad Request',
|
|
2054
|
+
message: `GraphQL query failed for URL '${url}': ${pageError.message}`,
|
|
2055
|
+
data: response.errors
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2044
2058
|
}
|
|
2045
2059
|
const pageResponse = graphqlToPageEntity(response.data.page);
|
|
2046
2060
|
if (!pageResponse) {
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2061
|
+
// Throw HTTP error - will be caught and wrapped in DotErrorPage below
|
|
2062
|
+
throw new DotHttpError({
|
|
2063
|
+
status: 404,
|
|
2064
|
+
statusText: 'Not Found',
|
|
2065
|
+
message: `Page ${url} not found. Check the page URL and permissions.`,
|
|
2066
|
+
data: response.errors
|
|
2050
2067
|
});
|
|
2051
2068
|
}
|
|
2052
2069
|
const contentResponse = mapContentResponse(response.data, Object.keys(content));
|
|
@@ -2060,7 +2077,7 @@ class PageClient extends BaseApiClient {
|
|
|
2060
2077
|
};
|
|
2061
2078
|
}
|
|
2062
2079
|
catch (error) {
|
|
2063
|
-
// Handle DotHttpError instances
|
|
2080
|
+
// Handle DotHttpError instances
|
|
2064
2081
|
if (error instanceof DotHttpError) {
|
|
2065
2082
|
throw new DotErrorPage(`Page request failed for URL '${url}': ${error.message}`, error, {
|
|
2066
2083
|
query: completeQuery,
|
package/package.json
CHANGED
|
@@ -249,7 +249,7 @@ export declare class CollectionBuilder<T = unknown> extends BaseApiClient {
|
|
|
249
249
|
*
|
|
250
250
|
* @example
|
|
251
251
|
* // For draft content without site constraint:
|
|
252
|
-
* // Returns: "+contentType:Blog +languageId:1 +live:false"
|
|
252
|
+
* // Returns: "+contentType:Blog +languageId:1 +(live:false AND working:true AND deleted:false)"
|
|
253
253
|
*
|
|
254
254
|
* @example
|
|
255
255
|
* // For content with explicit exclusion of current site (site ID 123):
|