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