@ht-sdks/consent-manager 0.1.0 → 0.2.0
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.
- package/commonjs/__tests__/consent-manager/dialog.test.js +33 -0
- package/commonjs/__tests__/consent-manager-builder/analytics.test.js +53 -46
- package/commonjs/__tests__/consent-manager-builder/index.todo.js +48 -87
- package/commonjs/__tests__/consent-manager-builder/preferences.test.js +34 -27
- package/commonjs/__tests__/index.test.js +12 -12
- package/commonjs/consent-manager/banner.js +35 -19
- package/commonjs/consent-manager/buttons.js +5 -5
- package/commonjs/consent-manager/cancel-dialog.js +26 -10
- package/commonjs/consent-manager/categories.js +2 -2
- package/commonjs/consent-manager/container.js +2 -3
- package/commonjs/consent-manager/dialog.js +39 -23
- package/commonjs/consent-manager/font-styles.js +2 -2
- package/commonjs/consent-manager/index.js +41 -25
- package/commonjs/consent-manager/preference-dialog.js +36 -20
- package/commonjs/consent-manager-builder/analytics.js +3 -5
- package/commonjs/consent-manager-builder/index.js +30 -30
- package/commonjs/consent-manager-builder/preferences.js +22 -16
- package/commonjs/index.js +5 -4
- package/commonjs/standalone.js +25 -11
- package/esm/__tests__/consent-manager/dialog.test.js +28 -0
- package/esm/__tests__/consent-manager-builder/analytics.test.js +41 -34
- package/esm/__tests__/consent-manager-builder/index.todo.js +34 -73
- package/esm/__tests__/consent-manager-builder/preferences.test.js +30 -23
- package/esm/consent-manager/banner.js +5 -3
- package/esm/consent-manager/buttons.js +4 -4
- package/esm/consent-manager/cancel-dialog.js +4 -2
- package/esm/consent-manager/categories.js +2 -2
- package/esm/consent-manager/container.js +1 -1
- package/esm/consent-manager/dialog.js +7 -5
- package/esm/consent-manager/font-styles.js +2 -2
- package/esm/consent-manager/index.js +19 -17
- package/esm/consent-manager/preference-dialog.js +7 -5
- package/esm/consent-manager-builder/analytics.js +2 -4
- package/esm/consent-manager-builder/index.js +26 -26
- package/esm/consent-manager-builder/preferences.js +17 -11
- package/esm/index.js +4 -3
- package/esm/standalone.js +3 -3
- package/esm/types.js +1 -0
- package/package.json +62 -67
- package/src/__tests__/consent-manager/dialog.test.tsx +42 -0
- package/src/__tests__/consent-manager-builder/analytics.test.ts +40 -33
- package/src/__tests__/consent-manager-builder/index.todo.js +52 -95
- package/src/__tests__/consent-manager-builder/preferences.test.ts +31 -21
- package/src/consent-manager/banner.tsx +11 -11
- package/src/consent-manager/buttons.tsx +26 -10
- package/src/consent-manager/cancel-dialog.tsx +1 -1
- package/src/consent-manager/categories.ts +2 -2
- package/src/consent-manager/container.tsx +14 -17
- package/src/consent-manager/dialog.tsx +4 -4
- package/src/consent-manager/font-styles.tsx +12 -2
- package/src/consent-manager/index.tsx +27 -29
- package/src/consent-manager/preference-dialog.tsx +13 -11
- package/src/consent-manager-builder/analytics.ts +5 -5
- package/src/consent-manager-builder/index.tsx +28 -28
- package/src/consent-manager-builder/preferences.ts +20 -14
- package/src/index.ts +8 -4
- package/src/standalone.tsx +1 -1
- package/src/types.ts +8 -2
- package/standalone/consent-manager.js +5 -10
- package/standalone/consent-manager.js.map +1 -1
- package/types/consent-manager/banner.d.ts +1 -1
- package/types/consent-manager/buttons.d.ts +6 -7
- package/types/consent-manager/cancel-dialog.d.ts +1 -1
- package/types/consent-manager/index.d.ts +3 -3
- package/types/consent-manager/preference-dialog.d.ts +1 -1
- package/types/consent-manager-builder/analytics.d.ts +1 -1
- package/types/consent-manager-builder/index.d.ts +7 -8
- package/types/consent-manager-builder/preferences.d.ts +4 -6
- package/types/index.d.ts +1 -1
- package/types/types.d.ts +14 -10
- package/commonjs/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -155
- package/commonjs/consent-manager-builder/fetch-destinations.js +0 -104
- package/esm/__tests__/consent-manager-builder/fetch-destinations.test.js +0 -150
- package/esm/consent-manager-builder/fetch-destinations.js +0 -98
- package/src/__tests__/consent-manager-builder/fetch-destinations.test.ts +0 -89
- package/src/consent-manager-builder/fetch-destinations.ts +0 -50
- package/types/consent-manager-builder/fetch-destinations.d.ts +0 -2
- package/types/src/__tests__/consent-manager-builder/analytics.test.d.ts +0 -1
- package/types/src/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +0 -1
- package/types/src/__tests__/consent-manager-builder/preferences.test.d.ts +0 -1
- package/types/src/__tests__/index.test.d.ts +0 -1
- package/types/src/consent-manager/banner.d.ts +0 -21
- package/types/src/consent-manager/buttons.d.ts +0 -13
- package/types/src/consent-manager/cancel-dialog.d.ts +0 -19
- package/types/src/consent-manager/categories.d.ts +0 -3
- package/types/src/consent-manager/container.d.ts +0 -35
- package/types/src/consent-manager/dialog.d.ts +0 -29
- package/types/src/consent-manager/font-styles.d.ts +0 -2
- package/types/src/consent-manager/index.d.ts +0 -35
- package/types/src/consent-manager/preference-dialog.d.ts +0 -32
- package/types/src/consent-manager-builder/analytics.d.ts +0 -14
- package/types/src/consent-manager-builder/fetch-destinations.d.ts +0 -2
- package/types/src/consent-manager-builder/index.d.ts +0 -126
- package/types/src/consent-manager-builder/preferences.d.ts +0 -26
- package/types/src/index.d.ts +0 -7
- package/types/src/standalone.d.ts +0 -5
- package/types/src/types.d.ts +0 -130
- /package/types/__tests__/{consent-manager-builder/fetch-destinations.test.d.ts → consent-manager/dialog.test.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// TODO: remove duplicate cookie library from bundle
|
|
2
|
-
import cookies
|
|
2
|
+
import cookies from 'js-cookie'
|
|
3
3
|
import topDomain from '@segment/top-domain'
|
|
4
|
-
import { WindowWithHtEvents, Preferences, CategoryPreferences } from '../types'
|
|
4
|
+
import { WindowWithHtEvents, Preferences, CategoryPreferences, CookieAttributes } from '../types'
|
|
5
5
|
import { EventEmitter } from 'events'
|
|
6
6
|
|
|
7
7
|
export const DEFAULT_COOKIE_NAME = 'ht-cm-preferences'
|
|
@@ -22,15 +22,21 @@ export interface PreferencesManager {
|
|
|
22
22
|
// TODO: harden against invalid cookies
|
|
23
23
|
// TODO: harden against different versions of cookies
|
|
24
24
|
export function loadPreferences(cookieName?: string): Preferences {
|
|
25
|
-
const
|
|
25
|
+
const raw = cookies.get(cookieName || DEFAULT_COOKIE_NAME)
|
|
26
|
+
if (!raw) {
|
|
27
|
+
return {}
|
|
28
|
+
}
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
let preferences: PreferencesCookie
|
|
31
|
+
try {
|
|
32
|
+
preferences = JSON.parse(raw) as PreferencesCookie
|
|
33
|
+
} catch {
|
|
28
34
|
return {}
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
return {
|
|
32
38
|
destinationPreferences: preferences.destination,
|
|
33
|
-
customPreferences: preferences.custom
|
|
39
|
+
customPreferences: preferences.custom,
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
42
|
|
|
@@ -60,7 +66,7 @@ export function savePreferences({
|
|
|
60
66
|
cookieDomain,
|
|
61
67
|
cookieName,
|
|
62
68
|
cookieExpires,
|
|
63
|
-
cookieAttributes = {}
|
|
69
|
+
cookieAttributes = {},
|
|
64
70
|
}: SavePreferences) {
|
|
65
71
|
const wd = window as WindowWithHtEvents
|
|
66
72
|
if (wd.htevents) {
|
|
@@ -69,15 +75,15 @@ export function savePreferences({
|
|
|
69
75
|
{
|
|
70
76
|
destinationPreferences,
|
|
71
77
|
// use `categoryPreferences` here for consistency with `context.consent.categoryPreferences`
|
|
72
|
-
categoryPreferences: customPreferences
|
|
78
|
+
categoryPreferences: customPreferences,
|
|
73
79
|
},
|
|
74
80
|
{
|
|
75
81
|
// update `context.consent` here to immediately reflect the updated preferences
|
|
76
82
|
consent: {
|
|
77
83
|
destinationPreferences,
|
|
78
|
-
categoryPreferences: customPreferences
|
|
79
|
-
}
|
|
80
|
-
}
|
|
84
|
+
categoryPreferences: customPreferences,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
81
87
|
)
|
|
82
88
|
} else {
|
|
83
89
|
console.warn('window.htevents not found...is the SDK snippet included on the page?')
|
|
@@ -88,17 +94,17 @@ export function savePreferences({
|
|
|
88
94
|
const value = {
|
|
89
95
|
version: 1,
|
|
90
96
|
destination: destinationPreferences,
|
|
91
|
-
custom: customPreferences
|
|
97
|
+
custom: customPreferences,
|
|
92
98
|
} as PreferencesCookie
|
|
93
99
|
|
|
94
|
-
cookies.set(cookieName || DEFAULT_COOKIE_NAME, value, {
|
|
100
|
+
cookies.set(cookieName || DEFAULT_COOKIE_NAME, JSON.stringify(value), {
|
|
95
101
|
expires,
|
|
96
102
|
domain,
|
|
97
|
-
...cookieAttributes
|
|
103
|
+
...cookieAttributes,
|
|
98
104
|
})
|
|
99
105
|
|
|
100
106
|
emitter.emit('preferencesSaved', {
|
|
101
107
|
destinationPreferences,
|
|
102
|
-
customPreferences
|
|
108
|
+
customPreferences,
|
|
103
109
|
})
|
|
104
110
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { openDialog as openConsentManager } from './consent-manager/container'
|
|
|
5
5
|
export {
|
|
6
6
|
loadPreferences,
|
|
7
7
|
savePreferences,
|
|
8
|
-
onPreferencesSaved
|
|
8
|
+
onPreferencesSaved,
|
|
9
9
|
} from './consent-manager-builder/preferences'
|
|
10
10
|
|
|
11
11
|
export const ConsentManagerBuilder = CMB
|
|
@@ -15,12 +15,16 @@ type Nav = Navigator & {
|
|
|
15
15
|
msDoNotTrack?: Navigator['doNotTrack']
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
type WindowWithDoNotTrack = Window & {
|
|
19
|
+
doNotTrack?: Navigator['doNotTrack']
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
export function doNotTrack(): boolean | null {
|
|
19
|
-
|
|
20
|
-
if (typeof window !== 'undefined' && (window.navigator || navigator)) {
|
|
23
|
+
if (typeof window !== 'undefined' && (window.navigator || navigator)) {
|
|
21
24
|
const nav = navigator as Nav
|
|
25
|
+
const win = window as WindowWithDoNotTrack
|
|
22
26
|
|
|
23
|
-
let doNotTrackValue = nav.doNotTrack ||
|
|
27
|
+
let doNotTrackValue = nav.doNotTrack || win.doNotTrack || nav.msDoNotTrack
|
|
24
28
|
|
|
25
29
|
// Normalise Firefox < 32
|
|
26
30
|
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/doNotTrack
|
package/src/standalone.tsx
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CloseBehaviorFunction } from './consent-manager/container'
|
|
2
2
|
import { PreferencesManager } from './consent-manager-builder/preferences'
|
|
3
|
-
import
|
|
3
|
+
import Cookies from 'js-cookie'
|
|
4
|
+
|
|
5
|
+
export type CookieAttributes = NonNullable<Parameters<typeof Cookies.set>[2]>
|
|
4
6
|
|
|
5
7
|
export type HtEventsBrowserOptions = {
|
|
6
8
|
integrations?: Record<string, boolean>
|
|
@@ -33,7 +35,7 @@ export type WindowWithHtEvents = Window &
|
|
|
33
35
|
export type WindowWithConsentManagerConfig = Window &
|
|
34
36
|
typeof globalThis & {
|
|
35
37
|
consentManagerConfig?: (
|
|
36
|
-
args: StandaloneConsentManagerParams
|
|
38
|
+
args: StandaloneConsentManagerParams,
|
|
37
39
|
) => ConsentManagerInput | ConsentManagerInput
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -139,6 +141,10 @@ export interface ConsentManagerProps {
|
|
|
139
141
|
initialPreferences?: CategoryPreferences
|
|
140
142
|
customCategories?: CustomCategories
|
|
141
143
|
defaultDestinationBehavior?: DefaultDestinationBehavior
|
|
144
|
+
/**
|
|
145
|
+
* Accepted for backward compatibility. Destinations are not fetched from the CDN,
|
|
146
|
+
* so this value is unused.
|
|
147
|
+
*/
|
|
142
148
|
cdnHost?: string
|
|
143
149
|
preferencesDialogTemplate?: PreferenceDialogTemplate
|
|
144
150
|
}
|