@adobe/spacecat-shared-content-client 1.5.6 → 1.6.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 +7 -0
- package/package.json +1 -1
- package/src/clients/content-client.js +43 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@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)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Add `ContentClient.prototype.getResourcePath` ([#702](https://github.com/adobe/spacecat-shared/issues/702)) ([639036e](https://github.com/adobe/spacecat-shared/commit/639036ef4c165e6faa9dc83320f62e2927ca9619))
|
|
7
|
+
|
|
1
8
|
# [@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
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -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
|
-
* @
|
|
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
|
-
|
|
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(
|
|
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
|
|