@fakeware/plugin-pickware 1.0.0 → 1.1.0
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/dist/index.d.mts +103 -16
- package/dist/index.mjs +114 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,27 +1,72 @@
|
|
|
1
|
-
import { FakewarePlugin, ShopContextFetcher } from "@fakeware/core";
|
|
1
|
+
import { AnyToken, FakewarePlugin, ShopContextFetcher } from "@fakeware/core";
|
|
2
2
|
|
|
3
3
|
//#region src/entities.d.ts
|
|
4
|
-
|
|
4
|
+
declare const PICKWARE_LIVE_VERSION = "0fa91ce3e96a4bc2be4bd9ce752c3425";
|
|
5
|
+
type Id = string | AnyToken;
|
|
6
|
+
interface PickwareBinLocationRecord {
|
|
5
7
|
$key?: string;
|
|
6
|
-
name: string;
|
|
7
8
|
code: string;
|
|
9
|
+
warehouseId: Id;
|
|
8
10
|
}
|
|
9
|
-
interface
|
|
11
|
+
interface PickwareSupplierRecord {
|
|
10
12
|
$key?: string;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
number: string;
|
|
14
|
+
name: string;
|
|
15
|
+
languageId: Id;
|
|
16
|
+
customerNumber?: string;
|
|
17
|
+
}
|
|
18
|
+
interface PickwarePrice {
|
|
19
|
+
currencyId: Id;
|
|
20
|
+
gross: number;
|
|
21
|
+
net: number;
|
|
22
|
+
linked: boolean;
|
|
13
23
|
}
|
|
14
|
-
interface
|
|
24
|
+
interface PickwareProductSupplierConfigurationRecord {
|
|
15
25
|
$key?: string;
|
|
16
|
-
productId:
|
|
26
|
+
productId: Id;
|
|
27
|
+
productVersionId?: string;
|
|
28
|
+
supplierId: Id;
|
|
29
|
+
minPurchase: number;
|
|
30
|
+
purchaseSteps: number;
|
|
31
|
+
purchasePrices: PickwarePrice[];
|
|
32
|
+
supplierIsDefault: boolean;
|
|
33
|
+
}
|
|
34
|
+
type PickwareReturnReason = 'wrong_item' | 'defective' | 'other';
|
|
35
|
+
interface PickwareReturnOrderLineItemRecord {
|
|
36
|
+
$key?: string;
|
|
37
|
+
versionId?: string;
|
|
38
|
+
type?: string;
|
|
39
|
+
name: string;
|
|
17
40
|
quantity: number;
|
|
18
|
-
|
|
41
|
+
position: number;
|
|
42
|
+
reason: PickwareReturnReason;
|
|
43
|
+
priceDefinition: object;
|
|
44
|
+
price: object;
|
|
45
|
+
productId?: Id;
|
|
46
|
+
productVersionId?: string;
|
|
47
|
+
orderLineItemId?: Id;
|
|
48
|
+
orderLineItemVersionId?: string;
|
|
49
|
+
}
|
|
50
|
+
interface PickwareReturnOrderRecord {
|
|
51
|
+
$key?: string;
|
|
52
|
+
versionId?: string;
|
|
53
|
+
number: string;
|
|
54
|
+
stateId?: Id;
|
|
55
|
+
orderId: Id;
|
|
56
|
+
orderVersionId?: string;
|
|
57
|
+
price: object;
|
|
58
|
+
shippingCosts?: object;
|
|
59
|
+
internalComment?: string;
|
|
60
|
+
warehouseId?: Id;
|
|
61
|
+
lineItems: PickwareReturnOrderLineItemRecord[];
|
|
19
62
|
}
|
|
20
63
|
declare module '@fakeware/core' {
|
|
21
64
|
interface EntityRegistry {
|
|
22
|
-
pickware_erp_warehouse: PickwareWarehouseRecord;
|
|
23
65
|
pickware_erp_bin_location: PickwareBinLocationRecord;
|
|
24
|
-
|
|
66
|
+
pickware_erp_supplier: PickwareSupplierRecord;
|
|
67
|
+
pickware_erp_product_supplier_configuration: PickwareProductSupplierConfigurationRecord;
|
|
68
|
+
pickware_erp_return_order: PickwareReturnOrderRecord;
|
|
69
|
+
pickware_erp_return_order_line_item: PickwareReturnOrderLineItemRecord;
|
|
25
70
|
}
|
|
26
71
|
}
|
|
27
72
|
//#endregion
|
|
@@ -34,19 +79,61 @@ interface PickwareWarehouseRow {
|
|
|
34
79
|
}
|
|
35
80
|
declare const PICKWARE_WAREHOUSES_KEY = "pickwareWarehouses";
|
|
36
81
|
declare function pickwareWarehouses(extensions: Record<string, unknown>): PickwareWarehouseRow[];
|
|
82
|
+
declare function warehouseIdByCode(extensions: Record<string, unknown>, code: string): string;
|
|
37
83
|
declare const warehousesFetcher: ShopContextFetcher;
|
|
38
84
|
//#endregion
|
|
39
85
|
//#region src/helpers.d.ts
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
86
|
+
declare const RETURN_ORDER_STATE_MACHINE = "pickware_erp_return_order.state";
|
|
87
|
+
type PickwareReturnState = 'requested' | 'announced' | 'partially_received' | 'received' | 'completed' | 'cancelled' | 'declined';
|
|
88
|
+
declare const RETURN_ORDER_INITIAL_STATE: PickwareReturnState;
|
|
89
|
+
interface BinLocationInput {
|
|
90
|
+
$key?: string;
|
|
91
|
+
code: string;
|
|
92
|
+
warehouseCode: string;
|
|
93
|
+
}
|
|
94
|
+
declare function binLocation(input: BinLocationInput): PickwareBinLocationRecord;
|
|
95
|
+
interface SupplierInput {
|
|
96
|
+
$key?: string;
|
|
97
|
+
number: string;
|
|
98
|
+
name: string;
|
|
99
|
+
customerNumber?: string;
|
|
100
|
+
languageId?: Id;
|
|
101
|
+
}
|
|
102
|
+
declare function supplier(input: SupplierInput): PickwareSupplierRecord;
|
|
103
|
+
interface ProductSupplierConfigInput {
|
|
104
|
+
$key?: string;
|
|
105
|
+
productId: Id;
|
|
106
|
+
supplierId: Id;
|
|
107
|
+
purchasePrices: PickwarePrice[];
|
|
108
|
+
minPurchase?: number;
|
|
109
|
+
purchaseSteps?: number;
|
|
110
|
+
supplierIsDefault?: boolean;
|
|
111
|
+
}
|
|
112
|
+
declare function productSupplierConfig(input: ProductSupplierConfigInput): PickwareProductSupplierConfigurationRecord;
|
|
113
|
+
interface ReturnLineInput {
|
|
114
|
+
name: string;
|
|
43
115
|
quantity: number;
|
|
116
|
+
position?: number;
|
|
117
|
+
reason?: PickwareReturnReason;
|
|
118
|
+
price: object;
|
|
119
|
+
priceDefinition: object;
|
|
120
|
+
productId?: Id;
|
|
121
|
+
orderLineItemId?: Id;
|
|
122
|
+
}
|
|
123
|
+
interface ReturnOrderInput {
|
|
44
124
|
$key?: string;
|
|
125
|
+
number: string;
|
|
126
|
+
orderId: Id;
|
|
127
|
+
price: object;
|
|
128
|
+
state?: PickwareReturnState;
|
|
129
|
+
internalComment?: string;
|
|
130
|
+
warehouseId?: Id;
|
|
131
|
+
lineItems: ReturnLineInput[];
|
|
45
132
|
}
|
|
46
|
-
declare function
|
|
133
|
+
declare function returnOrder(input: ReturnOrderInput): PickwareReturnOrderRecord;
|
|
47
134
|
//#endregion
|
|
48
135
|
//#region src/plugin.d.ts
|
|
49
136
|
declare function pickware(): FakewarePlugin;
|
|
50
137
|
//#endregion
|
|
51
|
-
export { PICKWARE_WAREHOUSES_KEY, type PickwareBinLocationRecord, type
|
|
138
|
+
export { type BinLocationInput, type Id, PICKWARE_LIVE_VERSION, PICKWARE_WAREHOUSES_KEY, type PickwareBinLocationRecord, type PickwarePrice, type PickwareProductSupplierConfigurationRecord, type PickwareReturnOrderLineItemRecord, type PickwareReturnOrderRecord, type PickwareReturnReason, type PickwareReturnState, type PickwareSupplierRecord, type PickwareWarehouseRow, type ProductSupplierConfigInput, RETURN_ORDER_INITIAL_STATE, RETURN_ORDER_STATE_MACHINE, type ReturnLineInput, type ReturnOrderInput, type SupplierInput, binLocation, pickware, pickwareWarehouses, productSupplierConfig, returnOrder, supplier, warehouseIdByCode, warehousesFetcher };
|
|
52
139
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,27 +1,129 @@
|
|
|
1
|
-
import { definePlugin } from "@fakeware/core";
|
|
1
|
+
import { definePlugin, shop, shopToken } from "@fakeware/core";
|
|
2
|
+
//#region src/entities.ts
|
|
3
|
+
const PICKWARE_LIVE_VERSION = "0fa91ce3e96a4bc2be4bd9ce752c3425";
|
|
4
|
+
//#endregion
|
|
2
5
|
//#region src/fetchers.ts
|
|
3
6
|
const PICKWARE_WAREHOUSES_KEY = "pickwareWarehouses";
|
|
7
|
+
const SEARCH_OPERATION = "searchPickwareWarehouse post /search/pickware-erp-warehouse";
|
|
8
|
+
const SEARCH_LIMIT = 500;
|
|
4
9
|
function pickwareWarehouses(extensions) {
|
|
5
10
|
return extensions["pickwareWarehouses"] ?? [];
|
|
6
11
|
}
|
|
12
|
+
function warehouseIdByCode(extensions, code) {
|
|
13
|
+
const warehouses = pickwareWarehouses(extensions);
|
|
14
|
+
const wanted = code.trim().toLowerCase();
|
|
15
|
+
const match = warehouses.find((w) => w.code?.trim().toLowerCase() === wanted);
|
|
16
|
+
if (!match) {
|
|
17
|
+
const known = warehouses.map((w) => w.code).filter(Boolean).join(", ") || "(none)";
|
|
18
|
+
throw new Error(`pickware: no warehouse with code "${code}". Available warehouse codes: ${known}.`);
|
|
19
|
+
}
|
|
20
|
+
return match.id;
|
|
21
|
+
}
|
|
22
|
+
function rowsOf(raw) {
|
|
23
|
+
let value = raw;
|
|
24
|
+
while (value && typeof value === "object" && !Array.isArray(value) && "data" in value) value = value.data;
|
|
25
|
+
return Array.isArray(value) ? value : [];
|
|
26
|
+
}
|
|
27
|
+
function totalOf(raw) {
|
|
28
|
+
let value = raw;
|
|
29
|
+
while (value && typeof value === "object" && !Array.isArray(value)) {
|
|
30
|
+
const record = value;
|
|
31
|
+
if (typeof record.total === "number") return record.total;
|
|
32
|
+
if (!("data" in record)) break;
|
|
33
|
+
value = record.data;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
7
36
|
const warehousesFetcher = {
|
|
8
37
|
entity: "pickware warehouses",
|
|
9
|
-
fetch: (client) =>
|
|
38
|
+
fetch: async (client) => {
|
|
39
|
+
const invoke = client.invoke;
|
|
40
|
+
const collected = [];
|
|
41
|
+
let page = 1;
|
|
42
|
+
for (;;) {
|
|
43
|
+
const raw = await invoke(SEARCH_OPERATION, { body: {
|
|
44
|
+
page,
|
|
45
|
+
limit: SEARCH_LIMIT,
|
|
46
|
+
"total-count-mode": 1
|
|
47
|
+
} });
|
|
48
|
+
const pageRows = rowsOf(raw);
|
|
49
|
+
collected.push(...pageRows);
|
|
50
|
+
const total = totalOf(raw);
|
|
51
|
+
if (pageRows.length === 0) break;
|
|
52
|
+
if (total !== void 0 && collected.length >= total) break;
|
|
53
|
+
if (total === void 0 && pageRows.length < SEARCH_LIMIT) break;
|
|
54
|
+
page += 1;
|
|
55
|
+
}
|
|
56
|
+
return { data: collected };
|
|
57
|
+
},
|
|
10
58
|
merge: (data, raw) => {
|
|
11
|
-
|
|
12
|
-
data.extensions[PICKWARE_WAREHOUSES_KEY] = rows;
|
|
59
|
+
data.extensions[PICKWARE_WAREHOUSES_KEY] = rowsOf(raw);
|
|
13
60
|
}
|
|
14
61
|
};
|
|
15
62
|
//#endregion
|
|
16
63
|
//#region src/helpers.ts
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
64
|
+
const RETURN_ORDER_STATE_MACHINE = "pickware_erp_return_order.state";
|
|
65
|
+
const RETURN_ORDER_INITIAL_STATE = "requested";
|
|
66
|
+
function pruneUndefined(record) {
|
|
67
|
+
for (const key of Object.keys(record)) if (record[key] === void 0) delete record[key];
|
|
68
|
+
return record;
|
|
69
|
+
}
|
|
70
|
+
function binLocation(input) {
|
|
71
|
+
return pruneUndefined({
|
|
72
|
+
$key: input.$key,
|
|
73
|
+
code: input.code,
|
|
74
|
+
warehouseId: shopToken(`pickwareWarehouse:${input.warehouseCode}`, (s) => warehouseIdByCode(s.extensions, input.warehouseCode))
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function supplier(input) {
|
|
78
|
+
return pruneUndefined({
|
|
79
|
+
$key: input.$key,
|
|
80
|
+
number: input.number,
|
|
81
|
+
name: input.name,
|
|
82
|
+
customerNumber: input.customerNumber,
|
|
83
|
+
languageId: input.languageId ?? shop.defaultLanguage
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function productSupplierConfig(input) {
|
|
87
|
+
return pruneUndefined({
|
|
88
|
+
$key: input.$key,
|
|
21
89
|
productId: input.productId,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
90
|
+
productVersionId: PICKWARE_LIVE_VERSION,
|
|
91
|
+
supplierId: input.supplierId,
|
|
92
|
+
minPurchase: input.minPurchase ?? 1,
|
|
93
|
+
purchaseSteps: input.purchaseSteps ?? 1,
|
|
94
|
+
purchasePrices: input.purchasePrices,
|
|
95
|
+
supplierIsDefault: input.supplierIsDefault ?? true
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function returnLine(line, index) {
|
|
99
|
+
return pruneUndefined({
|
|
100
|
+
versionId: PICKWARE_LIVE_VERSION,
|
|
101
|
+
type: "product",
|
|
102
|
+
name: line.name,
|
|
103
|
+
quantity: line.quantity,
|
|
104
|
+
position: line.position ?? index + 1,
|
|
105
|
+
reason: line.reason ?? "other",
|
|
106
|
+
priceDefinition: line.priceDefinition,
|
|
107
|
+
price: line.price,
|
|
108
|
+
productId: line.productId,
|
|
109
|
+
productVersionId: line.productId ? PICKWARE_LIVE_VERSION : void 0,
|
|
110
|
+
orderLineItemId: line.orderLineItemId,
|
|
111
|
+
orderLineItemVersionId: line.orderLineItemId ? PICKWARE_LIVE_VERSION : void 0
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function returnOrder(input) {
|
|
115
|
+
return pruneUndefined({
|
|
116
|
+
$key: input.$key,
|
|
117
|
+
versionId: PICKWARE_LIVE_VERSION,
|
|
118
|
+
number: input.number,
|
|
119
|
+
stateId: shop.stateMachineState(RETURN_ORDER_STATE_MACHINE, input.state ?? "requested"),
|
|
120
|
+
orderId: input.orderId,
|
|
121
|
+
orderVersionId: PICKWARE_LIVE_VERSION,
|
|
122
|
+
price: input.price,
|
|
123
|
+
internalComment: input.internalComment,
|
|
124
|
+
warehouseId: input.warehouseId,
|
|
125
|
+
lineItems: input.lineItems.map(returnLine)
|
|
126
|
+
});
|
|
25
127
|
}
|
|
26
128
|
//#endregion
|
|
27
129
|
//#region src/plugin.ts
|
|
@@ -32,6 +134,6 @@ function pickware() {
|
|
|
32
134
|
});
|
|
33
135
|
}
|
|
34
136
|
//#endregion
|
|
35
|
-
export { PICKWARE_WAREHOUSES_KEY, pickware, pickwareWarehouses,
|
|
137
|
+
export { PICKWARE_LIVE_VERSION, PICKWARE_WAREHOUSES_KEY, RETURN_ORDER_INITIAL_STATE, RETURN_ORDER_STATE_MACHINE, binLocation, pickware, pickwareWarehouses, productSupplierConfig, returnOrder, supplier, warehouseIdByCode, warehousesFetcher };
|
|
36
138
|
|
|
37
139
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/fetchers.ts","../src/helpers.ts","../src/plugin.ts"],"sourcesContent":["import type { ShopContextFetcher } from '@fakeware/core'\n\nexport interface PickwareWarehouseRow {\n id: string\n name?: string\n code?: string\n [key: string]: unknown\n}\n\nexport const PICKWARE_WAREHOUSES_KEY = 'pickwareWarehouses'\n\nexport function pickwareWarehouses(extensions: Record<string, unknown>): PickwareWarehouseRow[] {\n return (extensions[PICKWARE_WAREHOUSES_KEY] as PickwareWarehouseRow[] | undefined) ?? []\n}\n\nexport const warehousesFetcher: ShopContextFetcher = {\n entity: 'pickware warehouses',\n fetch: (client) =>\n (client.invoke as (path: string, params: unknown) => Promise<unknown>)(\n 'post /search/pickware-erp-warehouse',\n { body: { limit: 500 } },\n ),\n merge: (data, raw) => {\n const rows = (raw as { data?: PickwareWarehouseRow[] } | null)?.data ?? []\n data.extensions[PICKWARE_WAREHOUSES_KEY] = rows\n },\n}\n","import type { PickwareStockMovementRecord } from './entities'\n\nexport interface StockMovementInInput {\n productId: string\n warehouseId: string\n quantity: number\n $key?: string\n}\n\nexport function stockMovementIn(input: StockMovementInInput): PickwareStockMovementRecord {\n if (!Number.isFinite(input.quantity) || input.quantity <= 0) {\n throw new Error(`stockMovementIn: quantity must be a positive number, got ${input.quantity}.`)\n }\n return {\n ...(input.$key ? { $key: input.$key } : {}),\n productId: input.productId,\n quantity: input.quantity,\n destinationWarehouseId: input.warehouseId,\n }\n}\n","import { definePlugin, type FakewarePlugin } from '@fakeware/core'\nimport { warehousesFetcher } from './fetchers'\n\nexport function pickware(): FakewarePlugin {\n return definePlugin({\n name: 'pickware',\n fetchers: [warehousesFetcher],\n })\n}\n"],"mappings":";;AASA,MAAa,0BAA0B;AAEvC,SAAgB,mBAAmB,YAA6D;CAC9F,OAAQ,WAAA,yBAA8E,CAAC;AACzF;AAEA,MAAa,oBAAwC;CACnD,QAAQ;CACR,QAAQ,WACL,OAAO,OACN,uCACA,EAAE,MAAM,EAAE,OAAO,IAAI,EAAE,CACzB;CACF,QAAQ,MAAM,QAAQ;EACpB,MAAM,OAAQ,KAAkD,QAAQ,CAAC;EACzE,KAAK,WAAW,2BAA2B;CAC7C;AACF;;;ACjBA,SAAgB,gBAAgB,OAA0D;CACxF,IAAI,CAAC,OAAO,SAAS,MAAM,QAAQ,KAAK,MAAM,YAAY,GACxD,MAAM,IAAI,MAAM,4DAA4D,MAAM,SAAS,EAAE;CAE/F,OAAO;EACL,GAAI,MAAM,OAAO,EAAE,MAAM,MAAM,KAAK,IAAI,CAAC;EACzC,WAAW,MAAM;EACjB,UAAU,MAAM;EAChB,wBAAwB,MAAM;CAChC;AACF;;;AChBA,SAAgB,WAA2B;CACzC,OAAO,aAAa;EAClB,MAAM;EACN,UAAU,CAAC,iBAAiB;CAC9B,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/entities.ts","../src/fetchers.ts","../src/helpers.ts","../src/plugin.ts"],"sourcesContent":["import type { AnyToken } from '@fakeware/core'\n\nexport const PICKWARE_LIVE_VERSION = '0fa91ce3e96a4bc2be4bd9ce752c3425'\n\nexport type Id = string | AnyToken\n\nexport interface PickwareBinLocationRecord {\n $key?: string\n code: string\n warehouseId: Id\n}\n\nexport interface PickwareSupplierRecord {\n $key?: string\n number: string\n name: string\n languageId: Id\n customerNumber?: string\n}\n\nexport interface PickwarePrice {\n currencyId: Id\n gross: number\n net: number\n linked: boolean\n}\n\nexport interface PickwareProductSupplierConfigurationRecord {\n $key?: string\n productId: Id\n productVersionId?: string\n supplierId: Id\n minPurchase: number\n purchaseSteps: number\n purchasePrices: PickwarePrice[]\n supplierIsDefault: boolean\n}\n\nexport type PickwareReturnReason = 'wrong_item' | 'defective' | 'other'\n\nexport interface PickwareReturnOrderLineItemRecord {\n $key?: string\n versionId?: string\n type?: string\n name: string\n quantity: number\n position: number\n reason: PickwareReturnReason\n priceDefinition: object\n price: object\n productId?: Id\n productVersionId?: string\n orderLineItemId?: Id\n orderLineItemVersionId?: string\n}\n\nexport interface PickwareReturnOrderRecord {\n $key?: string\n versionId?: string\n number: string\n stateId?: Id\n orderId: Id\n orderVersionId?: string\n price: object\n shippingCosts?: object\n internalComment?: string\n warehouseId?: Id\n lineItems: PickwareReturnOrderLineItemRecord[]\n}\n\ndeclare module '@fakeware/core' {\n interface EntityRegistry {\n pickware_erp_bin_location: PickwareBinLocationRecord\n pickware_erp_supplier: PickwareSupplierRecord\n pickware_erp_product_supplier_configuration: PickwareProductSupplierConfigurationRecord\n pickware_erp_return_order: PickwareReturnOrderRecord\n pickware_erp_return_order_line_item: PickwareReturnOrderLineItemRecord\n }\n}\n","import type { ShopContextFetcher } from '@fakeware/core'\n\nexport interface PickwareWarehouseRow {\n id: string\n name?: string\n code?: string\n [key: string]: unknown\n}\n\nexport const PICKWARE_WAREHOUSES_KEY = 'pickwareWarehouses'\n\nconst SEARCH_OPERATION = 'searchPickwareWarehouse post /search/pickware-erp-warehouse'\nconst SEARCH_LIMIT = 500\n\nexport function pickwareWarehouses(extensions: Record<string, unknown>): PickwareWarehouseRow[] {\n return (extensions[PICKWARE_WAREHOUSES_KEY] as PickwareWarehouseRow[] | undefined) ?? []\n}\n\nexport function warehouseIdByCode(extensions: Record<string, unknown>, code: string): string {\n const warehouses = pickwareWarehouses(extensions)\n const wanted = code.trim().toLowerCase()\n const match = warehouses.find((w) => w.code?.trim().toLowerCase() === wanted)\n if (!match) {\n const known =\n warehouses\n .map((w) => w.code)\n .filter(Boolean)\n .join(', ') || '(none)'\n throw new Error(\n `pickware: no warehouse with code \"${code}\". Available warehouse codes: ${known}.`,\n )\n }\n return match.id\n}\n\nfunction rowsOf(raw: unknown): unknown[] {\n let value = raw\n while (value && typeof value === 'object' && !Array.isArray(value) && 'data' in value) {\n value = (value as { data?: unknown }).data\n }\n return Array.isArray(value) ? value : []\n}\n\nfunction totalOf(raw: unknown): number | undefined {\n let value = raw\n while (value && typeof value === 'object' && !Array.isArray(value)) {\n const record = value as { total?: unknown; data?: unknown }\n if (typeof record.total === 'number') return record.total\n if (!('data' in record)) break\n value = record.data\n }\n return undefined\n}\n\ntype Invoke = (operation: string, options: { body: Record<string, unknown> }) => Promise<unknown>\n\nexport const warehousesFetcher: ShopContextFetcher = {\n entity: 'pickware warehouses',\n fetch: async (client) => {\n const invoke = client.invoke as unknown as Invoke\n const collected: unknown[] = []\n let page = 1\n for (;;) {\n const raw = await invoke(SEARCH_OPERATION, {\n body: { page, limit: SEARCH_LIMIT, 'total-count-mode': 1 },\n })\n const pageRows = rowsOf(raw)\n collected.push(...pageRows)\n const total = totalOf(raw)\n if (pageRows.length === 0) break\n if (total !== undefined && collected.length >= total) break\n if (total === undefined && pageRows.length < SEARCH_LIMIT) break\n page += 1\n }\n return { data: collected }\n },\n merge: (data, raw) => {\n data.extensions[PICKWARE_WAREHOUSES_KEY] = rowsOf(raw) as PickwareWarehouseRow[]\n },\n}\n","import { shop, shopToken } from '@fakeware/core'\nimport {\n type Id,\n PICKWARE_LIVE_VERSION,\n type PickwareBinLocationRecord,\n type PickwarePrice,\n type PickwareProductSupplierConfigurationRecord,\n type PickwareReturnOrderLineItemRecord,\n type PickwareReturnOrderRecord,\n type PickwareReturnReason,\n type PickwareSupplierRecord,\n} from './entities'\nimport { warehouseIdByCode } from './fetchers'\n\nexport const RETURN_ORDER_STATE_MACHINE = 'pickware_erp_return_order.state'\n\nexport type PickwareReturnState =\n | 'requested'\n | 'announced'\n | 'partially_received'\n | 'received'\n | 'completed'\n | 'cancelled'\n | 'declined'\n\nexport const RETURN_ORDER_INITIAL_STATE: PickwareReturnState = 'requested'\n\nfunction pruneUndefined<T extends Record<string, unknown>>(record: T): T {\n for (const key of Object.keys(record)) {\n if (record[key] === undefined) delete record[key]\n }\n return record\n}\n\nexport interface BinLocationInput {\n $key?: string\n code: string\n warehouseCode: string\n}\n\nexport function binLocation(input: BinLocationInput): PickwareBinLocationRecord {\n return pruneUndefined({\n $key: input.$key,\n code: input.code,\n warehouseId: shopToken(`pickwareWarehouse:${input.warehouseCode}`, (s) =>\n warehouseIdByCode(s.extensions, input.warehouseCode),\n ),\n })\n}\n\nexport interface SupplierInput {\n $key?: string\n number: string\n name: string\n customerNumber?: string\n languageId?: Id\n}\n\nexport function supplier(input: SupplierInput): PickwareSupplierRecord {\n return pruneUndefined({\n $key: input.$key,\n number: input.number,\n name: input.name,\n customerNumber: input.customerNumber,\n languageId: input.languageId ?? shop.defaultLanguage,\n })\n}\n\nexport interface ProductSupplierConfigInput {\n $key?: string\n productId: Id\n supplierId: Id\n purchasePrices: PickwarePrice[]\n minPurchase?: number\n purchaseSteps?: number\n supplierIsDefault?: boolean\n}\n\nexport function productSupplierConfig(\n input: ProductSupplierConfigInput,\n): PickwareProductSupplierConfigurationRecord {\n return pruneUndefined({\n $key: input.$key,\n productId: input.productId,\n productVersionId: PICKWARE_LIVE_VERSION,\n supplierId: input.supplierId,\n minPurchase: input.minPurchase ?? 1,\n purchaseSteps: input.purchaseSteps ?? 1,\n purchasePrices: input.purchasePrices,\n supplierIsDefault: input.supplierIsDefault ?? true,\n })\n}\n\nexport interface ReturnLineInput {\n name: string\n quantity: number\n position?: number\n reason?: PickwareReturnReason\n price: object\n priceDefinition: object\n productId?: Id\n orderLineItemId?: Id\n}\n\nexport interface ReturnOrderInput {\n $key?: string\n number: string\n orderId: Id\n price: object\n state?: PickwareReturnState\n internalComment?: string\n warehouseId?: Id\n lineItems: ReturnLineInput[]\n}\n\nfunction returnLine(line: ReturnLineInput, index: number): PickwareReturnOrderLineItemRecord {\n return pruneUndefined({\n versionId: PICKWARE_LIVE_VERSION,\n type: 'product',\n name: line.name,\n quantity: line.quantity,\n position: line.position ?? index + 1,\n reason: line.reason ?? 'other',\n priceDefinition: line.priceDefinition,\n price: line.price,\n productId: line.productId,\n productVersionId: line.productId ? PICKWARE_LIVE_VERSION : undefined,\n orderLineItemId: line.orderLineItemId,\n orderLineItemVersionId: line.orderLineItemId ? PICKWARE_LIVE_VERSION : undefined,\n })\n}\n\nexport function returnOrder(input: ReturnOrderInput): PickwareReturnOrderRecord {\n return pruneUndefined({\n $key: input.$key,\n versionId: PICKWARE_LIVE_VERSION,\n number: input.number,\n stateId: shop.stateMachineState(\n RETURN_ORDER_STATE_MACHINE,\n input.state ?? RETURN_ORDER_INITIAL_STATE,\n ),\n orderId: input.orderId,\n orderVersionId: PICKWARE_LIVE_VERSION,\n price: input.price,\n internalComment: input.internalComment,\n warehouseId: input.warehouseId,\n lineItems: input.lineItems.map(returnLine),\n })\n}\n","import { definePlugin, type FakewarePlugin } from '@fakeware/core'\nimport { warehousesFetcher } from './fetchers'\n\nexport function pickware(): FakewarePlugin {\n return definePlugin({\n name: 'pickware',\n fetchers: [warehousesFetcher],\n })\n}\n"],"mappings":";;AAEA,MAAa,wBAAwB;;;ACOrC,MAAa,0BAA0B;AAEvC,MAAM,mBAAmB;AACzB,MAAM,eAAe;AAErB,SAAgB,mBAAmB,YAA6D;CAC9F,OAAQ,WAAA,yBAA8E,CAAC;AACzF;AAEA,SAAgB,kBAAkB,YAAqC,MAAsB;CAC3F,MAAM,aAAa,mBAAmB,UAAU;CAChD,MAAM,SAAS,KAAK,KAAK,CAAC,CAAC,YAAY;CACvC,MAAM,QAAQ,WAAW,MAAM,MAAM,EAAE,MAAM,KAAK,CAAC,CAAC,YAAY,MAAM,MAAM;CAC5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AA,WACR;EACA,SAAS,MAAM;EACf,gBAAgB;EAChB,OAAO,MAAM;EACb,iBAAiB,MAAM;EACvB,aAAa,MAAM;EACnB,WAAW,MAAM,UAAU,IAAI,UAAU;CAC3C,CAAC;AACH;;;ACjJA,SAAgB,WAA2B;CACzC,OAAO,aAAa;EAClB,MAAM;EACN,UAAU,CAAC,iBAAiB;CAC9B,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fakeware/plugin-pickware",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Pickware ERP plugin for fakeware. Seed
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Pickware ERP plugin for fakeware. Seed bin locations, suppliers, product-supplier configurations and return orders into a Shopware 6 shop running Pickware",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@biomejs/biome": "2.4.16",
|
|
49
|
-
"@fakeware/core": "0.0.
|
|
49
|
+
"@fakeware/core": "^0.0.10",
|
|
50
50
|
"@types/bun": "1.3.14",
|
|
51
51
|
"publint": "0.3.21",
|
|
52
|
-
"tsdown": "^0.22.
|
|
52
|
+
"tsdown": "^0.22.3",
|
|
53
53
|
"typescript": "^6.0.3"
|
|
54
54
|
}
|
|
55
55
|
}
|