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.
const availableBusinessClasses = await authentic.getBusinessClasses();
const customerBusinessClass = availableBusinessClasses.find(
(businessClass) => businessClass.name === "Juice Bar"
);
const customerStateCodes: Authentic.types.StateCode[] = ["OH", "NY"];
const availableProducts = await authentic.getAvailableProducts(
applicationMeta.businessClassCode,
applicationMeta.stateCodes
);
const customerProduct = availableProducts.find(
(product) => product.name === "General Liability"
);
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.)
const currentQuestion: Authentic.types.ApplicationField =
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: Authentic.types.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 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.
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: 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",
},
},
],
};
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 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>
);
}