permdock 0.27.3 → 0.28.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/{2020-bJfT8aIA.js → 2020-DBXhfpuK.js} +2 -2
- package/dist/{adoption-scan-CHMU7gnE.js → adoption-scan-BHQm3Li7.js} +1 -1
- package/dist/approvals/index.d.ts +1 -1
- package/dist/{arazzo-D1ZHjjea.js → arazzo-CAQr4N7Z.js} +2 -2
- package/dist/{arazzo-DuXmPMSu.js → arazzo-UwtVzma6.js} +1 -1
- package/dist/{args-0EWFk-4S.js → args-Bc0HLiD4.js} +1 -1
- package/dist/better-supabase/index.d.ts +2 -0
- package/dist/better-supabase/index.js +8 -6
- package/dist/{casbin-CwLL5QnK.js → casbin-CSgPeAJK.js} +1 -1
- package/dist/{casbin-Bf9jkDMy.js → casbin-Ccbaft52.js} +1 -1
- package/dist/catalog/index.d.ts +1 -1
- package/dist/{catalog-B3MJShnZ.js → catalog-COoxFOoy.js} +1 -1
- package/dist/catalog-DCjJIl3n.js +1 -0
- package/dist/{catalog-DyC3LKc7.js → catalog-DXSP1we9.js} +1 -1
- package/dist/cli/bin.js +1 -1
- package/dist/cli/generate/watch-worker.js +1 -1
- package/dist/cli/index.d.ts +5 -4
- package/dist/cli/index.js +1 -1
- 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/{cloud-nXogJ7e1.js → cloud-CFtvELWj.js} +2 -2
- package/dist/{codemod-DwL1E5of.js → codemod-3PFIcPag.js} +2 -2
- package/dist/{codemod-Bp2bKwKe.js → codemod-ClcPRv4c.js} +2 -2
- package/dist/{collect-BJZsuBW4.js → collect-BOh9Pxob.js} +1 -1
- package/dist/{collect-CpGnmGpL.js → collect-BYPq-0JU.js} +2 -2
- package/dist/collect-XcoQRyiA.js +1 -0
- package/dist/{compile-NM1GOb2q.js → compile-mfTqcMJ5.js} +1 -1
- package/dist/{completion-BQovwoTx.js → completion-D4p_MQX7.js} +2 -2
- package/dist/{config-DSyn7r1l.js → config-D9bq79Yi.js} +1 -1
- package/dist/{config-report--ae2r_MI.js → config-report-DZfIl6zc.js} +2 -2
- package/dist/{context-DmH-Eyvx.js → context-BdoA9DhS.js} +2 -2
- package/dist/{core-DKqrD_xW.js → core-tEfD0lwu.js} +1 -1
- package/dist/delivery/index.d.ts +1 -1
- package/dist/{diff-BIqibFnm.js → diff-CXRZ6qPa.js} +1 -1
- package/dist/{diff-n6LONVwL.js → diff-Cv9inVY5.js} +1 -1
- package/dist/{doctor-CIV882xS.js → doctor-CuhkBJ06.js} +3 -3
- package/dist/{doctor-kbRrZD3Q.js → doctor-FHjwjHYC.js} +18 -18
- package/dist/{execute-CE8P72Ez.js → execute-DdH84BHC.js} +3 -3
- package/dist/gen-BseS8XeZ.js +1 -0
- package/dist/{gen-CuEt0o6p.js → gen-CcKymoUw.js} +3 -3
- package/dist/{gen-kind-BLIhHgD3.js → gen-kind-Bf9jYVgn.js} +1 -1
- package/dist/{generate-Dl75LKbW.js → generate-BCUVV4vB.js} +11 -11
- package/dist/{generate-B-Hlc08D.js → generate-UMuStlLD.js} +2 -2
- package/dist/{generate-options-BUh621MW.js → generate-options-Cg5sAHhT.js} +6 -6
- package/dist/{hook-sql-Bxc_YRrd.js → hook-sql-C0aUoiOH.js} +6 -5
- package/dist/{import-BKTq4cxW.js → import--taRAR01.js} +1 -1
- package/dist/{index-Cq9N5B92.d.ts → index-BSJoxaOi.d.ts} +1 -1
- package/dist/{index-BXz-XXC3.d.ts → index-D1msamx_.d.ts} +1 -1
- package/dist/{index-CVuc3E1O.d.ts → index-eaNHkELi.d.ts} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{init-B8GG9vjg.js → init-CP3fYFb6.js} +3 -3
- package/dist/{init-D4YO8hVa.js → init-Cfi7_gXO.js} +1 -1
- package/dist/{json-schema-SDkWXxhu.d.ts → json-schema-DAeA-lJa.d.ts} +1 -1
- package/dist/{lazy-provider-CydlnKkS.d.ts → lazy-provider-C48LDq0q.d.ts} +1 -1
- package/dist/{lazy-provider-DG5rMeqL.js → lazy-provider-CVX534Kk.js} +1 -1
- package/dist/{login-OJdYkueH.js → login-BjkyJNGn.js} +3 -3
- package/dist/{login-Bl-SuTJA.js → login-kg9Pd0C2.js} +1 -1
- package/dist/{manifest-BY8lK4l4.js → manifest-C7dWk0k5.js} +35 -35
- package/dist/{migrate-CmTMk7rd.js → migrate-BwXtXUtE.js} +1 -1
- package/dist/next/index.d.ts +2 -2
- package/dist/next/plugin.d.ts +1 -1
- package/dist/next/plugin.js +1 -1
- package/dist/{openapi-CvAjVdK7.js → openapi-B5jo5ClY.js} +3 -3
- package/dist/{openapi-Dpetebzt.js → openapi-dJFJTHiW.js} +1 -1
- package/dist/{openapi-document-7K7rofeR.js → openapi-document-B58hIsZ4.js} +1 -1
- package/dist/{output-Cq0neio3.js → output-Pne7BTXn.js} +1 -1
- package/dist/{output-files-DNid6TBl.js → output-files-D5D-8-4l.js} +1 -1
- package/dist/output-files-aPXXhV4q.js +1 -0
- package/dist/{ownership-CHND0y5L.js → ownership-BPGoxz1T.js} +1 -1
- package/dist/{permissions-ijDw4sO1.js → permissions-Bj3DRIEi.js} +1 -1
- package/dist/{plugin-1XW5OfAZ.d.ts → plugin-zOs9uqQj.d.ts} +1 -1
- package/dist/{policy-DzTU5233.js → policy-G8iZ2T5P.js} +1 -1
- package/dist/{policy-bundle-Dafv5nOx.js → policy-bundle-nbcxlVOb.js} +3 -3
- package/dist/{powersync-IrDmJbqx.js → powersync-B9KEEiJE.js} +1 -1
- package/dist/{powersync-BfMIjRqo.js → powersync-BoOMFQRl.js} +1 -1
- package/dist/{powersync-DNeS5JrT.js → powersync-CqAj9QJt.js} +6 -6
- package/dist/{prompt-CSXHcJxy.js → prompt-CPlJn_4-.js} +3 -3
- package/dist/{protected-action-D6T3eJyW.d.ts → protected-action-CEzNNtfi.d.ts} +2 -2
- package/dist/{protected-action-BMb0ftEu.js → protected-action-Dco5O_Kc.js} +1 -1
- package/dist/{provider-ClD4rfgT.js → provider-BYcoTKuS.js} +1 -1
- package/dist/{provider-CydlnKkS.d.ts → provider-C48LDq0q.d.ts} +1 -1
- package/dist/{provider-store-atQUfsVO.js → provider-store-Dq_olUjC.js} +1 -1
- package/dist/{provider-with-CSw4mBDU.js → provider-with-fxHItxDh.js} +1 -1
- package/dist/pull-8Vce3V1e.js +1 -0
- package/dist/{pull-DOwvDn98.js → pull-DXuh-rob.js} +1 -1
- package/dist/{push-Cb7PqXdO.js → push-DXh936bz.js} +1 -1
- package/dist/{pushed-policy-pH-EFWyx.d.ts → pushed-policy-APjMbYdV.d.ts} +1 -1
- package/dist/{rbac-CygtQB85.js → rbac-FlJv7Ba9.js} +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +3 -3
- package/dist/react/lazy.d.ts +4 -4
- 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 +4 -4
- package/dist/react-native/index.js +2 -2
- package/dist/{resolve-names-D0hNHBp5.js → resolve-names-CROyyjVR.js} +1 -1
- package/dist/{resolver-kdZ4HrpC.js → resolver-4qxIIHcC.js} +1 -1
- package/dist/{rls-BjEp-1Ob.js → rls-BL90Ec30.js} +7 -7
- package/dist/{rls-BDmebOIp.js → rls-DV4MUNMb.js} +1 -1
- package/dist/{rls-files-kGXtfslQ.js → rls-files-BgLoAa9x.js} +2 -2
- package/dist/{rls-options-CEpg5nDP.d.ts → rls-options-BZxfMDFo.d.ts} +1 -1
- package/dist/{run-DFe2I0T7.js → run-BFDAiNuS.js} +3 -3
- package/dist/run-mEbYi2Ow.js +1 -0
- package/dist/{saas-DzjKUQr5.js → saas-CUwmgUB8.js} +2 -2
- package/dist/{scan-DGCpdOuR.js → scan-CoyAmDAz.js} +1 -1
- package/dist/{schema-wummOGn9.js → schema-9eGIiLry.js} +2 -2
- package/dist/{size-DF7xQ-nH.js → size-BqLd5oJ4.js} +1 -1
- package/dist/{skills-BQ9bEjPV.js → skills-B8nt-KuB.js} +2 -2
- package/dist/{skills-BntnICiJ.js → skills-BPDVfXgR.js} +2 -2
- package/dist/{snapshot-size-DU7CvpMt.js → snapshot-size-B_chu2c1.js} +1 -1
- package/dist/{snapshot-size-D-pCR8x0.js → snapshot-size-CHig-Nq_.js} +1 -1
- package/dist/solid/index.d.ts +24 -24
- package/dist/solid/index.js +2 -2
- package/dist/{src-D6_T4zd7.js → src-BAYcigFU.js} +1 -1
- package/dist/{store-core-eqG8jijs.d.ts → store-core-DyNo_BwA.d.ts} +4 -2
- package/dist/{store-options-C8x39AHa.js → store-options-BtHrfJUU.js} +1 -1
- package/dist/{stores-DoA7ACkz.js → stores-BIMyclLg.js} +1 -1
- package/dist/{stores-4DOaL4ZP.d.ts → stores-DyFCruRC.d.ts} +2 -2
- package/dist/supabase/index.d.ts +6 -0
- package/dist/supabase/index.js +2 -2
- package/dist/{supabase-BI5ZhzLl.js → supabase-Ctn_Z6xf.js} +1 -1
- package/dist/{supabase-CjUsihRL.js → supabase-D5KN965n.js} +1 -1
- package/dist/{supabase-config-CbK7xX77.js → supabase-config-CjX-GjEp.js} +1 -1
- package/dist/supabase-hook-CjChM-eX.js +2 -0
- package/dist/{supabase-hook-nGLUvn5x.js → supabase-hook-CmW2MLWa.js} +4 -4
- package/dist/svelte/index.d.ts +3 -3
- package/dist/svelte/index.js +3 -3
- package/dist/svelte/runtime.d.ts +2 -2
- package/dist/svelte/runtime.js +1 -1
- package/dist/svelte/source.d.ts +3 -3
- package/dist/svelte/source.js +2 -2
- package/dist/{tables-CbVpFhC6.js → tables-Btlt_Rp-.js} +43 -6
- package/dist/testing/core.js +1 -1
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +5 -5
- package/dist/testing/saas/index.js +2 -2
- package/dist/testing/saas/permissions.js +1 -1
- package/dist/{text-diff-CsglY49A.js → text-diff-DxKRNFlx.js} +2 -2
- package/dist/{types-C7QtRn3n.d.ts → types-4wjWMSFM.d.ts} +2 -2
- package/dist/{types-CVCRFYY_.d.ts → types-CQF-oYSz.d.ts} +1 -1
- package/dist/{types-3pRMqcvw.d.ts → types-PS10T9UK.d.ts} +1 -1
- package/dist/{types-nXo_oQYk.d.ts → types-config-Cq72dArb.d.ts} +740 -782
- package/dist/types-run-DG1H5vrX.d.ts +44 -0
- package/dist/unplugin/index.d.ts +1 -1
- package/dist/unplugin/index.js +1 -1
- package/dist/{usage-L1G1zlwz.js → usage-DRReZaxQ.js} +1 -1
- package/dist/{usage-C1NKRxBJ.js → usage-DVjr2ZDc.js} +3 -3
- package/dist/usage-nVi3-z-j.js +1 -0
- package/dist/{verify-KX4Ohvs_.js → verify-BOB_Jyjx.js} +4 -4
- package/dist/vue/index.d.ts +1 -1
- package/dist/vue/index.js +2 -2
- package/dist/{watch-CiN6WU9k.js → watch-BNxvqCS4.js} +1 -1
- package/dist/watch-CGLmIdld.js +1 -0
- package/dist/{watch-DNIGANvR.js → watch-CnRyGEtp.js} +1 -1
- package/package.json +14 -14
- package/skills/permdock-data/references/queries-and-rls.md +1 -0
- package/dist/catalog-CgK_L4Qf.js +0 -1
- package/dist/collect-CPvCXMQ-.js +0 -1
- package/dist/gen-DbPS6a4x.js +0 -1
- package/dist/output-files-C5LFnQa4.js +0 -1
- package/dist/pull-Qh7JjiO7.js +0 -1
- package/dist/run-CdxQr6w8.js +0 -1
- package/dist/supabase-hook-b7tej2Vw.js +0 -2
- package/dist/usage-BAUV1SYl.js +0 -1
- package/dist/watch-NAUnUXph.js +0 -1
|
@@ -1,850 +1,894 @@
|
|
|
1
1
|
import { i as Seeds } from "./seeds-uG196Ev4.js";
|
|
2
2
|
import { h as RoleThrough, m as RoleMap, s as SqlMembershipSource } from "./sources-NQio1yFq.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* terminated (SIGTERM).
|
|
4
|
+
* `permdock powersync generate` and `verify` input. Tables and memberships come
|
|
5
|
+
* from `rls`.
|
|
7
6
|
*/
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
readonly srcPath?: readonly string[];
|
|
11
|
-
readonly out?: string;
|
|
12
|
-
readonly barrel?: boolean | string;
|
|
13
|
-
};
|
|
14
|
-
type CatalogConfig = {
|
|
7
|
+
type PowerSyncConfig = {
|
|
8
|
+
/** The Sync Streams file; default `sync-config.yaml`. */
|
|
15
9
|
readonly out?: string;
|
|
16
|
-
};
|
|
17
|
-
type RlsDialect = "supabase" | "neon" | "guc";
|
|
18
|
-
type RlsTarget = "sql" | "drizzle" | "prisma";
|
|
19
|
-
type RlsMembershipTable = {
|
|
20
|
-
readonly table: string;
|
|
21
|
-
readonly user: string;
|
|
22
10
|
/**
|
|
23
|
-
* The
|
|
24
|
-
*
|
|
11
|
+
* The only resources that get a stream. A helper does not add one. None when
|
|
12
|
+
* omitted.
|
|
25
13
|
*/
|
|
26
|
-
readonly
|
|
14
|
+
readonly resources?: readonly string[];
|
|
15
|
+
/** The action whose grants decide which rows sync; default `read`. */
|
|
16
|
+
readonly action?: string;
|
|
27
17
|
/**
|
|
28
|
-
*
|
|
29
|
-
* and
|
|
18
|
+
* Where `generate` writes `localSnapshotManifest(policy)` as JSON for
|
|
19
|
+
* `localSnapshot` and `powerSyncSource`; none by default.
|
|
30
20
|
*/
|
|
31
|
-
readonly
|
|
32
|
-
readonly id?: string;
|
|
33
|
-
readonly expiresAt?: string;
|
|
34
|
-
readonly disabledAt?: string;
|
|
21
|
+
readonly manifest?: string;
|
|
35
22
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
23
|
+
* Tables that are not resources, by `schema.table`, each synced as its own
|
|
24
|
+
* stream: the user's own rows, the rows that point at a resource row the user
|
|
25
|
+
* reads, or both.
|
|
38
26
|
*/
|
|
39
|
-
readonly
|
|
40
|
-
readonly value: string;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
type RlsMemberships = {
|
|
44
|
-
/** The membership table of each named scope. */
|
|
45
|
-
readonly scopes?: Readonly<Record<string, RlsMembershipTable>>;
|
|
46
|
-
readonly resource?: Readonly<Record<string, RlsMembershipTable>>;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* A table whose row says whether a user or a scope instance is active. A
|
|
50
|
-
* missing row counts as suspended.
|
|
51
|
-
*/
|
|
52
|
-
type RlsActiveRow = {
|
|
53
|
-
readonly table: string;
|
|
54
|
-
/** Column holding the user id or the scope instance id. */
|
|
55
|
-
readonly id: string;
|
|
56
|
-
/** Nullable timestamp column; a row with a value is suspended. */
|
|
57
|
-
readonly disabledAt?: string;
|
|
58
|
-
/** Status column; only a row whose value is in `active` counts as active. */
|
|
59
|
-
readonly status?: string;
|
|
60
|
-
readonly active?: readonly string[];
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* A scope's active-row table, with the permissions its suspended instances
|
|
64
|
-
* keep.
|
|
65
|
-
*/
|
|
66
|
-
type RlsSuspendedScope = RlsActiveRow & {
|
|
27
|
+
readonly tables?: Readonly<Record<string, PowerSyncTable>>;
|
|
67
28
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
29
|
+
* Per resource, the membership column that narrows what a device syncs: a
|
|
30
|
+
* member with no value or `all` syncs the tenant's rows, `own` the rows of
|
|
31
|
+
* the resource's `own` level, `team` those of its `team` level. A resource
|
|
32
|
+
* without an entry syncs the tenant's rows to every member.
|
|
71
33
|
*/
|
|
72
|
-
readonly
|
|
73
|
-
readonly key: string;
|
|
74
|
-
})[];
|
|
75
|
-
};
|
|
76
|
-
type RlsSuspendedMembership = {
|
|
77
|
-
readonly keep?: readonly (string | {
|
|
78
|
-
readonly key: string;
|
|
79
|
-
})[];
|
|
34
|
+
readonly memberLevel?: Readonly<Record<string, PowerSyncMemberLevel>>;
|
|
80
35
|
};
|
|
81
|
-
type
|
|
82
|
-
/** A suspended user holds no role and no membership. */
|
|
83
|
-
readonly users?: RlsActiveRow;
|
|
36
|
+
type PowerSyncMemberLevel = {
|
|
84
37
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
38
|
+
* `table` or `schema.table` of the tenant scope's membership table, as
|
|
39
|
+
* `rls.memberships` or a membership source names it.
|
|
87
40
|
*/
|
|
88
|
-
readonly
|
|
89
|
-
|
|
41
|
+
readonly table: string;
|
|
42
|
+
/** The text column on that table holding `own`, `team` or `all`. */
|
|
43
|
+
readonly column: string;
|
|
90
44
|
};
|
|
91
|
-
type
|
|
92
|
-
|
|
93
|
-
readonly
|
|
45
|
+
type PowerSyncTable = {
|
|
46
|
+
/** The user id column: the stream holds the rows whose column is the user. */
|
|
47
|
+
readonly user?: string;
|
|
48
|
+
/** The resources a row points at; the stream holds rows of any of them. */
|
|
49
|
+
readonly follow?: readonly PowerSyncFollow[];
|
|
94
50
|
};
|
|
95
51
|
/**
|
|
96
|
-
* A
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* `permitted_<parent, singular>_ids(p_grant)`, a `security definer` helper that
|
|
100
|
-
* joins the parent to `permitted_<scope>_ids`.
|
|
52
|
+
* A row points at a `resource` row through `field`, which holds its id; `match`
|
|
53
|
+
* keeps the rows whose columns equal the given values, for a table whose rows
|
|
54
|
+
* point at several resources.
|
|
101
55
|
*/
|
|
102
|
-
type
|
|
103
|
-
|
|
104
|
-
readonly
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
111
|
-
readonly key?: string;
|
|
112
|
-
/** The parent's id column. Default `id`. */
|
|
56
|
+
type PowerSyncFollow = {
|
|
57
|
+
readonly resource: string;
|
|
58
|
+
readonly field: string;
|
|
59
|
+
readonly match?: Readonly<Record<string, string>>;
|
|
60
|
+
};
|
|
61
|
+
/** `rls.approvals.managers`: one row per user and manager. */
|
|
62
|
+
/** Column names of the table `rls.approvals.tenantPolicies` writes. */
|
|
63
|
+
type RlsApprovalPolicyColumns = {
|
|
113
64
|
readonly id?: string;
|
|
65
|
+
readonly tenant?: string;
|
|
66
|
+
readonly name?: string;
|
|
67
|
+
readonly body?: string;
|
|
68
|
+
readonly enabled?: string;
|
|
69
|
+
readonly createdAt?: string;
|
|
70
|
+
};
|
|
71
|
+
type RlsApprovalPolicies = {
|
|
72
|
+
/** The permission key whose holders in a tenant edit its policies. */
|
|
73
|
+
readonly manage: string;
|
|
114
74
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
75
|
+
* The table, as `table` or `schema.table`; the helper schema's
|
|
76
|
+
* `approval_policies` by default. It is created when missing.
|
|
117
77
|
*/
|
|
118
|
-
readonly type?: string;
|
|
119
|
-
/** The scope `column` holds. Default the policy's root scope. */
|
|
120
|
-
readonly scope?: string;
|
|
121
|
-
};
|
|
122
|
-
/**
|
|
123
|
-
* A resource's table. `false` is a resource with no table. `{ tableOf }` is the
|
|
124
|
-
* older way to store a resource in another resource's table; `also` on the
|
|
125
|
-
* owner replaces it. `follows` names child tables whose policies are an
|
|
126
|
-
* `exists` of `can_<resource>` on this row. `walk: "recursive"` is the manager
|
|
127
|
-
* chain: one recursive set helper.
|
|
128
|
-
*/
|
|
129
|
-
type RlsTableOwner = {
|
|
130
78
|
readonly table?: string;
|
|
131
|
-
readonly via?: RlsTableVia;
|
|
132
|
-
/** Other resources stored in this table. They get no policies of their own. */
|
|
133
|
-
readonly also?: readonly string[];
|
|
134
79
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
80
|
+
* The function `tableApprovalPolicySource` reads, in the helper schema;
|
|
81
|
+
* `permdock_approval_policies_for` by default. Pass the same name as
|
|
82
|
+
* `function` to the source.
|
|
137
83
|
*/
|
|
138
|
-
readonly
|
|
139
|
-
|
|
140
|
-
readonly walk?: "recursive";
|
|
84
|
+
readonly function?: string;
|
|
85
|
+
readonly columns?: RlsApprovalPolicyColumns;
|
|
141
86
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
87
|
+
* Where the `ApprovalPolicy` sits inside the body column, as object keys; the
|
|
88
|
+
* column itself by default. The constraint requires an `approval` key there.
|
|
144
89
|
*/
|
|
145
|
-
readonly
|
|
146
|
-
};
|
|
147
|
-
type RlsTable = string | false | RlsTableOwner | {
|
|
148
|
-
readonly tableOf: string;
|
|
90
|
+
readonly path?: readonly string[];
|
|
149
91
|
};
|
|
150
|
-
type
|
|
151
|
-
/**
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
readonly
|
|
157
|
-
readonly memberships?: RlsMemberships;
|
|
92
|
+
type RlsApprovalManagers = {
|
|
93
|
+
/** `table` or `schema.table`. */
|
|
94
|
+
readonly table: string;
|
|
95
|
+
/** The column holding the user's id. */
|
|
96
|
+
readonly user: string;
|
|
97
|
+
/** The column holding the id of that user's manager. */
|
|
98
|
+
readonly manager: string;
|
|
158
99
|
/**
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* the same SQL. Setting it selects `database` mode.
|
|
100
|
+
* The column holding the tenant each edge belongs to. Required when the
|
|
101
|
+
* policy has a tenant scope: both walks keep only the edges of the request's
|
|
102
|
+
* tenant, so the table or view must expose it.
|
|
163
103
|
*/
|
|
164
|
-
readonly
|
|
104
|
+
readonly tenant?: string;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* `rls.approvals` on a table the app already has: the store functions keep each
|
|
108
|
+
* request's body in `body` and its token in `token` (both added when missing)
|
|
109
|
+
* and read every field from the body; `mirror` copies request fields into the
|
|
110
|
+
* app's own columns on each write, converted to their types.
|
|
111
|
+
*/
|
|
112
|
+
type RlsApprovalsAdopt = {
|
|
113
|
+
readonly store?: boolean;
|
|
165
114
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
115
|
+
* `table` or `schema.table`. Without it the store is the generated
|
|
116
|
+
* `approval_requests`.
|
|
168
117
|
*/
|
|
169
|
-
readonly
|
|
170
|
-
readonly functions?: Readonly<Record<string, RlsFunctionMapping>>;
|
|
171
|
-
readonly inlineFunctions?: boolean;
|
|
118
|
+
readonly table?: string;
|
|
172
119
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
120
|
+
* Add `approval_delegations`, the out-of-office covers a user writes for
|
|
121
|
+
* themselves, and the four-argument `permdock_is_approver` that answers for a
|
|
122
|
+
* delegate inside an active cover. `tableApprovalDelegationSource` reads the
|
|
123
|
+
* same rows for `approvalsHandler`. Off by default.
|
|
175
124
|
*/
|
|
176
|
-
readonly
|
|
177
|
-
readonly fixtures?: string;
|
|
125
|
+
readonly delegations?: boolean;
|
|
178
126
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
127
|
+
* Add `approval_policies`, the approval requirements a tenant keeps as data,
|
|
128
|
+
* and `permdock_approval_policies_for`, which `tableApprovalPolicySource`
|
|
129
|
+
* reads. A holder of the `manage` permission key in a tenant writes that
|
|
130
|
+
* tenant's rows; rows with `tenant` null are platform floors, written only by
|
|
131
|
+
* the table owner. Off by default.
|
|
182
132
|
*/
|
|
183
|
-
readonly
|
|
184
|
-
readonly ignore?: readonly {
|
|
185
|
-
readonly id: string;
|
|
186
|
-
readonly reason: string;
|
|
187
|
-
}[];
|
|
188
|
-
};
|
|
189
|
-
readonly tenantClaim?: string;
|
|
133
|
+
readonly tenantPolicies?: RlsApprovalPolicies;
|
|
190
134
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* every such tenant whatever the claim says, for apps whose tenant comes from
|
|
195
|
-
* the URL or the query.
|
|
135
|
+
* The app's table that names each user's manager, so `manager()` approvers
|
|
136
|
+
* match in SQL: `permdock_manages` walks it and the four-argument
|
|
137
|
+
* `permdock_is_approver` calls it. Off by default.
|
|
196
138
|
*/
|
|
197
|
-
readonly
|
|
198
|
-
/**
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
139
|
+
readonly managers?: RlsApprovalManagers;
|
|
140
|
+
/** A text column unique per request. Default `token`. */
|
|
141
|
+
readonly token?: string;
|
|
142
|
+
/** A jsonb column holding the `ApprovalRequest`. Default `body`. */
|
|
143
|
+
readonly body?: string;
|
|
144
|
+
readonly open?: "insert" | "attach";
|
|
145
|
+
readonly schema?: string;
|
|
146
|
+
/** Request fields copied into the app's columns, field to column. */
|
|
147
|
+
readonly mirror?: {
|
|
148
|
+
readonly status?: string;
|
|
149
|
+
readonly permission?: string;
|
|
150
|
+
readonly tenant?: string;
|
|
151
|
+
readonly principalId?: string;
|
|
152
|
+
readonly actorId?: string;
|
|
153
|
+
readonly session?: string;
|
|
154
|
+
readonly approvals?: string;
|
|
155
|
+
readonly createdAt?: string;
|
|
156
|
+
readonly expiresAt?: string;
|
|
157
|
+
readonly resolvedAt?: string;
|
|
158
|
+
readonly resolvedBy?: string;
|
|
159
|
+
readonly consumedAt?: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
type RlsApiKeys = {
|
|
163
|
+
readonly claim?: string;
|
|
164
|
+
readonly scopes?: string;
|
|
165
|
+
readonly tenant?: string;
|
|
166
|
+
readonly roles?: string;
|
|
167
|
+
readonly serviceRoles?: readonly string[];
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* One more table whose rows assign a role, such as invitations
|
|
171
|
+
* (`rls.assignments.tables`).
|
|
172
|
+
*/
|
|
173
|
+
type RlsAssignmentTable = {
|
|
174
|
+
readonly table: string;
|
|
175
|
+
/** The declared scope the row assigns the role at. */
|
|
176
|
+
readonly scope: string;
|
|
177
|
+
/** The column holding the scope instance id. */
|
|
178
|
+
readonly id: string;
|
|
179
|
+
/**
|
|
180
|
+
* The tenant column for a scope below the first; defaults to `id` at the
|
|
181
|
+
* first scope.
|
|
202
182
|
*/
|
|
203
|
-
readonly
|
|
183
|
+
readonly tenant?: string;
|
|
204
184
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
* `<type>[]`), by resource name; `"*"` sets the default. Without it: `uuid`
|
|
208
|
-
* on Supabase, `text` elsewhere.
|
|
185
|
+
* The role key column, a reference to a roles table that holds the key, or
|
|
186
|
+
* several of them.
|
|
209
187
|
*/
|
|
210
|
-
readonly
|
|
211
|
-
readonly roleClaim?: string;
|
|
188
|
+
readonly role: string | RoleMap | RoleThrough | readonly (string | RoleMap | RoleThrough)[];
|
|
212
189
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* name for a mapped value; `rls migrate` filters a `role` helper by it. An
|
|
216
|
-
* unmapped value must already be a declared role.
|
|
190
|
+
* The column holding the user the row assigns to, which `ownRole` compares
|
|
191
|
+
* with the caller.
|
|
217
192
|
*/
|
|
218
|
-
readonly
|
|
219
|
-
|
|
220
|
-
|
|
193
|
+
readonly user?: string;
|
|
194
|
+
};
|
|
195
|
+
/** `rls.customRoleWrites.roles`: the application's table of custom roles. */
|
|
196
|
+
type RlsCustomRoleTable = {
|
|
197
|
+
readonly table: string;
|
|
198
|
+
/** The column holding the role name. */
|
|
199
|
+
readonly key: string;
|
|
221
200
|
/**
|
|
222
|
-
* The
|
|
223
|
-
*
|
|
224
|
-
* and doctor, to `out` with `{part}` replaced by `hook`.
|
|
201
|
+
* The tenant column; a row with no tenant is a platform custom role (`scope:
|
|
202
|
+
* 'global'`). Without it every row is a platform role.
|
|
225
203
|
*/
|
|
226
|
-
readonly
|
|
227
|
-
/** `--target drizzle`: where each policy's `.link()` finds its table. */
|
|
228
|
-
readonly drizzle?: {
|
|
229
|
-
/** Module exporting the tables, as imported from `out`. Default `./schema`. */
|
|
230
|
-
readonly schema?: string;
|
|
231
|
-
/**
|
|
232
|
-
* Export name per table name; defaults to the camelCased table name without
|
|
233
|
-
* its schema.
|
|
234
|
-
*/
|
|
235
|
-
readonly exports?: Readonly<Record<string, string>>;
|
|
236
|
-
};
|
|
237
|
-
/** `--target prisma`: the model each table maps to. */
|
|
238
|
-
readonly prisma?: {
|
|
239
|
-
/**
|
|
240
|
-
* Model name per table name; defaults to the PascalCased table name without
|
|
241
|
-
* its schema.
|
|
242
|
-
*/
|
|
243
|
-
readonly models?: Readonly<Record<string, string>>;
|
|
244
|
-
};
|
|
204
|
+
readonly tenant?: string;
|
|
245
205
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* Default `permdock`; keep it out of `[api] schemas`.
|
|
206
|
+
* A text column holding the scope name; without it a row with a tenant lives
|
|
207
|
+
* at the first scope.
|
|
249
208
|
*/
|
|
250
|
-
readonly
|
|
209
|
+
readonly scope?: string;
|
|
210
|
+
/** A column pinning the role to one instance of its scope. */
|
|
211
|
+
readonly id?: string;
|
|
251
212
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
213
|
+
* The row's id column: turns on the by-id write and read functions
|
|
214
|
+
* (`permdock_replace_custom_role_grants_by_id`).
|
|
254
215
|
*/
|
|
255
|
-
readonly
|
|
256
|
-
/** One policy per role and permission instead of one per table and command. */
|
|
257
|
-
readonly policyPerRole?: boolean;
|
|
216
|
+
readonly primaryKey?: string;
|
|
258
217
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* the `memberships[].grants` claim in `jwt` mode, always intersected with the
|
|
262
|
-
* `permdock_ceiling` view. Off by default. An object turns them on and names
|
|
263
|
-
* the application's existing role tables that `--backfill-out` copies from.
|
|
218
|
+
* A boolean column marking rows that are not custom roles (declared or system
|
|
219
|
+
* roles); those rows are skipped.
|
|
264
220
|
*/
|
|
265
|
-
readonly
|
|
221
|
+
readonly skip?: string;
|
|
266
222
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
223
|
+
* A boolean column marking a row with no tenant as a shared custom role, held
|
|
224
|
+
* at `scope` (default the first scope) in every tenant. Without it a row with
|
|
225
|
+
* no tenant is a platform role.
|
|
270
226
|
*/
|
|
271
|
-
readonly
|
|
227
|
+
readonly shared?: string;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* `rls.customRoles` as an object: custom roles on, plus where existing ones
|
|
231
|
+
* live.
|
|
232
|
+
*/
|
|
233
|
+
type RlsCustomRolesConfig = {
|
|
272
234
|
/**
|
|
273
|
-
*
|
|
274
|
-
* `
|
|
235
|
+
* The application's role tables `--backfill-out` copies into
|
|
236
|
+
* `custom_role_permissions` and `custom_role_includes`.
|
|
275
237
|
*/
|
|
276
|
-
readonly
|
|
238
|
+
readonly from?: RlsCustomRolesFrom;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Existing custom-role data. Each row's role is a row of
|
|
242
|
+
* `rls.customRoleWrites.roles`, which supplies its name, tenant, scope,
|
|
243
|
+
* instance and `skip` flag.
|
|
244
|
+
*/
|
|
245
|
+
type RlsCustomRolesFrom = {
|
|
277
246
|
/**
|
|
278
|
-
*
|
|
279
|
-
*
|
|
247
|
+
* `'trigger'`: after-row triggers on the permissions table and the includes
|
|
248
|
+
* table rebuild the affected role through
|
|
249
|
+
* `permdock_trusted_replace_custom_role_grants` on every legacy write, so the
|
|
250
|
+
* PermDock grants follow the application's editor. Without it the backfill
|
|
251
|
+
* copies once.
|
|
280
252
|
*/
|
|
281
|
-
readonly
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
* through a global role; only through a global role for a platform custom
|
|
286
|
-
* role), or `'manageRoles'` for any permission with `meta.manageRoles`.
|
|
287
|
-
* Unset, any member may write a role within what they may hand out.
|
|
288
|
-
*/
|
|
289
|
-
readonly requires?: "manageRoles" | readonly string[];
|
|
253
|
+
readonly sync?: "trigger";
|
|
254
|
+
readonly permissions: {
|
|
255
|
+
/** `table` or `schema.table`: one row per permission a role holds. */
|
|
256
|
+
readonly table: string;
|
|
290
257
|
/**
|
|
291
|
-
* The
|
|
292
|
-
*
|
|
293
|
-
* or instance changes, and deletes them with the row. A signed-in caller
|
|
294
|
-
* goes through the same checks as the write functions; a trusted path (a
|
|
295
|
-
* migration, a job, a nested trigger) moves the rows directly.
|
|
258
|
+
* The reference to the roles table: `{ through: 'roles', on: { role_id:
|
|
259
|
+
* 'id' }, column: 'key' }`.
|
|
296
260
|
*/
|
|
297
|
-
readonly
|
|
261
|
+
readonly role: RoleThrough;
|
|
298
262
|
/**
|
|
299
|
-
* The
|
|
300
|
-
*
|
|
301
|
-
* `target_type`, `record_id`, `tenant` and `metadata` plus `args`. Needs
|
|
302
|
-
* `roles.primaryKey`.
|
|
263
|
+
* The permission key column, or a reference to a permissions table that
|
|
264
|
+
* holds the key.
|
|
303
265
|
*/
|
|
304
|
-
readonly
|
|
266
|
+
readonly permission: string | RoleThrough;
|
|
267
|
+
/** A text column holding `allow` or `deny`. Without it every row allows. */
|
|
268
|
+
readonly effect?: string;
|
|
269
|
+
/** A text column holding the level of a leveled allow. */
|
|
270
|
+
readonly level?: string;
|
|
271
|
+
};
|
|
272
|
+
readonly includes?: {
|
|
273
|
+
readonly table: string;
|
|
274
|
+
/** The reference to the including role's row in the roles table. */
|
|
275
|
+
readonly role: RoleThrough;
|
|
276
|
+
/** The included role's key column, or a reference to the roles table. */
|
|
277
|
+
readonly include: string | RoleThrough;
|
|
305
278
|
};
|
|
279
|
+
};
|
|
280
|
+
/** One trigger the application owns on a generated table (`rls.triggers`). */
|
|
281
|
+
type RlsTrigger = {
|
|
282
|
+
/** The trigger name; `permdock_` is reserved for generated triggers. */
|
|
283
|
+
readonly name: string;
|
|
284
|
+
readonly when: "before" | "after";
|
|
285
|
+
readonly events: readonly ("insert" | "update" | "delete" | "truncate")[];
|
|
286
|
+
/** Default `row`. */
|
|
287
|
+
readonly level?: "row" | "statement";
|
|
288
|
+
/** `schema.function`, a trigger function that already exists. */
|
|
289
|
+
readonly function: string;
|
|
290
|
+
/** String arguments passed to the trigger function. */
|
|
291
|
+
readonly args?: readonly string[];
|
|
292
|
+
};
|
|
293
|
+
/**
|
|
294
|
+
* `rls.audit`: one `select <function>('<schema>.<table>'::regclass, <args>)`
|
|
295
|
+
* per generated table, for an audit module that registers a table by creating
|
|
296
|
+
* its own trigger.
|
|
297
|
+
*/
|
|
298
|
+
type RlsAudit = {
|
|
299
|
+
/** `schema.function` taking the table as its first argument. */
|
|
300
|
+
readonly function: string;
|
|
306
301
|
/**
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* `exchangeCapability` mints. Off by default.
|
|
302
|
+
* Generated tables, without the schema. Default the custom-role tables and
|
|
303
|
+
* `user_roles`, those this run creates.
|
|
310
304
|
*/
|
|
311
|
-
readonly
|
|
305
|
+
readonly tables?: readonly string[];
|
|
312
306
|
/**
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* `authenticated` role, so without it the grants to roles and to
|
|
316
|
-
* `authenticated()` reach it. The subject mapper has to refuse it in process
|
|
317
|
-
* too. Off by default.
|
|
307
|
+
* Named text arguments: `{ tenant_column: 'tenant_id' }` passes
|
|
308
|
+
* `tenant_column => 'tenant_id'`.
|
|
318
309
|
*/
|
|
319
|
-
readonly
|
|
310
|
+
readonly args?: Readonly<Record<string, string>>;
|
|
311
|
+
};
|
|
312
|
+
/** `rls.customRoleWrites.audit`: the function a by-id custom-role save calls. */
|
|
313
|
+
type RlsCustomRoleAudit = {
|
|
320
314
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* find no subject for `anon` and return nothing. Off by default: a policy
|
|
324
|
-
* that calls a helper says `to authenticated`.
|
|
315
|
+
* `schema.function` taking named `event_type`, `target_type`, `record_id`,
|
|
316
|
+
* `tenant` and `metadata` arguments.
|
|
325
317
|
*/
|
|
326
|
-
readonly
|
|
318
|
+
readonly function: string;
|
|
327
319
|
/**
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* in `tables` (such as invitations) refuses a client write that assigns,
|
|
331
|
-
* changes or removes a role the caller may not assign there, by the policy's
|
|
332
|
-
* `assigns` graph or, for a custom role, by what the caller may hand out.
|
|
333
|
-
* Writes that do not run as a client role (the table owner, a `security
|
|
334
|
-
* definer` function, a backend role) are trusted. Needs a role that declares
|
|
335
|
-
* `assigns`.
|
|
320
|
+
* Extra named text arguments: `{ actor_kind: 'user' }` passes `actor_kind =>
|
|
321
|
+
* 'user'`.
|
|
336
322
|
*/
|
|
337
|
-
readonly
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
323
|
+
readonly args?: Readonly<Record<string, string>>;
|
|
324
|
+
};
|
|
325
|
+
/** `rls.shims`: where the legacy-named wrappers go. */
|
|
326
|
+
type RlsShimsConfig = {
|
|
327
|
+
/** Schema of the legacy helpers. Default `public`. */
|
|
328
|
+
readonly schema?: string;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* An action verb's SQL command, or `'none'` for a verb that only `permdock_has`
|
|
332
|
+
* answers.
|
|
333
|
+
*/
|
|
334
|
+
type RlsActions = Readonly<Record<string, "select" | "insert" | "update" | "delete" | "none">>;
|
|
335
|
+
/**
|
|
336
|
+
* One existing SQL helper `rls migrate` rewrites. `form` names its arguments:
|
|
337
|
+
* `ids(key)` returns scope ids, `row(id, key)` and `membership(id)` test one
|
|
338
|
+
* id, `scoped(scope, id, key)` takes the scope as a literal, `global(key)`
|
|
339
|
+
* returns a boolean.
|
|
340
|
+
*/
|
|
341
|
+
type RlsMigrateHelper = {
|
|
342
|
+
readonly form: "ids" | "row" | "membership";
|
|
343
|
+
readonly scope: string;
|
|
344
|
+
} | {
|
|
345
|
+
readonly form: "role";
|
|
346
|
+
readonly scope: string;
|
|
347
|
+
} | {
|
|
348
|
+
readonly form: "scoped";
|
|
349
|
+
} | {
|
|
350
|
+
readonly form: "global";
|
|
351
|
+
};
|
|
352
|
+
type RlsMigrateConfig = {
|
|
353
|
+
/** By function name, without the schema. */
|
|
354
|
+
readonly helpers: Readonly<Record<string, RlsMigrateHelper>>;
|
|
355
|
+
/** Exact key renames, checked before `prefixes`. */
|
|
356
|
+
readonly keys?: Readonly<Record<string, string>>;
|
|
357
|
+
/** Key prefix renames, longest first: `{ 'organization.': '' }`. */
|
|
358
|
+
readonly prefixes?: Readonly<Record<string, string>>;
|
|
348
359
|
/**
|
|
349
|
-
*
|
|
350
|
-
* `
|
|
351
|
-
* the helper schema, executable by no client role. Off by default. An object
|
|
352
|
-
* with `table` adopts a table the app already has instead, and `delegations:
|
|
353
|
-
* true` adds the out-of-office covers.
|
|
360
|
+
* For `scoped` helpers, the scope literals that mean a global check, such as
|
|
361
|
+
* `system`.
|
|
354
362
|
*/
|
|
355
|
-
readonly
|
|
363
|
+
readonly globalScopes?: readonly string[];
|
|
356
364
|
/**
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
* `extensions`. Off by default. `'auto'` is refused: it needed a `do` block.
|
|
365
|
+
* For `scoped` helpers, a scope literal's PermDock scope when the names
|
|
366
|
+
* differ.
|
|
360
367
|
*/
|
|
361
|
-
readonly
|
|
368
|
+
readonly scopes?: Readonly<Record<string, string>>;
|
|
362
369
|
/**
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
370
|
+
* Materialised permission tables to retire, by `schema.table`: a table the
|
|
371
|
+
* application keeps in step with triggers and reads instead of the grants.
|
|
372
|
+
* `rls migrate --retire-out` drops it with its refresh triggers once nothing
|
|
373
|
+
* else reads it.
|
|
367
374
|
*/
|
|
368
|
-
readonly
|
|
375
|
+
readonly tables?: Readonly<Record<string, RlsMigrateTable>>;
|
|
376
|
+
};
|
|
377
|
+
type RlsMigrateTable = {
|
|
369
378
|
/**
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* the write when the token's `act` claim names one of these actor kinds,
|
|
373
|
-
* unless `act.read_only` is `false`. `true` is `['support',
|
|
374
|
-
* 'impersonation']`; with `support`, an `act` with a `session_id` and no
|
|
375
|
-
* `kind` counts too. Off by default.
|
|
379
|
+
* The functions that keep the table in step. Default: every function in
|
|
380
|
+
* `--sql` whose body writes it, and every function that calls one.
|
|
376
381
|
*/
|
|
377
|
-
readonly
|
|
378
|
-
|
|
382
|
+
readonly refresh?: readonly string[];
|
|
383
|
+
};
|
|
384
|
+
/** Where global roles live: `table (user, role)`. Defaults `user_id` and `role`. */
|
|
385
|
+
type GlobalRoles = {
|
|
386
|
+
readonly table: string;
|
|
387
|
+
readonly user?: string;
|
|
388
|
+
readonly role?: string | RoleThrough;
|
|
389
|
+
};
|
|
390
|
+
/** A permission reference from the app's definitions; only its `key` is read. */
|
|
391
|
+
type RlsPermissionRef = {
|
|
392
|
+
readonly key: string;
|
|
393
|
+
};
|
|
394
|
+
/**
|
|
395
|
+
* One private Realtime topic pattern, such as `org:{organization}:chat`:
|
|
396
|
+
* `:`-separated segments, one of them `{<scope>}`, which holds the id of a
|
|
397
|
+
* scope instance.
|
|
398
|
+
*/
|
|
399
|
+
type RlsRealtimeTopic = {
|
|
400
|
+
/** Receive broadcast and presence messages: `select` on `realtime.messages`. */
|
|
401
|
+
readonly read: RlsPermissionRef;
|
|
402
|
+
/** Send broadcast messages and track presence: `insert`. Absent: nobody may. */
|
|
403
|
+
readonly write?: RlsPermissionRef;
|
|
404
|
+
};
|
|
405
|
+
type RlsRealtime = {
|
|
406
|
+
readonly topics: Readonly<Record<string, RlsRealtimeTopic>>;
|
|
407
|
+
};
|
|
408
|
+
/** One Storage bucket whose object paths start with a scope instance id. */
|
|
409
|
+
type RlsStorageBucket = {
|
|
410
|
+
readonly scope: string;
|
|
411
|
+
/** The 1-based `storage.foldername(name)` entry that holds the id. Default 1. */
|
|
412
|
+
readonly folder?: number;
|
|
413
|
+
/** Download and list: `select` on `storage.objects`. */
|
|
414
|
+
readonly read?: RlsPermissionRef;
|
|
415
|
+
/** Upload and overwrite: `insert` and `update`. */
|
|
416
|
+
readonly write?: RlsPermissionRef;
|
|
417
|
+
readonly delete?: RlsPermissionRef;
|
|
418
|
+
};
|
|
419
|
+
type RlsStorage = {
|
|
420
|
+
readonly buckets: Readonly<Record<string, RlsStorageBucket>>;
|
|
421
|
+
};
|
|
422
|
+
type RlsDialect = "supabase" | "neon" | "guc";
|
|
423
|
+
type RlsTarget = "sql" | "drizzle" | "prisma";
|
|
424
|
+
type RlsMembershipTable = {
|
|
425
|
+
readonly table: string;
|
|
426
|
+
readonly user: string;
|
|
379
427
|
/**
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
* a grant passes only when one of the token's scopes reaches its permission
|
|
383
|
-
* (the permission's own scope, a former scope, or a policy `oauthScopes`
|
|
384
|
-
* entry). Denies always apply. Off by default.
|
|
428
|
+
* The role key column, a reference to a roles table that holds the key, or
|
|
429
|
+
* several of them: the row holds every non-null key.
|
|
385
430
|
*/
|
|
386
|
-
readonly
|
|
431
|
+
readonly role: string | RoleMap | RoleThrough | readonly (string | RoleMap | RoleThrough)[];
|
|
387
432
|
/**
|
|
388
|
-
*
|
|
389
|
-
*
|
|
433
|
+
* Per scope name, the column holding that scope's id: the table's own scope
|
|
434
|
+
* and its ancestors.
|
|
390
435
|
*/
|
|
391
|
-
readonly
|
|
436
|
+
readonly columns?: Readonly<Record<string, string>>;
|
|
437
|
+
readonly id?: string;
|
|
438
|
+
readonly expiresAt?: string;
|
|
439
|
+
readonly disabledAt?: string;
|
|
392
440
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
441
|
+
* The membership kind (`Membership.via`) roles with `for` match: a column
|
|
442
|
+
* holding it, or `{ value }` when every row has the same kind.
|
|
395
443
|
*/
|
|
396
|
-
readonly
|
|
444
|
+
readonly via?: string | {
|
|
445
|
+
readonly value: string;
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
type RlsMemberships = {
|
|
449
|
+
/** The membership table of each named scope. */
|
|
450
|
+
readonly scopes?: Readonly<Record<string, RlsMembershipTable>>;
|
|
451
|
+
readonly resource?: Readonly<Record<string, RlsMembershipTable>>;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* A table whose row says whether a user or a scope instance is active. A
|
|
455
|
+
* missing row counts as suspended.
|
|
456
|
+
*/
|
|
457
|
+
type RlsActiveRow = {
|
|
458
|
+
readonly table: string;
|
|
459
|
+
/** Column holding the user id or the scope instance id. */
|
|
460
|
+
readonly id: string;
|
|
461
|
+
/** Nullable timestamp column; a row with a value is suspended. */
|
|
462
|
+
readonly disabledAt?: string;
|
|
463
|
+
/** Status column; only a row whose value is in `active` counts as active. */
|
|
464
|
+
readonly status?: string;
|
|
465
|
+
readonly active?: readonly string[];
|
|
466
|
+
};
|
|
467
|
+
/**
|
|
468
|
+
* A scope's active-row table, with the permissions its suspended instances
|
|
469
|
+
* keep.
|
|
470
|
+
*/
|
|
471
|
+
type RlsSuspendedScope = RlsActiveRow & {
|
|
397
472
|
/**
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
* `<schema>.<table>_mask(p_row)`, which nulls the restricted columns of one
|
|
402
|
-
* row by the same masks, for SQL that reads the table without the view. Off
|
|
403
|
-
* by default.
|
|
473
|
+
* Permissions (references or keys) members of a suspended instance, and of
|
|
474
|
+
* every instance nested in it, still hold: restoring it, cancelling a
|
|
475
|
+
* scheduled deletion, exporting before a purge.
|
|
404
476
|
*/
|
|
405
|
-
readonly
|
|
477
|
+
readonly keep?: readonly (string | {
|
|
478
|
+
readonly key: string;
|
|
479
|
+
})[];
|
|
480
|
+
};
|
|
481
|
+
type RlsSuspendedMembership = {
|
|
482
|
+
readonly keep?: readonly (string | {
|
|
483
|
+
readonly key: string;
|
|
484
|
+
})[];
|
|
485
|
+
};
|
|
486
|
+
type RlsSuspension = {
|
|
487
|
+
/** A suspended user holds no role and no membership. */
|
|
488
|
+
readonly users?: RlsActiveRow;
|
|
406
489
|
/**
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* through the view. Breaks `select *`.
|
|
490
|
+
* Per scope name: a suspended instance voids its memberships and every
|
|
491
|
+
* membership nested under it, except for `keep`.
|
|
410
492
|
*/
|
|
411
|
-
readonly
|
|
493
|
+
readonly scopes?: Readonly<Record<string, RlsSuspendedScope>>;
|
|
494
|
+
readonly memberships?: RlsSuspendedMembership;
|
|
495
|
+
};
|
|
496
|
+
type RlsFunctionMapping = {
|
|
497
|
+
readonly twin: unknown;
|
|
498
|
+
readonly args?: readonly string[];
|
|
499
|
+
};
|
|
500
|
+
/**
|
|
501
|
+
* A table whose rows reach their scope through a parent table (`rls.tables`,
|
|
502
|
+
* `via`): the table's `key` column holds the parent's id, and the parent's
|
|
503
|
+
* `column` holds the scope instance id. The generated policies call
|
|
504
|
+
* `permitted_<parent, singular>_ids(p_grant)`, a `security definer` helper that
|
|
505
|
+
* joins the parent to `permitted_<scope>_ids`.
|
|
506
|
+
*/
|
|
507
|
+
type RlsTableVia = {
|
|
508
|
+
/** `schema.table` of the parent. */
|
|
509
|
+
readonly table: string;
|
|
510
|
+
/** The parent's column holding the scope instance id. */
|
|
511
|
+
readonly column: string;
|
|
412
512
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
513
|
+
* This table's column holding the parent's id. Default `<parent table,
|
|
514
|
+
* singular>_id`.
|
|
415
515
|
*/
|
|
416
|
-
readonly
|
|
417
|
-
/**
|
|
418
|
-
readonly
|
|
419
|
-
readonly schema?: string;
|
|
420
|
-
readonly authorize?: "database" | "jwt";
|
|
421
|
-
};
|
|
516
|
+
readonly key?: string;
|
|
517
|
+
/** The parent's id column. Default `id`. */
|
|
518
|
+
readonly id?: string;
|
|
422
519
|
/**
|
|
423
|
-
*
|
|
424
|
-
*
|
|
520
|
+
* SQL type of the parent's id column. Default `uuid` in the `supabase`
|
|
521
|
+
* dialect, else `text`.
|
|
425
522
|
*/
|
|
426
|
-
readonly
|
|
523
|
+
readonly type?: string;
|
|
524
|
+
/** The scope `column` holds. Default the policy's root scope. */
|
|
525
|
+
readonly scope?: string;
|
|
526
|
+
};
|
|
527
|
+
/**
|
|
528
|
+
* A resource's table. `false` is a resource with no table. `{ tableOf }` is the
|
|
529
|
+
* older way to store a resource in another resource's table; `also` on the
|
|
530
|
+
* owner replaces it. `follows` names child tables whose policies are an
|
|
531
|
+
* `exists` of `can_<resource>` on this row. `walk: "recursive"` is the manager
|
|
532
|
+
* chain: one recursive set helper.
|
|
533
|
+
*/
|
|
534
|
+
type RlsTableOwner = {
|
|
535
|
+
readonly table?: string;
|
|
536
|
+
readonly via?: RlsTableVia;
|
|
537
|
+
/** Other resources stored in this table. They get no policies of their own. */
|
|
538
|
+
readonly also?: readonly string[];
|
|
427
539
|
/**
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* `delete`). `'none'` compiles no policy. Every granted action is seeded into
|
|
431
|
-
* `role_permissions` either way, so `permdock_has` answers for it.
|
|
540
|
+
* Child table to the column that holds this resource's id. Each child gets
|
|
541
|
+
* select, insert, update and delete policies that call `can_<resource>`.
|
|
432
542
|
*/
|
|
433
|
-
readonly
|
|
543
|
+
readonly follows?: Readonly<Record<string, string>>;
|
|
544
|
+
/** A self-parented resource walked as one recursive set, the manager chain. */
|
|
545
|
+
readonly walk?: "recursive";
|
|
434
546
|
/**
|
|
435
|
-
*
|
|
436
|
-
*
|
|
547
|
+
* With `walk`, the column holding the row's user id, where the caller's walk
|
|
548
|
+
* starts. The id column when unset, which suits a users table.
|
|
437
549
|
*/
|
|
438
|
-
readonly
|
|
550
|
+
readonly user?: string;
|
|
551
|
+
};
|
|
552
|
+
type RlsTable = string | false | RlsTableOwner | {
|
|
553
|
+
readonly tableOf: string;
|
|
554
|
+
};
|
|
555
|
+
type RlsConfig = {
|
|
439
556
|
/**
|
|
440
|
-
*
|
|
441
|
-
*
|
|
442
|
-
* scope helpers and the `rowHelpers` sets. `'better-supabase'` calls
|
|
443
|
-
* `better_supabase.memo_get` and `memo_set`, so the memo shares
|
|
444
|
-
* better-supabase's one mechanism; the keys stay `permdock.m.*`. Needs the
|
|
445
|
-
* `better_supabase` schema. `'none'` (default) writes no memo: the helpers
|
|
446
|
-
* are `language sql stable parallel safe`, and a policy's `id in (select
|
|
447
|
-
* helper())` is one initPlan per statement.
|
|
557
|
+
* Per resource, the table its policies target; the table is named after the
|
|
558
|
+
* resource when unset, and `false` means it has none.
|
|
448
559
|
*/
|
|
449
|
-
readonly
|
|
560
|
+
readonly tables?: Readonly<Record<string, RlsTable>>;
|
|
561
|
+
readonly dialect?: RlsDialect;
|
|
562
|
+
readonly memberships?: RlsMemberships;
|
|
450
563
|
/**
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
* the generated policies decide them.
|
|
564
|
+
* `database` mode: the `tableMembershipSource` / `junctionMembershipSource`
|
|
565
|
+
* sources the helpers read for every scope `memberships` maps no table for.
|
|
566
|
+
* Default `supabase.hook.memberships`, so the helpers and the token hook run
|
|
567
|
+
* the same SQL. Setting it selects `database` mode.
|
|
456
568
|
*/
|
|
457
|
-
readonly
|
|
569
|
+
readonly membershipSources?: readonly SqlMembershipSource[];
|
|
458
570
|
/**
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
* no seeds migration: call `select <schema>.seed();` after each deploy.
|
|
462
|
-
*
|
|
463
|
-
* `'view'`: `role_permissions` is a `security_invoker` view over a `values`
|
|
464
|
-
* list, so the rows travel with the declarative schema and need no seeding
|
|
465
|
-
* step. Nothing can write the rows, so the view cannot take hand-added ones.
|
|
571
|
+
* Tables the helpers, `authorize()` and the token hook read to drop suspended
|
|
572
|
+
* users and scope instances.
|
|
466
573
|
*/
|
|
467
|
-
readonly
|
|
574
|
+
readonly suspension?: RlsSuspension;
|
|
575
|
+
readonly functions?: Readonly<Record<string, RlsFunctionMapping>>;
|
|
576
|
+
readonly inlineFunctions?: boolean;
|
|
468
577
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
* bundle from `<schema>.permdock_policy_bundle`; a bundle that is not loaded,
|
|
472
|
-
* or has another hash, denies every static grant. `'inline'` (the default)
|
|
473
|
-
* keeps the rows in the SQL as `rls.seeds` says. `'ref'` makes
|
|
474
|
-
* `role_permissions` a view, so it cannot combine with `seeds: 'function'`.
|
|
578
|
+
* Emit FORCE ROW LEVEL SECURITY so the table owner is subject to the
|
|
579
|
+
* policies.
|
|
475
580
|
*/
|
|
476
|
-
readonly
|
|
477
|
-
readonly
|
|
478
|
-
readonly treeValues?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
479
|
-
/** `rls migrate`: how existing helper calls map onto the generated helpers. */
|
|
480
|
-
readonly migrate?: RlsMigrateConfig;
|
|
581
|
+
readonly force?: boolean;
|
|
582
|
+
readonly fixtures?: string;
|
|
481
583
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
*
|
|
584
|
+
* `rls verify` findings accepted as a baseline. `id` is the
|
|
585
|
+
* `<code>:<table>:<key>` the finding prints; `reason` is required. An entry
|
|
586
|
+
* no finding matches is a warning, so the baseline shrinks.
|
|
485
587
|
*/
|
|
486
|
-
readonly
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
readonly
|
|
493
|
-
readonly name?: string;
|
|
494
|
-
readonly body?: string;
|
|
495
|
-
readonly enabled?: string;
|
|
496
|
-
readonly createdAt?: string;
|
|
497
|
-
};
|
|
498
|
-
type RlsApprovalPolicies = {
|
|
499
|
-
/** The permission key whose holders in a tenant edit its policies. */
|
|
500
|
-
readonly manage: string;
|
|
588
|
+
readonly verify?: {
|
|
589
|
+
readonly ignore?: readonly {
|
|
590
|
+
readonly id: string;
|
|
591
|
+
readonly reason: string;
|
|
592
|
+
}[];
|
|
593
|
+
};
|
|
594
|
+
readonly tenantClaim?: string;
|
|
501
595
|
/**
|
|
502
|
-
*
|
|
503
|
-
*
|
|
596
|
+
* Which tenants the helpers and `memberOf` checks admit. `'active'`
|
|
597
|
+
* (default): when the token carries a non-empty `tenantClaim`, only that
|
|
598
|
+
* tenant; without one, every tenant the subject is a member of. `'all'`:
|
|
599
|
+
* every such tenant whatever the claim says, for apps whose tenant comes from
|
|
600
|
+
* the URL or the query.
|
|
504
601
|
*/
|
|
505
|
-
readonly
|
|
602
|
+
readonly tenants?: "active" | "all";
|
|
506
603
|
/**
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
*
|
|
604
|
+
* Postgres type of each named scope's id column, `uuid` by default. The first
|
|
605
|
+
* scope's type also types the tenant claim and the helper results cast to
|
|
606
|
+
* it.
|
|
510
607
|
*/
|
|
511
|
-
readonly
|
|
512
|
-
readonly columns?: RlsApprovalPolicyColumns;
|
|
608
|
+
readonly scopeTypes?: Readonly<Record<string, string>>;
|
|
513
609
|
/**
|
|
514
|
-
*
|
|
515
|
-
*
|
|
610
|
+
* Postgres type of each resource's id in the `rls.rowHelpers` helpers
|
|
611
|
+
* (`permitted_<resource>_rows` returns `setof <type>` and its `p_ids` takes
|
|
612
|
+
* `<type>[]`), by resource name; `"*"` sets the default. Without it: `uuid`
|
|
613
|
+
* on Supabase, `text` elsewhere.
|
|
516
614
|
*/
|
|
517
|
-
readonly
|
|
518
|
-
|
|
519
|
-
type RlsApprovalManagers = {
|
|
520
|
-
/** `table` or `schema.table`. */
|
|
521
|
-
readonly table: string;
|
|
522
|
-
/** The column holding the user's id. */
|
|
523
|
-
readonly user: string;
|
|
524
|
-
/** The column holding the id of that user's manager. */
|
|
525
|
-
readonly manager: string;
|
|
615
|
+
readonly idTypes?: Readonly<Record<string, string>>;
|
|
616
|
+
readonly roleClaim?: string;
|
|
526
617
|
/**
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
618
|
+
* Role values the existing SQL compares against (a string literal or an enum
|
|
619
|
+
* label) and the PermDock role each one is. `rls import` writes the PermDock
|
|
620
|
+
* name for a mapped value; `rls migrate` filters a `role` helper by it. An
|
|
621
|
+
* unmapped value must already be a declared role.
|
|
622
|
+
*/
|
|
623
|
+
readonly roleValues?: Readonly<Record<string, string>>;
|
|
624
|
+
readonly gucPrefix?: string;
|
|
625
|
+
readonly out?: string;
|
|
626
|
+
/**
|
|
627
|
+
* The parts `rls generate --split` writes when the flag is absent. The hook
|
|
628
|
+
* part also moves `supabase.hook.out`'s default, read by `supabase inspect`
|
|
629
|
+
* and doctor, to `out` with `{part}` replaced by `hook`.
|
|
630
|
+
*/
|
|
631
|
+
readonly split?: readonly ("helpers" | "seeds" | "indexes" | "policies" | "hook")[];
|
|
632
|
+
/** `--target drizzle`: where each policy's `.link()` finds its table. */
|
|
633
|
+
readonly drizzle?: {
|
|
634
|
+
/** Module exporting the tables, as imported from `out`. Default `./schema`. */
|
|
635
|
+
readonly schema?: string;
|
|
636
|
+
/**
|
|
637
|
+
* Export name per table name; defaults to the camelCased table name without
|
|
638
|
+
* its schema.
|
|
639
|
+
*/
|
|
640
|
+
readonly exports?: Readonly<Record<string, string>>;
|
|
641
|
+
};
|
|
642
|
+
/** `--target prisma`: the model each table maps to. */
|
|
643
|
+
readonly prisma?: {
|
|
644
|
+
/**
|
|
645
|
+
* Model name per table name; defaults to the PascalCased table name without
|
|
646
|
+
* its schema.
|
|
647
|
+
*/
|
|
648
|
+
readonly models?: Readonly<Record<string, string>>;
|
|
649
|
+
};
|
|
650
|
+
/**
|
|
651
|
+
* Schema of `role_permissions` and the RLS helpers (`permdock_has`,
|
|
652
|
+
* `permitted_<scope>_ids`, `member_<scope>_ids`) (and the RBAC scaffold).
|
|
653
|
+
* Default `permdock`; keep it out of `[api] schemas`.
|
|
654
|
+
*/
|
|
655
|
+
readonly schema?: string;
|
|
656
|
+
/**
|
|
657
|
+
* Where the helpers read roles and memberships: `database` tables or `jwt`
|
|
658
|
+
* claims.
|
|
659
|
+
*/
|
|
660
|
+
readonly authorize?: "database" | "jwt";
|
|
661
|
+
/** One policy per role and permission instead of one per table and command. */
|
|
662
|
+
readonly policyPerRole?: boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Resolve tenant-defined custom roles in the helpers:
|
|
665
|
+
* `custom_role_permissions` and `custom_role_includes` in `database` mode,
|
|
666
|
+
* the `memberships[].grants` claim in `jwt` mode, always intersected with the
|
|
667
|
+
* `permdock_ceiling` view. Off by default. An object turns them on and names
|
|
668
|
+
* the application's existing role tables that `--backfill-out` copies from.
|
|
669
|
+
*/
|
|
670
|
+
readonly customRoles?: boolean | RlsCustomRolesConfig;
|
|
671
|
+
/**
|
|
672
|
+
* Triggers the application owns on tables `generate` creates, by table name
|
|
673
|
+
* without the schema (`custom_role_permissions`): written after the tables,
|
|
674
|
+
* each as `drop trigger if exists` and `create trigger`.
|
|
675
|
+
*/
|
|
676
|
+
readonly triggers?: Readonly<Record<string, readonly RlsTrigger[]>>;
|
|
677
|
+
/**
|
|
678
|
+
* Register generated tables with an audit function, such as
|
|
679
|
+
* `better_supabase.audit`.
|
|
530
680
|
*/
|
|
531
|
-
readonly
|
|
532
|
-
};
|
|
533
|
-
/**
|
|
534
|
-
* `rls.approvals` on a table the app already has: the store functions keep each
|
|
535
|
-
* request's body in `body` and its token in `token` (both added when missing)
|
|
536
|
-
* and read every field from the body; `mirror` copies request fields into the
|
|
537
|
-
* app's own columns on each write, converted to their types.
|
|
538
|
-
*/
|
|
539
|
-
type RlsApprovalsAdopt = {
|
|
540
|
-
readonly store?: boolean;
|
|
681
|
+
readonly audit?: RlsAudit;
|
|
541
682
|
/**
|
|
542
|
-
*
|
|
543
|
-
* `
|
|
683
|
+
* How the generated custom-role write functions check the caller (`database`
|
|
684
|
+
* mode with `customRoles`).
|
|
544
685
|
*/
|
|
545
|
-
readonly
|
|
686
|
+
readonly customRoleWrites?: {
|
|
687
|
+
/**
|
|
688
|
+
* Who may change custom roles at all, checked before the hand-out check:
|
|
689
|
+
* permission keys of which the caller must hold one in the tenant (or
|
|
690
|
+
* through a global role; only through a global role for a platform custom
|
|
691
|
+
* role), or `'manageRoles'` for any permission with `meta.manageRoles`.
|
|
692
|
+
* Unset, any member may write a role within what they may hand out.
|
|
693
|
+
*/
|
|
694
|
+
readonly requires?: "manageRoles" | readonly string[];
|
|
695
|
+
/**
|
|
696
|
+
* The application's own roles table, one row per custom role. A trigger on
|
|
697
|
+
* it moves a role's grants and includes when the row's name, tenant, scope
|
|
698
|
+
* or instance changes, and deletes them with the row. A signed-in caller
|
|
699
|
+
* goes through the same checks as the write functions; a trusted path (a
|
|
700
|
+
* migration, a job, a nested trigger) moves the rows directly.
|
|
701
|
+
*/
|
|
702
|
+
readonly roles?: RlsCustomRoleTable;
|
|
703
|
+
/**
|
|
704
|
+
* The audit function the by-id writers call after a save
|
|
705
|
+
* (`permdock_replace_custom_role_grants_by_id`), with `event_type`,
|
|
706
|
+
* `target_type`, `record_id`, `tenant` and `metadata` plus `args`. Needs
|
|
707
|
+
* `roles.primaryKey`.
|
|
708
|
+
*/
|
|
709
|
+
readonly audit?: RlsCustomRoleAudit;
|
|
710
|
+
};
|
|
546
711
|
/**
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
* same rows for `approvalsHandler`. Off by default.
|
|
712
|
+
* Let link capabilities reach resource-scoped grants: `anon` policies that
|
|
713
|
+
* call `permdock_capability_ids`, which reads the `capability` claim
|
|
714
|
+
* `exchangeCapability` mints. Off by default.
|
|
551
715
|
*/
|
|
552
|
-
readonly
|
|
716
|
+
readonly capabilities?: boolean;
|
|
553
717
|
/**
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
718
|
+
* `'deny'` (Supabase only): a token with `is_anonymous: true` reaches no
|
|
719
|
+
* grant but those to `anyone()`. Supabase gives an anonymous sign-in the
|
|
720
|
+
* `authenticated` role, so without it the grants to roles and to
|
|
721
|
+
* `authenticated()` reach it. The subject mapper has to refuse it in process
|
|
722
|
+
* too. Off by default.
|
|
559
723
|
*/
|
|
560
|
-
readonly
|
|
724
|
+
readonly anonymousSignIns?: "deny";
|
|
561
725
|
/**
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
* `
|
|
726
|
+
* Grant `anon` usage on the helper schema and `execute` on the helpers, for
|
|
727
|
+
* hand-written policies that apply to `public` or `anon` and call them. They
|
|
728
|
+
* find no subject for `anon` and return nothing. Off by default: a policy
|
|
729
|
+
* that calls a helper says `to authenticated`.
|
|
565
730
|
*/
|
|
566
|
-
readonly
|
|
567
|
-
/** A text column unique per request. Default `token`. */
|
|
568
|
-
readonly token?: string;
|
|
569
|
-
/** A jsonb column holding the `ApprovalRequest`. Default `body`. */
|
|
570
|
-
readonly body?: string;
|
|
571
|
-
readonly open?: "insert" | "attach";
|
|
572
|
-
readonly schema?: string;
|
|
573
|
-
/** Request fields copied into the app's columns, field to column. */
|
|
574
|
-
readonly mirror?: {
|
|
575
|
-
readonly status?: string;
|
|
576
|
-
readonly permission?: string;
|
|
577
|
-
readonly tenant?: string;
|
|
578
|
-
readonly principalId?: string;
|
|
579
|
-
readonly actorId?: string;
|
|
580
|
-
readonly session?: string;
|
|
581
|
-
readonly approvals?: string;
|
|
582
|
-
readonly createdAt?: string;
|
|
583
|
-
readonly expiresAt?: string;
|
|
584
|
-
readonly resolvedAt?: string;
|
|
585
|
-
readonly resolvedBy?: string;
|
|
586
|
-
readonly consumedAt?: string;
|
|
587
|
-
};
|
|
588
|
-
};
|
|
589
|
-
type RlsApiKeys = {
|
|
590
|
-
readonly claim?: string;
|
|
591
|
-
readonly scopes?: string;
|
|
592
|
-
readonly tenant?: string;
|
|
593
|
-
readonly roles?: string;
|
|
594
|
-
readonly serviceRoles?: readonly string[];
|
|
595
|
-
};
|
|
596
|
-
/**
|
|
597
|
-
* One more table whose rows assign a role, such as invitations
|
|
598
|
-
* (`rls.assignments.tables`).
|
|
599
|
-
*/
|
|
600
|
-
type RlsAssignmentTable = {
|
|
601
|
-
readonly table: string;
|
|
602
|
-
/** The declared scope the row assigns the role at. */
|
|
603
|
-
readonly scope: string;
|
|
604
|
-
/** The column holding the scope instance id. */
|
|
605
|
-
readonly id: string;
|
|
731
|
+
readonly anonExecute?: boolean;
|
|
606
732
|
/**
|
|
607
|
-
*
|
|
608
|
-
*
|
|
733
|
+
* Check role assignments in the database: a trigger on each scope's
|
|
734
|
+
* `rls.memberships` table, the global-roles table `rls.roles` and each table
|
|
735
|
+
* in `tables` (such as invitations) refuses a client write that assigns,
|
|
736
|
+
* changes or removes a role the caller may not assign there, by the policy's
|
|
737
|
+
* `assigns` graph or, for a custom role, by what the caller may hand out.
|
|
738
|
+
* Writes that do not run as a client role (the table owner, a `security
|
|
739
|
+
* definer` function, a backend role) are trusted. Needs a role that declares
|
|
740
|
+
* `assigns`.
|
|
609
741
|
*/
|
|
610
|
-
readonly
|
|
742
|
+
readonly assignments?: true | {
|
|
743
|
+
readonly tables?: readonly RlsAssignmentTable[];
|
|
744
|
+
/**
|
|
745
|
+
* `'refuse'`: a client write to a row whose user is the caller is
|
|
746
|
+
* refused on every guarded table with a user column, whatever the role.
|
|
747
|
+
* A map refuses it on the tables it names (`schema.table` as
|
|
748
|
+
* configured). Unset, a caller may change their own row within what
|
|
749
|
+
* they may assign.
|
|
750
|
+
*/
|
|
751
|
+
readonly ownRole?: "refuse" | Readonly<Record<string, "refuse">>;
|
|
752
|
+
};
|
|
611
753
|
/**
|
|
612
|
-
*
|
|
613
|
-
*
|
|
754
|
+
* Add the approval store `supabaseApprovalStore` reads and writes: the
|
|
755
|
+
* `approval_requests` table and one function per `ApprovalStore` method, in
|
|
756
|
+
* the helper schema, executable by no client role. Off by default. An object
|
|
757
|
+
* with `table` adopts a table the app already has instead, and `delegations:
|
|
758
|
+
* true` adds the out-of-office covers.
|
|
614
759
|
*/
|
|
615
|
-
readonly
|
|
760
|
+
readonly approvals?: boolean | RlsApprovalsAdopt;
|
|
616
761
|
/**
|
|
617
|
-
*
|
|
618
|
-
*
|
|
762
|
+
* A pg_jsonschema check constraint on the approval store's `body`: it must
|
|
763
|
+
* match `approval-request-v1.json`. `true` installs the extension into
|
|
764
|
+
* `extensions`. Off by default. `'auto'` is refused: it needed a `do` block.
|
|
619
765
|
*/
|
|
620
|
-
readonly
|
|
621
|
-
};
|
|
622
|
-
/** `rls.customRoleWrites.roles`: the application's table of custom roles. */
|
|
623
|
-
type RlsCustomRoleTable = {
|
|
624
|
-
readonly table: string;
|
|
625
|
-
/** The column holding the role name. */
|
|
626
|
-
readonly key: string;
|
|
766
|
+
readonly jsonSchema?: boolean;
|
|
627
767
|
/**
|
|
628
|
-
*
|
|
629
|
-
*
|
|
768
|
+
* `false` leaves out the holder-count and transfer-only triggers `min`, `max`
|
|
769
|
+
* and `transferOnly` put on the membership tables; a map with `<scope>:
|
|
770
|
+
* false` leaves them out for those scopes only. Those rules are then checked
|
|
771
|
+
* by `decideRoleChange` alone. On by default.
|
|
630
772
|
*/
|
|
631
|
-
readonly
|
|
773
|
+
readonly ownershipTriggers?: false | Readonly<Record<string, false>>;
|
|
632
774
|
/**
|
|
633
|
-
*
|
|
634
|
-
*
|
|
775
|
+
* Make a session acting for a user read-only in the database: one restrictive
|
|
776
|
+
* policy per table and write command the generated policies allow, refusing
|
|
777
|
+
* the write when the token's `act` claim names one of these actor kinds,
|
|
778
|
+
* unless `act.read_only` is `false`. `true` is `['support',
|
|
779
|
+
* 'impersonation']`; with `support`, an `act` with a `session_id` and no
|
|
780
|
+
* `kind` counts too. Off by default.
|
|
635
781
|
*/
|
|
636
|
-
readonly
|
|
637
|
-
|
|
638
|
-
readonly id?: string;
|
|
782
|
+
readonly readOnlyActors?: boolean | readonly string[];
|
|
783
|
+
readonly apiKeys?: true | RlsApiKeys;
|
|
639
784
|
/**
|
|
640
|
-
*
|
|
641
|
-
*
|
|
785
|
+
* Narrow a delegated token (a `client_id`, or an `act` that is not a support
|
|
786
|
+
* or impersonation session) by its `scope` claim in every helper and policy:
|
|
787
|
+
* a grant passes only when one of the token's scopes reaches its permission
|
|
788
|
+
* (the permission's own scope, a former scope, or a policy `oauthScopes`
|
|
789
|
+
* entry). Denies always apply. Off by default.
|
|
642
790
|
*/
|
|
643
|
-
readonly
|
|
791
|
+
readonly tokenScopes?: boolean;
|
|
644
792
|
/**
|
|
645
|
-
*
|
|
646
|
-
*
|
|
793
|
+
* Supabase Realtime: policies on `realtime.messages` for private channels.
|
|
794
|
+
* Supabase dialect only.
|
|
647
795
|
*/
|
|
648
|
-
readonly
|
|
796
|
+
readonly realtime?: RlsRealtime;
|
|
649
797
|
/**
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
* no tenant is a platform role.
|
|
798
|
+
* Supabase Storage: policies on `storage.objects` for buckets keyed by a
|
|
799
|
+
* scope folder. Supabase dialect only.
|
|
653
800
|
*/
|
|
654
|
-
readonly
|
|
655
|
-
};
|
|
656
|
-
/**
|
|
657
|
-
* `rls.customRoles` as an object: custom roles on, plus where existing ones
|
|
658
|
-
* live.
|
|
659
|
-
*/
|
|
660
|
-
type RlsCustomRolesConfig = {
|
|
801
|
+
readonly storage?: RlsStorage;
|
|
661
802
|
/**
|
|
662
|
-
*
|
|
663
|
-
*
|
|
803
|
+
* `'views'`: one `security_invoker` view `<table>_visible` per table with
|
|
804
|
+
* field-limited read grants, whose restricted columns are `case when
|
|
805
|
+
* <permitted> then col end`. `'mask'`: the same views plus
|
|
806
|
+
* `<schema>.<table>_mask(p_row)`, which nulls the restricted columns of one
|
|
807
|
+
* row by the same masks, for SQL that reads the table without the view. Off
|
|
808
|
+
* by default.
|
|
664
809
|
*/
|
|
665
|
-
readonly
|
|
666
|
-
};
|
|
667
|
-
/**
|
|
668
|
-
* Existing custom-role data. Each row's role is a row of
|
|
669
|
-
* `rls.customRoleWrites.roles`, which supplies its name, tenant, scope,
|
|
670
|
-
* instance and `skip` flag.
|
|
671
|
-
*/
|
|
672
|
-
type RlsCustomRolesFrom = {
|
|
810
|
+
readonly fields?: "views" | "mask";
|
|
673
811
|
/**
|
|
674
|
-
* `'
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
* PermDock grants follow the application's editor. Without it the backfill
|
|
678
|
-
* copies once.
|
|
812
|
+
* With `fields: 'views'` or `'mask'`, grant `anon` and `authenticated` only
|
|
813
|
+
* the unrestricted columns of the base table, so restricted columns are read
|
|
814
|
+
* through the view. Breaks `select *`.
|
|
679
815
|
*/
|
|
680
|
-
readonly
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
readonly
|
|
689
|
-
|
|
690
|
-
* The permission key column, or a reference to a permissions table that
|
|
691
|
-
* holds the key.
|
|
692
|
-
*/
|
|
693
|
-
readonly permission: string | RoleThrough;
|
|
694
|
-
/** A text column holding `allow` or `deny`. Without it every row allows. */
|
|
695
|
-
readonly effect?: string;
|
|
696
|
-
/** A text column holding the level of a leveled allow. */
|
|
697
|
-
readonly level?: string;
|
|
698
|
-
};
|
|
699
|
-
readonly includes?: {
|
|
700
|
-
readonly table: string;
|
|
701
|
-
/** The reference to the including role's row in the roles table. */
|
|
702
|
-
readonly role: RoleThrough;
|
|
703
|
-
/** The included role's key column, or a reference to the roles table. */
|
|
704
|
-
readonly include: string | RoleThrough;
|
|
816
|
+
readonly revokeColumns?: boolean;
|
|
817
|
+
/**
|
|
818
|
+
* Policy name template: `{table}`, `{op}`, plus `{role}` and `{permission}`
|
|
819
|
+
* with `policyPerRole`.
|
|
820
|
+
*/
|
|
821
|
+
readonly policyName?: string;
|
|
822
|
+
/** `rls generate --rbac supabase` defaults; flags override. */
|
|
823
|
+
readonly rbac?: {
|
|
824
|
+
readonly schema?: string;
|
|
825
|
+
readonly authorize?: "database" | "jwt";
|
|
705
826
|
};
|
|
706
|
-
};
|
|
707
|
-
/** One trigger the application owns on a generated table (`rls.triggers`). */
|
|
708
|
-
type RlsTrigger = {
|
|
709
|
-
/** The trigger name; `permdock_` is reserved for generated triggers. */
|
|
710
|
-
readonly name: string;
|
|
711
|
-
readonly when: "before" | "after";
|
|
712
|
-
readonly events: readonly ("insert" | "update" | "delete" | "truncate")[];
|
|
713
|
-
/** Default `row`. */
|
|
714
|
-
readonly level?: "row" | "statement";
|
|
715
|
-
/** `schema.function`, a trigger function that already exists. */
|
|
716
|
-
readonly function: string;
|
|
717
|
-
/** String arguments passed to the trigger function. */
|
|
718
|
-
readonly args?: readonly string[];
|
|
719
|
-
};
|
|
720
|
-
/**
|
|
721
|
-
* `rls.audit`: one `select <function>('<schema>.<table>'::regclass, <args>)`
|
|
722
|
-
* per generated table, for an audit module that registers a table by creating
|
|
723
|
-
* its own trigger.
|
|
724
|
-
*/
|
|
725
|
-
type RlsAudit = {
|
|
726
|
-
/** `schema.function` taking the table as its first argument. */
|
|
727
|
-
readonly function: string;
|
|
728
827
|
/**
|
|
729
|
-
*
|
|
730
|
-
*
|
|
828
|
+
* The global-roles table `permdock_has` reads in `database` mode. Default
|
|
829
|
+
* `<schema>.user_roles (user_id, role)`, which the helpers create.
|
|
731
830
|
*/
|
|
732
|
-
readonly
|
|
831
|
+
readonly roles?: GlobalRoles;
|
|
733
832
|
/**
|
|
734
|
-
*
|
|
735
|
-
* `
|
|
833
|
+
* The SQL command each action verb compiles to, merged over the defaults
|
|
834
|
+
* (`read`, `list`, `get` → `select`; `create` → `insert`; `update`;
|
|
835
|
+
* `delete`). `'none'` compiles no policy. Every granted action is seeded into
|
|
836
|
+
* `role_permissions` either way, so `permdock_has` answers for it.
|
|
736
837
|
*/
|
|
737
|
-
readonly
|
|
738
|
-
};
|
|
739
|
-
/** `rls.customRoleWrites.audit`: the function a by-id custom-role save calls. */
|
|
740
|
-
type RlsCustomRoleAudit = {
|
|
838
|
+
readonly actions?: RlsActions;
|
|
741
839
|
/**
|
|
742
|
-
*
|
|
743
|
-
*
|
|
840
|
+
* Emit only the helpers, their seeds and the scaffold; the table policies
|
|
841
|
+
* stay hand-written.
|
|
744
842
|
*/
|
|
745
|
-
readonly
|
|
843
|
+
readonly helpersOnly?: boolean;
|
|
746
844
|
/**
|
|
747
|
-
*
|
|
748
|
-
*
|
|
845
|
+
* Where the transaction-local helper memos live. `'permdock'` reads and
|
|
846
|
+
* writes `permdock.m.*` with `current_setting` and `set_config`, for the
|
|
847
|
+
* scope helpers and the `rowHelpers` sets. `'better-supabase'` calls
|
|
848
|
+
* `better_supabase.memo_get` and `memo_set`, so the memo shares
|
|
849
|
+
* better-supabase's one mechanism; the keys stay `permdock.m.*`. Needs the
|
|
850
|
+
* `better_supabase` schema. `'none'` (default) writes no memo: the helpers
|
|
851
|
+
* are `language sql stable parallel safe`, and a policy's `id in (select
|
|
852
|
+
* helper())` is one initPlan per statement.
|
|
749
853
|
*/
|
|
750
|
-
readonly
|
|
751
|
-
};
|
|
752
|
-
/** `rls.shims`: where the legacy-named wrappers go. */
|
|
753
|
-
type RlsShimsConfig = {
|
|
754
|
-
/** Schema of the legacy helpers. Default `public`. */
|
|
755
|
-
readonly schema?: string;
|
|
756
|
-
};
|
|
757
|
-
/**
|
|
758
|
-
* An action verb's SQL command, or `'none'` for a verb that only `permdock_has`
|
|
759
|
-
* answers.
|
|
760
|
-
*/
|
|
761
|
-
type RlsActions = Readonly<Record<string, "select" | "insert" | "update" | "delete" | "none">>;
|
|
762
|
-
/**
|
|
763
|
-
* One existing SQL helper `rls migrate` rewrites. `form` names its arguments:
|
|
764
|
-
* `ids(key)` returns scope ids, `row(id, key)` and `membership(id)` test one
|
|
765
|
-
* id, `scoped(scope, id, key)` takes the scope as a literal, `global(key)`
|
|
766
|
-
* returns a boolean.
|
|
767
|
-
*/
|
|
768
|
-
type RlsMigrateHelper = {
|
|
769
|
-
readonly form: "ids" | "row" | "membership";
|
|
770
|
-
readonly scope: string;
|
|
771
|
-
} | {
|
|
772
|
-
readonly form: "role";
|
|
773
|
-
readonly scope: string;
|
|
774
|
-
} | {
|
|
775
|
-
readonly form: "scoped";
|
|
776
|
-
} | {
|
|
777
|
-
readonly form: "global";
|
|
778
|
-
};
|
|
779
|
-
type RlsMigrateConfig = {
|
|
780
|
-
/** By function name, without the schema. */
|
|
781
|
-
readonly helpers: Readonly<Record<string, RlsMigrateHelper>>;
|
|
782
|
-
/** Exact key renames, checked before `prefixes`. */
|
|
783
|
-
readonly keys?: Readonly<Record<string, string>>;
|
|
784
|
-
/** Key prefix renames, longest first: `{ 'organization.': '' }`. */
|
|
785
|
-
readonly prefixes?: Readonly<Record<string, string>>;
|
|
854
|
+
readonly memo?: "permdock" | "better-supabase" | "none";
|
|
786
855
|
/**
|
|
787
|
-
*
|
|
788
|
-
* `
|
|
856
|
+
* Emit `permitted_<resource>_rows(p_permission)`, its `_for` form,
|
|
857
|
+
* `permitted_<resource>_rows(p_permission, p_ids)` limited to candidate ids
|
|
858
|
+
* and `can_<resource>(p_row, p_permission)` for these resources, or for every
|
|
859
|
+
* resource a grant reaches with `true`: the row ids the caller may act on, as
|
|
860
|
+
* the generated policies decide them.
|
|
789
861
|
*/
|
|
790
|
-
readonly
|
|
862
|
+
readonly rowHelpers?: true | readonly string[];
|
|
791
863
|
/**
|
|
792
|
-
*
|
|
793
|
-
*
|
|
864
|
+
* `'function'`: the `role_permissions` rows live in `<schema>.seed()`, which
|
|
865
|
+
* the helpers part creates. Declarative workflows (pg-delta, migra) then need
|
|
866
|
+
* no seeds migration: call `select <schema>.seed();` after each deploy.
|
|
867
|
+
*
|
|
868
|
+
* `'view'`: `role_permissions` is a `security_invoker` view over a `values`
|
|
869
|
+
* list, so the rows travel with the declarative schema and need no seeding
|
|
870
|
+
* step. Nothing can write the rows, so the view cannot take hand-added ones.
|
|
794
871
|
*/
|
|
795
|
-
readonly
|
|
872
|
+
readonly seeds?: "function" | "view";
|
|
796
873
|
/**
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
*
|
|
874
|
+
* `'ref'`: the static grants are not in the generated SQL. The helpers pin
|
|
875
|
+
* the hash of the policy bundle `permdock policy bundle` writes and read the
|
|
876
|
+
* bundle from `<schema>.permdock_policy_bundle`; a bundle that is not loaded,
|
|
877
|
+
* or has another hash, denies every static grant. `'inline'` (the default)
|
|
878
|
+
* keeps the rows in the SQL as `rls.seeds` says. `'ref'` makes
|
|
879
|
+
* `role_permissions` a view, so it cannot combine with `seeds: 'function'`.
|
|
801
880
|
*/
|
|
802
|
-
readonly
|
|
803
|
-
|
|
804
|
-
|
|
881
|
+
readonly staticGrants?: "inline" | "ref";
|
|
882
|
+
readonly trustedReaders?: readonly string[];
|
|
883
|
+
readonly treeValues?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
884
|
+
/** `rls migrate`: how existing helper calls map onto the generated helpers. */
|
|
885
|
+
readonly migrate?: RlsMigrateConfig;
|
|
805
886
|
/**
|
|
806
|
-
*
|
|
807
|
-
*
|
|
887
|
+
* Emit a wrapper under each `migrate.helpers` name that answers from the
|
|
888
|
+
* generated helpers, for legacy SQL `rls migrate` leaves alone. `true` puts
|
|
889
|
+
* them in `public`. Off by default; `--shims` turns it on.
|
|
808
890
|
*/
|
|
809
|
-
readonly
|
|
810
|
-
};
|
|
811
|
-
/** Where global roles live: `table (user, role)`. Defaults `user_id` and `role`. */
|
|
812
|
-
type GlobalRoles = {
|
|
813
|
-
readonly table: string;
|
|
814
|
-
readonly user?: string;
|
|
815
|
-
readonly role?: string | RoleThrough;
|
|
816
|
-
};
|
|
817
|
-
/** A permission reference from the app's definitions; only its `key` is read. */
|
|
818
|
-
type RlsPermissionRef = {
|
|
819
|
-
readonly key: string;
|
|
820
|
-
};
|
|
821
|
-
/**
|
|
822
|
-
* One private Realtime topic pattern, such as `org:{organization}:chat`:
|
|
823
|
-
* `:`-separated segments, one of them `{<scope>}`, which holds the id of a
|
|
824
|
-
* scope instance.
|
|
825
|
-
*/
|
|
826
|
-
type RlsRealtimeTopic = {
|
|
827
|
-
/** Receive broadcast and presence messages: `select` on `realtime.messages`. */
|
|
828
|
-
readonly read: RlsPermissionRef;
|
|
829
|
-
/** Send broadcast messages and track presence: `insert`. Absent: nobody may. */
|
|
830
|
-
readonly write?: RlsPermissionRef;
|
|
831
|
-
};
|
|
832
|
-
type RlsRealtime = {
|
|
833
|
-
readonly topics: Readonly<Record<string, RlsRealtimeTopic>>;
|
|
834
|
-
};
|
|
835
|
-
/** One Storage bucket whose object paths start with a scope instance id. */
|
|
836
|
-
type RlsStorageBucket = {
|
|
837
|
-
readonly scope: string;
|
|
838
|
-
/** The 1-based `storage.foldername(name)` entry that holds the id. Default 1. */
|
|
839
|
-
readonly folder?: number;
|
|
840
|
-
/** Download and list: `select` on `storage.objects`. */
|
|
841
|
-
readonly read?: RlsPermissionRef;
|
|
842
|
-
/** Upload and overwrite: `insert` and `update`. */
|
|
843
|
-
readonly write?: RlsPermissionRef;
|
|
844
|
-
readonly delete?: RlsPermissionRef;
|
|
845
|
-
};
|
|
846
|
-
type RlsStorage = {
|
|
847
|
-
readonly buckets: Readonly<Record<string, RlsStorageBucket>>;
|
|
891
|
+
readonly shims?: boolean | RlsShimsConfig;
|
|
848
892
|
};
|
|
849
893
|
/** `permdock supabase hook generate` input. */
|
|
850
894
|
type SupabaseHookConfig = {
|
|
@@ -1010,6 +1054,14 @@ type SupabaseConfig = {
|
|
|
1010
1054
|
*/
|
|
1011
1055
|
readonly schemas?: SupabaseSchemas;
|
|
1012
1056
|
};
|
|
1057
|
+
type CollectConfig = {
|
|
1058
|
+
readonly srcPath?: readonly string[];
|
|
1059
|
+
readonly out?: string;
|
|
1060
|
+
readonly barrel?: boolean | string;
|
|
1061
|
+
};
|
|
1062
|
+
type CatalogConfig = {
|
|
1063
|
+
readonly out?: string;
|
|
1064
|
+
};
|
|
1013
1065
|
type DoctorConfig = {
|
|
1014
1066
|
/**
|
|
1015
1067
|
* Directories or globs the source checks read (PD001, PD002, PD007 to PD015,
|
|
@@ -1138,98 +1190,4 @@ type GenConfig = {
|
|
|
1138
1190
|
readonly specifier?: "zod" | "zod/mini";
|
|
1139
1191
|
};
|
|
1140
1192
|
};
|
|
1141
|
-
|
|
1142
|
-
* `permdock powersync generate` and `verify` input. Tables and memberships come
|
|
1143
|
-
* from `rls`.
|
|
1144
|
-
*/
|
|
1145
|
-
type PowerSyncConfig = {
|
|
1146
|
-
/** The Sync Streams file; default `sync-config.yaml`. */
|
|
1147
|
-
readonly out?: string;
|
|
1148
|
-
/**
|
|
1149
|
-
* The only resources that get a stream. A helper does not add one. None when
|
|
1150
|
-
* omitted.
|
|
1151
|
-
*/
|
|
1152
|
-
readonly resources?: readonly string[];
|
|
1153
|
-
/** The action whose grants decide which rows sync; default `read`. */
|
|
1154
|
-
readonly action?: string;
|
|
1155
|
-
/**
|
|
1156
|
-
* Where `generate` writes `localSnapshotManifest(policy)` as JSON for
|
|
1157
|
-
* `localSnapshot` and `powerSyncSource`; none by default.
|
|
1158
|
-
*/
|
|
1159
|
-
readonly manifest?: string;
|
|
1160
|
-
/**
|
|
1161
|
-
* Tables that are not resources, by `schema.table`, each synced as its own
|
|
1162
|
-
* stream: the user's own rows, the rows that point at a resource row the user
|
|
1163
|
-
* reads, or both.
|
|
1164
|
-
*/
|
|
1165
|
-
readonly tables?: Readonly<Record<string, PowerSyncTable>>;
|
|
1166
|
-
/**
|
|
1167
|
-
* Per resource, the membership column that narrows what a device syncs: a
|
|
1168
|
-
* member with no value or `all` syncs the tenant's rows, `own` the rows of
|
|
1169
|
-
* the resource's `own` level, `team` those of its `team` level. A resource
|
|
1170
|
-
* without an entry syncs the tenant's rows to every member.
|
|
1171
|
-
*/
|
|
1172
|
-
readonly memberLevel?: Readonly<Record<string, PowerSyncMemberLevel>>;
|
|
1173
|
-
};
|
|
1174
|
-
type PowerSyncMemberLevel = {
|
|
1175
|
-
/**
|
|
1176
|
-
* `table` or `schema.table` of the tenant scope's membership table, as
|
|
1177
|
-
* `rls.memberships` or a membership source names it.
|
|
1178
|
-
*/
|
|
1179
|
-
readonly table: string;
|
|
1180
|
-
/** The text column on that table holding `own`, `team` or `all`. */
|
|
1181
|
-
readonly column: string;
|
|
1182
|
-
};
|
|
1183
|
-
type PowerSyncTable = {
|
|
1184
|
-
/** The user id column: the stream holds the rows whose column is the user. */
|
|
1185
|
-
readonly user?: string;
|
|
1186
|
-
/** The resources a row points at; the stream holds rows of any of them. */
|
|
1187
|
-
readonly follow?: readonly PowerSyncFollow[];
|
|
1188
|
-
};
|
|
1189
|
-
/**
|
|
1190
|
-
* A row points at a `resource` row through `field`, which holds its id; `match`
|
|
1191
|
-
* keeps the rows whose columns equal the given values, for a table whose rows
|
|
1192
|
-
* point at several resources.
|
|
1193
|
-
*/
|
|
1194
|
-
type PowerSyncFollow = {
|
|
1195
|
-
readonly resource: string;
|
|
1196
|
-
readonly field: string;
|
|
1197
|
-
readonly match?: Readonly<Record<string, string>>;
|
|
1198
|
-
};
|
|
1199
|
-
type CliIo = {
|
|
1200
|
-
readonly stdout: (text: string) => void;
|
|
1201
|
-
readonly stderr: (text: string) => void;
|
|
1202
|
-
readonly now?: () => Date;
|
|
1203
|
-
readonly fetch?: typeof fetch;
|
|
1204
|
-
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
1205
|
-
/** Styled stdout; `--no-color` turns it off. Unset is plain. */
|
|
1206
|
-
readonly color?: boolean;
|
|
1207
|
-
/** Styled stderr, decided for that stream on its own. Unset is plain. */
|
|
1208
|
-
readonly errColor?: boolean;
|
|
1209
|
-
/** A person at a terminal: commands may prompt. Unset never prompts. */
|
|
1210
|
-
readonly interactive?: boolean;
|
|
1211
|
-
/** stdout is a terminal; agent detection reads it. Unset is a pipe. */
|
|
1212
|
-
readonly stdoutIsTty?: boolean;
|
|
1213
|
-
/** stderr is a terminal: progress draws a spinner. Unset prints lines. */
|
|
1214
|
-
readonly stderrIsTty?: boolean;
|
|
1215
|
-
/** Reads all of stdin, for `--*-stdin` secrets. Unset reads nothing. */
|
|
1216
|
-
readonly readStdin?: () => Promise<string>;
|
|
1217
|
-
/** Aborted on SIGINT or SIGTERM. */
|
|
1218
|
-
readonly signal?: AbortSignal;
|
|
1219
|
-
};
|
|
1220
|
-
type RunResult = {
|
|
1221
|
-
readonly code: ExitCode;
|
|
1222
|
-
readonly stdout: string;
|
|
1223
|
-
readonly stderr: string;
|
|
1224
|
-
};
|
|
1225
|
-
type PermDockPluginOptions = {
|
|
1226
|
-
readonly collect?: CollectConfig;
|
|
1227
|
-
readonly onDrift?: "error" | "warn";
|
|
1228
|
-
/**
|
|
1229
|
-
* Unplugin only: compare instead of write in `buildStart`, failing the build
|
|
1230
|
-
* on drift (as `permdock collect --check` does). The Next plugin checks in
|
|
1231
|
-
* `phase-production-build` unless `PERMDOCK_COLLECT=write`.
|
|
1232
|
-
*/
|
|
1233
|
-
readonly check?: boolean;
|
|
1234
|
-
};
|
|
1235
|
-
export { RlsSuspension as _, GenKind as a, SupabaseSchemas as b, RlsActiveRow as c, RlsDialect as d, RlsFunctionMapping as f, RlsSuspendedScope as g, RlsSuspendedMembership as h, GenConfig as i, RlsApiKeys as l, RlsMemberships as m, CliIo as n, PermDockConfig as o, RlsMembershipTable as p, CollectConfig as r, PermDockPluginOptions as s, CatalogConfig as t, RlsConfig as u, RlsTarget as v, RunResult as y };
|
|
1193
|
+
export { RlsApiKeys as _, PermDockConfig as a, RlsConfig as c, RlsMembershipTable as d, RlsMemberships as f, RlsTarget as g, RlsSuspension as h, GenKind as i, RlsDialect as l, RlsSuspendedScope as m, CollectConfig as n, SupabaseSchemas as o, RlsSuspendedMembership as p, GenConfig as r, RlsActiveRow as s, CatalogConfig as t, RlsFunctionMapping as u };
|