@kwiz/common
Version:
KWIZ common utilities and helpers for M365 platform
128 lines (127 loc) • 6.33 kB
TypeScript
import { IDictionary } from "../types/common.types";
import { FieldTypeAsString, IFieldInfo, IFieldInfoEX, IFieldJsonSchema, PrincipalType, RententionLabelFieldValueType, SPBasePermissionKind, ThumbnailValueType, UrlValueType } from "../types/sharepoint.types";
import { UserEntityValueType } from "../types/sharepoint.utils.types";
export declare const KWIZ_CONTROLLER_FIELD_NAME = "kwizcomcontrollerfield";
export declare function IsClassicPage(): boolean;
export declare function restoreExperience(): void;
export declare function ensureClassicExperience(listId: string): void;
export declare function setExperienceCookie(value: string, reload?: boolean): void;
export declare function switchToClassicExperience(listId: string, reload?: boolean): void;
export declare function switchToModernExperience(reload?: boolean): void;
/** Gets field schema XML and converts it into JSON object */
export declare function SchemaXmlToJson(xml: string): IFieldJsonSchema;
export declare function SchemaJsonToXml(json: IFieldJsonSchema): string;
export declare function NormalizeListName(list: {
EntityTypeName: string;
BaseType: number;
}): string;
export declare class SPBasePermissions {
private $High;
private $Low;
constructor(EffectiveBasePermissions: {
High: number;
Low: number;
});
set(perm: SPBasePermissionKind): void;
clear(perm: any): void;
clearAll(): void;
has(perm: SPBasePermissionKind): boolean;
hasAny(...requestedPerms: SPBasePermissionKind[]): boolean;
haAll(...requestedPerms: SPBasePermissionKind[]): boolean;
hasPermissions(requestedPerms: {
High: number;
Low: number;
}): boolean;
hasAnyPermissions(...requestedPerms: {
High: number;
Low: number;
}[]): boolean;
hasAllPermissions(...requestedPerms: {
High: number;
Low: number;
}[]): boolean;
initPropertiesFromJson(EffectiveBasePermissions: {
High: number;
Low: number;
}): void;
}
export interface ISPPeoplePickerControlFormEntity {
/** ie: i:0#.f|membership|user@kwizcom.com */
Key: string;
EntityType: "FormsRole" | "SecGroup" | "SPGroup";
EntityData?: {
SPGroupID?: string;
PrincipalType?: "User" | "SecurityGroup" | "SharePointGroup";
/** string of number "8" */
SPUserID?: string;
SIPAddress?: string;
Email?: string;
};
Resolved?: boolean;
}
/** remove i:0#.f|membership| prefix from login */
export declare function CleanupUserClaimsLogin(login: string): string;
export declare function IsSPPeoplePickerControlFormEntity(entity: any): entity is ISPPeoplePickerControlFormEntity;
export declare function getPrincipalTypeFromPickerEntity(entity: ISPPeoplePickerControlFormEntity): PrincipalType.SecurityGroup | PrincipalType.SharePointGroup | PrincipalType.User;
/** rest object might put array values under ".results", this will place them at the property value directly */
export declare function NormalizeRestObject<T>(o: T): T;
/**
* Extends a field info into field info EX (adding SchemaJson)
* @param field REST field data
* @param allFields Optional - all list fields, used for discovering multi TaxonomyField's update hidden text field
*/
export declare function extendFieldInfo(field: IFieldInfo, allFields?: IFieldInfo[]): IFieldInfoEX;
export declare function extendFieldInfos(fields: IFieldInfo[]): IFieldInfoEX[];
export declare function getFieldOutputType(field: IFieldInfo): FieldTypeAsString;
export declare function isDocLib(list?: {
BaseType: number;
}): boolean;
export declare function GetOrderByFromCaml(camlQuery: string): {
Name: string;
IsAscending: boolean;
}[];
export declare function RemoveOrderByFromCaml(camlQuery: string): string;
export declare function EnsureViewFields(camlQuery: string, fields: string[], forceCreateViewFields: boolean, removeAllOthers?: boolean): string;
/**If it is a thumbnail field - parse and return a typed value */
export declare function ParseThumbnalFieldValue(value?: string, context?: {
itemId: number;
rootFolder: string;
}): ThumbnailValueType;
export declare function isTitleField(fieldName: string): boolean;
/** we are on a list view page, not a web part page with possible multiple list views */
export declare function isSingleViewPage(): boolean;
/**
* Splits the ViewFields of a CAML query into separate entries based on the batch size.
* @param {string} camlQuery - The CAML query string.
* @param {number} batchSize - The size of each batch (number of ViewFields per entry).
*/
export declare function splitViewFieldsByBatch(camlQuery: string, allListFieldsToLowerHash: IDictionary<IFieldInfoEX>, batchSize: number): string[];
/** Size=S = 48×48 px, M = 72×72 px, L = 300×300 px */
export declare function UserPhoto(siteUrl: string, userName: string, size?: "S" | "M" | "L"): string;
export declare function IsFolderContentType(contentTypeId: string): boolean;
export declare enum PageContainerTypes {
M365SPFx = 0,
M365OOBListForm = 1,
SP2019SPFx = 2,
SP2019ListForm = 3
}
export declare function GetModernPageContainers(): {
mainContent: HTMLElement;
commandBar: HTMLElement;
type: PageContainerTypes;
};
export declare function AddCamlQueryFragmentToViewQuery(viewXml: string, queryFragmentXml: string): string;
export declare function IsUserEntityValueType(value: any): value is UserEntityValueType;
export declare function IsMultiUserEntityValueType(value: any[]): value is UserEntityValueType[];
export declare function IsUrlValueType(value: any): value is UrlValueType;
export declare function IsRetentionLabelValueType(value: any): value is RententionLabelFieldValueType;
export declare function isHostedInTeams(): boolean;
export declare function isClassicAppIframe(): boolean;
export declare function isNumberFieldType(fieldInfo: IFieldInfoEX): boolean;
export declare function isSharePointOnline(): Promise<boolean>;
export declare function isSharePointOnlineSync(): boolean;
export declare function isAppWeb(): Promise<boolean>;
export declare function isAppWebSync(): boolean;
export declare function isSPPageContextInfoReady(): Promise<boolean>;
export declare function isSPPageContextInfoReadySync(): boolean;
export declare function isExternalUser(loginName: string): boolean;