Options
All
  • Public
  • Public/Protected
  • All
Menu

Authenticate against a Graphistry server using a username and password, and manage communications with it.

Different authentication modes may be desirable depending on the type of Graphistry server.




example

Authenticate against Graphistry Hub for a personal account

import { Client } from '@graphistry/node-api';
const client = new Client('my_username', 'my_password');

example

Authenticate against an org in Graphistry Hub

import { Client } from '@graphistry/node-api';
const client = new Client('my_username', 'my_password', 'my_org');

example

Authenticate against a private Graphistry server

import { Client } from '@graphistry/node-api';
const client = new Client('my_username', 'my_password', '', 'http', 'my-ec2.aws.com:8080');

example

Upload via internal IP but publish urls via a public domain

import { Client } from '@graphistry/node-api';
const client = new Client(
'my_username', 'my_password', '',
'http', '10.20.0.1:8080',
'https://www.my-site.com'
);

example

Upload through the local docker network but publish urls via a public domain

import { Client } from '@graphistry/node-api';
const client = new Client(
'my_username', 'my_password', '',
'http', 'nginx',
'https://www.my-site.com'
);

example

Create a client with an externally-provided JWT token

import { Client } from '@graphistry/node-api';
const client = new Client();
client.setToken('Bearer 123abc');

Hierarchy

  • AbstractClient
    • Client

Index

Methods

  • isConfigurationValid(userId: string, secret: string, host: string): boolean
  • Parameters

    • userId: string
    • secret: string
    • host: string

    Returns boolean

  • authTokenValid(): boolean
  • Returns boolean

    Whether the current token is valid

  • checkStale(username: string, password: string, protocol: string, host: string, clientProtocolHostname?: string): boolean
  • Parameters

    • username: string
    • password: string
    • protocol: string
    • host: string
    • Optional clientProtocolHostname: string

    Returns boolean

  • fetchToken(username: string, password: string, org?: string, protocol?: string, host?: string): Promise<string>
  • Parameters

    • username: string
    • password: string
    • Optional org: string
    • protocol: string = 'https'
    • host: string = 'hub.graphistry.com'

    Returns Promise<string>

    Promise for the authentication token

    Helper to fetch a token for a given user

  • isServerConfigured(): boolean
  • Returns boolean

  • post(uri: string, payload: any, baseHeaders?: any): Promise<any>
  • internal

    Internal helper

    Parameters

    • uri: string

      The URI to upload to.

    • payload: any

      The payload to upload.

    • baseHeaders: any = undefined

      Optionally override base header object to mix with auth header for the upload.

    Returns Promise<any>

    The response from the server.

  • setToken(token: string): Client
  • See examples at top of file

    Set JWT token if already known

    Parameters

    • token: string

      The token to use for authentication.

    Returns Client

    The client instance.

  • getAuthToken(force?: boolean): Promise<string>
  • Get the authentication token for the current user. By default, reuses current token if available.

    Parameters

    • force: boolean = false

      If true, forces a new token to be generated; defaults to false

    Returns Promise<string>

    The authentication token

  • getBaseHeaders(): { Accept: string; Content-Type: string }
  • Returns { Accept: string; Content-Type: string }

    • Accept: string
    • Content-Type: string
  • getBaseUrl(): string
  • getToApi(url: string, headers: any, baseUrl?: string): Promise<any>
  • Parameters

    • url: string
    • headers: any
    • Optional baseUrl: string

    Returns Promise<any>

  • postToApi(url: string, data: any, headers: any, baseUrl?: string): Promise<any>
  • Parameters

    • url: string
    • data: any
    • headers: any
    • Optional baseUrl: string

    Returns Promise<any>

Properties

agent: string
clientProtocolHostname: string
host: string
org?: string
protocol: string
username: string
version?: string
_getAuthTokenPromise?: Promise<string>
_token?: string
fetch: any
_password: string

Constructors

  • new Client(username: string, password: string, org?: string, protocol?: string, host?: string, clientProtocolHostname?: string, fetch?: any, version?: string, agent?: string): Client
  • See examples at top of file

    Parameters

    • username: string

      The username to authenticate with.

    • password: string

      The password to authenticate with.

    • Optional org: string

      The organization to use (optional)

    • protocol: string = 'https'

      The protocol to use for the server during uploads: 'http' or 'https'.

    • host: string = 'hub.graphistry.com'

      The hostname of the server during uploads: defaults to 'hub.graphistry.com'

    • Optional clientProtocolHostname: string

      Base path to use inside the browser and when sharing public URLs: defaults to '{protocol}://{host}'

    • Optional fetch: any

      The fetch implementation to use

    • Optional version: string

      The version of the client library

    • agent: string = '@graphistry/js-upload-api'

      The agent name to use when communicating with the server

    Returns Client