@flagify/node 1.0.0 → 1.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/README.md +77 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://flagify.dev">
|
|
3
|
-
<
|
|
4
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://flagify.dev/logo-white.svg" />
|
|
5
|
-
<source media="(prefers-color-scheme: light)" srcset="https://flagify.dev/logo-color.svg" />
|
|
6
|
-
<img alt="Flagify" src="https://flagify.dev/logo-color.svg" width="280" />
|
|
7
|
-
</picture>
|
|
3
|
+
<img alt="Flagify" src="https://flagify.dev/logo-color.svg" width="280" />
|
|
8
4
|
</a>
|
|
9
5
|
</p>
|
|
10
6
|
|
|
@@ -15,14 +11,14 @@
|
|
|
15
11
|
<p align="center">
|
|
16
12
|
<a href="https://www.npmjs.com/package/@flagify/node"><img src="https://img.shields.io/npm/v/@flagify/node.svg?style=flat-square&color=0D80F9" alt="npm version" /></a>
|
|
17
13
|
<a href="https://www.npmjs.com/package/@flagify/node"><img src="https://img.shields.io/npm/dm/@flagify/node.svg?style=flat-square&color=0D80F9" alt="npm downloads" /></a>
|
|
18
|
-
<a href="https://github.com/flagifyhq/
|
|
19
|
-
<a href="https://github.com/flagifyhq/
|
|
14
|
+
<a href="https://github.com/flagifyhq/javascript/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@flagify/node.svg?style=flat-square&color=0D80F9" alt="license" /></a>
|
|
15
|
+
<a href="https://github.com/flagifyhq/javascript"><img src="https://img.shields.io/github/stars/flagifyhq/javascript?style=flat-square&color=0D80F9" alt="github stars" /></a>
|
|
20
16
|
</p>
|
|
21
17
|
|
|
22
18
|
<p align="center">
|
|
23
19
|
<a href="https://flagify.dev/docs">Documentation</a> ·
|
|
24
20
|
<a href="https://flagify.dev/docs/sdks/node">SDK Reference</a> ·
|
|
25
|
-
<a href="https://github.com/flagifyhq/
|
|
21
|
+
<a href="https://github.com/flagifyhq/javascript/issues">Issues</a> ·
|
|
26
22
|
<a href="https://flagify.dev">Website</a>
|
|
27
23
|
</p>
|
|
28
24
|
|
|
@@ -133,6 +129,7 @@ const flagify = new Flagify({
|
|
|
133
129
|
| `options.apiUrl` | `string` | No | `https://api.flagify.dev` | Custom API base URL |
|
|
134
130
|
| `options.staleTimeMs` | `number` | No | `300000` | Cache staleness threshold in ms |
|
|
135
131
|
| `options.realtime` | `boolean` | No | `false` | Enable real-time SSE updates |
|
|
132
|
+
| `options.pollIntervalMs` | `number` | No | -- | Polling interval in ms for periodic flag sync |
|
|
136
133
|
| `options.user` | `FlagifyUser` | No | -- | User context for targeting |
|
|
137
134
|
|
|
138
135
|
## API reference
|
|
@@ -167,19 +164,80 @@ if (flagify.isEnabled('dark-mode')) {
|
|
|
167
164
|
|
|
168
165
|
---
|
|
169
166
|
|
|
170
|
-
### `flagify.getValue<T>(flagKey: string): T`
|
|
167
|
+
### `flagify.getValue<T>(flagKey: string, fallback: T): T`
|
|
171
168
|
|
|
172
|
-
Returns the resolved value of a feature flag with
|
|
169
|
+
Returns the resolved value of a feature flag with a typed fallback.
|
|
173
170
|
|
|
174
171
|
```typescript
|
|
175
172
|
// String variant
|
|
176
|
-
const variant = flagify.getValue<string>('checkout-flow')
|
|
173
|
+
const variant = flagify.getValue<string>('checkout-flow', 'control')
|
|
177
174
|
|
|
178
175
|
// Number
|
|
179
|
-
const limit = flagify.getValue<number>('rate-limit')
|
|
176
|
+
const limit = flagify.getValue<number>('rate-limit', 100)
|
|
180
177
|
|
|
181
178
|
// JSON object
|
|
182
|
-
const config = flagify.getValue<{ maxRetries: number; timeout: number }>('api-config'
|
|
179
|
+
const config = flagify.getValue<{ maxRetries: number; timeout: number }>('api-config', {
|
|
180
|
+
maxRetries: 3,
|
|
181
|
+
timeout: 5000,
|
|
182
|
+
})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
### `flagify.getVariant(flagKey: string, fallback: string): string`
|
|
188
|
+
|
|
189
|
+
Returns the string variant of a multivariate flag. Returns the variant with the highest weight, or the fallback if the flag has no variants or is disabled.
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const variant = flagify.getVariant('checkout-flow', 'control')
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### `flagify.evaluate(flagKey: string, user: FlagifyUser): Promise<EvaluateResult>`
|
|
198
|
+
|
|
199
|
+
Server-side evaluation with user targeting. Calls the Flagify API with user context for targeting rules.
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
const result = await flagify.evaluate('premium-feature', {
|
|
203
|
+
id: 'user_123',
|
|
204
|
+
email: 'mario@example.com',
|
|
205
|
+
role: 'admin',
|
|
206
|
+
})
|
|
207
|
+
// result: { key: 'premium-feature', value: true, reason: 'targeting_rule' }
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
### `flagify.ready(): Promise<void>`
|
|
213
|
+
|
|
214
|
+
Resolves when the initial flag sync is complete. Useful in server startup sequences.
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
const flagify = new Flagify({ projectKey: 'proj_xxx', publicKey: 'pk_xxx' })
|
|
218
|
+
await flagify.ready()
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
### `flagify.destroy(): void`
|
|
224
|
+
|
|
225
|
+
Disconnects the realtime listener, stops polling, and cleans up resources.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
flagify.destroy()
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
### `flagify.onFlagChange`
|
|
234
|
+
|
|
235
|
+
Callback invoked when a flag changes via SSE or background refetch.
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
flagify.onFlagChange = (event) => {
|
|
239
|
+
console.log(`Flag ${event.flagKey} was ${event.action}`)
|
|
240
|
+
}
|
|
183
241
|
```
|
|
184
242
|
|
|
185
243
|
## How it works
|
|
@@ -213,6 +271,10 @@ import type {
|
|
|
213
271
|
FlagifyUser,
|
|
214
272
|
FlagifyFlaggy,
|
|
215
273
|
IFlagifyClient,
|
|
274
|
+
EvaluateResult,
|
|
275
|
+
FlagChangeEvent,
|
|
276
|
+
RealtimeEvents,
|
|
277
|
+
RealtimeListener,
|
|
216
278
|
} from '@flagify/node'
|
|
217
279
|
```
|
|
218
280
|
|
|
@@ -222,8 +284,8 @@ We welcome contributions. Please open an issue first to discuss what you'd like
|
|
|
222
284
|
|
|
223
285
|
```bash
|
|
224
286
|
# Clone
|
|
225
|
-
git clone https://github.com/flagifyhq/
|
|
226
|
-
cd
|
|
287
|
+
git clone https://github.com/flagifyhq/javascript.git
|
|
288
|
+
cd javascript
|
|
227
289
|
|
|
228
290
|
# Install
|
|
229
291
|
pnpm install
|
package/package.json
CHANGED