@palbase/backend 29.0.0 → 30.0.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.
Files changed (34) hide show
  1. package/dist/bin/palbase-backend.cjs +22 -7
  2. package/dist/bin/palbase-backend.cjs.map +1 -1
  3. package/dist/bin/palbase-backend.js +2 -2
  4. package/dist/{chunk-DHJ3SYAE.js → chunk-RADVOY7Y.js} +23 -9
  5. package/dist/{chunk-DHJ3SYAE.js.map → chunk-RADVOY7Y.js.map} +1 -1
  6. package/dist/{chunk-ESSQ3YML.js → chunk-YRVIWHJC.js} +7 -3
  7. package/dist/{chunk-ESSQ3YML.js.map → chunk-YRVIWHJC.js.map} +1 -1
  8. package/dist/db/index.d.cts +1 -1
  9. package/dist/db/index.d.ts +1 -1
  10. package/dist/engine/index.cjs +22 -7
  11. package/dist/engine/index.cjs.map +1 -1
  12. package/dist/engine/index.d.cts +3 -3
  13. package/dist/engine/index.d.ts +3 -3
  14. package/dist/engine/index.js +2 -2
  15. package/dist/{index-BOe82fsK.d.ts → index-8qy3kIuA.d.ts} +66 -4
  16. package/dist/{index-ChvoVczS.d.cts → index-DtCgaZAg.d.cts} +66 -4
  17. package/dist/{index-BZfmdRmh.d.cts → index-Zi7MptvP.d.cts} +3 -3
  18. package/dist/{index-BYDUKexK.d.ts → index-b-Q3l7W5.d.ts} +3 -3
  19. package/dist/index.cjs +55 -2
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +51 -11
  22. package/dist/index.d.ts +51 -11
  23. package/dist/index.js +50 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/openapi/index.d.cts +2 -2
  26. package/dist/openapi/index.d.ts +2 -2
  27. package/dist/{registry-DaqHsOq8.d.ts → registry-BGJ-Al6F.d.ts} +1 -1
  28. package/dist/{registry-B2KfKWv1.d.cts → registry-CEYLH-Iz.d.cts} +1 -1
  29. package/dist/test/index.d.cts +1 -1
  30. package/dist/test/index.d.ts +1 -1
  31. package/docs/README.md +1 -1
  32. package/docs/llms-full.txt +1 -1
  33. package/package.json +1 -1
  34. package/template/package.json +1 -1
@@ -1,4 +1,4 @@
1
- export { f as AnyColumn, k as ColumnBuilder, l as ColumnDef, m as ColumnMap, n as ColumnType, E as EXTENSION_DEPENDENCIES, s as EmbeddingModelRef, u as EnvServiceDatabase, w as EnvTypedDatabase, N as InsertShape, V as Materialized, a0 as OnDeleteAction, a1 as PALBASE_EXTENSIONS, aA as PalbaseExtension, bx as PolicyBuilder, by as PolicyCommand, bz as PolicyDef, bC as PolicyMode, bE as RawConstraintDef, bG as Ref, bI as RowShape, S as SchemaDef, bR as TABLE_META, bS as TableDef, bT as TableHandle, bU as TableInput, bW as TxColumnExpr, bX as TxInsertShape, bZ as TxNow, b_ as TxPlan, T as TxPlanBody, b$ as TxPlanError, c0 as TxPlanHandle, c1 as TxPlanOpResult, c2 as TxPlanRejection, b as TxPlanResponse, c3 as TxRefError, c4 as TxRow, c5 as TxRows, c6 as TxSelectOptions, c7 as TxSetShape, c9 as TxTable, ca as TxTables, cb as TxWhere, ch as TypedDB, ci as TypedTable, cj as TypedTx, cs as bigint, ct as boolean, cv as dec, cy as defineSchema, cz as defineTable, cA as enumType, cC as inc, cF as installationRef, cG as integer, cH as isPalbaseExtension, cJ as jsonb, cK as makeTypedDB, cL as now, cP as openai, cQ as ownedByUser, cR as policy, cS as raw, cU as text, cV as timestamp, cW as userRef, cX as uuid, cY as vector } from '../index-ChvoVczS.cjs';
1
+ export { f as AnyColumn, l as ColumnBuilder, m as ColumnDef, n as ColumnMap, o as ColumnType, E as EXTENSION_DEPENDENCIES, t as EmbeddingModelRef, v as EnvServiceDatabase, x as EnvTypedDatabase, O as InsertShape, W as Materialized, a1 as OnDeleteAction, a2 as PALBASE_EXTENSIONS, aC as PalbaseExtension, bz as PolicyBuilder, bA as PolicyCommand, bB as PolicyDef, bE as PolicyMode, bG as RawConstraintDef, bI as Ref, bK as RowShape, S as SchemaDef, bT as TABLE_META, bU as TableDef, bV as TableHandle, bW as TableInput, bY as TxColumnExpr, bZ as TxInsertShape, b$ as TxNow, c0 as TxPlan, T as TxPlanBody, c1 as TxPlanError, c2 as TxPlanHandle, c3 as TxPlanOpResult, c4 as TxPlanRejection, b as TxPlanResponse, c5 as TxRefError, c6 as TxRow, c7 as TxRows, c8 as TxSelectOptions, c9 as TxSetShape, cb as TxTable, cc as TxTables, cd as TxWhere, cj as TypedDB, ck as TypedTable, cl as TypedTx, cu as bigint, cv as boolean, cx as dec, cA as defineSchema, cB as defineTable, cC as enumType, cE as inc, cH as installationRef, cI as integer, cJ as isPalbaseExtension, cL as jsonb, cM as makeTypedDB, cN as now, cR as openai, cS as ownedByUser, cT as policy, cU as raw, cW as text, cX as timestamp, cY as userRef, cZ as uuid, c_ as vector } from '../index-DtCgaZAg.cjs';
2
2
  import './env.cjs';
3
3
  import '../stack.cjs';
4
4
  import 'zod';
@@ -1,4 +1,4 @@
1
- export { f as AnyColumn, k as ColumnBuilder, l as ColumnDef, m as ColumnMap, n as ColumnType, E as EXTENSION_DEPENDENCIES, s as EmbeddingModelRef, u as EnvServiceDatabase, w as EnvTypedDatabase, N as InsertShape, V as Materialized, a0 as OnDeleteAction, a1 as PALBASE_EXTENSIONS, aA as PalbaseExtension, bx as PolicyBuilder, by as PolicyCommand, bz as PolicyDef, bC as PolicyMode, bE as RawConstraintDef, bG as Ref, bI as RowShape, S as SchemaDef, bR as TABLE_META, bS as TableDef, bT as TableHandle, bU as TableInput, bW as TxColumnExpr, bX as TxInsertShape, bZ as TxNow, b_ as TxPlan, T as TxPlanBody, b$ as TxPlanError, c0 as TxPlanHandle, c1 as TxPlanOpResult, c2 as TxPlanRejection, b as TxPlanResponse, c3 as TxRefError, c4 as TxRow, c5 as TxRows, c6 as TxSelectOptions, c7 as TxSetShape, c9 as TxTable, ca as TxTables, cb as TxWhere, ch as TypedDB, ci as TypedTable, cj as TypedTx, cs as bigint, ct as boolean, cv as dec, cy as defineSchema, cz as defineTable, cA as enumType, cC as inc, cF as installationRef, cG as integer, cH as isPalbaseExtension, cJ as jsonb, cK as makeTypedDB, cL as now, cP as openai, cQ as ownedByUser, cR as policy, cS as raw, cU as text, cV as timestamp, cW as userRef, cX as uuid, cY as vector } from '../index-BOe82fsK.js';
1
+ export { f as AnyColumn, l as ColumnBuilder, m as ColumnDef, n as ColumnMap, o as ColumnType, E as EXTENSION_DEPENDENCIES, t as EmbeddingModelRef, v as EnvServiceDatabase, x as EnvTypedDatabase, O as InsertShape, W as Materialized, a1 as OnDeleteAction, a2 as PALBASE_EXTENSIONS, aC as PalbaseExtension, bz as PolicyBuilder, bA as PolicyCommand, bB as PolicyDef, bE as PolicyMode, bG as RawConstraintDef, bI as Ref, bK as RowShape, S as SchemaDef, bT as TABLE_META, bU as TableDef, bV as TableHandle, bW as TableInput, bY as TxColumnExpr, bZ as TxInsertShape, b$ as TxNow, c0 as TxPlan, T as TxPlanBody, c1 as TxPlanError, c2 as TxPlanHandle, c3 as TxPlanOpResult, c4 as TxPlanRejection, b as TxPlanResponse, c5 as TxRefError, c6 as TxRow, c7 as TxRows, c8 as TxSelectOptions, c9 as TxSetShape, cb as TxTable, cc as TxTables, cd as TxWhere, cj as TypedDB, ck as TypedTable, cl as TypedTx, cu as bigint, cv as boolean, cx as dec, cA as defineSchema, cB as defineTable, cC as enumType, cE as inc, cH as installationRef, cI as integer, cJ as isPalbaseExtension, cL as jsonb, cM as makeTypedDB, cN as now, cR as openai, cS as ownedByUser, cT as policy, cU as raw, cW as text, cX as timestamp, cY as userRef, cZ as uuid, c_ as vector } from '../index-8qy3kIuA.js';
2
2
  import './env.js';
3
3
  import '../stack.js';
4
4
  import 'zod';
@@ -1092,6 +1092,7 @@ var Storage = Object.assign({
1092
1092
  });
1093
1093
  var Cache = makeServiceProxy("Cache");
1094
1094
  var Secrets = makeServiceProxy("Secrets");
1095
+ var Auth = makeServiceProxy("Auth");
1095
1096
  var Log = makeServiceProxy("Log");
1096
1097
  var Notifications = makeServiceProxy("Notifications");
1097
1098
  var rawFlags = makeServiceProxy("Flags");
@@ -4608,7 +4609,7 @@ var AUTHOR_ANSWERED = /* @__PURE__ */ new Set([
4608
4609
  409,
4609
4610
  429
4610
4611
  ]);
4611
- async function refuseUnlessAuthorized(client, spec, requestId) {
4612
+ async function refuseUnlessAuthorized(client, spec, requestId, rolesOfCaller) {
4612
4613
  if (spec.permission !== void 0) {
4613
4614
  const [row] = await client.query("select auth.has_permission($1) as ok", [
4614
4615
  spec.permission
@@ -4618,16 +4619,22 @@ async function refuseUnlessAuthorized(client, spec, requestId) {
4618
4619
  }
4619
4620
  }
4620
4621
  if (spec.role !== void 0) {
4621
- const [row] = await client.query("select $1 = any(auth.app_roles()) as ok", [
4622
- spec.role
4623
- ]);
4624
- if (row?.ok !== true) {
4622
+ const held = await rolesOfCaller();
4623
+ if (!held.includes(spec.role)) {
4625
4624
  return envelope("forbidden", `This endpoint requires the "${spec.role}" role`, 403, requestId);
4626
4625
  }
4627
4626
  }
4628
4627
  return null;
4629
4628
  }
4630
4629
  __name(refuseUnlessAuthorized, "refuseUnlessAuthorized");
4630
+ function makeRoleResolver(client) {
4631
+ let pending = null;
4632
+ return () => {
4633
+ pending ??= client.query("select unnest(auth.app_roles()) as role").then((rows) => rows.map((r) => r.role));
4634
+ return pending;
4635
+ };
4636
+ }
4637
+ __name(makeRoleResolver, "makeRoleResolver");
4631
4638
  async function createApp(opts) {
4632
4639
  const { config, controllers } = opts;
4633
4640
  const container = buildContainer();
@@ -4676,6 +4683,7 @@ async function createApp(opts) {
4676
4683
  Database: db?.client ?? stubModule("Database (a start hook runs before any request \u2014 open your own connection here)"),
4677
4684
  Cache: cache,
4678
4685
  Log: log,
4686
+ Auth: modules.Auth ?? stubModule("Auth"),
4679
4687
  Documents: modules.Documents ?? stubModule("Documents"),
4680
4688
  Storage: modules.Storage ?? stubModule("Storage"),
4681
4689
  Notifications: modules.Notifications ?? stubModule("Notifications"),
@@ -4726,7 +4734,7 @@ async function createApp(opts) {
4726
4734
  claimsJson: JSON.stringify(callerClaims)
4727
4735
  });
4728
4736
  try {
4729
- const refusal = await refuseUnlessAuthorized(uploadDb.client, spec, requestId);
4737
+ const refusal = await refuseUnlessAuthorized(uploadDb.client, spec, requestId, makeRoleResolver(uploadDb.client));
4730
4738
  if (refusal) {
4731
4739
  await uploadDb.commit();
4732
4740
  return refusal;
@@ -4773,8 +4781,9 @@ async function createApp(opts) {
4773
4781
  serviceRole: config.dbServiceRole,
4774
4782
  claimsJson: JSON.stringify(claims ?? {})
4775
4783
  });
4784
+ const rolesOfCaller = makeRoleResolver(db.client);
4776
4785
  if (claims) {
4777
- const refusal = await refuseUnlessAuthorized(db.client, spec, requestId);
4786
+ const refusal = await refuseUnlessAuthorized(db.client, spec, requestId, rolesOfCaller);
4778
4787
  if (refusal) return refusal;
4779
4788
  }
4780
4789
  if (claims && spec.verifiedEmail && claims.email_verified !== true) {
@@ -4927,6 +4936,12 @@ async function createApp(opts) {
4927
4936
  role: claims.role,
4928
4937
  emailVerified: claims.email_verified === true,
4929
4938
  metadata: claims.metadata ?? {},
4939
+ // The caller's APPLICATION roles, from `auth.user_roles` — the
4940
+ // same resolution the gate used, so the handler cannot read a
4941
+ // different set than the one it was admitted on. Never from a
4942
+ // claim: a revoked role has to bite on the next request, and a
4943
+ // token says only what was true when it was minted.
4944
+ roles: await rolesOfCaller(),
4930
4945
  // Server-owned and only ever filled from a verdict palauth
4931
4946
  // returned. Never from a raw header, never from JWT metadata —
4932
4947
  // the type has said so since it was written and this is the