Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
d3fca66600 | |||
14616a8cc8 | |||
1e90ec38e4 | |||
23bca9e4de | |||
4375c6f94f | |||
71a093b706 | |||
935bb64306 | |||
24e8a2d97a | |||
571efa201f | |||
a50e4df4ed | |||
c6b75f9236 | |||
9157d51471 | |||
0dc496d22a | |||
5f2350a9e7 | |||
e18fd0178d | |||
ebd7ccc171 |
22368
package-lock.json
generated
22368
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "@consentsoftware/webclient",
|
"name": "@consentsoftware/webclient",
|
||||||
"version": "1.0.7",
|
"version": "1.0.15",
|
||||||
"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",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -12,18 +13,18 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.63",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.72",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^14.11.2",
|
"@types/node": "^18.6.3",
|
||||||
"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": "^2.0.8",
|
||||||
"@consentsoftware/interfaces": "^1.0.7",
|
"@consentsoftware/interfaces": "^1.0.11",
|
||||||
"@pushrocks/smarttime": "^3.0.35",
|
"@pushrocks/smarttime": "^3.0.37",
|
||||||
"@pushrocks/webstore": "^1.0.14"
|
"@pushrocks/webstore": "^2.0.5"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
@ -1,32 +1,32 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as webclient from '../ts/index';
|
import * as webclient from '../ts/index.js';
|
||||||
|
|
||||||
let testClient: webclient.CsWebclient;
|
let testClient: webclient.CsWebclient;
|
||||||
|
|
||||||
tap.test('should create an instance of webclient', async () => {
|
tap.test('should create an instance of webclient', async () => {
|
||||||
testClient = new webclient.CsWebclient();
|
testClient = new webclient.CsWebclient();
|
||||||
expect(testClient).to.be.instanceOf(webclient.CsWebclient);
|
expect(testClient).toBeInstanceOf(webclient.CsWebclient);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should return false when asked for present settings', async () => {
|
tap.test('should return false when asked for present settings', async () => {
|
||||||
const result = await testClient.isCookieLevelSet();
|
const result = await testClient.isCookieLevelSet();
|
||||||
expect(result).to.be.false;
|
expect(result).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a cookielevel setting', async () => {
|
tap.test('should create a cookielevel setting', async () => {
|
||||||
await testClient.setCookieLevels(['functional']);
|
await testClient.setCookieLevels(['functional']);
|
||||||
const result = await testClient.getCookieLevels();
|
const result = await testClient.getCookieLevels();
|
||||||
expect(result).to.contain('functional');
|
expect(result).toContain('functional');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should return true when asked for present settings', async () => {
|
tap.test('should return true when asked for present settings', async () => {
|
||||||
const result = await testClient.isCookieLevelSet();
|
const result = await testClient.isCookieLevelSet();
|
||||||
expect(result).to.be.true;
|
expect(result).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should validity for present settings', async () => {
|
tap.test('should validity for present settings', async () => {
|
||||||
const result = await testClient.isCookieLevelStillValid();
|
const result = await testClient.isCookieLevelStillValid();
|
||||||
expect(result).to.be.true;
|
expect(result).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@consentsoftware/webclient',
|
||||||
|
version: '1.0.15',
|
||||||
|
description: 'a webclient for using consent.software in your website. Works with vanilla js, angular, react, you name it.'
|
||||||
|
}
|
32
ts/index.ts
32
ts/index.ts
@ -1,4 +1,4 @@
|
|||||||
import * as plugins from './webclient.plugins';
|
import * as plugins from './webclient.plugins.js';
|
||||||
|
|
||||||
export class CsWebclient {
|
export class CsWebclient {
|
||||||
webstore: plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>;
|
webstore: plugins.webstore.WebStore<plugins.csInterfaces.IWebclientSettings>;
|
||||||
@ -29,7 +29,7 @@ export class CsWebclient {
|
|||||||
plugins.csInterfaces.IWebclientSettings['acceptedCookieLevels']
|
plugins.csInterfaces.IWebclientSettings['acceptedCookieLevels']
|
||||||
> {
|
> {
|
||||||
const result = await this.webstore.get('acceptedCookieLevels');
|
const result = await this.webstore.get('acceptedCookieLevels');
|
||||||
return result.acceptedCookieLevels;
|
return result?.acceptedCookieLevels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async isCookieLevelStillValid(): Promise<boolean> {
|
public async isCookieLevelStillValid(): Promise<boolean> {
|
||||||
@ -46,7 +46,7 @@ export class CsWebclient {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAndRunConsentTuples() {
|
public async getAndRunConsentTuples(domainArg?: string) {
|
||||||
const acceptedCookieLevels = await this.getCookieLevels();
|
const acceptedCookieLevels = await this.getCookieLevels();
|
||||||
if (!acceptedCookieLevels) {
|
if (!acceptedCookieLevels) {
|
||||||
console.log('You need to set accepted cookielevels first');
|
console.log('You need to set accepted cookielevels first');
|
||||||
@ -55,16 +55,32 @@ export class CsWebclient {
|
|||||||
const csGetDomainSettingsRequest = new plugins.typedrequest.TypedRequest<
|
const csGetDomainSettingsRequest = new plugins.typedrequest.TypedRequest<
|
||||||
plugins.csInterfaces.IRequest_Client_ConsentSoftwareServer_GetDomainSettings
|
plugins.csInterfaces.IRequest_Client_ConsentSoftwareServer_GetDomainSettings
|
||||||
>('https://connect.api.global/consentsoftware', 'getDomainSettings');
|
>('https://connect.api.global/consentsoftware', 'getDomainSettings');
|
||||||
|
const domainToRequest = domainArg || window.location.hostname;
|
||||||
const response = await csGetDomainSettingsRequest.fire({
|
const response = await csGetDomainSettingsRequest.fire({
|
||||||
domain: window.location.hostname
|
domain: domainToRequest,
|
||||||
});
|
});
|
||||||
for (const consentTuple of response.consentTuples) {
|
for (const consentTuple of response.consentTuples) {
|
||||||
if (consentTuple.level === 'functional' || acceptedCookieLevels.includes(consentTuple.level)) {
|
if (
|
||||||
|
consentTuple.level === 'functional' ||
|
||||||
|
acceptedCookieLevels.includes(consentTuple.level)
|
||||||
|
) {
|
||||||
const scriptString = consentTuple.script as string;
|
const scriptString = consentTuple.script as string;
|
||||||
// tslint:disable-next-line: function-constructor
|
// tslint:disable-next-line: function-constructor
|
||||||
const tupleFunction = new Function(scriptString);
|
const tupleFunction: plugins.csInterfaces.IConsentTuple['script'] = new Function(
|
||||||
await tupleFunction();
|
'dataArg',
|
||||||
console.log (`Successfully executed ConsentTuple >>${consentTuple.name}<< -> ${consentTuple.description}`);
|
'cookieLevelsArg',
|
||||||
|
`return (${scriptString})(dataArg, cookieLevelsArg)`
|
||||||
|
) as plugins.csInterfaces.IConsentTuple['script'];
|
||||||
|
if (typeof tupleFunction === 'function') {
|
||||||
|
await tupleFunction(consentTuple.scriptExecutionDataArg, await this.getCookieLevels());
|
||||||
|
} else {
|
||||||
|
const errorText = 'got malformed script to execuute';
|
||||||
|
console.error(errorText);
|
||||||
|
throw new Error(errorText);
|
||||||
|
}
|
||||||
|
console.log(
|
||||||
|
`Successfully executed ConsentTuple >>${consentTuple.name}<< -> ${consentTuple.description}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user