@adobe/spacecat-shared-data-access 1.61.19 → 2.0.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 +19 -0
- package/package.json +5 -6
- package/src/index.d.ts +4 -934
- package/src/index.js +1 -91
- 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/base.model.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,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
|
-
});
|