You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**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.
Copy file name to clipboardExpand all lines: AGENTS.md
+44-29Lines changed: 44 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ This is the Protect.js repository - End-to-end, per-value encryption for JavaScr
3
3
## Prerequisites
4
4
5
5
-**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)
7
7
- Internet access to install the prebuilt native module `@cipherstash/protect-ffi`
8
8
9
9
If running integration tests or examples, you will also need CipherStash credentials (see Environment variables below).
@@ -24,7 +24,7 @@ pnpm run build
24
24
pnpm run build:js
25
25
```
26
26
27
-
Under the hood this uses Turborepo to build `./packages/*` with each package’s `tsup` configuration.
27
+
Under the hood this uses Turborepo to build `./packages/*` with each package's `tsup` configuration.
28
28
29
29
### Dev/watch
30
30
@@ -43,11 +43,11 @@ pnpm test
43
43
- Filter to a single package (recommended for fast iteration):
44
44
45
45
```bash
46
-
pnpm --filter @cipherstash/protecttest
46
+
pnpm --filter @cipherstash/stacktest
47
47
pnpm --filter @cipherstash/nextjs test
48
48
```
49
49
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.
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.
51
51
52
52
### Environment variables required for runtime/tests
If these variables are missing, tests that require live encryption will fail or be skipped; prefer filtering to specific packages and tests while developing.
71
71
72
72
## Repository Layout
73
73
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
-**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):
-`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.
98
108
99
109
## Critical Gotchas (read before coding)
100
110
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.
102
112
- Next.js: see `docs/how-to/nextjs-external-packages.md`
103
113
- SST/Serverless: see `docs/how-to/sst-external-packages.md`
104
114
- 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. Don’t 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. Don’t change them.
108
-
-**Exports must support ESM and CJS**: Each package’s `exports` maps must keep both `import` and `require` fields. Don’t 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.
109
119
110
120
## Development Workflow
111
121
@@ -127,25 +137,25 @@ pnpm changeset:publish
127
137
128
138
### Writing tests
129
139
130
-
- Use Vitest with `.test.ts` files under each package’s `__tests__/`.
140
+
- Use Vitest with `.test.ts` files under each package's `__tests__/`.
131
141
- Import `dotenv/config` at the top when tests need environment variables.
132
142
- Prefer testing via the public API. Avoid reaching into private internals.
133
143
- Some tests have larger timeouts (e.g., 30s) to accommodate network calls.
134
144
135
145
## Bundling and Deployment Notes
136
146
137
-
- When integrating into frameworks/build tools, ensure native modules are externalized and loaded via Node’s runtime require.
147
+
- When integrating into frameworks/build tools, ensure native modules are externalized and loaded via Node's runtime require.
138
148
- For Next.js, configure `serverExternalPackages` as documented in `docs/how-to/nextjs-external-packages.md`.
139
149
- For serverless/Linux targets with npm lockfile v3, see `docs/how-to/npm-lockfile-v3.md` to avoid runtime load errors.
140
150
141
151
## Adding Features Safely (LLM checklist)
142
152
143
153
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:
145
155
- The Result contract and error type strings remain stable.
146
156
-`.withLockContext()` remains available for affected operations.
147
-
- ESM/CJS exports continue to work (don’t 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`.
149
159
4. Add/extend tests in the same package. For features that require live credentials, guard with env checks or provide mock-friendly paths.
0 commit comments