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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@chaim-tools/cdk-lib

v0.1.2

Published

AWS CDK v2 constructs for Chaim schema management

Downloads

278

Readme

@chaim-tools/cdk-lib

AWS CDK L2 constructs for binding DynamoDB tables to Chaim schemas.

Installation

npm install @chaim-tools/cdk-lib
# or
pnpm add @chaim-tools/cdk-lib

Development

Build

pnpm install
pnpm build

Test

pnpm test              # Run tests
pnpm test:watch        # Watch mode
pnpm test:coverage     # With coverage

Clean

pnpm clean

Quick Start

import { ChaimDynamoDBBinder, ChaimCredentials, TableBindingConfig } from '@chaim-tools/cdk-lib';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';

// Create a DynamoDB table
const usersTable = new dynamodb.Table(this, 'Users', {
  partitionKey: { name: 'pk', type: dynamodb.AttributeType.STRING },
  billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
});

// Create binding configuration
const config = new TableBindingConfig(
  'my-app',
  ChaimCredentials.fromSecretsManager('chaim/api-credentials')
);

// Bind schema to table
new ChaimDynamoDBBinder(this, 'UsersBinding', {
  schemaPath: './schemas/users.bprint',
  table: usersTable,
  config,
});

API Reference

ChaimDynamoDBBinder

Construct that binds a DynamoDB table to a Chaim schema.

Props

| Property | Type | Required | Description | |----------|------|----------|-------------| | schemaPath | string | Yes | Path to .bprint schema file | | table | ITable | Yes | DynamoDB table to bind | | config | TableBindingConfig | Yes | Binding configuration (appId, credentials, failureMode) |

TableBindingConfig

Configuration for entity bindings. For single-table design, create one config and share across all entity bindings.

// Create config with Secrets Manager (recommended for production)
const config = new TableBindingConfig(
  'my-app',
  ChaimCredentials.fromSecretsManager('chaim/api-credentials')
);

// Or with direct API keys (for development)
const config = new TableBindingConfig(
  'my-app',
  ChaimCredentials.fromApiKeys(apiKey, apiSecret),
  FailureMode.STRICT  // Optional - defaults to BEST_EFFORT
);

Constructor Parameters:

  • appId (string) - Application ID for the Chaim platform
  • credentials (IChaimCredentials) - API credentials
  • failureMode (FailureMode) - Optional, defaults to BEST_EFFORT

ChaimCredentials

Factory class for creating Chaim API credentials.

// Using AWS Secrets Manager (recommended for production)
const credentials = ChaimCredentials.fromSecretsManager('chaim/api-credentials');

// Using direct API keys (for development/testing)
const credentials = ChaimCredentials.fromApiKeys(apiKey, apiSecret);

FailureMode

| Mode | Behavior | |------|----------| | BEST_EFFORT (default) | Log errors, return SUCCESS to CloudFormation | | STRICT | Return FAILED to CloudFormation on any ingestion error |

Single-Table Design (Multiple Entities)

For single-table design where multiple entity types share one DynamoDB table, create one TableBindingConfig and share it across all entity bindings:

import { ChaimDynamoDBBinder, ChaimCredentials, TableBindingConfig } from '@chaim-tools/cdk-lib';

const singleTable = new dynamodb.Table(this, 'SingleTable', {
  partitionKey: { name: 'PK', type: dynamodb.AttributeType.STRING },
  sortKey: { name: 'SK', type: dynamodb.AttributeType.STRING },
});

// Create config ONCE for the table
const tableConfig = new TableBindingConfig(
  'my-app',
  ChaimCredentials.fromSecretsManager('chaim/api-credentials')
);

// Share config across all entities in the table
new ChaimDynamoDBBinder(this, 'UserBinding', {
  schemaPath: './schemas/user.bprint',
  table: singleTable,
  config: tableConfig,
});

new ChaimDynamoDBBinder(this, 'OrderBinding', {
  schemaPath: './schemas/order.bprint',
  table: singleTable,
  config: tableConfig, // Same config!
});

new ChaimDynamoDBBinder(this, 'ProductBinding', {
  schemaPath: './schemas/product.bprint',
  table: singleTable,
  config: tableConfig, // Same config!
});

Why this pattern?

All entities in the same DynamoDB table must belong to the same application (appId) with the same credentials. TableBindingConfig enforces this by design:

  • Sharing the same config object makes consistency automatic
  • Validation catches accidental misconfigurations (different appIds)
  • Clear intent in your CDK code
  • DRY - define credentials once

Result:

  • 3 separate snapshots (one per entity)
  • 3 separate resourceIds: SingleTable__User, SingleTable__Order, SingleTable__Product
  • All with the same appId and credentials
  • Each entity can be independently created, updated, or deleted

How It Works

  1. At synth time: The construct reads your .bprint file, validates it, and writes a snapshot to the CDK asset directory
  2. During deploy: CloudFormation invokes the ingestion Lambda in your account
  3. The Lambda:
    • Reads the bundled snapshot from ./snapshot.json
    • Generates eventId (UUID v4), nonce (UUID v4), and contentHash (SHA-256)
    • Requests presigned URL: POST /ingest/presign with HMAC authentication
    • Uploads snapshot: PUT <presignedUrl>

Ingestion Flow

Create/Update:
  1. POST /ingest/presign with HMAC signature → get presigned S3 URL
     Request includes: appId, eventId, contentHash, timestamp, nonce
  2. PUT snapshot bytes to presigned S3 URL
  
Delete:
  1. Build DELETE snapshot (action: 'DELETE', schema: null)
  2. POST /ingest/presign with HMAC signature → get presigned S3 URL
  3. PUT DELETE snapshot bytes to presigned S3 URL

Snapshot Payload

The snapshot payload includes:

Schema & Identity:

  • schemaVersion - Payload version for backward compatibility (current: 1.0)
  • .bprint schema content (entity definitions, field types, constraints)
  • Application ID and resource identifiers

Infrastructure Metadata:

  • AWS account ID, region, stack information
  • DynamoDB table configuration (keys, indexes, TTL, streams)
  • CloudFormation context

Versioning Strategy:

  • Minor bump (1.0 → 1.1): Additive or optional field changes
  • Major bump (1.x → 2.0): Breaking changes (removed/renamed/required fields)

Configuration

Environment Configuration

The API defaults to production: https://api.chaim.co

Override for different environments via CDK context:

# Production (default - no context needed)
cdk deploy

# Development
cdk deploy --context chaimApiBaseUrl=https://api.dev.chaim.co

# Beta
cdk deploy --context chaimApiBaseUrl=https://api.beta.chaim.co

You can also set a custom API URL via environment variable in the Lambda:

  • CHAIM_API_BASE_URL - Overrides the default at runtime

License

Apache-2.0