@pisell/pisellos 2.2.294 → 2.2.295

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 (69) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +1 -4
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +35 -135
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +1 -8
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +1 -25
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +0 -44
  6. package/dist/model/strategy/adapter/itemRule/type.js +1 -19
  7. package/dist/modules/Order/index.d.ts +3 -18
  8. package/dist/modules/Order/index.js +485 -885
  9. package/dist/modules/Order/types.d.ts +5 -91
  10. package/dist/modules/Order/types.js +0 -5
  11. package/dist/modules/Order/utils.js +10 -22
  12. package/dist/modules/ProductList/index.d.ts +1 -2
  13. package/dist/modules/ProductList/index.js +20 -100
  14. package/dist/modules/ProductList/types.d.ts +0 -10
  15. package/dist/server/index.d.ts +0 -6
  16. package/dist/server/index.js +3 -43
  17. package/dist/solution/BaseSales/index.d.ts +1 -9
  18. package/dist/solution/BaseSales/index.js +706 -894
  19. package/dist/solution/BookingByStep/index.d.ts +2 -2
  20. package/dist/solution/BookingTicket/utils/orderCustomer.js +2 -3
  21. package/dist/solution/RegisterAndLogin/config.d.ts +3 -9
  22. package/dist/solution/RegisterAndLogin/config.js +40 -95
  23. package/dist/solution/RegisterAndLogin/index.js +1 -4
  24. package/dist/solution/ScanOrder/index.d.ts +0 -1
  25. package/dist/solution/ScanOrder/index.js +27 -31
  26. package/dist/solution/ScanOrder/utils.d.ts +0 -1
  27. package/dist/solution/ScanOrder/utils.js +0 -2
  28. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -15
  29. package/dist/solution/UnifiedBookingSales/index.js +484 -752
  30. package/dist/solution/UnifiedBookingSales/types.d.ts +1 -14
  31. package/dist/solution/VenueBooking/index.d.ts +0 -1
  32. package/dist/solution/VenueBooking/index.js +4 -8
  33. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +1 -4
  34. package/lib/model/strategy/adapter/itemRule/adapter.js +4 -73
  35. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +1 -8
  36. package/lib/model/strategy/adapter/itemRule/evaluator.js +1 -23
  37. package/lib/model/strategy/adapter/itemRule/type.d.ts +0 -44
  38. package/lib/model/strategy/adapter/itemRule/type.js +1 -19
  39. package/lib/modules/Order/index.d.ts +3 -18
  40. package/lib/modules/Order/index.js +28 -325
  41. package/lib/modules/Order/types.d.ts +5 -91
  42. package/lib/modules/Order/types.js +0 -4
  43. package/lib/modules/Order/utils.js +1 -13
  44. package/lib/modules/ProductList/index.d.ts +1 -2
  45. package/lib/modules/ProductList/index.js +2 -47
  46. package/lib/modules/ProductList/types.d.ts +0 -10
  47. package/lib/server/index.d.ts +0 -6
  48. package/lib/server/index.js +3 -37
  49. package/lib/solution/BaseSales/index.d.ts +1 -9
  50. package/lib/solution/BaseSales/index.js +1 -105
  51. package/lib/solution/BookingByStep/index.d.ts +2 -2
  52. package/lib/solution/BookingTicket/utils/orderCustomer.js +1 -2
  53. package/lib/solution/RegisterAndLogin/config.d.ts +3 -9
  54. package/lib/solution/RegisterAndLogin/config.js +8 -49
  55. package/lib/solution/RegisterAndLogin/index.js +1 -4
  56. package/lib/solution/ScanOrder/index.d.ts +0 -1
  57. package/lib/solution/ScanOrder/index.js +1 -5
  58. package/lib/solution/ScanOrder/utils.d.ts +0 -1
  59. package/lib/solution/ScanOrder/utils.js +0 -1
  60. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -15
  61. package/lib/solution/UnifiedBookingSales/index.js +1 -125
  62. package/lib/solution/UnifiedBookingSales/types.d.ts +1 -14
  63. package/lib/solution/VenueBooking/index.d.ts +0 -1
  64. package/lib/solution/VenueBooking/index.js +1 -5
  65. package/package.json +1 -1
  66. package/dist/modules/Order/salesNotes.d.ts +0 -31
  67. package/dist/modules/Order/salesNotes.js +0 -492
  68. package/lib/modules/Order/salesNotes.d.ts +0 -31
  69. package/lib/modules/Order/salesNotes.js +0 -382
@@ -1,382 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.buildSalesNoteText = buildSalesNoteText;
7
- exports.decodeSalesNotes = decodeSalesNotes;
8
- exports.decodeSalesNotesSnapshot = decodeSalesNotesSnapshot;
9
- exports.encodeSalesNotes = encodeSalesNotes;
10
- exports.finalizeSalesNotesForCheckout = finalizeSalesNotesForCheckout;
11
- exports.getSalesNotePolicy = getSalesNotePolicy;
12
- const MAX_UUID_LENGTH = 255;
13
- const LOCALIZED_NOTE_LOCALES = ['en', 'zh-CN', 'zh-HK', 'ja', 'pt'];
14
- const 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;
15
- /**
16
- * 备注业务规则统一注册在 OS;调用方只传 note_type、目标行和原始文本。
17
- * 后续新增备注类型时在这里增加 policy,不把 importance / Relation 规则下放给 UI。
18
- */
19
- const SALES_NOTE_POLICIES = {
20
- allergy: {
21
- note_type: 'allergy',
22
- importance: 'high',
23
- uniquePerPrimaryTarget: true,
24
- primary_relation_type: 'about',
25
- secondary_order_relation_type: 'related_to'
26
- }
27
- };
28
- function getSalesNotePolicy(note_type) {
29
- return SALES_NOTE_POLICIES[note_type] || null;
30
- }
31
- function normalizeUuid(value, field, options) {
32
- const uuid = String(value ?? '').trim();
33
- if (!uuid && !options?.allowEmpty) {
34
- throw new Error(`[Order Notes] ${field} 不能为空`);
35
- }
36
- if (uuid.length > MAX_UUID_LENGTH) {
37
- throw new Error(`[Order Notes] ${field} 不能超过 ${MAX_UUID_LENGTH} 个字符`);
38
- }
39
- return uuid;
40
- }
41
- function normalizeEntityUuid(value, field) {
42
- const uuid = normalizeUuid(value, field);
43
- if (!UUID_V4_PATTERN.test(uuid)) {
44
- throw new Error(`[Order Notes] ${field} 必须为 UUID v4`);
45
- }
46
- return uuid;
47
- }
48
- function normalizeTextRecord(value) {
49
- if (!value || typeof value !== 'object' || Array.isArray(value)) return {};
50
- return Object.entries(value).reduce((result, [locale, text]) => {
51
- if (typeof text === 'string') result[locale] = text;
52
- return result;
53
- }, {});
54
- }
55
- function normalizeLocalizedLabel(label) {
56
- if (typeof label === 'string') {
57
- const text = label.trim();
58
- return text ? {
59
- default: text
60
- } : {};
61
- }
62
- return Object.entries(label || {}).reduce((result, [locale, value]) => {
63
- const text = String(value ?? '').trim();
64
- if (text) result[locale] = text;
65
- return result;
66
- }, {});
67
- }
68
- function getLocaleCandidates(locale) {
69
- const raw = String(locale || '').trim();
70
- const normalized = raw.replace(/_/g, '-');
71
- const base = normalized.split('-')[0];
72
- return Array.from(new Set([raw, normalized, base].filter(Boolean)));
73
- }
74
- function normalizeLocaleLookupKey(locale) {
75
- return String(locale || '').trim().replace(/_/g, '-').toLowerCase();
76
- }
77
- function resolveLocalizedLabel(label, locale) {
78
- if (typeof label === 'string') return label.trim();
79
- const normalized = normalizeLocalizedLabel(label);
80
- const entries = Object.entries(normalized);
81
- const lowerCaseLookup = new Map(entries.map(([key, value]) => [normalizeLocaleLookupKey(key), value]));
82
- for (const candidate of getLocaleCandidates(locale)) {
83
- const matched = lowerCaseLookup.get(normalizeLocaleLookupKey(candidate));
84
- if (matched) return matched;
85
- }
86
- const localeBase = normalizeLocaleLookupKey(locale).split('-')[0];
87
- const sameLanguage = entries.find(([key]) => normalizeLocaleLookupKey(key).split('-')[0] === localeBase)?.[1];
88
- return sameLanguage || lowerCaseLookup.get('en') || lowerCaseLookup.get('zh-cn') || lowerCaseLookup.get('default') || entries[0]?.[1] || '';
89
- }
90
- function joinNoteParts(parts) {
91
- return parts.map(part => String(part ?? '')).filter(part => part.trim().length > 0).join(',');
92
- }
93
- function buildSalesNoteText(input) {
94
- if (input.kind === 'plain') {
95
- const text = String(input.input ?? '');
96
- if (!text.trim()) throw new Error('[Order Notes] 备注输入不能为空');
97
- return {
98
- 'zh-CN': '',
99
- original: text
100
- };
101
- }
102
- if (input.kind === 'resolved') {
103
- const text = normalizeTextRecord(input.text);
104
- if (!Object.values(text).some(value => value.trim())) {
105
- throw new Error('[Order Notes] 备注文本不能为空');
106
- }
107
- return text;
108
- }
109
- const inputText = String(input.input ?? '');
110
- const seenIds = new Set();
111
- const selections = (input.selections || []).filter(selection => {
112
- const id = String(selection?.id ?? '').trim();
113
- if (!id || seenIds.has(id)) return false;
114
- seenIds.add(id);
115
- return true;
116
- });
117
- if (!selections.length && !inputText.trim()) {
118
- throw new Error('[Order Notes] 过敏选项和补充说明不能同时为空');
119
- }
120
- const result = {};
121
- for (const locale of LOCALIZED_NOTE_LOCALES) {
122
- result[locale] = joinNoteParts([...selections.map(selection => resolveLocalizedLabel(selection.label, locale)), inputText]);
123
- }
124
- result.original = joinNoteParts([...selections.map(selection => resolveLocalizedLabel(selection.label, input.locale)), inputText]);
125
- return result;
126
- }
127
- function validateSalesNote(note, options = {}) {
128
- normalizeEntityUuid(note.uuid, 'Note uuid');
129
- const note_type = String(note.note_type || '').trim();
130
- const policy = getSalesNotePolicy(note_type);
131
- if (!policy) {
132
- throw new Error(`[Order Notes] 当前未注册备注类型: ${note_type || '(empty)'}`);
133
- }
134
- if (note.importance !== policy.importance) {
135
- throw new Error(`[Order Notes] ${note_type} importance 必须为 ${policy.importance}`);
136
- }
137
- const text = note.content?.text;
138
- if (!text || typeof text !== 'object' || Array.isArray(text) || Object.values(text).some(value => typeof value !== 'string') || !Object.values(text).some(value => value.trim())) {
139
- throw new Error('[Order Notes] content.text 不能为空');
140
- }
141
- if (!Array.isArray(note.note_relations) || note.note_relations.length === 0) {
142
- throw new Error('[Order Notes] note_relations 不能为空');
143
- }
144
- const relationUuids = new Set();
145
- let primaryCount = 0;
146
- let orderRelationCount = 0;
147
- for (const relation of note.note_relations) {
148
- const relationUuid = normalizeEntityUuid(relation.uuid, 'Relation uuid');
149
- if (relationUuids.has(relationUuid)) {
150
- throw new Error('[Order Notes] 同一 Note 内 Relation uuid 不能重复');
151
- }
152
- relationUuids.add(relationUuid);
153
- if (relation.is_primary !== 0 && relation.is_primary !== 1) {
154
- throw new Error('[Order Notes] is_primary 只允许整数 0 或 1');
155
- }
156
- if (relation.relation_type !== 'about' && relation.relation_type !== 'related_to') {
157
- throw new Error('[Order Notes] relation_type 不合法');
158
- }
159
- if (relation.target_type !== 'order' && relation.target_type !== 'order_detail') {
160
- throw new Error('[Order Notes] target_type 不合法');
161
- }
162
- if (relation.is_primary === 1) {
163
- primaryCount += 1;
164
- if (relation.relation_type !== policy.primary_relation_type || relation.target_type !== 'order_detail') {
165
- throw new Error('[Order Notes] 主关系必须使用 about + order_detail');
166
- }
167
- const targetUuid = normalizeUuid(relation.target_uuid, 'Relation target_uuid');
168
- if (options.productTargetUuids && !options.productTargetUuids.has(targetUuid)) {
169
- throw new Error('[Order Notes] 商品 Relation target_uuid 不属于当前订单');
170
- }
171
- continue;
172
- }
173
- if (relation.target_type === 'order' && relation.relation_type === policy.secondary_order_relation_type) {
174
- orderRelationCount += 1;
175
- const targetUuid = normalizeUuid(relation.target_uuid, 'Relation target_uuid', {
176
- allowEmpty: options.allowUnresolvedOrderTarget === true
177
- });
178
- if (options.expectedOrderTargetUuid !== undefined && targetUuid !== options.expectedOrderTargetUuid) {
179
- throw new Error('[Order Notes] 订单 Relation target_uuid 与 shop_order_number 不一致');
180
- }
181
- continue;
182
- }
183
- throw new Error('[Order Notes] 非主体关系必须使用 related_to + order');
184
- }
185
- if (primaryCount !== 1) {
186
- throw new Error('[Order Notes] 每条 Note 必须且只能有一个主关系');
187
- }
188
- if (orderRelationCount !== 1) {
189
- throw new Error('[Order Notes] 每条商品 Note 必须且只能有一个订单冗余关系');
190
- }
191
- }
192
- function encodeSalesNotes(notes, options = {}) {
193
- const entityUuids = new Set();
194
- const uniquePolicyTargets = new Set();
195
- return (notes || []).map(note => {
196
- validateSalesNote(note, options);
197
- const noteUuid = normalizeEntityUuid(note.uuid, 'Note uuid');
198
- if (entityUuids.has(noteUuid)) {
199
- throw new Error('[Order Notes] Note/Relation uuid 不能重复');
200
- }
201
- entityUuids.add(noteUuid);
202
- const note_type = String(note.note_type).trim();
203
- const noteRelations = note.note_relations.map(relation => {
204
- const relationUuid = normalizeEntityUuid(relation.uuid, 'Relation uuid');
205
- if (entityUuids.has(relationUuid)) {
206
- throw new Error('[Order Notes] Note/Relation uuid 不能重复');
207
- }
208
- entityUuids.add(relationUuid);
209
- const allowEmptyTarget = options.allowUnresolvedOrderTarget === true && relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order';
210
- return {
211
- uuid: relationUuid,
212
- relation_type: relation.relation_type,
213
- target_type: relation.target_type,
214
- target_uuid: normalizeUuid(relation.target_uuid, 'Relation target_uuid', {
215
- allowEmpty: allowEmptyTarget
216
- }),
217
- is_primary: relation.is_primary
218
- };
219
- });
220
- const primaryRelation = noteRelations.find(relation => relation.is_primary === 1);
221
- const policy = getSalesNotePolicy(note_type);
222
- if (policy.uniquePerPrimaryTarget) {
223
- const policyTargetKey = [note_type, primaryRelation.target_type, primaryRelation.target_uuid].join(':');
224
- if (uniquePolicyTargets.has(policyTargetKey)) {
225
- throw new Error('[Order Notes] 同一商品行不能重复提交同类型 Note');
226
- }
227
- uniquePolicyTargets.add(policyTargetKey);
228
- }
229
- return {
230
- uuid: noteUuid,
231
- note_type,
232
- content: {
233
- text: {
234
- ...(note.content?.text || {})
235
- }
236
- },
237
- importance: note.importance,
238
- note_relations: noteRelations
239
- };
240
- });
241
- }
242
- function decodeRelation(value) {
243
- if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
244
- const raw = value;
245
- const uuid = String(raw.uuid ?? '').trim();
246
- const target_uuid = String(raw.target_uuid ?? '').trim();
247
- const relation_type = raw.relation_type;
248
- const target_type = raw.target_type;
249
- const is_primary = raw.is_primary;
250
- if (!uuid || relation_type !== 'about' && relation_type !== 'related_to' || target_type !== 'order' && target_type !== 'order_detail' || is_primary !== 0 && is_primary !== 1) {
251
- return null;
252
- }
253
- return {
254
- uuid,
255
- relation_type,
256
- target_type,
257
- target_uuid,
258
- is_primary
259
- };
260
- }
261
- function decodeSalesNotesSnapshot(value, options = {}) {
262
- if (!Array.isArray(value)) return {
263
- notes: [],
264
- complete: false
265
- };
266
- const notes = [];
267
- const entityUuids = new Set();
268
- const uniquePolicyTargets = new Set();
269
- let complete = true;
270
- for (const item of value) {
271
- if (!item || typeof item !== 'object' || Array.isArray(item)) {
272
- complete = false;
273
- continue;
274
- }
275
- const raw = item;
276
- const uuid = String(raw.uuid ?? '').trim();
277
- const note_type = String(raw.note_type ?? '').trim();
278
- const importance = String(raw.importance ?? '').trim();
279
- const rawText = raw.content?.text;
280
- const text = normalizeTextRecord(rawText);
281
- if (!rawText || typeof rawText !== 'object' || Array.isArray(rawText) || Object.keys(text).length !== Object.keys(rawText).length) {
282
- complete = false;
283
- continue;
284
- }
285
- const rawNoteRelations = Array.isArray(raw.note_relations) ? raw.note_relations : null;
286
- const noteRelations = rawNoteRelations ? rawNoteRelations.map(relation => decodeRelation(relation)).filter(relation => relation !== null) : [];
287
- if (!rawNoteRelations || noteRelations.length !== rawNoteRelations.length) {
288
- complete = false;
289
- continue;
290
- }
291
- const note = {
292
- uuid,
293
- note_type,
294
- content: {
295
- text
296
- },
297
- importance,
298
- note_relations: noteRelations
299
- };
300
- try {
301
- validateSalesNote(note, {
302
- allowUnresolvedOrderTarget: options.allowUnresolvedOrderTarget
303
- });
304
- if (entityUuids.has(note.uuid)) {
305
- complete = false;
306
- continue;
307
- }
308
- entityUuids.add(note.uuid);
309
- let hasDuplicateRelationUuid = false;
310
- for (const relation of note.note_relations) {
311
- if (entityUuids.has(relation.uuid)) {
312
- hasDuplicateRelationUuid = true;
313
- break;
314
- }
315
- }
316
- if (hasDuplicateRelationUuid) {
317
- complete = false;
318
- continue;
319
- }
320
- note.note_relations.forEach(relation => entityUuids.add(relation.uuid));
321
- const policy = getSalesNotePolicy(note.note_type);
322
- const primaryRelation = note.note_relations.find(relation => relation.is_primary === 1);
323
- if (policy?.uniquePerPrimaryTarget && primaryRelation) {
324
- const policyTargetKey = [note.note_type, primaryRelation.target_type, primaryRelation.target_uuid].join(':');
325
- if (uniquePolicyTargets.has(policyTargetKey)) {
326
- complete = false;
327
- continue;
328
- }
329
- uniquePolicyTargets.add(policyTargetKey);
330
- }
331
- notes.push(note);
332
- } catch {
333
- complete = false;
334
- }
335
- }
336
- return {
337
- notes,
338
- complete
339
- };
340
- }
341
- function decodeSalesNotes(value, options = {}) {
342
- return decodeSalesNotesSnapshot(value, options).notes;
343
- }
344
- function finalizeSalesNotesForCheckout(params) {
345
- if (!Array.isArray(params.notes)) {
346
- throw new Error('[Order Notes] checkout notes 必须为数组');
347
- }
348
- if (params.notes.length === 0) return [];
349
- const shopOrderNumber = normalizeUuid(params.shopOrderNumber, 'shop_order_number');
350
- const productTargetUuids = new Set();
351
- for (const rawTargetUuid of params.productTargetUuids || []) {
352
- const targetUuid = normalizeUuid(rawTargetUuid, '商品 target_uuid');
353
- if (productTargetUuids.has(targetUuid)) {
354
- throw new Error('[Order Notes] 商品行业务标识不能重复');
355
- }
356
- productTargetUuids.add(targetUuid);
357
- }
358
- const decoded = decodeSalesNotesSnapshot(params.notes, {
359
- allowUnresolvedOrderTarget: true
360
- });
361
- if (!decoded.complete || decoded.notes.length !== params.notes.length) {
362
- throw new Error('[Order Notes] checkout Notes 快照不完整');
363
- }
364
- const finalizedNotes = decoded.notes.map(note => ({
365
- ...note,
366
- content: {
367
- text: {
368
- ...note.content.text
369
- }
370
- },
371
- note_relations: note.note_relations.map(relation => ({
372
- ...relation,
373
- ...(relation.is_primary === 0 && relation.relation_type === 'related_to' && relation.target_type === 'order' ? {
374
- target_uuid: shopOrderNumber
375
- } : {})
376
- }))
377
- }));
378
- return encodeSalesNotes(finalizedNotes, {
379
- expectedOrderTargetUuid: shopOrderNumber,
380
- productTargetUuids
381
- });
382
- }