@kizlo/woocommerce 0.6.1 → 0.8.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/dist/index.d.ts +16 -8
- package/dist/index.js +78 -51
- package/dist/test.d.ts +2 -2
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import * as zod_v4_core0 from "zod/v4/core";
|
|
|
8
8
|
//#region src/product/types.d.ts
|
|
9
9
|
|
|
10
10
|
/** The exact resolved custom-field shape configured for products on this WordPress site. */
|
|
11
|
-
type ProductCustomFields = WP_CustomFields<"postTypes.product">;
|
|
11
|
+
type ProductCustomFields = WP_CustomFields<"kizlo.postTypes.product">;
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/cart/schema.d.ts
|
|
14
14
|
declare const CartAdditionalFields: z$1.ZodRecord<z$1.ZodString, z$1.ZodUnion<readonly [z$1.ZodString, z$1.ZodBoolean]>>;
|
|
@@ -1042,6 +1042,8 @@ declare const ConfirmCheckoutInput: z$2.ZodObject<{
|
|
|
1042
1042
|
}, z$2.core.$strip>>>;
|
|
1043
1043
|
additionalFields: z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodUnion<readonly [z$2.ZodString, z$2.ZodBoolean]>>>;
|
|
1044
1044
|
extensions: z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>>;
|
|
1045
|
+
successPath: z$2.ZodOptional<z$2.ZodString>;
|
|
1046
|
+
cancelPath: z$2.ZodOptional<z$2.ZodString>;
|
|
1045
1047
|
}, z$2.core.$strip>;
|
|
1046
1048
|
type ConfirmCheckoutInput = z$2.input<typeof ConfirmCheckoutInput>;
|
|
1047
1049
|
declare const RetryCheckoutInput: z$2.ZodObject<{
|
|
@@ -1083,6 +1085,8 @@ declare const RetryCheckoutInput: z$2.ZodObject<{
|
|
|
1083
1085
|
customerNote: z$2.ZodOptional<z$2.ZodString>;
|
|
1084
1086
|
additionalFields: z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodUnion<readonly [z$2.ZodString, z$2.ZodBoolean]>>>;
|
|
1085
1087
|
extensions: z$2.ZodOptional<z$2.ZodRecord<z$2.ZodString, z$2.ZodUnknown>>;
|
|
1088
|
+
successPath: z$2.ZodOptional<z$2.ZodString>;
|
|
1089
|
+
cancelPath: z$2.ZodOptional<z$2.ZodString>;
|
|
1086
1090
|
}, z$2.core.$strip>;
|
|
1087
1091
|
type RetryCheckoutInput = z$2.input<typeof RetryCheckoutInput>;
|
|
1088
1092
|
//#endregion
|
|
@@ -2975,8 +2979,8 @@ declare const ProductStockStatus: z.ZodEnum<{
|
|
|
2975
2979
|
type ProductStockStatus = z.infer<typeof ProductStockStatus>;
|
|
2976
2980
|
declare const PRODUCT_CATALOG_VISIBILITIES: readonly ["any", "visible", "catalog", "search", "hidden"];
|
|
2977
2981
|
declare const ProductCatalogVisibility: z.ZodEnum<{
|
|
2978
|
-
any: "any";
|
|
2979
2982
|
search: "search";
|
|
2983
|
+
any: "any";
|
|
2980
2984
|
visible: "visible";
|
|
2981
2985
|
catalog: "catalog";
|
|
2982
2986
|
hidden: "hidden";
|
|
@@ -3091,8 +3095,8 @@ declare const ListProductInput: z.ZodObject<{
|
|
|
3091
3095
|
and: "and";
|
|
3092
3096
|
}>>;
|
|
3093
3097
|
catalogVisibility: z.ZodOptional<z.ZodEnum<{
|
|
3094
|
-
any: "any";
|
|
3095
3098
|
search: "search";
|
|
3099
|
+
any: "any";
|
|
3096
3100
|
visible: "visible";
|
|
3097
3101
|
catalog: "catalog";
|
|
3098
3102
|
hidden: "hidden";
|
|
@@ -3260,12 +3264,13 @@ declare const ProductAttributeCount: z.ZodObject<{
|
|
|
3260
3264
|
}, z.core.$strip>;
|
|
3261
3265
|
type ProductAttributeCount = z.input<typeof ProductAttributeCount>;
|
|
3262
3266
|
declare const RetrieveProductFiltersInput: z.ZodObject<{
|
|
3267
|
+
search: z.ZodOptional<z.ZodString>;
|
|
3263
3268
|
type: z.ZodOptional<z.ZodString>;
|
|
3264
3269
|
sku: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
3265
3270
|
slug: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
3266
3271
|
catalogVisibility: z.ZodOptional<z.ZodEnum<{
|
|
3267
|
-
any: "any";
|
|
3268
3272
|
search: "search";
|
|
3273
|
+
any: "any";
|
|
3269
3274
|
visible: "visible";
|
|
3270
3275
|
catalog: "catalog";
|
|
3271
3276
|
hidden: "hidden";
|
|
@@ -3284,7 +3289,6 @@ declare const RetrieveProductFiltersInput: z.ZodObject<{
|
|
|
3284
3289
|
asc: "asc";
|
|
3285
3290
|
desc: "desc";
|
|
3286
3291
|
}>>;
|
|
3287
|
-
search: z.ZodOptional<z.ZodString>;
|
|
3288
3292
|
related: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodCoercedNumber<string | number>>>;
|
|
3289
3293
|
parent: z.ZodOptional<z.ZodUnion<readonly [z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodCoercedNumber<string | number>>, z.ZodArray<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodCoercedNumber<string | number>>>]>>;
|
|
3290
3294
|
page: z.ZodOptional<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodCoercedNumber<string | number>>>;
|
|
@@ -6053,7 +6057,7 @@ declare function woocommerce(): kizlo0.Integration<"woocommerce", {
|
|
|
6053
6057
|
operator?: "in" | "not_in" | "and" | undefined;
|
|
6054
6058
|
}[] | undefined;
|
|
6055
6059
|
attributeRelation?: "in" | "and" | undefined;
|
|
6056
|
-
catalogVisibility?: "
|
|
6060
|
+
catalogVisibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
|
|
6057
6061
|
rating?: string | number | (string | number)[] | undefined;
|
|
6058
6062
|
related?: string | number | undefined;
|
|
6059
6063
|
taxonomies?: {
|
|
@@ -6066,10 +6070,11 @@ declare function woocommerce(): kizlo0.Integration<"woocommerce", {
|
|
|
6066
6070
|
}, ProductList, {}>;
|
|
6067
6071
|
filters: kizlo0.Procedure<"api", {
|
|
6068
6072
|
query?: {
|
|
6073
|
+
search?: string | undefined;
|
|
6069
6074
|
type?: string | undefined;
|
|
6070
6075
|
sku?: string | string[] | undefined;
|
|
6071
6076
|
slug?: string | string[] | undefined;
|
|
6072
|
-
catalogVisibility?: "
|
|
6077
|
+
catalogVisibility?: "search" | "any" | "visible" | "catalog" | "hidden" | undefined;
|
|
6073
6078
|
attributes?: {
|
|
6074
6079
|
taxonomy: string;
|
|
6075
6080
|
slug?: string | string[] | undefined;
|
|
@@ -6077,7 +6082,6 @@ declare function woocommerce(): kizlo0.Integration<"woocommerce", {
|
|
|
6077
6082
|
operator?: "in" | "not_in" | "and" | undefined;
|
|
6078
6083
|
}[] | undefined;
|
|
6079
6084
|
order?: "asc" | "desc" | undefined;
|
|
6080
|
-
search?: string | undefined;
|
|
6081
6085
|
related?: string | number | undefined;
|
|
6082
6086
|
parent?: string | number | (string | number)[] | undefined;
|
|
6083
6087
|
page?: string | number | undefined;
|
|
@@ -8486,6 +8490,8 @@ declare function woocommerce(): kizlo0.Integration<"woocommerce", {
|
|
|
8486
8490
|
}[] | undefined;
|
|
8487
8491
|
additionalFields?: Record<string, string | boolean> | undefined;
|
|
8488
8492
|
extensions?: Record<string, unknown> | undefined;
|
|
8493
|
+
successPath?: string | undefined;
|
|
8494
|
+
cancelPath?: string | undefined;
|
|
8489
8495
|
};
|
|
8490
8496
|
}, {
|
|
8491
8497
|
orderId: number | null;
|
|
@@ -11067,6 +11073,8 @@ declare function woocommerce(): kizlo0.Integration<"woocommerce", {
|
|
|
11067
11073
|
key: string;
|
|
11068
11074
|
value: string | boolean;
|
|
11069
11075
|
}[] | undefined;
|
|
11076
|
+
successPath?: string | undefined;
|
|
11077
|
+
cancelPath?: string | undefined;
|
|
11070
11078
|
billingEmail?: string | undefined;
|
|
11071
11079
|
};
|
|
11072
11080
|
params: {
|
package/dist/index.js
CHANGED
|
@@ -1203,7 +1203,7 @@ const CART_PROCEDURES = {
|
|
|
1203
1203
|
errors: GET_CART_ERROR_MAP,
|
|
1204
1204
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1205
1205
|
}, async ({ context, errors }) => {
|
|
1206
|
-
const response = await context.wordpress.woocommerce.store.cart.
|
|
1206
|
+
const response = await context.wordpress.woocommerce.store.cart.retrieve({}, { headers: context.sessionHeaders });
|
|
1207
1207
|
if (response.error) switch (response.error.code) {
|
|
1208
1208
|
default:
|
|
1209
1209
|
context.logger.error("Get cart unhandled error", response.error, { code: response.error.code });
|
|
@@ -1220,7 +1220,7 @@ const CART_PROCEDURES = {
|
|
|
1220
1220
|
errors: UPDATE_CART_ERROR_MAP,
|
|
1221
1221
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1222
1222
|
}, async ({ context, input: { body: input }, errors }) => {
|
|
1223
|
-
const response = await context.wordpress.woocommerce.store.cart.updateCustomer(serializeCartUpdateInput(input), { headers: context.sessionHeaders });
|
|
1223
|
+
const response = await context.wordpress.woocommerce.store.cart.updateCustomer.create({ body: serializeCartUpdateInput(input) }, { headers: context.sessionHeaders });
|
|
1224
1224
|
if (response.error) switch (response.error.code) {
|
|
1225
1225
|
case "rest_invalid_param":
|
|
1226
1226
|
case "woocommerce_rest_invalid_address":
|
|
@@ -1242,10 +1242,10 @@ const CART_PROCEDURES = {
|
|
|
1242
1242
|
errors: SELECT_SHIPPING_RATE_ERROR_MAP,
|
|
1243
1243
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1244
1244
|
}, async ({ context, input: { body }, errors }) => {
|
|
1245
|
-
const response = await context.wordpress.woocommerce.store.cart.selectShippingRate({
|
|
1245
|
+
const response = await context.wordpress.woocommerce.store.cart.selectShippingRate.create({ body: {
|
|
1246
1246
|
rate_id: body.rateId,
|
|
1247
1247
|
package_id: body.packageId
|
|
1248
|
-
}, { headers: context.sessionHeaders });
|
|
1248
|
+
} }, { headers: context.sessionHeaders });
|
|
1249
1249
|
if (response.error) switch (response.error.code) {
|
|
1250
1250
|
case "woocommerce_rest_cart_shipping_rate_not_found": throw errors.CART_SHIPPING_RATE_NOT_FOUND({ message: response.error.message });
|
|
1251
1251
|
case "woocommerce_rest_shipping_disabled": throw errors.CART_SHIPPING_DISABLED({ message: response.error.message });
|
|
@@ -1265,11 +1265,11 @@ const CART_PROCEDURES = {
|
|
|
1265
1265
|
errors: ADD_CART_ITEM_ERROR_MAP,
|
|
1266
1266
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1267
1267
|
}, async ({ context, input: { body: input }, errors }) => {
|
|
1268
|
-
const response = await context.wordpress.woocommerce.store.cart.addItem({
|
|
1268
|
+
const response = await context.wordpress.woocommerce.store.cart.addItem.create({ body: {
|
|
1269
1269
|
id: input.variationId ?? input.productId,
|
|
1270
1270
|
quantity: input.quantity,
|
|
1271
1271
|
variation: input.selectedAttributes ?? []
|
|
1272
|
-
}, { headers: context.sessionHeaders });
|
|
1272
|
+
} }, { headers: context.sessionHeaders });
|
|
1273
1273
|
if (response.error) switch (response.error.code) {
|
|
1274
1274
|
case "woocommerce_rest_product_out_of_stock": throw errors.CART_ITEM_OUT_OF_STOCK({ message: response.error.message });
|
|
1275
1275
|
case "woocommerce_rest_product_partially_out_of_stock": throw errors.CART_ITEM_INSUFFICIENT_STOCK({ message: response.error.message });
|
|
@@ -1298,10 +1298,10 @@ const CART_PROCEDURES = {
|
|
|
1298
1298
|
errors: UPDATE_CART_ITEM_ERROR_MAP,
|
|
1299
1299
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1300
1300
|
}, async ({ context, input: { params, body }, errors }) => {
|
|
1301
|
-
const response = await context.wordpress.woocommerce.store.cart.updateItem({
|
|
1301
|
+
const response = await context.wordpress.woocommerce.store.cart.updateItem.create({ body: {
|
|
1302
1302
|
key: params.key,
|
|
1303
1303
|
quantity: body.quantity
|
|
1304
|
-
}, { headers: context.sessionHeaders });
|
|
1304
|
+
} }, { headers: context.sessionHeaders });
|
|
1305
1305
|
if (response.error) switch (response.error.code) {
|
|
1306
1306
|
case "woocommerce_rest_cart_invalid_key": throw errors.CART_ITEM_NOT_FOUND({ message: response.error.message });
|
|
1307
1307
|
case "woocommerce_rest_cart_invalid_product": throw errors.CART_PRODUCT_INVALID({ message: response.error.message });
|
|
@@ -1323,7 +1323,7 @@ const CART_PROCEDURES = {
|
|
|
1323
1323
|
errors: REMOVE_CART_ITEM_ERROR_MAP,
|
|
1324
1324
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1325
1325
|
}, async ({ context, input: { params }, errors }) => {
|
|
1326
|
-
const response = await context.wordpress.woocommerce.store.cart.removeItem({ key: params.key }, { headers: context.sessionHeaders });
|
|
1326
|
+
const response = await context.wordpress.woocommerce.store.cart.removeItem.create({ body: { key: params.key } }, { headers: context.sessionHeaders });
|
|
1327
1327
|
if (response.error) switch (response.error.code) {
|
|
1328
1328
|
case "woocommerce_rest_cart_invalid_key": throw errors.CART_ITEM_NOT_FOUND({ message: response.error.message });
|
|
1329
1329
|
default:
|
|
@@ -1343,7 +1343,7 @@ const CART_PROCEDURES = {
|
|
|
1343
1343
|
errors: APPLY_COUPON_ERROR_MAP,
|
|
1344
1344
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1345
1345
|
}, async ({ context, input: { body }, errors }) => {
|
|
1346
|
-
const response = await context.wordpress.woocommerce.store.cart.applyCoupon({ code: body.code }, { headers: context.sessionHeaders });
|
|
1346
|
+
const response = await context.wordpress.woocommerce.store.cart.applyCoupon.create({ body: { code: body.code } }, { headers: context.sessionHeaders });
|
|
1347
1347
|
if (response.error) switch (response.error.code) {
|
|
1348
1348
|
case "woocommerce_rest_cart_coupon_error": throw errors.CART_COUPON_INVALID({ message: response.error.message });
|
|
1349
1349
|
case "woocommerce_rest_cart_coupon_disabled": throw errors.CART_COUPON_DISABLED({ message: response.error.message });
|
|
@@ -1362,7 +1362,7 @@ const CART_PROCEDURES = {
|
|
|
1362
1362
|
errors: REMOVE_COUPON_ERROR_MAP,
|
|
1363
1363
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1364
1364
|
}, async ({ context, input, errors }) => {
|
|
1365
|
-
const response = await context.wordpress.woocommerce.store.cart.removeCoupon({ code: input.params.code }, { headers: context.sessionHeaders });
|
|
1365
|
+
const response = await context.wordpress.woocommerce.store.cart.removeCoupon.create({ body: { code: input.params.code } }, { headers: context.sessionHeaders });
|
|
1366
1366
|
if (response.error) switch (response.error.code) {
|
|
1367
1367
|
case "woocommerce_rest_cart_coupon_error": throw errors.CART_COUPON_INVALID({ message: response.error.message });
|
|
1368
1368
|
case "woocommerce_rest_cart_coupon_disabled": throw errors.CART_COUPON_DISABLED({ message: response.error.message });
|
|
@@ -1574,6 +1574,7 @@ const CheckoutPaymentData = z$2.array(z$2.object({
|
|
|
1574
1574
|
key: z$2.string(),
|
|
1575
1575
|
value: z$2.union([z$2.string(), z$2.boolean()])
|
|
1576
1576
|
}));
|
|
1577
|
+
const RelativePath = z$2.string().refine((value) => /^\/(?![/\\])/.test(value), "must be a relative path starting with a single '/'");
|
|
1577
1578
|
const CheckoutPaymentResult = z$2.object({
|
|
1578
1579
|
status: z$2.string(),
|
|
1579
1580
|
details: z$2.array(z$2.object({
|
|
@@ -1613,7 +1614,9 @@ const ConfirmCheckoutInput = z$2.object({
|
|
|
1613
1614
|
customerPassword: z$2.string().optional(),
|
|
1614
1615
|
paymentData: CheckoutPaymentData.optional(),
|
|
1615
1616
|
additionalFields: CheckoutAdditionalFields.optional(),
|
|
1616
|
-
extensions: CheckoutExtensions.optional()
|
|
1617
|
+
extensions: CheckoutExtensions.optional(),
|
|
1618
|
+
successPath: RelativePath.optional(),
|
|
1619
|
+
cancelPath: RelativePath.optional()
|
|
1617
1620
|
});
|
|
1618
1621
|
const RetryCheckoutInput = z$2.object({
|
|
1619
1622
|
key: z$2.string(),
|
|
@@ -1625,7 +1628,9 @@ const RetryCheckoutInput = z$2.object({
|
|
|
1625
1628
|
shippingAddress: CartShippingAddress.optional(),
|
|
1626
1629
|
customerNote: z$2.string().optional(),
|
|
1627
1630
|
additionalFields: CheckoutAdditionalFields.optional(),
|
|
1628
|
-
extensions: CheckoutExtensions.optional()
|
|
1631
|
+
extensions: CheckoutExtensions.optional(),
|
|
1632
|
+
successPath: RelativePath.optional(),
|
|
1633
|
+
cancelPath: RelativePath.optional()
|
|
1629
1634
|
});
|
|
1630
1635
|
|
|
1631
1636
|
//#endregion
|
|
@@ -1661,6 +1666,27 @@ function deserializeCheckout(data) {
|
|
|
1661
1666
|
extensions
|
|
1662
1667
|
};
|
|
1663
1668
|
}
|
|
1669
|
+
/**
|
|
1670
|
+
* Fold the per-checkout redirect paths into `extensions.kizlo` so WooCommerce can
|
|
1671
|
+
* stamp them on the order and redirect there after checkout. Only defined paths
|
|
1672
|
+
* are added, and any existing `extensions.kizlo` block a caller passed is kept.
|
|
1673
|
+
* Returns the extensions unchanged when neither path is set.
|
|
1674
|
+
*/
|
|
1675
|
+
function withKizloRedirectPaths(extensions, paths) {
|
|
1676
|
+
const kizlo = {};
|
|
1677
|
+
if (paths.successPath !== void 0) kizlo.success_path = paths.successPath;
|
|
1678
|
+
if (paths.cancelPath !== void 0) kizlo.cancel_path = paths.cancelPath;
|
|
1679
|
+
if (Object.keys(kizlo).length === 0) return extensions;
|
|
1680
|
+
const existing = extensions?.kizlo;
|
|
1681
|
+
const existingKizlo = typeof existing === "object" && existing !== null && !Array.isArray(existing) ? existing : {};
|
|
1682
|
+
return {
|
|
1683
|
+
...extensions,
|
|
1684
|
+
kizlo: {
|
|
1685
|
+
...existingKizlo,
|
|
1686
|
+
...kizlo
|
|
1687
|
+
}
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1664
1690
|
function serializeCheckoutShippingAddress(address) {
|
|
1665
1691
|
return serializeCartShippingAddress(address);
|
|
1666
1692
|
}
|
|
@@ -1682,7 +1708,7 @@ const CHECKOUT_PROCEDURES = {
|
|
|
1682
1708
|
errors: GET_CHECKOUT_ERROR_MAP,
|
|
1683
1709
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1684
1710
|
}, async ({ context, errors }) => {
|
|
1685
|
-
const response = await context.wordpress.woocommerce.store.checkout.
|
|
1711
|
+
const response = await context.wordpress.woocommerce.store.checkout.retrieve({}, { headers: context.sessionHeaders });
|
|
1686
1712
|
if (response.error) {
|
|
1687
1713
|
if (response.error.code === "woocommerce_rest_checkout_missing_order") throw errors.CHECKOUT_ORDER_NOT_FOUND({ message: response.error.message });
|
|
1688
1714
|
context.logger.error("Get checkout unhandled error", response.error, { code: response.error.code });
|
|
@@ -1699,13 +1725,13 @@ const CHECKOUT_PROCEDURES = {
|
|
|
1699
1725
|
errors: UPDATE_CHECKOUT_ERROR_MAP,
|
|
1700
1726
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1701
1727
|
}, async ({ context, input, errors }) => {
|
|
1702
|
-
const response = await context.wordpress.woocommerce.store.checkout.update({
|
|
1728
|
+
const response = await context.wordpress.woocommerce.store.checkout.update({ body: {
|
|
1703
1729
|
order_notes: input.body.customerNote,
|
|
1704
1730
|
payment_method: gateway(input.body.paymentMethod),
|
|
1705
1731
|
additional_fields: input.body.additionalFields,
|
|
1706
1732
|
extensions: input.body.extensions,
|
|
1707
1733
|
__experimental_calc_totals: input.body.recalculateTotals
|
|
1708
|
-
}, { headers: context.sessionHeaders });
|
|
1734
|
+
} }, { headers: context.sessionHeaders });
|
|
1709
1735
|
if (response.error) {
|
|
1710
1736
|
const conflict = conflictData(response.error.data);
|
|
1711
1737
|
switch (response.error.code) {
|
|
@@ -1752,7 +1778,7 @@ const CHECKOUT_PROCEDURES = {
|
|
|
1752
1778
|
errors: CONFIRM_CHECKOUT_ERROR_MAP,
|
|
1753
1779
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1754
1780
|
}, async ({ context, input, errors }) => {
|
|
1755
|
-
const response = await context.wordpress.woocommerce.store.checkout.
|
|
1781
|
+
const response = await context.wordpress.woocommerce.store.checkout.create({ body: {
|
|
1756
1782
|
billing_address: serializeCheckoutBillingAddress(input.body.billingAddress),
|
|
1757
1783
|
shipping_address: input.body.shippingAddress ? serializeCheckoutShippingAddress(input.body.shippingAddress) : void 0,
|
|
1758
1784
|
payment_method: gateway(input.body.paymentMethod),
|
|
@@ -1761,8 +1787,11 @@ const CHECKOUT_PROCEDURES = {
|
|
|
1761
1787
|
customer_password: input.body.customerPassword,
|
|
1762
1788
|
payment_data: input.body.paymentData,
|
|
1763
1789
|
additional_fields: input.body.additionalFields,
|
|
1764
|
-
extensions: input.body.extensions
|
|
1765
|
-
|
|
1790
|
+
extensions: withKizloRedirectPaths(input.body.extensions, {
|
|
1791
|
+
successPath: input.body.successPath,
|
|
1792
|
+
cancelPath: input.body.cancelPath
|
|
1793
|
+
})
|
|
1794
|
+
} }, { headers: context.sessionHeaders });
|
|
1766
1795
|
if (response.error) {
|
|
1767
1796
|
const conflict = conflictData(response.error.data);
|
|
1768
1797
|
switch (response.error.code) {
|
|
@@ -1834,17 +1863,22 @@ const CHECKOUT_PROCEDURES = {
|
|
|
1834
1863
|
errors: RETRY_CHECKOUT_ERROR_MAP,
|
|
1835
1864
|
middlewares: [sessionMiddleware({ transitionGuestCart: true })]
|
|
1836
1865
|
}, async ({ context, input, errors }) => {
|
|
1837
|
-
const response = await context.wordpress.woocommerce.store.checkout.
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1866
|
+
const response = await context.wordpress.woocommerce.store.checkout.updateById({
|
|
1867
|
+
params: { id: String(input.params.orderId) },
|
|
1868
|
+
body: {
|
|
1869
|
+
key: input.body.key,
|
|
1870
|
+
payment_data: input.body.paymentData,
|
|
1871
|
+
billing_email: input.body.billingEmail,
|
|
1872
|
+
payment_method: gateway(input.body.paymentMethod),
|
|
1873
|
+
billing_address: serializeCheckoutBillingAddress(input.body.billingAddress),
|
|
1874
|
+
shipping_address: input.body.shippingAddress ? serializeCheckoutShippingAddress(input.body.shippingAddress) : void 0,
|
|
1875
|
+
customer_note: input.body.customerNote,
|
|
1876
|
+
additional_fields: input.body.additionalFields,
|
|
1877
|
+
extensions: withKizloRedirectPaths(input.body.extensions, {
|
|
1878
|
+
successPath: input.body.successPath,
|
|
1879
|
+
cancelPath: input.body.cancelPath
|
|
1880
|
+
})
|
|
1881
|
+
}
|
|
1848
1882
|
}, { headers: context.sessionHeaders });
|
|
1849
1883
|
if (response.error) switch (response.error.code) {
|
|
1850
1884
|
case "rest_invalid_param": throw errors.CHECKOUT_VALIDATION_FAILED({
|
|
@@ -1995,10 +2029,10 @@ const CUSTOMER_PROCEDURES = { get: createProcedure({
|
|
|
1995
2029
|
}, async ({ context, errors }) => {
|
|
1996
2030
|
const session = await context.getSession();
|
|
1997
2031
|
if (!session) throw errors.FORBIDDEN();
|
|
1998
|
-
const response = await context.wordpress.woocommerce.customers.list({
|
|
2032
|
+
const response = await context.wordpress.woocommerce.customers.list({ query: {
|
|
1999
2033
|
email: session.email,
|
|
2000
2034
|
role: "all"
|
|
2001
|
-
});
|
|
2035
|
+
} });
|
|
2002
2036
|
if (response.error) switch (response.error.code) {
|
|
2003
2037
|
case "woocommerce_rest_cannot_view": throw errors.FORBIDDEN();
|
|
2004
2038
|
default:
|
|
@@ -2241,10 +2275,12 @@ const ORDER_PROCEDURES = { get: createProcedure({
|
|
|
2241
2275
|
errors: GET_ORDER_ERROR_MAP,
|
|
2242
2276
|
middlewares: [sessionMiddleware()]
|
|
2243
2277
|
}, async ({ context, input, errors }) => {
|
|
2244
|
-
const response = await context.wordpress.woocommerce.store.
|
|
2245
|
-
id: input.params.orderId,
|
|
2246
|
-
|
|
2247
|
-
|
|
2278
|
+
const response = await context.wordpress.woocommerce.store.order.retrieve({
|
|
2279
|
+
params: { id: String(input.params.orderId) },
|
|
2280
|
+
query: {
|
|
2281
|
+
key: input.query?.key,
|
|
2282
|
+
billing_email: input.query?.billingEmail
|
|
2283
|
+
}
|
|
2248
2284
|
}, { headers: context.sessionHeaders });
|
|
2249
2285
|
if (response.error) switch (response.error.code) {
|
|
2250
2286
|
case "woocommerce_rest_invalid_order":
|
|
@@ -2289,7 +2325,7 @@ const PRODUCT_PROCEDURES = {
|
|
|
2289
2325
|
if (input.query?.previewToken) {
|
|
2290
2326
|
const result = await context.verifyPreviewToken(input.query.previewToken);
|
|
2291
2327
|
if (!result) throw errors.PRODUCT_NOT_FOUND();
|
|
2292
|
-
const response$1 = await context.wordpress.woocommerce.products.retrieve({ id: Number(result.id) });
|
|
2328
|
+
const response$1 = await context.wordpress.woocommerce.products.retrieve({ params: { id: Number(result.id) } });
|
|
2293
2329
|
if (response$1.error) switch (response$1.error.code) {
|
|
2294
2330
|
case "woocommerce_rest_product_invalid_id": throw errors.PRODUCT_NOT_FOUND({ message: response$1.error.message });
|
|
2295
2331
|
default:
|
|
@@ -2304,13 +2340,7 @@ const PRODUCT_PROCEDURES = {
|
|
|
2304
2340
|
const identifier = input.params.identifier;
|
|
2305
2341
|
const includeRecommendations = input.query?.recommendations ?? false;
|
|
2306
2342
|
const embeds = includeRecommendations ? { _embed: PRODUCT_EMBEDS } : {};
|
|
2307
|
-
const response = typeof identifier === "number" ? await context.wordpress.woocommerce.store.products.
|
|
2308
|
-
id: identifier,
|
|
2309
|
-
...embeds
|
|
2310
|
-
}) : await context.wordpress.woocommerce.store.products.getBySlug({
|
|
2311
|
-
slug: identifier,
|
|
2312
|
-
...embeds
|
|
2313
|
-
});
|
|
2343
|
+
const response = typeof identifier === "number" ? await context.wordpress.woocommerce.store.products.retrieve({ params: { id: identifier } }, { searchParams: embeds }) : await context.wordpress.woocommerce.store.products.retrieveBySlug({ params: { slug: identifier } }, { searchParams: embeds });
|
|
2314
2344
|
if (response.error) switch (response.error.code) {
|
|
2315
2345
|
case "woocommerce_rest_product_invalid_id":
|
|
2316
2346
|
case "woocommerce_rest_product_invalid_slug": throw errors.PRODUCT_NOT_FOUND({ message: response.error.message });
|
|
@@ -2334,10 +2364,7 @@ const PRODUCT_PROCEDURES = {
|
|
|
2334
2364
|
const searchParams = serializeProductListInput(input.query);
|
|
2335
2365
|
const includeRecommendations = input.query?.recommendations ?? false;
|
|
2336
2366
|
const embeds = includeRecommendations ? { _embed: PRODUCT_EMBEDS } : {};
|
|
2337
|
-
const response = await context.wordpress.woocommerce.store.products.list({
|
|
2338
|
-
...searchParams,
|
|
2339
|
-
...embeds
|
|
2340
|
-
});
|
|
2367
|
+
const response = await context.wordpress.woocommerce.store.products.list({ query: searchParams }, { searchParams: embeds });
|
|
2341
2368
|
if (response.error) switch (response.error.code) {
|
|
2342
2369
|
default:
|
|
2343
2370
|
context.logger.error("List products unhandled error", response.error, { code: response.error.code });
|
|
@@ -2361,7 +2388,7 @@ const PRODUCT_PROCEDURES = {
|
|
|
2361
2388
|
output: ProductFilters.nullable()
|
|
2362
2389
|
}, async ({ context, errors, input }) => {
|
|
2363
2390
|
const searchParams = serializeProductListInput(input.query);
|
|
2364
|
-
const response = await context.wordpress.woocommerce.store.products.collectionData({
|
|
2391
|
+
const response = await context.wordpress.woocommerce.store.products.collectionData.retrieve({ query: {
|
|
2365
2392
|
...searchParams,
|
|
2366
2393
|
calculate_price_range: true,
|
|
2367
2394
|
calculate_rating_counts: input.query?.ratingCounts,
|
|
@@ -2371,7 +2398,7 @@ const PRODUCT_PROCEDURES = {
|
|
|
2371
2398
|
taxonomy: item.taxonomy,
|
|
2372
2399
|
query_type: item.operator
|
|
2373
2400
|
}))
|
|
2374
|
-
});
|
|
2401
|
+
} });
|
|
2375
2402
|
if (response.error) switch (response.error.code) {
|
|
2376
2403
|
default:
|
|
2377
2404
|
context.logger.error("Filter products unhandled error", response.error, { code: response.error.code });
|
|
@@ -2396,7 +2423,7 @@ function woocommerce() {
|
|
|
2396
2423
|
"woocommerce.products",
|
|
2397
2424
|
"woocommerce.store.cart",
|
|
2398
2425
|
"woocommerce.store.checkout",
|
|
2399
|
-
"woocommerce.store.
|
|
2426
|
+
"woocommerce.store.order",
|
|
2400
2427
|
"woocommerce.store.products"
|
|
2401
2428
|
]
|
|
2402
2429
|
},
|
package/dist/test.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as kizlo0 from "kizlo";
|
|
2
2
|
import { DevPluginSource } from "kizlo/test";
|
|
3
3
|
|
|
4
4
|
//#region src/test/index.d.ts
|
|
@@ -20,6 +20,6 @@ declare const BANK_TRANSFER_DESCRIPTION = "Pay by transferring to our test bank
|
|
|
20
20
|
*/
|
|
21
21
|
declare function woocommerce(opts?: {
|
|
22
22
|
plugins?: DevPluginSource[];
|
|
23
|
-
}):
|
|
23
|
+
}): kizlo0.Fixture;
|
|
24
24
|
//#endregion
|
|
25
25
|
export { BANK_TRANSFER_DESCRIPTION, BANK_TRANSFER_TITLE, woocommerce };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizlo/woocommerce",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "WooCommerce integration for Kizlo.",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@kizlo/shared": "0.
|
|
52
|
+
"@kizlo/shared": "0.10.0",
|
|
53
53
|
"jose": "6.1.0",
|
|
54
54
|
"zod": "^4.3.6"
|
|
55
55
|
},
|