@dotcms/client 1.5.2-next.28 → 1.5.4-next.33

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
@@ -2160,6 +2160,7 @@ const buildPageQuery = ({ page, fragments, additionalQueries, verbose = false })
2160
2160
  lockedBy
2161
2161
  lockedByName
2162
2162
  numberContents
2163
+ styleEditorSchemas
2163
2164
  urlContentMap {
2164
2165
  _map
2165
2166
  }
@@ -2309,46 +2310,6 @@ function mapContentResponse(responseData, keys) {
2309
2310
  return accumulator;
2310
2311
  }, {});
2311
2312
  }
2312
- /**
2313
- * Loads style editor schemas from GET /api/v1/page/{pageId}/contenttype-schema.
2314
- * Requires READ on the page; failures are silently ignored so callers still work without auth.
2315
- *
2316
- * @internal
2317
- */
2318
- async function fetchStyleEditorSchemas(pageId, config, requestOptions, httpClient) {
2319
- if (!pageId) {
2320
- console.warn('[DotCMS PageClient]: fetchStyleEditorSchemas called without a pageId — ' +
2321
- 'make sure "identifier" is included in your GraphQL page fragment.');
2322
- return [];
2323
- }
2324
- try {
2325
- const url = new URL(config.dotcmsUrl);
2326
- url.pathname = `/api/v1/page/${encodeURIComponent(pageId)}/contenttype-schema`;
2327
- const data = await httpClient.request(url.toString(), {
2328
- ...requestOptions,
2329
- method: 'GET',
2330
- headers: {
2331
- Accept: 'application/json',
2332
- ...requestOptions.headers
2333
- }
2334
- });
2335
- const { entity } = data ?? {};
2336
- if (!Array.isArray(entity)) {
2337
- return [];
2338
- }
2339
- return entity;
2340
- }
2341
- catch (error) {
2342
- if (error instanceof types.DotHttpError && (error.status === 401 || error.status === 403)) {
2343
- console.warn(`[DotCMS PageClient]: Style editor schemas request failed with ${error.status} — ` +
2344
- 'make sure your DotCMS client is configured with a valid authToken that has READ access to the page.');
2345
- }
2346
- else {
2347
- console.warn('[DotCMS PageClient]: Skipping style editor schemas:', error);
2348
- }
2349
- return [];
2350
- }
2351
- }
2352
2313
  /**
2353
2314
  * Executes a GraphQL query against the DotCMS API.
2354
2315
  *
@@ -2472,7 +2433,8 @@ class PageClient extends BaseApiClient {
2472
2433
  const requestVariables = {
2473
2434
  // The url is expected to have a leading slash to comply on VanityURL Matching, some frameworks like Angular will not add the leading slash
2474
2435
  url: normalizedUrl,
2475
- mode,
2436
+ // Translate the UVE_MODE key ('EDIT' | 'PREVIEW' | ...) to the value the backend PageMode enum expects ('EDIT_MODE' | 'PREVIEW_MODE' | ...)
2437
+ mode: types.UVE_MODE[mode],
2476
2438
  languageId,
2477
2439
  personaId,
2478
2440
  fireRules,
@@ -2523,8 +2485,8 @@ class PageClient extends BaseApiClient {
2523
2485
  if (response.errors?.length && !response.data.page) {
2524
2486
  const structuredError = response.errors.find((error) => error.extensions?.code);
2525
2487
  if (structuredError) {
2526
- const code = structuredError.extensions.code;
2527
- const status = structuredError.extensions.status ??
2488
+ const code = structuredError.extensions?.code;
2489
+ const status = structuredError.extensions?.status ??
2528
2490
  (code === 'NOT_FOUND' ? 404 : code === 'PERMISSION_DENIED' ? 403 : 400);
2529
2491
  const message = code === 'NOT_FOUND'
2530
2492
  ? `Page '${normalizedUrl}' was not found`
@@ -2551,6 +2513,7 @@ class PageClient extends BaseApiClient {
2551
2513
  const pageResponse = response.data.page
2552
2514
  ? internal.graphqlToPageEntity(response.data.page)
2553
2515
  : null;
2516
+ const styleEditorSchemas = pageResponse ? pageResponse.page.styleEditorSchemas : [];
2554
2517
  if (!pageResponse) {
2555
2518
  throw new types.DotErrorPage(`Page '${normalizedUrl}' was not found`, 404, 'NOT_FOUND', new types.DotHttpError({
2556
2519
  status: 404,
@@ -2559,7 +2522,6 @@ class PageClient extends BaseApiClient {
2559
2522
  data: response.errors
2560
2523
  }), { query: completeQuery, variables: requestVariables });
2561
2524
  }
2562
- const styleEditorSchemas = await fetchStyleEditorSchemas(pageResponse.page.identifier, this.config, this.requestOptions, this.httpClient);
2563
2525
  // 5. Build response — include any non-fatal errors for consumers to inspect
2564
2526
  const contentResponse = mapContentResponse(response.data, Object.keys(content));
2565
2527
  return {
@@ -2570,7 +2532,7 @@ class PageClient extends BaseApiClient {
2570
2532
  variables: requestVariables
2571
2533
  },
2572
2534
  errors: response.errors?.length ? response.errors : undefined,
2573
- ...(styleEditorSchemas.length > 0 && { styleEditorSchemas })
2535
+ ...(styleEditorSchemas?.length && { styleEditorSchemas })
2574
2536
  };
2575
2537
  }
2576
2538
  catch (error) {
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { consola } from 'consola';
2
- import { BaseHttpClient, DISTANCE_FUNCTIONS, DotHttpError, DotErrorAISearch, DotErrorContent, DotErrorNavigation, DotErrorPage } from '@dotcms/types';
2
+ import { BaseHttpClient, DISTANCE_FUNCTIONS, DotHttpError, DotErrorAISearch, DotErrorContent, DotErrorNavigation, UVE_MODE, DotErrorPage } from '@dotcms/types';
3
3
  import { graphqlToPageEntity } from './internal.esm.js';
4
4
 
5
5
  /**
@@ -2158,6 +2158,7 @@ const buildPageQuery = ({ page, fragments, additionalQueries, verbose = false })
2158
2158
  lockedBy
2159
2159
  lockedByName
2160
2160
  numberContents
2161
+ styleEditorSchemas
2161
2162
  urlContentMap {
2162
2163
  _map
2163
2164
  }
@@ -2307,46 +2308,6 @@ function mapContentResponse(responseData, keys) {
2307
2308
  return accumulator;
2308
2309
  }, {});
2309
2310
  }
2310
- /**
2311
- * Loads style editor schemas from GET /api/v1/page/{pageId}/contenttype-schema.
2312
- * Requires READ on the page; failures are silently ignored so callers still work without auth.
2313
- *
2314
- * @internal
2315
- */
2316
- async function fetchStyleEditorSchemas(pageId, config, requestOptions, httpClient) {
2317
- if (!pageId) {
2318
- console.warn('[DotCMS PageClient]: fetchStyleEditorSchemas called without a pageId — ' +
2319
- 'make sure "identifier" is included in your GraphQL page fragment.');
2320
- return [];
2321
- }
2322
- try {
2323
- const url = new URL(config.dotcmsUrl);
2324
- url.pathname = `/api/v1/page/${encodeURIComponent(pageId)}/contenttype-schema`;
2325
- const data = await httpClient.request(url.toString(), {
2326
- ...requestOptions,
2327
- method: 'GET',
2328
- headers: {
2329
- Accept: 'application/json',
2330
- ...requestOptions.headers
2331
- }
2332
- });
2333
- const { entity } = data ?? {};
2334
- if (!Array.isArray(entity)) {
2335
- return [];
2336
- }
2337
- return entity;
2338
- }
2339
- catch (error) {
2340
- if (error instanceof DotHttpError && (error.status === 401 || error.status === 403)) {
2341
- console.warn(`[DotCMS PageClient]: Style editor schemas request failed with ${error.status} — ` +
2342
- 'make sure your DotCMS client is configured with a valid authToken that has READ access to the page.');
2343
- }
2344
- else {
2345
- console.warn('[DotCMS PageClient]: Skipping style editor schemas:', error);
2346
- }
2347
- return [];
2348
- }
2349
- }
2350
2311
  /**
2351
2312
  * Executes a GraphQL query against the DotCMS API.
2352
2313
  *
@@ -2470,7 +2431,8 @@ class PageClient extends BaseApiClient {
2470
2431
  const requestVariables = {
2471
2432
  // The url is expected to have a leading slash to comply on VanityURL Matching, some frameworks like Angular will not add the leading slash
2472
2433
  url: normalizedUrl,
2473
- mode,
2434
+ // Translate the UVE_MODE key ('EDIT' | 'PREVIEW' | ...) to the value the backend PageMode enum expects ('EDIT_MODE' | 'PREVIEW_MODE' | ...)
2435
+ mode: UVE_MODE[mode],
2474
2436
  languageId,
2475
2437
  personaId,
2476
2438
  fireRules,
@@ -2521,8 +2483,8 @@ class PageClient extends BaseApiClient {
2521
2483
  if (response.errors?.length && !response.data.page) {
2522
2484
  const structuredError = response.errors.find((error) => error.extensions?.code);
2523
2485
  if (structuredError) {
2524
- const code = structuredError.extensions.code;
2525
- const status = structuredError.extensions.status ??
2486
+ const code = structuredError.extensions?.code;
2487
+ const status = structuredError.extensions?.status ??
2526
2488
  (code === 'NOT_FOUND' ? 404 : code === 'PERMISSION_DENIED' ? 403 : 400);
2527
2489
  const message = code === 'NOT_FOUND'
2528
2490
  ? `Page '${normalizedUrl}' was not found`
@@ -2549,6 +2511,7 @@ class PageClient extends BaseApiClient {
2549
2511
  const pageResponse = response.data.page
2550
2512
  ? graphqlToPageEntity(response.data.page)
2551
2513
  : null;
2514
+ const styleEditorSchemas = pageResponse ? pageResponse.page.styleEditorSchemas : [];
2552
2515
  if (!pageResponse) {
2553
2516
  throw new DotErrorPage(`Page '${normalizedUrl}' was not found`, 404, 'NOT_FOUND', new DotHttpError({
2554
2517
  status: 404,
@@ -2557,7 +2520,6 @@ class PageClient extends BaseApiClient {
2557
2520
  data: response.errors
2558
2521
  }), { query: completeQuery, variables: requestVariables });
2559
2522
  }
2560
- const styleEditorSchemas = await fetchStyleEditorSchemas(pageResponse.page.identifier, this.config, this.requestOptions, this.httpClient);
2561
2523
  // 5. Build response — include any non-fatal errors for consumers to inspect
2562
2524
  const contentResponse = mapContentResponse(response.data, Object.keys(content));
2563
2525
  return {
@@ -2568,7 +2530,7 @@ class PageClient extends BaseApiClient {
2568
2530
  variables: requestVariables
2569
2531
  },
2570
2532
  errors: response.errors?.length ? response.errors : undefined,
2571
- ...(styleEditorSchemas.length > 0 && { styleEditorSchemas })
2533
+ ...(styleEditorSchemas?.length && { styleEditorSchemas })
2572
2534
  };
2573
2535
  }
2574
2536
  catch (error) {
package/internal.cjs.js CHANGED
@@ -42,7 +42,10 @@ const graphqlToPageEntity = (page) => {
42
42
  containers: parseContainers(containers),
43
43
  page: {
44
44
  ...data,
45
- ...typedPageAsset
45
+ ...typedPageAsset,
46
+ // GQL returns null when not in EDIT_MODE; normalize to undefined so the
47
+ // DotCMSPage type (StyleEditorFormSchema[], non-null) remains accurate.
48
+ styleEditorSchemas: typedPageAsset.styleEditorSchemas ?? undefined
46
49
  }
47
50
  };
48
51
  };
package/internal.esm.js CHANGED
@@ -40,7 +40,10 @@ const graphqlToPageEntity = (page) => {
40
40
  containers: parseContainers(containers),
41
41
  page: {
42
42
  ...data,
43
- ...typedPageAsset
43
+ ...typedPageAsset,
44
+ // GQL returns null when not in EDIT_MODE; normalize to undefined so the
45
+ // DotCMSPage type (StyleEditorFormSchema[], non-null) remains accurate.
46
+ styleEditorSchemas: typedPageAsset.styleEditorSchemas ?? undefined
44
47
  }
45
48
  };
46
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/client",
3
- "version": "1.5.2-next.28",
3
+ "version": "1.5.4-next.33",
4
4
  "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,4 @@
1
- import { DotCMSClientConfig, DotGraphQLApiResponse, DotHttpClient, DotRequestOptions } from '@dotcms/types';
2
- import { StyleEditorFormSchema } from '@dotcms/types/internal';
1
+ import { DotGraphQLApiResponse, DotHttpClient } from '@dotcms/types';
3
2
  /**
4
3
  * Builds a GraphQL query for retrieving page content from DotCMS.
5
4
  *
@@ -28,13 +27,6 @@ export declare function buildQuery(queryData: Record<string, string>): string;
28
27
  * @returns {Record<string, unknown> | undefined} New object containing only the specified keys
29
28
  */
30
29
  export declare function mapContentResponse(responseData: Record<string, unknown> | undefined, keys: string[]): Record<string, unknown> | undefined;
31
- /**
32
- * Loads style editor schemas from GET /api/v1/page/{pageId}/contenttype-schema.
33
- * Requires READ on the page; failures are silently ignored so callers still work without auth.
34
- *
35
- * @internal
36
- */
37
- export declare function fetchStyleEditorSchemas(pageId: string | undefined, config: DotCMSClientConfig, requestOptions: DotRequestOptions, httpClient: DotHttpClient): Promise<StyleEditorFormSchema[]>;
38
30
  /**
39
31
  * Executes a GraphQL query against the DotCMS API.
40
32
  *