Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @sap/cloud-sdk-core

cloud-sdk-core

This is the core of the SAP S/4HANA Cloud SDK for JavaScript. It contains the core functionality for the Virtual Data Model (VDM) as well as the Cloud Platform abstractions.

Index

Enumerations

Classes

Interfaces

Type aliases

Functions

Type aliases

AuthenticationType

AuthenticationType: "NoAuthentication" | "BasicAuthentication" | "OAuth2SAMLBearerAssertion"

DestinationSelectionStrategy

DestinationSelectionStrategy: function

Type declaration

    • (AllDestinations: any, string: any): Destination | null
    • Parameters

      • AllDestinations: any
      • string: any

      Returns Destination | null

EdmType

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

EntityBuilderType

EntityBuilderType: object & EntityBuilder<EntityT, JsonT>

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: FilterOperatorByType<FieldT>

Filterable

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

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

Orderable

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

RequestMethodType

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

Functions

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

    • orderBy: Selectable<EntityT>

      Selectable (field or link) to be ordered by

    Returns Orderable<EntityT>

    New order

buildHeaders

  • buildHeaders<EntityT, RequestT>(request: ODataRequest<EntityT, 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.

    Type parameters

    Parameters

    • request: ODataRequest<EntityT, 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

clientCredentialsGrant

  • Executes a client credentials grant request against the given URI.

    Parameters

    • xsuaaUri: string

      The URI of the XSUAA service

    • clientCredentials: ClientCredentials

      An instance of

    Returns Promise<ClientCredentialsResponse>

    A promise resolving to the response

convertToUriFormat

  • convertToUriFormat(value: any, edmType: EdmType): string
  • Parameters

    Returns string

desc

  • Create new Order by orderBy.fieldName in descending order

    Type parameters

    • EntityT: Entity

      Type of the entity to be ordered

    Parameters

    • orderBy: Selectable<EntityT>

      Selectable (field or link) to be ordered by

    Returns Orderable<EntityT>

    New order

edmToTs

  • edmToTs(value: any, edmType: EdmType): any
  • Parameters

    Returns any

fetchDestination

  • fetchDestination(destinationServiceUri: string, jwt: string, destinationName: string): Promise<Destination>
  • 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

    Returns Promise<Destination>

    A Promise resolving to the destination

fetchInstanceDestinations

  • fetchInstanceDestinations(destinationServiceUri: string, jwt: string): Promise<Destination[]>
  • Fetches all instance destinations from the given URI.

    Parameters

    • destinationServiceUri: string

      The URI of the destination service

    • jwt: string

      The access token

    Returns Promise<Destination[]>

    A promise resolving to a list of instance destinations

fetchSubaccountDestinations

  • fetchSubaccountDestinations(destinationServiceUri: string, jwt: string): Promise<Destination[]>
  • Fetches all subaccount destinations from the given URI.

    Parameters

    • destinationServiceUri: string

      The URI of the destination service

    • jwt: string

      The access token

    Returns Promise<Destination[]>

    A promise resolving to a list of subaccount destinations

getDestinationByName

  • getDestinationByName(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.

    Parameters

    • name: string

      Name of the destination

    Returns Destination | null

    The requested destination if existent, otherwise null

getDestinationConfig

  • Parameters

    • Default value dest: string | Destination = "ErpQueryEndpoint"

    Returns Destination | null

getDestinationOptions

  • getDestinationOptions(name: string, options?: DestinationOptions): Promise<Destination | null>
  • 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.

    export

    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.

getDestinations

  • Get all destination from the environment variable

    Returns Destination[]

    A list of destinations

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

getResourcePathForKeys

  • 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

isExistentProperty

  • isExistentProperty<EntityT, LinkedEntityT>(json: any, link: Link<EntityT, LinkedEntityT>): boolean
  • Type parameters

    Parameters

    • json: any
    • link: Link<EntityT, LinkedEntityT>

    Returns boolean

isExpandedProperty

  • isExpandedProperty<EntityT, LinkedEntityT>(json: any, link: Link<EntityT, LinkedEntityT>): boolean
  • Type parameters

    Parameters

    • json: any
    • link: Link<EntityT, LinkedEntityT>

    Returns boolean

isSelectedProperty

  • isSelectedProperty<EntityT>(json: any, selectable: Selectable<EntityT>): any
  • Type parameters

    Parameters

    Returns any

Const nonEnumerable

  • nonEnumerable(target: any, propertyKey: string): void
  • Parameters

    • target: any
    • propertyKey: string

    Returns void

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.

    export

    Parameters

    • destinationJson: DestinationJSON | DestinationConfiguration

      A JSON object returned by the destination service.

    Returns Destination

    An SDK compatible destination object.

parseNumber

  • parseNumber(value: string): number
  • Parameters

    • value: string

    Returns number

refreshTokenGrant

  • Executes a refresh token grant request against the given URI.

    Parameters

    • xsuaaUri: string

      The URI of the target 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.

    Returns Promise<UserTokenResponse>

    A promise resolving to the response of the XSUAA service.

removeLeadingSlashes

  • removeLeadingSlashes(path: string): string
  • Parameters

    • path: string

    Returns string

removeSlashes

  • removeSlashes(path: string): string
  • Parameters

    • path: string

    Returns string

removeTrailingSlashes

  • removeTrailingSlashes(path: string): string
  • Parameters

    • path: string

    Returns string

replaceSubdomain

  • replaceSubdomain(issuerUrl: string, xsuaaUrl: string): string
  • Parameters

    • issuerUrl: string
    • xsuaaUrl: string

    Returns string

sanitizeDestination

  • Takes an existing or a parsed destination and returns an SDK compatible destination object.

    export

    Parameters

    • destination: MapType<any>

      A JSON object returned by the destination service.

    Returns Destination

    An SDK compatible destination object.

serializeEntity

  • serializeEntity<EntityT>(entity: EntityT, entityConstructor: Constructable<EntityT>): object
  • Type parameters

    Parameters

    Returns object

    • [p: string]: any

subscriberFirst

  • Parameters

    Returns Destination | null

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.

toTitleCase

  • toTitleCase(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.

tsToEdm

  • tsToEdm(value: any, edmType: EdmType): string
  • Parameters

    Returns string

useOrFetchDestination

  • Returns the parameter if it is a destination, fetches one with the given name otherwise.

    This 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.

    export

    Parameters

    Returns Promise<Destination>

    A promise resolving to the requested destination on success.

userTokenGrant

  • userTokenGrant(xsuaaUri: string, userJwt: string, clientId: string): 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.

    Returns Promise<UserTokenResponse>

    A promise resolving to the response of the XSUAA service.