1.23.0 • Published 5 days ago

@adobe/spacecat-shared-data-access v1.23.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
5 days ago

SpaceCat Shared Data Access

This Node.js module, spacecat-shared-data-access, is a data access layer for managing sites and their audits, leveraging Amazon DynamoDB.

Installation

npm install @adobe/spacecat-shared-data-access

Entities

Sites

  • id (String): Unique identifier for a site.
  • baseURL (String): Base URL of the site.
  • imsOrgId (String): Organization ID associated with the site.
  • createdAt (String): Timestamp of creation.
  • updatedAt (String): Timestamp of the last update.
  • GSI1PK (String): Partition key for the Global Secondary Index.

SiteCandidates

  • baseURL (String): Base URL of the site candidate.
  • status (String): Status of the site candidate (PENDING, IGNORED, APPROVED, ERROR)
  • createdAt (String): Timestamp of creation.
  • updatedAt (String): Timestamp of the last update.
  • updatedBy (String): Slack id of the last person updated the site candidate.

Audits

  • siteId (String): Identifier of the site being audited.
  • SK (String): Sort key, typically a composite of audit type and timestamp.
  • auditedAt (String): Timestamp of the audit.
  • auditResult (Map): Results of the audit.
  • auditType (String): Type of the audit.
  • expiresAt (Number): Expiry timestamp of the audit.
  • fullAuditRef (String): Reference to the full audit details.

SiteTopPages

  • siteId (String): Identifier of the site.
  • url (String): URL of the top page.
  • traffic (Number): Traffic of the top page.
  • source (String): Source of the data.
  • geo (String): Geo of the top page.
  • importedAt (String): Timestamp of the import.

DynamoDB Data Model

The module is designed to work with the following DynamoDB tables:

  1. Sites Table: Manages site records.
  2. Audits Table: Stores audit information for each site.
  3. Latest Audits Table: Holds only the latest audit for each site for quick access.
  4. Site Candidates Table: Manages site candidates.
  5. Site Top Pages Table: Stores top pages for each site.

Each table is designed with scalability and efficient querying in mind, utilizing both key and non-key attributes effectively.

For a detailed schema, refer to docs/schema.json. This schema is importable to Amazon NoSQL Workbench and used by the integration tests.

Integration Testing

The module includes comprehensive integration tests embedding a local DynamoDB server with in-memory storage for testing:

npm run test:it

These tests create the schema, generate sample data, and test the data access patterns against the local DynamoDB instance.

Data Access API

The module provides the following DAOs:

Site Functions

  • getSites
  • getSitesToAudit
  • getSitesWithLatestAudit
  • getSiteByBaseURL
  • getSiteByBaseURLWithAuditInfo
  • getSiteByBaseURLWithAudits
  • getSiteByBaseURLWithLatestAudit
  • addSite
  • updateSite
  • removeSite

Site Candidate Functions

  • getSiteCandidateByBaseURL
  • upsertSiteCandidate
  • siteCandidateExists
  • updateSiteCandidate

Audit Functions

  • getAuditsForSite
  • getAuditForSite
  • getLatestAudits
  • getLatestAuditForSite
  • addAudit

Site Top Pages Functions

  • getTopPagesForSite
  • addSiteTopPage

Integrating Data Access in AWS Lambda Functions

Our spacecat-shared-data-access module includes a wrapper that can be easily integrated into AWS Lambda functions using @adobe/helix-shared-wrap. This integration allows your Lambda functions to access and manipulate data seamlessly.

Steps for Integration

  1. Import the Data Access Wrapper

    Along with other wrappers and utilities, import the dataAccessWrapper.

    import dataAccessWrapper from '@adobe/spacecat-shared-data-access/wrapper';
  2. Modify Your Lambda Wrapper Script

    Include dataAccessWrapper in the chain of wrappers when defining your Lambda handler.

    export const main = wrap(run)
      .with(sqsEventAdapter)
      .with(dataAccessWrapper) // Add this line
      .with(sqs)
      .with(secrets)
      .with(helixStatus);
  3. Access Data in Your Lambda Function

    Use the dataAccess object from the context to interact with your data layer.

    async function run(message, context) {
      const { dataAccess } = context;
      
      // Example: Retrieve all sites
      const sites = await dataAccess.getSites();
      // ... more logic ...
    }

Example

Here's a complete example of a Lambda function utilizing the data access wrapper:

import wrap from '@adobe/helix-shared-wrap';
import dataAccessWrapper from '@adobe/spacecat-shared-data-access/wrapper';
import sqsEventAdapter from './sqsEventAdapter';
import sqs from './sqs';
import secrets from '@adobe/helix-shared-secrets';
import helixStatus from '@adobe/helix-status';

async function run(message, context) {
  const { dataAccess } = context;
  try {
    const sites = await dataAccess.getSites();
    // Function logic here
  } catch (error) {
    // Error handling
  }
}

export const main = wrap(run)
  .with(sqsEventAdapter)
  .with(dataAccessWrapper)
  .with(sqs)
  .with(secrets)
  .with(helixStatus);

Contributing

Contributions to spacecat-shared-data-access are welcome. Please adhere to the standard Git workflow and submit pull requests for proposed changes.

License

Licensed under the Apache-2.0 License.

1.23.0

5 days ago

1.22.1

9 days ago

1.22.0

9 days ago

1.21.3

13 days ago

1.21.2

22 days ago

1.21.1

1 month ago

1.21.0

1 month ago

1.20.5

2 months ago

1.20.4

2 months ago

1.20.3

2 months ago

1.20.2

2 months ago

1.20.1

2 months ago

1.20.0

2 months ago

1.19.3

2 months ago

1.19.0

2 months ago

1.19.2

2 months ago

1.19.1

2 months ago

1.18.1

2 months ago

1.18.0

3 months ago

1.17.2

3 months ago

1.17.1

3 months ago

1.16.0

3 months ago

1.17.0

3 months ago

1.15.6

3 months ago

1.15.5

3 months ago

1.15.4

3 months ago

1.15.2-test

3 months ago

1.15.0-test

3 months ago

1.15.3

3 months ago

1.15.2

3 months ago

1.15.1

3 months ago

1.15.0

3 months ago

1.14.1

3 months ago

1.14.0

3 months ago

1.12.0

3 months ago

1.11.0

3 months ago

1.13.2

3 months ago

1.13.1

3 months ago

1.13.0

3 months ago

1.10.5

3 months ago

1.10.4

3 months ago

1.10.3

4 months ago

1.10.2

4 months ago

1.9.6

4 months ago

1.9.5

4 months ago

1.10.1

4 months ago

1.10.0

4 months ago

1.9.4

4 months ago

1.9.3

4 months ago

1.9.2

4 months ago

1.9.1

4 months ago

1.9.0

4 months ago

1.8.0

4 months ago

1.7.0

4 months ago

1.6.4

4 months ago

1.6.3

4 months ago

1.6.2

4 months ago

1.6.1

4 months ago

1.6.0

4 months ago

1.5.2

4 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.4.4

5 months ago

1.4.3

5 months ago

1.4.2

5 months ago

1.4.1

5 months ago

1.3.2

5 months ago

1.4.0

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.7

5 months ago

1.2.6

5 months ago

1.2.5

5 months ago

1.2.4

5 months ago

1.2.3

5 months ago

1.2.2

5 months ago

1.2.1

5 months ago

1.2.0

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago