@asteby/storefront 0.14.0 → 0.16.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/dist/cli.js +19 -1
- package/dist/fiscal-document.cjs +72 -8
- package/dist/fiscal-document.cjs.map +1 -1
- package/dist/fiscal-document.d.cts +34 -4
- package/dist/fiscal-document.d.ts +34 -4
- package/dist/fiscal-document.js +71 -9
- package/dist/fiscal-document.js.map +1 -1
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/mock.cjs +121 -1
- package/dist/mock.cjs.map +1 -1
- package/dist/mock.d.cts +3 -1
- package/dist/mock.d.ts +3 -1
- package/dist/mock.js +121 -1
- 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/dist/{types-BeTemDg6.d.ts → types-DFK20t_g.d.ts} +55 -1
- package/dist/{types-BuKb-zbi.d.cts → types-TQPpYbac.d.cts} +55 -1
- package/package.json +1 -1
package/dist/mock.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a2 as IdentityRulesV1, ba as RegionFiscalId, a0 as IdentityDocumentSpec, b8 as Region, br as Shop, aX as Product, x as Collection, by as Theme, aC as Page, al as Menu, b as Article, C as Cart, A as Address, ab as InvoiceRequest, z as Customer, X as FiscalProfile, as as Order, aF as PaymentAttemptResult, aU as PendingPayment, ad as InvoiceStage, B as CustomerCapabilities, b2 as PromotionAnnouncement, bq as ShippingRate, aM as PaymentMethod } from './types-TQPpYbac.cjs';
|
|
2
2
|
import './geo.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -126,6 +126,8 @@ type MockState = {
|
|
|
126
126
|
carts: Map<string, CartRecord>;
|
|
127
127
|
customers: Customer[];
|
|
128
128
|
addresses: Map<string, Address[]>;
|
|
129
|
+
/** Saved fiscal profiles by customer id (contract 1.9). */
|
|
130
|
+
fiscalProfiles: Map<string, FiscalProfile[]>;
|
|
129
131
|
orders: (Order & {
|
|
130
132
|
customer_id: string | null;
|
|
131
133
|
})[];
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a2 as IdentityRulesV1, ba as RegionFiscalId, a0 as IdentityDocumentSpec, b8 as Region, br as Shop, aX as Product, x as Collection, by as Theme, aC as Page, al as Menu, b as Article, C as Cart, A as Address, ab as InvoiceRequest, z as Customer, X as FiscalProfile, as as Order, aF as PaymentAttemptResult, aU as PendingPayment, ad as InvoiceStage, B as CustomerCapabilities, b2 as PromotionAnnouncement, bq as ShippingRate, aM as PaymentMethod } from './types-DFK20t_g.js';
|
|
2
2
|
import './geo.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -126,6 +126,8 @@ type MockState = {
|
|
|
126
126
|
carts: Map<string, CartRecord>;
|
|
127
127
|
customers: Customer[];
|
|
128
128
|
addresses: Map<string, Address[]>;
|
|
129
|
+
/** Saved fiscal profiles by customer id (contract 1.9). */
|
|
130
|
+
fiscalProfiles: Map<string, FiscalProfile[]>;
|
|
129
131
|
orders: (Order & {
|
|
130
132
|
customer_id: string | null;
|
|
131
133
|
})[];
|
package/dist/mock.js
CHANGED
|
@@ -392,6 +392,7 @@ var SEED_MX_CSF = {
|
|
|
392
392
|
},
|
|
393
393
|
"verify_kind": "qr_validator",
|
|
394
394
|
"freshness_days": 90,
|
|
395
|
+
"image_mode": "qr_only",
|
|
395
396
|
"discard_fields": [
|
|
396
397
|
"curp",
|
|
397
398
|
"street",
|
|
@@ -635,6 +636,16 @@ var SEED_MX_INVOICE_USES = [
|
|
|
635
636
|
"624",
|
|
636
637
|
"625",
|
|
637
638
|
"626"
|
|
639
|
+
],
|
|
640
|
+
"suggested_for_regimes": [
|
|
641
|
+
"601",
|
|
642
|
+
"612",
|
|
643
|
+
"621",
|
|
644
|
+
"622",
|
|
645
|
+
"623",
|
|
646
|
+
"624",
|
|
647
|
+
"625",
|
|
648
|
+
"626"
|
|
638
649
|
]
|
|
639
650
|
},
|
|
640
651
|
{
|
|
@@ -1012,6 +1023,19 @@ var SEED_MX_INVOICE_USES = [
|
|
|
1012
1023
|
"624",
|
|
1013
1024
|
"625",
|
|
1014
1025
|
"626"
|
|
1026
|
+
],
|
|
1027
|
+
"suggested_for_regimes": [
|
|
1028
|
+
"603",
|
|
1029
|
+
"605",
|
|
1030
|
+
"606",
|
|
1031
|
+
"607",
|
|
1032
|
+
"608",
|
|
1033
|
+
"610",
|
|
1034
|
+
"611",
|
|
1035
|
+
"614",
|
|
1036
|
+
"615",
|
|
1037
|
+
"616",
|
|
1038
|
+
"620"
|
|
1015
1039
|
]
|
|
1016
1040
|
}
|
|
1017
1041
|
];
|
|
@@ -1095,7 +1119,10 @@ var MOCK_FISCAL_ID_MX = {
|
|
|
1095
1119
|
generic_ids: SEED_MX_GENERIC_IDS,
|
|
1096
1120
|
regimes: SEED_MX_REGIMES,
|
|
1097
1121
|
invoice_uses: SEED_MX_INVOICE_USES,
|
|
1098
|
-
documents: [SEED_MX_CSF]
|
|
1122
|
+
documents: [SEED_MX_CSF],
|
|
1123
|
+
// The pack's person-type patterns and check algorithm (region_settings.fiscal_id_person_patterns / _checksum).
|
|
1124
|
+
person_patterns: { individual: "^[A-Z\xD1&]{4}[0-9]{6}[A-Z0-9]{3}$", company: "^[A-Z\xD1&]{3}[0-9]{6}[A-Z0-9]{3}$" },
|
|
1125
|
+
checksum: "mx_rfc"
|
|
1099
1126
|
};
|
|
1100
1127
|
var MOCK_REGION_MX = {
|
|
1101
1128
|
country_code: "MX",
|
|
@@ -1557,6 +1584,7 @@ function createMockStorefront(options = {}) {
|
|
|
1557
1584
|
identity_documents: ["MX:csf"],
|
|
1558
1585
|
online_verify: false
|
|
1559
1586
|
},
|
|
1587
|
+
fiscal_profiles: { max: 10 },
|
|
1560
1588
|
...options.customerCapabilities
|
|
1561
1589
|
};
|
|
1562
1590
|
const missingScopes = options.missingScopes ?? [];
|
|
@@ -1587,6 +1615,7 @@ function createMockStorefront(options = {}) {
|
|
|
1587
1615
|
carts: /* @__PURE__ */ new Map(),
|
|
1588
1616
|
customers: buildCustomers(),
|
|
1589
1617
|
addresses: /* @__PURE__ */ new Map(),
|
|
1618
|
+
fiscalProfiles: /* @__PURE__ */ new Map(),
|
|
1590
1619
|
orders: [
|
|
1591
1620
|
{
|
|
1592
1621
|
id: "ord_seed_1",
|
|
@@ -2556,6 +2585,97 @@ function createMockStorefront(options = {}) {
|
|
|
2556
2585
|
};
|
|
2557
2586
|
return { body: file, headers: { "Cache-Control": "no-store" } };
|
|
2558
2587
|
});
|
|
2588
|
+
const MAX_FISCAL_PROFILES = 10;
|
|
2589
|
+
const profilesOf = (c) => state.fiscalProfiles.get(c.id) ?? [];
|
|
2590
|
+
const publicProfile = (p) => {
|
|
2591
|
+
if (!p.document) return p;
|
|
2592
|
+
const { sha256: _sha, ...document } = p.document;
|
|
2593
|
+
return { ...p, document };
|
|
2594
|
+
};
|
|
2595
|
+
const personTypeOf = (taxId) => {
|
|
2596
|
+
for (const [type, pattern] of Object.entries(region?.fiscal_id?.person_patterns ?? {})) if (new RegExp(pattern).test(taxId)) return type;
|
|
2597
|
+
return null;
|
|
2598
|
+
};
|
|
2599
|
+
const mirrorDefaultProfile = (c) => {
|
|
2600
|
+
const d = profilesOf(c).find((p) => p.is_default);
|
|
2601
|
+
c.fiscal = d ? { country_code: d.country_code, tax_id: d.tax_id, legal_name: d.legal_name, tax_regime: d.tax_regime, postal_code: d.postal_code, invoice_use: d.invoice_use ?? null, document: d.document ?? null, verification: d.verification ?? null } : null;
|
|
2602
|
+
};
|
|
2603
|
+
const profileFields = (body, base) => {
|
|
2604
|
+
const merged = {
|
|
2605
|
+
...base ? { tax_id: base.tax_id, legal_name: base.legal_name, tax_regime: base.tax_regime, postal_code: base.postal_code, country_code: base.country_code, ...base.invoice_use ? { use: base.invoice_use } : {} } : {},
|
|
2606
|
+
...body,
|
|
2607
|
+
requested: true
|
|
2608
|
+
};
|
|
2609
|
+
delete merged.label;
|
|
2610
|
+
delete merged.is_default;
|
|
2611
|
+
delete merged.verification;
|
|
2612
|
+
const fiscal = parseInvoice(merged, "fiscal");
|
|
2613
|
+
return {
|
|
2614
|
+
country_code: String(fiscal.country_code ?? region?.country_code ?? ""),
|
|
2615
|
+
tax_id: String(fiscal.tax_id ?? fiscal.rfc).toUpperCase(),
|
|
2616
|
+
legal_name: String(fiscal.legal_name ?? fiscal.razon_social),
|
|
2617
|
+
tax_regime: String(fiscal.tax_regime ?? fiscal.regimen),
|
|
2618
|
+
postal_code: String(fiscal.postal_code ?? fiscal.cp),
|
|
2619
|
+
invoice_use: String(fiscal.use ?? fiscal.uso_cfdi ?? fiscal.invoice_use ?? "") || null,
|
|
2620
|
+
document: fiscal.document ?? base?.document ?? null
|
|
2621
|
+
};
|
|
2622
|
+
};
|
|
2623
|
+
const ownProfile = (c, id) => {
|
|
2624
|
+
const p = profilesOf(c).find((x) => x.id === id);
|
|
2625
|
+
if (!p) throw new HttpError(404, "not_found", "Fiscal profile not found", "id");
|
|
2626
|
+
return p;
|
|
2627
|
+
};
|
|
2628
|
+
const makeDefault = (c, id) => state.fiscalProfiles.set(c.id, profilesOf(c).map((p) => ({ ...p, is_default: p.id === id })));
|
|
2629
|
+
route("GET", "/customer/fiscal-profiles", "customer:read", ({ headers }) => {
|
|
2630
|
+
const c = requireCustomer(headers);
|
|
2631
|
+
const nodes = [...profilesOf(c)].sort((a, b) => Number(b.is_default) - Number(a.is_default) || (b.last_used_at ?? "").localeCompare(a.last_used_at ?? ""));
|
|
2632
|
+
return { body: { nodes: nodes.map(publicProfile) }, cache: "private" };
|
|
2633
|
+
});
|
|
2634
|
+
route("POST", "/customer/fiscal-profiles", "customer:write", ({ headers, body }) => {
|
|
2635
|
+
const c = requireCustomer(headers);
|
|
2636
|
+
const list = profilesOf(c);
|
|
2637
|
+
const fid = profileFields(body);
|
|
2638
|
+
if (list.length >= MAX_FISCAL_PROFILES) throw new HttpError(409, "conflict", "Fiscal profile limit reached; delete one first");
|
|
2639
|
+
if (list.some((p) => p.country_code === fid.country_code && p.tax_id === fid.tax_id)) throw new HttpError(409, "conflict", "A profile with this tax id already exists", "tax_id");
|
|
2640
|
+
const at = now();
|
|
2641
|
+
const label = typeof body.label === "string" && body.label.trim() ? body.label.trim().slice(0, 40) : fid.legal_name.slice(0, 40);
|
|
2642
|
+
const profile = { ...fid, id: nextId("fisc"), label, person_type: personTypeOf(fid.tax_id), is_default: false, last_used_at: null, created_at: at, updated_at: at, verification: { status: "unverified", checked_at: null } };
|
|
2643
|
+
state.fiscalProfiles.set(c.id, [...list, profile]);
|
|
2644
|
+
if (list.length === 0 || body.is_default === true) makeDefault(c, profile.id);
|
|
2645
|
+
mirrorDefaultProfile(c);
|
|
2646
|
+
return { status: 201, body: publicProfile(profilesOf(c).find((p) => p.id === profile.id)), cache: "private" };
|
|
2647
|
+
});
|
|
2648
|
+
route("PATCH", "/customer/fiscal-profiles/:id", "customer:write", ({ headers, params, body }) => {
|
|
2649
|
+
const c = requireCustomer(headers);
|
|
2650
|
+
const cur = ownProfile(c, params[0]);
|
|
2651
|
+
if ("verification" in body) throw new HttpError(400, "validation", "verification is set by the server", "verification");
|
|
2652
|
+
if (body.is_default === false && cur.is_default) throw new HttpError(400, "validation", "Make another profile the default instead", "is_default");
|
|
2653
|
+
const fid = profileFields(body, cur);
|
|
2654
|
+
if (profilesOf(c).some((p) => p.id !== cur.id && p.country_code === fid.country_code && p.tax_id === fid.tax_id)) throw new HttpError(409, "conflict", "A profile with this tax id already exists", "tax_id");
|
|
2655
|
+
const identityChanged = fid.tax_id !== cur.tax_id || fid.country_code !== cur.country_code;
|
|
2656
|
+
const updated = {
|
|
2657
|
+
...cur,
|
|
2658
|
+
...fid,
|
|
2659
|
+
document: "document" in body ? fid.document : identityChanged ? null : cur.document,
|
|
2660
|
+
label: typeof body.label === "string" && body.label.trim() ? body.label.trim().slice(0, 40) : cur.label,
|
|
2661
|
+
person_type: personTypeOf(fid.tax_id),
|
|
2662
|
+
verification: identityChanged ? { status: "unverified", checked_at: null } : cur.verification,
|
|
2663
|
+
updated_at: now()
|
|
2664
|
+
};
|
|
2665
|
+
state.fiscalProfiles.set(c.id, profilesOf(c).map((p) => p.id === cur.id ? updated : p));
|
|
2666
|
+
if (body.is_default === true) makeDefault(c, cur.id);
|
|
2667
|
+
mirrorDefaultProfile(c);
|
|
2668
|
+
return { body: publicProfile(profilesOf(c).find((p) => p.id === cur.id)), cache: "private" };
|
|
2669
|
+
});
|
|
2670
|
+
route("DELETE", "/customer/fiscal-profiles/:id", "customer:write", ({ headers, params }) => {
|
|
2671
|
+
const c = requireCustomer(headers);
|
|
2672
|
+
const cur = ownProfile(c, params[0]);
|
|
2673
|
+
const rest = profilesOf(c).filter((p) => p.id !== cur.id);
|
|
2674
|
+
state.fiscalProfiles.set(c.id, rest);
|
|
2675
|
+
if (cur.is_default && rest[0]) makeDefault(c, rest[0].id);
|
|
2676
|
+
mirrorDefaultProfile(c);
|
|
2677
|
+
return { status: 204 };
|
|
2678
|
+
});
|
|
2559
2679
|
route("GET", "/customer/addresses", "customer:read", ({ headers }) => {
|
|
2560
2680
|
const c = requireCustomer(headers);
|
|
2561
2681
|
return { body: { nodes: state.addresses.get(c.id) ?? [] }, cache: "private" };
|