@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.
Files changed (43) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +5 -5
  3. package/src/v2/errors/data-access.error.js +24 -0
  4. package/src/v2/errors/index.d.ts +5 -1
  5. package/src/v2/errors/index.js +11 -1
  6. package/src/v2/errors/reference.error.js +22 -0
  7. package/src/v2/{models/base/constants.js → errors/schema-validation.error.js} +4 -6
  8. package/src/v2/errors/schema.builder.error.js +27 -0
  9. package/src/v2/errors/schema.error.js +19 -0
  10. package/src/v2/errors/validation.error.js +3 -1
  11. package/src/v2/models/api-key/index.d.ts +15 -2
  12. package/src/v2/models/audit/audit.collection.js +25 -1
  13. package/src/v2/models/audit/audit.schema.js +3 -0
  14. package/src/v2/models/audit/index.d.ts +16 -11
  15. package/src/v2/models/base/base.collection.js +148 -85
  16. package/src/v2/models/base/base.model.js +73 -14
  17. package/src/v2/models/base/entity.registry.js +7 -2
  18. package/src/v2/models/base/index.d.ts +30 -11
  19. package/src/v2/models/base/reference.js +81 -28
  20. package/src/v2/models/base/schema.builder.js +96 -24
  21. package/src/v2/models/base/schema.js +78 -10
  22. package/src/v2/models/configuration/index.d.ts +24 -90
  23. package/src/v2/models/experiment/index.d.ts +11 -3
  24. package/src/v2/models/import-job/index.d.ts +10 -3
  25. package/src/v2/models/import-url/index.d.ts +6 -3
  26. package/src/v2/models/index.d.ts +3 -0
  27. package/src/v2/models/index.js +1 -0
  28. package/src/v2/models/key-event/index.d.ts +5 -1
  29. package/src/v2/models/latest-audit/index.d.ts +43 -0
  30. package/src/v2/models/latest-audit/index.js +19 -0
  31. package/src/v2/models/latest-audit/latest-audit.collection.js +32 -0
  32. package/src/v2/models/latest-audit/latest-audit.model.js +26 -0
  33. package/src/v2/models/latest-audit/latest-audit.schema.js +72 -0
  34. package/src/v2/models/opportunity/index.d.ts +17 -1
  35. package/src/v2/models/opportunity/opportunity.schema.js +1 -0
  36. package/src/v2/models/organization/index.d.ts +3 -1
  37. package/src/v2/models/site/index.d.ts +43 -6
  38. package/src/v2/models/site/site.model.js +0 -6
  39. package/src/v2/models/site/site.schema.js +2 -0
  40. package/src/v2/models/site-candidate/index.d.ts +5 -7
  41. package/src/v2/models/site-top-page/index.d.ts +16 -2
  42. package/src/v2/models/suggestion/index.d.ts +2 -0
  43. package/src/v2/util/patcher.js +11 -0
@@ -10,12 +10,12 @@
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 SiteCandidate extends BaseModel {
16
16
  getBaseURL(): string;
17
17
  getHlxConfig(): object;
18
- getSite(): object;
18
+ getSite(): Promise<Site>;
19
19
  getSiteId(): string;
20
20
  getSource(): string;
21
21
  getStatus(): string;
@@ -29,10 +29,8 @@ export interface SiteCandidate extends BaseModel {
29
29
  }
30
30
 
31
31
  export interface SiteCandidateCollection extends BaseCollection<SiteCandidate> {
32
+ allByBaseURL(baseURL: string): Promise<SiteCandidate[]>;
32
33
  allBySiteId(siteId: string): Promise<SiteCandidate[]>;
33
- allBySiteIdAndSiteCandidateIdAndUrl(
34
- siteId: string,
35
- siteCandidateId: string,
36
- url: string,
37
- ): Promise<SiteCandidate[]>;
34
+ findByBaseURL(baseURL: string): Promise<SiteCandidate | null>;
35
+ findBySiteId(siteId: string): Promise<SiteCandidate | null>;
38
36
  }
@@ -10,11 +10,12 @@
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 SiteTopPage extends BaseModel {
16
16
  getGeo(): string;
17
- getImportedAt(): number;
17
+ getImportedAt(): string;
18
+ getSite(): Promise<Site>;
18
19
  getSiteId(): string;
19
20
  getSource(): string;
20
21
  getTopKeyword(): string;
@@ -31,5 +32,18 @@ export interface SiteTopPage extends BaseModel {
31
32
 
32
33
  export interface SiteTopPageCollection extends BaseCollection<SiteTopPage> {
33
34
  allBySiteId(siteId: string): Promise<SiteTopPage[]>;
35
+ allBySiteIdAndSource(siteId: string, source: string): Promise<SiteTopPage[]>;
34
36
  allBySiteIdAndSourceAndGeo(siteId: string, source: string, geo: string): Promise<SiteTopPage[]>;
37
+ allBySiteIdAndSourceAndGeoAndTraffic(
38
+ siteId: string, source: string, geo: string, traffic: number
39
+ ): Promise<SiteTopPage[]>;
40
+ findBySiteId(siteId: string): Promise<SiteTopPage | null>;
41
+ findBySiteIdAndSource(siteId: string, source: string): Promise<SiteTopPage | null>;
42
+ findBySiteIdAndSourceAndGeo(
43
+ siteId: string, source: string, geo: string
44
+ ): Promise<SiteTopPage | null>;
45
+ findBySiteIdAndSourceAndGeoAndTraffic(
46
+ siteId: string, source: string, geo: string, traffic: number
47
+ ): Promise<SiteTopPage | null>;
48
+ removeForSiteId(siteId: string, source: string, geo: string): Promise<void>;
35
49
  }
@@ -31,4 +31,6 @@ export interface SuggestionCollection extends BaseCollection<Suggestion> {
31
31
  allByOpportunityId(opportunityId: string): Promise<Suggestion[]>;
32
32
  allByOpportunityIdAndStatus(opportunityId: string, status: string): Promise<Suggestion[]>;
33
33
  bulkUpdateStatus(suggestions: Suggestion[], status: string): Promise<Suggestion[]>;
34
+ findByOpportunityId(opportunityId: string): Promise<Suggestion | null>;
35
+ findByOpportunityIdAndStatus(opportunityId: string, status: string): Promise<Suggestion | null>;
34
36
  }
@@ -40,6 +40,12 @@ const checkReadOnly = (propertyName, attribute) => {
40
40
  }
41
41
  };
42
42
 
43
+ const checkUpdatesAllowed = (schema) => {
44
+ if (!schema.allowsUpdates()) {
45
+ throw new ValidationError(`Updates prohibited by schema for ${schema.getModelName()}.`);
46
+ }
47
+ };
48
+
43
49
  class Patcher {
44
50
  /**
45
51
  * Creates a new Patcher instance for an entity.
@@ -49,6 +55,7 @@ class Patcher {
49
55
  */
50
56
  constructor(entity, schema, record) {
51
57
  this.entity = entity;
58
+ this.schema = schema;
52
59
  this.record = record;
53
60
 
54
61
  this.entityName = schema.getEntityName();
@@ -151,6 +158,8 @@ class Patcher {
151
158
  * @param {boolean} [isReference=false] - Whether the value is a reference to another entity.
152
159
  */
153
160
  patchValue(propertyName, value, isReference = false) {
161
+ checkUpdatesAllowed(this.schema);
162
+
154
163
  const attribute = this.model.schema?.attributes[propertyName];
155
164
  if (!isObject(attribute)) {
156
165
  throw new ValidationError(`Property ${propertyName} does not exist on entity ${this.entityName}.`);
@@ -202,6 +211,8 @@ class Patcher {
202
211
  * @throws {Error} - Throws an error if the save operation fails.
203
212
  */
204
213
  async save() {
214
+ checkUpdatesAllowed(this.schema);
215
+
205
216
  if (!this.hasUpdates()) {
206
217
  return;
207
218
  }