Skip to content

Commit

Permalink
Merge branch 'main' into luizgribeiro/#565/inMemoryClient
Browse files Browse the repository at this point in the history
Signed-off-by: Luiz Guilherme Ribeiro <[email protected]>
  • Loading branch information
luizgribeiro authored Oct 26, 2023
2 parents 1ff7ae8 + 8e873a3 commit e3f6c87
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
node-version: 16
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/dco-merge-group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: DCO
on:
merge_group:

# Workaround because the DCO app doesn't run on a merge_group trigger
# https://github.com/dcoapp/app/pull/200
jobs:
DCO:
runs-on: ubuntu-latest
if: ${{ github.actor != 'renovate[bot]' }}
steps:
- run: echo "dummy DCO workflow (it won't run any check actually) to trigger by merge_group in order to enable merge queue"
7 changes: 4 additions & 3 deletions .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- reopened
branches:
- main
merge_group:

jobs:
build-test-lint:
Expand All @@ -22,7 +23,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
Expand All @@ -44,7 +45,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
cache: 'npm'
Expand All @@ -69,7 +70,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
# we need 'fetch' for this test, which is only in 18
node-version: 18
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ jobs:
release_created: ${{ steps.release.outputs.releases_created }}

npm-release:
needs: Release-please
needs: release-please
runs-on: ubuntu-latest
if: ${{ needs.release-please.outputs.release_created }}
steps:
# The logic below handles the npm publication:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 16
registry-url: "https://registry.npmjs.org"
Expand Down
101 changes: 71 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"node": ">=16"
},
"devDependencies": {
"@openfeature/flagd-provider": "^0.8.1",
"@openfeature/flagd-provider": "^0.9.0",
"@openfeature/flagd-web-provider": "^0.4.0",
"@rollup/plugin-alias": "^5.0.0",
"@rollup/plugin-typescript": "^11.0.0",
Expand All @@ -46,7 +46,7 @@
"@typescript-eslint/parser": "^5.23.0",
"esbuild": "^0.17.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-check-file": "^2.0.0",
"eslint-plugin-import": "^2.26.0",
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from './client';
export * from './provider';
export * from './evaluation';
export * from './open-feature';
export * from './transaction-context';
export * from '@openfeature/shared';
45 changes: 44 additions & 1 deletion packages/server/src/open-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import {
objectOrUndefined,
stringOrUndefined,
} from '@openfeature/shared';
import {
ManageTransactionContextPropagator,
NOOP_TRANSACTION_CONTEXT_PROPAGATOR,
TransactionContext,
TransactionContextPropagator,
} from './transaction-context';
import { Client, OpenFeatureClient } from './client';

// use a symbol as a key for the global singleton
Expand All @@ -16,7 +22,11 @@ type OpenFeatureGlobal = {
};
const _globalThis = globalThis as OpenFeatureGlobal;

export class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> implements ManageContext<OpenFeatureAPI> {
export class OpenFeatureAPI
extends OpenFeatureCommonAPI<Provider>
implements ManageContext<OpenFeatureAPI>, ManageTransactionContextPropagator<OpenFeatureCommonAPI<Provider>>
{
private _transactionContextPropagator: TransactionContextPropagator = NOOP_TRANSACTION_CONTEXT_PROPAGATOR;
protected _defaultProvider: Provider = NOOP_PROVIDER;

private constructor() {
Expand Down Expand Up @@ -111,6 +121,39 @@ export class OpenFeatureAPI extends OpenFeatureCommonAPI<Provider> implements Ma
clearProviders(): Promise<void> {
return super.clearProvidersAndSetDefault(NOOP_PROVIDER);
}

setTransactionContextPropagator(
transactionContextPropagator: TransactionContextPropagator
): OpenFeatureCommonAPI<Provider> {
const baseMessage = 'Invalid TransactionContextPropagator, will not be set: ';
if (typeof transactionContextPropagator?.getTransactionContext !== 'function') {
this._logger.error(`${baseMessage}: getTransactionContext is not a function.`);
} else if (typeof transactionContextPropagator?.setTransactionContext !== 'function') {
this._logger.error(`${baseMessage}: setTransactionContext is not a function.`);
} else {
this._transactionContextPropagator = transactionContextPropagator;
}
return this;
}

setTransactionContext<R>(
transactionContext: TransactionContext,
callback: (...args: unknown[]) => R,
...args: unknown[]
): void {
this._transactionContextPropagator.setTransactionContext(transactionContext, callback, ...args);
}

getTransactionContext(): TransactionContext {
try {
return this._transactionContextPropagator.getTransactionContext();
} catch (err: unknown) {
const error = err as Error | undefined;
this._logger.error(`Error getting transaction context: ${error?.message}, returning empty context.`);
this._logger.error(error?.stack);
return {};
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EvaluationContext } from '../evaluation';
import { EvaluationContext } from '@openfeature/shared';
import { TransactionContextPropagator } from './transaction-context';

class NoopTransactionContextPropagator implements TransactionContextPropagator {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EvaluationContext } from '../evaluation';
import { EvaluationContext } from '@openfeature/shared';

/**
* Transaction context is a mechanism for adding transaction specific context that
Expand Down
1 change: 0 additions & 1 deletion packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ export * from './events';
export * from './logger';
export * from './provider';
export * from './evaluation';
export * from './transaction-context';
export * from './type-guards';
export * from './open-feature';
Loading

0 comments on commit e3f6c87

Please sign in to comment.