fix(core): update
This commit is contained in:
27
ts/index.ts
27
ts/index.ts
@ -55,17 +55,32 @@ export class CsWebclient {
|
||||
const csGetDomainSettingsRequest = new plugins.typedrequest.TypedRequest<
|
||||
plugins.csInterfaces.IRequest_Client_ConsentSoftwareServer_GetDomainSettings
|
||||
>('https://connect.api.global/consentsoftware', 'getDomainSettings');
|
||||
const domainToRequest = domainArg || window.location.hostname;
|
||||
const domainToRequest = domainArg || window.location.hostname;
|
||||
const response = await csGetDomainSettingsRequest.fire({
|
||||
domain: domainToRequest
|
||||
domain: domainToRequest,
|
||||
});
|
||||
for (const consentTuple of response.consentTuples) {
|
||||
if (consentTuple.level === 'functional' || acceptedCookieLevels.includes(consentTuple.level)) {
|
||||
if (
|
||||
consentTuple.level === 'functional' ||
|
||||
acceptedCookieLevels.includes(consentTuple.level)
|
||||
) {
|
||||
const scriptString = consentTuple.script as string;
|
||||
// tslint:disable-next-line: function-constructor
|
||||
const tupleFunction = new Function('dataArg',`return (${scriptString})(dataArg)`);
|
||||
await tupleFunction(consentTuple.scriptExecutionDataArg);
|
||||
console.log (`Successfully executed ConsentTuple >>${consentTuple.name}<< -> ${consentTuple.description}`);
|
||||
const tupleFunction: plugins.csInterfaces.IConsentTuple['script'] = new Function(
|
||||
'dataArg',
|
||||
'cookieLevelsArg',
|
||||
`return (${scriptString})(dataArg, cookieLevelsArg)`
|
||||
) as plugins.csInterfaces.IConsentTuple['script'];
|
||||
if (typeof tupleFunction === 'function') {
|
||||
await tupleFunction(consentTuple.scriptExecutionDataArg, await this.getCookieLevels());
|
||||
} else {
|
||||
const errorText = 'got malformed script to execuute';
|
||||
console.error(errorText);
|
||||
throw new Error(errorText);
|
||||
}
|
||||
console.log(
|
||||
`Successfully executed ConsentTuple >>${consentTuple.name}<< -> ${consentTuple.description}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user