@adobe/spacecat-shared-content-client 1.5.6 → 1.6.1

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.6.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.6.0...@adobe/spacecat-shared-content-client-v1.6.1) (2025-04-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update external fixes ([#708](https://github.com/adobe/spacecat-shared/issues/708)) ([57535ac](https://github.com/adobe/spacecat-shared/commit/57535ac8c636de229cec7c5cee83dead07ac09fb))
7
+
8
+ # [@adobe/spacecat-shared-content-client-v1.6.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.5.6...@adobe/spacecat-shared-content-client-v1.6.0) (2025-04-23)
9
+
10
+
11
+ ### Features
12
+
13
+ * Add `ContentClient.prototype.getResourcePath` ([#702](https://github.com/adobe/spacecat-shared/issues/702)) ([639036e](https://github.com/adobe/spacecat-shared/commit/639036ef4c165e6faa9dc83320f62e2927ca9619))
14
+
1
15
  # [@adobe/spacecat-shared-content-client-v1.5.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.5.5...@adobe/spacecat-shared-content-client-v1.5.6) (2025-04-22)
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.5.6",
3
+ "version": "1.6.1",
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.3.66",
39
39
  "@adobe/spacecat-shared-data-access": "2.0.2",
40
40
  "@adobe/spacecat-shared-utils": "1.26.4",
41
- "@aws-sdk/client-secrets-manager": "3.787.0",
41
+ "@aws-sdk/client-secrets-manager": "3.797.0",
42
42
  "aws-xray-sdk": "3.10.2",
43
43
  "graph-data-structure": "4.5.0"
44
44
  },
@@ -46,7 +46,7 @@
46
46
  "chai": "5.2.0",
47
47
  "chai-as-promised": "8.0.1",
48
48
  "esmock": "2.7.0",
49
- "nock": "14.0.3",
49
+ "nock": "14.0.4",
50
50
  "sinon": "20.0.0",
51
51
  "sinon-chai": "4.0.0",
52
52
  "typescript": "5.8.3"
@@ -20,9 +20,15 @@ import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-sec
20
20
  const CONTENT_SOURCE_TYPE_DRIVE_GOOGLE = 'drive.google';
21
21
  const CONTENT_SOURCE_TYPE_ONEDRIVE = 'onedrive';
22
22
 
23
+ /**
24
+ * @import {type Site} from "@adobe/spacecat-shared-data-access/src/models/site/index.js"
25
+ * @typedef {Pick<Console, 'debug' | 'info' | 'warn' | 'error'>} Logging
26
+ */
27
+
23
28
  /**
24
29
  * A list of supported content source types and their required configuration parameters.
25
- * @type {Map<string, object>}
30
+ * @typedef {typeof CONTENT_SOURCE_TYPE_DRIVE_GOOGLE | typeof CONTENT_SOURCE_TYPE_ONEDRIVE} _CSKey
31
+ * @type {Map<_CSKey, {[key: string]: string}>}
26
32
  */
27
33
  const SUPPORTED_CONTENT_SOURCES = new Map([
28
34
  [CONTENT_SOURCE_TYPE_DRIVE_GOOGLE, {
@@ -186,9 +192,15 @@ const removeRedirectLoops = (currentRedirects, newRedirects, log) => {
186
192
  };
187
193
 
188
194
  export default class ContentClient {
189
- static async createFrom(context, site) {
195
+ /**
196
+ * @param {{log: Logging, env: Record<string, any>}} context
197
+ * @param {Site} site
198
+ * @param {SecretsManagerClient} [secretsManagerClient]
199
+ */
200
+ static async createFrom(context, site, secretsManagerClient = new SecretsManagerClient({})) {
190
201
  const { log = console, env } = context;
191
202
 
203
+ /** @type {{[key: string]: string}} */
192
204
  const config = {};
193
205
  const contentSourceType = site.getHlxConfig()?.content?.source?.type;
194
206
  const envMapping = SUPPORTED_CONTENT_SOURCES.get(contentSourceType);
@@ -201,11 +213,12 @@ export default class ContentClient {
201
213
 
202
214
  try {
203
215
  const customerSecret = resolveCustomerSecretsName(site.getBaseURL(), context);
204
- const client = AWSXray.captureAWSv3Client(new SecretsManagerClient({}));
216
+ const client = AWSXray.captureAWSv3Client(secretsManagerClient);
205
217
  const command = new GetSecretValueCommand({ SecretId: customerSecret });
206
218
  const response = await client.send(command);
207
219
  const secrets = JSON.parse(response.SecretString);
208
220
  config.domainId = secrets.onedrive_domain_id;
221
+ config.helixAdminToken = secrets.helix_admin_token;
209
222
  } catch (e) {
210
223
  log.debug(`Customer ${site.getBaseURL()} secrets containing onedrive domain id not configured: ${e.message}`);
211
224
  }
@@ -241,6 +254,11 @@ export default class ContentClient {
241
254
  }
242
255
  }
243
256
 
257
+ /**
258
+ * @param {{[key: string]: any}} config
259
+ * @param {Site} site
260
+ * @param {Logging} log
261
+ */
244
262
  constructor(config, site, log) {
245
263
  validateSite(site);
246
264
  validateConfiguration(config, site.getHlxConfig()?.content.source?.type);
@@ -274,6 +292,28 @@ export default class ContentClient {
274
292
  return docPath;
275
293
  }
276
294
 
295
+ /**
296
+ * @param {string} path
297
+ * @returns {Promise<string>}
298
+ */
299
+ async getResourcePath(path) {
300
+ const { rso } = this.site.getHlxConfig();
301
+ // https://www.aem.live/docs/admin.html#tag/status
302
+ const adminEndpointUrl = `https://admin.hlx.page/status/${rso.owner}/${rso.site}/${rso.ref}/${path.replace(/^\/+/, '')}`;
303
+ const response = await fetch(adminEndpointUrl, {
304
+ headers: {
305
+ Authorization: `token ${this.config.helixAdminToken}`,
306
+ },
307
+ });
308
+ if (response.ok) {
309
+ const responseJson = await response.json();
310
+ return responseJson.resourcePath;
311
+ } else {
312
+ const errorMessage = await response.text();
313
+ throw new Error(`Failed to fetch document path for ${path}: ${errorMessage}`);
314
+ }
315
+ }
316
+
277
317
  async getPageMetadata(path) {
278
318
  const startTime = process.hrtime.bigint();
279
319