bazis 0.98.26 → 0.98.27

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.
@@ -0,0 +1,37 @@
1
+ import { JwtError } from "../../../library/jwt/errors";
2
+ import { ForbiddenError, UnauthorizedError } from "../Errors/HttpError";
3
+ import type { AuthorizeCheck } from "./metadata";
4
+
5
+ /**
6
+ * A check that passes when any of `checks` passes (`@Authorize(a, b)` needs
7
+ * all of them). Checks run in order and stop at the first that passes. When
8
+ * none passes, the request is `401` if every check failed as "not signed in"
9
+ * (`UnauthorizedError`, `JwtError`), otherwise `403`. Any other error of a
10
+ * check is a bug and propagates unchanged.
11
+ */
12
+ export function anyOf(...checks: AuthorizeCheck[]): AuthorizeCheck {
13
+ if (checks.length === 0) throw new TypeError("anyOf() needs at least one check");
14
+ return async (ctx) => {
15
+ let unauthenticated: UnauthorizedError | undefined;
16
+ let forbidden = false;
17
+ for (const check of checks) {
18
+ try {
19
+ if (await check(ctx)) return true;
20
+ forbidden = true;
21
+ } catch (error) {
22
+ if (error instanceof ForbiddenError) { forbidden = true; continue; }
23
+ if (error instanceof UnauthorizedError) { unauthenticated ??= error; continue; }
24
+ if (error instanceof JwtError) {
25
+ if (unauthenticated === undefined) {
26
+ unauthenticated = new UnauthorizedError();
27
+ Object.defineProperty(unauthenticated, "cause", { value: error, configurable: true, writable: true });
28
+ }
29
+ continue;
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+ if (forbidden) return false;
35
+ throw unauthenticated ?? new UnauthorizedError();
36
+ };
37
+ }
@@ -35,6 +35,7 @@ export { PRINCIPAL_STATE_KEY, type RequestPrincipal } from "./HttpContext/princi
35
35
  export { Authorize, AllowAnonymous } from "./Authorization/Authorize";
36
36
  export { createAuthorizeComposer } from "./Authorization/authorizeComposer";
37
37
  export { bearerToken } from "./Authorization/bearerToken";
38
+ export { anyOf } from "./Authorization/anyOf";
38
39
  export {
39
40
  resolveAuthorizeMeta,
40
41
  type AuthorizeCheck,
@@ -232,7 +232,7 @@ export class CodexAppServerClient implements CodexClient {
232
232
  if (method === "account/updated") this.modelCache = undefined;
233
233
  }, () => { this.clearLogin(); this.modelCache = undefined; });
234
234
  const initialized = await client.request("initialize", {
235
- clientInfo: { name: "bazis", title: "Bazis", version: "0.98.26" }, capabilities: { experimentalApi: true },
235
+ clientInfo: { name: "bazis", title: "Bazis", version: "0.98.27" }, capabilities: { experimentalApi: true },
236
236
  }, 15_000, signal);
237
237
  if (resolve(text(initialized.codexHome, 4096)) !== this.paths.home) throw new CodexError("PROTOCOL_ERROR");
238
238
  client.notify("initialized");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bazis",
3
- "version": "0.98.26",
3
+ "version": "0.98.27",
4
4
  "description": "Modular backend framework for Bun in TypeScript: DI wired by codegen, HTTP, a PostgreSQL ORM, JWT, WebSocket, agents and a CLI.",
5
5
  "license": "MIT",
6
6
  "author": "Alexander Alenin",