@cloudflare/flagship 0.0.0 → 0.0.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 ADDED
@@ -0,0 +1,184 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or designated in writing by the copyright owner as "Not a
57
+ Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a
80
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
81
+ or a Contribution incorporated within the Work constitutes direct
82
+ or contributory patent infringement, then any patent licenses
83
+ granted to You under this License for that Work shall terminate
84
+ as of the date such litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or
92
+ Derivative Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or as an addendum to
115
+ the NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, copy, modify, merge,
120
+ publish, distribute, sublicense, and/or sell copies of the Work,
121
+ and to permit persons to whom the Work is furnished to do so,
122
+ subject to the following conditions.
123
+
124
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
125
+ any Contribution intentionally submitted for inclusion in the Work
126
+ by You to the Licensor shall be under the terms and conditions of
127
+ this License, without any additional terms or conditions.
128
+ Notwithstanding the above, nothing herein shall supersede or modify
129
+ the terms of any separate license agreement you may have executed
130
+ with Licensor regarding such Contributions.
131
+
132
+ 6. Trademarks. This License does not grant permission to use the trade
133
+ names, trademarks, service marks, or product names of the Licensor,
134
+ except as required for reasonable and customary use in describing the
135
+ origin of the Work and reproducing the content of the NOTICE file.
136
+
137
+ 7. Disclaimer of Warranty. Unless required by applicable law or
138
+ agreed to in writing, Licensor provides the Work (and each
139
+ Contributor provides its Contributions) on an "AS IS" BASIS,
140
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
141
+ implied, including, without limitation, any warranties or conditions
142
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
143
+ PARTICULAR PURPOSE. You are solely responsible for determining the
144
+ appropriateness of using or redistributing the Work and assume any
145
+ risks associated with Your exercise of permissions under this License.
146
+
147
+ 8. Limitation of Liability. In no event and under no legal theory,
148
+ whether in tort (including negligence), contract, or otherwise,
149
+ unless required by applicable law (such as deliberate and grossly
150
+ negligent acts) or agreed to in writing, shall any Contributor be
151
+ liable to You for damages, including any direct, indirect, special,
152
+ incidental, or exemplary damages of any character arising as a
153
+ result of this License or out of the use or inability to use the
154
+ Work (including but not limited to damages for loss of goodwill,
155
+ work stoppage, computer failure or malfunction, or all other
156
+ commercial damages or losses), even if such Contributor has been
157
+ advised of the possibility of such damages.
158
+
159
+ 9. Accepting Warranty or Additional Liability. While redistributing
160
+ the Work or Derivative Works thereof, You may choose to offer,
161
+ and charge a fee for, acceptance of support, warranty, indemnity,
162
+ or other liability obligations and/or rights consistent with this
163
+ License. However, in accepting such obligations, You may act only
164
+ on Your own behalf and on Your sole responsibility, not on behalf
165
+ of any other Contributor, and only if You agree to indemnify,
166
+ defend, and hold each Contributor harmless for any liability
167
+ incurred by, or claims asserted against, such Contributor by reason
168
+ of your accepting any such warranty or additional liability.
169
+
170
+ END OF TERMS AND CONDITIONS
171
+
172
+ Copyright 2026 Cloudflare, Inc.
173
+
174
+ Licensed under the Apache License, Version 2.0 (the "License");
175
+ you may not use this file except in compliance with the License.
176
+ You may obtain a copy of the License at
177
+
178
+ http://www.apache.org/licenses/LICENSE-2.0
179
+
180
+ Unless required by applicable law or agreed to in writing, software
181
+ distributed under the License is distributed on an "AS IS" BASIS,
182
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183
+ See the License for the specific language governing permissions and
184
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @cloudflare/flagship
2
+
3
+ OpenFeature provider SDK for Flagship, Cloudflare's feature flag platform.
4
+
5
+ This is a technical preview. To learn more, see the [announcement blogpost](https://blog.cloudflare.com/flagship-feature-flags).
@@ -0,0 +1,233 @@
1
+ import { EvaluationContext } from "@openfeature/server-sdk";
2
+
3
+ //#region src/types.d.ts
4
+ /** Default base URL for the Flagship API. */
5
+ declare const FLAGSHIP_DEFAULT_BASE_URL = "https://api.cloudflare.com";
6
+ /**
7
+ * Configuration options for Flagship providers.
8
+ *
9
+ * Provide either `appId` + `accountId` (recommended) or `endpoint` (for full control).
10
+ *
11
+ * @example Using appId + accountId (recommended)
12
+ * { appId: 'app-abc123', accountId: 'your-account-id', authToken: 'your-token' }
13
+ *
14
+ * @example Using appId with custom base URL for local dev
15
+ * { appId: 'app-abc123', accountId: 'your-account-id', baseUrl: 'http://localhost:8787' }
16
+ *
17
+ * @example Using endpoint for full control
18
+ * { endpoint: 'http://localhost:8787/v1/my-account/apps/app-abc123/evaluate' }
19
+ */
20
+ interface FlagshipProviderOptions {
21
+ /**
22
+ * Your Flagship app ID. The SDK constructs the evaluation URL automatically.
23
+ * Mutually exclusive with `endpoint`.
24
+ */
25
+ appId?: string;
26
+ /**
27
+ * Base URL for the Flagship API. Only used with `appId`.
28
+ * @default 'https://api.cloudflare.com'
29
+ */
30
+ baseUrl?: string;
31
+ /**
32
+ * Account ID for multi-tenant routing. Required when using `appId`.
33
+ */
34
+ accountId?: string;
35
+ /**
36
+ * Full evaluation endpoint URL. Mutually exclusive with `appId`.
37
+ * Use this for local development or custom deployments.
38
+ */
39
+ endpoint?: string;
40
+ /**
41
+ * Enable SDK-level logging. When `false` (the default), the SDK produces no
42
+ * console output of its own — all internal `debug`, `warn`, and `error` calls
43
+ * are suppressed. Set to `true` to surface evaluation debug info and errors in
44
+ * the console, which can be helpful during development or debugging.
45
+ *
46
+ * Note: this only controls logs emitted directly by the Flagship SDK.
47
+ * OpenFeature's own framework-level logs are controlled separately via
48
+ * `OpenFeature.setLogger(...)`.
49
+ *
50
+ * @default false
51
+ */
52
+ logging?: boolean;
53
+ /**
54
+ * Bearer token for authenticating requests to the Flagship API.
55
+ * When set, an `Authorization: Bearer <token>` header is automatically
56
+ * added to every request.
57
+ *
58
+ * If you also supply an `Authorization` header via `fetchOptions.headers`,
59
+ * the explicit header takes precedence and `authToken` is ignored for
60
+ * that header slot.
61
+ *
62
+ * @example
63
+ * { appId: 'app-abc123', accountId: 'my-account', authToken: 'my-secret-token' }
64
+ */
65
+ authToken?: string;
66
+ /**
67
+ * Custom fetch options applied to every request (e.g. custom headers).
68
+ * Headers provided here are merged with any headers derived from other
69
+ * options (e.g. `authToken`), with values in `fetchOptions.headers`
70
+ * taking precedence.
71
+ */
72
+ fetchOptions?: RequestInit;
73
+ /**
74
+ * Request timeout in milliseconds.
75
+ * @default 5000
76
+ */
77
+ timeout?: number;
78
+ /**
79
+ * Number of retry attempts on transient errors. Capped at 10.
80
+ * 404 and 400 responses are never retried.
81
+ * @default 1
82
+ */
83
+ retries?: number;
84
+ /**
85
+ * Fixed delay in milliseconds between retry attempts. Capped at 30 000.
86
+ * @default 1000
87
+ */
88
+ retryDelay?: number;
89
+ }
90
+ /**
91
+ * Configuration options for `FlagshipClientProvider` (browser / static-context environments).
92
+ */
93
+ interface FlagshipClientProviderOptions extends FlagshipProviderOptions {
94
+ /**
95
+ * Flag keys to fetch during `initialize()` and on every `onContextChange()`.
96
+ * Fetched flags are stored in an in-memory cache and resolved synchronously
97
+ * by the OpenFeature web SDK. Any flag key not listed here will return
98
+ * `ErrorCode.FLAG_NOT_FOUND` at resolution time.
99
+ *
100
+ * @example
101
+ * prefetchFlags: ['dark-mode', 'welcome-message', 'max-uploads']
102
+ */
103
+ prefetchFlags?: string[];
104
+ }
105
+ /**
106
+ * A single entry in the client provider's in-memory flag cache.
107
+ * Fields mirror the data-plane's `EvaluateResult`.
108
+ */
109
+ interface CachedFlag {
110
+ value: unknown;
111
+ reason: string;
112
+ variant: string;
113
+ }
114
+ /**
115
+ * Shape of a successful response from the Flagship evaluation API.
116
+ * Mirrors the data-plane's `EvaluateResult` contract exactly — every field
117
+ * is always present on a 200 response.
118
+ */
119
+ interface FlagshipEvaluationResponse {
120
+ flagKey: string;
121
+ value: unknown;
122
+ /** The variation key that was served (e.g. `'on'`, `'off'`, `'v2'`). */
123
+ variant: string;
124
+ /**
125
+ * Why this value was returned:
126
+ * - `TARGETING_MATCH` — a rule matched the evaluation context
127
+ * - `SPLIT` — a percentage rollout rule matched
128
+ * - `DEFAULT` — no rule matched; the default variation was served
129
+ * - `DISABLED` — the flag is disabled
130
+ */
131
+ reason: 'TARGETING_MATCH' | 'DEFAULT' | 'DISABLED' | 'SPLIT';
132
+ }
133
+ /**
134
+ * Internal error codes produced by `FlagshipClient`.
135
+ * These are mapped to OpenFeature `ErrorCode` values by the providers.
136
+ */
137
+ declare enum FlagshipErrorCode {
138
+ /** HTTP or fetch-level failure (non-404/400 status, connection refused, etc.) */
139
+ NETWORK_ERROR = "NETWORK_ERROR",
140
+ /** The request was aborted because the configured timeout elapsed. */
141
+ TIMEOUT_ERROR = "TIMEOUT_ERROR",
142
+ /** The response body was not a valid evaluation response. */
143
+ PARSE_ERROR = "PARSE_ERROR",
144
+ /** The evaluation context contained complex values that cannot be serialized to query parameters. */
145
+ INVALID_CONTEXT = "INVALID_CONTEXT"
146
+ }
147
+ /**
148
+ * Error thrown by `FlagshipClient` for all abnormal conditions.
149
+ * Carries a `code` for programmatic handling and an optional `cause` which
150
+ * is the underlying `Response` object for HTTP errors, allowing callers to
151
+ * inspect the status code (e.g. to distinguish 404 → `FLAG_NOT_FOUND`).
152
+ */
153
+ declare class FlagshipError extends Error {
154
+ code: FlagshipErrorCode;
155
+ cause?: unknown | undefined;
156
+ constructor(message: string, code: FlagshipErrorCode, cause?: unknown | undefined);
157
+ }
158
+ //#endregion
159
+ //#region src/context.d.ts
160
+ /**
161
+ * Utility for transforming OpenFeature evaluation context
162
+ */
163
+ declare class ContextTransformer {
164
+ /**
165
+ * Transform OpenFeature evaluation context to query parameters
166
+ * for the Flagship API.
167
+ *
168
+ * Primitive values (`string`, `number`, `boolean`) and `Date` objects are
169
+ * serialized directly. Nested objects and arrays cannot be expressed as query
170
+ * parameters and are skipped.
171
+ *
172
+ * When a `droppedKeys` collector array is provided, skipped key names are
173
+ * pushed into it and **no** console warning is emitted — the caller is
174
+ * expected to handle the situation (e.g. throw `INVALID_CONTEXT`).
175
+ * When no collector is provided, a `console.warn` is emitted for each
176
+ * skipped key so the issue is still surfaced in development.
177
+ *
178
+ * @param context - OpenFeature evaluation context
179
+ * @param droppedKeys - Optional collector array; skipped key names are pushed here
180
+ */
181
+ static toQueryParams(context: EvaluationContext, droppedKeys?: string[]): Record<string, string>;
182
+ /**
183
+ * Build URL with query parameters from context.
184
+ *
185
+ * @param baseUrl - The base evaluation endpoint URL
186
+ * @param flagKey - The flag key to evaluate
187
+ * @param context - OpenFeature evaluation context
188
+ * @param droppedKeys - Optional collector array; skipped context key names are pushed here
189
+ */
190
+ static buildUrl(baseUrl: string, flagKey: string, context: EvaluationContext, droppedKeys?: string[]): string;
191
+ }
192
+ //#endregion
193
+ //#region ../../node_modules/.pnpm/@openfeature+core@1.9.2/node_modules/@openfeature/core/dist/types.d.ts
194
+ type PrimitiveValue = null | boolean | string | number;
195
+ type EvaluationContextValue = PrimitiveValue | Date | {
196
+ [key: string]: EvaluationContextValue;
197
+ } | EvaluationContextValue[];
198
+ /**
199
+ * A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
200
+ */
201
+ type EvaluationContext$1 = {
202
+ /**
203
+ * A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.
204
+ * Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users.
205
+ * Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
206
+ */
207
+ targetingKey?: string;
208
+ } & Record<string, EvaluationContextValue>;
209
+ //#endregion
210
+ //#region src/client.d.ts
211
+ declare class FlagshipClient {
212
+ private readonly options;
213
+ constructor(options: FlagshipProviderOptions);
214
+ /**
215
+ * Evaluate a flag with the given context.
216
+ *
217
+ * Throws a `FlagshipError` with `FlagshipErrorCode.INVALID_CONTEXT` if the
218
+ * evaluation context contains complex values (objects or arrays) that cannot
219
+ * be serialized to query parameters.
220
+ */
221
+ evaluate(flagKey: string, context: EvaluationContext$1): Promise<FlagshipEvaluationResponse>;
222
+ /**
223
+ * Fetch with retry logic. Only retries on transient network/server errors —
224
+ * 404 and 400 responses are terminal and propagated immediately.
225
+ */
226
+ private fetchWithRetry;
227
+ /**
228
+ * Fetch with timeout using AbortController
229
+ */
230
+ private fetchWithTimeout;
231
+ }
232
+ //#endregion
233
+ export { FlagshipClientProviderOptions as a, FlagshipEvaluationResponse as c, FLAGSHIP_DEFAULT_BASE_URL as i, FlagshipProviderOptions as l, ContextTransformer as n, FlagshipError as o, CachedFlag as r, FlagshipErrorCode as s, FlagshipClient as t };
@@ -0,0 +1,233 @@
1
+ import { EvaluationContext } from "@openfeature/server-sdk";
2
+
3
+ //#region src/types.d.ts
4
+ /** Default base URL for the Flagship API. */
5
+ declare const FLAGSHIP_DEFAULT_BASE_URL = "https://api.cloudflare.com";
6
+ /**
7
+ * Configuration options for Flagship providers.
8
+ *
9
+ * Provide either `appId` + `accountId` (recommended) or `endpoint` (for full control).
10
+ *
11
+ * @example Using appId + accountId (recommended)
12
+ * { appId: 'app-abc123', accountId: 'your-account-id', authToken: 'your-token' }
13
+ *
14
+ * @example Using appId with custom base URL for local dev
15
+ * { appId: 'app-abc123', accountId: 'your-account-id', baseUrl: 'http://localhost:8787' }
16
+ *
17
+ * @example Using endpoint for full control
18
+ * { endpoint: 'http://localhost:8787/v1/my-account/apps/app-abc123/evaluate' }
19
+ */
20
+ interface FlagshipProviderOptions {
21
+ /**
22
+ * Your Flagship app ID. The SDK constructs the evaluation URL automatically.
23
+ * Mutually exclusive with `endpoint`.
24
+ */
25
+ appId?: string;
26
+ /**
27
+ * Base URL for the Flagship API. Only used with `appId`.
28
+ * @default 'https://api.cloudflare.com'
29
+ */
30
+ baseUrl?: string;
31
+ /**
32
+ * Account ID for multi-tenant routing. Required when using `appId`.
33
+ */
34
+ accountId?: string;
35
+ /**
36
+ * Full evaluation endpoint URL. Mutually exclusive with `appId`.
37
+ * Use this for local development or custom deployments.
38
+ */
39
+ endpoint?: string;
40
+ /**
41
+ * Enable SDK-level logging. When `false` (the default), the SDK produces no
42
+ * console output of its own — all internal `debug`, `warn`, and `error` calls
43
+ * are suppressed. Set to `true` to surface evaluation debug info and errors in
44
+ * the console, which can be helpful during development or debugging.
45
+ *
46
+ * Note: this only controls logs emitted directly by the Flagship SDK.
47
+ * OpenFeature's own framework-level logs are controlled separately via
48
+ * `OpenFeature.setLogger(...)`.
49
+ *
50
+ * @default false
51
+ */
52
+ logging?: boolean;
53
+ /**
54
+ * Bearer token for authenticating requests to the Flagship API.
55
+ * When set, an `Authorization: Bearer <token>` header is automatically
56
+ * added to every request.
57
+ *
58
+ * If you also supply an `Authorization` header via `fetchOptions.headers`,
59
+ * the explicit header takes precedence and `authToken` is ignored for
60
+ * that header slot.
61
+ *
62
+ * @example
63
+ * { appId: 'app-abc123', accountId: 'my-account', authToken: 'my-secret-token' }
64
+ */
65
+ authToken?: string;
66
+ /**
67
+ * Custom fetch options applied to every request (e.g. custom headers).
68
+ * Headers provided here are merged with any headers derived from other
69
+ * options (e.g. `authToken`), with values in `fetchOptions.headers`
70
+ * taking precedence.
71
+ */
72
+ fetchOptions?: RequestInit;
73
+ /**
74
+ * Request timeout in milliseconds.
75
+ * @default 5000
76
+ */
77
+ timeout?: number;
78
+ /**
79
+ * Number of retry attempts on transient errors. Capped at 10.
80
+ * 404 and 400 responses are never retried.
81
+ * @default 1
82
+ */
83
+ retries?: number;
84
+ /**
85
+ * Fixed delay in milliseconds between retry attempts. Capped at 30 000.
86
+ * @default 1000
87
+ */
88
+ retryDelay?: number;
89
+ }
90
+ /**
91
+ * Configuration options for `FlagshipClientProvider` (browser / static-context environments).
92
+ */
93
+ interface FlagshipClientProviderOptions extends FlagshipProviderOptions {
94
+ /**
95
+ * Flag keys to fetch during `initialize()` and on every `onContextChange()`.
96
+ * Fetched flags are stored in an in-memory cache and resolved synchronously
97
+ * by the OpenFeature web SDK. Any flag key not listed here will return
98
+ * `ErrorCode.FLAG_NOT_FOUND` at resolution time.
99
+ *
100
+ * @example
101
+ * prefetchFlags: ['dark-mode', 'welcome-message', 'max-uploads']
102
+ */
103
+ prefetchFlags?: string[];
104
+ }
105
+ /**
106
+ * A single entry in the client provider's in-memory flag cache.
107
+ * Fields mirror the data-plane's `EvaluateResult`.
108
+ */
109
+ interface CachedFlag {
110
+ value: unknown;
111
+ reason: string;
112
+ variant: string;
113
+ }
114
+ /**
115
+ * Shape of a successful response from the Flagship evaluation API.
116
+ * Mirrors the data-plane's `EvaluateResult` contract exactly — every field
117
+ * is always present on a 200 response.
118
+ */
119
+ interface FlagshipEvaluationResponse {
120
+ flagKey: string;
121
+ value: unknown;
122
+ /** The variation key that was served (e.g. `'on'`, `'off'`, `'v2'`). */
123
+ variant: string;
124
+ /**
125
+ * Why this value was returned:
126
+ * - `TARGETING_MATCH` — a rule matched the evaluation context
127
+ * - `SPLIT` — a percentage rollout rule matched
128
+ * - `DEFAULT` — no rule matched; the default variation was served
129
+ * - `DISABLED` — the flag is disabled
130
+ */
131
+ reason: 'TARGETING_MATCH' | 'DEFAULT' | 'DISABLED' | 'SPLIT';
132
+ }
133
+ /**
134
+ * Internal error codes produced by `FlagshipClient`.
135
+ * These are mapped to OpenFeature `ErrorCode` values by the providers.
136
+ */
137
+ declare enum FlagshipErrorCode {
138
+ /** HTTP or fetch-level failure (non-404/400 status, connection refused, etc.) */
139
+ NETWORK_ERROR = "NETWORK_ERROR",
140
+ /** The request was aborted because the configured timeout elapsed. */
141
+ TIMEOUT_ERROR = "TIMEOUT_ERROR",
142
+ /** The response body was not a valid evaluation response. */
143
+ PARSE_ERROR = "PARSE_ERROR",
144
+ /** The evaluation context contained complex values that cannot be serialized to query parameters. */
145
+ INVALID_CONTEXT = "INVALID_CONTEXT"
146
+ }
147
+ /**
148
+ * Error thrown by `FlagshipClient` for all abnormal conditions.
149
+ * Carries a `code` for programmatic handling and an optional `cause` which
150
+ * is the underlying `Response` object for HTTP errors, allowing callers to
151
+ * inspect the status code (e.g. to distinguish 404 → `FLAG_NOT_FOUND`).
152
+ */
153
+ declare class FlagshipError extends Error {
154
+ code: FlagshipErrorCode;
155
+ cause?: unknown | undefined;
156
+ constructor(message: string, code: FlagshipErrorCode, cause?: unknown | undefined);
157
+ }
158
+ //#endregion
159
+ //#region src/context.d.ts
160
+ /**
161
+ * Utility for transforming OpenFeature evaluation context
162
+ */
163
+ declare class ContextTransformer {
164
+ /**
165
+ * Transform OpenFeature evaluation context to query parameters
166
+ * for the Flagship API.
167
+ *
168
+ * Primitive values (`string`, `number`, `boolean`) and `Date` objects are
169
+ * serialized directly. Nested objects and arrays cannot be expressed as query
170
+ * parameters and are skipped.
171
+ *
172
+ * When a `droppedKeys` collector array is provided, skipped key names are
173
+ * pushed into it and **no** console warning is emitted — the caller is
174
+ * expected to handle the situation (e.g. throw `INVALID_CONTEXT`).
175
+ * When no collector is provided, a `console.warn` is emitted for each
176
+ * skipped key so the issue is still surfaced in development.
177
+ *
178
+ * @param context - OpenFeature evaluation context
179
+ * @param droppedKeys - Optional collector array; skipped key names are pushed here
180
+ */
181
+ static toQueryParams(context: EvaluationContext, droppedKeys?: string[]): Record<string, string>;
182
+ /**
183
+ * Build URL with query parameters from context.
184
+ *
185
+ * @param baseUrl - The base evaluation endpoint URL
186
+ * @param flagKey - The flag key to evaluate
187
+ * @param context - OpenFeature evaluation context
188
+ * @param droppedKeys - Optional collector array; skipped context key names are pushed here
189
+ */
190
+ static buildUrl(baseUrl: string, flagKey: string, context: EvaluationContext, droppedKeys?: string[]): string;
191
+ }
192
+ //#endregion
193
+ //#region ../../node_modules/.pnpm/@openfeature+core@1.9.2/node_modules/@openfeature/core/dist/types.d.ts
194
+ type PrimitiveValue = null | boolean | string | number;
195
+ type EvaluationContextValue = PrimitiveValue | Date | {
196
+ [key: string]: EvaluationContextValue;
197
+ } | EvaluationContextValue[];
198
+ /**
199
+ * A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
200
+ */
201
+ type EvaluationContext$1 = {
202
+ /**
203
+ * A string uniquely identifying the subject (end-user, or client service) of a flag evaluation.
204
+ * Providers may require this field for fractional flag evaluation, rules, or overrides targeting specific users.
205
+ * Such providers may behave unpredictably if a targeting key is not specified at flag resolution.
206
+ */
207
+ targetingKey?: string;
208
+ } & Record<string, EvaluationContextValue>;
209
+ //#endregion
210
+ //#region src/client.d.ts
211
+ declare class FlagshipClient {
212
+ private readonly options;
213
+ constructor(options: FlagshipProviderOptions);
214
+ /**
215
+ * Evaluate a flag with the given context.
216
+ *
217
+ * Throws a `FlagshipError` with `FlagshipErrorCode.INVALID_CONTEXT` if the
218
+ * evaluation context contains complex values (objects or arrays) that cannot
219
+ * be serialized to query parameters.
220
+ */
221
+ evaluate(flagKey: string, context: EvaluationContext$1): Promise<FlagshipEvaluationResponse>;
222
+ /**
223
+ * Fetch with retry logic. Only retries on transient network/server errors —
224
+ * 404 and 400 responses are terminal and propagated immediately.
225
+ */
226
+ private fetchWithRetry;
227
+ /**
228
+ * Fetch with timeout using AbortController
229
+ */
230
+ private fetchWithTimeout;
231
+ }
232
+ //#endregion
233
+ export { FlagshipClientProviderOptions as a, FlagshipEvaluationResponse as c, FLAGSHIP_DEFAULT_BASE_URL as i, FlagshipProviderOptions as l, ContextTransformer as n, FlagshipError as o, CachedFlag as r, FlagshipErrorCode as s, FlagshipClient as t };
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_src = require("./src-De-abNIr.cjs");
3
+ exports.ContextTransformer = require_src.ContextTransformer;
4
+ exports.FLAGSHIP_DEFAULT_BASE_URL = require_src.FLAGSHIP_DEFAULT_BASE_URL;
5
+ exports.FlagshipClient = require_src.FlagshipClient;
6
+ exports.FlagshipError = require_src.FlagshipError;
7
+ exports.FlagshipErrorCode = require_src.FlagshipErrorCode;
@@ -0,0 +1,2 @@
1
+ import { a as FlagshipClientProviderOptions, c as FlagshipEvaluationResponse, i as FLAGSHIP_DEFAULT_BASE_URL, l as FlagshipProviderOptions, n as ContextTransformer, o as FlagshipError, r as CachedFlag, s as FlagshipErrorCode, t as FlagshipClient } from "./index-D8YLMfBG.cjs";
2
+ export { CachedFlag, ContextTransformer, FLAGSHIP_DEFAULT_BASE_URL, FlagshipClient, FlagshipClientProviderOptions, FlagshipError, FlagshipErrorCode, FlagshipEvaluationResponse, FlagshipProviderOptions };
@@ -0,0 +1,2 @@
1
+ import { a as FlagshipClientProviderOptions, c as FlagshipEvaluationResponse, i as FLAGSHIP_DEFAULT_BASE_URL, l as FlagshipProviderOptions, n as ContextTransformer, o as FlagshipError, r as CachedFlag, s as FlagshipErrorCode, t as FlagshipClient } from "./index-C_sW3e_7.mjs";
2
+ export { CachedFlag, ContextTransformer, FLAGSHIP_DEFAULT_BASE_URL, FlagshipClient, FlagshipClientProviderOptions, FlagshipError, FlagshipErrorCode, FlagshipEvaluationResponse, FlagshipProviderOptions };
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import { a as FlagshipErrorCode, i as FlagshipError, n as ContextTransformer, r as FLAGSHIP_DEFAULT_BASE_URL, t as FlagshipClient } from "./src-CiVDWmng.mjs";
2
+ export { ContextTransformer, FLAGSHIP_DEFAULT_BASE_URL, FlagshipClient, FlagshipError, FlagshipErrorCode };