Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
d3fca66600 | |||
14616a8cc8 | |||
1e90ec38e4 | |||
23bca9e4de | |||
4375c6f94f | |||
71a093b706 | |||
935bb64306 | |||
24e8a2d97a | |||
571efa201f | |||
a50e4df4ed | |||
c6b75f9236 | |||
9157d51471 | |||
0dc496d22a | |||
5f2350a9e7 | |||
e18fd0178d | |||
ebd7ccc171 | |||
7db0e622b6 | |||
482f3cb0ad | |||
adf4a7ee05 | |||
cf7e064074 | |||
dc9bb6a4a7 | |||
3b513c9efd | |||
cbac946c3b | |||
430a0a5ecd | |||
6b52185cd1 |
22348
package-lock.json
generated
22348
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@ -1,10 +1,11 @@
|
||||
{
|
||||
"name": "@consentsoftware/webclient",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.15",
|
||||
"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",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
@ -12,14 +13,19 @@
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.11.7",
|
||||
"tslint": "^5.11.0",
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tstest": "^1.0.72",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.3",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"@apiglobal/typedrequest": "^2.0.8",
|
||||
"@consentsoftware/interfaces": "^1.0.11",
|
||||
"@pushrocks/smarttime": "^3.0.37",
|
||||
"@pushrocks/webstore": "^2.0.5"
|
||||
},
|
||||
"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.js';
|
||||
|
||||
let testClient: webclient.CsWebclient;
|
||||
|
||||
tap.test('should create an instance of webclient', async () => {
|
||||
testClient = new webclient.CsWebclient();
|
||||
expect(testClient).toBeInstanceOf(webclient.CsWebclient);
|
||||
});
|
||||
|
||||
tap.test('should return false when asked for present settings', async () => {
|
||||
const result = await testClient.isCookieLevelSet();
|
||||
expect(result).toBeFalse();
|
||||
});
|
||||
|
||||
tap.test('should create a cookielevel setting', async () => {
|
||||
await testClient.setCookieLevels(['functional']);
|
||||
const result = await testClient.getCookieLevels();
|
||||
expect(result).toContain('functional');
|
||||
});
|
||||
|
||||
tap.test('should return true when asked for present settings', async () => {
|
||||
const result = await testClient.isCookieLevelSet();
|
||||
expect(result).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should validity for present settings', async () => {
|
||||
const result = await testClient.isCookieLevelStillValid();
|
||||
expect(result).toBeTrue();
|
||||
});
|
||||
|
||||
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();
|
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.'
|
||||
}
|
88
ts/index.ts
88
ts/index.ts
@ -1,3 +1,87 @@
|
||||
import * as plugins from './webclient.plugins';
|
||||
import * as plugins from './webclient.plugins.js';
|
||||
|
||||
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: plugins.csInterfaces.IConsentTuple['script'] = new Function(
|
||||
'dataArg',
|
||||
'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}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
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