@adobe/spacecat-shared-data-access 1.61.19 → 2.0.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 +19 -0
- package/package.json +5 -6
- package/src/index.d.ts +4 -934
- package/src/index.js +1 -91
- package/src/{v2 → models}/index.d.ts +14 -3
- package/src/{v2/models → models}/organization/organization.schema.js +1 -1
- package/src/{v2/models → models}/site/site.schema.js +1 -1
- package/src/service/index.d.ts +20 -0
- package/src/service/index.js +6 -46
- package/src/dto/api-key.js +0 -58
- package/src/dto/audit.js +0 -80
- package/src/dto/configuration.js +0 -49
- package/src/dto/dto-utils.js +0 -30
- package/src/dto/experiment.js +0 -66
- package/src/dto/import-job.js +0 -76
- package/src/dto/import-url.js +0 -55
- package/src/dto/key-event.js +0 -52
- package/src/dto/organization.js +0 -54
- package/src/dto/site-candidate.js +0 -54
- package/src/dto/site-top-page.js +0 -52
- package/src/dto/site.js +0 -62
- package/src/models/api-key/api-key.js +0 -182
- package/src/models/audit.js +0 -146
- package/src/models/base.js +0 -42
- package/src/models/configuration.js +0 -194
- package/src/models/experiment.js +0 -67
- package/src/models/importer/import-constants.js +0 -40
- package/src/models/importer/import-job.js +0 -252
- package/src/models/importer/import-url.js +0 -115
- package/src/models/key-event.js +0 -81
- package/src/models/organization.js +0 -120
- package/src/models/site-candidate.js +0 -111
- package/src/models/site-top-page.js +0 -62
- package/src/models/site.js +0 -218
- package/src/service/api-key/accessPatterns.js +0 -110
- package/src/service/api-key/index.js +0 -37
- package/src/service/audits/accessPatterns.js +0 -284
- package/src/service/audits/index.js +0 -72
- package/src/service/configurations/accessPatterns.js +0 -123
- package/src/service/configurations/index.js +0 -38
- package/src/service/experiments/accessPatterns.js +0 -98
- package/src/service/experiments/index.js +0 -40
- package/src/service/import-job/accessPatterns.js +0 -134
- package/src/service/import-job/index.js +0 -60
- package/src/service/import-url/accessPatterns.js +0 -153
- package/src/service/import-url/index.js +0 -53
- package/src/service/key-events/accessPatterns.js +0 -92
- package/src/service/key-events/index.js +0 -38
- package/src/service/organizations/accessPatterns.js +0 -160
- package/src/service/organizations/index.js +0 -51
- package/src/service/site-candidates/accessPatterns.js +0 -112
- package/src/service/site-candidates/index.js +0 -48
- package/src/service/site-top-pages/accessPatterns.js +0 -83
- package/src/service/site-top-pages/index.js +0 -42
- package/src/service/sites/accessPatterns.js +0 -467
- package/src/service/sites/index.js +0 -116
- package/src/v2/index.js +0 -15
- package/src/v2/models/index.d.ts +0 -26
- /package/src/{v2/errors → errors}/data-access.error.js +0 -0
- /package/src/{v2/errors → errors}/index.d.ts +0 -0
- /package/src/{v2/errors → errors}/index.js +0 -0
- /package/src/{v2/errors → errors}/reference.error.js +0 -0
- /package/src/{v2/errors → errors}/schema-validation.error.js +0 -0
- /package/src/{v2/errors → errors}/schema.builder.error.js +0 -0
- /package/src/{v2/errors → errors}/schema.error.js +0 -0
- /package/src/{v2/errors → errors}/validation.error.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.collection.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.model.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.schema.js +0 -0
- /package/src/{v2/models → models}/api-key/index.d.ts +0 -0
- /package/src/{v2/models → models}/api-key/index.js +0 -0
- /package/src/{v2/models → models}/audit/audit.collection.js +0 -0
- /package/src/{v2/models → models}/audit/audit.model.js +0 -0
- /package/src/{v2/models → models}/audit/audit.schema.js +0 -0
- /package/src/{v2/models → models}/audit/index.d.ts +0 -0
- /package/src/{v2/models → models}/audit/index.js +0 -0
- /package/src/{v2/models → models}/base/base.collection.js +0 -0
- /package/src/{v2/models → models}/base/base.model.js +0 -0
- /package/src/{v2/models → models}/base/entity.registry.js +0 -0
- /package/src/{v2/models → models}/base/index.d.ts +0 -0
- /package/src/{v2/models → models}/base/index.js +0 -0
- /package/src/{v2/models → models}/base/reference.js +0 -0
- /package/src/{v2/models → models}/base/schema.builder.js +0 -0
- /package/src/{v2/models → models}/base/schema.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.collection.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.model.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.schema.js +0 -0
- /package/src/{v2/models → models}/configuration/index.d.ts +0 -0
- /package/src/{v2/models → models}/configuration/index.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.collection.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.model.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.schema.js +0 -0
- /package/src/{v2/models → models}/experiment/index.d.ts +0 -0
- /package/src/{v2/models → models}/experiment/index.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.collection.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.model.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.schema.js +0 -0
- /package/src/{v2/models → models}/import-job/index.d.ts +0 -0
- /package/src/{v2/models → models}/import-job/index.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.collection.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.model.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.schema.js +0 -0
- /package/src/{v2/models → models}/import-url/index.d.ts +0 -0
- /package/src/{v2/models → models}/import-url/index.js +0 -0
- /package/src/{v2/models → models}/index.js +0 -0
- /package/src/{v2/models → models}/key-event/index.d.ts +0 -0
- /package/src/{v2/models → models}/key-event/index.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.collection.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.model.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.schema.js +0 -0
- /package/src/{v2/models → models}/latest-audit/index.d.ts +0 -0
- /package/src/{v2/models → models}/latest-audit/index.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.collection.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.model.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.schema.js +0 -0
- /package/src/{v2/models → models}/opportunity/index.d.ts +0 -0
- /package/src/{v2/models → models}/opportunity/index.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.collection.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.model.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.schema.js +0 -0
- /package/src/{v2/models → models}/organization/index.d.ts +0 -0
- /package/src/{v2/models → models}/organization/index.js +0 -0
- /package/src/{v2/models → models}/organization/organization.collection.js +0 -0
- /package/src/{v2/models → models}/organization/organization.model.js +0 -0
- /package/src/{v2/models → models}/site/index.d.ts +0 -0
- /package/src/{v2/models → models}/site/index.js +0 -0
- /package/src/{v2/models → models}/site/site.collection.js +0 -0
- /package/src/{v2/models → models}/site/site.model.js +0 -0
- /package/src/{v2/models → models}/site-candidate/index.d.ts +0 -0
- /package/src/{v2/models → models}/site-candidate/index.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.collection.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.model.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.schema.js +0 -0
- /package/src/{v2/models → models}/site-top-page/index.d.ts +0 -0
- /package/src/{v2/models → models}/site-top-page/index.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.collection.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.model.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.schema.js +0 -0
- /package/src/{v2/models → models}/suggestion/index.d.ts +0 -0
- /package/src/{v2/models → models}/suggestion/index.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.collection.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.model.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.schema.js +0 -0
- /package/src/{v2/readme.md → readme.md} +0 -0
- /package/src/{v2/util → util}/accessor.utils.js +0 -0
- /package/src/{v2/util → util}/guards.d.ts +0 -0
- /package/src/{v2/util → util}/guards.js +0 -0
- /package/src/{v2/util → util}/index.d.ts +0 -0
- /package/src/{v2/util → util}/index.js +0 -0
- /package/src/{v2/util → util}/patcher.js +0 -0
- /package/src/{v2/util → util}/util.js +0 -0
|
@@ -1,37 +0,0 @@
|
|
|
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 {
|
|
14
|
-
createNewApiKey,
|
|
15
|
-
getApiKeyByHashedApiKey,
|
|
16
|
-
getApiKeyById,
|
|
17
|
-
getApiKeysByImsUserIdAndImsOrgId,
|
|
18
|
-
updateApiKey,
|
|
19
|
-
} from './accessPatterns.js';
|
|
20
|
-
|
|
21
|
-
export const apiKeyFunctions = (dynamoClient, config, log) => ({
|
|
22
|
-
getApiKeyByHashedApiKey: (hashedApiKey) => getApiKeyByHashedApiKey(
|
|
23
|
-
hashedApiKey,
|
|
24
|
-
dynamoClient,
|
|
25
|
-
log,
|
|
26
|
-
config,
|
|
27
|
-
),
|
|
28
|
-
createNewApiKey: (apiKey) => createNewApiKey(apiKey, dynamoClient, config, log),
|
|
29
|
-
getApiKeysByImsUserIdAndImsOrgId: (imsUserId, imsOrgId) => getApiKeysByImsUserIdAndImsOrgId(
|
|
30
|
-
imsUserId,
|
|
31
|
-
imsOrgId,
|
|
32
|
-
dynamoClient,
|
|
33
|
-
config,
|
|
34
|
-
),
|
|
35
|
-
getApiKeyById: (id) => getApiKeyById(id, dynamoClient, config),
|
|
36
|
-
updateApiKey: (apiKey) => updateApiKey(apiKey, dynamoClient, config),
|
|
37
|
-
});
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2023 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, isObject } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
|
|
15
|
-
import { AuditDto } from '../../dto/audit.js';
|
|
16
|
-
import { createAudit } from '../../models/audit.js';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves audits for a specified site. If an audit type is provided,
|
|
20
|
-
* it returns only audits of that type.
|
|
21
|
-
*
|
|
22
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
23
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
24
|
-
* @param {Logger} log - The log.
|
|
25
|
-
* @param {string} siteId - The ID of the site for which audits are being retrieved.
|
|
26
|
-
* @param {string} [auditType] - Optional. The type of audits to retrieve.
|
|
27
|
-
* @param {boolean} [ascending] - Optional. Determines if the audits should be sorted
|
|
28
|
-
* ascending. Default is true.
|
|
29
|
-
* @returns {Promise<Readonly<Audit>[]>} A promise that resolves to an array of audits
|
|
30
|
-
* for the specified site.
|
|
31
|
-
*/
|
|
32
|
-
export const getAuditsForSite = async (
|
|
33
|
-
dynamoClient,
|
|
34
|
-
config,
|
|
35
|
-
log,
|
|
36
|
-
siteId,
|
|
37
|
-
auditType,
|
|
38
|
-
ascending = true,
|
|
39
|
-
) => {
|
|
40
|
-
const queryParams = {
|
|
41
|
-
TableName: config.tableNameAudits,
|
|
42
|
-
KeyConditionExpression: 'siteId = :siteId',
|
|
43
|
-
ExpressionAttributeValues: {
|
|
44
|
-
':siteId': siteId,
|
|
45
|
-
},
|
|
46
|
-
ScanIndexForward: ascending, // Sorts ascending if true, descending if false
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
if (hasText(auditType)) {
|
|
50
|
-
queryParams.KeyConditionExpression += ' AND begins_with(SK, :auditType)';
|
|
51
|
-
queryParams.ExpressionAttributeValues[':auditType'] = `${auditType}#`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const dynamoItems = await dynamoClient.query(queryParams);
|
|
55
|
-
|
|
56
|
-
return dynamoItems.map((item) => AuditDto.fromDynamoItem(item));
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Retrieves a specific audit for a specified site.
|
|
61
|
-
*
|
|
62
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
63
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
64
|
-
* @param {Logger} log - The log.
|
|
65
|
-
* @param {string} siteId - The ID of the site for which to retrieve the audit.
|
|
66
|
-
* @param {string} auditType - The type of audit to retrieve.
|
|
67
|
-
* @param auditedAt - The ISO 8601 timestamp of the audit.
|
|
68
|
-
* @returns {Promise<Readonly<Audit>|null>}
|
|
69
|
-
*/
|
|
70
|
-
export const getAuditForSite = async (
|
|
71
|
-
dynamoClient,
|
|
72
|
-
config,
|
|
73
|
-
log,
|
|
74
|
-
siteId,
|
|
75
|
-
auditType,
|
|
76
|
-
auditedAt,
|
|
77
|
-
) => {
|
|
78
|
-
const audit = await dynamoClient.getItem(config.tableNameAudits, {
|
|
79
|
-
siteId,
|
|
80
|
-
SK: `${auditType}#${auditedAt}`,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return audit ? AuditDto.fromDynamoItem(audit) : null;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Retrieves the latest audits of a specific type across all sites.
|
|
88
|
-
*
|
|
89
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
90
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
91
|
-
* @param {Logger} log - The log.
|
|
92
|
-
* @param {string} auditType - The type of audits to retrieve.
|
|
93
|
-
* @param {boolean} ascending - Determines if the audits should be sorted ascending
|
|
94
|
-
* or descending by scores.
|
|
95
|
-
* @returns {Promise<Readonly<Audit>[]>} A promise that resolves to an array of the latest
|
|
96
|
-
* audits of the specified type.
|
|
97
|
-
*/
|
|
98
|
-
export const getLatestAudits = async (
|
|
99
|
-
dynamoClient,
|
|
100
|
-
config,
|
|
101
|
-
log,
|
|
102
|
-
auditType,
|
|
103
|
-
ascending = true,
|
|
104
|
-
) => {
|
|
105
|
-
const dynamoItems = await dynamoClient.query({
|
|
106
|
-
TableName: config.tableNameLatestAudits,
|
|
107
|
-
IndexName: config.indexNameAllLatestAuditScores,
|
|
108
|
-
KeyConditionExpression: 'GSI1PK = :gsi1pk AND begins_with(GSI1SK, :auditType)',
|
|
109
|
-
ExpressionAttributeValues: {
|
|
110
|
-
':gsi1pk': config.pkAllLatestAudits,
|
|
111
|
-
':auditType': `${auditType}#`,
|
|
112
|
-
},
|
|
113
|
-
ScanIndexForward: ascending, // Sorts ascending if true, descending if false
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return dynamoItems.map((item) => AuditDto.fromDynamoItem(item));
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Retrieves latest audits for a specified site.
|
|
121
|
-
*
|
|
122
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
123
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
124
|
-
* @param {Logger} log - The log.
|
|
125
|
-
* @param {string} siteId - The ID of the site for which audits are being retrieved.
|
|
126
|
-
* @returns {Promise<Readonly<Audit>[]>} A promise that resolves to an array of latest audits
|
|
127
|
-
* for the specified site.
|
|
128
|
-
*/
|
|
129
|
-
export const getLatestAuditsForSite = async (
|
|
130
|
-
dynamoClient,
|
|
131
|
-
config,
|
|
132
|
-
log,
|
|
133
|
-
siteId,
|
|
134
|
-
) => {
|
|
135
|
-
const queryParams = {
|
|
136
|
-
TableName: config.tableNameLatestAudits,
|
|
137
|
-
KeyConditionExpression: 'siteId = :siteId',
|
|
138
|
-
ExpressionAttributeValues: { ':siteId': siteId },
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const dynamoItems = await dynamoClient.query(queryParams);
|
|
142
|
-
|
|
143
|
-
return dynamoItems.map((item) => AuditDto.fromDynamoItem(item));
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Retrieves the latest audit for a specified site and audit type.
|
|
148
|
-
*
|
|
149
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
150
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
151
|
-
* @param {Logger} log - The log.
|
|
152
|
-
* @param {string} siteId - The ID of the site for which the latest audit is being retrieved.
|
|
153
|
-
* @param {string} auditType - The type of audit to retrieve the latest instance of.
|
|
154
|
-
* @returns {Promise<Audit|null>} A promise that resolves to the latest audit of the
|
|
155
|
-
* specified type for the site, or null if none is found.
|
|
156
|
-
*/
|
|
157
|
-
export const getLatestAuditForSite = async (
|
|
158
|
-
dynamoClient,
|
|
159
|
-
config,
|
|
160
|
-
log,
|
|
161
|
-
siteId,
|
|
162
|
-
auditType,
|
|
163
|
-
) => {
|
|
164
|
-
const latestAudit = await dynamoClient.getItem(config.tableNameLatestAudits, {
|
|
165
|
-
siteId,
|
|
166
|
-
auditType,
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
return latestAudit ? AuditDto.fromDynamoItem(latestAudit) : null;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Adds an audit.
|
|
174
|
-
*
|
|
175
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
176
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
177
|
-
* @param {Logger} log - The log.
|
|
178
|
-
* @param {object} auditData - The audit data.
|
|
179
|
-
* @returns {Promise<Readonly<Audit>>}
|
|
180
|
-
*/
|
|
181
|
-
export const addAudit = async (
|
|
182
|
-
dynamoClient,
|
|
183
|
-
config,
|
|
184
|
-
log,
|
|
185
|
-
auditData,
|
|
186
|
-
) => {
|
|
187
|
-
const newAudit = createAudit(auditData);
|
|
188
|
-
const existingAudit = await getAuditForSite(
|
|
189
|
-
dynamoClient,
|
|
190
|
-
config,
|
|
191
|
-
log,
|
|
192
|
-
newAudit.getSiteId(),
|
|
193
|
-
newAudit.getAuditType(),
|
|
194
|
-
newAudit.getAuditedAt(),
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
if (isObject(existingAudit)) {
|
|
198
|
-
throw new Error('Audit already exists');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const latestAudit = await getLatestAuditForSite(
|
|
202
|
-
dynamoClient,
|
|
203
|
-
config,
|
|
204
|
-
log,
|
|
205
|
-
newAudit.getSiteId(),
|
|
206
|
-
newAudit.getAuditType(),
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
if (isObject(latestAudit)) {
|
|
210
|
-
newAudit.setPreviousAuditResult({
|
|
211
|
-
...latestAudit.getAuditResult(),
|
|
212
|
-
auditedAt: latestAudit.getAuditedAt(),
|
|
213
|
-
fullAuditRef: latestAudit.getFullAuditRef(),
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// TODO: Add transaction support
|
|
218
|
-
await dynamoClient.putItem(config.tableNameAudits, AuditDto.toDynamoItem(newAudit));
|
|
219
|
-
await dynamoClient.putItem(
|
|
220
|
-
config.tableNameLatestAudits,
|
|
221
|
-
AuditDto.toDynamoItem(newAudit, true),
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
return newAudit;
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Removes audits from the database.
|
|
229
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
230
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
231
|
-
* @param audits
|
|
232
|
-
* @param latest
|
|
233
|
-
* @returns {Promise<void>}
|
|
234
|
-
*/
|
|
235
|
-
async function removeAudits(
|
|
236
|
-
dynamoClient,
|
|
237
|
-
config,
|
|
238
|
-
audits,
|
|
239
|
-
latest = false,
|
|
240
|
-
) {
|
|
241
|
-
const tableName = latest ? config.tableNameLatestAudits : config.tableNameAudits;
|
|
242
|
-
// TODO: use batch-remove (needs dynamo client update)
|
|
243
|
-
const removeAuditPromises = audits.map((audit) => {
|
|
244
|
-
const sortKey = latest
|
|
245
|
-
? { auditType: `${audit.getAuditType()}` }
|
|
246
|
-
: { SK: `${audit.getAuditType()}#${audit.getAuditedAt()}` };
|
|
247
|
-
return dynamoClient.removeItem(
|
|
248
|
-
tableName,
|
|
249
|
-
{
|
|
250
|
-
siteId: audit.getSiteId(),
|
|
251
|
-
...sortKey,
|
|
252
|
-
},
|
|
253
|
-
);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
await Promise.all(removeAuditPromises);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Removes all audits for a specified site and the latest audit entry.
|
|
261
|
-
*
|
|
262
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
263
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
264
|
-
* @param {Logger} log - The log.
|
|
265
|
-
* @param {string} siteId - The ID of the site for which audits are being removed.
|
|
266
|
-
* @returns {Promise<void>}
|
|
267
|
-
*/
|
|
268
|
-
export const removeAuditsForSite = async (
|
|
269
|
-
dynamoClient,
|
|
270
|
-
config,
|
|
271
|
-
log,
|
|
272
|
-
siteId,
|
|
273
|
-
) => {
|
|
274
|
-
try {
|
|
275
|
-
const audits = await getAuditsForSite(dynamoClient, config, log, siteId);
|
|
276
|
-
const latestAudits = await getLatestAuditsForSite(dynamoClient, config, log, siteId);
|
|
277
|
-
|
|
278
|
-
await removeAudits(dynamoClient, config, audits);
|
|
279
|
-
await removeAudits(dynamoClient, config, latestAudits, true);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
log.error(`Error removing audits for site ${siteId}: ${error.message}`);
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2023 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 {
|
|
14
|
-
addAudit,
|
|
15
|
-
getAuditForSite,
|
|
16
|
-
getAuditsForSite,
|
|
17
|
-
getLatestAuditForSite,
|
|
18
|
-
getLatestAudits,
|
|
19
|
-
getLatestAuditsForSite,
|
|
20
|
-
removeAuditsForSite,
|
|
21
|
-
} from './accessPatterns.js';
|
|
22
|
-
|
|
23
|
-
export const auditFunctions = (dynamoClient, config, log) => ({
|
|
24
|
-
getAuditForSite: (siteId, auditType, auditedAt) => getAuditForSite(
|
|
25
|
-
dynamoClient,
|
|
26
|
-
config,
|
|
27
|
-
log,
|
|
28
|
-
siteId,
|
|
29
|
-
auditType,
|
|
30
|
-
auditedAt,
|
|
31
|
-
),
|
|
32
|
-
getAuditsForSite: (siteId, auditType, ascending) => getAuditsForSite(
|
|
33
|
-
dynamoClient,
|
|
34
|
-
config,
|
|
35
|
-
log,
|
|
36
|
-
siteId,
|
|
37
|
-
auditType,
|
|
38
|
-
ascending,
|
|
39
|
-
),
|
|
40
|
-
getLatestAudits: (auditType, ascending) => getLatestAudits(
|
|
41
|
-
dynamoClient,
|
|
42
|
-
config,
|
|
43
|
-
log,
|
|
44
|
-
auditType,
|
|
45
|
-
ascending,
|
|
46
|
-
),
|
|
47
|
-
getLatestAuditForSite: (siteId, auditType) => getLatestAuditForSite(
|
|
48
|
-
dynamoClient,
|
|
49
|
-
config,
|
|
50
|
-
log,
|
|
51
|
-
siteId,
|
|
52
|
-
auditType,
|
|
53
|
-
),
|
|
54
|
-
getLatestAuditsForSite: (siteId) => getLatestAuditsForSite(
|
|
55
|
-
dynamoClient,
|
|
56
|
-
config,
|
|
57
|
-
log,
|
|
58
|
-
siteId,
|
|
59
|
-
),
|
|
60
|
-
addAudit: (auditData) => addAudit(
|
|
61
|
-
dynamoClient,
|
|
62
|
-
config,
|
|
63
|
-
log,
|
|
64
|
-
auditData,
|
|
65
|
-
),
|
|
66
|
-
removeAuditsForSite: (siteId) => removeAuditsForSite(
|
|
67
|
-
dynamoClient,
|
|
68
|
-
config,
|
|
69
|
-
log,
|
|
70
|
-
siteId,
|
|
71
|
-
),
|
|
72
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
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 {
|
|
14
|
-
isInteger,
|
|
15
|
-
isObject,
|
|
16
|
-
} from '@adobe/spacecat-shared-utils';
|
|
17
|
-
|
|
18
|
-
import { ConfigurationDto } from '../../dto/configuration.js';
|
|
19
|
-
import { createConfiguration } from '../../models/configuration.js';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Retrieves configuration with latest version.
|
|
23
|
-
*
|
|
24
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
25
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
26
|
-
* @returns {Promise<Readonly<Configuration>>} A promise that resolves to the configuration
|
|
27
|
-
* object if found, otherwise null.
|
|
28
|
-
*/
|
|
29
|
-
export const getConfiguration = async (
|
|
30
|
-
dynamoClient,
|
|
31
|
-
config,
|
|
32
|
-
) => {
|
|
33
|
-
const dynamoItems = await dynamoClient.query({
|
|
34
|
-
TableName: config.tableNameConfigurations,
|
|
35
|
-
KeyConditionExpression: 'PK = :pk',
|
|
36
|
-
ExpressionAttributeValues: {
|
|
37
|
-
':pk': config.pkAllConfigurations,
|
|
38
|
-
},
|
|
39
|
-
Limit: 1,
|
|
40
|
-
ScanIndexForward: false, // Sorts ascending if true, descending if false
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (dynamoItems.length === 0) return null;
|
|
44
|
-
return ConfigurationDto.fromDynamoItem(dynamoItems[0]);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves all configurations.
|
|
49
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
50
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
51
|
-
* @return {Promise<Readonly<Configuration>[]>} A promise that resolves to the configurations.
|
|
52
|
-
*/
|
|
53
|
-
export const getConfigurations = async (
|
|
54
|
-
dynamoClient,
|
|
55
|
-
config,
|
|
56
|
-
) => {
|
|
57
|
-
const dynamoItems = await dynamoClient.query({
|
|
58
|
-
TableName: config.tableNameConfigurations,
|
|
59
|
-
KeyConditionExpression: 'PK = :pk',
|
|
60
|
-
ExpressionAttributeValues: {
|
|
61
|
-
':pk': config.pkAllConfigurations,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return dynamoItems.map(ConfigurationDto.fromDynamoItem);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Retrieves a site by its version.
|
|
70
|
-
*
|
|
71
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
72
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
73
|
-
* @param {string} version - The version of the configuration to retrieve.
|
|
74
|
-
* @returns {Promise<Readonly<Configuration>|null>} A promise that resolves to the configuration
|
|
75
|
-
* object if found, otherwise null.
|
|
76
|
-
*/
|
|
77
|
-
export const getConfigurationByVersion = async (
|
|
78
|
-
dynamoClient,
|
|
79
|
-
config,
|
|
80
|
-
version,
|
|
81
|
-
) => {
|
|
82
|
-
const dynamoItem = await dynamoClient.getItem(config.tableNameConfigurations, {
|
|
83
|
-
PK: config.pkAllConfigurations,
|
|
84
|
-
version,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
return isObject(dynamoItem) ? ConfigurationDto.fromDynamoItem(dynamoItem) : null;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
function incrementVersion(version) {
|
|
91
|
-
if (!isInteger(version)) return 1;
|
|
92
|
-
|
|
93
|
-
const versionNumber = parseInt(version, 10);
|
|
94
|
-
return versionNumber + 1;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Updates the configuration. Updating the configuration will create a new version of the
|
|
99
|
-
* configuration. The version is a string of the format "v<version-number>", for example "v1".
|
|
100
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
101
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
102
|
-
* @param {Configuration} configurationData - The configuration data.
|
|
103
|
-
* @return {Promise<void>} A promise that resolves when the configuration is updated.
|
|
104
|
-
*/
|
|
105
|
-
export const updateConfiguration = async (
|
|
106
|
-
dynamoClient,
|
|
107
|
-
config,
|
|
108
|
-
configurationData,
|
|
109
|
-
) => {
|
|
110
|
-
const newConfigurationData = { ...configurationData };
|
|
111
|
-
const latestConfiguration = await getConfiguration(dynamoClient, config);
|
|
112
|
-
|
|
113
|
-
newConfigurationData.version = incrementVersion(latestConfiguration?.getVersion());
|
|
114
|
-
|
|
115
|
-
const newConfiguration = createConfiguration(newConfigurationData);
|
|
116
|
-
|
|
117
|
-
await dynamoClient.putItem(
|
|
118
|
-
config.tableNameConfigurations,
|
|
119
|
-
ConfigurationDto.toDynamoItem(newConfiguration),
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
return newConfiguration;
|
|
123
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
import {
|
|
13
|
-
getConfiguration,
|
|
14
|
-
getConfigurationByVersion,
|
|
15
|
-
getConfigurations,
|
|
16
|
-
updateConfiguration,
|
|
17
|
-
} from './accessPatterns.js';
|
|
18
|
-
|
|
19
|
-
export const configurationFunctions = (dynamoClient, config) => ({
|
|
20
|
-
getConfiguration: () => getConfiguration(
|
|
21
|
-
dynamoClient,
|
|
22
|
-
config,
|
|
23
|
-
),
|
|
24
|
-
getConfigurations: () => getConfigurations(
|
|
25
|
-
dynamoClient,
|
|
26
|
-
config,
|
|
27
|
-
),
|
|
28
|
-
getConfigurationByVersion: (version) => getConfigurationByVersion(
|
|
29
|
-
dynamoClient,
|
|
30
|
-
config,
|
|
31
|
-
version,
|
|
32
|
-
),
|
|
33
|
-
updateConfiguration: (configurationData) => updateConfiguration(
|
|
34
|
-
dynamoClient,
|
|
35
|
-
config,
|
|
36
|
-
configurationData,
|
|
37
|
-
),
|
|
38
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
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 { isObject } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
import { createExperiment } from '../../models/experiment.js';
|
|
15
|
-
import { ExperimentDto } from '../../dto/experiment.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Returns the experiment if exists in experiments table using siteId, experimentId and url
|
|
19
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
20
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
21
|
-
* @param {string} siteId - siteId of the experiment.
|
|
22
|
-
* @param {string} id - id of the experiment.
|
|
23
|
-
* @return the experiment if exists, null otherwise
|
|
24
|
-
*/
|
|
25
|
-
export const getExperiment = async (dynamoClient, config, siteId, experimentId, url) => {
|
|
26
|
-
const queryParams = {
|
|
27
|
-
TableName: config.tableNameExperiments,
|
|
28
|
-
KeyConditionExpression: 'siteId = :siteId AND SK = :SK',
|
|
29
|
-
ExpressionAttributeValues: {
|
|
30
|
-
':siteId': siteId,
|
|
31
|
-
':SK': `${experimentId}#${url}`,
|
|
32
|
-
},
|
|
33
|
-
ScanIndexForward: false,
|
|
34
|
-
};
|
|
35
|
-
const dynamoItems = await dynamoClient.query(queryParams);
|
|
36
|
-
if (dynamoItems != null && dynamoItems.length > 0 && isObject(dynamoItems[0])) {
|
|
37
|
-
return ExperimentDto.fromDynamoItem(dynamoItems[0]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return null;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Retrieves all experiments for a given siteId.
|
|
45
|
-
* @param {*} dynamoClient - The DynamoDB client.
|
|
46
|
-
* @param {*} config - The data access config.
|
|
47
|
-
* @param {*} log - the log object
|
|
48
|
-
* @param {*} siteId - siteId of the experiment.
|
|
49
|
-
* @param {*} experimentId - experiment id.
|
|
50
|
-
* @returns {Promise<ReadonlyArray<SiteCandidate>>} A promise that resolves to
|
|
51
|
-
* an array of experiments
|
|
52
|
-
*/
|
|
53
|
-
export const getExperiments = async (
|
|
54
|
-
dynamoClient,
|
|
55
|
-
config,
|
|
56
|
-
log,
|
|
57
|
-
siteId,
|
|
58
|
-
experimentId,
|
|
59
|
-
) => {
|
|
60
|
-
const queryParams = {
|
|
61
|
-
TableName: config.tableNameExperiments,
|
|
62
|
-
KeyConditionExpression: 'siteId = :siteId',
|
|
63
|
-
ExpressionAttributeValues: { ':siteId': siteId },
|
|
64
|
-
ScanIndexForward: false,
|
|
65
|
-
};
|
|
66
|
-
if (experimentId) {
|
|
67
|
-
queryParams.KeyConditionExpression += ' AND begins_with(SK, :experimentId)';
|
|
68
|
-
queryParams.ExpressionAttributeValues[':experimentId'] = experimentId;
|
|
69
|
-
}
|
|
70
|
-
const dynamoItems = await dynamoClient.query(queryParams);
|
|
71
|
-
|
|
72
|
-
return dynamoItems.map((item) => ExperimentDto.fromDynamoItem(item));
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Upserts an experiment.
|
|
77
|
-
*
|
|
78
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
79
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
80
|
-
* @param {object} log - the log object
|
|
81
|
-
* @param {object} experimentData - The experiment data.
|
|
82
|
-
* @returns {Promise<Readonly<SiteCandidate>>} A promise that resolves to newly created/updated
|
|
83
|
-
* experiment
|
|
84
|
-
*/
|
|
85
|
-
export const upsertExperiment = async (
|
|
86
|
-
dynamoClient,
|
|
87
|
-
config,
|
|
88
|
-
log,
|
|
89
|
-
experimentData,
|
|
90
|
-
) => {
|
|
91
|
-
const experiment = createExperiment(experimentData);
|
|
92
|
-
await dynamoClient.putItem(
|
|
93
|
-
config.tableNameExperiments,
|
|
94
|
-
ExperimentDto.toDynamoItem(experiment),
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return experiment;
|
|
98
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
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 {
|
|
14
|
-
getExperiments,
|
|
15
|
-
upsertExperiment,
|
|
16
|
-
getExperiment,
|
|
17
|
-
} from './accessPatterns.js';
|
|
18
|
-
|
|
19
|
-
export const experimentFunctions = (dynamoClient, config, log) => ({
|
|
20
|
-
getExperiments: (siteId, experimentId) => getExperiments(
|
|
21
|
-
dynamoClient,
|
|
22
|
-
config,
|
|
23
|
-
log,
|
|
24
|
-
siteId,
|
|
25
|
-
experimentId,
|
|
26
|
-
),
|
|
27
|
-
upsertExperiment: (experimentData) => upsertExperiment(
|
|
28
|
-
dynamoClient,
|
|
29
|
-
config,
|
|
30
|
-
log,
|
|
31
|
-
experimentData,
|
|
32
|
-
),
|
|
33
|
-
getExperiment: (siteId, experimentId, url) => getExperiment(
|
|
34
|
-
dynamoClient,
|
|
35
|
-
config,
|
|
36
|
-
siteId,
|
|
37
|
-
experimentId,
|
|
38
|
-
url,
|
|
39
|
-
),
|
|
40
|
-
});
|