permdock 0.25.1 → 0.27.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/README.md +1 -1
- package/dist/2020-bJfT8aIA.js +6760 -0
- package/dist/a2a/index.d.ts +5 -9
- package/dist/a2a/index.js +13 -15
- package/dist/adapter-context-lHq_i_77.js +28 -0
- package/dist/adoption-scan-CMghLDUG.js +106 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/ai-sdk/index.d.ts +4 -6
- package/dist/ai-sdk/index.js +6 -7
- package/dist/annotate-doc-BCOCOrq_.js +214 -0
- package/dist/annotate-routes-BvSuEht3.js +75 -0
- package/dist/annotate-uZVGIRym.js +25 -0
- package/dist/app/index.d.ts +2 -103
- package/dist/app/index.js +1 -114
- package/dist/app-data-DbSPSPIl.js +62 -0
- package/dist/approval-header-BvszJE3l.js +25 -0
- package/dist/approval-normalize-Cpp8R0rY.js +190 -0
- package/dist/approval-prompt-C-vjNZyd.d.ts +57 -0
- package/dist/approval-prompt-Covyx_DB.js +60 -0
- package/dist/approval-required-B-R4Yw3J.js +5 -0
- package/dist/approvals/index.d.ts +5 -5
- package/dist/approvals/index.js +8 -8
- package/dist/approvals-7jHYXocE.js +1039 -0
- package/dist/approvers-BkY_ZfWl.js +76 -0
- package/dist/arazzo-B8heXoYy.js +76 -0
- package/dist/arazzo-DdJBVrsy.js +35 -0
- package/dist/args-0EWFk-4S.js +311 -0
- package/dist/astro/index.d.ts +6 -8
- package/dist/astro/index.js +3 -4
- package/dist/audience-DauhRBNg.js +54 -0
- package/dist/auth-WHKYWtnS.js +187 -0
- package/dist/authz-topic-D8x24Jv-.js +14 -0
- package/dist/authzen/index.d.ts +37 -22
- package/dist/authzen/index.js +69 -27
- package/dist/automation-CUcWz8uu.d.ts +122 -0
- package/dist/automation-CpPdFX91.js +157 -0
- package/dist/base-url--yJPQlIK.js +8 -0
- package/dist/better-auth/index.d.ts +2 -8
- package/dist/better-auth/index.js +10 -13
- package/dist/better-supabase/index.d.ts +141 -95
- package/dist/better-supabase/index.js +239 -794
- package/dist/better-supabase-DSbs4MtQ.js +201 -0
- package/dist/bind-B3MHrzw4.d.ts +56 -0
- package/dist/bind-up3QptTt.js +124 -0
- package/dist/body-W1_8r6Tw.js +9 -0
- package/dist/body-text-B-m3p-qY.js +55 -0
- package/dist/boundary--5Swp7sN.js +18 -0
- package/dist/boundary-DJqHADKu.d.ts +22 -0
- package/dist/budget-5LJ8kfZk.d.ts +12 -0
- package/dist/budget-BH81q2cj.js +19 -0
- package/dist/build-instance-hLKYe3-E.js +30 -0
- package/dist/canonical-json-BibZkXtE.js +28 -0
- package/dist/capability-CVt3lpVK.d.ts +128 -0
- package/dist/capability-_ZsyfYxU.js +204 -0
- package/dist/casbin-BHYVxJDD.js +29 -0
- package/dist/casbin-D33ZeUf5.js +241 -0
- package/dist/casl-CrltbDPa.js +23 -0
- package/dist/casl-D7n7yE-h.js +307 -0
- package/dist/catalog/index.d.ts +6 -20
- package/dist/catalog/index.js +13 -15
- package/dist/catalog-B3MJShnZ.js +51 -0
- package/dist/catalog-CgK_L4Qf.js +1 -0
- package/dist/catalog-DyC3LKc7.js +130 -0
- package/dist/catalog-doc-Bp5khmCG.js +352 -0
- package/dist/catalog-fingerprint-DAWZARy6.js +31 -0
- package/dist/catalog-operations-dxuOZr4J.js +59 -0
- package/dist/catalog-path-bG0XxHMu.js +11 -0
- package/dist/challenge-CjwmjcuX.js +518 -0
- package/dist/chat/index.d.ts +1 -1
- package/dist/chat/index.js +10 -13
- package/dist/chat-sdk/index.d.ts +3 -11
- package/dist/chat-sdk/index.js +7 -11
- package/dist/checks-DSm45qH7.js +71 -0
- package/dist/claims-map-BGbpbvGD.js +15 -0
- package/dist/claims-map-CLKQWxJG.d.ts +33 -0
- package/dist/claims-size-DcjhvUv5.js +58 -0
- package/dist/claude-agent/index.d.ts +3 -5
- package/dist/claude-agent/index.js +4 -5
- package/dist/clerk/index.d.ts +4 -8
- package/dist/clerk/index.js +7 -8
- package/dist/cli/bin.js +6 -7
- package/dist/cli/generate/watch-worker.d.ts +20 -0
- package/dist/cli/generate/watch-worker.js +69 -0
- package/dist/cli/index.d.ts +11 -20
- package/dist/cli/index.js +8 -8
- package/dist/cli/plugins/app.d.ts +24 -0
- package/dist/cli/plugins/app.js +36 -0
- package/dist/cli/plugins/better-supabase.d.ts +10 -0
- package/dist/cli/plugins/better-supabase.js +18 -0
- package/dist/cli/plugins/openapi.d.ts +19 -0
- package/dist/cli/plugins/openapi.js +40 -0
- package/dist/cli/plugins/powersync.d.ts +7 -0
- package/dist/cli/plugins/powersync.js +29 -0
- package/dist/cli/plugins/rls.d.ts +8 -0
- package/dist/cli/plugins/rls.js +27 -0
- package/dist/cli/plugins/schemas.d.ts +13 -0
- package/dist/cli/plugins/schemas.js +23 -0
- package/dist/cli/plugins/scim.d.ts +10 -0
- package/dist/cli/plugins/scim.js +32 -0
- package/dist/cli/plugins/supabase-hook.d.ts +13 -0
- package/dist/cli/plugins/supabase-hook.js +40 -0
- package/dist/cli/plugins/supabase.d.ts +27 -0
- package/dist/cli/plugins/supabase.js +69 -0
- package/dist/cli/plugins/ui.d.ts +11 -0
- package/dist/cli/plugins/ui.js +19 -0
- package/dist/client-V95IvZsF.d.ts +43 -0
- package/dist/client-subject-v89t811z.d.ts +25 -0
- package/dist/clients-Bb_33pRE.js +22 -0
- package/dist/clients-DGcyFDCc.d.ts +10 -0
- package/dist/cloud/index.d.ts +8 -26
- package/dist/cloud/index.js +22 -28
- package/dist/cloud-BmQrcTvx.js +85 -0
- package/dist/codemod-BpjMjxly.js +2159 -0
- package/dist/codemod-C_NKj01W.js +35 -0
- package/dist/collect-BJZsuBW4.js +535 -0
- package/dist/collect-CPvCXMQ-.js +1 -0
- package/dist/collect-CpGnmGpL.js +54 -0
- package/dist/command-9GAzSI7E.js +5 -0
- package/dist/compact-C4LFuqbW.js +28 -0
- package/dist/compare-dfHDj8kT.js +11 -0
- package/dist/compile/index.d.ts +2 -2
- package/dist/compile/index.js +1 -1
- package/dist/compile-BUKXrueE.js +685 -0
- package/dist/compile-D8c1nFGy.d.ts +118 -0
- package/dist/compile-Dy3zMRxo.js +724 -0
- package/dist/completion-CSncf6cX.js +150 -0
- package/dist/conditions-CkHgXoZB.js +385 -0
- package/dist/config-iyy90IOU.js +143 -0
- package/dist/config-report-D607UDnv.js +55 -0
- package/dist/config-shape-B6tdyBju.js +149 -0
- package/dist/config-xiX3R65I.js +25 -0
- package/dist/connection-BnoSqYU1.js +196 -0
- package/dist/connector-schema-BSRMyq4M.js +433 -0
- package/dist/constants-PCJiir_3.js +19 -0
- package/dist/context-DmH-Eyvx.js +95 -0
- package/dist/convex/index.d.ts +5 -9
- package/dist/convex/index.js +7 -8
- package/dist/core-CnC47rSf.d.ts +200 -0
- package/dist/core-DKqrD_xW.js +338 -0
- package/dist/coverage-DL7JCZmb.d.ts +133 -0
- package/dist/coverage-nFSMjFxH.js +42 -0
- package/dist/create-BAMPoEga.js +133 -0
- package/dist/create-BsRcXm_m.d.ts +125 -0
- package/dist/create-D3oXoXxM.js +373 -0
- package/dist/create-DeQ5t8mZ.d.ts +124 -0
- package/dist/create-sGl1ccTp.d.ts +185 -0
- package/dist/credential-ke0KMQeB.js +430 -0
- package/dist/credentials-6ZWbJ-Re.js +72 -0
- package/dist/credentials-BfzdL5kv.d.ts +123 -0
- package/dist/credentials-DOeqknte.js +309 -0
- package/dist/decide-set-CgNcE6pP.js +99 -0
- package/dist/deciding-columns-BnglEKqU.js +143 -0
- package/dist/decision-hHv4UZgy.js +20 -0
- package/dist/define-permdock-BLpQ0m95.d.ts +99 -0
- package/dist/define-permdock-CIxHBykk.js +148 -0
- package/dist/definition-options-9o8Hdww3.js +370 -0
- package/dist/delegation-BaUNCrE_.js +263 -0
- package/dist/delegation-input-7Y5Rlja7.js +18 -0
- package/dist/delivery/index.d.ts +4 -4
- package/dist/delivery/index.js +5 -5
- package/dist/delivery-Cb3VCij5.js +555 -0
- package/dist/delivery-event-D5b9yhaJ.js +39 -0
- package/dist/denied-text-D6JJTDr3.d.ts +20 -0
- package/dist/describe-B7EosIKA.js +100 -0
- package/dist/describe-lAafaRQQ.d.ts +43 -0
- package/dist/device-f3JEnqa0.js +195 -0
- package/dist/diff-BIqibFnm.js +464 -0
- package/dist/diff-n6LONVwL.js +36 -0
- package/dist/digest-BaP8bQzX.js +26 -0
- package/dist/digest-BcIZRYvp.d.ts +17 -0
- package/dist/doctor-BhoJiHi0.js +4847 -0
- package/dist/doctor-CoKSRLhf.js +53 -0
- package/dist/drizzle/index.d.ts +5 -9
- package/dist/drizzle/index.js +5 -6
- package/dist/elysia/index.d.ts +6 -8
- package/dist/elysia/index.js +6 -7
- package/dist/env-hbYumkRp.js +7 -0
- package/dist/errors-DOSkVeTC.js +127 -0
- package/dist/errors-DUJ7wLlE.d.ts +137 -0
- package/dist/errors-Da88YLm5.js +26 -0
- package/dist/errors-DgLOqc6j.js +148 -0
- package/dist/errors-KngVdJT9.d.ts +12 -0
- package/dist/evaluate-D8SdfP3h.js +1948 -0
- package/dist/evaluations-BQkpE7hC.js +609 -0
- package/dist/evaluations-K9qglDP7.d.ts +36 -0
- package/dist/evaluator-Dlhn2d7D.js +2 -0
- package/dist/evaluator-eager-UuJK6NX_.js +8 -0
- package/dist/eve/index.d.ts +11 -10
- package/dist/eve/index.js +7 -8
- package/dist/event-time-ChIrhzy5.js +26 -0
- package/dist/execute-CyQLisIB.js +166 -0
- package/dist/express/index.d.ts +6 -8
- package/dist/express/index.js +6 -7
- package/dist/fastify/index.d.ts +5 -11
- package/dist/fastify/index.js +6 -8
- package/dist/fetch-adapter-gmTCu4FR.d.ts +32 -0
- package/dist/fetch-adapter-ovZdSvlT.js +124 -0
- package/dist/fields-6d1j-q3c.js +502 -0
- package/dist/fields-C0L2FoZk.js +25 -0
- package/dist/files-DAR51W3J.js +157 -0
- package/dist/files-DuV7wRim.js +139 -0
- package/dist/fixtures-Bm0G0A7H.js +79 -0
- package/dist/flags-C0e-BzGW.js +112 -0
- package/dist/freeze-DGfJq_j2.js +86 -0
- package/dist/from-snapshot-CCDF_ihX.js +173 -0
- package/dist/gen-CJE3Xud5.js +1168 -0
- package/dist/gen-WzJbAcMJ.js +1 -0
- package/dist/gen-kind-DFQnQwFN.d.ts +13 -0
- package/dist/gen-kind-DGQxmID0.js +69 -0
- package/dist/generate-5_kz2309.js +305 -0
- package/dist/generate-DF6Y8ncI.js +67 -0
- package/dist/generate-DIZNzMuk.js +2339 -0
- package/dist/generate-DhP0jQDR.js +97 -0
- package/dist/generate-options-CLPUvgVW.js +1185 -0
- package/dist/grantee-BPUG6f0r.js +109 -0
- package/dist/grantee-conditions-Dob6QQAc.js +270 -0
- package/dist/grantee-match-CFQ-LRcL.js +147 -0
- package/dist/grants-BzjbUCdR.js +139 -0
- package/dist/graph-sql-Ds3nbevr.d.ts +27 -0
- package/dist/h3/index.d.ts +4 -6
- package/dist/h3/index.js +4 -5
- package/dist/headers-D1oRr-js.d.ts +8 -0
- package/dist/helpers-DSmj6SHi.js +533 -0
- package/dist/hono/index.d.ts +6 -8
- package/dist/hono/index.js +7 -8
- package/dist/hook-sql-FSets5NB.js +3412 -0
- package/dist/hosted-DMJKJPoc.js +361 -0
- package/dist/hosted-DUbuh0Td.d.ts +100 -0
- package/dist/http-BUIYu1Kc.d.ts +10 -0
- package/dist/http-BbX_Ou3_.js +48 -0
- package/dist/http-C9jDw_bZ.js +82 -0
- package/dist/http-dNltTpC8.js +71 -0
- package/dist/ids-0QDIxtxL.js +53 -0
- package/dist/import-BqoDHpFt.js +1158 -0
- package/dist/import-DemSCI1R.js +318 -0
- package/dist/index-BXz-XXC3.d.ts +1108 -0
- package/dist/index-CVuc3E1O.d.ts +196 -0
- package/dist/index-Cq9N5B92.d.ts +506 -0
- package/dist/index-D8A1d_Tt.d.ts +214 -0
- package/dist/index-DegTwZxD.d.ts +93 -0
- package/dist/index-O0qbI8Ha.d.ts +221 -0
- package/dist/index.d.ts +24 -25
- package/dist/index.js +47 -46
- package/dist/init-BlYRZRnQ.js +94 -0
- package/dist/init-CgoOwXtk.js +95 -0
- package/dist/instance-options-B4MD2wgl.d.ts +9 -0
- package/dist/instance-options-CLErhA76.js +23 -0
- package/dist/instance-snapshot-DdGOpSfN.js +716 -0
- package/dist/instant-Ih5riY_A.js +18 -0
- package/dist/interactive-only-BZu9rLpa.js +1567 -0
- package/dist/internals-D58TnmDB.js +19 -0
- package/dist/json-schema-SDkWXxhu.d.ts +38 -0
- package/dist/json-schema-jtX26ydD.js +148 -0
- package/dist/jwt/index.d.ts +6 -24
- package/dist/jwt/index.js +18 -26
- package/dist/kernel-Dn6pKMAF.js +423 -0
- package/dist/kysely/index.d.ts +5 -9
- package/dist/kysely/index.js +5 -6
- package/dist/lazy-provider-CydlnKkS.d.ts +4 -0
- package/dist/lazy-provider-DG5rMeqL.js +28 -0
- package/dist/limits-DpTxX6N4.js +166 -0
- package/dist/live-options-CIUmc-YQ.js +70 -0
- package/dist/load-BPzIqlGB.js +1 -0
- package/dist/load-CZnlAyZ8.js +98 -0
- package/dist/load-jose-CjzIBSKI.js +7 -0
- package/dist/login-CNQJN8Fy.js +67 -0
- package/dist/login-TwrSjf6k.js +255 -0
- package/dist/lru-Cp-AEvpR.js +27 -0
- package/dist/manifest-B-8d2lhG.js +45 -0
- package/dist/manifest-CRHphHxo.d.ts +362 -0
- package/dist/manifest-XIXxXYty.js +399 -0
- package/dist/manifest-json-DMaBWmcG.js +8 -0
- package/dist/manifest-schema-DJY5Q_pR.js +507 -0
- package/dist/map-claims-BKdnPwep.js +386 -0
- package/dist/map-error-DTi_JZT8.js +22 -0
- package/dist/markers-C-kThnKN.js +79 -0
- package/dist/may-use-Died1tNU.js +233 -0
- package/dist/mcp/index.d.ts +11 -21
- package/dist/mcp/index.js +56 -43
- package/dist/membership-filter-CSKH48eD.js +66 -0
- package/dist/migrate-CmTMk7rd.js +536 -0
- package/dist/model-B4EKVHMK.js +188 -0
- package/dist/module-values-Ddx0GLaJ.js +106 -0
- package/dist/nest/index.d.ts +7 -13
- package/dist/nest/index.js +12 -15
- package/dist/next/client.d.ts +1 -3
- package/dist/next/client.js +2 -3
- package/dist/next/index.d.ts +36 -16
- package/dist/next/index.js +161 -31
- package/dist/next/plugin.d.ts +1 -3
- package/dist/next/plugin.js +3 -4
- package/dist/node/index.d.ts +6 -8
- package/dist/node/index.js +4 -5
- package/dist/oauth-security-C8fjzFRF.js +25 -0
- package/dist/ocsf-DKRQc6uv.js +135 -0
- package/dist/openai/index.d.ts +5 -7
- package/dist/openai/index.js +5 -6
- package/dist/openapi/index.d.ts +4 -16
- package/dist/openapi/index.js +4 -3
- package/dist/openapi-CH9Dh5UX.js +260 -0
- package/dist/openapi-CrCBEFEm.js +95 -0
- package/dist/openapi-D2dmyWZK.js +411 -0
- package/dist/openapi-document-CJO6cUS1.js +35 -0
- package/dist/operation-findings-D5Uo-dcm.js +35 -0
- package/dist/operation-risks-BD-j14dj.js +12 -0
- package/dist/operations-B0yO77Zz.js +290 -0
- package/dist/operations-BS8ExH5A.d.ts +58 -0
- package/dist/operations-De3F7tlf.js +88 -0
- package/dist/optional-CaQWp9HA.js +46 -0
- package/dist/orpc/index.d.ts +8 -12
- package/dist/orpc/index.js +10 -12
- package/dist/otel/index.d.ts +3 -5
- package/dist/otel/index.js +5 -7
- package/dist/output-CU7OppLv.js +244 -0
- package/dist/output-files-C5LFnQa4.js +1 -0
- package/dist/output-files-DNid6TBl.js +197 -0
- package/dist/ownership-BBQe7GZp.js +558 -0
- package/dist/parse-local-manifest-BGLWVchi.d.ts +8 -0
- package/dist/parse-local-manifest-CfMjZAFi.js +67 -0
- package/dist/parse-nfHSt1Wy.js +149 -0
- package/dist/parse-request-IEEzVFM8.js +24 -0
- package/dist/parse-sink-events-B6nZx41L.js +125 -0
- package/dist/paths-CeS_gpHf.js +44 -0
- package/dist/pdp/index.d.ts +3 -9
- package/dist/pdp/index.js +22 -18
- package/dist/peer-BWTpSLs2.js +1 -0
- package/dist/peer-D77JpXe-.js +978 -0
- package/dist/perf-token-dFGVP14-.js +155 -0
- package/dist/permdock-BueSeg7X.js +1514 -0
- package/dist/permdock-Dz3yzWrp.d.ts +853 -0
- package/dist/permission-registry-DMYRZVcn.js +413 -0
- package/dist/permissions-CQW3cr2S.js +17 -0
- package/dist/permissions-DWULToSb.d.ts +52 -0
- package/dist/permissions-ijDw4sO1.js +144 -0
- package/dist/pg-CA651850.js +59 -0
- package/dist/pins-CXXkVEiD.js +14 -0
- package/dist/pipeline-CXuwijr2.js +307 -0
- package/dist/pkce-DdsRBK7n.js +20 -0
- package/dist/plugin-1XW5OfAZ.d.ts +221 -0
- package/dist/plugin-MQVfUBUS.js +93 -0
- package/dist/plugin-outputs-BE2YCiMj.js +28 -0
- package/dist/policy-C-Lzp3Zh.d.ts +18 -0
- package/dist/policy-DFD2J5o_.js +476 -0
- package/dist/policy-FrCL4wDQ.js +37 -0
- package/dist/policy-bundle-1Znzdxse.js +82 -0
- package/dist/policy-from-catalog-YKaTeaco.js +452 -0
- package/dist/policy-module-Bp4HvsRg.js +107 -0
- package/dist/policy-types-93NwI8iI.d.ts +2855 -0
- package/dist/postgres-store-CYFvw98w.js +1023 -0
- package/dist/postgrest-DyrYo_XT.d.ts +138 -0
- package/dist/powersync-DVgkPQKM.js +1 -0
- package/dist/powersync-Y-_z8V5X.js +40 -0
- package/dist/powersync-pbvC5g6K.js +1630 -0
- package/dist/preset/index.d.ts +0 -12
- package/dist/preset/index.js +1 -1
- package/dist/preset-BcFDaeqd.js +1849 -0
- package/dist/principal-source-BIcukkB3.js +102 -0
- package/dist/prisma/index.d.ts +4 -12
- package/dist/prisma/index.js +10 -14
- package/dist/problem-BZB7zPC7.js +202 -0
- package/dist/problem-details-EJHcvYCz.js +154 -0
- package/dist/problem-types-81BEw0IN.js +7 -0
- package/dist/prompt-CSXHcJxy.js +931 -0
- package/dist/protected-action-BMb0ftEu.js +241 -0
- package/dist/protected-action-D6T3eJyW.d.ts +73 -0
- package/dist/protected-action-DiXulRVj.js +78 -0
- package/dist/provider-BnnFjtWI.js +893 -0
- package/dist/provider-ClD4rfgT.js +11 -0
- package/dist/provider-CydlnKkS.d.ts +4 -0
- package/dist/provider-store-atQUfsVO.js +51 -0
- package/dist/provider-with-CSw4mBDU.js +70 -0
- package/dist/public-api-DIMZmzWi.js +5579 -0
- package/dist/pull-C3_fCkgX.js +1 -0
- package/dist/pull-CpLyeY2p.js +252 -0
- package/dist/push-Cb7PqXdO.js +158 -0
- package/dist/pushed-policy-pH-EFWyx.d.ts +61 -0
- package/dist/pushed-policy-rpB6k77P.js +240 -0
- package/dist/quote-BKrTBbcH.js +36 -0
- package/dist/rbac-B-49toAp.js +90 -0
- package/dist/react/index.d.ts +10 -9
- package/dist/react/index.js +8 -7
- package/dist/react/lazy.d.ts +10 -12
- package/dist/react/lazy.js +8 -35
- package/dist/react/provider-client-lazy.d.ts +2 -0
- package/dist/react/provider-client-lazy.js +2 -0
- package/dist/react/provider-client.d.ts +1 -1
- package/dist/react/provider-client.js +1 -1
- package/dist/react-native/index.d.ts +12 -30
- package/dist/react-native/index.js +31 -41
- package/dist/read-memberships-BkePIa1F.js +63 -0
- package/dist/refresh-on-C1zIMtJr.d.ts +47 -0
- package/dist/refresh-online-CYGZNo6V.js +19 -0
- package/dist/refresh-online-vtUfV6dk.d.ts +10 -0
- package/dist/refs-Cix9Zjis.js +103 -0
- package/dist/relation-walk-BlWy9gBK.js +188 -0
- package/dist/relations-CIgB5KPJ.js +162 -0
- package/dist/replay-ClGIMp5p.d.ts +3 -0
- package/dist/replay-X2m6moK1.js +28 -0
- package/dist/request-context-CVJodWx8.js +70 -0
- package/dist/request-context-E3-ps-H_.d.ts +3 -0
- package/dist/request-schema-DzEoR310.js +155 -0
- package/dist/resend/index.d.ts +4 -10
- package/dist/resend/index.js +14 -17
- package/dist/resolve-names-Ca4ClMU2.js +266 -0
- package/dist/resolver-kdZ4HrpC.js +404 -0
- package/dist/resource-ref-BiQtFK-I.js +19 -0
- package/dist/resource-relations-Ck5sjYQR.js +251 -0
- package/dist/retire-BNiXnbBR.js +248 -0
- package/dist/revocations-3jyzniOz.js +26 -0
- package/dist/revocations-ku_f2d2y.d.ts +24 -0
- package/dist/rls-CmyxiQsS.js +321 -0
- package/dist/rls-DY5ITGzf.js +946 -0
- package/dist/rls-files-BtaUXVp-.js +114 -0
- package/dist/rls-options-CEpg5nDP.d.ts +26 -0
- package/dist/role-builder-DhsGEVq-.js +501 -0
- package/dist/role-grants-Bk6ZsaS0.js +46 -0
- package/dist/roles-B29psCem.js +29 -0
- package/dist/rolldown-runtime-B8NLbhFH.js +3 -0
- package/dist/row-conditions-DwIJocfQ.js +27 -0
- package/dist/row-pair-CxEhErJU.js +33 -0
- package/dist/rpc-B-4IZOiU.js +111 -0
- package/dist/rpc-DjgxFbjK.d.ts +18 -0
- package/dist/run-BoVUFspr.js +726 -0
- package/dist/run-BriRChKE.js +1 -0
- package/dist/run-ticket-D6T39Xdi.js +370 -0
- package/dist/run-ticket-DXwrko2J.d.ts +157 -0
- package/dist/runtime-Cl6xSbEq.js +13 -0
- package/dist/saas-DzjKUQr5.js +1218 -0
- package/dist/scan-C4x8UqS7.js +28 -0
- package/dist/schema-BeY3croo.js +403 -0
- package/dist/schema-Zfpbku8U.js +133 -0
- package/dist/scim/index.d.ts +2 -2
- package/dist/scim/index.js +2 -2
- package/dist/scim-B9QyJ23q.js +1046 -0
- package/dist/scopes-B-KX9EI8.js +238 -0
- package/dist/seed-sql-CjF7u0aX.js +60 -0
- package/dist/seeds/index.d.ts +2 -0
- package/dist/seeds/index.js +1 -0
- package/dist/seeds-BDTG7xl-.js +53 -0
- package/dist/seeds-uG196Ev4.d.ts +73 -0
- package/dist/server/index.d.ts +13 -13
- package/dist/server/index.js +14 -14
- package/dist/server-Co9CYGqk.js +146 -0
- package/dist/server-types-BrHOGAYx.d.ts +318 -0
- package/dist/sha256-DFsnyVPo.js +157 -0
- package/dist/shared-BOsJIQf4.js +124 -0
- package/dist/shared-BdF5DJDQ.js +330 -0
- package/dist/signals-a1NxAP0X.js +31 -0
- package/dist/sink-BD34OS8T.d.ts +247 -0
- package/dist/sink-Bgvf9lIz.js +966 -0
- package/dist/size-DF7xQ-nH.js +95 -0
- package/dist/skills-B0cLRZ7w.js +202 -0
- package/dist/skills-DiGdMvMw.js +50 -0
- package/dist/snapshot-DckMnHk8.js +352 -0
- package/dist/snapshot-cache-DTTEfmxv.js +69 -0
- package/dist/snapshot-cache-DoP3avLl.d.ts +68 -0
- package/dist/snapshot-compact-CwAop_6C.js +119 -0
- package/dist/snapshot-empty-DZ6sZ83n.js +17 -0
- package/dist/snapshot-evaluate-9RGy7J3N.js +552 -0
- package/dist/snapshot-reads-D775amTL.js +65 -0
- package/dist/snapshot-size-D-pCR8x0.js +139 -0
- package/dist/snapshot-size-DU7CvpMt.js +1 -0
- package/dist/solid/index.d.ts +18 -20
- package/dist/solid/index.js +15 -19
- package/dist/solid-start/index.d.ts +6 -8
- package/dist/solid-start/index.js +4 -5
- package/dist/sources-BbSUNmFX.js +10 -0
- package/dist/sources-DnjJPGfb.js +657 -0
- package/dist/sources-NQio1yFq.d.ts +727 -0
- package/dist/sql-BYYNi1lu.d.ts +8 -0
- package/dist/sql-T4GaBh9X.js +93 -0
- package/dist/src-D6_T4zd7.js +1811 -0
- package/dist/ssf/index.d.ts +3 -3
- package/dist/ssf/index.js +20 -31
- package/dist/standard-webhooks-B3MQihcP.d.ts +86 -0
- package/dist/standard-webhooks-BtIkXclH.js +227 -0
- package/dist/storage-BhGDhsXm.js +131 -0
- package/dist/store-AH8bmaxW.js +377 -0
- package/dist/store-core-eqG8jijs.d.ts +306 -0
- package/dist/store-options-C8x39AHa.js +1034 -0
- package/dist/stores-4DOaL4ZP.d.ts +58 -0
- package/dist/stores-DoA7ACkz.js +127 -0
- package/dist/stream-DdF94h7T.js +73 -0
- package/dist/style-CQDaLJtP.js +24 -0
- package/dist/style-Crf-90o6.js +1 -0
- package/dist/subject-DkxY-AhF.js +23 -0
- package/dist/subject-cache-BZeSj4Xf.d.ts +156 -0
- package/dist/subject-settings-BO-frcYx.js +147 -0
- package/dist/subject-settings-C9F1sU1d.d.ts +48 -0
- package/dist/supabase/client.d.ts +1 -1
- package/dist/supabase/client.js +2 -3
- package/dist/supabase/index.d.ts +77 -24
- package/dist/supabase/index.js +9 -8
- package/dist/supabase/middleware.d.ts +27 -9
- package/dist/supabase/middleware.js +51 -21
- package/dist/supabase-B7Q5bO-P.js +30 -0
- package/dist/supabase-BI5ZhzLl.js +792 -0
- package/dist/supabase-config-mXcggV5I.js +890 -0
- package/dist/supabase-hook-C7FNwQ1p.js +2 -0
- package/dist/supabase-hook-loL2iJVb.js +405 -0
- package/dist/supabase-outcome-CMLuLW-V.js +9 -0
- package/dist/supautils-DXzJ2E2Q.js +96 -0
- package/dist/support-session-B8xrW28B.js +157 -0
- package/dist/svelte/index.d.ts +8 -10
- package/dist/svelte/index.js +12 -15
- package/dist/svelte/runtime.d.ts +4 -6
- package/dist/svelte/runtime.js +4 -4
- package/dist/svelte/source.d.ts +8 -10
- package/dist/svelte/source.js +6 -7
- package/dist/sveltekit/index.d.ts +6 -8
- package/dist/sveltekit/index.js +3 -4
- package/dist/tables-C8IwkTHq.js +3249 -0
- package/dist/tanstack-start/index.d.ts +6 -8
- package/dist/tanstack-start/index.js +3 -4
- package/dist/target-BGpxgKsN.js +50 -0
- package/dist/tenancy-B5Xxt9Sc.js +223 -0
- package/dist/terminal/index.d.ts +6 -16
- package/dist/terminal/index.js +18 -23
- package/dist/testing/core.d.ts +1 -1
- package/dist/testing/core.js +1 -1
- package/dist/testing/fixtures/index.d.ts +12 -10
- package/dist/testing/fixtures/index.js +48 -25
- package/dist/testing/index.d.ts +85 -85
- package/dist/testing/index.js +226 -115
- package/dist/testing/saas/index.d.ts +5 -15
- package/dist/testing/saas/index.js +2 -2
- package/dist/testing/saas/permissions.d.ts +1 -1
- package/dist/testing/saas/permissions.js +1 -1
- package/dist/text-D704xHVl.js +7 -0
- package/dist/text-diff-CsglY49A.js +440 -0
- package/dist/thenable-BxMy2v8w.js +39 -0
- package/dist/time-r0CKBm57.js +94 -0
- package/dist/timeout-nOqLpU2I.js +7 -0
- package/dist/token-BgswTQzt.d.ts +9 -0
- package/dist/token-CSljQqzA.js +76 -0
- package/dist/tool-refusal-DzCSbjp8.js +43 -0
- package/dist/trpc/index.d.ts +7 -9
- package/dist/trpc/index.js +7 -8
- package/dist/type-helpers-DHCQEPj8.d.ts +47 -0
- package/dist/types-3pRMqcvw.d.ts +84 -0
- package/dist/types-BFtFaI1W.d.ts +66 -0
- package/dist/types-BdNdMix7.d.ts +263 -0
- package/dist/types-C7QtRn3n.d.ts +66 -0
- package/dist/types-CVCRFYY_.d.ts +102 -0
- package/dist/types-CWmBZtQN.d.ts +274 -0
- package/dist/types-Cakw89Wx.d.ts +372 -0
- package/dist/types-D3tjoLwT.d.ts +124 -0
- package/dist/types-DFZKovb3.js +77 -0
- package/dist/types-DONLJQjY.d.ts +134 -0
- package/dist/types-OzSal_K_.d.ts +178 -0
- package/dist/types-XSfi6ihL.d.ts +65 -0
- package/dist/types-nXo_oQYk.d.ts +1235 -0
- package/dist/unplugin/index.d.ts +1 -3
- package/dist/unplugin/index.js +3 -4
- package/dist/usage-BgNAgZfj.js +31 -0
- package/dist/usage-D6HUlfvP.js +1 -0
- package/dist/usage-llSQehNg.js +761 -0
- package/dist/validation-error-BAO1W1yk.d.ts +27 -0
- package/dist/validation-error-CgDOA6VS.js +35 -0
- package/dist/validity-YNEEm2MZ.js +56 -0
- package/dist/verifier-BIYkGcJc.js +530 -0
- package/dist/verify-nMTdEqBB.js +1102 -0
- package/dist/version-CU6e2wxV.js +7 -0
- package/dist/version-D-jWyJb9.js +46 -0
- package/dist/version-DcZCjWXb.js +1 -0
- package/dist/version-cache-BXkl7-Fz.js +462 -0
- package/dist/views-Dpr1uB16.js +164 -0
- package/dist/vocabulary-CE2k7s1a.js +157 -0
- package/dist/vocabulary-FYgI_NoI.d.ts +400 -0
- package/dist/vue/index.d.ts +18 -20
- package/dist/vue/index.js +13 -18
- package/dist/waiter-DKdFHKVZ.js +66 -0
- package/dist/waiter-hYLJXA7r.d.ts +37 -0
- package/dist/watch-BecZtEdU.js +155 -0
- package/dist/watch-CiN6WU9k.js +221 -0
- package/dist/watch-NAUnUXph.js +1 -0
- package/dist/webmcp/index.d.ts +2 -6
- package/dist/webmcp/index.js +8 -9
- package/dist/who-can-rUSZfLvI.js +366 -0
- package/dist/wire-delegation-DC5Cyec4.js +35 -0
- package/dist/wire-denial-BcRQnA7p.js +26 -0
- package/dist/workflow/index.d.ts +3 -3
- package/dist/workflow/index.js +12 -14
- package/dist/workflow-sdk/index.d.ts +6 -8
- package/dist/workflow-sdk/index.js +2 -3
- package/dist/wrap-CsfsaJhd.js +32 -0
- package/dist/wrap-D-KvhzaC.d.ts +16 -0
- package/package.json +83 -39
- package/schemas/catalog-v2.json +665 -0
- package/schemas/cli-commands-v1.json +1 -1
- package/schemas/cli-result-v2.json +163 -0
- package/schemas/cloud-api-v1.json +1 -1
- package/schemas/snapshot-v1.json +26 -0
- package/schemas/supabase-claims-v1.json +5 -1
- package/schemas/supabase-manifest-v1.json +11 -2
- package/skills/permdock/SKILL.md +1 -1
- package/skills/permdock-data/references/queries-and-rls.md +2 -1
- package/skills/permdock-wire/references/adapters.md +5 -3
- package/dist/2020-CJbO8Bvz.js +0 -6773
- package/dist/active-tenant-DVee32-T.js +0 -39
- package/dist/adapter-context-OHikyRqV.js +0 -29
- package/dist/adoption-scan-8F9VSQrK.js +0 -107
- package/dist/app-J9PE1LNm.js +0 -24
- package/dist/app-data-UNNm07jV.js +0 -63
- package/dist/approval-header-8QV6MU4H.js +0 -26
- package/dist/approval-normalize-KfhzpD93.js +0 -196
- package/dist/approval-policies-BiXMlYBu.d.ts +0 -138
- package/dist/approval-prompt-B8hQY69x.js +0 -61
- package/dist/approval-prompt-j5PTItiy.d.ts +0 -59
- package/dist/approval-required-TzNB9oQA.js +0 -6
- package/dist/approvals-BfzI8Foe.js +0 -1048
- package/dist/approvers-BaNwKYgd.js +0 -77
- package/dist/arazzo-BUVqRmaJ.js +0 -36
- package/dist/arazzo-CWmM8pWw.js +0 -77
- package/dist/args-iafbHiXn.js +0 -311
- package/dist/audience-DLoopY4q.js +0 -55
- package/dist/auth-BxXHxWRy.js +0 -189
- package/dist/authz-topic-Dbc-HDOS.js +0 -15
- package/dist/automation-BueW05db.js +0 -158
- package/dist/automation-_iGeP54L.d.ts +0 -124
- package/dist/base-url-BQbddZO5.js +0 -9
- package/dist/better-supabase-DF8f8oly.js +0 -194
- package/dist/bind-CTj4dHc1.d.ts +0 -58
- package/dist/bind-LQ6zbARV.js +0 -125
- package/dist/body-Cy9S8zhw.js +0 -10
- package/dist/body-text-DQhcmqdY.js +0 -56
- package/dist/boundary-BV3O1eud.js +0 -19
- package/dist/boundary-C9ck-3uK.d.ts +0 -24
- package/dist/budget-BBCPDOGP.js +0 -14
- package/dist/budget-CNLsV2SL.d.ts +0 -14
- package/dist/build-instance-Bq8wkJ4i.js +0 -31
- package/dist/canonical-json-DwilZ1iB.js +0 -29
- package/dist/capability-CenWwTMR.js +0 -205
- package/dist/capability-DqCyFGip.d.ts +0 -130
- package/dist/casbin-DIvUMac7.js +0 -242
- package/dist/casbin-qpG_ZphP.js +0 -30
- package/dist/casl-CjBVJj8R.js +0 -24
- package/dist/casl-CkBssiB1.js +0 -308
- package/dist/catalog-B1MAmRQI.js +0 -131
- package/dist/catalog-BCVIH7kq.js +0 -1
- package/dist/catalog-CaZoXBD8.js +0 -52
- package/dist/catalog-doc-DnQDviXY.js +0 -353
- package/dist/catalog-fingerprint-e6aCWosn.js +0 -157
- package/dist/catalog-operations-Do1eD-Rt.js +0 -60
- package/dist/catalog-path-CnI0XTFK.js +0 -12
- package/dist/challenge-DKJpP-5P.js +0 -521
- package/dist/checks-fyDOhcz0.js +0 -72
- package/dist/claims-map-CKkoAAYF.js +0 -16
- package/dist/claims-map-D1Pb5oRq.d.ts +0 -35
- package/dist/client-JK504UCq.d.ts +0 -45
- package/dist/clients-C_NOET3z.d.ts +0 -12
- package/dist/clients-DYr3U86j.js +0 -23
- package/dist/cloud-CXgE1qpa.js +0 -86
- package/dist/codemod-BJ0Kgv9b.js +0 -36
- package/dist/codemod-DjgVx3RQ.js +0 -2800
- package/dist/collect-BG-SXFQv.js +0 -537
- package/dist/collect-CxPJRjoc.js +0 -55
- package/dist/collect-ZLgHgujd.js +0 -1
- package/dist/command-L8EstFNm.js +0 -6
- package/dist/compact-CAf557ZB.js +0 -29
- package/dist/compare-DTfyUunF.js +0 -12
- package/dist/compile-Cvru58id.js +0 -661
- package/dist/compile-Dh9pW_Co.d.ts +0 -120
- package/dist/completion-DUHSRdoQ.js +0 -152
- package/dist/config-CgA_Z5Ts.js +0 -26
- package/dist/config-DC7aiuhP.js +0 -116
- package/dist/config-report-B31MnuKf.js +0 -56
- package/dist/config-shape-ChhsuGSV.js +0 -147
- package/dist/connection-zoAgwdsD.js +0 -197
- package/dist/connector-schema-CYLQNMYq.js +0 -434
- package/dist/constants-DcJABbLW.js +0 -20
- package/dist/context-BXM0MDB0.js +0 -95
- package/dist/core-BTJlqWsv.js +0 -341
- package/dist/core-BhZEo5Le.d.ts +0 -206
- package/dist/coverage-BuGlwUms.d.ts +0 -135
- package/dist/coverage-CGu_Kovx.js +0 -261
- package/dist/create--q7-j0hX.d.ts +0 -127
- package/dist/create-C5IQw_-i.d.ts +0 -191
- package/dist/create-CYj0cjTu.d.ts +0 -128
- package/dist/create-D7D94oNh.js +0 -376
- package/dist/create-DaddhCIg.js +0 -134
- package/dist/credential-BMsbcaeP.js +0 -431
- package/dist/credentials-BZU7Twpt.js +0 -310
- package/dist/credentials-Bq-Xa7Vq.d.ts +0 -125
- package/dist/credentials-dkycUsY3.js +0 -74
- package/dist/decide-set-DXEPepY1.js +0 -100
- package/dist/deciding-columns-NB4wcyBf.js +0 -134
- package/dist/decision-CaG5_eNJ.js +0 -21
- package/dist/delegation-CrdqnesZ.js +0 -262
- package/dist/delegation-input-DcXhiMkf.js +0 -19
- package/dist/delivery-BupfvJIV.js +0 -560
- package/dist/delivery-event-JioK5YbS.js +0 -40
- package/dist/denied-text-B6s29jcf.d.ts +0 -22
- package/dist/describe-BZAlPHxT.js +0 -101
- package/dist/describe-DwcoWMLB.d.ts +0 -45
- package/dist/device-BkSynWdg.js +0 -196
- package/dist/diff-BnYHpRSI.js +0 -466
- package/dist/diff-H75YU6Q-.js +0 -37
- package/dist/digest-8Yx2CchM.d.ts +0 -19
- package/dist/digest-BI-6aa6d.js +0 -27
- package/dist/doctor-Dvt1_ROJ.js +0 -3560
- package/dist/doctor-JLouRSQt.js +0 -54
- package/dist/env-DJZrPjRi.js +0 -8
- package/dist/errors-BDUwg2qC.js +0 -27
- package/dist/errors-BhRkoNS7.js +0 -145
- package/dist/errors-CHwoRRpB.d.ts +0 -14
- package/dist/errors-D_SnqcRn.d.ts +0 -141
- package/dist/errors-ynga1EQy.js +0 -128
- package/dist/evaluate-BQ2nWOki.js +0 -1905
- package/dist/evaluations-BVtY66lF.d.ts +0 -38
- package/dist/evaluations-Bj5xw0EM.js +0 -612
- package/dist/evaluator-CDl2YUd_.js +0 -2
- package/dist/evaluator-eager-CULtQ8t6.js +0 -9
- package/dist/event-time-BGy48400.js +0 -27
- package/dist/fetch-adapter-BJ76IZZg.d.ts +0 -34
- package/dist/fetch-adapter-CXeBg4CH.js +0 -124
- package/dist/fields-D9PIYlJy.js +0 -504
- package/dist/fields-DlKwZYiy.js +0 -26
- package/dist/files-BSjrtIHw.js +0 -141
- package/dist/files-CfiRtQ-m.js +0 -140
- package/dist/fixtures-BVZc7OCF.js +0 -80
- package/dist/flags-BlmpmXoY.js +0 -86
- package/dist/freeze-jjan0lCv.js +0 -63
- package/dist/from-snapshot-FdVXG_QZ.js +0 -159
- package/dist/gen-D17P8vo0.js +0 -827
- package/dist/gen-YA3SK59O.js +0 -58
- package/dist/generate-BqkZq8Dr.js +0 -165
- package/dist/generate-CezbCaTI.js +0 -275
- package/dist/grantee-OG4klcNr.js +0 -110
- package/dist/grantee-conditions-Dzprappv.js +0 -271
- package/dist/grantee-match-CPQ9zV-H.js +0 -148
- package/dist/graph-sql-BwFC4Qjs.d.ts +0 -29
- package/dist/headers-B9jQxjtW.d.ts +0 -10
- package/dist/helpers-CO2hDpBU.js +0 -537
- package/dist/hosted-CQW_YNx7.js +0 -362
- package/dist/hosted-D5StFpKa.d.ts +0 -102
- package/dist/http-B_LphE5Y.d.ts +0 -12
- package/dist/http-DH94eh6f.js +0 -72
- package/dist/http-DKLXrFGk.js +0 -83
- package/dist/http-dptLQzPP.js +0 -49
- package/dist/ids-DzhJaCUj.js +0 -55
- package/dist/import-B8zbuskR.js +0 -5950
- package/dist/import-BYYXmHvP.js +0 -1143
- package/dist/index-B1-tE0Kx.d.ts +0 -1159
- package/dist/index-BwSEp_O5.d.ts +0 -210
- package/dist/index-CB_eM-qx.d.ts +0 -101
- package/dist/index-CvcE9mYP.d.ts +0 -234
- package/dist/index-D7sMtTf6.d.ts +0 -542
- package/dist/index-d7f0hNss.d.ts +0 -233
- package/dist/init-BdgWNuc3.js +0 -96
- package/dist/init-DKRhYiGW.js +0 -95
- package/dist/instance-options-DhQVCuhT.d.ts +0 -11
- package/dist/instance-options-URVwqpMW.js +0 -24
- package/dist/instance-snapshot-DyG_5ASl.js +0 -693
- package/dist/instant-DK3Iz83e.js +0 -19
- package/dist/internals-B3IgHrvo.js +0 -20
- package/dist/json-schema-BPGa-RjQ.js +0 -149
- package/dist/json-schema-BfXgnRNT.d.ts +0 -40
- package/dist/kernel-D9AxUqmz.js +0 -427
- package/dist/limits-CAhpRrhk.js +0 -167
- package/dist/live-options-BBIT68le.js +0 -73
- package/dist/load-C4p4VgwR.js +0 -99
- package/dist/load-DiBUJx77.js +0 -1
- package/dist/load-jose-DZ4dnjri.js +0 -8
- package/dist/login-DEvccJwP.js +0 -68
- package/dist/login-IIUDSAYW.js +0 -257
- package/dist/lru-8q4WZjBV.js +0 -28
- package/dist/manifest-BoCYBbQL.js +0 -46
- package/dist/manifest-C6eFl3Vo.d.ts +0 -349
- package/dist/manifest-CZ-GmsOL.js +0 -401
- package/dist/manifest-json-CAGzls-C.js +0 -9
- package/dist/manifest-schema-svAkgqMc.js +0 -501
- package/dist/map-claims-CAa_bQt9.js +0 -387
- package/dist/map-error-BCdb2Nrp.js +0 -23
- package/dist/markers-BeHZ4x9Q.js +0 -80
- package/dist/may-use-WDhFPqGG.js +0 -125
- package/dist/membership-filter-BWnfRQzo.js +0 -68
- package/dist/migrate-DVsxeE0y.js +0 -537
- package/dist/module-values-CdaVwrab.js +0 -107
- package/dist/oauth-security-X7Em8DbH.js +0 -26
- package/dist/ocsf-TcjRBgIs.js +0 -136
- package/dist/openapi-BFUnL8Yi.js +0 -137
- package/dist/openapi-Cc-aS9xC.js +0 -416
- package/dist/openapi-DcjyfR1g.js +0 -256
- package/dist/operation-findings-CVwJHEu_.js +0 -36
- package/dist/operation-risks-BKOcTv8J.js +0 -13
- package/dist/operations-BMPx7HyO.d.ts +0 -62
- package/dist/operations-Bm9HFecz.js +0 -89
- package/dist/optional-8TKc-0j4.js +0 -47
- package/dist/output-LDciF_4t.js +0 -96
- package/dist/output-files-BYscrQl-.js +0 -1
- package/dist/output-files-CM0BnH05.js +0 -150
- package/dist/ownership-DvK6INyx.js +0 -1062
- package/dist/parse-CORUNcCo.js +0 -151
- package/dist/parse-local-manifest-Ce2N-Opr.js +0 -69
- package/dist/parse-local-manifest-w_ksIkB9.d.ts +0 -10
- package/dist/parse-request-DOBVaeiQ.js +0 -25
- package/dist/paths-CUvURzHp.js +0 -45
- package/dist/peer-BuK9F53f.js +0 -982
- package/dist/peer-n-swIV4H.js +0 -1
- package/dist/permdock-B3zE16To.js +0 -1203
- package/dist/permdock-DV3opaI3.d.ts +0 -674
- package/dist/permission-registry-B8tYxPIt.js +0 -398
- package/dist/permissions-BaoLxy66.js +0 -18
- package/dist/permissions-D-M48hW-.js +0 -146
- package/dist/permissions-DriWkV7q.d.ts +0 -54
- package/dist/pg-Ddxsd5ZB.js +0 -60
- package/dist/pins-nqarl3oE.js +0 -15
- package/dist/pkce-CnmmYqUZ.js +0 -21
- package/dist/policy-DIHfTqm6.d.ts +0 -20
- package/dist/policy-DnNOTENd.js +0 -430
- package/dist/policy-from-catalog-Z0hvSffr.js +0 -454
- package/dist/policy-module-xym9fnSq.js +0 -95
- package/dist/policy-types-DU389Elz.d.ts +0 -2809
- package/dist/postgres-store-DcyrPS-r.js +0 -1028
- package/dist/postgrest-3dE9SGx9.d.ts +0 -124
- package/dist/powersync-B5YjtUGd.js +0 -1532
- package/dist/powersync-BgUsk2Nf.js +0 -1
- package/dist/powersync-Dx7odzyw.js +0 -62
- package/dist/preset-Bn5Z54cH.js +0 -1858
- package/dist/principal-source-C6N60GtM.js +0 -103
- package/dist/problem-CPB8kqk7.js +0 -203
- package/dist/problem-details-CLDgX1KV.js +0 -156
- package/dist/problem-types-DSsRfONQ.js +0 -8
- package/dist/prompt-D1Gj1W4Y.js +0 -938
- package/dist/protected-action-CjSUoPGx.d.ts +0 -76
- package/dist/protected-action-D41o5LvP.js +0 -244
- package/dist/protected-action-OpOxtTsN.js +0 -80
- package/dist/provider-Bzzux0TR.js +0 -12
- package/dist/provider-D1jsNJ85.d.ts +0 -6
- package/dist/provider-store-tIAwP4aW.js +0 -52
- package/dist/provider-with-Do28DhxP.js +0 -69
- package/dist/pull-Pde1lapF.js +0 -257
- package/dist/pull-a4RpDxk8.js +0 -1
- package/dist/push-sJ5dy46a.js +0 -162
- package/dist/pushed-policy-Db651nih.d.ts +0 -63
- package/dist/pushed-policy-UZyQinrL.js +0 -241
- package/dist/refresh-on-L9UOwATg.d.ts +0 -49
- package/dist/refs-C8BKxc_e.js +0 -105
- package/dist/relation-walk-BDTaTKTM.js +0 -189
- package/dist/relations-CMsJ1ARY.js +0 -163
- package/dist/replay-BU09ad4L.js +0 -29
- package/dist/replay-BpmpY2ev.d.ts +0 -5
- package/dist/request-context-C2_1lchh.d.ts +0 -5
- package/dist/request-context-dyCY4V1t.js +0 -71
- package/dist/request-schema-CMP8Cmxd.js +0 -156
- package/dist/resolve-names-D5_kABup.js +0 -206
- package/dist/resource-ref-CaS9yVPi.js +0 -20
- package/dist/resource-relations-8-pCScBO.js +0 -252
- package/dist/retire-B2xffQgY.js +0 -249
- package/dist/revocations-BaUXHM1N.d.ts +0 -26
- package/dist/revocations-Bhr0aMIC.js +0 -27
- package/dist/rls-BI687j8q.js +0 -2700
- package/dist/rls-CKLHLcRl.js +0 -367
- package/dist/role-builder-BXdhhQcB.js +0 -507
- package/dist/rolldown-runtime-C3I60J0A.js +0 -4
- package/dist/row-conditions-BAGHOmVq.js +0 -28
- package/dist/row-pair-DglMdRFh.js +0 -34
- package/dist/rpc-BdFGYcWm.js +0 -112
- package/dist/rpc-DKRQobOX.d.ts +0 -22
- package/dist/run-B4heHtD1.js +0 -1
- package/dist/run-BG2kPruh.js +0 -694
- package/dist/run-ticket-Ddxt9OuU.js +0 -371
- package/dist/run-ticket-o4RxoaEN.d.ts +0 -159
- package/dist/runtime-rf0ZuyF3.js +0 -14
- package/dist/saas-D9maBt0q.js +0 -1223
- package/dist/scan-BvTBo9-D.js +0 -29
- package/dist/schema-BlnU_TzE.js +0 -414
- package/dist/schema-grK6TTBH.js +0 -134
- package/dist/scim-BG6uPUeW.js +0 -1056
- package/dist/scim-CovliQUg.js +0 -44
- package/dist/scopes-gdH__vDZ.js +0 -239
- package/dist/server-CKjFooaJ.js +0 -147
- package/dist/server-types-C4q8_8MM.d.ts +0 -325
- package/dist/sha256-C-4WXKIu.js +0 -158
- package/dist/shared-BRmCJxDK.js +0 -125
- package/dist/shared-DfaIWvIJ.js +0 -354
- package/dist/signals-B1vHR3fN.js +0 -32
- package/dist/sink-C3KDccl9.d.ts +0 -249
- package/dist/sink-D9_vh372.js +0 -968
- package/dist/skills-DzNdLezx.js +0 -51
- package/dist/skills-nPLVGtGH.js +0 -204
- package/dist/snapshot-D0VOanxQ.js +0 -334
- package/dist/snapshot-cache-B66h7FBK.js +0 -70
- package/dist/snapshot-cache-C1mN0pXe.d.ts +0 -70
- package/dist/snapshot-compact-CUtXsx6i.js +0 -75
- package/dist/snapshot-empty-F7d5BRlc.js +0 -18
- package/dist/snapshot-evaluate-C3ZA35O_.js +0 -501
- package/dist/snapshot-reads-CNNmp1cK.js +0 -66
- package/dist/sources-2virTxHt.d.ts +0 -721
- package/dist/sources-C4vkzZJV.js +0 -660
- package/dist/sources-qoIJQrJv.js +0 -11
- package/dist/sql-0WjxIp9g.js +0 -80
- package/dist/sql-B80DFdpG.d.ts +0 -10
- package/dist/src-ieIv22BA.js +0 -2080
- package/dist/standard-webhooks-B2g_yWK8.d.ts +0 -88
- package/dist/standard-webhooks-D67a3nzk.js +0 -228
- package/dist/storage-C2bWdvJH.js +0 -132
- package/dist/store-DXO0aVgf.js +0 -380
- package/dist/store-core-BI-9ZU-5.d.ts +0 -311
- package/dist/store-options-BYKNX_JG.js +0 -993
- package/dist/stores-DtM8pt8o.js +0 -128
- package/dist/stores-DwGfIcmq.d.ts +0 -57
- package/dist/stream-DQ3rbO3J.js +0 -74
- package/dist/style-DblOtSga.js +0 -1
- package/dist/style-Ds11Hmk4.js +0 -25
- package/dist/subject-C7RddW0G.js +0 -24
- package/dist/subject-cache-BT1fGuea.js +0 -193
- package/dist/subject-cache-TY2tw-k9.d.ts +0 -144
- package/dist/subject-jG6o8eKo.js +0 -556
- package/dist/subject-settings-8sH5HlII.js +0 -150
- package/dist/subject-settings-vNW8qmUH.d.ts +0 -52
- package/dist/supabase-BlAqmxD8.js +0 -723
- package/dist/supabase-dk1kB9bJ.js +0 -92
- package/dist/supabase-hook-Bu5gkzix.js +0 -1
- package/dist/supabase-hook-Cf9zKz8T.js +0 -4263
- package/dist/supautils-BREOPaHY.js +0 -1186
- package/dist/support-session-BGeEYDSq.js +0 -158
- package/dist/tables-DnNACfAr.js +0 -4003
- package/dist/target-qdEAnnhU.js +0 -51
- package/dist/tenancy-BlxY5T0q.js +0 -224
- package/dist/text-BMFRfBqc.js +0 -8
- package/dist/text-diff-BtfSmdUo.js +0 -444
- package/dist/thenable-BNSM1U2R.js +0 -40
- package/dist/time-nR1JesoH.js +0 -95
- package/dist/timeout-D51niuQP.js +0 -8
- package/dist/token-D6pWn8Uj.d.ts +0 -11
- package/dist/token-DaMnIU9O.js +0 -77
- package/dist/tool-refusal-D4spOJ7I.js +0 -44
- package/dist/type-helpers-tDoGEIsd.d.ts +0 -49
- package/dist/types-61f3KMtI.d.ts +0 -1136
- package/dist/types-BDgMzK1i.d.ts +0 -368
- package/dist/types-BIvkpVoc.d.ts +0 -180
- package/dist/types-BWjNPQkS.d.ts +0 -67
- package/dist/types-Bq4AU68k.d.ts +0 -105
- package/dist/types-BsqLNNvG.d.ts +0 -68
- package/dist/types-CH67RMvL.d.ts +0 -136
- package/dist/types-CcUXciSj.js +0 -79
- package/dist/types-DAyp592k.d.ts +0 -276
- package/dist/types-DEDocm4c.d.ts +0 -81
- package/dist/types-DQQkzF97.d.ts +0 -126
- package/dist/types-DdeivUBP.d.ts +0 -68
- package/dist/types-X40XNxRP.d.ts +0 -265
- package/dist/usage-BkDU1dYf.js +0 -762
- package/dist/usage-DNj42KHA.js +0 -32
- package/dist/usage-DrB_tDNk.js +0 -1
- package/dist/validation-error-CV0nV6_L.d.ts +0 -29
- package/dist/validation-error-CYg2kJEw.js +0 -36
- package/dist/validity-IcjQSR7I.js +0 -57
- package/dist/verifier-DUV6pLqZ.js +0 -519
- package/dist/verify-Boehaks6.js +0 -1736
- package/dist/version-DMQ0dnN5.js +0 -48
- package/dist/version-DizhmD72.js +0 -1
- package/dist/version-sources-BRb9ZteH.js +0 -34
- package/dist/views-MWmJ6Y4P.js +0 -147
- package/dist/vocabulary-BuYFWeCU.js +0 -158
- package/dist/vocabulary-DeZvUaTw.d.ts +0 -401
- package/dist/waiter-BophA4BT.d.ts +0 -39
- package/dist/waiter-aBLM63_f.js +0 -67
- package/dist/watch-CJKYQYNb.js +0 -167
- package/dist/watch-Cv-xvI6e.js +0 -1
- package/dist/who-can-Yh9WdiwK.js +0 -367
- package/dist/wire-delegation-Cv3W2eaM.js +0 -36
- package/dist/wire-denial-C7PaVYEM.js +0 -27
- package/dist/wrap-Bq9fHwuT.d.ts +0 -18
- package/dist/wrap-C5PWzgkq.js +0 -33
- package/schemas/catalog-v1.json +0 -679
- package/schemas/cli-result-v1.json +0 -95
|
@@ -0,0 +1,1567 @@
|
|
|
1
|
+
import { c as listPermissions } from "./permission-registry-DMYRZVcn.js";
|
|
2
|
+
import { c as rootScope, l as scopeChain, s as resolveScope } from "./scopes-B-KX9EI8.js";
|
|
3
|
+
import { i as configError } from "./errors-DgLOqc6j.js";
|
|
4
|
+
import { d as sqlTextArray, i as qualifySqlTable } from "./sql-T4GaBh9X.js";
|
|
5
|
+
import { a as scopeMembershipTable, i as scopeColumn } from "./compile-BUKXrueE.js";
|
|
6
|
+
import { d as keptKeys, l as roleColumn, u as roleManifest } from "./sources-DnjJPGfb.js";
|
|
7
|
+
import { a as quoteIdent, c as quoteTable, i as qualified, o as quoteLiteral, r as helperSchema, s as quoteQualified, t as CLI } from "./quote-BKrTBbcH.js";
|
|
8
|
+
import { A as tenantTypeOf, O as scopeTypeOf, _ as subjectClaimJsonSql, d as keyTenantSql, f as kindFilterSql, i as allowEntry, m as memberVia, o as rootName, r as HELPERS, s as signedIn, t as CUSTOM_ROLES, u as globalKindFilterSql, v as subjectClaimSql, y as subjectIdSql } from "./shared-BdF5DJDQ.js";
|
|
9
|
+
// src/cli/sql/active.ts
|
|
10
|
+
function checkActiveRow(label, row) {
|
|
11
|
+
quoteTable(row.table);
|
|
12
|
+
quoteIdent(row.id);
|
|
13
|
+
if (row.disabledAt !== void 0) quoteIdent(row.disabledAt);
|
|
14
|
+
if (row.status !== void 0) {
|
|
15
|
+
quoteIdent(row.status);
|
|
16
|
+
if (row.active === void 0 || row.active.length === 0) throw configError(`PermDock CLI: ${label}.status needs the active values in ${label}.active`);
|
|
17
|
+
}
|
|
18
|
+
if (row.disabledAt === void 0 && row.status === void 0) throw configError(`PermDock CLI: ${label} needs disabledAt or status to tell an active row`);
|
|
19
|
+
}
|
|
20
|
+
/** Validates `rls.suspension` and keys its scopes by declared name. */
|
|
21
|
+
function checkSuspension(suspension, scopes) {
|
|
22
|
+
if (suspension === void 0) return;
|
|
23
|
+
if (suspension.users !== void 0) checkActiveRow("rls.suspension.users", suspension.users);
|
|
24
|
+
const byName = {};
|
|
25
|
+
for (const [key, row] of Object.entries(suspension.scopes ?? {})) {
|
|
26
|
+
const name = resolveScope(scopes, key);
|
|
27
|
+
if (name === void 0) throw configError(`PermDock CLI: rls.suspension.scopes.${key} names a scope the policy does not declare`);
|
|
28
|
+
checkActiveRow(`rls.suspension.scopes.${key}`, row);
|
|
29
|
+
if (row.keep !== void 0 && !Array.isArray(row.keep)) throw configError(`PermDock CLI: rls.suspension.scopes.${key}.keep is a list of permissions or permission keys`);
|
|
30
|
+
const keep = keptKeys(row);
|
|
31
|
+
const { keep: _given, ...active } = row;
|
|
32
|
+
byName[name] = keep.length === 0 ? active : {
|
|
33
|
+
...active,
|
|
34
|
+
keep
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const memberships = suspension.memberships;
|
|
38
|
+
if (memberships?.keep !== void 0 && !Array.isArray(memberships.keep)) throw configError("PermDock CLI: rls.suspension.memberships.keep is a list of permissions or permission keys");
|
|
39
|
+
const keep = keptKeys(memberships);
|
|
40
|
+
return {
|
|
41
|
+
...suspension.users === void 0 ? {} : { users: suspension.users },
|
|
42
|
+
...Object.keys(byName).length === 0 ? {} : { scopes: byName },
|
|
43
|
+
...keep.length === 0 ? {} : { memberships: { keep } }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function disabledKeep(ctx) {
|
|
47
|
+
return keptKeys(ctx.suspension?.memberships);
|
|
48
|
+
}
|
|
49
|
+
function activeMembershipSql(ctx, disabledAt, permission = ctx.permission === void 0 ? void 0 : { key: ctx.permission }) {
|
|
50
|
+
if (disabledAt === void 0) return [];
|
|
51
|
+
const keep = disabledKeep(ctx);
|
|
52
|
+
if (permission !== void 0 && "key" in permission && keep.includes(permission.key)) return [];
|
|
53
|
+
return permission !== void 0 && "sql" in permission && keep.length > 0 ? [`(${disabledAt} is null or ${permission.sql} = any(array[${keep.map(quoteLiteral).join(", ")}]::text[]))`] : [`${disabledAt} is null`];
|
|
54
|
+
}
|
|
55
|
+
function keptRowSql(keep, permission) {
|
|
56
|
+
const kind = `coalesce(jsonb_typeof(${keep}), 'null')`;
|
|
57
|
+
if (permission === void 0) return `${kind} = 'null'`;
|
|
58
|
+
return `case ${kind} when 'null' then true when 'array' then ${keep} @> jsonb_build_array(${"key" in permission ? quoteLiteral(permission.key) : permission.sql}) else false end`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether `id` is among the active rows' ids: a missing row is suspended, so
|
|
62
|
+
* the check fails closed, and so does a null `id`. `id` stays outside the
|
|
63
|
+
* subquery so a column of the same name on `row.table` cannot capture it.
|
|
64
|
+
*/
|
|
65
|
+
function activeRowSql(row, id) {
|
|
66
|
+
const table = quoteTable(qualifySqlTable(row.table));
|
|
67
|
+
const parts = [];
|
|
68
|
+
if (row.disabledAt !== void 0) parts.push(`s.${quoteIdent(row.disabledAt)} is null`);
|
|
69
|
+
if (row.status !== void 0) {
|
|
70
|
+
const values = (row.active ?? []).map(quoteLiteral).join(", ");
|
|
71
|
+
parts.push(`s.${quoteIdent(row.status)}::text = any(array[${values}]::text[])`);
|
|
72
|
+
}
|
|
73
|
+
const where = parts.length === 0 ? "" : ` where ${parts.join(" and ")}`;
|
|
74
|
+
return `coalesce(${id} in (select s.${quoteIdent(row.id)} from ${table} s${where}), false)`;
|
|
75
|
+
}
|
|
76
|
+
function activeJoin(row, id, alias) {
|
|
77
|
+
const table = quoteTable(qualifySqlTable(row.table));
|
|
78
|
+
const parts = [`${alias}.${quoteIdent(row.id)} = ${id}`];
|
|
79
|
+
if (row.disabledAt !== void 0) parts.push(`${alias}.${quoteIdent(row.disabledAt)} is null`);
|
|
80
|
+
if (row.status !== void 0) {
|
|
81
|
+
const values = (row.active ?? []).map(quoteLiteral).join(", ");
|
|
82
|
+
parts.push(`${alias}.${quoteIdent(row.status)}::text = any(array[${values}]::text[])`);
|
|
83
|
+
}
|
|
84
|
+
return `join ${table} ${alias} on ${parts.join(" and ")}`;
|
|
85
|
+
}
|
|
86
|
+
function activeUserChecks(ctx, user, alias, indent) {
|
|
87
|
+
const row = ctx.suspension?.users;
|
|
88
|
+
return row === void 0 ? {
|
|
89
|
+
joins: [],
|
|
90
|
+
filters: []
|
|
91
|
+
} : {
|
|
92
|
+
joins: [`${indent}${activeJoin(row, user, alias)}`],
|
|
93
|
+
filters: []
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function activeInstanceChecks(ctx, scope, idOf, aliasOf, indent, permission = ctx.permission === void 0 ? void 0 : { key: ctx.permission }) {
|
|
97
|
+
const joins = [];
|
|
98
|
+
const filters = [];
|
|
99
|
+
for (const name of scopeChain(ctx.scopes, scope)) {
|
|
100
|
+
const row = ctx.suspension?.scopes?.[name];
|
|
101
|
+
if (row === void 0) continue;
|
|
102
|
+
const id = idOf(name);
|
|
103
|
+
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`);
|
|
104
|
+
const keep = keptKeys(row);
|
|
105
|
+
if (permission !== void 0 && "key" in permission && keep.includes(permission.key)) continue;
|
|
106
|
+
const cast = `(${id})::${scopeTypeOf(ctx, name)}`;
|
|
107
|
+
if (keep.length === 0) {
|
|
108
|
+
joins.push(`${indent}${activeJoin(row, cast, aliasOf(name))}`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const active = activeRowSql(row, cast);
|
|
112
|
+
filters.push(permission !== void 0 && "sql" in permission ? `(${active} or ${permission.sql} = any(array[${keep.map(quoteLiteral).join(", ")}]::text[]))` : active);
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
joins,
|
|
116
|
+
filters
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** The active-user check for `user`; empty without `rls.suspension.users`. */
|
|
120
|
+
function activeUserSql(ctx, user = subjectIdSql(ctx)) {
|
|
121
|
+
const row = ctx.suspension?.users;
|
|
122
|
+
return row === void 0 ? [] : [activeRowSql(row, user)];
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The permission of a grant key held in `grant`: `key#group` and `key@level`
|
|
126
|
+
* name `key`.
|
|
127
|
+
*/
|
|
128
|
+
function grantPermissionSql(grant) {
|
|
129
|
+
return { sql: `split_part(split_part(${grant}, '#', 1), '@', 1)` };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The active-instance check for every suspendable scope on `scope`'s chain: its
|
|
133
|
+
* own and each ancestor's. `idOf` gives the SQL for the id the membership holds
|
|
134
|
+
* for a scope on that chain. A scope's `keep` lets `permission` through a
|
|
135
|
+
* suspended instance: a kept key known now drops its check, and one read at run
|
|
136
|
+
* time is compared with the kept keys.
|
|
137
|
+
*/
|
|
138
|
+
function activeInstancesSql(ctx, scope, idOf, permission = ctx.permission === void 0 ? void 0 : { key: ctx.permission }) {
|
|
139
|
+
const parts = [];
|
|
140
|
+
for (const name of scopeChain(ctx.scopes, scope)) {
|
|
141
|
+
const row = ctx.suspension?.scopes?.[name];
|
|
142
|
+
if (row === void 0) continue;
|
|
143
|
+
const id = idOf(name);
|
|
144
|
+
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`);
|
|
145
|
+
const keep = keptKeys(row);
|
|
146
|
+
if (permission !== void 0 && "key" in permission && keep.includes(permission.key)) continue;
|
|
147
|
+
const active = activeRowSql(row, `(${id})::${scopeTypeOf(ctx, name)}`);
|
|
148
|
+
parts.push(permission !== void 0 && "sql" in permission && keep.length > 0 ? `(${active} or ${permission.sql} = any(array[${keep.map(quoteLiteral).join(", ")}]::text[]))` : active);
|
|
149
|
+
}
|
|
150
|
+
return parts;
|
|
151
|
+
}
|
|
152
|
+
// src/cli/sql/names.ts
|
|
153
|
+
/** The closure table graph grants read. Part of the SQL contract. */
|
|
154
|
+
const CLOSURE = { table: "permdock_closure" };
|
|
155
|
+
/**
|
|
156
|
+
* The snake_case SQL name of a resource or link (`chatThread` becomes
|
|
157
|
+
* `chat_thread`), or `undefined` when it is not made of ASCII letters, digits
|
|
158
|
+
* and underscores starting with a letter.
|
|
159
|
+
*/
|
|
160
|
+
function graphSqlName(name) {
|
|
161
|
+
if (!/^[A-Za-z][A-Za-z0-9_]*$/u.test(name)) return;
|
|
162
|
+
return name.replaceAll(/([a-z0-9])([A-Z])/gu, "$1_$2").replaceAll(/([A-Z]+)([A-Z][a-z])/gu, "$1_$2").toLowerCase();
|
|
163
|
+
}
|
|
164
|
+
function sqlNameOf(name, label) {
|
|
165
|
+
const sql = graphSqlName(name);
|
|
166
|
+
if (sql === void 0) throw configError(`PermDock CLI: ${label} is not a SQL name (letters, digits and underscores, starting with a letter), so rls generate cannot name its helper`);
|
|
167
|
+
return sql;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The helper returning the ids of `resource` the subject holds a relation on:
|
|
171
|
+
* `permitted_<snake_case resource>_ids`.
|
|
172
|
+
*/
|
|
173
|
+
function graphHelper(resource) {
|
|
174
|
+
return permittedIdsHelper(sqlNameOf(resource, `resource '${resource}'`));
|
|
175
|
+
}
|
|
176
|
+
function inheritedRowsHelper(resource) {
|
|
177
|
+
return `permitted_${sqlNameOf(resource, `resource '${resource}'`)}_rows`;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The helper returning the ids of `resource` whose `link` points into the ids
|
|
181
|
+
* it is given.
|
|
182
|
+
*/
|
|
183
|
+
function linkHelper(resource, link) {
|
|
184
|
+
return `permdock_link_${sqlNameOf(resource, `resource '${resource}'`)}_${sqlNameOf(link, `link '${link}' on ${resource}`)}`;
|
|
185
|
+
}
|
|
186
|
+
function restrictedHelper(resource) {
|
|
187
|
+
return `permdock_restricted_${sqlNameOf(resource, `resource '${resource}'`)}`;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Graph SQL parts as RLS text: values inline as literals, the subject from the
|
|
191
|
+
* dialect's claim.
|
|
192
|
+
*/
|
|
193
|
+
function graphSqlText(parts, ctx) {
|
|
194
|
+
return parts.map((part) => {
|
|
195
|
+
if ("text" in part) return part.text;
|
|
196
|
+
if ("column" in part) return quoteIdent(part.column);
|
|
197
|
+
if ("subject" in part) return subjectIdSql(ctx);
|
|
198
|
+
return typeof part.value === "string" ? quoteLiteral(part.value) : String(part.value);
|
|
199
|
+
}).join("");
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The role column of an `rls.memberships` table aliased `alias`; a `through`
|
|
203
|
+
* column joins its roles table as `<alias>k`, after a newline and `indent`
|
|
204
|
+
* (inline without one).
|
|
205
|
+
*/
|
|
206
|
+
function memberRoleOf(table, alias = "m", indent) {
|
|
207
|
+
return roleColumn(table.role, qualifySqlTable(table.table), alias, {
|
|
208
|
+
label: `rls.memberships ${table.table} role`,
|
|
209
|
+
prefix: CLI,
|
|
210
|
+
...indent === void 0 ? {} : { indent }
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/** The schema-qualified name of a table under `search_path = ''`. */
|
|
214
|
+
/** The helper returning the ids of scope `name` a grant key reaches. */
|
|
215
|
+
function permittedIdsHelper(name) {
|
|
216
|
+
if (!/^[a-z][a-z0-9_]*$/u.test(name)) throw configError(`PermDock CLI: unsafe scope name '${name}'`);
|
|
217
|
+
return `permitted_${name}_ids`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* `permitted_<scope>_ids_for(p_user, p_grant)`: the same ids for a user the
|
|
221
|
+
* caller names.
|
|
222
|
+
*/
|
|
223
|
+
function permittedForHelper(name) {
|
|
224
|
+
return `${permittedIdsHelper(name)}_for`;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The helper returning the ids of scope `name` the subject holds any live
|
|
228
|
+
* membership of.
|
|
229
|
+
*/
|
|
230
|
+
function memberIdsHelper(name) {
|
|
231
|
+
if (!/^[a-z][a-z0-9_]*$/u.test(name)) throw configError(`PermDock CLI: unsafe scope name '${name}'`);
|
|
232
|
+
return `member_${name}_ids`;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* `member_<scope>_ids_for(p_user uuid)`: the same rows for a user the caller
|
|
236
|
+
* names; the token hook's helper.
|
|
237
|
+
*/
|
|
238
|
+
function memberForHelper(name) {
|
|
239
|
+
return `${memberIdsHelper(name)}_for`;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* `member_<scope>_ids_of(p_user uuid)`: `member_<scope>_ids_for(p_user)` when
|
|
243
|
+
* `p_user` is the caller and no rows otherwise, so `authenticated` may execute
|
|
244
|
+
* it; better-supabase's `teamIdsOf` template calls it.
|
|
245
|
+
*/
|
|
246
|
+
function memberOfHelper(name) {
|
|
247
|
+
return `${memberIdsHelper(name)}_of`;
|
|
248
|
+
}
|
|
249
|
+
/** better-supabase's `bootstrapPermissions` reader. Part of the SQL contract. */
|
|
250
|
+
const BOOTSTRAP_PERMISSIONS = "permdock_bootstrap_permissions";
|
|
251
|
+
/** A scope better-supabase reads as its teams: `team` or `teams` (doctor BS417). */
|
|
252
|
+
function isTeamScope(name) {
|
|
253
|
+
return /^teams?$/u.test(name);
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Whether `member_<scope>_ids_of` is generated: a team scope with
|
|
257
|
+
* `member_<scope>_ids_for`.
|
|
258
|
+
*/
|
|
259
|
+
function hasMemberOf(input, name) {
|
|
260
|
+
return isTeamScope(name) && hasMemberFor(input, name);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Whether `member_<scope>_ids_for` is generated for `name`: Supabase only (its
|
|
264
|
+
* one caller is `supabase_auth_admin`), and only where `memberships` maps a
|
|
265
|
+
* table for the scope or a membership source can hold it.
|
|
266
|
+
*/
|
|
267
|
+
function hasMemberFor(input, name) {
|
|
268
|
+
if (input.dialect !== "supabase") return false;
|
|
269
|
+
return memberForTable(input, name) !== void 0 || memberForSources(input, name).length > 0;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Whether `permitted_<scope>_users` can list the members of one instance of
|
|
273
|
+
* `name`: a mapped membership table, or sources that all read a table.
|
|
274
|
+
*/
|
|
275
|
+
function hasPermittedUsers(input, name) {
|
|
276
|
+
if (memberForTable(input, name) !== void 0) return true;
|
|
277
|
+
const sources = memberForSources(input, name);
|
|
278
|
+
return sources.length > 0 && sources.every((source) => source.sql.holders !== void 0);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The table `member_<scope>_ids_for` reads for scope `name`, when `memberships`
|
|
282
|
+
* maps one with its id column.
|
|
283
|
+
*/
|
|
284
|
+
function memberForTable(input, name) {
|
|
285
|
+
const table = scopeMembershipTable(input.memberships, input.scopes, name);
|
|
286
|
+
return table !== void 0 && scopeColumn(table, input.scopes, name) !== void 0 ? table : void 0;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* The sources `member_<scope>_ids_for` reads: none when a table is mapped, as
|
|
290
|
+
* in `database` mode.
|
|
291
|
+
*/
|
|
292
|
+
function memberForSources(input, name) {
|
|
293
|
+
if (memberForTable(input, name) !== void 0) return [];
|
|
294
|
+
return (input.memberSources ?? []).filter((source) => source.sql.scope === void 0 || source.sql.scope === name);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* The membership sources that can hold scope `name` when `memberships` maps no
|
|
298
|
+
* table for it: every `tableMembershipSource` source and the
|
|
299
|
+
* `junctionMembershipSource` sources of that scope. Empty outside `database`
|
|
300
|
+
* mode.
|
|
301
|
+
*/
|
|
302
|
+
function scopeSources(ctx, name) {
|
|
303
|
+
if (ctx.authorize !== "database" || scopeTable(ctx, name) !== void 0) return [];
|
|
304
|
+
return (ctx.sources ?? []).filter((source) => source.sql.scope === void 0 || source.sql.scope === name);
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The membership table mapped for scope `name`, with the column of its id and
|
|
308
|
+
* of the first scope's id.
|
|
309
|
+
*/
|
|
310
|
+
function scopeTable(ctx, name) {
|
|
311
|
+
const table = scopeMembershipTable(ctx.memberships, ctx.scopes, name);
|
|
312
|
+
if (table === void 0) return;
|
|
313
|
+
const column = scopeColumn(table, ctx.scopes, name);
|
|
314
|
+
if (column === void 0) return;
|
|
315
|
+
const root = rootScope(ctx.scopes);
|
|
316
|
+
const tenantColumn = root !== void 0 && scopeChain(ctx.scopes, name).includes(root) ? scopeColumn(table, ctx.scopes, root) : void 0;
|
|
317
|
+
return tenantColumn === void 0 ? {
|
|
318
|
+
table,
|
|
319
|
+
column
|
|
320
|
+
} : {
|
|
321
|
+
table,
|
|
322
|
+
column,
|
|
323
|
+
tenantColumn
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
// src/cli/shared/compare.ts
|
|
327
|
+
/**
|
|
328
|
+
* UTF-16 code-unit order, never `localeCompare`: generated SQL must match byte
|
|
329
|
+
* for byte on every machine.
|
|
330
|
+
*/
|
|
331
|
+
function byCodeUnit(a, b) {
|
|
332
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
333
|
+
}
|
|
334
|
+
function byKey([a], [b]) {
|
|
335
|
+
return byCodeUnit(a, b);
|
|
336
|
+
}
|
|
337
|
+
// src/cli/rls/custom-roles.ts
|
|
338
|
+
/** The readers every helpers file ends with. Names are part of the SQL contract. */
|
|
339
|
+
const READERS = {
|
|
340
|
+
keys: "permdock_permission_keys",
|
|
341
|
+
roles: "permdock_role_permissions",
|
|
342
|
+
trusted: "permdock_trusted_role_permissions"
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* The custom-role objects: the tables (`database` mode), the ceiling view over
|
|
346
|
+
* the `assignable` declared roles, and `permdock_custom_keys`, which resolves
|
|
347
|
+
* one custom role to the grant keys it holds in a scope. A row in the tables
|
|
348
|
+
* can never reach a key outside the view.
|
|
349
|
+
*/
|
|
350
|
+
function customRolesSql(ctx) {
|
|
351
|
+
const custom = ctx.customRoles;
|
|
352
|
+
if (custom === void 0) return "";
|
|
353
|
+
const rp = qualified(ctx, "role_permissions");
|
|
354
|
+
const ceiling = qualified(ctx, CUSTOM_ROLES.ceiling);
|
|
355
|
+
const keys = qualified(ctx, CUSTOM_ROLES.keys);
|
|
356
|
+
const chunks = [];
|
|
357
|
+
if (ctx.authorize === "database") {
|
|
358
|
+
const tenantType = tenantTypeOf(ctx);
|
|
359
|
+
for (const [name, column, check] of [[
|
|
360
|
+
CUSTOM_ROLES.permissions,
|
|
361
|
+
"permission",
|
|
362
|
+
`,
|
|
363
|
+
effect text not null default 'allow' check (effect in ('allow', 'deny'))`
|
|
364
|
+
], [
|
|
365
|
+
CUSTOM_ROLES.includes,
|
|
366
|
+
"include_role",
|
|
367
|
+
""
|
|
368
|
+
]]) {
|
|
369
|
+
const table = qualified(ctx, name);
|
|
370
|
+
const leveled = custom.levels === true && name === CUSTOM_ROLES.permissions;
|
|
371
|
+
const unique = `tenant_id, scope, scope_id, role, ${column}${name === CUSTOM_ROLES.permissions ? ", effect" : ""}${leveled ? ", level" : ""}`;
|
|
372
|
+
const index = `${leveled ? `alter table ${table} add column if not exists level text check (level ~ '^[a-z][a-z0-9_]*$');\n` : ""}create unique index if not exists ${quoteIdent(`${name}_nnd_key`)}`;
|
|
373
|
+
chunks.push(`create table if not exists ${table} (
|
|
374
|
+
tenant_id ${tenantType},
|
|
375
|
+
scope text not null default ${quoteLiteral(rootName(ctx))},
|
|
376
|
+
scope_id text,
|
|
377
|
+
role text not null,
|
|
378
|
+
${column} text not null${check}
|
|
379
|
+
);
|
|
380
|
+
-- global: no tenant or instance; a tenant role: a tenant; a shared role: no tenant or instance
|
|
381
|
+
alter table ${table} drop constraint if exists ${quoteIdent(`${name}_check`)};
|
|
382
|
+
alter table ${table} drop constraint if exists ${quoteIdent(`${name}_shape`)};
|
|
383
|
+
alter table ${table} add constraint ${quoteIdent(`${name}_shape`)} check (
|
|
384
|
+
case when scope = 'global' then tenant_id is null and scope_id is null
|
|
385
|
+
else tenant_id is not null or scope_id is null end
|
|
386
|
+
);
|
|
387
|
+
${index}
|
|
388
|
+
on ${table} (${unique}) nulls not distinct;
|
|
389
|
+
-- the probe's equality columns lead, so one range scan reads a role's rows whatever its instance pin
|
|
390
|
+
create index if not exists ${quoteIdent(`${name}_probe_idx`)}
|
|
391
|
+
on ${table} (tenant_id, scope, role) include (scope_id, ${column}${name === CUSTOM_ROLES.permissions ? ", effect" : ""}${leveled ? ", level" : ""});
|
|
392
|
+
-- a row identity for triggers the application adds, such as an audit trigger that reads the primary key
|
|
393
|
+
alter table ${table} add column if not exists id bigint generated always as identity primary key;
|
|
394
|
+
alter table ${table} enable row level security;
|
|
395
|
+
revoke all on table ${table} from anon, authenticated, public;`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
chunks.push(`-- the ceiling: keys of assignable declared roles, and the denies of those roles on the same permissions
|
|
399
|
+
create or replace view ${ceiling} with (security_invoker = true) as
|
|
400
|
+
select rp.scope, rp.role, rp.permission, rp.grant_key, rp.effect
|
|
401
|
+
from ${rp} rp
|
|
402
|
+
where rp.role = any(${sqlTextArray(custom.assignable)})
|
|
403
|
+
and exists (
|
|
404
|
+
select 1 from ${rp} a
|
|
405
|
+
where a.role = rp.role
|
|
406
|
+
and a.permission = rp.permission
|
|
407
|
+
and a.scope = rp.scope
|
|
408
|
+
and a.effect = 'allow'
|
|
409
|
+
);
|
|
410
|
+
revoke all on table ${ceiling} from anon, authenticated, public;`);
|
|
411
|
+
const renames = Object.entries(custom.renamed ?? {}).toSorted(byKey);
|
|
412
|
+
const shared = sharedRoleSql(ctx);
|
|
413
|
+
if (custom.levels === true) {
|
|
414
|
+
chunks.push(leveledKeysSql(ctx, renames));
|
|
415
|
+
if (shared !== "") chunks.push(shared);
|
|
416
|
+
return chunks.join("\n\n");
|
|
417
|
+
}
|
|
418
|
+
const rename = renamesSql(renames);
|
|
419
|
+
chunks.push(`-- one custom role: included ceiling keys and same-scope denies, plus every ceiling key of an allowed permission, minus denied permissions
|
|
420
|
+
create or replace function ${keys}(p_allow text[], p_deny text[], p_include text[], p_scope text)
|
|
421
|
+
returns setof text
|
|
422
|
+
language sql
|
|
423
|
+
stable
|
|
424
|
+
set search_path = ''
|
|
425
|
+
as $$
|
|
426
|
+
with ${rename.prelude}ceiling as (
|
|
427
|
+
select c.role, ${rename.permission("c")}, c.grant_key, c.effect
|
|
428
|
+
from ${ceiling} c${rename.join("c")}
|
|
429
|
+
where c.scope = p_scope
|
|
430
|
+
),
|
|
431
|
+
included as (
|
|
432
|
+
select rp.role, ${rename.permission("rp")}, rp.grant_key, rp.scope, rp.effect
|
|
433
|
+
from ${rp} rp${rename.join("rp")}
|
|
434
|
+
where rp.role = any(coalesce(p_include, '{}'::text[]))
|
|
435
|
+
),
|
|
436
|
+
kept as (
|
|
437
|
+
select i.permission, i.grant_key
|
|
438
|
+
from included i
|
|
439
|
+
where i.effect = 'allow'
|
|
440
|
+
and i.scope = p_scope
|
|
441
|
+
and exists (
|
|
442
|
+
select 1 from ceiling c
|
|
443
|
+
where c.role = i.role and c.grant_key = i.grant_key and c.effect = 'allow'
|
|
444
|
+
)
|
|
445
|
+
),
|
|
446
|
+
wanted as (
|
|
447
|
+
${rename.allow}
|
|
448
|
+
union
|
|
449
|
+
select i.permission
|
|
450
|
+
from included i
|
|
451
|
+
where i.effect = 'allow'
|
|
452
|
+
and not (i.scope = p_scope and exists (
|
|
453
|
+
select 1 from ceiling c
|
|
454
|
+
where c.role = i.role and c.grant_key = i.grant_key and c.effect = 'allow'
|
|
455
|
+
))
|
|
456
|
+
),
|
|
457
|
+
allowed as (
|
|
458
|
+
select w.permission
|
|
459
|
+
from wanted w
|
|
460
|
+
where not (${rename.denied("w")})
|
|
461
|
+
and not exists (select 1 from kept k where k.permission = w.permission)
|
|
462
|
+
)
|
|
463
|
+
select k.grant_key from kept k
|
|
464
|
+
where not (${rename.denied("k")})
|
|
465
|
+
union
|
|
466
|
+
select i.grant_key from included i
|
|
467
|
+
where i.effect = 'deny' and i.scope = p_scope
|
|
468
|
+
union
|
|
469
|
+
select c.grant_key from ceiling c
|
|
470
|
+
where c.permission in (select a.permission from allowed a)
|
|
471
|
+
$$;
|
|
472
|
+
revoke execute on function ${keys}(text[], text[], text[], text) from public, anon, authenticated;`);
|
|
473
|
+
if (shared !== "") chunks.push(shared);
|
|
474
|
+
return chunks.join("\n\n");
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* `permdock_is_shared_role(p_scope, p_role)` (`database` mode): whether a
|
|
478
|
+
* shared custom role of that name exists at the scope.
|
|
479
|
+
*/
|
|
480
|
+
function sharedRoleSql(ctx) {
|
|
481
|
+
if (ctx.authorize !== "database") return "";
|
|
482
|
+
const perms = qualified(ctx, CUSTOM_ROLES.permissions);
|
|
483
|
+
const includes = qualified(ctx, CUSTOM_ROLES.includes);
|
|
484
|
+
const shared = qualified(ctx, CUSTOM_ROLES.shared);
|
|
485
|
+
return `-- a shared custom role: rows with no tenant at a scope below global; its name wins over a tenant role's in every tenant
|
|
486
|
+
create or replace function ${shared}(p_scope text, p_role text)
|
|
487
|
+
returns boolean
|
|
488
|
+
language sql
|
|
489
|
+
stable
|
|
490
|
+
security definer
|
|
491
|
+
set search_path = ''
|
|
492
|
+
as $$
|
|
493
|
+
select p_scope <> 'global' and (
|
|
494
|
+
exists (select 1 from ${perms} c where c.tenant_id is null and c.scope = p_scope and c.role = p_role)
|
|
495
|
+
or exists (select 1 from ${includes} c where c.tenant_id is null and c.scope = p_scope and c.role = p_role)
|
|
496
|
+
)
|
|
497
|
+
$$;
|
|
498
|
+
revoke execute on function ${shared}(text, text) from public, anon, authenticated;`;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* `permdock_custom_keys` when resources declare levels. An allow entry is `key`
|
|
502
|
+
* or `key@level`. A level reaches the ceiling's `<grant key>@<level>` keys,
|
|
503
|
+
* plus every narrower level when the resource sets `orderedLevels`, and the
|
|
504
|
+
* ceiling denies of that permission. A level no ceiling key carries removes the
|
|
505
|
+
* permission, as `resolveCustomRole` drops it with `unknown-level`.
|
|
506
|
+
*/
|
|
507
|
+
function leveledKeysSql(ctx, renames) {
|
|
508
|
+
const rp = qualified(ctx, "role_permissions");
|
|
509
|
+
const ceiling = qualified(ctx, CUSTOM_ROLES.ceiling);
|
|
510
|
+
const keys = qualified(ctx, CUSTOM_ROLES.keys);
|
|
511
|
+
const order = ctx.customRoles?.levelOrder ?? [];
|
|
512
|
+
const orderCte = order.length === 0 ? "" : `level_order (permission, level, ord) as (values ${order.map(([permission, level, ord]) => `(${quoteLiteral(permission)}, ${quoteLiteral(level)}, ${String(ord)})`).join(", ")}),
|
|
513
|
+
`;
|
|
514
|
+
const covered = order.length === 0 ? "" : `
|
|
515
|
+
or exists (
|
|
516
|
+
select 1
|
|
517
|
+
from level_order held
|
|
518
|
+
join level_order asked on asked.permission = held.permission and asked.ord <= held.ord
|
|
519
|
+
where held.permission = a.permission
|
|
520
|
+
and held.level = a.level
|
|
521
|
+
and asked.level = split_part(c.grant_key, '@', 2)
|
|
522
|
+
)`;
|
|
523
|
+
const renamed = renames.length > 0;
|
|
524
|
+
const prelude = renamed ? `renamed (former, key) as (values ${renames.map(([former, current]) => `(${quoteLiteral(former)}, ${quoteLiteral(current)})`).join(", ")}),
|
|
525
|
+
` : "";
|
|
526
|
+
const current = (raw, alias) => renamed ? `coalesce(r_${alias}.key, ${raw})` : raw;
|
|
527
|
+
const join = (raw, alias) => renamed ? ` left join renamed r_${alias} on r_${alias}.former = ${raw}` : "";
|
|
528
|
+
return `-- one custom role: as above, where an allow entry key@level reaches the ceiling keys of that level and, when ordered, every narrower level
|
|
529
|
+
create or replace function ${keys}(p_allow text[], p_deny text[], p_include text[], p_scope text)
|
|
530
|
+
returns setof text
|
|
531
|
+
language sql
|
|
532
|
+
stable
|
|
533
|
+
set search_path = ''
|
|
534
|
+
as $$
|
|
535
|
+
with ${prelude}${orderCte}entries as (
|
|
536
|
+
select ${current("split_part(e.entry, '@', 1)", "e")} as permission, nullif(split_part(e.entry, '@', 2), '') as level
|
|
537
|
+
from unnest(coalesce(p_allow, '{}'::text[])) as e(entry)${join("split_part(e.entry, '@', 1)", "e")}
|
|
538
|
+
),
|
|
539
|
+
ceiling as (
|
|
540
|
+
select c.role, ${current("c.permission", "c")} as permission, c.grant_key, c.effect
|
|
541
|
+
from ${ceiling} c${join("c.permission", "c")}
|
|
542
|
+
where c.scope = p_scope
|
|
543
|
+
),
|
|
544
|
+
levels as (
|
|
545
|
+
select distinct c.permission, split_part(c.grant_key, '@', 2) as level
|
|
546
|
+
from ceiling c
|
|
547
|
+
where c.effect = 'allow' and strpos(c.grant_key, '@') > 0
|
|
548
|
+
),
|
|
549
|
+
denied as (
|
|
550
|
+
select ${current("d.permission", "d")} as permission
|
|
551
|
+
from unnest(coalesce(p_deny, '{}'::text[])) as d(permission)${join("d.permission", "d")}
|
|
552
|
+
union
|
|
553
|
+
select e.permission from entries e
|
|
554
|
+
where e.level is not null
|
|
555
|
+
and not exists (select 1 from levels l where l.permission = e.permission and l.level = e.level)
|
|
556
|
+
),
|
|
557
|
+
included as (
|
|
558
|
+
select rp.role, ${current("rp.permission", "rp")} as permission, rp.grant_key, rp.scope, rp.effect
|
|
559
|
+
from ${rp} rp${join("rp.permission", "rp")}
|
|
560
|
+
where rp.role = any(coalesce(p_include, '{}'::text[]))
|
|
561
|
+
),
|
|
562
|
+
kept as (
|
|
563
|
+
select i.permission, i.grant_key
|
|
564
|
+
from included i
|
|
565
|
+
where i.effect = 'allow'
|
|
566
|
+
and i.scope = p_scope
|
|
567
|
+
and exists (
|
|
568
|
+
select 1 from ceiling c
|
|
569
|
+
where c.role = i.role and c.grant_key = i.grant_key and c.effect = 'allow'
|
|
570
|
+
)
|
|
571
|
+
),
|
|
572
|
+
wanted as (
|
|
573
|
+
select e.permission from entries e where e.level is null
|
|
574
|
+
union
|
|
575
|
+
select i.permission
|
|
576
|
+
from included i
|
|
577
|
+
where i.effect = 'allow'
|
|
578
|
+
and not (i.scope = p_scope and exists (
|
|
579
|
+
select 1 from ceiling c
|
|
580
|
+
where c.role = i.role and c.grant_key = i.grant_key and c.effect = 'allow'
|
|
581
|
+
))
|
|
582
|
+
),
|
|
583
|
+
allowed as (
|
|
584
|
+
select w.permission
|
|
585
|
+
from wanted w
|
|
586
|
+
where w.permission not in (select d.permission from denied d)
|
|
587
|
+
and not exists (select 1 from kept k where k.permission = w.permission)
|
|
588
|
+
),
|
|
589
|
+
allowed_levels as (
|
|
590
|
+
select e.permission, e.level
|
|
591
|
+
from entries e
|
|
592
|
+
where e.level is not null
|
|
593
|
+
and e.permission not in (select d.permission from denied d)
|
|
594
|
+
and e.permission not in (select a.permission from allowed a)
|
|
595
|
+
and not exists (select 1 from kept k where k.permission = e.permission)
|
|
596
|
+
)
|
|
597
|
+
select k.grant_key from kept k
|
|
598
|
+
where k.permission not in (select d.permission from denied d)
|
|
599
|
+
union
|
|
600
|
+
select i.grant_key from included i
|
|
601
|
+
where i.effect = 'deny' and i.scope = p_scope
|
|
602
|
+
union
|
|
603
|
+
select c.grant_key from ceiling c
|
|
604
|
+
where c.permission in (select a.permission from allowed a)
|
|
605
|
+
union
|
|
606
|
+
select c.grant_key from ceiling c
|
|
607
|
+
join allowed_levels a on a.permission = c.permission
|
|
608
|
+
where c.effect = 'deny' or split_part(c.grant_key, '@', 2) = a.level${covered}
|
|
609
|
+
$$;
|
|
610
|
+
revoke execute on function ${keys}(text[], text[], text[], text) from public, anon, authenticated;`;
|
|
611
|
+
}
|
|
612
|
+
function currentKeysSql(array) {
|
|
613
|
+
return `select coalesce(r.key, e.permission) as permission
|
|
614
|
+
from unnest(coalesce(${array}, '{}'::text[])) as e(permission)
|
|
615
|
+
left join renamed r on r.former = e.permission`;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* SQL fragments that read a stored former key as its current key inside
|
|
619
|
+
* `permdock_custom_keys`. Without renames they are the plain column and array
|
|
620
|
+
* reads.
|
|
621
|
+
*/
|
|
622
|
+
function renamesSql(renames) {
|
|
623
|
+
if (renames.length === 0) return {
|
|
624
|
+
prelude: "",
|
|
625
|
+
permission: (alias) => `${alias}.permission`,
|
|
626
|
+
join: () => "",
|
|
627
|
+
allow: "select unnest(coalesce(p_allow, '{}'::text[])) as permission",
|
|
628
|
+
denied: (alias) => `${alias}.permission = any(coalesce(p_deny, '{}'::text[]))`
|
|
629
|
+
};
|
|
630
|
+
return {
|
|
631
|
+
prelude: `renamed (former, key) as (values ${renames.map(([former, current]) => `(${quoteLiteral(former)}, ${quoteLiteral(current)})`).join(", ")}),
|
|
632
|
+
denied as (
|
|
633
|
+
${currentKeysSql("p_deny")}
|
|
634
|
+
),
|
|
635
|
+
`,
|
|
636
|
+
permission: (alias) => `coalesce(r_${alias}.key, ${alias}.permission) as permission`,
|
|
637
|
+
join: (alias) => ` left join renamed r_${alias} on r_${alias}.former = ${alias}.permission`,
|
|
638
|
+
allow: currentKeysSql("p_allow"),
|
|
639
|
+
denied: (alias) => `${alias}.permission in (select d.permission from denied d)`
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* The catalog reader `permdock_permission_keys()` and the role reader
|
|
644
|
+
* `permdock_role_permissions(p_role, p_scope, p_tenant, p_scope_id)`, both for
|
|
645
|
+
* `authenticated`. A declared role answers from `role_permissions`, which is
|
|
646
|
+
* the catalog. A custom role (`database` mode) answers from the tenant's own
|
|
647
|
+
* rows through `permdock_custom_keys`, only to a member of the tenant or a
|
|
648
|
+
* holder of a `meta.manageRoles` permission for a platform role; a shared role
|
|
649
|
+
* (no tenant below global) to any signed-in caller. The effect is `deny` for a
|
|
650
|
+
* deny the role carries after the ceiling, as `resolveCustomRole` returns it,
|
|
651
|
+
* never for a deny that merely removes an allow.
|
|
652
|
+
*/
|
|
653
|
+
function roleReadersSql(ctx, permissions, trustedReaders) {
|
|
654
|
+
const rp = qualified(ctx, "role_permissions");
|
|
655
|
+
const reader = qualified(ctx, READERS.roles);
|
|
656
|
+
const tenantType = tenantTypeOf(ctx);
|
|
657
|
+
const custom = ctx.customRoles;
|
|
658
|
+
const root = ctx.scopes[0]?.name;
|
|
659
|
+
const database = ctx.authorize === "database";
|
|
660
|
+
const chunks = [];
|
|
661
|
+
if (permissions !== void 0) {
|
|
662
|
+
const catalog = qualified(ctx, READERS.keys);
|
|
663
|
+
chunks.push(`-- every declared permission key
|
|
664
|
+
create or replace function ${catalog}()
|
|
665
|
+
returns setof text
|
|
666
|
+
language sql
|
|
667
|
+
stable
|
|
668
|
+
set search_path = ''
|
|
669
|
+
as $$
|
|
670
|
+
select k.permission from unnest(${sqlTextArray(permissions.toSorted())}) k(permission) order by 1
|
|
671
|
+
$$;
|
|
672
|
+
revoke execute on function ${catalog}() from public, anon;
|
|
673
|
+
grant execute on function ${catalog}() to authenticated;
|
|
674
|
+
|
|
675
|
+
create or replace function ${catalog}(p_scope text)
|
|
676
|
+
returns setof text
|
|
677
|
+
language sql
|
|
678
|
+
stable
|
|
679
|
+
security definer
|
|
680
|
+
set search_path = ''
|
|
681
|
+
as $$
|
|
682
|
+
select distinct rp.permission
|
|
683
|
+
from ${rp} rp
|
|
684
|
+
where rp.scope = p_scope
|
|
685
|
+
and rp.effect = 'allow'
|
|
686
|
+
and rp.permission = any(${sqlTextArray(permissions.toSorted())})
|
|
687
|
+
order by 1
|
|
688
|
+
$$;
|
|
689
|
+
revoke execute on function ${catalog}(text) from public, anon;
|
|
690
|
+
grant execute on function ${catalog}(text) to authenticated;`);
|
|
691
|
+
}
|
|
692
|
+
const declared = ` select distinct rp.permission, rp.effect
|
|
693
|
+
from ${rp} rp
|
|
694
|
+
where rp.role = p_role and rp.scope = p_scope
|
|
695
|
+
order by 1, 2`;
|
|
696
|
+
let body = `begin
|
|
697
|
+
perform p_tenant, p_scope_id; -- only a custom role reads them
|
|
698
|
+
return query
|
|
699
|
+
${declared};
|
|
700
|
+
end;`;
|
|
701
|
+
let trustedBody = body;
|
|
702
|
+
if (custom !== void 0 && database && root !== void 0) {
|
|
703
|
+
const tenant = qualified(ctx, CUSTOM_ROLES.permissions);
|
|
704
|
+
const includes = qualified(ctx, CUSTOM_ROLES.includes);
|
|
705
|
+
const keys = qualified(ctx, CUSTOM_ROLES.keys);
|
|
706
|
+
const shape = qualified(ctx, CUSTOM_ROLES.shape);
|
|
707
|
+
const ids = (helper) => `(select x::text from ${qualified(ctx, helper)}() x)`;
|
|
708
|
+
const memberOf = `p_tenant::text in ${ids(memberIdsHelper(root))}
|
|
709
|
+
or ${perScope(ctx, (scope) => scope === root ? "false" : `p_scope_id in ${ids(memberIdsHelper(scope))}`)}`;
|
|
710
|
+
const manage = custom.manage ?? [];
|
|
711
|
+
const platform = manage.length === 0 ? "false" : `exists (
|
|
712
|
+
select 1 from ${rp} m
|
|
713
|
+
where m.effect = 'allow'
|
|
714
|
+
and m.permission = any(${sqlTextArray(manage)})
|
|
715
|
+
and ${qualified(ctx, HELPERS.has)}(m.grant_key)
|
|
716
|
+
)`;
|
|
717
|
+
const match = `(p_tenant is null and c.tenant_id is null or c.tenant_id = p_tenant) and c.scope = p_scope and (p_scope_id is null and c.scope_id is null or c.scope_id = p_scope_id) and c.role = p_role`;
|
|
718
|
+
const allowEntryOf = `c.${allowEntry(ctx)}`;
|
|
719
|
+
const checked = (gate) => `begin
|
|
720
|
+
if p_role = any(${sqlTextArray(custom.declared)}) then
|
|
721
|
+
return query
|
|
722
|
+
${declared};
|
|
723
|
+
return;
|
|
724
|
+
end if;
|
|
725
|
+
perform ${shape}(p_tenant, p_scope, p_scope_id, p_role);${gate}
|
|
726
|
+
return query
|
|
727
|
+
select distinct rp.permission, rp.effect
|
|
728
|
+
from ${keys}(
|
|
729
|
+
array(select ${allowEntryOf} from ${tenant} c where ${match} and c.effect = 'allow'),
|
|
730
|
+
array(select c.permission from ${tenant} c where ${match} and c.effect = 'deny'),
|
|
731
|
+
array(select c.include_role from ${includes} c where ${match}),
|
|
732
|
+
p_scope
|
|
733
|
+
) k(grant_key)
|
|
734
|
+
join ${rp} rp on rp.grant_key = k.grant_key and rp.scope = p_scope
|
|
735
|
+
order by 1, 2;
|
|
736
|
+
end;`;
|
|
737
|
+
body = checked(`
|
|
738
|
+
if not (${signedIn(ctx)} and (
|
|
739
|
+
${platform}
|
|
740
|
+
or (p_scope <> 'global' and p_tenant is null and p_scope_id is null)
|
|
741
|
+
or (p_scope <> 'global' and (${memberOf}))
|
|
742
|
+
)) then
|
|
743
|
+
${raiseSql(" ", "42501", `'permdock: the caller is not a member of ' || coalesce(p_tenant::text, 'the platform')`, "not-member")}
|
|
744
|
+
end if;`);
|
|
745
|
+
trustedBody = checked("");
|
|
746
|
+
}
|
|
747
|
+
chunks.push(`-- the permission keys a role holds on a scope, with effect allow or deny; a custom role is read for its tenant and, below the first scope, its instance
|
|
748
|
+
create or replace function ${reader}(p_role text, p_scope text, p_tenant ${tenantType} default null, p_scope_id text default null)
|
|
749
|
+
returns table (permission text, effect text)
|
|
750
|
+
language plpgsql
|
|
751
|
+
stable
|
|
752
|
+
security definer
|
|
753
|
+
set search_path = ''
|
|
754
|
+
as $$
|
|
755
|
+
${body}
|
|
756
|
+
$$;
|
|
757
|
+
revoke execute on function ${reader}(text, text, ${tenantType}, text) from public, anon;
|
|
758
|
+
grant execute on function ${reader}(text, text, ${tenantType}, text) to authenticated;`);
|
|
759
|
+
const trusted = qualified(ctx, READERS.trusted);
|
|
760
|
+
const signature = `text, text, ${tenantType}, text`;
|
|
761
|
+
const grants = trustedReaders === void 0 || trustedReaders.length === 0 ? "" : `\n${trustedReaderGrants(ctx, `${trusted}(${signature})`, trustedReaders)}`;
|
|
762
|
+
chunks.push(`create or replace function ${trusted}(p_role text, p_scope text, p_tenant ${tenantType} default null, p_scope_id text default null)
|
|
763
|
+
returns table (permission text, effect text)
|
|
764
|
+
language plpgsql
|
|
765
|
+
stable
|
|
766
|
+
security definer
|
|
767
|
+
set search_path = ''
|
|
768
|
+
as $$
|
|
769
|
+
${trustedBody}
|
|
770
|
+
$$;
|
|
771
|
+
revoke execute on function ${trusted}(${signature}) from public, anon, authenticated;${grants}`);
|
|
772
|
+
return chunks.join("\n\n");
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* The stored definition of `p_role` at `p_scope` for `p_tenant`: the shared
|
|
776
|
+
* rows when a shared role has the name.
|
|
777
|
+
*/
|
|
778
|
+
function storedTenant(ctx) {
|
|
779
|
+
return `case when ${qualified(ctx, CUSTOM_ROLES.shared)}(p_scope, p_role) then c.tenant_id is null else (p_tenant is null and c.tenant_id is null or c.tenant_id = p_tenant) end`;
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* The compiled row of one custom role, as a `select` of its `grant_keys`:
|
|
783
|
+
* `custom_role_compiled` holds one row per role and instance pin, so a probe is
|
|
784
|
+
* an index read and never resolves the role. A role pinned to the membership's
|
|
785
|
+
* instance wins over the same role with no pin; a shared role of that name wins
|
|
786
|
+
* over the tenant's. A platform role (`tenant` undefined) has no tenant.
|
|
787
|
+
*/
|
|
788
|
+
function customKeysArrayQuery(ctx, input) {
|
|
789
|
+
const scope = quoteLiteral(input.scope);
|
|
790
|
+
const tenantMatch = input.tenant === void 0 ? "c.tenant_id is null" : `(not pdk_s.shared and c.tenant_id = ${input.tenant} or pdk_s.shared and c.tenant_id is null)`;
|
|
791
|
+
const instance = input.instance === void 0 ? "c.scope_id is null" : `(c.scope_id is null or c.scope_id = ${input.instance})`;
|
|
792
|
+
return `select c.grant_keys as keys
|
|
793
|
+
from ${input.tenant === void 0 ? "(select false as shared)" : `(select ${qualified(ctx, CUSTOM_ROLES.shared)}(${scope}, ${input.role}) as shared offset 0)`} pdk_s
|
|
794
|
+
cross join lateral (
|
|
795
|
+
select c.grant_keys from ${qualified(ctx, CUSTOM_ROLES.compiled)} c
|
|
796
|
+
where ${tenantMatch} and c.scope = ${scope} and ${instance} and c.role = ${input.role}
|
|
797
|
+
order by c.scope_id nulls last
|
|
798
|
+
limit 1
|
|
799
|
+
) c`;
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* The grant keys one custom role holds, as a `select` of `grant_key`, for a
|
|
803
|
+
* caller that asks per membership.
|
|
804
|
+
*/
|
|
805
|
+
function customKeysQuery(ctx, input) {
|
|
806
|
+
return `select k.grant_key
|
|
807
|
+
from (${customKeysArrayQuery(ctx, input)}) pdk_e
|
|
808
|
+
cross join lateral unnest(pdk_e.keys) k(grant_key)`;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* The scope of a row of the application's roles table: its scope column (or the
|
|
812
|
+
* first scope) with a tenant; with no tenant, the same scope when the `shared`
|
|
813
|
+
* column is true, else `'global'`.
|
|
814
|
+
*/
|
|
815
|
+
function rolesTableScope(table, tenant, root, column) {
|
|
816
|
+
const own = table.scope === void 0 ? quoteLiteral(root) : `${column(table.scope)}::text`;
|
|
817
|
+
return `case when ${tenant} is null then ${table.shared === void 0 ? "'global'" : `case when coalesce(${column(table.shared)}, false) then ${own} else 'global' end`} else ${own} end`;
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* `expr` read as its current key: a former key maps to the key it was renamed
|
|
821
|
+
* to.
|
|
822
|
+
*/
|
|
823
|
+
function currentKeyExpr(renames, expr) {
|
|
824
|
+
if (renames.length === 0) return expr;
|
|
825
|
+
return `(case ${expr} ${renames.map(([former, current]) => `when ${quoteLiteral(former)} then ${quoteLiteral(current)}`).join(" ")} else ${expr} end)`;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* `case p_scope when '<scope>' then <sql for scope> ... else false end` over
|
|
829
|
+
* the declared scopes.
|
|
830
|
+
*/
|
|
831
|
+
function perScope(ctx, sql) {
|
|
832
|
+
const arms = ctx.scopes.map((scope) => `when ${quoteLiteral(scope.name)} then ${sql(scope.name)}`).join(" ");
|
|
833
|
+
return arms === "" ? "false" : `(case p_scope ${arms} else false end)`;
|
|
834
|
+
}
|
|
835
|
+
function raiseSql(indent, errcode, message, hint) {
|
|
836
|
+
return `${indent}raise exception using
|
|
837
|
+
${indent} errcode = '${errcode}',
|
|
838
|
+
${indent} hint = ${quoteLiteral(hint)},
|
|
839
|
+
${indent} message = ${message};`;
|
|
840
|
+
}
|
|
841
|
+
function hasCustomRoleChecksFor(ctx) {
|
|
842
|
+
return ctx.authorize === "database" && ctx.customRoles !== void 0 && ctx.scopes.length > 0 && ctx.scopes.every((scope) => hasMemberFor(ctx, scope.name));
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* The grants a `rls.trustedReaders` role needs for one reader: usage on the
|
|
846
|
+
* helper schema, which no client role reaches through these lines, and execute
|
|
847
|
+
* on the function.
|
|
848
|
+
*/
|
|
849
|
+
function trustedReaderGrants(ctx, fn, readers) {
|
|
850
|
+
const to = readers.map(quoteIdent).join(", ");
|
|
851
|
+
return `grant usage on schema ${quoteIdent(helperSchema(ctx))} to ${to};
|
|
852
|
+
grant execute on function ${fn} to ${to};`;
|
|
853
|
+
}
|
|
854
|
+
// src/cli/sql/global-roles.ts
|
|
855
|
+
function qualify(name, schema) {
|
|
856
|
+
return name.includes(".") ? name : `${schema}.${name}`;
|
|
857
|
+
}
|
|
858
|
+
function throughTenant(through, roles) {
|
|
859
|
+
if (through === void 0 || roles?.tenant === void 0) return;
|
|
860
|
+
return qualify(roles.table, "public") === through.table ? roles.tenant : void 0;
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* Resolves `source` against `schema`, aliasing the table `alias` and the roles
|
|
864
|
+
* table `<alias>k`.
|
|
865
|
+
*/
|
|
866
|
+
function globalRoleSource(source, schema, alias, roles) {
|
|
867
|
+
const table = qualify(source.table, schema);
|
|
868
|
+
const user = source.user ?? "user_id";
|
|
869
|
+
const role = roleColumn(source.role ?? "role", table, alias, {
|
|
870
|
+
label: "roles.role",
|
|
871
|
+
prefix: "PermDock CLI",
|
|
872
|
+
indent: " "
|
|
873
|
+
});
|
|
874
|
+
const tenant = role.lateral ? void 0 : throughTenant(role.through, roles);
|
|
875
|
+
const shared = tenant === void 0 ? void 0 : roles?.shared;
|
|
876
|
+
const global = tenant === void 0 ? "" : ` and ${alias}k.${quoteIdent(tenant)} is null${shared === void 0 ? "" : ` and ${alias}k.${quoteIdent(shared)} is not true`}`;
|
|
877
|
+
return {
|
|
878
|
+
table,
|
|
879
|
+
user,
|
|
880
|
+
from: `${quoteTable(table)} ${alias}${role.join}${global}`,
|
|
881
|
+
userSql: `${alias}.${quoteIdent(user)}`,
|
|
882
|
+
roleSql: role.sql,
|
|
883
|
+
nullable: role.nullable,
|
|
884
|
+
role: roleManifest(role),
|
|
885
|
+
...role.through === void 0 ? {} : { through: role.through },
|
|
886
|
+
...tenant === void 0 ? {} : { tenant },
|
|
887
|
+
...shared === void 0 ? {} : { shared }
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
// src/cli/rls/helper-rows.ts
|
|
891
|
+
function activeTenant(ctx) {
|
|
892
|
+
return `nullif(${subjectClaimSql(ctx, ctx.tenantClaim)}, '')`;
|
|
893
|
+
}
|
|
894
|
+
function keyTenantLine(ctx, scope, tenant) {
|
|
895
|
+
const keyed = keyTenantSql(ctx, underRoot(ctx, scope) ? tenant : void 0);
|
|
896
|
+
return keyed === void 0 ? "" : `\n and ${keyed}`;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Whether the helper for `scope` narrows to the tenant claim: unless
|
|
900
|
+
* `rls.tenants` is `'all'`, when the first scope is on its chain.
|
|
901
|
+
*/
|
|
902
|
+
function narrowsTo(ctx, scope) {
|
|
903
|
+
return ctx.tenants !== "all" && underRoot(ctx, scope);
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Whether the active tenant narrows memberships of `scope`: the first scope is
|
|
907
|
+
* on its chain.
|
|
908
|
+
*/
|
|
909
|
+
function underRoot(ctx, scope) {
|
|
910
|
+
const root = ctx.scopes[0]?.name;
|
|
911
|
+
let current = ctx.scopes.find((item) => item.name === scope);
|
|
912
|
+
const seen = /* @__PURE__ */ new Set();
|
|
913
|
+
while (current !== void 0 && !seen.has(current.name)) {
|
|
914
|
+
if (current.name === root) return true;
|
|
915
|
+
seen.add(current.name);
|
|
916
|
+
const parent = current.within;
|
|
917
|
+
current = parent === void 0 ? void 0 : ctx.scopes.find((item) => item.name === parent);
|
|
918
|
+
}
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* `and exists (...)` lines for an active user; empty without
|
|
923
|
+
* `rls.suspension.users`.
|
|
924
|
+
*/
|
|
925
|
+
function userActive(ctx, indent, user) {
|
|
926
|
+
return activeUserSql(ctx, user).map((part) => `${indent}and ${part}`);
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* `and exists (...)` lines for every suspendable instance on the chain of
|
|
930
|
+
* `scope`'s membership.
|
|
931
|
+
*/
|
|
932
|
+
function instancesActive(ctx, scope, idOf, indent, permission) {
|
|
933
|
+
return activeInstancesSql(ctx, scope, idOf, permission).map((part) => `${indent}and ${part}`);
|
|
934
|
+
}
|
|
935
|
+
function roleRows(ctx) {
|
|
936
|
+
const claim = ctx.roleClaim ?? "user_role";
|
|
937
|
+
switch (ctx.dialect) {
|
|
938
|
+
case "guc": return `unnest(string_to_array(nullif(current_setting(${quoteLiteral(`${ctx.gucPrefix}.${claim}`)}, true), ''), ',')) r(role)`;
|
|
939
|
+
case "supabase":
|
|
940
|
+
case "neon": {
|
|
941
|
+
const raw = subjectClaimJsonSql(ctx, claim);
|
|
942
|
+
const value = ctx.dialect === "supabase" ? `coalesce(nullif(${raw}, 'null'::jsonb), (select auth.jwt()) -> 'app_metadata' -> ${quoteLiteral(claim)})` : raw;
|
|
943
|
+
return `jsonb_array_elements_text(
|
|
944
|
+
case jsonb_typeof(${value})
|
|
945
|
+
when 'array' then ${value}
|
|
946
|
+
when 'string' then jsonb_build_array(${value})
|
|
947
|
+
else '[]'::jsonb
|
|
948
|
+
end
|
|
949
|
+
) r(role)`;
|
|
950
|
+
}
|
|
951
|
+
default: return ctx.dialect;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
function membershipRows(ctx) {
|
|
955
|
+
const raw = subjectClaimJsonSql(ctx, "memberships");
|
|
956
|
+
return `(select ${ctx.dialect === "supabase" ? `coalesce(${raw}, (select auth.jwt()) -> 'app_metadata' -> 'memberships')` : raw} as v) pdk_c
|
|
957
|
+
cross join lateral jsonb_array_elements(
|
|
958
|
+
case jsonb_typeof(pdk_c.v) when 'array' then pdk_c.v else '[]'::jsonb end
|
|
959
|
+
) m
|
|
960
|
+
cross join lateral jsonb_array_elements_text(
|
|
961
|
+
case jsonb_typeof(m -> 'roles') when 'array' then m -> 'roles' else '[]'::jsonb end
|
|
962
|
+
) r(role)`;
|
|
963
|
+
}
|
|
964
|
+
function andLine(indent, condition) {
|
|
965
|
+
return condition === void 0 ? "" : `\n${indent}and ${condition}`;
|
|
966
|
+
}
|
|
967
|
+
/** `rls.roles`, or the generated `user_roles (user_id, role)`, aliased `ur`. */
|
|
968
|
+
function globalRoleRows(ctx) {
|
|
969
|
+
return ctx.roles === void 0 ? {
|
|
970
|
+
from: `${qualified(ctx, "user_roles")} ur`,
|
|
971
|
+
userSql: "ur.user_id",
|
|
972
|
+
roleSql: "ur.role::text"
|
|
973
|
+
} : globalRoleSource(ctx.roles, "public", "ur", ctx.customRoles?.table);
|
|
974
|
+
}
|
|
975
|
+
function customKeysJoin(ctx, scope, allows, denies, includes) {
|
|
976
|
+
return ` cross join lateral ${qualified(ctx, CUSTOM_ROLES.keys)}(
|
|
977
|
+
${allows},
|
|
978
|
+
${denies},
|
|
979
|
+
${includes},
|
|
980
|
+
${quoteLiteral(scope)}
|
|
981
|
+
) ck(grant_key)`;
|
|
982
|
+
}
|
|
983
|
+
// src/cli/rls/helper-bodies.ts
|
|
984
|
+
/** The call that answers the grant keys a declared role holds on a scope. */
|
|
985
|
+
function roleKeys(ctx, scope, role) {
|
|
986
|
+
return `${qualified(ctx, "permdock_role_keys")}(${quoteLiteral(scope)}, ${role})`;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* How a body reaches the grant keys of a declared role: a lateral call of
|
|
990
|
+
* `permdock_role_grants(scope, role)`, the one inlinable function over
|
|
991
|
+
* `role_permissions`, or with `rls.seeds: 'view'` the jsonb map
|
|
992
|
+
* `permdock_role_keys(scope, role)`, which a hash lookup answers where the
|
|
993
|
+
* view's `values` list is scanned.
|
|
994
|
+
*/
|
|
995
|
+
function rpJoin(ctx, scope, role, set, indent) {
|
|
996
|
+
if (ctx.seeds !== "view") return `${indent}cross join lateral ${qualified(ctx, HELPERS.roleGrantKeys)}(${quoteLiteral(scope)}, ${role}) rp(grant_key)\n`;
|
|
997
|
+
return set ? `${indent}cross join lateral jsonb_array_elements_text(coalesce(${roleKeys(ctx, scope, role)}, '[]'::jsonb)) rp(grant_key)\n` : "";
|
|
998
|
+
}
|
|
999
|
+
function rpConds(ctx, scope, role, set) {
|
|
1000
|
+
if (ctx.seeds !== "view") return set ? [] : ["rp.grant_key = p_grant"];
|
|
1001
|
+
return set ? [] : [`jsonb_exists(${roleKeys(ctx, scope, role)}, p_grant)`];
|
|
1002
|
+
}
|
|
1003
|
+
function rpWhere(ctx, scope, role, set, indent) {
|
|
1004
|
+
return rpConds(ctx, scope, role, set).map((cond) => `\n${indent}and ${cond}`).join("");
|
|
1005
|
+
}
|
|
1006
|
+
function hasSetBody(ctx) {
|
|
1007
|
+
const active = userActive(ctx, " ").map((line) => `\n${line}`).join("");
|
|
1008
|
+
const custom = ctx.customRoles;
|
|
1009
|
+
if (ctx.authorize === "database") {
|
|
1010
|
+
const ur = globalRoleRows(ctx);
|
|
1011
|
+
const declared = ` select rp.grant_key
|
|
1012
|
+
from ${ur.from}
|
|
1013
|
+
${rpJoin(ctx, "global", ur.roleSql, true, " ")} where ${ur.userSql} = ${subjectIdSql(ctx)}${rpWhere(ctx, "global", ur.roleSql, true, " ")}${andLine(" ", globalKindFilterSql(ctx, ur.roleSql))}${active}`;
|
|
1014
|
+
if (custom === void 0) return declared;
|
|
1015
|
+
const keys = customKeysQuery(ctx, {
|
|
1016
|
+
scope: "global",
|
|
1017
|
+
role: ur.roleSql,
|
|
1018
|
+
tenant: void 0,
|
|
1019
|
+
instance: void 0
|
|
1020
|
+
});
|
|
1021
|
+
return `${declared}
|
|
1022
|
+
union
|
|
1023
|
+
select ck.grant_key
|
|
1024
|
+
from ${ur.from}
|
|
1025
|
+
cross join lateral (${keys}) ck(grant_key)
|
|
1026
|
+
where ${ur.userSql} = ${subjectIdSql(ctx)}
|
|
1027
|
+
and not (${ur.roleSql} = any(${sqlTextArray(custom.declared)}))${active}`;
|
|
1028
|
+
}
|
|
1029
|
+
const declared = ` select rp.grant_key
|
|
1030
|
+
from ${roleRows(ctx)}
|
|
1031
|
+
${rpJoin(ctx, "global", "r.role", true, " ")} where ${signedIn(ctx)}${rpWhere(ctx, "global", "r.role", true, " ")}${andLine(" ", globalKindFilterSql(ctx, "r.role"))}${active}`;
|
|
1032
|
+
if (custom === void 0) return declared;
|
|
1033
|
+
const claim = subjectClaimJsonSql(ctx, GLOBAL_GRANTS_CLAIM);
|
|
1034
|
+
return `${declared}
|
|
1035
|
+
union
|
|
1036
|
+
select ck.grant_key
|
|
1037
|
+
from ${roleRows(ctx)}
|
|
1038
|
+
cross join lateral (select ${claim} -> r.role as g) cg
|
|
1039
|
+
${customKeysJoin(ctx, "global", claimEntries("left(e, 1) not in ('-', '@')", "e"), claimEntries("left(e, 1) = '-'", "substr(e, 2)"), claimEntries("left(e, 1) = '@'", "substr(e, 2)"))}
|
|
1040
|
+
where ${signedIn(ctx)}
|
|
1041
|
+
and jsonb_typeof(cg.g) = 'array'
|
|
1042
|
+
and not (r.role = any(${sqlTextArray(custom.declared)}))${active}`;
|
|
1043
|
+
}
|
|
1044
|
+
function hasBody(ctx) {
|
|
1045
|
+
if (ctx.grantSet === true) return hasSetBody(ctx);
|
|
1046
|
+
const active = userActive(ctx, " ").map((line) => `\n${line}`).join("");
|
|
1047
|
+
const custom = ctx.customRoles;
|
|
1048
|
+
if (ctx.authorize === "database") {
|
|
1049
|
+
const ur = globalRoleRows(ctx);
|
|
1050
|
+
const declared = ` select exists (
|
|
1051
|
+
select 1
|
|
1052
|
+
from ${ur.from}
|
|
1053
|
+
${rpJoin(ctx, "global", ur.roleSql, false, " ")} where ${ur.userSql} = ${subjectIdSql(ctx)}${rpWhere(ctx, "global", ur.roleSql, false, " ")}${andLine(" ", globalKindFilterSql(ctx, ur.roleSql))}${active}
|
|
1054
|
+
)`;
|
|
1055
|
+
if (custom === void 0) return declared;
|
|
1056
|
+
const keys = customKeysQuery(ctx, {
|
|
1057
|
+
scope: "global",
|
|
1058
|
+
role: ur.roleSql,
|
|
1059
|
+
tenant: void 0,
|
|
1060
|
+
instance: void 0
|
|
1061
|
+
});
|
|
1062
|
+
return `${declared}
|
|
1063
|
+
or exists (
|
|
1064
|
+
select 1
|
|
1065
|
+
from ${ur.from}
|
|
1066
|
+
where ${ur.userSql} = ${subjectIdSql(ctx)}
|
|
1067
|
+
and not (${ur.roleSql} = any(${sqlTextArray(custom.declared)}))${active}
|
|
1068
|
+
and p_grant in (${keys})
|
|
1069
|
+
)`;
|
|
1070
|
+
}
|
|
1071
|
+
const declared = ` select ${signedIn(ctx)} and exists (
|
|
1072
|
+
select 1
|
|
1073
|
+
from ${roleRows(ctx)}
|
|
1074
|
+
${rpJoin(ctx, "global", "r.role", false, " ")} where ${rpConds(ctx, "global", "r.role", false).join("\n and ")}${andLine(" ", globalKindFilterSql(ctx, "r.role"))}${active}
|
|
1075
|
+
)`;
|
|
1076
|
+
if (custom === void 0) return declared;
|
|
1077
|
+
const claim = subjectClaimJsonSql(ctx, GLOBAL_GRANTS_CLAIM);
|
|
1078
|
+
return `${declared}
|
|
1079
|
+
or (${signedIn(ctx)} and exists (
|
|
1080
|
+
select 1
|
|
1081
|
+
from ${roleRows(ctx)}
|
|
1082
|
+
cross join lateral (select ${claim} -> r.role as g) cg
|
|
1083
|
+
where jsonb_typeof(cg.g) = 'array'
|
|
1084
|
+
and not (r.role = any(${sqlTextArray(custom.declared)}))${active}
|
|
1085
|
+
${customKeysSql(ctx, "global", claimEntries("left(e, 1) not in ('-', '@')", "e"), claimEntries("left(e, 1) = '-'", "substr(e, 2)"), claimEntries("left(e, 1) = '@'", "substr(e, 2)")).trimStart()}
|
|
1086
|
+
))`;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* The claim `jwt` mode reads platform custom roles from:
|
|
1090
|
+
* `customRoleClaim(globalRoles)`.
|
|
1091
|
+
*/
|
|
1092
|
+
const GLOBAL_GRANTS_CLAIM = "role_grants";
|
|
1093
|
+
function memberColumn(name) {
|
|
1094
|
+
return `m.${quoteIdent(name)}`;
|
|
1095
|
+
}
|
|
1096
|
+
function disabledColumn(table) {
|
|
1097
|
+
return table.disabledAt === void 0 ? void 0 : memberColumn(table.disabledAt);
|
|
1098
|
+
}
|
|
1099
|
+
function claimKeptLines(ctx, indent, permission) {
|
|
1100
|
+
return disabledKeep(ctx).length === 0 ? [] : [`${indent}and ${keptRowSql("m -> 'keep'", permission)}`];
|
|
1101
|
+
}
|
|
1102
|
+
/** Entries of a compact custom-role claim (`cg.g`) that match `where`. */
|
|
1103
|
+
function claimEntries(where, value) {
|
|
1104
|
+
return `array(select ${value} from jsonb_array_elements_text(cg.g) e where ${where})`;
|
|
1105
|
+
}
|
|
1106
|
+
/** `p_grant in (select permdock_custom_keys(allows, denies, includes, scope))`. */
|
|
1107
|
+
function customKeysSql(ctx, scope, allows, denies, includes) {
|
|
1108
|
+
return ` and p_grant in (select ${qualified(ctx, CUSTOM_ROLES.keys)}(
|
|
1109
|
+
${allows},
|
|
1110
|
+
${denies},
|
|
1111
|
+
${includes},
|
|
1112
|
+
${quoteLiteral(scope)}
|
|
1113
|
+
))`;
|
|
1114
|
+
}
|
|
1115
|
+
function tableFilters(ctx, scope, table, tenantColumn, grant) {
|
|
1116
|
+
const filters = [];
|
|
1117
|
+
if (table.expiresAt !== void 0) {
|
|
1118
|
+
const expires = memberColumn(table.expiresAt);
|
|
1119
|
+
filters.push(` and (${expires} is null or ${expires} > now())`);
|
|
1120
|
+
}
|
|
1121
|
+
filters.push(...activeMembershipSql(ctx, disabledColumn(table), grantPermissionSql(grant)).map((part) => ` and ${part}`));
|
|
1122
|
+
if (tenantColumn !== void 0 && ctx.tenants !== "all") filters.push(` and (${activeTenant(ctx)} is null or ${memberColumn(tenantColumn)}::text = ${activeTenant(ctx)})`);
|
|
1123
|
+
const keyed = keyTenantSql(ctx, tenantColumn === void 0 ? void 0 : memberColumn(tenantColumn));
|
|
1124
|
+
if (keyed !== void 0) filters.push(` and ${keyed}`);
|
|
1125
|
+
const user = activeUserChecks(ctx, memberColumn(table.user), "act_user", " ");
|
|
1126
|
+
const instances = activeInstanceChecks(ctx, scope, (name) => {
|
|
1127
|
+
const held = scopeColumn(table, ctx.scopes, name);
|
|
1128
|
+
return held === void 0 ? void 0 : memberColumn(held);
|
|
1129
|
+
}, (name) => `act_${name}`, " ", grantPermissionSql(grant));
|
|
1130
|
+
filters.push(...instances.filters.map((part) => ` and ${part}`));
|
|
1131
|
+
return {
|
|
1132
|
+
owner: ` where ${memberColumn(table.user)} = ${subjectIdSql(ctx)}`,
|
|
1133
|
+
joins: [...user.joins, ...instances.joins],
|
|
1134
|
+
filters
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
function tableBranch(ctx, scope, type, table, column, tenantColumn, branch, set, declared, stale, holder) {
|
|
1138
|
+
const checks = tableFilters(ctx, scope, table, tenantColumn, branch === "custom" && set ? "ck.grant_key" : set ? "rp.grant_key" : "p_grant");
|
|
1139
|
+
const role = memberRoleOf(table, "m", " ");
|
|
1140
|
+
const kind = kindFilterSql(ctx, role.sql, memberVia(table));
|
|
1141
|
+
const gate = stale === true ? [` and not (select ${qualified(ctx, HELPERS.tokenCurrent)}())`] : [];
|
|
1142
|
+
const custom = ctx.customRoles;
|
|
1143
|
+
const shared = branch === "custom" && !set && custom !== void 0;
|
|
1144
|
+
const selected = holder === void 0 ? `${memberColumn(column)}::${type}` : `${memberColumn(table.user)}::${holder.userType}`;
|
|
1145
|
+
return [
|
|
1146
|
+
branch === "declared" ? ` select${role.lateral ? " distinct" : ""} ${selected}${set ? ", rp.grant_key" : ""}` : shared ? ` select ${memberColumn(column)}::${type} as id, pdk_e.keys` : ` select ${selected}, ck.grant_key`,
|
|
1147
|
+
` from ${quoteQualified(table.table)} m${role.join}`,
|
|
1148
|
+
...checks.joins,
|
|
1149
|
+
...shared ? [` cross join lateral (${customKeysArrayQuery(ctx, probeOf(ctx, scope, column, tenantColumn, role.sql))}) pdk_e`] : [],
|
|
1150
|
+
...branch === "custom" && set && custom !== void 0 ? [` cross join lateral (${customKeysQuery(ctx, probeOf(ctx, scope, column, tenantColumn, role.sql))}) ck(grant_key)`] : [],
|
|
1151
|
+
...branch === "declared" ? rpJoin(ctx, scope, role.sql, set, " ").split("\n").filter((line) => line !== "") : [],
|
|
1152
|
+
holder === void 0 ? checks.owner : ` where ${memberColumn(column)} = ${holder.instance}`,
|
|
1153
|
+
...gate,
|
|
1154
|
+
...branch === "declared" ? [...rpConds(ctx, scope, role.sql, set).map((cond) => ` and ${cond}`), ...kind === void 0 ? [] : [` and ${kind}`]] : [` and not (${role.sql} = any(${sqlTextArray(declared)}))`],
|
|
1155
|
+
...checks.filters
|
|
1156
|
+
].join("\n");
|
|
1157
|
+
}
|
|
1158
|
+
function probeOf(ctx, scope, column, tenantColumn, roleSql) {
|
|
1159
|
+
return {
|
|
1160
|
+
scope,
|
|
1161
|
+
role: roleSql,
|
|
1162
|
+
tenant: `(${memberColumn(tenantColumn ?? column)})::${tenantTypeOf(ctx)}`,
|
|
1163
|
+
instance: `${memberColumn(column)}::text`
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
function tableBody(ctx, scope, type) {
|
|
1167
|
+
const mapped = scopeTable(ctx, scope);
|
|
1168
|
+
if (mapped === void 0) return ` select null::${type}${ctx.grantSet === true ? ", null::text" : ""} where false -- no ${scope} memberships table configured`;
|
|
1169
|
+
const { table, column, tenantColumn } = mapped;
|
|
1170
|
+
const set = ctx.grantSet === true;
|
|
1171
|
+
const custom = ctx.customRoles;
|
|
1172
|
+
const branches = [];
|
|
1173
|
+
if (ctx.claimsFirst === true && !set) {
|
|
1174
|
+
branches.push(claimDeclaredBody(ctx, scope, type));
|
|
1175
|
+
branches.push(tableBranch(ctx, scope, type, table, column, tenantColumn, "declared", set, [], true));
|
|
1176
|
+
} else branches.push(tableBranch(ctx, scope, type, table, column, tenantColumn, "declared", set, []));
|
|
1177
|
+
if (custom === void 0) return branches.join("\n union\n");
|
|
1178
|
+
const held = tableBranch(ctx, scope, type, table, column, tenantColumn, "custom", set, custom.declared);
|
|
1179
|
+
if (set) return [...branches, held].join("\n union\n");
|
|
1180
|
+
return withCustomKeys(held, branches, "p_grant");
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* `(user_id, grant_key)` for every member of the instance `instance` of `scope`
|
|
1184
|
+
* and each grant key their membership holds there, through declared and custom
|
|
1185
|
+
* roles, with the same expiry, suspension, disabled and kind filters as
|
|
1186
|
+
* `permitted_<scope>_ids_for`. `undefined` unless the scope's memberships are
|
|
1187
|
+
* one table, the only form a holder list reads in one query.
|
|
1188
|
+
*/
|
|
1189
|
+
function holderBody(ctx, scope, userType, instance) {
|
|
1190
|
+
const mapped = scopeTable(ctx, scope);
|
|
1191
|
+
if (mapped === void 0 || scopeSources(ctx, scope).length > 0) return;
|
|
1192
|
+
const { table, column, tenantColumn } = mapped;
|
|
1193
|
+
const holder = {
|
|
1194
|
+
userType,
|
|
1195
|
+
instance
|
|
1196
|
+
};
|
|
1197
|
+
const branch = (kind, declared) => tableBranch(ctx, scope, userType, table, column, tenantColumn, kind, true, declared, false, holder);
|
|
1198
|
+
const custom = ctx.customRoles;
|
|
1199
|
+
return custom === void 0 ? branch("declared", []) : [branch("declared", []), branch("custom", custom.declared)].join("\n union\n");
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* The branches of a body asked by one grant key, with the custom roles' branch
|
|
1203
|
+
* over `pdk_m`: one row per membership with the compiled keys of its role.
|
|
1204
|
+
*/
|
|
1205
|
+
function withCustomKeys(members, declared, grant) {
|
|
1206
|
+
const held = ` select pdk_m.id from pdk_m
|
|
1207
|
+
where ${grant} = any(pdk_m.keys)`;
|
|
1208
|
+
return ` with pdk_m as (
|
|
1209
|
+
${members}
|
|
1210
|
+
)
|
|
1211
|
+
${[...declared, held].join("\n union\n")}`;
|
|
1212
|
+
}
|
|
1213
|
+
/** The membership's instance of the first scope, from the canonical claim. */
|
|
1214
|
+
function claimTenant(ctx, scope) {
|
|
1215
|
+
const root = rootName(ctx);
|
|
1216
|
+
return scope === root ? `m ->> 'id'` : `m -> 'within' ->> ${quoteLiteral(root)}`;
|
|
1217
|
+
}
|
|
1218
|
+
function claimDeclaredBody(ctx, scope, type) {
|
|
1219
|
+
const grant = "p_grant";
|
|
1220
|
+
const narrow = narrowsTo(ctx, scope) ? `\n and (${activeTenant(ctx)} is null or ${claimTenant(ctx, scope)} = ${activeTenant(ctx)})` : "";
|
|
1221
|
+
const user = activeUserChecks(ctx, subjectIdSql(ctx), "act_user", " ");
|
|
1222
|
+
const instances = activeInstanceChecks(ctx, scope, (name) => name === scope ? `m ->> 'id'` : `m -> 'within' ->> ${quoteLiteral(name)}`, (name) => `act_${name}`, " ", grantPermissionSql(grant));
|
|
1223
|
+
const filters = [
|
|
1224
|
+
` and (select ${qualified(ctx, HELPERS.tokenCurrent)}())`,
|
|
1225
|
+
` and m ->> 'scope' = ${quoteLiteral(scope)}`,
|
|
1226
|
+
` and m ->> 'id' is not null${narrow}${keyTenantLine(ctx, scope, claimTenant(ctx, scope))}`,
|
|
1227
|
+
` and case jsonb_typeof(m -> 'expires_at')
|
|
1228
|
+
when 'number' then (m ->> 'expires_at')::numeric > extract(epoch from now())
|
|
1229
|
+
else true
|
|
1230
|
+
end`,
|
|
1231
|
+
...claimKeptLines(ctx, " ", grantPermissionSql(grant)),
|
|
1232
|
+
...instances.filters.map((part) => ` and ${part}`)
|
|
1233
|
+
];
|
|
1234
|
+
const kind = kindFilterSql(ctx, "r.role", "m ->> 'via'");
|
|
1235
|
+
return [
|
|
1236
|
+
` select (m ->> 'id')::${type}`,
|
|
1237
|
+
` from ${membershipRows(ctx)}`,
|
|
1238
|
+
...user.joins,
|
|
1239
|
+
...instances.joins,
|
|
1240
|
+
...rpJoin(ctx, scope, "r.role", false, " ").split("\n").filter((line) => line !== ""),
|
|
1241
|
+
` where ${signedIn(ctx)}`,
|
|
1242
|
+
...rpConds(ctx, scope, "r.role", false).map((cond) => ` and ${cond}`),
|
|
1243
|
+
...kind === void 0 ? [] : [` and ${kind}`],
|
|
1244
|
+
...filters
|
|
1245
|
+
].join("\n");
|
|
1246
|
+
}
|
|
1247
|
+
function claimBody(ctx, scope, type) {
|
|
1248
|
+
const set = ctx.grantSet === true;
|
|
1249
|
+
const narrow = narrowsTo(ctx, scope) ? `
|
|
1250
|
+
and (${activeTenant(ctx)} is null or ${claimTenant(ctx, scope)} = ${activeTenant(ctx)})` : "";
|
|
1251
|
+
const filtersFor = (grant) => ` and m ->> 'scope' = ${quoteLiteral(scope)}
|
|
1252
|
+
and m ->> 'id' is not null${narrow}${keyTenantLine(ctx, scope, claimTenant(ctx, scope))}
|
|
1253
|
+
and case jsonb_typeof(m -> 'expires_at')
|
|
1254
|
+
when 'number' then (m ->> 'expires_at')::numeric > extract(epoch from now())
|
|
1255
|
+
else true
|
|
1256
|
+
end${[
|
|
1257
|
+
...claimKeptLines(ctx, " ", grantPermissionSql(grant)),
|
|
1258
|
+
...userActive(ctx, " "),
|
|
1259
|
+
...instancesActive(ctx, scope, (name) => name === scope ? `m ->> 'id'` : `m -> 'within' ->> ${quoteLiteral(name)}`, " ", grantPermissionSql(grant))
|
|
1260
|
+
].map((line) => `\n${line}`).join("")}`;
|
|
1261
|
+
const filters = filtersFor(set ? "rp.grant_key" : "p_grant");
|
|
1262
|
+
const declared = ` select (m ->> 'id')::${type}${set ? ", rp.grant_key" : ""}
|
|
1263
|
+
from ${membershipRows(ctx)}
|
|
1264
|
+
${rpJoin(ctx, scope, "r.role", set, " ")} where ${signedIn(ctx)}${rpWhere(ctx, scope, "r.role", set, " ")}${andLine(" ", kindFilterSql(ctx, "r.role", "m ->> 'via'"))}
|
|
1265
|
+
${filters}`;
|
|
1266
|
+
const custom = ctx.customRoles;
|
|
1267
|
+
if (custom === void 0) return declared;
|
|
1268
|
+
if (set) return `${declared}
|
|
1269
|
+
union
|
|
1270
|
+
select (m ->> 'id')::${type}, ck.grant_key
|
|
1271
|
+
from ${membershipRows(ctx)}
|
|
1272
|
+
cross join lateral (select m -> 'grants' -> r.role as g) cg
|
|
1273
|
+
${customKeysJoin(ctx, scope, claimEntries("left(e, 1) not in ('-', '@')", "e"), claimEntries("left(e, 1) = '-'", "substr(e, 2)"), claimEntries("left(e, 1) = '@'", "substr(e, 2)"))}
|
|
1274
|
+
where ${signedIn(ctx)}
|
|
1275
|
+
and jsonb_typeof(cg.g) = 'array'
|
|
1276
|
+
and not (r.role = any(${sqlTextArray(custom.declared)}))
|
|
1277
|
+
${filtersFor("ck.grant_key")}`;
|
|
1278
|
+
return `${declared}
|
|
1279
|
+
union
|
|
1280
|
+
select (m ->> 'id')::${type}
|
|
1281
|
+
from ${membershipRows(ctx)}
|
|
1282
|
+
cross join lateral (select m -> 'grants' -> r.role as g) cg
|
|
1283
|
+
where ${signedIn(ctx)}
|
|
1284
|
+
and jsonb_typeof(cg.g) = 'array'
|
|
1285
|
+
and not (r.role = any(${sqlTextArray(custom.declared)}))
|
|
1286
|
+
${filters}
|
|
1287
|
+
${customKeysSql(ctx, scope, claimEntries("left(e, 1) not in ('-', '@')", "e"), claimEntries("left(e, 1) = '-'", "substr(e, 2)"), claimEntries("left(e, 1) = '@'", "substr(e, 2)"))}`;
|
|
1288
|
+
}
|
|
1289
|
+
/**
|
|
1290
|
+
* The rows the membership sources select for the subject, one per instance
|
|
1291
|
+
* (`scope`, `id`, `within`, `roles`, `via`), with each source's own expiry and
|
|
1292
|
+
* suspension filters: the statements the token hook runs.
|
|
1293
|
+
*/
|
|
1294
|
+
function sourcesKeep(sources) {
|
|
1295
|
+
return sources.some((source) => source.sql.keeps);
|
|
1296
|
+
}
|
|
1297
|
+
function sourceRows(sources) {
|
|
1298
|
+
const keep = sourcesKeep(sources);
|
|
1299
|
+
return sources.map((source, index) => source.sql.select(sourceUser(index), keep).replaceAll(/^/gmu, " ")).join("\n union all\n");
|
|
1300
|
+
}
|
|
1301
|
+
function sourceUser(index) {
|
|
1302
|
+
return `v_user_${String(index)}`;
|
|
1303
|
+
}
|
|
1304
|
+
function memoizes(ctx) {
|
|
1305
|
+
return ctx.noMemo !== true && ctx.authorize === "database" && ctx.dialect === "supabase" && ctx.grantSet !== true && ctx.subjectId === void 0;
|
|
1306
|
+
}
|
|
1307
|
+
function sqlBody(sql) {
|
|
1308
|
+
return {
|
|
1309
|
+
sql,
|
|
1310
|
+
vars: []
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
function sourcesBodyOf(sql, sources, user) {
|
|
1314
|
+
return {
|
|
1315
|
+
sql,
|
|
1316
|
+
vars: sources.map((source, index) => `${sourceUser(index)} ${source.sql.userType} := ${user};`)
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
/** SQL reading the memo at `key`: a text value, or null when unset. */
|
|
1320
|
+
function memoReadSql(api, key) {
|
|
1321
|
+
return api === "better-supabase" ? `better_supabase.memo_get(${key})` : `nullif(current_setting(${key}, true), '')`;
|
|
1322
|
+
}
|
|
1323
|
+
/** SQL writing `value` to the memo at `key`. */
|
|
1324
|
+
function memoWriteSql(api, key, value) {
|
|
1325
|
+
return api === "better-supabase" ? `better_supabase.memo_set(${key}, ${value})` : `set_config(${key}, ${value}, true)`;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* The volatile memo for a relation-id helper. A generation bump misses, so a
|
|
1329
|
+
* fresh evaluation that denies is not answered from an earlier allow.
|
|
1330
|
+
*/
|
|
1331
|
+
function memoizedSetofSql(input) {
|
|
1332
|
+
const disc = memoDiscriminatorSql("v_user", input.keySql);
|
|
1333
|
+
const read = memoReadSql(input.api, "v_key");
|
|
1334
|
+
const write = memoWriteSql(input.api, "v_key", "jsonb_build_object('k', v_disc, 'ids', to_jsonb(v_ids))::text");
|
|
1335
|
+
return `create or replace function ${input.fn}(${input.param})
|
|
1336
|
+
returns ${input.returns}
|
|
1337
|
+
language plpgsql
|
|
1338
|
+
volatile
|
|
1339
|
+
security definer
|
|
1340
|
+
cost 1000
|
|
1341
|
+
set search_path = ''
|
|
1342
|
+
as $$
|
|
1343
|
+
declare
|
|
1344
|
+
v_user text := ${input.userSql}::text;
|
|
1345
|
+
v_key text := 'permdock.m.' || ${quoteLiteral(input.scope)} || '.k' || (hashtext(${input.keySql}) & 1023)::text;
|
|
1346
|
+
v_disc text := ${disc};
|
|
1347
|
+
v_memo text := ${read};
|
|
1348
|
+
v_ids ${input.idType}[];
|
|
1349
|
+
begin
|
|
1350
|
+
if v_memo is not null and (v_memo::jsonb ->> 'k') = v_disc then
|
|
1351
|
+
v_ids := array(select jsonb_array_elements_text(v_memo::jsonb -> 'ids')::${input.idType});
|
|
1352
|
+
else
|
|
1353
|
+
v_ids := array(
|
|
1354
|
+
${input.query}
|
|
1355
|
+
);
|
|
1356
|
+
${input.cap === void 0 ? `perform ${write};` : `if cardinality(v_ids) <= ${String(input.cap)} then
|
|
1357
|
+
perform ${write};
|
|
1358
|
+
end if;`}
|
|
1359
|
+
end if;
|
|
1360
|
+
return query select unnest(v_ids);
|
|
1361
|
+
end;
|
|
1362
|
+
$$;
|
|
1363
|
+
${input.grants}`;
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Ids from a memoized helper. A hit reads the stored ids and does not call the
|
|
1367
|
+
* helper; a miss calls it, which stores them. The key matches the helper's.
|
|
1368
|
+
*/
|
|
1369
|
+
function memoHitList(scope, keySql, call, userSql, api, idType = "text") {
|
|
1370
|
+
const setting = `'permdock.m.' || ${quoteLiteral(scope)} || '.k' || (hashtext(${keySql}) & 1023)::text`;
|
|
1371
|
+
const disc = memoDiscriminatorSql(userSql, keySql);
|
|
1372
|
+
const read = api === "better-supabase" ? `nullif(better_supabase.memo_get(${setting}), '')::jsonb` : `nullif(current_setting(${setting}, true), '')::jsonb`;
|
|
1373
|
+
return `select e::${idType} from jsonb_array_elements_text(case when (${read} ->> 'k') = ${disc} then ${read} -> 'ids' else to_jsonb(array(select * from ${call})) end) s(e)`;
|
|
1374
|
+
}
|
|
1375
|
+
function memoDiscriminatorSql(user, key) {
|
|
1376
|
+
return `md5(concat_ws('|',
|
|
1377
|
+
${user},
|
|
1378
|
+
${key},
|
|
1379
|
+
coalesce((select auth.jwt()) ->> 'authz_ver', ''),
|
|
1380
|
+
coalesce(nullif(current_setting('permdock.m.gen', true), ''), '0'),
|
|
1381
|
+
coalesce((select auth.jwt()) ->> 'session_id', ''),
|
|
1382
|
+
statement_timestamp()::text
|
|
1383
|
+
))`;
|
|
1384
|
+
}
|
|
1385
|
+
/** The planner's row estimate for a memoised id-set helper. */
|
|
1386
|
+
const SETOF_ROWS = 10;
|
|
1387
|
+
/**
|
|
1388
|
+
* `language sql`, or `plpgsql` returning the query when the body declares
|
|
1389
|
+
* variables.
|
|
1390
|
+
*/
|
|
1391
|
+
function functionBody(body, parallelSafe = false, setof = false) {
|
|
1392
|
+
const planner = `cost 1000${setof ? `\nrows ${String(SETOF_ROWS)}` : ""}${parallelSafe ? "\nparallel safe" : ""}`;
|
|
1393
|
+
if (body.memo !== void 0) {
|
|
1394
|
+
const declare = [
|
|
1395
|
+
...body.vars,
|
|
1396
|
+
`v_user text := ${body.memo.user}::text;`,
|
|
1397
|
+
`v_key text := 'permdock.m.' || ${quoteLiteral(body.memo.scope)} || '.k' || (hashtext(p_grant) & 1023)::text;`,
|
|
1398
|
+
`v_disc text := ${memoDiscriminatorSql("v_user", "p_grant")};`,
|
|
1399
|
+
`v_memo text := ${memoReadSql(body.memo.api, "v_key")};`
|
|
1400
|
+
];
|
|
1401
|
+
if (body.memo.type === "boolean") return `language plpgsql
|
|
1402
|
+
volatile
|
|
1403
|
+
security definer
|
|
1404
|
+
cost 1000
|
|
1405
|
+
set search_path = ''
|
|
1406
|
+
as $$
|
|
1407
|
+
declare
|
|
1408
|
+
${[...declare, "v_has boolean;"].map((line) => ` ${line}`).join("\n")}
|
|
1409
|
+
begin
|
|
1410
|
+
if v_memo is not null and (v_memo::jsonb ->> 'k') = v_disc then
|
|
1411
|
+
return (v_memo::jsonb ->> 'v')::boolean;
|
|
1412
|
+
end if;
|
|
1413
|
+
v_has := (
|
|
1414
|
+
${body.sql}
|
|
1415
|
+
);
|
|
1416
|
+
perform ${memoWriteSql(body.memo.api, "v_key", "jsonb_build_object('k', v_disc, 'v', v_has)::text")};
|
|
1417
|
+
return v_has;
|
|
1418
|
+
end;
|
|
1419
|
+
$$;`;
|
|
1420
|
+
declare.push(`v_ids ${body.memo.type}[];`);
|
|
1421
|
+
return `language plpgsql
|
|
1422
|
+
volatile
|
|
1423
|
+
security definer
|
|
1424
|
+
cost 1000
|
|
1425
|
+
rows ${SETOF_ROWS}
|
|
1426
|
+
set search_path = ''
|
|
1427
|
+
as $$
|
|
1428
|
+
declare
|
|
1429
|
+
${declare.map((line) => ` ${line}`).join("\n")}
|
|
1430
|
+
begin
|
|
1431
|
+
if v_memo is not null and (v_memo::jsonb ->> 'k') = v_disc then
|
|
1432
|
+
v_ids := array(select jsonb_array_elements_text(v_memo::jsonb -> 'ids')::${body.memo.type});
|
|
1433
|
+
else
|
|
1434
|
+
v_ids := array(
|
|
1435
|
+
${body.sql}
|
|
1436
|
+
);
|
|
1437
|
+
perform ${memoWriteSql(body.memo.api, "v_key", "jsonb_build_object('k', v_disc, 'ids', to_jsonb(v_ids))::text")};
|
|
1438
|
+
end if;
|
|
1439
|
+
return query select unnest(v_ids);
|
|
1440
|
+
end;
|
|
1441
|
+
$$;`;
|
|
1442
|
+
}
|
|
1443
|
+
if (body.vars.length === 0) return `language sql
|
|
1444
|
+
stable
|
|
1445
|
+
security definer
|
|
1446
|
+
${planner}
|
|
1447
|
+
set search_path = ''
|
|
1448
|
+
as $$
|
|
1449
|
+
${body.sql}
|
|
1450
|
+
$$;`;
|
|
1451
|
+
return `language plpgsql
|
|
1452
|
+
stable
|
|
1453
|
+
security definer
|
|
1454
|
+
${planner}
|
|
1455
|
+
set search_path = ''
|
|
1456
|
+
as $$
|
|
1457
|
+
declare
|
|
1458
|
+
${body.vars.map((line) => ` ${line}`).join("\n")}
|
|
1459
|
+
begin
|
|
1460
|
+
return query
|
|
1461
|
+
${body.sql};
|
|
1462
|
+
end;
|
|
1463
|
+
$$;`;
|
|
1464
|
+
}
|
|
1465
|
+
/**
|
|
1466
|
+
* `ms.id` for the scope itself and `ms.within ->> name` for an ancestor. The
|
|
1467
|
+
* alias is not `s`, which `activeRowSql` binds inside its `exists`.
|
|
1468
|
+
*/
|
|
1469
|
+
function sourceIdOf(scope) {
|
|
1470
|
+
return (name) => name === scope ? "ms.id" : `ms.within ->> ${quoteLiteral(name)}`;
|
|
1471
|
+
}
|
|
1472
|
+
function sourceFilters(ctx, scope, user = subjectIdSql(ctx), permission, keeps = false) {
|
|
1473
|
+
return [
|
|
1474
|
+
...keeps ? [` and ${keptRowSql("ms.keep", permission)}`] : [],
|
|
1475
|
+
...userActive(ctx, " ", user),
|
|
1476
|
+
...instancesActive(ctx, scope, sourceIdOf(scope), " ", permission)
|
|
1477
|
+
].map((line) => `\n${line}`).join("");
|
|
1478
|
+
}
|
|
1479
|
+
function sourcesBody(ctx, scope, type) {
|
|
1480
|
+
const root = rootName(ctx);
|
|
1481
|
+
const tenant = sourceIdOf(scope)(root);
|
|
1482
|
+
const narrow = narrowsTo(ctx, scope) ? `\n and (${activeTenant(ctx)} is null or ${tenant} = ${activeTenant(ctx)})${keyTenantLine(ctx, scope, tenant)}` : keyTenantLine(ctx, scope, tenant);
|
|
1483
|
+
const sources = scopeSources(ctx, scope);
|
|
1484
|
+
const set = ctx.grantSet === true;
|
|
1485
|
+
const rows = ` from (
|
|
1486
|
+
${sourceRows(sources)}
|
|
1487
|
+
) ms
|
|
1488
|
+
cross join lateral jsonb_array_elements_text(
|
|
1489
|
+
case jsonb_typeof(ms.roles) when 'array' then ms.roles else '[]'::jsonb end
|
|
1490
|
+
) r(role)`;
|
|
1491
|
+
const declared = ` select (ms.id)::${type}${set ? ", rp.grant_key" : ""}
|
|
1492
|
+
${rows}
|
|
1493
|
+
${rpJoin(ctx, scope, "r.role", set, " ")} where ${signedIn(ctx)}
|
|
1494
|
+
and ms.scope = ${quoteLiteral(scope)}${rpWhere(ctx, scope, "r.role", set, " ")}${andLine(" ", kindFilterSql(ctx, "r.role", "ms.via"))}${narrow}${sourceFilters(ctx, scope, subjectIdSql(ctx), grantPermissionSql(set ? "rp.grant_key" : "p_grant"), sourcesKeep(sources))}`;
|
|
1495
|
+
const custom = ctx.customRoles;
|
|
1496
|
+
if (custom === void 0) return sourcesBodyOf(declared, sources, subjectIdSql(ctx));
|
|
1497
|
+
const keys = customKeysQuery(ctx, {
|
|
1498
|
+
scope,
|
|
1499
|
+
role: "r.role",
|
|
1500
|
+
tenant: `(${tenant})::${tenantTypeOf(ctx)}`,
|
|
1501
|
+
instance: "(ms.id)::text"
|
|
1502
|
+
});
|
|
1503
|
+
if (set) return sourcesBodyOf(`${declared}
|
|
1504
|
+
union
|
|
1505
|
+
select (ms.id)::${type}, ck.grant_key
|
|
1506
|
+
${rows}
|
|
1507
|
+
cross join lateral (${keys}) ck(grant_key)
|
|
1508
|
+
where ${signedIn(ctx)}
|
|
1509
|
+
and ms.scope = ${quoteLiteral(scope)}
|
|
1510
|
+
and not (r.role = any(${sqlTextArray(custom.declared)}))${narrow}${sourceFilters(ctx, scope, subjectIdSql(ctx), grantPermissionSql("ck.grant_key"), sourcesKeep(sources))}`, sources, subjectIdSql(ctx));
|
|
1511
|
+
return sourcesBodyOf(withCustomKeys(` select (ms.id)::${type} as id, pdk_e.keys
|
|
1512
|
+
${rows}
|
|
1513
|
+
cross join lateral (${customKeysArrayQuery(ctx, {
|
|
1514
|
+
scope,
|
|
1515
|
+
role: "r.role",
|
|
1516
|
+
tenant: `(${tenant})::${tenantTypeOf(ctx)}`,
|
|
1517
|
+
instance: "(ms.id)::text"
|
|
1518
|
+
})}) pdk_e
|
|
1519
|
+
where ${signedIn(ctx)}
|
|
1520
|
+
and ms.scope = ${quoteLiteral(scope)}
|
|
1521
|
+
and not (r.role = any(${sqlTextArray(custom.declared)}))${narrow}${sourceFilters(ctx, scope, subjectIdSql(ctx), grantPermissionSql("p_grant"), sourcesKeep(sources))}`, [declared], "p_grant"), sources, subjectIdSql(ctx));
|
|
1522
|
+
}
|
|
1523
|
+
function scopedBody(ctx, scope, type) {
|
|
1524
|
+
if (ctx.authorize !== "database") return sqlBody(claimBody(ctx, scope, type));
|
|
1525
|
+
return scopeSources(ctx, scope).length > 0 ? sourcesBody(ctx, scope, type) : sqlBody(tableBody(ctx, scope, type));
|
|
1526
|
+
}
|
|
1527
|
+
// src/cli/rls/interactive-only.ts
|
|
1528
|
+
const INTERACTIVE_ALLOWS = "permdock_interactive_allows";
|
|
1529
|
+
function interactiveOnlyKeys(policy) {
|
|
1530
|
+
const keys = listPermissions(policy.permissions).filter((leaf) => leaf.meta.interactiveOnly === true).map((leaf) => leaf.key).toSorted();
|
|
1531
|
+
return keys.length === 0 ? void 0 : keys;
|
|
1532
|
+
}
|
|
1533
|
+
function absent(json) {
|
|
1534
|
+
return `(${json} is null or ${json} = 'null'::jsonb)`;
|
|
1535
|
+
}
|
|
1536
|
+
function interactiveSessionSql(ctx) {
|
|
1537
|
+
return `(${[
|
|
1538
|
+
...[.../* @__PURE__ */ new Set(["api_key", ctx.apiKeys?.claim ?? "api_key"])].map((claim) => absent(subjectClaimJsonSql(ctx, claim))),
|
|
1539
|
+
`coalesce(${subjectClaimSql(ctx, "client_id")}, '') = ''`,
|
|
1540
|
+
absent(subjectClaimJsonSql(ctx, "act"))
|
|
1541
|
+
].join(" and ")})`;
|
|
1542
|
+
}
|
|
1543
|
+
function interactiveAllowsCall(ctx, grant) {
|
|
1544
|
+
return `${qualified(ctx, INTERACTIVE_ALLOWS)}(${grant})`;
|
|
1545
|
+
}
|
|
1546
|
+
function interactiveAllowsSql(ctx, keys, anonExecute) {
|
|
1547
|
+
const fn = qualified(ctx, INTERACTIVE_ALLOWS);
|
|
1548
|
+
const grants = anonExecute ? `revoke execute on function ${fn}(text) from public;
|
|
1549
|
+
grant execute on function ${fn}(text) to anon, authenticated;` : `revoke execute on function ${fn}(text) from public, anon;
|
|
1550
|
+
grant execute on function ${fn}(text) to authenticated;`;
|
|
1551
|
+
return `-- Interactive-only permissions: only a user's own session holds them; an API key, an OAuth client or an act chain never does, whatever its scopes
|
|
1552
|
+
create or replace function ${fn}(p_grant text)
|
|
1553
|
+
returns boolean
|
|
1554
|
+
language sql
|
|
1555
|
+
stable
|
|
1556
|
+
security definer
|
|
1557
|
+
set search_path = ''
|
|
1558
|
+
as $$
|
|
1559
|
+
select split_part(split_part(p_grant, '#', 1), '@', 1) <> all (array[${keys.map(quoteLiteral).join(", ")}]::text[])
|
|
1560
|
+
or ${interactiveSessionSql(ctx)}
|
|
1561
|
+
$$;
|
|
1562
|
+
${grants}`;
|
|
1563
|
+
}
|
|
1564
|
+
function memoUserSql(ctx, user) {
|
|
1565
|
+
return ctx.interactiveOnly === void 0 ? user : `(${user}::text || case when ${interactiveSessionSql(ctx)} then '' else '|delegated' end)`;
|
|
1566
|
+
}
|
|
1567
|
+
export { linkHelper as $, userActive as A, trustedReaderGrants as B, sourcesKeep as C, keyTenantLine as D, instancesActive as E, perScope as F, graphHelper as G, byKey as H, raiseSql as I, hasMemberFor as J, graphSqlName as K, roleReadersSql as L, currentKeyExpr as M, customRolesSql as N, membershipRows as O, hasCustomRoleChecksFor as P, isTeamScope as Q, rolesTableScope as R, sourcesBodyOf as S, globalRoleRows as T, BOOTSTRAP_PERMISSIONS as U, byCodeUnit as V, CLOSURE as W, hasPermittedUsers as X, hasMemberOf as Y, inheritedRowsHelper as Z, memoizes as _, interactiveSessionSql as a, memberRoleOf as at, sourceIdOf as b, claimTenant as c, restrictedHelper as ct, hasBody as d, activeInstancesSql as dt, memberForHelper as et, holderBody as f, activeMembershipSql as ft, memoizedSetofSql as g, grantPermissionSql as gt, memoWriteSql as h, checkSuspension as ht, interactiveOnlyKeys as i, memberOfHelper as it, globalRoleSource as j, roleRows as k, disabledColumn as l, scopeSources as lt, memoHitList as m, activeUserSql as mt, interactiveAllowsCall as n, memberForTable as nt, memoUserSql as o, permittedForHelper as ot, memberColumn as p, activeRowSql as pt, graphSqlText as q, interactiveAllowsSql as r, memberIdsHelper as rt, claimKeptLines as s, permittedIdsHelper as st, INTERACTIVE_ALLOWS as t, memberForSources as tt, functionBody as u, scopeTable as ut, scopedBody as v, sqlBody as w, sourceRows as x, sourceFilters as y, storedTenant as z };
|