Content-Length: 959327 | pFad | http://github.com/optimizely/javascript-sdk/pull/749/files

05 refact: Integrate code from `utils` package into `optimizely-sdk` by ozayr-zaviar · Pull Request #749 · optimizely/javascript-sdk · GitHub
Skip to content

refact: Integrate code from utils package into optimizely-sdk #749

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 38 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
92e3ab7
utils integrated
ozayr-zaviar Mar 2, 2022
37cab7b
logging integrated
ozayr-zaviar Mar 14, 2022
1d5368c
testcases fix
ozayr-zaviar Mar 14, 2022
82b0fa1
revert logging
ozayr-zaviar Mar 25, 2022
2843dcc
utils merged in optimizely sdk
ozayr-zaviar Mar 25, 2022
8574c7e
small changes removed
ozayr-zaviar Mar 25, 2022
f725a21
Merge branch 'master' into uzair/consolidate-packages
ozayr-zaviar Mar 28, 2022
28905d0
ts config added because jest and mocha use similar declarations
ozayr-zaviar Mar 28, 2022
11518e1
type warning fixed
ozayr-zaviar Mar 28, 2022
d3371ce
more types fixed
ozayr-zaviar Mar 28, 2022
da73e11
fix
ozayr-zaviar Mar 28, 2022
069e501
fix
ozayr-zaviar Mar 28, 2022
bc6d5fb
fix
ozayr-zaviar Mar 28, 2022
3b758bd
type defined
ozayr-zaviar Mar 28, 2022
73e1db8
type fix
ozayr-zaviar Mar 28, 2022
d41146d
Merge branch 'master' into uzair/consolidate-packages
ozayr-zaviar Apr 12, 2022
550c3ba
headers updated
ozayr-zaviar Apr 12, 2022
39b5d69
fix
ozayr-zaviar Apr 12, 2022
d00a828
correct notification type imported
ozayr-zaviar Apr 12, 2022
c958cda
comment addressed
ozayr-zaviar Apr 12, 2022
c36dee9
headers updated and notification center moved
ozayr-zaviar Apr 13, 2022
19d1ca0
comments addressed
ozayr-zaviar Apr 14, 2022
6622d21
removed Notification center interface
ozayr-zaviar Apr 18, 2022
71f7e14
notification center renamed
ozayr-zaviar Apr 18, 2022
4b9c124
notification type corrected
ozayr-zaviar Apr 18, 2022
9e3d8d4
renamed a conflicting interface
zashraf1985 Apr 19, 2022
bef10a0
removed unused line
zashraf1985 Apr 19, 2022
dcdd371
comments addressed
ozayr-zaviar Apr 21, 2022
4fc4b51
fns exported in same import
ozayr-zaviar Apr 21, 2022
a8e7858
comment addressed
ozayr-zaviar Apr 28, 2022
0bb709c
Merge branch 'master' into uzair/consolidate-packages
ozayr-zaviar Apr 28, 2022
f36baf4
comments addressed
ozayr-zaviar May 5, 2022
f7e9855
Merge branch 'master' into uzair/consolidate-packages
zashraf1985 May 13, 2022
055860f
comments addressed
ozayr-zaviar May 16, 2022
5796dbe
Merge branch 'uzair/consolidate-packages' of github.com:optimizely/ja…
May 16, 2022
fe25893
alias @utils removed
ozayr-zaviar May 18, 2022
86cbb08
renamed a variable
zashraf1985 May 18, 2022
a1a6033
removed utils from dependency and added changelog entry
zashraf1985 May 23, 2022
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
3 changes: 2 additions & 1 deletion packages/optimizely-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ 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))
- Replaced explicit typescript typings with auto generated ones ([#745](https://github.com/optimizely/javascript-sdk/pull/745)).
- Integrated code from `utils` package into `optimizely-sdk` ([#749](https://github.com/optimizely/javascript-sdk/pull/749)).

## [4.9.1] - January 18, 2022

Expand Down
14 changes: 14 additions & 0 deletions packages/optimizely-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016, 2018-2020, Optimizely
* Copyright 2016, 2018-2020, 2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
import sinon from 'sinon';
import { assert } from 'chai';
import { getLogger } from '@optimizely/js-sdk-logging';
import { sprintf } from '@optimizely/js-sdk-utils';
import { sprintf } from '../../utils/fns';
Copy link
Contributor

Choose a reason for hiding this comment

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

Any thoughts on using path aliases in the optimizely-sdk/tsconfig.json file to make these imports a bit easier to read?

Example tsconfig.js:

"paths": {
  "*": [ "./typings/*" ],
  "@utils": [ "./lib/utils/*" ],
},

Usage:

import { sprint } from '@utils/fns'


import { createAudienceEvaluator } from './index';
import * as conditionTreeEvaluator from '../condition_tree_evaluator';
Expand Down
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/core/bucketer/index.tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2017, 2019-2021, Optimizely
* Copyright 2016-2017, 2019-2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
import sinon from 'sinon';
import { assert, expect } from 'chai';
import { cloneDeep } from 'lodash';
import { sprintf } from '@optimizely/js-sdk-utils';
import { sprintf } from '../../utils/fns';

import * as bucketer from './';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/core/bucketer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016, 2019-2021, Optimizely
* Copyright 2016, 2019-2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
/**
* Bucketer API for determining the variation id from the specified parameters
*/
import { sprintf } from '@optimizely/js-sdk-utils';
import { sprintf } from '../../utils/fns';
import murmurhash from 'murmurhash';
import { LogHandler } from '@optimizely/js-sdk-logging';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2018-2020, Optimizely, Inc. and contributors *
* Copyright 2018-2020, 2022, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand All @@ -15,7 +15,7 @@
***************************************************************************/
import sinon from 'sinon';
import { assert } from 'chai';
import { sprintf } from '@optimizely/js-sdk-utils';
import { sprintf } from '../../utils/fns';

import {
LOG_LEVEL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2017-2021 Optimizely, Inc. and contributors *
* Copyright 2017-2022 Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand All @@ -16,7 +16,7 @@
import sinon from 'sinon';
import { assert } from 'chai';
import cloneDeep from 'lodash/cloneDeep';
import { sprintf } from '@optimizely/js-sdk-utils';
import { sprintf } from '../../utils/fns';

import { createDecisionService } from './';
import * as bucketer from '../bucketer';
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/core/decision_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/
import { sprintf } from '@optimizely/js-sdk-utils';
import { LogHandler } from '@optimizely/js-sdk-logging';
import { sprintf } from '../../utils/fns';

import fns from '../../utils/fns';
import { bucket } from '../bucketer';
Expand Down
15 changes: 10 additions & 5 deletions packages/optimizely-sdk/lib/core/notification_center/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020, Optimizely
* Copyright 2020, 2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { objectValues } from '@optimizely/js-sdk-utils';
import { LogHandler, ErrorHandler } from '@optimizely/js-sdk-logging';
import { NOTIFICATION_TYPES as notificationTypesEnum } from '@optimizely/js-sdk-utils';
import { objectValues } from '../../utils/fns';
import { NotificationListener, ListenerPayload } from '../../shared_types';

import {
Expand Down Expand Up @@ -186,9 +185,9 @@ export class NotificationCenter {

/**
* Remove all previously added notification listeners for the argument type
* @param {notificationTypesEnum} notificationType One of NOTIFICATION_TYPES
* @param {NOTIFICATION_TYPES} notificationType One of NOTIFICATION_TYPES
*/
clearNotificationListeners(notificationType: notificationTypesEnum): void {
clearNotificationListeners(notificationType: NOTIFICATION_TYPES): void {
try {
this.notificationListeners[notificationType] = [];
} catch (e) {
Expand Down Expand Up @@ -239,3 +238,9 @@ export class NotificationCenter {
export function createNotificationCenter(options: NotificationCenterOptions): NotificationCenter {
return new NotificationCenter(options);
}

export interface NotificationSender {
// TODO[OASIS-6649]: Don't use any type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sendNotifications(notificationType: NOTIFICATION_TYPES, notificationData?: any): void
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2021, Optimizely
* Copyright 2016-2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@ import sinon from 'sinon';
import { assert } from 'chai';
import { forEach, cloneDeep } from 'lodash';
import { getLogger } from '@optimizely/js-sdk-logging';
import { sprintf } from '@optimizely/js-sdk-utils';
import { sprintf } from '../../utils/fns';

import fns from '../../utils/fns';
import projectConfig from './';
Expand Down
53 changes: 27 additions & 26 deletions packages/optimizely-sdk/lib/core/project_config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import {
find,
objectEntries,
objectValues,
sprintf
} from '@optimizely/js-sdk-utils';
sprintf,
assign,
keyBy
} from '../../utils/fns';

import fns from '../../utils/fns';
import {
ERROR_MESSAGES,
LOG_LEVEL,
Expand Down Expand Up @@ -105,27 +106,27 @@ const MODULE_NAME = 'PROJECT_CONFIG';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function createMutationSafeDatafileCopy(datafile: any): ProjectConfig {
const datafileCopy = fns.assign({}, datafile);
const datafileCopy = assign({}, datafile);
datafileCopy.audiences = (datafile.audiences || []).map((audience: Audience) => {
return fns.assign({}, audience);
return assign({}, audience);
});
datafileCopy.experiments = (datafile.experiments || []).map((experiment: Experiment) => {
return fns.assign({}, experiment);
return assign({}, experiment);
});
datafileCopy.featureFlags = (datafile.featureFlags || []).map((featureFlag: FeatureFlag) => {
return fns.assign({}, featureFlag);
return assign({}, featureFlag);
});
datafileCopy.groups = (datafile.groups || []).map((group: Group) => {
const groupCopy = fns.assign({}, group);
const groupCopy = assign({}, group);
groupCopy.experiments = (group.experiments || []).map((experiment) => {
return fns.assign({}, experiment);
return assign({}, experiment);
});
return groupCopy;
});
datafileCopy.rollouts = (datafile.rollouts || []).map((rollout: Rollout) => {
const rolloutCopy = fns.assign({}, rollout);
const rolloutCopy = assign({}, rollout);
rolloutCopy.experiments = (rollout.experiments || []).map((experiment) => {
return fns.assign({}, experiment);
return assign({}, experiment);
});
return rolloutCopy;
});
Expand Down Expand Up @@ -157,46 +158,46 @@ export const createProjectConfig = function(
(projectConfig.audiences || []).forEach((audience) => {
audience.conditions = JSON.parse(audience.conditions as string);
});
projectConfig.audiencesById = fns.keyBy(projectConfig.audiences, 'id');
fns.assign(projectConfig.audiencesById, fns.keyBy(projectConfig.typedAudiences, 'id'));
projectConfig.audiencesById = keyBy(projectConfig.audiences, 'id');
assign(projectConfig.audiencesById, keyBy(projectConfig.typedAudiences, 'id'));

projectConfig.attributeKeyMap = fns.keyBy(projectConfig.attributes, 'key');
projectConfig.eventKeyMap = fns.keyBy(projectConfig.events, 'key');
projectConfig.groupIdMap = fns.keyBy(projectConfig.groups, 'id');
projectConfig.attributeKeyMap = keyBy(projectConfig.attributes, 'key');
projectConfig.eventKeyMap = keyBy(projectConfig.events, 'key');
projectConfig.groupIdMap = keyBy(projectConfig.groups, 'id');

let experiments;
Object.keys(projectConfig.groupIdMap || {}).forEach((Id) => {
experiments = projectConfig.groupIdMap[Id].experiments;
(experiments || []).forEach((experiment) => {
projectConfig.experiments.push(fns.assign(experiment, { groupId: Id }));
projectConfig.experiments.push(assign(experiment, { groupId: Id }));
});
});

projectConfig.rolloutIdMap = fns.keyBy(projectConfig.rollouts || [], 'id');
projectConfig.rolloutIdMap = keyBy(projectConfig.rollouts || [], 'id');
objectValues(projectConfig.rolloutIdMap || {}).forEach(
(rollout) => {
(rollout.experiments || []).forEach((experiment) => {
projectConfig.experiments.push(experiment);
// Creates { <variationKey>: <variation> } map inside of the experiment
experiment.variationKeyMap = fns.keyBy(experiment.variations, 'key');
experiment.variationKeyMap = keyBy(experiment.variations, 'key');
});
}
);

projectConfig.experimentKeyMap = fns.keyBy(projectConfig.experiments, 'key');
projectConfig.experimentIdMap = fns.keyBy(projectConfig.experiments, 'id');
projectConfig.experimentKeyMap = keyBy(projectConfig.experiments, 'key');
projectConfig.experimentIdMap = keyBy(projectConfig.experiments, 'id');

projectConfig.variationIdMap = {};
projectConfig.variationVariableUsageMap = {};
(projectConfig.experiments || []).forEach((experiment) => {
// Creates { <variationKey>: <variation> } map inside of the experiment
experiment.variationKeyMap = fns.keyBy(experiment.variations, 'key');
experiment.variationKeyMap = keyBy(experiment.variations, 'key');

// Creates { <variationId>: { key: <variationKey>, id: <variationId> } } mapping for quick lookup
fns.assign(projectConfig.variationIdMap, fns.keyBy(experiment.variations, 'id'));
assign(projectConfig.variationIdMap, keyBy(experiment.variations, 'id'));
objectValues(experiment.variationKeyMap || {}).forEach((variation) => {
if (variation.variables) {
projectConfig.variationVariableUsageMap[variation.id] = fns.keyBy(variation.variables, 'id');
projectConfig.variationVariableUsageMap[variation.id] = keyBy(variation.variables, 'id');
}
});
});
Expand All @@ -205,7 +206,7 @@ export const createProjectConfig = function(
// for checking that experiment is a feature experiment or not.
projectConfig.experimentFeatureMap = {};

projectConfig.featureKeyMap = fns.keyBy(projectConfig.featureFlags || [], 'key');
projectConfig.featureKeyMap = keyBy(projectConfig.featureFlags || [], 'key');
objectValues(projectConfig.featureKeyMap || {}).forEach(
(feature) => {
// Json type is represented in datafile as a subtype of string for the sake of backwards compatibility.
Expand All @@ -217,7 +218,7 @@ export const createProjectConfig = function(
}
});

feature.variableKeyMap = fns.keyBy(feature.variables, 'key');
feature.variableKeyMap = keyBy(feature.variables, 'key');
(feature.experimentIds || []).forEach((experimentId) => {
// Add this experiment in experiment-feature map.
if (projectConfig.experimentFeatureMap[experimentId]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2019-2020 Optimizely
* Copyright 2019-2020, 2022, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,8 +17,8 @@ import sinon from 'sinon';
import { assert } from 'chai';
import { cloneDeep } from 'lodash';

import { sprintf } from '@optimizely/js-sdk-utils';
import * as logging from '@optimizely/js-sdk-logging';
import { sprintf } from '../../utils/fns';
Copy link
Contributor

@opti-jnguyen opti-jnguyen Apr 20, 2022

Choose a reason for hiding this comment

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

We should consider adding linting for consistent import ordering if we don't have that yet.

import * as datafileManager from '@optimizely/js-sdk-datafile-manager';

import * as projectConfig from './index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { sprintf } from '@optimizely/js-sdk-utils';
import { getLogger } from '@optimizely/js-sdk-logging';
import { sprintf } from '../../utils/fns';

import { ERROR_MESSAGES } from '../../utils/enums';
import { createOptimizelyConfig } from '../optimizely_config';
Expand Down
5 changes: 3 additions & 2 deletions packages/optimizely-sdk/lib/optimizely/index.tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright 2016-2021, Optimizely, Inc. and contributors *
* Copyright 2016-2022, Optimizely, Inc. and contributors *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
Expand All @@ -15,7 +15,8 @@
***************************************************************************/
import { assert, expect } from 'chai';
import sinon from 'sinon';
import { sprintf, NOTIFICATION_TYPES } from '@optimizely/js-sdk-utils';
import { sprintf } from '../utils/fns';
import { NOTIFICATION_TYPES } from '../utils/enums';
import eventProcessor from '../plugins/event_processor';
import * as logging from '@optimizely/js-sdk-logging';

Expand Down
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/optimizely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/
import { sprintf, objectValues } from '@optimizely/js-sdk-utils';
import { LoggerFacade, ErrorHandler } from '@optimizely/js-sdk-logging';
import { sprintf, objectValues } from '../utils/fns';
import { NotificationCenter } from '../core/notification_center';
import { EventProcessor } from '@optimizely/js-sdk-event-processor';
import {NotificationCenter} from '../core/notification_center'

import {
UserAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { assert } from 'chai';
import sinon from 'sinon';

import * as logging from '@optimizely/js-sdk-logging';
import { sprintf, NOTIFICATION_TYPES } from '@optimizely/js-sdk-utils';
import { sprintf } from '../utils/fns';
import { NOTIFICATION_TYPES } from '../utils/enums';

import OptimizelyUserContext from './';
import { createLogger } from '../plugins/logger';
Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/optimizely/javascript-sdk/pull/749/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy