@nulvless/nulvless-js 0.1.5 → 0.1.7

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.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  type SdkErrorCode = 'no_session' | 'request_timeout' | 'network_error' | 'invalid_path' | 'unknown_error';
2
2
  type GatewayErrorCode = 'rate_limit_exceeded' | 'service_not_enabled' | 'service_unavailable' | 'project_not_ready' | 'project_paused' | 'project_unavailable' | 'bad_gateway' | 'upstream_timeout' | 'idle_timeout' | 'deadline_exceeded' | 'internal_error';
3
- type AuthErrorCode = 'unauthorized' | 'not_allowed' | 'unavailable' | 'invalid_credentials' | 'mfa_required' | 'refresh_token_not_found' | 'refresh_token_already_used' | 'refresh_token_not_issued_here' | 'registration_closed' | 'user_not_confirmed' | 'user_already_confirmed' | 'user_banned' | 'user_already_banned' | 'user_not_banned' | 'user_missing_email' | 'user_missing_phone' | 'email_already_exists' | 'phone_already_exists' | 'username_already_exists' | 'password_weak' | 'password_leaked' | 'captcha_required' | 'captcha_verification_failed' | 'protected_action_denied' | 'action_verification_failed' | 'forbidden_resource_access' | 'forbidden_access_waiting_accept' | 'forbidden_special_role_required' | 'cannot_leave_owner_access' | 'permission_already_granted' | 'bad_oauth_state' | 'bad_oauth_callback' | 'redirect_uri_mismatch' | 'provider_unavailable' | 'provider_unsupported_method' | 'oauth_email_missing' | 'oauth_email_not_verified' | 'oauth_account_link_required' | 'rate_limit_exceeded';
3
+ type AuthErrorCode = 'unauthorized' | 'not_allowed' | 'unavailable' | 'invalid_credentials' | 'mfa_required' | 'mfa_factors_limit_reached' | 'mfa_phone_already_enrolled' | 'mfa_phone_not_supported' | 'refresh_token_not_found' | 'refresh_token_already_used' | 'refresh_token_not_issued_here' | 'registration_closed' | 'user_not_confirmed' | 'user_already_confirmed' | 'user_banned' | 'user_already_banned' | 'user_not_banned' | 'user_missing_email' | 'user_missing_phone' | 'email_already_exists' | 'phone_already_exists' | 'username_already_exists' | 'password_weak' | 'password_leaked' | 'captcha_required' | 'captcha_verification_failed' | 'protected_action_denied' | 'login_required' | 'action_verification_failed' | 'forbidden_resource_access' | 'forbidden_access_waiting_accept' | 'forbidden_special_role_required' | 'cannot_leave_owner_access' | 'permission_already_granted' | 'bad_oauth_state' | 'bad_oauth_callback' | 'redirect_uri_mismatch' | 'provider_unavailable' | 'provider_unsupported_method' | 'oauth_email_missing' | 'oauth_email_not_verified' | 'oauth_account_link_required' | 'rate_limit_exceeded';
4
4
  type CommsErrorCode = 'unauthorized_platform' | 'rate_limit_exceeded';
5
5
  type EdgeFunctionErrorCode = 'function_not_found' | 'function_unavailable' | 'boot_failed' | 'execution_timeout' | 'cpu_time_limit_exceeded' | 'memory_limit_exceeded' | 'resource_unavailable' | 'internal_server_error';
6
6
  type ErrorCode = SdkErrorCode | GatewayErrorCode | AuthErrorCode | CommsErrorCode | (string & {});
@@ -343,6 +343,20 @@ interface ChangeChallengeParams {
343
343
  token: string;
344
344
  /** MFA method to switch to. */
345
345
  type: MFAMethod;
346
+ /**
347
+ * For `sms_otp`, which SMS factor receives the code — an `id` from
348
+ * `challenge.mfas`. Defaults to the oldest SMS factor.
349
+ */
350
+ factor_id?: string;
351
+ }
352
+ interface CreateChallengeParams {
353
+ /** MFA method to verify with. */
354
+ type: MFAMethod;
355
+ /**
356
+ * For `sms_otp`, which SMS factor receives the code — an `id` from
357
+ * `factors.list()`. Defaults to the oldest SMS factor.
358
+ */
359
+ factor_id?: string;
346
360
  }
347
361
  type AuthFactorStatus = 'configured' | 'not_configured';
348
362
  interface AuthMethod {
@@ -379,6 +393,11 @@ interface EnableFactorParams {
379
393
  interface EnrollFactorParams extends Nonce {
380
394
  type: MFAMethod;
381
395
  name?: string;
396
+ /**
397
+ * For `sms_otp`, the phone that receives the codes. Defaults to the user's
398
+ * phone. It may match the user's phone but not another SMS factor.
399
+ */
400
+ phone?: Phone;
382
401
  }
383
402
  interface UnenrollFactorParams extends Nonce {
384
403
  id: string;
@@ -471,11 +490,6 @@ interface ChangePasswordParams extends Nonce {
471
490
  password: string;
472
491
  new_password: string;
473
492
  }
474
- interface PlatformInfo {
475
- id: string;
476
- name: string;
477
- slug: string;
478
- }
479
493
  type PaginationSort = 'asc' | 'desc';
480
494
  interface Paginated<T> {
481
495
  items: T[];
@@ -704,7 +718,10 @@ interface OAuthAuthorizeParams {
704
718
  state?: string;
705
719
  resource?: string;
706
720
  nonce?: string;
721
+ prompt?: OAuthPrompt | `${OAuthPrompt} ${OAuthPrompt}`;
722
+ max_age?: number;
707
723
  }
724
+ type OAuthPrompt = 'none' | 'login' | 'consent' | 'select_account';
708
725
  interface ExchangeOAuthCodeParams {
709
726
  code: string;
710
727
  code_verifier: string;
@@ -736,6 +753,8 @@ interface OAuthAuthorization {
736
753
  uri?: string;
737
754
  };
738
755
  scope: string[];
756
+ prompt: OAuthPrompt[];
757
+ max_age: number | null;
739
758
  auto_approved: boolean;
740
759
  redirect?: {
741
760
  uri: string;
@@ -906,6 +925,10 @@ declare class FactorsClient extends AuthSubClient {
906
925
  * the factor on the user's device.
907
926
  *
908
927
  * For TOTP: use `secret` for manual entry or `url` to generate a QR code.
928
+ * For SMS: pass `phone` to send the codes to a number other than the user's.
929
+ *
930
+ * A user holds up to 10 authenticator apps and SMS factors combined, and one
931
+ * email factor and one set of recovery codes.
909
932
  *
910
933
  * After the user configures their device, call `enable` with the `token` and
911
934
  * the first OTP code to activate the factor.
@@ -1142,10 +1165,14 @@ declare class ChallengesClient extends AuthSubClient {
1142
1165
  * Requires an authenticated session. Prompt the user for the code, then call
1143
1166
  * `verify({ token, code })`.
1144
1167
  *
1168
+ * A `totp` challenge accepts a code from any of the user's authenticator
1169
+ * apps. For `sms_otp`, pass `factor_id` to pick which phone receives it.
1170
+ *
1145
1171
  * @example
1146
- * const { data } = await nulvless.auth.challenges.create('totp')
1172
+ * const { data } = await nulvless.auth.challenges.create({ type: 'totp' })
1173
+ * const { data: sms } = await nulvless.auth.challenges.create({ type: 'sms_otp', factor_id })
1147
1174
  */
1148
- create(targetType: MFAMethod, options?: RequestOptions): Promise<NulvlessResult<{
1175
+ create(params: CreateChallengeParams, options?: RequestOptions): Promise<NulvlessResult<{
1149
1176
  challenge: Challenge;
1150
1177
  }>>;
1151
1178
  /**
@@ -1263,8 +1290,7 @@ declare class OAuthGrantsClient extends AuthSubClient {
1263
1290
  * The project's OAuth 2.1 / OpenID Connect provider surface — the project
1264
1291
  * acting as an identity provider for third-party applications.
1265
1292
  *
1266
- * Available with both public (`pk_`) and private (`sk_`) keys
1267
- * (`@SetPlatformGuardRoles([PUBLIC, PRIVATE])`).
1293
+ * Available with both public (`pk_`) and private (`sk_`) keys.
1268
1294
  *
1269
1295
  * Method scopes:
1270
1296
  * - `token`, `register` — platform key only (no bearer token).
@@ -1529,16 +1555,11 @@ declare class AdminClient {
1529
1555
  readonly grants: AdminGrantsClient;
1530
1556
  readonly oauthClients: AdminOAuthClientsClient;
1531
1557
  constructor(http: HttpClient);
1532
- /**
1533
- * Returns basic platform information (id, name, slug).
1534
- */
1535
- getPlatform(options?: RequestOptions): Promise<NulvlessResult<PlatformInfo>>;
1536
1558
  }
1537
1559
 
1538
1560
  interface AccountEntry {
1539
1561
  userId: string;
1540
1562
  access_token: string;
1541
- /** Seconds remaining until the token expires. May be negative if already expired. */
1542
1563
  expires_in: number;
1543
1564
  refresh_token?: string;
1544
1565
  user?: User;
@@ -1587,7 +1608,6 @@ declare class AuthEventEmitter {
1587
1608
 
1588
1609
  /**
1589
1610
  * Auth methods accessible with both public (`pk_`) and private (`sk_`) keys.
1590
- * Corresponds to endpoints decorated with `@SetPlatformGuardRoles([PUBLIC, PRIVATE])`.
1591
1611
  */
1592
1612
  declare class AuthClient {
1593
1613
  protected readonly http: HttpClient;
@@ -2331,4 +2351,4 @@ declare function createClient(url: string, publicKey: string, options?: ClientOp
2331
2351
  */
2332
2352
  declare function createServerClient(url: string, privateKey: string, options?: ServerClientOptions): NulvlessServerClient;
2333
2353
 
2334
- export { AUTH_CACHE_HEADERS, type AccountEntry, type AddEmailIdentityParams, type AddPhoneIdentityParams, AdminClient, type AdminCreateUserParams, type AdminUpdateUserParams, type AssuranceLevel, AuthBrowserClient, AuthClient, type AuthErrorCode, AuthEventEmitter, type AuthEvents, type AuthFactorStatus, type AuthMethod, type AuthMethods, type AuthOptions, AuthServerClient, type Authenticated, type BlockGrantParams, type Challenge, type ChallengeSubject, type ChangeChallengeParams, type ChangePasswordParams, type ClientOptions, CommsClient, type CommsErrorCode, type ConfirmationType, type CreateRoleParams, type CreateTemplateParams, type EdgeFunctionErrorCode, EmailClient, type EnableFactorParams, type EnrollFactorParams, type ErrorCode, type ExchangeOAuthCodeParams, type FactorEnrollment, FactorsClient, type GatewayErrorCode, type Grant, type GrantMembers, type GrantStatus, GrantsClient, HttpClient, type Identity, type IdentityType, type Invite, type InviteParams, type Language, type LeaveGrantParams, type LookupMatch, type LookupParams, type LookupResult, type MFAMethod, type Nonce, type NotificationChannel, NulvlessClient, type NulvlessError, NulvlessException, type NulvlessResult, NulvlessServerClient, type NulvlessStorage, type OAuthApp, type OAuthAppGrantType, type OAuthAppTokenEndpointAuthMethod, type OAuthAppType, type OAuthAuthorization, type OAuthAuthorizeParams, OAuthClient, type OAuthConsentAction, type OAuthConsentResult, type OAuthDiscovery, OAuthGrantsClient, type OAuthJWKS, type OAuthProvider, type OAuthTokenResponse, type OAuthUserGrant, type OAuthUserInfo, type PaginateGrantsParams, type PaginateUsersParams, type Paginated, type PaginatedTemplates, type PaginationSort, type Phone, type PlatformInfo, type RecoverParams, type RefreshOAuthTokenParams, type RefreshTokenParams, type RegisterOAuthAppParams, type RemoveIdentityParams, type RequestOptions, type ResetPasswordParams, type RevokeGrantParams, type RevokeSessionParams, type Role, type SdkErrorCode, SecurityClient, type SendEmailParams, type SendOTPToUpdateEmailParams, type SendOTPToUpdatePhoneParams, type SendSMSParams, type ServerClientOptions, type Session, type SessionFingerPrint, SessionManager, SessionsClient, type SetGrantParams, type SignInMethod, type SignInParams, type SignInWithOTPParams, type SignOutScope, type SignUpParams, SmsClient, Storage, type StoredSession, type SudoMethod, type Template, type TemplateFilters, type TemplateLanguage, TemplatesClient, type TokenType, type UnenrollFactorParams, type UpdateGrantParams, type UpdateIdentityParams, type UpdateOAuthAppParams, type UpdateRoleParams, type UpdateTemplateParams, type User, type UserGender, type UserProfile, UsersClient, type Verified, type VerifyChallengeParams, type VerifyParams, type VerifyReason, applyAuthCacheHeaders, createClient, createServerClient, forwardUserHeaders };
2354
+ export { AUTH_CACHE_HEADERS, type AccountEntry, type AddEmailIdentityParams, type AddPhoneIdentityParams, AdminClient, type AdminCreateUserParams, type AdminUpdateUserParams, type AssuranceLevel, AuthBrowserClient, AuthClient, type AuthErrorCode, AuthEventEmitter, type AuthEvents, type AuthFactorStatus, type AuthMethod, type AuthMethods, type AuthOptions, AuthServerClient, type Authenticated, type BlockGrantParams, type Challenge, type ChallengeSubject, type ChangeChallengeParams, type ChangePasswordParams, type ClientOptions, CommsClient, type CommsErrorCode, type ConfirmationType, type CreateChallengeParams, type CreateRoleParams, type CreateTemplateParams, type EdgeFunctionErrorCode, EmailClient, type EnableFactorParams, type EnrollFactorParams, type ErrorCode, type ExchangeOAuthCodeParams, type FactorEnrollment, FactorsClient, type GatewayErrorCode, type Grant, type GrantMembers, type GrantStatus, GrantsClient, HttpClient, type Identity, type IdentityType, type Invite, type InviteParams, type Language, type LeaveGrantParams, type LookupMatch, type LookupParams, type LookupResult, type MFAMethod, type Nonce, type NotificationChannel, NulvlessClient, type NulvlessError, NulvlessException, type NulvlessResult, NulvlessServerClient, type NulvlessStorage, type OAuthApp, type OAuthAppGrantType, type OAuthAppTokenEndpointAuthMethod, type OAuthAppType, type OAuthAuthorization, type OAuthAuthorizeParams, OAuthClient, type OAuthConsentAction, type OAuthConsentResult, type OAuthDiscovery, OAuthGrantsClient, type OAuthJWKS, type OAuthPrompt, type OAuthProvider, type OAuthTokenResponse, type OAuthUserGrant, type OAuthUserInfo, type PaginateGrantsParams, type PaginateUsersParams, type Paginated, type PaginatedTemplates, type PaginationSort, type Phone, type RecoverParams, type RefreshOAuthTokenParams, type RefreshTokenParams, type RegisterOAuthAppParams, type RemoveIdentityParams, type RequestOptions, type ResetPasswordParams, type RevokeGrantParams, type RevokeSessionParams, type Role, type SdkErrorCode, SecurityClient, type SendEmailParams, type SendOTPToUpdateEmailParams, type SendOTPToUpdatePhoneParams, type SendSMSParams, type ServerClientOptions, type Session, type SessionFingerPrint, SessionManager, SessionsClient, type SetGrantParams, type SignInMethod, type SignInParams, type SignInWithOTPParams, type SignOutScope, type SignUpParams, SmsClient, Storage, type StoredSession, type SudoMethod, type Template, type TemplateFilters, type TemplateLanguage, TemplatesClient, type TokenType, type UnenrollFactorParams, type UpdateGrantParams, type UpdateIdentityParams, type UpdateOAuthAppParams, type UpdateRoleParams, type UpdateTemplateParams, type User, type UserGender, type UserProfile, UsersClient, type Verified, type VerifyChallengeParams, type VerifyParams, type VerifyReason, applyAuthCacheHeaders, createClient, createServerClient, forwardUserHeaders };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  type SdkErrorCode = 'no_session' | 'request_timeout' | 'network_error' | 'invalid_path' | 'unknown_error';
2
2
  type GatewayErrorCode = 'rate_limit_exceeded' | 'service_not_enabled' | 'service_unavailable' | 'project_not_ready' | 'project_paused' | 'project_unavailable' | 'bad_gateway' | 'upstream_timeout' | 'idle_timeout' | 'deadline_exceeded' | 'internal_error';
3
- type AuthErrorCode = 'unauthorized' | 'not_allowed' | 'unavailable' | 'invalid_credentials' | 'mfa_required' | 'refresh_token_not_found' | 'refresh_token_already_used' | 'refresh_token_not_issued_here' | 'registration_closed' | 'user_not_confirmed' | 'user_already_confirmed' | 'user_banned' | 'user_already_banned' | 'user_not_banned' | 'user_missing_email' | 'user_missing_phone' | 'email_already_exists' | 'phone_already_exists' | 'username_already_exists' | 'password_weak' | 'password_leaked' | 'captcha_required' | 'captcha_verification_failed' | 'protected_action_denied' | 'action_verification_failed' | 'forbidden_resource_access' | 'forbidden_access_waiting_accept' | 'forbidden_special_role_required' | 'cannot_leave_owner_access' | 'permission_already_granted' | 'bad_oauth_state' | 'bad_oauth_callback' | 'redirect_uri_mismatch' | 'provider_unavailable' | 'provider_unsupported_method' | 'oauth_email_missing' | 'oauth_email_not_verified' | 'oauth_account_link_required' | 'rate_limit_exceeded';
3
+ type AuthErrorCode = 'unauthorized' | 'not_allowed' | 'unavailable' | 'invalid_credentials' | 'mfa_required' | 'mfa_factors_limit_reached' | 'mfa_phone_already_enrolled' | 'mfa_phone_not_supported' | 'refresh_token_not_found' | 'refresh_token_already_used' | 'refresh_token_not_issued_here' | 'registration_closed' | 'user_not_confirmed' | 'user_already_confirmed' | 'user_banned' | 'user_already_banned' | 'user_not_banned' | 'user_missing_email' | 'user_missing_phone' | 'email_already_exists' | 'phone_already_exists' | 'username_already_exists' | 'password_weak' | 'password_leaked' | 'captcha_required' | 'captcha_verification_failed' | 'protected_action_denied' | 'login_required' | 'action_verification_failed' | 'forbidden_resource_access' | 'forbidden_access_waiting_accept' | 'forbidden_special_role_required' | 'cannot_leave_owner_access' | 'permission_already_granted' | 'bad_oauth_state' | 'bad_oauth_callback' | 'redirect_uri_mismatch' | 'provider_unavailable' | 'provider_unsupported_method' | 'oauth_email_missing' | 'oauth_email_not_verified' | 'oauth_account_link_required' | 'rate_limit_exceeded';
4
4
  type CommsErrorCode = 'unauthorized_platform' | 'rate_limit_exceeded';
5
5
  type EdgeFunctionErrorCode = 'function_not_found' | 'function_unavailable' | 'boot_failed' | 'execution_timeout' | 'cpu_time_limit_exceeded' | 'memory_limit_exceeded' | 'resource_unavailable' | 'internal_server_error';
6
6
  type ErrorCode = SdkErrorCode | GatewayErrorCode | AuthErrorCode | CommsErrorCode | (string & {});
@@ -343,6 +343,20 @@ interface ChangeChallengeParams {
343
343
  token: string;
344
344
  /** MFA method to switch to. */
345
345
  type: MFAMethod;
346
+ /**
347
+ * For `sms_otp`, which SMS factor receives the code — an `id` from
348
+ * `challenge.mfas`. Defaults to the oldest SMS factor.
349
+ */
350
+ factor_id?: string;
351
+ }
352
+ interface CreateChallengeParams {
353
+ /** MFA method to verify with. */
354
+ type: MFAMethod;
355
+ /**
356
+ * For `sms_otp`, which SMS factor receives the code — an `id` from
357
+ * `factors.list()`. Defaults to the oldest SMS factor.
358
+ */
359
+ factor_id?: string;
346
360
  }
347
361
  type AuthFactorStatus = 'configured' | 'not_configured';
348
362
  interface AuthMethod {
@@ -379,6 +393,11 @@ interface EnableFactorParams {
379
393
  interface EnrollFactorParams extends Nonce {
380
394
  type: MFAMethod;
381
395
  name?: string;
396
+ /**
397
+ * For `sms_otp`, the phone that receives the codes. Defaults to the user's
398
+ * phone. It may match the user's phone but not another SMS factor.
399
+ */
400
+ phone?: Phone;
382
401
  }
383
402
  interface UnenrollFactorParams extends Nonce {
384
403
  id: string;
@@ -471,11 +490,6 @@ interface ChangePasswordParams extends Nonce {
471
490
  password: string;
472
491
  new_password: string;
473
492
  }
474
- interface PlatformInfo {
475
- id: string;
476
- name: string;
477
- slug: string;
478
- }
479
493
  type PaginationSort = 'asc' | 'desc';
480
494
  interface Paginated<T> {
481
495
  items: T[];
@@ -704,7 +718,10 @@ interface OAuthAuthorizeParams {
704
718
  state?: string;
705
719
  resource?: string;
706
720
  nonce?: string;
721
+ prompt?: OAuthPrompt | `${OAuthPrompt} ${OAuthPrompt}`;
722
+ max_age?: number;
707
723
  }
724
+ type OAuthPrompt = 'none' | 'login' | 'consent' | 'select_account';
708
725
  interface ExchangeOAuthCodeParams {
709
726
  code: string;
710
727
  code_verifier: string;
@@ -736,6 +753,8 @@ interface OAuthAuthorization {
736
753
  uri?: string;
737
754
  };
738
755
  scope: string[];
756
+ prompt: OAuthPrompt[];
757
+ max_age: number | null;
739
758
  auto_approved: boolean;
740
759
  redirect?: {
741
760
  uri: string;
@@ -906,6 +925,10 @@ declare class FactorsClient extends AuthSubClient {
906
925
  * the factor on the user's device.
907
926
  *
908
927
  * For TOTP: use `secret` for manual entry or `url` to generate a QR code.
928
+ * For SMS: pass `phone` to send the codes to a number other than the user's.
929
+ *
930
+ * A user holds up to 10 authenticator apps and SMS factors combined, and one
931
+ * email factor and one set of recovery codes.
909
932
  *
910
933
  * After the user configures their device, call `enable` with the `token` and
911
934
  * the first OTP code to activate the factor.
@@ -1142,10 +1165,14 @@ declare class ChallengesClient extends AuthSubClient {
1142
1165
  * Requires an authenticated session. Prompt the user for the code, then call
1143
1166
  * `verify({ token, code })`.
1144
1167
  *
1168
+ * A `totp` challenge accepts a code from any of the user's authenticator
1169
+ * apps. For `sms_otp`, pass `factor_id` to pick which phone receives it.
1170
+ *
1145
1171
  * @example
1146
- * const { data } = await nulvless.auth.challenges.create('totp')
1172
+ * const { data } = await nulvless.auth.challenges.create({ type: 'totp' })
1173
+ * const { data: sms } = await nulvless.auth.challenges.create({ type: 'sms_otp', factor_id })
1147
1174
  */
1148
- create(targetType: MFAMethod, options?: RequestOptions): Promise<NulvlessResult<{
1175
+ create(params: CreateChallengeParams, options?: RequestOptions): Promise<NulvlessResult<{
1149
1176
  challenge: Challenge;
1150
1177
  }>>;
1151
1178
  /**
@@ -1263,8 +1290,7 @@ declare class OAuthGrantsClient extends AuthSubClient {
1263
1290
  * The project's OAuth 2.1 / OpenID Connect provider surface — the project
1264
1291
  * acting as an identity provider for third-party applications.
1265
1292
  *
1266
- * Available with both public (`pk_`) and private (`sk_`) keys
1267
- * (`@SetPlatformGuardRoles([PUBLIC, PRIVATE])`).
1293
+ * Available with both public (`pk_`) and private (`sk_`) keys.
1268
1294
  *
1269
1295
  * Method scopes:
1270
1296
  * - `token`, `register` — platform key only (no bearer token).
@@ -1529,16 +1555,11 @@ declare class AdminClient {
1529
1555
  readonly grants: AdminGrantsClient;
1530
1556
  readonly oauthClients: AdminOAuthClientsClient;
1531
1557
  constructor(http: HttpClient);
1532
- /**
1533
- * Returns basic platform information (id, name, slug).
1534
- */
1535
- getPlatform(options?: RequestOptions): Promise<NulvlessResult<PlatformInfo>>;
1536
1558
  }
1537
1559
 
1538
1560
  interface AccountEntry {
1539
1561
  userId: string;
1540
1562
  access_token: string;
1541
- /** Seconds remaining until the token expires. May be negative if already expired. */
1542
1563
  expires_in: number;
1543
1564
  refresh_token?: string;
1544
1565
  user?: User;
@@ -1587,7 +1608,6 @@ declare class AuthEventEmitter {
1587
1608
 
1588
1609
  /**
1589
1610
  * Auth methods accessible with both public (`pk_`) and private (`sk_`) keys.
1590
- * Corresponds to endpoints decorated with `@SetPlatformGuardRoles([PUBLIC, PRIVATE])`.
1591
1611
  */
1592
1612
  declare class AuthClient {
1593
1613
  protected readonly http: HttpClient;
@@ -2331,4 +2351,4 @@ declare function createClient(url: string, publicKey: string, options?: ClientOp
2331
2351
  */
2332
2352
  declare function createServerClient(url: string, privateKey: string, options?: ServerClientOptions): NulvlessServerClient;
2333
2353
 
2334
- export { AUTH_CACHE_HEADERS, type AccountEntry, type AddEmailIdentityParams, type AddPhoneIdentityParams, AdminClient, type AdminCreateUserParams, type AdminUpdateUserParams, type AssuranceLevel, AuthBrowserClient, AuthClient, type AuthErrorCode, AuthEventEmitter, type AuthEvents, type AuthFactorStatus, type AuthMethod, type AuthMethods, type AuthOptions, AuthServerClient, type Authenticated, type BlockGrantParams, type Challenge, type ChallengeSubject, type ChangeChallengeParams, type ChangePasswordParams, type ClientOptions, CommsClient, type CommsErrorCode, type ConfirmationType, type CreateRoleParams, type CreateTemplateParams, type EdgeFunctionErrorCode, EmailClient, type EnableFactorParams, type EnrollFactorParams, type ErrorCode, type ExchangeOAuthCodeParams, type FactorEnrollment, FactorsClient, type GatewayErrorCode, type Grant, type GrantMembers, type GrantStatus, GrantsClient, HttpClient, type Identity, type IdentityType, type Invite, type InviteParams, type Language, type LeaveGrantParams, type LookupMatch, type LookupParams, type LookupResult, type MFAMethod, type Nonce, type NotificationChannel, NulvlessClient, type NulvlessError, NulvlessException, type NulvlessResult, NulvlessServerClient, type NulvlessStorage, type OAuthApp, type OAuthAppGrantType, type OAuthAppTokenEndpointAuthMethod, type OAuthAppType, type OAuthAuthorization, type OAuthAuthorizeParams, OAuthClient, type OAuthConsentAction, type OAuthConsentResult, type OAuthDiscovery, OAuthGrantsClient, type OAuthJWKS, type OAuthProvider, type OAuthTokenResponse, type OAuthUserGrant, type OAuthUserInfo, type PaginateGrantsParams, type PaginateUsersParams, type Paginated, type PaginatedTemplates, type PaginationSort, type Phone, type PlatformInfo, type RecoverParams, type RefreshOAuthTokenParams, type RefreshTokenParams, type RegisterOAuthAppParams, type RemoveIdentityParams, type RequestOptions, type ResetPasswordParams, type RevokeGrantParams, type RevokeSessionParams, type Role, type SdkErrorCode, SecurityClient, type SendEmailParams, type SendOTPToUpdateEmailParams, type SendOTPToUpdatePhoneParams, type SendSMSParams, type ServerClientOptions, type Session, type SessionFingerPrint, SessionManager, SessionsClient, type SetGrantParams, type SignInMethod, type SignInParams, type SignInWithOTPParams, type SignOutScope, type SignUpParams, SmsClient, Storage, type StoredSession, type SudoMethod, type Template, type TemplateFilters, type TemplateLanguage, TemplatesClient, type TokenType, type UnenrollFactorParams, type UpdateGrantParams, type UpdateIdentityParams, type UpdateOAuthAppParams, type UpdateRoleParams, type UpdateTemplateParams, type User, type UserGender, type UserProfile, UsersClient, type Verified, type VerifyChallengeParams, type VerifyParams, type VerifyReason, applyAuthCacheHeaders, createClient, createServerClient, forwardUserHeaders };
2354
+ export { AUTH_CACHE_HEADERS, type AccountEntry, type AddEmailIdentityParams, type AddPhoneIdentityParams, AdminClient, type AdminCreateUserParams, type AdminUpdateUserParams, type AssuranceLevel, AuthBrowserClient, AuthClient, type AuthErrorCode, AuthEventEmitter, type AuthEvents, type AuthFactorStatus, type AuthMethod, type AuthMethods, type AuthOptions, AuthServerClient, type Authenticated, type BlockGrantParams, type Challenge, type ChallengeSubject, type ChangeChallengeParams, type ChangePasswordParams, type ClientOptions, CommsClient, type CommsErrorCode, type ConfirmationType, type CreateChallengeParams, type CreateRoleParams, type CreateTemplateParams, type EdgeFunctionErrorCode, EmailClient, type EnableFactorParams, type EnrollFactorParams, type ErrorCode, type ExchangeOAuthCodeParams, type FactorEnrollment, FactorsClient, type GatewayErrorCode, type Grant, type GrantMembers, type GrantStatus, GrantsClient, HttpClient, type Identity, type IdentityType, type Invite, type InviteParams, type Language, type LeaveGrantParams, type LookupMatch, type LookupParams, type LookupResult, type MFAMethod, type Nonce, type NotificationChannel, NulvlessClient, type NulvlessError, NulvlessException, type NulvlessResult, NulvlessServerClient, type NulvlessStorage, type OAuthApp, type OAuthAppGrantType, type OAuthAppTokenEndpointAuthMethod, type OAuthAppType, type OAuthAuthorization, type OAuthAuthorizeParams, OAuthClient, type OAuthConsentAction, type OAuthConsentResult, type OAuthDiscovery, OAuthGrantsClient, type OAuthJWKS, type OAuthPrompt, type OAuthProvider, type OAuthTokenResponse, type OAuthUserGrant, type OAuthUserInfo, type PaginateGrantsParams, type PaginateUsersParams, type Paginated, type PaginatedTemplates, type PaginationSort, type Phone, type RecoverParams, type RefreshOAuthTokenParams, type RefreshTokenParams, type RegisterOAuthAppParams, type RemoveIdentityParams, type RequestOptions, type ResetPasswordParams, type RevokeGrantParams, type RevokeSessionParams, type Role, type SdkErrorCode, SecurityClient, type SendEmailParams, type SendOTPToUpdateEmailParams, type SendOTPToUpdatePhoneParams, type SendSMSParams, type ServerClientOptions, type Session, type SessionFingerPrint, SessionManager, SessionsClient, type SetGrantParams, type SignInMethod, type SignInParams, type SignInWithOTPParams, type SignOutScope, type SignUpParams, SmsClient, Storage, type StoredSession, type SudoMethod, type Template, type TemplateFilters, type TemplateLanguage, TemplatesClient, type TokenType, type UnenrollFactorParams, type UpdateGrantParams, type UpdateIdentityParams, type UpdateOAuthAppParams, type UpdateRoleParams, type UpdateTemplateParams, type User, type UserGender, type UserProfile, UsersClient, type Verified, type VerifyChallengeParams, type VerifyParams, type VerifyReason, applyAuthCacheHeaders, createClient, createServerClient, forwardUserHeaders };
package/dist/index.mjs CHANGED
@@ -315,6 +315,10 @@ var FactorsClient = class extends AuthSubClient {
315
315
  * the factor on the user's device.
316
316
  *
317
317
  * For TOTP: use `secret` for manual entry or `url` to generate a QR code.
318
+ * For SMS: pass `phone` to send the codes to a number other than the user's.
319
+ *
320
+ * A user holds up to 10 authenticator apps and SMS factors combined, and one
321
+ * email factor and one set of recovery codes.
318
322
  *
319
323
  * After the user configures their device, call `enable` with the `token` and
320
324
  * the first OTP code to activate the factor.
@@ -330,8 +334,9 @@ var FactorsClient = class extends AuthSubClient {
330
334
  async enroll(params, options) {
331
335
  const auth = await this.bearer(options);
332
336
  if (!auth.ok) return { data: null, error: auth.error };
333
- const { nonce, type, name } = params;
334
- return this.http.post(route`/factors/${type}`, name ? { name } : {}, {
337
+ const { nonce, type, name, phone } = params;
338
+ const body = { ...name ? { name } : {}, ...phone ? { phone } : {} };
339
+ return this.http.post(route`/factors/${type}`, body, {
335
340
  ...options,
336
341
  nonce,
337
342
  headers: { ...options?.headers, ...auth.headers }
@@ -377,7 +382,6 @@ var FactorsClient = class extends AuthSubClient {
377
382
 
378
383
  // src/auth/users/index.ts
379
384
  var UsersClient = class extends AuthSubClient {
380
- // ─── Profile ────────────────────────────────────────────────────────────────
381
385
  /**
382
386
  * Returns the authenticated user's full profile.
383
387
  */
@@ -402,7 +406,6 @@ var UsersClient = class extends AuthSubClient {
402
406
  headers: { ...options?.headers, ...auth.headers }
403
407
  });
404
408
  }
405
- // ─── Identities ─────────────────────────────────────────────────────────────
406
409
  /**
407
410
  * Lists all identities (email, phone, OAuth) linked to the authenticated user.
408
411
  *
@@ -493,7 +496,6 @@ var UsersClient = class extends AuthSubClient {
493
496
  headers: { ...options?.headers, ...auth.headers }
494
497
  });
495
498
  }
496
- // ─── Credential updates ──────────────────────────────────────────────────────
497
499
  /**
498
500
  * Sends an OTP to the new email address to initiate an email change.
499
501
  *
@@ -693,14 +695,19 @@ var ChallengesClient = class extends AuthSubClient {
693
695
  * Requires an authenticated session. Prompt the user for the code, then call
694
696
  * `verify({ token, code })`.
695
697
  *
698
+ * A `totp` challenge accepts a code from any of the user's authenticator
699
+ * apps. For `sms_otp`, pass `factor_id` to pick which phone receives it.
700
+ *
696
701
  * @example
697
- * const { data } = await nulvless.auth.challenges.create('totp')
702
+ * const { data } = await nulvless.auth.challenges.create({ type: 'totp' })
703
+ * const { data: sms } = await nulvless.auth.challenges.create({ type: 'sms_otp', factor_id })
698
704
  */
699
- async create(targetType, options) {
705
+ async create(params, options) {
700
706
  const auth = await this.bearer(options);
701
707
  if (!auth.ok) return { data: null, error: auth.error };
702
- return this.http.post(route`/challenges/${targetType}`, void 0, {
708
+ return this.http.post(route`/challenges/${params.type}`, void 0, {
703
709
  ...options,
710
+ ...params.factor_id ? { query: { factor_id: params.factor_id } } : {},
704
711
  headers: { ...options?.headers, ...auth.headers }
705
712
  });
706
713
  }
@@ -720,7 +727,7 @@ var ChallengesClient = class extends AuthSubClient {
720
727
  return this.http.patch(
721
728
  route`/challenges/${params.type}`,
722
729
  { token: params.token },
723
- options
730
+ params.factor_id ? { ...options, query: { factor_id: params.factor_id } } : options
724
731
  );
725
732
  }
726
733
  /**
@@ -920,7 +927,6 @@ var OAuthClient = class extends AuthSubClient {
920
927
  super(http, getToken);
921
928
  this.grants = new OAuthGrantsClient(http, getToken);
922
929
  }
923
- // ─── Authorization redirect (platform key) ──────────────────────────────────
924
930
  /**
925
931
  * Builds the OAuth authorization URL and, in the browser, redirects the user
926
932
  * agent to it. On the server the URL is returned for manual handling.
@@ -955,7 +961,9 @@ var OAuthClient = class extends AuthSubClient {
955
961
  scope: params.scope,
956
962
  state: params.state,
957
963
  resource: params.resource,
958
- nonce: params.nonce
964
+ nonce: params.nonce,
965
+ prompt: params.prompt,
966
+ max_age: params.max_age === void 0 ? void 0 : String(params.max_age)
959
967
  };
960
968
  for (const [key, value] of Object.entries(query)) {
961
969
  if (value !== void 0) url.searchParams.set(key, value);
@@ -965,7 +973,6 @@ var OAuthClient = class extends AuthSubClient {
965
973
  }
966
974
  return { data: { url: url.toString() }, error: null };
967
975
  }
968
- // ─── Token endpoint (public) ────────────────────────────────────────────────
969
976
  /**
970
977
  * Exchanges an authorization code for tokens
971
978
  * (`POST /oauth/token`, `grant_type=authorization_code`).
@@ -995,7 +1002,6 @@ var OAuthClient = class extends AuthSubClient {
995
1002
  { ...options, skipApiKey: true }
996
1003
  );
997
1004
  }
998
- // ─── Dynamic registration (platform key) ────────────────────────────────────
999
1005
  /**
1000
1006
  * Dynamically registers a new OAuth app (RFC 7591, `POST /oauth/register`).
1001
1007
  *
@@ -1005,7 +1011,6 @@ var OAuthClient = class extends AuthSubClient {
1005
1011
  register(params, options) {
1006
1012
  return this.http.post("/oauth/register", params, { ...options, skipApiKey: true });
1007
1013
  }
1008
- // ─── Consent flow (authenticated user) ──────────────────────────────────────
1009
1014
  /**
1010
1015
  * Loads a pending authorization for the consent screen
1011
1016
  * (`GET /oauth/authorizations/:id`).
@@ -1040,7 +1045,6 @@ var OAuthClient = class extends AuthSubClient {
1040
1045
  headers: { ...options?.headers, ...auth.headers }
1041
1046
  });
1042
1047
  }
1043
- // ─── UserInfo (authenticated user) ──────────────────────────────────────────
1044
1048
  /**
1045
1049
  * Returns OIDC UserInfo claims for the access token (`GET /oauth/userinfo`).
1046
1050
  *
@@ -1056,7 +1060,6 @@ var OAuthClient = class extends AuthSubClient {
1056
1060
  headers: { ...options?.headers, ...auth.headers }
1057
1061
  });
1058
1062
  }
1059
- // ─── Public OIDC metadata (no auth) ─────────────────────────────────────────
1060
1063
  /**
1061
1064
  * Returns the OpenID Connect discovery document
1062
1065
  * (`GET /.well-known/openid-configuration`). Public — no auth required.
@@ -1281,12 +1284,6 @@ var AdminClient = class {
1281
1284
  roles;
1282
1285
  grants;
1283
1286
  oauthClients;
1284
- /**
1285
- * Returns basic platform information (id, name, slug).
1286
- */
1287
- getPlatform(options) {
1288
- return this.http.get("/admin/platform", options);
1289
- }
1290
1287
  };
1291
1288
 
1292
1289
  // src/session/stored.ts
@@ -1461,14 +1458,12 @@ var AuthClient = class {
1461
1458
  async getAccessToken() {
1462
1459
  return this.session?.getValidToken() ?? null;
1463
1460
  }
1464
- // ─── Helpers ──────────────────────────────────────────────────────────────
1465
1461
  async persistSession(result) {
1466
1462
  if (!result.error && result.data.access_token && this.session) {
1467
1463
  await this.session.save(result.data);
1468
1464
  }
1469
1465
  return result;
1470
1466
  }
1471
- // ─── Sign-up / Sign-in ─────────────────────────────────────────────────────
1472
1467
  /**
1473
1468
  * Creates a new user account.
1474
1469
  *
@@ -1629,7 +1624,6 @@ var AuthClient = class {
1629
1624
  headers: { ...options?.headers, ...auth.headers }
1630
1625
  });
1631
1626
  }
1632
- // ─── Challenge ─────────────────────────────────────────────────────────────
1633
1627
  /**
1634
1628
  * Looks up whether an identifier exists and which sign-in method applies.
1635
1629
  *
@@ -1656,7 +1650,6 @@ var AuthClient = class {
1656
1650
  async verifyChallenge(params, options) {
1657
1651
  return this.challenges.verify(params, options);
1658
1652
  }
1659
- // ─── Account lifecycle ─────────────────────────────────────────────────────
1660
1653
  /**
1661
1654
  * Activates an account via the confirmation link sent to the user's email/phone.
1662
1655
  */
@@ -1690,7 +1683,6 @@ var AuthClient = class {
1690
1683
  resetPassword(params, options) {
1691
1684
  return this.http.post("/recover/reset-password", params, options);
1692
1685
  }
1693
- // ─── Session ───────────────────────────────────────────────────────────────
1694
1686
  /**
1695
1687
  * Validates the current session and optionally checks a grant.
1696
1688
  *
@@ -1809,7 +1801,6 @@ var AuthBrowserClient = class extends AuthClient {
1809
1801
  on(event, handler) {
1810
1802
  return this.emitter.on(event, handler);
1811
1803
  }
1812
- // ─── Session persistence override ─────────────────────────────────────────
1813
1804
  async persistSession(result) {
1814
1805
  const out = await super.persistSession(result);
1815
1806
  if (!out.error) {
@@ -1824,7 +1815,6 @@ var AuthBrowserClient = class extends AuthClient {
1824
1815
  }
1825
1816
  return out;
1826
1817
  }
1827
- // ─── Active session helpers ────────────────────────────────────────────────
1828
1818
  /**
1829
1819
  * Returns the session currently stored in storage, or `null` if there is none.
1830
1820
  *
@@ -1856,7 +1846,6 @@ var AuthBrowserClient = class extends AuthClient {
1856
1846
  await this.session?.save(data);
1857
1847
  }
1858
1848
  }
1859
- // ─── Multi-account ─────────────────────────────────────────────────────────
1860
1849
  /**
1861
1850
  * Adds an account to the accounts store without switching the active session.
1862
1851
  *
@@ -1935,7 +1924,6 @@ var AuthBrowserClient = class extends AuthClient {
1935
1924
  }
1936
1925
  await this.session?.clear();
1937
1926
  }
1938
- // ─── signOut override ──────────────────────────────────────────────────────
1939
1927
  async signOut(scope, options) {
1940
1928
  const stored = await this.session?.get();
1941
1929
  const userId = stored ? stored.user?.id ?? extractUserId({ access_token: stored.access_token }) : null;