@getstrata/core 2.2.57 → 2.2.58

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @getstrata/core changelog
2
2
 
3
+ ## 2.2.58
4
+
5
+ PostgreSQL runtime privilege fix: Replace broad table/sequence grants with explicit CRUD and sequence usage/read permissions. Repair legacy helper-managed grants that allowed TRUNCATE across RLS tenant boundaries. Preserve provisioning locks and transactional rollback. Resolves #364 through #370.
6
+ UUID schema columns: Add table.uuid() with PostgreSQL native UUID, MySQL CHAR(36) and SQLite TEXT. Supports explicit constraints and application-supplied identifiers; existing schemas remain unchanged. #365
7
+ Model and view generators: Add make:model for declarative models with automatic repositories, and make:view for escaped Eta templates. Support nested names and explicit model metadata, with path validation and overwrite protection. Migrations remain explicit and separate. #368
8
+ Repeated form values: Add opt-in { preserveRepeated: true } parsing through core form helpers and WebFormRequest, retaining repeated text and files in order. Existing parsing defaults remain unchanged; applications retain responsibility for duplicate validation. #366
9
+ Mail extension documentation and coverage: Qualify existing injected MailDriver integrations, including HTTPS providers, cancellation, deadlines, error propagation and provider-controlled idempotency. This adds tests and guidance without changing stock mail transports. #367
10
+
3
11
  ## 2.2.57
4
12
 
5
13
  Add opt-in CsrfOptions.targetOrigin with strict request Host/URL authority and source-origin validation while retaining signed cookie/token checks and existing defaults. Preserve native Request identity and ignore forwarding claims. Fall back safely to JSON error formatting for malformed native URL metadata.
@@ -33,6 +33,8 @@ declare class Blueprint {
33
33
  /** Generated 64-bit primary key; does not change existing id() migrations. */
34
34
  bigId(name?: string): ColumnDefinition;
35
35
  string(name: string, length?: number): ColumnDefinition;
36
+ /** Application-supplied UUID: native PostgreSQL UUID, MySQL CHAR(36), SQLite TEXT. */
37
+ uuid(name: string): ColumnDefinition;
36
38
  text(name: string): ColumnDefinition;
37
39
  boolean(name: string): ColumnDefinition;
38
40
  integer(name: string): ColumnDefinition;
@@ -1,4 +1,4 @@
1
- type ColumnKind = "id" | "bigId" | "string" | "text" | "boolean" | "integer" | "bigInteger" | "timestamp" | "json" | "jsonb" | "foreignId";
1
+ type ColumnKind = "id" | "bigId" | "uuid" | "string" | "text" | "boolean" | "integer" | "bigInteger" | "timestamp" | "json" | "jsonb" | "foreignId";
2
2
  interface ForeignKeyOptions {
3
3
  referencesTable: string;
4
4
  referencesColumn: string;
@@ -1,6 +1,28 @@
1
- interface FormDataLike {
2
- entries(): Iterable<[string, unknown]>;
1
+ interface FormDataLike<T = unknown> {
2
+ entries(): Iterable<[string, T]>;
3
3
  }
4
- declare function parseFormBody(request: Request): Promise<Record<string, string>>;
5
- declare function formDataToRecord(formData: FormDataLike): Record<string, string>;
4
+ interface FormBodyOptions {
5
+ /** Preserve every entry as an array, including single text fields and File entries. */
6
+ preserveRepeated?: boolean;
7
+ }
8
+ type PreservedFormValues = Record<string, (string | File)[]>;
9
+ declare function parseFormBody(request: Request, options: {
10
+ preserveRepeated: true;
11
+ }): Promise<PreservedFormValues>;
12
+ declare function parseFormBody(request: Request, options?: {
13
+ preserveRepeated?: false;
14
+ }): Promise<Record<string, string>>;
15
+ declare function parseFormBody(request: Request, options: FormBodyOptions): Promise<Record<string, string> | PreservedFormValues>;
16
+ declare function formDataToRecord(formData: FormData, options: {
17
+ preserveRepeated: true;
18
+ }): PreservedFormValues;
19
+ declare function formDataToRecord<T>(formData: FormDataLike<T>, options: {
20
+ preserveRepeated: true;
21
+ }): Record<string, T[]>;
22
+ declare function formDataToRecord(formData: FormDataLike, options?: {
23
+ preserveRepeated?: false;
24
+ }): Record<string, string>;
25
+ declare function formDataToRecord(formData: FormData, options: FormBodyOptions): Record<string, string> | PreservedFormValues;
26
+ declare function formDataToRecord<T>(formData: FormDataLike<T>, options: FormBodyOptions): Record<string, string> | Record<string, T[]>;
27
+ export type { FormBodyOptions, PreservedFormValues };
6
28
  export { formDataToRecord, parseFormBody };
@@ -1,4 +1,7 @@
1
+ import { type FormBodyOptions } from "./parseFormBody";
1
2
  declare abstract class WebFormRequest<TOutput> {
3
+ #private;
4
+ constructor(options?: FormBodyOptions);
2
5
  authorize(_request: Request): boolean | Promise<boolean>;
3
6
  protected abstract parse(payload: unknown): TOutput;
4
7
  validatePayload(payload: unknown): TOutput;
@@ -10,7 +10,7 @@
10
10
  * existing volumes get the role and table GRANTs after migrate:fresh. Production
11
11
  * runtime processes only connect through the already-provisioned restricted role.
12
12
  *
13
- * Admin DDL (GRANT ALL TABLES, CREATE TABLE, DROP TABLE) must run on the
13
+ * Admin DDL (table grants, CREATE TABLE, DROP TABLE) must run on the
14
14
  * application database. postgres/template1 are only for CREATE DATABASE.
15
15
  */
16
16
  declare const POSTGRES_APP_ROLE = "strata_app";
@@ -365,6 +365,12 @@ class Blueprint {
365
365
  this.columns.push(column);
366
366
  return column;
367
367
  }
368
+ uuid(name) {
369
+ const column = new ColumnDefinition(name, "uuid");
370
+ column.notNullable();
371
+ this.columns.push(column);
372
+ return column;
373
+ }
368
374
  text(name) {
369
375
  const column = new ColumnDefinition(name, "text");
370
376
  column.notNullable();
@@ -507,6 +513,10 @@ function compileColumnType(driver, column) {
507
513
  return compileIdType(driver);
508
514
  case "string":
509
515
  return compileStringType(driver, column.length);
516
+ case "uuid":
517
+ if (column.autoIncrement)
518
+ throw new UnsupportedSchemaFeatureError("auto-increment UUID columns", driver);
519
+ return driver === "pgsql" ? "UUID" : driver === "mysql" ? "CHAR(36)" : "TEXT";
510
520
  case "text":
511
521
  return compileTextType(driver);
512
522
  case "boolean":
@@ -357,6 +357,12 @@ class Blueprint {
357
357
  this.columns.push(column);
358
358
  return column;
359
359
  }
360
+ uuid(name) {
361
+ const column = new ColumnDefinition(name, "uuid");
362
+ column.notNullable();
363
+ this.columns.push(column);
364
+ return column;
365
+ }
360
366
  text(name) {
361
367
  const column = new ColumnDefinition(name, "text");
362
368
  column.notNullable();
@@ -499,6 +505,10 @@ function compileColumnType(driver, column) {
499
505
  return compileIdType(driver);
500
506
  case "string":
501
507
  return compileStringType(driver, column.length);
508
+ case "uuid":
509
+ if (column.autoIncrement)
510
+ throw new UnsupportedSchemaFeatureError("auto-increment UUID columns", driver);
511
+ return driver === "pgsql" ? "UUID" : driver === "mysql" ? "CHAR(36)" : "TEXT";
502
512
  case "text":
503
513
  return compileTextType(driver);
504
514
  case "boolean":
@@ -1,14 +1,25 @@
1
1
  // @bun
2
2
  // ../../src/core/http/parseFormBody.ts
3
3
  import { BadRequestError } from "@getstrata/core/errors/http";
4
- async function parseFormBody(request) {
4
+ async function parseFormBody(request, options = {}) {
5
5
  const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
6
6
  if (!contentType.includes("application/x-www-form-urlencoded") && !contentType.includes("multipart/form-data")) {
7
7
  throw new BadRequestError("Expected a form submission.");
8
8
  }
9
- return formDataToRecord(await request.formData());
9
+ return formDataToRecord(await request.formData(), options);
10
10
  }
11
- function formDataToRecord(formData) {
11
+ function formDataToRecord(formData, options = {}) {
12
+ if (options.preserveRepeated === true) {
13
+ const values = new Map;
14
+ for (const [key, value] of formData.entries()) {
15
+ const entries = values.get(key);
16
+ if (entries)
17
+ entries.push(value);
18
+ else
19
+ values.set(key, [value]);
20
+ }
21
+ return Object.fromEntries(values);
22
+ }
12
23
  const values = {};
13
24
  for (const [key, value] of formData.entries()) {
14
25
  if (typeof value === "string") {
@@ -35,14 +35,25 @@ function requestPrefersJson(request) {
35
35
 
36
36
  // ../../src/core/http/parseFormBody.ts
37
37
  import { BadRequestError } from "@getstrata/core/errors/http";
38
- async function parseFormBody(request) {
38
+ async function parseFormBody(request, options = {}) {
39
39
  const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
40
40
  if (!contentType.includes("application/x-www-form-urlencoded") && !contentType.includes("multipart/form-data")) {
41
41
  throw new BadRequestError("Expected a form submission.");
42
42
  }
43
- return formDataToRecord(await request.formData());
44
- }
45
- function formDataToRecord(formData) {
43
+ return formDataToRecord(await request.formData(), options);
44
+ }
45
+ function formDataToRecord(formData, options = {}) {
46
+ if (options.preserveRepeated === true) {
47
+ const values = new Map;
48
+ for (const [key, value] of formData.entries()) {
49
+ const entries = values.get(key);
50
+ if (entries)
51
+ entries.push(value);
52
+ else
53
+ values.set(key, [value]);
54
+ }
55
+ return Object.fromEntries(values);
56
+ }
46
57
  const values = {};
47
58
  for (const [key, value] of formData.entries()) {
48
59
  if (typeof value === "string") {
@@ -183,6 +194,10 @@ function parsePositiveIntParam(value, name = "id") {
183
194
 
184
195
  // ../../src/core/http/webFormRequest.ts
185
196
  class WebFormRequest {
197
+ #preserveRepeated;
198
+ constructor(options = {}) {
199
+ this.#preserveRepeated = options.preserveRepeated === true;
200
+ }
186
201
  authorize(_request) {
187
202
  return true;
188
203
  }
@@ -193,7 +208,7 @@ class WebFormRequest {
193
208
  if (!await this.authorize(request)) {
194
209
  throw new ForbiddenError;
195
210
  }
196
- const payload = requestPrefersJson(request) ? await parseJsonBody(request, (body) => body) : await parseFormBody(request);
211
+ const payload = requestPrefersJson(request) ? await parseJsonBody(request, (body) => body) : await parseFormBody(request, { preserveRepeated: this.#preserveRepeated });
197
212
  try {
198
213
  return this.validatePayload(payload);
199
214
  } catch (error) {
@@ -197,11 +197,15 @@ function postgresAppRolePrivilegeSql(options) {
197
197
  const role = assertSafeSqlIdentifier(options.role ?? POSTGRES_APP_ROLE, "role name");
198
198
  return `GRANT CONNECT ON DATABASE ${database} TO ${role};
199
199
  GRANT USAGE ON SCHEMA public TO ${role};
200
- GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO ${role};
201
- GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO ${role};
200
+ REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM ${role};
201
+ GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO ${role};
202
+ REVOKE ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public FROM ${role};
203
+ GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ${role};
202
204
  GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO ${role};
203
- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO ${role};
204
- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO ${role};
205
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON TABLES FROM ${role};
206
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO ${role};
207
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public REVOKE ALL ON SEQUENCES FROM ${role};
208
+ ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE, SELECT ON SEQUENCES TO ${role};
205
209
  ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT EXECUTE ON FUNCTIONS TO ${role};
206
210
  `;
207
211
  }
package/dist/index.js CHANGED
@@ -6990,6 +6990,12 @@ class Blueprint {
6990
6990
  this.columns.push(column);
6991
6991
  return column;
6992
6992
  }
6993
+ uuid(name) {
6994
+ const column = new ColumnDefinition(name, "uuid");
6995
+ column.notNullable();
6996
+ this.columns.push(column);
6997
+ return column;
6998
+ }
6993
6999
  text(name) {
6994
7000
  const column = new ColumnDefinition(name, "text");
6995
7001
  column.notNullable();
@@ -7132,6 +7138,10 @@ function compileColumnType(driver, column) {
7132
7138
  return compileIdType(driver);
7133
7139
  case "string":
7134
7140
  return compileStringType(driver, column.length);
7141
+ case "uuid":
7142
+ if (column.autoIncrement)
7143
+ throw new UnsupportedSchemaFeatureError("auto-increment UUID columns", driver);
7144
+ return driver === "pgsql" ? "UUID" : driver === "mysql" ? "CHAR(36)" : "TEXT";
7135
7145
  case "text":
7136
7146
  return compileTextType(driver);
7137
7147
  case "boolean":
@@ -14293,14 +14303,25 @@ function createValidateSignatureMiddleware() {
14293
14303
  };
14294
14304
  }
14295
14305
  // ../../src/core/http/parseFormBody.ts
14296
- async function parseFormBody(request) {
14306
+ async function parseFormBody(request, options = {}) {
14297
14307
  const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
14298
14308
  if (!contentType.includes("application/x-www-form-urlencoded") && !contentType.includes("multipart/form-data")) {
14299
14309
  throw new BadRequestError("Expected a form submission.");
14300
14310
  }
14301
- return formDataToRecord(await request.formData());
14311
+ return formDataToRecord(await request.formData(), options);
14302
14312
  }
14303
- function formDataToRecord(formData) {
14313
+ function formDataToRecord(formData, options = {}) {
14314
+ if (options.preserveRepeated === true) {
14315
+ const values = new Map;
14316
+ for (const [key, value] of formData.entries()) {
14317
+ const entries = values.get(key);
14318
+ if (entries)
14319
+ entries.push(value);
14320
+ else
14321
+ values.set(key, [value]);
14322
+ }
14323
+ return Object.fromEntries(values);
14324
+ }
14304
14325
  const values = {};
14305
14326
  for (const [key, value] of formData.entries()) {
14306
14327
  if (typeof value === "string") {
@@ -14312,6 +14333,10 @@ function formDataToRecord(formData) {
14312
14333
 
14313
14334
  // ../../src/core/http/webFormRequest.ts
14314
14335
  class WebFormRequest {
14336
+ #preserveRepeated;
14337
+ constructor(options = {}) {
14338
+ this.#preserveRepeated = options.preserveRepeated === true;
14339
+ }
14315
14340
  authorize(_request) {
14316
14341
  return true;
14317
14342
  }
@@ -14322,7 +14347,7 @@ class WebFormRequest {
14322
14347
  if (!await this.authorize(request)) {
14323
14348
  throw new ForbiddenError;
14324
14349
  }
14325
- const payload = requestPrefersJson(request) ? await parseJsonBody(request, (body) => body) : await parseFormBody(request);
14350
+ const payload = requestPrefersJson(request) ? await parseJsonBody(request, (body) => body) : await parseFormBody(request, { preserveRepeated: this.#preserveRepeated });
14326
14351
  try {
14327
14352
  return this.validatePayload(payload);
14328
14353
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getstrata/core",
3
- "version": "2.2.57",
3
+ "version": "2.2.58",
4
4
  "description": "Strata Bun framework public API",
5
5
  "type": "module",
6
6
  "license": "MIT",