Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: data model for organizations #84

Merged
merged 21 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10,885 changes: 9,200 additions & 1,685 deletions package-lock.json

Large diffs are not rendered by default.

105 changes: 103 additions & 2 deletions packages/spacecat-shared-data-access/docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"AttributeType": "S"
},
{
"AttributeName": "imsOrgId",
"AttributeName": "organizationId",
"AttributeType": "S"
},
{
Expand All @@ -50,6 +50,10 @@
"AttributeName": "auditConfig",
"AttributeType": "M"
},
{
"AttributeName": "config",
"AttributeType": "M"
},
{
"AttributeName": "createdAt",
"AttributeType": "S"
Expand All @@ -76,6 +80,18 @@
"ProjectionType": "ALL"
}
},
{
"IndexName": "spacecat-services-all-sites-organizations",
"KeyAttributes": {
"PartitionKey": {
"AttributeName": "organizationId",
"AttributeType": "S"
}
},
"Projection": {
"ProjectionType": "ALL"
}
},
{
"IndexName": "spacecat-services-all-sites-by-delivery-type",
"KeyAttributes": {
Expand Down Expand Up @@ -105,7 +121,92 @@
"identifiers",
"URL"
],
"imsOrgId": [
"organizationId": [
"identifiers",
"UUID"
]
},
"BillingMode": "PROVISIONED",
"ProvisionedCapacitySettings": {
"ProvisionedThroughput": {
"ReadCapacityUnits": 5,
"WriteCapacityUnits": 5
},
"AutoScalingRead": {
"ScalableTargetRequest": {
"MinCapacity": 1,
"MaxCapacity": 10,
"ServiceRole": "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
},
"ScalingPolicyConfiguration": {
"TargetValue": 70
}
},
"AutoScalingWrite": {
"ScalableTargetRequest": {
"MinCapacity": 1,
"MaxCapacity": 10,
"ServiceRole": "AWSServiceRoleForApplicationAutoScaling_DynamoDBTable"
},
"ScalingPolicyConfiguration": {
"TargetValue": 70
}
}
}
},
{
"TableName": "spacecat-services-organizations",
"KeyAttributes": {
"PartitionKey": {
"AttributeName": "id",
"AttributeType": "S"
}
},
"NonKeyAttributes": [
{
"AttributeName": "name",
"AttributeType": "S"
},
{
"AttributeName": "GSI1PK",
"AttributeType": "S"
},
{
"AttributeName": "auditConfig",
"AttributeType": "M"
},
{
"AttributeName": "config",
"AttributeType": "M"
},
{
"AttributeName": "createdAt",
"AttributeType": "S"
},
{
"AttributeName": "updatedAt",
"AttributeType": "S"
}
],
"GlobalSecondaryIndexes": [
{
"IndexName": "spacecat-services-all-organizations",
"KeyAttributes": {
"PartitionKey": {
"AttributeName": "GSI1PK",
"AttributeType": "S"
}
},
"Projection": {
"ProjectionType": "ALL"
}
}
],
"DataAccess": {
"MySql": {}
},
"SampleDataFormats": {
"id": [
"identifiers",
"UUID"
]
Expand Down
2 changes: 2 additions & 0 deletions packages/spacecat-shared-data-access/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@adobe/spacecat-shared-utils": "1.2.0",
"@aws-sdk/client-dynamodb": "3.490.0",
"@aws-sdk/lib-dynamodb": "3.490.0",
"@types/joi": "17.2.3",
"joi": "17.11.0",
"uuid": "9.0.1"
},
"devDependencies": {
Expand Down
52 changes: 52 additions & 0 deletions packages/spacecat-shared-data-access/src/dto/organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import { Config } from '../models/site/config.js';
import { createOrganization } from '../models/organization.js';

/**
* Data transfer object for Organization.
*/
export const OrganizationDto = {
/**
* Converts an Organization object into a DynamoDB item.
* @param {Readonly<Organization>} organization - Organization object.
* @returns {{createdAt, baseURL, GSI1PK: string, id, imsOrgId, updatedAt}}
*/
toDynamoItem: (organization) => ({
id: organization.getId(),
name: organization.getName(),
imsOrgId: organization.getImsOrgId(),
createdAt: organization.getCreatedAt(),
updatedAt: organization.getUpdatedAt(),
GSI1PK: 'ALL_ORGANIZATIONS',
config: Config.toDynamoItem(organization.getConfig()),
}),

/**
* Converts a DynamoDB item into a Organization object.
* @param {object } dynamoItem - DynamoDB item.
* @returns {Readonly<Organization>} Organization object.
*/
fromDynamoItem: (dynamoItem) => {
const organizationData = {
id: dynamoItem.id,
name: dynamoItem.name,
imsOrgId: dynamoItem.imsOrgId,
createdAt: dynamoItem.createdAt,
updatedAt: dynamoItem.updatedAt,
config: dynamoItem.config,
};

return createOrganization(organizationData);
},
};
9 changes: 6 additions & 3 deletions packages/spacecat-shared-data-access/src/dto/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import { createSite } from '../models/site.js';
import AuditConfig from '../models/site/audit-config.js';
import { Config } from '../models/site/config.js';

/**
* Data transfer object for Site.
Expand All @@ -20,20 +21,21 @@ export const SiteDto = {
/**
* Converts a Site object into a DynamoDB item.
* @param {Readonly<Site>} site - Site object.
* @returns {{createdAt, baseURL, GSI1PK: string, id, imsOrgId, updatedAt}}
* @returns {{createdAt, baseURL, GSI1PK: string, id, organizationId, updatedAt}}
*/
toDynamoItem: (site) => ({
id: site.getId(),
baseURL: site.getBaseURL(),
deliveryType: site.getDeliveryType(),
gitHubURL: site.getGitHubURL() || '',
imsOrgId: site.getImsOrgId() || '',
organizationId: site.getOrganizationId() || '',
isLive: site.isLive(),
isLiveToggledAt: site.getIsLiveToggledAt(),
createdAt: site.getCreatedAt(),
updatedAt: site.getUpdatedAt(),
GSI1PK: 'ALL_SITES',
auditConfig: AuditConfig.toDynamoItem(site.getAuditConfig()),
config: Config.toDynamoItem(site.getConfig()),
}),

/**
Expand All @@ -47,12 +49,13 @@ export const SiteDto = {
baseURL: dynamoItem.baseURL,
deliveryType: dynamoItem.deliveryType,
gitHubURL: dynamoItem.gitHubURL,
imsOrgId: dynamoItem.imsOrgId,
organizationId: dynamoItem.organizationId,
isLive: dynamoItem.isLive,
isLiveToggledAt: dynamoItem.isLiveToggledAt,
createdAt: dynamoItem.createdAt,
updatedAt: dynamoItem.updatedAt,
auditConfig: dynamoItem.auditConfig,
config: dynamoItem.config,
};

return createSite(siteData);
Expand Down
79 changes: 74 additions & 5 deletions packages/spacecat-shared-data-access/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export interface AuditConfigType {
disabled: () => boolean;
}

export interface Config {

}

/**
* AuditConfig defines the structure for the overall audit configuration of a site.
*/
Expand Down Expand Up @@ -150,10 +154,10 @@ export interface Site {
getGitHubURL: () => string;

/**
* Retrieves the IMS Organization ID associated with the site.
* @returns {string} The IMS Org ID.
* Retrieves the Organization ID associated with the site.
* @returns {string} The Org ID.
*/
getImsOrgId: () => string;
getOrganizationId: () => string;

/**
* Retrieves the creation timestamp of the site.
Expand All @@ -173,6 +177,12 @@ export interface Site {
*/
getAuditConfig: () => AuditConfig;

/**
* Retrieves the current configuration for the site.
* @returns {Config} The current configuration.
*/
getConfig: () => Config;

/**
* Retrieves the audits associated with the site.
* @returns {Audit[]} The list of audits.
Expand Down Expand Up @@ -213,10 +223,48 @@ export interface Site {

/**
* Updates the IMS Org ID of the site.
* @param {string} imsOrgId The new IMS Org ID.
* @param {string} organizationId The new Org ID.
* @returns {Site} The updated site instance.
*/
updateImsOrgId: (imsOrgId: string) => Site;
updateOrganizationId: (organizationId: string) => Site;
}

export interface Organization {
/**
* Retrieves the ID of the site.
* @returns {string} The site ID.
*/
getId: () => string;

/**
* Retrieves the base URL of the site.
* @returns {string} The base URL.
*/
getName: () => string;

/**
* Retrieves the IMS Organization ID associated with the site.
* @returns {string} The IMS Org ID.
*/
getImsOrgId: () => string;

/**
* Retrieves the creation timestamp of the site.
* @returns {string} The creation timestamp.
*/
getCreatedAt: () => string;

/**
* Retrieves the last update timestamp of the site.
* @returns {string} The last update timestamp.
*/
getUpdatedAt: () => string;

/**
* Retrieves the current audit configuration for the site.
* @returns {Config} The current audit configuration.
*/
getConfig: () => Config;
}

export interface DataAccess {
Expand Down Expand Up @@ -257,6 +305,9 @@ export interface DataAccess {
sortAuditsAscending?: boolean,
deliveryType?: string,
) => Promise<Site[]>;
getSitesByOrganizationId: (
alinarublea marked this conversation as resolved.
Show resolved Hide resolved
organizationId: string,
) => Promise<Organization[]>
getSiteByBaseURL: (
baseUrl: string,
) => Promise<Site | null>;
Expand Down Expand Up @@ -285,17 +336,35 @@ export interface DataAccess {
removeSite: (
siteId: string,
) => Promise<void>;
getOrganizations:
() => Promise<Organization[]>;
getOrganizationByID: (
organizationID: string,
) => Promise<Organization | null>;
addOrganization: (
organizationData: object,
) => Promise<Organization>;
updateOrganization: (
organization: Organization,
) => Promise<Organization>;
removeRemoveOrganization: (
organizationId: string,
) => Promise<void>;
}

interface DataAccessConfig {
tableNameAudits: string;
tableNameLatestAudits: string;
tableNameOrganizations: string,
tableNameSites: string;
indexNameAllSites: string;
indexNameAllSitesOrganizations: string,
indexNameAllSitesByDeliveryType: string;
indexNameAllLatestAuditScores: string;
indexNameAllOrganizations: string,
pkAllSites: string;
pkAllLatestAudits: string;
pkAllOrganizations: string;
}

export function createDataAccess(
Expand Down
Loading
Loading