@everymatrix/user-action-controller 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/dist/cjs/generic-user-consent_3.cjs.entry.js +182 -0
- package/dist/cjs/index-4a3038bd.js +1255 -0
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/loader.cjs.js +21 -0
- package/dist/cjs/user-action-controller.cjs.js +19 -0
- package/dist/collection/collection-manifest.json +25 -0
- package/dist/collection/components/user-action-controller/user-action-controller.css +48 -0
- package/dist/collection/components/user-action-controller/user-action-controller.js +237 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/utils/utils.js +3 -0
- package/dist/components/generic-user-consent.js +6 -0
- package/dist/components/generic-user-consent2.js +93 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/components/index.js +1 -0
- package/dist/components/legislation-wrapper.js +6 -0
- package/dist/components/legislation-wrapper2.js +33 -0
- package/dist/components/user-action-controller.d.ts +11 -0
- package/dist/components/user-action-controller.js +137 -0
- package/dist/esm/generic-user-consent_3.entry.js +176 -0
- package/dist/esm/index-9eef5ef8.js +1229 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +17 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/esm/user-action-controller.js +17 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/stencil.config.js +22 -0
- package/dist/types/Users/user/workspace/everymatrix/widgets-stencil/packages/user-action-controller/.stencil/packages/user-action-controller/stencil.config.d.ts +2 -0
- package/dist/types/components/user-action-controller/user-action-controller.d.ts +55 -0
- package/dist/types/components.d.ts +93 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1565 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/user-action-controller/index.esm.js +0 -0
- package/dist/user-action-controller/p-013051ff.entry.js +1 -0
- package/dist/user-action-controller/p-54386d36.js +1 -0
- package/dist/user-action-controller/user-action-controller.esm.js +1 -0
- package/loader/cdn.js +3 -0
- package/loader/index.cjs.js +3 -0
- package/loader/index.d.ts +12 -0
- package/loader/index.es2017.js +3 -0
- package/loader/index.js +4 -0
- package/loader/package.json +10 -0
- package/package.json +19 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const index = require('./index-4a3038bd.js');
|
|
6
|
+
|
|
7
|
+
const genericUserConsentCss = ":host{display:block}.ConsentTitle{margin-bottom:0.2rem;font-weight:600}.userConsent:hover{border-bottom:1px solid #000;cursor:pointer}.MandatoryItem{color:#f00;font-size:1.2rem}";
|
|
8
|
+
|
|
9
|
+
const GenericUserConsent = class {
|
|
10
|
+
constructor(hostRef) {
|
|
11
|
+
index.registerInstance(this, hostRef);
|
|
12
|
+
this.userLegislationConsent = index.createEvent(this, "userLegislationConsent", 7);
|
|
13
|
+
/**
|
|
14
|
+
* 'true' when parent expects component to emit it's current value
|
|
15
|
+
*/
|
|
16
|
+
this.queried = false;
|
|
17
|
+
/**
|
|
18
|
+
* the type of the consent, used to determine render details
|
|
19
|
+
*/
|
|
20
|
+
this.consentType = '';
|
|
21
|
+
/**
|
|
22
|
+
* wether or not this consent is mandatory. Used for render details
|
|
23
|
+
*/
|
|
24
|
+
this.mandatory = false;
|
|
25
|
+
/**
|
|
26
|
+
* the title of the consent to be displayed
|
|
27
|
+
*/
|
|
28
|
+
this.consentTitle = '';
|
|
29
|
+
/**
|
|
30
|
+
* link to the t&c page
|
|
31
|
+
*/
|
|
32
|
+
this.tcLink = '#';
|
|
33
|
+
/**
|
|
34
|
+
* link to privacy policy page
|
|
35
|
+
*/
|
|
36
|
+
this.privacyLink = '#';
|
|
37
|
+
/**
|
|
38
|
+
* the text content to be rendered by the component. Determined at runtime
|
|
39
|
+
*/
|
|
40
|
+
this.textContent = '';
|
|
41
|
+
// Maybe switch this out with a localization source
|
|
42
|
+
this.stringVariants = {
|
|
43
|
+
termsandconditions1: "I accept the ",
|
|
44
|
+
termsandconditions2: ", I have read and understood the ",
|
|
45
|
+
termsandconditions3: " as published on this site and confirm that I am over 18 years old.",
|
|
46
|
+
tc: "Terms and Conditions",
|
|
47
|
+
privacy: "Privacy Policy",
|
|
48
|
+
sms: "I consent to receive marketing communication via SMS.",
|
|
49
|
+
emailmarketing: "I consent to receive marketing communication via Email."
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
determineTextContent() {
|
|
53
|
+
let result = this.consentType === 'termsandconditions' ?
|
|
54
|
+
index.h("span", null, this.stringVariants['termsandconditions1'], index.h("a", { href: this.tcLink }, this.stringVariants['tc']), this.stringVariants['termsandconditions2'], index.h("a", { href: this.privacyLink }, this.stringVariants['privacy']), this.stringVariants['termsandconditions3'])
|
|
55
|
+
: index.h("span", null, this.stringVariants[this.consentType]);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
userLegislationConsentHandler() {
|
|
59
|
+
this.userLegislationConsent.emit({
|
|
60
|
+
type: this.consentType,
|
|
61
|
+
value: this.checkboxInput.checked
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
render() {
|
|
65
|
+
if (this.queried) {
|
|
66
|
+
this.userLegislationConsentHandler();
|
|
67
|
+
}
|
|
68
|
+
this.textContent = this.determineTextContent();
|
|
69
|
+
return (index.h("div", null, index.h("p", { class: "ConsentTitle" }, this.consentTitle), index.h("label", { class: "userConsent", htmlFor: "userConsent" }, index.h("input", { ref: el => this.checkboxInput = el, id: "userConsent", type: "checkbox", onInput: () => this.userLegislationConsentHandler() }), this.textContent, this.mandatory && index.h("span", { class: "MandatoryItem" }, "*"))));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
GenericUserConsent.style = genericUserConsentCss;
|
|
73
|
+
|
|
74
|
+
const legislationWrapperCss = ":host{display:block}";
|
|
75
|
+
|
|
76
|
+
const LegislationWrapper = class {
|
|
77
|
+
constructor(hostRef) {
|
|
78
|
+
index.registerInstance(this, hostRef);
|
|
79
|
+
}
|
|
80
|
+
render() {
|
|
81
|
+
const activeUAList = this.activeUserActions.replace(/ /g, '').split(',');
|
|
82
|
+
return (index.h("div", { class: "LegislationWrapper" }, activeUAList.map(action => (index.h("slot", { name: action })))));
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
LegislationWrapper.style = legislationWrapperCss;
|
|
86
|
+
|
|
87
|
+
const userActionControllerCss = ":host{display:block}.QueryReferenceContainer{height:100%;width:100%}.UserConsentNotice{font-size:1.2rem;font-weight:200;text-align:center}.UserActionController{font-family:Arial, Helvetica, sans-serif;font-weight:100;height:100%;width:100%;padding:1rem 1.5rem 2rem;background-color:#fff;display:flex;flex-direction:column;justify-content:space-between;border-radius:5%}.ConsentSubmitButton{font-size:1rem;padding:0.4rem 1.4rem;background:#fff;border:2px solid #000;color:#000;border-radius:5px;align-self:flex-end}.ConsentSubmitButton:disabled{border:2px solid #ccc;color:#ccc}@media screen and (max-width: 320px){.QueryReferenceContainer{font-size:0.8rem;color:blue}}";
|
|
88
|
+
|
|
89
|
+
const UserActionController = class {
|
|
90
|
+
constructor(hostRef) {
|
|
91
|
+
index.registerInstance(this, hostRef);
|
|
92
|
+
this.consentTitles = {
|
|
93
|
+
termsandconditions: "Terms and Conditions",
|
|
94
|
+
sms: "SMS marketing",
|
|
95
|
+
emailmarketing: "Email marketing"
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Which actions are required in order to activate the "Apply" button. Other actions are considered optional.
|
|
99
|
+
*/
|
|
100
|
+
this.queryFired = false;
|
|
101
|
+
this.readyActionsCount = 0;
|
|
102
|
+
this.receivedQueryResponses = 0;
|
|
103
|
+
this.mandatoryActions = ['termsandconditions'];
|
|
104
|
+
this.requiredActionsCount = 0;
|
|
105
|
+
this.expectedQueryResponses = 0;
|
|
106
|
+
this.userActions = [];
|
|
107
|
+
}
|
|
108
|
+
determineMandatoryActions() {
|
|
109
|
+
let url = new URL(`${this.endpoint}v1/player/consentRequirements`);
|
|
110
|
+
return fetch(url.href)
|
|
111
|
+
.then(res => res.json())
|
|
112
|
+
.then(data => {
|
|
113
|
+
data.items.forEach(action => {
|
|
114
|
+
action.mustAccept && this.mandatoryActions.push(action.tagCode);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
handleQueryResponse() {
|
|
119
|
+
if (this.receivedQueryResponses === this.expectedQueryResponses) {
|
|
120
|
+
this.updateUserConsents();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
updateUserConsents() {
|
|
124
|
+
const url = new URL(`${this.endpoint}v1/player/${this.userId}/consent`);
|
|
125
|
+
let body = {
|
|
126
|
+
items: this.userActions
|
|
127
|
+
};
|
|
128
|
+
let options = {
|
|
129
|
+
method: 'POST',
|
|
130
|
+
headers: {
|
|
131
|
+
'Content-Type': 'application/json',
|
|
132
|
+
'Accept': 'application/json',
|
|
133
|
+
'X-SessionId': `${this.userSession}`,
|
|
134
|
+
},
|
|
135
|
+
body: JSON.stringify(body)
|
|
136
|
+
};
|
|
137
|
+
fetch(url.href, options)
|
|
138
|
+
.then(res => res.json())
|
|
139
|
+
// .then(data => {
|
|
140
|
+
// console.log(data);
|
|
141
|
+
// })
|
|
142
|
+
.finally(() => {
|
|
143
|
+
window.postMessage({ type: "UserActionsCompleted" }, window.location.href);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
handleApplyClick() {
|
|
147
|
+
this.queryFired = true;
|
|
148
|
+
}
|
|
149
|
+
userLegislationConsentHandler(event) {
|
|
150
|
+
// Increase / Decrease the amount of mandatory actions taken
|
|
151
|
+
if (this.mandatoryActions.includes(event.detail.type)) {
|
|
152
|
+
if (event.detail.value)
|
|
153
|
+
this.readyActionsCount++;
|
|
154
|
+
else
|
|
155
|
+
this.readyActionsCount--;
|
|
156
|
+
}
|
|
157
|
+
// Register final user choices only if we're ready to update
|
|
158
|
+
if (this.queryFired) {
|
|
159
|
+
this.userActions.push({ tagCode: event.detail.type, status: event.detail.value ? 'Accepted' : 'Denied' });
|
|
160
|
+
this.receivedQueryResponses++;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Returning a promise here will ensure that the fetch completes before we render the component
|
|
164
|
+
componentWillLoad() {
|
|
165
|
+
return this.determineMandatoryActions();
|
|
166
|
+
}
|
|
167
|
+
render() {
|
|
168
|
+
const activeUAList = this.activeUserActions.replace(/ /g, '').split(',');
|
|
169
|
+
this.requiredActionsCount = activeUAList.filter(action => this.mandatoryActions.includes(action)).length;
|
|
170
|
+
this.expectedQueryResponses = activeUAList.length;
|
|
171
|
+
return (index.h("div", { class: "QueryReferenceContainer" }, index.h("div", { class: "UserActionController" }, index.h("h2", { class: "UserConsentNotice" }, this.userNoticeText), index.h("legislation-wrapper", { "active-user-actions": this.activeUserActions }, activeUAList.map(item => (index.h("generic-user-consent", { slot: item, consentType: item, consentTitle: this.consentTitles[item], queried: this.queryFired, mandatory: this.mandatoryActions.includes(item) })))), this.includeSubmitButton &&
|
|
172
|
+
index.h("button", { class: "ConsentSubmitButton", disabled: this.readyActionsCount === this.requiredActionsCount ? false : true, onClick: () => this.handleApplyClick() }, this.submitButtonText))));
|
|
173
|
+
}
|
|
174
|
+
static get watchers() { return {
|
|
175
|
+
"receivedQueryResponses": ["handleQueryResponse"]
|
|
176
|
+
}; }
|
|
177
|
+
};
|
|
178
|
+
UserActionController.style = userActionControllerCss;
|
|
179
|
+
|
|
180
|
+
exports.generic_user_consent = GenericUserConsent;
|
|
181
|
+
exports.legislation_wrapper = LegislationWrapper;
|
|
182
|
+
exports.user_action_controller = UserActionController;
|