@voltro/plugin-rbac 0.1.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/CHANGELOG.md +52 -0
- package/LICENSE +57 -0
- package/README.md +26 -0
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +347 -0
- package/dist/index.d.ts +331 -0
- package/dist/index.js +82 -0
- package/dist/permission-1Z68oD-d.js +62 -0
- package/dist/permission.d.ts +78 -0
- package/dist/permission.js +2 -0
- package/dist/web/index.d.ts +46 -0
- package/dist/web/index.js +5 -0
- package/package.json +61 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `@voltro/*` packages are recorded here. The format
|
|
4
|
+
follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
|
+
|
|
6
|
+
## Stability contract — read this before you pin a version
|
|
7
|
+
|
|
8
|
+
Voltro is **`0.x` — pre-1.0, and deliberately so.** Under SemVer, `0.y.z` means
|
|
9
|
+
"anything MAY change." We hold to exactly that, stated out loud:
|
|
10
|
+
|
|
11
|
+
- **Pin exact versions.** Depend on `@voltro/runtime@0.4.2`, never `^0.4.2` or
|
|
12
|
+
`~0.4.2`. There is no compatible-range promise below 1.0.
|
|
13
|
+
- **Every MINOR may break.** Breaking changes land on a minor bump (`0.4.x →
|
|
14
|
+
0.5.0`); patches (`0.4.1 → 0.4.2`) are additive or fixes only. This is the
|
|
15
|
+
standard `0.x` reading of SemVer — the minor slot carries breaking under `0.x`.
|
|
16
|
+
- **Read this changelog before upgrading.** The `⚠ BREAKING` section of each
|
|
17
|
+
release lists every incompatible change with its migration. It is the only
|
|
18
|
+
migration path we provide — there is no deprecation cycle, no compat shim.
|
|
19
|
+
- **All packages release together (lockstep).** One coordinated version across
|
|
20
|
+
the whole framework; the git tag is the source of truth.
|
|
21
|
+
|
|
22
|
+
This is not a placeholder disclaimer — it is the contract. The framework is
|
|
23
|
+
refactored aggressively while it has no external stability obligations, and that
|
|
24
|
+
velocity is the point. A stable-core tier and per-package `1.0` graduation are
|
|
25
|
+
planned, but not yet; until then, treat the whole surface as movable and pin
|
|
26
|
+
exact.
|
|
27
|
+
|
|
28
|
+
The **public API** of each package is its `publishConfig.exports` entry points,
|
|
29
|
+
minus anything marked `@internal` (those are cross-package internals and are
|
|
30
|
+
stripped from the published `.d.ts`). Importing a deep path that isn't an
|
|
31
|
+
exported entry point is unsupported.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## [Unreleased]
|
|
36
|
+
|
|
37
|
+
_Changes staged for the next release accumulate here (rolled up from
|
|
38
|
+
`.changes/*.md` at tag time — see `.changes/README.md`)._
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## [0.1.0]
|
|
43
|
+
|
|
44
|
+
Initial pre-release baseline. This is the starting point the changelog tracks
|
|
45
|
+
from; it is not an exhaustive history of prior development. The framework ships
|
|
46
|
+
as `@voltro/*` packages spanning the runtime, database/query layer, web client
|
|
47
|
+
and router, durable workflows, the CLI, and the plugin ecosystem
|
|
48
|
+
(auth, storage, mail, billing, observability, and more). Not published to a
|
|
49
|
+
public registry yet.
|
|
50
|
+
|
|
51
|
+
Subsequent releases record their deltas from here under dated headings, with
|
|
52
|
+
`⚠ BREAKING` first.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Voltro — Proprietary Software License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Voltro UG. All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software and all associated source code, documentation, and other
|
|
6
|
+
materials (the "Software") are the proprietary property of Voltro UG
|
|
7
|
+
("Voltro"). This is NOT open-source software.
|
|
8
|
+
|
|
9
|
+
Your access to and use of the Software is governed exclusively by the Voltro
|
|
10
|
+
Terms of Service at:
|
|
11
|
+
|
|
12
|
+
https://voltro.cloud/legal/terms
|
|
13
|
+
|
|
14
|
+
By downloading, installing, or using the Software you agree to those Terms.
|
|
15
|
+
Subject to and conditioned on your continued compliance with them, Voltro
|
|
16
|
+
grants you a limited, non-exclusive, non-transferable, non-sublicensable,
|
|
17
|
+
revocable license to use the Software. All rights not expressly granted in the
|
|
18
|
+
Terms are reserved by Voltro. If you do not agree to the Terms, you have no
|
|
19
|
+
license and may not use the Software.
|
|
20
|
+
|
|
21
|
+
The Terms of Service — including the scope of permitted use, plan
|
|
22
|
+
entitlements, fees, and pricing — may change from time to time. The version in
|
|
23
|
+
force is the one published at the URL above. Commercial terms and pricing are
|
|
24
|
+
NOT part of this notice and are not fixed by, or granted in perpetuity by, the
|
|
25
|
+
version of the Software in which this file appears.
|
|
26
|
+
|
|
27
|
+
Permitted use — your own software. Voltro is a development framework. You may
|
|
28
|
+
use the Software to build, run, and commercially distribute your own
|
|
29
|
+
applications and services, and to charge your own customers for them, without
|
|
30
|
+
owing Voltro any share of that revenue or any further permission beyond the
|
|
31
|
+
Terms. Applications you build with the Software are yours.
|
|
32
|
+
|
|
33
|
+
Prohibited use — reselling Voltro. You may NOT redistribute, resell,
|
|
34
|
+
sublicense, publish, or otherwise provide the Software itself — in whole or in
|
|
35
|
+
part, in source or compiled form — to third parties as a library, framework,
|
|
36
|
+
SDK, template, starter, or development tool for them to build upon, whether
|
|
37
|
+
standalone or repackaged. Shipping the Software as a non-separable, bundled
|
|
38
|
+
dependency inside an application you deliver (for example, compiled into your
|
|
39
|
+
deployed app) is permitted; extracting or re-exposing it as a reusable
|
|
40
|
+
component for others is not.
|
|
41
|
+
|
|
42
|
+
Except as expressly permitted above or by the Terms, you may not copy, modify,
|
|
43
|
+
merge, publish, sublicense, sell, distribute, or create derivative works of the
|
|
44
|
+
Software, in whole or in part.
|
|
45
|
+
|
|
46
|
+
Third-party open-source components distributed alongside the Software are the
|
|
47
|
+
property of their respective owners and are licensed under their own terms; see
|
|
48
|
+
THIRD-PARTY-NOTICES.md where provided. Nothing in this notice limits your
|
|
49
|
+
rights, or extends Voltro's, in those components.
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
52
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
53
|
+
FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
54
|
+
VOLTRO BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY ARISING FROM,
|
|
55
|
+
OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR ITS USE.
|
|
56
|
+
|
|
57
|
+
For licensing inquiries, contact Voltro UG.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @voltro/plugin-rbac
|
|
4
|
+
|
|
5
|
+
**Role-based access control — roles compile to scopes on top of @voltro/protocol's scope system. Ships rbacPlugin() (role→scope interceptor + typed Forbidden error), the permission()/assertPermission()/anyPermission() handler guards, the compileRoles() pure compiler, cross-dialect roles + userRoles tables, and a browser-safe useCan() UI affordance.**
|
|
6
|
+
|
|
7
|
+
[📖 Documentation](https://docs.voltro.dev/docs/plugins/rbac) · [Changelog](./CHANGELOG.md) · [voltro.dev](https://voltro.dev) · [Voltro Cloud](https://voltro.cloud)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @voltro/plugin-rbac
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
> ### [→ Read the documentation for @voltro/plugin-rbac](https://docs.voltro.dev/docs/plugins/rbac)
|
|
18
|
+
|
|
19
|
+
Installation, guides, the full API reference, and examples all live in the
|
|
20
|
+
**[Voltro documentation](https://docs.voltro.dev/docs/intro/getting-started)** — the single source of truth. This README is
|
|
21
|
+
deliberately short so there is nothing here to drift out of date.
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
Proprietary. © 2026 Voltro UG. Your use is governed by the
|
|
26
|
+
[Terms of Service](https://voltro.cloud/legal/terms). See the bundled `LICENSE`.
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
We take the security of Voltro and the applications built on it seriously. This
|
|
4
|
+
document explains how to report a vulnerability and what to expect in return.
|
|
5
|
+
|
|
6
|
+
## Reporting a vulnerability
|
|
7
|
+
|
|
8
|
+
**Please do not open public issues or discuss suspected vulnerabilities in
|
|
9
|
+
public channels.** Report them privately by email:
|
|
10
|
+
|
|
11
|
+
**security contact: [support@voltro.dev](mailto:support@voltro.dev)**
|
|
12
|
+
(subject line: `SECURITY`).
|
|
13
|
+
|
|
14
|
+
Include, where you can:
|
|
15
|
+
|
|
16
|
+
- the affected package(s) and version(s) (e.g. `@voltro/runtime@x.y.z`);
|
|
17
|
+
- a description of the issue and its impact;
|
|
18
|
+
- a minimal reproduction or proof of concept;
|
|
19
|
+
- any suggested remediation.
|
|
20
|
+
|
|
21
|
+
If you'd like to encrypt your report, ask in a first plain email and we'll
|
|
22
|
+
arrange a key.
|
|
23
|
+
|
|
24
|
+
## What to expect
|
|
25
|
+
|
|
26
|
+
- **Acknowledgement** of your report within **3 business days**.
|
|
27
|
+
- An initial assessment (severity, affected surface) and a remediation plan as
|
|
28
|
+
soon as we've reproduced the issue.
|
|
29
|
+
- **Coordinated disclosure:** we'll agree a disclosure timeline with you and
|
|
30
|
+
credit you in the release notes if you wish. Please give us reasonable time to
|
|
31
|
+
ship a fix before any public disclosure.
|
|
32
|
+
|
|
33
|
+
We do not currently run a paid bug-bounty program, but we genuinely appreciate
|
|
34
|
+
responsible disclosure and will credit reporters.
|
|
35
|
+
|
|
36
|
+
## Software Bill of Materials (SBOM)
|
|
37
|
+
|
|
38
|
+
A CycloneDX SBOM of the third-party runtime dependency graph is generated for the
|
|
39
|
+
published packages (`pnpm gen:sbom` → `sbom.cdx.json`). If your procurement or
|
|
40
|
+
security team needs it, request it at
|
|
41
|
+
[support@voltro.dev](mailto:support@voltro.dev).
|
|
42
|
+
|
|
43
|
+
## Supported versions
|
|
44
|
+
|
|
45
|
+
Voltro is pre-1.0 and ships in lockstep: **only the latest published minor of
|
|
46
|
+
each `@voltro/*` package receives security fixes.** Please upgrade to the latest
|
|
47
|
+
release before reporting, and pin exact versions in production.
|
|
48
|
+
|
|
49
|
+
## Scope
|
|
50
|
+
|
|
51
|
+
In scope: the published `@voltro/*` packages and the framework's own code.
|
|
52
|
+
|
|
53
|
+
Out of scope: vulnerabilities in third-party dependencies that are already
|
|
54
|
+
tracked upstream (we monitor these via a production-dependency audit gate in
|
|
55
|
+
CI), and issues that require a non-default, explicitly-unsafe configuration. If
|
|
56
|
+
you're unsure, report it anyway — we'd rather hear about it.
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
# Third-Party Notices — @voltro/plugin-rbac
|
|
2
|
+
|
|
3
|
+
This package depends on the open-source software listed below. Each is the
|
|
4
|
+
property of its respective copyright holders and is used under the terms of
|
|
5
|
+
its license. This file is provided for attribution; it grants no rights in
|
|
6
|
+
@voltro/plugin-rbac itself, which is proprietary (see LICENSE).
|
|
7
|
+
|
|
8
|
+
Generated from the resolved runtime dependency closure (6 packages).
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## @effect/sql@0.51.1
|
|
13
|
+
|
|
14
|
+
License: MIT
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
MIT License
|
|
18
|
+
|
|
19
|
+
Copyright (c) 2023-present The Contributors
|
|
20
|
+
|
|
21
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
in the Software without restriction, including without limitation the rights
|
|
24
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
furnished to do so, subject to the following conditions:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
copies or substantial portions of the Software.
|
|
30
|
+
|
|
31
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
SOFTWARE.
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## jose@6.2.3
|
|
41
|
+
|
|
42
|
+
License: MIT
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
The MIT License (MIT)
|
|
46
|
+
|
|
47
|
+
Copyright (c) 2018 Filip Skokan
|
|
48
|
+
|
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
50
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
51
|
+
in the Software without restriction, including without limitation the rights
|
|
52
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
53
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
54
|
+
furnished to do so, subject to the following conditions:
|
|
55
|
+
|
|
56
|
+
The above copyright notice and this permission notice shall be included in all
|
|
57
|
+
copies or substantial portions of the Software.
|
|
58
|
+
|
|
59
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
60
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
61
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
62
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
63
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
64
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
65
|
+
SOFTWARE.
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## layerr@3.0.0
|
|
69
|
+
|
|
70
|
+
License: MIT
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
MIT License
|
|
74
|
+
|
|
75
|
+
Copyright (c) 2020 Perry Mitchell
|
|
76
|
+
|
|
77
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
78
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
79
|
+
in the Software without restriction, including without limitation the rights
|
|
80
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
81
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
82
|
+
furnished to do so, subject to the following conditions:
|
|
83
|
+
|
|
84
|
+
The above copyright notice and this permission notice shall be included in all
|
|
85
|
+
copies or substantial portions of the Software.
|
|
86
|
+
|
|
87
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
88
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
89
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
90
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
91
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
92
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
93
|
+
SOFTWARE.
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## typeid-js@1.2.0
|
|
97
|
+
|
|
98
|
+
License: Apache-2.0
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
Apache License
|
|
102
|
+
Version 2.0, January 2004
|
|
103
|
+
http://www.apache.org/licenses/
|
|
104
|
+
|
|
105
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
106
|
+
|
|
107
|
+
1. Definitions.
|
|
108
|
+
|
|
109
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
110
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
111
|
+
|
|
112
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
113
|
+
the copyright owner that is granting the License.
|
|
114
|
+
|
|
115
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
116
|
+
other entities that control, are controlled by, or are under common
|
|
117
|
+
control with that entity. For the purposes of this definition,
|
|
118
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
119
|
+
direction or management of such entity, whether by contract or
|
|
120
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
121
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
122
|
+
|
|
123
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
124
|
+
exercising permissions granted by this License.
|
|
125
|
+
|
|
126
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
127
|
+
including but not limited to software source code, documentation
|
|
128
|
+
source, and configuration files.
|
|
129
|
+
|
|
130
|
+
"Object" form shall mean any form resulting from mechanical
|
|
131
|
+
transformation or translation of a Source form, including but
|
|
132
|
+
not limited to compiled object code, generated documentation,
|
|
133
|
+
and conversions to other media types.
|
|
134
|
+
|
|
135
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
136
|
+
Object form, made available under the License, as indicated by a
|
|
137
|
+
copyright notice that is included in or attached to the work
|
|
138
|
+
(an example is provided in the Appendix below).
|
|
139
|
+
|
|
140
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
141
|
+
form, that is based on (or derived from) the Work and for which the
|
|
142
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
143
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
144
|
+
of this License, Derivative Works shall not include works that remain
|
|
145
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
146
|
+
the Work and Derivative Works thereof.
|
|
147
|
+
|
|
148
|
+
"Contribution" shall mean any work of authorship, including
|
|
149
|
+
the original version of the Work and any modifications or additions
|
|
150
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
151
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
152
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
153
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
154
|
+
means any form of electronic, verbal, or written communication sent
|
|
155
|
+
to the Licensor or its representatives, including but not limited to
|
|
156
|
+
communication on electronic mailing lists, source code control systems,
|
|
157
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
158
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
159
|
+
excluding communication that is conspicuously marked or otherwise
|
|
160
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
161
|
+
|
|
162
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
163
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
164
|
+
subsequently incorporated within the Work.
|
|
165
|
+
|
|
166
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
167
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
168
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
169
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
170
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
171
|
+
Work and such Derivative Works in Source or Object form.
|
|
172
|
+
|
|
173
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
174
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
175
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
176
|
+
(except as stated in this section) patent license to make, have made,
|
|
177
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
178
|
+
where such license applies only to those patent claims licensable
|
|
179
|
+
by such Contributor that are necessarily infringed by their
|
|
180
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
181
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
182
|
+
institute patent litigation against any entity (including a
|
|
183
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
184
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
185
|
+
or contributory patent infringement, then any patent licenses
|
|
186
|
+
granted to You under this License for that Work shall terminate
|
|
187
|
+
as of the date such litigation is filed.
|
|
188
|
+
|
|
189
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
190
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
191
|
+
modifications, and in Source or Object form, provided that You
|
|
192
|
+
meet the following conditions:
|
|
193
|
+
|
|
194
|
+
(a) You must give any other recipients of the Work or
|
|
195
|
+
Derivative Works a copy of this License; and
|
|
196
|
+
|
|
197
|
+
(b) You must cause any modified files to carry prominent notices
|
|
198
|
+
stating that You changed the files; and
|
|
199
|
+
|
|
200
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
201
|
+
that You distribute, all copyright, patent, trademark, and
|
|
202
|
+
attribution notices from the Source form of the Work,
|
|
203
|
+
excluding those notices that do not pertain to any part of
|
|
204
|
+
the Derivative Works; and
|
|
205
|
+
|
|
206
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
207
|
+
distribution, then any Derivative Works that You distribute must
|
|
208
|
+
include a readable copy of the attribution notices contained
|
|
209
|
+
within such NOTICE file, excluding those notices that do not
|
|
210
|
+
pertain to any part of the Derivative Works, in at least one
|
|
211
|
+
of the following places: within a NOTICE text file distributed
|
|
212
|
+
as part of the Derivative Works; within the Source form or
|
|
213
|
+
documentation, if provided along with the Derivative Works; or,
|
|
214
|
+
within a display generated by the Derivative Works, if and
|
|
215
|
+
wherever such third-party notices normally appear. The contents
|
|
216
|
+
of the NOTICE file are for informational purposes only and
|
|
217
|
+
do not modify the License. You may add Your own attribution
|
|
218
|
+
notices within Derivative Works that You distribute, alongside
|
|
219
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
220
|
+
that such additional attribution notices cannot be construed
|
|
221
|
+
as modifying the License.
|
|
222
|
+
|
|
223
|
+
You may add Your own copyright statement to Your modifications and
|
|
224
|
+
may provide additional or different license terms and conditions
|
|
225
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
226
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
227
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
228
|
+
the conditions stated in this License.
|
|
229
|
+
|
|
230
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
231
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
232
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
233
|
+
this License, without any additional terms or conditions.
|
|
234
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
235
|
+
the terms of any separate license agreement you may have executed
|
|
236
|
+
with Licensor regarding such Contributions.
|
|
237
|
+
|
|
238
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
239
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
240
|
+
except as required for reasonable and customary use in describing the
|
|
241
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
242
|
+
|
|
243
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
244
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
245
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
246
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
247
|
+
implied, including, without limitation, any warranties or conditions
|
|
248
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
249
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
250
|
+
appropriateness of using or redistributing the Work and assume any
|
|
251
|
+
risks associated with Your exercise of permissions under this License.
|
|
252
|
+
|
|
253
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
254
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
255
|
+
unless required by applicable law (such as deliberate and grossly
|
|
256
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
257
|
+
liable to You for damages, including any direct, indirect, special,
|
|
258
|
+
incidental, or consequential damages of any character arising as a
|
|
259
|
+
result of this License or out of the use or inability to use the
|
|
260
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
261
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
262
|
+
other commercial damages or losses), even if such Contributor
|
|
263
|
+
has been advised of the possibility of such damages.
|
|
264
|
+
|
|
265
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
266
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
267
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
268
|
+
or other liability obligations and/or rights consistent with this
|
|
269
|
+
License. However, in accepting such obligations, You may act only
|
|
270
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
271
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
272
|
+
defend, and hold each Contributor harmless for any liability
|
|
273
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
274
|
+
of your accepting any such warranty or additional liability.
|
|
275
|
+
|
|
276
|
+
END OF TERMS AND CONDITIONS
|
|
277
|
+
|
|
278
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
279
|
+
|
|
280
|
+
To apply the Apache License to your work, attach the following
|
|
281
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
282
|
+
replaced with your own identifying information. (Don't include
|
|
283
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
284
|
+
comment syntax for the file format. We also recommend that a
|
|
285
|
+
file or class name and description of purpose be included on the
|
|
286
|
+
same "printed page" as the copyright notice for easier
|
|
287
|
+
identification within third-party archives.
|
|
288
|
+
|
|
289
|
+
Copyright [yyyy] [name of copyright owner]
|
|
290
|
+
|
|
291
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
292
|
+
you may not use this file except in compliance with the License.
|
|
293
|
+
You may obtain a copy of the License at
|
|
294
|
+
|
|
295
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
296
|
+
|
|
297
|
+
Unless required by applicable law or agreed to in writing, software
|
|
298
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
299
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
300
|
+
See the License for the specific language governing permissions and
|
|
301
|
+
limitations under the License.
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
## ulidx@2.4.1
|
|
305
|
+
|
|
306
|
+
License: MIT
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
MIT License
|
|
310
|
+
|
|
311
|
+
Copyright (c) 2021 Perry Mitchell
|
|
312
|
+
|
|
313
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
314
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
315
|
+
in the Software without restriction, including without limitation the rights
|
|
316
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
317
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
318
|
+
furnished to do so, subject to the following conditions:
|
|
319
|
+
|
|
320
|
+
The above copyright notice and this permission notice shall be included in all
|
|
321
|
+
copies or substantial portions of the Software.
|
|
322
|
+
|
|
323
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
324
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
325
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
326
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
327
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
328
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
329
|
+
SOFTWARE.
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## uuid@11.1.1
|
|
333
|
+
|
|
334
|
+
License: MIT
|
|
335
|
+
|
|
336
|
+
```
|
|
337
|
+
The MIT License (MIT)
|
|
338
|
+
|
|
339
|
+
Copyright (c) 2010-2020 Robert Kieffer and other contributors
|
|
340
|
+
|
|
341
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
342
|
+
|
|
343
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
344
|
+
|
|
345
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
346
|
+
```
|
|
347
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { Schema } from 'effect';
|
|
3
|
+
import { SchemaTable } from '@voltro/database';
|
|
4
|
+
import { Subject } from '@voltro/protocol';
|
|
5
|
+
import { VoltroPlugin } from '@voltro/protocol';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Effect-form OR guard. Passes if the caller holds AT LEAST ONE of the
|
|
9
|
+
* listed permissions. Fails `Forbidden` (naming the first option) when it
|
|
10
|
+
* holds none. The `admin:full` bypass passes.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* yield* anyPermission(ctx, ['notes:write', 'notes:admin'])
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const anyPermission: (ctx: RbacContext, required: ReadonlyArray<string>) => Effect.Effect<void, Forbidden>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sync-form guard for async (non-Effect) handlers. THROWS `Forbidden`
|
|
20
|
+
* when the caller lacks the required permission(s). Array = AND.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const execute = async (input, ctx) => {
|
|
24
|
+
* assertPermission(ctx, 'notes:write')
|
|
25
|
+
* return ctx.store.insert('notes', { ... })
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const assertPermission: (ctx: RbacContext, required: string | ReadonlyArray<string>) => void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Build the `userRoles` table. `tenantId` scopes a role assignment to the
|
|
33
|
+
* active tenant (`null` = a global, all-tenant role).
|
|
34
|
+
*
|
|
35
|
+
* - `multitenant: true` → `tenantId` is a nullable FK to the `tenants`
|
|
36
|
+
* table (resolved via `requireTenants()`), so the DDL carries the
|
|
37
|
+
* foreign key when multitenancy is present.
|
|
38
|
+
* - `multitenant: false` (default) → `tenantId` is a plain
|
|
39
|
+
* `text().nullable()` column, so the package has NO hard dependency on
|
|
40
|
+
* @voltro/plugin-multitenancy for single-tenant projects.
|
|
41
|
+
*/
|
|
42
|
+
export declare const buildUserRolesTable: (options?: {
|
|
43
|
+
readonly multitenant?: boolean;
|
|
44
|
+
}) => RbacTable;
|
|
45
|
+
|
|
46
|
+
/** Pure boolean check — no throw, no Effect. For branching inside a handler. */
|
|
47
|
+
export declare const can: (ctx: RbacContext, required: string | ReadonlyArray<string>) => boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Compile a caller's granted role slugs into a flat, deduped scope set.
|
|
51
|
+
*
|
|
52
|
+
* - Unknown slugs (not present in `roleMap`) are ignored — a stale role
|
|
53
|
+
* reference never grants anything, and never throws.
|
|
54
|
+
* - If ANY granted role lists the `'*'` wildcard, the result collapses to
|
|
55
|
+
* `[ADMIN_SCOPE]` (the blanket bypass) — no point carrying the rest.
|
|
56
|
+
* - Otherwise the result is the deduped union of every listed permission,
|
|
57
|
+
* in first-seen order.
|
|
58
|
+
*
|
|
59
|
+
* The output is a SCOPE set: feed it straight into `hasScope` / the
|
|
60
|
+
* `permission()` guard. A project can mix declarative roles AND raw
|
|
61
|
+
* key-minted scopes; both land in the same resolved set.
|
|
62
|
+
*/
|
|
63
|
+
export declare const compileRoles: (roleSlugs: ReadonlyArray<string>, roleMap: RoleMap) => ReadonlyArray<string>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A {@link RoleResolver} backed by the `userRoles` table — resolves a
|
|
67
|
+
* subject's role slugs from the store, scoped to the subject's tenant (so
|
|
68
|
+
* tenant-aware role assignments Just Work). Drop into
|
|
69
|
+
* `rbacPlugin({ resolveRoles: dataStoreRoleResolver(userRoleStore(ds)) })`.
|
|
70
|
+
*/
|
|
71
|
+
export declare const dataStoreRoleResolver: (store: UserRoleStore) => RoleResolver;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Raised when a caller lacks a required permission. Distinct from
|
|
75
|
+
* protocol's `ScopeError` so rbac owns its own wire surface; `rbacPlugin`
|
|
76
|
+
* registers it via `errorSchemas` so it decodes TYPED on the client.
|
|
77
|
+
*
|
|
78
|
+
* Declare it in a mutation's `error:` schema (or rely on `rbacPlugin`'s
|
|
79
|
+
* cross-cutting registration) so callers can pattern-match on
|
|
80
|
+
* `_tag === 'Forbidden'`.
|
|
81
|
+
*/
|
|
82
|
+
export declare class Forbidden extends Forbidden_base {
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare const Forbidden_base: Schema.TaggedErrorClass<Forbidden, "Forbidden", {
|
|
86
|
+
readonly _tag: Schema.tag<"Forbidden">;
|
|
87
|
+
} & {
|
|
88
|
+
/** The permission (or first missing permission) the caller lacked. */
|
|
89
|
+
required: typeof Schema.String;
|
|
90
|
+
/** Optional human-readable context. */
|
|
91
|
+
reason: Schema.optional<typeof Schema.String>;
|
|
92
|
+
}>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Compile a subject's roles + raw permissions into one resolved scope
|
|
96
|
+
* set: `subject.scopes` ∪ compiled(roles) ∪ extraPermissions, deduped.
|
|
97
|
+
* Pure given resolved inputs — the interceptor awaits the (possibly
|
|
98
|
+
* async) resolvers, then calls this.
|
|
99
|
+
*/
|
|
100
|
+
export declare const mergeResolvedScopes: (subject: Subject, roleSlugs: ReadonlyArray<string>, roleMap: RoleMap, extraPermissions?: ReadonlyArray<string>) => ReadonlyArray<string>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Default `RoleResolver` — reads `subject.metadata.roles` if it's a
|
|
104
|
+
* `string[]`, else `[]`. The framework never reads `metadata`; it's the
|
|
105
|
+
* IdP slot, so a strategy that wants config-driven roles puts the slugs
|
|
106
|
+
* there and the default resolver picks them up table-less.
|
|
107
|
+
*/
|
|
108
|
+
export declare const metadataRoleResolver: RoleResolver;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Effect-form guard. Fails with a typed `Forbidden` on the error channel
|
|
112
|
+
* when the caller lacks the required permission(s). An array means ALL
|
|
113
|
+
* are required (AND). The `admin:full` bypass passes everything.
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* export default (input, ctx) => Effect.gen(function* () {
|
|
117
|
+
* yield* permission(ctx, 'notes:write')
|
|
118
|
+
* // ...
|
|
119
|
+
* })
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare const permission: (ctx: RbacContext, required: string | ReadonlyArray<string>) => Effect.Effect<void, Forbidden>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A resolver that yields raw permission strings merged into the resolved
|
|
126
|
+
* set IN ADDITION to role-derived ones (per-row ACLs, feature flags, …).
|
|
127
|
+
*/
|
|
128
|
+
export declare type PermissionResolver = (subject: Subject) => ReadonlyArray<string> | Promise<ReadonlyArray<string>>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Anything carrying a resolved subject under `ctx.request.subject` — the
|
|
132
|
+
* shape every handler executor receives (`AppContext`). Kept structural
|
|
133
|
+
* so rbac needs no dependency on @voltro/runtime.
|
|
134
|
+
*/
|
|
135
|
+
export declare interface RbacContext {
|
|
136
|
+
readonly request: {
|
|
137
|
+
readonly subject: Subject;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Build the rbac plugin. Returns the `VoltroPlugin` you pass into
|
|
143
|
+
* `app.config.ts`'s `plugins: [...]` array.
|
|
144
|
+
*
|
|
145
|
+
* The interceptor runs once per mutation / query / action, BEFORE the
|
|
146
|
+
* executor: it resolves the caller's roles, compiles them to scopes,
|
|
147
|
+
* merges with the subject's raw scopes + any extra permissions, and
|
|
148
|
+
* stashes the resolved set for `permission()` to read. A resolver failure
|
|
149
|
+
* is logged and degrades to the subject's raw scopes — never silently
|
|
150
|
+
* grants.
|
|
151
|
+
*/
|
|
152
|
+
export declare const rbacPlugin: (options: RbacPluginOptions) => VoltroPlugin;
|
|
153
|
+
|
|
154
|
+
export declare interface RbacPluginOptions {
|
|
155
|
+
/**
|
|
156
|
+
* Declarative role → permission map. Each role lists the permission
|
|
157
|
+
* strings (== scope strings) it grants. `'*'` in any role's list
|
|
158
|
+
* expands to the `admin:full` blanket bypass.
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* roles: {
|
|
162
|
+
* viewer: ['notes:read'],
|
|
163
|
+
* editor: ['notes:read', 'notes:write'],
|
|
164
|
+
* admin: ['*'],
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
readonly roles: RoleMap;
|
|
169
|
+
/**
|
|
170
|
+
* Where a subject's role slugs come from. Default: `metadataRoleResolver`
|
|
171
|
+
* (reads `subject.metadata.roles` as a `string[]`). A project that
|
|
172
|
+
* assigns roles at runtime supplies its own — e.g. a DB lookup filtered
|
|
173
|
+
* by `subject.tenantId` for tenant-aware roles.
|
|
174
|
+
*/
|
|
175
|
+
readonly resolveRoles?: RoleResolver;
|
|
176
|
+
/**
|
|
177
|
+
* Extra raw permission strings merged into the resolved set in ADDITION
|
|
178
|
+
* to role-derived ones (per-row ACLs, feature flags, …). Default: none.
|
|
179
|
+
*/
|
|
180
|
+
readonly resolvePermissions?: PermissionResolver;
|
|
181
|
+
/**
|
|
182
|
+
* Contribute the `roles` + `userRoles` tables via `extendSchema.tables`.
|
|
183
|
+
* Default `false` — config-only / metadata-resolver projects run
|
|
184
|
+
* table-less. Set `true` (or `{ multitenant: true }` for a FK to
|
|
185
|
+
* `tenants`) when assigning roles at runtime against the DB.
|
|
186
|
+
*/
|
|
187
|
+
readonly tables?: boolean | {
|
|
188
|
+
readonly multitenant?: boolean;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The slice of a built `Table` this package exposes: the table name, its
|
|
194
|
+
* columns, and its indexes. `SchemaTable` is @voltro/database's PUBLIC
|
|
195
|
+
* structural table type — it names exactly this surface WITHOUT dragging in
|
|
196
|
+
* the private column-builder class the fully-inferred `Table` generic would
|
|
197
|
+
* (which is what forces TS4094 across a package boundary). Alias kept for
|
|
198
|
+
* readability at the annotation sites below.
|
|
199
|
+
*/
|
|
200
|
+
export declare type RbacTable = SchemaTable;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Both rbac tables, ready to spread into `extendSchema.tables`. Pass
|
|
204
|
+
* `{ multitenant: true }` to make `userRoles.tenantId` a FK to `tenants`.
|
|
205
|
+
*/
|
|
206
|
+
export declare const rbacTables: (options?: {
|
|
207
|
+
readonly multitenant?: boolean;
|
|
208
|
+
}) => ReadonlyArray<RbacTable>;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Read the role slugs that produced the subject's resolved set, if the
|
|
212
|
+
* interceptor recorded them. Empty when roles weren't resolved (or the
|
|
213
|
+
* plugin isn't installed). For introspection only — NOT an authz signal.
|
|
214
|
+
*/
|
|
215
|
+
export declare const resolvedRoles: (subject: Subject) => ReadonlyArray<string>;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Read the resolved scope set for a subject. Returns the interceptor's
|
|
219
|
+
* compiled set if present; otherwise falls back to the subject's own
|
|
220
|
+
* `scopes` (raw key-minted scopes still gate). Never returns undefined.
|
|
221
|
+
*/
|
|
222
|
+
export declare const resolvedScopes: (subject: Subject) => ReadonlyArray<string>;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* A role: a slug plus the flat permission strings it grants. The
|
|
226
|
+
* permission strings ARE scope strings — `compileRoles` unions them into
|
|
227
|
+
* the caller's resolved scope set.
|
|
228
|
+
*
|
|
229
|
+
* The wildcard `'*'` in any granted role's permission list expands to the
|
|
230
|
+
* blanket `ADMIN_SCOPE` bypass — a caller who holds a `'*'` role passes
|
|
231
|
+
* every `permission()` check.
|
|
232
|
+
*/
|
|
233
|
+
export declare interface RoleDefinition {
|
|
234
|
+
/** Stable role identifier, e.g. `'editor'`. */
|
|
235
|
+
readonly slug: string;
|
|
236
|
+
/** Flat permission strings, e.g. `['notes:read', 'notes:write']` or `['*']`. */
|
|
237
|
+
readonly permissions: ReadonlyArray<string>;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* The declarative `roles:` map passed to `rbacPlugin({ roles })`. Maps a
|
|
242
|
+
* role slug to the permission strings it grants. `'*'` is the wildcard
|
|
243
|
+
* that compiles to `[ADMIN_SCOPE]`.
|
|
244
|
+
*
|
|
245
|
+
* ```ts
|
|
246
|
+
* const roles = {
|
|
247
|
+
* viewer: ['notes:read', 'comments:read'],
|
|
248
|
+
* editor: ['notes:read', 'notes:write', 'comments:read', 'comments:write'],
|
|
249
|
+
* admin: ['*'],
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
export declare type RoleMap = Readonly<Record<string, ReadonlyArray<string>>>;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* A resolver that yields the role slugs a subject holds. The default
|
|
257
|
+
* reads `subject.metadata.roles` (a `string[]`) when present; a project
|
|
258
|
+
* that assigns roles at runtime supplies its own (e.g. a DB lookup
|
|
259
|
+
* filtered by `subject.tenantId`).
|
|
260
|
+
*/
|
|
261
|
+
export declare type RoleResolver = (subject: Subject) => ReadonlyArray<string> | Promise<ReadonlyArray<string>>;
|
|
262
|
+
|
|
263
|
+
export declare const ROLES_TABLE = "_voltro_rbac_roles";
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Normalise a `RoleMap` into a list of `RoleDefinition`s. Convenience for
|
|
267
|
+
* callers that want the structured shape (e.g. to seed the `roles` table
|
|
268
|
+
* or render a role picker).
|
|
269
|
+
*/
|
|
270
|
+
export declare const rolesFromMap: (roleMap: RoleMap) => ReadonlyArray<RoleDefinition>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The `roles` table: one row per role, carrying its flat permission set.
|
|
274
|
+
* `permissions` is a portable `json<string[]>()` column (JSONB on pg,
|
|
275
|
+
* JSON on mysql/mariadb, NVARCHAR(MAX) on mssql, TEXT on sqlite) — never
|
|
276
|
+
* a postgres-only `text[]`.
|
|
277
|
+
*/
|
|
278
|
+
export declare const rolesTable: RbacTable;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Stash the resolved scope set (+ originating role slugs) for a subject.
|
|
282
|
+
* Called once per request by the interceptor, before the executor runs.
|
|
283
|
+
*/
|
|
284
|
+
export declare const setResolvedScopes: (subject: Subject, scopes: ReadonlyArray<string>, roleSlugs?: ReadonlyArray<string>) => void;
|
|
285
|
+
|
|
286
|
+
export declare const USER_ROLES_TABLE = "_voltro_rbac_user_roles";
|
|
287
|
+
|
|
288
|
+
/** A role assignment as stored: the subject, the role slug, and its tenant scope. */
|
|
289
|
+
export declare interface UserRoleAssignment {
|
|
290
|
+
readonly userId: string;
|
|
291
|
+
readonly roleSlug: string;
|
|
292
|
+
/** `null` = a global (all-tenant) assignment. */
|
|
293
|
+
readonly tenantId?: string | null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** Narrow slice of the framework DataStore the user-role helpers need. */
|
|
297
|
+
export declare interface UserRoleDataStore {
|
|
298
|
+
query: (descriptor: Record<string, unknown>) => Promise<ReadonlyArray<Record<string, unknown>>>;
|
|
299
|
+
insert: (table: string, row: Record<string, unknown>) => Promise<unknown>;
|
|
300
|
+
delete: (table: string, primaryKey: string) => Promise<unknown>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** Single-tenant default — `tenantId` is a plain nullable text column. */
|
|
304
|
+
export declare const userRolesTable: RbacTable;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Assign / revoke / read role assignments over the `userRoles` table. All
|
|
308
|
+
* methods are tenant-aware: `tenantId` scopes an assignment (or query) to a
|
|
309
|
+
* tenant; `null` (the default) is a global assignment across all tenants.
|
|
310
|
+
*/
|
|
311
|
+
export declare interface UserRoleStore {
|
|
312
|
+
/** Grant `roleSlug` to `userId` (idempotent — a duplicate assignment is a no-op). */
|
|
313
|
+
readonly assign: (userId: string, roleSlug: string, tenantId?: string | null) => Promise<void>;
|
|
314
|
+
/** Remove `roleSlug` from `userId` for the given tenant scope. */
|
|
315
|
+
readonly revoke: (userId: string, roleSlug: string, tenantId?: string | null) => Promise<void>;
|
|
316
|
+
/**
|
|
317
|
+
* The role slugs `userId` holds. With a `tenantId`, returns the tenant's
|
|
318
|
+
* assignments PLUS global (`tenantId: null`) ones; without, every assignment.
|
|
319
|
+
*/
|
|
320
|
+
readonly rolesOf: (userId: string, tenantId?: string | null) => Promise<ReadonlyArray<string>>;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** A {@link UserRoleStore} over a framework DataStore. */
|
|
324
|
+
export declare const userRoleStore: (store: UserRoleDataStore) => UserRoleStore;
|
|
325
|
+
|
|
326
|
+
export { VoltroPlugin }
|
|
327
|
+
|
|
328
|
+
/** The wildcard permission string that compiles to the admin bypass. */
|
|
329
|
+
export declare const WILDCARD_PERMISSION = "*";
|
|
330
|
+
|
|
331
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./permission-1Z68oD-d.js";
|
|
2
|
+
import { Effect as p } from "effect";
|
|
3
|
+
import { definePlugin as m } from "@voltro/protocol";
|
|
4
|
+
import { createLogger as h } from "@voltro/logger";
|
|
5
|
+
import { and as g, boolean as _, eq as v, id as y, json as b, or as x, reference as S, requireTenants as C, table as w, text as T } from "@voltro/database";
|
|
6
|
+
//#region src/tables.ts
|
|
7
|
+
var E = "_voltro_rbac_roles", D = "_voltro_rbac_user_roles", O = w(E, {
|
|
8
|
+
id: y({ prefix: "role" }),
|
|
9
|
+
slug: T().unique(),
|
|
10
|
+
name: T(),
|
|
11
|
+
permissions: b(),
|
|
12
|
+
isDefault: _().default(!1)
|
|
13
|
+
}).index("byRolesSlug", ["slug"]), k = (e = {}) => w(D, {
|
|
14
|
+
id: y({ prefix: "urole" }),
|
|
15
|
+
userId: T(),
|
|
16
|
+
tenantId: e.multitenant ? S(C(), { index: !1 }).nullable() : T().nullable(),
|
|
17
|
+
roleSlug: T()
|
|
18
|
+
}).index("byUserTenant", ["userId", "tenantId"]).index("byRoleSlug", ["roleSlug"]), A = k(), j = (e = {}) => [O, k(e)], M = (e, t) => e.query({
|
|
19
|
+
table: D,
|
|
20
|
+
predicate: t,
|
|
21
|
+
order: [{
|
|
22
|
+
column: "id",
|
|
23
|
+
direction: "asc"
|
|
24
|
+
}],
|
|
25
|
+
take: void 0,
|
|
26
|
+
skip: void 0,
|
|
27
|
+
projection: void 0
|
|
28
|
+
}), N = (e) => {
|
|
29
|
+
let t = (t, n, r) => M(e, g(v("userId", t), v("roleSlug", n), v("tenantId", r)));
|
|
30
|
+
return {
|
|
31
|
+
assign: async (n, r, i = null) => {
|
|
32
|
+
(await t(n, r, i)).length > 0 || await e.insert(D, {
|
|
33
|
+
userId: n,
|
|
34
|
+
roleSlug: r,
|
|
35
|
+
tenantId: i
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
revoke: async (n, r, i = null) => {
|
|
39
|
+
let a = await t(n, r, i);
|
|
40
|
+
for (let t of a) await e.delete(D, String(t.id));
|
|
41
|
+
},
|
|
42
|
+
rolesOf: async (t, n) => {
|
|
43
|
+
let r = (n === void 0 ? await M(e, v("userId", t)) : await M(e, g(v("userId", t), P(n)))).map((e) => String(e.roleSlug));
|
|
44
|
+
return [...new Set(r)];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}, P = (e) => e === null ? v("tenantId", null) : x(v("tenantId", e), v("tenantId", null)), F = (e) => (t) => {
|
|
48
|
+
let n = ("tenantId" in t ? t.tenantId : void 0) ?? null, r = ("id" in t ? t.id : void 0) ?? null;
|
|
49
|
+
return r ? e.rolesOf(r, n) : [];
|
|
50
|
+
}, I = h({ scope: "@voltro/plugin-rbac" }), L = (e) => e instanceof Promise ? p.promise(() => e) : p.succeed(e), R = (e) => {
|
|
51
|
+
let t = e.resolveRoles ?? u, n = e.resolvePermissions, r = e.tables !== void 0 && e.tables !== !1, i = typeof e.tables == "object" ? e.tables : {}, a = (r, i) => p.gen(function* () {
|
|
52
|
+
let a = yield* L(t(i.subject)).pipe(p.catchAllCause((e) => (I.warn("resolveRoles failed; falling back to raw subject scopes", {
|
|
53
|
+
tag: i.tag,
|
|
54
|
+
traceId: i.traceId,
|
|
55
|
+
cause: String(e)
|
|
56
|
+
}), p.succeed([])))), o = n ? yield* L(n(i.subject)).pipe(p.catchAllCause(() => p.succeed([]))) : [], c = s(i.subject, a, e.roles, o);
|
|
57
|
+
return f(i.subject, c, a), yield* r;
|
|
58
|
+
});
|
|
59
|
+
return m({
|
|
60
|
+
name: "@voltro/plugin-rbac",
|
|
61
|
+
description: "Role-based access control — roles compile to scopes on top of the protocol scope system. Ships the permission() handler guard + a role→scope interceptor + a typed Forbidden error.",
|
|
62
|
+
permissions: [
|
|
63
|
+
"rpc:intercept:mutation",
|
|
64
|
+
"rpc:intercept:query",
|
|
65
|
+
"rpc:intercept:action",
|
|
66
|
+
...r ? ["store:write"] : []
|
|
67
|
+
],
|
|
68
|
+
interceptMutation: a,
|
|
69
|
+
interceptQuery: a,
|
|
70
|
+
interceptAction: a,
|
|
71
|
+
errorSchemas: [{
|
|
72
|
+
schema: d,
|
|
73
|
+
import: {
|
|
74
|
+
module: "@voltro/plugin-rbac/errors",
|
|
75
|
+
name: "Forbidden"
|
|
76
|
+
}
|
|
77
|
+
}],
|
|
78
|
+
...r ? { extendSchema: { tables: [...j(i)] } } : {}
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { d as Forbidden, E as ROLES_TABLE, D as USER_ROLES_TABLE, n as WILDCARD_PERMISSION, o as anyPermission, l as assertPermission, k as buildUserRolesTable, i as can, r as compileRoles, F as dataStoreRoleResolver, s as mergeResolvedScopes, u as metadataRoleResolver, e as permission, R as rbacPlugin, j as rbacTables, t as resolvedRoles, a as resolvedScopes, c as rolesFromMap, O as rolesTable, f as setResolvedScopes, N as userRoleStore, A as userRolesTable };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Effect as e, Schema as t } from "effect";
|
|
2
|
+
import { ADMIN_SCOPE as n, subjectScopes as r } from "@voltro/protocol";
|
|
3
|
+
//#region src/roles.ts
|
|
4
|
+
var i = "*", a = (e, t) => {
|
|
5
|
+
let r = [], i = /* @__PURE__ */ new Set();
|
|
6
|
+
for (let a of e) {
|
|
7
|
+
let e = t[a];
|
|
8
|
+
if (e !== void 0) for (let t of e) {
|
|
9
|
+
if (t === "*") return [n];
|
|
10
|
+
i.has(t) || (i.add(t), r.push(t));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return r;
|
|
14
|
+
}, o = (e) => Object.entries(e).map(([e, t]) => ({
|
|
15
|
+
slug: e,
|
|
16
|
+
permissions: t
|
|
17
|
+
})), s = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), l = (e, t, n) => {
|
|
18
|
+
s.set(e, t), n !== void 0 && c.set(e, n);
|
|
19
|
+
}, u = (e) => s.get(e) ?? r(e), d = (e) => c.get(e) ?? [], f = (e) => {
|
|
20
|
+
if (!("metadata" in e) || e.metadata === void 0) return [];
|
|
21
|
+
let t = e.metadata.roles;
|
|
22
|
+
return Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
|
|
23
|
+
}, p = (e, t, n, i = []) => {
|
|
24
|
+
let o = a(t, n), s = [], c = /* @__PURE__ */ new Set();
|
|
25
|
+
for (let t of [
|
|
26
|
+
...r(e),
|
|
27
|
+
...o,
|
|
28
|
+
...i
|
|
29
|
+
]) c.has(t) || (c.add(t), s.push(t));
|
|
30
|
+
return s;
|
|
31
|
+
}, m = class extends t.TaggedError()("Forbidden", {
|
|
32
|
+
required: t.String,
|
|
33
|
+
reason: t.optional(t.String)
|
|
34
|
+
}) {}, h = (e, t) => {
|
|
35
|
+
let r = u(e);
|
|
36
|
+
return r.includes(n) || r.includes(t);
|
|
37
|
+
}, g = (e) => typeof e == "string" ? [e] : e, _ = (e, t) => {
|
|
38
|
+
for (let n of t) if (!h(e, n)) return n;
|
|
39
|
+
return null;
|
|
40
|
+
}, v = (t, n) => {
|
|
41
|
+
let r = g(n), i = _(t.request.subject, r);
|
|
42
|
+
return i === null ? e.void : e.fail(new m({
|
|
43
|
+
required: i,
|
|
44
|
+
reason: `missing required permission '${i}'`
|
|
45
|
+
}));
|
|
46
|
+
}, y = (t, n) => {
|
|
47
|
+
let r = t.request.subject;
|
|
48
|
+
if (n.length === 0) return e.void;
|
|
49
|
+
for (let t of n) if (h(r, t)) return e.void;
|
|
50
|
+
return e.fail(new m({
|
|
51
|
+
required: n[0],
|
|
52
|
+
reason: `missing all of required permissions [${n.join(", ")}]`
|
|
53
|
+
}));
|
|
54
|
+
}, b = (e, t) => {
|
|
55
|
+
let n = _(e.request.subject, g(t));
|
|
56
|
+
if (n !== null) throw new m({
|
|
57
|
+
required: n,
|
|
58
|
+
reason: `missing required permission '${n}'`
|
|
59
|
+
});
|
|
60
|
+
}, x = (e, t) => _(e.request.subject, g(t)) === null;
|
|
61
|
+
//#endregion
|
|
62
|
+
export { v as a, d as c, i as d, a as f, x as i, u as l, y as n, p as o, o as p, b as r, f as s, m as t, l as u };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { Schema } from 'effect';
|
|
3
|
+
import { Subject } from '@voltro/protocol';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Effect-form OR guard. Passes if the caller holds AT LEAST ONE of the
|
|
7
|
+
* listed permissions. Fails `Forbidden` (naming the first option) when it
|
|
8
|
+
* holds none. The `admin:full` bypass passes.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* yield* anyPermission(ctx, ['notes:write', 'notes:admin'])
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const anyPermission: (ctx: RbacContext, required: ReadonlyArray<string>) => Effect.Effect<void, Forbidden>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sync-form guard for async (non-Effect) handlers. THROWS `Forbidden`
|
|
18
|
+
* when the caller lacks the required permission(s). Array = AND.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* const execute = async (input, ctx) => {
|
|
22
|
+
* assertPermission(ctx, 'notes:write')
|
|
23
|
+
* return ctx.store.insert('notes', { ... })
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const assertPermission: (ctx: RbacContext, required: string | ReadonlyArray<string>) => void;
|
|
28
|
+
|
|
29
|
+
/** Pure boolean check — no throw, no Effect. For branching inside a handler. */
|
|
30
|
+
export declare const can: (ctx: RbacContext, required: string | ReadonlyArray<string>) => boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Raised when a caller lacks a required permission. Distinct from
|
|
34
|
+
* protocol's `ScopeError` so rbac owns its own wire surface; `rbacPlugin`
|
|
35
|
+
* registers it via `errorSchemas` so it decodes TYPED on the client.
|
|
36
|
+
*
|
|
37
|
+
* Declare it in a mutation's `error:` schema (or rely on `rbacPlugin`'s
|
|
38
|
+
* cross-cutting registration) so callers can pattern-match on
|
|
39
|
+
* `_tag === 'Forbidden'`.
|
|
40
|
+
*/
|
|
41
|
+
export declare class Forbidden extends Forbidden_base {
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare const Forbidden_base: Schema.TaggedErrorClass<Forbidden, "Forbidden", {
|
|
45
|
+
readonly _tag: Schema.tag<"Forbidden">;
|
|
46
|
+
} & {
|
|
47
|
+
/** The permission (or first missing permission) the caller lacked. */
|
|
48
|
+
required: typeof Schema.String;
|
|
49
|
+
/** Optional human-readable context. */
|
|
50
|
+
reason: Schema.optional<typeof Schema.String>;
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Effect-form guard. Fails with a typed `Forbidden` on the error channel
|
|
55
|
+
* when the caller lacks the required permission(s). An array means ALL
|
|
56
|
+
* are required (AND). The `admin:full` bypass passes everything.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* export default (input, ctx) => Effect.gen(function* () {
|
|
60
|
+
* yield* permission(ctx, 'notes:write')
|
|
61
|
+
* // ...
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const permission: (ctx: RbacContext, required: string | ReadonlyArray<string>) => Effect.Effect<void, Forbidden>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Anything carrying a resolved subject under `ctx.request.subject` — the
|
|
69
|
+
* shape every handler executor receives (`AppContext`). Kept structural
|
|
70
|
+
* so rbac needs no dependency on @voltro/runtime.
|
|
71
|
+
*/
|
|
72
|
+
export declare interface RbacContext {
|
|
73
|
+
readonly request: {
|
|
74
|
+
readonly subject: Subject;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Context } from 'react';
|
|
2
|
+
import { Provider } from 'react';
|
|
3
|
+
|
|
4
|
+
/** The blanket bypass scope — mirrors @voltro/protocol's ADMIN_SCOPE.
|
|
5
|
+
* Re-declared here so the web subpath never imports the node-side
|
|
6
|
+
* package root. */
|
|
7
|
+
export declare const ADMIN_SCOPE = "admin:full";
|
|
8
|
+
|
|
9
|
+
/** Pure OR check — passes if the set holds AT LEAST ONE of `required`. */
|
|
10
|
+
export declare const canAnyFromScopes: (scopes: ReadonlyArray<string>, required: ReadonlyArray<string>) => boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Pure check against a known scope set. `required` as an array means ALL
|
|
14
|
+
* are required (AND). The `admin:full` bypass passes everything. Exposed
|
|
15
|
+
* so non-hook code (loaders, route guards) can branch on the same logic.
|
|
16
|
+
*/
|
|
17
|
+
export declare const canFromScopes: (scopes: ReadonlyArray<string>, required: string | ReadonlyArray<string>) => boolean;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The resolved scope set the current caller holds, as the client knows
|
|
21
|
+
* it. Fed by the app's SubjectProvider (e.g. from `@voltro/plugin-auth`'s
|
|
22
|
+
* web `subjectContext`): wrap the tree in `<RbacScopeProvider scopes={...}>`
|
|
23
|
+
* sourced from the resolved subject.
|
|
24
|
+
*/
|
|
25
|
+
export declare const RbacScopeContext: Context<readonly string[]>;
|
|
26
|
+
|
|
27
|
+
/** Provider for the caller's resolved scopes. */
|
|
28
|
+
export declare const RbacScopeProvider: Provider<readonly string[]>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* UI-only permission check. Reads the caller's resolved scopes from
|
|
32
|
+
* `RbacScopeContext` and returns whether they hold `required` (array =
|
|
33
|
+
* AND). For hiding affordances ONLY — the server `permission()` guard is
|
|
34
|
+
* the real authorization boundary.
|
|
35
|
+
*
|
|
36
|
+
* ```tsx
|
|
37
|
+
* const canEdit = useCan('notes:write')
|
|
38
|
+
* return canEdit ? <EditButton /> : null
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const useCan: (required: string | ReadonlyArray<string>) => boolean;
|
|
42
|
+
|
|
43
|
+
/** UI-only OR check — true if the caller holds at least one of `required`. */
|
|
44
|
+
export declare const useCanAny: (required: ReadonlyArray<string>) => boolean;
|
|
45
|
+
|
|
46
|
+
export { }
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createContext as e, useContext as t } from "react";
|
|
2
|
+
//#region src/web/index.ts
|
|
3
|
+
var n = "admin:full", r = e([]), i = r.Provider, a = (e, t) => e.includes("admin:full") || e.includes(t), o = (e, t) => (typeof t == "string" ? [t] : t).every((t) => a(e, t)), s = (e, t) => t.length === 0 || t.some((t) => a(e, t)), c = (e) => o(t(r), e), l = (e) => s(t(r), e);
|
|
4
|
+
//#endregion
|
|
5
|
+
export { n as ADMIN_SCOPE, r as RbacScopeContext, i as RbacScopeProvider, s as canAnyFromScopes, o as canFromScopes, c as useCan, l as useCanAny };
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voltro/plugin-rbac",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Role-based access control — roles compile to scopes on top of @voltro/protocol's scope system. Ships rbacPlugin() (role→scope interceptor + typed Forbidden error), the permission()/assertPermission()/anyPermission() handler guards, the compileRoles() pure compiler, cross-dialect roles + userRoles tables, and a browser-safe useCan() UI affordance.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"voltro",
|
|
7
|
+
"typescript",
|
|
8
|
+
"framework"
|
|
9
|
+
],
|
|
10
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
11
|
+
"homepage": "https://voltro.dev",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"email": "support@voltro.dev"
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Voltro UG",
|
|
17
|
+
"url": "https://voltro.dev"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./web": {
|
|
27
|
+
"types": "./dist/web/index.d.ts",
|
|
28
|
+
"import": "./dist/web/index.js",
|
|
29
|
+
"default": "./dist/web/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./errors": {
|
|
32
|
+
"types": "./dist/permission.d.ts",
|
|
33
|
+
"import": "./dist/permission.js",
|
|
34
|
+
"default": "./dist/permission.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"module": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"sideEffects": false,
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=24.0.0"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@voltro/database": "0.1.0",
|
|
46
|
+
"@voltro/logger": "0.1.0",
|
|
47
|
+
"@voltro/protocol": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"effect": "^3.21.4",
|
|
51
|
+
"react": "^19.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"react": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
}
|
|
61
|
+
}
|