@kizlo/woocommerce 0.14.1 → 0.16.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 +45 -0
- package/dist/checkout-validation.d.ts +1 -1
- package/dist/index.d.ts +2106 -2100
- package/dist/index.js +52 -13
- package/dist/{schema-ScTHhVY4.d.ts → schema-CWDJjtW7.d.ts} +3 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -50,8 +50,9 @@ function sessionMiddleware(options) {
|
|
|
50
50
|
maxAge: ttlSeconds
|
|
51
51
|
};
|
|
52
52
|
return createMiddleware(async ({ context, next }) => {
|
|
53
|
-
const connInfo = await context.getConnInfo();
|
|
54
53
|
const session = await context.getSession();
|
|
54
|
+
if (!session && options?.allowGuest === false) throw new KizloError("UNAUTHORIZED");
|
|
55
|
+
const connInfo = await context.getConnInfo();
|
|
55
56
|
const foundToken = await context.cookies.get(cookieName);
|
|
56
57
|
if (!session) {
|
|
57
58
|
if (!foundToken) {
|
|
@@ -1383,6 +1384,10 @@ const CART_PROCEDURES = {
|
|
|
1383
1384
|
//#endregion
|
|
1384
1385
|
//#region src/checkout/error.ts
|
|
1385
1386
|
const CheckoutConflictData = z$2.object({ cart: Cart.nullable() });
|
|
1387
|
+
const CheckoutTotalMismatchData = CheckoutConflictData.extend({
|
|
1388
|
+
expectedTotal: z$2.string().regex(/^[0-9]+$/).optional(),
|
|
1389
|
+
actualTotal: z$2.string().regex(/^[0-9]+$/).optional()
|
|
1390
|
+
});
|
|
1386
1391
|
const GET_CHECKOUT_ERROR_MAP = defineErrorMap({ CHECKOUT_ORDER_NOT_FOUND: {
|
|
1387
1392
|
status: 404,
|
|
1388
1393
|
message: "No checkout order found."
|
|
@@ -1454,6 +1459,11 @@ const CONFIRM_CHECKOUT_ERROR_MAP = defineErrorMap({
|
|
|
1454
1459
|
message: "The cart is empty.",
|
|
1455
1460
|
data: CheckoutConflictData
|
|
1456
1461
|
},
|
|
1462
|
+
CHECKOUT_TOTAL_MISMATCH: {
|
|
1463
|
+
status: 409,
|
|
1464
|
+
message: "The order total increased. Please review the updated total.",
|
|
1465
|
+
data: CheckoutTotalMismatchData
|
|
1466
|
+
},
|
|
1457
1467
|
CHECKOUT_CART_INVALID: {
|
|
1458
1468
|
status: 409,
|
|
1459
1469
|
message: "An item in the cart is no longer valid.",
|
|
@@ -1599,7 +1609,6 @@ const Checkout = z$2.object({
|
|
|
1599
1609
|
paymentMethod: z$2.string().nullable(),
|
|
1600
1610
|
paymentResult: CheckoutPaymentResult.nullable(),
|
|
1601
1611
|
additionalFields: CheckoutAdditionalFields,
|
|
1602
|
-
cart: Cart.nullable(),
|
|
1603
1612
|
extensions: CheckoutExtensions
|
|
1604
1613
|
});
|
|
1605
1614
|
const UpdateCheckoutInput = z$2.object({
|
|
@@ -1613,6 +1622,7 @@ const ConfirmCheckoutInput = z$2.object({
|
|
|
1613
1622
|
billingAddress: CartBillingAddressSubmission,
|
|
1614
1623
|
shippingAddress: CartShippingAddressSubmission.optional(),
|
|
1615
1624
|
paymentMethod: z$2.string(),
|
|
1625
|
+
expectedTotal: z$2.string().regex(/^[0-9]+$/).optional(),
|
|
1616
1626
|
customerNote: z$2.string().optional(),
|
|
1617
1627
|
createAccount: z$2.boolean().optional(),
|
|
1618
1628
|
customerPassword: z$2.string().optional(),
|
|
@@ -1667,7 +1677,6 @@ function deserializeCheckout(data) {
|
|
|
1667
1677
|
redirectUrl: paymentResult.redirect_url === "" ? null : paymentResult.redirect_url
|
|
1668
1678
|
},
|
|
1669
1679
|
additionalFields: checkoutAdditionalFields(data.additional_fields),
|
|
1670
|
-
cart: data.__experimentalCart ? deserializeCart(data.__experimentalCart) : null,
|
|
1671
1680
|
extensions
|
|
1672
1681
|
};
|
|
1673
1682
|
}
|
|
@@ -1704,14 +1713,17 @@ function checkoutAdditionalFields(fields) {
|
|
|
1704
1713
|
|
|
1705
1714
|
//#endregion
|
|
1706
1715
|
//#region src/checkout/index.ts
|
|
1707
|
-
const
|
|
1716
|
+
const createCheckoutProcedures = (allowGuest = true) => ({
|
|
1708
1717
|
get: createProcedure({
|
|
1709
1718
|
scope: "api",
|
|
1710
1719
|
method: "GET",
|
|
1711
1720
|
path: "/checkout",
|
|
1712
1721
|
output: schemaType(Checkout),
|
|
1713
1722
|
errors: GET_CHECKOUT_ERROR_MAP,
|
|
1714
|
-
middlewares: [sessionMiddleware({
|
|
1723
|
+
middlewares: [sessionMiddleware({
|
|
1724
|
+
transitionGuestCart: true,
|
|
1725
|
+
allowGuest
|
|
1726
|
+
})]
|
|
1715
1727
|
}, async ({ context, errors }) => {
|
|
1716
1728
|
const response = await context.wordpress.woocommerce.store.checkout.retrieve({}, { headers: context.sessionHeaders });
|
|
1717
1729
|
if (response.error) {
|
|
@@ -1728,7 +1740,10 @@ const checkoutProcedures = {
|
|
|
1728
1740
|
body: schemaType(UpdateCheckoutInput),
|
|
1729
1741
|
output: schemaType(Checkout),
|
|
1730
1742
|
errors: UPDATE_CHECKOUT_ERROR_MAP,
|
|
1731
|
-
middlewares: [sessionMiddleware({
|
|
1743
|
+
middlewares: [sessionMiddleware({
|
|
1744
|
+
transitionGuestCart: true,
|
|
1745
|
+
allowGuest
|
|
1746
|
+
})]
|
|
1732
1747
|
}, async ({ context, input, errors }) => {
|
|
1733
1748
|
const response = await context.wordpress.woocommerce.store.checkout.update({ body: {
|
|
1734
1749
|
order_notes: input.body.customerNote,
|
|
@@ -1782,13 +1797,17 @@ const checkoutProcedures = {
|
|
|
1782
1797
|
body: schemaType(ConfirmCheckoutInput),
|
|
1783
1798
|
output: schemaType(Checkout),
|
|
1784
1799
|
errors: CONFIRM_CHECKOUT_ERROR_MAP,
|
|
1785
|
-
middlewares: [sessionMiddleware({
|
|
1800
|
+
middlewares: [sessionMiddleware({
|
|
1801
|
+
transitionGuestCart: true,
|
|
1802
|
+
allowGuest
|
|
1803
|
+
})]
|
|
1786
1804
|
}, async ({ context, input, errors }) => {
|
|
1787
1805
|
const response = await context.wordpress.woocommerce.store.checkout.create({ body: {
|
|
1788
1806
|
billing_address: serializeCheckoutBillingAddress(input.body.billingAddress),
|
|
1789
1807
|
shipping_address: input.body.shippingAddress ? serializeCheckoutShippingAddress(input.body.shippingAddress) : void 0,
|
|
1790
1808
|
payment_method: gateway(input.body.paymentMethod),
|
|
1791
1809
|
customer_note: input.body.customerNote,
|
|
1810
|
+
...input.body.expectedTotal !== void 0 && { expected_total: input.body.expectedTotal },
|
|
1792
1811
|
create_account: input.body.createAccount ?? false,
|
|
1793
1812
|
customer_password: input.body.customerPassword,
|
|
1794
1813
|
payment_data: input.body.paymentData,
|
|
@@ -1832,6 +1851,10 @@ const checkoutProcedures = {
|
|
|
1832
1851
|
message: response.error.message,
|
|
1833
1852
|
data: conflict
|
|
1834
1853
|
});
|
|
1854
|
+
case "woocommerce_rest_checkout_total_mismatch": throw errors.CHECKOUT_TOTAL_MISMATCH({
|
|
1855
|
+
message: response.error.message,
|
|
1856
|
+
data: totalMismatchData(response.error.data)
|
|
1857
|
+
});
|
|
1835
1858
|
case "woocommerce_rest_coupon_reserve_failed": throw errors.CHECKOUT_COUPON_RESERVATION_FAILED({
|
|
1836
1859
|
message: response.error.message,
|
|
1837
1860
|
data: conflict
|
|
@@ -1864,7 +1887,10 @@ const checkoutProcedures = {
|
|
|
1864
1887
|
body: schemaType(RetryCheckoutInput.omit({ orderId: true })),
|
|
1865
1888
|
output: schemaType(Checkout),
|
|
1866
1889
|
errors: RETRY_CHECKOUT_ERROR_MAP,
|
|
1867
|
-
middlewares: [sessionMiddleware({
|
|
1890
|
+
middlewares: [sessionMiddleware({
|
|
1891
|
+
transitionGuestCart: true,
|
|
1892
|
+
allowGuest
|
|
1893
|
+
})]
|
|
1868
1894
|
}, async ({ context, input, errors }) => {
|
|
1869
1895
|
const response = await context.wordpress.woocommerce.store.checkout.updateById({
|
|
1870
1896
|
params: { id: String(input.params.orderId) },
|
|
@@ -1906,7 +1932,7 @@ const checkoutProcedures = {
|
|
|
1906
1932
|
}
|
|
1907
1933
|
return deserializeCheckout(response.data);
|
|
1908
1934
|
})
|
|
1909
|
-
};
|
|
1935
|
+
});
|
|
1910
1936
|
function conflictData(data) {
|
|
1911
1937
|
if (!isRecord(data) || !isRecord(data.cart)) return { cart: null };
|
|
1912
1938
|
try {
|
|
@@ -1918,8 +1944,21 @@ function conflictData(data) {
|
|
|
1918
1944
|
function isRecord(value) {
|
|
1919
1945
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1920
1946
|
}
|
|
1921
|
-
|
|
1922
|
-
const
|
|
1947
|
+
function totalMismatchData(data) {
|
|
1948
|
+
const { cart } = conflictData(data);
|
|
1949
|
+
const expectedTotal = minorUnitTotal(isRecord(data) ? data.expected_total : void 0);
|
|
1950
|
+
const actualTotal = minorUnitTotal(isRecord(data) ? data.actual_total : void 0);
|
|
1951
|
+
return {
|
|
1952
|
+
cart: Cart.safeParse(cart).success ? cart : null,
|
|
1953
|
+
...expectedTotal !== void 0 && { expectedTotal },
|
|
1954
|
+
...actualTotal !== void 0 && { actualTotal }
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
function minorUnitTotal(value) {
|
|
1958
|
+
if (typeof value === "string" && /^[0-9]+$/.test(value)) return value;
|
|
1959
|
+
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return String(value);
|
|
1960
|
+
}
|
|
1961
|
+
const CHECKOUT_PROCEDURES = createCheckoutProcedures();
|
|
1923
1962
|
|
|
1924
1963
|
//#endregion
|
|
1925
1964
|
//#region src/schema.ts
|
|
@@ -2647,7 +2686,7 @@ const STOREFRONT_PROCEDURES = { get: createProcedure({
|
|
|
2647
2686
|
|
|
2648
2687
|
//#endregion
|
|
2649
2688
|
//#region src/index.ts
|
|
2650
|
-
function woocommerce() {
|
|
2689
|
+
function woocommerce(options = {}) {
|
|
2651
2690
|
return createIntegration({
|
|
2652
2691
|
id: "woocommerce",
|
|
2653
2692
|
requires: {
|
|
@@ -2668,7 +2707,7 @@ function woocommerce() {
|
|
|
2668
2707
|
procedures: {
|
|
2669
2708
|
cart: CART_PROCEDURES,
|
|
2670
2709
|
products: PRODUCT_PROCEDURES,
|
|
2671
|
-
checkout:
|
|
2710
|
+
checkout: createCheckoutProcedures(options.allowGuest),
|
|
2672
2711
|
customers: CUSTOMER_PROCEDURES,
|
|
2673
2712
|
orders: ORDER_PROCEDURES,
|
|
2674
2713
|
storefront: STOREFRONT_PROCEDURES
|
|
@@ -127,8 +127,8 @@ declare const StorefrontField: z$2.ZodObject<{
|
|
|
127
127
|
id: z$2.ZodString;
|
|
128
128
|
location: z$2.ZodEnum<{
|
|
129
129
|
address: "address";
|
|
130
|
-
order: "order";
|
|
131
130
|
contact: "contact";
|
|
131
|
+
order: "order";
|
|
132
132
|
}>;
|
|
133
133
|
attributes: z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>;
|
|
134
134
|
schema: z$2.ZodUnion<readonly [z$2.ZodBoolean, z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>]>;
|
|
@@ -200,8 +200,8 @@ declare const StorefrontAddress: z$2.ZodObject<{
|
|
|
200
200
|
id: z$2.ZodString;
|
|
201
201
|
location: z$2.ZodEnum<{
|
|
202
202
|
address: "address";
|
|
203
|
-
order: "order";
|
|
204
203
|
contact: "contact";
|
|
204
|
+
order: "order";
|
|
205
205
|
}>;
|
|
206
206
|
attributes: z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>;
|
|
207
207
|
schema: z$2.ZodUnion<readonly [z$2.ZodBoolean, z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>]>;
|
|
@@ -295,8 +295,8 @@ declare const Storefront: z$2.ZodObject<{
|
|
|
295
295
|
id: z$2.ZodString;
|
|
296
296
|
location: z$2.ZodEnum<{
|
|
297
297
|
address: "address";
|
|
298
|
-
order: "order";
|
|
299
298
|
contact: "contact";
|
|
299
|
+
order: "order";
|
|
300
300
|
}>;
|
|
301
301
|
attributes: z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>;
|
|
302
302
|
schema: z$2.ZodUnion<readonly [z$2.ZodBoolean, z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizlo/woocommerce",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "WooCommerce integration for Kizlo.",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"zod": "^4.3.6"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"kizlo": ">=0.
|
|
63
|
+
"kizlo": ">=0.26.1"
|
|
64
64
|
}
|
|
65
65
|
}
|