webhooks: endpoint API, fan-out and delivery log43fa43f13 days ago122 lines · 4.9 KB | 1 | import type { Database } from '@ghost/db'; |
| 2 | import { Module } |
| 3 | import { ConfigModule, ConfigService |
| 4 | import { AuthModule } |
| 5 | |
| 6 | import { AppController } |
| 7 | import { AppService } |
| 8 | import { DATABASE, DatabaseModule |
| 9 | import { GitModule } |
| 10 | import { createAuth } |
| 11 | import { |
| 12 | emailVerificationEnabled, |
| 13 | MailModule, |
| 14 | mailConfigured, |
| 15 | } from './mail/mail.module.js'; |
| 16 | import { MailService } |
| 17 | import { CollaboratorsModule } |
| 18 | import { WebhooksModule } |
| 19 | import { EmailsModule } |
| 20 | import { GpgKeysModule } |
| 21 | import { IssuesModule } |
| 22 | import { OrganizationsModule } |
| 23 | import { AvatarStorageService } |
| 24 | import { AvatarsModule } |
| 25 | import { PullRequestsModule } |
| 26 | import { ReleasesModule } |
| 27 | import { BranchesModule } |
| 28 | import { NotificationsModule } |
| 29 | import { RepositoriesModule } |
| 30 | import { SshKeysModule } |
| 31 | import { UserModule } |
| 32 | import { BranchesService } |
| 33 | import { RepositoryAccessService } |
| 34 | import { WalService } |
| 35 | import { S3Service } |
| 36 | import { AppStatsService } |
| 37 | import { UsersService } |
| 38 | |
| 39 | @Module({ |
| 40 | imports: [ |
| 41 | ConfigModule.forRoot({ |
| 42 | isGlobal: true, |
| 43 | // `.env` interpolates values (e.g. BETTER_AUTH_URL=http://localhost:${API_PORT}), which dotenv does not expand on its own. |
| 44 | expandVariables: true, |
| 45 | envFilePath: ['.env.local', |
| 46 | }), |
| 47 | DatabaseModule, |
| 48 | MailModule, |
| 49 | AuthModule.forRootAsync({ |
| 50 | imports: [DatabaseModule, |
| 51 | inject: [DATABASE, |
| 52 | useFactory: ( |
| 53 | db: Database |
| 54 | config: ConfigService |
| 55 | mail: MailService |
| 56 | avatars: AvatarStorageService |
| 57 | ) => ({ |
| 58 | auth: createAuth(db |
| 59 | secret: config.getOrThrow |
| 60 | baseURL: config.getOrThrow |
| 61 | trustedOrigins: config |
| 62 | .get<string>( |
| 63 | .split(',') |
| 64 | .map((origin) |
| 65 | .filter(Boolean), |
| 66 | cookieDomain: config.get |
| 67 | webAppUrl: config.get |
| 68 | sendChangeEmail: mailConfigured(config |
| 69 | ? ({ email, |
| 70 | mail.sendChangeEmailEmail(email |
| 71 | name, |
| 72 | newEmail, |
| 73 | approveUrl: url, |
| 74 | }) |
| 75 | : undefined, |
| 76 | onOrganizationDeleted: (organizationId) |
| 77 | avatars.remove(organizationId |
| 78 | sendOrganizationInvitation: mailConfigured(config |
| 79 | ? ({ email, |
| 80 | mail.sendOrganizationInvitationEmail(email |
| 81 | ...context, |
| 82 | acceptUrl: url, |
| 83 | }) |
| 84 | : undefined, |
| 85 | sendResetPassword: mailConfigured(config |
| 86 | ? ({ email, |
| 87 | mail.sendResetPasswordEmail(email |
| 88 | : undefined, |
| 89 | sendVerificationEmail: emailVerificationEnabled(config |
| 90 | ? ({ email, |
| 91 | mail.sendVerificationEmail(email |
| 92 | : undefined, |
| 93 | }), |
| 94 | }), |
| 95 | }), |
| 96 | RepositoriesModule, |
| 97 | OrganizationsModule, |
| 98 | PullRequestsModule, |
| 99 | IssuesModule, |
| 100 | ReleasesModule, |
| 101 | BranchesModule, |
| 102 | NotificationsModule, |
| 103 | CollaboratorsModule, |
| 104 | WebhooksModule, |
| 105 | EmailsModule, |
| 106 | GpgKeysModule, |
| 107 | SshKeysModule, |
| 108 | GitModule, |
| 109 | UserModule, |
| 110 | ], |
| 111 | controllers: [AppController], |
| 112 | providers: [ |
| 113 | AppService, |
| 114 | AppStatsService, |
| 115 | UsersService, |
| 116 | S3Service, |
| 117 | WalService, |
| 118 | BranchesService, |
| 119 | RepositoryAccessService, |
| 120 | ], |
| 121 | }) |
| 122 | export class AppModule |
from
'
@nestjs/common
'
;
}
from
'
@nestjs/config
'
;
from
'
@thallesp/nestjs-better-auth
'
;
from
'
./app.controller.js
'
;
from
'
./app.service.js
'
;
}
from
'
./database/database.module.js
'
;
from
'
./git/git.module.js
'
;
from
'
./lib/auth.js
'
;
from
'
./mail/mail.service.js
'
;
from
'
./resources/collaborators/collaborators.module.js
'
;
from
'
./resources/webhooks/webhooks.module.js
'
;
from
'
./resources/emails/emails.module.js
'
;
from
'
./resources/gpg-keys/gpg-keys.module.js
'
;
from
'
./resources/issues/issues.module.js
'
;
from
'
./resources/organizations/organizations.module.js
'
;
from
'
./services/avatars/avatar-storage.service.js
'
;
from
'
./avatars/avatars.module.js
'
;
from
'
./resources/pull-requests/pull-requests.module.js
'
;
from
'
./resources/releases/releases.module.js
'
;
from
'
./resources/branches/branches.module.js
'
;
from
'
./resources/notifications/notifications.module.js
'
;
from
'
./resources/repositories/repositories.module.js
'
;
from
'
./resources/ssh-keys/ssh-keys.module.js
'
;
from
'
./resources/user/user.module.js
'
;
from
'
./services/git/branches/branches.service.js
'
;
from
'
./services/git/repository-access/repository-access.service.js
'
;
from
'
./services/git/wal/wal.service.js
'
;
from
'
./services/s3/s3.service.js
'
;
from
'
./services/stats/app-stats.service.js
'
;
from
'
./services/users/users.service.js
'
;
'
.env
'
,
'
../../.env
'
]
,
MailModule
,
AvatarsModule
]
,
ConfigService
,
MailService
,
AvatarStorageService
]
,
,
,
,
,
,
{
<
string
>
(
'
BETTER_AUTH_SECRET
'
)
,
<
string
>
(
'
BETTER_AUTH_URL
'
)
,
'
AUTH_TRUSTED_ORIGINS
'
,
'
http://localhost:3000
'
)
=>
origin
.
trim
())
<
string
>
(
'
AUTH_COOKIE_DOMAIN
'
)
,
<
string
>
(
'
WEB_APP_URL
'
,
'
http://localhost:3000
'
)
,
)
name
,
newEmail
,
url
}
)
=>
,
{
=>
)
,
)
url
,
...
context
}
)
=>
,
{
)
name
,
url
}
)
=>
,
{
name
,
resetUrl
:
url
}
)
)
name
,
url
}
)
=>
,
{
name
,
verifyUrl
:
url
}
)
{}