0.11.20 • Published 3 years ago

@funpodium/fp-captcha-client-react-sdk v0.11.20

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

fpCaptcha Client React SDK

🚧 This is still a WIP project, do not use this in production. 🚧

install

  1. Follow this guide to retrieve a GitLab personal access token.
  2. Run these lines in shell to add the config to npm.
$ npm config set @funpodium:registry https://gitlab.com/api/v4/packages/npm/
$ npm config set -- '//gitlab.com/api/v4/packages/npm/:_authToken' "<your_personal_access_token>"
  1. Run one of these lines to add it to the project's package.json.
npm install @funpodium/fp-captcha-client-react-sdk
# or use yarn
yarn add @funpodium/fp-captcha-client-react-sdk

usage

<FpCaptcha />

all-in-one React component that encapsulate the logic in a nice package.

import { FpCaptcha } from "@funpodium/fp-captcha-client-react-sdk";

const App: React.FC = () => {
  const [visible, useVisible] = useState(false);
  const [challengeUuid, setChallengeUuid] = useState("");

  const startNewChallenge = () => {
    //TODO: get challengeId
  };

  const handlePassed = () => {
    //TODO: after pass
  };

  useEffect(() => {
    startNewChallenge();
  }, []);

  return (
    <FpCaptcha
      visible={visible}
      challengeId={challengeUuid}
      options={{
        window: global.window,
        dialogMode: true,
        config: {
          apiUrl: CAPTCHA_SERVICE_API_URL,
          applicationLocale: "zh",
          chunkSize: 10,
          dragThreshold: 20,
        },
      }}
      onClose={() => setVisible(false)}
      onPassed={handlePassed}
    />
  );
};

 

FpCaptcha Features

AttributeUsageType
visibleshowing the Fpcaptcha componentBoolean
challengeIdchallengeUuid came form client serverString
onClosetriggered when closing()=>void
onPassedtriggered when passing the judgement()=>void
optionssetting of captchaOptionsType

 

FpCaptcha-options

AttributeUsageType
windowwindow which the captcha object binding onWindow
dialogModeFpcaptcha may appear in a dialogboolean
configconfig of captchaConfigType

 

FpCaptcha-options-config

AttributeUsageType
apiUrlmain captcha judgement services urlURL
applicationLocaleLocale of captchastring
dismissTimeunder developing!!number
chunkSizechunk size for the deciphernumber
dragThresholddrag active area on the mapnumber

 

useFpCaptcha hook

a React hook that handles the dirty work for you while it allows you to trigger methods on your command.

import { useFpCaptcha } from "@funpodium/fp-captcha-client-react-sdk";

const App: React.FC = () => {
  const canvasRef = useRef();
  const { build, refresh, result, fpCaptcha } = useFpCaptcha(canvasRef);

  useEffect(() => {
    build();
  }, [build]);

  return <canvas ref={canvasRef} />;
};

 

useFpCaptcha-Return type

AttributeUsageType
buildbuild fpCaptcha component(challengeId: string) => Promise\
refreshrefresh fpCaptcha component() => Promise\
judgementjudgement object return by serverJudgementType
localelocale object return by server (setting of each product)LocaleType
fpCaptchafpCaptcha class object (not usually used / object from js-captcha-sdk)FpCaptchaType
loadingis loadingboolean

 

Type

 

JudgementType

{
  challengeUuid: string;
  code: number;
  message: string;
  isPassed: boolean;
}

LocaleType

{
  fail: string;
  abnormal: string;
  provide: string;
  success: string;
  refresh: string;
  description: string;
  info: string;
}
0.11.20

3 years ago

0.11.8

3 years ago

0.11.9

3 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.11.2

3 years ago

0.11.3

3 years ago

0.11.5

3 years ago

0.11.6

3 years ago

0.11.7

3 years ago

0.10.8

3 years ago

0.11.10

3 years ago

0.11.19

3 years ago

0.11.15

3 years ago

0.11.16

3 years ago

0.11.17

3 years ago

0.11.18

3 years ago

0.11.11

3 years ago

0.11.12

3 years ago

0.11.13

3 years ago

0.11.14

3 years ago

0.10.7

4 years ago

0.10.6

4 years ago

0.10.5

4 years ago