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

@cashier/web

v0.11.0

Published

cashier - Web SDK for webinfra service

Downloads

11

Readme

SDK of webinfra service for User & License management

Introduction

You can use the SDK to quickly integrate authentication & license & payment capabilities for new or existing web applications

Demo

import React, { useCallback, useEffect, useMemo, useState } from "react";
import Cashier from '@cashier/web';
import {
  TUserInfo,
} from "@cashier/web";
function App() {
  const sdk = useMemo(() => {
    return new Cashier({
      // 应用 ID
      appId: process.env.REACT_APP_SDK_APPID as string,
      appToken: process.env.REACT_APP_SDK_TOKEN as string,
      //   domain: 'https://test-sdk-api.my.webinfra.cloud'
      privacyLink: 'https://your-docs-link.com/privacy.html',
      version: 4,
    });
  }, []);

  const [loginState, setLoginState] = useState<TUserInfo | null>();
  const [resource, setResource] = useState<object | null>();
  const [canResp, setCanResp] = useState<object | null>()
  const [products, setProducts] = useState([]);

  useEffect(() => {
    sdk.init();
  }, [])
  /**
   * 以弹窗方式打开 Cashier 托管的登录页
   */
  const loginWithPopup = async () => {
    const res = await sdk.login({
      forced: true
    });
    setLoginState(res);
  };

  const loginWithPopupWithCache = async () => {
    const res = await sdk.login({
      forced: false
    });
    setLoginState(res);
  };

  /**
   * 获取用户的登录状态
   */
  const getLoginState = useCallback(async () => {
    const state = await sdk.getUserInfo();
    console.debug('loginState: ', state)
    setLoginState(state);
  }, [sdk]);

  
  const cleanLoginState = useCallback(async () => {
    const state = await sdk.logout();
    console.debug('loginState: ', state)
    setLoginState(null);
  }, [sdk]);

  const can = (plan: number) => {
    return async (e: any) => {
      console.debug('go to verify Product Level');
      const resp = await sdk.can({
        plan,
        auto: true
      });
      console.debug('can resp: ', resp);
      setCanResp(resp)
      return;
    }
  }

  const productsList = async (e: any) => {
    e.preventDefault();
    const p = await sdk.getProducts()
    setProducts(p);
  }

  return (
    <div>
      <h2>快速集成 Cashier SDK Demo</h2>
      <p>
        <button onClick={loginWithPopup}>login with popup</button>
        <button onClick={loginWithPopupWithCache}>login with popup with cache</button>
        <button onClick={getLoginState}>getLoginState</button>
        <button onClick={cleanLoginState}>cleanLoginState</button>
        {/* <button onClick={purchase}>purchase</button> */}
        <button onClick={can(1)}>can - plan(1)</button>
        <button onClick={can(2)}>can - plan(2)</button>
      </p>
      <p>
        <button onClick={productsList}> products </button>
      </p>
      <p>
        {loginState && (
          <textarea
            cols={100}
            rows={20}
            readOnly
            value={JSON.stringify(loginState, null, 2)}
          ></textarea>
        )}
      </p>
      <p>
        {resource && (
          <textarea
            cols={100}
            rows={5}
            value={JSON.stringify(resource, null, 2)}
          ></textarea>
        )}
      </p>
      <p>
        {canResp && (
          <textarea
            cols={100}
            rows={5}
            value={JSON.stringify(canResp, null, 2)}
          ></textarea>
        )}
      </p>
      <p>
        {products && (
          <textarea
            cols={100}
            rows={5}
            value={JSON.stringify(products, null, 2)}
          ></textarea>
        )}
      </p>
    </div>
  );
}

export default App;

SDK Init Props

export interface CashierOptions {
  /**
   * 认证域名
   *
   * 如果应用未开启单点登录,使用应用域名;如果应用开启了单点登录,使用用户池域名
   */
  domain?: string // TODO: 认证模型调整后统一使用用户池域名
  storageType?: string // 支持插件chrome.storage.sync - 'chrome'

  pageDomain?: string // 登录页面域名
  mobile?: boolean // 是否是移动端页面,适配
  mobileSessId?: string // 移动端跳转的回调ID
  redirect?: boolean // 跳转模式还是弹窗模式,Default: false
  inPage?: boolean // 页面交互方式 弹窗(默认)或者iframe, Default: false
  root?: string // root container for in page popup
  hidePurchase?: boolean // hide purchsae button in the page
  version?: number // SDK 版本号,例如:4,Default: undefined
  privacyLink?: string // 用户隐私协议url
  authTypes?: string // 支持的登录方式,默认ab - a: Email b: Wechat, 例如 authTypes=ab
  /**
   * 应用 ID
   */
  appId: string

   /**
   * 应用 Token
   */
   appToken: string

  debug?: boolean

  /**
   *
   * 对应用户信息的子集
   */
  scope?: string

  /**
   * 弹出窗口的宽度
   */
  popupWidth?: number

  /**
   * 弹出窗口的高度
   */
  popupHeight?: number
}