@deenruv/react-ui-devkit 1.0.17-dev.20 → 1.0.17-dev.23

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.
Files changed (39) hide show
  1. package/dist/access.d.ts +9 -0
  2. package/dist/access.js +25 -1
  3. package/dist/access.js.map +1 -1
  4. package/dist/components/molecules/ListTable.js +3 -3
  5. package/dist/components/molecules/ListTable.js.map +1 -1
  6. package/dist/components/templates/DetailList/DetailList.d.ts +2 -1
  7. package/dist/components/templates/DetailList/DetailList.js +10 -9
  8. package/dist/components/templates/DetailList/DetailList.js.map +1 -1
  9. package/dist/components/templates/DetailList/DetailListColumns/ActionsDropdown.js +2 -1
  10. package/dist/components/templates/DetailList/DetailListColumns/ActionsDropdown.js.map +1 -1
  11. package/dist/components/templates/DetailList/useDetailListHook/buildSearchFilter.d.ts +9 -0
  12. package/dist/components/templates/DetailList/useDetailListHook/buildSearchFilter.js +37 -0
  13. package/dist/components/templates/DetailList/useDetailListHook/buildSearchFilter.js.map +1 -0
  14. package/dist/components/templates/DetailList/useDetailListHook/index.d.ts +3 -1
  15. package/dist/components/templates/DetailList/useDetailListHook/index.js +7 -12
  16. package/dist/components/templates/DetailList/useDetailListHook/index.js.map +1 -1
  17. package/dist/components/templates/DetailView/DetailView.d.ts +5 -4
  18. package/dist/components/templates/DetailView/DetailView.js +14 -8
  19. package/dist/components/templates/DetailView/DetailView.js.map +1 -1
  20. package/dist/components/templates/DetailView/useDetailView.d.ts +185 -182
  21. package/dist/hooks/useAssets.d.ts +2 -2
  22. package/dist/plugins/plugin-store.d.ts +2 -2
  23. package/dist/selectors/ModifyOrderSelector.d.ts +6 -0
  24. package/dist/selectors/details/OrderDetailSelector.d.ts +6 -0
  25. package/dist/selectors/details/OrderDetailSelector.js +3 -0
  26. package/dist/selectors/details/OrderDetailSelector.js.map +1 -1
  27. package/dist/state/order-refund.d.ts +117 -0
  28. package/dist/state/order-refund.js +156 -0
  29. package/dist/state/order-refund.js.map +1 -0
  30. package/dist/state/order.d.ts +13 -5
  31. package/dist/state/order.js +76 -26
  32. package/dist/state/order.js.map +1 -1
  33. package/dist/state/server.d.ts +6 -1
  34. package/dist/state/server.js +29 -3
  35. package/dist/state/server.js.map +1 -1
  36. package/dist/types/models.d.ts +1 -0
  37. package/dist/types/types.d.ts +9 -0
  38. package/dist/version.js +1 -1
  39. package/package.json +5 -5
@@ -73,8 +73,8 @@ export declare class PluginStore {
73
73
  */
74
74
  getComponents(location: string, passedTab?: string): React.ComponentType[];
75
75
  getModalComponents(location: string): React.ComponentType<any>[];
76
- getTableExtensions(location: LocationKeys): import("./types.js").DeenruvUITable<"assets-list-view" | "countries-list-view" | "admins-list-view" | "channels-list-view" | "collections-list-view" | "customers-list-view" | "facets-list-view" | "orders-list-view" | "products-list-view" | "promotions-list-view" | "roles-list-view" | "sellers-list-view" | "zones-list-view" | "productVariants-list-view" | "customerGroups-list-view" | "paymentMethods-list-view" | "shippingMethods-list-view" | "stockLocations-list-view" | "taxCategories-list-view" | "taxRates-list-view" | "stockLocations-list" | "facet-values-list">[];
77
- getDetailViewTabs(location: DetailLocationID): import("./types.js").DeenruvTabs<"orders-summary" | "countries-detail-view" | "admins-detail-view" | "channels-detail-view" | "collections-detail-view" | "customers-detail-view" | "facets-detail-view" | "orders-detail-view" | "products-detail-view" | "promotions-detail-view" | "roles-detail-view" | "sellers-detail-view" | "zones-detail-view" | "globalSettings-detail-view" | "customerGroups-detail-view" | "paymentMethods-detail-view" | "shippingMethods-detail-view" | "stockLocations-detail-view" | "taxCategories-detail-view" | "taxRates-detail-view">[];
76
+ getTableExtensions(location: LocationKeys): import("./types.js").DeenruvUITable<"channels-list-view" | "assets-list-view" | "collections-list-view" | "promotions-list-view" | "productVariants-list-view" | "customers-list-view" | "orders-list-view" | "roles-list-view" | "countries-list-view" | "admins-list-view" | "facets-list-view" | "products-list-view" | "sellers-list-view" | "zones-list-view" | "customerGroups-list-view" | "paymentMethods-list-view" | "shippingMethods-list-view" | "stockLocations-list-view" | "taxCategories-list-view" | "taxRates-list-view" | "stockLocations-list" | "facet-values-list">[];
77
+ getDetailViewTabs(location: DetailLocationID): import("./types.js").DeenruvTabs<"orders-summary" | "channels-detail-view" | "collections-detail-view" | "promotions-detail-view" | "customers-detail-view" | "orders-detail-view" | "roles-detail-view" | "countries-detail-view" | "admins-detail-view" | "facets-detail-view" | "products-detail-view" | "sellers-detail-view" | "zones-detail-view" | "globalSettings-detail-view" | "customerGroups-detail-view" | "paymentMethods-detail-view" | "shippingMethods-detail-view" | "stockLocations-detail-view" | "taxCategories-detail-view" | "taxRates-detail-view">[];
78
78
  getDetailViewActions(location: DetailLocationID): NonNullable<DeenruvUIPlugin["actions"]>;
79
79
  get topNavigationComponents(): (import("./types.js").PluginComponent & {
80
80
  plugin: DeenruvPluginStored;
@@ -160,6 +160,9 @@ export declare const modifyOrderSelector: {
160
160
  unitPriceWithTax: true;
161
161
  discountedUnitPrice: true;
162
162
  discountedUnitPriceWithTax: true;
163
+ proratedUnitPrice: true;
164
+ proratedUnitPriceWithTax: true;
165
+ orderPlacedQuantity: true;
163
166
  taxRate: true;
164
167
  };
165
168
  payments: {
@@ -359,6 +362,9 @@ export declare const modifyOrderSelector: {
359
362
  unitPriceWithTax: true;
360
363
  discountedUnitPrice: true;
361
364
  discountedUnitPriceWithTax: true;
365
+ proratedUnitPrice: true;
366
+ proratedUnitPriceWithTax: true;
367
+ orderPlacedQuantity: true;
362
368
  taxRate: true;
363
369
  };
364
370
  payments: {
@@ -35,6 +35,9 @@ declare const draftOrderLineSelector: {
35
35
  unitPriceWithTax: true;
36
36
  discountedUnitPrice: true;
37
37
  discountedUnitPriceWithTax: true;
38
+ proratedUnitPrice: true;
39
+ proratedUnitPriceWithTax: true;
40
+ orderPlacedQuantity: true;
38
41
  taxRate: true;
39
42
  };
40
43
  declare const paymentSelector: {
@@ -235,6 +238,9 @@ export declare const OrderDetailSelector: {
235
238
  unitPriceWithTax: true;
236
239
  discountedUnitPrice: true;
237
240
  discountedUnitPriceWithTax: true;
241
+ proratedUnitPrice: true;
242
+ proratedUnitPriceWithTax: true;
243
+ orderPlacedQuantity: true;
238
244
  taxRate: true;
239
245
  };
240
246
  payments: {
@@ -38,6 +38,9 @@ const draftOrderLineSelector = Selector("OrderLine")({
38
38
  unitPriceWithTax: true,
39
39
  discountedUnitPrice: true,
40
40
  discountedUnitPriceWithTax: true,
41
+ proratedUnitPrice: true,
42
+ proratedUnitPriceWithTax: true,
43
+ orderPlacedQuantity: true,
41
44
  taxRate: true,
42
45
  });
43
46
  const paymentSelector = Selector("Payment")({
@@ -1 +1 @@
1
- {"version":3,"file":"OrderDetailSelector.js","sourceRoot":"","sources":["../../../src/selectors/details/OrderDetailSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEzE,MAAM,mBAAmB,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;CAClB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACxD,EAAE,EAAE,IAAI;IACR,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE;IAC1C,GAAG,EAAE,IAAI;IACT,SAAS,EAAE,IAAI;IACf,OAAO,EAAE;QACP,IAAI,EAAE,IAAI;QACV,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,IAAI;QACV,aAAa,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;KAC3C;IACD,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE,IAAI;IACX,YAAY,EAAE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c,EAAE;YACd,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,IAAI;YACV,sBAAsB,EAAE,IAAI;SAC7B;KACF;IACD,cAAc,EAAE;QACd,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,GAAG,mBAAmB;KACvB;IACD,eAAe,EAAE;QACf,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,GAAG,mBAAmB;KACvB;IACD,QAAQ,EAAE;QACR,EAAE,EAAE,IAAI;QACR,KAAK,EAAE,IAAI;QACX,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE;YACT,EAAE,EAAE,IAAI;YACR,qBAAqB,EAAE,IAAI;YAC3B,sBAAsB,EAAE,IAAI;YAC5B,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;YACnC,GAAG,mBAAmB;SACvB;KACF;IACD,KAAK,EAAE,sBAAsB;IAC7B,QAAQ,EAAE,eAAe;CAC1B,CAAC,CAAC"}
1
+ {"version":3,"file":"OrderDetailSelector.js","sourceRoot":"","sources":["../../../src/selectors/details/OrderDetailSelector.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEzE,MAAM,mBAAmB,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,IAAI;IACd,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;CAClB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACxD,EAAE,EAAE,IAAI;IACR,aAAa,EAA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AW,EAAE,IAAI;QACjB,gBAAgB,EAAE,IAAI;QACtB,aAAa,EAAE,IAAI;QACnB,IAAI,EAAE,IAAI;KACX;IACD,YAAY,EAAE,mBAAmB;IACjC,oBAAoB,EAAE,IAAI;IAC1B,UAAU,EAAE;QACV,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,EAAE,EAAE,IAAI;QACR,KAAK,EAAE,IAAI;QACX,YAAY,EAAE,IAAI;QAClB,eAAe,EAAE,IAAI;QACrB,sBAAsB,EAAE,IAAI;QAC5B,cAAc,EAAE;YACd,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,IAAI;YACV,sBAAsB,EAAE,IAAI;SAC7B;KACF;IACD,cAAc,EAAE;QACd,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,GAAG,mBAAmB;KACvB;IACD,eAAe,EAAE;QACf,WAAW,EAAE,IAAI;QACjB,OAAO,EAAE,IAAI;QACb,GAAG,mBAAmB;KACvB;IACD,QAAQ,EAAE;QACR,EAAE,EAAE,IAAI;QACR,KAAK,EAAE,IAAI;QACX,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE;YACT,EAAE,EAAE,IAAI;YACR,qBAAqB,EAAE,IAAI;YAC3B,sBAAsB,EAAE,IAAI;YAC5B,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;YACnC,GAAG,mBAAmB;SACvB;KACF;IACD,KAAK,EAAE,sBAAsB;IAC7B,QAAQ,EAAE,eAAe;CAC1B,CAAC,CAAC"}
@@ -0,0 +1,117 @@
1
+ export interface RefundLineSource {
2
+ id: string;
3
+ maxRefundQuantity: number;
4
+ maxCancelQuantity: number;
5
+ unitPriceWithTax: number;
6
+ }
7
+ export interface RefundLineSelection {
8
+ refundQuantity: number;
9
+ cancelQuantity: number;
10
+ }
11
+ export interface RefundPaymentSource {
12
+ id: string;
13
+ amount: number;
14
+ state: string;
15
+ refunds: Array<{
16
+ state: string;
17
+ total: number;
18
+ }>;
19
+ }
20
+ export interface RefundAllocation {
21
+ paymentId: string;
22
+ amount: number;
23
+ }
24
+ export interface OrderRefundPlan {
25
+ cancelLines: Array<{
26
+ orderLineId: string;
27
+ quantity: number;
28
+ }>;
29
+ refundLines: Array<{
30
+ orderLineId: string;
31
+ quantity: number;
32
+ }>;
33
+ itemAmount: number;
34
+ totalAmount: number;
35
+ allocations: RefundAllocation[];
36
+ cancelShipping: boolean;
37
+ }
38
+ export interface RefundMutationInput {
39
+ paymentId: string;
40
+ amount: number;
41
+ lines: Array<{
42
+ orderLineId: string;
43
+ quantity: number;
44
+ }>;
45
+ reason: string;
46
+ shipping: number;
47
+ adjustment: number;
48
+ }
49
+ export type OrderRefundOutcome = "cancellation" | "refund" | "combined";
50
+ export interface CancellationMutationInput {
51
+ cancelShipping: boolean;
52
+ lines: Array<{
53
+ orderLineId: string;
54
+ quantity: number;
55
+ }>;
56
+ reason: string;
57
+ }
58
+ export declare const buildCancellationMutationInput: (input: {
59
+ cancelShipping: boolean;
60
+ cancelLines: Array<{
61
+ orderLineId: string;
62
+ quantity: number;
63
+ }>;
64
+ reason: string;
65
+ }) => CancellationMutationInput;
66
+ export declare const getOrderRefundOutcome: (input: {
67
+ hasCancellation: boolean;
68
+ hasRefund: boolean;
69
+ }) => OrderRefundOutcome;
70
+ export declare const assertMutationSuccess: <T extends {
71
+ __typename?: string;
72
+ message?: string;
73
+ }>(result: T, successType: string) => T;
74
+ export declare const getRefundablePayments: (payments: RefundPaymentSource[]) => {
75
+ paymentId: string;
76
+ capacity: number;
77
+ }[];
78
+ export declare const getRefundedQuantities: (payments: Array<{
79
+ refunds: Array<{
80
+ state: string;
81
+ lines: Array<{
82
+ orderLineId: string;
83
+ quantity: number;
84
+ }>;
85
+ }>;
86
+ }>) => Record<string, number>;
87
+ export declare const allocateRefund: (amount: number, capacities: Array<{
88
+ paymentId: string;
89
+ capacity: number;
90
+ }>, overrides?: RefundAllocation[]) => RefundAllocation[];
91
+ export declare const planOrderRefund: (input: {
92
+ lines: RefundLineSource[];
93
+ selections: Record<string, RefundLineSelection>;
94
+ shippingAmount: number;
95
+ cancelShipping: boolean;
96
+ reason: string;
97
+ capacities: Array<{
98
+ paymentId: string;
99
+ capacity: number;
100
+ }>;
101
+ amountOverride?: number;
102
+ allocationOverrides?: RefundAllocation[];
103
+ }) => OrderRefundPlan;
104
+ export declare const buildRefundMutationInputs: (input: {
105
+ allocations: RefundAllocation[];
106
+ refundLines: Array<{
107
+ orderLineId: string;
108
+ quantity: number;
109
+ }>;
110
+ reason: string;
111
+ shipping: number;
112
+ adjustment: number;
113
+ }) => RefundMutationInput[];
114
+ export declare const executeCancellationAndRefunds: <T>(input: {
115
+ cancel?: () => Promise<T>;
116
+ refunds: Array<() => Promise<T>>;
117
+ }) => Promise<T[]>;
@@ -0,0 +1,156 @@
1
+ export const buildCancellationMutationInput = (input) => {
2
+ if (input.cancelLines.length === 0) {
3
+ throw new Error("Select at least one line before cancelling shipping");
4
+ }
5
+ return {
6
+ cancelShipping: input.cancelShipping,
7
+ lines: input.cancelLines,
8
+ reason: input.reason,
9
+ };
10
+ };
11
+ export const getOrderRefundOutcome = (input) => input.hasRefund
12
+ ? input.hasCancellation
13
+ ? "combined"
14
+ : "refund"
15
+ : "cancellation";
16
+ export const assertMutationSuccess = (result, successType) => {
17
+ if (result.__typename !== successType) {
18
+ throw new Error(result.message || `Unexpected ${result.__typename || "mutation"} result`);
19
+ }
20
+ return result;
21
+ };
22
+ export const getRefundablePayments = (payments) => payments
23
+ .filter((payment) => payment.state === "Settled")
24
+ .map((payment) => ({
25
+ paymentId: payment.id,
26
+ capacity: Math.max(0, payment.amount -
27
+ payment.refunds
28
+ .filter((refund) => refund.state !== "Failed")
29
+ .reduce((total, refund) => total + refund.total, 0)),
30
+ }))
31
+ .filter((payment) => payment.capacity > 0);
32
+ export const getRefundedQuantities = (payments) => {
33
+ const quantities = {};
34
+ for (const payment of payments) {
35
+ for (const refund of payment.refunds) {
36
+ if (refund.state === "Failed")
37
+ continue;
38
+ for (const line of refund.lines) {
39
+ quantities[line.orderLineId] =
40
+ (quantities[line.orderLineId] ?? 0) + line.quantity;
41
+ }
42
+ }
43
+ }
44
+ return quantities;
45
+ };
46
+ export const allocateRefund = (amount, capacities, overrides) => {
47
+ if (!Number.isInteger(amount) || amount <= 0) {
48
+ throw new Error("Refund amount must be a positive integer");
49
+ }
50
+ const capacityByPayment = new Map(capacities.map((payment) => [payment.paymentId, payment.capacity]));
51
+ if (overrides) {
52
+ const seen = new Set();
53
+ let allocated = 0;
54
+ for (const allocation of overrides) {
55
+ const capacity = capacityByPayment.get(allocation.paymentId);
56
+ if (seen.has(allocation.paymentId) ||
57
+ capacity === undefined ||
58
+ !Number.isInteger(allocation.amount) ||
59
+ allocation.amount <= 0 ||
60
+ allocation.amount > capacity) {
61
+ throw new Error("Refund allocation exceeds payment capacity");
62
+ }
63
+ seen.add(allocation.paymentId);
64
+ allocated += allocation.amount;
65
+ }
66
+ if (allocated !== amount)
67
+ throw new Error("Refund allocations must equal the refund amount");
68
+ return overrides.map((allocation) => ({ ...allocation }));
69
+ }
70
+ let remaining = amount;
71
+ const allocations = [];
72
+ for (const payment of capacities) {
73
+ const allocated = Math.min(payment.capacity, remaining);
74
+ if (allocated > 0)
75
+ allocations.push({ paymentId: payment.paymentId, amount: allocated });
76
+ remaining -= allocated;
77
+ if (remaining === 0)
78
+ break;
79
+ }
80
+ if (remaining > 0)
81
+ throw new Error("Refund amount exceeds settled payment capacity");
82
+ return allocations;
83
+ };
84
+ export const planOrderRefund = (input) => {
85
+ if (!input.reason.trim())
86
+ throw new Error("A reason is required");
87
+ const cancelLines = [];
88
+ const refundLines = [];
89
+ let itemAmount = 0;
90
+ for (const line of input.lines) {
91
+ const selection = input.selections[line.id] ?? {
92
+ refundQuantity: 0,
93
+ cancelQuantity: 0,
94
+ };
95
+ for (const [quantity, maximum] of [
96
+ [selection.refundQuantity, line.maxRefundQuantity],
97
+ [selection.cancelQuantity, line.maxCancelQuantity],
98
+ ]) {
99
+ if (!Number.isInteger(quantity) || quantity < 0 || quantity > maximum) {
100
+ throw new Error("Line quantities must be whole numbers within the available range");
101
+ }
102
+ }
103
+ if (selection.refundQuantity > 0) {
104
+ refundLines.push({
105
+ orderLineId: line.id,
106
+ quantity: selection.refundQuantity,
107
+ });
108
+ itemAmount += line.unitPriceWithTax * selection.refundQuantity;
109
+ }
110
+ if (selection.cancelQuantity > 0) {
111
+ cancelLines.push({
112
+ orderLineId: line.id,
113
+ quantity: selection.cancelQuantity,
114
+ });
115
+ }
116
+ }
117
+ if (!Number.isInteger(input.shippingAmount) || input.shippingAmount < 0) {
118
+ throw new Error("Shipping refund must be a non-negative integer");
119
+ }
120
+ const totalAmount = input.amountOverride ?? itemAmount + input.shippingAmount;
121
+ if (!Number.isInteger(totalAmount) || totalAmount < 0)
122
+ throw new Error("Refund amount must be a non-negative integer");
123
+ const allocations = totalAmount > 0
124
+ ? allocateRefund(totalAmount, input.capacities, input.allocationOverrides)
125
+ : [];
126
+ if (input.cancelShipping && cancelLines.length === 0) {
127
+ throw new Error("Select at least one line before cancelling shipping");
128
+ }
129
+ if (cancelLines.length === 0 && totalAmount === 0)
130
+ throw new Error("Select a cancellation or refund");
131
+ return {
132
+ cancelLines,
133
+ refundLines,
134
+ itemAmount,
135
+ totalAmount,
136
+ allocations,
137
+ cancelShipping: input.cancelShipping,
138
+ };
139
+ };
140
+ export const buildRefundMutationInputs = (input) => input.allocations.map((allocation, index) => ({
141
+ paymentId: allocation.paymentId,
142
+ amount: allocation.amount,
143
+ lines: index === 0 ? input.refundLines : [],
144
+ reason: input.reason,
145
+ shipping: index === 0 ? input.shipping : 0,
146
+ adjustment: index === 0 ? input.adjustment : 0,
147
+ }));
148
+ export const executeCancellationAndRefunds = async (input) => {
149
+ const results = [];
150
+ if (input.cancel)
151
+ results.push(await input.cancel());
152
+ for (const refund of input.refunds)
153
+ results.push(await refund());
154
+ return results;
155
+ };
156
+ //# sourceMappingURL=order-refund.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-refund.js","sourceRoot":"","sources":["../../src/state/order-refund.ts"],"names":[],"mappings":"AAkDA,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,KAI9C,EAA6B,EAAE;IAC9B,IAAI,KAAK,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,OAAO;QACL,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,KAAK,EAAE,KAAK,CAAC,WAAW;QACxB,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAGrC,EAAsB,EAAE,CACvB,KAAK,CAAC,SAAS;IACb,CAAC,CAAC,KAAK,CAAC,eAAe;QACrB,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,QAAQ;IACZ,CAAC,CAAC,cAAc,CAAC;AAErB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAGnC,MAAS,EACT,WAAmB,EAChB,EAAE;IACL,IAAI,MAAM,CAAC,UAAU,KAAK,WAAW,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACb,MAAM,CAAC,OAAO,IAAI,cAAc,MAAM,CAAC,UAAU,IAAI,UAAU,SAAS,CACzE,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAA+B,EAAE,EAAE,CACvE,QAAQ;KACL,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OA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es, ResolverInputTypes } from "@deenruv/
3
3
  import { ServerConfigType } from "../selectors/BaseSelectors.js";
4
4
  import { OrderDetailType } from "../selectors/index.js";
5
5
  import { ORDER_STATE } from "../utils/order_state.js";
6
+ import { RefundAllocation } from "./order-refund.js";
7
+ export * from "./order-refund.js";
6
8
  export type UnknownObject = Record<string, unknown>;
7
9
  export type ModifyOrderInput = Omit<ResolverInputTypes["ModifyOrderInput"], "dryRun" | "orderId">;
8
10
  export type OrderLineActions = "quantity-price" | "attributes";
@@ -94,7 +96,9 @@ interface Actions {
94
96
  addPaymentToOrder: (input: ResolverInputTypes["ManualPaymentInput"]) => void;
95
97
  settlePayment: (input: {
96
98
  id: string;
97
- }) => void;
99
+ }) => Promise<{
100
+ id: string;
101
+ } | void>;
98
102
  cancelPayment: (id: string) => void;
99
103
  cancelFulfillment: (id: string) => void;
100
104
  initializeOrderCustomFields(serverConfig: ServerConfigType): void;
@@ -116,22 +120,26 @@ interface Actions {
116
120
  cancelOrder: (input: Omit<ModelTypes["CancelOrderInput"], "orderId">, noOrderRefetch?: boolean) => Promise<{
117
121
  id: string;
118
122
  } | void>;
119
- refundOrder: (input: Omit<ModelTypes["RefundOrderInput"], "paymentId">) => Promise<{
123
+ refundOrder: (input: ModelTypes["RefundOrderInput"], noOrderRefetch?: boolean) => Promise<{
120
124
  id: string;
121
125
  } | void>;
122
126
  cancelAndRefundOrder: (input: {
123
127
  cancelShipping: boolean;
124
- amount: number;
125
- lines: {
128
+ cancelLines: {
129
+ orderLineId: string;
130
+ quantity: number;
131
+ }[];
132
+ refundLines: {
126
133
  orderLineId: string;
127
134
  quantity: number;
128
135
  }[];
136
+ allocations: RefundAllocation[];
129
137
  reason: string;
130
138
  shipping: number;
131
139
  adjustment: number;
132
140
  }) => Promise<{
133
141
  id: string;
142
+ outcome: "cancellation" | "refund" | "combined";
134
143
  } | void>;
135
144
  }
136
145
  export declare const useOrder: import("zustand").UseBoundStore<import("zustand").StoreApi<Order & Actions>>;
137
- export {};
@@ -8,6 +8,8 @@ import { toast } from "sonner";
8
8
  import { create } from "zustand";
9
9
  import { OrderDetailSelector } from "../selectors/index.js";
10
10
  import { ORDER_STATE } from "../utils/order_state.js";
11
+ import { assertMutationSuccess, buildCancellationMutationInput, buildRefundMutationInputs, executeCancellationAndRefunds, getOrderRefundOutcome, } from "./order-refund.js";
12
+ export * from "./order-refund.js";
11
13
  const cancelPaymentMutation = (id) => apiClient("mutation")({
12
14
  cancelPayment: [{ id }, { "...on CancelPaymentError": { message: true } }],
13
15
  });
@@ -27,6 +29,16 @@ const cancelFulfillmentMutation = (id) => apiClient("mutation")({
27
29
  ],
28
30
  });
29
31
  const TAKE = 100;
32
+ const mutationError = (result, successType) => {
33
+ try {
34
+ assertMutationSuccess(result, successType);
35
+ }
36
+ catch (cause) {
37
+ const error = cause instanceof Error ? cause : new Error("Mutation failed");
38
+ toast.error(error.message);
39
+ throw error;
40
+ }
41
+ };
30
42
  const getAllOrderHistory = async (id) => {
31
43
  let history = [];
32
44
  let totalItems = 0;
@@ -524,12 +536,11 @@ export const useOrder = create()((set, get) => {
524
536
  },
525
537
  ],
526
538
  });
527
- // if (settlePayment.__typename !== 'Payment') {
528
- // toast.error(`${settlePayment.message}`, { position: 'top-center' });
529
- // return;
530
- // }
531
- fetchOrder(order.id);
532
- fetchOrderHistory();
539
+ mutationError(settlePayment, "Payment");
540
+ if (settlePayment.__typename !== "Payment")
541
+ return;
542
+ await Promise.all([fetchOrder(order.id), fetchOrderHistory()]);
543
+ return { id: settlePayment.id };
533
544
  },
534
545
  changeOrderState: async (newState) => {
535
546
  const { order, fetchOrder, fetchOrderHistory } = get();
@@ -559,7 +570,7 @@ export const useOrder = create()((set, get) => {
559
570
  },
560
571
  cancelOrder: async (input, noOrderRefetch) => {
561
572
  const { order, fetchOrder, fetchOrderHistory } = get();
562
- if (!order || !order.payments?.length)
573
+ if (!order)
563
574
  return;
564
575
  return apiClient("mutation")({
565
576
  cancelOrder: [
@@ -594,44 +605,83 @@ export const useOrder = create()((set, get) => {
594
605
  },
595
606
  },
596
607
  ],
597
- }).then((resp) => {
598
- if (!noOrderRefetch && resp.cancelOrder?.__typename === "Order") {
599
- fetchOrder(order?.id);
600
- fetchOrderHistory();
601
- }
608
+ }).then(async (resp) => {
609
+ mutationError(resp.cancelOrder, "Order");
610
+ if (resp.cancelOrder.__typename !== "Order")
611
+ return;
612
+ if (!noOrderRefetch)
613
+ await Promise.all([fetchOrder(order.id), fetchOrderHistory()]);
614
+ return { id: resp.cancelOrder.id };
602
615
  });
603
616
  },
604
- refundOrder: async (input) => {
617
+ refundOrder: async (input, noOrderRefetch) => {
605
618
  const { order, fetchOrder, fetchOrderHistory } = get();
606
- if (!order || !order.payments?.length)
607
- return;
608
- const paymentId = order.payments[order.payments?.length - 1].id;
619
+ if (!order || !input.paymentId)
620
+ throw new Error("A payment is required for a refund");
609
621
  return apiClient("mutation")({
610
622
  refundOrder: [
611
623
  {
612
624
  input: {
613
- paymentId,
614
625
  ...input,
615
626
  },
616
627
  },
617
628
  {
618
- "...on Refund": { id: true },
629
+ "...on Refund": { id: true, state: true },
630
+ "...on QuantityTooGreatError": { message: true },
631
+ "...on NothingToRefundError": { message: true },
632
+ "...on OrderStateTransitionError": { message: true },
633
+ "...on MultipleOrderError": { message: true },
634
+ "...on PaymentOrderMismatchError": { message: true },
635
+ "...on RefundOrderStateError": { message: true },
636
+ "...on AlreadyRefundedError": { message: true },
637
+ "...on RefundStateTransitionError": { message: true },
638
+ "...on RefundAmountError": { message: true },
619
639
  __typename: true,
620
640
  },
621
641
  ],
622
- }).then((resp) => {
623
- if (resp.refundOrder?.__typename === "Refund") {
624
- fetchOrder(order?.id);
625
- fetchOrderHistory();
642
+ }).then(async (resp) => {
643
+ mutationError(resp.refundOrder, "Refund");
644
+ if (resp.refundOrder.__typename !== "Refund")
645
+ return;
646
+ if (resp.refundOrder.state === "Failed") {
647
+ const error = new Error("The refund failed");
648
+ toast.error(error.message);
649
+ throw error;
626
650
  }
651
+ if (!noOrderRefetch)
652
+ await Promise.all([fetchOrder(order.id), fetchOrderHistory()]);
653
+ return { id: resp.refundOrder.id };
627
654
  });
628
655
  },
629
656
  cancelAndRefundOrder: async (input) => {
630
- const { order, cancelOrder, refundOrder } = get();
631
- if (!order || !order.payments?.length)
657
+ const { order, cancelOrder, refundOrder, fetchOrder, fetchOrderHistory } = get();
658
+ if (!order)
632
659
  return;
633
- const { adjustment, amount, cancelShipping, lines, reason, shipping } = input;
634
- return cancelOrder({ cancelShipping, lines, reason }, true).then(() => refundOrder({ adjustment, lines, shipping, amount, reason }));
660
+ const { adjustment, allocations, cancelShipping, cancelLines, reason, refundLines, shipping, } = input;
661
+ const results = await executeCancellationAndRefunds({
662
+ cancel: cancelLines.length > 0
663
+ ? () => cancelOrder(buildCancellationMutationInput({
664
+ cancelShipping,
665
+ cancelLines,
666
+ reason,
667
+ }), true)
668
+ : undefined,
669
+ refunds: buildRefundMutationInputs({
670
+ allocations,
671
+ refundLines,
672
+ reason,
673
+ shipping,
674
+ adjustment,
675
+ }).map((refundInput) => () => refundOrder(refundInput, true)),
676
+ });
677
+ await Promise.all([fetchOrder(order.id), fetchOrderHistory()]);
678
+ return {
679
+ id: results.at(-1)?.id ?? order.id,
680
+ outcome: getOrderRefundOutcome({
681
+ hasCancellation: cancelLines.length > 0 || cancelShipping,
682
+ hasRefund: allocations.length > 0,
683
+ }),
684
+ };
635
685
  },
636
686
  };
637
687
  });