@mdxui/auth 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,8 +44,10 @@ function Dashboard() {
44
44
 
45
45
  - **Authentication Providers** - `IdentityProvider` and `AuthGate` for managing auth state
46
46
  - **WorkOS Widgets** - Pre-built components for user management (profile, security, API keys)
47
+ - **Vault Components** - UI for managing encrypted secrets with `VaultProvider`
48
+ - **Secrets Manager** - Full-featured secrets management widget
47
49
  - **Type-Safe Schemas** - Zod schemas extending mdxui's `UserIdentity` and `Session` types
48
- - **React Hooks** - `useAuth` and `useWidgetToken` for accessing auth state
50
+ - **React Hooks** - `useAuth`, `useWidgetToken`, and `useVault` for accessing state
49
51
  - **UI Components** - Sign in/out buttons, user menu, team switcher
50
52
 
51
53
  ## Exports
@@ -61,6 +63,7 @@ import {
61
63
  IdentityProviderMinimal,
62
64
  AuthGate,
63
65
  WidgetsProvider,
66
+ VaultProvider,
64
67
 
65
68
  // Widgets
66
69
  UserProfile,
@@ -70,6 +73,14 @@ import {
70
73
  UsersManagement,
71
74
  OrganizationSwitcher,
72
75
 
76
+ // Vault Components
77
+ VaultList,
78
+ VaultItemCard,
79
+ VaultInputModal,
80
+ VaultDeleteDialog,
81
+ VaultEmptyState,
82
+ SecretsManager,
83
+
73
84
  // Components
74
85
  SignInButton,
75
86
  SignOutButton,
@@ -79,6 +90,8 @@ import {
79
90
  // Hooks
80
91
  useAuth,
81
92
  useWidgetToken,
93
+ useVault,
94
+ useVaultContext,
82
95
 
83
96
  // Schemas
84
97
  AuthUserSchema,
@@ -92,6 +105,9 @@ import type {
92
105
  AuthSession,
93
106
  AuthOrganization,
94
107
  AuthToken,
108
+ VaultClient,
109
+ VaultItem,
110
+ VaultField,
95
111
  } from '@mdxui/auth'
96
112
  ```
97
113
 
@@ -291,6 +307,117 @@ function ApiKeysWidget() {
291
307
  }
292
308
  ```
293
309
 
310
+ ## Vault Components
311
+
312
+ @mdxui/auth includes components for managing encrypted secrets via WorkOS Vault.
313
+
314
+ ### VaultProvider
315
+
316
+ Wrap your app with `VaultProvider` to enable vault functionality:
317
+
318
+ ```tsx
319
+ import { VaultProvider, useVault } from '@mdxui/auth'
320
+
321
+ function App() {
322
+ const vaultClient = useMyVaultClient() // Your vault client implementation
323
+
324
+ return (
325
+ <VaultProvider client={vaultClient}>
326
+ <SecretsPage />
327
+ </VaultProvider>
328
+ )
329
+ }
330
+ ```
331
+
332
+ ### useVault Hook
333
+
334
+ Access vault state and operations:
335
+
336
+ ```tsx
337
+ function SecretsPage() {
338
+ const {
339
+ items, // Array of vault items
340
+ isLoading, // Loading state
341
+ error, // Error message if any
342
+ createItem, // Create new secret
343
+ updateItem, // Update existing secret
344
+ deleteItem, // Delete a secret
345
+ refresh, // Refresh the list
346
+ } = useVault()
347
+
348
+ return <VaultList items={items} onRefresh={refresh} />
349
+ }
350
+ ```
351
+
352
+ ### Vault UI Components
353
+
354
+ Pre-built components for secrets management:
355
+
356
+ ```tsx
357
+ import {
358
+ VaultList,
359
+ VaultItemCard,
360
+ VaultInputModal,
361
+ VaultDeleteDialog,
362
+ VaultEmptyState,
363
+ } from '@mdxui/auth'
364
+
365
+ function SecretsManager() {
366
+ const { items, isLoading, createItem, deleteItem } = useVault()
367
+ const [showCreate, setShowCreate] = useState(false)
368
+ const [deleteTarget, setDeleteTarget] = useState(null)
369
+
370
+ if (isLoading) return <Spinner />
371
+ if (items.length === 0) return <VaultEmptyState onCreate={() => setShowCreate(true)} />
372
+
373
+ return (
374
+ <>
375
+ <VaultList
376
+ items={items}
377
+ onItemClick={(item) => console.log('View', item)}
378
+ onItemDelete={(item) => setDeleteTarget(item)}
379
+ />
380
+
381
+ <VaultInputModal
382
+ open={showCreate}
383
+ onClose={() => setShowCreate(false)}
384
+ onSubmit={async (data) => {
385
+ await createItem(data)
386
+ setShowCreate(false)
387
+ }}
388
+ />
389
+
390
+ <VaultDeleteDialog
391
+ open={!!deleteTarget}
392
+ item={deleteTarget}
393
+ onClose={() => setDeleteTarget(null)}
394
+ onConfirm={async () => {
395
+ await deleteItem(deleteTarget.id)
396
+ setDeleteTarget(null)
397
+ }}
398
+ />
399
+ </>
400
+ )
401
+ }
402
+ ```
403
+
404
+ ### SecretsManager Widget
405
+
406
+ A complete, ready-to-use secrets management interface:
407
+
408
+ ```tsx
409
+ import { SecretsManager } from '@mdxui/auth'
410
+
411
+ function SettingsPage() {
412
+ return (
413
+ <SecretsManager
414
+ context={{ organizationId: 'org_123' }}
415
+ onSecretChange={(secret) => console.log('Changed:', secret)}
416
+ />
417
+ )
418
+ }
419
+ ```
420
+
294
421
  ## API Reference
295
422
 
296
423
  ### Schemas
@@ -1,5 +1,6 @@
1
1
  export { useAuth } from '@workos-inc/authkit-react';
2
2
  import { U as UseWidgetTokenOptions, b as UseWidgetTokenResult } from '../auth-Ba2f778e.js';
3
+ import { V as VaultItem, a as VaultField } from '../types-8tixck1H.js';
3
4
  import 'react';
4
5
 
5
6
  /**
@@ -39,4 +40,93 @@ import 'react';
39
40
  */
40
41
  declare function useWidgetToken({ widget, organizationId, endpoint, }: UseWidgetTokenOptions): UseWidgetTokenResult;
41
42
 
42
- export { useWidgetToken };
43
+ /**
44
+ * Result from useVault hook
45
+ */
46
+ interface UseVaultResult {
47
+ /** List of vault items */
48
+ items: VaultItem[];
49
+ /** Whether the vault is loading */
50
+ loading: boolean;
51
+ /** Error message if any */
52
+ error: string | null;
53
+ /** Whether a vault client is connected */
54
+ isConnected: boolean;
55
+ /** Reload vault items from the backend */
56
+ reload: () => Promise<void>;
57
+ /** Create a new vault item */
58
+ create: (integrationId: string, credentials: Record<string, string>) => Promise<void>;
59
+ /** Rotate credentials for an existing item */
60
+ rotate: (id: string, credentials: Record<string, string>) => Promise<void>;
61
+ /** Delete a vault item */
62
+ remove: (id: string) => Promise<void>;
63
+ /** Get field configuration for an integration */
64
+ getIntegrationFields: (integrationId: string) => VaultField[];
65
+ /** Find an item by ID */
66
+ findItem: (id: string) => VaultItem | undefined;
67
+ /** Find items by integration ID */
68
+ findByIntegration: (integrationId: string) => VaultItem[];
69
+ }
70
+ /**
71
+ * Hook to access vault state and operations
72
+ *
73
+ * Provides access to the vault context with helper methods for
74
+ * common operations like finding items and managing credentials.
75
+ *
76
+ * Must be used within a VaultProvider.
77
+ *
78
+ * @example
79
+ * ```tsx
80
+ * import { useVault } from '@mdxui/auth'
81
+ *
82
+ * function VaultDashboard() {
83
+ * const {
84
+ * items,
85
+ * loading,
86
+ * create,
87
+ * rotate,
88
+ * remove,
89
+ * findByIntegration,
90
+ * } = useVault()
91
+ *
92
+ * const openaiItems = findByIntegration('openai')
93
+ *
94
+ * const handleCreate = async () => {
95
+ * await create('github', { personal_access_token: 'ghp_...' })
96
+ * }
97
+ *
98
+ * if (loading) return <div>Loading...</div>
99
+ *
100
+ * return (
101
+ * <ul>
102
+ * {items.map(item => (
103
+ * <li key={item.id}>{item.name}</li>
104
+ * ))}
105
+ * </ul>
106
+ * )
107
+ * }
108
+ * ```
109
+ */
110
+ declare function useVault(): UseVaultResult;
111
+ /**
112
+ * Optional vault hook that returns null if not within a VaultProvider
113
+ *
114
+ * Useful for components that can optionally integrate with the vault
115
+ * when it's available.
116
+ *
117
+ * @example
118
+ * ```tsx
119
+ * function MaybeVaultComponent() {
120
+ * const vault = useVaultOptional()
121
+ *
122
+ * if (!vault) {
123
+ * return <div>Vault not available</div>
124
+ * }
125
+ *
126
+ * return <VaultList items={vault.items} ... />
127
+ * }
128
+ * ```
129
+ */
130
+ declare function useVaultOptional(): UseVaultResult | null;
131
+
132
+ export { type UseVaultResult, useVault, useVaultOptional, useWidgetToken };
@@ -36,8 +36,92 @@ function useWidgetToken({
36
36
  }, [fetchToken]);
37
37
  return { token, loading, error, refetch: fetchToken };
38
38
  }
39
+
40
+ // src/hooks/use-vault.ts
41
+ import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
42
+
43
+ // src/providers/vault-provider.tsx
44
+ import { createContext, useContext, useMemo } from "react";
45
+ import { jsx } from "react/jsx-runtime";
46
+ var VaultContext = createContext(null);
47
+ function useVaultContext() {
48
+ const context = useContext(VaultContext);
49
+ if (!context) {
50
+ throw new Error("useVaultContext must be used within a VaultProvider");
51
+ }
52
+ return context;
53
+ }
54
+ function useVaultContextOptional() {
55
+ return useContext(VaultContext);
56
+ }
57
+
58
+ // src/hooks/use-vault.ts
59
+ function useVault() {
60
+ const context = useVaultContext();
61
+ const findItem = useCallback2(
62
+ (id) => {
63
+ return context.items.find((item) => item.id === id);
64
+ },
65
+ [context.items]
66
+ );
67
+ const findByIntegration = useCallback2(
68
+ (integrationId) => {
69
+ return context.items.filter((item) => item.integrationId === integrationId);
70
+ },
71
+ [context.items]
72
+ );
73
+ return useMemo2(
74
+ () => ({
75
+ items: context.items,
76
+ loading: context.loading,
77
+ error: context.error,
78
+ isConnected: context.client !== null,
79
+ reload: context.reload,
80
+ create: context.createItem,
81
+ rotate: context.rotateItem,
82
+ remove: context.deleteItem,
83
+ getIntegrationFields: context.getIntegrationFields,
84
+ findItem,
85
+ findByIntegration
86
+ }),
87
+ [context, findItem, findByIntegration]
88
+ );
89
+ }
90
+ function useVaultOptional() {
91
+ const context = useVaultContextOptional();
92
+ const findItem = useCallback2(
93
+ (id) => {
94
+ return context?.items.find((item) => item.id === id);
95
+ },
96
+ [context?.items]
97
+ );
98
+ const findByIntegration = useCallback2(
99
+ (integrationId) => {
100
+ return context?.items.filter((item) => item.integrationId === integrationId) ?? [];
101
+ },
102
+ [context?.items]
103
+ );
104
+ if (!context) {
105
+ return null;
106
+ }
107
+ return {
108
+ items: context.items,
109
+ loading: context.loading,
110
+ error: context.error,
111
+ isConnected: context.client !== null,
112
+ reload: context.reload,
113
+ create: context.createItem,
114
+ rotate: context.rotateItem,
115
+ remove: context.deleteItem,
116
+ getIntegrationFields: context.getIntegrationFields,
117
+ findItem,
118
+ findByIntegration
119
+ };
120
+ }
39
121
  export {
40
122
  useAuth,
123
+ useVault,
124
+ useVaultOptional,
41
125
  useWidgetToken
42
126
  };
43
127
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hooks/use-auth.ts","../../src/hooks/use-widget-token.ts"],"sourcesContent":["'use client'\n\n/**\n * Re-export useAuth from WorkOS AuthKit\n *\n * This hook provides access to the authentication state and methods:\n * - user: The authenticated user object\n * - isLoading: Whether auth state is being loaded\n * - signIn: Function to initiate sign in\n * - signOut: Function to sign out\n * - getAccessToken: Function to get the current access token\n * - organizationId: Current organization ID (if in org context)\n * - permissions: User's permissions array\n *\n * @example\n * ```tsx\n * import { useAuth } from '@mdxui/auth'\n *\n * function MyComponent() {\n * const { user, isLoading, signIn, signOut, getAccessToken } = useAuth()\n *\n * if (isLoading) return <div>Loading...</div>\n * if (!user) return <button onClick={() => signIn()}>Sign In</button>\n *\n * return (\n * <div>\n * <p>Hello, {user.firstName}!</p>\n * <button onClick={() => signOut()}>Sign Out</button>\n * </div>\n * )\n * }\n * ```\n */\nexport { useAuth } from '@workos-inc/authkit-react'\n","'use client'\n\nimport { useCallback, useEffect, useState } from 'react'\nimport type { UseWidgetTokenOptions, UseWidgetTokenResult } from '../types/auth'\n\n/**\n * Hook to fetch authorization tokens for WorkOS widgets\n *\n * Use this hook when you need to fetch widget tokens from a backend endpoint,\n * typically for server-side auth scenarios. For client-side AuthKit usage,\n * you can use `getAccessToken` from `useAuth()` directly with widgets.\n *\n * @param options - Options for token fetching\n * @param options.widget - The widget type (user-profile, user-security, api-keys, etc.)\n * @param options.organizationId - Optional organization context\n * @param options.endpoint - Custom endpoint (default: /api/workos/widget-token)\n * @returns Token state and refetch function\n *\n * @example\n * ```tsx\n * // Server-side token fetching (via backend endpoint)\n * const { token, loading, error } = useWidgetToken({\n * widget: 'user-profile',\n * })\n *\n * if (loading) return <Spinner />\n * if (error) return <Error message={error} />\n * return <UserProfile authToken={token!} />\n * ```\n *\n * @example\n * ```tsx\n * // Client-side AuthKit (recommended - no backend needed)\n * import { useAuth } from '@mdxui/auth'\n * import { UserProfile } from '@mdxui/auth/widgets'\n *\n * const { getAccessToken } = useAuth()\n * return <UserProfile authToken={getAccessToken} />\n * ```\n */\nexport function useWidgetToken({\n widget,\n organizationId,\n endpoint = '/api/workos/widget-token',\n}: UseWidgetTokenOptions): UseWidgetTokenResult {\n const [token, setToken] = useState<string | null>(null)\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState<string | null>(null)\n\n const fetchToken = useCallback(async () => {\n try {\n setLoading(true)\n setError(null)\n\n const params = new URLSearchParams({ widget })\n if (organizationId) {\n params.set('organizationId', organizationId)\n }\n\n const response = await fetch(`${endpoint}?${params}`)\n const data = await response.json()\n\n if (!response.ok) {\n throw new Error(data.error || 'Failed to fetch token')\n }\n\n setToken(data.token)\n } catch (err) {\n setError(err instanceof Error ? err.message : 'Token fetch failed')\n } finally {\n setLoading(false)\n }\n }, [widget, organizationId, endpoint])\n\n useEffect(() => {\n fetchToken()\n }, [fetchToken])\n\n return { token, loading, error, refetch: fetchToken }\n}\n"],"mappings":";AAiCA,SAAS,eAAe;;;AC/BxB,SAAS,aAAa,WAAW,gBAAgB;AAsC1C,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA,WAAW;AACb,GAAgD;AAC9C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AACtD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,IAAI;AAC3C,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,IAAI;AAEtD,QAAM,aAAa,YAAY,YAAY;AACzC,QAAI;AACF,iBAAW,IAAI;AACf,eAAS,IAAI;AAEb,YAAM,SAAS,IAAI,gBAAgB,EAAE,OAAO,CAAC;AAC7C,UAAI,gBAAgB;AAClB,eAAO,IAAI,kBAAkB,cAAc;AAAA,MAC7C;AAEA,YAAM,WAAW,MAAM,MAAM,GAAG,QAAQ,IAAI,MAAM,EAAE;AACpD,YAAM,OAAO,MAAM,SAAS,KAAK;AAEjC,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,IAAI,MAAM,KAAK,SAAS,uBAAuB;AAAA,MACvD;AAEA,eAAS,KAAK,KAAK;AAAA,IACrB,SAAS,KAAK;AACZ,eAAS,eAAe,QAAQ,IAAI,UAAU,oBAAoB;AAAA,IACpE,UAAE;AACA,iBAAW,KAAK;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,QAAQ,gBAAgB,QAAQ,CAAC;AAErC,YAAU,MAAM;AACd,eAAW;AAAA,EACb,GAAG,CAAC,UAAU,CAAC;AAEf,SAAO,EAAE,OAAO,SAAS,OAAO,SAAS,WAAW;AACtD;","names":[]}
1
+ {"version":3,"sources":["../../src/hooks/use-auth.ts","../../src/hooks/use-widget-token.ts","../../src/hooks/use-vault.ts","../../src/providers/vault-provider.tsx"],"sourcesContent":["'use client'\n\n/**\n * Re-export useAuth from WorkOS AuthKit\n *\n * This hook provides access to the authentication state and methods:\n * - user: The authenticated user object\n * - isLoading: Whether auth state is being loaded\n * - signIn: Function to initiate sign in\n * - signOut: Function to sign out\n * - getAccessToken: Function to get the current access token\n * - organizationId: Current organization ID (if in org context)\n * - permissions: User's permissions array\n *\n * @example\n * ```tsx\n * import { useAuth } from '@mdxui/auth'\n *\n * function MyComponent() {\n * const { user, isLoading, signIn, signOut, getAccessToken } = useAuth()\n *\n * if (isLoading) return <div>Loading...</div>\n * if (!user) return <button onClick={() => signIn()}>Sign In</button>\n *\n * return (\n * <div>\n * <p>Hello, {user.firstName}!</p>\n * <button onClick={() => signOut()}>Sign Out</button>\n * </div>\n * )\n * }\n * ```\n */\nexport { useAuth } from '@workos-inc/authkit-react'\n","'use client'\n\nimport { useCallback, useEffect, useState } from 'react'\nimport type { UseWidgetTokenOptions, UseWidgetTokenResult } from '../types/auth'\n\n/**\n * Hook to fetch authorization tokens for WorkOS widgets\n *\n * Use this hook when you need to fetch widget tokens from a backend endpoint,\n * typically for server-side auth scenarios. For client-side AuthKit usage,\n * you can use `getAccessToken` from `useAuth()` directly with widgets.\n *\n * @param options - Options for token fetching\n * @param options.widget - The widget type (user-profile, user-security, api-keys, etc.)\n * @param options.organizationId - Optional organization context\n * @param options.endpoint - Custom endpoint (default: /api/workos/widget-token)\n * @returns Token state and refetch function\n *\n * @example\n * ```tsx\n * // Server-side token fetching (via backend endpoint)\n * const { token, loading, error } = useWidgetToken({\n * widget: 'user-profile',\n * })\n *\n * if (loading) return <Spinner />\n * if (error) return <Error message={error} />\n * return <UserProfile authToken={token!} />\n * ```\n *\n * @example\n * ```tsx\n * // Client-side AuthKit (recommended - no backend needed)\n * import { useAuth } from '@mdxui/auth'\n * import { UserProfile } from '@mdxui/auth/widgets'\n *\n * const { getAccessToken } = useAuth()\n * return <UserProfile authToken={getAccessToken} />\n * ```\n */\nexport function useWidgetToken({\n widget,\n organizationId,\n endpoint = '/api/workos/widget-token',\n}: UseWidgetTokenOptions): UseWidgetTokenResult {\n const [token, setToken] = useState<string | null>(null)\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState<string | null>(null)\n\n const fetchToken = useCallback(async () => {\n try {\n setLoading(true)\n setError(null)\n\n const params = new URLSearchParams({ widget })\n if (organizationId) {\n params.set('organizationId', organizationId)\n }\n\n const response = await fetch(`${endpoint}?${params}`)\n const data = await response.json()\n\n if (!response.ok) {\n throw new Error(data.error || 'Failed to fetch token')\n }\n\n setToken(data.token)\n } catch (err) {\n setError(err instanceof Error ? err.message : 'Token fetch failed')\n } finally {\n setLoading(false)\n }\n }, [widget, organizationId, endpoint])\n\n useEffect(() => {\n fetchToken()\n }, [fetchToken])\n\n return { token, loading, error, refetch: fetchToken }\n}\n","'use client'\n\nimport { useCallback, useMemo } from 'react'\nimport { useVaultContext, useVaultContextOptional } from '../providers/vault-provider'\nimport type { VaultItem, VaultField } from '../vault/types'\n\n/**\n * Result from useVault hook\n */\nexport interface UseVaultResult {\n /** List of vault items */\n items: VaultItem[]\n /** Whether the vault is loading */\n loading: boolean\n /** Error message if any */\n error: string | null\n /** Whether a vault client is connected */\n isConnected: boolean\n /** Reload vault items from the backend */\n reload: () => Promise<void>\n /** Create a new vault item */\n create: (integrationId: string, credentials: Record<string, string>) => Promise<void>\n /** Rotate credentials for an existing item */\n rotate: (id: string, credentials: Record<string, string>) => Promise<void>\n /** Delete a vault item */\n remove: (id: string) => Promise<void>\n /** Get field configuration for an integration */\n getIntegrationFields: (integrationId: string) => VaultField[]\n /** Find an item by ID */\n findItem: (id: string) => VaultItem | undefined\n /** Find items by integration ID */\n findByIntegration: (integrationId: string) => VaultItem[]\n}\n\n/**\n * Hook to access vault state and operations\n *\n * Provides access to the vault context with helper methods for\n * common operations like finding items and managing credentials.\n *\n * Must be used within a VaultProvider.\n *\n * @example\n * ```tsx\n * import { useVault } from '@mdxui/auth'\n *\n * function VaultDashboard() {\n * const {\n * items,\n * loading,\n * create,\n * rotate,\n * remove,\n * findByIntegration,\n * } = useVault()\n *\n * const openaiItems = findByIntegration('openai')\n *\n * const handleCreate = async () => {\n * await create('github', { personal_access_token: 'ghp_...' })\n * }\n *\n * if (loading) return <div>Loading...</div>\n *\n * return (\n * <ul>\n * {items.map(item => (\n * <li key={item.id}>{item.name}</li>\n * ))}\n * </ul>\n * )\n * }\n * ```\n */\nexport function useVault(): UseVaultResult {\n const context = useVaultContext()\n\n const findItem = useCallback(\n (id: string): VaultItem | undefined => {\n return context.items.find((item) => item.id === id)\n },\n [context.items]\n )\n\n const findByIntegration = useCallback(\n (integrationId: string): VaultItem[] => {\n return context.items.filter((item) => item.integrationId === integrationId)\n },\n [context.items]\n )\n\n return useMemo(\n () => ({\n items: context.items,\n loading: context.loading,\n error: context.error,\n isConnected: context.client !== null,\n reload: context.reload,\n create: context.createItem,\n rotate: context.rotateItem,\n remove: context.deleteItem,\n getIntegrationFields: context.getIntegrationFields,\n findItem,\n findByIntegration,\n }),\n [context, findItem, findByIntegration]\n )\n}\n\n/**\n * Optional vault hook that returns null if not within a VaultProvider\n *\n * Useful for components that can optionally integrate with the vault\n * when it's available.\n *\n * @example\n * ```tsx\n * function MaybeVaultComponent() {\n * const vault = useVaultOptional()\n *\n * if (!vault) {\n * return <div>Vault not available</div>\n * }\n *\n * return <VaultList items={vault.items} ... />\n * }\n * ```\n */\nexport function useVaultOptional(): UseVaultResult | null {\n const context = useVaultContextOptional()\n\n const findItem = useCallback(\n (id: string): VaultItem | undefined => {\n return context?.items.find((item) => item.id === id)\n },\n [context?.items]\n )\n\n const findByIntegration = useCallback(\n (integrationId: string): VaultItem[] => {\n return context?.items.filter((item) => item.integrationId === integrationId) ?? []\n },\n [context?.items]\n )\n\n if (!context) {\n return null\n }\n\n return {\n items: context.items,\n loading: context.loading,\n error: context.error,\n isConnected: context.client !== null,\n reload: context.reload,\n create: context.createItem,\n rotate: context.rotateItem,\n remove: context.deleteItem,\n getIntegrationFields: context.getIntegrationFields,\n findItem,\n findByIntegration,\n }\n}\n","'use client'\n\nimport { createContext, useContext, useMemo, type ReactNode } from 'react'\nimport type { VaultItem, VaultField } from '../vault/types'\n\n/**\n * Vault client interface\n *\n * Defines the contract for a vault backend. The actual implementation\n * can be provided by vault.do SDK or any other vault service.\n */\nexport interface VaultClient {\n /** List all vault items */\n list: () => Promise<VaultItem[]>\n /** Create a new vault item */\n create: (integrationId: string, credentials: Record<string, string>) => Promise<VaultItem>\n /** Rotate credentials for an existing vault item */\n rotate: (id: string, credentials: Record<string, string>) => Promise<VaultItem>\n /** Delete a vault item */\n delete: (id: string) => Promise<void>\n /** Get field configuration for an integration */\n getIntegrationFields?: (integrationId: string) => VaultField[]\n}\n\n/**\n * Vault context state\n */\nexport interface VaultContextState {\n /** The vault client instance */\n client: VaultClient | null\n /** Vault items currently loaded */\n items: VaultItem[]\n /** Whether the vault is currently loading */\n loading: boolean\n /** Error message if vault operations failed */\n error: string | null\n /** Reload vault items */\n reload: () => Promise<void>\n /** Create a new vault item */\n createItem: (integrationId: string, credentials: Record<string, string>) => Promise<void>\n /** Rotate credentials for an existing item */\n rotateItem: (id: string, credentials: Record<string, string>) => Promise<void>\n /** Delete a vault item */\n deleteItem: (id: string) => Promise<void>\n /** Get field configuration for an integration */\n getIntegrationFields: (integrationId: string) => VaultField[]\n}\n\nconst VaultContext = createContext<VaultContextState | null>(null)\n\n/**\n * Props for VaultProvider\n */\nexport interface VaultProviderProps {\n /** Children to render */\n children: ReactNode\n /** Optional vault client implementation */\n client?: VaultClient\n /** Initial items to display (for SSR or static rendering) */\n initialItems?: VaultItem[]\n}\n\n/**\n * Default fields for unknown integrations\n */\nconst defaultFields: VaultField[] = [\n { key: 'api_key', label: 'API Key', type: 'password', required: true }\n]\n\n/**\n * Provider for vault state and operations\n *\n * Provides context for vault components to access the vault client\n * and perform CRUD operations on credentials.\n *\n * The actual vault.do SDK integration will be done in vault.do/react.\n * This provider is designed to be a generic wrapper that can work\n * with any vault backend implementation.\n *\n * @example\n * ```tsx\n * import { VaultProvider } from '@mdxui/auth'\n *\n * // Basic usage with a custom client\n * function App() {\n * return (\n * <VaultProvider client={myVaultClient}>\n * <VaultDashboard />\n * </VaultProvider>\n * )\n * }\n *\n * // Static/SSR usage with initial items\n * function App() {\n * return (\n * <VaultProvider initialItems={serverSideItems}>\n * <VaultDashboard />\n * </VaultProvider>\n * )\n * }\n * ```\n */\nexport function VaultProvider({\n children,\n client,\n initialItems = [],\n}: VaultProviderProps) {\n // Note: In a real implementation, this would use useState and useEffect\n // to manage state and load items from the client. For now, we provide\n // a basic structure that the vault.do SDK can extend.\n\n const contextValue = useMemo<VaultContextState>(() => {\n const getIntegrationFields = (integrationId: string): VaultField[] => {\n if (client?.getIntegrationFields) {\n return client.getIntegrationFields(integrationId)\n }\n return defaultFields\n }\n\n return {\n client: client ?? null,\n items: initialItems,\n loading: false,\n error: null,\n reload: async () => {\n if (!client) {\n console.warn('VaultProvider: No client provided, cannot reload')\n return\n }\n // Implementation would update state here\n await client.list()\n },\n createItem: async (integrationId, credentials) => {\n if (!client) {\n throw new Error('VaultProvider: No client provided')\n }\n await client.create(integrationId, credentials)\n },\n rotateItem: async (id, credentials) => {\n if (!client) {\n throw new Error('VaultProvider: No client provided')\n }\n await client.rotate(id, credentials)\n },\n deleteItem: async (id) => {\n if (!client) {\n throw new Error('VaultProvider: No client provided')\n }\n await client.delete(id)\n },\n getIntegrationFields,\n }\n }, [client, initialItems])\n\n return (\n <VaultContext.Provider value={contextValue}>\n {children}\n </VaultContext.Provider>\n )\n}\n\n/**\n * Hook to access vault context\n *\n * Must be used within a VaultProvider.\n *\n * @throws Error if used outside of VaultProvider\n */\nexport function useVaultContext(): VaultContextState {\n const context = useContext(VaultContext)\n if (!context) {\n throw new Error('useVaultContext must be used within a VaultProvider')\n }\n return context\n}\n\n/**\n * Hook to optionally access vault context\n *\n * Returns null if not within a VaultProvider.\n */\nexport function useVaultContextOptional(): VaultContextState | null {\n return useContext(VaultContext)\n}\n"],"mappings":"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","names":["useCallback","useMemo","useCallback","useMemo"]}
@@ -1,5 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { I as IdentityProviderProps, A as AuthGateProps, W as WidgetsProviderProps } from './auth-Ba2f778e.js';
3
+ import { ReactNode } from 'react';
4
+ import { V as VaultItem, a as VaultField } from './types-8tixck1H.js';
3
5
 
4
6
  /**
5
7
  * Identity provider that wraps your app with WorkOS AuthKit authentication.
@@ -156,4 +158,105 @@ declare function useThemeDetection(): {
156
158
  */
157
159
  declare function WidgetsProvider({ children, appearance, radius, scaling, }: WidgetsProviderProps): react_jsx_runtime.JSX.Element;
158
160
 
159
- export { AuthGate as A, IdentityProvider as I, WidgetsProvider as W, IdentityProviderMinimal as a, useThemeDetection as u };
161
+ /**
162
+ * Vault client interface
163
+ *
164
+ * Defines the contract for a vault backend. The actual implementation
165
+ * can be provided by vault.do SDK or any other vault service.
166
+ */
167
+ interface VaultClient {
168
+ /** List all vault items */
169
+ list: () => Promise<VaultItem[]>;
170
+ /** Create a new vault item */
171
+ create: (integrationId: string, credentials: Record<string, string>) => Promise<VaultItem>;
172
+ /** Rotate credentials for an existing vault item */
173
+ rotate: (id: string, credentials: Record<string, string>) => Promise<VaultItem>;
174
+ /** Delete a vault item */
175
+ delete: (id: string) => Promise<void>;
176
+ /** Get field configuration for an integration */
177
+ getIntegrationFields?: (integrationId: string) => VaultField[];
178
+ }
179
+ /**
180
+ * Vault context state
181
+ */
182
+ interface VaultContextState {
183
+ /** The vault client instance */
184
+ client: VaultClient | null;
185
+ /** Vault items currently loaded */
186
+ items: VaultItem[];
187
+ /** Whether the vault is currently loading */
188
+ loading: boolean;
189
+ /** Error message if vault operations failed */
190
+ error: string | null;
191
+ /** Reload vault items */
192
+ reload: () => Promise<void>;
193
+ /** Create a new vault item */
194
+ createItem: (integrationId: string, credentials: Record<string, string>) => Promise<void>;
195
+ /** Rotate credentials for an existing item */
196
+ rotateItem: (id: string, credentials: Record<string, string>) => Promise<void>;
197
+ /** Delete a vault item */
198
+ deleteItem: (id: string) => Promise<void>;
199
+ /** Get field configuration for an integration */
200
+ getIntegrationFields: (integrationId: string) => VaultField[];
201
+ }
202
+ /**
203
+ * Props for VaultProvider
204
+ */
205
+ interface VaultProviderProps {
206
+ /** Children to render */
207
+ children: ReactNode;
208
+ /** Optional vault client implementation */
209
+ client?: VaultClient;
210
+ /** Initial items to display (for SSR or static rendering) */
211
+ initialItems?: VaultItem[];
212
+ }
213
+ /**
214
+ * Provider for vault state and operations
215
+ *
216
+ * Provides context for vault components to access the vault client
217
+ * and perform CRUD operations on credentials.
218
+ *
219
+ * The actual vault.do SDK integration will be done in vault.do/react.
220
+ * This provider is designed to be a generic wrapper that can work
221
+ * with any vault backend implementation.
222
+ *
223
+ * @example
224
+ * ```tsx
225
+ * import { VaultProvider } from '@mdxui/auth'
226
+ *
227
+ * // Basic usage with a custom client
228
+ * function App() {
229
+ * return (
230
+ * <VaultProvider client={myVaultClient}>
231
+ * <VaultDashboard />
232
+ * </VaultProvider>
233
+ * )
234
+ * }
235
+ *
236
+ * // Static/SSR usage with initial items
237
+ * function App() {
238
+ * return (
239
+ * <VaultProvider initialItems={serverSideItems}>
240
+ * <VaultDashboard />
241
+ * </VaultProvider>
242
+ * )
243
+ * }
244
+ * ```
245
+ */
246
+ declare function VaultProvider({ children, client, initialItems, }: VaultProviderProps): react_jsx_runtime.JSX.Element;
247
+ /**
248
+ * Hook to access vault context
249
+ *
250
+ * Must be used within a VaultProvider.
251
+ *
252
+ * @throws Error if used outside of VaultProvider
253
+ */
254
+ declare function useVaultContext(): VaultContextState;
255
+ /**
256
+ * Hook to optionally access vault context
257
+ *
258
+ * Returns null if not within a VaultProvider.
259
+ */
260
+ declare function useVaultContextOptional(): VaultContextState | null;
261
+
262
+ export { AuthGate as A, IdentityProvider as I, VaultProvider as V, WidgetsProvider as W, IdentityProviderMinimal as a, useVaultContext as b, useVaultContextOptional as c, type VaultClient as d, type VaultContextState as e, type VaultProviderProps as f, useThemeDetection as u };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export { A as AuthGate, I as IdentityProvider, a as IdentityProviderMinimal, W as WidgetsProvider, u as useThemeDetection } from './index-Bl4BwORF.js';
1
+ export { A as AuthGate, I as IdentityProvider, a as IdentityProviderMinimal, d as VaultClient, e as VaultContextState, V as VaultProvider, f as VaultProviderProps, W as WidgetsProvider, u as useThemeDetection, b as useVaultContext, c as useVaultContextOptional } from './index-DGthQxCM.js';
2
2
  export { ApiKeys, OrganizationSwitcher, Pipes, UserProfile, UserSecurity, UserSessions, UsersManagement } from './widgets/index.js';
3
+ export { Secret, SecretForm, SecretsManager, SecretsManagerProps, VaultDeleteDialog, VaultEmptyState, VaultInputModal, VaultItemCard, VaultList } from './vault/index.js';
4
+ export { f as VaultDeleteDialogProps, g as VaultEmptyStateProps, a as VaultField, e as VaultInputModalProps, b as VaultIntegration, V as VaultItem, d as VaultItemCardProps, c as VaultListProps } from './types-8tixck1H.js';
3
5
  export { SignInButton, SignOutButton, TeamSwitcher, UserMenu } from './components/index.js';
4
6
  export { useAuth } from '@workos-inc/authkit-react';
5
- export { useWidgetToken } from './hooks/index.js';
7
+ export { UseVaultResult, useVault, useVaultOptional, useWidgetToken } from './hooks/index.js';
6
8
  export { A as AuthGateProps, a as AuthToken, B as BaseWidgetProps, I as IdentityProviderProps, O as OrganizationWidgetProps, U as UseWidgetTokenOptions, b as UseWidgetTokenResult, W as WidgetsProviderProps } from './auth-Ba2f778e.js';
7
9
  export { a as AuthOrganization, e as AuthOrganizationSchema, b as AuthSession, d as AuthSessionSchema, A as AuthUser, c as AuthUserSchema, I as Impersonator, f as ImpersonatorSchema } from './auth-organization-CN1WpGnL.js';
8
10
  export { AppearanceSchema, AuthGatePropsSchema, AuthTokenSchema, BaseWidgetPropsSchema, IdentityProviderPropsSchema, OrganizationWidgetPropsSchema, RadiusSchema, ScalingSchema, UnauthenticatedActionSchema, UseWidgetTokenOptionsSchema, UseWidgetTokenResultSchema, WidgetsProviderPropsSchema } from './schemas/index.js';