@stamhoofd/backend 2.116.0 → 2.117.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/migrations.ts +1 -1
- package/package.json +10 -10
- package/src/audit-logs/DocumentTemplateLogger.ts +1 -1
- package/src/audit-logs/EmailAddressLogger.ts +1 -1
- package/src/audit-logs/EmailLogger.ts +1 -1
- package/src/audit-logs/EmailTemplateLogger.ts +1 -1
- package/src/audit-logs/EventLogger.ts +1 -1
- package/src/audit-logs/GroupLogger.ts +1 -1
- package/src/audit-logs/MemberLogger.ts +1 -1
- package/src/audit-logs/MemberPlatformMembershipLogger.ts +1 -1
- package/src/audit-logs/MemberResponsibilityRecordLogger.ts +1 -1
- package/src/audit-logs/ModelLogger.ts +25 -16
- package/src/audit-logs/OrderLogger.ts +1 -1
- package/src/audit-logs/OrganizationLogger.ts +23 -3
- package/src/audit-logs/OrganizationRegistrationPeriodLogger.ts +1 -1
- package/src/audit-logs/PaymentLogger.ts +1 -1
- package/src/audit-logs/PlatformLogger.ts +1 -1
- package/src/audit-logs/RegistrationLogger.ts +1 -1
- package/src/audit-logs/RegistrationPeriodLogger.ts +1 -1
- package/src/audit-logs/StripeAccountLogger.ts +1 -1
- package/src/audit-logs/UserLogger.ts +1 -1
- package/src/audit-logs/WebshopLogger.ts +1 -1
- package/src/audit-logs/init.ts +40 -0
- package/src/boot.ts +3 -0
- package/src/crons/amazon-ses.ts +1 -1
- package/src/crons/balance-emails.ts +1 -1
- package/src/crons/clearExcelCache.test.ts +1 -1
- package/src/crons/endFunctionsOfUsersWithoutRegistration.ts +1 -1
- package/src/crons.ts +3 -3
- package/src/email-recipient-loaders/members.ts +1 -1
- package/src/email-recipient-loaders/orders.ts +3 -3
- package/src/email-recipient-loaders/payments.ts +117 -352
- package/src/email-replacements/getEmailReplacementsForPayment.ts +321 -0
- package/src/endpoints/admin/members/ChargeMembersEndpoint.ts +9 -7
- package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +2 -2
- package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +1 -1
- package/src/endpoints/admin/organizations/ChargeOrganizationsEndpoint.ts +16 -50
- package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +2 -2
- package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +4 -4
- package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +21 -6
- package/src/endpoints/admin/registrations/ChargeRegistrationsEndpoint.ts +9 -7
- package/src/endpoints/auth/CreateAdminEndpoint.ts +2 -2
- package/src/endpoints/auth/CreateTokenEndpoint.test.ts +2 -2
- package/src/endpoints/auth/CreateTokenEndpoint.ts +1 -1
- package/src/endpoints/auth/DeleteTokenEndpoint.ts +1 -1
- package/src/endpoints/auth/DeleteUserEndpoint.ts +1 -1
- package/src/endpoints/auth/ForgotPasswordEndpoint.ts +1 -1
- package/src/endpoints/auth/GetOtherUserEndpoint.ts +2 -2
- package/src/endpoints/auth/GetUserEndpoint.test.ts +2 -2
- package/src/endpoints/auth/GetUserEndpoint.ts +2 -2
- package/src/endpoints/auth/OpenIDConnectAuthTokenEndpoint.ts +2 -2
- package/src/endpoints/auth/OpenIDConnectCallbackEndpoint.ts +2 -2
- package/src/endpoints/auth/OpenIDConnectStartEndpoint.ts +2 -2
- package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +1 -1
- package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +1 -1
- package/src/endpoints/auth/SignupEndpoint.ts +1 -1
- package/src/endpoints/auth/VerifyEmailEndpoint.ts +1 -1
- package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +1 -1
- package/src/endpoints/global/audit-logs/GetAuditLogsEndpoint.ts +4 -4
- package/src/endpoints/global/billing/ActivatePackagesEndpoint.ts +191 -7
- package/src/endpoints/global/billing/DeactivatePackageEndpoint.ts +64 -0
- package/src/endpoints/global/email/GetAdminEmailsEndpoint.test.ts +2 -2
- package/src/endpoints/global/email/GetAdminEmailsEndpoint.ts +3 -3
- package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +1 -1
- package/src/endpoints/global/email/GetEmailEndpoint.ts +1 -1
- package/src/endpoints/global/email/GetUserEmailsEndpoint.test.ts +2 -2
- package/src/endpoints/global/email/GetUserEmailsEndpoint.ts +3 -3
- package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +62 -16
- package/src/endpoints/global/email/PatchEmailEndpoint.test.ts +6 -6
- package/src/endpoints/global/email-recipients/GetEmailRecipientsCountEndpoint.ts +2 -2
- package/src/endpoints/global/email-recipients/GetEmailRecipientsEndpoint.test.ts +2 -2
- package/src/endpoints/global/email-recipients/GetEmailRecipientsEndpoint.ts +4 -4
- package/src/endpoints/global/email-recipients/RetryEmailRecipientEndpoint.ts +1 -1
- package/src/endpoints/global/email-recipients/helpers/validateEmailRecipientFilter.ts +1 -1
- package/src/endpoints/global/events/GetEventNotificationsCountEndpoint.ts +2 -2
- package/src/endpoints/global/events/GetEventNotificationsEndpoint.ts +4 -4
- package/src/endpoints/global/events/GetEventsEndpoint.ts +4 -4
- package/src/endpoints/global/events/PatchEventNotificationsEndpoint.test.ts +2 -2
- package/src/endpoints/global/events/PatchEventNotificationsEndpoint.ts +3 -3
- package/src/endpoints/global/events/PatchEventsEndpoint.test.ts +2 -2
- package/src/endpoints/global/events/PatchEventsEndpoint.ts +5 -5
- package/src/endpoints/global/files/ExportToExcelEndpoint.ts +4 -4
- package/src/endpoints/global/files/GetFileCache.ts +2 -2
- package/src/endpoints/global/files/UploadFile.ts +2 -2
- package/src/endpoints/global/files/UploadImage.ts +1 -1
- package/src/endpoints/global/groups/GetGroupsEndpoint.test.ts +3 -3
- package/src/endpoints/global/groups/GetGroupsEndpoint.ts +4 -4
- package/src/endpoints/global/members/GetMembersEndpoint.test.ts +3 -3
- package/src/endpoints/global/members/helpers/validateGroupFilter.ts +1 -1
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +2 -2
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +23 -12
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +2 -2
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +1 -1
- package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +1 -1
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +2 -2
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +1 -1
- package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +3 -3
- package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +1 -1
- package/src/endpoints/global/platform/GetPlatformEndpoint.test.ts +2 -2
- package/src/endpoints/global/platform/GetPlatformEndpoint.ts +1 -1
- package/src/endpoints/global/platform/PatchPlatformEnpoint.test.ts +2 -2
- package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +7 -7
- package/src/endpoints/global/registration/GetRegistrationsEndpoint.test.ts +2 -2
- package/src/endpoints/global/registration/GetRegistrationsEndpoint.ts +1 -2
- package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +2 -2
- package/src/endpoints/global/registration/GetUserPayableBalanceEndpoint.ts +2 -2
- package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +14 -384
- package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +3 -3
- package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +2 -2
- package/src/endpoints/global/sso/GetSSOEndpoint.ts +2 -2
- package/src/endpoints/global/sso/SetSSOEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemEndpoint.ts +55 -0
- package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemsCountEndpoint.ts +43 -0
- package/src/endpoints/organization/dashboard/balance-items/GetBalanceItemsEndpoint.ts +160 -0
- package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedPayableBalanceEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/billing/GetOrganizationPayableBalanceEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/billing/GetPackagesEndpoint.test.ts +3 -3
- package/src/endpoints/organization/dashboard/billing/GetPackagesEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +1 -1
- package/src/endpoints/organization/dashboard/documents/GetDocumentsCountEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +30 -2
- package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.test.ts +2 -2
- package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.test.ts +2 -2
- package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/invoices/PatchInvoicesEndpoint.ts +53 -0
- package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +2 -2
- package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +2 -2
- package/src/endpoints/organization/dashboard/organization/GetUitpasClientIdEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +2 -2
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +12 -1
- package/src/endpoints/organization/dashboard/organization/SearchUitpasOrganizersEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/organization/SetUitpasClientCredentialsEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +4 -4
- package/src/endpoints/organization/dashboard/receivable-balances/GetReceivableBalancesCountEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/receivable-balances/GetReceivableBalancesEndpoint.ts +4 -4
- package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.test.ts +2 -2
- package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +4 -4
- package/src/endpoints/organization/dashboard/registration-periods/MoveRegistrationPeriods.test.ts +2 -2
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.test.ts +2 -2
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +3 -3
- package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.test.ts +3 -3
- package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/users/PatchApiUserEndpoint.test.ts +3 -3
- package/src/endpoints/organization/dashboard/users/PatchApiUserEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersCountEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +5 -5
- package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +5 -5
- package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +1 -1
- package/src/endpoints/organization/dashboard/webshops/SearchUitpasEventsEndpoint.ts +2 -2
- package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +1 -1
- package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +3 -3
- package/src/endpoints/organization/shared/GetDocumentHtml.ts +1 -1
- package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +2 -2
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +2 -2
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +2 -2
- package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +1 -1
- package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +1 -1
- package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +1 -1
- package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +1 -1
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +2 -2
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +2 -2
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +4 -4
- package/src/excel-loaders/balance-items.ts +268 -0
- package/src/excel-loaders/event-notifications.ts +3 -3
- package/src/excel-loaders/index.ts +6 -5
- package/src/excel-loaders/organizations.ts +4 -4
- package/src/excel-loaders/payments.ts +11 -3
- package/src/excel-loaders/receivable-balances.ts +2 -2
- package/src/helpers/AddressValidator.test.ts +1 -1
- package/src/helpers/AddressValidator.ts +1 -1
- package/src/helpers/AdminPermissionChecker.ts +1 -1
- package/src/helpers/AuthenticatedStructures.ts +17 -2
- package/src/helpers/EmailResumer.ts +1 -1
- package/src/helpers/FlagMomentCleanup.ts +1 -1
- package/src/helpers/ForwardHandler.test.ts +1 -1
- package/src/helpers/ForwardHandler.ts +1 -1
- package/src/helpers/GlobalHelper.ts +4 -4
- package/src/helpers/GroupBuilder.ts +417 -0
- package/src/helpers/GroupedThrottledQueue.test.ts +1 -1
- package/src/helpers/GroupedThrottledQueue.ts +1 -1
- package/src/helpers/MemberUserSyncer.test.ts +1 -1
- package/src/helpers/MemberUserSyncer.ts +1 -1
- package/src/helpers/ServiceFeeHelper.ts +5 -1
- package/src/helpers/TagHelper.ts +1 -1
- package/src/helpers/ThrottledQueue.test.ts +1 -1
- package/src/helpers/ViesHelper.ts +9 -0
- package/src/helpers/email-html-helpers.ts +0 -41
- package/src/middleware/ContextMiddleware.ts +1 -1
- package/src/seeds/1726572303-schedule-stock-updates.ts +1 -1
- package/src/seeds/1726847064-setup-steps.ts +1 -1
- package/src/seeds/1728928974-update-cached-outstanding-balance-from-items.ts +1 -1
- package/src/seeds/1740046783-update-membership.ts +1 -1
- package/src/seeds/1754560914-groups-prices.test.ts +1 -1
- package/src/seeds/1755876819-remove-duplicate-members.ts +1 -1
- package/src/seeds/1760702454-update-cached-outstanding-balance-from-items.ts +1 -1
- package/src/seeds/1761665607-sync-member-users.ts +1 -1
- package/src/seeds/data/default-email-templates.sql +1 -1
- package/src/seeds-temporary/1732117645-move-rrn.ts +1 -1
- package/src/services/AuditLogService.ts +1 -41
- package/src/services/BalanceItemPaymentService.ts +1 -1
- package/src/services/BalanceItemService.ts +12 -5
- package/src/services/EventNotificationService.ts +3 -3
- package/src/services/InvoiceService.ts +131 -17
- package/src/services/MemberRecordStore.ts +1 -1
- package/src/services/PaymentReallocationService.test.ts +9 -10
- package/src/services/PaymentReallocationService.ts +1 -1
- package/src/services/PaymentService.ts +548 -18
- package/src/services/RegistrationService.ts +3 -3
- package/src/services/SSOService.ts +2 -2
- package/src/services/STPackageService.ts +241 -0
- package/src/services/uitpas/UitpasService.test.ts +1 -1
- package/src/sql-filters/balance-items.ts +56 -0
- package/src/sql-filters/emails.ts +1 -1
- package/src/sql-filters/event-notifications.ts +2 -2
- package/src/sql-filters/events.ts +51 -0
- package/src/sql-filters/members.ts +37 -1
- package/src/sql-filters/receivable-balances.ts +3 -3
- package/src/sql-filters/users.ts +10 -0
- package/src/sql-sorters/balance-items.ts +36 -0
- package/src/sql-sorters/document-templates.ts +2 -2
- package/src/sql-sorters/documents.ts +2 -2
- package/src/sql-sorters/event-notifications.ts +1 -1
- package/src/sql-sorters/orders.ts +2 -2
- package/src/sql-sorters/tickets.ts +2 -2
- package/tests/actions/patchOrganizationMember.ts +3 -3
- package/tests/actions/patchPaymentStatus.ts +3 -3
- package/tests/actions/patchUserMember.ts +2 -2
- package/tests/assertions/assertBalances.ts +1 -1
- package/tests/e2e/api-rate-limits.test.ts +3 -3
- package/tests/e2e/charge-members.test.ts +14 -14
- package/tests/e2e/documents.test.ts +8 -8
- package/tests/e2e/private-files.test.ts +4 -4
- package/tests/e2e/stock.test.ts +4 -4
- package/tests/e2e/tickets.test.ts +4 -4
- package/tests/helpers/TestServer.ts +2 -2
- package/tests/init/index.ts +7 -7
- package/tests/init/initAdmin.ts +1 -1
- /package/src/endpoints/organization/dashboard/{payments → balance-items}/PatchBalanceItemsEndpoint.ts +0 -0
|
@@ -2,7 +2,7 @@ import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-
|
|
|
2
2
|
|
|
3
3
|
import { getDefaultEmailFrom, sendEmailTemplate } from '@stamhoofd/models';
|
|
4
4
|
import { EmailTemplateType, Recipient } from '@stamhoofd/structures';
|
|
5
|
-
import { Context } from '../../helpers/Context';
|
|
5
|
+
import { Context } from '../../helpers/Context.js';
|
|
6
6
|
|
|
7
7
|
type Params = Record<string, never>;
|
|
8
8
|
type Query = undefined;
|
|
@@ -4,7 +4,7 @@ import { PasswordToken, Platform, sendEmailTemplate, User } from '@stamhoofd/mod
|
|
|
4
4
|
import { EmailTemplateType, ForgotPasswordRequest, LoginMethod, Recipient, Replacement } from '@stamhoofd/structures';
|
|
5
5
|
|
|
6
6
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
7
|
-
import { Context } from '../../helpers/Context';
|
|
7
|
+
import { Context } from '../../helpers/Context.js';
|
|
8
8
|
|
|
9
9
|
type Params = Record<string, never>;
|
|
10
10
|
type Query = undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { UserWithMembers } from '@stamhoofd/structures';
|
|
3
3
|
|
|
4
|
-
import { AuthenticatedStructures } from '../../helpers/AuthenticatedStructures';
|
|
5
|
-
import { Context } from '../../helpers/Context';
|
|
4
|
+
import { AuthenticatedStructures } from '../../helpers/AuthenticatedStructures.js';
|
|
5
|
+
import { Context } from '../../helpers/Context.js';
|
|
6
6
|
import { User } from '@stamhoofd/models';
|
|
7
7
|
|
|
8
8
|
type Params = { id: string };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Request } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { OrganizationFactory, Token, UserFactory } from '@stamhoofd/models';
|
|
3
3
|
|
|
4
|
-
import { testServer } from '../../../tests/helpers/TestServer';
|
|
5
|
-
import { GetUserEndpoint } from './GetUserEndpoint';
|
|
4
|
+
import { testServer } from '../../../tests/helpers/TestServer.js';
|
|
5
|
+
import { GetUserEndpoint } from './GetUserEndpoint.js';
|
|
6
6
|
|
|
7
7
|
describe('Endpoint.GetUser', () => {
|
|
8
8
|
// Test endpoint
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { UserWithMembers } from '@stamhoofd/structures';
|
|
3
3
|
|
|
4
|
-
import { AuthenticatedStructures } from '../../helpers/AuthenticatedStructures';
|
|
5
|
-
import { Context } from '../../helpers/Context';
|
|
4
|
+
import { AuthenticatedStructures } from '../../helpers/AuthenticatedStructures.js';
|
|
5
|
+
import { Context } from '../../helpers/Context.js';
|
|
6
6
|
|
|
7
7
|
type Params = Record<string, never>;
|
|
8
8
|
type Query = undefined;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AutoEncoder, field, StringDecoder } from '@simonbackx/simple-encoding';
|
|
2
2
|
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
3
|
|
|
4
|
-
import { Context } from '../../helpers/Context';
|
|
5
|
-
import { SSOService } from '../../services/SSOService';
|
|
4
|
+
import { Context } from '../../helpers/Context.js';
|
|
5
|
+
import { SSOService } from '../../services/SSOService.js';
|
|
6
6
|
import { OpenIDAuthTokenResponse } from '@stamhoofd/structures';
|
|
7
7
|
|
|
8
8
|
type Params = Record<string, never>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { AnyDecoder, Decoder } from '@simonbackx/simple-encoding';
|
|
2
2
|
import { DecodedRequest, Endpoint, Request } from '@simonbackx/simple-endpoints';
|
|
3
3
|
|
|
4
|
-
import { Context } from '../../helpers/Context';
|
|
5
|
-
import { SSOServiceWithSession } from '../../services/SSOService';
|
|
4
|
+
import { Context } from '../../helpers/Context.js';
|
|
5
|
+
import { SSOServiceWithSession } from '../../services/SSOService.js';
|
|
6
6
|
|
|
7
7
|
type Params = Record<string, never>;
|
|
8
8
|
type Query = undefined;
|
|
@@ -2,8 +2,8 @@ import { Decoder } from '@simonbackx/simple-encoding';
|
|
|
2
2
|
import { DecodedRequest, Endpoint, Request } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { StartOpenIDFlowStruct } from '@stamhoofd/structures';
|
|
4
4
|
|
|
5
|
-
import { Context } from '../../helpers/Context';
|
|
6
|
-
import { SSOService } from '../../services/SSOService';
|
|
5
|
+
import { Context } from '../../helpers/Context.js';
|
|
6
|
+
import { SSOService } from '../../services/SSOService.js';
|
|
7
7
|
|
|
8
8
|
type Params = Record<string, never>;
|
|
9
9
|
type Query = StartOpenIDFlowStruct;
|
|
@@ -3,7 +3,7 @@ import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-
|
|
|
3
3
|
import { EmailVerificationCode } from '@stamhoofd/models';
|
|
4
4
|
import { PollEmailVerificationRequest, PollEmailVerificationResponse } from '@stamhoofd/structures';
|
|
5
5
|
|
|
6
|
-
import { Context } from '../../helpers/Context';
|
|
6
|
+
import { Context } from '../../helpers/Context.js';
|
|
7
7
|
|
|
8
8
|
type Params = Record<string, never>;
|
|
9
9
|
type Query = undefined;
|
|
@@ -3,7 +3,7 @@ import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-
|
|
|
3
3
|
import { EmailVerificationCode } from '@stamhoofd/models';
|
|
4
4
|
import { PollEmailVerificationRequest, PollEmailVerificationResponse } from '@stamhoofd/structures';
|
|
5
5
|
|
|
6
|
-
import { Context } from '../../helpers/Context';
|
|
6
|
+
import { Context } from '../../helpers/Context.js';
|
|
7
7
|
|
|
8
8
|
type Params = Record<string, never>;
|
|
9
9
|
type Query = undefined;
|
|
@@ -4,7 +4,7 @@ import { SimpleError } from '@simonbackx/simple-errors';
|
|
|
4
4
|
import { EmailVerificationCode, PasswordToken, Platform, sendEmailTemplate, User } from '@stamhoofd/models';
|
|
5
5
|
import { EmailTemplateType, LoginMethod, NewUser, Recipient, Replacement, SignupResponse } from '@stamhoofd/structures';
|
|
6
6
|
|
|
7
|
-
import { Context } from '../../helpers/Context';
|
|
7
|
+
import { Context } from '../../helpers/Context.js';
|
|
8
8
|
|
|
9
9
|
type Params = Record<string, never>;
|
|
10
10
|
type Query = undefined;
|
|
@@ -4,7 +4,7 @@ import { SimpleError } from '@simonbackx/simple-errors';
|
|
|
4
4
|
import { EmailVerificationCode, Token, User } from '@stamhoofd/models';
|
|
5
5
|
import { Token as TokenStruct, VerifyEmailRequest } from '@stamhoofd/structures';
|
|
6
6
|
|
|
7
|
-
import { Context } from '../../helpers/Context';
|
|
7
|
+
import { Context } from '../../helpers/Context.js';
|
|
8
8
|
|
|
9
9
|
type Params = Record<string, never>;
|
|
10
10
|
type Query = undefined;
|
|
@@ -2,7 +2,7 @@ import { Decoder } from '@simonbackx/simple-encoding';
|
|
|
2
2
|
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { Address, ValidatedAddress } from '@stamhoofd/structures';
|
|
4
4
|
|
|
5
|
-
import { AddressValidator } from '../../../helpers/AddressValidator';
|
|
5
|
+
import { AddressValidator } from '../../../helpers/AddressValidator.js';
|
|
6
6
|
|
|
7
7
|
type Params = Record<string, never>;
|
|
8
8
|
type Query = undefined;
|
|
@@ -5,10 +5,10 @@ import { AuditLog } from '@stamhoofd/models';
|
|
|
5
5
|
import { SQL, SQLSortDefinitions, applySQLSorter, compileToSQLFilter } from '@stamhoofd/sql';
|
|
6
6
|
import { AuditLog as AuditLogStruct, CountFilteredRequest, LimitedFilteredRequest, PaginatedResponse, StamhoofdFilter, assertSort, getSortFilter } from '@stamhoofd/structures';
|
|
7
7
|
|
|
8
|
-
import { AuthenticatedStructures } from '../../../helpers/AuthenticatedStructures';
|
|
9
|
-
import { Context } from '../../../helpers/Context';
|
|
10
|
-
import { auditLogFilterCompilers } from '../../../sql-filters/audit-logs';
|
|
11
|
-
import { auditLogSorters } from '../../../sql-sorters/audit-logs';
|
|
8
|
+
import { AuthenticatedStructures } from '../../../helpers/AuthenticatedStructures.js';
|
|
9
|
+
import { Context } from '../../../helpers/Context.js';
|
|
10
|
+
import { auditLogFilterCompilers } from '../../../sql-filters/audit-logs.js';
|
|
11
|
+
import { auditLogSorters } from '../../../sql-sorters/audit-logs.js';
|
|
12
12
|
|
|
13
13
|
type Params = Record<string, never>;
|
|
14
14
|
type Query = LimitedFilteredRequest;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
import { DecodedRequest, Endpoint, Request } from '@simonbackx/simple-endpoints';
|
|
3
|
-
import {
|
|
1
|
+
import { Decoder } from '@simonbackx/simple-encoding';
|
|
2
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
|
+
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
|
+
import { BalanceItem, Organization, Platform, STPackage } from '@stamhoofd/models';
|
|
5
|
+
import { CheckoutResponse, PackageCheckout, Payment as PaymentStruct, STPackageBundleHelper, STPackageStruct } from '@stamhoofd/structures';
|
|
6
|
+
import { Context } from '../../../helpers/Context.js';
|
|
7
|
+
import { PaymentService } from '../../../services/PaymentService.js';
|
|
8
|
+
import { STPackageService } from '../../../services/STPackageService.js';
|
|
4
9
|
|
|
5
10
|
type Params = Record<string, never>;
|
|
6
11
|
type Query = undefined;
|
|
7
|
-
type Body =
|
|
8
|
-
type ResponseBody =
|
|
12
|
+
type Body = PackageCheckout;
|
|
13
|
+
type ResponseBody = CheckoutResponse;
|
|
9
14
|
|
|
10
15
|
export class ActivatePackagesEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
11
|
-
bodyDecoder =
|
|
16
|
+
bodyDecoder = PackageCheckout as Decoder<Body>;
|
|
12
17
|
|
|
13
18
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
14
19
|
if (request.method != 'POST') {
|
|
@@ -24,7 +29,186 @@ export class ActivatePackagesEndpoint extends Endpoint<Params, Query, Body, Resp
|
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
32
|
+
const organization = await Context.setOrganizationScope();
|
|
33
|
+
const { user } = await Context.authenticate();
|
|
27
34
|
|
|
35
|
+
// If the user has permission, we'll also search if he has access to the organization's key
|
|
36
|
+
if (!await Context.auth.canActivatePackages(organization.id)) {
|
|
37
|
+
throw Context.auth.error();
|
|
38
|
+
}
|
|
39
|
+
const checkout = request.body;
|
|
40
|
+
|
|
41
|
+
// Validate company
|
|
42
|
+
if (checkout.customer && checkout.customer.company) {
|
|
43
|
+
// Search company id
|
|
44
|
+
// this avoids needing to check the VAT number every time
|
|
45
|
+
const id = checkout.customer.company.id;
|
|
46
|
+
const foundCompany = organization.meta.companies.find(c => c.id === id);
|
|
47
|
+
|
|
48
|
+
if (!foundCompany) {
|
|
49
|
+
throw new SimpleError({
|
|
50
|
+
code: 'invalid_data',
|
|
51
|
+
message: $t(`0ab71307-8f4f-4701-b120-b552a1b6bdd0`),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const currentPackages = await STPackageService.getActivePackages(organization.id);
|
|
57
|
+
|
|
58
|
+
const packages: STPackageStruct[] = [];
|
|
59
|
+
const balanceItems: Map<BalanceItem, number> = new Map();
|
|
60
|
+
const models: STPackage[] = [];
|
|
61
|
+
let totalPrice = 0;
|
|
62
|
+
|
|
63
|
+
if (STAMHOOFD.userMode === 'organization') {
|
|
64
|
+
// Only allowed in organization mode
|
|
65
|
+
for (const bundle of request.body.purchases.packageBundles) {
|
|
66
|
+
// Renew after currently running packages
|
|
67
|
+
let date = new Date();
|
|
68
|
+
|
|
69
|
+
let skip = false;
|
|
70
|
+
|
|
71
|
+
// Do we have a collision? Make sure our package only start after the expiry date of existing packages
|
|
72
|
+
for (const currentPack of currentPackages) {
|
|
73
|
+
if (!STPackageBundleHelper.isCombineable(bundle, STPackageStruct.create(currentPack))) {
|
|
74
|
+
if (!STPackageBundleHelper.isStackable(bundle, STPackageStruct.create(currentPack))) {
|
|
75
|
+
// WE skip silently
|
|
76
|
+
console.error('Tried to activate non combineable, non stackable packages...');
|
|
77
|
+
skip = true;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (currentPack.validUntil !== null) {
|
|
81
|
+
const end = currentPack.validUntil;
|
|
82
|
+
if (end > date) {
|
|
83
|
+
date = end;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (skip) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
packages.push(STPackageBundleHelper.getCurrentPackage(bundle, date));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Add renewals
|
|
96
|
+
if (checkout.purchases.renewPackageIds.length > 0) {
|
|
97
|
+
for (const id of checkout.purchases.renewPackageIds) {
|
|
98
|
+
const pack = currentPackages.find(c => c.id === id);
|
|
99
|
+
if (!pack) {
|
|
100
|
+
throw new SimpleError({
|
|
101
|
+
code: 'not_found',
|
|
102
|
+
message: 'Package not found',
|
|
103
|
+
human: $t('0e5baf7f-89be-4665-a3dd-b1603b5a6627'),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Renew
|
|
108
|
+
const model = pack.createRenewed();
|
|
109
|
+
|
|
110
|
+
const balanceItem = await STPackageService.chargePackage(model, undefined, checkout.customer ?? undefined);
|
|
111
|
+
if (balanceItem) {
|
|
112
|
+
totalPrice += balanceItem.priceWithVAT;
|
|
113
|
+
balanceItems.set(balanceItem, balanceItem.priceWithVAT);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (!request.body.proForma) {
|
|
117
|
+
await model.save();
|
|
118
|
+
await balanceItem?.save();
|
|
119
|
+
}
|
|
120
|
+
models.push(model);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Create the real models for each package
|
|
126
|
+
// calculate the price for these packages and create a hidden balance item
|
|
127
|
+
for (const pack of packages) {
|
|
128
|
+
const model = new STPackage();
|
|
129
|
+
model.id = pack.id;
|
|
130
|
+
model.meta = pack.meta;
|
|
131
|
+
model.validUntil = pack.validUntil;
|
|
132
|
+
model.removeAt = pack.removeAt;
|
|
133
|
+
|
|
134
|
+
// Not yet valid / active (ignored until valid)
|
|
135
|
+
model.validAt = null;
|
|
136
|
+
model.organizationId = organization.id;
|
|
137
|
+
|
|
138
|
+
const balanceItem = await STPackageService.chargePackage(model, undefined, checkout.customer ?? undefined);
|
|
139
|
+
if (balanceItem) {
|
|
140
|
+
totalPrice += balanceItem.priceWithVAT;
|
|
141
|
+
balanceItems.set(balanceItem, balanceItem.priceWithVAT);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!request.body.proForma) {
|
|
145
|
+
await model.save();
|
|
146
|
+
await balanceItem?.save();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
models.push(model);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// todo: Add pending items (balance items in request)
|
|
153
|
+
|
|
154
|
+
const membershipOrganizationId = (await Platform.getShared()).membershipOrganizationId;
|
|
155
|
+
if (!membershipOrganizationId) {
|
|
156
|
+
throw new SimpleError({
|
|
157
|
+
code: 'unavailable',
|
|
158
|
+
message: 'No membership organization id set on the platform',
|
|
159
|
+
human: 'Package purchases are currently unavailable',
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const membershipOrganization = await Organization.getByID(membershipOrganizationId);
|
|
164
|
+
if (!membershipOrganization) {
|
|
165
|
+
throw new Error('Unexpected missing membershipOrganization');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const result = await PaymentService.createPayment({
|
|
169
|
+
balanceItems,
|
|
170
|
+
checkout,
|
|
171
|
+
user,
|
|
172
|
+
organization: membershipOrganization,
|
|
173
|
+
payingOrganization: organization,
|
|
174
|
+
serviceFeeType: 'system',
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
console.log('Created payment', result);
|
|
178
|
+
|
|
179
|
+
if (!result) {
|
|
180
|
+
// No payment needed
|
|
181
|
+
throw new SimpleError({
|
|
182
|
+
code: 'missing_data',
|
|
183
|
+
message: 'Checkout was empty',
|
|
184
|
+
human: $t('c5cf0531-9751-4be0-be0c-31ccfac1722d'),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!checkout.proForma) {
|
|
189
|
+
for (const pack of models) {
|
|
190
|
+
await pack.save();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
// Delete payment again
|
|
195
|
+
if (result) {
|
|
196
|
+
await result.payment.delete();
|
|
197
|
+
result.paymentUrl = null;
|
|
198
|
+
result.paymentQRCode = null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
for (const [item] of balanceItems) {
|
|
202
|
+
await item.delete();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const { payment, paymentUrl, paymentQRCode } = result;
|
|
207
|
+
|
|
208
|
+
return new Response(CheckoutResponse.create({
|
|
209
|
+
payment: payment ? PaymentStruct.create(payment) : null,
|
|
210
|
+
paymentUrl,
|
|
211
|
+
paymentQRCode,
|
|
212
|
+
}));
|
|
28
213
|
}
|
|
29
214
|
}
|
|
30
|
-
*/
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
|
+
import { SimpleError } from '@simonbackx/simple-errors';
|
|
3
|
+
import { STPackage } from '@stamhoofd/models';
|
|
4
|
+
|
|
5
|
+
import { Context } from '../../../helpers/Context.js';
|
|
6
|
+
import { STPackageService } from '../../../services/STPackageService.js';
|
|
7
|
+
type Params = { id: string };
|
|
8
|
+
type Query = undefined;
|
|
9
|
+
type ResponseBody = undefined;
|
|
10
|
+
type Body = undefined;
|
|
11
|
+
|
|
12
|
+
export class DeactivatePackageEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
13
|
+
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
14
|
+
if (request.method != 'POST') {
|
|
15
|
+
return [false];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const params = Endpoint.parseParameters(request.url, '/billing/deactivate-package/@id', { id: String });
|
|
19
|
+
|
|
20
|
+
if (params) {
|
|
21
|
+
return [true, params as Params];
|
|
22
|
+
}
|
|
23
|
+
return [false];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
27
|
+
const organization = await Context.setOrganizationScope();
|
|
28
|
+
await Context.authenticate();
|
|
29
|
+
|
|
30
|
+
// If the user has permission, we'll also search if he has access to the organization's key
|
|
31
|
+
if (!await Context.auth.canDeactivatePackages(organization.id)) {
|
|
32
|
+
throw Context.auth.error();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const packages = await STPackageService.getActivePackages(organization.id);
|
|
36
|
+
|
|
37
|
+
const pack = packages.find(p => p.id === request.params.id);
|
|
38
|
+
if (!pack) {
|
|
39
|
+
throw new SimpleError({
|
|
40
|
+
code: 'not_found',
|
|
41
|
+
message: 'Package not found',
|
|
42
|
+
human: $t('c6adb3c8-c494-4f2a-8287-6bcac853a88a'),
|
|
43
|
+
statusCode: 404,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!pack.meta.canDeactivate) {
|
|
48
|
+
throw new SimpleError({
|
|
49
|
+
code: 'not_allowed',
|
|
50
|
+
message: "Can't deactivate this package",
|
|
51
|
+
human: $t('242cee92-c0ea-4736-a8c8-6d82c8faf342'),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Deactivate
|
|
56
|
+
pack.removeAt = new Date();
|
|
57
|
+
pack.removeAt.setTime(pack.removeAt.getTime() - 5_000);
|
|
58
|
+
await pack.save();
|
|
59
|
+
|
|
60
|
+
await STPackageService.updateOrganizationPackages(organization.id);
|
|
61
|
+
|
|
62
|
+
return new Response(undefined);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -2,8 +2,8 @@ import { Request } from '@simonbackx/simple-endpoints';
|
|
|
2
2
|
import { Email, EmailRecipient, MemberFactory, Organization, OrganizationFactory, RegistrationPeriod, RegistrationPeriodFactory, Token, User, UserFactory } from '@stamhoofd/models';
|
|
3
3
|
import { EmailStatus, LimitedFilteredRequest, PermissionLevel, Permissions, Replacement } from '@stamhoofd/structures';
|
|
4
4
|
import { TestUtils } from '@stamhoofd/test-utils';
|
|
5
|
-
import { testServer } from '../../../../tests/helpers/TestServer';
|
|
6
|
-
import { GetAdminEmailsEndpoint } from './GetAdminEmailsEndpoint';
|
|
5
|
+
import { testServer } from '../../../../tests/helpers/TestServer.js';
|
|
6
|
+
import { GetAdminEmailsEndpoint } from './GetAdminEmailsEndpoint.js';
|
|
7
7
|
import { Formatter } from '@stamhoofd/utility';
|
|
8
8
|
|
|
9
9
|
const baseUrl = `/email`;
|
|
@@ -5,9 +5,9 @@ import { Decoder } from '@simonbackx/simple-encoding';
|
|
|
5
5
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
6
6
|
import { Email, Platform } from '@stamhoofd/models';
|
|
7
7
|
import { applySQLSorter, compileToSQLFilter, SQLFilterDefinitions, SQLSortDefinitions } from '@stamhoofd/sql';
|
|
8
|
-
import { Context } from '../../../helpers/Context';
|
|
9
|
-
import { emailFilterCompilers } from '../../../sql-filters/emails';
|
|
10
|
-
import { emailSorters } from '../../../sql-sorters/emails';
|
|
8
|
+
import { Context } from '../../../helpers/Context.js';
|
|
9
|
+
import { emailFilterCompilers } from '../../../sql-filters/emails.js';
|
|
10
|
+
import { emailSorters } from '../../../sql-sorters/emails.js';
|
|
11
11
|
|
|
12
12
|
type Params = Record<string, never>;
|
|
13
13
|
type Query = LimitedFilteredRequest;
|
|
@@ -4,7 +4,7 @@ import { SimpleError } from '@simonbackx/simple-errors';
|
|
|
4
4
|
import { EmailAddress } from '@stamhoofd/email';
|
|
5
5
|
import { Organization } from '@stamhoofd/models';
|
|
6
6
|
import { EmailAddressSettings, OrganizationSimple } from '@stamhoofd/structures';
|
|
7
|
-
import { Context } from '../../../helpers/Context';
|
|
7
|
+
import { Context } from '../../../helpers/Context.js';
|
|
8
8
|
|
|
9
9
|
type Params = Record<string, never>;
|
|
10
10
|
type Body = undefined;
|
|
@@ -3,7 +3,7 @@ import { Email } from '@stamhoofd/models';
|
|
|
3
3
|
import { EmailPreview } from '@stamhoofd/structures';
|
|
4
4
|
|
|
5
5
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
6
|
-
import { Context } from '../../../helpers/Context';
|
|
6
|
+
import { Context } from '../../../helpers/Context.js';
|
|
7
7
|
|
|
8
8
|
type Params = { id: string };
|
|
9
9
|
type Query = undefined;
|
|
@@ -2,8 +2,8 @@ import { Request } from '@simonbackx/simple-endpoints';
|
|
|
2
2
|
import { Email, EmailRecipient, MemberFactory, Organization, OrganizationFactory, RegistrationPeriod, RegistrationPeriodFactory, Token, User, UserFactory } from '@stamhoofd/models';
|
|
3
3
|
import { EmailStatus, LimitedFilteredRequest, Replacement } from '@stamhoofd/structures';
|
|
4
4
|
import { TestUtils } from '@stamhoofd/test-utils';
|
|
5
|
-
import { testServer } from '../../../../tests/helpers/TestServer';
|
|
6
|
-
import { GetUserEmailsEndpoint } from './GetUserEmailsEndpoint';
|
|
5
|
+
import { testServer } from '../../../../tests/helpers/TestServer.js';
|
|
6
|
+
import { GetUserEmailsEndpoint } from './GetUserEmailsEndpoint.js';
|
|
7
7
|
import { Formatter } from '@stamhoofd/utility';
|
|
8
8
|
|
|
9
9
|
const baseUrl = `/user/email`;
|
|
@@ -5,9 +5,9 @@ import { Decoder } from '@simonbackx/simple-encoding';
|
|
|
5
5
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
6
6
|
import { Email, Member } from '@stamhoofd/models';
|
|
7
7
|
import { applySQLSorter, compileToSQLFilter, SQLFilterDefinitions, SQLSortDefinitions } from '@stamhoofd/sql';
|
|
8
|
-
import { Context } from '../../../helpers/Context';
|
|
9
|
-
import { emailFilterCompilers, userEmailFilterCompilers } from '../../../sql-filters/emails';
|
|
10
|
-
import { emailSorters } from '../../../sql-sorters/emails';
|
|
8
|
+
import { Context } from '../../../helpers/Context.js';
|
|
9
|
+
import { emailFilterCompilers, userEmailFilterCompilers } from '../../../sql-filters/emails.js';
|
|
10
|
+
import { emailSorters } from '../../../sql-sorters/emails.js';
|
|
11
11
|
|
|
12
12
|
type Params = Record<string, never>;
|
|
13
13
|
type Query = LimitedFilteredRequest;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { AutoEncoder, BooleanDecoder, Decoder, field, StringDecoder } from '@simonbackx/simple-encoding';
|
|
2
2
|
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
|
-
import { EmailAddress } from '@stamhoofd/email';
|
|
5
|
-
import { Context } from '../../../helpers/Context';
|
|
4
|
+
import { Email, EmailAddress } from '@stamhoofd/email';
|
|
5
|
+
import { Context } from '../../../helpers/Context.js';
|
|
6
6
|
import { SESv2Client, DeleteSuppressedDestinationCommand } from '@aws-sdk/client-sesv2'; // ES Modules import
|
|
7
|
+
import { RateLimiter } from '@stamhoofd/models';
|
|
8
|
+
import { SQL } from '@stamhoofd/sql';
|
|
7
9
|
|
|
8
10
|
type Params = Record<string, never>;
|
|
9
11
|
type Query = undefined;
|
|
@@ -37,6 +39,16 @@ class Body extends AutoEncoder {
|
|
|
37
39
|
markedAsSpam?: boolean;
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
export const unblockLimiter = new RateLimiter({
|
|
43
|
+
limits: [
|
|
44
|
+
{
|
|
45
|
+
// Max 10 per week
|
|
46
|
+
limit: 10,
|
|
47
|
+
duration: 24 * 60 * 1000 * 60 * 7,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
|
|
40
52
|
type ResponseBody = undefined;
|
|
41
53
|
|
|
42
54
|
export class ManageEmailAddressEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
@@ -89,20 +101,20 @@ export class ManageEmailAddressEndpoint extends Endpoint<Params, Query, Body, Re
|
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
const organization = await Context.setOptionalOrganizationScope();
|
|
92
|
-
await Context.authenticate();
|
|
93
|
-
|
|
94
|
-
if (!Context.auth.hasPlatformFullAccess()) {
|
|
95
|
-
throw Context.auth.error();
|
|
96
|
-
}
|
|
104
|
+
const { user } = await Context.authenticate();
|
|
97
105
|
|
|
98
|
-
const query = EmailAddress.select().where(
|
|
99
|
-
'email', request.body.email,
|
|
100
|
-
);
|
|
101
106
|
if (organization) {
|
|
102
|
-
|
|
107
|
+
if (!await Context.auth.hasFullAccess(organization.id)) {
|
|
108
|
+
throw Context.auth.error();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (!Context.auth.hasPlatformFullAccess()) {
|
|
113
|
+
throw Context.auth.error();
|
|
114
|
+
}
|
|
103
115
|
}
|
|
104
116
|
|
|
105
|
-
const emails = await
|
|
117
|
+
const emails = await EmailAddress.getByEmails([request.body.email], organization?.id ?? null);
|
|
106
118
|
|
|
107
119
|
if (emails.length === 0) {
|
|
108
120
|
throw new SimpleError({
|
|
@@ -112,6 +124,43 @@ export class ManageEmailAddressEndpoint extends Endpoint<Params, Query, Body, Re
|
|
|
112
124
|
statusCode: 404,
|
|
113
125
|
});
|
|
114
126
|
}
|
|
127
|
+
|
|
128
|
+
// Track limits
|
|
129
|
+
for (const email of emails) {
|
|
130
|
+
const wasBlocked = email.unsubscribedAll || email.unsubscribedMarketing || email.hardBounce || email.markedAsSpam;
|
|
131
|
+
|
|
132
|
+
if (email.organizationId === null || (organization && email.organizationId === organization.id)) {
|
|
133
|
+
if (Context.auth.hasPlatformFullAccess()) {
|
|
134
|
+
// Only allowed as platform admins
|
|
135
|
+
email.unsubscribedAll = request.body.unsubscribedAll ?? email.unsubscribedAll;
|
|
136
|
+
email.unsubscribedMarketing = request.body.unsubscribedMarketing ?? email.unsubscribedMarketing;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
email.hardBounce = request.body.hardBounce ?? email.hardBounce;
|
|
141
|
+
email.markedAsSpam = request.body.markedAsSpam ?? email.markedAsSpam;
|
|
142
|
+
|
|
143
|
+
const isBlocked = email.unsubscribedAll || email.unsubscribedMarketing || email.hardBounce || email.markedAsSpam;
|
|
144
|
+
|
|
145
|
+
if (!isBlocked && wasBlocked && !Context.auth.hasPlatformFullAccess()) {
|
|
146
|
+
try {
|
|
147
|
+
unblockLimiter.track(organization?.id ?? '', 1);
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
Email.sendWebmaster({
|
|
151
|
+
subject: '[Limiet] Limiet bereikt voor aantal unblocks',
|
|
152
|
+
text: 'Beste, \nDe limiet werd bereikt voor het aantal email unblocks per week. \nUser: ' + user.email + '\n\nVereniging: ' + (organization ? (organization.id + ' (' + organization.name + ')') : 'platform') + '\n\n' + e.message + '\n\nStamhoofd',
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
throw new SimpleError({
|
|
156
|
+
code: 'too_many_unblocks',
|
|
157
|
+
message: 'Too many unblocks',
|
|
158
|
+
human: $t(`ed5bd32c-7d9a-42d8-b9d0-da74d82ef3a9`),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
115
164
|
console.log('Updated email address settings', request.body);
|
|
116
165
|
const client = new SESv2Client({});
|
|
117
166
|
|
|
@@ -132,10 +181,7 @@ export class ManageEmailAddressEndpoint extends Endpoint<Params, Query, Body, Re
|
|
|
132
181
|
}
|
|
133
182
|
|
|
134
183
|
for (const email of emails) {
|
|
135
|
-
|
|
136
|
-
email.unsubscribedMarketing = request.body.unsubscribedMarketing ?? email.unsubscribedMarketing;
|
|
137
|
-
email.hardBounce = request.body.hardBounce ?? email.hardBounce;
|
|
138
|
-
email.markedAsSpam = request.body.markedAsSpam ?? email.markedAsSpam;
|
|
184
|
+
// Only save if all went well
|
|
139
185
|
await email.save();
|
|
140
186
|
}
|
|
141
187
|
|