@kizlo/woocommerce 0.15.0 → 0.17.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 +46 -3
- package/dist/index.d.ts +1849 -2115
- package/dist/index.js +40 -25
- package/package.json +1 -1
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) {
|
|
@@ -99,7 +100,7 @@ function sessionMiddleware(options) {
|
|
|
99
100
|
//#endregion
|
|
100
101
|
//#region src/cart/error.ts
|
|
101
102
|
const GET_CART_ERROR_MAP = defineErrorMap({});
|
|
102
|
-
const
|
|
103
|
+
const UPDATE_CART_ADDRESS_ERROR_MAP = defineErrorMap({ CART_ADDRESS_INVALID: {
|
|
103
104
|
status: 400,
|
|
104
105
|
message: "The cart address is invalid."
|
|
105
106
|
} });
|
|
@@ -709,7 +710,7 @@ const SelectCartShippingRateInput = z$1.object({
|
|
|
709
710
|
});
|
|
710
711
|
const CartShippingAddressInput = z$1.object(CartAddressFields).partial();
|
|
711
712
|
const CartBillingAddressInput = CartBillingAddress.partial().extend(BillingNativeInputFields);
|
|
712
|
-
const
|
|
713
|
+
const UpdateCartAddressInput = z$1.object({
|
|
713
714
|
shippingAddress: CartShippingAddressInput.optional(),
|
|
714
715
|
billingAddress: CartBillingAddressInput.optional()
|
|
715
716
|
});
|
|
@@ -1170,7 +1171,7 @@ const BILLING_ADDRESS_KEYS = new Set([...SHIPPING_ADDRESS_KEYS, "email"]);
|
|
|
1170
1171
|
function additionalAddressFields(address, standardKeys) {
|
|
1171
1172
|
return additionalFieldValues(Object.fromEntries(Object.entries(address).filter((entry) => !standardKeys.has(entry[0]) && (typeof entry[1] === "string" || typeof entry[1] === "boolean"))));
|
|
1172
1173
|
}
|
|
1173
|
-
function
|
|
1174
|
+
function serializeCartAddressInput(input) {
|
|
1174
1175
|
return {
|
|
1175
1176
|
...input.billingAddress !== void 0 && { billing_address: serializeCartBillingAddress(input.billingAddress) },
|
|
1176
1177
|
...input.shippingAddress !== void 0 && { shipping_address: serializeCartShippingAddress(input.shippingAddress) }
|
|
@@ -1215,16 +1216,16 @@ const CART_PROCEDURES = {
|
|
|
1215
1216
|
}
|
|
1216
1217
|
return deserializeCart(response.data);
|
|
1217
1218
|
}),
|
|
1218
|
-
|
|
1219
|
+
updateAddress: createProcedure({
|
|
1219
1220
|
scope: "api",
|
|
1220
1221
|
method: "PUT",
|
|
1221
1222
|
path: "/cart",
|
|
1222
1223
|
output: schemaType(Cart),
|
|
1223
|
-
body: schemaType(
|
|
1224
|
-
errors:
|
|
1224
|
+
body: schemaType(UpdateCartAddressInput),
|
|
1225
|
+
errors: UPDATE_CART_ADDRESS_ERROR_MAP,
|
|
1225
1226
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1226
1227
|
}, async ({ context, input: { body: input }, errors }) => {
|
|
1227
|
-
const response = await context.wordpress.woocommerce.store.cart.updateCustomer.create({ body:
|
|
1228
|
+
const response = await context.wordpress.woocommerce.store.cart.updateCustomer.create({ body: serializeCartAddressInput(input) }, { headers: context.sessionHeaders });
|
|
1228
1229
|
if (response.error) switch (response.error.code) {
|
|
1229
1230
|
case "rest_invalid_param":
|
|
1230
1231
|
case "woocommerce_rest_invalid_address":
|
|
@@ -1608,7 +1609,6 @@ const Checkout = z$2.object({
|
|
|
1608
1609
|
paymentMethod: z$2.string().nullable(),
|
|
1609
1610
|
paymentResult: CheckoutPaymentResult.nullable(),
|
|
1610
1611
|
additionalFields: CheckoutAdditionalFields,
|
|
1611
|
-
cart: Cart.nullable(),
|
|
1612
1612
|
extensions: CheckoutExtensions
|
|
1613
1613
|
});
|
|
1614
1614
|
const UpdateCheckoutInput = z$2.object({
|
|
@@ -1618,9 +1618,14 @@ const UpdateCheckoutInput = z$2.object({
|
|
|
1618
1618
|
additionalFields: CheckoutAdditionalFields.optional(),
|
|
1619
1619
|
extensions: CheckoutExtensions.optional()
|
|
1620
1620
|
});
|
|
1621
|
+
const CheckoutBillingAddressInput = CartBillingAddressSubmission.partial().extend({
|
|
1622
|
+
...BillingNativeInputFields,
|
|
1623
|
+
additionalFields: CartBillingAddressSubmission.shape.additionalFields
|
|
1624
|
+
});
|
|
1625
|
+
const CheckoutShippingAddressInput = CartShippingAddressSubmission.partial().extend({ additionalFields: CartShippingAddressSubmission.shape.additionalFields });
|
|
1621
1626
|
const ConfirmCheckoutInput = z$2.object({
|
|
1622
|
-
billingAddress:
|
|
1623
|
-
shippingAddress:
|
|
1627
|
+
billingAddress: CheckoutBillingAddressInput,
|
|
1628
|
+
shippingAddress: CheckoutShippingAddressInput.optional(),
|
|
1624
1629
|
paymentMethod: z$2.string(),
|
|
1625
1630
|
expectedTotal: z$2.string().regex(/^[0-9]+$/).optional(),
|
|
1626
1631
|
customerNote: z$2.string().optional(),
|
|
@@ -1637,9 +1642,9 @@ const RetryCheckoutInput = z$2.object({
|
|
|
1637
1642
|
orderId: NumberLike,
|
|
1638
1643
|
paymentMethod: z$2.string(),
|
|
1639
1644
|
billingEmail: z$2.email().optional(),
|
|
1640
|
-
billingAddress:
|
|
1645
|
+
billingAddress: CheckoutBillingAddressInput,
|
|
1641
1646
|
paymentData: CheckoutPaymentData.optional(),
|
|
1642
|
-
shippingAddress:
|
|
1647
|
+
shippingAddress: CheckoutShippingAddressInput.optional(),
|
|
1643
1648
|
customerNote: z$2.string().optional(),
|
|
1644
1649
|
additionalFields: CheckoutAdditionalFieldsSubmissionSchema.optional(),
|
|
1645
1650
|
extensions: CheckoutExtensions.optional(),
|
|
@@ -1677,7 +1682,6 @@ function deserializeCheckout(data) {
|
|
|
1677
1682
|
redirectUrl: paymentResult.redirect_url === "" ? null : paymentResult.redirect_url
|
|
1678
1683
|
},
|
|
1679
1684
|
additionalFields: checkoutAdditionalFields(data.additional_fields),
|
|
1680
|
-
cart: data.__experimentalCart ? deserializeCart(data.__experimentalCart) : null,
|
|
1681
1685
|
extensions
|
|
1682
1686
|
};
|
|
1683
1687
|
}
|
|
@@ -1714,14 +1718,17 @@ function checkoutAdditionalFields(fields) {
|
|
|
1714
1718
|
|
|
1715
1719
|
//#endregion
|
|
1716
1720
|
//#region src/checkout/index.ts
|
|
1717
|
-
const
|
|
1721
|
+
const createCheckoutProcedures = (allowGuest = true) => ({
|
|
1718
1722
|
get: createProcedure({
|
|
1719
1723
|
scope: "api",
|
|
1720
1724
|
method: "GET",
|
|
1721
1725
|
path: "/checkout",
|
|
1722
1726
|
output: schemaType(Checkout),
|
|
1723
1727
|
errors: GET_CHECKOUT_ERROR_MAP,
|
|
1724
|
-
middlewares: [sessionMiddleware({
|
|
1728
|
+
middlewares: [sessionMiddleware({
|
|
1729
|
+
transitionGuestCart: true,
|
|
1730
|
+
allowGuest
|
|
1731
|
+
})]
|
|
1725
1732
|
}, async ({ context, errors }) => {
|
|
1726
1733
|
const response = await context.wordpress.woocommerce.store.checkout.retrieve({}, { headers: context.sessionHeaders });
|
|
1727
1734
|
if (response.error) {
|
|
@@ -1738,7 +1745,10 @@ const checkoutProcedures = {
|
|
|
1738
1745
|
body: schemaType(UpdateCheckoutInput),
|
|
1739
1746
|
output: schemaType(Checkout),
|
|
1740
1747
|
errors: UPDATE_CHECKOUT_ERROR_MAP,
|
|
1741
|
-
middlewares: [sessionMiddleware({
|
|
1748
|
+
middlewares: [sessionMiddleware({
|
|
1749
|
+
transitionGuestCart: true,
|
|
1750
|
+
allowGuest
|
|
1751
|
+
})]
|
|
1742
1752
|
}, async ({ context, input, errors }) => {
|
|
1743
1753
|
const response = await context.wordpress.woocommerce.store.checkout.update({ body: {
|
|
1744
1754
|
order_notes: input.body.customerNote,
|
|
@@ -1792,7 +1802,10 @@ const checkoutProcedures = {
|
|
|
1792
1802
|
body: schemaType(ConfirmCheckoutInput),
|
|
1793
1803
|
output: schemaType(Checkout),
|
|
1794
1804
|
errors: CONFIRM_CHECKOUT_ERROR_MAP,
|
|
1795
|
-
middlewares: [sessionMiddleware({
|
|
1805
|
+
middlewares: [sessionMiddleware({
|
|
1806
|
+
transitionGuestCart: true,
|
|
1807
|
+
allowGuest
|
|
1808
|
+
})]
|
|
1796
1809
|
}, async ({ context, input, errors }) => {
|
|
1797
1810
|
const response = await context.wordpress.woocommerce.store.checkout.create({ body: {
|
|
1798
1811
|
billing_address: serializeCheckoutBillingAddress(input.body.billingAddress),
|
|
@@ -1879,7 +1892,10 @@ const checkoutProcedures = {
|
|
|
1879
1892
|
body: schemaType(RetryCheckoutInput.omit({ orderId: true })),
|
|
1880
1893
|
output: schemaType(Checkout),
|
|
1881
1894
|
errors: RETRY_CHECKOUT_ERROR_MAP,
|
|
1882
|
-
middlewares: [sessionMiddleware({
|
|
1895
|
+
middlewares: [sessionMiddleware({
|
|
1896
|
+
transitionGuestCart: true,
|
|
1897
|
+
allowGuest
|
|
1898
|
+
})]
|
|
1883
1899
|
}, async ({ context, input, errors }) => {
|
|
1884
1900
|
const response = await context.wordpress.woocommerce.store.checkout.updateById({
|
|
1885
1901
|
params: { id: String(input.params.orderId) },
|
|
@@ -1921,7 +1937,7 @@ const checkoutProcedures = {
|
|
|
1921
1937
|
}
|
|
1922
1938
|
return deserializeCheckout(response.data);
|
|
1923
1939
|
})
|
|
1924
|
-
};
|
|
1940
|
+
});
|
|
1925
1941
|
function conflictData(data) {
|
|
1926
1942
|
if (!isRecord(data) || !isRecord(data.cart)) return { cart: null };
|
|
1927
1943
|
try {
|
|
@@ -1947,8 +1963,7 @@ function minorUnitTotal(value) {
|
|
|
1947
1963
|
if (typeof value === "string" && /^[0-9]+$/.test(value)) return value;
|
|
1948
1964
|
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return String(value);
|
|
1949
1965
|
}
|
|
1950
|
-
|
|
1951
|
-
const CHECKOUT_PROCEDURES = checkoutProcedures;
|
|
1966
|
+
const CHECKOUT_PROCEDURES = createCheckoutProcedures();
|
|
1952
1967
|
|
|
1953
1968
|
//#endregion
|
|
1954
1969
|
//#region src/schema.ts
|
|
@@ -2676,7 +2691,7 @@ const STOREFRONT_PROCEDURES = { get: createProcedure({
|
|
|
2676
2691
|
|
|
2677
2692
|
//#endregion
|
|
2678
2693
|
//#region src/index.ts
|
|
2679
|
-
function woocommerce() {
|
|
2694
|
+
function woocommerce(options = {}) {
|
|
2680
2695
|
return createIntegration({
|
|
2681
2696
|
id: "woocommerce",
|
|
2682
2697
|
requires: {
|
|
@@ -2697,7 +2712,7 @@ function woocommerce() {
|
|
|
2697
2712
|
procedures: {
|
|
2698
2713
|
cart: CART_PROCEDURES,
|
|
2699
2714
|
products: PRODUCT_PROCEDURES,
|
|
2700
|
-
checkout:
|
|
2715
|
+
checkout: createCheckoutProcedures(options.allowGuest),
|
|
2701
2716
|
customers: CUSTOMER_PROCEDURES,
|
|
2702
2717
|
orders: ORDER_PROCEDURES,
|
|
2703
2718
|
storefront: STOREFRONT_PROCEDURES
|
|
@@ -2706,4 +2721,4 @@ function woocommerce() {
|
|
|
2706
2721
|
}
|
|
2707
2722
|
|
|
2708
2723
|
//#endregion
|
|
2709
|
-
export { AddCartItemInput, ApplyCouponInput, BillingFieldProjections, Cart, CartAdditionalFields, CartBillingAddress, CartBillingAddressSubmission, CartCoupon, CartCouponTotals, CartError, CartFee, CartFeeTotals, CartItem, CartItemData, CartItemQuantityLimits, CartItemTotals, CartPaymentMethod, CartSelectedAttribute, CartShippingAddress, CartShippingAddressSubmission, CartShippingDestination, CartShippingItem, CartShippingPackage, CartShippingRate, CartShippingRateMetadata, CartTaxLine, CartTotals, Checkout, CheckoutAdditionalFields, CheckoutExtensions, CheckoutPaymentData, CheckoutPaymentResult, CheckoutRegisteredFieldReference, CheckoutValidationData, CheckoutValidationIssue, ConfirmCheckoutInput, GetOrderInput, ListProductInput, Order, OrderFee, OrderItem, OrderItemProduct, OrderTotals, PRODUCT_ATTRIBUTE_RELATIONS, PRODUCT_CATALOG_VISIBILITIES, PRODUCT_DATE_COLUMNS, PRODUCT_RATINGS, PRODUCT_STOCK_STATUSES, PRODUCT_TYPES, Product, ProductAddToCart, ProductAttributeCount, ProductAttributeFilter, ProductAttributeRelation, ProductAttributeSummary, ProductAttributeTermSummary, ProductBrandSummary, ProductCatalogVisibility, ProductCategorySummary, ProductCustomFieldsSchema, ProductDateColumn, ProductDimensions, ProductExtensions, ProductFilters, ProductFiltersAttributeTerm, ProductFiltersPriceRange, ProductFiltersRatingCount, ProductFiltersStockStatus, ProductFiltersTaxonomyTerm, ProductFiltersTerm, ProductList, ProductOrderBy, ProductPriceRange, ProductPrices, ProductRating, ProductRecommendations, ProductStockAvailability, ProductStockStatus, ProductSummary, ProductTagSummary, ProductTaxonomyFilter, ProductTaxonomyOperator, ProductTermSummary, ProductType, ProductVariationAttributeSummary, ProductVariationSummary, RemoveCartItemInput, RemoveCouponInput, RetrieveProductFiltersInput, RetrieveProductInput, RetryCheckoutInput, SWATCH_TYPES, SelectCartShippingRateInput, Storefront, StorefrontAddress, StorefrontCatalog, StorefrontCheckout, StorefrontCountry, StorefrontField, StorefrontFieldOption, StorefrontFieldOverride, StorefrontFieldRule, StorefrontFieldSchema, StorefrontPricing, SwatchType,
|
|
2724
|
+
export { AddCartItemInput, ApplyCouponInput, BillingFieldProjections, Cart, CartAdditionalFields, CartBillingAddress, CartBillingAddressSubmission, CartCoupon, CartCouponTotals, CartError, CartFee, CartFeeTotals, CartItem, CartItemData, CartItemQuantityLimits, CartItemTotals, CartPaymentMethod, CartSelectedAttribute, CartShippingAddress, CartShippingAddressSubmission, CartShippingDestination, CartShippingItem, CartShippingPackage, CartShippingRate, CartShippingRateMetadata, CartTaxLine, CartTotals, Checkout, CheckoutAdditionalFields, CheckoutBillingAddressInput, CheckoutExtensions, CheckoutPaymentData, CheckoutPaymentResult, CheckoutRegisteredFieldReference, CheckoutShippingAddressInput, CheckoutValidationData, CheckoutValidationIssue, ConfirmCheckoutInput, GetOrderInput, ListProductInput, Order, OrderFee, OrderItem, OrderItemProduct, OrderTotals, PRODUCT_ATTRIBUTE_RELATIONS, PRODUCT_CATALOG_VISIBILITIES, PRODUCT_DATE_COLUMNS, PRODUCT_RATINGS, PRODUCT_STOCK_STATUSES, PRODUCT_TYPES, Product, ProductAddToCart, ProductAttributeCount, ProductAttributeFilter, ProductAttributeRelation, ProductAttributeSummary, ProductAttributeTermSummary, ProductBrandSummary, ProductCatalogVisibility, ProductCategorySummary, ProductCustomFieldsSchema, ProductDateColumn, ProductDimensions, ProductExtensions, ProductFilters, ProductFiltersAttributeTerm, ProductFiltersPriceRange, ProductFiltersRatingCount, ProductFiltersStockStatus, ProductFiltersTaxonomyTerm, ProductFiltersTerm, ProductList, ProductOrderBy, ProductPriceRange, ProductPrices, ProductRating, ProductRecommendations, ProductStockAvailability, ProductStockStatus, ProductSummary, ProductTagSummary, ProductTaxonomyFilter, ProductTaxonomyOperator, ProductTermSummary, ProductType, ProductVariationAttributeSummary, ProductVariationSummary, RemoveCartItemInput, RemoveCouponInput, RetrieveProductFiltersInput, RetrieveProductInput, RetryCheckoutInput, SWATCH_TYPES, SelectCartShippingRateInput, Storefront, StorefrontAddress, StorefrontCatalog, StorefrontCheckout, StorefrontCountry, StorefrontField, StorefrontFieldOption, StorefrontFieldOverride, StorefrontFieldRule, StorefrontFieldSchema, StorefrontPricing, SwatchType, UpdateCartAddressInput, UpdateCartItemInput, UpdateCheckoutInput, resolveRegisteredFieldTarget, woocommerce };
|