Skip to content

Commit 36ff5d7

Browse files
authored
[FSSDK-9562] set pixel api endpoint dynamically (#852)
1 parent 91826b0 commit 36ff5d7

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

lib/index.browser.tests.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import configValidator from './utils/config_validator';
2626
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
2727
import OptimizelyUserContext from './optimizely_user_context';
2828

29-
import { LOG_MESSAGES, ODP_EVENT_ACTION, ODP_EVENT_BROWSER_ENDPOINT } from './utils/enums';
29+
import { LOG_MESSAGES, ODP_EVENT_ACTION } from './utils/enums';
3030
import { BrowserOdpManager } from './plugins/odp_manager/index.browser';
3131
import { OdpConfig } from './core/odp/odp_config';
3232
import { BrowserOdpEventManager } from './plugins/odp/event_manager/index.browser';
@@ -1031,6 +1031,7 @@ describe('javascript-sdk (Browser)', function() {
10311031

10321032
it('should send an odp event to the browser endpoint', async () => {
10331033
const odpConfig = new OdpConfig();
1034+
10341035
const apiManager = new BrowserOdpEventApiManager(mockRequestHandler, logger);
10351036
const eventManager = new BrowserOdpEventManager({
10361037
odpConfig,
@@ -1065,8 +1066,9 @@ describe('javascript-sdk (Browser)', function() {
10651066

10661067
let publicKey = datafile.integrations[0].publicKey;
10671068

1069+
const pixelApiEndpoint = 'https://jumbe.zaius.com/v2/zaius.gif';
10681070
let requestEndpoint = new URL(requestParams.get('endpoint'));
1069-
assert.equal(requestEndpoint.origin + requestEndpoint.pathname, ODP_EVENT_BROWSER_ENDPOINT);
1071+
assert.equal(requestEndpoint.origin + requestEndpoint.pathname, pixelApiEndpoint);
10701072
assert.equal(requestParams.get('method'), 'GET');
10711073

10721074
let searchParams = requestEndpoint.searchParams;

lib/plugins/odp/event_api_manager/index.browser.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { OdpEvent } from '../../../core/odp/odp_event';
22
import { OdpEventApiManager } from '../../../core/odp/odp_event_api_manager';
33
import { LogLevel } from '../../../modules/logging';
4-
import { ODP_EVENT_BROWSER_ENDPOINT } from '../../../utils/enums';
54
import { ODP_CONFIG_NOT_READY_MESSAGE } from '../../../core/odp/odp_event_api_manager';
65

76
const EVENT_SENDING_FAILURE_MESSAGE = 'ODP event send failed';
87

8+
const pixelApiPath = 'v2/zaius.gif';
9+
910
export class BrowserOdpEventApiManager extends OdpEventApiManager {
1011
protected shouldSendEvents(events: OdpEvent[]): boolean {
1112
if (events.length <= 1) {
@@ -15,6 +16,15 @@ export class BrowserOdpEventApiManager extends OdpEventApiManager {
1516
return false;
1617
}
1718

19+
private getPixelApiEndpoint(): string {
20+
if (!this.odpConfig?.isReady()) {
21+
throw new Error(ODP_CONFIG_NOT_READY_MESSAGE);
22+
}
23+
const apiHost = this.odpConfig.apiHost;
24+
const pixelApiEndpoint = new URL(pixelApiPath, apiHost.replace('api', 'jumbe')).href;
25+
return pixelApiEndpoint;
26+
}
27+
1828
protected generateRequestData(
1929
events: OdpEvent[]
2030
): { method: string; endpoint: string; headers: { [key: string]: string }; data: string } {
@@ -23,11 +33,17 @@ export class BrowserOdpEventApiManager extends OdpEventApiManager {
2333
this.getLogger().log(LogLevel.ERROR, ODP_CONFIG_NOT_READY_MESSAGE);
2434
throw new Error(ODP_CONFIG_NOT_READY_MESSAGE);
2535
}
36+
37+
// this cannot be cached cause OdpConfig is mutable
38+
// and can be updated in place and it is done so in odp
39+
// manager. We should make OdpConfig immutable and
40+
// refacator later
41+
const pixelApiEndpoint = this.getPixelApiEndpoint();
2642

2743
const apiKey = this.odpConfig.apiKey;
2844
const method = 'GET';
2945
const event = events[0];
30-
const url = new URL(ODP_EVENT_BROWSER_ENDPOINT);
46+
const url = new URL(pixelApiEndpoint);
3147
event.identifiers.forEach((v, k) => {
3248
url.searchParams.append(k, v);
3349
});

lib/plugins/odp_manager/index.node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class NodeOdpManager extends OdpManager {
114114
});
115115
}
116116

117-
this.eventManager!.start();
117+
this.eventManager.start();
118118

119119
this.initPromise = Promise.resolve();
120120
}

lib/utils/enums/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ export enum ODP_USER_KEY {
357357
export const FS_USER_ID_ALIAS = 'fs-user-id';
358358

359359
export const ODP_DEFAULT_EVENT_TYPE = 'fullstack';
360-
export const ODP_EVENT_BROWSER_ENDPOINT = 'https://jumbe.zaius.com/v2/zaius.gif';
361360

362361
/**
363362
* ODP Event Action Options

0 commit comments

Comments
 (0)