Craft My Plate AWS Database

raw JSON →
1.7.1 verified Sat Apr 25 auth: no javascript

Defines global tables for the Craft My Plate application ecosystem, providing a shared database schema and utilities for AWS-based deployments. Current stable version is 1.7.1, released as needed alongside the main application. It is tightly coupled with the Craft My Plate monorepo and is not designed for independent use. Export models include DynamoDB table definitions and helper functions for common database operations.

error Cannot find module 'cmp-aws-database' or its corresponding type declarations.
cause The package is not installed or TypeScript cannot locate its types.
fix
Run 'npm install cmp-aws-database' and ensure tsconfig.json includes 'moduleResolution': 'node'.
error TypeError: UserTable.name is undefined
cause Importing incorrectly (e.g., using default import instead of named import).
fix
Use 'import { UserTable } from 'cmp-aws-database''.
error ValidationError: "name" is required
cause Missing required field when putting item into a table with Zod validation.
fix
Ensure all required fields per the Zod schema are provided in the item object.
error Region is missing
cause getDatabaseClient() called without region option.
fix
Provide region in the config object to getDatabaseClient().
breaking Version 2.0 removes support for Node.js 14 and below.
fix Upgrade Node.js to version 16 or higher.
gotcha Table names are defined as constants (e.g., 'cmp-users'). Do not hardcode table names; use the exported constants.
fix Import the table constant (e.g., UserTable.name) to avoid mismatches.
deprecated The function 'getDB' is deprecated in favor of 'getDatabaseClient'.
fix Replace getDB() with getDatabaseClient().
gotcha All tables are defined in the us-east-1 region by default. If your stack uses a different region, you must override it in the client configuration.
fix Pass region explicitly to getDatabaseClient().
breaking In version 1.6.0, the schema validation library changed from Joi to Zod. Existing implicit validation will break.
fix Update validation logic to use Zod schemas exposed by the package.
npm install cmp-aws-database
yarn add cmp-aws-database
pnpm add cmp-aws-database

Initializes the database client and creates a user item in the UserTable.

import { UserTable, RecipeTable, getDatabaseClient } from 'cmp-aws-database';

const client = getDatabaseClient({
  region: 'us-east-1',
  accessKeyId: process.env.AWS_ACCESS_KEY_ID ?? '',
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY ?? ''
});

async function createUser(userId: string, name: string) {
  const params = {
    TableName: UserTable.name,
    Item: { userId, name, createdAt: new Date().toISOString() }
  };
  await client.put(params).promise();
  console.log('User created');
}

createUser('123', 'Alice').catch(console.error);