hookwright 2.1.0 → 2.3.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 +68 -35
  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: "2.1.0",
27
+ version: "2.3.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",
@@ -1875,7 +1875,7 @@ function editableFieldsFor3(eventName) {
1875
1875
  }
1876
1876
  var editableFields6 = editableFieldsFor3(DEFAULT_EVENT4);
1877
1877
  function statusBlock(reached, at, comment = null) {
1878
- return { status: reached, comment, created_at: reached ? at : null };
1878
+ return { status: reached, comment: comment ?? "quickreply test", created_at: at };
1879
1879
  }
1880
1880
  function buildPayload6(ctx) {
1881
1881
  const { config, items, phone } = ctx;
@@ -1892,20 +1892,21 @@ function buildPayload6(ctx) {
1892
1892
  const reached = (name) => STATUSES.indexOf(name) <= reachedIndex && def.status !== "requested";
1893
1893
  const makeLineItem = (sel, idx) => {
1894
1894
  const repl = replacementFor(sel, idx);
1895
+ const qty = def.requestType === "exchange" ? repl?.quantity ?? sel?.quantity ?? 1 : sel?.quantity ?? 1;
1895
1896
  const originalPrice = money2(sel?.variant?.price ?? 0);
1896
1897
  const exchangePrice = money2(repl?.variant?.price ?? 0);
1897
1898
  return {
1898
1899
  id: Number(sel?.variant?.id ?? sel?.product?.id ?? 0),
1899
1900
  refund: {
1900
1901
  requested_mode: "store_credit",
1901
- actual_mode: def.status === "rejected" ? "store_credit" : null,
1902
- meta: def.status === "rejected" && ctx.couponCode ? { discount_code: ctx.couponCode } : null,
1903
- status: def.status === "rejected" ? "refunded" : "pending",
1902
+ actual_mode: "store_credit",
1903
+ meta: { discount_code: ctx.couponCode ?? `RP${String(now.getTime()).slice(-7)}` },
1904
+ status: def.status === "requested" ? "pending" : "refunded",
1904
1905
  refunded_amount: {
1905
- shop_money: { ...def.status === "rejected" ? { amount: originalPrice } : {}, currency_code: currency },
1906
- presentment_money: { ...def.status === "rejected" ? { amount: originalPrice } : {}, currency_code: currency }
1906
+ shop_money: { amount: originalPrice, currency_code: currency },
1907
+ presentment_money: { amount: originalPrice, currency_code: currency }
1907
1908
  },
1908
- refunded_at: def.status === "rejected" ? at : null,
1909
+ refunded_at: at,
1909
1910
  comment: null
1910
1911
  },
1911
1912
  return_fee: {
@@ -1917,8 +1918,8 @@ function buildPayload6(ctx) {
1917
1918
  },
1918
1919
  exchange_fee: {
1919
1920
  price_set: {
1920
- shop_money: { amount: null, currency_code: null },
1921
- presentment_money: { amount: null, currency_code: null }
1921
+ shop_money: { amount: ctx.exchangeFee ?? 0, currency_code: currency },
1922
+ presentment_money: { amount: ctx.exchangeFee ?? 0, currency_code: currency }
1922
1923
  }
1923
1924
  },
1924
1925
  exchange: { order: null },
@@ -1947,7 +1948,7 @@ function buildPayload6(ctx) {
1947
1948
  }
1948
1949
  } : {},
1949
1950
  shipping: [
1950
- def.status === "requested" ? { tracking_available: false, labels: [] } : {
1951
+ {
1951
1952
  shipping_company: "bluedartV2",
1952
1953
  tracking_available: true,
1953
1954
  awb: String(now.getTime()).slice(-11),
@@ -1957,12 +1958,12 @@ function buildPayload6(ctx) {
1957
1958
  tracking_url: `https://www.bluedart.com/trackdartresultthirdparty?trackFor=0&trackNo=${String(now.getTime()).slice(-11)}`
1958
1959
  }
1959
1960
  ],
1960
- quantity: sel?.quantity ?? 1,
1961
+ quantity: qty,
1961
1962
  reason: ctx.reason ?? "Size of Fit Issues",
1962
1963
  shop_price: {
1963
1964
  actual_amount: originalPrice,
1964
1965
  total_tax: 0,
1965
- return_quantity: sel?.quantity ?? 1,
1966
+ return_quantity: qty,
1966
1967
  total_discount: 0,
1967
1968
  shipping_amount: 0,
1968
1969
  taxes_included: true,
@@ -1972,7 +1973,7 @@ function buildPayload6(ctx) {
1972
1973
  presentment_price: {
1973
1974
  actual_amount: originalPrice,
1974
1975
  total_tax: 0,
1975
- return_quantity: sel?.quantity ?? 1,
1976
+ return_quantity: qty,
1976
1977
  total_discount: 0,
1977
1978
  shipping_amount: 0,
1978
1979
  taxes_included: true,
@@ -1980,13 +1981,13 @@ function buildPayload6(ctx) {
1980
1981
  do_not_carry_forward_discount: true
1981
1982
  },
1982
1983
  shopify_order_fulfillment_location: null,
1983
- return_location: def.status === "requested" ? null : {
1984
+ return_location: {
1984
1985
  id: "rp-location-1",
1985
1986
  fullName: config.shopify.shop?.name ?? config.shopify.domain,
1986
1987
  mobileNumber: nationalNumber(phone, cust.countryCode),
1987
1988
  pinCode: cust.zip,
1988
1989
  streetAddress1: cust.address1,
1989
- streetAddress2: cust.address2 ?? "",
1990
+ streetAddress2: cust.address2 || "Second line",
1990
1991
  landmark: "",
1991
1992
  city: cust.city,
1992
1993
  state: cust.province,
@@ -2039,7 +2040,7 @@ function buildPayload6(ctx) {
2039
2040
  country_code: cust.countryCode,
2040
2041
  province_code: cust.provinceCode,
2041
2042
  address_line_1: cust.address1,
2042
- address_line_2: cust.address2 ?? "",
2043
+ address_line_2: cust.address2 || "Second line",
2043
2044
  country: cust.country,
2044
2045
  address_line_3: ""
2045
2046
  },
@@ -3943,6 +3944,11 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
3943
3944
  const [items, setItems] = useState([]);
3944
3945
  const [pendingVariant, setPendingVariant] = useState(null);
3945
3946
  const [exchangeItems, setExchangeItems] = useState([]);
3947
+ const [side, setSide] = useState("returned");
3948
+ const [replacementChosen, setReplacementChosen] = useState([]);
3949
+ const [replacements, setReplacements] = useState([]);
3950
+ const active = () => side === "replacement" ? replacementChosen : chosen;
3951
+ const defaultQty = () => side === "replacement" ? String(items[cursor]?.quantity ?? 1) : "1";
3946
3952
  const [delta, setDelta] = useState([]);
3947
3953
  const isDeltaEvent = providerId === "nitro" && (eventName === "addtocart" || eventName === "removefromcart");
3948
3954
  const [draft, setDraft] = useState(null);
@@ -3963,13 +3969,15 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
3963
3969
  case STEP.COLLECTION:
3964
3970
  return multiEvent ? setStep(STEP.EVENT) : onDone();
3965
3971
  case STEP.VARIANT:
3966
- if (cursor === 0) return setStep(STEP.PICK);
3967
- setItems(items.slice(0, -1));
3972
+ if (cursor === 0) return setStep(side === "replacement" ? STEP.REPLACEMENT : STEP.PICK);
3973
+ if (side === "replacement") setReplacements(replacements.slice(0, -1));
3974
+ else setItems(items.slice(0, -1));
3968
3975
  return stepInto(cursor - 1);
3969
3976
  case STEP.QUANTITY:
3970
- if (chosen[cursor]?.variants.length > 1) return setStep(STEP.VARIANT);
3971
- if (cursor === 0) return setStep(STEP.PICK);
3972
- setItems(items.slice(0, -1));
3977
+ if (active()[cursor]?.variants.length > 1) return setStep(STEP.VARIANT);
3978
+ if (cursor === 0) return setStep(side === "replacement" ? STEP.REPLACEMENT : STEP.PICK);
3979
+ if (side === "replacement") setReplacements(replacements.slice(0, -1));
3980
+ else setItems(items.slice(0, -1));
3973
3981
  return stepInto(cursor - 1);
3974
3982
  case STEP.DISCOUNT: {
3975
3983
  if (selection === "none") return multiEvent ? setStep(STEP.EVENT) : onDone();
@@ -3997,7 +4005,7 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
3997
4005
  };
3998
4006
  const stepInto = (index) => {
3999
4007
  setCursor(index);
4000
- const product = chosen[index];
4008
+ const product = active()[index];
4001
4009
  if (!product) return setStep(STEP.PICK);
4002
4010
  if (product.variants.length > 1) return setStep(STEP.VARIANT);
4003
4011
  setPendingVariant(product.variants[0]);
@@ -4068,9 +4076,31 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
4068
4076
  const onReplacementsPicked = (ids) => {
4069
4077
  const picked = ids.map((id) => products.find((p) => p.id === id)).filter(Boolean);
4070
4078
  if (!picked.length) return;
4071
- const pairs = picked.map((p) => ({ product: p, variant: p.variants[0], quantity: 1 }));
4072
- setExchangeItems(pairs);
4073
- startReview(0, collection, items, delta, pairs);
4079
+ setReplacementChosen(picked);
4080
+ setReplacements([]);
4081
+ setSide("replacement");
4082
+ setCursor(0);
4083
+ const first = picked[0];
4084
+ if (first.variants.length > 1) setStep(STEP.VARIANT);
4085
+ else {
4086
+ setPendingVariant(first.variants[0]);
4087
+ setStep(STEP.QUANTITY);
4088
+ }
4089
+ };
4090
+ const advanceReplacement = (nextPairs, nextCursor) => {
4091
+ if (nextCursor >= replacementChosen.length) {
4092
+ setReplacements(nextPairs);
4093
+ setExchangeItems(nextPairs);
4094
+ setSide("returned");
4095
+ startReview(0, collection, items, delta, nextPairs);
4096
+ return;
4097
+ }
4098
+ setReplacements(nextPairs);
4099
+ setCursor(nextCursor);
4100
+ const product = replacementChosen[nextCursor];
4101
+ if (product.variants.length > 1) return setStep(STEP.VARIANT);
4102
+ setPendingVariant(product.variants[0]);
4103
+ setStep(STEP.QUANTITY);
4074
4104
  };
4075
4105
  const advance = (nextItems, nextCursor) => {
4076
4106
  if (nextCursor >= chosen.length) {
@@ -4123,13 +4153,16 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
4123
4153
  }
4124
4154
  };
4125
4155
  const onVariantPicked = (variantId) => {
4126
- const product = chosen[cursor];
4156
+ const product = active()[cursor];
4127
4157
  setPendingVariant(product.variants.find((v) => v.id === variantId) ?? product.variants[0]);
4128
4158
  setStep(STEP.QUANTITY);
4129
4159
  };
4130
4160
  const onQuantity = (raw) => {
4131
4161
  const qty = Math.max(1, Number.parseInt(raw, 10) || 1);
4132
- const product = chosen[cursor];
4162
+ const product = active()[cursor];
4163
+ if (side === "replacement") {
4164
+ return advanceReplacement([...replacements, { product, variant: pendingVariant, quantity: qty }], cursor + 1);
4165
+ }
4133
4166
  const nextItems = [...items, { product, variant: pendingVariant, quantity: qty }];
4134
4167
  advance(nextItems, cursor + 1);
4135
4168
  };
@@ -4325,31 +4358,31 @@ function Build({ config, providerId = "cashfree-occ", onDone }) {
4325
4358
  ] }),
4326
4359
  step === STEP.VARIANT && /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", children: [
4327
4360
  /* @__PURE__ */ jsxs8(Text8, { children: [
4328
- `Variant for `,
4329
- /* @__PURE__ */ jsx8(Text8, { bold: true, color: palette.accent, children: chosen[cursor]?.title })
4361
+ side === "replacement" ? "Replacement variant for " : "Variant for ",
4362
+ /* @__PURE__ */ jsx8(Text8, { bold: true, color: palette.accent, children: active()[cursor]?.title })
4330
4363
  ] }),
4331
4364
  /* @__PURE__ */ jsx8(Box8, { marginTop: 1, children: /* @__PURE__ */ jsx8(
4332
4365
  Select4,
4333
4366
  {
4334
4367
  visibleOptionCount: 8,
4335
- options: chosen[cursor].variants.map((v) => ({
4368
+ options: active()[cursor].variants.map((v) => ({
4336
4369
  label: `${truncate(v.title, 34).padEnd(35)} ${money(v.price, currency)}${v.sku ? " " + v.sku : ""}`,
4337
4370
  value: v.id
4338
4371
  })),
4339
4372
  onChange: onVariantPicked
4340
4373
  },
4341
- `variant-${cursor}`
4374
+ `variant-${side}-${cursor}`
4342
4375
  ) })
4343
4376
  ] }),
4344
4377
  step === STEP.QUANTITY && /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", children: [
4345
4378
  /* @__PURE__ */ jsxs8(Text8, { children: [
4346
- `Quantity for `,
4347
- /* @__PURE__ */ jsx8(Text8, { bold: true, color: palette.accent, children: chosen[cursor]?.title }),
4379
+ side === "replacement" ? "Replacement quantity for " : "Quantity for ",
4380
+ /* @__PURE__ */ jsx8(Text8, { bold: true, color: palette.accent, children: active()[cursor]?.title }),
4348
4381
  /* @__PURE__ */ jsx8(Text8, { color: palette.dim, children: pendingVariant?.title ? ` \xB7 ${pendingVariant.title}` : "" })
4349
4382
  ] }),
4350
4383
  /* @__PURE__ */ jsxs8(Box8, { marginTop: 1, children: [
4351
4384
  /* @__PURE__ */ jsx8(Text8, { color: palette.accent, children: "\u276F " }),
4352
- /* @__PURE__ */ jsx8(TextInput, { defaultValue: "1", placeholder: "1", onSubmit: onQuantity }, `qty-${cursor}`)
4385
+ /* @__PURE__ */ jsx8(TextInput, { defaultValue: defaultQty(), placeholder: defaultQty(), onSubmit: onQuantity }, `qty-${side}-${cursor}`)
4353
4386
  ] })
4354
4387
  ] }),
4355
4388
  step === STEP.DISCOUNT && /* @__PURE__ */ jsxs8(Box8, { flexDirection: "column", children: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hookwright",
3
- "version": "2.1.0",
3
+ "version": "2.3.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",