4 Commits

Author SHA1 Message Date
e18fd0178d 1.0.8 2020-10-20 21:02:14 +00:00
ebd7ccc171 fix(core): update 2020-10-20 21:02:14 +00:00
7db0e622b6 1.0.7 2020-09-22 14:49:14 +00:00
482f3cb0ad fix(core): update 2020-09-22 14:49:13 +00:00
3 changed files with 731 additions and 825 deletions

1495
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@consentsoftware/webclient", "name": "@consentsoftware/webclient",
"version": "1.0.6", "version": "1.0.8",
"private": false, "private": false,
"description": "a webclient for using consent.software in your website. Works with vanilla js, angular, react, you name it.", "description": "a webclient for using consent.software in your website. Works with vanilla js, angular, react, you name it.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -13,17 +13,17 @@
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.0.22",
"@gitzone/tstest": "^1.0.15", "@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.0.7", "@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^14.11.1", "@types/node": "^14.14.0",
"tslint": "^6.1.3", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"@apiglobal/typedrequest": "^1.0.43", "@apiglobal/typedrequest": "^1.0.54",
"@consentsoftware/interfaces": "^1.0.5", "@consentsoftware/interfaces": "^1.0.10",
"@pushrocks/smarttime": "^3.0.35", "@pushrocks/smarttime": "^3.0.37",
"@pushrocks/webstore": "^1.0.14" "@pushrocks/webstore": "^1.0.16"
}, },
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"

View File

@ -6,7 +6,7 @@ export class CsWebclient {
constructor() { constructor() {
this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({ this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({
dbName: 'consentsoftware', dbName: 'consentsoftware',
storeName: 'webclient' storeName: 'webclient',
}); });
} }
@ -15,15 +15,19 @@ export class CsWebclient {
return !!result; 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', { await this.webstore.set('acceptedCookieLevels', {
acceptanceTimestamp: Date.now(), acceptanceTimestamp: Date.now(),
acceptedCookieLevels: cookieLevelsArg acceptedCookieLevels: cookieLevelsArg,
}); });
return true; 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'); const result = await this.webstore.get('acceptedCookieLevels');
return result.acceptedCookieLevels; return result.acceptedCookieLevels;
} }
@ -33,9 +37,36 @@ export class CsWebclient {
return false; return false;
} }
const result = await this.webstore.get('acceptedCookieLevels'); 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 false;
} }
return true; return true;
} }
public async getAndRunConsentTuples(domainArg?: string) {
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 domainToRequest = domainArg || window.location.hostname;
const response = await csGetDomainSettingsRequest.fire({
domain: domainToRequest
});
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}`);
}
}
}
} }