@adonis-agora/authkit-react 0.12.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 (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +146 -0
  3. package/build/index.d.ts +68 -0
  4. package/build/index.js +36 -0
  5. package/build/src/authkit_provider.d.ts +13 -0
  6. package/build/src/authkit_provider.js +11 -0
  7. package/build/src/client/client.d.ts +172 -0
  8. package/build/src/client/client.js +218 -0
  9. package/build/src/client/context.d.ts +11 -0
  10. package/build/src/client/context.js +28 -0
  11. package/build/src/client/types.d.ts +425 -0
  12. package/build/src/client/types.js +1 -0
  13. package/build/src/components/authenticated.d.ts +11 -0
  14. package/build/src/components/authenticated.js +10 -0
  15. package/build/src/components/authorized_apps.d.ts +10 -0
  16. package/build/src/components/authorized_apps.js +34 -0
  17. package/build/src/components/avatar.d.ts +22 -0
  18. package/build/src/components/avatar.js +15 -0
  19. package/build/src/components/can.d.ts +10 -0
  20. package/build/src/components/can.js +19 -0
  21. package/build/src/components/key_rotation.d.ts +8 -0
  22. package/build/src/components/key_rotation.js +36 -0
  23. package/build/src/components/organization_profile.d.ts +10 -0
  24. package/build/src/components/organization_profile.js +94 -0
  25. package/build/src/components/organization_switcher.d.ts +9 -0
  26. package/build/src/components/organization_switcher.js +65 -0
  27. package/build/src/components/password_strength_meter.d.ts +11 -0
  28. package/build/src/components/password_strength_meter.js +39 -0
  29. package/build/src/components/sign_in_button.d.ts +297 -0
  30. package/build/src/components/sign_in_button.js +16 -0
  31. package/build/src/components/sign_out_button.d.ts +296 -0
  32. package/build/src/components/sign_out_button.js +16 -0
  33. package/build/src/components/user_button.d.ts +8 -0
  34. package/build/src/components/user_button.js +31 -0
  35. package/build/src/components/user_profile.d.ts +8 -0
  36. package/build/src/components/user_profile.js +35 -0
  37. package/build/src/config.d.ts +30 -0
  38. package/build/src/config.js +42 -0
  39. package/build/src/hooks/use_authorized_apps.d.ts +16 -0
  40. package/build/src/hooks/use_authorized_apps.js +15 -0
  41. package/build/src/hooks/use_org_invitations.d.ts +19 -0
  42. package/build/src/hooks/use_org_invitations.js +20 -0
  43. package/build/src/hooks/use_organization.d.ts +23 -0
  44. package/build/src/hooks/use_organization.js +8 -0
  45. package/build/src/hooks/use_organizations.d.ts +18 -0
  46. package/build/src/hooks/use_organizations.js +14 -0
  47. package/build/src/hooks/use_passkey_autofill.d.ts +8 -0
  48. package/build/src/hooks/use_passkey_autofill.js +76 -0
  49. package/build/src/hooks/use_password_strength.d.ts +11 -0
  50. package/build/src/hooks/use_password_strength.js +34 -0
  51. package/build/src/hooks/use_profile.d.ts +13 -0
  52. package/build/src/hooks/use_profile.js +28 -0
  53. package/build/src/hooks/use_resource.d.ts +11 -0
  54. package/build/src/hooks/use_resource.js +48 -0
  55. package/build/src/hooks/use_sessions.d.ts +16 -0
  56. package/build/src/hooks/use_sessions.js +15 -0
  57. package/build/src/hooks/use_sign_in.d.ts +6 -0
  58. package/build/src/hooks/use_sign_in.js +13 -0
  59. package/build/src/hooks/use_sign_out.d.ts +6 -0
  60. package/build/src/hooks/use_sign_out.js +11 -0
  61. package/build/src/hooks/use_switch_organization.d.ts +7 -0
  62. package/build/src/hooks/use_switch_organization.js +42 -0
  63. package/build/src/hooks/use_user.d.ts +6 -0
  64. package/build/src/hooks/use_user.js +5 -0
  65. package/build/src/provider.d.ts +16 -0
  66. package/build/src/provider.js +5 -0
  67. package/build/src/queries/account/index.d.ts +86 -0
  68. package/build/src/queries/account/index.js +150 -0
  69. package/build/src/queries/admin/index.d.ts +226 -0
  70. package/build/src/queries/admin/index.js +287 -0
  71. package/build/src/queries/keys.d.ts +50 -0
  72. package/build/src/queries/keys.js +34 -0
  73. package/build/src/roles.d.ts +7 -0
  74. package/build/src/roles.js +39 -0
  75. package/build/src/types.d.ts +27 -0
  76. package/build/src/types.js +1 -0
  77. package/build/src/use_auth.d.ts +2 -0
  78. package/build/src/use_auth.js +33 -0
  79. package/build/src/utils.d.ts +2 -0
  80. package/build/src/utils.js +18 -0
  81. package/package.json +68 -0
  82. package/styles.css +303 -0
@@ -0,0 +1,218 @@
1
+ export class AuthkitClientError extends Error {
2
+ status;
3
+ code;
4
+ body;
5
+ constructor(status, message, code, body) {
6
+ super(message);
7
+ this.status = status;
8
+ this.code = code;
9
+ this.body = body;
10
+ this.name = 'AuthkitClientError';
11
+ Object.defineProperty(this, 'isUnauthorized', { value: status === 401, enumerable: true });
12
+ }
13
+ isUnauthorized;
14
+ }
15
+ const MUTATING = new Set(['POST', 'PUT', 'PATCH', 'DELETE']);
16
+ function resolveWindow() {
17
+ try {
18
+ if (typeof window === 'undefined')
19
+ return null;
20
+ return window.__AUTHKIT__ ?? null;
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ }
26
+ function toQueryString(params) {
27
+ const parts = [];
28
+ for (const [k, v] of Object.entries(params)) {
29
+ if (v === undefined || v === null)
30
+ continue;
31
+ parts.push(`${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`);
32
+ }
33
+ return parts.length ? `?${parts.join('&')}` : '';
34
+ }
35
+ class AuthkitClient {
36
+ _baseUrl;
37
+ _accountBaseUrl;
38
+ _csrfToken;
39
+ _fetch;
40
+ constructor(opts = {}) {
41
+ const win = resolveWindow();
42
+ this._baseUrl = opts.baseUrl ?? win?.endpoints.api;
43
+ this._accountBaseUrl = opts.accountBaseUrl ?? '/account/api';
44
+ this._csrfToken = opts.csrfToken ?? win?.csrfToken;
45
+ this._fetch = opts.fetch ?? globalThis.fetch.bind(globalThis);
46
+ }
47
+ async request(method, url, body, extraHeaders) {
48
+ const isMutating = MUTATING.has(method.toUpperCase());
49
+ const headers = {
50
+ Accept: 'application/json',
51
+ ...extraHeaders,
52
+ };
53
+ if (isMutating && this._csrfToken) {
54
+ headers['X-CSRF-TOKEN'] = this._csrfToken;
55
+ }
56
+ if (body !== undefined) {
57
+ headers['Content-Type'] = 'application/json';
58
+ }
59
+ const res = await this._fetch(url, {
60
+ method: method.toUpperCase(),
61
+ credentials: 'include',
62
+ headers,
63
+ ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
64
+ });
65
+ if (!res.ok) {
66
+ let message = `Request failed (${res.status})`;
67
+ let code;
68
+ let parsed;
69
+ try {
70
+ parsed = await res.json();
71
+ const envelope = parsed;
72
+ if (envelope?.error?.message)
73
+ message = envelope.error.message;
74
+ if (envelope?.error?.code)
75
+ code = envelope.error.code;
76
+ else if (typeof envelope?.message === 'string')
77
+ message = envelope.message;
78
+ }
79
+ catch {
80
+ }
81
+ throw new AuthkitClientError(res.status, message, code, parsed);
82
+ }
83
+ const text = await res.text();
84
+ return (text ? JSON.parse(text) : null);
85
+ }
86
+ get(path, params) {
87
+ const qs = params ? toQueryString(params) : '';
88
+ return this.request('GET', `${path}${qs}`);
89
+ }
90
+ post(path, body) {
91
+ return this.request('POST', path, body);
92
+ }
93
+ patch(path, body) {
94
+ return this.request('PATCH', path, body);
95
+ }
96
+ put(path, body) {
97
+ return this.request('PUT', path, body);
98
+ }
99
+ delete(path) {
100
+ return this.request('DELETE', path);
101
+ }
102
+ b(path) {
103
+ if (!this._baseUrl) {
104
+ throw new Error('[AuthkitClient] admin base URL ausente: passe `baseUrl` em createAuthkitClient({ baseUrl }) ' +
105
+ 'ou use o client onde window.__AUTHKIT__ está injetado (console admin). ' +
106
+ 'Telas que só usam client.account.* não precisam de baseUrl.');
107
+ }
108
+ return `${this._baseUrl}${path}`;
109
+ }
110
+ a(path) {
111
+ return `${this._accountBaseUrl}${path}`;
112
+ }
113
+ admin = {
114
+ overview: () => this.get(this.b('/overview')),
115
+ users: {
116
+ list: (params) => this.get(this.b('/users'), params),
117
+ get: (id) => this.get(this.b(`/users/${encodeURIComponent(id)}`)),
118
+ create: (data) => this.post(this.b('/users'), data),
119
+ update: (id, data) => this.patch(this.b(`/users/${encodeURIComponent(id)}`), data),
120
+ disable: (id) => this.post(this.b(`/users/${encodeURIComponent(id)}/disable`)),
121
+ enable: (id) => this.post(this.b(`/users/${encodeURIComponent(id)}/enable`)),
122
+ resetPassword: (id) => this.post(this.b(`/users/${encodeURIComponent(id)}/reset-password`)),
123
+ remove: (id) => this.delete(this.b(`/users/${encodeURIComponent(id)}`)),
124
+ getSessions: (id) => this.get(this.b(`/users/${encodeURIComponent(id)}/sessions`)),
125
+ revokeSessions: (id) => this.post(this.b(`/users/${encodeURIComponent(id)}/revoke-sessions`)),
126
+ },
127
+ sessions: {
128
+ list: (accountId) => this.get(this.b('/sessions'), accountId ? { accountId } : undefined),
129
+ revokeAll: (accountId) => this.post(this.b('/sessions/revoke-all'), accountId ? { accountId } : undefined),
130
+ },
131
+ clients: {
132
+ list: () => this.get(this.b('/clients')),
133
+ get: (id) => this.get(this.b(`/clients/${encodeURIComponent(id)}`)),
134
+ create: (data) => this.post(this.b('/clients'), data),
135
+ update: (id, data) => this.patch(this.b(`/clients/${encodeURIComponent(id)}`), data),
136
+ remove: (id) => this.delete(this.b(`/clients/${encodeURIComponent(id)}`)),
137
+ regenerateSecret: (id) => this.post(this.b(`/clients/${encodeURIComponent(id)}/regenerate-secret`)),
138
+ },
139
+ roles: {
140
+ list: () => this.get(this.b('/roles')),
141
+ create: (data) => this.post(this.b('/roles'), data),
142
+ update: (name, data) => this.patch(this.b(`/roles/${encodeURIComponent(name)}`), data),
143
+ remove: (name) => this.delete(this.b(`/roles/${encodeURIComponent(name)}`)),
144
+ },
145
+ orgs: {
146
+ list: () => this.get(this.b('/orgs')),
147
+ create: (data) => this.post(this.b('/orgs'), data),
148
+ get: (id) => this.get(this.b(`/orgs/${encodeURIComponent(id)}`)),
149
+ update: (id, data) => this.patch(this.b(`/orgs/${encodeURIComponent(id)}`), data),
150
+ remove: (id) => this.delete(this.b(`/orgs/${encodeURIComponent(id)}`)),
151
+ addMember: (orgId, data) => this.post(this.b(`/orgs/${encodeURIComponent(orgId)}/members`), data),
152
+ removeMember: (orgId, accountId) => this.delete(this.b(`/orgs/${encodeURIComponent(orgId)}/members/${encodeURIComponent(accountId)}`)),
153
+ updateMemberRole: (orgId, accountId, role) => this.patch(this.b(`/orgs/${encodeURIComponent(orgId)}/members/${encodeURIComponent(accountId)}`), { role }),
154
+ createInvitation: (orgId, data) => this.post(this.b(`/orgs/${encodeURIComponent(orgId)}/invitations`), data),
155
+ revokeInvitation: (orgId, invitationId) => this.delete(this.b(`/orgs/${encodeURIComponent(orgId)}/invitations/${encodeURIComponent(invitationId)}`)),
156
+ },
157
+ audit: {
158
+ list: (params) => this.get(this.b('/audit'), params),
159
+ },
160
+ settings: {
161
+ list: (orgId) => {
162
+ const qs = orgId ? `?organizationId=${encodeURIComponent(orgId)}` : '';
163
+ return this.get(this.b(`/settings${qs}`));
164
+ },
165
+ set: (key, value, orgId) => {
166
+ const qs = orgId ? `?organizationId=${encodeURIComponent(orgId)}` : '';
167
+ return this.put(this.b(`/settings/${encodeURIComponent(key)}${qs}`), { value });
168
+ },
169
+ remove: (key, orgId) => {
170
+ const qs = orgId ? `?organizationId=${encodeURIComponent(orgId)}` : '';
171
+ return this.delete(this.b(`/settings/${encodeURIComponent(key)}${qs}`));
172
+ },
173
+ },
174
+ impersonation: {
175
+ get: (userId) => this.get(this.b(`/impersonation/${encodeURIComponent(userId)}`)),
176
+ },
177
+ keys: {
178
+ status: () => this.get(this.b('/keys')),
179
+ rotate: (input) => this.post(this.b('/keys/rotate'), input ?? {}),
180
+ },
181
+ };
182
+ account = {
183
+ me: () => this.get(this.a('/me')),
184
+ security: () => this.get(this.a('/security')),
185
+ updateProfile: (data) => this.patch(this.a('/profile'), data),
186
+ changePassword: (data) => this.post(this.a('/password'), data),
187
+ emailChange: (data) => this.post(this.a('/email-change'), data),
188
+ cancelEmailChange: () => this.post(this.a('/email-change/cancel')),
189
+ sessions: {
190
+ list: () => this.get(this.a('/sessions')),
191
+ revoke: (id) => this.delete(this.a(`/sessions/${encodeURIComponent(id)}`)),
192
+ revokeOthers: () => this.post(this.a('/sessions/revoke-others')),
193
+ revokeAll: () => this.post(this.a('/sessions/revoke-all')),
194
+ },
195
+ apps: {
196
+ list: () => this.get(this.a('/apps')),
197
+ revoke: (clientId) => this.delete(this.a(`/apps/${encodeURIComponent(clientId)}`)),
198
+ },
199
+ mfa: () => this.get(this.a('/mfa')),
200
+ passkeys: {
201
+ list: () => this.get(this.a('/passkeys')),
202
+ remove: (id) => this.delete(this.a(`/passkeys/${encodeURIComponent(id)}`)),
203
+ },
204
+ tokens: {
205
+ list: () => this.get(this.a('/tokens')),
206
+ create: (data) => this.post(this.a('/tokens'), data),
207
+ remove: (id) => this.delete(this.a(`/tokens/${encodeURIComponent(id)}`)),
208
+ },
209
+ orgs: {
210
+ list: () => this.get(this.a('/orgs')),
211
+ invitations: () => this.get(this.a('/orgs/invitations')),
212
+ get: (id) => this.get(this.a(`/orgs/${encodeURIComponent(id)}`)),
213
+ },
214
+ };
215
+ }
216
+ export function createAuthkitClient(opts) {
217
+ return new AuthkitClient(opts);
218
+ }
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from 'react';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import { type AuthkitClient, type AuthkitClientOptions } from './client.js';
4
+ export declare function useAuthkitClient(): AuthkitClient;
5
+ export interface AuthkitClientProviderProps {
6
+ client?: AuthkitClient;
7
+ opts?: AuthkitClientOptions;
8
+ children: ReactNode;
9
+ }
10
+ export declare function AuthkitClientProvider({ client, opts, children }: AuthkitClientProviderProps): import("react").FunctionComponentElement<import("react").ProviderProps<AuthkitClient | null>>;
11
+ export declare function createAuthkitQueryClient(): QueryClient;
@@ -0,0 +1,28 @@
1
+ import { createContext, createElement, useContext } from 'react';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import { createAuthkitClient } from './client.js';
4
+ const AuthkitClientContext = createContext(null);
5
+ export function useAuthkitClient() {
6
+ const client = useContext(AuthkitClientContext);
7
+ if (!client) {
8
+ throw new Error('[AuthkitClient] useAuthkitClient() chamado fora de <AuthkitClientProvider>. ' +
9
+ 'Envolva sua árvore com <AuthkitClientProvider>.');
10
+ }
11
+ return client;
12
+ }
13
+ export function AuthkitClientProvider({ client, opts, children }) {
14
+ const resolved = client ?? createAuthkitClient(opts);
15
+ return createElement(AuthkitClientContext.Provider, { value: resolved }, children);
16
+ }
17
+ export function createAuthkitQueryClient() {
18
+ return new QueryClient({
19
+ defaultOptions: {
20
+ queries: {
21
+ staleTime: 30_000,
22
+ gcTime: 5 * 60_000,
23
+ retry: 1,
24
+ refetchOnWindowFocus: false,
25
+ },
26
+ },
27
+ });
28
+ }
@@ -0,0 +1,425 @@
1
+ export interface ApiErrorBody {
2
+ error: {
3
+ code: string;
4
+ message: string;
5
+ };
6
+ }
7
+ export interface AdminUser {
8
+ id: string;
9
+ email: string;
10
+ name: string | null;
11
+ avatarUrl: string | null;
12
+ globalRoles: string[];
13
+ disabled: boolean;
14
+ invited?: boolean;
15
+ }
16
+ export interface AdminUserListResult {
17
+ data: AdminUser[];
18
+ total: number;
19
+ page: number;
20
+ limit: number;
21
+ }
22
+ export interface CreateUserInput {
23
+ email: string;
24
+ name?: string | null;
25
+ password?: string | null;
26
+ invite?: boolean;
27
+ }
28
+ export interface UpdateUserInput {
29
+ globalRoles?: string[];
30
+ name?: string | null;
31
+ avatarUrl?: string | null;
32
+ }
33
+ export interface AdminSessionEntry {
34
+ id: string;
35
+ accountId: string;
36
+ email: string | null;
37
+ loginTs: string | null;
38
+ amr: string[];
39
+ userAgent: string | null;
40
+ browser: string | null;
41
+ os: string | null;
42
+ ip: string | null;
43
+ location: string | null;
44
+ }
45
+ export interface AdminGrantEntry {
46
+ id: string;
47
+ accountId: string;
48
+ clientId: string | null;
49
+ accessTokens: number;
50
+ refreshTokens: number;
51
+ }
52
+ export interface UserSessionsResult {
53
+ supported: boolean;
54
+ truncated?: boolean;
55
+ sessions: AdminSessionEntry[];
56
+ grants: AdminGrantEntry[];
57
+ }
58
+ export interface RevokeSessionsResult {
59
+ revoked?: number;
60
+ [key: string]: unknown;
61
+ }
62
+ export interface AdminSessionListResult {
63
+ canList: boolean;
64
+ sessions: AdminSessionEntry[];
65
+ grants: AdminGrantEntry[];
66
+ }
67
+ export interface AdminClient {
68
+ clientId: string;
69
+ confidential: boolean;
70
+ grants: string[];
71
+ redirectUris: string[];
72
+ postLogoutRedirectUris: string[];
73
+ tokenEndpointAuthMethod: string;
74
+ backchannelLogoutUri: string | null;
75
+ backchannelLogoutSessionRequired: boolean;
76
+ }
77
+ export interface AdminClientListResult {
78
+ data: AdminClient[];
79
+ canList: boolean;
80
+ }
81
+ export interface CreatedClientResult {
82
+ clientId: string;
83
+ clientSecret: string | null;
84
+ }
85
+ export interface RegenerateSecretResult {
86
+ clientId: string;
87
+ clientSecret: string;
88
+ }
89
+ export interface CreateClientInput {
90
+ clientId?: string;
91
+ redirectUris?: string[];
92
+ postLogoutRedirectUris?: string[];
93
+ grantTypes?: string[];
94
+ tokenEndpointAuthMethod?: string;
95
+ backchannelLogoutUri?: string;
96
+ backchannelLogoutSessionRequired?: boolean;
97
+ }
98
+ export type UpdateClientInput = CreateClientInput;
99
+ export interface RoleCatalogEntry {
100
+ name: string;
101
+ description?: string;
102
+ }
103
+ export interface RoleListResult {
104
+ data: RoleCatalogEntry[];
105
+ }
106
+ export interface CreateRoleInput {
107
+ name: string;
108
+ description?: string;
109
+ }
110
+ export interface UpdateRoleInput {
111
+ description?: string;
112
+ }
113
+ export interface AdminOrgEntry {
114
+ id: string;
115
+ name: string;
116
+ slug: string;
117
+ logoUrl: string | null;
118
+ metadata: unknown | null;
119
+ createdAt: string;
120
+ memberCount?: number;
121
+ }
122
+ export interface AdminOrgMember {
123
+ accountId: string;
124
+ email: string | null;
125
+ role: string;
126
+ joinedAt: string;
127
+ }
128
+ export interface AdminOrgInvitation {
129
+ id: string;
130
+ organizationId: string;
131
+ email: string;
132
+ role: string;
133
+ invitedBy: string;
134
+ expiresAt: string;
135
+ acceptedAt: string | null;
136
+ createdAt: string;
137
+ }
138
+ export interface AdminOrgDetail extends AdminOrgEntry {
139
+ members: AdminOrgMember[];
140
+ pendingInvitations: AdminOrgInvitation[];
141
+ }
142
+ export interface AdminOrgListResult {
143
+ data: AdminOrgEntry[];
144
+ }
145
+ export interface CreateOrgInput {
146
+ name: string;
147
+ slug: string;
148
+ ownerAccountId: string;
149
+ logoUrl?: string | null;
150
+ }
151
+ export interface UpdateOrgInput {
152
+ name?: string;
153
+ logoUrl?: string | null;
154
+ }
155
+ export interface AuditEventEntry {
156
+ id: string;
157
+ type: string;
158
+ accountId: string | null;
159
+ email: string | null;
160
+ clientId: string | null;
161
+ actorId: string | null;
162
+ ip: string | null;
163
+ metadata: unknown | null;
164
+ createdAt: string;
165
+ }
166
+ export interface AuditListResult {
167
+ data: AuditEventEntry[];
168
+ total: number;
169
+ page: number;
170
+ limit: number;
171
+ }
172
+ export interface AuditListParams {
173
+ type?: string;
174
+ page?: number;
175
+ limit?: number;
176
+ subject?: string;
177
+ }
178
+ export interface SettingEntry {
179
+ key: string;
180
+ organizationId: string | null;
181
+ value: unknown;
182
+ updatedAt: string | null;
183
+ updatedBy: string | null;
184
+ }
185
+ export interface SettingListResult {
186
+ data: SettingEntry[];
187
+ }
188
+ export interface ImpersonationPanel {
189
+ targetUserId: string;
190
+ targetEmail: string;
191
+ clientId: string;
192
+ [key: string]: unknown;
193
+ }
194
+ export interface DailyPoint {
195
+ date: string;
196
+ count: number;
197
+ }
198
+ export interface AdminOverview {
199
+ usersTotal: number;
200
+ activeSessions: number | null;
201
+ mau: number;
202
+ signInsTotal: number;
203
+ signUpsTotal: number;
204
+ signInsPerDay: DailyPoint[];
205
+ signUpsPerDay: DailyPoint[];
206
+ windowDays: number;
207
+ auditSupported: boolean;
208
+ clientsCount: number;
209
+ auditTotal: number;
210
+ recentEvents: AuditEventEntry[];
211
+ }
212
+ export interface AccountCapabilities {
213
+ securitySupported: boolean;
214
+ profileSupported: boolean;
215
+ passkeysSupported: boolean;
216
+ orgsSupported: boolean;
217
+ tokensSupported: boolean;
218
+ avatarUploadSupported: boolean;
219
+ sessionsSupported: boolean;
220
+ }
221
+ export interface AccountMe {
222
+ id: string;
223
+ email: string;
224
+ emailVerified: boolean | null;
225
+ name: string | null;
226
+ avatarUrl: string | null;
227
+ globalRoles: string[];
228
+ hasPassword: boolean;
229
+ mfaEnabled: boolean;
230
+ passkeyCount: number;
231
+ sudoActive: boolean;
232
+ capabilities: AccountCapabilities;
233
+ }
234
+ export interface AccountSessionEntry {
235
+ id: string;
236
+ loginTs: string | null;
237
+ browser: string | null;
238
+ os: string | null;
239
+ ip: string | null;
240
+ location: string | null;
241
+ amr: string[];
242
+ }
243
+ export interface AccountSecurityOverview {
244
+ email: string;
245
+ pendingEmail: string | null;
246
+ securitySupported: boolean;
247
+ profileSupported: boolean;
248
+ sessionsSupported: boolean;
249
+ activeSessions: AccountSessionEntry[];
250
+ mfa: {
251
+ enabled: boolean;
252
+ totpEnrolled: boolean;
253
+ passkeyCount: number;
254
+ passkeysSupported: boolean;
255
+ };
256
+ }
257
+ export interface AccountSessionsResult {
258
+ supported: boolean;
259
+ sessions: AccountSessionEntry[];
260
+ }
261
+ export interface RevokeSessionResult {
262
+ ok: boolean;
263
+ revoked: string;
264
+ }
265
+ export interface RevokeOthersResult {
266
+ ok: boolean;
267
+ [key: string]: unknown;
268
+ }
269
+ export interface RevokeAllResult {
270
+ ok: boolean;
271
+ signedOut: boolean;
272
+ [key: string]: unknown;
273
+ }
274
+ export interface AccountAppEntry {
275
+ clientId: string;
276
+ accessTokens: number;
277
+ refreshTokens: number;
278
+ }
279
+ export interface AccountAppsResult {
280
+ supported: boolean;
281
+ apps: AccountAppEntry[];
282
+ }
283
+ export interface RevokeAppResult {
284
+ ok: boolean;
285
+ [key: string]: unknown;
286
+ }
287
+ export interface PasskeySummaryEntry {
288
+ id: string;
289
+ label: string | null;
290
+ createdAt: string | null;
291
+ }
292
+ export interface AccountMfaStatus {
293
+ enabled: boolean;
294
+ totp: {
295
+ enrolled: boolean;
296
+ };
297
+ passkeys: {
298
+ supported: boolean;
299
+ count: number;
300
+ items: PasskeySummaryEntry[];
301
+ };
302
+ recovery: {
303
+ available: boolean;
304
+ };
305
+ }
306
+ export interface AccountPasskeysResult {
307
+ supported: boolean;
308
+ passkeys: PasskeySummaryEntry[];
309
+ }
310
+ export interface RemovePasskeyResult {
311
+ ok: boolean;
312
+ removed: string;
313
+ }
314
+ export interface PatEntry {
315
+ id: string;
316
+ name: string;
317
+ scopes: string[];
318
+ audience: string | null;
319
+ lastUsedAt: string | null;
320
+ createdAt: string;
321
+ }
322
+ export interface CreatedPatResult extends PatEntry {
323
+ secret: string;
324
+ }
325
+ export interface AccountTokensResult {
326
+ supported: boolean;
327
+ tokens: PatEntry[];
328
+ }
329
+ export interface CreateTokenInput {
330
+ name?: string;
331
+ }
332
+ export interface RevokeTokenResult {
333
+ ok: boolean;
334
+ revoked: string;
335
+ }
336
+ export interface UpdateProfileInput {
337
+ name?: string | null;
338
+ avatarUrl?: string | null;
339
+ }
340
+ export interface UpdateProfileResult {
341
+ id: string;
342
+ name: string | null;
343
+ avatarUrl: string | null;
344
+ }
345
+ export interface ChangePasswordInput {
346
+ currentPassword: string;
347
+ newPassword: string;
348
+ }
349
+ export interface RequestEmailChangeInput {
350
+ newEmail: string;
351
+ currentPassword?: string;
352
+ }
353
+ export interface OkResult {
354
+ ok: boolean;
355
+ }
356
+ export interface EmailChangeResult {
357
+ ok: boolean;
358
+ email: string;
359
+ }
360
+ export interface AccountOrgEntry {
361
+ id: string;
362
+ name: string;
363
+ slug: string;
364
+ logoUrl: string | null;
365
+ role: string;
366
+ isActive: boolean;
367
+ }
368
+ export interface AccountOrgsResult {
369
+ supported: boolean;
370
+ activeOrgId: string | null;
371
+ orgs: AccountOrgEntry[];
372
+ }
373
+ export interface AccountOrgDetail {
374
+ id: string;
375
+ name: string;
376
+ slug: string;
377
+ logoUrl: string | null;
378
+ role: string;
379
+ canManage: boolean;
380
+ members: Array<{
381
+ accountId: string;
382
+ email: string | null;
383
+ role: string;
384
+ joinedAt: string;
385
+ }>;
386
+ }
387
+ export interface AccountOrgInvitationsResult {
388
+ supported: boolean;
389
+ invitations: Array<{
390
+ id: string;
391
+ organizationId: string;
392
+ orgName: string;
393
+ orgSlug: string;
394
+ email: string;
395
+ role: string;
396
+ expiresAt: string;
397
+ createdAt: string;
398
+ }>;
399
+ }
400
+ export interface ManagedKeyInfo {
401
+ kid: string;
402
+ alg: string;
403
+ ageDays: number;
404
+ active: boolean;
405
+ }
406
+ export interface KeysStatus {
407
+ ageDays: number;
408
+ policy: {
409
+ enabled: boolean;
410
+ maxAgeDays: number;
411
+ keep: number;
412
+ };
413
+ nextRotationInDays: number | null;
414
+ keys: ManagedKeyInfo[];
415
+ }
416
+ export interface KeysRotateInput {
417
+ retire?: boolean;
418
+ keep?: number;
419
+ }
420
+ export interface KeysRotateResult {
421
+ rotated: true;
422
+ newKid: string;
423
+ retiredKids: string[];
424
+ keptKids: string[];
425
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface AuthenticatedProps {
3
+ children: ReactNode;
4
+ fallback?: ReactNode;
5
+ }
6
+ export declare function Authenticated({ children, fallback }: AuthenticatedProps): import("react").FunctionComponentElement<import("react").FragmentProps>;
7
+ export interface GuestProps {
8
+ children: ReactNode;
9
+ fallback?: ReactNode;
10
+ }
11
+ export declare function Guest({ children, fallback }: GuestProps): import("react").FunctionComponentElement<import("react").FragmentProps>;
@@ -0,0 +1,10 @@
1
+ import { createElement, Fragment } from 'react';
2
+ import { useAuth } from '../use_auth.js';
3
+ export function Authenticated({ children, fallback = null }) {
4
+ const { isAuthenticated } = useAuth();
5
+ return createElement(Fragment, null, isAuthenticated ? children : fallback);
6
+ }
7
+ export function Guest({ children, fallback = null }) {
8
+ const { isAuthenticated } = useAuth();
9
+ return createElement(Fragment, null, isAuthenticated ? fallback : children);
10
+ }