@adobe/spacecat-shared-data-access 1.59.2 → 1.60.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 (102) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +2 -2
  3. package/src/models/site/config.js +1 -1
  4. package/src/service/audits/accessPatterns.js +7 -7
  5. package/src/service/experiments/accessPatterns.js +2 -2
  6. package/src/service/import-job/accessPatterns.js +1 -1
  7. package/src/service/import-url/accessPatterns.js +2 -2
  8. package/src/service/index.js +10 -18
  9. package/src/service/key-events/accessPatterns.js +3 -3
  10. package/src/service/organizations/accessPatterns.js +3 -3
  11. package/src/service/site-candidates/accessPatterns.js +1 -1
  12. package/src/service/sites/accessPatterns.js +11 -11
  13. package/src/v2/models/api-key/api-key.collection.js +26 -0
  14. package/src/v2/models/api-key/api-key.model.js +59 -0
  15. package/src/v2/models/api-key/api-key.schema.js +82 -0
  16. package/src/v2/models/api-key/index.d.ts +37 -0
  17. package/src/v2/models/api-key/index.js +19 -0
  18. package/src/v2/models/audit/audit.collection.js +26 -0
  19. package/src/v2/models/audit/audit.model.js +89 -0
  20. package/src/v2/models/audit/audit.schema.js +66 -0
  21. package/src/v2/models/audit/index.d.ts +40 -0
  22. package/src/v2/models/audit/index.js +19 -0
  23. package/src/v2/models/base/base.collection.js +450 -0
  24. package/src/v2/models/{base.model.js → base/base.model.js} +109 -89
  25. package/src/v2/models/base/constants.js +17 -0
  26. package/src/v2/models/base/entity.registry.js +137 -0
  27. package/src/v2/models/base/index.d.ts +83 -0
  28. package/src/v2/models/base/index.js +27 -0
  29. package/src/v2/models/base/reference.js +159 -0
  30. package/src/v2/models/base/schema.builder.js +420 -0
  31. package/src/v2/models/base/schema.js +283 -0
  32. package/src/v2/models/configuration/configuration.collection.js +39 -0
  33. package/src/v2/models/configuration/configuration.model.js +160 -0
  34. package/src/v2/models/configuration/configuration.schema.js +103 -0
  35. package/src/v2/models/configuration/index.d.ts +111 -0
  36. package/src/v2/models/configuration/index.js +19 -0
  37. package/src/v2/models/experiment/experiment.collection.js +26 -0
  38. package/src/v2/models/experiment/experiment.model.js +28 -0
  39. package/src/v2/models/experiment/experiment.schema.js +70 -0
  40. package/src/v2/models/experiment/index.d.ts +49 -0
  41. package/src/v2/models/experiment/index.js +19 -0
  42. package/src/v2/models/import-job/import-job.collection.js +45 -0
  43. package/src/v2/models/import-job/import-job.model.js +55 -0
  44. package/src/v2/models/import-job/import-job.schema.js +152 -0
  45. package/src/v2/models/import-job/index.d.ts +51 -0
  46. package/src/v2/models/import-job/index.js +19 -0
  47. package/src/v2/models/import-url/import-url.collection.js +26 -0
  48. package/src/v2/models/import-url/import-url.model.js +28 -0
  49. package/src/v2/models/import-url/import-url.schema.js +59 -0
  50. package/src/v2/models/import-url/index.d.ts +35 -0
  51. package/src/v2/models/import-url/index.js +19 -0
  52. package/src/v2/models/index.d.ts +11 -99
  53. package/src/v2/models/index.js +14 -15
  54. package/src/v2/models/key-event/index.d.ts +28 -0
  55. package/src/v2/models/key-event/index.js +19 -0
  56. package/src/v2/models/key-event/key-event.collection.js +26 -0
  57. package/src/v2/models/key-event/key-event.model.js +37 -0
  58. package/src/v2/models/key-event/key-event.schema.js +45 -0
  59. package/src/v2/models/opportunity/index.d.ts +46 -0
  60. package/src/v2/models/opportunity/index.js +19 -0
  61. package/src/v2/models/opportunity/opportunity.collection.js +26 -0
  62. package/src/v2/models/{opportunity.model.js → opportunity/opportunity.model.js} +15 -2
  63. package/src/v2/models/opportunity/opportunity.schema.js +69 -0
  64. package/src/v2/models/organization/index.d.ts +28 -0
  65. package/src/v2/models/organization/index.js +19 -0
  66. package/src/v2/models/organization/organization.collection.js +26 -0
  67. package/src/v2/models/organization/organization.model.js +31 -0
  68. package/src/v2/models/organization/organization.schema.js +51 -0
  69. package/src/v2/models/site/index.d.ts +43 -0
  70. package/src/v2/models/site/index.js +20 -0
  71. package/src/v2/models/site/site.collection.js +28 -0
  72. package/src/v2/models/site/site.model.js +47 -0
  73. package/src/v2/models/site/site.schema.js +91 -0
  74. package/src/v2/models/site-candidate/index.d.ts +38 -0
  75. package/src/v2/models/site-candidate/index.js +19 -0
  76. package/src/v2/models/site-candidate/site-candidate.collection.js +27 -0
  77. package/src/v2/models/site-candidate/site-candidate.model.js +41 -0
  78. package/src/v2/models/site-candidate/site-candidate.schema.js +59 -0
  79. package/src/v2/models/site-top-page/index.d.ts +35 -0
  80. package/src/v2/models/site-top-page/index.js +19 -0
  81. package/src/v2/models/site-top-page/site-top-page.collection.js +44 -0
  82. package/src/v2/models/site-top-page/site-top-page.model.js +28 -0
  83. package/src/v2/models/site-top-page/site-top-page.schema.js +65 -0
  84. package/src/v2/models/suggestion/index.d.ts +34 -0
  85. package/src/v2/models/suggestion/index.js +19 -0
  86. package/src/v2/models/suggestion/suggestion.collection.js +55 -0
  87. package/src/v2/models/{suggestion.model.js → suggestion/suggestion.model.js} +16 -1
  88. package/src/v2/models/suggestion/suggestion.schema.js +53 -0
  89. package/src/v2/readme.md +201 -256
  90. package/src/v2/util/accessor.utils.js +158 -0
  91. package/src/v2/util/guards.d.ts +7 -0
  92. package/src/v2/util/guards.js +21 -4
  93. package/src/v2/util/index.js +1 -0
  94. package/src/v2/util/patcher.js +54 -25
  95. package/src/v2/util/util.js +84 -0
  96. package/src/v2/models/base.collection.js +0 -275
  97. package/src/v2/models/model.factory.js +0 -74
  98. package/src/v2/models/opportunity.collection.js +0 -74
  99. package/src/v2/models/suggestion.collection.js +0 -104
  100. package/src/v2/schema/opportunity.schema.js +0 -159
  101. package/src/v2/schema/suggestion.schema.js +0 -132
  102. package/src/v2/util/reference.js +0 -41
@@ -0,0 +1,51 @@
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 { isNonEmptyObject } from '@adobe/spacecat-shared-utils';
16
+
17
+ import { DEFAULT_CONFIG, validateConfiguration } from '../../../models/site/config.js';
18
+ import SchemaBuilder from '../base/schema.builder.js';
19
+ import Organization from './organization.model.js';
20
+ import OrganizationCollection from './organization.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(Organization, OrganizationCollection)
29
+ // this will add an attribute 'organizationId' as well as an index 'byOrganizationId'
30
+ .addReference('has_many', 'Sites')
31
+ .addAttribute('config', {
32
+ type: 'any',
33
+ required: true,
34
+ default: DEFAULT_CONFIG,
35
+ validate: (value) => isNonEmptyObject(validateConfiguration(value)),
36
+ })
37
+ .addAttribute('name', {
38
+ type: 'string',
39
+ required: true,
40
+ })
41
+ .addAttribute('imsOrgId', {
42
+ type: 'string',
43
+ default: 'default',
44
+ })
45
+ .addAttribute('fulfillableItems', {
46
+ type: 'any',
47
+ validate: (value) => !value || isNonEmptyObject(value),
48
+ })
49
+ .addAllIndexWithComposite('imsOrgId');
50
+
51
+ export default schema.build();
@@ -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, Organization,
15
+ } from '../index';
16
+
17
+ export interface Site extends BaseModel {
18
+ getAudits(): Promise<Audit>;
19
+ getBaseURL(): string;
20
+ getConfig(): object;
21
+ getDeliveryType(): string;
22
+ getFulfillableItems(): object;
23
+ getGitHubURL(): string;
24
+ getHlxConfig(): object;
25
+ getIsLive(): boolean;
26
+ getIsLiveToggledAt(): string;
27
+ getOrganization(): Promise<Organization>;
28
+ getOrganizationId(): string;
29
+ setConfig(config: object): Site;
30
+ setDeliveryType(deliveryType: string): Site;
31
+ setFulfillableItems(fulfillableItems: object): Site;
32
+ setGitHubURL(gitHubURL: string): Site;
33
+ setHlxConfig(hlxConfig: object): Site;
34
+ setIsLive(isLive: boolean): Site;
35
+ setOrganizationId(organizationId: string): Site;
36
+ toggleLive(): Site;
37
+ }
38
+
39
+ export interface SiteCollection extends BaseCollection<Organization> {
40
+ findByBaseURL(siteId: string): Promise<Site>;
41
+ allByDeliveryType(siteId: string): Promise<Site[]>;
42
+ allByOrganizationId(siteId: string): Promise<Site[]>;
43
+ }
@@ -0,0 +1,20 @@
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
+ // eslint-disable-next-line import/no-cycle
14
+ import Site from './site.model.js';
15
+ import SiteCollection from './site.collection.js';
16
+
17
+ export {
18
+ Site,
19
+ SiteCollection,
20
+ };
@@ -0,0 +1,28 @@
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
+ * SiteCollection - A collection class responsible for managing Site entities.
17
+ * Extends the BaseCollection to provide specific methods for interacting with Site records.
18
+ *
19
+ * @class SiteCollection
20
+ * @extends BaseCollection
21
+ */
22
+ class SiteCollection extends BaseCollection {
23
+ async allSitesToAudit() {
24
+ return (await this.all({ attributes: ['siteId'] })).map((site) => site.getId());
25
+ }
26
+ }
27
+
28
+ export default SiteCollection;
@@ -0,0 +1,47 @@
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 { Config } from '../../../models/site/config.js';
14
+ import BaseModel from '../base/base.model.js';
15
+
16
+ export const DELIVERY_TYPES = {
17
+ AEM_CS: 'aem_cs',
18
+ AEM_EDGE: 'aem_edge',
19
+ OTHER: 'other',
20
+ };
21
+
22
+ export const DEFAULT_DELIVERY_TYPE = DELIVERY_TYPES.AEM_EDGE;
23
+
24
+ /**
25
+ * A class representing a Site entity. Provides methods to access and manipulate Site-specific data.
26
+ * @class Site
27
+ * @extends BaseModel
28
+ */
29
+ class Site extends BaseModel {
30
+ getConfig() {
31
+ return Config(this.record.config);
32
+ }
33
+
34
+ async getLatestAuditByType(auditType) {
35
+ const collection = this.entityRegistry.getCollection('AuditCollection');
36
+
37
+ return collection.findByIndexKeys({ siteId: this.getId(), auditType });
38
+ }
39
+
40
+ async toggleLive() {
41
+ const newIsLive = !this.getIsLive();
42
+ this.setIsLive(newIsLive);
43
+ return this;
44
+ }
45
+ }
46
+
47
+ export default Site;
@@ -0,0 +1,91 @@
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 {
16
+ isIsoDate,
17
+ isNonEmptyObject,
18
+ isObject,
19
+ isValidUrl,
20
+ } from '@adobe/spacecat-shared-utils';
21
+
22
+ import { Config, DEFAULT_CONFIG, validateConfiguration } from '../../../models/site/config.js';
23
+ import SchemaBuilder from '../base/schema.builder.js';
24
+
25
+ import Site, {
26
+ DEFAULT_DELIVERY_TYPE,
27
+ DELIVERY_TYPES,
28
+ } from './site.model.js';
29
+ import SiteCollection from './site.collection.js';
30
+
31
+ /*
32
+ Schema Doc: https://electrodb.dev/en/modeling/schema/
33
+ Attribute Doc: https://electrodb.dev/en/modeling/attributes/
34
+ Indexes Doc: https://electrodb.dev/en/modeling/indexes/
35
+ */
36
+
37
+ const schema = new SchemaBuilder(Site, SiteCollection)
38
+ // this will add an attribute 'organizationId' as well as an index 'byOrganizationId'
39
+ .addReference('belongs_to', 'Organization')
40
+ // has_many references do not add attributes or indexes
41
+ .addReference('has_many', 'Audits')
42
+ .addReference('has_many', 'Experiments')
43
+ .addReference('has_many', 'KeyEvents')
44
+ .addReference('has_many', 'Opportunities')
45
+ .addReference('has_many', 'SiteCandidates')
46
+ .addReference('has_many', 'SiteTopPages')
47
+ .addAttribute('baseURL', {
48
+ type: 'string',
49
+ required: true,
50
+ validate: (value) => isValidUrl(value),
51
+ })
52
+ .addAttribute('config', {
53
+ type: 'any',
54
+ required: true,
55
+ default: DEFAULT_CONFIG,
56
+ validate: (value) => isNonEmptyObject(validateConfiguration(value)),
57
+ get: (value) => Config(value),
58
+ })
59
+ .addAttribute('deliveryType', {
60
+ type: Object.values(DELIVERY_TYPES),
61
+ default: DEFAULT_DELIVERY_TYPE,
62
+ required: true,
63
+ })
64
+ .addAttribute('gitHubURL', {
65
+ type: 'string',
66
+ validate: (value) => !value || isValidUrl(value),
67
+ })
68
+ .addAttribute('hlxConfig', {
69
+ type: 'any',
70
+ default: {},
71
+ validate: (value) => isObject(value),
72
+ })
73
+ .addAttribute('isLive', {
74
+ type: 'boolean',
75
+ required: true,
76
+ default: false,
77
+ })
78
+ .addAttribute('isLiveToggledAt', {
79
+ type: 'string',
80
+ watch: ['isLive'],
81
+ set: () => new Date().toISOString(),
82
+ validate: (value) => !value || isIsoDate(value),
83
+ })
84
+ .addAllIndexWithComposite('baseURL')
85
+ .addIndex(
86
+ 'byDeliveryType',
87
+ { composite: ['deliveryType'] },
88
+ { composite: ['updatedAt'] },
89
+ );
90
+
91
+ export default schema.build();
@@ -0,0 +1,38 @@
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 { BaseCollection, BaseModel } from '../index';
14
+
15
+ export interface SiteCandidate extends BaseModel {
16
+ getBaseURL(): string;
17
+ getHlxConfig(): object;
18
+ getSite(): object;
19
+ getSiteId(): string;
20
+ getSource(): string;
21
+ getStatus(): string;
22
+ getUpdatedBy(): string;
23
+ setBaseURL(baseURL: string): SiteCandidate;
24
+ setHlxConfig(hlxConfig: object): SiteCandidate;
25
+ setSiteId(siteId: string): SiteCandidate;
26
+ setSource(source: string): SiteCandidate;
27
+ setStatus(status: string): SiteCandidate;
28
+ setUpdatedBy(updatedBy: string): SiteCandidate;
29
+ }
30
+
31
+ export interface SiteCandidateCollection extends BaseCollection<SiteCandidate> {
32
+ allBySiteId(siteId: string): Promise<SiteCandidate[]>;
33
+ allBySiteIdAndSiteCandidateIdAndUrl(
34
+ siteId: string,
35
+ siteCandidateId: string,
36
+ url: string,
37
+ ): Promise<SiteCandidate[]>;
38
+ }
@@ -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 SiteCandidate from './site-candidate.model.js';
14
+ import SiteCandidateCollection from './site-candidate.collection.js';
15
+
16
+ export {
17
+ SiteCandidate,
18
+ SiteCandidateCollection,
19
+ };
@@ -0,0 +1,27 @@
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
+ * SiteCandidateCollection - A collection class responsible for managing SiteCandidate entities.
17
+ * Extends the BaseCollection to provide specific methods for interacting with
18
+ * SiteCandidate records.
19
+ *
20
+ * @class SiteCandidateCollection
21
+ * @extends BaseCollection
22
+ */
23
+ class SiteCandidateCollection extends BaseCollection {
24
+ // add custom methods here
25
+ }
26
+
27
+ export default SiteCandidateCollection;
@@ -0,0 +1,41 @@
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
+ export const DEFAULT_UPDATED_BY = 'spacecat';
16
+
17
+ export const SITE_CANDIDATE_SOURCES = {
18
+ SPACECAT_SLACK_BOT: 'SPACECAT_SLACK_BOT',
19
+ RUM: 'RUM',
20
+ CDN: 'CDN',
21
+ };
22
+
23
+ export const SITE_CANDIDATE_STATUS = {
24
+ PENDING: 'PENDING', // site candidate notification sent and waiting for human input
25
+ IGNORED: 'IGNORED', // site candidate discarded: not to be added to star catalogue
26
+ APPROVED: 'APPROVED', // site candidate is added to star catalogue
27
+ ERROR: 'ERROR', // site candidate is discovered
28
+ };
29
+
30
+ /**
31
+ * SiteCandidate - A class representing an SiteCandidate entity.
32
+ * Provides methods to access and manipulate SiteCandidate-specific data.
33
+ *
34
+ * @class SiteCandidate
35
+ * @extends BaseModel
36
+ */
37
+ class SiteCandidate extends BaseModel {
38
+ // add your custom methods or overrides here
39
+ }
40
+
41
+ export default SiteCandidate;
@@ -0,0 +1,59 @@
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 { isObject, 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 SiteCandidate, { SITE_CANDIDATE_SOURCES, SITE_CANDIDATE_STATUS } from './site-candidate.model.js';
21
+ import SiteCandidateCollection from './site-candidate.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(SiteCandidate, SiteCandidateCollection)
30
+ .addReference('belongs_to', 'Site')
31
+ .addAttribute('siteId', {
32
+ type: 'string',
33
+ validate: (value) => !value || uuidValidate(value),
34
+ })
35
+ .addAttribute('baseURL', {
36
+ type: 'string',
37
+ required: true,
38
+ validate: (value) => isValidUrl(value),
39
+ })
40
+ .addAttribute('hlxConfig', {
41
+ type: 'any',
42
+ required: true,
43
+ default: {},
44
+ validate: (value) => isObject(value),
45
+ })
46
+ .addAttribute('source', {
47
+ type: Object.values(SITE_CANDIDATE_SOURCES),
48
+ required: true,
49
+ })
50
+ .addAttribute('status', {
51
+ type: Object.values(SITE_CANDIDATE_STATUS),
52
+ required: true,
53
+ })
54
+ .addAttribute('updatedBy', {
55
+ type: 'string',
56
+ })
57
+ .addAllIndexWithComposite('baseURL');
58
+
59
+ export default schema.build();
@@ -0,0 +1,35 @@
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 { BaseCollection, BaseModel } from '../index';
14
+
15
+ export interface SiteTopPage extends BaseModel {
16
+ getGeo(): string;
17
+ getImportedAt(): number;
18
+ getSiteId(): string;
19
+ getSource(): string;
20
+ getTopKeyword(): string;
21
+ getTraffic(): number;
22
+ getUrl(): string;
23
+ setGeo(geo: string): SiteTopPage;
24
+ setImportedAt(importedAt: number): SiteTopPage;
25
+ setSiteId(siteId: string): SiteTopPage;
26
+ setSource(source: string): SiteTopPage;
27
+ setTopKeyword(topKeyword: string): SiteTopPage;
28
+ setTraffic(traffic: number): SiteTopPage;
29
+ setUrl(url: string): SiteTopPage;
30
+ }
31
+
32
+ export interface SiteTopPageCollection extends BaseCollection<SiteTopPage> {
33
+ allBySiteId(siteId: string): Promise<SiteTopPage[]>;
34
+ allBySiteIdAndSourceAndGeo(siteId: string, source: string, geo: string): Promise<SiteTopPage[]>;
35
+ }
@@ -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 SiteTopPage from './site-top-page.model.js';
14
+ import SiteTopPageCollection from './site-top-page.collection.js';
15
+
16
+ export {
17
+ SiteTopPage,
18
+ SiteTopPageCollection,
19
+ };
@@ -0,0 +1,44 @@
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 { hasText } from '@adobe/spacecat-shared-utils';
14
+
15
+ import BaseCollection from '../base/base.collection.js';
16
+
17
+ /**
18
+ * SiteTopPageCollection - A collection class responsible for managing SiteTopPage entities.
19
+ * Extends the BaseCollection to provide specific methods for interacting with SiteTopPage records.
20
+ *
21
+ * @class SiteTopPageCollection
22
+ * @extends BaseCollection
23
+ */
24
+ class SiteTopPageCollection extends BaseCollection {
25
+ async removeForSiteId(siteId, source, geo) {
26
+ if (!hasText(siteId)) {
27
+ throw new Error('SiteId is required');
28
+ }
29
+
30
+ let topPagesToRemove;
31
+
32
+ if (hasText(source) && hasText(geo)) {
33
+ topPagesToRemove = await this.allBySiteIdAndSourceAndGeo(siteId, source, geo);
34
+ } else {
35
+ topPagesToRemove = await this.allBySiteId(siteId);
36
+ }
37
+
38
+ const topPageIdsToRemove = topPagesToRemove.map((topPage) => topPage.getId());
39
+
40
+ await this.removeByIds(topPageIdsToRemove);
41
+ }
42
+ }
43
+
44
+ export default SiteTopPageCollection;
@@ -0,0 +1,28 @@
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
+ export const DEFAULT_GEO = 'global';
16
+
17
+ /**
18
+ * SiteTopPage - A class representing an SiteTopPage entity.
19
+ * Provides methods to access and manipulate SiteTopPage-specific data.
20
+ *
21
+ * @class SiteTopPage
22
+ * @extends BaseModel
23
+ */
24
+ class SiteTopPage extends BaseModel {
25
+ // add your custom methods or overrides here
26
+ }
27
+
28
+ export default SiteTopPage;
@@ -0,0 +1,65 @@
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 { 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 SiteTopPage, { DEFAULT_GEO } from './site-top-page.model.js';
21
+ import SiteTopPageCollection from './site-top-page.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(SiteTopPage, SiteTopPageCollection)
30
+ .addReference('belongs_to', 'Site', ['source', 'geo', '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('traffic', {
42
+ type: 'number',
43
+ required: true,
44
+ validate: (value) => isInteger(value),
45
+ })
46
+ .addAttribute('source', {
47
+ type: 'string',
48
+ required: true,
49
+ })
50
+ .addAttribute('topKeyword', {
51
+ type: 'string',
52
+ })
53
+ .addAttribute('geo', {
54
+ type: 'string',
55
+ required: false,
56
+ default: DEFAULT_GEO,
57
+ })
58
+ .addAttribute('importedAt', {
59
+ type: 'string',
60
+ required: true,
61
+ default: () => new Date().toISOString(),
62
+ validate: (value) => isIsoDate(value),
63
+ });
64
+
65
+ export default schema.build();