hookwright 1.4.0 → 1.5.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.
Files changed (2) hide show
  1. package/dist/cli.js +50 -8
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -24,7 +24,7 @@ var init_package = __esm({
24
24
  "package.json"() {
25
25
  package_default = {
26
26
  name: "hookwright",
27
- version: "1.4.0",
27
+ version: "1.5.0",
28
28
  description: "Build real, signed e-commerce webhooks from a live Shopify catalogue \u2014 interactive terminal UI, no backend",
29
29
  keywords: [
30
30
  "webhook",
@@ -919,15 +919,55 @@ function buildPayload3(ctx) {
919
919
  const cust = config.customer;
920
920
  const session = crypto3.randomBytes(8).toString("hex");
921
921
  const first = items[0];
922
- const lineItems = items.map(({ product, variant, quantity }) => ({
922
+ const cartLine = ({ product, variant, quantity }) => ({
923
923
  quantity,
924
924
  title: product.title,
925
925
  line_price: money2((variant?.price ?? 0) * quantity).toFixed(2),
926
926
  id: Number(variant?.id ?? product.id),
927
927
  product_id: Number(product.id),
928
928
  image_url: imageForVariant(product, variant)
929
- }));
930
- const cartValue = money2(items.reduce((sum, i) => sum + money2(i.variant?.price ?? 0) * i.quantity, 0));
929
+ });
930
+ const removedLine = ({ product, variant, quantity }) => {
931
+ const unit = money2(variant?.price ?? 0).toFixed(2);
932
+ const line = money2((variant?.price ?? 0) * quantity).toFixed(2);
933
+ const priceSet = (amount) => {
934
+ const value = Number(amount).toFixed(1);
935
+ return {
936
+ shop_money: { amount: value, currency_code: currency },
937
+ presentment_money: { amount: value, currency_code: currency }
938
+ };
939
+ };
940
+ return {
941
+ id: Number(variant?.id ?? product.id),
942
+ properties: null,
943
+ quantity,
944
+ variant_id: Number(variant?.id ?? product.id),
945
+ key: `${variant?.id ?? product.id}:${crypto3.randomBytes(16).toString("hex")}`,
946
+ discounted_price: unit,
947
+ discounts: [],
948
+ gift_card: false,
949
+ grams: 0,
950
+ line_price: line,
951
+ original_line_price: line,
952
+ original_price: unit,
953
+ price: unit,
954
+ product_id: Number(product.id),
955
+ sku: variant?.sku || "",
956
+ taxable: true,
957
+ title: product.title,
958
+ total_discount: "0.00",
959
+ vendor: config.shopify.shop?.name ?? config.shopify.domain,
960
+ discounted_price_set: priceSet(unit),
961
+ line_price_set: priceSet(line),
962
+ original_line_price_set: priceSet(line),
963
+ price_set: priceSet(unit),
964
+ total_discount_set: priceSet(0),
965
+ parent_relationship: null
966
+ };
967
+ };
968
+ const lineItems = items.map(cartLine);
969
+ const valueOf = (list) => money2(list.reduce((sum, i) => sum + money2(i.variant?.price ?? 0) * i.quantity, 0));
970
+ const cartValue = valueOf(items);
931
971
  const customer = {
932
972
  email: cust.email,
933
973
  phone,
@@ -982,14 +1022,16 @@ function buildPayload3(ctx) {
982
1022
  case "addtocart":
983
1023
  case "removefromcart": {
984
1024
  const added = eventName === "addtocart";
1025
+ const removed = added ? [] : items.slice(-1);
1026
+ const remaining = added ? items : items.slice(0, -1);
985
1027
  eventVal = {
986
- line_items: added ? lineItems : [],
987
- cart_value: added ? cartValue : 0,
1028
+ line_items: added ? lineItems : remaining.map(cartLine),
1029
+ cart_value: added ? cartValue : valueOf(remaining),
988
1030
  recent_product_image: added ? lineItems[0]?.image_url ?? null : null,
989
1031
  init_cart: false,
990
- empty_cart: !added,
1032
+ empty_cart: !added && remaining.length === 0,
991
1033
  items_added: added ? lineItems : [],
992
- items_removed: added ? [] : lineItems,
1034
+ items_removed: removed.map(removedLine),
993
1035
  customer,
994
1036
  bik_customer_id: null
995
1037
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hookwright",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Build real, signed e-commerce webhooks from a live Shopify catalogue — interactive terminal UI, no backend",
5
5
  "keywords": [
6
6
  "webhook",