@datar-platform/better-auth-dynamodb 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +33 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @datar-platform/better-auth-dynamodb
|
|
2
2
|
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
Documentation only — no runtime change.
|
|
6
|
+
|
|
7
|
+
- The uniqueness section still said markers "do not find duplicates already
|
|
8
|
+
there", which 0.2.1's `migrateKeys()` made untrue, and which contradicted the
|
|
9
|
+
upgrade section a few paragraphs above it.
|
|
10
|
+
- The install step now states the `better-auth >= 1.7` and Node >= 22
|
|
11
|
+
requirements, rather than leaving them to be discovered as a peer error.
|
|
12
|
+
- The opening claim that any model or plugin "just works" now says what the
|
|
13
|
+
no-hidden-scan default actually does, instead of implying every query is
|
|
14
|
+
served.
|
|
15
|
+
- Documents the exported error types, so a caller can tell "this email is taken"
|
|
16
|
+
from a failed write by catching `UniqueConstraintError`.
|
|
17
|
+
- The query-planning description covers the `id` and `id in [...]` paths added
|
|
18
|
+
in 0.2.0, not only index selection.
|
|
19
|
+
- The bring-your-own-store sketch calls out `consumeOne`/`incrementOne` — they
|
|
20
|
+
are optional, but they are what makes single-use codes and counters atomic.
|
|
21
|
+
|
|
3
22
|
## 0.2.1
|
|
4
23
|
|
|
5
24
|
### Added
|
package/README.md
CHANGED
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
A generic [DynamoDB](https://aws.amazon.com/dynamodb/) adapter for [Better Auth](https://better-auth.com).
|
|
4
4
|
|
|
5
5
|
- **Works out of the box** with any Better Auth model or plugin — the built-in
|
|
6
|
-
single-table store derives its indexes from your schema (`unique` fields
|
|
7
|
-
foreign keys), so two-factor, passkey,
|
|
6
|
+
single-table store derives its indexes from your schema (`unique` fields,
|
|
7
|
+
foreign keys, and anything marked `index: true`), so two-factor, passkey,
|
|
8
|
+
API-key, organization, etc. work with no per-model configuration. Queries no
|
|
9
|
+
index can serve are refused rather than silently scanned, so an access pattern
|
|
10
|
+
nobody designed for shows up in development (see `unsafeAllowScan`).
|
|
8
11
|
- **Bring your own store.** The adapter talks to a small `DynamoStore` seam, so
|
|
9
12
|
you can back it with an existing single-table design (ElectroDB, custom key
|
|
10
13
|
encoding, a shared table) without changing the adapter.
|
|
@@ -26,6 +29,9 @@ A generic [DynamoDB](https://aws.amazon.com/dynamodb/) adapter for [Better Auth]
|
|
|
26
29
|
npm install @datar-platform/better-auth-dynamodb @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
|
|
27
30
|
```
|
|
28
31
|
|
|
32
|
+
Requires `better-auth` 1.7 or newer, and Node 22 or newer. On `better-auth`
|
|
33
|
+
1.5/1.6, stay on 0.1.x.
|
|
34
|
+
|
|
29
35
|
## Quick start (built-in single-table store)
|
|
30
36
|
|
|
31
37
|
```ts
|
|
@@ -131,13 +137,25 @@ Better Auth's own enforcement is a check-then-insert, which both racers can
|
|
|
131
137
|
pass. Set `atomicUniqueness: false` to fall back to it and halve the write cost
|
|
132
138
|
of creates.
|
|
133
139
|
|
|
134
|
-
Two
|
|
140
|
+
Two things worth knowing:
|
|
135
141
|
|
|
136
|
-
-
|
|
137
|
-
|
|
142
|
+
- On a table upgraded from 0.1.x, markers only cover rows written since the
|
|
143
|
+
upgrade until you run [`migrateKeys()`](#upgrading-from-01x), which backfills
|
|
144
|
+
them for the rows already there.
|
|
138
145
|
- Do not write Better Auth rows into the table with a raw `PutItem`. Entity
|
|
139
146
|
rows, index keys, markers, and TTL attributes have to move together.
|
|
140
147
|
|
|
148
|
+
A write that loses a uniqueness race throws `UniqueConstraintError`, so you can
|
|
149
|
+
tell "this email is taken" apart from a failed write:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
import { UniqueConstraintError } from "@datar-platform/better-auth-dynamodb";
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
`DynamoDBAdapterError` is the base of everything this package throws;
|
|
156
|
+
`UnsupportedQueryError` and `OptimisticLockError` are the other two you might
|
|
157
|
+
catch by name.
|
|
158
|
+
|
|
141
159
|
## Bring your own store
|
|
142
160
|
|
|
143
161
|
Implement `DynamoStore` to run the same adapter against your own table layout.
|
|
@@ -171,7 +189,10 @@ const store: DynamoStore = {
|
|
|
171
189
|
listByType({ model }) {
|
|
172
190
|
/* list all rows of a model */
|
|
173
191
|
},
|
|
174
|
-
//
|
|
192
|
+
// Optional, and worth implementing: `consumeOne` (atomic delete-and-return,
|
|
193
|
+
// which is what stops a one-time code being used twice) and `incrementOne`
|
|
194
|
+
// (atomic counter). Without them the adapter falls back to a non-atomic
|
|
195
|
+
// get-then-write. Also optional: `count()`, `createSchema()`.
|
|
175
196
|
};
|
|
176
197
|
|
|
177
198
|
// Describe which fields each model is looked up by:
|
|
@@ -187,10 +208,12 @@ const indexMap: IndexMap = {
|
|
|
187
208
|
betterAuth({ database: dynamoAdapter({ store, indexMap }) });
|
|
188
209
|
```
|
|
189
210
|
|
|
190
|
-
Given a `where`, the adapter
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
211
|
+
Given a `where`, the adapter takes the cheapest path it can prove: an `id`
|
|
212
|
+
equality becomes a direct get, an `id in [...]` becomes a bounded set of gets,
|
|
213
|
+
and otherwise it picks the first access pattern whose partition-key fields are
|
|
214
|
+
all present (attaching any leading sort-key fields). Whatever the chosen path
|
|
215
|
+
does not cover is filtered in memory. Provide an `indexMap` to match your table,
|
|
216
|
+
or omit it to auto-derive from the schema.
|
|
194
217
|
|
|
195
218
|
## Configuration
|
|
196
219
|
|
package/package.json
CHANGED