Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

authentic-ts-client

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

authentic-ts-client

TypeScript SDK for interacting with the Authentic API.

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Authentic TypeScript Client

TypeScript SDK for interacting with the Authentic API.

Installation

npm install authentic-ts-client

Instantiating the Client

Most interaction with the SDK is done through the Client class, which must be configured to your tenant's AuthConfig on instantiation.

import * as Authentic from "authentic-ts-client";

const authentic = new Authentic.Client({
  awsRegion: "{{YOUR_AWS_REGION}}",
  awsIdentityPoolId: "{{YOUR_AWS_IDENTITY_POOL_ID}}",
  awsUserPoolId: "{{YOUR_AWS_USER_POOL_ID}}",
  awsUserPoolWebClientId: "{{YOUR_AWS_USER_POOL_WEB_CLIENT_ID}}",
});

Creating an Application

An insurance Application with Authentic consists of three main parts: meta, questions (also referred to as fields), and exposures.

ApplicationMeta can be thought of as a prequalification or "lead" which is submitted to create a new application.

// Find the customer's business class
const availableBusinessClasses = await authentic.getBusinessClasses();
const customerBusinessClass = availableBusinessClasses.find(
  (businessClass) => businessClass.name === "Juice Bar"
);

// Set up the customer's states of operation
const customerStateCodes: Authentic.types.StateCode[] = ["OH", "NY"];

// Choose which insurance product the customer is applying for
const availableProducts = await authentic.getAvailableProducts(
  applicationMeta.businessClassCode,
  applicationMeta.stateCodes
);
const customerProduct = availableProducts.find(
  (product) => product.name === "General Liability"
);

// Submit the customer's `ApplicationMeta` to create a new application
const applicationMeta: Authentic.types.ApplicationMeta = {
  email: "customer@email.com",
  businessClassCode: customerBusinessClass.code,
  stateCodes: customerStateCodes,
  productIds: customerProduct.id;
};
const application = await authentic.createApplication(applicationMeta);

Answering application questions

An Application's questions are broken up into sections. These sections are ordered, as are the questions within them. The SDK provides getters to track which sections have yet to be completed, updating these getters as new answers are submitted.

Note: If accepting user input, each ApplicationField includes properties to validate input as well as display the question. (ex: type, title, description, helperText, minimum, maximum, etc.)

// Find the first question within the current section that has yet to be answered
const currentQuestion: Authentic.types.ApplicationField =
  application.currentSection.fields.find(
    (field) => !application.answers.questions[field.name]
  );

// Submit an answer for the current question
const wasErrorSubmitting = await application.submitQuestionAnswer(
  authentic.api,
  {
    fieldName: currentQuestion.name,
    fieldValue: "Example answer",
  }
);

Submitting exposure answers

Once all Application.sections are complete, at least one answer for each ApplicationExposure must be submitted. Exposures are the last piece of application information needed to generate policy quotes.

// Set up an exposure answer to submit
const exposureAnswer: Authentic.types.ApplicationExposureAnswer = {
  id: "1",
  exposureName: application.currentExposure.name,
  fieldValues: {},
};

// Populate our exposure answer's `fieldValues` (question answers)
for (const exposureSection of application.currentExposure.sections) {
  for (const exposureQuestion of exposureSection.fields) {
    exposureAnswer.fieldValues[exposureQuestion.name] = "Example answer";
  }
}

// Submit the exposure answer
const wasErrorSubmitting = await application.submitExposureAnswer(
  authentic.api,
  exposureAnswer
);

Authenticating the user

In order to generate policy quotes the user must be signed up and authenticated. This is done by a verification code sent to the customer's email.

// Send verification code (flagging `true` to sign up a new user if the email isn't registered)
const wasErrorSending = await authentic.auth.sendCode(
  application.meta.email,
  true
);

// Verify the code
const wasErrorVerifying = await authentic.auth.verifyCode(code);

Generating quotes (applying for insurance)

With a completed Application and an authenticated user, policy quotes can now be generated for the customer. These quotes can purchased by the customer through a generated payment link.

const wasErrorApplying = await application.apply(authentic.api);

const policyQuotes: Authentic.types.QuoteData[] = application.quotes;

const quotesPaymentLink = await application.getQuotesPaymentLink(authentic.api);

Fetching customer policies

With an authenticated user, you can easily fetch all policies associated with that user.

const policies: Authentic.types.Policy[] = await authentic.getPolicies();

Prefill data

An important tool within the SDK is the ability to prefill applications by answering questions on behalf of the end customer. These prefilled answers serve to provide the customer with a "one-click" experience.

Prefilling can be done programmatically when creating an application within the SDK, or encoded into your custom application URL.

Note: You do not need to answer every question, or prefill every property on the application. Applications can be created with partial prefills, with the customer then providing the missing information.

const prefillData: ApplicationPrefillData = {
  meta: {
    email: "customer@email.com",
    businessClassCode: "72311",
    stateCodes: ["OH"],
    productIds: ["aee80d5f-d110-4edb-8708-e5db2190a618"],
  },
  answers: {
    CLASS_DESCRIPTION: "Barber Shops & Beauty Salons",
    MARKET_GROUP_LONG: "Personal Services",
    BUSINESS_LEGAL_NAME: "Customer Business Name",
    NAME: "Customer Name",
    FRANCHISE_SELECTED: "No",
    GENERIC_BUSINESS_MGMT_PRACTICES_DECLINE: "None of the above",
  },
  exposures: [
    {
      id: "1",
      name: "business_location",
      fieldValues: {
        ADDRESS: "100 street, UNIT 2, city, OH 33333, US",
        SALES: "250000",
        PAYROLL: "40000",
        AREA: "3500",
      },
    },
  ],
};

// Prefilling programmatically
const application = await authentic.createApplication(
  prefillData.meta,
  prefillData
);

// Prefilling via encoded URL
const applicationUrl = getApplicationUrl({
  baseUrl: "your-company.authenticinsurance.com/apply",
  prefillData,
});

Branding your URL

Authentic allows you to theme your insurance portal to your brand, giving the end customer a seamless and trustworthy experience.

Below is an example of redirecting your user to a partially prefilled, fully branded insurance application with a React component.

function InsuranceQuoteButton() {
  const baseUrl = "your-company.authenticinsurance.com/apply";
  const prefillData: ApplicationPrefillData = {
    meta: {
      email: "customer@email.com",
      stateCodes: ["OH"],
    },
  };
  const themeOverrides: ThemeOverrides = {
    brandName: "Your company",
    brandLogoUrl: "https://your-company.com/logo.png",
    primaryColor: "#000000",
    borderRadius: 4,
  };

  return (
    <button
      onClick={() =>
        redirectToApplicationUrl({
          baseUrl,
          prefillData,
          themeOverrides,
        })
      }
    >
      Get A Quote
    </button>
  );
}

FAQs

Package last updated on 30 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc