@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,467 +0,0 @@
1
- /*
2
- * Copyright 2023 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 {
16
- getAuditsForSite,
17
- getLatestAuditForSite,
18
- getLatestAudits,
19
- removeAuditsForSite,
20
- } from '../audits/accessPatterns.js';
21
-
22
- import { createSite } from '../../models/site.js';
23
- import { SiteDto } from '../../dto/site.js';
24
-
25
- /**
26
- * Retrieves all sites.
27
- *
28
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
29
- * @param {DataAccessConfig} config - The data access config.
30
- * @returns {Promise<Readonly<Site>[]>} A promise that resolves to an array of all sites.
31
- */
32
- export const getSites = async (dynamoClient, config) => {
33
- const dynamoItems = await dynamoClient.query({
34
- TableName: config.tableNameSites,
35
- IndexName: config.indexNameAllSites,
36
- KeyConditionExpression: 'GSI1PK = :gsi1pk',
37
- ExpressionAttributeValues: {
38
- ':gsi1pk': config.pkAllSites,
39
- },
40
- });
41
-
42
- return dynamoItems.map((dynamoItem) => SiteDto.fromDynamoItem(dynamoItem));
43
- };
44
-
45
- /**
46
- * Retrieves all sites of a specific delivery type.
47
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
48
- * @param {DataAccessConfig} config - The data access config.
49
- * @param {string} deliveryType - The delivery type.
50
- * @return {Promise<Readonly<Site>[]>} A promise that resolves to an array of all sites of the
51
- * specified delivery type.
52
- */
53
- export const getSitesByDeliveryType = async (dynamoClient, config, deliveryType) => {
54
- if (deliveryType === 'all') {
55
- return getSites(dynamoClient, config);
56
- }
57
-
58
- const dynamoItems = await dynamoClient.query({
59
- TableName: config.tableNameSites,
60
- IndexName: config.indexNameAllSitesByDeliveryType,
61
- KeyConditionExpression: 'GSI1PK = :gsi1pk AND deliveryType = :deliveryType',
62
- ExpressionAttributeValues: {
63
- ':gsi1pk': config.pkAllSites,
64
- ':deliveryType': deliveryType,
65
- },
66
- });
67
-
68
- return dynamoItems.map((dynamoItem) => SiteDto.fromDynamoItem(dynamoItem));
69
- };
70
-
71
- /**
72
- * Retrieves a list of site IDs of all sites.
73
- *
74
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
75
- * @param {DataAccessConfig} config - The data access config.
76
- * @returns {Promise<Array<string>>} A promise that resolves to an array of site IDs of all sites.
77
- */
78
- export const getSitesToAudit = async (dynamoClient, config) => {
79
- const sites = await getSites(dynamoClient, config);
80
-
81
- return sites.map((site) => site.getId());
82
- };
83
-
84
- /**
85
- * Retrieves all sites with their latest audit. Sites without a latest audit will be included
86
- * in the result, but will have an empty audits array. The sites are sorted by their latest
87
- * audit scores in ascending order by default. The sortAuditsAscending parameter can be used
88
- * to change the sort order. If a site has no latest audit, it will be sorted at the end of
89
- * the list.
90
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
91
- * @param {DataAccessConfig} config - The data access config.
92
- * @param {Logger} log - The log.
93
- * @param {string} auditType - The type of audits to retrieve for the sites.
94
- * @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
95
- * ascending order.
96
- * @param {string} [deliveryType=DEFAULT_DELIVERY_TYPE] - The delivery type of the sites
97
- * to retrieve.
98
- * @return {Promise<Readonly<Site>[]>} A promise that resolves to an array of sites with their
99
- * latest audit.
100
- */
101
- export const getSitesWithLatestAudit = async (
102
- dynamoClient,
103
- config,
104
- log,
105
- auditType,
106
- sortAuditsAscending = true,
107
- deliveryType = 'all',
108
- ) => {
109
- const [sites, latestAudits] = await Promise.all([
110
- getSitesByDeliveryType(dynamoClient, config, deliveryType),
111
- getLatestAudits(dynamoClient, config, log, auditType, sortAuditsAscending),
112
- ]);
113
-
114
- const sitesMap = new Map(sites.map((site) => [site.getId(), site]));
115
- const orderedSites = [];
116
-
117
- // First, append sites with a latest audit in the sorted order
118
- latestAudits.forEach((audit) => {
119
- const site = sitesMap.get(audit.getSiteId());
120
- if (site) {
121
- site.setAudits([audit]);
122
- orderedSites.push(site);
123
- sitesMap.delete(site.getId()); // Remove the site from the map to avoid adding it again
124
- }
125
- });
126
-
127
- // Then, append the remaining sites (without a latest audit)
128
- sitesMap.forEach((site) => {
129
- site.setAudits([]);
130
- orderedSites.push(site);
131
- });
132
-
133
- return orderedSites;
134
- };
135
-
136
- /**
137
- * Retrieves a site by its base URL.
138
- *
139
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
140
- * @param {DataAccessConfig} config - The data access config.
141
- * @param {Logger} log - The log.
142
- * @param {string} baseURL - The base URL of the site to retrieve.
143
- * @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object if found,
144
- * otherwise null.
145
- */
146
- export const getSiteByBaseURL = async (
147
- dynamoClient,
148
- config,
149
- log,
150
- baseURL,
151
- ) => {
152
- const dynamoItems = await dynamoClient.query({
153
- TableName: config.tableNameSites,
154
- IndexName: config.indexNameAllSites,
155
- KeyConditionExpression: 'GSI1PK = :gsi1pk AND baseURL = :baseURL',
156
- ExpressionAttributeValues: {
157
- ':gsi1pk': config.pkAllSites,
158
- ':baseURL': baseURL,
159
- },
160
- Limit: 1,
161
- });
162
-
163
- return dynamoItems.length > 0 ? SiteDto.fromDynamoItem(dynamoItems[0]) : null;
164
- };
165
-
166
- /**
167
- * Retrieves a site by its base URL, along with associated audit information.
168
- *
169
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
170
- * @param {DataAccessConfig} config - The data access config.
171
- * @param {Logger} log - The log.
172
- * @param {string} baseUrl - The base URL of the site to retrieve.
173
- * @param {string} auditType - The type of audits to retrieve for the site.
174
- * @param {boolean} [latestOnly=false] - Determines if only the latest audit should be retrieved.
175
- * @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object with audit
176
- * data if found, otherwise null.
177
- */
178
- export const getSiteByBaseURLWithAuditInfo = async (
179
- dynamoClient,
180
- config,
181
- log,
182
- baseUrl,
183
- auditType,
184
- latestOnly = false,
185
- ) => {
186
- const site = await getSiteByBaseURL(dynamoClient, config, log, baseUrl);
187
-
188
- if (!isObject(site)) {
189
- return null;
190
- }
191
-
192
- const audits = latestOnly
193
- ? [await getLatestAuditForSite(
194
- dynamoClient,
195
- config,
196
- log,
197
- site.getId(),
198
- auditType,
199
- )].filter((audit) => audit != null)
200
- : await getAuditsForSite(
201
- dynamoClient,
202
- config,
203
- log,
204
- site.getId(),
205
- auditType,
206
- );
207
-
208
- site.setAudits(audits);
209
-
210
- return site;
211
- };
212
-
213
- /**
214
- * Retrieves a site by its base URL, including all its audits.
215
- *
216
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
217
- * @param {DataAccessConfig} config - The data access config.
218
- * @param {Logger} log - The log.
219
- * @param {string} baseUrl - The base URL of the site to retrieve.
220
- * @param {string} auditType - The type of audits to retrieve for the site.
221
- * @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object
222
- * with all its audits.
223
- */
224
- export const getSiteByBaseURLWithAudits = async (
225
- dynamoClient,
226
- config,
227
- log,
228
- baseUrl,
229
- auditType,
230
- ) => getSiteByBaseURLWithAuditInfo(dynamoClient, config, log, baseUrl, auditType, false);
231
-
232
- /**
233
- * Retrieves a site by its base URL, including only its latest audit.
234
- *
235
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
236
- * @param {DataAccessConfig} config - The data access config.
237
- * @param {Logger} log - The log.
238
- * @param {string} baseUrl - The base URL of the site to retrieve.
239
- * @param {string} auditType - The type of the latest audit to retrieve for the site.
240
- * @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object
241
- * with its latest audit.
242
- */
243
- export const getSiteByBaseURLWithLatestAudit = async (
244
- dynamoClient,
245
- config,
246
- log,
247
- baseUrl,
248
- auditType,
249
- ) => getSiteByBaseURLWithAuditInfo(dynamoClient, config, log, baseUrl, auditType, true);
250
-
251
- export const getSitesByOrganizationID = async (
252
- dynamoClient,
253
- config,
254
- organizationId,
255
- ) => {
256
- const dynamoItems = await dynamoClient.query({
257
- TableName: config.tableNameSites,
258
- IndexName: config.indexNameAllSitesOrganizations,
259
- KeyConditionExpression: 'organizationId = :organizationId',
260
- ExpressionAttributeValues: {
261
- ':organizationId': organizationId,
262
- },
263
- });
264
-
265
- return dynamoItems.map((dynamoItem) => SiteDto.fromDynamoItem(dynamoItem));
266
- };
267
-
268
- /**
269
- * Retrieves sites by organizationId with their latest audit. Sites without a latest
270
- * audit will not be included in the result.
271
- * The sites are sorted by their latest audit scores in ascending order by default.
272
- * The sortAuditsAscending parameter can be used to change the sort order.
273
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
274
- * @param {DataAccessConfig} config - The data access config.
275
- * @param {Logger} log - The log.
276
- * @param {string} auditType - The type of audits to retrieve for the sites.
277
- * @param {string} organizationId - The organizationId to retrieve the sites.
278
- * @param {boolean} [sortAuditsAscending=true] - Determines if the audits should be sorted in
279
- * ascending order.
280
- * to retrieve.
281
- * @return {Promise<Readonly<Site>[]>} A promise that resolves to an array of sites with their
282
- * latest audit.
283
- */
284
- export const getSitesByOrganizationIDWithLatestAudits = async (
285
- dynamoClient,
286
- config,
287
- log,
288
- organizationId,
289
- auditType,
290
- sortAuditsAscending = true,
291
- ) => {
292
- const [sites, latestAudits] = await Promise.all([
293
- getSitesByOrganizationID(dynamoClient, config, organizationId),
294
- getLatestAudits(dynamoClient, config, log, auditType, sortAuditsAscending),
295
- ]);
296
-
297
- const sitesMap = new Map(sites.map((site) => [site.getId(), site]));
298
- const orderedSites = [];
299
-
300
- // Append sites with the latest audit in the sorted order
301
- latestAudits.forEach((audit) => {
302
- const site = sitesMap.get(audit.getSiteId());
303
- if (site) {
304
- site.setAudits([audit]);
305
- orderedSites.push(site);
306
- sitesMap.delete(site.getId()); // Remove the site from the map to avoid adding it again
307
- }
308
- });
309
-
310
- // Then, append the remaining sites (without a latest audit)
311
- sitesMap.forEach((site) => {
312
- site.setAudits([]);
313
- orderedSites.push(site);
314
- });
315
-
316
- return orderedSites;
317
- };
318
-
319
- /**
320
- * Retrieves a site by its ID.
321
- *
322
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
323
- * @param {DataAccessConfig} config - The data access config.
324
- * @param {Logger} log - The log.
325
- * @param {string} siteId - The ID of the site to retrieve.
326
- * @returns {Promise<Readonly<Site>|null>} A promise that resolves to the site object if found,
327
- * otherwise null.
328
- */
329
- export const getSiteByID = async (
330
- dynamoClient,
331
- config,
332
- log,
333
- siteId,
334
- ) => {
335
- const dynamoItem = await dynamoClient.getItem(config.tableNameSites, { id: siteId });
336
-
337
- return isObject(dynamoItem) ? SiteDto.fromDynamoItem(dynamoItem) : null;
338
- };
339
- /**
340
- * Adds a site.
341
- *
342
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
343
- * @param {DataAccessConfig} config - The data access config.
344
- * @param {Logger} log - The log.
345
- * @param {object} siteData - The site data.
346
- * @returns {Promise<Readonly<Site>>}
347
- */
348
- export const addSite = async (
349
- dynamoClient,
350
- config,
351
- log,
352
- siteData,
353
- ) => {
354
- const site = createSite(siteData);
355
- const existingSite = await getSiteByBaseURL(
356
- dynamoClient,
357
- config,
358
- log,
359
- site.getBaseURL(),
360
- );
361
-
362
- if (isObject(existingSite)) {
363
- throw new Error('Site already exists');
364
- }
365
-
366
- await dynamoClient.putItem(config.tableNameSites, SiteDto.toDynamoItem(site));
367
-
368
- return site;
369
- };
370
-
371
- /**
372
- * Updates a site.
373
- *
374
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
375
- * @param {DataAccessConfig} config - The data access config.
376
- * @param {Logger} log - The log.
377
- * @param {Site} site - The site.
378
- * @returns {Promise<Readonly<Site>>} - The updated site.
379
- */
380
- export const updateSite = async (
381
- dynamoClient,
382
- config,
383
- log,
384
- site,
385
- ) => {
386
- const existingSite = await getSiteByBaseURL(dynamoClient, config, log, site.getBaseURL());
387
-
388
- if (!isObject(existingSite)) {
389
- throw new Error('Site not found');
390
- }
391
-
392
- await dynamoClient.putItem(config.tableNameSites, SiteDto.toDynamoItem(site));
393
-
394
- return site;
395
- };
396
-
397
- /**
398
- * Removes a site and its related audits.
399
- *
400
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
401
- * @param {DataAccessConfig} config - The data access config.
402
- * @param {Logger} log - The log.
403
- * @param {string} siteId - The ID of the site to remove.
404
- * @returns {Promise<void>}
405
- */
406
- export const removeSite = async (
407
- dynamoClient,
408
- config,
409
- log,
410
- siteId,
411
- ) => {
412
- try {
413
- // TODO: Add transaction support
414
- await removeAuditsForSite(dynamoClient, config, log, siteId);
415
-
416
- await dynamoClient.removeItem(config.tableNameSites, { id: siteId });
417
- } catch (error) {
418
- log.error(`Error removing site: ${error.message}`);
419
- throw error;
420
- }
421
- };
422
-
423
- /**
424
- * Removes all given sites.
425
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
426
- * @param {DataAccessConfig} config - The data access config.
427
- * @param {Array<Site>} sites - The sites to remove.
428
- * @return {Promise<void>} A promise that resolves when all sites have been removed.
429
- */
430
- async function removeSites(
431
- dynamoClient,
432
- config,
433
- sites,
434
- ) {
435
- const tableName = config.tableNameSites;
436
- // TODO: use batch-remove (needs dynamo client update)
437
- const removeSitePromises = sites.map((site) => dynamoClient.removeItem(
438
- tableName,
439
- { id: site.getId() },
440
- ));
441
-
442
- await Promise.all(removeSitePromises);
443
- }
444
-
445
- /**
446
- * Removes all sites for an organization.
447
- * @param {DynamoDbClient} dynamoClient - The DynamoDB client.
448
- * @param {DataAccessConfig} config - The data access config.
449
- * @param {Logger} log - The log.
450
- * @param {string} organizationId - The ID of the organization to remove the sites for.
451
- * @return {Promise<void>} A promise that resolves when all sites for the organization have been
452
- * removed.
453
- */
454
- export const removeSitesForOrganization = async (
455
- dynamoClient,
456
- config,
457
- log,
458
- organizationId,
459
- ) => {
460
- try {
461
- const sites = await getSitesByOrganizationID(dynamoClient, config, organizationId);
462
- await removeSites(dynamoClient, config, sites);
463
- } catch (error) {
464
- log.error(`Error removing sites for organization ${organizationId}: ${error.message}`);
465
- throw error;
466
- }
467
- };
@@ -1,116 +0,0 @@
1
- /*
2
- * Copyright 2023 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
- addSite,
15
- getSiteByBaseURL,
16
- getSiteByBaseURLWithAuditInfo,
17
- getSiteByBaseURLWithAudits,
18
- getSiteByBaseURLWithLatestAudit,
19
- getSiteByID,
20
- getSites,
21
- getSitesByDeliveryType,
22
- getSitesByOrganizationID, getSitesByOrganizationIDWithLatestAudits,
23
- getSitesToAudit,
24
- getSitesWithLatestAudit,
25
- removeSite,
26
- removeSitesForOrganization,
27
- updateSite,
28
- } from './accessPatterns.js';
29
-
30
- export const siteFunctions = (dynamoClient, config, log) => ({
31
- getSites: () => getSites(
32
- dynamoClient,
33
- config,
34
- ),
35
- getSitesByDeliveryType: (deliveryType) => getSitesByDeliveryType(
36
- dynamoClient,
37
- config,
38
- deliveryType,
39
- ),
40
- getSitesByOrganizationID: (organizationId) => getSitesByOrganizationID(
41
- dynamoClient,
42
- config,
43
- organizationId,
44
- ),
45
- getSitesToAudit: () => getSitesToAudit(
46
- dynamoClient,
47
- config,
48
- ),
49
- getSitesWithLatestAudit: (
50
- auditType,
51
- sortAuditsAscending,
52
- deliveryType,
53
- ) => getSitesWithLatestAudit(
54
- dynamoClient,
55
- config,
56
- log,
57
- auditType,
58
- sortAuditsAscending,
59
- deliveryType,
60
- ),
61
- getSitesByOrganizationIDWithLatestAudits: (
62
- organizationId,
63
- auditType,
64
- sortAuditsAscending,
65
- ) => getSitesByOrganizationIDWithLatestAudits(
66
- dynamoClient,
67
- config,
68
- log,
69
- organizationId,
70
- auditType,
71
- sortAuditsAscending,
72
- ),
73
- getSiteByBaseURL: (baseUrl) => getSiteByBaseURL(
74
- dynamoClient,
75
- config,
76
- log,
77
- baseUrl,
78
- ),
79
- getSiteByID: (siteId) => getSiteByID(
80
- dynamoClient,
81
- config,
82
- log,
83
- siteId,
84
- ),
85
- getSiteByBaseURLWithAuditInfo: (baseUrl, auditType, latestOnly) => getSiteByBaseURLWithAuditInfo(
86
- dynamoClient,
87
- config,
88
- log,
89
- baseUrl,
90
- auditType,
91
- latestOnly,
92
- ),
93
- getSiteByBaseURLWithAudits: (baseUrl, auditType) => getSiteByBaseURLWithAudits(
94
- dynamoClient,
95
- config,
96
- log,
97
- baseUrl,
98
- auditType,
99
- ),
100
- getSiteByBaseURLWithLatestAudit: (baseUrl, auditType) => getSiteByBaseURLWithLatestAudit(
101
- dynamoClient,
102
- config,
103
- log,
104
- baseUrl,
105
- auditType,
106
- ),
107
- addSite: (siteData) => addSite(dynamoClient, config, log, siteData),
108
- updateSite: (site) => updateSite(dynamoClient, config, log, site),
109
- removeSite: (siteId) => removeSite(dynamoClient, config, log, siteId),
110
- removeSitesForOrganization: (organizationId) => removeSitesForOrganization(
111
- dynamoClient,
112
- config,
113
- log,
114
- organizationId,
115
- ),
116
- });
package/src/v2/index.js DELETED
@@ -1,15 +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
- export * from './errors/index.js';
14
- export * from './models/index.js';
15
- export * from './util/index.js';
@@ -1,26 +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
- export type * from './audit/index.d.ts';
14
- export type * from './configuration/index.d.ts';
15
- export type * from './base/index.d.ts';
16
- export type * from './experiment/index.d.ts';
17
- export type * from './import-job/index.d.ts';
18
- export type * from './import-url/index.d.ts';
19
- export type * from './key-event/index.d.ts';
20
- export type * from './latest-audit/index.d.ts';
21
- export type * from './opportunity/index.d.ts';
22
- export type * from './organization/index.d.ts';
23
- export type * from './site/index.d.ts';
24
- export type * from './site-candidate/index.d.ts';
25
- export type * from './site-top-page/index.d.ts';
26
- export type * from './suggestion/index.d.ts';
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes