@thorprovider/storefront 0.6.3 → 0.9.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.
- package/README.md +22 -2
- package/assets/templates/AGENTS.md +14 -2
- package/assets/templates/app/app/[[...slug]]/page.tsx +9 -2
- package/assets/templates/app/lib/__STOREFRONT__/account-address.ts +129 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-lifecycle.client.tsx +2 -2
- package/assets/templates/app/lib/__STOREFRONT__/account-private.core.ts +143 -0
- package/assets/templates/app/lib/__STOREFRONT__/account-profile.ts +220 -0
- package/assets/templates/app/lib/__STOREFRONT__/actions.ts +1234 -75
- package/assets/templates/app/lib/__STOREFRONT__/addresses-port.ts +107 -0
- package/assets/templates/app/lib/__STOREFRONT__/checkout-shipping.core.ts +37 -0
- package/assets/templates/app/lib/__STOREFRONT__/commerce.ts +460 -35
- package/assets/templates/app/lib/__STOREFRONT__/confirmation.core.ts +240 -0
- package/assets/templates/app/lib/__STOREFRONT__/customer-profile-port.ts +103 -0
- package/assets/templates/app/lib/__STOREFRONT__/order-detail-port.ts +26 -0
- package/assets/templates/app/lib/__STOREFRONT__/orders-port.ts +30 -0
- package/assets/templates/app/lib/__STOREFRONT__/ports.ts +18 -0
- package/assets/templates/app/lib/__STOREFRONT__/projection-ownership.client.tsx +4 -4
- package/assets/templates/app/lib/__STOREFRONT__/session.ts +24 -6
- package/assets/templates/app/lib/__STOREFRONT__/state.core.ts +28 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/address-book-advanced.client.tsx +29 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/checkout-commerce-v1.client.tsx +19 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/checkout-commerce-v1.tsx +16 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/customer-profile.client.tsx +27 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/index.ts +5 -1
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/marketplace-product-card.client.tsx +19 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/marketplace-product-card.tsx +16 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/mega-menu-universal.client.tsx +19 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/mega-menu-universal.tsx +16 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.address-book-advanced.ts +437 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.checkout-commerce-v1.ts +398 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.customer-profile.ts +138 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.marketplace-product-card.ts +67 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.mega-menu-universal.ts +76 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/schema.universal-banner.ts +217 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/universal-banner.client.tsx +24 -0
- package/assets/templates/app/lib/__STOREFRONT__/views/sections/universal-banner.tsx +16 -0
- package/assets/templates/features/checkout/handlers.ts +348 -33
- package/assets/templates/features/checkout/state.ts +79 -3
- package/assets/templates/features/customer-addresses/handlers.ts +11 -0
- package/assets/templates/features/customer-addresses/state.ts +33 -0
- package/assets/templates/features/customer-auth/state.ts +10 -0
- package/assets/templates/features/customer-profile/handlers.ts +11 -0
- package/assets/templates/features/customer-profile/state.ts +18 -0
- package/assets/templates/views/account/address-book-advanced.defaults.ts +534 -0
- package/assets/templates/views/account/assembly/assembly.json +41 -0
- package/assets/templates/views/account/assembly/index.skeleton.tsx +229 -0
- package/assets/templates/views/account/assembly/registry.skeleton.tsx +1116 -0
- package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/binding.json +5 -0
- package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/catalog.part +4 -0
- package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/element.part +5 -0
- package/assets/templates/views/account/assembly/slots/addresses/AddressBookAdvanced/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/addresses/cards/catalog.part +5 -0
- package/assets/templates/views/account/assembly/slots/addresses/cards/element.part +10 -0
- package/assets/templates/views/account/assembly/slots/addresses/cards/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/boot/AccountBoot/catalog.part +5 -0
- package/assets/templates/views/account/assembly/slots/boot/AccountBoot/element.part +5 -0
- package/assets/templates/views/account/assembly/slots/boot/AccountBoot/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/login/card/catalog.part +4 -0
- package/assets/templates/views/account/assembly/slots/login/card/element.part +13 -0
- package/assets/templates/views/account/assembly/slots/login/card/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/orders/OrderHistory/catalog.part +5 -0
- package/assets/templates/views/account/assembly/slots/orders/OrderHistory/element.part +5 -0
- package/assets/templates/views/account/assembly/slots/orders/OrderHistory/registry.part +2 -0
- package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/binding.json +5 -0
- package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/catalog.part +5 -0
- package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/element.part +5 -0
- package/assets/templates/views/account/assembly/slots/orders/OrderHistoryAdvanced/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/binding.json +5 -0
- package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/catalog.part +4 -0
- package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/element.part +5 -0
- package/assets/templates/views/account/assembly/slots/profile/CustomerProfileAdvanced/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/profile/form/catalog.part +5 -0
- package/assets/templates/views/account/assembly/slots/profile/form/element.part +10 -0
- package/assets/templates/views/account/assembly/slots/profile/form/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/register/SignUpPage1/catalog.part +4 -0
- package/assets/templates/views/account/assembly/slots/register/SignUpPage1/element.part +13 -0
- package/assets/templates/views/account/assembly/slots/register/SignUpPage1/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/summary/stack/catalog.part +5 -0
- package/assets/templates/views/account/assembly/slots/summary/stack/element.part +5 -0
- package/assets/templates/views/account/assembly/slots/summary/stack/registry.part +1 -0
- package/assets/templates/views/account/assembly/slots/summary/tabs/catalog.part +5 -0
- package/assets/templates/views/account/assembly/slots/summary/tabs/element.part +5 -0
- package/assets/templates/views/account/assembly/slots/summary/tabs/registry.part +1 -0
- package/assets/templates/views/account/content.ts +326 -0
- package/assets/templates/views/account/customer-profile.defaults.ts +136 -0
- package/assets/templates/views/account/index.tsx +218 -35
- package/assets/templates/views/account/order-detail.client.tsx +35 -0
- package/assets/templates/views/account/order-detail.defaults.ts +457 -0
- package/assets/templates/views/account/orders-advanced.client.tsx +166 -0
- package/assets/templates/views/account/orders-advanced.defaults.ts +230 -0
- package/assets/templates/views/account/registry.tsx +944 -369
- package/assets/templates/views/account/schema.ts +50 -0
- package/assets/templates/views/account/sections-data.ts +2 -0
- package/assets/templates/views/cart/content.ts +1 -0
- package/assets/templates/views/category/assembly/index.skeleton.tsx +1 -0
- package/assets/templates/views/category/assembly/slots/filter/CategoryListing/element.part +1 -0
- package/assets/templates/views/category/content.ts +2 -0
- package/assets/templates/views/category/index.tsx +2 -0
- package/assets/templates/views/category/sections-data.ts +2 -0
- package/assets/templates/views/checkout/checkout-commerce-hosted.tsx +1089 -0
- package/assets/templates/views/checkout/content.ts +114 -2
- package/assets/templates/views/checkout/index.tsx +7 -1
- package/assets/templates/views/checkout/props.ts +70 -22
- package/assets/templates/views/checkout/registry.tsx +400 -71
- package/assets/templates/views/checkout/schema.ts +260 -9
- package/assets/templates/views/home/assembly/assembly.json +28 -0
- package/assets/templates/views/home/assembly/index.skeleton.tsx +1 -0
- package/assets/templates/views/home/content.ts +2 -0
- package/assets/templates/views/home/index.tsx +1 -0
- package/assets/templates/views/home/sections-data.ts +2 -0
- package/assets/templates/views/product/content.ts +1 -0
- package/assets/templates/views/static/content.ts +1 -0
- package/bin/storefront.js +343 -13
- package/package.json +2 -1
- package/recipes/adapter-surface.json +158 -0
- package/recipes/archetypes.json +38 -3
- package/recipes/catalog.json +138 -1
- package/recipes/feature.schema.json +9 -0
- package/recipes/features.json +72 -1
- package/recipes/manifest.schema.json +5 -0
- package/recipes/recipe.schema.json +14 -2
- package/recipes/recipes.json +35 -5
- package/recipes/section.schema.json +112 -0
- package/recipes/sections.json +289 -3
- package/recipes/validate.mjs +83 -1
- package/scripts/adapter-surface.mjs +41 -0
- package/scripts/agent-blocks.mjs +700 -0
- package/scripts/block-validator.mjs +45 -0
- package/scripts/candidate.mjs +5 -4
- package/scripts/composers.mjs +7 -2
- package/scripts/default-sections.mjs +78 -0
- package/scripts/file-classes.mjs +15 -0
- package/scripts/generate-adapter-surface.mjs +148 -0
- package/scripts/operations.mjs +100 -0
- package/scripts/reconcile.mjs +67 -39
- package/scripts/section-configure.mjs +316 -0
- package/scripts/sync-assets.mjs +1 -0
- package/scripts/view-assembly.mjs +101 -14
- package/skills/sf-feature/SKILL.md +19 -0
- package/skills/sf-view-gen/SKILL.md +79 -7
- package/skills/sf-view-gen/assets/recipes/archetypes.json +38 -3
- package/skills/sf-view-gen/assets/recipes/catalog.json +138 -1
- package/skills/sf-view-gen/assets/recipes/features.json +72 -1
- package/skills/sf-view-gen/assets/recipes/recipes.json +35 -5
- package/skills/sf-view-gen/assets/recipes/section.schema.json +112 -0
- package/skills/sf-view-gen/assets/recipes/sections.json +289 -3
- package/skills/sf-view-gen/assets/templates/views/sections/checkout-commerce-v1.client.tsx +19 -0
- package/skills/sf-view-gen/assets/templates/views/sections/checkout-commerce-v1.tsx +16 -0
- package/skills/sf-view-gen/assets/templates/views/sections/marketplace-product-card.client.tsx +19 -0
- package/skills/sf-view-gen/assets/templates/views/sections/marketplace-product-card.tsx +16 -0
- package/skills/sf-view-gen/assets/templates/views/sections/mega-menu-universal.client.tsx +19 -0
- package/skills/sf-view-gen/assets/templates/views/sections/mega-menu-universal.tsx +16 -0
- package/skills/sf-view-gen/assets/templates/views/sections/schema.checkout-commerce-v1.ts +398 -0
- package/skills/sf-view-gen/assets/templates/views/sections/schema.marketplace-product-card.ts +67 -0
- package/skills/sf-view-gen/assets/templates/views/sections/schema.mega-menu-universal.ts +76 -0
- package/skills/sf-view-gen/assets/templates/views/sections/schema.universal-banner.ts +217 -0
- package/skills/sf-view-gen/assets/templates/views/sections/universal-banner.client.tsx +24 -0
- package/skills/sf-view-gen/assets/templates/views/sections/universal-banner.tsx +16 -0
- package/skills/sf-view-gen/scripts/validate.mjs +83 -1
- package/skills/storefront-workflow/SKILL.md +5 -0
- package/skills/storefront-workflow/references/mobile-responsiveness.md +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { PortError } from '@thorprovider/blocks/ports'
|
|
2
|
+
import type {
|
|
3
|
+
AddressBookPort,
|
|
4
|
+
AddressDraft,
|
|
5
|
+
AddressListResult,
|
|
6
|
+
AddressQuery,
|
|
7
|
+
CommerceAddress,
|
|
8
|
+
} from '@thorprovider/blocks/ports'
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
findCreatedAddress,
|
|
12
|
+
toAddressInput,
|
|
13
|
+
toAddressListResult,
|
|
14
|
+
toCommerceAddress,
|
|
15
|
+
} from './account-address'
|
|
16
|
+
import {
|
|
17
|
+
createAccountAddressAction,
|
|
18
|
+
deleteAccountAddressAction,
|
|
19
|
+
loadAccountAddressesAction,
|
|
20
|
+
setDefaultAccountAddressAction,
|
|
21
|
+
updateAccountAddressAction,
|
|
22
|
+
} from './actions'
|
|
23
|
+
|
|
24
|
+
async function loadViews() {
|
|
25
|
+
const result = await loadAccountAddressesAction()
|
|
26
|
+
if (!result.ok) throw new PortError('unavailable', result.error)
|
|
27
|
+
return result.addresses
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function findAddress(id: string): Promise<CommerceAddress> {
|
|
31
|
+
const view = (await loadViews()).find((candidate) => candidate.id === id)
|
|
32
|
+
if (!view) throw new PortError('not_found', 'The saved address no longer exists.')
|
|
33
|
+
return toCommerceAddress(view)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Defaults are a second backend call. A failure there must not fail the save
|
|
38
|
+
* that already succeeded (a retry would create a duplicate), so the returned
|
|
39
|
+
* address reflects the backend's actual default state.
|
|
40
|
+
*/
|
|
41
|
+
async function applyDefaults(id: string, draft: AddressDraft): Promise<void> {
|
|
42
|
+
if (draft.defaults.shipping) {
|
|
43
|
+
await setDefaultAccountAddressAction({ id, kind: 'shipping' })
|
|
44
|
+
}
|
|
45
|
+
if (draft.defaults.billing) {
|
|
46
|
+
await setDefaultAccountAddressAction({ id, kind: 'billing' })
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Host seam for the address-book surface. Every read and mutation goes through
|
|
52
|
+
* the existing account address actions; the block keeps its own scopes, drafts,
|
|
53
|
+
* defaults and validation states. The backend exposes personal addresses only,
|
|
54
|
+
* so company/company-location scopes return an empty list.
|
|
55
|
+
*/
|
|
56
|
+
export function createAddressesPort(): AddressBookPort {
|
|
57
|
+
return {
|
|
58
|
+
async list(context, query?: AddressQuery): Promise<AddressListResult> {
|
|
59
|
+
if (context.scope !== 'customer') {
|
|
60
|
+
return {
|
|
61
|
+
items: [],
|
|
62
|
+
total: 0,
|
|
63
|
+
page: query?.page ?? 1,
|
|
64
|
+
pageSize: query?.pageSize ?? 10,
|
|
65
|
+
hasMore: false,
|
|
66
|
+
permissions: {
|
|
67
|
+
view: true,
|
|
68
|
+
create: false,
|
|
69
|
+
edit: false,
|
|
70
|
+
delete: false,
|
|
71
|
+
setDefault: false,
|
|
72
|
+
useInCheckout: false,
|
|
73
|
+
},
|
|
74
|
+
serverQuery: false,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return toAddressListResult(await loadViews(), query)
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
async create(_context, draft) {
|
|
81
|
+
const result = await createAccountAddressAction(toAddressInput(draft))
|
|
82
|
+
if (!result.ok) throw new PortError('validation', result.error)
|
|
83
|
+
const created = findCreatedAddress(result.addresses, draft)
|
|
84
|
+
if (!created) throw new PortError('unavailable', 'The new address was not returned.')
|
|
85
|
+
await applyDefaults(created.id, draft)
|
|
86
|
+
return findAddress(created.id)
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
async update(_context, id, draft) {
|
|
90
|
+
const result = await updateAccountAddressAction({ ...toAddressInput(draft), id })
|
|
91
|
+
if (!result.ok) throw new PortError('validation', result.error)
|
|
92
|
+
await applyDefaults(id, draft)
|
|
93
|
+
return findAddress(id)
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
async delete(_context, id) {
|
|
97
|
+
const result = await deleteAccountAddressAction({ id })
|
|
98
|
+
if (!result.ok) throw new PortError('unavailable', result.error)
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
async setDefault(_context, id, kind) {
|
|
102
|
+
const result = await setDefaultAccountAddressAction({ id, kind })
|
|
103
|
+
if (!result.ok) throw new PortError('unavailable', result.error)
|
|
104
|
+
return findAddress(id)
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Generated by Thor Commerce storefront (template: assets/templates/app/lib/__STOREFRONT__/checkout-shipping.core.ts)
|
|
2
|
+
//
|
|
3
|
+
// Pure grouped-delivery host helper. No React, no Next, no I/O: the checkout
|
|
4
|
+
// handlers and their tests share exactly one selection rule, and the module
|
|
5
|
+
// stays importable from a client component.
|
|
6
|
+
//
|
|
7
|
+
// The backend owns grouping. This helper only translates the presentation
|
|
8
|
+
// groups the mapper produced plus their backend `products` identity into the
|
|
9
|
+
// selection payload the grouped apply expects; it never groups, splits, ranks,
|
|
10
|
+
// or re-prices a shipment.
|
|
11
|
+
|
|
12
|
+
import type { CheckoutShippingGroup } from '@thorprovider/blocks'
|
|
13
|
+
import type { ShippingGroupSelection } from '@thorprovider/types'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Build ONE backend selection per returned delivery group, or `null` while any
|
|
17
|
+
* group is still incomplete: an empty group list (no delivery to select), a
|
|
18
|
+
* group without options, a group without a chosen option, or a group without
|
|
19
|
+
* its backend `products` identity. Otherwise the selections keep the backend's
|
|
20
|
+
* group order and carry that group's `products` verbatim plus its chosen
|
|
21
|
+
* `option_id`.
|
|
22
|
+
*/
|
|
23
|
+
export function toShippingSelections(
|
|
24
|
+
groups: CheckoutShippingGroup[],
|
|
25
|
+
productsByGroup: Record<string, string[]>,
|
|
26
|
+
): ShippingGroupSelection[] | null {
|
|
27
|
+
if (groups.length === 0) return null
|
|
28
|
+
const selections: ShippingGroupSelection[] = []
|
|
29
|
+
for (const group of groups) {
|
|
30
|
+
const products = productsByGroup[group.id]
|
|
31
|
+
if (!Array.isArray(products) || products.length === 0) return null
|
|
32
|
+
if (group.options.length === 0) return null
|
|
33
|
+
if (!group.selectedOptionId) return null
|
|
34
|
+
selections.push({ products, option_id: group.selectedOptionId })
|
|
35
|
+
}
|
|
36
|
+
return selections
|
|
37
|
+
}
|