@kizlo/woocommerce 0.15.0 → 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 +23 -0
- package/dist/checkout-validation.d.ts +1 -1
- package/dist/index.d.ts +1790 -2098
- package/dist/index.js +23 -13
- package/dist/{schema-ScTHhVY4.d.ts → schema-CWDJjtW7.d.ts} +3 -3
- 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) {
|
|
@@ -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({
|
|
@@ -1677,7 +1677,6 @@ function deserializeCheckout(data) {
|
|
|
1677
1677
|
redirectUrl: paymentResult.redirect_url === "" ? null : paymentResult.redirect_url
|
|
1678
1678
|
},
|
|
1679
1679
|
additionalFields: checkoutAdditionalFields(data.additional_fields),
|
|
1680
|
-
cart: data.__experimentalCart ? deserializeCart(data.__experimentalCart) : null,
|
|
1681
1680
|
extensions
|
|
1682
1681
|
};
|
|
1683
1682
|
}
|
|
@@ -1714,14 +1713,17 @@ function checkoutAdditionalFields(fields) {
|
|
|
1714
1713
|
|
|
1715
1714
|
//#endregion
|
|
1716
1715
|
//#region src/checkout/index.ts
|
|
1717
|
-
const
|
|
1716
|
+
const createCheckoutProcedures = (allowGuest = true) => ({
|
|
1718
1717
|
get: createProcedure({
|
|
1719
1718
|
scope: "api",
|
|
1720
1719
|
method: "GET",
|
|
1721
1720
|
path: "/checkout",
|
|
1722
1721
|
output: schemaType(Checkout),
|
|
1723
1722
|
errors: GET_CHECKOUT_ERROR_MAP,
|
|
1724
|
-
middlewares: [sessionMiddleware({
|
|
1723
|
+
middlewares: [sessionMiddleware({
|
|
1724
|
+
transitionGuestCart: true,
|
|
1725
|
+
allowGuest
|
|
1726
|
+
})]
|
|
1725
1727
|
}, async ({ context, errors }) => {
|
|
1726
1728
|
const response = await context.wordpress.woocommerce.store.checkout.retrieve({}, { headers: context.sessionHeaders });
|
|
1727
1729
|
if (response.error) {
|
|
@@ -1738,7 +1740,10 @@ const checkoutProcedures = {
|
|
|
1738
1740
|
body: schemaType(UpdateCheckoutInput),
|
|
1739
1741
|
output: schemaType(Checkout),
|
|
1740
1742
|
errors: UPDATE_CHECKOUT_ERROR_MAP,
|
|
1741
|
-
middlewares: [sessionMiddleware({
|
|
1743
|
+
middlewares: [sessionMiddleware({
|
|
1744
|
+
transitionGuestCart: true,
|
|
1745
|
+
allowGuest
|
|
1746
|
+
})]
|
|
1742
1747
|
}, async ({ context, input, errors }) => {
|
|
1743
1748
|
const response = await context.wordpress.woocommerce.store.checkout.update({ body: {
|
|
1744
1749
|
order_notes: input.body.customerNote,
|
|
@@ -1792,7 +1797,10 @@ const checkoutProcedures = {
|
|
|
1792
1797
|
body: schemaType(ConfirmCheckoutInput),
|
|
1793
1798
|
output: schemaType(Checkout),
|
|
1794
1799
|
errors: CONFIRM_CHECKOUT_ERROR_MAP,
|
|
1795
|
-
middlewares: [sessionMiddleware({
|
|
1800
|
+
middlewares: [sessionMiddleware({
|
|
1801
|
+
transitionGuestCart: true,
|
|
1802
|
+
allowGuest
|
|
1803
|
+
})]
|
|
1796
1804
|
}, async ({ context, input, errors }) => {
|
|
1797
1805
|
const response = await context.wordpress.woocommerce.store.checkout.create({ body: {
|
|
1798
1806
|
billing_address: serializeCheckoutBillingAddress(input.body.billingAddress),
|
|
@@ -1879,7 +1887,10 @@ const checkoutProcedures = {
|
|
|
1879
1887
|
body: schemaType(RetryCheckoutInput.omit({ orderId: true })),
|
|
1880
1888
|
output: schemaType(Checkout),
|
|
1881
1889
|
errors: RETRY_CHECKOUT_ERROR_MAP,
|
|
1882
|
-
middlewares: [sessionMiddleware({
|
|
1890
|
+
middlewares: [sessionMiddleware({
|
|
1891
|
+
transitionGuestCart: true,
|
|
1892
|
+
allowGuest
|
|
1893
|
+
})]
|
|
1883
1894
|
}, async ({ context, input, errors }) => {
|
|
1884
1895
|
const response = await context.wordpress.woocommerce.store.checkout.updateById({
|
|
1885
1896
|
params: { id: String(input.params.orderId) },
|
|
@@ -1921,7 +1932,7 @@ const checkoutProcedures = {
|
|
|
1921
1932
|
}
|
|
1922
1933
|
return deserializeCheckout(response.data);
|
|
1923
1934
|
})
|
|
1924
|
-
};
|
|
1935
|
+
});
|
|
1925
1936
|
function conflictData(data) {
|
|
1926
1937
|
if (!isRecord(data) || !isRecord(data.cart)) return { cart: null };
|
|
1927
1938
|
try {
|
|
@@ -1947,8 +1958,7 @@ function minorUnitTotal(value) {
|
|
|
1947
1958
|
if (typeof value === "string" && /^[0-9]+$/.test(value)) return value;
|
|
1948
1959
|
if (typeof value === "number" && Number.isSafeInteger(value) && value >= 0) return String(value);
|
|
1949
1960
|
}
|
|
1950
|
-
|
|
1951
|
-
const CHECKOUT_PROCEDURES = checkoutProcedures;
|
|
1961
|
+
const CHECKOUT_PROCEDURES = createCheckoutProcedures();
|
|
1952
1962
|
|
|
1953
1963
|
//#endregion
|
|
1954
1964
|
//#region src/schema.ts
|
|
@@ -2676,7 +2686,7 @@ const STOREFRONT_PROCEDURES = { get: createProcedure({
|
|
|
2676
2686
|
|
|
2677
2687
|
//#endregion
|
|
2678
2688
|
//#region src/index.ts
|
|
2679
|
-
function woocommerce() {
|
|
2689
|
+
function woocommerce(options = {}) {
|
|
2680
2690
|
return createIntegration({
|
|
2681
2691
|
id: "woocommerce",
|
|
2682
2692
|
requires: {
|
|
@@ -2697,7 +2707,7 @@ function woocommerce() {
|
|
|
2697
2707
|
procedures: {
|
|
2698
2708
|
cart: CART_PROCEDURES,
|
|
2699
2709
|
products: PRODUCT_PROCEDURES,
|
|
2700
|
-
checkout:
|
|
2710
|
+
checkout: createCheckoutProcedures(options.allowGuest),
|
|
2701
2711
|
customers: CUSTOMER_PROCEDURES,
|
|
2702
2712
|
orders: ORDER_PROCEDURES,
|
|
2703
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>]>;
|