@asteby/storefront 0.24.0 → 0.26.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.
@@ -1,5 +1,5 @@
1
- import { a2 as FiscalDocumentSource, bn as RegionFiscalEntry, aa as IdentityDocumentSpec, a1 as FiscalDocumentEvidence, bo as RegionFiscalId, ac as IdentityRulesV1 } from './account-settings-CrQV1rPU.js';
2
- export { a9 as IdentityCapture, ab as IdentityFieldRule, ad as IdentityStrategy } from './account-settings-CrQV1rPU.js';
1
+ import { a2 as FiscalDocumentSource, bq as RegionFiscalEntry, aa as IdentityDocumentSpec, a1 as FiscalDocumentEvidence, br as RegionFiscalId, ac as IdentityRulesV1 } from './account-settings-BnhDUPWx.js';
2
+ export { a9 as IdentityCapture, ab as IdentityFieldRule, ad as IdentityStrategy } from './account-settings-BnhDUPWx.js';
3
3
  import './geo.js';
4
4
 
5
5
  /** A value read from a document: text, or the codes of a catalog (`multiple` fields). */
package/dist/index.cjs CHANGED
@@ -112,6 +112,15 @@ function isTokenPublishable(token) {
112
112
  }
113
113
 
114
114
  // src/query.ts
115
+ function accountListQuery(params) {
116
+ if (!params) return void 0;
117
+ const out = {};
118
+ for (const [key, value] of Object.entries(params)) {
119
+ if (value === void 0 || value === null || value === "") continue;
120
+ out[key] = value;
121
+ }
122
+ return out;
123
+ }
115
124
  function appendParams(search, params) {
116
125
  if (!params) return search;
117
126
  for (const [key, raw] of Object.entries(params)) {
@@ -569,7 +578,50 @@ function createStorefrontClient(config) {
569
578
  * repeat after success is also fine. Afterwards the token is dead: drop it.
570
579
  */
571
580
  deleteAccount: (input, options) => write("DELETE", "/storefront/customer", input, options),
572
- orders: (params, options) => get("/storefront/customer/orders", params, options),
581
+ /**
582
+ * The buyer's orders, newest first. Callable as before (`orders({ first })`) and, since contract 1.19, with
583
+ * `orders.list({ first, after, before, status, delivery_method, has_invoice, from, to, q })`: cursor paging
584
+ * (keyset, stable while new orders arrive), `page_info.start_cursor` / `has_previous_page` to go back, and
585
+ * `total_count` when it is cheap to know. An OPS older than 1.19 ignores the new parameters.
586
+ */
587
+ orders: Object.assign(
588
+ (params, options) => get("/storefront/customer/orders", params, options),
589
+ {
590
+ list: (params, options) => get("/storefront/customer/orders", accountListQuery(params), { ...options, cache: "no-store" })
591
+ }
592
+ ),
593
+ /**
594
+ * The buyer's invoices, one node per order that has them (`{ order, invoices }`), cursor-paged like `orders.list`.
595
+ * It replaces opening the detail of every order. An OPS older than 1.19 (no such route) is served from one page of
596
+ * orders and their details, so the account keeps working until the addon is updated.
597
+ */
598
+ invoices: {
599
+ list: async (params, options) => {
600
+ const page = await getOrNull("/storefront/customer/invoices", accountListQuery(params), { ...options, cache: "no-store" });
601
+ return page ?? legacyAccountList(client, params, options, (o) => o.invoice ? !["not_requested", "awaiting_payment", "window_closed"].includes(o.invoice.stage ?? "not_requested") : true, (o) => (o.invoices ?? []).length ? { order: orderRef(o), invoices: o.invoices ?? [] } : null);
602
+ }
603
+ },
604
+ /**
605
+ * The buyer's shipments, one node per delivered order with its service and parcels (`{ order, stage, service,
606
+ * shipments }`), cursor-paged like `orders.list`, without tracking events or map (those come with `order(id)`).
607
+ * An OPS older than 1.19 is served from one page of orders and their details.
608
+ */
609
+ shipments: {
610
+ list: async (params, options) => {
611
+ const page = await getOrNull("/storefront/customer/shipments", accountListQuery(params), { ...options, cache: "no-store" });
612
+ return page ?? legacyAccountList(
613
+ client,
614
+ params,
615
+ options,
616
+ (o) => o.delivery_method !== "pickup" && !["cancelled", "refunded", "pending_payment"].includes(o.status),
617
+ (o) => {
618
+ const service = o.shipping_service ?? null;
619
+ const shipments = o.shipments ?? [];
620
+ return service || shipments.length ? { order: orderRef(o), stage: o.progress?.stage ?? o.status, service, shipments } : null;
621
+ }
622
+ );
623
+ }
624
+ },
573
625
  /** `null` when the order does not exist or belongs to someone else. */
574
626
  order: (id, options) => getOrNull(`/storefront/customer/orders/${enc(id)}`, void 0, options),
575
627
  requestReturn: (orderId, input, options) => write("POST", `/storefront/customer/orders/${enc(orderId)}/returns`, input, options),
@@ -657,6 +709,20 @@ function createStorefrontClient(config) {
657
709
  };
658
710
  return client;
659
711
  }
712
+ var orderRef = (o) => ({ id: o.id, number: o.number, created_at: o.created_at });
713
+ async function legacyAccountList(client, params, options, keep, toNode) {
714
+ const page = await client.customer.orders.list({ ...params?.first ? { first: params.first } : {}, ...params?.after ? { after: params.after } : {}, ...params?.from ? { from: params.from } : {}, ...params?.to ? { to: params.to } : {}, ...params?.q ? { q: params.q } : {} }, options);
715
+ const details = await Promise.all(
716
+ page.nodes.filter(keep).map(
717
+ (o) => client.customer.order(o.id, options).catch((err) => {
718
+ if (err instanceof StorefrontError && err.status === 401) throw err;
719
+ return null;
720
+ })
721
+ )
722
+ );
723
+ const nodes = details.map((d) => d ? toNode(d) : null).filter((n) => n !== null);
724
+ return { nodes, page_info: { has_next_page: page.page_info.has_next_page, end_cursor: page.page_info.end_cursor } };
725
+ }
660
726
  function storefrontDomainHeader(domain, market) {
661
727
  const host = domain.trim();
662
728
  const code = (market ?? "").trim().toLowerCase();
@@ -741,6 +807,7 @@ var ES = {
741
807
  "status.preorder": "Preventa",
742
808
  "sub.backorder_eta": "Se env\xEDa a partir del {date}",
743
809
  "sub.preorder_date": "Sale a la venta el {date}",
810
+ "line.ships_on": "Se enviar\xE1 el: {date}",
744
811
  "cta.add": "Agregar al carrito",
745
812
  "cta.out_of_stock": "Agotado",
746
813
  "cta.backorder": "Pedir bajo pedido",
@@ -780,6 +847,7 @@ var EN = {
780
847
  "status.preorder": "Pre-order",
781
848
  "sub.backorder_eta": "Ships from {date}",
782
849
  "sub.preorder_date": "Available on {date}",
850
+ "line.ships_on": "Ships on: {date}",
783
851
  "cta.add": "Add to cart",
784
852
  "cta.out_of_stock": "Sold out",
785
853
  "cta.backorder": "Order now, ships later",
@@ -834,6 +902,18 @@ function formatDate(value, locale) {
834
902
  return value.slice(0, 10);
835
903
  }
836
904
  }
905
+ function lineShipDate(line) {
906
+ const day = (v) => {
907
+ const d = typeof v === "string" ? v.slice(0, 10) : "";
908
+ return /^\d{4}-\d{2}-\d{2}$/.test(d) ? d : null;
909
+ };
910
+ return day(line.ships_on) ?? day(line.availability?.restock_eta) ?? day(line.availability?.preorder_release_at);
911
+ }
912
+ function lineShipLabel(line, locale, overrides) {
913
+ const date = formatDate(lineShipDate(line), locale);
914
+ if (!date) return null;
915
+ return formatAvailabilityMessage(availabilityMessages(locale, overrides)["line.ships_on"], { date });
916
+ }
837
917
  function resolveAvailability(source, options = {}) {
838
918
  const a = source.availability;
839
919
  if (a && typeof a === "object" && typeof a.status === "string") return a;
@@ -1821,9 +1901,136 @@ function deliveryNotices(delivery) {
1821
1901
  };
1822
1902
  }
1823
1903
 
1904
+ // src/account-lists.ts
1905
+ var LIST_URL_ES = {
1906
+ after: "despues",
1907
+ before: "antes",
1908
+ pos: "pos",
1909
+ status: "estado",
1910
+ delivery: "entrega",
1911
+ invoice: "factura",
1912
+ from: "desde",
1913
+ to: "hasta",
1914
+ q: "q",
1915
+ deliveryValues: { shipping: "envio", pickup: "recoger" },
1916
+ invoiceValues: { yes: "si", no: "no" }
1917
+ };
1918
+ var LIST_URL_EN = {
1919
+ after: "after",
1920
+ before: "before",
1921
+ pos: "pos",
1922
+ status: "status",
1923
+ delivery: "delivery",
1924
+ invoice: "invoice",
1925
+ from: "from",
1926
+ to: "to",
1927
+ q: "q",
1928
+ deliveryValues: { shipping: "shipping", pickup: "pickup" },
1929
+ invoiceValues: { yes: "yes", no: "no" }
1930
+ };
1931
+ var CURSOR = /^[A-Za-z0-9_-]{1,300}$/;
1932
+ var DAY = /^\d{4}-\d{2}-\d{2}$/;
1933
+ var STATUS = /^[a-z_]{1,32}$/;
1934
+ var MAX_Q = 64;
1935
+ var MAX_POS = 1e6;
1936
+ var asParams = (search) => search instanceof URLSearchParams ? search : new URLSearchParams(typeof search === "string" ? search : "");
1937
+ var validDay = (v) => {
1938
+ if (!v || !DAY.test(v)) return void 0;
1939
+ const d = /* @__PURE__ */ new Date(`${v}T00:00:00Z`);
1940
+ return Number.isNaN(d.getTime()) || d.toISOString().slice(0, 10) !== v ? void 0 : v;
1941
+ };
1942
+ function readListQuery(search, names = LIST_URL_ES) {
1943
+ const p = asParams(search);
1944
+ const out = {};
1945
+ const after = p.get(names.after);
1946
+ const before = p.get(names.before);
1947
+ if (after && CURSOR.test(after)) out.after = after;
1948
+ else if (before && CURSOR.test(before)) out.before = before;
1949
+ const pos = Number(p.get(names.pos));
1950
+ if (Number.isInteger(pos) && pos >= 1 && pos <= MAX_POS) out.pos = pos;
1951
+ const status = p.get(names.status);
1952
+ if (status && STATUS.test(status)) out.status = status;
1953
+ const delivery = p.get(names.delivery);
1954
+ if (delivery === names.deliveryValues.shipping) out.delivery = "shipping";
1955
+ else if (delivery === names.deliveryValues.pickup) out.delivery = "pickup";
1956
+ const invoice = p.get(names.invoice);
1957
+ if (invoice === names.invoiceValues.yes) out.invoice = true;
1958
+ else if (invoice === names.invoiceValues.no) out.invoice = false;
1959
+ const from = validDay(p.get(names.from));
1960
+ const to = validDay(p.get(names.to));
1961
+ if (from) out.from = from;
1962
+ if (to && (!from || to >= from)) out.to = to;
1963
+ const q = (p.get(names.q) ?? "").trim().replace(/^#/, "").trim();
1964
+ if (q && q.length <= MAX_Q) out.q = q;
1965
+ return out;
1966
+ }
1967
+ function isFiltered(query) {
1968
+ return !!(query.status || query.delivery || query.invoice !== void 0 || query.from || query.to || query.q);
1969
+ }
1970
+ function firstPageQuery(query) {
1971
+ const { after: _a, before: _b, pos: _p, ...filters } = query;
1972
+ return filters;
1973
+ }
1974
+ function listApiParams(query, first) {
1975
+ const params = { first };
1976
+ if (query.after) params.after = query.after;
1977
+ else if (query.before) params.before = query.before;
1978
+ if (query.status) params.status = query.status;
1979
+ if (query.delivery) params.delivery_method = query.delivery;
1980
+ if (query.invoice !== void 0) params.has_invoice = query.invoice;
1981
+ if (query.from) params.from = query.from;
1982
+ if (query.to) params.to = query.to;
1983
+ if (query.q) params.q = query.q;
1984
+ return params;
1985
+ }
1986
+ function listQueryString(query, names = LIST_URL_ES) {
1987
+ const p = new URLSearchParams();
1988
+ if (query.after) p.set(names.after, query.after);
1989
+ else if (query.before) p.set(names.before, query.before);
1990
+ if (query.pos && query.pos > 1) p.set(names.pos, String(query.pos));
1991
+ if (query.status) p.set(names.status, query.status);
1992
+ if (query.delivery) p.set(names.delivery, names.deliveryValues[query.delivery]);
1993
+ if (query.invoice !== void 0) p.set(names.invoice, query.invoice ? names.invoiceValues.yes : names.invoiceValues.no);
1994
+ if (query.from) p.set(names.from, query.from);
1995
+ if (query.to) p.set(names.to, query.to);
1996
+ if (query.q) p.set(names.q, query.q);
1997
+ const s = p.toString();
1998
+ return s ? `?${s}` : "";
1999
+ }
2000
+ var listHref = (path, query, names = LIST_URL_ES) => `${path}${listQueryString(query, names)}`;
2001
+ function pagePosition({ query, pageInfo, count }) {
2002
+ if (count === 0) return void 0;
2003
+ if (!query.after && !query.before) return 1;
2004
+ if (pageInfo && pageInfo.has_previous_page === false) return 1;
2005
+ return query.pos;
2006
+ }
2007
+ function nextPageQuery(state) {
2008
+ const { query, pageInfo, count } = state;
2009
+ if (!pageInfo?.has_next_page || !pageInfo.end_cursor) return null;
2010
+ const here = pagePosition(state);
2011
+ return { ...firstPageQuery(query), after: pageInfo.end_cursor, ...here ? { pos: here + count } : {} };
2012
+ }
2013
+ function previousPageQuery(state) {
2014
+ const { query, pageInfo, first } = state;
2015
+ if (!query.after && !query.before) return null;
2016
+ if (pageInfo?.has_previous_page === false) return firstPageQuery(query);
2017
+ const cursor = pageInfo?.start_cursor;
2018
+ if (!cursor) return query.after || query.before ? firstPageQuery(query) : null;
2019
+ const here = pagePosition(state);
2020
+ if (here !== void 0 && here - first <= 1) return firstPageQuery(query);
2021
+ return { ...firstPageQuery(query), before: cursor, ...here ? { pos: Math.max(1, here - first) } : {} };
2022
+ }
2023
+ function pageRange(state) {
2024
+ const from = pagePosition(state);
2025
+ if (!from || state.count === 0) return null;
2026
+ return { from, to: from + state.count - 1, total: typeof state.total === "number" && state.total >= 0 ? state.total : null };
2027
+ }
2028
+
1824
2029
  exports.CLIENT_IP_HEADER = CLIENT_IP_HEADER;
1825
2030
  exports.COUNTRY_HEADERS = COUNTRY_HEADERS;
1826
2031
  exports.DEFAULT_FIT_TAG_PREFIX = DEFAULT_FIT_TAG_PREFIX;
2032
+ exports.LIST_URL_EN = LIST_URL_EN;
2033
+ exports.LIST_URL_ES = LIST_URL_ES;
1827
2034
  exports.MAX_SUBJECT_YEAR = MAX_SUBJECT_YEAR;
1828
2035
  exports.MIN_SUBJECT_YEAR = MIN_SUBJECT_YEAR;
1829
2036
  exports.MISSING_WEIGHT = MISSING_WEIGHT;
@@ -1834,6 +2041,7 @@ exports.PRIVATE_MASK = PRIVATE_MASK;
1834
2041
  exports.SHIPPING_STEPS = SHIPPING_STEPS;
1835
2042
  exports.SUBJECT_CATALOG_PAGE_BYTES = SUBJECT_CATALOG_PAGE_BYTES;
1836
2043
  exports.StorefrontError = StorefrontError;
2044
+ exports.accountListQuery = accountListQuery;
1837
2045
  exports.appendParams = appendParams;
1838
2046
  exports.availabilityLocale = availabilityLocale;
1839
2047
  exports.availabilityMessages = availabilityMessages;
@@ -1849,6 +2057,7 @@ exports.declineMessageKey = declineMessageKey;
1849
2057
  exports.deliveryInput = deliveryInput;
1850
2058
  exports.deliveryNotices = deliveryNotices;
1851
2059
  exports.diagnose = diagnose;
2060
+ exports.firstPageQuery = firstPageQuery;
1852
2061
  exports.fitTag = fitTag;
1853
2062
  exports.fitTagsAny = fitTagsAny;
1854
2063
  exports.formatAvailabilityMessage = formatAvailabilityMessage;
@@ -1859,20 +2068,29 @@ exports.groupInvoiceDocs = groupInvoiceDocs;
1859
2068
  exports.hreflangLinks = hreflangLinks;
1860
2069
  exports.invoiceFileBytes = invoiceFileBytes;
1861
2070
  exports.isAccountDeleteBlocked = isAccountDeleteBlocked;
2071
+ exports.isFiltered = isFiltered;
1862
2072
  exports.isMasked = isMasked;
1863
2073
  exports.isReauthRequired = isReauthRequired;
1864
2074
  exports.isStorefrontError = isStorefrontError;
1865
2075
  exports.isTestInvoice = isTestInvoice;
1866
2076
  exports.isTestShipment = isTestShipment;
1867
2077
  exports.isTokenPublishable = isTokenPublishable;
2078
+ exports.lineShipDate = lineShipDate;
2079
+ exports.lineShipLabel = lineShipLabel;
2080
+ exports.listApiParams = listApiParams;
2081
+ exports.listHref = listHref;
2082
+ exports.listQueryString = listQueryString;
1868
2083
  exports.maskToken = maskToken;
1869
2084
  exports.negotiateLocale = negotiateLocale;
1870
2085
  exports.nextAction = nextAction;
2086
+ exports.nextPageQuery = nextPageQuery;
1871
2087
  exports.normalizeClientIp = normalizeClientIp;
1872
2088
  exports.normalizeNote = normalizeNote;
1873
2089
  exports.opsSaysNotRetryable = opsSaysNotRetryable;
1874
2090
  exports.orderProgress = orderProgress;
1875
2091
  exports.orderShipments = orderShipments;
2092
+ exports.pagePosition = pagePosition;
2093
+ exports.pageRange = pageRange;
1876
2094
  exports.parseDelivery = parseDelivery;
1877
2095
  exports.parseMoney = parseMoney;
1878
2096
  exports.parseProductFilters = parseProductFilters;
@@ -1881,10 +2099,12 @@ exports.paymentIdempotencyKey = paymentIdempotencyKey;
1881
2099
  exports.paymentMessages = paymentMessages;
1882
2100
  exports.paymentOutcome = paymentOutcome;
1883
2101
  exports.preferredLanguages = preferredLanguages;
2102
+ exports.previousPageQuery = previousPageQuery;
1884
2103
  exports.productAvailability = productAvailability;
1885
2104
  exports.productListQuery = productListQuery;
1886
2105
  exports.promoProgressView = promoProgressView;
1887
2106
  exports.promotionMessages = promotionMessages;
2107
+ exports.readListQuery = readListQuery;
1888
2108
  exports.reconcileSubjectValues = reconcileSubjectValues;
1889
2109
  exports.repairPath = repairPath;
1890
2110
  exports.resolveAvailability = resolveAvailability;