@dotcms/client 1.5.5-next.2260 → 1.5.5-next.2261

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
@@ -2310,6 +2310,19 @@ function mapContentResponse(responseData, keys) {
2310
2310
  return accumulator;
2311
2311
  }, {});
2312
2312
  }
2313
+ /**
2314
+ * Returns a shallow copy of the object with every key whose value is `undefined` removed.
2315
+ *
2316
+ * `undefined` is not valid JSON, so keeping such keys breaks consumers that serialize the value
2317
+ * (e.g. Next.js Pages Router `getServerSideProps`/`getStaticProps`). `null` and other falsy values
2318
+ * are preserved since they serialize fine.
2319
+ *
2320
+ * @param {Record<string, unknown>} object - Source object to clean
2321
+ * @returns {Record<string, unknown>} New object without `undefined` values
2322
+ */
2323
+ function removeUndefinedValues(object) {
2324
+ return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== undefined));
2325
+ }
2313
2326
  /**
2314
2327
  * Executes a GraphQL query against the DotCMS API.
2315
2328
  *
@@ -2429,12 +2442,10 @@ class PageClient extends BaseApiClient {
2429
2442
  additionalQueries: contentQuery,
2430
2443
  verbose
2431
2444
  });
2432
- const normalizedUrl = url.startsWith('/') ? url : `/${url}`;
2433
- const requestVariables = {
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
2435
- url: normalizedUrl,
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],
2445
+ const newURL = url.startsWith('/') ? url : `/${url}`;
2446
+ const requestVariables = removeUndefinedValues({
2447
+ url: newURL,
2448
+ mode: types.UVE_MODE[mode], // Translate the UVE_MODE key ('EDIT' | 'PREVIEW' | ...) to the value the backend PageMode enum expects ('EDIT_MODE' | 'PREVIEW_MODE' | ...)
2438
2449
  languageId,
2439
2450
  personaId,
2440
2451
  fireRules,
@@ -2442,7 +2453,7 @@ class PageClient extends BaseApiClient {
2442
2453
  siteId,
2443
2454
  variantName,
2444
2455
  ...variables
2445
- };
2456
+ });
2446
2457
  const requestHeaders = this.requestOptions.headers;
2447
2458
  const requestBody = JSON.stringify({ query: completeQuery, variables: requestVariables });
2448
2459
  try {
@@ -2458,12 +2469,12 @@ class PageClient extends BaseApiClient {
2458
2469
  .filter((error) => !error.extensions?.code)
2459
2470
  .forEach((error) => {
2460
2471
  if (verbose) {
2461
- logVerboseError(normalizedUrl, error.message, {
2472
+ logVerboseError(newURL, error.message, {
2462
2473
  variables: requestVariables
2463
2474
  });
2464
2475
  }
2465
2476
  else {
2466
- consola.consola.error(`[DotCMS GraphQL Error] ${normalizedUrl}: `, error.message);
2477
+ consola.consola.error(`[DotCMS GraphQL Error] ${newURL}: `, error.message);
2467
2478
  }
2468
2479
  });
2469
2480
  }
@@ -2489,19 +2500,19 @@ class PageClient extends BaseApiClient {
2489
2500
  const status = structuredError.extensions?.status ??
2490
2501
  (code === 'NOT_FOUND' ? 404 : code === 'PERMISSION_DENIED' ? 403 : 400);
2491
2502
  const message = code === 'NOT_FOUND'
2492
- ? `Page '${normalizedUrl}' was not found`
2503
+ ? `Page '${newURL}' was not found`
2493
2504
  : code === 'PERMISSION_DENIED'
2494
- ? `Permission denied: you do not have access to page '${normalizedUrl}'. Verify the page permissions in dotCMS and that the auth token has sufficient access.`
2495
- : `Page '${normalizedUrl}' could not be loaded (${code})`;
2505
+ ? `Permission denied: you do not have access to page '${newURL}'. Verify the page permissions in dotCMS and that the auth token has sufficient access.`
2506
+ : `Page '${newURL}' could not be loaded (${code})`;
2496
2507
  if (verbose) {
2497
- logVerboseError(normalizedUrl, message, {
2508
+ logVerboseError(newURL, message, {
2498
2509
  status,
2499
2510
  code,
2500
2511
  variables: requestVariables
2501
2512
  });
2502
2513
  }
2503
2514
  else {
2504
- consola.consola.error(`[DotCMS GraphQL Error] ${normalizedUrl}: `, message);
2515
+ consola.consola.error(`[DotCMS GraphQL Error] ${newURL}: `, message);
2505
2516
  }
2506
2517
  throw new types.DotErrorPage(message, status, code, undefined, {
2507
2518
  query: completeQuery,
@@ -2515,10 +2526,10 @@ class PageClient extends BaseApiClient {
2515
2526
  : null;
2516
2527
  const styleEditorSchemas = pageResponse ? pageResponse.page.styleEditorSchemas : [];
2517
2528
  if (!pageResponse) {
2518
- throw new types.DotErrorPage(`Page '${normalizedUrl}' was not found`, 404, 'NOT_FOUND', new types.DotHttpError({
2529
+ throw new types.DotErrorPage(`Page '${newURL}' was not found`, 404, 'NOT_FOUND', new types.DotHttpError({
2519
2530
  status: 404,
2520
2531
  statusText: 'Not Found',
2521
- message: `Page '${normalizedUrl}' was not found`,
2532
+ message: `Page '${newURL}' was not found`,
2522
2533
  data: response.errors
2523
2534
  }), { query: completeQuery, variables: requestVariables });
2524
2535
  }
@@ -2540,9 +2551,9 @@ class PageClient extends BaseApiClient {
2540
2551
  throw error;
2541
2552
  }
2542
2553
  if (error instanceof types.DotHttpError) {
2543
- throw new types.DotErrorPage(`Page request failed for URL '${normalizedUrl}': ${error.message}`, error.status, 'UNKNOWN', error, { query: completeQuery, variables: requestVariables });
2554
+ throw new types.DotErrorPage(`Page request failed for URL '${newURL}': ${error.message}`, error.status, 'UNKNOWN', error, { query: completeQuery, variables: requestVariables });
2544
2555
  }
2545
- throw new types.DotErrorPage(`Page request failed for URL '${normalizedUrl}': ${error instanceof Error ? error.message : 'Unknown error'}`, 500, 'UNKNOWN', undefined, { query: completeQuery, variables: requestVariables });
2556
+ throw new types.DotErrorPage(`Page request failed for URL '${newURL}': ${error instanceof Error ? error.message : 'Unknown error'}`, 500, 'UNKNOWN', undefined, { query: completeQuery, variables: requestVariables });
2546
2557
  }
2547
2558
  }
2548
2559
  }
package/index.esm.js CHANGED
@@ -2308,6 +2308,19 @@ function mapContentResponse(responseData, keys) {
2308
2308
  return accumulator;
2309
2309
  }, {});
2310
2310
  }
2311
+ /**
2312
+ * Returns a shallow copy of the object with every key whose value is `undefined` removed.
2313
+ *
2314
+ * `undefined` is not valid JSON, so keeping such keys breaks consumers that serialize the value
2315
+ * (e.g. Next.js Pages Router `getServerSideProps`/`getStaticProps`). `null` and other falsy values
2316
+ * are preserved since they serialize fine.
2317
+ *
2318
+ * @param {Record<string, unknown>} object - Source object to clean
2319
+ * @returns {Record<string, unknown>} New object without `undefined` values
2320
+ */
2321
+ function removeUndefinedValues(object) {
2322
+ return Object.fromEntries(Object.entries(object).filter(([, value]) => value !== undefined));
2323
+ }
2311
2324
  /**
2312
2325
  * Executes a GraphQL query against the DotCMS API.
2313
2326
  *
@@ -2427,12 +2440,10 @@ class PageClient extends BaseApiClient {
2427
2440
  additionalQueries: contentQuery,
2428
2441
  verbose
2429
2442
  });
2430
- const normalizedUrl = url.startsWith('/') ? url : `/${url}`;
2431
- const requestVariables = {
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
2433
- url: normalizedUrl,
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],
2443
+ const newURL = url.startsWith('/') ? url : `/${url}`;
2444
+ const requestVariables = removeUndefinedValues({
2445
+ url: newURL,
2446
+ mode: UVE_MODE[mode], // Translate the UVE_MODE key ('EDIT' | 'PREVIEW' | ...) to the value the backend PageMode enum expects ('EDIT_MODE' | 'PREVIEW_MODE' | ...)
2436
2447
  languageId,
2437
2448
  personaId,
2438
2449
  fireRules,
@@ -2440,7 +2451,7 @@ class PageClient extends BaseApiClient {
2440
2451
  siteId,
2441
2452
  variantName,
2442
2453
  ...variables
2443
- };
2454
+ });
2444
2455
  const requestHeaders = this.requestOptions.headers;
2445
2456
  const requestBody = JSON.stringify({ query: completeQuery, variables: requestVariables });
2446
2457
  try {
@@ -2456,12 +2467,12 @@ class PageClient extends BaseApiClient {
2456
2467
  .filter((error) => !error.extensions?.code)
2457
2468
  .forEach((error) => {
2458
2469
  if (verbose) {
2459
- logVerboseError(normalizedUrl, error.message, {
2470
+ logVerboseError(newURL, error.message, {
2460
2471
  variables: requestVariables
2461
2472
  });
2462
2473
  }
2463
2474
  else {
2464
- consola.error(`[DotCMS GraphQL Error] ${normalizedUrl}: `, error.message);
2475
+ consola.error(`[DotCMS GraphQL Error] ${newURL}: `, error.message);
2465
2476
  }
2466
2477
  });
2467
2478
  }
@@ -2487,19 +2498,19 @@ class PageClient extends BaseApiClient {
2487
2498
  const status = structuredError.extensions?.status ??
2488
2499
  (code === 'NOT_FOUND' ? 404 : code === 'PERMISSION_DENIED' ? 403 : 400);
2489
2500
  const message = code === 'NOT_FOUND'
2490
- ? `Page '${normalizedUrl}' was not found`
2501
+ ? `Page '${newURL}' was not found`
2491
2502
  : code === 'PERMISSION_DENIED'
2492
- ? `Permission denied: you do not have access to page '${normalizedUrl}'. Verify the page permissions in dotCMS and that the auth token has sufficient access.`
2493
- : `Page '${normalizedUrl}' could not be loaded (${code})`;
2503
+ ? `Permission denied: you do not have access to page '${newURL}'. Verify the page permissions in dotCMS and that the auth token has sufficient access.`
2504
+ : `Page '${newURL}' could not be loaded (${code})`;
2494
2505
  if (verbose) {
2495
- logVerboseError(normalizedUrl, message, {
2506
+ logVerboseError(newURL, message, {
2496
2507
  status,
2497
2508
  code,
2498
2509
  variables: requestVariables
2499
2510
  });
2500
2511
  }
2501
2512
  else {
2502
- consola.error(`[DotCMS GraphQL Error] ${normalizedUrl}: `, message);
2513
+ consola.error(`[DotCMS GraphQL Error] ${newURL}: `, message);
2503
2514
  }
2504
2515
  throw new DotErrorPage(message, status, code, undefined, {
2505
2516
  query: completeQuery,
@@ -2513,10 +2524,10 @@ class PageClient extends BaseApiClient {
2513
2524
  : null;
2514
2525
  const styleEditorSchemas = pageResponse ? pageResponse.page.styleEditorSchemas : [];
2515
2526
  if (!pageResponse) {
2516
- throw new DotErrorPage(`Page '${normalizedUrl}' was not found`, 404, 'NOT_FOUND', new DotHttpError({
2527
+ throw new DotErrorPage(`Page '${newURL}' was not found`, 404, 'NOT_FOUND', new DotHttpError({
2517
2528
  status: 404,
2518
2529
  statusText: 'Not Found',
2519
- message: `Page '${normalizedUrl}' was not found`,
2530
+ message: `Page '${newURL}' was not found`,
2520
2531
  data: response.errors
2521
2532
  }), { query: completeQuery, variables: requestVariables });
2522
2533
  }
@@ -2538,9 +2549,9 @@ class PageClient extends BaseApiClient {
2538
2549
  throw error;
2539
2550
  }
2540
2551
  if (error instanceof DotHttpError) {
2541
- throw new DotErrorPage(`Page request failed for URL '${normalizedUrl}': ${error.message}`, error.status, 'UNKNOWN', error, { query: completeQuery, variables: requestVariables });
2552
+ throw new DotErrorPage(`Page request failed for URL '${newURL}': ${error.message}`, error.status, 'UNKNOWN', error, { query: completeQuery, variables: requestVariables });
2542
2553
  }
2543
- throw new DotErrorPage(`Page request failed for URL '${normalizedUrl}': ${error instanceof Error ? error.message : 'Unknown error'}`, 500, 'UNKNOWN', undefined, { query: completeQuery, variables: requestVariables });
2554
+ throw new DotErrorPage(`Page request failed for URL '${newURL}': ${error instanceof Error ? error.message : 'Unknown error'}`, 500, 'UNKNOWN', undefined, { query: completeQuery, variables: requestVariables });
2544
2555
  }
2545
2556
  }
2546
2557
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotcms/client",
3
- "version": "1.5.5-next.2260",
3
+ "version": "1.5.5-next.2261",
4
4
  "description": "Official JavaScript library for interacting with DotCMS REST APIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,6 +27,17 @@ export declare function buildQuery(queryData: Record<string, string>): string;
27
27
  * @returns {Record<string, unknown> | undefined} New object containing only the specified keys
28
28
  */
29
29
  export declare function mapContentResponse(responseData: Record<string, unknown> | undefined, keys: string[]): Record<string, unknown> | undefined;
30
+ /**
31
+ * Returns a shallow copy of the object with every key whose value is `undefined` removed.
32
+ *
33
+ * `undefined` is not valid JSON, so keeping such keys breaks consumers that serialize the value
34
+ * (e.g. Next.js Pages Router `getServerSideProps`/`getStaticProps`). `null` and other falsy values
35
+ * are preserved since they serialize fine.
36
+ *
37
+ * @param {Record<string, unknown>} object - Source object to clean
38
+ * @returns {Record<string, unknown>} New object without `undefined` values
39
+ */
40
+ export declare function removeUndefinedValues(object: Record<string, unknown>): Record<string, unknown>;
30
41
  /**
31
42
  * Executes a GraphQL query against the DotCMS API.
32
43
  *