@adobe/spacecat-shared-data-access 1.47.0 → 1.48.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 +14 -0
- package/package.json +1 -1
- package/src/index.d.ts +1 -1
- package/src/models/api-key.js +1 -0
- package/src/models/site/config.js +6 -6
- package/src/service/import-job/accessPatterns.js +20 -0
- package/src/service/import-job/index.js +9 -2
- package/src/service/import-url/accessPatterns.js +39 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.48.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.47.1...@adobe/spacecat-shared-data-access-v1.48.0) (2024-10-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Support import job deletion ([#400](https://github.com/adobe/spacecat-shared/issues/400)) ([d5a9df6](https://github.com/adobe/spacecat-shared/commit/d5a9df68f103b34adab87dfc78cc5bca7aa99ebc))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-data-access-v1.47.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.47.0...@adobe/spacecat-shared-data-access-v1.47.1) (2024-10-07)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* gracefully handle config in case handler is not defined ([#396](https://github.com/adobe/spacecat-shared/issues/396)) ([a4c8abd](https://github.com/adobe/spacecat-shared/commit/a4c8abdf4c99cfc32b1d92233eb8786f439320f1))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-data-access-v1.47.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.46.1...@adobe/spacecat-shared-data-access-v1.47.0) (2024-10-07)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -890,7 +890,7 @@ interface DataAccessConfig {
|
|
|
890
890
|
indexNameAllOrganizationsByImsOrgId: string,
|
|
891
891
|
indexNameAllImportJobsByStatus: string,
|
|
892
892
|
indexNameAllImportJobsByDateRange: string,
|
|
893
|
-
|
|
893
|
+
indexNameImportUrlsByJobIdAndStatus: string,
|
|
894
894
|
indexNameApiKeyByHashedApiKey: string,
|
|
895
895
|
pkAllSites: string;
|
|
896
896
|
pkAllLatestAudits: string;
|
package/src/models/api-key.js
CHANGED
|
@@ -57,14 +57,14 @@ export const Config = (data = {}) => {
|
|
|
57
57
|
const state = { ...validConfig };
|
|
58
58
|
const self = { state };
|
|
59
59
|
self.getSlackConfig = () => state.slack;
|
|
60
|
-
self.getSlackMentions = (type) => state?.handlers[type]?.mentions?.slack;
|
|
61
|
-
self.getHandlerConfig = (type) => state?.handlers[type];
|
|
60
|
+
self.getSlackMentions = (type) => state?.handlers?.[type]?.mentions?.slack;
|
|
61
|
+
self.getHandlerConfig = (type) => state?.handlers?.[type];
|
|
62
62
|
self.getHandlers = () => state.handlers;
|
|
63
63
|
self.getImports = () => state.imports;
|
|
64
|
-
self.getExcludedURLs = (type) => state?.handlers[type]?.excludedURLs;
|
|
65
|
-
self.getManualOverwrites = (type) => state?.handlers[type]?.manualOverwrites;
|
|
66
|
-
self.getFixedURLs = (type) => state?.handlers[type]?.fixedURLs;
|
|
67
|
-
self.getIncludedURLs = (type) => state?.handlers[type]?.includedURLs;
|
|
64
|
+
self.getExcludedURLs = (type) => state?.handlers?.[type]?.excludedURLs;
|
|
65
|
+
self.getManualOverwrites = (type) => state?.handlers?.[type]?.manualOverwrites;
|
|
66
|
+
self.getFixedURLs = (type) => state?.handlers?.[type]?.fixedURLs;
|
|
67
|
+
self.getIncludedURLs = (type) => state?.handlers?.[type]?.includedURLs;
|
|
68
68
|
|
|
69
69
|
self.updateSlackConfig = (channel, workspace, invitedUserCount) => {
|
|
70
70
|
state.slack = {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { isObject } from '@adobe/spacecat-shared-utils';
|
|
14
14
|
import { ImportJobDto } from '../../dto/import-job.js';
|
|
15
15
|
import { createImportJob } from '../../models/importer/import-job.js';
|
|
16
|
+
import { removeUrlsForImportJob } from '../import-url/accessPatterns.js';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Get all Import Jobs within a specific date range
|
|
@@ -112,3 +113,22 @@ export const updateImportJob = async (dynamoClient, config, log, importJob) => {
|
|
|
112
113
|
|
|
113
114
|
return importJob;
|
|
114
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 logger.
|
|
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
|
+
};
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
getImportJobsByStatus,
|
|
17
17
|
updateImportJob,
|
|
18
18
|
getImportJobsByDateRange,
|
|
19
|
+
removeImportJob,
|
|
19
20
|
} from './accessPatterns.js';
|
|
20
21
|
|
|
21
22
|
export const importJobFunctions = (dynamoClient, config, log) => ({
|
|
@@ -44,10 +45,16 @@ export const importJobFunctions = (dynamoClient, config, log) => ({
|
|
|
44
45
|
log,
|
|
45
46
|
importJobData,
|
|
46
47
|
),
|
|
47
|
-
updateImportJob: (
|
|
48
|
+
updateImportJob: (importJob) => updateImportJob(
|
|
48
49
|
dynamoClient,
|
|
49
50
|
config,
|
|
50
51
|
log,
|
|
51
|
-
|
|
52
|
+
importJob,
|
|
53
|
+
),
|
|
54
|
+
removeImportJob: (importJob) => removeImportJob(
|
|
55
|
+
dynamoClient,
|
|
56
|
+
config,
|
|
57
|
+
log,
|
|
58
|
+
importJob,
|
|
52
59
|
),
|
|
53
60
|
});
|
|
@@ -99,11 +99,11 @@ export const getImportUrlsByJobIdAndStatus = async (dynamoClient, config, log, j
|
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
101
|
* Get Import Urls by Job ID, if no urls exist an empty array is returned.
|
|
102
|
-
* @param {
|
|
103
|
-
* @param {
|
|
104
|
-
* @param {Logger} log
|
|
105
|
-
* @param {string} jobId
|
|
106
|
-
* @returns {Promise<
|
|
102
|
+
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
103
|
+
* @param {DataAccessConfig} config - The data access config.
|
|
104
|
+
* @param {Logger} log - The logger.
|
|
105
|
+
* @param {string} jobId - The ID of the import job.
|
|
106
|
+
* @returns {Promise<ImportUrl[]>}
|
|
107
107
|
*/
|
|
108
108
|
export const getImportUrlsByJobId = async (dynamoClient, config, log, jobId) => {
|
|
109
109
|
const items = await dynamoClient.query({
|
|
@@ -117,3 +117,37 @@ export const getImportUrlsByJobId = async (dynamoClient, config, log, jobId) =>
|
|
|
117
117
|
|
|
118
118
|
return items ? items.map((item) => ImportUrlDto.fromDynamoItem(item)) : [];
|
|
119
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 logger.
|
|
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
|
+
};
|