@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
127 lines (125 loc) • 4.69 kB
TypeScript
import { User } from "./user.js";
import { Formatting } from "../formatting.js";
import { SoftrContext } from "./context.js";
import * as react0 from "react";
import { ReactNode } from "react";
import * as _tanstack_react_start0 from "@tanstack/react-start";
//#region src/auth/isomorphic.d.ts
/**
* Resolves the Softr visitor, their permissions and the app's formatting for
* every request, so that `getSoftrContext` and the route guards have something
* to read.
*
* Register it once, as a global request middleware in the app's `src/start.ts`.
* It writes the session cookie, and in production a header that stops other
* sites from embedding the app.
*
* @example
* export const startInstance = createStart(() => ({
* requestMiddleware: [softrAuthMiddleware()],
* }))
*/
declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
user: User | null;
permissions: {
datasources: {};
};
formatting: Formatting;
origin: string;
}>;
/**
* Resolves the route context of the root route: the visitor and what they may
* do. It requires {@link softrAuthMiddleware} to be registered.
*
* @example
* export const Route = createRootRouteWithContext<SoftrContext>()({
* beforeLoad: async () => await getSoftrContext(),
* })
*/
declare const getSoftrContext: _tanstack_react_start0.OptionalFetcher<undefined, undefined, Promise<SoftrContext>>;
/**
* The context to hand `createRouter`, before any request has resolved one.
*
* @example
* createRouter({ routeTree, context: initialSoftrContext() })
*
* @example
* createRouter({ routeTree, context: { ...initialSoftrContext(), something: "else" } })
*/
declare function initialSoftrContext(): SoftrContext;
/**
* Resolves the current user, returning `null` for anonymous visitors.
*
* @example
* function Greeting() {
* const user = useCurrentUser()
* return <p>{user ? `Hello, ${user.fullName}` : "Please sign in"}</p>
* }
*/
declare function useCurrentUser(): User | null;
/** Which ways in this app offers, each named for the `auth` call it unlocks. */
type AuthOptions = {
/** `auth.signIn` */
password: boolean;
/** `auth.sendSignInCode`, then `auth.signInWithCode` */
emailCode: boolean;
/** `auth.signInWithMagicLink` */
magicLink: boolean;
/** `auth.signInWithGoogle`, with the client id to start Google sign-in with. */
google: {
clientId: string;
} | null;
/**
* Single sign-on through the app's identity provider: a link to
* `ssoSignInHref`, and `auth.discoverSso` to route by email.
*/
sso: {
type: "SAML" | "OPEN_ID";
} | null;
/** `auth.signUp`, then `auth.confirmSignUp` */
signUp: boolean;
/** The builder asked for strong passwords whenever a visitor sets one. */
strongPasswords: boolean;
};
/**
* Loads the app's {@link AuthOptions}. Call it from the auth layout's loader
* and hand the result to {@link AuthSettingsProvider}.
*
* @example
* export const Route = createFileRoute("/_auth")({
* loader: () => getAuthSettings(),
* staleTime: 60_000,
* })
*/
declare const getAuthSettings: _tanstack_react_start0.OptionalFetcher<undefined, undefined, Promise<AuthOptions>>;
/**
* Makes the auth options readable with {@link useAuthSettings} anywhere below.
*
* @example
* function AuthLayout() {
* const authSettings = Route.useLoaderData()
* return (
* <AuthSettingsProvider value={authSettings}>
* <Outlet />
* </AuthSettingsProvider>
* )
* }
*/
declare function AuthSettingsProvider({
value,
children
}: {
value: AuthOptions;
children?: ReactNode;
}): react0.JSX.Element;
/**
* Which ways in this app offers. Requires an {@link AuthSettingsProvider}
* above it.
*
* @example
* const options = useAuthSettings()
* return options.password && <PasswordForm />
*/
declare function useAuthSettings(): AuthOptions;
//#endregion
export { AuthOptions, AuthSettingsProvider, getAuthSettings, getSoftrContext, initialSoftrContext, softrAuthMiddleware, useAuthSettings, useCurrentUser };