Skip to content

Commit 4aee16a

Browse files
authored
Update to work with client version 0.5.0. (#5)
1 parent b6f4bd8 commit 4aee16a

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

__tests__/LaunchDarklyProvider.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OpenFeature, Client } from '@openfeature/js-sdk';
1+
import { OpenFeature, Client, ErrorCode } from '@openfeature/js-sdk';
22
import { LDClient } from 'launchdarkly-node-server-sdk';
33
import { LaunchDarklyProvider } from '../src';
44
import translateContext from '../src/translateContext';
@@ -210,12 +210,12 @@ describe('given a mock LaunchDarkly client', () => {
210210
});
211211

212212
it.each([
213-
['CLIENT_NOT_READY', 'PROVIDER_NOT_READY'],
214-
['MALFORMED_FLAG', 'PARSE_ERROR'],
215-
['FLAG_NOT_FOUND', 'FLAG_NOT_FOUND'],
216-
['USER_NOT_SPECIFIED', 'GENERAL'],
217-
['UNSPECIFIED', 'GENERAL'],
218-
[undefined, 'GENERAL'],
213+
['CLIENT_NOT_READY', ErrorCode.PROVIDER_NOT_READY],
214+
['MALFORMED_FLAG', ErrorCode.PARSE_ERROR],
215+
['FLAG_NOT_FOUND', ErrorCode.FLAG_NOT_FOUND],
216+
['USER_NOT_SPECIFIED', ErrorCode.TARGETING_KEY_MISSING],
217+
['UNSPECIFIED', ErrorCode.GENERAL],
218+
[undefined, ErrorCode.GENERAL],
219219
])('handles errors from the client', async (ldError, ofError) => {
220220
ldClient.variationDetail = jest.fn(async () => ({
221221
value: { yes: 'no' },

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"launchdarkly-node-server-sdk": "6.x"
2424
},
2525
"devDependencies": {
26-
"@openfeature/js-sdk": "0.4.0",
26+
"@openfeature/js-sdk": "0.5.0",
2727
"@types/jest": "^27.4.1",
2828
"@typescript-eslint/eslint-plugin": "^5.22.0",
2929
"@typescript-eslint/parser": "^5.22.0",

src/LaunchDarklyProvider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
2+
ErrorCode,
23
EvaluationContext, FlagValue, Hook,
34
JsonValue,
4-
Provider, ProviderMetadata, ResolutionDetails,
5+
Provider, ProviderMetadata, ResolutionDetails, StandardResolutionReasons,
56
} from '@openfeature/js-sdk';
67
import {
78
basicLogger, LDClient, LDLogger,
@@ -19,8 +20,8 @@ import translateResult from './translateResult';
1920
function wrongTypeResult<T>(value: T): ResolutionDetails<T> {
2021
return {
2122
value,
22-
reason: 'ERROR',
23-
errorCode: 'TYPE_MISMATCH',
23+
reason: StandardResolutionReasons.ERROR,
24+
errorCode: ErrorCode.TYPE_MISMATCH,
2425
};
2526
}
2627

src/translateResult.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
import { ResolutionDetails } from '@openfeature/js-sdk';
1+
import { ErrorCode, ResolutionDetails } from '@openfeature/js-sdk';
22
import { LDEvaluationDetail } from 'launchdarkly-node-server-sdk';
33

44
/**
55
* Convert an `errorKind` into an OpenFeature `errorCode`.
66
* @param {string} errorKind The error kind to translate.
77
* @returns {string} The OpenFeature error code.
88
*/
9-
function translateErrorKind(errorKind) {
9+
function translateErrorKind(errorKind): ErrorCode {
1010
// Error code specification.
1111
// https://github.com/open-feature/spec/blob/main/specification/sections/02-providers.md#requirement-28
1212
switch (errorKind) {
1313
case 'CLIENT_NOT_READY':
14-
return 'PROVIDER_NOT_READY';
14+
return ErrorCode.PROVIDER_NOT_READY;
1515
case 'MALFORMED_FLAG':
16-
return 'PARSE_ERROR';
16+
return ErrorCode.PARSE_ERROR;
1717
case 'FLAG_NOT_FOUND':
18-
return 'FLAG_NOT_FOUND';
18+
return ErrorCode.FLAG_NOT_FOUND;
19+
case 'USER_NOT_SPECIFIED':
20+
return ErrorCode.TARGETING_KEY_MISSING;
1921
// General errors.
20-
// 'USER_NOT_SPECIFIED' also falls through to default.
2122
default:
22-
return 'GENERAL';
23+
return ErrorCode.GENERAL;
2324
}
2425
}
2526

0 commit comments

Comments
 (0)