permdock 0.31.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2a/index.d.ts +4 -4
- package/dist/a2a/index.js +2 -2
- package/dist/{adoption-scan-9brJ_mUG.js → adoption-scan-BPW1eWy5.js} +1 -1
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/ai-sdk/index.d.ts +3 -3
- package/dist/ai-sdk/index.js +3 -3
- package/dist/app/index.d.ts +1 -1
- package/dist/app/index.js +1 -1
- package/dist/{approval-chain-D97rgMoA.js → approval-chain-BEeExHpb.js} +15 -10
- package/dist/{approval-prompt-yNyhQqn8.d.ts → approval-prompt-CJvYBdja.d.ts} +1 -1
- package/dist/approvals/index.d.ts +3 -3
- package/dist/{arazzo-C0bltfjv.js → arazzo-BUXKjylF.js} +1 -1
- package/dist/{arazzo-Cs-3yoxR.js → arazzo-DqzmZG-x.js} +2 -2
- package/dist/astro/index.d.ts +4 -4
- package/dist/astro/index.js +1 -1
- package/dist/{audience-CARf-b-R.js → audience-B6DQ5wQu.js} +1 -1
- package/dist/authzen/index.d.ts +6 -6
- package/dist/authzen/index.js +1 -1
- package/dist/{automation-0VF1xe4o.d.ts → automation-BqUmdFfe.d.ts} +1 -1
- package/dist/better-auth/index.d.ts +1 -1
- package/dist/better-supabase/index.d.ts +57 -14
- package/dist/better-supabase/index.js +29 -20
- package/dist/{bind-zQacwAOg.d.ts → bind-Bwk9tt1z.d.ts} +7 -7
- package/dist/{bind-BYeoLJgN.js → bind-DPptdk31.js} +2 -2
- package/dist/{bsb-access-tags-B1TBUQLj.js → bsb-access-tags-Nv4nDQ2U.js} +20 -44
- package/dist/{bsb-action-keys-iKmZChtQ.js → bsb-action-keys-CYEREFMg.js} +1 -1
- package/dist/{budgets-Dpumu_Dt.js → budgets-hi-ecgEd.js} +3 -3
- package/dist/{build-instance-CFiegi_w.js → build-instance-DZEWYO-A.js} +1 -1
- package/dist/bundle-size-BRFeBvuv.js +1 -0
- package/dist/{bundle-size-Ddhv_H_v.js → bundle-size-DbXV65Ix.js} +2 -2
- package/dist/{capability-BPzseilU.d.ts → capability-qoD_jlcI.d.ts} +1 -1
- package/dist/{casbin-s6_zDJi1.js → casbin-CM9mWO1V.js} +1 -1
- package/dist/{casbin-DGsO-QmR.js → casbin-qEW6RfXA.js} +1 -1
- package/dist/catalog/index.d.ts +4 -4
- package/dist/catalog/index.js +4 -4
- package/dist/{challenge-CRB1X3Ry.js → challenge-E9sicsCA.js} +1 -1
- package/dist/chat/index.d.ts +1 -1
- package/dist/chat/index.js +1 -1
- package/dist/chat-sdk/index.d.ts +3 -3
- package/dist/{claims-size-BsSDVD5u.js → claims-size-BUhCWS88.js} +18 -3
- package/dist/claims-size-C6oKGuOM.js +1 -0
- package/dist/claude-agent/index.d.ts +3 -3
- package/dist/claude-agent/index.js +2 -2
- package/dist/clerk/index.d.ts +2 -2
- package/dist/cli/bin.js +1 -1
- package/dist/cli/generate/watch-worker.js +2 -2
- package/dist/cli/index.d.ts +6 -6
- package/dist/cli/index.js +3 -3
- package/dist/cli/plugins/app.d.ts +1 -1
- package/dist/cli/plugins/app.js +1 -1
- package/dist/cli/plugins/better-supabase.d.ts +1 -1
- package/dist/cli/plugins/openapi.d.ts +1 -1
- package/dist/cli/plugins/openapi.js +1 -1
- package/dist/cli/plugins/powersync.d.ts +1 -1
- package/dist/cli/plugins/powersync.js +1 -1
- package/dist/cli/plugins/rls.d.ts +2 -2
- package/dist/cli/plugins/rls.js +1 -1
- package/dist/cli/plugins/schemas.d.ts +1 -1
- package/dist/cli/plugins/schemas.js +1 -1
- package/dist/cli/plugins/scim.d.ts +2 -2
- package/dist/cli/plugins/supabase-hook.d.ts +2 -2
- package/dist/cli/plugins/supabase-hook.js +1 -1
- package/dist/cli/plugins/supabase.d.ts +3 -3
- package/dist/cli/plugins/supabase.js +2 -2
- package/dist/cli/plugins/ui.d.ts +1 -1
- package/dist/cli/plugins/ui.js +1 -1
- package/dist/{client-subject-BOPbpwgm.d.ts → client-subject-Dzo49nco.d.ts} +2 -2
- package/dist/cloud/index.d.ts +8 -8
- package/dist/cloud/index.js +1 -1
- package/dist/{cloud-fRv3j6sq.js → cloud-CNGblWX0.js} +2 -2
- package/dist/{codemod-DT0dMVdd.js → codemod-BtJFcsD7.js} +8 -7
- package/dist/{codemod-DsqEKP6A.js → codemod-Dlhxov9D.js} +14 -11
- package/dist/{collect-CCgmm5xN.js → collect-CE5wK0AX.js} +1 -1
- package/dist/compile/index.d.ts +1 -1
- package/dist/{compile-tG1zkSgX.d.ts → compile-DNgpHgcK.d.ts} +2 -2
- package/dist/{compile-DNVVdVWs.js → compile-nR1gQhXo.js} +10 -9
- package/dist/{completion-DrJkWgZa.js → completion-BIN9YXIe.js} +1 -1
- package/dist/{config-D8iWeV9k.js → config-7QvEq57a.js} +2 -2
- package/dist/{config-BaKkd6HB.js → config-CoYhD6ur.js} +1 -1
- package/dist/{config-report-uuD5eVEn.js → config-report-D_L1HXDb.js} +3 -3
- package/dist/{context-Ne0EdD45.js → context-D8tN3SZm.js} +1 -1
- package/dist/{context-BQHKgT1m.js → context-Nr3nknZX.js} +2 -2
- package/dist/convex/index.d.ts +4 -4
- package/dist/convex/index.js +2 -2
- package/dist/{core-C5yCD-Ls.js → core-DIUrkFNL.js} +5 -5
- package/dist/{core-bf8qgaZf.d.ts → core-DPuDmlbL.d.ts} +2 -2
- package/dist/{create-Cn5EpEez.d.ts → create-BKrKxipb.d.ts} +4 -4
- package/dist/{create-COQVXK6C.js → create-BMRnaZel.js} +3 -3
- package/dist/{create-nOWD3Joc.js → create-BRY0OtFV.js} +3 -3
- package/dist/{create-B7Xa4jSQ.d.ts → create-CdB9FCZh.d.ts} +7 -7
- package/dist/{create-DHA0fhmi.d.ts → create-CdbVXh5I.d.ts} +6 -6
- package/dist/{credentials-COT-cjnP.d.ts → credentials-Dl0-R2aB.d.ts} +2 -2
- package/dist/{custom-role-rebuild-BBKC7Bt1.js → custom-role-rebuild-wzN8pqDk.js} +5 -5
- package/dist/{define-permdock-DBgwTFi1.d.ts → define-permdock-4IkoNaB3.d.ts} +6 -6
- package/dist/{define-permdock-D7aKxIax.js → define-permdock-CO7YNrOF.js} +2 -2
- package/dist/{definition-options-9o8Hdww3.js → definition-options-DO0kIrB9.js} +7 -1
- package/dist/delivery/index.d.ts +4 -4
- package/dist/delivery/index.js +1 -1
- package/dist/{denied-text-C_AWc0f0.d.ts → denied-text-CllTzVJM.d.ts} +1 -1
- package/dist/{describe-AdETpWsn.d.ts → describe-FT1oVN_o.d.ts} +1 -1
- package/dist/{diff-CW9eZy9X.js → diff-CS8ks9h3.js} +1 -1
- package/dist/{diff-COdwpP31.js → diff-CkSZF7LO.js} +2 -2
- package/dist/{doctor-C1T2G2mn.js → doctor-Bn5OPJMB.js} +131 -44
- package/dist/{doctor-Ch4VGl2q.js → doctor-C9lLeLp2.js} +2 -2
- package/dist/drizzle/index.d.ts +3 -3
- package/dist/elysia/index.d.ts +4 -4
- package/dist/elysia/index.js +1 -1
- package/dist/{errors-COoiWqIs.d.ts → errors-BGosrHl8.d.ts} +1 -1
- package/dist/{evaluate-Dmd0bShm.js → evaluate-DNz6wMYv.js} +1 -1
- package/dist/{evaluations-GW9j_ARq.d.ts → evaluations-CaXNkxTp.d.ts} +3 -3
- package/dist/{evaluator-eager-CpVYslzY.js → evaluator-eager-BLNVbEAC.js} +1 -1
- package/dist/evaluator-zpeC7zel.js +2 -0
- package/dist/eve/index.d.ts +4 -4
- package/dist/eve/index.js +2 -2
- package/dist/{execute-BhWXiQAy.js → execute-DsHFIBuO.js} +4 -4
- package/dist/{explain-DRC9V5Qb.js → explain-D4ipf8IH.js} +1 -1
- package/dist/{explain-jg0KLCVt.js → explain-DISCeeYS.js} +2 -2
- package/dist/express/index.d.ts +4 -4
- package/dist/express/index.js +1 -1
- package/dist/fastify/index.d.ts +4 -4
- package/dist/fastify/index.js +1 -1
- package/dist/{fetch-adapter-CU1DIkXu.js → fetch-adapter-BXQc4NoV.js} +1 -1
- package/dist/{fetch-adapter-CJncmsPg.d.ts → fetch-adapter-Dci9NnyZ.d.ts} +2 -2
- package/dist/{fields-y_PSRCyJ.js → fields-CwFej4gp.js} +3 -3
- package/dist/{from-snapshot-DGc9W4QU.js → from-snapshot-DZ4D2sLa.js} +14 -9
- package/dist/gen-CpS9JkCb.js +1 -0
- package/dist/{gen-CGjbD8I_.js → gen-Fi4GcvIY.js} +3 -3
- package/dist/{gen-kind-thoT0NYV.js → gen-kind-DR2-to9P.js} +1 -1
- package/dist/{generate-eor7vXGN.js → generate-BSD_eI61.js} +22 -17
- package/dist/{generate-vEW8Brg8.js → generate-QEHCJSyv.js} +3 -3
- package/dist/{generate-options-MJgn0dgl.js → generate-options-BZ2nqy28.js} +14 -13
- package/dist/h3/index.d.ts +4 -4
- package/dist/h3/index.js +2 -2
- package/dist/{helper-calls-DHvgN9tr.js → helper-calls-B5MOl99d.js} +1 -1
- package/dist/hono/index.d.ts +4 -4
- package/dist/hono/index.js +1 -1
- package/dist/{hook-sql-DJQ_yOEC.js → hook-sql-CbkH78FC.js} +267 -223
- package/dist/{hosted-Bkw3Oyh-.d.ts → hosted-BISipW6F.d.ts} +1 -1
- package/dist/{hosted-DZwCFrcy.js → hosted-D3USbpS6.js} +1 -1
- package/dist/{import-D_8tLF9g.js → import-Bz6IKoMM.js} +3 -3
- package/dist/{import-CGQIK3iN.js → import-DppjSugv.js} +1 -1
- package/dist/{index-DT3hOxA7.d.ts → index-BDJ2OZvV.d.ts} +34 -11
- package/dist/{index-Kj5S3IWE.d.ts → index-BF4IlvkT.d.ts} +4 -4
- package/dist/{index-DWmIuQLz.d.ts → index-BO5f180f.d.ts} +4 -4
- package/dist/{index-WOx7TBbj.d.ts → index-CWwWkz10.d.ts} +2 -2
- package/dist/{index-xShPsK8G.d.ts → index-Co_e22iJ.d.ts} +1 -1
- package/dist/{index-DPVeDtAO.d.ts → index-giCl-aQY.d.ts} +4 -4
- package/dist/index.d.ts +16 -16
- package/dist/index.js +13 -13
- package/dist/{init-C6te_dSg.js → init-BOYIObRF.js} +3 -3
- package/dist/{init-DN19mlwE.js → init-DJYSpo-H.js} +1 -1
- package/dist/inspect-functions-CwEAQpVF.js +34 -0
- package/dist/{instance-options-DQCiBBuz.d.ts → instance-options-hq5Cp2Ih.d.ts} +1 -1
- package/dist/{instance-snapshot-D9kjL37B.js → instance-snapshot-D03srwnf.js} +9 -8
- package/dist/{interactive-only-BjYwp9mm.js → interactive-only-Bbq9e61G.js} +27 -182
- package/dist/jwt/index.d.ts +4 -4
- package/dist/{kernel-C5akxw5n.js → kernel-DSnWVZ0O.js} +5 -5
- package/dist/{keys-qFqDoYeF.js → keys-U2V0maaq.js} +1 -1
- package/dist/kysely/index.d.ts +3 -3
- package/dist/{lazy-provider-CMgFAGf8.d.ts → lazy-provider-W8KwlWJU.d.ts} +1 -1
- package/dist/{lazy-provider-DNVjY4n3.js → lazy-provider-b8UHGi8P.js} +2 -2
- package/dist/{login-BYXaH_yT.js → login-Dv8TFykx.js} +1 -1
- package/dist/{login-CMzfsdm8.js → login-xgjt0a5o.js} +3 -3
- package/dist/{manager-chain-CStuYb7A.js → manager-chain-FggG63qD.js} +2 -2
- package/dist/{manifest-CowZuywo.js → manifest-BUeAHWDT.js} +45 -38
- package/dist/{manifest-CA3E0KP8.d.ts → manifest-BwhZ1s5b.d.ts} +71 -2
- package/dist/{manifest-DdNYR_pl.js → manifest-CIWOmdlP.js} +1 -1
- package/dist/{manifest-schema-CLbcbDz7.js → manifest-schema-N3v2RVL-.js} +68 -1
- package/dist/{may-use-4HzzgYJ3.js → may-use-ikNCnNgZ.js} +1 -1
- package/dist/mcp/index.d.ts +8 -8
- package/dist/mcp/index.js +2 -2
- package/dist/measure-DZtly0oE.js +272 -0
- package/dist/membership-claim-sql-DGfhIn__.js +33 -0
- package/dist/{membership-filter-C7ZuhAqJ.js → membership-filter-Bz9QX6E9.js} +1 -1
- package/dist/memberships-4e6qi8Uv.js +1 -0
- package/dist/memberships-CNoAlsma.js +180 -0
- package/dist/{migrate-pg-lkbDu.js → migrate-BXk_rUmb.js} +2 -2
- package/dist/{model-BqHWwfcg.js → model-D0EKt-ED.js} +3 -3
- package/dist/names-DBxKx2bz.js +182 -0
- package/dist/nest/index.d.ts +4 -4
- package/dist/nest/index.js +1 -1
- package/dist/next/index.d.ts +12 -11
- package/dist/next/index.js +4 -3
- package/dist/next/plugin.d.ts +1 -1
- package/dist/next/plugin.js +1 -1
- package/dist/node/index.d.ts +4 -4
- package/dist/node/index.js +1 -1
- package/dist/openai/index.d.ts +4 -4
- package/dist/openai/index.js +3 -3
- package/dist/openapi/index.d.ts +2 -2
- package/dist/{openapi-BP7YpJeF.js → openapi-Bfakk4cF.js} +1 -1
- package/dist/{openapi-document-_QSOtSKS.js → openapi-document-ZWpur4f1.js} +1 -1
- package/dist/{openapi-Dsh0MDSZ.js → openapi-g58VVrsc.js} +2 -2
- package/dist/orpc/index.d.ts +5 -5
- package/dist/orpc/index.js +2 -2
- package/dist/otel/index.d.ts +3 -3
- package/dist/{output-Didy9Ys4.js → output-D4FLF3_v.js} +1 -1
- package/dist/{ownership-CG5_N8b5.js → ownership-DvmaGcup.js} +13 -9
- package/dist/{parse-local-manifest-B92rFWnk.d.ts → parse-local-manifest-AJWs3pkW.d.ts} +1 -1
- package/dist/pdp/index.d.ts +3 -3
- package/dist/pdp/index.js +1 -1
- package/dist/{permdock-CJPIwU1T.js → permdock-JM9TKevZ.js} +14 -14
- package/dist/{permdock-BShHM8OJ.d.ts → permdock-V86uejcm.d.ts} +2 -2
- package/dist/{permissions-wEkTVr_I.js → permissions-xPyAmuXi.js} +1 -1
- package/dist/{pipeline-B4iyaOK7.js → pipeline-DCERGTTY.js} +2 -2
- package/dist/{plugin-DQJuZVl1.d.ts → plugin-BnvEp5tS.d.ts} +2 -2
- package/dist/{policy-BBvhhH9X.js → policy-CZBJDcTx.js} +2 -1
- package/dist/{policy-BUtwixSN.d.ts → policy-DZORR-Fw.d.ts} +1 -1
- package/dist/{policy-hnVT4MC4.js → policy-DoHkOOTQ.js} +1 -1
- package/dist/{policy-bundle-BIDV0DZF.js → policy-bundle-CsnNAo-n.js} +3 -3
- package/dist/{policy-from-catalog-_zwn1sNj.js → policy-from-catalog-BohzTN3J.js} +3 -3
- package/dist/{policy-types-CfW4X_yX.d.ts → policy-types-BnBZvh7N.d.ts} +50 -1
- package/dist/{postgrest-PQ3zAOD2.d.ts → postgrest-BG0ipED3.d.ts} +9 -2
- package/dist/{powersync-_2ElzOhQ.js → powersync-CTKfjnPT.js} +12 -12
- package/dist/{powersync-D7YfMHke.js → powersync-Cz3MUw6R.js} +1 -1
- package/dist/{powersync-DUvN9v5a.js → powersync-Dbpn-n0o.js} +1 -1
- package/dist/prisma/index.d.ts +2 -2
- package/dist/{protected-action-BPN0NaRb.js → protected-action-DDYvU-9Z.js} +1 -1
- package/dist/{protected-action-DhCQ4bSe.d.ts → protected-action-aGL_gT4j.d.ts} +5 -5
- package/dist/{provider-D1vlNPWo.js → provider-BwqzED5h.js} +100 -52
- package/dist/{provider-1xqxLVEz.js → provider-NQwLSlgb.js} +2 -2
- package/dist/{provider-CMgFAGf8.d.ts → provider-W8KwlWJU.d.ts} +1 -1
- package/dist/{provider-store-Cf8HRNtb.js → provider-store-BizF6jyu.js} +2 -2
- package/dist/{provider-with-cpL9vRjC.js → provider-with-DtBgCCV_.js} +1 -1
- package/dist/{prune-config-5vtQpiLk.js → prune-config--x-cEF8G.js} +6 -6
- package/dist/{pull-BnxZmo3f.js → pull-BQELP7aV.js} +2 -2
- package/dist/pull-C_ZiPZ5X.js +1 -0
- package/dist/{push-Bu0uCkJg.js → push-D5so0ptb.js} +2 -2
- package/dist/{pushed-policy-DcvO8NXy.d.ts → pushed-policy-CQaXRDe3.d.ts} +1 -1
- package/dist/{pushed-policy-DSjSWEAl.js → pushed-policy-dm_hFstN.js} +1 -1
- package/dist/{quote-BKrTBbcH.js → quote-LNaBdCGA.js} +1 -1
- package/dist/{rbac-CwcucZPx.js → rbac-BRMnQ9Rl.js} +5 -4
- package/dist/react/index.d.ts +6 -6
- package/dist/react/index.js +3 -3
- package/dist/react/lazy.d.ts +6 -6
- package/dist/react/lazy.js +3 -3
- package/dist/react/provider-client-lazy.d.ts +1 -1
- package/dist/react/provider-client-lazy.js +1 -1
- package/dist/react/provider-client.d.ts +1 -1
- package/dist/react/provider-client.js +1 -1
- package/dist/react-native/index.d.ts +8 -8
- package/dist/react-native/index.js +5 -5
- package/dist/read-memberships-DVBitJZG.js +164 -0
- package/dist/{rename-CLoDRrbc.js → rename-BjP2CFUY.js} +5 -5
- package/dist/replay-Dg5-l7xu.d.ts +3 -0
- package/dist/report-DF0zUNut.js +1 -0
- package/dist/{report-BI_hek_d.js → report-XdCm1y_J.js} +76 -6
- package/dist/{request-context-BNVY3kZ1.js → request-context-CqqdiVp4.js} +1 -1
- package/dist/resend/index.d.ts +4 -4
- package/dist/{resolve-config-9NYYVc30.js → resolve-config-Cu_mE2wt.js} +1 -1
- package/dist/{resolve-names-CTji5IPe.js → resolve-names-xBg9s2IJ.js} +7 -6
- package/dist/{resolver-CuIY8aFD.js → resolver-C_a-bddD.js} +99 -15
- package/dist/{rls-UY6p6ztg.js → rls-BzCz7ZV0.js} +55 -3
- package/dist/{rls-files-CDZdTh8v.js → rls-files-Bu0O7cZ6.js} +1 -1
- package/dist/{rls-options-BgD-KZkm.d.ts → rls-options-f1wRhXSG.d.ts} +1 -1
- package/dist/{rls-BPHCyA5v.js → rls-rk-QH4fc.js} +22 -12
- package/dist/{rpc-D7G7IJDa.js → rpc-BQPa7tLP.js} +1 -1
- package/dist/{rpc-COnquydd.d.ts → rpc-DyCWVn6C.d.ts} +1 -1
- package/dist/run-BvtApZDp.js +1 -0
- package/dist/{run-C3ztA88m.js → run-DTz-e3Od.js} +3 -3
- package/dist/{run-ticket-Mmor5sYW.d.ts → run-ticket-mVPqm6M6.d.ts} +2 -2
- package/dist/{saas-DcqUkynn.js → saas-DSeazNrN.js} +3 -3
- package/dist/{scan-m5m1M6Qn.js → scan-Cn79IAJs.js} +1 -1
- package/dist/{schema-BpGuLrwk.js → schema-CbzVUpWv.js} +1 -1
- package/dist/scim/index.d.ts +1 -1
- package/dist/seeds/index.d.ts +1 -1
- package/dist/{seeds-Cih1ztkf.d.ts → seeds-DLjPbhvM.d.ts} +1 -1
- package/dist/server/index.d.ts +11 -11
- package/dist/server/index.js +1 -1
- package/dist/{server-types-C2XX60aF.d.ts → server-types-BlMijUtb.d.ts} +8 -8
- package/dist/share-key-claims-CZGAeVqa.js +28 -0
- package/dist/{shared-C6_T7QUo.js → shared-DnVY767H.js} +2 -1
- package/dist/{sink-BQ_6K81r.d.ts → sink-DhrVLPSJ.d.ts} +2 -2
- package/dist/{size-l1pDHE2z.js → size-CY6rK6l9.js} +3 -3
- package/dist/{skills-BytzDi34.js → skills-BKrN1qej.js} +1 -1
- package/dist/{skills-CzhnDo-C.js → skills-oZ8Ng2e7.js} +1 -1
- package/dist/{snapshot-Ty0uk9wZ.js → snapshot-Dzi4LR6n.js} +8 -1
- package/dist/{snapshot-cache-DGvLQW0-.d.ts → snapshot-cache-CVYqOThu.d.ts} +1 -1
- package/dist/{snapshot-compact-yXFxZLPo.js → snapshot-compact-BWMLnIXK.js} +35 -4
- package/dist/{snapshot-evaluate-DSNj2rhV.js → snapshot-evaluate-C382Z1mQ.js} +1 -1
- package/dist/{snapshot-reads-BnAHiuoa.js → snapshot-reads-JxcUSUfW.js} +2 -2
- package/dist/{snapshot-size-DNY1MTsV.js → snapshot-size-D6ixbYvH.js} +1 -1
- package/dist/{snapshot-size-2fkXbCkP.js → snapshot-size-NklqBKcV.js} +1 -1
- package/dist/solid/index.d.ts +5 -5
- package/dist/solid/index.js +2 -2
- package/dist/solid-start/index.d.ts +4 -4
- package/dist/solid-start/index.js +2 -2
- package/dist/{sources-D5n28164.d.ts → sources-Bq7k7g34.d.ts} +7 -2
- package/dist/{sources-DnjJPGfb.js → sources-C6Id63F8.js} +2 -1
- package/dist/{src-HRYn4UFj.js → src-BXDohWNO.js} +154 -11
- package/dist/ssf/index.d.ts +3 -3
- package/dist/{standard-webhooks-Bnnrqa6d.d.ts → standard-webhooks-D6SPYjSQ.d.ts} +2 -2
- package/dist/{store-core-BdFcruPm.d.ts → store-core-Bq7Qc9QM.d.ts} +4 -4
- package/dist/{store-options-DpCQo0vB.js → store-options-DgOuhUSn.js} +4 -4
- package/dist/{stores-D6MIjN_-.d.ts → stores-Dn7TpQFa.d.ts} +5 -5
- package/dist/{stores-KpBCaY6c.js → stores-jgDndNHa.js} +1 -1
- package/dist/{subject-CrldGifz.js → subject-B7p94Y0s.js} +1 -1
- package/dist/{subject-cache-CnJcz2K_.d.ts → subject-cache-UKUgQCEX.d.ts} +3 -1
- package/dist/supabase/index.d.ts +36 -9
- package/dist/supabase/index.js +8 -7
- package/dist/supabase/middleware.d.ts +5 -5
- package/dist/supabase/middleware.js +4 -4
- package/dist/{supabase-CAswAUeb.js → supabase-BNPS-Gr1.js} +15 -1
- package/dist/{supabase-kWQlkrHw.js → supabase-DrazwRER.js} +14 -7
- package/dist/supabase-hook-D0Yzbl19.js +2 -0
- package/dist/{supabase-hook-C0LIaT7b.js → supabase-hook-t1HnQf8U.js} +11 -185
- package/dist/{supabase-schemas-BUFeyErz.js → supabase-schemas-_ubYYw9i.js} +10 -9
- package/dist/svelte/index.d.ts +5 -5
- package/dist/svelte/index.js +5 -3
- package/dist/svelte/runtime.d.ts +3 -3
- package/dist/svelte/runtime.js +1 -1
- package/dist/svelte/source.d.ts +5 -5
- package/dist/svelte/source.js +2 -2
- package/dist/sveltekit/index.d.ts +4 -4
- package/dist/sveltekit/index.js +1 -1
- package/dist/table-reads-B7z40Yu-.js +766 -0
- package/dist/table-reads-Ci-ZVo5m.js +1 -0
- package/dist/{tables-sLA1CpuN.js → tables-Bxmf2beb.js} +108 -11
- package/dist/tanstack-start/index.d.ts +4 -4
- package/dist/tanstack-start/index.js +1 -1
- package/dist/tenant-check-DW0kbH-a.js +105 -0
- package/dist/terminal/index.d.ts +5 -5
- package/dist/terminal/index.js +3 -3
- package/dist/testing/core.d.ts +1 -1
- package/dist/testing/core.js +1 -1
- package/dist/testing/fixtures/index.d.ts +4 -4
- package/dist/testing/fixtures/index.js +41 -17
- package/dist/testing/index.d.ts +23 -23
- package/dist/testing/index.js +13 -13
- package/dist/testing/saas/index.d.ts +3 -3
- package/dist/testing/saas/index.js +2 -2
- package/dist/testing/saas/permissions.js +1 -1
- package/dist/trpc/index.d.ts +5 -5
- package/dist/trpc/index.js +2 -2
- package/dist/{type-helpers-CUmJFGV6.d.ts → type-helpers-CVN-p62O.d.ts} +1 -1
- package/dist/{types-vKKndyxx.d.ts → types-5cvjmHTG.d.ts} +1 -1
- package/dist/{types-DwoRXDvN.d.ts → types-BMKDvcXc.d.ts} +2 -2
- package/dist/{types-CIzXPPV-.d.ts → types-B_I8TBA9.d.ts} +2 -2
- package/dist/{types-h9W3CNC_.d.ts → types-BmTW35E5.d.ts} +4 -4
- package/dist/{types-BhBfMdQ5.d.ts → types-CDkJNA3a.d.ts} +3 -3
- package/dist/{types-euUv1wsO.d.ts → types-CgaGxF5q.d.ts} +1 -1
- package/dist/{types-BsRf5rKk.d.ts → types-CrUguLsE.d.ts} +2 -2
- package/dist/{types-BRECeQ2n.d.ts → types-DNOJRhyn.d.ts} +3 -3
- package/dist/{types-BKnUwgvx.d.ts → types-Dl2jRkyq.d.ts} +4 -4
- package/dist/{types-config-BiMM_zJ-.d.ts → types-config-CyawIkMF.d.ts} +2 -2
- package/dist/{types-CjZscT16.d.ts → types-gp1w86cV.d.ts} +4 -4
- package/dist/{types-run-N2ffLN_Z.d.ts → types-run-ByHuYUen.d.ts} +1 -1
- package/dist/unplugin/index.d.ts +1 -1
- package/dist/unplugin/index.js +1 -1
- package/dist/{usage-DT6QK86a.js → usage-B8ca_Nj_.js} +2 -2
- package/dist/usage-CKTsomEq.js +1 -0
- package/dist/{usage-Dcbg6zu6.js → usage-Do7LQ4i4.js} +1 -1
- package/dist/{validation-error-P4Z9HUuP.d.ts → validation-error-BKgVVMc1.d.ts} +1 -1
- package/dist/{verify-DNERav8K.js → verify-ZojGAC3f.js} +12 -12
- package/dist/{version-cache-BzK8dwJy.js → version-cache-Ccrfu2A4.js} +6 -1
- package/dist/vue/index.d.ts +5 -5
- package/dist/vue/index.js +2 -2
- package/dist/{waiter-BqUxSRxq.d.ts → waiter-Bov7Cig6.d.ts} +2 -2
- package/dist/warm-BKD3FN6k.d.ts +16 -0
- package/dist/warm-BZ0ZwSmO.js +32 -0
- package/dist/{watch-fldErlRf.js → watch-D-5ztqN8.js} +1 -1
- package/dist/{watch-BsQ4n3NV.js → watch-EzX_aG73.js} +2 -2
- package/dist/watch-J1PfGMfb.js +1 -0
- package/dist/webmcp/index.d.ts +1 -1
- package/dist/webmcp/index.js +1 -1
- package/dist/{who-can-CGVpM3fZ.js → who-can-CIgYpEvy.js} +1 -1
- package/dist/workflow/index.d.ts +3 -3
- package/dist/workflow/index.js +1 -1
- package/dist/workflow-sdk/index.d.ts +4 -4
- package/dist/{wrap-D8WtzrB7.d.ts → wrap-CaAA3ubO.d.ts} +2 -2
- package/package.json +11 -11
- package/schemas/snapshot-v2.json +20 -0
- package/schemas/supabase-claims-v1.json +48 -2
- package/schemas/supabase-manifest-v1.json +137 -19
- package/skills/permdock-data/references/queries-and-rls.md +1 -1
- package/dist/bundle-size-DwZ4e1gu.js +0 -1
- package/dist/claims-size-B6j0Ff4Q.js +0 -1
- package/dist/evaluator-COmATWCr.js +0 -2
- package/dist/gen-CkUEZ5Z6.js +0 -1
- package/dist/platform-CSxTsLsr.js +0 -35
- package/dist/pull-CGncYZNZ.js +0 -1
- package/dist/read-memberships-BkePIa1F.js +0 -63
- package/dist/replay-BCOZifwx.d.ts +0 -3
- package/dist/report-BevPHMy6.js +0 -1
- package/dist/run-3ySqmufy.js +0 -1
- package/dist/supabase-hook-DXGg5bNn.js +0 -2
- package/dist/tenant-check-gL2miiaS.js +0 -31
- package/dist/usage-DdOFc5xq.js +0 -1
- package/dist/watch-eay1PztJ.js +0 -1
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
import { r as isRecord } from "./compact-C4LFuqbW.js";
|
|
2
|
+
import { d as scopeList } from "./scopes-B-KX9EI8.js";
|
|
3
|
+
import { n as parseSupabaseManifest } from "./manifest-CIWOmdlP.js";
|
|
4
|
+
import { i as readJsonFile } from "./files-DAR51W3J.js";
|
|
5
|
+
import { t as MANIFEST_FILE } from "./manifest-json-DMaBWmcG.js";
|
|
6
|
+
import { i as loadConfiguredPolicy } from "./load-m7jmit3y.js";
|
|
7
|
+
import { a as parseSqlFile, c as readPolicy, d as sqlCalls, f as stringValues, t as SqlSyntaxError } from "./ast-Dnm2TOHN.js";
|
|
8
|
+
import { i as taggedAccessPolicies } from "./bsb-access-Bcw6GrQm.js";
|
|
9
|
+
import { a as droppedPolicy, s as reportFiles, u as isPlatformSchema } from "./report-XdCm1y_J.js";
|
|
10
|
+
import { a as tryKeyReasons, n as tenantCheck, r as keyReason, t as svals } from "./tenant-check-DW0kbH-a.js";
|
|
11
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { join, relative } from "node:path";
|
|
13
|
+
// src/cli/rls/shared-functions.ts
|
|
14
|
+
/** Functions that read who is asking, so the result differs per caller. */
|
|
15
|
+
const IDENTITY_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
16
|
+
"current_setting",
|
|
17
|
+
"current_user_id",
|
|
18
|
+
"permdock_user_id",
|
|
19
|
+
"permdock_subject",
|
|
20
|
+
"uid",
|
|
21
|
+
"jwt",
|
|
22
|
+
"role",
|
|
23
|
+
"email"
|
|
24
|
+
]);
|
|
25
|
+
/** `SQLValueFunction` ops that name the caller. */
|
|
26
|
+
const IDENTITY_VALUES = /* @__PURE__ */ new Set([
|
|
27
|
+
"SVFOP_CURRENT_USER",
|
|
28
|
+
"SVFOP_SESSION_USER",
|
|
29
|
+
"SVFOP_USER",
|
|
30
|
+
"SVFOP_CURRENT_ROLE"
|
|
31
|
+
]);
|
|
32
|
+
const DEFAULT_SCHEMA = "public";
|
|
33
|
+
function defElems(node) {
|
|
34
|
+
const options = Array.isArray(node["options"]) ? node["options"] : [];
|
|
35
|
+
const found = {};
|
|
36
|
+
for (const option of options) {
|
|
37
|
+
const def = isRecord(option) ? option["DefElem"] : void 0;
|
|
38
|
+
if (isRecord(def) && typeof def["defname"] === "string") found[def["defname"]] = def["arg"];
|
|
39
|
+
}
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
function sval(arg) {
|
|
43
|
+
const text = isRecord(arg) ? arg["String"] : void 0;
|
|
44
|
+
return isRecord(text) && typeof text["sval"] === "string" ? text["sval"].toLowerCase() : void 0;
|
|
45
|
+
}
|
|
46
|
+
function bodyOf(arg) {
|
|
47
|
+
const list = isRecord(arg) ? arg["List"] : void 0;
|
|
48
|
+
return stringValues(isRecord(list) ? list["items"] : []).join("");
|
|
49
|
+
}
|
|
50
|
+
/** Every value stored under `key` anywhere inside `value`. */
|
|
51
|
+
function collect(value, key) {
|
|
52
|
+
const out = [];
|
|
53
|
+
const visit = (item) => {
|
|
54
|
+
if (Array.isArray(item)) {
|
|
55
|
+
for (const child of item) visit(child);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!isRecord(item)) return;
|
|
59
|
+
for (const [name, child] of Object.entries(item)) {
|
|
60
|
+
if (name === key) out.push(child);
|
|
61
|
+
visit(child);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
visit(value);
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether `node` is a `language sql`, `security invoker`, `stable` or
|
|
69
|
+
* `immutable` function with a body libpg_query parses; `volatile` is the
|
|
70
|
+
* default, so a function that states nothing is not eligible.
|
|
71
|
+
*/
|
|
72
|
+
function definitionOf(node) {
|
|
73
|
+
const parts = stringValues(node["funcname"]);
|
|
74
|
+
const name = parts.at(-1);
|
|
75
|
+
if (name === void 0) return;
|
|
76
|
+
const schema = (parts.length > 1 ? parts[0] : DEFAULT_SCHEMA) ?? DEFAULT_SCHEMA;
|
|
77
|
+
const defs = defElems(node);
|
|
78
|
+
const security = defs["security"];
|
|
79
|
+
const definer = isRecord(security) ? isRecord(security["Boolean"]) && security["Boolean"]["boolval"] === true : false;
|
|
80
|
+
const volatility = sval(defs["volatility"]);
|
|
81
|
+
const language = sval(defs["language"]);
|
|
82
|
+
return {
|
|
83
|
+
schema: schema.toLowerCase(),
|
|
84
|
+
name: name.toLowerCase(),
|
|
85
|
+
body: bodyOf(defs["as"]),
|
|
86
|
+
header: `language ${language ?? "unstated"}, security ${definer ? "definer" : "invoker"}, ${volatility ?? "volatile"}`,
|
|
87
|
+
eligible: sval(defs["language"]) === "sql" && !definer && (volatility === "stable" || volatility === "immutable")
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The tables a body reads and the functions it calls, or why it is not shared:
|
|
92
|
+
* it reads the caller, calls a function outside `known`, or reads a relation
|
|
93
|
+
* that is not a table in `reads`.
|
|
94
|
+
*/
|
|
95
|
+
async function readsOf$1(definition, defined, reads, helperSchema) {
|
|
96
|
+
let statements;
|
|
97
|
+
try {
|
|
98
|
+
statements = await parseSqlFile(definition.body);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error instanceof SqlSyntaxError) return "the body does not parse";
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
const tables = /* @__PURE__ */ new Set();
|
|
104
|
+
const calls = /* @__PURE__ */ new Set();
|
|
105
|
+
const keys = /* @__PURE__ */ new Set();
|
|
106
|
+
for (const statement of statements) {
|
|
107
|
+
if (statement.kind !== "SelectStmt") return `the body holds a ${statement.kind}, not a select`;
|
|
108
|
+
if (collect(statement.node, "SQLValueFunction").some((value) => isRecord(value) && typeof value["op"] === "string" && IDENTITY_VALUES.has(value["op"]))) return "it reads current_user, session_user or user";
|
|
109
|
+
const ctes = new Set(collect(statement.node, "CommonTableExpr").flatMap((value) => isRecord(value) && typeof value["ctename"] === "string" ? [value["ctename"].toLowerCase()] : []));
|
|
110
|
+
for (const value of collect(statement.node, "RangeVar")) {
|
|
111
|
+
if (!isRecord(value) || typeof value["relname"] !== "string") return "it reads a relation inspect cannot name";
|
|
112
|
+
const relname = value["relname"].toLowerCase();
|
|
113
|
+
const explicit = typeof value["schemaname"] === "string" ? value["schemaname"].toLowerCase() : void 0;
|
|
114
|
+
if (explicit === void 0 && ctes.has(relname)) continue;
|
|
115
|
+
const candidates = (explicit === void 0 ? [definition.schema, DEFAULT_SCHEMA] : [explicit]).map((schema) => `${schema}.${relname}`);
|
|
116
|
+
const found = candidates.find((table) => reads.has(table));
|
|
117
|
+
if (found === void 0) return `it reads ${candidates[0] ?? relname}, which is no table the schema files create`;
|
|
118
|
+
tables.add(found);
|
|
119
|
+
}
|
|
120
|
+
for (const call of sqlCalls(statement.node)) {
|
|
121
|
+
const last = call.name.at(-1);
|
|
122
|
+
const schema = call.name.length > 1 ? call.name[0] : void 0;
|
|
123
|
+
if (last === void 0 || IDENTITY_FUNCTIONS.has(last) || schema === "auth") return `it reads the caller through ${call.name.join(".")}()`;
|
|
124
|
+
if (schema === helperSchema) {
|
|
125
|
+
const key = permissionFilterKey(call, helperSchema);
|
|
126
|
+
if (key === void 0) return `it calls the helper ${call.name.join(".")}(), which is not a permissionFilters helper`;
|
|
127
|
+
if (typeof key !== "string") return `it calls ${call.name.join(".")}() with a permission key that is not a string literal, so the key cannot join the share key`;
|
|
128
|
+
keys.add(key);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const target = (schema === void 0 ? [`${definition.schema}.${last}`, `${DEFAULT_SCHEMA}.${last}`] : [`${schema}.${last}`]).find((name) => defined.has(name));
|
|
132
|
+
if (target !== void 0) calls.add(target);
|
|
133
|
+
else if (schema !== void 0 && schema !== "pg_catalog") return `it calls ${call.name.join(".")}(), which no schema file defines`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
tables,
|
|
138
|
+
calls,
|
|
139
|
+
keys
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/** Why `definition` fails the header checks, or `undefined`. */
|
|
143
|
+
function headerReason(definition) {
|
|
144
|
+
return definition.eligible ? void 0 : `it is not language sql, security invoker and stable or immutable (${definition.header})`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* `rls.sharedFunctions`: the functions better-supabase's doctor BS430 accepts
|
|
148
|
+
* in a `share: "tenant"` fill, read from the same SQL files as `tableReads`. A
|
|
149
|
+
* function is listed when it is `language sql`, `security invoker` and `stable`
|
|
150
|
+
* or `immutable`, parses, reads the caller through neither `auth.*`,
|
|
151
|
+
* `current_user`, `current_setting` nor a helper of the `helperSchema`, calls
|
|
152
|
+
* only other listed functions or built-ins, and reads only tables that
|
|
153
|
+
* `tableReads` marks `tenant`. An overloaded name is listed when every overload
|
|
154
|
+
* qualifies. A file libpg_query rejects is skipped; the last definition of a
|
|
155
|
+
* function wins.
|
|
156
|
+
*/
|
|
157
|
+
async function sharedFunctionsOf(input) {
|
|
158
|
+
const outcomes = await analyse(input);
|
|
159
|
+
return [...outcomes.keys()].toSorted().flatMap((name) => {
|
|
160
|
+
const shared = outcomes.get(name)?.shared;
|
|
161
|
+
return shared === void 0 ? [] : [shared];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
/** `*` matches any run of characters, every other character itself. */
|
|
165
|
+
function matcher(pattern) {
|
|
166
|
+
const source = pattern.split("*").map((part) => part.replaceAll(/[.+?^${}()|[\]\\]/gu, String.raw`\$&`)).join(".*");
|
|
167
|
+
const regex = new RegExp(`^${source}$`, "u");
|
|
168
|
+
return (name) => regex.test(name);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* For each function the schema files define whose `schema.name` matches
|
|
172
|
+
* `pattern` (`public.*_payload`), a pass or every reason `sharedFunctionsOf`
|
|
173
|
+
* does not list it: a header it fails, a read of the caller, an unknown call,
|
|
174
|
+
* or the `row` table it reads with the rules that make it so.
|
|
175
|
+
*/
|
|
176
|
+
async function functionShares(input, pattern) {
|
|
177
|
+
const matches = matcher(pattern.toLowerCase());
|
|
178
|
+
const outcomes = await analyse(input);
|
|
179
|
+
return [...outcomes.keys()].filter((name) => matches(name)).toSorted().map((name) => {
|
|
180
|
+
const outcome = outcomes.get(name);
|
|
181
|
+
return {
|
|
182
|
+
function: name,
|
|
183
|
+
shared: outcome?.shared !== void 0,
|
|
184
|
+
reasons: outcome?.reasons ?? []
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
async function analyse(input) {
|
|
189
|
+
const reads = new Map(input.tableReads.map((read) => [read.table, read]));
|
|
190
|
+
const byArity = /* @__PURE__ */ new Map();
|
|
191
|
+
for (const file of reportFiles(input.cwd, input.config)) {
|
|
192
|
+
let nodes;
|
|
193
|
+
try {
|
|
194
|
+
nodes = await parseSqlFile(readFileSync(file, "utf8"));
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error instanceof SqlSyntaxError) continue;
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
for (const node of nodes) {
|
|
200
|
+
if (node.kind !== "CreateFunctionStmt") continue;
|
|
201
|
+
const definition = definitionOf(node.node);
|
|
202
|
+
if (definition === void 0) continue;
|
|
203
|
+
const params = collect(node.node["parameters"], "FunctionParameter").map((value) => isRecord(value) && isRecord(value["argType"]) ? stringValues(value["argType"]["names"]).join(".") : "").join(",");
|
|
204
|
+
byArity.set(`${definition.schema}.${definition.name}(${params})`, definition);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const defined = /* @__PURE__ */ new Map();
|
|
208
|
+
for (const definition of byArity.values()) {
|
|
209
|
+
const key = `${definition.schema}.${definition.name}`;
|
|
210
|
+
defined.set(key, [...defined.get(key) ?? [], definition]);
|
|
211
|
+
}
|
|
212
|
+
const helperSchema = input.schema.toLowerCase();
|
|
213
|
+
const analysed = /* @__PURE__ */ new Map();
|
|
214
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
215
|
+
for (const [name, overloads] of defined) {
|
|
216
|
+
const merged = [];
|
|
217
|
+
const why = [];
|
|
218
|
+
for (const definition of overloads) {
|
|
219
|
+
const found = headerReason(definition) ?? await readsOf$1(definition, defined, reads, helperSchema);
|
|
220
|
+
if (typeof found === "string") why.push(found);
|
|
221
|
+
else merged.push(found);
|
|
222
|
+
}
|
|
223
|
+
reasons.set(name, why);
|
|
224
|
+
if (why.length === 0 && merged.length > 0) analysed.set(name, {
|
|
225
|
+
tables: new Set(merged.flatMap((entry) => [...entry.tables])),
|
|
226
|
+
calls: new Set(merged.flatMap((entry) => [...entry.calls])),
|
|
227
|
+
keys: new Set(merged.flatMap((entry) => [...entry.keys]))
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
for (let changed = true; changed;) {
|
|
231
|
+
changed = false;
|
|
232
|
+
for (const [name, entry] of analysed) {
|
|
233
|
+
const gone = [...entry.calls].filter((call) => !analysed.has(call));
|
|
234
|
+
if (gone.length > 0) {
|
|
235
|
+
analysed.delete(name);
|
|
236
|
+
reasons.set(name, gone.map((call) => `it calls ${call}, which is not shared`));
|
|
237
|
+
changed = true;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const close = (name, seen) => {
|
|
242
|
+
if (seen.has(name)) return;
|
|
243
|
+
seen.add(name);
|
|
244
|
+
for (const call of analysed.get(name)?.calls ?? []) close(call, seen);
|
|
245
|
+
};
|
|
246
|
+
const outcomes = /* @__PURE__ */ new Map();
|
|
247
|
+
for (const name of defined.keys()) {
|
|
248
|
+
if (!analysed.has(name)) {
|
|
249
|
+
outcomes.set(name, { reasons: reasons.get(name) ?? [] });
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
const reached = /* @__PURE__ */ new Set();
|
|
253
|
+
close(name, reached);
|
|
254
|
+
const tables = /* @__PURE__ */ new Set();
|
|
255
|
+
const filterKeys = /* @__PURE__ */ new Set();
|
|
256
|
+
for (const member of reached) {
|
|
257
|
+
const entry = analysed.get(member);
|
|
258
|
+
for (const table of entry?.tables ?? []) tables.add(table);
|
|
259
|
+
for (const key of entry?.keys ?? []) filterKeys.add(key);
|
|
260
|
+
}
|
|
261
|
+
const rows = [...tables].toSorted().filter((table) => reads.get(table)?.share !== "tenant");
|
|
262
|
+
if (tables.size === 0 || rows.length > 0) {
|
|
263
|
+
outcomes.set(name, { reasons: tables.size === 0 ? ["it reads no table"] : rows.map((table) => rowReason(table, reads.get(table))) });
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
outcomes.set(name, {
|
|
267
|
+
reasons: [],
|
|
268
|
+
shared: {
|
|
269
|
+
function: name,
|
|
270
|
+
tables: [...tables].toSorted(),
|
|
271
|
+
permissions: [.../* @__PURE__ */ new Set([...[...tables].flatMap((table) => reads.get(table)?.permissions ?? []), ...filterKeys])].toSorted()
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return outcomes;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* The string literal a call passes to a `permissionFilters` helper, `false`
|
|
279
|
+
* when the helper is one but the key is not a string literal, or `undefined`
|
|
280
|
+
* when the call is not such a helper. Better-supabase 0.87 adds only a string
|
|
281
|
+
* literal to the share key.
|
|
282
|
+
*/
|
|
283
|
+
function permissionFilterKey(call, helperSchema) {
|
|
284
|
+
const name = call.name.at(-1);
|
|
285
|
+
if ((call.name.length > 1 ? call.name[0] : void 0) !== helperSchema || name === void 0 || !name.endsWith("_has_active") && !name.endsWith("_permission_keys_active")) return;
|
|
286
|
+
const [first] = Array.isArray(call.node["args"]) ? call.node["args"] : [];
|
|
287
|
+
const cast = isRecord(first) ? first["TypeCast"] : void 0;
|
|
288
|
+
const inner = isRecord(cast) && isRecord(cast["arg"]) ? cast["arg"] : first;
|
|
289
|
+
const constant = isRecord(inner) ? inner["A_Const"] : void 0;
|
|
290
|
+
const value = isRecord(constant) && isRecord(constant["sval"]) ? constant["sval"]["sval"] : void 0;
|
|
291
|
+
return typeof value === "string" ? value : false;
|
|
292
|
+
}
|
|
293
|
+
/** The `row` table a function reads, under which rule and why. */
|
|
294
|
+
function rowReason(table, read) {
|
|
295
|
+
return `it reads ${table}, a row table (rule ${read?.rules?.join(", ") ?? "unknown"})${read?.reason === void 0 ? "" : `: ${read.reason}`}`;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* `rls.tenantPureHelpers`: the helpers of the root scope that answer from the
|
|
299
|
+
* caller's grants of the passed key in the passed tenant and nothing else, so
|
|
300
|
+
* two callers with an equal `grantFingerprint` for the key get one answer.
|
|
301
|
+
*
|
|
302
|
+
* - `permdock_<root>_has(p_grant, p_tenant)` tests one grant key in one tenant.
|
|
303
|
+
* - `permitted_<root>_permission_keys(p_id, p_keys)` lists which of `p_keys` the
|
|
304
|
+
* caller holds on one tenant.
|
|
305
|
+
*
|
|
306
|
+
* Every other helper reads grants outside the tenant (`permitted_<root>_ids`,
|
|
307
|
+
* `permitted_<root>_ids_by_permission`, `permitted_<root>_id_array`,
|
|
308
|
+
* `permdock_has`), a decision of one row (`permitted_<resource>_rows`) or the
|
|
309
|
+
* caller (`permdock_subject`, `permdock_bootstrap_permissions`), and is left
|
|
310
|
+
* out. `rls generate` writes both for every scope, so the manifest names them
|
|
311
|
+
* whenever it has an `rls` block.
|
|
312
|
+
*/
|
|
313
|
+
function tenantPureHelpersOf(manifest) {
|
|
314
|
+
const root = manifest.rls.scopes[0]?.name;
|
|
315
|
+
if (root === void 0) return [];
|
|
316
|
+
const prefix = `permitted_${root}`;
|
|
317
|
+
return [{
|
|
318
|
+
name: `permdock_${root}_has`,
|
|
319
|
+
keyArgument: "p_grant",
|
|
320
|
+
keyPosition: 0,
|
|
321
|
+
tenantArgument: "p_tenant"
|
|
322
|
+
}, {
|
|
323
|
+
name: `${prefix}_permission_keys`,
|
|
324
|
+
keyArgument: "p_keys",
|
|
325
|
+
keyPosition: 1,
|
|
326
|
+
tenantArgument: "p_id"
|
|
327
|
+
}].map((candidate) => ({
|
|
328
|
+
...candidate,
|
|
329
|
+
name: `${manifest.rls.schema}.${candidate.name}`
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* `rls.permissionFilters`: the one-argument forms of the tenant-pure helpers.
|
|
334
|
+
* Each reads the tenant from the token, so a call with a literal key depends
|
|
335
|
+
* only on the caller's grants of that key in the active tenant. The
|
|
336
|
+
* two-argument helpers stay in `tenantPureHelpers` and are never filters:
|
|
337
|
+
* better-supabase 0.87 checks the key argument only.
|
|
338
|
+
*/
|
|
339
|
+
function permissionFiltersOf(manifest) {
|
|
340
|
+
const root = manifest.rls.scopes[0]?.name;
|
|
341
|
+
if (root === void 0) return [];
|
|
342
|
+
const schema = manifest.rls.schema;
|
|
343
|
+
return [{
|
|
344
|
+
name: `${schema}.permdock_${root}_has_active`,
|
|
345
|
+
keyPosition: 0
|
|
346
|
+
}, {
|
|
347
|
+
name: `${schema}.permitted_${root}_permission_keys_active`,
|
|
348
|
+
keyPosition: 0
|
|
349
|
+
}];
|
|
350
|
+
}
|
|
351
|
+
// src/cli/rls/table-reasons.ts
|
|
352
|
+
/** `policy <name>` with the file that defines it. */
|
|
353
|
+
function policyLabel(policy) {
|
|
354
|
+
return `policy ${policy.name}${policy.file === void 0 ? "" : ` in ${policy.file}`}`;
|
|
355
|
+
}
|
|
356
|
+
/** The column names an expression reads, in order of first appearance. */
|
|
357
|
+
function columnsOf(expr) {
|
|
358
|
+
const found = /* @__PURE__ */ new Set();
|
|
359
|
+
const visit = (value) => {
|
|
360
|
+
if (Array.isArray(value)) {
|
|
361
|
+
for (const item of value) visit(item);
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (!isRecord(value)) return;
|
|
365
|
+
for (const [key, child] of Object.entries(value)) if (key === "ColumnRef" && isRecord(child)) found.add(svals(child["fields"]).join("."));
|
|
366
|
+
else visit(child);
|
|
367
|
+
};
|
|
368
|
+
visit(expr);
|
|
369
|
+
return [...found].filter((name) => name !== "");
|
|
370
|
+
}
|
|
371
|
+
const list = (items) => items.length === 0 ? "none" : items.join(", ");
|
|
372
|
+
/** The function calls and columns of a policy's `using`, as one phrase. */
|
|
373
|
+
function readsOf(policy) {
|
|
374
|
+
const calls = [...new Set(sqlCalls(policy.using).map((call) => `${call.name.join(".")}()`))];
|
|
375
|
+
const columns = columnsOf(policy.using);
|
|
376
|
+
return `calls ${list(calls)} and reads ${columns.length === 0 ? "no column" : `column ${list(columns)}`}`;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Whether a policy file is a migration, which `codemod bsb-access-tags` leaves
|
|
380
|
+
* alone.
|
|
381
|
+
*/
|
|
382
|
+
function inMigration(policy) {
|
|
383
|
+
return policy.file?.split(/[/\\]/u).includes("migrations") === true;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* What keeps the codemod `bsb-access-tags` from moving a `form` select policy
|
|
387
|
+
* to an `@bsb access` tag: the policy, the tenant column or the migration. The
|
|
388
|
+
* codemod rewrites only declarative schema files, and only a policy that is
|
|
389
|
+
* `<column> in (select <helper>('<key>'))` for `authenticated` alone, with no
|
|
390
|
+
* other policy on the same operation and one tenant column on the table.
|
|
391
|
+
*/
|
|
392
|
+
function formBlockers(policy, others, helpers) {
|
|
393
|
+
const label = policyLabel(policy);
|
|
394
|
+
const blockers = [];
|
|
395
|
+
if (inMigration(policy)) blockers.push(`${label} is a migration, which the codemod does not rewrite: move the policy to the schema files`);
|
|
396
|
+
if (policy.roles.length !== 1 || policy.roles[0] !== "authenticated") blockers.push(`${label} applies to ${list(policy.roles)}, not authenticated alone`);
|
|
397
|
+
if (policy.command === "all") blockers.push(`${label} covers all commands: split it into one policy per command`);
|
|
398
|
+
if (tenantCheck(policy.using, helpers.plain) === void 0) blockers.push(`${label} uses ${helpers.plain} inside a larger expression, not as "<column> in (select ${helpers.plain}('<key>'))"`);
|
|
399
|
+
const selects = others.filter((other) => other !== policy && (other.command === "select" || other.command === "all"));
|
|
400
|
+
if (selects.length > 0) {
|
|
401
|
+
const named = selects.map((other) => `${other.permissive ? "" : "restrictive "}${other.name}`);
|
|
402
|
+
blockers.push(`${named.join(", ")} also ${selects.length === 1 ? "applies" : "apply"} to select on the table`);
|
|
403
|
+
}
|
|
404
|
+
const columns = /* @__PURE__ */ new Map();
|
|
405
|
+
for (const other of [policy, ...others]) {
|
|
406
|
+
const found = tenantCheck(other.using, helpers.plain) ?? tenantCheck(other.check, helpers.plain);
|
|
407
|
+
if (found !== void 0 && !columns.has(found.column)) columns.set(found.column, other.name);
|
|
408
|
+
}
|
|
409
|
+
if (columns.size > 1) blockers.push(`the tenant column differs between policies: ${[...columns].map(([column, name]) => `${name} uses ${column}`).join(", ")}`);
|
|
410
|
+
return blockers;
|
|
411
|
+
}
|
|
412
|
+
/** Why a permissive select policy that is no tenant form makes its table `row`. */
|
|
413
|
+
function ruleReason(rule, policy, helpers) {
|
|
414
|
+
const label = policyLabel(policy);
|
|
415
|
+
switch (rule) {
|
|
416
|
+
case "owner": return `${label} is an owner rule: it ${readsOf(policy)}, so a row is read by the user it names, not by a tenant grant`;
|
|
417
|
+
case "condition": return policy.using === void 0 ? `${label} has no using clause` : `${label} is a row condition: it ${readsOf(policy)}, which no tenant check of ${helpers.byPermission} covers`;
|
|
418
|
+
case "follows":
|
|
419
|
+
case "via":
|
|
420
|
+
case "walk": return `${label} resolves rows through a ${rule} helper: it ${readsOf(policy)}`;
|
|
421
|
+
default: return `${label} is a ${rule} rule`;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/** A restrictive select policy that reads a column of the row. */
|
|
425
|
+
function restrictiveReason(policy) {
|
|
426
|
+
return `restrictive ${policyLabel(policy)} reads ${columnsOf(policy.using).length === 0 ? "the row" : `column ${list(columnsOf(policy.using))}`}, so the rows it hides differ per row, not per tenant`;
|
|
427
|
+
}
|
|
428
|
+
/** Why a table with no readable policy is `unknown`. */
|
|
429
|
+
function unknownReason(state, policies) {
|
|
430
|
+
switch (state) {
|
|
431
|
+
case "no-facts": return "no policy or enable row level security statement for the table in the files inspect read; the table may exist only in a file libpg_query rejects, or be created by a function";
|
|
432
|
+
case "no-rls": return "no alter table ... enable row level security statement for the table in the files inspect read";
|
|
433
|
+
case "no-select": {
|
|
434
|
+
const named = policies.map((policy) => policy.name);
|
|
435
|
+
return `row level security is on and no permissive select policy applies to authenticated or public${named.length === 0 ? "" : ` (policies: ${list(named)})`}, so the table is not read through PostgREST by a signed-in role; inspect does not read grants, so a table grant is not checked`;
|
|
436
|
+
}
|
|
437
|
+
default: throw new Error(state);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
// src/cli/rls/table-reads.ts
|
|
441
|
+
/** better-supabase's own tables, which its block SQL owns. */
|
|
442
|
+
const LIBRARY_SCHEMAS = /* @__PURE__ */ new Set(["better_supabase"]);
|
|
443
|
+
function relationName(relation) {
|
|
444
|
+
if (!isRecord(relation) || typeof relation["relname"] !== "string") return;
|
|
445
|
+
return `${typeof relation["schemaname"] === "string" ? relation["schemaname"] : "public"}.${relation["relname"]}`.toLowerCase();
|
|
446
|
+
}
|
|
447
|
+
/** The qualified tables a `drop table` statement removes, lower case. */
|
|
448
|
+
function droppedTables(node) {
|
|
449
|
+
const objects = node["objects"];
|
|
450
|
+
if (node["removeType"] !== "OBJECT_TABLE" || !Array.isArray(objects)) return [];
|
|
451
|
+
return objects.flatMap((object) => {
|
|
452
|
+
const list = isRecord(object) ? object["List"] : void 0;
|
|
453
|
+
const items = isRecord(list) ? list["items"] : void 0;
|
|
454
|
+
const parts = stringValues(items);
|
|
455
|
+
const name = parts.at(-1);
|
|
456
|
+
return name === void 0 ? [] : [`${parts.length > 1 ? parts.at(-2) : "public"}.${name}`.toLowerCase()];
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
/** `alter table <from> rename to <to>`: the two qualified names, lower case. */
|
|
460
|
+
function renamedTable(node) {
|
|
461
|
+
const from = relationName(node["relation"]);
|
|
462
|
+
const name = node["newname"];
|
|
463
|
+
if (node["renameType"] !== "OBJECT_TABLE" || from === void 0 || typeof name !== "string") return;
|
|
464
|
+
return {
|
|
465
|
+
from,
|
|
466
|
+
to: `${from.slice(0, from.indexOf("."))}.${name.toLowerCase()}`
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function renameTable(created, facts, renamed) {
|
|
470
|
+
if (renamed === void 0) return;
|
|
471
|
+
created.delete(renamed.from);
|
|
472
|
+
created.add(renamed.to);
|
|
473
|
+
const moved = facts.get(renamed.from);
|
|
474
|
+
facts.delete(renamed.from);
|
|
475
|
+
if (moved !== void 0) facts.set(renamed.to, moved);
|
|
476
|
+
}
|
|
477
|
+
function enablesRls(node) {
|
|
478
|
+
return (Array.isArray(node["cmds"]) ? node["cmds"] : []).some((cmd) => {
|
|
479
|
+
const alter = isRecord(cmd) ? cmd["AlterTableCmd"] : void 0;
|
|
480
|
+
return isRecord(alter) && alter["subtype"] === "AT_EnableRowSecurity";
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
function readsColumn(expr) {
|
|
484
|
+
if (Array.isArray(expr)) return expr.some((item) => readsColumn(item));
|
|
485
|
+
if (!isRecord(expr)) return false;
|
|
486
|
+
return Object.entries(expr).some(([key, child]) => key === "ColumnRef" || readsColumn(child));
|
|
487
|
+
}
|
|
488
|
+
function appliesToSelect(policy) {
|
|
489
|
+
return (policy.command === "select" || policy.command === "all") && policy.roles.some((role) => role === "authenticated" || role === "public");
|
|
490
|
+
}
|
|
491
|
+
/** The rule a permissive select policy that is not the tenant form breaks. */
|
|
492
|
+
function ruleOf(policy, plainHelper) {
|
|
493
|
+
const names = sqlCalls(policy.using).map((call) => call.name.join("."));
|
|
494
|
+
if (names.length > 0 && names.every((name) => name === plainHelper)) return "form";
|
|
495
|
+
if (names.some((name) => name.includes("follows"))) return "follows";
|
|
496
|
+
if (names.some((name) => name.includes("_via"))) return "via";
|
|
497
|
+
if (names.some((name) => name.includes("walk"))) return "walk";
|
|
498
|
+
if (names.some((name) => name === "auth.uid" || name.endsWith("permdock_user_id"))) return "owner";
|
|
499
|
+
return policy.using === void 0 ? "unknown" : "condition";
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* The tenant checks a permissive policy ORs in: the expression itself or an
|
|
503
|
+
* argument of its top-level `or`. Other disjuncts only add rows.
|
|
504
|
+
*/
|
|
505
|
+
function tenantDisjuncts(expr, helper) {
|
|
506
|
+
const bool = isRecord(expr) ? expr["BoolExpr"] : void 0;
|
|
507
|
+
return (isRecord(bool) && bool["boolop"] === "OR_EXPR" && Array.isArray(bool["args"]) ? bool["args"] : [expr]).flatMap((arg) => {
|
|
508
|
+
const check = tenantCheck(arg, helper);
|
|
509
|
+
return check === void 0 ? [] : [check];
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
function keysOf(expr, helper) {
|
|
513
|
+
return sqlCalls(expr).flatMap((call) => {
|
|
514
|
+
if (call.name.join(".") !== helper) return [];
|
|
515
|
+
const args = Array.isArray(call.node["args"]) ? call.node["args"] : [];
|
|
516
|
+
const [first] = args;
|
|
517
|
+
const cast = isRecord(first) ? first["TypeCast"] : void 0;
|
|
518
|
+
const inner = isRecord(cast) && isRecord(cast["arg"]) ? cast["arg"] : first;
|
|
519
|
+
const constant = args.length === 1 && isRecord(inner) ? inner["A_Const"] : void 0;
|
|
520
|
+
const value = isRecord(constant) && isRecord(constant["sval"]) ? constant["sval"]["sval"] : void 0;
|
|
521
|
+
return typeof value === "string" ? [value] : [];
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
function readOf(table, facts, helpers, fieldTables, reasons) {
|
|
525
|
+
if (facts === void 0 || !facts.rls) return {
|
|
526
|
+
table,
|
|
527
|
+
share: "row",
|
|
528
|
+
rules: ["unknown"],
|
|
529
|
+
reason: unknownReason(facts === void 0 ? "no-facts" : "no-rls", facts === void 0 ? [] : [...facts.policies.values()])
|
|
530
|
+
};
|
|
531
|
+
const all = [...facts.policies.values()];
|
|
532
|
+
const selects = all.filter(appliesToSelect);
|
|
533
|
+
const permissive = selects.filter((policy) => policy.permissive);
|
|
534
|
+
const rules = /* @__PURE__ */ new Set();
|
|
535
|
+
const columns = /* @__PURE__ */ new Map();
|
|
536
|
+
const keys = /* @__PURE__ */ new Set();
|
|
537
|
+
const formKeys = /* @__PURE__ */ new Set();
|
|
538
|
+
const formPolicies = [];
|
|
539
|
+
const parts = [];
|
|
540
|
+
const widenKeys = /* @__PURE__ */ new Set();
|
|
541
|
+
const widenColumns = /* @__PURE__ */ new Set();
|
|
542
|
+
const stale = [];
|
|
543
|
+
const hasTag = all.some((p) => p.tagged !== void 0);
|
|
544
|
+
if (fieldTables.has(table)) {
|
|
545
|
+
rules.add("fields");
|
|
546
|
+
parts.push("the table has a field view, which reads rows per field grant");
|
|
547
|
+
}
|
|
548
|
+
if (permissive.length === 0) {
|
|
549
|
+
rules.add("unknown");
|
|
550
|
+
parts.push(unknownReason("no-select", all));
|
|
551
|
+
}
|
|
552
|
+
for (const policy of permissive) {
|
|
553
|
+
const check = policy.tagged ?? tenantCheck(policy.using, helpers.byPermission);
|
|
554
|
+
for (const key of policy.tagged === void 0 ? keysOf(policy.using, helpers.byPermission) : [policy.tagged.key]) keys.add(key);
|
|
555
|
+
for (const found of policy.tagged === void 0 ? tenantDisjuncts(policy.using, helpers.byPermission) : [policy.tagged]) {
|
|
556
|
+
widenKeys.add(found.key);
|
|
557
|
+
widenColumns.add(found.column);
|
|
558
|
+
}
|
|
559
|
+
if (check === void 0) {
|
|
560
|
+
const rule = ruleOf(policy, helpers.plain);
|
|
561
|
+
rules.add(rule);
|
|
562
|
+
if (rule === "form") {
|
|
563
|
+
formPolicies.push(policy);
|
|
564
|
+
if (hasTag) stale.push(policy);
|
|
565
|
+
for (const key of keysOf(policy.using, helpers.plain)) formKeys.add(key);
|
|
566
|
+
} else parts.push(ruleReason(rule, policy, helpers));
|
|
567
|
+
} else if (!columns.has(check.column)) columns.set(check.column, policy.name);
|
|
568
|
+
}
|
|
569
|
+
for (const policy of selects) if (!policy.permissive && readsColumn(policy.using)) {
|
|
570
|
+
rules.add("restrictive");
|
|
571
|
+
parts.push(restrictiveReason(policy));
|
|
572
|
+
}
|
|
573
|
+
if (rules.size === 0 && columns.size > 1) {
|
|
574
|
+
rules.add("condition");
|
|
575
|
+
parts.push(`tenant checks on ${columns.size} columns: ${[...columns].map(([column, name]) => `${name} on ${column}`).join(", ")}`);
|
|
576
|
+
}
|
|
577
|
+
const permissions = [...keys].toSorted();
|
|
578
|
+
const listed = permissions.length === 0 ? {} : { permissions };
|
|
579
|
+
if (rules.size > 0) {
|
|
580
|
+
for (const policy of formPolicies) {
|
|
581
|
+
const blockers = stale.includes(policy) ? [`policy ${policy.name} is still defined${policy.file === void 0 ? "" : ` in ${policy.file}`} next to an @bsb access tag that renders the table's policy: write a migration that drops it`] : formBlockers(policy, all, helpers);
|
|
582
|
+
parts.push(...blockers);
|
|
583
|
+
if (blockers.length === 0 && reasons !== void 0 && keysOf(policy.using, helpers.plain).every((key) => reasons.swappable.has(key))) parts.push(`policy ${policy.name} is movable: nothing on the table blocks permdock codemod bsb-access-tags`);
|
|
584
|
+
}
|
|
585
|
+
if (reasons !== void 0 && stale.length === 0) parts.push(...[...formKeys].toSorted().map((key) => `key ${key}: ${keyReason(reasons, key)}`));
|
|
586
|
+
const why = parts.length === 0 ? void 0 : parts.join("; ");
|
|
587
|
+
const [widened] = widenColumns;
|
|
588
|
+
const holds = widenColumns.size === 1 && widened !== void 0 && widenKeys.size > 0 && !rules.has("restrictive") && !rules.has("fields") && !rules.has("unknown");
|
|
589
|
+
return {
|
|
590
|
+
table,
|
|
591
|
+
share: "row",
|
|
592
|
+
...holds ? { column: widened } : {},
|
|
593
|
+
...listed,
|
|
594
|
+
rules: [...rules].toSorted(),
|
|
595
|
+
...holds ? { tenantFor: [...widenKeys].toSorted() } : {},
|
|
596
|
+
...why === void 0 ? {} : { reason: why }
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
const [column] = columns.keys();
|
|
600
|
+
return {
|
|
601
|
+
table,
|
|
602
|
+
share: "tenant",
|
|
603
|
+
...column === void 0 ? {} : { column },
|
|
604
|
+
...listed
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* `rls.tableReads`: for each table the schema files and migrations create, from
|
|
609
|
+
* the select policies they leave defined plus the policies `@bsb access` tags
|
|
610
|
+
* render. A table is `tenant` only when row level security is on, it has no
|
|
611
|
+
* field view, every permissive select policy for `authenticated` is `<column>
|
|
612
|
+
* in (select <schema>.permitted_<root>_ids_by_permission('<key>'))` on one
|
|
613
|
+
* column, and every restrictive select policy reads no column of the row.
|
|
614
|
+
* Everything else is `row`, with the rules it breaks. Tables in the helpers'
|
|
615
|
+
* schema, `better_supabase` and platform schemas are left out. A file
|
|
616
|
+
* libpg_query rejects is skipped. The files are read from disk, so select
|
|
617
|
+
* policies a `generate` run changes in `rls.out` are recorded on the next run.
|
|
618
|
+
*/
|
|
619
|
+
async function tableReads(input) {
|
|
620
|
+
const created = /* @__PURE__ */ new Set();
|
|
621
|
+
const facts = /* @__PURE__ */ new Map();
|
|
622
|
+
const factsOf = (table) => {
|
|
623
|
+
const found = facts.get(table) ?? {
|
|
624
|
+
rls: false,
|
|
625
|
+
policies: /* @__PURE__ */ new Map()
|
|
626
|
+
};
|
|
627
|
+
facts.set(table, found);
|
|
628
|
+
return found;
|
|
629
|
+
};
|
|
630
|
+
for (const file of reportFiles(input.cwd, input.config)) {
|
|
631
|
+
let nodes;
|
|
632
|
+
try {
|
|
633
|
+
nodes = await parseSqlFile(readFileSync(file, "utf8"));
|
|
634
|
+
} catch (error) {
|
|
635
|
+
if (error instanceof SqlSyntaxError) continue;
|
|
636
|
+
throw error;
|
|
637
|
+
}
|
|
638
|
+
for (const node of nodes) if (node.kind === "CreateStmt") {
|
|
639
|
+
const table = relationName(node.node["relation"]);
|
|
640
|
+
if (table !== void 0) created.add(table);
|
|
641
|
+
} else if (node.kind === "AlterTableStmt" && enablesRls(node.node)) {
|
|
642
|
+
const table = relationName(node.node["relation"]);
|
|
643
|
+
if (table !== void 0) factsOf(table).rls = true;
|
|
644
|
+
} else if (node.kind === "DropStmt") {
|
|
645
|
+
const dropped = droppedPolicy(node.node);
|
|
646
|
+
if (dropped !== void 0) facts.get(`${dropped.schema}.${dropped.table}`.toLowerCase())?.policies.delete(dropped.name);
|
|
647
|
+
for (const table of droppedTables(node.node)) {
|
|
648
|
+
created.delete(table);
|
|
649
|
+
facts.delete(table);
|
|
650
|
+
}
|
|
651
|
+
} else if (node.kind === "RenameStmt") renameTable(created, facts, renamedTable(node.node));
|
|
652
|
+
else {
|
|
653
|
+
const policy = readPolicy(node);
|
|
654
|
+
if (policy !== void 0) factsOf(`${policy.schema}.${policy.table}`.toLowerCase()).policies.set(policy.name, {
|
|
655
|
+
...policy,
|
|
656
|
+
file: relative(input.cwd, file)
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
for (const tagged of await taggedAccessPolicies(input.cwd)) {
|
|
661
|
+
if (tagged.operation.toLowerCase() !== "read") continue;
|
|
662
|
+
factsOf(`${tagged.schema}.${tagged.table}`.toLowerCase()).policies.set(tagged.name, {
|
|
663
|
+
name: tagged.name,
|
|
664
|
+
command: "select",
|
|
665
|
+
permissive: true,
|
|
666
|
+
roles: ["authenticated"],
|
|
667
|
+
tagged: {
|
|
668
|
+
column: tagged.tenantColumn,
|
|
669
|
+
key: tagged.key
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
const helpers = {
|
|
674
|
+
plain: `${input.schema}.permitted_${input.root}_ids`,
|
|
675
|
+
byPermission: `${input.schema}.permitted_${input.root}_ids_by_permission`
|
|
676
|
+
};
|
|
677
|
+
const helperSchema = input.schema.toLowerCase();
|
|
678
|
+
return [...created].filter((table) => {
|
|
679
|
+
const schema = table.slice(0, table.indexOf("."));
|
|
680
|
+
return schema !== helperSchema && !LIBRARY_SCHEMAS.has(schema) && !isPlatformSchema(schema);
|
|
681
|
+
}).toSorted().map((table) => readOf(table, facts.get(table), helpers, input.fieldTables ?? /* @__PURE__ */ new Set(), input.reasons));
|
|
682
|
+
}
|
|
683
|
+
/** `tableReads` for the helpers, root scope and field views `manifest` names. */
|
|
684
|
+
function manifestTableReads(cwd, config, manifest, reasons) {
|
|
685
|
+
const root = manifest.rls.scopes[0]?.name;
|
|
686
|
+
if (root === void 0) return Promise.resolve([]);
|
|
687
|
+
const fieldTables = new Set(Object.values(manifest.names?.resources ?? {}).flatMap((names) => names.table === void 0 || names.visible === void 0 ? [] : [(names.table.includes(".") ? names.table : `public.${names.table}`).toLowerCase()]));
|
|
688
|
+
return tableReads({
|
|
689
|
+
cwd,
|
|
690
|
+
config,
|
|
691
|
+
schema: manifest.rls.schema,
|
|
692
|
+
root,
|
|
693
|
+
fieldTables,
|
|
694
|
+
...reasons === void 0 ? {} : { reasons }
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* `manifest` with `rls.tableReads` from the files on disk; unchanged when the
|
|
699
|
+
* files create no table.
|
|
700
|
+
*/
|
|
701
|
+
async function withTableReads(cwd, config, manifest, reasons) {
|
|
702
|
+
const reads = await manifestTableReads(cwd, config, manifest, reasons);
|
|
703
|
+
const tenantPureHelpers = tenantPureHelpersOf(manifest);
|
|
704
|
+
const permissionFilters = permissionFiltersOf(manifest);
|
|
705
|
+
const pure = {
|
|
706
|
+
...tenantPureHelpers.length === 0 ? {} : { tenantPureHelpers },
|
|
707
|
+
...permissionFilters.length === 0 ? {} : { permissionFilters }
|
|
708
|
+
};
|
|
709
|
+
if (reads.length === 0) return {
|
|
710
|
+
...manifest,
|
|
711
|
+
rls: {
|
|
712
|
+
...manifest.rls,
|
|
713
|
+
...pure
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
const sharedFunctions = await sharedFunctionsOf({
|
|
717
|
+
cwd,
|
|
718
|
+
config,
|
|
719
|
+
schema: manifest.rls.schema,
|
|
720
|
+
tableReads: reads
|
|
721
|
+
});
|
|
722
|
+
return {
|
|
723
|
+
...manifest,
|
|
724
|
+
rls: {
|
|
725
|
+
...manifest.rls,
|
|
726
|
+
tableReads: reads,
|
|
727
|
+
sharedFunctions,
|
|
728
|
+
...pure
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* The committed `permdock.manifest.json`, or `undefined` when it is absent or
|
|
734
|
+
* unreadable.
|
|
735
|
+
*/
|
|
736
|
+
function committedManifest(cwd) {
|
|
737
|
+
const path = join(cwd, MANIFEST_FILE);
|
|
738
|
+
if (!existsSync(path)) return;
|
|
739
|
+
try {
|
|
740
|
+
return parseSupabaseManifest(readJsonFile(path));
|
|
741
|
+
} catch {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* `tableReads` for the configured policy, with the reason of each `form` table.
|
|
747
|
+
* Field views come from the committed manifest when there is one. Without a
|
|
748
|
+
* policy the answer is empty; a policy the generator refuses leaves out the
|
|
749
|
+
* reasons only.
|
|
750
|
+
*/
|
|
751
|
+
async function configuredTableReads(cwd, config) {
|
|
752
|
+
const policy = await loadConfiguredPolicy(cwd, config.policy);
|
|
753
|
+
const root = policy === void 0 ? void 0 : scopeList(policy.scopes)[0]?.name;
|
|
754
|
+
if (policy === void 0 || root === void 0) return [];
|
|
755
|
+
const reasons = tryKeyReasons(config, policy, cwd);
|
|
756
|
+
const manifest = committedManifest(cwd);
|
|
757
|
+
if (manifest !== void 0) return manifestTableReads(cwd, config, manifest, reasons);
|
|
758
|
+
return tableReads({
|
|
759
|
+
cwd,
|
|
760
|
+
config,
|
|
761
|
+
schema: config.rls?.schema ?? "permdock",
|
|
762
|
+
root,
|
|
763
|
+
...reasons === void 0 ? {} : { reasons }
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
export { withTableReads as a, tableReads as i, configuredTableReads as n, functionShares as o, manifestTableReads as r, sharedFunctionsOf as s, committedManifest as t };
|