UNPKG

@raona/sp

Version:

Raona utilities to work with Sharepoint using pnp/sp

185 lines (184 loc) 11.1 kB
import "@pnp/polyfill-ie11"; import { CheckinType, FileAddResult } from "@pnp/sp"; import { GetListItemOptions } from './GetListItemsOptions'; import LikeInfo from "../entities/sharepoint/LikeInfo"; import { SearchResults } from "@pnp/sp"; import { GetFolderOptions } from "./GetFolderOptions"; import { SearchQueryInit } from "@pnp/sp/src/search"; import { BaseComponentContext } from "@microsoft/sp-component-base"; import { SPPickerTerm } from '../entities/sharepoint/SPPickerTerm'; import { MultiSiteGetOptions } from "../entities/MultiSiteGetOptions"; import { Web, WebEnsureUserResult } from "@pnp/sp"; import { SPRest } from "@pnp/sp"; import { LoggingOptions } from "../logger/entities/LoggingOptions"; import { List } from "@pnp/sp"; import { ItemAddResult, Item, PagedItemCollection, ItemUpdateResult } from "@pnp/sp"; import { Field } from "@pnp/sp"; import { TypedHash } from "../entities/TypedHash"; import { CamlQuery, PermissionKind } from "@pnp/sp"; import { SPBatch } from "@pnp/sp"; import { SPTaxonomy } from "../entities/sharepoint/SPTaxonomy"; import { RelativeFile } from "../entities/sharepoint/RelativeFile"; import { RoleAssignment } from "../entities/sharepoint/RoleAssignment"; import { SPContentType } from "../entities/sharepoint/SPContentType"; import { FileBuffer } from "../entities/FileBuffer"; import { FolderField } from "../entities/sharepoint/FolderField"; import { FolderAddResult } from "@pnp/sp"; import { PaginatedCamlQueryInfo } from "./PaginatedCamlQueryInfo"; declare global { interface Window { _spPageContextInfo: any; } } export declare enum AssociatedGroupType { OWNERS = 0, MEMBERS = 1, VISITORS = 2 } export declare class SPAbstractService { private context?; private logOptions?; private web; private oldWeb; private sp; private logger; private absoluteUrl; private oldAbsoluteUrl; private relativeUrl; /** * @param context WebpartContextBase or ListViewCommandSetContext */ constructor(context?: any, logOptions?: LoggingOptions, webUrlToOperate?: string); getServerRelativeUrl(): Promise<any>; updateAllListItems(listName: string, update: {}): Promise<void>; getListbyId(listId: string): Promise<List>; getList(listName: string): Promise<List>; List(listName: string): List; getListItemEntity(listName: string): Promise<string>; getLists(): Promise<List[]>; getFieldsFromList(listName: string, ...fieldNames: string[]): Promise<Field[]>; addListItemOnFolder(listName: string, folderName: string, item: any, listPath?: string): Promise<ItemAddResult>; getFieldByTitle(listName: string, fieldName: string): Promise<any>; getAllFieldsFromList(listName: string): Promise<any[]>; getFieldsFromCurrentList(...fieldNames: string[]): Promise<TypedHash<Field[]>>; getFieldFromListCommon(listName: string, fieldName: string): Promise<any>; private getFieldFromListId; recycleListItem(listName: string, itemId: number): Promise<string>; recycleListItemByFilter(listName: string, filter: string): Promise<string>; deleteListItem(listName: string, itemId: number): Promise<void>; deleteListItemByFilter(listName: string, filter: string): Promise<void>; getListItemById<T>(options: GetListItemOptions, itemId: number): Promise<T>; getListItemByIdToUpdate(listName: string, itemId: number): Promise<Item>; getListContentTypes(options: GetListItemOptions): Promise<any[]>; getListItems<T>(options: GetListItemOptions): Promise<T[]>; getListItemsPaged<T>(options: GetListItemOptions): Promise<PagedItemCollection<T[]>>; getListItemsCaml<T = any>(listName: string, query: CamlQuery, expand?: string, batch?: SPBatch): Promise<T[]>; getListByIdItemsCaml<T = any>(listId: string, query: CamlQuery, expand?: string, batch?: SPBatch): Promise<T[]>; getFileItems<T>(options: GetListItemOptions): Promise<T[]>; toggleLike(listName: string, itemId: number, likeInfo: LikeInfo, userId: number, liked: boolean): Promise<any>; getTaxonomyInternalNameForList(listName: string, internalName: string): Promise<string>; stringifyTaxonomy(taxonomy: SPTaxonomy | SPPickerTerm, wssid?: number): string; private like; private unlike; getFileUrlsFromFolder(folderPath: string, top?: number, expand?: string[]): Promise<RelativeFile[]>; ensureUserByLoginName(loginName: string): Promise<WebEnsureUserResult>; getUserByLoginName(loginName: string): Promise<any>; getUserByEmail(email: string): Promise<any>; getUserById(userId: number): Promise<any>; getCurrentUserGroups(): Promise<any>; getUserGroupsById(userId: number): Promise<any[]>; getUserGroupsByLoginName(loginName: string): Promise<any[]>; getUserGroupsByEmail(email: string): Promise<any[]>; getUsers(): Promise<any>; isUserInGroup(id: number | string, groupName: string, isIdEmail?: boolean): Promise<boolean>; canCurrentUserViewMembership(groupName: string): Promise<boolean>; private getGroupByAssociatedGroupType; isUserInGroupAssociated(id: number | string, associatedType: AssociatedGroupType, isIdEmail?: boolean): Promise<boolean>; canCurrentUserViewMembershipAssociated(associatedType: AssociatedGroupType): Promise<boolean>; isCurrentUserSiteCollectionAdmin(): Promise<boolean>; getCurrentUserProperties(): Promise<TypedHash<any>>; getUserPropertiesFor(loginName: string): Promise<TypedHash<any>>; getUserPropertiesForById(userId: number): Promise<TypedHash<any>>; getRawUserPropertiesFor(loginName: string): Promise<TypedHash<any>>; private convertUserProfilePropertiesToHash; getCurrentListItem<T = any>(): Promise<T>; getCurrentListItemFieldsByPrefix<T = any>(...prefix: string[]): Promise<T>; getCurrentListItemFieldsNamesByPrefix(...prefix: string[]): Promise<string[]>; updateCurrentListItem<T>(item: Partial<Item> & T): Promise<ItemUpdateResult>; assignMultipleRoleDefinitionsToCurrentListItems(copyRoleAssignments: boolean, ids: number[], roleAssignments: RoleAssignment[]): Promise<void>; assignMultipleRoleDefinitionsByListName(listName: string, copyRoleAssignments: boolean, ids: number[], roleAssignments: RoleAssignment[]): Promise<void>; assignMultipleRoleDefinitionsByListId(listId: string, copyRoleAssignments: boolean, ids: number[], roleAssignments: RoleAssignment[]): Promise<void>; private commonAssignMultipleRoleDefinitions; resetRoleInheritanceMultipleByListName(listName: string, ids: number[]): Promise<void>; resetRoleInheritanceMultipleByListId(listId: string, ids: number[]): Promise<void>; resetRoleInheritanceMultipleOnCurrentList(ids: number[]): Promise<void>; private commonResetRoleInheritance; updateManyOfListByName<T = any>(listName: string, ids: number[], items: (Partial<T>)[]): Promise<void>; updateManyOfListById<T = any>(listId: string, ids: number[], items: (Partial<T>)[]): Promise<void>; updateManyOfCurrentList<T = any>(ids: number[], items: (Partial<T>)[]): Promise<void>; private updateManyLengthCheck; private updateManyCommon; multiSiteGet(sitesGetOptions: MultiSiteGetOptions[]): Promise<TypedHash<any>>; tryDiscardCurrentPage(): Promise<void>; checkoutCurrentPage(): Promise<void>; checkinCurrentPage(): Promise<void>; checkoutMultipleFiles(fileUrls: string[]): Promise<void>; checkinMultipleFiles(fileUrls: string[], type?: CheckinType): Promise<void>; checkUserPermissionOnCurrentList(permission: PermissionKind, listId?: string): Promise<boolean>; checkUserPermissionOnCurrentListItem(permission: PermissionKind, itemId?: number): Promise<boolean>; getRawSP(): SPRest; getRawWeb(): Web; readonly webContext: BaseComponentContext; getContentTypeByName(name: string): Promise<SPContentType>; private applyQueryCollectionOptions; private getCurrentListQuery; private getCurrentListItemQuery; addListItem<T = any>(listName: string, item: T): Promise<ItemAddResult>; addFileToList(listName: string, file: FileBuffer, overwrite: boolean): Promise<FileAddResult>; addFileToFolder(folderPath: string, file: FileBuffer, overwrite: boolean): Promise<FileAddResult>; addFileToFolderWithoutFileBuffer(folderPath: string, fileName: string, file: string | Blob | ArrayBuffer, overwrite: boolean): Promise<FileAddResult>; addFileToFolderChunks(folderPath: string, fileName: string, file: Blob, overwrite: boolean): Promise<FileAddResult>; addFolderToFolder(folderPath: string, folderName: string): Promise<FolderField>; addMockFileToFolder(path: string, folderRelativePath: string): Promise<any>; getCanvasContentAndLayout(templateFileRef: string): Promise<{ canvas: string; layout: string; }>; removeFileFromRelativeUrl(filePath: string): Promise<void>; recycleFileFromRelativeUrl(filePath: string): Promise<string>; getFolderByUrl(folderUrl: string, expand?: string): Promise<FolderField>; getFolderFilesByUrl(options: GetFolderOptions): Promise<any[]>; getFolderFilesByName(folderName: string, listName: string): Promise<any[]>; getFoldersOnFolderByUrl(options: GetFolderOptions): Promise<FolderField[]>; getFolderOnList(listName: string, folderName: string): Promise<FolderField>; createFolderOnList(listName: string, folderName: string): Promise<FolderField>; createFolderOnListV2(listName: string, folderName: string): Promise<FolderField>; createFolderOnCustomList(listName: string, folderName: string): Promise<any>; createFoldersOnFolder(folderUrl: string, folderNames: string[]): Promise<FolderAddResult[]>; getDocumentIcon(fileName: string): Promise<string>; searchEntities(query: SearchQueryInit, useCaching?: boolean): Promise<SearchResults>; /** * Method to change the web where the SPAbstractService operates * * @example when from subsites you need to call lists on parent site, etc * * @param webUrl String indicating the new absolute url to use on the service * @param useForNextCalls When true, it will save the absoluteUrl and the relativeUrl * * @returns Previously assigned Web, just in case you need to call multiple times setWeb without calling restoreWeb in between */ setWeb(webUrl: string, useForNextCalls?: boolean): Web; /** * Gets relative url * @returns currently assigned web server relative */ getRelativeUrl(): string; /** * It will retore the web existing before the last call to setWeb * * @remark multiple calls to setWeb without calling restore web every time could lead to unexpected bugs when using this method. * @see SetWeb Method. */ restoreWeb(): void; getListItemsCamlPaged<T>(listName: string, query: CamlQuery, rowLimit?: number): Promise<PaginatedCamlQueryInfo<T>>; }