@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.
Files changed (151) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.json +5 -6
  3. package/src/index.d.ts +4 -934
  4. package/src/index.js +1 -91
  5. package/src/{v2 → models}/index.d.ts +14 -3
  6. package/src/{v2/models → models}/organization/organization.schema.js +1 -1
  7. package/src/{v2/models → models}/site/site.schema.js +1 -1
  8. package/src/service/index.d.ts +20 -0
  9. package/src/service/index.js +6 -46
  10. package/src/dto/api-key.js +0 -58
  11. package/src/dto/audit.js +0 -80
  12. package/src/dto/configuration.js +0 -49
  13. package/src/dto/dto-utils.js +0 -30
  14. package/src/dto/experiment.js +0 -66
  15. package/src/dto/import-job.js +0 -76
  16. package/src/dto/import-url.js +0 -55
  17. package/src/dto/key-event.js +0 -52
  18. package/src/dto/organization.js +0 -54
  19. package/src/dto/site-candidate.js +0 -54
  20. package/src/dto/site-top-page.js +0 -52
  21. package/src/dto/site.js +0 -62
  22. package/src/models/api-key/api-key.js +0 -182
  23. package/src/models/audit.js +0 -146
  24. package/src/models/base.js +0 -42
  25. package/src/models/configuration.js +0 -194
  26. package/src/models/experiment.js +0 -67
  27. package/src/models/importer/import-constants.js +0 -40
  28. package/src/models/importer/import-job.js +0 -252
  29. package/src/models/importer/import-url.js +0 -115
  30. package/src/models/key-event.js +0 -81
  31. package/src/models/organization.js +0 -120
  32. package/src/models/site-candidate.js +0 -111
  33. package/src/models/site-top-page.js +0 -62
  34. package/src/models/site.js +0 -218
  35. package/src/service/api-key/accessPatterns.js +0 -110
  36. package/src/service/api-key/index.js +0 -37
  37. package/src/service/audits/accessPatterns.js +0 -284
  38. package/src/service/audits/index.js +0 -72
  39. package/src/service/configurations/accessPatterns.js +0 -123
  40. package/src/service/configurations/index.js +0 -38
  41. package/src/service/experiments/accessPatterns.js +0 -98
  42. package/src/service/experiments/index.js +0 -40
  43. package/src/service/import-job/accessPatterns.js +0 -134
  44. package/src/service/import-job/index.js +0 -60
  45. package/src/service/import-url/accessPatterns.js +0 -153
  46. package/src/service/import-url/index.js +0 -53
  47. package/src/service/key-events/accessPatterns.js +0 -92
  48. package/src/service/key-events/index.js +0 -38
  49. package/src/service/organizations/accessPatterns.js +0 -160
  50. package/src/service/organizations/index.js +0 -51
  51. package/src/service/site-candidates/accessPatterns.js +0 -112
  52. package/src/service/site-candidates/index.js +0 -48
  53. package/src/service/site-top-pages/accessPatterns.js +0 -83
  54. package/src/service/site-top-pages/index.js +0 -42
  55. package/src/service/sites/accessPatterns.js +0 -467
  56. package/src/service/sites/index.js +0 -116
  57. package/src/v2/index.js +0 -15
  58. package/src/v2/models/index.d.ts +0 -26
  59. /package/src/{v2/errors → errors}/data-access.error.js +0 -0
  60. /package/src/{v2/errors → errors}/index.d.ts +0 -0
  61. /package/src/{v2/errors → errors}/index.js +0 -0
  62. /package/src/{v2/errors → errors}/reference.error.js +0 -0
  63. /package/src/{v2/errors → errors}/schema-validation.error.js +0 -0
  64. /package/src/{v2/errors → errors}/schema.builder.error.js +0 -0
  65. /package/src/{v2/errors → errors}/schema.error.js +0 -0
  66. /package/src/{v2/errors → errors}/validation.error.js +0 -0
  67. /package/src/{v2/models → models}/api-key/api-key.collection.js +0 -0
  68. /package/src/{v2/models → models}/api-key/api-key.model.js +0 -0
  69. /package/src/{v2/models → models}/api-key/api-key.schema.js +0 -0
  70. /package/src/{v2/models → models}/api-key/index.d.ts +0 -0
  71. /package/src/{v2/models → models}/api-key/index.js +0 -0
  72. /package/src/{v2/models → models}/audit/audit.collection.js +0 -0
  73. /package/src/{v2/models → models}/audit/audit.model.js +0 -0
  74. /package/src/{v2/models → models}/audit/audit.schema.js +0 -0
  75. /package/src/{v2/models → models}/audit/index.d.ts +0 -0
  76. /package/src/{v2/models → models}/audit/index.js +0 -0
  77. /package/src/{v2/models → models}/base/base.collection.js +0 -0
  78. /package/src/{v2/models → models}/base/base.model.js +0 -0
  79. /package/src/{v2/models → models}/base/entity.registry.js +0 -0
  80. /package/src/{v2/models → models}/base/index.d.ts +0 -0
  81. /package/src/{v2/models → models}/base/index.js +0 -0
  82. /package/src/{v2/models → models}/base/reference.js +0 -0
  83. /package/src/{v2/models → models}/base/schema.builder.js +0 -0
  84. /package/src/{v2/models → models}/base/schema.js +0 -0
  85. /package/src/{v2/models → models}/configuration/configuration.collection.js +0 -0
  86. /package/src/{v2/models → models}/configuration/configuration.model.js +0 -0
  87. /package/src/{v2/models → models}/configuration/configuration.schema.js +0 -0
  88. /package/src/{v2/models → models}/configuration/index.d.ts +0 -0
  89. /package/src/{v2/models → models}/configuration/index.js +0 -0
  90. /package/src/{v2/models → models}/experiment/experiment.collection.js +0 -0
  91. /package/src/{v2/models → models}/experiment/experiment.model.js +0 -0
  92. /package/src/{v2/models → models}/experiment/experiment.schema.js +0 -0
  93. /package/src/{v2/models → models}/experiment/index.d.ts +0 -0
  94. /package/src/{v2/models → models}/experiment/index.js +0 -0
  95. /package/src/{v2/models → models}/import-job/import-job.collection.js +0 -0
  96. /package/src/{v2/models → models}/import-job/import-job.model.js +0 -0
  97. /package/src/{v2/models → models}/import-job/import-job.schema.js +0 -0
  98. /package/src/{v2/models → models}/import-job/index.d.ts +0 -0
  99. /package/src/{v2/models → models}/import-job/index.js +0 -0
  100. /package/src/{v2/models → models}/import-url/import-url.collection.js +0 -0
  101. /package/src/{v2/models → models}/import-url/import-url.model.js +0 -0
  102. /package/src/{v2/models → models}/import-url/import-url.schema.js +0 -0
  103. /package/src/{v2/models → models}/import-url/index.d.ts +0 -0
  104. /package/src/{v2/models → models}/import-url/index.js +0 -0
  105. /package/src/{v2/models → models}/index.js +0 -0
  106. /package/src/{v2/models → models}/key-event/index.d.ts +0 -0
  107. /package/src/{v2/models → models}/key-event/index.js +0 -0
  108. /package/src/{v2/models → models}/key-event/key-event.collection.js +0 -0
  109. /package/src/{v2/models → models}/key-event/key-event.model.js +0 -0
  110. /package/src/{v2/models → models}/key-event/key-event.schema.js +0 -0
  111. /package/src/{v2/models → models}/latest-audit/index.d.ts +0 -0
  112. /package/src/{v2/models → models}/latest-audit/index.js +0 -0
  113. /package/src/{v2/models → models}/latest-audit/latest-audit.collection.js +0 -0
  114. /package/src/{v2/models → models}/latest-audit/latest-audit.model.js +0 -0
  115. /package/src/{v2/models → models}/latest-audit/latest-audit.schema.js +0 -0
  116. /package/src/{v2/models → models}/opportunity/index.d.ts +0 -0
  117. /package/src/{v2/models → models}/opportunity/index.js +0 -0
  118. /package/src/{v2/models → models}/opportunity/opportunity.collection.js +0 -0
  119. /package/src/{v2/models → models}/opportunity/opportunity.model.js +0 -0
  120. /package/src/{v2/models → models}/opportunity/opportunity.schema.js +0 -0
  121. /package/src/{v2/models → models}/organization/index.d.ts +0 -0
  122. /package/src/{v2/models → models}/organization/index.js +0 -0
  123. /package/src/{v2/models → models}/organization/organization.collection.js +0 -0
  124. /package/src/{v2/models → models}/organization/organization.model.js +0 -0
  125. /package/src/{v2/models → models}/site/index.d.ts +0 -0
  126. /package/src/{v2/models → models}/site/index.js +0 -0
  127. /package/src/{v2/models → models}/site/site.collection.js +0 -0
  128. /package/src/{v2/models → models}/site/site.model.js +0 -0
  129. /package/src/{v2/models → models}/site-candidate/index.d.ts +0 -0
  130. /package/src/{v2/models → models}/site-candidate/index.js +0 -0
  131. /package/src/{v2/models → models}/site-candidate/site-candidate.collection.js +0 -0
  132. /package/src/{v2/models → models}/site-candidate/site-candidate.model.js +0 -0
  133. /package/src/{v2/models → models}/site-candidate/site-candidate.schema.js +0 -0
  134. /package/src/{v2/models → models}/site-top-page/index.d.ts +0 -0
  135. /package/src/{v2/models → models}/site-top-page/index.js +0 -0
  136. /package/src/{v2/models → models}/site-top-page/site-top-page.collection.js +0 -0
  137. /package/src/{v2/models → models}/site-top-page/site-top-page.model.js +0 -0
  138. /package/src/{v2/models → models}/site-top-page/site-top-page.schema.js +0 -0
  139. /package/src/{v2/models → models}/suggestion/index.d.ts +0 -0
  140. /package/src/{v2/models → models}/suggestion/index.js +0 -0
  141. /package/src/{v2/models → models}/suggestion/suggestion.collection.js +0 -0
  142. /package/src/{v2/models → models}/suggestion/suggestion.model.js +0 -0
  143. /package/src/{v2/models → models}/suggestion/suggestion.schema.js +0 -0
  144. /package/src/{v2/readme.md → readme.md} +0 -0
  145. /package/src/{v2/util → util}/accessor.utils.js +0 -0
  146. /package/src/{v2/util → util}/guards.d.ts +0 -0
  147. /package/src/{v2/util → util}/guards.js +0 -0
  148. /package/src/{v2/util → util}/index.d.ts +0 -0
  149. /package/src/{v2/util → util}/index.js +0 -0
  150. /package/src/{v2/util → util}/patcher.js +0 -0
  151. /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
- });