@fluid-app/rep-sdk 0.1.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 (52) hide show
  1. package/README.md +413 -0
  2. package/dist/ContactsScreen-BYXF74BO.js +4 -0
  3. package/dist/ContactsScreen-BYXF74BO.js.map +1 -0
  4. package/dist/ContactsScreen-XZOQJVFE.cjs +17 -0
  5. package/dist/ContactsScreen-XZOQJVFE.cjs.map +1 -0
  6. package/dist/CustomersScreen-53SXRDDK.cjs +17 -0
  7. package/dist/CustomersScreen-53SXRDDK.cjs.map +1 -0
  8. package/dist/CustomersScreen-VS6LGULO.js +4 -0
  9. package/dist/CustomersScreen-VS6LGULO.js.map +1 -0
  10. package/dist/MessagingScreen-O42JEJMW.js +4 -0
  11. package/dist/MessagingScreen-O42JEJMW.js.map +1 -0
  12. package/dist/MessagingScreen-UCVLYWZB.cjs +17 -0
  13. package/dist/MessagingScreen-UCVLYWZB.cjs.map +1 -0
  14. package/dist/OrdersScreen-QQJFTTSS.js +4 -0
  15. package/dist/OrdersScreen-QQJFTTSS.js.map +1 -0
  16. package/dist/OrdersScreen-WNT2WDLI.cjs +17 -0
  17. package/dist/OrdersScreen-WNT2WDLI.cjs.map +1 -0
  18. package/dist/ProductsScreen-CTIAKS3Z.cjs +17 -0
  19. package/dist/ProductsScreen-CTIAKS3Z.cjs.map +1 -0
  20. package/dist/ProductsScreen-TRIT2FE3.js +4 -0
  21. package/dist/ProductsScreen-TRIT2FE3.js.map +1 -0
  22. package/dist/chunk-2AWTZV3T.js +16 -0
  23. package/dist/chunk-2AWTZV3T.js.map +1 -0
  24. package/dist/chunk-CXRJSGO6.js +16 -0
  25. package/dist/chunk-CXRJSGO6.js.map +1 -0
  26. package/dist/chunk-DEQ3PBVX.cjs +29 -0
  27. package/dist/chunk-DEQ3PBVX.cjs.map +1 -0
  28. package/dist/chunk-JZRNKSKT.cjs +19 -0
  29. package/dist/chunk-JZRNKSKT.cjs.map +1 -0
  30. package/dist/chunk-LO2HDG6C.js +26 -0
  31. package/dist/chunk-LO2HDG6C.js.map +1 -0
  32. package/dist/chunk-MBUCXIUN.cjs +19 -0
  33. package/dist/chunk-MBUCXIUN.cjs.map +1 -0
  34. package/dist/chunk-MEOOAMH2.cjs +19 -0
  35. package/dist/chunk-MEOOAMH2.cjs.map +1 -0
  36. package/dist/chunk-PJWPO4BJ.js +16 -0
  37. package/dist/chunk-PJWPO4BJ.js.map +1 -0
  38. package/dist/chunk-PZIHCYDD.js +16 -0
  39. package/dist/chunk-PZIHCYDD.js.map +1 -0
  40. package/dist/chunk-QUVJ3R4T.cjs +19 -0
  41. package/dist/chunk-QUVJ3R4T.cjs.map +1 -0
  42. package/dist/chunk-WH7WZXT6.js +16 -0
  43. package/dist/chunk-WH7WZXT6.js.map +1 -0
  44. package/dist/chunk-YII3IXF4.cjs +19 -0
  45. package/dist/chunk-YII3IXF4.cjs.map +1 -0
  46. package/dist/index.cjs +2446 -0
  47. package/dist/index.cjs.map +1 -0
  48. package/dist/index.d.cts +2164 -0
  49. package/dist/index.d.ts +2164 -0
  50. package/dist/index.js +2079 -0
  51. package/dist/index.js.map +1 -0
  52. package/package.json +58 -0
@@ -0,0 +1,2164 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React, { ReactNode, ComponentProps } from 'react';
3
+ import { QueryClient, UseQueryResult } from '@tanstack/react-query';
4
+ import { WidgetSchema, Theme, BackgroundValue, ColorOptions, PaddingOptions, BorderRadiusOptions } from '@fluid-app/rep-core/types';
5
+ export { AlignOptions, BackgroundType, BackgroundValue, BorderRadiusOptions, ButtonSizeOptions, ColorOptions, FontSizeOptions, GapOptions, PaddingOptions, SectionLayoutType, ShareableItem, Theme, TypedWidgetSchema, WIDGET_TYPE_NAMES, WidgetPath, WidgetRegistry, WidgetSchema, WidgetType, WidgetTypeName, assertDefined, assertNever, isWidgetType, isWidgetTypeName, sectionLayoutConfig } from '@fluid-app/rep-core/types';
6
+ export { BUILT_IN_THEMES, CORE_COLOR_KEYS, CoreColors, DEFAULT_CORE_COLORS, Oklch, ThemeConfig, catppuccinMocha, clampChroma, defaultTheme, detectThemeMode, dracula, everforest, generateColorSwatches, generateDualTheme, generateSmartDualTheme, generateTheme, generateThemeCssVars, gruvbox, mod, monokai, nord, oklchString, parseOklch, rosePine, rotateHue, rotateSoft, solarized, toDarkMode, toLightMode, tokyoNight } from '@fluid-app/rep-core/theme';
7
+ export { AlertWidget, CalendarWidget, CarouselWidget, CatchUpWidget, ChartWidget, ContainerWidget, EmbedWidget, ImageWidget, LayoutWidget, ListWidget, MySiteWidget, NestedWidget, QuickShareWidget, RecentActivityWidget, SpacerWidget, TableWidget, TextWidget, ToDoWidget, VideoWidget, alertWidgetPropertySchema, calendarWidgetPropertySchema, carouselWidgetPropertySchema, catchUpWidgetPropertySchema, chartWidgetPropertySchema, containerWidgetPropertySchema, embedWidgetPropertySchema, imageWidgetPropertySchema, layoutWidgetPropertySchema, listWidgetPropertySchema, mySiteWidgetPropertySchema, nestedWidgetPropertySchema, quickShareWidgetPropertySchema, recentActivityWidgetPropertySchema, spacerWidgetPropertySchema, tableWidgetPropertySchema, textWidgetPropertySchema, toDoWidgetPropertySchema, videoWidgetPropertySchema, widgetPropertySchemas } from '@fluid-app/rep-widgets/widgets';
8
+ import * as _fluid_app_rep_core_registries from '@fluid-app/rep-core/registries';
9
+ import { WidgetPropertySchema } from '@fluid-app/rep-core/registries';
10
+ export { PROPERTY_FIELD_TYPES, PropertyFieldSchema, PropertyFieldType, TabConfig, WidgetPropertySchema, gapValues, isPropertyFieldType } from '@fluid-app/rep-core/registries';
11
+ export { createScreen, createWidgetFromShareable, createWidgetRegistry, groupChildrenByColumn } from '@fluid-app/rep-core/widget-utils';
12
+
13
+ /**
14
+ * Rep (sales representative) user profile
15
+ */
16
+ interface Rep {
17
+ readonly id: string;
18
+ email: string;
19
+ first_name: string;
20
+ last_name: string;
21
+ avatar_url?: string;
22
+ phone?: string;
23
+ readonly company_id: string;
24
+ readonly created_at: string;
25
+ readonly updated_at: string;
26
+ }
27
+ /**
28
+ * Data for updating a rep's profile
29
+ */
30
+ interface UpdateRepData {
31
+ first_name?: string;
32
+ last_name?: string;
33
+ avatar_url?: string;
34
+ phone?: string;
35
+ }
36
+
37
+ /**
38
+ * Category for organizing page templates in the registry
39
+ */
40
+ interface PageCategory {
41
+ /** Unique identifier for the category */
42
+ readonly id: string;
43
+ /** Display label */
44
+ label: string;
45
+ /** Icon identifier (e.g., lucide icon name) */
46
+ icon?: string;
47
+ }
48
+ /**
49
+ * A reusable page template that can be shared across multiple navigations
50
+ */
51
+ interface PageTemplate {
52
+ /** Unique identifier for the template */
53
+ readonly id: string;
54
+ /** URL-friendly slug */
55
+ slug: string;
56
+ /** Display name */
57
+ name: string;
58
+ /** Description of the template's purpose */
59
+ description?: string;
60
+ /** Category ID for organization */
61
+ category: string;
62
+ /** Tags for filtering and search */
63
+ tags?: readonly string[];
64
+ /** The widget tree that defines the page content */
65
+ component_tree: readonly WidgetSchema[];
66
+ /** Semantic version of the template */
67
+ version: string;
68
+ /** Whether this is a core feature that cannot be removed */
69
+ isCore?: boolean;
70
+ /** Default prop values that can be customized */
71
+ defaultProps?: Readonly<Record<string, unknown>>;
72
+ /** Thumbnail image URL for UI display */
73
+ thumbnail?: string;
74
+ }
75
+ /**
76
+ * Reference to a shared page template within a navigation
77
+ */
78
+ interface PageReference {
79
+ /** ID of the page template being referenced */
80
+ page_template_id: string;
81
+ /** Screen ID to assign to this page in the navigation */
82
+ screen_id: number;
83
+ /** Optional prop overrides (only prop values, not widget structure) */
84
+ overrides?: readonly PageOverride[];
85
+ }
86
+ /**
87
+ * Override for a specific widget's props within a page template
88
+ */
89
+ interface PageOverride {
90
+ /** ID of the widget to override (must match WidgetSchema.id in the template) */
91
+ readonly widget_id: string;
92
+ /** Props to override (merged with original props) */
93
+ props: Readonly<Record<string, unknown>>;
94
+ }
95
+ /**
96
+ * Built-in page category IDs
97
+ */
98
+ declare const PAGE_CATEGORIES: {
99
+ readonly CORE: "core";
100
+ readonly COMMERCE: "commerce";
101
+ readonly COMMUNICATION: "communication";
102
+ readonly DATA: "data";
103
+ readonly CUSTOM: "custom";
104
+ };
105
+ type PageCategoryId = (typeof PAGE_CATEGORIES)[keyof typeof PAGE_CATEGORIES];
106
+
107
+ /**
108
+ * Navigation item in the sidebar/menu structure
109
+ */
110
+ interface NavigationItem {
111
+ /** Database-generated identifier */
112
+ readonly id?: number;
113
+ /** URL slug for routing */
114
+ slug?: string;
115
+ /** Display label */
116
+ label: string;
117
+ /** Icon identifier (e.g., FontAwesome name) */
118
+ icon?: string;
119
+ /** Associated screen ID */
120
+ screen_id?: number;
121
+ /** Sort order */
122
+ position?: number;
123
+ /** Parent navigation item ID (null for root items) */
124
+ parent_id?: number | null;
125
+ /** Nested navigation items */
126
+ children: NavigationItem[];
127
+ }
128
+ /**
129
+ * Screen definition with its component tree
130
+ */
131
+ interface ScreenDefinition {
132
+ readonly id: number;
133
+ slug: string;
134
+ name: string;
135
+ component_tree: WidgetSchema[];
136
+ }
137
+ /**
138
+ * Navigation configuration for the rep portal
139
+ */
140
+ interface Navigation {
141
+ readonly definition_id: number;
142
+ readonly id: number;
143
+ name: string;
144
+ navigation_items: NavigationItem[];
145
+ /** Local screen definitions (for backwards compatibility and custom screens) */
146
+ screens: ScreenDefinition[];
147
+ /** References to shared page templates from the registry */
148
+ page_refs?: PageReference[];
149
+ }
150
+
151
+ /**
152
+ * Rep portal profile containing themes and navigation configuration
153
+ */
154
+ interface Profile {
155
+ /** Profile name */
156
+ name: string;
157
+ /** Available themes for the portal */
158
+ themes: Theme[];
159
+ /** Navigation structure and screens */
160
+ navigation: Navigation;
161
+ /** Portal definition ID */
162
+ readonly definition_id: number;
163
+ }
164
+
165
+ /**
166
+ * Standard permission action constants.
167
+ * Use these constants instead of string literals for type safety.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * if (permissions[PERMISSION_ACTIONS.view]) { ... }
172
+ * ```
173
+ */
174
+ declare const PERMISSION_ACTIONS: {
175
+ readonly view: "view";
176
+ readonly create: "create";
177
+ readonly update: "update";
178
+ readonly delete: "delete";
179
+ readonly settings: "settings";
180
+ readonly add: "add";
181
+ readonly manage: "manage";
182
+ readonly send: "send";
183
+ };
184
+ /**
185
+ * Union type of standard permission actions.
186
+ * Derived from PERMISSION_ACTIONS constant to avoid duplication.
187
+ */
188
+ type PermissionAction = (typeof PERMISSION_ACTIONS)[keyof typeof PERMISSION_ACTIONS];
189
+ /**
190
+ * Permission flags for a single resource.
191
+ * Known actions have explicit properties; index signature allows custom actions.
192
+ */
193
+ interface ResourcePermissions {
194
+ readonly view?: boolean;
195
+ readonly create?: boolean;
196
+ readonly update?: boolean;
197
+ readonly delete?: boolean;
198
+ readonly settings?: boolean;
199
+ readonly add?: boolean;
200
+ readonly manage?: boolean;
201
+ readonly send?: boolean;
202
+ /** Allow custom action keys beyond the standard set */
203
+ readonly [key: string]: boolean | undefined;
204
+ }
205
+ /**
206
+ * Map of resource names to their permissions
207
+ */
208
+ type Permissions = Record<string, ResourcePermissions>;
209
+ /**
210
+ * User's complete permission profile
211
+ */
212
+ interface UserPermissions {
213
+ /** Resource permission mappings */
214
+ permissions: Permissions;
215
+ /** User's assigned roles */
216
+ roles: readonly string[];
217
+ /** Super admin bypass flag */
218
+ is_super_admin: boolean;
219
+ }
220
+
221
+ /**
222
+ * HTTP methods supported by the API client.
223
+ * Use `as const` for literal type inference and type safety.
224
+ */
225
+ declare const HTTP_METHODS: {
226
+ readonly GET: "GET";
227
+ readonly POST: "POST";
228
+ readonly PUT: "PUT";
229
+ readonly PATCH: "PATCH";
230
+ readonly DELETE: "DELETE";
231
+ };
232
+ /**
233
+ * Union type of all supported HTTP methods.
234
+ * Derived from HTTP_METHODS constant to avoid duplication.
235
+ */
236
+ type HttpMethod = (typeof HTTP_METHODS)[keyof typeof HTTP_METHODS];
237
+ /**
238
+ * Configuration for the Fluid SDK client.
239
+ * Use Readonly<FluidSDKConfig> when the config should not be modified after creation.
240
+ */
241
+ interface FluidSDKConfig {
242
+ /**
243
+ * Base URL for all API requests (e.g., "https://api.fluid.app/api")
244
+ */
245
+ readonly baseUrl: string;
246
+ /**
247
+ * Function to retrieve the authentication token
248
+ * Return null/undefined if no token is available
249
+ */
250
+ readonly getAuthToken?: () => string | null | Promise<string | null>;
251
+ /**
252
+ * Callback invoked when a 401 authentication error occurs
253
+ * Use this to trigger re-authentication flows
254
+ */
255
+ readonly onAuthError?: () => void;
256
+ /**
257
+ * Default headers to include in all requests
258
+ * Example: { "x-fluid-client": "rep-portal" }
259
+ */
260
+ readonly defaultHeaders?: Readonly<Record<string, string>>;
261
+ }
262
+ /**
263
+ * Options for individual API requests.
264
+ * Uses HttpMethod type for method to ensure type safety.
265
+ */
266
+ interface RequestOptions {
267
+ readonly method?: HttpMethod;
268
+ readonly body?: unknown;
269
+ readonly params?: Readonly<Record<string, unknown>>;
270
+ readonly headers?: Readonly<Record<string, string>>;
271
+ readonly signal?: AbortSignal;
272
+ }
273
+ /**
274
+ * Pagination parameters for list endpoints
275
+ */
276
+ interface PaginationParams {
277
+ readonly page?: number;
278
+ readonly per_page?: number;
279
+ }
280
+ /**
281
+ * Sort order constant - single source of truth for sort direction values.
282
+ * Use SORT_ORDERS.asc instead of "asc" for type-safe comparisons.
283
+ */
284
+ declare const SORT_ORDERS: {
285
+ readonly asc: "asc";
286
+ readonly desc: "desc";
287
+ };
288
+ /**
289
+ * Union type of sort order values, derived from SORT_ORDERS constant.
290
+ * @see deriving-typeof-for-object-keys pattern
291
+ */
292
+ type SortOrder = (typeof SORT_ORDERS)[keyof typeof SORT_ORDERS];
293
+ /**
294
+ * Common filter parameters for list endpoints
295
+ */
296
+ interface BaseListParams extends PaginationParams {
297
+ readonly sort_by?: string;
298
+ readonly sort_order?: SortOrder;
299
+ readonly search?: string;
300
+ }
301
+
302
+ /**
303
+ * Fluid API Client
304
+ * Adapted from: packages/fluidos-api-client/src/lib/fetch-client.ts
305
+ * Provides authenticated API access with domain-specific methods
306
+ */
307
+
308
+ /**
309
+ * API Error class for structured error handling
310
+ */
311
+ declare class ApiError extends Error {
312
+ readonly status: number;
313
+ readonly data: unknown;
314
+ constructor(message: string, status: number, data?: unknown);
315
+ toJSON(): {
316
+ name: string;
317
+ message: string;
318
+ status: number;
319
+ data: unknown;
320
+ };
321
+ }
322
+ /**
323
+ * Type guard for ApiError
324
+ */
325
+ declare function isApiError(error: unknown): error is ApiError;
326
+ /**
327
+ * Discriminated union representing the result of an API call.
328
+ * Use `isApiSuccess` and `isApiFailure` type guards to narrow.
329
+ */
330
+ type ApiResult<T> = {
331
+ readonly success: true;
332
+ readonly data: T;
333
+ } | {
334
+ readonly success: false;
335
+ readonly error: ApiError;
336
+ };
337
+ interface Product {
338
+ readonly id: number;
339
+ readonly title: string;
340
+ readonly sku?: string | null;
341
+ readonly price: string | number;
342
+ readonly description?: string | null;
343
+ readonly image_url?: string;
344
+ readonly status?: string;
345
+ readonly active?: boolean;
346
+ readonly slug?: string;
347
+ readonly in_stock?: boolean;
348
+ readonly display_price?: string;
349
+ readonly currency_code?: string;
350
+ readonly updated_at?: string;
351
+ }
352
+ interface ProductListParams extends BaseListParams {
353
+ readonly search_query?: string;
354
+ readonly status?: readonly ("active" | "draft" | "archived" | "all")[];
355
+ readonly category_id?: string;
356
+ readonly category_ids?: readonly number[];
357
+ readonly collection_id?: string;
358
+ readonly collection_ids?: readonly number[];
359
+ readonly order_by?: readonly string[];
360
+ readonly country_code?: readonly string[];
361
+ readonly published_stores?: readonly ("retail" | "rep")[];
362
+ }
363
+ interface ProductsResponse {
364
+ readonly products: readonly Product[];
365
+ readonly meta: {
366
+ readonly request_id: string;
367
+ readonly timestamp: string;
368
+ readonly pagination?: {
369
+ readonly current_page: number;
370
+ readonly per_page: number;
371
+ readonly total_pages: number;
372
+ readonly total_count: number;
373
+ };
374
+ };
375
+ }
376
+ interface Order {
377
+ readonly id: string;
378
+ readonly order_number: string;
379
+ readonly status: string;
380
+ readonly total: number;
381
+ readonly customer_id: string;
382
+ readonly rep_id?: string;
383
+ readonly created_at: string;
384
+ readonly updated_at: string;
385
+ }
386
+ interface OrderListParams extends BaseListParams {
387
+ readonly status?: string;
388
+ readonly customer_id?: string;
389
+ readonly date_from?: string;
390
+ readonly date_to?: string;
391
+ }
392
+ interface CreateOrderData {
393
+ readonly customer_id: string;
394
+ readonly line_items: readonly OrderLineItem[];
395
+ readonly notes?: string;
396
+ }
397
+ interface OrderLineItem {
398
+ readonly product_id: string;
399
+ readonly quantity: number;
400
+ readonly price?: number;
401
+ }
402
+ interface DashboardData {
403
+ readonly total_sales: number;
404
+ readonly total_orders: number;
405
+ readonly total_customers: number;
406
+ readonly recent_orders: readonly Order[];
407
+ }
408
+ interface SalesParams {
409
+ readonly date_from?: string;
410
+ readonly date_to?: string;
411
+ readonly group_by?: "day" | "week" | "month";
412
+ }
413
+ interface SalesData {
414
+ readonly total: number;
415
+ readonly data: readonly SalesDataPoint[];
416
+ }
417
+ interface SalesDataPoint {
418
+ readonly date: string;
419
+ readonly amount: number;
420
+ readonly orders: number;
421
+ }
422
+ /**
423
+ * Creates a configured Fluid API client instance
424
+ */
425
+ declare function createFluidClient(config: FluidSDKConfig): {
426
+ request: <TResponse = unknown>(endpoint: string, options?: RequestOptions) => Promise<TResponse>;
427
+ requestNullable: <TResponse>(endpoint: string, options?: RequestOptions) => Promise<TResponse | null>;
428
+ safeRequest: <TResponse>(endpoint: string, options?: RequestOptions) => Promise<ApiResult<TResponse>>;
429
+ get: <TResponse = unknown, TParams extends object = Record<string, unknown>>(endpoint: string, params?: TParams, options?: Omit<RequestOptions, "method" | "params">) => Promise<TResponse>;
430
+ post: <TResponse = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, "method" | "body">) => Promise<TResponse>;
431
+ put: <TResponse = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, "method" | "body">) => Promise<TResponse>;
432
+ patch: <TResponse = unknown>(endpoint: string, body?: unknown, options?: Omit<RequestOptions, "method" | "body">) => Promise<TResponse>;
433
+ delete: <TResponse = unknown>(endpoint: string, options?: Omit<RequestOptions, "method">) => Promise<TResponse>;
434
+ products: {
435
+ list: (params?: ProductListParams) => Promise<ProductsResponse>;
436
+ get: (id: string | number) => Promise<{
437
+ product: Product;
438
+ }>;
439
+ search: (query: string, params?: ProductListParams) => Promise<ProductsResponse>;
440
+ };
441
+ orders: {
442
+ list: (params?: OrderListParams) => Promise<Order[]>;
443
+ get: (id: string) => Promise<Order>;
444
+ create: (data: CreateOrderData) => Promise<Order>;
445
+ };
446
+ reps: {
447
+ current: () => Promise<Rep>;
448
+ updateProfile: (data: UpdateRepData) => Promise<Rep>;
449
+ };
450
+ profile: {
451
+ get: () => Promise<Profile>;
452
+ };
453
+ permissions: {
454
+ get: () => Promise<UserPermissions>;
455
+ };
456
+ analytics: {
457
+ dashboard: () => Promise<DashboardData>;
458
+ sales: (params?: SalesParams) => Promise<SalesData>;
459
+ };
460
+ };
461
+ type FluidClient = ReturnType<typeof createFluidClient>;
462
+
463
+ /**
464
+ * Context value for FluidProvider.
465
+ * All properties are readonly since context values should not be mutated by consumers.
466
+ */
467
+ interface FluidContextValue {
468
+ /** Configured API client instance */
469
+ readonly client: FluidClient;
470
+ /** SDK configuration */
471
+ readonly config: FluidSDKConfig;
472
+ }
473
+ interface FluidProviderProps {
474
+ /** SDK configuration (baseUrl, auth, etc.) */
475
+ config: FluidSDKConfig;
476
+ /** React children */
477
+ children: ReactNode;
478
+ /** Optional custom QueryClient instance */
479
+ queryClient?: QueryClient;
480
+ /** Optional initial theme */
481
+ initialTheme?: Theme;
482
+ /** Optional container for scoped theme application */
483
+ themeContainer?: HTMLElement | null;
484
+ }
485
+ /**
486
+ * Main provider for the Fluid Rep SDK
487
+ *
488
+ * @example
489
+ * ```tsx
490
+ * import { FluidProvider } from "@fluid-app/rep-sdk";
491
+ *
492
+ * function App() {
493
+ * return (
494
+ * <FluidProvider
495
+ * config={{
496
+ * baseUrl: "https://api.fluid.app/api",
497
+ * getAuthToken: () => localStorage.getItem("token"),
498
+ * }}
499
+ * >
500
+ * <YourApp />
501
+ * </FluidProvider>
502
+ * );
503
+ * }
504
+ * ```
505
+ */
506
+ declare function FluidProvider({ config, children, queryClient, initialTheme, themeContainer, }: FluidProviderProps): react_jsx_runtime.JSX.Element;
507
+ /**
508
+ * Hook to access the Fluid context
509
+ * Must be used within a FluidProvider
510
+ */
511
+ declare function useFluidContext(): FluidContextValue;
512
+
513
+ /**
514
+ * Context value for theme management.
515
+ * All properties are readonly since context values should not be mutated by consumers.
516
+ */
517
+ interface ThemeContextValue {
518
+ /** Currently active theme */
519
+ readonly currentTheme: Theme | null;
520
+ /** Switch to a different theme */
521
+ readonly setTheme: (theme: Theme) => void;
522
+ /** Switch between light and dark mode for the current theme */
523
+ readonly setThemeMode: (mode: "light" | "dark") => void;
524
+ }
525
+ interface FluidThemeProviderProps {
526
+ children: ReactNode;
527
+ /** Initial theme to apply */
528
+ initialTheme?: Theme;
529
+ /** Container element for scoped theme application (defaults to document.documentElement) */
530
+ container?: HTMLElement | null;
531
+ }
532
+ declare function FluidThemeProvider({ children, initialTheme, container, }: FluidThemeProviderProps): react_jsx_runtime.JSX.Element;
533
+ /**
534
+ * Hook to access theme context
535
+ * Must be used within a FluidThemeProvider
536
+ */
537
+ declare function useThemeContext(): ThemeContextValue;
538
+
539
+ /**
540
+ * Auth Types for Fluid Rep SDK
541
+ *
542
+ * These types define the JWT payload structure and authentication
543
+ * configuration options for rep portal applications.
544
+ */
545
+ /**
546
+ * User type constant - single source of truth for user role values.
547
+ * Use USER_TYPES.admin instead of "admin" for type-safe comparisons.
548
+ */
549
+ declare const USER_TYPES: {
550
+ readonly admin: "admin";
551
+ readonly rep: "rep";
552
+ readonly root_admin: "root_admin";
553
+ readonly customer: "customer";
554
+ };
555
+ /**
556
+ * Union type of all user types, derived from USER_TYPES constant.
557
+ * @see deriving-typeof-for-object-keys pattern
558
+ */
559
+ type UserType = (typeof USER_TYPES)[keyof typeof USER_TYPES];
560
+ /**
561
+ * Runtime validation for user types.
562
+ * @param value - The value to check
563
+ * @returns true if value is a valid UserType
564
+ */
565
+ declare function isUserType(value: string): value is UserType;
566
+ /**
567
+ * JWT payload structure from Fluid Commerce authentication.
568
+ * Contains user identity and role information.
569
+ */
570
+ interface JWTPayload {
571
+ /** User ID */
572
+ id?: number | undefined;
573
+ /** User email address */
574
+ email?: string | undefined;
575
+ /** Full name of the user */
576
+ full_name?: string | undefined;
577
+ /** User role type */
578
+ user_type: UserType;
579
+ /** Original user type (for impersonation scenarios) */
580
+ og_user_type?: UserType | undefined;
581
+ /** Company ID the user belongs to */
582
+ company_id?: number | undefined;
583
+ /** Token expiration timestamp (Unix seconds) */
584
+ exp?: number | undefined;
585
+ /** Authentication type (e.g., "standard", "impersonation") */
586
+ auth_type?: string | undefined;
587
+ }
588
+ /**
589
+ * Configuration options for FluidAuthProvider.
590
+ * All options have sensible defaults.
591
+ */
592
+ interface FluidAuthConfig {
593
+ /**
594
+ * URL parameter name for the auth token.
595
+ * @default "fluidUserToken"
596
+ */
597
+ tokenKey?: string;
598
+ /**
599
+ * Cookie name for storing the auth token.
600
+ * @default "auth_token"
601
+ */
602
+ cookieKey?: string;
603
+ /**
604
+ * Cookie max age in seconds.
605
+ * @default 777600 (9 days)
606
+ */
607
+ cookieMaxAge?: number;
608
+ /**
609
+ * Grace period in milliseconds to account for clock skew
610
+ * when checking token expiration.
611
+ * @default 30000 (30 seconds)
612
+ */
613
+ gracePeriodMs?: number;
614
+ /**
615
+ * Callback invoked when authentication fails (no valid token).
616
+ * Use this to redirect to a login page or show an error.
617
+ */
618
+ onAuthFailure?: () => void;
619
+ /**
620
+ * Enable dev-mode auth bypass.
621
+ * When true AND running in Vite dev mode (import.meta.env.DEV),
622
+ * auth will use a synthetic mock user instead of requiring a real JWT.
623
+ * The mock user allows UI rendering but API calls will fail (token is null).
624
+ * @default false
625
+ */
626
+ devBypass?: boolean;
627
+ /**
628
+ * JWKS (JSON Web Key Set) URL for signature verification.
629
+ * When provided, JWT signatures will be verified against keys
630
+ * from this endpoint before accepting the token.
631
+ *
632
+ * This provides defense-in-depth client-side verification.
633
+ * Without this, tokens are only decoded (not verified) client-side,
634
+ * and real verification happens server-side on API calls.
635
+ *
636
+ * @example "https://api.fluid.app/.well-known/jwks.json"
637
+ */
638
+ jwksUrl?: string;
639
+ }
640
+ /**
641
+ * Value provided by the FluidAuthContext.
642
+ * All properties are readonly since context values should not be mutated by consumers.
643
+ */
644
+ interface FluidAuthContextValue {
645
+ /** Whether the user is authenticated with a valid token */
646
+ readonly isAuthenticated: boolean;
647
+ /** Whether authentication is still being initialized */
648
+ readonly isLoading: boolean;
649
+ /** Decoded JWT payload if authenticated, null otherwise */
650
+ readonly user: JWTPayload | null;
651
+ /** Raw JWT token string if authenticated, null otherwise */
652
+ readonly token: string | null;
653
+ /** Clear authentication state and stored tokens */
654
+ readonly clearAuth: () => void;
655
+ /** Authentication error if any occurred during initialization */
656
+ readonly error: Error | null;
657
+ }
658
+ /**
659
+ * Result of token validation.
660
+ * Uses a discriminated union for type-safe handling of valid/invalid states.
661
+ */
662
+ type TokenValidationResult = {
663
+ /** Token is valid */
664
+ isValid: true;
665
+ /** Decoded JWT payload */
666
+ payload: JWTPayload;
667
+ /** No error when valid */
668
+ error?: undefined;
669
+ } | {
670
+ /** Token is invalid */
671
+ isValid: false;
672
+ /** Decoded JWT payload if parseable but expired */
673
+ payload?: JWTPayload;
674
+ /** Error message explaining why validation failed */
675
+ error: string;
676
+ };
677
+
678
+ interface FluidAuthProviderProps {
679
+ /** React children to wrap with auth context */
680
+ children: ReactNode;
681
+ /** Auth configuration options */
682
+ config?: FluidAuthConfig;
683
+ }
684
+ /**
685
+ * Authentication provider for Fluid rep portal applications.
686
+ *
687
+ * On mount, this provider:
688
+ * 1. Checks for a token in the URL (passed from parent app)
689
+ * 2. Cleans token from URL immediately (security)
690
+ * 3. Falls back to stored token (cookie/localStorage)
691
+ * 4. Validates the token (checks expiration)
692
+ * 5. Stores valid tokens for future use
693
+ * 6. Calls onAuthFailure if no valid token found
694
+ *
695
+ * @example
696
+ * ```tsx
697
+ * import { FluidAuthProvider } from "@fluid-app/rep-sdk";
698
+ *
699
+ * function App() {
700
+ * return (
701
+ * <FluidAuthProvider
702
+ * config={{
703
+ * onAuthFailure: () => {
704
+ * window.location.href = "/login";
705
+ * },
706
+ * }}
707
+ * >
708
+ * <YourApp />
709
+ * </FluidAuthProvider>
710
+ * );
711
+ * }
712
+ * ```
713
+ */
714
+ declare function FluidAuthProvider({ children, config, }: FluidAuthProviderProps): react_jsx_runtime.JSX.Element;
715
+ /**
716
+ * Hook to access the auth context directly.
717
+ * Prefer using `useFluidAuth` for most use cases.
718
+ *
719
+ * @throws Error if used outside FluidAuthProvider
720
+ */
721
+ declare function useFluidAuthContext(): FluidAuthContextValue;
722
+
723
+ /**
724
+ * Screen Types - Type definitions for core feature screens
725
+ *
726
+ * All status and type unions are derived from constants for single source of truth.
727
+ * Use the constants (e.g., CONVERSATION_STATUSES.active) for type-safe comparisons.
728
+ */
729
+ /**
730
+ * Conversation status constant - single source of truth.
731
+ */
732
+ declare const CONVERSATION_STATUSES: {
733
+ readonly active: "active";
734
+ readonly archived: "archived";
735
+ readonly muted: "muted";
736
+ };
737
+ /**
738
+ * Union type derived from CONVERSATION_STATUSES constant.
739
+ */
740
+ type ConversationStatus = (typeof CONVERSATION_STATUSES)[keyof typeof CONVERSATION_STATUSES];
741
+ /**
742
+ * Message type constant - single source of truth.
743
+ */
744
+ declare const MESSAGE_TYPES: {
745
+ readonly text: "text";
746
+ readonly image: "image";
747
+ readonly file: "file";
748
+ readonly system: "system";
749
+ };
750
+ /**
751
+ * Union type derived from MESSAGE_TYPES constant.
752
+ */
753
+ type MessageType = (typeof MESSAGE_TYPES)[keyof typeof MESSAGE_TYPES];
754
+ interface Participant {
755
+ readonly id: string;
756
+ readonly name: string;
757
+ readonly email: string;
758
+ readonly avatarUrl?: string;
759
+ readonly isOnline?: boolean;
760
+ }
761
+ /**
762
+ * Message attachment type - extracted for reusability and clarity.
763
+ */
764
+ interface MessageAttachment {
765
+ readonly id: string;
766
+ readonly name: string;
767
+ readonly url: string;
768
+ readonly type: string;
769
+ readonly size?: number;
770
+ }
771
+ interface Message {
772
+ readonly id: string;
773
+ readonly conversationId: string;
774
+ readonly senderId: string;
775
+ readonly senderName: string;
776
+ readonly senderAvatarUrl?: string;
777
+ readonly type: MessageType;
778
+ readonly content: string;
779
+ readonly timestamp: string;
780
+ readonly isRead: boolean;
781
+ readonly attachments?: readonly MessageAttachment[];
782
+ }
783
+ interface Conversation {
784
+ readonly id: string;
785
+ readonly title: string;
786
+ readonly participants: readonly Participant[];
787
+ readonly lastMessage?: Message;
788
+ readonly unreadCount: number;
789
+ readonly status: ConversationStatus;
790
+ readonly createdAt: string;
791
+ readonly updatedAt: string;
792
+ }
793
+ /**
794
+ * Contact status constant - single source of truth.
795
+ */
796
+ declare const CONTACT_STATUSES: {
797
+ readonly active: "active";
798
+ readonly inactive: "inactive";
799
+ readonly lead: "lead";
800
+ readonly prospect: "prospect";
801
+ };
802
+ /**
803
+ * Union type derived from CONTACT_STATUSES constant.
804
+ */
805
+ type ContactStatus = (typeof CONTACT_STATUSES)[keyof typeof CONTACT_STATUSES];
806
+ /**
807
+ * Contact type constant - single source of truth.
808
+ */
809
+ declare const CONTACT_TYPES: {
810
+ readonly individual: "individual";
811
+ readonly company: "company";
812
+ };
813
+ /**
814
+ * Union type derived from CONTACT_TYPES constant.
815
+ */
816
+ type ContactType = (typeof CONTACT_TYPES)[keyof typeof CONTACT_TYPES];
817
+ interface ContactAddress {
818
+ readonly street?: string;
819
+ readonly city?: string;
820
+ readonly state?: string;
821
+ readonly postalCode?: string;
822
+ readonly country?: string;
823
+ }
824
+ interface Contact {
825
+ readonly id: string;
826
+ readonly firstName: string;
827
+ readonly lastName: string;
828
+ readonly email: string;
829
+ readonly phone?: string;
830
+ readonly company?: string;
831
+ readonly jobTitle?: string;
832
+ readonly avatarUrl?: string;
833
+ readonly status: ContactStatus;
834
+ readonly type: ContactType;
835
+ readonly address?: ContactAddress;
836
+ readonly tags?: readonly string[];
837
+ readonly notes?: string;
838
+ readonly createdAt: string;
839
+ readonly updatedAt: string;
840
+ }
841
+
842
+ /**
843
+ * Context value for page template resolution.
844
+ * All properties are readonly since context values should not be mutated by consumers.
845
+ */
846
+ interface PageTemplateContextValue {
847
+ /**
848
+ * Resolve a navigation's page_refs and screens into a unified screen list
849
+ */
850
+ readonly resolvePages: (navigation: Navigation) => ScreenDefinition[];
851
+ /**
852
+ * Get all available page templates
853
+ */
854
+ readonly listTemplates: () => PageTemplate[];
855
+ /**
856
+ * Get a specific template by ID
857
+ */
858
+ readonly getTemplate: (id: string) => PageTemplate | undefined;
859
+ /**
860
+ * Check if a template exists
861
+ */
862
+ readonly hasTemplate: (id: string) => boolean;
863
+ }
864
+ /**
865
+ * Props for PageTemplateProvider
866
+ */
867
+ interface PageTemplateProviderProps {
868
+ children: React.ReactNode;
869
+ /**
870
+ * Additional custom page templates to register.
871
+ * These are registered when the provider mounts and unregistered when it unmounts.
872
+ */
873
+ templates?: readonly PageTemplate[];
874
+ }
875
+ /**
876
+ * Provider for page template resolution.
877
+ *
878
+ * This provider:
879
+ * 1. Registers any custom templates passed via props
880
+ * 2. Provides methods for resolving navigation pages
881
+ * 3. Cleans up custom templates on unmount
882
+ *
883
+ * @example
884
+ * ```tsx
885
+ * // With custom templates
886
+ * const customTemplates: PageTemplate[] = [
887
+ * {
888
+ * id: 'custom-dashboard',
889
+ * slug: 'dashboard',
890
+ * name: 'Dashboard',
891
+ * category: 'custom',
892
+ * version: '1.0.0',
893
+ * component_tree: [{ type: 'TextWidget', props: { text: 'Custom Dashboard' } }],
894
+ * },
895
+ * ];
896
+ *
897
+ * <PageTemplateProvider templates={customTemplates}>
898
+ * <App />
899
+ * </PageTemplateProvider>
900
+ *
901
+ * // Without custom templates (uses only core templates)
902
+ * <PageTemplateProvider>
903
+ * <App />
904
+ * </PageTemplateProvider>
905
+ * ```
906
+ */
907
+ declare function PageTemplateProvider({ children, templates, }: PageTemplateProviderProps): react_jsx_runtime.JSX.Element;
908
+ /**
909
+ * Hook to access page template functionality.
910
+ *
911
+ * @throws Error if used outside of PageTemplateProvider
912
+ *
913
+ * @example
914
+ * ```tsx
915
+ * function NavigationRenderer({ navigation }: { navigation: Navigation }) {
916
+ * const { resolvePages } = usePageTemplates();
917
+ * const screens = resolvePages(navigation);
918
+ *
919
+ * return (
920
+ * <div>
921
+ * {screens.map((screen) => (
922
+ * <Screen key={screen.id} definition={screen} />
923
+ * ))}
924
+ * </div>
925
+ * );
926
+ * }
927
+ * ```
928
+ */
929
+ declare function usePageTemplates(): PageTemplateContextValue;
930
+ /**
931
+ * Hook to resolve navigation pages directly.
932
+ * Convenience wrapper around usePageTemplates().resolvePages.
933
+ *
934
+ * @param navigation - The navigation to resolve
935
+ * @returns Array of resolved screen definitions
936
+ */
937
+ declare function useResolvedPages(navigation: Navigation): ScreenDefinition[];
938
+
939
+ /**
940
+ * Hook to access the Fluid API client
941
+ *
942
+ * @example
943
+ * ```tsx
944
+ * function ProductList() {
945
+ * const api = useFluidApi();
946
+ *
947
+ * const { data: products } = useQuery({
948
+ * queryKey: ["products"],
949
+ * queryFn: () => api.products.list(),
950
+ * });
951
+ *
952
+ * return <ul>{products?.map(p => <li key={p.id}>{p.name}</li>)}</ul>;
953
+ * }
954
+ * ```
955
+ */
956
+ declare function useFluidApi(): FluidClient;
957
+
958
+ /**
959
+ * Query key for profile data
960
+ */
961
+ declare const PROFILE_QUERY_KEY: readonly ["fluid", "profile"];
962
+ /**
963
+ * Hook to fetch the rep portal profile (themes, navigation, screens)
964
+ *
965
+ * @example
966
+ * ```tsx
967
+ * function Navigation() {
968
+ * const { data: profile, isLoading } = useFluidProfile();
969
+ *
970
+ * if (isLoading) return <Spinner />;
971
+ *
972
+ * return (
973
+ * <nav>
974
+ * {profile?.navigation.navigation_items.map(item => (
975
+ * <NavItem key={item.id} item={item} />
976
+ * ))}
977
+ * </nav>
978
+ * );
979
+ * }
980
+ * ```
981
+ */
982
+ declare function useFluidProfile(): UseQueryResult<Profile>;
983
+
984
+ /**
985
+ * Query key for permissions data
986
+ */
987
+ declare const PERMISSIONS_QUERY_KEY: readonly ["fluid", "permissions"];
988
+ /**
989
+ * Result of useFluidPermissions hook
990
+ */
991
+ interface UseFluidPermissionsResult {
992
+ /** Raw permissions query result */
993
+ query: UseQueryResult<UserPermissions>;
994
+ /** Permissions data (alias for query.data) */
995
+ permissions: UserPermissions | undefined;
996
+ /** Check if user has a specific permission */
997
+ can: (resource: string, action?: PermissionAction) => boolean;
998
+ /** Check if user is a super admin */
999
+ isSuperAdmin: boolean;
1000
+ }
1001
+ /**
1002
+ * Hook to fetch and check user permissions
1003
+ *
1004
+ * @example
1005
+ * ```tsx
1006
+ * function TeamSettings() {
1007
+ * const { can, isSuperAdmin } = useFluidPermissions();
1008
+ *
1009
+ * if (!can("team", "manage")) {
1010
+ * return <AccessDenied />;
1011
+ * }
1012
+ *
1013
+ * return <TeamSettingsForm canDelete={can("team", "delete")} />;
1014
+ * }
1015
+ * ```
1016
+ */
1017
+ declare function useFluidPermissions(): UseFluidPermissionsResult;
1018
+
1019
+ /**
1020
+ * Result of useFluidTheme hook
1021
+ */
1022
+ interface UseFluidThemeResult {
1023
+ /** Currently active theme */
1024
+ currentTheme: Theme | null;
1025
+ /** Switch to a different theme */
1026
+ setTheme: (theme: Theme) => void;
1027
+ /** Switch between light and dark mode */
1028
+ setThemeMode: (mode: "light" | "dark") => void;
1029
+ /** Current theme mode (convenience accessor) */
1030
+ mode: "light" | "dark" | undefined;
1031
+ }
1032
+ /**
1033
+ * Hook to access and control theme settings
1034
+ *
1035
+ * @example
1036
+ * ```tsx
1037
+ * function ThemeSwitcher({ themes }: { themes: Theme[] }) {
1038
+ * const { currentTheme, setTheme, setThemeMode, mode } = useFluidTheme();
1039
+ *
1040
+ * return (
1041
+ * <div>
1042
+ * <select
1043
+ * value={currentTheme?.name}
1044
+ * onChange={(e) => {
1045
+ * const theme = themes.find(t => t.name === e.target.value);
1046
+ * if (theme) setTheme(theme);
1047
+ * }}
1048
+ * >
1049
+ * {themes.map(theme => (
1050
+ * <option key={theme.name} value={theme.name}>
1051
+ * {theme.name}
1052
+ * </option>
1053
+ * ))}
1054
+ * </select>
1055
+ *
1056
+ * <button onClick={() => setThemeMode(mode === "dark" ? "light" : "dark")}>
1057
+ * Toggle {mode === "dark" ? "Light" : "Dark"} Mode
1058
+ * </button>
1059
+ * </div>
1060
+ * );
1061
+ * }
1062
+ * ```
1063
+ */
1064
+ declare function useFluidTheme(): UseFluidThemeResult;
1065
+
1066
+ /**
1067
+ * Query key for current rep data
1068
+ */
1069
+ declare const CURRENT_REP_QUERY_KEY: readonly ["fluid", "currentRep"];
1070
+ /**
1071
+ * Hook to fetch the currently authenticated rep's profile
1072
+ *
1073
+ * @example
1074
+ * ```tsx
1075
+ * function RepHeader() {
1076
+ * const { data: rep, isLoading } = useCurrentRep();
1077
+ *
1078
+ * if (isLoading) return <Skeleton />;
1079
+ *
1080
+ * return (
1081
+ * <div>
1082
+ * <Avatar src={rep?.avatar_url} />
1083
+ * <span>{rep?.first_name} {rep?.last_name}</span>
1084
+ * </div>
1085
+ * );
1086
+ * }
1087
+ * ```
1088
+ */
1089
+ declare function useCurrentRep(): UseQueryResult<Rep>;
1090
+
1091
+ /**
1092
+ * useFluidAuth Hook
1093
+ *
1094
+ * Provides access to authentication state and utilities.
1095
+ * This is the primary hook for interacting with auth in components.
1096
+ */
1097
+
1098
+ /**
1099
+ * Hook to access authentication state and utilities.
1100
+ *
1101
+ * Must be used within a `FluidAuthProvider`.
1102
+ *
1103
+ * @returns Authentication context with user info, loading state, and utilities
1104
+ * @throws Error if used outside FluidAuthProvider
1105
+ *
1106
+ * @example
1107
+ * ```tsx
1108
+ * function UserProfile() {
1109
+ * const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();
1110
+ *
1111
+ * if (isLoading) {
1112
+ * return <Spinner />;
1113
+ * }
1114
+ *
1115
+ * if (!isAuthenticated) {
1116
+ * return <p>Please log in</p>;
1117
+ * }
1118
+ *
1119
+ * return (
1120
+ * <div>
1121
+ * <p>Welcome, {user.full_name}!</p>
1122
+ * <button onClick={clearAuth}>Log out</button>
1123
+ * </div>
1124
+ * );
1125
+ * }
1126
+ * ```
1127
+ */
1128
+ declare function useFluidAuth(): FluidAuthContextValue;
1129
+
1130
+ /**
1131
+ * Hook type utilities and type predicates.
1132
+ *
1133
+ * This module provides:
1134
+ * - Generic hook result types with default type parameters
1135
+ * - Type predicates for query state narrowing
1136
+ * - Reusable patterns for type-safe property access in hooks
1137
+ *
1138
+ * Following generics best practices:
1139
+ * - generics-default-type-parameters: Default E to Error for common case
1140
+ * - generics-type-predicates: Type predicates for result state narrowing
1141
+ * - generics-constrain-type-parameters: K extends keyof T for property access
1142
+ */
1143
+ /**
1144
+ * Base result type for query hooks with default error type.
1145
+ * Uses default type parameter for E (generics-default-type-parameters rule).
1146
+ *
1147
+ * @typeParam T - The data type
1148
+ * @typeParam E - The error type (defaults to Error)
1149
+ *
1150
+ * @example
1151
+ * // Error type defaults to Error
1152
+ * type UsersResult = QueryResult<User[]>;
1153
+ *
1154
+ * // Can override when needed
1155
+ * type CustomResult = QueryResult<User[], ApiError>;
1156
+ */
1157
+ interface QueryResult<T, E = Error> {
1158
+ readonly data: T;
1159
+ readonly isLoading: boolean;
1160
+ readonly isError: boolean;
1161
+ readonly error?: E | undefined;
1162
+ }
1163
+ /**
1164
+ * Result type for hooks that may not have data yet.
1165
+ * Extends QueryResult with nullable data.
1166
+ *
1167
+ * @typeParam T - The data type
1168
+ * @typeParam E - The error type (defaults to Error)
1169
+ */
1170
+ interface QueryResultNullable<T, E = Error> {
1171
+ readonly data: T | null | undefined;
1172
+ readonly isLoading: boolean;
1173
+ readonly isError: boolean;
1174
+ readonly error?: E | undefined;
1175
+ }
1176
+ /**
1177
+ * Result type for list/collection hooks with aggregates.
1178
+ *
1179
+ * @typeParam T - The item type in the array
1180
+ * @typeParam E - The error type (defaults to Error)
1181
+ */
1182
+ interface ListQueryResult<T, E = Error> extends QueryResult<T[], E> {
1183
+ readonly totalCount: number;
1184
+ }
1185
+ /**
1186
+ * Result type for list hooks with value aggregation (e.g., deals with total value).
1187
+ *
1188
+ * @typeParam T - The item type in the array
1189
+ * @typeParam E - The error type (defaults to Error)
1190
+ */
1191
+ interface ValueListQueryResult<T, E = Error> extends ListQueryResult<T, E> {
1192
+ readonly totalValue: number;
1193
+ }
1194
+ /**
1195
+ * Type predicate to check if a query result has successfully loaded data.
1196
+ * Narrows the data type from T | null | undefined to T.
1197
+ *
1198
+ * @example
1199
+ * const result = useContact(id);
1200
+ * if (hasData(result)) {
1201
+ * // TypeScript knows result.data is Contact, not Contact | null
1202
+ * console.log(result.data.name);
1203
+ * }
1204
+ */
1205
+ declare function hasData<T, E = Error>(result: QueryResultNullable<T, E>): result is QueryResultNullable<T, E> & {
1206
+ readonly data: T;
1207
+ };
1208
+ /**
1209
+ * Type predicate to check if a query result is in loading state.
1210
+ * Useful for conditional rendering.
1211
+ *
1212
+ * @example
1213
+ * if (isLoading(result)) {
1214
+ * return <Spinner />;
1215
+ * }
1216
+ */
1217
+ declare function isLoading<T, E = Error>(result: QueryResult<T, E> | QueryResultNullable<T, E>): boolean;
1218
+ /**
1219
+ * Type predicate to check if a query result has an error.
1220
+ * Narrows to include the error property.
1221
+ *
1222
+ * @example
1223
+ * if (isErrorResult(result)) {
1224
+ * console.error(result.error); // error is E, not undefined
1225
+ * }
1226
+ */
1227
+ declare function isErrorResult<T, E = Error>(result: QueryResult<T, E> | QueryResultNullable<T, E>): result is (QueryResult<T, E> | QueryResultNullable<T, E>) & {
1228
+ readonly isError: true;
1229
+ readonly error: E;
1230
+ };
1231
+ /**
1232
+ * Type predicate to check if a query result is in idle state (not loading, no error, has data).
1233
+ *
1234
+ * @example
1235
+ * if (isIdle(result)) {
1236
+ * // Safe to access and render data
1237
+ * }
1238
+ */
1239
+ declare function isIdle<T, E = Error>(result: QueryResult<T, E> | QueryResultNullable<T, E>): boolean;
1240
+ /**
1241
+ * Type-safe property selector for hook results.
1242
+ * Uses K extends keyof T constraint (generics-function-constraints rule).
1243
+ *
1244
+ * @typeParam T - The data object type
1245
+ * @typeParam K - Key of T (constrained to actual keys)
1246
+ *
1247
+ * @example
1248
+ * const users = [{ name: "Alice", age: 30 }];
1249
+ * const names = selectProperty(users, "name"); // string[]
1250
+ * const ages = selectProperty(users, "age"); // number[]
1251
+ * selectProperty(users, "invalid"); // Error: "invalid" not in "name" | "age"
1252
+ */
1253
+ declare function selectProperty<T, K extends keyof T>(items: readonly T[], key: K): T[K][];
1254
+ /**
1255
+ * Type-safe property getter for a single item.
1256
+ * Returns undefined if item is null/undefined.
1257
+ *
1258
+ * @typeParam T - The data object type
1259
+ * @typeParam K - Key of T (constrained to actual keys)
1260
+ */
1261
+ declare function getProperty<T, K extends keyof T>(item: T | null | undefined, key: K): T[K] | undefined;
1262
+ /**
1263
+ * Generic type for hooks that fetch a single resource by ID.
1264
+ * Useful for creating consistent API across different resource types.
1265
+ *
1266
+ * @typeParam T - The resource type
1267
+ * @typeParam E - The error type (defaults to Error)
1268
+ */
1269
+ type UseSingleResourceHook<T, E = Error> = (id: string) => QueryResultNullable<T, E>;
1270
+ /**
1271
+ * Generic type for hooks that fetch a list of resources with optional params.
1272
+ * Uses generics-default-type-parameters for the params type.
1273
+ *
1274
+ * @typeParam T - The item type
1275
+ * @typeParam P - The params type (defaults to empty object)
1276
+ * @typeParam E - The error type (defaults to Error)
1277
+ */
1278
+ type UseListResourceHook<T, P extends Record<string, unknown> = Record<string, never>, E = Error> = (params?: P) => ListQueryResult<T, E>;
1279
+ /**
1280
+ * Transforms a nullable result to a non-nullable one if data exists.
1281
+ * Useful when you've already checked hasData().
1282
+ */
1283
+ type WithData<R extends QueryResultNullable<unknown>> = R extends QueryResultNullable<infer T, infer E> ? QueryResultNullable<T, E> & {
1284
+ readonly data: T;
1285
+ } : never;
1286
+ /**
1287
+ * Activity slug constants as a const object.
1288
+ * Derive the ActivitySlug type from this single source of truth.
1289
+ */
1290
+ declare const ACTIVITY_SLUGS: {
1291
+ readonly abandonedCart: "abandoned_cart";
1292
+ readonly announcements: "announcements";
1293
+ readonly cartItemsAdded: "cart_items_added";
1294
+ readonly commentReply: "comment_reply";
1295
+ readonly directMessage: "direct_message";
1296
+ readonly fantasyPoint: "fantasy_point";
1297
+ readonly newLead: "new_lead";
1298
+ readonly orderPlaced: "order_placed";
1299
+ readonly pageViews: "page_views";
1300
+ readonly pageViewsContact: "page_views_contact";
1301
+ readonly tasks: "tasks";
1302
+ readonly upcomingEvent: "upcoming_event";
1303
+ readonly video: "video";
1304
+ readonly videoComplete: "video_complete";
1305
+ readonly videoCompleteContact: "video_complete_contact";
1306
+ readonly videoContact: "video_contact";
1307
+ readonly messageReceived: "message_received";
1308
+ readonly messageSent: "message_sent";
1309
+ readonly newCartItemsAdded: "new_cart_items_added";
1310
+ readonly smartLinkClicked: "smart_link_clicked";
1311
+ readonly reviewLeft: "review_left";
1312
+ };
1313
+ /** Activity slug union type derived from ACTIVITY_SLUGS constant. */
1314
+ type ActivitySlug = (typeof ACTIVITY_SLUGS)[keyof typeof ACTIVITY_SLUGS];
1315
+ /** Type predicate to check if a string is a valid ActivitySlug. */
1316
+ declare function isActivitySlug(value: string): value is ActivitySlug;
1317
+ /** Transformed activity for display. */
1318
+ interface Activity {
1319
+ readonly id: number;
1320
+ readonly userName: string;
1321
+ readonly avatarUrl: string | null;
1322
+ readonly activityType: string;
1323
+ readonly targetName: string;
1324
+ readonly timestamp: string;
1325
+ readonly slug: ActivitySlug;
1326
+ }
1327
+ /** Description/rich text metadata for a calendar event. */
1328
+ interface CalendarEventDescription {
1329
+ readonly id?: number | null;
1330
+ readonly name?: string | null;
1331
+ readonly body?: string | null;
1332
+ readonly record_type?: string | null;
1333
+ readonly record_id?: number | null;
1334
+ readonly created_at?: string | null;
1335
+ readonly updated_at?: string | null;
1336
+ readonly locale?: string | null;
1337
+ }
1338
+ /** Calendar event data from the API. */
1339
+ interface CalendarEvent {
1340
+ readonly id: number;
1341
+ readonly title: string;
1342
+ readonly description?: CalendarEventDescription | null;
1343
+ readonly color?: string | null;
1344
+ readonly url?: string | null;
1345
+ readonly start: string;
1346
+ readonly end: string;
1347
+ readonly active?: boolean | null;
1348
+ readonly time_zone?: string | null;
1349
+ readonly status?: string | null;
1350
+ readonly image_url?: string | null;
1351
+ readonly images?: readonly unknown[] | null;
1352
+ readonly venue?: string | null;
1353
+ readonly countries?: readonly string[] | null;
1354
+ readonly hasTomorrow?: boolean | null;
1355
+ readonly hasYesterday?: boolean | null;
1356
+ readonly isAllDay?: boolean;
1357
+ }
1358
+ /** Catch up suggestion data from the API. */
1359
+ interface CatchUp {
1360
+ readonly id: number;
1361
+ readonly suggestion_title: string;
1362
+ }
1363
+ /** MySite data returned by the hook. */
1364
+ interface MySiteData {
1365
+ readonly url: string | null;
1366
+ readonly views: number;
1367
+ readonly leads: number;
1368
+ readonly userName: string;
1369
+ }
1370
+ /** Transformed todo for display. */
1371
+ interface Todo {
1372
+ readonly id: number;
1373
+ readonly body: string;
1374
+ readonly dueAt: string | null;
1375
+ readonly completedAt: string | null;
1376
+ readonly createdAt: string;
1377
+ readonly contactName: string | null;
1378
+ }
1379
+
1380
+ /**
1381
+ * Calendar events hook - stub implementation for SDK
1382
+ * In production, implement this hook to fetch from your API
1383
+ */
1384
+
1385
+ /**
1386
+ * Result type for useCalendarEvents hook.
1387
+ * Uses QueryResult<CalendarEvent[]> with default Error type.
1388
+ */
1389
+ type UseCalendarEventsResult = QueryResult<CalendarEvent[]>;
1390
+ /**
1391
+ * Hook to fetch calendar events.
1392
+ * This is a stub implementation - override with your own data fetching logic.
1393
+ */
1394
+ declare function useCalendarEvents(): UseCalendarEventsResult;
1395
+
1396
+ /**
1397
+ * Todos hook - stub implementation for SDK
1398
+ * In production, implement this hook to fetch from your API
1399
+ */
1400
+
1401
+ /**
1402
+ * Result type for useTodos hook.
1403
+ * Uses QueryResult<Todo[]> with default Error type.
1404
+ */
1405
+ type UseTodosResult = QueryResult<Todo[]>;
1406
+ /**
1407
+ * Hook to fetch todo items.
1408
+ * This is a stub implementation - override with your own data fetching logic.
1409
+ */
1410
+ declare function useTodos(): UseTodosResult;
1411
+
1412
+ /**
1413
+ * Activities hook - stub implementation for SDK
1414
+ * In production, implement this hook to fetch from your API
1415
+ */
1416
+
1417
+ /**
1418
+ * Result type for useActivities hook.
1419
+ * Uses QueryResult generic with Activity[] and default Error type.
1420
+ */
1421
+ type UseActivitiesResult = QueryResult<Activity[]>;
1422
+ /**
1423
+ * Hook to fetch recent activities.
1424
+ * This is a stub implementation - override with your own data fetching logic.
1425
+ */
1426
+ declare function useActivities(): UseActivitiesResult;
1427
+
1428
+ /**
1429
+ * Catch ups hook - stub implementation for SDK
1430
+ * In production, implement this hook to fetch from your API
1431
+ */
1432
+
1433
+ /**
1434
+ * Result type for useCatchUps hook.
1435
+ * Uses QueryResult<CatchUp[]> with default Error type.
1436
+ */
1437
+ type UseCatchUpsResult = QueryResult<CatchUp[]>;
1438
+ /**
1439
+ * Hook to fetch catch up items.
1440
+ * This is a stub implementation - override with your own data fetching logic.
1441
+ */
1442
+ declare function useCatchUps(): UseCatchUpsResult;
1443
+
1444
+ /**
1445
+ * MySite hook - stub implementation for SDK
1446
+ * In production, implement this hook to fetch from your API
1447
+ */
1448
+
1449
+ /**
1450
+ * Result type for useMySite hook.
1451
+ * Uses QueryResultNullable since MySite data may not be available.
1452
+ */
1453
+ type UseMySiteResult = QueryResultNullable<MySiteData>;
1454
+ /**
1455
+ * Hook to fetch MySite data.
1456
+ * This is a stub implementation - override with your own data fetching logic.
1457
+ */
1458
+ declare function useMySite(): UseMySiteResult;
1459
+
1460
+ /**
1461
+ * Conversations hooks - stub implementations for SDK
1462
+ * In production, implement these hooks to fetch from your API
1463
+ */
1464
+
1465
+ /**
1466
+ * Result type for useConversations hook.
1467
+ * Uses QueryResult<Conversation[]> with default Error type.
1468
+ */
1469
+ type UseConversationsResult = QueryResult<Conversation[]>;
1470
+ /**
1471
+ * Hook to fetch all conversations.
1472
+ * This is a stub implementation - override with your own data fetching logic.
1473
+ *
1474
+ * @returns UseConversationsResult with empty data array
1475
+ *
1476
+ * @example
1477
+ * ```tsx
1478
+ * const { data: conversations, isLoading, isError } = useConversations();
1479
+ *
1480
+ * if (isLoading) return <Loading />;
1481
+ * if (isError) return <Error />;
1482
+ *
1483
+ * return conversations.map(conv => <ConversationItem key={conv.id} {...conv} />);
1484
+ * ```
1485
+ */
1486
+ declare function useConversations(): UseConversationsResult;
1487
+ /**
1488
+ * Result type for useConversationMessages hook.
1489
+ * Uses QueryResult<Message[]> with default Error type.
1490
+ */
1491
+ type UseConversationMessagesResult = QueryResult<Message[]>;
1492
+ /**
1493
+ * Hook to fetch messages for a specific conversation.
1494
+ * This is a stub implementation - override with your own data fetching logic.
1495
+ *
1496
+ * @param conversationId - The ID of the conversation to fetch messages for
1497
+ * @returns UseConversationMessagesResult with empty data array
1498
+ *
1499
+ * @example
1500
+ * ```tsx
1501
+ * const { data: messages, isLoading, isError } = useConversationMessages(conversationId);
1502
+ *
1503
+ * if (isLoading) return <Loading />;
1504
+ * if (isError) return <Error />;
1505
+ *
1506
+ * return messages.map(msg => <MessageBubble key={msg.id} {...msg} />);
1507
+ * ```
1508
+ */
1509
+ declare function useConversationMessages(_conversationId: string): UseConversationMessagesResult;
1510
+
1511
+ /**
1512
+ * Contacts hooks - stub implementation for SDK
1513
+ * In production, implement these hooks to fetch from your API
1514
+ */
1515
+
1516
+ /**
1517
+ * Type predicate to check if a status string is a valid ContactStatus.
1518
+ * Enables runtime validation with type narrowing.
1519
+ */
1520
+ declare function isContactStatus(value: string): value is ContactStatus;
1521
+ /**
1522
+ * Parameters for filtering and paginating contacts.
1523
+ * Uses readonly properties and proper ContactStatus type for status.
1524
+ */
1525
+ interface UseContactsParams {
1526
+ /** Search query to filter contacts by name, email, or company */
1527
+ readonly search?: string;
1528
+ /** Filter contacts by status - uses ContactStatus union type for type safety */
1529
+ readonly status?: ContactStatus;
1530
+ /** Maximum number of contacts to return */
1531
+ readonly limit?: number;
1532
+ }
1533
+ /**
1534
+ * Result type for the useContacts hook.
1535
+ * Uses ListQueryResult<Contact> with totalCount and default Error type.
1536
+ */
1537
+ type UseContactsResult = ListQueryResult<Contact>;
1538
+ /**
1539
+ * Result type for the useContact hook.
1540
+ * Uses QueryResultNullable since a specific contact may not exist.
1541
+ */
1542
+ type UseContactResult = QueryResultNullable<Contact>;
1543
+ /**
1544
+ * Hook to fetch a list of contacts with optional filtering and pagination.
1545
+ * This is a stub implementation - override with your own data fetching logic.
1546
+ *
1547
+ * @param params - Optional parameters for filtering and pagination
1548
+ * @returns Object containing contacts data, loading state, error state, and total count
1549
+ *
1550
+ * @example
1551
+ * ```tsx
1552
+ * const { data: contacts, isLoading, totalCount } = useContacts({
1553
+ * search: 'john',
1554
+ * status: 'active',
1555
+ * limit: 20
1556
+ * });
1557
+ * ```
1558
+ */
1559
+ declare function useContacts(_params?: UseContactsParams): UseContactsResult;
1560
+ /**
1561
+ * Hook to fetch a single contact by ID.
1562
+ * This is a stub implementation - override with your own data fetching logic.
1563
+ *
1564
+ * @param contactId - The unique identifier of the contact to fetch
1565
+ * @returns Object containing contact data, loading state, and error state
1566
+ *
1567
+ * @example
1568
+ * ```tsx
1569
+ * const { data: contact, isLoading, isError } = useContact('contact-123');
1570
+ * ```
1571
+ */
1572
+ declare function useContact(_contactId: string): UseContactResult;
1573
+
1574
+ /**
1575
+ * Auth Constants for Fluid Rep SDK
1576
+ *
1577
+ * These constants define the default values for authentication
1578
+ * configuration and storage keys.
1579
+ */
1580
+ /**
1581
+ * Authentication-related constants with sensible defaults.
1582
+ */
1583
+ declare const AUTH_CONSTANTS: {
1584
+ /**
1585
+ * Grace period in milliseconds to account for clock skew
1586
+ * when checking token expiration. Tokens are considered valid
1587
+ * if they expire within this period.
1588
+ */
1589
+ readonly TOKEN_GRACE_PERIOD_MS: number;
1590
+ /**
1591
+ * Default cookie max age in seconds (9 days).
1592
+ * This matches the typical JWT token lifetime from the Fluid API.
1593
+ */
1594
+ readonly COOKIE_MAX_AGE: number;
1595
+ };
1596
+ /**
1597
+ * Storage keys for auth tokens.
1598
+ */
1599
+ declare const STORAGE_KEYS: {
1600
+ /** localStorage key for user token */
1601
+ readonly USER_TOKEN: "fluidUserToken";
1602
+ /** localStorage key for company token (legacy) */
1603
+ readonly COMPANY_TOKEN: "fluidCompanyToken";
1604
+ /** Cookie name for auth token */
1605
+ readonly AUTH_COOKIE: "auth_token";
1606
+ };
1607
+ /**
1608
+ * Default URL parameter names for token extraction.
1609
+ */
1610
+ declare const URL_PARAMS: {
1611
+ /** URL parameter name for user token */
1612
+ readonly USER_TOKEN: "fluidUserToken";
1613
+ /** URL parameter name for company token (legacy) */
1614
+ readonly COMPANY_TOKEN: "fluidCompanyToken";
1615
+ };
1616
+
1617
+ /**
1618
+ * Token Utilities for Fluid Rep SDK
1619
+ *
1620
+ * Functions for decoding, validating, and checking JWT tokens.
1621
+ */
1622
+
1623
+ /**
1624
+ * Decode a JWT token and extract its payload.
1625
+ *
1626
+ * **Security note:** This function does NOT verify the JWT signature.
1627
+ * It only decodes the payload. Any valid JWT structure will be accepted,
1628
+ * regardless of who signed it.
1629
+ *
1630
+ * Client-side token decoding is used for UX purposes only (displaying
1631
+ * user info, role-based UI). The real security boundary is the server-side
1632
+ * API, which verifies the signature on every request.
1633
+ *
1634
+ * For signature verification, use {@link verifyToken} with a JWKS URL.
1635
+ *
1636
+ * @param token - The JWT token string
1637
+ * @returns The decoded JWT payload, or null if decoding fails
1638
+ *
1639
+ * @example
1640
+ * ```ts
1641
+ * const payload = decodeToken(token);
1642
+ * if (payload) {
1643
+ * console.log(`User: ${payload.email}`);
1644
+ * }
1645
+ * ```
1646
+ */
1647
+ declare function decodeToken(token: string): JWTPayload | null;
1648
+ /**
1649
+ * Check if a token has expired.
1650
+ * Includes a configurable grace period to account for clock skew.
1651
+ *
1652
+ * @param token - The JWT token string
1653
+ * @param gracePeriodMs - Grace period in milliseconds (default: 30 seconds)
1654
+ * @returns true if the token is expired, false otherwise
1655
+ *
1656
+ * @example
1657
+ * ```ts
1658
+ * if (isTokenExpired(token)) {
1659
+ * // Token is expired, need to re-authenticate
1660
+ * clearAuth();
1661
+ * }
1662
+ * ```
1663
+ */
1664
+ declare function isTokenExpired(token: string, gracePeriodMs?: number): boolean;
1665
+ /**
1666
+ * Validate a JWT token for format and expiration.
1667
+ *
1668
+ * **Security note:** This function checks JWT structure and expiration
1669
+ * but does NOT verify the signature. It is a UX-level check only.
1670
+ * For signature verification, use {@link verifyToken} with a JWKS URL.
1671
+ *
1672
+ * @param token - The JWT token string
1673
+ * @param gracePeriodMs - Grace period for expiration check (default: 30 seconds)
1674
+ * @returns Validation result with status and decoded payload if valid
1675
+ *
1676
+ * @example
1677
+ * ```ts
1678
+ * const result = validateToken(token);
1679
+ * if (result.isValid) {
1680
+ * console.log(`Welcome, ${result.payload?.full_name}`);
1681
+ * } else {
1682
+ * console.error(`Auth failed: ${result.error}`);
1683
+ * }
1684
+ * ```
1685
+ */
1686
+ declare function validateToken(token: string, gracePeriodMs?: number): TokenValidationResult;
1687
+ /**
1688
+ * Type guard to check if a validation result is valid.
1689
+ * Enables TypeScript narrowing of the result type.
1690
+ *
1691
+ * @param result - The validation result to check
1692
+ * @returns true if the token is valid (narrows payload to non-optional)
1693
+ *
1694
+ * @example
1695
+ * ```ts
1696
+ * const result = validateToken(token);
1697
+ * if (isValidToken(result)) {
1698
+ * // result.payload is guaranteed to be JWTPayload (not undefined)
1699
+ * console.log(result.payload.email);
1700
+ * }
1701
+ * ```
1702
+ */
1703
+ declare function isValidToken(result: TokenValidationResult): result is TokenValidationResult & {
1704
+ isValid: true;
1705
+ payload: JWTPayload;
1706
+ };
1707
+ /**
1708
+ * Get the expiration time of a token as a Date.
1709
+ *
1710
+ * @param token - The JWT token string
1711
+ * @returns The expiration Date, or null if token has no expiration or is invalid
1712
+ */
1713
+ declare function getTokenExpiration(token: string): Date | null;
1714
+ /**
1715
+ * Get the time remaining until token expiration in milliseconds.
1716
+ *
1717
+ * @param token - The JWT token string
1718
+ * @returns Milliseconds until expiration, or 0 if expired/invalid, or Infinity if no expiration
1719
+ */
1720
+ declare function getTokenTimeRemaining(token: string): number;
1721
+
1722
+ /**
1723
+ * Token Storage Utilities for Fluid Rep SDK
1724
+ *
1725
+ * Functions for storing and retrieving auth tokens from
1726
+ * cookies and localStorage.
1727
+ */
1728
+
1729
+ /**
1730
+ * Get the stored auth token.
1731
+ * Checks cookie first, then falls back to localStorage.
1732
+ *
1733
+ * @param config - Optional auth config for custom cookie key
1734
+ * @returns The stored token or null if not found
1735
+ *
1736
+ * @example
1737
+ * ```ts
1738
+ * const token = getStoredToken();
1739
+ * if (token) {
1740
+ * console.log("User is logged in");
1741
+ * }
1742
+ * ```
1743
+ */
1744
+ declare function getStoredToken(config?: FluidAuthConfig): string | null;
1745
+ /**
1746
+ * Store an auth token in both cookie and localStorage.
1747
+ * Using both provides redundancy and compatibility with different auth flows.
1748
+ *
1749
+ * @param token - The JWT token to store
1750
+ * @param config - Optional auth config for custom storage options
1751
+ *
1752
+ * @example
1753
+ * ```ts
1754
+ * storeToken(newToken);
1755
+ * // Token is now accessible via getStoredToken()
1756
+ * ```
1757
+ */
1758
+ declare function storeToken(token: string, config?: FluidAuthConfig): void;
1759
+ /**
1760
+ * Clear all stored auth tokens from cookies and localStorage.
1761
+ *
1762
+ * @param config - Optional auth config for custom cookie key
1763
+ *
1764
+ * @example
1765
+ * ```ts
1766
+ * // User logs out
1767
+ * clearTokens();
1768
+ * ```
1769
+ */
1770
+ declare function clearTokens(config?: FluidAuthConfig): void;
1771
+ /**
1772
+ * Check if any auth token is stored.
1773
+ *
1774
+ * @param config - Optional auth config
1775
+ * @returns true if a token is stored, false otherwise
1776
+ */
1777
+ declare function hasStoredToken(config?: FluidAuthConfig): boolean;
1778
+
1779
+ /**
1780
+ * URL Token Utilities for Fluid Rep SDK
1781
+ *
1782
+ * Functions for extracting and cleaning auth tokens from URL parameters.
1783
+ * This is the primary way tokens are passed from the parent Fluid Commerce
1784
+ * app to embedded rep portals.
1785
+ *
1786
+ * **Security model**: Tokens in URL parameters are a known tradeoff.
1787
+ * The token is extracted and immediately cleaned from the URL via
1788
+ * `history.replaceState()`. A `Referrer-Policy` meta tag in the
1789
+ * starter template prevents the token from leaking in referrer headers.
1790
+ * See docs/authentication.md for full security analysis.
1791
+ */
1792
+ /**
1793
+ * Extract the auth token from the URL query parameters.
1794
+ *
1795
+ * @param tokenKey - The URL parameter name (default: "fluidUserToken")
1796
+ * @returns The token value or null if not present
1797
+ *
1798
+ * @example
1799
+ * ```ts
1800
+ * // URL: https://myportal.com?fluidUserToken=eyJhbG...
1801
+ * const token = extractTokenFromUrl();
1802
+ * // token = "eyJhbG..."
1803
+ * ```
1804
+ */
1805
+ declare function extractTokenFromUrl(tokenKey?: string): string | null;
1806
+ /**
1807
+ * Extract the company token from the URL query parameters.
1808
+ * This is a legacy parameter that may still be used in some flows.
1809
+ *
1810
+ * @param tokenKey - The URL parameter name (default: "fluidCompanyToken")
1811
+ * @returns The token value or null if not present
1812
+ */
1813
+ declare function extractCompanyTokenFromUrl(tokenKey?: string): string | null;
1814
+ /**
1815
+ * Remove the auth token from the URL without reloading the page.
1816
+ * This prevents the token from being accidentally shared via URL copy/paste
1817
+ * or appearing in browser history.
1818
+ *
1819
+ * Uses history.replaceState to update the URL cleanly.
1820
+ *
1821
+ * @param tokenKey - The URL parameter name to remove (default: "fluidUserToken")
1822
+ *
1823
+ * @example
1824
+ * ```ts
1825
+ * // Before: https://myportal.com?fluidUserToken=eyJhbG...&page=1
1826
+ * cleanTokenFromUrl();
1827
+ * // After: https://myportal.com?page=1
1828
+ * ```
1829
+ */
1830
+ declare function cleanTokenFromUrl(tokenKey?: string): void;
1831
+ /**
1832
+ * Check if the URL contains an auth token parameter.
1833
+ *
1834
+ * @param tokenKey - The URL parameter name (default: "fluidUserToken")
1835
+ * @returns true if the URL contains the token parameter
1836
+ */
1837
+ declare function hasTokenInUrl(tokenKey?: string): boolean;
1838
+ /**
1839
+ * Extract all auth-related tokens from the URL at once.
1840
+ *
1841
+ * @param userTokenKey - The URL parameter name for user token
1842
+ * @param companyTokenKey - The URL parameter name for company token
1843
+ * @returns Object with both token values (or null if not present)
1844
+ */
1845
+ declare function extractAllTokensFromUrl(userTokenKey?: string, companyTokenKey?: string): {
1846
+ userToken: string | null;
1847
+ companyToken: string | null;
1848
+ };
1849
+
1850
+ interface RequireAuthProps {
1851
+ /** Content to render when authenticated */
1852
+ children: ReactNode;
1853
+ /** Component to show while checking authentication (default: AuthLoading) */
1854
+ fallback?: ReactNode;
1855
+ /** Component to show when not authenticated (default: AuthError) */
1856
+ errorComponent?: ReactNode;
1857
+ }
1858
+ /**
1859
+ * Component that protects content requiring authentication.
1860
+ *
1861
+ * **Important:** This provides UX-level protection only. It prevents
1862
+ * unauthenticated users from seeing the UI, but the real security
1863
+ * boundary is the server-side API. Client-side auth can always be
1864
+ * bypassed by modifying browser state.
1865
+ *
1866
+ * For defense-in-depth, configure `jwksUrl` in `FluidAuthConfig`
1867
+ * to enable client-side JWT signature verification.
1868
+ *
1869
+ * Shows different states based on auth status:
1870
+ * - Loading: Shows fallback (spinner by default)
1871
+ * - Not authenticated: Shows errorComponent (AuthError by default)
1872
+ * - Authenticated: Shows children
1873
+ *
1874
+ * @example
1875
+ * ```tsx
1876
+ * // Basic usage - shows default loading/error states
1877
+ * <RequireAuth>
1878
+ * <ProtectedContent />
1879
+ * </RequireAuth>
1880
+ *
1881
+ * // Custom loading state
1882
+ * <RequireAuth fallback={<CustomSpinner />}>
1883
+ * <ProtectedContent />
1884
+ * </RequireAuth>
1885
+ *
1886
+ * // Custom error component
1887
+ * <RequireAuth errorComponent={<LoginPrompt />}>
1888
+ * <ProtectedContent />
1889
+ * </RequireAuth>
1890
+ *
1891
+ * // Both custom
1892
+ * <RequireAuth
1893
+ * fallback={<SkeletonLoader />}
1894
+ * errorComponent={<RedirectToLogin />}
1895
+ * >
1896
+ * <Dashboard />
1897
+ * </RequireAuth>
1898
+ * ```
1899
+ */
1900
+ declare function RequireAuth({ children, fallback, errorComponent, }: RequireAuthProps): react_jsx_runtime.JSX.Element;
1901
+
1902
+ interface AuthErrorProps {
1903
+ /** Error message to display */
1904
+ message?: string;
1905
+ /** Optional title */
1906
+ title?: string;
1907
+ /** Optional children for custom content */
1908
+ children?: ReactNode;
1909
+ }
1910
+ /**
1911
+ * Default authentication error component.
1912
+ *
1913
+ * Displays a simple error message when authentication fails.
1914
+ * Can be customized via props or replaced entirely in RequireAuth.
1915
+ *
1916
+ * @example
1917
+ * ```tsx
1918
+ * // Use with default message
1919
+ * <AuthError />
1920
+ *
1921
+ * // Use with custom message
1922
+ * <AuthError message="Session expired. Please log in again." />
1923
+ *
1924
+ * // Use with custom content
1925
+ * <AuthError>
1926
+ * <CustomLoginButton />
1927
+ * </AuthError>
1928
+ * ```
1929
+ */
1930
+ declare function AuthError({ message, title, children, }: AuthErrorProps): react_jsx_runtime.JSX.Element;
1931
+ /**
1932
+ * Simple loading spinner component for auth loading state.
1933
+ */
1934
+ declare function AuthLoading(): react_jsx_runtime.JSX.Element;
1935
+
1936
+ type MessagingScreenProps = ComponentProps<"div"> & {
1937
+ background?: BackgroundValue;
1938
+ textColor?: ColorOptions;
1939
+ accentColor?: ColorOptions;
1940
+ padding?: PaddingOptions;
1941
+ borderRadius?: BorderRadiusOptions;
1942
+ onConversationSelect?: (conversationId: string) => void;
1943
+ onSendMessage?: (conversationId: string, message: string) => void;
1944
+ };
1945
+ declare function MessagingScreen(_props: MessagingScreenProps): react_jsx_runtime.JSX.Element;
1946
+ declare const messagingScreenPropertySchema: WidgetPropertySchema;
1947
+
1948
+ type ContactsScreenProps = ComponentProps<"div"> & {
1949
+ background?: BackgroundValue;
1950
+ textColor?: ColorOptions;
1951
+ accentColor?: ColorOptions;
1952
+ padding?: PaddingOptions;
1953
+ borderRadius?: BorderRadiusOptions;
1954
+ defaultViewMode?: "list" | "grid";
1955
+ onContactSelect?: (contactId: string) => void;
1956
+ onCreateContact?: () => void;
1957
+ };
1958
+ declare function ContactsScreen(_props: ContactsScreenProps): react_jsx_runtime.JSX.Element;
1959
+ declare const contactsScreenPropertySchema: WidgetPropertySchema;
1960
+
1961
+ type OrdersScreenProps = ComponentProps<"div"> & {
1962
+ background?: BackgroundValue;
1963
+ textColor?: ColorOptions;
1964
+ accentColor?: ColorOptions;
1965
+ padding?: PaddingOptions;
1966
+ borderRadius?: BorderRadiusOptions;
1967
+ };
1968
+ declare function OrdersScreen(_props: OrdersScreenProps): react_jsx_runtime.JSX.Element;
1969
+ declare const ordersScreenPropertySchema: WidgetPropertySchema;
1970
+
1971
+ type CustomersScreenProps = ComponentProps<"div"> & {
1972
+ background?: BackgroundValue;
1973
+ textColor?: ColorOptions;
1974
+ accentColor?: ColorOptions;
1975
+ padding?: PaddingOptions;
1976
+ borderRadius?: BorderRadiusOptions;
1977
+ };
1978
+ declare function CustomersScreen(_props: CustomersScreenProps): react_jsx_runtime.JSX.Element;
1979
+ declare const customersScreenPropertySchema: WidgetPropertySchema;
1980
+
1981
+ type ProductsScreenProps = ComponentProps<"div"> & {
1982
+ background?: BackgroundValue;
1983
+ textColor?: ColorOptions;
1984
+ accentColor?: ColorOptions;
1985
+ padding?: PaddingOptions;
1986
+ borderRadius?: BorderRadiusOptions;
1987
+ };
1988
+ declare function ProductsScreen(_props: ProductsScreenProps): react_jsx_runtime.JSX.Element;
1989
+ declare const productsScreenPropertySchema: WidgetPropertySchema;
1990
+
1991
+ declare const screenPropertySchemas: {
1992
+ MessagingScreen: () => Promise<_fluid_app_rep_core_registries.WidgetPropertySchema>;
1993
+ ContactsScreen: () => Promise<_fluid_app_rep_core_registries.WidgetPropertySchema>;
1994
+ OrdersScreen: () => Promise<_fluid_app_rep_core_registries.WidgetPropertySchema>;
1995
+ CustomersScreen: () => Promise<_fluid_app_rep_core_registries.WidgetPropertySchema>;
1996
+ ProductsScreen: () => Promise<_fluid_app_rep_core_registries.WidgetPropertySchema>;
1997
+ };
1998
+ /**
1999
+ * Core page template IDs
2000
+ */
2001
+ declare const CORE_PAGE_IDS: {
2002
+ readonly MESSAGING: "core-messaging";
2003
+ readonly CONTACTS: "core-contacts";
2004
+ readonly ORDERS: "core-orders";
2005
+ readonly CUSTOMERS: "core-customers";
2006
+ readonly PRODUCTS: "core-products";
2007
+ };
2008
+
2009
+ /**
2010
+ * Resolve all page references and local screens into a unified screen list.
2011
+ *
2012
+ * This function merges:
2013
+ * 1. Screen definitions from page_refs (shared templates)
2014
+ * 2. Local screen definitions (for backwards compatibility and custom screens)
2015
+ *
2016
+ * When a screen_id appears in both page_refs and screens, the local screen
2017
+ * takes precedence (allows local overrides of template pages).
2018
+ *
2019
+ * @param navigation - The navigation configuration
2020
+ * @returns A unified array of ScreenDefinition objects
2021
+ *
2022
+ * @example
2023
+ * ```ts
2024
+ * const navigation: Navigation = {
2025
+ * definition_id: 1,
2026
+ * id: 1,
2027
+ * name: "Main Nav",
2028
+ * navigation_items: [...],
2029
+ * screens: [
2030
+ * // Local custom screen
2031
+ * { id: 1, slug: "home", name: "Home", component_tree: [...] }
2032
+ * ],
2033
+ * page_refs: [
2034
+ * // Reference to shared messaging template
2035
+ * { page_template_id: "core-messaging", screen_id: 2 }
2036
+ * ],
2037
+ * };
2038
+ *
2039
+ * const allScreens = resolveNavigationPages(navigation);
2040
+ * // Returns: [home screen, messaging screen from template]
2041
+ * ```
2042
+ */
2043
+ declare function resolveNavigationPages(navigation: Readonly<Navigation>): ScreenDefinition[];
2044
+ /**
2045
+ * Get all available page templates for use in navigation.
2046
+ *
2047
+ * @returns Array of page templates from the registry
2048
+ */
2049
+ declare function getAvailablePageTemplates(): PageTemplate[];
2050
+ /**
2051
+ * Get core page templates that are required for basic functionality.
2052
+ *
2053
+ * @returns Array of core page templates
2054
+ */
2055
+ declare function getCorePageTemplates(): PageTemplate[];
2056
+ /**
2057
+ * Get optional page templates that can be added to navigation.
2058
+ *
2059
+ * @returns Array of optional (non-core) page templates
2060
+ */
2061
+ declare function getOptionalPageTemplates(): PageTemplate[];
2062
+ /**
2063
+ * Check if a navigation has all required core pages.
2064
+ *
2065
+ * @param navigation - The navigation to check
2066
+ * @returns Object with validation result and missing page IDs
2067
+ */
2068
+ declare function validateNavigationPages(navigation: Readonly<Navigation>): {
2069
+ readonly valid: boolean;
2070
+ readonly missingCorePages: readonly string[];
2071
+ };
2072
+
2073
+ /**
2074
+ * Registry for managing reusable page templates.
2075
+ *
2076
+ * The registry provides a central store for page templates that can be
2077
+ * shared across multiple navigations. Core pages (like Messaging, Contacts)
2078
+ * are pre-registered and cannot be removed.
2079
+ *
2080
+ * @example
2081
+ * ```ts
2082
+ * // Register a custom page template
2083
+ * PageTemplateRegistry.register({
2084
+ * id: 'custom-dashboard',
2085
+ * slug: 'dashboard',
2086
+ * name: 'Custom Dashboard',
2087
+ * category: 'custom',
2088
+ * version: '1.0.0',
2089
+ * component_tree: [{ type: 'TextWidget', props: { text: 'Hello' } }],
2090
+ * });
2091
+ *
2092
+ * // Get a template by ID
2093
+ * const template = PageTemplateRegistry.get('custom-dashboard');
2094
+ *
2095
+ * // List all templates in a category
2096
+ * const corePages = PageTemplateRegistry.getByCategory('core');
2097
+ * ```
2098
+ */
2099
+ declare class PageTemplateRegistryImpl {
2100
+ private templates;
2101
+ private categories;
2102
+ constructor();
2103
+ /**
2104
+ * Register a new page template.
2105
+ * @throws Error if a template with the same ID already exists
2106
+ */
2107
+ register(template: PageTemplate): void;
2108
+ /**
2109
+ * Unregister a page template by ID.
2110
+ * Core templates cannot be unregistered.
2111
+ * @returns true if the template was removed, false if it didn't exist or is a core template
2112
+ */
2113
+ unregister(id: string): boolean;
2114
+ /**
2115
+ * Get a page template by ID.
2116
+ */
2117
+ get(id: string): PageTemplate | undefined;
2118
+ /**
2119
+ * Get all page templates in a specific category.
2120
+ */
2121
+ getByCategory(category: PageCategoryId | string): PageTemplate[];
2122
+ /**
2123
+ * List all registered page templates.
2124
+ */
2125
+ listAll(): PageTemplate[];
2126
+ /**
2127
+ * List all core page templates (isCore: true).
2128
+ */
2129
+ listCore(): PageTemplate[];
2130
+ /**
2131
+ * List all non-core page templates.
2132
+ */
2133
+ listOptional(): PageTemplate[];
2134
+ /**
2135
+ * List all registered categories.
2136
+ */
2137
+ listCategories(): PageCategory[];
2138
+ /**
2139
+ * Add a custom category.
2140
+ */
2141
+ addCategory(category: PageCategory): void;
2142
+ /**
2143
+ * Check if a template exists by ID.
2144
+ */
2145
+ has(id: string): boolean;
2146
+ /**
2147
+ * Get the count of registered templates.
2148
+ */
2149
+ get size(): number;
2150
+ /**
2151
+ * Clear all non-core templates.
2152
+ * Useful for testing or resetting the registry.
2153
+ */
2154
+ clearNonCore(): void;
2155
+ }
2156
+ /**
2157
+ * Global page template registry singleton.
2158
+ *
2159
+ * This registry is automatically populated with core page templates
2160
+ * (Messaging, Contacts) when the SDK is imported.
2161
+ */
2162
+ declare const PageTemplateRegistry: PageTemplateRegistryImpl;
2163
+
2164
+ export { ACTIVITY_SLUGS, AUTH_CONSTANTS, type Activity as ActivityItem, type ActivitySlug, ApiError, AuthError, type AuthErrorProps, AuthLoading, type BaseListParams, CORE_PAGE_IDS, CURRENT_REP_QUERY_KEY, type CalendarEvent, type CatchUp as CatchUpItem, type Contact, type ContactAddress, type ContactStatus, type ContactType, ContactsScreen, type Conversation, type ConversationStatus, type CreateOrderData, CustomersScreen, type DashboardData, type FluidAuthConfig, type FluidAuthContextValue, FluidAuthProvider, type FluidAuthProviderProps, type FluidClient, FluidProvider, type FluidProviderProps, type FluidSDKConfig, FluidThemeProvider, type FluidThemeProviderProps, type JWTPayload, type ListQueryResult, type Message, type MessageType, MessagingScreen, type MySiteData, type Navigation, type NavigationItem, type Order, type OrderLineItem, type OrderListParams, OrdersScreen, PAGE_CATEGORIES, PERMISSIONS_QUERY_KEY, PROFILE_QUERY_KEY, type PageCategory, type PageCategoryId, type PageOverride, type PageReference, type PageTemplate, PageTemplateProvider, PageTemplateRegistry, type PaginationParams, type Participant, type PermissionAction, type Permissions, type Product, type ProductListParams, ProductsScreen, type Profile, type QueryResult, type QueryResultNullable, type Rep, type RequestOptions, RequireAuth, type RequireAuthProps, type ResourcePermissions, STORAGE_KEYS, type SalesData, type SalesDataPoint, type SalesParams, type ScreenDefinition, type Todo as TodoItem, type TokenValidationResult, URL_PARAMS, USER_TYPES, type UpdateRepData, type UseContactResult, type UseContactsParams, type UseContactsResult, type UseConversationMessagesResult, type UseConversationsResult, type UseFluidPermissionsResult, type UseFluidThemeResult, type UseListResourceHook, type UseSingleResourceHook, type UserPermissions, type UserType, type ValueListQueryResult, type WithData, cleanTokenFromUrl, clearTokens, contactsScreenPropertySchema, createFluidClient, customersScreenPropertySchema, decodeToken, extractAllTokensFromUrl, extractCompanyTokenFromUrl, extractTokenFromUrl, getAvailablePageTemplates, getCorePageTemplates, getOptionalPageTemplates, getProperty, getStoredToken, getTokenExpiration, getTokenTimeRemaining, hasData, hasStoredToken, hasTokenInUrl, isActivitySlug, isApiError, isContactStatus, isErrorResult, isIdle, isLoading, isTokenExpired, isUserType, isValidToken, messagingScreenPropertySchema, ordersScreenPropertySchema, productsScreenPropertySchema, resolveNavigationPages, screenPropertySchemas, selectProperty, storeToken, useActivities, useCalendarEvents, useCatchUps, useContact, useContacts, useConversationMessages, useConversations, useCurrentRep, useFluidApi, useFluidAuth, useFluidAuthContext, useFluidContext, useFluidPermissions, useFluidProfile, useFluidTheme, useMySite, usePageTemplates, useResolvedPages, useThemeContext, useTodos, validateNavigationPages, validateToken };