Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ scaffold.
## Where things stand

Phase 3 lands `@pegma/flags-launchdarkly`,
`@pegma/flags-aws-appconfig`, and `@pegma/flags-cloudflare-flagship`
beside the Phase 1 packages and `@pegma/flags-azure-appconfig` at
`0.1.0` (unpublished). Remaining vendor adapters (flagd) are still
later.
`@pegma/flags-aws-appconfig`, `@pegma/flags-cloudflare-flagship`, and
`@pegma/flags-flagd` beside the Phase 1 packages and
`@pegma/flags-azure-appconfig` at `0.1.0` (unpublished). Phase 3 vendor
adapters are complete.

Siblings: [spine](https://github.com/pegma-dev/spine),
[health](https://github.com/pegma-dev/health),
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,9 @@ const detail = await client.evaluate("checkoutEnabled", {
| `@pegma/flags-azure-appconfig` | Azure App Configuration provider |
| `@pegma/flags-aws-appconfig` | AWS AppConfig provider |
| `@pegma/flags-cloudflare-flagship` | Cloudflare Flagship provider |
| `@pegma/flags-flagd` | flagd / OpenFeature provider |
| `@pegma/flags-launchdarkly` | LaunchDarkly provider |

Remaining vendor adapters (flagd) are named in
[the plan](docs/PROJECT_PLAN.md) and stay later.

## Development

Requires Node.js 22 or 24.
Expand Down
35 changes: 19 additions & 16 deletions docs/PROJECT_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

## Status

**Stage:** Phase 3 LaunchDarkly, AWS AppConfig, and Cloudflare Flagship
adapters implemented in-tree; unpublished. Public API unstable (`0.x`).
**Stage:** Phase 3 vendor adapters implemented in-tree; unpublished.
Public API unstable (`0.x`).

**First named consumers:** RetireGolden.org (Azure App Configuration).
Remaining vendor adapters (flagd) are still later.
Phase 3 vendor adapters (LaunchDarkly, AWS AppConfig, Cloudflare
Flagship, flagd) are complete.

**License:** MIT

Expand Down Expand Up @@ -104,7 +105,6 @@ package here would invite the wrong extractions.

- Flag authoring, admin UI, or a Pegma-owned flag store.
- A custom expression / rule language or AppConfig document evaluator.
- flagd adapter packages in this phase.
- Metrics, experiment assignment, or percentage math in the core.

## Package architecture
Expand All @@ -118,13 +118,14 @@ package here would invite the wrong extractions.
| `@pegma/flags-azure-appconfig` | Azure App Configuration adapter | 2 |
| `@pegma/flags-aws-appconfig` | AWS AppConfig adapter | 3 |
| `@pegma/flags-cloudflare-flagship` | Cloudflare Flagship adapter | 3 |
| `@pegma/flags-flagd` | flagd / OpenFeature adapter | later |
| `@pegma/flags-flagd` | flagd / OpenFeature adapter | 3 |

Dependencies: `@pegma/spine` pinned exactly. `@pegma/flags-static`,
`@pegma/flags-azure-appconfig`, `@pegma/flags-aws-appconfig`,
`@pegma/flags-cloudflare-flagship`, and `@pegma/flags-launchdarkly`
depend only on `@pegma/flags-contracts` (no vendor SDK). Adapters pin
contracts (and spine, if they need `Logger` / `Clock`) exactly.
`@pegma/flags-cloudflare-flagship`, `@pegma/flags-launchdarkly`, and
`@pegma/flags-flagd` depend only on `@pegma/flags-contracts` (no vendor
SDK). Adapters pin contracts (and spine, if they need `Logger` / `Clock`)
exactly.

## Delivery phases

Expand All @@ -146,14 +147,16 @@ still carries those rules. Do not pre-build the other vendors.

### Phase 3 — remaining adapters

`@pegma/flags-launchdarkly`, `@pegma/flags-aws-appconfig`, and
`@pegma/flags-cloudflare-flagship` are in-tree. Each translates an
injected reader result and must pass the Phase 1 conformance suite.
None import a vendor SDK or evaluate targeting rules. The AWS adapter
maps an already-evaluated value or an unconditional feature-flag
setting and rejects an enabled document that still carries
multi-variant rules. The Flagship adapter translates an already-evaluated
`*Details` result. flagd remains later as its own package.
`@pegma/flags-launchdarkly`, `@pegma/flags-aws-appconfig`,
`@pegma/flags-cloudflare-flagship`, and `@pegma/flags-flagd` are
in-tree. Each translates an injected reader result and must pass the
Phase 1 conformance suite. None import a vendor SDK or evaluate
targeting rules. The AWS adapter maps an already-evaluated value or an
unconditional feature-flag setting and rejects an enabled document that
still carries multi-variant rules. The Flagship adapter translates an
already-evaluated `*Details` result. The flagd adapter translates an
already-evaluated OpenFeature detail. Phase 3 vendor adapters are
complete.

### Phase 4 — publish

Expand Down
5 changes: 3 additions & 2 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

`@pegma/flags-contracts`, `@pegma/flags-core`, `@pegma/flags-static`,
`@pegma/flags-azure-appconfig`, `@pegma/flags-aws-appconfig`,
`@pegma/flags-cloudflare-flagship`, and `@pegma/flags-launchdarkly`
`@pegma/flags-cloudflare-flagship`, `@pegma/flags-flagd`, and
`@pegma/flags-launchdarkly`
publish
only from a stable GitHub release. Merging a pull request never
publishes, and the workflow has no manual-dispatch or npm-token
Expand All @@ -16,7 +17,7 @@ Before the first release through this workflow:
- configure `@pegma/flags-contracts`, `@pegma/flags-core`,
`@pegma/flags-static`, `@pegma/flags-azure-appconfig`,
`@pegma/flags-aws-appconfig`, `@pegma/flags-cloudflare-flagship`,
and `@pegma/flags-launchdarkly` on npm with
`@pegma/flags-flagd`, and `@pegma/flags-launchdarkly` on npm with
the GitHub Actions trusted publisher
`pegma-dev/flags-core`, workflow `publish.yml`, environment
`npm-publish`, and allowed action `npm publish`;
Expand Down
21 changes: 21 additions & 0 deletions packages/flags-flagd/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 RetireGolden, LLC

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
83 changes: 83 additions & 0 deletions packages/flags-flagd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# `@pegma/flags-flagd`

flagd / OpenFeature `FlagProvider` for Pegma hosts.

> [!IMPORTANT]
> Pegma is in early `0.x` development. This package's public API is unstable.

The host constructs and injects a flagd / OpenFeature reader. This package
never imports the OpenFeature SDK or a flagd provider, never owns a client
singleton, and does not evaluate targeting rules or percentage rollouts. It
translates an already-evaluated OpenFeature detail into a `FlagResolution`.

```ts
import {
createFlagdFlagProvider,
flagdEvaluationContext,
} from "@pegma/flags-flagd";
import { createFlagsClient, declareFlags, flag } from "@pegma/flags-core";
import type { Logger } from "@pegma/spine";

const schema = declareFlags({
checkoutEnabled: flag.boolean({ defaultValue: false }),
});

const logger: Logger = {
log(level, message, fields) {
console.log(level, message, fields);
},
};

const provider = createFlagdFlagProvider({
reader: {
async getDetails({ flagKey, context, defaultValue, kind }) {
const evaluationContext = flagdEvaluationContext(context);
switch (kind) {
case "boolean":
return client.getBooleanDetails(
flagKey,
defaultValue,
evaluationContext,
);
case "string":
return client.getStringDetails(
flagKey,
defaultValue,
evaluationContext,
);
case "number":
return client.getNumberDetails(
flagKey,
defaultValue,
evaluationContext,
);
case "json":
return client.getObjectDetails(
flagKey,
defaultValue,
evaluationContext,
);
}
},
close() {
return client.close?.();
},
},
});

const flags = createFlagsClient({ schema, logger, provider });
```

`client` is the host's OpenFeature client configured with a flagd
provider. Import `flagdEvaluationContext` when the host wants the
documented OpenFeature context (`targetingKey` plus attributes). Hosts
that need a different context shape can map `EvaluationContext`
themselves inside the reader.

A missing flag (`undefined` from the reader, or OpenFeature
`FLAG_NOT_FOUND`) is `DEFAULT_FALLBACK`. `DISABLED` is `DISABLED`.
`STALE` is `STALE_CACHE` so the flags client records the stale reason
and emits fallback telemetry. `TARGETING_MATCH`, `SPLIT`, `DEFAULT`,
`STATIC`, and `CACHED` are `TARGETING_MATCH` — flagd already evaluated
those rules. Other OpenFeature `ERROR` codes propagate so the flags
client can record `ERROR`.
39 changes: 39 additions & 0 deletions packages/flags-flagd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@pegma/flags-flagd",
"version": "0.1.0",
"description": "flagd / OpenFeature FlagProvider for Pegma hosts.",
"license": "MIT",
"type": "module",
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"files": [
"dist/**/*.d.ts",
"dist/**/*.d.ts.map",
"dist/**/*.js",
"dist/**/*.js.map"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"engines": {
"node": ">=22"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pegma-dev/flags-core.git",
"directory": "packages/flags-flagd"
},
"dependencies": {
"@pegma/flags-contracts": "0.1.0"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"check": "tsc -p tsconfig.json --noEmit",
"prepack": "pnpm run build"
}
}
Loading
Loading