16 Commits

Author SHA1 Message Date
4375c6f94f 1.0.13 2020-10-20 23:58:43 +00:00
71a093b706 fix(core): update 2020-10-20 23:58:43 +00:00
935bb64306 1.0.12 2020-10-20 23:52:32 +00:00
24e8a2d97a fix(core): update 2020-10-20 23:52:31 +00:00
571efa201f 1.0.11 2020-10-20 23:07:15 +00:00
a50e4df4ed fix(core): update 2020-10-20 23:07:14 +00:00
c6b75f9236 1.0.10 2020-10-20 22:09:35 +00:00
9157d51471 fix(core): update 2020-10-20 22:09:35 +00:00
0dc496d22a 1.0.9 2020-10-20 21:50:22 +00:00
5f2350a9e7 fix(core): update 2020-10-20 21:50:21 +00:00
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
adf4a7ee05 1.0.6 2020-09-19 15:18:28 +00:00
cf7e064074 fix(core): update 2020-09-19 15:18:28 +00:00
6 changed files with 784 additions and 830 deletions

1496
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

32
test/test.browser.ts Normal file
View 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();

View File

@ -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();

View File

@ -1,12 +1,12 @@
import * as plugins from './webclient.plugins';
export class CsWebclient {
webstore: plugins.webstore.WebStore;
webstore: plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>;
constructor() {
this.webstore = new plugins.webstore.WebStore({
this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({
dbName: 'consentsoftware',
storeName: 'webclient'
storeName: 'webclient',
});
}
@ -15,7 +15,58 @@ export class CsWebclient {
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(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('dataArg',`return (${scriptString})(dataArg)`);
await tupleFunction(consentTuple.scriptExecutionDataArg);
console.log (`Successfully executed ConsentTuple >>${consentTuple.name}<< -> ${consentTuple.description}`);
}
}
}
}

View File

@ -13,8 +13,10 @@ export {
};
// @pushrocks scope
import * as smarttime from '@pushrocks/smarttime';
import * as webstore from '@pushrocks/webstore';
export {
smarttime,
webstore
};