@grandlinex/swagger-mate
    Preparing search index...

    Class BaseCon

    BaseCon provides a minimal client for interacting with an HTTP backend. It manages connection state, authentication tokens, and reconnection logic while delegating actual HTTP requests to a supplied ConHandle.

    Index
    • Parameters

      • conf: {
            con: ConHandle;
            endpoint: string;
            logger?: (arg: any) => void;
            permanentHeader?: Record<string, string>;
        }

      Returns BaseCon

    api: string
    authorization: string | null
    disconnected: boolean
    logger: (arg: any) => void
    noAuth: boolean
    onDisconnect: (con: BaseCon) => void
    onReconnect: (con: BaseCon) => void
    permanentHeader: Record<string, string>
    reconnecting: Promise<boolean> | null
    refresh: string | null
    • Establishes a connection to the backend using the supplied credentials. Performs a health‑check ping first; if successful, it requests an authentication token from the /token endpoint. When the token is obtained, the method updates internal state (authorization header, connection flags) and, unless a dry run is requested, sets up a reconnection routine. Any errors are logged and the method resolves to false.

      Parameters

      • email: string

        The user's email address for authentication.

      • pw: string

        The password (or token) for the specified user.

      • Optionalrefresh: boolean
      • Optionaldry: boolean

        If true, the method performs a dry run without persisting credentials or configuring reconnection logic.

      Returns Promise<boolean>

      Promise true if the connection was successfully established, otherwise false.

    • Attempts to establish a connection to the backend without authentication.

      This method sends a ping request. If the ping succeeds, it clears any existing authorization data, marks the instance as connected, enables the no‑authentication mode, and returns true. If the ping fails, it logs a warning, clears authorization, marks the instance as disconnected, and returns false.

      Returns Promise<boolean>

      true when a connection is successfully established without authentication, otherwise false.

    • Parameters

      Returns void

    • Returns Promise<boolean>

    • Forces a connection using the provided bearer token.

      Parameters

      • token: string | null

        The token to be used for authentication.

      • Optionalrefresh: string | null

      Returns void

    • Retrieves the API endpoint.

      Returns string

      The API endpoint string.

    • Returns the current authorization token.

      Returns string | null

      The authorization token or an empty string if none is set.

    • Performs an HTTP request using the client’s internal connection.

      The method verifies that the client is connected before attempting a request. It automatically injects the authorization token, permanent headers, and any headers supplied in config. If the request body is a FormData instance (or provides a getHeaders method), the appropriate form headers are added.

      Response handling:

      • 200 or 201: returns success: true with the received data.
      • 498: attempts to reconnect and retries the request once.
      • 401: logs an authentication error, marks the client as disconnected.
      • 403 and other status codes: return success: false with the status code.

      Type Parameters

      • T
      • J

      Parameters

      • type: "POST" | "GET" | "PATCH" | "DELETE" | "QUERY"

        The HTTP method to use.

      • path: string

        The endpoint path relative to the base URL.

      • Optionalbody: J

        Optional request payload. May be FormData or a plain object.

      • Optionalconfig: ConHandleConfig

        Optional Axios-like configuration for the request.

      Returns Promise<HandleRes<T>>

      A promise that resolves to a HandleRes object containing the response data, status code, any error information, and headers.

    • Indicates whether the instance is considered connected.

      The instance is regarded as connected when it either does not require authentication (noAuth is true) or it has an authorization token set (authorization is not null), and it is not currently marked as disconnected.

      Returns boolean

      true if the instance is connected, false otherwise.

    • Parameters

      Returns string

    • Sends a ping request to the API to verify connectivity and version availability.

      Returns Promise<boolean>

      true if the API responded with a 200 status code and a valid version object; false otherwise.

    • Returns Promise<boolean>

    • Sets the API endpoint URL used by the client.

      Parameters

      • endpoint: string

        The full URL of the API endpoint.

      Returns void

    • Parameters

      • header: Record<string, string>

      Returns void

    • Validates the current authentication token by performing a ping and a test request to the backend. The method first ensures connectivity via ping. If the ping succeeds, it attempts to retrieve a token from the /test/auth endpoint using the current token in the Authorization header. The operation is considered successful if the response status code is 200 or 201.

      If any step fails, an error is logged and the method returns {@code false}. On success, it returns {@code true}.

      Returns Promise<boolean>

      A promise that resolves to {@code true} if the token test succeeds, otherwise {@code false}.

    • Returns the current authorization token.

      Returns string | null

      The authorization token or an empty string if none is set.

    • Returns Record<string, string>