apirocket 0.18.9 → 0.19.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/README.md +24 -24
- package/dist/ecommerce.js +2 -2
- package/dist/services/customer.service.d.ts +5 -2
- package/dist/types/ecommerce.type.d.ts +0 -8
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,7 +62,6 @@ type EcommerceConfig = {
|
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
### Eventos
|
|
65
|
-
- apirocket.ecommerce.customer.login
|
|
66
65
|
- apirocket.ecommerce.updateEvents
|
|
67
66
|
- apirocket.cartitem-loaded
|
|
68
67
|
|
|
@@ -86,28 +85,6 @@ document.addEventListener('apirocket.cartitem-loaded', (event: CartItemLoadedEve
|
|
|
86
85
|
```
|
|
87
86
|
|
|
88
87
|
|
|
89
|
-
### CustomerLoginEvent
|
|
90
|
-
|
|
91
|
-
Se lanza cuando un cliente inicia sesion a traves de un enlace de acceso (`#/customer-login/<hash>`),
|
|
92
|
-
una vez validado el hash y actualizado el estado del cliente.
|
|
93
|
-
|
|
94
|
-
```javascript
|
|
95
|
-
interface CustomerLoginEvent extends Event {
|
|
96
|
-
login: {
|
|
97
|
-
token?: string;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
```javascript
|
|
103
|
-
document.addEventListener('apirocket.ecommerce.customer.login', (event: CustomerLoginEvent) => {
|
|
104
|
-
const token = event.login.token;
|
|
105
|
-
|
|
106
|
-
// ...
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
|
|
111
88
|
### DebugType
|
|
112
89
|
|
|
113
90
|
```javascript
|
|
@@ -147,9 +124,10 @@ interface ReadOnly <CustomerService> {
|
|
|
147
124
|
createBillingAddress: (input: Omit <BillingAddress, 'id'>) => Promise <BillingAddress>;
|
|
148
125
|
createShippingAddress: (input: Omit <ShippingAddress, 'id'>) => Promise <ShippingAddress>;
|
|
149
126
|
deleteShippingAddress: (id: number) => Promise <boolean>;
|
|
150
|
-
login: (email: string, password: string) => customer.login (email, password): { status: number,
|
|
127
|
+
login: (email: string, password: string) => customer.login (email, password): { status: number, customer?: CustomerData };
|
|
151
128
|
logout: () => customer.logout ();
|
|
152
129
|
myAccount: () => Promise <CustomerAccount>;
|
|
130
|
+
onAuthChange: (cb: (event: CustomerAuthEvent) => void) => () => void;
|
|
153
131
|
price: (productId: number) => Promise <ProductPrice>;
|
|
154
132
|
orders: (filter: OrdersFilter = {}) => Promise <Array <Order>>;
|
|
155
133
|
order: (id: number) => Promise <Order>;
|
|
@@ -163,6 +141,28 @@ interface ReadOnly <CustomerService> {
|
|
|
163
141
|
```
|
|
164
142
|
|
|
165
143
|
|
|
144
|
+
### CustomerAuthEvent
|
|
145
|
+
|
|
146
|
+
`customer.onAuthChange (cb)` invoca `cb` cada vez que el cliente inicia sesion, la cierra o se refresca su token.
|
|
147
|
+
El refresco llega como `'login'` con el token nuevo. Al suscribirse se recibe el estado actual si ya se conoce.
|
|
148
|
+
El token solo se guarda en memoria: tras recargar la pagina no esta disponible hasta el primer refresco.
|
|
149
|
+
Devuelve la funcion para desuscribirse.
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
type CustomerAuthEvent = {
|
|
153
|
+
action: 'login' | 'logout';
|
|
154
|
+
customerRole: string;
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
const unsubscribe = ecommerce.customer.onAuthChange ((event: CustomerAuthEvent) => {
|
|
160
|
+
if (event.action === 'login') { /* event.customerRole */ }
|
|
161
|
+
else { /* logout */ }
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
|
|
166
166
|
### CustomerData
|
|
167
167
|
```javascript
|
|
168
168
|
type CustomerData = {
|