Skip to content

Commit 9bb07f7

Browse files
committed
review
1 parent c280d5d commit 9bb07f7

29 files changed

+287
-33
lines changed

lib/odp/constant.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
export enum ODP_USER_KEY {
218
VUID = 'vuid',
319
FS_USER_ID = 'fs_user_id',

lib/odp/event_manager/odp_event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022-2023, Optimizely
2+
* Copyright 2022-2024, 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.

lib/odp/event_manager/odp_event_api_manager.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { describe, beforeEach, beforeAll, it, expect, vi } from 'vitest';
17+
import { describe, it, expect, vi } from 'vitest';
1818

19-
import { LogHandler, LogLevel } from '../../modules/logging';
2019
import { DefaultOdpEventApiManager, eventApiRequestGenerator, pixelApiRequestGenerator } from './odp_event_api_manager';
21-
import { OdpEvent } from './odp_event';
22-
import { RequestHandler } from '../../utils/http_request_handler/http';
20+
import { OdpEvent } from './odp_event';;
2321
import { OdpConfig } from '../odp_config';
24-
import { get } from 'http';
2522

2623
const data1 = new Map<string, unknown>();
2724
data1.set('key11', 'value-1');

lib/odp/event_manager/odp_event_api_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class DefaultOdpEventApiManager implements OdpEventApiManager {
5151

5252
async sendEvents(odpConfig: OdpConfig, events: OdpEvent[]): Promise<EventDispatchResponse> {
5353
if (events.length === 0) {
54-
return Promise.resolve({});
54+
return {};
5555
}
5656

5757
const { method, endpoint, headers, data } = this.requestGenerator(odpConfig, events);

lib/odp/event_manager/odp_event_manager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ describe('DefaultOdpEventManager', () => {
175175
expect(apiManager.sendEvents).toHaveBeenNthCalledWith(1, config, events);
176176
});
177177

178-
it('should should send events immediately asynchronously if batchSize is 1', async () => {
178+
it('should send events immediately asynchronously if batchSize is 1', async () => {
179179
const apiManager = getMockApiManager();
180180
apiManager.sendEvents.mockResolvedValue({ statusCode: 200 });
181181

lib/odp/odp_manager_factory.browser.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
vi.mock('../utils/http_request_handler/browser_request_handler', () => {
218
return { BrowserRequestHandler: vi.fn() };
319
});

lib/odp/odp_manager_factory.browser.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
import { BrowserRequestHandler } from '../utils/http_request_handler/browser_request_handler';
218
import { pixelApiRequestGenerator } from './event_manager/odp_event_api_manager';
319
import { OdpManager } from './odp_manager';

lib/odp/odp_manager_factory.node.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
vi.mock('../utils/http_request_handler/node_request_handler', () => {
218
return { NodeRequestHandler: vi.fn() };
319
});

lib/odp/odp_manager_factory.node.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
import { NodeRequestHandler } from '../utils/http_request_handler/node_request_handler';
218
import { eventApiRequestGenerator } from './event_manager/odp_event_api_manager';
319
import { OdpManager } from './odp_manager';

lib/odp/odp_manager_factory.react_native.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
vi.mock('../utils/http_request_handler/browser_request_handler', () => {
218
return { BrowserRequestHandler: vi.fn() };
319
});

lib/odp/odp_manager_factory.react_native.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
import { BrowserRequestHandler } from '../utils/http_request_handler/browser_request_handler';
218
import { eventApiRequestGenerator } from './event_manager/odp_event_api_manager';
319
import { OdpManager } from './odp_manager';

lib/odp/odp_manager_factory.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
vi.mock('./odp_manager', () => {
218
return {
319
DefaultOdpManager: vi.fn(),

lib/odp/odp_manager_factory.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
import { RequestHandler } from "../shared_types";
218
import { Cache } from "../utils/cache/cache";
319
import { InMemoryLruCache } from "../utils/cache/in_memory_lru_cache";

lib/odp/odp_types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022-2023, Optimizely
2+
* Copyright 2022-2024, 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.

lib/odp/segment_manager/odp_response_schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022, Optimizely
2+
* Copyright 2022, 2024, 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.

lib/odp/segment_manager/odp_segment_api_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022-2023, Optimizely
2+
* Copyright 2022-2024, 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.

lib/odp/segment_manager/odp_segment_manager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('DefaultOdpSegmentManager', () => {
7171
expect(cache.get(manager.makeCacheKey(userKey, userValue))).toEqual(['k', 'l']);
7272
});
7373

74-
it('should return sement from cache and not call apiManager on cache hit.', async () => {
74+
it('should return segment from cache and not call apiManager on cache hit.', async () => {
7575
const cache = getMockSyncCache<string[]>();
7676
const apiManager = getMockApiManager();
7777

lib/odp/segment_manager/optimizely_segment_option.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022, Optimizely
2+
* Copyright 2022, 2024, 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.

lib/optimizely/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ export default class Optimizely implements Client {
9191
private clientEngine: string;
9292
private clientVersion: string;
9393
private errorHandler: ErrorHandler;
94-
protected logger: LoggerFacade;
94+
private logger: LoggerFacade;
9595
private projectConfigManager: ProjectConfigManager;
9696
private decisionService: DecisionService;
9797
private eventProcessor?: EventProcessor;
9898
private defaultDecideOptions: { [key: string]: boolean };
99-
protected odpManager?: OdpManager;
99+
private odpManager?: OdpManager;
100100
public notificationCenter: DefaultNotificationCenter;
101101
private vuidManager?: VuidManager;
102102

lib/tests/testUtils.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
export const exhaustMicrotasks = async (loop = 100): Promise<void> => {
218
for(let i = 0; i < loop; i++) {
319
await Promise.resolve();
420
}
521
};
622

7-
export const wait = (ms: number): Promise<void> => new Promise(resolve => setTimeout(resolve, ms));
23+
export const wait = (ms: number): Promise<void> => new Promise(resolve => setTimeout(resolve, ms));

lib/utils/cache/in_memory_lru_cache.spec.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ describe('InMemoryLruCache', () => {
112112
expect(cache.getBatched(['a', 'b', 'c'])).toEqual([1, 2, undefined]);
113113
});
114114

115-
it('should return correct values when getBatched is called', () => {
116-
const cache = new InMemoryLruCache<number>(2);
117-
cache.set('a', 1);
118-
cache.set('b', 2);
119-
expect(cache.getBatched(['a', 'b', 'c'])).toEqual([1, 2, undefined]);
120-
});
121-
122115
it('should not return expired values when getBatched is called', async () => {
123116
const cache = new InMemoryLruCache<number>(2, 100);
124117
cache.set('a', 1);

lib/utils/cache/in_memory_lru_cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022-2023, Optimizely
2+
* Copyright 2022-2024, 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.

lib/vuid/vuid.spec.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
1-
import { vi, describe, expect, it } from 'vitest';
1+
/**
2+
* Copyright 2024, 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+
* https://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+
*/
216

3-
import { VUID_PREFIX, VUID_MAX_LENGTH, isVuid, makeVuid } from './vuid';
17+
import { describe, expect, it } from 'vitest';
18+
19+
import { isVuid, makeVuid, VUID_MAX_LENGTH } from './vuid';
420

521
describe('isVuid', () => {
622
it('should return true if and only if the value strats with the VUID_PREFIX and is longer than vuid_prefix', () => {
@@ -13,3 +29,11 @@ describe('isVuid', () => {
1329
expect(isVuid('123')).toBe(false);
1430
})
1531
});
32+
33+
describe('makeVuid', () => {
34+
it('should return a string that is a valid vuid and whose length is within VUID_MAX_LENGTH', () => {
35+
const vuid = makeVuid();
36+
expect(isVuid(vuid)).toBe(true);
37+
expect(vuid.length).toBeLessThanOrEqual(VUID_MAX_LENGTH);
38+
});
39+
});

lib/vuid/vuid.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2024, 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+
* https://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+
117
import { v4 as uuidV4 } from 'uuid';
218

319
export const VUID_PREFIX = `vuid_`;

0 commit comments

Comments
 (0)