flags 0.2.1 → 3.1.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.
Files changed (55) hide show
  1. package/CHANGELOG.md +428 -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-AVMIIWOF.cjs +21 -0
  13. package/dist/chunk-AVMIIWOF.cjs.map +1 -0
  14. package/dist/chunk-D2GBVCQQ.cjs +406 -0
  15. package/dist/chunk-D2GBVCQQ.cjs.map +1 -0
  16. package/dist/chunk-MEG7RDX7.cjs +9 -0
  17. package/dist/chunk-MEG7RDX7.cjs.map +1 -0
  18. package/dist/chunk-OQHOV3IB.js +406 -0
  19. package/dist/chunk-OQHOV3IB.js.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 +611 -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 +611 -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-swW0-Ony.d.cts +236 -0
  47. package/dist/types-swW0-Ony.d.ts +236 -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,428 @@
1
+ # @vercel/flags
2
+
3
+ ## 3.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 6955b68: emit reduced console info when falling back to defaultValue during development
8
+ - cf532da: Update package.json and tsup.config.js for flags package
9
+
10
+ ## 3.1.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 76feb16: Add `mergeProviderData` function to `@vercel/flags`.
15
+
16
+ This function allows merging ProviderData from multiple sources.
17
+
18
+ This is handy when you declare feature flags in code, and want to extend those definitions with data loaded from your feature flag provider.
19
+
20
+ ```ts
21
+ import { verifyAccess, mergeProviderData, type ApiData } from '@vercel/flags';
22
+ import { getProviderData } from '@vercel/flags/next';
23
+ import { NextResponse, type NextRequest } from 'next/server';
24
+ import { getProviderData as getStatsigProviderData } from '@flags-sdk/statsig';
25
+ import * as flagsA from '../../../../flags-a'; // your feature flags file(s)
26
+ import * as flagsB from '../../../../flags-b'; // your feature flags file(s)
27
+
28
+ export async function GET(request: NextRequest) {
29
+ const access = await verifyAccess(request.headers.get('Authorization'));
30
+ if (!access) return NextResponse.json(null, { status: 401 });
31
+
32
+ const providerData = await mergeProviderData([
33
+ // expose flags declared in code first
34
+ getProviderData({ ...flagsA, ...flagsB }),
35
+ // then enhance them with metadata from your flag provider
36
+ getStatsigProviderData({ consoleApiKey: '', projectId: '' }),
37
+ ]);
38
+
39
+ return NextResponse.json<ApiData>(providerData);
40
+ }
41
+ ```
42
+
43
+ ### Patch Changes
44
+
45
+ - 2713ea7: Handle `undefined` values
46
+
47
+ - fix: Fall back to `defaultValue` when a feature flag returns `undefined`
48
+ - fix: Throw error when a flag resolves to `undefined` and no `defaultValue` is present
49
+
50
+ The value `undefined` can not be serialized so feature flags should never resolve to `undefined`. Use `null` instead.
51
+
52
+ Fix exports
53
+
54
+ - fix: Export `Identify` and `Decide` types
55
+
56
+ ## 3.0.2
57
+
58
+ ### Patch Changes
59
+
60
+ - 708d5e2: generatePermutations: infer options of boolean flags
61
+
62
+ ## 3.0.1
63
+
64
+ ### Patch Changes
65
+
66
+ - 7e21d4f: add metadata to package.json
67
+
68
+ ## 3.0.0
69
+
70
+ ### Major Changes
71
+
72
+ - db89f0d: - **BREAKING CHANGE** removed all `unstable_` prefixes, e.g. `unstable_flag` is now `flag`
73
+
74
+ - **BREAKING CHANGE** removed `getPrecomputationContext`, use `dedupe` instead (see below)
75
+ - **BREAKING CHANGE** moved all provider functions to dedicated packages
76
+ - `@vercel/flags/providers/launchdarkly` → `@flags-sdk/launchdarkly`
77
+ - `@vercel/flags/providers/statsig` → `@flags-sdk/statsig`
78
+ - `@vercel/flags/providers/split` → `@flags-sdk/split`
79
+ - `@vercel/flags/providers/hypertune` → `@flags-sdk/hypertune`
80
+ - `@vercel/flags/providers/optimizely` → `@flags-sdk/optimizely`
81
+ - `@vercel/flags/providers/happykit` → `@flags-sdk/happykit`
82
+ - **BREAKING CHANGE** changed `.run({})` behavior
83
+
84
+ See [flags-sdk.com](https://flags-sdk.com/) for the latest APIs.
85
+
86
+ - db89f0d: remove unstable\_ prefixes
87
+
88
+ ### Minor Changes
89
+
90
+ - db89f0d: **@vercel/flags/next: Added a `dedupe` function**
91
+
92
+ `dedupe` is a middleware-friendly version of `React.cache`. It allows ensuring a function only ever runs once per request.
93
+
94
+ ```ts
95
+ import { dedupe } from '@vercel/flags/next';
96
+
97
+ let i = 0;
98
+ const runOnce = dedupe(async () => {
99
+ return i++;
100
+ });
101
+
102
+ await runOnce(); // returns 0
103
+ await runOnce(); // still returns 0
104
+ ```
105
+
106
+ 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.
107
+
108
+ `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.
109
+
110
+ ```ts
111
+ import { nanoid } from 'nanoid';
112
+ import { cookies, headers } from 'next/headers';
113
+ import { dedupe } from '@vercel/flags/next';
114
+
115
+ /**
116
+ * Reads the visitor id from a cookie or returns a new visitor id
117
+ */
118
+ export const getOrGenerateVisitorId = dedupe(
119
+ async (): Promise<{ value: string; fresh: boolean }> => {
120
+ const visitorIdCookie = (await cookies()).get('visitor-id')?.value;
121
+
122
+ return visitorIdCookie
123
+ ? { value: visitorIdCookie, fresh: false }
124
+ : { value: nanoid(), fresh: true };
125
+ },
126
+ );
127
+ ```
128
+
129
+ > 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.
130
+
131
+ > Note: This function acts as a sort of polyfill until similar functionality lands in Next.js directly.
132
+
133
+ ## 2.7.0
134
+
135
+ ### Minor Changes
136
+
137
+ - fb50709: Adds support for using feature flags in Pages Router.
138
+
139
+ The same feature flag declared for App Router can now also be used in Pages Router. Feature flags need to be used server-side.
140
+
141
+ 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 })`.
142
+
143
+ **Dynamic usage example**
144
+
145
+ ```ts
146
+ export async function getServerSideProps({ req }) {
147
+ const showFreeDeliveryBanner = await showFreeDeliveryBannerFlag(req);
148
+ return { props: { showFreeDeliveryBanner } };
149
+ }
150
+ ```
151
+
152
+ **Precomputed usage example**
153
+
154
+ ```ts
155
+ import { bannerFlags, showFreeDeliveryBannerFlag } from './flags';
156
+ import type {
157
+ GetStaticPaths,
158
+ GetStaticProps,
159
+ InferGetStaticPropsType,
160
+ } from 'next';
161
+ import { unstable_generatePermutations as generatePermutations } from '@vercel/flags/next';
162
+
163
+ export const getStaticPaths = (async () => {
164
+ const codes = await generatePermutations(bannerFlags);
165
+
166
+ return {
167
+ paths: codes.map((code) => ({ params: { code } })),
168
+ fallback: 'blocking',
169
+ };
170
+ }) satisfies GetStaticPaths;
171
+
172
+ export const getStaticProps = (async (context) => {
173
+ const showFreeDeliveryBanner = await showFreeDeliveryBannerFlag(
174
+ context.params!.code as string,
175
+ bannerFlags,
176
+ );
177
+
178
+ return { props: { showFreeDeliveryBanner } };
179
+ }) satisfies GetStaticProps<{ showFreeDeliveryBanner: boolean }>;
180
+ ```
181
+
182
+ - 87503b6: Return `createdAt` and `updatedAt` as part of the provider data for those that support it
183
+
184
+ ## 2.6.3
185
+
186
+ ### Patch Changes
187
+
188
+ - 69f8df0: use defaultValue when an async decide function throws
189
+ - 65d3d73: add MIT license
190
+
191
+ ## 2.6.2
192
+
193
+ ### Patch Changes
194
+
195
+ - 80e0737: Add Next.js 15 compatibility.
196
+
197
+ Uses the async versions of `headers` and `cookies` to avoid warnings during development.
198
+
199
+ ## 2.6.1
200
+
201
+ ### Patch Changes
202
+
203
+ - 9c379a8: add pagination to LaunchDarkly provider
204
+
205
+ ## 2.6.0
206
+
207
+ ### Minor Changes
208
+
209
+ - 7b9aa17: evaluate flags once per request only by reusing the result
210
+ - b049c26: add SvelteKit support
211
+
212
+ ### Patch Changes
213
+
214
+ - c12f4d4: Deprecates `FlagsReporter` and `injectFlags`.
215
+
216
+ Web Analytics now automatically detects flags present in the DOM, so these are no longer necessary.
217
+
218
+ You can safely remove `FlagsReporter` and any calls to `injectFlags`.
219
+
220
+ - 1be4799: add no-store to LaunchDarkly provider
221
+
222
+ ## 2.5.1
223
+
224
+ ### Patch Changes
225
+
226
+ - 3a68cf7: Simplify middleware usage
227
+
228
+ BREAKING CHANGE: `unstable_precompute` now returns code directly
229
+
230
+ **Before**
231
+
232
+ ```ts
233
+ const values = await unstable_precompute(precomputeFlags, context);
234
+ const code = await unstable_serialize(precomputeFlags, values);
235
+ ```
236
+
237
+ **After**
238
+
239
+ This can now be done in a single function call.
240
+
241
+ ```ts
242
+ const code = await unstable_precompute(precomputeFlags, context);
243
+ ```
244
+
245
+ **Other notes**
246
+
247
+ `unstable_precompute` conceptually calls `unstable_evaluate` and `unstable_serialize` to generate the code.
248
+
249
+ This can also be done manually if you need access to `values`:
250
+
251
+ ```ts
252
+ const values = await unstable_evaluate(precomputeFlags, context);
253
+ const code = await unstable_serialize(precomputeFlags, values);
254
+ ```
255
+
256
+ It's also possible to get the value of a specific flag in middleware based on the precomputation:
257
+
258
+ ```ts
259
+ // flags.ts
260
+ export const showBanner = flag({
261
+ /* ... */
262
+ });
263
+ export const precomputeFlags = [showBanner /* ... */];
264
+
265
+ // middleware.ts
266
+ const code = await unstable_precompute(precomputeFlags, context);
267
+ const banner = showBanner(code, precomputeFlags);
268
+ ```
269
+
270
+ ## 2.5.0
271
+
272
+ ### Minor Changes
273
+
274
+ - 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)
275
+
276
+ ## 2.4.0
277
+
278
+ ### Minor Changes
279
+
280
+ - c132300: Add `reportValue` function to report resolved flags
281
+ - 5911721: add HappyKit provider
282
+ - bf47adb: Provide a the `unstable_getFlagsProps` and `unstable_setGlobalFlagsAnalyticsKeys` functions that can be used to integrate with Vercel Analytics
283
+
284
+ ## 2.3.0
285
+
286
+ ### Minor Changes
287
+
288
+ - be714bd: add hypertune provider
289
+
290
+ ## 2.2.1
291
+
292
+ ### Patch Changes
293
+
294
+ - 6f401cc: update README
295
+
296
+ ## 2.2.0
297
+
298
+ ### Minor Changes
299
+
300
+ - a6883ad: Add Optimizely provider
301
+ - af787a9: Include Experiments from Statsig in `getStatsigData`
302
+
303
+ ### Patch Changes
304
+
305
+ - ae3f59c: Fix pagination for Statsig provider in `getStatsigData`
306
+
307
+ ## 2.1.2
308
+
309
+ ### Patch Changes
310
+
311
+ - b22ab52: support undefined as authHeader in verifyAccess for Pages Router compatibility
312
+ - 155d5ac: make overrideEncryptionMode optional in ApiData type
313
+
314
+ ## 2.1.1
315
+
316
+ ### Patch Changes
317
+
318
+ - 6b79659: expose ApiData type
319
+
320
+ ## 2.1.0
321
+
322
+ ### Minor Changes
323
+
324
+ - abae5af: Add verifyAccess to allow skipping encryption on the .well-known/vercel/flags endpoint
325
+
326
+ ## 2.0.0
327
+
328
+ ### Major Changes
329
+
330
+ - 59befe1: Unify `encrypt` and `decrypt` functions
331
+
332
+ BREAKING CHANGE
333
+ Replace the existing calls to any encrypt* or decrypt* functions like `encryptApiData`, `encryptOverrides`, `encryptValues` or `decryptApiData`, `decryptOverrides`, `decryptValues` with `encrypt` or `decrypt`
334
+
335
+ ## 1.1.2
336
+
337
+ ### Patch Changes
338
+
339
+ - 9ff283b: Fix auto-import showing `@vercel/flags/*` as option
340
+
341
+ ## 1.1.1
342
+
343
+ ### Patch Changes
344
+
345
+ - 80a1acc: Fix type export for providers
346
+
347
+ ## 1.1.0
348
+
349
+ ### Minor Changes
350
+
351
+ - 1f4fb18: Add Statsig and Split providers and update exports in package.json
352
+
353
+ ## 1.0.0
354
+
355
+ ### Major Changes
356
+
357
+ - c1e29ea: BREAKING CHANGE: `VERCEL_FLAGS_SECRET` env var has been renamed to `FLAGS_SECRET`
358
+
359
+ - Rename your `VERCEL_FLAGS_SECRET` environment variable to `FLAGS_SECRET` in your project settings on vercel.com
360
+ - Pull down the latest environment variables using `vercel env pull .env.local`
361
+
362
+ ## 0.2.1
363
+
364
+ ### Patch Changes
365
+
366
+ - 794b711: prevent xss
367
+
368
+ ## 0.2.0
369
+
370
+ ### Minor Changes
371
+
372
+ - 11a4bb6: add LaunchDarkly provider
373
+
374
+ ## 0.1.9
375
+
376
+ ### Patch Changes
377
+
378
+ - 1808b9c: fix auto-import in vs code defaulting to wrong path
379
+
380
+ ## 0.1.8
381
+
382
+ ### Patch Changes
383
+
384
+ - 91f801d: add JSDoc to `FlagDefinitionsType`, `FlagValuesType` and `FlagOverridesType`
385
+
386
+ ## 0.1.7
387
+
388
+ ### Patch Changes
389
+
390
+ - 1dbfd2c: add jsdoc to origin
391
+
392
+ ## 0.1.6
393
+
394
+ ### Patch Changes
395
+
396
+ - fa6a6d1: rename types to end with \*Types to avoid clash with component names
397
+
398
+ ## 0.1.5
399
+
400
+ ### Patch Changes
401
+
402
+ - 0e97393: omit src folder from package
403
+
404
+ ## 0.1.4
405
+
406
+ ### Patch Changes
407
+
408
+ - fe169df: change README wording
409
+
410
+ ## 0.1.3
411
+
412
+ ### Patch Changes
413
+
414
+ - effd1f6: replace url with origin in FlagDefinition type
415
+
416
+ ## 0.1.2
417
+
418
+ ### Patch Changes
419
+
420
+ - a4ee199: add main export
421
+ - 1a97981: rename data-variant-values to data-variant-state
422
+
423
+ ## 0.1.1
424
+
425
+ ### Patch Changes
426
+
427
+ - 446f640: rename types
428
+ - 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.com](https://flags-sdk.com/) 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.com](https://flags-sdk.com/).
@@ -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":[]}