@palbase/backend 39.0.0 → 39.1.1

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.
@@ -1,5 +1,5 @@
1
1
  import '../index-pK2At5Yc.cjs';
2
- export { A as App, g as AuthVerifier, B as BootRefused, h as COMMAND_EXECUTOR_DDL, j as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, k as EngineConfig, M as ModuleClients, R as RateLimiter, l as RequestDatabase, m as RouteEntry, n as RuntimeHooks, S as ScrubResult, o as SqlDriver, p as SqlTx, q as buildRouteTable, r as createApp, s as createLazyTransaction, t as createOps, u as createRequestDatabase, v as effectiveAuth, w as hostAllowed, x as installCommandExecutor, y as installEgressFence, i as isDeclarationRefused, z as loadConfig, F as makeMemoryCache, G as matchRoute, H as quoteIdent, I as scrubSecrets, J as setCursorKey, K as withQueryCancellation, L as withTables } from '../index-B0mjUnxy.cjs';
2
+ export { A as App, g as AuthVerifier, B as BootRefused, h as COMMAND_EXECUTOR_DDL, j as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, k as EngineConfig, M as ModuleClients, R as RateLimiter, l as RequestDatabase, m as RouteEntry, n as RuntimeHooks, S as ScrubResult, o as SqlDriver, p as SqlTx, q as buildRouteTable, r as createApp, s as createLazyTransaction, t as createOps, u as createRequestDatabase, v as effectiveAuth, w as hostAllowed, x as installCommandExecutor, y as installEgressFence, i as isDeclarationRefused, z as loadConfig, F as makeMemoryCache, G as matchRoute, H as quoteIdent, I as scrubSecrets, J as setCursorKey, K as withQueryCancellation, L as withTables } from '../index-Brhp8cxj.cjs';
3
3
  import 'zod';
4
4
  import '../db/env.cjs';
5
5
  import '../stack.cjs';
@@ -1,5 +1,5 @@
1
1
  import '../index-eN4KzGa5.js';
2
- export { A as App, g as AuthVerifier, B as BootRefused, h as COMMAND_EXECUTOR_DDL, j as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, k as EngineConfig, M as ModuleClients, R as RateLimiter, l as RequestDatabase, m as RouteEntry, n as RuntimeHooks, S as ScrubResult, o as SqlDriver, p as SqlTx, q as buildRouteTable, r as createApp, s as createLazyTransaction, t as createOps, u as createRequestDatabase, v as effectiveAuth, w as hostAllowed, x as installCommandExecutor, y as installEgressFence, i as isDeclarationRefused, z as loadConfig, F as makeMemoryCache, G as matchRoute, H as quoteIdent, I as scrubSecrets, J as setCursorKey, K as withQueryCancellation, L as withTables } from '../index-yDno9Ju9.js';
2
+ export { A as App, g as AuthVerifier, B as BootRefused, h as COMMAND_EXECUTOR_DDL, j as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, k as EngineConfig, M as ModuleClients, R as RateLimiter, l as RequestDatabase, m as RouteEntry, n as RuntimeHooks, S as ScrubResult, o as SqlDriver, p as SqlTx, q as buildRouteTable, r as createApp, s as createLazyTransaction, t as createOps, u as createRequestDatabase, v as effectiveAuth, w as hostAllowed, x as installCommandExecutor, y as installEgressFence, i as isDeclarationRefused, z as loadConfig, F as makeMemoryCache, G as matchRoute, H as quoteIdent, I as scrubSecrets, J as setCursorKey, K as withQueryCancellation, L as withTables } from '../index-Dlu2b9-f.js';
3
3
  import 'zod';
4
4
  import '../db/env.js';
5
5
  import '../stack.js';
@@ -20,7 +20,7 @@ import {
20
20
  setCursorKey,
21
21
  withQueryCancellation,
22
22
  withTables
23
- } from "../chunk-JJSR4BUX.js";
23
+ } from "../chunk-C525N4OW.js";
24
24
  import {
25
25
  DECLARATION_REFUSAL,
26
26
  DeclarationRefused,
@@ -895,18 +895,6 @@ interface RouteMatch {
895
895
  /** First match wins; the table is small and declaration order is the tiebreak. */
896
896
  declare function matchRoute(table: readonly RouteEntry[], method: string, pathname: string): RouteMatch | null;
897
897
 
898
- /**
899
- * engine/auth.ts — verifying the stack's own access tokens.
900
- *
901
- * The engine does this itself rather than trusting a header stamped upstream.
902
- * In the isolate architecture a gateway verified the token and the runtime read
903
- * the result; a backend that boots on its own has no such upstream, so the
904
- * verification lives here — against the keys the stack publishes.
905
- *
906
- * Deliberately narrow: ES256 over P-256, which is what palauth mints. An
907
- * unrecognised `alg` is refused rather than accommodated, because the classic
908
- * JWT break is a verifier that is helpful about algorithms.
909
- */
910
898
  /** The claims the engine reads. Everything else rides along untyped. */
911
899
  interface VerifiedClaims extends Record<string, unknown> {
912
900
  sub?: string;
@@ -930,20 +918,26 @@ declare class AuthVerifier {
930
918
  private keys;
931
919
  private fetchedAt;
932
920
  private inflight;
921
+ private nextRefreshAt;
922
+ private refreshFailed;
933
923
  private readonly jwksUrl;
934
924
  private readonly issuer?;
935
925
  private readonly fetchImpl;
936
926
  private readonly ttl;
937
927
  constructor(opts: AuthVerifierOptions);
938
- /** Fetch the keyset at most once per TTL, and at most once concurrently. */
928
+ /** Fetch once concurrently. Known keys use their trust TTL; misses and
929
+ * failures share a short cooldown so arbitrary kids cannot force a fetch
930
+ * per request, and recovery does not wait for an entire trust TTL. */
939
931
  private refresh;
932
+ private fetchKeyset;
940
933
  private key;
941
934
  /**
942
935
  * Verify an `Authorization` header value.
943
936
  *
944
937
  * @returns the verified claims, or `null` for absent / malformed / expired /
945
- * wrong-issuer / bad-signature. One `null` for every failure on purpose:
946
- * the caller answers 401 either way, and a detailed reason is an oracle.
938
+ * wrong-issuer / bad-signature. Credential refusals deliberately share one
939
+ * result. An unavailable keyset throws 503 instead: no authentication
940
+ * decision was possible, and the caller's session must not be invalidated.
947
941
  */
948
942
  verify(authorization: string | null | undefined): Promise<VerifiedClaims | null>;
949
943
  }
@@ -895,18 +895,6 @@ interface RouteMatch {
895
895
  /** First match wins; the table is small and declaration order is the tiebreak. */
896
896
  declare function matchRoute(table: readonly RouteEntry[], method: string, pathname: string): RouteMatch | null;
897
897
 
898
- /**
899
- * engine/auth.ts — verifying the stack's own access tokens.
900
- *
901
- * The engine does this itself rather than trusting a header stamped upstream.
902
- * In the isolate architecture a gateway verified the token and the runtime read
903
- * the result; a backend that boots on its own has no such upstream, so the
904
- * verification lives here — against the keys the stack publishes.
905
- *
906
- * Deliberately narrow: ES256 over P-256, which is what palauth mints. An
907
- * unrecognised `alg` is refused rather than accommodated, because the classic
908
- * JWT break is a verifier that is helpful about algorithms.
909
- */
910
898
  /** The claims the engine reads. Everything else rides along untyped. */
911
899
  interface VerifiedClaims extends Record<string, unknown> {
912
900
  sub?: string;
@@ -930,20 +918,26 @@ declare class AuthVerifier {
930
918
  private keys;
931
919
  private fetchedAt;
932
920
  private inflight;
921
+ private nextRefreshAt;
922
+ private refreshFailed;
933
923
  private readonly jwksUrl;
934
924
  private readonly issuer?;
935
925
  private readonly fetchImpl;
936
926
  private readonly ttl;
937
927
  constructor(opts: AuthVerifierOptions);
938
- /** Fetch the keyset at most once per TTL, and at most once concurrently. */
928
+ /** Fetch once concurrently. Known keys use their trust TTL; misses and
929
+ * failures share a short cooldown so arbitrary kids cannot force a fetch
930
+ * per request, and recovery does not wait for an entire trust TTL. */
939
931
  private refresh;
932
+ private fetchKeyset;
940
933
  private key;
941
934
  /**
942
935
  * Verify an `Authorization` header value.
943
936
  *
944
937
  * @returns the verified claims, or `null` for absent / malformed / expired /
945
- * wrong-issuer / bad-signature. One `null` for every failure on purpose:
946
- * the caller answers 401 either way, and a detailed reason is an oracle.
938
+ * wrong-issuer / bad-signature. Credential refusals deliberately share one
939
+ * result. An unavailable keyset throws 503 instead: no authentication
940
+ * decision was possible, and the caller's session must not be invalidated.
947
941
  */
948
942
  verify(authorization: string | null | undefined): Promise<VerifiedClaims | null>;
949
943
  }
package/dist/index.cjs CHANGED
@@ -4456,12 +4456,13 @@ __name(sqlFragment, "sqlFragment");
4456
4456
  // src/db/repository.ts
4457
4457
  function defineRepository(table, opts) {
4458
4458
  const tenantColumn = opts.tenant;
4459
+ const rowKey = opts.key ?? "id";
4459
4460
  const scope = /* @__PURE__ */ __name((tenant) => ({
4460
4461
  [tenantColumn]: tenant
4461
4462
  }), "scope");
4462
4463
  const scopeRow = /* @__PURE__ */ __name((tenant, id) => ({
4463
4464
  [tenantColumn]: tenant,
4464
- id
4465
+ [rowKey]: id
4465
4466
  }), "scopeRow");
4466
4467
  const scopedPayload = /* @__PURE__ */ __name((values, tenant) => ({
4467
4468
  ...values,
@@ -4489,7 +4490,7 @@ function defineRepository(table, opts) {
4489
4490
  async update(tenant, id, patch) {
4490
4491
  const row = await this.updateScoped(tenant, id, patch);
4491
4492
  if (row === null) {
4492
- throw new NotFound(`${String(tenantColumn)}=${String(tenant)} kapsam\u0131nda ${id} bulunamad\u0131`);
4493
+ throw new NotFound(`${String(tenantColumn)}=${String(tenant)} kapsam\u0131nda ${rowKey}=${String(id)} bulunamad\u0131`);
4493
4494
  }
4494
4495
  return row;
4495
4496
  }