@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.
- package/README.md +18 -0
- package/dist/{account-settings-CrQV1rPU.d.ts → account-settings-BnhDUPWx.d.ts} +29 -1
- package/dist/{account-settings-BZKux56f.d.cts → account-settings-C0r3jJ72.d.cts} +29 -1
- package/dist/{chunk-5BJRZIS3.js → chunk-ZLVXWHHQ.js} +17 -3
- package/dist/chunk-ZLVXWHHQ.js.map +1 -0
- package/dist/cli.js +68 -2
- package/dist/fiscal-document.d.cts +2 -2
- package/dist/fiscal-document.d.ts +2 -2
- package/dist/index.cjs +221 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +162 -5
- package/dist/index.d.ts +162 -5
- package/dist/index.js +195 -4
- package/dist/index.js.map +1 -1
- package/dist/mock.cjs +186 -4
- package/dist/mock.cjs.map +1 -1
- package/dist/mock.d.cts +6 -1
- package/dist/mock.d.ts +6 -1
- package/dist/mock.js +187 -5
- package/dist/mock.js.map +1 -1
- package/dist/mockup.d.cts +1 -1
- package/dist/mockup.d.ts +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-5BJRZIS3.js.map +0 -1
package/dist/mock.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bZ as SubjectKind, ac as IdentityRulesV1, br as RegionFiscalId, aa as IdentityDocumentSpec, bp as Region, bK as Shop, ba as Product, B as Collection, c0 as Theme, aR as Page, ay as Menu, e as Article, C as Cart, a as Address, ao as InvoiceRequest, E as Customer, a5 as FiscalProfile, bT as Subject, aF as Order, aU as PaymentAttemptResult, b7 as PendingPayment, aq as InvoiceStage, F as CustomerCapabilities, bh as PromotionAnnouncement, bJ as ShippingRate, a$ as PaymentMethod, c as AddressSuggestion } from './account-settings-C0r3jJ72.cjs';
|
|
2
2
|
import './geo.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -57,6 +57,11 @@ type MockStorefrontOptions = {
|
|
|
57
57
|
* when `customer:write` is among them. Implies scope enforcement.
|
|
58
58
|
*/
|
|
59
59
|
missingScopes?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* How many MORE orders the demo buyer (`cus_1`) has, numbered `S0001`…, to rehearse a long history (paging, filters,
|
|
62
|
+
* a B2B buyer with hundreds of orders). Default 0.
|
|
63
|
+
*/
|
|
64
|
+
syntheticOrders?: number;
|
|
60
65
|
/** Failed password logins per email before `429 rate_limited` (default 5; a success or a reset clears the count). */
|
|
61
66
|
maxLoginAttempts?: number;
|
|
62
67
|
/** Discount codes → percentage off the subtotal (default `{ BIENVENIDA10: 10 }`). */
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bZ as SubjectKind, ac as IdentityRulesV1, br as RegionFiscalId, aa as IdentityDocumentSpec, bp as Region, bK as Shop, ba as Product, B as Collection, c0 as Theme, aR as Page, ay as Menu, e as Article, C as Cart, a as Address, ao as InvoiceRequest, E as Customer, a5 as FiscalProfile, bT as Subject, aF as Order, aU as PaymentAttemptResult, b7 as PendingPayment, aq as InvoiceStage, F as CustomerCapabilities, bh as PromotionAnnouncement, bJ as ShippingRate, a$ as PaymentMethod, c as AddressSuggestion } from './account-settings-BnhDUPWx.js';
|
|
2
2
|
import './geo.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -57,6 +57,11 @@ type MockStorefrontOptions = {
|
|
|
57
57
|
* when `customer:write` is among them. Implies scope enforcement.
|
|
58
58
|
*/
|
|
59
59
|
missingScopes?: string[];
|
|
60
|
+
/**
|
|
61
|
+
* How many MORE orders the demo buyer (`cus_1`) has, numbered `S0001`…, to rehearse a long history (paging, filters,
|
|
62
|
+
* a B2B buyer with hundreds of orders). Default 0.
|
|
63
|
+
*/
|
|
64
|
+
syntheticOrders?: number;
|
|
60
65
|
/** Failed password logins per email before `429 rate_limited` (default 5; a success or a reset clears the count). */
|
|
61
66
|
maxLoginAttempts?: number;
|
|
62
67
|
/** Discount codes → percentage off the subtotal (default `{ BIENVENIDA10: 10 }`). */
|
package/dist/mock.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { resolveAvailability, isMasked, isTestShipment, sortTrackingEvents, orderProgress, nextAction, orderShipments, shipmentsStatus, PRIVATE_MASK, resolveSubject } from './chunk-
|
|
1
|
+
import { resolveAvailability, isMasked, isTestShipment, sortTrackingEvents, orderProgress, nextAction, orderShipments, shipmentsStatus, PRIVATE_MASK, resolveSubject } from './chunk-ZLVXWHHQ.js';
|
|
2
2
|
import { isValidPoint, rankByDistance } from './chunk-45R47HYO.js';
|
|
3
3
|
|
|
4
4
|
// src/mock/account-seed.ts
|
|
@@ -209,6 +209,76 @@ function buildPendingPayments(currency, nowMs) {
|
|
|
209
209
|
}
|
|
210
210
|
];
|
|
211
211
|
}
|
|
212
|
+
function buildSyntheticOrders(count, currency) {
|
|
213
|
+
const out = [];
|
|
214
|
+
const base = Date.parse("2026-08-01T12:00:00.000Z");
|
|
215
|
+
for (let i = 1; i <= count; i++) {
|
|
216
|
+
const kind = i % 6;
|
|
217
|
+
const status = kind === 0 ? "cancelled" : kind === 1 ? "pending_payment" : kind === 2 ? "fulfilling" : kind === 3 ? "shipped" : "delivered";
|
|
218
|
+
const pickup = i % 5 === 0;
|
|
219
|
+
const number = `S${String(i).padStart(4, "0")}`;
|
|
220
|
+
const total = 1e4 + i * 7919 % 9e4;
|
|
221
|
+
const o = {
|
|
222
|
+
id: `ord_syn_${i}`,
|
|
223
|
+
number,
|
|
224
|
+
status,
|
|
225
|
+
created_at: new Date(base - i * 36e5).toISOString(),
|
|
226
|
+
total: money(total, currency),
|
|
227
|
+
customer_id: "cus_1",
|
|
228
|
+
lines: [line(`Producto ${i}`, null, 1 + i % 3, Math.round(total / (1 + i % 3)), currency)],
|
|
229
|
+
delivery_method: pickup ? "pickup" : "shipping",
|
|
230
|
+
payment_status: status === "pending_payment" ? "pending" : status === "cancelled" ? "cancelled" : "paid",
|
|
231
|
+
shipping_address: address
|
|
232
|
+
};
|
|
233
|
+
if (!pickup && (status === "shipped" || status === "delivered")) {
|
|
234
|
+
o.shipments = [
|
|
235
|
+
{
|
|
236
|
+
id: `shp_syn_${i}`,
|
|
237
|
+
number: `ENV-S${i}`,
|
|
238
|
+
kind: "outbound",
|
|
239
|
+
status: status === "delivered" ? "delivered" : "in_transit",
|
|
240
|
+
environment: "production",
|
|
241
|
+
test_mode: false,
|
|
242
|
+
carrier: i % 2 ? "Estafeta" : "DHL",
|
|
243
|
+
carrier_logo_key: i % 2 ? "estafeta" : "dhl",
|
|
244
|
+
service: "Terrestre",
|
|
245
|
+
tracking_number: `SYN${String(i).padStart(8, "0")}`,
|
|
246
|
+
tracking_url: `https://rastreo.example.com/syn/${i}`,
|
|
247
|
+
shipped_at: new Date(base - i * 36e5 + 72e5).toISOString(),
|
|
248
|
+
delivered_at: status === "delivered" ? new Date(base - i * 36e5 + 864e5).toISOString() : null,
|
|
249
|
+
promised_by: null,
|
|
250
|
+
label_url: null,
|
|
251
|
+
events: [],
|
|
252
|
+
map: null
|
|
253
|
+
}
|
|
254
|
+
];
|
|
255
|
+
} else if (!pickup && status === "fulfilling") {
|
|
256
|
+
o.shipping_service = { title: "Env\xEDo Estafeta", carrier: "estafeta", carrier_logo_key: "estafeta", eta_days_min: 1, eta_days_max: 3 };
|
|
257
|
+
o.shipments = [];
|
|
258
|
+
}
|
|
259
|
+
if (status === "delivered" && i % 3 === 1) {
|
|
260
|
+
o.invoices = [
|
|
261
|
+
{
|
|
262
|
+
id: `inv_syn_${i}`,
|
|
263
|
+
status: "issued",
|
|
264
|
+
kind: "invoice",
|
|
265
|
+
stage: "issued",
|
|
266
|
+
action: "download",
|
|
267
|
+
can_request: false,
|
|
268
|
+
folio: `SYN-${String(i).padStart(8, "0")}`,
|
|
269
|
+
series: "A",
|
|
270
|
+
folio_number: String(2e3 + i),
|
|
271
|
+
total: money(total, currency),
|
|
272
|
+
issued_at: new Date(base - i * 36e5 + 36e5).toISOString(),
|
|
273
|
+
test_mode: false,
|
|
274
|
+
environment: "production"
|
|
275
|
+
}
|
|
276
|
+
];
|
|
277
|
+
}
|
|
278
|
+
out.push(o);
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
212
282
|
|
|
213
283
|
// src/mock/region-mx.seed.ts
|
|
214
284
|
var SEED_MX_CSF = {
|
|
@@ -1688,7 +1758,8 @@ function createMockStorefront(options = {}) {
|
|
|
1688
1758
|
{ title: "Playera b\xE1sica", variant_title: "M / Blanco", sku: null, quantity: 1, unit: fromCents(24900, currency), total: fromCents(24900, currency), image: null }
|
|
1689
1759
|
]
|
|
1690
1760
|
},
|
|
1691
|
-
...buildAccountOrders(currency)
|
|
1761
|
+
...buildAccountOrders(currency),
|
|
1762
|
+
...buildSyntheticOrders(options.syntheticOrders ?? 0, currency)
|
|
1692
1763
|
],
|
|
1693
1764
|
pendingPayments: buildPendingPayments(currency, Date.now()),
|
|
1694
1765
|
otps: /* @__PURE__ */ new Map(),
|
|
@@ -2812,10 +2883,121 @@ function createMockStorefront(options = {}) {
|
|
|
2812
2883
|
}
|
|
2813
2884
|
return order;
|
|
2814
2885
|
};
|
|
2815
|
-
|
|
2886
|
+
const accountPage = (rows, search, view, keep, total) => {
|
|
2887
|
+
const asked = search.has("first") ? Number(search.get("first")) : 10;
|
|
2888
|
+
if (!Number.isInteger(asked) || asked < 1 || asked > 100) throw new HttpError(400, "validation", "`first` must be an integer between 1 and 100 (a page has at most 50)", "first");
|
|
2889
|
+
const first = Math.min(asked, 50);
|
|
2890
|
+
const after = search.get("after");
|
|
2891
|
+
const before = search.get("before");
|
|
2892
|
+
if (after && before) throw new HttpError(400, "validation", "use after or before, not both", "before");
|
|
2893
|
+
const parse = (raw, field) => {
|
|
2894
|
+
let parts = [];
|
|
2895
|
+
try {
|
|
2896
|
+
parts = atob(raw.replace(/-/g, "+").replace(/_/g, "/")).split("|");
|
|
2897
|
+
} catch {
|
|
2898
|
+
}
|
|
2899
|
+
if (parts.length !== 3 || parts[0] !== "k1" || !parts[1] || !parts[2]) throw new HttpError(400, "validation", `${field} is not a valid cursor`, field);
|
|
2900
|
+
return { t: parts[1], id: parts[2] };
|
|
2901
|
+
};
|
|
2902
|
+
const enc = (k) => btoa(`k1|${k.t}|${k.id}`).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
2903
|
+
const newer = (a, b) => a.t === b.t ? a.id > b.id : a.t > b.t;
|
|
2904
|
+
const sorted = rows.slice().sort((a, b) => newer(a.key, b.key) ? -1 : newer(b.key, a.key) ? 1 : 0);
|
|
2905
|
+
const kept = keep ? sorted.filter((r) => keep(r.order)).map((r) => ({ r })) : sorted.map((r) => ({ r }));
|
|
2906
|
+
let slice;
|
|
2907
|
+
let more;
|
|
2908
|
+
if (before) {
|
|
2909
|
+
const c = parse(before, "before");
|
|
2910
|
+
const prior = kept.filter((x) => newer(x.r.key, c));
|
|
2911
|
+
slice = prior.slice(Math.max(0, prior.length - first));
|
|
2912
|
+
more = prior.length > first;
|
|
2913
|
+
} else {
|
|
2914
|
+
const c = after ? parse(after, "after") : null;
|
|
2915
|
+
const rest = c ? kept.filter((x) => newer(c, x.r.key)) : kept;
|
|
2916
|
+
slice = rest.slice(0, first);
|
|
2917
|
+
more = rest.length > first;
|
|
2918
|
+
}
|
|
2919
|
+
const nodes = slice.map((x) => view(x.r.order));
|
|
2920
|
+
const startKey = slice[0]?.r.key;
|
|
2921
|
+
const endKey = slice[slice.length - 1]?.r.key;
|
|
2922
|
+
const page_info = before ? { has_next_page: true, has_previous_page: more, start_cursor: startKey ? enc(startKey) : null, end_cursor: endKey ? enc(endKey) : null } : { has_next_page: more, has_previous_page: !!after, start_cursor: startKey ? enc(startKey) : null, end_cursor: endKey ? enc(endKey) : null };
|
|
2923
|
+
return { nodes, page_info, ...total ? { total_count: total(kept.length) } : {} };
|
|
2924
|
+
};
|
|
2925
|
+
const dayBounds = (search) => {
|
|
2926
|
+
const bound = (k, end) => {
|
|
2927
|
+
const v = search.get(k);
|
|
2928
|
+
if (!v) return null;
|
|
2929
|
+
const day = /^\d{4}-\d{2}-\d{2}$/.test(v);
|
|
2930
|
+
const t = Date.parse(day ? `${v}T00:00:00.000Z` : v);
|
|
2931
|
+
if (Number.isNaN(t)) throw new HttpError(400, "validation", `${k} must be a date (YYYY-MM-DD) or an RFC 3339 time`, k);
|
|
2932
|
+
return day && end ? t + 864e5 : t;
|
|
2933
|
+
};
|
|
2934
|
+
return { from: bound("from", false), to: bound("to", true) };
|
|
2935
|
+
};
|
|
2936
|
+
const ownRows = (headers, search) => {
|
|
2816
2937
|
const c = requireCustomer(headers);
|
|
2817
|
-
const
|
|
2818
|
-
|
|
2938
|
+
const { from, to } = dayBounds(search);
|
|
2939
|
+
const q = (search.get("q") ?? "").trim().replace(/^#/, "").toLowerCase();
|
|
2940
|
+
return state.orders.filter((o) => o.customer_id === c.id).filter((o) => (from === null || Date.parse(o.created_at) >= from) && (to === null || Date.parse(o.created_at) < to)).filter((o) => !q || o.number.toLowerCase() === q).map((o) => ({ order: o, key: { t: o.created_at, id: o.id } }));
|
|
2941
|
+
};
|
|
2942
|
+
const hasInvoice = (o) => (o.invoices ?? []).length > 0 || ["issuing", "queued", "requested", "issued", "needs_data", "needs_review"].includes(orderInvoice(o).stage ?? "");
|
|
2943
|
+
route("GET", "/customer/orders", "orders:read", ({ headers, search }) => {
|
|
2944
|
+
const status = search.get("status");
|
|
2945
|
+
const delivery = search.get("delivery_method");
|
|
2946
|
+
const wantInvoice = search.get("has_invoice");
|
|
2947
|
+
if (delivery && delivery !== "shipping" && delivery !== "pickup") throw new HttpError(400, "validation", "delivery_method must be pickup or shipping", "delivery_method");
|
|
2948
|
+
if (wantInvoice && wantInvoice !== "true" && wantInvoice !== "false") throw new HttpError(400, "validation", "has_invoice must be true or false", "has_invoice");
|
|
2949
|
+
const rows = ownRows(headers, search);
|
|
2950
|
+
const filtered = !!(status || delivery || wantInvoice || search.get("q"));
|
|
2951
|
+
const body = accountPage(
|
|
2952
|
+
rows,
|
|
2953
|
+
search,
|
|
2954
|
+
(o) => orderView(o, false),
|
|
2955
|
+
filtered ? (o) => {
|
|
2956
|
+
const view = orderView(o, false);
|
|
2957
|
+
if (status && view.status !== status && view.progress?.stage !== status) return false;
|
|
2958
|
+
if (delivery && o.delivery_method !== delivery) return false;
|
|
2959
|
+
if (wantInvoice && hasInvoice(o) !== (wantInvoice === "true")) return false;
|
|
2960
|
+
return true;
|
|
2961
|
+
} : null,
|
|
2962
|
+
filtered ? null : (n) => n
|
|
2963
|
+
);
|
|
2964
|
+
return { body, cache: "private" };
|
|
2965
|
+
});
|
|
2966
|
+
route("GET", "/customer/invoices", "orders:read", ({ headers, search }) => {
|
|
2967
|
+
const status = search.get("status");
|
|
2968
|
+
return {
|
|
2969
|
+
body: accountPage(
|
|
2970
|
+
ownRows(headers, search),
|
|
2971
|
+
search,
|
|
2972
|
+
(o) => ({ order: { id: o.id, number: o.number, created_at: o.created_at }, invoices: (o.invoices ?? []).filter((d) => !status || d.status === status) }),
|
|
2973
|
+
(o) => (o.invoices ?? []).some((d) => !status || d.status === status),
|
|
2974
|
+
null
|
|
2975
|
+
),
|
|
2976
|
+
cache: "private"
|
|
2977
|
+
};
|
|
2978
|
+
});
|
|
2979
|
+
route("GET", "/customer/shipments", "orders:read", ({ headers, search }) => {
|
|
2980
|
+
const status = search.get("status");
|
|
2981
|
+
return {
|
|
2982
|
+
body: accountPage(
|
|
2983
|
+
ownRows(headers, search),
|
|
2984
|
+
search,
|
|
2985
|
+
(o) => {
|
|
2986
|
+
const v = orderView(o, true);
|
|
2987
|
+
const shipments = (v.shipments ?? []).map((s) => ({ ...s, events: [], map: null }));
|
|
2988
|
+
return { order: { id: o.id, number: o.number, created_at: o.created_at }, stage: v.progress?.stage ?? o.status, service: v.shipping_service ?? null, shipments };
|
|
2989
|
+
},
|
|
2990
|
+
(o) => {
|
|
2991
|
+
if (o.delivery_method === "pickup" || ["cancelled", "refunded", "pending_payment"].includes(o.status)) return false;
|
|
2992
|
+
const v = orderView(o, true);
|
|
2993
|
+
const shipments = v.shipments ?? [];
|
|
2994
|
+
if (!v.shipping_service && shipments.length === 0) return false;
|
|
2995
|
+
return !status || shipments.some((s) => s.status === status);
|
|
2996
|
+
},
|
|
2997
|
+
null
|
|
2998
|
+
),
|
|
2999
|
+
cache: "private"
|
|
3000
|
+
};
|
|
2819
3001
|
});
|
|
2820
3002
|
const findOrder = (headers, id) => {
|
|
2821
3003
|
const c = requireCustomer(headers);
|