@adobe/spacecat-shared-utils 1.37.4 → 1.38.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-utils-v1.38.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.38.0...@adobe/spacecat-shared-utils-v1.38.1) (2025-05-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * local development friendly aws clients and sqs wrapper ([#739](https://github.com/adobe/spacecat-shared/issues/739)) ([fada9c6](https://github.com/adobe/spacecat-shared/commit/fada9c6fc0508ba6acf46a4416593427b67306dd))
7
+
8
+ # [@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)
9
+
10
+
11
+ ### Features
12
+
13
+ * add page authentication token retrieval functionality ([#738](https://github.com/adobe/spacecat-shared/issues/738)) ([f38fe55](https://github.com/adobe/spacecat-shared/commit/f38fe55a02aa4cc3c1c3427d938cf711f3862e01))
14
+
1
15
  # [@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
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.37.4",
3
+ "version": "1.38.1",
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>;
package/src/index.js CHANGED
@@ -73,3 +73,5 @@ export {
73
73
  getHighPageViewsLowFormCtrMetrics,
74
74
  FORMS_AUDIT_INTERVAL,
75
75
  } from './formcalc.js';
76
+
77
+ export { retrievePageAuthentication } from './auth.js';
package/src/sqs.js CHANGED
@@ -15,6 +15,7 @@ import { SendMessageCommand, SQSClient } from '@aws-sdk/client-sqs';
15
15
  import { instrumentAWSClient } from './xray.js';
16
16
 
17
17
  import { hasText, isNonEmptyArray } from './functions.js';
18
+ import { isAWSLambda } from './runtimes.js';
18
19
 
19
20
  function badRequest(message) {
20
21
  return new Response('', {
@@ -103,6 +104,12 @@ export function sqsEventAdapter(fn) {
103
104
  const { log } = context;
104
105
  let message;
105
106
 
107
+ // if not in aws lambda, invoke the function with json body as message
108
+ if (!isAWSLambda()) {
109
+ message = await req.json();
110
+ return fn(message, context);
111
+ }
112
+
106
113
  // currently not processing batch messages
107
114
  const records = context.invocation?.event?.Records;
108
115