@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.
- package/eslint.config.mjs +5 -0
- package/index.ts +81 -74
- package/jest.config.cjs +10 -0
- package/migrations.ts +16 -14
- package/package.json +11 -11
- package/src/crons/clear-excel-cache.test.ts +48 -50
- package/src/crons/clear-excel-cache.ts +18 -18
- package/src/crons/setup-steps.ts +2 -2
- package/src/crons.ts +325 -306
- package/src/decoders/StringArrayDecoder.ts +7 -7
- package/src/decoders/StringNullableDecoder.ts +1 -2
- package/src/email-recipient-loaders/members.ts +22 -22
- package/src/endpoints/admin/memberships/ChargeMembershipsEndpoint.ts +8 -9
- package/src/endpoints/admin/memberships/GetChargeMembershipsSummaryEndpoint.ts +39 -40
- package/src/endpoints/admin/organizations/GetOrganizationsCountEndpoint.ts +8 -8
- package/src/endpoints/admin/organizations/GetOrganizationsEndpoint.ts +44 -45
- package/src/endpoints/admin/organizations/PatchOrganizationsEndpoint.ts +58 -57
- package/src/endpoints/auth/CreateAdminEndpoint.ts +48 -45
- package/src/endpoints/auth/CreateTokenEndpoint.test.ts +31 -31
- package/src/endpoints/auth/CreateTokenEndpoint.ts +146 -147
- package/src/endpoints/auth/DeleteTokenEndpoint.ts +7 -7
- package/src/endpoints/auth/DeleteUserEndpoint.ts +15 -15
- package/src/endpoints/auth/ForgotPasswordEndpoint.ts +17 -18
- package/src/endpoints/auth/GetOtherUserEndpoint.ts +9 -10
- package/src/endpoints/auth/GetUserEndpoint.test.ts +32 -35
- package/src/endpoints/auth/GetUserEndpoint.ts +5 -6
- package/src/endpoints/auth/PatchApiUserEndpoint.ts +35 -33
- package/src/endpoints/auth/PatchUserEndpoint.ts +55 -52
- package/src/endpoints/auth/PollEmailVerificationEndpoint.ts +9 -9
- package/src/endpoints/auth/RetryEmailVerificationEndpoint.ts +8 -8
- package/src/endpoints/auth/SignupEndpoint.ts +37 -36
- package/src/endpoints/auth/VerifyEmailEndpoint.ts +29 -28
- package/src/endpoints/global/addresses/SearchRegionsEndpoint.ts +33 -33
- package/src/endpoints/global/addresses/ValidateAddressEndpoint.ts +7 -7
- package/src/endpoints/global/caddy/CheckDomainCertEndpoint.ts +37 -37
- package/src/endpoints/global/email/CreateEmailEndpoint.ts +30 -30
- package/src/endpoints/global/email/GetEmailAddressEndpoint.ts +13 -13
- package/src/endpoints/global/email/GetEmailEndpoint.ts +13 -13
- package/src/endpoints/global/email/ManageEmailAddressEndpoint.ts +16 -16
- package/src/endpoints/global/email/PatchEmailEndpoint.ts +25 -25
- package/src/endpoints/global/events/GetEventsEndpoint.ts +43 -44
- package/src/endpoints/global/events/PatchEventsEndpoint.ts +127 -172
- package/src/endpoints/global/files/ExportToExcelEndpoint.ts +49 -50
- package/src/endpoints/global/files/GetFileCache.ts +13 -13
- package/src/endpoints/global/files/UploadFile.ts +51 -54
- package/src/endpoints/global/files/UploadImage.ts +53 -53
- package/src/endpoints/global/groups/GetGroupsEndpoint.ts +25 -25
- package/src/endpoints/global/members/GetMemberFamilyEndpoint.ts +24 -23
- package/src/endpoints/global/members/GetMembersCountEndpoint.ts +8 -8
- package/src/endpoints/global/members/GetMembersEndpoint.ts +105 -102
- package/src/endpoints/global/members/PatchOrganizationMembersEndpoint.ts +240 -239
- package/src/endpoints/global/organizations/CheckRegisterCodeEndpoint.ts +12 -14
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.test.ts +32 -33
- package/src/endpoints/global/organizations/CreateOrganizationEndpoint.ts +48 -57
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.test.ts +21 -22
- package/src/endpoints/global/organizations/GetOrganizationFromDomainEndpoint.ts +28 -28
- package/src/endpoints/global/organizations/GetOrganizationFromUriEndpoint.ts +18 -18
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.test.ts +20 -20
- package/src/endpoints/global/organizations/SearchOrganizationEndpoint.ts +17 -17
- package/src/endpoints/global/payments/StripeWebhookEndpoint.ts +81 -75
- package/src/endpoints/global/platform/GetPlatformAdminsEndpoint.ts +14 -14
- package/src/endpoints/global/platform/GetPlatformEnpoint.ts +11 -11
- package/src/endpoints/global/platform/PatchPlatformEnpoint.ts +71 -68
- package/src/endpoints/global/registration/GetPaymentRegistrations.ts +27 -27
- package/src/endpoints/global/registration/GetUserBillingStatusEndpoint.ts +30 -30
- package/src/endpoints/global/registration/GetUserDetailedBillingStatusEndpoint.ts +34 -34
- package/src/endpoints/global/registration/GetUserDocumentsEndpoint.ts +26 -26
- package/src/endpoints/global/registration/GetUserMembersEndpoint.ts +12 -12
- package/src/endpoints/global/registration/PatchUserMembersEndpoint.ts +90 -90
- package/src/endpoints/global/registration/RegisterMembersEndpoint.test.ts +118 -121
- package/src/endpoints/global/registration/RegisterMembersEndpoint.ts +362 -350
- package/src/endpoints/global/registration-periods/GetRegistrationPeriodsEndpoint.ts +8 -9
- package/src/endpoints/global/registration-periods/PatchRegistrationPeriodsEndpoint.ts +21 -21
- package/src/endpoints/global/webshops/GetWebshopFromDomainEndpoint.ts +65 -65
- package/src/endpoints/organization/dashboard/billing/GetOrganizationBillingStatusEndpoint.ts +9 -9
- package/src/endpoints/organization/dashboard/billing/GetOrganizationDetailedBillingStatusEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplateXML.ts +17 -17
- package/src/endpoints/organization/dashboard/documents/GetDocumentTemplatesEndpoint.ts +21 -21
- package/src/endpoints/organization/dashboard/documents/GetDocumentsEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/documents/PatchDocumentEndpoint.ts +52 -52
- package/src/endpoints/organization/dashboard/documents/PatchDocumentTemplateEndpoint.ts +37 -37
- package/src/endpoints/organization/dashboard/email/CheckEmailBouncesEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/email/EmailEndpoint.ts +113 -112
- package/src/endpoints/organization/dashboard/email-templates/GetEmailTemplatesEndpoint.ts +29 -29
- package/src/endpoints/organization/dashboard/email-templates/PatchEmailTemplatesEndpoint.ts +48 -47
- package/src/endpoints/organization/dashboard/mollie/CheckMollieEndpoint.ts +22 -21
- package/src/endpoints/organization/dashboard/mollie/ConnectMollieEndpoint.ts +13 -14
- package/src/endpoints/organization/dashboard/mollie/DisconnectMollieEndpoint.ts +12 -13
- package/src/endpoints/organization/dashboard/mollie/GetMollieDashboardEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/nolt/CreateNoltTokenEndpoint.ts +10 -12
- package/src/endpoints/organization/dashboard/organization/GetOrganizationArchivedGroups.ts +14 -14
- package/src/endpoints/organization/dashboard/organization/GetOrganizationDeletedGroups.ts +13 -13
- package/src/endpoints/organization/dashboard/organization/GetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.test.ts +120 -124
- package/src/endpoints/organization/dashboard/organization/PatchOrganizationEndpoint.ts +172 -173
- package/src/endpoints/organization/dashboard/organization/SetOrganizationDomainEndpoint.ts +88 -89
- package/src/endpoints/organization/dashboard/organization/SetOrganizationSSOEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/payments/GetMemberBalanceEndpoint.ts +17 -17
- package/src/endpoints/organization/dashboard/payments/GetPaymentsCountEndpoint.ts +8 -8
- package/src/endpoints/organization/dashboard/payments/GetPaymentsEndpoint.ts +66 -67
- package/src/endpoints/organization/dashboard/payments/PatchBalanceItemsEndpoint.ts +47 -47
- package/src/endpoints/organization/dashboard/payments/PatchPaymentsEndpoint.ts +93 -91
- package/src/endpoints/organization/dashboard/registration-periods/GetOrganizationRegistrationPeriodsEndpoint.ts +16 -17
- package/src/endpoints/organization/dashboard/registration-periods/PatchOrganizationRegistrationPeriodsEndpoint.ts +170 -167
- package/src/endpoints/organization/dashboard/registration-periods/SetupStepReviewEndpoint.ts +25 -24
- package/src/endpoints/organization/dashboard/stripe/ConnectStripeEndpoint.ts +22 -23
- package/src/endpoints/organization/dashboard/stripe/DeleteStripeAccountEndpoint.ts +22 -22
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/GetStripeAccountsEndpoint.ts +8 -9
- package/src/endpoints/organization/dashboard/stripe/GetStripeLoginLinkEndpoint.ts +17 -18
- package/src/endpoints/organization/dashboard/stripe/UpdateStripeAccountEndpoint.ts +14 -15
- package/src/endpoints/organization/dashboard/users/CreateApiUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/DeleteUserEndpoint.ts +19 -19
- package/src/endpoints/organization/dashboard/users/GetApiUsersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/users/GetOrganizationAdminsEndpoint.ts +12 -12
- package/src/endpoints/organization/dashboard/webshops/CreateWebshopEndpoint.ts +103 -100
- package/src/endpoints/organization/dashboard/webshops/DeleteWebshopEndpoint.ts +11 -12
- package/src/endpoints/organization/dashboard/webshops/GetDiscountCodesEndpoint.ts +15 -15
- package/src/endpoints/organization/dashboard/webshops/GetWebshopOrdersEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopTicketsEndpoint.ts +14 -14
- package/src/endpoints/organization/dashboard/webshops/GetWebshopUriAvailabilityEndpoint.ts +23 -23
- package/src/endpoints/organization/dashboard/webshops/PatchDiscountCodesEndpoint.ts +54 -52
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopEndpoint.ts +84 -81
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopOrdersEndpoint.ts +120 -111
- package/src/endpoints/organization/dashboard/webshops/PatchWebshopTicketsEndpoint.ts +24 -24
- package/src/endpoints/organization/dashboard/webshops/VerifyWebshopDomainEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/ExchangePaymentEndpoint.ts +141 -130
- package/src/endpoints/organization/shared/GetDocumentHtml.ts +25 -25
- package/src/endpoints/organization/shared/GetPaymentEndpoint.ts +18 -18
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.test.ts +36 -37
- package/src/endpoints/organization/shared/auth/GetOrganizationEndpoint.ts +9 -9
- package/src/endpoints/organization/shared/auth/OpenIDConnectCallbackEndpoint.ts +11 -11
- package/src/endpoints/organization/shared/auth/OpenIDConnectStartEndpoint.ts +28 -27
- package/src/endpoints/organization/webshops/CheckWebshopDiscountCodesEndpoint.ts +20 -20
- package/src/endpoints/organization/webshops/GetOrderByPaymentEndpoint.ts +22 -22
- package/src/endpoints/organization/webshops/GetOrderEndpoint.ts +14 -14
- package/src/endpoints/organization/webshops/GetTicketsEndpoint.ts +57 -56
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.test.ts +65 -66
- package/src/endpoints/organization/webshops/GetWebshopEndpoint.ts +18 -17
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.test.ts +124 -128
- package/src/endpoints/organization/webshops/PlaceOrderEndpoint.ts +154 -145
- package/src/excel-loaders/members.ts +102 -103
- package/src/excel-loaders/payments.ts +155 -156
- package/src/helpers/AddressValidator.test.ts +32 -32
- package/src/helpers/AddressValidator.ts +128 -122
- package/src/helpers/AdminPermissionChecker.ts +339 -236
- package/src/helpers/AuthenticatedStructures.ts +233 -134
- package/src/helpers/BuckarooHelper.ts +134 -134
- package/src/helpers/CheckSettlements.ts +94 -88
- package/src/helpers/Context.ts +87 -86
- package/src/helpers/CookieHelper.ts +23 -22
- package/src/helpers/EmailResumer.ts +10 -10
- package/src/helpers/FileCache.ts +62 -62
- package/src/helpers/ForwardHandler.test.ts +122 -124
- package/src/helpers/ForwardHandler.ts +76 -70
- package/src/helpers/MemberUserSyncer.ts +101 -96
- package/src/helpers/MembershipCharger.ts +69 -69
- package/src/helpers/MembershipHelper.ts +11 -12
- package/src/helpers/OpenIDConnectHelper.ts +85 -82
- package/src/helpers/PeriodHelper.ts +65 -70
- package/src/helpers/StripeHelper.ts +146 -137
- package/src/helpers/StripePayoutChecker.ts +51 -52
- package/src/helpers/ViesHelper.ts +46 -44
- package/src/helpers/fetchToAsyncIterator.ts +14 -14
- package/src/helpers/xlsxAddressTransformerColumnFactory.ts +50 -52
- package/src/middleware/ContextMiddleware.ts +5 -5
- package/src/migrations/1646578856-validate-addresses.ts +6 -9
- package/src/seeds/0000000000-example.ts +3 -5
- package/src/seeds/1715028563-user-permissions.ts +16 -18
- package/src/seeds/1722256498-group-update-occupancy.ts +12 -12
- package/src/seeds/1722344162-sync-member-users.ts +14 -15
- package/src/seeds/1722344162-update-membership.ts +6 -6
- package/src/seeds/1726055544-balance-item-paid.ts +4 -4
- package/src/seeds/1726055545-balance-item-pending.ts +4 -4
- package/src/seeds/1726494419-update-cached-outstanding-balance.ts +16 -16
- package/src/seeds/1726494420-update-cached-outstanding-balance-from-items.ts +12 -12
- package/src/seeds/1726572303-schedule-stock-updates.ts +12 -12
- package/src/seeds/1726847064-setup-steps.ts +16 -0
- package/src/sql-filters/balance-item-payments.ts +7 -7
- package/src/sql-filters/events.ts +14 -14
- package/src/sql-filters/members.ts +96 -96
- package/src/sql-filters/organizations.ts +139 -75
- package/src/sql-filters/payments.ts +28 -28
- package/src/sql-filters/registrations.ts +14 -14
- package/src/sql-sorters/events.ts +25 -25
- package/src/sql-sorters/members.ts +26 -26
- package/src/sql-sorters/organizations.ts +36 -36
- package/src/sql-sorters/payments.ts +26 -26
- package/tests/e2e/stock.test.ts +616 -621
- package/tests/e2e/tickets.test.ts +255 -260
- package/tests/helpers/StripeMocker.ts +177 -179
- package/tests/helpers/TestServer.ts +9 -9
- package/tests/jest.global.setup.ts +14 -13
- package/tests/jest.setup.ts +33 -32
- package/.eslintrc.js +0 -61
- package/jest.config.js +0 -11
- package/src/helpers/SetupStepsUpdater.ts +0 -359
- package/src/seeds/1724076679-setup-steps.ts +0 -16
|
@@ -1,78 +1,77 @@
|
|
|
1
|
-
import { Request } from
|
|
1
|
+
import { Request } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { GroupFactory, OrganizationFactory, Token, UserFactory } from '@stamhoofd/models';
|
|
3
3
|
import { Organization, PermissionLevel, Permissions } from '@stamhoofd/structures';
|
|
4
4
|
|
|
5
|
-
import { testServer } from
|
|
5
|
+
import { testServer } from '../../../../../tests/helpers/TestServer';
|
|
6
6
|
import { GetOrganizationEndpoint } from './GetOrganizationEndpoint';
|
|
7
7
|
|
|
8
|
-
describe(
|
|
8
|
+
describe('Endpoint.GetOrganization', () => {
|
|
9
9
|
// Test endpoint
|
|
10
10
|
const endpoint = new GetOrganizationEndpoint();
|
|
11
11
|
|
|
12
|
-
test(
|
|
13
|
-
const organization = await new OrganizationFactory({}).create()
|
|
14
|
-
const user = await new UserFactory({ organization }).create()
|
|
15
|
-
const groups = await new GroupFactory({ organization }).createMultiple(2)
|
|
16
|
-
const token = await Token.createToken(user)
|
|
12
|
+
test('Get organization as signed in user', async () => {
|
|
13
|
+
const organization = await new OrganizationFactory({}).create();
|
|
14
|
+
const user = await new UserFactory({ organization }).create();
|
|
15
|
+
const groups = await new GroupFactory({ organization }).createMultiple(2);
|
|
16
|
+
const token = await Token.createToken(user);
|
|
17
17
|
|
|
18
|
-
const r = Request.buildJson(
|
|
19
|
-
r.headers.authorization =
|
|
18
|
+
const r = Request.buildJson('GET', '/v3/organization', organization.getApiHost());
|
|
19
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
20
20
|
|
|
21
21
|
const response = await testServer.test(endpoint, r);
|
|
22
22
|
expect(response.body).toBeDefined();
|
|
23
23
|
|
|
24
24
|
if (!(response.body instanceof Organization)) {
|
|
25
|
-
throw new Error(
|
|
25
|
+
throw new Error('Expected Organization');
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
expect(response.body.id).toEqual(organization.id)
|
|
29
|
-
expect(response.body.groups.map(g => g.id).sort()).toEqual(groups.map(g => g.id).sort())
|
|
30
|
-
expect(response.body.privateMeta).toEqual(null)
|
|
28
|
+
expect(response.body.id).toEqual(organization.id);
|
|
29
|
+
expect(response.body.groups.map(g => g.id).sort()).toEqual(groups.map(g => g.id).sort());
|
|
30
|
+
expect(response.body.privateMeta).toEqual(null);
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
-
test(
|
|
34
|
-
const organization = await new OrganizationFactory({}).create()
|
|
33
|
+
test('Get organization as admin', async () => {
|
|
34
|
+
const organization = await new OrganizationFactory({}).create();
|
|
35
35
|
const user = await new UserFactory({
|
|
36
36
|
organization,
|
|
37
37
|
permissions: Permissions.create({
|
|
38
|
-
level: PermissionLevel.Read
|
|
39
|
-
})
|
|
40
|
-
}).create()
|
|
38
|
+
level: PermissionLevel.Read,
|
|
39
|
+
}),
|
|
40
|
+
}).create();
|
|
41
41
|
|
|
42
|
-
const groups = await new GroupFactory({ organization }).createMultiple(2)
|
|
43
|
-
const token = await Token.createToken(user)
|
|
42
|
+
const groups = await new GroupFactory({ organization }).createMultiple(2);
|
|
43
|
+
const token = await Token.createToken(user);
|
|
44
44
|
|
|
45
|
-
const r = Request.buildJson(
|
|
46
|
-
r.headers.authorization =
|
|
45
|
+
const r = Request.buildJson('GET', '/v3/organization', organization.getApiHost());
|
|
46
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
47
47
|
|
|
48
48
|
const response = await testServer.test(endpoint, r);
|
|
49
49
|
expect(response.body).toBeDefined();
|
|
50
50
|
|
|
51
51
|
if (!(response.body instanceof Organization)) {
|
|
52
|
-
throw new Error(
|
|
52
|
+
throw new Error('Expected Organization');
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
expect(response.body.id).toEqual(organization.id)
|
|
56
|
-
expect(response.body.groups.map(g => g.id).sort()).toEqual(groups.map(g => g.id).sort())
|
|
57
|
-
expect(response.body.privateMeta).not.toEqual(null)
|
|
55
|
+
expect(response.body.id).toEqual(organization.id);
|
|
56
|
+
expect(response.body.groups.map(g => g.id).sort()).toEqual(groups.map(g => g.id).sort());
|
|
57
|
+
expect(response.body.privateMeta).not.toEqual(null);
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
const organization = await new OrganizationFactory({}).create()
|
|
62
|
-
const organization2 = await new OrganizationFactory({}).create()
|
|
60
|
+
test('Get organization as admin of a different organization', async () => {
|
|
61
|
+
const organization = await new OrganizationFactory({}).create();
|
|
62
|
+
const organization2 = await new OrganizationFactory({}).create();
|
|
63
63
|
const user = await new UserFactory({
|
|
64
64
|
organization: organization2,
|
|
65
65
|
permissions: Permissions.create({
|
|
66
|
-
level: PermissionLevel.Read
|
|
67
|
-
})
|
|
68
|
-
}).create()
|
|
66
|
+
level: PermissionLevel.Read,
|
|
67
|
+
}),
|
|
68
|
+
}).create();
|
|
69
69
|
|
|
70
|
-
const token = await Token.createToken(user)
|
|
70
|
+
const token = await Token.createToken(user);
|
|
71
71
|
|
|
72
|
-
const r = Request.buildJson(
|
|
73
|
-
r.headers.authorization =
|
|
72
|
+
const r = Request.buildJson('GET', '/v3/organization', organization.getApiHost());
|
|
73
|
+
r.headers.authorization = 'Bearer ' + token.accessToken;
|
|
74
74
|
|
|
75
75
|
await expect(testServer.test(endpoint, r)).rejects.toThrow('The access token is invalid');
|
|
76
76
|
});
|
|
77
|
-
|
|
78
77
|
});
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { DecodedRequest, Endpoint, Request, Response } from
|
|
2
|
-
import { Organization as OrganizationStruct } from
|
|
1
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
|
+
import { Organization as OrganizationStruct } from '@stamhoofd/structures';
|
|
3
3
|
|
|
4
|
-
import { AuthenticatedStructures } from
|
|
5
|
-
import { Context } from
|
|
4
|
+
import { AuthenticatedStructures } from '../../../../helpers/AuthenticatedStructures';
|
|
5
|
+
import { Context } from '../../../../helpers/Context';
|
|
6
6
|
|
|
7
7
|
type Params = Record<string, never>;
|
|
8
8
|
type Query = undefined;
|
|
9
|
-
type Body = undefined
|
|
9
|
+
type Body = undefined;
|
|
10
10
|
type ResponseBody = OrganizationStruct;
|
|
11
11
|
|
|
12
12
|
export class GetOrganizationEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
13
13
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
14
|
-
if (request.method
|
|
14
|
+
if (request.method !== 'GET') {
|
|
15
15
|
return [false];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const params = Endpoint.parseParameters(request.url,
|
|
18
|
+
const params = Endpoint.parseParameters(request.url, '/organization', {});
|
|
19
19
|
|
|
20
20
|
if (params) {
|
|
21
21
|
return [true, params as Params];
|
|
@@ -25,10 +25,10 @@ export class GetOrganizationEndpoint extends Endpoint<Params, Query, Body, Respo
|
|
|
25
25
|
|
|
26
26
|
async handle(_: DecodedRequest<Params, Query, Body>) {
|
|
27
27
|
const organization = await Context.setOrganizationScope();
|
|
28
|
-
await Context.optionalAuthenticate({allowWithoutAccount: true})
|
|
28
|
+
await Context.optionalAuthenticate({ allowWithoutAccount: true });
|
|
29
29
|
|
|
30
30
|
return new Response(
|
|
31
|
-
await AuthenticatedStructures.organization(organization)
|
|
31
|
+
await AuthenticatedStructures.organization(organization),
|
|
32
32
|
);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyDecoder, Decoder } from '@simonbackx/simple-encoding';
|
|
2
|
-
import { DecodedRequest, Endpoint, Request } from
|
|
2
|
+
import { DecodedRequest, Endpoint, Request } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
4
|
|
|
5
5
|
import { Context } from '../../../../helpers/Context';
|
|
@@ -14,11 +14,11 @@ export class OpenIDConnectCallbackEndpoint extends Endpoint<Params, Query, Body,
|
|
|
14
14
|
bodyDecoder = AnyDecoder as Decoder<any>;
|
|
15
15
|
|
|
16
16
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
17
|
-
if (request.method
|
|
17
|
+
if (request.method !== 'POST') {
|
|
18
18
|
return [false];
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const params = Endpoint.parseParameters(request.url,
|
|
21
|
+
const params = Endpoint.parseParameters(request.url, '/openid/callback', {});
|
|
22
22
|
|
|
23
23
|
if (params) {
|
|
24
24
|
return [true, params as Params];
|
|
@@ -27,18 +27,18 @@ export class OpenIDConnectCallbackEndpoint extends Endpoint<Params, Query, Body,
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
30
|
-
const organization = await Context.setOrganizationScope()
|
|
31
|
-
const configuration = organization.serverMeta.ssoConfiguration
|
|
30
|
+
const organization = await Context.setOrganizationScope();
|
|
31
|
+
const configuration = organization.serverMeta.ssoConfiguration;
|
|
32
32
|
|
|
33
33
|
if (!configuration) {
|
|
34
34
|
throw new SimpleError({
|
|
35
|
-
code:
|
|
36
|
-
message:
|
|
37
|
-
statusCode: 400
|
|
35
|
+
code: 'invalid_configuration',
|
|
36
|
+
message: 'Invalid configuration',
|
|
37
|
+
statusCode: 400,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const helper = new OpenIDConnectHelper(organization, configuration)
|
|
42
|
-
return await helper.callback(request)
|
|
41
|
+
const helper = new OpenIDConnectHelper(organization, configuration);
|
|
42
|
+
return await helper.callback(request);
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Decoder } from '@simonbackx/simple-encoding';
|
|
2
|
-
import { DecodedRequest, Endpoint, Request } from
|
|
2
|
+
import { DecodedRequest, Endpoint, Request } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
4
|
import { Webshop } from '@stamhoofd/models';
|
|
5
|
-
import { StartOpenIDFlowStruct } from
|
|
5
|
+
import { StartOpenIDFlowStruct } from '@stamhoofd/structures';
|
|
6
6
|
|
|
7
7
|
import { Context } from '../../../../helpers/Context';
|
|
8
8
|
import { OpenIDConnectHelper } from '../../../../helpers/OpenIDConnectHelper';
|
|
@@ -16,11 +16,11 @@ export class OpenIDConnectStartEndpoint extends Endpoint<Params, Query, Body, Re
|
|
|
16
16
|
bodyDecoder = StartOpenIDFlowStruct as Decoder<StartOpenIDFlowStruct>;
|
|
17
17
|
|
|
18
18
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
19
|
-
if (request.method
|
|
19
|
+
if (request.method !== 'POST') {
|
|
20
20
|
return [false];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
const params = Endpoint.parseParameters(request.url,
|
|
23
|
+
const params = Endpoint.parseParameters(request.url, '/openid/start', {});
|
|
24
24
|
|
|
25
25
|
if (params) {
|
|
26
26
|
return [true, params as Params];
|
|
@@ -30,20 +30,20 @@ export class OpenIDConnectStartEndpoint extends Endpoint<Params, Query, Body, Re
|
|
|
30
30
|
|
|
31
31
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
32
32
|
// Check webshop and/or organization
|
|
33
|
-
const organization = await Context.setOrganizationScope()
|
|
33
|
+
const organization = await Context.setOrganizationScope();
|
|
34
34
|
const webshopId = request.body.webshopId;
|
|
35
|
-
let redirectUri = 'https://' + organization.getHost()
|
|
36
|
-
|
|
35
|
+
let redirectUri = 'https://' + organization.getHost();
|
|
36
|
+
|
|
37
37
|
if (webshopId) {
|
|
38
|
-
const webshop = await Webshop.getByID(webshopId)
|
|
38
|
+
const webshop = await Webshop.getByID(webshopId);
|
|
39
39
|
if (!webshop || webshop.organizationId !== organization.id) {
|
|
40
40
|
throw new SimpleError({
|
|
41
|
-
code:
|
|
42
|
-
message:
|
|
43
|
-
statusCode: 400
|
|
41
|
+
code: 'invalid_webshop',
|
|
42
|
+
message: 'Invalid webshop',
|
|
43
|
+
statusCode: 400,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
redirectUri = 'https://' + webshop.setRelation(Webshop.organization, organization).getHost()
|
|
46
|
+
redirectUri = 'https://' + webshop.setRelation(Webshop.organization, organization).getHost();
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
if (request.body.redirectUri) {
|
|
@@ -51,32 +51,33 @@ export class OpenIDConnectStartEndpoint extends Endpoint<Params, Query, Body, Re
|
|
|
51
51
|
const allowedHost = new URL(redirectUri);
|
|
52
52
|
const givenUrl = new URL(request.body.redirectUri);
|
|
53
53
|
|
|
54
|
-
if (allowedHost.host === givenUrl.host && givenUrl.protocol ===
|
|
55
|
-
redirectUri = givenUrl.href
|
|
54
|
+
if (allowedHost.host === givenUrl.host && givenUrl.protocol === 'https:') {
|
|
55
|
+
redirectUri = givenUrl.href;
|
|
56
56
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.error('Invalid redirect uri', request.body.redirectUri);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
if (request.body.spaState.length < 10) {
|
|
63
64
|
throw new SimpleError({
|
|
64
|
-
code:
|
|
65
|
-
message:
|
|
66
|
-
statusCode: 400
|
|
65
|
+
code: 'invalid_state',
|
|
66
|
+
message: 'Invalid state',
|
|
67
|
+
statusCode: 400,
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
const configuration = organization.serverMeta.ssoConfiguration
|
|
70
|
+
|
|
71
|
+
const configuration = organization.serverMeta.ssoConfiguration;
|
|
71
72
|
if (!configuration) {
|
|
72
73
|
throw new SimpleError({
|
|
73
|
-
code:
|
|
74
|
-
message:
|
|
75
|
-
statusCode: 400
|
|
74
|
+
code: 'invalid_client',
|
|
75
|
+
message: 'SSO not configured',
|
|
76
|
+
statusCode: 400,
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
const helper = new OpenIDConnectHelper(organization, configuration)
|
|
80
|
-
return await helper.startAuthCodeFlow(redirectUri, request.body.provider, request.body.spaState, request.body.prompt)
|
|
80
|
+
const helper = new OpenIDConnectHelper(organization, configuration);
|
|
81
|
+
return await helper.startAuthCodeFlow(redirectUri, request.body.provider, request.body.spaState, request.body.prompt);
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { ArrayDecoder, StringDecoder } from
|
|
2
|
-
import { DecodedRequest, Endpoint, Request, Response } from
|
|
1
|
+
import { ArrayDecoder, StringDecoder } from '@simonbackx/simple-encoding';
|
|
2
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
4
|
import { Webshop, WebshopDiscountCode } from '@stamhoofd/models';
|
|
5
|
-
import { DiscountCode } from
|
|
5
|
+
import { DiscountCode } from '@stamhoofd/structures';
|
|
6
6
|
|
|
7
|
-
import { Context } from
|
|
7
|
+
import { Context } from '../../../helpers/Context';
|
|
8
8
|
|
|
9
9
|
type Params = { id: string };
|
|
10
10
|
type Query = undefined;
|
|
11
|
-
type Body = string[]
|
|
12
|
-
type ResponseBody = DiscountCode[]
|
|
11
|
+
type Body = string[];
|
|
12
|
+
type ResponseBody = DiscountCode[];
|
|
13
13
|
|
|
14
14
|
export class CheckWebshopDiscountCodesEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
15
|
-
bodyDecoder = new ArrayDecoder(StringDecoder)
|
|
15
|
+
bodyDecoder = new ArrayDecoder(StringDecoder);
|
|
16
16
|
|
|
17
17
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
18
|
-
if (request.method
|
|
18
|
+
if (request.method !== 'POST') {
|
|
19
19
|
return [false];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const params = Endpoint.parseParameters(request.url,
|
|
22
|
+
const params = Endpoint.parseParameters(request.url, '/webshop/@id/discount-codes', { id: String });
|
|
23
23
|
|
|
24
24
|
if (params) {
|
|
25
25
|
return [true, params as Params];
|
|
@@ -28,29 +28,29 @@ export class CheckWebshopDiscountCodesEndpoint extends Endpoint<Params, Query, B
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
31
|
-
const organization = await Context.setOrganizationScope()
|
|
32
|
-
const webshop = await Webshop.getByID(request.params.id)
|
|
33
|
-
if (!webshop || webshop.organizationId
|
|
31
|
+
const organization = await Context.setOrganizationScope();
|
|
32
|
+
const webshop = await Webshop.getByID(request.params.id);
|
|
33
|
+
if (!webshop || webshop.organizationId !== organization.id) {
|
|
34
34
|
throw new SimpleError({
|
|
35
|
-
code:
|
|
36
|
-
message:
|
|
37
|
-
human:
|
|
38
|
-
})
|
|
35
|
+
code: 'not_found',
|
|
36
|
+
message: 'Webshop not found',
|
|
37
|
+
human: 'Deze webshop bestaat niet (meer)',
|
|
38
|
+
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
if (request.body.length > 10) {
|
|
42
42
|
// Auto limit
|
|
43
|
-
request.body = request.body.slice(0, 10)
|
|
43
|
+
request.body = request.body.slice(0, 10);
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
// Check all discount codes
|
|
47
47
|
// Return all valid ones
|
|
48
48
|
if (request.body.length > 0) {
|
|
49
|
-
const codes = await WebshopDiscountCode.getActiveCodes(webshop.id, request.body)
|
|
49
|
+
const codes = await WebshopDiscountCode.getActiveCodes(webshop.id, request.body);
|
|
50
50
|
|
|
51
51
|
// todo
|
|
52
52
|
return new Response(
|
|
53
|
-
codes.map(c => c.getStructure())
|
|
53
|
+
codes.map(c => c.getStructure()),
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { PartialWithoutMethods } from
|
|
2
|
-
import { DecodedRequest, Endpoint, Request, Response } from
|
|
1
|
+
import { PartialWithoutMethods } from '@simonbackx/simple-encoding';
|
|
2
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
3
3
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
4
4
|
import { Order } from '@stamhoofd/models';
|
|
5
5
|
import { Payment } from '@stamhoofd/models';
|
|
6
|
-
import { Order as OrderStruct } from
|
|
6
|
+
import { Order as OrderStruct } from '@stamhoofd/structures';
|
|
7
7
|
|
|
8
|
-
import { Context } from
|
|
8
|
+
import { Context } from '../../../helpers/Context';
|
|
9
9
|
type Params = { id: string; paymentId: string };
|
|
10
10
|
type Query = undefined;
|
|
11
|
-
type Body = undefined
|
|
12
|
-
type ResponseBody = OrderStruct
|
|
11
|
+
type Body = undefined;
|
|
12
|
+
type ResponseBody = OrderStruct;
|
|
13
13
|
|
|
14
14
|
export class GetOrderByPaymentEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
15
15
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
16
|
-
if (request.method
|
|
16
|
+
if (request.method !== 'GET') {
|
|
17
17
|
return [false];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const params = Endpoint.parseParameters(request.url,
|
|
20
|
+
const params = Endpoint.parseParameters(request.url, '/webshop/@id/payment/@paymentId/order', { id: String, paymentId: String });
|
|
21
21
|
|
|
22
22
|
if (params) {
|
|
23
23
|
return [true, params as Params];
|
|
@@ -26,26 +26,26 @@ export class GetOrderByPaymentEndpoint extends Endpoint<Params, Query, Body, Res
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
29
|
-
const organization = await Context.setOrganizationScope()
|
|
30
|
-
const payment = await Payment.getByID(request.params.paymentId)
|
|
29
|
+
const organization = await Context.setOrganizationScope();
|
|
30
|
+
const payment = await Payment.getByID(request.params.paymentId);
|
|
31
31
|
|
|
32
|
-
if (!payment || payment.organizationId
|
|
32
|
+
if (!payment || payment.organizationId !== organization.id) {
|
|
33
33
|
throw new SimpleError({
|
|
34
|
-
code:
|
|
35
|
-
message:
|
|
36
|
-
human:
|
|
37
|
-
})
|
|
34
|
+
code: 'not_found',
|
|
35
|
+
message: 'Order not found',
|
|
36
|
+
human: 'Deze bestelling bestaat niet (meer)',
|
|
37
|
+
});
|
|
38
38
|
}
|
|
39
|
-
const [order] = await Order.where({ paymentId: payment.id }, { limit: 1})
|
|
40
|
-
if (!order || order.webshopId
|
|
39
|
+
const [order] = await Order.where({ paymentId: payment.id }, { limit: 1 });
|
|
40
|
+
if (!order || order.webshopId !== request.params.id || order.organizationId !== organization.id) {
|
|
41
41
|
throw new SimpleError({
|
|
42
|
-
code:
|
|
43
|
-
message:
|
|
44
|
-
human:
|
|
45
|
-
})
|
|
42
|
+
code: 'not_found',
|
|
43
|
+
message: 'Order not found',
|
|
44
|
+
human: 'Deze bestelling bestaat niet (meer)',
|
|
45
|
+
});
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
order.setRelation(Order.payment, payment)
|
|
48
|
+
order.setRelation(Order.payment, payment);
|
|
49
49
|
return new Response(await order.getStructure());
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { DecodedRequest, Endpoint, Request, Response } from
|
|
1
|
+
import { DecodedRequest, Endpoint, Request, Response } from '@simonbackx/simple-endpoints';
|
|
2
2
|
import { SimpleError } from '@simonbackx/simple-errors';
|
|
3
3
|
import { Order } from '@stamhoofd/models';
|
|
4
|
-
import { Order as OrderStruct } from
|
|
4
|
+
import { Order as OrderStruct } from '@stamhoofd/structures';
|
|
5
5
|
|
|
6
|
-
import { Context } from
|
|
6
|
+
import { Context } from '../../../helpers/Context';
|
|
7
7
|
type Params = { id: string; orderId: string };
|
|
8
8
|
type Query = undefined;
|
|
9
|
-
type Body = undefined
|
|
10
|
-
type ResponseBody = OrderStruct
|
|
9
|
+
type Body = undefined;
|
|
10
|
+
type ResponseBody = OrderStruct;
|
|
11
11
|
|
|
12
12
|
export class GetOrderEndpoint extends Endpoint<Params, Query, Body, ResponseBody> {
|
|
13
13
|
protected doesMatch(request: Request): [true, Params] | [false] {
|
|
14
|
-
if (request.method
|
|
14
|
+
if (request.method !== 'GET') {
|
|
15
15
|
return [false];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const params = Endpoint.parseParameters(request.url,
|
|
18
|
+
const params = Endpoint.parseParameters(request.url, '/webshop/@id/order/@orderId', { id: String, orderId: String });
|
|
19
19
|
|
|
20
20
|
if (params) {
|
|
21
21
|
return [true, params as Params];
|
|
@@ -24,15 +24,15 @@ export class GetOrderEndpoint extends Endpoint<Params, Query, Body, ResponseBody
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async handle(request: DecodedRequest<Params, Query, Body>) {
|
|
27
|
-
const organization = await Context.setOrganizationScope()
|
|
28
|
-
const order = await Order.getByID(request.params.orderId)
|
|
27
|
+
const organization = await Context.setOrganizationScope();
|
|
28
|
+
const order = await Order.getByID(request.params.orderId);
|
|
29
29
|
|
|
30
|
-
if (!order || order.webshopId
|
|
30
|
+
if (!order || order.webshopId !== request.params.id || order.organizationId !== organization.id) {
|
|
31
31
|
throw new SimpleError({
|
|
32
|
-
code:
|
|
33
|
-
message:
|
|
34
|
-
human:
|
|
35
|
-
})
|
|
32
|
+
code: 'not_found',
|
|
33
|
+
message: 'Order not found',
|
|
34
|
+
human: 'Deze bestelling bestaat niet (meer)',
|
|
35
|
+
});
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return new Response(await order.getStructure());
|