@nxgt/janus-mongo 0.1.0 → 0.1.1
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/README.md +4 -3
- package/docs/guide/sync.md +2 -2
- package/docs/troubleshooting.md +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# @nxgt/janus-mongo
|
|
2
2
|
|
|
3
|
-
The MongoDB adapter for [`@nxgt/janus`](https://www.npmjs.com/package/@nxgt/janus): its
|
|
3
|
+
The MongoDB adapter for [`@nxgt/janus`](https://www.npmjs.com/package/@nxgt/janus): its identity stores —
|
|
4
4
|
users, sessions and one-time tokens — and the relation store of
|
|
5
5
|
`@nxgt/janus/permissions`, over one database, on
|
|
6
6
|
[`@nxgt/mongo`](https://www.npmjs.com/package/@nxgt/mongo).
|
|
7
7
|
|
|
8
8
|
It passes both `@nxgt/janus/conformance` suites against a real mongod, outages
|
|
9
|
-
included.
|
|
9
|
+
included. Each side is usable alone, as in `@nxgt/janus`: `createMongoStores`
|
|
10
|
+
for identities, `createMongoRelations` for permissions, or both, as below.
|
|
10
11
|
|
|
11
12
|
```ts
|
|
12
13
|
import { janus, scryptHasher } from '@nxgt/janus';
|
|
@@ -54,7 +55,7 @@ declarations import without extensions, so `nodenext` is not supported.
|
|
|
54
55
|
| `users`, `sessions`, `tokens` | The `@nxgt/mongo` definitions. Defining them registers them, so `syncAll(db)` syncs them with your own collections. |
|
|
55
56
|
| `janusCollections` | The three definitions, in sync order. |
|
|
56
57
|
| `createMongoRelations(db)` | The `RelationStore` that `permissions()` takes as `store`, and `janus()` as `relations`. Connects to nothing. |
|
|
57
|
-
| `syncMongoRelations(db, options?)` | Creates the `relations` collection and its indexes. A separate step: an application that
|
|
58
|
+
| `syncMongoRelations(db, options?)` | Creates the `relations` collection and its indexes. A separate step: an application that uses identities alone keeps no tuples. |
|
|
58
59
|
| `relations` | Its `@nxgt/mongo` definition. |
|
|
59
60
|
|
|
60
61
|
## What the database holds
|
package/docs/guide/sync.md
CHANGED
|
@@ -36,8 +36,8 @@ nothing.**
|
|
|
36
36
|
|
|
37
37
|
- It is a **deployment step**, never a request-time one: `collMod` needs the
|
|
38
38
|
`dbAdmin` role, and neither it nor an index build may run in a transaction.
|
|
39
|
-
- The relation store is a separate step because an application that
|
|
40
|
-
|
|
39
|
+
- The relation store is a separate step because an application that uses
|
|
40
|
+
identities alone keeps no tuples.
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
43
|
for (const report of await syncMongoStores(db)) {
|
package/docs/troubleshooting.md
CHANGED
|
@@ -139,7 +139,7 @@ const auth = janus({ ..., store: createMongoStores(client.db('janus')) });
|
|
|
139
139
|
|
|
140
140
|
`StoreFailure`, for example `users.findUserByLogin: the store could not answer`, with `slot`, `operation` and the driver's error as `cause`.
|
|
141
141
|
|
|
142
|
-
**When:** any call that reaches MongoDB while it cannot answer: the server is unreachable, server selection timed out, the
|
|
142
|
+
**When:** any call that reaches MongoDB while it cannot answer: the server is unreachable, server selection timed out, MongoDB refused the connection's user and password, a primary stepped down.
|
|
143
143
|
**Why:** a store that cannot answer throws — it never answers `null`. The driver's message stays out of the error's message, because it can hold the connection string, and a connection string holds a password.
|
|
144
144
|
**Fix:** answer **503** and log `cause`; never map it to 401, 404, `null` or `false`.
|
|
145
145
|
|
|
@@ -157,7 +157,7 @@ if (error instanceof JanusError && error.code === 'STORE_FAILED') {
|
|
|
157
157
|
`StoreConflict` with `on: 'login'`, for example `insertUser: the login "ada@example.com" is taken by another patient`. It carries `login` and `userType`.
|
|
158
158
|
|
|
159
159
|
**When:** `signUp`, `create`, or an `update` that changes the login, when another user **of the same type** already holds it. The message names the port method (`insertUser`, `updateUser`), not your call.
|
|
160
|
-
**Why:** the `loginUnique` index on `{ type, logins }` refused the write. The same e-mail may hold one
|
|
160
|
+
**Why:** the `loginUnique` index on `{ type, logins }` refused the write. The same e-mail may hold one user per user type.
|
|
161
161
|
**Fix:** answer 409.
|
|
162
162
|
|
|
163
163
|
### `STORE_FAILED` — `<slot>.<operation>: a duplicate key on <fields>, which this adapter never writes on purpose`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxgt/janus-mongo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "The MongoDB adapter for @nxgt/janus: users, sessions, one-time tokens and permission tuples",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
]
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@nxgt/janus": "^0.1.
|
|
51
|
+
"@nxgt/janus": "^0.1.1",
|
|
52
52
|
"@nxgt/mongo": "^0.17.1",
|
|
53
53
|
"@types/bun": "^1.4.2",
|
|
54
54
|
"mongodb": "^7.6.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"zod": "^4.6.5"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@nxgt/janus": "^0.1.
|
|
59
|
+
"@nxgt/janus": "^0.1.1",
|
|
60
60
|
"@nxgt/mongo": ">=0.17.0 <1",
|
|
61
61
|
"mongodb": ">=7.0.0 <8",
|
|
62
62
|
"typescript": "^6.0.3",
|