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

xterio-auth

v0.0.2

Published

xterio-auth

Downloads

3

Readme

@xterio-sdk/auth

1. Install

npm install @xterio-sdk/auth | yarn add @xterio-sdk/auth | pnpm add @xterio-sdk/auth

2. Usage

import '@xterio-sdk/auth/style/main.css'
import { XterioAuth, XterEventEmiter } from '@xterio-sdk/auth'

//1. Initialize only once
const redirect_uri = ''
const client_id = ''
const client_secret = ''
const app_id = ''
XterioAuth.init({app_id, client_id, client_secret, redirect_uri })

//2. Register to listen for user information
const unsubscribe = XterEventEmiter.subscribe(info=>{
  //subscribe
  console.log('info=', info)
})

unsubscribe() //unsubscribe

//or

XterEventEmiter.unsubscribe()//unsubscribe all account event

//3. SignIn
XterioAuth.login()
...

3. How to get userinfo

XterioAuth.userinfo (not recommend)

XterioAuth.getUserInfo((info) => {})

//example
XterioAuth.getUserInfo((info) => {
  //info:IUserInfo
})

XterEventEmiter.subscribe((info) => {})

//example1
const unsubscribe = XterEventEmiter.subscribe((info: IUserInfo) => {
  updateInfo(info)
})

//example2
const unsubscribe = XterEventEmiter.subscribe<IUserInfo>((info) => {
  updateInfo(info)
})

4. API Reference

4.1 Method

init(config, env?:Env)

Initialize Function

XterioAuth.init({
  app_id:'',
  client_id:'',
  client_secret:'',
  redirect_uri:'',
  //sso login mode, the value of 'default'|'email'
  //the default value is 'default'
  mode:'default',
  //sso login whether logout when login, the value of '1'|'0'
  //the default value is '1'
  logout:'1',
  //the log level, close all console(>=5),open all log(<=1)
  //the default value is 1
  logLevel: 1
}, Env.Dev)

login(mode?: LoginType)

login xterio

XterioAuth.login() //default: LoginType.Default
XterioAuth.login(LoginType.Email)
XterioAuth.login(LoginType.Mini)

logout()

quit xterio

XterioAuth.logout()

getIdToken()

check whether the idToken is valid. If the idToken is invalid, empty string is returned, else the non-empty str.

XterioAuth.getIdToken() //Promise<string>

getUserInfo(p:Function)

get userinfo with callback

//example
XterioAuth.getUserInfo((info) => {
  //info:IUserInfo
})

openPage(page:PageType,mode?:OpenPageMode, options?:PageOptionParam)

default mode: OpenPageMode.alert

//example1: page:asset, mode:alert
XterioAuth.openPage(PageType.asset, OpenPageMode.alert, {active: 'ingame'})

//example2: page:account, mode:page
XterioAuth.openPage(PageType.account, OpenPageMode.page)

//example3: page:wallet, mode:iframeDom
await XterioAuth.openPage(PageType.wallet, OpenPageMode.iframeDom) //return: domNode

//example4: page:nft, mode:iframeUri
await XterioAuth.openPage(PageType.nft, OpenPageMode.iframeUri, {
  keyword: '',
  collection: '',
  features: [{ k: '', initValues: [], type: '' }]
}) //return: uri

4.2 Property

isLogin

whether to log in

XterioAuth.isLogin //boolean

userinfo

get xterio user information

XterioAuth.userinfo

4.3 EventEmiter

subscribe(callback:Func, _event?: string)

//subscribe userinfo
const unsubscribe = XterEventEmiter.subscribe(()=>{}) //default: XTERIO_EVENTS.ACCOUNT

//unsubscribe userinfo(this userinfo event)
unsubscribe()

//unsubscribe userinfo(all userinfo event)
XterEventEmiter.unsubscribe() //default: XTERIO_EVENTS.ACCOUNT

off/on(event:string, callback:Func)

const cb = (info) => {
  console.log('emiter auth userinfo==', info)
}
XterEventEmiter.on(cb, 'event_name')
XterEventEmiter.off(cb, 'event_name')

clear()

clear all listeners

5. Interface/Type

Env

export enum Env {
  Dev = 'Dev',
  Staging = 'Staging',
  Production = 'Production'
}

LoginType

export enum LoginType {
  Default = 'default',
  Email = 'email',
  Mini = 'mini'
}

OpenPageMode

export enum OpenPageMode {
  alert = 'alert', //open alert
  page = 'page', //open new page
  iframeDom = 'dom', //return iframe dom
  iframeUri = 'url' //return url
}

PageType

export enum PageType {
  asset = 'asset',
  nft = 'nft',
  account = 'account',
  wallet = 'wallet'
}

PageOptionParam

export interface PageOptionParam {
  /** asset page */
  active?: 'ingame' | 'onchain'
  /** nft page */
  keyword?: string
  /** nft page */
  collection?: string
  /** nft page */
  features?: { k: string; initValues: (number | string)[]; type?: string }[]
  /** whether hide wallet entry */
  hide_wallet_entrance?: boolean
  /** whether hide account */
  hide_account_entrance?: boolean
  /** whether hide top nav menu */
  hide_menu_entrance?: boolean
  /** whether hide logout btn */
  hide_sign_out?: boolean
  /** whether hide footer */
  hide_footer?: boolean
  /** whether disable logo click event */
  disable_logo_click?: boolean
  /** whether hide game select, only asset page */
  hide_game_select?: boolean
  /** whether hide game tokens, only asset page */
  hide_game_tokens?: boolean
  /** whether hide game filter, only nft page */
  hide_game_filter?: boolean
  /** set alert configs */
  alertConfig?: {
    placement: 'left' | 'right' | 'center' //default: 'right'
    style: Partial<CSSStyleDeclaration> //default: { width: '400px', height: '100%' }
    showCloseIcon?: boolean
  }
}