flags 0.2.2 → 3.1.2

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +434 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +44 -93
  4. package/dist/analytics.cjs +7 -0
  5. package/dist/analytics.cjs.map +1 -0
  6. package/dist/analytics.d.cts +8 -0
  7. package/dist/analytics.d.ts +8 -0
  8. package/dist/analytics.js +7 -0
  9. package/dist/analytics.js.map +1 -0
  10. package/dist/chunk-2UDLZC33.js +9 -0
  11. package/dist/chunk-2UDLZC33.js.map +1 -0
  12. package/dist/chunk-7EGZDBDN.js +406 -0
  13. package/dist/chunk-7EGZDBDN.js.map +1 -0
  14. package/dist/chunk-AVMIIWOF.cjs +21 -0
  15. package/dist/chunk-AVMIIWOF.cjs.map +1 -0
  16. package/dist/chunk-IGXYQW6R.cjs +406 -0
  17. package/dist/chunk-IGXYQW6R.cjs.map +1 -0
  18. package/dist/chunk-MEG7RDX7.cjs +9 -0
  19. package/dist/chunk-MEG7RDX7.cjs.map +1 -0
  20. package/dist/chunk-ZNKTXALY.js +21 -0
  21. package/dist/chunk-ZNKTXALY.js.map +1 -0
  22. package/dist/index.cjs +25 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +89 -0
  25. package/dist/index.d.ts +89 -0
  26. package/dist/index.js +25 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/next.cjs +613 -0
  29. package/dist/next.cjs.map +1 -0
  30. package/dist/next.d.cts +191 -0
  31. package/dist/next.d.ts +191 -0
  32. package/dist/next.js +613 -0
  33. package/dist/next.js.map +1 -0
  34. package/dist/react.cjs +39 -0
  35. package/dist/react.cjs.map +1 -0
  36. package/dist/react.d.cts +20 -0
  37. package/dist/react.d.ts +20 -0
  38. package/dist/react.js +39 -0
  39. package/dist/react.js.map +1 -0
  40. package/dist/sveltekit.cjs +171 -0
  41. package/dist/sveltekit.cjs.map +1 -0
  42. package/dist/sveltekit.d.cts +42 -0
  43. package/dist/sveltekit.d.ts +42 -0
  44. package/dist/sveltekit.js +171 -0
  45. package/dist/sveltekit.js.map +1 -0
  46. package/dist/types-CGpl9epN.d.cts +237 -0
  47. package/dist/types-CGpl9epN.d.ts +237 -0
  48. package/package.json +112 -28
  49. package/LICENSE +0 -9
  50. package/dist/flags.cjs +0 -366
  51. package/dist/flags.cjs.map +0 -1
  52. package/dist/flags.d.cts +0 -84
  53. package/dist/flags.d.ts +0 -84
  54. package/dist/flags.js +0 -330
  55. package/dist/flags.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,434 @@
1
+ # @vercel/flags
2
+
3
+ ## 3.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - b79a84a: Pass the `defaultValue` to the adapter's decide function
8
+
9
+ ## 3.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 6955b68: emit reduced console info when falling back to defaultValue during development
14
+ - cf532da: Update package.json and tsup.config.js for flags package
15
+
16
+ ## 3.1.0
17
+
18
+ ### Minor Changes
19
+
20
+ - 76feb16: Add `mergeProviderData` function to `@vercel/flags`.
21
+
22
+ This function allows merging ProviderData from multiple sources.
23
+
24
+ This is handy when you declare feature flags in code, and want to extend those definitions with data loaded from your feature flag provider.
25
+
26
+ ```ts
27
+ import { verifyAccess, mergeProviderData, type ApiData } from '@vercel/flags';
28
+ import { getProviderData } from '@vercel/flags/next';
29
+ import { NextResponse, type NextRequest } from 'next/server';
30
+ import { getProviderData as getStatsigProviderData } from '@flags-sdk/statsig';
31
+ import * as flagsA from '../../../../flags-a'; // your feature flags file(s)
32
+ import * as flagsB from '../../../../flags-b'; // your feature flags file(s)
33
+
34
+ export async function GET(request: NextRequest) {
35
+ const access = await verifyAccess(request.headers.get('Authorization'));
36
+ if (!access) return NextResponse.json(null, { status: 401 });
37
+
38
+ const providerData = await mergeProviderData([
39
+ // expose flags declared in code first
40
+ getProviderData({ ...flagsA, ...flagsB }),
41
+ // then enhance them with metadata from your flag provider
42
+ getStatsigProviderData({ consoleApiKey: '', projectId: '' }),
43
+ ]);
44
+
45
+ return NextResponse.json<ApiData>(providerData);
46
+ }
47
+ ```
48
+
49
+ ### Patch Changes
50
+
51
+ - 2713ea7: Handle `undefined` values
52
+
53
+ - fix: Fall back to `defaultValue` when a feature flag returns `undefined`
54
+ - fix: Throw error when a flag resolves to `undefined` and no `defaultValue` is present
55
+
56
+ The value `undefined` can not be serialized so feature flags should never resolve to `undefined`. Use `null` instead.
57
+
58
+ Fix exports
59
+
60
+ - fix: Export `Identify` and `Decide` types
61
+
62
+ ## 3.0.2
63
+
64
+ ### Patch Changes
65
+
66
+ - 708d5e2: generatePermutations: infer options of boolean flags
67
+
68
+ ## 3.0.1
69
+
70
+ ### Patch Changes
71
+
72
+ - 7e21d4f: add metadata to package.json
73
+
74
+ ## 3.0.0
75
+
76
+ ### Major Changes
77
+
78
+ - db89f0d: - **BREAKING CHANGE** removed all `unstable_` prefixes, e.g. `unstable_flag` is now `flag`
79
+
80
+ - **BREAKING CHANGE** removed `getPrecomputationContext`, use `dedupe` instead (see below)
81
+ - **BREAKING CHANGE** moved all provider functions to dedicated packages
82
+ - `@vercel/flags/providers/launchdarkly` → `@flags-sdk/launchdarkly`
83
+ - `@vercel/flags/providers/statsig` → `@flags-sdk/statsig`
84
+ - `@vercel/flags/providers/split` → `@flags-sdk/split`
85
+ - `@vercel/flags/providers/hypertune` → `@flags-sdk/hypertune`
86
+ - `@vercel/flags/providers/optimizely` → `@flags-sdk/optimizely`
87
+ - `@vercel/flags/providers/happykit` → `@flags-sdk/happykit`
88
+ - **BREAKING CHANGE** changed `.run({})` behavior
89
+
90
+ See [flags-sdk.com](https://flags-sdk.com/) for the latest APIs.
91
+
92
+ - db89f0d: remove unstable\_ prefixes
93
+
94
+ ### Minor Changes
95
+
96
+ - db89f0d: **@vercel/flags/next: Added a `dedupe` function**
97
+
98
+ `dedupe` is a middleware-friendly version of `React.cache`. It allows ensuring a function only ever runs once per request.
99
+
100
+ ```ts
101
+ import { dedupe } from '@vercel/flags/next';
102
+
103
+ let i = 0;
104
+ const runOnce = dedupe(async () => {
105
+ return i++;
106
+ });
107
+
108
+ await runOnce(); // returns 0
109
+ await runOnce(); // still returns 0
110
+ ```
111
+
112
+ This function is useful when you want to deduplicate work within each feature flag's `decide` function. For example if multiple flags need to check auth you can dedupe the auth function so it only runs once per request.
113
+
114
+ `dedupe` is also useful to optimistically generate a random visitor id to be set in a cookie, while also allowing each feature flag to access the id. You can call a dedupe'd function to generate the random id within your Edge Middleware and also within your feature flag's `decide` functions. The function will return a consistent id.
115
+
116
+ ```ts
117
+ import { nanoid } from 'nanoid';
118
+ import { cookies, headers } from 'next/headers';
119
+ import { dedupe } from '@vercel/flags/next';
120
+
121
+ /**
122
+ * Reads the visitor id from a cookie or returns a new visitor id
123
+ */
124
+ export const getOrGenerateVisitorId = dedupe(
125
+ async (): Promise<{ value: string; fresh: boolean }> => {
126
+ const visitorIdCookie = (await cookies()).get('visitor-id')?.value;
127
+
128
+ return visitorIdCookie
129
+ ? { value: visitorIdCookie, fresh: false }
130
+ : { value: nanoid(), fresh: true };
131
+ },
132
+ );
133
+ ```
134
+
135
+ > Note: "once per request" is an imprecise description. A `dedupe`d function actually runs once per request, per compute instance. If a dedupe'd function is used in Edge Middleware and in a React Server Component it will run twice, as there are two separate compute instances handling this request.
136
+
137
+ > Note: This function acts as a sort of polyfill until similar functionality lands in Next.js directly.
138
+
139
+ ## 2.7.0
140
+
141
+ ### Minor Changes
142
+
143
+ - fb50709: Adds support for using feature flags in Pages Router.
144
+
145
+ The same feature flag declared for App Router can now also be used in Pages Router. Feature flags need to be used server-side.
146
+
147
+ Note that your implementation of the actual feature flag needs to be compatible with Pages Router if you plan on using it inside of Pages Router. This means you can not call functions like `headers()` and `cookies()` which are not available in Pages Router. You can instead rely on the `headers` and `cookies` arguments passed to your `decide` function as `decide({ headers, cookies })`.
148
+
149
+ **Dynamic usage example**
150
+
151
+ ```ts
152
+ export async function getServerSideProps({ req }) {
153
+ const showFreeDeliveryBanner = await showFreeDeliveryBannerFlag(req);
154
+ return { props: { showFreeDeliveryBanner } };
155
+ }
156
+ ```
157
+
158
+ **Precomputed usage example**
159
+
160
+ ```ts
161
+ import { bannerFlags, showFreeDeliveryBannerFlag } from './flags';
162
+ import type {
163
+ GetStaticPaths,
164
+ GetStaticProps,
165
+ InferGetStaticPropsType,
166
+ } from 'next';
167
+ import { unstable_generatePermutations as generatePermutations } from '@vercel/flags/next';
168
+
169
+ export const getStaticPaths = (async () => {
170
+ const codes = await generatePermutations(bannerFlags);
171
+
172
+ return {
173
+ paths: codes.map((code) => ({ params: { code } })),
174
+ fallback: 'blocking',
175
+ };
176
+ }) satisfies GetStaticPaths;
177
+
178
+ export const getStaticProps = (async (context) => {
179
+ const showFreeDeliveryBanner = await showFreeDeliveryBannerFlag(
180
+ context.params!.code as string,
181
+ bannerFlags,
182
+ );
183
+
184
+ return { props: { showFreeDeliveryBanner } };
185
+ }) satisfies GetStaticProps<{ showFreeDeliveryBanner: boolean }>;
186
+ ```
187
+
188
+ - 87503b6: Return `createdAt` and `updatedAt` as part of the provider data for those that support it
189
+
190
+ ## 2.6.3
191
+
192
+ ### Patch Changes
193
+
194
+ - 69f8df0: use defaultValue when an async decide function throws
195
+ - 65d3d73: add MIT license
196
+
197
+ ## 2.6.2
198
+
199
+ ### Patch Changes
200
+
201
+ - 80e0737: Add Next.js 15 compatibility.
202
+
203
+ Uses the async versions of `headers` and `cookies` to avoid warnings during development.
204
+
205
+ ## 2.6.1
206
+
207
+ ### Patch Changes
208
+
209
+ - 9c379a8: add pagination to LaunchDarkly provider
210
+
211
+ ## 2.6.0
212
+
213
+ ### Minor Changes
214
+
215
+ - 7b9aa17: evaluate flags once per request only by reusing the result
216
+ - b049c26: add SvelteKit support
217
+
218
+ ### Patch Changes
219
+
220
+ - c12f4d4: Deprecates `FlagsReporter` and `injectFlags`.
221
+
222
+ Web Analytics now automatically detects flags present in the DOM, so these are no longer necessary.
223
+
224
+ You can safely remove `FlagsReporter` and any calls to `injectFlags`.
225
+
226
+ - 1be4799: add no-store to LaunchDarkly provider
227
+
228
+ ## 2.5.1
229
+
230
+ ### Patch Changes
231
+
232
+ - 3a68cf7: Simplify middleware usage
233
+
234
+ BREAKING CHANGE: `unstable_precompute` now returns code directly
235
+
236
+ **Before**
237
+
238
+ ```ts
239
+ const values = await unstable_precompute(precomputeFlags, context);
240
+ const code = await unstable_serialize(precomputeFlags, values);
241
+ ```
242
+
243
+ **After**
244
+
245
+ This can now be done in a single function call.
246
+
247
+ ```ts
248
+ const code = await unstable_precompute(precomputeFlags, context);
249
+ ```
250
+
251
+ **Other notes**
252
+
253
+ `unstable_precompute` conceptually calls `unstable_evaluate` and `unstable_serialize` to generate the code.
254
+
255
+ This can also be done manually if you need access to `values`:
256
+
257
+ ```ts
258
+ const values = await unstable_evaluate(precomputeFlags, context);
259
+ const code = await unstable_serialize(precomputeFlags, values);
260
+ ```
261
+
262
+ It's also possible to get the value of a specific flag in middleware based on the precomputation:
263
+
264
+ ```ts
265
+ // flags.ts
266
+ export const showBanner = flag({
267
+ /* ... */
268
+ });
269
+ export const precomputeFlags = [showBanner /* ... */];
270
+
271
+ // middleware.ts
272
+ const code = await unstable_precompute(precomputeFlags, context);
273
+ const banner = showBanner(code, precomputeFlags);
274
+ ```
275
+
276
+ ## 2.5.0
277
+
278
+ ### Minor Changes
279
+
280
+ - 1003c29: add experimental `@vercel/flags/next` pattern [for working with feature flags in Next.js](https://vercel.com/docs/workflow-collaboration/feature-flags/flags-pattern-nextjs)
281
+
282
+ ## 2.4.0
283
+
284
+ ### Minor Changes
285
+
286
+ - c132300: Add `reportValue` function to report resolved flags
287
+ - 5911721: add HappyKit provider
288
+ - bf47adb: Provide a the `unstable_getFlagsProps` and `unstable_setGlobalFlagsAnalyticsKeys` functions that can be used to integrate with Vercel Analytics
289
+
290
+ ## 2.3.0
291
+
292
+ ### Minor Changes
293
+
294
+ - be714bd: add hypertune provider
295
+
296
+ ## 2.2.1
297
+
298
+ ### Patch Changes
299
+
300
+ - 6f401cc: update README
301
+
302
+ ## 2.2.0
303
+
304
+ ### Minor Changes
305
+
306
+ - a6883ad: Add Optimizely provider
307
+ - af787a9: Include Experiments from Statsig in `getStatsigData`
308
+
309
+ ### Patch Changes
310
+
311
+ - ae3f59c: Fix pagination for Statsig provider in `getStatsigData`
312
+
313
+ ## 2.1.2
314
+
315
+ ### Patch Changes
316
+
317
+ - b22ab52: support undefined as authHeader in verifyAccess for Pages Router compatibility
318
+ - 155d5ac: make overrideEncryptionMode optional in ApiData type
319
+
320
+ ## 2.1.1
321
+
322
+ ### Patch Changes
323
+
324
+ - 6b79659: expose ApiData type
325
+
326
+ ## 2.1.0
327
+
328
+ ### Minor Changes
329
+
330
+ - abae5af: Add verifyAccess to allow skipping encryption on the .well-known/vercel/flags endpoint
331
+
332
+ ## 2.0.0
333
+
334
+ ### Major Changes
335
+
336
+ - 59befe1: Unify `encrypt` and `decrypt` functions
337
+
338
+ BREAKING CHANGE
339
+ Replace the existing calls to any encrypt* or decrypt* functions like `encryptApiData`, `encryptOverrides`, `encryptValues` or `decryptApiData`, `decryptOverrides`, `decryptValues` with `encrypt` or `decrypt`
340
+
341
+ ## 1.1.2
342
+
343
+ ### Patch Changes
344
+
345
+ - 9ff283b: Fix auto-import showing `@vercel/flags/*` as option
346
+
347
+ ## 1.1.1
348
+
349
+ ### Patch Changes
350
+
351
+ - 80a1acc: Fix type export for providers
352
+
353
+ ## 1.1.0
354
+
355
+ ### Minor Changes
356
+
357
+ - 1f4fb18: Add Statsig and Split providers and update exports in package.json
358
+
359
+ ## 1.0.0
360
+
361
+ ### Major Changes
362
+
363
+ - c1e29ea: BREAKING CHANGE: `VERCEL_FLAGS_SECRET` env var has been renamed to `FLAGS_SECRET`
364
+
365
+ - Rename your `VERCEL_FLAGS_SECRET` environment variable to `FLAGS_SECRET` in your project settings on vercel.com
366
+ - Pull down the latest environment variables using `vercel env pull .env.local`
367
+
368
+ ## 0.2.1
369
+
370
+ ### Patch Changes
371
+
372
+ - 794b711: prevent xss
373
+
374
+ ## 0.2.0
375
+
376
+ ### Minor Changes
377
+
378
+ - 11a4bb6: add LaunchDarkly provider
379
+
380
+ ## 0.1.9
381
+
382
+ ### Patch Changes
383
+
384
+ - 1808b9c: fix auto-import in vs code defaulting to wrong path
385
+
386
+ ## 0.1.8
387
+
388
+ ### Patch Changes
389
+
390
+ - 91f801d: add JSDoc to `FlagDefinitionsType`, `FlagValuesType` and `FlagOverridesType`
391
+
392
+ ## 0.1.7
393
+
394
+ ### Patch Changes
395
+
396
+ - 1dbfd2c: add jsdoc to origin
397
+
398
+ ## 0.1.6
399
+
400
+ ### Patch Changes
401
+
402
+ - fa6a6d1: rename types to end with \*Types to avoid clash with component names
403
+
404
+ ## 0.1.5
405
+
406
+ ### Patch Changes
407
+
408
+ - 0e97393: omit src folder from package
409
+
410
+ ## 0.1.4
411
+
412
+ ### Patch Changes
413
+
414
+ - fe169df: change README wording
415
+
416
+ ## 0.1.3
417
+
418
+ ### Patch Changes
419
+
420
+ - effd1f6: replace url with origin in FlagDefinition type
421
+
422
+ ## 0.1.2
423
+
424
+ ### Patch Changes
425
+
426
+ - a4ee199: add main export
427
+ - 1a97981: rename data-variant-values to data-variant-state
428
+
429
+ ## 0.1.1
430
+
431
+ ### Patch Changes
432
+
433
+ - 446f640: rename types
434
+ - c1d2bee: fix return value of decryptOverrides
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Vercel, Inc.
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,122 +1,73 @@
1
- # Node-Flags
1
+ ![hero illustration](./assets/hero-dark.png)
2
2
 
3
- A flexible and easy-to-use command-line flag parsing library for Node.js applications.
3
+ # Flags SDK
4
4
 
5
- [![npm version](https://badge.fury.io/js/flags.svg)](https://badge.fury.io/js/flags)
6
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ The feature flags toolkit for Next.js and SvelteKit.
7
6
 
8
- ## Features
7
+ From the creators of Next.js, the Flags SDK is a free open-source library that gives you the tools you need to use feature flags in Next.js and SvelteKit applications.
9
8
 
10
- - Define flags across multiple files
11
- - Support for various data types (string, boolean, integer, number, string list, multi-string)
12
- - Easy-to-use API for defining and accessing flags
13
- - Customizable flag validation
14
- - Built-in help text generation
9
+ - Works with any flag provider, custom setups or no flag provider at all
10
+ - Compatible with App Router, Pages Router, and Edge Middleware
11
+ - Built for feature flags and experimentation
12
+
13
+ See [flags-sdk.dev](https://flags-sdk.dev/) for full docs and examples.
15
14
 
16
15
  ## Installation
17
16
 
18
- Install using your favorite package manager:
17
+ Install the package using your package manager:
19
18
 
20
- ```bash
19
+ ```sh
21
20
  npm install flags
22
- # or
23
- yarn add flags
24
- # or
25
- pnpm add flags
26
21
  ```
27
22
 
28
- ## Usage
29
-
30
- Here's a quick example of how to use Node-Flags:
31
-
32
- ```javascript
33
- import * as flags from "flags";
23
+ ## Setup
34
24
 
35
- // Define flags
36
- flags.defineString("name", "Anonymous", "Your name");
37
- flags.defineInteger("age", 21, "Your age in years");
38
- flags.defineNumber("height", 1.8, "Your height in meters");
39
- flags.defineStringList("pets", [], "List of your pets");
40
- flags.defineMultiString("hobby", [], "Your hobbies");
25
+ Create an environment variable called `FLAGS_SECRET`.
41
26
 
42
- // Parse command-line arguments
43
- flags.parse();
27
+ The `FLAGS_SECRET` value must have a specific length (32 random bytes encoded in base64) to work as an encryption key. Create one using node:
44
28
 
45
- // Access flag values
46
- const info = [
47
- `Name: ${flags.get("name")}`,
48
- `Age: ${flags.get("age")}`,
49
- `Height: ${flags.get("height")}m`,
50
- `Pets: ${flags.get("pets").join(", ")}`,
51
- `Hobbies:\n ${flags.get("hobby").join("\n ")}`,
52
- ];
53
-
54
- console.log(info.join("\n"));
29
+ ```sh
30
+ node -e "console.log(crypto.randomBytes(32).toString('base64url'))"
55
31
  ```
56
32
 
57
- Run your script with flags:
58
-
59
- ```bash
60
- node example.js --name="John Doe" --age=30 --height=1.75 --pets=dog,cat --hobby=reading --hobby=gaming
61
- ```
33
+ This secret is required to use the SDK. It is used to read overrides and to encrypt flag values in case they are sent to the client and should stay secret.
62
34
 
63
- ## Defining Flags
64
-
65
- Node-Flags provides several methods to define flags:
66
-
67
- - `defineString(name, defaultValue, description)`
68
- - `defineBoolean(name, defaultValue, description)`
69
- - `defineInteger(name, defaultValue, description)`
70
- - `defineNumber(name, defaultValue, description)`
71
- - `defineStringList(name, defaultValue, description)`
72
- - `defineMultiString(name, defaultValue, description)`
73
-
74
- Each method returns a `Flag` object that allows further configuration:
75
-
76
- ```javascript
77
- flags
78
- .defineString("api-key")
79
- .setDefault("your-default-key")
80
- .setDescription("API key for authentication")
81
- .setValidator((value) => {
82
- if (value.length < 10) {
83
- throw new Error("API key must be at least 10 characters long");
84
- }
85
- })
86
- .setSecret(true);
87
- ```
88
-
89
- ## Passing Flags
90
-
91
- - Use double dashes for flag names: `--flagname`
92
- - Separate values with an equal sign or space: `--flagname=value` or `--flagname value`
93
- - Quote complex string values: `--message="Hello, World!"`
94
- - Use `--` to separate flags from additional arguments: `--flag1 value1 -- arg1 arg2`
35
+ ## Usage
95
36
 
96
- ## Querying Flag Values
37
+ Create a file called flags.ts in your project and declare your first feature flag there:
97
38
 
98
- Access flag values using `flags.get(flagName)` or `flags.FLAGS.flagName.get()`.
39
+ ```ts
40
+ // app/flags.tsx
41
+ import { flag } from 'flags/next';
99
42
 
100
- Flag objects also provide properties like `name`, `defaultValue`, `currentValue`, and `isSet`.
43
+ export const exampleFlag = flag<boolean>({
44
+ key: 'example-flag',
45
+ decide() {
46
+ return true;
47
+ },
48
+ });
49
+ ```
101
50
 
102
- ## Help Text
51
+ Call your feature flag in a React Server Component:
103
52
 
104
- Node-Flags automatically generates help text. Access it by running your script with the `--help` flag.
53
+ ```tsx
54
+ // app/page.tsx
55
+ import { exampleFlag } from './flags';
105
56
 
106
- ## Testing
57
+ export default async function Page() {
58
+ const example = await exampleFlag();
59
+ return <div>{example ? 'Flag is on' : 'Flag is off'}</div>;
60
+ }
61
+ ```
107
62
 
108
- For testing, you can pass predefined arguments to `flags.parse()`:
63
+ Feature Flags can also be called in Edge Middleware and API Routes.
109
64
 
110
- ```javascript
111
- flags.parse(["--flag1", "--noflag2", "--flag3=value"]);
112
- ```
65
+ ## Adapters
113
66
 
114
- Reset flags between test cases:
67
+ The Flags SDK has adapters for popular feature flag providers including LaunchDarkly, Optimizely, and Statsig.
115
68
 
116
- ```javascript
117
- flags.reset();
118
- ```
69
+ ## Documentation
119
70
 
120
- ## License
71
+ There is a lot more to the Flags SDK than shown in the example above.
121
72
 
122
- This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
73
+ See the full documentation and examples on [flags-sdk.dev](https://flags-sdk.dev/).
@@ -0,0 +1,7 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/analytics.ts
2
+ var injectFlags = (_params) => {
3
+ };
4
+
5
+
6
+ exports.injectFlags = injectFlags;
7
+ //# sourceMappingURL=analytics.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/analytics.ts"],"names":[],"mappings":";AAGO,IAAM,cAAc,CACzB,YACS;AAAC","sourcesContent":["/**\n * @deprecated It is no longer necessary to call this function. Web Analytics now automatically detects flags present in the DOM.\n */\nexport const injectFlags = (\n _params: { keys?: string[] } | undefined,\n): void => {};\n"]}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @deprecated It is no longer necessary to call this function. Web Analytics now automatically detects flags present in the DOM.
3
+ */
4
+ declare const injectFlags: (_params: {
5
+ keys?: string[];
6
+ } | undefined) => void;
7
+
8
+ export { injectFlags };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @deprecated It is no longer necessary to call this function. Web Analytics now automatically detects flags present in the DOM.
3
+ */
4
+ declare const injectFlags: (_params: {
5
+ keys?: string[];
6
+ } | undefined) => void;
7
+
8
+ export { injectFlags };
@@ -0,0 +1,7 @@
1
+ // src/analytics.ts
2
+ var injectFlags = (_params) => {
3
+ };
4
+ export {
5
+ injectFlags
6
+ };
7
+ //# sourceMappingURL=analytics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/analytics.ts"],"sourcesContent":["/**\n * @deprecated It is no longer necessary to call this function. Web Analytics now automatically detects flags present in the DOM.\n */\nexport const injectFlags = (\n _params: { keys?: string[] } | undefined,\n): void => {};\n"],"mappings":";AAGO,IAAM,cAAc,CACzB,YACS;AAAC;","names":[]}
@@ -0,0 +1,9 @@
1
+ // src/lib/safe-json-stringify.ts
2
+ function safeJsonStringify(value, replacer, space) {
3
+ return JSON.stringify(value, replacer, space).replace(/</g, "\\u003c");
4
+ }
5
+
6
+ export {
7
+ safeJsonStringify
8
+ };
9
+ //# sourceMappingURL=chunk-2UDLZC33.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/safe-json-stringify.ts"],"sourcesContent":["/**\n * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.\n *\n * This function is just like JSON.stringify but also escapes the resulting string to prevent XSS.\n *\n * @see https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss\n * @param value A JavaScript value, usually an object or array, to be converted.\n * @param replacer A function that transforms the results.\n * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.\n */\nexport function safeJsonStringify(\n value: any,\n replacer?: (this: any, key: string, value: any) => any,\n space?: string | number,\n): string;\n/**\n * Converts a JavaScript value to a JavaScript Object Notation (JSON) string.\n *\n * This function is just like JSON.stringify but also escapes the resulting string to prevent XSS.\n *\n * @see https://pragmaticwebsecurity.com/articles/spasecurity/json-stringify-xss\n * @param value A JavaScript value, usually an object or array, to be converted.\n * @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.\n * @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.\n */\nexport function safeJsonStringify(\n value: any,\n replacer?: (number | string)[] | null,\n space?: string | number,\n): string;\n\nexport function safeJsonStringify(\n value: any,\n replacer: any,\n space: any,\n): string {\n return JSON.stringify(value, replacer, space).replace(/</g, '\\\\u003c');\n}\n"],"mappings":";AA+BO,SAAS,kBACd,OACA,UACA,OACQ;AACR,SAAO,KAAK,UAAU,OAAO,UAAU,KAAK,EAAE,QAAQ,MAAM,SAAS;AACvE;","names":[]}