Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
All pkgs removed from package,json except logging
  • Loading branch information
Amna Ejaz committed Aug 10, 2020
commit 2d520630b639c961ee83e2a34f00a5b80206d3c6
7 changes: 5 additions & 2 deletions packages/optimizely-sdk/lib/core/audience_evaluator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
* 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 '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');

// import { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../logging/logger');

import fns from '../../utils/fns';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
import sinon from 'sinon';
import { assert } from 'chai';
import { getLogger } from '@optimizely/js-sdk-logging';
// import { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../logging/logger');

import AudienceEvaluator from './index';
import conditionTreeEvaluator from '../condition_tree_evaluator';
Expand Down
4 changes: 3 additions & 1 deletion packages/optimizely-sdk/lib/core/bucketer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
/**
* Bucketer API for determining the variation id from the specified parameters
*/
import { sprintf } from '@optimizely/js-sdk-utils';
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');

import murmurhash from 'murmurhash';

import {
Expand Down
3 changes: 2 additions & 1 deletion packages/optimizely-sdk/lib/core/bucketer/index.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import sinon from 'sinon';
import { assert, expect } from 'chai';
import { cloneDeep } from 'lodash';
import { sprintf } from '@optimizely/js-sdk-utils';
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');

import bucketer from './';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/
import { sprintf } from '@optimizely/js-sdk-utils';
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');

import fns from '../../utils/fns';
import {
Expand Down
3 changes: 2 additions & 1 deletion packages/optimizely-sdk/lib/core/decision_service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and *
* limitations under the License. *
***************************************************************************/
import { sprintf } from'@optimizely/js-sdk-utils';
// import { sprintf } from'@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');

import bucketer from '../bucketer';
import enums from '../../utils/enums';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import sinon from 'sinon';
import { assert } from 'chai';
import cloneDeep from 'lodash/cloneDeep';
import { sprintf } from '@optimizely/js-sdk-utils';
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');

import DecisionService from './';
import bucketer from '../bucketer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getLogger } from '@optimizely/js-sdk-logging';
// import { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../logging/logger');

import fns from '../../utils/fns';
import projectConfig from '../project_config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { sprintf, objectValues } from '@optimizely/js-sdk-utils';
// import { sprintf, objectValues } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');
var objectValues = require('../../pkg-utils/index');

import {
LOG_LEVEL,
Expand Down
4 changes: 3 additions & 1 deletion packages/optimizely-sdk/lib/core/project_config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { sprintf, objectValues } from '@optimizely/js-sdk-utils';
// import { sprintf, objectValues } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');
var objectValues = require('../../pkg-utils/index');

import fns from '../../utils/fns';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
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 { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../../logging/logger');
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');

import fns from '../../utils/fns';
import projectConfig from './';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
* 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 { HttpPollingDatafileManager } from '@optimizely/js-sdk-datafile-manager';
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');
// import { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../logging/logger');
// import { HttpPollingDatafileManager } from '../../datafile-manager/src/httpPollingDatafileManager.ts';
var HttpPollingDatafileManager = require('../../datafile-manager/src/httpPollingDatafileManager.ts');


import fns from '../../utils/fns';
import { ERROR_MESSAGES } from '../../utils/enums';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
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 * as datafileManager from '@optimizely/js-sdk-datafile-manager';
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../../pkg-utils/index');
// import * as logging from '@optimizely/js-sdk-logging';
var logging = require('../logging/logger');

// import * as datafileManager from '../../datafile-manager/src/datafileManager.ts';
var datafileManager = require('../../datafile-manager/datafileManager.ts');


import projectConfig from './index';
import { ERROR_MESSAGES, LOG_MESSAGES } from '../../utils/enums';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import { AbortableRequest, Response, Headers } from './http';
import { REQUEST_TIMEOUT_MS } from './config';
import { getLogger } from '@optimizely/js-sdk-logging';
// import { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../logging/logger');

const logger = getLogger('DatafileManager');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
* limitations under the License.
*/

import { getLogger } from '@optimizely/js-sdk-logging';
import { sprintf } from '@optimizely/js-sdk-utils';
// import { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../logging/logger');
// import { sprintf } from '@optimizely/js-sdk-utils';
var sprintf = require('../pkg-utils/index');
import { DatafileManager, DatafileManagerConfig, DatafileUpdate } from './datafileManager';
import EventEmitter, { Disposer } from './eventEmitter';
import { AbortableRequest, Response, Headers } from './http';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import { getLogger } from '@optimizely/js-sdk-logging';
// import { getLogger } from '@optimizely/js-sdk-logging';
var getLogger = require('../logging/logger');
import { makeGetRequest } from './nodeRequest';
import HttpPollingDatafileManager from './httpPollingDatafileManager';
import { Headers, AbortableRequest } from './http';
Expand Down
32 changes: 32 additions & 0 deletions packages/optimizely-sdk/lib/event-processor/eventDispatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2019, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { EventV1 } from "./v1/buildEventV1";

export type EventDispatcherResponse = {
statusCode: number
}

export type EventDispatcherCallback = (response: EventDispatcherResponse) => void

export interface EventDispatcher {
dispatchEvent(event: EventV1Request, callback: EventDispatcherCallback): void
}

export interface EventV1Request {
url: string
httpVerb: 'POST' | 'PUT' | 'GET' | 'PATCH'
params: EventV1,
}
86 changes: 86 additions & 0 deletions packages/optimizely-sdk/lib/event-processor/eventProcessor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright 2019-2020, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TODO change this to use Managed from js-sdk-models when available
import { Managed } from './managed'
import { ConversionEvent, ImpressionEvent } from './events'
import { EventV1Request } from './eventDispatcher'
import { EventQueue, DefaultEventQueue, SingleEventQueue } from './eventQueue'
// import { getLogger } from '@optimizely/js-sdk-logging'
var getLogger = require('../logging/logger');

// import { NOTIFICATION_TYPES, NotificationCenter } from '@optimizely/js-sdk-utils'
var NOTIFICATION_TYPES = require('../pkg-utils/index');
var NotificationCenter = require('../pkg-utils/index');
var NotificationCenter = require('../pkg-utils/index');

export const DEFAULT_FLUSH_INTERVAL = 30000 // Unit is ms - default flush interval is 30s
export const DEFAULT_BATCH_SIZE = 10

const logger = getLogger('EventProcessor')

export type ProcessableEvent = ConversionEvent | ImpressionEvent

export type EventDispatchResult = { result: boolean; event: ProcessableEvent }

export interface EventProcessor extends Managed {
process(event: ProcessableEvent): void
}

export function validateAndGetFlushInterval(flushInterval: number): number {
if (flushInterval <= 0) {
logger.warn(
`Invalid flushInterval ${flushInterval}, defaulting to ${DEFAULT_FLUSH_INTERVAL}`,
)
flushInterval = DEFAULT_FLUSH_INTERVAL
}
return flushInterval
}

export function validateAndGetBatchSize(batchSize: number): number {
batchSize = Math.floor(batchSize)
if (batchSize < 1) {
logger.warn(
`Invalid batchSize ${batchSize}, defaulting to ${DEFAULT_BATCH_SIZE}`,
)
batchSize = DEFAULT_BATCH_SIZE
}
batchSize = Math.max(1, batchSize)
return batchSize
}

export function getQueue(batchSize: number, flushInterval: number, sink: any, batchComparator: any): EventQueue<ProcessableEvent> {
let queue: EventQueue<ProcessableEvent>
if (batchSize > 1) {
queue = new DefaultEventQueue<ProcessableEvent>({
flushInterval,
maxQueueSize: batchSize,
sink,
batchComparator,
})
} else {
queue = new SingleEventQueue({ sink })
}
return queue
}

export function sendEventNotification(notificationCenter: typeof NotificationCenter | undefined, event: EventV1Request): void {
if (notificationCenter) {
notificationCenter.sendNotifications(
NOTIFICATION_TYPES.LOG_EVENT,
event,
)
}
}
Loading