@defra/flood-webchat 0.0.1-beta.2 → 0.0.1-beta.21
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/README.md +83 -1
- package/dist/client.js +1607 -212
- package/dist/client.js.map +1 -1
- package/dist/server.js +181 -240
- package/dist/server.js.map +1 -1
- package/main.scss +4 -3
- package/package.json +6 -2
- package/src/client/components/availability/availability.jsx +44 -46
- package/src/client/components/availability/availability.scss +105 -5
- package/src/client/components/chat/chat.jsx +169 -0
- package/src/client/components/chat/chat.scss +143 -0
- package/src/client/components/errorSummary/error-summary.jsx +34 -0
- package/src/client/components/message/message.jsx +20 -0
- package/src/client/components/panel/panel-footer.jsx +9 -0
- package/src/client/components/panel/panel-header.jsx +41 -0
- package/src/client/components/panel/panel.jsx +119 -0
- package/src/client/components/panel/panel.scss +72 -0
- package/src/client/components/screens/end-chat.jsx +17 -0
- package/src/client/components/screens/pre-chat.jsx +65 -0
- package/src/client/components/screens/request-chat.jsx +156 -0
- package/src/client/components/screens/settings.jsx +67 -0
- package/src/client/components/screens/unavailable.jsx +23 -0
- package/src/client/hooks/useFocusedElements.js +71 -0
- package/src/client/hooks/useTextareaAutosize.js +13 -0
- package/src/client/index.jsx +15 -1
- package/src/client/lib/check-availability.js +1 -0
- package/src/client/lib/message-notification.js +36 -0
- package/src/client/lib/transform-messages.js +35 -0
- package/src/client/store/AppProvider.jsx +139 -0
- package/src/client/store/actions-map.js +119 -0
- package/src/client/store/constants.js +3 -0
- package/src/client/store/reducer.js +28 -0
- package/src/client/store/useApp.js +5 -0
- package/src/client/store/useChatSdk.js +37 -0
- package/src/server/index.js +15 -6
- package/src/server/lib/client.js +31 -35
- package/src/server/lib/utils.js +18 -9
- package/src/client/lib/external-stores.js +0 -4
- package/src/client/lib/external-sync-store.js +0 -42
package/dist/server.js
CHANGED
|
@@ -7,21 +7,12 @@
|
|
|
7
7
|
\*****************************/
|
|
8
8
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return { value: void 0, done: !0 }; } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; 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; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; 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); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable || "" === iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } throw new TypeError(_typeof(iterable) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { 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); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; 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; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
17
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
19
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
20
|
-
var _require = __webpack_require__(/*! ./lib/client.js */ "./src/server/lib/client.js"),
|
|
21
|
-
authenticate = _require.authenticate,
|
|
22
|
-
getHost = _require.getHost,
|
|
23
|
-
getIsOpen = _require.getIsOpen,
|
|
24
|
-
getActivity = _require.getActivity;
|
|
10
|
+
const {
|
|
11
|
+
authenticate,
|
|
12
|
+
getApiBaseUrl,
|
|
13
|
+
getIsOpen,
|
|
14
|
+
getActivity
|
|
15
|
+
} = __webpack_require__(/*! ./lib/client.js */ "./src/server/lib/client.js");
|
|
25
16
|
|
|
26
17
|
/**
|
|
27
18
|
* Returns webchat availability
|
|
@@ -32,77 +23,67 @@ var _require = __webpack_require__(/*! ./lib/client.js */ "./src/server/lib/clie
|
|
|
32
23
|
* @param options.accessSecret {string}
|
|
33
24
|
* @param options.skillEndpoint {string}
|
|
34
25
|
* @param options.hoursEndpoint {string}
|
|
26
|
+
* @param options.authenticationUri {string}
|
|
27
|
+
* @param options.wellKnownUri {string}
|
|
35
28
|
* @param options.maxQueueCount {string}
|
|
36
29
|
* @returns {Promise<{date: Date, availability: (string)}>}
|
|
37
30
|
*/
|
|
38
|
-
module.exports =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} else if (isExistingOnly) {
|
|
89
|
-
availability = 'EXISTING';
|
|
90
|
-
}
|
|
91
|
-
return _context.abrupt("return", {
|
|
92
|
-
date: new Date(),
|
|
93
|
-
availability: availability
|
|
94
|
-
});
|
|
95
|
-
case 24:
|
|
96
|
-
case "end":
|
|
97
|
-
return _context.stop();
|
|
98
|
-
}
|
|
99
|
-
}, _callee);
|
|
100
|
-
}));
|
|
101
|
-
function getAvailability(_x) {
|
|
102
|
-
return _getAvailability.apply(this, arguments);
|
|
31
|
+
module.exports = async function getAvailability({
|
|
32
|
+
clientId,
|
|
33
|
+
clientSecret,
|
|
34
|
+
accessKey,
|
|
35
|
+
accessSecret,
|
|
36
|
+
maxQueueCount,
|
|
37
|
+
skillEndpoint,
|
|
38
|
+
hoursEndpoint,
|
|
39
|
+
wellKnownUri = 'https://cxone.niceincontact.com/.well-known/cxone-configuration',
|
|
40
|
+
authenticationUri = 'https://cxone.niceincontact.com/auth/token'
|
|
41
|
+
}) {
|
|
42
|
+
const authorisation = 'Basic ' + Buffer.from(`${encodeURIComponent(clientId)}:${encodeURIComponent(clientSecret)}`).toString('base64');
|
|
43
|
+
|
|
44
|
+
// Cache authentication and re-authenticate when needed (lasts 1 hour?)
|
|
45
|
+
const {
|
|
46
|
+
tenantId,
|
|
47
|
+
token,
|
|
48
|
+
tokenType
|
|
49
|
+
} = await authenticate({
|
|
50
|
+
authenticationUri,
|
|
51
|
+
authorisation,
|
|
52
|
+
accessKey,
|
|
53
|
+
accessSecret
|
|
54
|
+
});
|
|
55
|
+
const apiBaseUrl = await getApiBaseUrl({
|
|
56
|
+
wellKnownUri,
|
|
57
|
+
tenantId
|
|
58
|
+
});
|
|
59
|
+
const [{
|
|
60
|
+
hasCapacity,
|
|
61
|
+
hasAgentsAvailable
|
|
62
|
+
}, isOpen] = await Promise.all([getActivity({
|
|
63
|
+
baseUrl: apiBaseUrl,
|
|
64
|
+
tokenType,
|
|
65
|
+
token,
|
|
66
|
+
skillEndpoint,
|
|
67
|
+
maxQueueCount
|
|
68
|
+
}), getIsOpen({
|
|
69
|
+
baseUrl: apiBaseUrl,
|
|
70
|
+
token,
|
|
71
|
+
tokenType,
|
|
72
|
+
hoursEndpoint
|
|
73
|
+
})]);
|
|
74
|
+
const isAvailable = isOpen && hasAgentsAvailable && hasCapacity;
|
|
75
|
+
const isExistingOnly = isOpen && hasAgentsAvailable && !hasCapacity;
|
|
76
|
+
let availability = 'UNAVAILABLE';
|
|
77
|
+
if (isAvailable) {
|
|
78
|
+
availability = 'AVAILABLE';
|
|
79
|
+
} else if (isExistingOnly) {
|
|
80
|
+
availability = 'EXISTING';
|
|
103
81
|
}
|
|
104
|
-
return
|
|
105
|
-
|
|
82
|
+
return {
|
|
83
|
+
date: new Date(),
|
|
84
|
+
availability
|
|
85
|
+
};
|
|
86
|
+
};
|
|
106
87
|
|
|
107
88
|
/***/ }),
|
|
108
89
|
|
|
@@ -112,155 +93,100 @@ module.exports = /*#__PURE__*/function () {
|
|
|
112
93
|
\**********************************/
|
|
113
94
|
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
114
95
|
|
|
115
|
-
|
|
116
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return { value: void 0, done: !0 }; } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; 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; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; 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); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable || "" === iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } throw new TypeError(_typeof(iterable) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { 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); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; 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; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
});
|
|
147
|
-
_context.next = 6;
|
|
148
|
-
return axios.post(uri, body, config);
|
|
149
|
-
case 6:
|
|
150
|
-
auth = _context.sent;
|
|
151
|
-
return _context.abrupt("return", {
|
|
152
|
-
token: auth.data.access_token,
|
|
153
|
-
tokenType: auth.data.token_type,
|
|
154
|
-
tenantId: (_jwtdecode = jwtdecode(auth.data.id_token)) === null || _jwtdecode === void 0 ? void 0 : _jwtdecode.tenantId
|
|
155
|
-
});
|
|
156
|
-
case 8:
|
|
157
|
-
case "end":
|
|
158
|
-
return _context.stop();
|
|
159
|
-
}
|
|
160
|
-
}, _callee);
|
|
161
|
-
}));
|
|
162
|
-
return function authenticate(_x) {
|
|
163
|
-
return _ref2.apply(this, arguments);
|
|
164
|
-
};
|
|
165
|
-
}();
|
|
166
|
-
var getHost = /*#__PURE__*/function () {
|
|
167
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref3) {
|
|
168
|
-
var tenantId, uri, config, api;
|
|
169
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
170
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
171
|
-
case 0:
|
|
172
|
-
tenantId = _ref3.tenantId;
|
|
173
|
-
uri = "https://cxone.niceincontact.com/.well-known/cxone-configuration?tenantId=".concat(tenantId);
|
|
174
|
-
config = {
|
|
175
|
-
signal: AbortSignal.timeout(3000)
|
|
176
|
-
};
|
|
177
|
-
_context2.next = 5;
|
|
178
|
-
return axios.get(uri, config);
|
|
179
|
-
case 5:
|
|
180
|
-
api = _context2.sent;
|
|
181
|
-
return _context2.abrupt("return", "api-".concat(api.data.area, ".niceincontact.com"));
|
|
182
|
-
case 7:
|
|
183
|
-
case "end":
|
|
184
|
-
return _context2.stop();
|
|
185
|
-
}
|
|
186
|
-
}, _callee2);
|
|
187
|
-
}));
|
|
188
|
-
return function getHost(_x2) {
|
|
189
|
-
return _ref4.apply(this, arguments);
|
|
190
|
-
};
|
|
191
|
-
}();
|
|
192
|
-
var getActivity = /*#__PURE__*/function () {
|
|
193
|
-
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref5) {
|
|
194
|
-
var tokenType, token, host, skillEndpoint, maxQueueCount, config, uri, skill, activity;
|
|
195
|
-
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
196
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
197
|
-
case 0:
|
|
198
|
-
tokenType = _ref5.tokenType, token = _ref5.token, host = _ref5.host, skillEndpoint = _ref5.skillEndpoint, maxQueueCount = _ref5.maxQueueCount;
|
|
199
|
-
config = {
|
|
200
|
-
signal: AbortSignal.timeout(3000),
|
|
201
|
-
headers: {
|
|
202
|
-
Host: host,
|
|
203
|
-
Authorization: "".concat(tokenType, " ").concat(token),
|
|
204
|
-
'Content-Type': contentType
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
uri = "https://".concat(host).concat(skillEndpoint);
|
|
208
|
-
_context3.next = 5;
|
|
209
|
-
return axios.get(uri, config);
|
|
210
|
-
case 5:
|
|
211
|
-
skill = _context3.sent;
|
|
212
|
-
activity = skill.data.skillActivity[0];
|
|
213
|
-
return _context3.abrupt("return", {
|
|
214
|
-
hasCapacity: activity.queueCount < maxQueueCount,
|
|
215
|
-
hasAgentsAvailable: activity.agentsAvailable >= 1
|
|
216
|
-
});
|
|
217
|
-
case 8:
|
|
218
|
-
case "end":
|
|
219
|
-
return _context3.stop();
|
|
220
|
-
}
|
|
221
|
-
}, _callee3);
|
|
222
|
-
}));
|
|
223
|
-
return function getActivity(_x3) {
|
|
224
|
-
return _ref6.apply(this, arguments);
|
|
96
|
+
const querystring = __webpack_require__(/*! querystring */ "querystring");
|
|
97
|
+
const axios = __webpack_require__(/*! axios */ "axios");
|
|
98
|
+
const jwtdecode = __webpack_require__(/*! jwt-decode */ "jwt-decode");
|
|
99
|
+
const {
|
|
100
|
+
isWithinHours
|
|
101
|
+
} = __webpack_require__(/*! ./utils.js */ "./src/server/lib/utils.js");
|
|
102
|
+
const contentType = 'application/x-www-form-urlencoded';
|
|
103
|
+
const authenticate = async ({
|
|
104
|
+
authenticationUri,
|
|
105
|
+
authorisation,
|
|
106
|
+
accessKey,
|
|
107
|
+
accessSecret
|
|
108
|
+
}) => {
|
|
109
|
+
const url = new URL(authenticationUri);
|
|
110
|
+
const body = querystring.stringify({
|
|
111
|
+
grant_type: 'password',
|
|
112
|
+
username: accessKey,
|
|
113
|
+
password: accessSecret
|
|
114
|
+
});
|
|
115
|
+
const auth = await axios.post(url.href, body, {
|
|
116
|
+
signal: AbortSignal.timeout(3000),
|
|
117
|
+
headers: {
|
|
118
|
+
Host: url.host,
|
|
119
|
+
'Content-Type': contentType,
|
|
120
|
+
Authorization: authorisation
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
token: auth.data.access_token,
|
|
125
|
+
tokenType: auth.data.token_type,
|
|
126
|
+
tenantId: jwtdecode(auth.data.id_token)?.tenantId
|
|
225
127
|
};
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
128
|
+
};
|
|
129
|
+
const getApiBaseUrl = async ({
|
|
130
|
+
wellKnownUri,
|
|
131
|
+
tenantId
|
|
132
|
+
}) => {
|
|
133
|
+
const url = new URL(wellKnownUri);
|
|
134
|
+
url.searchParams.set('tenantId', tenantId);
|
|
135
|
+
const {
|
|
136
|
+
data
|
|
137
|
+
} = await axios.get(url.href, {
|
|
138
|
+
headers: {
|
|
139
|
+
Host: url.host
|
|
140
|
+
},
|
|
141
|
+
signal: AbortSignal.timeout(3000)
|
|
142
|
+
});
|
|
143
|
+
return data.api_endpoint;
|
|
144
|
+
};
|
|
145
|
+
const getActivity = async ({
|
|
146
|
+
tokenType,
|
|
147
|
+
token,
|
|
148
|
+
baseUrl,
|
|
149
|
+
skillEndpoint,
|
|
150
|
+
maxQueueCount
|
|
151
|
+
}) => {
|
|
152
|
+
const url = new URL(skillEndpoint, baseUrl);
|
|
153
|
+
const skill = await axios.get(url.href, {
|
|
154
|
+
signal: AbortSignal.timeout(3000),
|
|
155
|
+
headers: {
|
|
156
|
+
Host: url.host,
|
|
157
|
+
Authorization: `${tokenType} ${token}`,
|
|
158
|
+
'Content-Type': contentType
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const activity = skill.data.skillActivity[0];
|
|
162
|
+
return {
|
|
163
|
+
hasCapacity: activity.queueCount < maxQueueCount,
|
|
164
|
+
hasAgentsAvailable: activity.agentsAvailable >= 1
|
|
257
165
|
};
|
|
258
|
-
}
|
|
166
|
+
};
|
|
167
|
+
const getIsOpen = async ({
|
|
168
|
+
baseUrl,
|
|
169
|
+
token,
|
|
170
|
+
tokenType,
|
|
171
|
+
hoursEndpoint
|
|
172
|
+
}) => {
|
|
173
|
+
const url = new URL(hoursEndpoint, baseUrl);
|
|
174
|
+
const hours = await axios.get(url.href, {
|
|
175
|
+
signal: AbortSignal.timeout(3000),
|
|
176
|
+
headers: {
|
|
177
|
+
Host: url.host,
|
|
178
|
+
Authorization: `${tokenType} ${token}`,
|
|
179
|
+
'Content-Type': contentType
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const days = hours.data.resultSet.hoursOfOperationProfiles[0].days;
|
|
183
|
+
return isWithinHours(days);
|
|
184
|
+
};
|
|
259
185
|
module.exports = {
|
|
260
|
-
authenticate
|
|
261
|
-
|
|
262
|
-
getIsOpen
|
|
263
|
-
getActivity
|
|
186
|
+
authenticate,
|
|
187
|
+
getApiBaseUrl,
|
|
188
|
+
getIsOpen,
|
|
189
|
+
getActivity
|
|
264
190
|
};
|
|
265
191
|
|
|
266
192
|
/***/ }),
|
|
@@ -269,23 +195,27 @@ module.exports = {
|
|
|
269
195
|
/*!*********************************!*\
|
|
270
196
|
!*** ./src/server/lib/utils.js ***!
|
|
271
197
|
\*********************************/
|
|
272
|
-
/***/ ((module) => {
|
|
198
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
273
199
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
200
|
+
const {
|
|
201
|
+
DateTime
|
|
202
|
+
} = __webpack_require__(/*! luxon */ "luxon");
|
|
203
|
+
const getHour = time => Number(time.split(':')[0]);
|
|
204
|
+
const isWithinHours = (days, date) => {
|
|
205
|
+
const now = date ? DateTime.fromISO(date) : DateTime.local();
|
|
206
|
+
now.setZone('Europe/London');
|
|
207
|
+
const newDate = date ? new Date(date) : new Date();
|
|
208
|
+
const today = newDate.toLocaleDateString('en-GB', {
|
|
277
209
|
weekday: 'long'
|
|
278
210
|
});
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
var close = "".concat(date[2], "-").concat(date[1], "-").concat(date[0], "T").concat(day.closeTime, ".000Z");
|
|
285
|
-
return now.getTime() >= Date.parse(open) && now.getTime() <= Date.parse(close);
|
|
211
|
+
const dateParts = newDate.toLocaleDateString('en-GB').split('/');
|
|
212
|
+
const todaysAvailability = days.find(item => item.day === today);
|
|
213
|
+
const todaysDateTimeOpen = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.openTime));
|
|
214
|
+
const todaysDateTimeClose = DateTime.local(Number(dateParts[2]), Number(dateParts[1]), Number(dateParts[0]), getHour(todaysAvailability.closeTime));
|
|
215
|
+
return now.diff(todaysDateTimeOpen).milliseconds >= 0 && now.diff(todaysDateTimeClose).milliseconds <= 0;
|
|
286
216
|
};
|
|
287
217
|
module.exports = {
|
|
288
|
-
isWithinHours
|
|
218
|
+
isWithinHours
|
|
289
219
|
};
|
|
290
220
|
|
|
291
221
|
/***/ }),
|
|
@@ -312,6 +242,17 @@ module.exports = require("jwt-decode");
|
|
|
312
242
|
|
|
313
243
|
/***/ }),
|
|
314
244
|
|
|
245
|
+
/***/ "luxon":
|
|
246
|
+
/*!************************!*\
|
|
247
|
+
!*** external "luxon" ***!
|
|
248
|
+
\************************/
|
|
249
|
+
/***/ ((module) => {
|
|
250
|
+
|
|
251
|
+
"use strict";
|
|
252
|
+
module.exports = require("luxon");
|
|
253
|
+
|
|
254
|
+
/***/ }),
|
|
255
|
+
|
|
315
256
|
/***/ "querystring":
|
|
316
257
|
/*!******************************!*\
|
|
317
258
|
!*** external "querystring" ***!
|