@blamejs/blamejs-shop 0.3.4 → 0.3.5
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/CHANGELOG.md +2 -0
- package/lib/admin.js +428 -6
- package/lib/asset-manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.3.x
|
|
10
10
|
|
|
11
|
+
- v0.3.5 (2026-05-30) — **Shipping-label management in the admin console.** The admin console gains shipping-label tools. On an order, void a purchased label — with a reason — when it needs reprinting, alongside the existing mark-as-used action. A new Shipping labels section adds cross-order visibility: a status-filtered list, the mint queue of labels awaiting a broker, and a broker-spend report that totals label costs by carrier and currency over a date range. This is bookkeeping and reporting only — nothing in the storefront, cart, or checkout changes. **Added:** *Void a shipping label from the order* — Each purchased label on an order now offers a Void action with a reason, for when a label is reprinted at a different weight or carrier. Voiding is refused once a label has been used or already voided, or once it is past the carrier's void window. · *Shipping labels admin section* — A new Shipping labels section gives cross-order visibility: a status-filtered label list, the mint queue of labels awaiting a broker, and a broker-spend report totalling label cost grouped by carrier and currency over a date range.
|
|
12
|
+
|
|
11
13
|
- v0.3.4 (2026-05-30) — **Sales-tax filings and remittance tracking in the admin console.** The admin console gains a Tax filings section for tracking sales-tax remittance across reporting periods. Open a filing period for a jurisdiction, compute the tax collected from completed orders in that window, then record the submission and the payment as you remit. Each filing carries a per-rate breakdown and an audit trail, and the list surfaces what's due soon or already overdue. A per-jurisdiction remittance report totals the tax owed across a date range. Every figure derives from completed orders — nothing in the storefront, cart, or checkout changes. **Added:** *Tax filings admin console* — A new Tax filings section tracks sales-tax remittance: open a filing period for a jurisdiction and reporting kind, compute the tax collected from completed orders in the window with a per-rate breakdown, then record submission and payment through the filing lifecycle. The list surfaces filings due soon or overdue, and a remittance report totals tax owed per jurisdiction across a date range. This is reporting only — it reads completed orders and changes nothing in checkout.
|
|
12
14
|
|
|
13
15
|
- v0.3.3 (2026-05-30) — **Manage quantity-break (volume) pricing from the admin console.** The admin console gains a Quantity breaks section for creating and managing volume-pricing tier sets — buy-more-save-more rules scoped to a SKU, product, collection, vendor, category, or the whole store. Each set defines one or more quantity thresholds (e.g. buy 5, buy 10) with a percentage off, an amount off each unit, an amount off the line, or a fixed per-unit price, and can be marked exclusive or left to stack with others. A sample-price preview shows the discounted unit at each threshold before you commit, and sets archive and restore. The tiers take effect immediately on the product page, in the cart, and at checkout. **Added:** *Quantity Breaks admin console* — A new Quantity breaks section manages volume-pricing tier sets: create a set scoped to a SKU, product, collection, vendor, category, or globally; define one or more quantity thresholds with a percent-off, amount-off-each, amount-off-line, or fixed-per-unit discount; mark a set exclusive or let it stack. A sample-price preview shows the discounted unit at each threshold, and sets archive and restore. The tiers apply automatically on the product page, the cart, and at checkout.
|
package/lib/admin.js
CHANGED
|
@@ -145,6 +145,11 @@ var _UPLOAD_IMAGE_CT = {
|
|
|
145
145
|
// generic 413.
|
|
146
146
|
var _UPLOAD_MAX_BYTES = b.constants.BYTES.mib(10);
|
|
147
147
|
|
|
148
|
+
// Cap on the standalone shipping-labels list / pending-queue reads. Matches
|
|
149
|
+
// the labels primitive's own MAX_PENDING_LIMIT so a console drain can never
|
|
150
|
+
// ask for more than the primitive will return.
|
|
151
|
+
var MAX_LABEL_LIST_LIMIT = 200;
|
|
152
|
+
|
|
148
153
|
// ---- shared helpers -----------------------------------------------------
|
|
149
154
|
|
|
150
155
|
function _parseEpochMs(str, label) {
|
|
@@ -446,7 +451,7 @@ function mount(router, deps) {
|
|
|
446
451
|
// `reports` is always present in the nav (read-only sales summary needs no
|
|
447
452
|
// extra dep); its route mounts unconditionally and renders an unconfigured
|
|
448
453
|
// notice when the salesReports primitive isn't wired.
|
|
449
|
-
var navAvailable = { returns: !!returns, reviews: !!reviews, productQa: !!productQa, subscriptions: !!deps.subscriptions, webhooks: !!deps.webhooks, collections: !!deps.collections, customers: !!deps.customers, giftcards: !!deps.giftcards, announcementBar: !!deps.announcementBar, customerSurveys: !!deps.customerSurveys, businessHours: !!deps.businessHours, taxRates: !!deps.taxRates, shippingZones: !!deps.shippingZones, autoDiscount: !!deps.autoDiscount, quantityDiscounts: !!deps.quantityDiscounts, pickLists: !!pickLists, salesTaxFilings: !!salesTaxFilings };
|
|
454
|
+
var navAvailable = { returns: !!returns, reviews: !!reviews, productQa: !!productQa, subscriptions: !!deps.subscriptions, webhooks: !!deps.webhooks, collections: !!deps.collections, customers: !!deps.customers, giftcards: !!deps.giftcards, announcementBar: !!deps.announcementBar, customerSurveys: !!deps.customerSurveys, businessHours: !!deps.businessHours, taxRates: !!deps.taxRates, shippingZones: !!deps.shippingZones, autoDiscount: !!deps.autoDiscount, quantityDiscounts: !!deps.quantityDiscounts, pickLists: !!pickLists, salesTaxFilings: !!salesTaxFilings, shippingLabels: !!shippingLabels };
|
|
450
455
|
|
|
451
456
|
try { b.audit.registerNamespace(AUDIT_NAMESPACE); } catch (_e) { /* idempotent */ }
|
|
452
457
|
|
|
@@ -1671,6 +1676,46 @@ function mount(router, deps) {
|
|
|
1671
1676
|
_redirect(res, "/admin/orders/" + enc + "?label=1");
|
|
1672
1677
|
},
|
|
1673
1678
|
));
|
|
1679
|
+
|
|
1680
|
+
// Void a recorded label (broker void, within the 30-day window).
|
|
1681
|
+
// purchased → voided. Mirrors the /used route: the primitive enforces
|
|
1682
|
+
// the transition + window, a TypeError (bad id / missing reason) or a
|
|
1683
|
+
// SHIPPING_LABELS_* coded error (wrong status / expired window) surfaces
|
|
1684
|
+
// as a 400 on the JSON path and an `?err` notice on the browser path.
|
|
1685
|
+
router.post("/admin/orders/:id/labels/:labelId/void", _pageOrApi(false,
|
|
1686
|
+
W("order.shipment.label.void", async function (req, res) {
|
|
1687
|
+
var body = req.body || {};
|
|
1688
|
+
var out;
|
|
1689
|
+
try {
|
|
1690
|
+
out = await shippingLabels.voidLabel({ label_id: req.params.labelId, reason: body.reason });
|
|
1691
|
+
} catch (e) {
|
|
1692
|
+
if (e instanceof TypeError) return _problem(res, 400, "bad-request", e.message);
|
|
1693
|
+
if (e && e.code && /SHIPPING_LABELS/.test(e.code)) return _problem(res, 400, "bad-request", e.message);
|
|
1694
|
+
throw e;
|
|
1695
|
+
}
|
|
1696
|
+
_json(res, 200, out);
|
|
1697
|
+
return { id: req.params.id };
|
|
1698
|
+
}),
|
|
1699
|
+
async function (req, res) {
|
|
1700
|
+
var id = req.params.id;
|
|
1701
|
+
var enc = encodeURIComponent(id);
|
|
1702
|
+
var body = req.body || {};
|
|
1703
|
+
try {
|
|
1704
|
+
await shippingLabels.voidLabel({
|
|
1705
|
+
label_id: req.params.labelId,
|
|
1706
|
+
// A blank reason field reaches the primitive as undefined so the
|
|
1707
|
+
// operator-facing "reason required" message surfaces, rather than
|
|
1708
|
+
// the empty string slipping past the non-empty check.
|
|
1709
|
+
reason: (body.reason && body.reason.length) ? body.reason : undefined,
|
|
1710
|
+
});
|
|
1711
|
+
} catch (e) {
|
|
1712
|
+
if (!(e instanceof TypeError) && !(e && e.code && /SHIPPING_LABELS/.test(e.code))) throw e;
|
|
1713
|
+
return _redirect(res, "/admin/orders/" + enc + "?err=1");
|
|
1714
|
+
}
|
|
1715
|
+
b.audit.safeEmit({ action: AUDIT_NAMESPACE + ".order.shipment.label.void", outcome: "success", metadata: { id: id, label_id: req.params.labelId } });
|
|
1716
|
+
_redirect(res, "/admin/orders/" + enc + "?label=1");
|
|
1717
|
+
},
|
|
1718
|
+
));
|
|
1674
1719
|
}
|
|
1675
1720
|
|
|
1676
1721
|
// Compose requestLabel + markPurchased into one recorded label. The
|
|
@@ -1713,6 +1758,206 @@ function mount(router, deps) {
|
|
|
1713
1758
|
});
|
|
1714
1759
|
}
|
|
1715
1760
|
|
|
1761
|
+
// ---- shipping labels (standalone back-office console) ---------------
|
|
1762
|
+
//
|
|
1763
|
+
// A cross-order view of the carrier-label store, separate from the
|
|
1764
|
+
// per-shipment panel on the order detail. Three screens, each composing
|
|
1765
|
+
// a labels-primitive read:
|
|
1766
|
+
// - /admin/shipping-labels — a status-filtered list. The
|
|
1767
|
+
// primitive exposes a list read per backable status: `pending`
|
|
1768
|
+
// (pendingLabels) and `voided` (voidedInWindow over a date range).
|
|
1769
|
+
// There is no cross-order list for purchased/used labels — those
|
|
1770
|
+
// are reached from their order detail — so the filter offers the
|
|
1771
|
+
// two engine-backed views, defaulting to pending.
|
|
1772
|
+
// - /admin/shipping-labels/costs — broker-spend report grouped by
|
|
1773
|
+
// broker + currency over a date range (costsByPeriod).
|
|
1774
|
+
// - /admin/shipping-labels/pending — the mint queue (pendingLabels,
|
|
1775
|
+
// capped at 200) the operator's broker worker drains.
|
|
1776
|
+
// Mounted only when the labels primitive is wired. Every HTML handler
|
|
1777
|
+
// parses its from/to/carrier query params defensively: a malformed value
|
|
1778
|
+
// re-renders the page with a correction notice (never a 500). The bearer
|
|
1779
|
+
// JSON contract returns the same composed payload.
|
|
1780
|
+
if (shippingLabels) {
|
|
1781
|
+
// Resolve a {from, to} epoch-ms window from the query string, accepting
|
|
1782
|
+
// either raw epoch-ms (from/to — machine clients) or calendar dates
|
|
1783
|
+
// (from-date/to-date — the browser date inputs). `to-date` is the
|
|
1784
|
+
// inclusive end day, advanced to the next UTC midnight. Throws TypeError
|
|
1785
|
+
// on a malformed value; defaults to the trailing 30 days. Mirrors the
|
|
1786
|
+
// reports window resolver so both report surfaces parse identically.
|
|
1787
|
+
function _labelWindow(url) {
|
|
1788
|
+
var from = _parseEpochMs(url && url.searchParams.get("from"), "from");
|
|
1789
|
+
var to = _parseEpochMs(url && url.searchParams.get("to"), "to");
|
|
1790
|
+
if (from == null) from = _parseDateParam(url && url.searchParams.get("from-date"), "from");
|
|
1791
|
+
if (to == null) {
|
|
1792
|
+
var toDate = _parseDateParam(url && url.searchParams.get("to-date"), "to");
|
|
1793
|
+
if (toDate != null) to = toDate + b.constants.TIME.days(1);
|
|
1794
|
+
}
|
|
1795
|
+
var now = Date.now();
|
|
1796
|
+
return {
|
|
1797
|
+
to: to == null ? now : to,
|
|
1798
|
+
from: from == null ? (now - b.constants.TIME.days(30)) : from,
|
|
1799
|
+
};
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
// The status filter on the standalone list — only the values the
|
|
1803
|
+
// primitive exposes a cross-order list read for.
|
|
1804
|
+
function _labelStatusParam(url) {
|
|
1805
|
+
var raw = url && url.searchParams.get("status");
|
|
1806
|
+
if (raw == null || raw === "") return "pending";
|
|
1807
|
+
if (raw !== "pending" && raw !== "voided") {
|
|
1808
|
+
throw new TypeError("admin: status must be one of pending, voided");
|
|
1809
|
+
}
|
|
1810
|
+
return raw;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
// Optional carrier filter for the costs report. Validated against the
|
|
1814
|
+
// primitive's frozen enum so a bad value is a notice, not a 500.
|
|
1815
|
+
function _labelCarrierParam(url) {
|
|
1816
|
+
var raw = url && url.searchParams.get("carrier");
|
|
1817
|
+
if (raw == null || raw === "") return null;
|
|
1818
|
+
if (shippingLabels.CARRIERS.indexOf(raw) === -1) {
|
|
1819
|
+
throw new TypeError("admin: carrier must be one of " + shippingLabels.CARRIERS.join(", "));
|
|
1820
|
+
}
|
|
1821
|
+
return raw;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// Compose the list payload for the chosen status. `pending` drains the
|
|
1825
|
+
// queue (limit 200, ignoring the window — a pending label has no
|
|
1826
|
+
// purchased/voided timestamp to range on); `voided` ranges voided_at
|
|
1827
|
+
// over the window.
|
|
1828
|
+
async function _labelListPayload(status, win) {
|
|
1829
|
+
if (status === "voided") {
|
|
1830
|
+
var voided = await shippingLabels.voidedInWindow({ from: win.from, to: win.to });
|
|
1831
|
+
return { status: "voided", from: win.from, to: win.to, labels: voided };
|
|
1832
|
+
}
|
|
1833
|
+
var pending = await shippingLabels.pendingLabels({ limit: MAX_LABEL_LIST_LIMIT });
|
|
1834
|
+
return { status: "pending", from: win.from, to: win.to, labels: pending };
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
router.get("/admin/shipping-labels", _pageOrApi(true,
|
|
1838
|
+
R(async function (req, res) {
|
|
1839
|
+
var url = req.url ? new URL(req.url, "http://localhost") : null;
|
|
1840
|
+
var status, win;
|
|
1841
|
+
try { status = _labelStatusParam(url); win = _labelWindow(url); }
|
|
1842
|
+
catch (e) { if (e instanceof TypeError) return _problem(res, 400, "bad-request", e.message); throw e; }
|
|
1843
|
+
var payload;
|
|
1844
|
+
try { payload = await _labelListPayload(status, win); }
|
|
1845
|
+
catch (e) { if (e instanceof TypeError) return _problem(res, 400, "bad-request", e.message); throw e; }
|
|
1846
|
+
_json(res, 200, payload);
|
|
1847
|
+
}),
|
|
1848
|
+
async function (req, res) {
|
|
1849
|
+
var url = req.url ? new URL(req.url, "http://localhost") : null;
|
|
1850
|
+
var status = "pending", notice = null;
|
|
1851
|
+
var win = { to: Date.now(), from: Date.now() - b.constants.TIME.days(30) };
|
|
1852
|
+
try { status = _labelStatusParam(url); win = _labelWindow(url); }
|
|
1853
|
+
catch (e) {
|
|
1854
|
+
if (!(e instanceof TypeError)) throw e;
|
|
1855
|
+
notice = e.message.replace(/^admin:\s*/, "");
|
|
1856
|
+
}
|
|
1857
|
+
var payload;
|
|
1858
|
+
try { payload = await _labelListPayload(status, win); }
|
|
1859
|
+
catch (e2) {
|
|
1860
|
+
if (!(e2 instanceof TypeError)) throw e2;
|
|
1861
|
+
// A bad range that slipped past the param parse (primitive
|
|
1862
|
+
// re-validates from < to) → fall back to the default window.
|
|
1863
|
+
win = { to: Date.now(), from: Date.now() - b.constants.TIME.days(30) };
|
|
1864
|
+
notice = e2.message.replace(/^shipping-labels:\s*/, "");
|
|
1865
|
+
payload = await _labelListPayload(status, win);
|
|
1866
|
+
}
|
|
1867
|
+
_sendHtml(res, 200, renderAdminShippingLabels({
|
|
1868
|
+
shop_name: deps.shop_name, nav_available: navAvailable,
|
|
1869
|
+
payload: payload, notice: notice,
|
|
1870
|
+
}));
|
|
1871
|
+
},
|
|
1872
|
+
));
|
|
1873
|
+
|
|
1874
|
+
router.get("/admin/shipping-labels/pending", _pageOrApi(true,
|
|
1875
|
+
R(async function (req, res) {
|
|
1876
|
+
var rows;
|
|
1877
|
+
try { rows = await shippingLabels.pendingLabels({ limit: MAX_LABEL_LIST_LIMIT }); }
|
|
1878
|
+
catch (e) { if (e instanceof TypeError) return _problem(res, 400, "bad-request", e.message); throw e; }
|
|
1879
|
+
_json(res, 200, { limit: MAX_LABEL_LIST_LIMIT, labels: rows });
|
|
1880
|
+
}),
|
|
1881
|
+
async function (req, res) {
|
|
1882
|
+
var rows = [], notice = null;
|
|
1883
|
+
try { rows = await shippingLabels.pendingLabels({ limit: MAX_LABEL_LIST_LIMIT }); }
|
|
1884
|
+
catch (e) {
|
|
1885
|
+
if (!(e instanceof TypeError)) throw e;
|
|
1886
|
+
notice = e.message.replace(/^shipping-labels:\s*/, "");
|
|
1887
|
+
}
|
|
1888
|
+
_sendHtml(res, 200, renderAdminShippingLabelsPending({
|
|
1889
|
+
shop_name: deps.shop_name, nav_available: navAvailable,
|
|
1890
|
+
labels: rows, notice: notice,
|
|
1891
|
+
}));
|
|
1892
|
+
},
|
|
1893
|
+
));
|
|
1894
|
+
|
|
1895
|
+
router.get("/admin/shipping-labels/costs", _pageOrApi(true,
|
|
1896
|
+
R(async function (req, res) {
|
|
1897
|
+
var url = req.url ? new URL(req.url, "http://localhost") : null;
|
|
1898
|
+
var win, carrier;
|
|
1899
|
+
try { win = _labelWindow(url); carrier = _labelCarrierParam(url); }
|
|
1900
|
+
catch (e) { if (e instanceof TypeError) return _problem(res, 400, "bad-request", e.message); throw e; }
|
|
1901
|
+
var report;
|
|
1902
|
+
try { report = await _labelCostsReport(win, carrier); }
|
|
1903
|
+
catch (e) { if (e instanceof TypeError) return _problem(res, 400, "bad-request", e.message); throw e; }
|
|
1904
|
+
_json(res, 200, report);
|
|
1905
|
+
}),
|
|
1906
|
+
async function (req, res) {
|
|
1907
|
+
var url = req.url ? new URL(req.url, "http://localhost") : null;
|
|
1908
|
+
var notice = null, carrier = null;
|
|
1909
|
+
var win = { to: Date.now(), from: Date.now() - b.constants.TIME.days(30) };
|
|
1910
|
+
try { win = _labelWindow(url); carrier = _labelCarrierParam(url); }
|
|
1911
|
+
catch (e) {
|
|
1912
|
+
if (!(e instanceof TypeError)) throw e;
|
|
1913
|
+
notice = e.message.replace(/^admin:\s*/, "");
|
|
1914
|
+
}
|
|
1915
|
+
var report;
|
|
1916
|
+
try { report = await _labelCostsReport(win, carrier); }
|
|
1917
|
+
catch (e2) {
|
|
1918
|
+
if (!(e2 instanceof TypeError)) throw e2;
|
|
1919
|
+
win = { to: Date.now(), from: Date.now() - b.constants.TIME.days(30) };
|
|
1920
|
+
carrier = null;
|
|
1921
|
+
notice = e2.message.replace(/^shipping-labels:\s*/, "");
|
|
1922
|
+
report = await _labelCostsReport(win, carrier);
|
|
1923
|
+
}
|
|
1924
|
+
_sendHtml(res, 200, renderAdminShippingLabelCosts({
|
|
1925
|
+
shop_name: deps.shop_name, nav_available: navAvailable,
|
|
1926
|
+
report: report, carriers: shippingLabels.CARRIERS, notice: notice,
|
|
1927
|
+
}));
|
|
1928
|
+
},
|
|
1929
|
+
));
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
// Compose the broker-spend report: the per-(broker, currency) aggregate
|
|
1933
|
+
// from costsByPeriod plus a per-currency rollup of the gross spend +
|
|
1934
|
+
// label count across the window. `_strictMinorInt`-safe — the primitive
|
|
1935
|
+
// already returns integer minor units; the rollup only sums them.
|
|
1936
|
+
async function _labelCostsReport(win, carrier) {
|
|
1937
|
+
var opts2 = { from: win.from, to: win.to };
|
|
1938
|
+
if (carrier) opts2.carrier = carrier;
|
|
1939
|
+
var rows = await shippingLabels.costsByPeriod(opts2);
|
|
1940
|
+
var byCurrency = {};
|
|
1941
|
+
for (var i = 0; i < rows.length; i += 1) {
|
|
1942
|
+
var r = rows[i];
|
|
1943
|
+
var cur = r.currency || "USD";
|
|
1944
|
+
if (!byCurrency[cur]) byCurrency[cur] = { currency: cur, total_minor: 0, label_count: 0 };
|
|
1945
|
+
// costsByPeriod coerces these to plain numbers already; treat them as
|
|
1946
|
+
// integer minor units (admin never renders raw broker prose here).
|
|
1947
|
+
byCurrency[cur].total_minor += _strictMinorInt(r.total_minor, "shippingLabels", "total_minor");
|
|
1948
|
+
byCurrency[cur].label_count += _strictMinorInt(r.label_count, "shippingLabels", "label_count");
|
|
1949
|
+
}
|
|
1950
|
+
var totals = Object.keys(byCurrency).map(function (k) { return byCurrency[k]; });
|
|
1951
|
+
totals.sort(function (a, c) { return a.currency < c.currency ? -1 : a.currency > c.currency ? 1 : 0; });
|
|
1952
|
+
return {
|
|
1953
|
+
from: win.from,
|
|
1954
|
+
to: win.to,
|
|
1955
|
+
carrier: carrier || null,
|
|
1956
|
+
by_broker: rows,
|
|
1957
|
+
totals: totals,
|
|
1958
|
+
};
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1716
1961
|
// ---- split shipments (order-detail planner) -------------------------
|
|
1717
1962
|
//
|
|
1718
1963
|
// Splits one order into N parcels: ship some lines now, the rest later.
|
|
@@ -5894,6 +6139,7 @@ var ADMIN_NAV_ITEMS = [
|
|
|
5894
6139
|
{ key: "tax", href: "/admin/tax-rates", label: "Tax", requires: "taxRates" },
|
|
5895
6140
|
{ key: "tax-filings", href: "/admin/tax-filings", label: "Tax filings", requires: "salesTaxFilings" },
|
|
5896
6141
|
{ key: "shipping", href: "/admin/shipping", label: "Shipping", requires: "shippingZones" },
|
|
6142
|
+
{ key: "shipping-labels", href: "/admin/shipping-labels", label: "Shipping labels", requires: "shippingLabels" },
|
|
5897
6143
|
{ key: "pick-lists", href: "/admin/pick-lists", label: "Pick lists", requires: "pickLists" },
|
|
5898
6144
|
{ key: "announcements", href: "/admin/announcements", label: "Announcements", requires: "announcementBar" },
|
|
5899
6145
|
{ key: "surveys", href: "/admin/surveys", label: "Surveys", requires: "customerSurveys" },
|
|
@@ -6296,6 +6542,173 @@ function renderAdminReports(opts) {
|
|
|
6296
6542
|
return _renderAdminShell(opts.shop_name, "Reports", body, "reports", opts.nav_available);
|
|
6297
6543
|
}
|
|
6298
6544
|
|
|
6545
|
+
// A single shipping-label row for the standalone cross-order tables. Shows
|
|
6546
|
+
// carrier + service, tracking number, cost (via pricing.format from the
|
|
6547
|
+
// label's own minor units + currency), the broker it came from, its status
|
|
6548
|
+
// pill, and a link to the broker's label URL. Read-only — lifecycle actions
|
|
6549
|
+
// (mark used / void) live on the order detail where the shipment context is.
|
|
6550
|
+
function _shippingLabelRow(l) {
|
|
6551
|
+
var costCell = (l.cost_minor != null && l.currency)
|
|
6552
|
+
? _htmlEscape(pricing.format(l.cost_minor, l.currency))
|
|
6553
|
+
: "<span class=\"meta\">—</span>";
|
|
6554
|
+
var trackCell = l.tracking_number
|
|
6555
|
+
? "<code class=\"order-id\">" + _htmlEscape(String(l.tracking_number)) + "</code>"
|
|
6556
|
+
: "<span class=\"meta\">—</span>";
|
|
6557
|
+
var urlCell = l.label_url
|
|
6558
|
+
? "<a class=\"order-id\" href=\"" + _htmlEscape(String(l.label_url)) + "\" rel=\"noopener nofollow\" target=\"_blank\">Open ↗</a>"
|
|
6559
|
+
: "<span class=\"meta\">—</span>";
|
|
6560
|
+
var viaCell = l.purchased_via
|
|
6561
|
+
? _htmlEscape(String(l.purchased_via))
|
|
6562
|
+
: "<span class=\"meta\">—</span>";
|
|
6563
|
+
return "<tr>" +
|
|
6564
|
+
"<td>" + _htmlEscape(String(l.carrier)) + " <span class=\"meta\">" + _htmlEscape(String(l.service_level || "")) + "</span></td>" +
|
|
6565
|
+
"<td>" + trackCell + "</td>" +
|
|
6566
|
+
"<td class=\"num\">" + costCell + "</td>" +
|
|
6567
|
+
"<td>" + viaCell + "</td>" +
|
|
6568
|
+
"<td><span class=\"status-pill " + _htmlEscape(String(l.status)) + "\">" + _htmlEscape(String(l.status)) + "</span></td>" +
|
|
6569
|
+
"<td>" + urlCell + "</td>" +
|
|
6570
|
+
"<td>" + _htmlEscape(_fmtDate(l.created_at)) + "</td>" +
|
|
6571
|
+
"</tr>";
|
|
6572
|
+
}
|
|
6573
|
+
|
|
6574
|
+
// Sub-nav shared by the three standalone shipping-label screens — the
|
|
6575
|
+
// list, the broker-spend report, and the mint queue.
|
|
6576
|
+
function _shippingLabelSubnav(active) {
|
|
6577
|
+
var tabs = [
|
|
6578
|
+
["list", "/admin/shipping-labels", "All labels"],
|
|
6579
|
+
["pending", "/admin/shipping-labels/pending", "Mint queue"],
|
|
6580
|
+
["costs", "/admin/shipping-labels/costs", "Broker spend"],
|
|
6581
|
+
];
|
|
6582
|
+
return "<div class=\"order-filters\">" + tabs.map(function (t) {
|
|
6583
|
+
return "<a class=\"chip" + (active === t[0] ? " chip--on" : "") + "\" href=\"" + t[1] + "\">" + _htmlEscape(t[2]) + "</a>";
|
|
6584
|
+
}).join("") + "</div>";
|
|
6585
|
+
}
|
|
6586
|
+
|
|
6587
|
+
// Standalone cross-order label list. The primitive exposes a list read for
|
|
6588
|
+
// two statuses — pending (the mint queue) and voided (over a date range) —
|
|
6589
|
+
// so the status filter offers those two. Purchased + used labels are
|
|
6590
|
+
// reached from their order's detail panel, not browsed cross-order. A date
|
|
6591
|
+
// range narrows the voided view (ignored for pending, which has no
|
|
6592
|
+
// purchased/voided timestamp to range on).
|
|
6593
|
+
function renderAdminShippingLabels(opts) {
|
|
6594
|
+
opts = opts || {};
|
|
6595
|
+
var payload = opts.payload || { status: "pending", labels: [], from: Date.now(), to: Date.now() };
|
|
6596
|
+
var notice = opts.notice ? "<div class=\"banner banner--warn\">" + _htmlEscape(opts.notice) + "</div>" : "";
|
|
6597
|
+
var labels = payload.labels || [];
|
|
6598
|
+
var status = payload.status || "pending";
|
|
6599
|
+
|
|
6600
|
+
var statuses = [["pending", "Pending"], ["voided", "Voided"]];
|
|
6601
|
+
var chips = "<div class=\"order-filters\">" + statuses.map(function (s) {
|
|
6602
|
+
return "<a class=\"chip" + (status === s[0] ? " chip--on" : "") + "\" href=\"/admin/shipping-labels?status=" + encodeURIComponent(s[0]) + "\">" + _htmlEscape(s[1]) + "</a>";
|
|
6603
|
+
}).join("") + "</div>";
|
|
6604
|
+
|
|
6605
|
+
// Date-range form only narrows the voided view (GET so the window lives in
|
|
6606
|
+
// the URL). For pending it's still shown for consistency but the window is
|
|
6607
|
+
// not applied.
|
|
6608
|
+
var fromVal = _dateInputValue(payload.from);
|
|
6609
|
+
var toVal = _dateInputValue((payload.to || Date.now()) - b.constants.TIME.days(1));
|
|
6610
|
+
var rangeForm =
|
|
6611
|
+
"<form method=\"get\" action=\"/admin/shipping-labels\" class=\"order-filters\">" +
|
|
6612
|
+
"<input type=\"hidden\" name=\"status\" value=\"" + _htmlEscape(status) + "\">" +
|
|
6613
|
+
"<label class=\"form-field\"><span>From</span><input type=\"date\" name=\"from-date\" value=\"" + _htmlEscape(fromVal) + "\"></label>" +
|
|
6614
|
+
"<label class=\"form-field\"><span>To</span><input type=\"date\" name=\"to-date\" value=\"" + _htmlEscape(toVal) + "\"></label>" +
|
|
6615
|
+
"<button class=\"btn\" type=\"submit\">Apply</button>" +
|
|
6616
|
+
"</form>";
|
|
6617
|
+
|
|
6618
|
+
var rows = labels.map(_shippingLabelRow).join("");
|
|
6619
|
+
var table = labels.length
|
|
6620
|
+
? "<div class=\"panel\"><table><thead><tr><th scope=\"col\">Carrier</th><th scope=\"col\">Tracking</th><th scope=\"col\" class=\"num\">Cost</th><th scope=\"col\">Broker</th><th scope=\"col\">Status</th><th scope=\"col\">Label</th><th scope=\"col\">Created</th></tr></thead><tbody>" + rows + "</tbody></table></div>"
|
|
6621
|
+
: "<p class=\"empty\">No " + _htmlEscape(status) + " labels" + (status === "voided" ? " in this window" : "") + ".</p>";
|
|
6622
|
+
|
|
6623
|
+
var body =
|
|
6624
|
+
"<section><h2>Shipping labels</h2>" + notice +
|
|
6625
|
+
_shippingLabelSubnav("list") +
|
|
6626
|
+
chips +
|
|
6627
|
+
(status === "voided" ? rangeForm : "") +
|
|
6628
|
+
table +
|
|
6629
|
+
"</section>";
|
|
6630
|
+
return _renderAdminShell(opts.shop_name, "Shipping labels", body, "shipping-labels", opts.nav_available);
|
|
6631
|
+
}
|
|
6632
|
+
|
|
6633
|
+
// The mint queue: pending labels awaiting a broker mint, oldest first. The
|
|
6634
|
+
// operator's broker worker drains this (requestLabel wrote each row;
|
|
6635
|
+
// markPurchased clears it). Read-only console view of the same queue.
|
|
6636
|
+
function renderAdminShippingLabelsPending(opts) {
|
|
6637
|
+
opts = opts || {};
|
|
6638
|
+
var labels = opts.labels || [];
|
|
6639
|
+
var notice = opts.notice ? "<div class=\"banner banner--warn\">" + _htmlEscape(opts.notice) + "</div>" : "";
|
|
6640
|
+
var rows = labels.map(_shippingLabelRow).join("");
|
|
6641
|
+
var table = labels.length
|
|
6642
|
+
? "<div class=\"panel\"><table><thead><tr><th scope=\"col\">Carrier</th><th scope=\"col\">Tracking</th><th scope=\"col\" class=\"num\">Cost</th><th scope=\"col\">Broker</th><th scope=\"col\">Status</th><th scope=\"col\">Label</th><th scope=\"col\">Created</th></tr></thead><tbody>" + rows + "</tbody></table></div>"
|
|
6643
|
+
: "<p class=\"empty\">No labels awaiting a broker mint.</p>";
|
|
6644
|
+
var body =
|
|
6645
|
+
"<section><h2>Shipping labels</h2>" + notice +
|
|
6646
|
+
_shippingLabelSubnav("pending") +
|
|
6647
|
+
"<p class=\"meta\">Pending labels awaiting a broker mint, oldest first (up to " + String(MAX_LABEL_LIST_LIMIT) + ").</p>" +
|
|
6648
|
+
table +
|
|
6649
|
+
"</section>";
|
|
6650
|
+
return _renderAdminShell(opts.shop_name, "Shipping labels", body, "shipping-labels", opts.nav_available);
|
|
6651
|
+
}
|
|
6652
|
+
|
|
6653
|
+
// Broker-spend report: gross label spend + label count grouped by broker +
|
|
6654
|
+
// currency over a date range, with an optional carrier filter and a
|
|
6655
|
+
// per-currency headline rollup. Money formats through the same pricing
|
|
6656
|
+
// helper the order + reports pages use.
|
|
6657
|
+
function renderAdminShippingLabelCosts(opts) {
|
|
6658
|
+
opts = opts || {};
|
|
6659
|
+
var report = opts.report || { from: Date.now(), to: Date.now(), by_broker: [], totals: [], carrier: null };
|
|
6660
|
+
var carriers = opts.carriers || [];
|
|
6661
|
+
var notice = opts.notice ? "<div class=\"banner banner--warn\">" + _htmlEscape(opts.notice) + "</div>" : "";
|
|
6662
|
+
|
|
6663
|
+
var fromVal = _dateInputValue(report.from);
|
|
6664
|
+
var toVal = _dateInputValue(report.to - b.constants.TIME.days(1));
|
|
6665
|
+
var carrierOpts = "<option value=\"\">All carriers</option>" + carriers.map(function (c) {
|
|
6666
|
+
return "<option value=\"" + _htmlEscape(c) + "\"" + (report.carrier === c ? " selected" : "") + ">" + _htmlEscape(c) + "</option>";
|
|
6667
|
+
}).join("");
|
|
6668
|
+
var rangeForm =
|
|
6669
|
+
"<form method=\"get\" action=\"/admin/shipping-labels/costs\" class=\"order-filters\">" +
|
|
6670
|
+
"<label class=\"form-field\"><span>From</span><input type=\"date\" name=\"from-date\" value=\"" + _htmlEscape(fromVal) + "\"></label>" +
|
|
6671
|
+
"<label class=\"form-field\"><span>To</span><input type=\"date\" name=\"to-date\" value=\"" + _htmlEscape(toVal) + "\"></label>" +
|
|
6672
|
+
"<label class=\"form-field\"><span>Carrier</span><select name=\"carrier\">" + carrierOpts + "</select></label>" +
|
|
6673
|
+
"<button class=\"btn\" type=\"submit\">Apply</button>" +
|
|
6674
|
+
"</form>";
|
|
6675
|
+
|
|
6676
|
+
// Per-currency headline cards — total gross spend + label count.
|
|
6677
|
+
var totals = report.totals || [];
|
|
6678
|
+
var statsBlock = totals.length
|
|
6679
|
+
? "<section><h2>Total spend</h2><div class=\"stat-grid\">" + totals.map(function (t) {
|
|
6680
|
+
return _statCard("Spend (" + t.currency + ")", pricing.format(t.total_minor, t.currency)) +
|
|
6681
|
+
_statCard("Labels (" + t.currency + ")", String(t.label_count));
|
|
6682
|
+
}).join("") + "</div></section>"
|
|
6683
|
+
: "<section><h2>Total spend</h2><p class=\"empty\">No labels purchased in this window.</p></section>";
|
|
6684
|
+
|
|
6685
|
+
var byBroker = report.by_broker || [];
|
|
6686
|
+
var brokerRows = byBroker.length
|
|
6687
|
+
? byBroker.map(function (r) {
|
|
6688
|
+
return "<tr>" +
|
|
6689
|
+
"<td>" + _htmlEscape(String(r.purchased_via)) + "</td>" +
|
|
6690
|
+
"<td>" + _htmlEscape(String(r.currency)) + "</td>" +
|
|
6691
|
+
"<td class=\"num\">" + _htmlEscape(String(r.label_count)) + "</td>" +
|
|
6692
|
+
"<td class=\"num\">" + _htmlEscape(pricing.format(r.total_minor, r.currency)) + "</td>" +
|
|
6693
|
+
"</tr>";
|
|
6694
|
+
}).join("")
|
|
6695
|
+
: "<tr><td colspan=\"4\" class=\"empty\">No labels purchased in this window.</td></tr>";
|
|
6696
|
+
var brokerBlock =
|
|
6697
|
+
"<section><h2>By broker</h2><div class=\"panel\">" +
|
|
6698
|
+
"<table><thead><tr><th scope=\"col\">Broker</th><th scope=\"col\">Currency</th><th scope=\"col\" class=\"num\">Labels</th><th scope=\"col\" class=\"num\">Spend</th></tr></thead><tbody>" + brokerRows + "</tbody></table>" +
|
|
6699
|
+
"</div></section>";
|
|
6700
|
+
|
|
6701
|
+
var body =
|
|
6702
|
+
"<section><h2>Shipping labels</h2>" + notice +
|
|
6703
|
+
_shippingLabelSubnav("costs") +
|
|
6704
|
+
"<p class=\"meta\">Window: " + _htmlEscape(_fmtDate(report.from)) + " → " + _htmlEscape(_fmtDate(report.to)) +
|
|
6705
|
+
(report.carrier ? " · carrier " + _htmlEscape(String(report.carrier)) : "") + "</p>" +
|
|
6706
|
+
rangeForm +
|
|
6707
|
+
"</section>" +
|
|
6708
|
+
statsBlock + brokerBlock;
|
|
6709
|
+
return _renderAdminShell(opts.shop_name, "Shipping labels", body, "shipping-labels", opts.nav_available);
|
|
6710
|
+
}
|
|
6711
|
+
|
|
6299
6712
|
function renderAdminOrder(opts) {
|
|
6300
6713
|
opts = opts || {};
|
|
6301
6714
|
var o = opts.order;
|
|
@@ -6506,17 +6919,26 @@ function _orderLabelPanel(orderId, shipment, carriers, packageTypes, purchasedVi
|
|
|
6506
6919
|
var urlCell = l.label_url
|
|
6507
6920
|
? "<a class=\"order-id\" href=\"" + _htmlEscape(String(l.label_url)) + "\" rel=\"noopener nofollow\" target=\"_blank\">Open ↗</a>"
|
|
6508
6921
|
: "<span class=\"meta\">—</span>";
|
|
6509
|
-
|
|
6510
|
-
|
|
6511
|
-
|
|
6512
|
-
|
|
6922
|
+
// A purchased label can be marked used (handed to the carrier) OR voided
|
|
6923
|
+
// (broker void, within the 30-day window). The void form carries a
|
|
6924
|
+
// required reason input so the operator records WHY before the POST; the
|
|
6925
|
+
// primitive refuses a blank/expired void with a 400 → notice.
|
|
6926
|
+
var actionCell = "<span class=\"meta\">—</span>";
|
|
6927
|
+
if (l.status === "purchased") {
|
|
6928
|
+
actionCell =
|
|
6929
|
+
"<form method=\"post\" action=\"/admin/orders/" + _htmlEscape(orderId) + "/labels/" + _htmlEscape(l.id) + "/used\" class=\"form-inline\">" +
|
|
6930
|
+
"<button class=\"btn btn--ghost\" type=\"submit\">Mark used</button></form> " +
|
|
6931
|
+
"<form method=\"post\" action=\"/admin/orders/" + _htmlEscape(orderId) + "/labels/" + _htmlEscape(l.id) + "/void\" class=\"form-inline\">" +
|
|
6932
|
+
"<input type=\"text\" name=\"reason\" placeholder=\"Void reason\" maxlength=\"512\" aria-label=\"Void reason\" required>" +
|
|
6933
|
+
"<button class=\"btn btn--danger\" type=\"submit\">Void</button></form>";
|
|
6934
|
+
}
|
|
6513
6935
|
return "<tr>" +
|
|
6514
6936
|
"<td>" + _htmlEscape(String(l.carrier)) + " <span class=\"meta\">" + _htmlEscape(String(l.service_level || "")) + "</span></td>" +
|
|
6515
6937
|
"<td>" + trackCell + "</td>" +
|
|
6516
6938
|
"<td class=\"num\">" + costCell + "</td>" +
|
|
6517
6939
|
"<td><span class=\"status-pill " + _htmlEscape(l.status) + "\">" + _htmlEscape(l.status) + "</span></td>" +
|
|
6518
6940
|
"<td>" + urlCell + "</td>" +
|
|
6519
|
-
"<td>" +
|
|
6941
|
+
"<td>" + actionCell + "</td>" +
|
|
6520
6942
|
"</tr>";
|
|
6521
6943
|
}).join("");
|
|
6522
6944
|
var labelsTable = labels.length
|
package/lib/asset-manifest.json
CHANGED
package/package.json
CHANGED