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.

Write semantics ​

Writes are create-only: each upload is sent with IfNoneMatch: '*', so S3 rejects it if an object with the same key already exists. If two PUTs of the same hash race past the server's existence check, the first one to finish is kept and the second is dropped without error (S3 answers 412 PreconditionFailed or 409 ConditionalRequestConflict, both treated as success). A stored entry is never overwritten. The protection depends on the endpoint supporting conditional writes; S3-compatible services that do not support IfNoneMatch may not enforce it.

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 encryption (key derivation, IV and blob format) is documented in @renatorodrigues/cacheiro-encryption. This KDF differs from the deprecated official Nx S3 plugin, 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 🌐