@adobe/spacecat-shared-data-access 1.45.5 → 1.46.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/dto/audit.js +1 -9
- package/src/dto/dto-utils.js +30 -0
- package/src/dto/import-url.js +3 -0
- package/src/models/importer/import-url.js +9 -0
- package/src/models/site/config.js +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.46.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.45.6...@adobe/spacecat-shared-data-access-v1.46.0) (2024-10-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Expire Import URLs automatically after set period of time ([#392](https://github.com/adobe/spacecat-shared/issues/392)) ([294fd9e](https://github.com/adobe/spacecat-shared/commit/294fd9ec112b99a66e7025bed9219fed280eb128))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-data-access-v1.45.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.45.5...@adobe/spacecat-shared-data-access-v1.45.6) (2024-10-02)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* content client should use the hlxConfig ([8e74827](https://github.com/adobe/spacecat-shared/commit/8e74827613421828eaef29cf1372d329433526cc))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-data-access-v1.45.5](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.45.4...@adobe/spacecat-shared-data-access-v1.45.5) (2024-09-30)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/dto/audit.js
CHANGED
|
@@ -13,15 +13,7 @@
|
|
|
13
13
|
import { isObject } from '@adobe/spacecat-shared-utils';
|
|
14
14
|
|
|
15
15
|
import { createAudit } from '../models/audit.js';
|
|
16
|
-
|
|
17
|
-
function parseEpochToDate(epochInSeconds) {
|
|
18
|
-
const milliseconds = epochInSeconds * 1000;
|
|
19
|
-
return new Date(milliseconds);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function convertDateToEpochSeconds(date) {
|
|
23
|
-
return Math.floor(date.getTime() / 1000);
|
|
24
|
-
}
|
|
16
|
+
import { convertDateToEpochSeconds, parseEpochToDate } from './dto-utils.js';
|
|
25
17
|
|
|
26
18
|
/**
|
|
27
19
|
* Data transfer object for Audit.
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Parse the given Epoch timestamp, in seconds, to a Date object.
|
|
15
|
+
* @param {number} epochInSeconds - The Epoch timestamp in seconds.
|
|
16
|
+
* @returns {Date} A new Date object set to the given timestamp.
|
|
17
|
+
*/
|
|
18
|
+
export function parseEpochToDate(epochInSeconds) {
|
|
19
|
+
const milliseconds = epochInSeconds * 1000;
|
|
20
|
+
return new Date(milliseconds);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Convert the given Date object to an Epoch timestamp, in seconds.
|
|
25
|
+
* @param {Date} date - The Date object to convert.
|
|
26
|
+
* @returns {number} The Epoch timestamp in seconds.
|
|
27
|
+
*/
|
|
28
|
+
export function convertDateToEpochSeconds(date) {
|
|
29
|
+
return Math.floor(date.getTime() / 1000);
|
|
30
|
+
}
|
package/src/dto/import-url.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { createImportUrl } from '../models/importer/import-url.js';
|
|
14
|
+
import { convertDateToEpochSeconds, parseEpochToDate } from './dto-utils.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* The ImportUrlDto is a helper that can convert an ImportUrl object to a DynamoDB item and
|
|
@@ -30,6 +31,7 @@ export const ImportUrlDto = {
|
|
|
30
31
|
reason: importUrl.getReason(),
|
|
31
32
|
path: importUrl.getPath(),
|
|
32
33
|
file: importUrl.getFile(),
|
|
34
|
+
expiresAt: convertDateToEpochSeconds(importUrl.getExpiresAt()),
|
|
33
35
|
}),
|
|
34
36
|
|
|
35
37
|
/**
|
|
@@ -46,6 +48,7 @@ export const ImportUrlDto = {
|
|
|
46
48
|
reason: dynamoItem.reason,
|
|
47
49
|
path: dynamoItem.path,
|
|
48
50
|
file: dynamoItem.file,
|
|
51
|
+
expiresAt: parseEpochToDate(dynamoItem.expiresAt),
|
|
49
52
|
};
|
|
50
53
|
return createImportUrl(importUrlData);
|
|
51
54
|
},
|
|
@@ -14,6 +14,8 @@ import { hasText, isValidUrl } from '@adobe/spacecat-shared-utils';
|
|
|
14
14
|
import { Base } from '../base.js';
|
|
15
15
|
import { ImportUrlStatus } from './import-constants.js';
|
|
16
16
|
|
|
17
|
+
export const IMPORT_URL_EXPIRES_IN_DAYS = 30;
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
20
|
* Creates a new ImportUrl object
|
|
19
21
|
*
|
|
@@ -31,6 +33,8 @@ const ImportUrl = (data) => {
|
|
|
31
33
|
self.getPath = () => self.state.path;
|
|
32
34
|
// Resulting path and filename of the imported .docx file
|
|
33
35
|
self.getFile = () => self.state.file;
|
|
36
|
+
// Expiration date for the URL
|
|
37
|
+
self.getExpiresAt = () => self.state.expiresAt;
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
40
|
* Updates the state of the ImportJob.
|
|
@@ -102,5 +106,10 @@ export const createImportUrl = (data) => {
|
|
|
102
106
|
throw new Error(`Invalid Import URL status: ${newState.status}`);
|
|
103
107
|
}
|
|
104
108
|
|
|
109
|
+
if (!newState.expiresAt) {
|
|
110
|
+
newState.expiresAt = new Date();
|
|
111
|
+
newState.expiresAt.setDate(newState.expiresAt.getDate() + IMPORT_URL_EXPIRES_IN_DAYS);
|
|
112
|
+
}
|
|
113
|
+
|
|
105
114
|
return ImportUrl(newState);
|
|
106
115
|
};
|
|
@@ -60,7 +60,6 @@ export const Config = (data = {}) => {
|
|
|
60
60
|
self.getSlackMentions = (type) => state?.handlers[type]?.mentions?.slack;
|
|
61
61
|
self.getHandlerConfig = (type) => state?.handlers[type];
|
|
62
62
|
self.getHandlers = () => state.handlers;
|
|
63
|
-
self.getHlxContentConfig = () => state.content;
|
|
64
63
|
self.getImports = () => state.imports;
|
|
65
64
|
self.getExcludedURLs = (type) => state?.handlers[type]?.excludedURLs;
|
|
66
65
|
self.getManualOverwrites = (type) => state?.handlers[type]?.manualOverwrites;
|
|
@@ -75,13 +74,6 @@ export const Config = (data = {}) => {
|
|
|
75
74
|
};
|
|
76
75
|
};
|
|
77
76
|
|
|
78
|
-
self.updateHlxContentConfig = (source, path) => {
|
|
79
|
-
state.content = {
|
|
80
|
-
source,
|
|
81
|
-
path,
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
|
|
85
77
|
self.updateImports = (imports) => {
|
|
86
78
|
state.imports = imports;
|
|
87
79
|
};
|
|
@@ -118,7 +110,6 @@ Config.fromDynamoItem = (dynamoItem) => Config(dynamoItem);
|
|
|
118
110
|
|
|
119
111
|
Config.toDynamoItem = (config) => ({
|
|
120
112
|
slack: config.getSlackConfig(),
|
|
121
|
-
content: config.getHlxContentConfig(),
|
|
122
113
|
handlers: config.getHandlers(),
|
|
123
114
|
imports: config.getImports(),
|
|
124
115
|
});
|