Skip to content

Commit 5d5de8e

Browse files
committed
Convert Optimizely Module
Fix comments Update formatting and add optional attribute sign Clean up Address Matt's comments part 1 Address comment part2 Incorporating commenta part 3 Incorporate comments part 4 Updating names of private methods Update private methods Create configObj interface Clean up Add back DatafileOptions Create ProjectConfigManagerConfig interface Fix LogTierV1EventProcessor compiler error without re-defining LogTierV1EventProcessorConfig Fix EventTags to not except boolean incporporating comments part 1 Incoprorate comments part 2 Returned UserAttributes type back go index.d.ts Return all types back to index.d.ts
1 parent 24baa9e commit 5d5de8e

File tree

16 files changed

+1841
-1617
lines changed

16 files changed

+1841
-1617
lines changed

packages/optimizely-sdk/CHANGELOG.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Bug fixes
11+
12+
- Fixed return type of `getAllFeatureVariables` method and `dispatchEvent ` method signature of `EventDispatcher` interface in TypeScript type definitions ([#576](https://github.com/optimizely/javascript-sdk/pull/576))
13+
1014
## [4.3.1] - October 5, 2020
1115

1216
### Bug fixes

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

Lines changed: 80 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -13,95 +13,94 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { LogHandler } from '@optimizely/js-sdk-logging';
17+
import { ProjectConfig } from '../project_config';
18+
import { UserAttributes, UserProfileService } from '../../shared_types';
19+
import { FeatureFlag, Experiment, Variation } from '../project_config/entities';
1620

17-
declare module '@optimizely/optimizely-sdk/lib/core/decision_service' {
18-
import { LogHandler } from '@optimizely/js-sdk-logging';
19-
import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config';
21+
/**
22+
* Creates an instance of the DecisionService.
23+
* @param {Options} options Configuration options
24+
* @return {DecisionService} An instance of the DecisionService
25+
*/
26+
export function createDecisionService(options: Options): DecisionService;
27+
28+
export interface DecisionService {
2029

2130
/**
22-
* Creates an instance of the DecisionService.
23-
* @param {Options} options Configuration options
24-
* @return {DecisionService} An instance of the DecisionService
31+
* Gets variation where visitor will be bucketed.
32+
* @param {ProjectConfig} configObj The parsed project configuration object
33+
* @param {string} experimentKey
34+
* @param {string} userId
35+
* @param {UserAttributes} attributes
36+
* @return {string|null} The variation the user is bucketed into.
2537
*/
26-
export function createDecisionService(options: Options): DecisionService;
27-
28-
interface DecisionService {
38+
getVariation(
39+
configObj: ProjectConfig,
40+
experimentKey: string,
41+
userId: string,
42+
attributes?: UserAttributes
43+
): string | null;
2944

30-
/**
31-
* Gets variation where visitor will be bucketed.
32-
* @param {ProjectConfig} configObj The parsed project configuration object
33-
* @param {string} experimentKey
34-
* @param {string} userId
35-
* @param {UserAttributes} attributes
36-
* @return {string|null} The variation the user is bucketed into.
37-
*/
38-
getVariation(
39-
configObj: ProjectConfig,
40-
experimentKey: string,
41-
userId: string,
42-
attributes?: import('../../shared_types').UserAttributes
43-
): string | null;
44-
45-
/**
46-
* Given a feature, user ID, and attributes, returns an object representing a
47-
* decision. If the user was bucketed into a variation for the given feature
48-
* and attributes, the returned decision object will have variation and
49-
* experiment properties (both objects), as well as a decisionSource property.
50-
* decisionSource indicates whether the decision was due to a rollout or an
51-
* experiment.
52-
* @param {ProjectConfig} configObj The parsed project configuration object
53-
* @param {FeatureFlag} feature A feature flag object from project configuration
54-
* @param {string} userId A string identifying the user, for bucketing
55-
* @param {unknown} attributes Optional user attributes
56-
* @return {Decision} An object with experiment, variation, and decisionSource
57-
* properties. If the user was not bucketed into a variation, the variation
58-
* property is null.
59-
*/
60-
getVariationForFeature(
61-
configObj: ProjectConfig,
62-
feature: import('../project_config/entities').FeatureFlag,
63-
userId: string,
64-
attributes: unknown
65-
): Decision;
45+
/**
46+
* Given a feature, user ID, and attributes, returns an object representing a
47+
* decision. If the user was bucketed into a variation for the given feature
48+
* and attributes, the returned decision object will have variation and
49+
* experiment properties (both objects), as well as a decisionSource property.
50+
* decisionSource indicates whether the decision was due to a rollout or an
51+
* experiment.
52+
* @param {ProjectConfig} configObj The parsed project configuration object
53+
* @param {FeatureFlag} feature A feature flag object from project configuration
54+
* @param {string} userId A string identifying the user, for bucketing
55+
* @param {unknown} attributes Optional user attributes
56+
* @return {Decision} An object with experiment, variation, and decisionSource
57+
* properties. If the user was not bucketed into a variation, the variation
58+
* property is null.
59+
*/
60+
getVariationForFeature(
61+
configObj: ProjectConfig,
62+
feature: FeatureFlag,
63+
userId: string,
64+
attributes: unknown
65+
): Decision;
6666

67-
/**
68-
* Removes forced variation for given userId and experimentKey
69-
* @param {unknown} userId String representing the user id
70-
* @param {string} experimentId Number representing the experiment id
71-
* @param {string} experimentKey Key representing the experiment id
72-
* @throws If the user id is not valid or not in the forced variation map
73-
*/
74-
removeForcedVariation(userId: unknown, experimentId: string, experimentKey: string): void;
67+
/**
68+
* Removes forced variation for given userId and experimentKey
69+
* @param {unknown} userId String representing the user id
70+
* @param {string} experimentId Number representing the experiment id
71+
* @param {string} experimentKey Key representing the experiment id
72+
* @throws If the user id is not valid or not in the forced variation map
73+
*/
74+
removeForcedVariation(userId: unknown, experimentId: string, experimentKey: string): void;
7575

76-
/**
77-
* Gets the forced variation key for the given user and experiment.
78-
* @param {ProjectConfig} configObj Object representing project configuration
79-
* @param {string} experimentKey Key for experiment.
80-
* @param {string} userId The user Id.
81-
* @return {string|null} Variation key that specifies the variation which the given user and experiment should be forced into.
82-
*/
83-
getForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string): string | null;
76+
/**
77+
* Gets the forced variation key for the given user and experiment.
78+
* @param {ProjectConfig} configObj Object representing project configuration
79+
* @param {string} experimentKey Key for experiment.
80+
* @param {string} userId The user Id.
81+
* @return {string|null} Variation key that specifies the variation which the given user and experiment should be forced into.
82+
*/
83+
getForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string): string | null;
8484

85-
/**
86-
* Sets the forced variation for a user in a given experiment
87-
* @param {ProjectConfig} configObj Object representing project configuration
88-
* @param {string} experimentKey Key for experiment.
89-
* @param {string} userId The user Id.
90-
* @param {unknown} variationKey Key for variation. If null, then clear the existing experiment-to-variation mapping
91-
* @return {boolean} A boolean value that indicates if the set completed successfully.
92-
*/
93-
setForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string, variationKey: unknown): boolean;
94-
}
85+
/**
86+
* Sets the forced variation for a user in a given experiment
87+
* @param {ProjectConfig} configObj Object representing project configuration
88+
* @param {string} experimentKey Key for experiment.
89+
* @param {string} userId The user Id.
90+
* @param {unknown} variationKey Key for variation. If null, then clear the existing experiment-to-variation mapping
91+
* @return {boolean} A boolean value that indicates if the set completed successfully.
92+
*/
93+
setForcedVariation(configObj: ProjectConfig, experimentKey: string, userId: string, variationKey: unknown): boolean;
94+
}
9595

96-
interface Options {
97-
userProfileService: import('../../shared_types').UserProfileService | null;
98-
logger: LogHandler;
99-
UNSTABLE_conditionEvaluators: unknown;
100-
}
96+
interface Options {
97+
userProfileService: UserProfileService | null;
98+
logger: LogHandler;
99+
UNSTABLE_conditionEvaluators: unknown;
100+
}
101101

102-
interface Decision {
103-
experiment: import('../../shared_types').Experiment | null;
104-
variation: import('../../shared_types').Variation | null;
105-
decisionSource: string;
106-
}
102+
interface Decision {
103+
experiment: Experiment | null;
104+
variation: Variation | null;
105+
decisionSource: string;
107106
}

packages/optimizely-sdk/lib/core/event_builder/event_helpers.d.ts

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,42 @@ interface ImpressionConfig {
2525
clientVersion: string;
2626
configObj: ProjectConfig;
2727
}
28+
type VisitorAttribute = {
29+
entityId: string;
30+
key: string;
31+
value: string | number | boolean;
32+
}
33+
type EventContext = {
34+
accountId: string;
35+
projectId: string;
36+
revision: string;
37+
clientName: string;
38+
clientVersion: string;
39+
anonymizeIP: boolean;
40+
botFiltering: boolean | undefined;
41+
}
2842

29-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
30-
interface ImpressionEvent {}
43+
interface ImpressionEvent {
44+
type: 'impression';
45+
timestamp: number;
46+
uuid: string;
47+
user: {
48+
id: string;
49+
attributes: VisitorAttribute[];
50+
};
51+
context: EventContext;
52+
layer: {
53+
id: string;
54+
};
55+
experiment: {
56+
id: string;
57+
key: string;
58+
} | null;
59+
variation: {
60+
id: string;
61+
key: string;
62+
} | null;
63+
}
3164

3265
interface ConversionConfig {
3366
eventKey: string;
@@ -39,8 +72,27 @@ interface ConversionConfig {
3972
configObj: ProjectConfig;
4073
}
4174

42-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
43-
interface ConversionEvent {}
75+
interface ConversionEvent {
76+
type: 'conversion';
77+
timestamp: number;
78+
uuid: string;
79+
user: {
80+
id: string;
81+
attributes: VisitorAttribute[];
82+
};
83+
context: EventContext;
84+
experiment: {
85+
id: string;
86+
key: string;
87+
};
88+
event: {
89+
id: string;
90+
key: string;
91+
};
92+
revenue: number | null;
93+
value: number | null;
94+
tags: EventTags;
95+
}
4496

4597
/**
4698
* Creates an ImpressionEvent object from decision data

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
import { ProjectConfig } from '../project_config';
1717
import { LogHandler } from '@optimizely/js-sdk-logging';
18-
import { EventTags, UserAttributes } from '../../shared_types';
19-
import { Event as EventLoggingEndpoint } from '../../shared_types';
18+
import { EventTags, UserAttributes, Event as EventLoggingEndpoint } from '../../shared_types';
2019

2120
interface ImpressionOptions {
2221
attributes?: UserAttributes;

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@
1515
* limitations under the License.
1616
*/
1717
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
18-
import {
19-
Event,
20-
EventTags,
21-
UserAttributes,
22-
Experiment,
23-
Variation
24-
} from '../../shared_types';
18+
import { EventTags, UserAttributes, Event } from '../../shared_types';
19+
import { Experiment, Variation } from '../project_config/entities';
2520

2621
export enum NOTIFICATION_TYPES {
2722
ACTIVATE = 'ACTIVATE:experiment, user_id,attributes, variation, event',
@@ -67,7 +62,6 @@ export type DecisionInfo = {
6762
};
6863

6964
export interface NotificationData {
70-
// type?: DECISION_NOTIFICATION_TYPES;
7165
type?: string;
7266
userId?: string;
7367
attributes?: UserAttributes;

packages/optimizely-sdk/lib/core/project_config/entities.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,40 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
export interface FeatureVariable {
1817
type: string;
18+
key: string;
19+
id: string;
20+
defaultValue: string;
1921
}
2022

2123
export interface FeatureFlag {
22-
variables: FeatureVariable[];
24+
rolloutId: string;
25+
key: string;
26+
id: string;
27+
experimentIds: string[],
28+
variables: FeatureVariable[],
29+
variableKeyMap: {[key: string]: FeatureVariable}
30+
}
31+
32+
export interface FeatureKeyMap {
33+
[key: string]: FeatureFlag
34+
}
35+
36+
export interface Variation {
37+
id: string;
38+
key: string;
39+
featureEnabled: boolean;
40+
variables: VariationVariable[];
41+
}
42+
43+
export interface VariationVariable {
44+
id: string;
45+
value: string;
2346
}
2447

48+
export interface Experiment {
49+
id: string;
50+
key: string;
51+
variationKeyMap: {[key: string]: Variation}
52+
}

0 commit comments

Comments
 (0)