@adobe/spacecat-shared-data-access 1.61.18 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/package.json +1 -2
- package/src/index.d.ts +4 -934
- package/src/index.js +1 -91
- package/src/{v2/models → models}/base/base.model.js +16 -3
- 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/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,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
|
-
});
|
|
@@ -1,134 +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 { ImportJobDto } from '../../dto/import-job.js';
|
|
15
|
-
import { createImportJob } from '../../models/importer/import-job.js';
|
|
16
|
-
import { removeUrlsForImportJob } from '../import-url/accessPatterns.js';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get all Import Jobs within a specific date range
|
|
20
|
-
* @param {DynamoClient} dynamoClient
|
|
21
|
-
* @param {Object} config
|
|
22
|
-
* @param {Logger} log
|
|
23
|
-
* @param {string} startDate
|
|
24
|
-
* @param {string} endDate
|
|
25
|
-
*/
|
|
26
|
-
export const getImportJobsByDateRange = async (dynamoClient, config, log, startDate, endDate) => {
|
|
27
|
-
const items = await dynamoClient.query({
|
|
28
|
-
TableName: config.tableNameImportJobs,
|
|
29
|
-
IndexName: config.indexNameAllImportJobsByDateRange,
|
|
30
|
-
KeyConditionExpression: 'GSI1PK = :gsi1pk AND #startTime BETWEEN :startDate AND :endDate',
|
|
31
|
-
ExpressionAttributeNames: {
|
|
32
|
-
'#startTime': 'startTime',
|
|
33
|
-
},
|
|
34
|
-
ExpressionAttributeValues: {
|
|
35
|
-
':gsi1pk': config.pkAllImportJobs,
|
|
36
|
-
':startDate': startDate,
|
|
37
|
-
':endDate': endDate,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
return items.map((item) => ImportJobDto.fromDynamoItem(item));
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Get Import Job by ID.
|
|
45
|
-
* @param {DynamoClient} dynamoClient
|
|
46
|
-
* @param {Object} config
|
|
47
|
-
* @param {Logger} log
|
|
48
|
-
* @param {string} id
|
|
49
|
-
* @returns {Promise<ImportJobDto> | null}
|
|
50
|
-
*/
|
|
51
|
-
export const getImportJobByID = async (dynamoClient, config, log, id) => {
|
|
52
|
-
const item = await dynamoClient.getItem(
|
|
53
|
-
config.tableNameImportJobs,
|
|
54
|
-
{ id },
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
return item ? ImportJobDto.fromDynamoItem(item) : null;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Get Import jobs by status
|
|
62
|
-
* @param {DynamoClient} dynamoClient
|
|
63
|
-
* @param {Object} config
|
|
64
|
-
* @param {Logger} log
|
|
65
|
-
* @param {string} status
|
|
66
|
-
* @returns {Promise<ImportJobDto[]>}
|
|
67
|
-
*/
|
|
68
|
-
export const getImportJobsByStatus = async (dynamoClient, config, log, status) => {
|
|
69
|
-
const items = await dynamoClient.query({
|
|
70
|
-
TableName: config.tableNameImportJobs,
|
|
71
|
-
IndexName: config.indexNameAllImportJobsByStatus,
|
|
72
|
-
KeyConditionExpression: 'GSI1PK = :gsi1pk AND #status = :status',
|
|
73
|
-
ExpressionAttributeNames: {
|
|
74
|
-
'#status': 'status',
|
|
75
|
-
},
|
|
76
|
-
ExpressionAttributeValues: {
|
|
77
|
-
':gsi1pk': config.pkAllImportJobs,
|
|
78
|
-
':status': status,
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
return items.map((item) => ImportJobDto.fromDynamoItem(item));
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Creates a new Import Job
|
|
86
|
-
* @param {DynamoClient} dynamoClient
|
|
87
|
-
* @param {Object} config
|
|
88
|
-
* @param {Logger} log
|
|
89
|
-
* @param {Object} importJobData
|
|
90
|
-
* @returns {Promise<ImportJobDto>}
|
|
91
|
-
*/
|
|
92
|
-
export const createNewImportJob = async (dynamoClient, config, log, importJobData) => {
|
|
93
|
-
const importJob = createImportJob(importJobData);
|
|
94
|
-
await dynamoClient.putItem(config.tableNameImportJobs, ImportJobDto.toDynamoItem(importJob));
|
|
95
|
-
return importJob;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Updates an Import Job
|
|
100
|
-
* @param {DynamoClient} dynamoClient
|
|
101
|
-
* @param {Object} config
|
|
102
|
-
* @param {Logger} log
|
|
103
|
-
* @param {ImportJobDto} importJob
|
|
104
|
-
*/
|
|
105
|
-
export const updateImportJob = async (dynamoClient, config, log, importJob) => {
|
|
106
|
-
const existingImportJob = await getImportJobByID(dynamoClient, config, log, importJob.getId());
|
|
107
|
-
|
|
108
|
-
if (!isObject(existingImportJob)) {
|
|
109
|
-
throw new Error(`Import Job with id: ${importJob.getId()} does not exist`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
await dynamoClient.putItem(config.tableNameImportJobs, ImportJobDto.toDynamoItem(importJob));
|
|
113
|
-
|
|
114
|
-
return importJob;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Removes an Import Job and all associated URLs.
|
|
119
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
120
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
121
|
-
* @param {Logger} log - The log.
|
|
122
|
-
* @param {ImportJob} importJob - The import job to remove.
|
|
123
|
-
* @return {Promise<void>} A promise that resolves when the import job has been removed.
|
|
124
|
-
*/
|
|
125
|
-
export const removeImportJob = async (dynamoClient, config, log, importJob) => {
|
|
126
|
-
try {
|
|
127
|
-
await removeUrlsForImportJob(dynamoClient, config, log, importJob.getId());
|
|
128
|
-
|
|
129
|
-
await dynamoClient.removeItem(config.tableNameImportJobs, { id: importJob.getId() });
|
|
130
|
-
} catch (error) {
|
|
131
|
-
log.error(`Error removing import job: ${error.message}`);
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
@@ -1,60 +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
|
-
createNewImportJob,
|
|
15
|
-
getImportJobByID,
|
|
16
|
-
getImportJobsByStatus,
|
|
17
|
-
updateImportJob,
|
|
18
|
-
getImportJobsByDateRange,
|
|
19
|
-
removeImportJob,
|
|
20
|
-
} from './accessPatterns.js';
|
|
21
|
-
|
|
22
|
-
export const importJobFunctions = (dynamoClient, config, log) => ({
|
|
23
|
-
getImportJobsByDateRange: (startDate, endDate) => getImportJobsByDateRange(
|
|
24
|
-
dynamoClient,
|
|
25
|
-
config,
|
|
26
|
-
log,
|
|
27
|
-
startDate,
|
|
28
|
-
endDate,
|
|
29
|
-
),
|
|
30
|
-
getImportJobByID: (id) => getImportJobByID(
|
|
31
|
-
dynamoClient,
|
|
32
|
-
config,
|
|
33
|
-
log,
|
|
34
|
-
id,
|
|
35
|
-
),
|
|
36
|
-
getImportJobsByStatus: (status) => getImportJobsByStatus(
|
|
37
|
-
dynamoClient,
|
|
38
|
-
config,
|
|
39
|
-
log,
|
|
40
|
-
status,
|
|
41
|
-
),
|
|
42
|
-
createNewImportJob: (importJobData) => createNewImportJob(
|
|
43
|
-
dynamoClient,
|
|
44
|
-
config,
|
|
45
|
-
log,
|
|
46
|
-
importJobData,
|
|
47
|
-
),
|
|
48
|
-
updateImportJob: (importJob) => updateImportJob(
|
|
49
|
-
dynamoClient,
|
|
50
|
-
config,
|
|
51
|
-
log,
|
|
52
|
-
importJob,
|
|
53
|
-
),
|
|
54
|
-
removeImportJob: (importJob) => removeImportJob(
|
|
55
|
-
dynamoClient,
|
|
56
|
-
config,
|
|
57
|
-
log,
|
|
58
|
-
importJob,
|
|
59
|
-
),
|
|
60
|
-
});
|
|
@@ -1,153 +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 { ImportUrlDto } from '../../dto/import-url.js';
|
|
15
|
-
import { createImportUrl } from '../../models/importer/import-url.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get import url by ID
|
|
19
|
-
* @param {DynamoClient} dynamoClient
|
|
20
|
-
* @param {Object} config
|
|
21
|
-
* @param {Logger} log
|
|
22
|
-
* @param {string} id
|
|
23
|
-
* @returns {Promise<ImportUrlDto> | null}
|
|
24
|
-
*/
|
|
25
|
-
export const getImportUrlById = async (dynamoClient, config, log, id) => {
|
|
26
|
-
const item = await dynamoClient.getItem(
|
|
27
|
-
config.tableNameImportUrls,
|
|
28
|
-
{ id },
|
|
29
|
-
);
|
|
30
|
-
return item ? ImportUrlDto.fromDynamoItem(item) : null;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Create a new Import Url
|
|
35
|
-
* @param {DynamoClient} dynamoClient
|
|
36
|
-
* @param {Object} config
|
|
37
|
-
* @param {Logger} log
|
|
38
|
-
* @param {Object} importUrlData
|
|
39
|
-
* @returns {Promise<ImportUrlDto>}
|
|
40
|
-
*/
|
|
41
|
-
export const createNewImportUrl = async (dynamoClient, config, log, importUrlData) => {
|
|
42
|
-
const importUrl = createImportUrl(importUrlData);
|
|
43
|
-
await dynamoClient.putItem(
|
|
44
|
-
config.tableNameImportUrls,
|
|
45
|
-
ImportUrlDto.toDynamoItem(importUrl),
|
|
46
|
-
);
|
|
47
|
-
return importUrl;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Update an existing Import Url
|
|
52
|
-
* @param {DynamoClient} dynamoClient
|
|
53
|
-
* @param {Object} config
|
|
54
|
-
* @param {Logger} log
|
|
55
|
-
* @param {Object} importUrl
|
|
56
|
-
* @returns {ImportUrlDto}
|
|
57
|
-
*/
|
|
58
|
-
export const updateImportUrl = async (dynamoClient, config, log, importUrl) => {
|
|
59
|
-
const existingImportUrl = await getImportUrlById(
|
|
60
|
-
dynamoClient,
|
|
61
|
-
config,
|
|
62
|
-
log,
|
|
63
|
-
importUrl.getId(),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
if (!isObject(existingImportUrl)) {
|
|
67
|
-
throw new Error(`Import Url with ID: ${importUrl.getId()} does not exist`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
await dynamoClient.putItem(config.tableNameImportUrls, ImportUrlDto.toDynamoItem(importUrl));
|
|
71
|
-
|
|
72
|
-
return importUrl;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Get Import Urls by Job ID and Status
|
|
77
|
-
* @param {DynamoClient} dynamoClient
|
|
78
|
-
* @param {Object} config
|
|
79
|
-
* @param {Logger} log
|
|
80
|
-
* @param {string} jobId
|
|
81
|
-
* @param {string} status
|
|
82
|
-
* @returns {Promise<ImportUrl[]>}
|
|
83
|
-
*/
|
|
84
|
-
export const getImportUrlsByJobIdAndStatus = async (dynamoClient, config, log, jobId, status) => {
|
|
85
|
-
const items = await dynamoClient.query({
|
|
86
|
-
TableName: config.tableNameImportUrls,
|
|
87
|
-
IndexName: config.indexNameImportUrlsByJobIdAndStatus,
|
|
88
|
-
KeyConditionExpression: 'jobId = :jobId AND #status = :status',
|
|
89
|
-
ExpressionAttributeNames: {
|
|
90
|
-
'#status': 'status',
|
|
91
|
-
},
|
|
92
|
-
ExpressionAttributeValues: {
|
|
93
|
-
':jobId': jobId,
|
|
94
|
-
':status': status,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
return items.map((item) => ImportUrlDto.fromDynamoItem(item));
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get Import Urls by Job ID, if no urls exist an empty array is returned.
|
|
102
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
103
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
104
|
-
* @param {Logger} log - The log.
|
|
105
|
-
* @param {string} jobId - The ID of the import job.
|
|
106
|
-
* @returns {Promise<ImportUrl[]>}
|
|
107
|
-
*/
|
|
108
|
-
export const getImportUrlsByJobId = async (dynamoClient, config, log, jobId) => {
|
|
109
|
-
const items = await dynamoClient.query({
|
|
110
|
-
TableName: config.tableNameImportUrls,
|
|
111
|
-
IndexName: config.indexNameImportUrlsByJobIdAndStatus,
|
|
112
|
-
KeyConditionExpression: 'jobId = :jobId',
|
|
113
|
-
ExpressionAttributeValues: {
|
|
114
|
-
':jobId': jobId,
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
return items ? items.map((item) => ImportUrlDto.fromDynamoItem(item)) : [];
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Remove all given import URLs.
|
|
123
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
124
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
125
|
-
* @param {ImportUrl[]} urls - The import URLs to remove.
|
|
126
|
-
* @return {Promise<void>} A promise that resolves when all URLs have been removed.
|
|
127
|
-
*/
|
|
128
|
-
async function removeUrls(dynamoClient, config, urls) {
|
|
129
|
-
const removeUrlPromises = urls.map((url) => dynamoClient.removeItem(
|
|
130
|
-
config.tableNameImportUrls,
|
|
131
|
-
{ id: url.getId() },
|
|
132
|
-
));
|
|
133
|
-
|
|
134
|
-
await Promise.all(removeUrlPromises);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Remove all URLs associated with an import job.
|
|
139
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
140
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
141
|
-
* @param {Logger} log - The log.
|
|
142
|
-
* @param {string} jobId - The ID of the import job.
|
|
143
|
-
* @return {Promise<void>} A promise that resolves when all URLs have been removed.
|
|
144
|
-
*/
|
|
145
|
-
export const removeUrlsForImportJob = async (dynamoClient, config, log, jobId) => {
|
|
146
|
-
try {
|
|
147
|
-
const urls = await getImportUrlsByJobId(dynamoClient, config, log, jobId);
|
|
148
|
-
await removeUrls(dynamoClient, config, urls);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
log.error(`Error removing urls for import jobId: ${jobId} : ${error.message}`);
|
|
151
|
-
throw error;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
@@ -1,53 +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
|
-
getImportUrlById,
|
|
15
|
-
createNewImportUrl,
|
|
16
|
-
updateImportUrl,
|
|
17
|
-
getImportUrlsByJobIdAndStatus,
|
|
18
|
-
getImportUrlsByJobId,
|
|
19
|
-
} from './accessPatterns.js';
|
|
20
|
-
|
|
21
|
-
export const importUrlFunctions = (dynamoClient, config, log) => ({
|
|
22
|
-
getImportUrlById: (id) => getImportUrlById(
|
|
23
|
-
dynamoClient,
|
|
24
|
-
config,
|
|
25
|
-
log,
|
|
26
|
-
id,
|
|
27
|
-
),
|
|
28
|
-
createNewImportUrl: (importUrlData) => createNewImportUrl(
|
|
29
|
-
dynamoClient,
|
|
30
|
-
config,
|
|
31
|
-
log,
|
|
32
|
-
importUrlData,
|
|
33
|
-
),
|
|
34
|
-
updateImportUrl: (importUrl) => updateImportUrl(
|
|
35
|
-
dynamoClient,
|
|
36
|
-
config,
|
|
37
|
-
log,
|
|
38
|
-
importUrl,
|
|
39
|
-
),
|
|
40
|
-
getImportUrlsByJobIdAndStatus: (jobId, status) => getImportUrlsByJobIdAndStatus(
|
|
41
|
-
dynamoClient,
|
|
42
|
-
config,
|
|
43
|
-
log,
|
|
44
|
-
jobId,
|
|
45
|
-
status,
|
|
46
|
-
),
|
|
47
|
-
getImportUrlsByJobId: (jobId) => getImportUrlsByJobId(
|
|
48
|
-
dynamoClient,
|
|
49
|
-
config,
|
|
50
|
-
log,
|
|
51
|
-
jobId,
|
|
52
|
-
),
|
|
53
|
-
});
|
|
@@ -1,92 +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 { createKeyEvent } from '../../models/key-event.js';
|
|
14
|
-
import { KeyEventDto } from '../../dto/key-event.js';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Adds a new key event for a site.
|
|
18
|
-
*
|
|
19
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
20
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
21
|
-
* @param {object} log - the log object
|
|
22
|
-
* @param {object} keyEventData - The key event data.
|
|
23
|
-
* @returns {Promise<Readonly<KeyEvent>>} newly created key event
|
|
24
|
-
*/
|
|
25
|
-
export const addKeyEvent = async (
|
|
26
|
-
dynamoClient,
|
|
27
|
-
config,
|
|
28
|
-
log,
|
|
29
|
-
keyEventData,
|
|
30
|
-
) => {
|
|
31
|
-
const keyEvent = createKeyEvent(keyEventData);
|
|
32
|
-
|
|
33
|
-
await dynamoClient.putItem(
|
|
34
|
-
config.tableNameKeyEvents,
|
|
35
|
-
KeyEventDto.toDynamoItem(keyEvent),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
return keyEvent;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Retrieves key events for a specified site.
|
|
43
|
-
*
|
|
44
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
45
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
46
|
-
* @param {Logger} log - The log.
|
|
47
|
-
* @param {string} siteId - The ID of the site for which key events are being retrieved.
|
|
48
|
-
* @param {boolean} ascending - Determines if the key events should be sorted ascending
|
|
49
|
-
* or descending by createdAt.
|
|
50
|
-
* @returns {Promise<Readonly<KeyEvent>[]>} A promise that resolves to an array of key events
|
|
51
|
-
* for the specified site.
|
|
52
|
-
*/
|
|
53
|
-
export const getKeyEventsForSite = async (
|
|
54
|
-
dynamoClient,
|
|
55
|
-
config,
|
|
56
|
-
log,
|
|
57
|
-
siteId,
|
|
58
|
-
ascending = false,
|
|
59
|
-
) => {
|
|
60
|
-
const dynamoItems = await dynamoClient.query({
|
|
61
|
-
TableName: config.tableNameKeyEvents,
|
|
62
|
-
IndexName: config.indexNameAllKeyEventsBySiteId,
|
|
63
|
-
KeyConditionExpression: 'siteId = :siteId',
|
|
64
|
-
ExpressionAttributeValues: { ':siteId': siteId },
|
|
65
|
-
ScanIndexForward: ascending, // Sorts ascending if true, descending if false
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return dynamoItems.map((item) => KeyEventDto.fromDynamoItem(item));
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Removes a key event.
|
|
73
|
-
*
|
|
74
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
75
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
76
|
-
* @param {Logger} log - The log.
|
|
77
|
-
* @param {string} keyEventId - The ID of the key event to remove.
|
|
78
|
-
* @returns {Promise<void>}
|
|
79
|
-
*/
|
|
80
|
-
export const removeKeyEvent = async (
|
|
81
|
-
dynamoClient,
|
|
82
|
-
config,
|
|
83
|
-
log,
|
|
84
|
-
keyEventId,
|
|
85
|
-
) => {
|
|
86
|
-
try {
|
|
87
|
-
await dynamoClient.removeItem(config.tableNameKeyEvents, { id: keyEventId });
|
|
88
|
-
} catch (error) {
|
|
89
|
-
log.error(`Error removing key event: ${error.message}`);
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
};
|
|
@@ -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
|
-
|
|
13
|
-
import {
|
|
14
|
-
addKeyEvent,
|
|
15
|
-
getKeyEventsForSite,
|
|
16
|
-
removeKeyEvent,
|
|
17
|
-
} from './accessPatterns.js';
|
|
18
|
-
|
|
19
|
-
export const keyEventFunctions = (dynamoClient, config, log) => ({
|
|
20
|
-
createKeyEvent: (keyEventData) => addKeyEvent(
|
|
21
|
-
dynamoClient,
|
|
22
|
-
config,
|
|
23
|
-
log,
|
|
24
|
-
keyEventData,
|
|
25
|
-
),
|
|
26
|
-
getKeyEventsForSite: (siteId) => getKeyEventsForSite(
|
|
27
|
-
dynamoClient,
|
|
28
|
-
config,
|
|
29
|
-
log,
|
|
30
|
-
siteId,
|
|
31
|
-
),
|
|
32
|
-
removeKeyEvent: (keyEventId) => removeKeyEvent(
|
|
33
|
-
dynamoClient,
|
|
34
|
-
config,
|
|
35
|
-
log,
|
|
36
|
-
keyEventId,
|
|
37
|
-
),
|
|
38
|
-
});
|