hookwright 2.0.0 → 2.0.1

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 +119 -114
  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.0.0",
27
+ version: "2.0.1",
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",
@@ -1878,124 +1878,129 @@ function buildPayload6(ctx) {
1878
1878
  const currency = ctx.currency || config.defaults.currency;
1879
1879
  const cust = config.customer;
1880
1880
  const at = now.toISOString();
1881
- const first = items?.[0];
1882
- const second = ctx.exchange ?? items?.[1] ?? first;
1883
- const originalPrice = money2(first?.variant?.price ?? 0);
1884
- const exchangePrice = money2(second?.variant?.price ?? 0);
1881
+ const selected = (items ?? []).filter(Boolean);
1882
+ const replacements = ctx.exchangeItems ?? (ctx.exchange ? [ctx.exchange] : []);
1883
+ const replacementFor = (sel, idx) => replacements[idx] ?? ctx.exchange ?? sel;
1885
1884
  const reachedIndex = STATUSES.indexOf(def.status);
1886
1885
  const reached = (name) => STATUSES.indexOf(name) <= reachedIndex && def.status !== "requested";
1887
- const lineItem = {
1888
- id: Number(first?.variant?.id ?? first?.product?.id ?? 0),
1889
- refund: {
1890
- requested_mode: "store_credit",
1891
- actual_mode: def.status === "rejected" ? "store_credit" : null,
1892
- meta: def.status === "rejected" && ctx.couponCode ? { discount_code: ctx.couponCode } : null,
1893
- status: def.status === "rejected" ? "refunded" : "pending",
1894
- refunded_amount: {
1895
- shop_money: { ...def.status === "rejected" ? { amount: originalPrice } : {}, currency_code: currency },
1896
- presentment_money: { ...def.status === "rejected" ? { amount: originalPrice } : {}, currency_code: currency }
1886
+ const makeLineItem = (sel, idx) => {
1887
+ const repl = replacementFor(sel, idx);
1888
+ const originalPrice = money2(sel?.variant?.price ?? 0);
1889
+ const exchangePrice = money2(repl?.variant?.price ?? 0);
1890
+ return {
1891
+ id: Number(sel?.variant?.id ?? sel?.product?.id ?? 0),
1892
+ refund: {
1893
+ requested_mode: "store_credit",
1894
+ actual_mode: def.status === "rejected" ? "store_credit" : null,
1895
+ meta: def.status === "rejected" && ctx.couponCode ? { discount_code: ctx.couponCode } : null,
1896
+ status: def.status === "rejected" ? "refunded" : "pending",
1897
+ refunded_amount: {
1898
+ shop_money: { ...def.status === "rejected" ? { amount: originalPrice } : {}, currency_code: currency },
1899
+ presentment_money: { ...def.status === "rejected" ? { amount: originalPrice } : {}, currency_code: currency }
1900
+ },
1901
+ refunded_at: def.status === "rejected" ? at : null,
1902
+ comment: null
1897
1903
  },
1898
- refunded_at: def.status === "rejected" ? at : null,
1899
- comment: null
1900
- },
1901
- return_fee: {
1902
- price_set: {
1903
- shop_money: { amount: ctx.returnFee ?? 0, currency_code: currency },
1904
- presentment_money: { amount: ctx.returnFee ?? 0, currency_code: currency }
1904
+ return_fee: {
1905
+ price_set: {
1906
+ shop_money: { amount: ctx.returnFee ?? 0, currency_code: currency },
1907
+ presentment_money: { amount: ctx.returnFee ?? 0, currency_code: currency }
1908
+ },
1909
+ rule: "order"
1905
1910
  },
1906
- rule: "order"
1907
- },
1908
- exchange_fee: {
1909
- price_set: {
1910
- shop_money: { amount: null, currency_code: null },
1911
- presentment_money: { amount: null, currency_code: null }
1912
- }
1913
- },
1914
- exchange: { order: null },
1915
- original_product: {
1916
- title: first?.product?.title,
1917
- variant_title: first?.variant?.title ?? null,
1918
- product_id: Number(first?.product?.id ?? 0),
1919
- variant_id: Number(first?.variant?.id ?? 0),
1920
- image: { src: imageForVariant(first?.product, first?.variant) },
1921
- price: originalPrice,
1922
- sku: first?.variant?.sku || "",
1923
- variant_deleted: false,
1924
- product_deleted: false
1925
- },
1926
- ...def.requestType === "exchange" ? {
1927
- exchange_product: {
1928
- product_id: Number(second?.product?.id ?? 0),
1929
- title: second?.product?.title,
1930
- variant_title: second?.variant?.title ?? "Default Title",
1931
- variant_id: Number(second?.variant?.id ?? 0),
1932
- image: { src: imageForVariant(second?.product, second?.variant) },
1933
- price: exchangePrice,
1934
- sku: second?.variant?.sku || "",
1911
+ exchange_fee: {
1912
+ price_set: {
1913
+ shop_money: { amount: null, currency_code: null },
1914
+ presentment_money: { amount: null, currency_code: null }
1915
+ }
1916
+ },
1917
+ exchange: { order: null },
1918
+ original_product: {
1919
+ title: sel?.product?.title,
1920
+ variant_title: sel?.variant?.title ?? null,
1921
+ product_id: Number(sel?.product?.id ?? 0),
1922
+ variant_id: Number(sel?.variant?.id ?? 0),
1923
+ image: { src: imageForVariant(sel?.product, sel?.variant) },
1924
+ price: originalPrice,
1925
+ sku: sel?.variant?.sku || "",
1935
1926
  variant_deleted: false,
1936
1927
  product_deleted: false
1937
- }
1938
- } : {},
1939
- shipping: [
1940
- def.status === "requested" ? { tracking_available: false, labels: [] } : {
1941
- shipping_company: "bluedartV2",
1942
- tracking_available: true,
1943
- awb: String(now.getTime()).slice(-11),
1944
- tracking_updated_at: null,
1945
- labels: [],
1946
- shipment_status: "Requested",
1947
- tracking_url: `https://www.bluedart.com/trackdartresultthirdparty?trackFor=0&trackNo=${String(now.getTime()).slice(-11)}`
1948
- }
1949
- ],
1950
- quantity: first?.quantity ?? 1,
1951
- reason: ctx.reason ?? "Size of Fit Issues",
1952
- shop_price: {
1953
- actual_amount: originalPrice,
1954
- total_tax: 0,
1955
- return_quantity: first?.quantity ?? 1,
1956
- total_discount: 0,
1957
- shipping_amount: 0,
1958
- taxes_included: true,
1959
- currency,
1960
- do_not_carry_forward_discount: true
1961
- },
1962
- presentment_price: {
1963
- actual_amount: originalPrice,
1964
- total_tax: 0,
1965
- return_quantity: first?.quantity ?? 1,
1966
- total_discount: 0,
1967
- shipping_amount: 0,
1968
- taxes_included: true,
1969
- currency,
1970
- do_not_carry_forward_discount: true
1971
- },
1972
- shopify_order_fulfillment_location: null,
1973
- return_location: def.status === "requested" ? null : {
1974
- id: "rp-location-1",
1975
- fullName: config.shopify.shop?.name ?? config.shopify.domain,
1976
- mobileNumber: nationalNumber(phone, cust.countryCode),
1977
- pinCode: cust.zip,
1978
- streetAddress1: cust.address1,
1979
- streetAddress2: cust.address2 ?? "",
1980
- landmark: "",
1981
- city: cust.city,
1982
- state: cust.province,
1983
- stateCode: cust.provinceCode,
1984
- countryCode: cust.countryCode,
1985
- country: cust.country,
1986
- store: config.shopify.domain,
1987
- facilityCode: "",
1988
- isDefault: true,
1989
- latitude: "",
1990
- longitude: "",
1991
- inStoreReturnExchange: false,
1992
- external: false,
1993
- createdAt: at,
1994
- updatedAt: at
1995
- },
1996
- notes: null,
1997
- tags: []
1928
+ },
1929
+ ...def.requestType === "exchange" ? {
1930
+ exchange_product: {
1931
+ product_id: Number(repl?.product?.id ?? 0),
1932
+ title: repl?.product?.title,
1933
+ variant_title: repl?.variant?.title ?? "Default Title",
1934
+ variant_id: Number(repl?.variant?.id ?? 0),
1935
+ image: { src: imageForVariant(repl?.product, repl?.variant) },
1936
+ price: exchangePrice,
1937
+ sku: repl?.variant?.sku || "",
1938
+ variant_deleted: false,
1939
+ product_deleted: false
1940
+ }
1941
+ } : {},
1942
+ shipping: [
1943
+ def.status === "requested" ? { tracking_available: false, labels: [] } : {
1944
+ shipping_company: "bluedartV2",
1945
+ tracking_available: true,
1946
+ awb: String(now.getTime()).slice(-11),
1947
+ tracking_updated_at: null,
1948
+ labels: [],
1949
+ shipment_status: "Requested",
1950
+ tracking_url: `https://www.bluedart.com/trackdartresultthirdparty?trackFor=0&trackNo=${String(now.getTime()).slice(-11)}`
1951
+ }
1952
+ ],
1953
+ quantity: sel?.quantity ?? 1,
1954
+ reason: ctx.reason ?? "Size of Fit Issues",
1955
+ shop_price: {
1956
+ actual_amount: originalPrice,
1957
+ total_tax: 0,
1958
+ return_quantity: sel?.quantity ?? 1,
1959
+ total_discount: 0,
1960
+ shipping_amount: 0,
1961
+ taxes_included: true,
1962
+ currency,
1963
+ do_not_carry_forward_discount: true
1964
+ },
1965
+ presentment_price: {
1966
+ actual_amount: originalPrice,
1967
+ total_tax: 0,
1968
+ return_quantity: sel?.quantity ?? 1,
1969
+ total_discount: 0,
1970
+ shipping_amount: 0,
1971
+ taxes_included: true,
1972
+ currency,
1973
+ do_not_carry_forward_discount: true
1974
+ },
1975
+ shopify_order_fulfillment_location: null,
1976
+ return_location: def.status === "requested" ? null : {
1977
+ id: "rp-location-1",
1978
+ fullName: config.shopify.shop?.name ?? config.shopify.domain,
1979
+ mobileNumber: nationalNumber(phone, cust.countryCode),
1980
+ pinCode: cust.zip,
1981
+ streetAddress1: cust.address1,
1982
+ streetAddress2: cust.address2 ?? "",
1983
+ landmark: "",
1984
+ city: cust.city,
1985
+ state: cust.province,
1986
+ stateCode: cust.provinceCode,
1987
+ countryCode: cust.countryCode,
1988
+ country: cust.country,
1989
+ store: config.shopify.domain,
1990
+ facilityCode: "",
1991
+ isDefault: true,
1992
+ latitude: "",
1993
+ longitude: "",
1994
+ inStoreReturnExchange: false,
1995
+ external: false,
1996
+ createdAt: at,
1997
+ updatedAt: at
1998
+ },
1999
+ notes: null,
2000
+ tags: []
2001
+ };
1998
2002
  };
2003
+ const lineItems = selected.map(makeLineItem);
1999
2004
  const request = {
2000
2005
  id: `rp-${now.getTime()}`,
2001
2006
  request_number: ctx.requestNumber ?? `${def.requestType === "exchange" ? "EXC" : "RET"}${String(now.getTime()).slice(-3)}`,
@@ -2010,7 +2015,7 @@ function buildPayload6(ctx) {
2010
2015
  name: ctx.orderName ?? `#${String(now.getTime()).slice(-5)}`,
2011
2016
  order_manual_payment: false,
2012
2017
  payment_gateways: [],
2013
- fulfillments: [{ id: Number(String(now.getTime()).slice(-10)), line_items: [lineItem.id], delivery_status: null, delivery_date: null }],
2018
+ fulfillments: [{ id: Number(String(now.getTime()).slice(-10)), line_items: lineItems.map((li) => li.id), delivery_status: null, delivery_date: null }],
2014
2019
  created_at: at
2015
2020
  },
2016
2021
  customer: {
@@ -2040,7 +2045,7 @@ function buildPayload6(ctx) {
2040
2045
  archived: statusBlock(false, at),
2041
2046
  unarchived: statusBlock(false, at),
2042
2047
  incentive: null,
2043
- line_items: [lineItem],
2048
+ line_items: lineItems,
2044
2049
  created_at: at
2045
2050
  };
2046
2051
  return ctx.envelope === "root" ? request : { request };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hookwright",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
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",