idosell 0.4.11 → 0.4.13
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/changelog.md +5 -0
- package/dist/gateways.d.ts +15 -2
- package/dist/index.js +2 -1
- package/dist/reqparams.d.ts +12 -0
- package/dist/responses.d.ts +1224 -0
- package/dist/utils.d.ts +31 -0
- package/dist/utils.js +99 -0
- package/package.json +1 -1
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SearchProductsResponse } from "./responses.d.ts"
|
|
2
|
+
|
|
3
|
+
export enum QunatityType {
|
|
4
|
+
ProductSizeQuantityOwnStock = "productSizeQuantityOwnStock",
|
|
5
|
+
ProductSizeQuantityOutsideStock = "productSizeQuantityOutsideStock",
|
|
6
|
+
ProductSizeQuantityAllStocks = "productSizeQuantityAllStocks",
|
|
7
|
+
ProductStocksQuantities = "productStocksQuantities",
|
|
8
|
+
ProductOrdersUnfinishedQuantities = "productOrdersUnfinishedQuantities",
|
|
9
|
+
ProductSizesDeliveries = "productSizesDeliveries",
|
|
10
|
+
ProductSizesDispositionsInAuctions = "productSizesDispositionsInAuctions",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type IdosellProduct = SearchProductsResponse['results'][0];
|
|
14
|
+
|
|
15
|
+
export type GetIaICodeFunction = (productId: number|string, sizeId: string) => string;
|
|
16
|
+
|
|
17
|
+
export type SumProductQuantitiesFunction = (productStocksData: IdosellProduct['productStocksData'], stockType?: QunatityType) => number;
|
|
18
|
+
|
|
19
|
+
export type MapSizeQuantitesFunction = (product: IdosellProduct, stockType?: QunatityType) => Record<string,number>;
|
|
20
|
+
|
|
21
|
+
export type MapProductCodesFunction = (product: IdosellProduct, codeType?: 'productSizeCodeExternal'|'productSizeCodeProducer'|'sizePanelName') => Record<string,string>;
|
|
22
|
+
|
|
23
|
+
declare namespace utils {
|
|
24
|
+
const QUANTITY_TYPE_ENUM: typeof QunatityType;
|
|
25
|
+
const getIaiCode: GetIaICodeFunction;
|
|
26
|
+
const sumProductQuantities: SumProductQuantitiesFunction;
|
|
27
|
+
const mapSizeQuantites: MapSizeQuantitesFunction;
|
|
28
|
+
const mapProductCodes: MapProductCodesFunction;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default utils;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export var QunatityType;
|
|
2
|
+
(function (QunatityType) {
|
|
3
|
+
QunatityType["ProductSizeQuantityOwnStock"] = "productSizeQuantityOwnStock";
|
|
4
|
+
QunatityType["ProductSizeQuantityOutsideStock"] = "productSizeQuantityOutsideStock";
|
|
5
|
+
QunatityType["ProductSizeQuantityAllStocks"] = "productSizeQuantityAllStocks";
|
|
6
|
+
QunatityType["ProductStocksQuantities"] = "productStocksQuantities";
|
|
7
|
+
QunatityType["ProductOrdersUnfinishedQuantities"] = "productOrdersUnfinishedQuantities";
|
|
8
|
+
QunatityType["ProductSizesDeliveries"] = "productSizesDeliveries";
|
|
9
|
+
QunatityType["ProductSizesDispositionsInAuctions"] = "productSizesDispositionsInAuctions";
|
|
10
|
+
})(QunatityType || (QunatityType = {}));
|
|
11
|
+
const productQuantityPathMap = {
|
|
12
|
+
// ----- Product Dispositions -----
|
|
13
|
+
[QunatityType.ProductSizeQuantityOwnStock]: ["productSizesDispositions", "productSizesDispositionsInSales", "productSizeQuantityOwnStock"],
|
|
14
|
+
[QunatityType.ProductSizeQuantityOutsideStock]: ["productSizesDispositions", "productSizesDispositionsInSales", "productSizeQuantityOutsideStock"],
|
|
15
|
+
[QunatityType.ProductSizeQuantityAllStocks]: ["productSizesDispositions", "productSizesDispositionsInSales", "productSizeQuantityAllStocks"],
|
|
16
|
+
[QunatityType.ProductSizesDispositionsInAuctions]: ["productSizesDispositions", "productSizesDispositionsInAuctions", "productSizeQuantity"],
|
|
17
|
+
// ----- Stocks & related quantities -----
|
|
18
|
+
[QunatityType.ProductStocksQuantities]: ["productStocksQuantities", "productSizeQuantity"],
|
|
19
|
+
[QunatityType.ProductOrdersUnfinishedQuantities]: ["productOrdersUnfinishedQuantities", "productSizeQuantity"],
|
|
20
|
+
[QunatityType.ProductSizesDeliveries]: ["productSizesDeliveries", "productSizeQuantity"],
|
|
21
|
+
};
|
|
22
|
+
const getProductSizeArrayNode = (productStocksData, key) => {
|
|
23
|
+
const pathNode = productQuantityPathMap[key];
|
|
24
|
+
if (!pathNode)
|
|
25
|
+
throw new Error("Invalid stock type " + key);
|
|
26
|
+
const path = pathNode.slice(0, -1);
|
|
27
|
+
const node = pathNode[pathNode.length - 1];
|
|
28
|
+
const arr = getProductSizeArray(productStocksData, path);
|
|
29
|
+
return { arr, node };
|
|
30
|
+
};
|
|
31
|
+
const getProductSizeArray = (productStocksData, path) => {
|
|
32
|
+
let current = productStocksData;
|
|
33
|
+
for (const segment of path) {
|
|
34
|
+
if (current && typeof current === "object" && segment in current) {
|
|
35
|
+
current = current[segment];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(current)) {
|
|
42
|
+
if (current.length && current[0]?.productSizesData) {
|
|
43
|
+
return current.flatMap((s) => s.productSizesData);
|
|
44
|
+
}
|
|
45
|
+
return current;
|
|
46
|
+
}
|
|
47
|
+
return [];
|
|
48
|
+
};
|
|
49
|
+
const sumProductQuantities = (productStocksData, stockType = QunatityType.ProductSizeQuantityOwnStock) => {
|
|
50
|
+
const { arr, node } = getProductSizeArrayNode(productStocksData, stockType);
|
|
51
|
+
return arr.reduce((total, item) => {
|
|
52
|
+
const value = item[node];
|
|
53
|
+
if (typeof value === 'number')
|
|
54
|
+
total += value;
|
|
55
|
+
return total;
|
|
56
|
+
}, 0);
|
|
57
|
+
};
|
|
58
|
+
const getIaiCode = (productId, sizeId) => {
|
|
59
|
+
if (sizeId === 'uniw')
|
|
60
|
+
return productId.toString();
|
|
61
|
+
return [productId, sizeId].join('-');
|
|
62
|
+
};
|
|
63
|
+
const mapSizeQuantites = (product, stockType = QunatityType.ProductSizeQuantityOwnStock) => {
|
|
64
|
+
const obj = {};
|
|
65
|
+
if (!product.productStocksData)
|
|
66
|
+
return obj;
|
|
67
|
+
const { arr, node } = getProductSizeArrayNode(product.productStocksData, stockType);
|
|
68
|
+
for (const item of arr) {
|
|
69
|
+
const value = item[node];
|
|
70
|
+
if (typeof value !== 'number')
|
|
71
|
+
continue;
|
|
72
|
+
const index = getIaiCode(product.productId, item.sizeId);
|
|
73
|
+
if (!obj[index])
|
|
74
|
+
obj[index] = value;
|
|
75
|
+
else
|
|
76
|
+
obj[index] += value;
|
|
77
|
+
}
|
|
78
|
+
return obj;
|
|
79
|
+
};
|
|
80
|
+
const mapProductCodes = (product, codeType = 'productSizeCodeProducer') => {
|
|
81
|
+
const obj = {};
|
|
82
|
+
if (product.productSizesAttributes) {
|
|
83
|
+
for (const size of product.productSizesAttributes) {
|
|
84
|
+
const code = size[codeType];
|
|
85
|
+
if (!code)
|
|
86
|
+
continue;
|
|
87
|
+
const sku = getIaiCode(product.productId, size.sizeId);
|
|
88
|
+
obj[sku] = code;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return obj;
|
|
92
|
+
};
|
|
93
|
+
export default {
|
|
94
|
+
QUANTITY_TYPE_ENUM: QunatityType,
|
|
95
|
+
getIaiCode,
|
|
96
|
+
sumProductQuantities,
|
|
97
|
+
mapSizeQuantites,
|
|
98
|
+
mapProductCodes
|
|
99
|
+
};
|