@pisell/pisellos 0.10.50 → 0.10.52
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/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
- package/dist/modules/FulfillmentTiming/index.js +407 -0
- package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
- package/dist/modules/FulfillmentTiming/types.js +1 -0
- package/dist/modules/OpenData/types.d.ts +6 -0
- package/dist/modules/Order/index.d.ts +18 -1
- package/dist/modules/Order/index.js +322 -195
- package/dist/modules/Order/pickupTiming.d.ts +46 -0
- package/dist/modules/Order/pickupTiming.js +53 -0
- package/dist/modules/Order/types.d.ts +11 -1
- package/dist/modules/Order/utils.d.ts +10 -0
- package/dist/modules/Order/utils.js +145 -85
- package/dist/modules/Rules/index.js +3 -2
- package/dist/modules/Schedule/index.d.ts +8 -0
- package/dist/modules/Schedule/index.js +134 -37
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +1 -0
- package/dist/server/modules/order/index.d.ts +8 -0
- package/dist/server/modules/order/index.js +506 -453
- package/dist/server/modules/order/types.d.ts +1 -0
- package/dist/server/utils/small-ticket.js +165 -94
- package/dist/solution/BaseSales/index.d.ts +24 -0
- package/dist/solution/BaseSales/index.js +1231 -1037
- package/dist/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/dist/solution/BaseSales/pickupTiming.js +589 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +2 -2
- package/dist/solution/BookingTicket/utils/cartView.js +3 -1
- package/dist/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/dist/solution/UnifiedBookingSales/index.js +873 -708
- package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
- package/lib/modules/FulfillmentTiming/index.js +359 -0
- package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
- package/lib/modules/FulfillmentTiming/types.js +5 -0
- package/lib/modules/OpenData/types.d.ts +6 -0
- package/lib/modules/Order/index.d.ts +18 -1
- package/lib/modules/Order/index.js +101 -3
- package/lib/modules/Order/pickupTiming.d.ts +46 -0
- package/lib/modules/Order/pickupTiming.js +61 -0
- package/lib/modules/Order/types.d.ts +11 -1
- package/lib/modules/Order/utils.d.ts +10 -0
- package/lib/modules/Order/utils.js +58 -4
- package/lib/modules/Rules/index.js +3 -2
- package/lib/modules/Schedule/index.d.ts +8 -0
- package/lib/modules/Schedule/index.js +64 -11
- package/lib/modules/index.d.ts +1 -0
- package/lib/modules/index.js +11 -0
- package/lib/server/modules/order/index.d.ts +8 -0
- package/lib/server/modules/order/index.js +19 -0
- package/lib/server/modules/order/types.d.ts +1 -0
- package/lib/server/utils/small-ticket.js +86 -22
- package/lib/solution/BaseSales/index.d.ts +24 -0
- package/lib/solution/BaseSales/index.js +109 -1
- package/lib/solution/BaseSales/pickupTiming.d.ts +43 -0
- package/lib/solution/BaseSales/pickupTiming.js +269 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +2 -2
- package/lib/solution/BookingTicket/utils/cartView.js +3 -1
- package/lib/solution/UnifiedBookingSales/index.d.ts +13 -4
- package/lib/solution/UnifiedBookingSales/index.js +130 -46
- package/package.json +1 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { OrderModule } from '../../modules/Order';
|
|
2
|
+
import type { ScheduleModule } from '../../modules/Schedule';
|
|
3
|
+
import { type PickupTimingAvailability, type PickupTimingSelection, type PickupTimingValidationResult } from '../../modules/FulfillmentTiming';
|
|
4
|
+
interface PickupTimingHost {
|
|
5
|
+
getOrder: () => OrderModule;
|
|
6
|
+
getSchedule: () => ScheduleModule | undefined;
|
|
7
|
+
loadOpenData: (force: boolean) => Promise<Record<string, unknown>>;
|
|
8
|
+
getTimezone: () => string;
|
|
9
|
+
getScope: () => string;
|
|
10
|
+
isPos: () => boolean;
|
|
11
|
+
now?: () => Date;
|
|
12
|
+
}
|
|
13
|
+
/** Reuses runtime configuration and schedules; every calculation still uses the live clock. */
|
|
14
|
+
export declare class PickupTimingController {
|
|
15
|
+
private readonly host;
|
|
16
|
+
private latest?;
|
|
17
|
+
private runtime?;
|
|
18
|
+
private writeSequence;
|
|
19
|
+
constructor(host: PickupTimingHost);
|
|
20
|
+
private now;
|
|
21
|
+
/** A new solution context or an explicit settings refresh invalidates pending work too. */
|
|
22
|
+
invalidate(): void;
|
|
23
|
+
private assertCurrentRuntime;
|
|
24
|
+
private getRuntime;
|
|
25
|
+
private loadConfig;
|
|
26
|
+
private loadSchedules;
|
|
27
|
+
private snapshot;
|
|
28
|
+
getAvailability(params?: {
|
|
29
|
+
date?: string;
|
|
30
|
+
force?: boolean;
|
|
31
|
+
}): Promise<PickupTimingAvailability>;
|
|
32
|
+
getSelection(): PickupTimingSelection;
|
|
33
|
+
private validateSnapshot;
|
|
34
|
+
validate(selection: PickupTimingSelection): Promise<PickupTimingValidationResult>;
|
|
35
|
+
setSelection(selection: PickupTimingSelection, options?: {
|
|
36
|
+
frozen?: boolean;
|
|
37
|
+
}): Promise<PickupTimingSelection>;
|
|
38
|
+
/** Called before a new checkout/payment; payment callbacks keep their already prepared appointment. */
|
|
39
|
+
prepare(options?: {
|
|
40
|
+
freeze?: boolean;
|
|
41
|
+
}): Promise<PickupTimingSelection>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
+
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
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); } }
|
|
18
|
+
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); }); }; }
|
|
19
|
+
import { cloneDeep } from 'lodash-es';
|
|
20
|
+
import { computePickupTimingAvailability, getAsapPickupTiming, normalizePickupTimingConfig, validatePickupTimingSelection } from "../../modules/FulfillmentTiming";
|
|
21
|
+
function withTimeout(_x) {
|
|
22
|
+
return _withTimeout.apply(this, arguments);
|
|
23
|
+
}
|
|
24
|
+
/** Reuses runtime configuration and schedules; every calculation still uses the live clock. */
|
|
25
|
+
function _withTimeout() {
|
|
26
|
+
_withTimeout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(request) {
|
|
27
|
+
var timer;
|
|
28
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
29
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
30
|
+
case 0:
|
|
31
|
+
_context11.prev = 0;
|
|
32
|
+
_context11.next = 3;
|
|
33
|
+
return Promise.race([request, new Promise(function (_, reject) {
|
|
34
|
+
timer = setTimeout(function () {
|
|
35
|
+
return reject(new Error('Unable to load pickup times. Please try again.'));
|
|
36
|
+
}, 30000);
|
|
37
|
+
})]);
|
|
38
|
+
case 3:
|
|
39
|
+
return _context11.abrupt("return", _context11.sent);
|
|
40
|
+
case 4:
|
|
41
|
+
_context11.prev = 4;
|
|
42
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
43
|
+
return _context11.finish(4);
|
|
44
|
+
case 7:
|
|
45
|
+
case "end":
|
|
46
|
+
return _context11.stop();
|
|
47
|
+
}
|
|
48
|
+
}, _callee11, null, [[0,, 4, 7]]);
|
|
49
|
+
}));
|
|
50
|
+
return _withTimeout.apply(this, arguments);
|
|
51
|
+
}
|
|
52
|
+
export var PickupTimingController = /*#__PURE__*/function () {
|
|
53
|
+
function PickupTimingController(host) {
|
|
54
|
+
_classCallCheck(this, PickupTimingController);
|
|
55
|
+
_defineProperty(this, "latest", void 0);
|
|
56
|
+
_defineProperty(this, "runtime", void 0);
|
|
57
|
+
_defineProperty(this, "writeSequence", 0);
|
|
58
|
+
this.host = host;
|
|
59
|
+
}
|
|
60
|
+
_createClass(PickupTimingController, [{
|
|
61
|
+
key: "now",
|
|
62
|
+
value: function now() {
|
|
63
|
+
var _this$host$now, _this$host$now2, _this$host;
|
|
64
|
+
return (_this$host$now = (_this$host$now2 = (_this$host = this.host).now) === null || _this$host$now2 === void 0 ? void 0 : _this$host$now2.call(_this$host)) !== null && _this$host$now !== void 0 ? _this$host$now : new Date();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A new solution context or an explicit settings refresh invalidates pending work too. */
|
|
68
|
+
}, {
|
|
69
|
+
key: "invalidate",
|
|
70
|
+
value: function invalidate() {
|
|
71
|
+
this.runtime = undefined;
|
|
72
|
+
this.latest = undefined;
|
|
73
|
+
this.writeSequence += 1;
|
|
74
|
+
}
|
|
75
|
+
}, {
|
|
76
|
+
key: "assertCurrentRuntime",
|
|
77
|
+
value: function assertCurrentRuntime(runtime) {
|
|
78
|
+
if (this.runtime !== runtime || runtime.scope !== this.host.getScope()) {
|
|
79
|
+
throw new Error('Store settings changed. Please try again.');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}, {
|
|
83
|
+
key: "getRuntime",
|
|
84
|
+
value: function getRuntime() {
|
|
85
|
+
var _this$runtime;
|
|
86
|
+
var scope = this.host.getScope();
|
|
87
|
+
if (((_this$runtime = this.runtime) === null || _this$runtime === void 0 ? void 0 : _this$runtime.scope) !== scope) {
|
|
88
|
+
this.latest = undefined;
|
|
89
|
+
this.runtime = {
|
|
90
|
+
scope: scope
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return this.runtime;
|
|
94
|
+
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "loadConfig",
|
|
97
|
+
value: function () {
|
|
98
|
+
var _loadConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(runtime) {
|
|
99
|
+
var _this = this;
|
|
100
|
+
var _request, request;
|
|
101
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
102
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
103
|
+
case 0:
|
|
104
|
+
if (!runtime.config) {
|
|
105
|
+
_context2.next = 2;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return _context2.abrupt("return", runtime.config);
|
|
109
|
+
case 2:
|
|
110
|
+
if (!runtime.configRequest) {
|
|
111
|
+
_request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
112
|
+
var config;
|
|
113
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
114
|
+
while (1) switch (_context.prev = _context.next) {
|
|
115
|
+
case 0:
|
|
116
|
+
_context.t0 = normalizePickupTimingConfig;
|
|
117
|
+
_context.next = 3;
|
|
118
|
+
return withTimeout(_this.host.loadOpenData(false));
|
|
119
|
+
case 3:
|
|
120
|
+
_context.t1 = _context.sent;
|
|
121
|
+
config = (0, _context.t0)(_context.t1);
|
|
122
|
+
_this.assertCurrentRuntime(runtime);
|
|
123
|
+
runtime.config = config;
|
|
124
|
+
return _context.abrupt("return", config);
|
|
125
|
+
case 8:
|
|
126
|
+
case "end":
|
|
127
|
+
return _context.stop();
|
|
128
|
+
}
|
|
129
|
+
}, _callee);
|
|
130
|
+
}))();
|
|
131
|
+
runtime.configRequest = _request;
|
|
132
|
+
}
|
|
133
|
+
request = runtime.configRequest;
|
|
134
|
+
_context2.prev = 4;
|
|
135
|
+
_context2.next = 7;
|
|
136
|
+
return request;
|
|
137
|
+
case 7:
|
|
138
|
+
return _context2.abrupt("return", _context2.sent);
|
|
139
|
+
case 8:
|
|
140
|
+
_context2.prev = 8;
|
|
141
|
+
if (runtime.configRequest === request) runtime.configRequest = undefined;
|
|
142
|
+
return _context2.finish(8);
|
|
143
|
+
case 11:
|
|
144
|
+
case "end":
|
|
145
|
+
return _context2.stop();
|
|
146
|
+
}
|
|
147
|
+
}, _callee2, null, [[4,, 8, 11]]);
|
|
148
|
+
}));
|
|
149
|
+
function loadConfig(_x2) {
|
|
150
|
+
return _loadConfig.apply(this, arguments);
|
|
151
|
+
}
|
|
152
|
+
return loadConfig;
|
|
153
|
+
}()
|
|
154
|
+
}, {
|
|
155
|
+
key: "loadSchedules",
|
|
156
|
+
value: function () {
|
|
157
|
+
var _loadSchedules = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(runtime, config) {
|
|
158
|
+
var _this2 = this;
|
|
159
|
+
var _request2, request;
|
|
160
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
161
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
if (!runtime.schedules) {
|
|
164
|
+
_context4.next = 2;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
return _context4.abrupt("return", runtime.schedules);
|
|
168
|
+
case 2:
|
|
169
|
+
if (!runtime.scheduleRequest) {
|
|
170
|
+
_request2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
171
|
+
var schedule, ids, schedules;
|
|
172
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
173
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
174
|
+
case 0:
|
|
175
|
+
schedule = _this2.host.getSchedule();
|
|
176
|
+
if (schedule) {
|
|
177
|
+
_context3.next = 3;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
throw new Error('Pickup schedule is unavailable. Please try again.');
|
|
181
|
+
case 3:
|
|
182
|
+
_context3.next = 5;
|
|
183
|
+
return withTimeout(schedule.loadAllSchedule({
|
|
184
|
+
useCache: true
|
|
185
|
+
}));
|
|
186
|
+
case 5:
|
|
187
|
+
_this2.assertCurrentRuntime(runtime);
|
|
188
|
+
ids = _toConsumableArray(new Set([].concat(_toConsumableArray(config.scheduleIds), _toConsumableArray(config.operatingHoursScheduleIds || []))));
|
|
189
|
+
schedules = cloneDeep(schedule.getScheduleListByIds(ids) || []);
|
|
190
|
+
runtime.schedules = schedules;
|
|
191
|
+
return _context3.abrupt("return", schedules);
|
|
192
|
+
case 10:
|
|
193
|
+
case "end":
|
|
194
|
+
return _context3.stop();
|
|
195
|
+
}
|
|
196
|
+
}, _callee3);
|
|
197
|
+
}))();
|
|
198
|
+
runtime.scheduleRequest = _request2;
|
|
199
|
+
}
|
|
200
|
+
request = runtime.scheduleRequest;
|
|
201
|
+
_context4.prev = 4;
|
|
202
|
+
_context4.next = 7;
|
|
203
|
+
return request;
|
|
204
|
+
case 7:
|
|
205
|
+
return _context4.abrupt("return", _context4.sent);
|
|
206
|
+
case 8:
|
|
207
|
+
_context4.prev = 8;
|
|
208
|
+
if (runtime.scheduleRequest === request) runtime.scheduleRequest = undefined;
|
|
209
|
+
return _context4.finish(8);
|
|
210
|
+
case 11:
|
|
211
|
+
case "end":
|
|
212
|
+
return _context4.stop();
|
|
213
|
+
}
|
|
214
|
+
}, _callee4, null, [[4,, 8, 11]]);
|
|
215
|
+
}));
|
|
216
|
+
function loadSchedules(_x3, _x4) {
|
|
217
|
+
return _loadSchedules.apply(this, arguments);
|
|
218
|
+
}
|
|
219
|
+
return loadSchedules;
|
|
220
|
+
}()
|
|
221
|
+
}, {
|
|
222
|
+
key: "snapshot",
|
|
223
|
+
value: function () {
|
|
224
|
+
var _snapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(includeSchedule) {
|
|
225
|
+
var tolerateScheduleError,
|
|
226
|
+
runtime,
|
|
227
|
+
config,
|
|
228
|
+
schedules,
|
|
229
|
+
error,
|
|
230
|
+
result,
|
|
231
|
+
_args5 = arguments;
|
|
232
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
233
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
234
|
+
case 0:
|
|
235
|
+
tolerateScheduleError = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : false;
|
|
236
|
+
runtime = this.getRuntime();
|
|
237
|
+
_context5.next = 4;
|
|
238
|
+
return this.loadConfig(runtime);
|
|
239
|
+
case 4:
|
|
240
|
+
config = _context5.sent;
|
|
241
|
+
this.assertCurrentRuntime(runtime);
|
|
242
|
+
schedules = [];
|
|
243
|
+
if (!(includeSchedule && config.handoverModes.includes('pick_up') && config.timingMode !== 'asap_only' && config.scheduleIds.length)) {
|
|
244
|
+
_context5.next = 19;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
_context5.prev = 8;
|
|
248
|
+
_context5.next = 11;
|
|
249
|
+
return this.loadSchedules(runtime, config);
|
|
250
|
+
case 11:
|
|
251
|
+
schedules = _context5.sent;
|
|
252
|
+
_context5.next = 19;
|
|
253
|
+
break;
|
|
254
|
+
case 14:
|
|
255
|
+
_context5.prev = 14;
|
|
256
|
+
_context5.t0 = _context5["catch"](8);
|
|
257
|
+
if (tolerateScheduleError) {
|
|
258
|
+
_context5.next = 18;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
throw _context5.t0;
|
|
262
|
+
case 18:
|
|
263
|
+
error = _context5.t0 instanceof Error ? _context5.t0.message : 'Pickup schedule is unavailable. Please try again.';
|
|
264
|
+
case 19:
|
|
265
|
+
this.assertCurrentRuntime(runtime);
|
|
266
|
+
result = {
|
|
267
|
+
config: config,
|
|
268
|
+
timezone: this.host.getTimezone(),
|
|
269
|
+
schedules: schedules,
|
|
270
|
+
scope: runtime.scope,
|
|
271
|
+
error: error
|
|
272
|
+
};
|
|
273
|
+
this.latest = result;
|
|
274
|
+
return _context5.abrupt("return", result);
|
|
275
|
+
case 23:
|
|
276
|
+
case "end":
|
|
277
|
+
return _context5.stop();
|
|
278
|
+
}
|
|
279
|
+
}, _callee5, this, [[8, 14]]);
|
|
280
|
+
}));
|
|
281
|
+
function snapshot(_x5) {
|
|
282
|
+
return _snapshot.apply(this, arguments);
|
|
283
|
+
}
|
|
284
|
+
return snapshot;
|
|
285
|
+
}()
|
|
286
|
+
}, {
|
|
287
|
+
key: "getAvailability",
|
|
288
|
+
value: function () {
|
|
289
|
+
var _getAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
290
|
+
var params,
|
|
291
|
+
snapshot,
|
|
292
|
+
now,
|
|
293
|
+
_args6 = arguments;
|
|
294
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
295
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
296
|
+
case 0:
|
|
297
|
+
params = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
|
|
298
|
+
_context6.next = 3;
|
|
299
|
+
return this.snapshot(true, true);
|
|
300
|
+
case 3:
|
|
301
|
+
snapshot = _context6.sent;
|
|
302
|
+
now = this.now();
|
|
303
|
+
_context6.prev = 5;
|
|
304
|
+
return _context6.abrupt("return", _objectSpread(_objectSpread({}, computePickupTimingAvailability(_objectSpread(_objectSpread({}, snapshot), {}, {
|
|
305
|
+
date: params.date,
|
|
306
|
+
now: now
|
|
307
|
+
}))), {}, {
|
|
308
|
+
error: snapshot.error
|
|
309
|
+
}));
|
|
310
|
+
case 9:
|
|
311
|
+
_context6.prev = 9;
|
|
312
|
+
_context6.t0 = _context6["catch"](5);
|
|
313
|
+
return _context6.abrupt("return", {
|
|
314
|
+
config: snapshot.config,
|
|
315
|
+
timezone: snapshot.timezone,
|
|
316
|
+
now: now.toISOString(),
|
|
317
|
+
today: '',
|
|
318
|
+
maxDate: '',
|
|
319
|
+
date: params.date || '',
|
|
320
|
+
dates: [],
|
|
321
|
+
slots: [],
|
|
322
|
+
error: _context6.t0 instanceof Error ? _context6.t0.message : 'Pickup times are unavailable. Please try again.'
|
|
323
|
+
});
|
|
324
|
+
case 12:
|
|
325
|
+
case "end":
|
|
326
|
+
return _context6.stop();
|
|
327
|
+
}
|
|
328
|
+
}, _callee6, this, [[5, 9]]);
|
|
329
|
+
}));
|
|
330
|
+
function getAvailability() {
|
|
331
|
+
return _getAvailability.apply(this, arguments);
|
|
332
|
+
}
|
|
333
|
+
return getAvailability;
|
|
334
|
+
}()
|
|
335
|
+
}, {
|
|
336
|
+
key: "getSelection",
|
|
337
|
+
value: function getSelection() {
|
|
338
|
+
var _this$latest, _tempOrder$metadata, _details$mode;
|
|
339
|
+
var order = this.host.getOrder();
|
|
340
|
+
var tempOrder = order.getTempOrder();
|
|
341
|
+
var booking = order.getPickupTimingBooking();
|
|
342
|
+
var config = ((_this$latest = this.latest) === null || _this$latest === void 0 ? void 0 : _this$latest.scope) === this.host.getScope() ? this.latest.config : undefined;
|
|
343
|
+
var storedServiceType = String((tempOrder === null || tempOrder === void 0 || (_tempOrder$metadata = tempOrder.metadata) === null || _tempOrder$metadata === void 0 || (_tempOrder$metadata = _tempOrder$metadata.shop_service_data) === null || _tempOrder$metadata === void 0 ? void 0 : _tempOrder$metadata.service_type) || '');
|
|
344
|
+
var serviceType = config !== null && config !== void 0 && config.handoverModes.length ? config.handoverModes.includes(storedServiceType) ? storedServiceType : config.handoverModes[0] : storedServiceType;
|
|
345
|
+
var details = serviceType === 'pick_up' ? booking === null || booking === void 0 ? void 0 : booking.metadata.fulfillment_timing : undefined;
|
|
346
|
+
var mode = (config === null || config === void 0 ? void 0 : config.timingMode) === 'asap_only' ? 'asap' : (config === null || config === void 0 ? void 0 : config.timingMode) === 'scheduled_only' ? 'scheduled' : (_details$mode = details === null || details === void 0 ? void 0 : details.mode) !== null && _details$mode !== void 0 ? _details$mode : 'asap';
|
|
347
|
+
var sameMode = (details === null || details === void 0 ? void 0 : details.mode) === mode;
|
|
348
|
+
return _objectSpread({
|
|
349
|
+
serviceType: serviceType,
|
|
350
|
+
mode: mode,
|
|
351
|
+
source: mode === 'asap' ? 'asap' : sameMode && (details === null || details === void 0 ? void 0 : details.source) || 'schedule'
|
|
352
|
+
}, sameMode && booking ? {
|
|
353
|
+
date: booking.start_date,
|
|
354
|
+
time: booking.start_time,
|
|
355
|
+
instant: details === null || details === void 0 ? void 0 : details.instant
|
|
356
|
+
} : {});
|
|
357
|
+
}
|
|
358
|
+
}, {
|
|
359
|
+
key: "validateSnapshot",
|
|
360
|
+
value: function () {
|
|
361
|
+
var _validateSnapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(selection) {
|
|
362
|
+
var snapshot, now, result;
|
|
363
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
364
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
365
|
+
case 0:
|
|
366
|
+
_context7.next = 2;
|
|
367
|
+
return this.snapshot(selection.serviceType === 'pick_up' && selection.mode === 'scheduled' && selection.source !== 'pos_manual');
|
|
368
|
+
case 2:
|
|
369
|
+
snapshot = _context7.sent;
|
|
370
|
+
now = this.now();
|
|
371
|
+
result = validatePickupTimingSelection(selection, _objectSpread(_objectSpread({}, snapshot), {}, {
|
|
372
|
+
now: now,
|
|
373
|
+
allowManualOverride: this.host.isPos()
|
|
374
|
+
}));
|
|
375
|
+
return _context7.abrupt("return", {
|
|
376
|
+
snapshot: snapshot,
|
|
377
|
+
now: now,
|
|
378
|
+
result: result
|
|
379
|
+
});
|
|
380
|
+
case 6:
|
|
381
|
+
case "end":
|
|
382
|
+
return _context7.stop();
|
|
383
|
+
}
|
|
384
|
+
}, _callee7, this);
|
|
385
|
+
}));
|
|
386
|
+
function validateSnapshot(_x6) {
|
|
387
|
+
return _validateSnapshot.apply(this, arguments);
|
|
388
|
+
}
|
|
389
|
+
return validateSnapshot;
|
|
390
|
+
}()
|
|
391
|
+
}, {
|
|
392
|
+
key: "validate",
|
|
393
|
+
value: function () {
|
|
394
|
+
var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(selection) {
|
|
395
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
396
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
397
|
+
case 0:
|
|
398
|
+
_context8.next = 2;
|
|
399
|
+
return this.validateSnapshot(selection);
|
|
400
|
+
case 2:
|
|
401
|
+
return _context8.abrupt("return", _context8.sent.result);
|
|
402
|
+
case 3:
|
|
403
|
+
case "end":
|
|
404
|
+
return _context8.stop();
|
|
405
|
+
}
|
|
406
|
+
}, _callee8, this);
|
|
407
|
+
}));
|
|
408
|
+
function validate(_x7) {
|
|
409
|
+
return _validate.apply(this, arguments);
|
|
410
|
+
}
|
|
411
|
+
return validate;
|
|
412
|
+
}()
|
|
413
|
+
}, {
|
|
414
|
+
key: "setSelection",
|
|
415
|
+
value: function () {
|
|
416
|
+
var _setSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(selection) {
|
|
417
|
+
var _tempOrder$metadata2, _options$frozen;
|
|
418
|
+
var options,
|
|
419
|
+
order,
|
|
420
|
+
tempOrder,
|
|
421
|
+
sequence,
|
|
422
|
+
_yield$this$validateS,
|
|
423
|
+
snapshot,
|
|
424
|
+
now,
|
|
425
|
+
result,
|
|
426
|
+
slot,
|
|
427
|
+
_args9 = arguments;
|
|
428
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
429
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
430
|
+
case 0:
|
|
431
|
+
options = _args9.length > 1 && _args9[1] !== undefined ? _args9[1] : {};
|
|
432
|
+
order = this.host.getOrder();
|
|
433
|
+
tempOrder = order.ensureTempOrder();
|
|
434
|
+
sequence = ++this.writeSequence;
|
|
435
|
+
_context9.next = 6;
|
|
436
|
+
return this.validateSnapshot(selection);
|
|
437
|
+
case 6:
|
|
438
|
+
_yield$this$validateS = _context9.sent;
|
|
439
|
+
snapshot = _yield$this$validateS.snapshot;
|
|
440
|
+
now = _yield$this$validateS.now;
|
|
441
|
+
result = _yield$this$validateS.result;
|
|
442
|
+
if (!(sequence !== this.writeSequence || order.getTempOrder() !== tempOrder || snapshot.scope !== this.host.getScope())) {
|
|
443
|
+
_context9.next = 12;
|
|
444
|
+
break;
|
|
445
|
+
}
|
|
446
|
+
throw new Error('The order changed. Please choose the pickup time again.');
|
|
447
|
+
case 12:
|
|
448
|
+
if (result.valid) {
|
|
449
|
+
_context9.next = 14;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
throw new Error(result.message || 'Please choose a valid pickup time.');
|
|
453
|
+
case 14:
|
|
454
|
+
if (snapshot.config.handoverModes.length) {
|
|
455
|
+
_context9.next = 17;
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
order.clearPickupTimingBooking();
|
|
459
|
+
return _context9.abrupt("return", this.getSelection());
|
|
460
|
+
case 17:
|
|
461
|
+
if (!(selection.serviceType !== 'pick_up')) {
|
|
462
|
+
_context9.next = 20;
|
|
463
|
+
break;
|
|
464
|
+
}
|
|
465
|
+
order.updateTempOrderServiceType(selection.serviceType);
|
|
466
|
+
return _context9.abrupt("return", this.getSelection());
|
|
467
|
+
case 20:
|
|
468
|
+
slot = selection.mode === 'asap' ? getAsapPickupTiming(_objectSpread(_objectSpread({}, snapshot), {}, {
|
|
469
|
+
now: now
|
|
470
|
+
})) : result.slot;
|
|
471
|
+
if (slot) {
|
|
472
|
+
_context9.next = 23;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
throw new Error('Please choose a pickup time.');
|
|
476
|
+
case 23:
|
|
477
|
+
// Validate everything before either field is changed; notify once after the combined update.
|
|
478
|
+
tempOrder.metadata = _objectSpread(_objectSpread({}, tempOrder.metadata || {}), {}, {
|
|
479
|
+
shop_service_data: _objectSpread(_objectSpread({}, ((_tempOrder$metadata2 = tempOrder.metadata) === null || _tempOrder$metadata2 === void 0 ? void 0 : _tempOrder$metadata2.shop_service_data) || {}), {}, {
|
|
480
|
+
service_type: 'pick_up'
|
|
481
|
+
})
|
|
482
|
+
});
|
|
483
|
+
order.setPickupTimingBooking({
|
|
484
|
+
mode: selection.mode,
|
|
485
|
+
source: selection.mode === 'asap' ? 'asap' : selection.source === 'pos_manual' ? 'pos_manual' : 'schedule',
|
|
486
|
+
date: slot.date,
|
|
487
|
+
time: slot.time,
|
|
488
|
+
instant: slot.instant,
|
|
489
|
+
timezone: snapshot.timezone,
|
|
490
|
+
frozen: (_options$frozen = options.frozen) !== null && _options$frozen !== void 0 ? _options$frozen : false
|
|
491
|
+
});
|
|
492
|
+
return _context9.abrupt("return", this.getSelection());
|
|
493
|
+
case 26:
|
|
494
|
+
case "end":
|
|
495
|
+
return _context9.stop();
|
|
496
|
+
}
|
|
497
|
+
}, _callee9, this);
|
|
498
|
+
}));
|
|
499
|
+
function setSelection(_x8) {
|
|
500
|
+
return _setSelection.apply(this, arguments);
|
|
501
|
+
}
|
|
502
|
+
return setSelection;
|
|
503
|
+
}() /** Called before a new checkout/payment; payment callbacks keep their already prepared appointment. */
|
|
504
|
+
}, {
|
|
505
|
+
key: "prepare",
|
|
506
|
+
value: (function () {
|
|
507
|
+
var _prepare = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
508
|
+
var _order$getOrderIdenti, _booking$metadata$ful, _order$getTempOrder, _options$freeze;
|
|
509
|
+
var options,
|
|
510
|
+
order,
|
|
511
|
+
tempOrder,
|
|
512
|
+
sequence,
|
|
513
|
+
booking,
|
|
514
|
+
paymentStatus,
|
|
515
|
+
detail,
|
|
516
|
+
snapshot,
|
|
517
|
+
selection,
|
|
518
|
+
_args10 = arguments;
|
|
519
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
520
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
521
|
+
case 0:
|
|
522
|
+
options = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
|
|
523
|
+
order = this.host.getOrder();
|
|
524
|
+
tempOrder = order.getTempOrder();
|
|
525
|
+
sequence = this.writeSequence;
|
|
526
|
+
if (!((_order$getOrderIdenti = order.getOrderIdentity()) !== null && _order$getOrderIdenti !== void 0 && _order$getOrderIdenti.isSubmitted)) {
|
|
527
|
+
_context10.next = 6;
|
|
528
|
+
break;
|
|
529
|
+
}
|
|
530
|
+
return _context10.abrupt("return", this.getSelection());
|
|
531
|
+
case 6:
|
|
532
|
+
booking = order.getPickupTimingBooking();
|
|
533
|
+
if (!(booking !== null && booking !== void 0 && (_booking$metadata$ful = booking.metadata.fulfillment_timing) !== null && _booking$metadata$ful !== void 0 && _booking$metadata$ful.frozen)) {
|
|
534
|
+
_context10.next = 9;
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
return _context10.abrupt("return", this.getSelection());
|
|
538
|
+
case 9:
|
|
539
|
+
// An actual payment callback must never revalidate or move the time after funds have been taken.
|
|
540
|
+
paymentStatus = (_order$getTempOrder = order.getTempOrder()) === null || _order$getTempOrder === void 0 ? void 0 : _order$getTempOrder.payment_status;
|
|
541
|
+
if (!(paymentStatus === 'paid' || paymentStatus === 'partially_paid')) {
|
|
542
|
+
_context10.next = 13;
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
if (booking !== null && booking !== void 0 && booking.metadata.fulfillment_timing) {
|
|
546
|
+
detail = booking.metadata.fulfillment_timing;
|
|
547
|
+
order.setPickupTimingBooking(_objectSpread(_objectSpread({}, detail), {}, {
|
|
548
|
+
date: booking.start_date,
|
|
549
|
+
time: booking.start_time,
|
|
550
|
+
frozen: true
|
|
551
|
+
}));
|
|
552
|
+
}
|
|
553
|
+
return _context10.abrupt("return", this.getSelection());
|
|
554
|
+
case 13:
|
|
555
|
+
_context10.next = 15;
|
|
556
|
+
return this.snapshot(false);
|
|
557
|
+
case 15:
|
|
558
|
+
snapshot = _context10.sent;
|
|
559
|
+
if (!(order !== this.host.getOrder() || order.getTempOrder() !== tempOrder || sequence !== this.writeSequence)) {
|
|
560
|
+
_context10.next = 18;
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
throw new Error('The order changed. Please choose the pickup time again.');
|
|
564
|
+
case 18:
|
|
565
|
+
selection = this.getSelection();
|
|
566
|
+
if (snapshot.config.handoverModes.length) {
|
|
567
|
+
_context10.next = 22;
|
|
568
|
+
break;
|
|
569
|
+
}
|
|
570
|
+
order.clearPickupTimingBooking();
|
|
571
|
+
return _context10.abrupt("return", selection);
|
|
572
|
+
case 22:
|
|
573
|
+
return _context10.abrupt("return", this.setSelection(selection, {
|
|
574
|
+
frozen: (_options$freeze = options.freeze) !== null && _options$freeze !== void 0 ? _options$freeze : false
|
|
575
|
+
}));
|
|
576
|
+
case 23:
|
|
577
|
+
case "end":
|
|
578
|
+
return _context10.stop();
|
|
579
|
+
}
|
|
580
|
+
}, _callee10, this);
|
|
581
|
+
}));
|
|
582
|
+
function prepare() {
|
|
583
|
+
return _prepare.apply(this, arguments);
|
|
584
|
+
}
|
|
585
|
+
return prepare;
|
|
586
|
+
}())
|
|
587
|
+
}]);
|
|
588
|
+
return PickupTimingController;
|
|
589
|
+
}();
|