25 Commits

Author SHA1 Message Date
d3fca66600 1.0.15 2022-08-01 18:02:07 +02:00
14616a8cc8 fix(core): update 2022-08-01 18:02:06 +02:00
1e90ec38e4 1.0.14 2020-10-24 12:35:32 +00:00
23bca9e4de fix(core): update 2020-10-24 12:35:31 +00:00
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
dc9bb6a4a7 1.0.5 2020-09-18 16:13:57 +00:00
3b513c9efd fix(core): update 2020-09-18 16:13:57 +00:00
cbac946c3b 1.0.4 2020-09-18 15:27:29 +00:00
430a0a5ecd fix(core): update 2020-09-18 15:27:29 +00:00
6b52185cd1 1.0.3 2020-09-18 15:26:44 +00:00
9 changed files with 13765 additions and 8782 deletions

22348
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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"
],

View File

@ -27,6 +27,8 @@ Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20W
Use TypeScript for best in class intellisense
This WebClient allows you to use the consent.software api in your webproject
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)

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

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

8
ts/00_commitinfo_data.ts Normal file
View 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.'
}

View File

@ -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}`
);
}
}
}
}

View File

@ -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
};

View File

@ -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"
}