Datalynk Client
    Preparing search index...

    Class Api

    Connect to Datalynk & send requests

    Index

    Constructors

    • Connect to Datalynk & send requests

      Parameters

      Returns Api

      const api = new Api('https://spoke.auxiliumgroup.com');
      

    Properties

    auth: Auth

    Authentication

    database?: Database

    Offline database

    files: Files

    File

    gps: Gps

    GPS

    online$: BehaviorSubject<boolean> = ...

    Backwards-compatible boolean connection state.

    false includes offline, unauthorized, and unavailable states.

    options: ApiOptions

    Options

    origin: string

    API URL

    pdf: Pdf

    PDF

    pwa: PWA

    PWA setup & prompt

    sliceCache: Map<number, Slice<any>> = ...

    Created slices

    socket: Socket

    Socket

    status$: BehaviorSubject<ApiConnectionStatus> = ...

    Detailed API connection state.

    Subscribe to this when callers need to distinguish physical/network offline state from authentication failure or server/API unavailability.

    superuser: Superuser

    Superuser

    token$: BehaviorSubject<null | string> = ...

    API Session token

    url: string

    API URL

    version: string = version

    Client library version

    webrtc: WebRtc

    WebRTC

    version: string = version

    Client library version

    Accessors

    • get expired(): boolean

      Is token expired

      Returns boolean

    • get jwtPayload(): null | JwtPayload

      Get session info from JWT payload

      Returns null | JwtPayload

    • get offline(): boolean

      Whether normal Datalynk API access is currently unavailable.

      This is the inverse of online. It can be true while the browser still has Internet access, for example during MySQL/HTTP 5xx recovery.

      Returns boolean

    • get online(): null | boolean

      Whether normal Datalynk network requests are currently available.

      This becomes false for network outages, rejected/expired sessions, and request-owned server recovery. It therefore describes Datalynk availability rather than only navigator.onLine.

      Returns null | boolean

    • set online(value: null | boolean): void

      Override the boolean connection state.

      Set true or false to force the corresponding state. Set null to remove the override and resume normal connection checking. This is a manual override and can supersede the current recovery state, so normal applications should generally observe status instead of forcing it.

      Parameters

      • value: null | boolean

      Returns void

    • get reauthenticationPending(): boolean

      Whether authentication expired while offline and must be renewed before replaying queued work.

      Returns boolean

    • get spoke(): string

      Logged in spoke

      Returns string

    • get token(): null | string

      Returns null | string

    • set token(token: null | string): void

      Parameters

      • token: null | string

      Returns void

    Methods

    • Chain multiple requests to execute together

      Parameters

      • ...requests: any[]

        List of requests to chain

      Returns Promise<any>

      API Response

    • Organize multiple requests into a single mapped request

      Parameters

      • request: { [key: string]: any }

        Map of requests

      Returns Promise<any>

      Map of API Responses

    • Lazily load and construct chat. No chat code or requests run before this call.

      Returns Promise<Chat>

    • Exact same as the request method, but logs the response in the console automatically

      Type Parameters

      • T = any

      Parameters

      Returns Promise<T>

      Datalynk response

    • Exact same as the request method, but logs the response in the console automatically

      Type Parameters

      • T = any

      Parameters

      • data: any

        Datalynk request as object or string

      • options: { offline: true } & ApiRequestOptions

      Returns Promise<void | T>

      Datalynk response

    • Get list of slices

      Returns Promise<number[]>

    • Send a request to Datalynk

      Type Parameters

      • T = any

      Parameters

      • data: any

        Request using Datalynk API syntax. Strings will be converted: '$/auth/current' -> {'$/auth/current': {}}

      • Optionaloptions: ApiRequestOptions

      Returns Promise<T>

      Datalynk response or error

      const response = await api.request('$/auth/current');
      
    • Send a request to Datalynk

      Type Parameters

      • T = any

      Parameters

      • data: any

        Request using Datalynk API syntax. Strings will be converted: '$/auth/current' -> {'$/auth/current': {}}

      • options: { offline: true } & ApiRequestOptions

      Returns Promise<void | T>

      Datalynk response or error

      const response = await api.request('$/auth/current');
      
    • Create a slice object using the API

      Type Parameters

      • T extends Meta = any

      Parameters

      • id: string | number

        Slice ID the object will target

      Returns Slice<T>

      Object for making requests & caching rows

      const contactsSlice = api.slice<Contacts>(12345);
      const allContacts = await contactsSlice.select().exec().rows();
      const unsubscribe = contactsSlice.sync().subscribe(rows => console.log(rows));