@elevasis/ui 2.64.1 → 2.66.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 (72) hide show
  1. package/dist/api/index.js +2 -2
  2. package/dist/app/index.d.ts +26 -0
  3. package/dist/app/index.js +8 -8
  4. package/dist/auth/index.d.ts +12 -5
  5. package/dist/auth/index.js +8 -8
  6. package/dist/charts/index.js +8 -8
  7. package/dist/{chunk-DRQPEMJI.js → chunk-4DV4ECMG.js} +3 -0
  8. package/dist/{chunk-KRWALB24.js → chunk-6SSQGWK7.js} +1 -1
  9. package/dist/{chunk-ZTWA5H77.js → chunk-6ZAP3FOA.js} +0 -1
  10. package/dist/{chunk-PGAA4G3T.js → chunk-ANNM5R7S.js} +275 -382
  11. package/dist/{chunk-I3CFGE3N.js → chunk-BLXJEIQS.js} +1 -1
  12. package/dist/chunk-L7BZZ4SI.js +56 -0
  13. package/dist/chunk-P45GQ3ZW.js +104 -0
  14. package/dist/{chunk-EIXSQONC.js → chunk-RT4KRGZT.js} +37 -59
  15. package/dist/{chunk-FVOMKZ7S.js → chunk-Y6I3IC45.js} +3 -6
  16. package/dist/components/index.d.ts +274 -191
  17. package/dist/components/index.js +8 -8
  18. package/dist/components/navigation/index.js +8 -8
  19. package/dist/execution/index.d.ts +115 -104
  20. package/dist/execution/index.js +2 -2
  21. package/dist/features/auth/index.d.ts +125 -9
  22. package/dist/features/auth/index.js +154 -14
  23. package/dist/features/clients/index.js +8 -8
  24. package/dist/features/crm/index.d.ts +20 -0
  25. package/dist/features/crm/index.js +8 -8
  26. package/dist/features/dashboard/index.js +8 -8
  27. package/dist/features/delivery/index.d.ts +20 -0
  28. package/dist/features/delivery/index.js +8 -8
  29. package/dist/features/knowledge/index.js +8 -8
  30. package/dist/features/lead-gen/index.js +8 -8
  31. package/dist/features/monitoring/index.js +8 -8
  32. package/dist/features/monitoring/requests/index.js +9 -9
  33. package/dist/features/notes/index.js +2 -2
  34. package/dist/features/operations/index.d.ts +177 -106
  35. package/dist/features/operations/index.js +8 -8
  36. package/dist/features/public-agent-chat/index.js +1 -1
  37. package/dist/features/settings/index.d.ts +21 -0
  38. package/dist/features/settings/index.js +8 -8
  39. package/dist/hooks/access/index.js +8 -8
  40. package/dist/hooks/delivery/index.d.ts +20 -0
  41. package/dist/hooks/delivery/index.js +8 -8
  42. package/dist/hooks/index.d.ts +319 -145
  43. package/dist/hooks/index.js +8 -8
  44. package/dist/hooks/operations/command-view/utils/transformCommandViewData.d.ts +0 -2
  45. package/dist/hooks/operations/command-view/utils/transformCommandViewData.js +1 -1
  46. package/dist/hooks/published.d.ts +319 -145
  47. package/dist/hooks/published.js +8 -8
  48. package/dist/index.d.ts +409 -219
  49. package/dist/index.js +8 -8
  50. package/dist/initialization/index.d.ts +95 -28
  51. package/dist/initialization/index.js +3 -3
  52. package/dist/knowledge/index.js +12 -12
  53. package/dist/{knowledge-search-index-JOPRYZN6.js → knowledge-search-index-6EZNBNSR.js} +4 -4
  54. package/dist/layout/index.js +8 -8
  55. package/dist/organization/index.d.ts +63 -4
  56. package/dist/organization/index.js +8 -8
  57. package/dist/profile/index.d.ts +43 -2
  58. package/dist/profile/index.js +1 -1
  59. package/dist/provider/index.d.ts +20 -0
  60. package/dist/provider/index.js +8 -8
  61. package/dist/provider/published.d.ts +20 -0
  62. package/dist/provider/published.js +8 -8
  63. package/dist/supabase/index.d.ts +40 -0
  64. package/dist/test-utils/index.d.ts +5 -0
  65. package/dist/test-utils/index.js +4 -4
  66. package/dist/test-utils/setup-integration.js +1 -1
  67. package/dist/test-utils/setup.js +1 -1
  68. package/dist/types/index.d.ts +483 -244
  69. package/dist/utils/index.js +2 -2
  70. package/package.json +6 -4
  71. package/dist/chunk-LO7GWG24.js +0 -75
  72. package/dist/chunk-T4LA4RY2.js +0 -56
@@ -205,110 +205,6 @@ interface ExecutionLogMessage {
205
205
  context?: LogContext;
206
206
  }
207
207
 
208
- /**
209
- * Serialized Registry Types
210
- *
211
- * Pre-computed JSON-safe types for API responses and Command View.
212
- * Serialization happens once at API startup, enabling instant response times.
213
- */
214
-
215
- /**
216
- * Serialized agent definition (JSON-safe)
217
- * Result of serializeDefinition(AgentDefinition)
218
- */
219
- interface SerializedAgentDefinition {
220
- config: {
221
- resourceId: string;
222
- name: string;
223
- description: string;
224
- version: string;
225
- type: 'agent';
226
- kind: 'orchestrator' | 'specialist' | 'utility' | 'system';
227
- status: 'dev' | 'prod';
228
- links?: ResourceLink[];
229
- category?: ResourceCategory;
230
- /** Whether this resource is archived and should be excluded from registration and deployment */
231
- archived?: boolean;
232
- systemPrompt: string;
233
- constraints?: {
234
- maxIterations?: number;
235
- timeout?: number;
236
- maxSessionMemoryKeys?: number;
237
- maxMemoryTokens?: number;
238
- };
239
- sessionCapable?: boolean;
240
- memoryPreferences?: string;
241
- };
242
- modelConfig: {
243
- provider: string;
244
- model: string;
245
- apiKey: string;
246
- temperature: number;
247
- maxOutputTokens: number;
248
- topP?: number;
249
- modelOptions?: Record<string, unknown>;
250
- };
251
- contract: {
252
- inputSchema: object;
253
- outputSchema?: object;
254
- };
255
- tools: Array<{
256
- name: string;
257
- description: string;
258
- inputSchema?: object;
259
- outputSchema?: object;
260
- }>;
261
- knowledgeMap?: {
262
- nodeCount: number;
263
- nodes: Array<{
264
- id: string;
265
- description: string;
266
- loaded: boolean;
267
- hasPrompt: boolean;
268
- }>;
269
- };
270
- metricsConfig?: object;
271
- }
272
- /**
273
- * Serialized workflow definition (JSON-safe)
274
- * Result of serializeDefinition(WorkflowDefinition)
275
- */
276
- interface SerializedWorkflowDefinition {
277
- config: {
278
- resourceId: string;
279
- name: string;
280
- description: string;
281
- version: string;
282
- type: 'workflow';
283
- status: 'dev' | 'prod';
284
- links?: ResourceLink[];
285
- category?: ResourceCategory;
286
- /** Whether this resource is archived and should be excluded from registration and deployment */
287
- archived?: boolean;
288
- };
289
- entryPoint: string;
290
- steps: Array<{
291
- id: string;
292
- name: string;
293
- description: string;
294
- inputSchema?: object;
295
- outputSchema?: object;
296
- next: {
297
- type: 'linear' | 'conditional';
298
- target?: string;
299
- routes?: Array<{
300
- target: string;
301
- }>;
302
- default?: string;
303
- } | null;
304
- }>;
305
- contract: {
306
- inputSchema: object;
307
- outputSchema?: object;
308
- };
309
- metricsConfig?: object;
310
- }
311
-
312
208
  /**
313
209
  * Workflow step state
314
210
  * Aggregates step context events with timing and logs
@@ -462,6 +358,121 @@ declare const LinkSchema: z.ZodObject<{
462
358
  }, z.core.$strip>;
463
359
  type Link = z.infer<typeof LinkSchema>;
464
360
 
361
+ /**
362
+ * Agent-specific type definitions
363
+ * Types for autonomous agents with tools, memory, and constraints
364
+ */
365
+
366
+ type AgentKind = 'orchestrator' | 'specialist' | 'utility' | 'platform';
367
+
368
+ /**
369
+ * Serialized Registry Types
370
+ *
371
+ * Pre-computed JSON-safe types for API responses and Command View.
372
+ * Serialization happens once at API startup, enabling instant response times.
373
+ */
374
+
375
+ /**
376
+ * Serialized agent definition (JSON-safe)
377
+ * Result of serializeDefinition(AgentDefinition)
378
+ */
379
+ interface SerializedAgentDefinition {
380
+ config: {
381
+ resourceId: string;
382
+ name: string;
383
+ description: string;
384
+ version: string;
385
+ type: 'agent';
386
+ /**
387
+ * Imported from the runtime type instead of hand-copied. It used to be a hand-written literal
388
+ * union that said `'system'` where `AgentKind`'s fourth member is `'platform'` -- undetected
389
+ * because `serializeDefinition` returns `any` and every call site casts the result to this
390
+ * interface, so the literal union was never actually checked against real data. Deriving from
391
+ * the source of truth makes that class of drift a type error instead of a silent typo.
392
+ */
393
+ kind: AgentKind;
394
+ status: 'dev' | 'prod';
395
+ links?: ResourceLink[];
396
+ category?: ResourceCategory;
397
+ /** Whether this resource is archived and should be excluded from registration and deployment */
398
+ archived?: boolean;
399
+ systemPrompt: string;
400
+ constraints?: {
401
+ maxIterations?: number;
402
+ timeout?: number;
403
+ maxSessionMemoryKeys?: number;
404
+ maxMemoryTokens?: number;
405
+ };
406
+ sessionCapable?: boolean;
407
+ memoryPreferences?: string;
408
+ };
409
+ modelConfig: {
410
+ provider: string;
411
+ model: string;
412
+ apiKey: string;
413
+ /**
414
+ * Optional here, matching `ModelConfig` -- this used to be required even though neither real
415
+ * agent literal in the monorepo (`local-test-agent`, the `createPlatformToolAgent` test fixture)
416
+ * sets it, and nothing caught the mismatch for the same `serializeDefinition`-returns-`any`
417
+ * reason `kind` drifted above.
418
+ */
419
+ temperature?: number;
420
+ maxOutputTokens?: number;
421
+ topP?: number;
422
+ modelOptions?: Record<string, unknown>;
423
+ };
424
+ contract: {
425
+ inputSchema: object;
426
+ outputSchema?: object;
427
+ };
428
+ tools: Array<{
429
+ name: string;
430
+ description: string;
431
+ inputSchema?: object;
432
+ outputSchema?: object;
433
+ }>;
434
+ metricsConfig?: object;
435
+ }
436
+ /**
437
+ * Serialized workflow definition (JSON-safe)
438
+ * Result of serializeDefinition(WorkflowDefinition)
439
+ */
440
+ interface SerializedWorkflowDefinition {
441
+ config: {
442
+ resourceId: string;
443
+ name: string;
444
+ description: string;
445
+ version: string;
446
+ type: 'workflow';
447
+ status: 'dev' | 'prod';
448
+ links?: ResourceLink[];
449
+ category?: ResourceCategory;
450
+ /** Whether this resource is archived and should be excluded from registration and deployment */
451
+ archived?: boolean;
452
+ };
453
+ entryPoint: string;
454
+ steps: Array<{
455
+ id: string;
456
+ name: string;
457
+ description: string;
458
+ inputSchema?: object;
459
+ outputSchema?: object;
460
+ next: {
461
+ type: 'linear' | 'conditional';
462
+ target?: string;
463
+ routes?: Array<{
464
+ target: string;
465
+ }>;
466
+ default?: string;
467
+ } | null;
468
+ }>;
469
+ contract: {
470
+ inputSchema: object;
471
+ outputSchema?: object;
472
+ };
473
+ metricsConfig?: object;
474
+ }
475
+
465
476
  /**
466
477
  * Resource Registry type definitions
467
478
  */
@@ -1,3 +1,3 @@
1
- export { AGENT_CONSTANTS, CONTAINER_CONSTANTS, SHARED_VIZ_CONSTANTS, STATUS_COLORS, TIMELINE_CONSTANTS, WORKFLOW_CONSTANTS, calculateBarPosition, formatDuration, getEdgeColor, getEdgeOpacity, getResourceStatusColor, getStatusColors, getStatusIcon, shouldAnimateEdge, useAgentIterationData, useExecutionPath, useMergedExecution, useReactFlowAgent, useTimelineData, useUnifiedWorkflowLayout, useWorkflowStepsLayout } from '../chunk-I3CFGE3N.js';
2
- import '../chunk-KRWALB24.js';
1
+ export { AGENT_CONSTANTS, CONTAINER_CONSTANTS, SHARED_VIZ_CONSTANTS, STATUS_COLORS, TIMELINE_CONSTANTS, WORKFLOW_CONSTANTS, calculateBarPosition, formatDuration, getEdgeColor, getEdgeOpacity, getResourceStatusColor, getStatusColors, getStatusIcon, shouldAnimateEdge, useAgentIterationData, useExecutionPath, useMergedExecution, useReactFlowAgent, useTimelineData, useUnifiedWorkflowLayout, useWorkflowStepsLayout } from '../chunk-BLXJEIQS.js';
2
+ import '../chunk-6SSQGWK7.js';
3
3
  import '../chunk-I2KLQ2HA.js';
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
3
  import { z } from 'zod';
4
+ import { QueryKey } from '@tanstack/react-query';
4
5
 
5
6
  type Json = string | number | boolean | null | {
6
7
  [key: string]: Json | undefined;
@@ -2746,6 +2747,7 @@ type Database = {
2746
2747
  deleted_at: string | null;
2747
2748
  ended_at: string | null;
2748
2749
  memory_snapshot: Json;
2750
+ memory_version: number;
2749
2751
  metadata: Json | null;
2750
2752
  organization_id: string;
2751
2753
  resource_id: string;
@@ -2762,6 +2764,7 @@ type Database = {
2762
2764
  deleted_at?: string | null;
2763
2765
  ended_at?: string | null;
2764
2766
  memory_snapshot: Json;
2767
+ memory_version?: number;
2765
2768
  metadata?: Json | null;
2766
2769
  organization_id: string;
2767
2770
  resource_id: string;
@@ -2778,6 +2781,7 @@ type Database = {
2778
2781
  deleted_at?: string | null;
2779
2782
  ended_at?: string | null;
2780
2783
  memory_snapshot?: Json;
2784
+ memory_version?: number;
2781
2785
  metadata?: Json | null;
2782
2786
  organization_id?: string;
2783
2787
  resource_id?: string;
@@ -3115,9 +3119,14 @@ type Database = {
3115
3119
  p_session_id: string;
3116
3120
  };
3117
3121
  Returns: {
3122
+ context_window_size: number;
3118
3123
  created_at: string;
3124
+ cumulative_input_tokens: number;
3125
+ cumulative_output_tokens: number;
3126
+ deleted_at: string;
3119
3127
  ended_at: string;
3120
3128
  memory_snapshot: Json;
3129
+ memory_version: number;
3121
3130
  metadata: Json;
3122
3131
  organization_id: string;
3123
3132
  resource_id: string;
@@ -3159,6 +3168,18 @@ type Database = {
3159
3168
  };
3160
3169
  Returns: boolean;
3161
3170
  };
3171
+ increment_session_tokens: {
3172
+ Args: {
3173
+ p_input_tokens: number;
3174
+ p_output_tokens: number;
3175
+ p_session_id: string;
3176
+ };
3177
+ Returns: {
3178
+ context_window_size: number;
3179
+ cumulative_input_tokens: number;
3180
+ cumulative_output_tokens: number;
3181
+ }[];
3182
+ };
3162
3183
  is_org_member: {
3163
3184
  Args: {
3164
3185
  org_id: string;
@@ -3270,6 +3291,12 @@ interface AccessAnswer {
3270
3291
  reason: AccessReason;
3271
3292
  }
3272
3293
 
3294
+ /**
3295
+ * Canonical initialization types, owned here next to {@link InitializationProvider}
3296
+ * (the live, wired implementation). The legacy `createUseAppInitialization`
3297
+ * factory in `./hooks/useAppInitialization.ts` imports these rather than
3298
+ * declaring its own copy, so the two implementations can never drift on shape.
3299
+ */
3273
3300
  interface InitializationError {
3274
3301
  layer: 'auth' | 'profile' | 'organization';
3275
3302
  message: string;
@@ -3298,8 +3325,9 @@ interface ProtectedRouteProps {
3298
3325
  /**
3299
3326
  * When true, waits for both user AND organization to be ready before
3300
3327
  * rendering children. When false, only waits for user readiness.
3301
- * Standalone apps typically use false; multi-tenant apps use true.
3302
- * @default false CC overrides to true in its wrapper
3328
+ * @default true -- see {@link DEFAULT_WAIT_FOR_ORGANIZATION}. The same
3329
+ * default is used by the base `@repo/ui/auth` guard this component wraps,
3330
+ * so behavior is identical regardless of which of the two you import.
3303
3331
  */
3304
3332
  waitForOrganization?: boolean;
3305
3333
  }
@@ -3307,10 +3335,13 @@ interface ProtectedRouteProps {
3307
3335
  * Shared ProtectedRoute — thin wrapper around the base guard from @repo/ui/auth.
3308
3336
  *
3309
3337
  * Renders an animated full-screen loader (fade-out on completion) and forwards
3310
- * errorFallback to the base guard. When waitForOrganization is false (default),
3311
- * the loader dismisses as soon as user auth is ready, allowing pages to handle
3312
- * the no-org state themselves. When true, the loader persists until both user
3313
- * and organization are ready.
3338
+ * errorFallback to the base guard. Loader visibility is derived from
3339
+ * {@link computeProtectedRouteGate} the same predicate the base guard uses
3340
+ * to decide whether to render children — so the loader and the guard's
3341
+ * render decision cannot drift apart. When waitForOrganization is true
3342
+ * (default), the loader persists until both user and organization are ready;
3343
+ * when false, it dismisses as soon as user auth is ready, leaving pages to
3344
+ * handle the no-org state themselves.
3314
3345
  *
3315
3346
  * Intentionally excludes onboarding gate logic — apps that need it (e.g.
3316
3347
  * Command Center) should wrap this component and add their own gate inside.
@@ -3369,18 +3400,103 @@ interface UseUserProfileReturn {
3369
3400
  error: Error | null;
3370
3401
  refetch: () => Promise<void>;
3371
3402
  }
3403
+ /**
3404
+ * Canonical TanStack Query key for the current user's profile.
3405
+ *
3406
+ * Every consumer (ProfileProvider, Command Center's root layout, the
3407
+ * onboarding gate, the welcome flow, account settings, ...) reads and writes
3408
+ * this exact key, so they share one cache entry instead of each issuing an
3409
+ * independent `/users/me/sync` call. Not user-scoped: a full sign-out /
3410
+ * sign-in cycle in this app navigates through WorkOS (a real page load),
3411
+ * which tears down the QueryClient, so no explicit user id is needed to
3412
+ * avoid stale cross-user reads within a single session.
3413
+ */
3414
+ declare const USER_PROFILE_QUERY_KEY: QueryKey;
3372
3415
  /**
3373
3416
  * Hook for managing user profile data with automatic WorkOS -> Supabase sync
3374
3417
  *
3375
- * This hook:
3418
+ * Backed by a single shared TanStack Query cache entry keyed on
3419
+ * {@link USER_PROFILE_QUERY_KEY}. This hook:
3376
3420
  * 1. Automatically syncs WorkOS user data to Supabase on authentication
3377
3421
  * 2. Provides access to the user's Supabase profile data
3378
3422
  * 3. Handles loading states and errors
3379
3423
  * 4. Includes a refetch function for manual updates
3380
3424
  *
3425
+ * Because every consumer queries the same key, calling this hook from
3426
+ * multiple places in the tree (directly or via `useProfile()`) triggers at
3427
+ * most one `/users/me/sync` request per session — later mounts simply read
3428
+ * the cached result. Call `refetch()` (or invalidate {@link USER_PROFILE_QUERY_KEY}
3429
+ * via `useQueryClient()`) to force a fresh sync after a mutation that changes
3430
+ * the profile, e.g. completing onboarding.
3431
+ *
3381
3432
  * @param options - Optional configuration including error handler and apiRequest
3382
3433
  */
3383
3434
  declare const useUserProfile: (options?: UseUserProfileOptions) => UseUserProfileReturn;
3384
3435
 
3385
- export { AccessGuard, AuthRedirectLoadingScreen, ProtectedRoute, useUserProfile };
3386
- export type { AccessGuardProps, AuthRedirectLoadingScreenProps, ProtectedRouteProps, UseUserProfileReturn };
3436
+ /**
3437
+ * Which WorkOS hosted screen an invited user should land on. Set by the platform's
3438
+ * invite router (`GET /api/invite`), which looks the email up in WorkOS at click
3439
+ * time and appends the answer to this route's URL.
3440
+ */
3441
+ type AuthMode = 'signin' | 'signup';
3442
+ interface LoginSearchParams {
3443
+ returnTo?: string;
3444
+ context?: string;
3445
+ invitation_token?: string;
3446
+ mode?: AuthMode;
3447
+ }
3448
+ /**
3449
+ * TanStack Router `validateSearch` for the `/login` route. Export it alongside
3450
+ * `LoginScreen` so every project's route file can wire both in directly:
3451
+ *
3452
+ * ```tsx
3453
+ * export const Route = createFileRoute('/login')({
3454
+ * component: () => <LoginScreen ... />,
3455
+ * validateSearch: validateLoginSearch
3456
+ * })
3457
+ * ```
3458
+ */
3459
+ declare function validateLoginSearch(search: Record<string, unknown>): LoginSearchParams;
3460
+ interface LoginScreenAppConfig {
3461
+ /**
3462
+ * WorkOS organization id for single-org deployments. Tenant route stubs pass
3463
+ * `__ELEVASIS_WORKOS_ORG_ID__` — the build-time constant the `elevasisVite()`
3464
+ * plugin injects from the project's `.elevasis` marker. Command Center omits
3465
+ * this prop entirely, matching its existing login route, which never binds a
3466
+ * single WorkOS organization.
3467
+ */
3468
+ workosOrganizationId?: string;
3469
+ }
3470
+ interface LoginScreenProps {
3471
+ /** Logo shown when the active Mantine color scheme is light. */
3472
+ lightModeLogo: string;
3473
+ /** Logo shown when the active Mantine color scheme is dark. */
3474
+ darkModeLogo: string;
3475
+ /** Application or company name shown in the heading and used for the logo alt text. */
3476
+ appName: string;
3477
+ /**
3478
+ * Project-specific auth configuration that is not presentation. Currently
3479
+ * only carries the WorkOS organization id — see `LoginScreenAppConfig`.
3480
+ */
3481
+ appConfig?: LoginScreenAppConfig;
3482
+ }
3483
+ /**
3484
+ * Shared login screen: the WorkOS-hosted sign-in/sign-up entry point.
3485
+ *
3486
+ * Owns the invitation-token branch, the WorkOS `context` branch, `returnTo`
3487
+ * state handling, and the authenticated-user redirect — logic that was
3488
+ * previously duplicated verbatim across five project-local `login.tsx` route
3489
+ * files. Each project keeps only a thin route stub that supplies branding and
3490
+ * registers the route:
3491
+ *
3492
+ * ```tsx
3493
+ * export const Route = createFileRoute('/login')({
3494
+ * component: () => <LoginScreen lightModeLogo={...} darkModeLogo={...} appName={...} />,
3495
+ * validateSearch: validateLoginSearch
3496
+ * })
3497
+ * ```
3498
+ */
3499
+ declare function LoginScreen({ lightModeLogo, darkModeLogo, appName, appConfig }: LoginScreenProps): react_jsx_runtime.JSX.Element;
3500
+
3501
+ export { AccessGuard, AuthRedirectLoadingScreen, LoginScreen, ProtectedRoute, USER_PROFILE_QUERY_KEY, useUserProfile, validateLoginSearch };
3502
+ export type { AccessGuardProps, AuthMode, AuthRedirectLoadingScreenProps, LoginScreenAppConfig, LoginScreenProps, LoginSearchParams, ProtectedRouteProps, UseUserProfileReturn };
@@ -1,35 +1,38 @@
1
- import { ProtectedRoute, AppearanceContext, AppShellError, useAppearance } from '../../chunk-PGAA4G3T.js';
2
- export { AccessGuard } from '../../chunk-PGAA4G3T.js';
1
+ import { computeProtectedRouteGate, DEFAULT_WAIT_FOR_ORGANIZATION, ProtectedRoute, AppearanceContext, useAppearance, AppShellError } from '../../chunk-ANNM5R7S.js';
2
+ export { AccessGuard } from '../../chunk-ANNM5R7S.js';
3
3
  import '../../chunk-4OEVLV66.js';
4
4
  import '../../chunk-RBGVNPA6.js';
5
- import '../../chunk-ZTWA5H77.js';
5
+ import '../../chunk-6ZAP3FOA.js';
6
6
  import '../../chunk-AUDNF2Q7.js';
7
7
  import '../../chunk-6M6OLGQY.js';
8
8
  import '../../chunk-MKH2KOAO.js';
9
9
  import '../../chunk-XNW3O6QW.js';
10
- import '../../chunk-T4LA4RY2.js';
10
+ import '../../chunk-L7BZZ4SI.js';
11
11
  import '../../chunk-GMXGDO3I.js';
12
12
  import '../../chunk-62GVNH5U.js';
13
- import { useInitialization } from '../../chunk-LO7GWG24.js';
13
+ import { useInitialization } from '../../chunk-P45GQ3ZW.js';
14
14
  import '../../chunk-DD3CCMCZ.js';
15
15
  import '../../chunk-M7WWRZ5Z.js';
16
16
  import '../../chunk-JFBZ6XDW.js';
17
17
  import '../../chunk-2IFYDILW.js';
18
18
  import '../../chunk-Q7DJKLEN.js';
19
19
  import '../../chunk-HENXLGVD.js';
20
- import '../../chunk-I3CFGE3N.js';
20
+ import '../../chunk-BLXJEIQS.js';
21
21
  import '../../chunk-RNP5R5I3.js';
22
- export { useUserProfile } from '../../chunk-EIXSQONC.js';
22
+ export { USER_PROFILE_QUERY_KEY, useUserProfile } from '../../chunk-RT4KRGZT.js';
23
23
  import '../../chunk-I7BZVVVU.js';
24
- import '../../chunk-FVOMKZ7S.js';
25
- import '../../chunk-KRWALB24.js';
24
+ import '../../chunk-Y6I3IC45.js';
25
+ import '../../chunk-6SSQGWK7.js';
26
26
  import '../../chunk-BI5VDO2K.js';
27
27
  import '../../chunk-MQZE7SUI.js';
28
28
  import '../../chunk-TVTSASST.js';
29
29
  import '../../chunk-BRJ3QZ4E.js';
30
30
  import '../../chunk-I2KLQ2HA.js';
31
- import { useContext, useState, useRef, useEffect, useCallback } from 'react';
31
+ import { useContext, useEffect, useState, useRef, useCallback } from 'react';
32
32
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
33
+ import { useRouter, useSearch } from '@tanstack/react-router';
34
+ import { useAuth } from '@workos-inc/authkit-react';
35
+ import { useMantineColorScheme, Container, Center, Paper, Stack, Text, Button, Image } from '@mantine/core';
33
36
 
34
37
  function FullScreenLoader({ hiding, onHidden }) {
35
38
  const { background, loader } = useAppearance();
@@ -82,11 +85,16 @@ function ProtectedRoute2({
82
85
  redirectTo = "/login",
83
86
  fallback,
84
87
  errorFallback,
85
- waitForOrganization = false
88
+ waitForOrganization = DEFAULT_WAIT_FOR_ORGANIZATION
86
89
  }) {
87
90
  const { isInitializing, userReady, allReady, error } = useInitialization();
88
- const orgSettled = allReady || error?.layer === "organization";
89
- const showLoader = !error && (isInitializing || !userReady || waitForOrganization && !orgSettled);
91
+ const { showFallback: showLoader } = computeProtectedRouteGate({
92
+ isInitializing,
93
+ userReady,
94
+ allReady,
95
+ error,
96
+ waitForOrganization
97
+ });
90
98
  const resolvedErrorFallback = errorFallback ?? ((err, retry) => /* @__PURE__ */ jsx(AppShellError, { message: err.message, retry }));
91
99
  return /* @__PURE__ */ jsxs(Fragment, { children: [
92
100
  fallback ? showLoader ? fallback : null : /* @__PURE__ */ jsx(AnimatedLoader, { showLoader }),
@@ -139,5 +147,137 @@ function AuthRedirectLoadingScreen({
139
147
  }
140
148
  );
141
149
  }
150
+ function getStringSearchParam(value) {
151
+ return typeof value === "string" ? value : void 0;
152
+ }
153
+ function getAuthModeSearchParam(value) {
154
+ return value === "signin" || value === "signup" ? value : void 0;
155
+ }
156
+ function validateLoginSearch(search) {
157
+ return {
158
+ returnTo: getStringSearchParam(search.returnTo),
159
+ context: getStringSearchParam(search.context),
160
+ invitation_token: getStringSearchParam(search.invitation_token),
161
+ mode: getAuthModeSearchParam(search.mode)
162
+ };
163
+ }
164
+ function LoginScreen({ lightModeLogo, darkModeLogo, appName, appConfig }) {
165
+ const { user, isLoading, signIn, signUp } = useAuth();
166
+ const { colorScheme } = useMantineColorScheme();
167
+ const router = useRouter();
168
+ const {
169
+ returnTo,
170
+ context,
171
+ invitation_token: invitationToken,
172
+ mode
173
+ } = useSearch({
174
+ strict: false
175
+ });
176
+ const { background, loader } = useAppearance();
177
+ const workosOrganizationId = appConfig?.workosOrganizationId;
178
+ useEffect(() => {
179
+ if (invitationToken) {
180
+ const startAuth = mode === "signin" ? signIn : signUp;
181
+ startAuth({
182
+ invitationToken,
183
+ state: returnTo ? { returnTo } : void 0,
184
+ ...workosOrganizationId && { organizationId: workosOrganizationId }
185
+ });
186
+ return;
187
+ }
188
+ if (context) {
189
+ signIn({
190
+ context,
191
+ state: returnTo ? { returnTo } : void 0,
192
+ ...workosOrganizationId && { organizationId: workosOrganizationId }
193
+ });
194
+ return;
195
+ }
196
+ }, [invitationToken, context, mode, signIn, signUp, returnTo, workosOrganizationId]);
197
+ useEffect(() => {
198
+ if (user && !isLoading) {
199
+ const destination = returnTo || "/";
200
+ router.navigate({ to: destination });
201
+ }
202
+ }, [user, isLoading, router, returnTo]);
203
+ if (invitationToken) {
204
+ return /* @__PURE__ */ jsx(AuthRedirectLoadingScreen, { testId: "invitation-redirect-loading" });
205
+ }
206
+ if (user) {
207
+ return /* @__PURE__ */ jsx(Container, { size: "sm", style: { minHeight: "100vh", display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx(Center, { style: { width: "100%" }, children: /* @__PURE__ */ jsx(Paper, { shadow: "sm", style: { minWidth: "400px" }, children: /* @__PURE__ */ jsxs(Stack, { align: "center", children: [
208
+ /* @__PURE__ */ jsx(Text, { size: "lg", fw: 600, style: { fontFamily: "var(--mantine-font-family-headings)" }, children: "Welcome back!" }),
209
+ /* @__PURE__ */ jsxs(Text, { c: "dimmed", ta: "center", children: [
210
+ "You are already signed in as ",
211
+ user.email
212
+ ] }),
213
+ /* @__PURE__ */ jsx(Button, { onClick: () => router.navigate({ to: "/" }), variant: "filled", children: "Continue to App" })
214
+ ] }) }) }) });
215
+ }
216
+ if (isLoading) {
217
+ return /* @__PURE__ */ jsxs(
218
+ "div",
219
+ {
220
+ style: {
221
+ height: "100vh",
222
+ display: "flex",
223
+ alignItems: "center",
224
+ justifyContent: "center",
225
+ backgroundColor: "var(--color-background)",
226
+ position: "relative"
227
+ },
228
+ children: [
229
+ background,
230
+ /* @__PURE__ */ jsx("div", { style: { zIndex: 1 }, children: loader })
231
+ ]
232
+ }
233
+ );
234
+ }
235
+ return /* @__PURE__ */ jsxs(
236
+ "div",
237
+ {
238
+ style: {
239
+ height: "100vh",
240
+ display: "flex",
241
+ alignItems: "center",
242
+ justifyContent: "center",
243
+ backgroundColor: "var(--color-background)",
244
+ position: "relative"
245
+ },
246
+ children: [
247
+ background,
248
+ /* @__PURE__ */ jsx(Center, { style: { width: "100%", zIndex: 1 }, children: /* @__PURE__ */ jsx(Paper, { shadow: "sm", style: { minWidth: "400px" }, children: /* @__PURE__ */ jsxs(Stack, { align: "center", children: [
249
+ /* @__PURE__ */ jsx(
250
+ Image,
251
+ {
252
+ src: colorScheme === "dark" ? darkModeLogo : lightModeLogo,
253
+ alt: `${appName} Logo`,
254
+ h: 50,
255
+ w: "auto",
256
+ fit: "contain"
257
+ }
258
+ ),
259
+ /* @__PURE__ */ jsxs(Text, { size: "xl", fw: 600, style: { fontFamily: "var(--mantine-font-family-headings)" }, children: [
260
+ "Sign In to ",
261
+ appName
262
+ ] }),
263
+ /* @__PURE__ */ jsx(
264
+ Button,
265
+ {
266
+ onClick: () => signIn({
267
+ state: returnTo ? { returnTo } : void 0,
268
+ ...workosOrganizationId && { organizationId: workosOrganizationId }
269
+ }),
270
+ variant: "filled",
271
+ size: "md",
272
+ fullWidth: true,
273
+ children: "Sign In"
274
+ }
275
+ ),
276
+ /* @__PURE__ */ jsx(Text, { c: "dimmed", ta: "center", size: "sm", children: "Powered by WorkOS for enterprise-grade security" })
277
+ ] }) }) })
278
+ ]
279
+ }
280
+ );
281
+ }
142
282
 
143
- export { AuthRedirectLoadingScreen, ProtectedRoute2 as ProtectedRoute };
283
+ export { AuthRedirectLoadingScreen, LoginScreen, ProtectedRoute2 as ProtectedRoute, validateLoginSearch };