@washingtonpost/subs-de-inputs 0.2.3-canary.0 → 0.3.1-canary.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.
- package/dist/components/DESelect/Dropdown.d.ts +16 -0
- package/dist/index.d.ts +2 -1
- package/dist/interfaces/twpdeu.d.ts +3 -2
- package/dist/services/getAttributes.d.ts +6 -0
- package/dist/services/{dataEnrichment.d.ts → ingest.d.ts} +1 -5
- package/dist/services/push.d.ts +15 -0
- package/dist/services/sendToGA.d.ts +19 -0
- package/dist/subs-de-inputs.cjs.development.js +225 -47
- package/dist/subs-de-inputs.cjs.development.js.map +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js +1 -1
- package/dist/subs-de-inputs.cjs.production.min.js.map +1 -1
- package/dist/subs-de-inputs.esm.js +227 -49
- package/dist/subs-de-inputs.esm.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface IDropdownProps {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
values: Array<string>;
|
|
5
|
+
required?: boolean;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
onChange?: (value: string) => void;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
|
|
12
|
+
* @param {IDropdownProps} props The props.
|
|
13
|
+
* @returns {React.ReactElement} The dropdown.
|
|
14
|
+
*/
|
|
15
|
+
export declare const Dropdown: ({ id, label, values, required, defaultValue, onChange, disabled, }: IDropdownProps) => JSX.Element;
|
|
16
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './interfaces/index';
|
|
2
2
|
export * from './interfaces/twpdeu';
|
|
3
3
|
export * from './utils/hasRequiredPrivacyCookies';
|
|
4
|
-
export * from './services/
|
|
4
|
+
export * from './services/getAttributes';
|
|
5
|
+
export * from './services/push';
|
|
5
6
|
export * from './components/DESelect';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { getAttributes
|
|
1
|
+
import { getAttributes } from '../services/getAttributes';
|
|
2
|
+
import { push } from '../services/push';
|
|
2
3
|
export declare type TWPDEU = {
|
|
3
4
|
getFieldConfigs: typeof getAttributes;
|
|
4
|
-
push: typeof
|
|
5
|
+
push: typeof push;
|
|
5
6
|
version?: string;
|
|
6
7
|
};
|
|
7
8
|
declare global {
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { ResponseStatus } from '@washingtonpost/subs-sdk';
|
|
2
|
-
import {
|
|
3
|
-
export declare const getAttributes: GetAttributesType;
|
|
4
|
-
declare type GetAttributesType = ({ fieldName, }: {
|
|
5
|
-
fieldName: string;
|
|
6
|
-
}) => Promise<Attribute[]>;
|
|
2
|
+
import { IngestResponseState, IngestType } from '../interfaces';
|
|
7
3
|
export declare const ingest: IngestType;
|
|
8
4
|
declare type IngestType = ({ submitData: { fieldName, value }, source, }: {
|
|
9
5
|
submitData: {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IngestResponseState, IngestType } from '../interfaces';
|
|
2
|
+
import { ResponseStatus } from '@washingtonpost/subs-sdk';
|
|
3
|
+
export declare const push: PushType;
|
|
4
|
+
declare type PushType = ({ submitData: { fieldName, value }, source, }: {
|
|
5
|
+
submitData: {
|
|
6
|
+
fieldName: string;
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
type?: (typeof IngestType)[keyof typeof IngestType];
|
|
10
|
+
source: string;
|
|
11
|
+
}) => Promise<{
|
|
12
|
+
status: ResponseStatus;
|
|
13
|
+
state: (typeof IngestResponseState)[keyof typeof IngestResponseState];
|
|
14
|
+
} | null | true>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IngestType } from '../interfaces';
|
|
2
|
+
export interface ISendGAEvent {
|
|
3
|
+
event: string;
|
|
4
|
+
category: string;
|
|
5
|
+
action: string;
|
|
6
|
+
label: string;
|
|
7
|
+
'de-label': string;
|
|
8
|
+
[key: string]: undefined | string | string[];
|
|
9
|
+
}
|
|
10
|
+
export declare const sendToGA: SendToGaType;
|
|
11
|
+
declare type SendToGaType = ({ submitData: { fieldName, value }, source, }: {
|
|
12
|
+
submitData: {
|
|
13
|
+
fieldName: string;
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
type?: (typeof IngestType)[keyof typeof IngestType];
|
|
17
|
+
source: string;
|
|
18
|
+
}) => Promise<true>;
|
|
19
|
+
export {};
|
|
@@ -9,6 +9,7 @@ var React = require('react');
|
|
|
9
9
|
var React__default = _interopDefault(React);
|
|
10
10
|
var wpdsUiKit = require('@washingtonpost/wpds-ui-kit');
|
|
11
11
|
var subsHooks = require('@washingtonpost/subs-hooks');
|
|
12
|
+
var wpdsAssets = require('@washingtonpost/wpds-assets');
|
|
12
13
|
|
|
13
14
|
const CollectionBehaviors = {
|
|
14
15
|
COLLECT: 'COLLECT',
|
|
@@ -45,26 +46,19 @@ const hasRequiredPrivacyCookies = () => {
|
|
|
45
46
|
return !!(wp_usp && countryCode === 'US');
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
const DEBUG_FLAG = 'f_de_debug';
|
|
49
49
|
const base = `${subsSdk.ENDPOINTS.base}/de/v1`;
|
|
50
50
|
const attributesCache = {};
|
|
51
51
|
const getAttributes = async _ref => {
|
|
52
52
|
let {
|
|
53
53
|
fieldName
|
|
54
54
|
} = _ref;
|
|
55
|
-
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
56
|
-
if (debug) {
|
|
57
|
-
console.debug('getAttributes()');
|
|
58
|
-
}
|
|
59
55
|
if (attributesCache[fieldName]) {
|
|
60
|
-
if (debug) console.debug('getAttributes() > return cached info');
|
|
61
56
|
return attributesCache[fieldName];
|
|
62
57
|
}
|
|
63
58
|
const fieldNames = [fieldName];
|
|
64
59
|
try {
|
|
65
60
|
const url = new URL(`${base}/attributes`);
|
|
66
61
|
url.searchParams.set('attributes', fieldNames.join(','));
|
|
67
|
-
if (debug) console.debug(`getAttributes() > ${url.toString()}`);
|
|
68
62
|
const data = await fetch(url.toString(), {
|
|
69
63
|
credentials: 'include',
|
|
70
64
|
headers: subsSdk.JSON_HEADERS
|
|
@@ -82,7 +76,42 @@ const getAttributes = async _ref => {
|
|
|
82
76
|
return [];
|
|
83
77
|
}
|
|
84
78
|
};
|
|
85
|
-
|
|
79
|
+
|
|
80
|
+
const sendGAEvent = props => {
|
|
81
|
+
if (typeof window === 'undefined') {
|
|
82
|
+
if (process.env.NODE_ENV !== "production") console.warn('NO WINDOW');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Initialize dataLayer if needed
|
|
86
|
+
window.dataLayer = window.dataLayer || [];
|
|
87
|
+
const eventData = {
|
|
88
|
+
...props
|
|
89
|
+
};
|
|
90
|
+
window.dataLayer.push(eventData);
|
|
91
|
+
};
|
|
92
|
+
const sendToGA = async _ref => {
|
|
93
|
+
let {
|
|
94
|
+
submitData: {
|
|
95
|
+
fieldName,
|
|
96
|
+
value
|
|
97
|
+
},
|
|
98
|
+
source
|
|
99
|
+
} = _ref;
|
|
100
|
+
sendGAEvent({
|
|
101
|
+
event: 'site-onpage-click',
|
|
102
|
+
action: 'site-onpage-click',
|
|
103
|
+
category: 'profile',
|
|
104
|
+
label: fieldName,
|
|
105
|
+
'de-label': fieldName,
|
|
106
|
+
[fieldName]: value,
|
|
107
|
+
section: 'profile',
|
|
108
|
+
subsection: source
|
|
109
|
+
});
|
|
110
|
+
return true;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const base$1 = `${subsSdk.ENDPOINTS.base}/de/v1`;
|
|
114
|
+
const ingest = async _ref => {
|
|
86
115
|
let {
|
|
87
116
|
submitData: {
|
|
88
117
|
fieldName,
|
|
@@ -90,30 +119,9 @@ const ingest = async _ref2 => {
|
|
|
90
119
|
},
|
|
91
120
|
type = IngestType.IMPLICIT,
|
|
92
121
|
source
|
|
93
|
-
} =
|
|
94
|
-
const
|
|
95
|
-
if (debug) {
|
|
96
|
-
console.debug('ingest()');
|
|
97
|
-
}
|
|
98
|
-
const url = `${base}/ingest`;
|
|
122
|
+
} = _ref;
|
|
123
|
+
const url = `${base$1}/ingest`;
|
|
99
124
|
const wapo_login_id = subsSdk.getCookie('wapo_login_id');
|
|
100
|
-
if (!hasRequiredPrivacyCookies()) {
|
|
101
|
-
if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');
|
|
102
|
-
throw new Error('does not satisfy cookie check');
|
|
103
|
-
}
|
|
104
|
-
let attributeInfo = attributesCache[fieldName];
|
|
105
|
-
if (!attributeInfo) {
|
|
106
|
-
if (debug) console.debug('ingest() > fetch attribute info');
|
|
107
|
-
attributeInfo = await getAttributes({
|
|
108
|
-
fieldName
|
|
109
|
-
});
|
|
110
|
-
} else {
|
|
111
|
-
if (debug) console.debug('ingest() > use cached attribute info');
|
|
112
|
-
}
|
|
113
|
-
if (attributeInfo[0] && attributeInfo[0].name === fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
|
|
114
|
-
if (debug) console.debug('ingest() > do not collect');
|
|
115
|
-
throw new Error('do not collect');
|
|
116
|
-
}
|
|
117
125
|
const jucid = localStorage.getItem('uuid');
|
|
118
126
|
const ga = subsSdk.getCookie('_ga');
|
|
119
127
|
const payload = {
|
|
@@ -143,6 +151,171 @@ const ingest = async _ref2 => {
|
|
|
143
151
|
}
|
|
144
152
|
};
|
|
145
153
|
|
|
154
|
+
const push = async _ref => {
|
|
155
|
+
let {
|
|
156
|
+
submitData,
|
|
157
|
+
type = IngestType.IMPLICIT,
|
|
158
|
+
source
|
|
159
|
+
} = _ref;
|
|
160
|
+
if (!hasRequiredPrivacyCookies()) {
|
|
161
|
+
throw new Error('does not satisfy cookie check');
|
|
162
|
+
}
|
|
163
|
+
const attributeInfo = await getAttributes({
|
|
164
|
+
fieldName: submitData.fieldName
|
|
165
|
+
});
|
|
166
|
+
if (attributeInfo[0] && attributeInfo[0].name === submitData.fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
|
|
167
|
+
throw new Error('do not collect');
|
|
168
|
+
}
|
|
169
|
+
if (type === IngestType.EXPLICIT) {
|
|
170
|
+
return ingest({
|
|
171
|
+
submitData,
|
|
172
|
+
type,
|
|
173
|
+
source
|
|
174
|
+
});
|
|
175
|
+
} else {
|
|
176
|
+
// One reason we wanted to send everything through GA is to honor region/consent status
|
|
177
|
+
// GA will send to ingest so you don’t need to send separately
|
|
178
|
+
return sendToGA({
|
|
179
|
+
submitData,
|
|
180
|
+
type,
|
|
181
|
+
source
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const StyledMobileSelect = /*#__PURE__*/wpdsUiKit.styled('select', {
|
|
187
|
+
padding: '12px 16px 12px 6px',
|
|
188
|
+
display: 'flex',
|
|
189
|
+
justifyContent: 'space-between',
|
|
190
|
+
width: '100%',
|
|
191
|
+
backgroundColor: '$secondary',
|
|
192
|
+
color: '$primary',
|
|
193
|
+
fontFamily: '$meta',
|
|
194
|
+
fontSize: '$100',
|
|
195
|
+
fontWeight: '$light',
|
|
196
|
+
lineHeight: '$125',
|
|
197
|
+
paddingBlockRight: '$125',
|
|
198
|
+
textOverflow: 'ellipsis',
|
|
199
|
+
position: 'relative',
|
|
200
|
+
borderColor: 'transparent',
|
|
201
|
+
borderRightWidth: '10px',
|
|
202
|
+
borderRightColor: 'transparent',
|
|
203
|
+
appearance: 'none',
|
|
204
|
+
'-webkit-appearance': 'none',
|
|
205
|
+
'&:disabled': {
|
|
206
|
+
backgroundColor: wpdsUiKit.theme.colors.disabled,
|
|
207
|
+
borderColor: wpdsUiKit.theme.colors.disabled,
|
|
208
|
+
color: wpdsUiKit.theme.colors.onDisabled,
|
|
209
|
+
cursor: 'not-allowed'
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
const StyledSelectWrapper = /*#__PURE__*/wpdsUiKit.styled('div', {
|
|
213
|
+
width: '100%',
|
|
214
|
+
maxWidth: '380px',
|
|
215
|
+
borderRadius: '$012',
|
|
216
|
+
borderColor: '$subtle',
|
|
217
|
+
borderStyle: 'solid',
|
|
218
|
+
borderWidth: '1px',
|
|
219
|
+
backgroundColor: '$secondary',
|
|
220
|
+
position: 'relative'
|
|
221
|
+
});
|
|
222
|
+
const StyledMobileOption = /*#__PURE__*/wpdsUiKit.styled('option', {
|
|
223
|
+
fontFamily: 'inherit',
|
|
224
|
+
fontSize: 'inherit',
|
|
225
|
+
color: 'inherit'
|
|
226
|
+
});
|
|
227
|
+
/**
|
|
228
|
+
* Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
|
|
229
|
+
* @param {IDropdownProps} props The props.
|
|
230
|
+
* @returns {React.ReactElement} The dropdown.
|
|
231
|
+
*/
|
|
232
|
+
const Dropdown = _ref => {
|
|
233
|
+
let {
|
|
234
|
+
id,
|
|
235
|
+
label,
|
|
236
|
+
values,
|
|
237
|
+
required = false,
|
|
238
|
+
defaultValue,
|
|
239
|
+
onChange = () => {},
|
|
240
|
+
disabled = false
|
|
241
|
+
} = _ref;
|
|
242
|
+
const [answer, setAnswer] = React.useState();
|
|
243
|
+
const {
|
|
244
|
+
isMobileSize
|
|
245
|
+
} = subsHooks.useWindowSize();
|
|
246
|
+
React.useEffect(() => {
|
|
247
|
+
if (answer) onChange(answer);
|
|
248
|
+
}, [answer]);
|
|
249
|
+
const disabledProp = disabled ? {
|
|
250
|
+
disabled: true
|
|
251
|
+
} : {};
|
|
252
|
+
// helps maintain state between WPDS and native dropdowns
|
|
253
|
+
const defaultValueProp = answer ? {
|
|
254
|
+
defaultValue: answer
|
|
255
|
+
} : defaultValue ? {
|
|
256
|
+
defaultValue
|
|
257
|
+
} : {};
|
|
258
|
+
const defaultValuePropMobile = value => {
|
|
259
|
+
if (answer) {
|
|
260
|
+
return value === answer ? {
|
|
261
|
+
selected: true
|
|
262
|
+
} : {};
|
|
263
|
+
}
|
|
264
|
+
return value === defaultValue ? {
|
|
265
|
+
selected: true
|
|
266
|
+
} : {};
|
|
267
|
+
};
|
|
268
|
+
return isMobileSize ? React__default.createElement(StyledSelectWrapper, null, React__default.createElement(StyledMobileSelect, {
|
|
269
|
+
id: "",
|
|
270
|
+
required: required,
|
|
271
|
+
onChange: e => setAnswer(e.target.value),
|
|
272
|
+
placeholder: label,
|
|
273
|
+
...disabledProp
|
|
274
|
+
}, React__default.createElement("label", null, label), React__default.createElement(StyledMobileOption, {
|
|
275
|
+
value: "",
|
|
276
|
+
disabled: true,
|
|
277
|
+
selected: true,
|
|
278
|
+
style: {
|
|
279
|
+
color: '#666666'
|
|
280
|
+
}
|
|
281
|
+
}, label), values.map(value => React__default.createElement(StyledMobileOption, {
|
|
282
|
+
value: value,
|
|
283
|
+
key: value,
|
|
284
|
+
...defaultValuePropMobile(value)
|
|
285
|
+
}, value))), React__default.createElement(wpdsUiKit.Icon, {
|
|
286
|
+
label: "",
|
|
287
|
+
size: "100",
|
|
288
|
+
fill: wpdsUiKit.theme.colors['gray80'],
|
|
289
|
+
style: {
|
|
290
|
+
pointerEvents: 'none',
|
|
291
|
+
position: 'absolute',
|
|
292
|
+
right: '10px',
|
|
293
|
+
top: '50%',
|
|
294
|
+
transform: 'translateY(-50%)'
|
|
295
|
+
}
|
|
296
|
+
}, React__default.createElement(wpdsAssets.ChevronDown, {
|
|
297
|
+
style: {
|
|
298
|
+
position: 'absolute',
|
|
299
|
+
right: '10px'
|
|
300
|
+
}
|
|
301
|
+
}))) : React__default.createElement(wpdsUiKit.Select.Root, {
|
|
302
|
+
onValueChange: e => setAnswer(e),
|
|
303
|
+
required: required,
|
|
304
|
+
...defaultValueProp,
|
|
305
|
+
...disabledProp
|
|
306
|
+
}, React__default.createElement(wpdsUiKit.Select.Trigger, {
|
|
307
|
+
"data-test-id": `${id}-select-trigger`
|
|
308
|
+
}, React__default.createElement(wpdsUiKit.Select.Label, null, label), React__default.createElement(wpdsUiKit.Select.Value, null)), React__default.createElement(wpdsUiKit.Select.Content, {
|
|
309
|
+
css: {
|
|
310
|
+
zIndex: wpdsUiKit.theme.zIndices.page
|
|
311
|
+
},
|
|
312
|
+
"data-test-id": `${id}-select-content`
|
|
313
|
+
}, values.map(value => React__default.createElement(wpdsUiKit.Select.Item, {
|
|
314
|
+
value: value,
|
|
315
|
+
key: value
|
|
316
|
+
}, value))));
|
|
317
|
+
};
|
|
318
|
+
|
|
146
319
|
const scriptSrc = `${subsSdk.ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static' ? 'https://www.washingtonpost.com/subscribe/static/' : subsSdk.ENDPOINTS.staticAssets}/de-utils/twpdeu.min.js`;
|
|
147
320
|
const DESelect = _ref => {
|
|
148
321
|
let {
|
|
@@ -194,7 +367,7 @@ const DESelect = _ref => {
|
|
|
194
367
|
type: config !== null && config !== void 0 && config.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,
|
|
195
368
|
source
|
|
196
369
|
}));
|
|
197
|
-
const isError = result ? result.status !== subsSdk.ResponseStatus.SUCCESS : true;
|
|
370
|
+
const isError = result === true ? false : result ? result.status !== subsSdk.ResponseStatus.SUCCESS : true;
|
|
198
371
|
onFinished({
|
|
199
372
|
isFinished: true,
|
|
200
373
|
isError
|
|
@@ -219,28 +392,33 @@ const DESelect = _ref => {
|
|
|
219
392
|
} : {};
|
|
220
393
|
// sort and filter out archived values
|
|
221
394
|
const values = config ? config.values.sort((a, b) => a.order - b.order).filter(value => value.archived !== true).filter(valuesFilter) : [];
|
|
222
|
-
return React__default.createElement(SelectWrapper, null, React__default.createElement(wpdsUiKit.Select.Root, {
|
|
395
|
+
return React__default.createElement(SelectWrapper, null, children && React__default.createElement(wpdsUiKit.Select.Root, {
|
|
223
396
|
onValueChange: e => {
|
|
397
|
+
setSelected(e);
|
|
224
398
|
onChange({
|
|
225
399
|
value: e
|
|
226
400
|
});
|
|
227
|
-
setSelected(e);
|
|
228
401
|
},
|
|
229
402
|
...defaultValueProp,
|
|
230
403
|
...disabledProp
|
|
231
|
-
}, children
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
404
|
+
}, children), !children && !config && React__default.createElement(Dropdown, {
|
|
405
|
+
id: 'loading',
|
|
406
|
+
label: 'Loading...',
|
|
407
|
+
values: [],
|
|
408
|
+
disabled: true
|
|
409
|
+
}), !children && config && React__default.createElement(Dropdown, {
|
|
410
|
+
id: config.name,
|
|
411
|
+
label: label || config.name,
|
|
412
|
+
onChange: e => {
|
|
413
|
+
setSelected(e);
|
|
414
|
+
onChange({
|
|
415
|
+
value: e
|
|
416
|
+
});
|
|
238
417
|
},
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}, value.name))))));
|
|
418
|
+
values: values.map(value => value.name),
|
|
419
|
+
defaultValue: defaultValue,
|
|
420
|
+
disabled: disabled
|
|
421
|
+
}));
|
|
244
422
|
};
|
|
245
423
|
const SelectWrapper = /*#__PURE__*/wpdsUiKit.styled('div', {
|
|
246
424
|
boxSizing: 'border-box',
|
|
@@ -262,5 +440,5 @@ exports.IngestResponseState = IngestResponseState;
|
|
|
262
440
|
exports.IngestType = IngestType;
|
|
263
441
|
exports.getAttributes = getAttributes;
|
|
264
442
|
exports.hasRequiredPrivacyCookies = hasRequiredPrivacyCookies;
|
|
265
|
-
exports.
|
|
443
|
+
exports.push = push;
|
|
266
444
|
//# sourceMappingURL=subs-de-inputs.cjs.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subs-de-inputs.cjs.development.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst DEBUG_FLAG = 'f_de_debug';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('getAttributes()');\n }\n\n if (attributesCache[fieldName]) {\n if (debug) console.debug('getAttributes() > return cached info');\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n if (debug) console.debug(`getAttributes() > ${url.toString()}`);\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('ingest()');\n }\n\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n if (debug) console.debug('ingest() > fetch attribute info');\n attributeInfo = await getAttributes({ fieldName });\n } else {\n if (debug) console.debug('ingest() > use cached attribute info');\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n if (debug) console.debug('ingest() > do not collect');\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && !config && (\n <>\n <Select.Trigger data-test-id={`select-trigger-loading`}>\n <Select.Label>{label || 'loading...'}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n </>\n )}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","DEBUG_FLAG","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","debug","location","search","includes","console","fieldNames","url","URL","searchParams","set","join","toString","data","fetch","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","ingest","_ref2","submitData","value","type","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","scriptSrc","staticAssets","DESelect","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","scriptStatus","useScript","useEffect","fetchConfig","_window","__twpdeu","getFieldConfigs","error","warn","ScriptStatus","READY","submitSelected","_window2","result","push","explicit","isError","isFinished","defaultValueProp","isLoading","disabledProp","values","sort","a","b","order","filter","archived","React","SelectWrapper","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","theme","zIndices","page","map","Item","key","styled","boxSizing","display","marginBottom","flexDirection","padding"],"mappings":";;;;;;;;;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAAU,GAAG;EACxBC,QAAQ,EAAE,UAAU;EACpBC,QAAQ,EAAE;;MAGCC,mBAAmB,GAAG;EACjCJ,OAAO,EAAE,KAAK;EACdK,YAAY,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ACW,CACA;AAEpB,CAAC;AAED,MAAM2D,aAAa,gBAAGgB,gBAAM,CAAC,KAAK,EAAE;EAClCC,SAAS,EAAE,YAAY;EACvBC,OAAO,EAAE,MAAM;EACfC,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACVC,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAEJ,SAAS,EAAE;;CACrB,CAAC;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"subs-de-inputs.cjs.development.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/getAttributes.ts","../src/services/sendToGA.ts","../src/services/ingest.ts","../src/services/push.ts","../src/components/DESelect/Dropdown.tsx","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n} from '@washingtonpost/subs-sdk';\nimport { Attribute } from '../interfaces';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n","import { IngestType } from '../interfaces';\n\nexport interface ISendGAEvent {\n event: string;\n category: string;\n action: string;\n label: string;\n 'de-label': string;\n [key: string]: undefined | string | string[];\n}\n\nconst sendGAEvent = (props: ISendGAEvent): void => {\n if (typeof window === 'undefined') {\n if (__DEV__) console.warn('NO WINDOW');\n return;\n }\n // Initialize dataLayer if needed\n window.dataLayer = window.dataLayer || [];\n\n const eventData: Record<string, any> = {\n ...props,\n };\n window.dataLayer.push(eventData);\n};\n\nexport const sendToGA: SendToGaType = async ({\n submitData: { fieldName, value },\n source,\n}) => {\n sendGAEvent({\n event: 'site-onpage-click',\n action: 'site-onpage-click',\n category: 'profile',\n\n label: fieldName,\n 'de-label': fieldName,\n [fieldName]: value,\n\n section: 'profile',\n subsection: source,\n });\n\n return true;\n};\n\ntype SendToGaType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<true>;\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n IngestResponseState,\n IngestType,\n} from '../interfaces';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import {\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { getAttributes } from './getAttributes';\nimport { sendToGA } from './sendToGA';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\nimport { ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { ingest } from './ingest';\n\nexport const push: PushType = async ({\n submitData,\n type = IngestType.IMPLICIT,\n source,\n}) => {\n if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n const attributeInfo = await getAttributes({\n fieldName: submitData.fieldName,\n });\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === submitData.fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n throw new Error('do not collect');\n }\n\n if (type === IngestType.EXPLICIT) {\n return ingest({ submitData, type, source });\n } else {\n // One reason we wanted to send everything through GA is to honor region/consent status\n // GA will send to ingest so you don’t need to send separately\n return sendToGA({ submitData, type, source });\n }\n};\n\ntype PushType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<\n | {\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n }\n | null\n | true\n>;\n","import React, { useEffect, useState } from 'react';\nimport { Icon, Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { useWindowSize } from '@washingtonpost/subs-hooks';\nimport { ChevronDown } from '@washingtonpost/wpds-assets';\n\ninterface IDropdownProps {\n id: string;\n label: string;\n values: Array<string>;\n required?: boolean;\n defaultValue?: string;\n onChange?: (value: string) => void;\n disabled?: boolean;\n}\n\nconst StyledMobileSelect = styled('select', {\n padding: '12px 16px 12px 6px',\n display: 'flex',\n justifyContent: 'space-between',\n width: '100%',\n backgroundColor: '$secondary',\n color: '$primary',\n fontFamily: '$meta',\n fontSize: '$100',\n fontWeight: '$light',\n lineHeight: '$125',\n paddingBlockRight: '$125',\n textOverflow: 'ellipsis',\n position: 'relative',\n borderColor: 'transparent',\n borderRightWidth: '10px',\n borderRightColor: 'transparent',\n appearance: 'none',\n '-webkit-appearance': 'none',\n '&:disabled': {\n backgroundColor: theme.colors.disabled,\n borderColor: theme.colors.disabled,\n color: theme.colors.onDisabled,\n cursor: 'not-allowed',\n },\n});\n\nconst StyledSelectWrapper = styled('div', {\n width: '100%',\n maxWidth: '380px',\n borderRadius: '$012',\n borderColor: '$subtle',\n borderStyle: 'solid',\n borderWidth: '1px',\n backgroundColor: '$secondary',\n position: 'relative',\n});\n\nconst StyledMobileOption = styled('option', {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n color: 'inherit',\n});\n\n/**\n * Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.\n * @param {IDropdownProps} props The props.\n * @returns {React.ReactElement} The dropdown.\n */\nexport const Dropdown = ({\n id,\n label,\n values,\n required = false,\n defaultValue,\n onChange = () => {},\n disabled = false,\n}: IDropdownProps) => {\n const [answer, setAnswer] = useState<string>();\n const { isMobileSize } = useWindowSize();\n\n useEffect(() => {\n if (answer) onChange(answer);\n }, [answer]);\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // helps maintain state between WPDS and native dropdowns\n const defaultValueProp = answer\n ? { defaultValue: answer }\n : defaultValue\n ? { defaultValue }\n : {};\n\n const defaultValuePropMobile = (value: string) => {\n if (answer) {\n return value === answer ? { selected: true } : {};\n }\n return value === defaultValue ? { selected: true } : {};\n };\n\n return isMobileSize ? (\n <StyledSelectWrapper>\n <StyledMobileSelect\n id=\"\"\n required={required}\n onChange={(e) => setAnswer(e.target.value)}\n placeholder={label}\n {...disabledProp}\n >\n <label>{label}</label>\n <StyledMobileOption\n value=\"\"\n disabled\n selected\n style={{ color: '#666666' }}\n >\n {label}\n </StyledMobileOption>\n {values.map((value) => (\n <StyledMobileOption\n value={value}\n key={value}\n {...defaultValuePropMobile(value)}\n >\n {value}\n </StyledMobileOption>\n ))}\n </StyledMobileSelect>\n <Icon\n label=\"\"\n size=\"100\"\n fill={theme.colors['gray80']}\n style={{\n pointerEvents: 'none',\n position: 'absolute',\n right: '10px',\n top: '50%',\n transform: 'translateY(-50%)',\n }}\n >\n <ChevronDown style={{ position: 'absolute', right: '10px' }} />\n </Icon>\n </StyledSelectWrapper>\n ) : (\n <Select.Root\n onValueChange={(e) => setAnswer(e)}\n required={required}\n {...defaultValueProp}\n {...disabledProp}\n >\n <Select.Trigger data-test-id={`${id}-select-trigger`}>\n <Select.Label>{label}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${id}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value} key={value}>\n {value}\n </Select.Item>\n ))}\n </Select.Content>\n </Select.Root>\n );\n};\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\nimport { Dropdown } from './Dropdown';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError =\n result === true\n ? false\n : result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n {children && (\n <Select.Root\n onValueChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children}\n </Select.Root>\n )}\n {!children && !config && (\n <Dropdown\n id={'loading'}\n label={'Loading...'}\n values={[]}\n disabled={true}\n />\n )}\n {!children && config && (\n <Dropdown\n id={config.name}\n label={label || config.name}\n onChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n values={values.map((value) => value.name)}\n defaultValue={defaultValue}\n disabled={disabled}\n />\n )}\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","console","debug","sendGAEvent","props","process","env","NODE_ENV","warn","dataLayer","eventData","push","sendToGA","submitData","value","source","event","action","category","label","section","subsection","ingest","type","wapo_login_id","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","Error","attributeInfo","name","collection_behavior","StyledMobileSelect","styled","padding","display","justifyContent","width","backgroundColor","color","fontFamily","fontSize","fontWeight","lineHeight","paddingBlockRight","textOverflow","position","borderColor","borderRightWidth","borderRightColor","appearance","theme","colors","disabled","onDisabled","cursor","StyledSelectWrapper","maxWidth","borderRadius","borderStyle","borderWidth","StyledMobileOption","Dropdown","id","values","required","defaultValue","onChange","answer","setAnswer","useState","isMobileSize","useWindowSize","useEffect","disabledProp","defaultValueProp","defaultValuePropMobile","selected","React","target","placeholder","style","map","key","Icon","size","fill","pointerEvents","right","top","transform","ChevronDown","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","zIndices","page","Item","scriptSrc","staticAssets","DESelect","dataDictionaryConfig","submit","onFinished","valuesFilter","children","config","setConfig","setSelected","scriptStatus","useScript","fetchConfig","_window","__twpdeu","getFieldConfigs","error","ScriptStatus","READY","submitSelected","_window2","result","explicit","isError","isFinished","isLoading","sort","a","b","order","filter","archived","SelectWrapper","boxSizing","marginBottom","flexDirection"],"mappings":";;;;;;;;;;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAA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AQ,CAAC;QAAE7D,KAAK,EAAEd;OAAG,CAAC;KACvB;IACDwE,MAAM,EAAEA,MAAM,CAACkB,GAAG,CAAE5E,KAAK,IAAKA,KAAK,CAACwB,IAAI,CAAC;IACzCoC,YAAY,EAAEA,YAAY;IAC1Bb,QAAQ,EAAEA;IAEb,CACa;AAEpB,CAAC;AAED,MAAMoF,aAAa,gBAAGxG,gBAAM,CAAC,KAAK,EAAE;EAClCyG,SAAS,EAAE,YAAY;EACvBvG,OAAO,EAAE,MAAM;EACfwG,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACV1G,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAEwG,SAAS,EAAE;;CACrB,CAAC;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@washingtonpost/subs-sdk"),o=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@washingtonpost/subs-sdk"),o=require("react"),a=(e=o)&&"object"==typeof e&&"default"in e?e.default:e,i=require("@washingtonpost/wpds-ui-kit"),s=require("@washingtonpost/subs-hooks"),r=require("@washingtonpost/wpds-assets");const n={COLLECT:"COLLECT",DO_NOT_COLLECT:"DO_NOT_COLLECT"},l={EXPLICIT:"explicit",IMPLICIT:"implicit"},d=()=>{var e;if("undefined"==typeof window)return!1;const o=t.getCookie("wp_usp"),a=null===(e=t.WPGeo())||void 0===e?void 0:e.country_code;return!(!o||"US"!==a)},c=t.ENDPOINTS.base+"/de/v1",u={},p=async e=>{let{fieldName:o}=e;if(u[o])return u[o];const a=[o];try{const e=new URL(c+"/attributes");e.searchParams.set("attributes",a.join(","));const i=await fetch(e.toString(),{credentials:"include",headers:t.JSON_HEADERS}),s=await i.json();if(i.ok&&s.status===t.ResponseStatus.SUCCESS){const e=s.attributes||[];return u[o]=e,e}return[]}catch(e){return console.debug(e),[]}},b=t.ENDPOINTS.base+"/de/v1",E=i.styled("select",{padding:"12px 16px 12px 6px",display:"flex",justifyContent:"space-between",width:"100%",backgroundColor:"$secondary",color:"$primary",fontFamily:"$meta",fontSize:"$100",fontWeight:"$light",lineHeight:"$125",paddingBlockRight:"$125",textOverflow:"ellipsis",position:"relative",borderColor:"transparent",borderRightWidth:"10px",borderRightColor:"transparent",appearance:"none","-webkit-appearance":"none","&:disabled":{backgroundColor:i.theme.colors.disabled,borderColor:i.theme.colors.disabled,color:i.theme.colors.onDisabled,cursor:"not-allowed"}}),g=i.styled("div",{width:"100%",maxWidth:"380px",borderRadius:"$012",borderColor:"$subtle",borderStyle:"solid",borderWidth:"1px",backgroundColor:"$secondary",position:"relative"}),m=i.styled("option",{fontFamily:"inherit",fontSize:"inherit",color:"inherit"}),h=e=>{let{id:t,label:n,values:l,required:d=!1,defaultValue:c,onChange:u=(()=>{}),disabled:p=!1}=e;const[b,h]=o.useState(),{isMobileSize:I}=s.useWindowSize();o.useEffect(()=>{b&&u(b)},[b]);const f=p?{disabled:!0}:{},S=b?{defaultValue:b}:c?{defaultValue:c}:{},w=e=>b?e===b?{selected:!0}:{}:e===c?{selected:!0}:{};return I?a.createElement(g,null,a.createElement(E,{id:"",required:d,onChange:e=>h(e.target.value),placeholder:n,...f},a.createElement("label",null,n),a.createElement(m,{value:"",disabled:!0,selected:!0,style:{color:"#666666"}},n),l.map(e=>a.createElement(m,{value:e,key:e,...w(e)},e))),a.createElement(i.Icon,{label:"",size:"100",fill:i.theme.colors.gray80,style:{pointerEvents:"none",position:"absolute",right:"10px",top:"50%",transform:"translateY(-50%)"}},a.createElement(r.ChevronDown,{style:{position:"absolute",right:"10px"}}))):a.createElement(i.Select.Root,{onValueChange:e=>h(e),required:d,...S,...f},a.createElement(i.Select.Trigger,{"data-test-id":t+"-select-trigger"},a.createElement(i.Select.Label,null,n),a.createElement(i.Select.Value,null)),a.createElement(i.Select.Content,{css:{zIndex:i.theme.zIndices.page},"data-test-id":t+"-select-content"},l.map(e=>a.createElement(i.Select.Item,{value:e,key:e},e))))},I=("https://subscribe.washingtonpost.com/static"===t.ENDPOINTS.staticAssets?"https://www.washingtonpost.com/subscribe/static/":t.ENDPOINTS.staticAssets)+"/de-utils/twpdeu.min.js",f=i.styled("div",{boxSizing:"border-box",display:"flex",marginBottom:"$100",flexDirection:"column","& button":{padding:"1px 6px"},"& *":{boxSizing:"border-box"}});exports.AttributesState={SUCCESS:"100"},exports.CollectionBehaviors=n,exports.DESelect=e=>{let{source:r,fieldName:n,label:d,dataDictionaryConfig:c,defaultValue:u,disabled:p,submit:b,onChange:E=(()=>{}),onFinished:g=(()=>{}),valuesFilter:m=(()=>!0),children:S}=e;const[w,C]=o.useState(c),[y,v]=o.useState(""),N=s.useScript(I);o.useEffect(()=>{N!==s.ScriptStatus.READY||S||w||(async()=>{try{var e;const t=await(null===(e=window)||void 0===e||null===(e=e.__twpdeu)||void 0===e?void 0:e.getFieldConfigs({fieldName:n}));t?C(t[0]):console.error("unable to get config",n)}catch(e){console.warn("unable to get config",n,e)}})()},[N]),o.useEffect(()=>{N===s.ScriptStatus.READY&&b&&y&&(async()=>{try{var e;const o=await(null===(e=window)||void 0===e||null===(e=e.__twpdeu)||void 0===e?void 0:e.push({submitData:{fieldName:n,value:y},type:null!=w&&w.explicit?l.EXPLICIT:l.IMPLICIT,source:r}));g({isFinished:!0,isError:!0!==o&&(!o||o.status!==t.ResponseStatus.SUCCESS)})}catch(e){g({isFinished:!1,isError:!0})}})()},[N,b]);const T=u&&w?{defaultValue:u}:{},D=p||!S&&!w?{disabled:!0}:{},_=w?w.values.sort((e,t)=>e.order-t.order).filter(e=>!0!==e.archived).filter(m):[];return a.createElement(f,null,S&&a.createElement(i.Select.Root,{onValueChange:e=>{v(e),E({value:e})},...T,...D},S),!S&&!w&&a.createElement(h,{id:"loading",label:"Loading...",values:[],disabled:!0}),!S&&w&&a.createElement(h,{id:w.name,label:d||w.name,onChange:e=>{v(e),E({value:e})},values:_.map(e=>e.name),defaultValue:u,disabled:p}))},exports.IngestResponseState={SUCCESS:"100",SYSTEM_ERROR:"101",INVALID_TYPE:"102",INVALID_IDENTIFIER:"103",INVALID_DATA:"104",INVALID_ATTRIBUTE_DEFINITION:"105",INVALID_META_DEFINITION:"106",UNAUTHENTICATED:"107",MISMATCHED_IDENTIFIER:"108",DISABLED_ATTRIBUTE_DEFINITION:"109",DO_NOT_COLLECT:"110"},exports.IngestType=l,exports.getAttributes=p,exports.hasRequiredPrivacyCookies=d,exports.push=async e=>{let{submitData:o,type:a=l.IMPLICIT,source:i}=e;if(!d())throw new Error("does not satisfy cookie check");const s=await p({fieldName:o.fieldName});if(s[0]&&s[0].name===o.fieldName&&s[0].collection_behavior===n.DO_NOT_COLLECT)throw new Error("do not collect");return a===l.EXPLICIT?(async e=>{let{submitData:{fieldName:o,value:a},type:i=l.IMPLICIT,source:s}=e;const r=b+"/ingest",n=t.getCookie("wapo_login_id"),d={jucid:localStorage.getItem("uuid"),ga:t.getCookie("_ga"),type:i,wapo_login_id:n,data:{[o]:[a]},metadata:{source:s}};try{const e=await fetch(r,{method:"POST",credentials:"include",headers:t.JSON_HEADERS,body:JSON.stringify(d)});return await e.json()}catch(e){return console.debug(e),null}})({submitData:o,type:a,source:i}):(async e=>{let{submitData:{fieldName:t,value:o},source:a}=e;return(e=>{if("undefined"==typeof window)return void("production"!==process.env.NODE_ENV&&console.warn("NO WINDOW"));window.dataLayer=window.dataLayer||[];const t={...e};window.dataLayer.push(t)})({event:"site-onpage-click",action:"site-onpage-click",category:"profile",label:t,"de-label":t,[t]:o,section:"profile",subsection:a}),!0})({submitData:o,type:a,source:i})};
|
|
2
2
|
//# sourceMappingURL=subs-de-inputs.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subs-de-inputs.cjs.production.min.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst DEBUG_FLAG = 'f_de_debug';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('getAttributes()');\n }\n\n if (attributesCache[fieldName]) {\n if (debug) console.debug('getAttributes() > return cached info');\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n if (debug) console.debug(`getAttributes() > ${url.toString()}`);\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('ingest()');\n }\n\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n if (debug) console.debug('ingest() > fetch attribute info');\n attributeInfo = await getAttributes({ fieldName });\n } else {\n if (debug) console.debug('ingest() > use cached attribute info');\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n if (debug) console.debug('ingest() > do not collect');\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && !config && (\n <>\n <Select.Trigger data-test-id={`select-trigger-loading`}>\n <Select.Label>{label || 'loading...'}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n </>\n )}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","IngestType","EXPLICIT","IMPLICIT","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","async","fieldName","_ref","debug","location","search","includes","console","fieldNames","url","URL","searchParams","set","join","toString","data","fetch","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","SUCCESS","attributes","e","scriptSrc","staticAssets","SelectWrapper","styled","boxSizing","display","marginBottom","flexDirection","& button","padding","& *","source","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","scriptStatus","useScript","useEffect","ScriptStatus","READY","_window","__twpdeu","getFieldConfigs","error","warn","fetchConfig","_window2","result","push","submitData","value","type","explicit","isFinished","isError","submitSelected","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","React","Select","Root","onValueChange","Trigger","Label","Value","name","Content","css","zIndex","theme","zIndices","page","map","Item","key","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","_ref2","wapo_login_id","Error","attributeInfo","collection_behavior","payload","jucid","localStorage","getItem","ga","[object Object]","metadata","response","method","body","JSON","stringify"],"mappings":"iRAQaA,EAAsB,CACjCC,QAAS,UACTC,eAAgB,kBAmBLC,EAAa,CACxBC,SAAU,WACVC,SAAU,YC7BCC,EAA4BA,WACvC,GAAsB,oBAAXC,OACT,OAAO,EAGT,MAAMC,EAASC,YAAU,UAEnBC,UAAWC,EAA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ACA/F,KAAM,CACJwG,CAACtH,GAAY,CAACmE,IAEhBoD,SAAU,CAAElF,OAAAA,IAGd,IACE,MAAMmF,QAAiBzG,MAAMP,EAAK,CAChCiH,OAAQ,OACRzG,YAAa,UACbC,QAASC,eACTwG,KAAMC,KAAKC,UAAUX,KAKvB,aAFmBO,EAASrG,OAG5B,MAAOM,GAEP,OADAnB,QAAQJ,MAAMuB,GACP"}
|
|
1
|
+
{"version":3,"file":"subs-de-inputs.cjs.production.min.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/getAttributes.ts","../src/services/ingest.ts","../src/components/DESelect/Dropdown.tsx","../src/components/DESelect/index.tsx","../src/services/push.ts","../src/services/sendToGA.ts"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n} from '@washingtonpost/subs-sdk';\nimport { Attribute } from '../interfaces';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n IngestResponseState,\n IngestType,\n} from '../interfaces';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useEffect, useState } from 'react';\nimport { Icon, Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { useWindowSize } from '@washingtonpost/subs-hooks';\nimport { ChevronDown } from '@washingtonpost/wpds-assets';\n\ninterface IDropdownProps {\n id: string;\n label: string;\n values: Array<string>;\n required?: boolean;\n defaultValue?: string;\n onChange?: (value: string) => void;\n disabled?: boolean;\n}\n\nconst StyledMobileSelect = styled('select', {\n padding: '12px 16px 12px 6px',\n display: 'flex',\n justifyContent: 'space-between',\n width: '100%',\n backgroundColor: '$secondary',\n color: '$primary',\n fontFamily: '$meta',\n fontSize: '$100',\n fontWeight: '$light',\n lineHeight: '$125',\n paddingBlockRight: '$125',\n textOverflow: 'ellipsis',\n position: 'relative',\n borderColor: 'transparent',\n borderRightWidth: '10px',\n borderRightColor: 'transparent',\n appearance: 'none',\n '-webkit-appearance': 'none',\n '&:disabled': {\n backgroundColor: theme.colors.disabled,\n borderColor: theme.colors.disabled,\n color: theme.colors.onDisabled,\n cursor: 'not-allowed',\n },\n});\n\nconst StyledSelectWrapper = styled('div', {\n width: '100%',\n maxWidth: '380px',\n borderRadius: '$012',\n borderColor: '$subtle',\n borderStyle: 'solid',\n borderWidth: '1px',\n backgroundColor: '$secondary',\n position: 'relative',\n});\n\nconst StyledMobileOption = styled('option', {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n color: 'inherit',\n});\n\n/**\n * Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.\n * @param {IDropdownProps} props The props.\n * @returns {React.ReactElement} The dropdown.\n */\nexport const Dropdown = ({\n id,\n label,\n values,\n required = false,\n defaultValue,\n onChange = () => {},\n disabled = false,\n}: IDropdownProps) => {\n const [answer, setAnswer] = useState<string>();\n const { isMobileSize } = useWindowSize();\n\n useEffect(() => {\n if (answer) onChange(answer);\n }, [answer]);\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // helps maintain state between WPDS and native dropdowns\n const defaultValueProp = answer\n ? { defaultValue: answer }\n : defaultValue\n ? { defaultValue }\n : {};\n\n const defaultValuePropMobile = (value: string) => {\n if (answer) {\n return value === answer ? { selected: true } : {};\n }\n return value === defaultValue ? { selected: true } : {};\n };\n\n return isMobileSize ? (\n <StyledSelectWrapper>\n <StyledMobileSelect\n id=\"\"\n required={required}\n onChange={(e) => setAnswer(e.target.value)}\n placeholder={label}\n {...disabledProp}\n >\n <label>{label}</label>\n <StyledMobileOption\n value=\"\"\n disabled\n selected\n style={{ color: '#666666' }}\n >\n {label}\n </StyledMobileOption>\n {values.map((value) => (\n <StyledMobileOption\n value={value}\n key={value}\n {...defaultValuePropMobile(value)}\n >\n {value}\n </StyledMobileOption>\n ))}\n </StyledMobileSelect>\n <Icon\n label=\"\"\n size=\"100\"\n fill={theme.colors['gray80']}\n style={{\n pointerEvents: 'none',\n position: 'absolute',\n right: '10px',\n top: '50%',\n transform: 'translateY(-50%)',\n }}\n >\n <ChevronDown style={{ position: 'absolute', right: '10px' }} />\n </Icon>\n </StyledSelectWrapper>\n ) : (\n <Select.Root\n onValueChange={(e) => setAnswer(e)}\n required={required}\n {...defaultValueProp}\n {...disabledProp}\n >\n <Select.Trigger data-test-id={`${id}-select-trigger`}>\n <Select.Label>{label}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${id}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value} key={value}>\n {value}\n </Select.Item>\n ))}\n </Select.Content>\n </Select.Root>\n );\n};\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\nimport { Dropdown } from './Dropdown';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError =\n result === true\n ? false\n : result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n {children && (\n <Select.Root\n onValueChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children}\n </Select.Root>\n )}\n {!children && !config && (\n <Dropdown\n id={'loading'}\n label={'Loading...'}\n values={[]}\n disabled={true}\n />\n )}\n {!children && config && (\n <Dropdown\n id={config.name}\n label={label || config.name}\n onChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n values={values.map((value) => value.name)}\n defaultValue={defaultValue}\n disabled={disabled}\n />\n )}\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n","import {\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { getAttributes } from './getAttributes';\nimport { sendToGA } from './sendToGA';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\nimport { ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { ingest } from './ingest';\n\nexport const push: PushType = async ({\n submitData,\n type = IngestType.IMPLICIT,\n source,\n}) => {\n if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n const attributeInfo = await getAttributes({\n fieldName: submitData.fieldName,\n });\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === submitData.fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n throw new Error('do not collect');\n }\n\n if (type === IngestType.EXPLICIT) {\n return ingest({ submitData, type, source });\n } else {\n // One reason we wanted to send everything through GA is to honor region/consent status\n // GA will send to ingest so you don’t need to send separately\n return sendToGA({ submitData, type, source });\n }\n};\n\ntype PushType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<\n | {\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n }\n | null\n | true\n>;\n","import { IngestType } from '../interfaces';\n\nexport interface ISendGAEvent {\n event: string;\n category: string;\n action: string;\n label: string;\n 'de-label': string;\n [key: string]: undefined | string | string[];\n}\n\nconst sendGAEvent = (props: ISendGAEvent): void => {\n if (typeof window === 'undefined') {\n if (__DEV__) console.warn('NO WINDOW');\n return;\n }\n // Initialize dataLayer if needed\n window.dataLayer = window.dataLayer || [];\n\n const eventData: Record<string, any> = {\n ...props,\n };\n window.dataLayer.push(eventData);\n};\n\nexport const sendToGA: SendToGaType = async ({\n submitData: { fieldName, value },\n source,\n}) => {\n sendGAEvent({\n event: 'site-onpage-click',\n action: 'site-onpage-click',\n category: 'profile',\n\n label: fieldName,\n 'de-label': fieldName,\n [fieldName]: value,\n\n section: 'profile',\n subsection: source,\n });\n\n return true;\n};\n\ntype SendToGaType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<true>;\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","IngestType","EXPLICIT","IMPLICIT","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","async","fieldName","_ref","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","SUCCESS","attributes","e","console","debug","StyledMobileSelect","styled","padding","display","justifyContent","width","backgroundColor","color","fontFamily","fontSize","fontWeight","lineHeight","paddingBlockRight","textOverflow","position","borderColor","borderRightWidth","borderRightColor","appearance","-webkit-appearance","&:disabled","theme","colors","disabled","onDisabled","cursor","StyledSelectWrapper","maxWidth","borderRadius","borderStyle","borderWidth","StyledMobileOption","Dropdown","id","label","values","required","defaultValue","onChange","answer","setAnswer","useState","isMobileSize","useWindowSize","useEffect","disabledProp","defaultValueProp","defaultValuePropMobile","value","selected","React","target","placeholder","style","map","key","Icon","size","fill","pointerEvents","right","top","transform","ChevronDown","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","zIndices","page","Item","scriptSrc","staticAssets","SelectWrapper","boxSizing","marginBottom","flexDirection","& button","& *","source","dataDictionaryConfig","submit","onFinished","valuesFilter","children","config","setConfig","setSelected","scriptStatus","useScript","ScriptStatus","READY","_window","__twpdeu","getFieldConfigs","error","warn","fetchConfig","_window2","result","push","submitData","type","explicit","isFinished","isError","submitSelected","sort","a","b","order","filter","archived","name","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","Error","attributeInfo","collection_behavior","wapo_login_id","payload","jucid","localStorage","getItem","ga","[object Object]","metadata","response","method","body","JSON","stringify","ingest","props","process","env","NODE_ENV","dataLayer","eventData","sendGAEvent","event","action","category","de-label","section","subsection","sendToGA"],"mappings":"0TAQaA,EAAsB,CACjCC,QAAS,UACTC,eAAgB,kBAmBLC,EAAa,CACxBC,SAAU,WACVC,SAAU,YC7BCC,EAA4BA,WACvC,GAAsB,oBAAXC,OACT,OAAO,EAGT,MAAMC,EA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ookie, WPGeo, JSON_HEADERS, ResponseStatus, ENDPOINTS } from '@washingtonpost/subs-sdk';
|
|
2
2
|
import React, { useState, useEffect } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';
|
|
3
|
+
import { Icon, theme, Select, styled } from '@washingtonpost/wpds-ui-kit';
|
|
4
|
+
import { useWindowSize, useScript, ScriptStatus } from '@washingtonpost/subs-hooks';
|
|
5
|
+
import { ChevronDown } from '@washingtonpost/wpds-assets';
|
|
5
6
|
|
|
6
7
|
const CollectionBehaviors = {
|
|
7
8
|
COLLECT: 'COLLECT',
|
|
@@ -38,26 +39,19 @@ const hasRequiredPrivacyCookies = () => {
|
|
|
38
39
|
return !!(wp_usp && countryCode === 'US');
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
const DEBUG_FLAG = 'f_de_debug';
|
|
42
42
|
const base = `${ENDPOINTS.base}/de/v1`;
|
|
43
43
|
const attributesCache = {};
|
|
44
44
|
const getAttributes = async _ref => {
|
|
45
45
|
let {
|
|
46
46
|
fieldName
|
|
47
47
|
} = _ref;
|
|
48
|
-
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
49
|
-
if (debug) {
|
|
50
|
-
console.debug('getAttributes()');
|
|
51
|
-
}
|
|
52
48
|
if (attributesCache[fieldName]) {
|
|
53
|
-
if (debug) console.debug('getAttributes() > return cached info');
|
|
54
49
|
return attributesCache[fieldName];
|
|
55
50
|
}
|
|
56
51
|
const fieldNames = [fieldName];
|
|
57
52
|
try {
|
|
58
53
|
const url = new URL(`${base}/attributes`);
|
|
59
54
|
url.searchParams.set('attributes', fieldNames.join(','));
|
|
60
|
-
if (debug) console.debug(`getAttributes() > ${url.toString()}`);
|
|
61
55
|
const data = await fetch(url.toString(), {
|
|
62
56
|
credentials: 'include',
|
|
63
57
|
headers: JSON_HEADERS
|
|
@@ -75,7 +69,42 @@ const getAttributes = async _ref => {
|
|
|
75
69
|
return [];
|
|
76
70
|
}
|
|
77
71
|
};
|
|
78
|
-
|
|
72
|
+
|
|
73
|
+
const sendGAEvent = props => {
|
|
74
|
+
if (typeof window === 'undefined') {
|
|
75
|
+
if (process.env.NODE_ENV !== "production") console.warn('NO WINDOW');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Initialize dataLayer if needed
|
|
79
|
+
window.dataLayer = window.dataLayer || [];
|
|
80
|
+
const eventData = {
|
|
81
|
+
...props
|
|
82
|
+
};
|
|
83
|
+
window.dataLayer.push(eventData);
|
|
84
|
+
};
|
|
85
|
+
const sendToGA = async _ref => {
|
|
86
|
+
let {
|
|
87
|
+
submitData: {
|
|
88
|
+
fieldName,
|
|
89
|
+
value
|
|
90
|
+
},
|
|
91
|
+
source
|
|
92
|
+
} = _ref;
|
|
93
|
+
sendGAEvent({
|
|
94
|
+
event: 'site-onpage-click',
|
|
95
|
+
action: 'site-onpage-click',
|
|
96
|
+
category: 'profile',
|
|
97
|
+
label: fieldName,
|
|
98
|
+
'de-label': fieldName,
|
|
99
|
+
[fieldName]: value,
|
|
100
|
+
section: 'profile',
|
|
101
|
+
subsection: source
|
|
102
|
+
});
|
|
103
|
+
return true;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const base$1 = `${ENDPOINTS.base}/de/v1`;
|
|
107
|
+
const ingest = async _ref => {
|
|
79
108
|
let {
|
|
80
109
|
submitData: {
|
|
81
110
|
fieldName,
|
|
@@ -83,30 +112,9 @@ const ingest = async _ref2 => {
|
|
|
83
112
|
},
|
|
84
113
|
type = IngestType.IMPLICIT,
|
|
85
114
|
source
|
|
86
|
-
} =
|
|
87
|
-
const
|
|
88
|
-
if (debug) {
|
|
89
|
-
console.debug('ingest()');
|
|
90
|
-
}
|
|
91
|
-
const url = `${base}/ingest`;
|
|
115
|
+
} = _ref;
|
|
116
|
+
const url = `${base$1}/ingest`;
|
|
92
117
|
const wapo_login_id = getCookie('wapo_login_id');
|
|
93
|
-
if (!hasRequiredPrivacyCookies()) {
|
|
94
|
-
if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');
|
|
95
|
-
throw new Error('does not satisfy cookie check');
|
|
96
|
-
}
|
|
97
|
-
let attributeInfo = attributesCache[fieldName];
|
|
98
|
-
if (!attributeInfo) {
|
|
99
|
-
if (debug) console.debug('ingest() > fetch attribute info');
|
|
100
|
-
attributeInfo = await getAttributes({
|
|
101
|
-
fieldName
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
if (debug) console.debug('ingest() > use cached attribute info');
|
|
105
|
-
}
|
|
106
|
-
if (attributeInfo[0] && attributeInfo[0].name === fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
|
|
107
|
-
if (debug) console.debug('ingest() > do not collect');
|
|
108
|
-
throw new Error('do not collect');
|
|
109
|
-
}
|
|
110
118
|
const jucid = localStorage.getItem('uuid');
|
|
111
119
|
const ga = getCookie('_ga');
|
|
112
120
|
const payload = {
|
|
@@ -136,6 +144,171 @@ const ingest = async _ref2 => {
|
|
|
136
144
|
}
|
|
137
145
|
};
|
|
138
146
|
|
|
147
|
+
const push = async _ref => {
|
|
148
|
+
let {
|
|
149
|
+
submitData,
|
|
150
|
+
type = IngestType.IMPLICIT,
|
|
151
|
+
source
|
|
152
|
+
} = _ref;
|
|
153
|
+
if (!hasRequiredPrivacyCookies()) {
|
|
154
|
+
throw new Error('does not satisfy cookie check');
|
|
155
|
+
}
|
|
156
|
+
const attributeInfo = await getAttributes({
|
|
157
|
+
fieldName: submitData.fieldName
|
|
158
|
+
});
|
|
159
|
+
if (attributeInfo[0] && attributeInfo[0].name === submitData.fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
|
|
160
|
+
throw new Error('do not collect');
|
|
161
|
+
}
|
|
162
|
+
if (type === IngestType.EXPLICIT) {
|
|
163
|
+
return ingest({
|
|
164
|
+
submitData,
|
|
165
|
+
type,
|
|
166
|
+
source
|
|
167
|
+
});
|
|
168
|
+
} else {
|
|
169
|
+
// One reason we wanted to send everything through GA is to honor region/consent status
|
|
170
|
+
// GA will send to ingest so you don’t need to send separately
|
|
171
|
+
return sendToGA({
|
|
172
|
+
submitData,
|
|
173
|
+
type,
|
|
174
|
+
source
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const StyledMobileSelect = /*#__PURE__*/styled('select', {
|
|
180
|
+
padding: '12px 16px 12px 6px',
|
|
181
|
+
display: 'flex',
|
|
182
|
+
justifyContent: 'space-between',
|
|
183
|
+
width: '100%',
|
|
184
|
+
backgroundColor: '$secondary',
|
|
185
|
+
color: '$primary',
|
|
186
|
+
fontFamily: '$meta',
|
|
187
|
+
fontSize: '$100',
|
|
188
|
+
fontWeight: '$light',
|
|
189
|
+
lineHeight: '$125',
|
|
190
|
+
paddingBlockRight: '$125',
|
|
191
|
+
textOverflow: 'ellipsis',
|
|
192
|
+
position: 'relative',
|
|
193
|
+
borderColor: 'transparent',
|
|
194
|
+
borderRightWidth: '10px',
|
|
195
|
+
borderRightColor: 'transparent',
|
|
196
|
+
appearance: 'none',
|
|
197
|
+
'-webkit-appearance': 'none',
|
|
198
|
+
'&:disabled': {
|
|
199
|
+
backgroundColor: theme.colors.disabled,
|
|
200
|
+
borderColor: theme.colors.disabled,
|
|
201
|
+
color: theme.colors.onDisabled,
|
|
202
|
+
cursor: 'not-allowed'
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
const StyledSelectWrapper = /*#__PURE__*/styled('div', {
|
|
206
|
+
width: '100%',
|
|
207
|
+
maxWidth: '380px',
|
|
208
|
+
borderRadius: '$012',
|
|
209
|
+
borderColor: '$subtle',
|
|
210
|
+
borderStyle: 'solid',
|
|
211
|
+
borderWidth: '1px',
|
|
212
|
+
backgroundColor: '$secondary',
|
|
213
|
+
position: 'relative'
|
|
214
|
+
});
|
|
215
|
+
const StyledMobileOption = /*#__PURE__*/styled('option', {
|
|
216
|
+
fontFamily: 'inherit',
|
|
217
|
+
fontSize: 'inherit',
|
|
218
|
+
color: 'inherit'
|
|
219
|
+
});
|
|
220
|
+
/**
|
|
221
|
+
* Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.
|
|
222
|
+
* @param {IDropdownProps} props The props.
|
|
223
|
+
* @returns {React.ReactElement} The dropdown.
|
|
224
|
+
*/
|
|
225
|
+
const Dropdown = _ref => {
|
|
226
|
+
let {
|
|
227
|
+
id,
|
|
228
|
+
label,
|
|
229
|
+
values,
|
|
230
|
+
required = false,
|
|
231
|
+
defaultValue,
|
|
232
|
+
onChange = () => {},
|
|
233
|
+
disabled = false
|
|
234
|
+
} = _ref;
|
|
235
|
+
const [answer, setAnswer] = useState();
|
|
236
|
+
const {
|
|
237
|
+
isMobileSize
|
|
238
|
+
} = useWindowSize();
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
if (answer) onChange(answer);
|
|
241
|
+
}, [answer]);
|
|
242
|
+
const disabledProp = disabled ? {
|
|
243
|
+
disabled: true
|
|
244
|
+
} : {};
|
|
245
|
+
// helps maintain state between WPDS and native dropdowns
|
|
246
|
+
const defaultValueProp = answer ? {
|
|
247
|
+
defaultValue: answer
|
|
248
|
+
} : defaultValue ? {
|
|
249
|
+
defaultValue
|
|
250
|
+
} : {};
|
|
251
|
+
const defaultValuePropMobile = value => {
|
|
252
|
+
if (answer) {
|
|
253
|
+
return value === answer ? {
|
|
254
|
+
selected: true
|
|
255
|
+
} : {};
|
|
256
|
+
}
|
|
257
|
+
return value === defaultValue ? {
|
|
258
|
+
selected: true
|
|
259
|
+
} : {};
|
|
260
|
+
};
|
|
261
|
+
return isMobileSize ? React.createElement(StyledSelectWrapper, null, React.createElement(StyledMobileSelect, {
|
|
262
|
+
id: "",
|
|
263
|
+
required: required,
|
|
264
|
+
onChange: e => setAnswer(e.target.value),
|
|
265
|
+
placeholder: label,
|
|
266
|
+
...disabledProp
|
|
267
|
+
}, React.createElement("label", null, label), React.createElement(StyledMobileOption, {
|
|
268
|
+
value: "",
|
|
269
|
+
disabled: true,
|
|
270
|
+
selected: true,
|
|
271
|
+
style: {
|
|
272
|
+
color: '#666666'
|
|
273
|
+
}
|
|
274
|
+
}, label), values.map(value => React.createElement(StyledMobileOption, {
|
|
275
|
+
value: value,
|
|
276
|
+
key: value,
|
|
277
|
+
...defaultValuePropMobile(value)
|
|
278
|
+
}, value))), React.createElement(Icon, {
|
|
279
|
+
label: "",
|
|
280
|
+
size: "100",
|
|
281
|
+
fill: theme.colors['gray80'],
|
|
282
|
+
style: {
|
|
283
|
+
pointerEvents: 'none',
|
|
284
|
+
position: 'absolute',
|
|
285
|
+
right: '10px',
|
|
286
|
+
top: '50%',
|
|
287
|
+
transform: 'translateY(-50%)'
|
|
288
|
+
}
|
|
289
|
+
}, React.createElement(ChevronDown, {
|
|
290
|
+
style: {
|
|
291
|
+
position: 'absolute',
|
|
292
|
+
right: '10px'
|
|
293
|
+
}
|
|
294
|
+
}))) : React.createElement(Select.Root, {
|
|
295
|
+
onValueChange: e => setAnswer(e),
|
|
296
|
+
required: required,
|
|
297
|
+
...defaultValueProp,
|
|
298
|
+
...disabledProp
|
|
299
|
+
}, React.createElement(Select.Trigger, {
|
|
300
|
+
"data-test-id": `${id}-select-trigger`
|
|
301
|
+
}, React.createElement(Select.Label, null, label), React.createElement(Select.Value, null)), React.createElement(Select.Content, {
|
|
302
|
+
css: {
|
|
303
|
+
zIndex: theme.zIndices.page
|
|
304
|
+
},
|
|
305
|
+
"data-test-id": `${id}-select-content`
|
|
306
|
+
}, values.map(value => React.createElement(Select.Item, {
|
|
307
|
+
value: value,
|
|
308
|
+
key: value
|
|
309
|
+
}, value))));
|
|
310
|
+
};
|
|
311
|
+
|
|
139
312
|
const scriptSrc = `${ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static' ? 'https://www.washingtonpost.com/subscribe/static/' : ENDPOINTS.staticAssets}/de-utils/twpdeu.min.js`;
|
|
140
313
|
const DESelect = _ref => {
|
|
141
314
|
let {
|
|
@@ -187,7 +360,7 @@ const DESelect = _ref => {
|
|
|
187
360
|
type: config !== null && config !== void 0 && config.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,
|
|
188
361
|
source
|
|
189
362
|
}));
|
|
190
|
-
const isError = result ? result.status !== ResponseStatus.SUCCESS : true;
|
|
363
|
+
const isError = result === true ? false : result ? result.status !== ResponseStatus.SUCCESS : true;
|
|
191
364
|
onFinished({
|
|
192
365
|
isFinished: true,
|
|
193
366
|
isError
|
|
@@ -212,28 +385,33 @@ const DESelect = _ref => {
|
|
|
212
385
|
} : {};
|
|
213
386
|
// sort and filter out archived values
|
|
214
387
|
const values = config ? config.values.sort((a, b) => a.order - b.order).filter(value => value.archived !== true).filter(valuesFilter) : [];
|
|
215
|
-
return React.createElement(SelectWrapper, null, React.createElement(Select.Root, {
|
|
388
|
+
return React.createElement(SelectWrapper, null, children && React.createElement(Select.Root, {
|
|
216
389
|
onValueChange: e => {
|
|
390
|
+
setSelected(e);
|
|
217
391
|
onChange({
|
|
218
392
|
value: e
|
|
219
393
|
});
|
|
220
|
-
setSelected(e);
|
|
221
394
|
},
|
|
222
395
|
...defaultValueProp,
|
|
223
396
|
...disabledProp
|
|
224
|
-
}, children
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
397
|
+
}, children), !children && !config && React.createElement(Dropdown, {
|
|
398
|
+
id: 'loading',
|
|
399
|
+
label: 'Loading...',
|
|
400
|
+
values: [],
|
|
401
|
+
disabled: true
|
|
402
|
+
}), !children && config && React.createElement(Dropdown, {
|
|
403
|
+
id: config.name,
|
|
404
|
+
label: label || config.name,
|
|
405
|
+
onChange: e => {
|
|
406
|
+
setSelected(e);
|
|
407
|
+
onChange({
|
|
408
|
+
value: e
|
|
409
|
+
});
|
|
231
410
|
},
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}, value.name))))));
|
|
411
|
+
values: values.map(value => value.name),
|
|
412
|
+
defaultValue: defaultValue,
|
|
413
|
+
disabled: disabled
|
|
414
|
+
}));
|
|
237
415
|
};
|
|
238
416
|
const SelectWrapper = /*#__PURE__*/styled('div', {
|
|
239
417
|
boxSizing: 'border-box',
|
|
@@ -248,5 +426,5 @@ const SelectWrapper = /*#__PURE__*/styled('div', {
|
|
|
248
426
|
}
|
|
249
427
|
});
|
|
250
428
|
|
|
251
|
-
export { AttributesState, CollectionBehaviors, DESelect, IngestResponseState, IngestType, getAttributes, hasRequiredPrivacyCookies,
|
|
429
|
+
export { AttributesState, CollectionBehaviors, DESelect, IngestResponseState, IngestType, getAttributes, hasRequiredPrivacyCookies, push };
|
|
252
430
|
//# sourceMappingURL=subs-de-inputs.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subs-de-inputs.esm.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/dataEnrichment.ts","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n Attribute,\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\n\nconst DEBUG_FLAG = 'f_de_debug';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('getAttributes()');\n }\n\n if (attributesCache[fieldName]) {\n if (debug) console.debug('getAttributes() > return cached info');\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n if (debug) console.debug(`getAttributes() > ${url.toString()}`);\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const debug = window.location.search.includes(DEBUG_FLAG);\n\n if (debug) {\n console.debug('ingest()');\n }\n\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n if (!hasRequiredPrivacyCookies()) {\n if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n if (debug) console.debug('ingest() > fetch attribute info');\n attributeInfo = await getAttributes({ fieldName });\n } else {\n if (debug) console.debug('ingest() > use cached attribute info');\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n if (debug) console.debug('ingest() > do not collect');\n throw new Error('do not collect');\n }\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n <Select.Root\n onValueChange={(e: string) => {\n onChange({ value: e });\n setSelected(e);\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children ? children : null}\n {!children && !config && (\n <>\n <Select.Trigger data-test-id={`select-trigger-loading`}>\n <Select.Label>{label || 'loading...'}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n </>\n )}\n {!children && config && (\n <>\n <Select.Trigger data-test-id={`${config.name}-select-trigger`}>\n <Select.Label>{label || config.name}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${config.name}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value.name} key={value.name}>\n {value.name}\n </Select.Item>\n ))}\n </Select.Content>\n </>\n )}\n </Select.Root>\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","DEBUG_FLAG","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","debug","location","search","includes","console","fieldNames","url","URL","searchParams","set","join","toString","data","fetch","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","ingest","_ref2","submitData","value","type","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","scriptSrc","staticAssets","DESelect","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","scriptStatus","useScript","useEffect","fetchConfig","_window","__twpdeu","getFieldConfigs","error","warn","ScriptStatus","READY","submitSelected","_window2","result","push","explicit","isError","isFinished","defaultValueProp","isLoading","disabledProp","values","sort","a","b","order","filter","archived","React","SelectWrapper","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","theme","zIndices","page","map","Item","key","styled","boxSizing","display","marginBottom","flexDirection","padding"],"mappings":";;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAAU,GAAG;EACxBC,QAAQ,EAAE,UAAU;EACpBC,QAAQ,EAAE;;MAGCC,mBAAmB,GAAG;EACjCJ,OAAO,EAAE,KAAK;EACdK,YAAY,EAAE,KAAK;EACnBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,KAAK;EACzBC,YAAY,EAAE,KAAK;EACnBC,4BAA4B,EAAE,KAAK;EACnCC,uBAAuB,EAAE,KAAK;EAC9BC,eAAe,EAAE,KAAK;EACtBC,qBAAqB,EAAE,KAAK;EAC5BC,6BAA6B,EAAE,KAAK;EACpCf,cAAc,EAAE;;;MC3CLgB,yBAAyB,GAAGA;;EACvC,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAO,KAAK;;EAGd,MAAMC,MAAM,GAAGC,SAAS,CAAC,QAAQ,CAAC;EAElC,MAAMC,WAAW,IAAAC,MAAA,GAAGC,KAAK,EAAE,cAAAD,MAAA,uBAAPA,MAAA,CAASE,YAAY;EAEzC,OAAO,CAAC,EAAEL,MAAM,IAAIE,WAAW,KA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,OAAO;;KACbL,oBAACE,MAAM,CAACI,KAAK,QAAEhD,KAAK,IAAI,YAAY,CAAgB,EACpD0C,oBAACE,MAAM,CAACK,KAAK,OAAG,CACD,CAEpB,EACA,CAACzC,QAAQ,IAAIC,MAAM,IAClBiC,0CACEA,oBAACE,MAAM,CAACG,OAAO;uBAAkBtC,MAAM,CAACzB;KACtC0D,oBAACE,MAAM,CAACI,KAAK,QAAEhD,KAAK,IAAIS,MAAM,CAACzB,IAAI,CAAgB,EACnD0D,oBAACE,MAAM,CAACK,KAAK,OAAG,CACD,EACjBP,oBAACE,MAAM,CAACM,OAAO;IACbC,GAAG,EAAE;MAAEC,MAAM,EAAEC,KAAK,CAACC,QAAQ,CAACC;KAAM;uBACnB9C,MAAM,CAACzB;KAEvBmD,MAAM,CAACqB,GAAG,CAAE9E,KAAK,IAChBgE,oBAACE,MAAM,CAACa,IAAI;IAAC/E,KAAK,EAAEA,KAAK,CAACM,IAAI;IAAE0E,GAAG,EAAEhF,KAAK,CAACM;KACxCN,KAAK,CAACM,IAAI,CAEd,CAAC,CACa,CAEpB,CACW,CACA;AAEpB,CAAC;AAED,MAAM2D,aAAa,gBAAGgB,MAAM,CAAC,KAAK,EAAE;EAClCC,SAAS,EAAE,YAAY;EACvBC,OAAO,EAAE,MAAM;EACfC,YAAY,EAAE,MAAM;EACpBC,aAAa,EAAE,QAAQ;EACvB,UAAU,EAAE;IACVC,OAAO,EAAE;GACV;EACD,KAAK,EAAE;IAAEJ,SAAS,EAAE;;CACrB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"subs-de-inputs.esm.js","sources":["../src/interfaces/index.ts","../src/utils/hasRequiredPrivacyCookies.ts","../src/services/getAttributes.ts","../src/services/sendToGA.ts","../src/services/ingest.ts","../src/services/push.ts","../src/components/DESelect/Dropdown.tsx","../src/components/DESelect/index.tsx"],"sourcesContent":["export type AttributeValue = {\n name: string;\n date_created: Number;\n last_modified_date: Number;\n archived: boolean;\n order: number;\n};\n\nexport const CollectionBehaviors = {\n COLLECT: 'COLLECT',\n DO_NOT_COLLECT: 'DO_NOT_COLLECT',\n} as const;\n\nexport type Attribute = {\n name: string;\n approved_for_use?: boolean;\n collection_behavior?: (typeof CollectionBehaviors)[keyof typeof CollectionBehaviors];\n datatype: 'string';\n explicit: boolean;\n multiple_value: boolean;\n last_modified_date: Number;\n date_created: Number;\n values: Array<AttributeValue>;\n};\n\nexport const AttributesState = {\n SUCCESS: '100',\n} as const;\n\nexport const IngestType = {\n EXPLICIT: 'explicit',\n IMPLICIT: 'implicit',\n} as const;\n\nexport const IngestResponseState = {\n SUCCESS: '100',\n SYSTEM_ERROR: '101',\n INVALID_TYPE: '102',\n INVALID_IDENTIFIER: '103',\n INVALID_DATA: '104',\n INVALID_ATTRIBUTE_DEFINITION: '105',\n INVALID_META_DEFINITION: '106',\n UNAUTHENTICATED: '107',\n MISMATCHED_IDENTIFIER: '108',\n DISABLED_ATTRIBUTE_DEFINITION: '109',\n DO_NOT_COLLECT: '110',\n} as const;\n","import { WPGeo, getCookie } from '@washingtonpost/subs-sdk';\n\nexport const hasRequiredPrivacyCookies = () => {\n if (typeof window === 'undefined') {\n return false;\n }\n\n const wp_usp = getCookie('wp_usp');\n\n const countryCode = WPGeo()?.country_code;\n\n return !!(wp_usp && countryCode === 'US');\n};\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n} from '@washingtonpost/subs-sdk';\nimport { Attribute } from '../interfaces';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nconst attributesCache: Record<string, any> = {};\nexport const getAttributes: GetAttributesType = async ({\n fieldName,\n}: {\n fieldName: string;\n}) => {\n if (attributesCache[fieldName]) {\n return attributesCache[fieldName];\n }\n\n const fieldNames = [fieldName];\n\n try {\n const url = new URL(`${base}/attributes`);\n url.searchParams.set('attributes', fieldNames.join(','));\n\n const data = await fetch(url.toString(), {\n credentials: 'include',\n headers: JSON_HEADERS,\n });\n const json = await data.json();\n\n if (data.ok && json.status === ResponseStatus.SUCCESS) {\n const attributes = json.attributes || [];\n attributesCache[fieldName] = attributes;\n return attributes;\n } else {\n return [];\n }\n } catch (e) {\n console.debug(e);\n return [];\n }\n};\n\ntype GetAttributesType = ({\n fieldName,\n}: {\n fieldName: string;\n}) => Promise<Attribute[]>;\n","import { IngestType } from '../interfaces';\n\nexport interface ISendGAEvent {\n event: string;\n category: string;\n action: string;\n label: string;\n 'de-label': string;\n [key: string]: undefined | string | string[];\n}\n\nconst sendGAEvent = (props: ISendGAEvent): void => {\n if (typeof window === 'undefined') {\n if (__DEV__) console.warn('NO WINDOW');\n return;\n }\n // Initialize dataLayer if needed\n window.dataLayer = window.dataLayer || [];\n\n const eventData: Record<string, any> = {\n ...props,\n };\n window.dataLayer.push(eventData);\n};\n\nexport const sendToGA: SendToGaType = async ({\n submitData: { fieldName, value },\n source,\n}) => {\n sendGAEvent({\n event: 'site-onpage-click',\n action: 'site-onpage-click',\n category: 'profile',\n\n label: fieldName,\n 'de-label': fieldName,\n [fieldName]: value,\n\n section: 'profile',\n subsection: source,\n });\n\n return true;\n};\n\ntype SendToGaType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<true>;\n","import {\n ENDPOINTS,\n ResponseStatus,\n JSON_HEADERS,\n getCookie,\n} from '@washingtonpost/subs-sdk';\nimport {\n IngestResponseState,\n IngestType,\n} from '../interfaces';\n\nconst base = `${ENDPOINTS.base}/de/v1`;\n\nexport const ingest: IngestType = async ({\n submitData: { fieldName, value },\n type = IngestType.IMPLICIT,\n source,\n}) => {\n const url = `${base}/ingest`;\n\n const wapo_login_id = getCookie('wapo_login_id');\n\n const jucid = localStorage.getItem('uuid');\n const ga = getCookie('_ga');\n\n const payload = {\n jucid,\n ga,\n type,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n [fieldName]: [value],\n },\n metadata: { source },\n };\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n credentials: 'include',\n headers: JSON_HEADERS,\n body: JSON.stringify(payload),\n });\n\n const json = await response.json();\n\n return json;\n } catch (e) {\n console.debug(e);\n return null;\n }\n};\n\ntype IngestType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<{\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n} | null>;\n","import {\n CollectionBehaviors,\n IngestResponseState,\n IngestType,\n} from '../interfaces';\nimport { getAttributes } from './getAttributes';\nimport { sendToGA } from './sendToGA';\nimport { hasRequiredPrivacyCookies } from '../utils/hasRequiredPrivacyCookies';\nimport { ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { ingest } from './ingest';\n\nexport const push: PushType = async ({\n submitData,\n type = IngestType.IMPLICIT,\n source,\n}) => {\n if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n const attributeInfo = await getAttributes({\n fieldName: submitData.fieldName,\n });\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === submitData.fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\n throw new Error('do not collect');\n }\n\n if (type === IngestType.EXPLICIT) {\n return ingest({ submitData, type, source });\n } else {\n // One reason we wanted to send everything through GA is to honor region/consent status\n // GA will send to ingest so you don’t need to send separately\n return sendToGA({ submitData, type, source });\n }\n};\n\ntype PushType = ({\n submitData: { fieldName, value },\n source,\n}: {\n submitData: {\n fieldName: string;\n value: string;\n };\n type?: (typeof IngestType)[keyof typeof IngestType];\n source: string;\n}) => Promise<\n | {\n status: ResponseStatus;\n state: (typeof IngestResponseState)[keyof typeof IngestResponseState];\n }\n | null\n | true\n>;\n","import React, { useEffect, useState } from 'react';\nimport { Icon, Select, styled, theme } from '@washingtonpost/wpds-ui-kit';\nimport { useWindowSize } from '@washingtonpost/subs-hooks';\nimport { ChevronDown } from '@washingtonpost/wpds-assets';\n\ninterface IDropdownProps {\n id: string;\n label: string;\n values: Array<string>;\n required?: boolean;\n defaultValue?: string;\n onChange?: (value: string) => void;\n disabled?: boolean;\n}\n\nconst StyledMobileSelect = styled('select', {\n padding: '12px 16px 12px 6px',\n display: 'flex',\n justifyContent: 'space-between',\n width: '100%',\n backgroundColor: '$secondary',\n color: '$primary',\n fontFamily: '$meta',\n fontSize: '$100',\n fontWeight: '$light',\n lineHeight: '$125',\n paddingBlockRight: '$125',\n textOverflow: 'ellipsis',\n position: 'relative',\n borderColor: 'transparent',\n borderRightWidth: '10px',\n borderRightColor: 'transparent',\n appearance: 'none',\n '-webkit-appearance': 'none',\n '&:disabled': {\n backgroundColor: theme.colors.disabled,\n borderColor: theme.colors.disabled,\n color: theme.colors.onDisabled,\n cursor: 'not-allowed',\n },\n});\n\nconst StyledSelectWrapper = styled('div', {\n width: '100%',\n maxWidth: '380px',\n borderRadius: '$012',\n borderColor: '$subtle',\n borderStyle: 'solid',\n borderWidth: '1px',\n backgroundColor: '$secondary',\n position: 'relative',\n});\n\nconst StyledMobileOption = styled('option', {\n fontFamily: 'inherit',\n fontSize: 'inherit',\n color: 'inherit',\n});\n\n/**\n * Dropdown component. Uses wpds-ui-kit on desktop and native select on mobile.\n * @param {IDropdownProps} props The props.\n * @returns {React.ReactElement} The dropdown.\n */\nexport const Dropdown = ({\n id,\n label,\n values,\n required = false,\n defaultValue,\n onChange = () => {},\n disabled = false,\n}: IDropdownProps) => {\n const [answer, setAnswer] = useState<string>();\n const { isMobileSize } = useWindowSize();\n\n useEffect(() => {\n if (answer) onChange(answer);\n }, [answer]);\n\n const disabledProp = disabled ? { disabled: true } : {};\n\n // helps maintain state between WPDS and native dropdowns\n const defaultValueProp = answer\n ? { defaultValue: answer }\n : defaultValue\n ? { defaultValue }\n : {};\n\n const defaultValuePropMobile = (value: string) => {\n if (answer) {\n return value === answer ? { selected: true } : {};\n }\n return value === defaultValue ? { selected: true } : {};\n };\n\n return isMobileSize ? (\n <StyledSelectWrapper>\n <StyledMobileSelect\n id=\"\"\n required={required}\n onChange={(e) => setAnswer(e.target.value)}\n placeholder={label}\n {...disabledProp}\n >\n <label>{label}</label>\n <StyledMobileOption\n value=\"\"\n disabled\n selected\n style={{ color: '#666666' }}\n >\n {label}\n </StyledMobileOption>\n {values.map((value) => (\n <StyledMobileOption\n value={value}\n key={value}\n {...defaultValuePropMobile(value)}\n >\n {value}\n </StyledMobileOption>\n ))}\n </StyledMobileSelect>\n <Icon\n label=\"\"\n size=\"100\"\n fill={theme.colors['gray80']}\n style={{\n pointerEvents: 'none',\n position: 'absolute',\n right: '10px',\n top: '50%',\n transform: 'translateY(-50%)',\n }}\n >\n <ChevronDown style={{ position: 'absolute', right: '10px' }} />\n </Icon>\n </StyledSelectWrapper>\n ) : (\n <Select.Root\n onValueChange={(e) => setAnswer(e)}\n required={required}\n {...defaultValueProp}\n {...disabledProp}\n >\n <Select.Trigger data-test-id={`${id}-select-trigger`}>\n <Select.Label>{label}</Select.Label>\n <Select.Value />\n </Select.Trigger>\n <Select.Content\n css={{ zIndex: theme.zIndices.page }}\n data-test-id={`${id}-select-content`}\n >\n {values.map((value) => (\n <Select.Item value={value} key={value}>\n {value}\n </Select.Item>\n ))}\n </Select.Content>\n </Select.Root>\n );\n};\n","import React, { useState, useEffect } from 'react';\nimport { Select, styled } from '@washingtonpost/wpds-ui-kit';\nimport { Attribute, AttributeValue, IngestType } from '../../interfaces';\nimport { ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';\nimport { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';\nimport { Dropdown } from './Dropdown';\n\ninterface DESelectProps {\n source: string;\n fieldName: string;\n label?: string;\n dataDictionaryConfig?: Attribute;\n defaultValue?: string;\n disabled?: boolean;\n submit: boolean;\n onChange?: ({ value }: { value: string }) => void;\n onFinished?: ({\n isFinished,\n isError,\n }: {\n isFinished: boolean;\n isError: boolean;\n }) => void;\n valuesFilter?: (value: AttributeValue) => boolean;\n selectProps?: {\n root?: any;\n trigger?: any;\n label?: any;\n value?: any;\n content?: any;\n item?: any;\n };\n children?: React.ReactNode;\n}\n\nconst scriptSrc = `${\n ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static'\n ? 'https://www.washingtonpost.com/subscribe/static/'\n : ENDPOINTS.staticAssets\n}/de-utils/twpdeu.min.js`;\n\nexport const DESelect: React.FC<DESelectProps> = ({\n source,\n fieldName,\n label,\n dataDictionaryConfig,\n defaultValue,\n disabled,\n submit,\n onChange = () => {},\n onFinished = () => {},\n valuesFilter = () => true,\n children,\n}) => {\n const [config, setConfig] = useState(dataDictionaryConfig);\n\n const [selected, setSelected] = useState('');\n\n const scriptStatus = useScript(scriptSrc);\n\n useEffect(() => {\n const fetchConfig = async () => {\n try {\n const config = await window?.__twpdeu?.getFieldConfigs({ fieldName });\n if (config) {\n setConfig(config[0]);\n } else {\n console.error('unable to get config', fieldName);\n }\n } catch (e) {\n console.warn('unable to get config', fieldName, e);\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && !(children || config)) {\n fetchConfig();\n }\n }, [scriptStatus]);\n\n useEffect(() => {\n const submitSelected = async () => {\n try {\n // TODO: Log to GA?\n\n const result = await window?.__twpdeu?.push({\n submitData: { fieldName, value: selected },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\n });\n\n const isError =\n result === true\n ? false\n : result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n } catch (e) {\n onFinished({\n isFinished: false,\n isError: true,\n });\n }\n };\n\n if (scriptStatus === ScriptStatus.READY && submit && selected) {\n submitSelected();\n }\n }, [scriptStatus, submit]);\n\n const defaultValueProp = defaultValue && config ? { defaultValue } : {};\n\n const isLoading = !(children || config);\n\n const disabledProp = disabled || isLoading ? { disabled: true } : {};\n\n // sort and filter out archived values\n const values = config\n ? config.values\n .sort((a, b) => a.order - b.order)\n .filter((value) => value.archived !== true)\n .filter(valuesFilter)\n : [];\n\n return (\n <SelectWrapper>\n {children && (\n <Select.Root\n onValueChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n {...defaultValueProp}\n {...disabledProp}\n >\n {children}\n </Select.Root>\n )}\n {!children && !config && (\n <Dropdown\n id={'loading'}\n label={'Loading...'}\n values={[]}\n disabled={true}\n />\n )}\n {!children && config && (\n <Dropdown\n id={config.name}\n label={label || config.name}\n onChange={(e) => {\n setSelected(e);\n onChange({ value: e });\n }}\n values={values.map((value) => value.name)}\n defaultValue={defaultValue}\n disabled={disabled}\n />\n )}\n </SelectWrapper>\n );\n};\n\nconst SelectWrapper = styled('div', {\n boxSizing: 'border-box',\n display: 'flex',\n marginBottom: '$100',\n flexDirection: 'column',\n '& button': {\n padding: '1px 6px',\n },\n '& *': { boxSizing: 'border-box' },\n});\n"],"names":["CollectionBehaviors","COLLECT","DO_NOT_COLLECT","AttributesState","SUCCESS","IngestType","EXPLICIT","IMPLICIT","IngestResponseState","SYSTEM_ERROR","INVALID_TYPE","INVALID_IDENTIFIER","INVALID_DATA","INVALID_ATTRIBUTE_DEFINITION","INVALID_META_DEFINITION","UNAUTHENTICATED","MISMATCHED_IDENTIFIER","DISABLED_ATTRIBUTE_DEFINITION","hasRequiredPrivacyCookies","window","wp_usp","getCookie","countryCode","_WPGeo","WPGeo","country_code","base","ENDPOINTS","attributesCache","getAttributes","_ref","fieldName","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","attributes","e","console","debug","sendGAEvent","props","process","env","NODE_ENV","warn","dataLayer","eventData","push","sendToGA","submitData","value","source","event","action","category","label","section","subsection","ingest","type","wapo_login_id","jucid","localStorage","getItem","ga","payload","metadata","response","method","body","JSON","stringify","Error","attributeInfo","name","collection_behavior","StyledMobileSelect","styled","padding","display","justifyContent","width","backgroundColor","color","fontFamily","fontSize","fontWeight","lineHeight","paddingBlockRight","textOverflow","position","borderColor","borderRightWidth","borderRightColor","appearance","theme","colors","disabled","onDisabled","cursor","StyledSelectWrapper","maxWidth","borderRadius","borderStyle","borderWidth","StyledMobileOption","Dropdown","id","values","required","defaultValue","onChange","answer","setAnswer","useState","isMobileSize","useWindowSize","useEffect","disabledProp","defaultValueProp","defaultValuePropMobile","selected","React","target","placeholder","style","map","key","Icon","size","fill","pointerEvents","right","top","transform","ChevronDown","Select","Root","onValueChange","Trigger","Label","Value","Content","css","zIndex","zIndices","page","Item","scriptSrc","staticAssets","DESelect","dataDictionaryConfig","submit","onFinished","valuesFilter","children","config","setConfig","setSelected","scriptStatus","useScript","fetchConfig","_window","__twpdeu","getFieldConfigs","error","ScriptStatus","READY","submitSelected","_window2","result","explicit","isError","isFinished","isLoading","sort","a","b","order","filter","archived","SelectWrapper","boxSizing","marginBottom","flexDirection"],"mappings":";;;;;;MAQaA,mBAAmB,GAAG;EACjCC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE;;MAeLC,eAAe,GAAG;EAC7BC,OAAO,EAAE;;MAGEC,UAAU,GAAG;EACxBC,QAAQ,EAAE,UAAU;EACpBC,QAAQ,EAAE;;MAGCC,mBAAmB,GAAG;EACjCJ,OAAO,EAAE,KAAK;EACdK,YAAY,EAAE,KAAK;EACnBC,YAAY,EAAE,KAAK;EACnBC,kBAAkB,EAAE,KAAK;EACzBC,YAAY,EAAE,KAAK;EACnBC,4BAA4B,EAAE,KAAK;EACnCC,uBAAuB,EAAE,KAAK;EAC9BC,eAAe,EAAE,KAAK;EACtBC,qBAAqB,EAAE,KAAK;EAC5BC,6BAA6B,EAAE,KAAK;EACpCf,cAAc,EAAE;;;MC3CLgB,yBAAyB,GAAGA;;EACvC,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAO,KAAK;;EAGd,MAAMC,MAAM,GAAGC,SAAS,CAAC,QAAQ,CAAC;EAElC,MAAMC,WAAW,IAAAC,MAAA,GAAGC,KAAK,EAAE,cAAAD,MAAA,uBAA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|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"name": "de-inputs: utils",
|
|
37
37
|
"path": "dist/subs-de-inputs.esm.js",
|
|
38
38
|
"import": "{ getAttributes, ingest }",
|
|
39
|
-
"limit": "1 KB"
|
|
39
|
+
"limit": "1.5 KB"
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
"name": "de-inputs: DESelect",
|
|
43
43
|
"path": "dist/subs-de-inputs.esm.js",
|
|
44
44
|
"import": "{ DESelect }",
|
|
45
|
-
"limit": "2 KB"
|
|
45
|
+
"limit": "2.5 KB"
|
|
46
46
|
}
|
|
47
47
|
],
|
|
48
48
|
"devDependencies": {
|