Skip to content

@renatorodrigues/cacheiro-store-s3 ​

S3 store for @renatorodrigues/cacheiro. Stores Nx cache artifacts in an AWS S3 bucket (or any S3-compatible storage: MinIO, LocalStack, DigitalOcean Spaces, Cloudflare R2).

Also available as a prebuilt Docker image: cacheiro-instants-s3, part of Cacheiro Instants.

Usage ​

ts
import { S3Store } from '@renatorodrigues/cacheiro-store-s3';

const store = new S3Store({
  bucket: 'my-nx-cache',
  region: 'us-east-1',
});

await store.mount();

Config validation ​

This package exports a JSON Schema (draft-07) and a TypeScript type for the config shape. Use them to validate and cast a raw config object before constructing the store — the example below uses AJV, but any JSON Schema validator works:

ts
import { configSchema, type S3StoreConfig } from '@renatorodrigues/cacheiro-store-s3';
import { Ajv } from 'ajv';

const validate = new Ajv({ allErrors: true }).compile(configSchema);

// example — error handling is up to your runner
if (!validate(raw)) throw new Error('invalid store config');
const store = new S3Store(raw as unknown as S3StoreConfig);

Development ​

sh
npm run watch        # tsc --watch (hot rebuild)
npm run build        # compile TypeScript
npm test             # vitest run
npm run test:watch
npm run lint
npm run fmt

Config ​

FieldTypeRequiredDescription
bucketstringYesS3 bucket name.
regionstringYesAWS region (e.g. us-east-1).
endpointstringNoCustom S3-compatible endpoint URL (MinIO, LocalStack, etc.).
accessKeyIdstringNoAWS access key ID. Falls back to the AWS credential chain (AWS_ACCESS_KEY_ID env var, AWS_PROFILE, IAM role, etc.) when omitted.
secretAccessKeystringNoAWS secret access key. Falls back to the AWS credential chain (AWS_SECRET_ACCESS_KEY env var, IAM role, etc.) when omitted.
forcePathStylebooleanNoUse path-style URLs instead of virtual-hosted. Required for most S3-compatible storage. Default: false.
prefixstringNoKey prefix for all cache entries. Useful when sharing a bucket across projects.
encryptionKeystringNoClient-side AES-256-CBC encryption key. When set, artifacts are encrypted before upload.
ssoProfilestringNoAWS SSO profile name. Falls back to the AWS_PROFILE env var when omitted.
disableChecksumbooleanNoDisable AWS response checksum validation. Default: false.
serverSideEncryptionbooleanNoEnable S3 SSE-S3 (AES256) server-side encryption. Ignored when encryptionKey is set. Default: false.

See Environment variables reference for conventional env var names.

Encryption ​

Two mutually exclusive modes are supported:

encryptionKeyserverSideEncryptionBehavior
setfalseClient-side AES-256-CBC. Bytes encrypted locally before upload.
unsettrueS3 SSE-S3. AWS encrypts at rest with managed keys.
settrueWarns and uses client-side only.
unsetfalseNo encryption (relies on bucket policies and TLS in transit).

Client-side keys are stretched with scrypt (fixed salt, default cost) to a 32-byte AES key. The IV is randomly generated per write and prepended to the ciphertext: [16-byte IV][ciphertext]. This KDF differs from the deprecated official Nx S3 plugin (which truncated/repeated the key), so buckets encrypted with the upstream plugin are not interoperable.

Environment variables reference ​

VariableConfig field
S3_BUCKETbucket
S3_REGIONregion
S3_ENDPOINTendpoint
AWS_ACCESS_KEY_IDaccessKeyId
AWS_SECRET_ACCESS_KEYsecretAccessKey
AWS_PROFILEssoProfile
S3_FORCE_PATH_STYLEforcePathStyle
S3_PREFIXprefix
S3_ENCRYPTION_KEYencryptionKey
S3_DISABLE_CHECKSUMdisableChecksum
S3_SERVER_SIDE_ENCRYPTIONserverSideEncryption

Crafted with 🤍 by a 🇧🇷 human in 🇩🇪, for the humans of the 🌐