@getstrata/core 2.2.41 → 2.2.43

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,17 @@
1
1
  # @getstrata/core changelog
2
2
 
3
+ ## 2.2.43
4
+
5
+ Add `afterCommit` for process-local effects after the outermost managed transaction, sharing savepoint rollback and tenant replay with model events. Generated auth SMTP uses this boundary even inside RLS request transactions; callback failures propagate after commit without undoing persisted accounts. Durable delivery still requires the SQL outbox.
6
+
7
+ Fix MySQL verification/reset and session-revocation timestamps through the shared SQL dialect; make signup account and verification-token persistence atomic with SMTP after commit; initialize no-tenancy seed connections; add installed starter auth/SMTP/MFA/rollback journeys for every database and frontend, plus generated TypeScript profiles.
8
+
9
+ ## 2.2.42
10
+
11
+ Generate auth JSON and forms with explicit private, no-store cache policy. Add privateJsonResponse and typed view namespace header defaults while preserving normal public defaults, native cookies, per-response overrides and HTMX representation behavior. Cover packed APIs and actual generated cookie/token/JWT/CSRF/profile/form HTTP responses.
12
+
13
+ Use the canonical error serializer for core JSON admission denials so authentication, policy/admin/ability, verification, password confirmation and body-limit failures retain no-store. Preserve exact status/message contracts, keep checker details private and retain HTML redirects/throws and successful response headers. Add packed producer regressions and a native detail-projection case.
14
+
3
15
  ## 2.2.41
4
16
 
5
17
  Make framework HTML/JSON error responses non-storeable, including configured/fallback renderers and custom-body 404 responses; retain success-response cache policy and add packed header regressions.
@@ -1,3 +1,4 @@
1
+ import { afterCommit } from "../events/deferredModelEvents.ts";
1
2
  import { type TransactionAcquisitionMetrics } from "./acquisitionMetrics.ts";
2
3
  import type { DatabaseConnection } from "./baseRepository.ts";
3
4
  import { hasActiveTransaction, requestTransactionRollback } from "./transactionControl.ts";
@@ -15,4 +16,8 @@ declare function runInTransaction<TValue>(operation: (connection: DatabaseConnec
15
16
  export type { TransactionAcquisitionMetrics, TransactionAcquisitionSnapshot, } from "./acquisitionMetrics.ts";
16
17
  export { createTransactionAcquisitionMetrics, renderTransactionAcquisitionMetrics, } from "./acquisitionMetrics.ts";
17
18
  export type { TransactionOptions };
18
- export { hasActiveTransaction, isActiveTransactionConnection, requestTransactionRollback, runInTransaction, };
19
+ /** Register process-local work for the successful outermost commit. Awaiting
20
+ * registration does not execute it early inside an active transaction. Outside
21
+ * a managed transaction it runs immediately. Failure propagates after commit;
22
+ * committed writes cannot roll back. Use the SQL outbox for durable delivery. */
23
+ export { afterCommit, hasActiveTransaction, isActiveTransactionConnection, requestTransactionRollback, runInTransaction, };
@@ -1,4 +1,7 @@
1
1
  declare function dispatchModelEvent(event: string, payload: unknown): Promise<void>;
2
+ /** Internal queue shared with model events so savepoint rollback and tenant replay
3
+ * follow exactly the same transaction boundary. This is not durable delivery. */
4
+ declare function afterCommit(callback: () => void | Promise<void>): Promise<void>;
2
5
  declare function runWithDeferredModelEvents<T>(callback: () => T | Promise<T>): Promise<T>;
3
6
  declare function onDeferredModelRollback(callback: () => void): void;
4
- export { dispatchModelEvent, onDeferredModelRollback, runWithDeferredModelEvents };
7
+ export { afterCommit, dispatchModelEvent, onDeferredModelRollback, runWithDeferredModelEvents };
@@ -1,5 +1,7 @@
1
1
  import type { Middleware } from "./middleware";
2
2
  declare function jsonResponse(data: unknown, init?: ResponseInit): Response;
3
+ /** Explicit private payloads (identity, credentials and CSRF); public JSON defaults stay unchanged. */
4
+ declare function privateJsonResponse(data: unknown, init?: ResponseInit): Response;
3
5
  declare function createdResponse(data: unknown, init?: ResponseInit): Response;
4
6
  declare function noContentResponse(): Response;
5
7
  declare function errorResponse(error: unknown): Response;
@@ -9,4 +11,4 @@ declare function withJsonErrorHandling<THandler extends (request: Request) => Re
9
11
  declare function withJsonErrorHandling<TArgs extends unknown[]>(handler: (...args: TArgs) => Response | Promise<Response>): (...args: TArgs) => Promise<Response>;
10
12
  declare function createJsonErrorMiddleware(): Middleware;
11
13
  declare function createWebErrorMiddleware(): Middleware;
12
- export { createdResponse, createJsonErrorMiddleware, createWebErrorMiddleware, errorResponse, jsonResponse, noContentResponse, withErrorHandling, withJsonErrorHandling, };
14
+ export { createdResponse, createJsonErrorMiddleware, createWebErrorMiddleware, errorResponse, jsonResponse, noContentResponse, privateJsonResponse, withErrorHandling, withJsonErrorHandling, };
@@ -2,7 +2,7 @@ export type { LayoutDataResolver, RenderOptions } from "./etaViewEngine";
2
2
  export { DEFAULT_VIEWS_DIRECTORY, EtaViewEngine } from "./etaViewEngine";
3
3
  export { htmlResponse, isHtmxRequest, redirectResponse, rssResponse, textResponse, xmlResponse, } from "./htmlResponse";
4
4
  export type { ViewEngine } from "./viewEngine";
5
- export type { HtmxViewResponseOptions, NamespacedViewRenderer, ViewResponseOptions, } from "./viewRenderer";
5
+ export type { HtmxViewResponseOptions, NamespacedViewRenderer, ViewNamespaceOptions, ViewResponseOptions, } from "./viewRenderer";
6
6
  export { CORE_VIEW_RENDERER_TOKEN, ViewRenderer } from "./viewRenderer";
7
7
  export type { WebErrorViewInput, WebErrorViewOptions } from "./webErrorView";
8
8
  export { configureWebErrorView, errorTemplateName, htmlErrorResponse, notFoundHtmlResponse, renderKernelErrorChrome, renderWebErrorHtml, } from "./webErrorView";
@@ -10,6 +10,10 @@ interface HtmxViewResponseOptions extends ViewResponseOptions {
10
10
  /** Optional fragment template; otherwise render the page template without its layout. */
11
11
  fragment?: string;
12
12
  }
13
+ interface ViewNamespaceOptions {
14
+ /** Copied response defaults. Per-render headers override defaults with the same name. */
15
+ headers?: ConstructorParameters<typeof Headers>[0];
16
+ }
13
17
  interface NamespacedViewRenderer {
14
18
  render: ViewRenderer["render"];
15
19
  renderHtmx: ViewRenderer["renderHtmx"];
@@ -20,11 +24,11 @@ declare class ViewRenderer {
20
24
  private readonly defaultLayout?;
21
25
  constructor(engine: ViewEngine, defaultLayout?: string | false | undefined);
22
26
  /** Explicit template prefix; layout names and response contracts remain unchanged. */
23
- namespace(prefix: string): NamespacedViewRenderer;
27
+ namespace(prefix: string, defaults?: ViewNamespaceOptions): NamespacedViewRenderer;
24
28
  render(name: string, data?: Record<string, unknown>, options?: ViewResponseOptions): Promise<Response>;
25
29
  /** Opt-in representation selection; auth/CSRF/tenancy remain the route's responsibility. */
26
30
  renderHtmx(name: string, data?: Record<string, unknown>, options?: HtmxViewResponseOptions): Promise<Response>;
27
31
  }
28
32
  declare const CORE_VIEW_RENDERER_TOKEN: import("../contracts/container").ServiceToken<ViewRenderer>;
29
- export type { HtmxViewResponseOptions, NamespacedViewRenderer, ViewResponseOptions };
33
+ export type { HtmxViewResponseOptions, NamespacedViewRenderer, ViewNamespaceOptions, ViewResponseOptions, };
30
34
  export { CORE_VIEW_RENDERER_TOKEN, ViewRenderer };
@@ -279,7 +279,7 @@ function groupQueuedModelEvents(queued) {
279
279
  for (const item of queued) {
280
280
  const lastGroup = groups[groups.length - 1];
281
281
  const last = lastGroup?.[lastGroup.length - 1];
282
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
282
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
283
283
  groups.push([item]);
284
284
  } else {
285
285
  lastGroup.push(item);
@@ -289,7 +289,10 @@ function groupQueuedModelEvents(queued) {
289
289
  }
290
290
  async function dispatchEventBatch(batch) {
291
291
  for (const item of batch) {
292
- await eventBus.dispatch(item.event, item.payload);
292
+ if ("callback" in item)
293
+ await item.callback();
294
+ else
295
+ await eventBus.dispatch(item.event, item.payload);
293
296
  }
294
297
  }
295
298
  async function dispatchQueuedModelEvents(queued) {
@@ -300,7 +303,11 @@ async function dispatchQueuedModelEvents(queued) {
300
303
  for (const batch of groupQueuedModelEvents(queued)) {
301
304
  const tenant = batch[0]?.tenant ?? null;
302
305
  if (tenant) {
303
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
306
+ if (batch.some((item) => ("callback" in item))) {
307
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
308
+ } else {
309
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
310
+ }
304
311
  } else {
305
312
  await dispatchEventBatch(batch);
306
313
  }
@@ -336,7 +336,7 @@ function groupQueuedModelEvents(queued) {
336
336
  for (const item of queued) {
337
337
  const lastGroup = groups[groups.length - 1];
338
338
  const last = lastGroup?.[lastGroup.length - 1];
339
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
339
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
340
340
  groups.push([item]);
341
341
  } else {
342
342
  lastGroup.push(item);
@@ -346,7 +346,10 @@ function groupQueuedModelEvents(queued) {
346
346
  }
347
347
  async function dispatchEventBatch(batch) {
348
348
  for (const item of batch) {
349
- await eventBus.dispatch(item.event, item.payload);
349
+ if ("callback" in item)
350
+ await item.callback();
351
+ else
352
+ await eventBus.dispatch(item.event, item.payload);
350
353
  }
351
354
  }
352
355
  async function dispatchQueuedModelEvents(queued) {
@@ -357,7 +360,11 @@ async function dispatchQueuedModelEvents(queued) {
357
360
  for (const batch of groupQueuedModelEvents(queued)) {
358
361
  const tenant = batch[0]?.tenant ?? null;
359
362
  if (tenant) {
360
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
363
+ if (batch.some((item) => ("callback" in item))) {
364
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
365
+ } else {
366
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
367
+ }
361
368
  } else {
362
369
  await dispatchEventBatch(batch);
363
370
  }
@@ -555,7 +555,7 @@ function groupQueuedModelEvents(queued) {
555
555
  for (const item of queued) {
556
556
  const lastGroup = groups[groups.length - 1];
557
557
  const last = lastGroup?.[lastGroup.length - 1];
558
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
558
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
559
559
  groups.push([item]);
560
560
  } else {
561
561
  lastGroup.push(item);
@@ -565,7 +565,10 @@ function groupQueuedModelEvents(queued) {
565
565
  }
566
566
  async function dispatchEventBatch(batch) {
567
567
  for (const item of batch) {
568
- await eventBus.dispatch(item.event, item.payload);
568
+ if ("callback" in item)
569
+ await item.callback();
570
+ else
571
+ await eventBus.dispatch(item.event, item.payload);
569
572
  }
570
573
  }
571
574
  async function dispatchQueuedModelEvents(queued) {
@@ -576,7 +579,11 @@ async function dispatchQueuedModelEvents(queued) {
576
579
  for (const batch of groupQueuedModelEvents(queued)) {
577
580
  const tenant = batch[0]?.tenant ?? null;
578
581
  if (tenant) {
579
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
582
+ if (batch.some((item) => ("callback" in item))) {
583
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
584
+ } else {
585
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
586
+ }
580
587
  } else {
581
588
  await dispatchEventBatch(batch);
582
589
  }
@@ -352,7 +352,7 @@ async function consumeOneTimeToken(sql, purpose, plain, now = new Date) {
352
352
  return null;
353
353
  }
354
354
  const dialect = currentSqlDialect();
355
- const consumedAt = now.toISOString();
355
+ const consumedAt = dialect.timestampValue(now);
356
356
  const hash = hashOneTimeToken(token);
357
357
  const returning = dialect.returningClause("user_id");
358
358
  const updated = await sql.unsafe(`UPDATE auth_one_time_tokens
@@ -377,7 +377,7 @@ async function consumeOneTimeToken(sql, purpose, plain, now = new Date) {
377
377
  async function revokeUserSessions(sql, userId, options = {}) {
378
378
  const dialect = currentSqlDialect();
379
379
  const versionUpdate = options.incrementAuthVersion ? ", auth_version = auth_version + 1" : "";
380
- await sql.unsafe(`UPDATE users SET session_valid_after = ${dialect.placeholder(1)}${versionUpdate} WHERE id = ${dialect.placeholder(2)}`, [new Date().toISOString(), userId]);
380
+ await sql.unsafe(`UPDATE users SET session_valid_after = ${dialect.placeholder(1)}${versionUpdate} WHERE id = ${dialect.placeholder(2)}`, [dialect.timestampValue(new Date), userId]);
381
381
  await deleteOptionalCredentials(sql, "sessions", userId);
382
382
  if (options.revokeApiTokens !== false) {
383
383
  await deleteOptionalCredentials(sql, "api_tokens", userId);
@@ -555,7 +555,7 @@ function groupQueuedModelEvents(queued) {
555
555
  for (const item of queued) {
556
556
  const lastGroup = groups[groups.length - 1];
557
557
  const last = lastGroup?.[lastGroup.length - 1];
558
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
558
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
559
559
  groups.push([item]);
560
560
  } else {
561
561
  lastGroup.push(item);
@@ -565,7 +565,10 @@ function groupQueuedModelEvents(queued) {
565
565
  }
566
566
  async function dispatchEventBatch(batch) {
567
567
  for (const item of batch) {
568
- await eventBus.dispatch(item.event, item.payload);
568
+ if ("callback" in item)
569
+ await item.callback();
570
+ else
571
+ await eventBus.dispatch(item.event, item.payload);
569
572
  }
570
573
  }
571
574
  async function dispatchQueuedModelEvents(queued) {
@@ -576,7 +579,11 @@ async function dispatchQueuedModelEvents(queued) {
576
579
  for (const batch of groupQueuedModelEvents(queued)) {
577
580
  const tenant = batch[0]?.tenant ?? null;
578
581
  if (tenant) {
579
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
582
+ if (batch.some((item) => ("callback" in item))) {
583
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
584
+ } else {
585
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
586
+ }
580
587
  } else {
581
588
  await dispatchEventBatch(batch);
582
589
  }
@@ -823,7 +823,7 @@ function groupQueuedModelEvents(queued) {
823
823
  for (const item of queued) {
824
824
  const lastGroup = groups[groups.length - 1];
825
825
  const last = lastGroup?.[lastGroup.length - 1];
826
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
826
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
827
827
  groups.push([item]);
828
828
  } else {
829
829
  lastGroup.push(item);
@@ -833,7 +833,10 @@ function groupQueuedModelEvents(queued) {
833
833
  }
834
834
  async function dispatchEventBatch(batch) {
835
835
  for (const item of batch) {
836
- await eventBus.dispatch(item.event, item.payload);
836
+ if ("callback" in item)
837
+ await item.callback();
838
+ else
839
+ await eventBus.dispatch(item.event, item.payload);
837
840
  }
838
841
  }
839
842
  async function dispatchQueuedModelEvents(queued) {
@@ -844,7 +847,11 @@ async function dispatchQueuedModelEvents(queued) {
844
847
  for (const batch of groupQueuedModelEvents(queued)) {
845
848
  const tenant = batch[0]?.tenant ?? null;
846
849
  if (tenant) {
847
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
850
+ if (batch.some((item) => ("callback" in item))) {
851
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
852
+ } else {
853
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
854
+ }
848
855
  } else {
849
856
  await dispatchEventBatch(batch);
850
857
  }
@@ -2,12 +2,13 @@
2
2
  // ../../src/core/http/authorizeMiddleware.ts
3
3
  import { currentAuthUser } from "@getstrata/core/auth/authContext";
4
4
  import { ForbiddenError } from "@getstrata/core/errors/http";
5
+ import { errorResponse } from "@getstrata/core/http/response";
5
6
  function createAuthorizeMiddleware(gate, auth, resource, action) {
6
7
  return async (request, next) => {
7
8
  const user = currentAuthUser() ?? await auth.resolve(request);
8
9
  if (!gate.allows(resource, action, user)) {
9
10
  const error = new ForbiddenError;
10
- return Response.json({ error: error.message }, { status: error.status });
11
+ return errorResponse(error);
11
12
  }
12
13
  return await next();
13
14
  };
@@ -1,6 +1,7 @@
1
1
  // @bun
2
2
  // ../../src/core/http/bodySizeLimitMiddleware.ts
3
3
  import { PayloadTooLargeError } from "@getstrata/core/errors/http";
4
+ import { errorResponse } from "@getstrata/core/http/response";
4
5
  var guards = new WeakMap;
5
6
  function guardBody(request, maxBytes) {
6
7
  const existing = guards.get(request);
@@ -76,7 +77,7 @@ function createBodySizeLimitMiddleware(maxBytes = resolveMaxBodyBytes()) {
76
77
  return async (request, next) => {
77
78
  const tooLarge = () => {
78
79
  const error = new PayloadTooLargeError(`Request body exceeds the ${maxBytes} byte limit.`);
79
- return Response.json({ error: error.message }, { status: error.status });
80
+ return errorResponse(error);
80
81
  };
81
82
  const length = Number(request.headers.get("content-length"));
82
83
  if (Number.isFinite(length) && length > maxBytes)
@@ -1,7 +1,8 @@
1
1
  // @bun
2
2
  // ../../src/core/http/requireAbilityMiddleware.ts
3
3
  import { currentAuthUser } from "@getstrata/core/auth/authContext";
4
- import { ForbiddenError } from "@getstrata/core/errors/http";
4
+ import { ForbiddenError, HttpError } from "@getstrata/core/errors/http";
5
+ import { errorResponse } from "@getstrata/core/http/response";
5
6
 
6
7
  // ../../src/core/runtime/frontendMode.ts
7
8
  var FRONTEND_MODES = ["api", "server-htmx", "spa-react", "hybrid"];
@@ -80,7 +81,7 @@ function createRequireAbilityMiddleware(abilityChecker) {
80
81
  if (isViewsEnabled() && !requestPrefersJson(request)) {
81
82
  throw error;
82
83
  }
83
- return Response.json({ error: error.message }, { status: error.status });
84
+ return errorResponse(new HttpError(error.status, error.message));
84
85
  }
85
86
  throw error;
86
87
  }
@@ -1,11 +1,12 @@
1
1
  // @bun
2
2
  // ../../src/core/http/requireAuthMiddleware.ts
3
3
  import { UnauthorizedError } from "@getstrata/core/errors/http";
4
+ import { errorResponse } from "@getstrata/core/http/response";
4
5
  function createRequireAuthMiddleware(auth) {
5
6
  return async (request, next) => {
6
7
  if (!await auth.check(request)) {
7
8
  const error = new UnauthorizedError;
8
- return Response.json({ error: error.message }, { status: error.status });
9
+ return errorResponse(error);
9
10
  }
10
11
  return await next();
11
12
  };
@@ -3,6 +3,7 @@
3
3
  import { isGlobalAdmin } from "@getstrata/core/auth/accessControl";
4
4
  import { currentAuthUser } from "@getstrata/core/auth/authContext";
5
5
  import { ForbiddenError } from "@getstrata/core/errors/http";
6
+ import { errorResponse } from "@getstrata/core/http/response";
6
7
  import { logSecurityEvent } from "@getstrata/core/security/securityEvents";
7
8
  function createRequireGlobalAdminMiddleware() {
8
9
  return async (_request, next) => {
@@ -13,7 +14,7 @@ function createRequireGlobalAdminMiddleware() {
13
14
  path: new URL(_request.url).pathname
14
15
  });
15
16
  const error = new ForbiddenError("Platform admin access required.");
16
- return Response.json({ error: error.message }, { status: error.status });
17
+ return errorResponse(error);
17
18
  }
18
19
  return await next();
19
20
  };
@@ -3,6 +3,8 @@
3
3
  import { resolveUserId } from "@getstrata/core/auth/accessControl";
4
4
  import { currentAuthUser } from "@getstrata/core/auth/authContext";
5
5
  import { hasFreshPasswordConfirmation } from "@getstrata/core/auth/passwordConfirmCookie";
6
+ import { HttpError, UnauthorizedError } from "@getstrata/core/errors/http";
7
+ import { errorResponse } from "@getstrata/core/http/response";
6
8
 
7
9
  // ../../src/core/http/contentNegotiation.ts
8
10
  function requestPrefersJson(request) {
@@ -101,7 +103,7 @@ function createRequirePasswordConfirmMiddleware() {
101
103
  const user = currentAuthUser();
102
104
  if (!user) {
103
105
  if (requestPrefersJson(request)) {
104
- return Response.json({ error: "Authentication required." }, { status: 401 });
106
+ return errorResponse(new UnauthorizedError("Authentication required."));
105
107
  }
106
108
  return Response.redirect("/login", 302);
107
109
  }
@@ -110,7 +112,7 @@ function createRequirePasswordConfirmMiddleware() {
110
112
  return await next();
111
113
  }
112
114
  if (requestPrefersJson(request)) {
113
- return Response.json({ error: PASSWORD_CONFIRM_MESSAGE }, { status: 423 });
115
+ return errorResponse(new HttpError(423, PASSWORD_CONFIRM_MESSAGE));
114
116
  }
115
117
  const url = new URL(request.url);
116
118
  const intended = request.method === "GET" ? `${url.pathname}${url.search}` : "/account";
@@ -6,6 +6,8 @@ import {
6
6
  isEmailVerificationRequired
7
7
  } from "@getstrata/core/auth/emailVerification";
8
8
  import { createIntendedUrlCookieFromRequest } from "@getstrata/core/auth/intendedUrlCookie";
9
+ import { ForbiddenError } from "@getstrata/core/errors/http";
10
+ import { errorResponse } from "@getstrata/core/http/response";
9
11
 
10
12
  // ../../src/core/http/contentNegotiation.ts
11
13
  function requestPrefersJson(request) {
@@ -46,7 +48,7 @@ function createRequireVerifiedMiddleware(auth) {
46
48
  return await next();
47
49
  }
48
50
  if (requestPrefersJson(request)) {
49
- return Response.json({ error: UNVERIFIED_MESSAGE }, { status: 403 });
51
+ return errorResponse(new ForbiddenError(UNVERIFIED_MESSAGE));
50
52
  }
51
53
  const headers = new Headers({ Location: VERIFY_NOTICE_PATH });
52
54
  const intended = createIntendedUrlCookieFromRequest(request);
@@ -266,6 +266,11 @@ function jsonResponse(data, init = {}) {
266
266
  headers: init.headers
267
267
  });
268
268
  }
269
+ function privateJsonResponse(data, init = {}) {
270
+ const response = jsonResponse(data, init);
271
+ response.headers.set("Cache-Control", "private, no-store");
272
+ return response;
273
+ }
269
274
  function createdResponse(data, init = {}) {
270
275
  return jsonResponse(data, { ...init, status: init.status ?? 201 });
271
276
  }
@@ -325,6 +330,7 @@ export {
325
330
  errorResponse,
326
331
  jsonResponse,
327
332
  noContentResponse,
333
+ privateJsonResponse,
328
334
  withErrorHandling,
329
335
  withJsonErrorHandling
330
336
  };
@@ -279,7 +279,7 @@ function groupQueuedModelEvents(queued) {
279
279
  for (const item of queued) {
280
280
  const lastGroup = groups[groups.length - 1];
281
281
  const last = lastGroup?.[lastGroup.length - 1];
282
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
282
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
283
283
  groups.push([item]);
284
284
  } else {
285
285
  lastGroup.push(item);
@@ -289,7 +289,10 @@ function groupQueuedModelEvents(queued) {
289
289
  }
290
290
  async function dispatchEventBatch(batch) {
291
291
  for (const item of batch) {
292
- await eventBus.dispatch(item.event, item.payload);
292
+ if ("callback" in item)
293
+ await item.callback();
294
+ else
295
+ await eventBus.dispatch(item.event, item.payload);
293
296
  }
294
297
  }
295
298
  async function dispatchQueuedModelEvents(queued) {
@@ -300,7 +303,11 @@ async function dispatchQueuedModelEvents(queued) {
300
303
  for (const batch of groupQueuedModelEvents(queued)) {
301
304
  const tenant = batch[0]?.tenant ?? null;
302
305
  if (tenant) {
303
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
306
+ if (batch.some((item) => ("callback" in item))) {
307
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
308
+ } else {
309
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
310
+ }
304
311
  } else {
305
312
  await dispatchEventBatch(batch);
306
313
  }
@@ -664,7 +664,7 @@ function groupQueuedModelEvents(queued) {
664
664
  for (const item of queued) {
665
665
  const lastGroup = groups[groups.length - 1];
666
666
  const last = lastGroup?.[lastGroup.length - 1];
667
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
667
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
668
668
  groups.push([item]);
669
669
  } else {
670
670
  lastGroup.push(item);
@@ -674,7 +674,10 @@ function groupQueuedModelEvents(queued) {
674
674
  }
675
675
  async function dispatchEventBatch(batch) {
676
676
  for (const item of batch) {
677
- await eventBus.dispatch(item.event, item.payload);
677
+ if ("callback" in item)
678
+ await item.callback();
679
+ else
680
+ await eventBus.dispatch(item.event, item.payload);
678
681
  }
679
682
  }
680
683
  async function dispatchQueuedModelEvents(queued) {
@@ -685,7 +688,11 @@ async function dispatchQueuedModelEvents(queued) {
685
688
  for (const batch of groupQueuedModelEvents(queued)) {
686
689
  const tenant = batch[0]?.tenant ?? null;
687
690
  if (tenant) {
688
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
691
+ if (batch.some((item) => ("callback" in item))) {
692
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
693
+ } else {
694
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
695
+ }
689
696
  } else {
690
697
  await dispatchEventBatch(batch);
691
698
  }
@@ -279,7 +279,7 @@ function groupQueuedModelEvents(queued) {
279
279
  for (const item of queued) {
280
280
  const lastGroup = groups[groups.length - 1];
281
281
  const last = lastGroup?.[lastGroup.length - 1];
282
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
282
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
283
283
  groups.push([item]);
284
284
  } else {
285
285
  lastGroup.push(item);
@@ -289,7 +289,10 @@ function groupQueuedModelEvents(queued) {
289
289
  }
290
290
  async function dispatchEventBatch(batch) {
291
291
  for (const item of batch) {
292
- await eventBus.dispatch(item.event, item.payload);
292
+ if ("callback" in item)
293
+ await item.callback();
294
+ else
295
+ await eventBus.dispatch(item.event, item.payload);
293
296
  }
294
297
  }
295
298
  async function dispatchQueuedModelEvents(queued) {
@@ -300,7 +303,11 @@ async function dispatchQueuedModelEvents(queued) {
300
303
  for (const batch of groupQueuedModelEvents(queued)) {
301
304
  const tenant = batch[0]?.tenant ?? null;
302
305
  if (tenant) {
303
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
306
+ if (batch.some((item) => ("callback" in item))) {
307
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
308
+ } else {
309
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
310
+ }
304
311
  } else {
305
312
  await dispatchEventBatch(batch);
306
313
  }
@@ -212,7 +212,7 @@ function groupQueuedModelEvents(queued) {
212
212
  for (const item of queued) {
213
213
  const lastGroup = groups[groups.length - 1];
214
214
  const last = lastGroup?.[lastGroup.length - 1];
215
- if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
215
+ if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
216
216
  groups.push([item]);
217
217
  } else {
218
218
  lastGroup.push(item);
@@ -222,7 +222,10 @@ function groupQueuedModelEvents(queued) {
222
222
  }
223
223
  async function dispatchEventBatch(batch) {
224
224
  for (const item of batch) {
225
- await eventBus.dispatch(item.event, item.payload);
225
+ if ("callback" in item)
226
+ await item.callback();
227
+ else
228
+ await eventBus.dispatch(item.event, item.payload);
226
229
  }
227
230
  }
228
231
  async function dispatchQueuedModelEvents(queued) {
@@ -233,7 +236,11 @@ async function dispatchQueuedModelEvents(queued) {
233
236
  for (const batch of groupQueuedModelEvents(queued)) {
234
237
  const tenant = batch[0]?.tenant ?? null;
235
238
  if (tenant) {
236
- await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
239
+ if (batch.some((item) => ("callback" in item))) {
240
+ await runWithTenant(tenant, () => dispatchEventBatch(batch));
241
+ } else {
242
+ await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
243
+ }
237
244
  } else {
238
245
  await dispatchEventBatch(batch);
239
246
  }
@@ -69,7 +69,7 @@ export type { Seeder, SeederDatabase } from "../core/database/seeders/types.ts";
69
69
  export { createSqliteConnection } from "../core/database/sqliteConnection.ts";
70
70
  export { defineTable } from "../core/database/table.ts";
71
71
  export type { TransactionOptions } from "../core/database/transaction.ts";
72
- export { hasActiveTransaction, isActiveTransactionConnection, requestTransactionRollback, runInTransaction, } from "../core/database/transaction.ts";
72
+ export { afterCommit, hasActiveTransaction, isActiveTransactionConnection, requestTransactionRollback, runInTransaction, } from "../core/database/transaction.ts";
73
73
  export type { ModelWhere, ModelWriteValues, QueryJoin, QueryJoinOn, QueryOptions, QueryOrder, QuerySelectItem, QueryWhere, } from "../core/database/types.ts";
74
74
  export type { WhereNode } from "../core/database/whereBuilder.ts";
75
75
  export { WhereBuilder } from "../core/database/whereBuilder.ts";
@@ -106,7 +106,7 @@ export { createRequireAbilityMiddleware } from "../core/http/requireAbilityMiddl
106
106
  export { createRequireGlobalAdminMiddleware } from "../core/http/requireGlobalAdminMiddleware.ts";
107
107
  export { createRequireWebAuthMiddleware } from "../core/http/requireWebAuthMiddleware.ts";
108
108
  export { JsonResource, ResourceCollection, serializeDate, toPaginatedResourceCollection, toResourceCollection, whenLoaded, } from "../core/http/resources.ts";
109
- export { createdResponse, errorResponse, jsonResponse, noContentResponse, withErrorHandling, } from "../core/http/response.ts";
109
+ export { createdResponse, errorResponse, jsonResponse, noContentResponse, privateJsonResponse, withErrorHandling, } from "../core/http/response.ts";
110
110
  export type { ResourceActions, ResourceMemberHandler, ResourceRouteMap, RouteRequest, } from "../core/http/route.ts";
111
111
  export { getRouteParams, mergeRouteMaps, resourceRoutes } from "../core/http/route.ts";
112
112
  export { loginRedirectLocation, safeInternalRedirectPath, sanitizeInternalPath, } from "../core/http/safeInternalPath.ts";
@@ -171,5 +171,5 @@ export type { ValidationRule, ValidationSchema } from "../core/validation/rules.
171
171
  export { emailRule, maxLength, minLength, required, stringRule, validateObject, } from "../core/validation/rules.ts";
172
172
  export { CORE_VIEW_RENDERER_TOKEN, configureWebErrorView, configureWebLayoutData, createWebLayoutDataResolver, DEFAULT_VIEWS_DIRECTORY, EtaViewEngine, errorTemplateName, htmlErrorResponse, htmlResponse, isHtmxRequest, notFoundHtmlResponse, redirectResponse, renderKernelErrorChrome, renderWebErrorHtml, resolveWebLayoutData, rssResponse, textResponse, ViewRenderer, xmlResponse, } from "../core/view/index.ts";
173
173
  export type { ViewEngine } from "../core/view/viewEngine.ts";
174
- export type { HtmxViewResponseOptions, NamespacedViewRenderer, ViewResponseOptions, } from "../core/view/viewRenderer.ts";
174
+ export type { HtmxViewResponseOptions, NamespacedViewRenderer, ViewNamespaceOptions, ViewResponseOptions, } from "../core/view/viewRenderer.ts";
175
175
  export type { WebLayoutAuthUser, WebLayoutData, WebLayoutDataOptions, WebLayoutUserKey, } from "../core/view/webLayoutData.ts";