@instabrain-sdks/api-client 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +430 -53
- package/dist/client/instabrain-client.d.ts +49 -13
- package/dist/client/instabrain-client.js +49 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -1
- package/dist/services/adb.service.d.ts +1 -1
- package/dist/services/adb.service.js +1 -1
- package/dist/services/application.service.d.ts +9 -2
- package/dist/services/application.service.js +9 -2
- package/dist/services/finalexpense.service.d.ts +1 -1
- package/dist/services/finalexpense.service.js +1 -1
- package/dist/services/gigdb.service.d.ts +19 -8
- package/dist/services/gigdb.service.js +20 -9
- package/dist/services/ibterm.service.d.ts +17 -5
- package/dist/services/ibterm.service.js +17 -5
- package/dist/services/pureterm.service.d.ts +12 -4
- package/dist/services/pureterm.service.js +12 -4
- package/dist/types/application.types.d.ts +27 -5
- package/dist/types/constants.d.ts +11 -0
- package/dist/types/constants.js +12 -1
- package/dist/types/enums.d.ts +17 -4
- package/dist/types/enums.js +18 -4
- package/dist/types/errors.d.ts +4 -4
- package/dist/types/errors.js +3 -2
- package/dist/types/gigdb.types.d.ts +34 -7
- package/dist/types/ibterm.types.d.ts +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/webhook.types.d.ts +55 -0
- package/dist/types/webhook.types.js +3 -0
- package/dist/utils/webhook-signature.d.ts +72 -0
- package/dist/utils/webhook-signature.js +172 -0
- package/package.json +19 -13
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ TypeScript SDK for Node.js. All operations go through `InstaBrainClient` — req
|
|
|
7
7
|
**Products covered:** GIGDB, ADB, IB Term, Pure Term.
|
|
8
8
|
|
|
9
9
|
- **GIGDB & ADB** — full client flow: `get*Quote()` → `start*Application()` → `saveEftPayment()` → SecureSign methods → `finalSubmit()`.
|
|
10
|
-
- **IB Term** — client flow ends at `startIBTermApplication()`; use returned `agentLink` / `applicantLink` / `eAppAgentLink` for the InstaBrain frontend.
|
|
10
|
+
- **IB Term** — client flow ends at `startIBTermApplication()`; use returned `agentLink` / `applicantLink` / `eAppAgentLink` for the InstaBrain frontend. The shared `saveEftPayment()` is the one optional exception.
|
|
11
11
|
- **Pure Term** — pre-fill flow: `getPureTermQuote()` → `startPureTermApplication()`; use returned links for the InstaBrain frontend.
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
@@ -60,31 +60,39 @@ Credentials (`userId` and `accessToken`) are provisioned during onboarding.
|
|
|
60
60
|
- [Update quote](#final-expense--update-quote)
|
|
61
61
|
- [Underwriting status (async)](#final-expense--underwriting-status-async)
|
|
62
62
|
- [GIGDB pivot after a decline](#gigdb-pivot--after-a-final-expense-decline)
|
|
63
|
-
9. [
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
9. [Generic start application](#generic-start-application)
|
|
64
|
+
10. [Application-status webhooks](#application-status-webhooks)
|
|
65
|
+
- [Registering for webhooks](#registering-for-webhooks)
|
|
66
|
+
- [Your endpoint](#your-endpoint)
|
|
67
|
+
- [Verifying signatures](#verifying-signatures)
|
|
68
|
+
- [Envelope & events](#envelope--events)
|
|
69
|
+
- [Idempotency & ordering](#idempotency--ordering)
|
|
70
|
+
- [Delivery is best-effort](#delivery-is-best-effort)
|
|
71
|
+
11. [Shared methods — GIGDB, ADB & Final Expense](#shared-methods--gigdb-adb--final-expense)
|
|
72
|
+
- [Payment — EFT or credit card](#payment--eft-or-credit-card)
|
|
73
|
+
- [Get credit card iframe URL](#get-credit-card-iframe-url)
|
|
74
|
+
- [Credit card payment status](#credit-card-payment-status)
|
|
75
|
+
- [Save EFT payment](#save-eft-payment)
|
|
76
|
+
- [Prepare docs & get delivery channels](#prepare-docs--get-delivery-channels)
|
|
77
|
+
- [Send PIN & get documents link](#send-pin--get-documents-link)
|
|
78
|
+
- [Resend PIN](#resend-pin)
|
|
79
|
+
- [Verify PIN](#verify-pin)
|
|
80
|
+
- [Final submit](#final-submit)
|
|
81
|
+
12. [Reporting](#reporting)
|
|
82
|
+
- [Request fields](#request-fields-shared-shape)
|
|
83
|
+
- [Filters (`SQLOperator`)](#filters--sqloperator-enum)
|
|
84
|
+
- [Response shapes](#response-shapes)
|
|
85
|
+
13. [Enums & Constants](#enums--constants)
|
|
86
|
+
14. [Beneficiary Reference](#beneficiary-reference)
|
|
79
87
|
- [No extra fields](#variant-1--no-extra-fields)
|
|
80
88
|
- [Named person](#variant-2--named-person)
|
|
81
89
|
- [Named entity](#variant-3--named-entity)
|
|
82
|
-
|
|
90
|
+
15. [Error Handling](#error-handling)
|
|
83
91
|
- [Error class hierarchy](#error-class-hierarchy)
|
|
84
92
|
- [Using `APIValidationError`](#using-apivalidationerror)
|
|
85
93
|
- [`BaseResponse<T>` envelope](#baseresponset-envelope)
|
|
86
94
|
- [Field-level error messages](#field-level-error-messages)
|
|
87
|
-
|
|
95
|
+
16. [Error codes (`APIErrorCode`)](#apierrorcode-reference)
|
|
88
96
|
- [Quote errors](#quote-errors)
|
|
89
97
|
- [Start application errors](#start-application-errors)
|
|
90
98
|
- [Payment & quote update errors](#payment--quote-update-errors)
|
|
@@ -92,10 +100,10 @@ Credentials (`userId` and `accessToken`) are provisioned during onboarding.
|
|
|
92
100
|
- [Final submit errors](#final-submit-errors)
|
|
93
101
|
- [Session](#session)
|
|
94
102
|
- [Deprecated codes (reference only)](#deprecated-codes-reference-only)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
17. [Environment Configuration](#environment-configuration)
|
|
104
|
+
18. [Token Management](#token-management)
|
|
105
|
+
19. [Examples Directory](#examples-directory)
|
|
106
|
+
20. [Support](#support)
|
|
99
107
|
|
|
100
108
|
---
|
|
101
109
|
|
|
@@ -1116,7 +1124,7 @@ const updatedQuote = await client.updateAdbQuote({
|
|
|
1116
1124
|
|
|
1117
1125
|
**InstaBrain Term** — term life product, no medical exam.
|
|
1118
1126
|
|
|
1119
|
-
This is a **pre-fill flow**: use `getQuote()` and `startIBTermApplication()`, then hand off via `agentLink`, `applicantLink`, and `eAppAgentLink`. Do **not** call
|
|
1127
|
+
This is a **pre-fill flow**: use `getQuote()` and `startIBTermApplication()`, then hand off via `agentLink`, `applicantLink`, and `eAppAgentLink`. Do **not** call SecureSign methods, `finalSubmit()`, or the credit-card iframe for IB Term. The shared [`saveEftPayment()`](#save-eft-payment) is allowed.
|
|
1120
1128
|
|
|
1121
1129
|
- **Eligible ages:** 18–60
|
|
1122
1130
|
- **Not available in:** WY, NY
|
|
@@ -1132,13 +1140,16 @@ This is a **pre-fill flow**: use `getQuote()` and `startIBTermApplication()`, th
|
|
|
1132
1140
|
└── flagProductNotAvailableForState = true → STOP
|
|
1133
1141
|
1. [`getQuote()`](#ib-term--get-quote) Get quote → quoteResponseId
|
|
1134
1142
|
2. [`startIBTermApplication()`](#ib-term--start-application) Start app → agentLink / applicantLink
|
|
1135
|
-
├── isDeclined = true
|
|
1143
|
+
├── isDeclined = true + empty / all-zero opportunityId → STOP (knockout, no application)
|
|
1144
|
+
├── isDeclined = true + real opportunityId → keep the id and any links
|
|
1136
1145
|
└── isQuoteChanged = true → re-present updated premium, then hand off via links
|
|
1137
1146
|
3. [`getExistingIBTermQuote()`](#ib-term--get-existing-quote) [Optional] Re-fetch prior quote for resumed session
|
|
1138
1147
|
|
|
1139
1148
|
→ Direct agent or applicant to agentLink / applicantLink / eAppAgentLink
|
|
1140
1149
|
All remaining steps (underwriting, payment, signing) complete inside the InstaBrain frontend.
|
|
1141
|
-
No further `InstaBrainClient` methods for IB Term
|
|
1150
|
+
No further `InstaBrainClient` methods for IB Term, except the optional shared saveEftPayment()
|
|
1151
|
+
(bank payment, including Pay Later). To follow the outcome, opt in to
|
|
1152
|
+
application-status webhooks on start-application (see Application-status webhooks).
|
|
1142
1153
|
```
|
|
1143
1154
|
|
|
1144
1155
|
---
|
|
@@ -1340,7 +1351,7 @@ Many fields are **optional** — validated only when sent. Backend validation fi
|
|
|
1340
1351
|
|
|
1341
1352
|
**Always required:** `quoteResponseId`, `firstName`, `lastName`, `email`, `phoneNumber`, `isUsCitizenOrIsPermanentResident`, `isPayerAlsoOwnerAndInsured`, `height`, `weight`, `isHoldingValidDriverLicense`, `areListedConditionsNotApplicable`.
|
|
1342
1353
|
|
|
1343
|
-
**Optional — validated when sent:** `address`, `dateOfBirth`, `socialSecurityNumber`, `birthJurisdiction`, `driverLicenseState`, `driverLicenseNumber`, `hasPrimaryCarePhysician` / `physicianDetails`, `tobaccoNicotineUsage`, `hasExistingCoverage` / `existingCoverageData`, `beneficiaryDetails`.
|
|
1354
|
+
**Optional — validated when sent:** `address`, `dateOfBirth`, `socialSecurityNumber`, `birthJurisdiction`, `driverLicenseState`, `driverLicenseNumber`, `hasPrimaryCarePhysician` / `physicianDetails`, `tobaccoNicotineUsage`, `hasExistingCoverage` / `existingCoverageData`, `beneficiaryDetails`, `webhookRegistrationDetails`.
|
|
1344
1355
|
|
|
1345
1356
|
**Conditional:** `childRiderInfo` — required when Dependent Child Rider is on the quote; must not be sent otherwise.
|
|
1346
1357
|
|
|
@@ -1506,6 +1517,25 @@ IB Term accepts only: `Person`, `Trust`, `Insured Estate`, `All Children Of The
|
|
|
1506
1517
|
> Total `insuranceAmount` for entries where `toBeReplaced = false` must not exceed $100,000.
|
|
1507
1518
|
|
|
1508
1519
|
|
|
1520
|
+
***
|
|
1521
|
+
|
|
1522
|
+
### Webhook Registration (optional)
|
|
1523
|
+
|
|
1524
|
+
Opt in to [application-status webhooks](#application-status-webhooks) for the opportunity this call creates. Omit `webhookRegistrationDetails` or pass `null` for no callbacks — both are treated the same.
|
|
1525
|
+
|
|
1526
|
+
| Field | Type | Required | Validation Error |
|
|
1527
|
+
|---|---|---|---|
|
|
1528
|
+
| `webhookRegistrationDetails` | `WebhookRegistrationDetails \| null` | No | — |
|
|
1529
|
+
| `webhookRegistrationDetails.callbackUrl` | `string` | When the object is sent | `Webhook registration callbackUrl is required when webhookRegistrationDetails is provided.` / `callbackUrl must be at most 2048 characters.` / `callbackUrl must be an absolute HTTPS URL.` |
|
|
1530
|
+
| `webhookRegistrationDetails.secretKey` | `string` | When the object is sent | `Webhook registration secretKey is required when webhookRegistrationDetails is provided.` / `secretKey must be between 16 and 256 characters.` |
|
|
1531
|
+
|
|
1532
|
+
- `callbackUrl` must be an absolute **HTTPS** URL, max 2048 characters, in **both sandbox and production** — `http://` is rejected. Use a public HTTPS tunnel for local testing.
|
|
1533
|
+
- `secretKey` is 16–256 characters. Keep it server-side; you need it to verify every delivery.
|
|
1534
|
+
- An empty object `{}` is not a skip — both fields are then required, and the request fails.
|
|
1535
|
+
- Invalid details fail the whole request with `InvalidRequestFormat` under `value.fields['WebhookRegistrationDetails.CallbackUrl']` / `['WebhookRegistrationDetails.SecretKey']`, and **no application is created**.
|
|
1536
|
+
- One callback per opportunity. It cannot be changed after start-application.
|
|
1537
|
+
|
|
1538
|
+
|
|
1509
1539
|
***
|
|
1510
1540
|
|
|
1511
1541
|
### Business Rules
|
|
@@ -1522,7 +1552,12 @@ IB Term accepts only: `Person`, `Trust`, `Insured Estate`, `All Children Of The
|
|
|
1522
1552
|
|
|
1523
1553
|
### Knockout Rules
|
|
1524
1554
|
|
|
1525
|
-
Returns `isDeclined: true` on a successful response — the SDK does **not** throw.
|
|
1555
|
+
Returns `isDeclined: true` on a successful response — the SDK does **not** throw. Read `isDeclined` **together with `opportunityId`**:
|
|
1556
|
+
|
|
1557
|
+
- **Knockout** — `opportunityId` is empty or all-zero. No application exists, no links are returned, and no webhook is registered. Stop.
|
|
1558
|
+
- **Declined after the application was created** — `opportunityId` is a real GUID. Keep it, and keep `agentLink` / `applicantLink` / `eAppAgentLink` if they are present. Trust this response; do not wait for a `Declined` webhook for this call.
|
|
1559
|
+
|
|
1560
|
+
These inputs are knockouts:
|
|
1526
1561
|
|
|
1527
1562
|
- `isPayerAlsoOwnerAndInsured = false`
|
|
1528
1563
|
- `isUsCitizenOrIsPermanentResident = false`
|
|
@@ -1557,14 +1592,14 @@ When `isQuoteChanged = true`, the carrier adjusted the premium. Re-present the u
|
|
|
1557
1592
|
|
|
1558
1593
|
| Field | Type | Description |
|
|
1559
1594
|
|---|---|---|
|
|
1560
|
-
| `opportunityId` | `string` |
|
|
1561
|
-
| `isDeclined` | `boolean` | `true` =
|
|
1595
|
+
| `opportunityId` | `string` | Empty or all-zero UUID on a knockout (no application). Same value as the webhook `opportunityUid` |
|
|
1596
|
+
| `isDeclined` | `boolean` | `true` = declined. Stop only when `opportunityId` is empty or all-zero; otherwise keep the id and links |
|
|
1562
1597
|
| `isQuoteChanged` | `boolean` | `true` = carrier adjusted premium; re-present before handoff |
|
|
1563
1598
|
| `agentLink` | `string\|null` | Agent Conversational UI |
|
|
1564
1599
|
| `applicantLink` | `string\|null` | Applicant Conversational UI |
|
|
1565
1600
|
| `eAppAgentLink` | `string\|null` | Agent E-App |
|
|
1566
1601
|
|
|
1567
|
-
> After a non-declined response, direct the agent or applicant to the appropriate link. All remaining steps (underwriting, payment, signing) complete inside the InstaBrain frontend.
|
|
1602
|
+
> After a non-declined response, direct the agent or applicant to the appropriate link. All remaining steps (underwriting, payment, signing) complete inside the InstaBrain frontend — bank payment can alternatively be saved with the shared [`saveEftPayment()`](#save-eft-payment). To follow the outcome, send `webhookRegistrationDetails` on this start-application call — see [application-status webhooks](#application-status-webhooks) (delivery is best-effort).
|
|
1568
1603
|
|
|
1569
1604
|
|
|
1570
1605
|
***
|
|
@@ -1595,16 +1630,22 @@ const appResp = await client.startIBTermApplication({
|
|
|
1595
1630
|
beneficiaryDetails: {
|
|
1596
1631
|
beneficiaryType: BeneficiaryType.Person,
|
|
1597
1632
|
beneficiaryPerson: { firstName: 'Mary', lastName: 'Smith', relationship: BeneficiaryRelationship.Spouse }
|
|
1633
|
+
},
|
|
1634
|
+
// Optional — receive application-status webhooks for this opportunity
|
|
1635
|
+
webhookRegistrationDetails: {
|
|
1636
|
+
callbackUrl: 'https://partner.example.com/webhooks/instabrain',
|
|
1637
|
+
secretKey: process.env.INSTABRAIN_WEBHOOK_SECRET!
|
|
1598
1638
|
}
|
|
1599
1639
|
});
|
|
1600
1640
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1641
|
+
const ALL_ZERO = '00000000-0000-0000-0000-000000000000';
|
|
1642
|
+
if (appResp.isDeclined && (!appResp.opportunityId || appResp.opportunityId === ALL_ZERO)) {
|
|
1643
|
+
return; // Knockout — no application exists
|
|
1603
1644
|
}
|
|
1604
1645
|
if (appResp.isQuoteChanged) {
|
|
1605
1646
|
// Re-present updated premium before directing to link
|
|
1606
1647
|
}
|
|
1607
|
-
// Hand off to InstaBrain frontend
|
|
1648
|
+
// Hand off to InstaBrain frontend. Persist opportunityId to match webhook deliveries.
|
|
1608
1649
|
console.log('Applicant link:', appResp.applicantLink);
|
|
1609
1650
|
```
|
|
1610
1651
|
|
|
@@ -1692,13 +1733,16 @@ Coverage and benefit-period availability tables are Pure-Term-specific — see [
|
|
|
1692
1733
|
└── flagProductNotAvailableForState = true → STOP (not sold in this state)
|
|
1693
1734
|
2. [`getPureTermQuote()`](#pure-term--get-quote) Get quote → quoteResponseId
|
|
1694
1735
|
3. [`startPureTermApplication()`](#pure-term--start-application) Start app → opportunityId + links
|
|
1695
|
-
├── isDeclined = true
|
|
1736
|
+
├── isDeclined = true + empty / all-zero opportunityId → STOP (knockout, no application)
|
|
1737
|
+
├── isDeclined = true + real opportunityId → keep the id and any links
|
|
1696
1738
|
└── isQuoteChanged = true → re-present updated premium, then hand off via links
|
|
1697
1739
|
|
|
1698
1740
|
[`getPureTermExistingQuote()`](#pure-term--get-existing-quote) (optional) Re-fetch the stored quote
|
|
1699
1741
|
|
|
1700
1742
|
→ Direct agent or applicant to agentLink / applicantLink / eAppAgentLink
|
|
1701
|
-
All remaining steps complete inside the InstaBrain frontend
|
|
1743
|
+
All remaining steps complete inside the InstaBrain frontend (the shared saveEftPayment() is
|
|
1744
|
+
allowed for bank payment). To follow the outcome, opt in to
|
|
1745
|
+
application-status webhooks on start-application (see Application-status webhooks).
|
|
1702
1746
|
```
|
|
1703
1747
|
|
|
1704
1748
|
---
|
|
@@ -1972,7 +2016,7 @@ console.log(existing.selectedQuote.quoteAmount, existing.selectedQuote.benefitPe
|
|
|
1972
2016
|
|
|
1973
2017
|
**Method:** `client.startPureTermApplication(request)` · **Type:** `PureTermStartApplicationReq`
|
|
1974
2018
|
|
|
1975
|
-
A **dedicated** Pure Term endpoint. This is separate from the generic `client.startApplication()
|
|
2019
|
+
A **dedicated** Pure Term endpoint. This is separate from the [generic `client.startApplication()`](#generic-start-application) — do not substitute one for the other.
|
|
1976
2020
|
|
|
1977
2021
|
The backend shares one request contract between IB Term and Pure Term start-application: same fields, same nesting, same optionality, same validation messages. `PureTermStartApplicationReq` is therefore the same structure as `IBTermStartApplicationReq`, and the full field-by-field tables in [IB Term — Start Application](#ib-term--start-application) apply here unchanged. Only the differences are listed below.
|
|
1978
2022
|
|
|
@@ -1984,6 +2028,7 @@ The backend shares one request contract between IB Term and Pure Term start-appl
|
|
|
1984
2028
|
| Field | Type | Required | Description |
|
|
1985
2029
|
|---|---|---|---|
|
|
1986
2030
|
| `quoteResponseId` | `string` | Yes | UUID from `getPureTermQuote()` — must belong to the **Pure Term** product |
|
|
2031
|
+
| `webhookRegistrationDetails` | `WebhookRegistrationDetails \| null` | No | Opt in to [application-status webhooks](#application-status-webhooks). Same rules and messages as [IB Term — Webhook Registration](#webhook-registration-optional) |
|
|
1987
2032
|
| *(all other fields)* | — | — | Identical to [IB Term — Start Application](#ib-term--start-application) |
|
|
1988
2033
|
|
|
1989
2034
|
> `proCode` does **not** apply here — it belongs to the generic `startApplication()` only.
|
|
@@ -1993,7 +2038,7 @@ The backend shares one request contract between IB Term and Pure Term start-appl
|
|
|
1993
2038
|
|
|
1994
2039
|
### Business Rules
|
|
1995
2040
|
|
|
1996
|
-
1. `isDeclined: true` is a valid success response
|
|
2041
|
+
1. `isDeclined: true` is a valid success response — the SDK does **not** throw. Stop only on a knockout (empty or all-zero `opportunityId`); with a real `opportunityId`, keep the id and any links.
|
|
1997
2042
|
2. When `isQuoteChanged = true`, the carrier adjusted the premium. Re-present it before directing the applicant to the link, or call `getPureTermExistingQuote()` to read the updated quote.
|
|
1998
2043
|
3. `quoteResponseId` must belong to Pure Term, otherwise: `QuoteResponseId does not exist or does not belong to the requested product.`
|
|
1999
2044
|
4. `address.state` (when sent) must match the quote state — a mismatch returns `StateMismatchIdentified`.
|
|
@@ -2002,13 +2047,14 @@ The backend shares one request contract between IB Term and Pure Term start-appl
|
|
|
2002
2047
|
7. `physicianDetails.stateCode` rejects both `"Outside Of The USA"` and `"OutsideUSA"`.
|
|
2003
2048
|
8. Pure Term does **not** run the `ApplicationLimitReached` duplicate SSN/email/phone check (that applies to GIGDB, ADB, and Final Expense).
|
|
2004
2049
|
9. Validation returns at most one message per field; `value.fields` keys are PascalCase and may be nested (e.g. `ChildRiderInfo.IsAnyChildTakingMedication`).
|
|
2050
|
+
10. `webhookRegistrationDetails` follows the IB Term rules: omit or `null` for no callbacks; when sent, `callbackUrl` (absolute HTTPS in sandbox and production) and `secretKey` (16–256 characters) are both required. Invalid details fail with `InvalidRequestFormat` and no application is created.
|
|
2005
2051
|
|
|
2006
2052
|
|
|
2007
2053
|
***
|
|
2008
2054
|
|
|
2009
2055
|
### Knockout Rules
|
|
2010
2056
|
|
|
2011
|
-
Any of the following returns HTTP `200` with `isDeclined: true` —
|
|
2057
|
+
Any of the following returns HTTP `200` with `isDeclined: true` and an empty or all-zero `opportunityId` — no application exists, and no webhook is registered. The SDK does **not** throw; check the fields explicitly. When `isDeclined` is `true` with a **real** `opportunityId`, the application was declined after it was created — keep the id and any returned links, and do not wait for a `Declined` webhook for this call.
|
|
2012
2058
|
|
|
2013
2059
|
- `isUsCitizenOrIsPermanentResident = false`
|
|
2014
2060
|
- `isPayerAlsoOwnerAndInsured = false`
|
|
@@ -2039,14 +2085,14 @@ Start Application is one shared service across both Term products, so the code s
|
|
|
2039
2085
|
|
|
2040
2086
|
| Field | Type | Description |
|
|
2041
2087
|
|---|---|---|
|
|
2042
|
-
| `opportunityId` | `string` |
|
|
2043
|
-
| `isDeclined` | `boolean` | `true` =
|
|
2088
|
+
| `opportunityId` | `string` | Empty or all-zero UUID on a knockout (no application). Same value as the webhook `opportunityUid` |
|
|
2089
|
+
| `isDeclined` | `boolean` | `true` = declined. Stop only when `opportunityId` is empty or all-zero; otherwise keep the id and links |
|
|
2044
2090
|
| `isQuoteChanged` | `boolean` | `true` = carrier adjusted premium; re-present before handoff |
|
|
2045
2091
|
| `agentLink` | `string \| null` | Agent Conversational UI |
|
|
2046
2092
|
| `applicantLink` | `string \| null` | Applicant Conversational UI |
|
|
2047
2093
|
| `eAppAgentLink` | `string \| null` | Agent E-App |
|
|
2048
2094
|
|
|
2049
|
-
> After a non-declined response, direct the agent or applicant to the appropriate link. All remaining steps (underwriting, payment, signing) complete inside the InstaBrain frontend. Do not pass this `opportunityId` to `finalSubmit()`, the SecureSign methods, or the credit-card iframe.
|
|
2095
|
+
> After a non-declined response, direct the agent or applicant to the appropriate link. All remaining steps (underwriting, payment, signing) complete inside the InstaBrain frontend — bank payment can alternatively be saved with the shared [`saveEftPayment()`](#save-eft-payment). Do not pass this `opportunityId` to `finalSubmit()`, the SecureSign methods, or the credit-card iframe. To follow the outcome, send `webhookRegistrationDetails` on this start-application call — see [application-status webhooks](#application-status-webhooks) (delivery is best-effort).
|
|
2050
2096
|
|
|
2051
2097
|
|
|
2052
2098
|
***
|
|
@@ -2094,18 +2140,24 @@ const appResp = await client.startPureTermApplication({
|
|
|
2094
2140
|
lastName: 'Doe',
|
|
2095
2141
|
relationship: BeneficiaryRelationship.Spouse
|
|
2096
2142
|
}
|
|
2143
|
+
},
|
|
2144
|
+
// Optional — receive application-status webhooks for this opportunity
|
|
2145
|
+
webhookRegistrationDetails: {
|
|
2146
|
+
callbackUrl: 'https://partner.example.com/webhooks/instabrain',
|
|
2147
|
+
secretKey: process.env.INSTABRAIN_WEBHOOK_SECRET!
|
|
2097
2148
|
}
|
|
2098
2149
|
// childRiderInfo — send ONLY when the Dependent Child Rider is on the quote
|
|
2099
2150
|
});
|
|
2100
2151
|
|
|
2101
|
-
|
|
2102
|
-
|
|
2152
|
+
const ALL_ZERO = '00000000-0000-0000-0000-000000000000';
|
|
2153
|
+
if (appResp.isDeclined && (!appResp.opportunityId || appResp.opportunityId === ALL_ZERO)) {
|
|
2154
|
+
return; // Knockout — no application exists
|
|
2103
2155
|
}
|
|
2104
2156
|
if (appResp.isQuoteChanged) {
|
|
2105
2157
|
const updated = await client.getPureTermExistingQuote(appResp.opportunityId);
|
|
2106
2158
|
// Re-present updated premium before directing to link
|
|
2107
2159
|
}
|
|
2108
|
-
// Hand off to InstaBrain frontend
|
|
2160
|
+
// Hand off to InstaBrain frontend. Persist opportunityId to match webhook deliveries.
|
|
2109
2161
|
console.log('Applicant link:', appResp.applicantLink);
|
|
2110
2162
|
```
|
|
2111
2163
|
|
|
@@ -2869,9 +2921,273 @@ await client.saveEftPayment({ opportunityId: gigdbOpportunityId, /* … */ } as
|
|
|
2869
2921
|
|
|
2870
2922
|
---
|
|
2871
2923
|
|
|
2924
|
+
## Generic Start Application
|
|
2925
|
+
|
|
2926
|
+
**Method:** `client.startApplication(request)` · **Type:** `ThirdPartyStartApplicationReq` · **Endpoint:** `POST /api/ThirdPartyStartApp/start-application`
|
|
2927
|
+
|
|
2928
|
+
The older, generic start-application endpoint. It starts an application from a quote and returns `opportunityId` plus links for the InstaBrain frontend. Pass `proCode` to start a specific product variant.
|
|
2929
|
+
|
|
2930
|
+
> For IB Term and Pure Term, InstaBrain recommends the dedicated [`startIBTermApplication()`](#ib-term--start-application) and [`startPureTermApplication()`](#pure-term--start-application), which carry the full request contract.
|
|
2931
|
+
|
|
2932
|
+
|
|
2933
|
+
***
|
|
2934
|
+
|
|
2935
|
+
### Request Fields
|
|
2936
|
+
|
|
2937
|
+
| Field | Type | Required | Description |
|
|
2938
|
+
|---|---|---|---|
|
|
2939
|
+
| `quoteResponseId` | `string` | Yes | UUID from the product quote response |
|
|
2940
|
+
| `firstName` | `string \| null` | Yes — pass `null` if not collected | Overrides the first name given on the quote |
|
|
2941
|
+
| `lastName` | `string \| null` | Yes — pass `null` if not collected | Overrides the last name given on the quote |
|
|
2942
|
+
| `email` | `string \| null` | Yes — pass `null` if not collected | Applicant email |
|
|
2943
|
+
| `phoneNumber` | `string \| null` | Yes — pass `null` if not collected | Applicant phone |
|
|
2944
|
+
| `proCode` | `string \| null` | No | Product variant code. Omit to start the base product; contact InstaBrain support for the correct code |
|
|
2945
|
+
| `webhookRegistrationDetails` | `WebhookRegistrationDetails \| null` | No | Opt in to [application-status webhooks](#application-status-webhooks). Same rules and messages as [IB Term — Webhook Registration](#webhook-registration-optional) |
|
|
2946
|
+
|
|
2947
|
+
|
|
2948
|
+
***
|
|
2949
|
+
|
|
2950
|
+
### Response
|
|
2951
|
+
|
|
2952
|
+
| Field | Type | Description |
|
|
2953
|
+
|---|---|---|
|
|
2954
|
+
| `opportunityId` | `string` | GUID of the created application. Same value as the webhook `opportunityUid` — persist it |
|
|
2955
|
+
| `agentLink` | `string \| null` | Agent Conversational UI |
|
|
2956
|
+
| `applicantLink` | `string \| null` | Applicant Conversational UI |
|
|
2957
|
+
| `eAppAgentLink` | `string \| null` | Agent E-App |
|
|
2958
|
+
| `isDeclined` | `boolean` | Normally `false` on this route's success path |
|
|
2959
|
+
| `isQuoteChanged` | `boolean` | Normally `false` on this route's success path |
|
|
2960
|
+
|
|
2961
|
+
> Consumer-facing platforms should always use `applicantLink`. `agentLink` and `eAppAgentLink` are for agent-facing interfaces only.
|
|
2962
|
+
|
|
2963
|
+
|
|
2964
|
+
***
|
|
2965
|
+
|
|
2966
|
+
### Error Codes
|
|
2967
|
+
|
|
2968
|
+
| Code | When |
|
|
2969
|
+
|---|---|
|
|
2970
|
+
| `InvalidRequestFormat` | Any validation failure, including invalid `webhookRegistrationDetails` — inspect `value.fields` |
|
|
2971
|
+
|
|
2972
|
+
> This route does not return `ApplicationLimitReached`. An invalid or expired token surfaces as `AuthenticationError`.
|
|
2973
|
+
|
|
2974
|
+
|
|
2975
|
+
***
|
|
2976
|
+
|
|
2977
|
+
### Example
|
|
2978
|
+
|
|
2979
|
+
```typescript
|
|
2980
|
+
const appResp = await client.startApplication({
|
|
2981
|
+
quoteResponseId,
|
|
2982
|
+
firstName: 'Jane',
|
|
2983
|
+
lastName: 'Doe',
|
|
2984
|
+
email: 'jane.doe@example.com',
|
|
2985
|
+
phoneNumber: '5551234567',
|
|
2986
|
+
// Optional — receive application-status webhooks for this opportunity
|
|
2987
|
+
webhookRegistrationDetails: {
|
|
2988
|
+
callbackUrl: 'https://partner.example.com/webhooks/instabrain',
|
|
2989
|
+
secretKey: process.env.INSTABRAIN_WEBHOOK_SECRET!
|
|
2990
|
+
}
|
|
2991
|
+
});
|
|
2992
|
+
|
|
2993
|
+
// Persist opportunityId — webhook deliveries carry it as opportunityUid.
|
|
2994
|
+
console.log(appResp.opportunityId, appResp.applicantLink);
|
|
2995
|
+
```
|
|
2996
|
+
|
|
2997
|
+
---
|
|
2998
|
+
|
|
2999
|
+
## Application-status Webhooks
|
|
3000
|
+
|
|
3001
|
+
InstaBrain can POST application-status events — payment, documents signed, policy issued, declined, pivoted — to an HTTPS endpoint you run. This is not a method you call: you opt in on start-application, and InstaBrain calls you.
|
|
3002
|
+
|
|
3003
|
+
```
|
|
3004
|
+
1. start…Application({ …, webhookRegistrationDetails }) → persist opportunityId
|
|
3005
|
+
2. InstaBrain POSTs each event to your callbackUrl
|
|
3006
|
+
3. verifyWebhookSignature(rawBody, timestamp, signature, secretKey)
|
|
3007
|
+
├── false → respond 401
|
|
3008
|
+
└── true → parse JSON, store eventId (dedupe), respond 2xx fast, process asynchronously
|
|
3009
|
+
```
|
|
3010
|
+
|
|
3011
|
+
Delivery is **best-effort** — see [Delivery is best-effort](#delivery-is-best-effort).
|
|
3012
|
+
|
|
3013
|
+
|
|
3014
|
+
***
|
|
3015
|
+
|
|
3016
|
+
### Registering for Webhooks
|
|
3017
|
+
|
|
3018
|
+
Send `webhookRegistrationDetails` on start-application. Only three methods accept it:
|
|
3019
|
+
|
|
3020
|
+
| Method | Registers webhooks |
|
|
3021
|
+
|---|---|
|
|
3022
|
+
| [`startIBTermApplication()`](#ib-term--start-application) | Yes |
|
|
3023
|
+
| [`startPureTermApplication()`](#pure-term--start-application) | Yes |
|
|
3024
|
+
| [`startApplication()`](#generic-start-application) (generic) | Yes |
|
|
3025
|
+
| `startAdbApplication()`, `startGigdbApplication()`, `startFinalExpenseApplication()` | **No** — the field is silently ignored: no error, and no callbacks |
|
|
3026
|
+
|
|
3027
|
+
```typescript
|
|
3028
|
+
webhookRegistrationDetails: {
|
|
3029
|
+
callbackUrl: 'https://partner.example.com/webhooks/instabrain', // absolute HTTPS, max 2048
|
|
3030
|
+
secretKey: process.env.INSTABRAIN_WEBHOOK_SECRET! // 16–256 characters
|
|
3031
|
+
}
|
|
3032
|
+
```
|
|
3033
|
+
|
|
3034
|
+
- Omit the field or pass `null` for no callbacks — both are treated the same. An empty object `{}` fails validation.
|
|
3035
|
+
- `callbackUrl` must be an absolute **HTTPS** URL in **both sandbox and production** — `http://` is rejected. For local testing, use a public HTTPS tunnel.
|
|
3036
|
+
- Invalid details fail the whole request with `InvalidRequestFormat` (messages under `value.fields['WebhookRegistrationDetails.CallbackUrl']` / `['WebhookRegistrationDetails.SecretKey']`), and **no application is created**. The limits are also exported, for reference, as `WEBHOOK_REGISTRATION_LIMITS`.
|
|
3037
|
+
- A knockout decline (empty or all-zero `opportunityId`) registers nothing.
|
|
3038
|
+
- One callback per opportunity. There is no API to change the URL or secret after start-application, so keep a copy of the secret.
|
|
3039
|
+
- If registration itself fails after the application was created, start-application still succeeds. If you opted in and receive no events, contact InstaBrain.
|
|
3040
|
+
|
|
3041
|
+
|
|
3042
|
+
***
|
|
3043
|
+
|
|
3044
|
+
### Your Endpoint
|
|
3045
|
+
|
|
3046
|
+
InstaBrain sends `POST {callbackUrl}` with `Content-Type: application/json` and waits up to **30 seconds** for a response. Store the `eventId`, return **2xx** straight away, and do the real work asynchronously.
|
|
3047
|
+
|
|
3048
|
+
| Your response | What InstaBrain does |
|
|
3049
|
+
|---|---|
|
|
3050
|
+
| `2xx` | Delivered. No retry |
|
|
3051
|
+
| `429` or `5xx` | Retried |
|
|
3052
|
+
| No HTTP response — connection or other transport failure | Retried |
|
|
3053
|
+
| Any other `4xx` | **Not retried** — the event is dropped |
|
|
3054
|
+
|
|
3055
|
+
- Retries: up to **5** after the first attempt, waiting **1, 2, 4, 8, and 16 minutes**.
|
|
3056
|
+
- **Every attempt is signed afresh**: a retry carries a new `X-InstaBrain-Timestamp` and `X-InstaBrain-Signature`. The body and `eventId` stay the same.
|
|
3057
|
+
- Return a 4xx only for a request you want dropped — such as a failed signature check. A bug in your handler should surface as a 5xx, so the event is retried.
|
|
3058
|
+
|
|
3059
|
+
**Where deliveries come from**
|
|
3060
|
+
|
|
3061
|
+
- Deliveries are sent server-to-server from InstaBrain's backend. They don't come from a browser, or from any API you call.
|
|
3062
|
+
- If your endpoint restricts inbound traffic by IP, contact [helpdesk@instabrain.io](mailto:helpdesk@instabrain.io) for InstaBrain's outbound IP addresses (sandbox and production), and allowlist them **before** you register a `callbackUrl`. A blocked delivery counts as a transport failure: it is retried 5 times over about 31 minutes and then dropped, and you never receive an error.
|
|
3063
|
+
- An IP allowlist is extra protection only. Always verify every delivery with `verifyWebhookSignature()`.
|
|
3064
|
+
|
|
3065
|
+
| Header | `WEBHOOK_HEADERS` key | Value |
|
|
3066
|
+
|---|---|---|
|
|
3067
|
+
| `X-InstaBrain-Timestamp` | `TIMESTAMP` | Unix time in seconds (UTC), plain digits — e.g. `1757588400` |
|
|
3068
|
+
| `X-InstaBrain-Signature` | `SIGNATURE` | Lowercase hex HMAC-SHA256 of `{timestamp}.{rawBody}` |
|
|
3069
|
+
| `X-InstaBrain-Event-Id` | `EVENT_ID` | Same value as the body `eventId`. **Not covered by the signature** |
|
|
3070
|
+
| `Content-Type` | — | Always `application/json` |
|
|
3071
|
+
|
|
3072
|
+
`WEBHOOK_HEADERS` holds the lowercase names Node.js uses for `req.headers`.
|
|
3073
|
+
|
|
3074
|
+
|
|
3075
|
+
***
|
|
3076
|
+
|
|
3077
|
+
### Verifying Signatures
|
|
3078
|
+
|
|
3079
|
+
Verify **every** delivery before trusting it, with `verifyWebhookSignature()`. It computes HMAC-SHA256 of `{timestamp}.{rawBody}` with your `secretKey`, compares it to `X-InstaBrain-Signature` in constant time, and checks the timestamp is within 5 minutes of now.
|
|
3080
|
+
|
|
3081
|
+
```typescript
|
|
3082
|
+
import express from 'express';
|
|
3083
|
+
import { verifyWebhookSignature, WEBHOOK_HEADERS } from '@instabrain-sdks/api-client';
|
|
3084
|
+
|
|
3085
|
+
const app = express();
|
|
3086
|
+
|
|
3087
|
+
// express.raw() on this route, ahead of any app-wide express.json(), keeps req.body as the
|
|
3088
|
+
// exact bytes InstaBrain signed.
|
|
3089
|
+
app.post('/webhooks/instabrain', express.raw({ type: 'application/json' }), (req, res) => {
|
|
3090
|
+
const ok = verifyWebhookSignature(
|
|
3091
|
+
req.body, // raw Buffer — never re-stringified JSON
|
|
3092
|
+
req.headers[WEBHOOK_HEADERS.TIMESTAMP],
|
|
3093
|
+
req.headers[WEBHOOK_HEADERS.SIGNATURE],
|
|
3094
|
+
process.env.INSTABRAIN_WEBHOOK_SECRET!
|
|
3095
|
+
);
|
|
3096
|
+
if (!ok) {
|
|
3097
|
+
res.sendStatus(401);
|
|
3098
|
+
return;
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
const event = JSON.parse(req.body.toString('utf8'));
|
|
3102
|
+
// 1. Skip if event.eventId was already stored; otherwise store it.
|
|
3103
|
+
// 2. Respond 2xx now, and handle event.data.event asynchronously.
|
|
3104
|
+
res.sendStatus(200);
|
|
3105
|
+
});
|
|
3106
|
+
```
|
|
3107
|
+
|
|
3108
|
+
**Pass the body exactly as received.** Parsing and re-stringifying it (`JSON.stringify(JSON.parse(body))`) can change spacing or escaping and break the signature — and because compact bodies often survive the round trip, the bug can stay hidden until production. The helper accepts a `string`, `Buffer`, `Uint8Array`, or `ArrayBuffer`. In fetch-style handlers (e.g. Next.js route handlers), pass `await req.text()` as the body and read the headers with `req.headers.get(WEBHOOK_HEADERS.TIMESTAMP)` and `req.headers.get(WEBHOOK_HEADERS.SIGNATURE)` — bracket access on a fetch `Headers` object returns `undefined`, which fails verification.
|
|
3109
|
+
|
|
3110
|
+
| Outcome | When | What to do |
|
|
3111
|
+
|---|---|---|
|
|
3112
|
+
| Returns `true` | Signature matches and the timestamp is within tolerance | Parse the body and handle the event |
|
|
3113
|
+
| Returns `false` | Missing, malformed, stale, or wrong signature or timestamp | Respond `401` |
|
|
3114
|
+
| Throws `TypeError` | Empty `secretKey`, a body that is not a string or bytes (e.g. an already-parsed object), or invalid options | If it happens on every InstaBrain delivery, fix your setup. Your framework answers `500`, so InstaBrain retries — but only 5 times over about 31 minutes; after that the event is lost. A stray request with a non-JSON `Content-Type` or no body can also land here, because body parsers then leave `req.body` as `{}` or `undefined` — one `TypeError` alone is not proof of misconfiguration |
|
|
3115
|
+
|
|
3116
|
+
- The timestamp window is **300 seconds** in either direction. Because every retry is signed afresh, a legitimate delivery never falls outside it. Keep your server clock in sync: a clock more than 5 minutes off rejects every delivery.
|
|
3117
|
+
- Options: `{ toleranceSeconds }` changes the window (`Infinity` disables it); `{ nowSeconds }` overrides the clock, in **seconds**, for tests.
|
|
3118
|
+
- Uppercase hex signatures are accepted.
|
|
3119
|
+
- `TypeError` is a standard JavaScript error, **not** an `InstaBrainError`.
|
|
3120
|
+
- Keep `secretKey` server-side. Never log it, and never build start-application requests in a browser.
|
|
3121
|
+
|
|
3122
|
+
|
|
3123
|
+
***
|
|
3124
|
+
|
|
3125
|
+
### Envelope & Events
|
|
3126
|
+
|
|
3127
|
+
Every delivery is one JSON envelope (camelCase). The SDK deliberately does **not** type the payload — InstaBrain may add events and fields over time. Parse it after verifying, and ignore what you don't recognise.
|
|
3128
|
+
|
|
3129
|
+
| Field | Type | Description |
|
|
3130
|
+
|---|---|---|
|
|
3131
|
+
| `eventId` | `string` (GUID) | Unique per event; retries reuse it. Deduplicate on this |
|
|
3132
|
+
| `webhookType` | `string` | Always `applicationStatus` |
|
|
3133
|
+
| `sequenceNo` | `number` | Order of events **for this `opportunityUid`**, starting at 1 |
|
|
3134
|
+
| `occurredOn` | `string` (ISO-8601, UTC) | When the event happened |
|
|
3135
|
+
| `product` | `string` | Webhook product code — see below |
|
|
3136
|
+
| `opportunityUid` | `string` (GUID) | Same value as the start-application `opportunityId` |
|
|
3137
|
+
| `data` | `object` | Event-specific fields. Always includes `data.event` |
|
|
3138
|
+
| `eventHistory` | `array \| null` | `null` on non-final events. On final events, the earlier envelopes for this opportunity (possibly `[]`), excluding the current one |
|
|
3139
|
+
|
|
3140
|
+
**`product` codes:** `InstaTerm` (IB Term), `InstaPureTerm` (Pure Term), `InstaADB` (ADB), `InstaGIGDB` (GIGDB), `InstaFinalExpense` (Final Expense). These are webhook codes. They match the quote-response `productName` for every product except Pure Term, whose quote `productName` is `"InstaBrain Pure Term"` — so don't treat the two strings as interchangeable. Tolerate values not in this list.
|
|
3141
|
+
|
|
3142
|
+
| `data.event` | Final? | When | Other `data` fields |
|
|
3143
|
+
|---|---|---|---|
|
|
3144
|
+
| `Payment` | No | **IB Term / Pure Term:** payment collected. **ADB / GIGDB / Final Expense:** payment details stored | `paymentMethod`: `EFT` or `CreditCard` |
|
|
3145
|
+
| `DocumentsSigned` | No | Applicant PIN verified / documents signed | — |
|
|
3146
|
+
| `PolicyIssued` | Yes | Policy issued, including scheduled issue | `policyNumber`, `faceAmount`, `premiumAmount`, `paymentFrequency` (nullable), `isPolicyScheduled`, `effectiveDate` (nullable) |
|
|
3147
|
+
| `Declined` | Yes | Declined after the application exists | — |
|
|
3148
|
+
| `Pivoted` | Yes | The application moved to an alternative product | `pivotFromUid`, `pivotToUid`, `pivotFromProductCode`, `pivotToProductCode` |
|
|
3149
|
+
|
|
3150
|
+
- **`Declined` is not a hard stop.** When the product allows a pivot, `Pivoted` can follow `Declined` on the same `opportunityUid` — keep accepting events.
|
|
3151
|
+
- **A `Declined` webhook is not the start-application `isDeclined`.** Trust the start-application response for that call; a `Declined` POST is not guaranteed at start-application time.
|
|
3152
|
+
- **On `Pivoted`**, the event is posted for the *source* `opportunityUid`, and the same `callbackUrl` and `secretKey` are copied to the new application. Later events arrive with `opportunityUid = pivotToUid`, and its `sequenceNo` starts again at 1. If you look up the secret per opportunity, map `pivotToUid` to the same secret.
|
|
3153
|
+
|
|
3154
|
+
Example — a `Payment` delivery:
|
|
3155
|
+
|
|
3156
|
+
```json
|
|
3157
|
+
{
|
|
3158
|
+
"eventId": "9c2e1f4a-1111-2222-3333-444455556666",
|
|
3159
|
+
"webhookType": "applicationStatus",
|
|
3160
|
+
"sequenceNo": 1,
|
|
3161
|
+
"occurredOn": "2026-09-11T06:00:00Z",
|
|
3162
|
+
"product": "InstaTerm",
|
|
3163
|
+
"opportunityUid": "7a1b2c3d-4e5f-6a7b-8c9d-0e1f2a3b4c5d",
|
|
3164
|
+
"data": { "event": "Payment", "paymentMethod": "EFT" },
|
|
3165
|
+
"eventHistory": null
|
|
3166
|
+
}
|
|
3167
|
+
```
|
|
3168
|
+
|
|
3169
|
+
|
|
3170
|
+
***
|
|
3171
|
+
|
|
3172
|
+
### Idempotency & Ordering
|
|
3173
|
+
|
|
3174
|
+
- The same event can arrive more than once — after a retry, for example. **Deduplicate on the `eventId` inside the verified body**, and store it before you return 2xx.
|
|
3175
|
+
- Don't rely on the `X-InstaBrain-Event-Id` header alone: it carries the same value, but the signature does not cover it.
|
|
3176
|
+
- Use `sequenceNo`, not arrival order, to order events for an opportunity.
|
|
3177
|
+
- Final events carry `eventHistory`, so you can rebuild earlier stages without having stored every POST.
|
|
3178
|
+
|
|
3179
|
+
|
|
3180
|
+
***
|
|
3181
|
+
|
|
3182
|
+
### Delivery is Best-Effort
|
|
3183
|
+
|
|
3184
|
+
A successful start-application does not guarantee delivery. Events can be missed — for example when your endpoint answers with a non-retryable 4xx, when retries run out, or when registration fails after the application was created. Treat webhooks as best-effort notifications rather than a guaranteed feed. If you opted in and see no events for an opportunity, contact InstaBrain.
|
|
3185
|
+
|
|
3186
|
+
---
|
|
3187
|
+
|
|
2872
3188
|
## Shared methods — GIGDB, ADB & Final Expense
|
|
2873
3189
|
|
|
2874
|
-
These methods apply to **GIGDB, ADB, and Final Expense**. IB Term and Pure Term use the frontend links returned by Start Application and do **not** call these.
|
|
3190
|
+
These methods apply to **GIGDB, ADB, and Final Expense**. IB Term and Pure Term use the frontend links returned by Start Application and do **not** call these — with one exception: [`saveEftPayment()`](#save-eft-payment) applies to **every product**, including IB Term and Pure Term. The credit-card iframe, the SecureSign methods, and `finalSubmit()` remain GIGDB / ADB / Final Expense only.
|
|
2875
3191
|
|
|
2876
3192
|
---
|
|
2877
3193
|
|
|
@@ -3023,7 +3339,7 @@ Each maps to a distinct `APIErrorCode` with its own `getUserFriendlyMessage()`.
|
|
|
3023
3339
|
**Method:** `client.saveEftPayment(request)` · **Type:** `ThirdPartyEftPaymentReq`
|
|
3024
3340
|
|
|
3025
3341
|
|
|
3026
|
-
Saves bank account details for premium payment
|
|
3342
|
+
Saves bank account details for premium payment — shared by **every product**. Call after Start Application and, for full-flow products, before Prepare Docs. Once saved, quote updates are blocked. Send `payLaterDate` to schedule the draft for a future date ([Pay Later](#pay-later)).
|
|
3027
3343
|
|
|
3028
3344
|
|
|
3029
3345
|
***
|
|
@@ -3036,8 +3352,26 @@ Saves bank account details for premium payment. Call after Start Application, be
|
|
|
3036
3352
|
| `accountHolderName` | `string` | Yes | `Account holder name is required.` / `Account holder name must be 100 characters or fewer.` / `Account holder name may only contain letters, spaces, hyphens, and apostrophes.` |
|
|
3037
3353
|
| `routingNumber` | `string` | Yes | `Routing number is required.` / `Routing number must be 9 digits.` |
|
|
3038
3354
|
| `accountNumber` | `string` | Yes | `Account number is required.` / `Account number must be 4 to 17 digits.` |
|
|
3355
|
+
| `payLaterDate` | `string` (`yyyy-MM-dd`) | No | `Pay later is not available for this opportunity.` (`PayLaterNotAvailable`) / `PayLaterDate must be after today and within the pay later window for this opportunity.` (`InvalidPaymentScheduledDate`) |
|
|
3356
|
+
|
|
3357
|
+
> `accountHolderName` must be at most 100 characters **and** pass the name format rules — in practice about **35** characters: letters, spaces, hyphens, apostrophes, and `*`; no consecutive special characters; and it must end with a letter. A name that fails these rules, including one longer than about 35 characters, returns `Account holder name may only contain letters, spaces, hyphens, and apostrophes.`
|
|
3358
|
+
|
|
3039
3359
|
|
|
3040
|
-
|
|
3360
|
+
***
|
|
3361
|
+
|
|
3362
|
+
### Pay Later
|
|
3363
|
+
|
|
3364
|
+
Send `payLaterDate` to schedule the bank draft for a future date; omit it to draft immediately. There is no separate flag — sending the date is the opt-in.
|
|
3365
|
+
|
|
3366
|
+
- **Format:** `yyyy-MM-dd`, date only. Don't send a time or a UTC offset: an offset can shift the value to a different day before the date part is taken.
|
|
3367
|
+
- **"Today" is the current UTC date,** not your local date. In the US evening UTC is often already the next day, so a local "tomorrow" can be "today" in UTC — and be rejected. Compute the date in UTC.
|
|
3368
|
+
- **Earliest:** tomorrow (UTC). Today or earlier returns `InvalidPaymentScheduledDate`.
|
|
3369
|
+
- **Latest:** whichever comes first of the platform's pay later window — **30 days** after today (UTC) by default — and the applicant's next birthday. The birthday itself is allowed.
|
|
3370
|
+
- **On the applicant's birthday (UTC date)** no `payLaterDate` is accepted. Omit it to draft immediately, or retry the next day (UTC), when the full window applies again.
|
|
3371
|
+
- **`Time-Zone` header:** the SDK doesn't send one. If you add one through `InstaBrainConfig.headers`, it cannot widen the range — and when its date differs from the UTC date, dates beyond the window (30 days by default) after the header's date are rejected too.
|
|
3372
|
+
- **Availability:** when Pay Later is switched off on the platform, any `payLaterDate` returns `PayLaterNotAvailable`. Retry without it to draft immediately. The switch is environment-wide — despite the message wording ("…for this opportunity"), it is not specific to the opportunity.
|
|
3373
|
+
|
|
3374
|
+
The SDK does not check the window itself: it depends on per-opportunity data and server settings. Handle the two error codes below instead.
|
|
3041
3375
|
|
|
3042
3376
|
|
|
3043
3377
|
***
|
|
@@ -3048,6 +3382,7 @@ Saves bank account details for premium payment. Call after Start Application, be
|
|
|
3048
3382
|
2. **EFT and credit card are mutually exclusive per `opportunityId`.** A successful payment that already exists — a prior EFT save, or a card that has already been charged — returns `PaymentAlreadyMade`. After a successful EFT save, [`getCcPaymentIframeUrl()`](#get-credit-card-iframe-url) returns `EftPaymentAlreadyCompleted`.
|
|
3049
3383
|
3. **No application-readiness gate here.** Unlike `getCcPaymentIframeUrl()`, this endpoint does not require Start Application to be fully complete at request validation — it only checks that the opportunity exists and that payment has not already completed. Still call it after Start Application in the integration flow.
|
|
3050
3384
|
4. A successful save **satisfies the payment prerequisite for [`finalSubmit()`](#final-submit)** — no charge runs again at final submit, and neither `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for payment reasons.
|
|
3385
|
+
5. **Pay Later** is EFT only — see [Pay Later](#pay-later) for the allowed range.
|
|
3051
3386
|
|
|
3052
3387
|
|
|
3053
3388
|
***
|
|
@@ -3056,8 +3391,11 @@ Saves bank account details for premium payment. Call after Start Application, be
|
|
|
3056
3391
|
|
|
3057
3392
|
| Code | When |
|
|
3058
3393
|
|---|---|
|
|
3059
|
-
| `InvalidRequestFormat` |
|
|
3394
|
+
| `InvalidRequestFormat` | A format failure on `opportunityId`, `accountHolderName`, `routingNumber`, or `accountNumber`, or `opportunityId` does not exist — inspect `value.fields`. `payLaterDate` failures use the two codes below |
|
|
3060
3395
|
| `PaymentAlreadyMade` | A successful payment already exists for this opportunity (prior EFT save, or a card already charged) |
|
|
3396
|
+
| `InvalidPaymentScheduledDate` | `payLaterDate` is outside the allowed range — see [Pay Later](#pay-later). Message under `value.fields.PayLaterDate` |
|
|
3397
|
+
| `PayLaterNotAvailable` | `payLaterDate` was sent while Pay Later is switched off on the platform. Retry without it. Message under `value.fields.PayLaterDate` |
|
|
3398
|
+
| `ErrorInSaveEftPaymentDetails` | The EFT details could not be saved |
|
|
3061
3399
|
|
|
3062
3400
|
> A credit card that was only **captured** and not yet charged does not trigger `PaymentAlreadyMade` at request validation. Do not rely on that edge case — treat the two payment methods as mutually exclusive.
|
|
3063
3401
|
|
|
@@ -3066,7 +3404,18 @@ Saves bank account details for premium payment. Call after Start Application, be
|
|
|
3066
3404
|
|
|
3067
3405
|
### Response
|
|
3068
3406
|
|
|
3069
|
-
`flagStatus: true` with `value
|
|
3407
|
+
`flagStatus: true` on success, with `value` holding a confirmation message and per-field validation results:
|
|
3408
|
+
|
|
3409
|
+
```json
|
|
3410
|
+
{
|
|
3411
|
+
"message": "Account Details saved successfully!",
|
|
3412
|
+
"accountNameValidation": { "flagAnswerValidation": true, "answerValidationMessage": null },
|
|
3413
|
+
"accountNumberValidation": { "flagAnswerValidation": true, "answerValidationMessage": null },
|
|
3414
|
+
"routingNumberValidation": { "flagAnswerValidation": true, "answerValidationMessage": null }
|
|
3415
|
+
}
|
|
3416
|
+
```
|
|
3417
|
+
|
|
3418
|
+
> `saveEftPayment()` is typed `Promise<boolean>` for backward compatibility, but at runtime it resolves to this `value` object. Treat any resolved value as success — failures throw.
|
|
3070
3419
|
|
|
3071
3420
|
|
|
3072
3421
|
***
|
|
@@ -3083,6 +3432,33 @@ await client.saveEftPayment({
|
|
|
3083
3432
|
// After this point, quote updates are blocked
|
|
3084
3433
|
```
|
|
3085
3434
|
|
|
3435
|
+
**Pay Later** — draft on a future date, computed in UTC:
|
|
3436
|
+
|
|
3437
|
+
```typescript
|
|
3438
|
+
import { APIErrorCode, APIValidationError } from '@instabrain-sdks/api-client';
|
|
3439
|
+
|
|
3440
|
+
// Earliest allowed date is tomorrow in UTC — 'yyyy-MM-dd'
|
|
3441
|
+
const tomorrowUtc = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString().slice(0, 10);
|
|
3442
|
+
|
|
3443
|
+
try {
|
|
3444
|
+
await client.saveEftPayment({
|
|
3445
|
+
opportunityId,
|
|
3446
|
+
accountHolderName: 'Jane Doe',
|
|
3447
|
+
routingNumber: '021000021',
|
|
3448
|
+
accountNumber: '123456789012',
|
|
3449
|
+
payLaterDate: tomorrowUtc
|
|
3450
|
+
});
|
|
3451
|
+
} catch (err) {
|
|
3452
|
+
if (err instanceof APIValidationError && err.isErrorType(APIErrorCode.PayLaterNotAvailable)) {
|
|
3453
|
+
// Pay Later is switched off — save again without payLaterDate to draft now
|
|
3454
|
+
} else if (err instanceof APIValidationError && err.isErrorType(APIErrorCode.InvalidPaymentScheduledDate)) {
|
|
3455
|
+
console.log(err.response?.value?.fields?.PayLaterDate); // outside the allowed range
|
|
3456
|
+
} else {
|
|
3457
|
+
throw err;
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3460
|
+
```
|
|
3461
|
+
|
|
3086
3462
|
---
|
|
3087
3463
|
|
|
3088
3464
|
## Prepare Docs & Get Delivery Channels
|
|
@@ -3883,7 +4259,10 @@ Some enum members remain in the package for backward compatibility but are **not
|
|
|
3883
4259
|
|
|
3884
4260
|
| Code | String Value | Products | When |
|
|
3885
4261
|
|---|---|---|---|
|
|
3886
|
-
| `PaymentAlreadyMade` | `'PaymentAlreadyMade'` | ADB, GIGDB, Final Expense | `update*Quote()` or `saveEftPayment()` when a **successful** payment already exists — a prior EFT save, or a card already charged. A card that was only captured and not yet charged does not trigger this |
|
|
4262
|
+
| `PaymentAlreadyMade` | `'PaymentAlreadyMade'` | All (`saveEftPayment()`); ADB, GIGDB, Final Expense (`update*Quote()`) | `update*Quote()` or `saveEftPayment()` when a **successful** payment already exists — a prior EFT save, or a card already charged. A card that was only captured and not yet charged does not trigger this |
|
|
4263
|
+
| `InvalidPaymentScheduledDate` | `'InvalidPaymentScheduledDate'` | All | `saveEftPayment()` — `payLaterDate` is outside the allowed range: today (UTC) or earlier, beyond the pay later window (30 days by default), after the applicant's next birthday, or sent on the birthday (UTC). Message under `value.fields.PayLaterDate` — see [Pay Later](#pay-later) |
|
|
4264
|
+
| `PayLaterNotAvailable` | `'PayLaterNotAvailable'` | All | `saveEftPayment()` — `payLaterDate` was sent while Pay Later is switched off on the platform. Retry without it to draft immediately. Message under `value.fields.PayLaterDate` |
|
|
4265
|
+
| `ErrorInSaveEftPaymentDetails` | `'ErrorInSaveEftPaymentDetails'` | All | `saveEftPayment()` — the EFT details could not be saved |
|
|
3887
4266
|
| `EftPaymentAlreadyCompleted` | `'EftPaymentAlreadyCompleted'` | ADB, GIGDB, Final Expense | `getCcPaymentIframeUrl()` after a successful EFT save — the two methods are mutually exclusive per opportunity |
|
|
3888
4267
|
| `ApplicationNotReady` | `'ApplicationNotReady'` | ADB, GIGDB, Final Expense | `getCcPaymentIframeUrl()` or `prepareDocsAndGetDeliveryChannels()` before Start Application has completed successfully. **Retryable** — complete Start Application, then call again |
|
|
3889
4268
|
|
|
@@ -3938,12 +4317,10 @@ Not documented as active responses. Kept on `APIErrorCode` for older integration
|
|
|
3938
4317
|
| `HeightNotValid` | `'HeightNotValid'` |
|
|
3939
4318
|
| `DocumentsNotViewed` | `'DocumentsNotViewed'` |
|
|
3940
4319
|
| `ThirdPartyQuoteError` | `'ThirdPartyQuoteError'` |
|
|
3941
|
-
| `ErrorInSaveEftPaymentDetails` | `'ErrorInSaveEftPaymentDetails'` |
|
|
3942
4320
|
| `InvalidBirthCountry` | `'InvalidBirthCountry'` |
|
|
3943
4321
|
| `InvalidBirthState` | `'InvalidBirthState'` |
|
|
3944
4322
|
| `InvalidResidenceState` | `'InvalidResidenceState'` |
|
|
3945
4323
|
| `OneOfTheExistingCoveragesQuestionsNotFound` | `'OneOfTheExistingCoveragesQuestionsNotFound'` |
|
|
3946
|
-
| `InvalidPaymentScheduledDate` | `'InvalidPaymentScheduledDate'` |
|
|
3947
4324
|
| `InvalidQuoteParameters` | `'InvalidQuoteParameters'` |
|
|
3948
4325
|
| `InvalidStateCode` | `'InvalidStateCode'` |
|
|
3949
4326
|
| `InvalidAdbAgeRange` | `'InvalidAdbAgeRange'` |
|