@adobe/spacecat-shared-data-access 1.59.2 → 1.60.1
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 +14 -0
- package/package.json +2 -2
- package/src/models/site/config.js +1 -1
- package/src/service/audits/accessPatterns.js +7 -7
- package/src/service/experiments/accessPatterns.js +2 -2
- package/src/service/import-job/accessPatterns.js +1 -1
- package/src/service/import-url/accessPatterns.js +2 -2
- package/src/service/index.js +10 -18
- package/src/service/key-events/accessPatterns.js +3 -3
- package/src/service/organizations/accessPatterns.js +3 -3
- package/src/service/site-candidates/accessPatterns.js +1 -1
- package/src/service/sites/accessPatterns.js +11 -11
- package/src/v2/models/api-key/api-key.collection.js +26 -0
- package/src/v2/models/api-key/api-key.model.js +59 -0
- package/src/v2/models/api-key/api-key.schema.js +82 -0
- package/src/v2/models/api-key/index.d.ts +37 -0
- package/src/v2/models/api-key/index.js +19 -0
- package/src/v2/models/audit/audit.collection.js +26 -0
- package/src/v2/models/audit/audit.model.js +89 -0
- package/src/v2/models/audit/audit.schema.js +66 -0
- package/src/v2/models/audit/index.d.ts +40 -0
- package/src/v2/models/audit/index.js +19 -0
- package/src/v2/models/base/base.collection.js +450 -0
- package/src/v2/models/{base.model.js → base/base.model.js} +109 -89
- package/src/v2/models/base/constants.js +17 -0
- package/src/v2/models/base/entity.registry.js +137 -0
- package/src/v2/models/base/index.d.ts +83 -0
- package/src/v2/models/base/index.js +27 -0
- package/src/v2/models/base/reference.js +159 -0
- package/src/v2/models/base/schema.builder.js +420 -0
- package/src/v2/models/base/schema.js +283 -0
- package/src/v2/models/configuration/configuration.collection.js +39 -0
- package/src/v2/models/configuration/configuration.model.js +160 -0
- package/src/v2/models/configuration/configuration.schema.js +103 -0
- package/src/v2/models/configuration/index.d.ts +111 -0
- package/src/v2/models/configuration/index.js +19 -0
- package/src/v2/models/experiment/experiment.collection.js +26 -0
- package/src/v2/models/experiment/experiment.model.js +28 -0
- package/src/v2/models/experiment/experiment.schema.js +70 -0
- package/src/v2/models/experiment/index.d.ts +49 -0
- package/src/v2/models/experiment/index.js +19 -0
- package/src/v2/models/import-job/import-job.collection.js +45 -0
- package/src/v2/models/import-job/import-job.model.js +55 -0
- package/src/v2/models/import-job/import-job.schema.js +152 -0
- package/src/v2/models/import-job/index.d.ts +51 -0
- package/src/v2/models/import-job/index.js +19 -0
- package/src/v2/models/import-url/import-url.collection.js +26 -0
- package/src/v2/models/import-url/import-url.model.js +28 -0
- package/src/v2/models/import-url/import-url.schema.js +59 -0
- package/src/v2/models/import-url/index.d.ts +35 -0
- package/src/v2/models/import-url/index.js +19 -0
- package/src/v2/models/index.d.ts +11 -99
- package/src/v2/models/index.js +14 -15
- package/src/v2/models/key-event/index.d.ts +28 -0
- package/src/v2/models/key-event/index.js +19 -0
- package/src/v2/models/key-event/key-event.collection.js +26 -0
- package/src/v2/models/key-event/key-event.model.js +37 -0
- package/src/v2/models/key-event/key-event.schema.js +45 -0
- package/src/v2/models/opportunity/index.d.ts +46 -0
- package/src/v2/models/opportunity/index.js +19 -0
- package/src/v2/models/opportunity/opportunity.collection.js +26 -0
- package/src/v2/models/{opportunity.model.js → opportunity/opportunity.model.js} +15 -2
- package/src/v2/models/opportunity/opportunity.schema.js +69 -0
- package/src/v2/models/organization/index.d.ts +28 -0
- package/src/v2/models/organization/index.js +19 -0
- package/src/v2/models/organization/organization.collection.js +26 -0
- package/src/v2/models/organization/organization.model.js +31 -0
- package/src/v2/models/organization/organization.schema.js +51 -0
- package/src/v2/models/site/index.d.ts +43 -0
- package/src/v2/models/site/index.js +20 -0
- package/src/v2/models/site/site.collection.js +28 -0
- package/src/v2/models/site/site.model.js +47 -0
- package/src/v2/models/site/site.schema.js +91 -0
- package/src/v2/models/site-candidate/index.d.ts +38 -0
- package/src/v2/models/site-candidate/index.js +19 -0
- package/src/v2/models/site-candidate/site-candidate.collection.js +27 -0
- package/src/v2/models/site-candidate/site-candidate.model.js +41 -0
- package/src/v2/models/site-candidate/site-candidate.schema.js +59 -0
- package/src/v2/models/site-top-page/index.d.ts +35 -0
- package/src/v2/models/site-top-page/index.js +19 -0
- package/src/v2/models/site-top-page/site-top-page.collection.js +44 -0
- package/src/v2/models/site-top-page/site-top-page.model.js +28 -0
- package/src/v2/models/site-top-page/site-top-page.schema.js +65 -0
- package/src/v2/models/suggestion/index.d.ts +34 -0
- package/src/v2/models/suggestion/index.js +19 -0
- package/src/v2/models/suggestion/suggestion.collection.js +55 -0
- package/src/v2/models/{suggestion.model.js → suggestion/suggestion.model.js} +16 -1
- package/src/v2/models/suggestion/suggestion.schema.js +53 -0
- package/src/v2/readme.md +201 -256
- package/src/v2/util/accessor.utils.js +158 -0
- package/src/v2/util/guards.d.ts +7 -0
- package/src/v2/util/guards.js +21 -4
- package/src/v2/util/index.js +1 -0
- package/src/v2/util/patcher.js +54 -25
- package/src/v2/util/util.js +104 -0
- package/src/v2/models/base.collection.js +0 -275
- package/src/v2/models/model.factory.js +0 -74
- package/src/v2/models/opportunity.collection.js +0 -74
- package/src/v2/models/suggestion.collection.js +0 -104
- package/src/v2/schema/opportunity.schema.js +0 -159
- package/src/v2/schema/suggestion.schema.js +0 -132
- package/src/v2/util/reference.js +0 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.60.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.60.0...@adobe/spacecat-shared-data-access-v1.60.1) (2024-12-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* removeElectroProperties ([#498](https://github.com/adobe/spacecat-shared/issues/498)) ([a21b188](https://github.com/adobe/spacecat-shared/commit/a21b1887d6872092679f9c5d02452e79711955e7))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-data-access-v1.60.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.59.2...@adobe/spacecat-shared-data-access-v1.60.0) (2024-12-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* migrate entities to electrodb ([#484](https://github.com/adobe/spacecat-shared/issues/484)) ([e9a6310](https://github.com/adobe/spacecat-shared/commit/e9a6310dbdea4d44562432b794aa1e287ba9428d))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-data-access-v1.59.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.59.1...@adobe/spacecat-shared-data-access-v1.59.2) (2024-12-14)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-data-access",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.60.1",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Data Access",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"main": "src/index.js",
|
|
11
11
|
"types": "src/index.d.ts",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"test:it": "mocha --spec \"test/it/**/*.test.js\"",
|
|
13
|
+
"test:it": "mocha --require ./test/it/fixtures.js --spec \"test/it/**/*.test.js\"",
|
|
14
14
|
"test": "c8 mocha --spec \"test/unit/**/*.test.js\"",
|
|
15
15
|
"lint": "eslint .",
|
|
16
16
|
"clean": "rm -rf package-lock.json node_modules"
|
|
@@ -45,7 +45,7 @@ export const DEFAULT_CONFIG = {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
// Function to validate incoming configuration
|
|
48
|
-
function validateConfiguration(config) {
|
|
48
|
+
export function validateConfiguration(config) {
|
|
49
49
|
const { error, value } = configSchema.validate(config);
|
|
50
50
|
|
|
51
51
|
if (error) {
|
|
@@ -21,7 +21,7 @@ import { createAudit } from '../../models/audit.js';
|
|
|
21
21
|
*
|
|
22
22
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
23
23
|
* @param {DataAccessConfig} config - The data access config.
|
|
24
|
-
* @param {Logger} log - The
|
|
24
|
+
* @param {Logger} log - The log.
|
|
25
25
|
* @param {string} siteId - The ID of the site for which audits are being retrieved.
|
|
26
26
|
* @param {string} [auditType] - Optional. The type of audits to retrieve.
|
|
27
27
|
* @param {boolean} [ascending] - Optional. Determines if the audits should be sorted
|
|
@@ -61,7 +61,7 @@ export const getAuditsForSite = async (
|
|
|
61
61
|
*
|
|
62
62
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
63
63
|
* @param {DataAccessConfig} config - The data access config.
|
|
64
|
-
* @param {Logger} log - The
|
|
64
|
+
* @param {Logger} log - The log.
|
|
65
65
|
* @param {string} siteId - The ID of the site for which to retrieve the audit.
|
|
66
66
|
* @param {string} auditType - The type of audit to retrieve.
|
|
67
67
|
* @param auditedAt - The ISO 8601 timestamp of the audit.
|
|
@@ -88,7 +88,7 @@ export const getAuditForSite = async (
|
|
|
88
88
|
*
|
|
89
89
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
90
90
|
* @param {DataAccessConfig} config - The data access config.
|
|
91
|
-
* @param {Logger} log - The
|
|
91
|
+
* @param {Logger} log - The log.
|
|
92
92
|
* @param {string} auditType - The type of audits to retrieve.
|
|
93
93
|
* @param {boolean} ascending - Determines if the audits should be sorted ascending
|
|
94
94
|
* or descending by scores.
|
|
@@ -121,7 +121,7 @@ export const getLatestAudits = async (
|
|
|
121
121
|
*
|
|
122
122
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
123
123
|
* @param {DataAccessConfig} config - The data access config.
|
|
124
|
-
* @param {Logger} log - The
|
|
124
|
+
* @param {Logger} log - The log.
|
|
125
125
|
* @param {string} siteId - The ID of the site for which audits are being retrieved.
|
|
126
126
|
* @returns {Promise<Readonly<Audit>[]>} A promise that resolves to an array of latest audits
|
|
127
127
|
* for the specified site.
|
|
@@ -148,7 +148,7 @@ export const getLatestAuditsForSite = async (
|
|
|
148
148
|
*
|
|
149
149
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
150
150
|
* @param {DataAccessConfig} config - The data access config.
|
|
151
|
-
* @param {Logger} log - The
|
|
151
|
+
* @param {Logger} log - The log.
|
|
152
152
|
* @param {string} siteId - The ID of the site for which the latest audit is being retrieved.
|
|
153
153
|
* @param {string} auditType - The type of audit to retrieve the latest instance of.
|
|
154
154
|
* @returns {Promise<Audit|null>} A promise that resolves to the latest audit of the
|
|
@@ -174,7 +174,7 @@ export const getLatestAuditForSite = async (
|
|
|
174
174
|
*
|
|
175
175
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
176
176
|
* @param {DataAccessConfig} config - The data access config.
|
|
177
|
-
* @param {Logger} log - The
|
|
177
|
+
* @param {Logger} log - The log.
|
|
178
178
|
* @param {object} auditData - The audit data.
|
|
179
179
|
* @returns {Promise<Readonly<Audit>>}
|
|
180
180
|
*/
|
|
@@ -261,7 +261,7 @@ async function removeAudits(
|
|
|
261
261
|
*
|
|
262
262
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
263
263
|
* @param {DataAccessConfig} config - The data access config.
|
|
264
|
-
* @param {Logger} log - The
|
|
264
|
+
* @param {Logger} log - The log.
|
|
265
265
|
* @param {string} siteId - The ID of the site for which audits are being removed.
|
|
266
266
|
* @returns {Promise<void>}
|
|
267
267
|
*/
|
|
@@ -44,7 +44,7 @@ export const getExperiment = async (dynamoClient, config, siteId, experimentId,
|
|
|
44
44
|
* Retrieves all experiments for a given siteId.
|
|
45
45
|
* @param {*} dynamoClient - The DynamoDB client.
|
|
46
46
|
* @param {*} config - The data access config.
|
|
47
|
-
* @param {*} log - the
|
|
47
|
+
* @param {*} log - the log object
|
|
48
48
|
* @param {*} siteId - siteId of the experiment.
|
|
49
49
|
* @param {*} experimentId - experiment id.
|
|
50
50
|
* @returns {Promise<ReadonlyArray<SiteCandidate>>} A promise that resolves to
|
|
@@ -77,7 +77,7 @@ export const getExperiments = async (
|
|
|
77
77
|
*
|
|
78
78
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
79
79
|
* @param {DataAccessConfig} config - The data access config.
|
|
80
|
-
* @param {object} log - the
|
|
80
|
+
* @param {object} log - the log object
|
|
81
81
|
* @param {object} experimentData - The experiment data.
|
|
82
82
|
* @returns {Promise<Readonly<SiteCandidate>>} A promise that resolves to newly created/updated
|
|
83
83
|
* experiment
|
|
@@ -118,7 +118,7 @@ export const updateImportJob = async (dynamoClient, config, log, importJob) => {
|
|
|
118
118
|
* Removes an Import Job and all associated URLs.
|
|
119
119
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
120
120
|
* @param {DataAccessConfig} config - The data access config.
|
|
121
|
-
* @param {Logger} log - The
|
|
121
|
+
* @param {Logger} log - The log.
|
|
122
122
|
* @param {ImportJob} importJob - The import job to remove.
|
|
123
123
|
* @return {Promise<void>} A promise that resolves when the import job has been removed.
|
|
124
124
|
*/
|
|
@@ -101,7 +101,7 @@ export const getImportUrlsByJobIdAndStatus = async (dynamoClient, config, log, j
|
|
|
101
101
|
* Get Import Urls by Job ID, if no urls exist an empty array is returned.
|
|
102
102
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
103
103
|
* @param {DataAccessConfig} config - The data access config.
|
|
104
|
-
* @param {Logger} log - The
|
|
104
|
+
* @param {Logger} log - The log.
|
|
105
105
|
* @param {string} jobId - The ID of the import job.
|
|
106
106
|
* @returns {Promise<ImportUrl[]>}
|
|
107
107
|
*/
|
|
@@ -138,7 +138,7 @@ async function removeUrls(dynamoClient, config, urls) {
|
|
|
138
138
|
* Remove all URLs associated with an import job.
|
|
139
139
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
140
140
|
* @param {DataAccessConfig} config - The data access config.
|
|
141
|
-
* @param {Logger} log - The
|
|
141
|
+
* @param {Logger} log - The log.
|
|
142
142
|
* @param {string} jobId - The ID of the import job.
|
|
143
143
|
* @return {Promise<void>} A promise that resolves when all URLs have been removed.
|
|
144
144
|
*/
|
package/src/service/index.js
CHANGED
|
@@ -13,14 +13,11 @@
|
|
|
13
13
|
import { createClient } from '@adobe/spacecat-shared-dynamo';
|
|
14
14
|
import { DynamoDB } from '@aws-sdk/client-dynamodb';
|
|
15
15
|
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
|
|
16
|
+
|
|
16
17
|
import AWSXray from 'aws-xray-sdk';
|
|
17
18
|
import { Service } from 'electrodb';
|
|
18
19
|
|
|
19
|
-
import
|
|
20
|
-
import OpportunityCollection from '../v2/models/opportunity.collection.js';
|
|
21
|
-
import SuggestionCollection from '../v2/models/suggestion.collection.js';
|
|
22
|
-
import OpportunitySchema from '../v2/schema/opportunity.schema.js';
|
|
23
|
-
import SuggestionSchema from '../v2/schema/suggestion.schema.js';
|
|
20
|
+
import EntityRegistry from '../v2/models/base/entity.registry.js';
|
|
24
21
|
|
|
25
22
|
import { auditFunctions } from './audits/index.js';
|
|
26
23
|
import { keyEventFunctions } from './key-events/index.js';
|
|
@@ -51,11 +48,9 @@ const createElectroService = (client, config, log) => {
|
|
|
51
48
|
log.debug(JSON.stringify(event, null, 4));
|
|
52
49
|
};
|
|
53
50
|
/* c8 ignore end */
|
|
51
|
+
|
|
54
52
|
return new Service(
|
|
55
|
-
|
|
56
|
-
opportunity: OpportunitySchema,
|
|
57
|
-
suggestion: SuggestionSchema,
|
|
58
|
-
},
|
|
53
|
+
EntityRegistry.getEntities(),
|
|
59
54
|
{
|
|
60
55
|
client,
|
|
61
56
|
table,
|
|
@@ -74,11 +69,11 @@ const createElectroService = (client, config, log) => {
|
|
|
74
69
|
* tableNameImportJobs: string, pkAllImportJobs: string, indexNameAllImportJobs: string,
|
|
75
70
|
* tableNameSiteTopPages: string, indexNameAllOrganizations: string,
|
|
76
71
|
* indexNameAllOrganizationsByImsOrgId: string, pkAllOrganizations: string}} config configuration
|
|
77
|
-
* @param {Logger} log
|
|
72
|
+
* @param {Logger} log log
|
|
78
73
|
* @returns {object} data access object
|
|
79
74
|
*/
|
|
80
|
-
export const createDataAccess = (config, log = console) => {
|
|
81
|
-
const dynamoClient = createClient(log);
|
|
75
|
+
export const createDataAccess = (config, log = console, client = undefined) => {
|
|
76
|
+
const dynamoClient = createClient(log, client);
|
|
82
77
|
|
|
83
78
|
const auditFuncs = auditFunctions(dynamoClient, config, log);
|
|
84
79
|
const keyEventFuncs = keyEventFunctions(dynamoClient, config, log);
|
|
@@ -95,10 +90,8 @@ export const createDataAccess = (config, log = console) => {
|
|
|
95
90
|
// electro-based data access objects
|
|
96
91
|
const rawClient = createRawClient();
|
|
97
92
|
const electroService = createElectroService(rawClient, config, log);
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
const Opportunity = modelFactory.getCollection(OpportunityCollection.name);
|
|
101
|
-
const Suggestion = modelFactory.getCollection(SuggestionCollection.name);
|
|
93
|
+
const entityRegistry = new EntityRegistry(electroService, log);
|
|
94
|
+
const collections = entityRegistry.getCollections();
|
|
102
95
|
|
|
103
96
|
return {
|
|
104
97
|
...auditFuncs,
|
|
@@ -113,7 +106,6 @@ export const createDataAccess = (config, log = console) => {
|
|
|
113
106
|
...experimentFuncs,
|
|
114
107
|
...apiKeyFuncs,
|
|
115
108
|
// electro-based data access objects
|
|
116
|
-
|
|
117
|
-
Suggestion,
|
|
109
|
+
...collections,
|
|
118
110
|
};
|
|
119
111
|
};
|
|
@@ -18,7 +18,7 @@ import { KeyEventDto } from '../../dto/key-event.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
20
20
|
* @param {DataAccessConfig} config - The data access config.
|
|
21
|
-
* @param {object} log - the
|
|
21
|
+
* @param {object} log - the log object
|
|
22
22
|
* @param {object} keyEventData - The key event data.
|
|
23
23
|
* @returns {Promise<Readonly<KeyEvent>>} newly created key event
|
|
24
24
|
*/
|
|
@@ -43,7 +43,7 @@ export const addKeyEvent = async (
|
|
|
43
43
|
*
|
|
44
44
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
45
45
|
* @param {DataAccessConfig} config - The data access config.
|
|
46
|
-
* @param {Logger} log - The
|
|
46
|
+
* @param {Logger} log - The log.
|
|
47
47
|
* @param {string} siteId - The ID of the site for which key events are being retrieved.
|
|
48
48
|
* @param {boolean} ascending - Determines if the key events should be sorted ascending
|
|
49
49
|
* or descending by createdAt.
|
|
@@ -73,7 +73,7 @@ export const getKeyEventsForSite = async (
|
|
|
73
73
|
*
|
|
74
74
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
75
75
|
* @param {DataAccessConfig} config - The data access config.
|
|
76
|
-
* @param {Logger} log - The
|
|
76
|
+
* @param {Logger} log - The log.
|
|
77
77
|
* @param {string} keyEventId - The ID of the key event to remove.
|
|
78
78
|
* @returns {Promise<void>}
|
|
79
79
|
*/
|
|
@@ -81,7 +81,7 @@ export const getOrganizationByImsOrgID = async (
|
|
|
81
81
|
*
|
|
82
82
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
83
83
|
* @param {DataAccessConfig} config - The data access config.
|
|
84
|
-
* @param {Logger} log - The
|
|
84
|
+
* @param {Logger} log - The log.
|
|
85
85
|
* @param {object} organizationData - The organization data.
|
|
86
86
|
* @returns {Promise<Readonly<Organization>>}
|
|
87
87
|
*/
|
|
@@ -106,7 +106,7 @@ export const addOrganization = async (
|
|
|
106
106
|
*
|
|
107
107
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
108
108
|
* @param {DataAccessConfig} config - The data access config.
|
|
109
|
-
* @param {Logger} log - The
|
|
109
|
+
* @param {Logger} log - The log.
|
|
110
110
|
* @param {Organization} organization - The organization.
|
|
111
111
|
* @returns {Promise<Readonly<Organization>>} - The updated organization.
|
|
112
112
|
*/
|
|
@@ -139,7 +139,7 @@ export const updateOrganization = async (
|
|
|
139
139
|
*
|
|
140
140
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
141
141
|
* @param {DataAccessConfig} config - The data access config.
|
|
142
|
-
* @param {Logger} log - The
|
|
142
|
+
* @param {Logger} log - The log.
|
|
143
143
|
* @param {string} organizationId - The ID of the organization to remove.
|
|
144
144
|
* @returns {Promise<void>}
|
|
145
145
|
*/
|
|
@@ -58,7 +58,7 @@ export const getSiteCandidateByBaseURL = async (
|
|
|
58
58
|
*
|
|
59
59
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
60
60
|
* @param {DataAccessConfig} config - The data access config.
|
|
61
|
-
* @param {object} log - the
|
|
61
|
+
* @param {object} log - the log object
|
|
62
62
|
* @param {object} siteCandidateData - The site candidate data.
|
|
63
63
|
* @returns {Promise<Readonly<SiteCandidate>>} newly created site candidate if hadn't created before
|
|
64
64
|
*/
|
|
@@ -89,7 +89,7 @@ export const getSitesToAudit = async (dynamoClient, config) => {
|
|
|
89
89
|
* the list.
|
|
90
90
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
91
91
|
* @param {DataAccessConfig} config - The data access config.
|
|
92
|
-
* @param {Logger} log - The
|
|
92
|
+
* @param {Logger} log - The log.
|
|
93
93
|
* @param {string} auditType - The type of audits to retrieve for the sites.
|
|
94
94
|
* @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
|
|
95
95
|
* ascending order.
|
|
@@ -138,7 +138,7 @@ export const getSitesWithLatestAudit = async (
|
|
|
138
138
|
*
|
|
139
139
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
140
140
|
* @param {DataAccessConfig} config - The data access config.
|
|
141
|
-
* @param {Logger} log - The
|
|
141
|
+
* @param {Logger} log - The log.
|
|
142
142
|
* @param {string} baseURL - The base URL of the site to retrieve.
|
|
143
143
|
* @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object if found,
|
|
144
144
|
* otherwise null.
|
|
@@ -168,7 +168,7 @@ export const getSiteByBaseURL = async (
|
|
|
168
168
|
*
|
|
169
169
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
170
170
|
* @param {DataAccessConfig} config - The data access config.
|
|
171
|
-
* @param {Logger} log - The
|
|
171
|
+
* @param {Logger} log - The log.
|
|
172
172
|
* @param {string} baseUrl - The base URL of the site to retrieve.
|
|
173
173
|
* @param {string} auditType - The type of audits to retrieve for the site.
|
|
174
174
|
* @param {boolean} [latestOnly=false] - Determines if only the latest audit should be retrieved.
|
|
@@ -215,7 +215,7 @@ export const getSiteByBaseURLWithAuditInfo = async (
|
|
|
215
215
|
*
|
|
216
216
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
217
217
|
* @param {DataAccessConfig} config - The data access config.
|
|
218
|
-
* @param {Logger} log - The
|
|
218
|
+
* @param {Logger} log - The log.
|
|
219
219
|
* @param {string} baseUrl - The base URL of the site to retrieve.
|
|
220
220
|
* @param {string} auditType - The type of audits to retrieve for the site.
|
|
221
221
|
* @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object
|
|
@@ -234,7 +234,7 @@ export const getSiteByBaseURLWithAudits = async (
|
|
|
234
234
|
*
|
|
235
235
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
236
236
|
* @param {DataAccessConfig} config - The data access config.
|
|
237
|
-
* @param {Logger} log - The
|
|
237
|
+
* @param {Logger} log - The log.
|
|
238
238
|
* @param {string} baseUrl - The base URL of the site to retrieve.
|
|
239
239
|
* @param {string} auditType - The type of the latest audit to retrieve for the site.
|
|
240
240
|
* @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object
|
|
@@ -272,7 +272,7 @@ export const getSitesByOrganizationID = async (
|
|
|
272
272
|
* The sortAuditsAscending parameter can be used to change the sort order.
|
|
273
273
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
274
274
|
* @param {DataAccessConfig} config - The data access config.
|
|
275
|
-
* @param {Logger} log - The
|
|
275
|
+
* @param {Logger} log - The log.
|
|
276
276
|
* @param {string} auditType - The type of audits to retrieve for the sites.
|
|
277
277
|
* @param {string} organizationId - The organizationId to retrieve the sites.
|
|
278
278
|
* @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
|
|
@@ -321,7 +321,7 @@ export const getSitesByOrganizationIDWithLatestAudits = async (
|
|
|
321
321
|
*
|
|
322
322
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
323
323
|
* @param {DataAccessConfig} config - The data access config.
|
|
324
|
-
* @param {Logger} log - The
|
|
324
|
+
* @param {Logger} log - The log.
|
|
325
325
|
* @param {string} siteId - The ID of the site to retrieve.
|
|
326
326
|
* @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object if found,
|
|
327
327
|
* otherwise null.
|
|
@@ -341,7 +341,7 @@ export const getSiteByID = async (
|
|
|
341
341
|
*
|
|
342
342
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
343
343
|
* @param {DataAccessConfig} config - The data access config.
|
|
344
|
-
* @param {Logger} log - The
|
|
344
|
+
* @param {Logger} log - The log.
|
|
345
345
|
* @param {object} siteData - The site data.
|
|
346
346
|
* @returns {Promise<Readonly<Site>>}
|
|
347
347
|
*/
|
|
@@ -373,7 +373,7 @@ export const addSite = async (
|
|
|
373
373
|
*
|
|
374
374
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
375
375
|
* @param {DataAccessConfig} config - The data access config.
|
|
376
|
-
* @param {Logger} log - The
|
|
376
|
+
* @param {Logger} log - The log.
|
|
377
377
|
* @param {Site} site - The site.
|
|
378
378
|
* @returns {Promise<Readonly<Site>>} - The updated site.
|
|
379
379
|
*/
|
|
@@ -399,7 +399,7 @@ export const updateSite = async (
|
|
|
399
399
|
*
|
|
400
400
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
401
401
|
* @param {DataAccessConfig} config - The data access config.
|
|
402
|
-
* @param {Logger} log - The
|
|
402
|
+
* @param {Logger} log - The log.
|
|
403
403
|
* @param {string} siteId - The ID of the site to remove.
|
|
404
404
|
* @returns {Promise<void>}
|
|
405
405
|
*/
|
|
@@ -446,7 +446,7 @@ async function removeSites(
|
|
|
446
446
|
* Removes all sites for an organization.
|
|
447
447
|
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
448
448
|
* @param {DataAccessConfig} config - The data access config.
|
|
449
|
-
* @param {Logger} log - The
|
|
449
|
+
* @param {Logger} log - The log.
|
|
450
450
|
* @param {string} organizationId - The ID of the organization to remove the sites for.
|
|
451
451
|
* @return {Promise<void>} A promise that resolves when all sites for the organization have been
|
|
452
452
|
* removed.
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
* ApiKeyCollection - A collection class responsible for managing ApiKey entities.
|
|
17
|
+
* Extends the BaseCollection to provide specific methods for interacting with ApiKey records.
|
|
18
|
+
*
|
|
19
|
+
* @class ApiKeyCollection
|
|
20
|
+
* @extends BaseCollection
|
|
21
|
+
*/
|
|
22
|
+
class ApiKeyCollection extends BaseCollection {
|
|
23
|
+
// add custom methods here
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default ApiKeyCollection;
|
|
@@ -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
|
+
import { isIsoDate } from '@adobe/spacecat-shared-utils';
|
|
14
|
+
|
|
15
|
+
import BaseModel from '../base/base.model.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* ApiKey - A class representing an ApiKey entity.
|
|
19
|
+
* Provides methods to access and manipulate ApiKey-specific data.
|
|
20
|
+
*
|
|
21
|
+
* @class ApiKey
|
|
22
|
+
* @extends BaseModel
|
|
23
|
+
*/
|
|
24
|
+
class ApiKey extends BaseModel {
|
|
25
|
+
static SCOPE_NAMES = [
|
|
26
|
+
'sites.read_all',
|
|
27
|
+
'sites.write_all',
|
|
28
|
+
'organizations.read_all',
|
|
29
|
+
'organizations.write_all',
|
|
30
|
+
'audits.read_all',
|
|
31
|
+
'audits.write_all',
|
|
32
|
+
'imports.read',
|
|
33
|
+
'imports.write',
|
|
34
|
+
'imports.delete',
|
|
35
|
+
'imports.read_all',
|
|
36
|
+
'imports.all_domains',
|
|
37
|
+
'imports.assistant',
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
isValid() {
|
|
41
|
+
const now = new Date();
|
|
42
|
+
|
|
43
|
+
if (isIsoDate(this.getDeletedAt()) && new Date(this.getDeletedAt()) < now) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isIsoDate(this.getRevokedAt()) && new Date(this.getRevokedAt()) < now) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (isIsoDate(this.getExpiresAt()) && new Date(this.getExpiresAt()) < now) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default ApiKey;
|
|
@@ -0,0 +1,82 @@
|
|
|
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 { isIsoDate, isValidUrl } from '@adobe/spacecat-shared-utils';
|
|
16
|
+
|
|
17
|
+
import SchemaBuilder from '../base/schema.builder.js';
|
|
18
|
+
import ApiKey from './api-key.model.js';
|
|
19
|
+
import ApiKeyCollection from './api-key.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(ApiKey, ApiKeyCollection)
|
|
28
|
+
.addAttribute('hashedApiKey', {
|
|
29
|
+
type: 'string',
|
|
30
|
+
required: true,
|
|
31
|
+
})
|
|
32
|
+
.addAttribute('imsUserId', {
|
|
33
|
+
type: 'string',
|
|
34
|
+
})
|
|
35
|
+
.addAttribute('imsOrgId', {
|
|
36
|
+
type: 'string',
|
|
37
|
+
})
|
|
38
|
+
.addAttribute('name', {
|
|
39
|
+
type: 'string',
|
|
40
|
+
required: true,
|
|
41
|
+
})
|
|
42
|
+
.addAttribute('deletedAt', {
|
|
43
|
+
type: 'string',
|
|
44
|
+
validate: (value) => !value || isIsoDate(value),
|
|
45
|
+
})
|
|
46
|
+
.addAttribute('expiresAt', {
|
|
47
|
+
type: 'string',
|
|
48
|
+
validate: (value) => !value || isIsoDate(value),
|
|
49
|
+
})
|
|
50
|
+
.addAttribute('revokedAt', {
|
|
51
|
+
type: 'string',
|
|
52
|
+
validate: (value) => !value || isIsoDate(value),
|
|
53
|
+
})
|
|
54
|
+
.addAttribute('scopes', {
|
|
55
|
+
type: 'list',
|
|
56
|
+
required: true,
|
|
57
|
+
items: {
|
|
58
|
+
type: 'map',
|
|
59
|
+
properties: {
|
|
60
|
+
domains: {
|
|
61
|
+
type: 'list',
|
|
62
|
+
items: {
|
|
63
|
+
type: 'string',
|
|
64
|
+
validate: (value) => isValidUrl(value),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
name: { type: ApiKey.SCOPE_NAMES },
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
.addIndex(
|
|
72
|
+
'byHashedApiKey',
|
|
73
|
+
{ composite: ['hashedApiKey'] },
|
|
74
|
+
{ composite: ['updatedAt'] },
|
|
75
|
+
)
|
|
76
|
+
.addIndex(
|
|
77
|
+
'byImsOrgIdAndImsUserId',
|
|
78
|
+
{ composite: ['imsOrgId', 'imsUserId'] },
|
|
79
|
+
{ composite: ['updatedAt'] },
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
export default schema.build();
|
|
@@ -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
|
+
import type { BaseCollection, BaseModel } from '../base';
|
|
14
|
+
|
|
15
|
+
export interface ApiKey extends BaseModel {
|
|
16
|
+
getDeletedAt(): string | undefined;
|
|
17
|
+
getExpiresAt(): string | undefined;
|
|
18
|
+
getHashedApiKey(): string;
|
|
19
|
+
getImsOrgId(): string | undefined;
|
|
20
|
+
getImsUserId(): string | undefined;
|
|
21
|
+
getName(): string;
|
|
22
|
+
getRevokedAt(): string | undefined;
|
|
23
|
+
getScopes(): string[];
|
|
24
|
+
setDeletedAt(deletedAt: string): void;
|
|
25
|
+
setExpiresAt(expiresAt: string): void;
|
|
26
|
+
setHashedApiKey(hashedApiKey: string): void;
|
|
27
|
+
setImsOrgId(imsOrgId: string): void;
|
|
28
|
+
setImsUserId(imsUserId: string): void;
|
|
29
|
+
setName(name: string): void;
|
|
30
|
+
setRevokedAt(revokedAt: string): void;
|
|
31
|
+
setScopes(scopes: object[]): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ApiKeyCollection extends BaseCollection<ApiKey> {
|
|
35
|
+
allByImsOrgIdAndImsUserId: (imsUserId: string, imsOrgId: string) => Promise<ApiKey[]>;
|
|
36
|
+
findByHashedApiKey: (hashedApiKey: string) => Promise<ApiKey | null>;
|
|
37
|
+
}
|
|
@@ -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 ApiKey from './api-key.model.js';
|
|
14
|
+
import ApiKeyCollection from './api-key.collection.js';
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
ApiKey,
|
|
18
|
+
ApiKeyCollection,
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
* AuditCollection - A collection class responsible for managing Audit entities.
|
|
17
|
+
* Extends the BaseCollection to provide specific methods for interacting with Audit records.
|
|
18
|
+
*
|
|
19
|
+
* @class AuditCollection
|
|
20
|
+
* @extends BaseCollection
|
|
21
|
+
*/
|
|
22
|
+
class AuditCollection extends BaseCollection {
|
|
23
|
+
// add custom methods here
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default AuditCollection;
|