8000 Merge branch 'master' into farhan-anjum/FSSDK-11446-add-exp/var-id-to… · optimizely/javascript-sdk@3897a5b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3897a5b

Browse files
Merge branch 'master' into farhan-anjum/FSSDK-11446-add-exp/var-id-to-notif-listener
2 parents e2cfa9a + 6f983eb commit 3897a5b

File tree

79 files changed

+1073
-903
lines changed

Some content is hidden

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

79 files changed

+1073
-903
lines changed

.github/workflows/javascript.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ jobs:
4040
CI_USER_TOKEN: ${{ secrets.CI_USER_TOKEN }}
4141
TRAVIS_COM_TOKEN: ${{ secrets.TRAVIS_COM_TOKEN }}
4242

43-
crossbrowser_and_umd_unit_tests:
44-
runs-on: ubuntu-latest
45-
env:
46-
BROWSER_STACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
47-
BROWSER_STACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
48-
steps:
49-
- uses: actions/checkout@v3
50-
- name: Set up Node
51-
uses: actions/setup-node@v3
52-
with:
53-
node-version: 16
54-
cache: 'npm'
55-
cache-dependency-path: ./package-lock.json
56-
- name: Cross-browser and umd unit tests
57-
working-directory: .
58-
run: |
59-
npm install
60-
npm run test-ci
43+
# crossbrowser_and_umd_unit_tests:
44+
# runs-on: ubuntu-latest
45+
# env:
46+
# BROWSER_STACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
47+
# BROWSER_STACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
48+
# steps:
49+
# - uses: actions/checkout@v3
50+
# - name: Set up Node
51+
# uses: actions/setup-node@v3
52+
# with:
53+
# node-version: 16
54+
# cache: 'npm'
55+
# cache-dependency-path: ./package-lock.json
56+
# - name: Cross-browser and umd unit tests
57+
# working-directory: .
58+
# run: |
59+
# npm install
60+
# npm run test-ci
6161

6262
unit_tests:
6363
runs-on: ubuntu-latest

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [5.3.5] - Jan 29, 2025
9+
10+
### Bug Fixes
11+
12+
- Rollout experiment key exclusion from activate method([#949](https://github.com/optimizely/javascript-sdk/pull/949))
13+
- Using optimizely.readyPromise instead of optimizely.onReady to avoid setTimeout call in edge environments. ([#995](https://github.com/optimizely/javascript-sdk/pull/995))
14+
15+
## [4.10.1] - November 18, 2024
16+
17+
### Changed
18+
- update uuid module improt and usage ([#961](https://github.com/optimizely/javascript-sdk/pull/961))
19+
20+
821
## [5.3.4] - Jun 28, 2024
922

1023
### Changed

lib/common_exports.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export { createStaticProjectConfigManager } from './project_config/config_manage
1919
export { LogLevel } from './logging/logger';
2020

2121
export {
22-
DebugLog,
23-
InfoLog,
24-
WarnLog,
25-
ErrorLog,
22+
DEBUG,
23+
INFO,
24+
WARN,
25+
ERROR,
2626
} from './logging/logger_factory';
2727

2828
export { createLogger } from './logging/logger_factory';

lib/core/decision_service/cmab/cmab_service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { LoggerFacade } from "../../../logging/logger";
1818
import { IOptimizelyUserContext } from "../../../optimizely_user_context";
1919
import { ProjectConfig } from "../../../project_config/project_config"
2020
import { OptimizelyDecideOption, UserAttributes } from "../../../shared_types"
21-
import { Cache } from "../../../utils/cache/cache";
21+
import { Cache, CacheWithRemove } from "../../../utils/cache/cache";
2222
import { CmabClient } from "./cmab_client";
2323
import { v4 as uuidV4 } from 'uuid';
2424
import murmurhash from "murmurhash";
@@ -53,12 +53,12 @@ export type CmabCacheValue = {
5353

5454
export type CmabServiceOptions = {
5555
logger?: LoggerFacade;
56-
cmabCache: Cache<CmabCacheValue>;
56+
cmabCache: CacheWithRemove<CmabCacheValue>;
5757
cmabClient: CmabClient;
5858
}
5959

6060
export class DefaultCmabService implements CmabService {
61-
private cmabCache: Cache<CmabCacheValue>;
61+
private cmabCache: CacheWithRemove<CmabCacheValue>;
6262
private cmabClient: CmabClient;
6363
private logger?: LoggerFacade;
6464

@@ -81,7 +81,7 @@ export class DefaultCmabService implements CmabService {
8181
}
8282

8383
if (options[OptimizelyDecideOption.RESET_CMAB_CACHE]) {
84-
this.cmabCache.clear();
84+
this.cmabCache.reset();
8585
}
8686

8787
const cacheKey = this.getCacheKey(userContext.getUserId(), ruleId);
@@ -90,7 +90,7 @@ export class DefaultCmabService implements CmabService {
9090
this.cmabCache.remove(cacheKey);
9191
}
9292

93-
const cachedValue = await this.cmabCache.get(cacheKey);
93+
const cachedValue = await this.cmabCache.lookup(cacheKey);
9494

9595
const attributesJson = JSON.stringify(filteredAttributes, Object.keys(filteredAttributes).sort());
9696
const attributesHash = String(murmurhash.v3(attributesJson));
@@ -104,7 +104,7 @@ export class DefaultCmabService implements CmabService {
104104
}
105105

106106
const variation = await this.fetchDecision(ruleId, userContext.getUserId(), filteredAttributes);
107-
this.cmabCache.set(cacheKey, {
107+
this.cmabCache.save(cacheKey, {
108108
attributesHash,
109109
variationId: variation.variationId,
110110
cmabUuid: variation.cmabUuid,

lib/core/decision_service/index.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import OptimizelyUserContext from '../../optimizely_user_context';
2020
import { bucket } from '../bucketer';
2121
import { getTestProjectConfig, getTestProjectConfigWithFeatures } from '../../tests/test_data';
2222
import { createProjectConfig, ProjectConfig } from '../../project_config/project_config';
23-
import { BucketerParams, Experiment, OptimizelyDecideOption, UserProfile } from '../../shared_types';
23+
import { BucketerParams, Experiment, OptimizelyDecideOption, UserAttributes, UserProfile } from '../../shared_types';
2424
import { CONTROL_ATTRIBUTES, DECISION_SOURCES } from '../../utils/enums';
2525
import { getDecisionTestDatafile } from '../../tests/decision_test_datafile';
2626
import { Value } from '../../utils/promise/operation_value';
@@ -344,7 +344,7 @@ describe('DecisionService', () => {
344344
const config = createProjectConfig(cloneDeep(testData));
345345
const experiment = config.experimentIdMap['111127'];
346346

347-
const attributes: any = {
347+
const attributes: UserAttributes = {
348348
$opt_experiment_bucket_map: {
349349
'111127': {
350350
variation_id: '111129', // ID of the 'variation' variation
@@ -682,7 +682,7 @@ describe('DecisionService', () => {
682682
const config = createProjectConfig(cloneDeep(testData));
683683
const experiment = config.experimentIdMap['111127'];
684684

685-
const attributes: any = {
685+
const attributes: UserAttributes = {
686686
$opt_experiment_bucket_map: {
687687
'111127': {
688688
variation_id: '111129', // ID of the 'variation' variation
@@ -715,7 +715,7 @@ describe('DecisionService', () => {
715715
const config = createProjectConfig(cloneDeep(testData));
716716
const experiment = config.experimentIdMap['111127'];
717717

718-
const attributes: any = {
718+
const attributes: UserAttributes = {
719719
$opt_experiment_bucket_map: {
720720
'122227': {
721721
variation_id: '111129', // ID of the 'variation' variation
@@ -748,7 +748,7 @@ describe('DecisionService', () => {
748748
const config = createProjectConfig(cloneDeep(testData));
749749
const experiment = config.experimentIdMap['111127'];
750750

751-
const attributes: any = {
751+
const attributes: UserAttributes = {
752752
$opt_experiment_bucket_map: {
753753
'111127': {
754754
variation_id: '111129', // ID of the 'variation' variation
@@ -774,7 +774,7 @@ describe('DecisionService', () => {
774774
const config = createProjectConfig(cloneDeep(testData));
775775
const experiment = config.experimentIdMap['111127'];
776776

777-
const attributes: any = {
777+
const attributes: UserAttributes = {
778778
$opt_experiment_bucket_map: {
779779
'111127': {
780780
variation_id: '111129', // ID of the 'variation' variation

lib/entrypoint.test-d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import { NOTIFICATION_TYPES, DECISION_NOTIFICATION_TYPES } from './notification_
5555
import { LogLevel } from './logging/logger';
5656

5757
import { OptimizelyDecideOption } from './shared_types';
58+
import { Maybe } from './utils/type';
5859

5960
export type Entrypoint = {
6061
// client factory
@@ -66,7 +67,7 @@ export type Entrypoint = {
6667

6768
// event processor related exports
6869
eventDispatcher: EventDispatcher;
69-
getSendBeaconEventDispatcher: () => EventDispatcher;
70+
getSendBeaconEventDispatcher: () => Maybe<EventDispatcher>;
7071
createForwardingEventProcessor: (eventDispatcher?: EventDispatcher) => OpaqueEventProcessor;
7172
createBatchEventProcessor: (options?: BatchEventProcessorOptions) => OpaqueEventProcessor;
7273

@@ -78,10 +79,10 @@ export type Entrypoint = {
7879

7980
// logger related exports
8081
LogLevel: typeof LogLevel;
81-
DebugLog: OpaqueLevelPreset,
82-
InfoLog: OpaqueLevelPreset,
83-
WarnLog: OpaqueLevelPreset,
84-
ErrorLog: OpaqueLevelPreset,
82+
DEBUG: OpaqueLevelPreset,
83+
INFO: OpaqueLevelPreset,
84+
WARN: OpaqueLevelPreset,
85+
ERROR: OpaqueLevelPreset,
8586
createLogger: (config: LoggerConfig) => OpaqueLogger;
8687

8788
// error related exports

lib/entrypoint.universal.test-d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ import { LogLevel } from './logging/logger';
4949

5050
import { OptimizelyDecideOption } from './shared_types';
5151
import { UniversalConfig } from './index.universal';
52+
import { OpaqueOdpManager } from './odp/odp_manager_factory';
53+
54+
import { UniversalOdpManagerOptions } from './odp/odp_manager_factory.universal';
5255

5356
export type UniversalEntrypoint = {
5457
// client factory
@@ -63,18 +66,17 @@ export type UniversalEntrypoint = {
6366
createForwardingEventProcessor: (eventDispatcher: EventDispatcher) => OpaqueEventProcessor;
6467
createBatchEventProcessor: (options: UniversalBatchEventProcessorOptions) => OpaqueEventProcessor;
6568

66-
// TODO: odp manager related exports
67-
// createOdpManager: (options: OdpManagerOptions) => OpaqueOdpManager;
69+
createOdpManager: (options: UniversalOdpManagerOptions) => OpaqueOdpManager;
6870

6971
// TODO: vuid manager related exports
7072
// createVuidManager: (options: VuidManagerOptions) => OpaqueVuidManager;
7173

7274
// logger related exports
7375
LogLevel: typeof LogLevel;
74-
DebugLog: OpaqueLevelPreset,
75-
InfoLog: OpaqueLevelPreset,
76-
WarnLog: OpaqueLevelPreset,
77-
ErrorLog: OpaqueLevelPreset,
76+
DEBUG: OpaqueLevelPreset,
77+
INFO: OpaqueLevelPreset,
78+
WARN: OpaqueLevelPreset,
79+
ERROR: OpaqueLevelPreset,
7880
createLogger: (config: LoggerConfig) => OpaqueLogger;
7981

8082
// error related exports

lib/error/optimizly_error.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,11 @@ export class OptimizelyError extends Error {
3030
// custom Errors when TS is compiled to es5
3131
Object.setPrototypeOf(this, OptimizelyError.prototype);
3232
}
33-
34-
getMessage(resolver?: MessageResolver): string {
35-
if (this.resolved) {
36-
return this.message;
37-
}
38-
39-
if (resolver) {
40-
this.setMessage(resolver);
41-
return this.message;
42-
}
43-
44-
return this.baseMessage;
45-
}
4633

4734
setMessage(resolver: MessageResolver): void {
48-
this.message = sprintf(resolver.resolve(this.baseMessage), ...this.params);
49-
this.resolved = true;
35+
if (!this.resolved) {
36+
this.message = sprintf(resolver.resolve(this.baseMessage), ...this.params);
37+
this.resolved = true;
38+
}
5039
}
5140
}

lib/event_processor/batch_event_processor.react_native.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const mockNetInfo = vi.hoisted(() => {
3939
return netInfo;
4040
});
4141

42-
vi.mock('../utils/import.react_native/@react-native-community/netinfo', () => {
42+
vi.mock('@react-native-community/netinfo', () => {
4343
return {
4444
addEventListener: mockNetInfo.addEventListener.bind(mockNetInfo),
4545
};

lib/event_processor/batch_event_processor.react_native.ts

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

17-
import { NetInfoState, addEventListener } from '../utils/import.react_native/@react-native-community/netinfo';
17+
import { NetInfoState, addEventListener } from '@react-native-community/netinfo';
1818

1919
import { BatchEventProcessor, BatchEventProcessorConfig } from './batch_event_processor';
2020
import { Fn } from '../utils/type';
@@ -41,15 +41,11 @@ export class ReactNativeNetInfoEventProcessor extends BatchEventProcessor {
4141

4242
start(): void {
4343
super.start();
44-
if (addEventListener) {
45-
this.unsubscribeNetInfo = addEventListener(this.connectionListener.bind(this));
46-
}
44+
this.unsubscribeNetInfo = addEventListener(this.connectionListener.bind(this));
4745
}
4846

4947
stop(): void {
50-
if (this.unsubscribeNetInfo) {
51-
this.unsubscribeNetInfo();
52-
}
48+
this.unsubscribeNetInfo?.();
5349
super.stop();
5450
}
5551
}

0 commit comments

Comments
 (0)
0