@asteby/storefront 0.23.0 → 0.25.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-BdKj3jWb.d.cts → account-settings-DOAM5mTk.d.cts} +42 -1
- package/dist/{account-settings-DHg2RUOH.d.ts → account-settings-mTEXvtfz.d.ts} +42 -1
- 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 +205 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +154 -4
- package/dist/index.d.ts +154 -4
- package/dist/index.js +193 -2
- 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 +186 -4
- 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/mock.cjs
CHANGED
|
@@ -381,6 +381,76 @@ function buildPendingPayments(currency, nowMs) {
|
|
|
381
381
|
}
|
|
382
382
|
];
|
|
383
383
|
}
|
|
384
|
+
function buildSyntheticOrders(count, currency) {
|
|
385
|
+
const out = [];
|
|
386
|
+
const base = Date.parse("2026-08-01T12:00:00.000Z");
|
|
387
|
+
for (let i = 1; i <= count; i++) {
|
|
388
|
+
const kind = i % 6;
|
|
389
|
+
const status = kind === 0 ? "cancelled" : kind === 1 ? "pending_payment" : kind === 2 ? "fulfilling" : kind === 3 ? "shipped" : "delivered";
|
|
390
|
+
const pickup = i % 5 === 0;
|
|
391
|
+
const number = `S${String(i).padStart(4, "0")}`;
|
|
392
|
+
const total = 1e4 + i * 7919 % 9e4;
|
|
393
|
+
const o = {
|
|
394
|
+
id: `ord_syn_${i}`,
|
|
395
|
+
number,
|
|
396
|
+
status,
|
|
397
|
+
created_at: new Date(base - i * 36e5).toISOString(),
|
|
398
|
+
total: money(total, currency),
|
|
399
|
+
customer_id: "cus_1",
|
|
400
|
+
lines: [line(`Producto ${i}`, null, 1 + i % 3, Math.round(total / (1 + i % 3)), currency)],
|
|
401
|
+
delivery_method: pickup ? "pickup" : "shipping",
|
|
402
|
+
payment_status: status === "pending_payment" ? "pending" : status === "cancelled" ? "cancelled" : "paid",
|
|
403
|
+
shipping_address: address
|
|
404
|
+
};
|
|
405
|
+
if (!pickup && (status === "shipped" || status === "delivered")) {
|
|
406
|
+
o.shipments = [
|
|
407
|
+
{
|
|
408
|
+
id: `shp_syn_${i}`,
|
|
409
|
+
number: `ENV-S${i}`,
|
|
410
|
+
kind: "outbound",
|
|
411
|
+
status: status === "delivered" ? "delivered" : "in_transit",
|
|
412
|
+
environment: "production",
|
|
413
|
+
test_mode: false,
|
|
414
|
+
carrier: i % 2 ? "Estafeta" : "DHL",
|
|
415
|
+
carrier_logo_key: i % 2 ? "estafeta" : "dhl",
|
|
416
|
+
service: "Terrestre",
|
|
417
|
+
tracking_number: `SYN${String(i).padStart(8, "0")}`,
|
|
418
|
+
tracking_url: `https://rastreo.example.com/syn/${i}`,
|
|
419
|
+
shipped_at: new Date(base - i * 36e5 + 72e5).toISOString(),
|
|
420
|
+
delivered_at: status === "delivered" ? new Date(base - i * 36e5 + 864e5).toISOString() : null,
|
|
421
|
+
promised_by: null,
|
|
422
|
+
label_url: null,
|
|
423
|
+
events: [],
|
|
424
|
+
map: null
|
|
425
|
+
}
|
|
426
|
+
];
|
|
427
|
+
} else if (!pickup && status === "fulfilling") {
|
|
428
|
+
o.shipping_service = { title: "Env\xEDo Estafeta", carrier: "estafeta", carrier_logo_key: "estafeta", eta_days_min: 1, eta_days_max: 3 };
|
|
429
|
+
o.shipments = [];
|
|
430
|
+
}
|
|
431
|
+
if (status === "delivered" && i % 3 === 1) {
|
|
432
|
+
o.invoices = [
|
|
433
|
+
{
|
|
434
|
+
id: `inv_syn_${i}`,
|
|
435
|
+
status: "issued",
|
|
436
|
+
kind: "invoice",
|
|
437
|
+
stage: "issued",
|
|
438
|
+
action: "download",
|
|
439
|
+
can_request: false,
|
|
440
|
+
folio: `SYN-${String(i).padStart(8, "0")}`,
|
|
441
|
+
series: "A",
|
|
442
|
+
folio_number: String(2e3 + i),
|
|
443
|
+
total: money(total, currency),
|
|
444
|
+
issued_at: new Date(base - i * 36e5 + 36e5).toISOString(),
|
|
445
|
+
test_mode: false,
|
|
446
|
+
environment: "production"
|
|
447
|
+
}
|
|
448
|
+
];
|
|
449
|
+
}
|
|
450
|
+
out.push(o);
|
|
451
|
+
}
|
|
452
|
+
return out;
|
|
453
|
+
}
|
|
384
454
|
|
|
385
455
|
// src/mock/region-mx.seed.ts
|
|
386
456
|
var SEED_MX_CSF = {
|
|
@@ -1965,7 +2035,8 @@ function createMockStorefront(options = {}) {
|
|
|
1965
2035
|
{ title: "Playera b\xE1sica", variant_title: "M / Blanco", sku: null, quantity: 1, unit: fromCents(24900, currency), total: fromCents(24900, currency), image: null }
|
|
1966
2036
|
]
|
|
1967
2037
|
},
|
|
1968
|
-
...buildAccountOrders(currency)
|
|
2038
|
+
...buildAccountOrders(currency),
|
|
2039
|
+
...buildSyntheticOrders(options.syntheticOrders ?? 0, currency)
|
|
1969
2040
|
],
|
|
1970
2041
|
pendingPayments: buildPendingPayments(currency, Date.now()),
|
|
1971
2042
|
otps: /* @__PURE__ */ new Map(),
|
|
@@ -3089,10 +3160,121 @@ function createMockStorefront(options = {}) {
|
|
|
3089
3160
|
}
|
|
3090
3161
|
return order;
|
|
3091
3162
|
};
|
|
3092
|
-
|
|
3163
|
+
const accountPage = (rows, search, view, keep, total) => {
|
|
3164
|
+
const asked = search.has("first") ? Number(search.get("first")) : 10;
|
|
3165
|
+
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");
|
|
3166
|
+
const first = Math.min(asked, 50);
|
|
3167
|
+
const after = search.get("after");
|
|
3168
|
+
const before = search.get("before");
|
|
3169
|
+
if (after && before) throw new HttpError(400, "validation", "use after or before, not both", "before");
|
|
3170
|
+
const parse = (raw, field) => {
|
|
3171
|
+
let parts = [];
|
|
3172
|
+
try {
|
|
3173
|
+
parts = atob(raw.replace(/-/g, "+").replace(/_/g, "/")).split("|");
|
|
3174
|
+
} catch {
|
|
3175
|
+
}
|
|
3176
|
+
if (parts.length !== 3 || parts[0] !== "k1" || !parts[1] || !parts[2]) throw new HttpError(400, "validation", `${field} is not a valid cursor`, field);
|
|
3177
|
+
return { t: parts[1], id: parts[2] };
|
|
3178
|
+
};
|
|
3179
|
+
const enc = (k) => btoa(`k1|${k.t}|${k.id}`).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
3180
|
+
const newer = (a, b) => a.t === b.t ? a.id > b.id : a.t > b.t;
|
|
3181
|
+
const sorted = rows.slice().sort((a, b) => newer(a.key, b.key) ? -1 : newer(b.key, a.key) ? 1 : 0);
|
|
3182
|
+
const kept = keep ? sorted.filter((r) => keep(r.order)).map((r) => ({ r })) : sorted.map((r) => ({ r }));
|
|
3183
|
+
let slice;
|
|
3184
|
+
let more;
|
|
3185
|
+
if (before) {
|
|
3186
|
+
const c = parse(before, "before");
|
|
3187
|
+
const prior = kept.filter((x) => newer(x.r.key, c));
|
|
3188
|
+
slice = prior.slice(Math.max(0, prior.length - first));
|
|
3189
|
+
more = prior.length > first;
|
|
3190
|
+
} else {
|
|
3191
|
+
const c = after ? parse(after, "after") : null;
|
|
3192
|
+
const rest = c ? kept.filter((x) => newer(c, x.r.key)) : kept;
|
|
3193
|
+
slice = rest.slice(0, first);
|
|
3194
|
+
more = rest.length > first;
|
|
3195
|
+
}
|
|
3196
|
+
const nodes = slice.map((x) => view(x.r.order));
|
|
3197
|
+
const startKey = slice[0]?.r.key;
|
|
3198
|
+
const endKey = slice[slice.length - 1]?.r.key;
|
|
3199
|
+
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 };
|
|
3200
|
+
return { nodes, page_info, ...total ? { total_count: total(kept.length) } : {} };
|
|
3201
|
+
};
|
|
3202
|
+
const dayBounds = (search) => {
|
|
3203
|
+
const bound = (k, end) => {
|
|
3204
|
+
const v = search.get(k);
|
|
3205
|
+
if (!v) return null;
|
|
3206
|
+
const day = /^\d{4}-\d{2}-\d{2}$/.test(v);
|
|
3207
|
+
const t = Date.parse(day ? `${v}T00:00:00.000Z` : v);
|
|
3208
|
+
if (Number.isNaN(t)) throw new HttpError(400, "validation", `${k} must be a date (YYYY-MM-DD) or an RFC 3339 time`, k);
|
|
3209
|
+
return day && end ? t + 864e5 : t;
|
|
3210
|
+
};
|
|
3211
|
+
return { from: bound("from", false), to: bound("to", true) };
|
|
3212
|
+
};
|
|
3213
|
+
const ownRows = (headers, search) => {
|
|
3093
3214
|
const c = requireCustomer(headers);
|
|
3094
|
-
const
|
|
3095
|
-
|
|
3215
|
+
const { from, to } = dayBounds(search);
|
|
3216
|
+
const q = (search.get("q") ?? "").trim().replace(/^#/, "").toLowerCase();
|
|
3217
|
+
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 } }));
|
|
3218
|
+
};
|
|
3219
|
+
const hasInvoice = (o) => (o.invoices ?? []).length > 0 || ["issuing", "queued", "requested", "issued", "needs_data", "needs_review"].includes(orderInvoice(o).stage ?? "");
|
|
3220
|
+
route("GET", "/customer/orders", "orders:read", ({ headers, search }) => {
|
|
3221
|
+
const status = search.get("status");
|
|
3222
|
+
const delivery = search.get("delivery_method");
|
|
3223
|
+
const wantInvoice = search.get("has_invoice");
|
|
3224
|
+
if (delivery && delivery !== "shipping" && delivery !== "pickup") throw new HttpError(400, "validation", "delivery_method must be pickup or shipping", "delivery_method");
|
|
3225
|
+
if (wantInvoice && wantInvoice !== "true" && wantInvoice !== "false") throw new HttpError(400, "validation", "has_invoice must be true or false", "has_invoice");
|
|
3226
|
+
const rows = ownRows(headers, search);
|
|
3227
|
+
const filtered = !!(status || delivery || wantInvoice || search.get("q"));
|
|
3228
|
+
const body = accountPage(
|
|
3229
|
+
rows,
|
|
3230
|
+
search,
|
|
3231
|
+
(o) => orderView(o, false),
|
|
3232
|
+
filtered ? (o) => {
|
|
3233
|
+
const view = orderView(o, false);
|
|
3234
|
+
if (status && view.status !== status && view.progress?.stage !== status) return false;
|
|
3235
|
+
if (delivery && o.delivery_method !== delivery) return false;
|
|
3236
|
+
if (wantInvoice && hasInvoice(o) !== (wantInvoice === "true")) return false;
|
|
3237
|
+
return true;
|
|
3238
|
+
} : null,
|
|
3239
|
+
filtered ? null : (n) => n
|
|
3240
|
+
);
|
|
3241
|
+
return { body, cache: "private" };
|
|
3242
|
+
});
|
|
3243
|
+
route("GET", "/customer/invoices", "orders:read", ({ headers, search }) => {
|
|
3244
|
+
const status = search.get("status");
|
|
3245
|
+
return {
|
|
3246
|
+
body: accountPage(
|
|
3247
|
+
ownRows(headers, search),
|
|
3248
|
+
search,
|
|
3249
|
+
(o) => ({ order: { id: o.id, number: o.number, created_at: o.created_at }, invoices: (o.invoices ?? []).filter((d) => !status || d.status === status) }),
|
|
3250
|
+
(o) => (o.invoices ?? []).some((d) => !status || d.status === status),
|
|
3251
|
+
null
|
|
3252
|
+
),
|
|
3253
|
+
cache: "private"
|
|
3254
|
+
};
|
|
3255
|
+
});
|
|
3256
|
+
route("GET", "/customer/shipments", "orders:read", ({ headers, search }) => {
|
|
3257
|
+
const status = search.get("status");
|
|
3258
|
+
return {
|
|
3259
|
+
body: accountPage(
|
|
3260
|
+
ownRows(headers, search),
|
|
3261
|
+
search,
|
|
3262
|
+
(o) => {
|
|
3263
|
+
const v = orderView(o, true);
|
|
3264
|
+
const shipments = (v.shipments ?? []).map((s) => ({ ...s, events: [], map: null }));
|
|
3265
|
+
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 };
|
|
3266
|
+
},
|
|
3267
|
+
(o) => {
|
|
3268
|
+
if (o.delivery_method === "pickup" || ["cancelled", "refunded", "pending_payment"].includes(o.status)) return false;
|
|
3269
|
+
const v = orderView(o, true);
|
|
3270
|
+
const shipments = v.shipments ?? [];
|
|
3271
|
+
if (!v.shipping_service && shipments.length === 0) return false;
|
|
3272
|
+
return !status || shipments.some((s) => s.status === status);
|
|
3273
|
+
},
|
|
3274
|
+
null
|
|
3275
|
+
),
|
|
3276
|
+
cache: "private"
|
|
3277
|
+
};
|
|
3096
3278
|
});
|
|
3097
3279
|
const findOrder = (headers, id) => {
|
|
3098
3280
|
const c = requireCustomer(headers);
|