Skip to content

Commit ee5a3d2

Browse files
authored
Merge pull request #306 from cipherstash/usability-1
feat: stack usability and docs updates
2 parents 02dc60b + 231cf7f commit ee5a3d2

File tree

96 files changed

+855
-5557
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+855
-5557
lines changed

.changeset/lazy-rocks-look.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@cipherstash/stack": minor
3+
---
4+
5+
### Documentation
6+
7+
- **TypeDoc**: Improved JSDoc for `Encryption()`, `EncryptOptions`, schema builders (`encryptedTable`, `encryptedColumn`, `encryptedField`, `EncryptedField`, `EncryptedTableColumn`), and `encrypt` / `bulkEncrypt` with clearer `@param`, `@returns`, `@throws`, `@example`, and `@see` links.
8+
- **README**: Refreshed main repo README and Stack package readme; basic example README now uses `npm install @cipherstash/stack`, CipherStash account and dashboard credentials, and drops Stash CLI references. Added docs badge linking to cipherstash.com/docs.
9+
10+
### Features
11+
12+
- **Logging**: Logger is now used consistently across Stack client interfaces for initialization and operations.

AGENTS.md

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This is the Protect.js repository - End-to-end, per-value encryption for JavaScr
33
## Prerequisites
44

55
- **Node.js**: >= 22 (enforced in `package.json` engines)
6-
- **pnpm**: 9.x (this repo uses pnpm workspaces and catalogs)
6+
- **pnpm**: 10.14.0 (this repo uses pnpm workspaces and catalogs)
77
- Internet access to install the prebuilt native module `@cipherstash/protect-ffi`
88

99
If running integration tests or examples, you will also need CipherStash credentials (see Environment variables below).
@@ -24,7 +24,7 @@ pnpm run build
2424
pnpm run build:js
2525
```
2626

27-
Under the hood this uses Turborepo to build `./packages/*` with each packages `tsup` configuration.
27+
Under the hood this uses Turborepo to build `./packages/*` with each package's `tsup` configuration.
2828

2929
### Dev/watch
3030

@@ -43,11 +43,11 @@ pnpm test
4343
- Filter to a single package (recommended for fast iteration):
4444

4545
```bash
46-
pnpm --filter @cipherstash/protect test
46+
pnpm --filter @cipherstash/stack test
4747
pnpm --filter @cipherstash/nextjs test
4848
```
4949

50-
Tests use **Vitest**. Many tests talk to the real CipherStash service; they require environment variables. Some tests (e.g., lock context) are skipped if optional tokens arent present.
50+
Tests use **Vitest**. Many tests talk to the real CipherStash service; they require environment variables. Some tests (e.g., lock context) are skipped if optional tokens aren't present.
5151

5252
### Environment variables required for runtime/tests
5353

@@ -64,48 +64,58 @@ USER_JWT=
6464
USER_2_JWT=
6565

6666
# Logging (plaintext is never logged by design)
67-
PROTECT_LOG_LEVEL=debug|info|error
67+
STASH_STACK_LOG=debug|info|error # default: error (errors only)
6868
```
6969

7070
If these variables are missing, tests that require live encryption will fail or be skipped; prefer filtering to specific packages and tests while developing.
7171

7272
## Repository Layout
7373

74-
- `packages/protect`: Core library
75-
- `src/index.ts`: Public API (`protect`, exports)
76-
- `src/ffi/index.ts`: `ProtectClient` implementation, bridges to `@cipherstash/protect-ffi`
77-
- `src/ffi/operations/*`: Encrypt/decrypt/model/bulk/search-terms operations (thenable pattern with optional `.withLockContext()`)
74+
- `packages/stack`: Main package (`@cipherstash/stack`) containing the encryption client and all integrations
75+
- Subpath exports: `@cipherstash/stack`, `@cipherstash/stack/schema`, `@cipherstash/stack/identity`, `@cipherstash/stack/secrets`, `@cipherstash/stack/drizzle`, `@cipherstash/stack/supabase`, `@cipherstash/stack/dynamodb`, `@cipherstash/stack/client`, `@cipherstash/stack/types`
76+
- `packages/protect`: Core encryption library (internal, re-exported via `@cipherstash/stack`)
77+
- `src/index.ts`: Public API (`Encryption`, exports)
78+
- `src/ffi/index.ts`: `EncryptionClient` implementation, bridges to `@cipherstash/protect-ffi`
79+
- `src/ffi/operations/*`: Encrypt/decrypt/model/bulk/query operations (thenable pattern with optional `.withLockContext()`)
7880
- `__tests__/*`: End-to-end and API contract tests (Vitest)
79-
- `packages/schema`: Schema builder utilities and types (`csTable`, `csColumn`, `buildEncryptConfig`)
81+
- `packages/schema`: Schema builder utilities and types (`encryptedTable`, `encryptedColumn`, `encryptedField`)
82+
- `packages/drizzle`: Drizzle ORM integration (`encryptedType`, `extractEncryptionSchema`, `createEncryptionOperators`)
8083
- `packages/nextjs`: Next.js helpers and Clerk integration (`./clerk` export)
81-
- `packages/protect-dynamodb`: DynamoDB helpers for Protect.js
84+
- `packages/protect-dynamodb`: DynamoDB helpers (`encryptedDynamoDB`)
8285
- `packages/utils`: Shared config (`utils/config`) and logger (`utils/logger`)
8386
- `examples/*`: Working apps (basic, drizzle, nextjs-clerk, next-drizzle-mysql, dynamo, hono-supabase)
8487
- `docs/*`: Concepts, how-to guides (Next.js bundling, SST, npm lockfile v3), reference
88+
- `skills/*`: Agent skills (`stash-encryption`, `stash-drizzle`, `stash-dynamodb`, `stash-secrets`, `stash-supabase`)
8589

8690
## Key Concepts and APIs
8791

88-
- **Initialization**: `protect({ schemas })` returns an initialized `ProtectClient`. Provide at least one `csTable`.
89-
- **Schema**: Define tables/columns with `csTable` and `csColumn`. Add `.freeTextSearch().equality().orderAndRange()` to enable searchable encryption on PostgreSQL.
90-
- **Operations** (all return Result-like objects and support chaining `.withLockContext(lockContext)` when applicable):
92+
- **Initialization**: `Encryption({ schemas })` returns an initialized `EncryptionClient`. Provide at least one `encryptedTable`.
93+
- **Schema**: Define tables/columns with `encryptedTable` and `encryptedColumn` from `@cipherstash/stack/schema`. Add `.freeTextSearch().equality().orderAndRange()` to enable searchable encryption on PostgreSQL. Use `.searchableJson()` for encrypted JSONB queries. Use `encryptedField` for nested object encryption (DynamoDB).
94+
- **Operations** (all return Result-like objects and support chaining `.withLockContext(lockContext)` and `.audit()` when applicable):
9195
- `encrypt(plaintext, { table, column })`
9296
- `decrypt(encryptedPayload)`
9397
- `encryptModel(model, table)` / `decryptModel(model)`
9498
- `bulkEncrypt(plaintexts[], { table, column })` / `bulkDecrypt(encrypted[])`
9599
- `bulkEncryptModels(models[], table)` / `bulkDecryptModels(models[])`
96-
- `createSearchTerms(terms)` for searchable queries
97-
- **Identity-aware encryption**: Use `LockContext` from `@cipherstash/protect/identify` and chain `.withLockContext()` on operations. Same context must be used for both encrypt and decrypt.
100+
- `encryptQuery(value, { table, column, queryType?, returnType? })` for searchable queries
101+
- `encryptQuery(terms[])` for batch query encryption
102+
- **Identity-aware encryption**: Use `LockContext` from `@cipherstash/stack/identity` and chain `.withLockContext()` on operations. Same context must be used for both encrypt and decrypt.
103+
- **Integrations**:
104+
- **Drizzle ORM**: `encryptedType`, `extractEncryptionSchema`, `createEncryptionOperators` from `@cipherstash/stack/drizzle`
105+
- **Supabase**: `encryptedSupabase` from `@cipherstash/stack/supabase`
106+
- **DynamoDB**: `encryptedDynamoDB` from `@cipherstash/stack/dynamodb`
107+
- **Secrets management**: `Secrets` class from `@cipherstash/stack/secrets` for encrypted secret storage and retrieval.
98108

99109
## Critical Gotchas (read before coding)
100110

101-
- **Native Node.js module**: Protect.js relies on `@cipherstash/protect-ffi` (Node-API). It must be loaded via native Node.js `require`. Do NOT bundle this module; configure bundlers to externalize it.
111+
- **Native Node.js module**: `@cipherstash/stack` relies on `@cipherstash/protect-ffi` (Node-API). It must be loaded via native Node.js `require`. Do NOT bundle this module; configure bundlers to externalize it.
102112
- Next.js: see `docs/how-to/nextjs-external-packages.md`
103113
- SST/Serverless: see `docs/how-to/sst-external-packages.md`
104114
- npm lockfile v3 on Linux: see `docs/how-to/npm-lockfile-v3.md`
105-
- **Do not log plaintext**: The library never logs plaintext by design. Dont add logs that risk leaking sensitive data.
106-
- **Result shape is contract**: Operations return `{ data }` or `{ failure }`. Preserve this shape and error `type` values in `ProtectErrorTypes`.
107-
- **Encrypted payload shape is contract**: Keys like `c` in the EQL payload are validated by tests and downstream tools. Dont change them.
108-
- **Exports must support ESM and CJS**: Each packages `exports` maps must keep both `import` and `require` fields. Dont remove CJS.
115+
- **Do not log plaintext**: The library never logs plaintext by design. Don't add logs that risk leaking sensitive data.
116+
- **Result shape is contract**: Operations return `{ data }` or `{ failure }`. Preserve this shape and error `type` values in `EncryptionErrorTypes`.
117+
- **Encrypted payload shape is contract**: Keys like `c` in the EQL payload are validated by tests and downstream tools. Don't change them.
118+
- **Exports must support ESM and CJS**: Each package's `exports` maps must keep both `import` and `require` fields. Don't remove CJS.
109119

110120
## Development Workflow
111121

@@ -127,25 +137,25 @@ pnpm changeset:publish
127137

128138
### Writing tests
129139

130-
- Use Vitest with `.test.ts` files under each packages `__tests__/`.
140+
- Use Vitest with `.test.ts` files under each package's `__tests__/`.
131141
- Import `dotenv/config` at the top when tests need environment variables.
132142
- Prefer testing via the public API. Avoid reaching into private internals.
133143
- Some tests have larger timeouts (e.g., 30s) to accommodate network calls.
134144

135145
## Bundling and Deployment Notes
136146

137-
- When integrating into frameworks/build tools, ensure native modules are externalized and loaded via Nodes runtime require.
147+
- When integrating into frameworks/build tools, ensure native modules are externalized and loaded via Node's runtime require.
138148
- For Next.js, configure `serverExternalPackages` as documented in `docs/how-to/nextjs-external-packages.md`.
139149
- For serverless/Linux targets with npm lockfile v3, see `docs/how-to/npm-lockfile-v3.md` to avoid runtime load errors.
140150

141151
## Adding Features Safely (LLM checklist)
142152

143153
1. Identify the target package(s) in `packages/*` and confirm whether changes affect public APIs or payload shapes.
144-
2. If modifying `packages/protect` operations or `ProtectClient`, ensure:
154+
2. If modifying `packages/protect` operations or `EncryptionClient`, ensure:
145155
- The Result contract and error type strings remain stable.
146156
- `.withLockContext()` remains available for affected operations.
147-
- ESM/CJS exports continue to work (dont break `require`).
148-
3. If changing schema behavior (`packages/schema`), update type definitions and ensure `buildEncryptConfig` still validates with Zod in `ProtectClient.init`.
157+
- ESM/CJS exports continue to work (don't break `require`).
158+
3. If changing schema behavior (`packages/schema`), update type definitions and ensure validation still works in `EncryptionClient.init`.
149159
4. Add/extend tests in the same package. For features that require live credentials, guard with env checks or provide mock-friendly paths.
150160
5. Run:
151161
- `pnpm run code:fix`
@@ -157,17 +167,22 @@ pnpm changeset:publish
157167

158168
- `README.md` for quickstart and feature overview
159169
- `docs/concepts/searchable-encryption.md`
170+
- `docs/concepts/aws-kms-vs-cipherstash-comparison.md`
160171
- `docs/reference/schema.md`
161172
- `docs/reference/searchable-encryption-postgres.md`
173+
- `docs/reference/configuration.md`
174+
- `docs/reference/identity.md`
175+
- `docs/reference/secrets.md`
176+
- `docs/reference/dynamodb.md`
177+
- `docs/reference/supabase-sdk.md`
178+
- `docs/reference/drizzle/drizzle.md`
162179
- `docs/how-to/nextjs-external-packages.md`
163180
- `docs/how-to/sst-external-packages.md`
164181
- `docs/how-to/npm-lockfile-v3.md`
165182

166183
## Troubleshooting
167184

168185
- Module load errors on Linux/serverless: review the npm lockfile v3 guide.
169-
- Cant decrypt after encrypting with a lock context: ensure the exact same lock context is provided to decrypt.
186+
- Can't decrypt after encrypting with a lock context: ensure the exact same lock context is provided to decrypt.
170187
- Tests failing due to missing credentials: provide `CS_*` env vars; lock-context tests are skipped without `USER_JWT`.
171188
- Performance testing: prefer bulk operations (`bulkEncrypt*` / `bulkDecrypt*`) to exercise ZeroKMS bulk speed.
172-
173-

0 commit comments

Comments
 (0)