@house-agency/session-service
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

Session Service Client Lib

Build Status

  • Build: npm run build
  • Test: npm test
  • Integration tests: npm run integration <- this depends on Docker and Docker Compose

How to install

Simply run: npm i --save -E @house-agency/session-service

How to use

Create a new session

import {Session} from 'session-service';

const session = new Session(
  'https://session.service.com', // The HOST
  'api-key', // API KEY
  'some-secret', // API SECRET
  ['a-service', 'other-service'] // An array with services the session will be using
);

session.get()
  .then(response => {
    // response.token
    // response.services
    // response.data
  });

Reinstanciate an existing session

import {Session} from 'session-service';

const session = new Session(
  'https://session.service.com', // The HOST
  'api-key', // API KEY
  'some-secret', // API SECRET
  'session-token' // An existing session token instead of an array of services
);

session.get()
  .then(response => {
    // response.token
    // response.services
    // response.data
  });

Update a session with new data

import {Session} from 'session-service';

const session = new Session('https://session.service.com', 'api-key', 'some-secret', ['service']);

// When not using concurrency control - skip check for the newest version
session.update({some_key: 'value'})
  .then(response => {
    // response.token
    // response.services
    // response.data
  });

// When using concurrency control - this will throw an error if it's not the latest version
session.update({some_key: 'value'}, true)
// Concurrency control -------------^
  .then(response => {
    // response.token
    // response.services
    // response.data
  });
  .catch(error => console.log('Error: ', error.errorCode)); // Error: 412

Delete a session

import {Session} from 'session-service';

const session = new Session('session.service.com', 'api-key', 'some-secret', ['service']);

// When not using concurrency control - skip check for the newest version
session.remove()
  .then(token => {
    //
  });

// When using concurrency control - this will throw an error if it's not the latest version
session.remove(true)
  .then(token => {
    //
  })
  .catch(error => console.log('Error: ', error.errorCode)); // Error: 412

What is concurrencyControl?

If you're altering a session with an update or a deletion that has been changed somewhere else, then you'll have a concurrency problem to deal with. This session service library has two ways of dealing with this. Either you skip the concurrency control and the library will fetch the latest version of your session and alter that one. This is the default alternative. The other alternative is that you're writing code to deal with this yourself. You'll then add the concurrencyControl boolean in the update or remove methods and then have code to deal with the eventual catch.

Package Sidebar

Install

npm i @house-agency/session-service

Weekly Downloads

0

Version

1.2.1

License

ISC

Last publish

Collaborators

  • lisandro.mindel
  • magnuswiden
  • martvdmoosdijk
  • botteu