@flagdeck/openfeature 0.0.0-stage → 1.0.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 +34 -0
- package/LICENSE +21 -0
- package/README.md +107 -2
- package/dist/chunk-5EDHN2AB.mjs +94 -0
- package/dist/chunk-5EDHN2AB.mjs.map +1 -0
- package/dist/index.d.mts +104 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +93 -0
- package/dist/index.mjs.map +1 -0
- package/dist/web.d.mts +46 -0
- package/dist/web.d.ts +46 -0
- package/dist/web.js +236 -0
- package/dist/web.js.map +1 -0
- package/dist/web.mjs +137 -0
- package/dist/web.mjs.map +1 -0
- package/package.json +68 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- b4295fc: Graduate the published packages to 1.0.0 and commit to a stable, semver-versioned public API. The SDK contract is add-only, so 1.0.0 is a stability declaration, not a set of breaking changes: existing code keeps working. This replaces the 0.0.x versions that read as pre-release.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [b4295fc]
|
|
12
|
+
- Updated dependencies [6e81c03]
|
|
13
|
+
- @flagdeck/js@1.0.0
|
|
14
|
+
|
|
15
|
+
All notable changes to `@flagdeck/openfeature` are documented here. This project
|
|
16
|
+
adheres to [Semantic Versioning](https://semver.org/). Per the package policy,
|
|
17
|
+
only additive changes ship in a minor release; a removal or rename is a major
|
|
18
|
+
release.
|
|
19
|
+
|
|
20
|
+
## [Unreleased]
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Context converter: `toFlagdeckContext` and `fromFlagdeckResult`, the pure
|
|
25
|
+
translation layer between OpenFeature and Flagdeck context/result shapes.
|
|
26
|
+
- `FlagdeckWebProvider` (via the `@flagdeck/openfeature/web` subpath): client-side
|
|
27
|
+
provider over `@openfeature/web-sdk`, reusing the same context converter;
|
|
28
|
+
synchronous resolvers backed by a lazy background fetch that emits
|
|
29
|
+
`ConfigurationChanged`. `@openfeature/server-sdk` and `@openfeature/web-sdk`
|
|
30
|
+
are optional peers (install only the one you use).
|
|
31
|
+
- `FlagdeckProvider`: server-side OpenFeature provider over `@flagdeck/js` with
|
|
32
|
+
the four typed resolvers, reason/error mapping, runtime type checking
|
|
33
|
+
(`TYPE_MISMATCH`), and no-throw semantics. Accepts either SDK options or a
|
|
34
|
+
pre-built client.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Flagdeck
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Flagdeck OpenFeature Provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A server-side [OpenFeature](https://openfeature.dev) provider for
|
|
4
|
+
[Flagdeck](https://flagdeck.com). Teams already standardized on OpenFeature can
|
|
5
|
+
use Flagdeck by swapping a provider instead of rewriting evaluation calls. It
|
|
6
|
+
wraps the [`@flagdeck/js`](https://www.npmjs.com/package/@flagdeck/js) client and
|
|
7
|
+
translates between OpenFeature's context/result shapes and Flagdeck's native
|
|
8
|
+
ones. The native evaluation model and the `/sdk/v1/*` contract are unchanged —
|
|
9
|
+
the whole job lives in the adapter.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @flagdeck/openfeature @flagdeck/js @openfeature/server-sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`@openfeature/server-sdk` is a peer dependency; `@flagdeck/js` is the runtime
|
|
18
|
+
client the provider wraps.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { OpenFeature } from '@openfeature/server-sdk';
|
|
24
|
+
import { FlagdeckProvider } from '@flagdeck/openfeature';
|
|
25
|
+
|
|
26
|
+
// The SDK key is scoped to one project + environment. Read it from the env.
|
|
27
|
+
await OpenFeature.setProviderAndWait(
|
|
28
|
+
new FlagdeckProvider({ apiKey: process.env.FLAGDECK_SDK_KEY! })
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const client = OpenFeature.getClient();
|
|
32
|
+
|
|
33
|
+
const showNewUi = await client.getBooleanValue('new-ui', false, {
|
|
34
|
+
targetingKey: user.id, // -> Flagdeck userId (bucketing identity)
|
|
35
|
+
email: user.email, // -> attributes.email
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
You can also hand the provider an already-configured `@flagdeck/js` client
|
|
40
|
+
instead of options:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { Flagdeck } from '@flagdeck/js';
|
|
44
|
+
new FlagdeckProvider(new Flagdeck({ apiKey: process.env.FLAGDECK_SDK_KEY! }));
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Browser (web) provider
|
|
48
|
+
|
|
49
|
+
For client-side apps, use the web provider over `@openfeature/web-sdk`:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install @flagdeck/openfeature @flagdeck/js @openfeature/web-sdk
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { OpenFeature } from '@openfeature/web-sdk';
|
|
57
|
+
import { FlagdeckWebProvider } from '@flagdeck/openfeature/web';
|
|
58
|
+
|
|
59
|
+
await OpenFeature.setContext({ targetingKey: user.id });
|
|
60
|
+
await OpenFeature.setProviderAndWait(
|
|
61
|
+
new FlagdeckWebProvider({
|
|
62
|
+
apiKey: import.meta.env.VITE_FLAGDECK_SDK_KEY,
|
|
63
|
+
realTimeUpdates: true,
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const client = OpenFeature.getClient();
|
|
68
|
+
const showNewUi = client.getBooleanValue('new-ui', false);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The web paradigm resolves synchronously against cached state. A flag that is not
|
|
72
|
+
loaded yet returns your default; the provider fetches it in the background and
|
|
73
|
+
emits `ConfigurationChanged`, so the client re-evaluates and the real value is
|
|
74
|
+
returned. With `realTimeUpdates: true`, a flag change pushed over SSE triggers
|
|
75
|
+
the same re-evaluation. A runnable app lives in `examples/openfeature-web`. The
|
|
76
|
+
context and result mapping below is shared by both providers.
|
|
77
|
+
|
|
78
|
+
## Context mapping
|
|
79
|
+
|
|
80
|
+
OpenFeature's `EvaluationContext` is a special `targetingKey` plus an open map of
|
|
81
|
+
attributes. Flagdeck's context is `{ userId?, sessionId?, attributes? }`, and the
|
|
82
|
+
engine resolves `userId`/`sessionId` as top-level identities and everything else
|
|
83
|
+
as a dot-path into `attributes`.
|
|
84
|
+
|
|
85
|
+
| OpenFeature context | Flagdeck context | Notes |
|
|
86
|
+
| ---------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------ |
|
|
87
|
+
| `targetingKey` | `userId` | OpenFeature's bucketing identity is Flagdeck's primary identity, so rollout/variant stickiness lines up 1:1. |
|
|
88
|
+
| `sessionId` (string) | `sessionId` | Promoted to the native slot so anonymous stickiness (`userId \|\| sessionId`) keeps working. |
|
|
89
|
+
| any other `key: value` | `attributes[key]` | Scalars and nested objects pass through unchanged; the engine reads dot-paths like `account.id`. |
|
|
90
|
+
|
|
91
|
+
Result mapping (Flagdeck → OpenFeature `ResolutionDetails`):
|
|
92
|
+
|
|
93
|
+
| Flagdeck result source | OpenFeature reason |
|
|
94
|
+
| ------------------------------------------ | --------------------- |
|
|
95
|
+
| `*_targeting` | `TARGETING_MATCH` |
|
|
96
|
+
| `*_rollout`, `variant`, `variant_fallback` | `SPLIT` |
|
|
97
|
+
| `default` | `DEFAULT` |
|
|
98
|
+
| `offline` | `CACHED` |
|
|
99
|
+
| error (flag missing, invalid context, …) | `ERROR` + `errorCode` |
|
|
100
|
+
|
|
101
|
+
The provider never throws to the caller. On an error it returns the caller's
|
|
102
|
+
default value with the mapped `errorCode` (`FLAG_NOT_FOUND`, `INVALID_CONTEXT`,
|
|
103
|
+
or `GENERAL`), and on a value whose runtime type does not match the requested
|
|
104
|
+
resolver it returns the default with `TYPE_MISMATCH` rather than coercing.
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
MIT — see [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/context-converter.ts
|
|
2
|
+
var Reason = {
|
|
3
|
+
TARGETING_MATCH: "TARGETING_MATCH",
|
|
4
|
+
SPLIT: "SPLIT",
|
|
5
|
+
DEFAULT: "DEFAULT",
|
|
6
|
+
CACHED: "CACHED",
|
|
7
|
+
ERROR: "ERROR"
|
|
8
|
+
};
|
|
9
|
+
var OpenFeatureErrorCode = {
|
|
10
|
+
FLAG_NOT_FOUND: "FLAG_NOT_FOUND",
|
|
11
|
+
TYPE_MISMATCH: "TYPE_MISMATCH",
|
|
12
|
+
INVALID_CONTEXT: "INVALID_CONTEXT",
|
|
13
|
+
GENERAL: "GENERAL"
|
|
14
|
+
};
|
|
15
|
+
var TARGETING_KEY = "targetingKey";
|
|
16
|
+
var SESSION_ID_KEY = "sessionId";
|
|
17
|
+
var SOURCE_TO_REASON = {
|
|
18
|
+
user_targeting: Reason.TARGETING_MATCH,
|
|
19
|
+
environment_targeting: Reason.TARGETING_MATCH,
|
|
20
|
+
global_targeting: Reason.TARGETING_MATCH,
|
|
21
|
+
environment_rollout: Reason.SPLIT,
|
|
22
|
+
global_rollout: Reason.SPLIT,
|
|
23
|
+
variant: Reason.SPLIT,
|
|
24
|
+
variant_fallback: Reason.SPLIT,
|
|
25
|
+
default: Reason.DEFAULT,
|
|
26
|
+
offline: Reason.CACHED,
|
|
27
|
+
error: Reason.ERROR
|
|
28
|
+
};
|
|
29
|
+
var ERROR_CODE_TO_OPENFEATURE = {
|
|
30
|
+
FLAG_NOT_FOUND: OpenFeatureErrorCode.FLAG_NOT_FOUND,
|
|
31
|
+
INVALID_CONTEXT: OpenFeatureErrorCode.INVALID_CONTEXT
|
|
32
|
+
};
|
|
33
|
+
function mapErrorCode(code) {
|
|
34
|
+
if (!code) return OpenFeatureErrorCode.GENERAL;
|
|
35
|
+
return ERROR_CODE_TO_OPENFEATURE[code] ?? OpenFeatureErrorCode.GENERAL;
|
|
36
|
+
}
|
|
37
|
+
function toFlagdeckContext(context) {
|
|
38
|
+
const result = {};
|
|
39
|
+
if (!context) return result;
|
|
40
|
+
const attributes = {};
|
|
41
|
+
for (const [key, value] of Object.entries(context)) {
|
|
42
|
+
if (key === TARGETING_KEY) continue;
|
|
43
|
+
if (key === SESSION_ID_KEY && typeof value === "string") {
|
|
44
|
+
result.sessionId = value;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (value !== void 0) attributes[key] = value;
|
|
48
|
+
}
|
|
49
|
+
if (typeof context.targetingKey === "string" && context.targetingKey) {
|
|
50
|
+
result.userId = context.targetingKey;
|
|
51
|
+
}
|
|
52
|
+
if (Object.keys(attributes).length > 0) {
|
|
53
|
+
result.attributes = attributes;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
function fromFlagdeckResult(result, defaultValue) {
|
|
58
|
+
if (result.source === "error" || result.error) {
|
|
59
|
+
const details2 = {
|
|
60
|
+
value: defaultValue,
|
|
61
|
+
reason: Reason.ERROR,
|
|
62
|
+
errorCode: mapErrorCode(result.error?.code)
|
|
63
|
+
};
|
|
64
|
+
if (result.error?.message) details2.errorMessage = result.error.message;
|
|
65
|
+
return details2;
|
|
66
|
+
}
|
|
67
|
+
const details = {
|
|
68
|
+
value: result.value,
|
|
69
|
+
reason: SOURCE_TO_REASON[result.source] ?? Reason.DEFAULT
|
|
70
|
+
};
|
|
71
|
+
if (result.variant?.name) details.variant = result.variant.name;
|
|
72
|
+
return details;
|
|
73
|
+
}
|
|
74
|
+
function matchesType(value, kind) {
|
|
75
|
+
switch (kind) {
|
|
76
|
+
case "boolean":
|
|
77
|
+
return typeof value === "boolean";
|
|
78
|
+
case "string":
|
|
79
|
+
return typeof value === "string";
|
|
80
|
+
case "number":
|
|
81
|
+
return typeof value === "number" && !Number.isNaN(value);
|
|
82
|
+
case "object":
|
|
83
|
+
return typeof value === "object" && value !== null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
Reason,
|
|
89
|
+
OpenFeatureErrorCode,
|
|
90
|
+
toFlagdeckContext,
|
|
91
|
+
fromFlagdeckResult,
|
|
92
|
+
matchesType
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=chunk-5EDHN2AB.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context-converter.ts"],"sourcesContent":["import type {\n EvaluationContext as FlagdeckContext,\n EvaluationResult,\n EvaluationSource,\n EvaluationErrorCode,\n} from '@flagdeck/js';\n\n/**\n * Minimal structural shape of an OpenFeature `EvaluationContext`. The real\n * `EvaluationContext` from `@openfeature/server-sdk` is assignable to this, so\n * the provider passes its context straight through. Kept local so the converter\n * stays a pure unit that can be type-checked and tested without the OpenFeature\n * SDK installed.\n */\nexport interface OpenFeatureContextLike {\n targetingKey?: string;\n [key: string]: unknown;\n}\n\n/**\n * OpenFeature standard resolution reasons we emit. String values mirror\n * `StandardResolutionReasons` in `@openfeature/server-sdk`.\n */\nexport const Reason = {\n TARGETING_MATCH: 'TARGETING_MATCH',\n SPLIT: 'SPLIT',\n DEFAULT: 'DEFAULT',\n CACHED: 'CACHED',\n ERROR: 'ERROR',\n} as const;\nexport type ResolutionReason = (typeof Reason)[keyof typeof Reason];\n\n/**\n * OpenFeature error codes we emit. String values mirror `ErrorCode` in\n * `@openfeature/server-sdk`.\n */\nexport const OpenFeatureErrorCode = {\n FLAG_NOT_FOUND: 'FLAG_NOT_FOUND',\n TYPE_MISMATCH: 'TYPE_MISMATCH',\n INVALID_CONTEXT: 'INVALID_CONTEXT',\n GENERAL: 'GENERAL',\n} as const;\nexport type OpenFeatureErrorCodeValue =\n (typeof OpenFeatureErrorCode)[keyof typeof OpenFeatureErrorCode];\n\n/**\n * Structural mirror of OpenFeature's `ResolutionDetails<T>`. Values of this\n * shape are assignable to the real `ResolutionDetails<T>`, so the provider's\n * resolvers can return them directly.\n */\nexport interface ResolutionDetailsLike<T> {\n value: T;\n variant?: string;\n reason?: string;\n errorCode?: OpenFeatureErrorCodeValue;\n errorMessage?: string;\n}\n\nconst TARGETING_KEY = 'targetingKey';\nconst SESSION_ID_KEY = 'sessionId';\n\n/**\n * Flagdeck evaluation source -> OpenFeature resolution reason.\n *\n * - *_targeting -> TARGETING_MATCH (an explicit rule/segment/user match)\n * - *_rollout, variant, variant_fallback -> SPLIT (percentage bucketing)\n * - default -> DEFAULT\n * - offline -> CACHED (served from the SDK's offline store)\n * - error -> ERROR\n */\nconst SOURCE_TO_REASON: Record<EvaluationSource, ResolutionReason> = {\n user_targeting: Reason.TARGETING_MATCH,\n environment_targeting: Reason.TARGETING_MATCH,\n global_targeting: Reason.TARGETING_MATCH,\n environment_rollout: Reason.SPLIT,\n global_rollout: Reason.SPLIT,\n variant: Reason.SPLIT,\n variant_fallback: Reason.SPLIT,\n default: Reason.DEFAULT,\n offline: Reason.CACHED,\n error: Reason.ERROR,\n};\n\n/** Flagdeck error code -> OpenFeature error code; unmapped codes fall to GENERAL. */\nconst ERROR_CODE_TO_OPENFEATURE: Partial<\n Record<EvaluationErrorCode, OpenFeatureErrorCodeValue>\n> = {\n FLAG_NOT_FOUND: OpenFeatureErrorCode.FLAG_NOT_FOUND,\n INVALID_CONTEXT: OpenFeatureErrorCode.INVALID_CONTEXT,\n};\n\nfunction mapErrorCode(code?: EvaluationErrorCode): OpenFeatureErrorCodeValue {\n if (!code) return OpenFeatureErrorCode.GENERAL;\n return ERROR_CODE_TO_OPENFEATURE[code] ?? OpenFeatureErrorCode.GENERAL;\n}\n\n/**\n * Translate an OpenFeature `EvaluationContext` into Flagdeck's native context.\n *\n * - `targetingKey` -> `userId`. OpenFeature's bucketing identity is Flagdeck's\n * primary identity, so rollout and variant stickiness line up 1:1.\n * - a string `sessionId` attribute -> native `sessionId`. The engine buckets on\n * `userId || sessionId`, so promoting it preserves anonymous stickiness; a\n * non-string `sessionId` is left in `attributes` rather than dropped.\n * - every other entry -> `attributes[key]`, unchanged. Scalars and nested\n * objects pass through; the engine resolves dot-paths such as `account.id`.\n *\n * An empty or missing context yields an empty Flagdeck context.\n */\nexport function toFlagdeckContext(\n context?: OpenFeatureContextLike | null\n): FlagdeckContext {\n const result: FlagdeckContext = {};\n if (!context) return result;\n\n const attributes: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(context)) {\n if (key === TARGETING_KEY) continue; // mapped to userId below\n if (key === SESSION_ID_KEY && typeof value === 'string') {\n result.sessionId = value;\n continue;\n }\n if (value !== undefined) attributes[key] = value;\n }\n\n if (typeof context.targetingKey === 'string' && context.targetingKey) {\n result.userId = context.targetingKey;\n }\n\n if (Object.keys(attributes).length > 0) {\n result.attributes = attributes as FlagdeckContext['attributes'];\n }\n\n return result;\n}\n\n/**\n * Translate a Flagdeck `EvaluationResult` into an OpenFeature\n * `ResolutionDetails`. On an error result the caller's `defaultValue` is\n * returned with the mapped error code and `reason: ERROR` — OpenFeature never\n * throws to the caller.\n *\n * Runtime type checking (OpenFeature's `TYPE_MISMATCH`) is applied by the\n * provider's typed resolvers, not here; this function maps reason, variant and\n * error only.\n */\nexport function fromFlagdeckResult<T>(\n result: EvaluationResult,\n defaultValue: T\n): ResolutionDetailsLike<T> {\n if (result.source === 'error' || result.error) {\n const details: ResolutionDetailsLike<T> = {\n value: defaultValue,\n reason: Reason.ERROR,\n errorCode: mapErrorCode(result.error?.code),\n };\n if (result.error?.message) details.errorMessage = result.error.message;\n return details;\n }\n\n const details: ResolutionDetailsLike<T> = {\n value: result.value as T,\n reason: SOURCE_TO_REASON[result.source] ?? Reason.DEFAULT,\n };\n if (result.variant?.name) details.variant = result.variant.name;\n return details;\n}\n\n/** The value kinds OpenFeature's typed resolvers check against. */\nexport type ValueKind = 'boolean' | 'string' | 'number' | 'object';\n\n/**\n * Runtime type check both providers apply before returning a resolved value:\n * OpenFeature returns the caller default with TYPE_MISMATCH rather than coercing.\n */\nexport function matchesType(value: unknown, kind: ValueKind): boolean {\n switch (kind) {\n case 'boolean':\n return typeof value === 'boolean';\n case 'string':\n return typeof value === 'string';\n case 'number':\n return typeof value === 'number' && !Number.isNaN(value);\n case 'object':\n return typeof value === 'object' && value !== null;\n }\n}\n"],"mappings":";AAuBO,IAAM,SAAS;AAAA,EACpB,iBAAiB;AAAA,EACjB,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,OAAO;AACT;AAOO,IAAM,uBAAuB;AAAA,EAClC,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,iBAAiB;AAAA,EACjB,SAAS;AACX;AAiBA,IAAM,gBAAgB;AACtB,IAAM,iBAAiB;AAWvB,IAAM,mBAA+D;AAAA,EACnE,gBAAgB,OAAO;AAAA,EACvB,uBAAuB,OAAO;AAAA,EAC9B,kBAAkB,OAAO;AAAA,EACzB,qBAAqB,OAAO;AAAA,EAC5B,gBAAgB,OAAO;AAAA,EACvB,SAAS,OAAO;AAAA,EAChB,kBAAkB,OAAO;AAAA,EACzB,SAAS,OAAO;AAAA,EAChB,SAAS,OAAO;AAAA,EAChB,OAAO,OAAO;AAChB;AAGA,IAAM,4BAEF;AAAA,EACF,gBAAgB,qBAAqB;AAAA,EACrC,iBAAiB,qBAAqB;AACxC;AAEA,SAAS,aAAa,MAAuD;AAC3E,MAAI,CAAC,KAAM,QAAO,qBAAqB;AACvC,SAAO,0BAA0B,IAAI,KAAK,qBAAqB;AACjE;AAeO,SAAS,kBACd,SACiB;AACjB,QAAM,SAA0B,CAAC;AACjC,MAAI,CAAC,QAAS,QAAO;AAErB,QAAM,aAAsC,CAAC;AAE7C,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,QAAI,QAAQ,cAAe;AAC3B,QAAI,QAAQ,kBAAkB,OAAO,UAAU,UAAU;AACvD,aAAO,YAAY;AACnB;AAAA,IACF;AACA,QAAI,UAAU,OAAW,YAAW,GAAG,IAAI;AAAA,EAC7C;AAEA,MAAI,OAAO,QAAQ,iBAAiB,YAAY,QAAQ,cAAc;AACpE,WAAO,SAAS,QAAQ;AAAA,EAC1B;AAEA,MAAI,OAAO,KAAK,UAAU,EAAE,SAAS,GAAG;AACtC,WAAO,aAAa;AAAA,EACtB;AAEA,SAAO;AACT;AAYO,SAAS,mBACd,QACA,cAC0B;AAC1B,MAAI,OAAO,WAAW,WAAW,OAAO,OAAO;AAC7C,UAAMA,WAAoC;AAAA,MACxC,OAAO;AAAA,MACP,QAAQ,OAAO;AAAA,MACf,WAAW,aAAa,OAAO,OAAO,IAAI;AAAA,IAC5C;AACA,QAAI,OAAO,OAAO,QAAS,CAAAA,SAAQ,eAAe,OAAO,MAAM;AAC/D,WAAOA;AAAA,EACT;AAEA,QAAM,UAAoC;AAAA,IACxC,OAAO,OAAO;AAAA,IACd,QAAQ,iBAAiB,OAAO,MAAM,KAAK,OAAO;AAAA,EACpD;AACA,MAAI,OAAO,SAAS,KAAM,SAAQ,UAAU,OAAO,QAAQ;AAC3D,SAAO;AACT;AASO,SAAS,YAAY,OAAgB,MAA0B;AACpE,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO,OAAO,UAAU;AAAA,IAC1B,KAAK;AACH,aAAO,OAAO,UAAU;AAAA,IAC1B,KAAK;AACH,aAAO,OAAO,UAAU,YAAY,CAAC,OAAO,MAAM,KAAK;AAAA,IACzD,KAAK;AACH,aAAO,OAAO,UAAU,YAAY,UAAU;AAAA,EAClD;AACF;","names":["details"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { EvaluationResult, EvaluationContext, FlagdeckClient, FlagdeckOptions } from '@flagdeck/js';
|
|
2
|
+
import { Provider, ProviderMetadata, Paradigm, EvaluationContext as EvaluationContext$1, ResolutionDetails, JsonValue } from '@openfeature/server-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal structural shape of an OpenFeature `EvaluationContext`. The real
|
|
6
|
+
* `EvaluationContext` from `@openfeature/server-sdk` is assignable to this, so
|
|
7
|
+
* the provider passes its context straight through. Kept local so the converter
|
|
8
|
+
* stays a pure unit that can be type-checked and tested without the OpenFeature
|
|
9
|
+
* SDK installed.
|
|
10
|
+
*/
|
|
11
|
+
interface OpenFeatureContextLike {
|
|
12
|
+
targetingKey?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* OpenFeature standard resolution reasons we emit. String values mirror
|
|
17
|
+
* `StandardResolutionReasons` in `@openfeature/server-sdk`.
|
|
18
|
+
*/
|
|
19
|
+
declare const Reason: {
|
|
20
|
+
readonly TARGETING_MATCH: "TARGETING_MATCH";
|
|
21
|
+
readonly SPLIT: "SPLIT";
|
|
22
|
+
readonly DEFAULT: "DEFAULT";
|
|
23
|
+
readonly CACHED: "CACHED";
|
|
24
|
+
readonly ERROR: "ERROR";
|
|
25
|
+
};
|
|
26
|
+
type ResolutionReason = (typeof Reason)[keyof typeof Reason];
|
|
27
|
+
/**
|
|
28
|
+
* OpenFeature error codes we emit. String values mirror `ErrorCode` in
|
|
29
|
+
* `@openfeature/server-sdk`.
|
|
30
|
+
*/
|
|
31
|
+
declare const OpenFeatureErrorCode: {
|
|
32
|
+
readonly FLAG_NOT_FOUND: "FLAG_NOT_FOUND";
|
|
33
|
+
readonly TYPE_MISMATCH: "TYPE_MISMATCH";
|
|
34
|
+
readonly INVALID_CONTEXT: "INVALID_CONTEXT";
|
|
35
|
+
readonly GENERAL: "GENERAL";
|
|
36
|
+
};
|
|
37
|
+
type OpenFeatureErrorCodeValue = (typeof OpenFeatureErrorCode)[keyof typeof OpenFeatureErrorCode];
|
|
38
|
+
/**
|
|
39
|
+
* Structural mirror of OpenFeature's `ResolutionDetails<T>`. Values of this
|
|
40
|
+
* shape are assignable to the real `ResolutionDetails<T>`, so the provider's
|
|
41
|
+
* resolvers can return them directly.
|
|
42
|
+
*/
|
|
43
|
+
interface ResolutionDetailsLike<T> {
|
|
44
|
+
value: T;
|
|
45
|
+
variant?: string;
|
|
46
|
+
reason?: string;
|
|
47
|
+
errorCode?: OpenFeatureErrorCodeValue;
|
|
48
|
+
errorMessage?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Translate an OpenFeature `EvaluationContext` into Flagdeck's native context.
|
|
52
|
+
*
|
|
53
|
+
* - `targetingKey` -> `userId`. OpenFeature's bucketing identity is Flagdeck's
|
|
54
|
+
* primary identity, so rollout and variant stickiness line up 1:1.
|
|
55
|
+
* - a string `sessionId` attribute -> native `sessionId`. The engine buckets on
|
|
56
|
+
* `userId || sessionId`, so promoting it preserves anonymous stickiness; a
|
|
57
|
+
* non-string `sessionId` is left in `attributes` rather than dropped.
|
|
58
|
+
* - every other entry -> `attributes[key]`, unchanged. Scalars and nested
|
|
59
|
+
* objects pass through; the engine resolves dot-paths such as `account.id`.
|
|
60
|
+
*
|
|
61
|
+
* An empty or missing context yields an empty Flagdeck context.
|
|
62
|
+
*/
|
|
63
|
+
declare function toFlagdeckContext(context?: OpenFeatureContextLike | null): EvaluationContext;
|
|
64
|
+
/**
|
|
65
|
+
* Translate a Flagdeck `EvaluationResult` into an OpenFeature
|
|
66
|
+
* `ResolutionDetails`. On an error result the caller's `defaultValue` is
|
|
67
|
+
* returned with the mapped error code and `reason: ERROR` — OpenFeature never
|
|
68
|
+
* throws to the caller.
|
|
69
|
+
*
|
|
70
|
+
* Runtime type checking (OpenFeature's `TYPE_MISMATCH`) is applied by the
|
|
71
|
+
* provider's typed resolvers, not here; this function maps reason, variant and
|
|
72
|
+
* error only.
|
|
73
|
+
*/
|
|
74
|
+
declare function fromFlagdeckResult<T>(result: EvaluationResult, defaultValue: T): ResolutionDetailsLike<T>;
|
|
75
|
+
/** The value kinds OpenFeature's typed resolvers check against. */
|
|
76
|
+
type ValueKind = 'boolean' | 'string' | 'number' | 'object';
|
|
77
|
+
/**
|
|
78
|
+
* Runtime type check both providers apply before returning a resolved value:
|
|
79
|
+
* OpenFeature returns the caller default with TYPE_MISMATCH rather than coercing.
|
|
80
|
+
*/
|
|
81
|
+
declare function matchesType(value: unknown, kind: ValueKind): boolean;
|
|
82
|
+
|
|
83
|
+
/** Either a pre-built Flagdeck client or the options to construct one. */
|
|
84
|
+
type FlagdeckProviderInit = FlagdeckClient | FlagdeckOptions;
|
|
85
|
+
/**
|
|
86
|
+
* OpenFeature server provider backed by Flagdeck. Wraps a `@flagdeck/js` client
|
|
87
|
+
* and implements the four typed resolvers. It never throws to the caller: on any
|
|
88
|
+
* error it returns the caller's default value with the mapped error code.
|
|
89
|
+
*/
|
|
90
|
+
declare class FlagdeckProvider implements Provider {
|
|
91
|
+
readonly metadata: ProviderMetadata;
|
|
92
|
+
readonly runsOn: Paradigm;
|
|
93
|
+
private readonly client;
|
|
94
|
+
constructor(init: FlagdeckProviderInit);
|
|
95
|
+
initialize(): Promise<void>;
|
|
96
|
+
onClose(): Promise<void>;
|
|
97
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext$1): Promise<ResolutionDetails<boolean>>;
|
|
98
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext$1): Promise<ResolutionDetails<string>>;
|
|
99
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext$1): Promise<ResolutionDetails<number>>;
|
|
100
|
+
resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext$1): Promise<ResolutionDetails<T>>;
|
|
101
|
+
private resolve;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { FlagdeckProvider, type FlagdeckProviderInit, type OpenFeatureContextLike, OpenFeatureErrorCode, type OpenFeatureErrorCodeValue, Reason, type ResolutionDetailsLike, type ResolutionReason, type ValueKind, fromFlagdeckResult, matchesType, toFlagdeckContext };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { EvaluationResult, EvaluationContext, FlagdeckClient, FlagdeckOptions } from '@flagdeck/js';
|
|
2
|
+
import { Provider, ProviderMetadata, Paradigm, EvaluationContext as EvaluationContext$1, ResolutionDetails, JsonValue } from '@openfeature/server-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal structural shape of an OpenFeature `EvaluationContext`. The real
|
|
6
|
+
* `EvaluationContext` from `@openfeature/server-sdk` is assignable to this, so
|
|
7
|
+
* the provider passes its context straight through. Kept local so the converter
|
|
8
|
+
* stays a pure unit that can be type-checked and tested without the OpenFeature
|
|
9
|
+
* SDK installed.
|
|
10
|
+
*/
|
|
11
|
+
interface OpenFeatureContextLike {
|
|
12
|
+
targetingKey?: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* OpenFeature standard resolution reasons we emit. String values mirror
|
|
17
|
+
* `StandardResolutionReasons` in `@openfeature/server-sdk`.
|
|
18
|
+
*/
|
|
19
|
+
declare const Reason: {
|
|
20
|
+
readonly TARGETING_MATCH: "TARGETING_MATCH";
|
|
21
|
+
readonly SPLIT: "SPLIT";
|
|
22
|
+
readonly DEFAULT: "DEFAULT";
|
|
23
|
+
readonly CACHED: "CACHED";
|
|
24
|
+
readonly ERROR: "ERROR";
|
|
25
|
+
};
|
|
26
|
+
type ResolutionReason = (typeof Reason)[keyof typeof Reason];
|
|
27
|
+
/**
|
|
28
|
+
* OpenFeature error codes we emit. String values mirror `ErrorCode` in
|
|
29
|
+
* `@openfeature/server-sdk`.
|
|
30
|
+
*/
|
|
31
|
+
declare const OpenFeatureErrorCode: {
|
|
32
|
+
readonly FLAG_NOT_FOUND: "FLAG_NOT_FOUND";
|
|
33
|
+
readonly TYPE_MISMATCH: "TYPE_MISMATCH";
|
|
34
|
+
readonly INVALID_CONTEXT: "INVALID_CONTEXT";
|
|
35
|
+
readonly GENERAL: "GENERAL";
|
|
36
|
+
};
|
|
37
|
+
type OpenFeatureErrorCodeValue = (typeof OpenFeatureErrorCode)[keyof typeof OpenFeatureErrorCode];
|
|
38
|
+
/**
|
|
39
|
+
* Structural mirror of OpenFeature's `ResolutionDetails<T>`. Values of this
|
|
40
|
+
* shape are assignable to the real `ResolutionDetails<T>`, so the provider's
|
|
41
|
+
* resolvers can return them directly.
|
|
42
|
+
*/
|
|
43
|
+
interface ResolutionDetailsLike<T> {
|
|
44
|
+
value: T;
|
|
45
|
+
variant?: string;
|
|
46
|
+
reason?: string;
|
|
47
|
+
errorCode?: OpenFeatureErrorCodeValue;
|
|
48
|
+
errorMessage?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Translate an OpenFeature `EvaluationContext` into Flagdeck's native context.
|
|
52
|
+
*
|
|
53
|
+
* - `targetingKey` -> `userId`. OpenFeature's bucketing identity is Flagdeck's
|
|
54
|
+
* primary identity, so rollout and variant stickiness line up 1:1.
|
|
55
|
+
* - a string `sessionId` attribute -> native `sessionId`. The engine buckets on
|
|
56
|
+
* `userId || sessionId`, so promoting it preserves anonymous stickiness; a
|
|
57
|
+
* non-string `sessionId` is left in `attributes` rather than dropped.
|
|
58
|
+
* - every other entry -> `attributes[key]`, unchanged. Scalars and nested
|
|
59
|
+
* objects pass through; the engine resolves dot-paths such as `account.id`.
|
|
60
|
+
*
|
|
61
|
+
* An empty or missing context yields an empty Flagdeck context.
|
|
62
|
+
*/
|
|
63
|
+
declare function toFlagdeckContext(context?: OpenFeatureContextLike | null): EvaluationContext;
|
|
64
|
+
/**
|
|
65
|
+
* Translate a Flagdeck `EvaluationResult` into an OpenFeature
|
|
66
|
+
* `ResolutionDetails`. On an error result the caller's `defaultValue` is
|
|
67
|
+
* returned with the mapped error code and `reason: ERROR` — OpenFeature never
|
|
68
|
+
* throws to the caller.
|
|
69
|
+
*
|
|
70
|
+
* Runtime type checking (OpenFeature's `TYPE_MISMATCH`) is applied by the
|
|
71
|
+
* provider's typed resolvers, not here; this function maps reason, variant and
|
|
72
|
+
* error only.
|
|
73
|
+
*/
|
|
74
|
+
declare function fromFlagdeckResult<T>(result: EvaluationResult, defaultValue: T): ResolutionDetailsLike<T>;
|
|
75
|
+
/** The value kinds OpenFeature's typed resolvers check against. */
|
|
76
|
+
type ValueKind = 'boolean' | 'string' | 'number' | 'object';
|
|
77
|
+
/**
|
|
78
|
+
* Runtime type check both providers apply before returning a resolved value:
|
|
79
|
+
* OpenFeature returns the caller default with TYPE_MISMATCH rather than coercing.
|
|
80
|
+
*/
|
|
81
|
+
declare function matchesType(value: unknown, kind: ValueKind): boolean;
|
|
82
|
+
|
|
83
|
+
/** Either a pre-built Flagdeck client or the options to construct one. */
|
|
84
|
+
type FlagdeckProviderInit = FlagdeckClient | FlagdeckOptions;
|
|
85
|
+
/**
|
|
86
|
+
* OpenFeature server provider backed by Flagdeck. Wraps a `@flagdeck/js` client
|
|
87
|
+
* and implements the four typed resolvers. It never throws to the caller: on any
|
|
88
|
+
* error it returns the caller's default value with the mapped error code.
|
|
89
|
+
*/
|
|
90
|
+
declare class FlagdeckProvider implements Provider {
|
|
91
|
+
readonly metadata: ProviderMetadata;
|
|
92
|
+
readonly runsOn: Paradigm;
|
|
93
|
+
private readonly client;
|
|
94
|
+
constructor(init: FlagdeckProviderInit);
|
|
95
|
+
initialize(): Promise<void>;
|
|
96
|
+
onClose(): Promise<void>;
|
|
97
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: EvaluationContext$1): Promise<ResolutionDetails<boolean>>;
|
|
98
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: EvaluationContext$1): Promise<ResolutionDetails<string>>;
|
|
99
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: EvaluationContext$1): Promise<ResolutionDetails<number>>;
|
|
100
|
+
resolveObjectEvaluation<T extends JsonValue>(flagKey: string, defaultValue: T, context: EvaluationContext$1): Promise<ResolutionDetails<T>>;
|
|
101
|
+
private resolve;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { FlagdeckProvider, type FlagdeckProviderInit, type OpenFeatureContextLike, OpenFeatureErrorCode, type OpenFeatureErrorCodeValue, Reason, type ResolutionDetailsLike, type ResolutionReason, type ValueKind, fromFlagdeckResult, matchesType, toFlagdeckContext };
|