@tallyui/connector-vendure 3.9.2 → 3.11.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.ts CHANGED
@@ -192,8 +192,10 @@ interface VendureOrder extends VendureOrderSummary {
192
192
  quantity: number;
193
193
  orderPlacedQuantity: number;
194
194
  proratedUnitPrice: number;
195
- /** Vendure's per-unit value used in refund calculations, which the till sums for `order.refund`'s `totalMinor` (ADR-080). */
195
+ /** Vendure's per-unit refund value, rounded per unit: for display, never multiplied by a quantity for `order.refund`'s `totalMinor` (ADR-080 amendment 2). */
196
196
  proratedUnitPriceWithTax: number;
197
+ /** The line's total with tax after order-level discounts; a refund's line amount is its share of this (vendurepos ADR 0007, decision 4.9). */
198
+ proratedLinePriceWithTax: number;
197
199
  taxRate: number;
198
200
  productVariant: {
199
201
  id: string;
@@ -294,7 +296,9 @@ interface VendureRefundableLine {
294
296
  refundedQuantity: number;
295
297
  cancelledQuantity: number;
296
298
  refundableQuantity: number;
299
+ /** @deprecated For display only; a refund's amount is vendureLineRefundWithTax. */
297
300
  unitRefundWithTax: number;
301
+ lineTotalWithTax: number;
298
302
  }
299
303
  interface VendureRefundable {
300
304
  lines: VendureRefundableLine[];
@@ -307,6 +311,12 @@ interface VendureRefundable {
307
311
  * Amounts are Vendure's minor units with tax.
308
312
  */
309
313
  declare function vendureRefundable(order: Pick<VendureOrder, 'lines' | 'shippingWithTax' | 'payments'>): VendureRefundable;
314
+ /**
315
+ * The amount, with tax, of refunding `quantity` more units of a line: its cumulative share of the line total
316
+ * (vendurepos ADR 0007, decision 4.9), the plugin's own rule for `amount_mismatch`. Refunding every refundable unit
317
+ * returns what is left of `lineTotalWithTax`, and partial refunds add up to it.
318
+ */
319
+ declare function vendureLineRefundWithTax(line: VendureRefundableLine, quantity: number): number;
310
320
 
311
321
  /**
312
322
  * Vendure connector for Tally UI. Build one per store session, anew on each sign-in or store change:
@@ -345,4 +355,4 @@ declare const createVendureConnector: (options?: {
345
355
  */
346
356
  declare const vendureConnector: TallyConnector;
347
357
 
348
- export { type VendureCredentialKind, type VendureCredentials, type VendureOrder, type VendureOrderList, type VendureOrderListOptions, type VendureOrderSummary, type VendureRefundable, type VendureRefundableLine, VendureTimezoneConfigError, createVendureConnector, createVendureCustomer, createVendureProductReplication, createVendureVariantFeedReplication, getVendureCustomer, getVendureOrder, listVendureOrders, searchVendureCustomers, toVendureCustomer, vendureAuth, vendureAuthFieldSets, vendureConnector, vendureGlobalStockSettings, vendureProductReplication, vendureProductSchema, vendureProductSync, vendureProductTraits, vendureRefundable, vendureSignIn, vendureStockReconcile, vendureStoreSettings };
358
+ export { type VendureCredentialKind, type VendureCredentials, type VendureOrder, type VendureOrderList, type VendureOrderListOptions, type VendureOrderSummary, type VendureRefundable, type VendureRefundableLine, VendureTimezoneConfigError, createVendureConnector, createVendureCustomer, createVendureProductReplication, createVendureVariantFeedReplication, getVendureCustomer, getVendureOrder, listVendureOrders, searchVendureCustomers, toVendureCustomer, vendureAuth, vendureAuthFieldSets, vendureConnector, vendureGlobalStockSettings, vendureLineRefundWithTax, vendureProductReplication, vendureProductSchema, vendureProductSync, vendureProductTraits, vendureRefundable, vendureSignIn, vendureStockReconcile, vendureStoreSettings };
package/dist/index.js CHANGED
@@ -978,7 +978,7 @@ var ORDER_DETAIL_FIELDS_START = `
978
978
  customer { id firstName lastName emailAddress }
979
979
  lines {`;
980
980
  var ORDER_DETAIL_FIELDS_END = `
981
- id quantity orderPlacedQuantity proratedUnitPrice proratedUnitPriceWithTax taxRate productVariant { id name sku }
981
+ id quantity orderPlacedQuantity proratedUnitPrice proratedUnitPriceWithTax proratedLinePriceWithTax taxRate productVariant { id name sku }
982
982
  unitPrice unitPriceWithTax linePrice linePriceWithTax discountedLinePrice discountedLinePriceWithTax
983
983
  discounts { description amount amountWithTax }
984
984
  }
@@ -1078,13 +1078,23 @@ function vendureRefundable(order) {
1078
1078
  refundedQuantity,
1079
1079
  cancelledQuantity: Number.isFinite(line.orderPlacedQuantity) ? Math.max(0, line.orderPlacedQuantity - quantity) : 0,
1080
1080
  refundableQuantity: Math.max(0, quantity - refundedQuantity),
1081
- unitRefundWithTax: Number.isFinite(line.proratedUnitPriceWithTax) ? line.proratedUnitPriceWithTax : 0
1081
+ unitRefundWithTax: Number.isFinite(line.proratedUnitPriceWithTax) ? line.proratedUnitPriceWithTax : 0,
1082
+ lineTotalWithTax: Number.isFinite(line.proratedLinePriceWithTax) ? line.proratedLinePriceWithTax : 0
1082
1083
  };
1083
1084
  }),
1084
1085
  shippingWithTax: Math.max(0, (Number.isFinite(order.shippingWithTax) ? order.shippingWithTax : 0) - refundedShipping),
1085
1086
  moneyWithTax
1086
1087
  };
1087
1088
  }
1089
+ function vendureLineRefundWithTax(line, quantity) {
1090
+ if (!Number.isInteger(quantity) || quantity < 1 || quantity > line.refundableQuantity) {
1091
+ throw new RangeError(`Line ${line.orderLineId}: quantity ${quantity} must be a whole number from 1 to refundable quantity ${line.refundableQuantity}`);
1092
+ }
1093
+ const N = line.quantity;
1094
+ const T = line.lineTotalWithTax;
1095
+ const r = line.refundedQuantity;
1096
+ return Math.round((r + quantity) * T / N) - Math.round(r * T / N);
1097
+ }
1088
1098
 
1089
1099
  // src/index.ts
1090
1100
  import { ConnectorUnauthorizedError as ConnectorUnauthorizedError6 } from "@tallyui/core";
@@ -1152,6 +1162,7 @@ export {
1152
1162
  vendureAuthFieldSets,
1153
1163
  vendureConnector,
1154
1164
  vendureGlobalStockSettings,
1165
+ vendureLineRefundWithTax,
1155
1166
  vendureProductReplication,
1156
1167
  vendureProductSchema,
1157
1168
  vendureProductSync,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/connector-vendure",
3
- "version": "3.9.2",
3
+ "version": "3.11.0",
4
4
  "type": "module",
5
5
  "description": "Vendure connector for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -27,11 +27,11 @@
27
27
  "directory": "connectors/vendure"
28
28
  },
29
29
  "peerDependencies": {
30
- "@tallyui/core": "^3.9.2"
30
+ "@tallyui/core": "^3.11.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@tallyui/database": "3.9.2",
34
- "@tallyui/pos": "3.9.2",
33
+ "@tallyui/database": "3.11.0",
34
+ "@tallyui/pos": "3.11.0",
35
35
  "rxdb": "17.5.0"
36
36
  },
37
37
  "scripts": {
package/src/index.ts CHANGED
@@ -115,7 +115,7 @@ export { vendureStoreSettings } from './store-settings';
115
115
  export { vendureGlobalStockSettings } from './global-settings';
116
116
  export { searchVendureCustomers, createVendureCustomer, getVendureCustomer, toVendureCustomer } from './customers';
117
117
  export { listVendureOrders, getVendureOrder, type VendureOrderListOptions, type VendureOrderList, type VendureOrderSummary, type VendureOrder } from './orders';
118
- export { vendureRefundable, type VendureRefundableLine, type VendureRefundable } from './refunds';
118
+ export { vendureRefundable, vendureLineRefundWithTax, type VendureRefundableLine, type VendureRefundable } from './refunds';
119
119
 
120
120
  export { ConnectorUnauthorizedError } from '@tallyui/core';
121
121
  export { VendureTimezoneConfigError } from './replication/products';
package/src/orders.ts CHANGED
@@ -53,8 +53,10 @@ export interface VendureOrder extends VendureOrderSummary {
53
53
  quantity: number;
54
54
  orderPlacedQuantity: number;
55
55
  proratedUnitPrice: number;
56
- /** Vendure's per-unit value used in refund calculations, which the till sums for `order.refund`'s `totalMinor` (ADR-080). */
56
+ /** Vendure's per-unit refund value, rounded per unit: for display, never multiplied by a quantity for `order.refund`'s `totalMinor` (ADR-080 amendment 2). */
57
57
  proratedUnitPriceWithTax: number;
58
+ /** The line's total with tax after order-level discounts; a refund's line amount is its share of this (vendurepos ADR 0007, decision 4.9). */
59
+ proratedLinePriceWithTax: number;
58
60
  taxRate: number;
59
61
  productVariant: { id: string; name: string; sku: string };
60
62
  unitPrice: number;
@@ -110,7 +112,7 @@ const ORDER_DETAIL_FIELDS_START = `
110
112
  customer { id firstName lastName emailAddress }
111
113
  lines {`;
112
114
  const ORDER_DETAIL_FIELDS_END = `
113
- id quantity orderPlacedQuantity proratedUnitPrice proratedUnitPriceWithTax taxRate productVariant { id name sku }
115
+ id quantity orderPlacedQuantity proratedUnitPrice proratedUnitPriceWithTax proratedLinePriceWithTax taxRate productVariant { id name sku }
114
116
  unitPrice unitPriceWithTax linePrice linePriceWithTax discountedLinePrice discountedLinePriceWithTax
115
117
  discounts { description amount amountWithTax }
116
118
  }
package/src/refunds.ts CHANGED
@@ -6,7 +6,9 @@ export interface VendureRefundableLine {
6
6
  refundedQuantity: number; // Sum of its refund lines over refunds not Failed.
7
7
  cancelledQuantity: number; // max(0, orderPlacedQuantity - quantity).
8
8
  refundableQuantity: number; // max(0, quantity - refundedQuantity).
9
- unitRefundWithTax: number; // The line's proratedUnitPriceWithTax.
9
+ /** @deprecated For display only; a refund's amount is vendureLineRefundWithTax. */
10
+ unitRefundWithTax: number; // The line's proratedUnitPriceWithTax, for display. Never multiply it by a quantity: use vendureLineRefundWithTax.
11
+ lineTotalWithTax: number; // The line's proratedLinePriceWithTax.
10
12
  }
11
13
 
12
14
  export interface VendureRefundable {
@@ -50,9 +52,25 @@ export function vendureRefundable(order: Pick<VendureOrder, 'lines' | 'shippingW
50
52
  cancelledQuantity: Number.isFinite(line.orderPlacedQuantity) ? Math.max(0, line.orderPlacedQuantity - quantity) : 0,
51
53
  refundableQuantity: Math.max(0, quantity - refundedQuantity),
52
54
  unitRefundWithTax: Number.isFinite(line.proratedUnitPriceWithTax) ? line.proratedUnitPriceWithTax : 0,
55
+ lineTotalWithTax: Number.isFinite(line.proratedLinePriceWithTax) ? line.proratedLinePriceWithTax : 0,
53
56
  };
54
57
  }),
55
58
  shippingWithTax: Math.max(0, (Number.isFinite(order.shippingWithTax) ? order.shippingWithTax : 0) - refundedShipping),
56
59
  moneyWithTax,
57
60
  };
58
61
  }
62
+
63
+ /**
64
+ * The amount, with tax, of refunding `quantity` more units of a line: its cumulative share of the line total
65
+ * (vendurepos ADR 0007, decision 4.9), the plugin's own rule for `amount_mismatch`. Refunding every refundable unit
66
+ * returns what is left of `lineTotalWithTax`, and partial refunds add up to it.
67
+ */
68
+ export function vendureLineRefundWithTax(line: VendureRefundableLine, quantity: number): number {
69
+ if (!Number.isInteger(quantity) || quantity < 1 || quantity > line.refundableQuantity) {
70
+ throw new RangeError(`Line ${line.orderLineId}: quantity ${quantity} must be a whole number from 1 to refundable quantity ${line.refundableQuantity}`);
71
+ }
72
+ const N = line.quantity;
73
+ const T = line.lineTotalWithTax;
74
+ const r = line.refundedQuantity;
75
+ return Math.round(((r + quantity) * T) / N) - Math.round((r * T) / N);
76
+ }