@pnp/common

  • Version 2.15.0
  • Published
  • 69.1 kB
  • 1 dependency
  • MIT license

Install

npm i @pnp/common
yarn add @pnp/common
pnpm add @pnp/common

Overview

pnp - provides shared functionality across all pnp libraries

Index

Variables

variable DefaultRuntime

const DefaultRuntime: Runtime;

    variable safeGlobal

    const safeGlobal: IGlobal;

      Functions

      function assign

      assign: <T extends ITypedHash<any> = any, S extends ITypedHash<any> = any>(
      target: T,
      source: S,
      noOverwrite?: boolean,
      filter?: (propName: string) => boolean
      ) => T & S;
      • Provides functionality to extend the given object by doing a shallow copy

        Parameter target

        The object to which properties will be copied

        Parameter source

        The source object from which properties will be copied

        Parameter noOverwrite

        If true existing properties on the target are not overwritten from the source

        Parameter filter

        If provided allows additional filtering on what properties are copied (propName: string) => boolean

      function combine

      combine: (...paths: string[]) => string;
      • Combines an arbitrary set of paths ensuring and normalizes the slashes

        Parameter paths

        0 to n path parts to combine

      function dateAdd

      dateAdd: (
      date: Date,
      interval: DateAddInterval,
      units: number
      ) => Date | undefined;
      • Adds a value to a date

        Parameter date

        The date to which we will add units, done in local time

        Parameter interval

        The name of the interval to add, one of: ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second']

        Parameter units

        The amount to add to date of the given interval

        http://stackoverflow.com/questions/1197928/how-to-add-30-minutes-to-a-javascript-date-object

      function getADALResource

      getADALResource: (url: string) => string;
      • Parses out the root of the request url to use as the resource when getting the token

        Parameter url

        The url to parse

      function getCtxCallback

      getCtxCallback: (context: any, method: Function, ...params: any[]) => Function;
      • Gets a callback function which will maintain context across async calls. Allows for the calling pattern getCtxCallback(thisobj, method, methodarg1, methodarg2, ...)

        Parameter context

        The object that will be the 'this' value in the callback

        Parameter method

        The method to which we will apply the context and parameters

        Parameter params

        Optional, additional arguments to supply to the wrapped method when it is invoked

      function getGUID

      getGUID: () => string;
      • Gets a random GUID value

        http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript

      function getHashCode

      getHashCode: (s: string) => number;
      • Generates a ~unique hash code

        From: https://stackoverflow.com/questions/6122571/simple-non-secure-hash-function-for-javascript

      function getRandomString

      getRandomString: (chars: number) => string;
      • Gets a random string of chars length

        https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript

        Parameter chars

        The length of the random string to generate

      function hOP

      hOP: (o: any, p: string) => boolean;
      • Shorthand for Object.hasOwnProperty

        Parameter o

        Object to check for

        Parameter p

        Name of the property

      function isArray

      isArray: (array: any) => boolean;
      • Returns

        whether the provided parameter is a JavaScript Array or not.

      function isFunc

      isFunc: (f: any) => boolean;
      • Determines if a given value is a function

        Parameter cf

        The thing to test for functionness

      function isUrlAbsolute

      isUrlAbsolute: (url: string) => boolean;
      • Determines if a given url is absolute

        Parameter url

        The url to check to see if it is absolute

      function jsS

      jsS: (o: any) => string;
      • Shorthand for JSON.stringify

        Parameter o

        Any type of object

      function mergeHeaders

      mergeHeaders: (target: Headers, source: HeadersInit) => void;

        function mergeMaps

        mergeMaps: <K = string, V = any>(
        target: Map<K, V>,
        ...maps: Map<K, V>[]
        ) => Map<K, V>;
        • Merges to Map instances together, overwriting values in target with matching keys, last in wins

          Parameter target

          map into which the other maps are merged

          Parameter maps

          One or more maps to merge into the target

        function mergeOptions

        mergeOptions: (target: IConfigOptions, source: IConfigOptions) => void;

          function objectDefinedNotNull

          objectDefinedNotNull: (obj: any) => boolean;
          • Determines if an object is both defined and not null

            Parameter obj

            Object to test

          function objectToMap

          objectToMap: <K, V>(o: any) => Map<K, V>;
          • Converts the supplied object to a map

            Parameter o

            The object to map

          function onRuntimeCreate

          onRuntimeCreate: (hook: (runtime: Runtime) => void) => void;

            function sanitizeGuid

            sanitizeGuid: (guid: string) => string;
            • Ensures guid values are represented consistently as "ea123463-137d-4ae3-89b8-cf3fc578ca05"

              Parameter guid

              The candidate guid

            function setup

            setup: <T = ILibraryConfiguration>(config: T, runtime?: Runtime) => void;

              function stringIsNullOrEmpty

              stringIsNullOrEmpty: (s: string) => boolean;
              • Determines if a string is null or empty or undefined

                Parameter s

                The string to test

              Classes

              class BearerTokenFetchClient

              class BearerTokenFetchClient extends FetchClient {}
              • Makes requests using the fetch API adding the supplied token to the Authorization header

              constructor

              constructor(token: string);

                property token

                token: string;

                  method fetch

                  fetch: (url: string, options?: IFetchOptions) => Promise<Response>;

                    class FetchClient

                    class FetchClient implements IHttpClientImpl {}
                    • Makes requests using the global/window fetch API

                    method fetch

                    fetch: (url: string, options: IFetchOptions) => Promise<Response>;

                      class LambdaFetchClient

                      class LambdaFetchClient extends BearerTokenFetchClient {}

                        constructor

                        constructor(tokenFactory: (parms: ILambdaTokenFactoryParams) => Promise<string>);

                          method fetch

                          fetch: (url: string, options: IFetchOptions) => Promise<Response>;
                          • Executes a fetch request using the supplied url and options

                            Parameter url

                            Absolute url of the request

                            Parameter options

                            Any options

                          class PnPClientStorage

                          class PnPClientStorage {}
                          • A class that will establish wrappers for both local and session storage

                          constructor

                          constructor(_local?: IPnPClientStore, _session?: IPnPClientStore);
                          • Creates a new instance of the PnPClientStorage class

                          property local

                          readonly local: IPnPClientStore;
                          • Provides access to the local storage of the browser

                          property session

                          readonly session: IPnPClientStore;
                          • Provides access to the session storage of the browser

                          class PnPClientStorageWrapper

                          class PnPClientStorageWrapper implements IPnPClientStore {}
                          • A wrapper class to provide a consistent interface to browser based storage

                          constructor

                          constructor(store: Storage, defaultTimeoutMinutes?: number);
                          • Creates a new instance of the PnPClientStorageWrapper class

                          property defaultTimeoutMinutes

                          defaultTimeoutMinutes: number;

                            property enabled

                            enabled: boolean;
                            • True if the wrapped storage is available; otherwise, false

                            method bind

                            static bind: (store: Storage) => IPnPClientStore;

                              method delete

                              delete: (key: string) => void;
                              • Deletes a value from the underlying storage

                                Parameter key

                                The key of the pair we want to remove from storage

                              method deleteExpired

                              deleteExpired: () => Promise<void>;
                              • Deletes any expired items placed in the store by the pnp library, leaves other items untouched

                              method get

                              get: <T>(key: string) => T | null;
                              • Get a value from storage, or null if that value does not exist

                                Parameter key

                                The key whose value we want to retrieve

                              method getOrPut

                              getOrPut: <T>(
                              key: string,
                              getter: () => Promise<T>,
                              expire?: Date
                              ) => Promise<T>;
                              • Gets an item from the underlying storage, or adds it if it does not exist using the supplied getter function

                                Parameter key

                                The key to use when storing the provided value

                                Parameter getter

                                A function which will upon execution provide the desired value

                                Parameter expire

                                Optional, if provided the expiration of the item, otherwise the default is used

                              method put

                              put: (key: string, o: any, expire?: Date) => void;
                              • Adds a value to the underlying storage

                                Parameter key

                                The key to use when storing the provided value

                                Parameter o

                                The value to store

                                Parameter expire

                                Optional, if provided the expiration of the item, otherwise the default is used

                              class Runtime

                              class Runtime {}

                                constructor

                                constructor(_v?: Map<string | number | symbol, any>);

                                  method assign

                                  assign: <T = ITypedHash<any>>(config: T) => void;
                                  • Parameter config

                                    The set of properties to add to this runtime instance

                                  method export

                                  export: () => Map<string | number | symbol, any>;
                                  • Exports the internal Map representing this runtime

                                  method get

                                  get: <T = ILibraryConfiguration, R = any>(key: keyof T) => R;
                                  • Gets a runtime value using T to define the available keys, and R to define the type returned by that key

                                    Parameter key

                                  class SPFxAdalClient

                                  class SPFxAdalClient extends LambdaFetchClient {}
                                  • Client wrapping the aadTokenProvider available from SPFx >= 1.6

                                  constructor

                                  constructor(context: ISPFXContext);
                                  • Parameter context

                                    provide the appropriate SPFx Context object

                                  method getToken

                                  getToken: (resource: string) => Promise<string>;
                                  • Gets an AAD token for the provided resource using the SPFx AADTokenProvider

                                    Parameter resource

                                    Resource for which a token is to be requested (ex: https://graph.microsoft.com)

                                  Interfaces

                                  interface IConfigOptions

                                  interface IConfigOptions {}

                                    property cache

                                    cache?:
                                    | 'default'
                                    | 'no-store'
                                    | 'reload'
                                    | 'no-cache'
                                    | 'force-cache'
                                    | 'only-if-cached';

                                      property credentials

                                      credentials?: 'omit' | 'same-origin' | 'include';

                                        property headers

                                        headers?:
                                        | string[][]
                                        | {
                                        [key: string]: string;
                                        }
                                        | Headers;

                                          property mode

                                          mode?: 'navigate' | 'same-origin' | 'no-cors' | 'cors';

                                            interface IFetchOptions

                                            interface IFetchOptions extends IConfigOptions {}

                                              property body

                                              body?: any;

                                                property method

                                                method?: string;

                                                  interface IGlobal

                                                  interface IGlobal {}

                                                    property location

                                                    location?: string;

                                                      method fetch

                                                      fetch: (url: string, options: any) => Promise<Response>;

                                                        interface IHttpClientImpl

                                                        interface IHttpClientImpl {}

                                                          method fetch

                                                          fetch: (url: string, options: IFetchOptions) => Promise<Response>;

                                                            interface ILambdaTokenFactoryParams

                                                            interface ILambdaTokenFactoryParams {}

                                                              property options

                                                              options: IFetchOptions;
                                                              • Any options supplied for the request

                                                              property url

                                                              url: string;
                                                              • Url to which the request for which we are requesting a token will be sent

                                                              interface ILibraryConfiguration

                                                              interface ILibraryConfiguration {}

                                                                property cacheExpirationIntervalMilliseconds

                                                                cacheExpirationIntervalMilliseconds?: number;
                                                                • Determines the interval in milliseconds at which the cache is checked to see if items have expired (min: 100)

                                                                property defaultCachingStore

                                                                defaultCachingStore?: 'session' | 'local';
                                                                • Defines the default store used by the usingCaching method, default: session

                                                                property defaultCachingTimeoutSeconds

                                                                defaultCachingTimeoutSeconds?: number;
                                                                • Defines the default timeout in seconds used by the usingCaching method, default 30

                                                                property enableCacheExpiration

                                                                enableCacheExpiration?: boolean;
                                                                • If true a timeout expired items will be removed from the cache in intervals determined by cacheTimeoutInterval

                                                                property globalCacheDisable

                                                                globalCacheDisable?: boolean;
                                                                • Allows caching to be global disabled, default: false

                                                                property ie11

                                                                ie11?: boolean;
                                                                • Used to place the library in ie11 compat mode. Some features may not work as expected

                                                                property spfxContext

                                                                spfxContext?: ISPFXContext;
                                                                • Used to supply the current context from an SPFx webpart to the library

                                                                interface IPnPClientStore

                                                                interface IPnPClientStore {}
                                                                • Interface which defines the operations provided by a client storage object

                                                                property enabled

                                                                enabled: boolean;
                                                                • True if the wrapped storage is available; otherwise, false

                                                                method delete

                                                                delete: (key: string) => void;
                                                                • Deletes a value from the underlying storage

                                                                  Parameter key

                                                                  The key of the pair we want to remove from storage

                                                                method deleteExpired

                                                                deleteExpired: () => Promise<void>;
                                                                • Removes any expired items placed in the store by the pnp library, leaves other items untouched

                                                                method get

                                                                get: (key: string) => any;
                                                                • Get a value from storage, or null if that value does not exist

                                                                  Parameter key

                                                                  The key whose value we want to retrieve

                                                                method getOrPut

                                                                getOrPut: <T>(
                                                                key: string,
                                                                getter: () => Promise<T>,
                                                                expire?: Date
                                                                ) => Promise<T>;
                                                                • Gets an item from the underlying storage, or adds it if it does not exist using the supplied getter function

                                                                  Parameter key

                                                                  The key to use when storing the provided value

                                                                  Parameter getter

                                                                  A function which will upon execution provide the desired value

                                                                  Parameter expire

                                                                  Optional, if provided the expiration of the item, otherwise the default is used

                                                                method put

                                                                put: (key: string, o: any, expire?: Date) => void;
                                                                • Adds a value to the underlying storage

                                                                  Parameter key

                                                                  The key to use when storing the provided value

                                                                  Parameter o

                                                                  The value to store

                                                                  Parameter expire

                                                                  Optional, if provided the expiration of the item, otherwise the default is used

                                                                interface IRequestClient

                                                                interface IRequestClient {}

                                                                  method delete

                                                                  delete: (url: string, options?: IFetchOptions) => Promise<Response>;

                                                                    method fetch

                                                                    fetch: (url: string, options?: IFetchOptions) => Promise<Response>;

                                                                      method fetchRaw

                                                                      fetchRaw: (url: string, options?: IFetchOptions) => Promise<Response>;

                                                                        method get

                                                                        get: (url: string, options?: IFetchOptions) => Promise<Response>;

                                                                          method patch

                                                                          patch: (url: string, options?: IFetchOptions) => Promise<Response>;

                                                                            method post

                                                                            post: (url: string, options?: IFetchOptions) => Promise<Response>;

                                                                              interface ISPFXContext

                                                                              interface ISPFXContext {}

                                                                                property aadTokenProviderFactory

                                                                                aadTokenProviderFactory?: {
                                                                                getTokenProvider(): Promise<{
                                                                                getToken(resource: string): Promise<string>;
                                                                                }>;
                                                                                };

                                                                                  property msGraphClientFactory

                                                                                  msGraphClientFactory?: {
                                                                                  getClient: () => Promise<any>;
                                                                                  };

                                                                                    property pageContext

                                                                                    pageContext: {
                                                                                    web: {
                                                                                    absoluteUrl: string;
                                                                                    };
                                                                                    };

                                                                                      interface ISPFXGraphHttpClient

                                                                                      interface ISPFXGraphHttpClient {}

                                                                                        method fetch

                                                                                        fetch: (url: string, configuration: any, options: any) => Promise<Response>;

                                                                                          interface ITypedHash

                                                                                          interface ITypedHash<T> {}
                                                                                          • Interface defining an object with a known property type

                                                                                          index signature

                                                                                          [key: string]: T;

                                                                                            Type Aliases

                                                                                            type DateAddInterval

                                                                                            type DateAddInterval =
                                                                                            | 'year'
                                                                                            | 'quarter'
                                                                                            | 'month'
                                                                                            | 'week'
                                                                                            | 'day'
                                                                                            | 'hour'
                                                                                            | 'minute'
                                                                                            | 'second';

                                                                                              Package Files (8)

                                                                                              Dependencies (1)

                                                                                              Dev Dependencies (0)

                                                                                              No dev dependencies.

                                                                                              Peer Dependencies (0)

                                                                                              No peer dependencies.

                                                                                              Badge

                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@pnp/common.

                                                                                              • Markdown
                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@pnp/common)
                                                                                              • HTML
                                                                                                <a href="https://www.jsdocs.io/package/@pnp/common"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>