@neowhale/storefront 0.2.39 → 0.2.41

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,536 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as react from 'react';
3
- import { ReactNode } from 'react';
4
- import { F as WhaleStorefrontConfig, r as Product, P as PaymentData, O as Order, a as CartItem, T as TaxBreakdown, W as WhaleClient, f as Customer, E as EventType, g as CustomerAnalytics, d as CheckoutSession, A as Address, b as Category, c as CategoryTreeNode, l as LoyaltyAccount, m as LoyaltyReward, n as LoyaltyTransaction, v as Review, w as ReviewSummary, G as WishlistItem, R as Recommendation, k as Location, x as ShippingMethod, y as ShippingRate, D as DealValidation, C as Cart, H as ReferralStatus, I as ReferralEnrollment, i as LandingSection, Q as QRLandingData, h as LandingPageRenderData } from '../client-CUKv5fMM.js';
5
- import { ThemeTokens } from '@neowhale/ui';
6
- import * as zustand_middleware from 'zustand/middleware';
7
- import * as zustand from 'zustand';
8
- import { P as PixelManager } from '../pixel-manager-DsrUxlIB.js';
9
-
10
- interface WhaleProviderProps extends WhaleStorefrontConfig {
11
- children: ReactNode;
12
- /** Server-fetched products passed to client for hooks */
13
- products?: Product[];
14
- /** Manual theme overrides — merged with store theme fetched from storefront config */
15
- theme?: Partial<ThemeTokens>;
16
- }
17
- declare function WhaleProvider({ children, products, theme: themeProp, storeId, apiKey, gatewayUrl, proxyPath, mediaSigningSecret, supabaseHost, storagePrefix, sessionTtl, debug, trackingEnabled, recordingRate, }: WhaleProviderProps): react_jsx_runtime.JSX.Element;
18
-
19
- interface CartState {
20
- cartId: string | null;
21
- items: CartItem[];
22
- itemCount: number;
23
- subtotal: number;
24
- taxAmount: number;
25
- total: number;
26
- taxBreakdown: TaxBreakdown[];
27
- cartOpen: boolean;
28
- cartLoading: boolean;
29
- productImages: Record<string, string>;
30
- addItemInFlight: boolean;
31
- }
32
- interface CartActions {
33
- openCart: () => void;
34
- closeCart: () => void;
35
- toggleCart: () => void;
36
- initCart: () => Promise<void>;
37
- syncCart: () => Promise<void>;
38
- addItem: (productId: string, quantity: number, tier?: string, unitPrice?: number, imageUrl?: string | null, productName?: string) => Promise<void>;
39
- updateQuantity: (itemId: string, quantity: number) => Promise<void>;
40
- removeItem: (itemId: string, productName?: string) => Promise<void>;
41
- clearCart: () => void;
42
- checkout: (customerEmail?: string, payment?: PaymentData) => Promise<Order>;
43
- }
44
- type CartStore = ReturnType<typeof createCartStore>;
45
- declare function createCartStore(client: WhaleClient, storagePrefix: string, onAddToCart?: (productId: string, productName: string, quantity: number, price: number, tier?: string) => void, onRemoveFromCart?: (productId: string, productName: string) => void, onCartChange?: (cartId: string, total: number, itemCount: number) => void): Omit<zustand.StoreApi<CartState & CartActions>, "setState" | "persist"> & {
46
- setState(partial: (CartState & CartActions) | Partial<CartState & CartActions> | ((state: CartState & CartActions) => (CartState & CartActions) | Partial<CartState & CartActions>), replace?: false | undefined): unknown;
47
- setState(state: (CartState & CartActions) | ((state: CartState & CartActions) => CartState & CartActions), replace: true): unknown;
48
- persist: {
49
- setOptions: (options: Partial<zustand_middleware.PersistOptions<CartState & CartActions, {
50
- cartId: string | null;
51
- productImages: Record<string, string>;
52
- }, unknown>>) => void;
53
- clearStorage: () => void;
54
- rehydrate: () => Promise<void> | void;
55
- hasHydrated: () => boolean;
56
- onHydrate: (fn: (state: CartState & CartActions) => void) => () => void;
57
- onFinishHydration: (fn: (state: CartState & CartActions) => void) => () => void;
58
- getOptions: () => Partial<zustand_middleware.PersistOptions<CartState & CartActions, {
59
- cartId: string | null;
60
- productImages: Record<string, string>;
61
- }, unknown>>;
62
- };
63
- };
64
-
65
- interface AuthState {
66
- customer: Customer | null;
67
- sessionToken: string | null;
68
- sessionExpiresAt: string | null;
69
- authLoading: boolean;
70
- }
71
- interface AuthActions {
72
- sendOTP: (email: string) => Promise<boolean>;
73
- verifyOTP: (email: string, code: string) => Promise<boolean>;
74
- updateProfile: (data: {
75
- first_name: string;
76
- last_name: string;
77
- phone?: string;
78
- date_of_birth?: string;
79
- }) => Promise<void>;
80
- restoreSession: () => Promise<void>;
81
- isSessionValid: () => boolean;
82
- logout: () => void;
83
- fetchCustomer: (id: string) => Promise<void>;
84
- }
85
- type AuthStore = ReturnType<typeof createAuthStore>;
86
- declare function createAuthStore(client: WhaleClient, storagePrefix: string): Omit<zustand.StoreApi<AuthState & AuthActions>, "setState" | "persist"> & {
87
- setState(partial: (AuthState & AuthActions) | Partial<AuthState & AuthActions> | ((state: AuthState & AuthActions) => (AuthState & AuthActions) | Partial<AuthState & AuthActions>), replace?: false | undefined): unknown;
88
- setState(state: (AuthState & AuthActions) | ((state: AuthState & AuthActions) => AuthState & AuthActions), replace: true): unknown;
89
- persist: {
90
- setOptions: (options: Partial<zustand_middleware.PersistOptions<AuthState & AuthActions, {
91
- sessionToken: string | null;
92
- sessionExpiresAt: string | null;
93
- customer: {
94
- id: string;
95
- email: string | null;
96
- first_name: string;
97
- last_name: string;
98
- phone: string | null;
99
- loyalty_points: number;
100
- loyalty_tier: string;
101
- total_spent: number;
102
- total_orders: number;
103
- } | null;
104
- }, unknown>>) => void;
105
- clearStorage: () => void;
106
- rehydrate: () => Promise<void> | void;
107
- hasHydrated: () => boolean;
108
- onHydrate: (fn: (state: AuthState & AuthActions) => void) => () => void;
109
- onFinishHydration: (fn: (state: AuthState & AuthActions) => void) => () => void;
110
- getOptions: () => Partial<zustand_middleware.PersistOptions<AuthState & AuthActions, {
111
- sessionToken: string | null;
112
- sessionExpiresAt: string | null;
113
- customer: {
114
- id: string;
115
- email: string | null;
116
- first_name: string;
117
- last_name: string;
118
- phone: string | null;
119
- loyalty_points: number;
120
- loyalty_tier: string;
121
- total_spent: number;
122
- total_orders: number;
123
- } | null;
124
- }, unknown>>;
125
- };
126
- };
127
-
128
- interface WhaleContextValue {
129
- client: WhaleClient;
130
- config: {
131
- storeId: string;
132
- apiKey: string;
133
- gatewayUrl: string;
134
- proxyPath: string;
135
- mediaSigningSecret: string;
136
- supabaseHost: string;
137
- storagePrefix: string;
138
- sessionTtl: number;
139
- debug: boolean;
140
- trackingEnabled: boolean;
141
- recordingRate: number;
142
- };
143
- cartStore: CartStore;
144
- authStore: AuthStore;
145
- /** Products fetched server-side and passed via provider */
146
- products: Product[];
147
- /** Pixel manager — set after storefront config loads */
148
- pixelManager: PixelManager | null;
149
- }
150
- declare const WhaleContext: react.Context<WhaleContextValue | null>;
151
-
152
- declare function useCart(): {
153
- cartId: string | null;
154
- items: CartItem[];
155
- itemCount: number;
156
- subtotal: number;
157
- taxAmount: number;
158
- total: number;
159
- taxBreakdown: TaxBreakdown[];
160
- cartOpen: boolean;
161
- cartLoading: boolean;
162
- productImages: Record<string, string>;
163
- addItem: (productId: string, quantity: number, tier?: string, unitPrice?: number, imageUrl?: string | null, productName?: string) => Promise<void>;
164
- removeItem: (itemId: string, productName?: string) => Promise<void>;
165
- updateQuantity: (itemId: string, quantity: number) => Promise<void>;
166
- toggleCart: () => void;
167
- openCart: () => void;
168
- closeCart: () => void;
169
- initCart: () => Promise<void>;
170
- syncCart: () => Promise<void>;
171
- clearCart: () => void;
172
- checkout: (customerEmail?: string, payment?: PaymentData) => Promise<Order>;
173
- };
174
- /** Granular selector — only re-renders on count change */
175
- declare function useCartItemCount(): number;
176
- /** Granular selector — only re-renders on total change */
177
- declare function useCartTotal(): number;
178
-
179
- declare function useAuth(): {
180
- customer: Customer | null;
181
- authLoading: boolean;
182
- sessionToken: string | null;
183
- isAuthenticated: boolean;
184
- sendCode: (email: string) => Promise<boolean>;
185
- verifyCode: (email: string, code: string) => Promise<boolean>;
186
- updateProfile: (data: {
187
- first_name: string;
188
- last_name: string;
189
- phone?: string;
190
- date_of_birth?: string;
191
- }) => Promise<void>;
192
- restoreSession: () => Promise<void>;
193
- logout: () => void;
194
- fetchCustomer: (id: string) => Promise<void>;
195
- };
196
-
197
- /**
198
- * Returns products passed via WhaleProvider.
199
- * Optionally filters by category or search.
200
- */
201
- declare function useProducts(opts?: {
202
- categoryId?: string;
203
- search?: string;
204
- }): {
205
- products: Product[];
206
- allProducts: Product[];
207
- loading: boolean;
208
- };
209
- /**
210
- * Returns a single product by slug from the provider's product list.
211
- */
212
- declare function useProduct(slug: string | null | undefined): {
213
- product: Product | null;
214
- loading: boolean;
215
- };
216
-
217
- declare function useAnalytics(): {
218
- track: (eventType: EventType, data?: Record<string, unknown>) => Promise<void>;
219
- trackPageView: (url: string, referrer?: string) => void;
220
- trackProductView: (productId: string, productName: string, category: string, price?: number) => void;
221
- trackCategoryView: (categoryId: string, categoryName: string) => void;
222
- trackSearch: (query: string, resultCount?: number) => void;
223
- trackBeginCheckout: (cartId: string, total: number, itemCount: number) => void;
224
- trackPurchase: (orderId: string, orderNumber: string, total: number) => void;
225
- trackAddToCart: (productId: string, productName: string, quantity: number, price: number, tier?: string) => void;
226
- trackRemoveFromCart: (productId: string, productName: string) => void;
227
- linkCustomer: (customerId: string) => Promise<void>;
228
- updateSessionCart: (cartId: string, cartTotal: number, cartItemCount: number) => Promise<void>;
229
- updateSessionOrder: (orderId: string) => Promise<void>;
230
- getOrCreateSession: () => Promise<string>;
231
- captureGeolocation: (options?: {
232
- timeout?: number;
233
- enableHighAccuracy?: boolean;
234
- }) => Promise<GeolocationPosition | null>;
235
- /** Whether tracking is globally enabled for this storefront */
236
- trackingEnabled: boolean;
237
- /** Configured recording sample rate (0–1) for behavioral session replays */
238
- recordingRate: number;
239
- /** Stable visitor ID for cross-session attribution */
240
- visitorId: string;
241
- };
242
-
243
- declare function useWhaleClient(): WhaleClient;
244
-
245
- declare function useCustomerOrders(): {
246
- orders: Order[];
247
- loading: boolean;
248
- refresh: () => Promise<void>;
249
- };
250
- declare function useCustomerAnalytics(): {
251
- analytics: CustomerAnalytics | null;
252
- loading: boolean;
253
- };
254
-
255
- declare function useCheckout(): {
256
- session: CheckoutSession | null;
257
- loading: boolean;
258
- error: Error | null;
259
- createSession: (params: {
260
- cart_id: string;
261
- customer_email?: string;
262
- shipping_address?: Address;
263
- billing_address?: Address;
264
- shipping_method_id?: string;
265
- coupon_code?: string;
266
- loyalty_reward_id?: string;
267
- selected_product_id?: string;
268
- }) => Promise<CheckoutSession>;
269
- updateSession: (params: {
270
- customer_email?: string;
271
- shipping_address?: Address;
272
- billing_address?: Address;
273
- shipping_method_id?: string;
274
- coupon_code?: string;
275
- }) => Promise<CheckoutSession>;
276
- complete: (payment?: PaymentData, opts?: {
277
- loyalty_reward_id?: string;
278
- selected_product_id?: string;
279
- }) => Promise<Order>;
280
- reset: () => void;
281
- };
282
-
283
- interface SearchParams {
284
- query: string;
285
- category_id?: string;
286
- min_price?: number;
287
- max_price?: number;
288
- sort_by?: string;
289
- sort_order?: 'asc' | 'desc';
290
- limit?: number;
291
- }
292
- declare function useSearch(): {
293
- results: Product[];
294
- hasMore: boolean;
295
- loading: boolean;
296
- error: Error | null;
297
- search: (params: SearchParams) => Promise<void>;
298
- loadMore: (params: SearchParams) => Promise<void>;
299
- clear: () => void;
300
- };
301
-
302
- declare function useCategories(): {
303
- categories: Category[];
304
- tree: CategoryTreeNode[];
305
- loading: boolean;
306
- error: Error | null;
307
- refresh: () => Promise<void>;
308
- getCategory: (id: string) => Promise<Category>;
309
- };
310
-
311
- declare function useLoyalty(): {
312
- account: LoyaltyAccount | null;
313
- rewards: LoyaltyReward[];
314
- transactions: LoyaltyTransaction[];
315
- loading: boolean;
316
- error: Error | null;
317
- refresh: () => Promise<void>;
318
- redeemReward: (rewardId: string) => Promise<{
319
- success: boolean;
320
- points_remaining: number;
321
- }>;
322
- fetchProductsByCategory: (category: string, locationId: string, tier?: string) => Promise<Product[]>;
323
- };
324
-
325
- declare function useReviews(productId: string | null | undefined): {
326
- reviews: Review[];
327
- summary: ReviewSummary | null;
328
- hasMore: boolean;
329
- loading: boolean;
330
- error: Error | null;
331
- refresh: () => Promise<void>;
332
- loadMore: () => Promise<void>;
333
- submit: (data: {
334
- rating: number;
335
- title?: string;
336
- body?: string;
337
- customer_name?: string;
338
- }) => Promise<Review>;
339
- };
340
-
341
- declare function useWishlist(): {
342
- items: WishlistItem[];
343
- loading: boolean;
344
- error: Error | null;
345
- refresh: () => Promise<void>;
346
- add: (productId: string) => Promise<WishlistItem>;
347
- remove: (productId: string) => Promise<void>;
348
- has: (productId: string) => boolean;
349
- toggle: (productId: string) => Promise<void>;
350
- };
351
-
352
- declare function useRecommendations(params?: {
353
- product_id?: string;
354
- customer_id?: string;
355
- limit?: number;
356
- type?: 'similar' | 'frequently_bought_together' | 'personalized';
357
- }): {
358
- recommendations: Recommendation[];
359
- loading: boolean;
360
- error: Error | null;
361
- refresh: () => Promise<void>;
362
- };
363
-
364
- declare function useLocations(): {
365
- locations: Location[];
366
- loading: boolean;
367
- error: Error | null;
368
- refresh: () => Promise<void>;
369
- getLocation: (id: string) => Promise<Location>;
370
- };
371
-
372
- declare function useShipping(): {
373
- methods: ShippingMethod[];
374
- rates: ShippingRate[];
375
- loading: boolean;
376
- error: Error | null;
377
- refreshMethods: () => Promise<void>;
378
- calculateRates: (params: {
379
- cart_id: string;
380
- shipping_address: Address;
381
- }) => Promise<ShippingRate[]>;
382
- };
383
-
384
- declare function useDeals(): {
385
- validation: DealValidation | null;
386
- loading: boolean;
387
- error: Error | null;
388
- validate: (code: string, cartId?: string) => Promise<DealValidation>;
389
- apply: (cartId: string, code: string) => Promise<Cart>;
390
- remove: (cartId: string) => Promise<Cart>;
391
- clear: () => void;
392
- };
393
- /** @deprecated Use useDeals instead */
394
- declare const useCoupons: typeof useDeals;
395
-
396
- declare function useReferral(): {
397
- status: ReferralStatus | null;
398
- loading: boolean;
399
- error: Error | null;
400
- enroll: () => Promise<ReferralEnrollment>;
401
- refresh: () => Promise<void>;
402
- share: () => Promise<void>;
403
- attributeReferral: (code: string) => Promise<{
404
- success: boolean;
405
- affiliate_id?: string;
406
- error?: string;
407
- }>;
408
- referralCode: string | null;
409
- shareUrl: string | null;
410
- isEnrolled: boolean;
411
- referredBy: {
412
- affiliate_id: string;
413
- referral_code: string;
414
- referrer_name: string;
415
- } | null;
416
- };
417
-
418
- interface QRLandingPageProps {
419
- code: string;
420
- gatewayUrl?: string;
421
- /** Override rendering for any section type */
422
- renderSection?: (section: LandingSection, defaultRenderer: () => React.ReactNode) => React.ReactNode;
423
- onDataLoaded?: (data: QRLandingData) => void;
424
- onError?: (error: Error) => void;
425
- }
426
- declare function QRLandingPage({ code, gatewayUrl, renderSection, onDataLoaded, onError, }: QRLandingPageProps): react_jsx_runtime.JSX.Element | null;
427
-
428
- interface LandingPageProps {
429
- slug: string;
430
- gatewayUrl?: string;
431
- renderSection?: (section: LandingSection, defaultRenderer: () => React.ReactNode) => React.ReactNode;
432
- onDataLoaded?: (data: LandingPageRenderData) => void;
433
- onError?: (error: Error) => void;
434
- onEvent?: (event: string, data: Record<string, unknown>) => void;
435
- analyticsContext?: {
436
- visitorId?: string;
437
- sessionId?: string;
438
- };
439
- enableAnalytics?: boolean;
440
- }
441
- declare function LandingPage({ slug, gatewayUrl, renderSection, onDataLoaded, onError, onEvent, analyticsContext, enableAnalytics, }: LandingPageProps): react_jsx_runtime.JSX.Element | null;
442
-
443
- interface SectionTheme {
444
- bg: string;
445
- fg: string;
446
- accent: string;
447
- surface: string;
448
- muted: string;
449
- fontDisplay?: string;
450
- fontBody?: string;
451
- }
452
- interface ClickTrackingContext {
453
- gatewayUrl?: string;
454
- code?: string;
455
- }
456
- interface SectionData {
457
- store?: {
458
- id?: string;
459
- name?: string | null;
460
- logo_url?: string | null;
461
- tagline?: string | null;
462
- theme?: Record<string, unknown> | null;
463
- } | null;
464
- product?: Record<string, unknown> | null;
465
- coa?: {
466
- url: string;
467
- viewer_url?: string | null;
468
- document_name: string;
469
- } | null;
470
- gatewayUrl?: string;
471
- landing_page?: {
472
- slug?: string;
473
- } | null;
474
- analyticsContext?: {
475
- visitorId?: string;
476
- sessionId?: string;
477
- };
478
- }
479
-
480
- /**
481
- * Routes a section to its renderer and tracks section visibility via IntersectionObserver.
482
- * Each section is wrapped in a div with data attributes for analytics targeting.
483
- */
484
- declare function SectionRenderer({ section, data, theme, tracking, onEvent, }: {
485
- section: LandingSection;
486
- data: SectionData;
487
- theme: SectionTheme;
488
- tracking?: ClickTrackingContext;
489
- onEvent?: (event: string, data: Record<string, unknown>) => void;
490
- }): react_jsx_runtime.JSX.Element;
491
-
492
- /**
493
- * Auto-tracks page views on pathname change and links customer sessions.
494
- * Rendered internally by WhaleProvider — storefronts don't need to add this manually.
495
- *
496
- * When `config.trackingEnabled` is false the component renders nothing and
497
- * skips all side-effects — the underlying hook guards individual calls too,
498
- * but short-circuiting here avoids session creation entirely.
499
- */
500
- declare function AnalyticsTracker({ pathname }: {
501
- pathname: string;
502
- }): null;
503
-
504
- /**
505
- * Hydrates cart from gateway on mount if a cartId is persisted.
506
- * Rendered internally by WhaleProvider.
507
- */
508
- declare function CartInitializer(): null;
509
-
510
- /**
511
- * Restores auth session on mount — syncs persisted token to client.
512
- * Rendered internally by WhaleProvider.
513
- */
514
- declare function AuthInitializer(): null;
515
-
516
- interface PixelInitializerProps {
517
- onReady: (manager: PixelManager) => void;
518
- onTheme?: (theme: Record<string, unknown>) => void;
519
- }
520
- /**
521
- * Fetches storefront config on mount and initializes pixel providers + theme.
522
- * Sets pixelManager on context so useAnalytics can dispatch events to it.
523
- * If the config includes a `theme` field, calls onTheme so the provider can apply it.
524
- * Rendered internally by WhaleProvider — storefronts don't need to add this manually.
525
- */
526
- declare function PixelInitializer({ onReady, onTheme }: PixelInitializerProps): null;
527
-
528
- declare function BehavioralTrackerComponent({ pathname }: {
529
- pathname: string | null;
530
- }): null;
531
-
532
- declare function FingerprintCollector(): null;
533
-
534
- declare function SessionRecorderComponent(): null;
535
-
536
- export { AnalyticsTracker, type AuthActions, AuthInitializer, type AuthState, type AuthStore, BehavioralTrackerComponent, type CartActions, CartInitializer, type CartState, type CartStore, type ClickTrackingContext, FingerprintCollector, LandingPage, type LandingPageProps, PixelInitializer, QRLandingPage, type QRLandingPageProps, type SearchParams, SectionRenderer, type SectionTheme, SessionRecorderComponent, WhaleContext, type WhaleContextValue, WhaleProvider, type WhaleProviderProps, useAnalytics, useAuth, useCart, useCartItemCount, useCartTotal, useCategories, useCheckout, useCoupons, useCustomerAnalytics, useCustomerOrders, useDeals, useLocations, useLoyalty, useProduct, useProducts, useRecommendations, useReferral, useReviews, useSearch, useShipping, useWhaleClient, useWishlist };