@washingtonpost/subs-de-inputs 0.2.2-canary.0 → 0.2.3-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/subs-de-inputs.cjs.development.js +16 -0
- 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 +16 -0
- package/dist/subs-de-inputs.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -45,19 +45,26 @@ const hasRequiredPrivacyCookies = () => {
|
|
|
45
45
|
return !!(wp_usp && countryCode === 'US');
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
const DEBUG_FLAG = 'f_de_debug';
|
|
48
49
|
const base = `${subsSdk.ENDPOINTS.base}/de/v1`;
|
|
49
50
|
const attributesCache = {};
|
|
50
51
|
const getAttributes = async _ref => {
|
|
51
52
|
let {
|
|
52
53
|
fieldName
|
|
53
54
|
} = _ref;
|
|
55
|
+
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
56
|
+
if (debug) {
|
|
57
|
+
console.debug('getAttributes()');
|
|
58
|
+
}
|
|
54
59
|
if (attributesCache[fieldName]) {
|
|
60
|
+
if (debug) console.debug('getAttributes() > return cached info');
|
|
55
61
|
return attributesCache[fieldName];
|
|
56
62
|
}
|
|
57
63
|
const fieldNames = [fieldName];
|
|
58
64
|
try {
|
|
59
65
|
const url = new URL(`${base}/attributes`);
|
|
60
66
|
url.searchParams.set('attributes', fieldNames.join(','));
|
|
67
|
+
if (debug) console.debug(`getAttributes() > ${url.toString()}`);
|
|
61
68
|
const data = await fetch(url.toString(), {
|
|
62
69
|
credentials: 'include',
|
|
63
70
|
headers: subsSdk.JSON_HEADERS
|
|
@@ -84,18 +91,27 @@ const ingest = async _ref2 => {
|
|
|
84
91
|
type = IngestType.IMPLICIT,
|
|
85
92
|
source
|
|
86
93
|
} = _ref2;
|
|
94
|
+
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
95
|
+
if (debug) {
|
|
96
|
+
console.debug('ingest()');
|
|
97
|
+
}
|
|
87
98
|
const url = `${base}/ingest`;
|
|
88
99
|
const wapo_login_id = subsSdk.getCookie('wapo_login_id');
|
|
89
100
|
if (!hasRequiredPrivacyCookies()) {
|
|
101
|
+
if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');
|
|
90
102
|
throw new Error('does not satisfy cookie check');
|
|
91
103
|
}
|
|
92
104
|
let attributeInfo = attributesCache[fieldName];
|
|
93
105
|
if (!attributeInfo) {
|
|
106
|
+
if (debug) console.debug('ingest() > fetch attribute info');
|
|
94
107
|
attributeInfo = await getAttributes({
|
|
95
108
|
fieldName
|
|
96
109
|
});
|
|
110
|
+
} else {
|
|
111
|
+
if (debug) console.debug('ingest() > use cached attribute info');
|
|
97
112
|
}
|
|
98
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');
|
|
99
115
|
throw new Error('do not collect');
|
|
100
116
|
}
|
|
101
117
|
const jucid = localStorage.getItem('uuid');
|
|
@@ -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 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\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 if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n attributeInfo = await getAttributes({ fieldName });\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\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","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","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,iBAAS,CAAC,QAAQ,CAAC;EAElC,MAAMC,WAAW,IAAAC,MAAA,GAAGC,aAAK,EAAE,cAAAD,MAAA,uBAAPA,MAAA,CAASE,YAAY;EAEzC,OAAO,CAAC,EAAEL,MAAM,IAAIE,WAAW,KAAK,IAAI,CAAC;AAC3C,CAAC;;ACED,MAAMI,IAAI,MAAMC,iBA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Aa,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/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,iBAAS,CAAC,QAAQ,CAAC;EAElC,MAAMC,WAAW,IAAAC,MAAA,GAAGC,aAAK,EAAE,cAAAD,MAAA,uBAAPA,MAAA,CAASE,YAAY;EAEzC,OAAO,CAAC,EAAEL,MAAM,IAAIE,WAAW,KAAK,IAAI,CAAC;AAC3C,CAAC;;ACED,MAAMI,UAAU,GAAG,YAAY;AAE/B,MAAMC,IAAI,MAAMC,iBAAS,CAACD,YAAY;AAEtC,MAAME,eAAe,GAAwB,EAAE;AAC/C,MAAaC,aAAa,GAAsB,MAAAC,IAAA;MAAO;IACrDC;GAGD,GAAAD,IAAA;EACC,MAAME,KAAK,GAAGd,MAAM,CAACe,QAAQ,CAACC,MAAM,CAACC,QAAQ,CAACV,UAAU,CAAC;EAEzD,IAAIO,KAAK,EAAE;IACTI,OAAO,CAACJ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AM,CAACK,KAAK,OAAG,CACD,EACjBP,6BAACE,gBAAM,CAACM,OAAO;IACbC,GAAG,EAAE;MAAEC,MAAM,EAAEC,eAAK,CAACC,QAAQ,CAACC;KAAM;uBACnB9C,MAAM,CAACzB;KAEvBmD,MAAM,CAACqB,GAAG,CAAE9E,KAAK,IAChBgE,6BAACE,gBAAM,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,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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@washingtonpost/subs-sdk"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@washingtonpost/subs-sdk"),o=require("react"),s=(e=o)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@washingtonpost/wpds-ui-kit"),i=require("@washingtonpost/subs-hooks");const a={COLLECT:"COLLECT",DO_NOT_COLLECT:"DO_NOT_COLLECT"},r={EXPLICIT:"explicit",IMPLICIT:"implicit"},l=()=>{var e;if("undefined"==typeof window)return!1;const o=t.getCookie("wp_usp"),s=null===(e=t.WPGeo())||void 0===e?void 0:e.country_code;return!(!o||"US"!==s)},c=t.ENDPOINTS.base+"/de/v1",u={},d=async e=>{let{fieldName:o}=e;const s=window.location.search.includes("f_de_debug");if(s&&console.debug("getAttributes()"),u[o])return s&&console.debug("getAttributes() > return cached info"),u[o];const n=[o];try{const e=new URL(c+"/attributes");e.searchParams.set("attributes",n.join(",")),s&&console.debug("getAttributes() > "+e.toString());const i=await fetch(e.toString(),{credentials:"include",headers:t.JSON_HEADERS}),a=await i.json();if(i.ok&&a.status===t.ResponseStatus.SUCCESS){const e=a.attributes||[];return u[o]=e,e}return[]}catch(e){return console.debug(e),[]}},g=("https://subscribe.washingtonpost.com/static"===t.ENDPOINTS.staticAssets?"https://www.washingtonpost.com/subscribe/static/":t.ENDPOINTS.staticAssets)+"/de-utils/twpdeu.min.js",E=n.styled("div",{boxSizing:"border-box",display:"flex",marginBottom:"$100",flexDirection:"column","& button":{padding:"1px 6px"},"& *":{boxSizing:"border-box"}});exports.AttributesState={SUCCESS:"100"},exports.CollectionBehaviors=a,exports.DESelect=e=>{let{source:a,fieldName:l,label:c,dataDictionaryConfig:u,defaultValue:d,disabled:I,submit:S,onChange:b=(()=>{}),onFinished:p=(()=>{}),valuesFilter:m=(()=>!0),children:f}=e;const[T,h]=o.useState(u),[_,w]=o.useState(""),C=i.useScript(g);o.useEffect(()=>{C!==i.ScriptStatus.READY||f||T||(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:l}));t?h(t[0]):console.error("unable to get config",l)}catch(e){console.warn("unable to get config",l,e)}})()},[C]),o.useEffect(()=>{C===i.ScriptStatus.READY&&S&&_&&(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:l,value:_},type:null!=T&&T.explicit?r.EXPLICIT:r.IMPLICIT,source:a}));p({isFinished:!0,isError:!o||o.status!==t.ResponseStatus.SUCCESS})}catch(e){p({isFinished:!1,isError:!0})}})()},[C,S]);const N=d&&T?{defaultValue:d}:{},D=I||!f&&!T?{disabled:!0}:{},v=T?T.values.sort((e,t)=>e.order-t.order).filter(e=>!0!==e.archived).filter(m):[];return s.createElement(E,null,s.createElement(n.Select.Root,{onValueChange:e=>{b({value:e}),w(e)},...N,...D},f||null,!f&&!T&&s.createElement(s.Fragment,null,s.createElement(n.Select.Trigger,{"data-test-id":"select-trigger-loading"},s.createElement(n.Select.Label,null,c||"loading..."),s.createElement(n.Select.Value,null))),!f&&T&&s.createElement(s.Fragment,null,s.createElement(n.Select.Trigger,{"data-test-id":T.name+"-select-trigger"},s.createElement(n.Select.Label,null,c||T.name),s.createElement(n.Select.Value,null)),s.createElement(n.Select.Content,{css:{zIndex:n.theme.zIndices.page},"data-test-id":T.name+"-select-content"},v.map(e=>s.createElement(n.Select.Item,{value:e.name,key:e.name},e.name))))))},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=r,exports.getAttributes=d,exports.hasRequiredPrivacyCookies=l,exports.ingest=async e=>{let{submitData:{fieldName:o,value:s},type:n=r.IMPLICIT,source:i}=e;const g=window.location.search.includes("f_de_debug");g&&console.debug("ingest()");const E=c+"/ingest",I=t.getCookie("wapo_login_id");if(!l())throw g&&console.debug("ingest() > hasRequiredPrivacyCookies falsy"),new Error("does not satisfy cookie check");let S=u[o];if(S?g&&console.debug("ingest() > use cached attribute info"):(g&&console.debug("ingest() > fetch attribute info"),S=await d({fieldName:o})),S[0]&&S[0].name===o&&S[0].collection_behavior===a.DO_NOT_COLLECT)throw g&&console.debug("ingest() > do not collect"),new Error("do not collect");const b={jucid:localStorage.getItem("uuid"),ga:t.getCookie("_ga"),type:n,wapo_login_id:I,data:{[o]:[s]},metadata:{source:i}};try{const e=await fetch(E,{method:"POST",credentials:"include",headers:t.JSON_HEADERS,body:JSON.stringify(b)});return await e.json()}catch(e){return console.debug(e),null}};
|
|
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 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\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 if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n attributeInfo = await getAttributes({ fieldName });\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\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","fieldNames","url","URL","searchParams","set","join","data","fetch","toString","credentials","headers","JSON_HEADERS","json","ok","status","ResponseStatus","SUCCESS","attributes","e","console","debug","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,EAAGC,qBAAOD,SAAPA,EAASE,aAE7B,SAAUL,GAA0B,OAAhBE,ICGhBI,EAAUC,YAAUD,cAEpBE,EAAuC,GAChCC,EAAmCC,MAAAA,QAAOC,UACrDA,GAGDC,EACC,GAAIJ,EAAgBG,GAClB,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,KAAMS,IAAK/B,EAAMsB,MACxCtB,EAAMsB,wCHzHU,CACjCpE,QAAS,MACT8E,aAAc,MACdC,aAAc,MACdC,mBAAoB,MACpBC,aAAc,MACdC,6BAA8B,MAC9BC,wBAAyB,MACzBC,gBAAiB,MACjBC,sBAAuB,MACvBC,8BAA+B,MAC/BzH,eAAgB,uGEYgBgB,MAAAA,QAChCgE,YAAY/D,UAAEA,EAASgE,MAAEA,GAAOC,KAChCA,EAAOjF,EAAWE,SAAQgD,OAC1BA,GACDuE,EACC,MAAMtG,EAASR,YAET+G,EAAgBpH,YAAU,iBAEhC,IAAKH,IACH,MAAM,IAAIwH,MAAM,iCAGlB,IAAIC,EAAgB/G,EAAgBG,GAKpC,GAJK4G,IACHA,QAAsB9G,EAAc,CAAEE,UAAAA,KAItC4G,EAAc,IACdA,EAAc,GAAGtB,OAAStF,GAC1B4G,EAAc,GAAGC,sBAAwBhI,EAAoBE,eAE7D,MAAM,IAAI4H,MAAM,kBAGlB,MAGMG,EAAU,CACdC,MAJYC,aAAaC,QAAQ,QAKjCC,GAJS5H,YAAU,OAKnB2E,KAAAA,EACAyC,cAAAA,EACAlG,KAAM,CACJ2G,CAACnH,GAAY,CAACgE,IAEhBoD,SAAU,CAAElF,OAAAA,IAGd,IACE,MAAMmF,QAAiB5G,MAAMN,EAAK,CAChCmH,OAAQ,OACR3G,YAAa,UACbC,QAASC,eACT0G,KAAMC,KAAKC,UAAUX,KAKvB,aAFmBO,EAASvG,OAG5B,MAAOM,GAEP,OADAC,QAAQC,MAAMF,GACP"}
|
|
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,EAAGC,qBAAOD,SAAPA,EAASE,aAE7B,SAAUL,GAA0B,OAAhBE,ICKhBI,EAAUC,YAAUD,cAEpBE,EAAuC,GAChCC,EAAmCC,MAAAA,QAAOC,UACrDA,GAGDC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Aa,UACbC,QAASC,eACTwG,KAAMC,KAAKC,UAAUX,KAKvB,aAFmBO,EAASrG,OAG5B,MAAOM,GAEP,OADAnB,QAAQJ,MAAMuB,GACP"}
|
|
@@ -38,19 +38,26 @@ const hasRequiredPrivacyCookies = () => {
|
|
|
38
38
|
return !!(wp_usp && countryCode === 'US');
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
+
const DEBUG_FLAG = 'f_de_debug';
|
|
41
42
|
const base = `${ENDPOINTS.base}/de/v1`;
|
|
42
43
|
const attributesCache = {};
|
|
43
44
|
const getAttributes = async _ref => {
|
|
44
45
|
let {
|
|
45
46
|
fieldName
|
|
46
47
|
} = _ref;
|
|
48
|
+
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
49
|
+
if (debug) {
|
|
50
|
+
console.debug('getAttributes()');
|
|
51
|
+
}
|
|
47
52
|
if (attributesCache[fieldName]) {
|
|
53
|
+
if (debug) console.debug('getAttributes() > return cached info');
|
|
48
54
|
return attributesCache[fieldName];
|
|
49
55
|
}
|
|
50
56
|
const fieldNames = [fieldName];
|
|
51
57
|
try {
|
|
52
58
|
const url = new URL(`${base}/attributes`);
|
|
53
59
|
url.searchParams.set('attributes', fieldNames.join(','));
|
|
60
|
+
if (debug) console.debug(`getAttributes() > ${url.toString()}`);
|
|
54
61
|
const data = await fetch(url.toString(), {
|
|
55
62
|
credentials: 'include',
|
|
56
63
|
headers: JSON_HEADERS
|
|
@@ -77,18 +84,27 @@ const ingest = async _ref2 => {
|
|
|
77
84
|
type = IngestType.IMPLICIT,
|
|
78
85
|
source
|
|
79
86
|
} = _ref2;
|
|
87
|
+
const debug = window.location.search.includes(DEBUG_FLAG);
|
|
88
|
+
if (debug) {
|
|
89
|
+
console.debug('ingest()');
|
|
90
|
+
}
|
|
80
91
|
const url = `${base}/ingest`;
|
|
81
92
|
const wapo_login_id = getCookie('wapo_login_id');
|
|
82
93
|
if (!hasRequiredPrivacyCookies()) {
|
|
94
|
+
if (debug) console.debug('ingest() > hasRequiredPrivacyCookies falsy');
|
|
83
95
|
throw new Error('does not satisfy cookie check');
|
|
84
96
|
}
|
|
85
97
|
let attributeInfo = attributesCache[fieldName];
|
|
86
98
|
if (!attributeInfo) {
|
|
99
|
+
if (debug) console.debug('ingest() > fetch attribute info');
|
|
87
100
|
attributeInfo = await getAttributes({
|
|
88
101
|
fieldName
|
|
89
102
|
});
|
|
103
|
+
} else {
|
|
104
|
+
if (debug) console.debug('ingest() > use cached attribute info');
|
|
90
105
|
}
|
|
91
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');
|
|
92
108
|
throw new Error('do not collect');
|
|
93
109
|
}
|
|
94
110
|
const jucid = localStorage.getItem('uuid');
|
|
@@ -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 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\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 if (!hasRequiredPrivacyCookies()) {\n throw new Error('does not satisfy cookie check');\n }\n\n let attributeInfo = attributesCache[fieldName];\n if (!attributeInfo) {\n attributeInfo = await getAttributes({ fieldName });\n }\n\n if (\n attributeInfo[0] &&\n attributeInfo[0].name === fieldName &&\n attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT\n ) {\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","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","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,KAAK,IAAI,CAAC;AAC3C,CAAC;;ACED,MAAMI,IAAI,MAAMC,SAAS,CAACD,YAAY;AAEtC,MAAME,eAAe,GAAwB,EAAE;AAC/C,MAAaC,aAAa,GAAsB,MAAAC,IAAA;MAAO;IACrDC;GAGD,GAAAD,IAAA;EACC,IAAIF,eAAe,CAACG,SAAS,CAAC,EAAE;IAC9B,OAAOH,eAAe,CAACG,SAAS,CAAC;;EAGnC,MAAMC,UAAU,GAAG,CAACD,SAAS,CAAC;EAE9B,IAAI;IACF,MA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AAQ,GAAGA,QAAQ,GAAG,IAAI,EAC1B,CAACA,QAAQ,IAAI,CAACC,MAAM,IACnBiC,0CACEA,oBAACE,MAAM,CAACG,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/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,G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