-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/whatsapp #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/whatsapp #12
Changes from all commits
6aadbc9
ada99be
c486b99
571aecc
73009e2
4210d2c
96a80f6
aac7189
81e390e
746f00e
2b5c2f4
0e0de92
804543a
5e2d970
e2c1e12
b27dd5d
d250e60
69ae2f6
b6d7cb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,62 +135,37 @@ const pushSender = new AwsSnsPushSender({ | |
|
|
||
| ## 💾 Repositories | ||
|
|
||
| > **Note**: Repository implementations are provided by separate database packages. | ||
| > Install the appropriate package for your database: | ||
|
|
||
| ### MongoDB | ||
|
|
||
| Install the MongoDB package: | ||
|
|
||
| ```bash | ||
| npm install @ciscode/notification-kit-mongodb | ||
| ``` | ||
| ### MongoDB with Mongoose | ||
|
|
||
| ```typescript | ||
| import { MongooseNotificationRepository } from "@ciscode/notification-kit-mongodb"; | ||
| import mongoose from "mongoose"; | ||
| import { MongooseNotificationRepository } from "@ciscode/notification-kit/infra"; | ||
|
|
||
| const connection = await mongoose.createConnection("mongodb://localhost:27017/mydb"); | ||
| const repository = new MongooseNotificationRepository(connection); | ||
| ``` | ||
|
|
||
| ### PostgreSQL | ||
|
|
||
| Install the PostgreSQL package: | ||
|
|
||
| ```bash | ||
| npm install @ciscode/notification-kit-postgres | ||
| const repository = new MongooseNotificationRepository( | ||
| connection, | ||
| "notifications", // collection name (optional) | ||
| ); | ||
|
Comment on lines
144
to
+149
|
||
| ``` | ||
|
|
||
| ### Custom Repository | ||
| **Peer Dependency**: `mongoose` | ||
|
|
||
| Implement the `INotificationRepository` interface: | ||
| ### In-Memory (Testing) | ||
|
|
||
| ```typescript | ||
| import type { INotificationRepository, Notification } from "@ciscode/notification-kit"; | ||
| import { InMemoryNotificationRepository } from "@ciscode/notification-kit/infra"; | ||
|
|
||
| class MyCustomRepository implements INotificationRepository { | ||
| async create(data: Omit<Notification, "id" | "createdAt" | "updatedAt">): Promise<Notification> { | ||
| // Your implementation | ||
| } | ||
| const repository = new InMemoryNotificationRepository(); | ||
|
|
||
| async findById(id: string): Promise<Notification | null> { | ||
| // Your implementation | ||
| } | ||
| // For testing - clear all data | ||
| repository.clear(); | ||
|
|
||
| // ... implement other methods | ||
| } | ||
| // For testing - get all notifications | ||
| const all = repository.getAll(); | ||
| ``` | ||
|
|
||
| ### Schema Reference | ||
|
|
||
| The MongoDB schema is exported as a reference: | ||
|
|
||
| ```typescript | ||
| import { notificationSchemaDefinition } from "@ciscode/notification-kit/infra"; | ||
|
|
||
| // Use this as a reference for your own schema implementations | ||
| ``` | ||
| **No dependencies** | ||
|
|
||
| ## 🛠️ Utility Providers | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,12 +3,12 @@ | |||||||||||
| * | ||||||||||||
| * This layer contains concrete implementations of the core interfaces. | ||||||||||||
| * It includes: | ||||||||||||
| * - Notification senders (email, SMS, push) | ||||||||||||
| * - Repository schemas (reference implementations) | ||||||||||||
| * - Notification senders (email, SMS, push, WhatsApp) | ||||||||||||
| * - Repositories (MongoDB, in-memory) | ||||||||||||
| * - Utility providers (ID generator, datetime, templates, events) | ||||||||||||
| * | ||||||||||||
| * NOTE: Repository implementations are provided by separate database packages. | ||||||||||||
| * Install the appropriate package: @ciscode/notification-kit-mongodb, etc. | ||||||||||||
| * These implementations are internal and not exported by default. | ||||||||||||
| * They can be used when configuring the NestJS module. | ||||||||||||
|
Comment on lines
+10
to
+11
|
||||||||||||
| * These implementations are internal and not exported by default. | |
| * They can be used when configuring the NestJS module. | |
| * These implementations are part of the public infrastructure layer and are | |
| * exported so they can be used when configuring the NestJS module or for | |
| * advanced/custom integrations. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,178 @@ | ||||||||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||||||||
| INotificationRepository, | ||||||||||||||||||||||||||||||||
| Notification, | ||||||||||||||||||||||||||||||||
| NotificationQueryCriteria, | ||||||||||||||||||||||||||||||||
| } from "../../../core"; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||
| * In-memory repository implementation for testing/simple cases | ||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||
| export class InMemoryNotificationRepository implements INotificationRepository { | ||||||||||||||||||||||||||||||||
| private notifications: Map<string, Notification> = new Map(); | ||||||||||||||||||||||||||||||||
| private idCounter = 1; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| async create( | ||||||||||||||||||||||||||||||||
| _notification: Omit<Notification, "id" | "createdAt" | "updatedAt">, | ||||||||||||||||||||||||||||||||
| ): Promise<Notification> { | ||||||||||||||||||||||||||||||||
| const now = new Date().toISOString(); | ||||||||||||||||||||||||||||||||
| const id = `notif_${this.idCounter++}`; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const notification: Notification = { | ||||||||||||||||||||||||||||||||
| id, | ||||||||||||||||||||||||||||||||
| ..._notification, | ||||||||||||||||||||||||||||||||
| createdAt: now, | ||||||||||||||||||||||||||||||||
| updatedAt: now, | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| this.notifications.set(id, notification); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return notification; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| async findById(_id: string): Promise<Notification | null> { | ||||||||||||||||||||||||||||||||
| return this.notifications.get(_id) || null; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| async find(_criteria: NotificationQueryCriteria): Promise<Notification[]> { | ||||||||||||||||||||||||||||||||
| let results = Array.from(this.notifications.values()); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Apply filters | ||||||||||||||||||||||||||||||||
| if (_criteria.recipientId) { | ||||||||||||||||||||||||||||||||
| results = results.filter((n) => n.recipient.id === _criteria.recipientId); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (_criteria.channel) { | ||||||||||||||||||||||||||||||||
| results = results.filter((n) => n.channel === _criteria.channel); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (_criteria.status) { | ||||||||||||||||||||||||||||||||
| results = results.filter((n) => n.status === _criteria.status); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (_criteria.priority) { | ||||||||||||||||||||||||||||||||
| results = results.filter((n) => n.priority === _criteria.priority); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (_criteria.fromDate) { | ||||||||||||||||||||||||||||||||
| results = results.filter((n) => n.createdAt >= _criteria.fromDate!); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (_criteria.toDate) { | ||||||||||||||||||||||||||||||||
| results = results.filter((n) => n.createdAt <= _criteria.toDate!); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Sort by createdAt descending | ||||||||||||||||||||||||||||||||
| results.sort((a, b) => (b.createdAt > a.createdAt ? 1 : -1)); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Apply pagination | ||||||||||||||||||||||||||||||||
| const offset = _criteria.offset || 0; | ||||||||||||||||||||||||||||||||
| const limit = _criteria.limit || 10; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return results.slice(offset, offset + limit); | ||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+71
|
||||||||||||||||||||||||||||||||
| const offset = _criteria.offset || 0; | |
| const limit = _criteria.limit || 10; | |
| return results.slice(offset, offset + limit); | |
| const offset = _criteria.offset ?? 0; | |
| if (typeof _criteria.limit === "number") { | |
| return results.slice(offset, offset + _criteria.limit); | |
| } | |
| if (typeof _criteria.offset === "number") { | |
| return results.slice(offset); | |
| } | |
| return results; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,6 @@ | ||
| /** | ||
| * Repository schemas and types | ||
| * | ||
| * NOTE: Concrete repository implementations are provided by separate packages. | ||
| * Install the appropriate database package: | ||
| * - @ciscode/notification-kit-mongodb | ||
| * - @ciscode/notification-kit-postgres | ||
| * - etc. | ||
| * | ||
| * These schemas serve as reference for implementing your own repository. | ||
| */ | ||
|
|
||
| // MongoDB/Mongoose schema (reference) | ||
| // MongoDB/Mongoose repository | ||
| export * from "./mongoose/notification.schema"; | ||
| export * from "./mongoose/mongoose.repository"; | ||
|
Comment on lines
+1
to
+3
|
||
|
|
||
| // In-memory repository | ||
| export * from "./in-memory/in-memory.repository"; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README examples import from
@ciscode/notification-kit/infra, butpackage.jsononly exports the root entry ".". This subpath import will fail in Node (and often in TS). Either update docs to import from@ciscode/notification-kitor add an explicit./infrasubpath export.