@adobe/spacecat-shared-data-access 1.16.0 → 1.17.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 +14 -0
- package/package.json +1 -1
- package/src/index.d.ts +4 -0
- package/src/index.js +4 -0
- package/src/models/organization.js +5 -0
- package/src/models/site/config.js +2 -11
- package/src/service/index.js +2 -1
- package/src/service/organizations/accessPatterns.js +26 -0
- package/src/service/organizations/index.js +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-data-access-v1.17.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.17.0...@adobe/spacecat-shared-data-access-v1.17.1) (2024-02-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* generify site and organization config ([0ec8ee1](https://github.com/adobe/spacecat-shared/commit/0ec8ee1445e389c47d6ece436853e5b4c105ca93))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-data-access-v1.17.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.16.0...@adobe/spacecat-shared-data-access-v1.17.0) (2024-02-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* get organization by IMS org ID ([#153](https://github.com/adobe/spacecat-shared/issues/153)) ([541e7e7](https://github.com/adobe/spacecat-shared/commit/541e7e721cb21e977b59b19cf53dfb7ba460905f))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-data-access-v1.16.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v1.15.6...@adobe/spacecat-shared-data-access-v1.16.0) (2024-02-14)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -413,6 +413,9 @@ export interface DataAccess {
|
|
|
413
413
|
getOrganizationByID: (
|
|
414
414
|
organizationID: string,
|
|
415
415
|
) => Promise<Organization | null>;
|
|
416
|
+
getOrganizationByImsOrgID: (
|
|
417
|
+
imsOrgID: string,
|
|
418
|
+
) => Promise<Organization | null>;
|
|
416
419
|
addOrganization: (
|
|
417
420
|
organizationData: object,
|
|
418
421
|
) => Promise<Organization>;
|
|
@@ -446,6 +449,7 @@ interface DataAccessConfig {
|
|
|
446
449
|
indexNameAllSitesByDeliveryType: string;
|
|
447
450
|
indexNameAllLatestAuditScores: string;
|
|
448
451
|
indexNameAllOrganizations: string,
|
|
452
|
+
indexNameAllOrganizationsByImsOrgId: string,
|
|
449
453
|
pkAllSites: string;
|
|
450
454
|
pkAllLatestAudits: string;
|
|
451
455
|
pkAllOrganizations: string;
|
package/src/index.js
CHANGED
|
@@ -21,6 +21,7 @@ const TABLE_NAME_CONFIGURATIONS = 'spacecat-services-configurations-dev';
|
|
|
21
21
|
|
|
22
22
|
const INDEX_NAME_ALL_SITES = 'spacecat-services-all-sites-dev';
|
|
23
23
|
const INDEX_NAME_ALL_ORGANIZATIONS = 'spacecat-services-all-organizations-dev';
|
|
24
|
+
const INDEX_NAME_ALL_ORGANIZATIONS_BY_IMS_ORG_ID = 'spacecat-services-all-organizations-by-ims-org-id-dev';
|
|
24
25
|
const INDEX_NAME_ALL_SITES_BY_DELIVERY_TYPE = 'spacecat-services-all-sites-by-delivery-type-dev';
|
|
25
26
|
const INDEX_NAME_ALL_LATEST_AUDIT_SCORES = 'spacecat-services-all-latest-audit-scores-dev';
|
|
26
27
|
const INDEX_NAME_ALL_SITES_ORGANIZATIONS = 'spacecat-services-all-sites-organizations-dev';
|
|
@@ -46,6 +47,8 @@ export default function dataAccessWrapper(fn) {
|
|
|
46
47
|
DYNAMO_INDEX_NAME_ALL_SITES_BY_DELIVERY_TYPE = INDEX_NAME_ALL_SITES_BY_DELIVERY_TYPE,
|
|
47
48
|
DYNAMO_INDEX_NAME_ALL_LATEST_AUDIT_SCORES = INDEX_NAME_ALL_LATEST_AUDIT_SCORES,
|
|
48
49
|
DYNAMO_INDEX_NAME_ALL_ORGANIZATIONS = INDEX_NAME_ALL_ORGANIZATIONS,
|
|
50
|
+
// eslint-disable-next-line max-len
|
|
51
|
+
DYNAMO_INDEX_NAME_ALL_ORGANIZATIONS_BY_IMS_ORG_ID = INDEX_NAME_ALL_ORGANIZATIONS_BY_IMS_ORG_ID,
|
|
49
52
|
DYNAMO_INDEX_NAME_ALL_SITES_ORGANIZATIONS = INDEX_NAME_ALL_SITES_ORGANIZATIONS,
|
|
50
53
|
} = context.env;
|
|
51
54
|
|
|
@@ -58,6 +61,7 @@ export default function dataAccessWrapper(fn) {
|
|
|
58
61
|
tableNameConfigurations: DYNAMO_TABLE_NAME_CONFIGURATIONS,
|
|
59
62
|
indexNameAllSites: DYNAMO_INDEX_NAME_ALL_SITES,
|
|
60
63
|
indexNameAllOrganizations: DYNAMO_INDEX_NAME_ALL_ORGANIZATIONS,
|
|
64
|
+
indexNameAllOrganizationsByImsOrgId: DYNAMO_INDEX_NAME_ALL_ORGANIZATIONS_BY_IMS_ORG_ID,
|
|
61
65
|
indexNameAllSitesByDeliveryType: DYNAMO_INDEX_NAME_ALL_SITES_BY_DELIVERY_TYPE,
|
|
62
66
|
indexNameAllLatestAuditScores: DYNAMO_INDEX_NAME_ALL_LATEST_AUDIT_SCORES,
|
|
63
67
|
indexNameAllSitesOrganizations: DYNAMO_INDEX_NAME_ALL_SITES_ORGANIZATIONS,
|
|
@@ -92,10 +92,15 @@ export const createOrganization = (data) => {
|
|
|
92
92
|
if (!isObject(newState.config)) {
|
|
93
93
|
newState.config = { ...DEFAULT_CONFIG };
|
|
94
94
|
}
|
|
95
|
+
|
|
95
96
|
if (!hasText(newState.name)) {
|
|
96
97
|
throw new Error('Org name must be provided');
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
if (!hasText(newState.imsOrgId)) {
|
|
101
|
+
newState.imsOrgId = DEFAULT_ORGANIZATION_ID;
|
|
102
|
+
}
|
|
103
|
+
|
|
99
104
|
newState.config = Config(newState.config);
|
|
100
105
|
|
|
101
106
|
return Organization(newState);
|
|
@@ -43,18 +43,9 @@ function validateConfiguration(config) {
|
|
|
43
43
|
|
|
44
44
|
export const Config = (data = {}) => {
|
|
45
45
|
const validConfig = validateConfiguration(data);
|
|
46
|
-
const state = {
|
|
47
|
-
slack: {
|
|
48
|
-
...(validConfig?.slack?.channel ? { channel: validConfig?.slack?.channel } : {}),
|
|
49
|
-
...(validConfig?.slack?.workspace ? { workspace: validConfig?.slack?.workspace } : {}),
|
|
50
|
-
},
|
|
51
|
-
alerts: validConfig.alerts || [],
|
|
52
|
-
};
|
|
46
|
+
const state = { ...validConfig };
|
|
53
47
|
|
|
54
|
-
const self = {
|
|
55
|
-
alerts: state.alerts,
|
|
56
|
-
slack: state.slack,
|
|
57
|
-
};
|
|
48
|
+
const self = { ...state };
|
|
58
49
|
|
|
59
50
|
return Object.freeze(self);
|
|
60
51
|
};
|
package/src/service/index.js
CHANGED
|
@@ -23,7 +23,8 @@ import { configurationFunctions } from './configurations/index.js';
|
|
|
23
23
|
* @param {{pkAllSites: string, pkAllLatestAudits: string, indexNameAllLatestAuditScores: string,
|
|
24
24
|
* tableNameAudits: string,tableNameLatestAudits: string, indexNameAllSitesOrganizations: string,
|
|
25
25
|
* tableNameSites: string, tableNameOrganizations: string, indexNameAllSites: string,
|
|
26
|
-
* indexNameAllOrganizations: string,
|
|
26
|
+
* indexNameAllOrganizations: string, indexNameAllOrganizationsByImsOrgId: string,
|
|
27
|
+
* pkAllOrganizations: string}} config configuration
|
|
27
28
|
* @param {Logger} log logger
|
|
28
29
|
* @returns {object} data access object
|
|
29
30
|
*/
|
|
@@ -50,6 +50,32 @@ export const getOrganizationByID = async (
|
|
|
50
50
|
return isObject(dynamoItem) ? OrganizationDto.fromDynamoItem(dynamoItem) : null;
|
|
51
51
|
};
|
|
52
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
|
+
|
|
53
79
|
/**
|
|
54
80
|
* Adds an organization.
|
|
55
81
|
*
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
addOrganization,
|
|
16
16
|
updateOrganization,
|
|
17
17
|
removeOrganization,
|
|
18
|
+
getOrganizationByImsOrgID,
|
|
18
19
|
} from './accessPatterns.js';
|
|
19
20
|
|
|
20
21
|
export const organizationFunctions = (dynamoClient, config, log) => ({
|
|
@@ -24,6 +25,11 @@ export const organizationFunctions = (dynamoClient, config, log) => ({
|
|
|
24
25
|
config,
|
|
25
26
|
organizationId,
|
|
26
27
|
),
|
|
28
|
+
getOrganizationByImsOrgID: (imsOrgId) => getOrganizationByImsOrgID(
|
|
29
|
+
dynamoClient,
|
|
30
|
+
config,
|
|
31
|
+
imsOrgId,
|
|
32
|
+
),
|
|
27
33
|
addOrganization: (organizationData) => addOrganization(
|
|
28
34
|
dynamoClient,
|
|
29
35
|
config,
|