@pcreative/commerce-contract 1.2.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 +1 -1
- package/src/adapters/api.js +16 -1
- package/src/index.d.ts +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pcreative/commerce-contract",
|
|
3
|
-
"version": "1.
|
|
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",
|
package/src/adapters/api.js
CHANGED
|
@@ -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) => ({
|
|
@@ -367,6 +372,8 @@ export function createCommerce({
|
|
|
367
372
|
price: money(o.precio ?? 0, moneda, true),
|
|
368
373
|
priceCalculated: Boolean(o.esCalculada),
|
|
369
374
|
description: o.datos?.description ?? null,
|
|
375
|
+
deliveryTime: o.plazo ?? null,
|
|
376
|
+
pickup: Boolean(o.recogida),
|
|
370
377
|
}))
|
|
371
378
|
},
|
|
372
379
|
async listShippingGroups(cartId) {
|
|
@@ -570,7 +577,7 @@ export function createCommerce({
|
|
|
570
577
|
content,
|
|
571
578
|
async getStore() {
|
|
572
579
|
try {
|
|
573
|
-
const { tienda, legal } = await api("/tienda/tienda")
|
|
580
|
+
const { tienda, legal, precios } = await api("/tienda/tienda")
|
|
574
581
|
if (!tienda) return null
|
|
575
582
|
return {
|
|
576
583
|
name: tienda.nombre ?? null,
|
|
@@ -580,6 +587,14 @@ export function createCommerce({
|
|
|
580
587
|
email: tienda.correo ?? null,
|
|
581
588
|
phone: tienda.telefono ?? null,
|
|
582
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,
|
|
583
598
|
legal: legal ?? null,
|
|
584
599
|
}
|
|
585
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
|
|
@@ -282,6 +296,10 @@ export interface ShippingOption {
|
|
|
282
296
|
/** El backend calcula el precio al elegirla (envío por peso, por ejemplo). */
|
|
283
297
|
priceCalculated?: boolean
|
|
284
298
|
description?: string | null
|
|
299
|
+
/** Plazo de entrega tal y como lo escribió la tienda: "24-48 h". */
|
|
300
|
+
deliveryTime?: string | null
|
|
301
|
+
/** El cliente recoge el pedido: no hay porte ni reparto. */
|
|
302
|
+
pickup?: boolean
|
|
285
303
|
}
|
|
286
304
|
|
|
287
305
|
export interface PaymentMethod {
|
|
@@ -468,6 +486,12 @@ export interface CommerceClient {
|
|
|
468
486
|
|
|
469
487
|
checkout: {
|
|
470
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 }>>
|
|
471
495
|
setVatNumber?(cartId: string, vatNumber: string | null): Promise<Cart>
|
|
472
496
|
setEmail(cartId: string, email: string): Promise<Cart>
|
|
473
497
|
setAddresses(cartId: string, shipping: Address, billing?: Address): Promise<Cart>
|