@pcreative/commerce-contract 1.3.0 → 1.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pcreative/commerce-contract",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Contrato de datos de commerce: los tipos que consume un tema y los adaptadores que los resuelven. Sin dependencias ni SDK del backend.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -359,6 +359,11 @@ export function createCommerce({
359
359
  })
360
360
  return mapCart(c)
361
361
  },
362
+ async listProvinces(country) {
363
+ if (!country) return []
364
+ const { provincias = [] } = await api(`/tienda/provincias?pais=${encodeURIComponent(country)}`)
365
+ return provincias.map((p) => ({ code: p.codigo, name: p.nombre }))
366
+ },
362
367
  async listShippingOptions(cartId) {
363
368
  const { moneda = "eur", opciones = [] } = await api(rutaCarrito(cartId, "/envios"))
364
369
  return opciones.map((o) => ({
@@ -572,7 +577,7 @@ export function createCommerce({
572
577
  content,
573
578
  async getStore() {
574
579
  try {
575
- const { tienda, legal } = await api("/tienda/tienda")
580
+ const { tienda, legal, precios } = await api("/tienda/tienda")
576
581
  if (!tienda) return null
577
582
  return {
578
583
  name: tienda.nombre ?? null,
@@ -582,6 +587,14 @@ export function createCommerce({
582
587
  email: tienda.correo ?? null,
583
588
  phone: tienda.telefono ?? null,
584
589
  country: tienda.pais ?? null,
590
+ priceDisplay: precios
591
+ ? {
592
+ show: precios.muestra === 'sin' ? 'without' : precios.muestra === 'ambos' ? 'both' : 'with',
593
+ storedWithTax: !!precios.guardadosConImpuesto,
594
+ defaultRate: Number(precios.tasaPorDefecto ?? 0),
595
+ country: precios.pais ?? null,
596
+ }
597
+ : null,
585
598
  legal: legal ?? null,
586
599
  }
587
600
  } catch {
package/src/index.d.ts CHANGED
@@ -244,6 +244,20 @@ export interface StoreInfo {
244
244
  email: string | null
245
245
  phone: string | null
246
246
  country?: string | null
247
+ /**
248
+ * Como quiere la tienda que se vean los precios en el escaparate.
249
+ * `show: 'with'` es lo que exige la ley europea para consumidores;
250
+ * `'without'` y `'both'` son para tiendas que venden a empresas.
251
+ * `storedWithTax` dice si el precio que llega ya lleva el impuesto dentro,
252
+ * y `defaultRate` es la tasa del pais de la tienda, para poder calcular el
253
+ * otro importe antes de que el cliente diga donde vive.
254
+ */
255
+ priceDisplay?: {
256
+ show: 'with' | 'without' | 'both'
257
+ storedWithTax: boolean
258
+ defaultRate: number
259
+ country: string | null
260
+ }
247
261
  legal?: {
248
262
  digital?: {
249
263
  pais: string
@@ -472,6 +486,12 @@ export interface CommerceClient {
472
486
 
473
487
  checkout: {
474
488
  listCountries?(): Promise<string[]>
489
+ /**
490
+ * Provincias, estados o departamentos de un pais, en el nivel que pide su
491
+ * caja (Espana pide provincia, Alemania Land, Malta nada). Lista vacia =
492
+ * ese pais no usa provincia y el tema debe dejar el campo libre.
493
+ */
494
+ listProvinces?(country: string): Promise<Array<{ code: string; name: string }>>
475
495
  setVatNumber?(cartId: string, vatNumber: string | null): Promise<Cart>
476
496
  setEmail(cartId: string, email: string): Promise<Cart>
477
497
  setAddresses(cartId: string, shipping: Address, billing?: Address): Promise<Cart>