npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

casted-auth-js-sdk

v1.0.12

Published

This sdk contains modules/services which provide functionality that interacts with Alpha Kit services.

Downloads

21

Readme

auth-js-sdk

This sdk contains modules/services which provide functionality that interacts with Alpha Kit services.

// IMPORT
import { Module } from 'auth-js-sdk'
import Module from 'auth-js-sdk/Module'
import authJsSdk from 'auth-js-sdk'
authJsSdk.Module

Auth

The Auth service contains convienent methods for interacting with the Authentication service. The Auth service also manages its own state through localstorage and getter/setter properties on the service. These state properties include accessToken, refreshToken, clientId and userId.

Usage

import { Auth } from 'auth-js-sdk'

// Instantiate a new Auth service
const client = new Auth({
  baseURL: 'http://localhost:8081', // The URL of the Auth service in the backend
  storagePrefix: 'auth_' // The prefix to use for the localstorage state items
})

// Properties

console.log(client.config) // The config passed into the constructor
// => <OBJECT> { baseURL: 'http://localhost:8081', storagePrefix: 'auth_' }

console.log(client.accessToken) // The accessToken managed by the Auth service, persisted in localStorage
// => <JWT> some.jwt.blah

console.log(client.refreshToken) // The refreshToken managed by the Auth service, persisted in localStorage
// => <JWT> some.jwt.blah

console.log(client.clientId) // The clientId managed by the Auth service, persisted in localStorage
// => <GUID> 17b9cb4a-e416-478a-b5d3-be1ac7ce000f

console.log(client.userId) // The userId managed by the Auth service, persisted in localStorage
// => <NUMBER> 1

// Methods

// Sends basic auth parameters (username, password) as login credentials to the Auth service.
// This will return (with a promise) the user as well as a flag which says whether or not there needs to be more verification.
// If no verification is needed, this will also return the access token and refresh token. Otherwise those tokens are excluded.
client.signInLocal(username, password).then((data) => {
  console.log(data) // => { user, needsVerification, accessToken?, refreshToken? }
})

// Will clear out localStorage auth state as well as make a request to the Auth service to clear out any long term session data
client.signOut().then((response) => {
  console.log(response) // => The http response object
})

// Calls the Auth service's /token endpoint to get a new access token from the given refreshToken.
// Will store the new accessToken in localStorage as well return it in a Promise
client.refresh().then((accessToken) => {
  console.log(accessToken) // => <JWT> some.jwt.blah
})

// Create a new user with the given username/password as credentials, the given user object for the details and an optional key used for provisioning.
// Returns a Promise with the created user.
client.postUser(username, password, user, key).then((savedUser) => {
  console.log(savedUser) // => { id: 2, first_name: 'john', last_name: 'smith', email: '...', phone: '...' }
})

// Creates and stores a temporary password reset code for the matching user, and sends an email with a link to reset their password.
client.sendResetEmail(email).then((response) => {
  console.log(response) // => The http response object
})

// Sends the new password along with the user's id and temp reset code to the Auth service to update the user's password.
client.resetPassword(identifier, password, code).then((response) => {
  console.log(response) // => The http response object
})

// Tells the Auth service to send a 2fa verification code to the user with the given id using the given delivery options.
// Delivery method should be one of 'sms' | 'email' | 'voice'.
// Delivery value should be the cooresponding identifier for the chosen method (such as the phone number).
client.sendVericationCode(userId, deliveryMethod, deliveryValue).then((response) => {
  console.log(response) // => The http response object
})

// Will send the user's id and chosen delivery options as well the submitted verification code to check that they are verified.
// Returns a Promise with both the refreshToken and accessToken for the user if successful.
client.checkVerificationCode(userId, deliveryMethod, deliveryValue, code).then((tokens) => {
  console.log(tokens) // => { accessToken, refreshToken }
})