@getstrata/starter 2.2.32 → 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 CHANGED
@@ -3163,9 +3163,9 @@ function renderPackageJson(projectName, options = {}) {
3163
3163
  "@getstrata/cli": "workspace:*",
3164
3164
  "@getstrata/core": "workspace:*"
3165
3165
  } : {
3166
- "@getstrata/bootstrap": "^2.2.32",
3167
- "@getstrata/cli": "^2.2.32",
3168
- "@getstrata/core": "^2.2.32"
3166
+ "@getstrata/bootstrap": "^2.2.33",
3167
+ "@getstrata/cli": "^2.2.33",
3168
+ "@getstrata/core": "^2.2.33"
3169
3169
  };
3170
3170
  coreDeps.eta = "^4.6.0";
3171
3171
  if (options.layers?.database === "mysql") {
@@ -5300,6 +5300,7 @@ import type { AppModule } from "@getstrata/bootstrap/contracts";
5300
5300
  import { routeParams } from "@getstrata/bootstrap/web/routing";
5301
5301
  import { createScimAuthMiddleware } from "@getstrata/core/auth/scimAuthMiddleware";
5302
5302
  import { hashPassword } from "@getstrata/core/auth/password";
5303
+ import { runInTransaction } from "@getstrata/core/database/transaction";
5303
5304
  import { BadRequestError } from "@getstrata/core/errors/http";
5304
5305
  import { parsePositiveIntParam } from "@getstrata/core/http/validation";
5305
5306
  import { withErrorHandling } from "@getstrata/core/http/response";
@@ -5393,6 +5394,59 @@ function readName(body: Record<string, unknown>, fallback: string): string {
5393
5394
  return fallback;
5394
5395
  }
5395
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
+
5396
5450
  function wrapScim(kernel: HttpKernel, handler: (request: Request) => Promise<Response>) {
5397
5451
  const throttle = kernel.ownThrottle(createScimThrottleMiddleware({
5398
5452
  redisUrl: process.env.REDIS_URL,
@@ -5404,7 +5458,9 @@ function wrapScim(kernel: HttpKernel, handler: (request: Request) => Promise<Res
5404
5458
  if (!scimEnabled()) {
5405
5459
  return scimError("SCIM is off.", 404);
5406
5460
  }
5407
- return handler(request);
5461
+ return ["POST", "PUT", "PATCH", "DELETE"].includes(request.method)
5462
+ ? await runInTransaction(() => handler(request))
5463
+ : await handler(request);
5408
5464
  }),
5409
5465
  );
5410
5466
  }
@@ -5475,7 +5531,10 @@ const scimModule: AppModule = {
5475
5531
  POST: kernel.wrap(
5476
5532
  "api",
5477
5533
  wrapScim(kernel, async (request) => {
5478
- const body = (await request.json()) as Record<string, unknown>;
5534
+ const body = await readScimBody(request);
5535
+ if (body instanceof Response) return body;
5536
+ const invalid = validateScimProfile(body);
5537
+ if (invalid) return invalid;
5479
5538
  const email = readUserName(body);
5480
5539
  const name = readName(body, email.split("@")[0] ?? "User");
5481
5540
  if (!email) {
@@ -5516,7 +5575,10 @@ const scimModule: AppModule = {
5516
5575
  if (id instanceof Response) {
5517
5576
  return id;
5518
5577
  }
5519
- const body = (await request.json()) as Record<string, unknown>;
5578
+ const body = await readScimBody(request);
5579
+ if (body instanceof Response) return body;
5580
+ const invalid = validateScimProfile(body);
5581
+ if (invalid) return invalid;
5520
5582
  const email = readUserName(body);
5521
5583
  const name = readName(body, email);
5522
5584
  if (!email || !name) {
@@ -5541,31 +5603,47 @@ const scimModule: AppModule = {
5541
5603
  if (!user) {
5542
5604
  return scimError("User not found.", 404);
5543
5605
  }
5544
- const body = (await request.json()) as { schemas?: string[]; Operations?: Array<{ op?: string; path?: string; value?: unknown }> };
5545
- if (body.schemas && !body.schemas.includes(PATCH_SCHEMA)) {
5606
+ const body = await readScimBody(request);
5607
+ if (body instanceof Response) return body;
5608
+ if (!Array.isArray(body.schemas) || !body.schemas.includes(PATCH_SCHEMA)) {
5546
5609
  return scimError("Unsupported patch schema.", 400);
5547
5610
  }
5611
+ if (!Array.isArray(body.Operations) || body.Operations.length === 0) {
5612
+ return scimError("A non-empty Operations array is required.", 400);
5613
+ }
5548
5614
  let name = String(user.get("name") ?? "");
5549
5615
  let email = String(user.get("email") ?? "");
5550
- for (const operation of body.Operations ?? []) {
5551
- const op = (operation.op ?? "replace").toLowerCase();
5552
- if (op !== "replace" && op !== "add") {
5553
- continue;
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);
5554
5622
  }
5555
- const path = (operation.path ?? "").toLowerCase();
5556
- if (path === "username" || path === "emails") {
5557
- email = String(operation.value ?? email).trim().toLowerCase();
5558
- } else if (path === "name.formatted" || path === "displayname" || path === "name") {
5559
- if (typeof operation.value === "string") {
5560
- name = operation.value.trim() || name;
5561
- } else if (operation.value && typeof operation.value === "object") {
5562
- name = readName({ name: operation.value as Record<string, unknown> }, name);
5563
- }
5564
- } else if (!path && operation.value && typeof operation.value === "object") {
5565
- const value = operation.value as Record<string, unknown>;
5566
- email = readUserName(value) || email;
5567
- name = readName(value, name);
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);
5568
5642
  }
5643
+ const invalid = validateScimProfile(value, true);
5644
+ if (invalid) return invalid;
5645
+ email = readUserName(value) || email;
5646
+ name = readName(value, name);
5569
5647
  }
5570
5648
  await user.update({ name, email });
5571
5649
  return scimJson(toScimUser(user));
@@ -12,9 +12,9 @@
12
12
  "check": "tsc --noEmit"
13
13
  },
14
14
  "dependencies": {
15
- "@getstrata/bootstrap": "^2.2.32",
16
- "@getstrata/cli": "^2.2.32",
17
- "@getstrata/core": "^2.2.32",
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": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/starter",
3
- "version": "2.2.32",
3
+ "version": "2.2.33",
4
4
  "description": "Interactive create-strata wizard. Choose each layer; one database engine.",
5
5
  "type": "module",
6
6
  "license": "MIT",