fix(core): update
This commit is contained in:
44
ts/index.ts
44
ts/index.ts
@ -6,7 +6,7 @@ export class CsWebclient {
|
||||
constructor() {
|
||||
this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({
|
||||
dbName: 'consentsoftware',
|
||||
storeName: 'webclient'
|
||||
storeName: 'webclient',
|
||||
});
|
||||
}
|
||||
|
||||
@ -15,27 +15,57 @@ export class CsWebclient {
|
||||
return !!result;
|
||||
}
|
||||
|
||||
public async setCookieLevels(cookieLevelsArg: plugins.csInterfaces.TCookieLevel[]): Promise<boolean> {
|
||||
public async setCookieLevels(
|
||||
cookieLevelsArg: plugins.csInterfaces.TCookieLevel[]
|
||||
): Promise<boolean> {
|
||||
await this.webstore.set('acceptedCookieLevels', {
|
||||
acceptanceTimestamp: Date.now(),
|
||||
acceptedCookieLevels: cookieLevelsArg
|
||||
acceptedCookieLevels: cookieLevelsArg,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public async getCookieLevels(): Promise<plugins.csInterfaces.IWebclientSettings['acceptedCookieLevels']> {
|
||||
public async getCookieLevels(): Promise<
|
||||
plugins.csInterfaces.IWebclientSettings['acceptedCookieLevels']
|
||||
> {
|
||||
const result = await this.webstore.get('acceptedCookieLevels');
|
||||
return result.acceptedCookieLevels;
|
||||
}
|
||||
|
||||
public async isCookieLevelStillValid(): Promise<boolean> {
|
||||
if(!this.isCookieLevelSet) {
|
||||
if (!this.isCookieLevelSet) {
|
||||
return false;
|
||||
}
|
||||
const result = await this.webstore.get('acceptedCookieLevels');
|
||||
if (result.acceptanceTimestamp < (Date.now() - plugins.smarttime.getMilliSecondsFromUnits({months: 3}))) {
|
||||
if (
|
||||
result.acceptanceTimestamp <
|
||||
Date.now() - plugins.smarttime.getMilliSecondsFromUnits({ months: 3 })
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public async getAndRunConsentTuples() {
|
||||
const acceptedCookieLevels = await this.getCookieLevels();
|
||||
if (!acceptedCookieLevels) {
|
||||
console.log('You need to set accepted cookielevels first');
|
||||
return;
|
||||
}
|
||||
const csGetDomainSettingsRequest = new plugins.typedrequest.TypedRequest<
|
||||
plugins.csInterfaces.IRequest_Client_ConsentSoftwareServer_GetDomainSettings
|
||||
>('https://connect.api.global/consentsoftware', 'getDomainSettings');
|
||||
const response = await csGetDomainSettingsRequest.fire({
|
||||
domain: window.location.hostname
|
||||
});
|
||||
for (const consentTuple of response.consentTuples) {
|
||||
if (consentTuple.level === 'functional' || acceptedCookieLevels.includes(consentTuple.level)) {
|
||||
const scriptString = consentTuple.script as string;
|
||||
// tslint:disable-next-line: function-constructor
|
||||
const tupleFunction = new Function(scriptString);
|
||||
await tupleFunction();
|
||||
console.log (`Successfully executed ConsentTuple >>${consentTuple.name}<< -> ${consentTuple.description}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user