@adobe/spacecat-shared-data-access 1.61.18 → 2.0.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 +19 -0
- package/package.json +1 -2
- package/src/index.d.ts +4 -934
- package/src/index.js +1 -91
- package/src/{v2/models → models}/base/base.model.js +16 -3
- package/src/{v2 → models}/index.d.ts +14 -3
- package/src/{v2/models → models}/organization/organization.schema.js +1 -1
- package/src/{v2/models → models}/site/site.schema.js +1 -1
- package/src/service/index.d.ts +20 -0
- package/src/service/index.js +6 -46
- package/src/dto/api-key.js +0 -58
- package/src/dto/audit.js +0 -80
- package/src/dto/configuration.js +0 -49
- package/src/dto/dto-utils.js +0 -30
- package/src/dto/experiment.js +0 -66
- package/src/dto/import-job.js +0 -76
- package/src/dto/import-url.js +0 -55
- package/src/dto/key-event.js +0 -52
- package/src/dto/organization.js +0 -54
- package/src/dto/site-candidate.js +0 -54
- package/src/dto/site-top-page.js +0 -52
- package/src/dto/site.js +0 -62
- package/src/models/api-key/api-key.js +0 -182
- package/src/models/audit.js +0 -146
- package/src/models/base.js +0 -42
- package/src/models/configuration.js +0 -194
- package/src/models/experiment.js +0 -67
- package/src/models/importer/import-constants.js +0 -40
- package/src/models/importer/import-job.js +0 -252
- package/src/models/importer/import-url.js +0 -115
- package/src/models/key-event.js +0 -81
- package/src/models/organization.js +0 -120
- package/src/models/site-candidate.js +0 -111
- package/src/models/site-top-page.js +0 -62
- package/src/models/site.js +0 -218
- package/src/service/api-key/accessPatterns.js +0 -110
- package/src/service/api-key/index.js +0 -37
- package/src/service/audits/accessPatterns.js +0 -284
- package/src/service/audits/index.js +0 -72
- package/src/service/configurations/accessPatterns.js +0 -123
- package/src/service/configurations/index.js +0 -38
- package/src/service/experiments/accessPatterns.js +0 -98
- package/src/service/experiments/index.js +0 -40
- package/src/service/import-job/accessPatterns.js +0 -134
- package/src/service/import-job/index.js +0 -60
- package/src/service/import-url/accessPatterns.js +0 -153
- package/src/service/import-url/index.js +0 -53
- package/src/service/key-events/accessPatterns.js +0 -92
- package/src/service/key-events/index.js +0 -38
- package/src/service/organizations/accessPatterns.js +0 -160
- package/src/service/organizations/index.js +0 -51
- package/src/service/site-candidates/accessPatterns.js +0 -112
- package/src/service/site-candidates/index.js +0 -48
- package/src/service/site-top-pages/accessPatterns.js +0 -83
- package/src/service/site-top-pages/index.js +0 -42
- package/src/service/sites/accessPatterns.js +0 -467
- package/src/service/sites/index.js +0 -116
- package/src/v2/index.js +0 -15
- package/src/v2/models/index.d.ts +0 -26
- /package/src/{v2/errors → errors}/data-access.error.js +0 -0
- /package/src/{v2/errors → errors}/index.d.ts +0 -0
- /package/src/{v2/errors → errors}/index.js +0 -0
- /package/src/{v2/errors → errors}/reference.error.js +0 -0
- /package/src/{v2/errors → errors}/schema-validation.error.js +0 -0
- /package/src/{v2/errors → errors}/schema.builder.error.js +0 -0
- /package/src/{v2/errors → errors}/schema.error.js +0 -0
- /package/src/{v2/errors → errors}/validation.error.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.collection.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.model.js +0 -0
- /package/src/{v2/models → models}/api-key/api-key.schema.js +0 -0
- /package/src/{v2/models → models}/api-key/index.d.ts +0 -0
- /package/src/{v2/models → models}/api-key/index.js +0 -0
- /package/src/{v2/models → models}/audit/audit.collection.js +0 -0
- /package/src/{v2/models → models}/audit/audit.model.js +0 -0
- /package/src/{v2/models → models}/audit/audit.schema.js +0 -0
- /package/src/{v2/models → models}/audit/index.d.ts +0 -0
- /package/src/{v2/models → models}/audit/index.js +0 -0
- /package/src/{v2/models → models}/base/base.collection.js +0 -0
- /package/src/{v2/models → models}/base/entity.registry.js +0 -0
- /package/src/{v2/models → models}/base/index.d.ts +0 -0
- /package/src/{v2/models → models}/base/index.js +0 -0
- /package/src/{v2/models → models}/base/reference.js +0 -0
- /package/src/{v2/models → models}/base/schema.builder.js +0 -0
- /package/src/{v2/models → models}/base/schema.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.collection.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.model.js +0 -0
- /package/src/{v2/models → models}/configuration/configuration.schema.js +0 -0
- /package/src/{v2/models → models}/configuration/index.d.ts +0 -0
- /package/src/{v2/models → models}/configuration/index.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.collection.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.model.js +0 -0
- /package/src/{v2/models → models}/experiment/experiment.schema.js +0 -0
- /package/src/{v2/models → models}/experiment/index.d.ts +0 -0
- /package/src/{v2/models → models}/experiment/index.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.collection.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.model.js +0 -0
- /package/src/{v2/models → models}/import-job/import-job.schema.js +0 -0
- /package/src/{v2/models → models}/import-job/index.d.ts +0 -0
- /package/src/{v2/models → models}/import-job/index.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.collection.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.model.js +0 -0
- /package/src/{v2/models → models}/import-url/import-url.schema.js +0 -0
- /package/src/{v2/models → models}/import-url/index.d.ts +0 -0
- /package/src/{v2/models → models}/import-url/index.js +0 -0
- /package/src/{v2/models → models}/index.js +0 -0
- /package/src/{v2/models → models}/key-event/index.d.ts +0 -0
- /package/src/{v2/models → models}/key-event/index.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.collection.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.model.js +0 -0
- /package/src/{v2/models → models}/key-event/key-event.schema.js +0 -0
- /package/src/{v2/models → models}/latest-audit/index.d.ts +0 -0
- /package/src/{v2/models → models}/latest-audit/index.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.collection.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.model.js +0 -0
- /package/src/{v2/models → models}/latest-audit/latest-audit.schema.js +0 -0
- /package/src/{v2/models → models}/opportunity/index.d.ts +0 -0
- /package/src/{v2/models → models}/opportunity/index.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.collection.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.model.js +0 -0
- /package/src/{v2/models → models}/opportunity/opportunity.schema.js +0 -0
- /package/src/{v2/models → models}/organization/index.d.ts +0 -0
- /package/src/{v2/models → models}/organization/index.js +0 -0
- /package/src/{v2/models → models}/organization/organization.collection.js +0 -0
- /package/src/{v2/models → models}/organization/organization.model.js +0 -0
- /package/src/{v2/models → models}/site/index.d.ts +0 -0
- /package/src/{v2/models → models}/site/index.js +0 -0
- /package/src/{v2/models → models}/site/site.collection.js +0 -0
- /package/src/{v2/models → models}/site/site.model.js +0 -0
- /package/src/{v2/models → models}/site-candidate/index.d.ts +0 -0
- /package/src/{v2/models → models}/site-candidate/index.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.collection.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.model.js +0 -0
- /package/src/{v2/models → models}/site-candidate/site-candidate.schema.js +0 -0
- /package/src/{v2/models → models}/site-top-page/index.d.ts +0 -0
- /package/src/{v2/models → models}/site-top-page/index.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.collection.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.model.js +0 -0
- /package/src/{v2/models → models}/site-top-page/site-top-page.schema.js +0 -0
- /package/src/{v2/models → models}/suggestion/index.d.ts +0 -0
- /package/src/{v2/models → models}/suggestion/index.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.collection.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.model.js +0 -0
- /package/src/{v2/models → models}/suggestion/suggestion.schema.js +0 -0
- /package/src/{v2/readme.md → readme.md} +0 -0
- /package/src/{v2/util → util}/accessor.utils.js +0 -0
- /package/src/{v2/util → util}/guards.d.ts +0 -0
- /package/src/{v2/util → util}/guards.js +0 -0
- /package/src/{v2/util → util}/index.d.ts +0 -0
- /package/src/{v2/util → util}/index.js +0 -0
- /package/src/{v2/util → util}/patcher.js +0 -0
- /package/src/{v2/util → util}/util.js +0 -0
|
@@ -1,160 +0,0 @@
|
|
|
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
|
-
import { isObject } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
|
|
15
|
-
import { createOrganization } from '../../models/organization.js';
|
|
16
|
-
import { OrganizationDto } from '../../dto/organization.js';
|
|
17
|
-
import { removeSitesForOrganization } from '../sites/accessPatterns.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves all organizations.
|
|
21
|
-
*
|
|
22
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
23
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
24
|
-
* @returns {Promise<Readonly<Organization>[]>} A promise that resolves to an array of all
|
|
25
|
-
* organizations.
|
|
26
|
-
*/
|
|
27
|
-
export const getOrganizations = async (dynamoClient, config) => {
|
|
28
|
-
const dynamoItems = await dynamoClient.query({
|
|
29
|
-
TableName: config.tableNameOrganizations,
|
|
30
|
-
IndexName: config.indexNameAllOrganizations,
|
|
31
|
-
KeyConditionExpression: 'GSI1PK = :gsi1pk',
|
|
32
|
-
ExpressionAttributeValues: {
|
|
33
|
-
':gsi1pk': config.pkAllOrganizations,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return dynamoItems.map((dynamoItem) => OrganizationDto.fromDynamoItem(dynamoItem));
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const getOrganizationByID = async (
|
|
41
|
-
dynamoClient,
|
|
42
|
-
config,
|
|
43
|
-
organizationId,
|
|
44
|
-
) => {
|
|
45
|
-
const dynamoItem = await dynamoClient.getItem(
|
|
46
|
-
config.tableNameOrganizations,
|
|
47
|
-
{ id: organizationId },
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
return isObject(dynamoItem) ? OrganizationDto.fromDynamoItem(dynamoItem) : null;
|
|
51
|
-
};
|
|
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
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Adds an organization.
|
|
81
|
-
*
|
|
82
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
83
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
84
|
-
* @param {Logger} log - The log.
|
|
85
|
-
* @param {object} organizationData - The organization data.
|
|
86
|
-
* @returns {Promise<Readonly<Organization>>}
|
|
87
|
-
*/
|
|
88
|
-
export const addOrganization = async (
|
|
89
|
-
dynamoClient,
|
|
90
|
-
config,
|
|
91
|
-
log,
|
|
92
|
-
organizationData,
|
|
93
|
-
) => {
|
|
94
|
-
const organization = createOrganization(organizationData);
|
|
95
|
-
|
|
96
|
-
await dynamoClient.putItem(
|
|
97
|
-
config.tableNameOrganizations,
|
|
98
|
-
OrganizationDto.toDynamoItem(organization),
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
return organization;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Updates an organization.
|
|
106
|
-
*
|
|
107
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
108
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
109
|
-
* @param {Logger} log - The log.
|
|
110
|
-
* @param {Organization} organization - The organization.
|
|
111
|
-
* @returns {Promise<Readonly<Organization>>} - The updated organization.
|
|
112
|
-
*/
|
|
113
|
-
export const updateOrganization = async (
|
|
114
|
-
dynamoClient,
|
|
115
|
-
config,
|
|
116
|
-
log,
|
|
117
|
-
organization,
|
|
118
|
-
) => {
|
|
119
|
-
const existingOrganization = await getOrganizationByID(
|
|
120
|
-
dynamoClient,
|
|
121
|
-
config,
|
|
122
|
-
organization.getId(),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
if (!isObject(existingOrganization)) {
|
|
126
|
-
throw new Error('Organization not found');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
await dynamoClient.putItem(
|
|
130
|
-
config.tableNameOrganizations,
|
|
131
|
-
OrganizationDto.toDynamoItem(organization),
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
return organization;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Removes an organization.
|
|
139
|
-
*
|
|
140
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
141
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
142
|
-
* @param {Logger} log - The log.
|
|
143
|
-
* @param {string} organizationId - The ID of the organization to remove.
|
|
144
|
-
* @returns {Promise<void>}
|
|
145
|
-
*/
|
|
146
|
-
export const removeOrganization = async (
|
|
147
|
-
dynamoClient,
|
|
148
|
-
config,
|
|
149
|
-
log,
|
|
150
|
-
organizationId,
|
|
151
|
-
) => {
|
|
152
|
-
try {
|
|
153
|
-
await removeSitesForOrganization(dynamoClient, config, log, organizationId);
|
|
154
|
-
|
|
155
|
-
await dynamoClient.removeItem(config.tableNameOrganizations, { id: organizationId });
|
|
156
|
-
} catch (error) {
|
|
157
|
-
log.error(`Error removing organization: ${error.message}`);
|
|
158
|
-
throw error;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
import {
|
|
13
|
-
getOrganizations,
|
|
14
|
-
getOrganizationByID,
|
|
15
|
-
addOrganization,
|
|
16
|
-
updateOrganization,
|
|
17
|
-
removeOrganization,
|
|
18
|
-
getOrganizationByImsOrgID,
|
|
19
|
-
} from './accessPatterns.js';
|
|
20
|
-
|
|
21
|
-
export const organizationFunctions = (dynamoClient, config, log) => ({
|
|
22
|
-
getOrganizations: () => getOrganizations(dynamoClient, config),
|
|
23
|
-
getOrganizationByID: (organizationId) => getOrganizationByID(
|
|
24
|
-
dynamoClient,
|
|
25
|
-
config,
|
|
26
|
-
organizationId,
|
|
27
|
-
),
|
|
28
|
-
getOrganizationByImsOrgID: (imsOrgId) => getOrganizationByImsOrgID(
|
|
29
|
-
dynamoClient,
|
|
30
|
-
config,
|
|
31
|
-
imsOrgId,
|
|
32
|
-
),
|
|
33
|
-
addOrganization: (organizationData) => addOrganization(
|
|
34
|
-
dynamoClient,
|
|
35
|
-
config,
|
|
36
|
-
log,
|
|
37
|
-
organizationData,
|
|
38
|
-
),
|
|
39
|
-
updateOrganization: (organizationData) => updateOrganization(
|
|
40
|
-
dynamoClient,
|
|
41
|
-
config,
|
|
42
|
-
log,
|
|
43
|
-
organizationData,
|
|
44
|
-
),
|
|
45
|
-
removeOrganization: (organizationId) => removeOrganization(
|
|
46
|
-
dynamoClient,
|
|
47
|
-
config,
|
|
48
|
-
log,
|
|
49
|
-
organizationId,
|
|
50
|
-
),
|
|
51
|
-
});
|
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
import { isObject } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
import { createSiteCandidate } from '../../models/site-candidate.js';
|
|
15
|
-
import { SiteCandidateDto } from '../../dto/site-candidate.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Retrieves all site candidates.
|
|
19
|
-
*
|
|
20
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
21
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
22
|
-
* @returns {Promise<Readonly<Site>[]>} A promise that resolves to an array of all site candidates.
|
|
23
|
-
*/
|
|
24
|
-
export const getSiteCandidates = async (dynamoClient, config) => {
|
|
25
|
-
const dynamoItems = await dynamoClient.scan({
|
|
26
|
-
TableName: config.tableNameSiteCandidates,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
return dynamoItems.map((dynamoItem) => SiteCandidateDto.fromDynamoItem(dynamoItem));
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Checks if a site candidate exists in site candidates table using base url
|
|
34
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
35
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
36
|
-
* @param {string} baseURL - base url of the site candidate.
|
|
37
|
-
* @return {Promise<Readonly<Boolean>>} A promise that resolves to true if site candidate exist
|
|
38
|
-
*/
|
|
39
|
-
export const exists = async (dynamoClient, config, baseURL) => {
|
|
40
|
-
const dynamoItem = await dynamoClient.getItem(config.tableNameSiteCandidates, { baseURL });
|
|
41
|
-
|
|
42
|
-
return isObject(dynamoItem);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const getSiteCandidateByBaseURL = async (
|
|
46
|
-
dynamoClient,
|
|
47
|
-
config,
|
|
48
|
-
log,
|
|
49
|
-
baseURL,
|
|
50
|
-
) => {
|
|
51
|
-
const dynamoItem = await dynamoClient.getItem(config.tableNameSiteCandidates, { baseURL });
|
|
52
|
-
|
|
53
|
-
return isObject(dynamoItem) ? SiteCandidateDto.fromDynamoItem(dynamoItem) : null;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Upserts a site candidate.
|
|
58
|
-
*
|
|
59
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
60
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
61
|
-
* @param {object} log - the log object
|
|
62
|
-
* @param {object} siteCandidateData - The site candidate data.
|
|
63
|
-
* @returns {Promise<Readonly<SiteCandidate>>} newly created site candidate if hadn't created before
|
|
64
|
-
*/
|
|
65
|
-
export const upsertSiteCandidate = async (
|
|
66
|
-
dynamoClient,
|
|
67
|
-
config,
|
|
68
|
-
log,
|
|
69
|
-
siteCandidateData,
|
|
70
|
-
) => {
|
|
71
|
-
const siteCandidate = createSiteCandidate(siteCandidateData);
|
|
72
|
-
const siteCandidateExists = await exists(dynamoClient, config, siteCandidate.getBaseURL());
|
|
73
|
-
|
|
74
|
-
if (siteCandidateExists) {
|
|
75
|
-
log.info(`Ignoring the site candidate with base url ${siteCandidate.getBaseURL()} because it already exists`);
|
|
76
|
-
return siteCandidate;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
await dynamoClient.putItem(
|
|
80
|
-
config.tableNameSiteCandidates,
|
|
81
|
-
SiteCandidateDto.toDynamoItem(siteCandidate),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return siteCandidate;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Updates a site candidate.
|
|
89
|
-
*
|
|
90
|
-
* @param {DynamoDbClient} dynamoClient - The DynamoDB client.
|
|
91
|
-
* @param {DataAccessConfig} config - The data access config.
|
|
92
|
-
* @param {SiteCandidate} siteCandidate - The site candidate object to be updated.
|
|
93
|
-
* @returns {Promise<Readonly<Site>>} - The updated site candidate.
|
|
94
|
-
*/
|
|
95
|
-
export const updateSiteCandidate = async (
|
|
96
|
-
dynamoClient,
|
|
97
|
-
config,
|
|
98
|
-
siteCandidate,
|
|
99
|
-
) => {
|
|
100
|
-
const siteCandidateExists = await exists(dynamoClient, config, siteCandidate.getBaseURL());
|
|
101
|
-
|
|
102
|
-
if (!siteCandidateExists) {
|
|
103
|
-
throw new Error(`Site candidate with base url ${siteCandidate.getBaseURL()} does not exist`);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
await dynamoClient.putItem(
|
|
107
|
-
config.tableNameSiteCandidates,
|
|
108
|
-
SiteCandidateDto.toDynamoItem(siteCandidate),
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
return siteCandidate;
|
|
112
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
import {
|
|
14
|
-
getSiteCandidates,
|
|
15
|
-
getSiteCandidateByBaseURL,
|
|
16
|
-
upsertSiteCandidate,
|
|
17
|
-
exists,
|
|
18
|
-
updateSiteCandidate,
|
|
19
|
-
} from './accessPatterns.js';
|
|
20
|
-
|
|
21
|
-
export const siteCandidateFunctions = (dynamoClient, config, log) => ({
|
|
22
|
-
getSiteCandidates: () => getSiteCandidates(
|
|
23
|
-
dynamoClient,
|
|
24
|
-
config,
|
|
25
|
-
),
|
|
26
|
-
getSiteCandidateByBaseURL: (baseURL) => getSiteCandidateByBaseURL(
|
|
27
|
-
dynamoClient,
|
|
28
|
-
config,
|
|
29
|
-
log,
|
|
30
|
-
baseURL,
|
|
31
|
-
),
|
|
32
|
-
upsertSiteCandidate: (siteCandidateData) => upsertSiteCandidate(
|
|
33
|
-
dynamoClient,
|
|
34
|
-
config,
|
|
35
|
-
log,
|
|
36
|
-
siteCandidateData,
|
|
37
|
-
),
|
|
38
|
-
siteCandidateExists: (baseUrl) => exists(
|
|
39
|
-
dynamoClient,
|
|
40
|
-
config,
|
|
41
|
-
baseUrl,
|
|
42
|
-
),
|
|
43
|
-
updateSiteCandidate: (siteCandidateData) => updateSiteCandidate(
|
|
44
|
-
dynamoClient,
|
|
45
|
-
config,
|
|
46
|
-
siteCandidateData,
|
|
47
|
-
),
|
|
48
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
import { hasText } from '@adobe/spacecat-shared-utils';
|
|
14
|
-
|
|
15
|
-
import { createSiteTopPage } from '../../models/site-top-page.js';
|
|
16
|
-
import { padWithZeros, SiteTopPageDto } from '../../dto/site-top-page.js';
|
|
17
|
-
|
|
18
|
-
export const getTopPagesForSite = async (
|
|
19
|
-
dynamoClient,
|
|
20
|
-
config,
|
|
21
|
-
log,
|
|
22
|
-
siteId,
|
|
23
|
-
source,
|
|
24
|
-
geo,
|
|
25
|
-
) => {
|
|
26
|
-
const queryParams = {
|
|
27
|
-
TableName: config.tableNameSiteTopPages,
|
|
28
|
-
KeyConditionExpression: 'siteId = :siteId',
|
|
29
|
-
ExpressionAttributeValues: { ':siteId': siteId },
|
|
30
|
-
ScanIndexForward: false,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (hasText(source)) {
|
|
34
|
-
if (hasText(geo)) {
|
|
35
|
-
queryParams.KeyConditionExpression += ' AND begins_with(SK, :sourceGeo)';
|
|
36
|
-
queryParams.ExpressionAttributeValues[':sourceGeo'] = `${source}#${geo}#`;
|
|
37
|
-
} else {
|
|
38
|
-
queryParams.KeyConditionExpression += ' AND begins_with(SK, :source)';
|
|
39
|
-
queryParams.ExpressionAttributeValues[':source'] = `${source}#`;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const dynamoItems = await dynamoClient.query(queryParams);
|
|
44
|
-
|
|
45
|
-
return dynamoItems.map((item) => SiteTopPageDto.fromDynamoItem(item));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const addSiteTopPage = async (
|
|
49
|
-
dynamoClient,
|
|
50
|
-
config,
|
|
51
|
-
log,
|
|
52
|
-
siteTopPageData,
|
|
53
|
-
) => {
|
|
54
|
-
const newSiteTopPage = createSiteTopPage(siteTopPageData);
|
|
55
|
-
|
|
56
|
-
await dynamoClient.putItem(
|
|
57
|
-
config.tableNameSiteTopPages,
|
|
58
|
-
SiteTopPageDto.toDynamoItem(newSiteTopPage),
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
return newSiteTopPage;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const removeSiteTopPages = async (
|
|
65
|
-
dynamoClient,
|
|
66
|
-
config,
|
|
67
|
-
log,
|
|
68
|
-
siteId,
|
|
69
|
-
source,
|
|
70
|
-
geo,
|
|
71
|
-
) => {
|
|
72
|
-
const siteTopPages = await getTopPagesForSite(dynamoClient, config, log, siteId, source, geo);
|
|
73
|
-
|
|
74
|
-
const removePromises = siteTopPages.map((siteTopPage) => dynamoClient.removeItem(
|
|
75
|
-
config.tableNameSiteTopPages,
|
|
76
|
-
{
|
|
77
|
-
siteId: siteTopPage.getSiteId(),
|
|
78
|
-
SK: `${siteTopPage.getSource()}#${siteTopPage.getGeo()}#${padWithZeros(siteTopPage.getTraffic())}`,
|
|
79
|
-
},
|
|
80
|
-
));
|
|
81
|
-
|
|
82
|
-
await Promise.all(removePromises);
|
|
83
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
import {
|
|
14
|
-
addSiteTopPage,
|
|
15
|
-
getTopPagesForSite,
|
|
16
|
-
removeSiteTopPages,
|
|
17
|
-
} from './accessPatterns.js';
|
|
18
|
-
|
|
19
|
-
export const siteTopPagesFunctions = (dynamoClient, config, log) => ({
|
|
20
|
-
getTopPagesForSite: (siteId, source, geo) => getTopPagesForSite(
|
|
21
|
-
dynamoClient,
|
|
22
|
-
config,
|
|
23
|
-
log,
|
|
24
|
-
siteId,
|
|
25
|
-
source,
|
|
26
|
-
geo,
|
|
27
|
-
),
|
|
28
|
-
addSiteTopPage: (siteTopPageData) => addSiteTopPage(
|
|
29
|
-
dynamoClient,
|
|
30
|
-
config,
|
|
31
|
-
log,
|
|
32
|
-
siteTopPageData,
|
|
33
|
-
),
|
|
34
|
-
removeSiteTopPages: (siteId, source, geo) => removeSiteTopPages(
|
|
35
|
-
dynamoClient,
|
|
36
|
-
config,
|
|
37
|
-
log,
|
|
38
|
-
siteId,
|
|
39
|
-
source,
|
|
40
|
-
geo,
|
|
41
|
-
),
|
|
42
|
-
});
|