Skip to content

Commit 9aadf74

Browse files
feat: support metadata (go feature flag provider) (#410)
Signed-off-by: Thomas Poignant <[email protected]> Co-authored-by: Todd Baert <[email protected]>
1 parent 5bf9932 commit 9aadf74

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

libs/providers/go-feature-flag/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"current-version": "echo $npm_package_version"
77
},
88
"peerDependencies": {
9-
"@openfeature/js-sdk": "^1.0.0"
9+
"@openfeature/js-sdk": "^1.3.0"
1010
}
1111
}

libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.spec.ts

+32
Original file line numberDiff line numberDiff line change
@@ -625,5 +625,37 @@ describe('GoFeatureFlagProvider', () => {
625625
} as ResolutionDetails<object>);
626626
});
627627
});
628+
it('should return metadata associated to the flag', async () => {
629+
const flagName = 'random-flag';
630+
const targetingKey = 'user-key';
631+
const dns = `${endpoint}v1/feature/${flagName}/eval`;
632+
633+
axiosMock.onPost(dns).reply(200, {
634+
value: true,
635+
variationType: 'trueVariation',
636+
reason: StandardResolutionReasons.TARGETING_MATCH,
637+
failed: false,
638+
trackEvents: true,
639+
version: '1.0.0',
640+
metadata: {
641+
description: 'a description of the flag',
642+
issue_number: 1,
643+
}
644+
} as GoFeatureFlagProxyResponse<boolean>);
645+
646+
await goff
647+
.resolveBooleanEvaluation(flagName, false, { targetingKey })
648+
.then((res) => {
649+
expect(res).toEqual({
650+
reason: StandardResolutionReasons.TARGETING_MATCH,
651+
value: true,
652+
variant: 'trueVariation',
653+
flagMetadata: {
654+
description: 'a description of the flag',
655+
issue_number: 1,
656+
}
657+
} as ResolutionDetails<boolean>);
658+
});
659+
});
628660
});
629661
});

libs/providers/go-feature-flag/src/lib/go-feature-flag-provider.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
StandardResolutionReasons,
99
TypeMismatchError,
1010
} from '@openfeature/js-sdk';
11-
import axios, { AxiosRequestConfig } from 'axios';
11+
import axios from 'axios';
1212
import { transformContext } from './context-transformer';
1313
import { ProxyNotReady } from './errors/proxyNotReady';
1414
import { ProxyTimeout } from './errors/proxyTimeout';
@@ -55,7 +55,7 @@ export class GoFeatureFlagProvider implements Provider {
5555
* @throws {ProxyTimeout} When the HTTP call is timing out
5656
* @throws {UnknownError} When an unknown error occurs
5757
* @throws {TypeMismatchError} When the type of the variation is not the one expected
58-
* @throws {FlagNotFoundError} When the flag does not exists
58+
* @throws {FlagNotFoundError} When the flag does not exist
5959
*/
6060
async resolveBooleanEvaluation(
6161
flagKey: string,
@@ -80,7 +80,7 @@ export class GoFeatureFlagProvider implements Provider {
8080
* @throws {ProxyTimeout} When the HTTP call is timing out
8181
* @throws {UnknownError} When an unknown error occurs
8282
* @throws {TypeMismatchError} When the type of the variation is not the one expected
83-
* @throws {FlagNotFoundError} When the flag does not exists
83+
* @throws {FlagNotFoundError} When the flag does not exist
8484
*/
8585
async resolveStringEvaluation(
8686
flagKey: string,
@@ -105,7 +105,7 @@ export class GoFeatureFlagProvider implements Provider {
105105
* @throws {ProxyTimeout} When the HTTP call is timing out
106106
* @throws {UnknownError} When an unknown error occurs
107107
* @throws {TypeMismatchError} When the type of the variation is not the one expected
108-
* @throws {FlagNotFoundError} When the flag does not exists
108+
* @throws {FlagNotFoundError} When the flag does not exist
109109
*/
110110
async resolveNumberEvaluation(
111111
flagKey: string,
@@ -130,7 +130,7 @@ export class GoFeatureFlagProvider implements Provider {
130130
* @throws {ProxyTimeout} When the HTTP call is timing out
131131
* @throws {UnknownError} When an unknown error occurs
132132
* @throws {TypeMismatchError} When the type of the variation is not the one expected
133-
* @throws {FlagNotFoundError} When the flag does not exists
133+
* @throws {FlagNotFoundError} When the flag does not exist
134134
*/
135135
async resolveObjectEvaluation<U extends JsonValue>(
136136
flagKey: string,
@@ -227,15 +227,16 @@ export class GoFeatureFlagProvider implements Provider {
227227

228228
// Case of the flag is disabled
229229
if (apiResponseData.reason === StandardResolutionReasons.DISABLED) {
230-
// we don't set a variant since we are using the default value and we are not able to know
230+
// we don't set a variant since we are using the default value, and we are not able to know
231231
// which variant it is.
232232
return { value: defaultValue, reason: apiResponseData.reason };
233233
}
234234

235235
const sdkResponse: ResolutionDetails<T> = {
236236
value: apiResponseData.value,
237237
variant: apiResponseData.variationType,
238-
reason: apiResponseData.reason?.toString() || 'UNKNOWN'
238+
reason: apiResponseData.reason?.toString() || 'UNKNOWN',
239+
flagMetadata: apiResponseData.metadata || undefined,
239240
};
240241
if (Object.values(ErrorCode).includes(apiResponseData.errorCode as ErrorCode)) {
241242
sdkResponse.errorCode = ErrorCode[apiResponseData.errorCode as ErrorCode];

libs/providers/go-feature-flag/src/lib/model.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface GoFeatureFlagProxyResponse<T> {
3737
variationType: string;
3838
version?: string;
3939
reason: string | GOFeatureFlagResolutionReasons;
40+
metadata: Record<string, string | number | boolean>;
4041
errorCode?: ErrorCode | GOFeatureFlagErrorCode;
4142
}
4243

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@nx/rollup": "16.2.2",
3939
"@nx/web": "16.2.2",
4040
"@nx/workspace": "16.2.2",
41-
"@openfeature/js-sdk": "^1.1.0",
41+
"@openfeature/js-sdk": "^1.3.1",
4242
"@swc-node/register": "~1.6.0",
4343
"@swc/cli": "~0.1.62",
4444
"@swc/core": "~1.3.51",

0 commit comments

Comments
 (0)