@fayz-ai/storefront 0.8.3 → 0.8.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"CheckoutPage.d.ts","sourceRoot":"","sources":["../../src/pages/CheckoutPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AA0GlD,wBAAgB,YAAY,sBAkkB3B"}
1
+ {"version":3,"file":"CheckoutPage.d.ts","sourceRoot":"","sources":["../../src/pages/CheckoutPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAA;AA0GlD,wBAAgB,YAAY,sBAskB3B"}
@@ -11,4 +11,5 @@ export declare function StorefrontScaffold({ manifest, surface }: {
11
11
  export declare namespace StorefrontScaffold {
12
12
  var displayName: string;
13
13
  }
14
+ export declare function registerStorefrontScaffold(): void;
14
15
  //# sourceMappingURL=scaffold.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../src/scaffold.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,WAAW,EAAmB,MAAM,eAAe,CAAA;AAEjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAIhD,OAAO,UAAU,CAAA;AAgBjB,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW,CAiCtE;AAgCD,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,qBAanG;yBAbe,kBAAkB"}
1
+ {"version":3,"file":"scaffold.d.ts","sourceRoot":"","sources":["../src/scaffold.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,WAAW,EAAmB,MAAM,eAAe,CAAA;AAEjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAIhD,OAAO,UAAU,CAAA;AAgBjB,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,WAAW,CAiCtE;AAgCD,wBAAgB,kBAAkB,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,qBAanG;yBAbe,kBAAkB;;;AAoBlC,wBAAgB,0BAA0B,IAAI,IAAI,CAIjD"}
package/package.json CHANGED
@@ -3,36 +3,33 @@
3
3
  "fayz": {
4
4
  "status": "beta"
5
5
  },
6
- "version": "0.8.3",
6
+ "version": "0.8.5",
7
7
  "description": "Fayz SDK storefront kit — Shopify-style customer-facing ecommerce template components",
8
8
  "type": "module",
9
- "main": "./dist/index.cjs",
9
+ "sideEffects": false,
10
+ "main": "./dist/index.js",
10
11
  "module": "./dist/index.js",
11
12
  "types": "./dist/index.d.ts",
12
13
  "exports": {
13
14
  ".": {
14
15
  "source": "./src/index.ts",
15
16
  "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js",
17
- "require": "./dist/index.cjs"
17
+ "import": "./dist/index.js"
18
18
  },
19
19
  "./ui": {
20
20
  "source": "./src/ui.ts",
21
21
  "types": "./dist/ui.d.ts",
22
- "import": "./dist/ui.js",
23
- "require": "./dist/ui.cjs"
22
+ "import": "./dist/ui.js"
24
23
  },
25
24
  "./catalog": {
26
25
  "source": "./src/catalog.ts",
27
26
  "types": "./dist/catalog.d.ts",
28
- "import": "./dist/catalog.js",
29
- "require": "./dist/catalog.cjs"
27
+ "import": "./dist/catalog.js"
30
28
  },
31
29
  "./shop": {
32
30
  "source": "./src/shop.ts",
33
31
  "types": "./dist/shop.d.ts",
34
- "import": "./dist/shop.js",
35
- "require": "./dist/shop.cjs"
32
+ "import": "./dist/shop.js"
36
33
  }
37
34
  },
38
35
  "files": [
@@ -40,25 +37,28 @@
40
37
  "src"
41
38
  ],
42
39
  "dependencies": {
43
- "@supabase/supabase-js": "^2.45.0",
44
- "lucide-react": "^0.400.0",
45
- "zustand": "^4.5.0",
46
- "@fayz-ai/auth": "^0.8.3",
47
- "@fayz-ai/core": "^0.8.3",
48
- "@fayz-ai/plugin-auth": "^0.8.0",
49
- "@fayz-ai/sdk": "^0.8.3",
50
- "@fayz-ai/shop": "^0.8.3",
51
- "@fayz-ai/ui": "^0.8.3"
40
+ "@fayz-ai/auth": "^0.8.5",
41
+ "@fayz-ai/sdk": "^0.8.5",
42
+ "@fayz-ai/ui": "^0.8.5",
43
+ "@fayz-ai/shop": "^0.8.4",
44
+ "@fayz-ai/core": "^0.8.5",
45
+ "@fayz-ai/plugin-auth": "^0.8.0"
52
46
  },
53
47
  "peerDependencies": {
54
48
  "react": "^18.0.0 || ^19.0.0",
55
- "react-dom": "^18.0.0 || ^19.0.0"
49
+ "react-dom": "^18.0.0 || ^19.0.0",
50
+ "zustand": "^4.5.0",
51
+ "@supabase/supabase-js": "^2.45.0",
52
+ "lucide-react": ">=0.400.0 <1.0.0"
56
53
  },
57
54
  "devDependencies": {
58
55
  "@types/react": "^18.3.0",
59
56
  "react": "^18.3.0",
60
57
  "tsup": "^8.2.0",
61
- "typescript": "^5.5.0"
58
+ "typescript": "^5.5.0",
59
+ "zustand": "^4.5.0",
60
+ "@supabase/supabase-js": "^2.45.0",
61
+ "lucide-react": "^0.400.0"
62
62
  },
63
63
  "keywords": [
64
64
  "fayz",
package/src/blocks.tsx CHANGED
@@ -39,8 +39,8 @@ export function registerStorefrontBlocks(): void {
39
39
  registerBlock('newsletter', NewsletterBand, { source: 'sdk', label: 'Newsletter band' })
40
40
  }
41
41
 
42
- // Register on import so any consumer of the storefront package has the blocks.
43
- registerStorefrontBlocks()
42
+ // Registration happens in initStorefrontRuntime (both the scaffold and
43
+ // createStorefront call it) so importing this module stays side-effect-free.
44
44
 
45
45
  /** Convert the typed storefront section blueprint into a generic block tree. */
46
46
  export function sectionsToBlocks(sections: readonly StorefrontSection[]): BlockNode[] {
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react'
2
- import { CreditCard, LogOut, Mail, Package, Phone, Search, ShoppingBag, User, UserCircle, X } from 'lucide-react'
2
+ import { CreditCard, LogOut, Mail, Menu, Package, Phone, Search, ShoppingBag, User, UserCircle, X } from 'lucide-react'
3
3
  import { signOutCustomer } from '../auth'
4
4
  import { useCartStore, selectCount } from '../stores/cart.store'
5
5
  import { useCatalogStore } from '../stores/catalog.store'
@@ -151,7 +151,7 @@ function SearchInput({ className, iconOnly = false }: { className?: string; icon
151
151
  )
152
152
  }
153
153
 
154
- function HeaderActions() {
154
+ function HeaderActions({ onMenuClick }: { onMenuClick?: () => void }) {
155
155
  const config = useStorefrontConfig()
156
156
  const count = useCartStore(selectCount)
157
157
  const openDrawer = useCartStore((s) => s.openDrawer)
@@ -251,6 +251,16 @@ function HeaderActions() {
251
251
  )}
252
252
  </button>
253
253
  )}
254
+ {onMenuClick && (
255
+ <button
256
+ type="button"
257
+ aria-label="Abrir menu"
258
+ onClick={onMenuClick}
259
+ className="relative rounded-full p-2.5 transition-opacity hover:opacity-70 md:hidden"
260
+ >
261
+ <Menu className="h-5 w-5" />
262
+ </button>
263
+ )}
254
264
  </nav>
255
265
  )
256
266
  }
@@ -296,12 +306,99 @@ function NavLinks({ className }: { className?: string }) {
296
306
  )
297
307
  }
298
308
 
309
+ function MobileMenuDrawer({ open, onClose }: { open: boolean; onClose: () => void }) {
310
+ const config = useStorefrontConfig()
311
+ const { categories } = useCategories()
312
+ const setCategoryId = useCatalogStore((s) => s.setCategoryId)
313
+ const showCategories = config.theme?.header?.showCategories !== false
314
+
315
+ const goCategory = (categoryId: string) => {
316
+ useCatalogStore.getState().reset()
317
+ setCategoryId(categoryId)
318
+ navigateTo(config.catalogPath)
319
+ onClose()
320
+ }
321
+
322
+ // a11y: close on Escape
323
+ React.useEffect(() => {
324
+ if (!open) return
325
+ const onKey = (e: KeyboardEvent) => {
326
+ if (e.key === 'Escape') onClose()
327
+ }
328
+ document.addEventListener('keydown', onKey)
329
+ return () => document.removeEventListener('keydown', onKey)
330
+ }, [open, onClose])
331
+
332
+ if (!open) return null
333
+
334
+ return (
335
+ <div className="fixed inset-0 z-50 md:hidden">
336
+ <div
337
+ className="absolute inset-0 animate-fade-in bg-black/40"
338
+ aria-hidden
339
+ onClick={onClose}
340
+ />
341
+ <div
342
+ data-testid="mobile-menu-drawer"
343
+ role="dialog"
344
+ aria-label="Menu Principal"
345
+ className="absolute right-0 top-0 flex h-full w-full max-w-[280px] animate-slide-in-from-right flex-col bg-background shadow-2xl"
346
+ >
347
+ <div className="flex items-center justify-between border-b px-5 py-4">
348
+ <h2 className="text-lg font-semibold">Menu</h2>
349
+ <button
350
+ type="button"
351
+ aria-label="Fechar menu"
352
+ onClick={onClose}
353
+ className="rounded-full p-1.5 hover:bg-muted"
354
+ >
355
+ <X className="h-5 w-5" />
356
+ </button>
357
+ </div>
358
+ <div className="flex-1 overflow-y-auto p-5">
359
+ <nav className="flex flex-col gap-4">
360
+ {config.nav.map((link) => (
361
+ <Link
362
+ key={link.to}
363
+ to={link.to}
364
+ onClick={onClose}
365
+ className="text-base font-semibold transition-opacity hover:opacity-70"
366
+ >
367
+ {link.label}
368
+ </Link>
369
+ ))}
370
+ {showCategories && categories.length > 0 && (
371
+ <>
372
+ <div className="my-2 border-t" />
373
+ <div className="mb-2 text-xs font-bold uppercase tracking-wider text-muted-foreground">
374
+ Categorias
375
+ </div>
376
+ {categories.map((c) => (
377
+ <button
378
+ key={c.id}
379
+ type="button"
380
+ onClick={() => goCategory(c.id)}
381
+ className="text-left text-sm font-medium transition-opacity hover:opacity-80"
382
+ >
383
+ {c.name}
384
+ </button>
385
+ ))}
386
+ </>
387
+ )}
388
+ </nav>
389
+ </div>
390
+ </div>
391
+ </div>
392
+ )
393
+ }
394
+
299
395
  export function StorefrontHeader() {
300
396
  const config = useStorefrontConfig()
301
397
  const variant = config.theme?.header?.variant ?? 'classic'
302
398
  const scrolled = useScrolled()
303
399
  const showSearch = config.theme?.header?.showSearch !== false
304
400
  const iconSearch = config.theme?.header?.searchStyle === 'icon'
401
+ const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
305
402
  const logo = (
306
403
  <Link to="/" className="sf-heading shrink-0 text-xl font-bold tracking-tight">
307
404
  {config.logo ?? config.name}
@@ -359,15 +456,21 @@ export function StorefrontHeader() {
359
456
  </div>
360
457
  </div>
361
458
  ) : (
362
- // classic: logo left, nav, then a right-aligned search + actions cluster
363
- <div className="mx-auto flex h-16 max-w-7xl items-center gap-6 px-4 sm:px-6">
364
- {logo}
365
- <NavLinks className="hidden md:flex" />
366
- <div className="ml-auto flex items-center gap-2 sm:gap-3">
367
- {showSearch && <SearchInput iconOnly={iconSearch} className={iconSearch ? '' : 'hidden w-full max-w-sm sm:block'} />}
368
- <HeaderActions />
459
+ // classic: logo left, nav, then a right-aligned search + actions cluster.
460
+ // NavLinks is hidden below md in the primary row (no room for it there) —
461
+ // below md a hamburger opens MobileMenuDrawer instead, otherwise mobile
462
+ // has no way to reach nav/category links at all.
463
+ <>
464
+ <div className="mx-auto flex h-16 max-w-7xl items-center gap-6 px-4 sm:px-6">
465
+ {logo}
466
+ <NavLinks className="hidden md:flex" />
467
+ <div className="ml-auto flex items-center gap-2 sm:gap-3">
468
+ {showSearch && <SearchInput iconOnly={iconSearch} className={iconSearch ? '' : 'hidden w-full max-w-sm sm:block'} />}
469
+ <HeaderActions onMenuClick={() => setMobileMenuOpen(true)} />
470
+ </div>
369
471
  </div>
370
- </div>
472
+ <MobileMenuDrawer open={mobileMenuOpen} onClose={() => setMobileMenuOpen(false)} />
473
+ </>
371
474
  )}
372
475
  </header>
373
476
  )
@@ -1,5 +1,5 @@
1
1
  import React, { useState } from 'react'
2
- import * as LucideIcons from 'lucide-react'
2
+ import { getLucideIcon } from '@fayz-ai/ui/icons'
3
3
  import { bannerPlaceholder } from '../../sections'
4
4
  import { Reveal } from '../../motion'
5
5
  import { Link } from '../../router'
@@ -7,7 +7,7 @@ import { TID } from '../../testids'
7
7
  import { SmoothImage } from '../SmoothImage'
8
8
 
9
9
  function Icon({ name, className }: { name: string; className?: string }) {
10
- const C = (LucideIcons as unknown as Record<string, React.ComponentType<{ className?: string }>>)[name]
10
+ const C = getLucideIcon(name)
11
11
  return C ? <C className={className} /> : null
12
12
  }
13
13
 
@@ -5,6 +5,7 @@ import type { MockShopSeed } from '@fayz-ai/shop/mock'
5
5
  import type { Discount } from '@fayz-ai/shop/types'
6
6
  import type { ShopProvider } from '@fayz-ai/shop/provider'
7
7
  import { initCustomerAuth, resolveAuthAdapter } from './auth'
8
+ import { registerStorefrontBlocks } from './blocks'
8
9
  import { getStorefrontComponents, StorefrontConfigProvider, resolveConfig, useStorefrontConfig } from './config'
9
10
  import type { StorefrontConfig, StorefrontDiscountConfig } from './config'
10
11
  import type { StorefrontComponents } from './component-contracts'
@@ -93,6 +94,10 @@ function storefrontDiscountToSeed(discount: StorefrontDiscountConfig): Discount
93
94
  value: discount.percent,
94
95
  usageLimit: null,
95
96
  oncePerCustomer: false,
97
+ minSubtotal: null,
98
+ appliesTo: 'all',
99
+ productIds: [],
100
+ categoryIds: [],
96
101
  startsAt: ts,
97
102
  endsAt: null,
98
103
  status: 'active',
@@ -116,6 +121,7 @@ function buildMockSeed(config: StorefrontConfig): MockShopSeed | undefined {
116
121
  }
117
122
 
118
123
  export function initStorefrontRuntime(config: StorefrontConfig): void {
124
+ registerStorefrontBlocks()
119
125
  if (resolveConfig(config).features.accounts) {
120
126
  initCustomerAuth(resolveAuthAdapter(config.auth, {
121
127
  supabaseUrl: config.supabaseUrl,
package/src/index.ts CHANGED
@@ -188,4 +188,15 @@ export type {
188
188
  // live on their own subpaths (./ui, ./catalog, ./shop) to keep module graphs
189
189
  // separate. Mirrors the @fayz-ai/saas front door.
190
190
  // ---------------------------------------------------------------------------
191
- export { renderApp, getSupabaseClientOptional } from '@fayz-ai/core'
191
+ // renderApp is wrapped (not re-exported) so the 'storefront' scaffold registers
192
+ // on first render instead of at import time — keeps the barrel side-effect-free.
193
+ import { renderApp as coreRenderApp } from '@fayz-ai/core'
194
+ import { registerStorefrontScaffold } from './scaffold'
195
+
196
+ export const renderApp: typeof coreRenderApp = (...args) => {
197
+ registerStorefrontScaffold()
198
+ return coreRenderApp(...args)
199
+ }
200
+
201
+ export { getSupabaseClientOptional } from '@fayz-ai/core'
202
+ export { registerStorefrontScaffold } from './scaffold'
@@ -346,7 +346,7 @@ export function CheckoutPage() {
346
346
  ]
347
347
  const minDuration = sleep(stepMs * 2)
348
348
  try {
349
- const { order } = await placeStorefrontOrder({
349
+ const { order, customerId } = await placeStorefrontOrder({
350
350
  config,
351
351
  cart,
352
352
  session,
@@ -369,6 +369,10 @@ export function CheckoutPage() {
369
369
  // declare it settled. The order is now born `pending` and only the
370
370
  // merchant (or a PSP webhook) can confirm the money arrived.
371
371
  })
372
+ // placeStorefrontOrder resolves/creates the customer record but doesn't persist
373
+ // it — without this, "My purchases" right after checkout queries by email, which
374
+ // anon can't read under RLS, and silently comes back empty.
375
+ if (customerId) session.setSession({ customerId, email: form.email, name: form.name })
372
376
 
373
377
  await minDuration
374
378
  cart.clear()
package/src/scaffold.tsx CHANGED
@@ -104,6 +104,12 @@ export function StorefrontScaffold({ manifest, surface }: { manifest: AppManifes
104
104
  }
105
105
  StorefrontScaffold.displayName = 'StorefrontScaffold'
106
106
 
107
- // Self-register so `renderApp(manifest)` can resolve the 'storefront' scaffold
108
- // whenever this package is imported.
109
- registerScaffold('storefront', StorefrontScaffold, { source: 'sdk', label: 'Storefront' })
107
+ // Registration is lazy (called from the storefront renderApp wrapper and
108
+ // createStorefront*) so that importing the @fayz-ai/storefront barrel stays
109
+ // side-effect-free and tree-shakable.
110
+ let storefrontScaffoldRegistered = false
111
+ export function registerStorefrontScaffold(): void {
112
+ if (storefrontScaffoldRegistered) return
113
+ storefrontScaffoldRegistered = true
114
+ registerScaffold('storefront', StorefrontScaffold, { source: 'sdk', label: 'Storefront' })
115
+ }
package/dist/catalog.cjs DELETED
@@ -1,14 +0,0 @@
1
- 'use strict';
2
-
3
- var catalog = require('@fayz-ai/shop/catalog');
4
-
5
-
6
-
7
- Object.keys(catalog).forEach(function (k) {
8
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
9
- enumerable: true,
10
- get: function () { return catalog[k]; }
11
- });
12
- });
13
- //# sourceMappingURL=catalog.cjs.map
14
- //# sourceMappingURL=catalog.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"catalog.cjs","sourcesContent":[]}