From cb00aff13e3bcb7f07222b1f562797359898c593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= Date: Sat, 2 Dec 2023 04:06:54 +0100 Subject: [PATCH 1/4] feat: allow configuration from context env --- .../docs/schema.json | 10 +-- .../src/index.d.ts | 11 +++ .../spacecat-shared-data-access/src/index.js | 29 ++++++- .../src/service/audits/accessPatterns.js | 87 ++++++++++++------- .../src/service/audits/index.js | 8 +- .../src/service/index.js | 7 +- .../src/service/sites/accessPatterns.js | 81 +++++++++++------ .../src/service/sites/index.js | 15 +++- .../test/it/db.test.js | 14 ++- .../test/it/generateSampleData.js | 46 +++++++--- .../test/unit/index.test.js | 5 +- .../test/unit/service/audits/index.test.js | 18 +++- .../test/unit/service/sites/index.test.js | 20 +++-- 13 files changed, 258 insertions(+), 93 deletions(-) diff --git a/packages/spacecat-shared-data-access/docs/schema.json b/packages/spacecat-shared-data-access/docs/schema.json index 4ba87ec92..cd11554ab 100644 --- a/packages/spacecat-shared-data-access/docs/schema.json +++ b/packages/spacecat-shared-data-access/docs/schema.json @@ -10,7 +10,7 @@ }, "DataModel": [ { - "TableName": "sites", + "TableName": "spacecat-services-sites", "KeyAttributes": { "PartitionKey": { "AttributeName": "id", @@ -41,7 +41,7 @@ ], "GlobalSecondaryIndexes": [ { - "IndexName": "all_sites", + "IndexName": "spacecat-services-all-sites", "KeyAttributes": { "PartitionKey": { "AttributeName": "GSI1PK", @@ -103,7 +103,7 @@ } }, { - "TableName": "audits", + "TableName": "spacecat-services-audits", "KeyAttributes": { "PartitionKey": { "AttributeName": "siteId", @@ -182,7 +182,7 @@ } }, { - "TableName": "latest_audits", + "TableName": "spacecat-services-latest-audits", "KeyAttributes": { "PartitionKey": { "AttributeName": "siteId", @@ -225,7 +225,7 @@ ], "GlobalSecondaryIndexes": [ { - "IndexName": "all_latest_audit_scores", + "IndexName": "spacecat-services-all-latest-audit-scores", "KeyAttributes": { "PartitionKey": { "AttributeName": "GSI1PK", diff --git a/packages/spacecat-shared-data-access/src/index.d.ts b/packages/spacecat-shared-data-access/src/index.d.ts index 09a4d509d..31026f86b 100644 --- a/packages/spacecat-shared-data-access/src/index.d.ts +++ b/packages/spacecat-shared-data-access/src/index.d.ts @@ -82,6 +82,17 @@ export interface DataAccess { ) => Promise; } +interface DataAccessConfig { + tableNameAudits: string; + tableNameLatestAudits: string; + tableNameSites: string; + indexNameAllSites: string; + indexNameAllLatestAuditScores: string; + pkAllSites: string; + pkAllLatestAudits: string; +} + export function createDataAccess( + config: DataAccessConfig, logger: object, ): DataAccess; diff --git a/packages/spacecat-shared-data-access/src/index.js b/packages/spacecat-shared-data-access/src/index.js index 3fab17cb4..7e7c8a504 100644 --- a/packages/spacecat-shared-data-access/src/index.js +++ b/packages/spacecat-shared-data-access/src/index.js @@ -12,11 +12,38 @@ import { createDataAccess } from './service/index.js'; +const TABLE_NAME_AUDITS = 'spacecat-services-audits'; +const TABLE_NAME_LATEST_AUDITS = 'spacecat-services-latest-audits'; +const TABLE_NAME_SITES = 'spacecat-services-sites'; + +const INDEX_NAME_ALL_SITES = 'spacecat-services-all-sites'; +const INDEX_NAME_ALL_LATEST_AUDIT_SCORES = 'spacecat-services-all-latest-audit-scores'; + +const PK_ALL_SITES = 'ALL_SITES'; +const PK_ALL_LATEST_AUDITS = 'ALL_LATEST_AUDITS'; + export default function dataAccessWrapper(fn) { return async (request, context) => { if (!context.dataAccess) { const { log } = context; - context.dataAccess = createDataAccess(log); + + const { + DYNAMO_TABLE_NAME_AUDITS = TABLE_NAME_AUDITS, + DYNAMO_TABLE_NAME_LATEST_AUDITS = TABLE_NAME_LATEST_AUDITS, + DYNAMO_TABLE_NAME_SITES = TABLE_NAME_SITES, + DYNAMO_INDEX_NAME_ALL_SITES = INDEX_NAME_ALL_SITES, + DYNAMO_INDEX_NAME_ALL_LATEST_AUDIT_SCORES = INDEX_NAME_ALL_LATEST_AUDIT_SCORES, + } = context.env; + + context.dataAccess = createDataAccess({ + tableNameAudits: DYNAMO_TABLE_NAME_AUDITS, + tableNameLatestAudits: DYNAMO_TABLE_NAME_LATEST_AUDITS, + tableNameSites: DYNAMO_TABLE_NAME_SITES, + indexNameAllSites: DYNAMO_INDEX_NAME_ALL_SITES, + indexNameAllLatestAuditScores: DYNAMO_INDEX_NAME_ALL_LATEST_AUDIT_SCORES, + pkAllSites: PK_ALL_SITES, + pkAllLatestAudits: PK_ALL_LATEST_AUDITS, + }, log); } return fn(request, context); diff --git a/packages/spacecat-shared-data-access/src/service/audits/accessPatterns.js b/packages/spacecat-shared-data-access/src/service/audits/accessPatterns.js index df611922d..cbb142e55 100644 --- a/packages/spacecat-shared-data-access/src/service/audits/accessPatterns.js +++ b/packages/spacecat-shared-data-access/src/service/audits/accessPatterns.js @@ -15,25 +15,21 @@ import { isObject } from '@adobe/spacecat-shared-utils'; import { AuditDto } from '../../dto/audit.js'; import { createAudit } from '../../models/audit.js'; -const TABLE_NAME_AUDITS = 'audits'; -const TABLE_NAME_LATEST_AUDITS = 'latest_audits'; -const INDEX_NAME_ALL_LATEST_AUDIT_SCORES = 'all_latest_audit_scores'; -const PK_ALL_LATEST_AUDITS = 'ALL_LATEST_AUDITS'; - /** * Retrieves audits for a specified site. If an audit type is provided, * it returns only audits of that type. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} siteId - The ID of the site for which audits are being retrieved. * @param {string} [auditType] - Optional. The type of audits to retrieve. * @returns {Promise[]>} A promise that resolves to an array of audits * for the specified site. */ -export const getAuditsForSite = async (dynamoClient, log, siteId, auditType) => { +export const getAuditsForSite = async (dynamoClient, config, log, siteId, auditType) => { const queryParams = { - TableName: TABLE_NAME_AUDITS, + TableName: config.tableNameAudits, KeyConditionExpression: 'siteId = :siteId', ExpressionAttributeValues: { ':siteId': siteId, @@ -54,6 +50,7 @@ export const getAuditsForSite = async (dynamoClient, log, siteId, auditType) => * Retrieves a specific audit for a specified site. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} siteId - The ID of the site for which to retrieve the audit. * @param {string} auditType - The type of audit to retrieve. @@ -62,13 +59,14 @@ export const getAuditsForSite = async (dynamoClient, log, siteId, auditType) => */ export const getAuditForSite = async ( dynamoClient, + config, log, siteId, auditType, auditedAt, ) => { const audit = await dynamoClient.query({ - TableName: TABLE_NAME_AUDITS, + TableName: config.tableNameAudits, KeyConditionExpression: 'siteId = :siteId AND SK = :sk', ExpressionAttributeValues: { ':siteId': siteId, @@ -84,6 +82,7 @@ export const getAuditForSite = async ( * Retrieves the latest audits of a specific type across all sites. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} auditType - The type of audits to retrieve. * @param {boolean} ascending - Determines if the audits should be sorted ascending @@ -93,16 +92,17 @@ export const getAuditForSite = async ( */ export const getLatestAudits = async ( dynamoClient, + config, log, auditType, ascending = true, ) => { const dynamoItems = await dynamoClient.query({ - TableName: TABLE_NAME_LATEST_AUDITS, - IndexName: INDEX_NAME_ALL_LATEST_AUDIT_SCORES, + TableName: config.tableNameLatestAudits, + IndexName: config.indexNameAllLatestAuditScores, KeyConditionExpression: 'GSI1PK = :gsi1pk AND begins_with(GSI1SK, :auditType)', ExpressionAttributeValues: { - ':gsi1pk': PK_ALL_LATEST_AUDITS, + ':gsi1pk': config.pkAllLatestAudits, ':auditType': `${auditType}#`, }, ScanIndexForward: ascending, // Sorts ascending if true, descending if false @@ -115,14 +115,20 @@ export const getLatestAudits = async ( * Retrieves latest audits for a specified site. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} siteId - The ID of the site for which audits are being retrieved. * @returns {Promise[]>} A promise that resolves to an array of latest audits * for the specified site. */ -export const getLatestAuditsForSite = async (dynamoClient, log, siteId) => { +export const getLatestAuditsForSite = async ( + dynamoClient, + config, + log, + siteId, +) => { const queryParams = { - TableName: TABLE_NAME_LATEST_AUDITS, + TableName: config.tableNameLatestAudits, KeyConditionExpression: 'siteId = :siteId', ExpressionAttributeValues: { ':siteId': siteId }, }; @@ -136,6 +142,7 @@ export const getLatestAuditsForSite = async (dynamoClient, log, siteId) => { * Retrieves the latest audit for a specified site and audit type. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} siteId - The ID of the site for which the latest audit is being retrieved. * @param {string} auditType - The type of audit to retrieve the latest instance of. @@ -144,12 +151,13 @@ export const getLatestAuditsForSite = async (dynamoClient, log, siteId) => { */ export const getLatestAuditForSite = async ( dynamoClient, + config, log, siteId, auditType, ) => { const latestAudit = await dynamoClient.query({ - TableName: TABLE_NAME_LATEST_AUDITS, + TableName: config.tableNameLatestAudits, KeyConditionExpression: 'siteId = :siteId AND begins_with(SK, :auditType)', ExpressionAttributeValues: { ':siteId': siteId, @@ -165,14 +173,21 @@ export const getLatestAuditForSite = async ( * Adds an audit. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {object} auditData - The audit data. * @returns {Promise>} */ -export const addAudit = async (dynamoClient, log, auditData) => { +export const addAudit = async ( + dynamoClient, + config, + log, + auditData, +) => { const audit = createAudit(auditData); const existingAudit = await getAuditForSite( dynamoClient, + config, log, audit.getSiteId(), audit.getAuditType(), @@ -184,8 +199,8 @@ export const addAudit = async (dynamoClient, log, auditData) => { } // TODO: Add transaction support - await dynamoClient.putItem('audits', AuditDto.toDynamoItem(audit)); - await dynamoClient.putItem('latest_audits', AuditDto.toDynamoItem(audit, true)); + await dynamoClient.putItem(config.tableNameAudits, AuditDto.toDynamoItem(audit)); + await dynamoClient.putItem(config.tableNameLatestAudits, AuditDto.toDynamoItem(audit, true)); return audit; }; @@ -193,18 +208,26 @@ export const addAudit = async (dynamoClient, log, auditData) => { /** * Removes audits from the database. * @param {DynamoDbClient} dynamoClient - The DynamoDB client. - * @param {Logger} log - The logger. + * @param {DataAccessConfig} config - The data access config. * @param audits * @param latest * @returns {Promise} */ -async function removeAudits(dynamoClient, audits, latest = false) { - const tableName = latest ? TABLE_NAME_LATEST_AUDITS : TABLE_NAME_AUDITS; +async function removeAudits( + dynamoClient, + config, + audits, + latest = false, +) { + const tableName = latest ? config.tableNameLatestAudits : config.tableNameAudits; // TODO: use batch-remove (needs dynamo client update) - const removeAuditPromises = audits.map((audit) => dynamoClient.removeItem(tableName, { - siteId: audit.getSiteId(), - SK: `${audit.getAuditType()}#${audit.getAuditedAt()}`, - })); + const removeAuditPromises = audits.map((audit) => dynamoClient.removeItem( + tableName, + { + siteId: audit.getSiteId(), + SK: `${audit.getAuditType()}#${audit.getAuditedAt()}`, + }, + )); await Promise.all(removeAuditPromises); } @@ -213,17 +236,23 @@ async function removeAudits(dynamoClient, audits, latest = false) { * Removes all audits for a specified site and the latest audit entry. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} siteId - The ID of the site for which audits are being removed. * @returns {Promise} */ -export const removeAuditsForSite = async (dynamoClient, log, siteId) => { +export const removeAuditsForSite = async ( + dynamoClient, + config, + log, + siteId, +) => { try { - const audits = await getAuditsForSite(dynamoClient, log, siteId); - const latestAudits = await getLatestAuditsForSite(dynamoClient, log, siteId); + const audits = await getAuditsForSite(dynamoClient, config, log, siteId); + const latestAudits = await getLatestAuditsForSite(dynamoClient, config, log, siteId); - await removeAudits(dynamoClient, audits); - await removeAudits(dynamoClient, latestAudits, true); + await removeAudits(dynamoClient, config, audits); + await removeAudits(dynamoClient, config, latestAudits, true); } catch (error) { log.error(`Error removing audits for site ${siteId}: ${error.message}`); throw error; diff --git a/packages/spacecat-shared-data-access/src/service/audits/index.js b/packages/spacecat-shared-data-access/src/service/audits/index.js index f21e86b27..c4280a7a4 100644 --- a/packages/spacecat-shared-data-access/src/service/audits/index.js +++ b/packages/spacecat-shared-data-access/src/service/audits/index.js @@ -18,9 +18,10 @@ import { removeAuditsForSite, } from './accessPatterns.js'; -export const auditFunctions = (dynamoClient, log) => ({ +export const auditFunctions = (dynamoClient, config, log) => ({ getAuditForSite: (siteId, auditType, auditedAt) => getAuditForSite( dynamoClient, + config, log, siteId, auditType, @@ -28,29 +29,34 @@ export const auditFunctions = (dynamoClient, log) => ({ ), getAuditsForSite: (siteId, auditType) => getAuditsForSite( dynamoClient, + config, log, siteId, auditType, ), getLatestAudits: (auditType, ascending) => getLatestAudits( dynamoClient, + config, log, auditType, ascending, ), getLatestAuditForSite: (siteId, auditType) => getLatestAuditForSite( dynamoClient, + config, log, siteId, auditType, ), addAudit: (auditData) => addAudit( dynamoClient, + config, log, auditData, ), removeAuditsForSite: (siteId) => removeAuditsForSite( dynamoClient, + config, log, siteId, ), diff --git a/packages/spacecat-shared-data-access/src/service/index.js b/packages/spacecat-shared-data-access/src/service/index.js index 6f0b9bddf..df680326a 100644 --- a/packages/spacecat-shared-data-access/src/service/index.js +++ b/packages/spacecat-shared-data-access/src/service/index.js @@ -17,14 +17,15 @@ import { siteFunctions } from './sites/index.js'; /** * Creates a data access object. * + * @param {DataAccessConfig} config configuration * @param {Logger} log logger * @returns {object} data access object */ -export const createDataAccess = (log = console) => { +export const createDataAccess = (config, log = console) => { const dynamoClient = createClient(log); - const auditFuncs = auditFunctions(dynamoClient, log); - const siteFuncs = siteFunctions(dynamoClient, log); + const auditFuncs = auditFunctions(dynamoClient, config, log); + const siteFuncs = siteFunctions(dynamoClient, config, log); return { ...auditFuncs, diff --git a/packages/spacecat-shared-data-access/src/service/sites/accessPatterns.js b/packages/spacecat-shared-data-access/src/service/sites/accessPatterns.js index f5bcf99c6..fe589753b 100644 --- a/packages/spacecat-shared-data-access/src/service/sites/accessPatterns.js +++ b/packages/spacecat-shared-data-access/src/service/sites/accessPatterns.js @@ -21,23 +21,20 @@ import { import { createSite } from '../../models/site.js'; import { SiteDto } from '../../dto/site.js'; -const INDEX_NAME_ALL_SITES = 'all_sites'; -const PK_ALL_SITES = 'ALL_SITES'; -const TABLE_NAME_SITES = 'sites'; - /** * Retrieves all sites. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @returns {Promise[]>} A promise that resolves to an array of all sites. */ -export const getSites = async (dynamoClient) => { +export const getSites = async (dynamoClient, config) => { const dynamoItems = await dynamoClient.query({ - TableName: TABLE_NAME_SITES, - IndexName: INDEX_NAME_ALL_SITES, // GSI name + TableName: config.tableNameSites, + IndexName: config.indexNameAllSites, KeyConditionExpression: 'GSI1PK = :gsi1pk', ExpressionAttributeValues: { - ':gsi1pk': PK_ALL_SITES, + ':gsi1pk': config.pkAllSites, }, }); @@ -48,10 +45,11 @@ export const getSites = async (dynamoClient) => { * Retrieves a list of base URLs for all sites. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @returns {Promise>} A promise that resolves to an array of base URLs for all sites. */ -export const getSitesToAudit = async (dynamoClient) => { - const sites = await getSites(dynamoClient); +export const getSitesToAudit = async (dynamoClient, config) => { + const sites = await getSites(dynamoClient, config); return sites.map((site) => site.getBaseURL()); }; @@ -60,6 +58,7 @@ export const getSitesToAudit = async (dynamoClient) => { * Retrieves sites with their latest audit of a specified type. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} auditType - The type of the latest audits to retrieve for each site. * @param {boolean} [sortAuditsAscending] - Optional. Determines if the audits @@ -69,13 +68,14 @@ export const getSitesToAudit = async (dynamoClient) => { */ export const getSitesWithLatestAudit = async ( dynamoClient, + config, log, auditType, sortAuditsAscending = true, ) => { const [sites, latestAudits] = await Promise.all([ - getSites(dynamoClient), - getLatestAudits(dynamoClient, log, auditType, sortAuditsAscending), + getSites(dynamoClient, config), + getLatestAudits(dynamoClient, config, log, auditType, sortAuditsAscending), ]); const sitesMap = new Map(sites.map((site) => [site.getId(), site])); @@ -94,6 +94,7 @@ export const getSitesWithLatestAudit = async ( * Retrieves a site by its base URL. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} baseURL - The base URL of the site to retrieve. * @returns {Promise|null>} A promise that resolves to the site object if found, @@ -101,15 +102,16 @@ export const getSitesWithLatestAudit = async ( */ export const getSiteByBaseURL = async ( dynamoClient, + config, log, baseURL, ) => { const dynamoItems = await dynamoClient.query({ - TableName: TABLE_NAME_SITES, - IndexName: INDEX_NAME_ALL_SITES, + TableName: config.tableNameSites, + IndexName: config.indexNameAllSites, KeyConditionExpression: 'GSI1PK = :gsi1pk AND baseURL = :baseURL', ExpressionAttributeValues: { - ':gsi1pk': PK_ALL_SITES, + ':gsi1pk': config.pkAllSites, ':baseURL': baseURL, }, Limit: 1, @@ -126,6 +128,7 @@ export const getSiteByBaseURL = async ( * Retrieves a site by its base URL, along with associated audit information. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} baseUrl - The base URL of the site to retrieve. * @param {string} auditType - The type of audits to retrieve for the site. @@ -135,12 +138,13 @@ export const getSiteByBaseURL = async ( */ export const getSiteByBaseURLWithAuditInfo = async ( dynamoClient, + config, log, baseUrl, auditType, latestOnly = false, ) => { - const site = await getSiteByBaseURL(dynamoClient, log, baseUrl); + const site = await getSiteByBaseURL(dynamoClient, config, log, baseUrl); if (!isObject(site)) { return null; @@ -149,12 +153,14 @@ export const getSiteByBaseURLWithAuditInfo = async ( const audits = latestOnly ? [await getLatestAuditForSite( dynamoClient, + config, log, site.getId(), auditType, )].filter((audit) => audit != null) : await getAuditsForSite( dynamoClient, + config, log, site.getId(), auditType, @@ -169,6 +175,7 @@ export const getSiteByBaseURLWithAuditInfo = async ( * Retrieves a site by its base URL, including all its audits. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} baseUrl - The base URL of the site to retrieve. * @param {string} auditType - The type of audits to retrieve for the site. @@ -177,15 +184,17 @@ export const getSiteByBaseURLWithAuditInfo = async ( */ export const getSiteByBaseURLWithAudits = async ( dynamoClient, + config, log, baseUrl, auditType, -) => getSiteByBaseURLWithAuditInfo(dynamoClient, log, baseUrl, auditType, false); +) => getSiteByBaseURLWithAuditInfo(dynamoClient, config, log, baseUrl, auditType, false); /** * Retrieves a site by its base URL, including only its latest audit. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} baseUrl - The base URL of the site to retrieve. * @param {string} auditType - The type of the latest audit to retrieve for the site. @@ -194,23 +203,31 @@ export const getSiteByBaseURLWithAudits = async ( */ export const getSiteByBaseURLWithLatestAudit = async ( dynamoClient, + config, log, baseUrl, auditType, -) => getSiteByBaseURLWithAuditInfo(dynamoClient, log, baseUrl, auditType, true); +) => getSiteByBaseURLWithAuditInfo(dynamoClient, config, log, baseUrl, auditType, true); /** * Adds a site. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {object} siteData - The site data. * @returns {Promise>} */ -export const addSite = async (dynamoClient, log, siteData) => { +export const addSite = async ( + dynamoClient, + config, + log, + siteData, +) => { const site = createSite(siteData); const existingSite = await getSiteByBaseURL( dynamoClient, + config, log, site.getBaseURL(), ); @@ -219,7 +236,7 @@ export const addSite = async (dynamoClient, log, siteData) => { throw new Error('Site already exists'); } - await dynamoClient.putItem(TABLE_NAME_SITES, SiteDto.toDynamoItem(site)); + await dynamoClient.putItem(config.tableNameSites, SiteDto.toDynamoItem(site)); return site; }; @@ -228,18 +245,24 @@ export const addSite = async (dynamoClient, log, siteData) => { * Updates a site. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {Site} site - The site. * @returns {Promise>} - The updated site. */ -export const updateSite = async (dynamoClient, log, site) => { - const existingSite = await getSiteByBaseURL(dynamoClient, log, site.getBaseURL()); +export const updateSite = async ( + dynamoClient, + config, + log, + site, +) => { + const existingSite = await getSiteByBaseURL(dynamoClient, config, log, site.getBaseURL()); if (!isObject(existingSite)) { throw new Error('Site not found'); } - await dynamoClient.putItem(TABLE_NAME_SITES, SiteDto.toDynamoItem(site)); + await dynamoClient.putItem(config.tableNameSites, SiteDto.toDynamoItem(site)); return site; }; @@ -248,16 +271,22 @@ export const updateSite = async (dynamoClient, log, site) => { * Removes a site and its related audits. * * @param {DynamoDbClient} dynamoClient - The DynamoDB client. + * @param {DataAccessConfig} config - The data access config. * @param {Logger} log - The logger. * @param {string} siteId - The ID of the site to remove. * @returns {Promise} */ -export const removeSite = async (dynamoClient, log, siteId) => { +export const removeSite = async ( + dynamoClient, + config, + log, + siteId, +) => { try { // TODO: Add transaction support - await removeAuditsForSite(dynamoClient, log, siteId); + await removeAuditsForSite(dynamoClient, config, log, siteId); - await dynamoClient.removeItem(TABLE_NAME_SITES, { id: siteId }); + await dynamoClient.removeItem(config.tableNameSites, { id: siteId }); } catch (error) { log.error(`Error removing site: ${error.message}`); throw error; diff --git a/packages/spacecat-shared-data-access/src/service/sites/index.js b/packages/spacecat-shared-data-access/src/service/sites/index.js index f43a2cb5c..e0e357511 100644 --- a/packages/spacecat-shared-data-access/src/service/sites/index.js +++ b/packages/spacecat-shared-data-access/src/service/sites/index.js @@ -22,26 +22,31 @@ import { updateSite, } from './accessPatterns.js'; -export const siteFunctions = (dynamoClient, log) => ({ +export const siteFunctions = (dynamoClient, config, log) => ({ getSites: () => getSites( dynamoClient, + config, ), getSitesToAudit: () => getSitesToAudit( dynamoClient, + config, ), getSitesWithLatestAudit: (auditType, sortAuditsAscending) => getSitesWithLatestAudit( dynamoClient, + config, log, auditType, sortAuditsAscending, ), getSiteByBaseURL: (baseUrl) => getSiteByBaseURL( dynamoClient, + config, log, baseUrl, ), getSiteByBaseURLWithAuditInfo: (baseUrl, auditType, latestOnly) => getSiteByBaseURLWithAuditInfo( dynamoClient, + config, log, baseUrl, auditType, @@ -49,17 +54,19 @@ export const siteFunctions = (dynamoClient, log) => ({ ), getSiteByBaseURLWithAudits: (baseUrl, auditType) => getSiteByBaseURLWithAudits( dynamoClient, + config, log, baseUrl, auditType, ), getSiteByBaseURLWithLatestAudit: (baseUrl, auditType) => getSiteByBaseURLWithLatestAudit( dynamoClient, + config, log, baseUrl, auditType, ), - addSite: (siteData) => addSite(dynamoClient, log, siteData), - updateSite: (site) => updateSite(dynamoClient, log, site), - removeSite: (siteId) => removeSite(dynamoClient, log, siteId), + addSite: (siteData) => addSite(dynamoClient, config, log, siteData), + updateSite: (site) => updateSite(dynamoClient, config, log, site), + removeSite: (siteId) => removeSite(dynamoClient, config, log, siteId), }); diff --git a/packages/spacecat-shared-data-access/test/it/db.test.js b/packages/spacecat-shared-data-access/test/it/db.test.js index 102842a18..2e838ecfa 100644 --- a/packages/spacecat-shared-data-access/test/it/db.test.js +++ b/packages/spacecat-shared-data-access/test/it/db.test.js @@ -48,6 +48,16 @@ function checkAudit(audit) { expect(audit.getFullAuditRef()).to.be.a('string'); } +const TEST_DA_CONFIG = { + tableNameAudits: 'spacecat-services-audits', + tableNameLatestAudits: 'spacecat-services-latest-audits', + tableNameSites: 'spacecat-services-sites', + indexNameAllSites: 'spacecat-services-all-sites', + indexNameAllLatestAuditScores: 'spacecat-services-all-latest-audit-scores', + pkAllSites: 'ALL_SITES', + pkAllLatestAudits: 'ALL_LATEST_AUDITS', +}; + describe('DynamoDB Integration Test', async () => { let dynamoDbLocalProcess; let dataAccess; @@ -67,9 +77,9 @@ describe('DynamoDB Integration Test', async () => { await sleep(1000); // give db time to start up - await generateSampleData(NUMBER_OF_SITES, NUMBER_OF_AUDITS_PER_TYPE_AND_SITE); + await generateSampleData(TEST_DA_CONFIG, NUMBER_OF_SITES, NUMBER_OF_AUDITS_PER_TYPE_AND_SITE); - dataAccess = createDataAccess(console); + dataAccess = createDataAccess(TEST_DA_CONFIG, console); }); after(() => { diff --git a/packages/spacecat-shared-data-access/test/it/generateSampleData.js b/packages/spacecat-shared-data-access/test/it/generateSampleData.js index 60719db65..d59bf8888 100644 --- a/packages/spacecat-shared-data-access/test/it/generateSampleData.js +++ b/packages/spacecat-shared-data-access/test/it/generateSampleData.js @@ -37,10 +37,12 @@ async function createTablesFromSchema() { * Iterates over a list of table names and deletes each one using the deleteTable function. * This is typically used to clean up the database before creating new tables or * generating test data. + * + * @param {Array} tableNames - An array of table names to delete. + * @returns {Promise} A promise that resolves when all tables have been deleted. */ -async function deleteExistingTables() { - const deletionPromises = ['sites', 'audits', 'latest_audits'] - .map((tableName) => deleteTable(dbClient, tableName)); +async function deleteExistingTables(tableNames) { + const deletionPromises = tableNames.map((tableName) => deleteTable(dbClient, tableName)); await Promise.all(deletionPromises); } @@ -73,6 +75,7 @@ async function batchWrite(tableName, items) { /** * Generates audit data for a specific site. * + * @param {DataAccessConfig} config - The data access config. * @param {string} siteId - The ID of the site for which to generate audit data. * @param {Array} auditTypes - An array of audit types to generate data for. * @param {number} numberOfAuditsPerType - The number of audits to generate for each type. @@ -82,7 +85,12 @@ async function batchWrite(tableName, items) { * // Example usage * const audits = generateAuditData('site123', ['lhs', 'cwv'], 5); */ -function generateAuditData(siteId, auditTypes, numberOfAuditsPerType) { +function generateAuditData( + config, + siteId, + auditTypes, + numberOfAuditsPerType, +) { const latestAudits = {}; const auditData = []; @@ -110,7 +118,7 @@ function generateAuditData(siteId, auditTypes, numberOfAuditsPerType) { return { ...audit, - GSI1PK: 'ALL_LATEST_AUDITS', + GSI1PK: config.pkAllLatestAudits, GSI1SK, }; }); @@ -121,6 +129,7 @@ function generateAuditData(siteId, auditTypes, numberOfAuditsPerType) { /** * Generates sample data for testing purposes. * + * @param {DataAccessConfig} config - The data access config. * @param {number} [numberOfSites=10] - The number of sites to generate. * @param {number} [numberOfAuditsPerType=5] - The number of audits per type to generate * for each site. @@ -129,9 +138,17 @@ function generateAuditData(siteId, auditTypes, numberOfAuditsPerType) { * // Example usage * generateSampleData(20, 10); // Generates 20 sites with 10 audits per type for each site */ -export default async function generateSampleData(numberOfSites = 10, numberOfAuditsPerType = 5) { +export default async function generateSampleData( + config, + numberOfSites = 10, + numberOfAuditsPerType = 5, +) { console.time('Sample data generated in'); - await deleteExistingTables(); + await deleteExistingTables([ + config.tableNameSites, + config.tableNameAudits, + config.tableNameLatestAudits, + ]); await createTablesFromSchema(); const auditTypes = ['lhs', 'cwv']; @@ -147,21 +164,26 @@ export default async function generateSampleData(numberOfSites = 10, numberOfAud id: siteId, baseURL: `https://example${i}.com`, imsOrgId: `${i}-1234@AdobeOrg`, - GSI1PK: 'ALL_SITES', + GSI1PK: config.pkAllSites, createdAt: nowIso, updatedAt: nowIso, }); if (i % 10 !== 0) { // Every tenth site will not have any audits - const latestAudits = generateAuditData(siteId, auditTypes, numberOfAuditsPerType); + const latestAudits = generateAuditData( + config, + siteId, + auditTypes, + numberOfAuditsPerType, + ); auditItems.push(...latestAudits.auditData); latestAuditItems.push(...latestAudits.latestAuditData); } } - await batchWrite('sites', sites); - await batchWrite('audits', auditItems); - await batchWrite('latest_audits', latestAuditItems); + await batchWrite(config.tableNameSites, sites); + await batchWrite(config.tableNameAudits, auditItems); + await batchWrite(config.tableNameLatestAudits, latestAuditItems); console.log(`Generated ${numberOfSites} sites with ${numberOfAuditsPerType} audits per type for each site`); console.timeEnd('Sample data generated in'); diff --git a/packages/spacecat-shared-data-access/test/unit/index.test.js b/packages/spacecat-shared-data-access/test/unit/index.test.js index 893ca5042..68a6abaaf 100644 --- a/packages/spacecat-shared-data-access/test/unit/index.test.js +++ b/packages/spacecat-shared-data-access/test/unit/index.test.js @@ -23,7 +23,10 @@ describe('Data Access Wrapper Tests', () => { beforeEach(() => { mockFn = sinon.stub().resolves('function response'); - mockContext = { log: sinon.spy() }; + mockContext = { + env: {}, + log: sinon.spy(), + }; mockRequest = {}; }); diff --git a/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js b/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js index ec064c789..9de4105b4 100644 --- a/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js +++ b/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js @@ -22,12 +22,22 @@ chai.use(chaiAsPromised); const { expect } = chai; +const TEST_DA_CONFIG = { + tableNameAudits: 'test-audits', + tableNameLatestAudits: 'test-latest-audits', + tableNameSites: 'test-sites', + indexNameAllSites: 'test-index-all-sites', + indexNameAllLatestAuditScores: 'test-index-all-latest-audit-scores', + pkAllSites: 'test-pk-all-sites', + pkAllLatestAudits: 'test-pk-all-latest-audits', +}; + describe('Audit Access Pattern Tests', () => { describe('Audit Functions Export Tests', () => { const mockDynamoClient = {}; const mockLog = {}; - const exportedFunctions = auditFunctions(mockDynamoClient, mockLog); + const exportedFunctions = auditFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); it('exports getAuditsForSite function', () => { expect(exportedFunctions).to.have.property('getAuditsForSite'); @@ -60,7 +70,7 @@ describe('Audit Access Pattern Tests', () => { error: sinon.stub(), }; - exportedFunctions = auditFunctions(mockDynamoClient, mockLog); + exportedFunctions = auditFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); }); it('calls getAuditsForSite and return an array', async () => { @@ -92,7 +102,7 @@ describe('Audit Access Pattern Tests', () => { query: sinon.stub().returns(Promise.resolve([])), }; mockLog = { log: sinon.stub() }; - exportedFunctions = auditFunctions(mockDynamoClient, mockLog); + exportedFunctions = auditFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); }); it('successfully retrieves an audit for a site', async () => { @@ -153,7 +163,7 @@ describe('Audit Access Pattern Tests', () => { log: sinon.stub(), error: sinon.stub(), }; - exportedFunctions = auditFunctions(mockDynamoClient, mockLog); + exportedFunctions = auditFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); }); it('successfully adds a new audit', async () => { diff --git a/packages/spacecat-shared-data-access/test/unit/service/sites/index.test.js b/packages/spacecat-shared-data-access/test/unit/service/sites/index.test.js index 6082a81a5..457ff467f 100644 --- a/packages/spacecat-shared-data-access/test/unit/service/sites/index.test.js +++ b/packages/spacecat-shared-data-access/test/unit/service/sites/index.test.js @@ -23,12 +23,22 @@ chai.use(chaiAsPromised); const { expect } = chai; +const TEST_DA_CONFIG = { + tableNameAudits: 'test-audits', + tableNameLatestAudits: 'test-latest-audits', + tableNameSites: 'test-sites', + indexNameAllSites: 'test-index-all-sites', + indexNameAllLatestAuditScores: 'test-index-all-latest-audit-scores', + pkAllSites: 'test-pk-all-sites', + pkAllLatestAudits: 'test-pk-all-latest-audits', +}; + describe('Site Access Pattern Tests', () => { describe('Site Functions Export Tests', () => { const mockDynamoClient = {}; const mockLog = {}; - const exportedFunctions = siteFunctions(mockDynamoClient, mockLog); + const exportedFunctions = siteFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); it('exports getSites function', () => { expect(exportedFunctions).to.have.property('getSites'); @@ -78,7 +88,7 @@ describe('Site Access Pattern Tests', () => { }; mockLog = { log: sinon.stub() }; - exportedFunctions = siteFunctions(mockDynamoClient, mockLog); + exportedFunctions = siteFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); }); it('calls getSites and returns an array', async () => { @@ -264,7 +274,7 @@ describe('Site Access Pattern Tests', () => { putItem: sinon.stub().returns(Promise.resolve()), }; mockLog = { log: sinon.stub() }; - exportedFunctions = siteFunctions(mockDynamoClient, mockLog); + exportedFunctions = siteFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); }); it('adds a new site successfully', async () => { @@ -296,7 +306,7 @@ describe('Site Access Pattern Tests', () => { putItem: sinon.stub().returns(Promise.resolve()), }; mockLog = { log: sinon.stub() }; - exportedFunctions = siteFunctions(mockDynamoClient, mockLog); + exportedFunctions = siteFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); }); it('updates an existing site successfully', async () => { @@ -333,7 +343,7 @@ describe('Site Access Pattern Tests', () => { log: sinon.stub(), error: sinon.stub(), }; - exportedFunctions = siteFunctions(mockDynamoClient, mockLog); + exportedFunctions = siteFunctions(mockDynamoClient, TEST_DA_CONFIG, mockLog); }); it('removes the site and its related audits', async () => { From 0805c64848c00ed7d4227ebf1aeeff4f0356f8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= Date: Sat, 2 Dec 2023 04:36:52 +0100 Subject: [PATCH 2/4] fix: export missing audit functions --- packages/spacecat-shared-data-access/src/index.d.ts | 6 ++++++ .../test/unit/service/audits/index.test.js | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/spacecat-shared-data-access/src/index.d.ts b/packages/spacecat-shared-data-access/src/index.d.ts index 31026f86b..680140c49 100644 --- a/packages/spacecat-shared-data-access/src/index.d.ts +++ b/packages/spacecat-shared-data-access/src/index.d.ts @@ -49,6 +49,12 @@ export interface DataAccess { getLatestAuditsForSite: ( siteId: string, ) => Promise; + addAudit: ( + auditData: object, + ) => Promise; + removeAuditsForSite: ( + siteId: string, + ) => Promise; getSites: () => Promise; getSitesToAudit: () => Promise; getSitesWithLatestAudit: ( diff --git a/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js b/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js index 9de4105b4..f60a01ab2 100644 --- a/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js +++ b/packages/spacecat-shared-data-access/test/unit/service/audits/index.test.js @@ -53,6 +53,16 @@ describe('Audit Access Pattern Tests', () => { expect(exportedFunctions).to.have.property('getLatestAuditForSite'); expect(exportedFunctions.getLatestAuditForSite).to.be.a('function'); }); + + it('exports removeAuditsForSite function', () => { + expect(exportedFunctions).to.have.property('removeAuditsForSite'); + expect(exportedFunctions.removeAuditsForSite).to.be.a('function'); + }); + + it('exports addAudit function', () => { + expect(exportedFunctions).to.have.property('addAudit'); + expect(exportedFunctions.addAudit).to.be.a('function'); + }); }); describe('Audit Functions Tests', () => { From 7480b01657efb9bcee40ef7ab2607c0513d55a16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= Date: Sat, 2 Dec 2023 08:07:02 +0100 Subject: [PATCH 3/4] fix: add missing fields gitHubURL/isLive --- .../spacecat-shared-data-access/docs/schema.json | 16 ++++++++++++++++ .../spacecat-shared-data-access/src/dto/audit.js | 2 ++ .../spacecat-shared-data-access/src/dto/site.js | 4 ++++ .../spacecat-shared-data-access/src/index.d.ts | 6 +++++- .../src/models/audit.js | 5 +++++ .../src/models/site.js | 11 +++++++++++ .../test/it/auditUtils.js | 11 ++--------- .../test/it/db.test.js | 8 ++++++++ .../test/it/generateSampleData.js | 2 ++ .../test/unit/models/site.test.js | 8 ++++++++ 10 files changed, 63 insertions(+), 10 deletions(-) diff --git a/packages/spacecat-shared-data-access/docs/schema.json b/packages/spacecat-shared-data-access/docs/schema.json index cd11554ab..1b79c1bec 100644 --- a/packages/spacecat-shared-data-access/docs/schema.json +++ b/packages/spacecat-shared-data-access/docs/schema.json @@ -22,10 +22,18 @@ "AttributeName": "baseURL", "AttributeType": "S" }, + { + "AttributeName": "gitHubURL", + "AttributeType": "S" + }, { "AttributeName": "imsOrgId", "AttributeType": "S" }, + { + "AttributeName": "isLive", + "AttributeType": "B" + }, { "AttributeName": "GSI1PK", "AttributeType": "S" @@ -134,6 +142,10 @@ { "AttributeName": "fullAuditRef", "AttributeType": "S" + }, + { + "AttributeName": "isLive", + "AttributeType": "B" } ], "DataAccess": { @@ -214,6 +226,10 @@ "AttributeName": "fullAuditRef", "AttributeType": "S" }, + { + "AttributeName": "isLive", + "AttributeType": "B" + }, { "AttributeName": "GSI1PK", "AttributeType": "S" diff --git a/packages/spacecat-shared-data-access/src/dto/audit.js b/packages/spacecat-shared-data-access/src/dto/audit.js index 0903e251c..13c427152 100644 --- a/packages/spacecat-shared-data-access/src/dto/audit.js +++ b/packages/spacecat-shared-data-access/src/dto/audit.js @@ -44,6 +44,7 @@ export const AuditDto = { auditType: audit.getAuditType(), expiresAt: convertDateToEpochSeconds(audit.getExpiresAt()), fullAuditRef: audit.getFullAuditRef(), + isLive: audit.isLive(), SK: `${audit.getAuditType()}#${audit.getAuditedAt()}`, ...latestAuditProps, }; @@ -62,6 +63,7 @@ export const AuditDto = { auditType: dynamoItem.auditType, expiresAt: parseEpochToDate(dynamoItem.expiresAt), fullAuditRef: dynamoItem.fullAuditRef, + isLive: dynamoItem.isLive, }; return createAudit(auditData); diff --git a/packages/spacecat-shared-data-access/src/dto/site.js b/packages/spacecat-shared-data-access/src/dto/site.js index c2203f5dc..1f3da20e4 100644 --- a/packages/spacecat-shared-data-access/src/dto/site.js +++ b/packages/spacecat-shared-data-access/src/dto/site.js @@ -24,7 +24,9 @@ export const SiteDto = { toDynamoItem: (site) => ({ id: site.getId(), baseURL: site.getBaseURL(), + gitHubURL: site.getGitHubURL(), imsOrgId: site.getImsOrgId(), + isLive: site.isLive(), createdAt: site.getCreatedAt(), updatedAt: site.getUpdatedAt(), GSI1PK: 'ALL_SITES', @@ -39,7 +41,9 @@ export const SiteDto = { const siteData = { id: dynamoItem.id, baseURL: dynamoItem.baseURL, + gitHubURL: dynamoItem.gitHubURL, imsOrgId: dynamoItem.imsOrgId, + isLive: dynamoItem.isLive, createdAt: dynamoItem.createdAt, updatedAt: dynamoItem.updatedAt, }; diff --git a/packages/spacecat-shared-data-access/src/index.d.ts b/packages/spacecat-shared-data-access/src/index.d.ts index 680140c49..e2ced738b 100644 --- a/packages/spacecat-shared-data-access/src/index.d.ts +++ b/packages/spacecat-shared-data-access/src/index.d.ts @@ -19,18 +19,22 @@ export interface Audit { getAuditType: () => object; getExpiresAt: () => Date; getFullAuditRef: () => string; + isLive: () => boolean; getScores: () => object; } export interface Site { getId: () => string; getBaseURL: () => string; + getGitHubURL: () => string; getImsOrgId: () => string; getCreatedAt: () => string; getUpdatedAt: () => string; getAudits: () => Audit[]; - updateImsOrgId: (imsOrgId: string) => Site; + isLive: () => boolean; setAudits: (audits: Audit[]) => Site; + toggleLive: () => Site; + updateImsOrgId: (imsOrgId: string) => Site; } export interface DataAccess { diff --git a/packages/spacecat-shared-data-access/src/models/audit.js b/packages/spacecat-shared-data-access/src/models/audit.js index 6b9d77f34..7c163bf67 100644 --- a/packages/spacecat-shared-data-access/src/models/audit.js +++ b/packages/spacecat-shared-data-access/src/models/audit.js @@ -58,6 +58,7 @@ const Audit = (data = {}) => { self.getAuditType = () => self.state.auditType.toLowerCase(); self.getExpiresAt = () => self.state.expiresAt; self.getFullAuditRef = () => self.state.fullAuditRef; + self.isLive = () => self.state.isLive; self.getScores = () => self.getAuditResult(); return Object.freeze(self); @@ -99,5 +100,9 @@ export const createAudit = (data) => { newState.expiresAt.setDate(newState.expiresAt.getDate() + EXPIRES_IN_DAYS); } + if (!Object.prototype.hasOwnProperty.call(newState, 'isLive')) { + newState.isLive = false; + } + return Audit(newState); }; diff --git a/packages/spacecat-shared-data-access/src/models/site.js b/packages/spacecat-shared-data-access/src/models/site.js index 94fe8cc35..1db378270 100644 --- a/packages/spacecat-shared-data-access/src/models/site.js +++ b/packages/spacecat-shared-data-access/src/models/site.js @@ -24,7 +24,9 @@ const Site = (data = {}) => { self.getAudits = () => self.state.audits; self.getBaseURL = () => self.state.baseURL; + self.getGitHubURL = () => self.state.gitHubURL; self.getImsOrgId = () => self.state.imsOrgId; + self.isLive = () => self.state.isLive; // TODO: updating the baseURL is not supported yet, it will require a transact write // on dynamodb (put then delete) since baseURL is part of the primary key, something like: @@ -79,6 +81,11 @@ const Site = (data = {}) => { return self; }; + self.toggleLive = () => { + self.state.isLive = !self.state.isLive; + return self; + }; + return Object.freeze(self); }; @@ -95,6 +102,10 @@ export const createSite = (data) => { throw new Error('Base URL must be a valid URL'); } + if (!Object.prototype.hasOwnProperty.call(newState, 'isLive')) { + newState.isLive = false; + } + if (!Array.isArray(newState.audits)) { newState.audits = []; } diff --git a/packages/spacecat-shared-data-access/test/it/auditUtils.js b/packages/spacecat-shared-data-access/test/it/auditUtils.js index 9d1170036..ff8a75859 100644 --- a/packages/spacecat-shared-data-access/test/it/auditUtils.js +++ b/packages/spacecat-shared-data-access/test/it/auditUtils.js @@ -12,7 +12,7 @@ import { v4 as uuidv4 } from 'uuid'; -import { randomDate } from './util.js'; +import { getRandomDecimal, getRandomInt, randomDate } from './util.js'; function generateRandomAudit(siteId, auditType) { let auditResult = {}; @@ -21,14 +21,6 @@ function generateRandomAudit(siteId, auditType) { expiresAt.setDate(expiresAt.getDate() + 30); const fullAuditRef = `s3://audit-results/${uuidv4()}.json`; - function getRandomDecimal(precision) { - return parseFloat(Math.random().toFixed(precision)); - } - - function getRandomInt(max) { - return Math.floor(Math.random() * max); - } - if (auditType === 'lhs') { auditResult = { performance: getRandomDecimal(2), @@ -50,6 +42,7 @@ function generateRandomAudit(siteId, auditType) { auditType, auditedAt, auditResult, + isLive: true, expiresAt: Math.floor(expiresAt.getTime() / 1000), // AWS expects unix epoch in seconds fullAuditRef, }; diff --git a/packages/spacecat-shared-data-access/test/it/db.test.js b/packages/spacecat-shared-data-access/test/it/db.test.js index 2e838ecfa..790085e5b 100644 --- a/packages/spacecat-shared-data-access/test/it/db.test.js +++ b/packages/spacecat-shared-data-access/test/it/db.test.js @@ -30,10 +30,12 @@ function checkSite(site) { expect(site).to.be.an('object'); expect(site.getId()).to.be.a('string'); expect(site.getBaseURL()).to.be.a('string'); + expect(site.getGitHubURL()).to.be.a('string'); expect(site.getImsOrgId()).to.be.a('string'); expect(isIsoDate(site.getCreatedAt())).to.be.true; expect(isIsoDate(site.getUpdatedAt())).to.be.true; expect(site.getAudits()).to.be.an('array'); + expect(site.isLive()).to.be.a('boolean'); } function checkAudit(audit) { @@ -46,6 +48,7 @@ function checkAudit(audit) { expect(audit.getAuditResult()).to.be.an('object'); expect(audit.getScores()).to.be.an('object'); expect(audit.getFullAuditRef()).to.be.a('string'); + expect(audit.isLive()).to.be.a('boolean'); } const TEST_DA_CONFIG = { @@ -137,6 +140,7 @@ describe('DynamoDB Integration Test', async () => { it('adds a new site', async () => { const newSiteData = { baseURL: 'https://newexample.com', + gitHubURL: 'https://github.com/some-org/test-repo', imsOrgId: 'newOrg123', audits: [], }; @@ -151,6 +155,7 @@ describe('DynamoDB Integration Test', async () => { expect(newSite.getId()).to.to.be.a('string'); expect(newSite.getBaseURL()).to.equal(newSiteData.baseURL); + expect(newSite.getGitHubURL()).to.equal(newSiteData.gitHubURL); expect(newSite.getImsOrgId()).to.equal(newSiteData.imsOrgId); expect(newSite.getAudits()).to.be.an('array').that.is.empty; }); @@ -293,6 +298,7 @@ describe('DynamoDB Integration Test', async () => { siteId: 'https://example1.com', auditType: AUDIT_TYPE_LHS, auditedAt: new Date().toISOString(), + isLive: true, fullAuditRef: 's3://ref', auditResult: { performance: 0, @@ -308,6 +314,7 @@ describe('DynamoDB Integration Test', async () => { expect(newAudit.getSiteId()).to.equal(auditData.siteId); expect(newAudit.getAuditType()).to.equal(auditData.auditType); expect(newAudit.getAuditedAt()).to.equal(auditData.auditedAt); + expect(newAudit.isLive()).to.be.a('boolean').that.is.true; // Retrieve the latest audit for the site from the latest_audits table const latestAudit = await dataAccess.getLatestAuditForSite( @@ -327,6 +334,7 @@ describe('DynamoDB Integration Test', async () => { auditType: AUDIT_TYPE_LHS, auditedAt: new Date().toISOString(), fullAuditRef: 's3://ref', + isLive: true, auditResult: { performance: 0, seo: 0, diff --git a/packages/spacecat-shared-data-access/test/it/generateSampleData.js b/packages/spacecat-shared-data-access/test/it/generateSampleData.js index d59bf8888..1a933224e 100644 --- a/packages/spacecat-shared-data-access/test/it/generateSampleData.js +++ b/packages/spacecat-shared-data-access/test/it/generateSampleData.js @@ -163,7 +163,9 @@ export default async function generateSampleData( sites.push({ id: siteId, baseURL: `https://example${i}.com`, + gitHubURL: `https://github.com/org-${i}/test-repo`, imsOrgId: `${i}-1234@AdobeOrg`, + isLive: true, GSI1PK: config.pkAllSites, createdAt: nowIso, updatedAt: nowIso, diff --git a/packages/spacecat-shared-data-access/test/unit/models/site.test.js b/packages/spacecat-shared-data-access/test/unit/models/site.test.js index 72adcd26a..c9f7636eb 100644 --- a/packages/spacecat-shared-data-access/test/unit/models/site.test.js +++ b/packages/spacecat-shared-data-access/test/unit/models/site.test.js @@ -91,5 +91,13 @@ describe('Site Model Tests', () => { expect(site.getUpdatedAt()).to.not.equal(initialUpdatedAt); }); + + it('toggles live status', async () => { + expect(site.isLive()).to.be.false; + + site.toggleLive(); + + expect(site.isLive()).to.be.true; + }); }); }); From 1fcf67044ef2f1fe780ed1d8e434b4a7aa68aa0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominique=20J=C3=A4ggi?= Date: Sat, 2 Dec 2023 09:02:39 +0100 Subject: [PATCH 4/4] chore(deps): update spacecat-shared-dynamo --- package-lock.json | 559 +----------------- .../spacecat-shared-data-access/package.json | 2 +- 2 files changed, 14 insertions(+), 547 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4f5f98b31..860cfedcf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -438,18 +438,6 @@ "node": ">=14.0.0" } }, - "node_modules/@aws-sdk/core": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.451.0.tgz", - "integrity": "sha512-SamWW2zHEf1ZKe3j1w0Piauryl8BQIlej0TBS18A4ACzhjhWXhCs13bO1S88LvPR5mBFXok3XOT6zPOnKDFktw==", - "dependencies": { - "@smithy/smithy-client": "^2.1.15", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, "node_modules/@aws-sdk/credential-provider-env": { "version": "3.465.0", "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.465.0.tgz", @@ -551,18 +539,6 @@ "node": ">=14.0.0" } }, - "node_modules/@aws-sdk/endpoint-cache": { - "version": "3.310.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/endpoint-cache/-/endpoint-cache-3.310.0.tgz", - "integrity": "sha512-y3wipforet41EDTI0vnzxILqwAGll1KfI5qcdX9pXF/WF1f+3frcOtPiWtQEZQpy4czRogKm3BHo70QBYAZxlQ==", - "dependencies": { - "mnemonist": "0.38.3", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, "node_modules/@aws-sdk/lib-dynamodb": { "version": "3.465.0", "resolved": "https://registry.npmjs.org/@aws-sdk/lib-dynamodb/-/lib-dynamodb-3.465.0.tgz", @@ -695,21 +671,6 @@ "node": ">=14.0.0" } }, - "node_modules/@aws-sdk/region-config-resolver": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/region-config-resolver/-/region-config-resolver-3.451.0.tgz", - "integrity": "sha512-3iMf4OwzrFb4tAAmoROXaiORUk2FvSejnHIw/XHvf/jjR4EqGGF95NZP/n/MeFZMizJWVssrwS412GmoEyoqhg==", - "dependencies": { - "@smithy/node-config-provider": "^2.1.5", - "@smithy/types": "^2.5.0", - "@smithy/util-config-provider": "^2.0.0", - "@smithy/util-middleware": "^2.0.6", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, "node_modules/@aws-sdk/token-providers": { "version": "3.465.0", "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.465.0.tgz", @@ -12391,14 +12352,14 @@ }, "packages/spacecat-shared-data-access": { "name": "@adobe/spacecat-shared-data-access", - "version": "1.0.1", + "version": "1.0.2", "license": "Apache-2.0", "dependencies": { - "@adobe/spacecat-shared-dynamo": "1.1.4", + "@adobe/spacecat-shared-dynamo": "1.2.3", "@adobe/spacecat-shared-utils": "1.2.0", "@aws-sdk/client-dynamodb": "3.465.0", "@aws-sdk/lib-dynamodb": "3.465.0", - "uuid": "^9.0.1" + "uuid": "9.0.1" }, "devDependencies": { "chai": "4.3.10", @@ -12408,517 +12369,23 @@ } }, "packages/spacecat-shared-data-access/node_modules/@adobe/spacecat-shared-dynamo": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-dynamo/-/spacecat-shared-dynamo-1.1.4.tgz", - "integrity": "sha512-geJZoXHOH3uZ5x3pFn05C1Vu5yrS2vsequYdxRLk03BjyynhLBuW0tT3vvTc9sTfFf1ZuEGhiT9hdWOQvJFh2g==", + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-dynamo/-/spacecat-shared-dynamo-1.2.3.tgz", + "integrity": "sha512-ord82ihIg58lDjXJwfLTERSRidgpVHwLxCG5g5LX1HWUu51o/Hvch0L2uTEHR0QKBE5e3xuG0SQe0nZtscw8cA==", "dependencies": { - "@adobe/spacecat-shared-utils": "1.0.1", - "@aws-sdk/client-dynamodb": "3.454.0", - "@aws-sdk/lib-dynamodb": "3.454.0" + "@adobe/spacecat-shared-utils": "1.1.0", + "@aws-sdk/client-dynamodb": "3.465.0", + "@aws-sdk/lib-dynamodb": "3.465.0" } }, "packages/spacecat-shared-data-access/node_modules/@adobe/spacecat-shared-dynamo/node_modules/@adobe/spacecat-shared-utils": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-utils/-/spacecat-shared-utils-1.0.1.tgz", - "integrity": "sha512-6HiCywan5y9jpbFYkQX87Vg0q5dXoJf2m6MiDvNBEJdREdUxFwE+oYA6Fr86qqd32ECnCeYCFO13HcNRn1RxkQ==" - }, - "packages/spacecat-shared-data-access/node_modules/@adobe/spacecat-shared-dynamo/node_modules/@aws-sdk/client-dynamodb": { - "version": "3.454.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/client-dynamodb/-/client-dynamodb-3.454.0.tgz", - "integrity": "sha512-GztsAk/OwhksDYclc0JoqhoXGqowzfyqJ6405L6m1x3ydS0B0csul/1xnCmmyVEIr9aLJZK7dk0DgdfKsyj3KA==", - "dependencies": { - "@aws-crypto/sha256-browser": "3.0.0", - "@aws-crypto/sha256-js": "3.0.0", - "@aws-sdk/client-sts": "3.454.0", - "@aws-sdk/core": "3.451.0", - "@aws-sdk/credential-provider-node": "3.451.0", - "@aws-sdk/middleware-endpoint-discovery": "3.451.0", - "@aws-sdk/middleware-host-header": "3.451.0", - "@aws-sdk/middleware-logger": "3.451.0", - "@aws-sdk/middleware-recursion-detection": "3.451.0", - "@aws-sdk/middleware-signing": "3.451.0", - "@aws-sdk/middleware-user-agent": "3.451.0", - "@aws-sdk/region-config-resolver": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@aws-sdk/util-endpoints": "3.451.0", - "@aws-sdk/util-user-agent-browser": "3.451.0", - "@aws-sdk/util-user-agent-node": "3.451.0", - "@smithy/config-resolver": "^2.0.18", - "@smithy/fetch-http-handler": "^2.2.6", - "@smithy/hash-node": "^2.0.15", - "@smithy/invalid-dependency": "^2.0.13", - "@smithy/middleware-content-length": "^2.0.15", - "@smithy/middleware-endpoint": "^2.2.0", - "@smithy/middleware-retry": "^2.0.20", - "@smithy/middleware-serde": "^2.0.13", - "@smithy/middleware-stack": "^2.0.7", - "@smithy/node-config-provider": "^2.1.5", - "@smithy/node-http-handler": "^2.1.9", - "@smithy/protocol-http": "^3.0.9", - "@smithy/smithy-client": "^2.1.15", - "@smithy/types": "^2.5.0", - "@smithy/url-parser": "^2.0.13", - "@smithy/util-base64": "^2.0.1", - "@smithy/util-body-length-browser": "^2.0.0", - "@smithy/util-body-length-node": "^2.1.0", - "@smithy/util-defaults-mode-browser": "^2.0.19", - "@smithy/util-defaults-mode-node": "^2.0.25", - "@smithy/util-endpoints": "^1.0.4", - "@smithy/util-retry": "^2.0.6", - "@smithy/util-utf8": "^2.0.2", - "@smithy/util-waiter": "^2.0.13", - "tslib": "^2.5.0", - "uuid": "^8.3.2" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@adobe/spacecat-shared-dynamo/node_modules/@aws-sdk/lib-dynamodb": { - "version": "3.454.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/lib-dynamodb/-/lib-dynamodb-3.454.0.tgz", - "integrity": "sha512-qeu0ZhTBXrAGzP9fpZDN88u7tLWtoBdGebC0WvE9oMaQnGICu1mgLwb6u+u8TAS19cvPySHln9VmSVs52m8L1g==", - "dependencies": { - "@aws-sdk/util-dynamodb": "3.454.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "@aws-sdk/client-dynamodb": "^3.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@adobe/spacecat-shared-dynamo/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/client-sso": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.451.0.tgz", - "integrity": "sha512-KkYSke3Pdv3MfVH/5fT528+MKjMyPKlcLcd4zQb0x6/7Bl7EHrPh1JZYjzPLHelb+UY5X0qN8+cb8iSu1eiwIQ==", - "dependencies": { - "@aws-crypto/sha256-browser": "3.0.0", - "@aws-crypto/sha256-js": "3.0.0", - "@aws-sdk/core": "3.451.0", - "@aws-sdk/middleware-host-header": "3.451.0", - "@aws-sdk/middleware-logger": "3.451.0", - "@aws-sdk/middleware-recursion-detection": "3.451.0", - "@aws-sdk/middleware-user-agent": "3.451.0", - "@aws-sdk/region-config-resolver": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@aws-sdk/util-endpoints": "3.451.0", - "@aws-sdk/util-user-agent-browser": "3.451.0", - "@aws-sdk/util-user-agent-node": "3.451.0", - "@smithy/config-resolver": "^2.0.18", - "@smithy/fetch-http-handler": "^2.2.6", - "@smithy/hash-node": "^2.0.15", - "@smithy/invalid-dependency": "^2.0.13", - "@smithy/middleware-content-length": "^2.0.15", - "@smithy/middleware-endpoint": "^2.2.0", - "@smithy/middleware-retry": "^2.0.20", - "@smithy/middleware-serde": "^2.0.13", - "@smithy/middleware-stack": "^2.0.7", - "@smithy/node-config-provider": "^2.1.5", - "@smithy/node-http-handler": "^2.1.9", - "@smithy/protocol-http": "^3.0.9", - "@smithy/smithy-client": "^2.1.15", - "@smithy/types": "^2.5.0", - "@smithy/url-parser": "^2.0.13", - "@smithy/util-base64": "^2.0.1", - "@smithy/util-body-length-browser": "^2.0.0", - "@smithy/util-body-length-node": "^2.1.0", - "@smithy/util-defaults-mode-browser": "^2.0.19", - "@smithy/util-defaults-mode-node": "^2.0.25", - "@smithy/util-endpoints": "^1.0.4", - "@smithy/util-retry": "^2.0.6", - "@smithy/util-utf8": "^2.0.2", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/client-sts": { - "version": "3.454.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/client-sts/-/client-sts-3.454.0.tgz", - "integrity": "sha512-0fDvr8WeB6IYO8BUCzcivWmahgGl/zDbaYfakzGnt4mrl5ztYaXE875WI6b7+oFcKMRvN+KLvwu5TtyFuNY+GQ==", - "dependencies": { - "@aws-crypto/sha256-browser": "3.0.0", - "@aws-crypto/sha256-js": "3.0.0", - "@aws-sdk/core": "3.451.0", - "@aws-sdk/credential-provider-node": "3.451.0", - "@aws-sdk/middleware-host-header": "3.451.0", - "@aws-sdk/middleware-logger": "3.451.0", - "@aws-sdk/middleware-recursion-detection": "3.451.0", - "@aws-sdk/middleware-sdk-sts": "3.451.0", - "@aws-sdk/middleware-signing": "3.451.0", - "@aws-sdk/middleware-user-agent": "3.451.0", - "@aws-sdk/region-config-resolver": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@aws-sdk/util-endpoints": "3.451.0", - "@aws-sdk/util-user-agent-browser": "3.451.0", - "@aws-sdk/util-user-agent-node": "3.451.0", - "@smithy/config-resolver": "^2.0.18", - "@smithy/fetch-http-handler": "^2.2.6", - "@smithy/hash-node": "^2.0.15", - "@smithy/invalid-dependency": "^2.0.13", - "@smithy/middleware-content-length": "^2.0.15", - "@smithy/middleware-endpoint": "^2.2.0", - "@smithy/middleware-retry": "^2.0.20", - "@smithy/middleware-serde": "^2.0.13", - "@smithy/middleware-stack": "^2.0.7", - "@smithy/node-config-provider": "^2.1.5", - "@smithy/node-http-handler": "^2.1.9", - "@smithy/protocol-http": "^3.0.9", - "@smithy/smithy-client": "^2.1.15", - "@smithy/types": "^2.5.0", - "@smithy/url-parser": "^2.0.13", - "@smithy/util-base64": "^2.0.1", - "@smithy/util-body-length-browser": "^2.0.0", - "@smithy/util-body-length-node": "^2.1.0", - "@smithy/util-defaults-mode-browser": "^2.0.19", - "@smithy/util-defaults-mode-node": "^2.0.25", - "@smithy/util-endpoints": "^1.0.4", - "@smithy/util-retry": "^2.0.6", - "@smithy/util-utf8": "^2.0.2", - "fast-xml-parser": "4.2.5", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/credential-provider-env": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.451.0.tgz", - "integrity": "sha512-9dAav7DcRgaF7xCJEQR5ER9ErXxnu/tdnVJ+UPmb1NPeIZdESv1A3lxFDEq1Fs8c4/lzAj9BpshGyJVIZwZDKg==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/property-provider": "^2.0.0", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/credential-provider-ini": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.451.0.tgz", - "integrity": "sha512-TySt64Ci5/ZbqFw1F9Z0FIGvYx5JSC9e6gqDnizIYd8eMnn8wFRUscRrD7pIHKfrhvVKN5h0GdYovmMO/FMCBw==", - "dependencies": { - "@aws-sdk/credential-provider-env": "3.451.0", - "@aws-sdk/credential-provider-process": "3.451.0", - "@aws-sdk/credential-provider-sso": "3.451.0", - "@aws-sdk/credential-provider-web-identity": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@smithy/credential-provider-imds": "^2.0.0", - "@smithy/property-provider": "^2.0.0", - "@smithy/shared-ini-file-loader": "^2.0.6", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/credential-provider-node": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.451.0.tgz", - "integrity": "sha512-AEwM1WPyxUdKrKyUsKyFqqRFGU70e4qlDyrtBxJnSU9NRLZI8tfEZ67bN7fHSxBUBODgDXpMSlSvJiBLh5/3pw==", - "dependencies": { - "@aws-sdk/credential-provider-env": "3.451.0", - "@aws-sdk/credential-provider-ini": "3.451.0", - "@aws-sdk/credential-provider-process": "3.451.0", - "@aws-sdk/credential-provider-sso": "3.451.0", - "@aws-sdk/credential-provider-web-identity": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@smithy/credential-provider-imds": "^2.0.0", - "@smithy/property-provider": "^2.0.0", - "@smithy/shared-ini-file-loader": "^2.0.6", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/credential-provider-process": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.451.0.tgz", - "integrity": "sha512-HQywSdKeD5PErcLLnZfSyCJO+6T+ZyzF+Lm/QgscSC+CbSUSIPi//s15qhBRVely/3KBV6AywxwNH+5eYgt4lQ==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/property-provider": "^2.0.0", - "@smithy/shared-ini-file-loader": "^2.0.6", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/credential-provider-sso": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.451.0.tgz", - "integrity": "sha512-Usm/N51+unOt8ID4HnQzxIjUJDrkAQ1vyTOC0gSEEJ7h64NSSPGD5yhN7il5WcErtRd3EEtT1a8/GTC5TdBctg==", - "dependencies": { - "@aws-sdk/client-sso": "3.451.0", - "@aws-sdk/token-providers": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@smithy/property-provider": "^2.0.0", - "@smithy/shared-ini-file-loader": "^2.0.6", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/credential-provider-web-identity": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.451.0.tgz", - "integrity": "sha512-Xtg3Qw65EfDjWNG7o2xD6sEmumPfsy3WDGjk2phEzVg8s7hcZGxf5wYwe6UY7RJvlEKrU0rFA+AMn6Hfj5oOzg==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/property-provider": "^2.0.0", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/middleware-endpoint-discovery": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-endpoint-discovery/-/middleware-endpoint-discovery-3.451.0.tgz", - "integrity": "sha512-OvRb9M12JZaxjpdwPqTndAexjp/s4Ub/GumxED2uy7KDzo95f2A4CA3yRB03ExBERWtKtCShpJG87oTERkDiaQ==", - "dependencies": { - "@aws-sdk/endpoint-cache": "3.310.0", - "@aws-sdk/types": "3.451.0", - "@smithy/node-config-provider": "^2.1.5", - "@smithy/protocol-http": "^3.0.9", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/middleware-host-header": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.451.0.tgz", - "integrity": "sha512-j8a5jAfhWmsK99i2k8oR8zzQgXrsJtgrLxc3js6U+525mcZytoiDndkWTmD5fjJ1byU1U2E5TaPq+QJeDip05Q==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/protocol-http": "^3.0.9", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/middleware-logger": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.451.0.tgz", - "integrity": "sha512-0kHrYEyVeB2QBfP6TfbI240aRtatLZtcErJbhpiNUb+CQPgEL3crIjgVE8yYiJumZ7f0jyjo8HLPkwD1/2APaw==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/middleware-recursion-detection": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.451.0.tgz", - "integrity": "sha512-J6jL6gJ7orjHGM70KDRcCP7so/J2SnkN4vZ9YRLTeeZY6zvBuHDjX8GCIgSqPn/nXFXckZO8XSnA7u6+3TAT0w==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/protocol-http": "^3.0.9", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/middleware-sdk-sts": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-sdk-sts/-/middleware-sdk-sts-3.451.0.tgz", - "integrity": "sha512-UJ6UfVUEgp0KIztxpAeelPXI5MLj9wUtUCqYeIMP7C1ZhoEMNm3G39VLkGN43dNhBf1LqjsV9jkKMZbVfYXuwg==", - "dependencies": { - "@aws-sdk/middleware-signing": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/middleware-signing": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-signing/-/middleware-signing-3.451.0.tgz", - "integrity": "sha512-s5ZlcIoLNg1Huj4Qp06iKniE8nJt/Pj1B/fjhWc6cCPCM7XJYUCejCnRh6C5ZJoBEYodjuwZBejPc1Wh3j+znA==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/property-provider": "^2.0.0", - "@smithy/protocol-http": "^3.0.9", - "@smithy/signature-v4": "^2.0.0", - "@smithy/types": "^2.5.0", - "@smithy/util-middleware": "^2.0.6", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/middleware-user-agent": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.451.0.tgz", - "integrity": "sha512-8NM/0JiKLNvT9wtAQVl1DFW0cEO7OvZyLSUBLNLTHqyvOZxKaZ8YFk7d8PL6l76LeUKRxq4NMxfZQlUIRe0eSA==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@aws-sdk/util-endpoints": "3.451.0", - "@smithy/protocol-http": "^3.0.9", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/token-providers": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.451.0.tgz", - "integrity": "sha512-ij1L5iUbn6CwxVOT1PG4NFjsrsKN9c4N1YEM0lkl6DwmaNOscjLKGSNyj9M118vSWsOs1ZDbTwtj++h0O/BWrQ==", - "dependencies": { - "@aws-crypto/sha256-browser": "3.0.0", - "@aws-crypto/sha256-js": "3.0.0", - "@aws-sdk/middleware-host-header": "3.451.0", - "@aws-sdk/middleware-logger": "3.451.0", - "@aws-sdk/middleware-recursion-detection": "3.451.0", - "@aws-sdk/middleware-user-agent": "3.451.0", - "@aws-sdk/region-config-resolver": "3.451.0", - "@aws-sdk/types": "3.451.0", - "@aws-sdk/util-endpoints": "3.451.0", - "@aws-sdk/util-user-agent-browser": "3.451.0", - "@aws-sdk/util-user-agent-node": "3.451.0", - "@smithy/config-resolver": "^2.0.18", - "@smithy/fetch-http-handler": "^2.2.6", - "@smithy/hash-node": "^2.0.15", - "@smithy/invalid-dependency": "^2.0.13", - "@smithy/middleware-content-length": "^2.0.15", - "@smithy/middleware-endpoint": "^2.2.0", - "@smithy/middleware-retry": "^2.0.20", - "@smithy/middleware-serde": "^2.0.13", - "@smithy/middleware-stack": "^2.0.7", - "@smithy/node-config-provider": "^2.1.5", - "@smithy/node-http-handler": "^2.1.9", - "@smithy/property-provider": "^2.0.0", - "@smithy/protocol-http": "^3.0.9", - "@smithy/shared-ini-file-loader": "^2.0.6", - "@smithy/smithy-client": "^2.1.15", - "@smithy/types": "^2.5.0", - "@smithy/url-parser": "^2.0.13", - "@smithy/util-base64": "^2.0.1", - "@smithy/util-body-length-browser": "^2.0.0", - "@smithy/util-body-length-node": "^2.1.0", - "@smithy/util-defaults-mode-browser": "^2.0.19", - "@smithy/util-defaults-mode-node": "^2.0.25", - "@smithy/util-endpoints": "^1.0.4", - "@smithy/util-retry": "^2.0.6", - "@smithy/util-utf8": "^2.0.2", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/types": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.451.0.tgz", - "integrity": "sha512-rhK+qeYwCIs+laJfWCcrYEjay2FR/9VABZJ2NRM89jV/fKqGVQR52E5DQqrI+oEIL5JHMhhnr4N4fyECMS35lw==", - "dependencies": { - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/util-dynamodb": { - "version": "3.454.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-dynamodb/-/util-dynamodb-3.454.0.tgz", - "integrity": "sha512-gcxzlUzFHHLnnDB8Pc3BqRc2WmbVDf3A8Xre1H5zPNtF8bZihYj0xk3KMK9Sfnk/tkDTL2PfQ2qNf7R7RLTNpw==", - "dependencies": { - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "@aws-sdk/client-dynamodb": "^3.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/util-endpoints": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.451.0.tgz", - "integrity": "sha512-giqLGBTnRIcKkDqwU7+GQhKbtJ5Ku35cjGQIfMyOga6pwTBUbaK0xW1Sdd8sBQ1GhApscnChzI9o/R9x0368vw==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/util-endpoints": "^1.0.4", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/util-user-agent-browser": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.451.0.tgz", - "integrity": "sha512-Ws5mG3J0TQifH7OTcMrCTexo7HeSAc3cBgjfhS/ofzPUzVCtsyg0G7I6T7wl7vJJETix2Kst2cpOsxygPgPD9w==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/types": "^2.5.0", - "bowser": "^2.11.0", - "tslib": "^2.5.0" - } - }, - "packages/spacecat-shared-data-access/node_modules/@aws-sdk/util-user-agent-node": { - "version": "3.451.0", - "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.451.0.tgz", - "integrity": "sha512-TBzm6P+ql4mkGFAjPlO1CI+w3yUT+NulaiALjl/jNX/nnUp6HsJsVxJf4nVFQTG5KRV0iqMypcs7I3KIhH+LmA==", - "dependencies": { - "@aws-sdk/types": "3.451.0", - "@smithy/node-config-provider": "^2.1.5", - "@smithy/types": "^2.5.0", - "tslib": "^2.5.0" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "aws-crt": ">=1.0.0" - }, - "peerDependenciesMeta": { - "aws-crt": { - "optional": true - } - } + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@adobe/spacecat-shared-utils/-/spacecat-shared-utils-1.1.0.tgz", + "integrity": "sha512-yq6o47d6IuMApgvlGWdIfUOkqYNwcEm4IzO5WHnrTpWXPK4vvssfAfFtoeki7NQ+A4nFoc7/esqOfX42Q452nA==" }, "packages/spacecat-shared-dynamo": { "name": "@adobe/spacecat-shared-dynamo", - "version": "1.2.1", + "version": "1.2.2", "license": "Apache-2.0", "dependencies": { "@adobe/spacecat-shared-utils": "1.1.0", diff --git a/packages/spacecat-shared-data-access/package.json b/packages/spacecat-shared-data-access/package.json index ff1f32ca0..145b7f2ef 100644 --- a/packages/spacecat-shared-data-access/package.json +++ b/packages/spacecat-shared-data-access/package.json @@ -29,7 +29,7 @@ "access": "public" }, "dependencies": { - "@adobe/spacecat-shared-dynamo": "1.1.4", + "@adobe/spacecat-shared-dynamo": "1.2.3", "@adobe/spacecat-shared-utils": "1.2.0", "@aws-sdk/client-dynamodb": "3.465.0", "@aws-sdk/lib-dynamodb": "3.465.0",