@mcaptcha/core-glue

internal library containig shared glue code

Usage no npm install needed!

<script type="module">
  import mcaptchaCoreGlue from 'https://cdn.skypack.dev/@mcaptcha/core-glue';
</script>

README

Core Glue

Shared code used in other JavaScript glue implementations

NPM 0.1.0 Build) codecov

Usage

A custom glue implementation

  const instanceUrl = "https://api.mcaptcha.org";
  const siteKey: g.SiteKey = {
    key: "randomSitekeyasShowninmCaptchaDashboard",
    instanceUrl: new URL(instanceUrl),
  };

  /** callback function to update hidden input field. Varies for each
   * framework/ glue implementation
   */
  const cb = (token: string): void {
      let input = document.getElementById("mcaptcha__token");
      if (input) {
          input.value =  token;
      }
  }

  const config: g.WidgetConfig = {
    siteKey,
  };

  const r = new Receiver(config, cb.setToken);

  // register listener when component is mounted/necessary HTML for
  // callback function is rendered
  r.listen();

  // teardown
  r.destroy();