2022-07-06 23:19:05 +02:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/pocketbase/pocketbase/daos"
|
|
|
|
"github.com/pocketbase/pocketbase/models"
|
|
|
|
"github.com/pocketbase/pocketbase/models/schema"
|
2022-11-26 14:42:45 +02:00
|
|
|
"github.com/pocketbase/pocketbase/models/settings"
|
2023-01-15 17:00:28 +02:00
|
|
|
"github.com/pocketbase/pocketbase/tools/auth"
|
2023-01-27 22:19:08 +02:00
|
|
|
"github.com/pocketbase/pocketbase/tools/hook"
|
2022-07-06 23:19:05 +02:00
|
|
|
"github.com/pocketbase/pocketbase/tools/mailer"
|
|
|
|
"github.com/pocketbase/pocketbase/tools/search"
|
|
|
|
"github.com/pocketbase/pocketbase/tools/subscriptions"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v5"
|
|
|
|
)
|
|
|
|
|
2023-01-27 22:19:08 +02:00
|
|
|
type BaseCollectionEvent struct {
|
|
|
|
Collection *models.Collection
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *BaseCollectionEvent) Tags() []string {
|
|
|
|
if e.Collection == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
tags := make([]string, 0, 2)
|
|
|
|
|
|
|
|
if e.Collection.Id != "" {
|
|
|
|
tags = append(tags, e.Collection.Id)
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.Collection.Name != "" {
|
|
|
|
tags = append(tags, e.Collection.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return tags
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Serve events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2022-11-26 14:42:45 +02:00
|
|
|
type BootstrapEvent struct {
|
|
|
|
App App
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
type ServeEvent struct {
|
|
|
|
App App
|
|
|
|
Router *echo.Echo
|
|
|
|
}
|
|
|
|
|
2022-12-02 16:36:15 +02:00
|
|
|
type ApiErrorEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Error error
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Model DAO events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2023-01-27 22:19:08 +02:00
|
|
|
var _ hook.Tagger = (*ModelEvent)(nil)
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
type ModelEvent struct {
|
|
|
|
Dao *daos.Dao
|
|
|
|
Model models.Model
|
|
|
|
}
|
|
|
|
|
2023-01-27 22:19:08 +02:00
|
|
|
func (e *ModelEvent) Tags() []string {
|
|
|
|
if e.Model == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if r, ok := e.Model.(*models.Record); ok && r.Collection() != nil {
|
|
|
|
return []string{r.Collection().Id, r.Collection().Name}
|
|
|
|
}
|
|
|
|
|
|
|
|
return []string{e.Model.TableName()}
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Mailer events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2022-10-30 10:28:14 +02:00
|
|
|
type MailerRecordEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
MailClient mailer.Mailer
|
2022-11-21 14:53:05 +02:00
|
|
|
Message *mailer.Message
|
2022-10-30 10:28:14 +02:00
|
|
|
Record *models.Record
|
2022-07-06 23:19:05 +02:00
|
|
|
Meta map[string]any
|
|
|
|
}
|
|
|
|
|
|
|
|
type MailerAdminEvent struct {
|
|
|
|
MailClient mailer.Mailer
|
2022-11-21 14:53:05 +02:00
|
|
|
Message *mailer.Message
|
2022-07-06 23:19:05 +02:00
|
|
|
Admin *models.Admin
|
|
|
|
Meta map[string]any
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Realtime API events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
type RealtimeConnectEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Client subscriptions.Client
|
|
|
|
}
|
|
|
|
|
2022-12-02 14:25:36 +02:00
|
|
|
type RealtimeDisconnectEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Client subscriptions.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
type RealtimeMessageEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Client subscriptions.Client
|
|
|
|
Message *subscriptions.Message
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
type RealtimeSubscribeEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Client subscriptions.Client
|
|
|
|
Subscriptions []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Settings API events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
type SettingsListEvent struct {
|
|
|
|
HttpContext echo.Context
|
2022-11-26 14:42:45 +02:00
|
|
|
RedactedSettings *settings.Settings
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type SettingsUpdateEvent struct {
|
|
|
|
HttpContext echo.Context
|
2022-11-26 14:42:45 +02:00
|
|
|
OldSettings *settings.Settings
|
|
|
|
NewSettings *settings.Settings
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2022-12-03 14:50:02 +02:00
|
|
|
// Record CRUD API events data
|
2022-07-06 23:19:05 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
type RecordsListEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Records []*models.Record
|
|
|
|
Result *search.Result
|
|
|
|
}
|
|
|
|
|
|
|
|
type RecordViewEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
}
|
|
|
|
|
|
|
|
type RecordCreateEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
}
|
|
|
|
|
|
|
|
type RecordUpdateEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
}
|
|
|
|
|
|
|
|
type RecordDeleteEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------
|
2022-12-03 14:50:02 +02:00
|
|
|
// Auth Record API events data
|
2022-07-06 23:19:05 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
type RecordAuthEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
2022-12-03 14:50:02 +02:00
|
|
|
Record *models.Record
|
|
|
|
Token string
|
|
|
|
Meta any
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2023-01-15 17:00:28 +02:00
|
|
|
type RecordAuthWithPasswordEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2023-01-15 17:00:28 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
Identity string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
|
|
|
type RecordAuthWithOAuth2Event struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2023-01-15 17:00:28 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
OAuth2User *auth.AuthUser
|
|
|
|
}
|
|
|
|
|
|
|
|
type RecordAuthRefreshEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2023-01-15 17:00:28 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
}
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
type RecordRequestPasswordResetEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
2022-12-03 14:50:02 +02:00
|
|
|
Record *models.Record
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
type RecordConfirmPasswordResetEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
2022-12-03 14:50:02 +02:00
|
|
|
Record *models.Record
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
type RecordRequestVerificationEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
2022-12-03 14:50:02 +02:00
|
|
|
Record *models.Record
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
type RecordConfirmVerificationEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
2022-12-03 14:50:02 +02:00
|
|
|
Record *models.Record
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
type RecordRequestEmailChangeEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
2022-12-03 14:50:02 +02:00
|
|
|
Record *models.Record
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
type RecordConfirmEmailChangeEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
2022-10-30 10:28:14 +02:00
|
|
|
Record *models.Record
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-10-30 10:28:14 +02:00
|
|
|
type RecordListExternalAuthsEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-08-31 12:38:31 +02:00
|
|
|
HttpContext echo.Context
|
2022-10-30 10:28:14 +02:00
|
|
|
Record *models.Record
|
2022-08-31 12:38:31 +02:00
|
|
|
ExternalAuths []*models.ExternalAuth
|
|
|
|
}
|
|
|
|
|
2022-10-30 10:28:14 +02:00
|
|
|
type RecordUnlinkExternalAuthEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-08-31 12:38:31 +02:00
|
|
|
HttpContext echo.Context
|
2022-10-30 10:28:14 +02:00
|
|
|
Record *models.Record
|
2022-08-31 12:38:31 +02:00
|
|
|
ExternalAuth *models.ExternalAuth
|
2022-07-06 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2022-12-03 14:50:02 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Admin API events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
type AdminsListEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admins []*models.Admin
|
|
|
|
Result *search.Result
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminViewEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminCreateEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminUpdateEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminDeleteEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminAuthEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
2023-01-15 17:00:28 +02:00
|
|
|
type AdminAuthWithPasswordEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
Identity string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminAuthRefreshEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminRequestPasswordResetEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
}
|
|
|
|
|
|
|
|
type AdminConfirmPasswordResetEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Admin *models.Admin
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// Collection API events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
type CollectionsListEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Collections []*models.Collection
|
|
|
|
Result *search.Result
|
|
|
|
}
|
|
|
|
|
|
|
|
type CollectionViewEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type CollectionCreateEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type CollectionUpdateEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
type CollectionDeleteEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
}
|
|
|
|
|
2022-08-07 19:58:21 +02:00
|
|
|
type CollectionsImportEvent struct {
|
|
|
|
HttpContext echo.Context
|
|
|
|
Collections []*models.Collection
|
|
|
|
}
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
// -------------------------------------------------------------------
|
|
|
|
// File API events data
|
|
|
|
// -------------------------------------------------------------------
|
|
|
|
|
|
|
|
type FileDownloadEvent struct {
|
2023-01-27 22:19:08 +02:00
|
|
|
BaseCollectionEvent
|
|
|
|
|
2022-07-06 23:19:05 +02:00
|
|
|
HttpContext echo.Context
|
|
|
|
Record *models.Record
|
|
|
|
FileField *schema.SchemaField
|
|
|
|
ServedPath string
|
|
|
|
ServedName string
|
|
|
|
}
|