@fakeware/plugin-pickware 0.0.1 → 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/README.md CHANGED
@@ -2,139 +2,3 @@
2
2
 
3
3
  A [fakeware](https://github.com/fakeware-sh/fakeware) plugin for **Pickware ERP** —
4
4
  seed warehouses, bin locations, and stock into a Shopware 6 shop running Pickware.
5
-
6
- It teaches fakeware about Pickware's DAL entities so you can author them with
7
- `define(...)` in your data files, and contributes a fetcher that loads the shop's
8
- existing warehouses into the run context.
9
-
10
- > **Status: minimal v1.** Covers `pickware_erp_warehouse`, `pickware_erp_bin_location`,
11
- > and `pickware_erp_stock_movement`. Suppliers, purchasing, stocktakes, and the
12
- > WMS/POS/Shipping entities are intentionally out of scope for now.
13
-
14
- ## Install
15
-
16
- ```sh
17
- bun add -D @fakeware/plugin-pickware
18
- # @fakeware/core is a peer dependency — your fakeware project already has it.
19
- ```
20
-
21
- ## Usage
22
-
23
- Register the plugin in `fakeware.config.ts`:
24
-
25
- ```ts
26
- import { defineConfig } from '@fakeware/core/config'
27
- import { pickware } from '@fakeware/plugin-pickware'
28
-
29
- export default defineConfig({
30
- shopware: {
31
- url: process.env.SHOPWARE_URL!,
32
- clientId: process.env.SHOPWARE_CLIENT_ID!,
33
- clientSecret: process.env.SHOPWARE_CLIENT_SECRET!,
34
- },
35
- plugins: [pickware()],
36
- })
37
- ```
38
-
39
- Author Pickware data in `data/*.ts`. Importing the package augments fakeware's
40
- `EntityRegistry`, so the `pickware_erp_*` entity names are fully type-checked:
41
-
42
- `data/pickware.ts`:
43
-
44
- ```ts
45
- import { define, ref } from '@fakeware/core'
46
- import { stockMovementIn } from '@fakeware/plugin-pickware'
47
-
48
- define('pickware_erp_warehouse', { $key: 'main', name: 'Main', code: 'WH-01' })
49
-
50
- define('pickware_erp_bin_location', {
51
- $key: 'a1',
52
- code: 'A1',
53
- warehouseId: ref('pickware_erp_warehouse/main'),
54
- })
55
-
56
- define(
57
- 'pickware_erp_stock_movement',
58
- stockMovementIn({
59
- productId: ref('product/my-product'),
60
- warehouseId: ref('pickware_erp_warehouse/main'),
61
- quantity: 100,
62
- }),
63
- )
64
- ```
65
-
66
- Bin locations referencing a warehouse via `ref()` are written after it
67
- automatically. Seed stock through `pickware_erp_stock_movement` (an append-only
68
- ledger) — never write `product.stock` directly while Pickware is active.
69
-
70
- Run it with the fakeware CLI:
71
-
72
- ```sh
73
- fakeware up --dry-run
74
- fakeware up
75
- ```
76
-
77
- ### Referencing existing warehouses
78
-
79
- `pickware()` adds a fetcher that loads the shop's current warehouses into the run
80
- context. Read them in a plugin `setup` hook or any code with access to the context:
81
-
82
- ```ts
83
- import { pickwareWarehouses } from '@fakeware/plugin-pickware'
84
-
85
- const existing = pickwareWarehouses(shopContext.extensions)
86
- const main = existing.find((w) => w.code === 'WH-01')
87
- ```
88
-
89
- ## ⚠️ Verify field names against your install
90
-
91
- Pickware publishes **no Shopware 6 API documentation**, so the entity *field
92
- names* in this plugin (especially `destinationWarehouseId` on the stock movement)
93
- are best-effort. **Before a live `up`, confirm them against your shop:**
94
-
95
- ```sh
96
- curl -H "Authorization: Bearer <token>" \
97
- https://your-shop.example/api/_info/entity-schema.json \
98
- | jq 'keys | map(select(startswith("pickware_erp")))'
99
- ```
100
-
101
- Inspect the `pickware_erp_warehouse`, `pickware_erp_bin_location`, and
102
- `pickware_erp_stock_movement` field definitions there (or watch the Pickware
103
- admin module's network requests) and adjust the record shapes in
104
- `src/entities.ts` / the `stockMovementIn` helper to match.
105
-
106
- Key facts the plugin is built around:
107
-
108
- - Stock is owned by Pickware's **append-only ledger** (`pickware_erp_stock_movement`).
109
- You change stock by **adding movements**; Pickware recomputes
110
- `pickware_erp_stock` and mirrors the total back into `product.stock`.
111
- - Writing `product.stock` directly via the standard API while Pickware is active
112
- **nulls** the Pickware warehouses — don't do it.
113
-
114
- ## Publishing
115
-
116
- This repo publishes `@fakeware/plugin-pickware` to npm via
117
- [release-please](https://github.com/googleapis/release-please) — the same flow as
118
- the fakeware monorepo. Conventional commits on `main` open a release PR; merging
119
- it tags a version and publishes.
120
-
121
- **One-time repo setup** (in GitHub → Settings):
122
-
123
- - Add an npm publish credential for the `@fakeware` scope. The release workflow
124
- uses npm provenance (`id-token: write`) — configure a trusted publisher on npm,
125
- or add an `NPM_TOKEN` secret and wire it into `.github/workflows/release.yml`.
126
- - The default `GITHUB_TOKEN` is sufficient for release-please's PR/tagging.
127
-
128
- ## Development
129
-
130
- ```sh
131
- bun install
132
- bun run build
133
- bun run typecheck
134
- bun test
135
- bun run check
136
- ```
137
-
138
- ## License
139
-
140
- MIT
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
- interface PickwareWarehouseRecord {
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 PickwareBinLocationRecord {
11
+ interface PickwareSupplierRecord {
10
12
  $key?: string;
11
- code: string;
12
- warehouseId: string;
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 PickwareStockMovementRecord {
24
+ interface PickwareProductSupplierConfigurationRecord {
15
25
  $key?: string;
16
- productId: string;
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
- destinationWarehouseId: string;
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
- pickware_erp_stock_movement: PickwareStockMovementRecord;
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
- interface StockMovementInInput {
41
- productId: string;
42
- warehouseId: string;
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 stockMovementIn(input: StockMovementInInput): PickwareStockMovementRecord;
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 PickwareStockMovementRecord, type PickwareWarehouseRecord, type PickwareWarehouseRow, type StockMovementInInput, pickware, pickwareWarehouses, stockMovementIn, warehousesFetcher };
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) => client.invoke("post /search/pickware-erp-warehouse", { body: { limit: 500 } }),
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
- const rows = raw?.data ?? [];
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
- function stockMovementIn(input) {
18
- if (!Number.isFinite(input.quantity) || input.quantity <= 0) throw new Error(`stockMovementIn: quantity must be a positive number, got ${input.quantity}.`);
19
- return {
20
- ...input.$key ? { $key: input.$key } : {},
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
- quantity: input.quantity,
23
- destinationWarehouseId: input.warehouseId
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, stockMovementIn, warehousesFetcher };
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
@@ -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;CAC5E,IAAI,CAAC,OAAO;EACV,MAAM,QACJ,WACG,KAAK,MAAM,EAAE,IAAI,CAAC,CAClB,OAAO,OAAO,CAAC,CACf,KAAK,IAAI,KAAK;EACnB,MAAM,IAAI,MACR,qCAAqC,KAAK,gCAAgC,MAAM,EAClF;CACF;CACA,OAAO,MAAM;AACf;AAEA,SAAS,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AC,iBAAiB;CAC9B,CAAC;AACH"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fakeware/plugin-pickware",
3
- "version": "0.0.1",
4
- "description": "Pickware ERP plugin for fakeware. Seed warehouses, bin locations and stock into a Shopware 6 shop running Pickware",
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.9",
49
+ "@fakeware/core": "^0.0.10",
50
50
  "@types/bun": "1.3.14",
51
51
  "publint": "0.3.21",
52
- "tsdown": "^0.22.2",
52
+ "tsdown": "^0.22.3",
53
53
  "typescript": "^6.0.3"
54
54
  }
55
55
  }