@nathapp/nestjs-notify 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.
- package/AGENTS.md +73 -0
- package/CLAUDE.md +71 -0
- package/GEMINI.md +71 -0
- package/README.md +181 -2
- package/codex.md +71 -0
- package/dist/constant/index.d.ts +1 -0
- package/dist/constant/index.js +18 -0
- package/dist/constant/index.js.map +1 -0
- package/dist/constant/tokens.d.ts +15 -0
- package/dist/constant/tokens.js +28 -0
- package/dist/constant/tokens.js.map +1 -0
- package/dist/delivery/console-delivery.channel.d.ts +8 -0
- package/dist/delivery/console-delivery.channel.js +31 -0
- package/dist/delivery/console-delivery.channel.js.map +1 -0
- package/dist/delivery/delivery-channel.registry.d.ts +11 -0
- package/dist/delivery/delivery-channel.registry.js +35 -0
- package/dist/delivery/delivery-channel.registry.js.map +1 -0
- package/dist/delivery/index.d.ts +2 -0
- package/dist/delivery/index.js +19 -0
- package/dist/delivery/index.js.map +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +18 -0
- package/dist/error/index.js.map +1 -0
- package/dist/error/permanent-notification.error.d.ts +5 -0
- package/dist/error/permanent-notification.error.js +52 -0
- package/dist/error/permanent-notification.error.js.map +1 -0
- package/dist/event/index.d.ts +7 -0
- package/dist/event/index.js +10 -0
- package/dist/event/index.js.map +1 -0
- package/dist/exception/index.d.ts +2 -0
- package/dist/exception/index.js +19 -0
- package/dist/exception/index.js.map +1 -0
- package/dist/exception/notify-exception-code.d.ts +11 -0
- package/dist/exception/notify-exception-code.js +28 -0
- package/dist/exception/notify-exception-code.js.map +1 -0
- package/dist/exception/notify.exception.d.ts +6 -0
- package/dist/exception/notify.exception.js +28 -0
- package/dist/exception/notify.exception.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/interface/index.d.ts +4 -0
- package/dist/interface/index.js +21 -0
- package/dist/interface/index.js.map +1 -0
- package/dist/interface/models/delivery-log.interface.d.ts +30 -0
- package/dist/interface/models/delivery-log.interface.js +12 -0
- package/dist/interface/models/delivery-log.interface.js.map +1 -0
- package/dist/interface/models/dlq-job.interface.d.ts +8 -0
- package/dist/interface/models/dlq-job.interface.js +3 -0
- package/dist/interface/models/dlq-job.interface.js.map +1 -0
- package/dist/interface/models/index.d.ts +4 -0
- package/dist/interface/models/index.js +21 -0
- package/dist/interface/models/index.js.map +1 -0
- package/dist/interface/models/preference.interface.d.ts +28 -0
- package/dist/interface/models/preference.interface.js +11 -0
- package/dist/interface/models/preference.interface.js.map +1 -0
- package/dist/interface/models/template.interface.d.ts +29 -0
- package/dist/interface/models/template.interface.js +3 -0
- package/dist/interface/models/template.interface.js.map +1 -0
- package/dist/interface/providers/delivery-channel-provider.interface.d.ts +7 -0
- package/dist/interface/providers/delivery-channel-provider.interface.js +3 -0
- package/dist/interface/providers/delivery-channel-provider.interface.js.map +1 -0
- package/dist/interface/providers/index.d.ts +2 -0
- package/dist/interface/providers/index.js +19 -0
- package/dist/interface/providers/index.js.map +1 -0
- package/dist/interface/providers/provider-event-normalizer.interface.d.ts +4 -0
- package/dist/interface/providers/provider-event-normalizer.interface.js +10 -0
- package/dist/interface/providers/provider-event-normalizer.interface.js.map +1 -0
- package/dist/interface/repositories/delivery-log-repository.interface.d.ts +9 -0
- package/dist/interface/repositories/delivery-log-repository.interface.js +3 -0
- package/dist/interface/repositories/delivery-log-repository.interface.js.map +1 -0
- package/dist/interface/repositories/index.d.ts +3 -0
- package/dist/interface/repositories/index.js +20 -0
- package/dist/interface/repositories/index.js.map +1 -0
- package/dist/interface/repositories/preference-repository.interface.d.ts +7 -0
- package/dist/interface/repositories/preference-repository.interface.js +3 -0
- package/dist/interface/repositories/preference-repository.interface.js.map +1 -0
- package/dist/interface/repositories/template-repository.interface.d.ts +7 -0
- package/dist/interface/repositories/template-repository.interface.js +3 -0
- package/dist/interface/repositories/template-repository.interface.js.map +1 -0
- package/dist/interface/services/delivery-tracker.interface.d.ts +20 -0
- package/dist/interface/services/delivery-tracker.interface.js +15 -0
- package/dist/interface/services/delivery-tracker.interface.js.map +1 -0
- package/dist/interface/services/dlq-service.interface.d.ts +8 -0
- package/dist/interface/services/dlq-service.interface.js +3 -0
- package/dist/interface/services/dlq-service.interface.js.map +1 -0
- package/dist/interface/services/index.d.ts +48 -0
- package/dist/interface/services/index.js +19 -0
- package/dist/interface/services/index.js.map +1 -0
- package/dist/module/index.d.ts +30 -0
- package/dist/module/index.js +191 -0
- package/dist/module/index.js.map +1 -0
- package/dist/processor/index.d.ts +1 -0
- package/dist/processor/index.js +18 -0
- package/dist/processor/index.js.map +1 -0
- package/dist/processor/notification.processor.d.ts +14 -0
- package/dist/processor/notification.processor.js +101 -0
- package/dist/processor/notification.processor.js.map +1 -0
- package/dist/service/default-delivery-tracker.service.d.ts +11 -0
- package/dist/service/default-delivery-tracker.service.js +124 -0
- package/dist/service/default-delivery-tracker.service.js.map +1 -0
- package/dist/service/default-dlq.service.d.ts +16 -0
- package/dist/service/default-dlq.service.js +86 -0
- package/dist/service/default-dlq.service.js.map +1 -0
- package/dist/service/default-notify.service.d.ts +23 -0
- package/dist/service/default-notify.service.js +168 -0
- package/dist/service/default-notify.service.js.map +1 -0
- package/dist/service/default-preference.service.d.ts +15 -0
- package/dist/service/default-preference.service.js +57 -0
- package/dist/service/default-preference.service.js.map +1 -0
- package/dist/service/default-template.service.d.ts +36 -0
- package/dist/service/default-template.service.js +142 -0
- package/dist/service/default-template.service.js.map +1 -0
- package/dist/service/index.d.ts +5 -0
- package/dist/service/index.js +22 -0
- package/dist/service/index.js.map +1 -0
- package/dist/template/handlebars-template.engine.d.ts +8 -0
- package/dist/template/handlebars-template.engine.js +37 -0
- package/dist/template/handlebars-template.engine.js.map +1 -0
- package/dist/template/index.d.ts +15 -0
- package/dist/template/index.js +50 -0
- package/dist/template/index.js.map +1 -0
- package/dist/template/template-cache.d.ts +27 -0
- package/dist/template/template-cache.js +65 -0
- package/dist/template/template-cache.js.map +1 -0
- package/i18n/en/notify.json +14 -0
- package/i18n/zh/notify.json +14 -0
- package/package.json +49 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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`
|
|
15
|
+
|
|
16
|
+
**Language:** TypeScript
|
|
17
|
+
|
|
18
|
+
**Key dependencies:** typescript
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
# CLAUDE.md — @nathapp/nestjs-notify
|
|
22
|
+
|
|
23
|
+
Notification management with templates, preferences and delivery strategies for NestJS. Management layer on top of `@nathapp/nestjs-notification` (which handles actual sending).
|
|
24
|
+
|
|
25
|
+
## Status: ✅ Complete (ADR-004 adopted)
|
|
26
|
+
|
|
27
|
+
## Directory Structure
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
lib/
|
|
31
|
+
├── constant/tokens.ts — DI tokens
|
|
32
|
+
├── delivery/ — TODO: delivery strategies (immediate, batched, digest, fallback chain)
|
|
33
|
+
├── dto/ — TODO: DTOs for notification operations
|
|
34
|
+
├── event/ — TODO: domain events (NotificationSent, DeliveryFailed, etc.)
|
|
35
|
+
├── exception/ — TODO: NotifyExceptionCode enum
|
|
36
|
+
├── interface/
|
|
37
|
+
│ ├── models/ — TODO: ITemplate, IPreference, IDeliveryLog
|
|
38
|
+
│ ├── repositories/ — TODO: repository interfaces
|
|
39
|
+
│ └── services/ — TODO: service interfaces
|
|
40
|
+
├── module/ — TODO: NotifyModule.register() / registerAsync()
|
|
41
|
+
├── service/ — TODO: DefaultNotifyService, DefaultTemplateService, etc.
|
|
42
|
+
└── template/ — TODO: Handlebars template engine integration
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## DI Tokens
|
|
46
|
+
|
|
47
|
+
**Repositories**: `TEMPLATE_REPOSITORY`, `PREFERENCE_REPOSITORY`, `DELIVERY_LOG_REPOSITORY`
|
|
48
|
+
|
|
49
|
+
**Services**: `NOTIFY_SERVICE`, `TEMPLATE_SERVICE`, `PREFERENCE_SERVICE`, `DELIVERY_SERVICE`, `DELIVERY_TRACKER`
|
|
50
|
+
|
|
51
|
+
## Dependencies
|
|
52
|
+
|
|
53
|
+
- `@nathapp/nestjs-tenant` (workspace) — tenant context
|
|
54
|
+
- `@nathapp/nestjs-common` ^3.0.0 — `AppException`
|
|
55
|
+
- `@nathapp/nestjs-notification` ^3.0.0 — actual email/SMS/push sending
|
|
56
|
+
- `@nestjs/event-emitter` — domain events
|
|
57
|
+
- `handlebars` ^4.7.8 — template rendering
|
|
58
|
+
|
|
59
|
+
## Architecture Notes
|
|
60
|
+
|
|
61
|
+
- **nestjs-notify** = management (templates, preferences, delivery tracking, retry/fallback)
|
|
62
|
+
- **nestjs-notification** (existing) = transport (send email via SES, SMS via Twilio, push via FCM)
|
|
63
|
+
- This package orchestrates WHEN and HOW to send; `nestjs-notification` handles the actual delivery
|
|
64
|
+
- Template rendering uses Handlebars — consumers register templates with variables
|
|
65
|
+
- Preferences: per-user, per-tenant channel preferences (email/SMS/push opt-in/out)
|
|
66
|
+
|
|
67
|
+
## ADR-004 Notes
|
|
68
|
+
|
|
69
|
+
All three repository interfaces (`ITemplateRepository`, `IPreferenceRepository`, `IDeliveryLogRepository`) now extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`. This aligns them with the platform-wide repository contract (tenant, iam, account).
|
|
70
|
+
|
|
71
|
+
The tenant-guard pattern (ensuring tenant context before repository access) lives in `DefaultTemplateService` — it is not a separate guard class.
|
|
72
|
+
|
|
73
|
+
**No transactional flows** are introduced in nestjs-notify. Notification delivery spans external I/O (email/SMS/push providers) which cannot participate in a DB transaction. Failed deliveries are routed through the DLQ (`DefaultDlqService`) and retried via queue (BullMQ/Kafka/RabbitMQ) — a queue-only durability pattern, not a transaction pattern.
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** typescript
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
# CLAUDE.md — @nathapp/nestjs-notify
|
|
20
|
+
|
|
21
|
+
Notification management with templates, preferences and delivery strategies for NestJS. Management layer on top of `@nathapp/nestjs-notification` (which handles actual sending).
|
|
22
|
+
|
|
23
|
+
## Status: ✅ Complete (ADR-004 adopted)
|
|
24
|
+
|
|
25
|
+
## Directory Structure
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
lib/
|
|
29
|
+
├── constant/tokens.ts — DI tokens
|
|
30
|
+
├── delivery/ — TODO: delivery strategies (immediate, batched, digest, fallback chain)
|
|
31
|
+
├── dto/ — TODO: DTOs for notification operations
|
|
32
|
+
├── event/ — TODO: domain events (NotificationSent, DeliveryFailed, etc.)
|
|
33
|
+
├── exception/ — TODO: NotifyExceptionCode enum
|
|
34
|
+
├── interface/
|
|
35
|
+
│ ├── models/ — TODO: ITemplate, IPreference, IDeliveryLog
|
|
36
|
+
│ ├── repositories/ — TODO: repository interfaces
|
|
37
|
+
│ └── services/ — TODO: service interfaces
|
|
38
|
+
├── module/ — TODO: NotifyModule.register() / registerAsync()
|
|
39
|
+
├── service/ — TODO: DefaultNotifyService, DefaultTemplateService, etc.
|
|
40
|
+
└── template/ — TODO: Handlebars template engine integration
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## DI Tokens
|
|
44
|
+
|
|
45
|
+
**Repositories**: `TEMPLATE_REPOSITORY`, `PREFERENCE_REPOSITORY`, `DELIVERY_LOG_REPOSITORY`
|
|
46
|
+
|
|
47
|
+
**Services**: `NOTIFY_SERVICE`, `TEMPLATE_SERVICE`, `PREFERENCE_SERVICE`, `DELIVERY_SERVICE`, `DELIVERY_TRACKER`
|
|
48
|
+
|
|
49
|
+
## Dependencies
|
|
50
|
+
|
|
51
|
+
- `@nathapp/nestjs-tenant` (workspace) — tenant context
|
|
52
|
+
- `@nathapp/nestjs-common` ^3.0.0 — `AppException`
|
|
53
|
+
- `@nathapp/nestjs-notification` ^3.0.0 — actual email/SMS/push sending
|
|
54
|
+
- `@nestjs/event-emitter` — domain events
|
|
55
|
+
- `handlebars` ^4.7.8 — template rendering
|
|
56
|
+
|
|
57
|
+
## Architecture Notes
|
|
58
|
+
|
|
59
|
+
- **nestjs-notify** = management (templates, preferences, delivery tracking, retry/fallback)
|
|
60
|
+
- **nestjs-notification** (existing) = transport (send email via SES, SMS via Twilio, push via FCM)
|
|
61
|
+
- This package orchestrates WHEN and HOW to send; `nestjs-notification` handles the actual delivery
|
|
62
|
+
- Template rendering uses Handlebars — consumers register templates with variables
|
|
63
|
+
- Preferences: per-user, per-tenant channel preferences (email/SMS/push opt-in/out)
|
|
64
|
+
|
|
65
|
+
## ADR-004 Notes
|
|
66
|
+
|
|
67
|
+
All three repository interfaces (`ITemplateRepository`, `IPreferenceRepository`, `IDeliveryLogRepository`) now extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`. This aligns them with the platform-wide repository contract (tenant, iam, account).
|
|
68
|
+
|
|
69
|
+
The tenant-guard pattern (ensuring tenant context before repository access) lives in `DefaultTemplateService` — it is not a separate guard class.
|
|
70
|
+
|
|
71
|
+
**No transactional flows** are introduced in nestjs-notify. Notification delivery spans external I/O (email/SMS/push providers) which cannot participate in a DB transaction. Failed deliveries are routed through the DLQ (`DefaultDlqService`) and retried via queue (BullMQ/Kafka/RabbitMQ) — a queue-only durability pattern, not a transaction pattern.
|
package/GEMINI.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** typescript
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
# CLAUDE.md — @nathapp/nestjs-notify
|
|
20
|
+
|
|
21
|
+
Notification management with templates, preferences and delivery strategies for NestJS. Management layer on top of `@nathapp/nestjs-notification` (which handles actual sending).
|
|
22
|
+
|
|
23
|
+
## Status: ✅ Complete (ADR-004 adopted)
|
|
24
|
+
|
|
25
|
+
## Directory Structure
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
lib/
|
|
29
|
+
├── constant/tokens.ts — DI tokens
|
|
30
|
+
├── delivery/ — TODO: delivery strategies (immediate, batched, digest, fallback chain)
|
|
31
|
+
├── dto/ — TODO: DTOs for notification operations
|
|
32
|
+
├── event/ — TODO: domain events (NotificationSent, DeliveryFailed, etc.)
|
|
33
|
+
├── exception/ — TODO: NotifyExceptionCode enum
|
|
34
|
+
├── interface/
|
|
35
|
+
│ ├── models/ — TODO: ITemplate, IPreference, IDeliveryLog
|
|
36
|
+
│ ├── repositories/ — TODO: repository interfaces
|
|
37
|
+
│ └── services/ — TODO: service interfaces
|
|
38
|
+
├── module/ — TODO: NotifyModule.register() / registerAsync()
|
|
39
|
+
├── service/ — TODO: DefaultNotifyService, DefaultTemplateService, etc.
|
|
40
|
+
└── template/ — TODO: Handlebars template engine integration
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## DI Tokens
|
|
44
|
+
|
|
45
|
+
**Repositories**: `TEMPLATE_REPOSITORY`, `PREFERENCE_REPOSITORY`, `DELIVERY_LOG_REPOSITORY`
|
|
46
|
+
|
|
47
|
+
**Services**: `NOTIFY_SERVICE`, `TEMPLATE_SERVICE`, `PREFERENCE_SERVICE`, `DELIVERY_SERVICE`, `DELIVERY_TRACKER`
|
|
48
|
+
|
|
49
|
+
## Dependencies
|
|
50
|
+
|
|
51
|
+
- `@nathapp/nestjs-tenant` (workspace) — tenant context
|
|
52
|
+
- `@nathapp/nestjs-common` ^3.0.0 — `AppException`
|
|
53
|
+
- `@nathapp/nestjs-notification` ^3.0.0 — actual email/SMS/push sending
|
|
54
|
+
- `@nestjs/event-emitter` — domain events
|
|
55
|
+
- `handlebars` ^4.7.8 — template rendering
|
|
56
|
+
|
|
57
|
+
## Architecture Notes
|
|
58
|
+
|
|
59
|
+
- **nestjs-notify** = management (templates, preferences, delivery tracking, retry/fallback)
|
|
60
|
+
- **nestjs-notification** (existing) = transport (send email via SES, SMS via Twilio, push via FCM)
|
|
61
|
+
- This package orchestrates WHEN and HOW to send; `nestjs-notification` handles the actual delivery
|
|
62
|
+
- Template rendering uses Handlebars — consumers register templates with variables
|
|
63
|
+
- Preferences: per-user, per-tenant channel preferences (email/SMS/push opt-in/out)
|
|
64
|
+
|
|
65
|
+
## ADR-004 Notes
|
|
66
|
+
|
|
67
|
+
All three repository interfaces (`ITemplateRepository`, `IPreferenceRepository`, `IDeliveryLogRepository`) now extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`. This aligns them with the platform-wide repository contract (tenant, iam, account).
|
|
68
|
+
|
|
69
|
+
The tenant-guard pattern (ensuring tenant context before repository access) lives in `DefaultTemplateService` — it is not a separate guard class.
|
|
70
|
+
|
|
71
|
+
**No transactional flows** are introduced in nestjs-notify. Notification delivery spans external I/O (email/SMS/push providers) which cannot participate in a DB transaction. Failed deliveries are routed through the DLQ (`DefaultDlqService`) and retried via queue (BullMQ/Kafka/RabbitMQ) — a queue-only durability pattern, not a transaction pattern.
|
package/README.md
CHANGED
|
@@ -1,3 +1,182 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nathapp/nestjs-notify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Notification **management** for NestJS: templates, per-user/per-tenant preferences,
|
|
4
|
+
delivery channels, and delivery tracking. It orchestrates *when* and *how* a
|
|
5
|
+
notification is sent; the actual transport (email/SMS/push) is provided by a
|
|
6
|
+
delivery channel — either one you register, or `ConsoleDeliveryChannel` for
|
|
7
|
+
development.
|
|
8
|
+
|
|
9
|
+
- **Templates** — register and render content with a pluggable `ITemplateEngine`
|
|
10
|
+
(an HTML-escaping `SimpleTemplateEngine` ships by default).
|
|
11
|
+
- **Preferences** — per `(userId, tenantId, channel)` opt-in/out, with a
|
|
12
|
+
`metadata` bag for richer state (e.g. consent).
|
|
13
|
+
- **Delivery channels** — pluggable adapters keyed by a channel string. The
|
|
14
|
+
package ships no transport of its own except a dev-only console logger.
|
|
15
|
+
- **Delivery tracking** — `IDeliveryTracker` records normalized delivery events
|
|
16
|
+
you feed it from provider webhooks.
|
|
17
|
+
|
|
18
|
+
This package is ORM-agnostic: the core defines repository interfaces, and the
|
|
19
|
+
`@nathapp/nestjs-notify-prisma` package supplies Prisma implementations.
|
|
20
|
+
|
|
21
|
+
## Built-in channels
|
|
22
|
+
|
|
23
|
+
`NotificationChannel` enumerates four channels. Note the **lowercase** string
|
|
24
|
+
values:
|
|
25
|
+
|
|
26
|
+
| Member | Value | Delivery adapter shipped? |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| `NotificationChannel.EMAIL` | `'email'` | No transport in this package |
|
|
29
|
+
| `NotificationChannel.PUSH` | `'push'` | No transport in this package |
|
|
30
|
+
| `NotificationChannel.SMS` | `'sms'` | No transport in this package |
|
|
31
|
+
| `NotificationChannel.IN_APP` | `'in_app'` | **No** — in-app delivery is entirely the consumer's concern |
|
|
32
|
+
|
|
33
|
+
`IN_APP` ships **no** delivery adapter. If you send on `IN_APP` you must register
|
|
34
|
+
your own channel for it (or accept the `CHANNEL_NOT_REGISTERED` error).
|
|
35
|
+
|
|
36
|
+
`ConsoleDeliveryChannel` is a development/testing adapter that logs the channel
|
|
37
|
+
name and template code to stdout instead of sending. It reads no recipient or
|
|
38
|
+
rendered content. It **defaults to `EMAIL`** (`new ConsoleDeliveryChannel()`
|
|
39
|
+
registers as `'email'`), but the constructor accepts any channel name, e.g.
|
|
40
|
+
`new ConsoleDeliveryChannel('sms')`. Do not register it in production.
|
|
41
|
+
|
|
42
|
+
## Registering a custom channel
|
|
43
|
+
|
|
44
|
+
A channel is any `@Injectable()` class implementing `IDeliveryChannel` — a
|
|
45
|
+
`channel` name plus a `send()` method. Register it under `deliveryChannels`,
|
|
46
|
+
passing an `IDeliveryChannelProvider` (`{ channel, provider }`) so Nest can
|
|
47
|
+
instantiate it with full DI:
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import {
|
|
51
|
+
IDeliveryChannel,
|
|
52
|
+
NotificationChannelLike,
|
|
53
|
+
NotifyModule,
|
|
54
|
+
SendNotificationPayload,
|
|
55
|
+
} from '@nathapp/nestjs-notify';
|
|
56
|
+
import { Injectable, Module } from '@nestjs/common';
|
|
57
|
+
|
|
58
|
+
@Injectable()
|
|
59
|
+
export class WechatMpDeliveryChannel implements IDeliveryChannel {
|
|
60
|
+
readonly channel: NotificationChannelLike = 'wechat_mp';
|
|
61
|
+
|
|
62
|
+
async send(
|
|
63
|
+
payload: SendNotificationPayload,
|
|
64
|
+
renderedContent: string,
|
|
65
|
+
renderedSubject?: string,
|
|
66
|
+
): Promise<void> {
|
|
67
|
+
// call the WeChat subscribeMessage API
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@Module({
|
|
72
|
+
imports: [
|
|
73
|
+
NotifyModule.register({
|
|
74
|
+
deliveryChannels: [{ channel: 'wechat_mp', provider: WechatMpDeliveryChannel }],
|
|
75
|
+
}),
|
|
76
|
+
],
|
|
77
|
+
})
|
|
78
|
+
export class AppModule {}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`channel` on the instance and `channel` in the provider entry must be the same
|
|
82
|
+
string; the module uses the provider entry to build the DI injection token and
|
|
83
|
+
the instance's own `channel` as the registry key.
|
|
84
|
+
|
|
85
|
+
## Case sensitivity
|
|
86
|
+
|
|
87
|
+
Channel keys are **case- and separator-sensitive, end to end**. The DI token key
|
|
88
|
+
(`getDeliveryChannelToken`) and the `DeliveryChannelRegistry` `Map` key are both
|
|
89
|
+
the **raw channel string**, byte for byte. Therefore:
|
|
90
|
+
|
|
91
|
+
- `'EMAIL'` and `'email'` are **two different channels** with two different DI
|
|
92
|
+
tokens and two different registry entries.
|
|
93
|
+
- `'wechat-mp'` and `'wechat_mp'` are **two different channels** (as they always
|
|
94
|
+
were — the separator is never normalized).
|
|
95
|
+
|
|
96
|
+
History: `getDeliveryChannelToken` previously upper-cased the channel when
|
|
97
|
+
building its cache key, which folded **case** variants onto a single token
|
|
98
|
+
(`'EMAIL'` and `'email'` both became `DELIVERY_CHANNEL_EMAIL`). That case folding
|
|
99
|
+
has been fixed to raw-string keying. Separator variants were never collapsed.
|
|
100
|
+
Prefer the `NotificationChannel` enum members or a single lower-case convention
|
|
101
|
+
in your own code.
|
|
102
|
+
|
|
103
|
+
## The typo hazard
|
|
104
|
+
|
|
105
|
+
Because `NotificationChannelLike` is `NotificationChannel | (string & Record<never, never>)`, a
|
|
106
|
+
mistyped channel name is **no longer a compile error** — the widened type
|
|
107
|
+
deliberately accepts arbitrary strings. Two failure modes follow:
|
|
108
|
+
|
|
109
|
+
1. **At send time:** sending on an unregistered channel throws
|
|
110
|
+
`NotifyException(NotifyExceptionCode.CHANNEL_NOT_REGISTERED)` → HTTP **400**.
|
|
111
|
+
2. **Worse, silently:** `DefaultPreferenceService.updatePreference` delegates to
|
|
112
|
+
`IPreferenceRepository.upsertByUserAndChannel`, whose Prisma implementation
|
|
113
|
+
uses `update: { enabled }`. Saving a preference under a wrong channel does not
|
|
114
|
+
error — it upserts a row for that (wrong) channel key, and on a subsequent
|
|
115
|
+
call with the same wrong key **overwrites** the existing row's `enabled`
|
|
116
|
+
rather than surfacing the mistake.
|
|
117
|
+
|
|
118
|
+
If your code accepts **user-supplied** channel names, validate them against the
|
|
119
|
+
registry before persisting or sending:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { BadRequestException, Inject } from '@nestjs/common';
|
|
123
|
+
import { DELIVERY_CHANNEL_REGISTRY, DeliveryChannelRegistry } from '@nathapp/nestjs-notify';
|
|
124
|
+
|
|
125
|
+
constructor(
|
|
126
|
+
@Inject(DELIVERY_CHANNEL_REGISTRY) private readonly registry: DeliveryChannelRegistry,
|
|
127
|
+
) {}
|
|
128
|
+
|
|
129
|
+
setPreference(userId: string, tenantId: string, channel: string, enabled: boolean) {
|
|
130
|
+
if (!this.registry.has(channel)) {
|
|
131
|
+
throw new BadRequestException(`Unknown notification channel: ${channel}`);
|
|
132
|
+
}
|
|
133
|
+
return this.preferenceService.updatePreference(userId, tenantId, channel, enabled);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Preferences
|
|
138
|
+
|
|
139
|
+
A preference is keyed by `@@unique([userId, tenantId, channel])`, so there is at
|
|
140
|
+
most one row per user, tenant, and channel. Each row carries an `enabled: boolean`
|
|
141
|
+
and an optional `metadata: Record<string, any>`.
|
|
142
|
+
|
|
143
|
+
`metadata` is where **consent state** belongs. A boolean `enabled` alone cannot
|
|
144
|
+
model consent-gated transports: WeChat mini-program subscribe messages, for
|
|
145
|
+
example, require per-message user consent that can be `pending`, `granted`, or
|
|
146
|
+
`revoked`, and often carries a consent timestamp or scope token. Store that in
|
|
147
|
+
`metadata` alongside `enabled`.
|
|
148
|
+
|
|
149
|
+
Note: the shipped defaults **ignore `metadata` on write** —
|
|
150
|
+
`DefaultPreferenceService.updatePreference` hardcodes `metadata: {}`, and the
|
|
151
|
+
Prisma repository's `upsertByUserAndChannel` updates only `{ enabled }`. To
|
|
152
|
+
persist consent state in `metadata`, override the default preference service
|
|
153
|
+
(and/or repository) with an implementation that accepts and writes it.
|
|
154
|
+
|
|
155
|
+
## No controllers ship
|
|
156
|
+
|
|
157
|
+
This package exposes services, module registration, and interfaces only. It
|
|
158
|
+
ships **no controllers and no DTOs**. Validating a channel name, authorizing the
|
|
159
|
+
caller, shaping request bodies, and deciding which channels a user may configure
|
|
160
|
+
are all the consumer's responsibility.
|
|
161
|
+
|
|
162
|
+
## Queue processing
|
|
163
|
+
|
|
164
|
+
When enabling the notification processor, import the configured queue module
|
|
165
|
+
inside NotifyModule so its QueueService can resolve in the notification module.
|
|
166
|
+
A sibling import alone does not expose a non-global queue provider.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
const queue = QueueModule.register({
|
|
170
|
+
provider: QueueProviderType.BULLMQ,
|
|
171
|
+
options: { connection: { host: 'localhost', port: 6379 } },
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
NotifyModule.register({
|
|
175
|
+
enableProcessor: true,
|
|
176
|
+
imports: [queue],
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Import QueueModule and QueueProviderType from `@nathapp/nestjs-queue`.
|
|
181
|
+
For asynchronous registration, pass the same module in
|
|
182
|
+
`NotifyModule.registerAsync({ imports: [queue], ... })`.
|
package/codex.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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`
|
|
13
|
+
|
|
14
|
+
**Language:** TypeScript
|
|
15
|
+
|
|
16
|
+
**Key dependencies:** typescript
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
# CLAUDE.md — @nathapp/nestjs-notify
|
|
20
|
+
|
|
21
|
+
Notification management with templates, preferences and delivery strategies for NestJS. Management layer on top of `@nathapp/nestjs-notification` (which handles actual sending).
|
|
22
|
+
|
|
23
|
+
## Status: ✅ Complete (ADR-004 adopted)
|
|
24
|
+
|
|
25
|
+
## Directory Structure
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
lib/
|
|
29
|
+
├── constant/tokens.ts — DI tokens
|
|
30
|
+
├── delivery/ — TODO: delivery strategies (immediate, batched, digest, fallback chain)
|
|
31
|
+
├── dto/ — TODO: DTOs for notification operations
|
|
32
|
+
├── event/ — TODO: domain events (NotificationSent, DeliveryFailed, etc.)
|
|
33
|
+
├── exception/ — TODO: NotifyExceptionCode enum
|
|
34
|
+
├── interface/
|
|
35
|
+
│ ├── models/ — TODO: ITemplate, IPreference, IDeliveryLog
|
|
36
|
+
│ ├── repositories/ — TODO: repository interfaces
|
|
37
|
+
│ └── services/ — TODO: service interfaces
|
|
38
|
+
├── module/ — TODO: NotifyModule.register() / registerAsync()
|
|
39
|
+
├── service/ — TODO: DefaultNotifyService, DefaultTemplateService, etc.
|
|
40
|
+
└── template/ — TODO: Handlebars template engine integration
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## DI Tokens
|
|
44
|
+
|
|
45
|
+
**Repositories**: `TEMPLATE_REPOSITORY`, `PREFERENCE_REPOSITORY`, `DELIVERY_LOG_REPOSITORY`
|
|
46
|
+
|
|
47
|
+
**Services**: `NOTIFY_SERVICE`, `TEMPLATE_SERVICE`, `PREFERENCE_SERVICE`, `DELIVERY_SERVICE`, `DELIVERY_TRACKER`
|
|
48
|
+
|
|
49
|
+
## Dependencies
|
|
50
|
+
|
|
51
|
+
- `@nathapp/nestjs-tenant` (workspace) — tenant context
|
|
52
|
+
- `@nathapp/nestjs-common` ^3.0.0 — `AppException`
|
|
53
|
+
- `@nathapp/nestjs-notification` ^3.0.0 — actual email/SMS/push sending
|
|
54
|
+
- `@nestjs/event-emitter` — domain events
|
|
55
|
+
- `handlebars` ^4.7.8 — template rendering
|
|
56
|
+
|
|
57
|
+
## Architecture Notes
|
|
58
|
+
|
|
59
|
+
- **nestjs-notify** = management (templates, preferences, delivery tracking, retry/fallback)
|
|
60
|
+
- **nestjs-notification** (existing) = transport (send email via SES, SMS via Twilio, push via FCM)
|
|
61
|
+
- This package orchestrates WHEN and HOW to send; `nestjs-notification` handles the actual delivery
|
|
62
|
+
- Template rendering uses Handlebars — consumers register templates with variables
|
|
63
|
+
- Preferences: per-user, per-tenant channel preferences (email/SMS/push opt-in/out)
|
|
64
|
+
|
|
65
|
+
## ADR-004 Notes
|
|
66
|
+
|
|
67
|
+
All three repository interfaces (`ITemplateRepository`, `IPreferenceRepository`, `IDeliveryLogRepository`) now extend `IRepository<Domain, string>` from `@nathapp/nestjs-data`. This aligns them with the platform-wide repository contract (tenant, iam, account).
|
|
68
|
+
|
|
69
|
+
The tenant-guard pattern (ensuring tenant context before repository access) lives in `DefaultTemplateService` — it is not a separate guard class.
|
|
70
|
+
|
|
71
|
+
**No transactional flows** are introduced in nestjs-notify. Notification delivery spans external I/O (email/SMS/push providers) which cannot participate in a DB transaction. Failed deliveries are routed through the DLQ (`DefaultDlqService`) and retried via queue (BullMQ/Kafka/RabbitMQ) — a queue-only durability pattern, not a transaction pattern.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tokens';
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
__exportStar(require("./tokens"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/constant/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NotificationChannelLike } from '../interface/models';
|
|
2
|
+
export declare const TEMPLATE_REPOSITORY: unique symbol;
|
|
3
|
+
export declare const PREFERENCE_REPOSITORY: unique symbol;
|
|
4
|
+
export declare const DELIVERY_LOG_REPOSITORY: unique symbol;
|
|
5
|
+
export declare const NOTIFY_SERVICE: unique symbol;
|
|
6
|
+
export declare const TEMPLATE_SERVICE: unique symbol;
|
|
7
|
+
export declare const TEMPLATE_ENGINE: unique symbol;
|
|
8
|
+
export declare const PREFERENCE_SERVICE: unique symbol;
|
|
9
|
+
export declare const DLQ_SERVICE: unique symbol;
|
|
10
|
+
export declare const DELIVERY_CHANNEL_REGISTRY: unique symbol;
|
|
11
|
+
export declare const DELIVERY_TRACKER: unique symbol;
|
|
12
|
+
export declare const PROVIDER_EVENT_NORMALIZER: unique symbol;
|
|
13
|
+
export declare const NOTIFICATION_QUEUE_NAME = "notifications";
|
|
14
|
+
export declare const NOTIFY_MODULE_OPTIONS: unique symbol;
|
|
15
|
+
export declare function getDeliveryChannelToken(channel: NotificationChannelLike): symbol;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NOTIFY_MODULE_OPTIONS = exports.NOTIFICATION_QUEUE_NAME = exports.PROVIDER_EVENT_NORMALIZER = exports.DELIVERY_TRACKER = exports.DELIVERY_CHANNEL_REGISTRY = exports.DLQ_SERVICE = exports.PREFERENCE_SERVICE = exports.TEMPLATE_ENGINE = exports.TEMPLATE_SERVICE = exports.NOTIFY_SERVICE = exports.DELIVERY_LOG_REPOSITORY = exports.PREFERENCE_REPOSITORY = exports.TEMPLATE_REPOSITORY = void 0;
|
|
4
|
+
exports.getDeliveryChannelToken = getDeliveryChannelToken;
|
|
5
|
+
exports.TEMPLATE_REPOSITORY = Symbol('TEMPLATE_REPOSITORY');
|
|
6
|
+
exports.PREFERENCE_REPOSITORY = Symbol('PREFERENCE_REPOSITORY');
|
|
7
|
+
exports.DELIVERY_LOG_REPOSITORY = Symbol('DELIVERY_LOG_REPOSITORY');
|
|
8
|
+
exports.NOTIFY_SERVICE = Symbol('NOTIFY_SERVICE');
|
|
9
|
+
exports.TEMPLATE_SERVICE = Symbol('TEMPLATE_SERVICE');
|
|
10
|
+
exports.TEMPLATE_ENGINE = Symbol('TEMPLATE_ENGINE');
|
|
11
|
+
exports.PREFERENCE_SERVICE = Symbol('PREFERENCE_SERVICE');
|
|
12
|
+
exports.DLQ_SERVICE = Symbol('DLQ_SERVICE');
|
|
13
|
+
exports.DELIVERY_CHANNEL_REGISTRY = Symbol('DELIVERY_CHANNEL_REGISTRY');
|
|
14
|
+
exports.DELIVERY_TRACKER = Symbol('DELIVERY_TRACKER');
|
|
15
|
+
exports.PROVIDER_EVENT_NORMALIZER = Symbol('PROVIDER_EVENT_NORMALIZER');
|
|
16
|
+
exports.NOTIFICATION_QUEUE_NAME = 'notifications';
|
|
17
|
+
exports.NOTIFY_MODULE_OPTIONS = Symbol('NOTIFY_MODULE_OPTIONS');
|
|
18
|
+
const deliveryChannelTokenCache = new Map();
|
|
19
|
+
function getDeliveryChannelToken(channel) {
|
|
20
|
+
const key = `DELIVERY_CHANNEL_${channel}`;
|
|
21
|
+
let token = deliveryChannelTokenCache.get(key);
|
|
22
|
+
if (!token) {
|
|
23
|
+
token = Symbol(key);
|
|
24
|
+
deliveryChannelTokenCache.set(key, token);
|
|
25
|
+
}
|
|
26
|
+
return token;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../lib/constant/tokens.ts"],"names":[],"mappings":";;;AAkCA,0DAQC;AAxCY,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AACpD,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACxD,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAE5D,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC1C,QAAA,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC9C,QAAA,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAC5C,QAAA,kBAAkB,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAClD,QAAA,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AACpC,QAAA,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAChE,QAAA,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC9C,QAAA,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEhE,QAAA,uBAAuB,GAAG,eAAe,CAAC;AAE1C,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAErE,MAAM,yBAAyB,GAAG,IAAI,GAAG,EAAkB,CAAC;AAe5D,SAAgB,uBAAuB,CAAC,OAAgC;IACtE,MAAM,GAAG,GAAG,oBAAoB,OAAO,EAAE,CAAC;IAC1C,IAAI,KAAK,GAAG,yBAAyB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,yBAAyB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { NotificationChannelLike } from '../interface/models';
|
|
2
|
+
import type { IDeliveryChannel, SendNotificationPayload } from '../interface/services';
|
|
3
|
+
export declare class ConsoleDeliveryChannel implements IDeliveryChannel {
|
|
4
|
+
readonly channel: NotificationChannelLike;
|
|
5
|
+
private readonly logger;
|
|
6
|
+
constructor(channel?: NotificationChannelLike);
|
|
7
|
+
send(payload: SendNotificationPayload, _renderedContent: string, _renderedSubject?: string): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 ConsoleDeliveryChannel_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ConsoleDeliveryChannel = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const models_1 = require("../interface/models");
|
|
16
|
+
let ConsoleDeliveryChannel = ConsoleDeliveryChannel_1 = class ConsoleDeliveryChannel {
|
|
17
|
+
constructor(channel = models_1.NotificationChannel.EMAIL) {
|
|
18
|
+
this.logger = new common_1.Logger(ConsoleDeliveryChannel_1.name);
|
|
19
|
+
this.channel = channel;
|
|
20
|
+
}
|
|
21
|
+
async send(payload, _renderedContent, _renderedSubject) {
|
|
22
|
+
var _a;
|
|
23
|
+
this.logger.log(`[${payload.channel}] template: ${(_a = payload.templateCode) !== null && _a !== void 0 ? _a : '(none)'}`);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.ConsoleDeliveryChannel = ConsoleDeliveryChannel;
|
|
27
|
+
exports.ConsoleDeliveryChannel = ConsoleDeliveryChannel = ConsoleDeliveryChannel_1 = __decorate([
|
|
28
|
+
(0, common_1.Injectable)(),
|
|
29
|
+
__metadata("design:paramtypes", [String])
|
|
30
|
+
], ConsoleDeliveryChannel);
|
|
31
|
+
//# sourceMappingURL=console-delivery.channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-delivery.channel.js","sourceRoot":"","sources":["../../lib/delivery/console-delivery.channel.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,gDAA0D;AAcnD,IAAM,sBAAsB,8BAA5B,MAAM,sBAAsB;IAIjC,YAAY,UAAmC,4BAAmB,CAAC,KAAK;QAFvD,WAAM,GAAG,IAAI,eAAM,CAAC,wBAAsB,CAAC,IAAI,CAAC,CAAC;QAGhE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,IAAI,CACR,OAAgC,EAChC,gBAAwB,EACxB,gBAAyB;;QAEzB,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,IAAI,OAAO,CAAC,OAAO,eAAe,MAAA,OAAO,CAAC,YAAY,mCAAI,QAAQ,EAAE,CACrE,CAAC;IACJ,CAAC;CACF,CAAA;AAjBY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;;GACA,sBAAsB,CAiBlC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Logger } from '@nestjs/common';
|
|
2
|
+
import type { IDeliveryChannel } from '../interface/services';
|
|
3
|
+
import type { NotificationChannelLike } from '../interface/models';
|
|
4
|
+
export declare class DeliveryChannelRegistry {
|
|
5
|
+
protected readonly logger: Logger;
|
|
6
|
+
private readonly channels;
|
|
7
|
+
register(channel: IDeliveryChannel): void;
|
|
8
|
+
get(channel: NotificationChannelLike): IDeliveryChannel | undefined;
|
|
9
|
+
has(channel: NotificationChannelLike): boolean;
|
|
10
|
+
getAll(): IDeliveryChannel[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 DeliveryChannelRegistry_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DeliveryChannelRegistry = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
let DeliveryChannelRegistry = DeliveryChannelRegistry_1 = class DeliveryChannelRegistry {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.logger = new common_1.Logger(DeliveryChannelRegistry_1.name);
|
|
15
|
+
this.channels = new Map();
|
|
16
|
+
}
|
|
17
|
+
register(channel) {
|
|
18
|
+
this.channels.set(channel.channel, channel);
|
|
19
|
+
this.logger.log(`Registered delivery channel: ${channel.channel}`);
|
|
20
|
+
}
|
|
21
|
+
get(channel) {
|
|
22
|
+
return this.channels.get(channel);
|
|
23
|
+
}
|
|
24
|
+
has(channel) {
|
|
25
|
+
return this.channels.has(channel);
|
|
26
|
+
}
|
|
27
|
+
getAll() {
|
|
28
|
+
return Array.from(this.channels.values());
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
exports.DeliveryChannelRegistry = DeliveryChannelRegistry;
|
|
32
|
+
exports.DeliveryChannelRegistry = DeliveryChannelRegistry = DeliveryChannelRegistry_1 = __decorate([
|
|
33
|
+
(0, common_1.Injectable)()
|
|
34
|
+
], DeliveryChannelRegistry);
|
|
35
|
+
//# sourceMappingURL=delivery-channel.registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery-channel.registry.js","sourceRoot":"","sources":["../../lib/delivery/delivery-channel.registry.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAoD;AAK7C,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAA7B;QACc,WAAM,GAAG,IAAI,eAAM,CAAC,yBAAuB,CAAC,IAAI,CAAC,CAAC;QACpD,aAAQ,GAAG,IAAI,GAAG,EAA6C,CAAC;IAkBnF,CAAC;IAhBC,QAAQ,CAAC,OAAyB;QAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,gCAAgC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,GAAG,CAAC,OAAgC;QAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,GAAG,CAAC,OAAgC;QAClC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF,CAAA;AApBY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;GACA,uBAAuB,CAoBnC"}
|