ILRD Client Adapter
Infinity Infrastructure Package For Frontend Services
Table of Contents
How To Install
echo '@werxpace:registry=https://dev.infinitylabs.co.il/api/v4/packages/npm/' >> .npmrc
echo '//dev.infinitylabs.co.il/api/v4/packages/npm/:_authToken=${NPM_TOKEN}' >> .npmrc
cat .npmrc
- You should commit the .npmrc
- Then run:
export NPM_TOKEN=<your_npm_token>
echo $NPM_TOKEN
npm i @werxpace/client-utils
How To Update:
npx npm-check-updates -u @werxpace/client-utils && npm i
Users In Development -
username = 'Liad'
password = '12345678'
username = 'Erez'
password = '12345678'
Publish New Version
cd pkg
npm publish
Working With Docker:
- NPM_TOKEN variable need to be accessed during build time.
- In old npm versions, it need to exist during runtime as well.
- To make NPM_TOKEN accessible during build, add this line to your
dockerfile
:
ARG NPM_TOKEN=$NPM_TOKEN
- Use
--build-arg NPM_TOKEN=$NPM_TOKEN
with docker build (and possibly with docker run). - If you're using
docker-compose
, do the same in your docker-compose file:
services:
some_service:
build:
...
args:
NPM_TOKEN: ${NPM_TOKEN} # build time env
environment:
- NPM_TOKEN=${NPM_TOKEN} # runtime env
API
Usage:
import werx from "@werxpace/client-utils";
const user = werx();
// Alternatively you may pass a config object: (ask devCore team for client name)
const user = werx({
realm: 'ilrd-dev',
url: 'https://iam-dev.infinitylabs.co.il/auth/',
clientId: '<client-name>',
});
// You should add your token to the requests headers.
// You may do it manually by setting: headers["authorization"]: `Bearer ${user.getToken()`.
// Alternatively, you can use the helper function like this:
const axiosInst = axios.create();
user.axiosSetup(axiosInst);
// For communication via sockets using socket.io.
// If you're using socket.io middleware provided by server-utils, you MUST use user.getSocket(io) from the client side:
import { io } from 'socket.io-client';
const socket = user.createProtectedSocket({ io, url: "http://backend.url.com" });
User
🌐 user.login() Promise
Single Sign In - redirect to Werxpace Login page.
🌐 user.getUserInfo()
Return
Object
.
{ uuid: String, // e.g. "2f4466c9-35b6-4089-a0c1-0b1498960270a" email: String, // e.g. "somemail@ilrd.co.il" firstName: String, // e.g. "John" lastName: String, // e.g. "Travolta" picture: String, // http://link.to.picture gender: String, // e.g. female / male / other preferredName: String, // e.g. Johnny employeeID: String, // 007 }
🌐 user.getToken()
Return token.
🌐 user.isAuthenticated()
Return
Boolean
.
🌐 user.logout()
Single Sign Out - logout from Werxpace.
Helpers
🌐 user.axiosSetup(axiosInstance)
Protect REST requests.
Applies interceptors for axios instance that will add user token Automagically to all axios requests.
🌐 user.createProtectedSocket({ io, url, params })
Get a secure socket.io socket instansce.
io
: socket.io (engine) object. If you're using server-utils socket middleware, you MUST use this method to create a socket.