Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
935bb64306 | |||
24e8a2d97a | |||
571efa201f | |||
a50e4df4ed | |||
c6b75f9236 | |||
9157d51471 | |||
0dc496d22a | |||
5f2350a9e7 | |||
e18fd0178d | |||
ebd7ccc171 | |||
7db0e622b6 | |||
482f3cb0ad | |||
adf4a7ee05 | |||
cf7e064074 | |||
dc9bb6a4a7 | |||
3b513c9efd | |||
cbac946c3b | |||
430a0a5ecd |
1533
package-lock.json
generated
1533
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@consentsoftware/webclient",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.12",
|
||||
"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,13 +13,18 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@gitzone/tstest": "^1.0.52",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.11.7",
|
||||
"tslint": "^5.11.0",
|
||||
"@types/node": "^14.14.0",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"@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"
|
||||
],
|
||||
|
@ -27,6 +27,8 @@ Platform support | [ or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
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();
|
71
ts/index.ts
71
ts/index.ts
@ -1,3 +1,72 @@
|
||||
import * as plugins from './webclient.plugins';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
||||
export class CsWebclient {
|
||||
webstore: plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>;
|
||||
|
||||
constructor() {
|
||||
this.webstore = new plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>({
|
||||
dbName: 'consentsoftware',
|
||||
storeName: 'webclient',
|
||||
});
|
||||
}
|
||||
|
||||
public async isCookieLevelSet(): Promise<boolean> {
|
||||
const result = await this.webstore.get('acceptedCookieLevels');
|
||||
return !!result;
|
||||
}
|
||||
|
||||
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(`return (${scriptString})()`);
|
||||
await tupleFunction(consentTuple.scriptExecutionDataArg);
|
||||
console.log (`Successfully executed ConsentTuple >>${consentTuple.name}<< -> ${consentTuple.description}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,22 @@
|
||||
const removeme = {};
|
||||
export { removeme };
|
||||
// consentsoftware scope
|
||||
import * as csInterfaces from '@consentsoftware/interfaces';
|
||||
|
||||
export {
|
||||
csInterfaces
|
||||
};
|
||||
|
||||
// apiglobal scope
|
||||
import * as typedrequest from '@apiglobal/typedrequest';
|
||||
|
||||
export {
|
||||
typedrequest
|
||||
};
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smarttime from '@pushrocks/smarttime';
|
||||
import * as webstore from '@pushrocks/webstore';
|
||||
|
||||
export {
|
||||
smarttime,
|
||||
webstore
|
||||
};
|
||||
|
Reference in New Issue
Block a user