@adobe/spacecat-shared-content-client 1.7.39 → 1.8.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-content-client-v1.8.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.7.39...@adobe/spacecat-shared-content-client-v1.8.0) (2025-11-04)
2
+
3
+
4
+ ### Features
5
+
6
+ * adding getEditURL support for content client ([#1047](https://github.com/adobe/spacecat-shared/issues/1047)) ([ca91f51](https://github.com/adobe/spacecat-shared/commit/ca91f512d3bf074d3fc88a6705f01f4a7661d6bc))
7
+
1
8
  # [@adobe/spacecat-shared-content-client-v1.7.39](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.7.38...@adobe/spacecat-shared-content-client-v1.7.39) (2025-11-04)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-content-client",
3
- "version": "1.7.39",
3
+ "version": "1.8.0",
4
4
  "description": "Shared modules of the Spacecat Services - Content Client",
5
5
  "type": "module",
6
6
  "engines": {
@@ -311,10 +311,12 @@ export default class ContentClient {
311
311
  return docPath;
312
312
  }
313
313
 
314
- async #getHelixResourceStatus(path) {
314
+ async #getHelixResourceStatus(path, includeEditUrl = false) {
315
315
  const { rso } = this.site.getHlxConfig();
316
- // https://www.aem.live/docs/admin.html#tag/status
317
- const adminEndpointUrl = `https://admin.hlx.page/status/${rso.owner}/${rso.site}/${rso.ref}/${path.replace(/^\/+/, '')}`;
316
+ // https://www.aem.live/docs/admin.html#tag/status,
317
+ let adminEndpointUrl = `https://admin.hlx.page/status/${rso.owner}/${rso.site}/${rso.ref}/${path.replace(/^\/+/, '')}`;
318
+ // ?editUrl=auto for URL of the edit (authoring) document
319
+ adminEndpointUrl = includeEditUrl ? `${adminEndpointUrl}?editUrl=auto` : adminEndpointUrl;
318
320
  const response = await fetch(adminEndpointUrl, {
319
321
  headers: {
320
322
  Authorization: `token ${this.config.helixAdminToken}`,
@@ -349,6 +351,15 @@ export default class ContentClient {
349
351
  };
350
352
  }
351
353
 
354
+ /**
355
+ * @param {string} path
356
+ * @returns {Promise<string>}
357
+ */
358
+ async getEditURL(path) {
359
+ const helixResourceStatus = await this.#getHelixResourceStatus(path, true);
360
+ return helixResourceStatus?.edit?.url;
361
+ }
362
+
352
363
  async getPageMetadata(path) {
353
364
  const startTime = process.hrtime.bigint();
354
365
 
@@ -391,7 +402,7 @@ export default class ContentClient {
391
402
 
392
403
  const response = await document.updateMetadata(mergedMetadata);
393
404
  if (response?.status !== 200) {
394
- throw new Error(`Failed to update metadata for path ${path}`);
405
+ throw new Error(`Failed to update metadata for path ${path}: ${response.statusText}`);
395
406
  }
396
407
 
397
408
  this.#logDuration('updatePageMetadata', startTime);
@@ -168,6 +168,28 @@ export class ContentClient {
168
168
  getLivePreviewURLs(path: string):
169
169
  Promise<{ liveURL: string | undefined, previewURL: string | undefined }>;
170
170
 
171
+ /**
172
+ * Retrieves the edit URL for a given content path from the AEM admin API.
173
+ * The edit URL represents the URL of the document source for the given content path
174
+ *
175
+ * The path should stem from a page's URL and is relative to the site's root.
176
+ * Example: "/path/to/page" (from the full URL: "https://www.example.com/path/to/page").
177
+ *
178
+ * @param {string} path The content path to get the edit URL for.
179
+ *
180
+ * @returns {Promise<string | undefined>} A promise that resolves to the edit URL
181
+ * string if found, or undefined if not available.
182
+ * @throws {Error} If the Helix admin API request fails or returns an error response.
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const client = await ContentClient.createFrom(context, site);
187
+ * const editURL = await client.getEditURL('/content/page');
188
+ * console.log(editURL); // e.g., 'https://adobe.sharepoint.com/sites/Projects/_layouts/15/Doc.aspx?sourcedoc=%7xxxxxx-xxxx-xxxx-xxxx-xxxxxx%7D&file=page.docx&action=default'
189
+ *
190
+ */
191
+ getEditURL(path: string): Promise<string | undefined>;
192
+
171
193
  /**
172
194
  * Retrieves all links from a document at the specified path.
173
195
  * This method extracts links from the document content, including both internal