@adobe/spacecat-shared-data-access 2.40.2 → 2.42.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.42.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.41.0...@adobe/spacecat-shared-data-access-v2.42.0) (2025-07-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * added `status` field in reports ([#883](https://github.com/adobe/spacecat-shared/issues/883)) ([f6e9fcd](https://github.com/adobe/spacecat-shared/commit/f6e9fcd1e8e5eabb731c4cdbd89654fc725c9837))
7
+
8
+ # [@adobe/spacecat-shared-data-access-v2.41.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.40.2...@adobe/spacecat-shared-data-access-v2.41.0) (2025-07-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * add top form model ([#863](https://github.com/adobe/spacecat-shared/issues/863)) ([66138ce](https://github.com/adobe/spacecat-shared/commit/66138ced4a0b0e3c68bf0aaec02b7adaafb0503d))
14
+
1
15
  # [@adobe/spacecat-shared-data-access-v2.40.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v2.40.1...@adobe/spacecat-shared-data-access-v2.40.2) (2025-07-28)
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.40.2",
3
+ "version": "2.42.0",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -29,6 +29,7 @@ import ScrapeJobCollection from '../scrape-job/scrape-job.collection.js';
29
29
  import ScrapeUrlCollection from '../scrape-url/scrape-url.collection.js';
30
30
  import SiteCandidateCollection from '../site-candidate/site-candidate.collection.js';
31
31
  import SiteCollection from '../site/site.collection.js';
32
+ import SiteTopFormCollection from '../site-top-form/site-top-form.collection.js';
32
33
  import SiteTopPageCollection from '../site-top-page/site-top-page.collection.js';
33
34
  import SuggestionCollection from '../suggestion/suggestion.collection.js';
34
35
  import PageIntentCollection from '../page-intent/page-intent.collection.js';
@@ -50,6 +51,7 @@ import ScrapeJobSchema from '../scrape-job/scrape-job.schema.js';
50
51
  import ScrapeUrlSchema from '../scrape-url/scrape-url.schema.js';
51
52
  import SiteSchema from '../site/site.schema.js';
52
53
  import SiteCandidateSchema from '../site-candidate/site-candidate.schema.js';
54
+ import SiteTopFormSchema from '../site-top-form/site-top-form.schema.js';
53
55
  import SiteTopPageSchema from '../site-top-page/site-top-page.schema.js';
54
56
  import SuggestionSchema from '../suggestion/suggestion.schema.js';
55
57
  import PageIntentSchema from '../page-intent/page-intent.schema.js';
@@ -152,6 +154,7 @@ EntityRegistry.registerEntity(ScrapeJobSchema, ScrapeJobCollection);
152
154
  EntityRegistry.registerEntity(ScrapeUrlSchema, ScrapeUrlCollection);
153
155
  EntityRegistry.registerEntity(SiteSchema, SiteCollection);
154
156
  EntityRegistry.registerEntity(SiteCandidateSchema, SiteCandidateCollection);
157
+ EntityRegistry.registerEntity(SiteTopFormSchema, SiteTopFormCollection);
155
158
  EntityRegistry.registerEntity(SiteTopPageSchema, SiteTopPageCollection);
156
159
  EntityRegistry.registerEntity(SuggestionSchema, SuggestionCollection);
157
160
  EntityRegistry.registerEntity(PageIntentSchema, PageIntentCollection);
@@ -26,6 +26,7 @@ export type * from './scrape-job';
26
26
  export type * from './scrape-url';
27
27
  export type * from './site';
28
28
  export type * from './site-candidate';
29
+ export type * from './site-top-form';
29
30
  export type * from './site-top-page';
30
31
  export type * from './suggestion';
31
32
  export type * from './report';
@@ -26,6 +26,7 @@ export * from './organization/index.js';
26
26
  export * from './scrape-job/index.js';
27
27
  export * from './scrape-url/index.js';
28
28
  export * from './site-candidate/index.js';
29
+ export * from './site-top-form/index.js';
29
30
  export * from './site-top-page/index.js';
30
31
  export * from './site/index.js';
31
32
  export * from './suggestion/index.js';
@@ -48,6 +48,11 @@ const schema = new SchemaBuilder(Report, ReportCollection)
48
48
  required: false,
49
49
  default: () => '',
50
50
  validate: (value) => !value || (isString(value) && value.length >= 0),
51
+ })
52
+ .addAttribute('status', {
53
+ type: ['processing', 'success', 'failed'],
54
+ required: true,
55
+ default: 'processing',
51
56
  });
52
57
 
53
58
  export default schema.build();
@@ -25,6 +25,7 @@ export const IMPORT_TYPES = {
25
25
  CWV_DAILY: 'cwv-daily',
26
26
  CWV_WEEKLY: 'cwv-weekly',
27
27
  TRAFFIC_ANALYSIS: 'traffic-analysis',
28
+ TOP_FORMS: 'top-forms',
28
29
  };
29
30
 
30
31
  export const IMPORT_DESTINATIONS = {
@@ -138,6 +139,12 @@ export const IMPORT_TYPE_SCHEMAS = {
138
139
  week: Joi.number().integer().optional(),
139
140
  ...IMPORT_BASE_KEYS,
140
141
  }),
142
+ [IMPORT_TYPES.TOP_FORMS]: Joi.object({
143
+ type: Joi.string().valid(IMPORT_TYPES.TOP_FORMS).required(),
144
+ ...IMPORT_BASE_KEYS,
145
+ limit: Joi.number().integer().min(1).max(2000)
146
+ .optional(),
147
+ }),
141
148
  };
142
149
 
143
150
  export const DEFAULT_IMPORT_CONFIGS = {
@@ -208,6 +215,12 @@ export const DEFAULT_IMPORT_CONFIGS = {
208
215
  sources: ['rum'],
209
216
  enabled: true,
210
217
  },
218
+ 'top-forms': {
219
+ type: 'top-forms',
220
+ destinations: ['default'],
221
+ sources: ['rum'],
222
+ enabled: true,
223
+ },
211
224
  };
212
225
 
213
226
  export const configSchema = Joi.object({
@@ -36,6 +36,7 @@ export type IMPORT_TYPES = {
36
36
  readonly ORGANIC_KEYWORDS: 'organic-keywords';
37
37
  readonly ORGANIC_TRAFFIC: 'organic-traffic';
38
38
  readonly TOP_PAGES: 'top-pages';
39
+ readonly TOP_FORMS: 'top-forms';
39
40
  };
40
41
 
41
42
  export type IMPORT_DESTINATIONS = {
@@ -47,7 +48,7 @@ export type IMPORT_SOURCES = {
47
48
  readonly GSC: 'google';
48
49
  };
49
50
 
50
- export type ImportType = 'organic-keywords' | 'organic-traffic' | 'top-pages';
51
+ export type ImportType = 'organic-keywords' | 'organic-traffic' | 'top-pages' | 'top-forms';
51
52
  export type ImportDestination = 'default';
52
53
  export type ImportSource = 'ahrefs' | 'google';
53
54
 
@@ -42,6 +42,7 @@ const schema = new SchemaBuilder(Site, SiteCollection)
42
42
  .addReference('has_one', 'LatestAudit', ['auditType'], { required: false })
43
43
  .addReference('has_many', 'Opportunities')
44
44
  .addReference('has_many', 'SiteCandidates')
45
+ .addReference('has_many', 'SiteTopForms')
45
46
  .addReference('has_many', 'SiteTopPages')
46
47
  .addReference('has_many', 'PageIntents')
47
48
  .addAttribute('baseURL', {
@@ -0,0 +1,39 @@
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 { BaseCollection, BaseModel, Site } from '../index';
14
+
15
+ export interface SiteTopForm extends BaseModel {
16
+ getFormSource(): string;
17
+ getImportedAt(): string;
18
+ getSite(): Promise<Site>;
19
+ getSiteId(): string;
20
+ getSource(): string;
21
+ getTraffic(): number | undefined;
22
+ getUrl(): string;
23
+ setFormSource(formSource: string): SiteTopForm;
24
+ setImportedAt(importedAt: string): SiteTopForm;
25
+ setSiteId(siteId: string): SiteTopForm;
26
+ setSource(source: string): SiteTopForm;
27
+ setTraffic(traffic: number): SiteTopForm;
28
+ setUrl(url: string): SiteTopForm;
29
+ }
30
+
31
+ export interface SiteTopFormCollection extends BaseCollection<SiteTopForm> {
32
+ allBySiteId(siteId: string): Promise<SiteTopForm[]>;
33
+ allBySiteIdAndSource(siteId: string, source: string): Promise<SiteTopForm[]>;
34
+ findBySiteId(siteId: string): Promise<SiteTopForm | null>;
35
+ findBySiteIdAndSource(siteId: string, source: string): Promise<SiteTopForm | null>;
36
+ findByUrlAndFormSource(url: string, formSource: string): Promise<SiteTopForm | null>;
37
+ removeByUrlAndFormSource(url: string, formSource: string): Promise<void>;
38
+ removeForSiteId(siteId: string, source: string): Promise<void>;
39
+ }
@@ -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 SiteTopForm from './site-top-form.model.js';
14
+ import SiteTopFormCollection from './site-top-form.collection.js';
15
+
16
+ export {
17
+ SiteTopForm,
18
+ SiteTopFormCollection,
19
+ };
@@ -0,0 +1,61 @@
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 { hasText, isNonEmptyArray } from '@adobe/spacecat-shared-utils';
14
+
15
+ import BaseCollection from '../base/base.collection.js';
16
+
17
+ /**
18
+ * SiteTopFormCollection - A collection class responsible for managing SiteTopForm entities.
19
+ * Extends the BaseCollection to provide specific methods for interacting with SiteTopForm records.
20
+ *
21
+ * @class SiteTopFormCollection
22
+ * @extends BaseCollection
23
+ */
24
+ class SiteTopFormCollection extends BaseCollection {
25
+ async removeForSiteId(siteId, source) {
26
+ if (!hasText(siteId)) {
27
+ throw new Error('SiteId is required');
28
+ }
29
+
30
+ let topFormsToRemove;
31
+
32
+ if (hasText(source)) {
33
+ topFormsToRemove = await this.allBySiteIdAndSource(siteId, source);
34
+ } else {
35
+ topFormsToRemove = await this.allBySiteId(siteId);
36
+ }
37
+
38
+ const topFormIdsToRemove = topFormsToRemove.map((topForm) => topForm.getId());
39
+
40
+ if (isNonEmptyArray(topFormIdsToRemove)) {
41
+ await this.removeByIds(topFormIdsToRemove);
42
+ }
43
+ }
44
+
45
+ async removeByUrlAndFormSource(url, formSource) {
46
+ if (!hasText(url)) {
47
+ throw new Error('URL is required');
48
+ }
49
+ if (!hasText(formSource)) {
50
+ throw new Error('FormSource is required');
51
+ }
52
+
53
+ const formToRemove = await this.findByUrlAndFormSource(url, formSource);
54
+
55
+ if (formToRemove) {
56
+ await this.removeByIds([formToRemove.getId()]);
57
+ }
58
+ }
59
+ }
60
+
61
+ export default SiteTopFormCollection;
@@ -0,0 +1,26 @@
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
+ /**
16
+ * SiteTopForm - A class representing a SiteTopForm entity.
17
+ * Provides methods to access and manipulate SiteTopForm-specific data.
18
+ *
19
+ * @class SiteTopForm
20
+ * @extends BaseModel
21
+ */
22
+ class SiteTopForm extends BaseModel {
23
+ // add your custom methods or overrides here
24
+ }
25
+
26
+ export default SiteTopForm;
@@ -0,0 +1,66 @@
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 { isInteger, isIsoDate, isValidUrl } from '@adobe/spacecat-shared-utils';
16
+
17
+ import { validate as uuidValidate } from 'uuid';
18
+
19
+ import SchemaBuilder from '../base/schema.builder.js';
20
+ import SiteTopForm from './site-top-form.model.js';
21
+ import SiteTopFormCollection from './site-top-form.collection.js';
22
+
23
+ /*
24
+ Schema Doc: https://electrodb.dev/en/modeling/schema/
25
+ Attribute Doc: https://electrodb.dev/en/modeling/attributes/
26
+ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
27
+ */
28
+
29
+ const schema = new SchemaBuilder(SiteTopForm, SiteTopFormCollection)
30
+ .addReference('belongs_to', 'Site', ['source', 'traffic'])
31
+ .addAttribute('siteId', {
32
+ type: 'string',
33
+ required: true,
34
+ validate: (value) => uuidValidate(value),
35
+ })
36
+ .addAttribute('url', {
37
+ type: 'string',
38
+ required: true,
39
+ validate: (value) => isValidUrl(value),
40
+ })
41
+ .addAttribute('formSource', {
42
+ type: 'string',
43
+ required: true,
44
+ })
45
+ .addAttribute('traffic', {
46
+ type: 'number',
47
+ required: false,
48
+ default: 0,
49
+ validate: (value) => isInteger(value),
50
+ })
51
+ .addAttribute('source', {
52
+ type: 'string',
53
+ required: true,
54
+ })
55
+ .addAttribute('importedAt', {
56
+ type: 'string',
57
+ required: true,
58
+ default: () => new Date().toISOString(),
59
+ validate: (value) => isIsoDate(value),
60
+ })
61
+ .addIndex(
62
+ { composite: ['url', 'formSource'] },
63
+ { composite: ['traffic'] },
64
+ );
65
+
66
+ export default schema.build();