-
Notifications
You must be signed in to change notification settings - Fork 72
feat: OFREP web provider #776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
76408f0
Update OF packages
thomaspoignant d2d0a3a
POC remote evaluation
thomaspoignant 2679a2d
Adding ETag management
thomaspoignant b3b7cc7
Add polling
thomaspoignant 1f26cca
Merge remote-tracking branch 'origin/main' into ofrep-web-provider-poc
thomaspoignant 9ec4dca
Merge remote-tracking branch 'origin/main' into ofrep-web-provider-poc
thomaspoignant 75f7547
OFREP web provider
thomaspoignant bb249bc
Merge remote-tracking branch 'origin/main' into ofrep-web-provider-poc
thomaspoignant 23af98e
Emit configurationChanged event
thomaspoignant dc3db76
add tests
thomaspoignant 180f3d4
Add more tests
thomaspoignant 88575d6
Merge remote-tracking branch 'origin/main' into ofrep-web-provider-poc
thomaspoignant 301fe78
Store errors in the cache
thomaspoignant 91578a8
Adding tests
thomaspoignant 700d814
Address review comments
thomaspoignant 166d3ed
Commenting the checks because of STALE evaluation not returning CACHED
thomaspoignant 08a6e04
regenerate package lock
beeme1mr 71f0b25
Merge branch 'main' into ofrep-web-provider-poc
beeme1mr b97f648
add missing comma
beeme1mr 2055c33
Handle 428 retry-after header
thomaspoignant 9b93ab2
Fix test in ofrep-core
thomaspoignant ca3483d
Merge branch 'main' into ofrep-web-provider-poc
beeme1mr 259ef62
Return the list of flags
thomaspoignant 47d7589
Keep the new context in memory even if we are not able to call the API
thomaspoignant 98bd26b
Merge branch 'main' into ofrep-web-provider-poc
thomaspoignant b33b944
Merge branch 'main' into ofrep-web-provider-poc
thomaspoignant 109571b
Merge branch 'main' into ofrep-web-provider-poc
beeme1mr 98b610b
Handle all errors not only the 400
thomaspoignant 1d021a0
Move initialize to the top
thomaspoignant 65577aa
Merge remote-tracking branch 'origin/main' into ofrep-web-provider-poc
thomaspoignant 37436b4
Add option from shared
thomaspoignant 5f9fe91
Adding the peer dependency
thomaspoignant d932a4d
Rename Ofrep to OFREP
thomaspoignant d4453bd
Update README
thomaspoignant 5a4c8f0
Merge remote-tracking branch 'origin/main' into ofrep-web-provider-poc
thomaspoignant 6f1666d
Add peer dependency to ofrep-core
thomaspoignant 8036e22
Use retryAfter method from ofrep-core
thomaspoignant ad2674c
Add the right version
thomaspoignant 71cecda
remove coverage folder
thomaspoignant 72edcb8
Merge remote-tracking branch 'origin/main' into ofrep-web-provider-poc
thomaspoignant c3c9076
Create a type for in memory cache
thomaspoignant 127f79d
Renaming options type
thomaspoignant 8b81130
fix typo
thomaspoignant 9da3a6d
Use not experimental version
thomaspoignant 7197251
Merge branch 'main' into ofrep-web-provider-poc
thomaspoignant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,25 @@ | ||
| { | ||
| "extends": ["../../../.eslintrc.json"], | ||
| "ignorePatterns": ["!**/*"], | ||
| "overrides": [ | ||
| { | ||
| "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.ts", "*.tsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.js", "*.jsx"], | ||
| "rules": {} | ||
| }, | ||
| { | ||
| "files": ["*.json"], | ||
| "parser": "jsonc-eslint-parser", | ||
| "rules": { | ||
| "@nx/dependency-checks": "error" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,15 @@ | ||
| # ofrep-web Provider | ||
|
|
||
| ## Installation | ||
|
|
||
| ``` | ||
| $ npm install @openfeature/ofrep-web-provider | ||
| ``` | ||
|
|
||
| ## Building | ||
|
|
||
| Run `nx package providers-ofrep-web` to build the library. | ||
|
|
||
| ## Running unit tests | ||
|
|
||
| Run `nx test providers-ofrep-web` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains hidden or 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,3 @@ | ||
| { | ||
| "presets": [["minify", { "builtIns": false }]] | ||
| } |
This file contains hidden or 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,16 @@ | ||
| /* eslint-disable */ | ||
| export default { | ||
| displayName: 'providers-ofrep-web', | ||
| preset: '../../../jest.preset.js', | ||
| globals: { | ||
| 'ts-jest': { | ||
| tsconfig: '<rootDir>/tsconfig.spec.json', | ||
| }, | ||
| }, | ||
| transform: { | ||
| '^.+\\.[tj]s$': 'ts-jest', | ||
| }, | ||
| testEnvironment: 'jsdom', | ||
| moduleFileExtensions: ['ts', 'js', 'html'], | ||
| setupFiles: ['./jest.polyfills.js'], | ||
| }; |
This file contains hidden or 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,32 @@ | ||
| // jest.polyfills.js | ||
| /** | ||
| * @note The block below contains polyfills for Node.js globals | ||
| * required for Jest to function when running JSDOM tests. | ||
| * These HAVE to be require's and HAVE to be in this exact | ||
| * order, since "undici" depends on the "TextEncoder" global API. | ||
| * | ||
| * Consider migrating to a more modern test runner if | ||
| * you don't want to deal with this. | ||
| */ | ||
|
|
||
| const { TextDecoder, TextEncoder } = require('node:util'); | ||
|
|
||
| // eslint-disable-next-line no-undef | ||
| Object.defineProperties(globalThis, { | ||
| TextDecoder: { value: TextDecoder }, | ||
| TextEncoder: { value: TextEncoder }, | ||
| }) | ||
|
|
||
| const { Blob, File } = require('node:buffer'); | ||
| const { fetch, Headers, FormData, Request, Response } = require('undici'); | ||
|
|
||
| // eslint-disable-next-line no-undef | ||
| Object.defineProperties(globalThis, { | ||
| fetch: { value: fetch, writable: true }, | ||
| Blob: { value: Blob }, | ||
| File: { value: File }, | ||
| Headers: { value: Headers }, | ||
| FormData: { value: FormData }, | ||
| Request: { value: Request }, | ||
| Response: { value: Response }, | ||
| }) |
This file contains hidden or 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,16 @@ | ||
| { | ||
| "name": "@openfeature/ofrep-web-provider", | ||
| "version": "0.0.1-alpha.0", | ||
| "dependencies": { | ||
| "tslib": "^2.3.0" | ||
| }, | ||
| "main": "./src/index.js", | ||
| "typings": "./src/index.d.ts", | ||
| "scripts": { | ||
| "publish-if-not-exists": "cp $NPM_CONFIG_USERCONFIG .npmrc && if [ \"$(npm show $npm_package_name@$npm_package_version version)\" = \"$(npm run current-version -s)\" ]; then echo 'already published, skipping'; else npm publish --access public; fi", | ||
| "current-version": "echo $npm_package_version" | ||
| }, | ||
| "peerDependencies": { | ||
| "@openfeature/web-sdk": ">=0.4.0" | ||
| } | ||
| } | ||
This file contains hidden or 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,76 @@ | ||
| { | ||
| "name": "providers-ofrep-web", | ||
| "$schema": "../../../node_modules/nx/schemas/project-schema.json", | ||
| "sourceRoot": "libs/providers/ofrep-web/src", | ||
| "projectType": "library", | ||
| "targets": { | ||
| "publish": { | ||
| "executor": "nx:run-commands", | ||
| "options": { | ||
| "command": "npm run publish-if-not-exists", | ||
| "cwd": "dist/libs/providers/ofrep-web" | ||
| }, | ||
| "dependsOn": [ | ||
| { | ||
| "projects": "self", | ||
| "target": "package" | ||
| } | ||
| ] | ||
| }, | ||
| "lint": { | ||
| "executor": "@nx/linter:eslint", | ||
| "outputs": ["{options.outputFile}"], | ||
| "options": { | ||
| "lintFilePatterns": ["libs/providers/ofrep-web/**/*.ts", "libs/providers/ofrep-web/package.json"] | ||
| } | ||
| }, | ||
| "test": { | ||
| "executor": "@nx/jest:jest", | ||
| "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
| "options": { | ||
| "jestConfig": "libs/providers/ofrep-web/jest.config.ts", | ||
| "passWithNoTests": true | ||
| }, | ||
| "configurations": { | ||
| "ci": { | ||
| "ci": true, | ||
| "codeCoverage": true | ||
| } | ||
| } | ||
| }, | ||
| "package": { | ||
| "executor": "@nx/rollup:rollup", | ||
| "outputs": ["{options.outputPath}"], | ||
| "options": { | ||
| "project": "libs/providers/ofrep-web/package.json", | ||
| "outputPath": "dist/libs/providers/ofrep-web", | ||
| "entryFile": "libs/providers/ofrep-web/src/index.ts", | ||
| "tsConfig": "libs/providers/ofrep-web/tsconfig.lib.json", | ||
| "buildableProjectDepsInPackageJsonType": "dependencies", | ||
| "compiler": "tsc", | ||
| "generateExportsField": true, | ||
| "umdName": "ofrep-web", | ||
| "external": "all", | ||
| "format": ["cjs", "esm"], | ||
| "assets": [ | ||
| { | ||
| "glob": "package.json", | ||
| "input": "./assets", | ||
| "output": "./src/" | ||
| }, | ||
| { | ||
| "glob": "LICENSE", | ||
| "input": "./", | ||
| "output": "./" | ||
| }, | ||
| { | ||
| "glob": "README.md", | ||
| "input": "./libs/providers/ofrep-web", | ||
| "output": "./" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "tags": [] | ||
| } |
This file contains hidden or 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 @@ | ||
| export * from './lib/ofrep-web-provider'; |
This file contains hidden or 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,4 @@ | ||
| export enum EvaluationStatus { | ||
| SUCCESS_NO_CHANGES = 'SUCCESS_NO_CHANGES', | ||
| SUCCESS_WITH_CHANGES = 'SUCCESS_WITH_CHANGES', | ||
| } |
6 changes: 6 additions & 0 deletions
6
libs/providers/ofrep-web/src/lib/model/ofrep-web-provider-options.ts
This file contains hidden or 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,6 @@ | ||
| import { FetchAPI } from '@openfeature/ofrep-core'; | ||
| export interface OfrepWebProviderOptions { | ||
|
thomaspoignant marked this conversation as resolved.
Outdated
|
||
| baseUrl: string; | ||
| pollInterval?: number; // in milliseconds | ||
| disablePolling?: boolean; | ||
|
thomaspoignant marked this conversation as resolved.
Outdated
|
||
| } | ||
This file contains hidden or 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,15 @@ | ||
| import { ResolutionReason } from '@openfeature/web-sdk'; | ||
| import { EvaluationFailureErrorCode } from '@openfeature/ofrep-core'; | ||
|
|
||
| export type ResolutionError = { | ||
| reason: ResolutionReason; | ||
| errorCode: EvaluationFailureErrorCode; | ||
| }; | ||
|
|
||
| export function isResolutionError(response: unknown): response is ResolutionError { | ||
| if (!response || typeof response !== 'object') { | ||
| return false; | ||
| } | ||
|
|
||
| return 'reason' in response && 'errorCode' in response && !('value' in response); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.