Skip to content

Commit 553dd69

Browse files
authored
fix: Fix type definitions to avoid compiling source files (#655)
* WIP * Clean up * Add getUserId and getAttributes * Move OptimizelyUserContext and OptimizelyDecision interfaces to shared_types
1 parent 7969661 commit 553dd69

File tree

5 files changed

+53
-30
lines changed

5 files changed

+53
-30
lines changed

packages/optimizely-sdk/lib/index.d.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,31 @@ declare module '@optimizely/optimizely-sdk' {
4343

4444
export type OptimizelyFeature = import('./shared_types').OptimizelyFeature;
4545

46-
export type EventTags = import ('./shared_types').EventTags;
46+
export type EventTags = import('./shared_types').EventTags;
4747

48-
export type Event = import ('./shared_types').Event;
48+
export type Event = import('./shared_types').Event;
4949

50-
export type EventDispatcher = import ('./shared_types').EventDispatcher;
50+
export type EventDispatcher = import('./shared_types').EventDispatcher;
5151

52-
export type DatafileOptions = import ('./shared_types').DatafileOptions;
52+
export type DatafileOptions = import('./shared_types').DatafileOptions;
5353

54-
export type SDKOptions = import ('./shared_types').SDKOptions;
54+
export type SDKOptions = import('./shared_types').SDKOptions;
5555

56-
export type OptimizelyOptions = import ('./shared_types').OptimizelyOptions;
56+
export type OptimizelyOptions = import('./shared_types').OptimizelyOptions;
5757

5858
export type UserProfileService = import('./shared_types').UserProfileService;
5959

6060
export type UserProfile = import('./shared_types').UserProfile;
6161

6262
export type ListenerPayload = import('./shared_types').ListenerPayload;
6363

64-
export type OptimizelyUserContext = import('./optimizely_user_context').default;
64+
export type OptimizelyDecision = import('./shared_types').OptimizelyDecision;
6565

66-
export type OptimizelyDecision = import('./optimizely_decision').OptimizelyDecision;
66+
export type OptimizelyUserContext = import('./shared_types').OptimizelyUserContext;
6767

6868
export enum OptimizelyDecideOption {
6969
DISABLE_DECISION_EVENT = 'DISABLE_DECISION_EVENT',
70-
ENABLED_FLAGS_ONLY = 'ENABLED_FLAGS_ONLY',
70+
ENABLED_FLAGS_ONLY = 'ENABLED_FLAGS_ONLY',
7171
IGNORE_USER_PROFILE_SERVICE = 'IGNORE_USER_PROFILE_SERVICE',
7272
INCLUDE_REASONS = 'INCLUDE_REASONS',
7373
EXCLUDE_VARIABLES = 'EXCLUDE_VARIABLES'

packages/optimizely-sdk/lib/optimizely/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ import {
2626
FeatureFlag,
2727
FeatureVariable,
2828
OptimizelyOptions,
29-
OptimizelyDecideOption
29+
OptimizelyDecideOption,
30+
OptimizelyDecision
3031
} from '../shared_types';
31-
import { OptimizelyDecision, newErrorDecision } from '../optimizely_decision';
32+
import { newErrorDecision } from '../optimizely_decision';
3233
import OptimizelyUserContext from '../optimizely_user_context';
3334
import { createProjectConfigManager, ProjectConfigManager } from '../core/project_config/project_config_manager';
3435
import { createNotificationCenter, NotificationCenter } from '../core/notification_center';

packages/optimizely-sdk/lib/optimizely_decision/index.ts

+1-17
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,7 @@
1313
* See the License for the specific language governing permissions and *
1414
* limitations under the License. *
1515
***************************************************************************/
16-
import OptimizelyUserContext from '../optimizely_user_context';
17-
18-
export interface OptimizelyDecision {
19-
variationKey: string | null;
20-
// The boolean value indicating if the flag is enabled or not
21-
enabled: boolean;
22-
// The collection of variables associated with the decision
23-
variables: { [variableKey: string]: unknown };
24-
// The rule key of the decision
25-
ruleKey: string | null;
26-
// The flag key for which the decision has been made for
27-
flagKey: string;
28-
// A copy of the user context for which the decision has been made for
29-
userContext: OptimizelyUserContext;
30-
// An array of error/info messages describing why the decision has been made.
31-
reasons: string[];
32-
}
16+
import { OptimizelyUserContext, OptimizelyDecision } from '../shared_types';
3317

3418
export function newErrorDecision(key: string, user: OptimizelyUserContext, reasons: string[]): OptimizelyDecision {
3519
return {

packages/optimizely-sdk/lib/optimizely_user_context/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
* limitations under the License. *
1515
***************************************************************************/
1616
import Optimizely from '../../lib/optimizely';
17-
import { UserAttributes, OptimizelyDecideOption, EventTags } from '../../lib/shared_types';
18-
import { OptimizelyDecision } from '../optimizely_decision';
17+
import {
18+
UserAttributes,
19+
OptimizelyDecideOption,
20+
OptimizelyDecision,
21+
EventTags
22+
} from '../../lib/shared_types';
1923

2024
export default class OptimizelyUserContext {
2125
private optimizely: Optimizely;

packages/optimizely-sdk/lib/shared_types.ts

+34
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,37 @@ export interface OptimizelyConfig {
249249
revision: string;
250250
getDatafile(): string;
251251
}
252+
253+
export interface OptimizelyUserContext {
254+
getUserId(): string;
255+
getAttributes(): UserAttributes;
256+
setAttribute(key: string, value: unknown): void;
257+
decide(
258+
key: string,
259+
options: OptimizelyDecideOption[]
260+
): OptimizelyDecision;
261+
decideForKeys(
262+
keys: string[],
263+
options: OptimizelyDecideOption[],
264+
): { [key: string]: OptimizelyDecision };
265+
decideAll(
266+
options: OptimizelyDecideOption[],
267+
): { [key: string]: OptimizelyDecision };
268+
trackEvent(eventName: string, eventTags?: EventTags): void;
269+
}
270+
271+
export interface OptimizelyDecision {
272+
variationKey: string | null;
273+
// The boolean value indicating if the flag is enabled or not
274+
enabled: boolean;
275+
// The collection of variables associated with the decision
276+
variables: { [variableKey: string]: unknown };
277+
// The rule key of the decision
278+
ruleKey: string | null;
279+
// The flag key for which the decision has been made for
280+
flagKey: string;
281+
// A copy of the user context for which the decision has been made for
282+
userContext: OptimizelyUserContext;
283+
// An array of error/info messages describing why the decision has been made.
284+
reasons: string[];
285+
}

0 commit comments

Comments
 (0)