/** * Built-in context functions. * * @example * var contextLib = require('/lib/xp/context'); * * @module context */ declare global { interface XpLibraries { '/lib/xp/context': typeof import('./context'); } } import type { PrincipalKey, User } from '@enonic-types/core'; export type { PrincipalKey, UserKey, Principal, ScriptValue, User } from '@enonic-types/core'; export interface AuthInfo { user?: User; principals?: PrincipalKey[]; } export type ContextAttributes = Record>; export interface Context { branch?: string; repository?: string; authInfo?: AuthInfo; attributes: ContextAttributes; } export interface ContextUserParams { login: string; idProvider?: string; } export interface ContextParams { repository?: string; branch?: string; user?: ContextUserParams; principals?: PrincipalKey[]; attributes?: ContextAttributes; } /** * Runs a function within a specified context. * * @example-ref examples/context/run.js * * @param {object} context JSON parameters. * @param {string} [context.repository] Repository to execute the callback in. Default is the current repository set in portal. * @param {string} [context.branch] Name of the branch to execute the callback in. Default is the current branch set in portal. * @param {object} [context.user] User to execute the callback with. Default is the current user. * @param {string} context.user.login Login of the user. * @param {string} [context.user.idProvider] Id provider containing the user. By default, the system id provider will be used. * @param {array} [context.principals] Additional principals to execute the callback with. * @param {object} [context.attributes] Additional Context attributes. * @param {function} callback Function to execute. * @returns {*} Result of the function execution. */ export declare function run(context: ContextParams, callback: () => T): T; /** * Returns the current context. * * @example-ref examples/context/get.js * * @returns {object} Return the current context as JSON object. */ export declare function get(): Context;