permdock 0.25.1 → 0.26.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-b0_Xpab8.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-DMmcumRx.js +76 -0
- package/dist/arazzo-Hxerfx3_.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-CYwbggCS.js +29 -0
- package/dist/casbin-Co1KcLWU.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 +18 -0
- package/dist/cli/plugins/app.js +26 -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-BfEI9TLS.js +85 -0
- package/dist/codemod-DwH0IZ2x.js +2159 -0
- package/dist/codemod-p67ePW25.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-Blrr5WWw.js +724 -0
- package/dist/compile-D8c1nFGy.d.ts +118 -0
- package/dist/completion-CfrZOGcB.js +150 -0
- package/dist/conditions-CkHgXoZB.js +385 -0
- package/dist/config-D6gh_xvs.js +25 -0
- package/dist/config-iyy90IOU.js +143 -0
- package/dist/config-report-BaHEBpt-.js +55 -0
- package/dist/config-shape-B6tdyBju.js +149 -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-Bg12v-8M.js +4847 -0
- package/dist/doctor-DCsyH7YR.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-SN8_dlch.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-B4GUqsfM.js +1160 -0
- package/dist/gen-BC66z5Fd.js +1 -0
- package/dist/gen-kind-Bahz_i3U.js +67 -0
- package/dist/gen-kind-DFQnQwFN.d.ts +13 -0
- package/dist/generate-5_kz2309.js +305 -0
- package/dist/generate-B-msjuaO.js +2339 -0
- package/dist/generate-CbtjKcjn.js +67 -0
- package/dist/generate-DhP0jQDR.js +97 -0
- package/dist/generate-options-BDgadlwe.js +1104 -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-BIR4fL7i.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-BZi1tZxq.js +318 -0
- package/dist/import-BqoDHpFt.js +1158 -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-9cqnSJWG.js +95 -0
- package/dist/init-K3tKOwf4.js +94 -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-C1I5KIsK.js +67 -0
- package/dist/login-CP0UxnLw.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-DvS2IoXo.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-BHqqNSoG.js +95 -0
- package/dist/openapi-BT5XY7HY.js +260 -0
- package/dist/openapi-D2dmyWZK.js +411 -0
- package/dist/openapi-document-Ca5yAjc6.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-djxu62oH.js +244 -0
- package/dist/output-files-C5LFnQa4.js +1 -0
- package/dist/output-files-DNid6TBl.js +197 -0
- package/dist/ownership-BO0sI5FB.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-DGmbeXwA.d.ts +221 -0
- package/dist/plugin-MQVfUBUS.js +93 -0
- package/dist/plugin-outputs-BE2YCiMj.js +28 -0
- package/dist/policy-BhSUlHRr.js +37 -0
- package/dist/policy-C-Lzp3Zh.d.ts +18 -0
- package/dist/policy-DFD2J5o_.js +476 -0
- package/dist/policy-bundle-97xaDULc.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-CN7IQIKk.js +40 -0
- package/dist/powersync-DdDLP02A.js +1630 -0
- package/dist/powersync-m9uYgCFF.js +1 -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-9oQvY18T.js +252 -0
- package/dist/pull-jvJPMQhP.js +1 -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-Cmg6SPAa.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-BrsMogAP.js +321 -0
- package/dist/rls-Cv1V8YfI.js +946 -0
- package/dist/rls-files-Bj446vbj.js +114 -0
- package/dist/rls-options-Dpj_pEyU.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-DX4D6S6V.js +726 -0
- package/dist/run-decqEKNa.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-Cj7PQLrS.js +28 -0
- package/dist/schema-BeY3croo.js +403 -0
- package/dist/schema-CJPvTfeN.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-B5bc6JIA.js +50 -0
- package/dist/skills-Cr1C0b9D.js +202 -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-BG1HPdQU.js +30 -0
- package/dist/supabase-BI5ZhzLl.js +792 -0
- package/dist/supabase-config-mXcggV5I.js +890 -0
- package/dist/supabase-hook-hd9abKy4.js +2 -0
- package/dist/supabase-hook-tdR45aXY.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-CRTCBuFi.js +3240 -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-D8VXQxKL.d.ts +1231 -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/unplugin/index.d.ts +1 -3
- package/dist/unplugin/index.js +3 -4
- package/dist/usage-B-E747wO.js +31 -0
- package/dist/usage-B7nx0_aa.js +761 -0
- package/dist/usage-rqQ9ViXv.js +1 -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-9HObfifg.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
package/dist/doctor-Dvt1_ROJ.js
DELETED
|
@@ -1,3560 +0,0 @@
|
|
|
1
|
-
import { r as isRecord } from "./compact-CAf557ZB.js";
|
|
2
|
-
import { o as hasConditionOp, u as isSqlFunctionField } from "./refs-C8BKxc_e.js";
|
|
3
|
-
import { c as listPermissions, h as formerKeys } from "./permission-registry-B8tYxPIt.js";
|
|
4
|
-
import { u as isPrincipalRelation } from "./resource-relations-8-pCScBO.js";
|
|
5
|
-
import { o as flattenGrantee } from "./grantee-OG4klcNr.js";
|
|
6
|
-
import { c as rootScope, d as scopeList, o as normalizeMemberships, s as resolveScope } from "./scopes-gdH__vDZ.js";
|
|
7
|
-
import { t as canonicalJson } from "./canonical-json-DwilZ1iB.js";
|
|
8
|
-
import { u as separationConflicts } from "./policy-DnNOTENd.js";
|
|
9
|
-
import { T as validateCustomRole } from "./evaluate-BQ2nWOki.js";
|
|
10
|
-
import { s as parseCredential } from "./credential-BMsbcaeP.js";
|
|
11
|
-
import "./authz-topic-Dbc-HDOS.js";
|
|
12
|
-
import { a as describeError, i as configError } from "./errors-BhRkoNS7.js";
|
|
13
|
-
import { t as policyRowConditionKeys } from "./row-conditions-BAGHOmVq.js";
|
|
14
|
-
import { a as rel, n as doctorSrcPath, o as sqlFiles, r as listSourceFiles } from "./files-BSjrtIHw.js";
|
|
15
|
-
import { i as DOCTOR_REPORT_SCHEMA } from "./version-DMQ0dnN5.js";
|
|
16
|
-
import { c as jsonSchemaOf, i as catalogOAuthScopes } from "./catalog-doc-DnQDviXY.js";
|
|
17
|
-
import { r as parseSync, t as createVisitor } from "./optional-8TKc-0j4.js";
|
|
18
|
-
import { a as loadModule, i as loadConfiguredPolicy, n as asPolicy, s as pickNamed } from "./load-C4p4VgwR.js";
|
|
19
|
-
import { t as catalogPath } from "./catalog-path-CnI0XTFK.js";
|
|
20
|
-
import { r as runCollect } from "./collect-BG-SXFQv.js";
|
|
21
|
-
import { n as supabaseTenantClaim } from "./budget-BBCPDOGP.js";
|
|
22
|
-
import { a as betterSupabaseInstalled, c as filesOf, i as betterSupabaseDefaults, l as nodeFiles, n as betterSupabaseAuthzVersions, o as betterSupabaseTenantClaim, r as betterSupabaseConfig, s as workspaceDirs, t as BETTER_SUPABASE_AUTHZ_TOPIC, u as readJson } from "./better-supabase-DF8f8oly.js";
|
|
23
|
-
import { t as operationCoverage } from "./coverage-CGu_Kovx.js";
|
|
24
|
-
import { i as qualifySqlTable, s as quoteSqlLiteral } from "./sql-0WjxIp9g.js";
|
|
25
|
-
import { a as scopeMembershipTable } from "./compile-Cvru58id.js";
|
|
26
|
-
import { d as keptKeys, r as PERMDOCK_SCHEMA } from "./sources-C4vkzZJV.js";
|
|
27
|
-
import { t as parseCatalog } from "./parse-CORUNcCo.js";
|
|
28
|
-
import { n as activeTenantMismatch } from "./active-tenant-DVee32-T.js";
|
|
29
|
-
import "./markers-BeHZ4x9Q.js";
|
|
30
|
-
import { t as didYouMean } from "./args-iafbHiXn.js";
|
|
31
|
-
import { t as DOCS_BASE } from "./manifest-CZ-GmsOL.js";
|
|
32
|
-
import { t as createStyle } from "./style-Ds11Hmk4.js";
|
|
33
|
-
import { a as nonEmptyOr, r as findingOf } from "./output-LDciF_4t.js";
|
|
34
|
-
import { i as runSkillsInstall } from "./skills-nPLVGtGH.js";
|
|
35
|
-
import { n as MIGRATION_DIRS, t as DEFAULT_SENSITIVE_ACTIONS } from "./constants-DcJABbLW.js";
|
|
36
|
-
import { l as partPath } from "./output-files-CM0BnH05.js";
|
|
37
|
-
import { n as pgConnector } from "./pg-Ddxsd5ZB.js";
|
|
38
|
-
import { _ as readSupabaseConfig, a as supabaseHookManifest, c as activeSource, d as resolveSchemas, g as pd074, h as pd045, l as pd039, m as attrsPlan, n as hookOut, v as supabaseConfig } from "./supabase-hook-Cf9zKz8T.js";
|
|
39
|
-
import { O as quoteIdent, t as CUSTOM_ROLES } from "./shared-DfaIWvIJ.js";
|
|
40
|
-
import { $ as byKey, c as graphPlan, i as tableNames, ot as graphSqlName, r as tableNameOf } from "./tables-DnNACfAr.js";
|
|
41
|
-
import { a as guardedTables, p as contextRefs, r as unsatisfiedKinds, t as ownershipRules } from "./ownership-DvK6INyx.js";
|
|
42
|
-
import { t as membershipSourcesOf } from "./sources-qoIJQrJv.js";
|
|
43
|
-
import { i as group, n as membershipColumns, o as sqlStatements, r as tableKey } from "./deciding-columns-NB4wcyBf.js";
|
|
44
|
-
import { t as FIELD_VIEWS } from "./fields-D9PIYlJy.js";
|
|
45
|
-
import { t as resolveNames } from "./resolve-names-D5_kABup.js";
|
|
46
|
-
import { C as splitIgnored, S as parseIgnores, d as rowConditionMessage, f as commandFor, h as tableFor, p as compileGrants, s as ROW_CONDITION_FIX, u as helperTablePolicies } from "./verify-Boehaks6.js";
|
|
47
|
-
import { a as pd010, c as pd014, d as pd038, f as pd041, i as pd008, l as pd015, n as pd001, o as pd011, p as pd057, r as pd007, s as pd013, t as runUsage, u as pd036 } from "./usage-BkDU1dYf.js";
|
|
48
|
-
import { a as streamOf, i as scopeSourcesOf, r as staleFiles, t as powersyncFiles } from "./powersync-B5YjtUGd.js";
|
|
49
|
-
import { a as buildContext, n as generateOptions, r as isRefusal, s as inheritTargets, t as supautilsRejections } from "./supautils-BREOPaHY.js";
|
|
50
|
-
import { n as legacyHelperNames, r as retirePlan, t as legacyHelperCalls } from "./retire-B2xffQgY.js";
|
|
51
|
-
import { basename, dirname, join, resolve } from "node:path";
|
|
52
|
-
import { pathToFileURL } from "node:url";
|
|
53
|
-
import { createRequire } from "node:module";
|
|
54
|
-
//#region src/cli/project/project.ts
|
|
55
|
-
function loadProject(input) {
|
|
56
|
-
const { cwd, config } = input;
|
|
57
|
-
const files = input.files ?? nodeFiles;
|
|
58
|
-
let sources;
|
|
59
|
-
let policyLoad;
|
|
60
|
-
let collected;
|
|
61
|
-
const loadPolicy = () => {
|
|
62
|
-
policyLoad ??= readPolicy(cwd, config.policy);
|
|
63
|
-
return policyLoad;
|
|
64
|
-
};
|
|
65
|
-
const policy = async () => {
|
|
66
|
-
const load = await loadPolicy();
|
|
67
|
-
return load.status === "loaded" ? load.policy : void 0;
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
cwd,
|
|
71
|
-
config,
|
|
72
|
-
files,
|
|
73
|
-
now: input.now,
|
|
74
|
-
io: input.io,
|
|
75
|
-
...input.database === void 0 ? {} : { database: input.database },
|
|
76
|
-
sources: () => {
|
|
77
|
-
sources ??= listSourceFiles(cwd, doctorSrcPath(config)).map((file) => ({
|
|
78
|
-
file: rel(cwd, file),
|
|
79
|
-
text: files.read(file)
|
|
80
|
-
}));
|
|
81
|
-
return sources;
|
|
82
|
-
},
|
|
83
|
-
policyLoad: loadPolicy,
|
|
84
|
-
policy,
|
|
85
|
-
collected: () => {
|
|
86
|
-
collected ??= runCollect({
|
|
87
|
-
cwd,
|
|
88
|
-
config,
|
|
89
|
-
collect: config.collect ?? {},
|
|
90
|
-
scanPath: doctorSrcPath(config),
|
|
91
|
-
check: true,
|
|
92
|
-
now: input.now,
|
|
93
|
-
io: input.io,
|
|
94
|
-
loadPolicy: policy
|
|
95
|
-
});
|
|
96
|
-
return collected;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
async function readPolicy(cwd, path) {
|
|
101
|
-
if (path === void 0) return { status: "unset" };
|
|
102
|
-
try {
|
|
103
|
-
return {
|
|
104
|
-
status: "loaded",
|
|
105
|
-
policy: asPolicy(pickNamed(await loadModule(resolve(cwd, path)), ["policy"]))
|
|
106
|
-
};
|
|
107
|
-
} catch (error) {
|
|
108
|
-
return {
|
|
109
|
-
status: "failed",
|
|
110
|
-
path,
|
|
111
|
-
message: describeError(error)
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region src/cli/doctor/inputs.ts
|
|
117
|
-
/** The configured policy, through the project's memoised load when there is one. */
|
|
118
|
-
function policyOf(input) {
|
|
119
|
-
const path = input.config.policy;
|
|
120
|
-
if (path === void 0) return Promise.resolve(void 0);
|
|
121
|
-
return input.policy === void 0 ? loadConfiguredPolicy(input.cwd, path) : input.policy();
|
|
122
|
-
}
|
|
123
|
-
/** `collect --check`, through the project's memoised run when there is one. */
|
|
124
|
-
function collectedOf(input) {
|
|
125
|
-
return input.collected === void 0 ? runCollect({
|
|
126
|
-
cwd: input.cwd,
|
|
127
|
-
config: input.config,
|
|
128
|
-
collect: input.config.collect ?? {},
|
|
129
|
-
scanPath: doctorSrcPath(input.config),
|
|
130
|
-
check: true,
|
|
131
|
-
now: input.now,
|
|
132
|
-
io: input.io
|
|
133
|
-
}) : input.collected();
|
|
134
|
-
}
|
|
135
|
-
function asMembershipsFixture(parsed) {
|
|
136
|
-
return parsed !== null && typeof parsed === "object" ? parsed : {};
|
|
137
|
-
}
|
|
138
|
-
function readFixture(input, path) {
|
|
139
|
-
const files = filesOf(input);
|
|
140
|
-
if (path === void 0) return;
|
|
141
|
-
const absolute = resolve(input.cwd, path);
|
|
142
|
-
if (!files.exists(absolute)) return;
|
|
143
|
-
try {
|
|
144
|
-
return readJson(files, absolute);
|
|
145
|
-
} catch {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
function listField(value, field) {
|
|
150
|
-
if (value === null || typeof value !== "object") return [];
|
|
151
|
-
const list = value[field];
|
|
152
|
-
return Array.isArray(list) ? list : [];
|
|
153
|
-
}
|
|
154
|
-
/** Reads the doctor memberships fixture, if one is configured and parseable. */
|
|
155
|
-
function membershipsFixture(input) {
|
|
156
|
-
const files = filesOf(input);
|
|
157
|
-
const fixturePath = input.config.doctor?.memberships;
|
|
158
|
-
if (fixturePath === void 0) return {};
|
|
159
|
-
const absolute = resolve(input.cwd, fixturePath);
|
|
160
|
-
if (!files.exists(absolute)) return {};
|
|
161
|
-
try {
|
|
162
|
-
return asMembershipsFixture(readJson(files, absolute));
|
|
163
|
-
} catch {
|
|
164
|
-
return {};
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/cli/doctor/assignments.ts
|
|
169
|
-
const TRIGGER = new RegExp(String.raw`^create\s+(?:or\s+replace\s+)?trigger\s+"?permdock_assignment"?\s[\s\S]*?\bon\s+((?:"[^"]+"|\w+)(?:\.(?:"[^"]+"|\w+))?)`, "iu");
|
|
170
|
-
/**
|
|
171
|
-
* The tables a `permdock_assignment` trigger is created on in the migrations
|
|
172
|
-
* and the `rls generate` output.
|
|
173
|
-
*/
|
|
174
|
-
function triggeredTables(input) {
|
|
175
|
-
const out = input.config.rls?.out ?? "rls.sql";
|
|
176
|
-
const files = sqlFiles(input.cwd, [...input.config.doctor?.migrations ?? MIGRATION_DIRS, ...new Set([
|
|
177
|
-
out,
|
|
178
|
-
partPath(out, "helpers"),
|
|
179
|
-
partPath(out, "policies")
|
|
180
|
-
].filter((file) => file.endsWith(".sql")))]);
|
|
181
|
-
const tables = /* @__PURE__ */ new Set();
|
|
182
|
-
for (const file of files) for (const statement of sqlStatements(filesOf(input).read(file))) {
|
|
183
|
-
const match = TRIGGER.exec(statement.text);
|
|
184
|
-
if (match !== null) tables.add(tableKey(group(match, 1)));
|
|
185
|
-
}
|
|
186
|
-
return tables;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* PD064: `rls.assignments` guards a table (a membership table, the global-roles
|
|
190
|
-
* table or a listed table) that no `permdock_assignment` trigger is created on
|
|
191
|
-
* in the migrations or the `rls generate` output, so a client may write any
|
|
192
|
-
* role there.
|
|
193
|
-
*/
|
|
194
|
-
async function pd064(input) {
|
|
195
|
-
if (input.config.rls?.assignments === void 0) return [];
|
|
196
|
-
const policy = await policyOf(input);
|
|
197
|
-
if (policy === void 0) return [];
|
|
198
|
-
const scopes = scopeList(policy.scopes);
|
|
199
|
-
if ((ownershipRules(policy, scopes)?.assigns.length ?? 0) === 0) return [];
|
|
200
|
-
const found = triggeredTables(input);
|
|
201
|
-
return guardedTables(input.config, scopes).filter((table) => !found.has(tableKey(table))).map((table) => ({
|
|
202
|
-
code: "PD064",
|
|
203
|
-
severity: "warning",
|
|
204
|
-
message: `rls.assignments guards ${table}, but no migration creates its permdock_assignment trigger, so a client may write any role there`,
|
|
205
|
-
fix: "run permdock rls generate and apply its output in a migration, or set rls.out or doctor.migrations to where it lives"
|
|
206
|
-
}));
|
|
207
|
-
}
|
|
208
|
-
//#endregion
|
|
209
|
-
//#region src/cli/doctor/baseline.ts
|
|
210
|
-
const LOCATION = /^([^\s:]+\.[A-Za-z0-9]+):(\d+)\b/u;
|
|
211
|
-
/**
|
|
212
|
-
* The finding's target: the one its check set, else the `file:line` its message
|
|
213
|
-
* opens with, else the message's first word when it is a path or a key, else
|
|
214
|
-
* `project`.
|
|
215
|
-
*/
|
|
216
|
-
function targetOf(finding) {
|
|
217
|
-
if (finding.target !== void 0) return finding.target;
|
|
218
|
-
const match = LOCATION.exec(finding.message);
|
|
219
|
-
if (match?.[0] !== void 0) return match[0];
|
|
220
|
-
const first = finding.message.split(/\s+/u)[0] ?? "";
|
|
221
|
-
return /[./]/u.test(first) ? first : "project";
|
|
222
|
-
}
|
|
223
|
-
function reported(finding) {
|
|
224
|
-
const target = targetOf(finding);
|
|
225
|
-
return {
|
|
226
|
-
...finding,
|
|
227
|
-
target,
|
|
228
|
-
id: `${finding.code}:${target}`
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Splits `findings` by `doctor.ignore` and `--ignore`. An entry that matches no
|
|
233
|
-
* finding comes back as an `ignore-stale` warning so the baseline can shrink.
|
|
234
|
-
*/
|
|
235
|
-
function applyDoctorIgnores(findings, config, flags) {
|
|
236
|
-
const ignores = parseIgnores(config.doctor?.ignore, "doctor.ignore", flags);
|
|
237
|
-
const split = splitIgnored(findings, (item) => item.id, ignores);
|
|
238
|
-
const stale = split.stale.filter((entry) => entry.reason !== "--ignore").map((entry) => reported({
|
|
239
|
-
code: "ignore-stale",
|
|
240
|
-
severity: "warning",
|
|
241
|
-
target: entry.id,
|
|
242
|
-
message: `ignore entry ${entry.id} matches no finding`,
|
|
243
|
-
fix: "remove it from doctor.ignore"
|
|
244
|
-
}));
|
|
245
|
-
return {
|
|
246
|
-
findings: [...split.kept, ...stale],
|
|
247
|
-
ignored: split.ignored.map((entry) => ({
|
|
248
|
-
id: entry.id,
|
|
249
|
-
reason: entry.reason,
|
|
250
|
-
message: entry.item.message
|
|
251
|
-
}))
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
//#endregion
|
|
255
|
-
//#region src/cli/doctor/better-supabase.ts
|
|
256
|
-
function lookupOf(input) {
|
|
257
|
-
return {
|
|
258
|
-
cwd: input.cwd,
|
|
259
|
-
...input.files === void 0 ? {} : { files: input.files },
|
|
260
|
-
...input.config.betterSupabase?.config === void 0 ? {} : { path: input.config.betterSupabase.config }
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
function activeTenantOf(config) {
|
|
264
|
-
const blocks = config["blocks"];
|
|
265
|
-
const permissions = isRecord(blocks) ? blocks["permissions"] : void 0;
|
|
266
|
-
const value = isRecord(permissions) ? permissions["activeTenant"] : void 0;
|
|
267
|
-
if (value === "claim" || value === "resolver") return value;
|
|
268
|
-
if (isRecord(value) && typeof value["profileColumn"] === "string") {
|
|
269
|
-
const key = value["key"];
|
|
270
|
-
return {
|
|
271
|
-
profileColumn: value["profileColumn"],
|
|
272
|
-
...typeof key === "string" ? { key } : {}
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* PermDock's token hook reads the active tenant from another place than
|
|
278
|
-
* better-supabase's `blocks.permissions.activeTenant` writes it, so
|
|
279
|
-
* `switch_organization` never changes the tenant claim.
|
|
280
|
-
*/
|
|
281
|
-
async function pd078(input) {
|
|
282
|
-
if (input.config.supabase?.hook === void 0) return [];
|
|
283
|
-
const config = await betterSupabaseConfig(lookupOf(input));
|
|
284
|
-
if (config === void 0) return [];
|
|
285
|
-
const activeTenant = activeTenantOf(config);
|
|
286
|
-
if (activeTenant === void 0) return [];
|
|
287
|
-
const policy = await policyOf(input);
|
|
288
|
-
const root = policy === void 0 ? void 0 : rootScope(scopeList(policy.scopes));
|
|
289
|
-
let from;
|
|
290
|
-
try {
|
|
291
|
-
from = activeSource(betterSupabaseDefaults(input.config, config).supabase?.hook?.activeFrom, root ?? "tenant");
|
|
292
|
-
} catch {
|
|
293
|
-
return [];
|
|
294
|
-
}
|
|
295
|
-
const mismatch = activeTenantMismatch(from, betterSupabaseTenantClaim(input.config, config), activeTenant);
|
|
296
|
-
return mismatch === void 0 ? [] : [{
|
|
297
|
-
code: "PD078",
|
|
298
|
-
severity: "warning",
|
|
299
|
-
message: mismatch,
|
|
300
|
-
fix: "set supabase.hook.activeFrom, then run permdock supabase hook generate"
|
|
301
|
-
}];
|
|
302
|
-
}
|
|
303
|
-
function isBlockPermissionKey(value) {
|
|
304
|
-
return isRecord(value) && typeof value["module"] === "string" && typeof value["action"] === "string" && typeof value["key"] === "string";
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Every permission key the configured blocks check, from the project's own
|
|
308
|
-
* `better-supabase/sql`; `undefined` when it does not resolve or refuses the
|
|
309
|
-
* config.
|
|
310
|
-
*/
|
|
311
|
-
async function blockPermissionKeys(cwd, blocks) {
|
|
312
|
-
try {
|
|
313
|
-
const file = createRequire(resolve(cwd, "package.json")).resolve("better-supabase/sql");
|
|
314
|
-
const list = (await import(pathToFileURL(file).href))["modulePermissionKeys"];
|
|
315
|
-
if (!isKeyLister(list)) return;
|
|
316
|
-
const keys = list(blocks, Object.keys(blocks));
|
|
317
|
-
return Array.isArray(keys) ? keys.filter(isBlockPermissionKey) : void 0;
|
|
318
|
-
} catch {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function isKeyLister(value) {
|
|
323
|
-
return typeof value === "function";
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* A permission key a configured better-supabase block checks that the catalog
|
|
327
|
-
* does not list: no role holds it, so the block's SQL checks deny it.
|
|
328
|
-
*/
|
|
329
|
-
async function pd079(input) {
|
|
330
|
-
const blocks = (await betterSupabaseConfig(lookupOf(input)))?.["blocks"];
|
|
331
|
-
if (!isRecord(blocks)) return [];
|
|
332
|
-
const files = filesOf(input);
|
|
333
|
-
const path = catalogPath(input.config, input.cwd);
|
|
334
|
-
if (!files.exists(path)) return [];
|
|
335
|
-
let declared;
|
|
336
|
-
try {
|
|
337
|
-
declared = new Set(parseCatalog(files.read(path)).permissions.map(({ key }) => key));
|
|
338
|
-
} catch {
|
|
339
|
-
return [];
|
|
340
|
-
}
|
|
341
|
-
const keys = await blockPermissionKeys(input.cwd, blocks);
|
|
342
|
-
if (keys === void 0) return [];
|
|
343
|
-
const missing = /* @__PURE__ */ new Map();
|
|
344
|
-
for (const entry of keys) if (!declared.has(entry.key)) {
|
|
345
|
-
const uses = missing.get(entry.key) ?? [];
|
|
346
|
-
uses.push(`blocks.${entry.module}.permissions.${entry.action}`);
|
|
347
|
-
missing.set(entry.key, uses);
|
|
348
|
-
}
|
|
349
|
-
const catalog = rel(input.cwd, path);
|
|
350
|
-
return [...missing].map(([key, uses]) => ({
|
|
351
|
-
code: "PD079",
|
|
352
|
-
severity: "warning",
|
|
353
|
-
message: `${key} (${[...new Set(uses)].join(", ")}) is not in ${catalog}, so no role holds it and better-supabase's SQL check denies it`,
|
|
354
|
-
fix: `declare ${key} in the policy and run permdock collect, or map the block action to a key the catalog lists`
|
|
355
|
-
}));
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* PermDock's hook keeps `permdock_authz_version` and better-supabase's
|
|
359
|
-
* `sessions.authzVersions` keeps `user_authz_versions`: two tables bump on
|
|
360
|
-
* different triggers, and only one reaches the `authz_ver` claim.
|
|
361
|
-
*/
|
|
362
|
-
async function pd082(input) {
|
|
363
|
-
const hook = input.config.supabase?.hook;
|
|
364
|
-
if (hook === void 0 || hook.version === false) return [];
|
|
365
|
-
const config = await betterSupabaseConfig(lookupOf(input));
|
|
366
|
-
if (config === void 0 || !betterSupabaseAuthzVersions(config)) return [];
|
|
367
|
-
return [{
|
|
368
|
-
code: "PD082",
|
|
369
|
-
severity: "warning",
|
|
370
|
-
message: "supabase.hook keeps permdock_authz_version and better-supabase's blocks.sessions.authzVersions keeps user_authz_versions: two version tables bump on different triggers, and only PermDock's reaches the authz_ver claim",
|
|
371
|
-
fix: "turn blocks.sessions.authzVersions off; PermDock's trigger broadcasts on better_supabase:authz and authz:<uid>, which better-supabase's subscribeAuthzVersions and SessionProvider read"
|
|
372
|
-
}];
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* The hook broadcasts a version bump on another topic than better-supabase
|
|
376
|
-
* subscribes to, or better-supabase is a dependency while its config is not
|
|
377
|
-
* found, so the hook cannot read its tenant claim and sessions block.
|
|
378
|
-
*/
|
|
379
|
-
async function pd087(input) {
|
|
380
|
-
const hook = input.config.supabase?.hook;
|
|
381
|
-
if (hook === void 0 || hook.version === false) return [];
|
|
382
|
-
const config = await betterSupabaseConfig(lookupOf(input));
|
|
383
|
-
const installed = config !== void 0 || betterSupabaseInstalled(input);
|
|
384
|
-
if (!installed) return [];
|
|
385
|
-
const findings = [];
|
|
386
|
-
const resolved = betterSupabaseDefaults(input.config, config, installed).supabase?.hook?.broadcast;
|
|
387
|
-
if (resolved !== false) {
|
|
388
|
-
const topic = resolved?.topic ?? "permdock:authz";
|
|
389
|
-
if (topic !== "better_supabase:authz") findings.push({
|
|
390
|
-
code: "PD087",
|
|
391
|
-
severity: "warning",
|
|
392
|
-
message: `supabase.hook broadcasts authorization version changes on ${topic}, and better-supabase's subscribeAuthzVersions and SessionProvider listen on ${BETTER_SUPABASE_AUTHZ_TOPIC}: a role change never reaches a signed-in client`,
|
|
393
|
-
fix: `remove supabase.hook.broadcast.topic, or set it to ${BETTER_SUPABASE_AUTHZ_TOPIC}, then run permdock supabase hook generate`
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
if (config === void 0) findings.push({
|
|
397
|
-
code: "PD087",
|
|
398
|
-
severity: "warning",
|
|
399
|
-
message: "better-supabase is a dependency but its config file was not found from permdock.config.ts up to the workspace root, so supabase.hook cannot read its tenant claim or sessions block",
|
|
400
|
-
fix: "set betterSupabase.config in permdock.config.ts to the better-supabase.config.* path"
|
|
401
|
-
});
|
|
402
|
-
return findings;
|
|
403
|
-
}
|
|
404
|
-
//#endregion
|
|
405
|
-
//#region src/cli/doctor/catalog.ts
|
|
406
|
-
/**
|
|
407
|
-
* A policy that declares `oauthScopes` against a catalog on disk without them,
|
|
408
|
-
* or with another set. `authorizationProvider` builds better-supabase's
|
|
409
|
-
* `delegation.scopes` from the catalog, so its SQL checks deny a token that
|
|
410
|
-
* holds only the coarse scope.
|
|
411
|
-
*/
|
|
412
|
-
async function pd070(input) {
|
|
413
|
-
const declared = (await policyOf(input))?.oauthScopes ?? [];
|
|
414
|
-
if (declared.length === 0) return [];
|
|
415
|
-
const files = filesOf(input);
|
|
416
|
-
const path = catalogPath(input.config, input.cwd);
|
|
417
|
-
if (!files.exists(path)) return [];
|
|
418
|
-
let listed;
|
|
419
|
-
try {
|
|
420
|
-
listed = parseCatalog(files.read(path)).oauthScopes;
|
|
421
|
-
} catch {
|
|
422
|
-
return [];
|
|
423
|
-
}
|
|
424
|
-
const expected = catalogOAuthScopes(declared);
|
|
425
|
-
if (listed !== void 0 && canonicalJson(listed) === canonicalJson(expected)) return [];
|
|
426
|
-
return [{
|
|
427
|
-
code: "PD070",
|
|
428
|
-
severity: "warning",
|
|
429
|
-
message: listed === void 0 ? `the policy declares oauthScopes (${expected.map(({ scope }) => scope).join(", ")}) and ${rel(input.cwd, path)} lists none, so better-supabase's SQL checks deny a token that holds only a coarse scope` : `${rel(input.cwd, path)} lists other oauthScopes than the policy declares`,
|
|
430
|
-
fix: "pnpm exec permdock collect"
|
|
431
|
-
}];
|
|
432
|
-
}
|
|
433
|
-
async function pd002(input) {
|
|
434
|
-
const collected = await collectedOf(input);
|
|
435
|
-
if (collected.scan === void 0) return [];
|
|
436
|
-
return collected.scan.unknown.map((usage) => ({
|
|
437
|
-
code: "PD002",
|
|
438
|
-
severity: "error",
|
|
439
|
-
message: `unknown permission ${usage.call} at ${usage.file}:${String(usage.line)}`,
|
|
440
|
-
fix: "use a defined permission reference"
|
|
441
|
-
}));
|
|
442
|
-
}
|
|
443
|
-
async function pd003(input) {
|
|
444
|
-
if (input.config.policy === void 0) return [];
|
|
445
|
-
const usage = await runUsage({
|
|
446
|
-
cwd: input.cwd,
|
|
447
|
-
config: input.config,
|
|
448
|
-
ignore: [],
|
|
449
|
-
strict: false,
|
|
450
|
-
json: true,
|
|
451
|
-
dynamicAsUsed: false,
|
|
452
|
-
now: input.now,
|
|
453
|
-
io: input.io,
|
|
454
|
-
collected: () => collectedOf(input),
|
|
455
|
-
policy: () => policyOf(input)
|
|
456
|
-
});
|
|
457
|
-
if (usage.code === 2) return [];
|
|
458
|
-
return JSON.parse(usage.output).ungranted.map((item) => ({
|
|
459
|
-
code: "PD003",
|
|
460
|
-
severity: "warning",
|
|
461
|
-
message: `${item.key} is used but never granted (${item.detail})`,
|
|
462
|
-
fix: "add an allow() with a to: selector, or a role() binding, in definePolicy"
|
|
463
|
-
}));
|
|
464
|
-
}
|
|
465
|
-
async function pd004(input) {
|
|
466
|
-
const collected = await collectedOf(input);
|
|
467
|
-
if (collected.code === 0) return [];
|
|
468
|
-
if (collected.code === 2) return [];
|
|
469
|
-
return [{
|
|
470
|
-
code: "PD004",
|
|
471
|
-
severity: "error",
|
|
472
|
-
message: collected.message,
|
|
473
|
-
fix: "pnpm exec permdock collect"
|
|
474
|
-
}];
|
|
475
|
-
}
|
|
476
|
-
async function pd067(input) {
|
|
477
|
-
if (input.config.operations === void 0) return [];
|
|
478
|
-
const document = (await collectedOf(input)).document;
|
|
479
|
-
if (document?.operations === void 0) return [];
|
|
480
|
-
const declared = new Set(document.permissions.map(({ key }) => key));
|
|
481
|
-
return document.operations.flatMap((operation) => [["permission", operation.permission], ["results", operation.results]].flatMap(([field, key]) => key === void 0 || declared.has(key) ? [] : [{
|
|
482
|
-
code: "PD067",
|
|
483
|
-
severity: "error",
|
|
484
|
-
message: `operation ${operation.name} has ${field} ${key}, which the permissions module does not declare`,
|
|
485
|
-
fix: "pass the same permission tree to defineOperations and to permdock.config.ts permissions, or declare the permission"
|
|
486
|
-
}]));
|
|
487
|
-
}
|
|
488
|
-
//#endregion
|
|
489
|
-
//#region src/cli/doctor/config-names.ts
|
|
490
|
-
const PLACEHOLDER = /\{([^{}]*)\}/gu;
|
|
491
|
-
/** The scope aliases `ScopeNames` admits next to the declared names. */
|
|
492
|
-
const ALIASES = ["tenant", "team"];
|
|
493
|
-
function keysOf(record) {
|
|
494
|
-
return record === void 0 ? [] : Object.keys(record);
|
|
495
|
-
}
|
|
496
|
-
function named(where, kind, names) {
|
|
497
|
-
return names.map((name) => ({
|
|
498
|
-
where,
|
|
499
|
-
kind,
|
|
500
|
-
name
|
|
501
|
-
}));
|
|
502
|
-
}
|
|
503
|
-
function namedIn(config) {
|
|
504
|
-
const rls = config.rls;
|
|
505
|
-
return [
|
|
506
|
-
...named("rls.tables", "resource", keysOf(rls?.tables)),
|
|
507
|
-
...named("rls.scopeTypes", "scope", keysOf(rls?.scopeTypes)),
|
|
508
|
-
...named("rls.idTypes", "resource", keysOf(rls?.idTypes).filter((name) => name !== "*")),
|
|
509
|
-
...named("rls.actions", "action", keysOf(rls?.actions)),
|
|
510
|
-
...named("rls.memberships.scopes", "scope", keysOf(rls?.memberships?.scopes)),
|
|
511
|
-
...named("rls.suspension.scopes", "scope", keysOf(rls?.suspension?.scopes)),
|
|
512
|
-
...Object.keys(rls?.realtime?.topics ?? {}).flatMap((pattern) => named(`rls.realtime.topics['${pattern}']`, "scope", [...pattern.matchAll(PLACEHOLDER)].map((match) => match[1] ?? ""))),
|
|
513
|
-
...Object.entries(rls?.storage?.buckets ?? {}).flatMap(([name, bucket]) => named(`rls.storage.buckets.${name}.scope`, "scope", [bucket.scope])),
|
|
514
|
-
...named("powersync.resources", "resource", config.powersync?.resources ?? []),
|
|
515
|
-
...named("powersync.action", "action", config.powersync?.action === void 0 ? [] : [config.powersync.action])
|
|
516
|
-
];
|
|
517
|
-
}
|
|
518
|
-
/**
|
|
519
|
-
* PD077: a config key or value names a scope, resource or action the policy
|
|
520
|
-
* does not declare, such as a Realtime topic `{organisation}` placeholder for
|
|
521
|
-
* the scope `organization`. `defineConfig` with the policy value reports the
|
|
522
|
-
* same names at compile time. Also a SQL helper name `resolveNames` rejects:
|
|
523
|
-
* two sources sharing one, or one Postgres cannot hold.
|
|
524
|
-
*/
|
|
525
|
-
async function pd077(input) {
|
|
526
|
-
if (input.config.policy === void 0) return [];
|
|
527
|
-
const policy = await policyOf(input);
|
|
528
|
-
if (policy === void 0) return [];
|
|
529
|
-
const leaves = listPermissions(policy.vocabulary.permissions);
|
|
530
|
-
const declared = {
|
|
531
|
-
scope: /* @__PURE__ */ new Set([...policy.scopes.map((scope) => scope.name), ...ALIASES]),
|
|
532
|
-
resource: new Set(leaves.map((leaf) => leaf.resource)),
|
|
533
|
-
action: new Set(leaves.map((leaf) => leaf.action))
|
|
534
|
-
};
|
|
535
|
-
return [...namedIn(input.config).filter((entry) => !declared[entry.kind].has(entry.name)).map((entry) => ({
|
|
536
|
-
code: "PD077",
|
|
537
|
-
severity: "error",
|
|
538
|
-
message: `${entry.where} names the ${entry.kind} '${entry.name}', which the policy does not declare`,
|
|
539
|
-
fix: `use one of ${[...declared[entry.kind]].toSorted().join(", ")}, or pass the policy value to defineConfig to catch this at compile time`
|
|
540
|
-
})), ...helperNames(policy, input.config)];
|
|
541
|
-
}
|
|
542
|
-
function helperNames(policy, config) {
|
|
543
|
-
try {
|
|
544
|
-
resolveNames(policy, config);
|
|
545
|
-
return [];
|
|
546
|
-
} catch (cause) {
|
|
547
|
-
return [{
|
|
548
|
-
code: "PD077",
|
|
549
|
-
severity: "error",
|
|
550
|
-
message: describeError(cause).replace(/^PermDock CLI: /u, ""),
|
|
551
|
-
fix: "rename the scope or resource so each generated SQL helper has its own name of at most 63 bytes"
|
|
552
|
-
}];
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
//#endregion
|
|
556
|
-
//#region src/cli/doctor/declarative.ts
|
|
557
|
-
const SCHEMAS = "supabase/schemas";
|
|
558
|
-
const MIGRATIONS = "supabase/migrations";
|
|
559
|
-
const CREATES_HOOK = /\bcreate\s+(?:or\s+replace\s+)?function\s+[\w."]*custom_access_token_hook\b/iu;
|
|
560
|
-
const DROPS_HOOK = /\bdrop\s+function\s+(?:if\s+exists\s+)?[\w."]*custom_access_token_hook\b/iu;
|
|
561
|
-
const GRANTS_HOOK = /\bgrant\s+execute\s+on\s+function\s+[\w."]*custom_access_token_hook\s*\(\s*jsonb\s*\)\s+to\s+supabase_auth_admin\b/iu;
|
|
562
|
-
const DEFINES_HELPER = /\bcreate\s+(?:or\s+replace\s+)?function\s+[\w."]*permdock_has\s*\(/iu;
|
|
563
|
-
const CALLS_HELPER = /\b(?:permdock_has|(?:permitted|member)_[a-z][a-z0-9_]*_ids)\s*\(/iu;
|
|
564
|
-
function uncommented(text) {
|
|
565
|
-
return text.replaceAll(/--[^\n]*/gu, "").replaceAll(/\/\*[\s\S]*?\*\//gu, "");
|
|
566
|
-
}
|
|
567
|
-
/**
|
|
568
|
-
* Whether `text` starts with a line `rls generate` or `supabase hook generate`
|
|
569
|
-
* writes.
|
|
570
|
-
*/
|
|
571
|
-
function generatedByPermDock(text) {
|
|
572
|
-
return text.startsWith("-- permdock:") || text.startsWith("-- generated by permdock");
|
|
573
|
-
}
|
|
574
|
-
/**
|
|
575
|
-
* PD042: under migra, a hook declared under `supabase/schemas` reaches the
|
|
576
|
-
* database through `supabase db diff`, which drops its `supabase_auth_admin`
|
|
577
|
-
* grants. pg-delta keeps them, so the check runs only for `migra`. A function
|
|
578
|
-
* created (or dropped and created again) without them is executable by `public`
|
|
579
|
-
* and not by the auth server, so a migration at or after the one that creates
|
|
580
|
-
* it must carry the grants.
|
|
581
|
-
*/
|
|
582
|
-
function pd042(cwd, config, files = nodeFiles) {
|
|
583
|
-
if (config.supabase?.hook === void 0 || resolveSchemas(cwd, config).mode !== "migra") return [];
|
|
584
|
-
if (!sqlFiles(cwd, [SCHEMAS]).some((file) => files.read(file).startsWith(`-- permdock:hook v1 `))) return [];
|
|
585
|
-
const migrations = sqlFiles(cwd, [MIGRATIONS]).map((file) => ({
|
|
586
|
-
file,
|
|
587
|
-
text: uncommented(files.read(file))
|
|
588
|
-
}));
|
|
589
|
-
const created = migrations.findIndex(({ text }) => CREATES_HOOK.test(text));
|
|
590
|
-
const dropped = migrations.findLastIndex(({ text }) => DROPS_HOOK.test(text));
|
|
591
|
-
const needed = Math.max(created, dropped);
|
|
592
|
-
if (needed === -1) return [];
|
|
593
|
-
if (migrations.findLastIndex(({ text }) => GRANTS_HOOK.test(text)) >= needed) return [];
|
|
594
|
-
return [{
|
|
595
|
-
code: "PD042",
|
|
596
|
-
severity: "error",
|
|
597
|
-
message: `${rel(cwd, migrations[needed]?.file ?? MIGRATIONS)} creates custom_access_token_hook from supabase/schemas, and no migration from it on grants it to supabase_auth_admin: supabase db diff drops those grants, so the auth server cannot call the hook and public can`,
|
|
598
|
-
fix: "switch to pg-delta, which keeps the grants ([experimental.pgdelta] enabled = true and no supabase.schemas: 'migra'), or generate the grants with permdock supabase hook generate --grants-out (or rls generate --split ...,hook --grants-out) into a new file from supabase migration new, after the db diff migration"
|
|
599
|
-
}];
|
|
600
|
-
}
|
|
601
|
-
/** The PermDock-generated files under the declarative schema directory. */
|
|
602
|
-
function generatedSchemaFiles(cwd, schemaDir, files) {
|
|
603
|
-
if (!files.exists(join(cwd, schemaDir))) return [];
|
|
604
|
-
return sqlFiles(cwd, [schemaDir]).filter((file) => generatedByPermDock(files.read(file)));
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* PD068: PermDock generates for pg-delta (the default), but
|
|
608
|
-
* `supabase/config.toml` does not set `[experimental.pgdelta] enabled = true`,
|
|
609
|
-
* so Supabase CLI 2.x diffs the schema files with migra. migra drops the hook's
|
|
610
|
-
* `supabase_auth_admin` grants and the helpers' privileges, and PermDock wrote
|
|
611
|
-
* no `--grants-out` file to restore them.
|
|
612
|
-
*/
|
|
613
|
-
function pd068(cwd, config, files = nodeFiles) {
|
|
614
|
-
const read = readSupabaseConfig(cwd);
|
|
615
|
-
if (read?.ok !== true || read.config.pgDelta?.enabled === true) return [];
|
|
616
|
-
const schemas = resolveSchemas(cwd, config);
|
|
617
|
-
if (schemas.mode !== "pg-delta") return [];
|
|
618
|
-
const [first] = generatedSchemaFiles(cwd, schemas.schemaDir, files);
|
|
619
|
-
if (first === void 0) return [];
|
|
620
|
-
return [{
|
|
621
|
-
code: "PD068",
|
|
622
|
-
severity: "error",
|
|
623
|
-
message: `${rel(cwd, first)} is written for pg-delta, but supabase/config.toml does not set [experimental.pgdelta] enabled = true, so the Supabase CLI diffs it with migra and drops the hook and helper grants`,
|
|
624
|
-
fix: "add [experimental.pgdelta] with enabled = true to supabase/config.toml (Supabase CLI 2.119 or later), or set supabase.schemas: 'migra' in permdock.config.ts and regenerate with --grants-out"
|
|
625
|
-
}];
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* PD069: leftovers of declarative schemas on migra in a pg-delta project:
|
|
629
|
-
* `[db.migrations] schema_paths`, which pg-delta's dependency order makes
|
|
630
|
-
* unnecessary, and numbered `NNN_permdock_<part>.sql` files that duplicate the
|
|
631
|
-
* per-schema layout `rls generate --split` now writes.
|
|
632
|
-
*/
|
|
633
|
-
function pd069(cwd, config, files = nodeFiles) {
|
|
634
|
-
const schemas = resolveSchemas(cwd, config);
|
|
635
|
-
if (schemas.mode !== "pg-delta") return [];
|
|
636
|
-
const findings = [];
|
|
637
|
-
if ((supabaseConfig(cwd).schemaPaths ?? []).length > 0) findings.push({
|
|
638
|
-
code: "PD069",
|
|
639
|
-
severity: "warning",
|
|
640
|
-
message: "supabase/config.toml sets [db.migrations] schema_paths, which pg-delta does not need: it orders the schema files by their dependencies",
|
|
641
|
-
fix: "remove schema_paths from [db.migrations] in supabase/config.toml"
|
|
642
|
-
});
|
|
643
|
-
for (const file of generatedSchemaFiles(cwd, schemas.schemaDir, files)) if (/^\d+_permdock_/u.test(basename(file))) findings.push({
|
|
644
|
-
code: "PD069",
|
|
645
|
-
severity: "warning",
|
|
646
|
-
message: `${rel(cwd, file)} is a numbered part from declarative schemas on migra; under pg-delta, rls generate --split writes the per-schema layout instead`,
|
|
647
|
-
fix: "delete the numbered parts, run permdock rls generate --split without --out, then supabase db schema declarative sync"
|
|
648
|
-
});
|
|
649
|
-
return findings;
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* The `[db.migrations] schema_paths` globs of `supabase/config.toml`, or
|
|
653
|
-
* Supabase's default.
|
|
654
|
-
*/
|
|
655
|
-
function schemaPaths(cwd) {
|
|
656
|
-
const paths = supabaseConfig(cwd).schemaPaths ?? [];
|
|
657
|
-
return paths.length === 0 ? ["./schemas/**/*.sql"] : paths;
|
|
658
|
-
}
|
|
659
|
-
/**
|
|
660
|
-
* Schema files in the order `supabase db diff` applies them: each glob in turn,
|
|
661
|
-
* sorted within it.
|
|
662
|
-
*/
|
|
663
|
-
function orderedSchemaFiles(cwd) {
|
|
664
|
-
return sqlFiles(join(cwd, "supabase"), schemaPaths(cwd), { order: "entry" });
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* PD043: under migra, `db diff` applies schema files in `schema_paths` order,
|
|
668
|
-
* so a policy that calls `permdock_has` or `permitted_<scope>_ids` before the
|
|
669
|
-
* file that defines them fails to apply. pg-delta orders by dependencies
|
|
670
|
-
* instead.
|
|
671
|
-
*/
|
|
672
|
-
function pd043(cwd, config, files = nodeFiles) {
|
|
673
|
-
if (resolveSchemas(cwd, config).mode !== "migra") return [];
|
|
674
|
-
if (!files.exists(join(cwd, SCHEMAS))) return [];
|
|
675
|
-
const schemas = orderedSchemaFiles(cwd).map((file) => ({
|
|
676
|
-
file,
|
|
677
|
-
text: uncommented(files.read(file))
|
|
678
|
-
}));
|
|
679
|
-
const helpers = schemas.findIndex(({ text }) => DEFINES_HELPER.test(text));
|
|
680
|
-
const defined = sqlFiles(cwd, [SCHEMAS]).find((file) => DEFINES_HELPER.test(uncommented(files.read(file))));
|
|
681
|
-
if (helpers === -1) return defined === void 0 ? [] : [{
|
|
682
|
-
code: "PD043",
|
|
683
|
-
severity: "warning",
|
|
684
|
-
message: `${rel(cwd, defined)} defines the PermDock helpers, but schema_paths in supabase/config.toml does not list it, so supabase db diff never applies it`,
|
|
685
|
-
fix: `add it to [db.migrations] schema_paths before every file that calls permdock_has, permitted_<scope>_ids or member_<scope>_ids`
|
|
686
|
-
}];
|
|
687
|
-
const helperFile = rel(cwd, schemas[helpers]?.file ?? "");
|
|
688
|
-
return schemas.slice(0, helpers).filter(({ text }) => CALLS_HELPER.test(text)).map(({ file }) => ({
|
|
689
|
-
code: "PD043",
|
|
690
|
-
severity: "warning",
|
|
691
|
-
message: `${rel(cwd, file)} calls the PermDock helpers, but schema_paths applies it before ${helperFile}, which defines them`,
|
|
692
|
-
fix: `list ${helperFile} earlier in [db.migrations] schema_paths, or give it a lower number, such as 056_permdock_helpers.sql before 060_policies.sql`
|
|
693
|
-
}));
|
|
694
|
-
}
|
|
695
|
-
//#endregion
|
|
696
|
-
//#region src/cli/doctor/fixtures.ts
|
|
697
|
-
async function pd018(input) {
|
|
698
|
-
const files = filesOf(input);
|
|
699
|
-
if (input.config.policy === void 0) return [];
|
|
700
|
-
const policy = await policyOf(input);
|
|
701
|
-
if (policy === void 0) return [];
|
|
702
|
-
const findings = [];
|
|
703
|
-
const declared = new Set(policy.roles.map((item) => item.name));
|
|
704
|
-
for (const binding of policy.roles) for (const name of binding.exclusiveWith ?? []) if (!declared.has(name)) findings.push({
|
|
705
|
-
code: "PD018",
|
|
706
|
-
severity: "error",
|
|
707
|
-
message: `exclusiveWith names undeclared role ${name} on ${binding.name}`,
|
|
708
|
-
fix: "declare the exclusive role with role() or remove it from exclusiveWith"
|
|
709
|
-
});
|
|
710
|
-
const fixturePath = input.config.doctor?.memberships;
|
|
711
|
-
if (fixturePath === void 0) return findings;
|
|
712
|
-
const absolute = resolve(input.cwd, fixturePath);
|
|
713
|
-
if (!files.exists(absolute)) {
|
|
714
|
-
findings.push({
|
|
715
|
-
code: "PD018",
|
|
716
|
-
severity: "warning",
|
|
717
|
-
message: `doctor.memberships fixture ${fixturePath} is missing`,
|
|
718
|
-
fix: "add the JSON fixture or remove doctor.memberships"
|
|
719
|
-
});
|
|
720
|
-
return findings;
|
|
721
|
-
}
|
|
722
|
-
let parsed;
|
|
723
|
-
try {
|
|
724
|
-
parsed = readJson(files, absolute);
|
|
725
|
-
} catch {
|
|
726
|
-
findings.push({
|
|
727
|
-
code: "PD018",
|
|
728
|
-
severity: "warning",
|
|
729
|
-
message: `doctor.memberships fixture ${fixturePath} is not valid JSON`,
|
|
730
|
-
fix: "fix the JSON fixture"
|
|
731
|
-
});
|
|
732
|
-
return findings;
|
|
733
|
-
}
|
|
734
|
-
const record = asMembershipsFixture(parsed);
|
|
735
|
-
for (const custom of record.customRoles ?? []) {
|
|
736
|
-
const conflicts = separationConflicts(policy, [{
|
|
737
|
-
principal: custom.name,
|
|
738
|
-
...custom.tenant === void 0 ? {} : { tenant: custom.tenant },
|
|
739
|
-
roles: custom.includes ?? []
|
|
740
|
-
}]);
|
|
741
|
-
for (const conflict of conflicts) findings.push({
|
|
742
|
-
code: "PD018",
|
|
743
|
-
severity: "warning",
|
|
744
|
-
message: `custom role ${custom.name} includes exclusive roles ${conflict.roles.join(" and ")}`,
|
|
745
|
-
fix: "split the custom role so it does not include exclusiveWith pairs"
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
for (const conflict of separationConflicts(policy, record.memberships ?? [])) findings.push({
|
|
749
|
-
code: "PD018",
|
|
750
|
-
severity: "warning",
|
|
751
|
-
message: `membership ${nonEmptyOr(conflict.principal, "unknown")} holds exclusive roles ${conflict.roles.join(" and ")}`,
|
|
752
|
-
fix: "remove one of the exclusive roles from the membership fixture"
|
|
753
|
-
});
|
|
754
|
-
return findings;
|
|
755
|
-
}
|
|
756
|
-
function customRoleLabel(role) {
|
|
757
|
-
return role.tenant === void 0 ? `global custom role ${role.name}` : `custom role ${role.name} in ${role.tenant}`;
|
|
758
|
-
}
|
|
759
|
-
async function pd023(input) {
|
|
760
|
-
const files = filesOf(input);
|
|
761
|
-
const fixturePath = input.config.doctor?.memberships;
|
|
762
|
-
if (input.config.policy === void 0 || fixturePath === void 0) return [];
|
|
763
|
-
const absolute = resolve(input.cwd, fixturePath);
|
|
764
|
-
if (!files.exists(absolute)) return [];
|
|
765
|
-
let parsed;
|
|
766
|
-
try {
|
|
767
|
-
parsed = readJson(files, absolute);
|
|
768
|
-
} catch {
|
|
769
|
-
return [];
|
|
770
|
-
}
|
|
771
|
-
const policy = await policyOf(input);
|
|
772
|
-
if (policy === void 0) return [];
|
|
773
|
-
const findings = [];
|
|
774
|
-
for (const custom of asMembershipsFixture(parsed).customRoles ?? []) for (const entry of validateCustomRole(policy, custom).dropped) {
|
|
775
|
-
const what = "role" in entry ? `include ${entry.role}` : `permission ${entry.permission}`;
|
|
776
|
-
findings.push({
|
|
777
|
-
code: "PD023",
|
|
778
|
-
severity: "warning",
|
|
779
|
-
message: `${customRoleLabel(custom)} drops ${what} (${entry.reason})`,
|
|
780
|
-
fix: entry.reason === "outside-ceiling" ? "grant it to a declared assignable role, or remove it from the custom role" : entry.reason === "condition-not-allowed" ? "remove the condition; custom-role grants inherit the declared grant condition" : "use a declared permission key or assignable role name"
|
|
781
|
-
});
|
|
782
|
-
}
|
|
783
|
-
return findings;
|
|
784
|
-
}
|
|
785
|
-
/**
|
|
786
|
-
* PD055: a stored custom role names a permission by a key it was renamed from.
|
|
787
|
-
* It still resolves; the alias can only be dropped once storage holds the
|
|
788
|
-
* current key.
|
|
789
|
-
*/
|
|
790
|
-
async function pd055(input) {
|
|
791
|
-
const files = filesOf(input);
|
|
792
|
-
const fixturePath = input.config.doctor?.memberships;
|
|
793
|
-
if (input.config.policy === void 0 || fixturePath === void 0) return [];
|
|
794
|
-
const absolute = resolve(input.cwd, fixturePath);
|
|
795
|
-
if (!files.exists(absolute)) return [];
|
|
796
|
-
let parsed;
|
|
797
|
-
try {
|
|
798
|
-
parsed = readJson(files, absolute);
|
|
799
|
-
} catch {
|
|
800
|
-
return [];
|
|
801
|
-
}
|
|
802
|
-
const policy = await policyOf(input);
|
|
803
|
-
if (policy === void 0) return [];
|
|
804
|
-
const table = `${input.config.rls?.schema ?? "permdock"}.custom_role_permissions`;
|
|
805
|
-
const findings = [];
|
|
806
|
-
for (const custom of asMembershipsFixture(parsed).customRoles ?? []) for (const { from, to } of validateCustomRole(policy, custom).renamed) findings.push({
|
|
807
|
-
code: "PD055",
|
|
808
|
-
severity: "warning",
|
|
809
|
-
message: `${customRoleLabel(custom)} stores ${from}, which was renamed to ${to}`,
|
|
810
|
-
fix: `rewrite the stored key before removing the alias: update ${table} set permission = ${quoteSqlLiteral(to)} where permission = ${quoteSqlLiteral(from)};`
|
|
811
|
-
});
|
|
812
|
-
return findings;
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Fixture API keys that never expire, credential policies that allow it, and
|
|
816
|
-
* records that are not v1 credentials.
|
|
817
|
-
*/
|
|
818
|
-
function pd029(input) {
|
|
819
|
-
const parsed = readFixture(input, input.config.doctor?.credentials);
|
|
820
|
-
const findings = [];
|
|
821
|
-
for (const [index, record] of listField(parsed, "credentials").entries()) {
|
|
822
|
-
const credential = parseCredential(record);
|
|
823
|
-
if (credential === void 0) {
|
|
824
|
-
findings.push({
|
|
825
|
-
code: "PD029",
|
|
826
|
-
severity: "warning",
|
|
827
|
-
message: `credentials[${String(index)}] is not a valid v1 credential, so it verifies to no subject`,
|
|
828
|
-
fix: "give it v: 1, id, kind, principal, permissions, createdBy and createdAt; a service key also needs tenant and roles"
|
|
829
|
-
});
|
|
830
|
-
continue;
|
|
831
|
-
}
|
|
832
|
-
if (credential.expiresAt === void 0) findings.push({
|
|
833
|
-
code: "PD029",
|
|
834
|
-
severity: "warning",
|
|
835
|
-
message: `API key ${credential.id} never expires`,
|
|
836
|
-
fix: "set expiresAt and rotate the key before it; a leaked key without expiry stays live until someone revokes it"
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
const settings = parsed !== null && typeof parsed === "object" ? parsed.settings : void 0;
|
|
840
|
-
const tenants = settings !== null && typeof settings === "object" ? Object.entries(settings) : [];
|
|
841
|
-
for (const [tenant, value] of tenants) if ((value !== null && typeof value === "object" ? value.credentials : void 0)?.allowNoExpiry === true) findings.push({
|
|
842
|
-
code: "PD029",
|
|
843
|
-
severity: "warning",
|
|
844
|
-
message: `tenant ${tenant} allows API keys that never expire`,
|
|
845
|
-
fix: "drop allowNoExpiry and set maxTtl, or keep it only for a tenant that rotates keys on its own schedule"
|
|
846
|
-
});
|
|
847
|
-
return findings;
|
|
848
|
-
}
|
|
849
|
-
async function pd025(input) {
|
|
850
|
-
const files = filesOf(input);
|
|
851
|
-
const fixturePath = input.config.doctor?.memberships;
|
|
852
|
-
if (input.config.policy === void 0 || fixturePath === void 0) return [];
|
|
853
|
-
const absolute = resolve(input.cwd, fixturePath);
|
|
854
|
-
if (!files.exists(absolute)) return [];
|
|
855
|
-
let parsed;
|
|
856
|
-
try {
|
|
857
|
-
parsed = readJson(files, absolute);
|
|
858
|
-
} catch {
|
|
859
|
-
return [];
|
|
860
|
-
}
|
|
861
|
-
const policy = await policyOf(input);
|
|
862
|
-
if (policy === void 0) return [];
|
|
863
|
-
const scopes = scopeList(policy.scopes);
|
|
864
|
-
const names = scopes.map((scope) => scope.name).join(", ");
|
|
865
|
-
const findings = [];
|
|
866
|
-
for (const [index, membership] of (asMembershipsFixture(parsed).memberships ?? []).entries()) {
|
|
867
|
-
if (normalizeMemberships([membership], scopes).length > 0) continue;
|
|
868
|
-
findings.push({
|
|
869
|
-
code: "PD025",
|
|
870
|
-
severity: "warning",
|
|
871
|
-
message: `membership ${membership.principal ?? String(index)} grants nothing: its scope is not one of ${names}, a parent id is missing from within, it mixes shapes, or it uses the { tenant, team } form 0.17.0 removed (permdock codemod 0.17 rewrites it)`,
|
|
872
|
-
fix: "use { scope, id, within: { <parent>: id }, roles } with a declared scope, or { on: { resource, id }, roles }"
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
return findings;
|
|
876
|
-
}
|
|
877
|
-
//#endregion
|
|
878
|
-
//#region src/cli/doctor/hook-role.ts
|
|
879
|
-
/** A user id no account has: the hook still reads every table it reads. */
|
|
880
|
-
const NOBODY = "00000000-0000-0000-0000-000000000000";
|
|
881
|
-
function eventsOf(project) {
|
|
882
|
-
const nobody = {
|
|
883
|
-
label: "a user with no rows",
|
|
884
|
-
event: {
|
|
885
|
-
user_id: NOBODY,
|
|
886
|
-
claims: {
|
|
887
|
-
sub: NOBODY,
|
|
888
|
-
role: "authenticated",
|
|
889
|
-
aud: "authenticated"
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
};
|
|
893
|
-
const fixture = project.config.doctor?.claims;
|
|
894
|
-
if (fixture === void 0) return [nobody];
|
|
895
|
-
let samples;
|
|
896
|
-
try {
|
|
897
|
-
samples = JSON.parse(project.files.read(resolve(project.cwd, fixture)));
|
|
898
|
-
} catch {
|
|
899
|
-
return [nobody];
|
|
900
|
-
}
|
|
901
|
-
if (!Array.isArray(samples)) return [nobody];
|
|
902
|
-
return [nobody, ...samples.flatMap((sample, index) => {
|
|
903
|
-
const sub = isRecord(sample) ? sample["sub"] : void 0;
|
|
904
|
-
return typeof sub === "string" && sub !== "" ? [{
|
|
905
|
-
label: `sample ${String(index)} in ${fixture}`,
|
|
906
|
-
event: {
|
|
907
|
-
user_id: sub,
|
|
908
|
-
claims: sample
|
|
909
|
-
}
|
|
910
|
-
}] : [];
|
|
911
|
-
})];
|
|
912
|
-
}
|
|
913
|
-
/**
|
|
914
|
-
* PD085: `custom_access_token_hook` fails when `supabase_auth_admin` calls it,
|
|
915
|
-
* as GoTrue does at every sign-in and refresh. Runs only with `--db-url-stdin`,
|
|
916
|
-
* inside a transaction it rolls back.
|
|
917
|
-
*/
|
|
918
|
-
async function pd085(project) {
|
|
919
|
-
const { database } = project;
|
|
920
|
-
const hook = project.config.supabase?.hook;
|
|
921
|
-
if (database === void 0 || hook === void 0) return [];
|
|
922
|
-
const schema = hook.schema ?? project.config.rls?.schema ?? "permdock";
|
|
923
|
-
const fn = `${quoteIdent(schema)}.custom_access_token_hook`;
|
|
924
|
-
const client = await database.connect(database.url);
|
|
925
|
-
const findings = [];
|
|
926
|
-
try {
|
|
927
|
-
for (const { label, event } of eventsOf(project)) {
|
|
928
|
-
await client.query("begin", []);
|
|
929
|
-
try {
|
|
930
|
-
await client.query("set local role supabase_auth_admin", []);
|
|
931
|
-
await client.query(`select ${fn}($1::jsonb) as event`, [JSON.stringify(event)]);
|
|
932
|
-
} catch (error) {
|
|
933
|
-
findings.push({
|
|
934
|
-
code: "PD085",
|
|
935
|
-
severity: "error",
|
|
936
|
-
message: `${schema}.custom_access_token_hook fails as supabase_auth_admin for ${label} (${describeError(error)}), so that sign-in gets no token`,
|
|
937
|
-
fix: hook.security === "definer" ? "apply the hook migration as the owner of the tables it reads, and grant supabase_auth_admin usage on its schema and execute on the hook" : "apply the hook migration's grants and read policies, or set supabase.hook.security to 'definer' so the hook reads with its owner's rights"
|
|
938
|
-
});
|
|
939
|
-
} finally {
|
|
940
|
-
await client.query("rollback", []);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
} finally {
|
|
944
|
-
await client.end();
|
|
945
|
-
}
|
|
946
|
-
return findings;
|
|
947
|
-
}
|
|
948
|
-
//#endregion
|
|
949
|
-
//#region src/cli/doctor/lockfile.ts
|
|
950
|
-
const LOCKFILE = "pnpm-lock.yaml";
|
|
951
|
-
const MAX_LEVELS = 8;
|
|
952
|
-
/**
|
|
953
|
-
* `permdock@0.21.0(react@19.1.0)(zod@4.1.0):` under `snapshots:`; the peers are
|
|
954
|
-
* the parenthesised groups.
|
|
955
|
-
*/
|
|
956
|
-
const SNAPSHOT_KEY = /^ {2}'?permdock@([^(:'\s]+)((?:\([^)]*\))*)'?:\s*$/gmu;
|
|
957
|
-
/**
|
|
958
|
-
* The body of the top-level `snapshots:` section. `packages:` lists the same
|
|
959
|
-
* name once without peers, which is not a second copy.
|
|
960
|
-
*/
|
|
961
|
-
function snapshotsSection(lock) {
|
|
962
|
-
const start = /^snapshots:\s*$/mu.exec(lock);
|
|
963
|
-
if (start === null) return "";
|
|
964
|
-
const rest = lock.slice(start.index + start[0].length);
|
|
965
|
-
const end = /^\S/mu.exec(rest.replace(/^\r?\n/u, ""));
|
|
966
|
-
const body = rest.replace(/^\r?\n/u, "");
|
|
967
|
-
return end === null ? body : body.slice(0, end.index);
|
|
968
|
-
}
|
|
969
|
-
function lockfileFrom(project) {
|
|
970
|
-
let dir = project.cwd;
|
|
971
|
-
for (let level = 0; level < MAX_LEVELS; level += 1) {
|
|
972
|
-
const candidate = join(dir, LOCKFILE);
|
|
973
|
-
if (project.files.exists(candidate)) return candidate;
|
|
974
|
-
const parent = dirname(dir);
|
|
975
|
-
if (parent === dir) return;
|
|
976
|
-
dir = parent;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
/**
|
|
980
|
-
* PD092: `pnpm-lock.yaml` resolves one `permdock` version with two or more peer
|
|
981
|
-
* sets, so an app loads two copies. Module state does not cross copies except
|
|
982
|
-
* through `Symbol.for` brands.
|
|
983
|
-
*/
|
|
984
|
-
function pd092(project) {
|
|
985
|
-
const lockfile = lockfileFrom(project);
|
|
986
|
-
if (lockfile === void 0) return [];
|
|
987
|
-
const variants = /* @__PURE__ */ new Map();
|
|
988
|
-
for (const match of snapshotsSection(project.files.read(lockfile)).matchAll(SNAPSHOT_KEY)) {
|
|
989
|
-
const version = String(match[1]);
|
|
990
|
-
const peers = variants.get(version) ?? /* @__PURE__ */ new Set();
|
|
991
|
-
peers.add(String(match[2]));
|
|
992
|
-
variants.set(version, peers);
|
|
993
|
-
}
|
|
994
|
-
return [...variants].filter(([, peers]) => peers.size > 1).map(([version, peers]) => {
|
|
995
|
-
const sets = [...peers].map((peer) => peer === "" ? "(no peers)" : peer);
|
|
996
|
-
return {
|
|
997
|
-
code: "PD092",
|
|
998
|
-
severity: "warning",
|
|
999
|
-
message: `${LOCKFILE} resolves permdock@${version} ${String(peers.size)} times: ${sets.join(" and ")}`,
|
|
1000
|
-
fix: "align the peer versions across workspace packages, or add a pnpm overrides entry for the peer that differs",
|
|
1001
|
-
target: `permdock@${version}`
|
|
1002
|
-
};
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
//#endregion
|
|
1006
|
-
//#region src/cli/doctor/next.ts
|
|
1007
|
-
const ROUTE_GLOBS = ["**/api/permdock/route.{ts,tsx,js,jsx,mjs}"];
|
|
1008
|
-
const ENDPOINT = /\bendpoint\s*(?::|=)\s*\{?\s*['"`]/u;
|
|
1009
|
-
const NATIVE_IMPORT = /\bfrom\s*['"]permdock\/react-native['"]/u;
|
|
1010
|
-
const CLIENT_READS = /* @__PURE__ */ new Set(["usePermission", "reference"]);
|
|
1011
|
-
/**
|
|
1012
|
-
* A grant the snapshot marks `portable: false`, so a client check needs the
|
|
1013
|
-
* endpoint.
|
|
1014
|
-
*/
|
|
1015
|
-
function serverOnly(policy, grant) {
|
|
1016
|
-
if (!grant.portable || hasConditionOp(grant.where, "related")) return true;
|
|
1017
|
-
const relations = policy.resources.get(grant.permission.resource)?.relations;
|
|
1018
|
-
return flattenGrantee(grant.to).some((item) => {
|
|
1019
|
-
if (item.kind !== "relation") return false;
|
|
1020
|
-
const spec = relations?.[item.relation];
|
|
1021
|
-
return item.through !== void 0 || isPrincipalRelation(spec) && spec.period !== void 0;
|
|
1022
|
-
});
|
|
1023
|
-
}
|
|
1024
|
-
function serverOnlyKeys(policy) {
|
|
1025
|
-
const keys = /* @__PURE__ */ new Set();
|
|
1026
|
-
for (const grant of [...policy.grants, ...policy.roles.flatMap((binding) => binding.grants)]) if (grant.hosted === void 0 && grant.effect === "allow" && serverOnly(policy, grant)) keys.add(grant.permission.key);
|
|
1027
|
-
return keys;
|
|
1028
|
-
}
|
|
1029
|
-
/**
|
|
1030
|
-
* An `app/**\/api/permdock/route.ts` that exports `permdockHandler`'s result,
|
|
1031
|
-
* or an `endpoint` string in the source.
|
|
1032
|
-
*/
|
|
1033
|
-
function hasEndpoint(files, cwd, sources) {
|
|
1034
|
-
if (listSourceFiles(cwd, ROUTE_GLOBS).filter((file) => /(?:^|[\\/])app[\\/]/u.test(rel(cwd, file))).some((file) => files.read(file).includes("permdockHandler"))) return true;
|
|
1035
|
-
return sources.some((file) => ENDPOINT.test(files.read(file)));
|
|
1036
|
-
}
|
|
1037
|
-
/**
|
|
1038
|
-
* PD044: `usePermission` reads a permission whose grant the snapshot cannot
|
|
1039
|
-
* answer, and the app has no endpoint to ask, so the client always denies it.
|
|
1040
|
-
*/
|
|
1041
|
-
async function pd044(input) {
|
|
1042
|
-
const policy = await policyOf(input);
|
|
1043
|
-
if (policy === void 0) return [];
|
|
1044
|
-
const keys = serverOnlyKeys(policy);
|
|
1045
|
-
if (keys.size === 0) return [];
|
|
1046
|
-
const usages = (await collectedOf(input)).scan?.usages ?? {};
|
|
1047
|
-
const hooked = [...keys].toSorted().flatMap((key) => (usages[key] ?? []).filter((usage) => usage.call === "usePermission").map((usage) => ({
|
|
1048
|
-
key,
|
|
1049
|
-
usage
|
|
1050
|
-
})));
|
|
1051
|
-
if (hooked.length === 0) return [];
|
|
1052
|
-
const sources = listSourceFiles(input.cwd, doctorSrcPath(input.config));
|
|
1053
|
-
if (hasEndpoint(filesOf(input), input.cwd, sources)) return [];
|
|
1054
|
-
return hooked.map(({ key, usage }) => ({
|
|
1055
|
-
code: "PD044",
|
|
1056
|
-
severity: "warning",
|
|
1057
|
-
message: `usePermission reads ${key} at ${usage.file}:${String(usage.line)}, whose grant needs the server (a closure, graph relation or period), and no app/**/api/permdock/route.ts exports permdockHandler and no endpoint is configured: the client always answers denied (server-only)`,
|
|
1058
|
-
fix: "add app/api/permdock/route.ts exporting permdockHandler(), pass endpoint to createPermDock, or check it on the server with getPermission"
|
|
1059
|
-
}));
|
|
1060
|
-
}
|
|
1061
|
-
/**
|
|
1062
|
-
* PD065: a file that imports `permdock/react-native` reads a permission whose
|
|
1063
|
-
* grant the snapshot cannot answer, so the device answers it only online.
|
|
1064
|
-
*/
|
|
1065
|
-
async function pd065(input) {
|
|
1066
|
-
const policy = await policyOf(input);
|
|
1067
|
-
if (policy === void 0) return [];
|
|
1068
|
-
const keys = serverOnlyKeys(policy);
|
|
1069
|
-
if (keys.size === 0) return [];
|
|
1070
|
-
const usages = (await collectedOf(input)).scan?.usages ?? {};
|
|
1071
|
-
const native = /* @__PURE__ */ new Map();
|
|
1072
|
-
const isNative = (file) => {
|
|
1073
|
-
let hit = native.get(file);
|
|
1074
|
-
if (hit === void 0) {
|
|
1075
|
-
try {
|
|
1076
|
-
hit = NATIVE_IMPORT.test(filesOf(input).read(join(input.cwd, file)));
|
|
1077
|
-
} catch {
|
|
1078
|
-
hit = false;
|
|
1079
|
-
}
|
|
1080
|
-
native.set(file, hit);
|
|
1081
|
-
}
|
|
1082
|
-
return hit;
|
|
1083
|
-
};
|
|
1084
|
-
return [...keys].toSorted().flatMap((key) => (usages[key] ?? []).filter((usage) => CLIENT_READS.has(usage.call) && isNative(usage.file)).map((usage) => ({
|
|
1085
|
-
code: "PD065",
|
|
1086
|
-
severity: "warning",
|
|
1087
|
-
message: `React Native code reads ${key} at ${usage.file}:${String(usage.line)}, whose grant needs the server (a closure, graph relation or period): offline the device answers denied (server-only)`,
|
|
1088
|
-
fix: "express the grant with a portable condition if the screen must work offline, or show the offline state for it"
|
|
1089
|
-
})));
|
|
1090
|
-
}
|
|
1091
|
-
//#endregion
|
|
1092
|
-
//#region src/cli/doctor/openapi.ts
|
|
1093
|
-
function isOperationPermissions(value) {
|
|
1094
|
-
return isRecord(value) && typeof value["entries"] === "function";
|
|
1095
|
-
}
|
|
1096
|
-
/** `path#export` splits at the last `#`; without one the export is `operations`. */
|
|
1097
|
-
function splitSpecifier(specifier) {
|
|
1098
|
-
const hash = specifier.lastIndexOf("#");
|
|
1099
|
-
return hash === -1 ? {
|
|
1100
|
-
path: specifier,
|
|
1101
|
-
name: "operations"
|
|
1102
|
-
} : {
|
|
1103
|
-
path: specifier.slice(0, hash),
|
|
1104
|
-
name: specifier.slice(hash + 1)
|
|
1105
|
-
};
|
|
1106
|
-
}
|
|
1107
|
-
/**
|
|
1108
|
-
* PD091 runs only when the config names the operations, the documents and the
|
|
1109
|
-
* tenant paths.
|
|
1110
|
-
*/
|
|
1111
|
-
function pd091Applies(config) {
|
|
1112
|
-
return config.openapi?.operations !== void 0 && config.openapi.tenantPaths !== void 0 && (config.openapi.doc?.length ?? 0) > 0;
|
|
1113
|
-
}
|
|
1114
|
-
/**
|
|
1115
|
-
* PD091: an operation under `openapi.tenantPaths` that `openapi.operations`
|
|
1116
|
-
* declares no entry for, so the HTTP gate denies it, or a declared entry that
|
|
1117
|
-
* matches no operation of an `openapi.doc` document. It runs
|
|
1118
|
-
* `operationCoverage`, the function `testOperationCoverage` runs.
|
|
1119
|
-
*/
|
|
1120
|
-
async function pd091(project) {
|
|
1121
|
-
const openapi = project.config.openapi;
|
|
1122
|
-
if (openapi?.operations === void 0 || openapi.tenantPaths === void 0) return [];
|
|
1123
|
-
const { path, name } = splitSpecifier(openapi.operations);
|
|
1124
|
-
let operations;
|
|
1125
|
-
try {
|
|
1126
|
-
operations = (await loadModule(resolve(project.cwd, path)))[name];
|
|
1127
|
-
} catch (error) {
|
|
1128
|
-
return [{
|
|
1129
|
-
code: "PD091",
|
|
1130
|
-
severity: "error",
|
|
1131
|
-
message: `openapi.operations '${openapi.operations}' does not load: ${describeError(error)}`,
|
|
1132
|
-
fix: "point openapi.operations at '<module>#<export>' of an operationPermissions(...) result",
|
|
1133
|
-
target: openapi.operations
|
|
1134
|
-
}];
|
|
1135
|
-
}
|
|
1136
|
-
if (!isOperationPermissions(operations)) return [{
|
|
1137
|
-
code: "PD091",
|
|
1138
|
-
severity: "error",
|
|
1139
|
-
message: `openapi.operations '${openapi.operations}' is not an operationPermissions(...) result`,
|
|
1140
|
-
fix: "export the operationPermissions(...) result and name it as '<module>#<export>'",
|
|
1141
|
-
target: openapi.operations
|
|
1142
|
-
}];
|
|
1143
|
-
const kernel = Reflect.get(operations, "kernel");
|
|
1144
|
-
const checked = openapi.enforcement === "kernel" && isOperationPermissions(kernel) ? kernel : operations;
|
|
1145
|
-
const findings = [];
|
|
1146
|
-
for (const doc of openapi.doc ?? []) {
|
|
1147
|
-
const abs = resolve(project.cwd, doc);
|
|
1148
|
-
if (!project.files.exists(abs)) continue;
|
|
1149
|
-
let document;
|
|
1150
|
-
try {
|
|
1151
|
-
document = JSON.parse(project.files.read(abs));
|
|
1152
|
-
} catch {
|
|
1153
|
-
findings.push({
|
|
1154
|
-
code: "PD091",
|
|
1155
|
-
severity: "error",
|
|
1156
|
-
message: `${doc} is not valid JSON, so operation coverage cannot be checked`,
|
|
1157
|
-
fix: "regenerate the document with permdock openapi",
|
|
1158
|
-
target: doc
|
|
1159
|
-
});
|
|
1160
|
-
continue;
|
|
1161
|
-
}
|
|
1162
|
-
const coverage = operationCoverage(checked, document, {
|
|
1163
|
-
tenantPaths: openapi.tenantPaths,
|
|
1164
|
-
...openapi.base === void 0 ? {} : { base: openapi.base }
|
|
1165
|
-
});
|
|
1166
|
-
for (const label of coverage.undeclared) findings.push({
|
|
1167
|
-
code: "PD091",
|
|
1168
|
-
severity: "error",
|
|
1169
|
-
message: `${doc}: ${label} is under a tenant path and has no entry in ${openapi.operations}, so the gate denies it`,
|
|
1170
|
-
fix: `declare '${label.replace(openapi.base ?? "", "")}' in operationPermissions, or move it out of openapi.tenantPaths`,
|
|
1171
|
-
target: `${doc}:${label}`
|
|
1172
|
-
});
|
|
1173
|
-
for (const label of coverage.stale) findings.push({
|
|
1174
|
-
code: "PD091",
|
|
1175
|
-
severity: "error",
|
|
1176
|
-
message: `${doc}: ${openapi.operations} declares ${label}, which the document does not contain`,
|
|
1177
|
-
fix: "remove the entry or regenerate the document",
|
|
1178
|
-
target: `${doc}:${label}`
|
|
1179
|
-
});
|
|
1180
|
-
}
|
|
1181
|
-
return findings;
|
|
1182
|
-
}
|
|
1183
|
-
//#endregion
|
|
1184
|
-
//#region src/cli/doctor/per-request.ts
|
|
1185
|
-
/** Factories whose answers or entries only pay off when one is shared. */
|
|
1186
|
-
const SHARED_FACTORIES = {
|
|
1187
|
-
postgrestSources: "PD080",
|
|
1188
|
-
memoryVersionCache: "PD080",
|
|
1189
|
-
claimsFirst: "PD080",
|
|
1190
|
-
instanceCache: "PD081"
|
|
1191
|
-
};
|
|
1192
|
-
/** Factories whose cost differs from their code's message. */
|
|
1193
|
-
const FACTORY_MESSAGES = { claimsFirst: {
|
|
1194
|
-
what: "so every call passes a new memberships source, which the instance cache compares by identity, and no instance is reused",
|
|
1195
|
-
fix: "create claimsFirst(...) once at module scope, or use permdockFor(...).sources(versions), and pass the same object to every adapter"
|
|
1196
|
-
} };
|
|
1197
|
-
const MESSAGES = {
|
|
1198
|
-
PD080: {
|
|
1199
|
-
what: "so every call starts with no shared version reads",
|
|
1200
|
-
fix: "create it once at module scope and pass the same object to every getPermDock call"
|
|
1201
|
-
},
|
|
1202
|
-
PD081: {
|
|
1203
|
-
what: "so every call gets an empty cache and no instance is reused",
|
|
1204
|
-
fix: "create one instanceCache() at module scope and pass it as instances to every adapter"
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
function isPermDockSpecifier(value) {
|
|
1208
|
-
return value === "permdock" || value.startsWith("permdock/");
|
|
1209
|
-
}
|
|
1210
|
-
/**
|
|
1211
|
-
* The calls to `postgrestSources`, `memoryVersionCache` and `instanceCache`
|
|
1212
|
-
* imported from PermDock that sit inside a function body, except the right side
|
|
1213
|
-
* of a `??=` or `||=`, the assignment guarded by `if (!x)` on the same name,
|
|
1214
|
-
* and the arguments of a call to a cache helper named in `doctor.cacheHelpers`:
|
|
1215
|
-
* each builds the object once.
|
|
1216
|
-
*/
|
|
1217
|
-
function callsInFunctions(source, cacheHelpers) {
|
|
1218
|
-
const { program } = parseSync(source.file, source.text);
|
|
1219
|
-
const names = /* @__PURE__ */ new Map();
|
|
1220
|
-
const namespaces = /* @__PURE__ */ new Set();
|
|
1221
|
-
const lazy = [];
|
|
1222
|
-
const found = [];
|
|
1223
|
-
let depth = 0;
|
|
1224
|
-
const enter = () => {
|
|
1225
|
-
depth += 1;
|
|
1226
|
-
};
|
|
1227
|
-
const exit = () => {
|
|
1228
|
-
depth -= 1;
|
|
1229
|
-
};
|
|
1230
|
-
createVisitor({
|
|
1231
|
-
ImportDeclaration(node) {
|
|
1232
|
-
if (node.importKind === "type" || !isPermDockSpecifier(node.source.value)) return;
|
|
1233
|
-
for (const specifier of node.specifiers) if (specifier.type === "ImportNamespaceSpecifier") namespaces.add(specifier.local.name);
|
|
1234
|
-
else if (specifier.type === "ImportSpecifier" && specifier.importKind !== "type") {
|
|
1235
|
-
const imported = specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value;
|
|
1236
|
-
if (Object.hasOwn(SHARED_FACTORIES, imported)) names.set(specifier.local.name, imported);
|
|
1237
|
-
}
|
|
1238
|
-
},
|
|
1239
|
-
FunctionDeclaration: enter,
|
|
1240
|
-
"FunctionDeclaration:exit": exit,
|
|
1241
|
-
FunctionExpression: enter,
|
|
1242
|
-
"FunctionExpression:exit": exit,
|
|
1243
|
-
ArrowFunctionExpression: enter,
|
|
1244
|
-
"ArrowFunctionExpression:exit": exit,
|
|
1245
|
-
AssignmentExpression(node) {
|
|
1246
|
-
if (node.operator === "??=" || node.operator === "||=") lazy.push({
|
|
1247
|
-
start: node.right.start,
|
|
1248
|
-
end: node.right.end
|
|
1249
|
-
});
|
|
1250
|
-
},
|
|
1251
|
-
IfStatement(node) {
|
|
1252
|
-
const { test } = node;
|
|
1253
|
-
if (test.type !== "UnaryExpression" || test.operator !== "!" || test.argument.type !== "Identifier") return;
|
|
1254
|
-
const guarded = test.argument.name;
|
|
1255
|
-
const body = node.consequent.type === "BlockStatement" ? node.consequent.body : [node.consequent];
|
|
1256
|
-
for (const statement of body) if (statement.type === "ExpressionStatement" && statement.expression.type === "AssignmentExpression" && statement.expression.operator === "=" && statement.expression.left.type === "Identifier" && statement.expression.left.name === guarded) {
|
|
1257
|
-
const { right } = statement.expression;
|
|
1258
|
-
lazy.push({
|
|
1259
|
-
start: right.start,
|
|
1260
|
-
end: right.end
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
},
|
|
1264
|
-
CallExpression(node) {
|
|
1265
|
-
const { callee } = node;
|
|
1266
|
-
const helper = callee.type === "Identifier" ? callee.name : callee.type === "MemberExpression" && callee.property.type === "Identifier" ? callee.property.name : void 0;
|
|
1267
|
-
if (helper !== void 0 && cacheHelpers.has(helper)) for (const argument of node.arguments) lazy.push({
|
|
1268
|
-
start: argument.start,
|
|
1269
|
-
end: argument.end
|
|
1270
|
-
});
|
|
1271
|
-
if (depth === 0) return;
|
|
1272
|
-
let factory;
|
|
1273
|
-
if (callee.type === "Identifier") factory = names.get(callee.name);
|
|
1274
|
-
else if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && namespaces.has(callee.object.name) && callee.property.type === "Identifier" && Object.hasOwn(SHARED_FACTORIES, callee.property.name)) factory = callee.property.name;
|
|
1275
|
-
if (factory !== void 0) found.push({
|
|
1276
|
-
call: node,
|
|
1277
|
-
factory
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
}).visit(program);
|
|
1281
|
-
return found.filter(({ call }) => !lazy.some((range) => call.start >= range.start && call.end <= range.end));
|
|
1282
|
-
}
|
|
1283
|
-
function findings(sources, code, cacheHelpers) {
|
|
1284
|
-
const out = [];
|
|
1285
|
-
for (const source of sources) {
|
|
1286
|
-
if (!source.text.includes("permdock")) continue;
|
|
1287
|
-
for (const { call, factory } of callsInFunctions(source, cacheHelpers)) {
|
|
1288
|
-
if (SHARED_FACTORIES[factory] !== code) continue;
|
|
1289
|
-
const line = source.text.slice(0, call.start).split("\n").length;
|
|
1290
|
-
const { what, fix } = FACTORY_MESSAGES[factory] ?? MESSAGES[code];
|
|
1291
|
-
out.push({
|
|
1292
|
-
code,
|
|
1293
|
-
severity: "warning",
|
|
1294
|
-
target: `${source.file}:${String(line)}`,
|
|
1295
|
-
message: `${source.file}:${String(line)} creates ${factory}() inside a function, ${what}`,
|
|
1296
|
-
fix
|
|
1297
|
-
});
|
|
1298
|
-
}
|
|
1299
|
-
}
|
|
1300
|
-
return out;
|
|
1301
|
-
}
|
|
1302
|
-
/**
|
|
1303
|
-
* PD080: `postgrestSources`, `memoryVersionCache` or `claimsFirst` created per
|
|
1304
|
-
* call.
|
|
1305
|
-
*/
|
|
1306
|
-
function pd080(sources, cacheHelpers = []) {
|
|
1307
|
-
return findings(sources, "PD080", new Set(cacheHelpers));
|
|
1308
|
-
}
|
|
1309
|
-
/** PD081: `instanceCache` created per call. */
|
|
1310
|
-
function pd081(sources, cacheHelpers = []) {
|
|
1311
|
-
return findings(sources, "PD081", new Set(cacheHelpers));
|
|
1312
|
-
}
|
|
1313
|
-
//#endregion
|
|
1314
|
-
//#region src/cli/doctor/policy.ts
|
|
1315
|
-
/** `doctor.waivers`, checked; PD017 is the only code a waiver names. */
|
|
1316
|
-
function waiversOf(input) {
|
|
1317
|
-
const entries = input.config.doctor?.waivers ?? [];
|
|
1318
|
-
if (!Array.isArray(entries)) throw configError("PermDock CLI: doctor.waivers must be a list of { code, key, reason }");
|
|
1319
|
-
return entries.map((entry, index) => {
|
|
1320
|
-
if (!isRecord(entry) || entry["code"] !== "PD017" || typeof entry["key"] !== "string" || entry["key"] === "" || typeof entry["reason"] !== "string" || entry["reason"].trim() === "") throw configError(`PermDock CLI: doctor.waivers[${String(index)}] needs code "PD017", a permission key and a non-empty reason`);
|
|
1321
|
-
return {
|
|
1322
|
-
key: entry["key"],
|
|
1323
|
-
reason: entry["reason"]
|
|
1324
|
-
};
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
async function pd017(input) {
|
|
1328
|
-
if (input.config.policy === void 0) return [];
|
|
1329
|
-
const policy = await policyOf(input);
|
|
1330
|
-
if (policy === void 0) return [];
|
|
1331
|
-
const sensitive = new Set(input.config.doctor?.sensitiveActions ?? DEFAULT_SENSITIVE_ACTIONS);
|
|
1332
|
-
const denied = new Set(policy.grants.filter((grant) => grant.effect === "deny").map((grant) => grant.permission.key));
|
|
1333
|
-
const waivers = waiversOf(input);
|
|
1334
|
-
const waived = new Set(waivers.map((waiver) => waiver.key));
|
|
1335
|
-
const matched = /* @__PURE__ */ new Set();
|
|
1336
|
-
const findings = [];
|
|
1337
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1338
|
-
for (const grant of policy.grants) {
|
|
1339
|
-
if (grant.effect !== "allow") continue;
|
|
1340
|
-
if (!sensitive.has(grant.permission.action)) continue;
|
|
1341
|
-
if (grant.approval !== void 0) continue;
|
|
1342
|
-
if (denied.has(grant.permission.key)) continue;
|
|
1343
|
-
if (seen.has(grant.permission.key)) continue;
|
|
1344
|
-
seen.add(grant.permission.key);
|
|
1345
|
-
if (waived.has(grant.permission.key)) {
|
|
1346
|
-
matched.add(grant.permission.key);
|
|
1347
|
-
continue;
|
|
1348
|
-
}
|
|
1349
|
-
findings.push({
|
|
1350
|
-
code: "PD017",
|
|
1351
|
-
severity: "warning",
|
|
1352
|
-
target: grant.permission.key,
|
|
1353
|
-
message: `${grant.permission.key} is a sensitive verb without approval`,
|
|
1354
|
-
fix: "add approval: { by } on the allow, or a deny on the same leaf, or waive it in doctor.waivers with a reason"
|
|
1355
|
-
});
|
|
1356
|
-
}
|
|
1357
|
-
for (const waiver of waivers) if (!matched.has(waiver.key)) findings.push({
|
|
1358
|
-
code: "PD017",
|
|
1359
|
-
severity: "warning",
|
|
1360
|
-
target: `waiver:${waiver.key}`,
|
|
1361
|
-
message: `doctor.waivers entry for ${waiver.key} matches no sensitive allow without approval`,
|
|
1362
|
-
fix: "remove the entry from doctor.waivers"
|
|
1363
|
-
});
|
|
1364
|
-
return findings;
|
|
1365
|
-
}
|
|
1366
|
-
async function pd024(input) {
|
|
1367
|
-
if (input.config.policy === void 0) return [];
|
|
1368
|
-
const policy = await policyOf(input);
|
|
1369
|
-
if (policy === void 0) return [];
|
|
1370
|
-
const findings = [];
|
|
1371
|
-
for (const grant of policy.grants) {
|
|
1372
|
-
const approval = grant.approval;
|
|
1373
|
-
if (grant.effect !== "allow" || approval === void 0 || approval === "human" || approval.mode !== "confirm") continue;
|
|
1374
|
-
findings.push({
|
|
1375
|
-
code: "PD024",
|
|
1376
|
-
severity: "warning",
|
|
1377
|
-
target: `${grant.permission.key}${grant.role === null ? "" : `@${grant.role}`}`,
|
|
1378
|
-
message: `${grant.permission.key}${grant.role === null ? "" : ` (role ${grant.role})`} sets approval.mode: 'confirm', so the requester can approve their own request`,
|
|
1379
|
-
fix: "remove mode: 'confirm' unless the requester confirming their own call (an agent asking its user) is the intent"
|
|
1380
|
-
});
|
|
1381
|
-
}
|
|
1382
|
-
return findings;
|
|
1383
|
-
}
|
|
1384
|
-
async function pd021(input) {
|
|
1385
|
-
if (input.config.policy === void 0) return [];
|
|
1386
|
-
const policy = await policyOf(input);
|
|
1387
|
-
if (policy === void 0 || (policy.hostable ?? []).length === 0) return [];
|
|
1388
|
-
const missing = ["PERMDOCK_CLOUD_URL", "PERMDOCK_CLOUD_KEY"].filter((name) => (input.env[name] ?? "") === "");
|
|
1389
|
-
if (missing.length === 0) return [];
|
|
1390
|
-
return [{
|
|
1391
|
-
code: "PD021",
|
|
1392
|
-
severity: "warning",
|
|
1393
|
-
message: `the policy lists hostable permissions but ${missing.join(" and ")} is not set, so no hosted grant can be published or fetched`,
|
|
1394
|
-
fix: "set the variables from the PermDock Cloud dashboard, or remove hostable"
|
|
1395
|
-
}];
|
|
1396
|
-
}
|
|
1397
|
-
async function pd019(input) {
|
|
1398
|
-
const rls = input.config.rls;
|
|
1399
|
-
if ((rls?.authorize ?? rls?.rbac?.authorize) !== "jwt") return [];
|
|
1400
|
-
const expiry = supabaseConfig(input.cwd).jwtExpiry ?? 3600;
|
|
1401
|
-
if (expiry <= 3600 || input.config.policy === void 0) return [];
|
|
1402
|
-
const policy = await policyOf(input);
|
|
1403
|
-
if (policy === void 0) return [];
|
|
1404
|
-
const sensitive = new Set(input.config.doctor?.sensitiveActions ?? DEFAULT_SENSITIVE_ACTIONS);
|
|
1405
|
-
const keys = [...new Set(policy.grants.filter((grant) => grant.effect === "allow" && sensitive.has(grant.permission.action)).map((grant) => grant.permission.key))];
|
|
1406
|
-
if (keys.length === 0) return [];
|
|
1407
|
-
return [{
|
|
1408
|
-
code: "PD019",
|
|
1409
|
-
severity: "warning",
|
|
1410
|
-
message: `the RLS helpers and authorize() read roles from the JWT and jwt_expiry is ${String(expiry)}s: a revoked role keeps ${keys.join(", ")} until the token expires`,
|
|
1411
|
-
fix: "set rls.authorize: 'database', or lower [auth] jwt_expiry in supabase/config.toml to 3600 or less"
|
|
1412
|
-
}];
|
|
1413
|
-
}
|
|
1414
|
-
/**
|
|
1415
|
-
* Fixture memberships the policy's scopes would drop: an undeclared scope, a
|
|
1416
|
-
* missing parent id, mixed shapes.
|
|
1417
|
-
*/
|
|
1418
|
-
/**
|
|
1419
|
-
* A scope whose roles can all be removed can end up with nobody able to manage
|
|
1420
|
-
* it. Setting `min` on any of its roles (even `min: 0`) records the decision
|
|
1421
|
-
* and silences the warning.
|
|
1422
|
-
*/
|
|
1423
|
-
async function pd026(input) {
|
|
1424
|
-
if (input.config.policy === void 0) return [];
|
|
1425
|
-
const policy = await policyOf(input);
|
|
1426
|
-
if (policy === void 0) return [];
|
|
1427
|
-
const scopes = scopeList(policy.scopes);
|
|
1428
|
-
const findings = [];
|
|
1429
|
-
for (const { name } of scopes) {
|
|
1430
|
-
const held = policy.roles.filter((binding) => typeof binding.on === "string" && resolveScope(scopes, binding.on) === name);
|
|
1431
|
-
if (held.length === 0 || held.some((binding) => binding.min !== void 0)) continue;
|
|
1432
|
-
findings.push({
|
|
1433
|
-
code: "PD026",
|
|
1434
|
-
severity: "warning",
|
|
1435
|
-
message: `no role on scope '${name}' keeps a holder: every ${name} can lose its last ${held.map((binding) => binding.name).join(" / ")}`,
|
|
1436
|
-
fix: `set min: 1 on the role that manages a ${name} (role(..., { on: '${name}', min: 1 })), or min: 0 to record that none must stay`
|
|
1437
|
-
});
|
|
1438
|
-
}
|
|
1439
|
-
return findings;
|
|
1440
|
-
}
|
|
1441
|
-
/**
|
|
1442
|
-
* PD033: a role activation without a `maxDuration` (an elevation with no
|
|
1443
|
-
* ceiling never expires on its own), and an activation role that a fixture
|
|
1444
|
-
* membership also holds standing (an eligible-only role must never be held
|
|
1445
|
-
* directly).
|
|
1446
|
-
*/
|
|
1447
|
-
async function pd033(input) {
|
|
1448
|
-
if (input.config.policy === void 0) return [];
|
|
1449
|
-
const policy = await policyOf(input);
|
|
1450
|
-
if (policy === void 0) return [];
|
|
1451
|
-
const findings = [];
|
|
1452
|
-
const activation = /* @__PURE__ */ new Set();
|
|
1453
|
-
for (const binding of policy.roles) {
|
|
1454
|
-
if (binding.activation === void 0) continue;
|
|
1455
|
-
activation.add(binding.name);
|
|
1456
|
-
if (binding.activation.maxDuration === void 0) findings.push({
|
|
1457
|
-
code: "PD033",
|
|
1458
|
-
severity: "warning",
|
|
1459
|
-
message: `role '${binding.name}' has activation without maxDuration: an elevation never expires on its own`,
|
|
1460
|
-
fix: `set activation: { maxDuration: 14_400, ... } on role '${binding.name}'`
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
const fixture = membershipsFixture(input);
|
|
1464
|
-
const standing = /* @__PURE__ */ new Set();
|
|
1465
|
-
const eligible = /* @__PURE__ */ new Set();
|
|
1466
|
-
for (const membership of fixture.memberships ?? []) {
|
|
1467
|
-
for (const name of membership.roles ?? []) standing.add(name);
|
|
1468
|
-
for (const name of membership.eligible ?? []) eligible.add(name);
|
|
1469
|
-
}
|
|
1470
|
-
for (const name of activation) if (standing.has(name)) findings.push({
|
|
1471
|
-
code: "PD033",
|
|
1472
|
-
severity: "warning",
|
|
1473
|
-
message: `activation role '${name}' is held standing by a fixture membership: an eligible-only role must never be held directly`,
|
|
1474
|
-
fix: `list '${name}' under eligible, never roles, and activate it with permdock.activate`
|
|
1475
|
-
});
|
|
1476
|
-
return findings;
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* PD035: a `supportAccess` role without `actorRequired`. Support access is
|
|
1480
|
-
* impersonation; without an actor the session is unattributed.
|
|
1481
|
-
*/
|
|
1482
|
-
async function pd035(input) {
|
|
1483
|
-
if (input.config.policy === void 0) return [];
|
|
1484
|
-
const policy = await policyOf(input);
|
|
1485
|
-
if (policy === void 0) return [];
|
|
1486
|
-
const findings = [];
|
|
1487
|
-
for (const binding of policy.roles) if (binding.support !== void 0 && !binding.support.actorRequired) findings.push({
|
|
1488
|
-
code: "PD035",
|
|
1489
|
-
severity: "warning",
|
|
1490
|
-
message: `support access role '${binding.name}' has actorRequired: false: a support session then runs as the tenant, unattributed`,
|
|
1491
|
-
fix: `set actorRequired: true on supportAccess({ role: '${binding.name}', ... })`
|
|
1492
|
-
});
|
|
1493
|
-
return findings;
|
|
1494
|
-
}
|
|
1495
|
-
//#endregion
|
|
1496
|
-
//#region src/cli/doctor/postgrest.ts
|
|
1497
|
-
const POSTGREST_IMPORT = /import\s*\{[^}]*\bpostgrestSources\b[^}]*\}\s*from\s*["']permdock\/supabase["']/u;
|
|
1498
|
-
function definesFunction(sql, suffix) {
|
|
1499
|
-
return new RegExp(String.raw`create\s+(?:or\s+replace\s+)?function\s+(?:(?:"[^"]+"|\w+)\.)?"?\w*${suffix}"?\s*\(`, "iu").test(sql);
|
|
1500
|
-
}
|
|
1501
|
-
/**
|
|
1502
|
-
* PD083: `postgrestSources` from `permdock/supabase` with a hook file that
|
|
1503
|
-
* defines `subject_for` and no `authz_version_for`. Since 0.17.0 `version`
|
|
1504
|
-
* calls only the version function, so every `claimsFirst` check fails closed.
|
|
1505
|
-
*/
|
|
1506
|
-
function pd083(cwd, config, sources, files = nodeFiles) {
|
|
1507
|
-
const user = sources.find((source) => POSTGREST_IMPORT.test(source.text));
|
|
1508
|
-
if (user === void 0) return [];
|
|
1509
|
-
const sql = sqlFiles(cwd, config.doctor?.migrations ?? MIGRATION_DIRS).map((file) => ({
|
|
1510
|
-
file,
|
|
1511
|
-
text: files.read(file)
|
|
1512
|
-
}));
|
|
1513
|
-
const subject = sql.find((item) => definesFunction(item.text, "subject_for"));
|
|
1514
|
-
if (subject === void 0 || sql.some((item) => definesFunction(item.text, "authz_version_for"))) return [];
|
|
1515
|
-
return [{
|
|
1516
|
-
code: "PD083",
|
|
1517
|
-
severity: "error",
|
|
1518
|
-
message: `${rel(cwd, user.file)} uses postgrestSources and ${rel(cwd, subject.file)} defines subject_for but no authz_version_for, so every version read fails and claimsFirst denies`,
|
|
1519
|
-
fix: "run permdock supabase hook generate (with supabase.hook.api for the PostgREST wrappers) and apply the migration it writes"
|
|
1520
|
-
}];
|
|
1521
|
-
}
|
|
1522
|
-
//#endregion
|
|
1523
|
-
//#region src/cli/doctor/powersync.ts
|
|
1524
|
-
/**
|
|
1525
|
-
* Why each membership source of a scope the streams read through sources has no
|
|
1526
|
-
* stream form, once per source.
|
|
1527
|
-
*/
|
|
1528
|
-
function sourceGaps(policy, config) {
|
|
1529
|
-
const scopes = scopeList(policy.scopes);
|
|
1530
|
-
const sources = membershipSourcesOf(config);
|
|
1531
|
-
const gaps = /* @__PURE__ */ new Set();
|
|
1532
|
-
for (const scope of scopes) {
|
|
1533
|
-
if (scopeMembershipTable(config.rls?.memberships, scopes, scope.name) !== void 0) continue;
|
|
1534
|
-
for (const source of scopeSourcesOf(sources, scope.name)) {
|
|
1535
|
-
const stream = streamOf(source);
|
|
1536
|
-
if (typeof stream === "string") gaps.add(stream);
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
return [...gaps];
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* PD058: `sync-config.yaml` or the `powersync.manifest` file is not what the
|
|
1543
|
-
* policy compiles to, so PowerSync syncs rows, or the device builds snapshots,
|
|
1544
|
-
* by an older policy. A policy that does not compile is a finding too, and so
|
|
1545
|
-
* is each membership source of a synced scope with no stream form: its members
|
|
1546
|
-
* sync none of the rows it grants.
|
|
1547
|
-
*/
|
|
1548
|
-
async function pd058(input) {
|
|
1549
|
-
const { cwd, config } = input;
|
|
1550
|
-
if (config.powersync === void 0 || config.policy === void 0) return [];
|
|
1551
|
-
const policy = await policyOf(input);
|
|
1552
|
-
if (policy === void 0) return [];
|
|
1553
|
-
let compiled;
|
|
1554
|
-
try {
|
|
1555
|
-
compiled = powersyncFiles(policy, config);
|
|
1556
|
-
} catch (cause) {
|
|
1557
|
-
return [{
|
|
1558
|
-
code: "PD058",
|
|
1559
|
-
severity: "warning",
|
|
1560
|
-
message: `the policy does not compile to Sync Streams: ${cause instanceof Error ? cause.message : String(cause)}`,
|
|
1561
|
-
fix: "fix the powersync and rls config, then run permdock powersync generate"
|
|
1562
|
-
}];
|
|
1563
|
-
}
|
|
1564
|
-
const gaps = sourceGaps(policy, config).map((gap) => ({
|
|
1565
|
-
code: "PD058",
|
|
1566
|
-
severity: "warning",
|
|
1567
|
-
message: gap,
|
|
1568
|
-
fix: "build the source with tableMembershipSource or junctionMembershipSource, without expiresAt, or serve its members from the server"
|
|
1569
|
-
}));
|
|
1570
|
-
return [...staleFiles(cwd, compiled.files).map((file) => ({
|
|
1571
|
-
code: "PD058",
|
|
1572
|
-
severity: "warning",
|
|
1573
|
-
message: file.missing ? `${file.path} is missing, so ${file.path === config.powersync?.manifest ? "the device builds no local snapshot" : "PowerSync syncs no stream the policy compiles to"}` : `${file.path} is not what the policy compiles to, so ${file.path === config.powersync?.manifest ? "the device builds snapshots" : "PowerSync syncs rows"} by an older policy`,
|
|
1574
|
-
fix: "run permdock powersync generate and deploy the files"
|
|
1575
|
-
})), ...gaps];
|
|
1576
|
-
}
|
|
1577
|
-
/**
|
|
1578
|
-
* PD084: a synced stream reads a token claim. PowerSync keeps the claims a
|
|
1579
|
-
* connection started with, so after a role or tenant change the device syncs by
|
|
1580
|
-
* the old claims until the app refreshes the session and reconnects.
|
|
1581
|
-
*/
|
|
1582
|
-
async function pd084(input) {
|
|
1583
|
-
const { config } = input;
|
|
1584
|
-
if (config.powersync === void 0 || config.policy === void 0) return [];
|
|
1585
|
-
const policy = await policyOf(input);
|
|
1586
|
-
if (policy === void 0) return [];
|
|
1587
|
-
let claims;
|
|
1588
|
-
try {
|
|
1589
|
-
({claims} = powersyncFiles(policy, config));
|
|
1590
|
-
} catch {
|
|
1591
|
-
return [];
|
|
1592
|
-
}
|
|
1593
|
-
return claims.map((message) => ({
|
|
1594
|
-
code: "PD084",
|
|
1595
|
-
severity: "warning",
|
|
1596
|
-
message,
|
|
1597
|
-
fix: "pass nativeRefresh from permdock/react-native to refreshOn, which refreshes the session and reconnects PowerSync on each authz:<uid> message"
|
|
1598
|
-
}));
|
|
1599
|
-
}
|
|
1600
|
-
//#endregion
|
|
1601
|
-
//#region src/cli/doctor/project.ts
|
|
1602
|
-
/**
|
|
1603
|
-
* Whether `dir` holds a skills lock: PermDock's own, or the `skills` CLI's
|
|
1604
|
-
* naming the `permdock` skill.
|
|
1605
|
-
*/
|
|
1606
|
-
function hasSkillsLock(files, dir) {
|
|
1607
|
-
if (files.exists(join(dir, ".permdock/skills-lock.json"))) return true;
|
|
1608
|
-
const shared = join(dir, "skills-lock.json");
|
|
1609
|
-
if (!files.exists(shared)) return false;
|
|
1610
|
-
try {
|
|
1611
|
-
const parsed = readJson(files, shared);
|
|
1612
|
-
const skills = parsed !== null && typeof parsed === "object" ? Reflect.get(parsed, "skills") : void 0;
|
|
1613
|
-
return skills !== null && typeof skills === "object" && Object.hasOwn(skills, "permdock");
|
|
1614
|
-
} catch {
|
|
1615
|
-
return false;
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
function pd005(cwd, files = nodeFiles) {
|
|
1619
|
-
const dirs = workspaceDirs(files, cwd);
|
|
1620
|
-
if (!dirs.some((dir) => [
|
|
1621
|
-
".agents/skills",
|
|
1622
|
-
".claude/skills",
|
|
1623
|
-
".cursor/skills"
|
|
1624
|
-
].some((folder) => files.exists(join(dir, folder, "permdock/SKILL.md"))))) return [{
|
|
1625
|
-
code: "PD005",
|
|
1626
|
-
severity: "warning",
|
|
1627
|
-
message: "Agent Skills are not installed",
|
|
1628
|
-
fix: "pnpm exec permdock skills install"
|
|
1629
|
-
}];
|
|
1630
|
-
if (!dirs.some((dir) => hasSkillsLock(files, dir))) return [{
|
|
1631
|
-
code: "PD005",
|
|
1632
|
-
severity: "warning",
|
|
1633
|
-
message: "skills lock is missing",
|
|
1634
|
-
fix: "pnpm exec permdock skills install"
|
|
1635
|
-
}];
|
|
1636
|
-
return [];
|
|
1637
|
-
}
|
|
1638
|
-
function pd006(cwd) {
|
|
1639
|
-
try {
|
|
1640
|
-
const pkg = createRequire(resolve(cwd, "package.json"))("typescript/package.json");
|
|
1641
|
-
const major = Number(pkg.version.split(".")[0]);
|
|
1642
|
-
if (major < 5 || major === 5 && Number(pkg.version.split(".")[1]) < 9) return [{
|
|
1643
|
-
code: "PD006",
|
|
1644
|
-
severity: "error",
|
|
1645
|
-
message: `TypeScript ${pkg.version} is below the supported matrix (5.9, 6, 7)`,
|
|
1646
|
-
fix: "upgrade typescript to 5.9 or later"
|
|
1647
|
-
}];
|
|
1648
|
-
if (major > 7) return [{
|
|
1649
|
-
code: "PD006",
|
|
1650
|
-
severity: "error",
|
|
1651
|
-
message: `TypeScript ${pkg.version} is not in the supported matrix (5.9, 6, 7)`,
|
|
1652
|
-
fix: "use TypeScript 5.9, 6 or 7"
|
|
1653
|
-
}];
|
|
1654
|
-
return [];
|
|
1655
|
-
} catch {
|
|
1656
|
-
return [{
|
|
1657
|
-
code: "PD006",
|
|
1658
|
-
severity: "error",
|
|
1659
|
-
message: "typescript is not installed",
|
|
1660
|
-
fix: "add typescript 5.9, 6 or 7"
|
|
1661
|
-
}];
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
function pd009(cwd, files = nodeFiles) {
|
|
1665
|
-
const copies = [];
|
|
1666
|
-
function walk(dir, depth) {
|
|
1667
|
-
if (depth > 6 || !files.exists(dir)) return;
|
|
1668
|
-
const pkg = join(dir, "node_modules/permdock/package.json");
|
|
1669
|
-
if (files.exists(pkg)) copies.push(pkg);
|
|
1670
|
-
if (!files.exists(join(dir, "node_modules"))) return;
|
|
1671
|
-
for (const name of files.list(join(dir, "node_modules"))) {
|
|
1672
|
-
if (name.startsWith(".")) continue;
|
|
1673
|
-
const nested = join(dir, "node_modules", name);
|
|
1674
|
-
try {
|
|
1675
|
-
if (files.isDirectory(nested)) walk(nested, depth + 1);
|
|
1676
|
-
} catch {}
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
walk(cwd, 0);
|
|
1680
|
-
if (copies.length > 1) return [{
|
|
1681
|
-
code: "PD009",
|
|
1682
|
-
severity: "error",
|
|
1683
|
-
message: `duplicate permdock copies: ${copies.map((item) => rel(cwd, dirname(item))).join(", ")}`,
|
|
1684
|
-
fix: "dedupe so only one permdock version is installed"
|
|
1685
|
-
}];
|
|
1686
|
-
return [];
|
|
1687
|
-
}
|
|
1688
|
-
function pd012(cwd, config, files = nodeFiles) {
|
|
1689
|
-
const docs = config.openapi?.doc ?? [];
|
|
1690
|
-
const findings = [];
|
|
1691
|
-
for (const doc of docs) {
|
|
1692
|
-
const abs = resolve(cwd, doc);
|
|
1693
|
-
if (!files.exists(abs)) continue;
|
|
1694
|
-
const text = files.read(abs);
|
|
1695
|
-
if (text.includes("\"drafts\"") && !text.includes("overlay")) findings.push({
|
|
1696
|
-
code: "PD012",
|
|
1697
|
-
severity: "warning",
|
|
1698
|
-
message: `${doc} carries a draft pin the CLI no longer emits`,
|
|
1699
|
-
fix: "regenerate with permdock openapi"
|
|
1700
|
-
});
|
|
1701
|
-
}
|
|
1702
|
-
return findings;
|
|
1703
|
-
}
|
|
1704
|
-
const VIEW_NAME = String.raw`((?:"[^"]+"|\w+)(?:\.(?:"[^"]+"|\w+))?)`;
|
|
1705
|
-
const CREATE_VIEW = new RegExp(String.raw`\bcreate\s+(?:or\s+replace\s+)?(?:temp(?:orary)?\s+)?(?:recursive\s+)?view\s+${VIEW_NAME}([\s\S]*?)\bas\b`, "giu");
|
|
1706
|
-
const ALTER_VIEW = new RegExp(String.raw`\balter\s+view\s+(?:if\s+exists\s+)?${VIEW_NAME}\s+set\s*\(([^)]*)\)`, "giu");
|
|
1707
|
-
const INVOKER = /\bsecurity_invoker\s*(?:=\s*(?:true|on|'true'|'on'|1)\b|[,)]|$)/iu;
|
|
1708
|
-
const COMPANION = new RegExp(String.raw`\bcomment\s+on\s+view\s+${VIEW_NAME}\s+is\s+'${FIELD_VIEWS.comment}\b`, "giu");
|
|
1709
|
-
/**
|
|
1710
|
-
* Views run as their owner unless `security_invoker` is set, so they read past
|
|
1711
|
-
* RLS on the tables beneath them. The `<table>_visible_fields` companion `rls
|
|
1712
|
-
* generate --revoke-columns` writes reads as its owner on purpose and carries a
|
|
1713
|
-
* comment that says so.
|
|
1714
|
-
*/
|
|
1715
|
-
function pd022(cwd, config, files = nodeFiles) {
|
|
1716
|
-
if (config.rls === void 0 && config.doctor?.migrations === void 0) return [];
|
|
1717
|
-
const created = /* @__PURE__ */ new Map();
|
|
1718
|
-
const invoker = /* @__PURE__ */ new Set();
|
|
1719
|
-
const companions = /* @__PURE__ */ new Set();
|
|
1720
|
-
for (const file of sqlFiles(cwd, config.doctor?.migrations ?? MIGRATION_DIRS)) {
|
|
1721
|
-
const raw = files.read(file);
|
|
1722
|
-
const text = raw.replaceAll(/--[^\n]*/gu, "").replaceAll(/\/\*[\s\S]*?\*\//gu, "");
|
|
1723
|
-
for (const [, name = "", options = ""] of text.matchAll(CREATE_VIEW)) {
|
|
1724
|
-
const key = tableKey(name);
|
|
1725
|
-
created.set(key, rel(cwd, file));
|
|
1726
|
-
if (INVOKER.test(options)) invoker.add(key);
|
|
1727
|
-
else invoker.delete(key);
|
|
1728
|
-
}
|
|
1729
|
-
for (const [, name = "", options = ""] of text.matchAll(ALTER_VIEW)) if (INVOKER.test(options)) invoker.add(tableKey(name));
|
|
1730
|
-
for (const [, name = ""] of raw.matchAll(COMPANION)) companions.add(tableKey(name));
|
|
1731
|
-
}
|
|
1732
|
-
return [...created].filter(([key]) => !invoker.has(key) && !companions.has(key)).map(([key, file]) => ({
|
|
1733
|
-
code: "PD022",
|
|
1734
|
-
severity: "warning",
|
|
1735
|
-
message: `view ${key} in ${file} is not security_invoker, so it reads past row level security`,
|
|
1736
|
-
fix: `create the view with (security_invoker = true), or alter view ${key} set (security_invoker = true); Postgres 15 or later. For column-level reads, generate field views with permdock rls generate --fields views`
|
|
1737
|
-
}));
|
|
1738
|
-
}
|
|
1739
|
-
const AUTH_ROLE = /\bauth\.role\s*\(\s*\)/giu;
|
|
1740
|
-
/**
|
|
1741
|
-
* PD040: `auth.role()` in a migration. Supabase deprecated it; a policy names
|
|
1742
|
-
* its Postgres roles with `to authenticated` instead, and the role claim it
|
|
1743
|
-
* reads is the one PostgREST already switched to.
|
|
1744
|
-
*/
|
|
1745
|
-
function pd040(cwd, config, files = nodeFiles) {
|
|
1746
|
-
const findings = [];
|
|
1747
|
-
for (const file of sqlFiles(cwd, config.doctor?.migrations ?? MIGRATION_DIRS)) {
|
|
1748
|
-
const text = files.read(file).replaceAll(/--[^\n]*/gu, (comment) => " ".repeat(comment.length)).replaceAll(/\/\*[\s\S]*?\*\//gu, (comment) => comment.replaceAll(/[^\n]/gu, " "));
|
|
1749
|
-
for (const match of text.matchAll(AUTH_ROLE)) {
|
|
1750
|
-
const line = text.slice(0, match.index).split("\n").length;
|
|
1751
|
-
findings.push({
|
|
1752
|
-
code: "PD040",
|
|
1753
|
-
severity: "warning",
|
|
1754
|
-
message: `${rel(cwd, file)}:${String(line)} calls auth.role(), which Supabase deprecated`,
|
|
1755
|
-
fix: "name the roles on the policy (create policy ... to authenticated) and drop the auth.role() = 'authenticated' test; call permdock_has or permitted_<scope>_ids for permissions"
|
|
1756
|
-
});
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
return findings;
|
|
1760
|
-
}
|
|
1761
|
-
const GRANT = /\b(grant|revoke)\s+([\s\S]+?)\s+on\s+(?:table\s+)?([\w."]+)\s+(?:to|from)\s+([\w\s,"]+?)(?:\s+with\s+grant\s+option|\s+cascade|\s+restrict)?\s*;/giu;
|
|
1762
|
-
const CLIENT_ROLES = /* @__PURE__ */ new Set([
|
|
1763
|
-
"anon",
|
|
1764
|
-
"authenticated",
|
|
1765
|
-
"public"
|
|
1766
|
-
]);
|
|
1767
|
-
function applyPrivilege(writable, verb, part) {
|
|
1768
|
-
const match = /^\s*(all(?:\s+privileges)?|insert|update)\s*(?:\(([^)]*)\))?\s*$/iu.exec(part);
|
|
1769
|
-
if (match === null) return;
|
|
1770
|
-
const kind = (match[1] ?? "").toLowerCase();
|
|
1771
|
-
const sets = kind === "insert" ? [writable.insert] : kind === "update" ? [writable.update] : [writable.insert, writable.update];
|
|
1772
|
-
const columns = match[2] === void 0 ? ["*"] : match[2].split(",").map((column) => column.trim().replaceAll("\"", ""));
|
|
1773
|
-
for (const set of sets) for (const column of columns) if (verb.toLowerCase() === "grant") set.add(column);
|
|
1774
|
-
else if (column === "*") set.clear();
|
|
1775
|
-
else set.delete(column);
|
|
1776
|
-
}
|
|
1777
|
-
const CREATE_TABLE$1 = /^create\s+(?:(?:global|local)\s+)?(?:(?:temp|temporary|unlogged)\s+)?table\s+(?:if\s+not\s+exists\s+)?((?:"[^"]+"|\w+)(?:\.(?:"[^"]+"|\w+))?)\s*\(/iu;
|
|
1778
|
-
const REVOKE_DEFAULT_TABLES = /^alter\s+default\s+privileges\s+(?:for\s+(?:role|user)\s+[\w\s,"]+?\s+)?in\s+schema\s+"?public"?\s+revoke\s+[\s\S]+?\s+on\s+tables\s+from\s+[\s\S]*\b(?:anon|authenticated)\b/iu;
|
|
1779
|
-
/**
|
|
1780
|
-
* Columns of `table` a client role may insert or update, per the migrations in
|
|
1781
|
-
* order; `*` for every column. On Supabase a table created in `public` starts
|
|
1782
|
-
* writable: the default privileges grant `anon` and `authenticated` everything,
|
|
1783
|
-
* until a migration revokes them.
|
|
1784
|
-
*/
|
|
1785
|
-
function clientWritable(files, cwd, config, target) {
|
|
1786
|
-
const writable = {
|
|
1787
|
-
insert: /* @__PURE__ */ new Set(),
|
|
1788
|
-
update: /* @__PURE__ */ new Set()
|
|
1789
|
-
};
|
|
1790
|
-
let defaults = config.supabase !== void 0 && target.startsWith("public.");
|
|
1791
|
-
for (const file of sqlFiles(cwd, config.doctor?.migrations ?? MIGRATION_DIRS)) for (const { text } of sqlStatements(files.read(file))) {
|
|
1792
|
-
if (REVOKE_DEFAULT_TABLES.test(text)) {
|
|
1793
|
-
defaults = false;
|
|
1794
|
-
continue;
|
|
1795
|
-
}
|
|
1796
|
-
const created = CREATE_TABLE$1.exec(text);
|
|
1797
|
-
if (created !== null) {
|
|
1798
|
-
if (defaults && tableKey(created[1] ?? "") === target) {
|
|
1799
|
-
writable.insert.add("*");
|
|
1800
|
-
writable.update.add("*");
|
|
1801
|
-
}
|
|
1802
|
-
continue;
|
|
1803
|
-
}
|
|
1804
|
-
for (const [, verb = "", privileges = "", name = "", roles = ""] of `${text};`.matchAll(GRANT)) {
|
|
1805
|
-
if (tableKey(name) !== target) continue;
|
|
1806
|
-
if (!roles.split(",").map((role) => role.trim().replaceAll("\"", "").toLowerCase()).some((role) => CLIENT_ROLES.has(role))) continue;
|
|
1807
|
-
for (const part of privileges.split(/,(?![^(]*\))/u)) applyPrivilege(writable, verb, part);
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
return /* @__PURE__ */ new Set([...writable.insert, ...writable.update]);
|
|
1811
|
-
}
|
|
1812
|
-
/**
|
|
1813
|
-
* Membership columns a client can write: a user who sets `user_id` or `role`
|
|
1814
|
-
* grants themselves access.
|
|
1815
|
-
*/
|
|
1816
|
-
function membershipFindings(files, cwd, config) {
|
|
1817
|
-
const findings = [];
|
|
1818
|
-
for (const [table, columns] of membershipColumns(config)) {
|
|
1819
|
-
const writable = clientWritable(files, cwd, config, table);
|
|
1820
|
-
const exposed = [...columns].filter((column) => writable.has("*") || writable.has(column));
|
|
1821
|
-
if (exposed.length > 0) findings.push({
|
|
1822
|
-
code: "PD028",
|
|
1823
|
-
severity: "warning",
|
|
1824
|
-
message: `${table}.${exposed.join(", ")} decide${exposed.length === 1 ? "s" : ""} memberships, and the migrations let anon or authenticated insert or update ${exposed.length === 1 ? "it" : "them"}: a user could give themselves a membership`,
|
|
1825
|
-
fix: `revoke insert, update on ${table} from anon, authenticated, then grant update (<columns clients edit>) on ${table} to authenticated; a column-level revoke alone leaves a table-level grant in place`
|
|
1826
|
-
});
|
|
1827
|
-
}
|
|
1828
|
-
return findings;
|
|
1829
|
-
}
|
|
1830
|
-
/**
|
|
1831
|
-
* `attrs` claims must come from server-owned columns: never `user_metadata`,
|
|
1832
|
-
* never a column clients can write. Membership sources' deciding columns are
|
|
1833
|
-
* held to the same rule.
|
|
1834
|
-
*/
|
|
1835
|
-
function pd028(cwd, config, plan, files = nodeFiles) {
|
|
1836
|
-
const memberships = membershipFindings(files, cwd, config);
|
|
1837
|
-
const attrs = config.supabase?.hook?.attrs;
|
|
1838
|
-
if (attrs === void 0) return memberships;
|
|
1839
|
-
const planned = plan(attrs);
|
|
1840
|
-
const findings = planned.errors.map((message) => ({
|
|
1841
|
-
code: "PD028",
|
|
1842
|
-
severity: "error",
|
|
1843
|
-
message,
|
|
1844
|
-
fix: "list server-owned columns or app_metadata.<key> entries; user_metadata is user-editable"
|
|
1845
|
-
}));
|
|
1846
|
-
if (planned.table !== void 0 && planned.columns.length > 0) {
|
|
1847
|
-
const writable = clientWritable(files, cwd, config, tableKey(planned.table));
|
|
1848
|
-
const exposed = planned.columns.filter((column) => writable.has("*") || writable.has(column));
|
|
1849
|
-
if (exposed.length > 0) findings.push({
|
|
1850
|
-
code: "PD028",
|
|
1851
|
-
severity: "warning",
|
|
1852
|
-
message: `attrs reads ${exposed.join(", ")} from ${tableKey(planned.table)}, which the migrations let anon or authenticated insert or update: a user could set their own attribute`,
|
|
1853
|
-
fix: `revoke insert, update on ${tableKey(planned.table)} from anon, authenticated, and grant column-level update only on columns that are not attributes; the generated hook migration refuses to install otherwise`
|
|
1854
|
-
});
|
|
1855
|
-
}
|
|
1856
|
-
return [...findings, ...memberships];
|
|
1857
|
-
}
|
|
1858
|
-
//#endregion
|
|
1859
|
-
//#region src/cli/doctor/rls.ts
|
|
1860
|
-
async function pd027(input) {
|
|
1861
|
-
if (input.config.rls === void 0 || input.config.policy === void 0) return [];
|
|
1862
|
-
const policy = await policyOf(input);
|
|
1863
|
-
if (policy === void 0) return [];
|
|
1864
|
-
const findings = [];
|
|
1865
|
-
for (const grant of policy.grants) {
|
|
1866
|
-
const refs = [.../* @__PURE__ */ new Set([...contextRefs(grant.where), ...contextRefs(grant.check)])];
|
|
1867
|
-
if (refs.length === 0) continue;
|
|
1868
|
-
findings.push({
|
|
1869
|
-
code: "PD027",
|
|
1870
|
-
severity: "warning",
|
|
1871
|
-
message: `${grant.permission.key}${grant.role === null ? "" : ` (role ${grant.role})`} reads ${refs.join(", ")}: request context is not in the token, so permdock rls generate cannot compile it and the database cannot enforce it`,
|
|
1872
|
-
fix: "move the value to a server-set claim and compare with principal.claims.<name>, or keep the check API-side and pass --skip-closures to rls generate"
|
|
1873
|
-
});
|
|
1874
|
-
}
|
|
1875
|
-
return findings;
|
|
1876
|
-
}
|
|
1877
|
-
async function pd016(input) {
|
|
1878
|
-
const files = filesOf(input);
|
|
1879
|
-
if (input.config.rls === void 0 || input.config.policy === void 0) return [];
|
|
1880
|
-
const policy = await policyOf(input);
|
|
1881
|
-
if (policy === void 0) return [];
|
|
1882
|
-
const findings = [];
|
|
1883
|
-
let opaque = false;
|
|
1884
|
-
let sqlFunction = false;
|
|
1885
|
-
for (const grant of policy.grants) {
|
|
1886
|
-
if (hasConditionOp(grant.where, "opaque") || hasConditionOp(grant.check, "opaque")) opaque = true;
|
|
1887
|
-
if (hasConditionOp(grant.where, "sqlFunction") || hasConditionOp(grant.check, "sqlFunction")) sqlFunction = true;
|
|
1888
|
-
}
|
|
1889
|
-
if (opaque) findings.push({
|
|
1890
|
-
code: "PD016",
|
|
1891
|
-
severity: "warning",
|
|
1892
|
-
message: "policy has opaque RLS conditions that deny in memory",
|
|
1893
|
-
fix: "add rls.functions.<name> with a portable twin, or rewrite as sqlFunction()"
|
|
1894
|
-
});
|
|
1895
|
-
if (sqlFunction) {
|
|
1896
|
-
const fixtures = input.config.rls.fixtures ?? "rls.fixtures.json";
|
|
1897
|
-
if (!files.exists(resolve(input.cwd, fixtures)) && !files.exists(resolve(input.cwd, "rls.fixtures.ts"))) findings.push({
|
|
1898
|
-
code: "PD016",
|
|
1899
|
-
severity: "warning",
|
|
1900
|
-
message: "sqlFunction grants have no rls fixtures for verify --db-url-stdin",
|
|
1901
|
-
fix: "add rls.fixtures.json and run permdock rls verify --db-url-stdin"
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
return findings;
|
|
1905
|
-
}
|
|
1906
|
-
async function pd020(input) {
|
|
1907
|
-
if (input.config.rls === void 0 || input.config.policy === void 0) return [];
|
|
1908
|
-
const policy = await policyOf(input);
|
|
1909
|
-
if (policy === void 0) return [];
|
|
1910
|
-
const tables = input.config.rls.tables;
|
|
1911
|
-
const compiled = (policy.hostable ?? []).filter((key) => {
|
|
1912
|
-
const resource = key.slice(0, key.lastIndexOf("."));
|
|
1913
|
-
return tables === void 0 || tables[resource] !== void 0;
|
|
1914
|
-
});
|
|
1915
|
-
if (compiled.length === 0) return [];
|
|
1916
|
-
return [{
|
|
1917
|
-
code: "PD020",
|
|
1918
|
-
severity: "warning",
|
|
1919
|
-
message: `hostable permissions are also compiled into RLS, which never sees hosted grants: ${compiled.join(", ")}`,
|
|
1920
|
-
fix: "remove them from hostable, or drop their tables from rls.tables and enforce them in the application"
|
|
1921
|
-
}];
|
|
1922
|
-
}
|
|
1923
|
-
/**
|
|
1924
|
-
* Columns of `resource` a field-limited read grant can hide: missing from an
|
|
1925
|
-
* allow's list, or on a deny's.
|
|
1926
|
-
*/
|
|
1927
|
-
function limitedColumns(policy, resource, actions) {
|
|
1928
|
-
const reads = policy.grants.filter((grant) => grant.permission.resource === resource && grant.fields !== void 0 && commandFor(grant.permission.action, actions) === "select");
|
|
1929
|
-
const node = policy.resources.get(resource);
|
|
1930
|
-
const schema = node === void 0 ? null : jsonSchemaOf(node);
|
|
1931
|
-
const properties = schema !== null && typeof schema === "object" ? schema.properties : void 0;
|
|
1932
|
-
const columns = properties !== null && typeof properties === "object" ? Object.keys(properties) : [...new Set(reads.flatMap((grant) => grant.fields ?? []))];
|
|
1933
|
-
const key = node?.id ?? "id";
|
|
1934
|
-
return columns.filter((column) => column !== key && reads.some((grant) => grant.effect === "deny" ? (grant.fields ?? []).includes(column) : !(grant.fields ?? []).includes(column)));
|
|
1935
|
-
}
|
|
1936
|
-
/**
|
|
1937
|
-
* `fields` redact in the application; RLS is row-level unless field views
|
|
1938
|
-
* compile, and a field view protects nothing while the base table still returns
|
|
1939
|
-
* the columns to a direct read.
|
|
1940
|
-
*/
|
|
1941
|
-
async function pd030(input) {
|
|
1942
|
-
const rls = input.config.rls;
|
|
1943
|
-
if (rls === void 0 || input.config.policy === void 0) return [];
|
|
1944
|
-
const policy = await policyOf(input);
|
|
1945
|
-
if (policy === void 0) return [];
|
|
1946
|
-
const resources = [...new Set(policy.grants.filter((grant) => grant.fields !== void 0 && commandFor(grant.permission.action, rls.actions) === "select").map((grant) => grant.permission.resource))].toSorted();
|
|
1947
|
-
const findings = [];
|
|
1948
|
-
for (const resource of resources) {
|
|
1949
|
-
const columns = limitedColumns(policy, resource, rls.actions);
|
|
1950
|
-
if (columns.length === 0) continue;
|
|
1951
|
-
const table = tableFor(resource, tableNames(rls.tables));
|
|
1952
|
-
if (rls.fields === void 0) {
|
|
1953
|
-
findings.push({
|
|
1954
|
-
code: "PD030",
|
|
1955
|
-
severity: "warning",
|
|
1956
|
-
message: `read grants on ${resource} limit ${columns.join(", ")}, but RLS on ${table} is row-level: any client that reads ${table} directly gets those columns`,
|
|
1957
|
-
fix: `set rls.fields: 'views' and rls.revokeColumns: true (permdock rls generate --fields views --revoke-columns), or keep direct reads server-side and redact with pick`
|
|
1958
|
-
});
|
|
1959
|
-
continue;
|
|
1960
|
-
}
|
|
1961
|
-
if (rls.revokeColumns !== true) findings.push({
|
|
1962
|
-
code: "PD030",
|
|
1963
|
-
severity: "warning",
|
|
1964
|
-
message: `${table}_visible masks ${columns.join(", ")}, but ${table} still returns them to a direct read`,
|
|
1965
|
-
fix: `set rls.revokeColumns: true (--revoke-columns) so clients read ${columns.join(", ")} only through ${table}_visible`
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
return findings;
|
|
1969
|
-
}
|
|
1970
|
-
/**
|
|
1971
|
-
* A self-parented resource no `through` grant walks, or a `restricted` column
|
|
1972
|
-
* no graph grant reaches: the declaration has no effect on any decision, and
|
|
1973
|
-
* `rls generate` keeps no closure for it.
|
|
1974
|
-
*/
|
|
1975
|
-
async function pd031(input) {
|
|
1976
|
-
if (input.config.policy === void 0) return [];
|
|
1977
|
-
const policy = await policyOf(input);
|
|
1978
|
-
if (policy === void 0) return [];
|
|
1979
|
-
const plan = graphPlan(policy);
|
|
1980
|
-
const findings = [];
|
|
1981
|
-
for (const node of policy.resources.values()) {
|
|
1982
|
-
const walked = plan.get(node.name)?.closure !== void 0;
|
|
1983
|
-
if (node.parent?.resource === node.name && !walked) findings.push({
|
|
1984
|
-
code: "PD031",
|
|
1985
|
-
severity: "warning",
|
|
1986
|
-
message: `${node.name} parents itself through ${node.parent.field}, but no grant walks it with relation(..., { through: 'parent' }): its ancestors grant nothing and rls generate keeps no closure for it`,
|
|
1987
|
-
fix: `grant through the chain (relation(permissions.${node.name}, '<relation>', { through: 'parent', depth: 16 })) or drop the self-parent`
|
|
1988
|
-
});
|
|
1989
|
-
const reached = [...plan.values()].some((entry) => entry.node.name === node.name || node.parent?.resource === entry.node.name && entry.node.name !== node.name);
|
|
1990
|
-
if (node.restricted !== void 0 && !reached) findings.push({
|
|
1991
|
-
code: "PD031",
|
|
1992
|
-
severity: "warning",
|
|
1993
|
-
message: `${node.name} declares restricted: '${node.restricted}', but no graph grant reaches ${node.name} rows, so the column keeps nothing out`,
|
|
1994
|
-
fix: `add a relation(..., { through: 'parent' }) grant that reaches ${node.name}, or remove restricted`
|
|
1995
|
-
});
|
|
1996
|
-
}
|
|
1997
|
-
return findings;
|
|
1998
|
-
}
|
|
1999
|
-
/**
|
|
2000
|
-
* Under an `rls` config, a graph resource `rls generate` cannot name a helper
|
|
2001
|
-
* for: one that shares a scope's name (its `permitted_<name>_ids` would replace
|
|
2002
|
-
* the scope helper) or is not a lowercase SQL name.
|
|
2003
|
-
*/
|
|
2004
|
-
async function pd032(input) {
|
|
2005
|
-
if (input.config.rls === void 0 || input.config.policy === void 0) return [];
|
|
2006
|
-
const policy = await policyOf(input);
|
|
2007
|
-
if (policy === void 0) return [];
|
|
2008
|
-
const scopes = scopeList(policy.scopes);
|
|
2009
|
-
const findings = [];
|
|
2010
|
-
const sqlNames = /* @__PURE__ */ new Map();
|
|
2011
|
-
for (const name of graphPlan(policy).keys()) {
|
|
2012
|
-
const sql = graphSqlName(name);
|
|
2013
|
-
if (sql === void 0) {
|
|
2014
|
-
findings.push({
|
|
2015
|
-
code: "PD032",
|
|
2016
|
-
severity: "error",
|
|
2017
|
-
message: `graph resource ${name} is not a SQL name, so rls generate cannot name its permitted_<name>_ids helper`,
|
|
2018
|
-
fix: "rename the resource to letters, digits and underscores, starting with a letter"
|
|
2019
|
-
});
|
|
2020
|
-
continue;
|
|
2021
|
-
}
|
|
2022
|
-
if (scopes.some((scope) => scope.name === sql)) findings.push({
|
|
2023
|
-
code: "PD032",
|
|
2024
|
-
severity: "error",
|
|
2025
|
-
message: `graph resource ${name} shares its SQL name with the ${sql} scope: permitted_${sql}_ids would replace the scope helper, so rls generate refuses it`,
|
|
2026
|
-
fix: `rename the resource (for example ${sql}s or ${sql}_node) or the scope`
|
|
2027
|
-
});
|
|
2028
|
-
const other = sqlNames.get(sql);
|
|
2029
|
-
if (other !== void 0) findings.push({
|
|
2030
|
-
code: "PD032",
|
|
2031
|
-
severity: "error",
|
|
2032
|
-
message: `graph resources ${other} and ${name} both become permitted_${sql}_ids in SQL, so rls generate refuses them`,
|
|
2033
|
-
fix: "rename one of the resources"
|
|
2034
|
-
});
|
|
2035
|
-
sqlNames.set(sql, name);
|
|
2036
|
-
}
|
|
2037
|
-
return findings;
|
|
2038
|
-
}
|
|
2039
|
-
/**
|
|
2040
|
-
* PD034: a break-glass grant under an `rls` config. RLS never compiles a
|
|
2041
|
-
* break-glass override; the server must read through a `security definer`
|
|
2042
|
-
* function that checks a signed break-glass session and writes an audit row.
|
|
2043
|
-
*/
|
|
2044
|
-
async function pd034(input) {
|
|
2045
|
-
if (input.config.policy === void 0 || input.config.rls === void 0) return [];
|
|
2046
|
-
const policy = await policyOf(input);
|
|
2047
|
-
if (policy === void 0) return [];
|
|
2048
|
-
const keys = /* @__PURE__ */ new Set();
|
|
2049
|
-
for (const grant of policy.grants) if (grant.breakGlass !== void 0) keys.add(grant.permission.key);
|
|
2050
|
-
return [...keys].map((key) => ({
|
|
2051
|
-
code: "PD034",
|
|
2052
|
-
severity: "warning",
|
|
2053
|
-
message: `break-glass grant on ${key} cannot be compiled to RLS: it would leak the override into a database policy`,
|
|
2054
|
-
fix: "read break-glass rows through a security definer function that checks a signed break-glass session and writes an audit row"
|
|
2055
|
-
}));
|
|
2056
|
-
}
|
|
2057
|
-
/**
|
|
2058
|
-
* PD076: `rls.actions` entries set to `'none'` that change nothing: a verb that
|
|
2059
|
-
* is not one of the six default verbs and does not read as a write compiles to
|
|
2060
|
-
* no policy anyway, and a verb no permission uses compiles to nothing at all. A
|
|
2061
|
-
* write-sounding `none` stays, because it silences PD071.
|
|
2062
|
-
*/
|
|
2063
|
-
async function pd076(input) {
|
|
2064
|
-
const actions = input.config.rls?.actions;
|
|
2065
|
-
if (actions === void 0 || input.config.policy === void 0) return [];
|
|
2066
|
-
const policy = await policyOf(input);
|
|
2067
|
-
if (policy === void 0) return [];
|
|
2068
|
-
const used = new Set(listPermissions(policy.vocabulary.permissions).map((leaf) => leaf.action));
|
|
2069
|
-
const unused = Object.keys(actions).filter((verb) => !used.has(verb)).toSorted();
|
|
2070
|
-
const noop = Object.entries(actions).filter(([verb, command]) => command === "none" && used.has(verb) && commandFor(verb) === void 0 && !suggestsWrite(verb)).map(([verb]) => verb).toSorted();
|
|
2071
|
-
return [...noop.length === 0 ? [] : [{
|
|
2072
|
-
code: "PD076",
|
|
2073
|
-
severity: "info",
|
|
2074
|
-
message: `rls.actions sets ${noop.join(", ")} to 'none', which is already what ${noop.length === 1 ? "that verb compiles" : "those verbs compile"} to`,
|
|
2075
|
-
fix: `delete these entries: ${noop.join(", ")}`
|
|
2076
|
-
}], ...unused.length === 0 ? [] : [{
|
|
2077
|
-
code: "PD076",
|
|
2078
|
-
severity: "info",
|
|
2079
|
-
message: `rls.actions maps ${unused.join(", ")}, which no permission uses`,
|
|
2080
|
-
fix: `delete these entries, or fix the verb's spelling: ${unused.join(", ")}`
|
|
2081
|
-
}]];
|
|
2082
|
-
}
|
|
2083
|
-
/**
|
|
2084
|
-
* Storage and Realtime policies written outside PermDock that call the SQL
|
|
2085
|
-
* helpers for a permission whose grants carry row conditions: the helpers check
|
|
2086
|
-
* only role and scope.
|
|
2087
|
-
*/
|
|
2088
|
-
async function pd037(input) {
|
|
2089
|
-
const files = filesOf(input);
|
|
2090
|
-
if (input.config.policy === void 0) return [];
|
|
2091
|
-
const policy = await policyOf(input);
|
|
2092
|
-
if (policy === void 0) return [];
|
|
2093
|
-
const conditioned = policyRowConditionKeys(policy);
|
|
2094
|
-
const findings = [];
|
|
2095
|
-
for (const file of sqlFiles(input.cwd, input.config.doctor?.migrations ?? MIGRATION_DIRS)) for (const found of helperTablePolicies(files.read(file))) {
|
|
2096
|
-
const keys = found.keys.filter((key) => conditioned.has(key));
|
|
2097
|
-
if (keys.length > 0) findings.push({
|
|
2098
|
-
code: "PD037",
|
|
2099
|
-
severity: "error",
|
|
2100
|
-
message: rowConditionMessage(found, keys),
|
|
2101
|
-
fix: ROW_CONDITION_FIX
|
|
2102
|
-
});
|
|
2103
|
-
}
|
|
2104
|
-
return findings;
|
|
2105
|
-
}
|
|
2106
|
-
const WRITE_VERB_PREFIXES = [
|
|
2107
|
-
"create",
|
|
2108
|
-
"update",
|
|
2109
|
-
"delete",
|
|
2110
|
-
"remove",
|
|
2111
|
-
"send",
|
|
2112
|
-
"mark",
|
|
2113
|
-
"cancel",
|
|
2114
|
-
"approve",
|
|
2115
|
-
"receive",
|
|
2116
|
-
"fulfill",
|
|
2117
|
-
"reimburse",
|
|
2118
|
-
"withdraw",
|
|
2119
|
-
"writeOff",
|
|
2120
|
-
"confirm",
|
|
2121
|
-
"pause"
|
|
2122
|
-
];
|
|
2123
|
-
/**
|
|
2124
|
-
* `verb` starts with a write prefix that ends at a word boundary: `markPaid`,
|
|
2125
|
-
* not `market`.
|
|
2126
|
-
*/
|
|
2127
|
-
function suggestsWrite(verb) {
|
|
2128
|
-
return WRITE_VERB_PREFIXES.some((prefix) => {
|
|
2129
|
-
if (!verb.startsWith(prefix)) return false;
|
|
2130
|
-
const next = verb.charAt(prefix.length);
|
|
2131
|
-
return next === "" || /[A-Z0-9_-]/u.test(next);
|
|
2132
|
-
});
|
|
2133
|
-
}
|
|
2134
|
-
async function pd071(input) {
|
|
2135
|
-
const rls = input.config.rls;
|
|
2136
|
-
if (rls === void 0 || input.config.policy === void 0) return [];
|
|
2137
|
-
const policy = await policyOf(input);
|
|
2138
|
-
if (policy === void 0) return [];
|
|
2139
|
-
const byVerb = /* @__PURE__ */ new Map();
|
|
2140
|
-
for (const leaf of listPermissions(policy.vocabulary.permissions)) {
|
|
2141
|
-
if (rls.actions !== void 0 && Object.hasOwn(rls.actions, leaf.action) || commandFor(leaf.action) !== void 0 || !suggestsWrite(leaf.action)) continue;
|
|
2142
|
-
byVerb.set(leaf.action, [...byVerb.get(leaf.action) ?? [], leaf.key]);
|
|
2143
|
-
}
|
|
2144
|
-
return [...byVerb.entries()].toSorted(byKey).map(([verb, keys]) => ({
|
|
2145
|
-
code: "PD071",
|
|
2146
|
-
severity: "warning",
|
|
2147
|
-
message: `action '${verb}' (${keys.toSorted().join(", ")}) reads as a write but has no rls.actions entry, so it compiles to 'none' and adds no SQL policy`,
|
|
2148
|
-
fix: `map it on purpose in rls.actions: ${verb}: "insert", "update", "delete" or "none"`
|
|
2149
|
-
}));
|
|
2150
|
-
}
|
|
2151
|
-
const NAME_GUARD_TRIGGER = new RegExp(String.raw`create\s+(?:or\s+replace\s+)?(?:constraint\s+)?trigger\s+"?${CUSTOM_ROLES.nameGuard}"?`, "iu");
|
|
2152
|
-
/**
|
|
2153
|
-
* Whether a declarative schema file, migration or generated SQL file creates
|
|
2154
|
-
* the `permdock_custom_role_name_guard` trigger.
|
|
2155
|
-
*/
|
|
2156
|
-
function hasNameGuard(input) {
|
|
2157
|
-
const files = filesOf(input);
|
|
2158
|
-
const out = input.config.rls?.out;
|
|
2159
|
-
const entries = [
|
|
2160
|
-
"supabase/schemas",
|
|
2161
|
-
...input.config.doctor?.migrations ?? MIGRATION_DIRS,
|
|
2162
|
-
...out === void 0 ? [] : [out]
|
|
2163
|
-
];
|
|
2164
|
-
return sqlFiles(input.cwd, entries).some((file) => NAME_GUARD_TRIGGER.test(files.read(file)));
|
|
2165
|
-
}
|
|
2166
|
-
/**
|
|
2167
|
-
* PD072: a membership source reads role keys through the table of custom roles
|
|
2168
|
-
* (`rls.customRoleWrites.roles`), which tenants write.
|
|
2169
|
-
*/
|
|
2170
|
-
function pd072(input) {
|
|
2171
|
-
const roles = input.config.rls?.customRoleWrites?.roles;
|
|
2172
|
-
if (roles?.tenant === void 0) return [];
|
|
2173
|
-
const target = qualifySqlTable(roles.table);
|
|
2174
|
-
const sources = membershipSourcesOf(input.config).filter((source) => source.sql.throughs.some((through) => through.table === target));
|
|
2175
|
-
if (sources.length === 0 || hasNameGuard(input)) return [];
|
|
2176
|
-
return sources.map((source) => ({
|
|
2177
|
-
code: "PD072",
|
|
2178
|
-
target: `${target}:${source.sql.table}`,
|
|
2179
|
-
severity: "warning",
|
|
2180
|
-
message: `the ${source.sql.table} membership source reads role keys through ${target}, whose tenant rows tenants write: a tenant row named like a declared role must not grant it`,
|
|
2181
|
-
fix: `keep the permdock_custom_role_name_guard trigger on ${target} (rls generate emits it with customRoleWrites.roles) and generate with this config, so helpers read a tenant row named like a declared role as no role; doctor reads supabase/schemas, the migrations and rls.out for it`
|
|
2182
|
-
}));
|
|
2183
|
-
}
|
|
2184
|
-
/** PD073: a role's `for` lists kinds no membership source of its scope can hold. */
|
|
2185
|
-
async function pd073(input) {
|
|
2186
|
-
const rls = input.config.rls;
|
|
2187
|
-
if (rls === void 0 || input.config.policy === void 0) return [];
|
|
2188
|
-
const policy = await policyOf(input);
|
|
2189
|
-
if (policy === void 0) return [];
|
|
2190
|
-
const scopes = scopeList(policy.scopes);
|
|
2191
|
-
const ownership = ownershipRules(policy, scopes);
|
|
2192
|
-
const sources = membershipSourcesOf(input.config);
|
|
2193
|
-
const ctx = {
|
|
2194
|
-
dialect: "supabase",
|
|
2195
|
-
scopes,
|
|
2196
|
-
tenantClaim: "tenant_id",
|
|
2197
|
-
gucPrefix: "app",
|
|
2198
|
-
...rls.memberships === void 0 ? {} : { memberships: rls.memberships },
|
|
2199
|
-
...sources === void 0 ? {} : { memberSources: sources },
|
|
2200
|
-
...ownership === void 0 ? {} : { ownership }
|
|
2201
|
-
};
|
|
2202
|
-
return unsatisfiedKinds(ctx, policy).map((item) => ({
|
|
2203
|
-
code: "PD073",
|
|
2204
|
-
severity: "error",
|
|
2205
|
-
message: `role ${item.role} is for ${item.for.join(", ")}, but its membership sources hold ${item.sources.join(", ")}: no membership can hold it`,
|
|
2206
|
-
fix: `set via on one of those sources to ${item.for.join(" or ")}, or change for on role ${item.role}`
|
|
2207
|
-
}));
|
|
2208
|
-
}
|
|
2209
|
-
/**
|
|
2210
|
-
* Every `sqlFunction` set variant in `condition`, through `and`, `or` and
|
|
2211
|
-
* `not`.
|
|
2212
|
-
*/
|
|
2213
|
-
function sqlFunctionSets(condition) {
|
|
2214
|
-
if (condition === void 0) return [];
|
|
2215
|
-
if (condition.op === "sqlFunction") return [...condition.set === void 0 ? [] : [condition], ...sqlFunctionSets(condition.twin)];
|
|
2216
|
-
if (condition.op === "and" || condition.op === "or") return condition.conditions.flatMap(sqlFunctionSets);
|
|
2217
|
-
if (condition.op === "not") return sqlFunctionSets(condition.condition);
|
|
2218
|
-
return [];
|
|
2219
|
-
}
|
|
2220
|
-
/**
|
|
2221
|
-
* PD086: a `sqlFunction` set variant names a column the resource does not
|
|
2222
|
-
* declare, or passes row-field args the set form drops because the function is
|
|
2223
|
-
* called once per statement.
|
|
2224
|
-
*/
|
|
2225
|
-
async function pd086(input) {
|
|
2226
|
-
if (input.config.rls === void 0 || input.config.policy === void 0) return [];
|
|
2227
|
-
const policy = await policyOf(input);
|
|
2228
|
-
if (policy === void 0) return [];
|
|
2229
|
-
const findings = [];
|
|
2230
|
-
for (const grant of policy.grants) {
|
|
2231
|
-
const node = policy.resources.get(grant.permission.resource);
|
|
2232
|
-
const schema = node === void 0 ? null : jsonSchemaOf(node);
|
|
2233
|
-
const properties = schema !== null && typeof schema === "object" ? schema.properties : void 0;
|
|
2234
|
-
const columns = properties !== null && typeof properties === "object" ? new Set(Object.keys(properties)) : void 0;
|
|
2235
|
-
for (const [kind, condition] of [["where", grant.where], ["check", grant.check]]) for (const fn of sqlFunctionSets(condition)) {
|
|
2236
|
-
const column = fn.set?.column;
|
|
2237
|
-
if (column !== void 0 && columns !== void 0 && !columns.has(column)) findings.push({
|
|
2238
|
-
code: "PD086",
|
|
2239
|
-
target: `${grant.permission.key}:${kind}`,
|
|
2240
|
-
severity: "error",
|
|
2241
|
-
message: `sqlFunction ${fn.name} set compares ${grant.permission.resource}.${column}, which the resource does not declare`,
|
|
2242
|
-
fix: `set column to one of ${[...columns].toSorted().join(", ")} or add ${column} to the resource schema`
|
|
2243
|
-
});
|
|
2244
|
-
const dropped = fn.args.filter(isSqlFunctionField);
|
|
2245
|
-
if (dropped.length > 0) findings.push({
|
|
2246
|
-
code: "PD086",
|
|
2247
|
-
target: `${grant.permission.key}:${kind}`,
|
|
2248
|
-
severity: "warning",
|
|
2249
|
-
message: `sqlFunction ${fn.name} set passes row fields (${dropped.map((arg) => arg.field).join(", ")}), which the set form drops: the function is called once per statement`,
|
|
2250
|
-
fix: "pass only the function's own arguments, or drop set to call it per row"
|
|
2251
|
-
});
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
return findings;
|
|
2255
|
-
}
|
|
2256
|
-
/**
|
|
2257
|
-
* PD075: two resources that `rls.tables` maps to one table, each with its own
|
|
2258
|
-
* keys and helpers for the same rows. A resource declared `{ tableOf }` is the
|
|
2259
|
-
* intended way to share a table and is not counted.
|
|
2260
|
-
*/
|
|
2261
|
-
async function pd075(input) {
|
|
2262
|
-
const rls = input.config.rls;
|
|
2263
|
-
if (rls === void 0 || input.config.policy === void 0) return [];
|
|
2264
|
-
const policy = await policyOf(input);
|
|
2265
|
-
if (policy === void 0) return [];
|
|
2266
|
-
const byTable = /* @__PURE__ */ new Map();
|
|
2267
|
-
for (const leaf of listPermissions(policy.vocabulary.permissions)) {
|
|
2268
|
-
const entry = rls.tables?.[leaf.resource];
|
|
2269
|
-
if (typeof entry === "object" && "tableOf" in entry) continue;
|
|
2270
|
-
const table = qualifySqlTable(tableNameOf(entry, leaf.resource));
|
|
2271
|
-
byTable.set(table, (byTable.get(table) ?? /* @__PURE__ */ new Set()).add(leaf.resource));
|
|
2272
|
-
}
|
|
2273
|
-
return [...byTable.entries()].filter(([, resources]) => resources.size > 1).toSorted(byKey).map(([table, resources]) => {
|
|
2274
|
-
return {
|
|
2275
|
-
code: "PD075",
|
|
2276
|
-
severity: "warning",
|
|
2277
|
-
message: `rls.tables maps ${[...resources].toSorted().join(" and ")} to ${table}, so the same rows carry two sets of keys and helpers`,
|
|
2278
|
-
fix: `merge them into one resource (https://permdock.com/docs/guides/merge-resources), or declare one with rls.tables.<resource>: { tableOf: '<owner>' } so only the owner writes ${table} policies`
|
|
2279
|
-
};
|
|
2280
|
-
});
|
|
2281
|
-
}
|
|
2282
|
-
//#endregion
|
|
2283
|
-
//#region src/cli/doctor/seeds.ts
|
|
2284
|
-
const SEED_INSERT = /^insert\s+into\s+((?:"[^"]+"|\w+)(?:\.(?:"[^"]+"|\w+))?)\s*\(\s*role\s*,\s*permission\s*,\s*grant_key\s*,\s*scope\s*,\s*effect\s*\)\s*values\s*([\s\S]*?)\s*on\s+conflict\b/iu;
|
|
2285
|
-
const SEED_CLEAR = /^delete\s+from\s+((?:"[^"]+"|\w+)(?:\.(?:"[^"]+"|\w+))?)\s*$/iu;
|
|
2286
|
-
const LITERAL = String.raw`'((?:[^']|'')*)'`;
|
|
2287
|
-
const SEED_ROW = new RegExp(String.raw`\(\s*${LITERAL}\s*,\s*${LITERAL}\s*,\s*${LITERAL}\s*,\s*${LITERAL}\s*,\s*${LITERAL}\s*\)`, "gu");
|
|
2288
|
-
const SEED_VIEW = /^create\s+(?:or\s+replace\s+)?view\s+((?:"[^"]+"|\w+)(?:\.(?:"[^"]+"|\w+))?)\s*\([^)]*\)\s*with\s*\([^)]*\)\s*as\s+([\s\S]*)$/iu;
|
|
2289
|
-
const SEED_FUNCTION = /^create\s+(?:or\s+replace\s+)?function\s+(?:"[^"]+"|\w+)\.(?:"seed"|seed)\s*\(\s*\)[\s\S]*?\$(\w*)\$([\s\S]*)\$\1\$/iu;
|
|
2290
|
-
function rowKey(values) {
|
|
2291
|
-
return values.join(" ");
|
|
2292
|
-
}
|
|
2293
|
-
/**
|
|
2294
|
-
* The statements of a file, with the body of `<schema>.seed()` (`rls.seeds:
|
|
2295
|
-
* 'function'`) in place of its `create function`.
|
|
2296
|
-
*/
|
|
2297
|
-
function seedStatements(sql) {
|
|
2298
|
-
return sqlStatements(sql).flatMap((statement) => {
|
|
2299
|
-
const fn = SEED_FUNCTION.exec(statement.text);
|
|
2300
|
-
return fn === null ? [statement] : sqlStatements(group(fn, 2));
|
|
2301
|
-
});
|
|
2302
|
-
}
|
|
2303
|
-
/**
|
|
2304
|
-
* The rows of the last statement that seeds or clears `table`, in migration
|
|
2305
|
-
* order.
|
|
2306
|
-
*/
|
|
2307
|
-
function lastSeed(files, cwd, config, table) {
|
|
2308
|
-
let seeded;
|
|
2309
|
-
for (const file of sqlFiles(cwd, config.doctor?.migrations ?? MIGRATION_DIRS)) for (const { text } of seedStatements(files.read(file))) {
|
|
2310
|
-
const insert = SEED_INSERT.exec(text) ?? SEED_VIEW.exec(text);
|
|
2311
|
-
if (insert !== null && tableKey(group(insert, 1)) === table) {
|
|
2312
|
-
const rows = /* @__PURE__ */ new Set();
|
|
2313
|
-
for (const row of group(insert, 2).matchAll(SEED_ROW)) rows.add(rowKey(row.slice(1, 6).map((value) => value.replaceAll("''", "'"))));
|
|
2314
|
-
seeded = {
|
|
2315
|
-
file: rel(cwd, file),
|
|
2316
|
-
rows
|
|
2317
|
-
};
|
|
2318
|
-
continue;
|
|
2319
|
-
}
|
|
2320
|
-
const clear = SEED_CLEAR.exec(text);
|
|
2321
|
-
if (clear !== null && tableKey(group(clear, 1)) === table) seeded = {
|
|
2322
|
-
file: rel(cwd, file),
|
|
2323
|
-
rows: /* @__PURE__ */ new Set()
|
|
2324
|
-
};
|
|
2325
|
-
}
|
|
2326
|
-
return seeded;
|
|
2327
|
-
}
|
|
2328
|
-
/** The first three rows, as `(role permission grant_key scope effect)`. */
|
|
2329
|
-
function sample(rows) {
|
|
2330
|
-
return rows.slice(0, 3).map((row) => `(${row})`).join(", ");
|
|
2331
|
-
}
|
|
2332
|
-
/**
|
|
2333
|
-
* PD054: the `role_permissions` rows the migrations seed last are not the rows
|
|
2334
|
-
* the policy compiles to, so the helpers answer from a stale policy.
|
|
2335
|
-
*/
|
|
2336
|
-
async function pd054(input) {
|
|
2337
|
-
const { cwd, config } = input;
|
|
2338
|
-
const rls = config.rls;
|
|
2339
|
-
if (config.policy === void 0 || rls === void 0 && config.supabase === void 0) return [];
|
|
2340
|
-
const schema = rls?.schema ?? rls?.rbac?.schema ?? "permdock";
|
|
2341
|
-
const seeded = lastSeed(filesOf(input), cwd, config, `${schema}.role_permissions`);
|
|
2342
|
-
if (seeded === void 0) return [];
|
|
2343
|
-
const policy = await policyOf(input);
|
|
2344
|
-
if (policy === void 0) return [];
|
|
2345
|
-
const generate = {
|
|
2346
|
-
cwd,
|
|
2347
|
-
config,
|
|
2348
|
-
target: "sql",
|
|
2349
|
-
dialect: rls?.dialect ?? "supabase",
|
|
2350
|
-
rbac: false,
|
|
2351
|
-
check: false,
|
|
2352
|
-
skipClosures: true,
|
|
2353
|
-
inlineFunctions: false,
|
|
2354
|
-
io: {
|
|
2355
|
-
stdout: () => void 0,
|
|
2356
|
-
stderr: () => void 0
|
|
2357
|
-
}
|
|
2358
|
-
};
|
|
2359
|
-
let expected;
|
|
2360
|
-
try {
|
|
2361
|
-
const options = generateOptions(generate);
|
|
2362
|
-
const built = isRefusal(options) ? options : buildContext(generate, policy, options);
|
|
2363
|
-
if (isRefusal(built)) return [];
|
|
2364
|
-
expected = new Set(compileGrants(policy, built.ctx, tableNames(rls?.tables), [], true, rls?.rowHelpers !== void 0 || inheritTargets(policy).length > 0).rolePermissions.map((row) => rowKey([
|
|
2365
|
-
row.role,
|
|
2366
|
-
row.permission,
|
|
2367
|
-
row.grantKey,
|
|
2368
|
-
row.scope,
|
|
2369
|
-
row.effect
|
|
2370
|
-
])));
|
|
2371
|
-
} catch {
|
|
2372
|
-
return [];
|
|
2373
|
-
}
|
|
2374
|
-
const missing = [...expected].filter((row) => !seeded.rows.has(row));
|
|
2375
|
-
const stale = [...seeded.rows].filter((row) => !expected.has(row));
|
|
2376
|
-
if (missing.length === 0 && stale.length === 0) return [];
|
|
2377
|
-
const parts = [...missing.length === 0 ? [] : [`${String(missing.length)} missing, such as ${sample(missing)}`], ...stale.length === 0 ? [] : [`${String(stale.length)} stale, such as ${sample(stale)}`]];
|
|
2378
|
-
return [{
|
|
2379
|
-
code: "PD054",
|
|
2380
|
-
severity: "warning",
|
|
2381
|
-
message: `${seeded.file} seeds ${schema}.role_permissions with rows the policy no longer compiles to: ${parts.join("; ")}`,
|
|
2382
|
-
fix: "run permdock rls generate (for declarative schemas, --split ...,seeds --seeds-out supabase/migrations/, which writes a new migration) and apply it"
|
|
2383
|
-
}];
|
|
2384
|
-
}
|
|
2385
|
-
//#endregion
|
|
2386
|
-
//#region src/cli/doctor/sql.ts
|
|
2387
|
-
/** Supabase's `[api] schemas` when `config.toml` sets none. */
|
|
2388
|
-
const API_SCHEMAS = ["public", "graphql_public"];
|
|
2389
|
-
const NAME = String.raw`((?:"[^"]+"|\w+)(?:\.(?:"[^"]+"|\w+))?)`;
|
|
2390
|
-
const IDENT = String.raw`("[^"]+"|\w+)`;
|
|
2391
|
-
/** A statement without its dollar-quoted bodies: what a function header says. */
|
|
2392
|
-
function header(text) {
|
|
2393
|
-
return text.replaceAll(/\$([A-Za-z_]*)\$[\s\S]*?\$\1\$/gu, "$$$$");
|
|
2394
|
-
}
|
|
2395
|
-
function isSupabase(files, cwd, config) {
|
|
2396
|
-
return files.exists(join(cwd, "supabase")) || config.rls?.dialect === "supabase" || config.supabase !== void 0;
|
|
2397
|
-
}
|
|
2398
|
-
function migrationStatements(files, cwd, config) {
|
|
2399
|
-
return sqlFiles(cwd, config.doctor?.migrations ?? MIGRATION_DIRS).flatMap((file) => sqlStatements(files.read(file)).map((statement) => Object.assign({ file: rel(cwd, file) }, statement)));
|
|
2400
|
-
}
|
|
2401
|
-
/** The schema of a `tableKey`, which always names one. */
|
|
2402
|
-
function schemaOf(key) {
|
|
2403
|
-
return key.slice(0, key.indexOf("."));
|
|
2404
|
-
}
|
|
2405
|
-
function unquote(name) {
|
|
2406
|
-
return name.replaceAll("\"", "").toLowerCase();
|
|
2407
|
-
}
|
|
2408
|
-
/**
|
|
2409
|
-
* PD046: the schema of PermDock's `security definer` helpers is one the Data
|
|
2410
|
-
* API exposes, so PostgREST serves them as RPCs.
|
|
2411
|
-
*/
|
|
2412
|
-
function pd046(cwd, config, files = nodeFiles) {
|
|
2413
|
-
if (!files.exists(join(cwd, "supabase/config.toml"))) return [];
|
|
2414
|
-
const schema = config.rls?.schema ?? config.rls?.rbac?.schema ?? "permdock";
|
|
2415
|
-
if (!(supabaseConfig(cwd).apiSchemas ?? API_SCHEMAS).includes(schema)) return [];
|
|
2416
|
-
return [{
|
|
2417
|
-
code: "PD046",
|
|
2418
|
-
severity: "warning",
|
|
2419
|
-
message: `the PermDock helper schema ${schema} is in [api] schemas in supabase/config.toml, so the Data API serves its security definer helpers as RPCs`,
|
|
2420
|
-
fix: schema === "public" ? `drop rls.schema: 'public' so the helpers move to the private ${PERMDOCK_SCHEMA} schema, regenerate with permdock rls generate, and keep ${PERMDOCK_SCHEMA} out of [api] schemas` : `remove ${schema} from [api] schemas; policies reach the helpers through grant usage, not the Data API`
|
|
2421
|
-
}];
|
|
2422
|
-
}
|
|
2423
|
-
const USER_METADATA = /\b(raw_user_meta_data|user_metadata)\b/giu;
|
|
2424
|
-
/**
|
|
2425
|
-
* PD047: SQL that reads `user_metadata`, which every user can edit for
|
|
2426
|
-
* themselves.
|
|
2427
|
-
*/
|
|
2428
|
-
function pd047(cwd, config, files = nodeFiles) {
|
|
2429
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2430
|
-
return migrationStatements(files, cwd, config).flatMap((statement) => [...statement.text.matchAll(USER_METADATA)].map((match) => ({
|
|
2431
|
-
code: "PD047",
|
|
2432
|
-
severity: "warning",
|
|
2433
|
-
message: `${statement.file}:${String(statement.line + statement.text.slice(0, match.index).split("\n").length - 1)} reads ${match[0]}, which a user can set for themselves`,
|
|
2434
|
-
fix: "decide access from app_metadata (raw_app_meta_data), a server-owned table or a hook claim; user_metadata is for display only"
|
|
2435
|
-
})));
|
|
2436
|
-
}
|
|
2437
|
-
const CREATE_FUNCTION = new RegExp(String.raw`^create\s+(?:or\s+replace\s+)?function\s+${NAME}\s*\(`, "iu");
|
|
2438
|
-
const ALTER_SEARCH_PATH = new RegExp(String.raw`^alter\s+function\s+${NAME}\s*(?:\([^)]*\))?\s+set\s+search_path\b`, "iu");
|
|
2439
|
-
const REVOKE_EXECUTE = new RegExp(String.raw`^revoke\s+(?:all(?:\s+privileges)?|execute)\s+on\s+(?:function|routine)\s+${NAME}\s*(?:\([^)]*\))?\s+from\s+([\s\S]+)$`, "iu");
|
|
2440
|
-
const REVOKE_ALL_FUNCTIONS = new RegExp(String.raw`^(?:alter\s+default\s+privileges\s+(?:for\s+role\s+\S+\s+)?in\s+schema\s+${IDENT}\s+)?revoke\s+(?:all(?:\s+privileges)?|execute)\s+on\s+(?:all\s+)?(?:functions|routines)(?:\s+in\s+schema\s+${IDENT})?\s+from\s+([\s\S]+)$`, "iu");
|
|
2441
|
-
function createdFunctions(statements) {
|
|
2442
|
-
return statements.flatMap((statement) => {
|
|
2443
|
-
const match = CREATE_FUNCTION.exec(statement.text);
|
|
2444
|
-
return match === null ? [] : [{
|
|
2445
|
-
...statement,
|
|
2446
|
-
key: tableKey(group(match, 1)),
|
|
2447
|
-
head: header(statement.text)
|
|
2448
|
-
}];
|
|
2449
|
-
});
|
|
2450
|
-
}
|
|
2451
|
-
/**
|
|
2452
|
-
* PD048: a function without `set search_path`, so a caller's objects can shadow
|
|
2453
|
-
* the ones it names.
|
|
2454
|
-
*/
|
|
2455
|
-
function pd048(cwd, config, files = nodeFiles) {
|
|
2456
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2457
|
-
const statements = migrationStatements(files, cwd, config);
|
|
2458
|
-
const altered = new Set(statements.flatMap((statement) => {
|
|
2459
|
-
const match = ALTER_SEARCH_PATH.exec(statement.text);
|
|
2460
|
-
return match === null ? [] : [tableKey(group(match, 1))];
|
|
2461
|
-
}));
|
|
2462
|
-
return createdFunctions(statements).filter((fn) => !/\bset\s+search_path\b/iu.test(fn.head) && !altered.has(fn.key) && !/\blanguage\s+(?:c|internal)\b/iu.test(fn.head)).map((fn) => {
|
|
2463
|
-
const definer = /\bsecurity\s+definer\b/iu.test(fn.head);
|
|
2464
|
-
return {
|
|
2465
|
-
code: "PD048",
|
|
2466
|
-
severity: "warning",
|
|
2467
|
-
message: `${fn.file}:${String(fn.line)} ${definer ? "security definer " : ""}function ${fn.key} sets no search_path${definer ? ", so a caller can shadow what it reads with their own objects" : ""}`,
|
|
2468
|
-
fix: `add set search_path = '' and qualify every name in the body (Supabase advisor function_search_path_mutable)`
|
|
2469
|
-
};
|
|
2470
|
-
});
|
|
2471
|
-
}
|
|
2472
|
-
/**
|
|
2473
|
-
* Roles each `revoke` statement takes `execute` from, per function key or
|
|
2474
|
-
* `schema.*`.
|
|
2475
|
-
*/
|
|
2476
|
-
function revokedExecute(statements) {
|
|
2477
|
-
const revoked = /* @__PURE__ */ new Map();
|
|
2478
|
-
const add = (key, roles) => {
|
|
2479
|
-
const set = revoked.get(key) ?? /* @__PURE__ */ new Set();
|
|
2480
|
-
for (const role of roles.split(",")) set.add(unquote(role.trim().replace(/\s+(?:cascade|restrict)$/iu, "")));
|
|
2481
|
-
revoked.set(key, set);
|
|
2482
|
-
};
|
|
2483
|
-
for (const statement of statements) {
|
|
2484
|
-
const one = REVOKE_EXECUTE.exec(statement.text);
|
|
2485
|
-
if (one !== null) {
|
|
2486
|
-
add(tableKey(group(one, 1)), group(one, 2));
|
|
2487
|
-
continue;
|
|
2488
|
-
}
|
|
2489
|
-
const all = REVOKE_ALL_FUNCTIONS.exec(statement.text);
|
|
2490
|
-
if (all !== null) {
|
|
2491
|
-
const schema = all[1] ?? all[2];
|
|
2492
|
-
add(`${schema === void 0 ? "*" : unquote(schema)}.*`, group(all, 3));
|
|
2493
|
-
}
|
|
2494
|
-
}
|
|
2495
|
-
return revoked;
|
|
2496
|
-
}
|
|
2497
|
-
/**
|
|
2498
|
-
* `supabase.hook.claims` and `hook.before` functions, by key, with the argument
|
|
2499
|
-
* type the hook calls them with.
|
|
2500
|
-
*/
|
|
2501
|
-
function hookClaimFunctions(config) {
|
|
2502
|
-
const hook = config.supabase?.hook;
|
|
2503
|
-
const before = hook?.before;
|
|
2504
|
-
const functions = /* @__PURE__ */ new Map();
|
|
2505
|
-
for (const fn of Object.values(hook?.claims ?? {})) if (typeof fn === "string") functions.set(tableKey(fn), "uuid");
|
|
2506
|
-
for (const fn of typeof before === "string" ? [before] : before ?? []) if (typeof fn === "string") functions.set(tableKey(fn), "jsonb");
|
|
2507
|
-
return functions;
|
|
2508
|
-
}
|
|
2509
|
-
/**
|
|
2510
|
-
* PD049: a `security definer` function `public` (every role) or, in Supabase's
|
|
2511
|
-
* `public` schema, `anon` may still execute: Postgres grants `execute` to
|
|
2512
|
-
* `public` on create, and Supabase's default privileges grant it to `anon`. A
|
|
2513
|
-
* hook claim function returns any user's claims, so `authenticated` must not
|
|
2514
|
-
* execute it either, definer or not.
|
|
2515
|
-
*/
|
|
2516
|
-
function pd049(cwd, config, files = nodeFiles) {
|
|
2517
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2518
|
-
const statements = migrationStatements(files, cwd, config);
|
|
2519
|
-
const revoked = revokedExecute(statements);
|
|
2520
|
-
const hookFunctions = hookClaimFunctions(config);
|
|
2521
|
-
const findings = [];
|
|
2522
|
-
for (const fn of createdFunctions(statements)) {
|
|
2523
|
-
const hookArgument = hookFunctions.get(fn.key);
|
|
2524
|
-
if (hookArgument === void 0 && (!/\bsecurity\s+definer\b/iu.test(fn.head) || /\breturns\s+(?:event_)?trigger\b/iu.test(fn.head))) continue;
|
|
2525
|
-
const schema = schemaOf(fn.key);
|
|
2526
|
-
const from = /* @__PURE__ */ new Set([
|
|
2527
|
-
...revoked.get(fn.key) ?? [],
|
|
2528
|
-
...revoked.get(`${schema}.*`) ?? [],
|
|
2529
|
-
...revoked.get("*.*") ?? []
|
|
2530
|
-
]);
|
|
2531
|
-
const missing = (hookArgument === void 0 ? ["public", ...schema === "public" ? ["anon"] : []] : [
|
|
2532
|
-
"public",
|
|
2533
|
-
"anon",
|
|
2534
|
-
"authenticated"
|
|
2535
|
-
]).filter((role) => !from.has(role));
|
|
2536
|
-
if (missing.length > 0 && hookArgument !== void 0) {
|
|
2537
|
-
findings.push({
|
|
2538
|
-
code: "PD049",
|
|
2539
|
-
severity: "warning",
|
|
2540
|
-
message: `${fn.file}:${String(fn.line)} hook claim function ${fn.key} returns any user's claims and can be executed by ${missing.join(" and ")}`,
|
|
2541
|
-
fix: `regenerate the hook (permdock rls generate), which revokes it, or add revoke all on function ${fn.key}(${hookArgument}) from public, anon, authenticated;`
|
|
2542
|
-
});
|
|
2543
|
-
continue;
|
|
2544
|
-
}
|
|
2545
|
-
if (missing.length > 0) findings.push({
|
|
2546
|
-
code: "PD049",
|
|
2547
|
-
severity: "warning",
|
|
2548
|
-
message: `${fn.file}:${String(fn.line)} security definer function ${fn.key} can be executed by ${missing.join(" and ")}`,
|
|
2549
|
-
fix: `revoke execute on function ${fn.key}(…) from public, anon; then grant execute to the roles that call it`
|
|
2550
|
-
});
|
|
2551
|
-
}
|
|
2552
|
-
return findings;
|
|
2553
|
-
}
|
|
2554
|
-
const CREATE_TABLE = new RegExp(String.raw`^create\s+(?:(?:global|local)\s+)?(?:(?:temp|temporary|unlogged)\s+)?table\s+(?:if\s+not\s+exists\s+)?${NAME}\s*\(`, "iu");
|
|
2555
|
-
const ENABLE_RLS = new RegExp(String.raw`^alter\s+table\s+(?:if\s+exists\s+)?(?:only\s+)?${NAME}[\s\S]*\benable\s+row\s+level\s+security\b`, "iu");
|
|
2556
|
-
const DROP_TABLE = /^drop\s+table\s+(?:if\s+exists\s+)?([\s\S]+?)(?:\s+(?:cascade|restrict))?$/iu;
|
|
2557
|
-
/**
|
|
2558
|
-
* PD050: a `public` table without row level security, which the Data API serves
|
|
2559
|
-
* whole.
|
|
2560
|
-
*/
|
|
2561
|
-
function pd050(cwd, config, files = nodeFiles) {
|
|
2562
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2563
|
-
const created = /* @__PURE__ */ new Map();
|
|
2564
|
-
const enabled = /* @__PURE__ */ new Set();
|
|
2565
|
-
for (const statement of migrationStatements(files, cwd, config)) {
|
|
2566
|
-
const table = CREATE_TABLE.exec(statement.text);
|
|
2567
|
-
if (table !== null) {
|
|
2568
|
-
created.set(tableKey(group(table, 1)), statement);
|
|
2569
|
-
continue;
|
|
2570
|
-
}
|
|
2571
|
-
const rls = ENABLE_RLS.exec(statement.text);
|
|
2572
|
-
if (rls !== null) {
|
|
2573
|
-
enabled.add(tableKey(group(rls, 1)));
|
|
2574
|
-
continue;
|
|
2575
|
-
}
|
|
2576
|
-
const dropped = DROP_TABLE.exec(statement.text);
|
|
2577
|
-
if (dropped !== null) for (const name of group(dropped, 1).split(",")) created.delete(tableKey(name.trim()));
|
|
2578
|
-
}
|
|
2579
|
-
return [...created].filter(([key]) => schemaOf(key) === "public" && !enabled.has(key)).map(([key, statement]) => ({
|
|
2580
|
-
code: "PD050",
|
|
2581
|
-
severity: "error",
|
|
2582
|
-
message: `${statement.file}:${String(statement.line)} creates ${key} without row level security, so the Data API serves every row to anon and authenticated`,
|
|
2583
|
-
fix: `alter table ${key} enable row level security; permdock rls generate writes its policies`
|
|
2584
|
-
}));
|
|
2585
|
-
}
|
|
2586
|
-
const CREATE_POLICY = new RegExp(String.raw`^create\s+policy\s+${IDENT}\s+on\s+${NAME}([\s\S]*)$`, "iu");
|
|
2587
|
-
const UNWRAPPED_AUTH = /(?<!\bselect\s{1,20})\bauth\.(uid|jwt)\s*\(\s*\)/giu;
|
|
2588
|
-
/**
|
|
2589
|
-
* PD051: a policy that calls `auth.uid()` or `auth.jwt()` bare, so Postgres
|
|
2590
|
-
* runs it once per row.
|
|
2591
|
-
*/
|
|
2592
|
-
function pd051(cwd, config, files = nodeFiles) {
|
|
2593
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2594
|
-
return migrationStatements(files, cwd, config).flatMap((statement) => {
|
|
2595
|
-
const policy = CREATE_POLICY.exec(statement.text);
|
|
2596
|
-
if (policy === null) return [];
|
|
2597
|
-
const calls = [...new Set([...group(policy, 3).matchAll(UNWRAPPED_AUTH)].map((match) => `auth.${group(match, 1).toLowerCase()}()`))];
|
|
2598
|
-
const [first] = calls;
|
|
2599
|
-
return first === void 0 ? [] : [{
|
|
2600
|
-
code: "PD051",
|
|
2601
|
-
severity: "warning",
|
|
2602
|
-
message: `${statement.file}:${String(statement.line)} policy ${unquote(group(policy, 1))} on ${tableKey(group(policy, 2))} calls ${calls.join(" and ")} once per row`,
|
|
2603
|
-
fix: `wrap each call as (select ${first}) so Postgres evaluates it once per statement (Supabase advisor auth_rls_initplan)`
|
|
2604
|
-
}];
|
|
2605
|
-
});
|
|
2606
|
-
}
|
|
2607
|
-
/**
|
|
2608
|
-
* PD052: an update policy without `with check`, so nothing states what a row
|
|
2609
|
-
* may become.
|
|
2610
|
-
*/
|
|
2611
|
-
function pd052(cwd, config, files = nodeFiles) {
|
|
2612
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2613
|
-
return migrationStatements(files, cwd, config).flatMap((statement) => {
|
|
2614
|
-
const policy = CREATE_POLICY.exec(statement.text);
|
|
2615
|
-
const rest = policy?.[3] ?? "";
|
|
2616
|
-
if (policy === null || !/\bfor\s+update\b/iu.test(rest) || /\bwith\s+check\b/iu.test(rest)) return [];
|
|
2617
|
-
return [{
|
|
2618
|
-
code: "PD052",
|
|
2619
|
-
severity: "warning",
|
|
2620
|
-
message: `${statement.file}:${String(statement.line)} update policy ${unquote(group(policy, 1))} on ${tableKey(group(policy, 2))} has no with check, so Postgres checks the new row against using alone`,
|
|
2621
|
-
fix: "add with check (...) stating what the updated row must satisfy, such as the same tenant and owner test, so an update cannot move a row out of what the user may write"
|
|
2622
|
-
}];
|
|
2623
|
-
});
|
|
2624
|
-
}
|
|
2625
|
-
/** Top-level comma-separated parts of a parenthesised list. */
|
|
2626
|
-
function topLevelParts(body) {
|
|
2627
|
-
const parts = [];
|
|
2628
|
-
let depth = 0;
|
|
2629
|
-
let start = 0;
|
|
2630
|
-
for (let index = 0; index < body.length; index += 1) {
|
|
2631
|
-
const char = body[index];
|
|
2632
|
-
if (char === "(") depth += 1;
|
|
2633
|
-
else if (char === ")") depth -= 1;
|
|
2634
|
-
else if (char === "," && depth === 0) {
|
|
2635
|
-
parts.push(body.slice(start, index).trim());
|
|
2636
|
-
start = index + 1;
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
parts.push(body.slice(start).trim());
|
|
2640
|
-
return parts.filter((part) => part !== "");
|
|
2641
|
-
}
|
|
2642
|
-
/**
|
|
2643
|
-
* One column definition or table constraint of a `create table` body: its first
|
|
2644
|
-
* column, whether it is a foreign key, and whether a primary key or unique
|
|
2645
|
-
* constraint indexes that column.
|
|
2646
|
-
*/
|
|
2647
|
-
function tablePart(raw) {
|
|
2648
|
-
const part = raw.replace(/^constraint\s+(?:"[^"]+"|\w+)\s+/iu, "");
|
|
2649
|
-
const listed = /^(foreign\s+key|primary\s+key|unique)\s*\(([^)]*)\)/iu.exec(part);
|
|
2650
|
-
if (listed !== null) {
|
|
2651
|
-
const foreign = /^foreign/iu.test(group(listed, 1));
|
|
2652
|
-
return {
|
|
2653
|
-
column: firstColumn(group(listed, 2)),
|
|
2654
|
-
foreign,
|
|
2655
|
-
indexed: !foreign
|
|
2656
|
-
};
|
|
2657
|
-
}
|
|
2658
|
-
return {
|
|
2659
|
-
column: unquote(/^("[^"]+"|\w+)/u.exec(part)?.[1] ?? ""),
|
|
2660
|
-
foreign: /\breferences\b/iu.test(part),
|
|
2661
|
-
indexed: /\b(?:primary\s+key|unique)\b/iu.test(part)
|
|
2662
|
-
};
|
|
2663
|
-
}
|
|
2664
|
-
function firstColumn(list) {
|
|
2665
|
-
return unquote(list.replace(/,[\s\S]*$/u, "").trim());
|
|
2666
|
-
}
|
|
2667
|
-
const ADD_CONSTRAINT = new RegExp(String.raw`^alter\s+table\s+(?:if\s+exists\s+)?(?:only\s+)?${NAME}\s+add\s+(?:constraint\s+${IDENT}\s+)?(foreign\s+key|primary\s+key|unique)\s*\(([^)]*)\)`, "iu");
|
|
2668
|
-
const CREATE_INDEX = new RegExp(String.raw`^create\s+(?:unique\s+)?index\s+(?:concurrently\s+)?(?:if\s+not\s+exists\s+)?(?:${IDENT}\s+)?on\s+(?:only\s+)?${NAME}\s*(?:using\s+\w+\s*)?\(\s*${IDENT}`, "iu");
|
|
2669
|
-
/**
|
|
2670
|
-
* PD053: a foreign key no index starts with, so joins and deletes on the
|
|
2671
|
-
* referenced row scan the table.
|
|
2672
|
-
*/
|
|
2673
|
-
function pd053(cwd, config, files = nodeFiles) {
|
|
2674
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2675
|
-
const keys = [];
|
|
2676
|
-
const indexed = /* @__PURE__ */ new Set();
|
|
2677
|
-
for (const statement of migrationStatements(files, cwd, config)) {
|
|
2678
|
-
const table = CREATE_TABLE.exec(statement.text);
|
|
2679
|
-
if (table !== null) {
|
|
2680
|
-
const key = tableKey(group(table, 1));
|
|
2681
|
-
const open = statement.text.indexOf("(", table[0].length - 1);
|
|
2682
|
-
const body = statement.text.slice(open + 1, statement.text.lastIndexOf(")"));
|
|
2683
|
-
for (const raw of topLevelParts(body)) {
|
|
2684
|
-
const found = tablePart(raw);
|
|
2685
|
-
if (found.foreign) keys.push({
|
|
2686
|
-
...statement,
|
|
2687
|
-
table: key,
|
|
2688
|
-
column: found.column
|
|
2689
|
-
});
|
|
2690
|
-
if (found.indexed) indexed.add(`${key}.${found.column}`);
|
|
2691
|
-
}
|
|
2692
|
-
continue;
|
|
2693
|
-
}
|
|
2694
|
-
const added = ADD_CONSTRAINT.exec(statement.text);
|
|
2695
|
-
if (added !== null) {
|
|
2696
|
-
const key = tableKey(group(added, 1));
|
|
2697
|
-
const column = firstColumn(group(added, 4));
|
|
2698
|
-
if (/^foreign/iu.test(group(added, 3))) keys.push({
|
|
2699
|
-
...statement,
|
|
2700
|
-
table: key,
|
|
2701
|
-
column
|
|
2702
|
-
});
|
|
2703
|
-
else indexed.add(`${key}.${column}`);
|
|
2704
|
-
continue;
|
|
2705
|
-
}
|
|
2706
|
-
const index = CREATE_INDEX.exec(statement.text);
|
|
2707
|
-
if (index !== null) indexed.add(`${tableKey(group(index, 2))}.${unquote(group(index, 3))}`);
|
|
2708
|
-
}
|
|
2709
|
-
return keys.filter((fk) => !indexed.has(`${fk.table}.${fk.column}`)).map((fk) => ({
|
|
2710
|
-
code: "PD053",
|
|
2711
|
-
severity: "warning",
|
|
2712
|
-
message: `${fk.file}:${String(fk.line)} ${fk.table}.${fk.column} is a foreign key no index starts with, so policies that join on it and deletes of the referenced row scan ${fk.table}`,
|
|
2713
|
-
fix: `create index on ${fk.table} (${fk.column}); (Supabase advisor unindexed_foreign_keys)`
|
|
2714
|
-
}));
|
|
2715
|
-
}
|
|
2716
|
-
const LEGACY_CLAIM = /\brequest\.jwt\.claim\.(\w+)/giu;
|
|
2717
|
-
function at(statement) {
|
|
2718
|
-
return `${statement.file}:${String(statement.line)}`;
|
|
2719
|
-
}
|
|
2720
|
-
/**
|
|
2721
|
-
* PD062: SQL that reads or sets a per-claim `request.jwt.claim.<name>` setting.
|
|
2722
|
-
* Current PostgREST, `withPostgresClient`, PermDock's `withSubject` and `rls
|
|
2723
|
-
* verify` set only `request.jwt.claims`. A function replaced by a later
|
|
2724
|
-
* migration is judged by its last definition.
|
|
2725
|
-
*/
|
|
2726
|
-
function pd062(cwd, config, files = nodeFiles) {
|
|
2727
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2728
|
-
const statements = migrationStatements(files, cwd, config);
|
|
2729
|
-
const latest = /* @__PURE__ */ new Map();
|
|
2730
|
-
for (const fn of createdFunctions(statements)) latest.set(fn.key, at(fn));
|
|
2731
|
-
return statements.flatMap((statement) => {
|
|
2732
|
-
const fn = CREATE_FUNCTION.exec(statement.text);
|
|
2733
|
-
if (fn !== null && latest.get(tableKey(group(fn, 1))) !== at(statement)) return [];
|
|
2734
|
-
return [...new Set([...statement.text.matchAll(LEGACY_CLAIM)].map((match) => group(match, 1).toLowerCase()))].map((name) => ({
|
|
2735
|
-
code: "PD062",
|
|
2736
|
-
severity: "warning",
|
|
2737
|
-
message: `${statement.file}:${String(statement.line)} uses the legacy request.jwt.claim.${name} setting, which PostgREST 12 and PermDock's withSubject no longer set, so it reads null`,
|
|
2738
|
-
fix: name === "sub" ? "read the subject with (select permdock.permdock_user_id()) or (select auth.uid()), and set request.jwt.claims in tests and jobs" : `read (select auth.jwt()) ->> '${name}', and set request.jwt.claims in tests and jobs`
|
|
2739
|
-
}));
|
|
2740
|
-
});
|
|
2741
|
-
}
|
|
2742
|
-
/**
|
|
2743
|
-
* PD063: a migration statement supautils rejects for `postgres`, so `supabase
|
|
2744
|
-
* db push` fails on it.
|
|
2745
|
-
*/
|
|
2746
|
-
function pd063(cwd, config, files = nodeFiles) {
|
|
2747
|
-
if (!isSupabase(files, cwd, config)) return [];
|
|
2748
|
-
return sqlFiles(cwd, config.doctor?.migrations ?? MIGRATION_DIRS).flatMap((file) => supautilsRejections(files.read(file)).map((found) => ({
|
|
2749
|
-
code: "PD063",
|
|
2750
|
-
severity: "error",
|
|
2751
|
-
message: `${rel(cwd, file)}:${String(found.line)} ${found.reason}, which supautils rejects for the postgres role on Supabase`,
|
|
2752
|
-
fix: "remove the statement: reserved roles belong to Supabase. Grant your own role to authenticator instead, and change anon, authenticated, authenticator or service_role only with alter role … set"
|
|
2753
|
-
})));
|
|
2754
|
-
}
|
|
2755
|
-
/**
|
|
2756
|
-
* PD056: SQL still calls an `rls.migrate` helper by its legacy name, so the
|
|
2757
|
-
* shim (or the legacy function) cannot be dropped yet.
|
|
2758
|
-
*/
|
|
2759
|
-
function pd056(cwd, config, files = nodeFiles) {
|
|
2760
|
-
const migrate = config.rls?.migrate;
|
|
2761
|
-
const helpers = migrate === void 0 ? [] : legacyHelperNames(migrate);
|
|
2762
|
-
if (helpers.length === 0) return [];
|
|
2763
|
-
const statements = migrationStatements(files, cwd, config);
|
|
2764
|
-
const findings = [];
|
|
2765
|
-
for (const name of helpers) {
|
|
2766
|
-
const { count, files: callers } = legacyHelperCalls(statements, name);
|
|
2767
|
-
if (count === 0) continue;
|
|
2768
|
-
findings.push({
|
|
2769
|
-
code: "PD056",
|
|
2770
|
-
severity: "warning",
|
|
2771
|
-
message: `legacy helper ${name} is still called ${String(count)} time(s), in ${callers.join(", ")}`,
|
|
2772
|
-
fix: `run permdock rls migrate for policies, rewrite function bodies, views and triggers onto the permdock helpers by hand, then drop function ${name}`
|
|
2773
|
-
});
|
|
2774
|
-
}
|
|
2775
|
-
return findings;
|
|
2776
|
-
}
|
|
2777
|
-
/**
|
|
2778
|
-
* PD066: the migrations still create an `rls.migrate.tables` table: something
|
|
2779
|
-
* still reads it, or `rls migrate --retire-out` can drop it now.
|
|
2780
|
-
*/
|
|
2781
|
-
function pd066(cwd, config, files = nodeFiles) {
|
|
2782
|
-
const migrate = config.rls?.migrate;
|
|
2783
|
-
if (migrate?.tables === void 0) return [];
|
|
2784
|
-
return retirePlan(migrationStatements(files, cwd, config), migrate).tables.filter((table) => table.present).map((table) => {
|
|
2785
|
-
const [first] = table.readers;
|
|
2786
|
-
return first === void 0 ? {
|
|
2787
|
-
code: "PD066",
|
|
2788
|
-
severity: "warning",
|
|
2789
|
-
message: `${table.table} has no reader left, but the migrations still create it and its ${String(table.refreshTriggers.length)} refresh trigger(s)`,
|
|
2790
|
-
fix: "run permdock rls migrate --sql <dir> --retire-out supabase/migrations/ and apply the migration it writes"
|
|
2791
|
-
} : {
|
|
2792
|
-
code: "PD066",
|
|
2793
|
-
severity: "warning",
|
|
2794
|
-
message: `${table.table} is still read by ${String(table.readers.length)} object(s), first ${first.kind} ${first.name} at ${first.file}:${String(first.line)}`,
|
|
2795
|
-
fix: "rewrite each reader onto the permdock helpers, then run permdock rls migrate --retire-out"
|
|
2796
|
-
};
|
|
2797
|
-
});
|
|
2798
|
-
}
|
|
2799
|
-
const ROWS_HELPER = String.raw`(?:"[^"]+"\.|\w+\.)?"?permitted_\w+_rows"?`;
|
|
2800
|
-
const TEXT_CAST_ON_ROWS = new RegExp(String.raw`::\s*text\s+in\s*\(\s*select\s+${ROWS_HELPER}\s*\(|${ROWS_HELPER}\s*\([^()]*(?:\([^()]*\)[^()]*)*\)\s*::\s*text\b|(?:"[^"]+"\.|\w+\.)?"?permitted_\w+_row"?\s*\(\s*[^,()]+::\s*text\s*,`, "iu");
|
|
2801
|
-
const KNOWN_ID = String.raw`(?:\$\d+|\bp_\w+|\b(?:new|old)\.\w+)(?:\s*::\s*\w+)?`;
|
|
2802
|
-
const KNOWN_ID_IN_ROWS = new RegExp(String.raw`${KNOWN_ID}\s+in\s*\(\s*select\s+${ROWS_HELPER}\s*\(|${KNOWN_ID}\s*=\s*any\s*\(\s*array\s*\(\s*select\s+${ROWS_HELPER}\s*\(`, "iu");
|
|
2803
|
-
const GENERATED_ROW_HELPER = /^create\s+(?:or\s+replace\s+)?function\s+(?:"?\w+"?\.)?"?permitted_\w+/iu;
|
|
2804
|
-
function firstLine(statement, index) {
|
|
2805
|
-
return statement.line + statement.text.slice(0, index).split("\n").length - 1;
|
|
2806
|
-
}
|
|
2807
|
-
function rowHelperStatements(cwd, config, files) {
|
|
2808
|
-
return migrationStatements(files, cwd, config).filter((statement) => !CREATE_FUNCTION.test(statement.text));
|
|
2809
|
-
}
|
|
2810
|
-
/**
|
|
2811
|
-
* PD088: a `::text` cast on a row-helper call. The helpers return the
|
|
2812
|
-
* resource's id type, so the cast defeats the index on the id column and fails
|
|
2813
|
-
* against a `uuid` helper.
|
|
2814
|
-
*/
|
|
2815
|
-
function pd088(cwd, config, files = nodeFiles) {
|
|
2816
|
-
if (config.rls?.dialect === "neon" || config.rls?.idTypes?.["*"] === "text") return [];
|
|
2817
|
-
return rowHelperStatements(cwd, config, files).flatMap((statement) => {
|
|
2818
|
-
const match = TEXT_CAST_ON_ROWS.exec(statement.text);
|
|
2819
|
-
return match === null ? [] : [{
|
|
2820
|
-
code: "PD088",
|
|
2821
|
-
severity: "warning",
|
|
2822
|
-
message: `${statement.file}:${String(firstLine(statement, match.index))} casts to text around a permitted_*_rows or permitted_*_row call`,
|
|
2823
|
-
fix: "compare the id column to the helper's own type (uuid by default) and set rls.idTypes when the column is not uuid, then run permdock rls generate"
|
|
2824
|
-
}];
|
|
2825
|
-
});
|
|
2826
|
-
}
|
|
2827
|
-
/**
|
|
2828
|
-
* PD089: `<known id> in (select permitted_*_rows(...))` or `<known id> =
|
|
2829
|
-
* any(array(select permitted_*_rows(...)))`, in a policy or a function body.
|
|
2830
|
-
* The `_rows` helper lists every permitted row; for one id the
|
|
2831
|
-
* `permitted_*_row(id, permission)` overload checks that row alone.
|
|
2832
|
-
*/
|
|
2833
|
-
function pd089(cwd, config, files = nodeFiles) {
|
|
2834
|
-
return migrationStatements(files, cwd, config).filter((statement) => !GENERATED_ROW_HELPER.test(statement.text)).flatMap((statement) => {
|
|
2835
|
-
const match = KNOWN_ID_IN_ROWS.exec(statement.text);
|
|
2836
|
-
return match === null ? [] : [{
|
|
2837
|
-
code: "PD089",
|
|
2838
|
-
severity: "warning",
|
|
2839
|
-
message: `${statement.file}:${String(firstLine(statement, match.index))} tests one id against the whole permitted_*_rows set`,
|
|
2840
|
-
fix: "call permitted_<resource>_row(id, permission), which evaluates that row only"
|
|
2841
|
-
}];
|
|
2842
|
-
});
|
|
2843
|
-
}
|
|
2844
|
-
const POLICY_COMMAND = /\bfor\s+(all|select|insert|update|delete)\b/iu;
|
|
2845
|
-
const ACTOR_GUARD_CALL = /\bpermdock_actor_may_write\s*\(/iu;
|
|
2846
|
-
/** The expression `rls generate` inlined into the policies of 0.24 and earlier. */
|
|
2847
|
-
const INLINED_ACTOR_GUARD = /'act'[\s\S]*'read_only'/iu;
|
|
2848
|
-
function inlinesActorGuard(text) {
|
|
2849
|
-
return INLINED_ACTOR_GUARD.test(text.replaceAll("\"", ""));
|
|
2850
|
-
}
|
|
2851
|
-
const WRITE_COMMANDS = [
|
|
2852
|
-
"insert",
|
|
2853
|
-
"update",
|
|
2854
|
-
"delete"
|
|
2855
|
-
];
|
|
2856
|
-
function policyStatements(statements) {
|
|
2857
|
-
return statements.flatMap((statement) => {
|
|
2858
|
-
const match = CREATE_POLICY.exec(header(statement.text));
|
|
2859
|
-
if (match === null) return [];
|
|
2860
|
-
const command = POLICY_COMMAND.exec(group(match, 3))?.[1]?.toLowerCase();
|
|
2861
|
-
return [{
|
|
2862
|
-
...statement,
|
|
2863
|
-
name: unquote(group(match, 1)),
|
|
2864
|
-
table: tableKey(group(match, 2)),
|
|
2865
|
-
commands: command === void 0 || command === "all" ? WRITE_COMMANDS : [command],
|
|
2866
|
-
guarded: ACTOR_GUARD_CALL.test(statement.text) || inlinesActorGuard(statement.text)
|
|
2867
|
-
}];
|
|
2868
|
-
});
|
|
2869
|
-
}
|
|
2870
|
-
/**
|
|
2871
|
-
* The statements PD090 reads: the migration folders, plus the declarative
|
|
2872
|
-
* schemas and `rls.out`, which `doctor.migrations` does not drop.
|
|
2873
|
-
*/
|
|
2874
|
-
function guardStatements(files, cwd, config) {
|
|
2875
|
-
const out = config.rls?.out;
|
|
2876
|
-
const entries = [
|
|
2877
|
-
...config.doctor?.migrations ?? MIGRATION_DIRS,
|
|
2878
|
-
"supabase/schemas",
|
|
2879
|
-
...out === void 0 ? [] : [out]
|
|
2880
|
-
];
|
|
2881
|
-
return [...new Set(sqlFiles(cwd, entries))].flatMap((file) => sqlStatements(files.read(file)).map((statement) => Object.assign({ file: rel(cwd, file) }, statement)));
|
|
2882
|
-
}
|
|
2883
|
-
/**
|
|
2884
|
-
* PD090: a hand-written policy calls `permdock_actor_may_write()`, or inlines
|
|
2885
|
-
* the guard expression of 0.24 and earlier, on a table and command where
|
|
2886
|
-
* `permdock rls generate` already writes a restrictive `*_read_only_actors`
|
|
2887
|
-
* policy, so the guard runs twice.
|
|
2888
|
-
*/
|
|
2889
|
-
function pd090(cwd, config, files = nodeFiles) {
|
|
2890
|
-
const policies = policyStatements(guardStatements(files, cwd, config));
|
|
2891
|
-
const generated = new Set(policies.filter((policy) => policy.name.endsWith("_read_only_actors")).flatMap((policy) => policy.commands.map((command) => `${policy.table}:${command}`)));
|
|
2892
|
-
return policies.filter((policy) => !policy.name.endsWith("_read_only_actors")).filter((policy) => policy.guarded && policy.commands.some((command) => generated.has(`${policy.table}:${command}`))).map((policy) => ({
|
|
2893
|
-
code: "PD090",
|
|
2894
|
-
severity: "warning",
|
|
2895
|
-
message: `${policy.file}:${String(policy.line)} policy ${policy.name} on ${policy.table} repeats the permdock_actor_may_write() guard of the generated read-only actor policy`,
|
|
2896
|
-
fix: "remove the permdock_actor_may_write() call from the hand-written policy; the restrictive policy applies to it already"
|
|
2897
|
-
}));
|
|
2898
|
-
}
|
|
2899
|
-
const OWN_SUBJECT_FUNCTION = /\bcreate\s+(?:or\s+replace\s+)?function\s+(?:"?\w+"?\.)?"?own_subject"?\s*\(/iu;
|
|
2900
|
-
/**
|
|
2901
|
-
* PD093: a migration defines an `own_subject()` function. The hook migration
|
|
2902
|
-
* writes `permdock_subject()`, which better-supabase's `functions.subject`
|
|
2903
|
-
* names, so a bootstrap seeds the same subject without a second copy.
|
|
2904
|
-
*/
|
|
2905
|
-
function pd093(cwd, config, files = nodeFiles) {
|
|
2906
|
-
return migrationStatements(files, cwd, config).flatMap((statement) => {
|
|
2907
|
-
const match = OWN_SUBJECT_FUNCTION.exec(statement.text);
|
|
2908
|
-
return match === null ? [] : [{
|
|
2909
|
-
code: "PD093",
|
|
2910
|
-
severity: "warning",
|
|
2911
|
-
message: `${statement.file}:${String(firstLine(statement, match.index))} defines own_subject(), which permdock_subject() from the hook migration already is`,
|
|
2912
|
-
fix: "set subject: true on authorizationProvider and drop the function; better-supabase's bootstrap calls permdock_subject()"
|
|
2913
|
-
}];
|
|
2914
|
-
});
|
|
2915
|
-
}
|
|
2916
|
-
//#endregion
|
|
2917
|
-
//#region src/cli/doctor/suspension.ts
|
|
2918
|
-
/**
|
|
2919
|
-
* PD061: a suspended scope keeps permissions. Each scope's kept keys are listed
|
|
2920
|
-
* for review, since its members hold them while the instance is suspended, and
|
|
2921
|
-
* a key the definitions do not declare is named apart.
|
|
2922
|
-
*/
|
|
2923
|
-
async function pd061(input) {
|
|
2924
|
-
const suspension = input.config.rls?.suspension;
|
|
2925
|
-
const kept = [...Object.entries(suspension?.scopes ?? {}).map(([scope, row]) => ({
|
|
2926
|
-
path: `scopes.${scope}`,
|
|
2927
|
-
who: `members of a suspended ${scope}`,
|
|
2928
|
-
row
|
|
2929
|
-
})), ...suspension?.memberships === void 0 ? [] : [{
|
|
2930
|
-
path: "memberships",
|
|
2931
|
-
who: "suspended memberships",
|
|
2932
|
-
row: suspension.memberships
|
|
2933
|
-
}]].flatMap((entry) => {
|
|
2934
|
-
try {
|
|
2935
|
-
const keys = keptKeys(entry.row);
|
|
2936
|
-
return keys.length === 0 ? [] : [{
|
|
2937
|
-
path: entry.path,
|
|
2938
|
-
who: entry.who,
|
|
2939
|
-
keys
|
|
2940
|
-
}];
|
|
2941
|
-
} catch {
|
|
2942
|
-
return [{
|
|
2943
|
-
path: entry.path,
|
|
2944
|
-
who: entry.who,
|
|
2945
|
-
keys: [],
|
|
2946
|
-
invalid: true
|
|
2947
|
-
}];
|
|
2948
|
-
}
|
|
2949
|
-
});
|
|
2950
|
-
if (kept.length === 0) return [];
|
|
2951
|
-
const policy = await policyOf(input);
|
|
2952
|
-
const declared = /* @__PURE__ */ new Set();
|
|
2953
|
-
const former = /* @__PURE__ */ new Map();
|
|
2954
|
-
for (const leaf of policy === void 0 ? [] : listPermissions(policy.permissions)) {
|
|
2955
|
-
declared.add(leaf.key);
|
|
2956
|
-
for (const old of formerKeys(leaf)) former.set(old, leaf.key);
|
|
2957
|
-
}
|
|
2958
|
-
return kept.flatMap((item) => {
|
|
2959
|
-
if (item.invalid === true) return [{
|
|
2960
|
-
code: "PD061",
|
|
2961
|
-
severity: "warning",
|
|
2962
|
-
message: `rls.suspension.${item.path}.keep has an entry that is neither a permission nor a permission key, so generate refuses it`,
|
|
2963
|
-
fix: "list permission references or their keys in keep"
|
|
2964
|
-
}];
|
|
2965
|
-
const findings = [{
|
|
2966
|
-
code: "PD061",
|
|
2967
|
-
severity: "warning",
|
|
2968
|
-
message: `${item.who} still hold ${item.keys.join(", ")}`,
|
|
2969
|
-
fix: item.path === "memberships" ? "keep only what a suspended member must still do, such as leaving or exporting their own data, in rls.suspension.memberships.keep" : `keep only what a suspended ${item.path.slice(7)} must still do, such as restoring it or cancelling its deletion, in rls.suspension.${item.path}.keep`
|
|
2970
|
-
}];
|
|
2971
|
-
if (policy === void 0) return findings;
|
|
2972
|
-
const unknown = item.keys.filter((key) => !declared.has(key));
|
|
2973
|
-
if (unknown.length > 0) findings.push({
|
|
2974
|
-
code: "PD061",
|
|
2975
|
-
severity: "warning",
|
|
2976
|
-
message: `rls.suspension.${item.path}.keep names ${unknown.map((key) => former.has(key) ? `${key} (renamed to ${String(former.get(key))})` : key).join(", ")}, which the definitions do not declare, so a suspended ${item.path === "memberships" ? "membership" : item.path.slice(7)} keeps nothing for them`,
|
|
2977
|
-
fix: "keep permission references instead of keys, or replace each key with its current name"
|
|
2978
|
-
});
|
|
2979
|
-
return findings;
|
|
2980
|
-
});
|
|
2981
|
-
}
|
|
2982
|
-
const DOCTOR_CHECKS = [
|
|
2983
|
-
{
|
|
2984
|
-
code: "PD001",
|
|
2985
|
-
groups: ["imports"],
|
|
2986
|
-
run: (project) => pd001(project.sources(), new Set(listSourceFiles(project.cwd, project.config.doctor?.clientEntries ?? []).map((file) => rel(project.cwd, file))), project.config.policy === void 0 ? void 0 : {
|
|
2987
|
-
cwd: project.cwd,
|
|
2988
|
-
path: project.config.policy
|
|
2989
|
-
})
|
|
2990
|
-
},
|
|
2991
|
-
{
|
|
2992
|
-
code: "PD059",
|
|
2993
|
-
groups: ["project"],
|
|
2994
|
-
run: pd059
|
|
2995
|
-
},
|
|
2996
|
-
{
|
|
2997
|
-
code: "PD060",
|
|
2998
|
-
groups: ["project"],
|
|
2999
|
-
run: pd060
|
|
3000
|
-
},
|
|
3001
|
-
{
|
|
3002
|
-
code: "PD002",
|
|
3003
|
-
groups: ["references"],
|
|
3004
|
-
run: pd002
|
|
3005
|
-
},
|
|
3006
|
-
{
|
|
3007
|
-
code: "PD003",
|
|
3008
|
-
groups: ["ungranted"],
|
|
3009
|
-
run: pd003
|
|
3010
|
-
},
|
|
3011
|
-
{
|
|
3012
|
-
code: "PD004",
|
|
3013
|
-
groups: ["catalog"],
|
|
3014
|
-
run: pd004
|
|
3015
|
-
},
|
|
3016
|
-
{
|
|
3017
|
-
code: "PD067",
|
|
3018
|
-
groups: ["catalog", "operations"],
|
|
3019
|
-
when: (config) => config.operations !== void 0,
|
|
3020
|
-
run: pd067
|
|
3021
|
-
},
|
|
3022
|
-
{
|
|
3023
|
-
code: "PD070",
|
|
3024
|
-
groups: ["catalog", "better-supabase"],
|
|
3025
|
-
when: (config) => config.policy !== void 0,
|
|
3026
|
-
run: pd070
|
|
3027
|
-
},
|
|
3028
|
-
{
|
|
3029
|
-
code: "PD078",
|
|
3030
|
-
groups: ["supabase", "better-supabase"],
|
|
3031
|
-
when: (config) => config.supabase?.hook !== void 0,
|
|
3032
|
-
run: pd078
|
|
3033
|
-
},
|
|
3034
|
-
{
|
|
3035
|
-
code: "PD079",
|
|
3036
|
-
groups: ["catalog", "better-supabase"],
|
|
3037
|
-
run: pd079
|
|
3038
|
-
},
|
|
3039
|
-
{
|
|
3040
|
-
code: "PD080",
|
|
3041
|
-
groups: ["caching"],
|
|
3042
|
-
run: (project) => pd080(project.sources(), project.config.doctor?.cacheHelpers)
|
|
3043
|
-
},
|
|
3044
|
-
{
|
|
3045
|
-
code: "PD081",
|
|
3046
|
-
groups: ["caching"],
|
|
3047
|
-
run: (project) => pd081(project.sources(), project.config.doctor?.cacheHelpers)
|
|
3048
|
-
},
|
|
3049
|
-
{
|
|
3050
|
-
code: "PD082",
|
|
3051
|
-
groups: ["supabase", "better-supabase"],
|
|
3052
|
-
when: (config) => config.supabase?.hook !== void 0,
|
|
3053
|
-
run: pd082
|
|
3054
|
-
},
|
|
3055
|
-
{
|
|
3056
|
-
code: "PD087",
|
|
3057
|
-
groups: ["supabase", "better-supabase"],
|
|
3058
|
-
when: (config) => config.supabase?.hook !== void 0,
|
|
3059
|
-
run: pd087
|
|
3060
|
-
},
|
|
3061
|
-
{
|
|
3062
|
-
code: "PD083",
|
|
3063
|
-
groups: ["supabase"],
|
|
3064
|
-
run: (project) => pd083(project.cwd, project.config, project.sources())
|
|
3065
|
-
},
|
|
3066
|
-
{
|
|
3067
|
-
code: "PD005",
|
|
3068
|
-
groups: ["skills"],
|
|
3069
|
-
run: (project) => pd005(project.cwd, project.files)
|
|
3070
|
-
},
|
|
3071
|
-
{
|
|
3072
|
-
code: "PD006",
|
|
3073
|
-
groups: ["typescript"],
|
|
3074
|
-
run: (project) => pd006(project.cwd)
|
|
3075
|
-
},
|
|
3076
|
-
{
|
|
3077
|
-
code: "PD007",
|
|
3078
|
-
groups: ["validation"],
|
|
3079
|
-
run: (project) => pd007(project.sources())
|
|
3080
|
-
},
|
|
3081
|
-
{
|
|
3082
|
-
code: "PD008",
|
|
3083
|
-
groups: ["naming"],
|
|
3084
|
-
run: (project) => pd008(project.sources())
|
|
3085
|
-
},
|
|
3086
|
-
{
|
|
3087
|
-
code: "PD009",
|
|
3088
|
-
groups: ["duplicates"],
|
|
3089
|
-
run: (project) => pd009(project.cwd, project.files)
|
|
3090
|
-
},
|
|
3091
|
-
{
|
|
3092
|
-
code: "PD010",
|
|
3093
|
-
groups: ["claims"],
|
|
3094
|
-
run: (project) => pd010(project.sources())
|
|
3095
|
-
},
|
|
3096
|
-
{
|
|
3097
|
-
code: "PD011",
|
|
3098
|
-
groups: ["tenant"],
|
|
3099
|
-
run: (project) => pd011(project.sources())
|
|
3100
|
-
},
|
|
3101
|
-
{
|
|
3102
|
-
code: "PD012",
|
|
3103
|
-
groups: ["drafts"],
|
|
3104
|
-
run: (project) => pd012(project.cwd, project.config, project.files)
|
|
3105
|
-
},
|
|
3106
|
-
{
|
|
3107
|
-
code: "PD013",
|
|
3108
|
-
groups: ["algorithms"],
|
|
3109
|
-
run: (project) => pd013(project.sources())
|
|
3110
|
-
},
|
|
3111
|
-
{
|
|
3112
|
-
code: "PD014",
|
|
3113
|
-
groups: ["discovery"],
|
|
3114
|
-
run: (project) => pd014(project.sources())
|
|
3115
|
-
},
|
|
3116
|
-
{
|
|
3117
|
-
code: "PD015",
|
|
3118
|
-
groups: ["typ"],
|
|
3119
|
-
run: (project) => pd015(project.sources())
|
|
3120
|
-
},
|
|
3121
|
-
{
|
|
3122
|
-
code: "PD016",
|
|
3123
|
-
groups: ["rls"],
|
|
3124
|
-
run: pd016
|
|
3125
|
-
},
|
|
3126
|
-
{
|
|
3127
|
-
code: "PD017",
|
|
3128
|
-
groups: ["sensitive"],
|
|
3129
|
-
run: pd017
|
|
3130
|
-
},
|
|
3131
|
-
{
|
|
3132
|
-
code: "PD018",
|
|
3133
|
-
groups: ["separation"],
|
|
3134
|
-
run: pd018
|
|
3135
|
-
},
|
|
3136
|
-
{
|
|
3137
|
-
code: "PD019",
|
|
3138
|
-
groups: ["jwt-roles"],
|
|
3139
|
-
run: pd019
|
|
3140
|
-
},
|
|
3141
|
-
{
|
|
3142
|
-
code: "PD020",
|
|
3143
|
-
groups: ["hosted"],
|
|
3144
|
-
run: pd020
|
|
3145
|
-
},
|
|
3146
|
-
{
|
|
3147
|
-
code: "PD021",
|
|
3148
|
-
groups: ["hosted"],
|
|
3149
|
-
run: (project) => pd021({
|
|
3150
|
-
...project,
|
|
3151
|
-
env: project.io.env ?? process.env
|
|
3152
|
-
})
|
|
3153
|
-
},
|
|
3154
|
-
{
|
|
3155
|
-
code: "PD022",
|
|
3156
|
-
groups: ["views"],
|
|
3157
|
-
run: (project) => pd022(project.cwd, project.config, project.files)
|
|
3158
|
-
},
|
|
3159
|
-
{
|
|
3160
|
-
code: "PD023",
|
|
3161
|
-
groups: ["custom-roles"],
|
|
3162
|
-
run: pd023
|
|
3163
|
-
},
|
|
3164
|
-
{
|
|
3165
|
-
code: "PD024",
|
|
3166
|
-
groups: ["self-approval"],
|
|
3167
|
-
run: pd024
|
|
3168
|
-
},
|
|
3169
|
-
{
|
|
3170
|
-
code: "PD025",
|
|
3171
|
-
groups: ["scopes"],
|
|
3172
|
-
run: pd025
|
|
3173
|
-
},
|
|
3174
|
-
{
|
|
3175
|
-
code: "PD026",
|
|
3176
|
-
groups: ["ownership"],
|
|
3177
|
-
run: pd026
|
|
3178
|
-
},
|
|
3179
|
-
{
|
|
3180
|
-
code: "PD027",
|
|
3181
|
-
groups: ["rls", "context-refs"],
|
|
3182
|
-
run: pd027
|
|
3183
|
-
},
|
|
3184
|
-
{
|
|
3185
|
-
code: "PD071",
|
|
3186
|
-
groups: ["rls"],
|
|
3187
|
-
run: pd071
|
|
3188
|
-
},
|
|
3189
|
-
{
|
|
3190
|
-
code: "PD072",
|
|
3191
|
-
groups: ["rls"],
|
|
3192
|
-
run: pd072
|
|
3193
|
-
},
|
|
3194
|
-
{
|
|
3195
|
-
code: "PD073",
|
|
3196
|
-
groups: ["rls", "ownership"],
|
|
3197
|
-
run: pd073
|
|
3198
|
-
},
|
|
3199
|
-
{
|
|
3200
|
-
code: "PD075",
|
|
3201
|
-
groups: ["rls"],
|
|
3202
|
-
run: pd075
|
|
3203
|
-
},
|
|
3204
|
-
{
|
|
3205
|
-
code: "PD076",
|
|
3206
|
-
groups: ["rls"],
|
|
3207
|
-
run: pd076
|
|
3208
|
-
},
|
|
3209
|
-
{
|
|
3210
|
-
code: "PD077",
|
|
3211
|
-
groups: ["rls", "scopes"],
|
|
3212
|
-
run: pd077
|
|
3213
|
-
},
|
|
3214
|
-
{
|
|
3215
|
-
code: "PD028",
|
|
3216
|
-
groups: ["attrs", "supabase"],
|
|
3217
|
-
run: (project) => pd028(project.cwd, project.config, attrsPlan, project.files)
|
|
3218
|
-
},
|
|
3219
|
-
{
|
|
3220
|
-
code: "PD029",
|
|
3221
|
-
groups: ["credentials"],
|
|
3222
|
-
run: pd029
|
|
3223
|
-
},
|
|
3224
|
-
{
|
|
3225
|
-
code: "PD030",
|
|
3226
|
-
groups: ["fields"],
|
|
3227
|
-
run: pd030
|
|
3228
|
-
},
|
|
3229
|
-
{
|
|
3230
|
-
code: "PD031",
|
|
3231
|
-
groups: ["graph"],
|
|
3232
|
-
run: pd031
|
|
3233
|
-
},
|
|
3234
|
-
{
|
|
3235
|
-
code: "PD032",
|
|
3236
|
-
groups: ["graph", "rls"],
|
|
3237
|
-
run: pd032
|
|
3238
|
-
},
|
|
3239
|
-
{
|
|
3240
|
-
code: "PD033",
|
|
3241
|
-
groups: ["activation"],
|
|
3242
|
-
run: pd033
|
|
3243
|
-
},
|
|
3244
|
-
{
|
|
3245
|
-
code: "PD034",
|
|
3246
|
-
groups: ["break-glass"],
|
|
3247
|
-
run: pd034
|
|
3248
|
-
},
|
|
3249
|
-
{
|
|
3250
|
-
code: "PD035",
|
|
3251
|
-
groups: ["support"],
|
|
3252
|
-
run: pd035
|
|
3253
|
-
},
|
|
3254
|
-
{
|
|
3255
|
-
code: "PD036",
|
|
3256
|
-
groups: ["bola"],
|
|
3257
|
-
run: (project) => pd036(project.sources())
|
|
3258
|
-
},
|
|
3259
|
-
{
|
|
3260
|
-
code: "PD037",
|
|
3261
|
-
groups: ["supabase", "row-conditions"],
|
|
3262
|
-
run: pd037
|
|
3263
|
-
},
|
|
3264
|
-
{
|
|
3265
|
-
code: "PD039",
|
|
3266
|
-
groups: ["supabase", "helpers"],
|
|
3267
|
-
when: (config) => config.supabase?.hook !== void 0,
|
|
3268
|
-
run: supabaseSetup
|
|
3269
|
-
},
|
|
3270
|
-
{
|
|
3271
|
-
code: "PD038",
|
|
3272
|
-
groups: ["supabase", "tenant"],
|
|
3273
|
-
when: (config) => config.rls !== void 0 || config.supabase?.hook !== void 0,
|
|
3274
|
-
run: (project) => pd038(project.sources(), project.config.rls?.tenantClaim ?? "tenant_id", supabaseTenantClaim)
|
|
3275
|
-
},
|
|
3276
|
-
{
|
|
3277
|
-
code: "PD057",
|
|
3278
|
-
groups: ["supabase", "anonymous"],
|
|
3279
|
-
when: (config) => config.rls?.anonymousSignIns === "deny",
|
|
3280
|
-
run: (project) => pd057(project.sources())
|
|
3281
|
-
},
|
|
3282
|
-
{
|
|
3283
|
-
code: "PD040",
|
|
3284
|
-
groups: ["supabase", "auth-role"],
|
|
3285
|
-
run: (project) => pd040(project.cwd, project.config, project.files)
|
|
3286
|
-
},
|
|
3287
|
-
{
|
|
3288
|
-
code: "PD041",
|
|
3289
|
-
groups: ["supabase", "capabilities"],
|
|
3290
|
-
run: (project) => pd041(project.sources())
|
|
3291
|
-
},
|
|
3292
|
-
{
|
|
3293
|
-
code: "PD042",
|
|
3294
|
-
groups: ["supabase", "declarative"],
|
|
3295
|
-
run: (project) => pd042(project.cwd, project.config, project.files)
|
|
3296
|
-
},
|
|
3297
|
-
{
|
|
3298
|
-
code: "PD043",
|
|
3299
|
-
groups: ["supabase", "declarative"],
|
|
3300
|
-
run: (project) => pd043(project.cwd, project.config, project.files)
|
|
3301
|
-
},
|
|
3302
|
-
{
|
|
3303
|
-
code: "PD068",
|
|
3304
|
-
groups: ["supabase", "declarative"],
|
|
3305
|
-
run: (project) => pd068(project.cwd, project.config, project.files)
|
|
3306
|
-
},
|
|
3307
|
-
{
|
|
3308
|
-
code: "PD069",
|
|
3309
|
-
groups: ["supabase", "declarative"],
|
|
3310
|
-
run: (project) => pd069(project.cwd, project.config, project.files)
|
|
3311
|
-
},
|
|
3312
|
-
{
|
|
3313
|
-
code: "PD045",
|
|
3314
|
-
groups: ["supabase"],
|
|
3315
|
-
run: (project) => pd045(project.cwd)
|
|
3316
|
-
},
|
|
3317
|
-
{
|
|
3318
|
-
code: "PD074",
|
|
3319
|
-
groups: ["supabase", "helpers"],
|
|
3320
|
-
when: (config) => config.supabase?.hook !== void 0,
|
|
3321
|
-
run: (project) => pd074(project.cwd, project.config)
|
|
3322
|
-
},
|
|
3323
|
-
...[
|
|
3324
|
-
["PD046", pd046],
|
|
3325
|
-
["PD047", pd047],
|
|
3326
|
-
["PD048", pd048],
|
|
3327
|
-
["PD049", pd049],
|
|
3328
|
-
["PD050", pd050],
|
|
3329
|
-
["PD051", pd051],
|
|
3330
|
-
["PD052", pd052],
|
|
3331
|
-
["PD053", pd053],
|
|
3332
|
-
["PD062", pd062],
|
|
3333
|
-
["PD063", pd063],
|
|
3334
|
-
["PD088", pd088],
|
|
3335
|
-
["PD089", pd089],
|
|
3336
|
-
["PD090", pd090],
|
|
3337
|
-
["PD093", pd093]
|
|
3338
|
-
].map(([code, check]) => ({
|
|
3339
|
-
code,
|
|
3340
|
-
groups: ["supabase", "sql"],
|
|
3341
|
-
run: (project) => check(project.cwd, project.config, project.files)
|
|
3342
|
-
})),
|
|
3343
|
-
{
|
|
3344
|
-
code: "PD054",
|
|
3345
|
-
groups: ["supabase", "seeds"],
|
|
3346
|
-
run: pd054
|
|
3347
|
-
},
|
|
3348
|
-
{
|
|
3349
|
-
code: "PD055",
|
|
3350
|
-
groups: ["custom-roles", "renamed"],
|
|
3351
|
-
run: pd055
|
|
3352
|
-
},
|
|
3353
|
-
{
|
|
3354
|
-
code: "PD056",
|
|
3355
|
-
groups: ["sql", "shims"],
|
|
3356
|
-
run: (project) => pd056(project.cwd, project.config, project.files)
|
|
3357
|
-
},
|
|
3358
|
-
{
|
|
3359
|
-
code: "PD066",
|
|
3360
|
-
groups: ["sql", "shims"],
|
|
3361
|
-
when: (config) => config.rls?.migrate?.tables !== void 0,
|
|
3362
|
-
run: (project) => pd066(project.cwd, project.config, project.files)
|
|
3363
|
-
},
|
|
3364
|
-
{
|
|
3365
|
-
code: "PD085",
|
|
3366
|
-
groups: ["supabase", "hook"],
|
|
3367
|
-
when: (config) => config.supabase?.hook !== void 0,
|
|
3368
|
-
run: pd085
|
|
3369
|
-
},
|
|
3370
|
-
{
|
|
3371
|
-
code: "PD058",
|
|
3372
|
-
groups: ["powersync"],
|
|
3373
|
-
run: pd058
|
|
3374
|
-
},
|
|
3375
|
-
{
|
|
3376
|
-
code: "PD084",
|
|
3377
|
-
groups: ["powersync", "react-native"],
|
|
3378
|
-
run: pd084
|
|
3379
|
-
},
|
|
3380
|
-
{
|
|
3381
|
-
code: "PD086",
|
|
3382
|
-
groups: ["rls"],
|
|
3383
|
-
run: pd086
|
|
3384
|
-
},
|
|
3385
|
-
{
|
|
3386
|
-
code: "PD061",
|
|
3387
|
-
groups: ["rls", "suspension"],
|
|
3388
|
-
when: (config) => config.rls?.suspension?.scopes !== void 0,
|
|
3389
|
-
run: pd061
|
|
3390
|
-
},
|
|
3391
|
-
{
|
|
3392
|
-
code: "PD064",
|
|
3393
|
-
groups: ["rls", "assignments"],
|
|
3394
|
-
when: (config) => config.rls?.assignments !== void 0,
|
|
3395
|
-
run: pd064
|
|
3396
|
-
},
|
|
3397
|
-
{
|
|
3398
|
-
code: "PD091",
|
|
3399
|
-
groups: ["openapi"],
|
|
3400
|
-
when: pd091Applies,
|
|
3401
|
-
run: pd091
|
|
3402
|
-
},
|
|
3403
|
-
{
|
|
3404
|
-
code: "PD092",
|
|
3405
|
-
groups: ["project"],
|
|
3406
|
-
run: pd092
|
|
3407
|
-
},
|
|
3408
|
-
{
|
|
3409
|
-
code: "PD044",
|
|
3410
|
-
groups: ["next", "endpoint"],
|
|
3411
|
-
run: pd044
|
|
3412
|
-
},
|
|
3413
|
-
{
|
|
3414
|
-
code: "PD065",
|
|
3415
|
-
groups: ["react-native", "endpoint"],
|
|
3416
|
-
run: pd065
|
|
3417
|
-
}
|
|
3418
|
-
];
|
|
3419
|
-
async function runDoctor(input) {
|
|
3420
|
-
const wanted = new Set(input.only.map((item) => item.toLowerCase()));
|
|
3421
|
-
const unknown = unknownOnly(wanted);
|
|
3422
|
-
if (unknown !== void 0) return {
|
|
3423
|
-
code: 2,
|
|
3424
|
-
output: unknown
|
|
3425
|
-
};
|
|
3426
|
-
const fixed = [];
|
|
3427
|
-
if (input.fix) {
|
|
3428
|
-
const skills = runSkillsInstall({
|
|
3429
|
-
cwd: input.cwd,
|
|
3430
|
-
agents: []
|
|
3431
|
-
});
|
|
3432
|
-
fixed.push(`skills: ${skills.output}`);
|
|
3433
|
-
const collected = await runCollect({
|
|
3434
|
-
cwd: input.cwd,
|
|
3435
|
-
config: input.config,
|
|
3436
|
-
collect: input.config.collect ?? {},
|
|
3437
|
-
check: false,
|
|
3438
|
-
now: input.now,
|
|
3439
|
-
io: input.io
|
|
3440
|
-
});
|
|
3441
|
-
fixed.push(`catalog: ${collected.message.trim()}`);
|
|
3442
|
-
}
|
|
3443
|
-
const project = loadProject({
|
|
3444
|
-
...input,
|
|
3445
|
-
...input.db === void 0 ? {} : { database: {
|
|
3446
|
-
url: input.db,
|
|
3447
|
-
connect: input.connect ?? pgConnector("permdock doctor", input.cwd)
|
|
3448
|
-
} }
|
|
3449
|
-
});
|
|
3450
|
-
const selected = (check) => wanted.size === 0 || wanted.has(check.code.toLowerCase()) || check.groups.some((group) => wanted.has(group));
|
|
3451
|
-
const collected = [];
|
|
3452
|
-
for (const check of DOCTOR_CHECKS) {
|
|
3453
|
-
if (check.when !== void 0 && !check.when(input.config)) continue;
|
|
3454
|
-
if (selected(check)) collected.push(...await check.run(project));
|
|
3455
|
-
}
|
|
3456
|
-
const { findings, ignored } = applyDoctorIgnores(collected.map(reported), input.config, input.ignore ?? []);
|
|
3457
|
-
const errors = findings.filter((item) => item.severity === "error").length;
|
|
3458
|
-
const warnings = findings.filter((item) => item.severity === "warning").length;
|
|
3459
|
-
const report = {
|
|
3460
|
-
$schema: DOCTOR_REPORT_SCHEMA,
|
|
3461
|
-
fixed,
|
|
3462
|
-
findings,
|
|
3463
|
-
ignored,
|
|
3464
|
-
errors,
|
|
3465
|
-
warnings
|
|
3466
|
-
};
|
|
3467
|
-
return {
|
|
3468
|
-
code: errors > 0 || input.strict && warnings > 0 ? 1 : 0,
|
|
3469
|
-
output: input.json ? `${JSON.stringify(report, null, 2)}\n` : formatDoctor(report, input.color),
|
|
3470
|
-
findings: findings.map((item) => findingOf({
|
|
3471
|
-
...item,
|
|
3472
|
-
docs: `${DOCS_BASE}/doctor#checks`
|
|
3473
|
-
}))
|
|
3474
|
-
};
|
|
3475
|
-
}
|
|
3476
|
-
/**
|
|
3477
|
-
* PD059: the configured policy module throws or exports no policy, so every
|
|
3478
|
-
* policy check is skipped.
|
|
3479
|
-
*/
|
|
3480
|
-
async function pd059(project) {
|
|
3481
|
-
const load = await project.policyLoad();
|
|
3482
|
-
if (load.status !== "failed") return [];
|
|
3483
|
-
return [{
|
|
3484
|
-
code: "PD059",
|
|
3485
|
-
severity: "error",
|
|
3486
|
-
target: load.path,
|
|
3487
|
-
message: `policy module ${load.path} did not load (${load.message}), so doctor skipped every check that reads the policy`,
|
|
3488
|
-
fix: "fix the module so it exports policy from definePolicy, or point policy in permdock.config.ts at the module that does"
|
|
3489
|
-
}];
|
|
3490
|
-
}
|
|
3491
|
-
/**
|
|
3492
|
-
* PD060: a source file under srcPath has a syntax error, so collect and usage
|
|
3493
|
-
* miss what it references.
|
|
3494
|
-
*/
|
|
3495
|
-
async function pd060(project) {
|
|
3496
|
-
return ((await project.collected()).scan?.unparsed ?? []).map((item) => ({
|
|
3497
|
-
code: "PD060",
|
|
3498
|
-
severity: "warning",
|
|
3499
|
-
target: `${item.file}:${String(item.line)}`,
|
|
3500
|
-
message: `${item.file}:${String(item.line)} does not parse (${item.message}), so the catalog and usage report miss the permissions it references`,
|
|
3501
|
-
fix: "fix the syntax error, or exclude the file from collect.srcPath"
|
|
3502
|
-
}));
|
|
3503
|
-
}
|
|
3504
|
-
/**
|
|
3505
|
-
* A usage message for the first `--only` value that names no check code or
|
|
3506
|
-
* group.
|
|
3507
|
-
*/
|
|
3508
|
-
function unknownOnly(wanted) {
|
|
3509
|
-
const known = /* @__PURE__ */ new Set();
|
|
3510
|
-
for (const check of DOCTOR_CHECKS) {
|
|
3511
|
-
known.add(check.code.toLowerCase());
|
|
3512
|
-
for (const group of check.groups) known.add(group);
|
|
3513
|
-
}
|
|
3514
|
-
for (const item of wanted) if (!known.has(item)) {
|
|
3515
|
-
const suggestion = didYouMean(item, [...known]);
|
|
3516
|
-
return `doctor: --only ${item} names no check code or group${suggestion === void 0 ? "" : `. Did you mean ${suggestion}?`}`;
|
|
3517
|
-
}
|
|
3518
|
-
}
|
|
3519
|
-
function formatDoctor(report, color) {
|
|
3520
|
-
const style = createStyle(color);
|
|
3521
|
-
const lines = [style.paint("bold", "permdock doctor"), ""];
|
|
3522
|
-
for (const change of report.fixed) lines.push(` ${style.okMark} fixed ${change}`);
|
|
3523
|
-
if (report.fixed.length > 0) lines.push("");
|
|
3524
|
-
for (const finding of report.findings) {
|
|
3525
|
-
const mark = markOf(finding.severity, style);
|
|
3526
|
-
lines.push(` ${mark} ${style.paint("bold", finding.code)} ${finding.message}`);
|
|
3527
|
-
lines.push(` ${style.paint("dim", `fix: ${finding.fix} [${finding.id}]`)}`);
|
|
3528
|
-
}
|
|
3529
|
-
for (const item of report.ignored) lines.push(` ${style.paint("dim", `ignored ${item.id}: ${item.reason}`)}`);
|
|
3530
|
-
if (report.findings.length === 0) lines.push(" no findings");
|
|
3531
|
-
lines.push("");
|
|
3532
|
-
const notes = report.findings.filter((finding) => finding.severity === "info").length;
|
|
3533
|
-
lines.push(` ${String(report.errors)} error${report.errors === 1 ? "" : "s"}, ${String(report.warnings)} warning${report.warnings === 1 ? "" : "s"}${notes === 0 ? "" : `, ${String(notes)} note${notes === 1 ? "" : "s"}`}`);
|
|
3534
|
-
return `${lines.join("\n")}\n`;
|
|
3535
|
-
}
|
|
3536
|
-
function markOf(severity, style) {
|
|
3537
|
-
switch (severity) {
|
|
3538
|
-
case "error": return style.errorMark;
|
|
3539
|
-
case "warning": return style.warnMark;
|
|
3540
|
-
case "info": return style.infoMark;
|
|
3541
|
-
default: return severity;
|
|
3542
|
-
}
|
|
3543
|
-
}
|
|
3544
|
-
async function supabaseSetup(input) {
|
|
3545
|
-
const policy = await input.policy();
|
|
3546
|
-
if (policy === void 0) return [];
|
|
3547
|
-
let manifest;
|
|
3548
|
-
try {
|
|
3549
|
-
manifest = supabaseHookManifest(scopeList(policy.scopes), input.config, { out: hookOut(input.cwd, input.config) }, policy);
|
|
3550
|
-
} catch {
|
|
3551
|
-
return [];
|
|
3552
|
-
}
|
|
3553
|
-
return pd039({
|
|
3554
|
-
cwd: input.cwd,
|
|
3555
|
-
config: input.config,
|
|
3556
|
-
manifest
|
|
3557
|
-
});
|
|
3558
|
-
}
|
|
3559
|
-
//#endregion
|
|
3560
|
-
export { DOCTOR_CHECKS, runDoctor };
|