-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: consolidate browser and wasm engine (#226)
* feat(wip): consolidate browser and wasm engine * chore: architecture * chore: fmt * chore: dependabot, cleanup * chore: move back seperate dir * chore: dependabot * chore: update release-please * chore: fix build * chore(wip): try to get tests working * chore: blah tests * chore: comment out broken test for now
- Loading branch information
1 parent
a183ee1
commit 9c219b7
Showing
27 changed files
with
1,808 additions
and
1,015 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,3 +128,5 @@ dist | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BooleanResult, EngineOpts, VariantResult } from './models.js'; | ||
export declare class FliptEvaluationClient { | ||
private engine; | ||
private fetcher; | ||
private constructor(); | ||
static init(namespace?: string, engine_opts?: EngineOpts): Promise<FliptEvaluationClient>; | ||
refresh(): Promise<void>; | ||
evaluateVariant(flag_key: string, entity_id: string, context: {}): VariantResult; | ||
evaluateBoolean(flag_key: string, entity_id: string, context: {}): BooleanResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FliptEvaluationClient = void 0; | ||
const pkg_1 = require("../pkg"); | ||
class FliptEvaluationClient { | ||
engine; | ||
fetcher; | ||
constructor(engine, fetcher) { | ||
this.engine = engine; | ||
this.fetcher = fetcher; | ||
} | ||
static async init(namespace = 'default', engine_opts = { | ||
url: 'http://localhost:8080', | ||
reference: '' | ||
}) { | ||
await (0, pkg_1.default)(); | ||
let url = engine_opts.url ?? 'http://localhost:8080'; | ||
// trim trailing slash | ||
url = url.replace(/\/$/, ''); | ||
url = `${url}/internal/v1/evaluation/snapshot/namespace/${namespace}`; | ||
if (engine_opts.reference) { | ||
url = `${url}?ref=${engine_opts.reference}`; | ||
} | ||
const headers = new Headers(); | ||
headers.append('Accept', 'application/json'); | ||
headers.append('Content-Type', 'application/json'); | ||
if (engine_opts.authentication) { | ||
if ('client_token' in engine_opts.authentication) { | ||
headers.append('Authorization', `Bearer ${engine_opts.authentication.client_token}`); | ||
} | ||
else if ('jwt_token' in engine_opts.authentication) { | ||
headers.append('Authorization', `JWT ${engine_opts.authentication.jwt_token}`); | ||
} | ||
} | ||
const fetcher = async () => { | ||
const resp = await fetch(url, { | ||
method: 'GET', | ||
headers | ||
}); | ||
if (!resp.ok) { | ||
throw new Error('Failed to fetch data'); | ||
} | ||
return resp; | ||
}; | ||
const resp = await fetcher(); | ||
const data = await resp.json(); | ||
const engine = new pkg_1.Engine(namespace, data); | ||
return new FliptEvaluationClient(engine, fetcher); | ||
} | ||
async refresh() { | ||
const resp = await this.fetcher(); | ||
const data = await resp.json(); | ||
this.engine.snapshot(data); | ||
} | ||
evaluateVariant(flag_key, entity_id, context) { | ||
const evaluation_request = { | ||
flag_key, | ||
entity_id, | ||
context | ||
}; | ||
return this.engine.evaluate_variant(evaluation_request); | ||
} | ||
evaluateBoolean(flag_key, entity_id, context) { | ||
const evaluation_request = { | ||
flag_key, | ||
entity_id, | ||
context | ||
}; | ||
return this.engine.evaluate_boolean(evaluation_request); | ||
} | ||
} | ||
exports.FliptEvaluationClient = FliptEvaluationClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.