@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.
- package/dist/components/DESelect/index.d.ts +0 -5
- package/dist/index.d.ts +1 -0
- package/dist/interfaces/index.d.ts +6 -0
- package/dist/interfaces/twpdeu.d.ts +11 -0
- package/dist/services/dataEnrichment.d.ts +17 -2
- package/dist/subs-de-inputs.cjs.development.js +150 -476
- 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 +150 -478
- package/dist/subs-de-inputs.esm.js.map +1 -1
- package/package.json +21 -6
- package/CHANGELOG.md +0 -16
|
@@ -1,462 +1,139 @@
|
|
|
1
|
-
import { getCookie, WPGeo, JSON_HEADERS,
|
|
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
|
-
|
|
5
|
+
const CollectionBehaviors = {
|
|
6
6
|
COLLECT: 'COLLECT',
|
|
7
7
|
DO_NOT_COLLECT: 'DO_NOT_COLLECT'
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
const AttributesState = {
|
|
10
10
|
SUCCESS: '100'
|
|
11
11
|
};
|
|
12
|
-
|
|
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
|
-
|
|
28
|
+
const hasRequiredPrivacyCookies = () => {
|
|
23
29
|
var _WPGeo;
|
|
24
30
|
if (typeof window === 'undefined') {
|
|
25
31
|
return false;
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
|
|
325
|
-
|
|
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
|
-
}
|
|
332
|
-
}
|
|
333
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
104
|
+
};
|
|
334
105
|
try {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
onChange =
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
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(
|
|
491
|
-
|
|
492
|
-
if (
|
|
493
|
-
|
|
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
|
-
|
|
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
|
-
|
|
505
|
-
defaultValue
|
|
180
|
+
const defaultValueProp = defaultValue ? {
|
|
181
|
+
defaultValue
|
|
506
182
|
} : {};
|
|
507
|
-
|
|
183
|
+
const disabledProp = disabled ? {
|
|
508
184
|
disabled: true
|
|
509
185
|
} : {};
|
|
510
186
|
// sort and filter out archived values
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|
-
|
|
524
|
-
|
|
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
|
|
530
|
-
}, values.map(
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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
|
-
|
|
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
|