webclient/ts/index.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-09-18 15:15:37 +00:00
import * as plugins from './webclient.plugins';
2020-09-18 16:13:57 +00:00
export class CsWebclient {
2020-09-19 15:18:28 +00:00
webstore: plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>;
2020-09-18 16:13:57 +00:00
constructor() {
2020-09-19 15:18:28 +00:00
this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({
2020-09-18 16:13:57 +00:00
dbName: 'consentsoftware',
storeName: 'webclient'
});
}
public async isCookieLevelSet(): Promise<boolean> {
const result = await this.webstore.get('acceptedCookieLevels');
return !!result;
}
2020-09-19 15:18:28 +00:00
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;
}
2020-09-18 16:13:57 +00:00
2020-09-19 15:18:28 +00:00
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;
2020-09-18 16:13:57 +00:00
}
}