@washingtonpost/subs-de-inputs 0.2.0-canary.1 → 0.2.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/interfaces/index.d.ts +2 -0
- package/dist/services/dataEnrichment.d.ts +2 -1
- package/dist/subs-de-inputs.cjs.development.js +37 -23
- 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 +37 -23
- package/dist/subs-de-inputs.esm.js.map +1 -1
- package/package.json +3 -4
|
@@ -8,8 +8,9 @@ export declare const ingest: IngestType;
|
|
|
8
8
|
declare type IngestType = ({ submitData: { fieldName, value }, source, }: {
|
|
9
9
|
submitData: {
|
|
10
10
|
fieldName: string;
|
|
11
|
-
value: string;
|
|
11
|
+
value: string[];
|
|
12
12
|
};
|
|
13
|
+
type: (typeof IngestType)[keyof typeof IngestType];
|
|
13
14
|
source: string;
|
|
14
15
|
}) => Promise<{
|
|
15
16
|
status: ResponseStatus;
|
|
@@ -8,6 +8,7 @@ var subsSdk = require('@washingtonpost/subs-sdk');
|
|
|
8
8
|
var React = require('react');
|
|
9
9
|
var React__default = _interopDefault(React);
|
|
10
10
|
var wpdsUiKit = require('@washingtonpost/wpds-ui-kit');
|
|
11
|
+
var subsHooks = require('@washingtonpost/subs-hooks');
|
|
11
12
|
|
|
12
13
|
const CollectionBehaviors = {
|
|
13
14
|
COLLECT: 'COLLECT',
|
|
@@ -29,7 +30,9 @@ const IngestResponseState = {
|
|
|
29
30
|
INVALID_ATTRIBUTE_DEFINITION: '105',
|
|
30
31
|
INVALID_META_DEFINITION: '106',
|
|
31
32
|
UNAUTHENTICATED: '107',
|
|
32
|
-
MISMATCHED_IDENTIFIER: '108'
|
|
33
|
+
MISMATCHED_IDENTIFIER: '108',
|
|
34
|
+
DISABLED_ATTRIBUTE_DEFINITION: '109',
|
|
35
|
+
DO_NOT_COLLECT: '110'
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
const hasRequiredPrivacyCookies = () => {
|
|
@@ -78,6 +81,7 @@ const ingest = async _ref2 => {
|
|
|
78
81
|
fieldName,
|
|
79
82
|
value
|
|
80
83
|
},
|
|
84
|
+
type,
|
|
81
85
|
source
|
|
82
86
|
} = _ref2;
|
|
83
87
|
const url = `${base}/ingest`;
|
|
@@ -99,7 +103,7 @@ const ingest = async _ref2 => {
|
|
|
99
103
|
const payload = {
|
|
100
104
|
jucid,
|
|
101
105
|
ga,
|
|
102
|
-
type
|
|
106
|
+
type,
|
|
103
107
|
wapo_login_id,
|
|
104
108
|
data: {
|
|
105
109
|
fieldName,
|
|
@@ -124,6 +128,7 @@ const ingest = async _ref2 => {
|
|
|
124
128
|
}
|
|
125
129
|
};
|
|
126
130
|
|
|
131
|
+
const scriptSrc = `${subsSdk.ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static' ? 'https://www.washingtonpost.com/subscribe/static/' : subsSdk.ENDPOINTS.staticAssets}/de-utils/twpdeu.min.js`;
|
|
127
132
|
const DESelect = _ref => {
|
|
128
133
|
let {
|
|
129
134
|
source,
|
|
@@ -140,37 +145,38 @@ const DESelect = _ref => {
|
|
|
140
145
|
} = _ref;
|
|
141
146
|
const [config, setConfig] = React.useState(dataDictionaryConfig);
|
|
142
147
|
const [selected, setSelected] = React.useState('');
|
|
148
|
+
const scriptStatus = subsHooks.useScript(scriptSrc);
|
|
143
149
|
React.useEffect(() => {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (!config) {
|
|
151
|
-
(async () => {
|
|
152
|
-
// TODO: Switch to window.__twpdeu.getFieldConfigs
|
|
153
|
-
const config = await getAttributes({
|
|
150
|
+
const fetchConfig = async () => {
|
|
151
|
+
try {
|
|
152
|
+
var _window;
|
|
153
|
+
const config = await ((_window = window) === null || _window === void 0 || (_window = _window.__twpdeu) === null || _window === void 0 ? void 0 : _window.getFieldConfigs({
|
|
154
154
|
fieldName
|
|
155
|
-
});
|
|
156
|
-
if (
|
|
157
|
-
|
|
155
|
+
}));
|
|
156
|
+
if (config) {
|
|
157
|
+
setConfig(config[0]);
|
|
158
|
+
} else {
|
|
159
|
+
console.error('unable to get config', fieldName);
|
|
158
160
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.warn('unable to get config', fieldName, e);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
if (scriptStatus === subsHooks.ScriptStatus.READY && !(children || config)) {
|
|
166
|
+
fetchConfig();
|
|
161
167
|
}
|
|
162
|
-
}, []);
|
|
168
|
+
}, [scriptStatus]);
|
|
163
169
|
React.useEffect(() => {
|
|
164
|
-
|
|
165
|
-
|
|
170
|
+
const submitSelected = async () => {
|
|
171
|
+
try {
|
|
166
172
|
// TODO: Switch to window.__twpdeu.push
|
|
167
173
|
// TODO: Log to GA
|
|
168
|
-
// TODO: Differentiate between explicit and implicit inputs?
|
|
169
174
|
const result = await ingest({
|
|
170
175
|
submitData: {
|
|
171
176
|
fieldName,
|
|
172
|
-
value: selected
|
|
177
|
+
value: [selected]
|
|
173
178
|
},
|
|
179
|
+
type: config !== null && config !== void 0 && config.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,
|
|
174
180
|
source
|
|
175
181
|
});
|
|
176
182
|
const isError = result ? result.status !== subsSdk.ResponseStatus.SUCCESS : true;
|
|
@@ -178,8 +184,16 @@ const DESelect = _ref => {
|
|
|
178
184
|
isFinished: true,
|
|
179
185
|
isError
|
|
180
186
|
});
|
|
187
|
+
} catch (e) {
|
|
188
|
+
onFinished({
|
|
189
|
+
isFinished: false,
|
|
190
|
+
isError: true
|
|
191
|
+
});
|
|
181
192
|
}
|
|
182
|
-
}
|
|
193
|
+
};
|
|
194
|
+
if (submit && selected) {
|
|
195
|
+
submitSelected();
|
|
196
|
+
}
|
|
183
197
|
}, [submit, selected]);
|
|
184
198
|
if (!(children || config)) {
|
|
185
199
|
return React__default.createElement("span", null, "loading");
|
|
@@ -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} 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 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: IngestType.EXPLICIT,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n fieldName,\n 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 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 } from '../../interfaces';\nimport { getAttributes, ingest } from '../../services/dataEnrichment';\nimport { ResponseStatus } from '@washingtonpost/subs-sdk';\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\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 useEffect(() => {\n if (children) {\n if (__DEV__) {\n console.debug('childen props', children);\n }\n return;\n }\n\n if (!config) {\n (async () => {\n // TODO: Switch to window.__twpdeu.getFieldConfigs\n const config = await getAttributes({ fieldName });\n if (__DEV__) {\n console.debug('config from API', config);\n }\n setConfig(config[0]);\n })();\n }\n }, []);\n\n useEffect(() => {\n (async () => {\n if (submit && selected) {\n // TODO: Switch to window.__twpdeu.push\n // TODO: Log to GA\n // TODO: Differentiate between explicit and implicit inputs?\n const result = await ingest({\n submitData: { fieldName, value: selected },\n source,\n });\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n }\n })();\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { 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={`${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","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","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","type","metadata","response","method","body","JSON","stringify","DESelect","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","useEffect","process","env","NODE_ENV","result","isError","isFinished","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","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;;;MCzCZC,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,iBAAS,CAACD,YAAY;AAEtC,MAAME,eAAe,GAAwB,EAAE;AAC/C,MAAaC,aAAa,GAAsB,MAAAC,IAAA;MAAO;IACrDC;GAGD,GAAAD,IAAA;EACC,IAAIF,eAAe,CAACG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AAY,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/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,\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,\n 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 { ingest } from '../../services/dataEnrichment';\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: Switch to window.__twpdeu.push\n // TODO: Log to GA\n const result = await ingest({\n submitData: { fieldName, value: [selected] },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\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 (submit && selected) {\n submitSelected();\n }\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { 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={`${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","result","explicit","isError","isFinished","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","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,uBA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AAM;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"),s=require("react"),a=(e=s)&&"object"==typeof e&&"default"in e?e.default:e,o=require("@washingtonpost/wpds-ui-kit"),i=require("@washingtonpost/subs-hooks");const n={COLLECT:"COLLECT",DO_NOT_COLLECT:"DO_NOT_COLLECT"},r={EXPLICIT:"explicit",IMPLICIT:"implicit"},l=()=>{var e;if("undefined"==typeof window)return!1;const s=t.getCookie("wp_usp"),a=null===(e=t.WPGeo())||void 0===e?void 0:e.country_code;return!(!s||"US"!==a)},c=t.ENDPOINTS.base+"/de/v1",u={},d=async e=>{let{fieldName:s}=e;if(u[s])return u[s];const a=[s];try{const e=new URL(c+"/attributes");e.searchParams.set("attributes",a.join(","));const o=await fetch(e.toString(),{credentials:"include",headers:t.JSON_HEADERS}),i=await o.json();if(o.ok&&i.status===t.ResponseStatus.SUCCESS){const e=i.attributes||[];return u[s]=e,e}return[]}catch(e){return console.debug(e),[]}},E=async e=>{let{submitData:{fieldName:s,value:a},type:o,source:i}=e;const r=c+"/ingest",E=t.getCookie("wapo_login_id");if(!l())throw new Error("does not satisfy cookie check");let I=u[s];if(I||(I=await d({fieldName:s})),I[0]&&I[0].name===s&&I[0].collection_behavior===n.DO_NOT_COLLECT)throw new Error("do not collect");const S={jucid:localStorage.getItem("uuid"),ga:t.getCookie("_ga"),type:o,wapo_login_id:E,data:{fieldName:s,value:a},metadata:{source:i}};try{const e=await fetch(r,{method:"POST",credentials:"include",headers:t.JSON_HEADERS,body:JSON.stringify(S)});return await e.json()}catch(e){return console.debug(e),null}},I=("https://subscribe.washingtonpost.com/static"===t.ENDPOINTS.staticAssets?"https://www.washingtonpost.com/subscribe/static/":t.ENDPOINTS.staticAssets)+"/de-utils/twpdeu.min.js",S=o.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:n,fieldName:l,label:c,dataDictionaryConfig:u,defaultValue:d,disabled:p,submit:g,onChange:m=(()=>{}),onFinished:T=(()=>{}),valuesFilter:f=(()=>!0),children:C}=e;const[N,b]=s.useState(u),[_,h]=s.useState(""),w=i.useScript(I);if(s.useEffect(()=>{w!==i.ScriptStatus.READY||C||N||(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?b(t[0]):console.error("unable to get config",l)}catch(e){console.warn("unable to get config",l,e)}})()},[w]),s.useEffect(()=>{g&&_&&(async()=>{try{const e=await E({submitData:{fieldName:l,value:[_]},type:null!=N&&N.explicit?r.EXPLICIT:r.IMPLICIT,source:n});T({isFinished:!0,isError:!e||e.status!==t.ResponseStatus.SUCCESS})}catch(e){T({isFinished:!1,isError:!0})}})()},[g,_]),!C&&!N)return a.createElement("span",null,"loading");const D=d?{defaultValue:d}:{},O=p?{disabled:!0}:{},y=N?N.values.sort((e,t)=>e.order-t.order).filter(e=>!0!==e.archived).filter(f):[];return a.createElement(S,null,a.createElement(o.Select.Root,{onValueChange:e=>{m({value:e}),h(e)},...D,...O},C||null,!C&&N&&a.createElement(a.Fragment,null,a.createElement(o.Select.Trigger,{"data-test-id":N.name+"-select-trigger"},a.createElement(o.Select.Label,null,c||N.name),a.createElement(o.Select.Value,null)),a.createElement(o.Select.Content,{css:{zIndex:o.theme.zIndices.page},"data-test-id":N.name+"-select-content"},y.map(e=>a.createElement(o.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=E;
|
|
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} 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 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: IngestType.EXPLICIT,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n fieldName,\n 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 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 } from '../../interfaces';\nimport { getAttributes, ingest } from '../../services/dataEnrichment';\nimport { ResponseStatus } from '@washingtonpost/subs-sdk';\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\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 useEffect(() => {\n if (children) {\n if (__DEV__) {\n console.debug('childen props', children);\n }\n return;\n }\n\n if (!config) {\n (async () => {\n // TODO: Switch to window.__twpdeu.getFieldConfigs\n const config = await getAttributes({ fieldName });\n if (__DEV__) {\n console.debug('config from API', config);\n }\n setConfig(config[0]);\n })();\n }\n }, []);\n\n useEffect(() => {\n (async () => {\n if (submit && selected) {\n // TODO: Switch to window.__twpdeu.push\n // TODO: Log to GA\n // TODO: Differentiate between explicit and implicit inputs?\n const result = await ingest({\n submitData: { fieldName, value: selected },\n source,\n });\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n }\n })();\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { 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={`${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","ingest","submitData","value","source","_ref2","wapo_login_id","Error","attributeInfo","name","collection_behavior","payload","jucid","localStorage","getItem","ga","type","metadata","response","method","body","JSON","stringify","SelectWrapper","styled","boxSizing","display","marginBottom","flexDirection","& button","padding","& *","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","useEffect","process","env","NODE_ENV","result","isFinished","isError","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","Select","Root","onValueChange","Trigger","Label","Value","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"],"mappings":"yOAQaA,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,OAAOH,EAAgBG,GAGzB,MAAME,EAAa,CAACF,GAEpB,IACE,MAAMG,EAAM,IAAIC,IAAOT,iBACvBQ,EAAIE,aAAaC,IAAI,aAAcJ,EAAWK,KAAK,MAEnD,MAAMC,QAAaC,MAAMN,EAAIO,WAAY,CACvCC,YAAa,UACbC,QAASC,iBAELC,QAAaN,EAAKM,OAExB,GAAIN,EAAKO,IAAMD,EAAKE,SAAWC,iBAAeC,QAAS,CACrD,MAAMC,EAAaL,EAAKK,YAAc,GAEt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pBC,aAAc,MACdC,6BAA8B,MAC9BC,wBAAyB,MACzBC,gBAAiB,MACjBC,sBAAuB"}
|
|
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,\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,\n 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 { ingest } from '../../services/dataEnrichment';\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: Switch to window.__twpdeu.push\n // TODO: Log to GA\n const result = await ingest({\n submitData: { fieldName, value: [selected] },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\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 (submit && selected) {\n submitSelected();\n }\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { 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={`${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","ingest","submitData","value","type","source","_ref2","wapo_login_id","Error","attributeInfo","name","collection_behavior","payload","jucid","localStorage","getItem","ga","metadata","response","method","body","JSON","stringify","scriptSrc","staticAssets","SelectWrapper","styled","boxSizing","display","marginBottom","flexDirection","& button","padding","& *","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","result","explicit","isFinished","isError","submitSelected","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","Select","Root","onValueChange","Trigger","Label","Value","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"],"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,OAAOH,EAAgBG,GAGzB,MAAME,EAAa,CAACF,GAEpB,IACE,MAAMG,EAAM,IAAIC,IAAOT,iBACvBQ,EAAIE,aAAaC,IAAI,aAAcJ,E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OAAO/B,GACV,GAEJ,OACEuB,gBAACvC,OACCuC,gBAACU,SAAOC,MACNC,cAAgB9E,IACdyC,EAAS,CAAEpC,MAAOL,IAClBiD,EAAYjD,OAEVmE,KACAC,GAEHxB,GAAsB,MACrBA,GAAYC,GACZqB,gCACEA,gBAACU,SAAOG,wBAAyBlC,EAAOjC,wBACtCsD,gBAACU,SAAOI,WAAO5C,GAASS,EAAOjC,MAC/BsD,gBAACU,SAAOK,aAEVf,gBAACU,SAAOM,SACNC,IAAK,CAAEC,OAAQC,QAAMC,SAASC,qBACb1C,EAAOjC,wBAEvByD,EAAOmB,IAAKnF,GACX6D,gBAACU,SAAOa,MAAKpF,MAAOA,EAAMO,KAAM8E,IAAKrF,EAAMO,MACxCP,EAAMO,wCHnHU,CACjCd,QAAS,MACT6F,aAAc,MACdC,aAAc,MACdC,mBAAoB,MACpBC,aAAc,MACdC,6BAA8B,MAC9BC,wBAAyB,MACzBC,gBAAiB,MACjBC,sBAAuB,MACvBC,8BAA+B,MAC/BxI,eAAgB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getCookie, WPGeo, JSON_HEADERS, ResponseStatus, ENDPOINTS } from '@washingtonpost/subs-sdk';
|
|
2
2
|
import React, { useState, useEffect } from 'react';
|
|
3
3
|
import { Select, theme, styled } from '@washingtonpost/wpds-ui-kit';
|
|
4
|
+
import { useScript, ScriptStatus } from '@washingtonpost/subs-hooks';
|
|
4
5
|
|
|
5
6
|
const CollectionBehaviors = {
|
|
6
7
|
COLLECT: 'COLLECT',
|
|
@@ -22,7 +23,9 @@ const IngestResponseState = {
|
|
|
22
23
|
INVALID_ATTRIBUTE_DEFINITION: '105',
|
|
23
24
|
INVALID_META_DEFINITION: '106',
|
|
24
25
|
UNAUTHENTICATED: '107',
|
|
25
|
-
MISMATCHED_IDENTIFIER: '108'
|
|
26
|
+
MISMATCHED_IDENTIFIER: '108',
|
|
27
|
+
DISABLED_ATTRIBUTE_DEFINITION: '109',
|
|
28
|
+
DO_NOT_COLLECT: '110'
|
|
26
29
|
};
|
|
27
30
|
|
|
28
31
|
const hasRequiredPrivacyCookies = () => {
|
|
@@ -71,6 +74,7 @@ const ingest = async _ref2 => {
|
|
|
71
74
|
fieldName,
|
|
72
75
|
value
|
|
73
76
|
},
|
|
77
|
+
type,
|
|
74
78
|
source
|
|
75
79
|
} = _ref2;
|
|
76
80
|
const url = `${base}/ingest`;
|
|
@@ -92,7 +96,7 @@ const ingest = async _ref2 => {
|
|
|
92
96
|
const payload = {
|
|
93
97
|
jucid,
|
|
94
98
|
ga,
|
|
95
|
-
type
|
|
99
|
+
type,
|
|
96
100
|
wapo_login_id,
|
|
97
101
|
data: {
|
|
98
102
|
fieldName,
|
|
@@ -117,6 +121,7 @@ const ingest = async _ref2 => {
|
|
|
117
121
|
}
|
|
118
122
|
};
|
|
119
123
|
|
|
124
|
+
const scriptSrc = `${ENDPOINTS.staticAssets === 'https://subscribe.washingtonpost.com/static' ? 'https://www.washingtonpost.com/subscribe/static/' : ENDPOINTS.staticAssets}/de-utils/twpdeu.min.js`;
|
|
120
125
|
const DESelect = _ref => {
|
|
121
126
|
let {
|
|
122
127
|
source,
|
|
@@ -133,37 +138,38 @@ const DESelect = _ref => {
|
|
|
133
138
|
} = _ref;
|
|
134
139
|
const [config, setConfig] = useState(dataDictionaryConfig);
|
|
135
140
|
const [selected, setSelected] = useState('');
|
|
141
|
+
const scriptStatus = useScript(scriptSrc);
|
|
136
142
|
useEffect(() => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
if (!config) {
|
|
144
|
-
(async () => {
|
|
145
|
-
// TODO: Switch to window.__twpdeu.getFieldConfigs
|
|
146
|
-
const config = await getAttributes({
|
|
143
|
+
const fetchConfig = async () => {
|
|
144
|
+
try {
|
|
145
|
+
var _window;
|
|
146
|
+
const config = await ((_window = window) === null || _window === void 0 || (_window = _window.__twpdeu) === null || _window === void 0 ? void 0 : _window.getFieldConfigs({
|
|
147
147
|
fieldName
|
|
148
|
-
});
|
|
149
|
-
if (
|
|
150
|
-
|
|
148
|
+
}));
|
|
149
|
+
if (config) {
|
|
150
|
+
setConfig(config[0]);
|
|
151
|
+
} else {
|
|
152
|
+
console.error('unable to get config', fieldName);
|
|
151
153
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
} catch (e) {
|
|
155
|
+
console.warn('unable to get config', fieldName, e);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
if (scriptStatus === ScriptStatus.READY && !(children || config)) {
|
|
159
|
+
fetchConfig();
|
|
154
160
|
}
|
|
155
|
-
}, []);
|
|
161
|
+
}, [scriptStatus]);
|
|
156
162
|
useEffect(() => {
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
const submitSelected = async () => {
|
|
164
|
+
try {
|
|
159
165
|
// TODO: Switch to window.__twpdeu.push
|
|
160
166
|
// TODO: Log to GA
|
|
161
|
-
// TODO: Differentiate between explicit and implicit inputs?
|
|
162
167
|
const result = await ingest({
|
|
163
168
|
submitData: {
|
|
164
169
|
fieldName,
|
|
165
|
-
value: selected
|
|
170
|
+
value: [selected]
|
|
166
171
|
},
|
|
172
|
+
type: config !== null && config !== void 0 && config.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,
|
|
167
173
|
source
|
|
168
174
|
});
|
|
169
175
|
const isError = result ? result.status !== ResponseStatus.SUCCESS : true;
|
|
@@ -171,8 +177,16 @@ const DESelect = _ref => {
|
|
|
171
177
|
isFinished: true,
|
|
172
178
|
isError
|
|
173
179
|
});
|
|
180
|
+
} catch (e) {
|
|
181
|
+
onFinished({
|
|
182
|
+
isFinished: false,
|
|
183
|
+
isError: true
|
|
184
|
+
});
|
|
174
185
|
}
|
|
175
|
-
}
|
|
186
|
+
};
|
|
187
|
+
if (submit && selected) {
|
|
188
|
+
submitSelected();
|
|
189
|
+
}
|
|
176
190
|
}, [submit, selected]);
|
|
177
191
|
if (!(children || config)) {
|
|
178
192
|
return React.createElement("span", null, "loading");
|
|
@@ -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} 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 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: IngestType.EXPLICIT,\n wapo_login_id, // TODO: move this to BE to read from cookie headers\n data: {\n fieldName,\n 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 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 } from '../../interfaces';\nimport { getAttributes, ingest } from '../../services/dataEnrichment';\nimport { ResponseStatus } from '@washingtonpost/subs-sdk';\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\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 useEffect(() => {\n if (children) {\n if (__DEV__) {\n console.debug('childen props', children);\n }\n return;\n }\n\n if (!config) {\n (async () => {\n // TODO: Switch to window.__twpdeu.getFieldConfigs\n const config = await getAttributes({ fieldName });\n if (__DEV__) {\n console.debug('config from API', config);\n }\n setConfig(config[0]);\n })();\n }\n }, []);\n\n useEffect(() => {\n (async () => {\n if (submit && selected) {\n // TODO: Switch to window.__twpdeu.push\n // TODO: Log to GA\n // TODO: Differentiate between explicit and implicit inputs?\n const result = await ingest({\n submitData: { fieldName, value: selected },\n source,\n });\n const isError = result\n ? result.status !== ResponseStatus.SUCCESS\n : true;\n\n onFinished({\n isFinished: true,\n isError,\n });\n }\n })();\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { 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={`${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","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","source","wapo_login_id","Error","attributeInfo","name","collection_behavior","jucid","localStorage","getItem","ga","payload","type","metadata","response","method","body","JSON","stringify","DESelect","label","dataDictionaryConfig","defaultValue","disabled","submit","onChange","onFinished","valuesFilter","children","config","setConfig","useState","selected","setSelected","useEffect","process","env","NODE_ENV","result","isError","isFinished","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","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;;;MCzCZC,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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K,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 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,\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,\n 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 { ingest } from '../../services/dataEnrichment';\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: Switch to window.__twpdeu.push\n // TODO: Log to GA\n const result = await ingest({\n submitData: { fieldName, value: [selected] },\n type: config?.explicit ? IngestType.EXPLICIT : IngestType.IMPLICIT,\n source,\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 (submit && selected) {\n submitSelected();\n }\n }, [submit, selected]);\n\n if (!(children || config)) {\n return <span>loading</span>;\n }\n\n const defaultValueProp = defaultValue ? { defaultValue } : {};\n\n const disabledProp = disabled ? { 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={`${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","result","explicit","isError","isFinished","React","defaultValueProp","disabledProp","values","sort","a","b","order","filter","archived","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,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CACrB,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.1-canary.0",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
|
-
"main": "dist/index.js",
|
|
5
4
|
"typings": "dist/index.d.ts",
|
|
6
5
|
"files": [
|
|
7
6
|
"dist",
|
|
@@ -36,13 +35,13 @@
|
|
|
36
35
|
"name": "de-inputs: utils",
|
|
37
36
|
"path": "dist/subs-de-inputs.esm.js",
|
|
38
37
|
"import": "{ getAttributes, ingest }",
|
|
39
|
-
"limit": "
|
|
38
|
+
"limit": "1 KB"
|
|
40
39
|
},
|
|
41
40
|
{
|
|
42
41
|
"name": "de-inputs: DESelect",
|
|
43
42
|
"path": "dist/subs-de-inputs.esm.js",
|
|
44
43
|
"import": "{ DESelect }",
|
|
45
|
-
"limit": "
|
|
44
|
+
"limit": "2 KB"
|
|
46
45
|
}
|
|
47
46
|
],
|
|
48
47
|
"devDependencies": {
|