This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete distributorId before sending error (#87)
* Delete distributorId before sending error * Move config check to the initialization * Use valid config in minimal live connect * Expose event bus in minimal LC * Add LC instance to liQ_instances in mininal LC * include event-bus to esm and cjs * adjust the initializer to use the global bus and add mode param * small refactoring Co-authored-by: wiem <welabidine@liveintent.com>
- Loading branch information
1 parent
175c1e4
commit 318aa85
Showing
10 changed files
with
18,333 additions
and
51 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @param {LiveConnectConfiguration} config | ||
* @return {LiveConnectConfiguration} | ||
*/ | ||
export function removeInvalidPairs (config, eventBus) { | ||
if (config && config.appId && config.distributorId) { | ||
const distributorId = config.distributorId | ||
delete config.distributorId | ||
eventBus.emitError('AppIdAndDistributorIdPresent', new Error(`Event contains both appId: ${config.appId} and distributorId: ${distributorId}. Ignoring distributorId`)) | ||
} | ||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import { StandardLiveConnect } from './standard-live-connect' | ||
import { MinimalLiveConnect } from './minimal-live-connect' | ||
import { isObject } from './utils/types' | ||
const _minimalMode = process.env.LiveConnectMode === 'minimal' | ||
const _initializationFunction = _minimalMode ? MinimalLiveConnect : StandardLiveConnect | ||
import { EVENT_BUS_NAMESPACE } from './utils/consts' | ||
import { GlobalEventBus } from './events/event-bus' | ||
|
||
/** | ||
* @param {LiveConnectConfiguration} liveConnectConfig | ||
* @param {StorageHandler} externalStorageHandler | ||
* @param {CallHandler} externalCallHandler | ||
* @param {string} mode | ||
* @param {EventBus} externalEventBus | ||
* @returns {LiveConnect} | ||
* @constructor | ||
*/ | ||
export function LiveConnect (liveConnectConfig, externalStorageHandler, externalCallHandler, externalEventBus) { | ||
export function LiveConnect (liveConnectConfig, externalStorageHandler, externalCallHandler, mode, externalEventBus) { | ||
console.log('Initializing LiveConnect', liveConnectConfig) | ||
const minimalMode = mode === 'minimal' || process.env.LiveConnectMode === 'minimal' | ||
const bus = externalEventBus || GlobalEventBus(EVENT_BUS_NAMESPACE, 5, err => console.error(err)) | ||
const configuration = (isObject(liveConnectConfig) && liveConnectConfig) || {} | ||
return _initializationFunction(configuration, externalStorageHandler, externalCallHandler, externalEventBus) | ||
const initializationFunction = minimalMode ? MinimalLiveConnect : StandardLiveConnect | ||
return initializationFunction(configuration, externalStorageHandler, externalCallHandler, bus) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { expect, use } from 'chai' | ||
import dirtyChai from 'dirty-chai' | ||
import { removeInvalidPairs } from '../../../src/config-validators/remove-invalid-pairs' | ||
import { LocalEventBus } from '../../../src/events/event-bus' | ||
|
||
use(dirtyChai) | ||
|
||
describe('RemoveInvalidPairsTransformer', () => { | ||
const eventBus = LocalEventBus() | ||
let errors = [] | ||
|
||
beforeEach(() => { | ||
eventBus.on('li_errors', (error) => { errors.push(error) }) | ||
errors = [] | ||
}) | ||
|
||
it('should send event and remove distributorId when both appId and distributorId are present', function () { | ||
const config = { | ||
appId: 'a-0100', | ||
distributorId: 'did-9898', | ||
liveConnectId: '213245' | ||
} | ||
const expectedResult = { | ||
appId: 'a-0100', | ||
liveConnectId: '213245' | ||
} | ||
const result = removeInvalidPairs(config, eventBus) | ||
|
||
expect(result).to.eql(expectedResult) | ||
expect(errors).to.not.be.empty() | ||
}) | ||
|
||
it('should not modify config if appId and distributorId are not present', function () { | ||
const config = { | ||
appId: 'a-0100', | ||
liveConnectId: '213245', | ||
globalVarName: 'liQTest' | ||
} | ||
const expectedResult = { | ||
appId: 'a-0100', | ||
liveConnectId: '213245', | ||
globalVarName: 'liQTest' | ||
} | ||
const result = removeInvalidPairs(config, eventBus) | ||
|
||
expect(result).to.eql(expectedResult) | ||
expect(errors).to.be.empty() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters