hookwright 1.3.0 → 1.4.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 +65 -66
  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.3.0",
27
+ version: "1.4.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",
@@ -809,7 +809,7 @@ var FIELD_MAPS = {
809
809
  ...PAGE_FIELDS,
810
810
  { source: "eventVal.resource_id", target: "eventVal.resource_id", required: true, note: "the collection id" },
811
811
  { source: "eventVal.resource", target: "eventVal.resource" },
812
- { source: "eventVal.title", target: "collection name", required: true },
812
+ { source: "eventVal.resource_id", target: "collection lookup", required: true, note: "the consumer fetches the collection by this id" },
813
813
  { source: "eventVal.domain", target: "eventVal.domain" }
814
814
  ],
815
815
  product_view: [
@@ -828,7 +828,7 @@ var FIELD_MAPS = {
828
828
  { source: "eventVal.init_cart", target: "eventVal.init_cart" },
829
829
  { source: "eventVal.empty_cart", target: "eventVal.empty_cart" },
830
830
  { source: "eventVal.bik_customer_id", target: "eventVal.bik_customer_id" },
831
- { source: "eventVal.line_items[0].name", target: "cart enrichment", required: true }
831
+ { source: "eventVal.line_items[0].title", target: "cart enrichment", required: true }
832
832
  ],
833
833
  removefromcart: [
834
834
  ...COMMON_FIELDS,
@@ -836,7 +836,7 @@ var FIELD_MAPS = {
836
836
  { source: "eventVal.init_cart", target: "eventVal.init_cart" },
837
837
  { source: "eventVal.empty_cart", target: "eventVal.empty_cart" },
838
838
  { source: "eventVal.bik_customer_id", target: "eventVal.bik_customer_id" },
839
- { source: "eventVal.line_items[0].name", target: "cart enrichment" }
839
+ { source: "eventVal.line_items[0].title", target: "cart enrichment" }
840
840
  ],
841
841
  checkout: [
842
842
  ...COMMON_FIELDS,
@@ -875,7 +875,7 @@ var EDITABLE = {
875
875
  ],
876
876
  collection: [
877
877
  { group: "Collection", path: "eventVal.resource_id", label: "Collection id" },
878
- { group: "Collection", path: "eventVal.title", label: "Collection name" },
878
+ { group: "Collection", path: "eventVal.resource_id", label: "Collection id", type: "number" },
879
879
  { group: "Collection", path: "eventVal.l", label: "Collection URL" }
880
880
  ],
881
881
  product: [
@@ -920,104 +920,102 @@ function buildPayload3(ctx) {
920
920
  const session = crypto3.randomBytes(8).toString("hex");
921
921
  const first = items[0];
922
922
  const lineItems = items.map(({ product, variant, quantity }) => ({
923
- id: variant ? String(variant.id) : null,
924
- product_id: String(product.id),
925
- name: product.title,
926
- title: product.title,
927
923
  quantity,
928
- price: money2(variant?.price ?? 0),
929
- image: imageForVariant(product, variant),
930
- url: `https://${domain}/products/${product.handle ?? ""}`
924
+ title: product.title,
925
+ line_price: money2((variant?.price ?? 0) * quantity).toFixed(2),
926
+ id: Number(variant?.id ?? product.id),
927
+ product_id: Number(product.id),
928
+ image_url: imageForVariant(product, variant)
931
929
  }));
932
- const cartValue = money2(lineItems.reduce((sum, li) => sum + li.price * li.quantity, 0));
933
- const productUrl = first ? `https://${domain}/products/${first.product.handle ?? ""}` : `https://${domain}`;
930
+ const cartValue = money2(items.reduce((sum, i) => sum + money2(i.variant?.price ?? 0) * i.quantity, 0));
934
931
  const customer = {
935
- phone,
936
932
  email: cust.email,
937
- name: `${cust.firstName} ${cust.lastName}`.trim(),
938
- first_name: cust.firstName,
939
- last_name: cust.lastName
933
+ phone,
934
+ name: `${cust.firstName} ${cust.lastName}`.trim()
940
935
  };
936
+ const pageUrl = eventName === "product_view" ? `https://${domain}/products/${first?.product?.handle ?? ""}` : eventName === "category_view" ? `https://${domain}/collections/${ctx.collection?.handle ?? "all"}` : `https://${domain}/`;
937
+ const isBrowsing = ["view", "category_view", "product_view"].includes(eventName);
941
938
  const base = {
942
- org_token: config.defaults.orgToken ?? crypto3.randomBytes(12).toString("hex"),
939
+ org_token: config.defaults.orgToken ?? crypto3.randomUUID(),
943
940
  eventName,
941
+ u: isBrowsing ? pageUrl : "",
942
+ lang: config.defaults.lang ?? "en",
944
943
  userId: crypto3.randomUUID(),
945
944
  timestamp: now.toISOString(),
946
945
  country: cust.countryCode,
947
- domain
948
- };
949
- const page = {
950
- page: eventName === "product_view" ? "product" : eventName === "category_view" ? "collection" : "home",
951
- h: domain,
952
- l: productUrl,
953
- _ss: session,
954
- domain
946
+ state: isBrowsing ? cust.province : null,
947
+ city: isBrowsing ? cust.city : null,
948
+ pincode: isBrowsing ? cust.zip : null
955
949
  };
956
950
  let eventVal;
957
951
  switch (eventName) {
958
952
  case "view":
959
- eventVal = { page: "home", h: domain, l: `https://${domain}`, _ss: session, domain, customer };
953
+ eventVal = { page: pageUrl, h: domain, l: pageUrl, _ss: session, customer };
960
954
  break;
961
- case "category_view": {
962
- const collection = ctx.collection;
955
+ case "category_view":
963
956
  eventVal = {
964
- ...page,
965
- page: "collection",
966
- resource: "collection",
967
- resource_id: String(collection?.id ?? ""),
968
- title: collection?.title,
969
- image: collection?.image || void 0,
970
- l: collection?.handle ? `https://${domain}/collections/${collection.handle}` : `https://${domain}/collections/all`,
957
+ page: pageUrl,
958
+ resource_id: ctx.collection?.id ? Number(ctx.collection.id) : null,
959
+ resource: ctx.collection?.id ? "collection" : null,
960
+ domain,
961
+ h: domain,
962
+ l: pageUrl,
963
+ _ss: session,
971
964
  customer
972
965
  };
973
966
  break;
974
- }
975
967
  case "product_view":
976
968
  eventVal = {
977
- ...page,
969
+ page: pageUrl,
970
+ resource_id: Number(first?.product?.id ?? 0),
978
971
  resource: "product",
979
- resource_id: String(first?.product?.id ?? ""),
980
- title: first?.product?.title,
981
- image: first ? imageForVariant(first.product, first.variant) : void 0,
972
+ domain,
982
973
  price: money2(first?.variant?.price ?? 0),
974
+ h: domain,
975
+ l: pageUrl,
976
+ _ss: session,
977
+ image: first ? imageForVariant(first.product, first.variant) : void 0,
978
+ title: first?.product?.title,
983
979
  customer
984
980
  };
985
981
  break;
986
982
  case "addtocart":
987
- case "removefromcart":
983
+ case "removefromcart": {
984
+ const added = eventName === "addtocart";
988
985
  eventVal = {
989
- cart_value: cartValue,
990
- init_cart: eventName === "addtocart",
991
- empty_cart: eventName === "removefromcart" && items.length === 0,
992
- bik_customer_id: crypto3.randomUUID(),
993
- line_items: lineItems,
994
- [eventName === "addtocart" ? "items_added" : "items_removed"]: lineItems,
995
- customer
986
+ line_items: added ? lineItems : [],
987
+ cart_value: added ? cartValue : 0,
988
+ recent_product_image: added ? lineItems[0]?.image_url ?? null : null,
989
+ init_cart: false,
990
+ empty_cart: !added,
991
+ items_added: added ? lineItems : [],
992
+ items_removed: added ? [] : lineItems,
993
+ customer,
994
+ bik_customer_id: null
996
995
  };
997
996
  break;
997
+ }
998
998
  case "checkout":
999
999
  eventVal = {
1000
1000
  checkout: cartPermalink(domain, items.map(({ variant, quantity }) => ({ variantId: variant?.id, quantity }))),
1001
- cart_value: cartValue,
1002
- bik_customer_id: crypto3.randomUUID(),
1003
- line_items: lineItems,
1004
- customer
1001
+ cart_value: cartValue.toFixed(2),
1002
+ customer,
1003
+ bik_customer_id: null
1005
1004
  };
1006
1005
  break;
1007
1006
  case "orders/create":
1008
1007
  case "orders/updated": {
1009
1008
  const orderNumber = 1e3 + Math.floor(Math.random() * 9e3);
1010
1009
  eventVal = {
1011
- url: `https://${domain}/admin/orders/${orderNumber}`,
1012
- order_id: String(Date.now()),
1010
+ url: `https://${domain}/${crypto3.randomBytes(5).toString("hex")}/orders/${crypto3.randomBytes(16).toString("hex")}/authenticate?key=${crypto3.randomBytes(16).toString("hex")}`,
1011
+ order_id: Number(`${Date.now()}`.slice(-13)),
1013
1012
  order_number: orderNumber,
1014
- order_name: `#${orderNumber}`,
1015
- price: cartValue,
1013
+ order_name: crypto3.randomBytes(4).toString("hex").toUpperCase(),
1014
+ price: cartValue.toFixed(2),
1016
1015
  currency,
1017
1016
  order_created_at: now.toISOString(),
1018
- bik_customer_id: crypto3.randomUUID(),
1019
- line_items: lineItems,
1020
- customer
1017
+ customer,
1018
+ bik_customer_id: null
1021
1019
  };
1022
1020
  break;
1023
1021
  }
@@ -1047,9 +1045,10 @@ function summarize3(payload) {
1047
1045
  const items = Array.isArray(ev.line_items) ? ev.line_items : [];
1048
1046
  return {
1049
1047
  event: payload?.eventName,
1050
- store: payload?.domain,
1048
+ // the schema keeps the domain inside eventVal, not at the root
1049
+ store: payload?.eventVal?.h ?? payload?.eventVal?.domain,
1051
1050
  customer: `${ev.customer?.name ?? ""} \xB7 ${ev.customer?.phone ?? ""}`.trim(),
1052
- items: items.map((i) => `${i.name} x${i.quantity}`).join(", ") || "\u2014",
1051
+ items: items.map((i) => `${i.title} x${i.quantity}`).join(", ") || payload?.eventVal?.title || "\u2014",
1053
1052
  total: ev.cart_value ?? ev.price ?? void 0,
1054
1053
  currency: ev.currency,
1055
1054
  extra: ev.order_name ? `order ${ev.order_name}` : ev.checkout ? "checkout started" : "",
@@ -3131,7 +3130,7 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
3131
3130
  return setStep(STEP.MODE);
3132
3131
  case STEP.RESULT:
3133
3132
  case STEP.ERROR:
3134
- return onDone();
3133
+ return built ? setStep(STEP.REPORT) : onDone();
3135
3134
  default:
3136
3135
  return onDone();
3137
3136
  }
@@ -3558,7 +3557,7 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
3558
3557
  /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: "reproduce:" }),
3559
3558
  /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: sendResult.curl })
3560
3559
  ] }),
3561
- /* @__PURE__ */ jsx8(Box8, { marginTop: 1, children: /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: "press enter to return to the menu" }) })
3560
+ /* @__PURE__ */ jsx8(Box8, { marginTop: 1, children: /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: "enter returns to the menu \xB7 esc goes back to the report to retry" }) })
3562
3561
  ] }),
3563
3562
  step === STEP.ERROR && error && /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", children: [
3564
3563
  /* @__PURE__ */ jsx8(Alert, { variant: "error", children: error.message }),
@@ -3568,7 +3567,7 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
3568
3567
  /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: f.detail })
3569
3568
  ] }, i)) }) : null,
3570
3569
  error.hint ? /* @__PURE__ */ jsx8(Text8, { color: palette.warn, children: ` ${error.hint}` }) : null,
3571
- /* @__PURE__ */ jsx8(Box8, { marginTop: 1, children: /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: "press enter to return to the menu" }) })
3570
+ /* @__PURE__ */ jsx8(Box8, { marginTop: 1, children: /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: "enter returns to the menu \xB7 esc goes back to the report to retry" }) })
3572
3571
  ] })
3573
3572
  ] });
3574
3573
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hookwright",
3
- "version": "1.3.0",
3
+ "version": "1.4.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",