@adobe/spacecat-shared-data-access 2.65.2 → 2.67.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-data-access-v2.67.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.66.0...@adobe/spacecat-shared-data-access-v2.67.0) (2025-10-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * add support for region/language configurations ([#995](https://github.com/adobe/spacecat-shared/issues/995)) ([c5219da](https://github.com/adobe/spacecat-shared/commit/c5219da283370e7de5411aa778773315efdeb869))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v2.66.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.65.2...@adobe/spacecat-shared-data-access-v2.66.0) (2025-10-03)
9
+
10
+
11
+ ### Features
12
+
13
+ * Add configuration methods to register audits ([#1000](https://github.com/adobe/spacecat-shared/issues/1000)) ([f58670e](https://github.com/adobe/spacecat-shared/commit/f58670e5b3561bef09911102cc947fa6ba2a4955))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v2.65.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.65.1...@adobe/spacecat-shared-data-access-v2.65.2) (2025-10-01)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "2.65.2",
3
+ "version": "2.67.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -26,6 +26,7 @@ import KeyEventCollection from '../key-event/key-event.collection.js';
26
26
  import LatestAuditCollection from '../latest-audit/latest-audit.collection.js';
27
27
  import OpportunityCollection from '../opportunity/opportunity.collection.js';
28
28
  import OrganizationCollection from '../organization/organization.collection.js';
29
+ import ProjectCollection from '../project/project.collection.js';
29
30
  import ScrapeJobCollection from '../scrape-job/scrape-job.collection.js';
30
31
  import ScrapeUrlCollection from '../scrape-url/scrape-url.collection.js';
31
32
  import SiteCandidateCollection from '../site-candidate/site-candidate.collection.js';
@@ -52,6 +53,7 @@ import KeyEventSchema from '../key-event/key-event.schema.js';
52
53
  import LatestAuditSchema from '../latest-audit/latest-audit.schema.js';
53
54
  import OpportunitySchema from '../opportunity/opportunity.schema.js';
54
55
  import OrganizationSchema from '../organization/organization.schema.js';
56
+ import ProjectSchema from '../project/project.schema.js';
55
57
  import ScrapeJobSchema from '../scrape-job/scrape-job.schema.js';
56
58
  import ScrapeUrlSchema from '../scrape-url/scrape-url.schema.js';
57
59
  import SiteSchema from '../site/site.schema.js';
@@ -147,6 +149,7 @@ EntityRegistry.registerEntity(KeyEventSchema, KeyEventCollection);
147
149
  EntityRegistry.registerEntity(LatestAuditSchema, LatestAuditCollection);
148
150
  EntityRegistry.registerEntity(OpportunitySchema, OpportunityCollection);
149
151
  EntityRegistry.registerEntity(OrganizationSchema, OrganizationCollection);
152
+ EntityRegistry.registerEntity(ProjectSchema, ProjectCollection);
150
153
  EntityRegistry.registerEntity(ScrapeJobSchema, ScrapeJobCollection);
151
154
  EntityRegistry.registerEntity(ScrapeUrlSchema, ScrapeUrlCollection);
152
155
  EntityRegistry.registerEntity(SiteSchema, SiteCollection);
@@ -14,6 +14,7 @@ import { isNonEmptyObject, isNonEmptyArray } from '@adobe/spacecat-shared-utils'
14
14
 
15
15
  import { sanitizeIdAndAuditFields } from '../../util/util.js';
16
16
  import BaseModel from '../base/base.model.js';
17
+ import { Audit } from '../audit/index.js';
17
18
 
18
19
  /**
19
20
  * Configuration - A class representing an Configuration entity.
@@ -248,6 +249,70 @@ class Configuration extends BaseModel {
248
249
  this.updateHandlerOrgs(type, orgId, false);
249
250
  }
250
251
 
252
+ registerAudit(type, enabledByDefault = false, interval = Configuration.JOB_INTERVALS.NEVER) {
253
+ // Validate audit type
254
+ if (!Object.values(Audit.AUDIT_TYPES).includes(type)) {
255
+ throw new Error(`Audit type ${type} is not a valid audit type in the data model`);
256
+ }
257
+
258
+ // Validate job interval
259
+ if (!Object.values(Configuration.JOB_INTERVALS).includes(interval)) {
260
+ throw new Error(`Invalid interval ${interval}`);
261
+ }
262
+
263
+ // Add to handlers if not already registered
264
+ const handlers = this.getHandlers();
265
+ if (!handlers[type]) {
266
+ handlers[type] = {
267
+ enabledByDefault,
268
+ enabled: {
269
+ sites: [],
270
+ orgs: [],
271
+ },
272
+ disabled: {
273
+ sites: [],
274
+ orgs: [],
275
+ },
276
+ dependencies: [],
277
+ };
278
+ this.setHandlers(handlers);
279
+ }
280
+
281
+ // Add to jobs if not already registered
282
+ const jobs = this.getJobs();
283
+ const exists = jobs.find((job) => job.group === 'audits' && job.type === type);
284
+ if (!exists) {
285
+ jobs.push({
286
+ group: 'audits',
287
+ type,
288
+ interval,
289
+ });
290
+ this.setJobs(jobs);
291
+ }
292
+ }
293
+
294
+ unregisterAudit(type) {
295
+ // Validate audit type
296
+ if (!Object.values(Audit.AUDIT_TYPES).includes(type)) {
297
+ throw new Error(`Audit type ${type} is not a valid audit type in the data model`);
298
+ }
299
+
300
+ // Remove from handlers
301
+ const handlers = this.getHandlers();
302
+ if (handlers[type]) {
303
+ delete handlers[type];
304
+ this.setHandlers(handlers);
305
+ }
306
+
307
+ // Remove from jobs
308
+ const jobs = this.getJobs();
309
+ const jobIndex = jobs.findIndex((job) => job.group === 'audits' && job.type === type);
310
+ if (jobIndex !== -1) {
311
+ jobs.splice(jobIndex, 1);
312
+ this.setJobs(jobs);
313
+ }
314
+ }
315
+
251
316
  async save() {
252
317
  return this.collection.create(sanitizeIdAndAuditFields(this.constructor.name, this.toJSON()));
253
318
  }
@@ -39,6 +39,8 @@ export interface Configuration extends BaseModel {
39
39
  setSlackRoles(slackRoles: object): void;
40
40
  updateHandlerOrgs(type: string, orgId: string, enabled: boolean): void;
41
41
  updateHandlerSites(type: string, siteId: string, enabled: boolean): void;
42
+ registerAudit(type: string, enabledByDefault?: boolean, interval?: string): void;
43
+ unregisterAudit(type: string): void;
42
44
  }
43
45
 
44
46
  export interface ConfigurationCollection extends BaseCollection<Configuration> {
@@ -24,6 +24,7 @@ export * from './key-event/index.js';
24
24
  export * from './latest-audit/index.js';
25
25
  export * from './opportunity/index.js';
26
26
  export * from './organization/index.js';
27
+ export * from './project/index.js';
27
28
  export * from './scrape-job/index.js';
28
29
  export * from './scrape-url/index.js';
29
30
  export * from './site-candidate/index.js';
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import type {
14
- BaseCollection, BaseModel, Site, Entitlement, OrganizationIdentityProvider, TrialUser,
14
+ BaseCollection, BaseModel, Site, Project, Entitlement, OrganizationIdentityProvider, TrialUser,
15
15
  } from '../index';
16
16
 
17
17
  export interface Organization extends BaseModel {
@@ -20,6 +20,7 @@ export interface Organization extends BaseModel {
20
20
  getImsOrgId(): string;
21
21
  getName(): string;
22
22
  getSites(): Promise<Site[]>;
23
+ getProjects(): Promise<Project[]>;
23
24
  getEntitlements(): Promise<Entitlement[]>;
24
25
  getOrganizationIdentityProviders(): Promise<OrganizationIdentityProvider[]>;
25
26
  getTrialUsers(): Promise<TrialUser[]>;
@@ -28,6 +28,7 @@ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
28
28
  const schema = new SchemaBuilder(Organization, OrganizationCollection)
29
29
  // this will add an attribute 'organizationId' as well as an index 'byOrganizationId'
30
30
  .addReference('has_many', 'Sites')
31
+ .addReference('has_many', 'Projects')
31
32
  .addReference('has_many', 'Entitlements')
32
33
  .addReference('has_many', 'TrialUsers')
33
34
  .addAttribute('config', {
@@ -0,0 +1,31 @@
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
+ BaseCollection, BaseModel, Organization, Site,
15
+ } from '../index';
16
+
17
+ export interface Project extends BaseModel {
18
+ getProjectName(): string;
19
+ getOrganization(): Promise<Organization>;
20
+ getOrganizationId(): string;
21
+ getSites(): Promise<Site[]>;
22
+ getPrimaryLocaleSites(): Promise<Site[]>;
23
+ setProjectName(projectName: string): Project;
24
+ setOrganizationId(organizationId: string): Project;
25
+ }
26
+
27
+ export interface ProjectCollection extends BaseCollection<Project> {
28
+ allByOrganizationId(organizationId: string): Promise<Project[]>;
29
+ findByOrganizationId(organizationId: string): Promise<Project | null>;
30
+ findByProjectName(projectName: string): Promise<Project | null>;
31
+ }
@@ -0,0 +1,14 @@
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
+ export { default as Project } from './project.model.js';
14
+ export { default as ProjectCollection } from './project.collection.js';
@@ -0,0 +1,25 @@
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
+
15
+ /**
16
+ * ProjectCollection - A collection class responsible for managing Project entities.
17
+ * Extends the BaseCollection to provide specific methods for interacting with Project records.
18
+ *
19
+ * @class ProjectCollection
20
+ * @extends BaseCollection
21
+ */
22
+ class ProjectCollection extends BaseCollection {
23
+ }
24
+
25
+ export default ProjectCollection;
@@ -0,0 +1,29 @@
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 BaseModel from '../base/base.model.js';
14
+
15
+ /**
16
+ * Project - A class representing a Project entity.
17
+ * Provides methods to access and manipulate Project-specific data.
18
+ *
19
+ * @class Project
20
+ * @extends BaseModel
21
+ */
22
+ class Project extends BaseModel {
23
+ async getPrimaryLocaleSites() {
24
+ const sites = await this.getSites();
25
+ return sites.filter((site) => site.getIsPrimaryLocale());
26
+ }
27
+ }
28
+
29
+ export default Project;
@@ -0,0 +1,37 @@
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 { hasText } from '@adobe/spacecat-shared-utils';
16
+
17
+ import SchemaBuilder from '../base/schema.builder.js';
18
+ import Project from './project.model.js';
19
+ import ProjectCollection from './project.collection.js';
20
+
21
+ /*
22
+ Schema Doc: https://electrodb.dev/en/modeling/schema/
23
+ Attribute Doc: https://electrodb.dev/en/modeling/attributes/
24
+ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
25
+ */
26
+
27
+ const schema = new SchemaBuilder(Project, ProjectCollection)
28
+ .addReference('belongs_to', 'Organization')
29
+ .addReference('has_many', 'Sites')
30
+ .addAttribute('projectName', {
31
+ type: 'string',
32
+ required: true,
33
+ validate: (value) => hasText(value),
34
+ })
35
+ .addAllIndex(['projectName']);
36
+
37
+ export default schema.build();
@@ -19,6 +19,7 @@ import type {
19
19
  LatestAudit,
20
20
  Opportunity,
21
21
  Organization,
22
+ Project,
22
23
  SiteCandidate,
23
24
  SiteEnrollment,
24
25
  SiteTopPage,
@@ -214,6 +215,11 @@ export interface Site extends BaseModel {
214
215
  getOpportunitiesByStatusAndUpdatedAt(status: string, updatedAt: string): Promise<Opportunity[]>;
215
216
  getOrganization(): Promise<Organization>;
216
217
  getOrganizationId(): string;
218
+ getProject(): Promise<Project>;
219
+ getProjectId(): string;
220
+ getIsPrimaryLocale(): boolean;
221
+ getLanguage(): string;
222
+ getRegion(): string;
217
223
  getSiteCandidates(): Promise<SiteCandidate[]>;
218
224
  getSiteEnrollments(): Promise<SiteEnrollment[]>;
219
225
  getSiteTopPages(): Promise<SiteTopPage[]>;
@@ -234,18 +240,27 @@ export interface Site extends BaseModel {
234
240
  setIsSandbox(isSandbox: boolean): Site;
235
241
  setIsLiveToggledAt(isLiveToggledAt: string): Site;
236
242
  setOrganizationId(organizationId: string): Site;
243
+ setProjectId(projectId: string): Site;
244
+ setIsPrimaryLocale(primaryLocale: boolean): Site;
245
+ setLanguage(language: string): Site;
246
+ setRegion(region: string): Site;
237
247
  toggleLive(): Site;
238
248
  }
239
249
 
240
- export interface SiteCollection extends BaseCollection<Organization> {
250
+ export interface SiteCollection extends BaseCollection<Site> {
241
251
  allByBaseURL(baseURL: string): Promise<Site[]>;
242
252
  allByDeliveryType(deliveryType: string): Promise<Site[]>;
243
253
  allByOrganizationId(organizationId: string): Promise<Site[]>;
254
+ allByProjectId(projectId: string): Promise<Site[]>;
255
+ allByProjectName(projectName: string): Promise<Site[]>;
256
+ allByOrganizationIdAndProjectId(organizationId: string, projectId: string): Promise<Site[]>;
257
+ allByOrganizationIdAndProjectName(organizationId: string, projectName: string): Promise<Site[]>;
244
258
  allSitesToAudit(): Promise<string[]>;
245
259
  allWithLatestAudit(auditType: string, order?: string, deliveryType?: string): Promise<Site[]>;
246
260
  findByBaseURL(baseURL: string): Promise<Site | null>;
247
261
  findByDeliveryType(deliveryType: string): Promise<Site | null>;
248
262
  findByOrganizationId(organizationId: string): Promise<Site | null>;
263
+ findByProjectId(projectId: string): Promise<Site | null>;
249
264
  findByPreviewURL(previewURL: string): Promise<Site | null>;
250
265
  findByExternalOwnerIdAndExternalSiteId(
251
266
  externalOwnerId: string, externalSiteId: string
@@ -102,6 +102,72 @@ class SiteCollection extends BaseCollection {
102
102
  throw new DataAccessError(`Unsupported preview URL: ${previewURL}`, this);
103
103
  }
104
104
  }
105
+
106
+ async allByProjectName(projectName) {
107
+ if (!hasText(projectName)) {
108
+ throw new DataAccessError('projectName is required', this);
109
+ }
110
+
111
+ const projectCollection = this.entityRegistry.getCollection('ProjectCollection');
112
+ const project = await projectCollection.findByProjectName(projectName);
113
+
114
+ if (!project) {
115
+ return [];
116
+ }
117
+ return this.allByProjectId(project.getId());
118
+ }
119
+
120
+ async allByOrganizationIdAndProjectId(organizationId, projectId) {
121
+ if (!hasText(organizationId)) {
122
+ throw new DataAccessError('organizationId is required', this);
123
+ }
124
+ if (!hasText(projectId)) {
125
+ throw new DataAccessError('projectId is required', this);
126
+ }
127
+
128
+ const organizationCollection = this.entityRegistry.getCollection('OrganizationCollection');
129
+ const organization = await organizationCollection.findById(organizationId);
130
+
131
+ if (!organization) {
132
+ return [];
133
+ }
134
+
135
+ const projectCollection = this.entityRegistry.getCollection('ProjectCollection');
136
+ const projects = await projectCollection.allByOrganizationId(organizationId);
137
+ const project = projects.find((p) => p.getId() === projectId);
138
+
139
+ if (!project) {
140
+ return [];
141
+ }
142
+
143
+ return this.allByProjectId(projectId);
144
+ }
145
+
146
+ async allByOrganizationIdAndProjectName(organizationId, projectName) {
147
+ if (!hasText(organizationId)) {
148
+ throw new DataAccessError('organizationId is required', this);
149
+ }
150
+ if (!hasText(projectName)) {
151
+ throw new DataAccessError('projectName is required', this);
152
+ }
153
+
154
+ const organizationCollection = this.entityRegistry.getCollection('OrganizationCollection');
155
+ const organization = await organizationCollection.findById(organizationId);
156
+
157
+ if (!organization) {
158
+ return [];
159
+ }
160
+
161
+ const projectCollection = this.entityRegistry.getCollection('ProjectCollection');
162
+ const projects = await projectCollection.allByOrganizationId(organizationId);
163
+ const project = projects.find((p) => p.getProjectName() === projectName);
164
+
165
+ if (!project) {
166
+ return [];
167
+ }
168
+
169
+ return this.allByProjectId(project.getId());
170
+ }
105
171
  }
106
172
 
107
173
  export default SiteCollection;
@@ -34,6 +34,8 @@ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
34
34
  const schema = new SchemaBuilder(Site, SiteCollection)
35
35
  // this will add an attribute 'organizationId' as well as an index 'byOrganizationId'
36
36
  .addReference('belongs_to', 'Organization')
37
+ // this will add an attribute 'projectId' as well as an index 'byProjectId'
38
+ .addReference('belongs_to', 'Project', ['updatedAt'], { required: false })
37
39
  // has_many references do not add attributes or indexes
38
40
  .addReference('has_many', 'Audits')
39
41
  .addReference('has_many', 'Experiments')
@@ -55,6 +57,20 @@ const schema = new SchemaBuilder(Site, SiteCollection)
55
57
  .addAttribute('name', {
56
58
  type: 'string',
57
59
  })
60
+ .addAttribute('isPrimaryLocale', {
61
+ type: 'boolean',
62
+ required: false,
63
+ })
64
+ .addAttribute('language', {
65
+ type: 'string',
66
+ required: false,
67
+ validate: (value) => !value || /^[a-z]{2}$/.test(value), // ISO 639-1 format
68
+ })
69
+ .addAttribute('region', {
70
+ type: 'string',
71
+ required: false,
72
+ validate: (value) => !value || /^[A-Z]{2}$/.test(value), // ISO 3166-1 alpha-2 format
73
+ })
58
74
  .addAttribute('config', {
59
75
  type: 'any',
60
76
  required: true,