@voltro/plugin-flags 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/errors.d.ts +14 -0
- package/dist/errors.js +5 -0
- package/dist/index.d.ts +252 -0
- package/dist/index.js +341 -0
- package/dist/rpc.d.ts +17 -0
- package/dist/rpc.js +38 -0
- package/dist/web.d.ts +27 -0
- package/dist/web.js +11 -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-flags
|
|
4
|
+
|
|
5
|
+
**Feature flags — per-subject / per-tenant targeting, deterministic % rollouts, kill-switch. Gate mutations/queries/actions declaratively or guard in-handler; evaluate flags client-side for UI gating. Config-as-code (memory) or runtime-toggleable (postgres).**
|
|
6
|
+
|
|
7
|
+
[📖 Documentation](https://docs.voltro.dev/docs/plugins/flags) · [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-flags
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
> ### [→ Read the documentation for @voltro/plugin-flags](https://docs.voltro.dev/docs/plugins/flags)
|
|
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-flags
|
|
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-flags 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/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
|
|
3
|
+
/** Raised when a flag-gated call hits a disabled flag. Merged into every
|
|
4
|
+
* procedure's wire-error union so the client decodes it typed. */
|
|
5
|
+
export declare class FlagDisabled extends FlagDisabled_base {
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare const FlagDisabled_base: Schema.TaggedErrorClass<FlagDisabled, "FlagDisabled", {
|
|
9
|
+
readonly _tag: Schema.tag<"FlagDisabled">;
|
|
10
|
+
} & {
|
|
11
|
+
flag: typeof Schema.String;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
export { }
|
package/dist/errors.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
import { Schema } from 'effect';
|
|
3
|
+
import { VoltroPlugin } from '@voltro/protocol';
|
|
4
|
+
|
|
5
|
+
/** Convert a resolved flag to a dashboard/inspect row. Surfaces the variant
|
|
6
|
+
* names + a `scheduled` flag so the panel can badge multivariate / time-boxed
|
|
7
|
+
* flags without re-deriving the definition. */
|
|
8
|
+
export declare const describeFlags: (flags: Record<string, FlagValue>) => Array<{
|
|
9
|
+
key: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
rollout: number;
|
|
12
|
+
variants: ReadonlyArray<string> | undefined;
|
|
13
|
+
scheduled: boolean;
|
|
14
|
+
description: string | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
|
|
17
|
+
/** Evaluate every flag in a set → `{ key: boolean }`. */
|
|
18
|
+
export declare const evaluateAll: (flags: Record<string, FlagValue>, subject: FlagSubject, now?: number) => Record<string, boolean>;
|
|
19
|
+
|
|
20
|
+
/** Evaluate every flag in a set → `{ key: VariantResolution }` (variant + on). */
|
|
21
|
+
export declare const evaluateAllVariants: (flags: Record<string, FlagValue>, subject: FlagSubject, now?: number) => Record<string, VariantResolution>;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Evaluate a flag for a subject. Order: master switch → schedule (time-box +
|
|
25
|
+
* ramp) → targeting (OR-of-rules) → deterministic % rollout. The flag `key`
|
|
26
|
+
* salts the rollout bucket so each flag partitions subjects independently.
|
|
27
|
+
* Anonymous/idless callers bucket on `'anon'`. A multivariate flag is "on"
|
|
28
|
+
* unless the served variant is its `offVariant`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const evaluateFlag: (key: string, value: FlagValue, subject: FlagSubject, now?: number) => boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Resolve a schedule against `now`. Returns whether the flag is active and, for
|
|
34
|
+
* a `ramp`, the interpolated rollout % that REPLACES the static `rollout`.
|
|
35
|
+
* Outside `[activateAt, deactivateAt)` ⇒ inactive. A ramp linearly interpolates
|
|
36
|
+
* `from`→`to` across `[startAt, endAt)`; before `startAt` ⇒ `from`, at/after
|
|
37
|
+
* `endAt` ⇒ `to`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const evaluateSchedule: (schedule: FlagSchedule, now: number) => {
|
|
40
|
+
readonly active: boolean;
|
|
41
|
+
readonly rollout?: number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Evaluate a multivariate flag for a subject → the served variant + whether the
|
|
46
|
+
* flag counts as on. When the flag has no `variants`, a synthetic on/off variant
|
|
47
|
+
* (`'on'`/`'off'`) is returned from the boolean resolution, so every flag has a
|
|
48
|
+
* uniform variant surface.
|
|
49
|
+
*/
|
|
50
|
+
export declare const evaluateVariant: (key: string, value: FlagValue, subject: FlagSubject, now?: number) => VariantResolution;
|
|
51
|
+
|
|
52
|
+
/** One kill-switch audit row (who flipped what, when, old→new). */
|
|
53
|
+
export declare interface FlagAuditRow {
|
|
54
|
+
readonly flag: string;
|
|
55
|
+
readonly enabled: boolean;
|
|
56
|
+
readonly previousEnabled: boolean | null;
|
|
57
|
+
readonly actorId: string | null;
|
|
58
|
+
readonly at: Date;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export declare interface FlagDefinition {
|
|
62
|
+
/** Master switch. `false` → off for everyone regardless of rollout/targeting. Default true. */
|
|
63
|
+
readonly enabled?: boolean;
|
|
64
|
+
/** Percentage rollout 0..100 — deterministic per (key, subject/tenant) so a
|
|
65
|
+
* caller stays in/out consistently. Omit = 100 (everyone the targeting allows). */
|
|
66
|
+
readonly rollout?: number;
|
|
67
|
+
/** OR-of-rules targeting. When present, the caller must match at least one
|
|
68
|
+
* rule (in addition to passing the rollout). Omit = everyone. */
|
|
69
|
+
readonly targeting?: ReadonlyArray<FlagTargetingRule>;
|
|
70
|
+
/** Bucket on the tenant id instead of the subject id (rollout by tenant). */
|
|
71
|
+
readonly rolloutBy?: 'subject' | 'tenant';
|
|
72
|
+
/** Multivariate flag — a set of named variants the flag resolves ONE of per
|
|
73
|
+
* subject, deterministically weighted (see `FlagVariant.weight`). A subject
|
|
74
|
+
* stays in the same variant across calls. When present, `variant.evaluate`
|
|
75
|
+
* serves the resolved variant; the boolean resolution is `enabled && variant
|
|
76
|
+
* is served` (the flag is "on" for the caller unless a variant named in
|
|
77
|
+
* `offVariant` is served — omit ⇒ any served variant counts as on). */
|
|
78
|
+
readonly variants?: ReadonlyArray<FlagVariant>;
|
|
79
|
+
/** Variant name treated as the "off" state for boolean resolution. Omit ⇒
|
|
80
|
+
* passing targeting+rollout with any served variant counts as on. */
|
|
81
|
+
readonly offVariant?: string;
|
|
82
|
+
/** Time-boxed / ramping schedule, evaluated against the current time. */
|
|
83
|
+
readonly schedule?: FlagSchedule;
|
|
84
|
+
/** Surfaced in the dashboard / `flags.evaluate`. */
|
|
85
|
+
readonly description?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Raised when a flag-gated call hits a disabled flag. Merged into every
|
|
89
|
+
* procedure's wire-error union so the client decodes it typed. */
|
|
90
|
+
export declare class FlagDisabled extends FlagDisabled_base {
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
declare const FlagDisabled_base: Schema.TaggedErrorClass<FlagDisabled, "FlagDisabled", {
|
|
94
|
+
readonly _tag: Schema.tag<"FlagDisabled">;
|
|
95
|
+
} & {
|
|
96
|
+
flag: typeof Schema.String;
|
|
97
|
+
}>;
|
|
98
|
+
|
|
99
|
+
/** A persisted override row (`_voltro_feature_flags`). `targeting` is JSON. */
|
|
100
|
+
declare interface FlagOverrideRow {
|
|
101
|
+
readonly key: string;
|
|
102
|
+
readonly enabled: boolean;
|
|
103
|
+
readonly rollout: number | null;
|
|
104
|
+
readonly rolloutBy: string | null;
|
|
105
|
+
readonly targeting: unknown;
|
|
106
|
+
readonly variants: unknown;
|
|
107
|
+
readonly offVariant: string | null;
|
|
108
|
+
readonly schedule: unknown;
|
|
109
|
+
readonly description: string | null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Mutable live registry of resolved flags. The plugin sets it at activation
|
|
113
|
+
* (config) and refreshes it after a DB load / toggle. Read by the in-handler
|
|
114
|
+
* guards (`requireFlag`/`isFlagEnabled`). */
|
|
115
|
+
declare class FlagRegistry {
|
|
116
|
+
private flags;
|
|
117
|
+
set(flags: Record<string, FlagValue>): void;
|
|
118
|
+
all(): Record<string, FlagValue>;
|
|
119
|
+
get(key: string): FlagValue | undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Process-wide registry so the ctx guards (which can't reach the plugin
|
|
123
|
+
* instance) evaluate against the live flag set. */
|
|
124
|
+
export declare const flagRegistry: FlagRegistry;
|
|
125
|
+
|
|
126
|
+
/** A time-boxed / ramping schedule. Evaluated against the current time.
|
|
127
|
+
* Order: outside [activateAt, deactivateAt) ⇒ off; a `ramp` interpolates the
|
|
128
|
+
* effective rollout % linearly across its window. */
|
|
129
|
+
export declare interface FlagSchedule {
|
|
130
|
+
/** Flag is off before this instant (epoch millis or ISO string). Omit ⇒ no lower bound. */
|
|
131
|
+
readonly activateAt?: number | string;
|
|
132
|
+
/** Flag is off at/after this instant (epoch millis or ISO string). Omit ⇒ no upper bound. */
|
|
133
|
+
readonly deactivateAt?: number | string;
|
|
134
|
+
/** A ramping rollout: exposure grows linearly from `from`% to `to`% across
|
|
135
|
+
* [`startAt`, `endAt`). Before `startAt` ⇒ `from`%, after `endAt` ⇒ `to`%.
|
|
136
|
+
* The interpolated % REPLACES the flag's static `rollout` while active. */
|
|
137
|
+
readonly ramp?: {
|
|
138
|
+
readonly from: number;
|
|
139
|
+
readonly to: number;
|
|
140
|
+
readonly startAt: number | string;
|
|
141
|
+
readonly endAt: number | string;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export declare const flagsPlugin: (options?: FlagsPluginOptions) => VoltroPlugin;
|
|
146
|
+
|
|
147
|
+
export declare interface FlagsPluginOptions {
|
|
148
|
+
/** Flags as code. The baseline; a postgres store overlays runtime toggles. */
|
|
149
|
+
readonly flags?: Record<string, FlagValue>;
|
|
150
|
+
/** `'memory'` (config-as-code, default) | `'postgres'` (runtime-toggleable
|
|
151
|
+
* via `_voltro_feature_flags`, overlaid on the config baseline). */
|
|
152
|
+
readonly store?: 'memory' | 'postgres';
|
|
153
|
+
/** Declarative gate: map an rpc tag (or regex) → flag key. A call to a gated
|
|
154
|
+
* tag fails `FlagDisabled` BEFORE the handler runs when the flag is off. */
|
|
155
|
+
readonly gatedBy?: Record<string, string>;
|
|
156
|
+
/** Disambiguates multiple instances. */
|
|
157
|
+
readonly name?: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The minimal subject shape evaluation needs (avoids a hard `Subject` dep). */
|
|
161
|
+
export declare interface FlagSubject {
|
|
162
|
+
readonly id?: string | null;
|
|
163
|
+
readonly type?: string;
|
|
164
|
+
readonly tenantId?: string | null;
|
|
165
|
+
readonly metadata?: Record<string, unknown> | null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** One targeting rule — ANDs its conditions; a flag's `targeting` is an OR of rules. */
|
|
169
|
+
export declare interface FlagTargetingRule {
|
|
170
|
+
/** Match specific subject ids. */
|
|
171
|
+
readonly subjectIds?: ReadonlyArray<string>;
|
|
172
|
+
/** Match specific tenant ids. */
|
|
173
|
+
readonly tenantIds?: ReadonlyArray<string>;
|
|
174
|
+
/** Match `subject.type` (user / apiKey / serviceAccount / anonymous). */
|
|
175
|
+
readonly subjectTypes?: ReadonlyArray<string>;
|
|
176
|
+
/** Match `subject.metadata[key] === value` for every entry. */
|
|
177
|
+
readonly metadata?: Record<string, string>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** A flag value as authored: bare boolean (kill-switch) OR a rich definition. */
|
|
181
|
+
export declare type FlagValue = boolean | FlagDefinition;
|
|
182
|
+
|
|
183
|
+
/** One multivariate variant: a named value with an optional rollout weight. */
|
|
184
|
+
export declare interface FlagVariant {
|
|
185
|
+
/** Stable variant name (the resolution returns this). */
|
|
186
|
+
readonly name: string;
|
|
187
|
+
/** The value served for this variant (string / number / boolean / JSON). */
|
|
188
|
+
readonly value: FlagVariantValue;
|
|
189
|
+
/** Relative allocation weight. Omit ⇒ equal split of the remaining weight.
|
|
190
|
+
* Weights are normalised, so `[3, 1]` is 75% / 25%. */
|
|
191
|
+
readonly weight?: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** A concrete variant value — string / number / boolean / JSON. Kept browser-safe. */
|
|
195
|
+
export declare type FlagVariantValue = string | number | boolean | null | ReadonlyArray<unknown> | Record<string, unknown>;
|
|
196
|
+
|
|
197
|
+
/** Flip a flag's `enabled`, returning the PREVIOUS enabled state (for the audit
|
|
198
|
+
* trail), or `null` if the key is unknown. `setFlagEnabled` is the boolean
|
|
199
|
+
* companion for callers that don't need the old value. */
|
|
200
|
+
export declare const flipFlagEnabled: (key: string, enabled: boolean) => boolean | null;
|
|
201
|
+
|
|
202
|
+
/** Loose ctx shape: the framework `AppContext` (`ctx.request.subject`) OR a
|
|
203
|
+
* bare `{ subject }`. */
|
|
204
|
+
declare type GuardCtx = {
|
|
205
|
+
request?: {
|
|
206
|
+
subject?: FlagSubject;
|
|
207
|
+
};
|
|
208
|
+
} | {
|
|
209
|
+
subject?: FlagSubject;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/** `true` if the flag is on for the caller. */
|
|
213
|
+
export declare const isFlagEnabled: (ctx: GuardCtx, key: string) => boolean;
|
|
214
|
+
|
|
215
|
+
/** Overlay persisted override rows on top of the config baseline. An override
|
|
216
|
+
* fully replaces the config flag's definition (last-write-wins), so toggling a
|
|
217
|
+
* flag off in the DB beats the code default. Pure. */
|
|
218
|
+
export declare const mergeOverrides: (config: Record<string, FlagValue>, rows: ReadonlyArray<FlagOverrideRow>) => Record<string, FlagValue>;
|
|
219
|
+
|
|
220
|
+
/** Effect-native guard — fails typed `FlagDisabled` when the flag is off for
|
|
221
|
+
* the caller. Declare `error: FlagDisabled` on the procedure for a typed client. */
|
|
222
|
+
export declare const requireFlag: (ctx: GuardCtx, key: string) => Effect.Effect<void, FlagDisabled>;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Resolve WHICH variant a subject gets — deterministic + stable, weighted by
|
|
226
|
+
* each variant's `weight` (equal split when omitted). Buckets on a `variant`-
|
|
227
|
+
* salted hash so it's independent of the % rollout bucket. Falls back to the
|
|
228
|
+
* first variant.
|
|
229
|
+
*/
|
|
230
|
+
export declare const resolveVariant: (key: string, def: FlagDefinition, subject: FlagSubject) => FlagVariant;
|
|
231
|
+
|
|
232
|
+
/** Toggle a flag's `enabled` in the live registry (the dashboard panel's
|
|
233
|
+
* write action). Preserves rollout/targeting/variants/schedule/description —
|
|
234
|
+
* only flips the kill-switch. Returns `false` if the key is unknown. In-memory:
|
|
235
|
+
* persists only when a postgres overlay store is wired. */
|
|
236
|
+
export declare const setFlagEnabled: (key: string, enabled: boolean) => boolean;
|
|
237
|
+
|
|
238
|
+
/** Normalise a bare boolean to a definition. */
|
|
239
|
+
export declare const toDefinition: (value: FlagValue) => FlagDefinition;
|
|
240
|
+
|
|
241
|
+
/** The result of resolving a multivariate flag for a subject. */
|
|
242
|
+
export declare interface VariantResolution {
|
|
243
|
+
/** The resolved variant name. */
|
|
244
|
+
readonly name: string;
|
|
245
|
+
/** The resolved variant's value. */
|
|
246
|
+
readonly value: FlagVariantValue;
|
|
247
|
+
/** Whether the flag is on for the caller (master switch / schedule / targeting
|
|
248
|
+
* / rollout all passed, and the variant is not the `offVariant`). */
|
|
249
|
+
readonly enabled: boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { evaluateDescriptor as e, evaluateVariantsDescriptor as t, flagsRpcClientImports as n } from "./rpc.js";
|
|
2
|
+
import { FlagDisabled as r } from "./errors.js";
|
|
3
|
+
import { Effect as i } from "effect";
|
|
4
|
+
import { definePlugin as a } from "@voltro/protocol";
|
|
5
|
+
import { boolean as o, id as s, integer as c, json as l, queryFor as u, table as d, text as f, timestamp as p } from "@voltro/database";
|
|
6
|
+
//#region src/evaluate.ts
|
|
7
|
+
var m = (e) => typeof e == "boolean" ? { enabled: e } : e, h = (e, t) => {
|
|
8
|
+
let n = 2166136261, r = `${e}:${t}`;
|
|
9
|
+
for (let e = 0; e < r.length; e++) n ^= r.charCodeAt(e), n = Math.imul(n, 16777619);
|
|
10
|
+
return n >>> 0;
|
|
11
|
+
}, g = (e, t) => h(e, t) % 100, _ = (e, t) => h(`${e}:variant`, t) % 1e4, v = (e, t) => {
|
|
12
|
+
if (e.subjectIds && !(t.id != null && e.subjectIds.includes(t.id)) || e.tenantIds && !(t.tenantId != null && e.tenantIds.includes(t.tenantId)) || e.subjectTypes && !(t.type != null && e.subjectTypes.includes(t.type))) return !1;
|
|
13
|
+
if (e.metadata) {
|
|
14
|
+
let n = t.metadata ?? {};
|
|
15
|
+
for (let [t, r] of Object.entries(e.metadata)) if (String(n[t]) !== r) return !1;
|
|
16
|
+
}
|
|
17
|
+
return !0;
|
|
18
|
+
}, y = (e) => typeof e == "number" ? e : Date.parse(e), b = (e, t) => (e.rolloutBy === "tenant" ? t.tenantId : t.id) ?? "anon", x = (e, t) => {
|
|
19
|
+
if (e.activateAt != null && t < y(e.activateAt) || e.deactivateAt != null && t >= y(e.deactivateAt)) return { active: !1 };
|
|
20
|
+
if (e.ramp) {
|
|
21
|
+
let { from: n, to: r, startAt: i, endAt: a } = e.ramp, o = y(i), s = y(a);
|
|
22
|
+
if (t <= o) return {
|
|
23
|
+
active: !0,
|
|
24
|
+
rollout: n
|
|
25
|
+
};
|
|
26
|
+
if (t >= s || s <= o) return {
|
|
27
|
+
active: !0,
|
|
28
|
+
rollout: r
|
|
29
|
+
};
|
|
30
|
+
let c = (t - o) / (s - o);
|
|
31
|
+
return {
|
|
32
|
+
active: !0,
|
|
33
|
+
rollout: n + (r - n) * c
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return { active: !0 };
|
|
37
|
+
}, S = (e, t, n, r = Date.now()) => {
|
|
38
|
+
let i = m(t);
|
|
39
|
+
if (i.enabled === !1) return !1;
|
|
40
|
+
let a;
|
|
41
|
+
if (i.schedule) {
|
|
42
|
+
let e = x(i.schedule, r);
|
|
43
|
+
if (!e.active) return !1;
|
|
44
|
+
a = e.rollout;
|
|
45
|
+
}
|
|
46
|
+
if (i.targeting && i.targeting.length > 0 && !i.targeting.some((e) => v(e, n))) return !1;
|
|
47
|
+
let o = a ?? i.rollout ?? 100;
|
|
48
|
+
if (o < 100 && o > 0) {
|
|
49
|
+
if (!(g(e, b(i, n)) < o)) return !1;
|
|
50
|
+
} else if (o <= 0) return !1;
|
|
51
|
+
return i.variants && i.variants.length > 0 && i.offVariant != null ? w(e, i, n).name !== i.offVariant : !0;
|
|
52
|
+
}, C = (e) => {
|
|
53
|
+
let t = e.reduce((e, t) => e + (t.weight ?? 1), 0) || e.length, n = 0;
|
|
54
|
+
return e.map((r, i) => (n += r.weight ?? 1, i === e.length - 1 ? 1e4 : Math.round(n / t * 1e4)));
|
|
55
|
+
}, w = (e, t, n) => {
|
|
56
|
+
let r = t.variants ?? [];
|
|
57
|
+
if (r.length === 0) throw Error(`flag "${e}" has no variants`);
|
|
58
|
+
let i = _(e, b(t, n)), a = C(r);
|
|
59
|
+
for (let e = 0; e < r.length; e++) if (i < a[e]) return r[e];
|
|
60
|
+
return r[r.length - 1];
|
|
61
|
+
}, T = (e, t, n, r = Date.now()) => {
|
|
62
|
+
let i = m(t), a = S(e, t, n, r);
|
|
63
|
+
if (!i.variants || i.variants.length === 0) return {
|
|
64
|
+
name: a ? "on" : "off",
|
|
65
|
+
value: a,
|
|
66
|
+
enabled: a
|
|
67
|
+
};
|
|
68
|
+
let o = w(e, i, n);
|
|
69
|
+
return {
|
|
70
|
+
name: o.name,
|
|
71
|
+
value: o.value,
|
|
72
|
+
enabled: a
|
|
73
|
+
};
|
|
74
|
+
}, E = (e, t, n = Date.now()) => {
|
|
75
|
+
let r = {};
|
|
76
|
+
for (let [i, a] of Object.entries(e)) r[i] = S(i, a, t, n);
|
|
77
|
+
return r;
|
|
78
|
+
}, D = (e, t, n = Date.now()) => {
|
|
79
|
+
let r = {};
|
|
80
|
+
for (let [i, a] of Object.entries(e)) r[i] = T(i, a, t, n);
|
|
81
|
+
return r;
|
|
82
|
+
}, O = "_voltro_feature_flag_audit", k = "_voltro_feature_flags", A = d(k, {
|
|
83
|
+
id: s({ prefix: "flag" }),
|
|
84
|
+
key: f().unique(),
|
|
85
|
+
enabled: o().default(!0),
|
|
86
|
+
rollout: c().nullable(),
|
|
87
|
+
rolloutBy: f().nullable(),
|
|
88
|
+
targeting: l().nullable(),
|
|
89
|
+
variants: l().nullable(),
|
|
90
|
+
offVariant: f().nullable(),
|
|
91
|
+
schedule: l().nullable(),
|
|
92
|
+
description: f().nullable(),
|
|
93
|
+
updatedAt: p().default("now").onUpdate("now")
|
|
94
|
+
}), j = d(O, {
|
|
95
|
+
id: s({ prefix: "flagaud" }),
|
|
96
|
+
flag: f(),
|
|
97
|
+
enabled: o(),
|
|
98
|
+
previousEnabled: o().nullable(),
|
|
99
|
+
actorId: f().nullable(),
|
|
100
|
+
at: p().default("now")
|
|
101
|
+
}).index("byFlagAuditFlag", ["flag"]).index("byFlagAuditAt", ["at"]), M = (e, t) => {
|
|
102
|
+
let n = { ...e };
|
|
103
|
+
for (let e of t) {
|
|
104
|
+
let t = {
|
|
105
|
+
enabled: e.enabled,
|
|
106
|
+
...e.rollout == null ? {} : { rollout: e.rollout },
|
|
107
|
+
...e.rolloutBy === "tenant" || e.rolloutBy === "subject" ? { rolloutBy: e.rolloutBy } : {},
|
|
108
|
+
...Array.isArray(e.targeting) ? { targeting: e.targeting } : {},
|
|
109
|
+
...Array.isArray(e.variants) ? { variants: e.variants } : {},
|
|
110
|
+
...e.offVariant == null ? {} : { offVariant: e.offVariant },
|
|
111
|
+
...e.schedule != null && typeof e.schedule == "object" ? { schedule: e.schedule } : {},
|
|
112
|
+
...e.description == null ? {} : { description: e.description }
|
|
113
|
+
};
|
|
114
|
+
n[e.key] = t;
|
|
115
|
+
}
|
|
116
|
+
return n;
|
|
117
|
+
}, N = new class {
|
|
118
|
+
flags = {};
|
|
119
|
+
set(e) {
|
|
120
|
+
this.flags = e;
|
|
121
|
+
}
|
|
122
|
+
all() {
|
|
123
|
+
return this.flags;
|
|
124
|
+
}
|
|
125
|
+
get(e) {
|
|
126
|
+
return this.flags[e];
|
|
127
|
+
}
|
|
128
|
+
}(), P = (e, t) => F(e, t) !== null, F = (e, t) => {
|
|
129
|
+
let n = N.get(e);
|
|
130
|
+
if (n === void 0) return null;
|
|
131
|
+
let r = m(n), i = r.enabled !== !1;
|
|
132
|
+
return N.set({
|
|
133
|
+
...N.all(),
|
|
134
|
+
[e]: {
|
|
135
|
+
...r,
|
|
136
|
+
enabled: t
|
|
137
|
+
}
|
|
138
|
+
}), i;
|
|
139
|
+
}, I = (e) => Object.entries(e).map(([e, t]) => {
|
|
140
|
+
let n = m(t);
|
|
141
|
+
return {
|
|
142
|
+
key: e,
|
|
143
|
+
enabled: n.enabled !== !1,
|
|
144
|
+
rollout: n.rollout ?? 100,
|
|
145
|
+
variants: n.variants && n.variants.length > 0 ? n.variants.map((e) => e.name) : void 0,
|
|
146
|
+
scheduled: n.schedule != null,
|
|
147
|
+
description: n.description
|
|
148
|
+
};
|
|
149
|
+
}), L = (e, t) => {
|
|
150
|
+
let n = m(t);
|
|
151
|
+
return {
|
|
152
|
+
key: e,
|
|
153
|
+
enabled: n.enabled !== !1,
|
|
154
|
+
rollout: n.rollout ?? null,
|
|
155
|
+
rolloutBy: n.rolloutBy ?? null,
|
|
156
|
+
targeting: n.targeting ?? null,
|
|
157
|
+
variants: n.variants ?? null,
|
|
158
|
+
offVariant: n.offVariant ?? null,
|
|
159
|
+
schedule: n.schedule ?? null,
|
|
160
|
+
description: n.description ?? null
|
|
161
|
+
};
|
|
162
|
+
}, R = (e) => ({
|
|
163
|
+
loadOverrides: async () => (await e.query(u(A).descriptor)).map((e) => ({
|
|
164
|
+
key: String(e.key),
|
|
165
|
+
enabled: e.enabled === !0 || e.enabled === 1,
|
|
166
|
+
rollout: e.rollout == null ? null : Number(e.rollout),
|
|
167
|
+
rolloutBy: e.rolloutBy ?? null,
|
|
168
|
+
targeting: e.targeting ?? null,
|
|
169
|
+
variants: e.variants ?? null,
|
|
170
|
+
offVariant: e.offVariant ?? null,
|
|
171
|
+
schedule: e.schedule ?? null,
|
|
172
|
+
description: e.description ?? null
|
|
173
|
+
})),
|
|
174
|
+
upsertOverride: async (t) => {
|
|
175
|
+
let n = {
|
|
176
|
+
id: `flag_${t.key}`,
|
|
177
|
+
key: t.key,
|
|
178
|
+
enabled: t.enabled,
|
|
179
|
+
rollout: t.rollout,
|
|
180
|
+
rolloutBy: t.rolloutBy,
|
|
181
|
+
targeting: t.targeting,
|
|
182
|
+
variants: t.variants,
|
|
183
|
+
offVariant: t.offVariant,
|
|
184
|
+
schedule: t.schedule,
|
|
185
|
+
description: t.description,
|
|
186
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
187
|
+
};
|
|
188
|
+
await e.upsert(k, n, { conflictColumns: ["key"] });
|
|
189
|
+
}
|
|
190
|
+
}), z = (e) => ({
|
|
191
|
+
flag: String(e.flag),
|
|
192
|
+
enabled: e.enabled === !0 || e.enabled === 1,
|
|
193
|
+
previousEnabled: e.previousEnabled == null ? null : e.previousEnabled === !0 || e.previousEnabled === 1,
|
|
194
|
+
actorId: e.actorId ?? null,
|
|
195
|
+
at: e.at instanceof Date ? e.at : new Date(String(e.at))
|
|
196
|
+
}), B = (e) => ({
|
|
197
|
+
record: async (t) => {
|
|
198
|
+
await e.insert(O, {
|
|
199
|
+
id: `flagaud_${t.at.getTime()}_${Math.random().toString(36).slice(2, 10)}`,
|
|
200
|
+
flag: t.flag,
|
|
201
|
+
enabled: t.enabled,
|
|
202
|
+
previousEnabled: t.previousEnabled,
|
|
203
|
+
actorId: t.actorId,
|
|
204
|
+
at: t.at
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
list: async (t) => {
|
|
208
|
+
let n = u(j).orderBy("at", "desc");
|
|
209
|
+
t?.limit != null && (n = n.limit(t.limit));
|
|
210
|
+
let r = (await e.query(n.descriptor)).map(z);
|
|
211
|
+
return t?.flag == null ? r : r.filter((e) => e.flag === t.flag);
|
|
212
|
+
}
|
|
213
|
+
}), V = (e) => "request" in e && e.request?.subject || "subject" in e && e.subject || {}, H = (e, t) => {
|
|
214
|
+
let n = N.get(t);
|
|
215
|
+
return n !== void 0 && S(t, n, V(e));
|
|
216
|
+
}, U = (e, t) => H(e, t) ? i.void : i.fail(new r({ flag: t })), W = (e, t) => e === t || e.startsWith("/") && e.endsWith("/") && new RegExp(e.slice(1, -1)).test(t), G = (o = {}) => {
|
|
217
|
+
let s = { ...o.flags ?? {} }, c = o.gatedBy ?? {}, l = o.name ? `@voltro/plugin-flags#${o.name}` : "@voltro/plugin-flags", u = o.store === "postgres", d, f, p = async () => {
|
|
218
|
+
d && N.set(M(s, await d.loadOverrides()));
|
|
219
|
+
}, m = (e) => {
|
|
220
|
+
if (c[e] !== void 0) return c[e];
|
|
221
|
+
for (let [t, n] of Object.entries(c)) if (t !== e && W(t, e)) return n;
|
|
222
|
+
}, h = (e, t) => {
|
|
223
|
+
let n = m(t.tag);
|
|
224
|
+
return n === void 0 || H({ subject: t.subject }, n) ? e : i.fail(new r({ flag: n }));
|
|
225
|
+
}, g = Object.keys(c).length > 0, _ = {
|
|
226
|
+
...e,
|
|
227
|
+
description: "Resolve every feature flag for the calling subject.",
|
|
228
|
+
execute: (e, t) => i.succeed(E(N.all(), t.request.subject ?? {}))
|
|
229
|
+
}, v = {
|
|
230
|
+
...t,
|
|
231
|
+
description: "Resolve every feature flag to its served variant for the calling subject.",
|
|
232
|
+
execute: (e, t) => i.succeed(D(N.all(), t.request.subject ?? {}))
|
|
233
|
+
}, y = (e) => ({
|
|
234
|
+
kind: "json",
|
|
235
|
+
data: e
|
|
236
|
+
}), b = (e, t) => ({
|
|
237
|
+
kind: "json",
|
|
238
|
+
status: e,
|
|
239
|
+
data: { error: t }
|
|
240
|
+
}), x = [
|
|
241
|
+
{
|
|
242
|
+
method: "GET",
|
|
243
|
+
path: "/list",
|
|
244
|
+
description: "Every resolved flag (key, enabled, rollout, description).",
|
|
245
|
+
handler: () => i.succeed(y({ flags: I(N.all()) }))
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
method: "POST",
|
|
249
|
+
path: "/toggle",
|
|
250
|
+
description: "Flip a flag's kill-switch on/off (live registry; durable on the postgres tier). Logs an audit row.",
|
|
251
|
+
handler: (e) => i.gen(function* () {
|
|
252
|
+
let t;
|
|
253
|
+
try {
|
|
254
|
+
t = JSON.parse(e.body || "{}");
|
|
255
|
+
} catch {
|
|
256
|
+
return b(400, "invalid JSON body");
|
|
257
|
+
}
|
|
258
|
+
if (!t.key || typeof t.enabled != "boolean") return b(400, "key (string) + enabled (boolean) required");
|
|
259
|
+
let n = F(t.key, t.enabled);
|
|
260
|
+
if (n === null) return b(404, `unknown flag "${t.key}"`);
|
|
261
|
+
let r = d ? N.get(t.key) : void 0;
|
|
262
|
+
return d && r !== void 0 && (yield* i.promise(() => d.upsertOverride(L(t.key, r)))), f && (yield* i.promise(() => f.record({
|
|
263
|
+
flag: t.key,
|
|
264
|
+
enabled: t.enabled,
|
|
265
|
+
previousEnabled: n,
|
|
266
|
+
actorId: typeof t.actor == "string" ? t.actor : null,
|
|
267
|
+
at: /* @__PURE__ */ new Date()
|
|
268
|
+
}))), y({
|
|
269
|
+
ok: !0,
|
|
270
|
+
flags: I(N.all())
|
|
271
|
+
});
|
|
272
|
+
})
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
method: "GET",
|
|
276
|
+
path: "/audit",
|
|
277
|
+
description: "The kill-switch flip audit trail, newest-first. `?flag=<key>` filters; `?limit=<n>` caps (postgres tier only).",
|
|
278
|
+
handler: (e) => i.gen(function* () {
|
|
279
|
+
if (!f) return y({
|
|
280
|
+
audit: [],
|
|
281
|
+
note: "audit trail requires store: \"postgres\""
|
|
282
|
+
});
|
|
283
|
+
let t = new URL(e.url, "http://local"), n = t.searchParams.get("flag"), r = t.searchParams.get("limit"), a = r != null && Number.isFinite(Number(r)) ? Number(r) : 100, o = yield* i.promise(() => f.list({
|
|
284
|
+
...n == null ? {} : { flag: n },
|
|
285
|
+
limit: a
|
|
286
|
+
}));
|
|
287
|
+
return y({ audit: o.map((e) => ({
|
|
288
|
+
flag: e.flag,
|
|
289
|
+
enabled: e.enabled,
|
|
290
|
+
previousEnabled: e.previousEnabled,
|
|
291
|
+
actorId: e.actorId,
|
|
292
|
+
at: e.at instanceof Date ? e.at.toISOString() : e.at
|
|
293
|
+
})) });
|
|
294
|
+
})
|
|
295
|
+
}
|
|
296
|
+
];
|
|
297
|
+
return a({
|
|
298
|
+
name: l,
|
|
299
|
+
description: "Feature flags — targeting, % rollout, kill-switch, declarative gating + client evaluation.",
|
|
300
|
+
permissions: [
|
|
301
|
+
...g ? [
|
|
302
|
+
"rpc:intercept:mutation",
|
|
303
|
+
"rpc:intercept:query",
|
|
304
|
+
"rpc:intercept:action"
|
|
305
|
+
] : [],
|
|
306
|
+
...u ? ["store:write", "store:changes:read"] : [],
|
|
307
|
+
"inspect:read",
|
|
308
|
+
"inspect:write"
|
|
309
|
+
],
|
|
310
|
+
routes: [_, v],
|
|
311
|
+
rpcClientDescriptors: n,
|
|
312
|
+
inspectEndpoints: x,
|
|
313
|
+
errorSchemas: [{
|
|
314
|
+
schema: r,
|
|
315
|
+
import: {
|
|
316
|
+
module: "@voltro/plugin-flags/errors",
|
|
317
|
+
name: "FlagDisabled"
|
|
318
|
+
}
|
|
319
|
+
}],
|
|
320
|
+
...g ? {
|
|
321
|
+
interceptMutation: h,
|
|
322
|
+
interceptQuery: h,
|
|
323
|
+
interceptAction: h
|
|
324
|
+
} : {},
|
|
325
|
+
...u ? { extendSchema: { tables: [A, j] } } : {},
|
|
326
|
+
...u ? { bindDataStore: (e) => {
|
|
327
|
+
d = R(e), f = B(e);
|
|
328
|
+
} } : {},
|
|
329
|
+
...u ? { onChangeEvent: (e) => e.table === "_voltro_feature_flags" ? i.tryPromise(() => p()) : i.void } : {},
|
|
330
|
+
onActivate: (e) => i.gen(function* () {
|
|
331
|
+
N.set(s), u && d && (yield* i.promise(p)), e.logger.info("feature flags active", {
|
|
332
|
+
count: Object.keys(s).length,
|
|
333
|
+
gated: Object.keys(c).length,
|
|
334
|
+
store: o.store ?? "memory"
|
|
335
|
+
});
|
|
336
|
+
}),
|
|
337
|
+
onDeactivate: () => i.sync(() => N.set({}))
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
//#endregion
|
|
341
|
+
export { r as FlagDisabled, I as describeFlags, E as evaluateAll, D as evaluateAllVariants, S as evaluateFlag, x as evaluateSchedule, T as evaluateVariant, N as flagRegistry, G as flagsPlugin, F as flipFlagEnabled, H as isFlagEnabled, M as mergeOverrides, U as requireFlag, w as resolveVariant, P as setFlagEnabled, m as toDefinition };
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PluginRpcClientDescriptor } from '@voltro/protocol';
|
|
2
|
+
import { QueryProcedureDescriptor } from '@voltro/protocol';
|
|
3
|
+
import { Schema } from 'effect';
|
|
4
|
+
|
|
5
|
+
export declare const evaluateDescriptor: QueryProcedureDescriptor<"flags.evaluate", Schema.Struct<{}>, Schema.Record$<typeof Schema.String, typeof Schema.Boolean>, typeof Schema.Never>;
|
|
6
|
+
|
|
7
|
+
export declare const evaluateVariantsDescriptor: QueryProcedureDescriptor<"flags.variants", Schema.Struct<{}>, Schema.Record$<typeof Schema.String, Schema.Struct<{
|
|
8
|
+
name: typeof Schema.String;
|
|
9
|
+
value: typeof Schema.Unknown;
|
|
10
|
+
enabled: typeof Schema.Boolean;
|
|
11
|
+
}>>, typeof Schema.Never>;
|
|
12
|
+
|
|
13
|
+
/** Declared for the codegen (`VoltroPlugin.rpcClientDescriptors`) so each tag is
|
|
14
|
+
* emitted into the generated client group. Kept in lockstep with the exports. */
|
|
15
|
+
export declare const flagsRpcClientImports: ReadonlyArray<PluginRpcClientDescriptor>;
|
|
16
|
+
|
|
17
|
+
export { }
|
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Schema as e } from "effect";
|
|
2
|
+
import { defineQuery as t } from "@voltro/protocol";
|
|
3
|
+
//#region src/rpc.ts
|
|
4
|
+
var n = t({
|
|
5
|
+
name: "flags.evaluate",
|
|
6
|
+
input: e.Struct({}),
|
|
7
|
+
output: e.Record({
|
|
8
|
+
key: e.String,
|
|
9
|
+
value: e.Boolean
|
|
10
|
+
})
|
|
11
|
+
}), r = e.Struct({
|
|
12
|
+
name: e.String,
|
|
13
|
+
value: e.Unknown,
|
|
14
|
+
enabled: e.Boolean
|
|
15
|
+
}), i = t({
|
|
16
|
+
name: "flags.variants",
|
|
17
|
+
input: e.Struct({}),
|
|
18
|
+
output: e.Record({
|
|
19
|
+
key: e.String,
|
|
20
|
+
value: r
|
|
21
|
+
})
|
|
22
|
+
}), a = [{
|
|
23
|
+
tag: "flags.evaluate",
|
|
24
|
+
kind: "query",
|
|
25
|
+
import: {
|
|
26
|
+
module: "@voltro/plugin-flags/rpc",
|
|
27
|
+
name: "evaluateDescriptor"
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
tag: "flags.variants",
|
|
31
|
+
kind: "query",
|
|
32
|
+
import: {
|
|
33
|
+
module: "@voltro/plugin-flags/rpc",
|
|
34
|
+
name: "evaluateVariantsDescriptor"
|
|
35
|
+
}
|
|
36
|
+
}];
|
|
37
|
+
//#endregion
|
|
38
|
+
export { n as evaluateDescriptor, i as evaluateVariantsDescriptor, a as flagsRpcClientImports };
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare type FlagSet = Readonly<Record<string, boolean>>;
|
|
2
|
+
|
|
3
|
+
export declare type FlagVariantSet = Readonly<Record<string, FlagVariantView>>;
|
|
4
|
+
|
|
5
|
+
/** A resolved multivariate variant on the wire: name + value + on/off. */
|
|
6
|
+
export declare interface FlagVariantView {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly value: unknown;
|
|
9
|
+
readonly enabled: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** `true` iff a single flag is on for the caller. */
|
|
13
|
+
export declare const useFlag: (key: string, apiName?: string) => boolean;
|
|
14
|
+
|
|
15
|
+
/** The caller's resolved flag set for an api (default `'app'`). Live: re-reads
|
|
16
|
+
* on reconnect. Returns `{}` until the first response. */
|
|
17
|
+
export declare const useFlags: (apiName?: string) => FlagSet;
|
|
18
|
+
|
|
19
|
+
/** The served variant for a single multivariate flag (or `undefined` until the
|
|
20
|
+
* first response / for an unknown key). Read `.value` for the variant payload. */
|
|
21
|
+
export declare const useVariant: (key: string, apiName?: string) => FlagVariantView | undefined;
|
|
22
|
+
|
|
23
|
+
/** The caller's resolved variant set for an api (default `'app'`). Live. Boolean
|
|
24
|
+
* flags surface a synthetic `{ name:'on'|'off', value: boolean, enabled }`. */
|
|
25
|
+
export declare const useVariants: (apiName?: string) => FlagVariantSet;
|
|
26
|
+
|
|
27
|
+
export { }
|
package/dist/web.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useSubscription as e } from "@voltro/client";
|
|
2
|
+
//#region src/web.ts
|
|
3
|
+
var t = (t = "app") => {
|
|
4
|
+
let { data: n } = e(t, "flags.evaluate", {});
|
|
5
|
+
return n ?? {};
|
|
6
|
+
}, n = (e, n = "app") => t(n)[e] === !0, r = (t = "app") => {
|
|
7
|
+
let { data: n } = e(t, "flags.variants", {});
|
|
8
|
+
return n ?? {};
|
|
9
|
+
}, i = (e, t = "app") => r(t)[e];
|
|
10
|
+
//#endregion
|
|
11
|
+
export { n as useFlag, t as useFlags, i as useVariant, r as useVariants };
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voltro/plugin-flags",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Feature flags — per-subject / per-tenant targeting, deterministic % rollouts, kill-switch. Gate mutations/queries/actions declaratively or guard in-handler; evaluate flags client-side for UI gating. Config-as-code (memory) or runtime-toggleable (postgres).",
|
|
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.d.ts",
|
|
28
|
+
"import": "./dist/web.js",
|
|
29
|
+
"default": "./dist/web.js"
|
|
30
|
+
},
|
|
31
|
+
"./errors": {
|
|
32
|
+
"types": "./dist/errors.d.ts",
|
|
33
|
+
"import": "./dist/errors.js",
|
|
34
|
+
"default": "./dist/errors.js"
|
|
35
|
+
},
|
|
36
|
+
"./rpc": {
|
|
37
|
+
"types": "./dist/rpc.d.ts",
|
|
38
|
+
"import": "./dist/rpc.js",
|
|
39
|
+
"default": "./dist/rpc.js"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.js",
|
|
43
|
+
"module": "./dist/index.js",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=24.0.0"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@voltro/client": "0.1.0",
|
|
51
|
+
"@voltro/database": "0.1.0",
|
|
52
|
+
"@voltro/logger": "0.1.0",
|
|
53
|
+
"@voltro/protocol": "0.1.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"effect": "^3.21.4"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
}
|
|
61
|
+
}
|