This is a typescript client for interacting with the Luminous Money APIs. It is a somewhat bare- bones client and only seeks to provide some additional support around user management, error handling, logging, and other such things to make development against the Luminous REST APIs more robust.

Hierarchy

  • Client

Properties

requestHeaders: {
    [k: string]: string;
} = {}

An optional set of headers that can be added to every request

Type declaration

  • [k: string]: string
session: null | Session = null

A session object from a successful authentication

authBasic: string

Shorthand auth basic string for API calls

clientId: string

The client id to use for the connection

baseUrl: string

The base URL for API interactions

http: SimpleHttpClientInterface

The HTTP client to use for http calls

storage: StorageApi

A storage object to use for storing credentials. This will usually be window.localStorage or window.sessionStorage on the front-end, but could be anything.

log: SimpleLoggerInterface

A logger to use for logging errors and other info

storageKey: string = "@luminous-money/client::credentials"

An optional key to use for the storage key.

Constructors

  • Parameters

    • clientId: string

      The client id to use for the connection

    • secret: null | string

      The secret to use for the connection. May be null if this is a front-end connection.

    • baseUrl: string

      The base URL for API interactions

    • http: SimpleHttpClientInterface

      The HTTP client to use for http calls

    • storage: StorageApi

      A storage object to use for storing credentials. This will usually be window.localStorage or window.sessionStorage on the front-end, but could be anything.

    • log: SimpleLoggerInterface

      A logger to use for logging errors and other info

    • storageKey: string = "@luminous-money/client::credentials"

      An optional key to use for the storage key.

    Returns Client

Methods

  • Create a user

    Parameters

    • name: string
    • email: string
    • password: string
    • passwordConf: string

    Returns Promise<void>

  • Takes the user's email and password and attempts to obtain a session token with it. If there is already an active session, removes the session (live and stored) and replaces it with the new one.

    Parameters

    • email: string
    • password: string

    Returns Promise<LoginResult>

  • Use a 32-character hex code (received from the login method) and a TOTP obtained from the user to execute the 2fa step of the login process. This should return an active session or an error. The client will throw an error if some additional step is requested.

    Additionally, it should be noted that the 2fa flow is not well defined at the time of this writing, because 2fa is not yet implemented in the standard auth gateway.

    Parameters

    • stateCode: string
    • totp: string

    Returns Promise<LoginResult>

  • Log out of a currently logged in session (if exists)

    Returns Promise<void>

  • Perform a throw-away call to validate the session, if there is one

    Returns Promise<boolean>

  • get an API result

    Type Parameters

    • T

    Parameters

    • endpoint: string
    • Optional params: CollectionParams<unknown>
    • headers: {
          [k: string]: string;
      } = {}
      • [k: string]: string

    Returns Promise<T extends null ? NullResponse<unknown> : T extends O[] ? CollectionResponse<O, unknown, unknown> : T extends object ? SingleResponse<T, unknown, unknown> : Response<T, unknown, unknown, unknown, Obstruction<GenericParams>>>

  • post data to the API

    Type Parameters

    • T extends {
          tx: unknown;
          rx: unknown;
      }

    Parameters

    • endpoint: string
    • data: T["tx"]
    • headers: {
          [k: string]: string;
      } = {}
      • [k: string]: string

    Returns Promise<T["rx"] extends null ? NullResponse<unknown> : T["rx"] extends O[] ? CollectionResponse<O, unknown, unknown> : T["rx"] extends object ? SingleResponse<any[any], unknown, unknown> : Response<T["rx"], unknown, unknown, unknown, Obstruction<GenericParams>>>

  • update data in the API

    Type Parameters

    • T extends {
          tx: unknown;
          rx: unknown;
      }

    Parameters

    • endpoint: string
    • data: T["tx"]
    • headers: {
          [k: string]: string;
      } = {}
      • [k: string]: string

    Returns Promise<T["rx"] extends null ? NullResponse<unknown> : T["rx"] extends O[] ? CollectionResponse<O, unknown, unknown> : T["rx"] extends object ? SingleResponse<any[any], unknown, unknown> : Response<T["rx"], unknown, unknown, unknown, Obstruction<GenericParams>>>

  • delete data in the API

    Type Parameters

    • T = null

    Parameters

    • endpoint: string
    • headers: {
          [k: string]: string;
      } = {}
      • [k: string]: string

    Returns Promise<T extends null ? NullResponse<unknown> : T extends O[] ? CollectionResponse<O, unknown, unknown> : T extends object ? SingleResponse<T, unknown, unknown> : Response<T, unknown, unknown, unknown, Obstruction<GenericParams>>>

  • This is just like the get method, except it is meant to be used for paginated collection responses, and it allows you to pass in the response in order to get the next page of results for the same parameters.

    Note that you can also use it to get an initial page of responses, just like the get method.

    Type Parameters

    • T

    Parameters

    • endpoint: string
    • Optional params: CollectionParams<unknown>
    • Optional headers: {
          [k: string]: string;
      }
      • [k: string]: string

    Returns Promise<null | NextableResponse<T>>

  • Type Parameters

    • T

    Parameters

    Returns Promise<null | NextableResponse<T>>

  • This is just like the get method, except it is meant to be used for paginated collection responses, and it allows you to pass in the response in order to get the previous page of results for the same parameters.

    Note that you can also use it to get an initial page of responses, just like the get method.

    Type Parameters

    • T

    Parameters

    • endpoint: string
    • Optional params: CollectionParams<unknown>
    • Optional headers: {
          [k: string]: string;
      }
      • [k: string]: string

    Returns Promise<null | NextableResponse<T>>

  • Type Parameters

    • T

    Parameters

    Returns Promise<null | NextableResponse<T>>

  • This method is a convenience method used to find data objects of a certain type and/or id within a collection response.

    Type Parameters

    • T extends {
          id: string;
          type: string;
      }

    Parameters

    • inc: Included
    • spec: {
          id: string;
      }
      • id: string

    Returns undefined | T

  • Type Parameters

    • T extends {
          id: string;
          type: string;
      }

    Parameters

    • inc: Included
    • spec: {
          type: string;
      }
      • type: string

    Returns T[]

  • Type Parameters

    • T extends {
          id: string;
          type: string;
      }

    Parameters

    • inc: Included
    • spec: {
          id: string;
          type: string;
      }
      • id: string
      • type: string

    Returns undefined | T

  • Internal method facilitating a call for the next or previous response

    Type Parameters

    • T

    Parameters

    • endpoint: string
    • params: undefined | CollectionParams<unknown>
    • headers: undefined | {
          [k: string]: string;
      }
    • cursorParam: "nextCursor" | "prevCursor"

    Returns Promise<null | NextableResponse<T>>

  • Type Parameters

    • T

    Parameters

    • nextable: NextableResponse<T>
    • params: undefined
    • headers: undefined
    • cursorParam: "nextCursor" | "prevCursor"

    Returns Promise<null | NextableResponse<T>>

  • Use the current session to make the given HTTP call to the API and return to the result. This method automatically tries to refresh the session if it receives a 401 for a given call. If the call still fails, the error is thrown.

    Type Parameters

    • T = unknown

    Parameters

    • method: HttpMethods
    • endpoint: string
    • _req: SimpleHttpClientRequestConfig = {}

    Returns Promise<SimpleHttpClientResponseInterface<Response<T, unknown, unknown, unknown, Obstruction<GenericParams>>>>

  • Refresh an active session

    Returns Promise<true | SimpleHttpClientResponseInterface<ErrorResponse<unknown, Obstruction<GenericParams>>>>

  • Store a new session

    Parameters

    • data: Session

    Returns void

  • Accepts a string and returns the base64 representation of it

    Parameters

    • str: string

    Returns string

  • Generates a 32-character hex string for use as a "state" parameter in the login flow

    Returns string

  • Type-checks the credentials extracted from storage on instantiation

    Parameters

    • creds: any

    Returns creds is Session

  • Inflate and optionally dress an error from an error HTTP response

    Parameters

    • res: ErrorResponse<unknown, Obstruction<GenericParams>>

    Returns HttpError<GenericParams>

  • Parameters

    • res: ErrorResponse<unknown, Obstruction<GenericParams>>
    • state: "raw"

    Returns HttpError<GenericParams>

  • Parameters

    • res: ErrorResponse<unknown, Obstruction<GenericParams>>
    • state: "dressed"

    Returns ErrorResult

  • Condense a complex array of parameters into a flat set of key-value pairs. E.g:

    ``` const params = this.condenseParams({ pg: { size: 5, cursor: "abcde==", } })

    // params is equal to: { "pg[size]": 5, "pg[cursor]": "abcde==", }

    Parameters

    • p: any

    Returns {
        [k: string]: string | number;
    }

    • [k: string]: string | number

Generated using TypeDoc