@thorprovider/storefront 0.9.0 → 0.11.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.
Files changed (66) hide show
  1. package/README.md +8 -5
  2. package/assets/templates/app/app/globals.css +0 -1
  3. package/assets/templates/app/lib/__STOREFRONT__/account-session.core.ts +4 -2
  4. package/assets/templates/app/lib/__STOREFRONT__/account-user.core.ts +2 -1
  5. package/assets/templates/app/lib/__STOREFRONT__/actions.ts +130 -12
  6. package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +156 -9
  7. package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +38 -3
  8. package/assets/templates/app/lib/__STOREFRONT__/fulfillment-evidence-port.ts +31 -0
  9. package/assets/templates/app/lib/__STOREFRONT__/handlers.core.ts +21 -4
  10. package/assets/templates/app/lib/__STOREFRONT__/mappers.ts +6 -2
  11. package/assets/templates/app/lib/__STOREFRONT__/order-detail-aftersales.ts +55 -0
  12. package/assets/templates/app/lib/__STOREFRONT__/order-detail-capabilities.ts +79 -0
  13. package/assets/templates/app/lib/__STOREFRONT__/order-detail-mapper.ts +653 -0
  14. package/assets/templates/app/lib/__STOREFRONT__/order-detail-money.ts +39 -0
  15. package/assets/templates/app/lib/__STOREFRONT__/order-detail-port.ts +6 -7
  16. package/assets/templates/app/lib/__STOREFRONT__/order-detail-reorder.ts +62 -0
  17. package/assets/templates/app/lib/__STOREFRONT__/ports.ts +13 -3
  18. package/assets/templates/views/account/assembly/assembly.json +0 -5
  19. package/assets/templates/views/account/assembly/index.skeleton.tsx +51 -0
  20. package/assets/templates/views/account/assembly/registry.skeleton.tsx +120 -68
  21. package/assets/templates/views/account/content.ts +13 -7
  22. package/assets/templates/views/account/fulfillment-evidence.client.tsx +34 -0
  23. package/assets/templates/views/account/fulfillment-evidence.defaults.ts +145 -0
  24. package/assets/templates/views/account/fulfillment-evidence.schema.ts +15 -0
  25. package/assets/templates/views/account/index.tsx +44 -3
  26. package/assets/templates/views/account/order-detail-flows.defaults.ts +106 -0
  27. package/assets/templates/views/account/order-detail-invoice.ts +136 -0
  28. package/assets/templates/views/account/order-detail-sheet.tsx +100 -0
  29. package/assets/templates/views/account/order-detail-sheets.tsx +122 -0
  30. package/assets/templates/views/account/order-detail.client.tsx +401 -1
  31. package/assets/templates/views/account/orders-advanced.client.tsx +10 -99
  32. package/assets/templates/views/account/orders-advanced.defaults.ts +7 -7
  33. package/assets/templates/views/account/registry.tsx +120 -69
  34. package/assets/templates/views/account/schema.ts +2 -0
  35. package/assets/templates/views/home/assembly/assembly.json +1 -1
  36. package/assets/templates/views/home/assembly/index.skeleton.tsx +3 -1
  37. package/assets/templates/views/home/assembly/registry.skeleton.tsx +1 -0
  38. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/binding.json +5 -0
  39. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/catalog.part +4 -0
  40. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/element.part +4 -0
  41. package/assets/templates/views/home/assembly/slots/hero/UniversalBanner/registry.part +10 -0
  42. package/assets/templates/views/home/content.ts +248 -2
  43. package/assets/templates/views/home/data.ts +10 -1
  44. package/assets/templates/views/home/index.tsx +7 -6
  45. package/assets/templates/views/home/props.ts +7 -1
  46. package/assets/templates/views/home/registry.tsx +11 -28
  47. package/assets/templates/views/home/schema.ts +163 -0
  48. package/assets/templates/views/product/data.ts +13 -6
  49. package/assets/templates/views/product/index.tsx +3 -3
  50. package/bin/storefront.js +18 -18
  51. package/package.json +1 -1
  52. package/recipes/adapter-surface.json +1 -0
  53. package/recipes/archetypes.json +5 -1
  54. package/recipes/catalog.json +9 -1
  55. package/recipes/recipes.json +5 -4
  56. package/scripts/candidate.mjs +59 -14
  57. package/scripts/file-classes.mjs +4 -0
  58. package/scripts/mock-capabilities.mjs +22 -0
  59. package/scripts/reconcile.mjs +5 -2
  60. package/scripts/render-templates.mjs +126 -43
  61. package/skills/sf-view-gen/assets/recipes/archetypes.json +5 -1
  62. package/skills/sf-view-gen/assets/recipes/catalog.json +9 -1
  63. package/skills/sf-view-gen/assets/recipes/recipes.json +5 -4
  64. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/catalog.part +0 -5
  65. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/element.part +0 -5
  66. package/assets/templates/views/account/assembly/slots/boot/AccountBoot/registry.part +0 -1
@@ -21,11 +21,15 @@ export function toFeaturedProduct(card: CardProduct): FeaturedProduct {
21
21
  price: card.price,
22
22
  // Only a real compare-at price is forwarded: the block renders a discount
23
23
  // treatment solely from an `originalPrice > price` pair, and never from a
24
- // fabricated one. Popularity/review/stock fields are omitted — the block
25
- // renders nothing for them instead of claiming `rating: 0` or `inStock`.
24
+ // fabricated one. Popularity/review fields are omitted — the block renders
25
+ // nothing for them instead of claiming `rating: 0`. Availability is
26
+ // forwarded only from real backend evidence (`inStock` on the card): an
27
+ // explicit `false` disables the hero's purchase buttons; absence makes no
28
+ // stock claim (never invented).
26
29
  originalPrice: card.originalPrice,
27
30
  image: card.image ?? '',
28
31
  tag: card.badge,
32
+ ...(card.inStock !== undefined ? { inStock: card.inStock } : {}),
29
33
  }
30
34
  }
31
35
 
@@ -0,0 +1,55 @@
1
+ import type { AfterSalesLine } from '@thorprovider/blocks'
2
+
3
+ import { fromMinor } from './order-detail-money'
4
+ import type { OrderDetailOrder } from '@thorprovider/blocks/ports'
5
+
6
+ const DELIVERED_STATUSES = new Set(['delivered', 'partially_delivered'])
7
+ const RETURNED_STATUSES = new Set(['requested', 'approved', 'in_transit', 'received', 'completed'])
8
+
9
+ /**
10
+ * Project the order snapshot into the lines the after-sales flow may offer.
11
+ *
12
+ * `delivered` comes from the fulfilment allocations the backend reported;
13
+ * `returnable` subtracts units already in a live return case, so the flow can
14
+ * never ask for more than the shopper still holds. Rejected cases release their
15
+ * units again. Both numbers are computed here, never in the block.
16
+ */
17
+ export function toAfterSalesLines(order: OrderDetailOrder): AfterSalesLine[] {
18
+ const returned = new Map<string, number>()
19
+ for (const entry of order.cases ?? []) {
20
+ if (entry.type !== 'return' || !RETURNED_STATUSES.has(entry.status)) continue
21
+ for (const line of entry.lines) {
22
+ returned.set(line.lineId, (returned.get(line.lineId) ?? 0) + line.quantity)
23
+ }
24
+ }
25
+
26
+ const delivered = new Map<string, number>()
27
+ for (const fulfillment of order.fulfillments ?? []) {
28
+ if (!DELIVERED_STATUSES.has(fulfillment.status)) continue
29
+ for (const allocation of fulfillment.allocations) {
30
+ delivered.set(
31
+ allocation.lineId,
32
+ (delivered.get(allocation.lineId) ?? 0) + allocation.quantity,
33
+ )
34
+ }
35
+ }
36
+
37
+ return (order.lines ?? []).map((line) => {
38
+ const deliveredQuantity = delivered.get(line.id) ?? 0
39
+ const returnable = Math.max(0, deliveredQuantity - (returned.get(line.id) ?? 0))
40
+ return {
41
+ id: line.id,
42
+ name: line.name,
43
+ ...(line.sku ? { sku: line.sku } : {}),
44
+ ...(line.image ? { image: line.image } : {}),
45
+ // The block speaks the canonical decimal `Money`; the snapshot speaks
46
+ // integer minor units.
47
+ unitPrice: {
48
+ amount: fromMinor(line.unitPrice.applied.amount, line.unitPrice.applied.currency),
49
+ currencyCode: line.unitPrice.applied.currency,
50
+ },
51
+ delivered: deliveredQuantity,
52
+ returnable,
53
+ }
54
+ })
55
+ }
@@ -0,0 +1,79 @@
1
+ import type { OrderActionId, OrderDocument } from '@thorprovider/blocks/ports'
2
+
3
+ /**
4
+ * Host capability gate for the order-detail route.
5
+ *
6
+ * The delivered surface renders one control per action in `availableActions`, so
7
+ * an action that reaches the snapshot without a host handler becomes a dead
8
+ * control. This list is therefore the single source of truth for what the host
9
+ * can really serve: project actions through it, and register exactly one handler
10
+ * per entry in the route panel.
11
+ */
12
+ export const ORDER_DETAIL_HOST_ACTIONS: readonly OrderActionId[] = [
13
+ 'reorder',
14
+ 'invoice',
15
+ 'track',
16
+ 'pay-balance',
17
+ 'support',
18
+ 'return',
19
+ 'exchange',
20
+ 'problem',
21
+ 'cancel',
22
+ ]
23
+
24
+ /** Support destination declared by the store. Empty string hides the action. */
25
+ export const ORDER_DETAIL_SUPPORT_HREF = '/contact'
26
+
27
+ /**
28
+ * The actions the host can serve.
29
+ *
30
+ * An empty support destination means the store publishes no contact page, so
31
+ * `support` is dropped from the projection instead of becoming a button whose
32
+ * handler has nowhere to go.
33
+ */
34
+ export function orderDetailHostActions(
35
+ supportHref: string = ORDER_DETAIL_SUPPORT_HREF,
36
+ ): readonly OrderActionId[] {
37
+ if (supportHref !== '') return ORDER_DETAIL_HOST_ACTIONS
38
+ return ORDER_DETAIL_HOST_ACTIONS.filter((action) => action !== 'support')
39
+ }
40
+
41
+ /** Project an authorised action set through the host's real capabilities. */
42
+ export function projectHostActions(
43
+ actions: readonly OrderActionId[],
44
+ supportHref: string = ORDER_DETAIL_SUPPORT_HREF,
45
+ ): OrderActionId[] {
46
+ const served = orderDetailHostActions(supportHref)
47
+ return actions.filter((action) => served.includes(action))
48
+ }
49
+
50
+ /**
51
+ * Documents the demo storefront can actually open.
52
+ *
53
+ * Medusa issues no invoice or receipt file, so these exist only for mock orders,
54
+ * where the host renders a printable demonstration sheet from the snapshot. A
55
+ * live order keeps `documents: []`: an invented invoice on a real storefront
56
+ * would be a defect, not a placeholder.
57
+ */
58
+ export function orderDetailDemoDocuments(
59
+ order: { number: string; createdAt: string },
60
+ isMock: boolean,
61
+ ): OrderDocument[] {
62
+ if (!isMock) return []
63
+ return [
64
+ {
65
+ id: `${order.number}-invoice`,
66
+ kind: 'invoice',
67
+ label: `Factura ${order.number}`,
68
+ issuedAt: order.createdAt,
69
+ available: true,
70
+ },
71
+ {
72
+ id: `${order.number}-receipt`,
73
+ kind: 'receipt',
74
+ label: `Recibo ${order.number}`,
75
+ issuedAt: order.createdAt,
76
+ available: true,
77
+ },
78
+ ]
79
+ }