@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,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
|
-
});
|
|
@@ -1,160 +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
|
-
|
|
15
|
-
import { createOrganization } from '../../models/organization.js';
|
|
16
|
-
import { OrganizationDto } from '../../dto/organization.js';
|
|
17
|
-
import { removeSitesForOrganization } from '../sites/accessPatterns.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves all organizations.
|
|
21
|
-
*
|
|
22
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
23
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
24
|
-
* @returns {Promise<Readonly<Organization>[]>} A promise that resolves to an array of all
|
|
25
|
-
* organizations.
|
|
26
|
-
*/
|
|
27
|
-
export const getOrganizations = async (dynamoClient, config) => {
|
|
28
|
-
const dynamoItems = await dynamoClient.query({
|
|
29
|
-
TableName: config.tableNameOrganizations,
|
|
30
|
-
IndexName: config.indexNameAllOrganizations,
|
|
31
|
-
KeyConditionExpression: 'GSI1PK = :gsi1pk',
|
|
32
|
-
ExpressionAttributeValues: {
|
|
33
|
-
':gsi1pk': config.pkAllOrganizations,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return dynamoItems.map((dynamoItem) => OrganizationDto.fromDynamoItem(dynamoItem));
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const getOrganizationByID = async (
|
|
41
|
-
dynamoClient,
|
|
42
|
-
config,
|
|
43
|
-
organizationId,
|
|
44
|
-
) => {
|
|
45
|
-
const dynamoItem = await dynamoClient.getItem(
|
|
46
|
-
config.tableNameOrganizations,
|
|
47
|
-
{ id: organizationId },
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
return isObject(dynamoItem) ? OrganizationDto.fromDynamoItem(dynamoItem) : null;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves an organization by its IMS org ID.
|
|
55
|
-
*
|
|
56
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
57
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
58
|
-
* @param {string} imsOrgId - Organization identifier on IMS, in the format of {id}@AdobeOrg
|
|
59
|
-
* @returns {Promise<Readonly<Organization>>} A promise that resolves to an organization, if found.
|
|
60
|
-
*/
|
|
61
|
-
export const getOrganizationByImsOrgID = async (
|
|
62
|
-
dynamoClient,
|
|
63
|
-
config,
|
|
64
|
-
imsOrgId,
|
|
65
|
-
) => {
|
|
66
|
-
const dynamoItems = await dynamoClient.query({
|
|
67
|
-
TableName: config.tableNameOrganizations,
|
|
68
|
-
IndexName: config.indexNameAllOrganizationsByImsOrgId,
|
|
69
|
-
KeyConditionExpression: 'imsOrgId = :imsOrgId',
|
|
70
|
-
ExpressionAttributeValues: {
|
|
71
|
-
':imsOrgId': imsOrgId,
|
|
72
|
-
},
|
|
73
|
-
Limit: 1,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return dynamoItems.length > 0 ? OrganizationDto.fromDynamoItem(dynamoItems[0]) : null;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Adds an organization.
|
|
81
|
-
*
|
|
82
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
83
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
84
|
-
* @param {Logger} log - The log.
|
|
85
|
-
* @param {object} organizationData - The organization data.
|
|
86
|
-
* @returns {Promise<Readonly<Organization>>}
|
|
87
|
-
*/
|
|
88
|
-
export const addOrganization = async (
|
|
89
|
-
dynamoClient,
|
|
90
|
-
config,
|
|
91
|
-
log,
|
|
92
|
-
organizationData,
|
|
93
|
-
) => {
|
|
94
|
-
const organization = createOrganization(organizationData);
|
|
95
|
-
|
|
96
|
-
await dynamoClient.putItem(
|
|
97
|
-
config.tableNameOrganizations,
|
|
98
|
-
OrganizationDto.toDynamoItem(organization),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
return organization;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Updates an organization.
|
|
106
|
-
*
|
|
107
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
108
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
109
|
-
* @param {Logger} log - The log.
|
|
110
|
-
* @param {Organization} organization - The organization.
|
|
111
|
-
* @returns {Promise<Readonly<Organization>>} - The updated organization.
|
|
112
|
-
*/
|
|
113
|
-
export const updateOrganization = async (
|
|
114
|
-
dynamoClient,
|
|
115
|
-
config,
|
|
116
|
-
log,
|
|
117
|
-
organization,
|
|
118
|
-
) => {
|
|
119
|
-
const existingOrganization = await getOrganizationByID(
|
|
120
|
-
dynamoClient,
|
|
121
|
-
config,
|
|
122
|
-
organization.getId(),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
if (!isObject(existingOrganization)) {
|
|
126
|
-
throw new Error('Organization not found');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
await dynamoClient.putItem(
|
|
130
|
-
config.tableNameOrganizations,
|
|
131
|
-
OrganizationDto.toDynamoItem(organization),
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
return organization;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Removes an organization.
|
|
139
|
-
*
|
|
140
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
141
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
142
|
-
* @param {Logger} log - The log.
|
|
143
|
-
* @param {string} organizationId - The ID of the organization to remove.
|
|
144
|
-
* @returns {Promise<void>}
|
|
145
|
-
*/
|
|
146
|
-
export const removeOrganization = async (
|
|
147
|
-
dynamoClient,
|
|
148
|
-
config,
|
|
149
|
-
log,
|
|
150
|
-
organizationId,
|
|
151
|
-
) => {
|
|
152
|
-
try {
|
|
153
|
-
await removeSitesForOrganization(dynamoClient, config, log, organizationId);
|
|
154
|
-
|
|
155
|
-
await dynamoClient.removeItem(config.tableNameOrganizations, { id: organizationId });
|
|
156
|
-
} catch (error) {
|
|
157
|
-
log.error(`Error removing organization: ${error.message}`);
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
};
|