Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5ae8a81
WIP: fallback client
Jun 5, 2020
33af06f
Merge branch 'master' into fallback-client
Jun 10, 2020
6b349ec
Undo fallback client changes
Jun 10, 2020
3586598
Remove test investigation list
Jun 10, 2020
1d809a4
Restore unrelated rollup config changes
Jun 10, 2020
8ebe2b5
Remove unrelated eslint change
Jun 10, 2020
955a651
WIP: unit test support for typescript
Jun 10, 2020
77e65ec
Use version of mocha types compatible with our version of mocha
Jun 11, 2020
cfa3415
Consolidate to a single test command, remove esm, set allowJs: true i…
Jun 11, 2020
4d3d6bd
Sync exclude/include between rollup and tsconfig. Disable declaration…
Jun 11, 2020
6fd888e
Enable sourcemaps in tsconfig
Jun 11, 2020
19a1f5c
Foo test example for TS
Jun 11, 2020
68954e2
Update lint implementation for TypeScript
Jun 11, 2020
91797a6
Undo unrelated
Jun 11, 2020
9b2d7e0
Merge branch 'master' into mcarroll/optimizely-sdk-typescript
Jun 16, 2020
5f78cca
Remove duplicate entries in exclude arrays
Jun 16, 2020
b230942
Mention Jira number in index.d.ts TODOs
Jun 16, 2020
8dd1005
Convert string_value_validator module to TS
Jun 16, 2020
1923e00
Add ts-loader to karma + webpack configuration, enabling karma tests …
Jun 17, 2020
e1976ef
Merge branch 'master' into mcarroll/optimizely-sdk-typescript
Jul 14, 2020
fd1c2dc
Convert user_profile_service_validator module to TS (#526)
yavorona Jul 20, 2020
27288b3
feat: Convert event_tags_validator module to TS (#528)
yavorona Jul 29, 2020
de4e5b1
feat: Convert project_config_schema and json_schema_validator modules…
yavorona Jul 30, 2020
32839f4
feat: Convert attributes_validator to TS (#530)
yavorona Jul 30, 2020
ca0a3bc
fix(json schema validator): Replace empty object type assertion with …
mjc1283 Jul 30, 2020
8fad931
Fix configured entry point for json schema validator bundle
Jul 30, 2020
b9a4210
feat: Convert event_tag_utils module to TS (#544)
yavorona Jul 30, 2020
8b55526
Merge branch 'master' into mcarroll/optimizely-sdk-typescript
Jul 31, 2020
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
16 changes: 15 additions & 1 deletion packages/optimizely-sdk/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ module.exports = {
commonjs: true,
node: true,
},
extends: 'eslint:recommended',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
Expand All @@ -14,7 +17,18 @@ module.exports = {
ecmaVersion: 6,
sourceType: 'module',
},
overrides: [
{
'files': ['*.ts'],
'rules': {
'@typescript-eslint/explicit-module-boundary-types': ['error']
}
}
],
rules: {
'no-prototype-builtins': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-empty-function': 'off',
'no-shadow': 'error',
},
};
12 changes: 12 additions & 0 deletions packages/optimizely-sdk/karma.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ module.exports = {

webpack: {
mode: 'production',
module: {
rules: [
{
test: /\.[tj]s$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
},

//browserStack setup
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/core/decision_service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import enums from '../../utils/enums';
import fns from '../../utils/fns';
import projectConfig from '../project_config';
import AudienceEvaluator from '../audience_evaluator';
import stringValidator from '../../utils/string_value_validator';
import * as stringValidator from '../../utils/string_value_validator';

var MODULE_NAME = 'DECISION_SERVICE';
var ERROR_MESSAGES = enums.ERROR_MESSAGES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import AudienceEvaluator from '../audience_evaluator';
import errorHandler from '../../plugins/error_handler';
import eventBuilder from '../../core/event_builder/index.js';
import eventDispatcher from '../../plugins/event_dispatcher/index.node';
import jsonSchemaValidator from '../../utils/json_schema_validator';
import * as jsonSchemaValidator from '../../utils/json_schema_validator';
import {
getTestProjectConfig,
getTestProjectConfigWithFeatures,
Expand Down
16 changes: 12 additions & 4 deletions packages/optimizely-sdk/lib/core/event_builder/event_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { getLogger } from '@optimizely/js-sdk-logging';

import fns from '../../utils/fns';
import projectConfig from '../project_config';
import eventTagUtils from '../../utils/event_tag_utils';
import attributesValidator from'../../utils/attributes_validator';
import * as eventTagUtils from '../../utils/event_tag_utils';
import * as attributesValidator from'../../utils/attributes_validator';

var logger = getLogger('EVENT_BUILDER');

Expand Down Expand Up @@ -106,6 +106,14 @@ export var buildConversionEvent = function(config) {
var eventTags = config.eventTags;
var eventId = projectConfig.getEventId(configObj, eventKey);

let revenue = null;
let eventValue = null;

if (eventTags) {
revenue = eventTagUtils.getRevenueValue(eventTags, logger);
eventValue = eventTagUtils.getEventValue(eventTags, logger);
}

return {
type: 'conversion',
timestamp: fns.currentTimestamp(),
Expand All @@ -131,8 +139,8 @@ export var buildConversionEvent = function(config) {
key: eventKey,
},

revenue: eventTagUtils.getRevenueValue(eventTags, logger),
value: eventTagUtils.getEventValue(eventTags, logger),
revenue: revenue,
value: eventValue,
tags: eventTags,
};
};
Expand Down
4 changes: 2 additions & 2 deletions packages/optimizely-sdk/lib/core/event_builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import fns from '../../utils/fns';
import enums from '../../utils/enums';
import projectConfig from '../project_config';
import eventTagUtils from '../../utils/event_tag_utils';
import attributeValidator from '../../utils/attributes_validator';
import * as eventTagUtils from '../../utils/event_tag_utils';
import * as attributeValidator from '../../utils/attributes_validator';

var ACTIVATE_EVENT_KEY = 'campaign_activated';
var CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ERROR_MESSAGES, LOG_MESSAGES } from '../../utils/enums';
import testData from '../../tests/test_data';
import * as optimizelyConfig from '../optimizely_config/index';
import projectConfigManager from './project_config_manager';
import jsonSchemaValidator from '../../utils/json_schema_validator';
import * as jsonSchemaValidator from '../../utils/json_schema_validator';

describe('lib/core/project_config/project_config_manager', function() {
var globalStubErrorHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
/**
* Project Config JSON Schema file used to validate the project json datafile
*/
export var schema = {
import { JSONSchema4 } from 'json-schema';

var schemaDefinition = {
$schema: 'http://json-schema.org/draft-04/schema#',
type: 'object',
properties: {
Expand Down Expand Up @@ -276,4 +278,6 @@ export var schema = {
},
};

export default schema;
const schema = schemaDefinition as JSONSchema4

export default schema
10 changes: 10 additions & 0 deletions packages/optimizely-sdk/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ declare module '@optimizely/optimizely-sdk' {

// The options object given to Optimizely.createInstance.
export interface Config {
// TODO[OASIS-6649]: Don't use object type
// eslint-disable-next-line @typescript-eslint/ban-types
datafile?: object | string;
datafileOptions?: DatafileOptions;
errorHandler?: ErrorHandler;
Expand All @@ -50,6 +52,8 @@ declare module '@optimizely/optimizely-sdk' {
| enums.LOG_LEVEL.INFO
| enums.LOG_LEVEL.NOTSET
| enums.LOG_LEVEL.WARNING;
// TODO[OASIS-6649]: Don't use object type
// eslint-disable-next-line @typescript-eslint/ban-types
jsonSchemaValidator?: object;
userProfileService?: UserProfileService | null;
eventBatchSize?: number;
Expand Down Expand Up @@ -115,6 +119,8 @@ declare module '@optimizely/optimizely-sdk' {
// HTTP method with which to send the event.
httpVerb: 'POST';
// Value to send in the request body, JSON-serialized.
// TODO[OASIS-6649]: Don't use any type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
params: any;
}

Expand Down Expand Up @@ -159,6 +165,8 @@ declare module '@optimizely/optimizely-sdk' {
}

export type UserAttributes = {
// TODO[OASIS-6649]: Don't use any type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[name: string]: any;
};

Expand All @@ -183,6 +191,8 @@ declare module '@optimizely/optimizely-sdk' {
endOfRange: number;
}>;
audienceIds: string[];
// TODO[OASIS-6649]: Don't use object type
// eslint-disable-next-line @typescript-eslint/ban-types
forcedVariations: object;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/optimizely-sdk/lib/optimizely/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import decisionService from '../core/decision_service';
import enums from '../utils/enums';
import { getImpressionEvent, getConversionEvent } from '../core/event_builder/index.js';
import { buildConversionEvent, buildImpressionEvent } from '../core/event_builder/event_helpers';
import eventTagsValidator from '../utils/event_tags_validator';
import * as eventTagsValidator from '../utils/event_tags_validator';
import notificationCenter from '../core/notification_center';
import projectConfig from '../core/project_config';
import userProfileServiceValidator from '../utils/user_profile_service_validator';
import stringValidator from '../utils/string_value_validator';
import * as userProfileServiceValidator from '../utils/user_profile_service_validator';
import * as stringValidator from '../utils/string_value_validator';
import projectConfigManager from '../core/project_config/project_config_manager';

var ERROR_MESSAGES = enums.ERROR_MESSAGES;
Expand Down
2 changes: 1 addition & 1 deletion packages/optimizely-sdk/lib/optimizely/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import errorHandler from '../plugins/error_handler';
import fns from '../utils/fns';
import logger from '../plugins/logger';
import decisionService from '../core/decision_service';
import jsonSchemaValidator from '../utils/json_schema_validator';
import * as jsonSchemaValidator from '../utils/json_schema_validator';
import projectConfig from '../core/project_config';
import testData from '../tests/test_data';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { assert } from 'chai';
import { sprintf } from '@optimizely/js-sdk-utils';

import attributesValidator from './';
import * as attributesValidator from './';
import { ERROR_MESSAGES } from '../enums';

describe('lib/utils/attributes_validator', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ import { sprintf } from '@optimizely/js-sdk-utils';
import fns from '../../utils/fns';
import { ERROR_MESSAGES } from '../enums';

var MODULE_NAME = 'ATTRIBUTES_VALIDATOR';
const MODULE_NAME = 'ATTRIBUTES_VALIDATOR';

/**
* Validates user's provided attributes
* @param {Object} attributes
* @return {boolean} True if the attributes are valid
* @param {unknown} attributes
* @return {boolean} true if the attributes are valid
* @throws If the attributes are not valid
*/
export var validate = function(attributes) {

export function validate(attributes: unknown): boolean {
if (typeof attributes === 'object' && !Array.isArray(attributes) && attributes !== null) {
Object.keys(attributes).forEach(function(key) {
if (typeof attributes[key] === 'undefined') {
Expand All @@ -37,21 +38,19 @@ export var validate = function(attributes) {
} else {
throw new Error(sprintf(ERROR_MESSAGES.INVALID_ATTRIBUTES, MODULE_NAME));
}
};
}

export var isAttributeValid = function(attributeKey, attributeValue) {
/**
* Validates user's provided attribute
* @param {unknown} attributeKey
* @param {unknown} attributeValue
* @return {boolean} true if the attribute is valid
*/
export function isAttributeValid(attributeKey: unknown, attributeValue: unknown): boolean {
return (
typeof attributeKey === 'string' &&
(typeof attributeValue === 'string' ||
typeof attributeValue === 'boolean' ||
(fns.isNumber(attributeValue) && fns.isSafeInteger(attributeValue)))
);
};

/**
* Provides utility method for validating that the attributes user has provided are valid
*/
export default {
validate: validate,
isAttributeValid: isAttributeValid,
};
}
74 changes: 0 additions & 74 deletions packages/optimizely-sdk/lib/utils/event_tag_utils/index.js

This file was deleted.

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

import eventTagUtils from './';
import * as eventTagUtils from './';

describe('lib/utils/event_tag_utils', function() {
var mockLogger;
Expand Down
Loading