@adobe/spacecat-shared-utils 1.41.1 → 1.41.2

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-utils-v1.41.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.41.1...@adobe/spacecat-shared-utils-v1.41.2) (2025-06-23)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * creating accesstoken from promise token ([#816](https://github.com/adobe/spacecat-shared/issues/816)) ([e5cd3c2](https://github.com/adobe/spacecat-shared/commit/e5cd3c27552ccb48bee4fd4d91c311495f5a29bd))
7
+
1
8
  # [@adobe/spacecat-shared-utils-v1.41.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.41.0...@adobe/spacecat-shared-utils-v1.41.1) (2025-06-21)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.41.1",
3
+ "version": "1.41.2",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,7 +35,6 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@adobe/helix-shared-wrap": "2.0.2",
38
- "@adobe/spacecat-shared-data-access": "2.0.2",
39
38
  "chai": "5.2.0",
40
39
  "chai-as-promised": "8.0.1",
41
40
  "esmock": "2.7.0",
@@ -46,6 +45,8 @@
46
45
  },
47
46
  "dependencies": {
48
47
  "@adobe/fetch": "4.2.2",
48
+ "@adobe/spacecat-shared-data-access": "2.0.2",
49
+ "@adobe/spacecat-shared-ims-client": "1.8.3",
49
50
  "@aws-sdk/client-s3": "3.832.0",
50
51
  "@aws-sdk/client-secrets-manager": "3.830.0",
51
52
  "@aws-sdk/client-sqs": "3.831.0",
package/src/auth.js CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  import AWSXray from 'aws-xray-sdk';
14
14
  import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
15
+ import { Site } from '@adobe/spacecat-shared-data-access';
16
+ import { ImsPromiseClient } from '@adobe/spacecat-shared-ims-client';
15
17
  import { isString } from './functions.js';
16
18
  import { resolveCustomerSecretsName } from './helpers.js';
17
19
 
@@ -19,15 +21,40 @@ import { resolveCustomerSecretsName } from './helpers.js';
19
21
  * @import {type Site} from "@adobe/spacecat-shared-data-access/src/models/site/index.js"
20
22
  */
21
23
 
24
+ /**
25
+ * Get an access token by exchanging a promise token using IMS Promise Client.
26
+ * @param {object} context - The context object containing environment variables.
27
+ * @param {string} promiseToken - The promise token to exchange for an access token.
28
+ * @return {Promise<object>} - A promise that resolves to the access token response.
29
+ */
30
+ export async function getAccessToken(context, promiseToken) {
31
+ const imsClient = ImsPromiseClient.createFrom(
32
+ context,
33
+ ImsPromiseClient.CLIENT_TYPE.CONSUMER,
34
+ );
35
+
36
+ const token = await imsClient.exchangeToken(
37
+ promiseToken,
38
+ !!context.env?.AUTOFIX_CRYPT_SECRET && !!context.env?.AUTOFIX_CRYPT_SALT,
39
+ );
40
+
41
+ return token.access_token;
42
+ }
43
+
22
44
  /**
23
45
  * Retrieves the page authentication token for a given site.
24
46
  *
25
47
  * @param {Site} site - The site to retrieve authentication for
26
48
  * @param {object} context - The context object
27
- * @returns {Promise<string>} - The authentication token needed to access the page
49
+ * @param {object} authOptions - The authentication options
50
+ * @returns {Promise<string>} - The authentication token or access token
28
51
  * @throws {Error} - If secret is not found or token is missing
29
52
  */
30
- export async function retrievePageAuthentication(site, context) {
53
+ export async function retrievePageAuthentication(site, context, authOptions = {}) {
54
+ if (site && site.getDeliveryType() === Site.DELIVERY_TYPES.AEM_CS && authOptions.promiseToken) {
55
+ return getAccessToken(context, authOptions.promiseToken);
56
+ }
57
+
31
58
  const baseURL = site.getBaseURL();
32
59
  const customerSecret = resolveCustomerSecretsName(baseURL, context);
33
60
  const secretsManagerClient = new SecretsManagerClient({});
package/src/index.js CHANGED
@@ -76,4 +76,4 @@ export {
76
76
  FORMS_AUDIT_INTERVAL,
77
77
  } from './formcalc.js';
78
78
 
79
- export { retrievePageAuthentication } from './auth.js';
79
+ export { retrievePageAuthentication, getAccessToken } from './auth.js';