TypeScript Type Reference
SDK types used across @reauth-dev/sdk and its sub-paths (/server, /react, /webhooks). Source: libs/sdks/ts/src/types.ts.
Configuration
/** Configuration for browser-side reauth client */
type ReauthConfig = {
domain: string;
timeout?: number; // Default: 10000ms
};
/** Configuration for server-side reauth client */
type ReauthServerConfig = ReauthConfig & {
apiKey: string;
};
Authentication
/** Response from GET /api/public/auth/session */
type ReauthSession = {
valid: boolean;
end_user_id: string | null;
email: string | null;
roles: string[] | null;
active_org_id: string | null;
org_role: string | null;
waitlist_position: number | null;
google_linked: boolean | null;
twitter_linked: boolean | null;
error: string | null;
error_code: string | null;
subscription?: {
status: string;
plan_code: string | null;
plan_name: string | null;
current_period_end: number | null;
cancel_at_period_end: boolean | null;
trial_ends_at: number | null;
};
};
/** Authenticated user object (from useAuth / useAuthContext) */
type User = {
id: string;
email: string;
roles: string[];
activeOrgId: string;
orgRole: string;
};
/** Full user details (from Developer API getUserById) */
type UserDetails = {
id: string;
email: string;
roles: string[];
emailVerifiedAt: string | null;
lastLoginAt: string | null;
isFrozen: boolean;
isWhitelisted: boolean;
createdAt: string | null;
};
/** JWT claims for domain end-user tokens */
type DomainEndUserClaims = {
sub: string;
domain_id: string;
domain: string;
active_org_id: string;
org_role: string;
roles: string[];
subscription: {
status: string;
plan_code: string | null;
plan_name: string | null;
current_period_end: number | null;
cancel_at_period_end: boolean | null;
trial_ends_at: number | null;
};
exp: number;
iat: number;
};
/** Authentication result from verifyToken/authenticate */
type AuthResult = {
valid: boolean;
user: {
id: string;
roles: string[];
activeOrgId: string;
orgRole: string;
subscription: SubscriptionInfo;
} | null;
claims: DomainEndUserClaims | null;
error?: string;
};
/** Request-like object for extractToken/authenticate */
type RequestLike = {
headers?: {
authorization?: string;
cookie?: string;
};
};
/** Response from GET /auth/token */
type TokenResponse = {
accessToken: string;
expiresIn: number;
tokenType: string;
};
Headless Authentication
/** Public domain configuration */
type DomainConfig = {
domain: string;
authMethods: {
magicLink: boolean;
googleOauth: boolean;
twitterOauth: boolean;
};
redirectUrl: string | null;
headlessEnabled: boolean;
};
type RequestMagicLinkOptions = {
email: string;
callbackUrl?: string;
};
type VerifyMagicLinkOptions = {
token: string;
};
type MagicLinkVerifyResult = {
success: boolean;
redirectUrl: string | null;
endUserId: string | null;
email: string | null;
waitlistPosition: number | null;
};
type GoogleOAuthStartResult = {
authUrl: string;
state: string;
};
type TwitterOAuthStartResult = {
authUrl: string;
state: string;
};
Organizations
type OrgRole = "owner" | "member";
type Organization = {
id: string;
name: string;
isPersonal: boolean;
createdAt: string | null;
};
type OrgMember = {
id: string;
orgId: string;
endUserId: string;
role: OrgRole;
joinedAt: string | null;
};
type OrgInvitation = {
id: string;
orgId: string;
email: string;
token: string;
role: OrgRole;
status: "pending" | "accepted";
expiresAt: string;
acceptedAt: string | null;
createdAt: string | null;
};
type OrgInviteLink = {
id: string;
orgId: string;
token: string;
role: OrgRole;
isActive: boolean;
expiresAt: string;
createdAt: string | null;
};
type SwitchOrgResult = {
activeOrgId: string;
orgRole: OrgRole;
subscription: SubscriptionInfo;
};
Subscriptions
type SubscriptionStatus =
| "active"
| "past_due"
| "canceled"
| "trialing"
| "incomplete"
| "incomplete_expired"
| "unpaid"
| "paused"
| "none";
/** Subscription info included in JWT claims (camelCase) */
type SubscriptionInfo = {
status: SubscriptionStatus;
planCode: string | null;
planName: string | null;
currentPeriodEnd: number | null;
cancelAtPeriodEnd: boolean | null;
trialEndsAt: number | null;
};
/** Current subscription details (from getSubscription) */
type Subscription = {
id: string | null;
planCode: string | null;
planName: string | null;
status: SubscriptionStatus;
currentPeriodEnd: number | null;
trialEnd: number | null;
cancelAtPeriodEnd: boolean | null;
};
// Used internally by SubscriptionPlan — not exported from root SDK
type PlanType = "self_service" | "sales";
type PlanFeature = {
code: string;
name: string;
featureType: "boolean" | "numeric";
numericValue: number | null;
unitLabel: string | null;
};
type SubscriptionPlan = {
id: string;
code: string;
name: string;
description: string | null;
priceCents: number;
currency: string;
interval: "monthly" | "yearly" | "custom";
intervalCount: number;
trialDays: number;
features: PlanFeature[];
displayOrder: number;
creditsAmount: number;
planType: PlanType;
contactUrl: string | null;
};
// Return types — used by createCheckout() and openBillingPortal(), not exported from root SDK
type CheckoutSession = {
checkoutUrl: string;
};
type PortalSession = {
portalUrl: string;
};
Balance & Transactions
type BalanceTransaction = {
id: string;
amountDelta: number;
reason: Record<string, unknown>;
balanceAfter: number;
createdAt: string;
};
type ChargeOptions = {
amount: number;
requestUuid: string;
note?: string;
};
type DepositOptions = {
amount: number;
requestUuid: string;
note?: string;
};
type TransactionsPaginationOptions = {
limit?: number;
offset?: number;
};
Credits & Payment Methods
type SymbolPosition = "left" | "right";
type CreditsConfig = {
creditsEnabled: boolean;
creditsPerDollar: number;
displayName: string;
displaySymbol: string | null;
displaySymbolPosition: SymbolPosition;
displayDecimals: number;
minPurchaseCents: number;
maxPurchaseCents: number;
manualTopUpAvailable: boolean;
autoTopUpAvailable: boolean;
overdrawEnabled: boolean;
};
type PaymentMethod = {
id: string;
provider: string;
methodType: string;
cardBrand: string | null;
cardLast4: string | null;
cardExpMonth: number | null;
cardExpYear: number | null;
priority: number;
createdAt: number;
};
type SetupIntentResult = {
clientSecret: string;
setupIntentId: string;
};
type PurchaseCreditsOptions = {
amountCents: number;
paymentMethodId: string;
idempotencyKey: string;
};
type CreditPurchaseResult = {
creditsPurchased: number;
newBalance: number;
paymentIntentId: string;
};
type AutoTopUpStatus = {
enabled: boolean;
thresholdCents: number;
purchaseAmountCents: number;
status: string;
lastFailureReason?: string;
retriesRemaining?: number;
nextRetryAt?: string;
};
type UpdateAutoTopUpOptions = {
enabled: boolean;
thresholdCents: number;
purchaseAmountCents: number;
};
Webhooks
// From @reauth-dev/sdk/webhooks
type WebhookEvent = {
id: string;
type: string;
api_version: string;
created_at: string;
domain_id: string;
data: Record<string, unknown>;
};
type VerifyWebhookOptions = {
payload: string;
signature: string;
secret: string;
tolerance?: number; // Default: 300 seconds
};
Errors
// From @reauth-dev/sdk
enum ReauthErrorCode {
OAUTH_RETRY_EXPIRED = "OAUTH_RETRY_EXPIRED",
}
type ReauthError = {
code: ReauthErrorCode | string;
message?: string;
};
// Helper function
function requiresOAuthRestart(error: ReauthError | null | undefined): boolean;
Client Types
// Return types of factory functions
type ReauthClient = ReturnType<typeof createReauthClient>;
type ServerClient = ReturnType<typeof createServerClient>;