@lunora/flags 0.0.1 → 1.0.0-alpha.1
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/LICENSE.md +105 -0
- package/README.md +80 -28
- package/__assets__/package-og.svg +14 -0
- package/dist/index.d.mts +56 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.mjs +2 -0
- package/dist/packem_shared/createFlags-BQ8eiIlo.mjs +94 -0
- package/dist/packem_shared/defineFlags-DAIO8cWQ.mjs +15 -0
- package/dist/packem_shared/types.d-BWygZiSc.d.mts +85 -0
- package/dist/packem_shared/types.d-BWygZiSc.d.ts +85 -0
- package/dist/providers/env.d.mts +43 -0
- package/dist/providers/env.d.ts +43 -0
- package/dist/providers/env.mjs +75 -0
- package/dist/providers/flagship.d.mts +62 -0
- package/dist/providers/flagship.d.ts +62 -0
- package/dist/providers/flagship.mjs +20 -0
- package/dist/providers/memory.d.mts +37 -0
- package/dist/providers/memory.d.ts +37 -0
- package/dist/providers/memory.mjs +16 -0
- package/dist/web.d.mts +1 -0
- package/dist/web.d.ts +1 -0
- package/dist/web.mjs +1 -0
- package/package.json +77 -7
package/LICENSE.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 anolilab and contributors
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or service
|
|
34
|
+
that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software that
|
|
39
|
+
exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee using
|
|
52
|
+
the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to the
|
|
59
|
+
infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
|
|
79
|
+
IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following will
|
|
93
|
+
apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,45 +1,97 @@
|
|
|
1
1
|
# @lunora/flags
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- START_PACKAGE_OG_IMAGE_PLACEHOLDER -->
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
<a href="https://www.anolilab.com/open-source" align="center">
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<img src="__assets__/package-og.svg" alt="flags" />
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
</a>
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
1. Configure OIDC trusted publishing for the package name `@lunora/flags`
|
|
13
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
11
|
+
<h3 align="center">OpenFeature-based feature flags for Lunora — ctx.flags, useFlag, and a first-class Cloudflare Flagship provider with any OpenFeature provider pluggable</h3>
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
<!-- END_PACKAGE_OG_IMAGE_PLACEHOLDER -->
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
OpenFeature-based feature flags for [Lunora](https://lunora.sh). Configure one
|
|
16
|
+
OpenFeature provider in `lunora/flags.ts` and Lunora wires `ctx.flags` onto every
|
|
17
|
+
handler — Cloudflare [Flagship](https://github.com/cloudflare/flagship) is the
|
|
18
|
+
first-class default, but any OpenFeature provider plugs in unchanged.
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Install
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @lunora/flags @openfeature/server-sdk
|
|
24
|
+
# Flagship provider (default):
|
|
25
|
+
pnpm add @cloudflare/flagship
|
|
26
|
+
```
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
2. Configure the trusted publisher (e.g., GitHub Actions)
|
|
26
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
27
|
-
4. Use the configured workflow to publish your actual package
|
|
28
|
+
## Configure
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
```ts
|
|
31
|
+
// lunora/flags.ts
|
|
32
|
+
import { defineFlags } from "@lunora/flags";
|
|
33
|
+
import { flagshipProvider } from "@lunora/flags/providers/flagship";
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
export default defineFlags({
|
|
36
|
+
provider: flagshipProvider({ binding: "FLAGS" }), // Workers binding mode — no HTTP, no token
|
|
37
|
+
identify: (auth) => auth.userId ?? undefined, // default targetingKey
|
|
38
|
+
});
|
|
39
|
+
```
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
Binding mode reads `env.FLAGS`; configure it in `wrangler.jsonc`:
|
|
38
42
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
```jsonc
|
|
44
|
+
{ "flagship": [{ "binding": "FLAGS", "app_id": "<your-app-id>" }] }
|
|
45
|
+
```
|
|
42
46
|
|
|
43
|
-
|
|
47
|
+
HTTP mode (non-binding environments): `flagshipProvider({ appId, accountId, authToken })`.
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
Any OpenFeature provider works in place of Flagship:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
export default defineFlags({ provider: (env) => new SomeOpenFeatureProvider(env.SOME_KEY) });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Two zero-dependency providers ship in the box for tests, local defaults, and
|
|
56
|
+
binding-driven flags:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { memoryProvider } from "@lunora/flags/providers/memory";
|
|
60
|
+
import { envProvider } from "@lunora/flags/providers/env";
|
|
61
|
+
|
|
62
|
+
// Static key → value map (booleans, strings, numbers, JSON objects):
|
|
63
|
+
export default defineFlags({ provider: memoryProvider({ "dark-mode": true, "page-size": 25 }) });
|
|
64
|
+
|
|
65
|
+
// Read from the Worker env — `dark-mode` → `env.FLAG_DARK_MODE` (override with `prefix` / `name`):
|
|
66
|
+
export default defineFlags({ provider: envProvider() });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Evaluate
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
export const listPosts = query(async (ctx) => {
|
|
73
|
+
if (await ctx.flags.boolean("new-ranking", false)) {
|
|
74
|
+
/* ... */
|
|
75
|
+
}
|
|
76
|
+
const hero = await ctx.flags.string("homepage-hero", "control", { plan: "premium" });
|
|
77
|
+
const details = await ctx.flags.details.boolean("new-ranking", false); // value + reason + variant
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`ctx.flags` never throws: a missing flag, type mismatch, or provider error resolves
|
|
82
|
+
with the `defaultValue`. The default `targetingKey` (from `identify`) is merged under
|
|
83
|
+
any per-call context, and identical evaluations within one request are memoized.
|
|
84
|
+
|
|
85
|
+
## Exports
|
|
86
|
+
|
|
87
|
+
| Export | Contents | Peer dependency |
|
|
88
|
+
| ---------------------------------- | ----------------------------------------------- | ---------------------------------------------- |
|
|
89
|
+
| `@lunora/flags` | `defineFlags`, `createFlags`, types | `@openfeature/server-sdk` |
|
|
90
|
+
| `@lunora/flags/providers/flagship` | `flagshipProvider` (Cloudflare Flagship) | `@cloudflare/flagship` |
|
|
91
|
+
| `@lunora/flags/providers/memory` | `memoryProvider` (static `key → value` map) | — (zero extra deps) |
|
|
92
|
+
| `@lunora/flags/providers/env` | `envProvider` (reads flags from the Worker env) | — (zero extra deps) |
|
|
93
|
+
| `@lunora/flags/web` | `FlagshipClientProvider` (browser escape hatch) | `@openfeature/web-sdk`, `@cloudflare/flagship` |
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
[FSL-1.1-Apache-2.0](./LICENSE.md)
|