@zea.cl/auth 0.1.6
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/bin/zea-auth-init.mjs +53 -0
- package/dist/components/index.d.mts +150 -0
- package/dist/components/index.d.ts +150 -0
- package/dist/components/index.js +957 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +947 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/hooks/index.d.mts +2 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +621 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +618 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/index-BnHWPrKX.d.mts +69 -0
- package/dist/index-BnHWPrKX.d.ts +69 -0
- package/dist/index-C5rsqdqK.d.ts +453 -0
- package/dist/index-DtXFjTm2.d.mts +453 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1041 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1024 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles/base.css +219 -0
- package/package.json +72 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* zea-auth-init — ZEA Auth Setup CLI
|
|
5
|
+
*
|
|
6
|
+
* Scaffolds the environment variables needed for a frontend application
|
|
7
|
+
* to perform OAuth2 PKCE login against the ZEA Identity Provider.
|
|
8
|
+
*
|
|
9
|
+
* Usage: npx zea-auth-init
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { randomBytes } from 'crypto'
|
|
13
|
+
import { writeFileSync, existsSync, readFileSync, appendFileSync } from 'fs'
|
|
14
|
+
|
|
15
|
+
const THALAMUS_URL = process.env.THALAMUS_URL || 'http://auth.zea.localhost'
|
|
16
|
+
|
|
17
|
+
function base64url(b) {
|
|
18
|
+
return b.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function main() {
|
|
22
|
+
console.log('')
|
|
23
|
+
console.log('🧠 ZEA Auth — Frontend Setup')
|
|
24
|
+
console.log('')
|
|
25
|
+
|
|
26
|
+
// Generate a unique client_id for this app
|
|
27
|
+
const CLIENT_ID = 'app_' + base64url(randomBytes(8))
|
|
28
|
+
|
|
29
|
+
const envContent = `VITE_ZEA_AUTH_URL=${THALAMUS_URL}\nVITE_ZEA_CLIENT_ID=${CLIENT_ID}\n`
|
|
30
|
+
|
|
31
|
+
if (existsSync('.env.local')) {
|
|
32
|
+
const current = readFileSync('.env.local', 'utf8')
|
|
33
|
+
if (!current.includes('VITE_ZEA_CLIENT_ID')) {
|
|
34
|
+
appendFileSync('.env.local', `\n${envContent}`)
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
writeFileSync('.env.local', envContent)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log('✅ Setup complete!')
|
|
41
|
+
console.log(' Variables appended to .env.local:')
|
|
42
|
+
console.log(` - VITE_ZEA_AUTH_URL=${THALAMUS_URL}`)
|
|
43
|
+
console.log(` - VITE_ZEA_CLIENT_ID=${CLIENT_ID}`)
|
|
44
|
+
console.log('')
|
|
45
|
+
console.log(' Your React components (e.g. <LoginButton />) are now ready to perform PKCE login.')
|
|
46
|
+
console.log(' (Note: If you are building a backend/agent, do NOT use this script. Use `zea token create` to get a PAT instead).')
|
|
47
|
+
console.log('')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main().catch((err) => {
|
|
51
|
+
console.error('Fatal error:', err)
|
|
52
|
+
process.exit(1)
|
|
53
|
+
})
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { T as ThalamusConfig, U as UserInfo, a as User } from '../index-BnHWPrKX.mjs';
|
|
3
|
+
|
|
4
|
+
interface LoginButtonProps {
|
|
5
|
+
/** Thalamus config (same as ThalamusClient constructor) */
|
|
6
|
+
config: ThalamusConfig;
|
|
7
|
+
/** Storage key (default: 'thalamus_auth') */
|
|
8
|
+
storageKey?: string;
|
|
9
|
+
/** Button label */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Scopes to request */
|
|
12
|
+
scopes?: string[];
|
|
13
|
+
/** CSS class */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Button style overrides */
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Drop-in login button with full OAuth2 PKCE flow.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <LoginButton
|
|
24
|
+
* config={{
|
|
25
|
+
* clientId: 'my_app',
|
|
26
|
+
* redirectUri: 'http://localhost:5173/callback',
|
|
27
|
+
* baseUrl: 'http://auth.zea.localhost',
|
|
28
|
+
* }}
|
|
29
|
+
* />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function LoginButton({ config, storageKey, label, scopes, className, style, }: LoginButtonProps): React.JSX.Element | null;
|
|
33
|
+
|
|
34
|
+
interface RegisterButtonProps {
|
|
35
|
+
config: ThalamusConfig;
|
|
36
|
+
/** Organization name — Thalamus creates it automatically on registration */
|
|
37
|
+
orgName?: string;
|
|
38
|
+
/** App origin for auto-CORS + OAuth client registration */
|
|
39
|
+
appOrigin?: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
className?: string;
|
|
42
|
+
style?: React.CSSProperties;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Drop-in register button. Redirects to Thalamus /register page.
|
|
46
|
+
* Passes orgName + appOrigin so Thalamus can auto-create org, OAuth client, and CORS.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* // New developer — creates org + app config at the same time
|
|
51
|
+
* <RegisterButton
|
|
52
|
+
* config={{ clientId:'my_app', redirectUri:'http://localhost:5173/callback', baseUrl:'http://auth.zea.localhost' }}
|
|
53
|
+
* orgName="My Startup"
|
|
54
|
+
* appOrigin="http://localhost:5173"
|
|
55
|
+
* />
|
|
56
|
+
*
|
|
57
|
+
* // Returning developer — just login, Thalamus asks if they want to register a new app
|
|
58
|
+
* <RegisterButton
|
|
59
|
+
* config={{ clientId:'my_app2', redirectUri:'http://localhost:5299/callback', baseUrl:'http://auth.zea.localhost' }}
|
|
60
|
+
* />
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function RegisterButton({ config, orgName, appOrigin, label, className, style }: RegisterButtonProps): React.JSX.Element;
|
|
64
|
+
|
|
65
|
+
interface UserMenuProps {
|
|
66
|
+
config: ThalamusConfig;
|
|
67
|
+
storageKey?: string;
|
|
68
|
+
/** Render custom user info */
|
|
69
|
+
renderUser?: (user: UserInfo) => React.ReactNode;
|
|
70
|
+
className?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* User badge with logout. Shows nothing if not authenticated.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* <UserMenu
|
|
78
|
+
* config={{
|
|
79
|
+
* clientId: 'my_app',
|
|
80
|
+
* redirectUri: 'http://localhost:5173/callback',
|
|
81
|
+
* baseUrl: 'http://auth.zea.localhost',
|
|
82
|
+
* }}
|
|
83
|
+
* />
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function UserMenu({ config, storageKey, renderUser, className }: UserMenuProps): React.JSX.Element | null;
|
|
87
|
+
|
|
88
|
+
interface APIKeyManagerProps {
|
|
89
|
+
/** Base URL of the service that manages API keys (e.g. Soma, or Thalamus itself) */
|
|
90
|
+
baseUrl: string;
|
|
91
|
+
/** Storage key for the auth token (default: 'thalamus_auth') */
|
|
92
|
+
authStorageKey?: string;
|
|
93
|
+
/** Label for the create button */
|
|
94
|
+
label?: string;
|
|
95
|
+
className?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Drop-in API Key generator and manager.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* <APIKeyManager baseUrl="http://soma.zea.localhost" />
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function APIKeyManager({ baseUrl, authStorageKey, label, className }: APIKeyManagerProps): React.JSX.Element;
|
|
106
|
+
|
|
107
|
+
interface OrgSwitcherProps {
|
|
108
|
+
config: ThalamusConfig;
|
|
109
|
+
/** Called when user switches org */
|
|
110
|
+
onSwitch?: (orgId: string) => void;
|
|
111
|
+
className?: string;
|
|
112
|
+
style?: React.CSSProperties;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Organization switcher dropdown.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* <OrgSwitcher
|
|
120
|
+
* config={{ clientId: 'my_app', redirectUri: '/callback', baseUrl: 'http://auth.zea.localhost' }}
|
|
121
|
+
* onSwitch={(orgId) => console.log('Switched to', orgId)}
|
|
122
|
+
* />
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function OrgSwitcher({ config, onSwitch, className, style }: OrgSwitcherProps): React.JSX.Element | null;
|
|
126
|
+
|
|
127
|
+
interface OrgManagerProps {
|
|
128
|
+
config: ThalamusConfig;
|
|
129
|
+
className?: string;
|
|
130
|
+
}
|
|
131
|
+
declare function OrgManager({ config, className }: OrgManagerProps): React.JSX.Element;
|
|
132
|
+
|
|
133
|
+
interface UserCreateFormProps {
|
|
134
|
+
config: ThalamusConfig;
|
|
135
|
+
onCreated?: (user: User) => void;
|
|
136
|
+
className?: string;
|
|
137
|
+
}
|
|
138
|
+
declare function UserCreateForm({ config, onCreated, className }: UserCreateFormProps): React.JSX.Element;
|
|
139
|
+
interface UserTableProps {
|
|
140
|
+
users: User[];
|
|
141
|
+
loading?: boolean;
|
|
142
|
+
error?: string | null;
|
|
143
|
+
className?: string;
|
|
144
|
+
}
|
|
145
|
+
declare function UserTable({ users, loading, error, className }: UserTableProps): React.JSX.Element;
|
|
146
|
+
declare function StatusBadge({ status }: {
|
|
147
|
+
status: string;
|
|
148
|
+
}): React.JSX.Element;
|
|
149
|
+
|
|
150
|
+
export { APIKeyManager, type APIKeyManagerProps, LoginButton, type LoginButtonProps, OrgManager, type OrgManagerProps, OrgSwitcher, type OrgSwitcherProps, RegisterButton, type RegisterButtonProps, StatusBadge, UserCreateForm, type UserCreateFormProps, UserMenu, type UserMenuProps, UserTable, type UserTableProps };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { T as ThalamusConfig, U as UserInfo, a as User } from '../index-BnHWPrKX.js';
|
|
3
|
+
|
|
4
|
+
interface LoginButtonProps {
|
|
5
|
+
/** Thalamus config (same as ThalamusClient constructor) */
|
|
6
|
+
config: ThalamusConfig;
|
|
7
|
+
/** Storage key (default: 'thalamus_auth') */
|
|
8
|
+
storageKey?: string;
|
|
9
|
+
/** Button label */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Scopes to request */
|
|
12
|
+
scopes?: string[];
|
|
13
|
+
/** CSS class */
|
|
14
|
+
className?: string;
|
|
15
|
+
/** Button style overrides */
|
|
16
|
+
style?: React.CSSProperties;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Drop-in login button with full OAuth2 PKCE flow.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <LoginButton
|
|
24
|
+
* config={{
|
|
25
|
+
* clientId: 'my_app',
|
|
26
|
+
* redirectUri: 'http://localhost:5173/callback',
|
|
27
|
+
* baseUrl: 'http://auth.zea.localhost',
|
|
28
|
+
* }}
|
|
29
|
+
* />
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function LoginButton({ config, storageKey, label, scopes, className, style, }: LoginButtonProps): React.JSX.Element | null;
|
|
33
|
+
|
|
34
|
+
interface RegisterButtonProps {
|
|
35
|
+
config: ThalamusConfig;
|
|
36
|
+
/** Organization name — Thalamus creates it automatically on registration */
|
|
37
|
+
orgName?: string;
|
|
38
|
+
/** App origin for auto-CORS + OAuth client registration */
|
|
39
|
+
appOrigin?: string;
|
|
40
|
+
label?: string;
|
|
41
|
+
className?: string;
|
|
42
|
+
style?: React.CSSProperties;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Drop-in register button. Redirects to Thalamus /register page.
|
|
46
|
+
* Passes orgName + appOrigin so Thalamus can auto-create org, OAuth client, and CORS.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* // New developer — creates org + app config at the same time
|
|
51
|
+
* <RegisterButton
|
|
52
|
+
* config={{ clientId:'my_app', redirectUri:'http://localhost:5173/callback', baseUrl:'http://auth.zea.localhost' }}
|
|
53
|
+
* orgName="My Startup"
|
|
54
|
+
* appOrigin="http://localhost:5173"
|
|
55
|
+
* />
|
|
56
|
+
*
|
|
57
|
+
* // Returning developer — just login, Thalamus asks if they want to register a new app
|
|
58
|
+
* <RegisterButton
|
|
59
|
+
* config={{ clientId:'my_app2', redirectUri:'http://localhost:5299/callback', baseUrl:'http://auth.zea.localhost' }}
|
|
60
|
+
* />
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function RegisterButton({ config, orgName, appOrigin, label, className, style }: RegisterButtonProps): React.JSX.Element;
|
|
64
|
+
|
|
65
|
+
interface UserMenuProps {
|
|
66
|
+
config: ThalamusConfig;
|
|
67
|
+
storageKey?: string;
|
|
68
|
+
/** Render custom user info */
|
|
69
|
+
renderUser?: (user: UserInfo) => React.ReactNode;
|
|
70
|
+
className?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* User badge with logout. Shows nothing if not authenticated.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* <UserMenu
|
|
78
|
+
* config={{
|
|
79
|
+
* clientId: 'my_app',
|
|
80
|
+
* redirectUri: 'http://localhost:5173/callback',
|
|
81
|
+
* baseUrl: 'http://auth.zea.localhost',
|
|
82
|
+
* }}
|
|
83
|
+
* />
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function UserMenu({ config, storageKey, renderUser, className }: UserMenuProps): React.JSX.Element | null;
|
|
87
|
+
|
|
88
|
+
interface APIKeyManagerProps {
|
|
89
|
+
/** Base URL of the service that manages API keys (e.g. Soma, or Thalamus itself) */
|
|
90
|
+
baseUrl: string;
|
|
91
|
+
/** Storage key for the auth token (default: 'thalamus_auth') */
|
|
92
|
+
authStorageKey?: string;
|
|
93
|
+
/** Label for the create button */
|
|
94
|
+
label?: string;
|
|
95
|
+
className?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Drop-in API Key generator and manager.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```tsx
|
|
102
|
+
* <APIKeyManager baseUrl="http://soma.zea.localhost" />
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function APIKeyManager({ baseUrl, authStorageKey, label, className }: APIKeyManagerProps): React.JSX.Element;
|
|
106
|
+
|
|
107
|
+
interface OrgSwitcherProps {
|
|
108
|
+
config: ThalamusConfig;
|
|
109
|
+
/** Called when user switches org */
|
|
110
|
+
onSwitch?: (orgId: string) => void;
|
|
111
|
+
className?: string;
|
|
112
|
+
style?: React.CSSProperties;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Organization switcher dropdown.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* <OrgSwitcher
|
|
120
|
+
* config={{ clientId: 'my_app', redirectUri: '/callback', baseUrl: 'http://auth.zea.localhost' }}
|
|
121
|
+
* onSwitch={(orgId) => console.log('Switched to', orgId)}
|
|
122
|
+
* />
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function OrgSwitcher({ config, onSwitch, className, style }: OrgSwitcherProps): React.JSX.Element | null;
|
|
126
|
+
|
|
127
|
+
interface OrgManagerProps {
|
|
128
|
+
config: ThalamusConfig;
|
|
129
|
+
className?: string;
|
|
130
|
+
}
|
|
131
|
+
declare function OrgManager({ config, className }: OrgManagerProps): React.JSX.Element;
|
|
132
|
+
|
|
133
|
+
interface UserCreateFormProps {
|
|
134
|
+
config: ThalamusConfig;
|
|
135
|
+
onCreated?: (user: User) => void;
|
|
136
|
+
className?: string;
|
|
137
|
+
}
|
|
138
|
+
declare function UserCreateForm({ config, onCreated, className }: UserCreateFormProps): React.JSX.Element;
|
|
139
|
+
interface UserTableProps {
|
|
140
|
+
users: User[];
|
|
141
|
+
loading?: boolean;
|
|
142
|
+
error?: string | null;
|
|
143
|
+
className?: string;
|
|
144
|
+
}
|
|
145
|
+
declare function UserTable({ users, loading, error, className }: UserTableProps): React.JSX.Element;
|
|
146
|
+
declare function StatusBadge({ status }: {
|
|
147
|
+
status: string;
|
|
148
|
+
}): React.JSX.Element;
|
|
149
|
+
|
|
150
|
+
export { APIKeyManager, type APIKeyManagerProps, LoginButton, type LoginButtonProps, OrgManager, type OrgManagerProps, OrgSwitcher, type OrgSwitcherProps, RegisterButton, type RegisterButtonProps, StatusBadge, UserCreateForm, type UserCreateFormProps, UserMenu, type UserMenuProps, UserTable, type UserTableProps };
|