Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @sap/cloud-sdk-core

Index

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

AuthenticationType

AuthenticationType: "NoAuthentication" | "BasicAuthentication" | "OAuth2SAMLBearerAssertion" | "OAuth2ClientCredentials" | "ClientCertificateAuthentication"

BatchResponse

DestinationOptions

DestinationRetrievalOptions

DestinationRetrievalOptions: DestinationCachingOptions & ResilienceOptions

Options to use while fetching destinations. Encompasses both DestinationCachingOptions and ResilienceOptions interfaces.

DestinationSelectionStrategy

DestinationSelectionStrategy: function

Type declaration

    • (allDestinations: AllDestinations, destinationName: string): Destination | null
    • Parameters

      • allDestinations: AllDestinations
      • destinationName: string

      Returns Destination | null

EdmType

EdmType: "Edm.String" | "Edm.Boolean" | "Edm.Guid" | "Edm.Decimal" | "Edm.Double" | "Edm.Single" | "Edm.Float" | "Edm.Int16" | "Edm.Int32" | "Edm.Int64" | "Edm.SByte" | "Edm.DateTime" | "Edm.DateTimeOffset" | "Edm.Time" | "Edm.Binary" | "Edm.Byte"

EntityBuilderType

EntityBuilderType<EntityT, EntityTypeForceMandatoryT>: object & EntityBuilder<EntityT, EntityTypeForceMandatoryT>

Type parameters

  • EntityT: Entity

  • EntityTypeForceMandatoryT

ExecuteHttpRequestFn

ExecuteHttpRequestFn: function

Type declaration

FieldType

FieldType: string | number | boolean | Time | Moment | BigNumber

Union type to represent all possible types of a field.

FilterOperator

FilterOperator: FilterOperatorString | FilterOperatorBoolean | FilterOperatorNumber

FilterOperatorByType

FilterOperatorByType<FieldT>: FilterOperatorByType<FieldT>

Type parameters

Filterable

Filterable<EntityT>: Filter<EntityT, FieldType> | FilterLink<EntityT, any> | FilterList<EntityT>

A union of all types that can be used for filtering.

Type parameters

  • EntityT: Entity

    Type of the entity to be filtered on

FunctionImportParameters

FunctionImportParameters<ParametersT>: object

Internal representation of all parameters of a function import as a map

Type parameters

  • ParametersT

    External represenation of all parameters

Type declaration

HttpRequest

JwtKeyMapping

JwtKeyMapping<TypescriptKeys, JwtKeys>: object

Type parameters

  • TypescriptKeys

  • JwtKeys

Type declaration

Orderable

Orderable<EntityT>: Order<EntityT> | OrderLink<EntityT, Entity>

A union of all types that can be used for ordering.

Type parameters

  • EntityT: Entity

    Type of the entity to be ordered

OrderableInput

OrderableInput<EntityT>: SimpleTypeFields<EntityT> | Link<EntityT, Entity> | ComplexTypePropertyFields<EntityT>

A union of all types that can be used as input for ordering.

Type parameters

  • EntityT: Entity

    Type of the entity to be ordered

RegisteredJWTClaims

Interface to represent the registered claims of a JWT.

RequestMethodType

RequestMethodType: "get" | "post" | "patch" | "delete" | "put"

Selectable

Selectable<EntityT>: SimpleTypeFields<EntityT> | Link<EntityT, any> | ComplexTypeField<EntityT> | CustomField<EntityT> | AllFields<EntityT>

Represents all selectables, i.e. everything that can be used in a .select statement.

Type parameters

  • EntityT: Entity

    Type of the entity to be selected on

Variables

Const clientCredentialsTokenCache

clientCredentialsTokenCache: object = ClientCredentialsTokenCache(new Cache<ClientCredentialsResponse>())

Type declaration

Const content_transfer_encoding_line

content_transfer_encoding_line: "Content-Transfer-Encoding: binary" = "Content-Transfer-Encoding: binary"

Const destinationCache

destinationCache: object = DestinationCache(new Cache<Destination>({ hours: 0, minutes: 5, seconds: 0 }))

Type declaration

Const executeHttpRequest

executeHttpRequest: (Anonymous function) = execute(executeWithAxios)

Builds a DestinationHttpRequestConfig for the given destination, merges it into the given requestConfig and executes it (using Axios).

param

A destination or a destination name and a JWT.

param

Any object representing an HTTP request.

returns

An HttpResponse.

Const http_version

http_version: "HTTP/1.1" = "HTTP/1.1"

Const part_content_type_line

part_content_type_line: "Content-Type: application/http" = "Content-Type: application/http"

Functions

addAuthorizationHeader

  • addAuthorizationHeader<RequestT>(request: ODataRequest<RequestT>, headers: MapType<string>): Promise<MapType<string>>
  • Adds authorization headers for a given ODataRequest to existing headers.

    Type parameters

    • RequestT: ODataRequestConfig

    Parameters

    • request: ODataRequest<RequestT>

      an ODataRequest.

    • headers: MapType<string>

      The headers that should be added to.

    Returns Promise<MapType<string>>

    The provided headers with the new authorization headers.

addCsrfTokenAndCookies

  • addCsrfTokenAndCookies<RequestT>(request: ODataRequest<RequestT>, headers: MapType<string>): Promise<MapType<string>>
  • Type parameters

    • RequestT: ODataRequestConfig

    Parameters

    Returns Promise<MapType<string>>

addDestinationToRequestConfig

  • Builds a DestinationHttpRequestConfig for the given destination and then merges it into the given requestConfig. NOTE: If the properties baseURL, httpClient, and httpsClient exist on the given requestConfig, they will be overwritten. Headers will be merged, whereby any headers built from the given destination will overwrite existing headers (e.g. the Authorization header).

    Type parameters

    • T

    Parameters

    Returns Promise<T & DestinationHttpRequestConfig>

    The given request config merged with the config built for the given destination.

addProxyConfiguration

  • Given a destination and a JWT (required for subscriber destinations), this function will add a proxy configuration to a destination. See also ProxyConfiguration.

    This function will reject if no connectivity service is bound, no XSUAA service with plan application is bound or the client credentials grant with the XSUAA service fails.

    Parameters

    • destination: Destination

      The destination to which the proxy configuration should be added.

    • Optional jwt: undefined | string

      The JWT of the current user.

    Returns Promise<Destination>

    A promise resolving to the destiation with the added proxy configuration.

Const addProxyHeaders

  • Parameters

    Returns (Anonymous function)

addSapClientHeader

  • addSapClientHeader(sapClient?: undefined | string): (Anonymous function)
  • Parameters

    • Optional sapClient: undefined | string

    Returns (Anonymous function)

alwaysProvider

  • alwaysProvider(allDestinations: AllDestinations, destinationName: string): Destination | null
  • Constraints the selection to provider destinations.

    Parameters

    • allDestinations: AllDestinations

      Retrieved destinations

    • destinationName: string

      Name of the destination to retrieve

    Returns Destination | null

    the destination to retrieve, returns null if no matched provider destination is found

alwaysSubscriber

  • alwaysSubscriber(allDestinations: AllDestinations, destinationName: string): Destination | null
  • Constraints the selection to subscriber destinations.

    Parameters

    • allDestinations: AllDestinations

      Retrieved destinations

    • destinationName: string

      Name of the destination to retrieve

    Returns Destination | null

    the destination to retrieve, returns null if no matched subscriber destination is found

and

  • Create a FilterList by combining Filterables with logical and.

    Example:

    Entity.requestBuilder()
     .getAll()
     .filter(and(filterExp1, filterExp2));

    Note that the GetAllRequestBuilder.filter method takes a rest parameter and thereby an array of filter expressions that are then combined conjunctively. As a consequence following is equivalent to the example above:

    Entity.requestBuilder()
     .getAll()
     .filter(filterExp1, filterExp2);

    Type parameters

    • EntityT: Entity

      Type of the entity to be filtered on

    Parameters

    • Rest ...expressions: Array<Filterable<EntityT>>

      Filterables to be combined with logical and

    Returns FilterList<EntityT>

    The newly created FilterList

asc

  • Create new Order by orderBy.fieldName in ascending order.

    Type parameters

    • EntityT: Entity

      Type of the entity to be ordered

    Parameters

    Returns Orderable<EntityT>

    New order

audiences

  • audiences(decodedToken: DecodedJWT): Set<string>
  • Retrieve the audiences of a decoded JWT based on the audiences and scopes in the token.

    Parameters

    • decodedToken: DecodedJWT

      Token to retrieve the audiences from.

    Returns Set<string>

    A set of audiences.

Const buildAndAddAuthorizationHeader

  • buildAndAddAuthorizationHeader(destination: Destination): (Anonymous function)
  • Adds authorization headers for a given destination to existing headers.

    Parameters

    Returns (Anonymous function)

    The provided headers with the new authorization headers.

buildHeaders

  • buildHeaders<RequestT>(request: ODataRequest<RequestT>): Promise<MapType<string>>
  • Create object containing all headers, including custom headers for a given OData request configuration and destination. Custom headers override duplicate headers.

    typeparam

    Type of the entity the headers are built for

    Type parameters

    • RequestT: ODataRequestConfig

    Parameters

    • request: ODataRequest<RequestT>

      OData request configuration to create headers for

    Returns Promise<MapType<string>>

    Key-value pairs where the key is the name of a header property and the value is the respective value

Const buildHeadersForDestination

  • buildHeadersForDestination(destination: Destination): Promise<MapType<string>>
  • Builds the authorization, proxy authorization and SAP client headers for a given destination.

    Parameters

    Returns Promise<MapType<string>>

    HTTP headers for the given destination.

buildHttpRequest

checkMandatoryValue

  • checkMandatoryValue<TypeScriptKeys, JwtKeys>(key: keyof TypeScriptKeys, mapping: JwtKeyMapping<TypeScriptKeys, JwtKeys>, decodedJWT: DecodedJWT): void
  • Checks if a given key is in the decoded JWT. If not an error is raised

    exception

    Error is thrown if the key is not present.

    Type parameters

    • TypeScriptKeys

    • JwtKeys

    Parameters

    Returns void

clientCredentialsGrant

  • clientCredentialsGrant(xsuaaUriOrCredentials: string | XsuaaServiceCredentials, clientCredentials: ClientCredentials, options?: ResilienceOptions, customBody?: MapType<any>): Promise<ClientCredentialsResponse>
  • Executes a client credentials grant request. If the first parameter is an instance of [[XsuaaServiceCredentials]], the response's access_token will be verified. If the first parameter is an URI, the response will not be verified.

    Parameters

    • xsuaaUriOrCredentials: string | XsuaaServiceCredentials

      The URI or the credentials of a XSUAA service instance.

    • clientCredentials: ClientCredentials

      Client credentials for which to request a token

    • Optional options: ResilienceOptions

      Options to use by retrieving access token

    • Default value customBody: MapType<any> = {}

      Object containing value required for the body request

    Returns Promise<ClientCredentialsResponse>

    A promise resolving to the response

createAgent

  • Parameters

    Returns Agent | Agent

createComplexType

  • createComplexType<ComplexT>(json: any, converters: any): ComplexT
  • Type parameters

    • ComplexT

    Parameters

    • json: any
    • converters: any

    Returns ComplexT

customAttributes

  • customAttributes(decodedToken: DecodedJWT): Map<string, string[]>
  • Extracts the custom attributes in the JWT

    Parameters

    • decodedToken: DecodedJWT

      Token to read the custom attributes

    Returns Map<string, string[]>

    custom attributes added by the xsuaa to the issued JWT.

decodeJwt

  • Decode JWT.

    Parameters

    • token: string

      JWT to be decoded

    Returns DecodedJWT

    Decoded payload.

desc

  • Create new Order by orderBy.fieldName in descending order.

    Type parameters

    • EntityT: Entity

      Type of the entity to be ordered

    Parameters

    Returns Orderable<EntityT>

    New order

deserializeEntity

  • deserializeEntity<EntityT, JsonT>(json: Partial<JsonT>, entityConstructor: Constructable<EntityT>, requestHeader?: any): EntityT
  • Converts the JSON payload for a single entity into an instance of the corresponding generated entity class. It sets the remote state to the data provided by the JSON payload. If a version identifier is found in the '__metadata' or in the request header, the method also sets it.

    Type parameters

    Parameters

    • json: Partial<JsonT>

      The JSON payload.

    • entityConstructor: Constructable<EntityT>

      The constructor function of the entity class.

    • Optional requestHeader: any

    Returns EntityT

    An instance of the entity class.

destinationForServiceBinding

  • destinationForServiceBinding(serviceInstanceName: string, options?: DestinationForServiceBindingsOptions): Destination
  • Tries to build a destination from a service binding with the given name. Throws an error if no services are bound at all, no service with the given name can be found, or the service type is not supported. The last error can be circumvent by using the second parameter to provide a custom function that transforms a service binding to a destination.

    Parameters

    • serviceInstanceName: string

      The name of the service.

    • Default value options: DestinationForServiceBindingsOptions = {}

      Options to customize the behavior of this function.

    Returns Destination

    A destination.

Const execute

  • Takes as paramter a function that expects an HttpRequest and returns a Promise of HttpResponse. Returns a function that takes a destination and a request, builds an HttpRequest from them, and calls the provided execute function.

    NOTE: If you simply want to execute a request without passing your own execute function, use executeHttpRequest instead!

    Parameters

    Returns (Anonymous function)

    A function expecting destination and a request.

extractCustomFields

  • extractCustomFields<EntityT, JsonT>(json: Partial<JsonT>, entityConstructor: Constructable<EntityT>): MapType<any>
  • Extracts all custom fields from the JSON payload for a single entity. In this context, a custom fields is every property that is not known in the corresponding entity class.

    Type parameters

    Parameters

    • json: Partial<JsonT>

      The JSON payload.

    • entityConstructor: Constructable<EntityT>

      The constructor function of the entity class.

    Returns MapType<any>

    An object containing the custom fields as key-value pairs.

fetchDestination

  • Fetches a specific destination by name from the given URI, including authorization tokens. For destinations with authenticationType OAuth2SAMLBearerAssertion, this call will trigger the OAuth2SAMLBearerFlow against the target destination.

    Parameters

    • destinationServiceUri: string

      The URI of the destination service

    • jwt: string

      The access token

    • destinationName: string

      The name of the desired destination

    • Optional options: ResilienceOptions

      Options to use by retrieving destinations

    Returns Promise<Destination>

    A Promise resolving to the destination

fetchInstanceDestinations

  • Fetches all instance destinations from the given URI.

    Parameters

    • destinationServiceUri: string

      The URI of the destination service

    • jwt: string

      The access token

    • Optional options: ResilienceOptions

      Options to use by retrieving destinations

    Returns Promise<Destination[]>

    A promise resolving to a list of instance destinations

fetchSubaccountDestinations

  • Fetches all subaccount destinations from the given URI.

    Parameters

    • destinationServiceUri: string

      The URI of the destination service

    • jwt: string

      The access token

    • Optional options: ResilienceOptions

      Options to use by retrieving destinations

    Returns Promise<Destination[]>

    A promise resolving to a list of subaccount destinations

fetchVerificationKeys

  • fetchVerificationKeys(xsuaaCredentials: XsuaaServiceCredentials): Promise<TokenKey[]>
  • fetchVerificationKeys(url: string, clientId: string, clientSecret: string): Promise<TokenKey[]>
  • Fetches verification keys from the XSUAA service for the given credentials.

    Parameters

    • xsuaaCredentials: XsuaaServiceCredentials

      Credentials of the XSUAA service instance.

    Returns Promise<TokenKey[]>

    An array of TokenKeys.

  • Fetches verification keys from the XSUAA service for the given URL, with the given pair of credentials.

    Parameters

    • url: string

      URL of the XSUAA service instance.

    • clientId: string

      Client ID of the XSUAA service instance.

    • clientSecret: string

      Client secret of the XSUAA service instance.

    Returns Promise<TokenKey[]>

    An array of TokenKeys.

getAgentConfig

  • getAgentConfig(destination: Destination): HttpAgentConfig | HttpsAgentConfig
  • Parameters

    Returns HttpAgentConfig | HttpsAgentConfig

getDestination

  • Builds a destination from one of three sources (in the given order):

    • from the environment variable "destinations"
    • from service bindings
    • from the destination service

    If you want to get a destination only from a specific source, use the corresponding function directly (getDestinationFromEnvByName, destinationForServiceBinding, getDestinationFromDestinationService).

    Parameters

    • name: string

      The name of the destination to be retrieved.

    • Default value options: DestinationOptions = {}

      Configuration for how to retrieve destinations from the destination service.

    Returns Promise<Destination | null>

    A promise returning the requested destination on success.

getDestinationBasicCredentials

  • getDestinationBasicCredentials(): BasicCredentials
  • Basic Credentials Getter from Destination service credentials needed for JWT generator.

    Returns BasicCredentials

    credentials.

getDestinationByName

  • getDestinationByName(name: string): Destination | null
  • deprecated

    Since v1.4.2. Use getDestinationFromEnvByName instead.

    Get a destination from the environment variables by name. Throws an error if there are multiple destinations with the same name. This is discouraged for productive use! Use destination-accessor/useOrFetchDestination for fetching destinations from the Cloud Foundry destination service.

    Parameters

    • name: string

      Name of the destination

    Returns Destination | null

    The requested destination if existent, otherwise null

getDestinationFromDestinationService

  • Retrieves a destination with the given name from the Cloud Foundry destination service. Returns null if no destination can be found. Requires the following service bindings: destination, XSUAA By default, selects subscriber over provider and instance over subaccount destinations.

    If the destinations are read from the environment, the jwt will be ignored.

    Parameters

    • name: string

      The name of the destination to be retrieved.

    • options: DestinationOptions

      Configuration for how to retrieve destinations from the destination service.

    Returns Promise<Destination | null>

    A promise returning the requested destination on success.

getDestinationFromEnvByName

  • getDestinationFromEnvByName(name: string): Destination | null
  • Get a destination from the environment variables by name. Throws an error if there are multiple destinations with the same name. This is discouraged for productive use! Use destination-accessor/useOrFetchDestination for fetching destinations from the Cloud Foundry destination service.

    Parameters

    • name: string

      Name of the destination

    Returns Destination | null

    The requested destination if existent, otherwise null

getDestinationOptions

  • deprecated

    Since v1.0.1. Use getDestination instead.

    Retrieves a destination with the given name from the Cloud Foundry destination service. Returns null if no destination can be found. Requires the following service bindings: destination, XSUAA By default, selects subscriber over provider and instance over subaccount destinations.

    If the destinations are read from the environment, the jwt will be ignored.

    Parameters

    • name: string

      The name of the destination to be retrieved.

    • Default value options: DestinationOptions = {}

      The options of the fetching query of the destination that include the JWT of the current request and the strategy for selecting a destination.

    Returns Promise<Destination | null>

    A promise returning the requested destination on success.

getDestinationServiceCredentials

  • getDestinationServiceCredentials(): any
  • First 'destination' credentials getter.

    Returns any

    'destination' credentials object. null: if there is no existing 'destination' credentials

getDestinationServiceCredentialsList

  • getDestinationServiceCredentialsList(): DestinationServiceCredentials[]
  • Destination credentials getter.

    returns:

    list of 'credentials' objects in 'destination' service.

    Returns DestinationServiceCredentials[]

getDestinationServiceUri

  • getDestinationServiceUri(): string | null
  • Destination URI getter NOTICE: If there exist more than one destination/uri, the function returns the first entry.

    returns:

    the first existing uri in destination. null: if no valid destination is found.

    Returns string | null

getDestinations

  • deprecated

    Since v1.4.2. Use getDestinationsFromEnv instead.

    Get all destinations from the environment variable "destinations". This is discouraged for productive use! Use destination-accessor/useOrFetchDestination for fetching destinations from the Cloud Foundry destination service.

    Returns Destination[]

    A list of destinations

getDestinationsFromEnv

  • Get all destinations from the environment variable "destinations". This is discouraged for productive use! Use destination-accessor/useOrFetchDestination for fetching destinations from the Cloud Foundry destination service.

    Returns Destination[]

    A list of destinations

getEntityKeys

  • getEntityKeys<EntityT>(entity: EntityT, entityConstructor: Constructable<EntityT>): MapType<any>
  • Helper function that maps an entity to its keys map with their original names.

    Type parameters

    Parameters

    • entity: EntityT

      Entity to map

    • entityConstructor: Constructable<EntityT>

      The constructor of the entity

    Returns MapType<any>

    object that includes all keys that represent given entity

getEnvironmentVariable

  • getEnvironmentVariable(name: string): string | undefined | null
  • Environment variables accessor.

    Parameters

    • name: string

      Environment variable name.

    Returns string | undefined | null

    Env variable value if defined. null: If not defined.

getOAuth2ClientCredentialsToken

  • getOAuth2ClientCredentialsToken(destination: Destination): Promise<ClientCredentialsResponse>
  • Retrieves an access token required for "OAuth2ClientCredentials" destination authentication type.

    Parameters

    • destination: Destination

      A destination having OAuth2ClientCredentials authentication type

    Returns Promise<ClientCredentialsResponse>

    A promise returning the requested access token on success.

getQueryParametersForFilter

  • getQueryParametersForFilter<EntityT>(filter: Filterable<EntityT>, entityConstructor: Constructable<EntityT>): Partial<object>
  • Get an object containing the given filter as query parameter, or an empty object if none was given.

    Type parameters

    • EntityT: Entity

      Type of the entity to filter on

    Parameters

    • filter: Filterable<EntityT>

      The filter to transform to a query parameter

    • entityConstructor: Constructable<EntityT>

      Constructor type of the entity to filter on

    Returns Partial<object>

    } An object containing the query parameter or an empty object

getQueryParametersForOrderBy

  • getQueryParametersForOrderBy<EntityT>(orderBy: Array<Orderable<EntityT>>): Partial<object>
  • Get an object containing the given order bys as query parameter, or an empty object if none was given.

    Type parameters

    • EntityT: Entity

      Type of the entity to order

    Parameters

    • orderBy: Array<Orderable<EntityT>>

      A list of orderables to get the query parameters for

    Returns Partial<object>

    } An object containing the query parameter or an empty object

getQueryParametersForSelection

  • getQueryParametersForSelection<EntityT>(selects: Array<Selectable<EntityT>>): Partial<object>
  • Get an object containing the given Selectables as query parameter, or an empty object if none were given. This retrieves where in addition to the selection (select) there is also an expansion (expand) needed.

    Type parameters

    • EntityT: Entity

      Type of the entity to get the selection for

    Parameters

    • selects: Array<Selectable<EntityT>>

      The list of selectables to be transformed to query parameters

    Returns Partial<object>

    An object containing the query parameters or an empty object

getRequestLine

  • Generate the request line, containing method, url and http version from the request builder, e.g.: GET /sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartnerAddress?$format=json&$top=1 HTTP/1.1

    Parameters

    Returns string

    the generated request line.

getResourcePathForKeys

  • getResourcePathForKeys<EntityT>(keys: MapType<FieldType>, entityConstructor: Constructable<EntityT>): string
  • Get the resource path of an entity specified by key-value pairs.

    Type parameters

    • EntityT: Entity

      Type of the entity to get the resource path for

    Parameters

    • keys: MapType<FieldType>

      Key-value pairs where the key is the name of a key property of the given entity and the value is the respective value

    • entityConstructor: Constructable<EntityT>

      Constructor type of the entity to get the resource path for

    Returns string

    The path to the resource

getServiceCredentialsList

  • getServiceCredentialsList(service: string): any[]
  • Credentials list getter for a given service.

    Parameters

    • service: string

    Returns any[]

    Fetched credentials objects of existing service in 'VCAP_SERVICES'.

getServiceList

  • getServiceList(service: string): any[]
  • Services getter for a given service.

    Parameters

    • service: string

      Service name.

    Returns any[]

    List of service bindings of the given type. Returns an empty array if no service binding exists for the given type.

getUrlProtocol

  • Parameters

    Returns Protocol | undefined

getVcapService

  • getVcapService(): MapType<any> | null
  • 'VCAP_SERVICES' Getter from environment variables. This function returns the VCAP_SERVICES as object or null if it is not defined (i.e. no services are bound to the application).

    returns:

    'VCAP_SERVICES' found in environment variables or null if not defined. The key denotes the name ov the service and the value is the definition.

    Returns MapType<any> | null

getXsuaaServiceCredentials

  • getXsuaaServiceCredentials(token?: DecodedJWT | string): XsuaaServiceCredentials
  • Takes a decoded JWT and uses the client_id and audience claims to determine the XSUAA service instance that issued the JWT. Returns the credentials if a match is found otherwise returns null. If no decoded JWT is specified, then returns the first existing XSUAA credential service plan "application".

    Parameters

    • Optional token: DecodedJWT | string

      Either an encoded or decoded JWT.

    Returns XsuaaServiceCredentials

    The credentials for a match, otherwise null.

headerForClientCredentials

  • headerForClientCredentials(clientCredentials: ClientCredentials): string
  • Parameters

    • clientCredentials: ClientCredentials

    Returns string

isDestination

  • isDestination(destination: any): boolean
  • Parameters

    • destination: any

    Returns boolean

isDestinationNameAndJwt

  • isDestinationNameAndJwt(destination: any): boolean
  • Parameters

    • destination: any

    Returns boolean

isFilter

  • isFilter<T, FieldT>(filterable: Filterable<T>): boolean
  • Type parameters

    Parameters

    Returns boolean

isFilterLink

  • isFilterLink<EntityT, LinkedT>(filterable: Filterable<EntityT>): boolean
  • Type parameters

    Parameters

    Returns boolean

isFilterList

  • isFilterList<T>(filterable: Filterable<T>): boolean
  • Type parameters

    Parameters

    Returns boolean

isIdenticalTenant

  • Compare two decoded JWTs based on their tenantIds.

    Parameters

    Returns boolean

    Whether the tenant is identical.

issuerUrl

  • issuerUrl(decodedToken: DecodedJWT): string | undefined
  • Get the issuer url of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the issuer url from.

    Returns string | undefined

    The issuer url if available.

or

  • Create a FilterList by combining Filterables with logical or.

    Example:

    Entity.requestBuilder()
     .getAll()
     .filter(or(filterExp1, filterExp2));

    Type parameters

    • EntityT: Entity

      Type of the entity to be filtered on

    Parameters

    • Rest ...expressions: Array<Filterable<EntityT>>

      Filterables to be combined with logical or

    Returns FilterList<EntityT>

    The newly created FilterList

parseDestination

  • parseDestination(destinationJson: DestinationJSON | DestinationConfiguration): Destination
  • Takes a JSON object returned by any of the calls to the destination service and returns an SDK compatible destination object.

    Parameters

    • destinationJson: DestinationJSON | DestinationConfiguration

      A JSON object returned by the destination service.

    Returns Destination

    An SDK compatible destination object.

proxyAgent

  • proxyAgent(proxyHost: string, proxyPort: number): HttpProxyAgent
  • Parameters

    • proxyHost: string
    • proxyPort: number

    Returns HttpProxyAgent

refreshTokenGrant

  • refreshTokenGrant(xsuaaUriOrCredentials: string | XsuaaServiceCredentials, clientCredentials: ClientCredentials, refreshToken: string, options?: ResilienceOptions): Promise<UserTokenResponse>
  • Executes a refresh token grant request against the given URI. If the first parameter is an instance of [[XsuaaServiceCredentials]], the response's access_token will be verified. If the first parameter is an URI, the response will not be verified.

    Parameters

    • xsuaaUriOrCredentials: string | XsuaaServiceCredentials

      The URI or the credentials of a XSUAA service instance.

    • clientCredentials: ClientCredentials

      The credentials (client_id, client_secret) if the target XSUAA service instance.

    • refreshToken: string

      The refresh token that should be used to generate a new access token.

    • Optional options: ResilienceOptions

      Options to use by retrieving access token.

    Returns Promise<UserTokenResponse>

    A promise resolving to the response of the XSUAA service.

retrieveJwt

  • retrieveJwt(req: IncomingMessage): string | undefined
  • Retrieve JWT from a request that is based on the node IncomingMessage. Fails if no authorization header is given or has the wrong format. Expected format is 'Bearer '.

    Parameters

    • req: IncomingMessage

      Request to retrieve the JWT from

    Returns string | undefined

    JWT found in header

sanitizeDestination

  • sanitizeDestination(destination: MapType<any>): Destination
  • Takes an existing or a parsed destination and returns an SDK compatible destination object.

    Parameters

    • destination: MapType<any>

      A JSON object returned by the destination service.

    Returns Destination

    An SDK compatible destination object.

secondsToTime

  • secondsToTime(n: number): Time
  • Converts from seconds to time in HH:MM:SS format.

    Parameters

    • n: number

      Number of seconds to convert (should be positive).

    Returns Time

    Time The converted time from the given number of seconds

serializeEntity

  • serializeEntity<EntityT>(entity: EntityT, entityConstructor: Constructable<EntityT>): MapType<any>
  • Converts an instance of an entity class into a JSON payload to be sent to an OData service.

    Type parameters

    Parameters

    • entity: EntityT

      An instance of an entity.

    • entityConstructor: Constructable<EntityT>

      The constructor function of that entity.

    Returns MapType<any>

    JSON.

serializeEntityNonCustomFields

  • serializeEntityNonCustomFields<EntityT>(entity: EntityT, entityConstructor: Constructable<EntityT>): MapType<any>
  • Converts an instance of an entity class into a JSON payload to be sent to an OData service, ignoring custom fields.

    Type parameters

    Parameters

    • entity: EntityT

      An instance of an entity.

    • entityConstructor: Constructable<EntityT>

      The constructor function of that entity.

    Returns MapType<any>

    JSON.

subscriberFirst

  • subscriberFirst(allDestinations: AllDestinations, destinationName: string): Destination | null
  • Prioritizes the selection of subscriber destinations.

    Parameters

    • allDestinations: AllDestinations

      Retrieved destinations

    • destinationName: string

      Name of the destination to retrieve

    Returns Destination | null

    the destination to retrieve, returns null if no matched destination is found

tenantFromJwt

  • Creates a tenant object from the decoded JWT.

    exception

    Error Raised if no id is found in the decoded JWT.

    Parameters

    Returns Tenant

    Representation of the tenant.

tenantId

  • tenantId(decodedToken: DecodedJWT): string | undefined
  • Get the tenant id of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the tenant id from.

    Returns string | undefined

    The tenant id if available.

tenantName

  • tenantName(decodedToken: DecodedJWT): string | undefined
  • Get the tenant name of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the tenant id from.

    Returns string | undefined

    The tenant id if available.

timeToSeconds

  • timeToSeconds(time: Time): number
  • Converts the given time to seconds in positive numerical format.

    Parameters

    • time: Time

      Time to convert.

    Returns number

    number Time in seconds.

toBatchChangeSet

  • Build the change set payload as the partial payload of the batch request.

    Parameters

    Returns string | undefined

    The generated payload from the given change set.

toBatchRetrieveBody

  • Build a string as the request body of the retrieve request. Below is an example of the generated body, where the two empty line are mandatory to make the request valid. * example starts * Content-Type: application/http Content-Transfer-Encoding: binary

    GET /SomeUrl/API_BUSINESS_PARTNER/A_BusinessPartnerBank?$format=json&$top=1 HTTP/1.1

    * example ends *

    Parameters

    Returns string

    The request body.

toDestinationNameUrl

toPropertyFormat

  • toPropertyFormat(str: string): string
  • Converts a string to the format used by properties. Use this for serialization in the VDM.

    Parameters

    • str: string

      The string to be transformed.

    Returns string

    The transformed string.

toStaticPropertyFormat

  • toStaticPropertyFormat(str: string): string
  • Converts a string to the case used by static helpers in the VDM. Use this for serialization in the VDM.

    Parameters

    • str: string

      The string to be transformed.

    Returns string

    The input string in the case used by static helpers in the VDM.

toTitleFormat

  • toTitleFormat(str: string): string
  • Converts a string to a human readable format, e.g. it transforms to_BusinessPartner to To Business Partner. Use this for serialization in the VDM.

    Parameters

    • str: string

      The string to be transformed.

    Returns string

    The transformed string.

toTypeNameFormat

  • toTypeNameFormat(str: string): string
  • Converts a string to the format used by properties. Use this for serialization in the VDM.

    Parameters

    • str: string

      The string to be transformed.

    Returns string

    The transformed string.

transformReturnValueForComplexType

  • transformReturnValueForComplexType<ReturnT>(data: any, builderFn: function): ReturnT
  • Type parameters

    • ReturnT

    Parameters

    • data: any
    • builderFn: function
        • (data: any): ReturnT
        • Parameters

          • data: any

          Returns ReturnT

    Returns ReturnT

transformReturnValueForComplexTypeList

  • transformReturnValueForComplexTypeList<ReturnT>(data: any, builderFn: function): ReturnT[]
  • Type parameters

    • ReturnT

    Parameters

    • data: any
    • builderFn: function
        • (data: any): ReturnT
        • Parameters

          • data: any

          Returns ReturnT

    Returns ReturnT[]

transformReturnValueForEdmType

  • transformReturnValueForEdmType<ReturnT>(data: any, edmType: EdmType): ReturnT
  • Type parameters

    Parameters

    Returns ReturnT

transformReturnValueForEdmTypeList

  • transformReturnValueForEdmTypeList<ReturnT>(data: any, edmType: EdmType): ReturnT
  • Type parameters

    Parameters

    Returns ReturnT

transformReturnValueForEntity

  • transformReturnValueForEntity<ReturnT>(data: any, entityConstructor: Constructable<ReturnT>): ReturnT
  • Type parameters

    Parameters

    • data: any
    • entityConstructor: Constructable<ReturnT>

    Returns ReturnT

transformReturnValueForEntityList

  • transformReturnValueForEntityList<ReturnT>(data: any, entityConstructor: Constructable<ReturnT>): ReturnT[]
  • Type parameters

    Parameters

    • data: any
    • entityConstructor: Constructable<ReturnT>

    Returns ReturnT[]

useOrFetchDestination

  • Returns the parameter if it is a destination, calls getDestination otherwise (which will try to fetch the destination from the Cloud Foundry destination service).

    Fetching a destination requires:

    • a binding to exactly one XSUAA service instance with service plan "application"
    • a binding to a destination service instance

    If either of the prerequisites is not met or one of the services returns an error, this function will either throw an error or return a promise that rejects.

    Parameters

    Returns Promise<Destination | null>

    A promise resolving to the requested destination on success.

userEmail

  • userEmail(decodedToken: DecodedJWT): string | undefined
  • Get the user's email of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the user id from.

    Returns string | undefined

    The user id if available.

userFamilyName

  • userFamilyName(decodedToken: DecodedJWT): string | undefined
  • Get the user's family name of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the user id from.

    Returns string | undefined

    The user id if available.

userFromJwt

  • Creates a user object from the decoded JWT.

    exception

    Error Raised if no id is found in the decoded JWT.

    Parameters

    Returns User

    Representation of the user

userGivenName

  • userGivenName(decodedToken: DecodedJWT): string | undefined
  • Get the user's given name of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the user id from.

    Returns string | undefined

    The user id if available.

userId

  • userId(decodedToken: DecodedJWT): string | undefined
  • Get the user id of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the user id from.

    Returns string | undefined

    The user id if available.

userName

  • userName(decodedToken: DecodedJWT): string | undefined
  • Get the user name of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the user id from.

    Returns string | undefined

    The user id if available.

userScopes

  • Get the user's scopes of a decoded JWT.

    Parameters

    • decodedToken: DecodedJWT

      Token to read the user id from.

    Returns Scope[] | []

    The user id if available.

userTokenGrant

  • userTokenGrant(xsuaaUri: string, userJwt: string, clientId: string, options?: ResilienceOptions): Promise<UserTokenResponse>
  • Executes a user token grant request against the given URI.

    Parameters

    • xsuaaUri: string

      The URI of the target XSUAA service instance.

    • userJwt: string

      The JWT of the user on whose behalf the request is executed.

    • clientId: string

      The client_id of the target XSUAA service instance.

    • Optional options: ResilienceOptions

      Options to use by retrieving access token

    Returns Promise<UserTokenResponse>

    A promise resolving to the response of the XSUAA service.

verifyJwt

  • Verifies the given JWT and returns the decoded payload.

    Parameters

    • token: string

      JWT to be verified

    • Optional options: VerifyJwtOptions

      Options to control certain aspects of JWT verification behavior.

    Returns Promise<DecodedJWT>

    A Promise to the decoded and verified JWT.

verifyJwtWithKey

  • verifyJwtWithKey(token: string, key: string): Promise<DecodedJWT>
  • Verifies the given JWT with the given key and returns the decoded payload.

    Parameters

    • token: string

      JWT to be verified

    • key: string

      Key to use for verification

    Returns Promise<DecodedJWT>

    A Promise to the decoded and verified JWT.

wrapJwtInHeader

  • wrapJwtInHeader(token: string): AxiosRequestConfig
  • Wraps the access token in header's authorization.

    Parameters

    • token: string

      Token to attach in request header

    Returns AxiosRequestConfig

    The request header that holds the access token

Object literals

Const DestinationSelectionStrategies

DestinationSelectionStrategies: object

Selector of destination selection strategies. See alwaysProvider, alwaysSubscriber and subscriberFirst for more information available selection strategies.

alwaysProvider

alwaysProvider: alwaysProvider

alwaysSubscriber

alwaysSubscriber: alwaysSubscriber

subscriberFirst

subscriberFirst: subscriberFirst

Const EnvironmentAccessor

EnvironmentAccessor: object
deprecated

Use directly exported functions instead

getDestinationBasicCredentials

getDestinationBasicCredentials: getDestinationBasicCredentials

getDestinationServiceCredentials

getDestinationServiceCredentials: getDestinationServiceCredentials

getDestinationServiceCredentialsList

getDestinationServiceCredentialsList: getDestinationServiceCredentialsList

getDestinationServiceUri

getDestinationServiceUri: getDestinationServiceUri

getEnvironmentVariable

getEnvironmentVariable: getEnvironmentVariable

getServiceCredentialsList

getServiceCredentialsList: getServiceCredentialsList

getServiceList

getServiceList: getServiceList

getVcapService

getVcapService: getVcapService

getXsuaaServiceCredentials

getXsuaaServiceCredentials: getXsuaaServiceCredentials

Const circuitBreakerDefaultOptions

circuitBreakerDefaultOptions: object

errorThresholdPercentage

errorThresholdPercentage: number = 50

resetTimeout

resetTimeout: number = 30000

timeout

timeout: number = 10000

Const mapping

mapping: object

Mapping between key name in the Tenant and key name in decoded JWT and the

id

id: object

extractorFunction

extractorFunction: tenantId = tenantId

keyInJwt

keyInJwt: "zid" = "zid"

name

name: object

extractorFunction

extractorFunction: tenantName = tenantName

keyInJwt

keyInJwt: "zdn" = "zdn"

Const mapping

mapping: object

Mapping between key name in the User and key name in decoded JWT and the

customAttributes

customAttributes: object

extractorFunction

extractorFunction: customAttributes = customAttributes

keyInJwt

keyInJwt: "xs.user.attributes" = "xs.user.attributes"

email

email: object

extractorFunction

extractorFunction: userEmail = userEmail

keyInJwt

keyInJwt: "email" = "email"

familyName

familyName: object

extractorFunction

extractorFunction: userFamilyName = userFamilyName

keyInJwt

keyInJwt: "family_name" = "family_name"

givenName

givenName: object

extractorFunction

extractorFunction: userGivenName = userGivenName

keyInJwt

keyInJwt: "given_name" = "given_name"

id

id: object

extractorFunction

extractorFunction: userId = userId

keyInJwt

keyInJwt: "user_id" = "user_id"

scopes

scopes: object

extractorFunction

extractorFunction: userScopes = userScopes

keyInJwt

keyInJwt: "scope" = "scope"

userName

userName: object

extractorFunction

extractorFunction: userName = userName

keyInJwt

keyInJwt: "user_name" = "user_name"