import { Result } from "../utils/results.js"; import { ReadonlyJson } from "../utils/json.js"; import { KnownErrors } from "../known-errors.js"; import { inlineProductSchema } from "../schema-fields.js"; import { AccessToken, InternalSession, RefreshToken } from "../sessions.js"; import { ProjectPermissionsCrud } from "./crud/project-permissions.js"; import { AdminUserProjectsCrud, ClientProjectsCrud } from "./crud/projects.js"; import { TeamPermissionsCrud } from "./crud/team-permissions.js"; import { a as RegistrationResponseJSON, i as PublicKeyCredentialRequestOptionsJSON, r as PublicKeyCredentialCreationOptionsJSON, t as AuthenticationResponseJSON } from "../index-B_YgvhKa.js"; import { ConnectedAccountAccessTokenCrud, ConnectedAccountCrud } from "./crud/connected-accounts.js"; import { ContactChannelsCrud } from "./crud/contact-channels.js"; import { CurrentUserCrud } from "./crud/current-user.js"; import { CustomerInvoicesListResponse, ListCustomerInvoicesOptions } from "./crud/invoices.js"; import { ItemCrud } from "./crud/items.js"; import { NotificationPreferenceCrud } from "./crud/notification-preferences.js"; import { OAuthProviderCrud } from "./crud/oauth-providers.js"; import { CustomerProductsListResponse, ListCustomerProductsOptions } from "./crud/products.js"; import { TeamApiKeysCrud, UserApiKeysCrud, teamApiKeysCreateInputSchema, teamApiKeysCreateOutputSchema, userApiKeysCreateInputSchema, userApiKeysCreateOutputSchema } from "./crud/project-api-keys.js"; import { SessionsCrud } from "./crud/sessions.js"; import { TeamInvitationCrud } from "./crud/team-invitation.js"; import { TeamMemberProfilesCrud } from "./crud/team-member-profiles.js"; import { TeamsCrud } from "./crud/teams.js"; import * as yup from "yup"; //#region src/interface/client-interface.d.ts type RequestLogEntry = { path: string; method: string; status?: number; duration: number; error?: string; }; type RequestListener = (entry: RequestLogEntry) => void; type ClientInterfaceOptions = { clientVersion: string; getBaseUrl: () => string; getAnalyticsBaseUrl?: () => string; /** * Ordered list of base URLs for request routing with fallback. * Index 0 = primary, index 1..N = fallbacks in priority order. * A single-element array means no fallback occurs. */ getApiUrls: () => string[]; /** * When a fallback succeeds and becomes the active server, this is the initial probability * (0–1) that any given request will probe the primary to check if it's back. * Halves on each failed probe, resets on success. Default: 0.3 (30%). */ probeRate?: number; extraRequestHeaders: Record; projectId: string; prepareRequest?: () => Promise; } & ({ publishableClientKey?: string; } | { projectOwnerSession: InternalSession | (() => Promise); }); type BotChallengeInput = { token?: string; phase?: "invisible" | "visible"; unavailable?: true; }; declare class StackClientInterface { readonly options: ClientInterfaceOptions; private pendingNetworkDiagnostics?; private _requestListeners; /** * Fallback state. When null, we're in normal mode (primary first). * When set, we skip straight to `stickyIndex` and only probe primary occasionally. */ private _sticky; private readonly _initialProbeRate; constructor(options: ClientInterfaceOptions); addRequestListener(listener: RequestListener): () => void; get projectId(): string; getApiUrl(): string; getApiUrls(): string[]; /** * Returns the best-known-good API URL: the sticky fallback if we're in * fallback mode, otherwise the primary. Use for browser-navigated URLs * (e.g. OAuth authorize) where _withFallback can't help. */ getBestApiUrl(): string; /** * Routes a request through an ordered URL list with automatic failover. * * The URL list is [primary, ...fallbacks]. The logic has two modes: * * **Normal mode** (`_sticky` is null) — try each URL in order. If a * non-primary URL succeeds, enter sticky mode on that index. * * **Sticky mode** — a previous request already failed over. We remember * which URL worked and go there directly. Occasionally (controlled by a * decaying probe rate) we probe the primary to see if it recovered: * - Probe succeeds → exit sticky mode, use result. * - Probe fails → halve probe rate, use sticky URL. * - Sticky URL fails → exit sticky mode, do a full iteration. * * In both modes, a full iteration tries every URL once per pass for 2 * passes before giving up. KnownErrors are never retried (they're * application-level, not network-level). * * Single-URL lists skip all of this and use 5-retry behavior directly. */ protected _withFallback(cb: (apiUrl: string, retryOptions: { maxAttempts: number; skipDiagnostics: boolean; }) => Promise): Promise; /** * Attempts the sticky URL, optionally probing primary first. * Returns the result on success, or `undefined` if we should fall through to full iteration. */ private _tryStickyUrl; /** * Tries every URL in order for up to 2 passes. * If a non-primary URL (index > 0) succeeds, enters sticky mode on it. */ private _iterateUrls; getAnalyticsApiUrl(): string; runNetworkDiagnostics(session?: InternalSession | null, requestType?: "client" | "server" | "admin"): Promise<{ "navigator?.onLine": any; cfTrace: string; baseUrlBackend: string; prodDashboard: string; prodBackend: string; }>; private _runNetworkDiagnosticsInner; protected _createNetworkError(cause: Error, session?: InternalSession | null, requestType?: "client" | "server" | "admin"): Promise; protected _networkRetry(cb: () => Promise>, session?: InternalSession | null, requestType?: "client" | "server" | "admin", options?: { maxAttempts?: number; skipDiagnostics?: boolean; }): Promise; protected _networkRetryException(cb: () => Promise, session?: InternalSession | null, requestType?: "client" | "server" | "admin", options?: { maxAttempts?: number; skipDiagnostics?: boolean; }): Promise; fetchNewAccessToken(refreshToken: RefreshToken): Promise; private _fetchNewAccessTokenInner; sendClientRequest(path: string, requestOptions: RequestInit, session: InternalSession | null, requestType?: "client" | "server" | "admin", apiUrlOverride?: string): Promise; createSession(options: Omit[0], "refreshAccessTokenCallback">): InternalSession; sendSessionReplayBatch(body: string, session: InternalSession | null, options: { keepalive: boolean; }): Promise>; sendAnalyticsEventBatch(body: string, session: InternalSession | null, options: { keepalive: boolean; }): Promise>; protected sendClientRequestAndCatchKnownError(path: string, requestOptions: RequestInit, tokenStoreOrNull: InternalSession | null, errorsToCatch: readonly E[]): Promise>>; private sendClientRequestInner; private _processResponse; checkFeatureSupport(options: { featureName?: string; } & ReadonlyJson): Promise; sendForgotPasswordEmail(email: string, callbackUrl: string): Promise>; sendVerificationEmail(email: string, callbackUrl: string, session: InternalSession): Promise; sendMagicLinkEmail(email: string, callbackUrl: string, botChallenge?: BotChallengeInput): Promise>; resetPassword(options: { code: string; } & ({ password: string; } | { onlyVerifyCode: true; })): Promise>; updatePassword(options: { oldPassword: string; newPassword: string; }, session: InternalSession): Promise; setPassword(options: { password: string; }, session: InternalSession): Promise; verifyPasswordResetCode(code: string): Promise>; verifyEmail(code: string): Promise>; initiatePasskeyRegistration(options: {}, session: InternalSession): Promise>; registerPasskey(options: { credential: RegistrationResponseJSON; code: string; }, session: InternalSession): Promise>; initiatePasskeyAuthentication(options: {}, session: InternalSession): Promise>; sendTeamInvitation(options: { email: string; teamId: string; callbackUrl: string; session: InternalSession; }): Promise; acceptTeamInvitation(options: { code: string; session: InternalSession; type: T; }): Promise>; totpMfa(attemptCode: string, totp: string, session: InternalSession): Promise<{ accessToken: any; refreshToken: any; newUser: any; }>; signInWithCredential(email: string, password: string, session: InternalSession): Promise>; signUpWithCredential(email: string, password: string, emailVerificationRedirectUrl: string | undefined, session: InternalSession, botChallenge?: BotChallengeInput): Promise>; signUpAnonymously(session: InternalSession): Promise>; signInWithMagicLink(code: string, session: InternalSession): Promise>; signInWithMfa(totp: string, code: string, session: InternalSession): Promise>; signInWithPasskey(body: { authentication_response: AuthenticationResponseJSON; code: string; }, session: InternalSession): Promise>; getOAuthUrl(options: { provider: string; redirectUrl: string; errorRedirectUrl: string; afterCallbackRedirectUrl?: string; codeChallenge: string; state: string; type: "authenticate" | "link"; providerScope?: string; botChallenge?: BotChallengeInput; session: InternalSession; }): Promise; authorizeOAuth(options: { provider: string; redirectUrl: string; errorRedirectUrl: string; afterCallbackRedirectUrl?: string; codeChallenge: string; state: string; type: "authenticate" | "link"; providerScope?: string; botChallenge?: BotChallengeInput; session: InternalSession; }): Promise>; callOAuthCallback(options: { oauthParams: URLSearchParams; redirectUri: string; codeVerifier: string; state: string; }): Promise<{ newUser: boolean; afterCallbackRedirectUrl?: string; accessToken: string; refreshToken: string; }>; private _callOAuthCallbackInner; signOut(session: InternalSession): Promise; getClientUserByToken(session: InternalSession): Promise; listTeamInvitations(options: { teamId: string; }, session: InternalSession): Promise; listCurrentUserTeamInvitations(session: InternalSession): Promise; acceptTeamInvitationById(invitationId: string, session: InternalSession): Promise; revokeTeamInvitation(invitationId: string, teamId: string, session: InternalSession): Promise; listTeamMemberProfiles(options: { teamId?: string; userId?: string; }, session: InternalSession): Promise; getTeamMemberProfile(options: { teamId: string; userId: string; }, session: InternalSession): Promise; leaveTeam(teamId: string, session: InternalSession): Promise; updateTeamMemberProfile(options: { teamId: string; userId: string; profile: TeamMemberProfilesCrud['Client']['Update']; }, session: InternalSession): Promise; updateTeam(options: { teamId: string; data: TeamsCrud['Client']['Update']; }, session: InternalSession): Promise; listCurrentUserTeamPermissions(options: { teamId: string; recursive: boolean; }, session: InternalSession): Promise; listCurrentUserProjectPermissions(options: { recursive: boolean; }, session: InternalSession): Promise; listCurrentUserTeams(session: InternalSession): Promise; getClientProject(): Promise>; updateClientUser(update: CurrentUserCrud["Client"]["Update"], session: InternalSession): Promise; listProjects(session: InternalSession): Promise; createProject(project: AdminUserProjectsCrud['Client']['Create'], session: InternalSession): Promise; createProviderAccessToken(provider: string, scope: string, session: InternalSession): Promise; /** * Get access token for a specific connected account by provider ID and provider account ID. * This is the preferred method when dealing with multiple accounts of the same provider. */ createProviderAccessTokenByAccount(providerId: string, providerAccountId: string, scope: string, session: InternalSession): Promise; /** * List all connected accounts for the current user. */ listConnectedAccounts(session: InternalSession): Promise; createClientTeam(data: TeamsCrud['Client']['Create'], session: InternalSession): Promise; deleteTeam(teamId: string, session: InternalSession): Promise; deleteCurrentUser(session: InternalSession): Promise; createClientContactChannel(data: ContactChannelsCrud['Client']['Create'], session: InternalSession): Promise; updateClientContactChannel(id: string, data: ContactChannelsCrud['Client']['Update'], session: InternalSession): Promise; deleteClientContactChannel(id: string, session: InternalSession): Promise; deleteSession(sessionId: string, session: InternalSession): Promise; listSessions(session: InternalSession): Promise; listClientContactChannels(session: InternalSession): Promise; sendCurrentUserContactChannelVerificationEmail(contactChannelId: string, callbackUrl: string, session: InternalSession): Promise>; cliLogin(loginCode: string, refreshToken: string, session: InternalSession): Promise>; private _getApiKeyRequestInfo; listProjectApiKeys(options: { user_id: string; }, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; listProjectApiKeys(options: { team_id: string; }, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; listProjectApiKeys(options: { user_id: string; } | { team_id: string; }, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise<(UserApiKeysCrud['Client']['Read'] | TeamApiKeysCrud['Client']['Read'])[]>; createProjectApiKey(data: yup.InferType, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise>; createProjectApiKey(data: yup.InferType, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise>; createProjectApiKey(data: yup.InferType | yup.InferType, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise | yup.InferType>; getProjectApiKey(options: { user_id: string | null; }, keyId: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; getProjectApiKey(options: { team_id: string; }, keyId: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; getProjectApiKey(options: { user_id: string | null; } | { team_id: string; }, keyId: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; updateProjectApiKey(options: { user_id: string; }, keyId: string, data: UserApiKeysCrud['Client']['Update'], session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; updateProjectApiKey(options: { team_id: string; }, keyId: string, data: TeamApiKeysCrud['Client']['Update'], session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; updateProjectApiKey(options: { user_id: string; } | { team_id: string; }, keyId: string, data: UserApiKeysCrud['Client']['Update'] | TeamApiKeysCrud['Client']['Update'], session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; checkProjectApiKey(type: "user", apiKey: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; checkProjectApiKey(type: "team", apiKey: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; checkProjectApiKey(type: "user" | "team", apiKey: string, session: InternalSession | null, requestType: "client" | "server" | "admin"): Promise; listNotificationCategories(session: InternalSession): Promise; setNotificationsEnabled(notificationCategoryId: string, enabled: boolean, session: InternalSession): Promise; getOAuthProvider(userId: string, providerId: string, session: InternalSession): Promise; updateOAuthProvider(userId: string, providerId: string, data: OAuthProviderCrud['Client']['Update'], session: InternalSession): Promise; listOAuthProviders(options: { user_id?: string; } | undefined, session: InternalSession): Promise; deleteOAuthProvider(userId: string, providerId: string, session: InternalSession): Promise; getItem(options: ({ itemId: string; userId: string; } | { itemId: string; teamId: string; } | { itemId: string; customCustomerId: string; }), session: InternalSession | null, requestType?: "client" | "server" | "admin"): Promise; listProducts(options: ListCustomerProductsOptions, session: InternalSession | null, requestType?: "client" | "server" | "admin"): Promise; listInvoices(options: ListCustomerInvoicesOptions, session: InternalSession | null): Promise; cancelSubscription(options: { customer_type: "user" | "team" | "custom"; customer_id: string; product_id: string; subscription_id?: string; }, session: InternalSession | null): Promise; switchSubscription(options: { customer_type: "user" | "team"; customer_id: string; from_product_id: string; to_product_id: string; price_id?: string; quantity?: number; }, session: InternalSession | null): Promise; createCheckoutUrl(customer_type: "user" | "team" | "custom", customer_id: string, productIdOrInline: string | yup.InferType, session: InternalSession | null, returnUrl?: string, requestType?: "client" | "server" | "admin"): Promise; getCustomerBilling(customerType: "user" | "team", customerId: string, session: InternalSession | null): Promise<{ has_customer: boolean; default_payment_method: { id: string; brand: string | null; last4: string | null; exp_month: number | null; exp_year: number | null; } | null; }>; createCustomerPaymentMethodSetupIntent(customerType: "user" | "team", customerId: string, session: InternalSession | null): Promise<{ client_secret: string; stripe_account_id: string; }>; setDefaultCustomerPaymentMethodFromSetupIntent(customerType: "user" | "team", customerId: string, setupIntentId: string, session: InternalSession | null): Promise<{ default_payment_method: { id: string; brand: string | null; last4: string | null; exp_month: number | null; exp_year: number | null; }; }>; transferProject(internalProjectSession: InternalSession, projectIdToTransfer: string, newTeamId: string): Promise; } //#endregion export { ClientInterfaceOptions, RequestListener, RequestLogEntry, StackClientInterface }; //# sourceMappingURL=client-interface.d.ts.map