@enonic-types/lib-project
Version:
Type definitions for lib-project.
208 lines (206 loc) • 8.98 kB
TypeScript
/**
* Functions to manage Content Projects.
*
* @example
* var projectLib = require('/lib/xp/project');
*
* @module project
*/
declare global {
interface XpLibraries {
'/lib/xp/project': typeof import('./project');
}
}
export type { ScriptValue } from '@enonic-types/core';
export declare type ProjectRole = 'owner' | 'editor' | 'author' | 'contributor' | 'viewer';
export declare type ProjectPermission = Record<ProjectRole, string[]>;
export interface ProjectPermissions {
permissions?: Record<ProjectRole, string[]>;
}
export interface ProjectReadAccess {
public: boolean;
}
export interface SiteConfig<Config> {
applicationKey: string;
config?: Config;
}
export interface CreateProjectParams<Config extends Record<string, unknown>> {
id: string;
displayName: string;
description?: string;
language?: string;
parent?: string;
parents?: string[];
siteConfig?: SiteConfig<Config>[];
permissions?: ProjectPermission;
readAccess: ProjectReadAccess;
}
export interface Project<Config extends Record<string, unknown> = Record<string, unknown>> {
id: string;
displayName: string;
description: string;
parent?: string;
parents: string[];
siteConfig: SiteConfig<Config>[];
language?: string;
permissions?: ProjectPermission;
readAccess?: ProjectPermission;
}
/**
* Creates a new Content Project. Only `system.admin` and `cms.admin` roles have permissions to create new projects.
*
* @example-ref examples/project/create.js
*
* @param {Object} params JSON with the parameters.
* @param {string} params.id Unique project id (alphanumeric characters and hyphens allowed).
* @param {string} params.displayName Project's display name.
* @param {string} [params.description] Project description.
* @param {string} [params.language] Default project language.
* @param {string} [params.parent] Deprecated: use 'parents' param. Parent project id.
* @param {string[]} [params.parents] Parent project ids.
* @param {object} [params.siteConfig] Connected applications config.
* @param {Object.<string, string[]>} [params.permissions] Project permissions. 1 to 5 properties where key is role id and value is an array of principals.
* @param {string} params.permissions.role - Role id (one of `owner`, `editor`, `author`, `contributor`, `viewer`).
* @param {string[]} params.permissions.principals - Array of principals.
* @param {Object<string, boolean>} [params.readAccess] Read access settings.
* @param {boolean} params.readAccess.public Public read access (READ permissions for `system.everyone`).
*
* @returns {Object} Created project.
*/
export declare function create<Config extends Record<string, unknown> = Record<string, unknown>>(params: CreateProjectParams<Config>): Project<Config>;
export interface ModifyProjectParams<Config extends Record<string, unknown>> {
id: string;
displayName: string;
description?: string;
language?: string;
siteConfig?: SiteConfig<Config>[];
}
/**
* Modifies an existing Content Project.
* To modify a project, user must have `owner` permissions for this project, or either `system.admin` or `cms.admin` role.
*
* @example-ref examples/project/modify.js
*
* @param {Object} params JSON with the parameters.
* @param {string} params.id Unique project id to identify the project.
* @param {string} [params.displayName] Project's display name.
* @param {string} [params.description] Project description.
* @param {string} [params.language] Default project language.
* @param {object} [params.siteConfig] Connected applications config.
*
* @returns {Object} Modified project.
*/
export declare function modify<Config extends Record<string, unknown> = Record<string, unknown>>(params: ModifyProjectParams<Config>): Project<Config>;
export interface DeleteProjectParams {
id: string;
}
/**
* Deletes an existing Content Project. This will delete all of the data inside the project repository.
* To delete a project, user must have either `system.admin` or `cms.admin` role.
*
* @example-ref examples/project/delete.js
*
* @param {Object} params JSON with the parameters.
* @param {string} params.id Unique project id to identify the project.
*
* @returns {boolean} `true` if the project was successfully deleted.
*/
export declare function _delete(params: DeleteProjectParams): boolean;
export { _delete as delete, };
export interface GetProjectParams {
id: string;
}
/**
* Returns an existing Content Project.
* To `get` a project, user must be a member of one of the project roles, or either `system.admin` or `cms.admin` role.
*
* @example-ref examples/project/get.js
*
* @param {GetProjectParams} params JSON with the parameters.
* @param {string} params.id Unique project id to identify the project.
*
* @returns {Project} Content Project object or `null` if not found.
*/
export declare function get(params: GetProjectParams): Project | null;
export interface GetAvailableApplicationsParams {
id: string;
}
/**
* Returns available applications for the specified project. It contains apps specified for the current and all parent projects/layers.
* User must be a member of one of the project roles, or either `system.admin` or `cms.admin` role.
*
* @example-ref examples/project/getAvailableApplications.js
*
* @param {GetProjectParams} params JSON with the parameters.
* @param {string} params.id Unique project id to identify the project.
*
* @returns {string[]} Keys of the available applications.
*/
export declare function getAvailableApplications(params: GetAvailableApplicationsParams): string[];
/**
* Returns all Content Projects.
* The list will be limited to projects that user has permissions for.
* Users with `system.admin` or `cms.admin` roles will get the list of all projects.
*
* @example-ref examples/project/list.js
*
* @returns {Project[]} Array of Content Project objects.
*/
export declare function list(): Project[];
export interface AddProjectPermissionsParams {
id: string;
permissions?: ProjectPermission;
}
/**
* Adds permissions to an existing Content Project.
* To modify permissions, user must have `owner` permissions for the project, or either `system.admin` or `cms.admin` role.
*
* @example-ref examples/project/addPermissions.js
*
* @param {Object} params JSON with the parameters.
* @param {string} params.id Unique project id to identify the project.
* @param {Object.<string, string[]>} params.permissions Project permissions to add. 1 to 5 properties where key is role id and value is an array of principals.
* @param {string} params.permissions.role - Role id (one of `owner`, `editor`, `author`, `contributor`, `viewer`)
* @param {Object[]} params.permissions.principals - Array of principals to add to this role
*
* @returns {Object} All current project permissions.
*/
export declare function addPermissions(params: AddProjectPermissionsParams): ProjectPermissions | null;
export interface RemoveProjectPermissionsParams {
id: string;
permissions?: ProjectPermission;
}
/**
* Removes permissions from an existing Content Project.
* To modify permissions, user must have `owner` permissions for the project, or either `system.admin` or `cms.admin` role.
*
* @example-ref examples/project/removePermissions.js
*
* @param {Object} params JSON with the parameters.
* @param {string} params.id Unique project id to identify the project.
* @param {Object.<string, string[]>} params.permissions Project permissions to delete. 1 to 5 properties where key is role id and value is an array of principals.
* @param {string} params.permissions.role - Role id (one of `owner`, `editor`, `author`, `contributor`, `viewer`)
* @param {Object[]} params.permissions.principals - Array of principals to delete from this role
*
* @returns {Object} All current project permissions.
*/
export declare function removePermissions(params: RemoveProjectPermissionsParams): ProjectPermissions | null;
export interface ModifyProjectReadAccessParams {
id: string;
readAccess?: ProjectReadAccess;
}
/**
* Toggles public/private READ access for an existing Content Project.
* This will modify permissions on ALL the content items inside the project repository by adding or removing READ access for `system.everyone`.
* To modify READ access, user must have `owner` permissions for the project, or either `system.admin` or `cms.admin` role.
*
* @example-ref examples/project/modifyReadAccess.js
*
* @param {Object} params JSON with the parameters.
* @param {string} params.id Unique project id to identify the project.
* @param {Object<string, boolean>} params.readAccess READ access.
* @param {boolean} params.readAccess.public Public read access (READ permissions for `system.everyone`).
*
* @returns {Object<string, boolean>} Current state of READ access.
*/
export declare function modifyReadAccess(params: ModifyProjectReadAccessParams): ProjectReadAccess | null;