@nathapp/nestjs-iam-prisma 0.0.0-stage → 1.1.0
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 +372 -2
- package/dist/credential-id-hash.d.ts +1 -0
- package/dist/credential-id-hash.js +8 -0
- package/dist/credential-id-hash.js.map +1 -0
- package/dist/iam-prisma.module.d.ts +7 -0
- package/dist/iam-prisma.module.js +73 -0
- package/dist/iam-prisma.module.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/prisma-api-key.repository.d.ts +28 -0
- package/dist/prisma-api-key.repository.js +90 -0
- package/dist/prisma-api-key.repository.js.map +1 -0
- package/dist/prisma-auth-attempt.store.d.ts +42 -0
- package/dist/prisma-auth-attempt.store.js +112 -0
- package/dist/prisma-auth-attempt.store.js.map +1 -0
- package/dist/prisma-identity.repository.d.ts +26 -0
- package/dist/prisma-identity.repository.js +110 -0
- package/dist/prisma-identity.repository.js.map +1 -0
- package/dist/prisma-login-history.repository.d.ts +24 -0
- package/dist/prisma-login-history.repository.js +58 -0
- package/dist/prisma-login-history.repository.js.map +1 -0
- package/dist/prisma-mfa.repository.d.ts +20 -0
- package/dist/prisma-mfa.repository.js +57 -0
- package/dist/prisma-mfa.repository.js.map +1 -0
- package/dist/prisma-model.types.d.ts +188 -0
- package/dist/prisma-model.types.js +36 -0
- package/dist/prisma-model.types.js.map +1 -0
- package/dist/prisma-session.repository.d.ts +31 -0
- package/dist/prisma-session.repository.js +97 -0
- package/dist/prisma-session.repository.js.map +1 -0
- package/dist/prisma-sso-account.repository.d.ts +24 -0
- package/dist/prisma-sso-account.repository.js +71 -0
- package/dist/prisma-sso-account.repository.js.map +1 -0
- package/dist/prisma-sso-provider.repository.d.ts +28 -0
- package/dist/prisma-sso-provider.repository.js +91 -0
- package/dist/prisma-sso-provider.repository.js.map +1 -0
- package/dist/prisma-totp-replay.store.d.ts +34 -0
- package/dist/prisma-totp-replay.store.js +78 -0
- package/dist/prisma-totp-replay.store.js.map +1 -0
- package/dist/prisma-user.repository.d.ts +27 -0
- package/dist/prisma-user.repository.js +101 -0
- package/dist/prisma-user.repository.js.map +1 -0
- package/dist/prisma-verification-token.repository.d.ts +23 -0
- package/dist/prisma-verification-token.repository.js +66 -0
- package/dist/prisma-verification-token.repository.js.map +1 -0
- package/dist/prisma-webauthn-credential.repository.d.ts +32 -0
- package/dist/prisma-webauthn-credential.repository.js +113 -0
- package/dist/prisma-webauthn-credential.repository.js.map +1 -0
- package/dist/prisma-webauthn-mfa-binding.store.d.ts +26 -0
- package/dist/prisma-webauthn-mfa-binding.store.js +66 -0
- package/dist/prisma-webauthn-mfa-binding.store.js.map +1 -0
- package/package.json +47 -4
- package/prisma/iam.prisma +246 -0
- package/prisma/sql/api-key-scopes.postgresql.sql +18 -0
- package/prisma/sql/long-text-columns.mysql.sql +15 -0
- package/prisma/sql/primary-identity.mysql.sql +10 -0
- package/prisma/sql/primary-identity.postgresql.sql +11 -0
package/README.md
CHANGED
|
@@ -1,3 +1,373 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nathapp/nestjs-iam-prisma
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Prisma adapter for `@nathapp/nestjs-iam`. Binds the core package's repository
|
|
4
|
+
tokens to `AbstractPrismaRepository`-based implementations.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```shell
|
|
9
|
+
npm i @nathapp/nestjs-iam-prisma @prisma/client@7
|
|
10
|
+
npm i -D prisma@7
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Schema
|
|
14
|
+
|
|
15
|
+
Append the 13 models from the packaged fragment
|
|
16
|
+
`node_modules/@nathapp/nestjs-iam-prisma/prisma/iam.prisma` to your app's
|
|
17
|
+
`schema.prisma`. The fragment carries no `datasource` or `generator` block — it
|
|
18
|
+
is models only. For PostgreSQL, every `DateTime` in it uses `@db.Timestamptz(6)`;
|
|
19
|
+
bare `DateTime` is not correct for these fields. For MySQL, assemble the model
|
|
20
|
+
fragment with `@db.DateTime(6)` as shown below.
|
|
21
|
+
|
|
22
|
+
Two fields in the fragment are load-bearing, not cosmetic:
|
|
23
|
+
|
|
24
|
+
- `UserIdentity` declares its `user` relation and `User` its `identities` back
|
|
25
|
+
relation. `PrismaUserRepository.findByEmail` resolves the user through
|
|
26
|
+
`include: { user: true }` and throws
|
|
27
|
+
`userIdentity.user relation is undefined` when the relation is absent.
|
|
28
|
+
- `UserSession.previousRefreshTokenHash` is written and read by
|
|
29
|
+
`PrismaSessionRepository` for refresh-token replay detection (RFC 6819 §5.2.2.3).
|
|
30
|
+
|
|
31
|
+
`PrismaUserRepository.findByEmail` and `findByIdentifier` require a `tenantId` and
|
|
32
|
+
throw without one — email is stored on `user_identities`, never on `users`.
|
|
33
|
+
|
|
34
|
+
## Schema assembly and database support
|
|
35
|
+
|
|
36
|
+
When using the platform's tenant, IAM, account, notification, and OAuth Prisma
|
|
37
|
+
adapters together, concatenate their five model-only fragments into one schema
|
|
38
|
+
with exactly one generator and datasource. The packages do not publish a schema
|
|
39
|
+
generator or provider-specific copies of these models. This Node recipe writes a
|
|
40
|
+
separate schema file so you can add your application-owned models before running
|
|
41
|
+
Prisma 7:
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
mkdir -p scripts
|
|
45
|
+
cat > scripts/assemble-platform-schema.cjs <<'NODE'
|
|
46
|
+
const fs = require('node:fs');
|
|
47
|
+
const path = require('node:path');
|
|
48
|
+
|
|
49
|
+
const provider = process.env.PRISMA_PROVIDER;
|
|
50
|
+
if (provider !== 'postgresql' && provider !== 'mysql') {
|
|
51
|
+
throw new Error('Set PRISMA_PROVIDER to postgresql or mysql');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const fragments = [
|
|
55
|
+
'node_modules/@nathapp/nestjs-tenant-prisma/prisma/tenant.prisma',
|
|
56
|
+
'node_modules/@nathapp/nestjs-iam-prisma/prisma/iam.prisma',
|
|
57
|
+
'node_modules/@nathapp/nestjs-account-prisma/prisma/account.prisma',
|
|
58
|
+
'node_modules/@nathapp/nestjs-notify-prisma/prisma/notify.prisma',
|
|
59
|
+
'node_modules/@nathapp/nestjs-oauth-prisma/prisma/oauth.prisma',
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
let models = fragments.map((file) => fs.readFileSync(file, 'utf8')).join('\n\n');
|
|
63
|
+
if (provider === 'mysql') {
|
|
64
|
+
models = models.replaceAll('@db.Timestamptz(6)', '@db.DateTime(6)');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const schema = [
|
|
68
|
+
'generator client {',
|
|
69
|
+
' provider = "prisma-client"',
|
|
70
|
+
' output = "./client"',
|
|
71
|
+
' moduleFormat = "cjs"',
|
|
72
|
+
'}',
|
|
73
|
+
'',
|
|
74
|
+
'datasource db {',
|
|
75
|
+
` provider = "${provider}"`,
|
|
76
|
+
'}',
|
|
77
|
+
'',
|
|
78
|
+
models,
|
|
79
|
+
'',
|
|
80
|
+
].join('\n');
|
|
81
|
+
fs.mkdirSync('prisma', { recursive: true });
|
|
82
|
+
fs.writeFileSync(path.resolve('prisma/platform.schema.prisma'), schema);
|
|
83
|
+
NODE
|
|
84
|
+
|
|
85
|
+
# PostgreSQL
|
|
86
|
+
PRISMA_PROVIDER=postgresql node ./scripts/assemble-platform-schema.cjs
|
|
87
|
+
./node_modules/.bin/prisma validate --schema prisma/platform.schema.prisma
|
|
88
|
+
./node_modules/.bin/prisma generate --schema prisma/platform.schema.prisma
|
|
89
|
+
|
|
90
|
+
# MySQL: assemble a fresh schema before validating or generating its client
|
|
91
|
+
PRISMA_PROVIDER=mysql node ./scripts/assemble-platform-schema.cjs
|
|
92
|
+
./node_modules/.bin/prisma validate --schema prisma/platform.schema.prisma
|
|
93
|
+
./node_modules/.bin/prisma generate --schema prisma/platform.schema.prisma
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The generated client is written to `prisma/client/` as TypeScript source; import
|
|
97
|
+
`PrismaClient` from `./prisma/client/client` (adjust the relative path), not from
|
|
98
|
+
`@prisma/client`. Migrations and `db push` read the connection URL from your
|
|
99
|
+
`prisma.config.ts` (`datasource.url`), not from the schema. See the
|
|
100
|
+
`@nathapp/nestjs-prisma` README, "Prisma 7 setup".
|
|
101
|
+
|
|
102
|
+
The commands save a testable assembly script and run it for each provider.
|
|
103
|
+
PostgreSQL keeps
|
|
104
|
+
the published `@db.Timestamptz(6)` annotations. MySQL assembly changes only that
|
|
105
|
+
native annotation to `@db.DateTime(6)`; the model bodies and their relations stay
|
|
106
|
+
the same. Validate and generate with the local Prisma 7 CLI installed by your
|
|
107
|
+
application (`./node_modules/.bin/prisma`); these commands do not need an
|
|
108
|
+
`npx` download fallback.
|
|
109
|
+
|
|
110
|
+
MySQL `DateTime(6)` stores a wall-clock value without timezone metadata. Keep
|
|
111
|
+
application values and MySQL sessions on UTC (`time_zone = '+00:00'`) so Prisma
|
|
112
|
+
round-trips UTC instants consistently. Before migrating existing local wall-clock
|
|
113
|
+
values, determine their original timezone and convert them using a consumer
|
|
114
|
+
specific migration; do not relabel them as UTC in bulk. All fragments and SQL
|
|
115
|
+
files are inputs to consumer-owned schemas and migrations; this adapter does not
|
|
116
|
+
apply migrations for you.
|
|
117
|
+
|
|
118
|
+
## Consumer migrations
|
|
119
|
+
|
|
120
|
+
### Primary identity invariant
|
|
121
|
+
|
|
122
|
+
Primary identity status is scoped by (tenant_id, user_id). The reference DDL is in prisma/sql/primary-identity.postgresql.sql and prisma/sql/primary-identity.mysql.sql; copy the statement for your database into your own migration after confirming the physical table and identifier definitions in your assembled schema. These files are reference SQL, not migrations that the adapter runs for you.
|
|
123
|
+
|
|
124
|
+
Before enabling the index, run the commented GROUP BY tenant_id, user_id HAVING COUNT(*) > 1 preflight in the chosen SQL file. If it returns rows, stop and have an operator choose which identity remains primary; the preflight does not choose or update a winner. Quiesce primary-identity writes from preflight through successful index creation. If index creation fails, rerun preflight after resolving the cause and before retrying. Deploy the clear-before-set DefaultIdentityService.setPrimary implementation before enabling the index, and ensure PrismaModule.forRoot({ transaction: true }) supplies a real interactive transaction. The service re-reads and validates the target inside the transaction, reads its siblings, clears any current primary in the same tenant, then sets the target. When no transaction manager is configured it keeps the warning-backed sequential fallback, which is non-atomic.
|
|
125
|
+
|
|
126
|
+
Keep full tenant_id and user_id comparisons in the unique index. Do not replace it with a normal unique (tenant_id, user_id, is_primary) key; that would allow only one secondary identity per user. Preserve these custom indexes in future consumer migrations.
|
|
127
|
+
|
|
128
|
+
Run the real PostgreSQL 16 and MySQL 8.0 acceptance suites locally with Docker: npm run test:db --workspace=@nathapp/nestjs-iam-prisma. Explicit runs fail when Docker is unavailable.
|
|
129
|
+
|
|
130
|
+
### Long-text columns (MySQL)
|
|
131
|
+
|
|
132
|
+
A bare `String` maps to `VARCHAR(191)` on MySQL. Columns whose values can exceed
|
|
133
|
+
that now carry `@db.Text`: the SSO account's encrypted access/refresh tokens, the
|
|
134
|
+
SSO provider's `issuer`, encrypted client secret and `redirect_uri`, session and
|
|
135
|
+
login-history `user_agent`, and `avatar_url`. Before this, an SSO login with a
|
|
136
|
+
JWT-sized IdP token failed on MySQL. Upgrade a MySQL database built from an
|
|
137
|
+
earlier fragment with `prisma/sql/long-text-columns.mysql.sql`. PostgreSQL needs
|
|
138
|
+
nothing: `String` is already `text` there.
|
|
139
|
+
|
|
140
|
+
### API-key scopes
|
|
141
|
+
|
|
142
|
+
The shipped `ApiKey` fragment stores `scopes` as `Json @default("[]")`. The
|
|
143
|
+
domain API remains `string[]`; the adapter accepts only a native JSON array of
|
|
144
|
+
strings. Do not keep `String[]` in a custom `ApiKey` model or pass JSON text to
|
|
145
|
+
the adapter.
|
|
146
|
+
|
|
147
|
+
For a new install, assemble the updated fragment into your schema and generate
|
|
148
|
+
the Prisma client before deploying this adapter. For an existing PostgreSQL
|
|
149
|
+
database, copy `prisma/sql/api-key-scopes.postgresql.sql` into your own
|
|
150
|
+
migration, review the physical table and column names, and run it before
|
|
151
|
+
deploying the regenerated client and adapter. The file is reference SQL; the
|
|
152
|
+
adapter never runs consumer migrations.
|
|
153
|
+
|
|
154
|
+
The PostgreSQL conversion takes an `ACCESS EXCLUSIVE` table lock for its
|
|
155
|
+
transaction. Schedule a maintenance window, stop API-key writes, and rehearse
|
|
156
|
+
the migration against a recent database copy. Its preflight rejects NULL scope
|
|
157
|
+
arrays and arrays containing NULL entries. Resolve those rows explicitly before
|
|
158
|
+
retrying; the migration does not invent or discard grants. Valid arrays are
|
|
159
|
+
converted with `to_jsonb(scopes)`, preserving `[]`, `['read']`, and other
|
|
160
|
+
existing values, then the column receives a JSONB `[]` default and `NOT NULL`.
|
|
161
|
+
|
|
162
|
+
The old scalar-list client and the new JSON client are not interchangeable:
|
|
163
|
+
Prisma uses different operations for those field types. Apply the schema
|
|
164
|
+
migration, regenerate every consumer client, and deploy the adapter as one
|
|
165
|
+
coordinated cutover. If a maintenance window is not possible, use an
|
|
166
|
+
application-specific expand/contract plan with a shadow JSON column and dual
|
|
167
|
+
writes; retire every old client before cutting over. This adapter maps one
|
|
168
|
+
`scopes` column and does not provide the temporary dual-write path.
|
|
169
|
+
|
|
170
|
+
MySQL consumers can assemble the same `ApiKey` JSON model or update a custom
|
|
171
|
+
model to match it, then regenerate the client. With Prisma 7, the generated
|
|
172
|
+
MySQL table has `scopes JSON NOT NULL` but no SQL-level default; Prisma Client
|
|
173
|
+
applies the schema's `[]` default when a create call omits `scopes`. Raw SQL
|
|
174
|
+
inserts must supply the scopes value or add a consumer-owned MySQL default.
|
|
175
|
+
Consumers that omitted `ApiKey` from their schema must add the model and apply
|
|
176
|
+
their own schema migration before using the repository.
|
|
177
|
+
|
|
178
|
+
The `WebAuthnCredential` fragment is MySQL-portable only after a data migration.
|
|
179
|
+
These are fragments; **the adapter ships no migration** — you assemble them into
|
|
180
|
+
your own Prisma schema and migrations. Apply one authoritative sequence:
|
|
181
|
+
|
|
182
|
+
1. Add the `credential_id_hash` column.
|
|
183
|
+
2. Backfill `credential_id_hash`.
|
|
184
|
+
3. Set `credential_id_hash` NOT NULL.
|
|
185
|
+
4. Add the new unique index on `credential_id_hash`.
|
|
186
|
+
5. Drop the old unique object on `credential_id` (`webauthn_credentials_credential_id_key`).
|
|
187
|
+
6. Convert `credential_id` and `public_key` to `TEXT`.
|
|
188
|
+
|
|
189
|
+
MySQL:
|
|
190
|
+
|
|
191
|
+
```sql
|
|
192
|
+
ALTER TABLE webauthn_credentials
|
|
193
|
+
ADD COLUMN credential_id_hash VARCHAR(64) NULL;
|
|
194
|
+
|
|
195
|
+
UPDATE webauthn_credentials SET credential_id_hash = SHA2(credential_id, 256);
|
|
196
|
+
|
|
197
|
+
ALTER TABLE webauthn_credentials
|
|
198
|
+
MODIFY COLUMN credential_id_hash VARCHAR(64) NOT NULL;
|
|
199
|
+
|
|
200
|
+
ALTER TABLE webauthn_credentials
|
|
201
|
+
ADD UNIQUE INDEX webauthn_credentials_credential_id_hash_key (credential_id_hash);
|
|
202
|
+
|
|
203
|
+
ALTER TABLE webauthn_credentials
|
|
204
|
+
DROP INDEX webauthn_credentials_credential_id_key;
|
|
205
|
+
|
|
206
|
+
ALTER TABLE webauthn_credentials
|
|
207
|
+
MODIFY COLUMN credential_id TEXT NOT NULL,
|
|
208
|
+
MODIFY COLUMN public_key TEXT NOT NULL;
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
PostgreSQL:
|
|
212
|
+
|
|
213
|
+
```sql
|
|
214
|
+
ALTER TABLE webauthn_credentials ADD COLUMN credential_id_hash varchar(64);
|
|
215
|
+
UPDATE webauthn_credentials SET credential_id_hash = encode(sha256(convert_to(credential_id, 'UTF8')), 'hex');
|
|
216
|
+
ALTER TABLE webauthn_credentials ALTER COLUMN credential_id_hash SET NOT NULL;
|
|
217
|
+
CREATE UNIQUE INDEX "webauthn_credentials_credential_id_hash_key" ON webauthn_credentials (credential_id_hash);
|
|
218
|
+
DROP INDEX "webauthn_credentials_credential_id_key";
|
|
219
|
+
ALTER TABLE webauthn_credentials ALTER COLUMN credential_id TYPE text, ALTER COLUMN public_key TYPE text;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Ordering matters.** Backfill `credential_id_hash` **BEFORE** adding the NOT NULL
|
|
223
|
+
constraint and **BEFORE** the new unique index — not after. Create the new unique
|
|
224
|
+
index **BEFORE** dropping the old one: adding NOT NULL before the backfill fails on
|
|
225
|
+
existing rows, and dropping the old unique index before the new one exists leaves
|
|
226
|
+
the table without a credential-ID uniqueness guarantee. Backfill with
|
|
227
|
+
`convert_to(credential_id, 'UTF8')` on PostgreSQL, not `credential_id::bytea`: the
|
|
228
|
+
`bytea` cast interprets backslash escapes instead of hashing the text's bytes.
|
|
229
|
+
|
|
230
|
+
On MySQL the old unique index must also be dropped **BEFORE**
|
|
231
|
+
`credential_id` is converted to `TEXT`: MySQL rejects altering an indexed column to
|
|
232
|
+
`TEXT` while its single-column index still exists (error 1170).
|
|
233
|
+
|
|
234
|
+
The old unique object is Prisma's default `@map("credential_id")` name,
|
|
235
|
+
`webauthn_credentials_credential_id_key`, and Prisma Migrate emits it as a unique
|
|
236
|
+
index on both engines (so PostgreSQL uses a standalone `DROP INDEX`, not `ALTER TABLE ... DROP CONSTRAINT`; `ALTER TABLE ... DROP INDEX` is MySQL-only syntax). If
|
|
237
|
+
the database predates Prisma's naming convention, confirm the object name first
|
|
238
|
+
(`SHOW INDEX FROM webauthn_credentials` on MySQL; `\d webauthn_credentials` on
|
|
239
|
+
PostgreSQL).
|
|
240
|
+
|
|
241
|
+
`credential_id_hash` is **SHA-256 hex** (64 characters, `VARCHAR(64)`). Backfill it
|
|
242
|
+
with `SHA2(credential_id, 256)` on MySQL or
|
|
243
|
+
`encode(sha256(convert_to(credential_id, 'UTF8')), 'hex')` on PostgreSQL.
|
|
244
|
+
|
|
245
|
+
Direct `findUnique({ where: { credentialId } })` queries no longer type-check or
|
|
246
|
+
work — the old `credential_id` unique index is gone. Use `findByCredentialId`,
|
|
247
|
+
which looks up by hash, falls back to the raw column, and back-fills the hash on
|
|
248
|
+
read.
|
|
249
|
+
|
|
250
|
+
## Register
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
import { Module } from '@nestjs/common';
|
|
254
|
+
import { PrismaPg } from '@prisma/adapter-pg'; // MySQL: PrismaMariaDb from '@prisma/adapter-mariadb' (host/port/user/password/database, no connectionString)
|
|
255
|
+
import { PrismaClient } from './generated/prisma/client'; // your generator `output`
|
|
256
|
+
import { ClockModule } from '@nathapp/nestjs-common';
|
|
257
|
+
import { PrismaModule } from '@nathapp/nestjs-prisma';
|
|
258
|
+
import { IamPrismaModule } from '@nathapp/nestjs-iam-prisma';
|
|
259
|
+
|
|
260
|
+
@Module({
|
|
261
|
+
imports: [
|
|
262
|
+
PrismaModule.forRoot({
|
|
263
|
+
client: PrismaClient,
|
|
264
|
+
clientOptions: { adapter: new PrismaPg({ connectionString: process.env.DATABASE_URL! }) },
|
|
265
|
+
transaction: true,
|
|
266
|
+
}),
|
|
267
|
+
ClockModule.register(), // provides CLOCK, required by PrismaSessionRepository
|
|
268
|
+
IamPrismaModule.register(),
|
|
269
|
+
],
|
|
270
|
+
})
|
|
271
|
+
export class AppModule {}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
`ClockModule.register()` is not optional for this adapter.
|
|
275
|
+
`PrismaSessionRepository` injects `CLOCK` non-optionally for revocation timestamps
|
|
276
|
+
and expired-session sweeps, and no library package in this platform provides it
|
|
277
|
+
for you — omit it and Nest reports
|
|
278
|
+
`Nest can't resolve dependencies of the PrismaSessionRepository (Symbol(TRANSACTION_MANAGER), ?)`.
|
|
279
|
+
Please make sure that the argument Symbol(CLOCK) at index [1] is available in the
|
|
280
|
+
IamPrismaModule module.
|
|
281
|
+
|
|
282
|
+
`register()` takes an optional options object:
|
|
283
|
+
|
|
284
|
+
| Option | Type | Default | Meaning |
|
|
285
|
+
|---|---|---|---|
|
|
286
|
+
| `global` | `boolean` | `true` | Register as a global module so the repository tokens resolve anywhere. |
|
|
287
|
+
|
|
288
|
+
`register()` is the only import form for this adapter. There is no `registerAsync`.
|
|
289
|
+
|
|
290
|
+
### If you already wrap this adapter in `@Global()`
|
|
291
|
+
|
|
292
|
+
Pass `global: false`. Otherwise the adapter's own global exports are injected
|
|
293
|
+
**in addition to** your override, and last-registration-wins silently decides
|
|
294
|
+
which implementation is used:
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
import { Global, Module } from '@nestjs/common';
|
|
298
|
+
import { ClockModule } from '@nathapp/nestjs-common';
|
|
299
|
+
import { USER_REPOSITORY } from '@nathapp/nestjs-iam';
|
|
300
|
+
import { IamPrismaModule } from '@nathapp/nestjs-iam-prisma';
|
|
301
|
+
import { CachedUserRepository } from './cached-user.repository';
|
|
302
|
+
|
|
303
|
+
@Global()
|
|
304
|
+
@Module({
|
|
305
|
+
imports: [
|
|
306
|
+
ClockModule.register(), // required by PrismaSessionRepository
|
|
307
|
+
IamPrismaModule.register({ global: false }),
|
|
308
|
+
],
|
|
309
|
+
providers: [{ provide: USER_REPOSITORY, useClass: CachedUserRepository }],
|
|
310
|
+
exports: [USER_REPOSITORY],
|
|
311
|
+
})
|
|
312
|
+
export class PrismaOverridesModule {}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
`global: false` only helps if the adapter is registered once. A second, global
|
|
316
|
+
`register()` elsewhere in the app keeps its global exports, and `global: false`
|
|
317
|
+
here does not remove them — so the collision this section exists to prevent is
|
|
318
|
+
still there. Register the adapter in exactly one place.
|
|
319
|
+
|
|
320
|
+
The `global` option carries no documentation in the published type definitions
|
|
321
|
+
(`removeComments: true` strips the JSDoc from the emitted `.d.ts`), so this README
|
|
322
|
+
is where it is described. The options object is typed as `PrismaAdapterModuleOptions`,
|
|
323
|
+
which is exported from this package if you need to name the type.
|
|
324
|
+
|
|
325
|
+
## Transactions
|
|
326
|
+
|
|
327
|
+
Multi-write flows need `PrismaModule.forRoot({ client: PrismaClient, transaction: true })`
|
|
328
|
+
with `PrismaClient` imported from your generated client (Prisma 7 `prisma-client` generator).
|
|
329
|
+
Every repository resolves its client per operation from the `TRANSACTION_MANAGER`
|
|
330
|
+
token, and the two `PrismaModule` registration paths fail differently when
|
|
331
|
+
`transaction` is omitted:
|
|
332
|
+
|
|
333
|
+
- `PrismaModule.forRoot()` binds `TRANSACTION_MANAGER` only when `transaction: true`
|
|
334
|
+
is set. Without it nothing is bound, the repositories cannot resolve their
|
|
335
|
+
dependency, and Nest fails at boot.
|
|
336
|
+
- `PrismaModule.forRootAsync()` always binds the token, but with a manager whose
|
|
337
|
+
`run()` and `getClient()` throw and whose `isInTransaction()` returns `false`, so
|
|
338
|
+
the app boots and fails on first use instead.
|
|
339
|
+
|
|
340
|
+
Neither path is a silent passthrough: a real transaction manager either joins the
|
|
341
|
+
transaction already in scope or opens a Prisma interactive transaction.
|
|
342
|
+
|
|
343
|
+
Both of those are `PrismaModule` from `@nathapp/nestjs-prisma`. These adapters
|
|
344
|
+
expose only the synchronous `register()`; they have no `registerAsync`.
|
|
345
|
+
|
|
346
|
+
`DefaultUserService.register()` is the case that matters most: it creates a
|
|
347
|
+
`User` and a `UserIdentity` in two repository calls, and only rolls them back
|
|
348
|
+
together when `run()` is backed by a real interactive transaction.
|
|
349
|
+
|
|
350
|
+
## Tokens bound
|
|
351
|
+
|
|
352
|
+
| Token | Implementation |
|
|
353
|
+
|---|---|
|
|
354
|
+
| `USER_REPOSITORY` | `PrismaUserRepository` |
|
|
355
|
+
| `USER_IDENTITY_REPOSITORY` | `PrismaIdentityRepository` |
|
|
356
|
+
| `SESSION_REPOSITORY` | `PrismaSessionRepository` |
|
|
357
|
+
| `MFA_REPOSITORY` | `PrismaMfaRepository` |
|
|
358
|
+
| `SSO_ACCOUNT_REPOSITORY` | `PrismaSsoAccountRepository` |
|
|
359
|
+
| `SSO_PROVIDER_REPOSITORY` | `PrismaSsoProviderRepository` |
|
|
360
|
+
| `LOGIN_HISTORY_REPOSITORY` | `PrismaLoginHistoryRepository` |
|
|
361
|
+
| `VERIFICATION_TOKEN_REPOSITORY` | `PrismaVerificationTokenRepository` |
|
|
362
|
+
| `API_KEY_REPOSITORY` | `PrismaApiKeyRepository` |
|
|
363
|
+
| `WEBAUTHN_CREDENTIAL_REPOSITORY` | `PrismaWebAuthnCredentialRepository` |
|
|
364
|
+
| `WEBAUTHN_MFA_BINDING_STORE` | `PrismaWebAuthnMfaBindingStore` |
|
|
365
|
+
| `TOTP_REPLAY_STORE` | `PrismaTotpReplayStore` |
|
|
366
|
+
| `AUTH_ATTEMPT_STORE` | `PrismaAuthAttemptStore` |
|
|
367
|
+
|
|
368
|
+
The last three are store seams rather than repositories — they back the
|
|
369
|
+
WebAuthn MFA binding lookup, TOTP replay detection, and failed-verification
|
|
370
|
+
attempt counting (which trips `VERIFICATION_RATE_LIMIT`) respectively.
|
|
371
|
+
|
|
372
|
+
`PrismaSsoAccountRepository` reads and writes `accessTokenEnc` / `refreshTokenEnc`
|
|
373
|
+
exclusively; the unencrypted `accessToken` / `refreshToken` keys are not used.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hashCredentialId(credentialId: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashCredentialId = hashCredentialId;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
function hashCredentialId(credentialId) {
|
|
6
|
+
return (0, node_crypto_1.createHash)('sha256').update(credentialId).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=credential-id-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential-id-hash.js","sourceRoot":"","sources":["../lib/credential-id-hash.ts"],"names":[],"mappings":";;AAcA,4CAEC;AAhBD,6CAAyC;AAczC,SAAgB,gBAAgB,CAAC,YAAoB;IACnD,OAAO,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var IamPrismaModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.IamPrismaModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const nestjs_iam_1 = require("@nathapp/nestjs-iam");
|
|
13
|
+
const prisma_user_repository_1 = require("./prisma-user.repository");
|
|
14
|
+
const prisma_identity_repository_1 = require("./prisma-identity.repository");
|
|
15
|
+
const prisma_session_repository_1 = require("./prisma-session.repository");
|
|
16
|
+
const prisma_mfa_repository_1 = require("./prisma-mfa.repository");
|
|
17
|
+
const prisma_sso_account_repository_1 = require("./prisma-sso-account.repository");
|
|
18
|
+
const prisma_sso_provider_repository_1 = require("./prisma-sso-provider.repository");
|
|
19
|
+
const prisma_login_history_repository_1 = require("./prisma-login-history.repository");
|
|
20
|
+
const prisma_verification_token_repository_1 = require("./prisma-verification-token.repository");
|
|
21
|
+
const prisma_api_key_repository_1 = require("./prisma-api-key.repository");
|
|
22
|
+
const prisma_webauthn_credential_repository_1 = require("./prisma-webauthn-credential.repository");
|
|
23
|
+
const prisma_webauthn_mfa_binding_store_1 = require("./prisma-webauthn-mfa-binding.store");
|
|
24
|
+
const prisma_totp_replay_store_1 = require("./prisma-totp-replay.store");
|
|
25
|
+
const prisma_auth_attempt_store_1 = require("./prisma-auth-attempt.store");
|
|
26
|
+
let IamPrismaModule = IamPrismaModule_1 = class IamPrismaModule {
|
|
27
|
+
static register(options) {
|
|
28
|
+
var _a;
|
|
29
|
+
return {
|
|
30
|
+
module: IamPrismaModule_1,
|
|
31
|
+
global: (_a = options === null || options === void 0 ? void 0 : options.global) !== null && _a !== void 0 ? _a : true,
|
|
32
|
+
providers: [
|
|
33
|
+
prisma_user_repository_1.PrismaUserRepository,
|
|
34
|
+
{ provide: nestjs_iam_1.USER_REPOSITORY, useExisting: prisma_user_repository_1.PrismaUserRepository },
|
|
35
|
+
prisma_identity_repository_1.PrismaIdentityRepository,
|
|
36
|
+
{ provide: nestjs_iam_1.USER_IDENTITY_REPOSITORY, useExisting: prisma_identity_repository_1.PrismaIdentityRepository },
|
|
37
|
+
prisma_session_repository_1.PrismaSessionRepository,
|
|
38
|
+
{ provide: nestjs_iam_1.SESSION_REPOSITORY, useExisting: prisma_session_repository_1.PrismaSessionRepository },
|
|
39
|
+
prisma_mfa_repository_1.PrismaMfaRepository,
|
|
40
|
+
{ provide: nestjs_iam_1.MFA_REPOSITORY, useExisting: prisma_mfa_repository_1.PrismaMfaRepository },
|
|
41
|
+
prisma_sso_account_repository_1.PrismaSsoAccountRepository,
|
|
42
|
+
{ provide: nestjs_iam_1.SSO_ACCOUNT_REPOSITORY, useExisting: prisma_sso_account_repository_1.PrismaSsoAccountRepository },
|
|
43
|
+
prisma_sso_provider_repository_1.PrismaSsoProviderRepository,
|
|
44
|
+
{ provide: nestjs_iam_1.SSO_PROVIDER_REPOSITORY, useExisting: prisma_sso_provider_repository_1.PrismaSsoProviderRepository },
|
|
45
|
+
prisma_login_history_repository_1.PrismaLoginHistoryRepository,
|
|
46
|
+
{ provide: nestjs_iam_1.LOGIN_HISTORY_REPOSITORY, useExisting: prisma_login_history_repository_1.PrismaLoginHistoryRepository },
|
|
47
|
+
prisma_verification_token_repository_1.PrismaVerificationTokenRepository,
|
|
48
|
+
{ provide: nestjs_iam_1.VERIFICATION_TOKEN_REPOSITORY, useExisting: prisma_verification_token_repository_1.PrismaVerificationTokenRepository },
|
|
49
|
+
prisma_api_key_repository_1.PrismaApiKeyRepository,
|
|
50
|
+
{ provide: nestjs_iam_1.API_KEY_REPOSITORY, useExisting: prisma_api_key_repository_1.PrismaApiKeyRepository },
|
|
51
|
+
prisma_webauthn_credential_repository_1.PrismaWebAuthnCredentialRepository,
|
|
52
|
+
{ provide: nestjs_iam_1.WEBAUTHN_CREDENTIAL_REPOSITORY, useExisting: prisma_webauthn_credential_repository_1.PrismaWebAuthnCredentialRepository },
|
|
53
|
+
prisma_webauthn_mfa_binding_store_1.PrismaWebAuthnMfaBindingStore,
|
|
54
|
+
{ provide: nestjs_iam_1.WEBAUTHN_MFA_BINDING_STORE, useExisting: prisma_webauthn_mfa_binding_store_1.PrismaWebAuthnMfaBindingStore },
|
|
55
|
+
prisma_totp_replay_store_1.PrismaTotpReplayStore,
|
|
56
|
+
{ provide: nestjs_iam_1.TOTP_REPLAY_STORE, useExisting: prisma_totp_replay_store_1.PrismaTotpReplayStore },
|
|
57
|
+
prisma_auth_attempt_store_1.PrismaAuthAttemptStore,
|
|
58
|
+
{ provide: nestjs_iam_1.AUTH_ATTEMPT_STORE, useExisting: prisma_auth_attempt_store_1.PrismaAuthAttemptStore },
|
|
59
|
+
],
|
|
60
|
+
exports: [
|
|
61
|
+
nestjs_iam_1.USER_REPOSITORY, nestjs_iam_1.USER_IDENTITY_REPOSITORY, nestjs_iam_1.SESSION_REPOSITORY, nestjs_iam_1.MFA_REPOSITORY,
|
|
62
|
+
nestjs_iam_1.SSO_ACCOUNT_REPOSITORY, nestjs_iam_1.SSO_PROVIDER_REPOSITORY, nestjs_iam_1.LOGIN_HISTORY_REPOSITORY,
|
|
63
|
+
nestjs_iam_1.VERIFICATION_TOKEN_REPOSITORY, nestjs_iam_1.API_KEY_REPOSITORY, nestjs_iam_1.WEBAUTHN_CREDENTIAL_REPOSITORY,
|
|
64
|
+
nestjs_iam_1.WEBAUTHN_MFA_BINDING_STORE, nestjs_iam_1.TOTP_REPLAY_STORE, nestjs_iam_1.AUTH_ATTEMPT_STORE,
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.IamPrismaModule = IamPrismaModule;
|
|
70
|
+
exports.IamPrismaModule = IamPrismaModule = IamPrismaModule_1 = __decorate([
|
|
71
|
+
(0, common_1.Module)({})
|
|
72
|
+
], IamPrismaModule);
|
|
73
|
+
//# sourceMappingURL=iam-prisma.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-prisma.module.js","sourceRoot":"","sources":["../lib/iam-prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,oDAK6B;AAC7B,qEAAgE;AAChE,6EAAwE;AACxE,2EAAsE;AACtE,mEAA8D;AAC9D,mFAA6E;AAC7E,qFAA+E;AAC/E,uFAAiF;AACjF,iGAA2F;AAC3F,2EAAqE;AACrE,mGAA6F;AAC7F,2FAAoF;AACpF,yEAAmE;AACnE,2EAAqE;AAoB9D,IAAM,eAAe,uBAArB,MAAM,eAAe;IAC1B,MAAM,CAAC,QAAQ,CAAC,OAAoC;;QAClD,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,MAAM,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,IAAI;YAC/B,SAAS,EAAE;gBACT,6CAAoB;gBACpB,EAAE,OAAO,EAAE,4BAAe,EAAE,WAAW,EAAE,6CAAoB,EAAE;gBAC/D,qDAAwB;gBACxB,EAAE,OAAO,EAAE,qCAAwB,EAAE,WAAW,EAAE,qDAAwB,EAAE;gBAC5E,mDAAuB;gBACvB,EAAE,OAAO,EAAE,+BAAkB,EAAE,WAAW,EAAE,mDAAuB,EAAE;gBACrE,2CAAmB;gBACnB,EAAE,OAAO,EAAE,2BAAc,EAAE,WAAW,EAAE,2CAAmB,EAAE;gBAC7D,0DAA0B;gBAC1B,EAAE,OAAO,EAAE,mCAAsB,EAAE,WAAW,EAAE,0DAA0B,EAAE;gBAC5E,4DAA2B;gBAC3B,EAAE,OAAO,EAAE,oCAAuB,EAAE,WAAW,EAAE,4DAA2B,EAAE;gBAC9E,8DAA4B;gBAC5B,EAAE,OAAO,EAAE,qCAAwB,EAAE,WAAW,EAAE,8DAA4B,EAAE;gBAChF,wEAAiC;gBACjC,EAAE,OAAO,EAAE,0CAA6B,EAAE,WAAW,EAAE,wEAAiC,EAAE;gBAC1F,kDAAsB;gBACtB,EAAE,OAAO,EAAE,+BAAkB,EAAE,WAAW,EAAE,kDAAsB,EAAE;gBACpE,0EAAkC;gBAClC,EAAE,OAAO,EAAE,2CAA8B,EAAE,WAAW,EAAE,0EAAkC,EAAE;gBAC5F,iEAA6B;gBAC7B,EAAE,OAAO,EAAE,uCAA0B,EAAE,WAAW,EAAE,iEAA6B,EAAE;gBACnF,gDAAqB;gBACrB,EAAE,OAAO,EAAE,8BAAiB,EAAE,WAAW,EAAE,gDAAqB,EAAE;gBAClE,kDAAsB;gBACtB,EAAE,OAAO,EAAE,+BAAkB,EAAE,WAAW,EAAE,kDAAsB,EAAE;aACrE;YACD,OAAO,EAAE;gBACP,4BAAe,EAAE,qCAAwB,EAAE,+BAAkB,EAAE,2BAAc;gBAC7E,mCAAsB,EAAE,oCAAuB,EAAE,qCAAwB;gBACzE,0CAA6B,EAAE,+BAAkB,EAAE,2CAA8B;gBACjF,uCAA0B,EAAE,8BAAiB,EAAE,+BAAkB;aAClE;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAzCY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,eAAe,CAyC3B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from '@nathapp/nestjs-iam';
|
|
2
|
+
export { PrismaUserRepository } from './prisma-user.repository';
|
|
3
|
+
export { PrismaIdentityRepository } from './prisma-identity.repository';
|
|
4
|
+
export { PrismaSessionRepository } from './prisma-session.repository';
|
|
5
|
+
export { PrismaMfaRepository } from './prisma-mfa.repository';
|
|
6
|
+
export { PrismaSsoAccountRepository } from './prisma-sso-account.repository';
|
|
7
|
+
export { PrismaSsoProviderRepository } from './prisma-sso-provider.repository';
|
|
8
|
+
export { PrismaLoginHistoryRepository } from './prisma-login-history.repository';
|
|
9
|
+
export { PrismaVerificationTokenRepository } from './prisma-verification-token.repository';
|
|
10
|
+
export { PrismaApiKeyRepository } from './prisma-api-key.repository';
|
|
11
|
+
export { PrismaWebAuthnCredentialRepository } from './prisma-webauthn-credential.repository';
|
|
12
|
+
export { PrismaWebAuthnMfaBindingStore } from './prisma-webauthn-mfa-binding.store';
|
|
13
|
+
export { PrismaTotpReplayStore } from './prisma-totp-replay.store';
|
|
14
|
+
export { PrismaAuthAttemptStore } from './prisma-auth-attempt.store';
|
|
15
|
+
export { IamPrismaModule, type PrismaAdapterModuleOptions } from './iam-prisma.module';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.IamPrismaModule = exports.PrismaAuthAttemptStore = exports.PrismaTotpReplayStore = exports.PrismaWebAuthnMfaBindingStore = exports.PrismaWebAuthnCredentialRepository = exports.PrismaApiKeyRepository = exports.PrismaVerificationTokenRepository = exports.PrismaLoginHistoryRepository = exports.PrismaSsoProviderRepository = exports.PrismaSsoAccountRepository = exports.PrismaMfaRepository = exports.PrismaSessionRepository = exports.PrismaIdentityRepository = exports.PrismaUserRepository = void 0;
|
|
18
|
+
__exportStar(require("@nathapp/nestjs-iam"), exports);
|
|
19
|
+
var prisma_user_repository_1 = require("./prisma-user.repository");
|
|
20
|
+
Object.defineProperty(exports, "PrismaUserRepository", { enumerable: true, get: function () { return prisma_user_repository_1.PrismaUserRepository; } });
|
|
21
|
+
var prisma_identity_repository_1 = require("./prisma-identity.repository");
|
|
22
|
+
Object.defineProperty(exports, "PrismaIdentityRepository", { enumerable: true, get: function () { return prisma_identity_repository_1.PrismaIdentityRepository; } });
|
|
23
|
+
var prisma_session_repository_1 = require("./prisma-session.repository");
|
|
24
|
+
Object.defineProperty(exports, "PrismaSessionRepository", { enumerable: true, get: function () { return prisma_session_repository_1.PrismaSessionRepository; } });
|
|
25
|
+
var prisma_mfa_repository_1 = require("./prisma-mfa.repository");
|
|
26
|
+
Object.defineProperty(exports, "PrismaMfaRepository", { enumerable: true, get: function () { return prisma_mfa_repository_1.PrismaMfaRepository; } });
|
|
27
|
+
var prisma_sso_account_repository_1 = require("./prisma-sso-account.repository");
|
|
28
|
+
Object.defineProperty(exports, "PrismaSsoAccountRepository", { enumerable: true, get: function () { return prisma_sso_account_repository_1.PrismaSsoAccountRepository; } });
|
|
29
|
+
var prisma_sso_provider_repository_1 = require("./prisma-sso-provider.repository");
|
|
30
|
+
Object.defineProperty(exports, "PrismaSsoProviderRepository", { enumerable: true, get: function () { return prisma_sso_provider_repository_1.PrismaSsoProviderRepository; } });
|
|
31
|
+
var prisma_login_history_repository_1 = require("./prisma-login-history.repository");
|
|
32
|
+
Object.defineProperty(exports, "PrismaLoginHistoryRepository", { enumerable: true, get: function () { return prisma_login_history_repository_1.PrismaLoginHistoryRepository; } });
|
|
33
|
+
var prisma_verification_token_repository_1 = require("./prisma-verification-token.repository");
|
|
34
|
+
Object.defineProperty(exports, "PrismaVerificationTokenRepository", { enumerable: true, get: function () { return prisma_verification_token_repository_1.PrismaVerificationTokenRepository; } });
|
|
35
|
+
var prisma_api_key_repository_1 = require("./prisma-api-key.repository");
|
|
36
|
+
Object.defineProperty(exports, "PrismaApiKeyRepository", { enumerable: true, get: function () { return prisma_api_key_repository_1.PrismaApiKeyRepository; } });
|
|
37
|
+
var prisma_webauthn_credential_repository_1 = require("./prisma-webauthn-credential.repository");
|
|
38
|
+
Object.defineProperty(exports, "PrismaWebAuthnCredentialRepository", { enumerable: true, get: function () { return prisma_webauthn_credential_repository_1.PrismaWebAuthnCredentialRepository; } });
|
|
39
|
+
var prisma_webauthn_mfa_binding_store_1 = require("./prisma-webauthn-mfa-binding.store");
|
|
40
|
+
Object.defineProperty(exports, "PrismaWebAuthnMfaBindingStore", { enumerable: true, get: function () { return prisma_webauthn_mfa_binding_store_1.PrismaWebAuthnMfaBindingStore; } });
|
|
41
|
+
var prisma_totp_replay_store_1 = require("./prisma-totp-replay.store");
|
|
42
|
+
Object.defineProperty(exports, "PrismaTotpReplayStore", { enumerable: true, get: function () { return prisma_totp_replay_store_1.PrismaTotpReplayStore; } });
|
|
43
|
+
var prisma_auth_attempt_store_1 = require("./prisma-auth-attempt.store");
|
|
44
|
+
Object.defineProperty(exports, "PrismaAuthAttemptStore", { enumerable: true, get: function () { return prisma_auth_attempt_store_1.PrismaAuthAttemptStore; } });
|
|
45
|
+
var iam_prisma_module_1 = require("./iam-prisma.module");
|
|
46
|
+
Object.defineProperty(exports, "IamPrismaModule", { enumerable: true, get: function () { return iam_prisma_module_1.IamPrismaModule; } });
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,sDAAoC;AAGpC,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,yEAAsE;AAA7D,oIAAA,uBAAuB,OAAA;AAChC,iEAA8D;AAArD,4HAAA,mBAAmB,OAAA;AAC5B,iFAA6E;AAApE,2IAAA,0BAA0B,OAAA;AACnC,mFAA+E;AAAtE,6IAAA,2BAA2B,OAAA;AACpC,qFAAiF;AAAxE,+IAAA,4BAA4B,OAAA;AACrC,+FAA2F;AAAlF,yJAAA,iCAAiC,OAAA;AAC1C,yEAAqE;AAA5D,mIAAA,sBAAsB,OAAA;AAC/B,iGAA6F;AAApF,2JAAA,kCAAkC,OAAA;AAC3C,yFAAoF;AAA3E,kJAAA,6BAA6B,OAAA;AACtC,uEAAmE;AAA1D,iIAAA,qBAAqB,OAAA;AAC9B,yEAAqE;AAA5D,mIAAA,sBAAsB,OAAA;AAG/B,yDAAuF;AAA9E,oHAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AbstractPrismaRepository } from '@nathapp/nestjs-prisma';
|
|
2
|
+
import { ITransactionManager } from '@nathapp/nestjs-data';
|
|
3
|
+
import type { IPageOption } from '@nathapp/nestjs-common';
|
|
4
|
+
import type { IPageResult } from '@nathapp/nestjs-data';
|
|
5
|
+
import { IApiKeyRepository, ApiKey } from '@nathapp/nestjs-iam';
|
|
6
|
+
import type { PrismaClientLike } from '@nathapp/nestjs-prisma';
|
|
7
|
+
import type { ApiKeyRow } from './prisma-model.types';
|
|
8
|
+
export declare class PrismaApiKeyRepository extends AbstractPrismaRepository<ApiKey, ApiKeyRow, string> implements IApiKeyRepository {
|
|
9
|
+
constructor(tx: ITransactionManager);
|
|
10
|
+
protected modelDelegate(client: PrismaClientLike): import("./prisma-model.types").ConsumerModel<ApiKeyRow>;
|
|
11
|
+
protected toDomain(e: ApiKeyRow): ApiKey;
|
|
12
|
+
protected toPersistenceCreate(d: ApiKey): {
|
|
13
|
+
expiresAt?: Date | undefined;
|
|
14
|
+
id: string;
|
|
15
|
+
tenantId: string;
|
|
16
|
+
userId: string;
|
|
17
|
+
name: string;
|
|
18
|
+
prefix: string;
|
|
19
|
+
secretHash: string;
|
|
20
|
+
scopes: string[];
|
|
21
|
+
};
|
|
22
|
+
protected toPersistenceUpdate(p: Partial<ApiKey>): Record<string, unknown>;
|
|
23
|
+
findByPrefix(prefix: string): Promise<ApiKey | null>;
|
|
24
|
+
findByUser(userId: string, page: IPageOption): Promise<IPageResult<ApiKey>>;
|
|
25
|
+
update(idOrInput: string | {
|
|
26
|
+
id: string;
|
|
27
|
+
} & Partial<ApiKey>, patch?: Partial<ApiKey>): Promise<ApiKey>;
|
|
28
|
+
}
|