@adobe/spacecat-shared-content-client 1.7.9 → 1.7.11

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,17 @@
1
+ # [@adobe/spacecat-shared-content-client-v1.7.11](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.7.10...@adobe/spacecat-shared-content-client-v1.7.11) (2025-06-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update external fixes ([#817](https://github.com/adobe/spacecat-shared/issues/817)) ([522b440](https://github.com/adobe/spacecat-shared/commit/522b440ac1ac1d704b4106ad1f90f192541a8f0c))
7
+
8
+ # [@adobe/spacecat-shared-content-client-v1.7.10](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.7.9...@adobe/spacecat-shared-content-client-v1.7.10) (2025-06-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * properly identify broken internal link ([#813](https://github.com/adobe/spacecat-shared/issues/813)) ([4e19cbd](https://github.com/adobe/spacecat-shared/commit/4e19cbd632e128d78f996f63a436b1b8578b56a3))
14
+
1
15
  # [@adobe/spacecat-shared-content-client-v1.7.9](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.7.8...@adobe/spacecat-shared-content-client-v1.7.9) (2025-06-19)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-content-client",
3
- "version": "1.7.9",
3
+ "version": "1.7.11",
4
4
  "description": "Shared modules of the Spacecat Services - Content Client",
5
5
  "type": "module",
6
6
  "engines": {
@@ -38,7 +38,7 @@
38
38
  "@adobe/spacecat-helix-content-sdk": "1.4.15",
39
39
  "@adobe/spacecat-shared-data-access": "2.0.2",
40
40
  "@adobe/spacecat-shared-utils": "1.38.0",
41
- "@aws-sdk/client-secrets-manager": "3.828.0",
41
+ "@aws-sdk/client-secrets-manager": "3.830.0",
42
42
  "aws-xray-sdk": "3.10.3",
43
43
  "graph-data-structure": "4.5.0"
44
44
  },
@@ -311,11 +311,7 @@ export default class ContentClient {
311
311
  return docPath;
312
312
  }
313
313
 
314
- /**
315
- * @param {string} path
316
- * @returns {Promise<string>}
317
- */
318
- async getResourcePath(path) {
314
+ async #getHelixResourceStatus(path) {
319
315
  const { rso } = this.site.getHlxConfig();
320
316
  // https://www.aem.live/docs/admin.html#tag/status
321
317
  const adminEndpointUrl = `https://admin.hlx.page/status/${rso.owner}/${rso.site}/${rso.ref}/${path.replace(/^\/+/, '')}`;
@@ -325,14 +321,34 @@ export default class ContentClient {
325
321
  },
326
322
  });
327
323
  if (response.ok) {
328
- const responseJson = await response.json();
329
- return responseJson.resourcePath;
324
+ return response.json();
330
325
  } else {
331
326
  const errorMessage = await response.text();
332
327
  throw new Error(`Failed to fetch document path for ${path}: ${errorMessage}`);
333
328
  }
334
329
  }
335
330
 
331
+ /**
332
+ * @param {string} path
333
+ * @returns {Promise<string>}
334
+ */
335
+ async getResourcePath(path) {
336
+ const helixResourceStatus = await this.#getHelixResourceStatus(path);
337
+ return helixResourceStatus?.resourcePath;
338
+ }
339
+
340
+ /**
341
+ * @param {string} path
342
+ * @returns {Promise<{liveURL: string, previewURL: string}>}
343
+ */
344
+ async getLivePreviewURLs(path) {
345
+ const helixResourceStatus = await this.#getHelixResourceStatus(path);
346
+ return {
347
+ liveURL: helixResourceStatus?.live?.url,
348
+ previewURL: helixResourceStatus?.preview?.url,
349
+ };
350
+ }
351
+
336
352
  async getPageMetadata(path) {
337
353
  const startTime = process.hrtime.bigint();
338
354
 
@@ -427,6 +443,22 @@ export default class ContentClient {
427
443
  this.#logDuration('updateRedirects', startTime);
428
444
  }
429
445
 
446
+ async getDocumentLinks(path) {
447
+ const startTime = process.hrtime.bigint();
448
+
449
+ await this.#initClient();
450
+
451
+ this.log.info(`Getting document links for ${this.site.getId()} and path ${path}`);
452
+
453
+ const docPath = this.#resolveDocPath(path);
454
+ const document = await this.rawClient.getDocument(docPath);
455
+ const links = await document.getLinks();
456
+
457
+ this.#logDuration('getDocumentLinks', startTime);
458
+
459
+ return links;
460
+ }
461
+
430
462
  async updateBrokenInternalLink(path, brokenLink) {
431
463
  const startTime = process.hrtime.bigint();
432
464
 
@@ -117,4 +117,83 @@ export class ContentClient {
117
117
  */
118
118
  updateBrokenInternalLink(path: string, brokenLink: { from: string, to: string }):
119
119
  Promise<void>;
120
+
121
+ /**
122
+ * Retrieves the resource path for a given content path from the AEM admin API.
123
+ * The resource path represents the actual file location in the content source
124
+ * (e.g., Google Drive or OneDrive) that corresponds to the given content path.
125
+ *
126
+ * The path should stem from a page's URL and is relative to the site's root.
127
+ * Example: "/path/to/page" (from the full URL: "https://www.example.com/path/to/page").
128
+ *
129
+ * @param {string} path The content path to get the resource path for.
130
+ * Must be a valid path that exists in the content source.
131
+ * @returns {Promise<string | undefined>} A promise that resolves to the resource path
132
+ * string if found, or undefined if not available.
133
+ * @throws {Error} If the Helix admin API request fails or returns an error response.
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const client = await ContentClient.createFrom(context, site);
138
+ * const resourcePath = await client.getResourcePath('/content/page');
139
+ * console.log(resourcePath); // e.g., '/content/page.docx'
140
+ * ```
141
+ */
142
+ getResourcePath(path: string): Promise<string | undefined>;
143
+
144
+ /**
145
+ * Retrieves the live and preview URLs for a given content path from the AEM admin API.
146
+ * The live URL represents the published version of the content, while the preview URL
147
+ * represents the draft/preview version that can be used for testing before publishing.
148
+ *
149
+ * The path should stem from a page's URL and is relative to the site's root.
150
+ * Example: "/path/to/page" (from the full URL: "https://www.example.com/path/to/page").
151
+ *
152
+ * @param {string} path The content path to get URLs for. Must be a valid path
153
+ * that exists in the content source.
154
+ * @returns {Promise<{liveURL: string | undefined, previewURL: string | undefined}>}
155
+ * A promise that resolves to an object containing:
156
+ * - liveURL: The live/published URL if available, undefined otherwise
157
+ * - previewURL: The preview URL if available, undefined otherwise
158
+ * @throws {Error} If the Helix admin API request fails or returns an error response.
159
+ *
160
+ * @example
161
+ * ```typescript
162
+ * const client = await ContentClient.createFrom(context, site);
163
+ * const urls = await client.getLivePreviewURLs('/content/page');
164
+ * console.log(urls.liveURL); // e.g., 'https://owner--repo.hlx.live/content/page'
165
+ * console.log(urls.previewURL); // e.g., 'https://main--repo--owner.hlx.page/content/page'
166
+ * ```
167
+ */
168
+ getLivePreviewURLs(path: string):
169
+ Promise<{ liveURL: string | undefined, previewURL: string | undefined }>;
170
+
171
+ /**
172
+ * Retrieves all links from a document at the specified path.
173
+ * This method extracts links from the document content, including both internal
174
+ * and external links, anchors, email links, and other href attributes.
175
+ *
176
+ * The path should stem from a page's URL and is relative to the site's root.
177
+ * Example: "/path/to/page" (from the full URL: "https://www.example.com/path/to/page").
178
+ *
179
+ * @param {string} path The path to the document to extract links from.
180
+ * Must be a valid path that exists in the content source.
181
+ * @returns {Promise<Array<{url: string | null, text: string | null}>>}
182
+ * A promise that resolves to an array of link objects, where each object contains:
183
+ * - url: The URL or path the link points to (can be null if not available)
184
+ * - text: The display text of the link (can be null if not available)
185
+ * @throws {Error} If there is an issue retrieving the document or extracting links.
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const client = await ContentClient.createFrom(context, site);
190
+ * const links = await client.getDocumentLinks('/content/page');
191
+ * console.log(links);
192
+ * // [
193
+ * // { url: 'https://example.com/external', text: 'External Link' },
194
+ * // { url: '/internal/page', text: 'Internal Page' },
195
+ * // ]
196
+ * ```
197
+ */
198
+ getDocumentLinks(path: string): Promise<Array<{ url: string | null, text: string | null }>>;
120
199
  }