@reactionary/medusa 0.10.49 → 0.10.50
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.
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
CheckoutSchema,
|
|
23
23
|
MonetaryAmountSchema,
|
|
24
24
|
PaymentMethodSchema,
|
|
25
|
+
error,
|
|
25
26
|
Reactionary,
|
|
26
27
|
ShippingMethodIdentifierSchema,
|
|
27
28
|
ShippingMethodSchema,
|
|
@@ -31,7 +32,7 @@ import createDebug from "debug";
|
|
|
31
32
|
import * as z from "zod";
|
|
32
33
|
import {
|
|
33
34
|
} from "../schema/medusa.schema.js";
|
|
34
|
-
import { handleProviderError } from "../utils/medusa-helpers.js";
|
|
35
|
+
import { handleProviderError, isNotFoundFetchError } from "../utils/medusa-helpers.js";
|
|
35
36
|
const debug = createDebug("reactionary:medusa:checkout");
|
|
36
37
|
class CheckoutNotReadyForFinalizationError extends Error {
|
|
37
38
|
constructor(checkoutIdentifier) {
|
|
@@ -88,10 +89,20 @@ class MedusaCheckoutCapability extends CheckoutCapability {
|
|
|
88
89
|
}
|
|
89
90
|
async getById(payload) {
|
|
90
91
|
const client = await this.medusaApi.getClient();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
try {
|
|
93
|
+
const response = await client.store.cart.retrieve(payload.identifier.key, {
|
|
94
|
+
fields: this.includedFields
|
|
95
|
+
});
|
|
96
|
+
return success(this.factory.parseCheckout(this.context, response.cart));
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (isNotFoundFetchError(err)) {
|
|
99
|
+
return error({
|
|
100
|
+
type: "NotFound",
|
|
101
|
+
identifier: payload.identifier
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
handleProviderError("get checkout by id", err);
|
|
105
|
+
}
|
|
95
106
|
}
|
|
96
107
|
setShippingAddressPayload(payload) {
|
|
97
108
|
return {
|
|
@@ -240,10 +251,10 @@ class MedusaCheckoutCapability extends CheckoutCapability {
|
|
|
240
251
|
}
|
|
241
252
|
);
|
|
242
253
|
return success(this.factory.parseCheckout(this.context, updatedCartResponse.cart));
|
|
243
|
-
} catch (
|
|
244
|
-
debug("Failed to add payment instruction: {0}", [
|
|
254
|
+
} catch (error2) {
|
|
255
|
+
debug("Failed to add payment instruction: {0}", [error2]);
|
|
245
256
|
throw new Error(
|
|
246
|
-
`Failed to add payment instruction: ${
|
|
257
|
+
`Failed to add payment instruction: ${error2 instanceof Error ? error2.message : "Unknown error"}`
|
|
247
258
|
);
|
|
248
259
|
}
|
|
249
260
|
}
|
|
@@ -280,13 +291,16 @@ class MedusaCheckoutCapability extends CheckoutCapability {
|
|
|
280
291
|
return success(this.factory.parseCheckout(this.context, response.cart));
|
|
281
292
|
}
|
|
282
293
|
throw new Error("Failed to set shipping method");
|
|
283
|
-
} catch (
|
|
284
|
-
handleProviderError("set shipping method",
|
|
294
|
+
} catch (error2) {
|
|
295
|
+
handleProviderError("set shipping method", error2);
|
|
285
296
|
}
|
|
286
297
|
}
|
|
287
298
|
async finalizeCheckout(payload) {
|
|
288
299
|
let checkout = await this.getById({ identifier: payload.checkout });
|
|
289
|
-
if (!checkout.success
|
|
300
|
+
if (!checkout.success) {
|
|
301
|
+
return checkout;
|
|
302
|
+
}
|
|
303
|
+
if (!checkout.value.readyForFinalization) {
|
|
290
304
|
throw new CheckoutNotReadyForFinalizationError(payload.checkout);
|
|
291
305
|
}
|
|
292
306
|
if (!checkout.value.resultingOrder) {
|
|
@@ -9,6 +9,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
9
9
|
return result;
|
|
10
10
|
};
|
|
11
11
|
import {
|
|
12
|
+
error,
|
|
12
13
|
OrderCapability,
|
|
13
14
|
OrderQueryByIdSchema,
|
|
14
15
|
OrderSchema,
|
|
@@ -16,7 +17,7 @@ import {
|
|
|
16
17
|
success
|
|
17
18
|
} from "@reactionary/core";
|
|
18
19
|
import createDebug from "debug";
|
|
19
|
-
import { handleProviderError } from "../utils/medusa-helpers.js";
|
|
20
|
+
import { handleProviderError, isNotFoundFetchError } from "../utils/medusa-helpers.js";
|
|
20
21
|
const debug = createDebug("reactionary:medusa:order");
|
|
21
22
|
class MedusaOrderCapability extends OrderCapability {
|
|
22
23
|
constructor(config, cache, context, medusaApi, factory) {
|
|
@@ -36,6 +37,12 @@ class MedusaOrderCapability extends OrderCapability {
|
|
|
36
37
|
const order = this.factory.parseOrder(this.context, response.order);
|
|
37
38
|
return success(order);
|
|
38
39
|
} catch (err) {
|
|
40
|
+
if (isNotFoundFetchError(err)) {
|
|
41
|
+
return error({
|
|
42
|
+
type: "NotFound",
|
|
43
|
+
identifier: payload.order
|
|
44
|
+
});
|
|
45
|
+
}
|
|
39
46
|
return handleProviderError("order", err);
|
|
40
47
|
}
|
|
41
48
|
}
|
package/core/client.js
CHANGED
|
@@ -36,7 +36,7 @@ class RequestContextTokenStore {
|
|
|
36
36
|
}
|
|
37
37
|
if (debug.enabled) {
|
|
38
38
|
debug(
|
|
39
|
-
`Setting token item for key: ${this.keyPrefix + "_" + key} - Value: ${value}
|
|
39
|
+
`Setting token item for key: ${this.keyPrefix + "_" + key} - Value: <redacted, ${value.length} chars>`
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
this.context.session[SESSION_KEY][this.keyPrefix + "_" + key] = value;
|
|
@@ -103,16 +103,16 @@ class MedusaCheckoutFactory {
|
|
|
103
103
|
const billingAddress = data.billing_address ? this.parseAddress(context, data.billing_address) : void 0;
|
|
104
104
|
const shippingAddress = data.shipping_address ? this.parseAddress(context, data.shipping_address) : void 0;
|
|
105
105
|
const backupUnattendedDelivery = data.metadata?.["consent_for_unattended_delivery"] !== void 0 ? data.metadata?.["consent_for_unattended_delivery"] === "true" : void 0;
|
|
106
|
-
const backupInstructions = data.metadata?.["instructions"]
|
|
107
|
-
const backupPickupPoint = data.metadata?.["pickup_point"]
|
|
106
|
+
const backupInstructions = data.metadata?.["instructions"] != null ? String(data.metadata["instructions"]) : void 0;
|
|
107
|
+
const backupPickupPoint = data.metadata?.["pickup_point"] != null ? String(data.metadata["pickup_point"]) : void 0;
|
|
108
108
|
let shippingInstruction;
|
|
109
109
|
data.shipping_methods?.forEach((sm) => {
|
|
110
110
|
let pickupPoint = "";
|
|
111
111
|
let instructions = "";
|
|
112
112
|
let consentForUnattendedDelivery = false;
|
|
113
113
|
if (sm.data) {
|
|
114
|
-
pickupPoint = sm.data["pickup_point"]
|
|
115
|
-
instructions = sm.data["instructions"]
|
|
114
|
+
pickupPoint = sm.data["pickup_point"] != null ? String(sm.data["pickup_point"]) : "";
|
|
115
|
+
instructions = sm.data["instructions"] != null ? String(sm.data["instructions"]) : "";
|
|
116
116
|
consentForUnattendedDelivery = sm.data["consent_for_unattended_delivery"] === "true";
|
|
117
117
|
}
|
|
118
118
|
if (!pickupPoint) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reactionary/medusa",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.50",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./src/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@medusajs/js-sdk": "^2.13.3",
|
|
13
|
-
"@reactionary/core": "0.10.
|
|
13
|
+
"@reactionary/core": "0.10.50",
|
|
14
14
|
"debug": "^4.4.3",
|
|
15
15
|
"@medusajs/types": "^2.13.3",
|
|
16
16
|
"zod": "4.1.9"
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { StoreCart } from '@medusajs/types';
|
|
2
2
|
import type { CostBreakDown, Currency } from '@reactionary/core';
|
|
3
|
+
/**
|
|
4
|
+
* The Medusa SDK throws a FetchError for every non-2xx response. Returns true
|
|
5
|
+
* when the error is the SDK's way of saying the resource does not exist, so
|
|
6
|
+
* capabilities can answer with a typed NotFound result instead of throwing.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isNotFoundFetchError(error: unknown): boolean;
|
|
3
9
|
/**
|
|
4
10
|
* The subset of StoreCart/StoreOrder fields parseMedusaCostBreakdown reads.
|
|
5
11
|
* Narrowed (rather than StoreCart | StoreOrder) so tests can build a minimal,
|
package/utils/medusa-helpers.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { FetchError } from "@medusajs/js-sdk";
|
|
1
2
|
import createDebug from "debug";
|
|
2
3
|
const debug = createDebug("reactionary:medusa:helpers");
|
|
4
|
+
function isNotFoundFetchError(error) {
|
|
5
|
+
return error instanceof FetchError && error.status === 404;
|
|
6
|
+
}
|
|
3
7
|
function parseMedusaCostBreakdown(remote) {
|
|
4
8
|
const grandTotal = remote.total || 0;
|
|
5
9
|
const shippingTotal = remote.shipping_total || 0;
|
|
@@ -79,6 +83,7 @@ function safeStringConvert(val, defaultValue) {
|
|
|
79
83
|
}
|
|
80
84
|
export {
|
|
81
85
|
handleProviderError,
|
|
86
|
+
isNotFoundFetchError,
|
|
82
87
|
parseMedusaCostBreakdown,
|
|
83
88
|
parseMedusaItemPrice,
|
|
84
89
|
safeBoolConvert,
|