Represents the Vattenfall Service, providing methods to interact with the service's API.

Constructors

  • Constructs an instance of the class with a unique transaction ID, username, and password.

    Parameters

    • username: string

      The username for the instance.

    • password: string

      The password for the instance.

    Returns VattenfallService

Properties

_access_token_data?: AccessTokenData

Optional variable _access_token_data which holds the access token information.

This variable may contain the data structure defined by the AccessTokenData type in the Types namespace. It is used to store the details of an access token, which typically includes properties such as the token value, expiry time, and possibly other metadata related to authentication and authorization.

_debug_logging_enabled: boolean = false

A boolean flag that indicates whether debug logging is enabled. When set to true, the application will output additional debug information to the logs. This can be useful for troubleshooting and development purposes. Default value is false.

_parent_log_id?: string

Represents the unique identifier of the parent log entry. This variable is optional, meaning it might be undefined. If present, it denotes the ID of the log entry that is the parent in a hierarchical log structure, aiding in tracking relational log data.

_password: string

Represents the password of a user. This string is used for authenticating the user. It should be kept confidential and secured.

_properties?: ServiceProperties

Represents the properties associated with the service, retrieved at instantiation time from service_properties_uri.

_transaction_id: string

A unique identifier for a transaction. This ID is used to track and reference individual transactions within the system. It ensures that each transaction can be distinctly identified.

_username: string

Represents the username of a user in the system. This is a string that uniquely identifies a user.

access_token_ttl_seconds: number = ...

The number of seconds that an access token remains valid.

This value determines the time-to-live (TTL) for access tokens, ensuring they expire after a certain period of inactivity or usage. Typically used to control session timeouts and enhance security.

api_client: string = "KSO"

The client's API identifier used for making requests. This string is typically configured to represent the name or key associated with the API client in use.

api_tenant: string = "VESALES"

A string representing the tenant identifier for the API. This tenant id differentiates the API usage context and allows the system to apply the appropriate configurations and access controls.

Example: "VESALES"

api_version: number = 1.3

The version number of the API that the application is currently using. This variable helps in managing and differentiating between different iterations or releases of the API.

service_properties_uri = "https://service.vattenfall.de/properties.json"

The URI that points to the properties configuration file for the Vattenfall service. This URI is used to fetch various properties and settings required for the service's operation.

Accessors

  • get password(): string
  • Retrieves the current password.

    Returns string

    The current password.

  • get username(): string
  • Gets the current username.

    Returns string

    The current username.

Methods

  • Processes the HTTP response and returns it in the specified format.

    Type Parameters

    Parameters

    • response: Response

      The HTTP response to process.

    Returns Promise<R>

    The processed response in the specified format.

  • Makes an HTTP request to the specified URI with the given method and data. This is an internal method that returns a Response object.

    Type Parameters

    Parameters

    • uri: string

      The endpoint URI to which the request is made.

    • method: HTTPMethod = Types.HTTPMethod.GET

      The HTTP method to be used for the request (e.g., GET, POST).

    • Optionaldata: D

      The data to be sent with the request, if applicable.

    Returns Promise<Response>

    A promise that resolves to the response of the request.

  • Logs the provided data to the console if debug logging is enabled.

    Parameters

    • Rest...data: unknown[]

      The data to be logged.

    Returns void

  • Deletes a resource at the specified URI.

    Type Parameters

    Parameters

    • uri: string

      The URI of the resource to be deleted.

    Returns Promise<R>

    A promise resolving to the API response.

  • Throws a VattenfallApiError with the given message.

    Parameters

    • message: string

      The error message to be included in the VattenfallApiError.

    Returns never

    This method does not return as it always throws an error.

  • Makes an HTTP GET request to the given URI and returns the response.

    Type Parameters

    Parameters

    • uri: string

      The URI to send the GET request to.

    Returns Promise<R>

    A promise that resolves to the API response.

  • Retrieves an access token for the user. If the current access token is expired and the force parameter is set to false, it refreshes the access token.

    Parameters

    • force: boolean = false

      Whether to forcefully obtain a new access token even if the current one is not expired.

    Returns Promise<string>

    A promise that resolves to the access token string.

  • Fetches the account information from the server.

    Returns Promise<Account>

    A promise that resolves to the account information.

  • Retrieves contract data based on the provided contract ID.

    Parameters

    • contract_id: string

      The ID of the contract to retrieve.

    Returns Promise<ContractResponse>

    A promise that resolves with the contract data.

  • Fetches the meter readings for a given contract ID.

    Parameters

    • contract_id: string

      The ID of the contract for which meter readings are being requested.

    Returns Promise<MeterReadingResponse>

    A promise that resolves to the meter reading response.

  • Fetches and returns the service properties. If the service properties have been previously fetched and stored, it returns the stored properties. Otherwise, it fetches the properties from a predefined URL, stores them, and then returns them. In case of an error during fetching, it logs the error message.

    Parameters

    • refresh: boolean = false

    Returns Promise<ServiceProperties>

    A promise that resolves to the service properties.

  • Checks if the user is authenticated by verifying the presence of access token data.

    Returns boolean

    Returns true if access token data exists, otherwise false.

  • Checks if the current access token has expired.

    Returns boolean

    True if the token is expired, otherwise false.

  • Logs the user out by invalidating the current access token.

    This method checks if the user is authenticated before attempting to log out. If authenticated, it sends a request to the server to delete the current token. If the server response indicates a token expiry error, the error is not thrown. Otherwise, any other errors encountered during the logout process are thrown.

    Returns Promise<void>

    A promise that resolves when the logout operation is complete.

  • Sends an HTTP POST request to the specified URI with the given request data and returns the response.

    Type Parameters

    Parameters

    • uri: string

      The URI to send the POST request to.

    • data: D

      The data to be sent with the POST request.

    Returns Promise<R>

    A promise that resolves to the response data.

  • Sends an HTTP PUT request to the specified URI with the given data.

    Type Parameters

    Parameters

    • uri: string

      The URI to which the PUT request is sent.

    • data: D

      The data to be sent in the body of the PUT request.

    Returns Promise<R>

    A promise that resolves to the response of the PUT request.

  • Checks the given API response and throws an error if the response status is not "OK".

    Parameters

    • response: Response

      The API response to check for an error status.

    Returns void

    Returns nothing if the response is "OK"; otherwise, throws a VattenfallApiError.

  • Refreshes the access token using the refresh token.

    This method checks if the current access token data is available. If not, it triggers a fresh retrieval of the access token. Otherwise, it attempts to refresh the current access token using the refresh token. In case of any error that indicates token expiry, it retrieves a new access token.

    Returns Promise<void>

    A promise that resolves once the access token is refreshed or a new one is retrieved.

  • Makes an HTTP request to the specified URI with the provided method and data, and returns a promise that resolves to the response.

    Type Parameters

    Parameters

    • uri: string

      The URI to send the request to.

    • method: HTTPMethod = Types.HTTPMethod.GET

      The HTTP method to use for the request. Defaults to GET.

    • Optionaldata: D

      The data to send with the request. Optional.

    Returns Promise<R>

    A promise that resolves to the response of the HTTP request.

  • Resets the transaction ID for the current session.

    Parameters

    • Optionalid: string

      Optional parameter to set a specific transaction ID. If not provided, a new UUID will be generated and used.

    Returns Promise<void>

    • A promise that resolves when the transaction ID has been reset.
  • Asynchronously sets the user credentials for a transaction.

    Parameters

    • username: string

      The username to be set.

    • password: string

      The password to be set.

    Returns Promise<void>

  • Enables or disables debug logging for the application.

    Parameters

    • enabled: boolean

      A boolean value indicating whether debug logging should be enabled.

    Returns void