@pisell/pisellos 2.3.83 → 2.3.85

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.
@@ -11,12 +11,23 @@ export declare class QuotationModule extends BaseModule implements Module {
11
11
  private scheduleResolver?;
12
12
  private app;
13
13
  private quotationListUpdatedListener?;
14
+ private quotationCache;
15
+ private quotationLoadPromises;
16
+ private quotationCacheVersions;
17
+ private lifecycleGeneration;
18
+ private activeChannelKey;
14
19
  constructor(name?: string, version?: string);
15
20
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
16
21
  loadQuotations(params?: {
17
22
  channel?: string;
18
23
  customer_id?: number | string;
19
24
  }): Promise<void>;
25
+ ensureQuotations(params?: {
26
+ channel?: string;
27
+ customer_id?: number | string;
28
+ }): Promise<void>;
29
+ invalidateQuotationCache(channel?: string): void;
30
+ private fetchQuotations;
20
31
  getQuotationList(): QuotationItem[];
21
32
  setQuotationListUpdatedListener(listener?: () => void): void;
22
33
  getQuotationCustomerScopeInfo(): QuotationCustomerScopeInfo;
@@ -60,12 +71,17 @@ export declare class QuotationModule extends BaseModule implements Module {
60
71
  buildProductPriceMap(params: {
61
72
  productIds: number[];
62
73
  timePoints: string[];
74
+ channel?: string;
63
75
  customer_id?: number | string;
64
76
  }): Map<string, string | null>;
65
77
  setScheduleResolver(resolver: (id: number) => ScheduleItem | undefined): void;
66
78
  private applyQuotationResponse;
67
79
  private notifyQuotationListUpdated;
68
80
  private getQuotationCacheKeyData;
81
+ private normalizeChannel;
82
+ private activateChannel;
83
+ private getQuotationCacheVersion;
84
+ private bumpQuotationCacheVersion;
69
85
  private isQuotationVisibleForCustomer;
70
86
  private hasValidCustomerId;
71
87
  private normalizeCustomerId;
@@ -1,12 +1,12 @@
1
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
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
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 _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4
5
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
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); }
6
8
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9
- 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); }
10
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
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 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; }
12
12
  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); } }
@@ -42,6 +42,11 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
42
42
  _defineProperty(_assertThisInitialized(_this), "scheduleResolver", void 0);
43
43
  _defineProperty(_assertThisInitialized(_this), "app", void 0);
44
44
  _defineProperty(_assertThisInitialized(_this), "quotationListUpdatedListener", void 0);
45
+ _defineProperty(_assertThisInitialized(_this), "quotationCache", new Map());
46
+ _defineProperty(_assertThisInitialized(_this), "quotationLoadPromises", new Map());
47
+ _defineProperty(_assertThisInitialized(_this), "quotationCacheVersions", new Map());
48
+ _defineProperty(_assertThisInitialized(_this), "lifecycleGeneration", 0);
49
+ _defineProperty(_assertThisInitialized(_this), "activeChannelKey", '');
45
50
  return _this;
46
51
  }
47
52
  _createClass(QuotationModule, [{
@@ -64,7 +69,12 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
64
69
  this.store = {
65
70
  list: []
66
71
  };
67
- case 6:
72
+ this.quotationCache.clear();
73
+ this.quotationLoadPromises.clear();
74
+ this.quotationCacheVersions.clear();
75
+ this.activeChannelKey = '';
76
+ this.lifecycleGeneration += 1;
77
+ case 11:
68
78
  case "end":
69
79
  return _context.stop();
70
80
  }
@@ -79,24 +89,190 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
79
89
  key: "loadQuotations",
80
90
  value: function () {
81
91
  var _loadQuotations = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
82
- var _this2 = this;
83
- var query, initialResultApplied, applyRemoteUpdate, res;
92
+ var channelKey, cacheVersion, lifecycleGeneration, loadPromise;
84
93
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
85
94
  while (1) switch (_context2.prev = _context2.next) {
86
95
  case 0:
87
- query = {};
88
- if (params !== null && params !== void 0 && params.channel) query.channel = params.channel;
89
- if ((params === null || params === void 0 ? void 0 : params.channel) === 'online_store') {
90
- query.channel = 'online-store';
96
+ channelKey = this.normalizeChannel(params === null || params === void 0 ? void 0 : params.channel);
97
+ cacheVersion = this.bumpQuotationCacheVersion(channelKey);
98
+ lifecycleGeneration = this.lifecycleGeneration;
99
+ this.activateChannel(channelKey);
100
+ loadPromise = this.fetchQuotations({
101
+ channelKey: channelKey,
102
+ cacheVersion: cacheVersion,
103
+ lifecycleGeneration: lifecycleGeneration
104
+ });
105
+ this.quotationLoadPromises.set(channelKey, loadPromise);
106
+ _context2.prev = 6;
107
+ _context2.next = 9;
108
+ return loadPromise;
109
+ case 9:
110
+ _context2.prev = 9;
111
+ if (this.quotationLoadPromises.get(channelKey) === loadPromise) {
112
+ this.quotationLoadPromises.delete(channelKey);
113
+ }
114
+ return _context2.finish(9);
115
+ case 12:
116
+ case "end":
117
+ return _context2.stop();
118
+ }
119
+ }, _callee2, this, [[6,, 9, 12]]);
120
+ }));
121
+ function loadQuotations(_x3) {
122
+ return _loadQuotations.apply(this, arguments);
123
+ }
124
+ return loadQuotations;
125
+ }()
126
+ }, {
127
+ key: "ensureQuotations",
128
+ value: function () {
129
+ var _ensureQuotations = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
130
+ var channelKey, lifecycleGeneration, pending, cacheVersion, _latestPending, latestPending;
131
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
132
+ while (1) switch (_context3.prev = _context3.next) {
133
+ case 0:
134
+ channelKey = this.normalizeChannel(params === null || params === void 0 ? void 0 : params.channel);
135
+ lifecycleGeneration = this.lifecycleGeneration;
136
+ case 2:
137
+ if (!true) {
138
+ _context3.next = 46;
139
+ break;
140
+ }
141
+ if (!(this.lifecycleGeneration !== lifecycleGeneration)) {
142
+ _context3.next = 5;
143
+ break;
144
+ }
145
+ return _context3.abrupt("return");
146
+ case 5:
147
+ if (!this.quotationCache.has(channelKey)) {
148
+ _context3.next = 8;
149
+ break;
150
+ }
151
+ this.activateChannel(channelKey);
152
+ return _context3.abrupt("return");
153
+ case 8:
154
+ pending = this.quotationLoadPromises.get(channelKey);
155
+ if (pending) {
156
+ _context3.next = 24;
157
+ break;
158
+ }
159
+ _context3.prev = 10;
160
+ _context3.next = 13;
161
+ return this.loadQuotations(params);
162
+ case 13:
163
+ _context3.next = 23;
164
+ break;
165
+ case 15:
166
+ _context3.prev = 15;
167
+ _context3.t0 = _context3["catch"](10);
168
+ if (!this.quotationCache.has(channelKey)) {
169
+ _context3.next = 20;
170
+ break;
171
+ }
172
+ this.activateChannel(channelKey);
173
+ return _context3.abrupt("return");
174
+ case 20:
175
+ if (!this.quotationLoadPromises.has(channelKey)) {
176
+ _context3.next = 22;
177
+ break;
178
+ }
179
+ return _context3.abrupt("continue", 2);
180
+ case 22:
181
+ throw _context3.t0;
182
+ case 23:
183
+ return _context3.abrupt("continue", 2);
184
+ case 24:
185
+ cacheVersion = this.getQuotationCacheVersion(channelKey);
186
+ _context3.prev = 25;
187
+ _context3.next = 28;
188
+ return pending;
189
+ case 28:
190
+ _context3.next = 38;
191
+ break;
192
+ case 30:
193
+ _context3.prev = 30;
194
+ _context3.t1 = _context3["catch"](25);
195
+ _latestPending = this.quotationLoadPromises.get(channelKey);
196
+ if (!(_latestPending && _latestPending !== pending)) {
197
+ _context3.next = 35;
198
+ break;
91
199
  }
200
+ return _context3.abrupt("continue", 2);
201
+ case 35:
202
+ if (!(this.getQuotationCacheVersion(channelKey) !== cacheVersion)) {
203
+ _context3.next = 37;
204
+ break;
205
+ }
206
+ return _context3.abrupt("continue", 2);
207
+ case 37:
208
+ throw _context3.t1;
209
+ case 38:
210
+ if (!this.quotationCache.has(channelKey)) {
211
+ _context3.next = 41;
212
+ break;
213
+ }
214
+ this.activateChannel(channelKey);
215
+ return _context3.abrupt("return");
216
+ case 41:
217
+ latestPending = this.quotationLoadPromises.get(channelKey);
218
+ if (!(latestPending && latestPending !== pending)) {
219
+ _context3.next = 44;
220
+ break;
221
+ }
222
+ return _context3.abrupt("continue", 2);
223
+ case 44:
224
+ _context3.next = 2;
225
+ break;
226
+ case 46:
227
+ case "end":
228
+ return _context3.stop();
229
+ }
230
+ }, _callee3, this, [[10, 15], [25, 30]]);
231
+ }));
232
+ function ensureQuotations(_x4) {
233
+ return _ensureQuotations.apply(this, arguments);
234
+ }
235
+ return ensureQuotations;
236
+ }()
237
+ }, {
238
+ key: "invalidateQuotationCache",
239
+ value: function invalidateQuotationCache(channel) {
240
+ var _this2 = this;
241
+ if (channel !== undefined) {
242
+ var channelKey = this.normalizeChannel(channel);
243
+ this.bumpQuotationCacheVersion(channelKey);
244
+ this.quotationCache.delete(channelKey);
245
+ this.quotationLoadPromises.delete(channelKey);
246
+ if (this.activeChannelKey === channelKey) this.store.list = [];
247
+ return;
248
+ }
249
+ var channelKeys = new Set([].concat(_toConsumableArray(this.quotationCache.keys()), _toConsumableArray(this.quotationLoadPromises.keys()), _toConsumableArray(this.quotationCacheVersions.keys()), [this.activeChannelKey]));
250
+ channelKeys.forEach(function (channelKey) {
251
+ return _this2.bumpQuotationCacheVersion(channelKey);
252
+ });
253
+ this.quotationCache.clear();
254
+ this.quotationLoadPromises.clear();
255
+ this.store.list = [];
256
+ }
257
+ }, {
258
+ key: "fetchQuotations",
259
+ value: function () {
260
+ var _fetchQuotations = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
261
+ var _this3 = this;
262
+ var query, initialResultApplied, applyRemoteUpdate, res;
263
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
264
+ while (1) switch (_context4.prev = _context4.next) {
265
+ case 0:
266
+ query = {};
267
+ if (params.channelKey) query.channel = params.channelKey;
92
268
  initialResultApplied = false;
93
269
  applyRemoteUpdate = function applyRemoteUpdate(response) {
94
- _this2.applyQuotationResponse(response);
95
- if (initialResultApplied) {
96
- _this2.notifyQuotationListUpdated();
270
+ var applied = _this3.applyQuotationResponse(response, params);
271
+ if (applied && initialResultApplied && _this3.activeChannelKey === params.channelKey) {
272
+ _this3.notifyQuotationListUpdated();
97
273
  }
98
274
  };
99
- _context2.next = 7;
275
+ _context4.next = 6;
100
276
  return this.request.get('/quotation/available', query, {
101
277
  cache: {
102
278
  type: 'indexDB',
@@ -105,20 +281,20 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
105
281
  },
106
282
  cacheUpdateChange: applyRemoteUpdate
107
283
  });
108
- case 7:
109
- res = _context2.sent;
110
- this.applyQuotationResponse(res);
284
+ case 6:
285
+ res = _context4.sent;
286
+ this.applyQuotationResponse(res, params);
111
287
  initialResultApplied = true;
112
- case 10:
288
+ case 9:
113
289
  case "end":
114
- return _context2.stop();
290
+ return _context4.stop();
115
291
  }
116
- }, _callee2, this);
292
+ }, _callee4, this);
117
293
  }));
118
- function loadQuotations(_x3) {
119
- return _loadQuotations.apply(this, arguments);
294
+ function fetchQuotations(_x5) {
295
+ return _fetchQuotations.apply(this, arguments);
120
296
  }
121
- return loadQuotations;
297
+ return fetchQuotations;
122
298
  }()
123
299
  }, {
124
300
  key: "getQuotationList",
@@ -133,7 +309,7 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
133
309
  }, {
134
310
  key: "getQuotationCustomerScopeInfo",
135
311
  value: function getQuotationCustomerScopeInfo() {
136
- var _this3 = this;
312
+ var _this4 = this;
137
313
  var customerById = new Map();
138
314
  var quotationScopes = this.store.list.filter(function (quotation) {
139
315
  return Array.isArray(quotation.customer) && quotation.customer.length > 0;
@@ -143,7 +319,7 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
143
319
  var localSeen = new Set();
144
320
  var quotationCustomers = quotation.customer || [];
145
321
  quotationCustomers.forEach(function (customer) {
146
- var customerId = _this3.normalizeCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
322
+ var customerId = _this4.normalizeCustomerId(customer === null || customer === void 0 ? void 0 : customer.id);
147
323
  if (!customerId || localSeen.has(customerId)) return;
148
324
  localSeen.add(customerId);
149
325
  customerIds.push(customerId);
@@ -189,7 +365,8 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
189
365
  variantId = params.variantId,
190
366
  datetime = params.datetime,
191
367
  customer_id = params.customer_id;
192
- var _iterator = _createForOfIteratorHelper(this.store.list),
368
+ var quotations = params.channel === undefined ? this.store.list : this.quotationCache.get(this.normalizeChannel(params.channel)) || [];
369
+ var _iterator = _createForOfIteratorHelper(quotations),
193
370
  _step;
194
371
  try {
195
372
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
@@ -229,7 +406,8 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
229
406
  key: "buildProductPriceMap",
230
407
  value: function buildProductPriceMap(params) {
231
408
  var map = new Map();
232
- if (!this.store.list.length) return map;
409
+ var quotations = params.channel === undefined ? this.store.list : this.quotationCache.get(this.normalizeChannel(params.channel)) || [];
410
+ if (!quotations.length) return map;
233
411
  var _iterator2 = _createForOfIteratorHelper(params.productIds),
234
412
  _step2;
235
413
  try {
@@ -244,6 +422,7 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
244
422
  var price = this.getPriceForProduct({
245
423
  productId: productId,
246
424
  datetime: timePoint,
425
+ channel: params.channel,
247
426
  customer_id: params.customer_id
248
427
  });
249
428
  if (price !== null) {
@@ -270,12 +449,18 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
270
449
  }
271
450
  }, {
272
451
  key: "applyQuotationResponse",
273
- value: function applyQuotationResponse(response) {
452
+ value: function applyQuotationResponse(response, params) {
274
453
  var _data;
275
454
  var source = (response === null || response === void 0 || (_data = response.data) === null || _data === void 0 ? void 0 : _data.list) || (response === null || response === void 0 ? void 0 : response.list) || [];
276
- this.store.list = _toConsumableArray(source).sort(function (a, b) {
455
+ var list = _toConsumableArray(source).sort(function (a, b) {
277
456
  return Number(b.sort || 0) - Number(a.sort || 0);
278
457
  });
458
+ if (this.lifecycleGeneration !== params.lifecycleGeneration || this.getQuotationCacheVersion(params.channelKey) !== params.cacheVersion) {
459
+ return false;
460
+ }
461
+ this.quotationCache.set(params.channelKey, list);
462
+ if (this.activeChannelKey === params.channelKey) this.store.list = list;
463
+ return true;
279
464
  }
280
465
  }, {
281
466
  key: "notifyQuotationListUpdated",
@@ -303,6 +488,30 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
303
488
  shop_id: shopId
304
489
  });
305
490
  }
491
+ }, {
492
+ key: "normalizeChannel",
493
+ value: function normalizeChannel(channel) {
494
+ var normalized = (channel === null || channel === void 0 ? void 0 : channel.trim().toLowerCase()) || '';
495
+ return normalized === 'online_store' ? 'online-store' : normalized;
496
+ }
497
+ }, {
498
+ key: "activateChannel",
499
+ value: function activateChannel(channelKey) {
500
+ this.activeChannelKey = channelKey;
501
+ this.store.list = this.quotationCache.get(channelKey) || [];
502
+ }
503
+ }, {
504
+ key: "getQuotationCacheVersion",
505
+ value: function getQuotationCacheVersion(channelKey) {
506
+ return this.quotationCacheVersions.get(channelKey) || 0;
507
+ }
508
+ }, {
509
+ key: "bumpQuotationCacheVersion",
510
+ value: function bumpQuotationCacheVersion(channelKey) {
511
+ var nextVersion = this.getQuotationCacheVersion(channelKey) + 1;
512
+ this.quotationCacheVersions.set(channelKey, nextVersion);
513
+ return nextVersion;
514
+ }
306
515
  }, {
307
516
  key: "isQuotationVisibleForCustomer",
308
517
  value: function isQuotationVisibleForCustomer(quotation, customerId) {
@@ -329,17 +538,17 @@ export var QuotationModule = /*#__PURE__*/function (_BaseModule) {
329
538
  key: "isQuotationActiveAt",
330
539
  value: function isQuotationActiveAt(quotation, datetime) {
331
540
  var _quotation$schedule,
332
- _this4 = this;
541
+ _this5 = this;
333
542
  if (!((_quotation$schedule = quotation.schedule) !== null && _quotation$schedule !== void 0 && _quotation$schedule.length)) return false;
334
543
  var scheduleItems = [];
335
544
  quotation.schedule.forEach(function (s) {
336
- var _this4$scheduleResolv;
337
- var full = (_this4$scheduleResolv = _this4.scheduleResolver) === null || _this4$scheduleResolv === void 0 ? void 0 : _this4$scheduleResolv.call(_this4, s.id);
545
+ var _this5$scheduleResolv;
546
+ var full = (_this5$scheduleResolv = _this5.scheduleResolver) === null || _this5$scheduleResolv === void 0 ? void 0 : _this5$scheduleResolv.call(_this5, s.id);
338
547
  if (full) {
339
548
  scheduleItems.push(full);
340
549
  return;
341
550
  }
342
- if (_this4.scheduleResolver) {
551
+ if (_this5.scheduleResolver) {
343
552
  return;
344
553
  }
345
554
  var fallbackSchedule = _objectSpread(_objectSpread({}, s), {}, {
@@ -3634,7 +3634,7 @@ var Server = /*#__PURE__*/function () {
3634
3634
  // timerIds.push(timerId);
3635
3635
  // }
3636
3636
  setInterval(function () {
3637
- var currentTime = dayjs().format('hh:mm');
3637
+ var currentTime = dayjs().format('HH:mm');
3638
3638
  if (timePoints.includes(currentTime)) {
3639
3639
  _this8.onScheduleTimePointTimerFire(subscriberId);
3640
3640
  }