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