@adobe/spacecat-shared-data-access 1.60.2 → 1.61.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 +14 -0
- package/package.json +5 -5
- package/src/v2/errors/data-access.error.js +24 -0
- package/src/v2/errors/index.d.ts +5 -1
- package/src/v2/errors/index.js +11 -1
- package/src/v2/errors/reference.error.js +22 -0
- package/src/v2/{models/base/constants.js → errors/schema-validation.error.js} +4 -6
- package/src/v2/errors/schema.builder.error.js +27 -0
- package/src/v2/errors/schema.error.js +19 -0
- package/src/v2/errors/validation.error.js +3 -1
- package/src/v2/models/api-key/index.d.ts +15 -2
- package/src/v2/models/audit/audit.collection.js +25 -1
- package/src/v2/models/audit/audit.schema.js +3 -0
- package/src/v2/models/audit/index.d.ts +16 -11
- package/src/v2/models/base/base.collection.js +148 -85
- package/src/v2/models/base/base.model.js +73 -14
- package/src/v2/models/base/entity.registry.js +7 -2
- package/src/v2/models/base/index.d.ts +30 -11
- package/src/v2/models/base/reference.js +81 -28
- package/src/v2/models/base/schema.builder.js +96 -24
- package/src/v2/models/base/schema.js +78 -10
- package/src/v2/models/configuration/index.d.ts +24 -90
- package/src/v2/models/experiment/index.d.ts +11 -3
- package/src/v2/models/import-job/index.d.ts +10 -3
- package/src/v2/models/import-url/index.d.ts +6 -3
- package/src/v2/models/index.d.ts +3 -0
- package/src/v2/models/index.js +1 -0
- package/src/v2/models/key-event/index.d.ts +5 -1
- package/src/v2/models/latest-audit/index.d.ts +43 -0
- package/src/v2/models/latest-audit/index.js +19 -0
- package/src/v2/models/latest-audit/latest-audit.collection.js +32 -0
- package/src/v2/models/latest-audit/latest-audit.model.js +26 -0
- package/src/v2/models/latest-audit/latest-audit.schema.js +72 -0
- package/src/v2/models/opportunity/index.d.ts +17 -1
- package/src/v2/models/opportunity/opportunity.schema.js +1 -0
- package/src/v2/models/organization/index.d.ts +3 -1
- package/src/v2/models/site/index.d.ts +43 -6
- package/src/v2/models/site/site.model.js +0 -6
- package/src/v2/models/site/site.schema.js +2 -0
- package/src/v2/models/site-candidate/index.d.ts +5 -7
- package/src/v2/models/site-top-page/index.d.ts +16 -2
- package/src/v2/models/suggestion/index.d.ts +2 -0
- package/src/v2/util/patcher.js +11 -0
|
@@ -15,97 +15,31 @@ import type {
|
|
|
15
15
|
} from '../index';
|
|
16
16
|
|
|
17
17
|
export interface Configuration extends BaseModel {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
getQueues
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
getHandlers: () => object;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Retrieves the handler configuration for handler type.
|
|
44
|
-
* @param type The handler type.
|
|
45
|
-
* @returns {object} The handler type configuration.
|
|
46
|
-
*/
|
|
47
|
-
getHandler: (type) => object;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Retrieves the slack roles configuration.
|
|
51
|
-
* @returns {object} The slack roles configuration.
|
|
52
|
-
*/
|
|
53
|
-
getSlackRoles: () => object;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Return true if a handler type is enabled for an organization.
|
|
57
|
-
* @param type handler type
|
|
58
|
-
* @param org organization
|
|
59
|
-
*/
|
|
60
|
-
isHandlerEnabledForOrg: (type: string, org: Organization) => boolean;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Return true if a handler type is enabled for a site.
|
|
64
|
-
* @param type handler type
|
|
65
|
-
* @param site site
|
|
66
|
-
*/
|
|
67
|
-
isHandlerEnabledForSite: (type: string, site: Site) => boolean;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Enables a handler type for an site.
|
|
71
|
-
* @param type handler type
|
|
72
|
-
* @param site site
|
|
73
|
-
*/
|
|
74
|
-
enableHandlerForSite: (type: string, site: Site) => void;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Enables a handler type for an organization.
|
|
78
|
-
* @param type handler type
|
|
79
|
-
* @param org organization
|
|
80
|
-
*/
|
|
81
|
-
enableHandlerForOrg: (type: string, org: Organization) => void;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Disables a handler type for an site.
|
|
85
|
-
* @param type handler type
|
|
86
|
-
* @param site site
|
|
87
|
-
*/
|
|
88
|
-
disableHandlerForSite: (type: string, site: Site) => void;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Disables a handler type for an organization.
|
|
92
|
-
* @param type handler type
|
|
93
|
-
* @param org organization
|
|
94
|
-
*/
|
|
95
|
-
disableHandlerForOrg: (type:string, org: Organization) => void;
|
|
18
|
+
addHandler(type: string, handler: object): void;
|
|
19
|
+
disableHandlerForOrganization(type: string, organization: Organization): void;
|
|
20
|
+
disableHandlerForSite(type: string, site: Site): void;
|
|
21
|
+
enableHandlerForOrganization(type: string, organization: Organization): void;
|
|
22
|
+
enableHandlerForSite(type: string, site: Site): void;
|
|
23
|
+
getConfigurationId(): string;
|
|
24
|
+
getEnabledSiteIdsForHandler(type: string): string[];
|
|
25
|
+
getHandler(type: string): object | undefined;
|
|
26
|
+
getHandlers(): object;
|
|
27
|
+
getJobs(): object;
|
|
28
|
+
getQueues(): object;
|
|
29
|
+
getSlackRoleMembersByRole(role: string): string[];
|
|
30
|
+
getSlackRoles(): object;
|
|
31
|
+
getVersion(): number;
|
|
32
|
+
isHandlerEnabledForOrg(type: string, organization: Organization): boolean;
|
|
33
|
+
isHandlerEnabledForSite(type: string, site: Site): boolean;
|
|
34
|
+
setHandlers(handlers: object): void;
|
|
35
|
+
setJobs(jobs: object): void;
|
|
36
|
+
setQueues(queues: object): void;
|
|
37
|
+
setSlackRoles(slackRoles: object): void;
|
|
38
|
+
updateHandlerOrgs(type: string, orgId: string, enabled: boolean): void;
|
|
39
|
+
updateHandlerSites(type: string, siteId: string, enabled: boolean): void;
|
|
96
40
|
}
|
|
97
41
|
|
|
98
42
|
export interface ConfigurationCollection extends BaseCollection<Configuration> {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
* @returns {Configuration} The configuration.
|
|
102
|
-
*/
|
|
103
|
-
findLatest: () => Configuration;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Retrieves the configuration by version.
|
|
107
|
-
* @param version The configuration version.
|
|
108
|
-
* @returns {Configuration} The configuration.
|
|
109
|
-
*/
|
|
110
|
-
findByVersion: (version: number) => Configuration;
|
|
43
|
+
findByVersion(version: number): Promise<Configuration | null>;
|
|
44
|
+
findLatest(): Promise<Configuration | null>;
|
|
111
45
|
}
|
|
@@ -30,20 +30,28 @@ export interface Experiment extends BaseModel {
|
|
|
30
30
|
setEndDate(endDate: number): Experiment;
|
|
31
31
|
setExpId(expId: string): Experiment;
|
|
32
32
|
setName(name: string): Experiment;
|
|
33
|
+
setSiteId(siteId: string): Experiment;
|
|
33
34
|
setStartDate(startDate: number): Experiment;
|
|
34
35
|
setStatus(status: string): Experiment;
|
|
35
36
|
setType(type: string): Experiment;
|
|
36
37
|
setUrl(url: string): Experiment;
|
|
38
|
+
setUpdatedBy(updatedBy: string): Experiment;
|
|
37
39
|
setVariants(variants: object): Experiment;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
export interface ExperimentCollection extends BaseCollection<Experiment> {
|
|
41
43
|
allBySiteId(siteId: string): Promise<Experiment[]>;
|
|
42
44
|
allBySiteIdAndExpId(siteId: string, expId: string): Promise<Experiment[]>;
|
|
45
|
+
allBySiteIdAndExpIdAndUrl(siteId: string, expId: string, url: string): Promise<Experiment[]>;
|
|
46
|
+
allBySiteIdAndExpIdAndUrlAndUpdatedAt(
|
|
47
|
+
siteId: string, expId: string, url: string, updatedAt: string
|
|
48
|
+
): Promise<Experiment[]>;
|
|
49
|
+
findBySiteId(siteId: string): Promise<Experiment | null>;
|
|
43
50
|
findBySiteIdAndExpId(siteId: string, expId: string): Promise<Experiment | null>;
|
|
44
51
|
findBySiteIdAndExpIdAndUrl(
|
|
45
|
-
siteId: string,
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
siteId: string, expId: string, url: string
|
|
53
|
+
): Promise<Experiment | null>;
|
|
54
|
+
findBySiteIdAndExpIdAndUrlAndUpdatedAt(
|
|
55
|
+
siteId: string, expId: string, url: string, updatedAt: string
|
|
48
56
|
): Promise<Experiment | null>;
|
|
49
57
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type { BaseCollection, BaseModel } from '../base';
|
|
14
|
+
import type { ImportUrl } from '../import-url';
|
|
14
15
|
|
|
15
16
|
export interface ImportJob extends BaseModel {
|
|
16
17
|
getBaseURL(): string,
|
|
@@ -21,11 +22,13 @@ export interface ImportJob extends BaseModel {
|
|
|
21
22
|
getHasCustomImportJs(): boolean,
|
|
22
23
|
getHashedApiKey(): string,
|
|
23
24
|
getImportQueueId(): string,
|
|
25
|
+
getImportUrls(): Promise<ImportUrl[]>,
|
|
26
|
+
getImportUrlsByStatus(status: string): Promise<ImportUrl[]>,
|
|
24
27
|
getInitiatedBy(): string,
|
|
25
28
|
getOptions(): string,
|
|
26
29
|
getRedirectCount(): number,
|
|
27
|
-
getStatus(): string,
|
|
28
30
|
getStartedAt(): number,
|
|
31
|
+
getStatus(): string,
|
|
29
32
|
getSuccessCount(): number,
|
|
30
33
|
getUrlCount(): number,
|
|
31
34
|
setBaseURL(baseURL: string): void,
|
|
@@ -40,12 +43,16 @@ export interface ImportJob extends BaseModel {
|
|
|
40
43
|
setOptions(options: string): void,
|
|
41
44
|
setRedirectCount(redirectCount: number): void,
|
|
42
45
|
setStatus(status: string): void,
|
|
43
|
-
setStartedAt(startTime: number): void,
|
|
44
46
|
setSuccessCount(successCount: number): void,
|
|
45
47
|
setUrlCount(urlCount: number): void,
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
export interface ImportJobCollection extends BaseCollection<ImportJob> {
|
|
49
|
-
allByDateRange(startDate:
|
|
51
|
+
allByDateRange(startDate: string, endDate: string): Promise<ImportJob[]>;
|
|
52
|
+
allByStartedAt(startDate: string): Promise<ImportJob[]>;
|
|
50
53
|
allByStatus(status: string): Promise<ImportJob[]>;
|
|
54
|
+
allByStatusAndUpdatedAt(status: string, updatedAt: string): Promise<ImportJob[]>;
|
|
55
|
+
findByStartedAt(startDate: string): Promise<ImportJob | null>;
|
|
56
|
+
findByStatus(status: string): Promise<ImportJob | null>;
|
|
57
|
+
findByStatusAndUpdatedAt(status: string, updatedAt: string): Promise<ImportJob | null>;
|
|
51
58
|
}
|
|
@@ -10,17 +10,18 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import type { BaseCollection, BaseModel } from '../
|
|
13
|
+
import type { BaseCollection, BaseModel, ImportJob } from '../index';
|
|
14
14
|
|
|
15
15
|
export interface ImportUrl extends BaseModel {
|
|
16
|
-
getExpiresAt():
|
|
16
|
+
getExpiresAt(): string,
|
|
17
17
|
getFile(): string,
|
|
18
|
+
getImportJob(): Promise<ImportJob>,
|
|
18
19
|
getImportJobId(): string,
|
|
19
20
|
getPath(): string,
|
|
20
21
|
getReason(): string,
|
|
21
22
|
getStatus(): string,
|
|
22
23
|
getUrl(): string,
|
|
23
|
-
setExpiresAt(expiresAt:
|
|
24
|
+
setExpiresAt(expiresAt: string): void,
|
|
24
25
|
setFile(file: string): void,
|
|
25
26
|
setImportJobId(importJobId: string): void,
|
|
26
27
|
setPath(path: string): void,
|
|
@@ -32,4 +33,6 @@ export interface ImportUrl extends BaseModel {
|
|
|
32
33
|
export interface ImportUrlCollection extends BaseCollection<ImportUrl> {
|
|
33
34
|
allByImportJobId(importJobId: string): Promise<ImportUrl[]>;
|
|
34
35
|
allByImportUrlsByJobIdAndStatus(importJobId: string, status: string): Promise<ImportUrl[]>;
|
|
36
|
+
findByImportJobId(importJobId: string): Promise<ImportUrl | null>;
|
|
37
|
+
findByImportJobIdAndUrl(importJobId: string, url: string): Promise<ImportUrl | null>;
|
|
35
38
|
}
|
package/src/v2/models/index.d.ts
CHANGED
|
@@ -14,7 +14,10 @@ export type * from './audit/index.d.ts';
|
|
|
14
14
|
export type * from './configuration/index.d.ts';
|
|
15
15
|
export type * from './base/index.d.ts';
|
|
16
16
|
export type * from './experiment/index.d.ts';
|
|
17
|
+
export type * from './import-job/index.d.ts';
|
|
18
|
+
export type * from './import-url/index.d.ts';
|
|
17
19
|
export type * from './key-event/index.d.ts';
|
|
20
|
+
export type * from './latest-audit/index.d.ts';
|
|
18
21
|
export type * from './opportunity/index.d.ts';
|
|
19
22
|
export type * from './organization/index.d.ts';
|
|
20
23
|
export type * from './site/index.d.ts';
|
package/src/v2/models/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from './experiment/index.js';
|
|
|
18
18
|
export * from './import-job/index.js';
|
|
19
19
|
export * from './import-url/index.js';
|
|
20
20
|
export * from './key-event/index.js';
|
|
21
|
+
export * from './latest-audit/index.js';
|
|
21
22
|
export * from './opportunity/index.js';
|
|
22
23
|
export * from './organization/index.js';
|
|
23
24
|
export * from './site-candidate/index.js';
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import type { BaseCollection, BaseModel } from '../index';
|
|
13
|
+
import type { BaseCollection, BaseModel, Site } from '../index';
|
|
14
14
|
|
|
15
15
|
export interface KeyEvent extends BaseModel {
|
|
16
16
|
getName(): string;
|
|
17
|
+
getSite(): Promise<Site>;
|
|
17
18
|
getSiteId(): string;
|
|
18
19
|
getTime(): number;
|
|
19
20
|
getType(): string;
|
|
@@ -25,4 +26,7 @@ export interface KeyEvent extends BaseModel {
|
|
|
25
26
|
|
|
26
27
|
export interface KeyEventCollection extends BaseCollection<KeyEvent> {
|
|
27
28
|
allBySiteId(siteId: string): Promise<KeyEvent[]>;
|
|
29
|
+
allBySiteIdAndTime(siteId: string, time: string): Promise<KeyEvent[]>;
|
|
30
|
+
findBySiteId(siteId: string): Promise<KeyEvent | null>;
|
|
31
|
+
findBySiteIdAndTime(siteId: string, time: string): Promise<KeyEvent | null>;
|
|
28
32
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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 type {
|
|
14
|
+
Audit, BaseCollection, BaseModel, Opportunity, Site,
|
|
15
|
+
} from '../index';
|
|
16
|
+
|
|
17
|
+
export interface LatestAudit extends BaseModel {
|
|
18
|
+
getAudit(): Promise<Audit>
|
|
19
|
+
getAuditedAt(): number;
|
|
20
|
+
getAuditId(): object;
|
|
21
|
+
getAuditResult(): object;
|
|
22
|
+
getAuditType(): string;
|
|
23
|
+
getFullAuditRef(): string;
|
|
24
|
+
getIsError(): boolean;
|
|
25
|
+
getIsLive(): boolean;
|
|
26
|
+
getOpportunities(): Promise<Opportunity[]>;
|
|
27
|
+
getOpportunitiesByUpdatedAt(): Promise<Opportunity[]>;
|
|
28
|
+
getSite(): Promise<Site>;
|
|
29
|
+
getSiteId(): string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface LatestAuditCollection extends BaseCollection<LatestAudit> {
|
|
33
|
+
allByAuditId(auditId: string): Promise<LatestAudit[]>;
|
|
34
|
+
allByAuditIdAndAuditType(auditId: string, auditType: string): Promise<LatestAudit[]>;
|
|
35
|
+
allByAuditType(auditType: string): Promise<LatestAudit[]>;
|
|
36
|
+
allBySiteId(siteId: string): Promise<LatestAudit[]>;
|
|
37
|
+
allBySiteIdAndAuditType(siteId: string, auditType: string): Promise<LatestAudit[]>;
|
|
38
|
+
findByAuditId(auditId: string): Promise<LatestAudit | null>;
|
|
39
|
+
findByAuditIdAndAuditType(auditId: string, auditType: string): Promise<LatestAudit | null>;
|
|
40
|
+
findByAuditType(auditType: string): Promise<LatestAudit | null>;
|
|
41
|
+
findBySiteId(siteId: string): Promise<LatestAudit | null>;
|
|
42
|
+
findBySiteIdAndAuditType(siteId: string, auditType: string): Promise<LatestAudit | null>;
|
|
43
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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 LatestAudit from './latest-audit.model.js';
|
|
14
|
+
import LatestAuditCollection from './latest-audit.collection.js';
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
LatestAudit,
|
|
18
|
+
LatestAuditCollection,
|
|
19
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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 BaseCollection from '../base/base.collection.js';
|
|
14
|
+
import { guardId, guardString } from '../../util/index.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* LatestAuditCollection - A collection class responsible for managing LatestAudit entities.
|
|
18
|
+
* Extends the AuditCollection to provide specific methods for interacting with LatestAudit records.
|
|
19
|
+
*
|
|
20
|
+
* @class LatestAuditCollection
|
|
21
|
+
* @extends AuditCollection
|
|
22
|
+
*/
|
|
23
|
+
class LatestAuditCollection extends BaseCollection {
|
|
24
|
+
async findById(siteId, auditType) {
|
|
25
|
+
guardId('siteId', siteId, this.entityName);
|
|
26
|
+
guardString('auditType', auditType, this.entityName);
|
|
27
|
+
|
|
28
|
+
return this.findByIndexKeys({ siteId, auditType });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default LatestAuditCollection;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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 Audit from '../audit/audit.model.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* LatestAudit - A class representing an LatestAudit entity.
|
|
17
|
+
* Provides methods to access and manipulate Audit-specific data.
|
|
18
|
+
*
|
|
19
|
+
* @class LatestAudit
|
|
20
|
+
* @extends Audit
|
|
21
|
+
*/
|
|
22
|
+
class LatestAudit extends Audit {
|
|
23
|
+
// add your custom methods or overrides here
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default LatestAudit;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 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
|
+
/* c8 ignore start */
|
|
14
|
+
|
|
15
|
+
import { isIsoDate, isNonEmptyObject } from '@adobe/spacecat-shared-utils';
|
|
16
|
+
|
|
17
|
+
import { validateAuditResult } from '../audit/audit.model.js';
|
|
18
|
+
import SchemaBuilder from '../base/schema.builder.js';
|
|
19
|
+
import LatestAudit from './latest-audit.model.js';
|
|
20
|
+
import LatestAuditCollection from './latest-audit.collection.js';
|
|
21
|
+
|
|
22
|
+
/*
|
|
23
|
+
Schema Doc: https://electrodb.dev/en/modeling/schema/
|
|
24
|
+
Attribute Doc: https://electrodb.dev/en/modeling/attributes/
|
|
25
|
+
Indexes Doc: https://electrodb.dev/en/modeling/indexes/
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const schema = new SchemaBuilder(LatestAudit, LatestAuditCollection)
|
|
29
|
+
.withPrimaryPartitionKeys(['siteId'])
|
|
30
|
+
.withPrimarySortKeys(['auditType'])
|
|
31
|
+
.addReference('belongs_to', 'Site', ['auditType'])
|
|
32
|
+
.addReference('belongs_to', 'Audit', ['auditType'])
|
|
33
|
+
.addReference('has_many', 'Opportunities')
|
|
34
|
+
.addAllIndex(['auditType'])
|
|
35
|
+
.allowUpdates(false)
|
|
36
|
+
.allowRemove(false)
|
|
37
|
+
.addAttribute('auditResult', {
|
|
38
|
+
type: 'any',
|
|
39
|
+
required: true,
|
|
40
|
+
validate: (value) => isNonEmptyObject(value),
|
|
41
|
+
set: (value, attributes) => {
|
|
42
|
+
// as the electroDb validate function does not provide access to the model instance
|
|
43
|
+
// we need to call the validate function from the model on setting the value
|
|
44
|
+
validateAuditResult(value, attributes.auditType);
|
|
45
|
+
return value;
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
.addAttribute('auditType', {
|
|
49
|
+
type: 'string',
|
|
50
|
+
required: true,
|
|
51
|
+
})
|
|
52
|
+
.addAttribute('fullAuditRef', {
|
|
53
|
+
type: 'string',
|
|
54
|
+
required: true,
|
|
55
|
+
})
|
|
56
|
+
.addAttribute('isLive', {
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
required: true,
|
|
59
|
+
default: false,
|
|
60
|
+
})
|
|
61
|
+
.addAttribute('isError', {
|
|
62
|
+
type: 'boolean',
|
|
63
|
+
required: true,
|
|
64
|
+
default: false,
|
|
65
|
+
})
|
|
66
|
+
.addAttribute('auditedAt', {
|
|
67
|
+
type: 'string',
|
|
68
|
+
required: true,
|
|
69
|
+
validate: (value) => isIsoDate(value),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export default schema.build();
|
|
@@ -11,20 +11,24 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type {
|
|
14
|
-
BaseCollection, BaseModel, MultiStatusCreateResult, Suggestion,
|
|
14
|
+
Audit, BaseCollection, BaseModel, MultiStatusCreateResult, Site, Suggestion,
|
|
15
15
|
} from '../index';
|
|
16
16
|
|
|
17
17
|
export interface Opportunity extends BaseModel {
|
|
18
18
|
addSuggestions(suggestions: object[]): Promise<MultiStatusCreateResult<Suggestion>>;
|
|
19
|
+
getAudit(): Promise<Audit>;
|
|
19
20
|
getAuditId(): string;
|
|
20
21
|
getData(): object;
|
|
21
22
|
getDescription(): string;
|
|
22
23
|
getGuidance(): string;
|
|
23
24
|
getOrigin(): string;
|
|
24
25
|
getRunbook(): string;
|
|
26
|
+
getSite(): Promise<Site>;
|
|
25
27
|
getSiteId(): string;
|
|
26
28
|
getStatus(): string;
|
|
27
29
|
getSuggestions(): Promise<Suggestion[]>;
|
|
30
|
+
getSuggestionsByStatus(status: string): Promise<Suggestion[]>;
|
|
31
|
+
getSuggestionsByStatusAndRank(status: string, rank: string): Promise<Suggestion[]>;
|
|
28
32
|
getTags(): string[];
|
|
29
33
|
getTitle(): string;
|
|
30
34
|
getType(): string;
|
|
@@ -41,6 +45,18 @@ export interface Opportunity extends BaseModel {
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
export interface OpportunityCollection extends BaseCollection<Opportunity> {
|
|
48
|
+
allByAuditId(auditId: string): Promise<Opportunity[]>;
|
|
49
|
+
allByAuditIdAndUpdatedAt(auditId: string, updatedAt: string): Promise<Opportunity[]>;
|
|
44
50
|
allBySiteId(siteId: string): Promise<Opportunity[]>;
|
|
45
51
|
allBySiteIdAndStatus(siteId: string, status: string): Promise<Opportunity[]>;
|
|
52
|
+
allBySiteIdAndStatusAndUpdatedAt(
|
|
53
|
+
siteId: string, status: string, updatedAt: string
|
|
54
|
+
): Promise<Opportunity[]>;
|
|
55
|
+
findByAuditId(auditId: string): Promise<Opportunity | null>;
|
|
56
|
+
findByAuditIdAndUpdatedAt(auditId: string, updatedAt: string): Promise<Opportunity | null>;
|
|
57
|
+
findBySiteId(siteId: string): Promise<Opportunity | null>;
|
|
58
|
+
findBySiteIdAndStatus(siteId: string, status: string): Promise<Opportunity | null>;
|
|
59
|
+
findBySiteIdAndStatusAndUpdatedAt(
|
|
60
|
+
siteId: string, status: string, updatedAt: string
|
|
61
|
+
): Promise<Opportunity | null>;
|
|
46
62
|
}
|
|
@@ -27,6 +27,7 @@ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
|
|
|
27
27
|
const schema = new SchemaBuilder(Opportunity, OpportunityCollection)
|
|
28
28
|
.addReference('belongs_to', 'Site', ['status', 'updatedAt'])
|
|
29
29
|
.addReference('belongs_to', 'Audit', ['updatedAt'], { required: false })
|
|
30
|
+
.addReference('belongs_to', 'LatestAudit', ['updatedAt'], { required: false })
|
|
30
31
|
.addReference('has_many', 'Suggestions', ['updatedAt'], { removeDependents: true })
|
|
31
32
|
.addAttribute('runbook', {
|
|
32
33
|
type: 'string',
|
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import type { BaseCollection, BaseModel } from '../index';
|
|
13
|
+
import type { BaseCollection, BaseModel, Site } from '../index';
|
|
14
14
|
|
|
15
15
|
export interface Organization extends BaseModel {
|
|
16
16
|
getConfig(): object;
|
|
17
17
|
getFulfillableItems(): object;
|
|
18
18
|
getImsOrgId(): string;
|
|
19
19
|
getName(): string;
|
|
20
|
+
getSites(): Promise<Site[]>;
|
|
20
21
|
setConfig(config: object): Organization;
|
|
21
22
|
setFulfillableItems(fulfillableItems: object): Organization;
|
|
22
23
|
setImsOrgId(imsOrgId: string): Organization;
|
|
@@ -25,4 +26,5 @@ export interface Organization extends BaseModel {
|
|
|
25
26
|
|
|
26
27
|
export interface OrganizationCollection extends BaseCollection<Organization> {
|
|
27
28
|
allByImsOrgId(imsOrgId: string): Promise<Organization[]>;
|
|
29
|
+
findByImsOrgId(imsOrgId: string): Promise<Organization | null>;
|
|
28
30
|
}
|
|
@@ -11,33 +11,70 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type {
|
|
14
|
-
Audit,
|
|
14
|
+
Audit,
|
|
15
|
+
BaseCollection,
|
|
16
|
+
BaseModel,
|
|
17
|
+
Experiment,
|
|
18
|
+
KeyEvent,
|
|
19
|
+
LatestAudit,
|
|
20
|
+
Opportunity,
|
|
21
|
+
Organization,
|
|
22
|
+
SiteCandidate,
|
|
23
|
+
SiteTopPage,
|
|
15
24
|
} from '../index';
|
|
16
25
|
|
|
17
26
|
export interface Site extends BaseModel {
|
|
18
27
|
getAudits(): Promise<Audit>;
|
|
28
|
+
getAuditsByAuditType(auditType: string): Promise<Audit>;
|
|
29
|
+
getAuditsByAuditTypeAndAuditedAt(auditType: string, auditedAt: string): Promise<Audit>;
|
|
19
30
|
getBaseURL(): string;
|
|
20
31
|
getConfig(): object;
|
|
21
32
|
getDeliveryType(): string;
|
|
22
|
-
|
|
33
|
+
getExperiments(): Promise<Experiment[]>;
|
|
34
|
+
getExperimentsByExpId(expId: string): Promise<Experiment[]>;
|
|
35
|
+
getExperimentsByExpIdAndUrl(expId: string, url: string): Promise<Experiment[]>;
|
|
36
|
+
getExperimentsByExpIdAndUrlAndUpdatedAt(
|
|
37
|
+
expId: string, url: string, updatedAt: string
|
|
38
|
+
): Promise<Experiment[]>;
|
|
23
39
|
getGitHubURL(): string;
|
|
24
40
|
getHlxConfig(): object;
|
|
25
41
|
getIsLive(): boolean;
|
|
26
42
|
getIsLiveToggledAt(): string;
|
|
43
|
+
getKeyEvents(): Promise<KeyEvent[]>
|
|
44
|
+
getKeyEventsByTimestamp(timestamp: string): Promise<KeyEvent[]>
|
|
45
|
+
getLatestAudit(): Promise<LatestAudit>;
|
|
46
|
+
getLatestAuditByAuditType(auditType: string): Promise<LatestAudit>;
|
|
47
|
+
getLatestAudits(): Promise<LatestAudit>;
|
|
48
|
+
getLatestAuditByAuditType(auditType: string): Promise<LatestAudit>;
|
|
49
|
+
getOpportunities(): Promise<Opportunity[]>;
|
|
50
|
+
getOpportunitiesByStatus(status: string): Promise<Opportunity[]>;
|
|
51
|
+
getOpportunitiesByStatusAndUpdatedAt(status: string, updatedAt: string): Promise<Opportunity[]>;
|
|
27
52
|
getOrganization(): Promise<Organization>;
|
|
28
53
|
getOrganizationId(): string;
|
|
54
|
+
getSiteCandidates(): Promise<SiteCandidate[]>;
|
|
55
|
+
getSiteTopPages(): Promise<SiteTopPage[]>;
|
|
56
|
+
getSiteTopPagesBySource(source: string): Promise<SiteTopPage[]>;
|
|
57
|
+
getSiteTopPagesBySourceAndGeo(source: string, geo: string): Promise<SiteTopPage[]>;
|
|
58
|
+
getSiteTopPagesBySourceAndGeoAndTraffic(
|
|
59
|
+
source: string, geo: string, traffic: string
|
|
60
|
+
): Promise<SiteTopPage[]>;
|
|
61
|
+
setBaseURL(baseURL: string): Site;
|
|
29
62
|
setConfig(config: object): Site;
|
|
30
63
|
setDeliveryType(deliveryType: string): Site;
|
|
31
|
-
setFulfillableItems(fulfillableItems: object): Site;
|
|
32
64
|
setGitHubURL(gitHubURL: string): Site;
|
|
33
65
|
setHlxConfig(hlxConfig: object): Site;
|
|
34
66
|
setIsLive(isLive: boolean): Site;
|
|
67
|
+
setIsLiveToggledAt(isLiveToggledAt: string): Site;
|
|
35
68
|
setOrganizationId(organizationId: string): Site;
|
|
36
69
|
toggleLive(): Site;
|
|
37
70
|
}
|
|
38
71
|
|
|
39
72
|
export interface SiteCollection extends BaseCollection<Organization> {
|
|
40
|
-
|
|
41
|
-
allByDeliveryType(
|
|
42
|
-
allByOrganizationId(
|
|
73
|
+
allByBaseURL(baseURL: string): Promise<Site[]>;
|
|
74
|
+
allByDeliveryType(deliveryType: string): Promise<Site[]>;
|
|
75
|
+
allByOrganizationId(organizationId: string): Promise<Site[]>;
|
|
76
|
+
allSitesToAudit(): Promise<string[]>;
|
|
77
|
+
findByBaseURL(baseURL: string): Promise<Site | null>;
|
|
78
|
+
findByDeliveryType(deliveryType: string): Promise<Site | null>;
|
|
79
|
+
findByOrganizationId(organizationId: string): Promise<Site | null>;
|
|
43
80
|
}
|
|
@@ -31,12 +31,6 @@ class Site extends BaseModel {
|
|
|
31
31
|
return Config(this.record.config);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
async getLatestAuditByType(auditType) {
|
|
35
|
-
const collection = this.entityRegistry.getCollection('AuditCollection');
|
|
36
|
-
|
|
37
|
-
return collection.findByIndexKeys({ siteId: this.getId(), auditType });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
34
|
async toggleLive() {
|
|
41
35
|
const newIsLive = !this.getIsLive();
|
|
42
36
|
this.setIsLive(newIsLive);
|
|
@@ -41,6 +41,8 @@ const schema = new SchemaBuilder(Site, SiteCollection)
|
|
|
41
41
|
.addReference('has_many', 'Audits')
|
|
42
42
|
.addReference('has_many', 'Experiments')
|
|
43
43
|
.addReference('has_many', 'KeyEvents')
|
|
44
|
+
.addReference('has_many', 'LatestAudits', ['auditType'])
|
|
45
|
+
.addReference('has_one', 'LatestAudit', ['auditType'], { required: false })
|
|
44
46
|
.addReference('has_many', 'Opportunities')
|
|
45
47
|
.addReference('has_many', 'SiteCandidates')
|
|
46
48
|
.addReference('has_many', 'SiteTopPages')
|