npm.io
3.3.0 • Published 6 years ago

@cumulus-consulting/mfgx-io-api-client

Licence
MIT
Version
3.3.0
Deps
19
Size
98 kB
Vulns
25
Weekly
0

@cumulus-consulting/mfgx-io-api-client

API client designed to simplify use of MFGx APIs. Works in Node and browser environments.

Install via npm

npm install --save @cumulus-consulting/mfgx-io-api-client

Quick Start (ES6)

import { apiClient } from '@cumulus-consulting/mfgx-io-api-client';

apiClient.setBaseUrl('https://api.instance.mfgx.io');

await apiClient.signIn({
	email: 'test@email.com',
	password: 'password'
});

const { data: { userMany } } = await apiClient.graphQL({
	query: `{
	  userMany {
	    id
	    email
	  }
	}`
});

Documentation

Exports
import { 
  // Pre-constructed API client instance with default options.
  apiClient, 
  // Main API client class, used to construct a new instance or extend the client.
  MFGxClient, 
  // Map of MFGx APIs; see APIs section below
  APIS 
} from '@cumulus-consulting/mfgx-io-api-client'; 
Constructor Options
{
  // Base MFGx API url (i.e. 'https://api.instance.mfgx.io').  Can also be set
  // or changed via the setBaseUrl function on a client instance.
	url,
	// Promise-returning functions to get, set, and clear a token from storage.
	// Default behavior is to store tokens in a closure; override provides the
	// ability to store tokens in persistent or secure storage.
	tokenStorage: {
		get,
		set,
		clear,
	},
	// When true, token expiration 401 errors will be automatically caught, the
  // token will attempt to be refreshed, and the request retried.  Defaults to
  // false.
	autoRefreshToken: false,
  // Callback called when errors occur, in addition to function throws.  
  // Can be used to display error UI or for global error logging.
	onError,
	// Promise-returning callback used to request device information when
	// needed by the client.  Device information returned should match the
	// format of the DeviceInformationInput type in the signIn API.
	onRequestDeviceInformation,
}
APIs
{
	// Primary graphQL sign-in API.
	SIGN_IN:  '/signIn',
	// Main graphQL application API.
	GRAPHQL:  '/graphql',
	// Metadata graphQL API for system data.
	METADATA:  '/metadata',
	OCR: {
		// REST API to execute raw OCR requests; only applicable if OCR is enabled.
		RAW:  '/ocr/raw'
	},
	DOCUMENTS: {
		// REST API to generate PDF documents.
		GENERATE:  '/documents/generate'
	},
	WEBHOOKS: {
		// REST API to publish into a user-defined webhook.
		UDT:  '/webhooks/udt'
	},
	INTEGRATION: {
		// REST API for standardized requests to external systems.
		ENDPOINT:  '/integration/endpoint'
	},
	// Transformation graphQL API for executing MFGx scripts.
	TRANSFORMATION:  '/transformation'
}