@pisell/pisellos 0.10.49 → 0.10.51

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.
Files changed (62) hide show
  1. package/dist/modules/Discount/types.d.ts +2 -0
  2. package/dist/modules/FulfillmentTiming/index.d.ts +11 -0
  3. package/dist/modules/FulfillmentTiming/index.js +407 -0
  4. package/dist/modules/FulfillmentTiming/types.d.ts +67 -0
  5. package/dist/modules/FulfillmentTiming/types.js +1 -0
  6. package/dist/modules/OpenData/types.d.ts +6 -0
  7. package/dist/modules/Order/index.d.ts +19 -1
  8. package/dist/modules/Order/index.js +362 -217
  9. package/dist/modules/Order/pickupTiming.d.ts +46 -0
  10. package/dist/modules/Order/pickupTiming.js +53 -0
  11. package/dist/modules/Order/types.d.ts +11 -1
  12. package/dist/modules/Order/utils.d.ts +10 -0
  13. package/dist/modules/Order/utils.js +145 -85
  14. package/dist/modules/Rules/index.js +45 -26
  15. package/dist/modules/Rules/types.d.ts +4 -0
  16. package/dist/modules/index.d.ts +1 -0
  17. package/dist/modules/index.js +1 -0
  18. package/dist/server/modules/order/index.d.ts +8 -0
  19. package/dist/server/modules/order/index.js +506 -453
  20. package/dist/server/modules/order/types.d.ts +1 -0
  21. package/dist/server/utils/small-ticket.js +173 -95
  22. package/dist/solution/BaseSales/index.d.ts +23 -0
  23. package/dist/solution/BaseSales/index.js +1216 -1031
  24. package/dist/solution/BaseSales/pickupTiming.d.ts +37 -0
  25. package/dist/solution/BaseSales/pickupTiming.js +482 -0
  26. package/dist/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  27. package/dist/solution/BookingByStep/index.d.ts +1 -1
  28. package/dist/solution/BookingTicket/utils/cartView.js +3 -1
  29. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -0
  30. package/dist/solution/UnifiedBookingSales/index.js +583 -531
  31. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  32. package/lib/modules/Discount/types.d.ts +2 -0
  33. package/lib/modules/FulfillmentTiming/index.d.ts +11 -0
  34. package/lib/modules/FulfillmentTiming/index.js +359 -0
  35. package/lib/modules/FulfillmentTiming/types.d.ts +67 -0
  36. package/lib/modules/FulfillmentTiming/types.js +5 -0
  37. package/lib/modules/OpenData/types.d.ts +6 -0
  38. package/lib/modules/Order/index.d.ts +19 -1
  39. package/lib/modules/Order/index.js +120 -7
  40. package/lib/modules/Order/pickupTiming.d.ts +46 -0
  41. package/lib/modules/Order/pickupTiming.js +61 -0
  42. package/lib/modules/Order/types.d.ts +11 -1
  43. package/lib/modules/Order/utils.d.ts +10 -0
  44. package/lib/modules/Order/utils.js +58 -4
  45. package/lib/modules/Rules/index.js +24 -13
  46. package/lib/modules/Rules/types.d.ts +4 -0
  47. package/lib/modules/index.d.ts +1 -0
  48. package/lib/modules/index.js +11 -0
  49. package/lib/server/modules/order/index.d.ts +8 -0
  50. package/lib/server/modules/order/index.js +19 -0
  51. package/lib/server/modules/order/types.d.ts +1 -0
  52. package/lib/server/utils/small-ticket.js +93 -22
  53. package/lib/solution/BaseSales/index.d.ts +23 -0
  54. package/lib/solution/BaseSales/index.js +104 -1
  55. package/lib/solution/BaseSales/pickupTiming.d.ts +37 -0
  56. package/lib/solution/BaseSales/pickupTiming.js +222 -0
  57. package/lib/solution/BaseSales/utils/parseSalesResponse.js +3 -0
  58. package/lib/solution/BookingByStep/index.d.ts +1 -1
  59. package/lib/solution/BookingTicket/utils/cartView.js +3 -1
  60. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -0
  61. package/lib/solution/UnifiedBookingSales/index.js +20 -0
  62. package/package.json +1 -1
@@ -0,0 +1,37 @@
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
+ /** Coordinates fresh configuration with the independent appointment; UI keeps edit drafts. */
14
+ export declare class PickupTimingController {
15
+ private readonly host;
16
+ private latest?;
17
+ private readonly requests;
18
+ private writeSequence;
19
+ constructor(host: PickupTimingHost);
20
+ private now;
21
+ private snapshot;
22
+ getAvailability(params?: {
23
+ date?: string;
24
+ force?: boolean;
25
+ }): Promise<PickupTimingAvailability>;
26
+ getSelection(): PickupTimingSelection;
27
+ private validateSnapshot;
28
+ validate(selection: PickupTimingSelection): Promise<PickupTimingValidationResult>;
29
+ setSelection(selection: PickupTimingSelection, options?: {
30
+ frozen?: boolean;
31
+ }): Promise<PickupTimingSelection>;
32
+ /** Called before a new checkout/payment; payment callbacks keep their already prepared appointment. */
33
+ prepare(options?: {
34
+ freeze?: boolean;
35
+ }): Promise<PickupTimingSelection>;
36
+ }
37
+ export {};
@@ -0,0 +1,482 @@
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 _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; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ 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."); }
7
+ 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); }
8
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ 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; }
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
+ /** Coordinates fresh configuration with the independent appointment; UI keeps edit drafts. */
25
+ function _withTimeout() {
26
+ _withTimeout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(request) {
27
+ var timer;
28
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
29
+ while (1) switch (_context8.prev = _context8.next) {
30
+ case 0:
31
+ _context8.prev = 0;
32
+ _context8.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 _context8.abrupt("return", _context8.sent);
40
+ case 4:
41
+ _context8.prev = 4;
42
+ if (timer !== undefined) clearTimeout(timer);
43
+ return _context8.finish(4);
44
+ case 7:
45
+ case "end":
46
+ return _context8.stop();
47
+ }
48
+ }, _callee8, 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, "requests", new Map());
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
+ key: "snapshot",
68
+ value: function () {
69
+ var _snapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(force, includeSchedule) {
70
+ var _this = this;
71
+ var tolerateScheduleError,
72
+ scope,
73
+ key,
74
+ request,
75
+ result,
76
+ _args2 = arguments;
77
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
78
+ while (1) switch (_context2.prev = _context2.next) {
79
+ case 0:
80
+ tolerateScheduleError = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : false;
81
+ scope = this.host.getScope();
82
+ key = "".concat(scope, ":").concat(force, ":").concat(includeSchedule, ":").concat(tolerateScheduleError);
83
+ request = this.requests.get(key);
84
+ if (!request) {
85
+ request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
86
+ var config, timezone, schedules, error, schedule, ids;
87
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
88
+ while (1) switch (_context.prev = _context.next) {
89
+ case 0:
90
+ _context.t0 = normalizePickupTimingConfig;
91
+ _context.next = 3;
92
+ return withTimeout(_this.host.loadOpenData(force));
93
+ case 3:
94
+ _context.t1 = _context.sent;
95
+ config = (0, _context.t0)(_context.t1);
96
+ timezone = _this.host.getTimezone();
97
+ schedules = [];
98
+ if (!(includeSchedule && config.handoverModes.includes('pick_up') && config.timingMode !== 'asap_only' && config.scheduleIds.length)) {
99
+ _context.next = 23;
100
+ break;
101
+ }
102
+ _context.prev = 8;
103
+ schedule = _this.host.getSchedule();
104
+ if (schedule) {
105
+ _context.next = 12;
106
+ break;
107
+ }
108
+ throw new Error('Pickup schedule is unavailable. Please try again.');
109
+ case 12:
110
+ _context.next = 14;
111
+ return withTimeout(schedule.loadAllSchedule({
112
+ useCache: false
113
+ }));
114
+ case 14:
115
+ ids = _toConsumableArray(new Set([].concat(_toConsumableArray(config.scheduleIds), _toConsumableArray(config.operatingHoursScheduleIds || []))));
116
+ schedules = cloneDeep(schedule.getScheduleListByIds(ids) || []);
117
+ _context.next = 23;
118
+ break;
119
+ case 18:
120
+ _context.prev = 18;
121
+ _context.t2 = _context["catch"](8);
122
+ if (tolerateScheduleError) {
123
+ _context.next = 22;
124
+ break;
125
+ }
126
+ throw _context.t2;
127
+ case 22:
128
+ error = _context.t2 instanceof Error ? _context.t2.message : 'Pickup schedule is unavailable. Please try again.';
129
+ case 23:
130
+ if (!(scope !== _this.host.getScope())) {
131
+ _context.next = 25;
132
+ break;
133
+ }
134
+ throw new Error('Store settings changed. Please try again.');
135
+ case 25:
136
+ return _context.abrupt("return", {
137
+ config: config,
138
+ timezone: timezone,
139
+ schedules: schedules,
140
+ scope: scope,
141
+ error: error
142
+ });
143
+ case 26:
144
+ case "end":
145
+ return _context.stop();
146
+ }
147
+ }, _callee, null, [[8, 18]]);
148
+ }))();
149
+ this.requests.set(key, request);
150
+ }
151
+ _context2.prev = 5;
152
+ _context2.next = 8;
153
+ return request;
154
+ case 8:
155
+ result = _context2.sent;
156
+ if (!(scope !== this.host.getScope())) {
157
+ _context2.next = 11;
158
+ break;
159
+ }
160
+ throw new Error('Store settings changed. Please try again.');
161
+ case 11:
162
+ this.latest = result;
163
+ return _context2.abrupt("return", result);
164
+ case 13:
165
+ _context2.prev = 13;
166
+ if (this.requests.get(key) === request) this.requests.delete(key);
167
+ return _context2.finish(13);
168
+ case 16:
169
+ case "end":
170
+ return _context2.stop();
171
+ }
172
+ }, _callee2, this, [[5,, 13, 16]]);
173
+ }));
174
+ function snapshot(_x2, _x3) {
175
+ return _snapshot.apply(this, arguments);
176
+ }
177
+ return snapshot;
178
+ }()
179
+ }, {
180
+ key: "getAvailability",
181
+ value: function () {
182
+ var _getAvailability = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
183
+ var params,
184
+ snapshot,
185
+ now,
186
+ _args3 = arguments;
187
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
188
+ while (1) switch (_context3.prev = _context3.next) {
189
+ case 0:
190
+ params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
191
+ _context3.next = 3;
192
+ return this.snapshot(params.force !== false, true, true);
193
+ case 3:
194
+ snapshot = _context3.sent;
195
+ now = this.now();
196
+ _context3.prev = 5;
197
+ return _context3.abrupt("return", _objectSpread(_objectSpread({}, computePickupTimingAvailability(_objectSpread(_objectSpread({}, snapshot), {}, {
198
+ date: params.date,
199
+ now: now
200
+ }))), {}, {
201
+ error: snapshot.error
202
+ }));
203
+ case 9:
204
+ _context3.prev = 9;
205
+ _context3.t0 = _context3["catch"](5);
206
+ return _context3.abrupt("return", {
207
+ config: snapshot.config,
208
+ timezone: snapshot.timezone,
209
+ now: now.toISOString(),
210
+ today: '',
211
+ maxDate: '',
212
+ date: params.date || '',
213
+ dates: [],
214
+ slots: [],
215
+ error: _context3.t0 instanceof Error ? _context3.t0.message : 'Pickup times are unavailable. Please try again.'
216
+ });
217
+ case 12:
218
+ case "end":
219
+ return _context3.stop();
220
+ }
221
+ }, _callee3, this, [[5, 9]]);
222
+ }));
223
+ function getAvailability() {
224
+ return _getAvailability.apply(this, arguments);
225
+ }
226
+ return getAvailability;
227
+ }()
228
+ }, {
229
+ key: "getSelection",
230
+ value: function getSelection() {
231
+ var _this$latest, _tempOrder$metadata, _details$mode;
232
+ var order = this.host.getOrder();
233
+ var tempOrder = order.getTempOrder();
234
+ var booking = order.getPickupTimingBooking();
235
+ var config = ((_this$latest = this.latest) === null || _this$latest === void 0 ? void 0 : _this$latest.scope) === this.host.getScope() ? this.latest.config : undefined;
236
+ 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) || '');
237
+ var serviceType = config !== null && config !== void 0 && config.handoverModes.length ? config.handoverModes.includes(storedServiceType) ? storedServiceType : config.handoverModes[0] : storedServiceType;
238
+ var details = serviceType === 'pick_up' ? booking === null || booking === void 0 ? void 0 : booking.metadata.fulfillment_timing : undefined;
239
+ 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';
240
+ var sameMode = (details === null || details === void 0 ? void 0 : details.mode) === mode;
241
+ return _objectSpread({
242
+ serviceType: serviceType,
243
+ mode: mode,
244
+ source: mode === 'asap' ? 'asap' : sameMode && (details === null || details === void 0 ? void 0 : details.source) || 'schedule'
245
+ }, sameMode && booking ? {
246
+ date: booking.start_date,
247
+ time: booking.start_time,
248
+ instant: details === null || details === void 0 ? void 0 : details.instant
249
+ } : {});
250
+ }
251
+ }, {
252
+ key: "validateSnapshot",
253
+ value: function () {
254
+ var _validateSnapshot = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(selection) {
255
+ var snapshot, now, result;
256
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
257
+ while (1) switch (_context4.prev = _context4.next) {
258
+ case 0:
259
+ _context4.next = 2;
260
+ return this.snapshot(true, selection.serviceType === 'pick_up' && selection.mode === 'scheduled' && selection.source !== 'pos_manual');
261
+ case 2:
262
+ snapshot = _context4.sent;
263
+ now = this.now();
264
+ result = validatePickupTimingSelection(selection, _objectSpread(_objectSpread({}, snapshot), {}, {
265
+ now: now,
266
+ allowManualOverride: this.host.isPos()
267
+ }));
268
+ return _context4.abrupt("return", {
269
+ snapshot: snapshot,
270
+ now: now,
271
+ result: result
272
+ });
273
+ case 6:
274
+ case "end":
275
+ return _context4.stop();
276
+ }
277
+ }, _callee4, this);
278
+ }));
279
+ function validateSnapshot(_x4) {
280
+ return _validateSnapshot.apply(this, arguments);
281
+ }
282
+ return validateSnapshot;
283
+ }()
284
+ }, {
285
+ key: "validate",
286
+ value: function () {
287
+ var _validate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(selection) {
288
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
289
+ while (1) switch (_context5.prev = _context5.next) {
290
+ case 0:
291
+ _context5.next = 2;
292
+ return this.validateSnapshot(selection);
293
+ case 2:
294
+ return _context5.abrupt("return", _context5.sent.result);
295
+ case 3:
296
+ case "end":
297
+ return _context5.stop();
298
+ }
299
+ }, _callee5, this);
300
+ }));
301
+ function validate(_x5) {
302
+ return _validate.apply(this, arguments);
303
+ }
304
+ return validate;
305
+ }()
306
+ }, {
307
+ key: "setSelection",
308
+ value: function () {
309
+ var _setSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(selection) {
310
+ var _tempOrder$metadata2, _options$frozen;
311
+ var options,
312
+ order,
313
+ tempOrder,
314
+ sequence,
315
+ _yield$this$validateS,
316
+ snapshot,
317
+ now,
318
+ result,
319
+ slot,
320
+ _args6 = arguments;
321
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
322
+ while (1) switch (_context6.prev = _context6.next) {
323
+ case 0:
324
+ options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
325
+ order = this.host.getOrder();
326
+ tempOrder = order.ensureTempOrder();
327
+ sequence = ++this.writeSequence;
328
+ _context6.next = 6;
329
+ return this.validateSnapshot(selection);
330
+ case 6:
331
+ _yield$this$validateS = _context6.sent;
332
+ snapshot = _yield$this$validateS.snapshot;
333
+ now = _yield$this$validateS.now;
334
+ result = _yield$this$validateS.result;
335
+ if (!(sequence !== this.writeSequence || order.getTempOrder() !== tempOrder || snapshot.scope !== this.host.getScope())) {
336
+ _context6.next = 12;
337
+ break;
338
+ }
339
+ throw new Error('The order changed. Please choose the pickup time again.');
340
+ case 12:
341
+ if (result.valid) {
342
+ _context6.next = 14;
343
+ break;
344
+ }
345
+ throw new Error(result.message || 'Please choose a valid pickup time.');
346
+ case 14:
347
+ if (snapshot.config.handoverModes.length) {
348
+ _context6.next = 17;
349
+ break;
350
+ }
351
+ order.clearPickupTimingBooking();
352
+ return _context6.abrupt("return", this.getSelection());
353
+ case 17:
354
+ if (!(selection.serviceType !== 'pick_up')) {
355
+ _context6.next = 20;
356
+ break;
357
+ }
358
+ order.updateTempOrderServiceType(selection.serviceType);
359
+ return _context6.abrupt("return", this.getSelection());
360
+ case 20:
361
+ slot = selection.mode === 'asap' ? getAsapPickupTiming(_objectSpread(_objectSpread({}, snapshot), {}, {
362
+ now: now
363
+ })) : result.slot;
364
+ if (slot) {
365
+ _context6.next = 23;
366
+ break;
367
+ }
368
+ throw new Error('Please choose a pickup time.');
369
+ case 23:
370
+ // Validate everything before either field is changed; notify once after the combined update.
371
+ tempOrder.metadata = _objectSpread(_objectSpread({}, tempOrder.metadata || {}), {}, {
372
+ shop_service_data: _objectSpread(_objectSpread({}, ((_tempOrder$metadata2 = tempOrder.metadata) === null || _tempOrder$metadata2 === void 0 ? void 0 : _tempOrder$metadata2.shop_service_data) || {}), {}, {
373
+ service_type: 'pick_up'
374
+ })
375
+ });
376
+ order.setPickupTimingBooking({
377
+ mode: selection.mode,
378
+ source: selection.mode === 'asap' ? 'asap' : selection.source === 'pos_manual' ? 'pos_manual' : 'schedule',
379
+ date: slot.date,
380
+ time: slot.time,
381
+ instant: slot.instant,
382
+ timezone: snapshot.timezone,
383
+ frozen: (_options$frozen = options.frozen) !== null && _options$frozen !== void 0 ? _options$frozen : false
384
+ });
385
+ return _context6.abrupt("return", this.getSelection());
386
+ case 26:
387
+ case "end":
388
+ return _context6.stop();
389
+ }
390
+ }, _callee6, this);
391
+ }));
392
+ function setSelection(_x6) {
393
+ return _setSelection.apply(this, arguments);
394
+ }
395
+ return setSelection;
396
+ }() /** Called before a new checkout/payment; payment callbacks keep their already prepared appointment. */
397
+ }, {
398
+ key: "prepare",
399
+ value: (function () {
400
+ var _prepare = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
401
+ var _order$getOrderIdenti, _booking$metadata$ful, _order$getTempOrder, _options$freeze;
402
+ var options,
403
+ order,
404
+ tempOrder,
405
+ sequence,
406
+ booking,
407
+ paymentStatus,
408
+ detail,
409
+ snapshot,
410
+ selection,
411
+ _args7 = arguments;
412
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
413
+ while (1) switch (_context7.prev = _context7.next) {
414
+ case 0:
415
+ options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
416
+ order = this.host.getOrder();
417
+ tempOrder = order.getTempOrder();
418
+ sequence = this.writeSequence;
419
+ if (!((_order$getOrderIdenti = order.getOrderIdentity()) !== null && _order$getOrderIdenti !== void 0 && _order$getOrderIdenti.isSubmitted)) {
420
+ _context7.next = 6;
421
+ break;
422
+ }
423
+ return _context7.abrupt("return", this.getSelection());
424
+ case 6:
425
+ booking = order.getPickupTimingBooking();
426
+ if (!(booking !== null && booking !== void 0 && (_booking$metadata$ful = booking.metadata.fulfillment_timing) !== null && _booking$metadata$ful !== void 0 && _booking$metadata$ful.frozen)) {
427
+ _context7.next = 9;
428
+ break;
429
+ }
430
+ return _context7.abrupt("return", this.getSelection());
431
+ case 9:
432
+ // An actual payment callback must never revalidate or move the time after funds have been taken.
433
+ paymentStatus = (_order$getTempOrder = order.getTempOrder()) === null || _order$getTempOrder === void 0 ? void 0 : _order$getTempOrder.payment_status;
434
+ if (!(paymentStatus === 'paid' || paymentStatus === 'partially_paid')) {
435
+ _context7.next = 13;
436
+ break;
437
+ }
438
+ if (booking !== null && booking !== void 0 && booking.metadata.fulfillment_timing) {
439
+ detail = booking.metadata.fulfillment_timing;
440
+ order.setPickupTimingBooking(_objectSpread(_objectSpread({}, detail), {}, {
441
+ date: booking.start_date,
442
+ time: booking.start_time,
443
+ frozen: true
444
+ }));
445
+ }
446
+ return _context7.abrupt("return", this.getSelection());
447
+ case 13:
448
+ _context7.next = 15;
449
+ return this.snapshot(true, false);
450
+ case 15:
451
+ snapshot = _context7.sent;
452
+ if (!(order !== this.host.getOrder() || order.getTempOrder() !== tempOrder || sequence !== this.writeSequence)) {
453
+ _context7.next = 18;
454
+ break;
455
+ }
456
+ throw new Error('The order changed. Please choose the pickup time again.');
457
+ case 18:
458
+ selection = this.getSelection();
459
+ if (snapshot.config.handoverModes.length) {
460
+ _context7.next = 22;
461
+ break;
462
+ }
463
+ order.clearPickupTimingBooking();
464
+ return _context7.abrupt("return", selection);
465
+ case 22:
466
+ return _context7.abrupt("return", this.setSelection(selection, {
467
+ frozen: (_options$freeze = options.freeze) !== null && _options$freeze !== void 0 ? _options$freeze : false
468
+ }));
469
+ case 23:
470
+ case "end":
471
+ return _context7.stop();
472
+ }
473
+ }, _callee7, this);
474
+ }));
475
+ function prepare() {
476
+ return _prepare.apply(this, arguments);
477
+ }
478
+ return prepare;
479
+ }())
480
+ }]);
481
+ return PickupTimingController;
482
+ }();
@@ -24,6 +24,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
24
24
  */
25
25
 
26
26
  import { normalizeOrderCollections } from "../../../modules/Order/utils/orderCollectionIdentity";
27
+ import { isFulfillmentTimingBooking } from "../../../modules/Order/pickupTiming";
27
28
  /** OrderData 中除大数组外的"顶层 header 字段"白名单,按需扩展。 */
28
29
  var HEADER_KEYS = ['order_id', 'order_number', 'shop_order_number', 'shop_full_order_number', 'type', 'business_code', 'platform', 'sales_channel', 'order_sales_channel', 'vouchers', 'status', 'payment_status', 'shipping_status', 'customer_id', 'customer_name', 'country_calling_code', 'phone', 'email', 'is_price_include_tax', 'tax_title', 'tax_country_code', 'currency_code', 'currency_symbol', 'currency_format', 'is_deposit', 'deposit_amount', 'shop_discount', 'surcharge_fee', 'note', 'schedule_date', 'created_at', 'updated_at', 'order_meta_list', 'metadata', 'total_amount', 'shop_id', 'create_date', 'holder', 'relation_forms', 'contacts', 'contacts_info'];
29
30
  function pickHeader(raw) {
@@ -78,6 +79,7 @@ function pickCustomer(raw) {
78
79
  */
79
80
  function isRootBooking(booking) {
80
81
  if (!booking || _typeof(booking) !== 'object') return false;
82
+ if (isFulfillmentTimingBooking(booking)) return false;
81
83
  var parentId = booking.parent_id;
82
84
  if (parentId === 0 || parentId === null || parentId === undefined) return true;
83
85
  return false;
@@ -90,6 +92,7 @@ function indexBookingsByProductUid(bookings) {
90
92
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
91
93
  var _b$metadata;
92
94
  var b = _step2.value;
95
+ if (isFulfillmentTimingBooking(b)) continue;
93
96
  var uid = b && (b.product_uid || ((_b$metadata = b.metadata) === null || _b$metadata === void 0 ? void 0 : _b$metadata.product_uid)) || '';
94
97
  if (!uid) continue;
95
98
  var _key2 = String(uid);
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  date: string;
327
327
  status: string;
328
328
  week: string;
329
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
329
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
330
330
  }[]>;
331
331
  submitTimeSlot(timeSlots: TimeSliceItem): void;
332
332
  private getScheduleDataByIds;
@@ -5,12 +5,14 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  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); }
7
7
  import { resolveBookingCanAddTime } from "./addTimeAvailability";
8
+ import { isFulfillmentTimingBooking } from "../../../modules/Order/pickupTiming";
8
9
  /**
9
10
  * 仅按 booking.product_uid 建索引,避免发明 booking 与商品行之间的其它等价关系。
10
11
  */
11
12
  export function indexBookingsByProductUid(bookings) {
12
13
  if (!Array.isArray(bookings) || bookings.length === 0) return {};
13
14
  return bookings.reduce(function (acc, booking) {
15
+ if (isFulfillmentTimingBooking(booking)) return acc;
14
16
  var uid = booking === null || booking === void 0 ? void 0 : booking.product_uid;
15
17
  if (uid === undefined || uid === null || uid === '') return acc;
16
18
  var key = String(uid);
@@ -109,7 +111,7 @@ export function buildCartView(lines, bookings) {
109
111
  var productLines = Array.isArray(lines) ? lines : [];
110
112
  var bookingList = Array.isArray(bookings) ? bookings : [];
111
113
  var childBookings = bookingList.filter(function (booking) {
112
- return booking.parent_id !== 0;
114
+ return booking.parent_id !== 0 && !isFulfillmentTimingBooking(booking);
113
115
  });
114
116
  var bookingsByProductUid = indexBookingsByProductUid(childBookings);
115
117
  var linesByUid = indexProductsByUid(productLines);
@@ -59,6 +59,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
59
59
  protected defaultName: string;
60
60
  protected defaultVersion: string;
61
61
  protected store: UnifiedBookingSalesState;
62
+ protected pickupTimingEnabled: boolean;
62
63
  private unifiedProductCatalog;
63
64
  private availabilityRuntimeOffsetMinutes;
64
65
  private availabilityScheduleCatalog;
@@ -148,6 +149,7 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
148
149
  */
149
150
  loadOpenData(params: UnifiedBookingSalesLoadOpenDataParams): Promise<OpenDataConfig>;
150
151
  getOpenData(): Promise<OpenDataConfig | null>;
152
+ protected loadPickupTimingOpenData(force: boolean): Promise<Record<string, unknown>>;
151
153
  private resetAllergyItemRuleState;
152
154
  private fetchAllergyItemRuleConfigs;
153
155
  private ensureAllergyItemRuleConfigsLoaded;