@adobe/spacecat-shared-data-access 2.36.1 → 2.38.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.38.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.37.0...@adobe/spacecat-shared-data-access-v2.38.0) (2025-07-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * add pageTypes to store pattern matching for pageTypes ([#857](https://github.com/adobe/spacecat-shared/issues/857)) ([4081e8c](https://github.com/adobe/spacecat-shared/commit/4081e8cfd8571d43b9720c07caeb22ced77281d0))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v2.37.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.36.1...@adobe/spacecat-shared-data-access-v2.37.0) (2025-07-21)
9
+
10
+
11
+ ### Features
12
+
13
+ * added `Report` model, schema and collection implementation ([#855](https://github.com/adobe/spacecat-shared/issues/855)) ([4100a0e](https://github.com/adobe/spacecat-shared/commit/4100a0e557709d29dd590ff87c987d70b005f734))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v2.36.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.36.0...@adobe/spacecat-shared-data-access-v2.36.1) (2025-07-19)
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.36.1",
3
+ "version": "2.38.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -32,6 +32,7 @@ import SiteCollection from '../site/site.collection.js';
32
32
  import SiteTopPageCollection from '../site-top-page/site-top-page.collection.js';
33
33
  import SuggestionCollection from '../suggestion/suggestion.collection.js';
34
34
  import PageIntentCollection from '../page-intent/page-intent.collection.js';
35
+ import ReportCollection from '../report/report.collection.js';
35
36
 
36
37
  import ApiKeySchema from '../api-key/api-key.schema.js';
37
38
  import AsyncJobSchema from '../async-job/async-job.schema.js';
@@ -52,6 +53,7 @@ import SiteCandidateSchema from '../site-candidate/site-candidate.schema.js';
52
53
  import SiteTopPageSchema from '../site-top-page/site-top-page.schema.js';
53
54
  import SuggestionSchema from '../suggestion/suggestion.schema.js';
54
55
  import PageIntentSchema from '../page-intent/page-intent.schema.js';
56
+ import ReportSchema from '../report/report.schema.js';
55
57
 
56
58
  /**
57
59
  * EntityRegistry - A registry class responsible for managing entities, their schema and collection.
@@ -153,5 +155,6 @@ EntityRegistry.registerEntity(SiteCandidateSchema, SiteCandidateCollection);
153
155
  EntityRegistry.registerEntity(SiteTopPageSchema, SiteTopPageCollection);
154
156
  EntityRegistry.registerEntity(SuggestionSchema, SuggestionCollection);
155
157
  EntityRegistry.registerEntity(PageIntentSchema, PageIntentCollection);
158
+ EntityRegistry.registerEntity(ReportSchema, ReportCollection);
156
159
 
157
160
  export default EntityRegistry;
@@ -28,3 +28,4 @@ export type * from './site';
28
28
  export type * from './site-candidate';
29
29
  export type * from './site-top-page';
30
30
  export type * from './suggestion';
31
+ export type * from './report';
@@ -30,3 +30,4 @@ export * from './site-top-page/index.js';
30
30
  export * from './site/index.js';
31
31
  export * from './suggestion/index.js';
32
32
  export * from './page-intent/index.js';
33
+ export * from './report/index.js';
@@ -28,7 +28,6 @@ export interface PageIntent extends BaseModel {
28
28
  export interface PageIntentCollection extends BaseCollection<PageIntent> {
29
29
  allBySiteId(siteId: string): Promise<PageIntent[]>;
30
30
  findBySiteId(siteId: string): Promise<PageIntent | null>;
31
-
32
31
  allByUrl(url: string): Promise<PageIntent[]>;
33
32
  findByUrl(url: string): Promise<PageIntent | null>;
34
33
  }
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright 2025 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 { BaseModel, BaseCollection, Site } from '../index';
14
+
15
+ export interface Report extends BaseModel {
16
+ getReportType(): string;
17
+ getReportPeriod(): { startDate: string; endDate: string };
18
+ getComparisonPeriod(): { startDate: string; endDate: string };
19
+ getStoragePath(): string;
20
+ getSite(): Promise<Site>;
21
+ setReportType(reportType: string): Report;
22
+ setReportPeriod(period: { startDate: string; endDate: string }): Report;
23
+ setComparisonPeriod(period: { startDate: string; endDate: string }): Report;
24
+ setStoragePath(path: string): Report;
25
+ }
26
+
27
+ export interface ReportCollection extends BaseCollection<Report> {
28
+ // Add collection-specific methods here if needed
29
+ allBySiteId(siteId: string): Promise<Report[]>;
30
+ findBySiteId(siteId: string): Promise<Report | null>;
31
+ allByReportType(reportType: string): Promise<Report[]>;
32
+ findByReportType(reportType: string): Promise<Report | null>;
33
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2025 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 Report from './report.model.js';
14
+ import ReportCollection from './report.collection.js';
15
+
16
+ export {
17
+ Report,
18
+ ReportCollection,
19
+ };
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright 2025 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
+ * ReportCollection — A collection class responsible for managing Report entities.
17
+ * Extends the ReportCollection to provide specific methods for interacting with Report records.
18
+ *
19
+ * @class ReportCollection
20
+ * @extends BaseCollection
21
+ */
22
+ class ReportCollection extends BaseCollection {
23
+ async create(item) {
24
+ const report = await super.create(item, { upsert: true });
25
+
26
+ // If storagePath is empty string (default value), compute it automatically
27
+ if (report.getStoragePath() === '') {
28
+ const storagePath = `/reports/${item.siteId}/${item.reportType}/${report.getId()}/`;
29
+ report.setStoragePath(storagePath);
30
+ await report.save();
31
+ }
32
+
33
+ return report;
34
+ }
35
+ }
36
+
37
+ export default ReportCollection;
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright 2025 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
+ class Report extends BaseModel {
16
+
17
+ }
18
+
19
+ export default Report;
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Copyright 2025 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 { isNonEmptyObject, isString } from '@adobe/spacecat-shared-utils';
16
+ import SchemaBuilder from '../base/schema.builder.js';
17
+ import Report from './report.model.js';
18
+ import ReportCollection from './report.collection.js';
19
+
20
+ /*
21
+ Schema Doc: https://electrodb.dev/en/modeling/schema/
22
+ Attribute Doc: https://electrodb.dev/en/modeling/attributes/
23
+ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
24
+ */
25
+
26
+ const schema = new SchemaBuilder(Report, ReportCollection)
27
+ .addReference('belongs_to', 'Site')
28
+ .addAllIndex(['reportType'])
29
+ .addAttribute('reportType', {
30
+ type: 'string',
31
+ required: true,
32
+ validate: (value) => isString(value) && value.length > 0,
33
+ })
34
+ .addAttribute('reportPeriod', {
35
+ type: 'any',
36
+ required: true,
37
+ validate: (value) => isNonEmptyObject(value)
38
+ && isString(value.startDate) && isString(value.endDate),
39
+ })
40
+ .addAttribute('comparisonPeriod', {
41
+ type: 'any',
42
+ required: true,
43
+ validate: (value) => isNonEmptyObject(value)
44
+ && isString(value.startDate) && isString(value.endDate),
45
+ })
46
+ .addAttribute('storagePath', {
47
+ type: 'string',
48
+ required: false,
49
+ default: () => '',
50
+ validate: (value) => !value || (isString(value) && value.length >= 0),
51
+ });
52
+
53
+ export default schema.build();
@@ -117,6 +117,21 @@ const schema = new SchemaBuilder(Site, SiteCollection)
117
117
  watch: ['authoringType', 'hlxConfig', 'deliveryConfig'],
118
118
  set: (_, attrs) => computeExternalIds(attrs, Site.AUTHORING_TYPES).externalSiteId,
119
119
  })
120
+ .addAttribute('pageTypes', {
121
+ type: 'list',
122
+ required: false,
123
+ items: {
124
+ type: 'map',
125
+ required: true,
126
+ properties: {
127
+ name: { type: 'string', required: true },
128
+ pattern: {
129
+ type: 'string',
130
+ required: true,
131
+ },
132
+ },
133
+ },
134
+ })
120
135
  .addAllIndex(['baseURL'])
121
136
  .addIndex(
122
137
  { composite: ['deliveryType'] },