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