@flagwire/sdk-node 0.1.0 → 0.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 (2) hide show
  1. package/README.md +58 -5
  2. package/package.json +13 -3
package/README.md CHANGED
@@ -1,15 +1,68 @@
1
1
  # `@flagwire/sdk-node`
2
2
 
3
- Node.js SDK for deterministic local FlagWire evaluation. Bundles are fetched with ETags and kept
4
- fresh through polling with optional streaming notifications.
3
+ Node.js SDK with deterministic local evaluation. It validates and caches environment bundles,
4
+ polls with ETags, and can use streaming notifications for prompt refreshes.
5
+
6
+ Requires Node.js 22.4 or newer.
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ pnpm add @flagwire/sdk-node
12
+ ```
13
+
14
+ ## Usage
5
15
 
6
16
  ```ts
7
17
  import { createServerClient } from "@flagwire/sdk-node";
8
18
 
9
- const flags = createServerClient({ serverKey: process.env.FLAGWIRE_SERVER_KEY! });
19
+ const flags = createServerClient({
20
+ serverKey: process.env.FLAGWIRE_SERVER_KEY!,
21
+ });
22
+
10
23
  await flags.waitForInitialization({ timeoutMs: 5_000 });
11
24
 
12
- const enabled = flags.evaluate("checkout-redesign", { key: "user-123" }, false);
25
+ const enabled = flags.evaluate(
26
+ "checkout-redesign",
27
+ { key: "user-123", attributes: { region: "eu-west" } },
28
+ false,
29
+ );
30
+
31
+ // During graceful shutdown:
32
+ await flags.close();
13
33
  ```
14
34
 
15
- Call `await flags.close()` during graceful shutdown. Never expose a server key to a browser.
35
+ Create one long-lived client per process instead of one per request.
36
+
37
+ ## Options
38
+
39
+ | Option | Required | Default | Description |
40
+ | ---------------- | -------- | --------------------------- | ------------------------------------------------------------- |
41
+ | `serverKey` | yes | — | Secret server key beginning with `sk_live_` |
42
+ | `baseUrl` | no | `https://edge.flagwire.dev` | FlagWire edge endpoint |
43
+ | `pollIntervalMs` | no | `30000` | Refresh interval when a stream is not healthy |
44
+ | `stream` | no | `true` | Use version notifications when WebSocket support is available |
45
+
46
+ ## Client API
47
+
48
+ - `waitForInitialization({ timeoutMs })` waits for the first bundle attempt without blocking the
49
+ process indefinitely.
50
+ - `evaluate(key, context, defaultValue)` returns a locally evaluated value or the supplied default.
51
+ - `evaluateDetail(key, context, defaultValue)` also returns the evaluation reason and variant.
52
+ - `allFlags(context)` evaluates every flag in the active bundle.
53
+ - `flush()` sends queued exposure events.
54
+ - `close()` stops background work, flushes pending events, and releases the stream.
55
+
56
+ Bundles are validated before activation. Invalid, unavailable, or revoked bundle state fails
57
+ closed to application-provided defaults.
58
+
59
+ ## Key safety
60
+
61
+ Treat `sk_live_` keys as secrets. Load them from a secret manager or process environment; never
62
+ commit, log, or send them to a browser. Use [`@flagwire/sdk-js`](../sdk-js) with a `pk_live_` key for
63
+ client-side applications.
64
+
65
+ ## Type-safe flags
66
+
67
+ Run [`flagwire-typegen`](../../tools/typegen-cli) and import the generated declaration file once in
68
+ your application. `evaluate()` then infers known keys and value types.
package/package.json CHANGED
@@ -1,8 +1,18 @@
1
1
  {
2
2
  "name": "@flagwire/sdk-node",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Local-evaluation Node.js SDK for FlagWire feature flags",
5
+ "keywords": [
6
+ "feature-flags",
7
+ "nodejs",
8
+ "server",
9
+ "typescript"
10
+ ],
5
11
  "license": "MIT",
12
+ "homepage": "https://github.com/flagwire/flagwire-js/tree/main/packages/sdk-node#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/flagwire/flagwire-js/issues"
15
+ },
6
16
  "type": "module",
7
17
  "files": [
8
18
  "dist"
@@ -29,8 +39,8 @@
29
39
  "provenance": true
30
40
  },
31
41
  "dependencies": {
32
- "@flagwire/schema": "0.1.0",
33
- "@flagwire/evaluate": "0.1.0"
42
+ "@flagwire/evaluate": "0.1.1",
43
+ "@flagwire/schema": "0.1.1"
34
44
  },
35
45
  "devDependencies": {
36
46
  "esbuild": "0.28.2"