Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit efbba57

Browse files
chore(vendor): update @lightbasenl/backend
_This PR is created by sync and will be force-pushed daily. Overwriting any manual changes done to this PR._ - Allow custom function to check 2fa enabled (lightbasenl/platform-components#1352) (lightbasenl/platform-components@f69c14a) - feat(backend): various fixes for the TypeScript migration (lightbasenl/platform-components@9f6c1b0) - feat(backend): support passing user props to authTestCreateUser (lightbasenl/platform-components@a7f7fad) - chore(deps): Bump @xmldom/xmldom from 0.9.4 to 0.9.5 in the production group (lightbasenl/platform-components#1348) (lightbasenl/platform-components@4204470) - chore(deps): Bump rate-limiter-flexible from 5.0.3 to 5.0.4 in the production group (lightbasenl/platform-components#1346) (lightbasenl/platform-components@822c961) - chore(deps): Bump @xmldom/xmldom from 0.9.3 to 0.9.4 in the production group (lightbasenl/platform-components#1344) (lightbasenl/platform-components@5e34679) - fix(feature-flag): allow updating 'userValues' (lightbasenl/platform-components@bb290dd) - fix(feature-flag): use correct sql connection for fetching session (lightbasenl/platform-components@33e27e8) - chore(deps): bump xmldom (lightbasenl/platform-components@b1d5ba6) - chore: replace lint setup with @lightbase/eslint-config (lightbasenl/platform-components@c8e7656) - feat!(backend): feature flags per user (lightbasenl/platform-components#1341) (lightbasenl/platform-components@075e8cd) - feat(backend): add hook to be called in `authRequireUser` on a successful check (lightbasenl/platform-components@90f5223) - chore: make compatible with new and old lint configs (lightbasenl/platform-components@445035b) - chore(deps): Bump @lightbase/pull-through-cache from 0.2.0 to 0.2.1 in the production group (lightbasenl/platform-components#1326) (lightbasenl/platform-components@83e6a49) - chore(backend): remove duplicate check on `requiredPermissions` (lightbasenl/platform-components@387fa87) - feat(backend): support `oneOfRequiredPermissions` (lightbasenl/platform-components@f78adcc) - feat(feature-flag,multitenant): report cache events as Sentry metric (lightbasenl/platform-components@22ebc13)- Failed to execute `npx compas lint`. Sync is not able to correct this, so human checks and fixes are necessary for this PR.
1 parent 07e7822 commit efbba57

37 files changed

+266
-130
lines changed

gen/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import { storeGetStructure } from "@compas/store";
2+
import { featureFlagDefinition, permissions } from "../src/constants.js";
3+
import { extendWithAuthCustom } from "./auth.js";
4+
import { extendWithDatabase } from "./database.js";
5+
import { extendWithMail } from "./mail.js";
6+
import { extendWithScaffold } from "./scaffold.js";
7+
import { extendWithType } from "./type.js";
28
import {
39
authPermissions,
410
extendWithAuthAnonymousBased,
@@ -9,12 +15,6 @@ import {
915
extendWithFeatureFlag,
1016
extendWithManagement,
1117
} from "@lightbasenl/backend";
12-
import { featureFlagDefinition, permissions } from "../src/constants.js";
13-
import { extendWithAuthCustom } from "./auth.js";
14-
import { extendWithDatabase } from "./database.js";
15-
import { extendWithMail } from "./mail.js";
16-
import { extendWithScaffold } from "./scaffold.js";
17-
import { extendWithType } from "./type.js";
1818

1919
/**
2020
* Extend with compas additional/optional package structures

package-lock.json

+17-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/queue.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ import {
1010
queueWorkerCreate,
1111
queueWorkerRegisterCronJobs,
1212
} from "@compas/store";
13-
import {
14-
authEventNames,
15-
authJobNames,
16-
authPasswordBasedInvalidateResetTokens,
17-
managementInvalidateUsers,
18-
} from "@lightbasenl/backend";
1913
import {
2014
authAnonymousBasedUserRegisteredEvent,
2115
authPasswordBasedEmailUpdatedEvent,
@@ -29,6 +23,12 @@ import { injectServices } from "../src/service.js";
2923
import { serviceLogger } from "../src/services/logger.js";
3024
import { sql } from "../src/services/postgres.js";
3125
import { bucketName, s3Client } from "../src/services/s3.js";
26+
import {
27+
authEventNames,
28+
authJobNames,
29+
authPasswordBasedInvalidateResetTokens,
30+
managementInvalidateUsers,
31+
} from "@lightbasenl/backend";
3232

3333
mainFn(import.meta, main);
3434

src/auth/jobs.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function authAnonymousBasedUserRegisteredEvent(
3636
}
3737

3838
// TODO(platform): Act
39-
// eslint-disable-next-line no-unused-vars
39+
4040
const x = 5;
4141

4242
eventStop(event);
@@ -87,7 +87,7 @@ export async function authPasswordBasedUserRegisteredEvent(
8787
}
8888

8989
// TODO(platform): Act
90-
// eslint-disable-next-line no-unused-vars
90+
9191
const x = 5;
9292

9393
eventStop(event);
@@ -139,7 +139,7 @@ export async function authPasswordBasedForgotPasswordEvent(
139139
}
140140

141141
// TODO(platform): Act
142-
// eslint-disable-next-line no-unused-vars
142+
143143
const x = 5;
144144

145145
eventStop(event);
@@ -180,7 +180,7 @@ export async function authPasswordBasedPasswordUpdatedEvent(
180180
}
181181

182182
// TODO(platform): Act
183-
// eslint-disable-next-line no-unused-vars
183+
184184
const x = 5;
185185

186186
eventStop(event);
@@ -228,7 +228,7 @@ export async function authPasswordBasedEmailUpdatedEvent(event, sql, { data }) {
228228
}
229229

230230
// TODO(platform): Act
231-
// eslint-disable-next-line no-unused-vars
231+
232232
const x = 5;
233233

234234
eventStop(event);
@@ -269,7 +269,7 @@ export async function authPasswordBasedLoginVerifiedEvent(
269269
}
270270

271271
// TODO(platform): Act
272-
// eslint-disable-next-line no-unused-vars
272+
273273
const x = 5;
274274

275275
eventStop(event);
@@ -310,7 +310,7 @@ export async function authPasswordBasedPasswordResetEvent(
310310
}
311311

312312
// TODO(platform): Act
313-
// eslint-disable-next-line no-unused-vars
313+
314314
const x = 5;
315315

316316
eventStop(event);

src/mail/events.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function mailSendGeneric(event, email, payload) {
4242
* @param {function(MailAddressHeaders, T): MailTemplateResponse} template
4343
* @param {MailAddressHeaders} addresses
4444
* @param {T} [payload={}]
45-
* @param {import("@types/nodemailer").Attachment[]} [attachments]
45+
* @param {Array<import("@types/nodemailer").Attachment>} [attachments]
4646
* @returns {Promise<void>}
4747
*/
4848
async function mailSend(
@@ -92,9 +92,9 @@ async function mailSend(
9292
* Construct a mail header object for nodemailer
9393
*
9494
* @param {MailAddress} from
95-
* @param {MailAddress|MailAddress[]} to
96-
* @param {MailAddress[]|undefined} [cc]
97-
* @param {MailAddress[]|undefined} [bcc]
95+
* @param {MailAddress | Array<MailAddress>} to
96+
* @param {Array<MailAddress> | undefined} [cc]
97+
* @param {Array<MailAddress> | undefined} [bcc]
9898
* @returns {MailAddressHeaders}
9999
*/
100100
function constructMailAddressHeaders(from, to, cc, bcc) {

src/scaffold/controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { newEventFromEvent } from "@compas/stdlib";
2-
import { authCreateUser, multitenantRequireTenant } from "@lightbasenl/backend";
32
import { scaffoldHandlers } from "../generated/application/scaffold/controller.js";
43
import { sql } from "../services/postgres.js";
4+
import { authCreateUser, multitenantRequireTenant } from "@lightbasenl/backend";
55

66
// TODO(platform): remove this;
77
scaffoldHandlers.createUser = async (ctx) => {

src/services/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createBodyParser, getApp } from "@compas/server";
2-
import { backendGetConfig } from "@lightbasenl/backend";
32
import { router } from "../generated/application/common/router.js";
43
import { serviceLogger } from "./logger.js";
4+
import { backendGetConfig } from "@lightbasenl/backend";
55

66
/**
77
* @type {Application}

src/services/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AppError, environment } from "@compas/stdlib";
55
* This method should be used as guard during startup to ensure non-unexpected
66
* code paths are hit during runtime.
77
*
8-
* @param {string[]} requiredEnvironmentVariables
8+
* @param {Array<string>} requiredEnvironmentVariables
99
* @returns {void}
1010
*/
1111
export function ensureEnvironmentVars(requiredEnvironmentVariables) {

src/services/lpc.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { newEvent } from "@compas/stdlib";
2+
import { buildMandatoryRoles, permissions } from "../constants.js";
3+
import { serviceLogger } from "./logger.js";
24
import {
35
authPermissions,
46
backendInit,
57
backendInitServices,
68
} from "@lightbasenl/backend";
7-
import { buildMandatoryRoles, permissions } from "../constants.js";
8-
import { serviceLogger } from "./logger.js";
99

1010
/**
1111
* @returns {Promise<void>}

src/testing.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import {
44
cleanupTestPostgresDatabase,
55
objectStorageRemoveBucket,
66
} from "@compas/store";
7-
import {
8-
authInjectTokenInterceptors,
9-
multitenantInjectAxios,
10-
} from "@lightbasenl/backend";
117
import axios from "axios";
128
import { axiosInterceptErrorAndWrapWithAppError } from "./generated/application/common/api-client.js";
139
import {
@@ -25,6 +21,10 @@ import {
2521
serviceS3EnsureBuckets,
2622
serviceS3Init,
2723
} from "./services/s3.js";
24+
import {
25+
authInjectTokenInterceptors,
26+
multitenantInjectAxios,
27+
} from "@lightbasenl/backend";
2828

2929
/**
3030
* Initialize all services based on an empty database and fresh s3 bucket.

vendor/backend/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ erDiagram
200200
string description
201201
string name
202202
generic tenantValues
203+
generic userValues
203204
date createdAt
204205
date updatedAt
205206
}

vendor/backend/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
],
1414
"scripts": {},
1515
"dependencies": {
16-
"@lightbase/pull-through-cache": "0.1.2",
17-
"@xmldom/xmldom": "0.8.10",
16+
"@lightbase/pull-through-cache": "0.2.1",
17+
"@xmldom/xmldom": "0.9.5",
1818
"bcrypt": "5.1.1",
19-
"rate-limiter-flexible": "5.0.3",
19+
"rate-limiter-flexible": "5.0.4",
2020
"speakeasy": "2.0.0",
2121
"xml-crypto": "6.0.0",
2222
"xpath": "0.0.34"
@@ -30,5 +30,5 @@
3030
"url": "https://github.com/lightbasenl/platform-components.git",
3131
"directory": "packages/backend"
3232
},
33-
"gitHead": "b335a6c8aa6f5e14489b582b02b6fa45beda00b6"
33+
"gitHead": "f69c14a63c3acd44091d5d869c8c2d6ee20a82a7"
3434
}

vendor/backend/src/auth/anonymous-based/controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export async function applyAnonymousBasedController(settings) {
7979

8080
const set2FACheck =
8181
typeof settings.determineTwoStepFunction === "function" &&
82-
(settings.determineTwoStepFunction(user) ?? {});
82+
((await settings.determineTwoStepFunction(ctx, user)) ?? {});
8383

8484
const newSessionResult = await sessionStoreCreate(
8585
newEventFromEvent(ctx.event),

vendor/backend/src/auth/apply.js

+23-19
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,29 @@ import { applyTotpProviderController } from "./totp-provider/controller.js";
1717

1818
/**
1919
* @typedef {(
20-
* user: QueryResultAuthUser
21-
* ) => AuthDetermineTwoStepResult} AuthDetermineTwoStepCheckFunction
20+
* ctx: import("koa").ExtendableContext, user: QueryResultAuthUser
21+
* ) => Promise<AuthDetermineTwoStepResult>|AuthDetermineTwoStepResult}
22+
* AuthDetermineTwoStepCheckFunction
2223
*/
2324

25+
/**
26+
* @type {AuthDetermineTwoStepCheckFunction}
27+
*/
28+
export const authDefaultDetermineTwoStepFunction = (ctx, user) => {
29+
if (!isNil(user?.totpSettings?.verifiedAt)) {
30+
return {
31+
type: "checkTwoStep",
32+
twoStepType: "totpProvider",
33+
};
34+
} else if (!isNil(user?.passwordLogin?.otpEnabledAt)) {
35+
// TODO: what should happen if the user didn't login via passwordLogin?
36+
return {
37+
type: "checkTwoStep",
38+
twoStepType: "passwordBasedOtp",
39+
};
40+
}
41+
};
42+
2443
/**
2544
* Apply the auth package with the provided settings.
2645
* Make sure to call `routerClearMemoizedHandlers` when calling `applyAuth` again on the
@@ -37,24 +56,9 @@ export async function applyAuth({
3756
keycloakBased,
3857
passwordBased,
3958
totpProvider,
59+
determineTwoStepFunction,
4060
}) {
41-
/**
42-
* @type {AuthDetermineTwoStepCheckFunction}
43-
*/
44-
const determineTwoStepFunction = (user) => {
45-
if (!isNil(user?.totpSettings?.verifiedAt)) {
46-
return {
47-
type: "checkTwoStep",
48-
twoStepType: "totpProvider",
49-
};
50-
} else if (!isNil(user?.passwordLogin?.otpEnabledAt)) {
51-
// TODO: what should happen if the user didn't login via passwordLogin?
52-
return {
53-
type: "checkTwoStep",
54-
twoStepType: "passwordBasedOtp",
55-
};
56-
}
57-
};
61+
determineTwoStepFunction ??= authDefaultDetermineTwoStepFunction;
5862

5963
await applyAuthController();
6064
await applySessionController({});

vendor/backend/src/auth/digid-based/controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export async function applyDigidBasedController(settings) {
153153

154154
const set2FACheck =
155155
typeof settings.determineTwoStepFunction === "function" &&
156-
(settings.determineTwoStepFunction(user) ?? {});
156+
((await settings.determineTwoStepFunction(ctx, user)) ?? {});
157157

158158
const newSessionResult = await sessionStoreCreate(
159159
newEventFromEvent(ctx.event),

vendor/backend/src/auth/digid-based/events.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
uuid,
1616
} from "@compas/stdlib";
1717
import { queueWorkerAddJob } from "@compas/store";
18-
import xmldom from "@xmldom/xmldom";
18+
import xmldom, { MIME_TYPE } from "@xmldom/xmldom";
1919
import axios from "axios";
2020
import xmlCrypto from "xml-crypto";
2121
import xpath from "xpath";
@@ -362,7 +362,10 @@ export async function authDigidBasedResolveArtifact(
362362
);
363363
}
364364

365-
const doc = new xmldom.DOMParser().parseFromString(xmlResponse);
365+
const doc = new xmldom.DOMParser().parseFromString(
366+
xmlResponse,
367+
MIME_TYPE.XML_APPLICATION,
368+
);
366369
const [mainStatus, subStatus, subSubStatus] = xpath.select(
367370
"//*[local-name(.)='StatusCode']/@Value",
368371
doc,
@@ -534,7 +537,10 @@ async function authDigidBasedGetSignatureForPayload(
534537
async function authDigidBasedVerifySignaturesForXmlPayload(event, payload) {
535538
eventStart(event, "authDigidBased.verifySignaturesForXmlPayload");
536539

537-
const doc = new xmldom.DOMParser().parseFromString(payload);
540+
const doc = new xmldom.DOMParser().parseFromString(
541+
payload,
542+
MIME_TYPE.XML_APPLICATION,
543+
);
538544
const signatures = xpath.select("//*[local-name(.)='Signature']", doc);
539545
if (signatures.length === 0) {
540546
throw AppError.serverError({

0 commit comments

Comments
 (0)