Skip to content

Commit c79e772

Browse files
yavoronauzair-folio3
andauthored
feat: Convert optimizely module to TS (#576)
* added declaration file for notification center * comment addressed: seperate declaration file for event_helper event_helper.d.ts * event_helpers module name and declaration file name corrected * EOL in event_helpers.d.ts * 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 * Optimize imports and rebase * Optimize exports * Optimize NOTIFICATION_TYPES export * Fix indentation and remove unnecessary if statement Co-authored-by: uzair-folio3 <unadeem@folio3.com>
1 parent 405bdd0 commit c79e772

File tree

16 files changed

+1965
-1768
lines changed

16 files changed

+1965
-1768
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: 89 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,97 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { ProjectConfig } from '../project_config';
17+
import { EventTags, UserAttributes } from '../../shared_types';
1618

17-
declare module '@optimizely/optimizely-sdk/lib/core/event_builder' {
18-
import { ProjectConfig } from '@optimizely/optimizely-sdk/lib/core/project_config';
19-
20-
interface ImpressionConfig {
21-
experimentKey: string;
22-
variationKey: string;
23-
userId: string;
24-
userAttributes: import('../../shared_types').UserAttributes;
25-
clientEngine: string;
26-
clientVersion: string;
27-
configObj: ProjectConfig;
28-
}
19+
interface ImpressionConfig {
20+
experimentKey: string;
21+
variationKey: string;
22+
userId: string;
23+
userAttributes?: UserAttributes;
24+
clientEngine: string;
25+
clientVersion: string;
26+
configObj: ProjectConfig;
27+
}
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+
}
2942

30-
interface ConversionConfig {
31-
eventKey: string;
32-
eventTags: import('../../shared_types').EventTags;
33-
userId: string;
34-
userAttributes: import('../../shared_types').UserAttributes;
35-
clientEngine: string;
36-
clientVersion: string;
37-
configObj: ProjectConfig;
38-
}
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+
}
3964

40-
/**
41-
* Creates an ImpressionEvent object from decision data
42-
* @param {ImpressionConfig} config
43-
* @return {ImpressionEvent} an ImpressionEvent object
44-
*/
45-
export function buildImpressionEvent(config: ImpressionConfig): import('@optimizely/js-sdk-event-processor').ImpressionEvent;
65+
interface ConversionConfig {
66+
eventKey: string;
67+
eventTags?: EventTags;
68+
userId: string;
69+
userAttributes?: UserAttributes;
70+
clientEngine: string;
71+
clientVersion: string;
72+
configObj: ProjectConfig;
73+
}
4674

47-
/**
48-
* Creates a ConversionEvent object from track
49-
* @param {ConversionConfig} config
50-
* @return {ConversionEvent} a ConversionEvent object
51-
*/
52-
export function buildConversionEvent(config: ConversionConfig): import('@optimizely/js-sdk-event-processor').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;
5395
}
96+
97+
/**
98+
* Creates an ImpressionEvent object from decision data
99+
* @param {ImpressionConfig} config
100+
* @return {ImpressionEvent} an ImpressionEvent object
101+
*/
102+
export function buildImpressionEvent(config: ImpressionConfig): ImpressionEvent;
103+
104+
/**
105+
* Creates a ConversionEvent object from track
106+
* @param {ConversionConfig} config
107+
* @return {ConversionEvent} a ConversionEvent object
108+
*/
109+
export function buildConversionEvent(config: ConversionConfig): ConversionEvent;

0 commit comments

Comments
 (0)