Skip to content

Commit 979dadb

Browse files
author
uzair-folio3
committed
Merge branch 'pnguen/optimizely-module-to-ts' into uzair/react_native_js_to_ts
2 parents cb7a600 + 8da7267 commit 979dadb

File tree

12 files changed

+104
-36
lines changed

12 files changed

+104
-36
lines changed

packages/optimizely-sdk/CHANGELOG.MD

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Bug fixes
1111

12-
- Fixed return type of `getAllFeatureVariables` method in TypeScript type definitions ([#576](https://github.com/optimizely/javascript-sdk/pull/576))
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+
14+
## [4.3.0] - October 1, 2020
15+
16+
### New Features
17+
18+
- Added support for version audience evaluation ([#517](https://github.com/optimizely/javascript-sdk/pull/571))
19+
- Add datafile accessor ([#564](https://github.com/optimizely/javascript-sdk/pull/564))
1320

1421
## [4.2.1] - August 10, 2020
1522

@@ -19,11 +26,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1926
## [4.2.0] - July 31, 2020
2027

2128
### New Features
29+
2230
- Better offline support in React Native apps:
2331
- Persist downloaded datafiles in local storage for use in subsequent SDK initializations ([#430](https://github.com/optimizely/javascript-sdk/pull/430))
2432
- Persist pending impression & conversion events in local storage ([#517](https://github.com/optimizely/javascript-sdk/pull/517), [#532](https://github.com/optimizely/javascript-sdk/pull/532))
2533

2634
### Bug fixes
35+
2736
- Fixed log messages for Targeted Rollouts ([#515](https://github.com/optimizely/javascript-sdk/pull/515))
2837

2938
## [4.1.0] - July 7, 2020

packages/optimizely-sdk/lib/core/project_config/project_config_manager.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ interface ProjectConfigManagerConfig {
2929
* ProjectConfigManager provides project config objects via its methods
3030
* getConfig and onUpdate. It uses a DatafileManager to fetch datafiles. It is
3131
* responsible for parsing and validating datafiles, and converting datafile
32-
* JSON objects into project config objects.
32+
* string into project config objects.
3333
* @param {ProjectConfig} config
34-
* @param {Object|string} config.datafile
34+
* @param {string} config.datafile
3535
* @param {Object} config.datafileOptions
3636
* @param {Object} config.jsonSchemaValidator
3737
* @param {string} config.sdkKey

packages/optimizely-sdk/lib/core/project_config/project_config_manager.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ function getErrorMessage(maybeError, defaultMessage) {
4444
* ProjectConfigManager provides project config objects via its methods
4545
* getConfig and onUpdate. It uses a DatafileManager to fetch datafiles. It is
4646
* responsible for parsing and validating datafiles, and converting datafile
47-
* JSON objects into project config objects.
47+
* string into project config objects.
4848
* @param {Object} config
49-
* @param {Object|string=} config.datafile
49+
* @param {string} config.datafile
5050
* @param {Object=} config.datafileOptions
5151
* @param {Object=} config.jsonSchemaValidator
5252
* @param {string=} config.sdkKey

packages/optimizely-sdk/lib/index.browser.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('javascript-sdk', function() {
148148
optlyInstance.onReady().catch(function() {});
149149

150150
assert.instanceOf(optlyInstance, Optimizely);
151-
assert.equal(optlyInstance.clientVersion, '4.2.1');
151+
assert.equal(optlyInstance.clientVersion, '4.3.0');
152152
});
153153

154154
it('should set the JavaScript client engine and version', function() {

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

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,72 +67,72 @@ declare module '@optimizely/optimizely-sdk' {
6767
activate(
6868
experimentKey: string,
6969
userId: string,
70-
attributes?: import('./shared_types').UserAttributes
70+
attributes?: UserAttributes
7171
): string | null;
7272
track(
7373
eventKey: string,
7474
userId: string,
75-
attributes?: import('./shared_types').UserAttributes,
75+
attributes?: UserAttributes,
7676
eventTags?: EventTags
7777
): void;
7878
getVariation(
7979
experimentKey: string,
8080
userId: string,
81-
attributes?: import('./shared_types').UserAttributes
81+
attributes?: UserAttributes
8282
): string | null;
8383
setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean;
8484
getForcedVariation(experimentKey: string, userId: string): string | null;
8585
isFeatureEnabled(
8686
featureKey: string,
8787
userId: string,
88-
attributes?: import('./shared_types').UserAttributes
88+
attributes?: UserAttributes
8989
): boolean;
9090
getEnabledFeatures(
9191
userId: string,
92-
attributes?: import('./shared_types').UserAttributes
92+
attributes?: UserAttributes
9393
): string[];
9494
getFeatureVariable(
9595
featureKey: string,
9696
variableKey: string,
9797
userId: string,
98-
attributes?: import('./shared_types').UserAttributes
98+
attributes?: UserAttributes
9999
): unknown;
100100
getFeatureVariableBoolean(
101101
featureKey: string,
102102
variableKey: string,
103103
userId: string,
104-
attributes?: import('./shared_types').UserAttributes
104+
attributes?: UserAttributes
105105
): boolean | null;
106106
getFeatureVariableDouble(
107107
featureKey: string,
108108
variableKey: string,
109109
userId: string,
110-
attributes?: import('./shared_types').UserAttributes
110+
attributes?: UserAttributes
111111
): number | null;
112112
getFeatureVariableInteger(
113113
featureKey: string,
114114
variableKey: string,
115115
userId: string,
116-
attributes?: import('./shared_types').UserAttributes
116+
attributes?: UserAttributes
117117
): number | null;
118118
getFeatureVariableString(
119119
featureKey: string,
120120
variableKey: string,
121121
userId: string,
122-
attributes?: import('./shared_types').UserAttributes
122+
attributes?: UserAttributes
123123
): string | null;
124124
getFeatureVariableJSON(
125125
featureKey: string,
126126
variableKey: string,
127127
userId: string,
128-
attributes?: import('./shared_types').UserAttributes
128+
attributes?: UserAttributes
129129
): unknown;
130130
getAllFeatureVariables(
131131
featureKey: string,
132132
userId: string,
133-
attributes?: import('./shared_types').UserAttributes
133+
attributes?: UserAttributes
134134
): { [variableKey: string]: unknown } | null;
135-
getOptimizelyConfig(): import('./shared_types').OptimizelyConfig | null;
135+
getOptimizelyConfig(): OptimizelyConfig | null;
136136
onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }>;
137137
close(): Promise<{ success: boolean; reason?: string }>;
138138
}
@@ -150,6 +150,61 @@ declare module '@optimizely/optimizely-sdk' {
150150
params: any;
151151
}
152152

153+
export type UserAttributes = {
154+
// TODO[OASIS-6649]: Don't use any type
155+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
156+
[name: string]: any;
157+
}
158+
159+
/**
160+
* Optimizely Config Entities
161+
*/
162+
export interface OptimizelyExperiment {
163+
id: string;
164+
key: string;
165+
variationsMap: {
166+
[variationKey: string]: OptimizelyVariation;
167+
};
168+
}
169+
170+
export interface OptimizelyVariable {
171+
id: string;
172+
key: string;
173+
type: string;
174+
value: string;
175+
}
176+
177+
export interface OptimizelyFeature {
178+
id: string;
179+
key: string;
180+
experimentsMap: {
181+
[experimentKey: string]: OptimizelyExperiment;
182+
};
183+
variablesMap: {
184+
[variableKey: string]: OptimizelyVariable;
185+
};
186+
}
187+
188+
export interface OptimizelyVariation {
189+
id: string;
190+
key: string;
191+
featureEnabled?: boolean;
192+
variablesMap: {
193+
[variableKey: string]: OptimizelyVariable;
194+
};
195+
}
196+
197+
export interface OptimizelyConfig {
198+
experimentsMap: {
199+
[experimentKey: string]: OptimizelyExperiment;
200+
};
201+
featuresMap: {
202+
[featureKey: string]: OptimizelyFeature;
203+
};
204+
revision: string;
205+
getDatafile(): string;
206+
}
207+
153208
export interface EventDispatcher {
154209
/**
155210
* @param event
@@ -158,7 +213,7 @@ declare module '@optimizely/optimizely-sdk' {
158213
* After the event has at least been queued for dispatch, call this function to return
159214
* control back to the Client.
160215
*/
161-
dispatchEvent: (event: Event, callback: () => void) => void;
216+
dispatchEvent: (event: Event, callback: (response: { statusCode: number; }) => void) => void;
162217
}
163218

164219
export type EventTags = {
@@ -180,7 +235,7 @@ declare module '@optimizely/optimizely-sdk' {
180235

181236
export interface ListenerPayload {
182237
userId: string;
183-
attributes: import('./shared_types').UserAttributes;
238+
attributes: UserAttributes;
184239
}
185240

186241
export interface ActivateListenerPayload extends ListenerPayload {

packages/optimizely-sdk/lib/index.node.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('optimizelyFactory', function() {
9090
optlyInstance.onReady().catch(function() {});
9191

9292
assert.instanceOf(optlyInstance, Optimizely);
93-
assert.equal(optlyInstance.clientVersion, '4.2.1');
93+
assert.equal(optlyInstance.clientVersion, '4.3.0');
9494
});
9595

9696
describe('event processor configuration', function() {

packages/optimizely-sdk/lib/index.react_native.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('javascript-sdk/react-native', function() {
8989
optlyInstance.onReady().catch(function() {});
9090

9191
assert.instanceOf(optlyInstance, Optimizely);
92-
assert.equal(optlyInstance.clientVersion, '4.2.1');
92+
assert.equal(optlyInstance.clientVersion, '4.3.0');
9393
});
9494

9595
it('should set the Javascript client engine and version', function() {

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
***************************************************************************/
1616
import { sprintf, objectValues } from '@optimizely/js-sdk-utils';
1717
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
18-
// import {EventDispatcher} from '@optimizely/js-sdk-event-processor';
1918
import { FeatureFlag, FeatureVariable } from '../core/project_config/entities';
2019
import {
2120
UserAttributes,
2221
EventTags,
2322
OptimizelyConfig,
2423
UserProfileService,
2524
DatafileOptions,
26-
EventDispatcher
25+
EventDispatcher,
26+
OnReadyResult
2727
} from '../shared_types';
2828
import { Variation } from '../core/project_config/entities';
2929
import { createProjectConfigManager, ProjectConfigManager } from '../core/project_config/project_config_manager';
@@ -540,8 +540,7 @@ export class Optimizely {
540540
*/
541541
private validateInputs(
542542
// TODO: Make feature_key, user_id, variable_key, experiment_key camelCase
543-
// stringInputs: Record<'feature_key' | 'user_id' | 'variable_key' | 'experiment_key', unknown>,
544-
stringInputs: unknown,
543+
stringInputs: Partial<Record<'feature_key' | 'user_id' | 'variable_key' | 'experiment_key' | 'event_key', unknown>>,
545544
userAttributes?: unknown,
546545
eventTags?: unknown
547546
): boolean {
@@ -1330,7 +1329,7 @@ export class Optimizely {
13301329
* @param {number|undefined} options.timeout
13311330
* @return {Promise}
13321331
*/
1333-
onReady(options?: { timeout?: number }): Promise<{ success: boolean; reason?: string }> {
1332+
onReady(options?: { timeout?: number }): Promise<OnReadyResult> {
13341333
let timeoutValue: number | undefined;
13351334
if (typeof options === 'object' && options !== null) {
13361335
if (options.timeout !== undefined) {
@@ -1341,9 +1340,9 @@ export class Optimizely {
13411340
timeoutValue = DEFAULT_ONREADY_TIMEOUT;
13421341
}
13431342

1344-
let resolveTimeoutPromise: (value?: { success: boolean; reason?: string | undefined; }) => void;
1345-
const timeoutPromise = new Promise(
1346-
function(resolve: (value?: { success: boolean; reason?: string | undefined; }) => void) {
1343+
let resolveTimeoutPromise: (value: OnReadyResult) => void;
1344+
const timeoutPromise = new Promise<OnReadyResult>(
1345+
(resolve) => {
13471346
resolveTimeoutPromise = resolve;
13481347
}
13491348
);
@@ -1357,7 +1356,7 @@ export class Optimizely {
13571356
success: false,
13581357
reason: sprintf('onReady timeout expired after %s ms', timeoutValue),
13591358
});
1360-
}).bind(this);
1359+
});
13611360
const readyTimeout = setTimeout(onReadyTimeout, timeoutValue);
13621361
const onClose = function() {
13631362
resolveTimeoutPromise({

packages/optimizely-sdk/lib/shared_types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ export interface EventDispatcher {
4949
* After the event has at least been queued for dispatch, call this function to return
5050
* control back to the Client.
5151
*/
52-
dispatchEvent: (event: Event, callback: () => void) => void;
52+
dispatchEvent: (event: Event, callback: (response: { statusCode: number; }) => void) => void;
53+
}
54+
55+
export interface OnReadyResult {
56+
success: boolean;
57+
reason?: string;
5358
}
5459

5560
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const CONTROL_ATTRIBUTES = {
173173
export const JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk';
174174
export const NODE_CLIENT_ENGINE = 'node-sdk';
175175
export const REACT_CLIENT_ENGINE = 'react-sdk';
176-
export const NODE_CLIENT_VERSION = '4.2.1';
176+
export const NODE_CLIENT_VERSION = '4.3.0';
177177

178178
export const VALID_CLIENT_ENGINES = [
179179
NODE_CLIENT_ENGINE,

packages/optimizely-sdk/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/optimizely-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@optimizely/optimizely-sdk",
3-
"version": "4.2.1",
3+
"version": "4.3.0",
44
"description": "JavaScript SDK for Optimizely X Full Stack",
55
"module": "dist/optimizely.browser.es.min.js",
66
"main": "dist/optimizely.node.min.js",

0 commit comments

Comments
 (0)