permdock 0.20.0 → 0.21.0
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/dist/a2a/index.d.ts +1 -1
- package/dist/a2a/index.js +3 -3
- package/dist/{adoption-scan-BWL5H82_.js → adoption-scan-UkQisAqe.js} +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/ai-sdk/index.d.ts +1 -1
- package/dist/ai-sdk/index.js +3 -3
- package/dist/approvals/index.d.ts +1 -1
- package/dist/{arazzo-B_CPVseu.js → arazzo-BC3uLIZy.js} +2 -2
- package/dist/{arazzo-C8u26FUA.js → arazzo-CUthH61H.js} +1 -1
- package/dist/astro/index.d.ts +3 -3
- package/dist/astro/index.js +1 -1
- package/dist/authzen/index.d.ts +2 -2
- package/dist/authzen/index.js +1 -1
- package/dist/better-supabase/index.d.ts +2 -2
- package/dist/better-supabase/index.js +3 -3
- package/dist/{bind-gwEbe9hL.js → bind-CJf7S-Jd.js} +3 -3
- package/dist/{bind-CW7nsZ86.d.ts → bind-XvnD_SUz.d.ts} +5 -5
- package/dist/{build-instance-DaBdCRiz.js → build-instance-CkRKgjSj.js} +1 -1
- package/dist/{casbin-JWZGKqzy.js → casbin-BOZN1P2Y.js} +1 -1
- package/dist/{casbin-DaY-CWOr.js → casbin-v9Xo_XPa.js} +1 -1
- package/dist/catalog/index.js +2 -2
- package/dist/chat/index.d.ts +1 -1
- package/dist/chat/index.js +1 -1
- package/dist/chat-sdk/index.d.ts +1 -1
- package/dist/claude-agent/index.d.ts +2 -2
- package/dist/claude-agent/index.js +2 -2
- package/dist/clerk/index.d.ts +1 -1
- package/dist/cli/bin.js +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/{cloud-pEhjaPNs.js → cloud-CB0btByh.js} +2 -2
- package/dist/{codemod-Cv0-7Ogj.js → codemod-B-duJDFD.js} +1 -1
- package/dist/{codemod-BUhreN8m.js → codemod-C3a3Iz_w.js} +2 -2
- package/dist/compile/index.d.ts +1 -1
- package/dist/{compile-DZftFfXc.d.ts → compile-DonvwG9x.d.ts} +1 -1
- package/dist/{completion-BG1wcLJ3.js → completion-6IshPaPd.js} +1 -1
- package/dist/{config-Di9kWoLY.js → config-C45X7mpm.js} +1 -1
- package/dist/{config-report-B0IyW7EQ.js → config-report-Bmo62RRr.js} +1 -1
- package/dist/convex/index.d.ts +2 -2
- package/dist/convex/index.js +2 -2
- package/dist/{core-BOeGWbcR.d.ts → core-9KbhurkH.d.ts} +1 -1
- package/dist/{core-BwVkrpsi.js → core-Dxkwz4xR.js} +2 -2
- package/dist/{create-DMCC5ZOi.d.ts → create-BQOQkYYg.d.ts} +4 -4
- package/dist/{create-DDUFG1ul.js → create-BRiRVNUO.js} +5 -4
- package/dist/{create-DYSYYiLr.d.ts → create-BzgDDamI.d.ts} +1 -1
- package/dist/{create-BezeYFcT.d.ts → create-DH4ZD0A7.d.ts} +2 -2
- package/dist/{create-C0R8omeF.js → create-Q0wF9Elt.js} +3 -3
- package/dist/delivery/index.d.ts +1 -1
- package/dist/{diff-DXRNcjpg.js → diff-3fpwo3UD.js} +1 -1
- package/dist/{diff-Bd1-VCe5.js → diff-BJv7I3GR.js} +2 -2
- package/dist/{doctor-DpD4nHMS.js → doctor-Bz7s3JYD.js} +13 -13
- package/dist/{doctor-Bp3xspBi.js → doctor-keoa9DpH.js} +2 -2
- package/dist/drizzle/index.d.ts +2 -2
- package/dist/elysia/index.d.ts +3 -3
- package/dist/elysia/index.js +1 -1
- package/dist/{evaluations-BgxEfPL7.d.ts → evaluations-OCm_Z-8V.d.ts} +1 -1
- package/dist/eve/index.d.ts +2 -2
- package/dist/eve/index.js +2 -2
- package/dist/express/index.d.ts +3 -3
- package/dist/express/index.js +1 -1
- package/dist/fastify/index.d.ts +3 -3
- package/dist/fastify/index.js +1 -1
- package/dist/{fetch-adapter-acq4dPX3.js → fetch-adapter-4EB3cLgB.js} +3 -2
- package/dist/{fetch-adapter-DCQ4pZxf.d.ts → fetch-adapter-BlL-ZhHq.d.ts} +2 -2
- package/dist/{fields-COvJbUva.js → fields-D_TfExiI.js} +1 -1
- package/dist/{gen-CKr1Vfiz.js → gen-Cf7nQsOb.js} +1 -1
- package/dist/{gen-B2O9T25-.js → gen-DYF4LKUP.js} +1 -1
- package/dist/h3/index.d.ts +3 -3
- package/dist/h3/index.js +2 -2
- package/dist/hono/index.d.ts +3 -3
- package/dist/hono/index.js +1 -1
- package/dist/{import-DVI_1tO_.js → import-C2ExjVvv.js} +2 -2
- package/dist/{import-DG6uswAo.js → import-CQ_kH_Ny.js} +1 -1
- package/dist/{index-Bt37QovT.d.ts → index-BqzpT-90.d.ts} +1 -1
- package/dist/{index-CruReRkB.d.ts → index-Do7FqHEr.d.ts} +1 -1
- package/dist/{index-B_I6N8Ju.d.ts → index-DuOF7OqS.d.ts} +2 -2
- package/dist/{index-D7xGi1LS.d.ts → index-tuR-kZoJ.d.ts} +4 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/{init-C-cgOvCl.js → init-DvkvbvZ_.js} +1 -1
- package/dist/{init-DAPbdjcX.js → init-kTFkEu8S.js} +3 -3
- package/dist/{instance-options-VPsNQsTH.d.ts → instance-options-Cq66kEeR.d.ts} +1 -1
- package/dist/{instance-snapshot-SX8zH_1t.js → instance-snapshot-Bi4-dJk0.js} +1 -1
- package/dist/{kernel-_QEUOSU0.js → kernel-CLEzDmbv.js} +3 -3
- package/dist/kysely/index.d.ts +2 -2
- package/dist/{login-Cgix5FgG.js → login-9ycIcJZH.js} +1 -1
- package/dist/{login-CQGjpkuo.js → login-CM_etiLM.js} +3 -3
- package/dist/{manifest-CMu1IE0R.js → manifest-CCd-xrM3.js} +33 -33
- package/dist/mcp/index.d.ts +3 -3
- package/dist/mcp/index.js +3 -3
- package/dist/{migrate-BbY5-Khy.js → migrate-CkLHdwuH.js} +1 -1
- package/dist/nest/index.d.ts +3 -3
- package/dist/nest/index.js +1 -1
- package/dist/next/index.d.ts +9 -6
- package/dist/next/index.js +6 -4
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.js +1 -1
- package/dist/openai/index.d.ts +2 -2
- package/dist/openai/index.js +3 -3
- package/dist/{openapi-FVeCoh97.js → openapi-DA7FVG2F.js} +1 -1
- package/dist/{openapi-lsf1gEtr.js → openapi-QnnU2A1c.js} +2 -2
- package/dist/orpc/index.d.ts +4 -4
- package/dist/orpc/index.js +2 -2
- package/dist/otel/index.d.ts +2 -2
- package/dist/{output-DZQCr2lP.js → output-KT0a3B3H.js} +1 -1
- package/dist/{ownership-CBuIjxKh.js → ownership-CeNOtQMV.js} +2 -2
- package/dist/pdp/index.d.ts +2 -2
- package/dist/pdp/index.js +1 -1
- package/dist/{permdock-D4F2p5J8.d.ts → permdock-CsrvbzHk.d.ts} +5 -0
- package/dist/{permdock-C1DN_7a-.js → permdock-DbAq8_Fp.js} +2 -1
- package/dist/{permissions-8N2yFsUM.js → permissions-Dz79qsFw.js} +1 -1
- package/dist/{policy-from-catalog-CUNlpgz0.js → policy-from-catalog-BtqfxytV.js} +1 -1
- package/dist/powersync-CWCirKAJ.js +1 -0
- package/dist/{powersync-CRtuJXVB.js → powersync-CWsN-QaK.js} +2 -2
- package/dist/{powersync-Dz4H1FLs.js → powersync-DiqY3VBG.js} +6 -6
- package/dist/prisma/index.d.ts +1 -1
- package/dist/{protected-action-ua0cx5cW.d.ts → protected-action-CuG0xz4P.d.ts} +3 -3
- package/dist/{provider-D_hgjZRa.d.ts → provider-ihxuJbMi.d.ts} +1 -1
- package/dist/{pull-DnhBA9pf.js → pull-B4EhSqOG.js} +1 -1
- package/dist/pull-VzcECZ-R.js +1 -0
- package/dist/{push-D2SsRW0U.js → push-DYOI4bPf.js} +1 -1
- package/dist/{pushed-policy-BERO0x9O.js → pushed-policy-Dszouliu.js} +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/provider-client.d.ts +1 -1
- package/dist/react-native/index.d.ts +4 -4
- package/dist/{request-context-BPTi68z5.js → request-context-VjeXst1z.js} +1 -1
- package/dist/{resolve-names-CDnxNqNb.js → resolve-names-BIHnWL_L.js} +3 -3
- package/dist/{rls-CHZi5SUK.js → rls-C7qXye9M.js} +1 -1
- package/dist/{rls-CbDKv6GP.js → rls-CMFZWosz.js} +13 -13
- package/dist/{rpc-DdkbQVlT.js → rpc-BNIQwEB6.js} +1 -1
- package/dist/{rpc-D2LnFELm.d.ts → rpc-CYXICjM1.d.ts} +1 -1
- package/dist/{run-Bnm5VZ8m.js → run-CMJX9x7b.js} +2 -2
- package/dist/run-D2e1tybu.js +1 -0
- package/dist/{run-ticket-94DOS9Cd.d.ts → run-ticket-BXYqQ9dy.d.ts} +1 -1
- package/dist/{saas-BEXnrH9H.js → saas-DHFfthXv.js} +2 -2
- package/dist/{scan-VKkU4Ix9.js → scan-CSOkcNdl.js} +1 -1
- package/dist/{schema-5onstWlb.js → schema-7pXCaRYB.js} +1 -1
- package/dist/server/index.d.ts +4 -4
- package/dist/server/index.js +1 -1
- package/dist/{server-types-ChzXWU4Y.d.ts → server-types-Bfl-IrzZ.d.ts} +6 -5
- package/dist/{shared-DyYVEjKC.js → shared-sW3VYchq.js} +2 -1
- package/dist/{skills-Yz3LfoAZ.js → skills-DAjg-rgF.js} +1 -1
- package/dist/{skills-B6sLqv4E.js → skills-DrX83QBK.js} +1 -1
- package/dist/solid/index.d.ts +2 -2
- package/dist/solid-start/index.d.ts +3 -3
- package/dist/solid-start/index.js +2 -2
- package/dist/{src-B8SQNsvw.js → src-Cop53_X1.js} +3 -2
- package/dist/{store-Dpg_fSNQ.d.ts → store-CRQ5VrWR.d.ts} +1 -1
- package/dist/{stores-C2A6KsxE.d.ts → stores-pEBMy94l.d.ts} +3 -3
- package/dist/supabase/middleware.d.ts +4 -4
- package/dist/supabase/middleware.js +4 -4
- package/dist/{supabase-CWpADE8k.js → supabase-Cbl2orB2.js} +2 -2
- package/dist/{supabase-hook-bDeWbKee.js → supabase-hook-BUcu3vPM.js} +11 -6
- package/dist/supabase-hook-QWphWBnG.js +1 -0
- package/dist/{supautils-0RrdsFT3.js → supautils-a_253u1X.js} +67 -8
- package/dist/svelte/index.d.ts +3 -3
- package/dist/svelte/runtime.d.ts +2 -2
- package/dist/svelte/source.d.ts +3 -3
- package/dist/sveltekit/index.d.ts +3 -3
- package/dist/sveltekit/index.js +1 -1
- package/dist/{tables-C53U2zrN.js → tables-XrvffTMj.js} +329 -68
- package/dist/tanstack-start/index.d.ts +3 -3
- package/dist/tanstack-start/index.js +1 -1
- package/dist/terminal/index.d.ts +2 -2
- package/dist/terminal/index.js +2 -2
- package/dist/testing/core.d.ts +1 -1
- package/dist/testing/core.js +1 -1
- package/dist/testing/index.d.ts +7 -7
- package/dist/testing/index.js +6 -6
- package/dist/testing/saas/index.d.ts +1 -1
- package/dist/testing/saas/index.js +2 -2
- package/dist/testing/saas/permissions.js +1 -1
- package/dist/trpc/index.d.ts +4 -4
- package/dist/trpc/index.js +2 -2
- package/dist/{types-C5p2hoBR.d.ts → types-C3C9ien9.d.ts} +2 -2
- package/dist/{types-Drs3OOAy.d.ts → types-DjGZAU64.d.ts} +2 -2
- package/dist/{types-D8JVDWOr.d.ts → types-DotXrris.d.ts} +1 -1
- package/dist/{types-DnzRZjEu.d.ts → types-MixnvXQ5.d.ts} +2 -2
- package/dist/{types-CMclYgSk.d.ts → types-zh4WGQcP.d.ts} +1 -1
- package/dist/{usage-BFMCEgJp.js → usage-DHsqp4lN.js} +1 -1
- package/dist/{usage-B6gmS634.js → usage-DPbdI3Vi.js} +2 -2
- package/dist/usage-dmSjKx-Z.js +1 -0
- package/dist/{verify-DFruUfZg.js → verify-C0jGJrmb.js} +7 -7
- package/dist/vue/index.d.ts +2 -2
- package/dist/workflow/index.d.ts +1 -1
- package/dist/workflow/index.js +1 -1
- package/dist/workflow-sdk/index.d.ts +2 -2
- package/dist/{wrap-CE5lxje7.d.ts → wrap-EQ6Or2Hi.d.ts} +1 -1
- package/package.json +1 -1
- package/dist/powersync-BV68Jh-T.js +0 -1
- package/dist/pull-AOmtUo8V.js +0 -1
- package/dist/run-D6U-Gwok.js +0 -1
- package/dist/supabase-hook-Clczf4iF.js +0 -1
- package/dist/usage-Csu-M5jC.js +0 -1
|
@@ -4,12 +4,12 @@ import { c as rootScope, d as scopeList, l as scopeChain, s as resolveScope } fr
|
|
|
4
4
|
import { o as flattenGrantee } from "./grantee-Dke-9rd1.js";
|
|
5
5
|
import { r as relationCondition, t as inheritCondition } from "./grantee-conditions-DX4K_gGI.js";
|
|
6
6
|
import { l as partitionsOf, p as scopeField } from "./tenancy-DvOHHk3-.js";
|
|
7
|
-
import { a as delegatedScopeMap } from "./permdock-
|
|
7
|
+
import { a as delegatedScopeMap } from "./permdock-DbAq8_Fp.js";
|
|
8
8
|
import { i as configError } from "./errors-BhRkoNS7.js";
|
|
9
9
|
import { d as sqlTextArray, i as qualifySqlTable, t as SQL_IDENT } from "./sql-0WjxIp9g.js";
|
|
10
10
|
import { a as scopeMembershipTable, d as restrictedRowsSql, i as scopeColumn, l as relationArmSql } from "./compile-B_oJqmIg.js";
|
|
11
|
-
import { d as keptKeys, l as roleColumn, u as roleManifest } from "./sources-C4vkzZJV.js";
|
|
12
|
-
import { A as quoteQualified, D as qualified, E as helperSchema, I as scopeTypeOf, O as quoteIdent, R as tenantTypeOf, _ as subjectClaimJsonSql, d as keyTenantSql, f as kindFilterSql, h as roleKindSql, i as allowEntry, j as quoteTable, k as quoteLiteral, m as memberVia, n as GLOBAL_ROLES, o as rootName, r as HELPERS, s as signedIn, t as CUSTOM_ROLES, u as globalKindFilterSql, v as subjectClaimSql, w as CLI, x as userIdHelperSql, y as subjectIdSql } from "./shared-
|
|
11
|
+
import { d as keptKeys, l as roleColumn, t as AUTHZ_VERSION_TABLE, u as roleManifest } from "./sources-C4vkzZJV.js";
|
|
12
|
+
import { A as quoteQualified, D as qualified, E as helperSchema, I as scopeTypeOf, O as quoteIdent, R as tenantTypeOf, _ as subjectClaimJsonSql, d as keyTenantSql, f as kindFilterSql, h as roleKindSql, i as allowEntry, j as quoteTable, k as quoteLiteral, m as memberVia, n as GLOBAL_ROLES, o as rootName, r as HELPERS, s as signedIn, t as CUSTOM_ROLES, u as globalKindFilterSql, v as subjectClaimSql, w as CLI, x as userIdHelperSql, y as subjectIdSql } from "./shared-sW3VYchq.js";
|
|
13
13
|
//#region src/cli/sql/active.ts
|
|
14
14
|
function checkActiveRow(label, row) {
|
|
15
15
|
quoteTable(row.table);
|
|
@@ -77,6 +77,49 @@ function activeRowSql(row, id) {
|
|
|
77
77
|
const where = parts.length === 0 ? "" : ` where ${parts.join(" and ")}`;
|
|
78
78
|
return `coalesce(${id} in (select s.${quoteIdent(row.id)} from ${table} s${where}), false)`;
|
|
79
79
|
}
|
|
80
|
+
function activeJoin(row, id, alias) {
|
|
81
|
+
const table = quoteTable(qualifySqlTable(row.table));
|
|
82
|
+
const parts = [`${alias}.${quoteIdent(row.id)} = ${id}`];
|
|
83
|
+
if (row.disabledAt !== void 0) parts.push(`${alias}.${quoteIdent(row.disabledAt)} is null`);
|
|
84
|
+
if (row.status !== void 0) {
|
|
85
|
+
const values = (row.active ?? []).map(quoteLiteral).join(", ");
|
|
86
|
+
parts.push(`${alias}.${quoteIdent(row.status)}::text = any(array[${values}]::text[])`);
|
|
87
|
+
}
|
|
88
|
+
return `join ${table} ${alias} on ${parts.join(" and ")}`;
|
|
89
|
+
}
|
|
90
|
+
function activeUserChecks(ctx, user, alias, indent) {
|
|
91
|
+
const row = ctx.suspension?.users;
|
|
92
|
+
return row === void 0 ? {
|
|
93
|
+
joins: [],
|
|
94
|
+
filters: []
|
|
95
|
+
} : {
|
|
96
|
+
joins: [`${indent}${activeJoin(row, user, alias)}`],
|
|
97
|
+
filters: []
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function activeInstanceChecks(ctx, scope, idOf, aliasOf, indent, permission = ctx.permission === void 0 ? void 0 : { key: ctx.permission }) {
|
|
101
|
+
const joins = [];
|
|
102
|
+
const filters = [];
|
|
103
|
+
for (const name of scopeChain(ctx.scopes, scope)) {
|
|
104
|
+
const row = ctx.suspension?.scopes?.[name];
|
|
105
|
+
if (row === void 0) continue;
|
|
106
|
+
const id = idOf(name);
|
|
107
|
+
if (id === void 0) throw configError(`PermDock CLI: rls.suspension.scopes.${name} needs the ${name} id on ${scope} memberships: add columns.${name} to the ${scope} memberships table`);
|
|
108
|
+
const keep = keptKeys(row);
|
|
109
|
+
if (permission !== void 0 && "key" in permission && keep.includes(permission.key)) continue;
|
|
110
|
+
const cast = `(${id})::${scopeTypeOf(ctx, name)}`;
|
|
111
|
+
if (keep.length === 0) {
|
|
112
|
+
joins.push(`${indent}${activeJoin(row, cast, aliasOf(name))}`);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const active = activeRowSql(row, cast);
|
|
116
|
+
filters.push(permission !== void 0 && "sql" in permission ? `(${active} or ${permission.sql} = any(array[${keep.map(quoteLiteral).join(", ")}]::text[]))` : active);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
joins,
|
|
120
|
+
filters
|
|
121
|
+
};
|
|
122
|
+
}
|
|
80
123
|
/** The active-user check for `user`; empty without `rls.suspension.users`. */
|
|
81
124
|
function activeUserSql(ctx, user = subjectIdSql(ctx)) {
|
|
82
125
|
const row = ctx.suspension?.users;
|
|
@@ -1148,79 +1191,114 @@ function customKeysSql(ctx, scope, allows, denies, includes) {
|
|
|
1148
1191
|
${quoteLiteral(scope)}
|
|
1149
1192
|
))`;
|
|
1150
1193
|
}
|
|
1151
|
-
function
|
|
1152
|
-
const
|
|
1153
|
-
if (
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1194
|
+
function tableFilters(ctx, scope, table, tenantColumn, grant) {
|
|
1195
|
+
const filters = [];
|
|
1196
|
+
if (table.expiresAt !== void 0) {
|
|
1197
|
+
const expires = memberColumn(table.expiresAt);
|
|
1198
|
+
filters.push(` and (${expires} is null or ${expires} > now())`);
|
|
1199
|
+
}
|
|
1200
|
+
filters.push(...activeMembershipSql(ctx, disabledColumn(table), grantPermissionSql(grant)).map((part) => ` and ${part}`));
|
|
1201
|
+
if (tenantColumn !== void 0 && ctx.tenants !== "all") filters.push(` and (${activeTenant(ctx)} is null or ${memberColumn(tenantColumn)}::text = ${activeTenant(ctx)})`);
|
|
1202
|
+
const keyed = keyTenantSql(ctx, tenantColumn === void 0 ? void 0 : memberColumn(tenantColumn));
|
|
1203
|
+
if (keyed !== void 0) filters.push(` and ${keyed}`);
|
|
1204
|
+
const user = activeUserChecks(ctx, memberColumn(table.user), "act_user", " ");
|
|
1205
|
+
const instances = activeInstanceChecks(ctx, scope, (name) => {
|
|
1206
|
+
const held = scopeColumn(table, ctx.scopes, name);
|
|
1207
|
+
return held === void 0 ? void 0 : memberColumn(held);
|
|
1208
|
+
}, (name) => `act_${name}`, " ", grantPermissionSql(grant));
|
|
1209
|
+
filters.push(...instances.filters.map((part) => ` and ${part}`));
|
|
1210
|
+
return {
|
|
1211
|
+
owner: ` where ${memberColumn(table.user)} = ${subjectIdSql(ctx)}`,
|
|
1212
|
+
joins: [...user.joins, ...instances.joins],
|
|
1213
|
+
filters
|
|
1171
1214
|
};
|
|
1172
|
-
|
|
1173
|
-
|
|
1215
|
+
}
|
|
1216
|
+
function tableBranch(ctx, scope, type, table, column, tenantColumn, branch, set, declared, stale) {
|
|
1217
|
+
const checks = tableFilters(ctx, scope, table, tenantColumn, branch === "custom" && set ? "ck.grant_key" : set ? "rp.grant_key" : "p_grant");
|
|
1174
1218
|
const role = memberRoleOf(table, "m", " ");
|
|
1175
1219
|
const kind = kindFilterSql(ctx, role.sql, memberVia(table));
|
|
1176
|
-
const
|
|
1177
|
-
` select${role.lateral ? " distinct" : ""} ${memberColumn(column)}::${type}${set ? ", rp.grant_key" : ""}`,
|
|
1178
|
-
` from ${quoteQualified(table.table)} m${role.join}`,
|
|
1179
|
-
` join ${qualified(ctx, "role_permissions")} rp on rp.role = ${role.sql}`,
|
|
1180
|
-
owner ?? "",
|
|
1181
|
-
...set ? [] : [" and rp.grant_key = p_grant"],
|
|
1182
|
-
` and rp.scope = ${quoteLiteral(scope)}`,
|
|
1183
|
-
...kind === void 0 ? [] : [` and ${kind}`],
|
|
1184
|
-
...rest
|
|
1185
|
-
];
|
|
1220
|
+
const gate = stale === true ? [` and not (select ${qualified(ctx, HELPERS.tokenCurrent)}())`] : [];
|
|
1186
1221
|
const custom = ctx.customRoles;
|
|
1187
|
-
|
|
1222
|
+
return [
|
|
1223
|
+
branch === "declared" ? ` select${role.lateral ? " distinct" : ""} ${memberColumn(column)}::${type}${set ? ", rp.grant_key" : ""}` : ` select ${memberColumn(column)}::${type}${set ? ", ck.grant_key" : ""}`,
|
|
1224
|
+
` from ${quoteQualified(table.table)} m${role.join}`,
|
|
1225
|
+
...checks.joins,
|
|
1226
|
+
...branch === "custom" && set && custom !== void 0 ? [customKeysJoin(ctx, scope, ...customEntries(ctx, scope, column, tenantColumn, role.sql))] : [],
|
|
1227
|
+
...branch === "declared" ? [` join ${qualified(ctx, "role_permissions")} rp on rp.role = ${role.sql}`] : [],
|
|
1228
|
+
checks.owner,
|
|
1229
|
+
...gate,
|
|
1230
|
+
...branch === "declared" ? [
|
|
1231
|
+
...set ? [] : [" and rp.grant_key = p_grant"],
|
|
1232
|
+
` and rp.scope = ${quoteLiteral(scope)}`,
|
|
1233
|
+
...kind === void 0 ? [] : [` and ${kind}`]
|
|
1234
|
+
] : [` and not (${role.sql} = any(${sqlTextArray(declared)}))`],
|
|
1235
|
+
...checks.filters,
|
|
1236
|
+
...branch === "custom" && !set && custom !== void 0 ? [customKeysSql(ctx, scope, ...customEntries(ctx, scope, column, tenantColumn, role.sql))] : []
|
|
1237
|
+
].join("\n");
|
|
1238
|
+
}
|
|
1239
|
+
function customEntries(ctx, scope, column, tenantColumn, roleSql) {
|
|
1188
1240
|
const match = [
|
|
1189
|
-
customTenantMatch(ctx, `${memberColumn(tenantColumn ?? column)}::text`, scope,
|
|
1241
|
+
customTenantMatch(ctx, `${memberColumn(tenantColumn ?? column)}::text`, scope, roleSql),
|
|
1190
1242
|
`c.scope = ${quoteLiteral(scope)}`,
|
|
1191
1243
|
`(c.scope_id is null or c.scope_id = ${memberColumn(column)}::text)`,
|
|
1192
|
-
`c.role = ${
|
|
1244
|
+
`c.role = ${roleSql}`
|
|
1193
1245
|
].join(" and ");
|
|
1194
1246
|
const rows = (source, value, extra) => `array(select c.${value} from ${qualified(ctx, source)} c where ${match}${extra})`;
|
|
1195
|
-
|
|
1247
|
+
return [
|
|
1196
1248
|
rows(CUSTOM_ROLES.permissions, allowEntry(ctx), " and c.effect = 'allow'"),
|
|
1197
1249
|
rows(CUSTOM_ROLES.permissions, "permission", " and c.effect = 'deny'"),
|
|
1198
1250
|
rows(CUSTOM_ROLES.includes, "include_role", "")
|
|
1199
1251
|
];
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
...filters,
|
|
1215
|
-
` and not (${role.sql} = any(${sqlTextArray(custom.declared)}))`,
|
|
1216
|
-
customKeysSql(ctx, scope, ...entries)
|
|
1217
|
-
].join("\n");
|
|
1252
|
+
}
|
|
1253
|
+
function tableBody(ctx, scope, type) {
|
|
1254
|
+
const mapped = scopeTable(ctx, scope);
|
|
1255
|
+
if (mapped === void 0) return ` select null::${type} where false -- no ${scope} memberships table configured`;
|
|
1256
|
+
const { table, column, tenantColumn } = mapped;
|
|
1257
|
+
const set = ctx.grantSet === true;
|
|
1258
|
+
const custom = ctx.customRoles;
|
|
1259
|
+
const branches = [];
|
|
1260
|
+
if (ctx.claimsFirst === true && !set) {
|
|
1261
|
+
branches.push(claimDeclaredBody(ctx, scope, type));
|
|
1262
|
+
branches.push(tableBranch(ctx, scope, type, table, column, tenantColumn, "declared", set, [], true));
|
|
1263
|
+
} else branches.push(tableBranch(ctx, scope, type, table, column, tenantColumn, "declared", set, []));
|
|
1264
|
+
if (custom !== void 0) branches.push(tableBranch(ctx, scope, type, table, column, tenantColumn, "custom", set, custom.declared));
|
|
1265
|
+
return branches.join("\n union\n");
|
|
1218
1266
|
}
|
|
1219
1267
|
/** The membership's instance of the first scope, from the canonical claim. */
|
|
1220
1268
|
function claimTenant(ctx, scope) {
|
|
1221
1269
|
const root = rootName(ctx);
|
|
1222
1270
|
return scope === root ? `m ->> 'id'` : `m -> 'within' ->> ${quoteLiteral(root)}`;
|
|
1223
1271
|
}
|
|
1272
|
+
function claimDeclaredBody(ctx, scope, type) {
|
|
1273
|
+
const grant = "p_grant";
|
|
1274
|
+
const narrow = narrowsTo(ctx, scope) ? `\n and (${activeTenant(ctx)} is null or ${claimTenant(ctx, scope)} = ${activeTenant(ctx)})` : "";
|
|
1275
|
+
const user = activeUserChecks(ctx, subjectIdSql(ctx), "act_user", " ");
|
|
1276
|
+
const instances = activeInstanceChecks(ctx, scope, (name) => name === scope ? `m ->> 'id'` : `m -> 'within' ->> ${quoteLiteral(name)}`, (name) => `act_${name}`, " ", grantPermissionSql(grant));
|
|
1277
|
+
const filters = [
|
|
1278
|
+
` and (select ${qualified(ctx, HELPERS.tokenCurrent)}())`,
|
|
1279
|
+
` and m ->> 'scope' = ${quoteLiteral(scope)}`,
|
|
1280
|
+
` and m ->> 'id' is not null${narrow}${keyTenantLine(ctx, scope, claimTenant(ctx, scope))}`,
|
|
1281
|
+
` and case jsonb_typeof(m -> 'expires_at')
|
|
1282
|
+
when 'number' then (m ->> 'expires_at')::numeric > extract(epoch from now())
|
|
1283
|
+
else true
|
|
1284
|
+
end`,
|
|
1285
|
+
...claimKeptLines(ctx, " ", grantPermissionSql(grant)),
|
|
1286
|
+
...instances.filters.map((part) => ` and ${part}`)
|
|
1287
|
+
];
|
|
1288
|
+
const kind = kindFilterSql(ctx, "r.role", "m ->> 'via'");
|
|
1289
|
+
return [
|
|
1290
|
+
` select (m ->> 'id')::${type}`,
|
|
1291
|
+
` from ${membershipRows(ctx)}`,
|
|
1292
|
+
...user.joins,
|
|
1293
|
+
...instances.joins,
|
|
1294
|
+
` join ${qualified(ctx, "role_permissions")} rp on rp.role = r.role`,
|
|
1295
|
+
` where ${signedIn(ctx)}`,
|
|
1296
|
+
` and rp.grant_key = p_grant`,
|
|
1297
|
+
` and rp.scope = ${quoteLiteral(scope)}`,
|
|
1298
|
+
...kind === void 0 ? [] : [` and ${kind}`],
|
|
1299
|
+
...filters
|
|
1300
|
+
].join("\n");
|
|
1301
|
+
}
|
|
1224
1302
|
function claimBody(ctx, scope, type) {
|
|
1225
1303
|
const set = ctx.grantSet === true;
|
|
1226
1304
|
const narrow = narrowsTo(ctx, scope) ? `
|
|
@@ -1280,6 +1358,9 @@ function sourceRows(sources) {
|
|
|
1280
1358
|
function sourceUser(index) {
|
|
1281
1359
|
return `v_user_${String(index)}`;
|
|
1282
1360
|
}
|
|
1361
|
+
function memoizes(ctx) {
|
|
1362
|
+
return ctx.authorize === "database" && ctx.dialect === "supabase" && ctx.grantSet !== true && ctx.subjectId === void 0;
|
|
1363
|
+
}
|
|
1283
1364
|
function sqlBody(sql) {
|
|
1284
1365
|
return {
|
|
1285
1366
|
sql,
|
|
@@ -1297,6 +1378,39 @@ function sourcesBodyOf(sql, sources, user) {
|
|
|
1297
1378
|
* variables.
|
|
1298
1379
|
*/
|
|
1299
1380
|
function functionBody(body) {
|
|
1381
|
+
if (body.memo !== void 0) return `language plpgsql
|
|
1382
|
+
volatile
|
|
1383
|
+
security definer
|
|
1384
|
+
set search_path = ''
|
|
1385
|
+
as $$
|
|
1386
|
+
declare
|
|
1387
|
+
${[
|
|
1388
|
+
...body.vars,
|
|
1389
|
+
`v_user text := ${body.memo.user}::text;`,
|
|
1390
|
+
`v_key text := 'permdock.m.' || ${quoteLiteral(body.memo.scope)} || '.k' || (hashtext(p_grant) & 1023)::text;`,
|
|
1391
|
+
`v_disc text := md5(concat_ws('|',
|
|
1392
|
+
v_user,
|
|
1393
|
+
p_grant,
|
|
1394
|
+
coalesce((select auth.jwt()) ->> 'authz_ver', ''),
|
|
1395
|
+
coalesce(nullif(current_setting('permdock.m.gen', true), ''), '0'),
|
|
1396
|
+
statement_timestamp()::text,
|
|
1397
|
+
md5(coalesce((select auth.jwt())::text, ''))
|
|
1398
|
+
));`,
|
|
1399
|
+
`v_memo text := nullif(current_setting(v_key, true), '');`,
|
|
1400
|
+
`v_ids ${body.memo.type}[];`
|
|
1401
|
+
].map((line) => ` ${line}`).join("\n")}
|
|
1402
|
+
begin
|
|
1403
|
+
if v_memo is not null and (v_memo::jsonb ->> 'k') = v_disc then
|
|
1404
|
+
v_ids := array(select jsonb_array_elements_text(v_memo::jsonb -> 'ids')::${body.memo.type});
|
|
1405
|
+
else
|
|
1406
|
+
v_ids := array(
|
|
1407
|
+
${body.sql}
|
|
1408
|
+
);
|
|
1409
|
+
perform set_config(v_key, jsonb_build_object('k', v_disc, 'ids', to_jsonb(v_ids))::text, true);
|
|
1410
|
+
end if;
|
|
1411
|
+
return query select unnest(v_ids);
|
|
1412
|
+
end;
|
|
1413
|
+
$$;`;
|
|
1300
1414
|
if (body.vars.length === 0) return `language sql
|
|
1301
1415
|
stable
|
|
1302
1416
|
security definer
|
|
@@ -1726,6 +1840,7 @@ create trigger "permdock_custom_role_name_guard"
|
|
|
1726
1840
|
function callerFunctionsSql(ctx, custom, root, levelReach, forUser) {
|
|
1727
1841
|
const leveled = custom.levels === true;
|
|
1728
1842
|
const tenantType = tenantTypeOf(ctx);
|
|
1843
|
+
const volatility = forUser || !memoizes(ctx) ? "stable" : "volatile";
|
|
1729
1844
|
const rp = qualified(ctx, "role_permissions");
|
|
1730
1845
|
const keys = qualified(ctx, CUSTOM_ROLES.keys);
|
|
1731
1846
|
const perms = qualified(ctx, CUSTOM_ROLES.permissions);
|
|
@@ -1780,7 +1895,7 @@ ${raiseSql(" ", "42501", `'permdock: the caller may not manage roles in ' ||
|
|
|
1780
1895
|
create or replace function ${beyond}(${userParam}p_tenant ${tenantType}, p_scope text, p_scope_id text, p_allow text[], p_deny text[], p_include text[])
|
|
1781
1896
|
returns setof text
|
|
1782
1897
|
language plpgsql
|
|
1783
|
-
|
|
1898
|
+
${volatility}
|
|
1784
1899
|
security definer
|
|
1785
1900
|
set search_path = ''
|
|
1786
1901
|
as $$
|
|
@@ -1811,7 +1926,7 @@ revoke execute on function ${beyond}(${userArg}${tenantType}, text, text, text[]
|
|
|
1811
1926
|
create or replace function ${guard}(${userParam}p_tenant ${tenantType}, p_scope text, p_scope_id text, p_role text)
|
|
1812
1927
|
returns void
|
|
1813
1928
|
language plpgsql
|
|
1814
|
-
|
|
1929
|
+
${volatility}
|
|
1815
1930
|
security definer
|
|
1816
1931
|
set search_path = ''
|
|
1817
1932
|
as $$
|
|
@@ -2290,8 +2405,103 @@ revoke execute on function ${fn}(uuid) from public, anon;
|
|
|
2290
2405
|
grant execute on function ${fn}(uuid) to authenticated;`;
|
|
2291
2406
|
}
|
|
2292
2407
|
//#endregion
|
|
2408
|
+
//#region src/cli/rls/memo-generation.ts
|
|
2409
|
+
const BUMP = "permdock_bump_memo_generation";
|
|
2410
|
+
const TRIGGER = "permdock_memo_generation";
|
|
2411
|
+
function add(targets, table, columns = []) {
|
|
2412
|
+
const key = qualifySqlTable(table);
|
|
2413
|
+
const existing = targets.get(key);
|
|
2414
|
+
if (existing === void 0) {
|
|
2415
|
+
targets.set(key, {
|
|
2416
|
+
table,
|
|
2417
|
+
columns: columns.length === 0 ? void 0 : new Set(columns)
|
|
2418
|
+
});
|
|
2419
|
+
return;
|
|
2420
|
+
}
|
|
2421
|
+
if (existing.columns === void 0 || columns.length === 0) {
|
|
2422
|
+
targets.set(key, {
|
|
2423
|
+
table: existing.table,
|
|
2424
|
+
columns: void 0
|
|
2425
|
+
});
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
for (const column of columns) existing.columns.add(column);
|
|
2429
|
+
}
|
|
2430
|
+
function suspensionTargets(targets, row) {
|
|
2431
|
+
if (row === void 0) return;
|
|
2432
|
+
const columns = [...row.disabledAt === void 0 ? [] : [row.disabledAt], ...row.status === void 0 ? [] : [row.status]];
|
|
2433
|
+
add(targets, row.table, columns);
|
|
2434
|
+
}
|
|
2435
|
+
/**
|
|
2436
|
+
* The triggers that invalidate the memo when a write changes permitted ids
|
|
2437
|
+
* without changing a membership: the permission map, a custom role's grants and
|
|
2438
|
+
* a suspended user or scope. The hook's version triggers call the same bump.
|
|
2439
|
+
*/
|
|
2440
|
+
function memoGenerationSql(ctx) {
|
|
2441
|
+
if (!memoizes(ctx)) return "";
|
|
2442
|
+
const schema = helperSchema(ctx);
|
|
2443
|
+
const targets = /* @__PURE__ */ new Map();
|
|
2444
|
+
add(targets, `${schema}.role_permissions`);
|
|
2445
|
+
if (ctx.customRoles !== void 0) {
|
|
2446
|
+
add(targets, `${schema}.${CUSTOM_ROLES.permissions}`);
|
|
2447
|
+
add(targets, `${schema}.${CUSTOM_ROLES.includes}`);
|
|
2448
|
+
const roles = ctx.customRoles.table;
|
|
2449
|
+
if (roles !== void 0) add(targets, roles.table, [
|
|
2450
|
+
roles.key,
|
|
2451
|
+
...roles.tenant === void 0 ? [] : [roles.tenant],
|
|
2452
|
+
...roles.scope === void 0 ? [] : [roles.scope]
|
|
2453
|
+
]);
|
|
2454
|
+
}
|
|
2455
|
+
suspensionTargets(targets, ctx.suspension?.users);
|
|
2456
|
+
for (const row of Object.values(ctx.suspension?.scopes ?? {})) suspensionTargets(targets, row);
|
|
2457
|
+
const bump = qualified(ctx, BUMP);
|
|
2458
|
+
const trigger = qualified(ctx, TRIGGER);
|
|
2459
|
+
return `-- a permission, custom-role or suspension write changes permitted ids inside the statement
|
|
2460
|
+
create or replace function ${bump}()
|
|
2461
|
+
returns void
|
|
2462
|
+
language sql
|
|
2463
|
+
volatile
|
|
2464
|
+
security definer
|
|
2465
|
+
set search_path = ''
|
|
2466
|
+
as $$
|
|
2467
|
+
select set_config(
|
|
2468
|
+
'permdock.m.gen',
|
|
2469
|
+
(coalesce(nullif(current_setting('permdock.m.gen', true), ''), '0')::int + 1)::text,
|
|
2470
|
+
true
|
|
2471
|
+
)
|
|
2472
|
+
$$;
|
|
2473
|
+
revoke execute on function ${bump}() from public, anon, authenticated;
|
|
2474
|
+
|
|
2475
|
+
create or replace function ${trigger}()
|
|
2476
|
+
returns trigger
|
|
2477
|
+
language plpgsql
|
|
2478
|
+
volatile
|
|
2479
|
+
security definer
|
|
2480
|
+
set search_path = ''
|
|
2481
|
+
as $$
|
|
2482
|
+
begin
|
|
2483
|
+
perform ${bump}();
|
|
2484
|
+
return null;
|
|
2485
|
+
end;
|
|
2486
|
+
$$;
|
|
2487
|
+
revoke execute on function ${trigger}() from public, anon, authenticated;
|
|
2488
|
+
${[...targets.values()].map(({ table, columns }) => {
|
|
2489
|
+
const target = quoteTable(qualifySqlTable(table));
|
|
2490
|
+
const update = columns === void 0 ? "update" : `update of ${[...columns].map((column) => quoteIdent(column)).join(", ")}`;
|
|
2491
|
+
return `drop trigger if exists ${quoteIdent(TRIGGER)} on ${target};
|
|
2492
|
+
create trigger ${quoteIdent(TRIGGER)}
|
|
2493
|
+
after insert or ${update} or delete on ${target}
|
|
2494
|
+
for each statement execute function ${trigger}();
|
|
2495
|
+
drop trigger if exists ${quoteIdent(`${TRIGGER}_truncate`)} on ${target};
|
|
2496
|
+
create trigger ${quoteIdent(`${TRIGGER}_truncate`)}
|
|
2497
|
+
after truncate on ${target}
|
|
2498
|
+
for each statement execute function ${trigger}();`;
|
|
2499
|
+
}).join("\n")}`;
|
|
2500
|
+
}
|
|
2501
|
+
//#endregion
|
|
2293
2502
|
//#region src/cli/rls/token-scopes.ts
|
|
2294
2503
|
const TOKEN_SCOPE_ALLOWS = "permdock_token_scope_allows";
|
|
2504
|
+
const TOKEN_SCOPE_MAP = "permdock_token_scope_map";
|
|
2295
2505
|
/**
|
|
2296
2506
|
* `rls.tokenScopes` as the SQL generator needs it, or `undefined` when it is
|
|
2297
2507
|
* off.
|
|
@@ -2329,11 +2539,22 @@ function tokenScopeRows(ctx) {
|
|
|
2329
2539
|
*/
|
|
2330
2540
|
function tokenScopeAllowsSql(ctx, plan, anonExecute) {
|
|
2331
2541
|
const fn = qualified(ctx, TOKEN_SCOPE_ALLOWS);
|
|
2542
|
+
const map = qualified(ctx, TOKEN_SCOPE_MAP);
|
|
2332
2543
|
const act = subjectClaimJsonSql(ctx, "act");
|
|
2333
2544
|
const grants = anonExecute ? `revoke execute on function ${fn}(text) from public;
|
|
2334
2545
|
grant execute on function ${fn}(text) to anon, authenticated;` : `revoke execute on function ${fn}(text) from public, anon;
|
|
2335
2546
|
grant execute on function ${fn}(text) to authenticated;`;
|
|
2336
|
-
return
|
|
2547
|
+
return `create or replace function ${map}()
|
|
2548
|
+
returns jsonb
|
|
2549
|
+
language sql
|
|
2550
|
+
immutable
|
|
2551
|
+
set search_path = ''
|
|
2552
|
+
as $$
|
|
2553
|
+
select ${quoteLiteral(JSON.stringify(plan.scopes))}::jsonb
|
|
2554
|
+
$$;
|
|
2555
|
+
revoke execute on function ${map}() from public, anon, authenticated;
|
|
2556
|
+
|
|
2557
|
+
-- Token scopes: a delegated token holds only the permissions its scope claim maps to; denies always apply, and a token without client_id or an agent act is not limited
|
|
2337
2558
|
create or replace function ${fn}(p_grant text)
|
|
2338
2559
|
returns boolean
|
|
2339
2560
|
language sql
|
|
@@ -2355,7 +2576,7 @@ as $$
|
|
|
2355
2576
|
select 1
|
|
2356
2577
|
from ${tokenScopeRows(ctx)}
|
|
2357
2578
|
where s.scope <> ''
|
|
2358
|
-
and coalesce(${
|
|
2579
|
+
and coalesce(${map}() -> s.scope, '[]'::jsonb)
|
|
2359
2580
|
? split_part(split_part(p_grant, '#', 1), '@', 1)
|
|
2360
2581
|
)
|
|
2361
2582
|
end
|
|
@@ -2412,6 +2633,31 @@ ${anonExecute ? `revoke execute on function ${fn}() from public;
|
|
|
2412
2633
|
grant execute on function ${fn}() to anon, authenticated;` : `revoke execute on function ${fn}() from public, anon;
|
|
2413
2634
|
grant execute on function ${fn}() to authenticated;`}`;
|
|
2414
2635
|
}
|
|
2636
|
+
function tokenCurrentSql(ctx, anonExecute) {
|
|
2637
|
+
const fn = qualified(ctx, HELPERS.tokenCurrent);
|
|
2638
|
+
const version = qualified(ctx, AUTHZ_VERSION_TABLE);
|
|
2639
|
+
const grants = anonExecute ? `revoke execute on function ${fn}() from public;
|
|
2640
|
+
grant execute on function ${fn}() to anon, authenticated;` : `revoke execute on function ${fn}() from public, anon;
|
|
2641
|
+
grant execute on function ${fn}() to authenticated;`;
|
|
2642
|
+
return `create or replace function ${fn}()
|
|
2643
|
+
returns boolean
|
|
2644
|
+
language plpgsql
|
|
2645
|
+
stable
|
|
2646
|
+
security definer
|
|
2647
|
+
set search_path = ''
|
|
2648
|
+
as $$
|
|
2649
|
+
begin
|
|
2650
|
+
return coalesce((
|
|
2651
|
+
select to_jsonb(v.version) = ((select auth.jwt()) -> 'authz_ver')
|
|
2652
|
+
and coalesce((select auth.jwt()) -> 'memberships_truncated', 'false'::jsonb) <> 'true'::jsonb
|
|
2653
|
+
and jsonb_typeof((select auth.jwt()) -> 'memberships') = 'array'
|
|
2654
|
+
from ${version} v
|
|
2655
|
+
where v.user_id = ${subjectIdSql(ctx)}
|
|
2656
|
+
), false);
|
|
2657
|
+
end;
|
|
2658
|
+
$$;
|
|
2659
|
+
${grants}`;
|
|
2660
|
+
}
|
|
2415
2661
|
function helperFunction(ctx, name, returns, body, anonExecute) {
|
|
2416
2662
|
const fn = qualified(ctx, name);
|
|
2417
2663
|
const grants = anonExecute ? `revoke execute on function ${fn}(text) from public;
|
|
@@ -2531,6 +2777,7 @@ function helpersSql(ctx, rows, options) {
|
|
|
2531
2777
|
chunks.push(`create schema if not exists ${s};\nrevoke all on schema ${s} from public;\ngrant usage on schema ${s} to ${anonUsage ? "anon, authenticated" : "authenticated"};`);
|
|
2532
2778
|
}
|
|
2533
2779
|
if (ctx.dialect === "supabase") chunks.push(userIdSql(ctx, options.anonExecute === true));
|
|
2780
|
+
if (ctx.claimsFirst === true) chunks.push(tokenCurrentSql(ctx, options.anonExecute === true));
|
|
2534
2781
|
if (ctx.seeds === "view") chunks.push(seedViewSql(ctx, rows));
|
|
2535
2782
|
else chunks.push(`create table if not exists ${rp} (
|
|
2536
2783
|
role text not null,
|
|
@@ -2556,6 +2803,8 @@ revoke all on table ${ur} from anon, authenticated, public;`);
|
|
|
2556
2803
|
}
|
|
2557
2804
|
const custom = customRolesSql(ctx);
|
|
2558
2805
|
if (custom !== "") chunks.push(custom);
|
|
2806
|
+
const memoGeneration = memoGenerationSql(ctx);
|
|
2807
|
+
if (memoGeneration !== "") chunks.push(memoGeneration);
|
|
2559
2808
|
const anon = options.anonExecute === true;
|
|
2560
2809
|
const keys = ctx.apiKeys;
|
|
2561
2810
|
if (keys !== void 0) chunks.push(apiKeyAllowsSql(ctx, keys, anon));
|
|
@@ -2589,10 +2838,20 @@ revoke all on table ${ur} from anon, authenticated, public;`);
|
|
|
2589
2838
|
}
|
|
2590
2839
|
const globalRoles = globalRolesSql(ctx);
|
|
2591
2840
|
if (globalRoles !== "") chunks.push(globalRoles);
|
|
2592
|
-
|
|
2593
|
-
if (readers !== "") chunks.push(readers);
|
|
2841
|
+
chunks.push(roleReadersSql(ctx, options.permissions, options.trustedReaders));
|
|
2594
2842
|
return `${chunks.join("\n\n")}\n`;
|
|
2595
2843
|
}
|
|
2844
|
+
function memoBody(ctx, scope, type, body) {
|
|
2845
|
+
if (!memoizes(ctx)) return body;
|
|
2846
|
+
return {
|
|
2847
|
+
...body,
|
|
2848
|
+
memo: {
|
|
2849
|
+
type,
|
|
2850
|
+
scope,
|
|
2851
|
+
user: subjectIdSql(ctx)
|
|
2852
|
+
}
|
|
2853
|
+
};
|
|
2854
|
+
}
|
|
2596
2855
|
function grantBodies(ctx) {
|
|
2597
2856
|
const keys = ctx.apiKeys;
|
|
2598
2857
|
const scoped = ctx.tokenScopes !== void 0;
|
|
@@ -2613,21 +2872,23 @@ ${hasBody(ctx)}
|
|
|
2613
2872
|
ids: (scope) => {
|
|
2614
2873
|
const type = scopeTypeOf(ctx, scope);
|
|
2615
2874
|
const body = scopedBody(ctx, scope, type);
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2875
|
+
const sql = allows === void 0 ? body.sql : keys !== void 0 && scope === rootName(ctx) ? `${body.sql}\n union\n${serviceKeyIdsSql(ctx, keys, scope, type)}` : body.sql;
|
|
2876
|
+
return memoBody(ctx, scope, type, allows === void 0 ? {
|
|
2877
|
+
sql,
|
|
2878
|
+
vars: body.vars
|
|
2879
|
+
} : {
|
|
2619
2880
|
sql: set ? ` select ids.id, ids.grant_key
|
|
2620
2881
|
from (
|
|
2621
2882
|
${sql}
|
|
2622
2883
|
) ids(id, grant_key)
|
|
2623
2884
|
where ${allows}` : ceilingIdsSql(sql, allows),
|
|
2624
2885
|
vars: body.vars
|
|
2625
|
-
};
|
|
2886
|
+
});
|
|
2626
2887
|
}
|
|
2627
2888
|
};
|
|
2628
2889
|
}
|
|
2629
2890
|
function forUserContext(ctx) {
|
|
2630
|
-
const { apiKeys: _apiKeys, tokenScopes: _tokenScopes, ...unkeyed } = ctx;
|
|
2891
|
+
const { apiKeys: _apiKeys, tokenScopes: _tokenScopes, claimsFirst: _claimsFirst, ...unkeyed } = ctx;
|
|
2631
2892
|
return {
|
|
2632
2893
|
...unkeyed,
|
|
2633
2894
|
subjectId: "p_user",
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { D as Policy, N as PolicyVocabulary, en as Snapshot, yr as Principal } from "../policy-types-BI9C5Sp5.js";
|
|
2
2
|
import { u as Permission } from "../permission-types-CAY-GU7e.js";
|
|
3
3
|
import { a as OperationInput, t as Operation } from "../operations-Ci_rT6Uo.js";
|
|
4
|
-
import { a as PermDock } from "../permdock-
|
|
5
|
-
import { D as ConnectionOptions, T as Connection, f as InvalidSignatureError, i as OpenApiHooks, o as ProtectOptions, u as SnapshotQuery, v as discoverViaSignatureAgent, x as webBotAuthVerifier } from "../server-types-
|
|
6
|
-
import { a as ProtectTarget, n as FetchAdapterOptions, t as ContextReader } from "../fetch-adapter-
|
|
4
|
+
import { a as PermDock } from "../permdock-CsrvbzHk.js";
|
|
5
|
+
import { D as ConnectionOptions, T as Connection, f as InvalidSignatureError, i as OpenApiHooks, o as ProtectOptions, u as SnapshotQuery, v as discoverViaSignatureAgent, x as webBotAuthVerifier } from "../server-types-Bfl-IrzZ.js";
|
|
6
|
+
import { a as ProtectTarget, n as FetchAdapterOptions, t as ContextReader } from "../fetch-adapter-BlL-ZhHq.js";
|
|
7
7
|
import { RequestMiddleware, RequestMiddlewareAfterServer, createMiddleware } from "@tanstack/react-start";
|
|
8
8
|
//#region src/tanstack-start/create.d.ts
|
|
9
9
|
type TanStackStartPermDockOptions<TUser = unknown> = FetchAdapterOptions<Request, TUser>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { l as InvalidSignatureError, p as webBotAuthVerifier, u as discoverViaSignatureAgent } from "../evaluations-CNMVJVD6.js";
|
|
2
|
-
import { t as fetchAdapter } from "../fetch-adapter-
|
|
2
|
+
import { t as fetchAdapter } from "../fetch-adapter-4EB3cLgB.js";
|
|
3
3
|
import { createMiddleware } from "@tanstack/react-start";
|
|
4
4
|
//#region src/tanstack-start/create.ts
|
|
5
5
|
function createPermDock(policy, options) {
|
package/dist/terminal/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { D as Policy, N as PolicyVocabulary, Yn as Decision, qt as Instant, xr as Subject, yr as Principal } from "../policy-types-BI9C5Sp5.js";
|
|
2
2
|
import { u as Permission } from "../permission-types-CAY-GU7e.js";
|
|
3
|
-
import { a as PermDock } from "../permdock-
|
|
3
|
+
import { a as PermDock } from "../permdock-CsrvbzHk.js";
|
|
4
4
|
import { m as ApprovalStore } from "../types-BzxA2OAD.js";
|
|
5
5
|
import { a as ProblemDetails, t as ApprovalHint } from "../errors-OTE9u4Wk.js";
|
|
6
|
-
import { t as InstanceOptions } from "../instance-options-
|
|
6
|
+
import { t as InstanceOptions } from "../instance-options-Cq66kEeR.js";
|
|
7
7
|
//#region src/terminal/types.d.ts
|
|
8
8
|
type TokenSourceName = "device" | "keychain" | "env" | "ci-oidc";
|
|
9
9
|
type TokenSource = TokenSourceName | {
|
package/dist/terminal/index.js
CHANGED
|
@@ -3,11 +3,11 @@ import { a as deniedMessage, i as approvalMessage, n as PermDockDeniedError, t a
|
|
|
3
3
|
import { h as secondsAt } from "../time-nR1JesoH.js";
|
|
4
4
|
import { r as isSubject } from "../subject-C7RddW0G.js";
|
|
5
5
|
import { n as resourceRef } from "../resource-ref-CaS9yVPi.js";
|
|
6
|
-
import { l as withApp } from "../permdock-
|
|
6
|
+
import { l as withApp } from "../permdock-DbAq8_Fp.js";
|
|
7
7
|
import { n as readBodyText } from "../body-text-DQhcmqdY.js";
|
|
8
8
|
import { l as storedApprovalToken, s as resumeDecision } from "../helpers-D-MXwkOF.js";
|
|
9
9
|
import { t as timeoutSignal } from "../timeout-D51niuQP.js";
|
|
10
|
-
import { n as resolveOrNull, t as buildInstance } from "../build-instance-
|
|
10
|
+
import { n as resolveOrNull, t as buildInstance } from "../build-instance-CkRKgjSj.js";
|
|
11
11
|
import { a as refreshCredential, o as revokeCredential, s as runDeviceFlow, t as TERMINAL_TIMEOUT_MS } from "../device-BwbJNmb2.js";
|
|
12
12
|
import { i as writeCredentials, n as deleteCredentials, r as readCredentials } from "../storage-C2bWdvJH.js";
|
|
13
13
|
import { createInterface } from "node:readline";
|
package/dist/testing/core.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { S as policyMatrix, _ as DescribePolicyConfig, a as OrmParityScenario, b as PolicyMatrixCell, c as RlsFieldsOutcome, d as RlsParityOptions, f as RlsParityReport, g as testRlsParity, h as RlsQueryResult, i as OrmParityRunInput, l as RlsParityCase, m as RlsQueryFn, n as OrmParityOptions, o as testOrmParity, p as RlsParitySubject, r as OrmParityReport, s as RlsDbOutcome, t as OrmParityCase, u as RlsParityFixture, v as MatrixCell, x as PolicyMatrixReport, y as MatrixOutcome } from "../core-
|
|
1
|
+
import { S as policyMatrix, _ as DescribePolicyConfig, a as OrmParityScenario, b as PolicyMatrixCell, c as RlsFieldsOutcome, d as RlsParityOptions, f as RlsParityReport, g as testRlsParity, h as RlsQueryResult, i as OrmParityRunInput, l as RlsParityCase, m as RlsQueryFn, n as OrmParityOptions, o as testOrmParity, p as RlsParitySubject, r as OrmParityReport, s as RlsDbOutcome, t as OrmParityCase, u as RlsParityFixture, v as MatrixCell, x as PolicyMatrixReport, y as MatrixOutcome } from "../core-9KbhurkH.js";
|
|
2
2
|
export { type DescribePolicyConfig, type MatrixCell, type MatrixOutcome, type OrmParityCase, type OrmParityOptions, type OrmParityReport, type OrmParityRunInput, type OrmParityScenario, type PolicyMatrixCell, type PolicyMatrixReport, type RlsDbOutcome, type RlsFieldsOutcome, type RlsParityCase, type RlsParityFixture, type RlsParityOptions, type RlsParityReport, type RlsParitySubject, type RlsQueryFn, type RlsQueryResult, policyMatrix, testOrmParity, testRlsParity };
|
package/dist/testing/core.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { r as policyMatrix, t as testOrmParity, n as testRlsParity } from "../core-
|
|
1
|
+
export { r as policyMatrix, t as testOrmParity, n as testRlsParity } from "../core-Dxkwz4xR.js";
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Ct as WhereCompiler, D as Policy, G as CredentialVerifier, X as DecisionSink, Y as DecisionProvider, Z as EntitlementSource, _t as TokenSigner, ct as RelationSource, dn as DeliveryChannel, en as Snapshot, it as MembershipSource, lt as SettingsSource, mt as SubjectResolver, nt as LimitStore, q as CustomRoleSource, ut as SnapshotSource, vr as Membership, vt as TokenVerifier, xr as Subject, yr as Principal } from "../policy-types-BI9C5Sp5.js";
|
|
2
2
|
import { g as ResourceInit, l as InferPermissionTree, u as Permission } from "../permission-types-CAY-GU7e.js";
|
|
3
3
|
import { r as Role } from "../vocabulary-DEJ5j4mR.js";
|
|
4
|
-
import { st as LegacyCheck } from "../index-
|
|
4
|
+
import { st as LegacyCheck } from "../index-tuR-kZoJ.js";
|
|
5
5
|
import { i as ApprovalPolicySource } from "../approval-policies-CKlByf5o.js";
|
|
6
|
-
import { _ as PrincipalSource, a as PermDock, b as Limits, h as PrincipalIdentity, u as SnapshotOptions, w as InstanceCache } from "../permdock-
|
|
6
|
+
import { _ as PrincipalSource, a as PermDock, b as Limits, h as PrincipalIdentity, u as SnapshotOptions, w as InstanceCache } from "../permdock-CsrvbzHk.js";
|
|
7
7
|
import { s as PolicySource } from "../hosted-yhyAuQkL.js";
|
|
8
8
|
import { a as ApprovalDelegationSource, m as ApprovalStore } from "../types-BzxA2OAD.js";
|
|
9
9
|
import { a as ProblemDetails } from "../errors-OTE9u4Wk.js";
|
|
10
|
-
import { c as ModelMap, t as AgentPermDock, u as ToolMap } from "../create-
|
|
10
|
+
import { c as ModelMap, t as AgentPermDock, u as ToolMap } from "../create-BQOQkYYg.js";
|
|
11
11
|
import { c as AccessReviewStore } from "../types-DZwEOsK1.js";
|
|
12
|
-
import { R as IdempotencyStore } from "../index-
|
|
12
|
+
import { R as IdempotencyStore } from "../index-Do7FqHEr.js";
|
|
13
13
|
import { n as RevocationFeed } from "../revocations-BaUXHM1N.js";
|
|
14
|
-
import { s as SupportSessionSource } from "../index-
|
|
14
|
+
import { s as SupportSessionSource } from "../index-DuOF7OqS.js";
|
|
15
15
|
import { n as VersionCache } from "../version-cache-q5cpaDSt.js";
|
|
16
16
|
import { r as SupabaseHookManifest } from "../manifest-B5yF3CIq.js";
|
|
17
17
|
import { t as supabaseMembershipsBudget } from "../budget-CNLsV2SL.js";
|
|
@@ -20,10 +20,10 @@ import { c as DeliveryTransport, g as TransportMessages } from "../types-p8mhWTc
|
|
|
20
20
|
import { t as CloudApproverOptions } from "../types--_lpWUGV.js";
|
|
21
21
|
import { n as ApprovalWaiter } from "../waiter-BjVI_Byg.js";
|
|
22
22
|
import { g as SetQueue, l as ReplayStore } from "../types-DBVSljAx.js";
|
|
23
|
-
import { r as SnapshotStorage } from "../types-
|
|
23
|
+
import { r as SnapshotStorage } from "../types-DjGZAU64.js";
|
|
24
24
|
import { x as DirectoryStore } from "../index-CLbGOPBr.js";
|
|
25
25
|
import { S as SsfStreamStore } from "../index--AwSBzJC.js";
|
|
26
|
-
import { S as policyMatrix, _ as DescribePolicyConfig, a as OrmParityScenario, b as PolicyMatrixCell, c as RlsFieldsOutcome, d as RlsParityOptions, f as RlsParityReport, g as testRlsParity, h as RlsQueryResult, i as OrmParityRunInput, l as RlsParityCase, m as RlsQueryFn, n as OrmParityOptions, o as testOrmParity, p as RlsParitySubject, r as OrmParityReport, s as RlsDbOutcome, t as OrmParityCase, u as RlsParityFixture, v as MatrixCell, x as PolicyMatrixReport, y as MatrixOutcome } from "../core-
|
|
26
|
+
import { S as policyMatrix, _ as DescribePolicyConfig, a as OrmParityScenario, b as PolicyMatrixCell, c as RlsFieldsOutcome, d as RlsParityOptions, f as RlsParityReport, g as testRlsParity, h as RlsQueryResult, i as OrmParityRunInput, l as RlsParityCase, m as RlsQueryFn, n as OrmParityOptions, o as testOrmParity, p as RlsParitySubject, r as OrmParityReport, s as RlsDbOutcome, t as OrmParityCase, u as RlsParityFixture, v as MatrixCell, x as PolicyMatrixReport, y as MatrixOutcome } from "../core-9KbhurkH.js";
|
|
27
27
|
import { a as SaasProject } from "../permissions-Bx6UI8n1.js";
|
|
28
28
|
import { n as saasPolicy } from "../policy-Dh9WVSVz.js";
|
|
29
29
|
import { expectTypeOf } from "vitest";
|