@ecomiq/storefront 2.0.19 → 2.0.21
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 +71 -5
- package/package.json +7 -2
- package/src/auth/ecomiq-oauth-password-types.ts +0 -1
- package/src/auth/storefront-auth.ts +7 -0
- package/src/cloud-runtime-client.ts +218 -0
- package/src/codegen.mjs +55 -2
- package/src/components/checkout/format.ts +1 -8
- package/src/config.d.ts +26 -1
- package/src/config.mjs +20 -1
- package/src/format-money.ts +31 -0
- package/src/index.ts +16 -1
- package/src/pages/api.$.ts +20 -0
- package/src/pages/api.auth.$.ts +16 -0
- package/src/providers/auth.tsx +20 -7
- package/src/providers/cart.tsx +2 -2
- package/src/runtime/context.ts +1 -0
- package/src/server-config-store.ts +8 -0
- package/src/server.ts +10 -2
- package/src/storefront-definition/contract.ts +1 -0
- package/src/storefront-definition/index.ts +2 -0
- package/src/storefront-definition/renderer.tsx +905 -0
- package/src/storefront-layout.ts +37 -0
- package/src/storefront-runtime.ts +277 -0
- package/src/styles.css +13 -0
- package/templates/__root.tsx +6 -4
package/src/providers/auth.tsx
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Auth storefront: Better Auth client + sesión via context.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* <AuthProvider client={client}>
|
|
7
|
-
* <App />
|
|
8
|
-
* </AuthProvider>
|
|
4
|
+
* El framework monta `<AuthProvider>` en `__root` (cliente por defecto).
|
|
5
|
+
* Puedes pasar un `client` propio si necesitas opciones custom.
|
|
9
6
|
*
|
|
7
|
+
* ```tsx
|
|
10
8
|
* const { session, signIn, signOut } = useAuth()
|
|
11
9
|
* ```
|
|
12
10
|
*/
|
|
@@ -39,14 +37,29 @@ export type StorefrontSession = StorefrontAuthClientInstance['$Infer']['Session'
|
|
|
39
37
|
|
|
40
38
|
const AuthContext = createContext<StorefrontAuthClientInstance | null>(null)
|
|
41
39
|
|
|
40
|
+
/** Cliente por defecto del framework (una instancia por bundle). */
|
|
41
|
+
let defaultAuthClient: StorefrontAuthClientInstance | null = null
|
|
42
|
+
|
|
43
|
+
function getDefaultAuthClient(): StorefrontAuthClientInstance {
|
|
44
|
+
if (!defaultAuthClient) {
|
|
45
|
+
defaultAuthClient = createStorefrontAuthClient()
|
|
46
|
+
}
|
|
47
|
+
return defaultAuthClient
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
export function AuthProvider({
|
|
43
51
|
client,
|
|
44
52
|
children,
|
|
45
53
|
}: {
|
|
46
|
-
|
|
54
|
+
/** Si se omite, usa el cliente por defecto del storefront. */
|
|
55
|
+
client?: StorefrontAuthClientInstance
|
|
47
56
|
children: ReactNode
|
|
48
57
|
}) {
|
|
49
|
-
return
|
|
58
|
+
return (
|
|
59
|
+
<AuthContext.Provider value={client ?? getDefaultAuthClient()}>
|
|
60
|
+
{children}
|
|
61
|
+
</AuthContext.Provider>
|
|
62
|
+
)
|
|
50
63
|
}
|
|
51
64
|
|
|
52
65
|
/** Acceso a sesión y acciones de auth. Requiere `<AuthProvider>` + `<AppEcomiqProvider>`. */
|
package/src/providers/cart.tsx
CHANGED
|
@@ -17,14 +17,14 @@ import {
|
|
|
17
17
|
useState,
|
|
18
18
|
type ReactNode,
|
|
19
19
|
} from 'react'
|
|
20
|
-
import { type StorefrontCart } from '@ecomiq/core'
|
|
20
|
+
import { type StorefrontCart, EntityIdSchema } from '@ecomiq/core'
|
|
21
21
|
import { z } from 'zod'
|
|
22
22
|
import { serverApi } from '../server'
|
|
23
23
|
|
|
24
24
|
const CartSessionSchema = z.object({
|
|
25
25
|
version: z.literal(1),
|
|
26
26
|
storeId: z.string().min(1),
|
|
27
|
-
cartId:
|
|
27
|
+
cartId: EntityIdSchema,
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
export type CartLoadStatus = 'loading' | 'ready' | 'error'
|
package/src/runtime/context.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { CreateApiOptions } from '@ecomiq/core'
|
|
2
2
|
import { createServerOnlyFn } from '@tanstack/react-start'
|
|
3
3
|
|
|
4
|
+
export interface ServerEcomiqCloudConfig {
|
|
5
|
+
baseUrl?: string
|
|
6
|
+
storeSlug?: string
|
|
7
|
+
timeoutMs?: number
|
|
8
|
+
cacheTtlMs?: number
|
|
9
|
+
}
|
|
10
|
+
|
|
4
11
|
export interface ServerEcomiqConfig {
|
|
5
12
|
domain: string
|
|
6
13
|
api?: CreateApiOptions
|
|
14
|
+
cloud?: ServerEcomiqCloudConfig
|
|
7
15
|
}
|
|
8
16
|
|
|
9
17
|
const serverConfigKey = Symbol.for('@ecomiq/storefront/server-config')
|
package/src/server.ts
CHANGED
|
@@ -58,6 +58,8 @@ import {
|
|
|
58
58
|
type RemoveCartItemParams,
|
|
59
59
|
type UpdateCartItemQuantityParams,
|
|
60
60
|
type UploadPaymentReceiptParams,
|
|
61
|
+
EntityIdSchema,
|
|
62
|
+
OptionalEntityIdSchema,
|
|
61
63
|
} from '@ecomiq/core'
|
|
62
64
|
import { z } from 'zod'
|
|
63
65
|
import { getStorefrontClient } from './client'
|
|
@@ -69,11 +71,16 @@ import {
|
|
|
69
71
|
type AddProductToCartInput,
|
|
70
72
|
} from './cart-session'
|
|
71
73
|
import { submitProductReview } from './review-submission'
|
|
74
|
+
import { loadActiveStorefrontHome } from './storefront-runtime'
|
|
72
75
|
|
|
73
76
|
const getSettingsFn = createServerFn({ method: 'GET' }).handler(() =>
|
|
74
77
|
getStorefrontClient().getSettings(),
|
|
75
78
|
)
|
|
76
79
|
|
|
80
|
+
const getActiveStorefrontHomeFn = createServerFn({ method: 'GET' }).handler(
|
|
81
|
+
() => loadActiveStorefrontHome(),
|
|
82
|
+
)
|
|
83
|
+
|
|
77
84
|
const getStoreIdFn = createServerFn({ method: 'GET' }).handler(() =>
|
|
78
85
|
getStorefrontClient().getStoreId(),
|
|
79
86
|
)
|
|
@@ -133,7 +140,7 @@ const removeCartItemFn = createServerFn({ method: 'POST' })
|
|
|
133
140
|
.handler(({ data }) => submitCartItemRemoval(getStorefrontClient(), data))
|
|
134
141
|
|
|
135
142
|
const AddProductToCartServerSchema = z.object({
|
|
136
|
-
cartId:
|
|
143
|
+
cartId: OptionalEntityIdSchema,
|
|
137
144
|
currencyCode: z.string().length(3),
|
|
138
145
|
variantId: z.string().regex(/^[1-9]\d*$/),
|
|
139
146
|
quantity: z.number().int().positive(),
|
|
@@ -172,7 +179,7 @@ const checkoutCartFn = createServerFn({ method: 'POST' })
|
|
|
172
179
|
.handler(({ data }) => getStorefrontClient().checkoutCart(data))
|
|
173
180
|
|
|
174
181
|
const CartPaymentReceiptServerSchema = z.object({
|
|
175
|
-
cartId:
|
|
182
|
+
cartId: EntityIdSchema,
|
|
176
183
|
fileBase64: z.string().min(1),
|
|
177
184
|
fileName: z.string().min(1),
|
|
178
185
|
mimeType: z.string().min(1).optional(),
|
|
@@ -220,6 +227,7 @@ const getDistrictsFn = createServerFn({ method: 'GET' })
|
|
|
220
227
|
*/
|
|
221
228
|
export const serverApi = {
|
|
222
229
|
getSettings: () => getSettingsFn(),
|
|
230
|
+
getActiveStorefrontHome: () => getActiveStorefrontHomeFn(),
|
|
223
231
|
getStoreId: () => getStoreIdFn(),
|
|
224
232
|
getCollections: () => getCollectionsFn(),
|
|
225
233
|
getCollectionBySlug: (slug: string) => getCollectionBySlugFn({ data: { slug } }),
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@ecomiq/storefront-definition'
|