@getstrata/core 2.2.42 → 2.2.44
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 +16 -0
- package/dist/core/database/transaction.d.ts +6 -1
- package/dist/core/events/deferredModelEvents.d.ts +4 -1
- package/dist/entries/audit/exportAuditLogs.js +10 -3
- package/dist/entries/auth/basicAuthGuard.js +16 -3
- package/dist/entries/auth/oauth/samlProvider.js +10 -3
- package/dist/entries/auth/oneTimeToken.js +2 -2
- package/dist/entries/auth/passwordLogin.js +6 -0
- package/dist/entries/auth/saml/samlServiceProvider.js +10 -3
- package/dist/entries/auth/scimAuthMiddleware.js +10 -3
- package/dist/entries/http/requirePasswordConfirmMiddleware.js +43 -2
- package/dist/entries/jobs/exportAuditLogsJob.js +10 -3
- package/dist/entries/queue/queueMetrics.js +10 -3
- package/dist/entries/security/totp.js +6 -0
- package/dist/entries/tenant/databaseTenantContext.js +10 -3
- package/dist/entries/tenant/tenantDatabaseScope.js +10 -3
- package/dist/framework/public-api.d.ts +1 -1
- package/dist/index.js +26 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @getstrata/core changelog
|
|
2
2
|
|
|
3
|
+
## 2.2.44
|
|
4
|
+
|
|
5
|
+
Generate JSON registration, verification/resend, reset and password-confirmed MFA for API/SPA cookie starters; share guarded MFA persistence with HTML, reject malformed TOTP secrets, and extend installed-app SMTP, replay, revocation and compiler coverage without changing HTML contracts.
|
|
6
|
+
|
|
7
|
+
Preserve private/no-store headers when the tenancy boundary maps an HTTP error to JSON, without changing its status/body or transaction rollback. Rebuild the starter in standalone generated-app verification to prevent stale output from producing false green results.
|
|
8
|
+
|
|
9
|
+
Honor the explicit API JSON error context during password confirmation even when a client sends HTML/HTMX headers; preserve automatic HTML behavior outside that context.
|
|
10
|
+
|
|
11
|
+
Use the shared JSON parser for signed password reset so malformed input is a controlled 400 and does not consume the reset proof.
|
|
12
|
+
|
|
13
|
+
## 2.2.43
|
|
14
|
+
|
|
15
|
+
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.
|
|
16
|
+
|
|
17
|
+
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.
|
|
18
|
+
|
|
3
19
|
## 2.2.42
|
|
4
20
|
|
|
5
21
|
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.
|
|
@@ -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
|
-
|
|
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 };
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -1581,6 +1588,12 @@ function verifyTotp(secret, token, window = 1) {
|
|
|
1581
1588
|
if (!/^\d{6}$/u.test(normalized)) {
|
|
1582
1589
|
return false;
|
|
1583
1590
|
}
|
|
1591
|
+
try {
|
|
1592
|
+
if (decodeBase32(secret).length === 0)
|
|
1593
|
+
return false;
|
|
1594
|
+
} catch {
|
|
1595
|
+
return false;
|
|
1596
|
+
}
|
|
1584
1597
|
const timestep = Math.floor(Date.now() / 30000);
|
|
1585
1598
|
let matched = false;
|
|
1586
1599
|
for (let offset = -window;offset <= window; offset += 1) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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);
|
|
@@ -702,6 +702,12 @@ function verifyTotp(secret, token, window = 1) {
|
|
|
702
702
|
if (!/^\d{6}$/u.test(normalized)) {
|
|
703
703
|
return false;
|
|
704
704
|
}
|
|
705
|
+
try {
|
|
706
|
+
if (decodeBase32(secret).length === 0)
|
|
707
|
+
return false;
|
|
708
|
+
} catch {
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
705
711
|
const timestep = Math.floor(Date.now() / 30000);
|
|
706
712
|
let matched = false;
|
|
707
713
|
for (let offset = -window;offset <= window; offset += 1) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __esm = (fn, res, err) => () => {
|
|
3
|
+
if (fn)
|
|
4
|
+
try {
|
|
5
|
+
res = fn(fn = 0);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
err = [e];
|
|
8
|
+
}
|
|
9
|
+
if (err)
|
|
10
|
+
throw err[0];
|
|
11
|
+
return res;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// ../../src/core/runtime/asyncContextStore.ts
|
|
15
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
16
|
+
function createAsyncContextStore(key) {
|
|
17
|
+
const symbol = Symbol.for(key);
|
|
18
|
+
const globalRecord = globalThis;
|
|
19
|
+
const existing = globalRecord[symbol];
|
|
20
|
+
if (existing) {
|
|
21
|
+
return existing;
|
|
22
|
+
}
|
|
23
|
+
const store = new AsyncLocalStorage;
|
|
24
|
+
globalRecord[symbol] = store;
|
|
25
|
+
return store;
|
|
26
|
+
}
|
|
27
|
+
var init_asyncContextStore = () => {};
|
|
28
|
+
|
|
2
29
|
// ../../src/core/http/requirePasswordConfirmMiddleware.ts
|
|
3
30
|
import { resolveUserId } from "@getstrata/core/auth/accessControl";
|
|
4
31
|
import { currentAuthUser } from "@getstrata/core/auth/authContext";
|
|
@@ -32,6 +59,19 @@ function requestPrefersJson(request) {
|
|
|
32
59
|
return false;
|
|
33
60
|
}
|
|
34
61
|
|
|
62
|
+
// ../../src/core/http/requestMetaContext.ts
|
|
63
|
+
init_asyncContextStore();
|
|
64
|
+
var requestMetaContext = createAsyncContextStore("@getstrata/requestMetaContext");
|
|
65
|
+
function runWithRequestMeta(meta, callback) {
|
|
66
|
+
return requestMetaContext.run(meta, callback);
|
|
67
|
+
}
|
|
68
|
+
function currentRequestMeta() {
|
|
69
|
+
return requestMetaContext.getStore() ?? {
|
|
70
|
+
ipAddress: null,
|
|
71
|
+
userAgent: null
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
35
75
|
// ../../src/core/http/safeInternalPath.ts
|
|
36
76
|
var NESTED_REDIRECT_KEYS = new Set(["redirect", "next", "return", "returnTo", "return_to"]);
|
|
37
77
|
function looksLikeExternalTarget(value) {
|
|
@@ -101,8 +141,9 @@ var PASSWORD_CONFIRM_PATH = "/confirm-password";
|
|
|
101
141
|
function createRequirePasswordConfirmMiddleware() {
|
|
102
142
|
return async (request, next) => {
|
|
103
143
|
const user = currentAuthUser();
|
|
144
|
+
const json = currentRequestMeta().errorFormat === "json" || requestPrefersJson(request);
|
|
104
145
|
if (!user) {
|
|
105
|
-
if (
|
|
146
|
+
if (json) {
|
|
106
147
|
return errorResponse(new UnauthorizedError("Authentication required."));
|
|
107
148
|
}
|
|
108
149
|
return Response.redirect("/login", 302);
|
|
@@ -111,7 +152,7 @@ function createRequirePasswordConfirmMiddleware() {
|
|
|
111
152
|
if (hasFreshPasswordConfirmation(request, userId, user.authVersion)) {
|
|
112
153
|
return await next();
|
|
113
154
|
}
|
|
114
|
-
if (
|
|
155
|
+
if (json) {
|
|
115
156
|
return errorResponse(new HttpError(423, PASSWORD_CONFIRM_MESSAGE));
|
|
116
157
|
}
|
|
117
158
|
const url = new URL(request.url);
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -164,6 +164,12 @@ function verifyTotp(secret, token, window = 1) {
|
|
|
164
164
|
if (!/^\d{6}$/u.test(normalized)) {
|
|
165
165
|
return false;
|
|
166
166
|
}
|
|
167
|
+
try {
|
|
168
|
+
if (decodeBase32(secret).length === 0)
|
|
169
|
+
return false;
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
167
173
|
const timestep = Math.floor(Date.now() / 30000);
|
|
168
174
|
let matched = false;
|
|
169
175
|
for (let offset = -window;offset <= window; offset += 1) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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";
|
package/dist/index.js
CHANGED
|
@@ -384,7 +384,7 @@ function groupQueuedModelEvents(queued) {
|
|
|
384
384
|
for (const item of queued) {
|
|
385
385
|
const lastGroup = groups[groups.length - 1];
|
|
386
386
|
const last = lastGroup?.[lastGroup.length - 1];
|
|
387
|
-
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant)) {
|
|
387
|
+
if (!lastGroup || !last || !sameTenant(last.tenant, item.tenant) || "callback" in last !== "callback" in item) {
|
|
388
388
|
groups.push([item]);
|
|
389
389
|
} else {
|
|
390
390
|
lastGroup.push(item);
|
|
@@ -394,7 +394,10 @@ function groupQueuedModelEvents(queued) {
|
|
|
394
394
|
}
|
|
395
395
|
async function dispatchEventBatch(batch) {
|
|
396
396
|
for (const item of batch) {
|
|
397
|
-
|
|
397
|
+
if ("callback" in item)
|
|
398
|
+
await item.callback();
|
|
399
|
+
else
|
|
400
|
+
await eventBus.dispatch(item.event, item.payload);
|
|
398
401
|
}
|
|
399
402
|
}
|
|
400
403
|
async function dispatchQueuedModelEvents(queued) {
|
|
@@ -405,7 +408,11 @@ async function dispatchQueuedModelEvents(queued) {
|
|
|
405
408
|
for (const batch of groupQueuedModelEvents(queued)) {
|
|
406
409
|
const tenant = batch[0]?.tenant ?? null;
|
|
407
410
|
if (tenant) {
|
|
408
|
-
|
|
411
|
+
if (batch.some((item) => ("callback" in item))) {
|
|
412
|
+
await runWithTenant(tenant, () => dispatchEventBatch(batch));
|
|
413
|
+
} else {
|
|
414
|
+
await runWithTenantDatabase(tenant, () => dispatchEventBatch(batch));
|
|
415
|
+
}
|
|
409
416
|
} else {
|
|
410
417
|
await dispatchEventBatch(batch);
|
|
411
418
|
}
|
|
@@ -425,6 +432,14 @@ async function dispatchModelEvent(event, payload) {
|
|
|
425
432
|
}
|
|
426
433
|
await eventBus.dispatch(event, payload);
|
|
427
434
|
}
|
|
435
|
+
async function afterCommit(callback) {
|
|
436
|
+
const frame = deferredModelEvents.getStore()?.frames.at(-1);
|
|
437
|
+
if (frame) {
|
|
438
|
+
frame.push({ callback, tenant: currentTenant() });
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
await callback();
|
|
442
|
+
}
|
|
428
443
|
async function runWithDeferredModelEvents(callback) {
|
|
429
444
|
const existing = deferredModelEvents.getStore();
|
|
430
445
|
if (existing) {
|
|
@@ -1748,6 +1763,12 @@ function verifyTotp(secret, token, window = 1) {
|
|
|
1748
1763
|
if (!/^\d{6}$/u.test(normalized)) {
|
|
1749
1764
|
return false;
|
|
1750
1765
|
}
|
|
1766
|
+
try {
|
|
1767
|
+
if (decodeBase32(secret).length === 0)
|
|
1768
|
+
return false;
|
|
1769
|
+
} catch {
|
|
1770
|
+
return false;
|
|
1771
|
+
}
|
|
1751
1772
|
const timestep = Math.floor(Date.now() / 30000);
|
|
1752
1773
|
let matched = false;
|
|
1753
1774
|
for (let offset = -window;offset <= window; offset += 1) {
|
|
@@ -16266,7 +16287,7 @@ function createTenantMiddleware(options = {}) {
|
|
|
16266
16287
|
} catch (error) {
|
|
16267
16288
|
const httpError = toHttpError(error);
|
|
16268
16289
|
if (httpError) {
|
|
16269
|
-
return
|
|
16290
|
+
return privateJsonResponse({ error: httpError.message }, { status: httpError.status });
|
|
16270
16291
|
}
|
|
16271
16292
|
throw error;
|
|
16272
16293
|
}
|
|
@@ -17197,6 +17218,7 @@ export {
|
|
|
17197
17218
|
WhereBuilder,
|
|
17198
17219
|
absoluteTemporarySignedUrl,
|
|
17199
17220
|
acquireTracingRuntime,
|
|
17221
|
+
afterCommit,
|
|
17200
17222
|
apiPrefix,
|
|
17201
17223
|
appCookieName,
|
|
17202
17224
|
appDevSecret,
|