2.6.33 • Published 2 months ago

@authenticins/ts-client v2.6.33

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 months ago

Authentic TypeScript Client

TypeScript SDK for interacting with the Authentic API.

Installation

npm install @authenticins/ts-client

Creating the Client

Most interaction with the SDK is done through the Client class, which must be configured with a base API URL and your tenant's AuthConfig on creation.

import * as Authentic from "@authenticins/ts-client";

const authentic = await Authentic.Client.create("{{AUTHENTIC_API_URL}}", {
  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, fields, and exposures.

ApplicationMeta is a lead that is submitted to create a new application.

// Find the user's business class.
const businessClasses = await authentic.getBusinessClasses();
const userBusinessClass = businessClasses.find(
  (businessClass) => businessClass.name === "Juice Bar"
);

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

// Choose which insurance product the user is applying for.
const products = await authentic.getProducts(
  applicationMeta.businessClassCode,
  applicationMeta.stateCodes
);
const userProduct = products.find(
  (product) => product.backendIds.includes("GENERAL_LIABILITY")
);

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

Submitting a field response

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

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

// Find the first field within the current section that does not have a response.
const currentField: Authentic.types.ApplicationField = application.sections[
  application.firstIncompleteSectionIndex
].fields.find((field) => !application.answers.questions[field.name]);

// Submit a response for the current field.
const wasErrorSubmitting = await application.submitFieldResponses(
  authentic.api,
  [
    {
      fieldName: currentField.name,
      fieldValue: "Example value",
    },
  ]
);

Submitting an exposure reponse

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

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

// Populate our exposure response's `fieldValues`.
for (const exposureSection of application.currentExposure.sections) {
  for (const field of exposureSection.fields) {
    exposureResponse.fieldValues[field.name] = "Example value";
  }
}

// Submit the exposure response.
const wasErrorSubmitting = await application.submitExposureResponse(
  authentic.api,
  exposureResponse
);

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 user'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 user. These quotes can purchased by the user 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 user policies

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

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

Pre-filling data

An important tool within the SDK is the ability to pre-fill applications by responding to fields on behalf of the end user. These pre-filled responses serve to provide the user 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 respond to every field or exposure on the application. Applications can be created with partial pre-fills, with the user then providing the missing information.

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

// Pre-fill programmatically.
const application = await authentic.createApplication(
  prefillData.meta,
  prefillData
);

// Pre-fill via encoded URL.
const insurancePortalUrl = Authentic.utils.getEncodedInsurancePortalUrl(
  "https://partner-name.authenticinsurance.com",
  prefillData
);

Branding your URL

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

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

function InsuranceQuoteButton() {
  const baseInsurancePortalUrl = "https://partner-name.authenticinsurance.com";
  const prefillData: Authentic.types.ApplicationPrefillData = {
    meta: {
      email: "user@email.com",
      stateCodes: ["OH"],
    },
  };
  const themeOverrides: Authentic.types.ThemeOverrides = {
    brand: {
      name: "Partner Name",
      logoUrls:  {
        light: "https://partner-website.com/logo-white.png",
        dark: "https://partner-website.com/logo.png",
      },
      faviconUrl: "https://partner-website.com/favicon.ico",
    }
    primaryColor: "#000000",
    borderRadius: 4,
  };

  return (
    <button
      onClick={() =>
        Authentic.utils.redirectToInsurancePortalUrl(
          baseInsurancePortalUrl,
          prefillData,
          themeOverrides
        )
      }
    >
      Get A Quote
    </button>
  );
}

Managing reactivity

If you'd like to trigger state changes in your frontend application upon Client auth changes, or an changes in an insurance Application, you can pass callback functions upon creation.

function App() {
  const [authentic, setAuthentic] = useState<Authentic.Client | null>(null);
  const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
  const [application, setApplication] =
    useState<Authentic.types.Application | null>(null);

  function onAuthChange(auth: Authentic.types.Auth) {
    setIsAuthenticated(auth.isAuthenticated);
  }
  function onApplicationChange(application: Authentic.types.Application) {
    setApplication(application);
  }

  useEffect(() => {
    async function initAuthenticClient() {
      const authentic = await Authentic.Client.create(
        "{{AUTHENTIC_API_URL}}",
        {
          awsRegion: "{{YOUR_AWS_REGION}}",
          awsIdentityPoolId: "{{YOUR_AWS_IDENTITY_POOL_ID}}",
          awsUserPoolId: "{{YOUR_AWS_USER_POOL_ID}}",
          awsUserPoolWebClientId: "{{YOUR_AWS_USER_POOL_WEB_CLIENT_ID}}",
        },
        onAuthChange,
        onApplicationChange
      );
      setAuthentic(authentic);
    }
    initAuthenticClient();
  }, []);
}
2.6.33

2 months ago

2.6.32

2 months ago

2.6.30

3 months ago

2.6.31

3 months ago

3.0.1

3 months ago

3.0.0

3 months ago

2.6.29

3 months ago

2.6.27

3 months ago

2.6.28

3 months ago

2.6.26

3 months ago

2.6.23

4 months ago

2.6.24

4 months ago

2.6.25

4 months ago

2.6.22

4 months ago

2.6.21

4 months ago

2.6.19

4 months ago

2.6.18

4 months ago

2.6.20

4 months ago

2.6.17

4 months ago

2.6.16

4 months ago

2.6.15

4 months ago

2.6.14

4 months ago

2.6.11

4 months ago

2.6.12

4 months ago

2.6.13

4 months ago

2.6.10

4 months ago

2.6.9

4 months ago

2.6.7

4 months ago

2.6.8

4 months ago

2.6.6

5 months ago

2.6.5

5 months ago

2.6.4

5 months ago

2.6.3

5 months ago

2.6.2

5 months ago

2.6.1

5 months ago

2.6.0

5 months ago

2.5.10

5 months ago

2.5.11

5 months ago

2.5.12

5 months ago

2.5.8

5 months ago

2.5.7

5 months ago

2.5.9

5 months ago

2.5.6

5 months ago

2.4.3

6 months ago

2.4.2

6 months ago

2.4.5

6 months ago

2.4.4

6 months ago

2.5.0

5 months ago

2.5.2

5 months ago

2.5.1

5 months ago

2.5.4

5 months ago

2.5.3

5 months ago

2.4.7

5 months ago

2.4.6

6 months ago

2.4.8

5 months ago

2.2.1

6 months ago

2.2.0

6 months ago

2.4.1

6 months ago

2.4.0

6 months ago

2.1.5

6 months ago

2.1.4

7 months ago

2.1.3

7 months ago

2.1.2

7 months ago

2.1.1

7 months ago

2.1.0

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.100.0

7 months ago

1.3.7

7 months ago

1.3.6

7 months ago

1.3.5

7 months ago

1.3.4

7 months ago

1.3.3

7 months ago

1.3.2

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.9

7 months ago

1.2.8

7 months ago

1.2.7

7 months ago

1.2.6

7 months ago

1.2.5

8 months ago

1.2.4

8 months ago

1.2.3

8 months ago

1.2.2

8 months ago

1.2.1

8 months ago

1.2.0

8 months ago

1.1.9

8 months ago

1.1.8

8 months ago

1.1.7

8 months ago

1.1.6

8 months ago

1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

0.0.0

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago

0.0.1

8 months ago