@rollercoders/flagforge-node 0.1.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.
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +69 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rollercoders
|
|
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
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# flagforge-node
|
|
2
|
+
|
|
3
|
+
Node.js client for FlagForge feature flags. Read-only, zero dependencies, uses native `fetch` (Node 18+).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install flagforge-node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { FlagForgeClient } from 'flagforge-node';
|
|
15
|
+
|
|
16
|
+
const client = new FlagForgeClient({
|
|
17
|
+
host: 'https://flagforge.myapp.com',
|
|
18
|
+
apiKey: 'ff_xxxx',
|
|
19
|
+
timeout: 5000, // ms, optional — default: 5000
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Single flag — throws FlagForgeError on error
|
|
23
|
+
const enabled = await client.isEnabled('new-dashboard', {
|
|
24
|
+
userId: 'user-123',
|
|
25
|
+
attributes: { plan: 'premium' },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Single flag — returns false on error (no exception)
|
|
29
|
+
const safe = await client.isEnabledSafe('new-dashboard', { userId: 'user-123' });
|
|
30
|
+
|
|
31
|
+
// Subset of flags
|
|
32
|
+
const results = await client.evaluateMany(['flag-a', 'flag-b'], { userId: 'user-123' });
|
|
33
|
+
// { 'flag-a': true, 'flag-b': false }
|
|
34
|
+
|
|
35
|
+
// All flags for the environment
|
|
36
|
+
const all = await client.evaluateAll({ userId: 'user-123' });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Error Handling
|
|
40
|
+
|
|
41
|
+
All methods except `isEnabledSafe` throw `FlagForgeError` on:
|
|
42
|
+
- Network errors
|
|
43
|
+
- Non-2xx HTTP responses
|
|
44
|
+
- Invalid JSON responses
|
|
45
|
+
- Timeout
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { FlagForgeError } from 'flagforge-node';
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const enabled = await client.isEnabled('my-flag');
|
|
52
|
+
} catch (err) {
|
|
53
|
+
if (err instanceof FlagForgeError) {
|
|
54
|
+
console.error('Flag evaluation failed:', err.message);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Requirements
|
|
60
|
+
|
|
61
|
+
- Node.js 18+
|
|
62
|
+
- FlagForge server with `POST /api/evaluate/all` endpoint
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class FlagForgeError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export interface FlagForgeClientOptions {
|
|
5
|
+
host: string;
|
|
6
|
+
apiKey: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface EvaluationContext {
|
|
10
|
+
userId?: string;
|
|
11
|
+
attributes?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export type FlagResults = Record<string, boolean>;
|
|
14
|
+
export declare class FlagForgeClient {
|
|
15
|
+
private readonly host;
|
|
16
|
+
private readonly apiKey;
|
|
17
|
+
private readonly timeout;
|
|
18
|
+
constructor(options: FlagForgeClientOptions);
|
|
19
|
+
evaluateAll(context?: EvaluationContext): Promise<FlagResults>;
|
|
20
|
+
isEnabled(flagKey: string, context?: EvaluationContext): Promise<boolean>;
|
|
21
|
+
isEnabledSafe(flagKey: string, context?: EvaluationContext): Promise<boolean>;
|
|
22
|
+
evaluateMany(flagKeys: string[], context?: EvaluationContext): Promise<FlagResults>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,sBAAsB;IAMrC,WAAW,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC;IAyClE,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7E,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;IAQjF,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC;CAI9F"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export class FlagForgeError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'FlagForgeError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class FlagForgeClient {
|
|
8
|
+
host;
|
|
9
|
+
apiKey;
|
|
10
|
+
timeout;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.host = options.host.replace(/\/$/, '');
|
|
13
|
+
this.apiKey = options.apiKey;
|
|
14
|
+
this.timeout = options.timeout ?? 5000;
|
|
15
|
+
}
|
|
16
|
+
async evaluateAll(context = {}) {
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
19
|
+
let response;
|
|
20
|
+
try {
|
|
21
|
+
response = await fetch(`${this.host}/api/evaluate/all`, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: {
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
'Authorization': `Bearer ${this.apiKey}`,
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify(context),
|
|
28
|
+
signal: controller.signal,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
throw new FlagForgeError(err instanceof Error ? err.message : 'Network error');
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
}
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new FlagForgeError(`HTTP ${response.status}: ${response.statusText}`);
|
|
39
|
+
}
|
|
40
|
+
let data;
|
|
41
|
+
try {
|
|
42
|
+
data = await response.json();
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
throw new FlagForgeError('Invalid JSON response');
|
|
46
|
+
}
|
|
47
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
|
|
48
|
+
throw new FlagForgeError('Invalid JSON response');
|
|
49
|
+
}
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
async isEnabled(flagKey, context = {}) {
|
|
53
|
+
const results = await this.evaluateAll(context);
|
|
54
|
+
return results[flagKey] === true;
|
|
55
|
+
}
|
|
56
|
+
async isEnabledSafe(flagKey, context = {}) {
|
|
57
|
+
try {
|
|
58
|
+
return await this.isEnabled(flagKey, context);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async evaluateMany(flagKeys, context = {}) {
|
|
65
|
+
const all = await this.evaluateAll(context);
|
|
66
|
+
return Object.fromEntries(flagKeys.map((k) => [k, all[k] === true]));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAeD,MAAM,OAAO,eAAe;IACT,IAAI,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAS;IAEjC,YAAY,OAA+B;QACzC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,UAA6B,EAAE;QAC/C,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;QACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAEjE,IAAI,QAAkB,CAAC;QACvB,IAAI,CAAC;YACH,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,mBAAmB,EAAE;gBACtD,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,kBAAkB;oBAClC,eAAe,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;iBACzC;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;gBAC7B,MAAM,EAAE,UAAU,CAAC,MAAM;aAC1B,CAAC,CAAC;QAC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,QAAkB,EAAE,UAA6B,EAAE;QACpE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;IACvE,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rollercoders/flagforge-node",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Node.js client for FlagForge feature flagging",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"packageManager": "yarn@4.13.0",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"prepublishOnly": "yarn build",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"typescript": "^5",
|
|
32
|
+
"vitest": "^1"
|
|
33
|
+
}
|
|
34
|
+
}
|