@authowl/core 0.11.0 → 0.13.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.
package/dist/index.d.ts CHANGED
@@ -1,1251 +1,16 @@
1
- import { R as ResolvedAuthConfig, H as HasParams, O as OrganizationMembership } from './transport-BObDKlIh.js';
2
- export { A as AuthConfig, D as DecodedPublishableKey, T as TransportError, a as TransportErrorKind, c as createMembershipHas, d as decodePublishableKey, m as membershipHas, b as membershipHasPermission, e as membershipHasTeam, r as resolveConfig, s as sessionCookieName } from './transport-BObDKlIh.js';
1
+ export { A as AuthConfig, D as DecodedPublishableKey, H as HasParams, O as OrganizationMembership, R as ResolvedAuthConfig, c as createMembershipHas, d as decodePublishableKey, m as membershipHas, a as membershipHasPermission, b as membershipHasTeam, r as resolveConfig, s as sessionCookieName } from './organization-membership-B3m6PbmO.js';
2
+ import { P as PhoneOtpChallengeData, A as AkedlyShieldStartProof } from './client-jpaYv3wu.js';
3
+ export { a as AUTH_CHALLENGE_HEADER, b as AcceptOrganizationInvitationData, c as AccountClient, d as AccountSession, e as AccountStatusData, f as ActionFetchOptions, g as AddPasskeyOptions, h as AuthActionResult, i as AuthClientError, j as AuthErrorContext, k as AuthOwlClient, l as AuthOwlErrorCode, m as AuthPasskey, n as AuthRequestContext, o as AuthResponseContext, p as AuthSession, q as AuthUser, C as ChangeEmailOptions, r as ChangePasswordData, s as ChangePasswordOptions, t as ConsentAcceptResult, u as ConsentStatus, v as CreateOrganizationOptions, D as DeleteAccountData, w as DeleteAccountOptions, x as DeleteOrganizationOptions, y as DeletePasskeyData, z as DeletePasskeyOptions, B as DisableTwoFactorOptions, E as EmailAuthData, F as EmailOtpAuthData, G as EmailOtpSignInOptions, H as EmailOtpType, I as EmailSignInOptions, J as EmailSignUpData, K as EmailSignUpOptions, L as EnableTwoFactorOptions, M as EnvironmentType, N as GenerateBackupCodesOptions, O as GetOrganizationInvitationOptions, Q as GetOrganizationOptions, R as GetToken, S as GetTokenOptions, T as InviteOrganizationMemberOptions, U as JsonObject, V as JsonPrimitive, W as JsonValue, X as LeaveOrganizationOptions, Y as LinkSocialData, Z as LinkSocialOptions, _ as ListOrganizationInvitationsOptions, $ as ListOrganizationMembersOptions, a0 as ListOrganizationRolesOptions, a1 as ListOrganizationTeamsOptions, a2 as MagicLinkData, a3 as MagicLinkSignInOptions, a4 as Organization, a5 as OrganizationClient, a6 as OrganizationDetails, a7 as OrganizationFilterOperator, a8 as OrganizationInvitation, a9 as OrganizationInvitationActionOptions, aa as OrganizationInvitationDetails, ab as OrganizationInvitationStatus, ac as OrganizationMember, ad as OrganizationMemberUser, ae as OrganizationMemberWithUser, af as OrganizationMembersData, ag as OrganizationRoleSummary, ah as OrganizationSelector, ai as OrganizationTeam, aj as OrganizationUserInvitation, ak as PasskeyAuthData, al as PasskeySignInOptions, am as PasswordResetData, an as PhoneAuthUser, ao as PhoneOtpStartData, ap as PhoneOtpStartOptions, aq as PhoneOtpVerifyData, ar as PhoneOtpVerifyOptions, as as ProjectCapabilities, at as PublicConfig, au as RejectOrganizationInvitationData, av as RemoveOrganizationMemberData, aw as RemoveOrganizationMemberOptions, ax as RequestPasswordResetOptions, ay as ResetPasswordOptions, az as RevokeSessionOptions, aA as SendOtpData, aB as SendTwoFactorOtpData, aC as SendTwoFactorOtpOptions, aD as SendVerificationOtpOptions, aE as SessionState, aF as SessionStore, aG as SetActiveOrganizationOptions, aH as SetActiveTeamOptions, aI as SignOutData, aJ as SocialAccount, aK as SocialAuthData, aL as SocialIdTokenOptions, aM as SocialSignInOptions, aN as TokenClient, aO as TwoFactorBackupCodesData, aP as TwoFactorEnableData, aQ as TwoFactorRedirectData, aR as TwoFactorStatusData, aS as TwoFactorVerifyData, aT as UnlinkSocialOptions, aU as UpdateOrganizationMemberRoleOptions, aV as UpdateOrganizationOptions, aW as UpdatePasskeyData, aX as UpdatePasskeyOptions, aY as UpdateProfileOptions, aZ as UpdateUnsafeMetadataOptions, a_ as UserMetadata, a$ as UsernameSignInOptions, b0 as VerifyBackupCodeOptions, b1 as VerifyEmailOtpData, b2 as VerifyEmailOtpOptions, b3 as VerifyTotpOptions, b4 as VerifyTwoFactorOtpOptions, b5 as WaitlistJoinData, b6 as WaitlistJoinOptions, b7 as acceptConsent, b8 as createAuthOwlClient, b9 as createTokenClient, ba as getConsentStatus, bb as getPublicConfig, bc as resolveProjectCapabilities } from './client-jpaYv3wu.js';
4
+ export { T as TransportError, a as TransportErrorKind } from './transport-DcWDTRd4.js';
5
+ export { L as LOCALES, a as Locale, d as directionFor, i as isLocale } from './index-hIdXOzRp.js';
3
6
 
4
- /** Legal-consent status for the signed-in user (server contract: `GET /consent`). */
5
- type ConsentStatus = {
6
- /** Whether the project has an active consent gate at all. */
7
- required: boolean;
8
- /**
9
- * True when the signed-in user must (re-)accept the current version — either
10
- * never accepted, or the operator bumped the version since they did. Absent
11
- * when `required` is false or the user isn't signed in.
12
- */
13
- needsConsent?: boolean;
14
- version?: number;
15
- termsUrl?: string;
16
- privacyUrl?: string;
17
- };
18
- type ConsentAcceptResult = {
19
- ok: boolean;
20
- version?: number;
21
- };
22
7
  /**
23
- * Fetch the signed-in user's consent status. Sent WITH cookies (needs the
24
- * session). A 401 (not signed in) resolves to `{ required: false }` — new users
25
- * are handled by the sign-up consent gate, not this one.
8
+ * Complete Akedly Shield's browser-only proof ceremony. The provider package is
9
+ * lazy-loaded only when the server-selected route requires it.
26
10
  */
27
- declare function getConsentStatus(config: ResolvedAuthConfig): Promise<ConsentStatus>;
28
- /**
29
- * Record the signed-in user's acceptance of the terms version they were shown.
30
- * `version` is echoed from {@link getConsentStatus} so the server records only the
31
- * exact version the UI displayed; if the operator bumped it in between, the server
32
- * rejects with 409 (surfaced as a thrown error) and the caller should re-fetch.
33
- */
34
- declare function acceptConsent(config: ResolvedAuthConfig, version: number): Promise<ConsentAcceptResult>;
35
-
36
- /**
37
- * Short-lived JWTs for third-party backends (Convex, Supabase, Hasura - server
38
- * contract CONTRACTS §8, `GET <issuer>/token`). The server signs a ~15-minute
39
- * ES256 token for the signed-in user; verifiers check it statelessly against
40
- * the project's published JWKS.
41
- *
42
- * Contract (recorded from the convex@1.42.1 source, evidence 17-B.9):
43
- * - `forceRefresh: true` MUST bypass only the selected template cache and hit
44
- * the network. A stale token served to a verifier retry is a hard failure
45
- * loop.
46
- * - Tokens are cached in MEMORY ONLY (never localStorage - PLAN.md security
47
- * model), and served only while comfortably inside their `exp`. Named cache
48
- * keys include the client environment, token subject, active organization,
49
- * normalized template name, and server template policy version. The client
50
- * wrapper clears all entries when the auth identity changes.
51
- * - "Not signed in" (401) resolves to `null`; other failures throw (adapters
52
- * map them to null per Convex's error contract).
53
- */
54
- type GetTokenOptions = {
55
- /** Named JWT template configured for this environment. */
56
- template?: string;
57
- /** Bypass the in-memory cache and mint a fresh token from the server. */
58
- forceRefresh?: boolean;
59
- };
60
- type GetToken = (options?: GetTokenOptions) => Promise<string | null>;
61
- type TokenClient = {
62
- getToken: GetToken;
63
- /** Drop the cached token (call on any auth-identity change, e.g. sign-out). */
64
- clear: () => void;
65
- };
66
- /**
67
- * Build a token client bound to one config. `getToken` is cheap to call
68
- * repeatedly: fresh cached tokens return without a request, and concurrent
69
- * non-forced calls share one in-flight request.
70
- */
71
- declare function createTokenClient(config: ResolvedAuthConfig): TokenClient;
72
-
73
- declare const AUTH_CHALLENGE_HEADER = "x-authowl-turnstile-token";
74
-
75
- type JsonPrimitive = string | number | boolean | null;
76
- type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
77
- type JsonObject = {
78
- [key: string]: JsonValue;
79
- };
80
- /** Browser-safe metadata for the currently signed-in user. */
81
- interface UserMetadata {
82
- /** Trusted server-authored data. End users can read but cannot write it. */
83
- publicMetadata: JsonObject;
84
- /** End-user-owned data. Applications must treat every value as untrusted. */
85
- unsafeMetadata: JsonObject;
86
- /** Pass this value as expectedVersion on the next unsafe metadata write. */
87
- metadataVersion: number;
88
- }
89
- interface UpdateUnsafeMetadataOptions {
90
- expectedVersion: number;
91
- /** JSON Merge Patch. Null members delete the matching stored key. */
92
- unsafeMetadata: JsonObject;
93
- }
94
-
95
- interface UpdateProfileOptions {
96
- name?: string;
97
- image?: string | null;
98
- username?: string;
99
- firstName?: string;
100
- lastName?: string;
101
- }
102
- interface ChangeEmailOptions {
103
- newEmail: string;
104
- callbackURL?: string;
105
- }
106
- interface ChangePasswordOptions {
107
- currentPassword: string;
108
- newPassword: string;
109
- revokeOtherSessions?: boolean;
110
- }
111
- interface ChangePasswordData {
112
- user: AuthUser;
113
- }
114
- /** Browser-safe metadata for one signed-in session. */
115
- interface AccountSession {
116
- id: string;
117
- userId: string;
118
- createdAt: Date;
119
- updatedAt: Date;
120
- expiresAt: Date;
121
- ipAddress?: string | null;
122
- userAgent?: string | null;
123
- }
124
- interface RevokeSessionOptions {
125
- sessionId: string;
126
- }
127
- interface AccountStatusData {
128
- status: boolean;
129
- }
130
- interface SocialAccount {
131
- id: string;
132
- userId: string;
133
- providerId: string;
134
- accountId: string;
135
- scopes: string[];
136
- createdAt: Date;
137
- updatedAt: Date;
138
- /** False when disconnecting this provider would remove the last sign-in method. */
139
- canUnlink: boolean;
140
- }
141
- interface LinkSocialOptions {
142
- provider: string;
143
- callbackURL?: string;
144
- errorCallbackURL?: string;
145
- disableRedirect?: boolean;
146
- requestSignUp?: boolean;
147
- scopes?: string[];
148
- idToken?: SocialIdTokenOptions & {
149
- scopes?: string[];
150
- };
151
- }
152
- interface LinkSocialData {
153
- url: string;
154
- redirect: boolean;
155
- }
156
- interface UnlinkSocialOptions {
157
- providerId: string;
158
- accountId?: string;
159
- }
160
- interface DeleteAccountOptions {
161
- callbackURL?: string;
162
- password?: string;
163
- token?: string;
164
- }
165
- interface DeleteAccountData {
166
- success: boolean;
167
- message: string;
168
- }
169
- interface AccountClient {
170
- /** Read public and unsafe metadata for the signed-in user. Private metadata is never returned. */
171
- getMetadata(fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<UserMetadata>>;
172
- /** Optimistically apply a JSON Merge Patch to end-user-owned unsafe metadata. */
173
- updateUnsafeMetadata(params: UpdateUnsafeMetadataOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<UserMetadata>>;
174
- updateProfile(params: UpdateProfileOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AccountStatusData>>;
175
- changeEmail(params: ChangeEmailOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AccountStatusData>>;
176
- changePassword(params: ChangePasswordOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<ChangePasswordData>>;
177
- listSessions(fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AccountSession[]>>;
178
- revokeSession(params: RevokeSessionOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AccountStatusData>>;
179
- revokeOtherSessions(fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AccountStatusData>>;
180
- listSocialAccounts(fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<SocialAccount[]>>;
181
- linkSocial(params: LinkSocialOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<LinkSocialData>>;
182
- unlinkSocial(params: UnlinkSocialOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AccountStatusData>>;
183
- /** Available only when `PublicConfig.accountDeletion` is true. */
184
- delete(params?: DeleteAccountOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<DeleteAccountData>>;
185
- }
186
-
187
- interface Organization {
188
- id: string;
189
- name: string;
190
- slug: string;
191
- createdAt: Date;
192
- logo?: string | null;
193
- metadata?: unknown;
194
- }
195
- interface OrganizationMemberUser {
196
- id: string;
197
- name: string;
198
- email: string;
199
- image?: string | null;
200
- }
201
- interface OrganizationMember {
202
- id: string;
203
- organizationId: string;
204
- userId: string;
205
- role: string;
206
- createdAt: Date;
207
- user?: OrganizationMemberUser;
208
- }
209
- interface OrganizationMemberWithUser extends OrganizationMember {
210
- user: OrganizationMemberUser;
211
- }
212
- type OrganizationInvitationStatus = 'pending' | 'accepted' | 'rejected' | 'canceled';
213
- interface OrganizationInvitation {
214
- id: string;
215
- organizationId: string;
216
- email: string;
217
- role: string;
218
- status: OrganizationInvitationStatus;
219
- inviterId: string;
220
- expiresAt: Date;
221
- createdAt: Date;
222
- }
223
- interface OrganizationInvitationDetails extends OrganizationInvitation {
224
- organizationName: string;
225
- organizationSlug: string;
226
- inviterEmail: string;
227
- }
228
- interface OrganizationUserInvitation extends OrganizationInvitation {
229
- organizationName: string;
230
- }
231
- interface OrganizationDetails extends Organization {
232
- members: OrganizationMemberWithUser[];
233
- invitations: OrganizationInvitation[];
234
- }
235
- interface CreateOrganizationOptions {
236
- name: string;
237
- slug: string;
238
- logo?: string | null;
239
- metadata?: Record<string, unknown>;
240
- keepCurrentActiveOrganization?: boolean;
241
- }
242
- interface OrganizationSelector {
243
- organizationId?: string;
244
- organizationSlug?: string;
245
- }
246
- interface GetOrganizationOptions extends OrganizationSelector {
247
- membersLimit?: number;
248
- }
249
- interface SetActiveOrganizationOptions {
250
- organizationId?: string | null;
251
- organizationSlug?: string;
252
- }
253
- /**
254
- * A team: a named sub-group of members inside one organization.
255
- *
256
- * Teams are GROUPING only. Being on one grants nothing - a member's authority comes
257
- * from their organization role. Use a team to decide what your own product shows or
258
- * routes, never as an authority check.
259
- */
260
- interface OrganizationTeam {
261
- id: string;
262
- name: string;
263
- organizationId: string;
264
- createdAt: Date;
265
- updatedAt?: Date;
266
- }
267
- interface ListOrganizationTeamsOptions {
268
- /** Defaults to the caller's active organization. */
269
- organizationId?: string;
270
- }
271
- interface SetActiveTeamOptions {
272
- /** The team to make active, or null to clear it. Must be a team the caller is on. */
273
- teamId: string | null;
274
- }
275
- interface UpdateOrganizationOptions {
276
- organizationId?: string;
277
- data: {
278
- name?: string;
279
- slug?: string;
280
- logo?: string | null;
281
- metadata?: Record<string, unknown>;
282
- };
283
- }
284
- interface DeleteOrganizationOptions {
285
- organizationId: string;
286
- }
287
- type OrganizationFilterOperator = 'eq' | 'ne' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not_in' | 'contains' | 'starts_with' | 'ends_with';
288
- interface ListOrganizationMembersOptions extends OrganizationSelector {
289
- limit?: number;
290
- offset?: number;
291
- sortBy?: string;
292
- sortDirection?: 'asc' | 'desc';
293
- filterField?: string;
294
- filterValue?: string | number | boolean;
295
- filterOperator?: OrganizationFilterOperator;
296
- }
297
- interface OrganizationMembersData {
298
- members: OrganizationMemberWithUser[];
299
- total: number;
300
- }
301
- interface InviteOrganizationMemberOptions {
302
- email: string;
303
- role: string | string[];
304
- organizationId?: string;
305
- resend?: boolean;
306
- }
307
- interface ListOrganizationInvitationsOptions {
308
- organizationId?: string;
309
- }
310
- interface GetOrganizationInvitationOptions {
311
- id: string;
312
- }
313
- interface OrganizationInvitationActionOptions {
314
- invitationId: string;
315
- }
316
- interface AcceptOrganizationInvitationData {
317
- invitation: OrganizationInvitation;
318
- member: OrganizationMember;
319
- }
320
- interface RejectOrganizationInvitationData {
321
- invitation: OrganizationInvitation | null;
322
- member: null;
323
- }
324
- interface RemoveOrganizationMemberOptions {
325
- memberIdOrEmail: string;
326
- organizationId?: string;
327
- }
328
- interface RemoveOrganizationMemberData {
329
- member: OrganizationMember;
330
- }
331
- interface UpdateOrganizationMemberRoleOptions {
332
- memberId: string;
333
- role: string | string[];
334
- organizationId?: string;
335
- }
336
- interface LeaveOrganizationOptions {
337
- organizationId: string;
338
- }
339
- interface ListOrganizationRolesOptions {
340
- /** Defaults to the caller's active organization. */
341
- organizationId?: string;
342
- }
343
- /**
344
- * A role assignable in an organization, as returned by the engine's
345
- * `/organization/list-roles` (the per-org dynamic roles, which after projection
346
- * include this project's custom roles). Built-in `owner`/`admin`/`member` are
347
- * static and NOT returned here - the UI adds them alongside this list.
348
- */
349
- interface OrganizationRoleSummary {
350
- role: string;
351
- /** The role's ⊆14 system-statement document (engine shape); advisory here. */
352
- permission?: unknown;
353
- }
354
- interface OrganizationClient {
355
- create(params: CreateOrganizationOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<Organization>>;
356
- list(fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<Organization[]>>;
357
- get(params?: GetOrganizationOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationDetails | null>>;
358
- setActive(params: SetActiveOrganizationOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<Organization | null>>;
359
- /**
360
- * The teams of an organization, for resolving the team ids carried in the
361
- * membership claim to names. Requires membership of that organization.
362
- */
363
- listTeams(params?: ListOrganizationTeamsOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationTeam[]>>;
364
- /**
365
- * Select the caller's active team, which surfaces as `activeTeamId` on the session
366
- * and `team_id` in the project token. Only a team the caller is on can be made
367
- * active; pass null to clear it. Clearing also happens on its own whenever the
368
- * active organization changes.
369
- */
370
- setActiveTeam(params: SetActiveTeamOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationTeam | null>>;
371
- update(params: UpdateOrganizationOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<Organization | null>>;
372
- delete(params: DeleteOrganizationOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<Organization>>;
373
- listMembers(params?: ListOrganizationMembersOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationMembersData>>;
374
- inviteMember(params: InviteOrganizationMemberOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationInvitation>>;
375
- listInvitations(params?: ListOrganizationInvitationsOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationInvitation[]>>;
376
- listUserInvitations(fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationUserInvitation[]>>;
377
- getInvitation(params: GetOrganizationInvitationOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationInvitationDetails>>;
378
- acceptInvitation(params: OrganizationInvitationActionOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AcceptOrganizationInvitationData>>;
379
- rejectInvitation(params: OrganizationInvitationActionOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<RejectOrganizationInvitationData>>;
380
- cancelInvitation(params: OrganizationInvitationActionOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationInvitation | null>>;
381
- removeMember(params: RemoveOrganizationMemberOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<RemoveOrganizationMemberData>>;
382
- updateMemberRole(params: UpdateOrganizationMemberRoleOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationMember>>;
383
- leave(params: LeaveOrganizationOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationMember>>;
384
- /**
385
- * List the roles assignable in an organization (the engine's dynamic roles,
386
- * which include this project's projected custom roles). Built-in roles are
387
- * static and not returned; surfaces populate the select alongside them.
388
- */
389
- listRoles(params?: ListOrganizationRolesOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<OrganizationRoleSummary[]>>;
390
- /**
391
- * Clerk-style `has()` over the ACTIVE membership's advisory claim: true when
392
- * the signed-in member's role matches `role` AND/OR their permissions include
393
- * `permission`. PURE + synchronous - it reads the local session claim and
394
- * NEVER calls `/organization/has-permission` (which only knows the 14 static
395
- * statements and would wrongly deny custom permissions). UX affordance only;
396
- * enforce real authorization server-side over the verified token.
397
- */
398
- has(params: HasParams): boolean;
399
- /** Clerk-style `hasPermission()`: true when the active membership grants `permission`. Pure. */
400
- hasPermission(params: {
401
- permission: string;
402
- }): boolean;
403
- }
404
-
405
- /**
406
- * The narrow, portable surface of the underlying auth client that this SDK
407
- * depends on and re-exports.
408
- *
409
- * We deliberately do NOT expose the engine's full inferred client type: it
410
- * references internal module paths (not portable across package boundaries -
411
- * TS2742) and is too large to serialize into a `.d.ts` (TS7056). Hand-writing
412
- * the surface we actually use keeps the published types small, stable, and
413
- * portable. Extend these interfaces as the SDK starts using more of the client
414
- * (e.g. two-factor / organization / passkey flows in later plans).
415
- */
416
- /**
417
- * Minimal end-user shape the SDK surfaces (mirror of the underlying session
418
- * user). `name`/`image` are optional and nullable because the engine omits
419
- * them entirely for users that have none - this SDK only casts the response, it
420
- * does not normalize missing fields, so the type must not over-promise.
421
- */
422
- interface AuthUser {
423
- id: string;
424
- /** Null for phone-only users whose internal synthetic email is redacted. */
425
- email: string | null;
426
- /** Present for phone-authenticated users when the phone plugin is enabled. */
427
- phoneNumber?: string | null;
428
- /** Canonical project-scoped username, when username support is enabled. */
429
- username?: string | null;
430
- /** User-facing username casing retained alongside the canonical value. */
431
- displayUsername?: string | null;
432
- /** Structured profile names, when enabled by the project. */
433
- firstName?: string | null;
434
- lastName?: string | null;
435
- emailVerified: boolean;
436
- name?: string | null;
437
- image?: string | null;
438
- createdAt: Date;
439
- updatedAt: Date;
440
- /**
441
- * Whether the user has a verified second factor enrolled. Optional and
442
- * nullable because the engine only includes it once the twoFactor plugin is
443
- * active and the user has enrolled; treat a missing value as "not enrolled".
444
- */
445
- twoFactorEnabled?: boolean | null;
446
- }
447
- interface AuthSession {
448
- id: string;
449
- userId: string;
450
- expiresAt: Date;
451
- /**
452
- * The active organization id, present once the organization plugin is in use
453
- * and the user has set an active org. Mirrors the JWT's `org_id` claim, so
454
- * consumers (e.g. the Convex adapter) can re-mint tokens when it changes.
455
- */
456
- activeOrganizationId?: string | null;
457
- /**
458
- * The member's active team within the active organization, or null.
459
- *
460
- * AuthOwl VALIDATES this before returning it: a stored pointer at a team in
461
- * another organization, at a deleted team, or at one the member has been removed
462
- * from comes back null, so it never needs re-checking here. The JWT carries the
463
- * same value as `team_id`, which is OMITTED rather than null when there is none -
464
- * the same convention `org_id` follows.
465
- */
466
- activeTeamId?: string | null;
467
- /**
468
- * The active organization membership - the member's canonical role and its
469
- * advisory permission claim (`org:sys_*` + custom `org:<feature>:<action>`
470
- * ids), populated by AuthOwl's `/get-session` shaping for the active org, else
471
- * `null`. This is the array the client `has()`/`hasPermission()` evaluate. It
472
- * is a UX affordance, NOT a security boundary: enforce authorization on the
473
- * server with the verified token (`@authowl/next`'s server `has()`).
474
- */
475
- membership?: OrganizationMembership | null;
476
- /**
477
- * B.5c: true while this session is held at required-MFA enrolment (the
478
- * project requires MFA and the user has no verified factor). The SDK and
479
- * auth() treat such a session as unauthenticated for app purposes; it is
480
- * cleared server-side when enrolment completes (CONTRACTS §5).
481
- */
482
- pendingMfaEnrollment?: boolean | null;
483
- }
484
- interface AuthClientError {
485
- message?: string;
486
- status?: number;
487
- statusText?: string;
488
- code?: AuthOwlErrorCode | (string & {});
489
- /** Sanitized upstream correlation id, when the service supplied one. */
490
- requestId?: string;
491
- /** Present on VERSION_CONFLICT so the caller can re-read before retrying. */
492
- currentVersion?: number;
493
- /**
494
- * Seconds to wait before retrying, parsed from the body's `retryAfterSeconds`
495
- * field or the `Retry-After` / `X-Retry-After` header (delta-seconds form),
496
- * clamped to [1, 86400]. Present on rate-limit / lockout responses so callers
497
- * can render a live countdown; the drop-in forms surface it automatically.
498
- */
499
- retryAfterSeconds?: number;
500
- }
501
- /** Secret-free lifecycle metadata exposed before an auth request is sent. */
502
- type AuthRequestContext = Readonly<{
503
- method: 'GET' | 'POST' | 'PATCH';
504
- /** Endpoint path only. Query values, headers, cookies, and bodies are omitted. */
505
- path: string;
506
- }>;
507
- /** Secret-free lifecycle metadata exposed after a parsed response arrives. */
508
- type AuthResponseContext = Readonly<AuthRequestContext & {
509
- status: number;
510
- requestId?: string;
511
- }>;
512
- /** Secret-free lifecycle metadata exposed for transport or API failures. */
513
- type AuthErrorContext = Readonly<AuthRequestContext & {
514
- status: number;
515
- requestId?: string;
516
- failure: 'api' | 'aborted' | 'timeout' | 'network' | 'response_too_large' | 'invalid_response';
517
- }>;
518
- /** Stable AuthOwl policy codes that callers can handle without matching messages. */
519
- type AuthOwlErrorCode = 'MAU_BUDGET_REACHED' | 'BOT_CHALLENGE_FAILED' | 'VERSION_CONFLICT' | 'SESSION_NOT_FRESH' | 'ORGANIZATION_LAST_OWNER' | 'ORGANIZATION_NOT_FOUND' | 'MEMBER_NOT_FOUND' | 'INVITATION_NOT_FOUND' | 'EMAIL_VERIFICATION_REQUIRED_FOR_INVITATION' | 'EMAIL_VERIFICATION_REQUIRED_BEFORE_ACCEPTING_OR_REJECTING_INVITATION' | 'YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION';
520
- /** Framework-neutral reactive session snapshot. */
521
- interface SessionState {
522
- data: {
523
- user: AuthUser;
524
- session: AuthSession;
525
- } | null;
526
- isPending: boolean;
527
- isRefetching: boolean;
528
- error: AuthClientError | null;
529
- /**
530
- * Re-fetch the current session from the server. `query.disableCookieCache`
531
- * forces a database read AND re-sets the session cookie - the repair path
532
- * for a stale cookie-cached `pendingMfaEnrollment` (CONTRACTS §5).
533
- */
534
- refetch: (options?: {
535
- query?: {
536
- disableCookieCache?: boolean;
537
- };
538
- }) => void;
539
- }
540
- /**
541
- * External-store contract consumed by framework bindings such as
542
- * `@authowl/react`. Core never imports a UI framework.
543
- */
544
- interface SessionStore {
545
- subscribe(listener: () => void): () => void;
546
- getSnapshot(): SessionState;
547
- }
548
- /** Standard `{ data, error }` envelope returned by the client's auth actions. */
549
- interface AuthActionResult<T = Record<string, unknown>> {
550
- data: T | null;
551
- error: AuthClientError | null;
552
- }
553
- /** Success payload of the email sign-in action. */
554
- interface EmailAuthData {
555
- user: AuthUser;
556
- /** Whether the server supplied a callback redirect. */
557
- redirect: boolean;
558
- url?: string;
559
- }
560
- /** Success payload of an in-place email one-time-code sign-in. */
561
- interface EmailOtpAuthData {
562
- user: AuthUser;
563
- }
564
- /**
565
- * Returned by a credential sign-in when the user has two-factor enrolled: NO
566
- * session is issued (`token`/`user` are absent) and the client must clear the 2FA
567
- * challenge (verify a TOTP or backup code) before it is signed in. This is the
568
- * discriminant `<SignIn/>` branches on; a headless consumer must handle it too.
569
- */
570
- interface TwoFactorRedirectData {
571
- twoFactorRedirect: true;
572
- /** Factors the server will accept, e.g. `["totp"]` / `["otp"]`. */
573
- twoFactorMethods?: string[];
574
- }
575
- /**
576
- * Success payload of the email sign-up action. `sessionCreated` is false when
577
- * the project requires email verification or has auto-sign-in disabled, so no
578
- * browser session was issued yet.
579
- */
580
- interface EmailSignUpData {
581
- sessionCreated: boolean;
582
- user: AuthUser;
583
- }
584
- /** Success payload of the social sign-in action. */
585
- type SocialAuthData = {
586
- redirect: true;
587
- url: string;
588
- } | {
589
- redirect: false;
590
- url: string;
591
- } | {
592
- redirect: false;
593
- user: AuthUser;
594
- };
595
- /**
596
- * Success payload of the enterprise SSO sign-in action. OIDC/SAML SSO is always
597
- * a redirect flow (there is no in-place ID-token variant), so this is the
598
- * social payload's redirect half only: the client sends the browser to the
599
- * identity provider and the session is minted when the provider callback lands
600
- * on a fresh page.
601
- */
602
- interface SsoAuthData {
603
- /** Identity-provider authorization URL to send the browser to. */
604
- url: string;
605
- redirect: true;
606
- }
607
- /** Success payload of the sign-out action. */
608
- interface SignOutData {
609
- success: boolean;
610
- }
611
- interface EmailSignInOptions {
612
- email: string;
613
- password: string;
614
- rememberMe?: boolean;
615
- callbackURL?: string;
616
- }
617
- interface UsernameSignInOptions {
618
- username: string;
619
- password: string;
620
- rememberMe?: boolean;
621
- callbackURL?: string;
622
- }
623
- interface EmailSignUpOptions {
624
- email: string;
625
- password: string;
626
- name: string;
627
- username?: string;
628
- firstName?: string;
629
- lastName?: string;
630
- image?: string;
631
- callbackURL?: string;
632
- /**
633
- * The accepted legal-consent version (from `PublicConfig.legal.version`). Sent
634
- * in the sign-up body; when the project requires consent the server rejects a
635
- * sign-up whose value is missing or below the current version. <SignUp/> sets
636
- * this automatically when it renders the consent checkbox.
637
- */
638
- consentVersion?: number;
639
- }
640
- interface WaitlistJoinOptions {
641
- email: string;
642
- }
643
- interface WaitlistJoinData {
644
- accepted: true;
645
- }
646
- /** ID-token payload for non-redirect social sign-in (e.g. native Google/Apple). */
647
- interface SocialIdTokenOptions {
648
- token: string;
649
- nonce?: string;
650
- accessToken?: string;
651
- refreshToken?: string;
652
- expiresAt?: number;
653
- }
654
- /** Options for the social sign-in action (mirror of the underlying client's). */
655
- interface SocialSignInOptions {
656
- provider: string;
657
- callbackURL?: string;
658
- errorCallbackURL?: string;
659
- newUserCallbackURL?: string;
660
- disableRedirect?: boolean;
661
- scopes?: string[];
662
- loginHint?: string;
663
- requestSignUp?: boolean;
664
- /** Sign in with a provider ID token instead of the redirect flow. */
665
- idToken?: SocialIdTokenOptions;
666
- }
667
- /**
668
- * Options for enterprise SSO sign-in - a SAFE SUBSET of the server's
669
- * `signInSSOBodySchema` (the client posts the body wholesale, so no client-only
670
- * fields leak onto the wire). It deliberately omits `scopes` and `providerType`,
671
- * which stay server-resolved: the app injects `scopes` from the stored connection
672
- * rather than trusting the caller, since user-supplied scopes would be a
673
- * scope-escalation surface. Supply at least one of `email` / `providerId` /
674
- * `domain` / `organizationSlug` so the server can resolve the connection; the
675
- * drop-in resolves the IdP from the user's email domain. `callbackURL` is
676
- * REQUIRED by the server - where the browser lands after the IdP round-trip.
677
- */
678
- interface SsoSignInOptions {
679
- /** The user's email; its domain identifies the SSO connection to use. */
680
- email?: string;
681
- /** Resolve the connection by its provider id directly (instead of by email domain). */
682
- providerId?: string;
683
- /** Resolve the connection by verified email domain directly. */
684
- domain?: string;
685
- /** Resolve the connection by the organization slug it is bound to. */
686
- organizationSlug?: string;
687
- /** Where the browser lands after the IdP round-trip. Required by the server. */
688
- callbackURL: string;
689
- /** Where to send the browser if the SSO flow fails. */
690
- errorCallbackURL?: string;
691
- /** Where to land when SSO provisions a new account (if the connection allows it). */
692
- newUserCallbackURL?: string;
693
- /** `login_hint` forwarded to the identity provider when it supports one. */
694
- loginHint?: string;
695
- /** Explicitly request sign-up when the connection has implicit sign-up disabled. */
696
- requestSignUp?: boolean;
697
- }
698
- /** Options for passwordless magic-link sign-in (a link is emailed to the user). */
699
- interface MagicLinkSignInOptions {
700
- email: string;
701
- /** Where to land after the emailed link is followed. */
702
- callbackURL?: string;
703
- /** Where to send the browser if the link is invalid or expired. */
704
- errorCallbackURL?: string;
705
- /** Where to land when the link creates a new account (if the server allows it). */
706
- newUserCallbackURL?: string;
707
- }
708
- /**
709
- * Success payload of the magic-link request. No session is issued here - the
710
- * link is emailed and the session is created when the user follows it.
711
- */
712
- interface MagicLinkData {
713
- status: boolean;
714
- }
715
- /** Purpose of an email one-time code. Sign-in is the SDK's passwordless flow. */
716
- type EmailOtpType = 'sign-in' | 'email-verification' | 'forget-password';
717
- /** Options to request an email one-time code. */
718
- interface SendVerificationOtpOptions {
719
- email: string;
720
- type: EmailOtpType;
721
- }
722
- /** Success payload of the send-OTP request (no session yet). */
723
- interface SendOtpData {
724
- success: boolean;
725
- }
726
- /** Options to complete email-OTP sign-in with the emailed code. */
727
- interface EmailOtpSignInOptions {
728
- email: string;
729
- otp: string;
730
- }
731
- /** Options to complete required email ownership verification with a code. */
732
- interface VerifyEmailOtpOptions {
733
- email: string;
734
- otp: string;
735
- }
736
- interface VerifyEmailOtpData {
737
- status: boolean;
738
- user: AuthUser;
739
- }
740
- /** Start an Egyptian phone OTP sign-in. Reuse idempotencyKey after an ambiguous retry. */
741
- interface PhoneOtpStartOptions {
742
- phoneNumber: string;
743
- turnstileToken: string;
744
- idempotencyKey?: string;
745
- }
746
- interface PhoneOtpStartData {
747
- status: 'pending';
748
- }
749
- /** Verify the SMS code and create or resume the phone user's session. */
750
- interface PhoneOtpVerifyOptions {
751
- phoneNumber: string;
752
- code: string;
753
- consentVersion?: number;
754
- }
755
- interface PhoneAuthUser {
756
- id: string;
757
- name?: string | null;
758
- phoneNumber: string;
759
- phoneNumberVerified: boolean;
760
- createdAt?: Date;
761
- updatedAt?: Date;
762
- }
763
- interface PhoneOtpVerifyData {
764
- status: true;
765
- sessionCreated: true;
766
- user: PhoneAuthUser;
767
- }
768
- /** Options to request a password-reset email. */
769
- interface RequestPasswordResetOptions {
770
- email: string;
771
- /**
772
- * Where the emailed reset link lands - the page hosting your reset form. The
773
- * link validates the token server-side then redirects here with `?token=`. Its
774
- * origin must be one of the project's allowed origins.
775
- */
776
- redirectTo?: string;
777
- }
778
- /** Options to set a new password with a reset token. */
779
- interface ResetPasswordOptions {
780
- newPassword: string;
781
- /** The token from the `?token=` query param the reset link redirected to. */
782
- token: string;
783
- }
784
- /** Success payload of the request-reset / reset-password actions (no session). */
785
- interface PasswordResetData {
786
- status: boolean;
787
- }
788
- /** Options to (re)send the email-verification link. */
789
- interface SendVerificationEmailOptions {
790
- email: string;
791
- /**
792
- * Where the verification link lands after it confirms the address - the page
793
- * hosting <VerifyEmail/>. Its origin must be one of the project's allowed
794
- * origins. Defaults to "/" server-side when omitted.
795
- */
796
- callbackURL?: string;
797
- }
798
- /** Success payload of the send-verification-email action (no session). */
799
- interface VerificationEmailData {
800
- status: boolean;
801
- }
802
- /** Options for passkey (WebAuthn) sign-in. */
803
- interface PasskeySignInOptions {
804
- /**
805
- * Use conditional mediation (browser autofill) instead of a modal. The caller
806
- * must have an input with an `autocomplete` value containing `webauthn` on the
807
- * page for the browser to surface passkeys; the promise resolves when the user
808
- * picks one. Defaults to a modal prompt.
809
- */
810
- autoFill?: boolean;
811
- }
812
- /** Success payload of passkey sign-in. */
813
- interface PasskeyAuthData {
814
- session: AuthSession;
815
- user: AuthUser;
816
- }
817
- /**
818
- * A registered passkey credential projected from the engine's row. Only `id`,
819
- * `name`, `deviceType`, and `createdAt` are needed to render a management list;
820
- * the rest are surfaced for completeness.
821
- */
822
- interface AuthPasskey {
823
- id: string;
824
- name?: string | null;
825
- publicKey: string;
826
- userId: string;
827
- credentialID: string;
828
- counter: number;
829
- /** WebAuthn credential device type. */
830
- deviceType: 'singleDevice' | 'multiDevice';
831
- backedUp: boolean;
832
- transports?: string | null;
833
- createdAt: Date;
834
- aaguid?: string | null;
835
- }
836
- /** Options to register a new passkey for the signed-in user. */
837
- interface AddPasskeyOptions {
838
- /** Human label shown in the passkey list (defaults to a browser-chosen name). */
839
- name?: string;
840
- /** Prefer a platform (device) or cross-platform (security key) authenticator. */
841
- authenticatorAttachment?: 'platform' | 'cross-platform';
842
- }
843
- /** Options to rename an existing passkey. */
844
- interface UpdatePasskeyOptions {
845
- id: string;
846
- name: string;
847
- }
848
- /** Options to remove an existing passkey. */
849
- interface DeletePasskeyOptions {
850
- id: string;
851
- }
852
- /** Success payload of the delete-passkey action. */
853
- interface DeletePasskeyData {
854
- status: true;
855
- }
856
- /**
857
- * Success payload of the update-passkey action. The engine returns the updated
858
- * row wrapped as `{ passkey }` (not a bare passkey), so consumers read
859
- * `res.data.passkey`.
860
- */
861
- interface UpdatePasskeyData {
862
- passkey: AuthPasskey;
863
- }
864
- /** Options to begin TOTP two-factor enrolment (password-gated). */
865
- interface EnableTwoFactorOptions {
866
- password: string;
867
- /** Overrides the issuer label shown in the authenticator app (defaults server-side). */
868
- issuer?: string;
869
- }
870
- /**
871
- * Enrolment payload: the `otpauth://` URI to render as a QR (and its embedded
872
- * secret for manual entry) plus the one-time backup codes, shown ONCE. The factor
873
- * is not active until a live TOTP is verified.
874
- */
875
- interface TwoFactorEnableData {
876
- totpURI: string;
877
- backupCodes: string[];
878
- }
879
- /** Options to disable two-factor for the signed-in user (password-gated). */
880
- interface DisableTwoFactorOptions {
881
- password: string;
882
- }
883
- /** Options to (re)generate the backup codes (password-gated), invalidating the old set. */
884
- interface GenerateBackupCodesOptions {
885
- password: string;
886
- }
887
- /** Payload carrying a freshly-generated set of backup codes (shown once). */
888
- interface TwoFactorBackupCodesData {
889
- backupCodes: string[];
890
- }
891
- /** Verify a TOTP code - to activate a new factor, or to clear a sign-in challenge. */
892
- interface VerifyTotpOptions {
893
- code: string;
894
- /** Skip the challenge on this device for ~30 days (sets a trusted-device cookie). */
895
- trustDevice?: boolean;
896
- }
897
- /** Verify a single-use backup code to clear a sign-in challenge. */
898
- interface VerifyBackupCodeOptions {
899
- code: string;
900
- trustDevice?: boolean;
901
- }
902
- /** Request the emailed fallback code for a pending 2FA challenge (B.5d). */
903
- interface SendTwoFactorOtpOptions {
904
- /**
905
- * Inert here - the engine's send endpoint accepts this field but ignores it;
906
- * device trust is granted only when you verify. Pass `trustDevice` to
907
- * `verifyOtp` instead.
908
- */
909
- trustDevice?: boolean;
910
- }
911
- /** Success payload of the fallback-code send (the code goes to the user's email). */
912
- interface SendTwoFactorOtpData {
913
- status: boolean;
914
- }
915
- /** Verify the emailed fallback code to clear a sign-in challenge. */
916
- interface VerifyTwoFactorOtpOptions {
917
- code: string;
918
- trustDevice?: boolean;
919
- }
920
- /**
921
- * Result of clearing a 2FA challenge. The browser session is issued only via
922
- * Set-Cookie; its durable token is never projected into JavaScript state.
923
- */
924
- interface TwoFactorVerifyData {
925
- status: true;
926
- }
927
- /** Success payload of enable/disable (the engine returns a bare status flag). */
928
- interface TwoFactorStatusData {
929
- status: boolean;
930
- }
931
- /**
932
- * Per-call fetch options every action accepts as an optional second argument -
933
- * lifecycle callbacks and extra headers, matching the underlying client. The
934
- * callback context is intentionally `unknown`: narrow it at the call site.
935
- */
936
- interface ActionFetchOptions {
937
- headers?: Record<string, string>;
938
- /**
939
- * Single-use Cloudflare Turnstile token for a protected public-auth action.
940
- * The SDK transports it in `x-authowl-turnstile-token`; it is never serialized
941
- * into the action JSON body. Obtain the token with the exact action name
942
- * documented for the endpoint.
943
- */
944
- authChallengeToken?: string;
945
- signal?: AbortSignal;
946
- /**
947
- * Retry safe GET network failures and 5xx responses, capped at three retries.
948
- * POST and PATCH actions are never replayed by the generic client.
949
- */
950
- retry?: number;
951
- onRequest?: (context: AuthRequestContext) => unknown;
952
- onResponse?: (context: AuthResponseContext) => unknown;
953
- onSuccess?: (context: AuthResponseContext) => unknown;
954
- onError?: (context: AuthErrorContext) => unknown;
955
- }
956
- interface AuthOwlClient {
957
- /** Framework-neutral session state. React consumers use `@authowl/react`'s `useSession()`. */
958
- sessionStore: SessionStore;
959
- /** Signed-in account profile, credential, session, provider, and deletion actions. */
960
- account: AccountClient;
961
- /** Signed-in organization, membership, role, and invitation actions. */
962
- organization: OrganizationClient;
963
- signIn: {
964
- /**
965
- * Email + password sign-in. For a two-factor-enrolled user the result is a
966
- * {@link TwoFactorRedirectData} (no session) - branch on `twoFactorRedirect`
967
- * before treating the sign-in as complete.
968
- */
969
- email(params: EmailSignInOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<EmailAuthData | TwoFactorRedirectData>>;
970
- /** Username + password sign-in, when enabled by project policy. */
971
- username(params: UsernameSignInOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<EmailAuthData | TwoFactorRedirectData>>;
972
- social(params: SocialSignInOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<SocialAuthData>>;
973
- /**
974
- * Enterprise SSO (OIDC/SAML): resolve the tenant's identity provider (by the
975
- * email domain, or an explicit `providerId`/`domain`/`organizationSlug`) and
976
- * redirect the browser to it. Always a redirect flow - no session is issued
977
- * here; it is minted when the provider callback lands on a fresh page.
978
- */
979
- sso(params: SsoSignInOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<SsoAuthData>>;
980
- /** Passwordless: email a one-time sign-in link. */
981
- magicLink(params: MagicLinkSignInOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<MagicLinkData>>;
982
- /** Passwordless: complete sign-in with an emailed one-time code. */
983
- emailOtp(params: EmailOtpSignInOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<EmailOtpAuthData>>;
984
- /** Passwordless: sign in with a registered passkey (WebAuthn). */
985
- passkey(params?: PasskeySignInOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<PasskeyAuthData>>;
986
- };
987
- signUp: {
988
- email(params: EmailSignUpOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<EmailSignUpData>>;
989
- };
990
- /** Public email-only waitlist enrollment for this environment. */
991
- waitlist: {
992
- join(params: WaitlistJoinOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<WaitlistJoinData>>;
993
- };
994
- /** Email one-time-code actions (request side; completion is `signIn.emailOtp`). */
995
- emailOtp: {
996
- sendVerificationOtp(params: SendVerificationOtpOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<SendOtpData>>;
997
- /** Complete a required email verification ceremony with an emailed code. */
998
- verifyEmail(params: VerifyEmailOtpOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<VerifyEmailOtpData>>;
999
- };
1000
- /** Managed Egyptian phone OTP. Start sends the code; verify establishes the session. */
1001
- phoneOtp: {
1002
- start(params: PhoneOtpStartOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<PhoneOtpStartData>>;
1003
- verify(params: PhoneOtpVerifyOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<PhoneOtpVerifyData>>;
1004
- };
1005
- /** Email a password-reset link to the user (no session issued). */
1006
- requestPasswordReset(params: RequestPasswordResetOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<PasswordResetData>>;
1007
- /** Set a new password using the token from a reset link. */
1008
- resetPassword(params: ResetPasswordOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<PasswordResetData>>;
1009
- /** (Re)send the email-verification link. No session required. */
1010
- sendVerificationEmail(params: SendVerificationEmailOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<VerificationEmailData>>;
1011
- /** Passkey management for the signed-in user. */
1012
- passkey: {
1013
- addPasskey(params?: AddPasskeyOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<AuthPasskey>>;
1014
- /**
1015
- * List the signed-in user's passkeys. Takes no argument: this is a GET
1016
- * endpoint and the underlying client would send a first argument as a POST
1017
- * body (flipping the method), so fetch options are intentionally not exposed.
1018
- */
1019
- listUserPasskeys(): Promise<AuthActionResult<AuthPasskey[]>>;
1020
- updatePasskey(params: UpdatePasskeyOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<UpdatePasskeyData>>;
1021
- deletePasskey(params: DeletePasskeyOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<DeletePasskeyData>>;
1022
- };
1023
- /**
1024
- * TOTP two-factor for the signed-in user (enrolment) and the sign-in challenge
1025
- * (verify). Enrolment is password-gated; a factor only becomes active once a live
1026
- * TOTP is verified. Drives {@link useMFA}/<MFAEnrollment/>/<MFAChallenge/>.
1027
- */
1028
- twoFactor: {
1029
- /** Begin enrolment: returns the TOTP URI + one-time backup codes (factor stays inactive until verified). */
1030
- enable(params: EnableTwoFactorOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<TwoFactorEnableData>>;
1031
- /** Turn two-factor off for the user (password-gated). */
1032
- disable(params: DisableTwoFactorOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<TwoFactorStatusData>>;
1033
- /** Verify a TOTP code: activates a pending factor, or clears a sign-in challenge. */
1034
- verifyTotp(params: VerifyTotpOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<TwoFactorVerifyData>>;
1035
- /** Clear a sign-in challenge with a single-use backup code. */
1036
- verifyBackupCode(params: VerifyBackupCodeOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<TwoFactorVerifyData>>;
1037
- /**
1038
- * Email a fallback second-factor code for the pending challenge (B.5d -
1039
- * the lost-authenticator path; only live during a challenge).
1040
- */
1041
- sendOtp(params?: SendTwoFactorOtpOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<SendTwoFactorOtpData>>;
1042
- /** Clear a sign-in challenge with the emailed fallback code. */
1043
- verifyOtp(params: VerifyTwoFactorOtpOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<TwoFactorVerifyData>>;
1044
- /** Regenerate the backup codes (password-gated), invalidating the previous set. */
1045
- generateBackupCodes(params: GenerateBackupCodesOptions, fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<TwoFactorBackupCodesData>>;
1046
- };
1047
- signOut(fetchOptions?: ActionFetchOptions): Promise<AuthActionResult<SignOutData>>;
1048
- /**
1049
- * One-shot session fetch (the reactive form is `sessionStore`). `query.
1050
- * disableCookieCache: true` forces a database read - required before acting
1051
- * on `pendingMfaEnrollment` (its cookie-cached value can be stale-true for
1052
- * up to 5 minutes; CONTRACTS §5).
1053
- */
1054
- getSession(options?: {
1055
- query?: {
1056
- disableCookieCache?: boolean;
1057
- };
1058
- }): Promise<AuthActionResult<{
1059
- session: AuthSession;
1060
- user: AuthUser;
1061
- } | null>>;
1062
- /**
1063
- * Mint a short-lived JWT for third-party backends (Convex/Supabase/Hasura;
1064
- * requires the project's JWT issuer to be enabled). Cached in memory and
1065
- * refreshed ahead of expiry. `{ template: 'convex' }` selects a named
1066
- * environment template and `{ forceRefresh: true }` bypasses only that
1067
- * template's cache entry.
1068
- * Resolves `null` when nobody is signed in; throws on other failures.
1069
- */
1070
- getToken: GetToken;
1071
- /**
1072
- * Legal-consent status for the signed-in user. Drives the re-consent gate: when
1073
- * the operator bumps the terms version, `needsConsent` flips true until the user
1074
- * accepts. `{ required: false }` when the project has no gate or nobody's signed in.
1075
- */
1076
- getConsentStatus(): Promise<ConsentStatus>;
1077
- /**
1078
- * Record the signed-in user's acceptance of the terms `version` they were shown
1079
- * (echo `getConsentStatus().version`). A 409 (the operator bumped the version
1080
- * meanwhile) surfaces as a thrown error; re-fetch the status and re-prompt.
1081
- */
1082
- acceptConsent(version: number): Promise<ConsentAcceptResult>;
1083
- }
1084
- /**
1085
- * Build the underlying auth client pointed at the project's per-project endpoint.
1086
- * Every request is sent with credentials so the HttpOnly session cookie flows
1087
- * cross-origin (server must set SameSite=None + Secure for this to work).
1088
- * The publishable key travels in X-Publishable-Key on every request.
1089
- */
1090
- declare function createAuthOwlClient(config: ResolvedAuthConfig): AuthOwlClient;
1091
-
1092
- type EnvironmentType = 'development' | 'production';
1093
- /**
1094
- * The public, publishable-key-safe project config the SDK renders its sign-in
1095
- * UI from (server contract CONTRACTS §2, `GET /api/projects/:id/public-config`).
1096
- * Nothing here is secret. Method slugs are canonical snake_case.
1097
- */
1098
- type PublicConfig = {
1099
- /** Stable workspace product container shared by its environments. */
1100
- applicationId: string;
1101
- /** Stable tenant id for the exact environment selected by the publishable key. */
1102
- environmentId: string;
1103
- /** Environment class that determines key prefixes and billing treatment. */
1104
- environmentType: EnvironmentType;
1105
- /** Canonical authentication endpoint for this environment. */
1106
- authBaseUrl: string;
1107
- /**
1108
- * Public acquisition mode. Optional only for rolling compatibility with
1109
- * servers released before waitlist support.
1110
- */
1111
- signUp?: {
1112
- mode: 'open' | 'restricted' | 'allowlist' | 'waitlist';
1113
- };
1114
- /**
1115
- * Identity and credential lifecycle policy. Optional only for rolling
1116
- * compatibility with AuthOwl servers released before plan 35.
1117
- */
1118
- authentication?: {
1119
- email: {
1120
- signUp: boolean;
1121
- signIn: Array<'password' | 'magic_link' | 'email_otp'>;
1122
- };
1123
- phone: {
1124
- signUp: boolean;
1125
- signIn: boolean;
1126
- };
1127
- password: {
1128
- signUp: boolean;
1129
- add: boolean;
1130
- /** Server-owned password length policy. Optional for rolling compatibility. */
1131
- minLength?: number;
1132
- maxLength?: number;
1133
- };
1134
- passkey: {
1135
- signIn: boolean;
1136
- add: boolean;
1137
- };
1138
- username: {
1139
- collectOnSignUp: boolean;
1140
- signIn: boolean;
1141
- };
1142
- };
1143
- /** Email ownership ceremony selected by the project. */
1144
- emailVerification?: {
1145
- required: boolean;
1146
- method: 'link' | 'code';
1147
- };
1148
- /** End-user profile fields and self-service permissions. */
1149
- userModel?: {
1150
- requireEmail: boolean;
1151
- firstLastName: boolean;
1152
- emailChange: boolean;
1153
- accountDeletion: boolean;
1154
- };
1155
- /**
1156
- * MFA presentation contract. Backup codes follow TOTP and are not an
1157
- * independently configurable authentication method.
1158
- */
1159
- mfa?: {
1160
- totp: boolean;
1161
- required: boolean;
1162
- backupCodes: boolean;
1163
- };
1164
- branding: {
1165
- appName?: string;
1166
- logoUrl?: string;
1167
- /** Whether the application name is visible beside the logo. */
1168
- showAppName?: boolean;
1169
- /** Alignment of the brand identity within managed component headers. */
1170
- alignment?: 'left' | 'center' | 'right';
1171
- primaryColor?: string;
1172
- theme?: 'light' | 'dark' | 'system';
1173
- };
1174
- /** Canonical method slugs, e.g. "password", "magic_link", "passkey". */
1175
- enabledMethods: string[];
1176
- /** Configured social provider ids, e.g. "google". */
1177
- socialProviders: string[];
1178
- /**
1179
- * Public OAuth client ids keyed by provider. Optional for rolling compatibility
1180
- * with servers released before Google One Tap support.
1181
- */
1182
- socialProviderClientIds?: Record<string, string>;
1183
- /**
1184
- * When true, an email/password sign-up does not create a session - the user
1185
- * must confirm their address first. <SignUp/> shows a "check your email" state
1186
- * instead of redirecting. Always false unless password sign-up is enabled.
1187
- */
1188
- requireEmailVerification: boolean;
1189
- /**
1190
- * Legal consent gate. When `required`, <SignUp/> shows an acceptance checkbox
1191
- * linking `termsUrl`/`privacyUrl` and blocks sign-up until it's checked, echoing
1192
- * `version` back so the server records and enforces it. `required` is true only
1193
- * when the project both requires consent and has a document URL to link.
1194
- */
1195
- legal: {
1196
- termsUrl?: string;
1197
- privacyUrl?: string;
1198
- version: number;
1199
- required: boolean;
1200
- };
1201
- /**
1202
- * Whether the project lets signed-in users enrol a second factor (TOTP). A
1203
- * capability flag, not a sign-in method (so it's absent from `enabledMethods`):
1204
- * gate an "enable two-factor" affordance / <MFAEnrollment/> on it. The sign-in
1205
- * 2FA challenge is handled by <SignIn/> regardless of this flag.
1206
- */
1207
- twoFactor: boolean;
1208
- /** Whether enrolled MFA is mandatory rather than optional for this project. */
1209
- mfaRequired: boolean;
1210
- /** Whether signed-in users may delete their own account. */
1211
- accountDeletion: boolean;
1212
- /** Whether organization routes and components are available for this project. */
1213
- organizations: boolean;
1214
- /**
1215
- * Whether inbound enterprise SSO is enabled for this project. SSO IS a sign-in
1216
- * method, so when true the server also pushes `'sso'` into `enabledMethods`;
1217
- * this flag mirrors the server capability (matching the `twoFactor`
1218
- * convention). <SignIn/> gates the SSO affordance on `enabledMethods`, not on
1219
- * this flag, so the two never drift.
1220
- */
1221
- sso: boolean;
1222
- /**
1223
- * JWT issuer (server contract CONTRACTS §8). Non-null only when the project's
1224
- * issuer toggle is on: exactly what a third-party verifier needs (Convex
1225
- * `auth.config.ts` = `{ type: "customJwt", issuer, jwks: jwksUrl,
1226
- * applicationID: aud, algorithm: "ES256" }`). `getToken` mints from
1227
- * `<issuer>/token`.
1228
- */
1229
- jwtIssuer: {
1230
- issuer: string;
1231
- jwksUrl: string;
1232
- aud: string;
1233
- } | null;
1234
- /** Public Cloudflare Turnstile site key for the phone OTP challenge. */
1235
- turnstileSiteKey: string | null;
1236
- /** Public Cloudflare Turnstile site key for protected sign-up/sign-in actions. */
1237
- authTurnstileSiteKey: string | null;
1238
- locale: string;
1239
- badge: boolean;
1240
- configVersion: number;
1241
- };
1242
- /**
1243
- * Fetch a project's public config. Publishable-key gated server-side; sent
1244
- * without cookies (the payload is public, so no session is needed). Throws on a
1245
- * non-2xx response so the caller can distinguish "config unavailable" from a
1246
- * project that simply has a method disabled.
1247
- */
1248
- declare function getPublicConfig(config: ResolvedAuthConfig): Promise<PublicConfig>;
11
+ declare function solvePhoneOtpChallenge(challenge: Extract<PhoneOtpChallengeData, {
12
+ kind: 'akedly_shield_v1_2';
13
+ }>): Promise<AkedlyShieldStartProof>;
1249
14
 
1250
15
  /** Create a cryptographically random RFC 4122 v4 key for retry-safe write actions. */
1251
16
  declare function createIdempotencyKey(): string;
@@ -1269,18 +34,4 @@ declare class AuthOwlHttpError extends Error {
1269
34
  constructor(label: string, response: Response, requestId?: string);
1270
35
  }
1271
36
 
1272
- /**
1273
- * Locale primitives shared across packages (plan 04, B.3). Deliberately tiny:
1274
- * the message CATALOGS live in @authowl/react (they are component strings -
1275
- * headless @authowl/core consumers shouldn't ship ~5kb of UI copy), while the
1276
- * locale identity/direction helpers here are needed by anything that reads
1277
- * public-config `locale` or renders direction-aware UI.
1278
- */
1279
- declare const LOCALES: readonly ["en", "ar"];
1280
- type Locale = (typeof LOCALES)[number];
1281
- /** Text direction for a locale - drives the `dir` attribute on the component root. */
1282
- declare function directionFor(locale: Locale): 'ltr' | 'rtl';
1283
- /** Narrow an arbitrary string (e.g. public-config `locale`) to a supported Locale. */
1284
- declare function isLocale(value: unknown): value is Locale;
1285
-
1286
- export { AUTH_CHALLENGE_HEADER, type AcceptOrganizationInvitationData, type AccountClient, type AccountSession, type AccountStatusData, type ActionFetchOptions, type AddPasskeyOptions, type AuthActionResult, type AuthClientError, type AuthErrorContext, type AuthOwlClient, AuthOwlError, type AuthOwlErrorCode, AuthOwlHttpError, type AuthPasskey, type AuthRequestContext, type AuthResponseContext, type AuthSession, type AuthUser, type ChangeEmailOptions, type ChangePasswordData, type ChangePasswordOptions, type ConsentAcceptResult, type ConsentStatus, type CreateOrganizationOptions, type DeleteAccountData, type DeleteAccountOptions, type DeleteOrganizationOptions, type DeletePasskeyData, type DeletePasskeyOptions, type DisableTwoFactorOptions, type EmailAuthData, type EmailOtpAuthData, type EmailOtpSignInOptions, type EmailOtpType, type EmailSignInOptions, type EmailSignUpData, type EmailSignUpOptions, type EnableTwoFactorOptions, type EnvironmentType, type GenerateBackupCodesOptions, type GetOrganizationInvitationOptions, type GetOrganizationOptions, type GetToken, type GetTokenOptions, HasParams, InvalidKeyError, type InviteOrganizationMemberOptions, type JsonObject, type JsonPrimitive, type JsonValue, LOCALES, type LeaveOrganizationOptions, type LinkSocialData, type LinkSocialOptions, type ListOrganizationInvitationsOptions, type ListOrganizationMembersOptions, type ListOrganizationRolesOptions, type ListOrganizationTeamsOptions, type Locale, type MagicLinkData, type MagicLinkSignInOptions, type Organization, type OrganizationClient, type OrganizationDetails, type OrganizationFilterOperator, type OrganizationInvitation, type OrganizationInvitationActionOptions, type OrganizationInvitationDetails, type OrganizationInvitationStatus, type OrganizationMember, type OrganizationMemberUser, type OrganizationMemberWithUser, type OrganizationMembersData, OrganizationMembership, type OrganizationRoleSummary, type OrganizationSelector, type OrganizationTeam, type OrganizationUserInvitation, type PasskeyAuthData, type PasskeySignInOptions, type PasswordResetData, type PhoneAuthUser, type PhoneOtpStartData, type PhoneOtpStartOptions, type PhoneOtpVerifyData, type PhoneOtpVerifyOptions, type PublicConfig, RateLimitedError, type RejectOrganizationInvitationData, type RemoveOrganizationMemberData, type RemoveOrganizationMemberOptions, type RequestPasswordResetOptions, type ResetPasswordOptions, ResolvedAuthConfig, type RevokeSessionOptions, type SendOtpData, type SendTwoFactorOtpData, type SendTwoFactorOtpOptions, type SendVerificationOtpOptions, type SessionState, type SessionStore, type SetActiveOrganizationOptions, type SetActiveTeamOptions, type SignOutData, type SocialAccount, type SocialAuthData, type SocialIdTokenOptions, type SocialSignInOptions, type TokenClient, type TwoFactorBackupCodesData, type TwoFactorEnableData, type TwoFactorRedirectData, type TwoFactorStatusData, type TwoFactorVerifyData, type UnlinkSocialOptions, type UpdateOrganizationMemberRoleOptions, type UpdateOrganizationOptions, type UpdatePasskeyData, type UpdatePasskeyOptions, type UpdateProfileOptions, type UpdateUnsafeMetadataOptions, type UserMetadata, type UsernameSignInOptions, type VerifyBackupCodeOptions, type VerifyEmailOtpData, type VerifyEmailOtpOptions, type VerifyTotpOptions, type VerifyTwoFactorOtpOptions, type WaitlistJoinData, type WaitlistJoinOptions, acceptConsent, createAuthOwlClient, createIdempotencyKey, createTokenClient, directionFor, getConsentStatus, getPublicConfig, isLocale };
37
+ export { AkedlyShieldStartProof, AuthOwlError, AuthOwlHttpError, InvalidKeyError, PhoneOtpChallengeData, RateLimitedError, createIdempotencyKey, solvePhoneOtpChallenge };