@ht-sdks/consent-manager 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/commonjs/__tests__/consent-manager/dialog.test.js +33 -0
  2. package/commonjs/__tests__/consent-manager-builder/analytics.test.js +135 -46
  3. package/commonjs/__tests__/consent-manager-builder/index.todo.js +48 -87
  4. package/commonjs/__tests__/consent-manager-builder/preferences.test.js +136 -55
  5. package/commonjs/__tests__/index.test.js +12 -12
  6. package/commonjs/consent-manager/banner.js +35 -19
  7. package/commonjs/consent-manager/buttons.js +5 -5
  8. package/commonjs/consent-manager/cancel-dialog.js +26 -10
  9. package/commonjs/consent-manager/categories.js +2 -2
  10. package/commonjs/consent-manager/container.js +2 -3
  11. package/commonjs/consent-manager/dialog.js +39 -23
  12. package/commonjs/consent-manager/font-styles.js +2 -2
  13. package/commonjs/consent-manager/index.js +41 -25
  14. package/commonjs/consent-manager/preference-dialog.js +36 -20
  15. package/commonjs/consent-manager-builder/analytics.js +19 -7
  16. package/commonjs/consent-manager-builder/index.js +31 -30
  17. package/commonjs/consent-manager-builder/preferences.js +100 -24
  18. package/commonjs/index.js +5 -4
  19. package/commonjs/standalone.js +25 -11
  20. package/esm/__tests__/consent-manager/dialog.test.js +28 -0
  21. package/esm/__tests__/consent-manager-builder/analytics.test.js +123 -34
  22. package/esm/__tests__/consent-manager-builder/index.todo.js +34 -73
  23. package/esm/__tests__/consent-manager-builder/preferences.test.js +135 -54
  24. package/esm/consent-manager/banner.js +5 -3
  25. package/esm/consent-manager/buttons.js +4 -4
  26. package/esm/consent-manager/cancel-dialog.js +4 -2
  27. package/esm/consent-manager/categories.js +2 -2
  28. package/esm/consent-manager/container.js +1 -1
  29. package/esm/consent-manager/dialog.js +7 -5
  30. package/esm/consent-manager/font-styles.js +2 -2
  31. package/esm/consent-manager/index.js +19 -17
  32. package/esm/consent-manager/preference-dialog.js +7 -5
  33. package/esm/consent-manager-builder/analytics.js +18 -6
  34. package/esm/consent-manager-builder/index.js +28 -27
  35. package/esm/consent-manager-builder/preferences.js +96 -20
  36. package/esm/index.js +4 -3
  37. package/esm/standalone.js +3 -3
  38. package/esm/types.js +1 -0
  39. package/package.json +62 -67
  40. package/src/__tests__/consent-manager/dialog.test.tsx +42 -0
  41. package/src/__tests__/consent-manager-builder/analytics.test.ts +75 -33
  42. package/src/__tests__/consent-manager-builder/index.todo.js +52 -95
  43. package/src/__tests__/consent-manager-builder/preferences.test.ts +43 -27
  44. package/src/consent-manager/banner.tsx +11 -11
  45. package/src/consent-manager/buttons.tsx +26 -10
  46. package/src/consent-manager/cancel-dialog.tsx +1 -1
  47. package/src/consent-manager/categories.ts +2 -2
  48. package/src/consent-manager/container.tsx +14 -17
  49. package/src/consent-manager/dialog.tsx +4 -4
  50. package/src/consent-manager/font-styles.tsx +12 -2
  51. package/src/consent-manager/index.tsx +27 -29
  52. package/src/consent-manager/preference-dialog.tsx +13 -11
  53. package/src/consent-manager-builder/analytics.ts +20 -6
  54. package/src/consent-manager-builder/index.tsx +30 -29
  55. package/src/consent-manager-builder/preferences.ts +59 -30
  56. package/src/index.ts +8 -4
  57. package/src/standalone.tsx +1 -1
  58. package/src/types.ts +9 -3
  59. package/standalone/consent-manager.js +5 -10
  60. package/standalone/consent-manager.js.map +1 -1
  61. package/types/consent-manager/banner.d.ts +1 -1
  62. package/types/consent-manager/buttons.d.ts +6 -7
  63. package/types/consent-manager/cancel-dialog.d.ts +1 -1
  64. package/types/consent-manager/index.d.ts +3 -3
  65. package/types/consent-manager/preference-dialog.d.ts +1 -1
  66. package/types/consent-manager-builder/analytics.d.ts +2 -1
  67. package/types/consent-manager-builder/index.d.ts +7 -8
  68. package/types/consent-manager-builder/preferences.d.ts +4 -6
  69. package/types/index.d.ts +1 -1
  70. package/types/types.d.ts +15 -11
  71. package/commonjs/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -155
  72. package/commonjs/consent-manager-builder/fetch-destinations.js +0 -104
  73. package/esm/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -150
  74. package/esm/consent-manager-builder/fetch-destinations.js +0 -98
  75. package/src/__tests__/consent-manager-builder/fetch-destinations.test.ts +0 -89
  76. package/src/consent-manager-builder/fetch-destinations.ts +0 -50
  77. package/types/consent-manager-builder/fetch-destinations.d.ts +0 -2
  78. package/types/src/__tests__/consent-manager-builder/analytics.test.d.ts +0 -1
  79. package/types/src/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +0 -1
  80. package/types/src/__tests__/consent-manager-builder/preferences.test.d.ts +0 -1
  81. package/types/src/__tests__/index.test.d.ts +0 -1
  82. package/types/src/consent-manager/banner.d.ts +0 -21
  83. package/types/src/consent-manager/buttons.d.ts +0 -13
  84. package/types/src/consent-manager/cancel-dialog.d.ts +0 -19
  85. package/types/src/consent-manager/categories.d.ts +0 -3
  86. package/types/src/consent-manager/container.d.ts +0 -35
  87. package/types/src/consent-manager/dialog.d.ts +0 -29
  88. package/types/src/consent-manager/font-styles.d.ts +0 -2
  89. package/types/src/consent-manager/index.d.ts +0 -35
  90. package/types/src/consent-manager/preference-dialog.d.ts +0 -32
  91. package/types/src/consent-manager-builder/analytics.d.ts +0 -14
  92. package/types/src/consent-manager-builder/fetch-destinations.d.ts +0 -2
  93. package/types/src/consent-manager-builder/index.d.ts +0 -126
  94. package/types/src/consent-manager-builder/preferences.d.ts +0 -26
  95. package/types/src/index.d.ts +0 -7
  96. package/types/src/standalone.d.ts +0 -5
  97. package/types/src/types.d.ts +0 -130
  98. /package/types/__tests__/{consent-manager-builder/fetch-destinations.test.d.ts → consent-manager/dialog.test.d.ts} +0 -0
@@ -1,2 +0,0 @@
1
- import { Destination } from '../types';
2
- export default function fetchDestinations(cdnHost: string, writeKeys: string[]): Promise<Destination[]>;
@@ -1,126 +0,0 @@
1
- import { Component } from 'react';
2
- import { Destination, CategoryPreferences, CustomCategories, DefaultDestinationBehavior, HtEventsBrowserOptions } from '../types';
3
- import { CookieAttributes } from 'js-cookie';
4
- interface Props {
5
- /** Your Hightouch Write key for your website */
6
- writeKey: string;
7
- /** Options to pass to Hightouch Events Browser SDK */
8
- options?: HtEventsBrowserOptions;
9
- cookieDomain?: string;
10
- cookieName?: string;
11
- cookieAttributes?: CookieAttributes;
12
- /**
13
- * Number of days until the preferences cookie should expire
14
- */
15
- cookieExpires?: number;
16
- /**
17
- * An initial selection of Preferences
18
- */
19
- initialPreferences?: CategoryPreferences;
20
- /**
21
- * Provide a function to define whether or not consent should be required
22
- */
23
- shouldRequireConsent?: () => Promise<boolean> | boolean;
24
- /**
25
- * Render props for the Consent Manager builder
26
- */
27
- children: (props: RenderProps) => React.ReactElement;
28
- /**
29
- * Allows for customizing how to show different categories of consent.
30
- */
31
- mapCustomPreferences?: (destinations: Destination[], preferences: CategoryPreferences) => {
32
- destinationPreferences: CategoryPreferences;
33
- customPreferences: CategoryPreferences;
34
- };
35
- /**
36
- * Allows for adding custom consent categories by mapping a custom category to Hightouch integrations
37
- */
38
- customCategories?: CustomCategories;
39
- /**
40
- * Specified default behavior for when new destinations are detected on the source(s) of this consent manager.
41
- */
42
- defaultDestinationBehavior?: DefaultDestinationBehavior;
43
- /**
44
- * A callback for dealing with errors in the Consent Manager
45
- */
46
- onError?: (err: Error) => void | Promise<void>;
47
- /**
48
- * CDN to fetch list of integrations from
49
- */
50
- cdnHost?: string;
51
- /**
52
- * Default true
53
- * Reload the page if the trackers have already been initialized so that
54
- * the user's new preferences can take effect.
55
- */
56
- shouldReload?: boolean;
57
- /**
58
- * Default false
59
- * Disable htevents.load for local testing.
60
- */
61
- devMode?: boolean;
62
- /**
63
- * Default false
64
- * Use default categories set by Consent Manager instead of destinations
65
- */
66
- useDefaultCategories?: boolean;
67
- }
68
- interface RenderProps {
69
- destinations: Destination[];
70
- newDestinations: Destination[];
71
- preferences: CategoryPreferences;
72
- destinationPreferences: CategoryPreferences;
73
- isConsentRequired: boolean;
74
- customCategories?: CustomCategories;
75
- havePreferencesChanged: boolean;
76
- workspaceAddedNewDestinations: boolean;
77
- setPreferences: (newPreferences: CategoryPreferences) => void;
78
- resetPreferences: () => void;
79
- saveConsent: (newPreferences?: CategoryPreferences | boolean, shouldReload?: boolean, devMode?: boolean) => void;
80
- }
81
- interface State {
82
- isLoading: boolean;
83
- destinations: Destination[];
84
- newDestinations: Destination[];
85
- preferences?: CategoryPreferences;
86
- destinationPreferences?: CategoryPreferences;
87
- isConsentRequired: boolean;
88
- havePreferencesChanged: boolean;
89
- workspaceAddedNewDestinations: boolean;
90
- }
91
- export default class ConsentManagerBuilder extends Component<Props, State> {
92
- static displayName: string;
93
- static defaultProps: {
94
- options: undefined;
95
- onError: undefined;
96
- shouldRequireConsent: () => boolean;
97
- initialPreferences: {};
98
- cdnHost: string;
99
- shouldReload: boolean;
100
- devMode: boolean;
101
- useDefaultCategories: boolean;
102
- };
103
- state: {
104
- isLoading: boolean;
105
- destinations: never[];
106
- newDestinations: never[];
107
- preferences: {};
108
- destinationPreferences: {};
109
- isConsentRequired: boolean;
110
- havePreferencesChanged: boolean;
111
- workspaceAddedNewDestinations: boolean;
112
- useDefaultCategories: boolean;
113
- };
114
- render(): import("react").ReactElement<any, string | ((props: any) => import("react").ReactElement<any, any> | null) | (new (props: any) => Component<any, any, any>)> | null;
115
- componentDidMount(): Promise<void>;
116
- initialise: () => Promise<void>;
117
- handleSetPreferences: (newPreferences: CategoryPreferences) => void;
118
- handleResetPreferences: () => void;
119
- handleSaveConsent: (newPreferences: CategoryPreferences | undefined, shouldReload: boolean, devMode?: boolean | undefined) => void;
120
- mergePreferences: (args: {
121
- destinations: Destination[];
122
- existingPreferences?: CategoryPreferences | undefined;
123
- newPreferences?: CategoryPreferences | undefined;
124
- }) => CategoryPreferences;
125
- }
126
- export {};
@@ -1,26 +0,0 @@
1
- /// <reference types="node" />
2
- import { CookieAttributes } from 'js-cookie';
3
- import { Preferences } from '../types';
4
- import { EventEmitter } from 'events';
5
- export declare const DEFAULT_COOKIE_NAME = "ht-cm-preferences";
6
- export interface PreferencesManager {
7
- loadPreferences(cookieName?: string): Preferences;
8
- onPreferencesSaved(listener: (prefs: Preferences) => void): void;
9
- savePreferences(prefs: SavePreferences): void;
10
- }
11
- export declare function loadPreferences(cookieName?: string): Preferences;
12
- declare type SavePreferences = Preferences & {
13
- cookieDomain?: string;
14
- cookieName?: string;
15
- cookieExpires?: number;
16
- cookieAttributes?: CookieAttributes;
17
- };
18
- /**
19
- * Subscribes to consent preferences changing over time and returns
20
- * a cleanup function that can be invoked to remove the instantiated listener.
21
- *
22
- * @param listener a function to be invoked when ConsentPreferences are saved
23
- */
24
- export declare function onPreferencesSaved(listener: (prefs: Preferences) => void): () => EventEmitter;
25
- export declare function savePreferences({ destinationPreferences, customPreferences, cookieDomain, cookieName, cookieExpires, cookieAttributes }: SavePreferences): void;
26
- export {};
@@ -1,7 +0,0 @@
1
- import CMB from './consent-manager-builder';
2
- import CM from './consent-manager';
3
- export { openDialog as openConsentManager } from './consent-manager/container';
4
- export { loadPreferences, savePreferences, onPreferencesSaved } from './consent-manager-builder/preferences';
5
- export declare const ConsentManagerBuilder: typeof CMB;
6
- export declare const ConsentManager: typeof CM;
7
- export declare function doNotTrack(): boolean | null;
@@ -1,5 +0,0 @@
1
- import inEU from '@segment/in-eu';
2
- import { openConsentManager, doNotTrack } from '.';
3
- import * as preferences from './consent-manager-builder/preferences';
4
- export declare const version: string | undefined;
5
- export { openConsentManager, doNotTrack, inEU, preferences };
@@ -1,130 +0,0 @@
1
- /// <reference types="react" />
2
- import { CloseBehaviorFunction } from './consent-manager/container';
3
- import { PreferencesManager } from './consent-manager-builder/preferences';
4
- import { CookieAttributes } from 'js-cookie';
5
- export declare type HtEventsBrowserOptions = {
6
- integrations?: Record<string, boolean>;
7
- apiHost?: string;
8
- protocol?: string;
9
- };
10
- export declare type HtEventsBrowser = {
11
- initialized: boolean;
12
- load: (writeKey: string, options?: HtEventsBrowserOptions) => void;
13
- track: (event: string, properties: Record<string, any>, options?: any, callback?: any) => void;
14
- addSourceMiddleware: (middleware: Middleware) => void;
15
- };
16
- export declare type Middleware = (input: MiddlewareInput) => void;
17
- interface MiddlewareInput {
18
- payload: {
19
- obj: Record<string, any>;
20
- [key: string]: any;
21
- };
22
- integrations?: Record<string, boolean>;
23
- next: (payload: MiddlewareInput['payload']) => void;
24
- }
25
- export declare type WindowWithHtEvents = Window & typeof globalThis & {
26
- htevents?: HtEventsBrowser;
27
- };
28
- export declare type WindowWithConsentManagerConfig = Window & typeof globalThis & {
29
- consentManagerConfig?: (args: StandaloneConsentManagerParams) => ConsentManagerInput | ConsentManagerInput;
30
- };
31
- export declare type ConsentManagerInput = ConsentManagerProps & {
32
- container: string;
33
- };
34
- export declare type DefaultDestinationBehavior = 'enable' | 'disable' | 'imply' | 'ask';
35
- export declare type CloseBehavior = 'accept' | 'deny' | 'dismiss';
36
- interface StandaloneConsentManagerParams {
37
- React: unknown;
38
- version?: string;
39
- openConsentManager: () => void;
40
- doNotTrack: () => boolean | null;
41
- inEU: () => boolean;
42
- preferences: PreferencesManager;
43
- inRegions: (regions: string[]) => () => boolean;
44
- }
45
- export interface Preferences {
46
- destinationPreferences?: CategoryPreferences;
47
- customPreferences?: CategoryPreferences;
48
- }
49
- export interface Destination {
50
- id: string;
51
- name: string;
52
- creationName: string;
53
- description: string;
54
- website: string;
55
- category: string;
56
- }
57
- export interface CategoryPreferences {
58
- functional?: boolean | null | undefined;
59
- marketingAndAnalytics?: boolean | null | undefined;
60
- advertising?: boolean | null | undefined;
61
- [category: string]: boolean | null | undefined | string;
62
- }
63
- export interface CustomCategories {
64
- [key: string]: CustomCategory;
65
- }
66
- interface CustomCategory {
67
- integrations?: string[];
68
- purpose: string;
69
- }
70
- export interface PreferencesCategories {
71
- key: string;
72
- name?: string;
73
- description?: string;
74
- example?: string;
75
- }
76
- export interface PreferenceDialogTemplate {
77
- headings?: {
78
- allowValue?: string;
79
- categoryValue?: string;
80
- purposeValue?: string;
81
- toolsValue?: string;
82
- };
83
- checkboxes?: {
84
- noValue?: string;
85
- yesValue?: string;
86
- };
87
- actionButtons?: {
88
- saveValue?: string;
89
- cancelValue?: string;
90
- };
91
- cancelDialogButtons?: {
92
- cancelValue?: string;
93
- backValue?: string;
94
- };
95
- categories?: PreferencesCategories[];
96
- }
97
- export interface ConsentManagerProps {
98
- writeKey: string;
99
- options?: HtEventsBrowserOptions;
100
- shouldRequireConsent?: () => Promise<boolean> | boolean;
101
- implyConsentOnInteraction?: boolean;
102
- cookieDomain?: string;
103
- cookieName?: string;
104
- cookieAttributes?: CookieAttributes;
105
- cookieExpires?: number;
106
- bannerContent?: React.ReactNode;
107
- bannerSubContent?: string;
108
- bannerActionsBlock?: ((props: ActionsBlockProps) => React.ReactElement) | true;
109
- bannerTextColor?: string;
110
- bannerBackgroundColor?: string;
111
- bannerHideCloseButton: boolean;
112
- bannerAsModal?: boolean;
113
- preferencesDialogTitle?: React.ReactNode;
114
- preferencesDialogContent?: React.ReactNode;
115
- onError?: (error: Error | undefined) => void;
116
- cancelDialogTitle?: React.ReactNode;
117
- cancelDialogContent?: React.ReactNode;
118
- closeBehavior?: CloseBehavior | CloseBehaviorFunction;
119
- initialPreferences?: CategoryPreferences;
120
- customCategories?: CustomCategories;
121
- defaultDestinationBehavior?: DefaultDestinationBehavior;
122
- cdnHost?: string;
123
- preferencesDialogTemplate?: PreferenceDialogTemplate;
124
- }
125
- export interface ActionsBlockProps {
126
- acceptAll: () => void;
127
- denyAll: () => void;
128
- changePreferences: () => void;
129
- }
130
- export {};