Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
7db0e622b6 | |||
482f3cb0ad | |||
adf4a7ee05 | |||
cf7e064074 |
21
package-lock.json
generated
21
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@consentsoftware/webclient",
|
"name": "@consentsoftware/webclient",
|
||||||
"version": "1.0.5",
|
"version": "1.0.7",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -1125,9 +1125,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@consentsoftware/interfaces": {
|
"@consentsoftware/interfaces": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.7",
|
||||||
"resolved": "https://verdaccio.lossless.one/@consentsoftware%2finterfaces/-/interfaces-1.0.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@consentsoftware%2finterfaces/-/interfaces-1.0.7.tgz",
|
||||||
"integrity": "sha512-GovOjaywV+X9VW9AVOjIFIrue/6YXOMKjk/YBnxo52inYWit1v1HuUkjlG/AOqjipqoMB+aujKNXv70oeXa7xQ==",
|
"integrity": "sha512-9G1vGiFcSb+dCWlg+RctMxGE2jHMAc6jQADWya4cFjTJPihoyjfsRJyN8HzohxtTMcYvRMsFJg2djkWY3XHjJg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@apiglobal/typedrequest-interfaces": "^1.0.15"
|
"@apiglobal/typedrequest-interfaces": "^1.0.15"
|
||||||
}
|
}
|
||||||
@ -2049,10 +2049,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/webstore": {
|
"@pushrocks/webstore": {
|
||||||
"version": "1.0.9",
|
"version": "1.0.14",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fwebstore/-/webstore-1.0.9.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fwebstore/-/webstore-1.0.14.tgz",
|
||||||
"integrity": "sha512-wfPRKAVxiD5XWuJwMlgB2VWByrdXIjfPejgnUFJh5IIMt6Y/NA+lh3nRuZVMzNUWfZQIKQn7MOOt0nPDGAEvMw==",
|
"integrity": "sha512-RmI6m1VOW92Vw6I+HUKSrDRJ8vyUBaHpusOoMv0QXraSiwyPlEudEFzi0Ji0nN4++i+ejKIxOuD/gh/jruA4NA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"idb": "^5.0.6"
|
"idb": "^5.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -2315,9 +2316,9 @@
|
|||||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "14.11.1",
|
"version": "14.11.2",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-14.11.1.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-14.11.2.tgz",
|
||||||
"integrity": "sha512-oTQgnd0hblfLsJ6BvJzzSL+Inogp3lq9fGgqRkMB/ziKMgEUaFl801OncOzUmalfzt14N0oPHMK47ipl+wbTIw==",
|
"integrity": "sha512-jiE3QIxJ8JLNcb1Ps6rDbysDhN4xa8DJJvuC9prr6w+1tIh+QAbYyNF3tyiZNLDBIuBCf4KEcV2UvQm/V60xfA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/parcel-bundler": {
|
"@types/parcel-bundler": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@consentsoftware/webclient",
|
"name": "@consentsoftware/webclient",
|
||||||
"version": "1.0.5",
|
"version": "1.0.7",
|
||||||
"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",
|
||||||
@ -15,14 +15,15 @@
|
|||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.0.22",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.15",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"@types/node": "^14.11.1",
|
"@types/node": "^14.11.2",
|
||||||
"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.43",
|
||||||
"@consentsoftware/interfaces": "^1.0.4",
|
"@consentsoftware/interfaces": "^1.0.7",
|
||||||
"@pushrocks/webstore": "^1.0.9"
|
"@pushrocks/smarttime": "^3.0.35",
|
||||||
|
"@pushrocks/webstore": "^1.0.14"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
32
test/test.browser.ts
Normal file
32
test/test.browser.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
import * as webclient from '../ts/index';
|
||||||
|
|
||||||
|
let testClient: webclient.CsWebclient;
|
||||||
|
|
||||||
|
tap.test('should create an instance of webclient', async () => {
|
||||||
|
testClient = new webclient.CsWebclient();
|
||||||
|
expect(testClient).to.be.instanceOf(webclient.CsWebclient);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should return false when asked for present settings', async () => {
|
||||||
|
const result = await testClient.isCookieLevelSet();
|
||||||
|
expect(result).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create a cookielevel setting', async () => {
|
||||||
|
await testClient.setCookieLevels(['functional']);
|
||||||
|
const result = await testClient.getCookieLevels();
|
||||||
|
expect(result).to.contain('functional');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should return true when asked for present settings', async () => {
|
||||||
|
const result = await testClient.isCookieLevelSet();
|
||||||
|
expect(result).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should validity for present settings', async () => {
|
||||||
|
const result = await testClient.isCookieLevelStillValid();
|
||||||
|
expect(result).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.start();
|
@ -1,8 +0,0 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
|
||||||
import * as webclient from '../ts/index';
|
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
|
||||||
console.log(webclient.standardExport);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
|
62
ts/index.ts
62
ts/index.ts
@ -1,12 +1,12 @@
|
|||||||
import * as plugins from './webclient.plugins';
|
import * as plugins from './webclient.plugins';
|
||||||
|
|
||||||
export class CsWebclient {
|
export class CsWebclient {
|
||||||
webstore: plugins.webstore.WebStore;
|
webstore: plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.webstore = new plugins.webstore.WebStore({
|
this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({
|
||||||
dbName: 'consentsoftware',
|
dbName: 'consentsoftware',
|
||||||
storeName: 'webclient'
|
storeName: 'webclient',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,7 +15,57 @@ export class CsWebclient {
|
|||||||
return !!result;
|
return !!result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setCookieLevels(cookieLevels ): Promise<boolean> {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -13,8 +13,10 @@ export {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// @pushrocks scope
|
// @pushrocks scope
|
||||||
|
import * as smarttime from '@pushrocks/smarttime';
|
||||||
import * as webstore from '@pushrocks/webstore';
|
import * as webstore from '@pushrocks/webstore';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
smarttime,
|
||||||
webstore
|
webstore
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user