@stamhoofd/backend 2.39.0 → 2.40.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.
Files changed (198) hide show
  1. package/eslint.config.mjs +5 -0
  2. package/index.ts +81 -74
  3. package/jest.config.cjs +10 -0
  4. package/migrations.ts +16 -14
  5. package/package.json +11 -11
  6. package/src/crons/clear-excel-cache.test.ts +48 -50
  7. package/src/crons/clear-excel-cache.ts +18 -18
  8. package/src/crons/setup-steps.ts +2 -2
  9. package/src/crons.ts +325 -306
  10. package/src/decoders/StringArrayDecoder.ts +7 -7
  11. package/src/decoders/StringNullableDecoder.ts +1 -2
  12. package/src/email-recipient-loaders/members.ts +22 -22
  13. package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +8 -9
  14. package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +39 -40
  15. package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +8 -8
  16. package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +44 -45
  17. package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +58 -57
  18. package/src/endpoints/auth/CreateAdminEndpoint.ts +48 -45
  19. package/src/endpoints/auth/CreateTokenEndpoint.test.ts +31 -31
  20. package/src/endpoints/auth/CreateTokenEndpoint.ts +146 -147
  21. package/src/endpoints/auth/DeleteTokenEndpoint.ts +7 -7
  22. package/src/endpoints/auth/DeleteUserEndpoint.ts +15 -15
  23. package/src/endpoints/auth/ForgotPasswordEndpoint.ts +17 -18
  24. package/src/endpoints/auth/GetOtherUserEndpoint.ts +9 -10
  25. package/src/endpoints/auth/GetUserEndpoint.test.ts +32 -35
  26. package/src/endpoints/auth/GetUserEndpoint.ts +5 -6
  27. package/src/endpoints/auth/PatchApiUserEndpoint.ts +35 -33
  28. package/src/endpoints/auth/PatchUserEndpoint.ts +55 -52
  29. package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +9 -9
  30. package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +8 -8
  31. package/src/endpoints/auth/SignupEndpoint.ts +37 -36
  32. package/src/endpoints/auth/VerifyEmailEndpoint.ts +29 -28
  33. package/src/endpoints/global/addresses/SearchRegionsEndpoint.ts +33 -33
  34. package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +7 -7
  35. package/src/endpoints/global/caddy/CheckDomainCertEndpoint.ts +37 -37
  36. package/src/endpoints/global/email/CreateEmailEndpoint.ts +30 -30
  37. package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +13 -13
  38. package/src/endpoints/global/email/GetEmailEndpoint.ts +13 -13
  39. package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +16 -16
  40. package/src/endpoints/global/email/PatchEmailEndpoint.ts +25 -25
  41. package/src/endpoints/global/events/GetEventsEndpoint.ts +43 -44
  42. package/src/endpoints/global/events/PatchEventsEndpoint.ts +127 -172
  43. package/src/endpoints/global/files/ExportToExcelEndpoint.ts +49 -50
  44. package/src/endpoints/global/files/GetFileCache.ts +13 -13
  45. package/src/endpoints/global/files/UploadFile.ts +51 -54
  46. package/src/endpoints/global/files/UploadImage.ts +53 -53
  47. package/src/endpoints/global/groups/GetGroupsEndpoint.ts +25 -25
  48. package/src/endpoints/global/members/GetMemberFamilyEndpoint.ts +24 -23
  49. package/src/endpoints/global/members/GetMembersCountEndpoint.ts +8 -8
  50. package/src/endpoints/global/members/GetMembersEndpoint.ts +105 -102
  51. package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +240 -239
  52. package/src/endpoints/global/organizations/CheckRegisterCodeEndpoint.ts +12 -14
  53. package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +32 -33
  54. package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +48 -57
  55. package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +21 -22
  56. package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +28 -28
  57. package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +18 -18
  58. package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +20 -20
  59. package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +17 -17
  60. package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +81 -75
  61. package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +14 -14
  62. package/src/endpoints/global/platform/GetPlatformEnpoint.ts +11 -11
  63. package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +71 -68
  64. package/src/endpoints/global/registration/GetPaymentRegistrations.ts +27 -27
  65. package/src/endpoints/global/registration/GetUserBillingStatusEndpoint.ts +30 -30
  66. package/src/endpoints/global/registration/GetUserDetailedBillingStatusEndpoint.ts +34 -34
  67. package/src/endpoints/global/registration/GetUserDocumentsEndpoint.ts +26 -26
  68. package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +12 -12
  69. package/src/endpoints/global/registration/PatchUserMembersEndpoint.ts +90 -90
  70. package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +118 -121
  71. package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +362 -350
  72. package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +8 -9
  73. package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +21 -21
  74. package/src/endpoints/global/webshops/GetWebshopFromDomainEndpoint.ts +65 -65
  75. package/src/endpoints/organization/dashboard/billing/GetOrganizationBillingStatusEndpoint.ts +9 -9
  76. package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedBillingStatusEndpoint.ts +14 -14
  77. package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +17 -17
  78. package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesEndpoint.ts +21 -21
  79. package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +15 -15
  80. package/src/endpoints/organization/dashboard/documents/PatchDocumentEndpoint.ts +52 -52
  81. package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplateEndpoint.ts +37 -37
  82. package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +14 -14
  83. package/src/endpoints/organization/dashboard/email/EmailEndpoint.ts +113 -112
  84. package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +29 -29
  85. package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +48 -47
  86. package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +22 -21
  87. package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +13 -14
  88. package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +12 -13
  89. package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +24 -24
  90. package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +10 -12
  91. package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +14 -14
  92. package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +13 -13
  93. package/src/endpoints/organization/dashboard/organization/GetOrganizationSSOEndpoint.ts +12 -12
  94. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +120 -124
  95. package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +172 -173
  96. package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +88 -89
  97. package/src/endpoints/organization/dashboard/organization/SetOrganizationSSOEndpoint.ts +12 -12
  98. package/src/endpoints/organization/dashboard/payments/GetMemberBalanceEndpoint.ts +17 -17
  99. package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +8 -8
  100. package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +66 -67
  101. package/src/endpoints/organization/dashboard/payments/PatchBalanceItemsEndpoint.ts +47 -47
  102. package/src/endpoints/organization/dashboard/payments/PatchPaymentsEndpoint.ts +93 -91
  103. package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +16 -17
  104. package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +170 -167
  105. package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +25 -24
  106. package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +22 -23
  107. package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +22 -22
  108. package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +17 -18
  109. package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +8 -9
  110. package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +17 -18
  111. package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +14 -15
  112. package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +19 -19
  113. package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +19 -19
  114. package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +14 -14
  115. package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +12 -12
  116. package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +103 -100
  117. package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +11 -12
  118. package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +15 -15
  119. package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +14 -14
  120. package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +14 -14
  121. package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +23 -23
  122. package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +54 -52
  123. package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +84 -81
  124. package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +120 -111
  125. package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +24 -24
  126. package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +18 -18
  127. package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +141 -130
  128. package/src/endpoints/organization/shared/GetDocumentHtml.ts +25 -25
  129. package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +18 -18
  130. package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +36 -37
  131. package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +9 -9
  132. package/src/endpoints/organization/shared/auth/OpenIDConnectCallbackEndpoint.ts +11 -11
  133. package/src/endpoints/organization/shared/auth/OpenIDConnectStartEndpoint.ts +28 -27
  134. package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +20 -20
  135. package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +22 -22
  136. package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +14 -14
  137. package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +57 -56
  138. package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +65 -66
  139. package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +18 -17
  140. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +124 -128
  141. package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +154 -145
  142. package/src/excel-loaders/members.ts +102 -103
  143. package/src/excel-loaders/payments.ts +155 -156
  144. package/src/helpers/AddressValidator.test.ts +32 -32
  145. package/src/helpers/AddressValidator.ts +128 -122
  146. package/src/helpers/AdminPermissionChecker.ts +339 -236
  147. package/src/helpers/AuthenticatedStructures.ts +233 -134
  148. package/src/helpers/BuckarooHelper.ts +134 -134
  149. package/src/helpers/CheckSettlements.ts +94 -88
  150. package/src/helpers/Context.ts +87 -86
  151. package/src/helpers/CookieHelper.ts +23 -22
  152. package/src/helpers/EmailResumer.ts +10 -10
  153. package/src/helpers/FileCache.ts +62 -62
  154. package/src/helpers/ForwardHandler.test.ts +122 -124
  155. package/src/helpers/ForwardHandler.ts +76 -70
  156. package/src/helpers/MemberUserSyncer.ts +101 -96
  157. package/src/helpers/MembershipCharger.ts +69 -69
  158. package/src/helpers/MembershipHelper.ts +11 -12
  159. package/src/helpers/OpenIDConnectHelper.ts +85 -82
  160. package/src/helpers/PeriodHelper.ts +65 -70
  161. package/src/helpers/StripeHelper.ts +146 -137
  162. package/src/helpers/StripePayoutChecker.ts +51 -52
  163. package/src/helpers/ViesHelper.ts +46 -44
  164. package/src/helpers/fetchToAsyncIterator.ts +14 -14
  165. package/src/helpers/xlsxAddressTransformerColumnFactory.ts +50 -52
  166. package/src/middleware/ContextMiddleware.ts +5 -5
  167. package/src/migrations/1646578856-validate-addresses.ts +6 -9
  168. package/src/seeds/0000000000-example.ts +3 -5
  169. package/src/seeds/1715028563-user-permissions.ts +16 -18
  170. package/src/seeds/1722256498-group-update-occupancy.ts +12 -12
  171. package/src/seeds/1722344162-sync-member-users.ts +14 -15
  172. package/src/seeds/1722344162-update-membership.ts +6 -6
  173. package/src/seeds/1726055544-balance-item-paid.ts +4 -4
  174. package/src/seeds/1726055545-balance-item-pending.ts +4 -4
  175. package/src/seeds/1726494419-update-cached-outstanding-balance.ts +16 -16
  176. package/src/seeds/1726494420-update-cached-outstanding-balance-from-items.ts +12 -12
  177. package/src/seeds/1726572303-schedule-stock-updates.ts +12 -12
  178. package/src/seeds/1726847064-setup-steps.ts +16 -0
  179. package/src/sql-filters/balance-item-payments.ts +7 -7
  180. package/src/sql-filters/events.ts +14 -14
  181. package/src/sql-filters/members.ts +96 -96
  182. package/src/sql-filters/organizations.ts +139 -75
  183. package/src/sql-filters/payments.ts +28 -28
  184. package/src/sql-filters/registrations.ts +14 -14
  185. package/src/sql-sorters/events.ts +25 -25
  186. package/src/sql-sorters/members.ts +26 -26
  187. package/src/sql-sorters/organizations.ts +36 -36
  188. package/src/sql-sorters/payments.ts +26 -26
  189. package/tests/e2e/stock.test.ts +616 -621
  190. package/tests/e2e/tickets.test.ts +255 -260
  191. package/tests/helpers/StripeMocker.ts +177 -179
  192. package/tests/helpers/TestServer.ts +9 -9
  193. package/tests/jest.global.setup.ts +14 -13
  194. package/tests/jest.setup.ts +33 -32
  195. package/.eslintrc.js +0 -61
  196. package/jest.config.js +0 -11
  197. package/src/helpers/SetupStepsUpdater.ts +0 -359
  198. package/src/seeds/1724076679-setup-steps.ts +0 -16
@@ -1,22 +1,22 @@
1
1
  import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
2
  import { MollieToken } from '@stamhoofd/models';
3
- import { CheckMollieResponse, Organization as OrganizationStruct, PermissionLevel } from "@stamhoofd/structures";
3
+ import { CheckMollieResponse, Organization as OrganizationStruct, PermissionLevel } from '@stamhoofd/structures';
4
4
 
5
5
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures';
6
6
  import { Context } from '../../../../helpers/Context';
7
7
 
8
8
  type Params = Record<string, never>;
9
- type Body = undefined
10
- type Query = undefined
11
- type ResponseBody = OrganizationStruct|CheckMollieResponse
9
+ type Body = undefined;
10
+ type Query = undefined;
11
+ type ResponseBody = OrganizationStruct | CheckMollieResponse;
12
12
 
13
- export class CheckMollieEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
13
+ export class CheckMollieEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
14
14
  protected doesMatch(request: Request): [true, Params] | [false] {
15
- if (request.method != "POST") {
15
+ if (request.method !== 'POST') {
16
16
  return [false];
17
17
  }
18
18
 
19
- const params = Endpoint.parseParameters(request.url, "/mollie/check", {});
19
+ const params = Endpoint.parseParameters(request.url, '/mollie/check', {});
20
20
 
21
21
  if (params) {
22
22
  return [true, params as Params];
@@ -27,19 +27,19 @@ export class CheckMollieEndpoint extends Endpoint<Params, Query, Body, ResponseB
27
27
 
28
28
  async handle(request: DecodedRequest<Params, Query, Body>) {
29
29
  const organization = await Context.setOrganizationScope();
30
- await Context.authenticate()
30
+ await Context.authenticate();
31
31
 
32
32
  // Fast throw first (more in depth checking for patches later)
33
33
  if (!await Context.auth.canManagePaymentAccounts(organization.id, PermissionLevel.Full)) {
34
- throw Context.auth.error()
34
+ throw Context.auth.error();
35
35
  }
36
36
 
37
- const mollie = await MollieToken.getTokenFor(organization.id)
37
+ const mollie = await MollieToken.getTokenFor(organization.id);
38
38
 
39
39
  if (!mollie) {
40
- organization.privateMeta.mollieOnboarding = null
41
- organization.privateMeta.mollieProfile = null
42
- await organization.save()
40
+ organization.privateMeta.mollieOnboarding = null;
41
+ organization.privateMeta.mollieProfile = null;
42
+ await organization.save();
43
43
 
44
44
  if (request.request.getVersion() < 200) {
45
45
  return new Response(await AuthenticatedStructures.organization(organization));
@@ -47,7 +47,7 @@ export class CheckMollieEndpoint extends Endpoint<Params, Query, Body, ResponseB
47
47
 
48
48
  return new Response(CheckMollieResponse.create({
49
49
  organization: await AuthenticatedStructures.organization(organization),
50
- profiles: []
50
+ profiles: [],
51
51
  }));
52
52
  }
53
53
  const profiles = await mollie.getProfiles();
@@ -57,16 +57,17 @@ export class CheckMollieEndpoint extends Endpoint<Params, Query, Body, ResponseB
57
57
 
58
58
  // Check profile is still valid
59
59
  if (organization.privateMeta.mollieProfile) {
60
- const s = organization.privateMeta.mollieProfile.id
61
- const profile = profiles.find(p => p.id === s)
60
+ const s = organization.privateMeta.mollieProfile.id;
61
+ const profile = profiles.find(p => p.id === s);
62
62
  if (!profile) {
63
- organization.privateMeta.mollieProfile = null
64
- } else {
65
- organization.privateMeta.mollieProfile = profile
63
+ organization.privateMeta.mollieProfile = null;
64
+ }
65
+ else {
66
+ organization.privateMeta.mollieProfile = profile;
66
67
  }
67
68
  }
68
69
 
69
- await organization.save()
70
+ await organization.save();
70
71
 
71
72
  if (request.request.getVersion() < 200) {
72
73
  return new Response(await AuthenticatedStructures.organization(organization));
@@ -74,7 +75,7 @@ export class CheckMollieEndpoint extends Endpoint<Params, Query, Body, ResponseB
74
75
 
75
76
  return new Response(CheckMollieResponse.create({
76
77
  organization: await AuthenticatedStructures.organization(organization),
77
- profiles
78
+ profiles,
78
79
  }));
79
80
  }
80
81
  }
@@ -1,8 +1,7 @@
1
-
2
1
  import { AutoEncoder, Decoder, field, StringDecoder } from '@simonbackx/simple-encoding';
3
2
  import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
4
3
  import { MollieToken } from '@stamhoofd/models';
5
- import { Organization as OrganizationStruct, PermissionLevel } from "@stamhoofd/structures";
4
+ import { Organization as OrganizationStruct, PermissionLevel } from '@stamhoofd/structures';
6
5
 
7
6
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures';
8
7
  import { checkMollieSettlementsFor } from '../../../../helpers/CheckSettlements';
@@ -12,21 +11,21 @@ type Params = Record<string, never>;
12
11
 
13
12
  class Body extends AutoEncoder {
14
13
  @field({ decoder: StringDecoder })
15
- code: string
14
+ code: string;
16
15
  }
17
16
 
18
- type Query = undefined
19
- type ResponseBody = OrganizationStruct
17
+ type Query = undefined;
18
+ type ResponseBody = OrganizationStruct;
20
19
 
21
- export class ConnectMollieEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
22
- bodyDecoder = Body as Decoder<Body>
20
+ export class ConnectMollieEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
21
+ bodyDecoder = Body as Decoder<Body>;
23
22
 
24
23
  protected doesMatch(request: Request): [true, Params] | [false] {
25
- if (request.method != "POST") {
24
+ if (request.method !== 'POST') {
26
25
  return [false];
27
26
  }
28
27
 
29
- const params = Endpoint.parseParameters(request.url, "/mollie/connect", {});
28
+ const params = Endpoint.parseParameters(request.url, '/mollie/connect', {});
30
29
 
31
30
  if (params) {
32
31
  return [true, params as Params];
@@ -37,18 +36,18 @@ export class ConnectMollieEndpoint extends Endpoint<Params, Query, Body, Respons
37
36
 
38
37
  async handle(request: DecodedRequest<Params, Query, Body>) {
39
38
  const organization = await Context.setOrganizationScope();
40
- await Context.authenticate()
39
+ await Context.authenticate();
41
40
 
42
41
  // Fast throw first (more in depth checking for patches later)
43
42
  if (!await Context.auth.canManagePaymentAccounts(organization.id, PermissionLevel.Full)) {
44
- throw Context.auth.error()
43
+ throw Context.auth.error();
45
44
  }
46
45
 
47
- const mollieToken = await MollieToken.create(organization, request.body.code)
46
+ const mollieToken = await MollieToken.create(organization, request.body.code);
48
47
 
49
48
  // Check settlements after linking (shouldn't block)
50
- checkMollieSettlementsFor(mollieToken.accessToken, true).catch(console.error)
51
-
49
+ checkMollieSettlementsFor(mollieToken.accessToken, true).catch(console.error);
50
+
52
51
  return new Response(await AuthenticatedStructures.organization(organization));
53
52
  }
54
53
  }
@@ -1,23 +1,22 @@
1
-
2
1
  import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
3
2
  import { MollieToken } from '@stamhoofd/models';
4
- import { Organization as OrganizationStruct, PermissionLevel } from "@stamhoofd/structures";
3
+ import { Organization as OrganizationStruct, PermissionLevel } from '@stamhoofd/structures';
5
4
 
6
5
  import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures';
7
6
  import { Context } from '../../../../helpers/Context';
8
7
 
9
8
  type Params = Record<string, never>;
10
- type Body = undefined
11
- type Query = undefined
12
- type ResponseBody = OrganizationStruct
9
+ type Body = undefined;
10
+ type Query = undefined;
11
+ type ResponseBody = OrganizationStruct;
13
12
 
14
- export class DisonnectMollieEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
13
+ export class DisonnectMollieEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
15
14
  protected doesMatch(request: Request): [true, Params] | [false] {
16
- if (request.method != "POST") {
15
+ if (request.method !== 'POST') {
17
16
  return [false];
18
17
  }
19
18
 
20
- const params = Endpoint.parseParameters(request.url, "/mollie/disconnect", {});
19
+ const params = Endpoint.parseParameters(request.url, '/mollie/disconnect', {});
21
20
 
22
21
  if (params) {
23
22
  return [true, params as Params];
@@ -28,22 +27,22 @@ export class DisonnectMollieEndpoint extends Endpoint<Params, Query, Body, Respo
28
27
 
29
28
  async handle(_: DecodedRequest<Params, Query, Body>) {
30
29
  const organization = await Context.setOrganizationScope();
31
- await Context.authenticate()
30
+ await Context.authenticate();
32
31
 
33
32
  // Fast throw first (more in depth checking for patches later)
34
33
  if (!await Context.auth.canManagePaymentAccounts(organization.id, PermissionLevel.Full)) {
35
- throw Context.auth.error()
34
+ throw Context.auth.error();
36
35
  }
37
36
 
38
- const mollieToken = await MollieToken.getTokenFor(organization.id)
37
+ const mollieToken = await MollieToken.getTokenFor(organization.id);
39
38
  await mollieToken?.revoke();
40
39
  organization.privateMeta.mollieOnboarding = null;
41
40
  organization.privateMeta.mollieProfile = null;
42
41
 
43
- await organization.save()
42
+ await organization.save();
44
43
 
45
44
  // TODO: disable all payment methods that use this method
46
-
45
+
47
46
  return new Response(await AuthenticatedStructures.organization(organization));
48
47
  }
49
48
  }
@@ -1,23 +1,22 @@
1
-
2
1
  import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
3
- import { isSimpleError, isSimpleErrors,SimpleError } from '@simonbackx/simple-errors';
2
+ import { isSimpleError, isSimpleErrors, SimpleError } from '@simonbackx/simple-errors';
4
3
  import { MollieToken } from '@stamhoofd/models';
5
4
  import { PermissionLevel } from '@stamhoofd/structures';
6
5
 
7
6
  import { Context } from '../../../../helpers/Context';
8
7
 
9
8
  type Params = Record<string, never>;
10
- type Body = undefined
11
- type Query = undefined
12
- type ResponseBody = string
9
+ type Body = undefined;
10
+ type Query = undefined;
11
+ type ResponseBody = string;
13
12
 
14
- export class GetMollieDashboardEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
13
+ export class GetMollieDashboardEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
15
14
  protected doesMatch(request: Request): [true, Params] | [false] {
16
- if (request.method != "GET") {
15
+ if (request.method !== 'GET') {
17
16
  return [false];
18
17
  }
19
18
 
20
- const params = Endpoint.parseParameters(request.url, "/mollie/dashboard", {});
19
+ const params = Endpoint.parseParameters(request.url, '/mollie/dashboard', {});
21
20
 
22
21
  if (params) {
23
22
  return [true, params as Params];
@@ -28,36 +27,37 @@ export class GetMollieDashboardEndpoint extends Endpoint<Params, Query, Body, Re
28
27
 
29
28
  async handle(_: DecodedRequest<Params, Query, Body>) {
30
29
  const organization = await Context.setOrganizationScope();
31
- await Context.authenticate()
30
+ await Context.authenticate();
32
31
 
33
32
  // Fast throw first (more in depth checking for patches later)
34
33
  if (!await Context.auth.canManagePaymentAccounts(organization.id, PermissionLevel.Full)) {
35
- throw Context.auth.error()
34
+ throw Context.auth.error();
36
35
  }
37
-
38
- const mollie = await MollieToken.getTokenFor(organization.id)
36
+
37
+ const mollie = await MollieToken.getTokenFor(organization.id);
39
38
  if (!mollie) {
40
39
  throw new SimpleError({
41
- code: "not_yet_linked",
42
- message: "Mollie is nog niet gekoppeld. Koppel Mollie eerst voor je de gegevens aanvult"
43
- })
40
+ code: 'not_yet_linked',
41
+ message: 'Mollie is nog niet gekoppeld. Koppel Mollie eerst voor je de gegevens aanvult',
42
+ });
44
43
  }
45
44
 
46
45
  try {
47
- const url = await mollie.getOnboardingLink() as string
46
+ const url = await mollie.getOnboardingLink() as string;
48
47
 
49
- const response = new Response(url)
50
- response.headers['Content-Type'] = "text/plain"
51
- return response
52
- } catch (e) {
48
+ const response = new Response(url);
49
+ response.headers['Content-Type'] = 'text/plain';
50
+ return response;
51
+ }
52
+ catch (e) {
53
53
  if (isSimpleErrors(e) || isSimpleError(e)) {
54
54
  throw e;
55
55
  }
56
- await mollie.delete()
56
+ await mollie.delete();
57
57
  throw new SimpleError({
58
- code: "not_yet_linked",
59
- message: "Mollie is nog niet gekoppeld. Koppel Mollie eerst voor je de gegevens aanvult"
60
- })
58
+ code: 'not_yet_linked',
59
+ message: 'Mollie is nog niet gekoppeld. Koppel Mollie eerst voor je de gegevens aanvult',
60
+ });
61
61
  }
62
62
  }
63
63
  }
@@ -10,13 +10,12 @@ type Query = undefined;
10
10
  type Body = undefined;
11
11
  class ResponseBody extends AutoEncoder {
12
12
  @field({ decoder: StringDecoder })
13
- jwt: string
13
+ jwt: string;
14
14
  }
15
15
 
16
16
  export class CreateNoltTokenEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
17
-
18
17
  protected doesMatch(request: Request): [true, Params] | [false] {
19
- if (request.method != "POST") {
18
+ if (request.method !== 'POST') {
20
19
  return [false];
21
20
  }
22
21
 
@@ -24,7 +23,7 @@ export class CreateNoltTokenEndpoint extends Endpoint<Params, Query, Body, Respo
24
23
  return [false];
25
24
  }
26
25
 
27
- const params = Endpoint.parseParameters(request.url, "/nolt/create-token", {});
26
+ const params = Endpoint.parseParameters(request.url, '/nolt/create-token', {});
28
27
 
29
28
  if (params) {
30
29
  return [true, params as Params];
@@ -34,13 +33,13 @@ export class CreateNoltTokenEndpoint extends Endpoint<Params, Query, Body, Respo
34
33
 
35
34
  async handle(_: DecodedRequest<Params, Query, Body>) {
36
35
  const organization = await Context.setOrganizationScope();
37
- const {user} = await Context.authenticate()
36
+ const { user } = await Context.authenticate();
38
37
 
39
38
  // Fast throw first (more in depth checking for patches later)
40
39
  if (!await Context.auth.hasSomeAccess(organization.id)) {
41
- throw Context.auth.error()
40
+ throw Context.auth.error();
42
41
  }
43
-
42
+
44
43
  // Create token
45
44
  const payload = {
46
45
  // The ID that you use in your app for this user
@@ -49,14 +48,13 @@ export class CreateNoltTokenEndpoint extends Endpoint<Params, Query, Body, Respo
49
48
  // Nolt should use for notifications
50
49
  email: user.email,
51
50
  // The display name for this user
52
- name: user.firstName+" "+user.lastName,
51
+ name: user.firstName + ' ' + user.lastName,
53
52
 
54
53
  // Optional: The URL to the user's avatar picture
55
- imageUrl: organization.meta.squareLogo?.getPublicPath() ?? organization.meta.horizontalLogo?.getPublicPath() ?? undefined
56
- }
54
+ imageUrl: organization.meta.squareLogo?.getPublicPath() ?? organization.meta.horizontalLogo?.getPublicPath() ?? undefined,
55
+ };
57
56
 
58
57
  const str = jwt.sign(payload, STAMHOOFD.NOLT_SSO_SECRET_KEY, { algorithm: 'HS256' });
59
- return new Response(ResponseBody.create({ "jwt": str }));
60
-
58
+ return new Response(ResponseBody.create({ jwt: str }));
61
59
  }
62
60
  }
@@ -1,22 +1,22 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from "@simonbackx/simple-endpoints";
2
- import { SimpleError } from "@simonbackx/simple-errors";
1
+ import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
+ import { SimpleError } from '@simonbackx/simple-errors';
3
3
  import { Group, Token } from '@stamhoofd/models';
4
- import { Group as GroupStruct, GroupStatus } from "@stamhoofd/structures";
4
+ import { Group as GroupStruct, GroupStatus } from '@stamhoofd/structures';
5
5
 
6
- import { AuthenticatedStructures } from "../../../../helpers/AuthenticatedStructures";
7
- import { Context } from "../../../../helpers/Context";
6
+ import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures';
7
+ import { Context } from '../../../../helpers/Context';
8
8
  type Params = Record<string, never>;
9
9
  type Query = undefined;
10
- type Body = undefined
11
- type ResponseBody = GroupStruct[]
10
+ type Body = undefined;
11
+ type ResponseBody = GroupStruct[];
12
12
 
13
13
  export class GetOrganizationArchivedEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
14
14
  protected doesMatch(request: Request): [true, Params] | [false] {
15
- if (request.method != "GET") {
15
+ if (request.method !== 'GET') {
16
16
  return [false];
17
17
  }
18
18
 
19
- const params = Endpoint.parseParameters(request.url, "/organization/archived-groups", {});
19
+ const params = Endpoint.parseParameters(request.url, '/organization/archived-groups', {});
20
20
 
21
21
  if (params) {
22
22
  return [true, params as Params];
@@ -26,17 +26,17 @@ export class GetOrganizationArchivedEndpoint extends Endpoint<Params, Query, Bod
26
26
 
27
27
  async handle(_: DecodedRequest<Params, Query, Body>) {
28
28
  const organization = await Context.setOrganizationScope();
29
- await Context.authenticate()
29
+ await Context.authenticate();
30
30
 
31
31
  if (!await Context.auth.canAccessArchivedGroups(organization.id)) {
32
- throw Context.auth.error()
32
+ throw Context.auth.error();
33
33
  }
34
34
 
35
35
  // Get all admins
36
- const groups = await Group.where({ organizationId: organization.id, status: GroupStatus.Archived, deletedAt: null })
37
- const structures: GroupStruct[] = []
36
+ const groups = await Group.where({ organizationId: organization.id, status: GroupStatus.Archived, deletedAt: null });
37
+ const structures: GroupStruct[] = [];
38
38
  for (const g of groups) {
39
- structures.push(await AuthenticatedStructures.group(g))
39
+ structures.push(await AuthenticatedStructures.group(g));
40
40
  }
41
41
  return new Response(structures);
42
42
  }
@@ -1,21 +1,21 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from "@simonbackx/simple-endpoints";
1
+ import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
2
  import { Group } from '@stamhoofd/models';
3
- import { Group as GroupStruct } from "@stamhoofd/structures";
3
+ import { Group as GroupStruct } from '@stamhoofd/structures';
4
4
 
5
- import { AuthenticatedStructures } from "../../../../helpers/AuthenticatedStructures";
6
- import { Context } from "../../../../helpers/Context";
5
+ import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures';
6
+ import { Context } from '../../../../helpers/Context';
7
7
  type Params = Record<string, never>;
8
8
  type Query = undefined;
9
- type Body = undefined
10
- type ResponseBody = GroupStruct[]
9
+ type Body = undefined;
10
+ type ResponseBody = GroupStruct[];
11
11
 
12
12
  export class GetOrganizationAdminsEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
13
13
  protected doesMatch(request: Request): [true, Params] | [false] {
14
- if (request.method != "GET") {
14
+ if (request.method !== 'GET') {
15
15
  return [false];
16
16
  }
17
17
 
18
- const params = Endpoint.parseParameters(request.url, "/organization/deleted-groups", {});
18
+ const params = Endpoint.parseParameters(request.url, '/organization/deleted-groups', {});
19
19
 
20
20
  if (params) {
21
21
  return [true, params as Params];
@@ -25,17 +25,17 @@ export class GetOrganizationAdminsEndpoint extends Endpoint<Params, Query, Body,
25
25
 
26
26
  async handle(_: DecodedRequest<Params, Query, Body>) {
27
27
  const organization = await Context.setOrganizationScope();
28
- await Context.authenticate()
28
+ await Context.authenticate();
29
29
 
30
30
  if (!await Context.auth.canAccessArchivedGroups(organization.id)) {
31
- throw Context.auth.error()
31
+ throw Context.auth.error();
32
32
  }
33
33
 
34
34
  // Get all admins
35
- const groups = await Group.where({ organizationId: organization.id, deletedAt: { sign: '!=', value: null } })
36
- const structures: GroupStruct[] = []
35
+ const groups = await Group.where({ organizationId: organization.id, deletedAt: { sign: '!=', value: null } });
36
+ const structures: GroupStruct[] = [];
37
37
  for (const g of groups) {
38
- structures.push(await AuthenticatedStructures.group(g))
38
+ structures.push(await AuthenticatedStructures.group(g));
39
39
  }
40
40
  return new Response(structures);
41
41
  }
@@ -1,12 +1,12 @@
1
- import { DecodedRequest, Endpoint, Request, Response } from "@simonbackx/simple-endpoints";
2
- import { OpenIDClientConfiguration } from "@stamhoofd/structures";
1
+ import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
2
+ import { OpenIDClientConfiguration } from '@stamhoofd/structures';
3
3
 
4
- import { Context } from "../../../../helpers/Context";
4
+ import { Context } from '../../../../helpers/Context';
5
5
 
6
6
  type Params = Record<string, never>;
7
7
  type Query = undefined;
8
8
  type Body = undefined;
9
- type ResponseBody = OpenIDClientConfiguration
9
+ type ResponseBody = OpenIDClientConfiguration;
10
10
 
11
11
  /**
12
12
  * One endpoint to create, patch and delete groups. Usefull because on organization setup, we need to create multiple groups at once. Also, sometimes we need to link values and update multiple groups at once
@@ -14,11 +14,11 @@ type ResponseBody = OpenIDClientConfiguration
14
14
 
15
15
  export class GetOrganizationSSOEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
16
16
  protected doesMatch(request: Request): [true, Params] | [false] {
17
- if (request.method != "GET") {
17
+ if (request.method !== 'GET') {
18
18
  return [false];
19
19
  }
20
20
 
21
- const params = Endpoint.parseParameters(request.url, "/organization/sso", {});
21
+ const params = Endpoint.parseParameters(request.url, '/organization/sso', {});
22
22
 
23
23
  if (params) {
24
24
  return [true, params as Params];
@@ -28,16 +28,16 @@ export class GetOrganizationSSOEndpoint extends Endpoint<Params, Query, Body, Re
28
28
 
29
29
  async handle(_: DecodedRequest<Params, Query, Body>) {
30
30
  const organization = await Context.setOrganizationScope();
31
- await Context.authenticate()
31
+ await Context.authenticate();
32
32
 
33
33
  if (!await Context.auth.canManageSSOSettings(organization.id)) {
34
- throw Context.auth.error()
34
+ throw Context.auth.error();
35
35
  }
36
-
36
+
37
37
  return new Response(organization.serverMeta.ssoConfiguration ?? OpenIDClientConfiguration.create({
38
- clientId: "",
39
- clientSecret: "",
40
- issuer: ""
38
+ clientId: '',
39
+ clientSecret: '',
40
+ issuer: '',
41
41
  }));
42
42
  }
43
43
  }