@washingtonpost/subs-de-inputs 1.10.2 → 1.11.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.
@@ -1,783 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var subsSdk = require('@washingtonpost/subs-sdk');
6
- var React = require('react');
7
- var wpdsUiKit = require('@washingtonpost/wpds-ui-kit');
8
- var subsHooks = require('@washingtonpost/subs-hooks');
9
- var wpdsAssets = require('@washingtonpost/wpds-assets');
10
-
11
- const CollectionBehaviors = {
12
- COLLECT: 'COLLECT',
13
- DO_NOT_COLLECT: 'DO_NOT_COLLECT'
14
- };
15
- const AttributesState = {
16
- SUCCESS: '100'
17
- };
18
- // https://github.com/WashPost/subs-be-user-data-enrichment/blob/8e8f8460c59adbe9c83b50f368bff1d3300bfd6b/src/main/java/washpost/paywall/userdataenrichment/model/ResponseState.java#L19
19
- const DeleteAttributeState = {
20
- SUCCESS: '150',
21
- SYSTEM_ERROR: '151',
22
- INVALID_ATTRIBUTE_NAME: '152',
23
- INVALID_ATTRIBUTE_NOT_EXISTS: '153'
24
- };
25
- const IngestType = {
26
- EXPLICIT: 'explicit',
27
- IMPLICIT: 'implicit'
28
- };
29
- const IngestResponseState = {
30
- SUCCESS: '100',
31
- SYSTEM_ERROR: '101',
32
- INVALID_TYPE: '102',
33
- INVALID_IDENTIFIER: '103',
34
- INVALID_DATA: '104',
35
- INVALID_ATTRIBUTE_DEFINITION: '105',
36
- INVALID_META_DEFINITION: '106',
37
- UNAUTHENTICATED: '107',
38
- MISMATCHED_IDENTIFIER: '108',
39
- DISABLED_ATTRIBUTE_DEFINITION: '109',
40
- DO_NOT_COLLECT: '110'
41
- };
42
-
43
- const COOKIE$2 = 'OptanonConsent';
44
- /**
45
- * Checks the users OptanonConsent cookie to determine if the user has allowed targeting.
46
- * Returns true or false if the flag is found in the cookie, null otherwise.
47
- * @returns {boolean | null}
48
- */
49
- const checkConsentCookieForAllowTargeting = () => {
50
- const value = subsSdk.getCookie(COOKIE$2) || '';
51
- return value.includes('C0004%3A1') ? true : value.includes('C0004%3A0') ? false : null;
52
- };
53
-
54
- const COOKIE$1 = 'OptanonAlertBoxClosed';
55
- const checkAlertBoxClosedCookie = () => {
56
- const value = subsSdk.getCookie(COOKIE$1) || '';
57
- // Wed May 15 2024 06:29:23 GMT-0500 (Central Daylight Time)
58
- // "Invalid date" is 12 characters long
59
- return value.length > 12;
60
- };
61
-
62
- /**
63
- * Checks privacy cookies to decide if we can send up 1pd
64
- * If US, checks that wp_usp exists
65
- * Else If OptAnonConsent cookie exists, checks the value of targeting cookies consent
66
- * Else If EEA, always returns true
67
- * Else, returns false
68
- * @returns {boolean}
69
- */
70
- const hasRequiredPrivacyCookies = () => {
71
- if (typeof window === 'undefined') {
72
- return false;
73
- }
74
- const {
75
- intl_region,
76
- country_code: countryCode
77
- } = subsSdk.WPGeo();
78
- if (countryCode === 'US') {
79
- return !!subsSdk.getCookie('wp_usp');
80
- }
81
- if (window.pageType === 'onboarding') {
82
- const gdprAllowTargarting = checkConsentCookieForAllowTargeting();
83
- if (typeof gdprAllowTargarting === 'boolean' && checkAlertBoxClosedCookie()) {
84
- return gdprAllowTargarting;
85
- }
86
- // Downstream systems
87
- // Checking for window.pageType === 'onboarding' to avoid being true on graphics articles etc for now -- MNI-710
88
- if (intl_region === 'EEA' && window.pageType === 'onboarding') {
89
- return true;
90
- }
91
- }
92
- return false;
93
- };
94
-
95
- const base$1 = `${subsSdk.ENDPOINTS.base}/de/v1`;
96
- const attributesCache = {};
97
- const getAttributes = async ({
98
- fieldName
99
- }) => {
100
- if (attributesCache[fieldName]) {
101
- return attributesCache[fieldName];
102
- }
103
- const fieldNames = [fieldName];
104
- try {
105
- const url = new URL(`${base$1}/attributes`);
106
- url.searchParams.set('attributes', fieldNames.join(','));
107
- const data = await fetch(url.toString(), {
108
- credentials: 'include',
109
- headers: subsSdk.DEFAULT_HEADERS
110
- });
111
- const json = await data.json();
112
- if (data.ok && json.status === subsSdk.ResponseStatus.SUCCESS) {
113
- const attributes = json.attributes || [];
114
- attributesCache[fieldName] = attributes;
115
- return attributes;
116
- }
117
- return [];
118
- } catch (e) {
119
- console.debug(e);
120
- return [];
121
- }
122
- };
123
-
124
- const sendGAEvent = props => {
125
- if (typeof window === 'undefined') {
126
- console.warn('NO WINDOW');
127
- return;
128
- }
129
- // Initialize dataLayer if needed
130
- window.dataLayer = window.dataLayer || [];
131
- const eventData = {
132
- ...props
133
- };
134
- window.dataLayer.push(eventData);
135
- };
136
- const sendToGA = async ({
137
- submitData: {
138
- fieldName,
139
- value
140
- },
141
- source
142
- }) => {
143
- sendGAEvent({
144
- event: 'site-onpage-click',
145
- action: 'site-onpage-click',
146
- category: 'profile',
147
- label: fieldName,
148
- 'de-label': fieldName,
149
- [fieldName]: value,
150
- section: 'profile',
151
- subsection: source
152
- });
153
- return true;
154
- };
155
-
156
- const base = `${subsSdk.ENDPOINTS.base}/de/v1`;
157
- const ingest = async ({
158
- submitData: {
159
- fieldName,
160
- value
161
- },
162
- source
163
- }) => {
164
- const url = `${base}/ingest`;
165
- const wapo_login_id = subsSdk.getCookie('wapo_login_id');
166
- const jucid = localStorage.getItem('uuid');
167
- const ga = subsSdk.getCookie('_ga');
168
- const payload = {
169
- jucid,
170
- ga,
171
- type: IngestType.EXPLICIT,
172
- wapo_login_id,
173
- // TODO: move this to BE to read from cookie headers
174
- data: {
175
- [fieldName]: [value]
176
- },
177
- metadata: {
178
- source
179
- }
180
- };
181
- try {
182
- const response = await fetch(url, {
183
- method: 'POST',
184
- credentials: 'include',
185
- headers: subsSdk.DEFAULT_HEADERS,
186
- body: JSON.stringify(payload)
187
- });
188
- const json = await response.json();
189
- return json;
190
- } catch (e) {
191
- console.debug(e);
192
- return null;
193
- }
194
- };
195
-
196
- const isAnonymousWebview = () => {
197
- if (typeof window === 'undefined') {
198
- return false;
199
- }
200
- const wp_wv = subsSdk.getCookie('wp_wv');
201
- return !!(wp_wv && !subsSdk.isLoggedIn());
202
- };
203
-
204
- const push = async ({
205
- submitData,
206
- source
207
- }) => {
208
- if (!hasRequiredPrivacyCookies()) {
209
- throw new Error('does not satisfy cookie check');
210
- }
211
- if (isAnonymousWebview()) {
212
- throw new Error('does not satisfy cookie check');
213
- }
214
- const {
215
- fieldName
216
- } = submitData;
217
- const attributeInfo = await getAttributes({
218
- fieldName
219
- });
220
- if (attributeInfo[0] && attributeInfo[0].name === fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
221
- throw new Error('do not collect');
222
- }
223
- const type = attributeInfo[0] && attributeInfo[0].explicit === true ? IngestType.EXPLICIT : IngestType.IMPLICIT;
224
- if (!attributeInfo[0] && "development" !== "production") {
225
- console.warn(`no attribute info found for ${fieldName}, assuming implicit`);
226
- }
227
- if (type === IngestType.EXPLICIT) {
228
- return ingest({
229
- submitData,
230
- source
231
- });
232
- }
233
- return sendToGA({
234
- submitData,
235
- source
236
- });
237
- };
238
-
239
- const StyledMobileSelect = /*#__PURE__*/wpdsUiKit.styled('select', {
240
- padding: '12px 16px 12px 6px',
241
- display: 'flex',
242
- justifyContent: 'space-between',
243
- width: '100%',
244
- backgroundColor: '$secondary',
245
- color: '$primary',
246
- fontFamily: '$meta',
247
- fontSize: '$100',
248
- fontWeight: '$light',
249
- lineHeight: '$125',
250
- paddingBlockRight: '$125',
251
- textOverflow: 'ellipsis',
252
- position: 'relative',
253
- borderColor: 'transparent',
254
- borderRightWidth: '10px',
255
- borderRightColor: 'transparent',
256
- appearance: 'none',
257
- '-webkit-appearance': 'none',
258
- '&:disabled': {
259
- backgroundColor: wpdsUiKit.theme.colors.disabled,
260
- borderColor: wpdsUiKit.theme.colors.disabled,
261
- color: wpdsUiKit.theme.colors.onDisabled,
262
- cursor: 'not-allowed'
263
- }
264
- });
265
- const StyledSelectWrapper = /*#__PURE__*/wpdsUiKit.styled('div', {
266
- width: '100%',
267
- maxWidth: '380px',
268
- borderRadius: '$012',
269
- borderColor: '$subtle',
270
- borderStyle: 'solid',
271
- borderWidth: '1px',
272
- backgroundColor: '$secondary',
273
- position: 'relative'
274
- });
275
- const StyledMobileOption = /*#__PURE__*/wpdsUiKit.styled('option', {
276
- fontFamily: 'inherit',
277
- fontSize: 'inherit',
278
- color: 'inherit'
279
- });
280
- /**
281
- * Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
282
- * @param {IDropdownProps} props The props.
283
- * @returns {React.ReactElement} The dropdown.
284
- */
285
- const Dropdown = ({
286
- id,
287
- label,
288
- values,
289
- required = false,
290
- existingValue,
291
- onChange = () => {},
292
- disabled = false,
293
- valueSelectedByDefault
294
- }) => {
295
- const [answer, setAnswer] = React.useState();
296
- const {
297
- isMobileSize
298
- } = subsHooks.useWindowSize();
299
- React.useEffect(() => {
300
- if (answer) onChange(answer);
301
- }, [answer]);
302
- const disabledProp = disabled ? {
303
- disabled: true
304
- } : {};
305
- const presetDropdownValue = existingValue || valueSelectedByDefault;
306
- // helps maintain state between WPDS and native dropdowns
307
- const defaultValueProp = answer ? {
308
- defaultValue: answer
309
- } : presetDropdownValue ? {
310
- defaultValue: presetDropdownValue
311
- } : {};
312
- const defaultValuePropMobile = value => {
313
- if (answer) {
314
- return value === answer ? {
315
- selected: true
316
- } : {};
317
- }
318
- return value === presetDropdownValue ? {
319
- selected: true
320
- } : {};
321
- };
322
- return isMobileSize ? React.createElement(StyledSelectWrapper, null, React.createElement(StyledMobileSelect, {
323
- id: "",
324
- required: required,
325
- onChange: e => setAnswer(e.target.value),
326
- ...disabledProp
327
- }, React.createElement("label", null, label), React.createElement(StyledMobileOption, {
328
- value: "",
329
- disabled: true,
330
- selected: true,
331
- style: {
332
- color: '#666666'
333
- }
334
- }, label), values.map(value => React.createElement(StyledMobileOption, {
335
- value: value,
336
- key: value,
337
- ...defaultValuePropMobile(value)
338
- }, value))), React.createElement(wpdsUiKit.Icon, {
339
- label: "",
340
- size: "100",
341
- fill: wpdsUiKit.theme.colors.gray80,
342
- style: {
343
- pointerEvents: 'none',
344
- position: 'absolute',
345
- right: '10px',
346
- top: '50%',
347
- transform: 'translateY(-50%)'
348
- }
349
- }, React.createElement(wpdsAssets.ChevronDown, {
350
- style: {
351
- position: 'absolute',
352
- right: '10px'
353
- }
354
- }))) : React.createElement(wpdsUiKit.Select.Root, {
355
- onValueChange: e => setAnswer(e),
356
- required: required,
357
- ...defaultValueProp,
358
- ...disabledProp
359
- }, React.createElement(wpdsUiKit.Select.Trigger, {
360
- "data-test-id": `${id}-select-trigger`
361
- }, React.createElement(wpdsUiKit.Select.Label, null, label), React.createElement(wpdsUiKit.Select.Value, null)), React.createElement(wpdsUiKit.Select.Content, {
362
- css: {
363
- zIndex: wpdsUiKit.theme.zIndices.page
364
- },
365
- "data-test-id": `${id}-select-content`
366
- }, values.map(value => React.createElement(wpdsUiKit.Select.Item, {
367
- value: value,
368
- key: value
369
- }, value))));
370
- };
371
-
372
- const scriptSrc = `${subsSdk.ENDPOINTS.base}/de-utils/twpdeu.min.js`;
373
- const SelectWrapper = /*#__PURE__*/wpdsUiKit.styled('div', {
374
- boxSizing: 'border-box',
375
- display: 'flex',
376
- marginBottom: '$100',
377
- flexDirection: 'column',
378
- '& button': {
379
- padding: '1px 6px'
380
- },
381
- '& *': {
382
- boxSizing: 'border-box'
383
- }
384
- });
385
- const DESelect = ({
386
- source,
387
- fieldName,
388
- label,
389
- dataDictionaryConfig,
390
- existingValue,
391
- disabled,
392
- submit,
393
- onChange = () => {},
394
- onFinished = () => {},
395
- valuesFilter = () => true,
396
- children,
397
- valueSelectedByDefault
398
- }) => {
399
- const [config, setConfig] = React.useState(dataDictionaryConfig);
400
- const [selected, setSelected] = React.useState(!existingValue && valueSelectedByDefault ? valueSelectedByDefault : '');
401
- const scriptStatus = subsHooks.useScript(scriptSrc);
402
- React.useEffect(() => {
403
- const fetchConfig = async () => {
404
- try {
405
- var _window;
406
- // eslint-disable-next-line @typescript-eslint/no-shadow
407
- const config = await ((_window = window) === null || _window === void 0 || (_window = _window.__twpdeu) === null || _window === void 0 ? void 0 : _window.getFieldConfigs({
408
- fieldName
409
- }));
410
- if (config) {
411
- setConfig(config[0]);
412
- } else {
413
- console.error('unable to get config', fieldName);
414
- }
415
- } catch (e) {
416
- console.warn('unable to get config', fieldName, e);
417
- }
418
- };
419
- if (scriptStatus === subsHooks.ScriptStatus.READY && !(children || config)) {
420
- fetchConfig();
421
- }
422
- }, [scriptStatus]);
423
- React.useEffect(() => {
424
- const submitSelected = async () => {
425
- try {
426
- var _window2;
427
- const result = await ((_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.__twpdeu) === null || _window2 === void 0 ? void 0 : _window2.push({
428
- submitData: {
429
- fieldName,
430
- value: selected
431
- },
432
- source
433
- }));
434
- const isError = result === true ? false : result ? result.status !== subsSdk.ResponseStatus.SUCCESS : true;
435
- onFinished({
436
- isFinished: true,
437
- isError
438
- });
439
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
440
- } catch (e) {
441
- onFinished({
442
- isFinished: false,
443
- isError: true
444
- });
445
- }
446
- };
447
- if (scriptStatus === subsHooks.ScriptStatus.READY && submit && selected) {
448
- submitSelected();
449
- }
450
- }, [scriptStatus, submit]);
451
- const defaultValueProp = existingValue && config ? {
452
- defaultValue: existingValue
453
- } : {};
454
- const isLoading = !(children || config);
455
- const disabledProp = disabled || isLoading ? {
456
- disabled: true
457
- } : {};
458
- // sort and filter out archived values
459
- // Note: config.values may be readonly
460
- const values = config ? [...config.values].sort((a, b) => a.order - b.order).filter(value => value.archived !== true).filter(valuesFilter) : [];
461
- return React.createElement(SelectWrapper, null, children && React.createElement(wpdsUiKit.Select.Root, {
462
- onValueChange: e => {
463
- setSelected(e);
464
- onChange({
465
- value: e
466
- });
467
- },
468
- ...defaultValueProp,
469
- ...disabledProp
470
- }, children), !children && !config && React.createElement(Dropdown, {
471
- id: 'loading',
472
- label: 'Loading...',
473
- values: [],
474
- disabled: true
475
- }), !children && config && React.createElement(Dropdown, {
476
- id: config.name,
477
- label: label || config.name,
478
- onChange: e => {
479
- setSelected(e);
480
- onChange({
481
- value: e
482
- });
483
- },
484
- values: values.map(value => value.name),
485
- existingValue: existingValue,
486
- disabled: disabled,
487
- valueSelectedByDefault: valueSelectedByDefault
488
- }));
489
- };
490
-
491
- const configSrc = `${subsSdk.ENDPOINTS.base === 'https://subscribe.washingtonpost.com' ? 'https://www.washingtonpost.com/subscribe' : subsSdk.ENDPOINTS.base}/config/de/disclosure.json`;
492
- const getConfig = async () => {
493
- let myConfig;
494
- // step 1: fetch config
495
- const response = await fetch(configSrc);
496
- const remoteConfig = await response.json();
497
- // step 2: figure out which part of the config to use
498
- // if country- or region-specific config found, use that
499
- const {
500
- country_code,
501
- intl_region
502
- } = subsSdk.WPGeo();
503
- Object.keys(remoteConfig).forEach(configKey => {
504
- if (country_code && configKey.split('|').includes(country_code.toLowerCase())) {
505
- myConfig = remoteConfig[configKey];
506
- } else if (intl_region === 'EEA' && configKey === 'eea') {
507
- myConfig = remoteConfig[configKey];
508
- }
509
- });
510
- // TODO: Check for billing country also
511
- // else if no country-specific config, use the default config
512
- if (typeof myConfig === 'undefined' && remoteConfig._) {
513
- myConfig = remoteConfig._;
514
- }
515
- return myConfig;
516
- };
517
-
518
- const hydrateLinks = (str, onLinkClick = () => {}) => {
519
- const array = str.split(/({{PRIVACY_POLICY}})/g);
520
- const chunks = array.map((chunk, i) => {
521
- if (chunk === '{{PRIVACY_POLICY}}') {
522
- return React.createElement("a", {
523
- key: `privacy-link-${i}`,
524
- rel: "noopener noreferrer",
525
- target: "_blank",
526
- style: {
527
- color: 'inherit'
528
- },
529
- className: "underline",
530
- href: "https://www.washingtonpost.com/privacy-policy/",
531
- onClick: e => onLinkClick(e)
532
- }, "Privacy Policy");
533
- }
534
- return chunk;
535
- });
536
- const toReturn = chunks.reduce((prev, current) => React.createElement(React.Fragment, null, prev, current), React.createElement(React.Fragment, null));
537
- return toReturn;
538
- };
539
-
540
- const COOKIE = 'OptanonConsent';
541
- const checkOptanonConsentCookie = () => {
542
- const value = subsSdk.getCookie(COOKIE) || '';
543
- return value.length > 12;
544
- };
545
-
546
- const CONSENT_COOKIE = 'OptanonConsent';
547
- const ALERT_BOX_COOKIE = 'OptanonAlertBoxClosed';
548
- const useOnetrust = ({
549
- allowCookieStore
550
- }) => {
551
- const [consentCookieExists, setConsentCookieExists] = React.useState();
552
- const [alertBoxClosed, setAlertBoxClosed] = React.useState();
553
- const [listenToCookieStore, setListenToCookieStore] = React.useState(false);
554
- const [listenToTcfApi, setListenToTcfApi] = React.useState(false);
555
- React.useEffect(() => {
556
- var _window;
557
- if (checkOptanonConsentCookie()) {
558
- setConsentCookieExists(true);
559
- }
560
- if (checkAlertBoxClosedCookie()) {
561
- setAlertBoxClosed(true);
562
- return;
563
- }
564
- if (!window.__tcfapi) {
565
- console.warn('warning: __tcfapi not found');
566
- }
567
- if ((_window = window) !== null && _window !== void 0 && _window.cookieStore && allowCookieStore) {
568
- setListenToCookieStore(true);
569
- } else if (window.__tcfapi) {
570
- setListenToTcfApi(true);
571
- } else {
572
- console.warn('warning: neither cookieStore nor __tcfapi found');
573
- }
574
- }, []);
575
- React.useEffect(() => {
576
- const cleanupFns = [];
577
- if (listenToCookieStore && window.cookieStore) {
578
- const cleanupFn = subsSdk.listenToCookieStore(CONSENT_COOKIE, () => {
579
- if (checkOptanonConsentCookie()) {
580
- setConsentCookieExists(true);
581
- }
582
- });
583
- cleanupFns.push(cleanupFn);
584
- const cleanupFn2 = subsSdk.listenToCookieStore(ALERT_BOX_COOKIE, () => {
585
- if (checkAlertBoxClosedCookie()) {
586
- setAlertBoxClosed(true);
587
- } else {
588
- setAlertBoxClosed(false);
589
- }
590
- });
591
- cleanupFns.push(cleanupFn2);
592
- }
593
- return () => {
594
- cleanupFns.forEach(fn => fn && fn());
595
- };
596
- }, [listenToCookieStore]);
597
- React.useEffect(() => {
598
- let listenerId;
599
- if (listenToTcfApi && window.__tcfapi) {
600
- const callback = (_tcData, success) => {
601
- if (success) {
602
- listenerId = _tcData.listenerId;
603
- if (checkOptanonConsentCookie()) {
604
- setConsentCookieExists(true);
605
- }
606
- // tcData.eventStatus can be:
607
- // tcloaded means user has made a choice and we’re ready to check it
608
- // cmpuishown means the banner is shown
609
- // useractioncomplete means the user has interacted with the banner
610
- // but actually if the result for any of these is true, we just use the value of the cookie
611
- if (checkAlertBoxClosedCookie()) {
612
- setAlertBoxClosed(true);
613
- }
614
- }
615
- };
616
- window.__tcfapi('addEventListener', 2, callback);
617
- }
618
- // cleanup fn
619
- return () => {
620
- if (window.__tcfapi && listenerId) window.__tcfapi('removeEventListener', 2, success => {
621
- console.debug(success);
622
- }, listenerId);
623
- };
624
- }, [listenToTcfApi]);
625
- return {
626
- consentCookieExists,
627
- alertBoxClosed,
628
- listenToCookieStore,
629
- listenToTcfApi
630
- };
631
- };
632
-
633
- const DEDisclosureWithBannerStatus = ({
634
- config,
635
- onFinished,
636
- allowCookieStore = true,
637
- onPrivacyPolicyClick = () => {}
638
- }) => {
639
- const [disclosure, setDisclosure] = React.useState(null);
640
- const [disclosureRendering, setDisclosureRendering] = React.useState(null);
641
- const {
642
- alertBoxClosed,
643
- consentCookieExists
644
- } = useOnetrust({
645
- allowCookieStore
646
- });
647
- React.useEffect(() => {
648
- if (config) {
649
- // step 3: set disclosure based on config
650
- if (alertBoxClosed) {
651
- setDisclosure(config.disclosure_afterbanner);
652
- } else {
653
- setDisclosure(config.disclosure_beforebanner);
654
- }
655
- }
656
- }, [alertBoxClosed]);
657
- React.useEffect(() => {
658
- if (disclosure && Array.isArray(disclosure)) {
659
- setDisclosureRendering(disclosure.reduce((prev, current) => React.createElement(React.Fragment, null, prev, React.createElement("p", null, hydrateLinks(current, onPrivacyPolicyClick))), React.createElement(React.Fragment, null)));
660
- }
661
- }, [disclosure]);
662
- React.useEffect(() => {
663
- if (disclosureRendering && consentCookieExists) {
664
- onFinished({
665
- isFinished: true,
666
- isError: false
667
- });
668
- }
669
- }, [disclosureRendering, consentCookieExists]);
670
- return disclosureRendering;
671
- };
672
-
673
- const DEDisclosureWithoutBannerStatus = ({
674
- config,
675
- onFinished,
676
- onPrivacyPolicyClick = () => {}
677
- }) => {
678
- const [disclosure, setDisclosure] = React.useState(null);
679
- const [disclosureRendering, setDisclosureRendering] = React.useState(null);
680
- React.useEffect(() => {
681
- if (config) {
682
- setDisclosure(config.disclosure);
683
- }
684
- }, [config]);
685
- React.useEffect(() => {
686
- if (disclosure && Array.isArray(disclosure)) {
687
- setDisclosureRendering(disclosure.reduce((prev, current) => React.createElement(React.Fragment, null, prev, React.createElement("p", null, hydrateLinks(current, onPrivacyPolicyClick))), React.createElement(React.Fragment, null)));
688
- }
689
- }, [disclosure]);
690
- React.useEffect(() => {
691
- if (disclosureRendering) {
692
- onFinished({
693
- isFinished: true,
694
- isError: false
695
- });
696
- }
697
- }, [disclosureRendering]);
698
- return disclosureRendering;
699
- };
700
-
701
- const DEDisclosure = ({
702
- onFinished = () => {},
703
- allowCookieStore = true,
704
- onPrivacyPolicyClick = _e => {}
705
- }) => {
706
- const [disclosureRendering, setDisclosureRendering] = React.useState(null);
707
- const [myConfig, setMyConfig] = React.useState();
708
- // const { alertBoxClosed } = useOneTrustAlertBoxClosed({ allowCookieStore });
709
- React.useEffect(() => {
710
- (async () => {
711
- const config = await getConfig();
712
- setMyConfig(config);
713
- if (!config) {
714
- console.error('No config found');
715
- }
716
- })();
717
- }, []);
718
- React.useEffect(() => {
719
- if (myConfig) {
720
- // step 3: set disclosure based on config
721
- // if config says to check onetrust, check onetrust
722
- if ('checkBannerStatus' in myConfig && myConfig.checkBannerStatus) {
723
- // check if onetrust is closed
724
- // if it is, show the after banner disclosure
725
- // if it is not, show the before banner disclosure
726
- setDisclosureRendering(React.createElement(DEDisclosureWithBannerStatus, {
727
- config: myConfig,
728
- allowCookieStore: allowCookieStore,
729
- onFinished: onFinished,
730
- onPrivacyPolicyClick: onPrivacyPolicyClick
731
- }));
732
- } else if ('disclosure' in myConfig) {
733
- setDisclosureRendering(React.createElement(DEDisclosureWithoutBannerStatus, {
734
- config: myConfig,
735
- onFinished: onFinished,
736
- onPrivacyPolicyClick: onPrivacyPolicyClick
737
- }));
738
- } else {
739
- console.error('Invalid config');
740
- }
741
- }
742
- }, [myConfig]);
743
- if (disclosureRendering) {
744
- return React.createElement("div", {
745
- "data-test-id": "de-disclosure"
746
- }, disclosureRendering);
747
- }
748
- return React.createElement("div", {
749
- "data-test-id": "de-disclosure-loading"
750
- });
751
- };
752
-
753
- const FirstPartyIngestDataTypes = {
754
- JOB_LEVEL: 'profile_job_level',
755
- JOB_INDUSTRY: 'profile_job_industry',
756
- JOB_TITLE: 'profile_job_title',
757
- PERSONAL_GOALS: 'personal_goals',
758
- HOBBIES: 'hobbies',
759
- PROFESSIONAL_GOALS: 'professional_goals',
760
- INDUSTRY: 'industry',
761
- NEWS_LOCATION: 'news_location',
762
- NY_PERSONAL_GOALS: 'new_year_personal_goals',
763
- NY_HOBBIES: 'new_year_hobbies',
764
- NY_PROFESSIONAL_GOALS: 'new_year_professional_goals',
765
- NY_INDUSTRY: 'new_year_industry',
766
- NY_NEWS_LOCATION: 'new_year_news_location',
767
- EDU_ROLE: 'profile_edu_role',
768
- EDU_MAJOR: 'profile_edu_major',
769
- EDU_GRADUATION_YEAR: 'profile_edu_graduation_year'
770
- };
771
-
772
- exports.AttributesState = AttributesState;
773
- exports.CollectionBehaviors = CollectionBehaviors;
774
- exports.DEDisclosure = DEDisclosure;
775
- exports.DESelect = DESelect;
776
- exports.DeleteAttributeState = DeleteAttributeState;
777
- exports.FirstPartyIngestDataTypes = FirstPartyIngestDataTypes;
778
- exports.IngestResponseState = IngestResponseState;
779
- exports.IngestType = IngestType;
780
- exports.getAttributes = getAttributes;
781
- exports.hasRequiredPrivacyCookies = hasRequiredPrivacyCookies;
782
- exports.push = push;
783
- //# sourceMappingURL=subs-de-inputs.cjs.development.js.map