@adobe/spacecat-shared-utils 1.13.2 → 1.14.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,22 @@
1
+ # [@adobe/spacecat-shared-utils-v1.14.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.14.0...@adobe/spacecat-shared-utils-v1.14.1) (2024-03-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * jsdoc for generateCSVFile and release ([#187](https://github.com/adobe/spacecat-shared/issues/187)) ([e8e30ed](https://github.com/adobe/spacecat-shared/commit/e8e30eddb0609370898e022d1f986cbc5db83e36))
7
+
8
+ # [@adobe/spacecat-shared-utils-v1.14.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.13.2...@adobe/spacecat-shared-utils-v1.14.0) (2024-03-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update external fixes ([#183](https://github.com/adobe/spacecat-shared/issues/183)) ([0c292e5](https://github.com/adobe/spacecat-shared/commit/0c292e5cff5647e1947f4095ff8f28b3a0155ed6))
14
+
15
+
16
+ ### Features
17
+
18
+ * add json to csv helper function ([#185](https://github.com/adobe/spacecat-shared/issues/185)) ([ebeab43](https://github.com/adobe/spacecat-shared/commit/ebeab436d1964af4daa3d048e3821c30c732b714))
19
+
1
20
  # [@adobe/spacecat-shared-utils-v1.13.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.13.1...@adobe/spacecat-shared-utils-v1.13.2) (2024-03-09)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.13.2",
3
+ "version": "1.14.1",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -40,8 +40,9 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@adobe/fetch": "4.1.1",
43
- "@aws-sdk/client-s3": "3.529.1",
44
- "@aws-sdk/client-sqs": "3.529.1"
43
+ "@aws-sdk/client-s3": "3.535.0",
44
+ "@aws-sdk/client-sqs": "3.535.0",
45
+ "@json2csv/plainjs": "7.0.6"
45
46
  },
46
47
  "peerDependencies": {
47
48
  "@adobe/spacecat-shared-data-access": "1.x"
package/src/helpers.js CHANGED
@@ -10,6 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
+ import { Parser } from '@json2csv/plainjs';
13
14
  import { hasText, isString } from './functions.js';
14
15
 
15
16
  /**
@@ -55,3 +56,18 @@ export function isAuditsDisabled(site, organization, auditType) {
55
56
 
56
57
  return false;
57
58
  }
59
+
60
+ /**
61
+ * Generates a CSV file from the provided JSON data.
62
+ *
63
+ * Each key-value pair in the JSON objects
64
+ * corresponds to a column and its value in the CSV. The output is a UTF-8
65
+ * encoded Buffer that represents the CSV file content.
66
+ *
67
+ * @param {Object[]} data - An array of JSON objects to be converted into CSV format.
68
+ * @returns {Buffer} A Buffer containing the CSV formatted data, encoded in UTF-8.
69
+ */
70
+ export function generateCSVFile(data) {
71
+ const json2csvParser = new Parser();
72
+ return Buffer.from(json2csvParser.parse(data), 'utf-8');
73
+ }
package/src/index.d.ts CHANGED
@@ -108,3 +108,15 @@ declare function composeAuditURL(url: string): Promise<string>;
108
108
  * @returns {boolean} - True if the audit(s) are disabled, otherwise false.
109
109
  */
110
110
  declare function isAuditsDisabled(site: object, organization: object, auditType?: string): boolean
111
+
112
+ /**
113
+ * Generates a CSV file from the provided JSON data.
114
+ *
115
+ * Each key-value pair in the JSON objects
116
+ * corresponds to a column and its value in the CSV. The output is a UTF-8
117
+ * encoded Buffer that represents the CSV file content.
118
+ *
119
+ * @param {Object[]} data - An array of JSON objects to be converted into CSV format.
120
+ * @returns {Buffer} A Buffer containing the CSV formatted data, encoded in UTF-8.
121
+ */
122
+ declare function generateCSVFile(data: object[]): Buffer;
package/src/index.js CHANGED
@@ -30,6 +30,7 @@ export {
30
30
  export {
31
31
  isAuditsDisabled,
32
32
  resolveSecretsName,
33
+ generateCSVFile,
33
34
  } from './helpers.js';
34
35
 
35
36
  export { sqsWrapper } from './sqs.js';