@harrylabsj/kiwi 0.12.4 → 0.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/a2a/node.d.ts +5 -1
- package/dist/a2a/node.js +68 -30
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +4 -0
- package/dist/a2a/server/merchant-handler.js +123 -45
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/a2a/server/merchant-product-facts.d.ts +32 -0
- package/dist/a2a/server/merchant-product-facts.js +57 -0
- package/dist/a2a/server/merchant-product-facts.js.map +1 -0
- package/dist/agent/buyer/buyer-tools.js +285 -3
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/merchant/types.d.ts +4 -9
- package/dist/agent/merchant/types.js +14 -0
- package/dist/agent/merchant/types.js.map +1 -1
- package/dist/buyer-core/a2a-knp.d.ts +1 -0
- package/dist/buyer-core/a2a-knp.js +1 -1
- package/dist/buyer-core/a2a-knp.js.map +1 -1
- package/dist/buyer-core/a2a-negotiator.d.ts +2 -0
- package/dist/buyer-core/a2a-negotiator.js +20 -19
- package/dist/buyer-core/a2a-negotiator.js.map +1 -1
- package/dist/buyer-core/a2a-quote-fetcher.d.ts +2 -0
- package/dist/buyer-core/a2a-quote-fetcher.js +13 -5
- package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -1
- package/dist/buyer-core/product-summary.d.ts +4 -0
- package/dist/buyer-core/product-summary.js +6 -0
- package/dist/buyer-core/product-summary.js.map +1 -1
- package/dist/buyer-core/protocol-recovery.d.ts +12 -1
- package/dist/buyer-core/protocol-recovery.js +59 -19
- package/dist/buyer-core/protocol-recovery.js.map +1 -1
- package/dist/buyer-core/receive-gate.d.ts +11 -0
- package/dist/buyer-core/receive-gate.js +107 -0
- package/dist/buyer-core/receive-gate.js.map +1 -0
- package/dist/cloud/bootstrap.d.ts +4 -0
- package/dist/cloud/bootstrap.js +69 -55
- package/dist/cloud/bootstrap.js.map +1 -1
- package/dist/cloud/file-listing-publication.js +6 -0
- package/dist/cloud/file-listing-publication.js.map +1 -1
- package/dist/cloud/main.d.ts +3 -0
- package/dist/cloud/main.js +47 -11
- package/dist/cloud/main.js.map +1 -1
- package/dist/cloud/product-import-tabular.d.ts +1 -1
- package/dist/cloud/product-import-tabular.js +263 -36
- package/dist/cloud/product-import-tabular.js.map +1 -1
- package/dist/cloud/product-source.d.ts +6 -1
- package/dist/cloud/product-source.js +47 -15
- package/dist/cloud/product-source.js.map +1 -1
- package/dist/commerce/data-source.d.ts +4 -0
- package/dist/commerce/data-source.js.map +1 -1
- package/dist/commerce/shopping-cli-source.js +4 -0
- package/dist/commerce/shopping-cli-source.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.d.ts +2 -0
- package/dist/discovery/catalog-source/kiwi-source.js +4 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/handoff/index.d.ts +2 -1
- package/dist/handoff/index.js +1 -0
- package/dist/handoff/index.js.map +1 -1
- package/dist/handoff/launch-marketplace-policy.d.ts +149 -0
- package/dist/handoff/launch-marketplace-policy.js +301 -0
- package/dist/handoff/launch-marketplace-policy.js.map +1 -0
- package/dist/handoff/marketplace-product-link.d.ts +18 -0
- package/dist/handoff/marketplace-product-link.js +71 -0
- package/dist/handoff/marketplace-product-link.js.map +1 -0
- package/dist/handoff/transaction.d.ts +30 -0
- package/dist/handoff/transaction.js +64 -0
- package/dist/handoff/transaction.js.map +1 -1
- package/dist/handoff/url-safety.d.ts +3 -0
- package/dist/handoff/url-safety.js +4 -0
- package/dist/handoff/url-safety.js.map +1 -1
- package/dist/http/merchant-management/page.js +176 -45
- package/dist/http/merchant-management/page.js.map +1 -1
- package/dist/i18n.d.ts +1 -0
- package/dist/i18n.js +3 -0
- package/dist/i18n.js.map +1 -1
- package/dist/lifecycle/close.d.ts +24 -0
- package/dist/lifecycle/close.js +131 -0
- package/dist/lifecycle/close.js.map +1 -0
- package/dist/mcp/merchant-runtime-assembly.js +6 -4
- package/dist/mcp/merchant-runtime-assembly.js.map +1 -1
- package/dist/mcp/tools.js +17 -16
- package/dist/mcp/tools.js.map +1 -1
- package/dist/merchant/application/service.d.ts +4 -0
- package/dist/merchant/application/service.js.map +1 -1
- package/dist/merchant/stats-store.d.ts +3 -0
- package/dist/merchant/stats-store.js +15 -1
- package/dist/merchant/stats-store.js.map +1 -1
- package/dist/merchant-core/rfq/data-source-adapter.d.ts +2 -10
- package/dist/merchant-core/rfq/data-source-adapter.js +21 -9
- package/dist/merchant-core/rfq/data-source-adapter.js.map +1 -1
- package/dist/merchant-gateway/pinned-fetch.js +5 -2
- package/dist/merchant-gateway/pinned-fetch.js.map +1 -1
- package/package.json +10 -11
- package/scripts/check-install-toolchain.mjs +64 -40
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
* 既有 import-drafts 严格校验与整表替换预览;
|
|
32
32
|
* - 上限:数据行 5000、列 64、单文件 4 MiB、单元格 2000 字符。
|
|
33
33
|
*/
|
|
34
|
+
import { toMinorUnits as losslessToMinorUnits } from "../protocol/legacy-shopping-negotiation/money.js";
|
|
34
35
|
import { inflateRawSync } from "node:zlib";
|
|
36
|
+
import { MarketplaceProductLinkError, parseMarketplaceProductFields, } from "../handoff/marketplace-product-link.js";
|
|
35
37
|
import { parseProductTable, PRODUCT_TABLE_SCHEMA_VERSION, ProductTableError, } from "./product-source.js";
|
|
36
38
|
// ── 上限与常量 ─────────────────────────────────────────────────────────
|
|
37
39
|
export const TABULAR_IMPORT_MAX_ROWS = 5000;
|
|
@@ -58,7 +60,17 @@ export const TABULAR_FIELDS = [
|
|
|
58
60
|
field: "title",
|
|
59
61
|
zh: "名称",
|
|
60
62
|
required: true,
|
|
61
|
-
aliases: [
|
|
63
|
+
aliases: [
|
|
64
|
+
"title",
|
|
65
|
+
"name",
|
|
66
|
+
"productname",
|
|
67
|
+
"producttitle",
|
|
68
|
+
"商品名称",
|
|
69
|
+
"产品名称",
|
|
70
|
+
"品名",
|
|
71
|
+
"名称",
|
|
72
|
+
"商品标题",
|
|
73
|
+
],
|
|
62
74
|
},
|
|
63
75
|
{
|
|
64
76
|
field: "currency",
|
|
@@ -70,7 +82,17 @@ export const TABULAR_FIELDS = [
|
|
|
70
82
|
field: "unit",
|
|
71
83
|
zh: "计价单位",
|
|
72
84
|
required: true,
|
|
73
|
-
aliases: [
|
|
85
|
+
aliases: [
|
|
86
|
+
"unit",
|
|
87
|
+
"units",
|
|
88
|
+
"pricingunit",
|
|
89
|
+
"unitofmeasure",
|
|
90
|
+
"uom",
|
|
91
|
+
"计价单位",
|
|
92
|
+
"单位",
|
|
93
|
+
"计量单位",
|
|
94
|
+
"价格单位",
|
|
95
|
+
],
|
|
74
96
|
},
|
|
75
97
|
{
|
|
76
98
|
field: "price",
|
|
@@ -100,19 +122,50 @@ export const TABULAR_FIELDS = [
|
|
|
100
122
|
field: "stock",
|
|
101
123
|
zh: "库存",
|
|
102
124
|
required: false,
|
|
103
|
-
aliases: [
|
|
125
|
+
aliases: [
|
|
126
|
+
"stock",
|
|
127
|
+
"stockqty",
|
|
128
|
+
"inventory",
|
|
129
|
+
"qty",
|
|
130
|
+
"quantity",
|
|
131
|
+
"库存",
|
|
132
|
+
"库存数量",
|
|
133
|
+
"可用库存",
|
|
134
|
+
"剩余库存",
|
|
135
|
+
],
|
|
104
136
|
},
|
|
105
137
|
{
|
|
106
138
|
field: "supply_note",
|
|
107
139
|
zh: "供货说明",
|
|
108
140
|
required: false,
|
|
109
|
-
aliases: [
|
|
141
|
+
aliases: [
|
|
142
|
+
"supplynote",
|
|
143
|
+
"note",
|
|
144
|
+
"notes",
|
|
145
|
+
"remark",
|
|
146
|
+
"remarks",
|
|
147
|
+
"供货说明",
|
|
148
|
+
"供货备注",
|
|
149
|
+
"备注",
|
|
150
|
+
"说明",
|
|
151
|
+
"商品说明",
|
|
152
|
+
"描述",
|
|
153
|
+
"description",
|
|
154
|
+
],
|
|
110
155
|
},
|
|
111
156
|
{
|
|
112
157
|
field: "updated_at",
|
|
113
158
|
zh: "更新时间",
|
|
114
159
|
required: false,
|
|
115
|
-
aliases: [
|
|
160
|
+
aliases: [
|
|
161
|
+
"updatedat",
|
|
162
|
+
"updatetime",
|
|
163
|
+
"lastupdated",
|
|
164
|
+
"更新时间",
|
|
165
|
+
"数据时间",
|
|
166
|
+
"修改时间",
|
|
167
|
+
"最近更新",
|
|
168
|
+
],
|
|
116
169
|
},
|
|
117
170
|
{
|
|
118
171
|
field: "valid_until",
|
|
@@ -140,6 +193,18 @@ export const TABULAR_FIELDS = [
|
|
|
140
193
|
required: false,
|
|
141
194
|
aliases: ["status", "listingstatus", "active", "状态", "商品状态", "销售状态", "上架状态"],
|
|
142
195
|
},
|
|
196
|
+
{
|
|
197
|
+
field: "trade_platform",
|
|
198
|
+
zh: "交易平台",
|
|
199
|
+
required: false,
|
|
200
|
+
aliases: ["tradeplatform", "交易平台", "商品交易平台"],
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
field: "platform_product_id",
|
|
204
|
+
zh: "平台商品ID",
|
|
205
|
+
required: false,
|
|
206
|
+
aliases: ["platformproductid", "平台商品id", "交易平台商品id"],
|
|
207
|
+
},
|
|
143
208
|
];
|
|
144
209
|
/**
|
|
145
210
|
* 疑似底价/成本/进价列(归一化后**包含**即命中):整表拒绝。底价、成本
|
|
@@ -499,6 +564,9 @@ function columnToIndex(ref) {
|
|
|
499
564
|
}
|
|
500
565
|
/** 解析第一张工作表为字符串矩阵;数值保持原文,日期样式数值转 ISO。 */
|
|
501
566
|
export function parseXlsx(bytes) {
|
|
567
|
+
return parseXlsxGrid(bytes).rows;
|
|
568
|
+
}
|
|
569
|
+
function parseXlsxGrid(bytes) {
|
|
502
570
|
if (bytes.length > TABULAR_IMPORT_MAX_BYTES) {
|
|
503
571
|
throw new TabularImportError("LIMIT_BYTES", `文件超过上限 ${TABULAR_IMPORT_MAX_BYTES} 字节`);
|
|
504
572
|
}
|
|
@@ -512,6 +580,7 @@ export function parseXlsx(bytes) {
|
|
|
512
580
|
const dateStyles = readDateStyles(reader.read("xl/styles.xml"));
|
|
513
581
|
const xml = new TextDecoder().decode(sheetXml);
|
|
514
582
|
const rows = [];
|
|
583
|
+
const nonTextCells = new Set();
|
|
515
584
|
const rowRe = /<row[^>]*\br="(\d+)"[^>]*>([\s\S]*?)<\/row>|<row[^>]*\/>/g;
|
|
516
585
|
let rowMatch;
|
|
517
586
|
while ((rowMatch = rowRe.exec(xml)) !== null) {
|
|
@@ -519,6 +588,7 @@ export function parseXlsx(bytes) {
|
|
|
519
588
|
throw new TabularImportError("LIMIT_ROWS", `数据行超过上限 ${TABULAR_IMPORT_MAX_ROWS} 行`);
|
|
520
589
|
}
|
|
521
590
|
const cells = [];
|
|
591
|
+
const rowNonText = [];
|
|
522
592
|
const body = rowMatch[2] ?? "";
|
|
523
593
|
const cellRe = /<c([^>]*)(?:\/>|>([\s\S]*?)<\/c>)/g;
|
|
524
594
|
let cellMatch;
|
|
@@ -539,13 +609,21 @@ export function parseXlsx(bytes) {
|
|
|
539
609
|
}
|
|
540
610
|
const value = readCellValue(inner, type, style, shared, dateStyles);
|
|
541
611
|
cells[column] = value;
|
|
612
|
+
const sharedIndex = /<v>([\s\S]*?)<\/v>/.exec(inner)?.[1] ?? "";
|
|
613
|
+
const textCell = type === "inlineStr" || type === "str" || (type === "s" && /^[0-9]+$/.test(sharedIndex));
|
|
614
|
+
if (value !== "" && (!textCell || /<f[\s/>]/.test(inner)))
|
|
615
|
+
rowNonText.push(column);
|
|
542
616
|
}
|
|
543
617
|
// cells 是稀疏数组(按列号落位);map/forEach 会跳过空洞导致错位,
|
|
544
618
|
// 必须先稠密化。
|
|
545
619
|
const normalized = Array.from({ length: cells.length }, (_, index) => cells[index] ?? "");
|
|
546
|
-
|
|
620
|
+
if (!normalized.every((cell) => cell === "")) {
|
|
621
|
+
for (const column of rowNonText)
|
|
622
|
+
nonTextCells.add(`${rows.length}:${column}`);
|
|
623
|
+
rows.push(normalized.slice(0, TABULAR_IMPORT_MAX_COLUMNS));
|
|
624
|
+
}
|
|
547
625
|
}
|
|
548
|
-
return rows
|
|
626
|
+
return { rows, nonTextCells };
|
|
549
627
|
}
|
|
550
628
|
function resolveFirstSheetPath(reader) {
|
|
551
629
|
const workbook = reader.read("xl/workbook.xml");
|
|
@@ -631,7 +709,8 @@ function readDateStyles(xml) {
|
|
|
631
709
|
const numFmtId = Number(/\bnumFmtId="(\d+)"/.exec(xfMatch[0])?.[1] ?? 0);
|
|
632
710
|
if ((numFmtId >= 14 && numFmtId <= 22) ||
|
|
633
711
|
(numFmtId >= 45 && numFmtId <= 47) ||
|
|
634
|
-
(customFormats.get(numFmtId) ?? "").replace(/\[[^\]]*\]|"[^"]*"/g, "").match(/[ymdhs]/i) !==
|
|
712
|
+
(customFormats.get(numFmtId) ?? "").replace(/\[[^\]]*\]|"[^"]*"/g, "").match(/[ymdhs]/i) !==
|
|
713
|
+
null) {
|
|
635
714
|
styles.add(styleIndex);
|
|
636
715
|
}
|
|
637
716
|
styleIndex += 1;
|
|
@@ -652,33 +731,39 @@ export const TABULAR_TEMPLATE_HEADER = [
|
|
|
652
731
|
"更新时间/updated_at",
|
|
653
732
|
"有效期至/valid_until",
|
|
654
733
|
"状态/status",
|
|
734
|
+
"交易平台/trade_platform",
|
|
735
|
+
"平台商品ID/platform_product_id",
|
|
655
736
|
];
|
|
656
737
|
export const TABULAR_TEMPLATE_EXAMPLE_ROWS = [
|
|
657
738
|
[
|
|
658
739
|
"DEMO-001",
|
|
659
|
-
"
|
|
740
|
+
"示例保温杯(请替换为实际商品)",
|
|
660
741
|
"CNY",
|
|
661
742
|
"piece",
|
|
662
743
|
"29.90",
|
|
663
744
|
"50",
|
|
664
745
|
"2000",
|
|
665
|
-
"
|
|
746
|
+
"仅格式示例;平台商品ID不代表已核实商品,请替换",
|
|
666
747
|
"",
|
|
667
748
|
"2027-12-31",
|
|
668
749
|
"在售",
|
|
750
|
+
"京东",
|
|
751
|
+
"12345678901234567890",
|
|
669
752
|
],
|
|
670
753
|
[
|
|
671
754
|
"DEMO-002",
|
|
672
|
-
"
|
|
755
|
+
"示例纸箱(请替换为实际商品)",
|
|
673
756
|
"CNY",
|
|
674
757
|
"box",
|
|
675
758
|
"3.50",
|
|
676
759
|
"100",
|
|
677
760
|
"8000",
|
|
678
|
-
"
|
|
761
|
+
"仅格式示例;平台商品ID不代表已核实商品,请替换",
|
|
679
762
|
"2026-09-01",
|
|
680
763
|
"2028-06-30",
|
|
681
764
|
"在售",
|
|
765
|
+
"淘宝",
|
|
766
|
+
"98765432101234567890",
|
|
682
767
|
],
|
|
683
768
|
];
|
|
684
769
|
function csvEscape(cell) {
|
|
@@ -771,18 +856,19 @@ function sheetXmlFromGrid(rows) {
|
|
|
771
856
|
const cells = row
|
|
772
857
|
.map((cell, columnIndex) => cell === ""
|
|
773
858
|
? ""
|
|
774
|
-
: `<c r="${columnName(columnIndex)}${rowIndex + 1}" t="inlineStr"><is><t xml:space="preserve">${xmlEscape(cell)}</t></is></c>`)
|
|
859
|
+
: `<c r="${columnName(columnIndex)}${rowIndex + 1}"${columnIndex === 12 ? ' s="1"' : ""} t="inlineStr"><is><t xml:space="preserve">${xmlEscape(cell)}</t></is></c>`)
|
|
775
860
|
.join("");
|
|
776
861
|
return `<row r="${rowIndex + 1}">${cells}</row>`;
|
|
777
862
|
})
|
|
778
863
|
.join("");
|
|
779
864
|
const cols = Array.from({ length: columnCount }, (_, index) => {
|
|
780
865
|
const width = index === 0 || index === 7 ? 260 : 110;
|
|
781
|
-
return `<col min="${index + 1}" max="${index + 1}" width="${width}" customWidth="1"/>`;
|
|
866
|
+
return `<col min="${index + 1}" max="${index + 1}" width="${width}" customWidth="1"${index === 12 ? ' style="1"' : ""}/>`;
|
|
782
867
|
}).join("");
|
|
783
868
|
return (`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` +
|
|
784
869
|
`<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">` +
|
|
785
|
-
`<cols>${cols}</cols><sheetData>${body}</sheetData
|
|
870
|
+
`<cols>${cols}</cols><sheetData>${body}</sheetData>` +
|
|
871
|
+
`<dataValidations count="1"><dataValidation type="list" allowBlank="1" showErrorMessage="1" sqref="L2:L5001"><formula1>"京东,淘宝,天猫"</formula1></dataValidation></dataValidations></worksheet>`);
|
|
786
872
|
}
|
|
787
873
|
function columnName(index) {
|
|
788
874
|
let name = "";
|
|
@@ -805,6 +891,7 @@ export function renderImportTemplateXlsx() {
|
|
|
805
891
|
`<Default Extension="xml" ContentType="application/xml"/>` +
|
|
806
892
|
`<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>` +
|
|
807
893
|
`<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>` +
|
|
894
|
+
`<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>` +
|
|
808
895
|
`</Types>`,
|
|
809
896
|
},
|
|
810
897
|
{
|
|
@@ -826,9 +913,20 @@ export function renderImportTemplateXlsx() {
|
|
|
826
913
|
content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` +
|
|
827
914
|
`<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">` +
|
|
828
915
|
`<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>` +
|
|
916
|
+
`<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>` +
|
|
829
917
|
`</Relationships>`,
|
|
830
918
|
},
|
|
831
919
|
{ name: "xl/worksheets/sheet1.xml", content: sheetXmlFromGrid(grid) },
|
|
920
|
+
{
|
|
921
|
+
name: "xl/styles.xml",
|
|
922
|
+
content: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>` +
|
|
923
|
+
`<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">` +
|
|
924
|
+
`<fonts count="1"><font><sz val="11"/><name val="Calibri"/></font></fonts>` +
|
|
925
|
+
`<fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills>` +
|
|
926
|
+
`<borders count="1"><border/></borders><cellStyleXfs count="1"><xf numFmtId="0"/></cellStyleXfs>` +
|
|
927
|
+
`<cellXfs count="2"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/><xf numFmtId="49" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/></cellXfs>` +
|
|
928
|
+
`<cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>`,
|
|
929
|
+
},
|
|
832
930
|
]);
|
|
833
931
|
}
|
|
834
932
|
/**
|
|
@@ -839,14 +937,28 @@ export function convertTabularImport(input, options) {
|
|
|
839
937
|
const now = options.now ?? (() => new Date());
|
|
840
938
|
const errors = [];
|
|
841
939
|
let grid;
|
|
940
|
+
let nonTextCells = new Set();
|
|
842
941
|
try {
|
|
843
|
-
|
|
942
|
+
if (input.kind === "csv")
|
|
943
|
+
grid = parseCsv(input.text);
|
|
944
|
+
else {
|
|
945
|
+
const parsed = parseXlsxGrid(input.bytes);
|
|
946
|
+
grid = parsed.rows;
|
|
947
|
+
nonTextCells = parsed.nonTextCells;
|
|
948
|
+
}
|
|
844
949
|
}
|
|
845
950
|
catch (err) {
|
|
846
951
|
if (err instanceof TabularImportError) {
|
|
847
952
|
return {
|
|
848
953
|
ok: false,
|
|
849
|
-
report: {
|
|
954
|
+
report: {
|
|
955
|
+
format: input.kind,
|
|
956
|
+
rows: 0,
|
|
957
|
+
header_mapping: [],
|
|
958
|
+
unrecognized_columns: [],
|
|
959
|
+
defaulted_fields: [],
|
|
960
|
+
skipped_empty_rows: 0,
|
|
961
|
+
},
|
|
850
962
|
errors: [{ code: err.code, message: err.message }],
|
|
851
963
|
};
|
|
852
964
|
}
|
|
@@ -862,10 +974,18 @@ export function convertTabularImport(input, options) {
|
|
|
862
974
|
};
|
|
863
975
|
const headerRow = grid[0];
|
|
864
976
|
if (headerRow === undefined || headerRow.every((cell) => cell.trim() === "")) {
|
|
865
|
-
return {
|
|
977
|
+
return {
|
|
978
|
+
ok: false,
|
|
979
|
+
report,
|
|
980
|
+
errors: [{ code: "EMPTY_TABLE", message: "表格是空的:第一行应为表头" }],
|
|
981
|
+
};
|
|
866
982
|
}
|
|
867
983
|
if (grid.length - 1 <= 0) {
|
|
868
|
-
return {
|
|
984
|
+
return {
|
|
985
|
+
ok: false,
|
|
986
|
+
report,
|
|
987
|
+
errors: [{ code: "EMPTY_TABLE", message: "表格只有表头,没有商品行" }],
|
|
988
|
+
};
|
|
869
989
|
}
|
|
870
990
|
if (headerRow.length > TABULAR_IMPORT_MAX_COLUMNS) {
|
|
871
991
|
return {
|
|
@@ -969,56 +1089,116 @@ export function convertTabularImport(input, options) {
|
|
|
969
1089
|
}
|
|
970
1090
|
const sku = cellOf(row, "sku");
|
|
971
1091
|
if (sku === "") {
|
|
972
|
-
errors.push({
|
|
1092
|
+
errors.push({
|
|
1093
|
+
row: rowNumber,
|
|
1094
|
+
field: "sku",
|
|
1095
|
+
code: "EMPTY_REQUIRED",
|
|
1096
|
+
message: `第 ${rowNumber} 行商品编号(sku)为空`,
|
|
1097
|
+
});
|
|
973
1098
|
}
|
|
974
1099
|
const title = cellOf(row, "title");
|
|
975
1100
|
if (title === "") {
|
|
976
|
-
errors.push({
|
|
1101
|
+
errors.push({
|
|
1102
|
+
row: rowNumber,
|
|
1103
|
+
field: "title",
|
|
1104
|
+
code: "EMPTY_REQUIRED",
|
|
1105
|
+
message: `第 ${rowNumber} 行名称(title)为空`,
|
|
1106
|
+
});
|
|
977
1107
|
}
|
|
978
1108
|
const unit = cellOf(row, "unit");
|
|
979
1109
|
if (unit === "") {
|
|
980
|
-
errors.push({
|
|
1110
|
+
errors.push({
|
|
1111
|
+
row: rowNumber,
|
|
1112
|
+
field: "unit",
|
|
1113
|
+
code: "EMPTY_REQUIRED",
|
|
1114
|
+
message: `第 ${rowNumber} 行计价单位(unit)为空`,
|
|
1115
|
+
});
|
|
981
1116
|
}
|
|
982
1117
|
const priceRaw = cellOf(row, "price");
|
|
983
1118
|
const price = parseCellNumber(priceRaw);
|
|
984
1119
|
if (priceRaw === "") {
|
|
985
|
-
errors.push({
|
|
1120
|
+
errors.push({
|
|
1121
|
+
row: rowNumber,
|
|
1122
|
+
field: "price",
|
|
1123
|
+
code: "EMPTY_REQUIRED",
|
|
1124
|
+
message: `第 ${rowNumber} 行单价(price)为空:价格必须由商家提供,不能缺省`,
|
|
1125
|
+
});
|
|
986
1126
|
}
|
|
987
|
-
else if (Number.
|
|
988
|
-
errors.push({
|
|
1127
|
+
else if (!Number.isFinite(price) || price < 0 || !losslessToMinorUnits(price, 2).lossless) {
|
|
1128
|
+
errors.push({
|
|
1129
|
+
row: rowNumber,
|
|
1130
|
+
field: "price",
|
|
1131
|
+
code: "BAD_NUMBER",
|
|
1132
|
+
message: `第 ${rowNumber} 行单价必须是非负且可无损表示为两位小数(收到「${priceRaw}」)`,
|
|
1133
|
+
});
|
|
989
1134
|
}
|
|
990
1135
|
const currencyRaw = cellOf(row, "currency");
|
|
991
1136
|
const currency = parseCellCurrency(currencyRaw);
|
|
992
1137
|
if (currencyRaw === "") {
|
|
993
|
-
errors.push({
|
|
1138
|
+
errors.push({
|
|
1139
|
+
row: rowNumber,
|
|
1140
|
+
field: "currency",
|
|
1141
|
+
code: "EMPTY_REQUIRED",
|
|
1142
|
+
message: `第 ${rowNumber} 行币种为空`,
|
|
1143
|
+
});
|
|
994
1144
|
}
|
|
995
1145
|
else if (currency === "") {
|
|
996
|
-
errors.push({
|
|
1146
|
+
errors.push({
|
|
1147
|
+
row: rowNumber,
|
|
1148
|
+
field: "currency",
|
|
1149
|
+
code: "BAD_CURRENCY",
|
|
1150
|
+
message: `第 ${rowNumber} 行币种无法识别(收到「${currencyRaw}」):请填三字母代码(如 CNY/USD)或常见中文名(人民币/美元/欧元/港币/日元/英镑)`,
|
|
1151
|
+
});
|
|
997
1152
|
}
|
|
998
1153
|
const validRaw = cellOf(row, "valid_until");
|
|
999
1154
|
const validUntil = parseCellDate(validRaw, { endOfDay: true });
|
|
1000
1155
|
if (validRaw === "") {
|
|
1001
|
-
errors.push({
|
|
1156
|
+
errors.push({
|
|
1157
|
+
row: rowNumber,
|
|
1158
|
+
field: "valid_until",
|
|
1159
|
+
code: "EMPTY_REQUIRED",
|
|
1160
|
+
message: `第 ${rowNumber} 行有效期至为空:请填商品可报价的截止日期(如 2027-12-31)`,
|
|
1161
|
+
});
|
|
1002
1162
|
}
|
|
1003
1163
|
else if (validUntil === "") {
|
|
1004
|
-
errors.push({
|
|
1164
|
+
errors.push({
|
|
1165
|
+
row: rowNumber,
|
|
1166
|
+
field: "valid_until",
|
|
1167
|
+
code: "BAD_DATE",
|
|
1168
|
+
message: `第 ${rowNumber} 行有效期不是合法日期(收到「${validRaw}」):请用 2027-12-31、2027/12/31 或 2027年12月31日 格式`,
|
|
1169
|
+
});
|
|
1005
1170
|
}
|
|
1006
1171
|
const updatedRaw = cellOf(row, "updated_at");
|
|
1007
1172
|
const updatedAt = updatedRaw === "" ? now().toISOString() : parseCellDate(updatedRaw, { endOfDay: false });
|
|
1008
1173
|
if (updatedRaw !== "" && updatedAt === "") {
|
|
1009
|
-
errors.push({
|
|
1174
|
+
errors.push({
|
|
1175
|
+
row: rowNumber,
|
|
1176
|
+
field: "updated_at",
|
|
1177
|
+
code: "BAD_DATE",
|
|
1178
|
+
message: `第 ${rowNumber} 行更新时间不是合法日期(收到「${updatedRaw}」):留空将自动使用导入时间`,
|
|
1179
|
+
});
|
|
1010
1180
|
}
|
|
1011
1181
|
const statusRaw = cellOf(row, "status");
|
|
1012
1182
|
const status = statusRaw === "" ? "active" : parseCellStatus(statusRaw);
|
|
1013
1183
|
if (statusRaw !== "" && status === "") {
|
|
1014
|
-
errors.push({
|
|
1184
|
+
errors.push({
|
|
1185
|
+
row: rowNumber,
|
|
1186
|
+
field: "status",
|
|
1187
|
+
code: "BAD_STATUS",
|
|
1188
|
+
message: `第 ${rowNumber} 行状态无法识别(收到「${statusRaw}」):留空=在售;或填 在售/暂停`,
|
|
1189
|
+
});
|
|
1015
1190
|
}
|
|
1016
1191
|
const moqRaw = cellOf(row, "moq");
|
|
1017
1192
|
let moq;
|
|
1018
1193
|
if (moqRaw !== "") {
|
|
1019
1194
|
const parsed = parseCellNumber(moqRaw);
|
|
1020
1195
|
if (Number.isNaN(parsed) || !Number.isInteger(parsed) || parsed <= 0) {
|
|
1021
|
-
errors.push({
|
|
1196
|
+
errors.push({
|
|
1197
|
+
row: rowNumber,
|
|
1198
|
+
field: "moq",
|
|
1199
|
+
code: "BAD_NUMBER",
|
|
1200
|
+
message: `第 ${rowNumber} 行起订量必须是正整数(收到「${moqRaw}」)`,
|
|
1201
|
+
});
|
|
1022
1202
|
}
|
|
1023
1203
|
else {
|
|
1024
1204
|
moq = parsed;
|
|
@@ -1029,16 +1209,58 @@ export function convertTabularImport(input, options) {
|
|
|
1029
1209
|
if (stockRaw !== "") {
|
|
1030
1210
|
const parsed = parseCellNumber(stockRaw);
|
|
1031
1211
|
if (Number.isNaN(parsed) || !Number.isInteger(parsed) || parsed < 0) {
|
|
1032
|
-
errors.push({
|
|
1212
|
+
errors.push({
|
|
1213
|
+
row: rowNumber,
|
|
1214
|
+
field: "stock",
|
|
1215
|
+
code: "BAD_NUMBER",
|
|
1216
|
+
message: `第 ${rowNumber} 行库存必须是非负整数(收到「${stockRaw}」);不确定就留空,不要填 0 冒充`,
|
|
1217
|
+
});
|
|
1033
1218
|
}
|
|
1034
1219
|
else {
|
|
1035
1220
|
stock = parsed;
|
|
1036
1221
|
}
|
|
1037
1222
|
}
|
|
1223
|
+
let tradeFields = {};
|
|
1224
|
+
const platformRaw = cellOf(row, "trade_platform");
|
|
1225
|
+
const productIdRaw = cellOf(row, "platform_product_id");
|
|
1226
|
+
const productIdColumn = columnIndex.get("platform_product_id");
|
|
1227
|
+
if (productIdRaw !== "" &&
|
|
1228
|
+
productIdColumn !== undefined &&
|
|
1229
|
+
nonTextCells.has(`${index}:${productIdColumn}`)) {
|
|
1230
|
+
errors.push({
|
|
1231
|
+
row: rowNumber,
|
|
1232
|
+
field: "platform_product_id",
|
|
1233
|
+
code: "BAD_PLATFORM_PRODUCT_ID_TYPE",
|
|
1234
|
+
message: `第 ${rowNumber} 行平台商品ID必须是文本单元格,不能用数字或公式;请从平台重新复制准确ID到文本列`,
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
else {
|
|
1238
|
+
try {
|
|
1239
|
+
tradeFields = parseMarketplaceProductFields({
|
|
1240
|
+
trade_platform: platformRaw,
|
|
1241
|
+
platform_product_id: productIdRaw,
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
catch (error) {
|
|
1245
|
+
if (!(error instanceof MarketplaceProductLinkError))
|
|
1246
|
+
throw error;
|
|
1247
|
+
errors.push({
|
|
1248
|
+
row: rowNumber,
|
|
1249
|
+
field: error.field,
|
|
1250
|
+
code: "BAD_PRODUCT_TRADE_ENTRY",
|
|
1251
|
+
message: `第 ${rowNumber} 行:${error.message}`,
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1038
1255
|
if (sku !== "") {
|
|
1039
1256
|
const firstRow = skuRows.get(sku);
|
|
1040
1257
|
if (firstRow !== undefined) {
|
|
1041
|
-
errors.push({
|
|
1258
|
+
errors.push({
|
|
1259
|
+
row: rowNumber,
|
|
1260
|
+
field: "sku",
|
|
1261
|
+
code: "DUPLICATE_SKU",
|
|
1262
|
+
message: `第 ${rowNumber} 行商品编号「${sku}」与第 ${firstRow} 行重复:同一 SKU 只能出现一次`,
|
|
1263
|
+
});
|
|
1042
1264
|
}
|
|
1043
1265
|
else {
|
|
1044
1266
|
skuRows.set(sku, rowNumber);
|
|
@@ -1049,13 +1271,14 @@ export function convertTabularImport(input, options) {
|
|
|
1049
1271
|
title,
|
|
1050
1272
|
currency: currency === "" ? currencyRaw : currency,
|
|
1051
1273
|
unit,
|
|
1052
|
-
price: Number.isNaN(price) ? 0 :
|
|
1274
|
+
price: Number.isNaN(price) ? 0 : price,
|
|
1053
1275
|
...(moq !== undefined ? { moq } : {}),
|
|
1054
1276
|
...(stock !== undefined ? { stock } : {}),
|
|
1055
1277
|
...(cellOf(row, "supply_note") !== "" ? { supply_note: cellOf(row, "supply_note") } : {}),
|
|
1056
1278
|
updated_at: updatedAt === "" ? now().toISOString() : updatedAt,
|
|
1057
1279
|
valid_until: validUntil === "" ? validRaw : validUntil,
|
|
1058
1280
|
status: status === "" ? "active" : status,
|
|
1281
|
+
...tradeFields,
|
|
1059
1282
|
});
|
|
1060
1283
|
}
|
|
1061
1284
|
if (errors.length > 0)
|
|
@@ -1078,7 +1301,11 @@ export function convertTabularImport(input, options) {
|
|
|
1078
1301
|
}
|
|
1079
1302
|
catch (err) {
|
|
1080
1303
|
const message = err instanceof ProductTableError ? err.message : String(err);
|
|
1081
|
-
return {
|
|
1304
|
+
return {
|
|
1305
|
+
ok: false,
|
|
1306
|
+
report,
|
|
1307
|
+
errors: [{ code: "TABLE_INVALID", message: `转换结果未通过商品表校验:${message}` }],
|
|
1308
|
+
};
|
|
1082
1309
|
}
|
|
1083
1310
|
return { ok: true, table, report, errors: [] };
|
|
1084
1311
|
}
|