@flipt-io/flipt
Advanced tools
Comparing version 1.0.0 to 1.2.0
# Changelog | ||
## [1.2.0](https://github.com/flipt-io/flipt-server-sdks/compare/flipt-node-v1.1.0...flipt-node-v1.2.0) (2024-05-10) | ||
### Features | ||
* **nodejs:** allow setting arbitrary headers ([#203](https://github.com/flipt-io/flipt-server-sdks/issues/203)) ([b8f1286](https://github.com/flipt-io/flipt-server-sdks/commit/b8f12866f530dde6bb12b6119dc2b38f2a9a89ef)) | ||
## [1.1.0](https://github.com/flipt-io/flipt-server-sdks/compare/flipt-node-v1.0.0...flipt-node-v1.1.0) (2024-05-10) | ||
### Features | ||
* **nodejs:** allow setting arbitrary headers ([#203](https://github.com/flipt-io/flipt-server-sdks/issues/203)) ([b8f1286](https://github.com/flipt-io/flipt-server-sdks/commit/b8f12866f530dde6bb12b6119dc2b38f2a9a89ef)) | ||
## [1.0.0](https://github.com/flipt-io/flipt-server-sdks/compare/flipt-node-v1.0.0-rc.2...flipt-node-v1.0.0) (2024-01-16) | ||
@@ -4,0 +18,0 @@ |
@@ -7,3 +7,3 @@ import { AuthenticationStrategy } from ".."; | ||
private timeout?; | ||
constructor(url: string, timeout?: number, authenticationStrategy?: AuthenticationStrategy); | ||
constructor(url: string, timeout?: number, authenticationStrategy?: AuthenticationStrategy, headers?: Record<string, string>); | ||
variant(request: EvaluationRequest): Promise<VariantEvaluationResponse>; | ||
@@ -10,0 +10,0 @@ boolean(request: EvaluationRequest): Promise<BooleanEvaluationResponse>; |
@@ -5,7 +5,10 @@ "use strict"; | ||
class Evaluation { | ||
constructor(url, timeout, authenticationStrategy) { | ||
constructor(url, timeout, authenticationStrategy, headers) { | ||
this.url = url; | ||
this.headers = {}; | ||
this.headers = headers || {}; | ||
if (!!authenticationStrategy) { | ||
this.headers = Object.fromEntries(authenticationStrategy.authenticate().entries()); | ||
this.headers = { | ||
...this.headers, | ||
...Object.fromEntries(authenticationStrategy.authenticate()) | ||
}; | ||
} | ||
@@ -12,0 +15,0 @@ this.timeout = timeout; |
@@ -7,2 +7,3 @@ import { Evaluation } from "./evaluation"; | ||
timeout?: number; | ||
headers?: Record<string, string>; | ||
} | ||
@@ -9,0 +10,0 @@ export interface AuthenticationStrategy { |
@@ -41,3 +41,6 @@ "use strict"; | ||
} | ||
this.evaluation = new evaluation_1.Evaluation(clientOptions.url || defaultURL, clientOptions.timeout, clientOptions.authenticationStrategy); | ||
if ((options === null || options === void 0 ? void 0 : options.headers) !== undefined) { | ||
clientOptions.headers = options.headers; | ||
} | ||
this.evaluation = new evaluation_1.Evaluation(clientOptions.url || defaultURL, clientOptions.timeout, clientOptions.authenticationStrategy, clientOptions.headers); | ||
} | ||
@@ -44,0 +47,0 @@ } |
@@ -15,7 +15,13 @@ "use strict"; | ||
} | ||
test("variant", async () => { | ||
const client = new _1.FliptClient({ | ||
let client; | ||
beforeEach(() => { | ||
client = new _1.FliptClient({ | ||
url: fliptUrl, | ||
authenticationStrategy: new index_1.ClientTokenAuthentication(authToken) | ||
authenticationStrategy: new index_1.ClientTokenAuthentication(authToken), | ||
headers: { | ||
"x-custom-header": "custom-value" | ||
} | ||
}); | ||
}); | ||
test("variant", async () => { | ||
const variant = await client.evaluation.variant({ | ||
@@ -34,6 +40,2 @@ namespaceKey: "default", | ||
test("boolean", async () => { | ||
const client = new _1.FliptClient({ | ||
url: fliptUrl, | ||
authenticationStrategy: new index_1.ClientTokenAuthentication(authToken) | ||
}); | ||
const boolean = await client.evaluation.boolean({ | ||
@@ -50,6 +52,2 @@ namespaceKey: "default", | ||
test("batch", async () => { | ||
const client = new _1.FliptClient({ | ||
url: fliptUrl, | ||
authenticationStrategy: new index_1.ClientTokenAuthentication(authToken) | ||
}); | ||
const batch = await client.evaluation.batch({ | ||
@@ -56,0 +54,0 @@ requests: [ |
{ | ||
"name": "@flipt-io/flipt", | ||
"version": "1.0.0", | ||
"version": "1.2.0", | ||
"description": "Flipt Server SDK", | ||
@@ -10,4 +10,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"fmt": "prettier --config .prettierrc 'src/**/*.ts' 'example/index.ts' --write", | ||
"lint": "prettier --check src/**/*.ts example/index.ts", | ||
"fmt": "prettier --config .prettierrc 'src/**/*.ts' 'examples/index.ts' --write", | ||
"lint": "prettier --check src/**/*.ts examples/index.ts", | ||
"test": "jest", | ||
@@ -14,0 +14,0 @@ "build": "tsc" |
@@ -19,4 +19,23 @@ # Flipt Node | ||
In the [example](./example) directory, there is an example TypeScript program which imports in the flipt client, and uses it appropriately, please refer to that for how to use the client. | ||
In your Node code you can import this client and use it as so: | ||
```typescript | ||
import { FliptClient } from "@flipt-io/flipt"; | ||
const fliptClient = new FliptClient(); | ||
async function evaluate() { | ||
const variantEvaluationResponse = await fliptClient.evaluation.variant({ | ||
namespaceKey: "default", | ||
flagKey: "flag1", | ||
entityId: "entity", | ||
context: { fizz: "buzz" } | ||
}); | ||
console.log(variantEvaluationResponse); | ||
} | ||
``` | ||
There is a more detailed example in the [examples](./examples) directory. | ||
### Metrics | ||
@@ -23,0 +42,0 @@ |
@@ -12,3 +12,3 @@ import { AuthenticationStrategy } from ".."; | ||
private url: string; | ||
private headers: object; | ||
private headers: Record<string, string>; | ||
private timeout?: number; | ||
@@ -19,10 +19,12 @@ | ||
timeout?: number, | ||
authenticationStrategy?: AuthenticationStrategy | ||
authenticationStrategy?: AuthenticationStrategy, | ||
headers?: Record<string, string> | ||
) { | ||
this.url = url; | ||
this.headers = {}; | ||
this.headers = headers || {}; | ||
if (!!authenticationStrategy) { | ||
this.headers = Object.fromEntries( | ||
authenticationStrategy.authenticate().entries() | ||
); | ||
this.headers = { | ||
...this.headers, | ||
...Object.fromEntries(authenticationStrategy.authenticate()) | ||
}; | ||
} | ||
@@ -29,0 +31,0 @@ this.timeout = timeout; |
@@ -12,2 +12,3 @@ import { Evaluation } from "./evaluation"; | ||
timeout?: number; | ||
headers?: Record<string, string>; | ||
} | ||
@@ -69,6 +70,11 @@ | ||
if (options?.headers !== undefined) { | ||
clientOptions.headers = options.headers; | ||
} | ||
this.evaluation = new Evaluation( | ||
clientOptions.url || defaultURL, | ||
clientOptions.timeout, | ||
clientOptions.authenticationStrategy | ||
clientOptions.authenticationStrategy, | ||
clientOptions.headers | ||
); | ||
@@ -75,0 +81,0 @@ } |
@@ -16,8 +16,15 @@ import { ClientTokenAuthentication } from "./index"; | ||
test("variant", async () => { | ||
const client = new FliptClient({ | ||
let client: FliptClient; | ||
beforeEach(() => { | ||
client = new FliptClient({ | ||
url: fliptUrl, | ||
authenticationStrategy: new ClientTokenAuthentication(authToken) | ||
authenticationStrategy: new ClientTokenAuthentication(authToken), | ||
headers: { | ||
"x-custom-header": "custom-value" | ||
} | ||
}); | ||
}); | ||
test("variant", async () => { | ||
const variant = await client.evaluation.variant({ | ||
@@ -38,7 +45,2 @@ namespaceKey: "default", | ||
test("boolean", async () => { | ||
const client = new FliptClient({ | ||
url: fliptUrl, | ||
authenticationStrategy: new ClientTokenAuthentication(authToken) | ||
}); | ||
const boolean = await client.evaluation.boolean({ | ||
@@ -57,7 +59,2 @@ namespaceKey: "default", | ||
test("batch", async () => { | ||
const client = new FliptClient({ | ||
url: fliptUrl, | ||
authenticationStrategy: new ClientTokenAuthentication(authToken) | ||
}); | ||
const batch = await client.evaluation.batch({ | ||
@@ -64,0 +61,0 @@ requests: [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
35931
737
87