@nathapp/nestjs-account-prisma 0.0.0-stage → 1.0.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.
Files changed (58) hide show
  1. package/AGENTS.md +107 -0
  2. package/CLAUDE.md +105 -0
  3. package/GEMINI.md +105 -0
  4. package/README.md +143 -2
  5. package/codex.md +105 -0
  6. package/dist/account-prisma.module.d.ts +7 -0
  7. package/dist/account-prisma.module.js +78 -0
  8. package/dist/account-prisma.module.js.map +1 -0
  9. package/dist/index.d.ts +14 -0
  10. package/dist/index.js +45 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/prisma-account.repository.d.ts +24 -0
  13. package/dist/prisma-account.repository.js +99 -0
  14. package/dist/prisma-account.repository.js.map +1 -0
  15. package/dist/prisma-audit-log.repository.d.ts +41 -0
  16. package/dist/prisma-audit-log.repository.js +153 -0
  17. package/dist/prisma-audit-log.repository.js.map +1 -0
  18. package/dist/prisma-invitation.repository.d.ts +41 -0
  19. package/dist/prisma-invitation.repository.js +138 -0
  20. package/dist/prisma-invitation.repository.js.map +1 -0
  21. package/dist/prisma-membership-role.repository.d.ts +11 -0
  22. package/dist/prisma-membership-role.repository.js +80 -0
  23. package/dist/prisma-membership-role.repository.js.map +1 -0
  24. package/dist/prisma-membership.repository.d.ts +24 -0
  25. package/dist/prisma-membership.repository.js +75 -0
  26. package/dist/prisma-membership.repository.js.map +1 -0
  27. package/dist/prisma-model.types.d.ts +46 -0
  28. package/dist/prisma-model.types.js +20 -0
  29. package/dist/prisma-model.types.js.map +1 -0
  30. package/dist/prisma-onboarding-flow.repository.d.ts +23 -0
  31. package/dist/prisma-onboarding-flow.repository.js +75 -0
  32. package/dist/prisma-onboarding-flow.repository.js.map +1 -0
  33. package/dist/prisma-onboarding-progress.repository.d.ts +22 -0
  34. package/dist/prisma-onboarding-progress.repository.js +84 -0
  35. package/dist/prisma-onboarding-progress.repository.js.map +1 -0
  36. package/dist/prisma-ownership-transfer.repository.d.ts +33 -0
  37. package/dist/prisma-ownership-transfer.repository.js +95 -0
  38. package/dist/prisma-ownership-transfer.repository.js.map +1 -0
  39. package/dist/prisma-permission.repository.d.ts +14 -0
  40. package/dist/prisma-permission.repository.js +86 -0
  41. package/dist/prisma-permission.repository.js.map +1 -0
  42. package/dist/prisma-profile.repository.d.ts +23 -0
  43. package/dist/prisma-profile.repository.js +80 -0
  44. package/dist/prisma-profile.repository.js.map +1 -0
  45. package/dist/prisma-provider.d.ts +5 -0
  46. package/dist/prisma-provider.js +8 -0
  47. package/dist/prisma-provider.js.map +1 -0
  48. package/dist/prisma-role.repository.d.ts +27 -0
  49. package/dist/prisma-role.repository.js +109 -0
  50. package/dist/prisma-role.repository.js.map +1 -0
  51. package/dist/prisma-tenant-app.repository.d.ts +18 -0
  52. package/dist/prisma-tenant-app.repository.js +68 -0
  53. package/dist/prisma-tenant-app.repository.js.map +1 -0
  54. package/package.json +39 -4
  55. package/prisma/account.prisma +261 -0
  56. package/prisma/migrations/20260714_ownership_transfer_pending_unique/migration.mysql.sql +9 -0
  57. package/prisma/migrations/20260714_ownership_transfer_pending_unique/migration.sql +4 -0
  58. package/prisma/sql/long-text-columns.mysql.sql +13 -0
package/AGENTS.md ADDED
@@ -0,0 +1,107 @@
1
+ # Agent Instructions
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ These instructions apply to all AI coding agents in this project.
7
+
8
+ ---
9
+
10
+ ## Project Metadata
11
+
12
+ > Auto-injected by `nax generate`
13
+
14
+ **Project:** `@nathapp/nestjs-account-prisma`
15
+
16
+ **Language:** TypeScript
17
+
18
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
19
+
20
+ ---
21
+ # CLAUDE.md — @nathapp/nestjs-account-prisma
22
+
23
+ Prisma adapter for `@nathapp/nestjs-account`. Binds the 8 account repository
24
+ tokens to `AbstractPrismaRepository`-based implementations.
25
+
26
+ ## Status: ✅ Complete (all 8 repos on AbstractPrismaRepository)
27
+
28
+ ## Implemented Repositories
29
+
30
+ - `PrismaAccountRepository` → `IAccountRepository`
31
+ - `PrismaMembershipRepository` → `IMembershipRepository`
32
+ - `PrismaRoleRepository` → `IRoleRepository` (incl. `rolePermission` join table)
33
+ - `PrismaPermissionRepository` → `IPermissionRepository`
34
+ - `PrismaInvitationRepository` → `IInvitationRepository`
35
+ - `PrismaProfileRepository` → `IProfileRepository`
36
+ - `PrismaOnboardingFlowRepository` → `IOnboardingFlowRepository`
37
+ - `PrismaOnboardingProgressRepository` → `IOnboardingProgressRepository`
38
+
39
+ `AccountPrismaModule.register()` (no-arg) wires all 8 tokens to the concrete
40
+ implementations via `useExisting`.
41
+
42
+ ## Onboarding Repository Split
43
+
44
+ Onboarding was previously a single `ONBOARDING_REPOSITORY` token backed by one
45
+ class handling both flow + progress aggregates. It is now split:
46
+
47
+ - `ONBOARDING_FLOW_REPOSITORY` — `IOnboardingFlowRepository` (flow definitions)
48
+ - `ONBOARDING_PROGRESS_REPOSITORY` — `IOnboardingProgressRepository` (per-account progress + step merges)
49
+
50
+ Both extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`.
51
+
52
+ ## Wiring (Consumer App)
53
+
54
+ The consumer app must register `PrismaModule.forRoot({ transaction: true })` so
55
+ `TRANSACTION_MANAGER` is bound. `AccountPrismaModule` then resolves the
56
+ transaction-aware client per operation via `tx.getClient()`:
57
+
58
+ ```typescript
59
+ import { PrismaModule } from '@nathapp/nestjs-prisma';
60
+ import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
61
+
62
+ @Module({
63
+ imports: [
64
+ PrismaModule.forRoot({ client: PrismaClient, transaction: true }),
65
+ AccountPrismaModule.register(),
66
+ ],
67
+ })
68
+ export class AppModule {}
69
+ ```
70
+
71
+ ## Repository Pattern
72
+
73
+ All 8 repositories extend `AbstractPrismaRepository<TDomain, any, string>`
74
+ (from `@nathapp/nestjs-prisma`), providing:
75
+
76
+ - `modelDelegate(client)` — Prisma model accessor (e.g. `client.account`)
77
+ - `toDomain(e)` — persistence row → domain
78
+ - `toPersistenceCreate(d)` — domain → Prisma create input (omits `createdAt`/`updatedAt`)
79
+ - `toPersistenceUpdate(p)` — partial domain → Prisma update input
80
+
81
+ They inherit `findById`, `findOne`, `findAll`, `count`, `create`, `update`,
82
+ `delete` from the base class — all transaction-aware.
83
+
84
+ ## Dependencies
85
+
86
+ - `@nathapp/nestjs-account` (workspace)
87
+ - `@nathapp/nestjs-data` ^3.2.0 (peer)
88
+ - `@nathapp/nestjs-prisma` ^3.2.0 (peer)
89
+ - `@prisma/client` ^6.0.0 (peer)
90
+
91
+ ## Schema conventions
92
+
93
+ All `DateTime` fields in the consumer's `schema.prisma` for account models (Account, Membership, Role, Permission, Invitation, Profile, OnboardingFlow, OnboardingProgress) MUST use `@db.Timestamptz(6)`:
94
+
95
+ ```prisma
96
+ createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
97
+ updatedAt DateTime @db.Timestamptz(6) @updatedAt @map("updated_at")
98
+ expiresAt DateTime @db.Timestamptz(6) @map("expires_at")
99
+ ```
100
+
101
+ This maps to PostgreSQL `timestamptz`, which stores UTC and converts correctly regardless of DB server timezone. Bare `DateTime` (maps to `timestamp without time zone`) is NOT correct for this platform.
102
+
103
+ When migrating an existing database:
104
+ ```sql
105
+ ALTER TABLE <table> ALTER COLUMN <col> TYPE TIMESTAMPTZ(6) USING <col> AT TIME ZONE 'UTC';
106
+ ```
107
+ Run one statement per column. Verify `SHOW timezone;` returns `UTC` before migrating production data.
package/CLAUDE.md ADDED
@@ -0,0 +1,105 @@
1
+ # Project Context
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ ---
7
+
8
+ ## Project Metadata
9
+
10
+ > Auto-injected by `nax generate`
11
+
12
+ **Project:** `@nathapp/nestjs-account-prisma`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
17
+
18
+ ---
19
+ # CLAUDE.md — @nathapp/nestjs-account-prisma
20
+
21
+ Prisma adapter for `@nathapp/nestjs-account`. Binds the 8 account repository
22
+ tokens to `AbstractPrismaRepository`-based implementations.
23
+
24
+ ## Status: ✅ Complete (all 8 repos on AbstractPrismaRepository)
25
+
26
+ ## Implemented Repositories
27
+
28
+ - `PrismaAccountRepository` → `IAccountRepository`
29
+ - `PrismaMembershipRepository` → `IMembershipRepository`
30
+ - `PrismaRoleRepository` → `IRoleRepository` (incl. `rolePermission` join table)
31
+ - `PrismaPermissionRepository` → `IPermissionRepository`
32
+ - `PrismaInvitationRepository` → `IInvitationRepository`
33
+ - `PrismaProfileRepository` → `IProfileRepository`
34
+ - `PrismaOnboardingFlowRepository` → `IOnboardingFlowRepository`
35
+ - `PrismaOnboardingProgressRepository` → `IOnboardingProgressRepository`
36
+
37
+ `AccountPrismaModule.register()` (no-arg) wires all 8 tokens to the concrete
38
+ implementations via `useExisting`.
39
+
40
+ ## Onboarding Repository Split
41
+
42
+ Onboarding was previously a single `ONBOARDING_REPOSITORY` token backed by one
43
+ class handling both flow + progress aggregates. It is now split:
44
+
45
+ - `ONBOARDING_FLOW_REPOSITORY` — `IOnboardingFlowRepository` (flow definitions)
46
+ - `ONBOARDING_PROGRESS_REPOSITORY` — `IOnboardingProgressRepository` (per-account progress + step merges)
47
+
48
+ Both extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`.
49
+
50
+ ## Wiring (Consumer App)
51
+
52
+ The consumer app must register `PrismaModule.forRoot({ transaction: true })` so
53
+ `TRANSACTION_MANAGER` is bound. `AccountPrismaModule` then resolves the
54
+ transaction-aware client per operation via `tx.getClient()`:
55
+
56
+ ```typescript
57
+ import { PrismaModule } from '@nathapp/nestjs-prisma';
58
+ import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
59
+
60
+ @Module({
61
+ imports: [
62
+ PrismaModule.forRoot({ client: PrismaClient, transaction: true }),
63
+ AccountPrismaModule.register(),
64
+ ],
65
+ })
66
+ export class AppModule {}
67
+ ```
68
+
69
+ ## Repository Pattern
70
+
71
+ All 8 repositories extend `AbstractPrismaRepository<TDomain, any, string>`
72
+ (from `@nathapp/nestjs-prisma`), providing:
73
+
74
+ - `modelDelegate(client)` — Prisma model accessor (e.g. `client.account`)
75
+ - `toDomain(e)` — persistence row → domain
76
+ - `toPersistenceCreate(d)` — domain → Prisma create input (omits `createdAt`/`updatedAt`)
77
+ - `toPersistenceUpdate(p)` — partial domain → Prisma update input
78
+
79
+ They inherit `findById`, `findOne`, `findAll`, `count`, `create`, `update`,
80
+ `delete` from the base class — all transaction-aware.
81
+
82
+ ## Dependencies
83
+
84
+ - `@nathapp/nestjs-account` (workspace)
85
+ - `@nathapp/nestjs-data` ^3.2.0 (peer)
86
+ - `@nathapp/nestjs-prisma` ^3.2.0 (peer)
87
+ - `@prisma/client` ^6.0.0 (peer)
88
+
89
+ ## Schema conventions
90
+
91
+ All `DateTime` fields in the consumer's `schema.prisma` for account models (Account, Membership, Role, Permission, Invitation, Profile, OnboardingFlow, OnboardingProgress) MUST use `@db.Timestamptz(6)`:
92
+
93
+ ```prisma
94
+ createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
95
+ updatedAt DateTime @db.Timestamptz(6) @updatedAt @map("updated_at")
96
+ expiresAt DateTime @db.Timestamptz(6) @map("expires_at")
97
+ ```
98
+
99
+ This maps to PostgreSQL `timestamptz`, which stores UTC and converts correctly regardless of DB server timezone. Bare `DateTime` (maps to `timestamp without time zone`) is NOT correct for this platform.
100
+
101
+ When migrating an existing database:
102
+ ```sql
103
+ ALTER TABLE <table> ALTER COLUMN <col> TYPE TIMESTAMPTZ(6) USING <col> AT TIME ZONE 'UTC';
104
+ ```
105
+ Run one statement per column. Verify `SHOW timezone;` returns `UTC` before migrating production data.
package/GEMINI.md ADDED
@@ -0,0 +1,105 @@
1
+ # Gemini CLI Context
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ ---
7
+
8
+ ## Project Metadata
9
+
10
+ > Auto-injected by `nax generate`
11
+
12
+ **Project:** `@nathapp/nestjs-account-prisma`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
17
+
18
+ ---
19
+ # CLAUDE.md — @nathapp/nestjs-account-prisma
20
+
21
+ Prisma adapter for `@nathapp/nestjs-account`. Binds the 8 account repository
22
+ tokens to `AbstractPrismaRepository`-based implementations.
23
+
24
+ ## Status: ✅ Complete (all 8 repos on AbstractPrismaRepository)
25
+
26
+ ## Implemented Repositories
27
+
28
+ - `PrismaAccountRepository` → `IAccountRepository`
29
+ - `PrismaMembershipRepository` → `IMembershipRepository`
30
+ - `PrismaRoleRepository` → `IRoleRepository` (incl. `rolePermission` join table)
31
+ - `PrismaPermissionRepository` → `IPermissionRepository`
32
+ - `PrismaInvitationRepository` → `IInvitationRepository`
33
+ - `PrismaProfileRepository` → `IProfileRepository`
34
+ - `PrismaOnboardingFlowRepository` → `IOnboardingFlowRepository`
35
+ - `PrismaOnboardingProgressRepository` → `IOnboardingProgressRepository`
36
+
37
+ `AccountPrismaModule.register()` (no-arg) wires all 8 tokens to the concrete
38
+ implementations via `useExisting`.
39
+
40
+ ## Onboarding Repository Split
41
+
42
+ Onboarding was previously a single `ONBOARDING_REPOSITORY` token backed by one
43
+ class handling both flow + progress aggregates. It is now split:
44
+
45
+ - `ONBOARDING_FLOW_REPOSITORY` — `IOnboardingFlowRepository` (flow definitions)
46
+ - `ONBOARDING_PROGRESS_REPOSITORY` — `IOnboardingProgressRepository` (per-account progress + step merges)
47
+
48
+ Both extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`.
49
+
50
+ ## Wiring (Consumer App)
51
+
52
+ The consumer app must register `PrismaModule.forRoot({ transaction: true })` so
53
+ `TRANSACTION_MANAGER` is bound. `AccountPrismaModule` then resolves the
54
+ transaction-aware client per operation via `tx.getClient()`:
55
+
56
+ ```typescript
57
+ import { PrismaModule } from '@nathapp/nestjs-prisma';
58
+ import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
59
+
60
+ @Module({
61
+ imports: [
62
+ PrismaModule.forRoot({ client: PrismaClient, transaction: true }),
63
+ AccountPrismaModule.register(),
64
+ ],
65
+ })
66
+ export class AppModule {}
67
+ ```
68
+
69
+ ## Repository Pattern
70
+
71
+ All 8 repositories extend `AbstractPrismaRepository<TDomain, any, string>`
72
+ (from `@nathapp/nestjs-prisma`), providing:
73
+
74
+ - `modelDelegate(client)` — Prisma model accessor (e.g. `client.account`)
75
+ - `toDomain(e)` — persistence row → domain
76
+ - `toPersistenceCreate(d)` — domain → Prisma create input (omits `createdAt`/`updatedAt`)
77
+ - `toPersistenceUpdate(p)` — partial domain → Prisma update input
78
+
79
+ They inherit `findById`, `findOne`, `findAll`, `count`, `create`, `update`,
80
+ `delete` from the base class — all transaction-aware.
81
+
82
+ ## Dependencies
83
+
84
+ - `@nathapp/nestjs-account` (workspace)
85
+ - `@nathapp/nestjs-data` ^3.2.0 (peer)
86
+ - `@nathapp/nestjs-prisma` ^3.2.0 (peer)
87
+ - `@prisma/client` ^6.0.0 (peer)
88
+
89
+ ## Schema conventions
90
+
91
+ All `DateTime` fields in the consumer's `schema.prisma` for account models (Account, Membership, Role, Permission, Invitation, Profile, OnboardingFlow, OnboardingProgress) MUST use `@db.Timestamptz(6)`:
92
+
93
+ ```prisma
94
+ createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
95
+ updatedAt DateTime @db.Timestamptz(6) @updatedAt @map("updated_at")
96
+ expiresAt DateTime @db.Timestamptz(6) @map("expires_at")
97
+ ```
98
+
99
+ This maps to PostgreSQL `timestamptz`, which stores UTC and converts correctly regardless of DB server timezone. Bare `DateTime` (maps to `timestamp without time zone`) is NOT correct for this platform.
100
+
101
+ When migrating an existing database:
102
+ ```sql
103
+ ALTER TABLE <table> ALTER COLUMN <col> TYPE TIMESTAMPTZ(6) USING <col> AT TIME ZONE 'UTC';
104
+ ```
105
+ Run one statement per column. Verify `SHOW timezone;` returns `UTC` before migrating production data.
package/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ # @nathapp/nestjs-account-prisma
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Prisma adapter for `@nathapp/nestjs-account`. Binds the core package's repository
4
+ tokens to `AbstractPrismaRepository`-based implementations.
5
+
6
+ ## Install
7
+
8
+ ```shell
9
+ npm i @nathapp/nestjs-account-prisma
10
+ npm i -D prisma && npx prisma init
11
+ ```
12
+
13
+ ## Schema
14
+
15
+ Append the 13 models from the packaged fragment
16
+ `node_modules/@nathapp/nestjs-account-prisma/prisma/account.prisma` to your app's
17
+ `schema.prisma`. The fragment carries no `datasource` or `generator` block — it
18
+ is models only. Every `DateTime` in it uses `@db.Timestamptz(6)` (PostgreSQL
19
+ `timestamptz`); bare `DateTime` is not supported.
20
+
21
+ **PostgreSQL and MySQL.** The fragment is authored for PostgreSQL 16 and also
22
+ supports MySQL 8.0. For MySQL, assemble it with `@db.Timestamptz(6)` rewritten
23
+ to `@db.DateTime(6)` (the only change; see the `@nathapp/nestjs-iam-prisma`
24
+ README, "Schema assembly and database support") and keep the MySQL server and
25
+ sessions on UTC (`time_zone = '+00:00'`), because `DATETIME(6)` stores no
26
+ timezone. Upgrading a MySQL database built from an earlier fragment: apply
27
+ `prisma/sql/long-text-columns.mysql.sql` (PostgreSQL needs nothing). Each
28
+ packaged migration has a `migration.mysql.sql` twin next to its `migration.sql`;
29
+ on MySQL the single-pending-transfer guard is a functional unique index.
30
+
31
+ Two of the models are join tables (`RolePermission`, `MembershipRole`) that exist
32
+ to support the `ROLE_REPOSITORY` and `MEMBERSHIP_ROLE_REPOSITORY` bindings.
33
+
34
+ `prisma/migrations/` in this package holds one incremental patch,
35
+ `20260714_ownership_transfer_pending_unique`, which adds a partial unique index
36
+ enforcing a single pending ownership transfer per account:
37
+
38
+ ```sql
39
+ CREATE UNIQUE INDEX ownership_transfers_one_pending_per_account
40
+ ON ownership_transfers (account_id)
41
+ WHERE status = 1;
42
+ ```
43
+
44
+ It is a delta, not a complete initial migration set, and Prisma will not apply it
45
+ for you — the consumer's migration history lives in the consumer's own project.
46
+ Apply it by hand when upgrading an existing database, after
47
+ `prisma migrate dev` has produced your own migration from the fragment.
48
+
49
+ ## Register
50
+
51
+ ```ts
52
+ import { Module } from '@nestjs/common';
53
+ import { PrismaClient } from '@prisma/client';
54
+ import { PrismaModule } from '@nathapp/nestjs-prisma';
55
+ import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
56
+
57
+ @Module({
58
+ imports: [
59
+ PrismaModule.forRoot({ client: PrismaClient, transaction: true }),
60
+ AccountPrismaModule.register(),
61
+ ],
62
+ })
63
+ export class AppModule {}
64
+ ```
65
+
66
+ `register()` takes an optional options object:
67
+
68
+ | Option | Type | Default | Meaning |
69
+ |---|---|---|---|
70
+ | `global` | `boolean` | `true` | Register as a global module so the repository tokens resolve anywhere. |
71
+
72
+ `register()` is the only import form for this adapter. There is no `registerAsync`.
73
+
74
+ ### If you already wrap this adapter in `@Global()`
75
+
76
+ Pass `global: false`. Otherwise the adapter's own global exports are injected
77
+ **in addition to** your override, and last-registration-wins silently decides
78
+ which implementation is used:
79
+
80
+ ```ts
81
+ import { Global, Module } from '@nestjs/common';
82
+ import { ACCOUNT_REPOSITORY } from '@nathapp/nestjs-account';
83
+ import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
84
+ import { SoftDeleteAccountRepository } from './soft-delete-account.repository';
85
+
86
+ @Global()
87
+ @Module({
88
+ imports: [AccountPrismaModule.register({ global: false })],
89
+ providers: [{ provide: ACCOUNT_REPOSITORY, useClass: SoftDeleteAccountRepository }],
90
+ exports: [ACCOUNT_REPOSITORY],
91
+ })
92
+ export class PrismaOverridesModule {}
93
+ ```
94
+
95
+ `global: false` only helps if the adapter is registered once. A second, global
96
+ `register()` elsewhere in the app keeps its global exports, and `global: false`
97
+ here does not remove them — so the collision this section exists to prevent is
98
+ still there. Register the adapter in exactly one place.
99
+
100
+ The `global` option carries no documentation in the published type definitions
101
+ (`removeComments: true` strips the JSDoc from the emitted `.d.ts`), so this README
102
+ is where it is described. The options object is typed as `PrismaAdapterModuleOptions`,
103
+ which is exported from this package if you need to name the type.
104
+
105
+ ## Transactions
106
+
107
+ Multi-write flows need `PrismaModule.forRoot({ client: PrismaClient, transaction: true })`.
108
+ Every repository resolves its client per operation from the `TRANSACTION_MANAGER`
109
+ token, and the two `PrismaModule` registration paths fail differently when
110
+ `transaction` is omitted:
111
+
112
+ - `PrismaModule.forRoot()` binds `TRANSACTION_MANAGER` only when `transaction: true`
113
+ is set. Without it nothing is bound, the repositories cannot resolve their
114
+ dependency, and Nest fails at boot.
115
+ - `PrismaModule.forRootAsync()` always binds the token, but with a manager whose
116
+ `run()` and `getClient()` throw and whose `isInTransaction()` returns `false`, so
117
+ the app boots and fails on first use instead.
118
+
119
+ Neither path is a silent passthrough: a real transaction manager either joins the
120
+ transaction already in scope or opens a Prisma interactive transaction.
121
+
122
+ Both of those are `PrismaModule` from `@nathapp/nestjs-prisma`. These adapters
123
+ expose only the synchronous `register()`; they have no `registerAsync`.
124
+
125
+ ## Tokens bound
126
+
127
+ | Token | Implementation |
128
+ |---|---|
129
+ | `ACCOUNT_REPOSITORY` | `PrismaAccountRepository` |
130
+ | `MEMBERSHIP_REPOSITORY` | `PrismaMembershipRepository` |
131
+ | `ROLE_REPOSITORY` | `PrismaRoleRepository` |
132
+ | `PERMISSION_REPOSITORY` | `PrismaPermissionRepository` |
133
+ | `INVITATION_REPOSITORY` | `PrismaInvitationRepository` |
134
+ | `PROFILE_REPOSITORY` | `PrismaProfileRepository` |
135
+ | `ONBOARDING_FLOW_REPOSITORY` | `PrismaOnboardingFlowRepository` |
136
+ | `ONBOARDING_PROGRESS_REPOSITORY` | `PrismaOnboardingProgressRepository` |
137
+ | `TENANT_APP_REPOSITORY` | `PrismaTenantAppRepository` |
138
+ | `MEMBERSHIP_ROLE_REPOSITORY` | `PrismaMembershipRoleRepository` |
139
+ | `AUDIT_LOG_REPOSITORY` | `PrismaAuditLogRepository` |
140
+ | `OWNERSHIP_TRANSFER_REPOSITORY` | `PrismaOwnershipTransferRepository` |
141
+
142
+ Onboarding is split across two tokens — `ONBOARDING_FLOW_REPOSITORY` for flow
143
+ definitions and `ONBOARDING_PROGRESS_REPOSITORY` for per-account progress — not
144
+ one combined token.
package/codex.md ADDED
@@ -0,0 +1,105 @@
1
+ # Codex Instructions
2
+
3
+ This file is auto-generated from `.nax/context.md`.
4
+ DO NOT EDIT MANUALLY — run `nax generate` to regenerate.
5
+
6
+ ---
7
+
8
+ ## Project Metadata
9
+
10
+ > Auto-injected by `nax generate`
11
+
12
+ **Project:** `@nathapp/nestjs-account-prisma`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
17
+
18
+ ---
19
+ # CLAUDE.md — @nathapp/nestjs-account-prisma
20
+
21
+ Prisma adapter for `@nathapp/nestjs-account`. Binds the 8 account repository
22
+ tokens to `AbstractPrismaRepository`-based implementations.
23
+
24
+ ## Status: ✅ Complete (all 8 repos on AbstractPrismaRepository)
25
+
26
+ ## Implemented Repositories
27
+
28
+ - `PrismaAccountRepository` → `IAccountRepository`
29
+ - `PrismaMembershipRepository` → `IMembershipRepository`
30
+ - `PrismaRoleRepository` → `IRoleRepository` (incl. `rolePermission` join table)
31
+ - `PrismaPermissionRepository` → `IPermissionRepository`
32
+ - `PrismaInvitationRepository` → `IInvitationRepository`
33
+ - `PrismaProfileRepository` → `IProfileRepository`
34
+ - `PrismaOnboardingFlowRepository` → `IOnboardingFlowRepository`
35
+ - `PrismaOnboardingProgressRepository` → `IOnboardingProgressRepository`
36
+
37
+ `AccountPrismaModule.register()` (no-arg) wires all 8 tokens to the concrete
38
+ implementations via `useExisting`.
39
+
40
+ ## Onboarding Repository Split
41
+
42
+ Onboarding was previously a single `ONBOARDING_REPOSITORY` token backed by one
43
+ class handling both flow + progress aggregates. It is now split:
44
+
45
+ - `ONBOARDING_FLOW_REPOSITORY` — `IOnboardingFlowRepository` (flow definitions)
46
+ - `ONBOARDING_PROGRESS_REPOSITORY` — `IOnboardingProgressRepository` (per-account progress + step merges)
47
+
48
+ Both extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`.
49
+
50
+ ## Wiring (Consumer App)
51
+
52
+ The consumer app must register `PrismaModule.forRoot({ transaction: true })` so
53
+ `TRANSACTION_MANAGER` is bound. `AccountPrismaModule` then resolves the
54
+ transaction-aware client per operation via `tx.getClient()`:
55
+
56
+ ```typescript
57
+ import { PrismaModule } from '@nathapp/nestjs-prisma';
58
+ import { AccountPrismaModule } from '@nathapp/nestjs-account-prisma';
59
+
60
+ @Module({
61
+ imports: [
62
+ PrismaModule.forRoot({ client: PrismaClient, transaction: true }),
63
+ AccountPrismaModule.register(),
64
+ ],
65
+ })
66
+ export class AppModule {}
67
+ ```
68
+
69
+ ## Repository Pattern
70
+
71
+ All 8 repositories extend `AbstractPrismaRepository<TDomain, any, string>`
72
+ (from `@nathapp/nestjs-prisma`), providing:
73
+
74
+ - `modelDelegate(client)` — Prisma model accessor (e.g. `client.account`)
75
+ - `toDomain(e)` — persistence row → domain
76
+ - `toPersistenceCreate(d)` — domain → Prisma create input (omits `createdAt`/`updatedAt`)
77
+ - `toPersistenceUpdate(p)` — partial domain → Prisma update input
78
+
79
+ They inherit `findById`, `findOne`, `findAll`, `count`, `create`, `update`,
80
+ `delete` from the base class — all transaction-aware.
81
+
82
+ ## Dependencies
83
+
84
+ - `@nathapp/nestjs-account` (workspace)
85
+ - `@nathapp/nestjs-data` ^3.2.0 (peer)
86
+ - `@nathapp/nestjs-prisma` ^3.2.0 (peer)
87
+ - `@prisma/client` ^6.0.0 (peer)
88
+
89
+ ## Schema conventions
90
+
91
+ All `DateTime` fields in the consumer's `schema.prisma` for account models (Account, Membership, Role, Permission, Invitation, Profile, OnboardingFlow, OnboardingProgress) MUST use `@db.Timestamptz(6)`:
92
+
93
+ ```prisma
94
+ createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
95
+ updatedAt DateTime @db.Timestamptz(6) @updatedAt @map("updated_at")
96
+ expiresAt DateTime @db.Timestamptz(6) @map("expires_at")
97
+ ```
98
+
99
+ This maps to PostgreSQL `timestamptz`, which stores UTC and converts correctly regardless of DB server timezone. Bare `DateTime` (maps to `timestamp without time zone`) is NOT correct for this platform.
100
+
101
+ When migrating an existing database:
102
+ ```sql
103
+ ALTER TABLE <table> ALTER COLUMN <col> TYPE TIMESTAMPTZ(6) USING <col> AT TIME ZONE 'UTC';
104
+ ```
105
+ Run one statement per column. Verify `SHOW timezone;` returns `UTC` before migrating production data.
@@ -0,0 +1,7 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ export interface PrismaAdapterModuleOptions {
3
+ global?: boolean;
4
+ }
5
+ export declare class AccountPrismaModule {
6
+ static register(options?: PrismaAdapterModuleOptions): DynamicModule;
7
+ }
@@ -0,0 +1,78 @@
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 AccountPrismaModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AccountPrismaModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const nestjs_account_1 = require("@nathapp/nestjs-account");
13
+ const prisma_account_repository_1 = require("./prisma-account.repository");
14
+ const prisma_membership_repository_1 = require("./prisma-membership.repository");
15
+ const prisma_role_repository_1 = require("./prisma-role.repository");
16
+ const prisma_permission_repository_1 = require("./prisma-permission.repository");
17
+ const prisma_invitation_repository_1 = require("./prisma-invitation.repository");
18
+ const prisma_profile_repository_1 = require("./prisma-profile.repository");
19
+ const prisma_onboarding_flow_repository_1 = require("./prisma-onboarding-flow.repository");
20
+ const prisma_onboarding_progress_repository_1 = require("./prisma-onboarding-progress.repository");
21
+ const prisma_tenant_app_repository_1 = require("./prisma-tenant-app.repository");
22
+ const prisma_membership_role_repository_1 = require("./prisma-membership-role.repository");
23
+ const prisma_audit_log_repository_1 = require("./prisma-audit-log.repository");
24
+ const prisma_ownership_transfer_repository_1 = require("./prisma-ownership-transfer.repository");
25
+ let AccountPrismaModule = AccountPrismaModule_1 = class AccountPrismaModule {
26
+ static register(options) {
27
+ var _a;
28
+ return {
29
+ module: AccountPrismaModule_1,
30
+ global: (_a = options === null || options === void 0 ? void 0 : options.global) !== null && _a !== void 0 ? _a : true,
31
+ providers: [
32
+ prisma_account_repository_1.PrismaAccountRepository,
33
+ { provide: nestjs_account_1.ACCOUNT_REPOSITORY, useExisting: prisma_account_repository_1.PrismaAccountRepository },
34
+ prisma_membership_repository_1.PrismaMembershipRepository,
35
+ { provide: nestjs_account_1.MEMBERSHIP_REPOSITORY, useExisting: prisma_membership_repository_1.PrismaMembershipRepository },
36
+ prisma_role_repository_1.PrismaRoleRepository,
37
+ { provide: nestjs_account_1.ROLE_REPOSITORY, useExisting: prisma_role_repository_1.PrismaRoleRepository },
38
+ prisma_permission_repository_1.PrismaPermissionRepository,
39
+ { provide: nestjs_account_1.PERMISSION_REPOSITORY, useExisting: prisma_permission_repository_1.PrismaPermissionRepository },
40
+ prisma_invitation_repository_1.PrismaInvitationRepository,
41
+ { provide: nestjs_account_1.INVITATION_REPOSITORY, useExisting: prisma_invitation_repository_1.PrismaInvitationRepository },
42
+ prisma_profile_repository_1.PrismaProfileRepository,
43
+ { provide: nestjs_account_1.PROFILE_REPOSITORY, useExisting: prisma_profile_repository_1.PrismaProfileRepository },
44
+ prisma_onboarding_flow_repository_1.PrismaOnboardingFlowRepository,
45
+ { provide: nestjs_account_1.ONBOARDING_FLOW_REPOSITORY, useExisting: prisma_onboarding_flow_repository_1.PrismaOnboardingFlowRepository },
46
+ prisma_onboarding_progress_repository_1.PrismaOnboardingProgressRepository,
47
+ { provide: nestjs_account_1.ONBOARDING_PROGRESS_REPOSITORY, useExisting: prisma_onboarding_progress_repository_1.PrismaOnboardingProgressRepository },
48
+ prisma_tenant_app_repository_1.PrismaTenantAppRepository,
49
+ { provide: nestjs_account_1.TENANT_APP_REPOSITORY, useExisting: prisma_tenant_app_repository_1.PrismaTenantAppRepository },
50
+ prisma_membership_role_repository_1.PrismaMembershipRoleRepository,
51
+ { provide: nestjs_account_1.MEMBERSHIP_ROLE_REPOSITORY, useExisting: prisma_membership_role_repository_1.PrismaMembershipRoleRepository },
52
+ prisma_audit_log_repository_1.PrismaAuditLogRepository,
53
+ { provide: nestjs_account_1.AUDIT_LOG_REPOSITORY, useExisting: prisma_audit_log_repository_1.PrismaAuditLogRepository },
54
+ prisma_ownership_transfer_repository_1.PrismaOwnershipTransferRepository,
55
+ { provide: nestjs_account_1.OWNERSHIP_TRANSFER_REPOSITORY, useExisting: prisma_ownership_transfer_repository_1.PrismaOwnershipTransferRepository },
56
+ ],
57
+ exports: [
58
+ nestjs_account_1.ACCOUNT_REPOSITORY,
59
+ nestjs_account_1.MEMBERSHIP_REPOSITORY,
60
+ nestjs_account_1.ROLE_REPOSITORY,
61
+ nestjs_account_1.PERMISSION_REPOSITORY,
62
+ nestjs_account_1.INVITATION_REPOSITORY,
63
+ nestjs_account_1.PROFILE_REPOSITORY,
64
+ nestjs_account_1.ONBOARDING_FLOW_REPOSITORY,
65
+ nestjs_account_1.ONBOARDING_PROGRESS_REPOSITORY,
66
+ nestjs_account_1.TENANT_APP_REPOSITORY,
67
+ nestjs_account_1.MEMBERSHIP_ROLE_REPOSITORY,
68
+ nestjs_account_1.AUDIT_LOG_REPOSITORY,
69
+ nestjs_account_1.OWNERSHIP_TRANSFER_REPOSITORY,
70
+ ],
71
+ };
72
+ }
73
+ };
74
+ exports.AccountPrismaModule = AccountPrismaModule;
75
+ exports.AccountPrismaModule = AccountPrismaModule = AccountPrismaModule_1 = __decorate([
76
+ (0, common_1.Module)({})
77
+ ], AccountPrismaModule);
78
+ //# sourceMappingURL=account-prisma.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-prisma.module.js","sourceRoot":"","sources":["../lib/account-prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,4DAaiC;AACjC,2EAAsE;AACtE,iFAA4E;AAC5E,qEAAgE;AAChE,iFAA4E;AAC5E,iFAA4E;AAC5E,2EAAsE;AACtE,2FAAqF;AACrF,mGAA6F;AAC7F,iFAA2E;AAC3E,2FAAqF;AACrF,+EAAyE;AACzE,iGAA2F;AAoBpF,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,OAAoC;;QAClD,OAAO;YACL,MAAM,EAAE,qBAAmB;YAC3B,MAAM,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,IAAI;YAC/B,SAAS,EAAE;gBACT,mDAAuB;gBACvB,EAAE,OAAO,EAAE,mCAAkB,EAAE,WAAW,EAAE,mDAAuB,EAAE;gBACrE,yDAA0B;gBAC1B,EAAE,OAAO,EAAE,sCAAqB,EAAE,WAAW,EAAE,yDAA0B,EAAE;gBAC3E,6CAAoB;gBACpB,EAAE,OAAO,EAAE,gCAAe,EAAE,WAAW,EAAE,6CAAoB,EAAE;gBAC/D,yDAA0B;gBAC1B,EAAE,OAAO,EAAE,sCAAqB,EAAE,WAAW,EAAE,yDAA0B,EAAE;gBAC3E,yDAA0B;gBAC1B,EAAE,OAAO,EAAE,sCAAqB,EAAE,WAAW,EAAE,yDAA0B,EAAE;gBAC3E,mDAAuB;gBACvB,EAAE,OAAO,EAAE,mCAAkB,EAAE,WAAW,EAAE,mDAAuB,EAAE;gBACrE,kEAA8B;gBAC9B,EAAE,OAAO,EAAE,2CAA0B,EAAE,WAAW,EAAE,kEAA8B,EAAE;gBACpF,0EAAkC;gBAClC,EAAE,OAAO,EAAE,+CAA8B,EAAE,WAAW,EAAE,0EAAkC,EAAE;gBAC5F,wDAAyB;gBACzB,EAAE,OAAO,EAAE,sCAAqB,EAAE,WAAW,EAAE,wDAAyB,EAAE;gBAC1E,kEAA8B;gBAC9B,EAAE,OAAO,EAAE,2CAA0B,EAAE,WAAW,EAAE,kEAA8B,EAAE;gBACpF,sDAAwB;gBACxB,EAAE,OAAO,EAAE,qCAAoB,EAAE,WAAW,EAAE,sDAAwB,EAAE;gBACxE,wEAAiC;gBACjC,EAAE,OAAO,EAAE,8CAA6B,EAAE,WAAW,EAAE,wEAAiC,EAAE;aAC3F;YACD,OAAO,EAAE;gBACP,mCAAkB;gBAClB,sCAAqB;gBACrB,gCAAe;gBACf,sCAAqB;gBACrB,sCAAqB;gBACrB,mCAAkB;gBAClB,2CAA0B;gBAC1B,+CAA8B;gBAC9B,sCAAqB;gBACrB,2CAA0B;gBAC1B,qCAAoB;gBACpB,8CAA6B;aAC9B;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AA/CY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,mBAAmB,CA+C/B"}
@@ -0,0 +1,14 @@
1
+ export * from '@nathapp/nestjs-account';
2
+ export { PrismaAccountRepository } from './prisma-account.repository';
3
+ export { PrismaMembershipRepository } from './prisma-membership.repository';
4
+ export { PrismaRoleRepository } from './prisma-role.repository';
5
+ export { PrismaPermissionRepository } from './prisma-permission.repository';
6
+ export { PrismaInvitationRepository } from './prisma-invitation.repository';
7
+ export { PrismaProfileRepository } from './prisma-profile.repository';
8
+ export { PrismaOnboardingFlowRepository } from './prisma-onboarding-flow.repository';
9
+ export { PrismaOnboardingProgressRepository } from './prisma-onboarding-progress.repository';
10
+ export { PrismaTenantAppRepository } from './prisma-tenant-app.repository';
11
+ export { PrismaMembershipRoleRepository } from './prisma-membership-role.repository';
12
+ export { PrismaAuditLogRepository } from './prisma-audit-log.repository';
13
+ export { PrismaOwnershipTransferRepository } from './prisma-ownership-transfer.repository';
14
+ export { AccountPrismaModule, type PrismaAdapterModuleOptions } from './account-prisma.module';