@adobe/spacecat-shared-data-access 1.47.1 → 1.48.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-data-access-v1.48.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.48.0...@adobe/spacecat-shared-data-access-v1.48.1) (2024-10-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update external fixes ([#402](https://github.com/adobe/spacecat-shared/issues/402)) ([9a5acba](https://github.com/adobe/spacecat-shared/commit/9a5acba2773b83ce26f4ac97e04d8ad24b00d8ce))
7
+
8
+ # [@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)
9
+
10
+
11
+ ### Features
12
+
13
+ * Support import job deletion ([#400](https://github.com/adobe/spacecat-shared/issues/400)) ([d5a9df6](https://github.com/adobe/spacecat-shared/commit/d5a9df68f103b34adab87dfc78cc5bca7aa99ebc))
14
+
1
15
  # [@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)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-data-access",
3
- "version": "1.47.1",
3
+ "version": "1.48.1",
4
4
  "description": "Shared modules of the Spacecat Services - Data Access",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,8 +35,8 @@
35
35
  "dependencies": {
36
36
  "@adobe/spacecat-shared-dynamo": "1.2.5",
37
37
  "@adobe/spacecat-shared-utils": "1.2.0",
38
- "@aws-sdk/client-dynamodb": "3.665.0",
39
- "@aws-sdk/lib-dynamodb": "3.665.0",
38
+ "@aws-sdk/client-dynamodb": "3.670.0",
39
+ "@aws-sdk/lib-dynamodb": "3.670.0",
40
40
  "@types/joi": "17.2.3",
41
41
  "joi": "17.13.3",
42
42
  "uuid": "10.0.0"
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
- indexNameAllImportUrlsByJobIdAndStatus: string,
893
+ indexNameImportUrlsByJobIdAndStatus: string,
894
894
  indexNameApiKeyByHashedApiKey: string,
895
895
  pkAllSites: string;
896
896
  pkAllLatestAudits: string;
@@ -25,6 +25,7 @@ const scopeNames = [
25
25
  'audits.write_all',
26
26
  'imports.read',
27
27
  'imports.write',
28
+ 'imports.delete',
28
29
  'imports.read_all',
29
30
  'imports.all_domains',
30
31
  ];
@@ -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: (importJobData) => updateImportJob(
48
+ updateImportJob: (importJob) => updateImportJob(
48
49
  dynamoClient,
49
50
  config,
50
51
  log,
51
- importJobData,
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 {DynamoClient} dynamoClient
103
- * @param {Object} config
104
- * @param {Logger} log
105
- * @param {string} jobId
106
- * @returns {Promise<ImportUrlDto[]> | []}
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
+ };