/javascript-sdk

Extrahorizon Javascript SDK

Primary LanguageTypeScriptMIT LicenseMIT

Extra Horizon JavaScript SDK

This package serves as a JavaScript wrapper around all Extra Horizon cloud services.

Features

  • Auth: Provides authentication functionality. The Authentication service supports both OAuth 1.0a and OAuth 2.0 standards.
  • Users: The user service stands in for managing users themselves, as well as roles related to users and groups of users.
  • Data: A flexible data storage for structured data. Additionally, the service enables you to configure a state machine for instances of the structured data. You can couple actions that need to be triggered by the state machine, when/as the entities (instance of structured data) change their state. Thanks to these actions you can define automation rules (see later for more in depth description). These actions also make it possible to interact with other services.
  • Files: A service that handles file storage, metadata & file retrieval based on tokens.
  • Tasks: Start functions on demand, directly or at a future moment.
  • Templates: The template service manages templates used to build emails. It can be used to retrieve, create, update or delete templates as well as resolving them.
  • Mails: Provides mail functionality for other services.
  • Configurations: Provides storage for custom configuration objects. On different levels (general, groups, users, links between groups and users).
  • Dispatchers: Configure actions that need to be invoked when a specific event is/was triggered.
  • Payments: A service that provides payment functionality.
  • Profiles: Storage service of profiles. A profile is a separate object on its own, comprising medical information like medication and medical history, as well as technical information, like what phone a user is using.
  • Notifications: A service that handles push notifications.
  • Localizations: Storage and retrieval of text snippets, translated into multiple languages.
  • Events: Service that provides event (publish/subscribe) functionality for other services.

Getting started

To get started with the ExtraHorizon SDK you'll need to install it, and then get credentials which will allow you to access the backend.

Installation

In your project, if you are using yarn or npm you need to create a file called .npmrc at the root level of your project and add these lines. Replace ${AUTH_TOKEN} with your personal access token. You can get a new one at https://github.com/settings/tokens/new. Make sure you enable the read:packages scope.

@extrahorizon:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${AUTH_TOKEN}

Alternatively, this file can be added/edited in your home directory and it will be applied to all projects.

Explanation from GitHub on how to add your token can be found here https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-to-github-packages

Using npm:

npm install @extrahorizon/javascript-sdk

Using yarn:

yarn add @extrahorizon/javascript-sdk

Quick Start

import { createOAuth2Client } from '@extrahorizon/javascript-sdk';

(async () => {
  const exh = createOAuth2Client({
    host: '',
    clientId: '',
  });

  await exh.auth.authenticate({
    password: '',
    username: '',
  });

  console.log('exh.users.health()', await exh.users.health());
  console.log('exh.users.me()', await exh.users.me());
})();

Please see authentication examples for more options.

Interceptors

The data returned from the backend is mapped using interceptors:

  • Timestamps will be of type Date
  • Keys in objects will be camelCased
  • records_affected will be replaced by affected_records

Documentation

🔑 License

The MIT License (MIT). Please see License File for more information.

Developer Notes

Throughout the different services we use this for easy access to other functions in each service. The usage of this as first parameter is explained here: https://www.typescriptlang.org/docs/handbook/2/functions.html#declaring-this-in-a-function. This parameter is excluded from all exported types.

find(
  this: DataSchemasService,
  options?: { rql?: RQLString }
): Promise<PagedResult<Schema>>;

Migration Guides

Migrating to v8.0.0

Swagger files