0.3.0 • Published 2 months ago

@jifeline/core v0.3.0

Weekly downloads
-
License
-
Repository
-
Last release
2 months ago

Core library

The Core library contains all the core functionality that is needed to work with the different libraries implementing the Jifeline public API's.

The Core library provides modules for:

  • performing HTTP requests
  • handling Websocket implementations
  • dealing with internationalization
  • authentication at AWS Cognito

In order to use these libraries, simply import it with ES6 import statements. The namespace is @jifeline, so the full import path would be; @jifeline/core.

Usage of the library

The core library needs configuration in order to make the modules work. The configuration exists of which API is requested. These are the interfaces of the different configurations;

interface IConfig {
  auth: IAuthConfig,
  http: IHttpClientConfig,
  ws: IWsClientConfig
}

interface IAuthConfig {
  awsStage: 'stg' | 'acc' | 'prd';
  awsRegion: 'eu-central-1' | 'us-east-2';
  awsUserPoolWebClientId: string;
  awsUserPoolId: string;
}

interface IHttpClientConfig {
  apiBaseUrl: string;
}

interface IWsClientConfig {
  wsBaseUrl: string;
}

Set this config when using a module in order to make the Core library work. Only the Auth module is needed.

import { auth } from '@jifeline/core';
import { IAuthConfig } from './auth-config';
import { IHttpClientConfig } from './http-config';

// Start with defining the config for the staging environment
const stagingConfig = {
  auth: {} as IAuthConfig, // Replace with AWS Cognito config for given environment 
  http: {} as IHttpClientConfig, // Replace with API base url for given environment
  ws: {} as IWsClientConfig, // Replace with WS base url for given environment
}

// Configure the auth module
auth.configure(stagingConfig);

// Login with pin or username password to get a bearer token in order to cummunicate with the Customer API.
auth
  .loginPin('1234567890', '12345')
  .subscribe({
    next: tokens => console.log('loged in with connector / pin', tokens),
    error: err => console.error('login failed with connector / pin', err)
  });

auth
  .loginUsername('username', 'password')
  .subscribe({
    next: tokens => console.log('loged in with username / password', tokens),
    error: err => console.error('login failed with username / password', err)
  });

auth
  .loginFederated({
    customProvider: 'test-example-azure-ad-oidc', // ID of the Federated configuration in our identity provider. This ID is provided when Jifeline configured the trust between our identity provider and the federated identity provider.
    domain: 'test-user-pool.auth.eu-central-1.amazoncognito.com', // The domain of the Jifeline identity provider.
    redirectSignIn: 'https://some-url.com/', // The redirect to after sign in .
    redirectSignOut: 'https://some-url.com' // The redirect to after sign out - can't be the same as redirectSignIn.
  })
  .subscribe({
    next: tokens => console.log('loged in with federated sign in', tokens),
    error: err => console.error('login failed with federated sign in', err)
  });


// From here all libraries can be used. See other libraries for more specificks.

Features

The Core library provides the following features:

  • auth
  • httpClient
  • wsClient
  • i18n

Auth

This module provides authentication features. These features will authenticate a user at AWS Cognito and, if enabled, validate MFA. When authentication is successful, it will store the session tokens provided by Cognito, and share them with the HTTP module. The HTTP module will add the session token as a bearer token to each HTTP request as authorization header in order to be able to communicate with the Jifeline Customer API.

The following functions are supported:

  • configure
  • login pin
  • login username
  • login federated
  • on mfa software token required
  • logout
  • is authenticated
  • is authenticated
  • on authenticated
  • on unauthenticated
  • get access token
  • set mfa software token
  • is error reason password not strong enough

HTTP client

This module provides a wrapper around the Fetch API. The wrapper supports HTTP GET, POST, PUT, and DELETE calls. When provided by the Auth module, it will set the Authorization header. When provided by the i18n module, it will set the Accept-Language header. There is no need to use the HTTP client directly. All the endpoints are implemented in different libraries.

The following functions are supported:

  • configure
  • set access token
  • clear access token
  • do get
  • do post
  • do put
  • do delete

WS client

The WS client is an implementation around the RxJS websocket subject. It connects to the websocket server, and uses the same connection to subscribe to different channels by different topics.

The following functions are supported:

  • configure
  • subscribe to channel
  • set access token
  • clear access token

I18n

This module provides features for handling all topics around internationalization (i18n). For now, it only supports setting the locale, which will be fet to the HTTP module. The HTTP module will add the local as Accept-Language header so the Jifeline Customer API knows which language it needs to provide the responses.

The following functions are supported:

  • set locale
  • get locale
  • on locale changed
  • get locale
0.3.0

2 months ago

0.1.0

10 months ago

0.2.1-rc.0

6 months ago

0.2.1

6 months ago

0.2.0

8 months ago

0.2.0-rc.1

8 months ago

0.2.0-rc.0

8 months ago

0.0.2

2 years ago

0.0.1

2 years ago