@pisell/pisellos 2.3.93 → 2.3.95

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 (75) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +135 -35
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +25 -1
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +44 -0
  6. package/dist/model/strategy/adapter/itemRule/type.js +19 -1
  7. package/dist/modules/Order/index.d.ts +18 -3
  8. package/dist/modules/Order/index.js +885 -485
  9. package/dist/modules/Order/salesNotes.d.ts +31 -0
  10. package/dist/modules/Order/salesNotes.js +492 -0
  11. package/dist/modules/Order/types.d.ts +91 -5
  12. package/dist/modules/Order/types.js +5 -0
  13. package/dist/modules/Order/utils.d.ts +12 -0
  14. package/dist/modules/Order/utils.js +75 -26
  15. package/dist/modules/ProductList/index.d.ts +2 -1
  16. package/dist/modules/ProductList/index.js +100 -20
  17. package/dist/modules/ProductList/types.d.ts +10 -0
  18. package/dist/modules/ResourcePlanner/planner.js +5 -3
  19. package/dist/modules/ResourcePlanner/types.d.ts +5 -0
  20. package/dist/server/index.d.ts +6 -0
  21. package/dist/server/index.js +43 -3
  22. package/dist/solution/BaseSales/index.d.ts +9 -1
  23. package/dist/solution/BaseSales/index.js +894 -706
  24. package/dist/solution/BookingByStep/index.d.ts +2 -2
  25. package/dist/solution/BookingTicket/utils/orderCustomer.js +3 -2
  26. package/dist/solution/RegisterAndLogin/config.d.ts +9 -3
  27. package/dist/solution/RegisterAndLogin/config.js +95 -40
  28. package/dist/solution/RegisterAndLogin/index.js +4 -1
  29. package/dist/solution/ScanOrder/index.d.ts +1 -0
  30. package/dist/solution/ScanOrder/index.js +31 -27
  31. package/dist/solution/ScanOrder/utils.d.ts +1 -0
  32. package/dist/solution/ScanOrder/utils.js +2 -0
  33. package/dist/solution/UnifiedBookingSales/index.d.ts +15 -2
  34. package/dist/solution/UnifiedBookingSales/index.js +767 -488
  35. package/dist/solution/UnifiedBookingSales/types.d.ts +14 -1
  36. package/dist/solution/VenueBooking/index.d.ts +1 -0
  37. package/dist/solution/VenueBooking/index.js +8 -4
  38. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +4 -1
  39. package/lib/model/strategy/adapter/itemRule/adapter.js +73 -4
  40. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +8 -1
  41. package/lib/model/strategy/adapter/itemRule/evaluator.js +23 -1
  42. package/lib/model/strategy/adapter/itemRule/type.d.ts +44 -0
  43. package/lib/model/strategy/adapter/itemRule/type.js +19 -1
  44. package/lib/modules/Order/index.d.ts +18 -3
  45. package/lib/modules/Order/index.js +325 -28
  46. package/lib/modules/Order/salesNotes.d.ts +31 -0
  47. package/lib/modules/Order/salesNotes.js +382 -0
  48. package/lib/modules/Order/types.d.ts +91 -5
  49. package/lib/modules/Order/types.js +4 -0
  50. package/lib/modules/Order/utils.d.ts +12 -0
  51. package/lib/modules/Order/utils.js +68 -16
  52. package/lib/modules/ProductList/index.d.ts +2 -1
  53. package/lib/modules/ProductList/index.js +47 -2
  54. package/lib/modules/ProductList/types.d.ts +10 -0
  55. package/lib/modules/ResourcePlanner/planner.js +5 -3
  56. package/lib/modules/ResourcePlanner/types.d.ts +5 -0
  57. package/lib/server/index.d.ts +6 -0
  58. package/lib/server/index.js +37 -3
  59. package/lib/solution/BaseSales/index.d.ts +9 -1
  60. package/lib/solution/BaseSales/index.js +105 -1
  61. package/lib/solution/BookingByStep/index.d.ts +2 -2
  62. package/lib/solution/BookingTicket/utils/orderCustomer.js +2 -1
  63. package/lib/solution/RegisterAndLogin/config.d.ts +9 -3
  64. package/lib/solution/RegisterAndLogin/config.js +49 -8
  65. package/lib/solution/RegisterAndLogin/index.js +4 -1
  66. package/lib/solution/ScanOrder/index.d.ts +1 -0
  67. package/lib/solution/ScanOrder/index.js +5 -1
  68. package/lib/solution/ScanOrder/utils.d.ts +1 -0
  69. package/lib/solution/ScanOrder/utils.js +1 -0
  70. package/lib/solution/UnifiedBookingSales/index.d.ts +15 -2
  71. package/lib/solution/UnifiedBookingSales/index.js +140 -6
  72. package/lib/solution/UnifiedBookingSales/types.d.ts +14 -1
  73. package/lib/solution/VenueBooking/index.d.ts +1 -0
  74. package/lib/solution/VenueBooking/index.js +5 -1
  75. package/package.json +1 -1
@@ -0,0 +1,31 @@
1
+ import type { SalesNote, SalesNoteProtocol, SalesNoteTextInput } from './types';
2
+ export interface SalesNotePolicy {
3
+ note_type: string;
4
+ importance: string;
5
+ uniquePerPrimaryTarget: boolean;
6
+ primary_relation_type: 'about';
7
+ secondary_order_relation_type: 'related_to';
8
+ }
9
+ export declare function getSalesNotePolicy(note_type: string): SalesNotePolicy | null;
10
+ export declare function buildSalesNoteText(input: SalesNoteTextInput): Record<string, string>;
11
+ export interface SalesNoteValidationOptions {
12
+ allowUnresolvedOrderTarget?: boolean;
13
+ expectedOrderTargetUuid?: string;
14
+ productTargetUuids?: ReadonlySet<string>;
15
+ }
16
+ export type EncodeSalesNotesOptions = SalesNoteValidationOptions;
17
+ export declare function encodeSalesNotes(notes: SalesNote[], options?: EncodeSalesNotesOptions): SalesNoteProtocol[];
18
+ export interface DecodedSalesNotesSnapshot {
19
+ notes: SalesNote[];
20
+ complete: boolean;
21
+ }
22
+ export interface DecodeSalesNotesOptions {
23
+ allowUnresolvedOrderTarget?: boolean;
24
+ }
25
+ export declare function decodeSalesNotesSnapshot(value: unknown, options?: DecodeSalesNotesOptions): DecodedSalesNotesSnapshot;
26
+ export declare function decodeSalesNotes(value: unknown, options?: DecodeSalesNotesOptions): SalesNote[];
27
+ export declare function finalizeSalesNotesForCheckout(params: {
28
+ notes: unknown;
29
+ shopOrderNumber: unknown;
30
+ productTargetUuids: string[];
31
+ }): SalesNoteProtocol[];
@@ -0,0 +1,492 @@
1
+ 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; }
2
+ 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; }
3
+ 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; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
+ 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); }
6
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
7
+ 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."); }
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 _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; } } }; }
11
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
+ 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); }
14
+ 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; }
15
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
+ 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); }
18
+ var MAX_UUID_LENGTH = 255;
19
+ var LOCALIZED_NOTE_LOCALES = ['en', 'zh-CN', 'zh-HK', 'ja', 'pt'];
20
+ var UUID_V4_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
21
+ /**
22
+ * 备注业务规则统一注册在 OS;调用方只传 note_type、目标行和原始文本。
23
+ * 后续新增备注类型时在这里增加 policy,不把 importance / Relation 规则下放给 UI。
24
+ */
25
+ var SALES_NOTE_POLICIES = {
26
+ allergy: {
27
+ note_type: 'allergy',
28
+ importance: 'high',
29
+ uniquePerPrimaryTarget: true,
30
+ primary_relation_type: 'about',
31
+ secondary_order_relation_type: 'related_to'
32
+ }
33
+ };
34
+ export function getSalesNotePolicy(note_type) {
35
+ return SALES_NOTE_POLICIES[note_type] || null;
36
+ }
37
+ function normalizeUuid(value, field, options) {
38
+ var uuid = String(value !== null && value !== void 0 ? value : '').trim();
39
+ if (!uuid && !(options !== null && options !== void 0 && options.allowEmpty)) {
40
+ throw new Error("[Order Notes] ".concat(field, " \u4E0D\u80FD\u4E3A\u7A7A"));
41
+ }
42
+ if (uuid.length > MAX_UUID_LENGTH) {
43
+ throw new Error("[Order Notes] ".concat(field, " \u4E0D\u80FD\u8D85\u8FC7 ").concat(MAX_UUID_LENGTH, " \u4E2A\u5B57\u7B26"));
44
+ }
45
+ return uuid;
46
+ }
47
+ function normalizeEntityUuid(value, field) {
48
+ var uuid = normalizeUuid(value, field);
49
+ if (!UUID_V4_PATTERN.test(uuid)) {
50
+ throw new Error("[Order Notes] ".concat(field, " \u5FC5\u987B\u4E3A UUID v4"));
51
+ }
52
+ return uuid;
53
+ }
54
+ function normalizeTextRecord(value) {
55
+ if (!value || _typeof(value) !== 'object' || Array.isArray(value)) return {};
56
+ return Object.entries(value).reduce(function (result, _ref) {
57
+ var _ref2 = _slicedToArray(_ref, 2),
58
+ locale = _ref2[0],
59
+ text = _ref2[1];
60
+ if (typeof text === 'string') result[locale] = text;
61
+ return result;
62
+ }, {});
63
+ }
64
+ function normalizeLocalizedLabel(label) {
65
+ if (typeof label === 'string') {
66
+ var text = label.trim();
67
+ return text ? {
68
+ default: text
69
+ } : {};
70
+ }
71
+ return Object.entries(label || {}).reduce(function (result, _ref3) {
72
+ var _ref4 = _slicedToArray(_ref3, 2),
73
+ locale = _ref4[0],
74
+ value = _ref4[1];
75
+ var text = String(value !== null && value !== void 0 ? value : '').trim();
76
+ if (text) result[locale] = text;
77
+ return result;
78
+ }, {});
79
+ }
80
+ function getLocaleCandidates(locale) {
81
+ var raw = String(locale || '').trim();
82
+ var normalized = raw.replace(/_/g, '-');
83
+ var base = normalized.split('-')[0];
84
+ return Array.from(new Set([raw, normalized, base].filter(Boolean)));
85
+ }
86
+ function normalizeLocaleLookupKey(locale) {
87
+ return String(locale || '').trim().replace(/_/g, '-').toLowerCase();
88
+ }
89
+ function resolveLocalizedLabel(label, locale) {
90
+ var _entries$find, _entries$;
91
+ if (typeof label === 'string') return label.trim();
92
+ var normalized = normalizeLocalizedLabel(label);
93
+ var entries = Object.entries(normalized);
94
+ var lowerCaseLookup = new Map(entries.map(function (_ref5) {
95
+ var _ref6 = _slicedToArray(_ref5, 2),
96
+ key = _ref6[0],
97
+ value = _ref6[1];
98
+ return [normalizeLocaleLookupKey(key), value];
99
+ }));
100
+ var _iterator = _createForOfIteratorHelper(getLocaleCandidates(locale)),
101
+ _step;
102
+ try {
103
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
104
+ var candidate = _step.value;
105
+ var matched = lowerCaseLookup.get(normalizeLocaleLookupKey(candidate));
106
+ if (matched) return matched;
107
+ }
108
+ } catch (err) {
109
+ _iterator.e(err);
110
+ } finally {
111
+ _iterator.f();
112
+ }
113
+ var localeBase = normalizeLocaleLookupKey(locale).split('-')[0];
114
+ var sameLanguage = (_entries$find = entries.find(function (_ref7) {
115
+ var _ref8 = _slicedToArray(_ref7, 1),
116
+ key = _ref8[0];
117
+ return normalizeLocaleLookupKey(key).split('-')[0] === localeBase;
118
+ })) === null || _entries$find === void 0 ? void 0 : _entries$find[1];
119
+ return sameLanguage || lowerCaseLookup.get('en') || lowerCaseLookup.get('zh-cn') || lowerCaseLookup.get('default') || ((_entries$ = entries[0]) === null || _entries$ === void 0 ? void 0 : _entries$[1]) || '';
120
+ }
121
+ function joinNoteParts(parts) {
122
+ return parts.map(function (part) {
123
+ return String(part !== null && part !== void 0 ? part : '');
124
+ }).filter(function (part) {
125
+ return part.trim().length > 0;
126
+ }).join(',');
127
+ }
128
+ export function buildSalesNoteText(input) {
129
+ var _input$input2;
130
+ if (input.kind === 'plain') {
131
+ var _input$input;
132
+ var text = String((_input$input = input.input) !== null && _input$input !== void 0 ? _input$input : '');
133
+ if (!text.trim()) throw new Error('[Order Notes] 备注输入不能为空');
134
+ return {
135
+ 'zh-CN': '',
136
+ original: text
137
+ };
138
+ }
139
+ if (input.kind === 'resolved') {
140
+ var _text = normalizeTextRecord(input.text);
141
+ if (!Object.values(_text).some(function (value) {
142
+ return value.trim();
143
+ })) {
144
+ throw new Error('[Order Notes] 备注文本不能为空');
145
+ }
146
+ return _text;
147
+ }
148
+ var inputText = String((_input$input2 = input.input) !== null && _input$input2 !== void 0 ? _input$input2 : '');
149
+ var seenIds = new Set();
150
+ var selections = (input.selections || []).filter(function (selection) {
151
+ var _selection$id;
152
+ var id = String((_selection$id = selection === null || selection === void 0 ? void 0 : selection.id) !== null && _selection$id !== void 0 ? _selection$id : '').trim();
153
+ if (!id || seenIds.has(id)) return false;
154
+ seenIds.add(id);
155
+ return true;
156
+ });
157
+ if (!selections.length && !inputText.trim()) {
158
+ throw new Error('[Order Notes] 过敏选项和补充说明不能同时为空');
159
+ }
160
+ var result = {};
161
+ var _iterator2 = _createForOfIteratorHelper(LOCALIZED_NOTE_LOCALES),
162
+ _step2;
163
+ try {
164
+ var _loop = function _loop() {
165
+ var locale = _step2.value;
166
+ result[locale] = joinNoteParts([].concat(_toConsumableArray(selections.map(function (selection) {
167
+ return resolveLocalizedLabel(selection.label, locale);
168
+ })), [inputText]));
169
+ };
170
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
171
+ _loop();
172
+ }
173
+ } catch (err) {
174
+ _iterator2.e(err);
175
+ } finally {
176
+ _iterator2.f();
177
+ }
178
+ result.original = joinNoteParts([].concat(_toConsumableArray(selections.map(function (selection) {
179
+ return resolveLocalizedLabel(selection.label, input.locale);
180
+ })), [inputText]));
181
+ return result;
182
+ }
183
+ function validateSalesNote(note) {
184
+ var _note$content;
185
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
186
+ normalizeEntityUuid(note.uuid, 'Note uuid');
187
+ var note_type = String(note.note_type || '').trim();
188
+ var policy = getSalesNotePolicy(note_type);
189
+ if (!policy) {
190
+ throw new Error("[Order Notes] \u5F53\u524D\u672A\u6CE8\u518C\u5907\u6CE8\u7C7B\u578B: ".concat(note_type || '(empty)'));
191
+ }
192
+ if (note.importance !== policy.importance) {
193
+ throw new Error("[Order Notes] ".concat(note_type, " importance \u5FC5\u987B\u4E3A ").concat(policy.importance));
194
+ }
195
+ var text = (_note$content = note.content) === null || _note$content === void 0 ? void 0 : _note$content.text;
196
+ if (!text || _typeof(text) !== 'object' || Array.isArray(text) || Object.values(text).some(function (value) {
197
+ return typeof value !== 'string';
198
+ }) || !Object.values(text).some(function (value) {
199
+ return value.trim();
200
+ })) {
201
+ throw new Error('[Order Notes] content.text 不能为空');
202
+ }
203
+ if (!Array.isArray(note.note_relations) || note.note_relations.length === 0) {
204
+ throw new Error('[Order Notes] note_relations 不能为空');
205
+ }
206
+ var relationUuids = new Set();
207
+ var primaryCount = 0;
208
+ var orderRelationCount = 0;
209
+ var _iterator3 = _createForOfIteratorHelper(note.note_relations),
210
+ _step3;
211
+ try {
212
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
213
+ var relation = _step3.value;
214
+ var relationUuid = normalizeEntityUuid(relation.uuid, 'Relation uuid');
215
+ if (relationUuids.has(relationUuid)) {
216
+ throw new Error('[Order Notes] 同一 Note 内 Relation uuid 不能重复');
217
+ }
218
+ relationUuids.add(relationUuid);
219
+ if (relation.is_primary !== 0 && relation.is_primary !== 1) {
220
+ throw new Error('[Order Notes] is_primary 只允许整数 0 或 1');
221
+ }
222
+ if (relation.relation_type !== 'about' && relation.relation_type !== 'related_to') {
223
+ throw new Error('[Order Notes] relation_type 不合法');
224
+ }
225
+ if (relation.target_type !== 'order' && relation.target_type !== 'order_detail') {
226
+ throw new Error('[Order Notes] target_type 不合法');
227
+ }
228
+ if (relation.is_primary === 1) {
229
+ primaryCount += 1;
230
+ if (relation.relation_type !== policy.primary_relation_type || relation.target_type !== 'order_detail') {
231
+ throw new Error('[Order Notes] 主关系必须使用 about + order_detail');
232
+ }
233
+ var targetUuid = normalizeUuid(relation.target_uuid, 'Relation target_uuid');
234
+ if (options.productTargetUuids && !options.productTargetUuids.has(targetUuid)) {
235
+ throw new Error('[Order Notes] 商品 Relation target_uuid 不属于当前订单');
236
+ }
237
+ continue;
238
+ }
239
+ if (relation.target_type === 'order' && relation.relation_type === policy.secondary_order_relation_type) {
240
+ orderRelationCount += 1;
241
+ var _targetUuid = normalizeUuid(relation.target_uuid, 'Relation target_uuid', {
242
+ allowEmpty: options.allowUnresolvedOrderTarget === true
243
+ });
244
+ if (options.expectedOrderTargetUuid !== undefined && _targetUuid !== options.expectedOrderTargetUuid) {
245
+ throw new Error('[Order Notes] 订单 Relation target_uuid 与 shop_order_number 不一致');
246
+ }
247
+ continue;
248
+ }
249
+ throw new Error('[Order Notes] 非主体关系必须使用 related_to + order');
250
+ }
251
+ } catch (err) {
252
+ _iterator3.e(err);
253
+ } finally {
254
+ _iterator3.f();
255
+ }
256
+ if (primaryCount !== 1) {
257
+ throw new Error('[Order Notes] 每条 Note 必须且只能有一个主关系');
258
+ }
259
+ if (orderRelationCount !== 1) {
260
+ throw new Error('[Order Notes] 每条商品 Note 必须且只能有一个订单冗余关系');
261
+ }
262
+ }
263
+ export function encodeSalesNotes(notes) {
264
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
265
+ var entityUuids = new Set();
266
+ var uniquePolicyTargets = new Set();
267
+ return (notes || []).map(function (note) {
268
+ var _note$content2;
269
+ validateSalesNote(note, options);
270
+ var noteUuid = normalizeEntityUuid(note.uuid, 'Note uuid');
271
+ if (entityUuids.has(noteUuid)) {
272
+ throw new Error('[Order Notes] Note/Relation uuid 不能重复');
273
+ }
274
+ entityUuids.add(noteUuid);
275
+ var note_type = String(note.note_type).trim();
276
+ var noteRelations = note.note_relations.map(function (relation) {
277
+ var relationUuid = normalizeEntityUuid(relation.uuid, 'Relation uuid');
278
+ if (entityUuids.has(relationUuid)) {
279
+ throw new Error('[Order Notes] Note/Relation uuid 不能重复');
280
+ }
281
+ entityUuids.add(relationUuid);
282
+ var allowEmptyTarget = options.allowUnresolvedOrderTarget === true && relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order';
283
+ return {
284
+ uuid: relationUuid,
285
+ relation_type: relation.relation_type,
286
+ target_type: relation.target_type,
287
+ target_uuid: normalizeUuid(relation.target_uuid, 'Relation target_uuid', {
288
+ allowEmpty: allowEmptyTarget
289
+ }),
290
+ is_primary: relation.is_primary
291
+ };
292
+ });
293
+ var primaryRelation = noteRelations.find(function (relation) {
294
+ return relation.is_primary === 1;
295
+ });
296
+ var policy = getSalesNotePolicy(note_type);
297
+ if (policy.uniquePerPrimaryTarget) {
298
+ var policyTargetKey = [note_type, primaryRelation.target_type, primaryRelation.target_uuid].join(':');
299
+ if (uniquePolicyTargets.has(policyTargetKey)) {
300
+ throw new Error('[Order Notes] 同一商品行不能重复提交同类型 Note');
301
+ }
302
+ uniquePolicyTargets.add(policyTargetKey);
303
+ }
304
+ return {
305
+ uuid: noteUuid,
306
+ note_type: note_type,
307
+ content: {
308
+ text: _objectSpread({}, ((_note$content2 = note.content) === null || _note$content2 === void 0 ? void 0 : _note$content2.text) || {})
309
+ },
310
+ importance: note.importance,
311
+ note_relations: noteRelations
312
+ };
313
+ });
314
+ }
315
+ function decodeRelation(value) {
316
+ var _raw$uuid, _raw$target_uuid;
317
+ if (!value || _typeof(value) !== 'object' || Array.isArray(value)) return null;
318
+ var raw = value;
319
+ var uuid = String((_raw$uuid = raw.uuid) !== null && _raw$uuid !== void 0 ? _raw$uuid : '').trim();
320
+ var target_uuid = String((_raw$target_uuid = raw.target_uuid) !== null && _raw$target_uuid !== void 0 ? _raw$target_uuid : '').trim();
321
+ var relation_type = raw.relation_type;
322
+ var target_type = raw.target_type;
323
+ var is_primary = raw.is_primary;
324
+ if (!uuid || relation_type !== 'about' && relation_type !== 'related_to' || target_type !== 'order' && target_type !== 'order_detail' || is_primary !== 0 && is_primary !== 1) {
325
+ return null;
326
+ }
327
+ return {
328
+ uuid: uuid,
329
+ relation_type: relation_type,
330
+ target_type: target_type,
331
+ target_uuid: target_uuid,
332
+ is_primary: is_primary
333
+ };
334
+ }
335
+ export function decodeSalesNotesSnapshot(value) {
336
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
337
+ if (!Array.isArray(value)) return {
338
+ notes: [],
339
+ complete: false
340
+ };
341
+ var notes = [];
342
+ var entityUuids = new Set();
343
+ var uniquePolicyTargets = new Set();
344
+ var complete = true;
345
+ var _iterator4 = _createForOfIteratorHelper(value),
346
+ _step4;
347
+ try {
348
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
349
+ var _raw$uuid2, _raw$note_type, _raw$importance, _raw$content;
350
+ var item = _step4.value;
351
+ if (!item || _typeof(item) !== 'object' || Array.isArray(item)) {
352
+ complete = false;
353
+ continue;
354
+ }
355
+ var raw = item;
356
+ var uuid = String((_raw$uuid2 = raw.uuid) !== null && _raw$uuid2 !== void 0 ? _raw$uuid2 : '').trim();
357
+ var note_type = String((_raw$note_type = raw.note_type) !== null && _raw$note_type !== void 0 ? _raw$note_type : '').trim();
358
+ var importance = String((_raw$importance = raw.importance) !== null && _raw$importance !== void 0 ? _raw$importance : '').trim();
359
+ var rawText = (_raw$content = raw.content) === null || _raw$content === void 0 ? void 0 : _raw$content.text;
360
+ var text = normalizeTextRecord(rawText);
361
+ if (!rawText || _typeof(rawText) !== 'object' || Array.isArray(rawText) || Object.keys(text).length !== Object.keys(rawText).length) {
362
+ complete = false;
363
+ continue;
364
+ }
365
+ var rawNoteRelations = Array.isArray(raw.note_relations) ? raw.note_relations : null;
366
+ var noteRelations = rawNoteRelations ? rawNoteRelations.map(function (relation) {
367
+ return decodeRelation(relation);
368
+ }).filter(function (relation) {
369
+ return relation !== null;
370
+ }) : [];
371
+ if (!rawNoteRelations || noteRelations.length !== rawNoteRelations.length) {
372
+ complete = false;
373
+ continue;
374
+ }
375
+ var note = {
376
+ uuid: uuid,
377
+ note_type: note_type,
378
+ content: {
379
+ text: text
380
+ },
381
+ importance: importance,
382
+ note_relations: noteRelations
383
+ };
384
+ try {
385
+ validateSalesNote(note, {
386
+ allowUnresolvedOrderTarget: options.allowUnresolvedOrderTarget
387
+ });
388
+ if (entityUuids.has(note.uuid)) {
389
+ complete = false;
390
+ continue;
391
+ }
392
+ entityUuids.add(note.uuid);
393
+ var hasDuplicateRelationUuid = false;
394
+ var _iterator5 = _createForOfIteratorHelper(note.note_relations),
395
+ _step5;
396
+ try {
397
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
398
+ var relation = _step5.value;
399
+ if (entityUuids.has(relation.uuid)) {
400
+ hasDuplicateRelationUuid = true;
401
+ break;
402
+ }
403
+ }
404
+ } catch (err) {
405
+ _iterator5.e(err);
406
+ } finally {
407
+ _iterator5.f();
408
+ }
409
+ if (hasDuplicateRelationUuid) {
410
+ complete = false;
411
+ continue;
412
+ }
413
+ note.note_relations.forEach(function (relation) {
414
+ return entityUuids.add(relation.uuid);
415
+ });
416
+ var policy = getSalesNotePolicy(note.note_type);
417
+ var primaryRelation = note.note_relations.find(function (relation) {
418
+ return relation.is_primary === 1;
419
+ });
420
+ if (policy !== null && policy !== void 0 && policy.uniquePerPrimaryTarget && primaryRelation) {
421
+ var policyTargetKey = [note.note_type, primaryRelation.target_type, primaryRelation.target_uuid].join(':');
422
+ if (uniquePolicyTargets.has(policyTargetKey)) {
423
+ complete = false;
424
+ continue;
425
+ }
426
+ uniquePolicyTargets.add(policyTargetKey);
427
+ }
428
+ notes.push(note);
429
+ } catch (_unused) {
430
+ complete = false;
431
+ }
432
+ }
433
+ } catch (err) {
434
+ _iterator4.e(err);
435
+ } finally {
436
+ _iterator4.f();
437
+ }
438
+ return {
439
+ notes: notes,
440
+ complete: complete
441
+ };
442
+ }
443
+ export function decodeSalesNotes(value) {
444
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
445
+ return decodeSalesNotesSnapshot(value, options).notes;
446
+ }
447
+ export function finalizeSalesNotesForCheckout(params) {
448
+ if (!Array.isArray(params.notes)) {
449
+ throw new Error('[Order Notes] checkout notes 必须为数组');
450
+ }
451
+ if (params.notes.length === 0) return [];
452
+ var shopOrderNumber = normalizeUuid(params.shopOrderNumber, 'shop_order_number');
453
+ var productTargetUuids = new Set();
454
+ var _iterator6 = _createForOfIteratorHelper(params.productTargetUuids || []),
455
+ _step6;
456
+ try {
457
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
458
+ var rawTargetUuid = _step6.value;
459
+ var targetUuid = normalizeUuid(rawTargetUuid, '商品 target_uuid');
460
+ if (productTargetUuids.has(targetUuid)) {
461
+ throw new Error('[Order Notes] 商品行业务标识不能重复');
462
+ }
463
+ productTargetUuids.add(targetUuid);
464
+ }
465
+ } catch (err) {
466
+ _iterator6.e(err);
467
+ } finally {
468
+ _iterator6.f();
469
+ }
470
+ var decoded = decodeSalesNotesSnapshot(params.notes, {
471
+ allowUnresolvedOrderTarget: true
472
+ });
473
+ if (!decoded.complete || decoded.notes.length !== params.notes.length) {
474
+ throw new Error('[Order Notes] checkout Notes 快照不完整');
475
+ }
476
+ var finalizedNotes = decoded.notes.map(function (note) {
477
+ return _objectSpread(_objectSpread({}, note), {}, {
478
+ content: {
479
+ text: _objectSpread({}, note.content.text)
480
+ },
481
+ note_relations: note.note_relations.map(function (relation) {
482
+ return _objectSpread(_objectSpread({}, relation), relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order' ? {
483
+ target_uuid: shopOrderNumber
484
+ } : {});
485
+ })
486
+ });
487
+ });
488
+ return encodeSalesNotes(finalizedNotes, {
489
+ expectedOrderTargetUuid: shopOrderNumber,
490
+ productTargetUuids: productTargetUuids
491
+ });
492
+ }
@@ -8,6 +8,13 @@ import type { PaymentItem } from '../Payment/types';
8
8
  import type { ICustomer } from '../AccountList/types';
9
9
  import type { OrderProductDiscountItem } from '../../server/modules/order/types';
10
10
  export type { OrderProductDiscountItem } from '../../server/modules/order/types';
11
+ export type PickupReferenceMode = 'counter_pickup' | 'table_service';
12
+ export type ShopServiceType = 'dine_in' | 'takeaway';
13
+ export interface ShopServiceData {
14
+ pickup_reference_mode?: PickupReferenceMode;
15
+ service_type?: ShopServiceType | '';
16
+ [key: string]: any;
17
+ }
11
18
  export declare enum OrderHooks {
12
19
  OnOrderCreate = "order:onOrderCreate",
13
20
  OnOrderUpdate = "order:onOrderUpdate",
@@ -238,6 +245,72 @@ export interface OrderSummary {
238
245
  tax_title?: string;
239
246
  tax_rate?: number;
240
247
  }
248
+ export type SalesNoteRelationType = 'about' | 'related_to';
249
+ export type SalesNoteTargetType = 'order' | 'order_detail';
250
+ export type SalesNoteLocalizedText = string | Record<string, string>;
251
+ export interface SalesNoteLocalizedSelection {
252
+ id: string;
253
+ label: SalesNoteLocalizedText;
254
+ }
255
+ export type SalesNoteTextInput = {
256
+ kind: 'localizedSelections';
257
+ selections: SalesNoteLocalizedSelection[];
258
+ locale: string;
259
+ input?: string;
260
+ } | {
261
+ kind: 'plain';
262
+ input: string;
263
+ } | {
264
+ kind: 'resolved';
265
+ text: Record<string, string>;
266
+ };
267
+ export interface SalesNoteRelation {
268
+ uuid: string;
269
+ relation_type: SalesNoteRelationType;
270
+ target_type: SalesNoteTargetType;
271
+ target_uuid: string;
272
+ is_primary: 0 | 1;
273
+ }
274
+ export interface SalesNote {
275
+ uuid: string;
276
+ note_type: string;
277
+ content: {
278
+ text: Record<string, string>;
279
+ };
280
+ importance: string;
281
+ note_relations: SalesNoteRelation[];
282
+ }
283
+ export interface SalesNoteTarget {
284
+ target_type: 'order_detail';
285
+ target_uuid: string;
286
+ }
287
+ export interface SetSalesNoteInput {
288
+ note_type: string;
289
+ target: SalesNoteTarget;
290
+ text: SalesNoteTextInput;
291
+ }
292
+ export interface SalesNoteDraftInput {
293
+ note_type: string;
294
+ text: SalesNoteTextInput;
295
+ }
296
+ export interface SalesNotesRuntimeState {
297
+ loaded: boolean;
298
+ dirty: boolean;
299
+ }
300
+ /**
301
+ * Sales Notes 乐观写入前的可恢复快照。
302
+ * 该对象应视为 opaque token,只用于原样传回 restoreSalesNotesMutationSnapshot。
303
+ */
304
+ export interface SalesNotesMutationSnapshot {
305
+ orderIdentity: {
306
+ orderId: number | string | null;
307
+ externalSaleNumber: string;
308
+ };
309
+ notes: SalesNote[];
310
+ state: SalesNotesRuntimeState;
311
+ }
312
+ export type SalesNoteProtocolRelation = SalesNoteRelation;
313
+ export type SalesNoteProtocol = SalesNote;
241
314
  export interface OrderTempOrder {
242
315
  order_id: number | null;
243
316
  external_sale_number: string;
@@ -277,6 +350,7 @@ export interface OrderTempOrder {
277
350
  created_at: string | undefined;
278
351
  request_unique_idempotency_token?: string;
279
352
  products: OrderProduct[];
353
+ notes: SalesNote[];
280
354
  bookings: any[];
281
355
  payments: any[];
282
356
  surcharges: any[];
@@ -289,6 +363,7 @@ export interface OrderTempOrder {
289
363
  summary?: OrderSummary;
290
364
  _extend?: {
291
365
  productsByUid?: Record<string, Record<string, any>>;
366
+ salesNotesState?: SalesNotesRuntimeState;
292
367
  [key: string]: any;
293
368
  };
294
369
  }
@@ -297,7 +372,7 @@ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identific
297
372
  payment_price: string;
298
373
  product_sku: OrderProductSku;
299
374
  }
300
- export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
375
+ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | 'notes' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
301
376
  platform: string;
302
377
  created_at?: string | undefined;
303
378
  request_unique_idempotency_token?: string;
@@ -306,6 +381,7 @@ export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'p
306
381
  form_record_id: number | string;
307
382
  }>;
308
383
  products: OrderSubmitProduct[];
384
+ notes?: SalesNoteProtocol[];
309
385
  summary?: OrderSummary;
310
386
  small_ticket_data_flag?: number;
311
387
  }
@@ -334,6 +410,8 @@ export interface AddProductToOrderOptions {
334
410
  insertAfterProductUid?: string;
335
411
  /** 跳过同商品/规格匹配,始终新增购物车行。 */
336
412
  disableMerge?: boolean;
413
+ /** 商品行 UID 落定后,由 OrderModule 原子绑定到该行的 Sales Notes 草稿。 */
414
+ salesNotes?: SalesNoteDraftInput[];
337
415
  }
338
416
  /**
339
417
  * 删除商品后的可选位置保持策略。
@@ -749,9 +827,17 @@ export interface OrderModuleAPI {
749
827
  updateTempOrderShopDiscount: (amount: string | number) => string;
750
828
  updateTempOrderDepositAmount: (amount: string | number) => OrderSummary;
751
829
  updateTempOrderCustomer: (customer: UpdateTempOrderCustomerInput) => OrderSnapshot['customer'];
830
+ updateTempOrderPickupReferenceMode: (mode: PickupReferenceMode) => ShopServiceData;
831
+ updateTempOrderServiceType: (serviceType: ShopServiceType) => ShopServiceData;
752
832
  updateTempOrderBuzzer: (buzzer: string) => string;
753
833
  updateTempOrderContactsInfo: (contactsInfo: Record<string, any> | null) => Record<string, any> | null;
754
834
  addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions) => Promise<OrderProduct[]>;
835
+ getSalesNotes: () => SalesNote[];
836
+ createSalesNotesMutationSnapshot: () => SalesNotesMutationSnapshot;
837
+ restoreSalesNotesMutationSnapshot: (snapshot: SalesNotesMutationSnapshot) => void;
838
+ setSalesNote: (input: SetSalesNoteInput) => Promise<SalesNote>;
839
+ removeSalesNote: (uuid: string) => Promise<void>;
840
+ clearSalesNotes: () => Promise<void>;
755
841
  updateOrderProduct: (params: UpdateOrderProductParams) => Promise<OrderProduct[]>;
756
842
  /** 批量更新购物车行,末尾仅触发一次促销重算与 summary 刷新 */
757
843
  updateOrderProducts: (paramsList: UpdateOrderProductParams[]) => Promise<OrderProduct[]>;
@@ -899,10 +985,10 @@ export interface OrderModuleAPI {
899
985
  /** 读取上次 applyPromotion 产出的赠品操作 diff(toAdd / toReduce / toRemove) */
900
986
  getLastGiftActions: () => OrderLastGiftActions | null;
901
987
  /**
902
- * 取消订单
903
- * @param params 取消订单参数
904
- * @returns 后端返回结果
905
- */
988
+ * 取消订单
989
+ * @param params 取消订单参数
990
+ * @returns 后端返回结果
991
+ */
906
992
  cancelOrder: (params: CancelOrderParams) => Promise<any>;
907
993
  /**
908
994
  * 变更预约状态