@vercel/flags-core 0.1.8 → 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 +11 -0
- package/README.md +40 -0
- package/dist/chunk-7BUTND2Q.js +1496 -0
- package/dist/chunk-7BUTND2Q.js.map +1 -0
- package/dist/chunk-UQEFJL4F.js +1503 -0
- package/dist/chunk-UQEFJL4F.js.map +1 -0
- package/dist/index.default.d.ts +248 -0
- package/dist/index.default.js +21 -0
- package/dist/index.next-js.d.ts +235 -0
- package/dist/index.next-js.js +21 -0
- package/dist/index.next-js.js.map +1 -0
- package/dist/openfeature.default.d.ts +48 -0
- package/dist/openfeature.default.js +157 -0
- package/dist/openfeature.default.js.map +1 -0
- package/dist/openfeature.next-js.d.ts +49 -0
- package/dist/openfeature.next-js.js +157 -0
- package/dist/openfeature.next-js.js.map +1 -0
- package/dist/{client-BxFTPk0J.d.cts → types-508sZTBu.d.ts} +137 -58
- package/package.json +31 -19
- package/dist/chunk-4IFGPGNY.js +0 -566
- package/dist/chunk-4IFGPGNY.js.map +0 -1
- package/dist/chunk-6ZAELH3K.cjs +0 -566
- package/dist/chunk-6ZAELH3K.cjs.map +0 -1
- package/dist/client-BxFTPk0J.d.ts +0 -426
- package/dist/index.cjs +0 -27
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -79
- package/dist/index.d.ts +0 -79
- package/dist/index.js +0 -27
- package/dist/openfeature.cjs +0 -151
- package/dist/openfeature.cjs.map +0 -1
- package/dist/openfeature.d.cts +0 -24
- package/dist/openfeature.d.ts +0 -24
- package/dist/openfeature.js +0 -151
- package/dist/openfeature.js.map +0 -1
- /package/dist/{index.js.map → index.default.js.map} +0 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { D as DatafileInput, S as StreamOptions, P as PollingOptions, a as DataSource, b as Datafile, B as BundledDefinitions, E as EvaluationParams, c as EvaluationResult, F as FlagsClient } from './types-508sZTBu.js';
|
|
2
|
+
export { d as Packed, R as Reason } from './types-508sZTBu.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for FlagNetworkDataSource
|
|
6
|
+
*/
|
|
7
|
+
type FlagNetworkDataSourceOptions = {
|
|
8
|
+
/** SDK key for authentication (must start with "vf_") */
|
|
9
|
+
sdkKey: string;
|
|
10
|
+
/**
|
|
11
|
+
* Initial datafile to use immediately
|
|
12
|
+
* - At runtime: used while waiting for stream/poll, then updated in background
|
|
13
|
+
* - At build step: used as primary source (skips network)
|
|
14
|
+
*/
|
|
15
|
+
datafile?: DatafileInput;
|
|
16
|
+
/**
|
|
17
|
+
* Configure streaming connection (runtime only, ignored during build step)
|
|
18
|
+
* - `true`: Enable with default options (initTimeoutMs: 3000)
|
|
19
|
+
* - `false`: Disable streaming
|
|
20
|
+
* - `{ initTimeoutMs: number }`: Enable with custom timeout
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
stream?: boolean | StreamOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Configure polling fallback (runtime only, ignored during build step)
|
|
26
|
+
* - `true`: Enable with default options (intervalMs: 30000, initTimeoutMs: 3000)
|
|
27
|
+
* - `false`: Disable polling
|
|
28
|
+
* - `{ intervalMs: number, initTimeoutMs: number }`: Enable with custom options
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
polling?: boolean | PollingOptions;
|
|
32
|
+
/**
|
|
33
|
+
* Override build step detection
|
|
34
|
+
* - `true`: Treat as build step (use datafile/bundled only, no network)
|
|
35
|
+
* - `false`: Treat as runtime (try stream/poll first)
|
|
36
|
+
* @default auto-detected via CI=1 or NEXT_PHASE=phase-production-build
|
|
37
|
+
*/
|
|
38
|
+
buildStep?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Custom fetch function for making HTTP requests.
|
|
41
|
+
* Useful for testing (e.g. resolving to a different IP).
|
|
42
|
+
* @default globalThis.fetch
|
|
43
|
+
*/
|
|
44
|
+
fetch?: typeof globalThis.fetch;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* A DataSource implementation that connects to flags.vercel.com.
|
|
48
|
+
*
|
|
49
|
+
* Behavior differs based on environment:
|
|
50
|
+
*
|
|
51
|
+
* **Build step** (CI=1 or Next.js build, or buildStep: true):
|
|
52
|
+
* - Uses datafile (if provided) or bundled definitions
|
|
53
|
+
* - No streaming or polling (avoids network during build)
|
|
54
|
+
*
|
|
55
|
+
* **Runtime** (default):
|
|
56
|
+
* - Tries stream first, then poll, then datafile, then bundled
|
|
57
|
+
* - Stream and polling never run simultaneously
|
|
58
|
+
* - If stream reconnects while polling → stop polling
|
|
59
|
+
* - If stream disconnects → start polling (if enabled)
|
|
60
|
+
*/
|
|
61
|
+
declare class FlagNetworkDataSource implements DataSource {
|
|
62
|
+
private options;
|
|
63
|
+
private host;
|
|
64
|
+
private data;
|
|
65
|
+
private bundledDefinitionsPromise;
|
|
66
|
+
private streamAbortController;
|
|
67
|
+
private streamPromise;
|
|
68
|
+
private isStreamConnected;
|
|
69
|
+
private hasWarnedAboutStaleData;
|
|
70
|
+
private pollingIntervalId;
|
|
71
|
+
private pollingAbortController;
|
|
72
|
+
private usageTracker;
|
|
73
|
+
private isFirstGetData;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new FlagNetworkDataSource instance.
|
|
76
|
+
*/
|
|
77
|
+
constructor(options: FlagNetworkDataSourceOptions);
|
|
78
|
+
/**
|
|
79
|
+
* Initializes the data source.
|
|
80
|
+
*
|
|
81
|
+
* Build step: datafile → bundled → fetch
|
|
82
|
+
* Runtime: stream → poll → datafile → bundled
|
|
83
|
+
*/
|
|
84
|
+
initialize(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Reads the current datafile with metrics.
|
|
87
|
+
*/
|
|
88
|
+
read(): Promise<Datafile>;
|
|
89
|
+
/**
|
|
90
|
+
* Shuts down the data source and releases resources.
|
|
91
|
+
*/
|
|
92
|
+
shutdown(): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the datafile with metrics.
|
|
95
|
+
*
|
|
96
|
+
* During builds this will read from the bundled file if available.
|
|
97
|
+
*
|
|
98
|
+
* This method never opens a streaming connection, but will read from
|
|
99
|
+
* the stream if it is already open. Otherwise it fetches over the network.
|
|
100
|
+
*/
|
|
101
|
+
getDatafile(): Promise<Datafile>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns the bundled fallback datafile.
|
|
104
|
+
*/
|
|
105
|
+
getFallbackDatafile(): Promise<BundledDefinitions>;
|
|
106
|
+
/**
|
|
107
|
+
* Attempts to initialize via stream with timeout.
|
|
108
|
+
* Returns true if stream connected successfully within timeout.
|
|
109
|
+
*/
|
|
110
|
+
private tryInitializeStream;
|
|
111
|
+
/**
|
|
112
|
+
* Starts the stream connection with callbacks for data and disconnect.
|
|
113
|
+
*/
|
|
114
|
+
private startStream;
|
|
115
|
+
/**
|
|
116
|
+
* Stops the stream connection.
|
|
117
|
+
*/
|
|
118
|
+
private stopStream;
|
|
119
|
+
/**
|
|
120
|
+
* Attempts to initialize via polling with timeout.
|
|
121
|
+
* Returns true if first poll succeeded within timeout.
|
|
122
|
+
*/
|
|
123
|
+
private tryInitializePolling;
|
|
124
|
+
/**
|
|
125
|
+
* Starts polling (initial poll + interval).
|
|
126
|
+
*/
|
|
127
|
+
private startPolling;
|
|
128
|
+
/**
|
|
129
|
+
* Starts the polling interval (without initial poll).
|
|
130
|
+
*/
|
|
131
|
+
private startPollingInterval;
|
|
132
|
+
/**
|
|
133
|
+
* Stops polling.
|
|
134
|
+
*/
|
|
135
|
+
private stopPolling;
|
|
136
|
+
/**
|
|
137
|
+
* Performs a single poll request.
|
|
138
|
+
*/
|
|
139
|
+
private performPoll;
|
|
140
|
+
/**
|
|
141
|
+
* Starts background updates (stream or polling) without blocking.
|
|
142
|
+
* Used when we already have data from provided datafile.
|
|
143
|
+
*/
|
|
144
|
+
private startBackgroundUpdates;
|
|
145
|
+
/**
|
|
146
|
+
* Initializes data for build step environments.
|
|
147
|
+
*/
|
|
148
|
+
private initializeForBuildStep;
|
|
149
|
+
/**
|
|
150
|
+
* Retrieves data during build steps.
|
|
151
|
+
*/
|
|
152
|
+
private getDataForBuildStep;
|
|
153
|
+
/**
|
|
154
|
+
* Returns data from the in-memory cache.
|
|
155
|
+
*/
|
|
156
|
+
private getDataFromCache;
|
|
157
|
+
/**
|
|
158
|
+
* Retrieves data using the fallback chain.
|
|
159
|
+
*/
|
|
160
|
+
private getDataWithFallbacks;
|
|
161
|
+
/**
|
|
162
|
+
* Initializes from bundled definitions.
|
|
163
|
+
*/
|
|
164
|
+
private initializeFromBundled;
|
|
165
|
+
/**
|
|
166
|
+
* Parses a configUpdatedAt value (number or string) into a numeric timestamp.
|
|
167
|
+
* Returns undefined if the value is missing or cannot be parsed.
|
|
168
|
+
*/
|
|
169
|
+
private static parseConfigUpdatedAt;
|
|
170
|
+
/**
|
|
171
|
+
* Checks if the incoming data is newer than the current in-memory data.
|
|
172
|
+
* Returns true if the update should proceed, false if it should be skipped.
|
|
173
|
+
*
|
|
174
|
+
* Always accepts the update if:
|
|
175
|
+
* - There is no current data
|
|
176
|
+
* - The current data has no configUpdatedAt
|
|
177
|
+
* - The incoming data has no configUpdatedAt
|
|
178
|
+
*
|
|
179
|
+
* Skips the update only when both have configUpdatedAt and incoming is older.
|
|
180
|
+
*/
|
|
181
|
+
private isNewerData;
|
|
182
|
+
/**
|
|
183
|
+
* Logs a warning if returning cached data while stream is disconnected.
|
|
184
|
+
*/
|
|
185
|
+
private warnIfDisconnected;
|
|
186
|
+
/**
|
|
187
|
+
* Tracks a read operation for usage analytics.
|
|
188
|
+
*/
|
|
189
|
+
private trackRead;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Factory functions for exports of index.default.ts and index.next-js.ts
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Options for createClient
|
|
198
|
+
*/
|
|
199
|
+
type CreateClientOptions = Omit<FlagNetworkDataSourceOptions, 'sdkKey'>;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Error thrown when the fallback definitions file does not exist.
|
|
203
|
+
* This typically means the "vercel-flags prepare" command was not run before building.
|
|
204
|
+
*/
|
|
205
|
+
declare class FallbackNotFoundError extends Error {
|
|
206
|
+
constructor();
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Error thrown when the fallback definitions file exists but has no entry for the SDK key.
|
|
210
|
+
* This means the SDK key was not included when running "vercel-flags prepare".
|
|
211
|
+
*/
|
|
212
|
+
declare class FallbackEntryNotFoundError extends Error {
|
|
213
|
+
constructor();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Evaluates a single feature flag.
|
|
218
|
+
*
|
|
219
|
+
* This function should never throw for expected errors, instead it returns
|
|
220
|
+
* { reason: Reason.ERROR, errorMessage: ... }.
|
|
221
|
+
*
|
|
222
|
+
* The function can however throw for situations which should not happen under
|
|
223
|
+
* normal circumstances, for example if the environment config is not found.
|
|
224
|
+
*/
|
|
225
|
+
declare function evaluate<T>(
|
|
226
|
+
/**
|
|
227
|
+
* The params used for the evaluation
|
|
228
|
+
*/
|
|
229
|
+
params: EvaluationParams<T>): EvaluationResult<T>;
|
|
230
|
+
|
|
231
|
+
declare const flagsClient: FlagsClient;
|
|
232
|
+
declare const resetDefaultFlagsClient: () => void;
|
|
233
|
+
declare const createClient: (sdkKeyOrConnectionString: string, options?: CreateClientOptions) => FlagsClient;
|
|
234
|
+
|
|
235
|
+
export { BundledDefinitions, type CreateClientOptions, Datafile, DatafileInput, EvaluationParams, EvaluationResult, FallbackEntryNotFoundError, FallbackNotFoundError, FlagNetworkDataSource, type FlagNetworkDataSourceOptions, FlagsClient, PollingOptions, StreamOptions, createClient, evaluate, flagsClient, resetDefaultFlagsClient };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FallbackEntryNotFoundError,
|
|
3
|
+
FallbackNotFoundError,
|
|
4
|
+
FlagNetworkDataSource,
|
|
5
|
+
ResolutionReason,
|
|
6
|
+
createClient,
|
|
7
|
+
evaluate,
|
|
8
|
+
flagsClient,
|
|
9
|
+
resetDefaultFlagsClient
|
|
10
|
+
} from "./chunk-UQEFJL4F.js";
|
|
11
|
+
export {
|
|
12
|
+
FallbackEntryNotFoundError,
|
|
13
|
+
FallbackNotFoundError,
|
|
14
|
+
FlagNetworkDataSource,
|
|
15
|
+
ResolutionReason as Reason,
|
|
16
|
+
createClient,
|
|
17
|
+
evaluate,
|
|
18
|
+
flagsClient,
|
|
19
|
+
resetDefaultFlagsClient
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.next-js.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { F as FlagsClient } from './types-508sZTBu.js';
|
|
2
|
+
import * as _openfeature_server_sdk from '@openfeature/server-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenFeature provider for default runtimes
|
|
6
|
+
*
|
|
7
|
+
* There is also openfeature.next-js.ts which targets Next.js specifically.
|
|
8
|
+
* If you update this file, please update openfeature.next-js.ts as well.
|
|
9
|
+
*
|
|
10
|
+
* Try keeping this file small. Export through openfeature.make.
|
|
11
|
+
*/
|
|
12
|
+
declare const VercelProvider: {
|
|
13
|
+
new (): {
|
|
14
|
+
readonly metadata: _openfeature_server_sdk.ProviderMetadata;
|
|
15
|
+
readonly runsOn: "server";
|
|
16
|
+
readonly client: FlagsClient;
|
|
17
|
+
initialize(context?: _openfeature_server_sdk.EvaluationContext): Promise<void>;
|
|
18
|
+
onClose(): Promise<void>;
|
|
19
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<boolean>>;
|
|
20
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<string>>;
|
|
21
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<number>>;
|
|
22
|
+
resolveObjectEvaluation<T extends _openfeature_server_sdk.JsonValue>(flagKey: string, defaultValue: T, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<T>>;
|
|
23
|
+
};
|
|
24
|
+
new (client: FlagsClient): {
|
|
25
|
+
readonly metadata: _openfeature_server_sdk.ProviderMetadata;
|
|
26
|
+
readonly runsOn: "server";
|
|
27
|
+
readonly client: FlagsClient;
|
|
28
|
+
initialize(context?: _openfeature_server_sdk.EvaluationContext): Promise<void>;
|
|
29
|
+
onClose(): Promise<void>;
|
|
30
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<boolean>>;
|
|
31
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<string>>;
|
|
32
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<number>>;
|
|
33
|
+
resolveObjectEvaluation<T extends _openfeature_server_sdk.JsonValue>(flagKey: string, defaultValue: T, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<T>>;
|
|
34
|
+
};
|
|
35
|
+
new (connectionString: string): {
|
|
36
|
+
readonly metadata: _openfeature_server_sdk.ProviderMetadata;
|
|
37
|
+
readonly runsOn: "server";
|
|
38
|
+
readonly client: FlagsClient;
|
|
39
|
+
initialize(context?: _openfeature_server_sdk.EvaluationContext): Promise<void>;
|
|
40
|
+
onClose(): Promise<void>;
|
|
41
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<boolean>>;
|
|
42
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<string>>;
|
|
43
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<number>>;
|
|
44
|
+
resolveObjectEvaluation<T extends _openfeature_server_sdk.JsonValue>(flagKey: string, defaultValue: T, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<T>>;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export { VercelProvider };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createClient,
|
|
3
|
+
flagsClient
|
|
4
|
+
} from "./chunk-7BUTND2Q.js";
|
|
5
|
+
|
|
6
|
+
// src/openfeature.make.ts
|
|
7
|
+
import {
|
|
8
|
+
ErrorCode,
|
|
9
|
+
StandardResolutionReasons
|
|
10
|
+
} from "@openfeature/server-sdk";
|
|
11
|
+
function mapReason(reason) {
|
|
12
|
+
switch (reason) {
|
|
13
|
+
case "error" /* ERROR */:
|
|
14
|
+
return StandardResolutionReasons.ERROR;
|
|
15
|
+
case "paused" /* PAUSED */:
|
|
16
|
+
return StandardResolutionReasons.STATIC;
|
|
17
|
+
case "fallthrough" /* FALLTHROUGH */:
|
|
18
|
+
return StandardResolutionReasons.DEFAULT;
|
|
19
|
+
case "target_match" /* TARGET_MATCH */:
|
|
20
|
+
case "rule_match" /* RULE_MATCH */:
|
|
21
|
+
return StandardResolutionReasons.TARGETING_MATCH;
|
|
22
|
+
default:
|
|
23
|
+
return StandardResolutionReasons.UNKNOWN;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function make(createClient2, defaultFlagsClient) {
|
|
27
|
+
return class VercelProvider {
|
|
28
|
+
metadata = {
|
|
29
|
+
name: "vercel-nodejs-provider"
|
|
30
|
+
};
|
|
31
|
+
runsOn = "server";
|
|
32
|
+
client;
|
|
33
|
+
constructor(clientOrConnectionString = defaultFlagsClient) {
|
|
34
|
+
if (typeof clientOrConnectionString === "string") {
|
|
35
|
+
this.client = createClient2(clientOrConnectionString);
|
|
36
|
+
} else {
|
|
37
|
+
this.client = clientOrConnectionString;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async initialize(context) {
|
|
41
|
+
await this.client.initialize();
|
|
42
|
+
}
|
|
43
|
+
async onClose() {
|
|
44
|
+
await this.client.shutdown();
|
|
45
|
+
}
|
|
46
|
+
async resolveBooleanEvaluation(flagKey, defaultValue, context) {
|
|
47
|
+
const result = await this.client.evaluate(
|
|
48
|
+
flagKey,
|
|
49
|
+
defaultValue,
|
|
50
|
+
context
|
|
51
|
+
);
|
|
52
|
+
if (result.reason === "error" /* ERROR */) {
|
|
53
|
+
return {
|
|
54
|
+
value: defaultValue,
|
|
55
|
+
reason: StandardResolutionReasons.ERROR,
|
|
56
|
+
errorCode: ErrorCode.GENERAL,
|
|
57
|
+
errorMessage: result.errorMessage
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (typeof result.value !== "boolean") {
|
|
61
|
+
return {
|
|
62
|
+
value: defaultValue,
|
|
63
|
+
reason: StandardResolutionReasons.ERROR,
|
|
64
|
+
errorCode: ErrorCode.TYPE_MISMATCH,
|
|
65
|
+
errorMessage: `Expected boolean value for flag "${flagKey}"`
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
value: result.value,
|
|
70
|
+
reason: mapReason(result.reason)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async resolveStringEvaluation(flagKey, defaultValue, context) {
|
|
74
|
+
const result = await this.client.evaluate(
|
|
75
|
+
flagKey,
|
|
76
|
+
defaultValue,
|
|
77
|
+
context
|
|
78
|
+
);
|
|
79
|
+
if (result.reason === "error" /* ERROR */) {
|
|
80
|
+
return {
|
|
81
|
+
value: defaultValue,
|
|
82
|
+
reason: StandardResolutionReasons.ERROR,
|
|
83
|
+
errorCode: ErrorCode.GENERAL,
|
|
84
|
+
errorMessage: result.errorMessage
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (typeof result.value !== "string") {
|
|
88
|
+
return {
|
|
89
|
+
value: defaultValue,
|
|
90
|
+
reason: StandardResolutionReasons.ERROR,
|
|
91
|
+
errorCode: ErrorCode.TYPE_MISMATCH,
|
|
92
|
+
errorMessage: `Expected string value for flag "${flagKey}"`
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
value: result.value,
|
|
97
|
+
reason: mapReason(result.reason),
|
|
98
|
+
errorMessage: result.errorMessage
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async resolveNumberEvaluation(flagKey, defaultValue, context) {
|
|
102
|
+
const result = await this.client.evaluate(
|
|
103
|
+
flagKey,
|
|
104
|
+
defaultValue,
|
|
105
|
+
context
|
|
106
|
+
);
|
|
107
|
+
if (result.reason === "error" /* ERROR */) {
|
|
108
|
+
return {
|
|
109
|
+
value: defaultValue,
|
|
110
|
+
reason: StandardResolutionReasons.ERROR,
|
|
111
|
+
errorCode: ErrorCode.GENERAL,
|
|
112
|
+
errorMessage: result.errorMessage
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (typeof result.value !== "number") {
|
|
116
|
+
return {
|
|
117
|
+
value: defaultValue,
|
|
118
|
+
reason: StandardResolutionReasons.ERROR,
|
|
119
|
+
errorCode: ErrorCode.TYPE_MISMATCH,
|
|
120
|
+
errorMessage: `Expected number value for flag "${flagKey}"`
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
value: result.value,
|
|
125
|
+
reason: mapReason(result.reason),
|
|
126
|
+
errorMessage: result.errorMessage
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
async resolveObjectEvaluation(flagKey, defaultValue, context) {
|
|
130
|
+
const result = await this.client.evaluate(
|
|
131
|
+
flagKey,
|
|
132
|
+
defaultValue,
|
|
133
|
+
context
|
|
134
|
+
);
|
|
135
|
+
if (result.reason === "error" /* ERROR */) {
|
|
136
|
+
return {
|
|
137
|
+
value: defaultValue,
|
|
138
|
+
reason: StandardResolutionReasons.ERROR,
|
|
139
|
+
errorCode: ErrorCode.GENERAL,
|
|
140
|
+
errorMessage: result.errorMessage
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
value: result.value,
|
|
145
|
+
reason: mapReason(result.reason),
|
|
146
|
+
errorMessage: result.errorMessage
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/openfeature.default.ts
|
|
153
|
+
var VercelProvider = make(createClient, flagsClient);
|
|
154
|
+
export {
|
|
155
|
+
VercelProvider
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=openfeature.default.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/openfeature.make.ts","../src/openfeature.default.ts"],"sourcesContent":["/**\n * OpenFeature provider for Next.js App Router\n *\n * There is also openfeature.default.ts which targets default runtimes.\n * If you update this file, please update openfeature.default.ts as well.\n *\n * This file should stay equivalent to openfeature.default.ts, except that it\n * imports from index.next-js to get cached functions.\n */\n\nimport {\n ErrorCode,\n type EvaluationContext,\n type JsonValue,\n type Provider,\n type ProviderMetadata,\n type ResolutionDetails,\n type ResolutionReason,\n StandardResolutionReasons,\n} from '@openfeature/server-sdk';\nimport { type FlagsClient, ResolutionReason as Reason } from './types';\n\nfunction mapReason(reason: Reason): ResolutionReason {\n switch (reason) {\n case Reason.ERROR:\n return StandardResolutionReasons.ERROR;\n case Reason.PAUSED:\n return StandardResolutionReasons.STATIC;\n case Reason.FALLTHROUGH:\n return StandardResolutionReasons.DEFAULT;\n case Reason.TARGET_MATCH:\n case Reason.RULE_MATCH:\n return StandardResolutionReasons.TARGETING_MATCH;\n default:\n return StandardResolutionReasons.UNKNOWN;\n }\n}\n\nexport function make(\n createClient: (sdkKeyOrConnectionString: string) => FlagsClient,\n defaultFlagsClient: FlagsClient,\n) {\n return class VercelProvider implements Provider {\n readonly metadata: ProviderMetadata = {\n name: 'vercel-nodejs-provider',\n } as const;\n\n readonly runsOn = 'server';\n readonly client: FlagsClient;\n\n constructor();\n constructor(client: FlagsClient);\n constructor(connectionString: string);\n constructor(\n clientOrConnectionString: FlagsClient | string = defaultFlagsClient,\n ) {\n if (typeof clientOrConnectionString === 'string') {\n this.client = createClient(clientOrConnectionString);\n } else {\n this.client = clientOrConnectionString;\n }\n }\n\n async initialize(context?: EvaluationContext): Promise<void> {\n await this.client.initialize();\n }\n\n async onClose() {\n await this.client.shutdown();\n }\n\n async resolveBooleanEvaluation(\n flagKey: string,\n defaultValue: boolean,\n context: EvaluationContext,\n ): Promise<ResolutionDetails<boolean>> {\n const result = await this.client.evaluate<boolean>(\n flagKey,\n defaultValue,\n context,\n );\n\n if (result.reason === Reason.ERROR) {\n return {\n value: defaultValue,\n reason: StandardResolutionReasons.ERROR,\n errorCode: ErrorCode.GENERAL,\n errorMessage: result.errorMessage,\n };\n }\n\n if (typeof result.value !== 'boolean') {\n return {\n value: defaultValue,\n reason: StandardResolutionReasons.ERROR,\n errorCode: ErrorCode.TYPE_MISMATCH,\n errorMessage: `Expected boolean value for flag \"${flagKey}\"`,\n };\n }\n\n return {\n value: result.value,\n reason: mapReason(result.reason),\n };\n }\n\n async resolveStringEvaluation(\n flagKey: string,\n defaultValue: string,\n context: EvaluationContext,\n ): Promise<ResolutionDetails<string>> {\n const result = await this.client.evaluate<string>(\n flagKey,\n defaultValue,\n context,\n );\n\n if (result.reason === Reason.ERROR) {\n return {\n value: defaultValue,\n reason: StandardResolutionReasons.ERROR,\n errorCode: ErrorCode.GENERAL,\n errorMessage: result.errorMessage,\n };\n }\n\n if (typeof result.value !== 'string') {\n return {\n value: defaultValue,\n reason: StandardResolutionReasons.ERROR,\n errorCode: ErrorCode.TYPE_MISMATCH,\n errorMessage: `Expected string value for flag \"${flagKey}\"`,\n };\n }\n\n return {\n value: result.value,\n reason: mapReason(result.reason),\n errorMessage: result.errorMessage,\n };\n }\n\n async resolveNumberEvaluation(\n flagKey: string,\n defaultValue: number,\n context: EvaluationContext,\n ): Promise<ResolutionDetails<number>> {\n const result = await this.client.evaluate<number>(\n flagKey,\n defaultValue,\n context,\n );\n\n if (result.reason === Reason.ERROR) {\n return {\n value: defaultValue,\n reason: StandardResolutionReasons.ERROR,\n errorCode: ErrorCode.GENERAL,\n errorMessage: result.errorMessage,\n };\n }\n\n if (typeof result.value !== 'number') {\n return {\n value: defaultValue,\n reason: StandardResolutionReasons.ERROR,\n errorCode: ErrorCode.TYPE_MISMATCH,\n errorMessage: `Expected number value for flag \"${flagKey}\"`,\n };\n }\n\n return {\n value: result.value,\n reason: mapReason(result.reason),\n errorMessage: result.errorMessage,\n };\n }\n\n async resolveObjectEvaluation<T extends JsonValue>(\n flagKey: string,\n defaultValue: T,\n context: EvaluationContext,\n ): Promise<ResolutionDetails<T>> {\n const result = await this.client.evaluate<T>(\n flagKey,\n defaultValue,\n context,\n );\n\n if (result.reason === Reason.ERROR) {\n return {\n value: defaultValue,\n reason: StandardResolutionReasons.ERROR,\n errorCode: ErrorCode.GENERAL,\n errorMessage: result.errorMessage,\n };\n }\n\n return {\n value: result.value,\n reason: mapReason(result.reason),\n errorMessage: result.errorMessage,\n };\n }\n };\n}\n","/**\n * OpenFeature provider for default runtimes\n *\n * There is also openfeature.next-js.ts which targets Next.js specifically.\n * If you update this file, please update openfeature.next-js.ts as well.\n *\n * Try keeping this file small. Export through openfeature.make.\n */\n\nimport { createClient, flagsClient } from './index.default';\nimport { make } from './openfeature.make';\n\nexport const VercelProvider = make(createClient, flagsClient);\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AAAA,QAC/B;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,UAAI,OAAO,gCAAyB;AAClC,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ,0BAA0B;AAAA,UAClC,WAAW,UAAU;AAAA,UACrB,cAAc,OAAO;AAAA,QACvB;AAAA,MACF;AAEA,aAAO;AAAA,QACL,OAAO,OAAO;AAAA,QACd,QAAQ,UAAU,OAAO,MAAM;AAAA,QAC/B,cAAc,OAAO;AAAA,MACvB;AAAA,IACF;AAAA,EACF;AACF;;;ACjMO,IAAM,iBAAiB,KAAK,cAAc,WAAW;","names":["createClient"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { F as FlagsClient } from './types-508sZTBu.js';
|
|
2
|
+
import * as _openfeature_server_sdk from '@openfeature/server-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OpenFeature provider for Next.js App Router
|
|
6
|
+
*
|
|
7
|
+
* There is also openfeature.default.ts which targets default runtimes.
|
|
8
|
+
* If you update this file, please update openfeature.default.ts as well.
|
|
9
|
+
*
|
|
10
|
+
* This file should stay equivalent to openfeature.default.ts, except that it
|
|
11
|
+
* imports from index.next-js to get cached functions.
|
|
12
|
+
*/
|
|
13
|
+
declare const VercelProvider: {
|
|
14
|
+
new (): {
|
|
15
|
+
readonly metadata: _openfeature_server_sdk.ProviderMetadata;
|
|
16
|
+
readonly runsOn: "server";
|
|
17
|
+
readonly client: FlagsClient;
|
|
18
|
+
initialize(context?: _openfeature_server_sdk.EvaluationContext): Promise<void>;
|
|
19
|
+
onClose(): Promise<void>;
|
|
20
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<boolean>>;
|
|
21
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<string>>;
|
|
22
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<number>>;
|
|
23
|
+
resolveObjectEvaluation<T extends _openfeature_server_sdk.JsonValue>(flagKey: string, defaultValue: T, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<T>>;
|
|
24
|
+
};
|
|
25
|
+
new (client: FlagsClient): {
|
|
26
|
+
readonly metadata: _openfeature_server_sdk.ProviderMetadata;
|
|
27
|
+
readonly runsOn: "server";
|
|
28
|
+
readonly client: FlagsClient;
|
|
29
|
+
initialize(context?: _openfeature_server_sdk.EvaluationContext): Promise<void>;
|
|
30
|
+
onClose(): Promise<void>;
|
|
31
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<boolean>>;
|
|
32
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<string>>;
|
|
33
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<number>>;
|
|
34
|
+
resolveObjectEvaluation<T extends _openfeature_server_sdk.JsonValue>(flagKey: string, defaultValue: T, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<T>>;
|
|
35
|
+
};
|
|
36
|
+
new (connectionString: string): {
|
|
37
|
+
readonly metadata: _openfeature_server_sdk.ProviderMetadata;
|
|
38
|
+
readonly runsOn: "server";
|
|
39
|
+
readonly client: FlagsClient;
|
|
40
|
+
initialize(context?: _openfeature_server_sdk.EvaluationContext): Promise<void>;
|
|
41
|
+
onClose(): Promise<void>;
|
|
42
|
+
resolveBooleanEvaluation(flagKey: string, defaultValue: boolean, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<boolean>>;
|
|
43
|
+
resolveStringEvaluation(flagKey: string, defaultValue: string, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<string>>;
|
|
44
|
+
resolveNumberEvaluation(flagKey: string, defaultValue: number, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<number>>;
|
|
45
|
+
resolveObjectEvaluation<T extends _openfeature_server_sdk.JsonValue>(flagKey: string, defaultValue: T, context: _openfeature_server_sdk.EvaluationContext): Promise<_openfeature_server_sdk.ResolutionDetails<T>>;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { VercelProvider };
|