@adobe/spacecat-shared-utils 1.1.0 → 1.3.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.3.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.2.0...@adobe/spacecat-shared-utils-v1.3.0) (2023-12-10)
2
+
3
+
4
+ ### Features
5
+
6
+ * resolve secrets name ([#44](https://github.com/adobe-rnd/spacecat-shared/issues/44)) ([8c7604d](https://github.com/adobe-rnd/spacecat-shared/commit/8c7604da6b36f450a9054fa93c6c469c1f47319b))
7
+
8
+ # [@adobe/spacecat-shared-utils-v1.2.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.1.0...@adobe/spacecat-shared-utils-v1.2.0) (2023-11-30)
9
+
10
+
11
+ ### Features
12
+
13
+ * add isArray function ([eeb45a6](https://github.com/adobe-rnd/spacecat-shared/commit/eeb45a6784c6406403d0a59b65ba873a107c654c))
14
+
1
15
  # [@adobe/spacecat-shared-utils-v1.1.0](https://github.com/adobe-rnd/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.0.1...@adobe/spacecat-shared-utils-v1.1.0) (2023-11-29)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.1.0",
3
+ "version": "1.3.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/functions.js CHANGED
@@ -14,6 +14,16 @@
14
14
  const REGEX_ISO_DATE = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/;
15
15
  const REGEX_TIME_OFFSET_DATE = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}(Z|[+-]\d{2}:\d{2})/;
16
16
 
17
+ /**
18
+ * Determines if the given parameter is an array.
19
+ *
20
+ * @param {*} value - The value to check.
21
+ * @returns {boolean} True if the parameter is an array, false otherwise.
22
+ */
23
+ function isArray(value) {
24
+ return Array.isArray(value);
25
+ }
26
+
17
27
  /**
18
28
  * Determines case-insensitively if the given value is a boolean or a string
19
29
  * representation of a boolean.
@@ -53,7 +63,7 @@ function isNumber(value) {
53
63
  * @returns {boolean} True if the parameter is an object, false otherwise.
54
64
  */
55
65
  function isObject(value) {
56
- return !Array.isArray(value) && value !== null && typeof value === 'object';
66
+ return !isArray(value) && value !== null && typeof value === 'object';
57
67
  }
58
68
 
59
69
  /**
@@ -150,14 +160,15 @@ function toBoolean(value) {
150
160
  * @param {Array} b - The second array to compare.
151
161
  * @returns {boolean} True if the arrays are equal, false otherwise.
152
162
  */
153
- const arrayEquals = (a, b) => Array.isArray(a)
154
- && Array.isArray(b)
163
+ const arrayEquals = (a, b) => isArray(a)
164
+ && isArray(b)
155
165
  && a.length === b.length
156
166
  && a.every((val, index) => val === b[index]);
157
167
 
158
168
  export {
159
169
  arrayEquals,
160
170
  hasText,
171
+ isArray,
161
172
  isBoolean,
162
173
  isInteger,
163
174
  isValidDate,
package/src/helpers.js ADDED
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2023 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 { isString } from './functions.js';
14
+
15
+ /**
16
+ * Resolves the name of the secret based on the function version.
17
+ * @param {Object} opts - The options object, not used in this implementation.
18
+ * @param {Object} ctx - The context object containing the function version.
19
+ * @param {string} defaultPath - The default path for the secret.
20
+ * @returns {string} - The resolved secret name.
21
+ */
22
+ const resolveSecretsName = (opts, ctx, defaultPath) => {
23
+ const funcVersion = ctx?.func?.version;
24
+
25
+ if (!isString(funcVersion)) {
26
+ throw new Error('Invalid context: func.version is required and must be a string');
27
+ }
28
+ if (!isString(defaultPath)) {
29
+ throw new Error('Invalid defaultPath: must be a string');
30
+ }
31
+
32
+ return `${defaultPath}/${funcVersion}`;
33
+ };
34
+
35
+ export {
36
+ resolveSecretsName,
37
+ };
package/src/index.js CHANGED
@@ -13,6 +13,7 @@
13
13
  export {
14
14
  arrayEquals,
15
15
  hasText,
16
+ isArray,
16
17
  isBoolean,
17
18
  isInteger,
18
19
  isValidDate,
@@ -24,3 +25,5 @@ export {
24
25
  toBoolean,
25
26
  isValidUrl,
26
27
  } from './functions.js';
28
+
29
+ export { resolveSecretsName } from './helpers.js';