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

yotest-react-sdk

v1.0.2

Published

YoTest React SDK

Downloads

5

Readme

YoTest-React-SDK 文档

基于虚拟机保护、设备特征识别和操作行为识别的新一代智能验证码,具备智能评分、抗 Headless、模拟伪装、针对恶意设备自动提升验证难度等多项安全措施,帮助开发者减少恶意攻击导致的数字资产损失,强力护航业务安全。

仓库入口:

  

兼容性

  • React 17+

安装

npm install yotest-react-sdk --save

快速开始

当你使用 npm 进行安装后,你可以通过 import 直接引入

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    style: {
      width: 300,
      height: 40,
    },
    onSuccess({ token, verified }) {
      console.log("success", token, verified);
    },
    onError({ code, message }) {
      console.log("error", code, message);
    },
  });

  return <div className="App">{render()}</div>;
}

验证模式

  • 浮动式,默认 PC 展现形式,移动端不支持此模式,展示为弹窗式,设置 product: "float" 时生效

float

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    product: "float",
    style: {
      width: 300,
      height: 40,
    },
    onSuccess({ token, verified }) {
      console.log("success", token, verified);
    },
    onError({ code, message }) {
      console.log("error", code, message);
    },
  });

  return <div className="App">{render()}</div>;
}
  • 弹窗式,设置 product: "popup" 时生效

popup

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    product: "popup",
    style: {
      width: 300,
      height: 40,
    },
    onSuccess({ token, verified }) {
      console.log("success", token, verified);
    },
    onError({ code, message }) {
      console.log("error", code, message);
    },
  });

  return <div className="App">{render()}</div>;
}
  • 隐藏式,设置 product: "bind" 时生效,同时需要在 onReady 之后自行调用 verify 方法进行展现

bind

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render, verify } = useYoTest({
    accessId: "your accessId",
    product: "bind",
    style: {
      width: 300,
      height: 40,
    },
    onReady() {
      // 你也可以绑定事件,但需要注意:
      // 一定要在onReady之后进行verify的调用
      verify();
    },
    onSuccess({ token, verified }) {
      console.log("success", token, verified);
    },
    onError({ code, message }) {
      console.log("error", code, message);
    },
  });

  return <div className="App">{render()}</div>;
}
  • 自定义式,设置 product: "custom" 时生效,同时需要设置 area 参数

custom

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    product: "custom",
    area: ".App",
    bgColor: "red",
    style: {
      width: 300,
      height: 40,
    },
    onSuccess({ token, verified }) {
      console.log("success", token, verified);
    },
    onError({ code, message }) {
      console.log("error", code, message);
    },
  });

  return <div className="App">{render()}</div>;
}

API

useYoTest(props)

onReady() => void

  • return: void

监听验证的初始化完成事件。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    onReady() {
      console.log("yotest init completed...");
    },
  });

  return <div className="App">{render()}</div>;
}

onShow() => void

  • return: void

验证框展现的回调。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    onShow() {
      console.log("yotest showed...");
    },
  });

  return <div className="App">{render()}</div>;
}

onSuccess({ token:String, verified:Boolean }) => void

  • data <ValidateResult>
    • token <String> 当前验证的凭证,需要提交给后端来进行是否通过判断
    • verified <Boolean> 是否验证成功
  • return: void

验证成功的监听回调。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    onSuccess({ token, verified }) {
      console.log("success", token, verified);
    },
  });

  return <div className="App">{render()}</div>;
}

onError({ code:Number, message:String }) => void

  • data <ValidateError>
    • code <Number> 错误码
    • message <String> 错误相关信息
  • return: void

验证错误的监听回调。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    onError({ code, message }) {
      console.log("error", code, message);
    },
  });

  return <div className="App">{render()}</div>;
}

onClose() => void

  • return: void

验证关闭的监听回调。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
    onClose() {
      console.log("captcha close");
    },
  });

  return <div className="App">{render()}</div>;
}

render() => React.component

  • return: <React.component>

返回友验的UI DOM。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render } = useYoTest({
    accessId: "your accessId",
  });

  return <div className="App">{render()}</div>;
}

getValidate() => ValidateResult | void

  • return: <ValidateResult>
    • token <String> 当前验证的凭证,需要提交给后端来进行是否通过判断
    • verified <Boolean> 是否验证成功

获取当前验证结果。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render, getValidate } = useYoTest({
    accessId: "your accessId",
    onClose() {
      const { token, verified } = getValidate();
      if (verified) {
        // 通过ajax/fetch将token传给后端相应接口进行判断
      }
    },
  });

  return <div className="App">{render()}</div>;
}

reset() => void

  • return: void

重置 Captcha 当前状态为初始化状态。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render, reset } = useYoTest({
    accessId: "your accessId",
    onError({ code, message }) {
      if(code === -1){
        reset();
      }
    },
  });

  return <div className="App">{render()}</div>;
}

verify() => void

  • return: void

当 product: "bind" 时,调用此API可以呼出验证界面并要求验证。这种方式提供了更好的灵活性,方便开发者在不破坏原由功能和UI的情况下进行集成。

import React from "react";
import useYoTest from "yotest-react-sdk";

export default function App() {
  const { render, verify } = useYoTest({
    accessId: "your accessId",
    product: "bind",
    style: {
      width: 300,
      height: 40,
    },
    onReady() {
      // 你也可以绑定事件,但需要注意:
      // 一定要在onReady之后进行verify的调用
      verify();
    },
  });

  return <div className="App">{render()}</div>;
}