@adobe/spacecat-shared-data-access 1.19.3 → 1.20.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.20.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.20.0...@adobe/spacecat-shared-data-access-v1.20.1) (2024-03-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update external fixes ([#179](https://github.com/adobe/spacecat-shared/issues/179)) ([9d0aa97](https://github.com/adobe/spacecat-shared/commit/9d0aa97df6a67bb66c5f098c74aebdebbd0d5f01))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-data-access-v1.20.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.19.3...@adobe/spacecat-shared-data-access-v1.20.0) (2024-03-07)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* get and update configurations ([#178](https://github.com/adobe/spacecat-shared/issues/178)) ([163e27a](https://github.com/adobe/spacecat-shared/commit/163e27ad1cf704608a3fba8087d5103c8cb4226d)), closes [#183](https://github.com/adobe/spacecat-shared/issues/183) [/github.com/adobe/spacecat-api-service/issues/183#issuecomment-1973345923](https://github.com//github.com/adobe/spacecat-api-service/issues/183/issues/issuecomment-1973345923)
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-data-access-v1.19.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.19.2...@adobe/spacecat-shared-data-access-v1.19.3) (2024-03-02)
|
|
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.
|
|
3
|
+
"version": "1.20.1",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Data Access",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@adobe/spacecat-shared-dynamo": "1.2.5",
|
|
33
33
|
"@adobe/spacecat-shared-utils": "1.2.0",
|
|
34
|
-
"@aws-sdk/client-dynamodb": "3.
|
|
35
|
-
"@aws-sdk/lib-dynamodb": "3.
|
|
34
|
+
"@aws-sdk/client-dynamodb": "3.529.1",
|
|
35
|
+
"@aws-sdk/lib-dynamodb": "3.529.1",
|
|
36
36
|
"@types/joi": "17.2.3",
|
|
37
37
|
"joi": "17.12.2",
|
|
38
38
|
"uuid": "9.0.1"
|
package/src/dto/configuration.js
CHANGED
|
@@ -30,4 +30,16 @@ export const ConfigurationDto = {
|
|
|
30
30
|
|
|
31
31
|
return createConfiguration(configurationData);
|
|
32
32
|
},
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Converts a Configuration object into a DynamoDB item.
|
|
36
|
+
* @param {Readonly<Configuration>} configuration - Configuration object.
|
|
37
|
+
* @returns {object} DynamoDB item.
|
|
38
|
+
*/
|
|
39
|
+
toDynamoItem: (configuration) => ({
|
|
40
|
+
PK: 'ALL_CONFIGURATIONS',
|
|
41
|
+
version: configuration.getVersion(),
|
|
42
|
+
queues: configuration.getQueues(),
|
|
43
|
+
jobs: configuration.getJobs(),
|
|
44
|
+
}),
|
|
33
45
|
};
|
package/src/index.d.ts
CHANGED
|
@@ -443,8 +443,10 @@ export interface DataAccess {
|
|
|
443
443
|
updateSiteCandidate: (siteCandidate: SiteCandidate) => Promise<SiteCandidate>;
|
|
444
444
|
|
|
445
445
|
// configuration functions
|
|
446
|
-
getConfiguration: () => Promise<Configuration
|
|
447
|
-
|
|
446
|
+
getConfiguration: () => Promise<Readonly<Configuration>>
|
|
447
|
+
getConfigurations: () => Promise<Readonly<Configuration>[]>
|
|
448
|
+
getConfigurationByVersion: (version: string) => Promise<Readonly<Configuration>>
|
|
449
|
+
updateConfiguration: (configurationData: object) => Promise<Readonly<Configuration>>
|
|
448
450
|
}
|
|
449
451
|
|
|
450
452
|
interface DataAccessConfig {
|
|
@@ -10,9 +10,13 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
hasText,
|
|
15
|
+
isObject,
|
|
16
|
+
} from '@adobe/spacecat-shared-utils';
|
|
14
17
|
|
|
15
18
|
import { ConfigurationDto } from '../../dto/configuration.js';
|
|
19
|
+
import { createConfiguration } from '../../models/configuration.js';
|
|
16
20
|
|
|
17
21
|
/**
|
|
18
22
|
* Retrieves configuration with latest version.
|
|
@@ -40,6 +44,27 @@ export const getConfiguration = async (
|
|
|
40
44
|
return ConfigurationDto.fromDynamoItem(dynamoItems[0]);
|
|
41
45
|
};
|
|
42
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves all configurations.
|
|
49
|
+
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
50
|
+
* @param {DataAccessConfig} config - The data access config.
|
|
51
|
+
* @return {Promise<Readonly<Configuration>[]>} A promise that resolves to the configurations.
|
|
52
|
+
*/
|
|
53
|
+
export const getConfigurations = async (
|
|
54
|
+
dynamoClient,
|
|
55
|
+
config,
|
|
56
|
+
) => {
|
|
57
|
+
const dynamoItems = await dynamoClient.query({
|
|
58
|
+
TableName: config.tableNameConfigurations,
|
|
59
|
+
KeyConditionExpression: 'PK = :pk',
|
|
60
|
+
ExpressionAttributeValues: {
|
|
61
|
+
':pk': config.pkAllConfigurations,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return dynamoItems.map(ConfigurationDto.fromDynamoItem);
|
|
66
|
+
};
|
|
67
|
+
|
|
43
68
|
/**
|
|
44
69
|
* Retrieves a site by its version.
|
|
45
70
|
*
|
|
@@ -61,3 +86,39 @@ export const getConfigurationByVersion = async (
|
|
|
61
86
|
|
|
62
87
|
return isObject(dynamoItem) ? ConfigurationDto.fromDynamoItem(dynamoItem) : null;
|
|
63
88
|
};
|
|
89
|
+
|
|
90
|
+
function incrementVersion(version) {
|
|
91
|
+
if (!hasText(version)) return 'v1';
|
|
92
|
+
|
|
93
|
+
const versionNumber = parseInt(version.substring(1), 10);
|
|
94
|
+
return `v${versionNumber + 1}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Updates the configuration. Updating the configuration will create a new version of the
|
|
99
|
+
* configuration. The version is a string of the format "v<version-number>", for example "v1".
|
|
100
|
+
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
101
|
+
* @param {DataAccessConfig} config - The data access config.
|
|
102
|
+
* @param {Configuration} configurationData - The configuration data.
|
|
103
|
+
* @return {Promise<void>} A promise that resolves when the configuration is updated.
|
|
104
|
+
*/
|
|
105
|
+
export const updateConfiguration = async (
|
|
106
|
+
dynamoClient,
|
|
107
|
+
config,
|
|
108
|
+
configurationData,
|
|
109
|
+
) => {
|
|
110
|
+
const newConfigurationData = { ...configurationData };
|
|
111
|
+
const latestConfiguration = await getConfiguration(dynamoClient, config);
|
|
112
|
+
|
|
113
|
+
newConfigurationData.version = incrementVersion(latestConfiguration?.version);
|
|
114
|
+
newConfigurationData.PK = config.pkAllConfigurations;
|
|
115
|
+
|
|
116
|
+
const newConfiguration = createConfiguration(newConfigurationData);
|
|
117
|
+
|
|
118
|
+
await dynamoClient.putItem(
|
|
119
|
+
config.tableNameConfigurations,
|
|
120
|
+
ConfigurationDto.toDynamoItem(newConfiguration),
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
return newConfiguration;
|
|
124
|
+
};
|
|
@@ -9,16 +9,30 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
getConfiguration,
|
|
14
|
+
getConfigurationByVersion,
|
|
15
|
+
getConfigurations,
|
|
16
|
+
updateConfiguration,
|
|
17
|
+
} from './accessPatterns.js';
|
|
13
18
|
|
|
14
19
|
export const configurationFunctions = (dynamoClient, config) => ({
|
|
15
20
|
getConfiguration: () => getConfiguration(
|
|
16
21
|
dynamoClient,
|
|
17
22
|
config,
|
|
18
23
|
),
|
|
24
|
+
getConfigurations: () => getConfigurations(
|
|
25
|
+
dynamoClient,
|
|
26
|
+
config,
|
|
27
|
+
),
|
|
19
28
|
getConfigurationByVersion: (version) => getConfigurationByVersion(
|
|
20
29
|
dynamoClient,
|
|
21
30
|
config,
|
|
22
31
|
version,
|
|
23
32
|
),
|
|
33
|
+
updateConfiguration: (configurationData) => updateConfiguration(
|
|
34
|
+
dynamoClient,
|
|
35
|
+
config,
|
|
36
|
+
configurationData,
|
|
37
|
+
),
|
|
24
38
|
});
|