Refactor: Simplify notifications plugin configuration, remove unused code, and improve channel handling

This commit is contained in:
2025-09-28 13:43:01 +02:00
parent bb963a4da4
commit 9f78d3ef72
13 changed files with 152 additions and 626 deletions

View File

@@ -1,44 +1,5 @@
import type { Config, CollectionConfig, Access, Field } from 'payload'
import type * as webpush from 'web-push'
/**
* Configuration for a relationship field in the notifications collection
*/
export interface NotificationRelationship {
/** Field name in the attachments group */
name: string
/** Target collection slug to relate to */
relationTo: string
/** Label displayed in admin UI */
label?: string
/** Whether this relationship is required */
required?: boolean
/** Allow multiple selections */
hasMany?: boolean
}
/**
* Collection configuration options
*/
export interface NotificationCollectionConfig {
/** Collection slug */
slug?: string
/** Collection labels for admin UI */
labels?: {
singular?: string
plural?: string
}
}
/**
* Access control configuration for notifications collection
*/
export interface NotificationAccess {
read?: Access
create?: Access
update?: Access
delete?: Access
}
import type {CollectionConfig, Config} from 'payload'
import type {RequestOptions} from 'web-push'
/**
* Web push subscription data structure
@@ -61,8 +22,6 @@ export interface NotificationChannel {
name: string
/** Channel description */
description?: string
/** Default enabled state for new subscriptions */
defaultEnabled?: boolean
}
/**
@@ -78,7 +37,7 @@ export interface WebPushConfig {
/** Enable web push notifications */
enabled?: boolean
/** Custom push notification options */
options?: webpush.RequestOptions
options?: RequestOptions
/** Automatically send push notifications when notifications are created */
autoPush?: boolean
/** Custom notification content transformer */
@@ -93,8 +52,8 @@ export interface WebPushConfig {
tag?: string
requireInteraction?: boolean
}
/**
* Custom hook to find push subscriptions for a notification
/**
* Custom hook to find push subscriptions for a notification
* This allows implementing anonymous notifications or custom recipient logic
* If not provided, defaults to user-based subscriptions
*/
@@ -106,20 +65,17 @@ export interface WebPushConfig {
*/
export interface NotificationsPluginOptions {
/** Collection configuration */
collections?: NotificationCollectionConfig
/** Array of configurable relationship fields */
relationships?: NotificationRelationship[]
/** Custom access control functions */
access?: NotificationAccess
/** Additional custom fields to add to the collection */
fields?: Field[]
collectionOverrides?: {
notifications: (config: CollectionConfig) => CollectionConfig
pushSubscriptions: (config: CollectionConfig) => CollectionConfig
}
/** Web push notification configuration */
webPush?: WebPushConfig
/** Notification channels configuration */
channels?: NotificationChannel[]
channels: NotificationChannel[]
}
/**
* Plugin function type
*/
export type NotificationsPlugin = (options?: NotificationsPluginOptions) => (config: Config) => Config
export type NotificationsPlugin = (options?: NotificationsPluginOptions) => (config: Config) => Config