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

@kuantaz/api-client

v1.0.0

Published

JS API client to communicate with kzCaptcha.

Downloads

10

Readme

 


Description

With this JavaScript library you can connect to a kzCaptcha installation and verify the submitted data.

Installation

Install this library by using npm:

npm install @kuantaz/api-client

Usage

  1. Create a project in your kzCaptcha installation
  2. Include the kzCaptcha script in your form
<div id="kzCaptcha-box"></div>

<script src="https://[URL]/build/kzCaptcha-frontend.js" defer></script>
<script>
  var m;
  window.onload = function () {
    m = new kzCaptcha("kzCaptcha-box", "https://[URL]", "[UUID]", "[PUBLIC_KEY]", { loadCssResource: true });
  };
</script>
  1. Include the library in your project
const kzCaptcha = require('@kzCaptcha/api-client');
  1. After the form was submitted, verify the data before processing it
let client = new kzCaptcha.Client(host, publicKey, privateKey, {});

kzCaptchaSubmitToken = formData._kzCaptcha_submitToken;
kzCaptchaValidationToken = formData._kzCaptcha_validationToken;

client.verifySubmission(formData, kzCaptchaSubmitToken, kzCaptchaValidationToken).then((verificationResult) => {
  if (verificationResult.isSubmittable()) {
    // Send the email or process the data
  } else {
    // Show error message
  }
});

API Documentation

Client

Client initialization

Create a new client object to use the API client.

/**
 * @param string url URL of the kzCaptcha installation
 * @param string publicKey Public key of the kzCaptcha project
 * @param string privateKey Private key of the kzCaptcha project
 * @param array args Arguments for the axios request
 */
let client = new Client(url, publicKey, privateKey, args);

Verify form data

To verify the form data, call verifySubmission with the form data in an array and the submit and validation token, which kzCaptcha generated on the form initialization and the form data validation. The method will return a new Promise object that is resolved with the VerificationResult object.

/**
 * @param array formData Array with the form values. All not-processed fields by kzCaptcha (hidden, checkbox,
 *                       radio and so on) have to be removed from this array
 * @param string kzCaptchaSubmitToken Submit token which kzCaptcha returned on the form initialization
 * @param string kzCaptchaValidationToken Validation token which kzCaptcha returned after the form was validated
 * @return Promise Returns a Promise object that is resolved with a VerificationResult object
 */
client.verifySubmission(formData, kzCaptchaSubmitToken, kzCaptchaValidationToken).then((validationResult) => {
  if (verificationResult.isSubmittable()) {
    // Do your stuff, e.g. sending emails...
  }
});

VerificationResult

Constants

- FIELD_NOT_VERIFIED: 'not-verified'
- FIELD_VALID: 'valid'
- FIELD_INVALID: 'invalid'

isSubmittable(): boolean

Returns true, if the form is submittable. This means that the verification was successful and the form data are valid.

isValid(): boolean

Returns true, if kzCaptcha determined the form as valid. The difference to isSubmittable() is, that this is the raw result from kzCaptcha while isSubmittable() also checks if the verification was done correctly.

getVerifiedFields(): array (see Constants)

Returns an array with all verified field keys.

getVerifiedField(key): string (see Constants)

Returns the verification status of one field.

hasIssues(): boolean

Returns true, if there were verification issues.

getIssues(): array

Returns an array with all verification issues.