Skip to content

refactor: Replaced explicit typings with auto generated ones #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/optimizely-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed
- Add package.json script for running Karma tests locally using Chrome ([#651](https://github.com/optimizely/javascript-sdk/pull/651)).
- Replaced explicit typescript typings with auto generated ones ([#745](https://github.com/optimizely/javascript-sdk/pull/745))

## [4.9.1] - January 18, 2022

Expand All @@ -18,13 +19,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [4.9.0] - January 14, 2022

### New Features
* Add a set of new APIs for overriding and managing user-level flag, experiment and delivery rule decisions. These methods can be used for QA and automated testing purposes. They are an extension of the OptimizelyUserContext interface ([#705](https://github.com/optimizely/javascript-sdk/pull/705), [#727](https://github.com/optimizely/javascript-sdk/pull/727), [#729](https://github.com/optimizely/javascript-sdk/pull/729), [#730](https://github.com/optimizely/javascript-sdk/pull/730)):
- Add a set of new APIs for overriding and managing user-level flag, experiment and delivery rule decisions. These methods can be used for QA and automated testing purposes. They are an extension of the OptimizelyUserContext interface ([#705](https://github.com/optimizely/javascript-sdk/pull/705), [#727](https://github.com/optimizely/javascript-sdk/pull/727), [#729](https://github.com/optimizely/javascript-sdk/pull/729), [#730](https://github.com/optimizely/javascript-sdk/pull/730)):
- setForcedDecision
- getForcedDecision
- removeForcedDecision
- removeAllForcedDecisions

* For details, refer to our documentation pages: [OptimizelyUserContext](https://docs.developers.optimizely.com/full-stack/v4.0/docs/optimizelyusercontext-javascript-node) and [Forced Decision methods](https://docs.developers.optimizely.com/full-stack/v4.0/docs/forced-decision-methods-javascript-node).
- For details, refer to our documentation pages: [OptimizelyUserContext](https://docs.developers.optimizely.com/full-stack/v4.0/docs/optimizelyusercontext-javascript-node) and [Forced Decision methods](https://docs.developers.optimizely.com/full-stack/v4.0/docs/forced-decision-methods-javascript-node).

## [4.8.0] - November 29, 2021

Expand Down
4 changes: 3 additions & 1 deletion packages/optimizely-sdk/lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ import {
} from '../../shared_types';

interface TryCreatingProjectConfigConfig {
datafile: string;
// TODO[OASIS-6649]: Don't use object type
// eslint-disable-next-line @typescript-eslint/ban-types
datafile: string | object;
jsonSchemaValidator?: {
validate(jsonObject: unknown): boolean,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const logger = getLogger();
const MODULE_NAME = 'PROJECT_CONFIG_MANAGER';

interface ProjectConfigManagerConfig {
datafile?: string,
// TODO[OASIS-6649]: Don't use object type
// eslint-disable-next-line @typescript-eslint/ban-types
datafile?: string | object,
jsonSchemaValidator?: {
validate(jsonObject: unknown): boolean,
};
Expand Down Expand Up @@ -169,10 +171,12 @@ export class ProjectConfigManager {
* the new config object's revision is newer than the current one, sets/updates the project config
* and optimizely config object instance variables and returns null for the error. If unsuccessful,
* the project config and optimizely config objects will not be updated, and the error is returned.
* @param {string} newDatafile
* @param {string | object} newDatafile
* @returns {Error|null} error or null
*/
private handleNewDatafile(newDatafile: string): Error | null {
// TODO[OASIS-6649]: Don't use object type
// eslint-disable-next-line @typescript-eslint/ban-types
private handleNewDatafile(newDatafile: string | object): Error | null {
const { configObj, error } = tryCreatingProjectConfig({
datafile: newDatafile,
jsonSchemaValidator: this.jsonSchemaValidator,
Expand Down
26 changes: 26 additions & 0 deletions packages/optimizely-sdk/lib/export_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export {
UserAttributes,
OptimizelyConfig,
OptimizelyVariable,
OptimizelyVariation,
OptimizelyExperiment,
OptimizelyFeature,
OptimizelyDecisionContext,
OptimizelyForcedDecision,
EventTags,
Event,
EventDispatcher,
DatafileOptions,
OptimizelyOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDKOptions and OptimizelyOptions are not needed to be exposed. Config is enough for external usage

UserProfileService,
UserProfile,
ListenerPayload,
OptimizelyDecision,
OptimizelyUserContext,
NotificationListener,
Config,
Client,
ActivateListenerPayload,
TrackListenerPayload,
NotificationCenter
} from './shared_types'
11 changes: 7 additions & 4 deletions packages/optimizely-sdk/lib/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Optimizely from './optimizely';
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
import { createNotificationCenter } from './core/notification_center';
import { default as eventProcessor } from './plugins/event_processor';
import { SDKOptions, OptimizelyDecideOption } from './shared_types';
import { OptimizelyDecideOption, Client, Config } from './shared_types';
import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager';

const logger = getLogger();
Expand All @@ -47,11 +47,11 @@ let hasRetriedEvents = false;

/**
* Creates an instance of the Optimizely class
* @param {SDKOptions} config
* @return {Optimizely|null} the Optimizely object
* @param {Config} config
* @return {Client|null} the Optimizely client object
* null on error
*/
const createInstance = function(config: SDKOptions): Optimizely | null {
const createInstance = function(config: Config): Client | null {
try {
// TODO warn about setting per instance errorHandler / logger / logLevel
if (config.errorHandler) {
Expand Down Expand Up @@ -125,6 +125,7 @@ const createInstance = function(config: SDKOptions): Optimizely | null {
errorHandler,
datafileManager: config.sdkKey ? createHttpPollingDatafileManager(config.sdkKey, logger, config.datafile, config.datafileOptions) : undefined,
notificationCenter,
isValidInstance: config.isValidInstance
};

const optimizely = new Optimizely(optimizelyOptions);
Expand Down Expand Up @@ -181,3 +182,5 @@ export default {
__internalResetRetryState,
OptimizelyDecideOption,
};

export * from './export_types'
242 changes: 0 additions & 242 deletions packages/optimizely-sdk/lib/index.d.ts

This file was deleted.

Loading