@adobe/spacecat-shared-utils 1.30.4 → 1.31.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 +14 -0
- package/package.json +4 -4
- package/src/helpers.js +33 -2
- package/src/index.d.ts +15 -2
- package/src/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-utils-v1.31.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.31.0...@adobe/spacecat-shared-utils-v1.31.1) (2025-02-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update external fixes ([#603](https://github.com/adobe/spacecat-shared/issues/603)) ([b58d4c7](https://github.com/adobe/spacecat-shared/commit/b58d4c7237fb2522bba9b722e9eed7b0ae9e5f70))
|
|
7
|
+
|
|
8
|
+
# [@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)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* 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)
|
|
14
|
+
|
|
1
15
|
# [@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)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.1",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - utils",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@adobe/helix-shared-wrap": "2.0.2",
|
|
38
38
|
"@adobe/spacecat-shared-data-access": "2.0.2",
|
|
39
|
-
"chai": "5.
|
|
39
|
+
"chai": "5.2.0",
|
|
40
40
|
"chai-as-promised": "8.0.1",
|
|
41
41
|
"husky": "9.1.7",
|
|
42
42
|
"nock": "14.0.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@adobe/fetch": "4.1.11",
|
|
48
|
-
"@aws-sdk/client-s3": "3.
|
|
49
|
-
"@aws-sdk/client-sqs": "3.
|
|
48
|
+
"@aws-sdk/client-s3": "3.749.0",
|
|
49
|
+
"@aws-sdk/client-sqs": "3.749.0",
|
|
50
50
|
"@json2csv/plainjs": "7.0.6",
|
|
51
51
|
"aws-xray-sdk": "3.10.3",
|
|
52
52
|
"uuid": "11.0.5"
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
+
object[];
|
|
193
206
|
|
|
194
207
|
/**
|
|
195
208
|
* Retrieves stored metrics from S3.
|