@adobe/spacecat-shared-utils 1.12.3 → 1.13.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,10 @@
1
+ # [@adobe/spacecat-shared-utils-v1.13.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.12.3...@adobe/spacecat-shared-utils-v1.13.0) (2024-02-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * helper to detect audits are disabled ([#173](https://github.com/adobe/spacecat-shared/issues/173)) ([e698a76](https://github.com/adobe/spacecat-shared/commit/e698a76899399a7155175527b47c0fe5528b123a))
7
+
1
8
  # [@adobe/spacecat-shared-utils-v1.12.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-utils-v1.12.2...@adobe/spacecat-shared-utils-v1.12.3) (2024-02-28)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-utils",
3
- "version": "1.12.3",
3
+ "version": "1.13.0",
4
4
  "description": "Shared modules of the Spacecat Services - utils",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -42,5 +42,8 @@
42
42
  "@adobe/fetch": "4.1.1",
43
43
  "@aws-sdk/client-s3": "3.521.0",
44
44
  "@aws-sdk/client-sqs": "3.521.0"
45
+ },
46
+ "peerDependencies": {
47
+ "@adobe/spacecat-shared-data-access": "1.x"
45
48
  }
46
49
  }
package/src/helpers.js CHANGED
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { isString } from './functions.js';
13
+ import { hasText, isString } from './functions.js';
14
14
 
15
15
  /**
16
16
  * Resolves the name of the secret based on the function version.
@@ -19,7 +19,7 @@ import { isString } from './functions.js';
19
19
  * @param {string} defaultPath - The default path for the secret.
20
20
  * @returns {string} - The resolved secret name.
21
21
  */
22
- const resolveSecretsName = (opts, ctx, defaultPath) => {
22
+ export function resolveSecretsName(opts, ctx, defaultPath) {
23
23
  let funcVersion = ctx?.func?.version;
24
24
 
25
25
  if (!isString(funcVersion)) {
@@ -33,8 +33,25 @@ const resolveSecretsName = (opts, ctx, defaultPath) => {
33
33
  funcVersion = /^ci\d+$/i.test(funcVersion) ? 'ci' : funcVersion;
34
34
 
35
35
  return `${defaultPath}/${funcVersion}`;
36
- };
36
+ }
37
37
 
38
- export {
39
- resolveSecretsName,
40
- };
38
+ export function isAuditsDisabled(site, organization, auditType) {
39
+ // return early if all audits are disabled for the organization
40
+ if (organization.getAuditConfig().auditsDisabled()) {
41
+ return true;
42
+ }
43
+
44
+ // return early if all audits are disabled for the site
45
+ if (site.getAuditConfig().auditsDisabled()) {
46
+ return true;
47
+ }
48
+
49
+ if (hasText(auditType)) {
50
+ const disabledAtOrg = organization.getAuditConfig().getAuditTypeConfig(auditType)?.disabled();
51
+ const disabledAtSite = site.getAuditConfig().getAuditTypeConfig(auditType)?.disabled();
52
+
53
+ return !!disabledAtOrg || !!disabledAtSite;
54
+ }
55
+
56
+ return false;
57
+ }
package/src/index.d.ts CHANGED
@@ -38,10 +38,10 @@ export function isValidUrl(urlString: string): boolean;
38
38
  export function dateAfterDays(days: number, dateString: string): Date;
39
39
 
40
40
  export function sqsWrapper(fn: (message: object, context: object) => Promise<Response>):
41
- (request: object, context: object) => Promise<Response>;
41
+ (request: object, context: object) => Promise<Response>;
42
42
 
43
43
  export function sqsEventAdapter(fn: (message: object, context: object) => Promise<Response>):
44
- (request: object, context: object) => Promise<Response>;
44
+ (request: object, context: object) => Promise<Response>;
45
45
 
46
46
  /**
47
47
  * Prepends 'https://' schema to the URL if it's not already present.
@@ -91,3 +91,20 @@ declare function composeBaseURL(domain: string): string;
91
91
  * @returns a promise that resolves the composed audit URL.
92
92
  */
93
93
  declare function composeAuditURL(url: string): Promise<string>;
94
+
95
+ /**
96
+ * Checks whether audits are disabled for a given site by inspecting the audit configurations
97
+ * in the respective organization and site models.
98
+ *
99
+ * If the optional parameter `auditType` is NOT provided, only the root-level "auditsDisabled" flag
100
+ * in the site and organization is checked.
101
+ *
102
+ * If the optional parameter `auditType` is provided, then the specific audit configuration for the
103
+ * specified type is also checked.
104
+ *
105
+ * @param {object} site - The site object.
106
+ * @param {object} organization - The organization object.
107
+ * @param {string} [auditType] - The type of audit.
108
+ * @returns {boolean} - True if the audit(s) are disabled, otherwise false.
109
+ */
110
+ declare function isAuditsDisabled(site: object, organization: object, auditType?: string): boolean
package/src/index.js CHANGED
@@ -27,7 +27,10 @@ export {
27
27
  dateAfterDays,
28
28
  } from './functions.js';
29
29
 
30
- export { resolveSecretsName } from './helpers.js';
30
+ export {
31
+ isAuditsDisabled,
32
+ resolveSecretsName,
33
+ } from './helpers.js';
31
34
 
32
35
  export { sqsWrapper } from './sqs.js';
33
36
  export { sqsEventAdapter } from './sqs.js';