@washingtonpost/subs-de-inputs 0.1.1 → 0.2.0-canary.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,462 +1,139 @@
1
- import { getCookie, WPGeo, JSON_HEADERS, ENDPOINTS, ResponseStatus } from '@washingtonpost/subs-sdk';
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
4
 
5
- var CollectionBehaviors = {
5
+ const CollectionBehaviors = {
6
6
  COLLECT: 'COLLECT',
7
7
  DO_NOT_COLLECT: 'DO_NOT_COLLECT'
8
8
  };
9
- var AttributesState = {
9
+ const AttributesState = {
10
10
  SUCCESS: '100'
11
11
  };
12
- var IngestResponseState = {
12
+ const IngestType = {
13
+ EXPLICIT: 'explicit',
14
+ IMPLICIT: 'implicit'
15
+ };
16
+ const IngestResponseState = {
13
17
  SUCCESS: '100',
14
18
  SYSTEM_ERROR: '101',
15
19
  INVALID_TYPE: '102',
16
20
  INVALID_IDENTIFIER: '103',
17
21
  INVALID_DATA: '104',
18
22
  INVALID_ATTRIBUTE_DEFINITION: '105',
19
- INVALID_META_DEFINITION: '106'
23
+ INVALID_META_DEFINITION: '106',
24
+ UNAUTHENTICATED: '107',
25
+ MISMATCHED_IDENTIFIER: '108'
20
26
  };
21
27
 
22
- var hasRequiredPrivacyCookies = function hasRequiredPrivacyCookies() {
28
+ const hasRequiredPrivacyCookies = () => {
23
29
  var _WPGeo;
24
30
  if (typeof window === 'undefined') {
25
31
  return false;
26
32
  }
27
- var wp_usp = getCookie('wp_usp');
28
- var countryCode = (_WPGeo = WPGeo()) == null ? void 0 : _WPGeo.country_code;
33
+ const wp_usp = getCookie('wp_usp');
34
+ const countryCode = (_WPGeo = WPGeo()) === null || _WPGeo === void 0 ? void 0 : _WPGeo.country_code;
29
35
  return !!(wp_usp && countryCode === 'US');
30
36
  };
31
37
 
32
- function _regeneratorRuntime() {
33
- _regeneratorRuntime = function () {
34
- return exports;
35
- };
36
- var exports = {},
37
- Op = Object.prototype,
38
- hasOwn = Op.hasOwnProperty,
39
- defineProperty = Object.defineProperty || function (obj, key, desc) {
40
- obj[key] = desc.value;
41
- },
42
- $Symbol = "function" == typeof Symbol ? Symbol : {},
43
- iteratorSymbol = $Symbol.iterator || "@@iterator",
44
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
45
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
46
- function define(obj, key, value) {
47
- return Object.defineProperty(obj, key, {
48
- value: value,
49
- enumerable: !0,
50
- configurable: !0,
51
- writable: !0
52
- }), obj[key];
53
- }
38
+ const base = `${ENDPOINTS.base}/de/v1`;
39
+ const attributesCache = {};
40
+ const getAttributes = async _ref => {
41
+ let {
42
+ fieldName
43
+ } = _ref;
44
+ if (attributesCache[fieldName]) {
45
+ return attributesCache[fieldName];
46
+ }
47
+ const fieldNames = [fieldName];
54
48
  try {
55
- define({}, "");
56
- } catch (err) {
57
- define = function (obj, key, value) {
58
- return obj[key] = value;
59
- };
60
- }
61
- function wrap(innerFn, outerFn, self, tryLocsList) {
62
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
63
- generator = Object.create(protoGenerator.prototype),
64
- context = new Context(tryLocsList || []);
65
- return defineProperty(generator, "_invoke", {
66
- value: makeInvokeMethod(innerFn, self, context)
67
- }), generator;
68
- }
69
- function tryCatch(fn, obj, arg) {
70
- try {
71
- return {
72
- type: "normal",
73
- arg: fn.call(obj, arg)
74
- };
75
- } catch (err) {
76
- return {
77
- type: "throw",
78
- arg: err
79
- };
80
- }
81
- }
82
- exports.wrap = wrap;
83
- var ContinueSentinel = {};
84
- function Generator() {}
85
- function GeneratorFunction() {}
86
- function GeneratorFunctionPrototype() {}
87
- var IteratorPrototype = {};
88
- define(IteratorPrototype, iteratorSymbol, function () {
89
- return this;
90
- });
91
- var getProto = Object.getPrototypeOf,
92
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
93
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
94
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
95
- function defineIteratorMethods(prototype) {
96
- ["next", "throw", "return"].forEach(function (method) {
97
- define(prototype, method, function (arg) {
98
- return this._invoke(method, arg);
99
- });
49
+ const url = new URL(`${base}/attributes`);
50
+ url.searchParams.set('attributes', fieldNames.join(','));
51
+ const data = await fetch(url.toString(), {
52
+ credentials: 'include',
53
+ headers: JSON_HEADERS
100
54
  });
101
- }
102
- function AsyncIterator(generator, PromiseImpl) {
103
- function invoke(method, arg, resolve, reject) {
104
- var record = tryCatch(generator[method], generator, arg);
105
- if ("throw" !== record.type) {
106
- var result = record.arg,
107
- value = result.value;
108
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
109
- invoke("next", value, resolve, reject);
110
- }, function (err) {
111
- invoke("throw", err, resolve, reject);
112
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
113
- result.value = unwrapped, resolve(result);
114
- }, function (error) {
115
- return invoke("throw", error, resolve, reject);
116
- });
117
- }
118
- reject(record.arg);
55
+ const json = await data.json();
56
+ if (data.ok && json.status === ResponseStatus.SUCCESS) {
57
+ const attributes = json.attributes || [];
58
+ attributesCache[fieldName] = attributes;
59
+ return attributes;
60
+ } else {
61
+ return [];
119
62
  }
120
- var previousPromise;
121
- defineProperty(this, "_invoke", {
122
- value: function (method, arg) {
123
- function callInvokeWithMethodAndArg() {
124
- return new PromiseImpl(function (resolve, reject) {
125
- invoke(method, arg, resolve, reject);
126
- });
127
- }
128
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
129
- }
130
- });
63
+ } catch (e) {
64
+ console.debug(e);
65
+ return [];
131
66
  }
132
- function makeInvokeMethod(innerFn, self, context) {
133
- var state = "suspendedStart";
134
- return function (method, arg) {
135
- if ("executing" === state) throw new Error("Generator is already running");
136
- if ("completed" === state) {
137
- if ("throw" === method) throw arg;
138
- return doneResult();
139
- }
140
- for (context.method = method, context.arg = arg;;) {
141
- var delegate = context.delegate;
142
- if (delegate) {
143
- var delegateResult = maybeInvokeDelegate(delegate, context);
144
- if (delegateResult) {
145
- if (delegateResult === ContinueSentinel) continue;
146
- return delegateResult;
147
- }
148
- }
149
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
150
- if ("suspendedStart" === state) throw state = "completed", context.arg;
151
- context.dispatchException(context.arg);
152
- } else "return" === context.method && context.abrupt("return", context.arg);
153
- state = "executing";
154
- var record = tryCatch(innerFn, self, context);
155
- if ("normal" === record.type) {
156
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
157
- return {
158
- value: record.arg,
159
- done: context.done
160
- };
161
- }
162
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
163
- }
164
- };
165
- }
166
- function maybeInvokeDelegate(delegate, context) {
167
- var methodName = context.method,
168
- method = delegate.iterator[methodName];
169
- if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
170
- var record = tryCatch(method, delegate.iterator, context.arg);
171
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
172
- var info = record.arg;
173
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
174
- }
175
- function pushTryEntry(locs) {
176
- var entry = {
177
- tryLoc: locs[0]
178
- };
179
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
180
- }
181
- function resetTryEntry(entry) {
182
- var record = entry.completion || {};
183
- record.type = "normal", delete record.arg, entry.completion = record;
184
- }
185
- function Context(tryLocsList) {
186
- this.tryEntries = [{
187
- tryLoc: "root"
188
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
189
- }
190
- function values(iterable) {
191
- if (iterable) {
192
- var iteratorMethod = iterable[iteratorSymbol];
193
- if (iteratorMethod) return iteratorMethod.call(iterable);
194
- if ("function" == typeof iterable.next) return iterable;
195
- if (!isNaN(iterable.length)) {
196
- var i = -1,
197
- next = function next() {
198
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
199
- return next.value = undefined, next.done = !0, next;
200
- };
201
- return next.next = next;
202
- }
203
- }
204
- return {
205
- next: doneResult
206
- };
207
- }
208
- function doneResult() {
209
- return {
210
- value: undefined,
211
- done: !0
212
- };
213
- }
214
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
215
- value: GeneratorFunctionPrototype,
216
- configurable: !0
217
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
218
- value: GeneratorFunction,
219
- configurable: !0
220
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
221
- var ctor = "function" == typeof genFun && genFun.constructor;
222
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
223
- }, exports.mark = function (genFun) {
224
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
225
- }, exports.awrap = function (arg) {
226
- return {
227
- __await: arg
228
- };
229
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
230
- return this;
231
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
232
- void 0 === PromiseImpl && (PromiseImpl = Promise);
233
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
234
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
235
- return result.done ? result.value : iter.next();
236
- });
237
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
238
- return this;
239
- }), define(Gp, "toString", function () {
240
- return "[object Generator]";
241
- }), exports.keys = function (val) {
242
- var object = Object(val),
243
- keys = [];
244
- for (var key in object) keys.push(key);
245
- return keys.reverse(), function next() {
246
- for (; keys.length;) {
247
- var key = keys.pop();
248
- if (key in object) return next.value = key, next.done = !1, next;
249
- }
250
- return next.done = !0, next;
251
- };
252
- }, exports.values = values, Context.prototype = {
253
- constructor: Context,
254
- reset: function (skipTempReset) {
255
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
256
- },
257
- stop: function () {
258
- this.done = !0;
259
- var rootRecord = this.tryEntries[0].completion;
260
- if ("throw" === rootRecord.type) throw rootRecord.arg;
261
- return this.rval;
262
- },
263
- dispatchException: function (exception) {
264
- if (this.done) throw exception;
265
- var context = this;
266
- function handle(loc, caught) {
267
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
268
- }
269
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
270
- var entry = this.tryEntries[i],
271
- record = entry.completion;
272
- if ("root" === entry.tryLoc) return handle("end");
273
- if (entry.tryLoc <= this.prev) {
274
- var hasCatch = hasOwn.call(entry, "catchLoc"),
275
- hasFinally = hasOwn.call(entry, "finallyLoc");
276
- if (hasCatch && hasFinally) {
277
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
278
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
279
- } else if (hasCatch) {
280
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
281
- } else {
282
- if (!hasFinally) throw new Error("try statement without catch or finally");
283
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
284
- }
285
- }
286
- }
287
- },
288
- abrupt: function (type, arg) {
289
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
290
- var entry = this.tryEntries[i];
291
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
292
- var finallyEntry = entry;
293
- break;
294
- }
295
- }
296
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
297
- var record = finallyEntry ? finallyEntry.completion : {};
298
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
299
- },
300
- complete: function (record, afterLoc) {
301
- if ("throw" === record.type) throw record.arg;
302
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
303
- },
304
- finish: function (finallyLoc) {
305
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
306
- var entry = this.tryEntries[i];
307
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
308
- }
67
+ };
68
+ const ingest = async _ref2 => {
69
+ let {
70
+ submitData: {
71
+ fieldName,
72
+ value
309
73
  },
310
- catch: function (tryLoc) {
311
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
312
- var entry = this.tryEntries[i];
313
- if (entry.tryLoc === tryLoc) {
314
- var record = entry.completion;
315
- if ("throw" === record.type) {
316
- var thrown = record.arg;
317
- resetTryEntry(entry);
318
- }
319
- return thrown;
320
- }
321
- }
322
- throw new Error("illegal catch attempt");
74
+ source
75
+ } = _ref2;
76
+ const url = `${base}/ingest`;
77
+ const wapo_login_id = getCookie('wapo_login_id');
78
+ if (!hasRequiredPrivacyCookies()) {
79
+ throw new Error('does not satisfy cookie check');
80
+ }
81
+ let attributeInfo = attributesCache[fieldName];
82
+ if (!attributeInfo) {
83
+ attributeInfo = await getAttributes({
84
+ fieldName
85
+ });
86
+ }
87
+ if (attributeInfo[0] && attributeInfo[0].name === fieldName && attributeInfo[0].collection_behavior === CollectionBehaviors.DO_NOT_COLLECT) {
88
+ throw new Error('do not collect');
89
+ }
90
+ const jucid = localStorage.getItem('uuid');
91
+ const ga = getCookie('_ga');
92
+ const payload = {
93
+ jucid,
94
+ ga,
95
+ type: IngestType.EXPLICIT,
96
+ wapo_login_id,
97
+ data: {
98
+ fieldName,
99
+ value
323
100
  },
324
- delegateYield: function (iterable, resultName, nextLoc) {
325
- return this.delegate = {
326
- iterator: values(iterable),
327
- resultName: resultName,
328
- nextLoc: nextLoc
329
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
101
+ metadata: {
102
+ source
330
103
  }
331
- }, exports;
332
- }
333
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
104
+ };
334
105
  try {
335
- var info = gen[key](arg);
336
- var value = info.value;
337
- } catch (error) {
338
- reject(error);
339
- return;
340
- }
341
- if (info.done) {
342
- resolve(value);
343
- } else {
344
- Promise.resolve(value).then(_next, _throw);
345
- }
346
- }
347
- function _asyncToGenerator(fn) {
348
- return function () {
349
- var self = this,
350
- args = arguments;
351
- return new Promise(function (resolve, reject) {
352
- var gen = fn.apply(self, args);
353
- function _next(value) {
354
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
355
- }
356
- function _throw(err) {
357
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
358
- }
359
- _next(undefined);
106
+ const response = await fetch(url, {
107
+ method: 'POST',
108
+ credentials: 'include',
109
+ headers: JSON_HEADERS,
110
+ body: JSON.stringify(payload)
360
111
  });
361
- };
362
- }
363
- function _extends() {
364
- _extends = Object.assign ? Object.assign.bind() : function (target) {
365
- for (var i = 1; i < arguments.length; i++) {
366
- var source = arguments[i];
367
- for (var key in source) {
368
- if (Object.prototype.hasOwnProperty.call(source, key)) {
369
- target[key] = source[key];
370
- }
371
- }
372
- }
373
- return target;
374
- };
375
- return _extends.apply(this, arguments);
376
- }
377
-
378
- var base = ENDPOINTS.base + "/de/v1";
379
- var attributesCache = {};
380
- var getAttributes = /*#__PURE__*/function () {
381
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
382
- var fieldName, fieldNames, url, data, json, attributes;
383
- return _regeneratorRuntime().wrap(function _callee$(_context) {
384
- while (1) switch (_context.prev = _context.next) {
385
- case 0:
386
- fieldName = _ref.fieldName;
387
- if (!attributesCache[fieldName]) {
388
- _context.next = 3;
389
- break;
390
- }
391
- return _context.abrupt("return", attributesCache[fieldName]);
392
- case 3:
393
- fieldNames = [fieldName];
394
- _context.prev = 4;
395
- url = new URL(base + "/attributes");
396
- url.searchParams.set('attributes', fieldNames.join(','));
397
- _context.next = 9;
398
- return fetch(url.toString(), {
399
- credentials: 'include',
400
- headers: JSON_HEADERS
401
- });
402
- case 9:
403
- data = _context.sent;
404
- _context.next = 12;
405
- return data.json();
406
- case 12:
407
- json = _context.sent;
408
- if (!(data.ok && json.status === ResponseStatus.SUCCESS)) {
409
- _context.next = 19;
410
- break;
411
- }
412
- attributes = json.attributes || [];
413
- attributesCache[fieldName] = attributes;
414
- return _context.abrupt("return", attributes);
415
- case 19:
416
- return _context.abrupt("return", []);
417
- case 20:
418
- _context.next = 26;
419
- break;
420
- case 22:
421
- _context.prev = 22;
422
- _context.t0 = _context["catch"](4);
423
- console.debug(_context.t0);
424
- return _context.abrupt("return", []);
425
- case 26:
426
- case "end":
427
- return _context.stop();
428
- }
429
- }, _callee, null, [[4, 22]]);
430
- }));
431
- return function getAttributes(_x) {
432
- return _ref2.apply(this, arguments);
433
- };
434
- }();
112
+ const json = await response.json();
113
+ return json;
114
+ } catch (e) {
115
+ console.debug(e);
116
+ return null;
117
+ }
118
+ };
435
119
 
436
- var DESelect = function DESelect(_ref) {
437
- var source = _ref.source,
438
- fieldName = _ref.fieldName,
439
- label = _ref.label,
440
- dataDictionaryConfig = _ref.dataDictionaryConfig,
441
- defaultValue = _ref.defaultValue,
442
- disabled = _ref.disabled,
443
- submit = _ref.submit,
444
- _ref$onChange = _ref.onChange,
445
- onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
446
- _ref$onFinished = _ref.onFinished,
447
- onFinished = _ref$onFinished === void 0 ? function () {} : _ref$onFinished,
448
- _ref$valuesFilter = _ref.valuesFilter,
449
- valuesFilter = _ref$valuesFilter === void 0 ? function () {
450
- return true;
451
- } : _ref$valuesFilter,
452
- children = _ref.children;
453
- var _useState = useState(dataDictionaryConfig),
454
- config = _useState[0],
455
- setConfig = _useState[1];
456
- var _useState2 = useState(''),
457
- selected = _useState2[0],
458
- setSelected = _useState2[1];
459
- useEffect(function () {
120
+ const DESelect = _ref => {
121
+ let {
122
+ source,
123
+ fieldName,
124
+ label,
125
+ dataDictionaryConfig,
126
+ defaultValue,
127
+ disabled,
128
+ submit,
129
+ onChange = () => {},
130
+ onFinished = () => {},
131
+ valuesFilter = () => true,
132
+ children
133
+ } = _ref;
134
+ const [config, setConfig] = useState(dataDictionaryConfig);
135
+ const [selected, setSelected] = useState('');
136
+ useEffect(() => {
460
137
  if (children) {
461
138
  if (process.env.NODE_ENV !== "production") {
462
139
  console.debug('childen props', children);
@@ -464,77 +141,72 @@ var DESelect = function DESelect(_ref) {
464
141
  return;
465
142
  }
466
143
  if (!config) {
467
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
468
- var config;
469
- return _regeneratorRuntime().wrap(function _callee$(_context) {
470
- while (1) switch (_context.prev = _context.next) {
471
- case 0:
472
- _context.next = 2;
473
- return getAttributes({
474
- fieldName: fieldName
475
- });
476
- case 2:
477
- config = _context.sent;
478
- if (process.env.NODE_ENV !== "production") {
479
- console.debug('config from API', config);
480
- }
481
- setConfig(config[0]);
482
- case 5:
483
- case "end":
484
- return _context.stop();
485
- }
486
- }, _callee);
487
- }))();
144
+ (async () => {
145
+ // TODO: Switch to window.__twpdeu.getFieldConfigs
146
+ const config = await getAttributes({
147
+ fieldName
148
+ });
149
+ if (process.env.NODE_ENV !== "production") {
150
+ console.debug('config from API', config);
151
+ }
152
+ setConfig(config[0]);
153
+ })();
488
154
  }
489
155
  }, []);
490
- useEffect(function () {
491
- if (submit && selected) {
492
- if (process.env.NODE_ENV !== "production") {
493
- console.error('push not implemented', selected, source);
156
+ useEffect(() => {
157
+ (async () => {
158
+ if (submit && selected) {
159
+ // TODO: Switch to window.__twpdeu.push
160
+ // TODO: Log to GA
161
+ // TODO: Differentiate between explicit and implicit inputs?
162
+ const result = await ingest({
163
+ submitData: {
164
+ fieldName,
165
+ value: selected
166
+ },
167
+ source
168
+ });
169
+ const isError = result ? result.status !== ResponseStatus.SUCCESS : true;
170
+ onFinished({
171
+ isFinished: true,
172
+ isError
173
+ });
494
174
  }
495
- onFinished({
496
- isFinished: true,
497
- isError: false
498
- });
499
- }
175
+ })();
500
176
  }, [submit, selected]);
501
177
  if (!(children || config)) {
502
178
  return React.createElement("span", null, "loading");
503
179
  }
504
- var defaultValueProp = defaultValue ? {
505
- defaultValue: defaultValue
180
+ const defaultValueProp = defaultValue ? {
181
+ defaultValue
506
182
  } : {};
507
- var disabledProp = disabled ? {
183
+ const disabledProp = disabled ? {
508
184
  disabled: true
509
185
  } : {};
510
186
  // sort and filter out archived values
511
- var values = config ? config.values.sort(function (a, b) {
512
- return a.order - b.order;
513
- }).filter(function (value) {
514
- return value.archived !== true;
515
- }).filter(valuesFilter) : [];
516
- return React.createElement(SelectWrapper, null, React.createElement(Select.Root, _extends({
517
- onValueChange: function onValueChange(e) {
187
+ const values = config ? config.values.sort((a, b) => a.order - b.order).filter(value => value.archived !== true).filter(valuesFilter) : [];
188
+ return React.createElement(SelectWrapper, null, React.createElement(Select.Root, {
189
+ onValueChange: e => {
518
190
  onChange({
519
191
  value: e
520
192
  });
521
193
  setSelected(e);
522
- }
523
- }, defaultValueProp, disabledProp), children ? children : null, !children && config && React.createElement(React.Fragment, null, React.createElement(Select.Trigger, {
524
- "data-test-id": config.name + "-select-trigger"
194
+ },
195
+ ...defaultValueProp,
196
+ ...disabledProp
197
+ }, children ? children : null, !children && config && React.createElement(React.Fragment, null, React.createElement(Select.Trigger, {
198
+ "data-test-id": `${config.name}-select-trigger`
525
199
  }, React.createElement(Select.Label, null, label || config.name), React.createElement(Select.Value, null)), React.createElement(Select.Content, {
526
200
  css: {
527
201
  zIndex: theme.zIndices.page
528
202
  },
529
- "data-test-id": config.name + "-select-content"
530
- }, values.map(function (value) {
531
- return React.createElement(Select.Item, {
532
- value: value.name,
533
- key: value.name
534
- }, value.name);
535
- })))));
203
+ "data-test-id": `${config.name}-select-content`
204
+ }, values.map(value => React.createElement(Select.Item, {
205
+ value: value.name,
206
+ key: value.name
207
+ }, value.name))))));
536
208
  };
537
- var SelectWrapper = /*#__PURE__*/styled('div', {
209
+ const SelectWrapper = /*#__PURE__*/styled('div', {
538
210
  boxSizing: 'border-box',
539
211
  display: 'flex',
540
212
  marginBottom: '$100',
@@ -547,5 +219,5 @@ var SelectWrapper = /*#__PURE__*/styled('div', {
547
219
  }
548
220
  });
549
221
 
550
- export { AttributesState, CollectionBehaviors, DESelect, IngestResponseState, getAttributes, hasRequiredPrivacyCookies };
222
+ export { AttributesState, CollectionBehaviors, DESelect, IngestResponseState, IngestType, getAttributes, hasRequiredPrivacyCookies, ingest };
551
223
  //# sourceMappingURL=subs-de-inputs.esm.js.map