@toggld/node 0.2.0 → 0.4.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.
@@ -1,4 +1,3 @@
1
- //#region ../spec/src/index.d.ts
2
1
  /**
3
2
  * A resolved flag value. OpenFeature permits `boolean | string | number |
4
3
  * structure`; we model the union as JSON, which also covers arrays and null for
@@ -32,8 +31,6 @@ type Reason = "STATIC" | "DEFAULT" | "TARGETING_MATCH" | "SPLIT" | "CACHED" | "D
32
31
  * @see https://openfeature.dev/specification/types
33
32
  */
34
33
  type ErrorCode = "PROVIDER_NOT_READY" | "PROVIDER_FATAL" | "FLAG_NOT_FOUND" | "PARSE_ERROR" | "TYPE_MISMATCH" | "TARGETING_KEY_MISSING" | "INVALID_CONTEXT" | "GENERAL";
35
- //#endregion
36
- //#region src/internal/types.d.ts
37
34
  /**
38
35
  * How the client resolves flags.
39
36
  *
@@ -59,9 +56,12 @@ interface SyncOptions {
59
56
  */
60
57
  readonly transport?: "ws" | "poll";
61
58
  /**
62
- * Interval between snapshot polls in milliseconds. Default `30000`. Until
63
- * the first snapshot arrives, the client retries faster (exponential from
64
- * 250 ms) so cold starts aren't gated on this interval.
59
+ * Delay after each snapshot poll, in milliseconds. Default `30000`.
60
+ * Polling stays active while the stream is healthy to recover changes from
61
+ * other Node instances and dropped announcements. With successful reads,
62
+ * allow this delay plus two request timeouts and scheduling delays.
63
+ * Use a positive, finite value. Until the first snapshot arrives, the client
64
+ * retries faster (exponential from 250 ms).
65
65
  */
66
66
  readonly pollIntervalMs?: number;
67
67
  /**
@@ -76,23 +76,49 @@ interface SyncOptions {
76
76
  * global `WebSocket` (Node ≥ 22). Useful for tests or proxies.
77
77
  */
78
78
  readonly webSocketConstructor?: typeof globalThis.WebSocket;
79
+ /**
80
+ * Evaluate from a local snapshot **file** instead of syncing over the network
81
+ * (ADR-0013) — for local development, offline runs, CI, or pinning a known
82
+ * ruleset. The file is a `FlagSnapshot` on disk; generate one with `npx
83
+ * @toggld/node pull`. A file-backed client makes no network requests and needs
84
+ * no reachable endpoint, key, or stream.
85
+ *
86
+ * The path is resolved highest-precedence first:
87
+ *
88
+ * 1. the `TOGGLD_FLAGS_FILE` environment variable (always wins, so a deployed
89
+ * app can be redirected at a file with no code change),
90
+ * 2. this option when given a string path,
91
+ * 3. `./toggld.flags.json` when this is `true`.
92
+ *
93
+ * The file is **watched**: edits are adopted live, no restart. The poll
94
+ * interval above doubles as a re-read safety net (and picks the file up if it
95
+ * is created after the client starts).
96
+ */
97
+ readonly file?: string | boolean;
79
98
  }
80
99
  /** Configuration for a {@link https://toggld.io Toggld} client. */
81
100
  interface ToggldClientOptions {
82
101
  /**
83
102
  * An **evaluation** (or management) API key, sent as `Authorization: Bearer
84
103
  * <sdkKey>`. The key is scoped to one tenant + environment server-side, so a
85
- * client always evaluates against exactly that environment. Local evaluation
86
- * requires a secret key (`ffk_…`) — public browser tokens cannot read flag
87
- * definitions.
104
+ * client always evaluates against exactly that environment. Network local
105
+ * evaluation requires a secret key (`ffk_…`) — public browser tokens cannot
106
+ * read flag definitions.
107
+ *
108
+ * Optional **only** for a file-backed client ({@link SyncOptions.file}), which
109
+ * reads its snapshot from disk and never authenticates. Required for remote
110
+ * and network-synced local evaluation.
88
111
  */
89
- readonly sdkKey: string;
112
+ readonly sdkKey?: string;
90
113
  /**
91
114
  * Base URL of the flag API, e.g. `https://toggld-api.example.workers.dev` or
92
115
  * `http://localhost:3000` in local development. No trailing path — the client
93
116
  * appends the OFREP and sync routes (`/ofrep/v1/...`, `/sync/v1/...`).
117
+ *
118
+ * Optional **only** for a file-backed client ({@link SyncOptions.file}); it
119
+ * makes no requests. Required for remote and network-synced local evaluation.
94
120
  */
95
- readonly endpoint: string;
121
+ readonly endpoint?: string;
96
122
  /**
97
123
  * Evaluation mode. Defaults to `"remote"`; prefer `"local"` on long-lived
98
124
  * servers. See {@link EvaluationMode}.
@@ -100,6 +126,10 @@ interface ToggldClientOptions {
100
126
  readonly mode?: EvaluationMode;
101
127
  /** Background sync tuning for `mode: "local"`. Ignored in remote mode. */
102
128
  readonly sync?: SyncOptions;
129
+ /** Local network evaluations report grouped counts by default. Set false to disable. */
130
+ readonly telemetry?: false | {
131
+ readonly flushIntervalMs?: number;
132
+ };
103
133
  /**
104
134
  * Attributes merged into the evaluation context of **every** request, under
105
135
  * any per-call context (per-call attributes win on key collision). Handy for
@@ -133,5 +163,4 @@ interface EvaluationDetails<T extends FlagValue> {
133
163
  readonly errorMessage: string | undefined;
134
164
  readonly flagMetadata: FlagMetadata;
135
165
  }
136
- //#endregion
137
166
  export { ErrorCode as a, FlagValue as c, ToggldClientOptions as i, Reason as l, EvaluationMode as n, EvaluationContext as o, SyncOptions as r, FlagMetadata as s, EvaluationDetails as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toggld/node",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Toggld SDK for Node.js — local flag evaluation with a background definition sync. Plain Promise API by default; native Effect API via @toggld/node/effect.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://toggld.io",
@@ -22,6 +22,9 @@
22
22
  "files": [
23
23
  "dist"
24
24
  ],
25
+ "bin": {
26
+ "toggld": "./dist/cli.mjs"
27
+ },
25
28
  "exports": {
26
29
  "./package.json": "./package.json",
27
30
  ".": {
@@ -37,11 +40,11 @@
37
40
  "access": "public"
38
41
  },
39
42
  "dependencies": {
40
- "effect": "4.0.0-beta.78"
43
+ "effect": "4.0.6"
41
44
  },
42
45
  "devDependencies": {
43
- "tsdown": "^0.22.2",
44
- "typescript": "5.8.3",
46
+ "tsdown": "^0.23.2",
47
+ "typescript": "6.0.3",
45
48
  "unrun": "^0.3.1",
46
49
  "@toggld/engine": "0.1.0",
47
50
  "@toggld/schema": "0.1.0",