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.
- package/dist/cli.js +119 -114
- 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.
|
|
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
|
|
1882
|
-
const
|
|
1883
|
-
const
|
|
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
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
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
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
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
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
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
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
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:
|
|
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:
|
|
2048
|
+
line_items: lineItems,
|
|
2044
2049
|
created_at: at
|
|
2045
2050
|
};
|
|
2046
2051
|
return ctx.envelope === "root" ? request : { request };
|