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