export { getContextualAuth } from '@wix/sdk-runtime/context'; /** * Information about the currently active token. */ export interface TokenInfo { /** Whether the token is currently active. */ active: boolean; /** Type of subject the token represents. */ subjectType: 'APP' | 'USER' | 'MEMBER' | 'VISITOR' | 'UNKNOWN'; /** ID of the subject. */ subjectId: string; /** Expiration time of the token as a [Unix timestamp](https://www.unixtimestamp.com/). */ exp: number; /** Time the token was issued as a [Unix timestamp](https://www.unixtimestamp.com/). */ iat: number; /** Client ID associated with the token. */ clientId?: string; /** ID of the Wix site. */ siteId: string; /** ID of the app instance. */ instanceId?: string; } /** * Creates a copy of a method with the elevated permissions required by the original method. * * > This method is not intended for use with [self-hosted Apps](https://dev.wix.com/docs/build-apps/develop-your-app/frameworks/self-hosting/about-self-hosting-for-wix-apps) or [Wix Headless sites and apps](https://dev.wix.com/docs/go-headless). * * Some methods are restricted as to who can call them, based on identities and/or permissions. For example, the [\`createProduct()\`](https://dev.wix.com/docs/sdk/backend-modules/stores/products/create-product) method can only be called by Wix users, while the [\`confirmBooking()\`](https://dev.wix.com/docs/sdk/backend-modules/bookings/bookings/confirm-booking) method can only be called by site collaborators who have certain administrative bookings permissions. * * Methods that have authentication restrictions are indicated by an authentication note in their descriptions. * * When you need to call a method from a context without the necessary authentication or permissions, create an elevated version of the method and call that elevated method instead. * * Due to potential security issues, the elevate() method can only be called in the backend. * * Learn more about elevation when: * - [Developing websites](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/authorization/elevation) * - [Building apps](https://dev.wix.com/docs/build-apps/develop-your-app/access/authorization/about-elevation) * * > **Warning:** Elevation permits users to call methods they typically cannot access. Therefore, you should only use it intentionally and securely. You should pay special attention when using `elevate()` in backend code that can be triggered from the frontend and in code that is exposed as an API to outside callers. * @param sourceFunction SDK function to elevate. * @returns An SDK method that runs with elevated permissions. * @example * Create a new product with elevated permissions: * ```ts * import { auth } from "@wix/essentials"; * import { products } from "@wix/stores"; * * const newProduct = { * // Add product details. * }; * * const elevatedCreateProduct = auth.elevate(products.createProduct); * const createdProduct = await elevatedCreateProduct(newProduct); * ``` */ export declare function elevate(sourceFunction: T): T; /** * Returns the information encoded in the currently active token in backend extensions. * * When developing [backend extensions](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/about-backend-extensions) for an app or [web methods](https://dev.wix.com/docs/velo/api-reference/wix-web-module/web-method), you might need to access information about the session making the request to your backend. * * This information is encoded in the token sent with the request, and can be accessed using `getTokenInfo()`. It can include the user ID, the site ID, the instance ID, and more. * @returns {Promise} Information about the currently active token. * @example * Backend extension example: Code for extracting information from a request to a backend extension in a Wix CLI project: * ```ts * import { auth } from "@wix/essentials"; * * export async function GET(req: Request) { * const tokenInfo = await auth.getTokenInfo(); * * if (tokenInfo.subjectType === "USER") { * return new Response(`Hello user ${tokenInfo.subjectId}`); * } else if (tokenInfo.subjectType === "APP") { * return new Response("Hello app"); * } else if (tokenInfo.subjectType === "MEMBER") { * return new Response(`Hello member ${tokenInfo.subjectId}`); * } else { * return new Response(`Hello visitor ${tokenInfo.subjectId}`); * } * } * ``` * @example * Web method example: Code for extracting information from a request to a web method: * ```ts * import { auth } from "@wix/essentials"; * import { Permissions, webMethod } from "@wix/web-methods"; * * export const sayHello = webMethod(Permissions.Anyone, async () => { * const tokenInfo = await auth.getTokenInfo(); * * if (tokenInfo.subjectType === "USER") { * return `Hello user ${tokenInfo.subjectId}`; * } else if (tokenInfo.subjectType === "APP") { * return "Hello app"; * } else if (tokenInfo.subjectType === "MEMBER") { * return `Hello member ${tokenInfo.subjectId}`; * } else { * return `Hello visitor ${tokenInfo.subjectId}`; * } * }); * ``` */ export declare const getTokenInfo: (() => Promise) & ((restModuleOpts: import("@wix/sdk-types").HttpClient) => () => Promise);