41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import * as plugins from './webclient.plugins';
|
|
|
|
export class CsWebclient {
|
|
webstore: plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>;
|
|
|
|
constructor() {
|
|
this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({
|
|
dbName: 'consentsoftware',
|
|
storeName: 'webclient'
|
|
});
|
|
}
|
|
|
|
public async isCookieLevelSet(): Promise<boolean> {
|
|
const result = await this.webstore.get('acceptedCookieLevels');
|
|
return !!result;
|
|
}
|
|
|
|
public async setCookieLevels(cookieLevelsArg: plugins.csInterfaces.TCookieLevel[]): Promise<boolean> {
|
|
await this.webstore.set('acceptedCookieLevels', {
|
|
acceptanceTimestamp: Date.now(),
|
|
acceptedCookieLevels: cookieLevelsArg
|
|
});
|
|
return true;
|
|
}
|
|
|
|
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) {
|
|
return false;
|
|
}
|
|
const result = await this.webstore.get('acceptedCookieLevels');
|
|
if (result.acceptanceTimestamp < (Date.now() - plugins.smarttime.getMilliSecondsFromUnits({months: 3}))) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
} |