UNPKG

@edifice.io/client

Version:
401 lines (400 loc) • 12.7 kB
import { App, ID, ILinkedResource, ResourceType, RightRole, RightStringified } from '..'; /** * @deprecated Used by the internal linker ONLY * Old-fashioned way of listing resources => `behaviours.loadResources()` */ export interface IBehaviourService { /** App providing this service. */ getApplication(): App | string; /** Type of resource this service can manage. */ getResourceType(): ResourceType; /** Load resources. */ loadResources(parameters: GetContextParameters): Promise<ILinkedResource[]>; } /** * Resources management service. * Resources are assets created or imported in the whole solution (core and non-core apps) */ export interface IResourceService { /** App providing this service. */ getApplication(): App | string; /** Type of resource this service can manage. */ getResourceType(): ResourceType; /** Create a new resource from common parameters. */ create<T extends CreateParameters>(parameters: T): Promise<CreateResult>; /** Update an existing resource from common parameters. */ update<T extends UpdateParameters>(parameters: T): Promise<UpdateResult>; /** Copy a resource from common parameters. */ copy<T extends CopyParameters>(parameters: T): Promise<CopyResult>; /** Publish an resource */ publish(parameters: PublishParameters): Promise<PublishResult>; /** Delete folders and/or resources. */ deleteAll(parameters: DeleteParameters, useAssetId?: boolean): Promise<IActionResult>; /** Trash folders and/or resources. */ trashAll(parameters: DeleteParameters, useAssetId?: boolean): Promise<IActionResult>; /** Restore folders and/or resources from trash. */ restoreAll(parameters: DeleteParameters, useAssetId?: boolean): Promise<IActionResult>; /** Create a search context and get the first results page. */ createContext(parameters: GetContextParameters): Promise<GetContextResult>; /** Search / paginate within a search context. */ searchContext(parameters: GetContextParameters): Promise<ISearchResults>; /** Search 1 resource by `id` */ searchResource(parameters: GetResourceParameters): Promise<IResource>; /** Create a new folder. */ createFolder(parameters: CreateFolderParameters): Promise<CreateFolderResult>; /** Update folder. */ updateFolder(parameters: UpdateFolderParameters): Promise<CreateFolderResult>; /** Move resources/folders to a folder. */ moveToFolder(parameters: MoveParameters, useAssetId?: boolean): Promise<IActionResult>; /** List subfolders of a parent folder. */ listSubfolders(folderId: ID): Promise<GetSubFoldersResult>; } /** FIXME */ export interface IWebResourceService { /** URL where to print a resource. */ getPrintUrl(resourceId: string): string; /** URL where to view a resource. */ getViewUrl(resourceId: string): string; /** URL where to edit a resource. */ getEditUrl(resourceId: string): string; /** URL where to create a new resource. */ getFormUrl(folderId?: string): string; } /** Model of a searchable (indexed) resource. */ export interface IResource { application: App | string; assetId: ID; creatorId: ID; creatorName: string; comments?: number; createdAt: string; favorite?: boolean; folderIds?: ID[]; id: ID; modifiedAt: string; modifierId: ID; modifierName: string; name: string; slug?: string; public?: boolean; shared?: boolean; thumbnail: string; updatedAt: string; views?: number; trashed: boolean; trashedBy?: ID[]; rights: RightStringified[]; description: string; } /** * Core actions applicable on resources. * Specific actions, which would depend on the running application, * MUST BE typed and implemented in this application's agent. */ export declare const ACTION: { readonly SEARCH: "search"; readonly CREATE: "create"; readonly CREATE_PUBLIC: "createPublic"; readonly OPEN: "open"; readonly EDIT: "edit"; readonly MANAGE: "manage"; readonly UPD_PROPS: "properties"; readonly COMMENT: "comment"; readonly DELETE: "delete"; readonly TRASH: "trash"; readonly RESTORE: "restore"; readonly MOVE: "move"; readonly COPY: "copy"; readonly EXPORT: "export"; readonly SHARE: "share"; readonly PRINT: "print"; readonly PAGES_LIST: "pages_list"; readonly DISTRIBUTE: "distribute"; readonly REGISTER: "register"; readonly PUBLISH: "publish"; readonly PUBLISH_MOODLE: "publish_moodle"; }; export type ActionType = (typeof ACTION)[keyof typeof ACTION]; /** Constant folders IDs */ export declare const FOLDER: { /** Special ID of the bin, or trash folder. */ readonly BIN: "bin"; /** Special ID of the root folder. */ readonly DEFAULT: "default"; }; export type FolderType = (typeof FOLDER)[keyof typeof FOLDER]; /** Constant search filters IDs, having a boolean type. */ export declare const BOOLEAN_FILTER: { readonly OWNER: "owner"; readonly SHARED: "shared"; readonly PUBLIC: "public"; readonly FAVORITE: "favorite"; }; export type BooleanFilterType = (typeof BOOLEAN_FILTER)[keyof typeof BOOLEAN_FILTER]; /** Sort orders. */ export declare const SORT_ORDER: { readonly ASC: "asc"; readonly DESC: "desc"; }; export type SortOrderType = (typeof SORT_ORDER)[keyof typeof SORT_ORDER]; /** Sortable fields. */ export declare const SORT_BY: { readonly NAME: "name"; readonly MODIFY_DATE: "updatedAt"; readonly CREATED_AT: "createdAt"; readonly APPLICATION: "application"; readonly RESOURCE_TYPE: "resourceType"; }; export type SortByType = (typeof SORT_BY)[keyof typeof SORT_BY]; export type FilterValues = { [B in BooleanFilterType]?: boolean; } & { folder?: ID; }; export type OrderValues = { [O in SortByType]?: SortOrderType; }; /** * Model of actions the user can -or cannot- accomplish. */ export interface IAction { id: ActionType; /** Needed workflow right to accomplish this action. */ workflow: string; /** Thruthy if the user owns the corresponding right. */ available?: boolean; target?: 'actionbar' | 'tree'; right?: RightRole; } export interface IFolder { id: ID; parentId: ID; name: string; type: FolderType | ID; childNumber: number; trashed: boolean; rights: string[]; ancestors: string[]; } export interface IFilter { id: BooleanFilterType; defaultValue?: string | string[] | boolean | boolean[]; } export interface IOrder { id: SortByType; defaultValue?: SortOrderType; i18n: string; } export interface IPagination { /** Index of the first available result. */ startIdx: number; /** Number of actual results. */ pageSize: number; /** Index of the last result (number of hits less 1). */ maxIdx?: number; } /** Base */ export interface IActionParameters { application: App | string; } /** */ export interface IActionResult { } /** Parameters expected to create a resource */ export interface CreateParameters extends IActionParameters { name: string; description: string; thumbnail: string | Blob | File; folder: number | undefined; public?: boolean; slug?: string; commentType?: string; publishType?: string; } /** Response when creating resource */ export interface CreateResult { 'entId': string; 'thumbnail': string | undefined; '_id'?: string; 'title'?: string; 'description'?: string; 'visibility'?: string; 'trashed'?: boolean; 'publish-type'?: string; 'comment-type'?: string; 'created'?: { $date: string; }; 'modified'?: { $date: string; }; 'author'?: { userId: string; username: string; login: string; }; 'shared'?: Array<string>; } /** Parameters expected to copy a resource. */ export interface CopyParameters extends IActionParameters { resourceId: ID; } /** Response when copying a resource. */ export interface CopyResult extends IActionResult { duplicateId: ID; message: string; } /** Parameters expected to publish a resource */ export interface PublishParameters extends IActionParameters { userId: string | undefined; title: string; cover: Blob; language: string; activityType: string[]; subjectArea: string[]; age: [string, string]; description: string; keyWords: string; licence: string; teacherAvatar: Blob; resourceId: string; resourceEntId: string; userStructureName: string; } /** Response when publishing a resource */ export interface PublishResult extends IActionResult { details: { application: string; created_at: string; description: string; front_url: string; id: string; title: string; }; message: string; reason: string; success: boolean; } export interface IPreferences { view: 'card' | 'list'; } export interface ISearchParameters { types: ResourceType[]; filters: FilterValues; orders?: OrderValues; pagination: IPagination; search?: string; trashed?: boolean; id?: number; asset_id?: string[]; } export interface IResourceParameters { id: string; } export interface ISearchResults { folders: IFolder[]; pagination: IPagination; resources: IResource[]; searchConfig?: { minLength: number; }; } export interface IContext extends ISearchResults { preferences: IPreferences; } /** Parameters expected to search for a resource */ export type GetContextParameters = IActionParameters & ISearchParameters; /** Response when searching for a resource */ export type GetContextResult = IActionResult & IContext; /** Parameters expected to create a folder */ export interface CreateFolderParameters extends IActionParameters { type?: ResourceType; parentId: ID | 'default'; name: string; } /** Response when creating a folder */ export interface CreateFolderResult extends IActionResult, IFolder { createdAt: string; creator_id?: string; } /** Parameters expected to update a folder */ export interface UpdateFolderParameters extends IActionParameters { folderId: ID; type: ResourceType; parentId: ID | 'default'; name: string; } /** Response when updating a folder */ export interface UpdateFolderResult extends CreateFolderResult { updatedAt: string; parentId: ID | 'default'; } /** Parameters expected to move folders and/or resources */ export interface MoveParameters extends IActionParameters { folderId: ID; resourceIds: ID[]; folderIds: ID[]; } /** Response when listing subfolders of a folder */ export interface GetSubFoldersResult extends IActionResult { folders: IFolder[]; } /** Parameters expected to delete folders and/or resources */ export interface DeleteParameters extends IActionParameters { resourceType: string; resourceIds: ID[]; folderIds: ID[]; } export interface TrashParameters extends DeleteParameters { trash: boolean; } export type GetResourceParameters = IActionParameters & IResourceParameters; export type GetResourcesParameters = IActionParameters & ISearchParameters; export type GetResourcesResult = IActionResult & ISearchResults; /** Parameters expected to update resource. */ export interface UpdateParameters { entId: string; trashed: boolean; name: string; thumbnail: string | Blob | File; description: string; public: boolean; slug: string; } /** Response when updating resource. */ export interface UpdateResult { entId: string; thumbnail?: string; } export interface BlogUpdate extends UpdateParameters { 'publish-type'?: 'RESTRAINT' | 'IMMEDIATE'; } export interface BlogResource extends IResource { 'publish-type': 'RESTRAINT' | 'IMMEDIATE'; } export interface MindmapUpdate extends UpdateParameters { 'publish-type'?: 'RESTRAINT' | 'IMMEDIATE'; } export interface MindmapResource extends IResource { 'publish-type': 'RESTRAINT' | 'IMMEDIATE'; } export interface CollaborativewallUpdate extends UpdateParameters { 'publish-type'?: 'RESTRAINT' | 'IMMEDIATE'; } export interface CollaborativewallResource extends IResource { 'publish-type': 'RESTRAINT' | 'IMMEDIATE'; } export interface HomeworksCreate extends CreateParameters { repeats?: any[]; } export interface HomeworksUpdate extends UpdateParameters { repeats?: any[]; } export interface ScrapbookUpdate extends UpdateParameters { } export interface ScrapbookResource extends IResource { } export interface TimelineGeneratorUpdate extends UpdateParameters { } export interface CollaborativeEditorUpdate extends UpdateParameters { }