Skip to content

Commit 625cb7c

Browse files
authored
refactor: Consolidate event-processor package into optimizely-sdk (#761)
## Summary Integrated Event Processor package with Optimizely SDK to remove external dependency. ## Test plan All existing unit tests and FSC tests should pass. ## Jira [OASIS-8206](https://optimizely.atlassian.net/browse/OASIS-8206)
1 parent efe2f6c commit 625cb7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+10355
-352
lines changed

package-lock.json

Lines changed: 5073 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright 2022, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
let items: {[key: string]: string} = {}
17+
18+
export default class AsyncStorage {
19+
20+
static getItem(key: string, callback?: (error?: Error, result?: string) => void): Promise<string | null> {
21+
return new Promise(resolve => {
22+
setTimeout(() => resolve(items[key] || null), 1)
23+
})
24+
}
25+
26+
static setItem(key: string, value: string, callback?: (error?: Error) => void): Promise<void> {
27+
return new Promise((resolve) => {
28+
setTimeout(() => {
29+
items[key] = value
30+
resolve()
31+
}, 1)
32+
})
33+
}
34+
35+
static removeItem(key: string, callback?: (error?: Error, result?: string) => void): Promise<string | null> {
36+
return new Promise(resolve => {
37+
setTimeout(() => {
38+
items[key] && delete items[key]
39+
// @ts-ignore
40+
resolve()
41+
}, 1)
42+
})
43+
}
44+
45+
static dumpItems(): {[key: string]: string} {
46+
return items
47+
}
48+
49+
static clearStore(): void {
50+
items = {}
51+
}
52+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright 2022, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
let localCallback: any
17+
18+
export function addEventListener(callback: any) {
19+
localCallback = callback
20+
}
21+
22+
export function triggerInternetState(isInternetReachable: boolean) {
23+
localCallback({ isInternetReachable })
24+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
"transform": {
3-
"^.+\\.tsx?$": "ts-jest"
3+
"^.+\\.(ts|tsx|js|jsx)$": "ts-jest",
44
},
55
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.tsx?$",
66
"moduleFileExtensions": [
@@ -10,5 +10,5 @@ module.exports = {
1010
"jsx",
1111
"json",
1212
"node"
13-
],
13+
]
1414
}

packages/optimizely-sdk/lib/core/event_builder/build_event_v1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2021 Optimizely
2+
* Copyright 2021-2022, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@ import {
1717
EventTags,
1818
ConversionEvent,
1919
ImpressionEvent,
20-
} from '@optimizely/js-sdk-event-processor';
20+
} from '../../modules/event_processor';
2121

2222
import { Event } from '../../shared_types';
2323

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import { LoggerFacade } from '../../modules/logging';
17-
import { EventV1 as CommonEventParams } from '@optimizely/js-sdk-event-processor';
17+
import { EventV1 as CommonEventParams } from '../../modules/event_processor';
1818

1919
import fns from '../../utils/fns';
2020
import { CONTROL_ATTRIBUTES, RESERVED_EVENT_KEYWORDS } from '../../utils/enums';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
getErrorHandler,
2121
LogLevel
2222
} from './modules/logging';
23-
import { LocalStoragePendingEventsDispatcher } from '@optimizely/js-sdk-event-processor';
23+
import { LocalStoragePendingEventsDispatcher } from '../lib/modules/event_processor';
2424
import configValidator from './utils/config_validator';
2525
import defaultErrorHandler from './plugins/error_handler';
2626
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';

0 commit comments

Comments
 (0)