@nathapp/nestjs-notify-prisma 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.
package/AGENTS.md ADDED
@@ -0,0 +1,56 @@
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-notify-prisma`
15
+
16
+ **Language:** TypeScript
17
+
18
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
19
+
20
+ ---
21
+ # CLAUDE.md — @nathapp/nestjs-notify-prisma
22
+
23
+ Prisma adapter for `@nathapp/nestjs-notify`. Implements all repository interfaces using `@prisma/client`.
24
+
25
+ ## Status: ✅ Complete
26
+
27
+ ## What Is Implemented
28
+
29
+ 3 repository classes: `PrismaTemplateRepository`, `PrismaPreferenceRepository`, `PrismaDeliveryLogRepository` — each extending `AbstractPrismaRepository` from `@nathapp/nestjs-data` and implementing its corresponding interface from `@nathapp/nestjs-notify`.
30
+
31
+ `NotifyPrismaModule` registers all three repositories with their DI tokens.
32
+
33
+ ## Module Wiring (ADR-004)
34
+
35
+ `NotifyPrismaModule.register()` takes **no arguments**. The consumer is responsible for providing:
36
+
37
+ ```typescript
38
+ PrismaModule.forRoot({ transaction: true })
39
+ ```
40
+
41
+ This supplies `PRISMA_CLIENT` (via `@nathapp/nestjs-prisma`) and `TRANSACTION_MANAGER` (via `@nathapp/nestjs-data`) to all repositories. `NotifyPrismaModule` does **not** re-declare `PRISMA_CLIENT` — it is inherited from the consumer's `PrismaModule`.
42
+
43
+ ## Repository Pattern
44
+
45
+ All three repos extend `AbstractPrismaRepository<Domain, any, string>`:
46
+
47
+ - `AbstractPrismaRepository` provides `create`, `findById`, `update`, `delete` via the tx-aware `this.model` delegate
48
+ - Each repo implements domain-specific finders (`findByRecipient`, `findByUserAndChannel`, `findTemplate`, etc.)
49
+ - Tenant scoping is done **explicitly in custom finders** — `findById`/`update`/`delete` are unscoped at the repo level; the template tenant-guard lives in `DefaultTemplateService`
50
+
51
+ ## Dependencies
52
+
53
+ - `@nathapp/nestjs-notify` (workspace)
54
+ - `@nathapp/nestjs-data` (workspace) — `AbstractPrismaRepository`, `TRANSACTION_MANAGER`
55
+ - `@nathapp/nestjs-prisma` ^3.0.0 (peer) — `PrismaModule`, `PRISMA_CLIENT`
56
+ - `@prisma/client` ^6.0.0 (peer)
package/CLAUDE.md ADDED
@@ -0,0 +1,54 @@
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-notify-prisma`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
17
+
18
+ ---
19
+ # CLAUDE.md — @nathapp/nestjs-notify-prisma
20
+
21
+ Prisma adapter for `@nathapp/nestjs-notify`. Implements all repository interfaces using `@prisma/client`.
22
+
23
+ ## Status: ✅ Complete
24
+
25
+ ## What Is Implemented
26
+
27
+ 3 repository classes: `PrismaTemplateRepository`, `PrismaPreferenceRepository`, `PrismaDeliveryLogRepository` — each extending `AbstractPrismaRepository` from `@nathapp/nestjs-data` and implementing its corresponding interface from `@nathapp/nestjs-notify`.
28
+
29
+ `NotifyPrismaModule` registers all three repositories with their DI tokens.
30
+
31
+ ## Module Wiring (ADR-004)
32
+
33
+ `NotifyPrismaModule.register()` takes **no arguments**. The consumer is responsible for providing:
34
+
35
+ ```typescript
36
+ PrismaModule.forRoot({ transaction: true })
37
+ ```
38
+
39
+ This supplies `PRISMA_CLIENT` (via `@nathapp/nestjs-prisma`) and `TRANSACTION_MANAGER` (via `@nathapp/nestjs-data`) to all repositories. `NotifyPrismaModule` does **not** re-declare `PRISMA_CLIENT` — it is inherited from the consumer's `PrismaModule`.
40
+
41
+ ## Repository Pattern
42
+
43
+ All three repos extend `AbstractPrismaRepository<Domain, any, string>`:
44
+
45
+ - `AbstractPrismaRepository` provides `create`, `findById`, `update`, `delete` via the tx-aware `this.model` delegate
46
+ - Each repo implements domain-specific finders (`findByRecipient`, `findByUserAndChannel`, `findTemplate`, etc.)
47
+ - Tenant scoping is done **explicitly in custom finders** — `findById`/`update`/`delete` are unscoped at the repo level; the template tenant-guard lives in `DefaultTemplateService`
48
+
49
+ ## Dependencies
50
+
51
+ - `@nathapp/nestjs-notify` (workspace)
52
+ - `@nathapp/nestjs-data` (workspace) — `AbstractPrismaRepository`, `TRANSACTION_MANAGER`
53
+ - `@nathapp/nestjs-prisma` ^3.0.0 (peer) — `PrismaModule`, `PRISMA_CLIENT`
54
+ - `@prisma/client` ^6.0.0 (peer)
package/GEMINI.md ADDED
@@ -0,0 +1,54 @@
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-notify-prisma`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
17
+
18
+ ---
19
+ # CLAUDE.md — @nathapp/nestjs-notify-prisma
20
+
21
+ Prisma adapter for `@nathapp/nestjs-notify`. Implements all repository interfaces using `@prisma/client`.
22
+
23
+ ## Status: ✅ Complete
24
+
25
+ ## What Is Implemented
26
+
27
+ 3 repository classes: `PrismaTemplateRepository`, `PrismaPreferenceRepository`, `PrismaDeliveryLogRepository` — each extending `AbstractPrismaRepository` from `@nathapp/nestjs-data` and implementing its corresponding interface from `@nathapp/nestjs-notify`.
28
+
29
+ `NotifyPrismaModule` registers all three repositories with their DI tokens.
30
+
31
+ ## Module Wiring (ADR-004)
32
+
33
+ `NotifyPrismaModule.register()` takes **no arguments**. The consumer is responsible for providing:
34
+
35
+ ```typescript
36
+ PrismaModule.forRoot({ transaction: true })
37
+ ```
38
+
39
+ This supplies `PRISMA_CLIENT` (via `@nathapp/nestjs-prisma`) and `TRANSACTION_MANAGER` (via `@nathapp/nestjs-data`) to all repositories. `NotifyPrismaModule` does **not** re-declare `PRISMA_CLIENT` — it is inherited from the consumer's `PrismaModule`.
40
+
41
+ ## Repository Pattern
42
+
43
+ All three repos extend `AbstractPrismaRepository<Domain, any, string>`:
44
+
45
+ - `AbstractPrismaRepository` provides `create`, `findById`, `update`, `delete` via the tx-aware `this.model` delegate
46
+ - Each repo implements domain-specific finders (`findByRecipient`, `findByUserAndChannel`, `findTemplate`, etc.)
47
+ - Tenant scoping is done **explicitly in custom finders** — `findById`/`update`/`delete` are unscoped at the repo level; the template tenant-guard lives in `DefaultTemplateService`
48
+
49
+ ## Dependencies
50
+
51
+ - `@nathapp/nestjs-notify` (workspace)
52
+ - `@nathapp/nestjs-data` (workspace) — `AbstractPrismaRepository`, `TRANSACTION_MANAGER`
53
+ - `@nathapp/nestjs-prisma` ^3.0.0 (peer) — `PrismaModule`, `PRISMA_CLIENT`
54
+ - `@prisma/client` ^6.0.0 (peer)
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # @nathapp/nestjs-notify-prisma
2
+
3
+ Prisma adapter for `@nathapp/nestjs-notify`. Binds the core package's repository
4
+ tokens to `AbstractPrismaRepository`-based implementations.
5
+
6
+ ## Install
7
+
8
+ ```shell
9
+ npm i @nathapp/nestjs-notify-prisma
10
+ npm i -D prisma && npx prisma init
11
+ ```
12
+
13
+ ## Schema
14
+
15
+ Append the `NotificationPreference`, `DeliveryLog` and `NotificationTemplate`
16
+ models from the packaged fragment
17
+ `node_modules/@nathapp/nestjs-notify-prisma/prisma/notify.prisma` to your app's
18
+ `schema.prisma`. The fragment carries no `datasource` or `generator` block — it
19
+ is models only. Every `DateTime` in it uses `@db.Timestamptz(6)` (PostgreSQL
20
+ `timestamptz`); bare `DateTime` is not supported.
21
+
22
+ **PostgreSQL and MySQL.** The fragment is authored for PostgreSQL 16 and also
23
+ supports MySQL 8.0. For MySQL, assemble it with `@db.Timestamptz(6)` rewritten
24
+ to `@db.DateTime(6)` (the only change; see the `@nathapp/nestjs-iam-prisma`
25
+ README, "Schema assembly and database support") and keep the MySQL server and
26
+ sessions on UTC (`time_zone = '+00:00'`), because `DATETIME(6)` stores no
27
+ timezone. Upgrading a database built from an earlier fragment: on MySQL apply
28
+ `prisma/sql/long-text-columns.mysql.sql`; on PostgreSQL apply
29
+ `prisma/sql/recipient-varchar-512.postgresql.sql` (`delivery_logs.recipient`
30
+ becomes `VARCHAR(512)` so its index fits MySQL's key limit).
31
+
32
+ Keep the `@@unique([userId, tenantId, channel])` constraint on
33
+ `NotificationPreference` — `PrismaPreferenceRepository.upsertByUserAndChannel`
34
+ depends on it.
35
+
36
+ ## Register
37
+
38
+ ```ts
39
+ import { Module } from '@nestjs/common';
40
+ import { PrismaClient } from '@prisma/client';
41
+ import { PrismaModule } from '@nathapp/nestjs-prisma';
42
+ import { NotifyPrismaModule } from '@nathapp/nestjs-notify-prisma';
43
+
44
+ @Module({
45
+ imports: [
46
+ PrismaModule.forRoot({ client: PrismaClient, transaction: true }),
47
+ NotifyPrismaModule.register(),
48
+ ],
49
+ })
50
+ export class AppModule {}
51
+ ```
52
+
53
+ `register()` takes an optional options object:
54
+
55
+ | Option | Type | Default | Meaning |
56
+ |---|---|---|---|
57
+ | `global` | `boolean` | `true` | Register as a global module so the repository tokens resolve anywhere. |
58
+
59
+ `register()` is the only import form for this adapter. There is no `registerAsync`.
60
+
61
+ ### If you already wrap this adapter in `@Global()`
62
+
63
+ Pass `global: false`. Otherwise the adapter's own global exports are injected
64
+ **in addition to** your override, and last-registration-wins silently decides
65
+ which implementation is used:
66
+
67
+ ```ts
68
+ import { Global, Module } from '@nestjs/common';
69
+ import { TEMPLATE_REPOSITORY } from '@nathapp/nestjs-notify';
70
+ import { NotifyPrismaModule } from '@nathapp/nestjs-notify-prisma';
71
+ import { AuditedTemplateRepository } from './audited-template.repository';
72
+
73
+ @Global()
74
+ @Module({
75
+ imports: [NotifyPrismaModule.register({ global: false })],
76
+ providers: [{ provide: TEMPLATE_REPOSITORY, useClass: AuditedTemplateRepository }],
77
+ exports: [TEMPLATE_REPOSITORY],
78
+ })
79
+ export class PrismaOverridesModule {}
80
+ ```
81
+
82
+ `global: false` only helps if the adapter is registered once. A second, global
83
+ `register()` elsewhere in the app keeps its global exports, and `global: false`
84
+ here does not remove them — so the collision this section exists to prevent is
85
+ still there. Register the adapter in exactly one place.
86
+
87
+ The `global` option carries no documentation in the published type definitions
88
+ (`removeComments: true` strips the JSDoc from the emitted `.d.ts`), so this README
89
+ is where it is described. The options object is typed as `PrismaAdapterModuleOptions`,
90
+ which is exported from this package if you need to name the type.
91
+
92
+ ## Transactions
93
+
94
+ Multi-write flows need `PrismaModule.forRoot({ client: PrismaClient, transaction: true })`.
95
+ Every repository resolves its client per operation from the `TRANSACTION_MANAGER`
96
+ token, and the two `PrismaModule` registration paths fail differently when
97
+ `transaction` is omitted:
98
+
99
+ - `PrismaModule.forRoot()` binds `TRANSACTION_MANAGER` only when `transaction: true`
100
+ is set. Without it nothing is bound, the repositories cannot resolve their
101
+ dependency, and Nest fails at boot.
102
+ - `PrismaModule.forRootAsync()` always binds the token, but with a manager whose
103
+ `run()` and `getClient()` throw and whose `isInTransaction()` returns `false`, so
104
+ the app boots and fails on first use instead.
105
+
106
+ Neither path is a silent passthrough: a real transaction manager either joins the
107
+ transaction already in scope or opens a Prisma interactive transaction.
108
+
109
+ Both of those are `PrismaModule` from `@nathapp/nestjs-prisma`. These adapters
110
+ expose only the synchronous `register()`; they have no `registerAsync`.
111
+
112
+ ## Tokens bound
113
+
114
+ | Token | Implementation |
115
+ |---|---|
116
+ | `TEMPLATE_REPOSITORY` | `PrismaTemplateRepository` |
117
+ | `PREFERENCE_REPOSITORY` | `PrismaPreferenceRepository` |
118
+ | `DELIVERY_LOG_REPOSITORY` | `PrismaDeliveryLogRepository` |
package/codex.md ADDED
@@ -0,0 +1,54 @@
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-notify-prisma`
13
+
14
+ **Language:** TypeScript
15
+
16
+ **Key dependencies:** @nathapp/nestjs-prisma, typescript
17
+
18
+ ---
19
+ # CLAUDE.md — @nathapp/nestjs-notify-prisma
20
+
21
+ Prisma adapter for `@nathapp/nestjs-notify`. Implements all repository interfaces using `@prisma/client`.
22
+
23
+ ## Status: ✅ Complete
24
+
25
+ ## What Is Implemented
26
+
27
+ 3 repository classes: `PrismaTemplateRepository`, `PrismaPreferenceRepository`, `PrismaDeliveryLogRepository` — each extending `AbstractPrismaRepository` from `@nathapp/nestjs-data` and implementing its corresponding interface from `@nathapp/nestjs-notify`.
28
+
29
+ `NotifyPrismaModule` registers all three repositories with their DI tokens.
30
+
31
+ ## Module Wiring (ADR-004)
32
+
33
+ `NotifyPrismaModule.register()` takes **no arguments**. The consumer is responsible for providing:
34
+
35
+ ```typescript
36
+ PrismaModule.forRoot({ transaction: true })
37
+ ```
38
+
39
+ This supplies `PRISMA_CLIENT` (via `@nathapp/nestjs-prisma`) and `TRANSACTION_MANAGER` (via `@nathapp/nestjs-data`) to all repositories. `NotifyPrismaModule` does **not** re-declare `PRISMA_CLIENT` — it is inherited from the consumer's `PrismaModule`.
40
+
41
+ ## Repository Pattern
42
+
43
+ All three repos extend `AbstractPrismaRepository<Domain, any, string>`:
44
+
45
+ - `AbstractPrismaRepository` provides `create`, `findById`, `update`, `delete` via the tx-aware `this.model` delegate
46
+ - Each repo implements domain-specific finders (`findByRecipient`, `findByUserAndChannel`, `findTemplate`, etc.)
47
+ - Tenant scoping is done **explicitly in custom finders** — `findById`/`update`/`delete` are unscoped at the repo level; the template tenant-guard lives in `DefaultTemplateService`
48
+
49
+ ## Dependencies
50
+
51
+ - `@nathapp/nestjs-notify` (workspace)
52
+ - `@nathapp/nestjs-data` (workspace) — `AbstractPrismaRepository`, `TRANSACTION_MANAGER`
53
+ - `@nathapp/nestjs-prisma` ^3.0.0 (peer) — `PrismaModule`, `PRISMA_CLIENT`
54
+ - `@prisma/client` ^6.0.0 (peer)
@@ -0,0 +1,5 @@
1
+ export * from '@nathapp/nestjs-notify';
2
+ export { PrismaTemplateRepository } from './prisma-template.repository';
3
+ export { PrismaPreferenceRepository } from './prisma-preference.repository';
4
+ export { PrismaDeliveryLogRepository } from './prisma-delivery-log.repository';
5
+ export * from './notify-prisma.module';
package/dist/index.js ADDED
@@ -0,0 +1,26 @@
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.PrismaDeliveryLogRepository = exports.PrismaPreferenceRepository = exports.PrismaTemplateRepository = void 0;
18
+ __exportStar(require("@nathapp/nestjs-notify"), exports);
19
+ var prisma_template_repository_1 = require("./prisma-template.repository");
20
+ Object.defineProperty(exports, "PrismaTemplateRepository", { enumerable: true, get: function () { return prisma_template_repository_1.PrismaTemplateRepository; } });
21
+ var prisma_preference_repository_1 = require("./prisma-preference.repository");
22
+ Object.defineProperty(exports, "PrismaPreferenceRepository", { enumerable: true, get: function () { return prisma_preference_repository_1.PrismaPreferenceRepository; } });
23
+ var prisma_delivery_log_repository_1 = require("./prisma-delivery-log.repository");
24
+ Object.defineProperty(exports, "PrismaDeliveryLogRepository", { enumerable: true, get: function () { return prisma_delivery_log_repository_1.PrismaDeliveryLogRepository; } });
25
+ __exportStar(require("./notify-prisma.module"), exports);
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,2EAAwE;AAA/D,sIAAA,wBAAwB,OAAA;AACjC,+EAA4E;AAAnE,0IAAA,0BAA0B,OAAA;AACnC,mFAA+E;AAAtE,6IAAA,2BAA2B,OAAA;AACpC,yDAAuC"}
@@ -0,0 +1,7 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ export interface PrismaAdapterModuleOptions {
3
+ global?: boolean;
4
+ }
5
+ export declare class NotifyPrismaModule {
6
+ static register(options?: PrismaAdapterModuleOptions): DynamicModule;
7
+ }
@@ -0,0 +1,38 @@
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 NotifyPrismaModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.NotifyPrismaModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const nestjs_notify_1 = require("@nathapp/nestjs-notify");
13
+ const prisma_template_repository_1 = require("./prisma-template.repository");
14
+ const prisma_preference_repository_1 = require("./prisma-preference.repository");
15
+ const prisma_delivery_log_repository_1 = require("./prisma-delivery-log.repository");
16
+ let NotifyPrismaModule = NotifyPrismaModule_1 = class NotifyPrismaModule {
17
+ static register(options) {
18
+ var _a;
19
+ return {
20
+ module: NotifyPrismaModule_1,
21
+ global: (_a = options === null || options === void 0 ? void 0 : options.global) !== null && _a !== void 0 ? _a : true,
22
+ providers: [
23
+ prisma_template_repository_1.PrismaTemplateRepository,
24
+ { provide: nestjs_notify_1.TEMPLATE_REPOSITORY, useExisting: prisma_template_repository_1.PrismaTemplateRepository },
25
+ prisma_preference_repository_1.PrismaPreferenceRepository,
26
+ { provide: nestjs_notify_1.PREFERENCE_REPOSITORY, useExisting: prisma_preference_repository_1.PrismaPreferenceRepository },
27
+ prisma_delivery_log_repository_1.PrismaDeliveryLogRepository,
28
+ { provide: nestjs_notify_1.DELIVERY_LOG_REPOSITORY, useExisting: prisma_delivery_log_repository_1.PrismaDeliveryLogRepository },
29
+ ],
30
+ exports: [nestjs_notify_1.TEMPLATE_REPOSITORY, nestjs_notify_1.PREFERENCE_REPOSITORY, nestjs_notify_1.DELIVERY_LOG_REPOSITORY],
31
+ };
32
+ }
33
+ };
34
+ exports.NotifyPrismaModule = NotifyPrismaModule;
35
+ exports.NotifyPrismaModule = NotifyPrismaModule = NotifyPrismaModule_1 = __decorate([
36
+ (0, common_1.Module)({})
37
+ ], NotifyPrismaModule);
38
+ //# sourceMappingURL=notify-prisma.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notify-prisma.module.js","sourceRoot":"","sources":["../lib/notify-prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,0DAIgC;AAChC,6EAAwE;AACxE,iFAA4E;AAC5E,qFAA+E;AAoBxE,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC7B,MAAM,CAAC,QAAQ,CAAC,OAAoC;;QAClD,OAAO;YACL,MAAM,EAAE,oBAAkB;YAC1B,MAAM,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,IAAI;YAC/B,SAAS,EAAE;gBACT,qDAAwB;gBACxB,EAAE,OAAO,EAAE,mCAAmB,EAAE,WAAW,EAAE,qDAAwB,EAAE;gBACvE,yDAA0B;gBAC1B,EAAE,OAAO,EAAE,qCAAqB,EAAE,WAAW,EAAE,yDAA0B,EAAE;gBAC3E,4DAA2B;gBAC3B,EAAE,OAAO,EAAE,uCAAuB,EAAE,WAAW,EAAE,4DAA2B,EAAE;aAC/E;YACD,OAAO,EAAE,CAAC,mCAAmB,EAAE,qCAAqB,EAAE,uCAAuB,CAAC;SAC/E,CAAC;IACJ,CAAC;CACF,CAAA;AAhBY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,kBAAkB,CAgB9B"}
@@ -0,0 +1,34 @@
1
+ import { AbstractPrismaRepository, PrismaModelDelegate, PrismaClientLike } from '@nathapp/nestjs-prisma';
2
+ import { ITransactionManager, IPageResult } from '@nathapp/nestjs-data';
3
+ import type { IPageOption } from '@nathapp/nestjs-common';
4
+ import { IDeliveryLogRepository, IDeliveryLog, DeliveryStatus } from '@nathapp/nestjs-notify';
5
+ type DeliveryLogDelegate = PrismaModelDelegate<IDeliveryLog, string> & {
6
+ updateMany(args: {
7
+ where: Record<string, unknown>;
8
+ data: Record<string, unknown>;
9
+ }): Promise<{
10
+ count: number;
11
+ }>;
12
+ };
13
+ export declare class PrismaDeliveryLogRepository extends AbstractPrismaRepository<IDeliveryLog, IDeliveryLog, string> implements IDeliveryLogRepository {
14
+ constructor(tx: ITransactionManager);
15
+ protected modelDelegate(client: PrismaClientLike): DeliveryLogDelegate;
16
+ private get deliveryLogModel();
17
+ protected toDomain(e: IDeliveryLog): IDeliveryLog;
18
+ protected toPersistenceCreate(d: IDeliveryLog): {
19
+ id: string;
20
+ tenantId: string;
21
+ userId: string | undefined;
22
+ channel: string;
23
+ templateCode: string;
24
+ recipient: string;
25
+ status: DeliveryStatus;
26
+ metadata: Record<string, unknown>;
27
+ };
28
+ protected toPersistenceUpdate(p: Partial<IDeliveryLog>): Record<string, unknown>;
29
+ updateStatus(id: string, tenantId: string, status: DeliveryStatus, errorMessage?: string, providerMessageId?: string): Promise<IDeliveryLog>;
30
+ updateStatusIfCurrent(id: string, tenantId: string, expectedStatus: DeliveryStatus, newStatus: DeliveryStatus, reason?: string): Promise<boolean>;
31
+ findByRecipient(recipient: string, tenantId: string, page: IPageOption): Promise<IPageResult<IDeliveryLog>>;
32
+ findByProviderMessageId(providerMessageId: string, tenantId: string): Promise<IDeliveryLog | null>;
33
+ }
34
+ export {};
@@ -0,0 +1,118 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PrismaDeliveryLogRepository = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const nestjs_prisma_1 = require("@nathapp/nestjs-prisma");
18
+ const nestjs_data_1 = require("@nathapp/nestjs-data");
19
+ const nestjs_notify_1 = require("@nathapp/nestjs-notify");
20
+ let PrismaDeliveryLogRepository = class PrismaDeliveryLogRepository extends nestjs_prisma_1.AbstractPrismaRepository {
21
+ constructor(tx) { super(tx); }
22
+ modelDelegate(client) {
23
+ return client.deliveryLog;
24
+ }
25
+ get deliveryLogModel() {
26
+ return this.modelDelegate(this.tx.getClient());
27
+ }
28
+ toDomain(e) {
29
+ var _a, _b, _c, _d;
30
+ return {
31
+ id: e.id,
32
+ tenantId: e.tenantId,
33
+ userId: (_a = e.userId) !== null && _a !== void 0 ? _a : undefined,
34
+ channel: e.channel,
35
+ templateCode: e.templateCode,
36
+ recipient: e.recipient,
37
+ status: e.status,
38
+ providerMessageId: (_b = e.providerMessageId) !== null && _b !== void 0 ? _b : undefined,
39
+ errorMessage: (_c = e.errorMessage) !== null && _c !== void 0 ? _c : undefined,
40
+ metadata: e.metadata,
41
+ sentAt: (_d = e.sentAt) !== null && _d !== void 0 ? _d : undefined,
42
+ createdAt: e.createdAt,
43
+ };
44
+ }
45
+ toPersistenceCreate(d) {
46
+ var _a;
47
+ return {
48
+ id: d.id,
49
+ tenantId: d.tenantId,
50
+ userId: d.userId,
51
+ channel: d.channel,
52
+ templateCode: d.templateCode,
53
+ recipient: d.recipient,
54
+ status: d.status,
55
+ metadata: (_a = d.metadata) !== null && _a !== void 0 ? _a : {},
56
+ };
57
+ }
58
+ toPersistenceUpdate(p) {
59
+ const out = {};
60
+ if (p.status !== undefined)
61
+ out.status = p.status;
62
+ if (p.errorMessage !== undefined)
63
+ out.errorMessage = p.errorMessage;
64
+ if (p.sentAt !== undefined)
65
+ out.sentAt = p.sentAt;
66
+ return out;
67
+ }
68
+ async updateStatus(id, tenantId, status, errorMessage, providerMessageId) {
69
+ const sentAt = status === nestjs_notify_1.DeliveryStatus.SENT || status === nestjs_notify_1.DeliveryStatus.DELIVERED ? new Date() : undefined;
70
+ const data = { status };
71
+ if (errorMessage !== undefined)
72
+ data.errorMessage = errorMessage;
73
+ if (providerMessageId !== undefined)
74
+ data.providerMessageId = providerMessageId;
75
+ if (sentAt !== undefined)
76
+ data.sentAt = sentAt;
77
+ const result = await this.deliveryLogModel.updateMany({ where: { id, tenantId }, data });
78
+ if (result.count === 0) {
79
+ throw new nestjs_notify_1.NotifyException(nestjs_notify_1.NotifyExceptionCode.TENANT_MISMATCH);
80
+ }
81
+ const row = await this.deliveryLogModel.findFirst({ where: { id, tenantId } });
82
+ if (!row) {
83
+ throw new nestjs_notify_1.NotifyException(nestjs_notify_1.NotifyExceptionCode.DELIVERY_FAILED);
84
+ }
85
+ return this.toDomain(row);
86
+ }
87
+ async updateStatusIfCurrent(id, tenantId, expectedStatus, newStatus, reason) {
88
+ const sentAt = newStatus === nestjs_notify_1.DeliveryStatus.SENT || newStatus === nestjs_notify_1.DeliveryStatus.DELIVERED ? new Date() : undefined;
89
+ const data = { status: newStatus };
90
+ if (reason !== undefined)
91
+ data.errorMessage = reason;
92
+ if (sentAt !== undefined)
93
+ data.sentAt = sentAt;
94
+ const result = await this.deliveryLogModel.updateMany({
95
+ where: { id, tenantId, status: expectedStatus },
96
+ data,
97
+ });
98
+ return result.count === 1;
99
+ }
100
+ async findByRecipient(recipient, tenantId, page) {
101
+ const result = await (0, nestjs_prisma_1.Paginate)(this.deliveryLogModel, page, {
102
+ where: { recipient, tenantId },
103
+ orderBy: { createdAt: 'desc' },
104
+ });
105
+ return result.remap((row) => this.toDomain(row));
106
+ }
107
+ async findByProviderMessageId(providerMessageId, tenantId) {
108
+ const row = await this.model.findFirst({ where: { providerMessageId, tenantId } });
109
+ return row ? this.toDomain(row) : null;
110
+ }
111
+ };
112
+ exports.PrismaDeliveryLogRepository = PrismaDeliveryLogRepository;
113
+ exports.PrismaDeliveryLogRepository = PrismaDeliveryLogRepository = __decorate([
114
+ (0, common_1.Injectable)(),
115
+ __param(0, (0, common_1.Inject)(nestjs_data_1.TRANSACTION_MANAGER)),
116
+ __metadata("design:paramtypes", [Object])
117
+ ], PrismaDeliveryLogRepository);
118
+ //# sourceMappingURL=prisma-delivery-log.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-delivery-log.repository.js","sourceRoot":"","sources":["../lib/prisma-delivery-log.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,0DAAmH;AACnH,sDAA6F;AAE7F,0DAMgC;AAOzB,IAAM,2BAA2B,GAAjC,MAAM,2BACX,SAAQ,wCAA4D;IAGpE,YAAyC,EAAuB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtE,aAAa,CAAC,MAAwB;QAC9C,OAAQ,MAAkE,CAAC,WAAW,CAAC;IACzF,CAAC;IAED,IAAY,gBAAgB;QAC1B,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAoB,CAAC,CAAC;IACnE,CAAC;IAES,QAAQ,CAAC,CAAe;;QAChC,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,MAAM,EAAE,MAAA,CAAC,CAAC,MAAM,mCAAI,SAAS;YAC7B,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,MAAM,EAAE,CAAC,CAAC,MAAwB;YAClC,iBAAiB,EAAE,MAAA,CAAC,CAAC,iBAAiB,mCAAI,SAAS;YACnD,YAAY,EAAE,MAAA,CAAC,CAAC,YAAY,mCAAI,SAAS;YACzC,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,MAAM,EAAE,MAAA,CAAC,CAAC,MAAM,mCAAI,SAAS;YAC7B,SAAS,EAAE,CAAC,CAAC,SAAS;SACvB,CAAC;IACJ,CAAC;IAES,mBAAmB,CAAC,CAAe;;QAE3C,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,QAAQ,EAAE,CAAC,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;IAED,KAAK,CAAC,eAAe,CACnB,SAAiB,EACjB,QAAgB,EAChB,IAAiB;QAEjB,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAQ,EAAe,IAAI,CAAC,gBAAgB,EAAE,IAAI,EAAE;YACvE,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE;YAC9B,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE;SAC/B,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,uBAAuB,CAC3B,iBAAyB,EACzB,QAAgB;QAEhB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,iBAAiB,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;QACnF,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACzC,CAAC;CACF,CAAA;AAnHY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,mBAAU,GAAE;IAKE,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;;GAJ7B,2BAA2B,CAmHvC"}
@@ -0,0 +1,32 @@
1
+ import { AbstractPrismaRepository, PrismaClientLike, PrismaModelDelegate } from '@nathapp/nestjs-prisma';
2
+ import { ITransactionManager } from '@nathapp/nestjs-data';
3
+ import { IPreferenceRepository, INotificationPreference, NotificationChannelLike } from '@nathapp/nestjs-notify';
4
+ type PreferenceDelegate = PrismaModelDelegate<INotificationPreference, string> & {
5
+ findMany(args: {
6
+ where: Record<string, unknown>;
7
+ }): Promise<INotificationPreference[]>;
8
+ upsert(args: {
9
+ where: Record<string, unknown>;
10
+ create: Record<string, unknown>;
11
+ update: Record<string, unknown>;
12
+ }): Promise<INotificationPreference>;
13
+ };
14
+ export declare class PrismaPreferenceRepository extends AbstractPrismaRepository<INotificationPreference, INotificationPreference, string> implements IPreferenceRepository {
15
+ constructor(tx: ITransactionManager);
16
+ protected modelDelegate(client: PrismaClientLike): PreferenceDelegate;
17
+ private get preferenceModel();
18
+ protected toDomain(e: INotificationPreference): INotificationPreference;
19
+ protected toPersistenceCreate(d: INotificationPreference): {
20
+ id: string;
21
+ userId: string;
22
+ tenantId: string;
23
+ channel: NotificationChannelLike;
24
+ enabled: boolean;
25
+ metadata: Record<string, unknown>;
26
+ };
27
+ protected toPersistenceUpdate(p: Partial<INotificationPreference>): Record<string, unknown>;
28
+ findByUserId(userId: string, tenantId: string): Promise<INotificationPreference[]>;
29
+ findByUserAndChannel(userId: string, tenantId: string, channel: NotificationChannelLike): Promise<INotificationPreference | null>;
30
+ upsertByUserAndChannel(pref: INotificationPreference): Promise<INotificationPreference>;
31
+ }
32
+ export {};
@@ -0,0 +1,87 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PrismaPreferenceRepository = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const nestjs_prisma_1 = require("@nathapp/nestjs-prisma");
18
+ const nestjs_data_1 = require("@nathapp/nestjs-data");
19
+ let PrismaPreferenceRepository = class PrismaPreferenceRepository extends nestjs_prisma_1.AbstractPrismaRepository {
20
+ constructor(tx) { super(tx); }
21
+ modelDelegate(client) {
22
+ return client.notificationPreference;
23
+ }
24
+ get preferenceModel() {
25
+ return this.modelDelegate(this.tx.getClient());
26
+ }
27
+ toDomain(e) {
28
+ return {
29
+ id: e.id,
30
+ userId: e.userId,
31
+ tenantId: e.tenantId,
32
+ channel: e.channel,
33
+ enabled: e.enabled,
34
+ metadata: e.metadata,
35
+ createdAt: e.createdAt,
36
+ updatedAt: e.updatedAt,
37
+ };
38
+ }
39
+ toPersistenceCreate(d) {
40
+ var _a;
41
+ return {
42
+ id: d.id,
43
+ userId: d.userId,
44
+ tenantId: d.tenantId,
45
+ channel: d.channel,
46
+ enabled: d.enabled,
47
+ metadata: (_a = d.metadata) !== null && _a !== void 0 ? _a : {},
48
+ };
49
+ }
50
+ toPersistenceUpdate(p) {
51
+ const out = {};
52
+ if (p.enabled !== undefined)
53
+ out.enabled = p.enabled;
54
+ if (p.metadata !== undefined)
55
+ out.metadata = p.metadata;
56
+ return out;
57
+ }
58
+ async findByUserId(userId, tenantId) {
59
+ const rows = await this.preferenceModel.findMany({ where: { userId, tenantId } });
60
+ return rows.map((row) => this.toDomain(row));
61
+ }
62
+ async findByUserAndChannel(userId, tenantId, channel) {
63
+ const row = await this.model.findFirst({ where: { userId, tenantId, channel } });
64
+ return row ? this.toDomain(row) : null;
65
+ }
66
+ async upsertByUserAndChannel(pref) {
67
+ const row = await this.preferenceModel.upsert({
68
+ where: {
69
+ userId_tenantId_channel: {
70
+ userId: pref.userId,
71
+ tenantId: pref.tenantId,
72
+ channel: pref.channel,
73
+ },
74
+ },
75
+ create: this.toPersistenceCreate(pref),
76
+ update: { enabled: pref.enabled },
77
+ });
78
+ return this.toDomain(row);
79
+ }
80
+ };
81
+ exports.PrismaPreferenceRepository = PrismaPreferenceRepository;
82
+ exports.PrismaPreferenceRepository = PrismaPreferenceRepository = __decorate([
83
+ (0, common_1.Injectable)(),
84
+ __param(0, (0, common_1.Inject)(nestjs_data_1.TRANSACTION_MANAGER)),
85
+ __metadata("design:paramtypes", [Object])
86
+ ], PrismaPreferenceRepository);
87
+ //# sourceMappingURL=prisma-preference.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-preference.repository.js","sourceRoot":"","sources":["../lib/prisma-preference.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,0DAAyG;AACzG,sDAAgF;AAiBzE,IAAM,0BAA0B,GAAhC,MAAM,0BACX,SAAQ,wCAAkF;IAG1F,YAAyC,EAAuB,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtE,aAAa,CAAC,MAAwB;QAC9C,OAAQ,MAA4E,CAAC,sBAAsB,CAAC;IAC9G,CAAC;IAED,IAAY,eAAe;QACzB,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,EAAoB,CAAC,CAAC;IACnE,CAAC;IAES,QAAQ,CAAC,CAA0B;QAC3C,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,SAAS,EAAE,CAAC,CAAC,SAAS;SACvB,CAAC;IACJ,CAAC;IAES,mBAAmB,CAAC,CAA0B;;QACtD,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,OAAO,EAAE,CAAC,CAA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AC,MAAM;oBACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;oBACvB,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB;aACF;YACD,MAAM,EAAE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC;YACtC,MAAM,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;SAClC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AAzEY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAU,GAAE;IAKE,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;;GAJ7B,0BAA0B,CAyEtC"}
@@ -0,0 +1,23 @@
1
+ import { AbstractPrismaRepository, PrismaClientLike, PrismaModelDelegate } from '@nathapp/nestjs-prisma';
2
+ import { ITransactionManager, IPageResult } from '@nathapp/nestjs-data';
3
+ import type { IPageOption } from '@nathapp/nestjs-common';
4
+ import { ITemplateRepository, INotificationTemplate } from '@nathapp/nestjs-notify';
5
+ export declare class PrismaTemplateRepository extends AbstractPrismaRepository<INotificationTemplate, INotificationTemplate, string> implements ITemplateRepository {
6
+ constructor(tx: ITransactionManager);
7
+ protected modelDelegate(client: PrismaClientLike): PrismaModelDelegate<INotificationTemplate, string>;
8
+ protected toDomain(e: INotificationTemplate): INotificationTemplate;
9
+ protected toPersistenceCreate(d: INotificationTemplate): {
10
+ id: string;
11
+ tenantId: string;
12
+ code: string;
13
+ channel: string | undefined;
14
+ locale: string;
15
+ subject: string | undefined;
16
+ content: string;
17
+ isActive: boolean;
18
+ metadata: Record<string, unknown>;
19
+ };
20
+ protected toPersistenceUpdate(p: Partial<INotificationTemplate>): Record<string, unknown>;
21
+ findTemplate(code: string, locale: string, tenantId: string, channel?: string): Promise<INotificationTemplate | null>;
22
+ findAllByTenant(tenantId: string, page: IPageOption, channel?: string): Promise<IPageResult<INotificationTemplate>>;
23
+ }
@@ -0,0 +1,92 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PrismaTemplateRepository = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const nestjs_prisma_1 = require("@nathapp/nestjs-prisma");
18
+ const nestjs_data_1 = require("@nathapp/nestjs-data");
19
+ let PrismaTemplateRepository = class PrismaTemplateRepository extends nestjs_prisma_1.AbstractPrismaRepository {
20
+ constructor(tx) { super(tx); }
21
+ modelDelegate(client) {
22
+ return client.notificationTemplate;
23
+ }
24
+ toDomain(e) {
25
+ var _a, _b;
26
+ return {
27
+ id: e.id,
28
+ tenantId: e.tenantId,
29
+ code: e.code,
30
+ channel: (_a = e.channel) !== null && _a !== void 0 ? _a : undefined,
31
+ locale: e.locale,
32
+ subject: (_b = e.subject) !== null && _b !== void 0 ? _b : undefined,
33
+ content: e.content,
34
+ isActive: e.isActive,
35
+ metadata: e.metadata,
36
+ createdAt: e.createdAt,
37
+ updatedAt: e.updatedAt,
38
+ };
39
+ }
40
+ toPersistenceCreate(d) {
41
+ var _a, _b;
42
+ return {
43
+ id: d.id,
44
+ tenantId: d.tenantId,
45
+ code: d.code,
46
+ channel: d.channel,
47
+ locale: d.locale,
48
+ subject: d.subject,
49
+ content: d.content,
50
+ isActive: (_a = d.isActive) !== null && _a !== void 0 ? _a : true,
51
+ metadata: (_b = d.metadata) !== null && _b !== void 0 ? _b : {},
52
+ };
53
+ }
54
+ toPersistenceUpdate(p) {
55
+ const out = {};
56
+ if (p.channel !== undefined)
57
+ out.channel = p.channel;
58
+ if (p.subject !== undefined)
59
+ out.subject = p.subject;
60
+ if (p.content !== undefined)
61
+ out.content = p.content;
62
+ if (p.isActive !== undefined)
63
+ out.isActive = p.isActive;
64
+ if (p.metadata !== undefined)
65
+ out.metadata = p.metadata;
66
+ return out;
67
+ }
68
+ async findTemplate(code, locale, tenantId, channel) {
69
+ const where = { code, locale, tenantId, isActive: true };
70
+ if (channel)
71
+ where.channel = channel;
72
+ const row = await this.model.findFirst({ where });
73
+ return row ? this.toDomain(row) : null;
74
+ }
75
+ async findAllByTenant(tenantId, page, channel) {
76
+ const where = { tenantId };
77
+ if (channel)
78
+ where.channel = channel;
79
+ const result = await (0, nestjs_prisma_1.Paginate)(this.model, page, {
80
+ where,
81
+ orderBy: { createdAt: 'desc' },
82
+ });
83
+ return result.remap((row) => this.toDomain(row));
84
+ }
85
+ };
86
+ exports.PrismaTemplateRepository = PrismaTemplateRepository;
87
+ exports.PrismaTemplateRepository = PrismaTemplateRepository = __decorate([
88
+ (0, common_1.Injectable)(),
89
+ __param(0, (0, common_1.Inject)(nestjs_data_1.TRANSACTION_MANAGER)),
90
+ __metadata("design:paramtypes", [Object])
91
+ ], PrismaTemplateRepository);
92
+ //# sourceMappingURL=prisma-template.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma-template.repository.js","sourceRoot":"","sources":["../lib/prisma-template.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,0DAAmH;AACnH,sDAA6F;AAQtF,IAAM,wBAAwB,GAA9B,MAAM,wBACX,SAAQ,wCAA8E;IAGtF,YAAyC,EAAuB,IAAI,KA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AAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;CACF,CAAA;AA7EY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,mBAAU,GAAE;IAKE,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;;GAJ7B,wBAAwB,CA6EpC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@nathapp/nestjs-notify-prisma",
3
+ "version": "1.0.0",
4
+ "description": "Prisma adapter for @nathapp/nestjs-notify",
5
+ "scripts": {
6
+ "build": "rimraf dist && tsc -p tsconfig.json",
7
+ "clean": "rimraf dist/ .turbo/",
8
+ "lint": "eslint -c .eslintrc.js --ext .ts .",
9
+ "lint:fix": "eslint -c .eslintrc.js --ext .ts . --fix",
10
+ "test": "jest --config ./test/jest-test.json --forceExit --no-colors --silent",
11
+ "test:json": "jest --config ./test/jest-test.json --json --no-colors --silent",
12
+ "test:verbose": "jest --config ./test/jest-test.json",
13
+ "test:cov": "jest --config ./test/jest-test.json --coverage",
14
+ "type-check": "tsc --noEmit -p tsconfig.json"
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "engines": {
19
+ "node": "^20.19.0 || >=22.12.0"
20
+ },
21
+ "types": "dist/index.d.ts",
22
+ "main": "dist/index.js",
23
+ "directories": {
24
+ "lib": "lib"
25
+ },
26
+ "dependencies": {
27
+ "@nathapp/nestjs-notify": "1.0.0",
28
+ "@nathapp/nestjs-data": "^3.3.0 || ^4.0.2"
29
+ },
30
+ "devDependencies": {
31
+ "@nathapp/nestjs-prisma": "^4.0.2",
32
+ "eslint": "^8.57.0",
33
+ "typescript": "^5"
34
+ },
35
+ "peerDependencies": {
36
+ "@nestjs/common": "^11.0.0 || ^12.1.0",
37
+ "@nestjs/core": "^11.0.0 || ^12.1.0",
38
+ "@nathapp/nestjs-prisma": "^3.3.0 || ^4.0.2",
39
+ "@prisma/client": "^6.0.0"
40
+ }
41
+ }
@@ -0,0 +1,62 @@
1
+ // === @nathapp/nestjs-notify schema fragment ===
2
+ // Append these models to your application's schema.prisma.
3
+ // IMPORTANT: NotificationPreference requires @@unique([userId, tenantId, channel])
4
+ // for the atomic upsert in PrismaPreferenceRepository.upsertByUserAndChannel.
5
+ //
6
+ // TZ NOTE: All DateTime fields use @db.Timestamptz(6) (timestamptz in PostgreSQL).
7
+ // When migrating an existing database, use:
8
+ // ALTER TABLE t ALTER COLUMN col TYPE TIMESTAMPTZ(6) USING col AT TIME ZONE 'UTC';
9
+ // The USING clause treats existing values as UTC — safe if your DB was UTC-configured.
10
+ // Verify your DB timezone (SHOW timezone;) before running migrations on production data.
11
+
12
+ model NotificationPreference {
13
+ id String @id @default(uuid())
14
+ userId String @map("user_id")
15
+ tenantId String @map("tenant_id")
16
+ channel String
17
+ enabled Boolean @default(true)
18
+ metadata Json @default("{}")
19
+ createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
20
+ updatedAt DateTime @db.Timestamptz(6) @updatedAt @map("updated_at")
21
+
22
+ @@unique([userId, tenantId, channel])
23
+ @@map("notification_preferences")
24
+ }
25
+
26
+ model DeliveryLog {
27
+ id String @id @default(uuid())
28
+ tenantId String @map("tenant_id")
29
+ userId String? @map("user_id")
30
+ channel String
31
+ templateCode String @map("template_code")
32
+ recipient String @db.VarChar(512)
33
+ status String
34
+ providerMessageId String? @map("provider_message_id")
35
+ errorMessage String? @db.Text @map("error_message")
36
+ metadata Json @default("{}")
37
+ sentAt DateTime? @db.Timestamptz(6) @map("sent_at")
38
+ createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
39
+
40
+ @@index([tenantId])
41
+ @@index([recipient, tenantId])
42
+ @@index([tenantId, providerMessageId])
43
+ @@map("delivery_logs")
44
+ }
45
+
46
+ model NotificationTemplate {
47
+ id String @id @default(uuid())
48
+ tenantId String @map("tenant_id")
49
+ code String
50
+ channel String?
51
+ locale String
52
+ subject String? @db.Text
53
+ content String @db.Text
54
+ isActive Boolean @default(true) @map("is_active")
55
+ metadata Json @default("{}")
56
+ createdAt DateTime @db.Timestamptz(6) @default(now()) @map("created_at")
57
+ updatedAt DateTime @db.Timestamptz(6) @updatedAt @map("updated_at")
58
+
59
+ @@unique([tenantId, code, locale, channel])
60
+ @@index([tenantId])
61
+ @@map("notification_templates")
62
+ }
@@ -0,0 +1,8 @@
1
+ -- MySQL only. Widens columns whose values can exceed VARCHAR(191) (Prisma's MySQL
2
+ -- mapping for a bare String). PostgreSQL needs nothing: String is already text there.
3
+ -- Apply once to a MySQL database created from an earlier version of this fragment.
4
+ ALTER TABLE `delivery_logs` MODIFY `recipient` VARCHAR(512) NOT NULL,
5
+ MODIFY `error_message` TEXT NULL;
6
+
7
+ ALTER TABLE `notification_templates` MODIFY `subject` TEXT NULL,
8
+ MODIFY `content` TEXT NOT NULL;
@@ -0,0 +1,6 @@
1
+ -- PostgreSQL. Bounds delivery_logs.recipient to VARCHAR(512) so the (recipient, tenant_id)
2
+ -- index fits MySQL's key limit; the MySQL change is in long-text-columns.mysql.sql.
3
+ -- Fails if a stored recipient is longer than 512 characters; check first:
4
+ -- SELECT count(*) FROM "delivery_logs" WHERE length("recipient") > 512;
5
+ ALTER TABLE "delivery_logs" ALTER COLUMN "recipient" SET DATA TYPE VARCHAR(512);
6
+