npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@adobe/spacecat-shared-data-access

v1.44.3

Published

Shared modules of the Spacecat Services - Data Access

Downloads

4,370

Readme

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.