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 can be optionally configured on instantiation.
import { Client } from "authentic-ts-client";
const authentic = new Client({
authConfig: {
awsRegion: "us-east-1",
},
});
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.
const availableBusinessClasses = await authentic.getBusinessClasses();
const customerBusinessClass = availableBusinessClasses.find(
(businessClass) => businessClass.name === "Juice Bar"
);
const customerStateCodes = ["OH", "NY"];
const availableProducts = await authentic.getAvailableProducts(
applicationMeta.businessClassCode,
applicationMeta.stateCodes
);
const customerProduct = availableProducts.find(
(product) => product.name === "General Liability"
);
const 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.
const currentQuestion = application.currentSection.fields.find(
(field) => !application.answers.questions[field.name]
);
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.
const exposureAnswer: ApplicationExposureAnswer = {
id: "1",
exposureName: application.currentExposure.name,
fieldValues: {},
};
for (const exposureSection of application.currentExposure.sections) {
for (const exposureQuestion of exposureSection.fields) {
exposureAnswer.fieldValues[exposureQuestion.name] = "Example answer";
}
}
const wasErrorSubmitting = await application.submitExposureAnswer(
authentic.api,
exposureAnswer
);
Authenticating 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.
const wasErrorSending = await authentic.auth.sendCode(
application.meta.email,
true
);
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 = 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 = 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.
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",
MAILING_ADDRESS: "100 Ohio Ave UNIT T2, McDonald, OH 44437, US",
DATE_OF_BIRTH: "1994-01-06T05:00:00.000Z",
NAME: "Customer Name",
PHONE: "1112223333",
FRANCHISE_SELECTED: "No",
GENERIC_BUSINESS_MGMT_PRACTICES_DECLINE: "None of the above",
NUM_BARBERS: "2",
NUM_BEAUTICIANS: "3",
NUM_EMPLOYEES: "5",
PERSONAL_SERVICES_HERBAL_THERAPY: "No",
PERSONAL_SERVICES_KERATIN_BRAZILIAN: "No",
PERSONAL_SERVICES_MANUFACTURE: "No",
PERSONAL_SERVICES_MASSAGE_THERAPY: "No",
PERSONAL_SERVICES_SALON_SPA_FORBIDDEN_ACTIVITIES: "None of the above",
PERSONAL_SERVICES_SWIMMING_POOL: "No",
POLICY_START_DATE: "2023-08-28T04:00:00.000Z",
PRIOR_LOSS_COUNT: "0",
PL_END_ELECT: "No",
},
exposures: [
{
id: "1",
name: "business_location",
fieldValues: {
ADDRESS: "100 street, UNIT 2, city, OH 33333, US",
SALES: "250000",
PAYROLL: "40000",
AREA: "3500",
},
},
],
};
const application = await authentic.createApplication(
prefillData.meta,
prefillData
);
const applicationUrl = getApplicationUrl({
baseUrl: "your-company.authenticinsurance.com/apply",
prefillData,
});
Branding your URL
Authentic allows you to customize the theming of your insurance portal to your brand, giving the end customer a seamless and trustworthy experience.
const themeOverrides: ThemeOverrides = {
brandName: "Your company",
brandLogoUrl: "https://your-company.com/logo.png",
primaryColor: "#000000",
borderRadius: 4,
};
redirectToApplicationUrl({
baseUrl: "your-company.authenticinsurance.com/apply",
prefillData,
themeOverrides,
});