@adobe/spacecat-shared-utils 1.30.3 → 1.31.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-utils-v1.31.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.30.4...@adobe/spacecat-shared-utils-v1.31.0) (2025-02-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * util for reading .query static files, modeled after getPrompt ([#591](https://github.com/adobe/spacecat-shared/issues/591)) ([af3700d](https://github.com/adobe/spacecat-shared/commit/af3700d4a3d1953a312138f0ca46547eaa31eaac)), closes [#579](https://github.com/adobe/spacecat-shared/issues/579) [#579](https://github.com/adobe/spacecat-shared/issues/579)
7
+
8
+ # [@adobe/spacecat-shared-utils-v1.30.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.30.3...@adobe/spacecat-shared-utils-v1.30.4) (2025-02-12)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * log level adjustments ([#597](https://github.com/adobe/spacecat-shared/issues/597)) ([22cc302](https://github.com/adobe/spacecat-shared/commit/22cc302bd1d9d52f6f172748ef8be66dceff599b))
14
+
1
15
  # [@adobe/spacecat-shared-utils-v1.30.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.30.2...@adobe/spacecat-shared-utils-v1.30.3) (2025-02-11)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.30.3",
3
+ "version": "1.31.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "engines": {
package/src/helpers.js CHANGED
@@ -87,6 +87,19 @@ export function replacePlaceholders(content, placeholders) {
87
87
  });
88
88
  }
89
89
 
90
+ /**
91
+ * Internal function to support reading static file
92
+ * and replace placeholder strings with values.
93
+ *
94
+ * @param {Object} placeholders - A JSON object containing values to replace in the prompt content.
95
+ * @param {String} filename - The path of the prompt file.
96
+ * @returns {Promise<string|null>} - A promise that resolves to a string with the prompt content.
97
+ */
98
+ async function getStaticContent(placeholders, filename) {
99
+ const fileContent = await fs.readFile(filename, { encoding: 'utf8' });
100
+ return replacePlaceholders(fileContent, placeholders);
101
+ }
102
+
90
103
  /**
91
104
  * Reads the content of a prompt file asynchronously and replaces any placeholders
92
105
  * with the corresponding values. Logs the error and returns null in case of an error.
@@ -99,10 +112,28 @@ export function replacePlaceholders(content, placeholders) {
99
112
  */
100
113
  export async function getPrompt(placeholders, filename, log = console) {
101
114
  try {
102
- const promptContent = await fs.readFile(`./static/prompts/${filename}.prompt`, { encoding: 'utf8' });
103
- return replacePlaceholders(promptContent, placeholders);
115
+ return await getStaticContent(placeholders, `./static/prompts/${filename}.prompt`);
104
116
  } catch (error) {
105
117
  log.error('Error reading prompt file:', error.message);
106
118
  return null;
107
119
  }
108
120
  }
121
+
122
+ /**
123
+ * Reads the content of a query file asynchronously and replaces any placeholders
124
+ * with the corresponding values. Logs the error and returns null in case of an error.
125
+ *
126
+ * @param {Object} placeholders - A JSON object containing values to replace in the query content.
127
+ * @param {String} filename - The filename of the query file.
128
+ * @param {Object} log - The logger
129
+ * @returns {Promise<string|null>} - A promise that resolves to a string with the query content,
130
+ * or null if an error occurs.
131
+ */
132
+ export async function getQuery(placeholders, filename, log = console) {
133
+ try {
134
+ return await getStaticContent(placeholders, `./static/queries/${filename}.query`);
135
+ } catch (error) {
136
+ log.error('Error reading query file:', error.message);
137
+ return null;
138
+ }
139
+ }
package/src/index.d.ts CHANGED
@@ -166,6 +166,19 @@ declare function replacePlaceholders(content: string, placeholders: object): str
166
166
  declare function getPrompt(placeholders: object, filename: string, log: object):
167
167
  Promise<string | null>;
168
168
 
169
+ /**
170
+ * Reads the content of a query file asynchronously and replaces any placeholders
171
+ * with the corresponding values. Logs the error and returns null in case of an error.
172
+ *
173
+ * @param {Object} placeholders - A JSON object containing values to replace in the query content.
174
+ * @param {String} filename - The filename of the query file.
175
+ * @param {Object} log - The logger
176
+ * @returns {Promise<string|null>} - A promise that resolves to a string with the query content,
177
+ * or null if an error occurs.
178
+ */
179
+ declare function getQuery(placeholders: object, filename: string, log: object):
180
+ Promise<string | null>;
181
+
169
182
  /**
170
183
  * Retrieves the high-form-view-low-form-conversion metrics from the provided array of form vitals.
171
184
  * @param {Object[]} formVitals - An array of form vitals.
@@ -181,7 +194,7 @@ declare function getHighFormViewsLowConversionMetrics(formVitals: object[], inte
181
194
  * @returns {Object[]} - An array of high-page-view-low-form-view metrics.
182
195
  */
183
196
  declare function getHighPageViewsLowFormViewsMetrics(formVitals: object[], interval: number):
184
- object[];
197
+ object[];
185
198
 
186
199
  /**
187
200
  * Retrieves the high-page-view-low-form-ctr metrics from the provided array of form vitals.
@@ -189,7 +202,7 @@ declare function getHighPageViewsLowFormViewsMetrics(formVitals: object[], inter
189
202
  * @returns {Object[]} - An array of high-page-view-low-form-ctr metrics.
190
203
  */
191
204
  declare function getHighPageViewsLowFormCtrMetrics(formVitals: object[], interval: number):
192
- object[];
205
+ object[];
193
206
 
194
207
  /**
195
208
  * Retrieves stored metrics from S3.
package/src/index.js CHANGED
@@ -37,6 +37,7 @@ export {
37
37
  generateCSVFile,
38
38
  replacePlaceholders,
39
39
  getPrompt,
40
+ getQuery,
40
41
  } from './helpers.js';
41
42
 
42
43
  export { sqsWrapper } from './sqs.js';
package/src/sqs.js CHANGED
@@ -117,7 +117,7 @@ export function sqsEventAdapter(fn) {
117
117
 
118
118
  try {
119
119
  message = JSON.parse(record.body);
120
- log.info(`Received message with id: ${record.messageId}`);
120
+ log.debug(`Received message with id: ${record.messageId}`);
121
121
  } catch (e) {
122
122
  log.warn('Function was not invoked properly, message body is not a valid JSON', e);
123
123
  return badRequest('Event does not contain a valid message body');