@ht-sdks/consent-manager 0.0.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.
- package/LICENSE +45 -0
- package/README.md +851 -0
- package/commonjs/__tests__/consent-manager-builder/analytics.test.js +250 -0
- package/commonjs/__tests__/consent-manager-builder/fetch-destinations.test.js +155 -0
- package/commonjs/__tests__/consent-manager-builder/index.todo.js +327 -0
- package/commonjs/__tests__/consent-manager-builder/preferences.test.js +129 -0
- package/commonjs/__tests__/index.test.js +57 -0
- package/commonjs/consent-manager/banner.js +89 -0
- package/commonjs/consent-manager/buttons.js +18 -0
- package/commonjs/consent-manager/cancel-dialog.js +76 -0
- package/commonjs/consent-manager/categories.js +29 -0
- package/commonjs/consent-manager/container.js +169 -0
- package/commonjs/consent-manager/dialog.js +129 -0
- package/commonjs/consent-manager/font-styles.js +10 -0
- package/commonjs/consent-manager/index.js +244 -0
- package/commonjs/consent-manager/preference-dialog.js +178 -0
- package/commonjs/consent-manager-builder/analytics.js +76 -0
- package/commonjs/consent-manager-builder/fetch-destinations.js +104 -0
- package/commonjs/consent-manager-builder/index.js +330 -0
- package/commonjs/consent-manager-builder/preferences.js +82 -0
- package/commonjs/index.js +39 -0
- package/commonjs/standalone.js +86 -0
- package/commonjs/types.js +3 -0
- package/esm/__tests__/consent-manager-builder/analytics.test.js +245 -0
- package/esm/__tests__/consent-manager-builder/fetch-destinations.test.js +150 -0
- package/esm/__tests__/consent-manager-builder/index.todo.js +322 -0
- package/esm/__tests__/consent-manager-builder/preferences.test.js +124 -0
- package/esm/__tests__/index.test.js +55 -0
- package/esm/consent-manager/banner.js +65 -0
- package/esm/consent-manager/buttons.js +12 -0
- package/esm/consent-manager/cancel-dialog.js +52 -0
- package/esm/consent-manager/categories.js +26 -0
- package/esm/consent-manager/container.js +162 -0
- package/esm/consent-manager/dialog.js +105 -0
- package/esm/consent-manager/font-styles.js +8 -0
- package/esm/consent-manager/index.js +220 -0
- package/esm/consent-manager/preference-dialog.js +154 -0
- package/esm/consent-manager-builder/analytics.js +73 -0
- package/esm/consent-manager-builder/fetch-destinations.js +98 -0
- package/esm/consent-manager-builder/index.js +325 -0
- package/esm/consent-manager-builder/preferences.js +73 -0
- package/esm/index.js +28 -0
- package/esm/standalone.js +58 -0
- package/esm/types.js +1 -0
- package/package.json +168 -0
- package/src/__tests__/consent-manager-builder/analytics.test.ts +279 -0
- package/src/__tests__/consent-manager-builder/fetch-destinations.test.ts +89 -0
- package/src/__tests__/consent-manager-builder/index.todo.js +386 -0
- package/src/__tests__/consent-manager-builder/preferences.test.ts +156 -0
- package/src/__tests__/index.test.ts +68 -0
- package/src/consent-manager/banner.tsx +227 -0
- package/src/consent-manager/buttons.tsx +78 -0
- package/src/consent-manager/cancel-dialog.tsx +68 -0
- package/src/consent-manager/categories.ts +27 -0
- package/src/consent-manager/container.tsx +282 -0
- package/src/consent-manager/dialog.tsx +236 -0
- package/src/consent-manager/font-styles.tsx +14 -0
- package/src/consent-manager/index.tsx +327 -0
- package/src/consent-manager/preference-dialog.tsx +371 -0
- package/src/consent-manager-builder/analytics.ts +104 -0
- package/src/consent-manager-builder/fetch-destinations.ts +50 -0
- package/src/consent-manager-builder/index.tsx +426 -0
- package/src/consent-manager-builder/preferences.ts +100 -0
- package/src/index.ts +42 -0
- package/src/standalone.tsx +57 -0
- package/src/styled.d.ts +7 -0
- package/src/types.ts +151 -0
- package/standalone/consent-manager.js +23 -0
- package/standalone/consent-manager.js.map +1 -0
- package/types/__tests__/consent-manager-builder/analytics.test.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/index.todo.d.ts +1 -0
- package/types/__tests__/consent-manager-builder/preferences.test.d.ts +1 -0
- package/types/__tests__/index.test.d.ts +1 -0
- package/types/consent-manager/banner.d.ts +21 -0
- package/types/consent-manager/buttons.d.ts +13 -0
- package/types/consent-manager/cancel-dialog.d.ts +19 -0
- package/types/consent-manager/categories.d.ts +3 -0
- package/types/consent-manager/container.d.ts +35 -0
- package/types/consent-manager/dialog.d.ts +29 -0
- package/types/consent-manager/font-styles.d.ts +2 -0
- package/types/consent-manager/index.d.ts +35 -0
- package/types/consent-manager/preference-dialog.d.ts +32 -0
- package/types/consent-manager-builder/analytics.d.ts +14 -0
- package/types/consent-manager-builder/fetch-destinations.d.ts +2 -0
- package/types/consent-manager-builder/index.d.ts +126 -0
- package/types/consent-manager-builder/preferences.d.ts +26 -0
- package/types/index.d.ts +7 -0
- package/types/src/__tests__/consent-manager-builder/analytics.test.d.ts +1 -0
- package/types/src/__tests__/consent-manager-builder/fetch-destinations.test.d.ts +1 -0
- package/types/src/__tests__/consent-manager-builder/preferences.test.d.ts +1 -0
- package/types/src/__tests__/index.test.d.ts +1 -0
- package/types/src/consent-manager/banner.d.ts +21 -0
- package/types/src/consent-manager/buttons.d.ts +13 -0
- package/types/src/consent-manager/cancel-dialog.d.ts +19 -0
- package/types/src/consent-manager/categories.d.ts +3 -0
- package/types/src/consent-manager/container.d.ts +35 -0
- package/types/src/consent-manager/dialog.d.ts +29 -0
- package/types/src/consent-manager/font-styles.d.ts +2 -0
- package/types/src/consent-manager/index.d.ts +35 -0
- package/types/src/consent-manager/preference-dialog.d.ts +32 -0
- package/types/src/consent-manager-builder/analytics.d.ts +14 -0
- package/types/src/consent-manager-builder/fetch-destinations.d.ts +2 -0
- package/types/src/consent-manager-builder/index.d.ts +126 -0
- package/types/src/consent-manager-builder/preferences.d.ts +26 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/standalone.d.ts +5 -0
- package/types/src/types.d.ts +131 -0
- package/types/standalone.d.ts +5 -0
- package/types/types.d.ts +131 -0
package/package.json
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ht-sdks/consent-manager",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Drop-in consent management plugin for Hightouch Events Browser SDK",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gdpr",
|
|
7
|
+
"tracking",
|
|
8
|
+
"events-sdk-js-browser"
|
|
9
|
+
],
|
|
10
|
+
"author": "Hightouch <engineering@hightouch.com>",
|
|
11
|
+
"repository": "https://github.com/ht-sdks/consent-manager",
|
|
12
|
+
"homepage": "https://github.com/ht-sdks/consent-manager",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"main": "commonjs/index.js",
|
|
15
|
+
"module": "esm/index.js",
|
|
16
|
+
"types": "types/index.d.ts",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": [
|
|
19
|
+
"commonjs",
|
|
20
|
+
"esm",
|
|
21
|
+
"standalone",
|
|
22
|
+
"types",
|
|
23
|
+
"src"
|
|
24
|
+
],
|
|
25
|
+
"volta": {
|
|
26
|
+
"node": "16.20.2"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "jest src/__tests__",
|
|
30
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
31
|
+
"postpublish": "npm run build-storybook && npm run deploy-storybook -- --existing-output-dir=storybook-static",
|
|
32
|
+
"dev": "concurrently 'npm run build-standalone --watch' 'npx start-storybook -s ./ -p 9009'",
|
|
33
|
+
"build-commonjs": "tsc --outDir commonjs --module CommonJS --inlineSourceMap",
|
|
34
|
+
"build-esm": "tsc --module es2015 --outDir esm --inlineSourceMap",
|
|
35
|
+
"build-standalone": "webpack",
|
|
36
|
+
"build": "concurrently --names \"commonjs,esm,standalone\" \"npm run build-commonjs\" \"npm run build-esm\" \"npm run build-standalone\"",
|
|
37
|
+
"clean": "rm -rf commonjs esm standalone storybook-static types",
|
|
38
|
+
"standalone-hash": "shasum -b -a 256 standalone/consent-manager.js | xxd -r -p | base64",
|
|
39
|
+
"build-storybook": "npm run build-standalone && build-storybook && cp -r ./standalone ./storybook-static/standalone",
|
|
40
|
+
"deploy-storybook": "storybook-to-ghpages",
|
|
41
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
42
|
+
"size": "size-limit"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@emotion/react": "^11.8.2",
|
|
46
|
+
"@emotion/styled": "^11.8.1",
|
|
47
|
+
"@segment/in-regions": "^1.2.0",
|
|
48
|
+
"@segment/top-domain": "^3.0.0",
|
|
49
|
+
"emotion": "^9.1.2",
|
|
50
|
+
"events": "^3.3.0",
|
|
51
|
+
"isomorphic-fetch": "^3.0.0",
|
|
52
|
+
"js-cookie": "^2.2.0",
|
|
53
|
+
"lodash": "^4.17.21",
|
|
54
|
+
"nanoid": "^1.0.2",
|
|
55
|
+
"prop-types": "^15.6.1",
|
|
56
|
+
"styled-components": "^5.3.5"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@babel/core": "^7.6.2",
|
|
60
|
+
"@segment/in-eu": "^0.3.0",
|
|
61
|
+
"@storybook/addon-actions": "^5.2.3",
|
|
62
|
+
"@storybook/addon-info": "^5.2.3",
|
|
63
|
+
"@storybook/addon-links": "^5.2.3",
|
|
64
|
+
"@storybook/addon-options": "^5.2.3",
|
|
65
|
+
"@storybook/addon-storysource": "^5.2.3",
|
|
66
|
+
"@storybook/addons": "^5.2.3",
|
|
67
|
+
"@storybook/cli": "^5.2.3",
|
|
68
|
+
"@storybook/react": "^5.2.3",
|
|
69
|
+
"@storybook/storybook-deployer": "^2.8.1",
|
|
70
|
+
"@types/enzyme": "^3.10.3",
|
|
71
|
+
"@types/enzyme-adapter-react-16": "^1.0.5",
|
|
72
|
+
"@types/isomorphic-fetch": "^0.0.35",
|
|
73
|
+
"@types/jest": "^24.0.18",
|
|
74
|
+
"@types/js-cookie": "^2.2.2",
|
|
75
|
+
"@types/lodash": "^4.14.186",
|
|
76
|
+
"@types/nanoid": "^2.1.0",
|
|
77
|
+
"@types/nock": "^11.1.0",
|
|
78
|
+
"@types/node": "^12.7.11",
|
|
79
|
+
"@types/react": "^16.9.5",
|
|
80
|
+
"@types/react-dom": "^16.9.1",
|
|
81
|
+
"@types/sinon": "^7.5.0",
|
|
82
|
+
"@types/storybook__react": "^4.0.2",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "^2.3.3",
|
|
84
|
+
"@typescript-eslint/parser": "^2.3.3",
|
|
85
|
+
"babel-loader": "^8.0.6",
|
|
86
|
+
"concurrently": "^8.2.2",
|
|
87
|
+
"enzyme": "^3.10.0",
|
|
88
|
+
"enzyme-adapter-react-16": "^1.1.1",
|
|
89
|
+
"eslint": "^6.5.1",
|
|
90
|
+
"eslint-config-prettier": "^6.4.0",
|
|
91
|
+
"eslint-config-react": "^1.1.7",
|
|
92
|
+
"eslint-plugin-prettier": "^3.1.1",
|
|
93
|
+
"eslint-plugin-react": "^7.16.0",
|
|
94
|
+
"evergreen-ui": "^3.0.0",
|
|
95
|
+
"file-loader": "^4.2.0",
|
|
96
|
+
"husky": "^3.0.8",
|
|
97
|
+
"jest": "^24.9.0",
|
|
98
|
+
"lint-staged": "^7.0.4",
|
|
99
|
+
"nock": "^9.2.5",
|
|
100
|
+
"preact": "^10.0.0",
|
|
101
|
+
"prettier": "^1.19.1",
|
|
102
|
+
"pretty-quick": "^1.11.1",
|
|
103
|
+
"prismjs": "^1.17.1",
|
|
104
|
+
"raw-loader": "^3.1.0",
|
|
105
|
+
"react": "^16.10.2",
|
|
106
|
+
"react-docgen-typescript-loader": "^3.3.0",
|
|
107
|
+
"react-dom": "^16.10.2",
|
|
108
|
+
"react-simple-code-editor": "^0.10.0",
|
|
109
|
+
"react-syntax-highlighter": "^11.0.2",
|
|
110
|
+
"sinon": "^5.0.7",
|
|
111
|
+
"size-limit": "^0.17.0",
|
|
112
|
+
"ts-jest": "^24.1.0",
|
|
113
|
+
"ts-loader": "^6.2.0",
|
|
114
|
+
"ts-node": "^8.4.1",
|
|
115
|
+
"typescript": "^3.7.0-beta",
|
|
116
|
+
"webpack": "^4.8.2",
|
|
117
|
+
"webpack-cli": "^3.1.1"
|
|
118
|
+
},
|
|
119
|
+
"peerDependencies": {
|
|
120
|
+
"react": "^18.1.0",
|
|
121
|
+
"react-dom": "^18.1.0"
|
|
122
|
+
},
|
|
123
|
+
"jest": {
|
|
124
|
+
"preset": "ts-jest/presets/js-with-ts",
|
|
125
|
+
"testEnvironment": "jsdom",
|
|
126
|
+
"setupFiles": [
|
|
127
|
+
"./test/setupTests.ts"
|
|
128
|
+
],
|
|
129
|
+
"transform": {
|
|
130
|
+
"^.+\\.ts?$": "ts-jest"
|
|
131
|
+
},
|
|
132
|
+
"transformIgnorePatterns": [
|
|
133
|
+
"<rootDir>/node_modules/"
|
|
134
|
+
],
|
|
135
|
+
"modulePathIgnorePatterns": [
|
|
136
|
+
"<rootDir>/types/",
|
|
137
|
+
"<rootDir>/commonjs/",
|
|
138
|
+
"<rootDir>/esm/",
|
|
139
|
+
"<rootDir>/standalone/"
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
"size-limit": [
|
|
143
|
+
{
|
|
144
|
+
"path": "esm/index.js",
|
|
145
|
+
"limit": "30 KB"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"path": "standalone/consent-manager.js",
|
|
149
|
+
"limit": "50 KB"
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"husky": {
|
|
153
|
+
"hooks": {
|
|
154
|
+
"pre-commit": "pretty-quick --staged --pattern '**/*.{ts,tsx,js,jsx}'"
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
"prettier": {
|
|
158
|
+
"tabWidth": 2,
|
|
159
|
+
"semi": false,
|
|
160
|
+
"singleQuote": true,
|
|
161
|
+
"printWidth": 100
|
|
162
|
+
},
|
|
163
|
+
"storybook-deployer": {
|
|
164
|
+
"gitUsername": "GitHub Pages Bot",
|
|
165
|
+
"gitEmail": "engineering@hightouch.com",
|
|
166
|
+
"commitMessage": "Deploy Storybook to GitHub Pages [skip ci]"
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import sinon from 'sinon'
|
|
2
|
+
import { WindowWithHtEvents, Destination, Middleware } from '../../types'
|
|
3
|
+
import conditionallyLoadAnalytics from '../../consent-manager-builder/analytics'
|
|
4
|
+
|
|
5
|
+
describe('analytics', () => {
|
|
6
|
+
let wd
|
|
7
|
+
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
window = {} as WindowWithHtEvents
|
|
10
|
+
wd = window
|
|
11
|
+
wd.htevents = {
|
|
12
|
+
/*eslint-disable */
|
|
13
|
+
track: (_event, _properties, _optionsWithConsent, _callback) => {},
|
|
14
|
+
addSourceMiddleware: (_middleware: Middleware) => {}
|
|
15
|
+
/*eslint-enable */
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('loads events.js with preferences', () => {
|
|
20
|
+
const hteventsLoad = sinon.spy()
|
|
21
|
+
wd.htevents.load = hteventsLoad
|
|
22
|
+
const writeKey = '123'
|
|
23
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
24
|
+
const destinationPreferences = {
|
|
25
|
+
Amplitude: true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
conditionallyLoadAnalytics({
|
|
29
|
+
writeKey,
|
|
30
|
+
destinations,
|
|
31
|
+
destinationPreferences,
|
|
32
|
+
isConsentRequired: true,
|
|
33
|
+
categoryPreferences: {}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
expect(hteventsLoad.calledOnce).toBe(true)
|
|
37
|
+
expect(hteventsLoad.args[0][0]).toBe(writeKey)
|
|
38
|
+
expect(hteventsLoad.args[0][1]).toMatchObject({
|
|
39
|
+
integrations: {
|
|
40
|
+
All: false,
|
|
41
|
+
Amplitude: true,
|
|
42
|
+
'Hightouch.io': true
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('doesn՚t load events.js when there are no preferences', () => {
|
|
48
|
+
const hteventsLoad = sinon.spy()
|
|
49
|
+
wd.htevents.load = hteventsLoad
|
|
50
|
+
const writeKey = '123'
|
|
51
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
52
|
+
const destinationPreferences = null
|
|
53
|
+
|
|
54
|
+
conditionallyLoadAnalytics({
|
|
55
|
+
writeKey,
|
|
56
|
+
destinations,
|
|
57
|
+
destinationPreferences,
|
|
58
|
+
isConsentRequired: true,
|
|
59
|
+
categoryPreferences: {}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
expect(hteventsLoad.notCalled).toBe(true)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('doesn՚t load events.js when all preferences are false', () => {
|
|
66
|
+
const hteventsLoad = sinon.spy()
|
|
67
|
+
wd.htevents.load = hteventsLoad
|
|
68
|
+
const writeKey = '123'
|
|
69
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
70
|
+
const destinationPreferences = {
|
|
71
|
+
Amplitude: false
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
conditionallyLoadAnalytics({
|
|
75
|
+
writeKey,
|
|
76
|
+
destinations,
|
|
77
|
+
destinationPreferences,
|
|
78
|
+
isConsentRequired: true,
|
|
79
|
+
categoryPreferences: {}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
expect(hteventsLoad.notCalled).toBe(true)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('reloads the page when events.js has already been initialised', () => {
|
|
86
|
+
wd.htevents.load = function load() {
|
|
87
|
+
this.initialized = true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
jest.spyOn(window.location, 'reload')
|
|
91
|
+
|
|
92
|
+
const writeKey = '123'
|
|
93
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
94
|
+
const destinationPreferences = {
|
|
95
|
+
Amplitude: true
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
conditionallyLoadAnalytics({
|
|
99
|
+
writeKey,
|
|
100
|
+
destinations,
|
|
101
|
+
destinationPreferences,
|
|
102
|
+
isConsentRequired: true,
|
|
103
|
+
categoryPreferences: {}
|
|
104
|
+
})
|
|
105
|
+
conditionallyLoadAnalytics({
|
|
106
|
+
writeKey,
|
|
107
|
+
destinations,
|
|
108
|
+
destinationPreferences,
|
|
109
|
+
isConsentRequired: true,
|
|
110
|
+
categoryPreferences: {}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
expect(window.location.reload).toHaveBeenCalled()
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('should allow the reload behvaiour to be disabled', () => {
|
|
117
|
+
const reload = sinon.spy()
|
|
118
|
+
wd.htevents.load = function load() {
|
|
119
|
+
this.initialized = true
|
|
120
|
+
}
|
|
121
|
+
wd.location = { reload }
|
|
122
|
+
const writeKey = '123'
|
|
123
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
124
|
+
const destinationPreferences = {
|
|
125
|
+
Amplitude: true
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
conditionallyLoadAnalytics({
|
|
129
|
+
writeKey,
|
|
130
|
+
destinations,
|
|
131
|
+
destinationPreferences,
|
|
132
|
+
isConsentRequired: true,
|
|
133
|
+
categoryPreferences: {}
|
|
134
|
+
})
|
|
135
|
+
conditionallyLoadAnalytics({
|
|
136
|
+
writeKey,
|
|
137
|
+
destinations,
|
|
138
|
+
destinationPreferences,
|
|
139
|
+
isConsentRequired: true,
|
|
140
|
+
shouldReload: false,
|
|
141
|
+
categoryPreferences: {}
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
expect(reload.calledOnce).toBe(false)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test('loads events.js normally when consent isn՚t required', () => {
|
|
148
|
+
const hteventsLoad = sinon.spy()
|
|
149
|
+
wd.htevents.load = hteventsLoad
|
|
150
|
+
const writeKey = '123'
|
|
151
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
152
|
+
const destinationPreferences = null
|
|
153
|
+
|
|
154
|
+
conditionallyLoadAnalytics({
|
|
155
|
+
writeKey,
|
|
156
|
+
destinations,
|
|
157
|
+
destinationPreferences,
|
|
158
|
+
isConsentRequired: false,
|
|
159
|
+
categoryPreferences: {}
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
expect(hteventsLoad.calledOnce).toBe(true)
|
|
163
|
+
expect(hteventsLoad.args[0][0]).toBe(writeKey)
|
|
164
|
+
expect(hteventsLoad.args[0][1]).toBeUndefined()
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('still applies preferences when consent isn՚t required', () => {
|
|
168
|
+
const hteventsLoad = sinon.spy()
|
|
169
|
+
wd.htevents.load = hteventsLoad
|
|
170
|
+
const writeKey = '123'
|
|
171
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
172
|
+
const destinationPreferences = {
|
|
173
|
+
Amplitude: true
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
conditionallyLoadAnalytics({
|
|
177
|
+
writeKey,
|
|
178
|
+
destinations,
|
|
179
|
+
destinationPreferences,
|
|
180
|
+
isConsentRequired: false,
|
|
181
|
+
categoryPreferences: {}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
expect(hteventsLoad.calledOnce).toBe(true)
|
|
185
|
+
expect(hteventsLoad.args[0][0]).toBe(writeKey)
|
|
186
|
+
expect(hteventsLoad.args[0][1]).toMatchObject({
|
|
187
|
+
integrations: {
|
|
188
|
+
All: false,
|
|
189
|
+
Amplitude: true,
|
|
190
|
+
'Hightouch.io': true
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
test('sets new destinations to false if defaultDestinationBehavior is set to "disable"', () => {
|
|
196
|
+
const hteventsLoad = sinon.spy()
|
|
197
|
+
wd.htevents.load = hteventsLoad
|
|
198
|
+
const writeKey = '123'
|
|
199
|
+
const destinations = [
|
|
200
|
+
{ id: 'Amplitude' } as Destination,
|
|
201
|
+
{ id: 'Google Analytics' } as Destination
|
|
202
|
+
]
|
|
203
|
+
const destinationPreferences = {
|
|
204
|
+
Amplitude: true
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
conditionallyLoadAnalytics({
|
|
208
|
+
writeKey,
|
|
209
|
+
destinations,
|
|
210
|
+
destinationPreferences,
|
|
211
|
+
isConsentRequired: false,
|
|
212
|
+
shouldReload: true,
|
|
213
|
+
defaultDestinationBehavior: 'disable',
|
|
214
|
+
categoryPreferences: {}
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
expect(hteventsLoad.args[0][1]).toMatchObject({
|
|
218
|
+
integrations: {
|
|
219
|
+
All: false,
|
|
220
|
+
Amplitude: true,
|
|
221
|
+
'Google Analytics': false,
|
|
222
|
+
'Hightouch.io': true
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
test('sets new destinations to true if defaultDestinationBehavior is set to "enable"', () => {
|
|
228
|
+
const hteventsLoad = sinon.spy()
|
|
229
|
+
wd.htevents.load = hteventsLoad
|
|
230
|
+
const writeKey = '123'
|
|
231
|
+
const destinations = [
|
|
232
|
+
{ id: 'Amplitude' } as Destination,
|
|
233
|
+
{ id: 'Google Analytics' } as Destination
|
|
234
|
+
]
|
|
235
|
+
const destinationPreferences = {
|
|
236
|
+
Amplitude: true
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
conditionallyLoadAnalytics({
|
|
240
|
+
writeKey,
|
|
241
|
+
destinations,
|
|
242
|
+
destinationPreferences,
|
|
243
|
+
isConsentRequired: false,
|
|
244
|
+
shouldReload: true,
|
|
245
|
+
defaultDestinationBehavior: 'enable',
|
|
246
|
+
categoryPreferences: {}
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
expect(hteventsLoad.args[0][1]).toMatchObject({
|
|
250
|
+
integrations: {
|
|
251
|
+
All: false,
|
|
252
|
+
Amplitude: true,
|
|
253
|
+
'Google Analytics': true,
|
|
254
|
+
'Hightouch.io': true
|
|
255
|
+
}
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
test('Set devMode on true to disabled events.js load', () => {
|
|
260
|
+
const hteventsLoad = sinon.spy()
|
|
261
|
+
wd.htevents.load = hteventsLoad
|
|
262
|
+
const writeKey = '123'
|
|
263
|
+
const destinations = [{ id: 'Amplitude' } as Destination]
|
|
264
|
+
const destinationPreferences = {
|
|
265
|
+
Amplitude: true
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
conditionallyLoadAnalytics({
|
|
269
|
+
writeKey,
|
|
270
|
+
destinations,
|
|
271
|
+
destinationPreferences,
|
|
272
|
+
isConsentRequired: false,
|
|
273
|
+
categoryPreferences: {},
|
|
274
|
+
devMode: true
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
expect(hteventsLoad.calledOnce).toBe(false)
|
|
278
|
+
})
|
|
279
|
+
})
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import nock from 'nock'
|
|
2
|
+
import fetchDestinations from '../../consent-manager-builder/fetch-destinations'
|
|
3
|
+
|
|
4
|
+
describe('fetchDestinations', () => {
|
|
5
|
+
test('Returns destinations for a writekey', async () => {
|
|
6
|
+
nock('https://cdn.hightouch-events.com')
|
|
7
|
+
.get('/v1/projects/123/integrations')
|
|
8
|
+
.reply(200, [
|
|
9
|
+
{
|
|
10
|
+
name: 'Google Analytics',
|
|
11
|
+
creationName: 'Google Analytics'
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: 'Amplitude',
|
|
15
|
+
creationName: 'Amplitude'
|
|
16
|
+
}
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
expect(await fetchDestinations('cdn.hightouch-events.com', ['123'])).toMatchObject([
|
|
20
|
+
{
|
|
21
|
+
id: 'Amplitude',
|
|
22
|
+
name: 'Amplitude'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'Google Analytics',
|
|
26
|
+
name: 'Google Analytics'
|
|
27
|
+
}
|
|
28
|
+
])
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('Renames creationName to id', async () => {
|
|
32
|
+
nock('https://cdn.hightouch-events.com')
|
|
33
|
+
.get('/v1/projects/123/integrations')
|
|
34
|
+
.reply(200, [
|
|
35
|
+
{
|
|
36
|
+
name: 'New Amplitude',
|
|
37
|
+
creationName: 'Old Amplitude'
|
|
38
|
+
}
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
expect(await fetchDestinations('cdn.hightouch-events.com', ['123'])).toMatchObject([
|
|
42
|
+
{
|
|
43
|
+
id: 'Old Amplitude',
|
|
44
|
+
name: 'New Amplitude'
|
|
45
|
+
}
|
|
46
|
+
])
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('Doesn՚t include duplicate destinations', async () => {
|
|
50
|
+
nock('https://cdn.hightouch-events.com')
|
|
51
|
+
.get('/v1/projects/123/integrations')
|
|
52
|
+
.reply(200, [
|
|
53
|
+
{
|
|
54
|
+
name: 'Google Analytics',
|
|
55
|
+
creationName: 'Google Analytics'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'Amplitude',
|
|
59
|
+
creationName: 'Amplitude'
|
|
60
|
+
}
|
|
61
|
+
])
|
|
62
|
+
.get('/v1/projects/abc/integrations')
|
|
63
|
+
.reply(200, [
|
|
64
|
+
{
|
|
65
|
+
name: 'Google Analytics',
|
|
66
|
+
creationName: 'Google Analytics'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'FullStory',
|
|
70
|
+
creationName: 'FullStory'
|
|
71
|
+
}
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
expect(await fetchDestinations('cdn.hightouch-events.com', ['123', 'abc'])).toMatchObject([
|
|
75
|
+
{
|
|
76
|
+
id: 'Amplitude',
|
|
77
|
+
name: 'Amplitude'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: 'FullStory',
|
|
81
|
+
name: 'FullStory'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'Google Analytics',
|
|
85
|
+
name: 'Google Analytics'
|
|
86
|
+
}
|
|
87
|
+
])
|
|
88
|
+
})
|
|
89
|
+
})
|