@everymatrix/user-action-controller 1.34.0 → 1.35.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.
@@ -34,13 +34,14 @@ export class UserActionController {
34
34
  this.limitStylingAppends = false;
35
35
  this.isLoading = true;
36
36
  this.mandatoryActionsChecked = 0;
37
- //for now this variable is hardcoded bcs we have only terms and conditions mandatory and we dont receive with these new functionality the mandatory actions
38
- this.mandatoryActions = ['termsandconditions'];
37
+ //for now this variable is hardcoded bcs we have terms and conditions and privacy policy mandatory and we dont receive with these new functionality the mandatory actions
38
+ this.mandatoryActions = ['termsandconditions', 'privacypolicy'];
39
39
  this.userActions = [];
40
40
  this.consentTitles = {
41
41
  termsandconditions: translate('termsandconditions', this.lang),
42
42
  sms: translate('sms', this.lang),
43
- emailmarketing: translate('emailmarketing', this.lang)
43
+ emailmarketing: translate('emailmarketing', this.lang),
44
+ privacypolicy: translate('privacypolicy', this.lang)
44
45
  };
45
46
  this.setClientStyling = () => {
46
47
  let sheet = document.createElement('style');
@@ -82,56 +83,62 @@ export class UserActionController {
82
83
  this.receivedQueryResponses++;
83
84
  }
84
85
  }
85
- determineUserActions() {
86
+ determineUserActionsCore() {
86
87
  const url = new URL(`${this.endpoint}/v1/player/${this.userId}/consent`);
87
88
  const headers = new Headers();
88
89
  headers.append('X-SessionId', this.userSession);
89
- let requestOptions;
90
- requestOptions = {
90
+ let requestOptions = {
91
91
  method: 'GET',
92
92
  headers
93
93
  };
94
- if (url && requestOptions) {
95
- return fetch(url.href, requestOptions)
96
- .then(res => res.json())
97
- .then(data => {
98
- const actionItems = data.items;
99
- actionItems.forEach(element => {
100
- if (element.status === 'Expired') {
101
- this.activeUserActions.push(element.tagCode);
102
- }
103
- });
104
- this.isLoading = false;
105
- })
106
- .catch(error => {
107
- console.error('Error fetching data:', error);
108
- this.isLoading = false;
94
+ return fetch(url.href, requestOptions)
95
+ .then(res => res.json())
96
+ .then(data => {
97
+ const actionItems = data.items;
98
+ actionItems.forEach(element => {
99
+ if (element.status === 'Expired') {
100
+ this.activeUserActions.push(element.tagCode);
101
+ }
109
102
  });
110
- }
111
- else {
112
- return Promise.reject('Unsupported endpoint');
113
- }
103
+ this.isLoading = false;
104
+ })
105
+ .catch(error => {
106
+ console.error('Error fetching data:', error);
107
+ this.isLoading = false;
108
+ });
109
+ }
110
+ determineUserActions16() {
111
+ const url = new URL(`${this.endpoint}/v1/player/${this.userId}/legislation/consents`);
112
+ const headers = new Headers();
113
+ headers.append('X-SessionId', this.userSession);
114
+ let requestOptions = {
115
+ method: 'GET',
116
+ headers
117
+ };
118
+ return fetch(url.href, requestOptions)
119
+ .then(res => res.json())
120
+ .then(data => {
121
+ const actionItems = data.consents;
122
+ actionItems.forEach(element => {
123
+ if (element.status === 2) {
124
+ this.activeUserActions.push(element.tagCode);
125
+ }
126
+ });
127
+ this.isLoading = false;
128
+ })
129
+ .catch(error => {
130
+ console.error('Error fetching data:', error);
131
+ this.isLoading = false;
132
+ });
114
133
  }
115
134
  updateUserConsents() {
116
- let url;
117
- let requestOptions;
118
- url = (this.gmVersion === 'gmcore')
135
+ const url = (this.gmVersion === 'gmcore')
119
136
  ? new URL(`${this.endpoint}/v1/player/${this.userId}/consent`)
120
137
  : new URL(`${this.endpoint}/v1/player/${this.userId}/legislation/consents`);
121
- const body = (this.gmVersion === 'gmcore')
122
- ? {
123
- items: this.userActions
124
- }
125
- : {
126
- consents: [
127
- {
128
- tagCode: "termsandconditions",
129
- note: "",
130
- status: 1
131
- }
132
- ]
133
- };
134
- requestOptions = {
138
+ const body = {
139
+ items: this.userActions
140
+ };
141
+ let requestOptions = {
135
142
  method: 'POST',
136
143
  headers: {
137
144
  'Content-Type': 'application/json',
@@ -140,43 +147,40 @@ export class UserActionController {
140
147
  },
141
148
  body: JSON.stringify(body)
142
149
  };
143
- if (url && requestOptions) {
144
- fetch(url.href, requestOptions)
145
- .then(res => res.json())
146
- .then(() => {
147
- window.postMessage({
148
- type: 'WidgetNotification',
149
- data: {
150
- type: 'success',
151
- message: 'Consent update successful!'
152
- }
153
- }, window.location.href);
154
- })
155
- .catch((err) => {
156
- window.postMessage({
157
- type: 'WidgetNotification',
158
- data: {
159
- type: 'error',
160
- message: 'Server might not be responding',
161
- err
162
- }
163
- }, window.location.href);
164
- })
165
- .finally(() => {
166
- window.postMessage({ type: 'UserActionsCompleted' }, window.location.href);
167
- });
168
- }
150
+ fetch(url.href, requestOptions)
151
+ .then(res => res.json())
152
+ .then(() => {
153
+ window.postMessage({
154
+ type: 'WidgetNotification',
155
+ data: {
156
+ type: 'success',
157
+ message: 'Consent update successful!'
158
+ }
159
+ }, window.location.href);
160
+ })
161
+ .catch((err) => {
162
+ window.postMessage({
163
+ type: 'WidgetNotification',
164
+ data: {
165
+ type: 'error',
166
+ message: 'Server might not be responding',
167
+ err
168
+ }
169
+ }, window.location.href);
170
+ })
171
+ .finally(() => {
172
+ window.postMessage({ type: 'UserActionsCompleted' }, window.location.href);
173
+ });
169
174
  }
170
175
  handleApplyClick() {
171
176
  this.queryFired = true;
172
177
  }
173
178
  async componentWillLoad() {
174
179
  if (this.gmVersion === 'gmcore') {
175
- return this.determineUserActions();
180
+ this.determineUserActionsCore();
176
181
  }
177
- else {
178
- this.activeUserActions = ['termsandconditions'];
179
- this.isLoading = false;
182
+ if (this.gmVersion === 'gm16') {
183
+ this.determineUserActions16();
180
184
  }
181
185
  if (this.translationUrl.length > 2) {
182
186
  await getTranslations(this.translationUrl);
@@ -194,22 +198,24 @@ export class UserActionController {
194
198
  // end custom styling area
195
199
  }
196
200
  render() {
197
- const isMandatoryPresent = this.mandatoryActions.every(action => this.activeUserActions.includes(action));
198
- if (isMandatoryPresent) {
199
- this.userActionsValidated = !(this.mandatoryActionsChecked === this.mandatoryActions.length);
200
- }
201
- else {
202
- this.userActionsValidated = false;
203
- }
201
+ let mandatoryItems = 0;
202
+ const isMandatoryPresent = this.mandatoryActions.some(action => {
203
+ const isPresent = this.activeUserActions.includes(action);
204
+ if (isPresent) {
205
+ mandatoryItems++;
206
+ }
207
+ return isPresent;
208
+ });
209
+ this.userActionsValidated = isMandatoryPresent && (this.mandatoryActionsChecked === mandatoryItems);
204
210
  return (h("div", { class: "QueryReferenceContainer", ref: el => this.stylingContainer = el }, this.isLoading ? (h("slot", { name: 'spinner' })
205
211
  &&
206
212
  h("svg", { class: "spinner", viewBox: "0 0 50 50" },
207
213
  h("circle", { class: "path", cx: "25", cy: "25", r: "20", fill: "none", "stroke-width": "5" }))) : (h("div", { class: "UserActionController" },
208
214
  h("h2", { class: "UserConsentNotice" }, this.userNoticeText),
209
215
  h("div", { class: "PlayerLegislationWrapper" }, this.activeUserActions.map(action => (h("slot", { name: action },
210
- h("player-user-consents", { lang: this.lang, "translation-url": this.translationUrl, slot: action, consentType: action, consentTitle: this.consentTitles[action], queried: this.queryFired, mandatory: this.mandatoryActions.includes(action), "client-styling": this.clientStyling }))))),
216
+ h("player-user-consents", { lang: this.lang, "gm-version": this.gmVersion, "translation-url": this.translationUrl, slot: action, consentType: action, consentTitle: this.consentTitles[action], queried: this.queryFired, mandatory: this.mandatoryActions.includes(action), "client-styling": this.clientStyling }))))),
211
217
  this.includeSubmitButton &&
212
- h("button", { class: "ConsentSubmitButton", disabled: this.userActionsValidated, onClick: () => this.handleApplyClick() }, this.submitButtonText)))));
218
+ h("button", { class: "ConsentSubmitButton", disabled: !this.userActionsValidated, onClick: () => this.handleApplyClick() }, this.submitButtonText)))));
213
219
  }
214
220
  static get is() { return "user-action-controller"; }
215
221
  static get encapsulation() { return "shadow"; }
@@ -4,32 +4,38 @@ const TRANSLATIONS = {
4
4
  en: {
5
5
  termsandconditions: 'Terms and Conditions',
6
6
  sms: 'SMS marketing',
7
- emailmarketing: 'Email marketing'
7
+ emailmarketing: 'Email marketing',
8
+ privacypolicy: 'Privacy Policy'
8
9
  },
9
10
  ro: {
10
11
  termsandconditions: 'Termeni şi condiţii',
11
12
  sms: 'SMS marketing',
12
- emailmarketing: 'Email marketing'
13
+ emailmarketing: 'Email marketing',
14
+ privacypolicy: 'Privacy Policy'
13
15
  },
14
16
  hr: {
15
17
  termsandconditions: 'Terms and Conditions',
16
18
  sms: 'SMS marketing',
17
- emailmarketing: 'Email marketing'
19
+ emailmarketing: 'Email marketing',
20
+ privacypolicy: 'Privacy Policy'
18
21
  },
19
22
  fr: {
20
23
  termsandconditions: 'Terms and Conditions',
21
24
  sms: 'SMS marketing',
22
- emailmarketing: 'Email marketing'
25
+ emailmarketing: 'Email marketing',
26
+ privacypolicy: 'Privacy Policy'
23
27
  },
24
28
  cs: {
25
29
  termsandconditions: 'Terms and Conditions',
26
30
  sms: 'SMS marketing',
27
- emailmarketing: 'Email marketing'
31
+ emailmarketing: 'Email marketing',
32
+ privacypolicy: 'Privacy Policy'
28
33
  },
29
34
  de: {
30
35
  termsandconditions: 'Terms and Conditions',
31
36
  sms: 'SMS marketing',
32
- emailmarketing: 'Email marketing'
37
+ emailmarketing: 'Email marketing',
38
+ privacypolicy: 'Privacy Policy'
33
39
  },
34
40
  };
35
41
  export const getTranslations = (url) => {
@@ -3,58 +3,94 @@ import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/i
3
3
  const DEFAULT_LANGUAGE = 'en';
4
4
  const TRANSLATIONS = {
5
5
  en: {
6
- termsandconditions1: "I accept the ",
7
- termsandconditions2: ", I have read and understood the ",
8
- termsandconditions3: " as published on this site and confirm that I am over 18 years old.",
9
- tc: "Terms and Conditions",
10
- privacy: "Privacy Policy",
6
+ termsAndConditions: {
7
+ acceptPart1: "I accept the ",
8
+ acceptPart2: ", I have read and understood the ",
9
+ acceptPart3: " as published on this site and confirm that I am over 18 years old.",
10
+ tc: "Terms and Conditions"
11
+ },
12
+ privacyPolicy: {
13
+ readUnderstandPart1: "I have read and understood the ",
14
+ readUnderstandPart2: ", as published on this site and confirm that I am over 18 years old.",
15
+ privacy: "Privacy Policy"
16
+ },
11
17
  sms: "I consent to receive marketing communication via SMS.",
12
- emailmarketing: "I consent to receive marketing communication via Email."
18
+ email: "I consent to receive marketing communication via Email."
13
19
  },
14
20
  ro: {
15
- termsandconditions1: "Accept ",
16
- termsandconditions2: " platformei. Am citit şi înţeles ",
17
- termsandconditions3: " publicată pe acest site şi confirm că am vârstă peste 18 ani.",
18
- tc: "Termenii şi condiţiile",
19
- privacy: "Politica de confidenţialitate",
21
+ termsAndConditions: {
22
+ acceptPart1: "Accept ",
23
+ acceptPart2: " platformei. Am citit şi înţeles ",
24
+ acceptPart3: " publicată pe acest site şi confirm că am vârstă peste 18 ani.",
25
+ tc: "Termenii şi condiţiile"
26
+ },
27
+ privacyPolicy: {
28
+ readUnderstandPart1: "Am citit şi înţeles ",
29
+ readUnderstandPart2: " publicată pe acest site şi confirm că am vârstă peste 18 ani.",
30
+ privacy: "Politica de confidenţialitate"
31
+ },
20
32
  sms: "Sunt de acord să primesc promoţii de marketing prin SMS.",
21
- emailmarketing: "Sunt de acord să primesc promoţii de marketing pe e-mail."
33
+ email: "Sunt de acord să primesc promoţii de marketing pe e-mail."
22
34
  },
23
35
  hr: {
24
- termsandconditions1: "I accept the ",
25
- termsandconditions2: ", I have read and understood the ",
26
- termsandconditions3: " as published on this site and confirm that I am over 18 years old.",
27
- tc: "Terms and Conditions",
28
- privacy: "Privacy Policy",
36
+ termsAndConditions: {
37
+ acceptPart1: "I accept the ",
38
+ acceptPart2: ", I have read and understood the ",
39
+ acceptPart3: " as published on this site and confirm that I am over 18 years old.",
40
+ tc: "Terms and Conditions"
41
+ },
42
+ privacyPolicy: {
43
+ readUnderstandPart1: "I have read and understood the ",
44
+ readUnderstandPart2: ", as published on this site and confirm that I am over 18 years old.",
45
+ privacy: "Privacy Policy"
46
+ },
29
47
  sms: "I consent to receive marketing communication via SMS.",
30
- emailmarketing: "I consent to receive marketing communication via Email."
48
+ email: "I consent to receive marketing communication via Email."
31
49
  },
32
50
  fr: {
33
- termsandconditions1: "I accept the ",
34
- termsandconditions2: ", I have read and understood the ",
35
- termsandconditions3: " as published on this site and confirm that I am over 18 years old.",
36
- tc: "Terms and Conditions",
37
- privacy: "Privacy Policy",
51
+ termsAndConditions: {
52
+ acceptPart1: "I accept the ",
53
+ acceptPart2: ", I have read and understood the ",
54
+ acceptPart3: " as published on this site and confirm that I am over 18 years old.",
55
+ tc: "Terms and Conditions"
56
+ },
57
+ privacyPolicy: {
58
+ readUnderstandPart1: "I have read and understood the ",
59
+ readUnderstandPart2: ", as published on this site and confirm that I am over 18 years old.",
60
+ privacy: "Privacy Policy"
61
+ },
38
62
  sms: "I consent to receive marketing communication via SMS.",
39
- emailmarketing: "I consent to receive marketing communication via Email."
63
+ email: "I consent to receive marketing communication via Email."
40
64
  },
41
65
  cs: {
42
- termsandconditions1: "I accept the ",
43
- termsandconditions2: ", I have read and understood the ",
44
- termsandconditions3: " as published on this site and confirm that I am over 18 years old.",
45
- tc: "Terms and Conditions",
46
- privacy: "Privacy Policy",
66
+ termsAndConditions: {
67
+ acceptPart1: "I accept the ",
68
+ acceptPart2: ", I have read and understood the ",
69
+ acceptPart3: " as published on this site and confirm that I am over 18 years old.",
70
+ tc: "Terms and Conditions"
71
+ },
72
+ privacyPolicy: {
73
+ readUnderstandPart1: "I have read and understood the ",
74
+ readUnderstandPart2: ", as published on this site and confirm that I am over 18 years old.",
75
+ privacy: "Privacy Policy"
76
+ },
47
77
  sms: "I consent to receive marketing communication via SMS.",
48
- emailmarketing: "I consent to receive marketing communication via Email."
78
+ email: "I consent to receive marketing communication via Email."
49
79
  },
50
80
  de: {
51
- termsandconditions1: "I accept the ",
52
- termsandconditions2: ", I have read and understood the ",
53
- termsandconditions3: " as published on this site and confirm that I am over 18 years old.",
54
- tc: "Terms and Conditions",
55
- privacy: "Privacy Policy",
81
+ termsAndConditions: {
82
+ acceptPart1: "I accept the ",
83
+ acceptPart2: ", I have read and understood the ",
84
+ acceptPart3: " as published on this site and confirm that I am over 18 years old.",
85
+ tc: "Terms and Conditions"
86
+ },
87
+ privacyPolicy: {
88
+ readUnderstandPart1: "I have read and understood the ",
89
+ readUnderstandPart2: ", as published on this site and confirm that I am over 18 years old.",
90
+ privacy: "Privacy Policy"
91
+ },
56
92
  sms: "I consent to receive marketing communication via SMS.",
57
- emailmarketing: "I consent to receive marketing communication via Email."
93
+ email: "I consent to receive marketing communication via Email."
58
94
  },
59
95
  };
60
96
  const getTranslations = (url) => {
@@ -73,12 +109,18 @@ const getTranslations = (url) => {
73
109
  });
74
110
  };
75
111
  const translate = (key, customLang, values) => {
76
- const lang = customLang;
77
- let translation = TRANSLATIONS[lang !== undefined ? lang : DEFAULT_LANGUAGE][key];
112
+ const lang = customLang || DEFAULT_LANGUAGE;
113
+ const getNestedTranslation = (obj, path) => {
114
+ return path.split('.').reduce((o, k) => (o && o[k] !== undefined ? o[k] : null), obj);
115
+ };
116
+ let translation = getNestedTranslation(TRANSLATIONS[lang], key);
117
+ if (translation === null) {
118
+ return key;
119
+ }
78
120
  if (values !== undefined) {
79
- for (const [key, value] of Object.entries(values.values)) {
80
- const regex = new RegExp(`{${key}}`, 'g');
81
- translation = translation.replace(regex, value);
121
+ for (const [k, v] of Object.entries(values)) {
122
+ const regex = new RegExp(`{${k}}`, 'g');
123
+ translation = translation.replace(regex, v);
82
124
  }
83
125
  }
84
126
  return translation;
@@ -108,6 +150,10 @@ const PlayerUserConsents = /*@__PURE__*/ proxyCustomElement(class extends HTMLEl
108
150
  * wether or not this consent is mandatory. Used for render details
109
151
  */
110
152
  this.mandatory = false;
153
+ /**
154
+ * Select GM version
155
+ */
156
+ this.gmVersion = '';
111
157
  /**
112
158
  * the title of the consent to be displayed
113
159
  */
@@ -157,9 +203,20 @@ const PlayerUserConsents = /*@__PURE__*/ proxyCustomElement(class extends HTMLEl
157
203
  // end custom styling area
158
204
  }
159
205
  determineTextContent() {
160
- return this.consentType === 'termsandconditions' ?
161
- h("p", null, translate('termsandconditions1', this.lang), h("span", { class: "ConsentLink", onClick: this.goToTermsAndConditions }, translate('tc', this.lang)), translate('termsandconditions2', this.lang), h("span", { class: "ConsentLink", onClick: this.goToPrivacyPolicy }, translate('privacy', this.lang)), translate('termsandconditions3', this.lang))
162
- : h("p", null, translate(this.consentType, this.lang));
206
+ if (this.gmVersion === 'gmcore') {
207
+ if (this.consentType === 'termsandconditions') {
208
+ return h("p", null, translate('termsAndConditions.acceptPart1', this.lang), h("span", { class: "ConsentLink", onClick: this.goToTermsAndConditions }, translate('termsAndConditions.tc', this.lang)), translate('termsAndConditions.acceptPart2', this.lang), h("span", { class: "ConsentLink", onClick: this.goToPrivacyPolicy }, translate('privacyPolicy.privacy', this.lang)), translate('termsAndConditions.acceptPart3', this.lang));
209
+ }
210
+ }
211
+ if (this.gmVersion === 'gm16') {
212
+ if (this.consentType === 'termsandconditions') {
213
+ return h("p", null, translate('termsAndConditions.acceptPart1', this.lang), h("span", { class: "ConsentLink", onClick: this.goToTermsAndConditions }, translate('termsAndConditions.tc', this.lang)));
214
+ }
215
+ if (this.consentType === 'privacypolicy') {
216
+ return h("p", null, translate('privacyPolicy.readUnderstandPart1', this.lang), h("span", { class: "ConsentLink", onClick: this.goToPrivacyPolicy }, translate('privacyPolicy.privacy', this.lang)), translate('privacyPolicy.readUnderstandPart2', this.lang));
217
+ }
218
+ }
219
+ return h("p", null, translate(this.consentType, this.lang));
163
220
  }
164
221
  render() {
165
222
  if (this.queried) {
@@ -176,6 +233,7 @@ const PlayerUserConsents = /*@__PURE__*/ proxyCustomElement(class extends HTMLEl
176
233
  "queried": [516],
177
234
  "consentType": [513, "consent-type"],
178
235
  "mandatory": [516],
236
+ "gmVersion": [1, "gm-version"],
179
237
  "consentTitle": [513, "consent-title"],
180
238
  "clientStyling": [1, "client-styling"],
181
239
  "translationUrl": [513, "translation-url"],