@authyon/auth 0.2.0-beta.0 → 0.2.0-beta.2
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/LICENSE +21 -0
- package/README.md +177 -14
- package/dist/ability-g6nBpOQM.d.cts +617 -0
- package/dist/ability-g6nBpOQM.d.ts +617 -0
- package/dist/chunk-EHZEUM47.js +323 -0
- package/dist/index.cjs +748 -60
- package/dist/index.d.cts +57 -466
- package/dist/index.d.ts +57 -466
- package/dist/index.js +431 -58
- package/dist/react/index.cjs +428 -0
- package/dist/react/index.d.cts +47 -0
- package/dist/react/index.d.ts +47 -0
- package/dist/react/index.js +120 -0
- package/package.json +71 -37
package/dist/index.d.ts
CHANGED
|
@@ -1,484 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* wire — the SDK exposes it as "organization").
|
|
4
|
-
*/
|
|
5
|
-
interface Organization {
|
|
6
|
-
id: string;
|
|
7
|
-
slug: string;
|
|
8
|
-
name?: string;
|
|
9
|
-
description?: string;
|
|
10
|
-
roles?: string[];
|
|
11
|
-
}
|
|
12
|
-
/** POST /auth/tenants — creates an organization owned by the signed-in user. */
|
|
13
|
-
interface CreateOrganizationParams {
|
|
14
|
-
name?: string;
|
|
15
|
-
slug?: string;
|
|
16
|
-
description?: string;
|
|
17
|
-
}
|
|
18
|
-
/** GET /auth/tenants/{organizationId}/members — confirmed against the live API. */
|
|
19
|
-
interface OrganizationMember {
|
|
20
|
-
userId: string;
|
|
21
|
-
email?: string;
|
|
22
|
-
username?: string;
|
|
23
|
-
roles?: string[];
|
|
24
|
-
createdAt?: string;
|
|
25
|
-
lastLoginAt?: string | null;
|
|
26
|
-
}
|
|
27
|
-
/** POST /auth/tenants/{tenantId}/members — invites a member by e-mail. */
|
|
28
|
-
interface InviteMemberParams {
|
|
29
|
-
email: string;
|
|
30
|
-
roles: string[];
|
|
31
|
-
}
|
|
32
|
-
/** Pagination options accepted by list endpoints. */
|
|
33
|
-
interface PageParams {
|
|
34
|
-
skip?: number;
|
|
35
|
-
take?: number;
|
|
36
|
-
}
|
|
37
|
-
/** Authenticated user profile. */
|
|
38
|
-
interface User {
|
|
39
|
-
id: string;
|
|
40
|
-
email: string;
|
|
41
|
-
username?: string;
|
|
42
|
-
emailConfirmed?: boolean;
|
|
43
|
-
firstName?: string | null;
|
|
44
|
-
lastName?: string | null;
|
|
45
|
-
roles?: string[];
|
|
46
|
-
permissions?: string[];
|
|
47
|
-
createdAt?: string;
|
|
48
|
-
lastLoginAt?: string;
|
|
49
|
-
organizations?: Organization[];
|
|
50
|
-
activeOrganization?: Organization | null;
|
|
51
|
-
/** Actions the user must complete before continuing (e.g. confirm e-mail). */
|
|
52
|
-
pendencies?: string[];
|
|
53
|
-
}
|
|
54
|
-
/** Token pair issued by login / refresh / tenant switch. */
|
|
55
|
-
interface Session {
|
|
56
|
-
accessToken: string;
|
|
57
|
-
refreshToken: string;
|
|
58
|
-
/** Access-token lifetime in seconds (typically 1800). */
|
|
59
|
-
expiresIn: number;
|
|
60
|
-
/** Epoch ms when the access token expires (computed client-side). */
|
|
61
|
-
expiresAt: number;
|
|
62
|
-
user?: User;
|
|
63
|
-
}
|
|
64
|
-
type TwoFactorMethod = "authenticator" | "email" | "webauthn" | string;
|
|
65
|
-
/** Returned by `login()` when the account has 2FA enabled. */
|
|
66
|
-
interface TwoFactorChallenge {
|
|
67
|
-
twoFactorRequired: true;
|
|
68
|
-
challengeToken: string;
|
|
69
|
-
methods: TwoFactorMethod[];
|
|
70
|
-
emailHint?: string;
|
|
71
|
-
}
|
|
72
|
-
type LoginResult = {
|
|
73
|
-
twoFactorRequired: false;
|
|
74
|
-
session: Session;
|
|
75
|
-
} | TwoFactorChallenge;
|
|
76
|
-
interface RegisterParams {
|
|
77
|
-
email: string;
|
|
78
|
-
username?: string;
|
|
79
|
-
password: string;
|
|
80
|
-
}
|
|
81
|
-
interface LoginParams {
|
|
82
|
-
/** Provide `email` or `username`. */
|
|
83
|
-
email?: string;
|
|
84
|
-
username?: string;
|
|
85
|
-
password: string;
|
|
86
|
-
/** Optional organization to scope the session to (sent as `tenantSlug`). */
|
|
87
|
-
organizationSlug?: string;
|
|
88
|
-
}
|
|
89
|
-
/** A completed WebAuthn ceremony, handed back to the server to finish login/registration. */
|
|
90
|
-
interface WebAuthnAssertion {
|
|
91
|
-
ceremonyToken: string;
|
|
92
|
-
/** JSON-serialized `PublicKeyCredential` returned by `navigator.credentials.get()`. */
|
|
93
|
-
assertionJson: string;
|
|
94
|
-
}
|
|
95
|
-
/** POST /auth/2fa/verify — redeems a challenge from `login()`. */
|
|
96
|
-
interface TwoFactorVerifyParams {
|
|
97
|
-
challengeToken: string;
|
|
98
|
-
method: TwoFactorMethod;
|
|
99
|
-
/** TOTP / email / recovery code. Omit when `method` is `"webauthn"`. */
|
|
100
|
-
code?: string;
|
|
101
|
-
/** Required when `method` is `"webauthn"`. */
|
|
102
|
-
webAuthnAssertion?: WebAuthnAssertion;
|
|
103
|
-
}
|
|
104
|
-
/** GET /auth/2fa/status — per-method enrolment flags, confirmed against the live API. */
|
|
105
|
-
interface TwoFactorStatus {
|
|
106
|
-
authenticatorEnabled: boolean;
|
|
107
|
-
authenticatorConfirmedAt?: string | null;
|
|
108
|
-
emailEnabled: boolean;
|
|
109
|
-
emailEnabledAt?: string | null;
|
|
110
|
-
/** Partially redacted (e.g. `"n**********@h***.com"`). */
|
|
111
|
-
emailHint?: string | null;
|
|
112
|
-
webAuthnEnabled: boolean;
|
|
113
|
-
webAuthnCredentialCount: number;
|
|
114
|
-
webAuthnCredentials: WebAuthnCredential[];
|
|
115
|
-
remainingRecoveryCodes: number;
|
|
116
|
-
}
|
|
117
|
-
interface AuthenticatorSetup {
|
|
118
|
-
secret: string;
|
|
119
|
-
qrSvg: string;
|
|
120
|
-
otpauthUri: string;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Options handed back by a WebAuthn "start" endpoint: a ceremony token to
|
|
124
|
-
* correlate the "finish" call, plus the WebAuthn options object to pass into
|
|
125
|
-
* `navigator.credentials.get()` / `.create()` (after `JSON.parse`, per the
|
|
126
|
-
* WebAuthn spec — challenge/user.id are base64url strings on the wire).
|
|
127
|
-
*
|
|
128
|
-
* ⚠️ The exact shape of `options` is not published in the OpenAPI schema (no
|
|
129
|
-
* response bodies are documented for any endpoint at the time this SDK was
|
|
130
|
-
* written) — treat it as opaque input to the WebAuthn API.
|
|
131
|
-
*/
|
|
132
|
-
interface WebAuthnCeremonyStart {
|
|
133
|
-
ceremonyToken: string;
|
|
134
|
-
options: unknown;
|
|
135
|
-
}
|
|
136
|
-
interface WebAuthnCredential {
|
|
137
|
-
id: string;
|
|
138
|
-
nickname?: string;
|
|
139
|
-
createdAt?: string;
|
|
140
|
-
}
|
|
141
|
-
interface SsoProvider {
|
|
142
|
-
name: string;
|
|
143
|
-
slug: string;
|
|
144
|
-
/** URL to redirect the browser to in order to start this provider's flow. */
|
|
145
|
-
startUrl: string;
|
|
146
|
-
}
|
|
147
|
-
/** GET /auth/me/activities — one audit-trail entry, confirmed against the live API. */
|
|
148
|
-
interface Activity {
|
|
149
|
-
id: string;
|
|
150
|
-
eventType: string;
|
|
151
|
-
occurredAt: string;
|
|
152
|
-
environmentId?: string;
|
|
153
|
-
ip?: string;
|
|
154
|
-
userAgent?: string;
|
|
155
|
-
/** JSON-encoded string — `JSON.parse` it for the event-specific payload. */
|
|
156
|
-
payloadJson?: string;
|
|
157
|
-
}
|
|
158
|
-
/** Paginated list envelope returned by `user.activities()`. */
|
|
159
|
-
interface Page<T> {
|
|
160
|
-
data: T[];
|
|
161
|
-
/** Item count actually returned for this page. */
|
|
162
|
-
perPage?: number;
|
|
163
|
-
pageSize: number;
|
|
164
|
-
total: number;
|
|
165
|
-
pages: number;
|
|
166
|
-
hasNext: boolean;
|
|
167
|
-
hasPrev: boolean;
|
|
168
|
-
}
|
|
169
|
-
/** A role available within an organization (tenant). */
|
|
170
|
-
interface Role {
|
|
171
|
-
id: string;
|
|
172
|
-
name: string;
|
|
173
|
-
description?: string;
|
|
174
|
-
permissions?: string[];
|
|
175
|
-
}
|
|
176
|
-
/** GET /auth/sessions — confirmed against the live API. */
|
|
177
|
-
interface SessionInfo {
|
|
178
|
-
id: string;
|
|
179
|
-
createdAt: string;
|
|
180
|
-
expiresAt: string;
|
|
181
|
-
revokedAt?: string | null;
|
|
182
|
-
createdFromIp?: string;
|
|
183
|
-
isActive: boolean;
|
|
184
|
-
userAgent?: string;
|
|
185
|
-
lastUsedAt?: string | null;
|
|
186
|
-
lastUsedFromIp?: string | null;
|
|
187
|
-
}
|
|
188
|
-
/** POST /auth/introspect (RFC 7662) — confirmed against the live API. */
|
|
189
|
-
interface IntrospectResult {
|
|
190
|
-
active: boolean;
|
|
191
|
-
sub?: string;
|
|
192
|
-
username?: string | null;
|
|
193
|
-
email?: string | null;
|
|
194
|
-
roles?: string[] | null;
|
|
195
|
-
permissions?: string[];
|
|
196
|
-
client_id?: string;
|
|
197
|
-
scope?: string;
|
|
198
|
-
exp?: number;
|
|
199
|
-
iat?: number;
|
|
200
|
-
jti?: string;
|
|
201
|
-
token_type?: string;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* POST /auth/validate — confirmed against the live API. The wire shape is
|
|
205
|
-
* `{ valid, reason, profile }`, not `{ user, organization }` as the
|
|
206
|
-
* OpenAPI schema (which didn't document response bodies) suggested.
|
|
207
|
-
* `profile` is `null` for machine tokens (there's no user behind them) and
|
|
208
|
-
* for tokens that fail validation.
|
|
209
|
-
*/
|
|
210
|
-
interface ValidateResult {
|
|
211
|
-
valid: boolean;
|
|
212
|
-
reason?: string | null;
|
|
213
|
-
user: User | null;
|
|
214
|
-
}
|
|
215
|
-
type AuthEvent = {
|
|
216
|
-
type: "signed_in";
|
|
217
|
-
session: Session;
|
|
218
|
-
} | {
|
|
219
|
-
type: "refreshed";
|
|
220
|
-
session: Session;
|
|
221
|
-
} | {
|
|
222
|
-
type: "signed_out";
|
|
223
|
-
};
|
|
224
|
-
type AuthStateListener = (event: AuthEvent) => void;
|
|
225
|
-
/** Pluggable persistence for the token pair. */
|
|
226
|
-
interface TokenStorage {
|
|
227
|
-
get(): Session | null;
|
|
228
|
-
set(session: Session): void;
|
|
229
|
-
clear(): void;
|
|
230
|
-
}
|
|
231
|
-
interface AuthyonClientOptions {
|
|
232
|
-
/** Publishable environment key (`pk_live_...` / `pk_test_...`). */
|
|
233
|
-
envKey: string;
|
|
234
|
-
/** API origin. Defaults to `https://api.authyon.com`. */
|
|
235
|
-
baseUrl?: string;
|
|
236
|
-
/** Where tokens are persisted. Defaults to localStorage when available, memory otherwise. */
|
|
237
|
-
storage?: TokenStorage;
|
|
238
|
-
/**
|
|
239
|
-
* Automatically refresh the access token shortly before it expires and
|
|
240
|
-
* retry once on 401. Defaults to `true`.
|
|
241
|
-
*/
|
|
242
|
-
autoRefresh?: boolean;
|
|
243
|
-
/** Custom fetch implementation (useful for tests / non-browser runtimes). */
|
|
244
|
-
fetch?: typeof fetch;
|
|
245
|
-
}
|
|
1
|
+
import { T as TokenStorage, H as HttpAdapter, a as HttpLoggerOptions, A as AuthyonClient } from './ability-g6nBpOQM.js';
|
|
2
|
+
export { b as AbilityConditions, c as AbilityEvent, d as AbilityListener, e as AbilityRule, f as AbilitySubject, g as Activity, h as AuthEvent, i as AuthState, j as AuthStateListener, k as AuthenticatorSetup, l as AuthyonAbility, m as AuthyonAbilityBuilder, n as AuthyonAbilityOptions, o as AuthyonClientOptions, p as AuthyonPermissionSource, q as AuthyonSessionController, C as CreateOrganizationInput, F as FetchHttpAdapter, r as HttpAdapterRequest, s as HttpLogEvent, t as HttpLogger, I as IntrospectResult, u as InviteMemberInput, L as LoggingHttpAdapter, v as LoginInput, w as LoginResult, O as Organization, x as OrganizationMember, P as Paged, y as PaginationOptions, R as RegisterInput, z as Role, S as Session, B as SessionControllerOptions, D as SessionInfo, E as SessionSnapshot, G as SessionSnapshotListener, J as SessionStatus, K as SsoProvider, M as TwoFactorChallenge, N as TwoFactorMethod, Q as TwoFactorStatus, U as User, V as ValidateResult, W as VerifyTwoFactorInput, X as WebAuthnAssertion, Y as WebAuthnCeremonyStart, Z as WebAuthnCredential, _ as createAuthyonAbility, $ as createAuthyonRules, a0 as createClient, a1 as hasPermission } from './ability-g6nBpOQM.js';
|
|
246
3
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
private readonly
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
isAuthenticated(): boolean;
|
|
259
|
-
/**
|
|
260
|
-
* Returns a valid access token, refreshing it transparently when it is
|
|
261
|
-
* expired or about to expire. Returns null when signed out.
|
|
262
|
-
*/
|
|
263
|
-
getAccessToken(): Promise<string | null>;
|
|
264
|
-
/** Subscribe to sign-in / refresh / sign-out events. Returns an unsubscribe fn. */
|
|
265
|
-
onAuthStateChange(listener: AuthStateListener): () => void;
|
|
266
|
-
private emit;
|
|
267
|
-
private setSession;
|
|
268
|
-
private clearSession;
|
|
269
|
-
/**
|
|
270
|
-
* `/auth/login` and the other endpoints that mint a session don't return
|
|
271
|
-
* a `user` object on the wire — only `tokens` (plus `twoFactor`, when a
|
|
272
|
-
* challenge is required). Fetch the profile right after so callers get a
|
|
273
|
-
* fully-populated `session.user` without an extra manual round trip.
|
|
274
|
-
* Best-effort: keeps the session usable even if this fetch fails.
|
|
275
|
-
*/
|
|
276
|
-
private hydrateUser;
|
|
277
|
-
private request;
|
|
278
|
-
private toError;
|
|
279
|
-
/** POST /auth/register — creates a new user (rate-limited to 20/hour per IP). */
|
|
280
|
-
register(params: RegisterParams): Promise<{
|
|
281
|
-
id: string;
|
|
282
|
-
}>;
|
|
283
|
-
/**
|
|
284
|
-
* POST /auth/login — authenticates and stores the session, or returns a
|
|
285
|
-
* 2FA challenge to complete via `verifyTwoFactor()`.
|
|
286
|
-
*/
|
|
287
|
-
login(params: LoginParams): Promise<LoginResult>;
|
|
288
|
-
/** POST /auth/2fa/verify — redeems a 2FA challenge from `login()` and stores the session. */
|
|
289
|
-
verifyTwoFactor(params: TwoFactorVerifyParams): Promise<Session>;
|
|
290
|
-
/** POST /auth/refresh — rotates the single-use refresh token (single-flight). */
|
|
291
|
-
refresh(): Promise<Session>;
|
|
292
|
-
/**
|
|
293
|
-
* POST /auth/logout — revokes the current refresh token and clears local
|
|
294
|
-
* state. Pass `{ everywhere: true }` to revoke every session for the user.
|
|
295
|
-
*/
|
|
296
|
-
logout(options?: {
|
|
297
|
-
everywhere?: boolean;
|
|
298
|
-
}): Promise<void>;
|
|
299
|
-
readonly webauthn: {
|
|
300
|
-
/** POST /auth/webauthn/login/start — begins a passkey sign-in. */
|
|
301
|
-
loginStart: (email?: string) => Promise<WebAuthnCeremonyStart>;
|
|
302
|
-
/**
|
|
303
|
-
* POST /auth/webauthn/login/finish — completes the passkey ceremony and
|
|
304
|
-
* stores the session.
|
|
305
|
-
*/
|
|
306
|
-
loginFinish: (assertion: WebAuthnAssertion) => Promise<Session>;
|
|
307
|
-
};
|
|
308
|
-
readonly sso: {
|
|
309
|
-
/** GET /auth/sso/providers — providers enabled for this environment. */
|
|
310
|
-
providers: () => Promise<SsoProvider[]>;
|
|
311
|
-
/**
|
|
312
|
-
* Builds the URL to redirect the browser to in order to start a
|
|
313
|
-
* provider's sign-in flow (`GET /auth/sso/{provider}/start`). Navigate
|
|
314
|
-
* to it directly — e.g. `window.location.href = client.sso.startUrl(...)`.
|
|
315
|
-
*/
|
|
316
|
-
startUrl: (provider: string, params: {
|
|
317
|
-
redirectUri: string;
|
|
318
|
-
state?: string;
|
|
319
|
-
mode?: string;
|
|
320
|
-
}) => string;
|
|
321
|
-
/**
|
|
322
|
-
* POST /auth/sso/exchange — swaps the one-time code from the provider
|
|
323
|
-
* callback for tokens and stores the session.
|
|
324
|
-
*/
|
|
325
|
-
exchange: (code: string) => Promise<Session>;
|
|
326
|
-
};
|
|
327
|
-
readonly user: {
|
|
328
|
-
/** GET /auth/me — fresh profile of the current user. */
|
|
329
|
-
me: () => Promise<User>;
|
|
330
|
-
/** GET /auth/sessions — active refresh-token sessions with device/IP data. */
|
|
331
|
-
sessions: () => Promise<SessionInfo[]>;
|
|
332
|
-
/** GET /auth/me/activities — paginated recent account activity for the current user. */
|
|
333
|
-
activities: (params?: PageParams) => Promise<Page<Activity>>;
|
|
334
|
-
/**
|
|
335
|
-
* Revokes a single session by id (e.g. one entry from `sessions()`),
|
|
336
|
-
* signing that device out without affecting the current one.
|
|
337
|
-
*
|
|
338
|
-
* ⚠️ Not directly confirmed against the published API reference at the
|
|
339
|
-
* time this SDK was written — `DELETE /auth/sessions/{id}` follows the
|
|
340
|
-
* REST convention the rest of the documented API uses, but verify it
|
|
341
|
-
* against the Authyon dashboard/API reference before relying on it. If
|
|
342
|
-
* the endpoint differs, override via a raw call to your own backend.
|
|
343
|
-
*/
|
|
344
|
-
revokeSession: (sessionId: string) => Promise<void>;
|
|
345
|
-
/** POST /auth/password-reset/request — always resolves (no account enumeration). */
|
|
346
|
-
requestPasswordReset: (email: string) => Promise<void>;
|
|
347
|
-
/** POST /auth/password-reset/confirm — sets a new password and revokes all refresh tokens. */
|
|
348
|
-
confirmPasswordReset: (token: string, newPassword: string) => Promise<void>;
|
|
349
|
-
};
|
|
350
|
-
readonly organization: {
|
|
351
|
-
/** GET /auth/tenants — all organization memberships. */
|
|
352
|
-
list: () => Promise<Organization[]>;
|
|
353
|
-
/**
|
|
354
|
-
* POST /auth/tenants — creates an organization owned by the signed-in
|
|
355
|
-
* user (only available when self-service organization creation is
|
|
356
|
-
* enabled for the environment).
|
|
357
|
-
*/
|
|
358
|
-
create: (params?: CreateOrganizationParams) => Promise<Organization>;
|
|
359
|
-
/** GET /auth/tenants/{organizationId} — fetch one of the user's organizations by id. */
|
|
360
|
-
get: (organizationId: string) => Promise<Organization>;
|
|
361
|
-
/**
|
|
362
|
-
* PATCH /auth/tenants/{organizationId} — renames the organization.
|
|
363
|
-
* Requires the `tenants:manage` custom permission on it.
|
|
364
|
-
*/
|
|
365
|
-
rename: (organizationId: string, name: string) => Promise<Organization>;
|
|
366
|
-
/** POST /auth/switch-tenant — issues a fresh token scoped to the new organization. */
|
|
367
|
-
switch: (organizationSlug: string) => Promise<Session>;
|
|
368
|
-
/** The organization the current session is scoped to, from the cached session — no network call. */
|
|
369
|
-
current: () => Organization | null;
|
|
370
|
-
members: {
|
|
371
|
-
/**
|
|
372
|
-
* GET /auth/tenants/{organizationId}/members — paginated list of an
|
|
373
|
-
* organization's members. Consistent with the confirmed-live
|
|
374
|
-
* `Page<T>` envelope every other `skip`/`take` endpoint returns
|
|
375
|
-
* (`user.activities()`, `@authyon/server`'s `environment.users.list()`).
|
|
376
|
-
*/
|
|
377
|
-
list: (organizationId: string, params?: PageParams) => Promise<Page<OrganizationMember>>;
|
|
378
|
-
/** POST /auth/tenants/{organizationId}/members — invite a member by e-mail. */
|
|
379
|
-
invite: (organizationId: string, params: InviteMemberParams) => Promise<void>;
|
|
380
|
-
/** DELETE /auth/tenants/{organizationId}/members/{userId} — remove a member. */
|
|
381
|
-
remove: (organizationId: string, userId: string) => Promise<void>;
|
|
382
|
-
};
|
|
383
|
-
roles: {
|
|
384
|
-
/** GET /auth/tenants/{organizationId}/roles — roles available in the organization. */
|
|
385
|
-
list: (organizationId: string) => Promise<Role[]>;
|
|
386
|
-
};
|
|
387
|
-
};
|
|
388
|
-
readonly twoFactor: {
|
|
389
|
-
/** GET /auth/2fa/status — enrolled methods and recovery code count. */
|
|
390
|
-
status: () => Promise<TwoFactorStatus>;
|
|
391
|
-
/** POST /auth/2fa/resend-email — resends the code for an in-flight login challenge. */
|
|
392
|
-
resendEmail: (challengeToken: string) => Promise<void>;
|
|
393
|
-
/** POST /auth/2fa/authenticator/setup — returns secret, QR SVG and otpauth URI. */
|
|
394
|
-
setupAuthenticator: () => Promise<AuthenticatorSetup>;
|
|
395
|
-
/** POST /auth/2fa/authenticator/confirm — returns 10 single-use recovery codes. */
|
|
396
|
-
confirmAuthenticator: (code: string) => Promise<{
|
|
397
|
-
recoveryCodes: string[];
|
|
398
|
-
}>;
|
|
399
|
-
/**
|
|
400
|
-
* POST /auth/2fa/email/enable — two-step opt-in for email-based OTP.
|
|
401
|
-
* Call without `code` to receive one by e-mail, then call again with
|
|
402
|
-
* that code to confirm enrolment.
|
|
403
|
-
*/
|
|
404
|
-
enableEmail: (code?: string) => Promise<void>;
|
|
405
|
-
/** POST /auth/2fa/disable — turns off a specific 2FA method (requires current password). */
|
|
406
|
-
disable: (method: TwoFactorMethod, currentPassword: string) => Promise<void>;
|
|
407
|
-
/**
|
|
408
|
-
* POST /auth/2fa/recovery-codes/regenerate — rotates the 10 single-use
|
|
409
|
-
* recovery codes (requires current password).
|
|
410
|
-
*/
|
|
411
|
-
regenerateRecoveryCodes: (currentPassword: string) => Promise<{
|
|
412
|
-
recoveryCodes: string[];
|
|
413
|
-
}>;
|
|
414
|
-
webauthn: {
|
|
415
|
-
/** POST /auth/2fa/webauthn/register/start — begins passkey enrolment for 2FA. */
|
|
416
|
-
registerStart: () => Promise<WebAuthnCeremonyStart>;
|
|
417
|
-
/** POST /auth/2fa/webauthn/register/finish — finishes passkey enrolment. */
|
|
418
|
-
registerFinish: (ceremonyToken: string, attestationJson: string, nickname?: string) => Promise<WebAuthnCredential>;
|
|
419
|
-
/** GET /auth/2fa/webauthn/credentials — the caller's registered passkeys. */
|
|
420
|
-
credentials: () => Promise<WebAuthnCredential[]>;
|
|
421
|
-
/** PATCH /auth/2fa/webauthn/credentials/{id} — renames a passkey. */
|
|
422
|
-
renameCredential: (id: string, nickname: string) => Promise<WebAuthnCredential>;
|
|
423
|
-
/** DELETE /auth/2fa/webauthn/credentials/{id} — removes a passkey (requires current password). */
|
|
424
|
-
removeCredential: (id: string, currentPassword: string) => Promise<void>;
|
|
425
|
-
/**
|
|
426
|
-
* POST /auth/2fa/webauthn/assertion/start — fetches WebAuthn assertion
|
|
427
|
-
* options for an in-flight login challenge (2FA method `"webauthn"`).
|
|
428
|
-
*/
|
|
429
|
-
assertionStart: (challengeToken: string) => Promise<WebAuthnCeremonyStart>;
|
|
430
|
-
};
|
|
431
|
-
};
|
|
432
|
-
/**
|
|
433
|
-
* POST /auth/introspect — lightweight token introspection (RFC 7662).
|
|
434
|
-
*
|
|
435
|
-
* ⚠️ Confirmed live: this endpoint requires the CALLER to also
|
|
436
|
-
* authenticate, with an environment or tenant client-credentials bearer
|
|
437
|
-
* token — the end user's own access token doesn't satisfy that (401).
|
|
438
|
-
* A browser app has no client secret to present, so this will fail from
|
|
439
|
-
* `@authyon/auth` in practice; call it from your backend via
|
|
440
|
-
* `@authyon/server` instead.
|
|
441
|
-
*/
|
|
442
|
-
introspect(token?: string): Promise<IntrospectResult>;
|
|
443
|
-
/**
|
|
444
|
-
* POST /auth/validate — recommended: cross-checks DB state, catches
|
|
445
|
-
* revocation immediately. Same caller-authentication requirement (and
|
|
446
|
-
* the same practical limitation from the browser) as `introspect()`.
|
|
447
|
-
*/
|
|
448
|
-
validate(token?: string): Promise<ValidateResult>;
|
|
4
|
+
/** Builds an Authyon browser client through explicit, progressive configuration. */
|
|
5
|
+
declare class AuthyonClientBuilder {
|
|
6
|
+
private readonly options;
|
|
7
|
+
constructor(envKey: string);
|
|
8
|
+
withBaseUrl(baseUrl: string, allowInsecureHttp?: boolean): this;
|
|
9
|
+
withStorage(storage: TokenStorage): this;
|
|
10
|
+
withAutomaticRefresh(enabled?: boolean): this;
|
|
11
|
+
withTimeout(timeoutMs: number): this;
|
|
12
|
+
withHttpAdapter(httpAdapter: HttpAdapter): this;
|
|
13
|
+
withHttpLogger(httpLogger: HttpLoggerOptions): this;
|
|
14
|
+
build(): AuthyonClient;
|
|
449
15
|
}
|
|
450
|
-
/** Convenience factory: `const authyon = createClient({ envKey: "pk_live_..." })`. */
|
|
451
|
-
declare function createClient(options: AuthyonClientOptions): AuthyonClient;
|
|
452
16
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
17
|
+
declare const ErrorCodes: {
|
|
18
|
+
readonly Unknown: "unknown";
|
|
19
|
+
readonly NetworkError: "request.network_error";
|
|
20
|
+
readonly Timeout: "request.timeout";
|
|
21
|
+
readonly SessionMalformed: "session.malformed";
|
|
22
|
+
readonly NotAuthenticated: "auth.not_authenticated";
|
|
23
|
+
readonly InvalidToken: "auth.invalid_token";
|
|
24
|
+
readonly MissingToken: "auth.missing_token";
|
|
25
|
+
readonly EmailTaken: "user.email_taken";
|
|
26
|
+
readonly PasswordWeak: "user.password_weak";
|
|
27
|
+
readonly PasswordPwned: "user.password_pwned";
|
|
28
|
+
readonly RateLimited: "rate_limited";
|
|
29
|
+
};
|
|
30
|
+
type KnownErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
31
|
+
type AuthyonErrorCategory = "network" | "timeout" | "authentication" | "authorization" | "validation" | "not_found" | "conflict" | "rate_limit" | "server" | "unknown";
|
|
32
|
+
type AuthyonErrorAction = "retry" | "reauthenticate" | "request_access" | "fix_input" | "not_found" | "resolve_conflict" | "contact_support";
|
|
33
|
+
interface AuthyonErrorInterpretation {
|
|
34
|
+
category: AuthyonErrorCategory;
|
|
35
|
+
action: AuthyonErrorAction;
|
|
36
|
+
retryable: boolean;
|
|
37
|
+
retryAfter?: number;
|
|
38
|
+
requestId?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Shared RFC 7807 error implementation used by both public SDKs. */
|
|
459
41
|
declare class AuthyonError extends Error {
|
|
460
42
|
readonly status: number;
|
|
461
43
|
readonly code: string;
|
|
462
44
|
readonly title: string;
|
|
463
45
|
readonly detail?: string;
|
|
46
|
+
readonly requestId?: string;
|
|
47
|
+
readonly retryAfter?: number;
|
|
48
|
+
readonly cause?: unknown;
|
|
464
49
|
constructor(status: number, body: Partial<{
|
|
465
50
|
title: string;
|
|
466
51
|
detail: string;
|
|
467
52
|
code: string;
|
|
468
|
-
}
|
|
53
|
+
}>, options?: {
|
|
54
|
+
requestId?: string;
|
|
55
|
+
retryAfter?: number;
|
|
56
|
+
cause?: unknown;
|
|
57
|
+
});
|
|
469
58
|
is(code: string): boolean;
|
|
59
|
+
isAny(...codes: readonly string[]): boolean;
|
|
60
|
+
hasPrefix(prefix: string): boolean;
|
|
61
|
+
isStatus(...statuses: readonly number[]): boolean;
|
|
62
|
+
/** Stable interpretation for UI decisions, retries, telemetry and support flows. */
|
|
63
|
+
interpret(): AuthyonErrorInterpretation;
|
|
64
|
+
get category(): AuthyonErrorCategory;
|
|
65
|
+
get retryable(): boolean;
|
|
66
|
+
toJSON(): Record<string, unknown>;
|
|
470
67
|
}
|
|
471
|
-
/** Well-known error codes documented by Authyon. */
|
|
472
|
-
declare const ErrorCodes: {
|
|
473
|
-
readonly EmailTaken: "user.email_taken";
|
|
474
|
-
readonly PasswordWeak: "user.password_weak";
|
|
475
|
-
readonly PasswordPwned: "user.password_pwned";
|
|
476
|
-
};
|
|
477
68
|
|
|
478
69
|
/** Keeps the session in memory only (lost on page reload). */
|
|
479
|
-
declare function
|
|
70
|
+
declare function createMemoryStorage(): TokenStorage;
|
|
480
71
|
/** Persists the session in `localStorage` under a namespaced key. */
|
|
481
|
-
declare function
|
|
482
|
-
declare function
|
|
72
|
+
declare function createLocalStorage(key?: string): TokenStorage;
|
|
73
|
+
declare function createDefaultStorage(): TokenStorage;
|
|
483
74
|
|
|
484
|
-
export {
|
|
75
|
+
export { AuthyonClient, AuthyonClientBuilder, AuthyonError, type AuthyonErrorAction, type AuthyonErrorCategory, type AuthyonErrorInterpretation, ErrorCodes, HttpAdapter, HttpLoggerOptions, type KnownErrorCode, TokenStorage, createDefaultStorage, createLocalStorage, createMemoryStorage };
|