@asteby/storefront 0.1.0 → 0.3.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.
@@ -106,9 +106,10 @@ type ProductSort = 'relevance' | 'price_asc' | 'price_desc' | 'newest' | 'title_
106
106
  type ProductConnection = Connection<Product> & {
107
107
  facets: Facet[];
108
108
  };
109
+ /** `quantity_available` is `null` when the variant's stock is not tracked (always sellable). */
109
110
  type StockLevel = {
110
111
  sku: string;
111
- quantity_available: number;
112
+ quantity_available: number | null;
112
113
  };
113
114
  type ShopContact = {
114
115
  email: string | null;
@@ -159,6 +160,11 @@ type Address = {
159
160
  zip: string;
160
161
  country_code: string;
161
162
  phone: string | null;
163
+ /** Colonia. Sent and echoed by the cart API. */
164
+ neighborhood?: string | null;
165
+ province_code?: string | null;
166
+ /** Delivery reference ("between streets", gate code...). */
167
+ reference?: string | null;
162
168
  };
163
169
  type AddressInput = Partial<Omit<Address, 'id' | 'address1' | 'city' | 'zip' | 'country_code'>> & Pick<Address, 'address1' | 'city' | 'zip' | 'country_code'>;
164
170
  type CartLineMerchandise = ProductVariant & {
@@ -172,11 +178,14 @@ type CartLine = {
172
178
  total: Money;
173
179
  unit: Money;
174
180
  compare_at_unit: Money | null;
181
+ discount?: Money;
175
182
  };
176
183
  };
177
184
  type CartDiscountCode = {
178
185
  code: string;
179
186
  applicable: boolean;
187
+ /** Why an inapplicable code was not applied. */
188
+ reason?: string;
180
189
  };
181
190
  type CartBuyer = {
182
191
  email: string | null;
@@ -188,6 +197,12 @@ type CartDelivery = {
188
197
  method: DeliveryMethod | null;
189
198
  rate_id: string | null;
190
199
  branch_id: string | null;
200
+ /** Present when the chosen option is no longer valid (e.g. the quote expired). */
201
+ problem?: string;
202
+ /** Description of the chosen carrier rate (carrier addons only). */
203
+ title?: string | null;
204
+ carrier?: string | null;
205
+ eta?: string | null;
191
206
  };
192
207
  type CartCost = {
193
208
  subtotal: Money;
@@ -199,6 +214,9 @@ type CartCost = {
199
214
  };
200
215
  type Cart = {
201
216
  id: string;
217
+ /** `active` while it can be edited; anything else is a cart already turned into an order. */
218
+ status?: string;
219
+ currency_code?: string;
202
220
  lines: CartLine[];
203
221
  total_quantity: number;
204
222
  discount_codes: CartDiscountCode[];
@@ -206,6 +224,7 @@ type Cart = {
206
224
  shipping_address: Address | null;
207
225
  delivery: CartDelivery;
208
226
  cost: CartCost;
227
+ note?: string | null;
209
228
  updated_at: string;
210
229
  };
211
230
  type CartLineInput = {
@@ -220,19 +239,59 @@ type CartBuyerInput = {
220
239
  email?: string | null;
221
240
  phone?: string | null;
222
241
  };
242
+ /**
243
+ * A delivery rate. `id`, `title`, `cost` and `eta` are always present. The rest only
244
+ * comes from carrier addons (`commerce.shipping.rates`); `cost` already reflects a
245
+ * free-shipping code. Show it as is; never recompute.
246
+ */
223
247
  type ShippingRate = {
224
248
  id: string;
225
249
  title: string;
226
250
  cost: Money;
227
251
  eta: string | null;
252
+ /** Addon key of the rate provider. */
253
+ provider?: string;
254
+ carrier?: string | null;
255
+ service_code?: string | null;
256
+ eta_days_min?: number;
257
+ eta_days_max?: number;
258
+ /** e.g. `home`, `pickup_point`. */
259
+ delivery_type?: string | null;
260
+ pickup?: boolean;
261
+ taxes_included?: boolean | null;
262
+ /** RFC 3339: the quote is valid until then. */
263
+ expires_at?: string | null;
228
264
  };
229
265
  type PickupOption = {
230
266
  branch_id: string;
231
267
  name: string;
268
+ address?: string | null;
269
+ city?: string | null;
270
+ };
271
+ /** A rate provider that did not answer in time. */
272
+ type UnavailableRateProvider = {
273
+ provider: string;
274
+ code: string;
232
275
  };
233
276
  type DeliveryOptions = {
277
+ /** Empty until the cart has a shipping address. Cheapest first. */
234
278
  rates: ShippingRate[];
235
279
  pickup: PickupOption[];
280
+ /** `true` when some provider failed: `rates` holds only what arrived. */
281
+ partial?: boolean;
282
+ unavailable?: UnavailableRateProvider[];
283
+ };
284
+ /** One way to pay (`GET /storefront/carts/:id/payment-methods`). `key` is sent as `payment_method` at checkout. */
285
+ type PaymentMethod = {
286
+ key: string;
287
+ /** `builtin` (manual transfer/cash) or `provider` (a payment addon). */
288
+ kind: 'builtin' | 'provider';
289
+ default: boolean;
290
+ };
291
+ type PaymentMethods = {
292
+ methods: PaymentMethod[];
293
+ /** Market the request acted in; `null` when none. */
294
+ market: string | null;
236
295
  };
237
296
  type DeliveryInput = {
238
297
  method: DeliveryMethod;
@@ -240,31 +299,62 @@ type DeliveryInput = {
240
299
  branch_id?: string;
241
300
  };
242
301
  type InvoiceRequest = {
243
- rfc?: string;
302
+ requested?: boolean;
303
+ tax_id?: string;
244
304
  legal_name?: string;
245
305
  tax_regime?: string;
246
- zip?: string;
247
- cfdi_use?: string;
248
- email?: string;
306
+ /** CFDI use. */
307
+ use?: string;
308
+ postal_code?: string;
309
+ /** Spanish aliases the API also accepts. */
310
+ rfc?: string;
311
+ razon_social?: string;
312
+ regimen?: string;
313
+ uso_cfdi?: string;
314
+ cp?: string;
249
315
  [key: string]: unknown;
250
316
  };
251
317
  type CheckoutInput = {
318
+ /** `manual` or the `key` of a method from `carts.paymentMethods`. */
252
319
  payment_method: string;
253
320
  invoice?: InvoiceRequest;
321
+ /** Absolute URL; the API appends `?checkout=<id>` to it. */
254
322
  return_url: string;
323
+ note?: string;
255
324
  };
256
325
  type CheckoutPayment = {
257
326
  provider: string;
258
327
  status: string;
259
328
  redirect_url?: string | null;
260
329
  client_secret?: string | null;
330
+ /** What to do next (provider addons): `redirect`, `embed`, `voucher` or `none`. */
331
+ action_type?: string | null;
332
+ /** Isolated iframe URL of an embedded payment widget. */
333
+ embed_url?: string | null;
334
+ /** Offline instructions as data (OXXO reference, SPEI CLABE, deadline...). */
335
+ instructions_data?: Record<string, unknown>;
336
+ /** Offline payment instructions (OXXO reference, SPEI CLABE, manual transfer data) as text; `null` when none. */
337
+ instructions?: string | null;
338
+ };
339
+ type CheckoutInfo = {
340
+ /** Checkout session id; use it with `payment.instructions`. */
341
+ id: string;
342
+ /** e.g. `pending`, `paid`, `failed`, `cancelled`, `converted`. */
343
+ status: string;
344
+ external_order_id: string;
345
+ /** Amount to charge, computed by OPS (includes shipping and taxes). */
346
+ total: Money;
347
+ /** RFC 3339. Stock is held until then; `null` when nothing is held. */
348
+ stock_hold_expires_at: string | null;
261
349
  };
262
350
  type CheckoutResult = {
351
+ /** `number` is `null` until the order exists in OPS (it is created asynchronously after checkout). */
263
352
  order: {
264
353
  id: string;
265
- number: string;
354
+ number: string | null;
266
355
  };
267
356
  payment: CheckoutPayment;
357
+ checkout: CheckoutInfo;
268
358
  };
269
359
  type Customer = {
270
360
  id: string;
@@ -372,4 +462,4 @@ type StorefrontErrorBody = {
372
462
  };
373
463
  };
374
464
 
375
- export type { ShopBranch as $, Address as A, Money as B, Cart as C, DeliveryInput as D, MoneyRange as E, Facet as F, OrderLine as G, PageInfo as H, Image as I, PickupOption as J, Product as K, ProductAttributeValue as L, Menu as M, ProductCategory as N, Order as O, Page as P, ProductConnection as Q, ProductOption as R, ProductSort as S, ProductVariant as T, ReturnRequest as U, ReturnRequestInput as V, SEO as W, Section as X, SelectedOption as Y, ShippingRate as Z, Shop as _, AddressInput as a, ShopContact as a0, ShopPolicies as a1, StockLevel as a2, StorefrontErrorBody as a3, StorefrontErrorCode as a4, Theme as a5, Article as b, CartBuyer as c, CartBuyerInput as d, CartCost as e, CartDelivery as f, CartDiscountCode as g, CartLine as h, CartLineInput as i, CartLineMerchandise as j, CartLineUpdateInput as k, CheckoutInput as l, CheckoutPayment as m, CheckoutResult as n, Collection as o, Connection as p, Customer as q, CustomerIdentifier as r, CustomerSession as s, CustomerSessionInput as t, DeliveryMethod as u, DeliveryOptions as v, FacetValue as w, InvoiceRequest as x, InvoiceResult as y, MenuItem as z };
465
+ export type { SelectedOption as $, Address as A, MenuItem as B, Cart as C, DeliveryInput as D, Money as E, Facet as F, MoneyRange as G, OrderLine as H, Image as I, PageInfo as J, PaymentMethod as K, PaymentMethods as L, Menu as M, PickupOption as N, Order as O, Page as P, Product as Q, ProductAttributeValue as R, ProductCategory as S, ProductConnection as T, ProductOption as U, ProductSort as V, ProductVariant as W, ReturnRequest as X, ReturnRequestInput as Y, SEO as Z, Section as _, AddressInput as a, ShippingRate as a0, Shop as a1, ShopBranch as a2, ShopContact as a3, ShopPolicies as a4, StockLevel as a5, StorefrontErrorBody as a6, StorefrontErrorCode as a7, Theme as a8, UnavailableRateProvider as a9, Article as b, CartBuyer as c, CartBuyerInput as d, CartCost as e, CartDelivery as f, CartDiscountCode as g, CartLine as h, CartLineInput as i, CartLineMerchandise as j, CartLineUpdateInput as k, CheckoutInfo as l, CheckoutInput as m, CheckoutPayment as n, CheckoutResult as o, Collection as p, Connection as q, Customer as r, CustomerIdentifier as s, CustomerSession as t, CustomerSessionInput as u, DeliveryMethod as v, DeliveryOptions as w, FacetValue as x, InvoiceRequest as y, InvoiceResult as z };
@@ -106,9 +106,10 @@ type ProductSort = 'relevance' | 'price_asc' | 'price_desc' | 'newest' | 'title_
106
106
  type ProductConnection = Connection<Product> & {
107
107
  facets: Facet[];
108
108
  };
109
+ /** `quantity_available` is `null` when the variant's stock is not tracked (always sellable). */
109
110
  type StockLevel = {
110
111
  sku: string;
111
- quantity_available: number;
112
+ quantity_available: number | null;
112
113
  };
113
114
  type ShopContact = {
114
115
  email: string | null;
@@ -159,6 +160,11 @@ type Address = {
159
160
  zip: string;
160
161
  country_code: string;
161
162
  phone: string | null;
163
+ /** Colonia. Sent and echoed by the cart API. */
164
+ neighborhood?: string | null;
165
+ province_code?: string | null;
166
+ /** Delivery reference ("between streets", gate code...). */
167
+ reference?: string | null;
162
168
  };
163
169
  type AddressInput = Partial<Omit<Address, 'id' | 'address1' | 'city' | 'zip' | 'country_code'>> & Pick<Address, 'address1' | 'city' | 'zip' | 'country_code'>;
164
170
  type CartLineMerchandise = ProductVariant & {
@@ -172,11 +178,14 @@ type CartLine = {
172
178
  total: Money;
173
179
  unit: Money;
174
180
  compare_at_unit: Money | null;
181
+ discount?: Money;
175
182
  };
176
183
  };
177
184
  type CartDiscountCode = {
178
185
  code: string;
179
186
  applicable: boolean;
187
+ /** Why an inapplicable code was not applied. */
188
+ reason?: string;
180
189
  };
181
190
  type CartBuyer = {
182
191
  email: string | null;
@@ -188,6 +197,12 @@ type CartDelivery = {
188
197
  method: DeliveryMethod | null;
189
198
  rate_id: string | null;
190
199
  branch_id: string | null;
200
+ /** Present when the chosen option is no longer valid (e.g. the quote expired). */
201
+ problem?: string;
202
+ /** Description of the chosen carrier rate (carrier addons only). */
203
+ title?: string | null;
204
+ carrier?: string | null;
205
+ eta?: string | null;
191
206
  };
192
207
  type CartCost = {
193
208
  subtotal: Money;
@@ -199,6 +214,9 @@ type CartCost = {
199
214
  };
200
215
  type Cart = {
201
216
  id: string;
217
+ /** `active` while it can be edited; anything else is a cart already turned into an order. */
218
+ status?: string;
219
+ currency_code?: string;
202
220
  lines: CartLine[];
203
221
  total_quantity: number;
204
222
  discount_codes: CartDiscountCode[];
@@ -206,6 +224,7 @@ type Cart = {
206
224
  shipping_address: Address | null;
207
225
  delivery: CartDelivery;
208
226
  cost: CartCost;
227
+ note?: string | null;
209
228
  updated_at: string;
210
229
  };
211
230
  type CartLineInput = {
@@ -220,19 +239,59 @@ type CartBuyerInput = {
220
239
  email?: string | null;
221
240
  phone?: string | null;
222
241
  };
242
+ /**
243
+ * A delivery rate. `id`, `title`, `cost` and `eta` are always present. The rest only
244
+ * comes from carrier addons (`commerce.shipping.rates`); `cost` already reflects a
245
+ * free-shipping code. Show it as is; never recompute.
246
+ */
223
247
  type ShippingRate = {
224
248
  id: string;
225
249
  title: string;
226
250
  cost: Money;
227
251
  eta: string | null;
252
+ /** Addon key of the rate provider. */
253
+ provider?: string;
254
+ carrier?: string | null;
255
+ service_code?: string | null;
256
+ eta_days_min?: number;
257
+ eta_days_max?: number;
258
+ /** e.g. `home`, `pickup_point`. */
259
+ delivery_type?: string | null;
260
+ pickup?: boolean;
261
+ taxes_included?: boolean | null;
262
+ /** RFC 3339: the quote is valid until then. */
263
+ expires_at?: string | null;
228
264
  };
229
265
  type PickupOption = {
230
266
  branch_id: string;
231
267
  name: string;
268
+ address?: string | null;
269
+ city?: string | null;
270
+ };
271
+ /** A rate provider that did not answer in time. */
272
+ type UnavailableRateProvider = {
273
+ provider: string;
274
+ code: string;
232
275
  };
233
276
  type DeliveryOptions = {
277
+ /** Empty until the cart has a shipping address. Cheapest first. */
234
278
  rates: ShippingRate[];
235
279
  pickup: PickupOption[];
280
+ /** `true` when some provider failed: `rates` holds only what arrived. */
281
+ partial?: boolean;
282
+ unavailable?: UnavailableRateProvider[];
283
+ };
284
+ /** One way to pay (`GET /storefront/carts/:id/payment-methods`). `key` is sent as `payment_method` at checkout. */
285
+ type PaymentMethod = {
286
+ key: string;
287
+ /** `builtin` (manual transfer/cash) or `provider` (a payment addon). */
288
+ kind: 'builtin' | 'provider';
289
+ default: boolean;
290
+ };
291
+ type PaymentMethods = {
292
+ methods: PaymentMethod[];
293
+ /** Market the request acted in; `null` when none. */
294
+ market: string | null;
236
295
  };
237
296
  type DeliveryInput = {
238
297
  method: DeliveryMethod;
@@ -240,31 +299,62 @@ type DeliveryInput = {
240
299
  branch_id?: string;
241
300
  };
242
301
  type InvoiceRequest = {
243
- rfc?: string;
302
+ requested?: boolean;
303
+ tax_id?: string;
244
304
  legal_name?: string;
245
305
  tax_regime?: string;
246
- zip?: string;
247
- cfdi_use?: string;
248
- email?: string;
306
+ /** CFDI use. */
307
+ use?: string;
308
+ postal_code?: string;
309
+ /** Spanish aliases the API also accepts. */
310
+ rfc?: string;
311
+ razon_social?: string;
312
+ regimen?: string;
313
+ uso_cfdi?: string;
314
+ cp?: string;
249
315
  [key: string]: unknown;
250
316
  };
251
317
  type CheckoutInput = {
318
+ /** `manual` or the `key` of a method from `carts.paymentMethods`. */
252
319
  payment_method: string;
253
320
  invoice?: InvoiceRequest;
321
+ /** Absolute URL; the API appends `?checkout=<id>` to it. */
254
322
  return_url: string;
323
+ note?: string;
255
324
  };
256
325
  type CheckoutPayment = {
257
326
  provider: string;
258
327
  status: string;
259
328
  redirect_url?: string | null;
260
329
  client_secret?: string | null;
330
+ /** What to do next (provider addons): `redirect`, `embed`, `voucher` or `none`. */
331
+ action_type?: string | null;
332
+ /** Isolated iframe URL of an embedded payment widget. */
333
+ embed_url?: string | null;
334
+ /** Offline instructions as data (OXXO reference, SPEI CLABE, deadline...). */
335
+ instructions_data?: Record<string, unknown>;
336
+ /** Offline payment instructions (OXXO reference, SPEI CLABE, manual transfer data) as text; `null` when none. */
337
+ instructions?: string | null;
338
+ };
339
+ type CheckoutInfo = {
340
+ /** Checkout session id; use it with `payment.instructions`. */
341
+ id: string;
342
+ /** e.g. `pending`, `paid`, `failed`, `cancelled`, `converted`. */
343
+ status: string;
344
+ external_order_id: string;
345
+ /** Amount to charge, computed by OPS (includes shipping and taxes). */
346
+ total: Money;
347
+ /** RFC 3339. Stock is held until then; `null` when nothing is held. */
348
+ stock_hold_expires_at: string | null;
261
349
  };
262
350
  type CheckoutResult = {
351
+ /** `number` is `null` until the order exists in OPS (it is created asynchronously after checkout). */
263
352
  order: {
264
353
  id: string;
265
- number: string;
354
+ number: string | null;
266
355
  };
267
356
  payment: CheckoutPayment;
357
+ checkout: CheckoutInfo;
268
358
  };
269
359
  type Customer = {
270
360
  id: string;
@@ -372,4 +462,4 @@ type StorefrontErrorBody = {
372
462
  };
373
463
  };
374
464
 
375
- export type { ShopBranch as $, Address as A, Money as B, Cart as C, DeliveryInput as D, MoneyRange as E, Facet as F, OrderLine as G, PageInfo as H, Image as I, PickupOption as J, Product as K, ProductAttributeValue as L, Menu as M, ProductCategory as N, Order as O, Page as P, ProductConnection as Q, ProductOption as R, ProductSort as S, ProductVariant as T, ReturnRequest as U, ReturnRequestInput as V, SEO as W, Section as X, SelectedOption as Y, ShippingRate as Z, Shop as _, AddressInput as a, ShopContact as a0, ShopPolicies as a1, StockLevel as a2, StorefrontErrorBody as a3, StorefrontErrorCode as a4, Theme as a5, Article as b, CartBuyer as c, CartBuyerInput as d, CartCost as e, CartDelivery as f, CartDiscountCode as g, CartLine as h, CartLineInput as i, CartLineMerchandise as j, CartLineUpdateInput as k, CheckoutInput as l, CheckoutPayment as m, CheckoutResult as n, Collection as o, Connection as p, Customer as q, CustomerIdentifier as r, CustomerSession as s, CustomerSessionInput as t, DeliveryMethod as u, DeliveryOptions as v, FacetValue as w, InvoiceRequest as x, InvoiceResult as y, MenuItem as z };
465
+ export type { SelectedOption as $, Address as A, MenuItem as B, Cart as C, DeliveryInput as D, Money as E, Facet as F, MoneyRange as G, OrderLine as H, Image as I, PageInfo as J, PaymentMethod as K, PaymentMethods as L, Menu as M, PickupOption as N, Order as O, Page as P, Product as Q, ProductAttributeValue as R, ProductCategory as S, ProductConnection as T, ProductOption as U, ProductSort as V, ProductVariant as W, ReturnRequest as X, ReturnRequestInput as Y, SEO as Z, Section as _, AddressInput as a, ShippingRate as a0, Shop as a1, ShopBranch as a2, ShopContact as a3, ShopPolicies as a4, StockLevel as a5, StorefrontErrorBody as a6, StorefrontErrorCode as a7, Theme as a8, UnavailableRateProvider as a9, Article as b, CartBuyer as c, CartBuyerInput as d, CartCost as e, CartDelivery as f, CartDiscountCode as g, CartLine as h, CartLineInput as i, CartLineMerchandise as j, CartLineUpdateInput as k, CheckoutInfo as l, CheckoutInput as m, CheckoutPayment as n, CheckoutResult as o, Collection as p, Connection as q, Customer as r, CustomerIdentifier as s, CustomerSession as t, CustomerSessionInput as u, DeliveryMethod as v, DeliveryOptions as w, FacetValue as x, InvoiceRequest as y, InvoiceResult as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/storefront",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Typed client for the Storefront API v1 (catalog, cart, checkout, customer, content) using only global fetch — Node 20+, edge runtimes and browsers — plus an in-memory mock of the whole contract.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {