Skip to content

intersective/practera-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@practera/practera-sdk

This is the sdk of practera. Practera SDK can call different endpoints of API URL passed to the SDK. SDK will return promise as it's return value.

Health

Quality Gate Status Coverage Security Rating Maintainability Rating Bugs Code Smells

Table of Contents

Install

npm install @practera/practera-sdk

Import

TypeScript

Import the SDK to the TypeScript file that you need to use it.

import { PracteraSDK } from '@practera/practera-sdk';

Initialising PracteraSDK object.

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login.api.com',
  coreApiUrl: 'core.api.com',
  loginAppUrl: 'login.app.com',
  apiKey: 'apiKey',
});
Property name Description
loginApiUrl Need to provide Login Api Url when SDK initialising to make API calls to it. not required
coreApiUrl Need to provide Core Api Url when SDK initialising to make API calls to it. not required
loginAppUrl Need to provide Global Login App Url when SDK initialising to make API calls to it. not required
apiKey Need to provide Apikey when SDK rely on apikey for API calls. not required

Config Parameters

Config parameters you need to provide depends on which API call you going to make through practera SDK.

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login.api.com',
  coreApiUrl: 'core.api.com',
  loginAppUrl: 'login.app.com',
  apiKey: 'apiKey',
});
const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login.api.com'
});
const practeraSDK = new PracteraSDK({
  coreApiUrl: 'core.api.com',
  apiKey: 'apiKey',
});
const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login.api.com',
  loginAppUrl: 'login.app.com',
  apiKey: 'apiKey',
});

If you need to update config params after initialise Practera SDK, can use public method useConstructorParams

Public Methods

Public methods are the methods that's not calling any API cals and you can call to do different things.

useConstructorParams()

By using this method we can update config parameters passed when SDK initialisation.

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login.api.com'
});

practeraSDK.useConstructorParams({
  coreApiUrl: 'core.api.com',
  apiKey: 'apiKey',
});

practeraSDK.useConstructorParams({
  loginApiUrl: 'login-02.api.com',
  loginAppUrl: 'login.app.com',
  apiKey: 'apiKey-02',
});

API Calls

These are the API calls can make through Preactera SDK. Each API call reuire different config parameters when SDK initialisation. Before you make any API call make sure you provided correct config parameters when SDK initialise. Check Config Parameters for examples about how we can use them.

Login

Login service is calling /login endpoint of the API URL passed when SDK init. To call login service need to pass user credentials. Credentials contains two data. username, email address of user and password.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login api url'
});

let credentials = {
   username: 'abcd@gmail.com',
   password: '1234'
}

practeraSDK.login(credentials).then(
    (response) => {
        console.log('login success');
    },
    (error) => {
        console.error('error');
    }
);

Direct login

Login service is calling /login endpoint of the API URL passed when SDK init. To call login service as direct login need to pass apikey to the API.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login api url'
});

let data = {
   apikey: 'sample-apikey',
}

practeraSDK.directLogin(data).then(
    (response) => {
        console.log('login success');
    },
    (error) => {
        console.error('error');
    }
);

Forgot password

Forgot password service is calling /forgotPassword endpoint of the API URL passed when SDK init. To call forgot password service need to pass user registerd email. Email use to send password reset email to the user.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login api url',
  loginAppUrl: 'global login app url'
});

let data = {
   email: 'abcd@gmail.com'
}

practeraSDK.forgotpassword(data).then(
    (response) => {
        console.log('Password reset email send to provided email');
    },
    (error) => {
        console.error('error');
    }
);

Reset password

Reset password service is calling /user endpoint of the API URL passed when SDK init. To call reset password service need to pass user new password and apiKey getting from email link.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login api url',
  apiKey: '12345'
});

let data = {
   password: '123456'
}

practeraSDK.resetPassword(data).then(
    (response) => {
        console.log('Password change successfull');
    },
    (error) => {
        console.error('error');
    }
);

Account Registration/Activation

User account registration/activation uses /registration_details endpoint. Purpose: Activate/register user account with user-specified password.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  coreApiUrl: 'core api url',
  apiKey: '12345'
});

let data = {
  appkey: 'sample-appkey',
  password: 'sample-password',
  user_id: 12345,
  key: 'sample-key',
};

practeraSDK.register(data).then(
    (response) => {
        console.log('Registration successful.');
    },
    (error) => {
        console.error('error');
    }
);

Account Registration Verification

User account registration verification uses /verification_codes endpoint. Purpose: verify current user registration session

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  coreApiUrl: 'core api url',
  apiKey: '12345'
});

let data = {
  appkey: 'sample-appkey',
  email: 'sample-email',
  key: 'sample-key',
};

practeraSDK.verifyRegistration(data).then(
    (response) => {
        console.log('Registration session is valid.');
    },
    (error) => {
        console.error('error');
    }
);

MFA Register

MFA Register service is calling /mfa/register endpoint of the API URL passed when SDK init. To call MFA Register service need to pass country code of the phone number, actual phone number and user apiKey.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login api url',
  apiKey: '12345'
});

let data = {
   countryCode: '+94',
   number: '123456'
}

practeraSDK.mfaRegister(data).then(
    (response) => {
        console.log('Phone number registration successfull.');
    },
    (error) => {
        console.error('error');
    }
);

MFA Verify

MFA verify service is calling /mfa/verify endpoint of the API URL passed when SDK init. To call MFA verify service need to pass verification code and user apiKey.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login api url',
  apiKey: '12345'
});

let data = {
   code: '123456'
}

practeraSDK.mfaVerify(data).then(
    (response) => {
        console.log('Code verification successfull');
    },
    (error) => {
        console.error('error');
    }
);

MFA SMS

MFA sms service is calling /mfa/sms endpoint of the API URL passed when SDK init. To call MFA sms service need to pass user apiKey.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  loginApiUrl: 'login api url',
  apiKey: '12345'
});

practeraSDK.mfaSMS().then(
    (response) => {
        console.log('sms send with verification code.');
    },
    (error) => {
        console.error('error');
    }
);

Get Custom Config

Get custom config service is calling /api/v2/plan/experience/list endpoint of the API URL passed when SDK init. To call Get custom config service need to pass domain.

import { PracteraSDK } from '@practera/practera-sdk';

const practeraSDK = new PracteraSDK({
  coreApiUrl: 'core api url'
});

let data = {
   domain: 'https://app.practera.com'
}

practeraSDK.getCustomConfig(data).then(
    (response) => {
        console.log('returning experience config');
    },
    (error) => {
        console.error('error');
    }
);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •