create-strata 2.2.31 → 2.2.33
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/dist/cli.js +120 -37
- package/dist/templates/package.json +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1373,6 +1373,21 @@ async function revokeUserSessions(userId: number) {
|
|
|
1373
1373
|
});
|
|
1374
1374
|
}
|
|
1375
1375
|
|
|
1376
|
+
${verify ? `
|
|
1377
|
+
async function completeSignedEmailVerification(request: Request): Promise<boolean> {
|
|
1378
|
+
return await runInTransaction(async () => {
|
|
1379
|
+
const userId = await consumeSignedAuthToken(request, AUTH_ONE_TIME_PURPOSES.emailVerify);
|
|
1380
|
+
if (!userId) return false;
|
|
1381
|
+
await runAuthWrite(userId, async () => {
|
|
1382
|
+
const user = await User.find(userId);
|
|
1383
|
+
if (!user) throw new Error("Verification account no longer exists.");
|
|
1384
|
+
await user.update({ email_verified_at: ${nowTimestampLiteral(layers.database)} });
|
|
1385
|
+
});
|
|
1386
|
+
return true;
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
` : ""}
|
|
1390
|
+
|
|
1376
1391
|
async function completeSignedPasswordReset(request: Request, password: unknown): Promise<boolean> {
|
|
1377
1392
|
if (typeof password !== "string" || password.length < 8) return false;
|
|
1378
1393
|
return await runInTransaction(async () => {
|
|
@@ -1592,14 +1607,9 @@ async function completeBrowserSsoLogin(
|
|
|
1592
1607
|
const jsonVerify = jsonApi && verify ? `
|
|
1593
1608
|
"/api/v1/auth/verify-email": {
|
|
1594
1609
|
POST: kernel.wrap("api", kernel.wrapSigned(withErrorHandling(async (request) => {
|
|
1595
|
-
|
|
1596
|
-
if (!id) {
|
|
1610
|
+
if (!(await completeSignedEmailVerification(request))) {
|
|
1597
1611
|
return jsonResponse({ error: "Invalid or expired verification link." }, { status: 403 });
|
|
1598
1612
|
}
|
|
1599
|
-
await runAuthWrite(id, async () => {
|
|
1600
|
-
const user = await User.find(id);
|
|
1601
|
-
await user?.update({ email_verified_at: ${nowTimestampLiteral(layers.database)} });
|
|
1602
|
-
});
|
|
1603
1613
|
return jsonResponse({ ok: true });
|
|
1604
1614
|
}))),
|
|
1605
1615
|
},` : "";
|
|
@@ -1911,12 +1921,7 @@ async function completeBrowserSsoLogin(
|
|
|
1911
1921
|
const url = new URL(request.url);
|
|
1912
1922
|
if (url.searchParams.get("signature")) {
|
|
1913
1923
|
assertValidSignature(request);
|
|
1914
|
-
|
|
1915
|
-
if (id) {
|
|
1916
|
-
await runAuthWrite(id, async () => {
|
|
1917
|
-
const user = await User.find(id);
|
|
1918
|
-
await user?.update({ email_verified_at: ${nowTimestampLiteral(layers.database)} });
|
|
1919
|
-
});
|
|
1924
|
+
if (await completeSignedEmailVerification(request)) {
|
|
1920
1925
|
return flashResponse(
|
|
1921
1926
|
redirectTo("/login"),
|
|
1922
1927
|
{ level: "success", message: "Email verified. Sign in." },
|
|
@@ -3158,9 +3163,9 @@ function renderPackageJson(projectName, options = {}) {
|
|
|
3158
3163
|
"@getstrata/cli": "workspace:*",
|
|
3159
3164
|
"@getstrata/core": "workspace:*"
|
|
3160
3165
|
} : {
|
|
3161
|
-
"@getstrata/bootstrap": "^2.2.
|
|
3162
|
-
"@getstrata/cli": "^2.2.
|
|
3163
|
-
"@getstrata/core": "^2.2.
|
|
3166
|
+
"@getstrata/bootstrap": "^2.2.33",
|
|
3167
|
+
"@getstrata/cli": "^2.2.33",
|
|
3168
|
+
"@getstrata/core": "^2.2.33"
|
|
3164
3169
|
};
|
|
3165
3170
|
coreDeps.eta = "^4.6.0";
|
|
3166
3171
|
if (options.layers?.database === "mysql") {
|
|
@@ -5295,6 +5300,7 @@ import type { AppModule } from "@getstrata/bootstrap/contracts";
|
|
|
5295
5300
|
import { routeParams } from "@getstrata/bootstrap/web/routing";
|
|
5296
5301
|
import { createScimAuthMiddleware } from "@getstrata/core/auth/scimAuthMiddleware";
|
|
5297
5302
|
import { hashPassword } from "@getstrata/core/auth/password";
|
|
5303
|
+
import { runInTransaction } from "@getstrata/core/database/transaction";
|
|
5298
5304
|
import { BadRequestError } from "@getstrata/core/errors/http";
|
|
5299
5305
|
import { parsePositiveIntParam } from "@getstrata/core/http/validation";
|
|
5300
5306
|
import { withErrorHandling } from "@getstrata/core/http/response";
|
|
@@ -5388,6 +5394,59 @@ function readName(body: Record<string, unknown>, fallback: string): string {
|
|
|
5388
5394
|
return fallback;
|
|
5389
5395
|
}
|
|
5390
5396
|
|
|
5397
|
+
function isScimObject(value: unknown): value is Record<string, unknown> {
|
|
5398
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5399
|
+
}
|
|
5400
|
+
|
|
5401
|
+
// This minimal adapter persists profile fields only. Never acknowledge a status
|
|
5402
|
+
// change (or part of a PATCH) that it cannot actually apply.
|
|
5403
|
+
function validateScimProfile(body: Record<string, unknown>, strict = false): Response | null {
|
|
5404
|
+
if ("active" in body && body.active !== true) {
|
|
5405
|
+
return scimError("Account status changes are not supported; no deactivation was performed.", 400);
|
|
5406
|
+
}
|
|
5407
|
+
const fields = ["userName", "emails", "name", "displayName", "active"];
|
|
5408
|
+
if (strict && Object.keys(body).some((key) => !fields.includes(key))) {
|
|
5409
|
+
return scimError("Unsupported profile attribute.", 400);
|
|
5410
|
+
}
|
|
5411
|
+
if (strict && !fields.some((key) => key in body)) return scimError("A profile value is required.", 400);
|
|
5412
|
+
for (const key of ["userName", "displayName"]) {
|
|
5413
|
+
const value = body[key];
|
|
5414
|
+
if (key in body && (typeof value !== "string" || !value.trim())) {
|
|
5415
|
+
return scimError("Profile strings must be non-empty.", 400);
|
|
5416
|
+
}
|
|
5417
|
+
}
|
|
5418
|
+
if ("emails" in body) {
|
|
5419
|
+
if (!Array.isArray(body.emails) || body.emails.length !== 1) {
|
|
5420
|
+
return scimError("Exactly one email value is supported.", 400);
|
|
5421
|
+
}
|
|
5422
|
+
const email = body.emails[0];
|
|
5423
|
+
if (!isScimObject(email) || typeof email.value !== "string" || !email.value.trim()) {
|
|
5424
|
+
return scimError("An email value is required.", 400);
|
|
5425
|
+
}
|
|
5426
|
+
if (Object.keys(email).some((key) => !["value", "primary"].includes(key)) || ("primary" in email && email.primary !== true)) {
|
|
5427
|
+
return scimError("Only one primary email value is supported.", 400);
|
|
5428
|
+
}
|
|
5429
|
+
}
|
|
5430
|
+
if ("name" in body) {
|
|
5431
|
+
if (!isScimObject(body.name) || Object.keys(body.name).some((key) => !["formatted", "givenName", "familyName"].includes(key))) {
|
|
5432
|
+
return scimError("Unsupported name value.", 400);
|
|
5433
|
+
}
|
|
5434
|
+
if (!Object.values(body.name).some((value) => typeof value === "string" && value.trim()) || Object.values(body.name).some((value) => typeof value !== "string")) {
|
|
5435
|
+
return scimError("Name values must be strings with a non-empty name.", 400);
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
return null;
|
|
5439
|
+
}
|
|
5440
|
+
|
|
5441
|
+
async function readScimBody(request: Request): Promise<Record<string, unknown> | Response> {
|
|
5442
|
+
try {
|
|
5443
|
+
const body: unknown = await request.json();
|
|
5444
|
+
return isScimObject(body) ? body : scimError("An object body is required.", 400);
|
|
5445
|
+
} catch {
|
|
5446
|
+
return scimError("Invalid JSON body.", 400);
|
|
5447
|
+
}
|
|
5448
|
+
}
|
|
5449
|
+
|
|
5391
5450
|
function wrapScim(kernel: HttpKernel, handler: (request: Request) => Promise<Response>) {
|
|
5392
5451
|
const throttle = kernel.ownThrottle(createScimThrottleMiddleware({
|
|
5393
5452
|
redisUrl: process.env.REDIS_URL,
|
|
@@ -5399,7 +5458,9 @@ function wrapScim(kernel: HttpKernel, handler: (request: Request) => Promise<Res
|
|
|
5399
5458
|
if (!scimEnabled()) {
|
|
5400
5459
|
return scimError("SCIM is off.", 404);
|
|
5401
5460
|
}
|
|
5402
|
-
return
|
|
5461
|
+
return ["POST", "PUT", "PATCH", "DELETE"].includes(request.method)
|
|
5462
|
+
? await runInTransaction(() => handler(request))
|
|
5463
|
+
: await handler(request);
|
|
5403
5464
|
}),
|
|
5404
5465
|
);
|
|
5405
5466
|
}
|
|
@@ -5470,7 +5531,10 @@ const scimModule: AppModule = {
|
|
|
5470
5531
|
POST: kernel.wrap(
|
|
5471
5532
|
"api",
|
|
5472
5533
|
wrapScim(kernel, async (request) => {
|
|
5473
|
-
const body =
|
|
5534
|
+
const body = await readScimBody(request);
|
|
5535
|
+
if (body instanceof Response) return body;
|
|
5536
|
+
const invalid = validateScimProfile(body);
|
|
5537
|
+
if (invalid) return invalid;
|
|
5474
5538
|
const email = readUserName(body);
|
|
5475
5539
|
const name = readName(body, email.split("@")[0] ?? "User");
|
|
5476
5540
|
if (!email) {
|
|
@@ -5511,7 +5575,10 @@ const scimModule: AppModule = {
|
|
|
5511
5575
|
if (id instanceof Response) {
|
|
5512
5576
|
return id;
|
|
5513
5577
|
}
|
|
5514
|
-
const body =
|
|
5578
|
+
const body = await readScimBody(request);
|
|
5579
|
+
if (body instanceof Response) return body;
|
|
5580
|
+
const invalid = validateScimProfile(body);
|
|
5581
|
+
if (invalid) return invalid;
|
|
5515
5582
|
const email = readUserName(body);
|
|
5516
5583
|
const name = readName(body, email);
|
|
5517
5584
|
if (!email || !name) {
|
|
@@ -5536,31 +5603,47 @@ const scimModule: AppModule = {
|
|
|
5536
5603
|
if (!user) {
|
|
5537
5604
|
return scimError("User not found.", 404);
|
|
5538
5605
|
}
|
|
5539
|
-
const body =
|
|
5540
|
-
if (body
|
|
5606
|
+
const body = await readScimBody(request);
|
|
5607
|
+
if (body instanceof Response) return body;
|
|
5608
|
+
if (!Array.isArray(body.schemas) || !body.schemas.includes(PATCH_SCHEMA)) {
|
|
5541
5609
|
return scimError("Unsupported patch schema.", 400);
|
|
5542
5610
|
}
|
|
5611
|
+
if (!Array.isArray(body.Operations) || body.Operations.length === 0) {
|
|
5612
|
+
return scimError("A non-empty Operations array is required.", 400);
|
|
5613
|
+
}
|
|
5543
5614
|
let name = String(user.get("name") ?? "");
|
|
5544
5615
|
let email = String(user.get("email") ?? "");
|
|
5545
|
-
for (const operation of body.Operations
|
|
5546
|
-
|
|
5547
|
-
|
|
5548
|
-
|
|
5616
|
+
for (const operation of body.Operations) {
|
|
5617
|
+
if (!isScimObject(operation) || typeof operation.op !== "string" || !["replace", "add"].includes(operation.op.toLowerCase())) {
|
|
5618
|
+
return scimError("Only add and replace profile operations are supported.", 400);
|
|
5619
|
+
}
|
|
5620
|
+
if (operation.path !== undefined && typeof operation.path !== "string") {
|
|
5621
|
+
return scimError("Invalid patch path.", 400);
|
|
5549
5622
|
}
|
|
5550
|
-
const path =
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
}
|
|
5559
|
-
} else if (
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5623
|
+
const path = typeof operation.path === "string" ? operation.path.toLowerCase() : "";
|
|
5624
|
+
let value: Record<string, unknown>;
|
|
5625
|
+
if (!path) {
|
|
5626
|
+
if (!isScimObject(operation.value)) return scimError("A profile object is required.", 400);
|
|
5627
|
+
value = operation.value;
|
|
5628
|
+
} else if (path === "username") {
|
|
5629
|
+
value = { userName: operation.value };
|
|
5630
|
+
} else if (path === "emails") {
|
|
5631
|
+
value = { emails: operation.value };
|
|
5632
|
+
} else if (path === "name.formatted") {
|
|
5633
|
+
value = { name: { formatted: operation.value } };
|
|
5634
|
+
} else if (path === "displayname" || (path === "name" && typeof operation.value === "string")) {
|
|
5635
|
+
value = { displayName: operation.value };
|
|
5636
|
+
} else if (path === "name") {
|
|
5637
|
+
value = { name: operation.value };
|
|
5638
|
+
} else if (path === "active") {
|
|
5639
|
+
value = { active: operation.value };
|
|
5640
|
+
} else {
|
|
5641
|
+
return scimError("Unsupported patch path.", 400);
|
|
5563
5642
|
}
|
|
5643
|
+
const invalid = validateScimProfile(value, true);
|
|
5644
|
+
if (invalid) return invalid;
|
|
5645
|
+
email = readUserName(value) || email;
|
|
5646
|
+
name = readName(value, name);
|
|
5564
5647
|
}
|
|
5565
5648
|
await user.update({ name, email });
|
|
5566
5649
|
return scimJson(toScimUser(user));
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"check": "tsc --noEmit"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@getstrata/bootstrap": "^2.2.
|
|
16
|
-
"@getstrata/cli": "^2.2.
|
|
17
|
-
"@getstrata/core": "^2.2.
|
|
15
|
+
"@getstrata/bootstrap": "^2.2.33",
|
|
16
|
+
"@getstrata/cli": "^2.2.33",
|
|
17
|
+
"@getstrata/core": "^2.2.33",
|
|
18
18
|
"eta": "^4.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|