@adobe/spacecat-shared-utils 1.37.4 → 1.38.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 +2 -1
- package/src/auth.js +49 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.38.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.37.4...@adobe/spacecat-shared-utils-v1.38.0) (2025-05-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add page authentication token retrieval functionality ([#738](https://github.com/adobe/spacecat-shared/issues/738)) ([f38fe55](https://github.com/adobe/spacecat-shared/commit/f38fe55a02aa4cc3c1c3427d938cf711f3862e01))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-utils-v1.37.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.37.3...@adobe/spacecat-shared-utils-v1.37.4) (2025-05-10)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@adobe/fetch": "4.2.1",
|
|
49
49
|
"@aws-sdk/client-s3": "3.806.0",
|
|
50
|
+
"@aws-sdk/client-secrets-manager": "3.806.0",
|
|
50
51
|
"@aws-sdk/client-sqs": "3.806.0",
|
|
51
52
|
"@json2csv/plainjs": "7.0.6",
|
|
52
53
|
"aws-xray-sdk": "3.10.3",
|
package/src/auth.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import AWSXray from 'aws-xray-sdk';
|
|
14
|
+
import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
|
|
15
|
+
import { isString } from './functions.js';
|
|
16
|
+
import { resolveCustomerSecretsName } from './helpers.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @import {type Site} from "@adobe/spacecat-shared-data-access/src/models/site/index.js"
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves the page authentication token for a given site.
|
|
24
|
+
*
|
|
25
|
+
* @param {Site} site - The site to retrieve authentication for
|
|
26
|
+
* @param {object} context - The context object
|
|
27
|
+
* @returns {Promise<string>} - The authentication token needed to access the page
|
|
28
|
+
* @throws {Error} - If secret is not found or token is missing
|
|
29
|
+
*/
|
|
30
|
+
export async function retrievePageAuthentication(site, context) {
|
|
31
|
+
const baseURL = site.getBaseURL();
|
|
32
|
+
const customerSecret = resolveCustomerSecretsName(baseURL, context);
|
|
33
|
+
const secretsManagerClient = new SecretsManagerClient({});
|
|
34
|
+
const secretsClient = AWSXray.captureAWSv3Client(secretsManagerClient);
|
|
35
|
+
const command = new GetSecretValueCommand({ SecretId: customerSecret });
|
|
36
|
+
|
|
37
|
+
const response = await secretsClient.send(command);
|
|
38
|
+
if (!response.SecretString) {
|
|
39
|
+
throw new Error(`No secret string found for ${customerSecret}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const secrets = JSON.parse(response.SecretString);
|
|
43
|
+
|
|
44
|
+
if (!isString(secrets.PAGE_AUTH_TOKEN)) {
|
|
45
|
+
throw new Error(`Missing 'PAGE_AUTH_TOKEN' in secrets for ${customerSecret}`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return secrets.PAGE_AUTH_TOKEN;
|
|
49
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -245,3 +245,5 @@ export function fetch(url: string | Request, options?: RequestOptions): Promise<
|
|
|
245
245
|
export function tracingFetch(url: string | Request, options?: RequestOptions): Promise<Response>;
|
|
246
246
|
|
|
247
247
|
export const SPACECAT_USER_AGENT: string;
|
|
248
|
+
|
|
249
|
+
export function retrievePageAuthentication(site: object, context: object): Promise<string>;
|