Skip to content

Commit

Permalink
feat: ✨ add consent api
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmannZ committed Apr 10, 2024
1 parent 43d5aaf commit 06d2c4c
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 37 deletions.
31 changes: 0 additions & 31 deletions src/consent.spec.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/consent.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/consent/get-all-checkboxes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/get-all-checkboxes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get-all-checkboxes.ts#L1

Added line #L1 was not covered by tests

/**
* Returns an object with the checkbox status of all purposes.
*/
export function getAllCheckboxes(): { [key: string]: boolean } {
return getZaraz().consent.getAllCheckboxes();

Check warning on line 7 in src/consent/get-all-checkboxes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get-all-checkboxes.ts#L6-L7

Added lines #L6 - L7 were not covered by tests
}
8 changes: 8 additions & 0 deletions src/consent/get-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/get-all.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get-all.ts#L1

Added line #L1 was not covered by tests

/**
* Returns an object with the consent status of all purposes.
*/
export function getAll(): { [key: string]: boolean } {
return getZaraz().consent.getAll();

Check warning on line 7 in src/consent/get-all.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get-all.ts#L6-L7

Added lines #L6 - L7 were not covered by tests
}
14 changes: 14 additions & 0 deletions src/consent/get-purposes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/get-purposes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get-purposes.ts#L1

Added line #L1 was not covered by tests

type Purpose = {
name: string;
description: string;
order: number;
};

/**
* An object containing all configured purposes, with their ID, name, description, and order.
*/
export function getPurposes(): { [key: string]: Purpose } {
return getZaraz().consent.purposes;

Check warning on line 13 in src/consent/get-purposes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get-purposes.ts#L12-L13

Added lines #L12 - L13 were not covered by tests
}
14 changes: 14 additions & 0 deletions src/consent/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/get.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get.ts#L1

Added line #L1 was not covered by tests

/**
* Get the current consent status for a purpose using the purpose ID.
*
* ```
* true: The consent was granted.
* false: The consent was not granted.
* undefined: The purpose does not exist.
* ```
*/
export function get(purposeId: string): boolean | undefined {
return getZaraz().consent.get(purposeId);

Check warning on line 13 in src/consent/get.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/get.ts#L12-L13

Added lines #L12 - L13 were not covered by tests
}
19 changes: 19 additions & 0 deletions src/consent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { get } from './get';
import { getAll } from './get-all';
import { getAllCheckboxes } from './get-all-checkboxes';
import { sendQueuedEvents } from './send-queued-events';
import { set } from './set';
import { setAll } from './set-all';
import { setAllCheckboxes } from './set-all-checkboxes';
import { setCheckboxes } from './set-checkboxes';

Check warning on line 8 in src/consent/index.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/index.ts#L1-L8

Added lines #L1 - L8 were not covered by tests

export const consent = {

Check warning on line 10 in src/consent/index.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/index.ts#L10

Added line #L10 was not covered by tests
get,
set,
getAll,
setAll,
getAllCheckboxes,
setCheckboxes,
setAllCheckboxes,
sendQueuedEvents,
};
8 changes: 8 additions & 0 deletions src/consent/send-queued-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/send-queued-events.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/send-queued-events.ts#L1

Added line #L1 was not covered by tests

/**
* If some Pageview-based events were not sent due to a lack of consent, they can be sent using this method after consent was granted.
*/
export function sendQueuedEvents(): void {
getZaraz().consent.sendQueuedEvents();

Check warning on line 7 in src/consent/send-queued-events.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/send-queued-events.ts#L6-L7

Added lines #L6 - L7 were not covered by tests
}
8 changes: 8 additions & 0 deletions src/consent/set-all-checkboxes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/set-all-checkboxes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set-all-checkboxes.ts#L1

Added line #L1 was not covered by tests

/**
* Set the checkboxStatus status for all purposes in the consent modal at once.
*/
export function setAllCheckboxes(checkboxStatus: boolean): void {
getZaraz().consent.setAllCheckboxes(checkboxStatus);

Check warning on line 7 in src/consent/set-all-checkboxes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set-all-checkboxes.ts#L6-L7

Added lines #L6 - L7 were not covered by tests
}
8 changes: 8 additions & 0 deletions src/consent/set-all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/set-all.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set-all.ts#L1

Added line #L1 was not covered by tests

/**
* Set the consent status for all purposes at once.
*/
export function setAll(consentStatus: boolean): void {
getZaraz().consent.setAll(consentStatus);

Check warning on line 7 in src/consent/set-all.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set-all.ts#L6-L7

Added lines #L6 - L7 were not covered by tests
}
10 changes: 10 additions & 0 deletions src/consent/set-checkboxes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/set-checkboxes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set-checkboxes.ts#L1

Added line #L1 was not covered by tests

/**
* Set the consent status for some purposes using the purpose ID.
*/
export function setCheckboxes(checkboxesStatus: {

Check warning on line 6 in src/consent/set-checkboxes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set-checkboxes.ts#L6

Added line #L6 was not covered by tests
[key: string]: boolean;
}): void {
getZaraz().consent.setCheckboxes(checkboxesStatus);

Check warning on line 9 in src/consent/set-checkboxes.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set-checkboxes.ts#L8-L9

Added lines #L8 - L9 were not covered by tests
}
8 changes: 8 additions & 0 deletions src/consent/set.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getZaraz } from '../helpers/get-zaraz';

Check warning on line 1 in src/consent/set.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set.ts#L1

Added line #L1 was not covered by tests

/**
* Set the consent status for some purposes using the purpose ID.
*/
export function set(consentPreferences: { [key: string]: boolean }): void {
getZaraz().consent.set(consentPreferences);

Check warning on line 7 in src/consent/set.ts

View check run for this annotation

Codecov / codecov/patch

src/consent/set.ts#L6-L7

Added lines #L6 - L7 were not covered by tests
}
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* istanbul ignore file */

import { consent } from './consent';
import { ecommerce } from './ecommerce';
import { set } from './set';
import { track } from './track';
Expand All @@ -15,9 +16,11 @@ export const zaraz = {
track,
set,
ecommerce,
consent,
};

// Export typing etc.
export * from './consent';
export * from './ecommerce';
export * from './set';
export * from './track';

0 comments on commit 06d2c4c

Please sign in to comment.