From 482f3cb0ad213ada638e3dae6f4fe6f06072d61d Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 22 Sep 2020 14:49:13 +0000 Subject: [PATCH] fix(core): update --- package-lock.json | 12 ++++++------ package.json | 4 ++-- ts/index.ts | 44 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index b668be4..c014a0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1125,9 +1125,9 @@ } }, "@consentsoftware/interfaces": { - "version": "1.0.5", - "resolved": "https://verdaccio.lossless.one/@consentsoftware%2finterfaces/-/interfaces-1.0.5.tgz", - "integrity": "sha512-IcdWxVfTznNaTs4tVCkrWpYr2NSewBkQIuoznDhnZaRhRrS6ni5VN5WsRqeZOy5QY4733Kr9aQ8i6FL6OCnpqA==", + "version": "1.0.7", + "resolved": "https://verdaccio.lossless.one/@consentsoftware%2finterfaces/-/interfaces-1.0.7.tgz", + "integrity": "sha512-9G1vGiFcSb+dCWlg+RctMxGE2jHMAc6jQADWya4cFjTJPihoyjfsRJyN8HzohxtTMcYvRMsFJg2djkWY3XHjJg==", "requires": { "@apiglobal/typedrequest-interfaces": "^1.0.15" } @@ -2316,9 +2316,9 @@ "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==" }, "@types/node": { - "version": "14.11.1", - "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-14.11.1.tgz", - "integrity": "sha512-oTQgnd0hblfLsJ6BvJzzSL+Inogp3lq9fGgqRkMB/ziKMgEUaFl801OncOzUmalfzt14N0oPHMK47ipl+wbTIw==", + "version": "14.11.2", + "resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-14.11.2.tgz", + "integrity": "sha512-jiE3QIxJ8JLNcb1Ps6rDbysDhN4xa8DJJvuC9prr6w+1tIh+QAbYyNF3tyiZNLDBIuBCf4KEcV2UvQm/V60xfA==", "dev": true }, "@types/parcel-bundler": { diff --git a/package.json b/package.json index aa9a169..cdfff17 100644 --- a/package.json +++ b/package.json @@ -15,13 +15,13 @@ "@gitzone/tsbuild": "^2.0.22", "@gitzone/tstest": "^1.0.15", "@pushrocks/tapbundle": "^3.0.7", - "@types/node": "^14.11.1", + "@types/node": "^14.11.2", "tslint": "^6.1.3", "tslint-config-prettier": "^1.15.0" }, "dependencies": { "@apiglobal/typedrequest": "^1.0.43", - "@consentsoftware/interfaces": "^1.0.5", + "@consentsoftware/interfaces": "^1.0.7", "@pushrocks/smarttime": "^3.0.35", "@pushrocks/webstore": "^1.0.14" }, diff --git a/ts/index.ts b/ts/index.ts index 360683f..e8dcf94 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -6,7 +6,7 @@ export class CsWebclient { constructor() { this.webstore = new plugins.webstore.WebStore({ dbName: 'consentsoftware', - storeName: 'webclient' + storeName: 'webclient', }); } @@ -15,27 +15,57 @@ export class CsWebclient { return !!result; } - public async setCookieLevels(cookieLevelsArg: plugins.csInterfaces.TCookieLevel[]): Promise { + public async setCookieLevels( + cookieLevelsArg: plugins.csInterfaces.TCookieLevel[] + ): Promise { await this.webstore.set('acceptedCookieLevels', { acceptanceTimestamp: Date.now(), - acceptedCookieLevels: cookieLevelsArg + acceptedCookieLevels: cookieLevelsArg, }); return true; } - public async getCookieLevels(): Promise { + public async getCookieLevels(): Promise< + plugins.csInterfaces.IWebclientSettings['acceptedCookieLevels'] + > { const result = await this.webstore.get('acceptedCookieLevels'); return result.acceptedCookieLevels; } public async isCookieLevelStillValid(): Promise { - 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; } -} \ No newline at end of file + + 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}`); + } + } + } +}