@instabrain-sdks/api-client 2.5.0 → 2.6.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/LICENSE.md ADDED
@@ -0,0 +1,31 @@
1
+ # InstaBrain SDK - Proprietary Software License
2
+
3
+ Copyright (c) 2026 InstaBrain, Inc. All rights reserved.
4
+ 15169 N Scottsdale Rd, Suite 205, Scottsdale, AZ 85254
5
+
6
+ This software and associated documentation files (the "SDK") are proprietary to InstaBrain, Inc. ("InstaBrain"). The SDK files and documentation that InstaBrain publishes publicly are not confidential merely because they are proprietary, and public availability does not make the SDK open-source software or waive InstaBrain's intellectual-property rights. Use is permitted only under a valid written commercial or partner integration agreement with InstaBrain (the "Agreement") or the evaluation grant below, and only in accordance with this License. If this License and the Agreement conflict, the Agreement controls.
7
+
8
+ 0. Acceptance and Covered Versions. THIS LICENSE IS A LEGAL AGREEMENT. By downloading, installing, copying, accessing, or using the SDK after receiving notice of this License, the person doing so, and any entity on whose behalf that person acts, agrees to this License. That person represents that the person has authority to bind that entity. If these terms are not accepted, the SDK must not be downloaded, installed, copied, accessed, or used. "Licensee" means that person and, where applicable, that entity. "SDK" means only a version of the SDK distributed with this License. This License does not grant rights to any earlier version distributed without this License unless an Agreement expressly provides otherwise.
9
+
10
+ 1. License Grant
11
+ 1.1 Evaluation. Absent an Agreement, InstaBrain grants Licensee a limited, non-exclusive, non-transferable, non-sublicensable license to install and use the SDK in a non-production environment solely to evaluate integration with InstaBrain's authorized APIs during one evaluation period of ninety (90) consecutive days (the "Evaluation Period"). The Evaluation Period begins on the first date Licensee or any person acting on Licensee's behalf downloads, installs, accesses, or uses any version of the SDK distributed with this License. Downloading, installing, accessing, or using another copy or version does not restart or extend the Evaluation Period. InstaBrain may extend the Evaluation Period in writing. Evaluation excludes production, commercial, and end-user-facing use, and all evaluation rights automatically expire at the end of the Evaluation Period.
12
+ 1.2 Production. Subject to compliance with the Agreement and this License, InstaBrain grants a limited, non-exclusive, non-transferable, non-sublicensable license to install and use the SDK to develop and operate Licensee's own applications that integrate with InstaBrain's authorized APIs, for the term of the Agreement. Production/commercial/end-user-facing use requires an executed Agreement.
13
+ 1.3 Permitted users. Licensee's employees, contractors, affiliates, and service providers acting on Licensee's behalf and bound by at-least-as-protective obligations may use the SDK for Licensee's permitted purposes and are not prohibited sublicensees.
14
+
15
+ 2. Restrictions. Except as the Agreement permits, Licensee shall not: (a) redistribute, resell, sublicense, lease, or make the SDK available to a third party as a standalone product (integrating the SDK into Licensee's own delivered application is permitted); (b) reverse engineer non-source components except where law permits or for third-party OSS under Section 3; (c) modify or create derivative works of the SDK except to the limited extent reasonably necessary to integrate the SDK with InstaBrain's authorized APIs, provided that every permitted modification remains subject to this License and does not grant Licensee any rights in the InstaBrain-authored portions beyond those expressly stated here; (d) remove proprietary notices; (e) use Agreement Confidential Information, as defined in Section 5, to develop or improve a product or service that competes with the InstaBrain product or service to which that information relates, except as expressly permitted by the Agreement; or (f) use the SDK unlawfully or contrary to the Agreement.
16
+
17
+ 3. Third-Party Open-Source Components. The SDK may include or depend on third-party open-source components, licensed under their own terms (identified in source/manifest/notices); nothing here limits or supersedes Licensee's rights or obligations under those licenses. This License applies only to the InstaBrain-authored portions.
18
+
19
+ 4. Ownership. The InstaBrain-authored portions are licensed, not sold; InstaBrain retains all right, title, and interest, including IP rights. No rights granted except as stated.
20
+
21
+ 5. Confidentiality. The SDK files and documentation published by InstaBrain through npm or otherwise made publicly available by InstaBrain are not Confidential Information under this License. Non-public materials or information that InstaBrain discloses to Licensee under or in connection with an Agreement, including non-public credentials, technical materials, security information, specifications, and documentation, are "Agreement Confidential Information." Licensee shall use Agreement Confidential Information solely to exercise its rights and perform its obligations under the Agreement, protect it using at least reasonable care, and disclose it only to the persons permitted under Section 1.3 who are bound by confidentiality obligations at least as protective as those applicable to Licensee. Agreement Confidential Information excludes information that Licensee can document: (a) is publicly available through no breach of an obligation; (b) was previously known to Licensee without restriction; (c) was independently developed without use of Agreement Confidential Information; or (d) was rightfully received from a third party without a confidentiality duty. Legally compelled disclosure is permitted if Licensee provides reasonable prior notice to InstaBrain where legally allowed and reasonably cooperates in seeking protective treatment. The Agreement's confidentiality provisions control in the event of any conflict.
22
+
23
+ 6. Term and Termination. The evaluation license under Section 1.1 automatically expires at the end of the Evaluation Period and terminates earlier upon Licensee's material breach of this License. A license under Section 1.2 terminates upon expiration or termination of the Agreement or as otherwise provided in the Agreement. If the Agreement does not address termination for breach, InstaBrain may terminate the license under Section 1.2 by written notice if Licensee fails to cure a material breach within ten (10) days after receiving notice. Upon expiration or termination, Licensee shall cease use of the SDK and, within a reasonable period, delete or destroy its copies, except for archival, backup, or legally required copies retained subject to continuing confidentiality and use restrictions. Deployed applications are handled as provided in the Agreement. Sections 3, 4, 5, 7, 8, and 9 survive expiration or termination.
24
+
25
+ 7. Disclaimer of Warranty. THE SDK IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND (MERCHANTABILITY, FITNESS, TITLE, NON-INFRINGEMENT). Agreement warranty terms, if any, control.
26
+
27
+ 8. Limitation of Liability. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL INSTABRAIN BE LIABLE ARISING OUT OF OR RELATING TO THE SDK OR THIS LICENSE FOR: (A) ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, EXEMPLARY, OR PUNITIVE DAMAGES; (B) ANY LOSS OF PROFITS, REVENUE, DATA, BUSINESS OPPORTUNITY, OR GOODWILL; OR (C) AGGREGATE LIABILITY EXCEEDING THE GREATER OF ONE HUNDRED U.S. DOLLARS (US $100) OR THE AMOUNT LICENSEE PAID INSTABRAIN FOR THE SDK DURING THE TWELVE (12) MONTHS PRECEDING THE EVENT GIVING RISE TO LIABILITY. THESE LIMITATIONS APPLY REGARDLESS OF THE THEORY OF LIABILITY AND EVEN IF INSTABRAIN WAS ADVISED OF THE POSSIBILITY OF THE DAMAGES. If an Agreement applies, its limitation-of-liability terms control in the event of conflict.
28
+
29
+ 9. Governing Law. State of Arizona, USA, without regard to conflict-of-laws. The Agreement controls on conflict.
30
+
31
+ 10. Contact. InstaBrain, Inc. - legal@instabrain.io
package/README.md CHANGED
@@ -59,6 +59,7 @@ Credentials (`userId` and `accessToken`) are provisioned during onboarding.
59
59
  - [Get existing quote](#final-expense--get-existing-quote)
60
60
  - [Update quote](#final-expense--update-quote)
61
61
  - [Underwriting status (async)](#final-expense--underwriting-status-async)
62
+ - [GIGDB pivot after a decline](#gigdb-pivot--after-a-final-expense-decline)
62
63
  9. [Shared methods — GIGDB, ADB & Final Expense](#shared-methods--gigdb-adb--final-expense)
63
64
  - [Payment — EFT or credit card](#payment--eft-or-credit-card)
64
65
  - [Get credit card iframe URL](#get-credit-card-iframe-url)
@@ -100,6 +101,8 @@ Credentials (`userId` and `accessToken`) are provisioned during onboarding.
100
101
 
101
102
  ## Installation
102
103
 
104
+ > **Proprietary License Notice.** This package is proprietary software, not open-source software. Downloading, installing, copying, accessing, or using it is subject to [LICENSE.md](LICENSE.md). Without an executed InstaBrain agreement, use is limited to one ninety-day, non-production evaluation; production, commercial, and end-user-facing use requires an executed agreement.
105
+
103
106
  ```bash
104
107
  npm install @instabrain-sdks/api-client
105
108
  ```
@@ -196,9 +199,9 @@ await client.authenticate(userId, accessToken);
196
199
 
197
200
  | Field | Type | Required | Description | Validation Error |
198
201
  |---|---|---|---|---|
199
- | `faceAmount` | `number` | Yes | Coverage amount in dollars ($5,000–$25,000) | `Coverage amount (FaceAmount) is required.` |
202
+ | `faceAmount` | `number` | Yes | Coverage amount in dollars ($5,000–$25,000, in $1,000 increments; flat across ages 50–85) | `Coverage amount (FaceAmount) is required.` |
200
203
  | `gender` | `Gender` | Yes | `Gender.Male`, `Gender.Female` | `Gender is required.` / `Invalid gender.` |
201
- | `stateCode` | `string` | Yes | 2-letter US state code | `State code is required.` / `State code is not valid.` / `This product is not available for the selected state.` |
204
+ | `stateCode` | `string` | Yes | 2-letter US state code | `State code is required.` / `State code is not valid.` |
202
205
  | `age` | `number` | Yes* | Applicant age — must be 50–85 | `Either age or date of birth must be provided.` / `Age must be between 50 and 85 for GIGDB.` |
203
206
  | `dateOfBirth` | `string` (ISO 8601) | Yes* | Date of birth — derived age must be 50–85 | `Date of birth must be a valid date.` |
204
207
  | `paymentFreq` | `PaymentFrequency` | Yes | `"Monthly"` or `"Annually"` | `Payment frequency is required.` / `Invalid payment frequency.` |
@@ -229,6 +232,8 @@ await client.authenticate(userId, accessToken);
229
232
  | `InvalidRequestFormat` | Any field validation failure — inspect `value.fields` for details |
230
233
  | `StateNotFound` | State code not recognized |
231
234
  | `AgeNotFound` | Neither age nor date of birth supplied, or age could not be derived |
235
+ | `ProductNotAvailableForState` | Request validation — GIGDB has no carrier configuration for that state, or is flagged unavailable there. Message under `value.fields.StateCode` |
236
+ | `AgentNotLicensedForState` | Request validation — the authenticated agent is not licensed in that state. Message under `value.fields.StateCode` |
232
237
  | `NotAvailableForState` | GIGDB not available in the requested state |
233
238
  | `QuoteNotEligibleForGivenConditions` | State / age / smoker combination not eligible |
234
239
  | `CoverageNotAvailable` | Face amount outside allowed range for state / age / smoker |
@@ -783,9 +788,9 @@ No field-validation errors are returned for this method.
783
788
 
784
789
  | Field | Type | Required | Description | Validation Error |
785
790
  |---|---|---|---|---|
786
- | `faceAmount` | `number` | Yes | Coverage amount ($50,000–$300,000) | `Coverage amount (FaceAmount) is required.` |
791
+ | `faceAmount` | `number` | Yes | Coverage amount ($50,000–$300,000, in $1,000 increments; flat across ages 20–59) | `Coverage amount (FaceAmount) is required.` |
787
792
  | `gender` | `Gender` | Yes | `Gender.Male`, `Gender.Female` | `Gender is required.` / `Invalid gender.` |
788
- | `stateCode` | `string` | Yes | 2-letter US state — not MA, NH, AK, CA | `State code is required.` / `State code is not valid.` / `This state is currently not supported.` / `This product is not available for the selected state.` |
793
+ | `stateCode` | `string` | Yes | 2-letter US state — not MA, NH, AK, CA | `State code is required.` / `State code is not valid.` / `This state is currently not supported.` |
789
794
  | `age` | `number` | Yes* | Must be 20–59 | `Either age or date of birth must be provided.` / `Age must be between 20 and 59 for ADB.` |
790
795
  | `dateOfBirth` | `string` (ISO 8601) | Yes* | Derived age must be 20–59 | `Date of birth must be a valid date.` |
791
796
  | `paymentFreq` | `PaymentFrequency` | Yes | `"Monthly"` or `"Annually"` | `Payment frequency is required.` / `Invalid payment frequency.` |
@@ -815,6 +820,8 @@ No field-validation errors are returned for this method.
815
820
  | `InvalidRequestFormat` | Any field validation failure — inspect `value.fields` |
816
821
  | `StateNotFound` | State code not recognized |
817
822
  | `AgeNotFound` | Neither age nor date of birth supplied, or age could not be derived |
823
+ | `ProductNotAvailableForState` | Request validation — ADB has no carrier configuration for that state, or is flagged unavailable there. Message under `value.fields.StateCode` |
824
+ | `AgentNotLicensedForState` | Request validation — the authenticated agent is not licensed in that state. Message under `value.fields.StateCode` |
818
825
  | `NotAvailableForState` | ADB not available in the requested state |
819
826
  | `QuoteNotEligibleForGivenConditions` | State / age combination not eligible |
820
827
  | `CoverageNotAvailable` | Face amount outside allowed range |
@@ -1210,7 +1217,7 @@ Provide exactly one rating group (†) and exactly one age input (‡).
1210
1217
  | `benefitPeriod` | `number` | Yes | Term: 10, 20, or 30 years (state/age/nicotine dependent) | `Benefit period is required.` |
1211
1218
  | `flagTobaccoUse` | `boolean` | No | Defaults to `false` when omitted | — |
1212
1219
  | `gender` | `Gender` | Yes | `Gender.Male`, `Gender.Female` | `Gender is required.` / `Invalid gender.` |
1213
- | `stateCode` | `string` | Yes | 2-letter US state — do **not** send `zipCode` for IB Term | `State code is required.` / `State code is not valid.` / `This product is not available for the selected state.` |
1220
+ | `stateCode` | `string` | Yes | 2-letter US state — do **not** send `zipCode` for IB Term | `State code is required.` / `State code is not valid.` |
1214
1221
  | `rateClass` | `RateClass` | One of † | `"Preferred Plus"`, `"Preferred"`, `"Standard"`, `"Standard Extra"` | `Either RateClass, HealthClass, or Height and WeightInLbs must be provided.` / `Rate class is invalid. Allowed values: Preferred Plus, Preferred, Standard, Standard Extra.` |
1215
1222
  | `healthClass` | `HealthClass` | One of † | `"excellent"`, `"great"`, `"good"`, `"average"` (case-insensitive) | `Health class is invalid. Allowed values: excellent, great, good, average.` |
1216
1223
  | `height` | `ThirdPartyQuoteReqHeight \| null` | One of † | `feet` (1–8), `inches` (0–11) — required with `weightInLbs` | `Height or weight is invalid.` |
@@ -1268,6 +1275,8 @@ Provide exactly one rating group (†) and exactly one age input (‡).
1268
1275
  | `AgeNotFound` | `null` | Neither age nor date of birth supplied, or age could not be derived |
1269
1276
  | `BenefitPeriodNotAvailable` | `fields` object present | `benefitPeriod` not allowed for state/age/nicotine |
1270
1277
  | `CoverageNotAvailable` | `fields` object present | `faceAmount` out of range for state/age/nicotine |
1278
+ | `ProductNotAvailableForState` | Request validation — IB Term has no carrier configuration for that state, or is flagged unavailable there. Message under `value.fields.StateCode` |
1279
+ | `AgentNotLicensedForState` | Request validation — the authenticated agent is not licensed in that state. Message under `value.fields.StateCode` |
1271
1280
  | `NotAvailableForState` | `null` | Product not available in this state |
1272
1281
  | `QuoteNotEligibleForGivenConditions` | `null` | State/age/nicotine combination not eligible |
1273
1282
  | `OutsideBuildChart` | `null` | Height/weight outside carrier build chart |
@@ -1772,7 +1781,7 @@ Provide at least one rating group (†) and one age input (‡).
1772
1781
  | `benefitPeriod` | `number` | Yes | Term: 10, 15, 20, or 30 years (state/age/tobacco dependent) | `Benefit period is required.` |
1773
1782
  | `flagTobaccoUse` | `boolean` | No | Defaults to `false` when omitted | — |
1774
1783
  | `gender` | `Gender` | Yes | `Gender.Male`, `Gender.Female` | `Gender is required.` / `Invalid gender.` |
1775
- | `stateCode` | `string` | Yes | 2-letter US state code. Send `stateCode` only — do **not** send `zipCode` | `State code is required.` / `State code is not valid.` / `This product is not available for the selected state.` |
1784
+ | `stateCode` | `string` | Yes | 2-letter US state code. Send `stateCode` only — do **not** send `zipCode` | `State code is required.` / `State code is not valid.` |
1776
1785
  | `rateClass` | `PureTermRateClass` | One of † | `"Preferred Plus"`, `"Preferred"`, `"Standard"`, `"Standard Extra"`, `"Rated C"`, `"Rated D"` | `Either RateClass, HealthClass, or Height and WeightInLbs must be provided.` / `Rate class is invalid. Allowed values: Preferred Plus, Preferred, Standard, Standard Extra, Rated C, Rated D.` |
1777
1786
  | `healthClass` | `HealthClass` | One of † | `"excellent"`, `"great"`, `"good"`, `"average"` (case-insensitive) | `Health class is invalid.` |
1778
1787
  | `height` | `ThirdPartyQuoteReqHeight \| null` | One of † | `feet` (1–8), `inches` (0–11) — required with `weightInLbs` | `Height or weight is invalid.` |
@@ -1841,6 +1850,8 @@ The server applies these in order. Only rules 9's two outcomes get dedicated top
1841
1850
  | `AgeNotFound` | `null` | Neither age nor date of birth supplied, or age could not be derived |
1842
1851
  | `BenefitPeriodNotAvailable` | `fields` object present | `benefitPeriod` not allowed for state/age/nicotine |
1843
1852
  | `CoverageNotAvailable` | `fields` object present | `faceAmount` out of range for state/age/nicotine |
1853
+ | `ProductNotAvailableForState` | Request validation — Pure Term has no carrier configuration for that state, or is flagged unavailable there. Message under `value.fields.StateCode` |
1854
+ | `AgentNotLicensedForState` | Request validation — the authenticated agent is not licensed in that state. Message under `value.fields.StateCode` |
1844
1855
  | `NotAvailableForState` | `null` | Product not available in this state |
1845
1856
  | `QuoteNotEligibleForGivenConditions` | `null` | State/age/nicotine combination not eligible |
1846
1857
  | `OutsideBuildChart` | `null` | Height/weight outside carrier build chart |
@@ -2118,7 +2129,9 @@ This is a **full-flow product** like GIGDB and ADB: quote → start application
2118
2129
  ```
2119
2130
  1. getFinalExpenseQuote() Get quote → quoteResponseId
2120
2131
  2. startFinalExpenseApplication() Start app → opportunityId
2121
- └── isDeclined = true → STOP (knockout)
2132
+ ├── isDeclined = true + all-zero opportunityId → STOP (no application, no pivot)
2133
+ └── isDeclined = true + real opportunityId → STOP the FE flow, but keep the id:
2134
+ it is the input to the GIGDB pivot (step 7)
2122
2135
  3. saveEftPayment() Save bank details (shared method)
2123
2136
  4. Secure Sign flow prepareDocs → sendPin → verifyPin (shared)
2124
2137
  5. finalSubmit() → applicationStatus: 'InProgress' (async!)
@@ -2128,6 +2141,12 @@ This is a **full-flow product** like GIGDB and ADB: quote → start application
2128
2141
  └── (timeout) → resume manually with pingFinalExpenseUnderwritingStatus()
2129
2142
  ```
2130
2143
 
2144
+ ```
2145
+ 7. getPivotQuotes() Only after a decline with a real opportunityId
2146
+ 8. customizePivotQuote() Optional — re-price coverage / frequency
2147
+ 9. convertPivotToApplication() → NEW opportunityId on the alternative product
2148
+ ```
2149
+
2131
2150
  Optional: `getFinalExpenseExistingQuote(opportunityId)` to re-fetch a quote, and `updateFinalExpenseQuote()` to change `faceAmount` / `paymentFreq` before payment.
2132
2151
 
2133
2152
  ---
@@ -2144,9 +2163,9 @@ The response `selectedQuote.quoteResponseId` is the token for `startFinalExpense
2144
2163
 
2145
2164
  | Field | Type | Required | Description | Validation Error |
2146
2165
  |---|---|---|---|---|
2147
- | `faceAmount` | `number` | Yes | Coverage amount ($5,000–$50,000) | `Coverage amount (FaceAmount) is required.` |
2166
+ | `faceAmount` | `number` | Yes | Coverage amount — $5,000–$50,000 for ages 50–80, $5,000–$40,000 for ages 81–85 | `Coverage amount (FaceAmount) is required.` |
2148
2167
  | `gender` | `Gender` | Yes | `Gender.Male`, `Gender.Female` | `Gender is required.` / `Invalid gender.` |
2149
- | `stateCode` | `string` | Yes | 2-letter US state code; product must be available there | `State code is required.` / `State code is not valid.` / `This product is not available for the selected state.` |
2168
+ | `stateCode` | `string` | Yes | 2-letter US state code; product must be available there | `State code is required.` / `State code is not valid.` |
2150
2169
  | `age` | `number` | Yes‡ | 50–85 | `Either age or date of birth must be provided.` / `Age must be between 50 and 85.` |
2151
2170
  | `dateOfBirth` | `string` (ISO 8601) | Yes‡ | Wins over `age` when both provided; derived age 50–85 | `Date of birth must be a valid date.` |
2152
2171
  | `paymentFreq` | `PaymentFrequency` | Yes | `"Monthly"` or `"Annually"` | `Payment frequency is required.` / `Invalid payment frequency.` |
@@ -2160,6 +2179,27 @@ The response `selectedQuote.quoteResponseId` is the token for `startFinalExpense
2160
2179
 
2161
2180
  > **‡** Provide `age` OR `dateOfBirth`. When both are sent, `dateOfBirth` takes priority.
2162
2181
 
2182
+
2183
+ ***
2184
+
2185
+ ### Error Codes
2186
+
2187
+ | Code | When |
2188
+ |---|---|
2189
+ | `InvalidRequestFormat` | Any field validation failure — inspect `value.fields` |
2190
+ | `StateNotFound` | State code not recognized |
2191
+ | `AgeNotFound` | Neither age nor date of birth supplied, or age could not be derived |
2192
+ | `HeightNotValid` | `height.feet` / `height.inches` out of range |
2193
+ | `ProductNotAvailableForState` | Request validation — Final Expense has no carrier configuration for that state, or is flagged unavailable there. Message under `value.fields.StateCode` |
2194
+ | `AgentNotLicensedForState` | Request validation — the authenticated agent is not licensed in that state. Message under `value.fields.StateCode` |
2195
+ | `NotAvailableForState` | Post-validation eligibility — product not available in the state (`value: null`) |
2196
+ | `QuoteNotEligibleForGivenConditions` | State / age / nicotine combination not eligible |
2197
+ | `CoverageNotAvailable` | Face amount outside the allowed range for the age band |
2198
+ | `BenefitPeriodNotAvailable` | Benefit period not allowed for state / age / nicotine |
2199
+
2200
+ > `stateCode` is validated as a cascade that stops at the first failure: required/recognized → product available → agent licensed. See [Quote Errors](#quote-errors) for the full ordering and the distinction between `ProductNotAvailableForState` and `NotAvailableForState`.
2201
+
2202
+
2163
2203
  ***
2164
2204
 
2165
2205
  ### Response
@@ -2304,12 +2344,20 @@ All six fields are required when `includeSecondaryAddressee = true`. When `inclu
2304
2344
 
2305
2345
  ### Knockout summary — returns `isDeclined: true` (not thrown)
2306
2346
 
2347
+ A decline alone no longer tells you whether an application exists. **Branch on `isDeclined` *and* on whether `opportunityId` is all-zero.**
2348
+
2349
+ **All-zero `opportunityId`** — these hard stops fire before an application is created, so there is nothing to pivot from:
2350
+
2307
2351
  - `isPayerAlsoOwnerAndInsured === false`
2308
2352
  - `isUsCitizen === false` AND `isLegalUsResident === false`
2309
2353
  - `isHoldingValidDriverLicense === false`
2354
+ - Height/weight outside the Final Expense build chart
2355
+
2356
+ **Real (non-zero) `opportunityId`** — the application exists but Final Expense declined it. Stop the Final Expense sale path, but retain the id: it is the input to the [GIGDB pivot](#gigdb-pivot--after-a-final-expense-decline).
2357
+
2310
2358
  - Any of the 13 health-prequalification booleans `=== true`
2311
2359
  - Respiratory decline rules above
2312
- - Height/weight outside the Final Expense build chart (decline occurs after opportunity creation — `opportunityId` is a real GUID)
2360
+ - Later underwriting declines
2313
2361
 
2314
2362
  ***
2315
2363
 
@@ -2336,8 +2384,8 @@ All six fields are required when `includeSecondaryAddressee = true`. When `inclu
2336
2384
 
2337
2385
  | Field | Type | Description |
2338
2386
  |---|---|---|
2339
- | `opportunityId` | `string` | All-zero GUID when declined before opportunity creation; real GUID otherwise |
2340
- | `isDeclined` | `boolean` | `true` = knockout / underwriting decline; stop the flow |
2387
+ | `opportunityId` | `string` | All-zero GUID only for the four pre-creation hard stops above; a **real GUID** for every other decline — and that id is what the [GIGDB pivot](#gigdb-pivot--after-a-final-expense-decline) needs |
2388
+ | `isDeclined` | `boolean` | `true` = knockout / underwriting decline; stop the Final Expense flow. Check `opportunityId` before giving up — non-zero means a pivot is available |
2341
2389
  | `isQuoteChanged` | `boolean` | `true` = tobacco flag or DOB triggered a requote; re-present premium |
2342
2390
 
2343
2391
  ***
@@ -2641,6 +2689,186 @@ if (submit.applicationStatus === 'InProgress') {
2641
2689
 
2642
2690
  ---
2643
2691
 
2692
+ ## GIGDB Pivot — after a Final Expense decline
2693
+
2694
+ When Final Expense declines an application **but still creates one** (`isDeclined: true` with a non-zero `opportunityId`), the applicant can be offered an alternative product instead of being turned away. Today that alternative is GIGDB.
2695
+
2696
+ The pivot is not a product of its own — all three methods key off the **declined Final Expense `opportunityId`**.
2697
+
2698
+ ```
2699
+ 1. getPivotQuotes(opportunityId) Alternative quote options
2700
+ 2. customizePivotQuote(request) Optional — re-price coverage / frequency
2701
+ 3. convertPivotToApplication(request) Creates the application → NEW opportunityId
2702
+ 4. getExistingGigdbQuote(newId) Read the current premium
2703
+ 5. … continue the alternative product's normal lifecycle
2704
+ ```
2705
+
2706
+ **Entry condition — check both fields.** Call these methods only when Final Expense start-application returned `isDeclined: true` **and** a non-zero `opportunityId`. Do not call them for approved applications, for all-zero declines, or for products that do not support pivot (today, Final Expense is the only source product).
2707
+
2708
+ ***
2709
+
2710
+ ### Get Pivot Quotes
2711
+
2712
+ **Method:** `client.getPivotQuotes(opportunityId)` · **Endpoint:** `GET /api/ThirdPartyPivot/get-pivot-quotes`
2713
+
2714
+ Calling this repeatedly for the same opportunity is safe.
2715
+
2716
+ **Response:**
2717
+
2718
+ | Field | Type | Description |
2719
+ |---|---|---|
2720
+ | `pivotReason` | `string` | Why the pivot was offered, e.g. `"ApplicationDeclineOrNotEligible"`. Display / log only — do not branch business logic on it |
2721
+ | `quotes` | `PivotQuote[]` | The available alternative-product quotes |
2722
+
2723
+ **`PivotQuote`:**
2724
+
2725
+ | Field | Type | Description |
2726
+ |---|---|---|
2727
+ | `pivotProductCode` | `string` | **Persist this.** Required by both `customizePivotQuote()` and `convertPivotToApplication()`. Use the value the API returned (e.g. `"InstaGIGDB"`) — never construct one |
2728
+ | `productTitle` | `string` | Display title, e.g. `"InstaBrain Guaranteed Issue"` |
2729
+ | `quoteAmount` | `number` | Total premium at the requested payment frequency |
2730
+ | `coverageAmount` | `number` | Coverage in dollars |
2731
+ | `paymentFrequency` | `PaymentFrequency` | Payment frequency (Monthly or Annually) |
2732
+ | `termLength` | `number \| null` | Term in years, or `null` for whole-life products such as GIGDB |
2733
+ | `riders` | `Array<{ riderValue: string; riderLabel: string \| null }>` | Riders included in the quote; empty array when none apply |
2734
+
2735
+ **Error Codes:**
2736
+
2737
+ | Code | HTTP | When |
2738
+ |---|---|---|
2739
+ | `InvalidRequestFormat` | `400` | Missing / malformed / unknown `opportunityId`, or a source product that does not support pivot — inspect `value.fields` |
2740
+ | `PivotNotAvailable` | `400` | The opportunity cannot be pivoted. Top-level, `value: null` — a business state, not a bad request |
2741
+ | — | `403` | `opportunityId` is not authorized for this token. No body |
2742
+
2743
+ **Example:**
2744
+
2745
+ ```typescript
2746
+ const appResp = await client.startFinalExpenseApplication(request);
2747
+
2748
+ const ALL_ZERO = '00000000-0000-0000-0000-000000000000';
2749
+ if (appResp.isDeclined) {
2750
+ if (appResp.opportunityId === ALL_ZERO) {
2751
+ // No application was created — nothing to pivot from.
2752
+ return;
2753
+ }
2754
+
2755
+ const pivot = await client.getPivotQuotes(appResp.opportunityId);
2756
+ console.log(pivot.pivotReason); // 'ApplicationDeclineOrNotEligible'
2757
+ const offer = pivot.quotes[0];
2758
+ console.log(offer.productTitle, offer.quoteAmount, offer.coverageAmount);
2759
+
2760
+ // Persist BOTH for the next two calls.
2761
+ const { opportunityId } = appResp;
2762
+ const { pivotProductCode } = offer;
2763
+ }
2764
+ ```
2765
+
2766
+ ***
2767
+
2768
+ ### Customize Pivot Quote
2769
+
2770
+ **Method:** `client.customizePivotQuote(request)` · **Endpoint:** `POST /api/ThirdPartyPivot/customize-pivot-quote`
2771
+
2772
+ Optional — only call it when the applicant wants a different coverage amount or billing frequency than the default pivot quote. The response is a single quote item with the same shape as one element of `quotes[]`.
2773
+
2774
+ This does **not** persist the choice: `convertPivotToApplication()` still requires `faceAmount` and `paymentFreq` to be sent explicitly.
2775
+
2776
+ **Request Fields:**
2777
+
2778
+ | Field | Type | Required | Description |
2779
+ |---|---|---|---|
2780
+ | `opportunityId` | `string` | Yes | The declined Final Expense opportunity |
2781
+ | `pivotProductCode` | `string` | Yes | Value from `getPivotQuotes()` |
2782
+ | `faceAmount` | `number` | Yes | Desired coverage in dollars. GIGDB: $5,000–$25,000 in $1,000 increments |
2783
+ | `paymentFreq` | `PaymentFrequency` | Yes | `Monthly` or `Annually` only |
2784
+
2785
+ **Error Codes:**
2786
+
2787
+ | Code | HTTP | When |
2788
+ |---|---|---|
2789
+ | `InvalidRequestFormat` | `400` | Missing / malformed body fields, unknown `opportunityId`, or an invalid `pivotProductCode` |
2790
+ | `CoverageNotAvailable` | `400` | `faceAmount` outside the alternative product's range or off its required increment. Top-level, `value: null` |
2791
+ | `PivotNotAvailable` | `400` | The opportunity cannot be pivoted, or pricing could not produce a quote |
2792
+ | — | `403` | `opportunityId` not authorized for this token |
2793
+
2794
+ **Example:**
2795
+
2796
+ ```typescript
2797
+ const repriced = await client.customizePivotQuote({
2798
+ opportunityId,
2799
+ pivotProductCode,
2800
+ faceAmount: 25000,
2801
+ paymentFreq: PaymentFrequency.Monthly,
2802
+ });
2803
+
2804
+ console.log(repriced.quoteAmount); // 52.25
2805
+ console.log(repriced.coverageAmount); // 25000
2806
+ ```
2807
+
2808
+ ***
2809
+
2810
+ ### Convert Pivot to Application
2811
+
2812
+ **Method:** `client.convertPivotToApplication(request)` · **Endpoint:** `POST /api/ThirdPartyPivot/convert-pivot-to-application`
2813
+
2814
+ Call only once the applicant has confirmed the coverage amount and payment frequency they want.
2815
+
2816
+ **Request Fields:**
2817
+
2818
+ | Field | Type | Required | Description |
2819
+ |---|---|---|---|
2820
+ | `opportunityId` | `string` | Yes | The declined Final Expense opportunity |
2821
+ | `pivotProductCode` | `string` | Yes | Value from `getPivotQuotes()` |
2822
+ | `faceAmount` | `number` | Yes | Confirmed coverage. **Required every call** — not carried over from a prior `customizePivotQuote()` |
2823
+ | `paymentFreq` | `PaymentFrequency` | Yes | Confirmed billing frequency. Required every call |
2824
+
2825
+ **Response:**
2826
+
2827
+ | Field | Type | Description |
2828
+ |---|---|---|
2829
+ | `opportunityId` | `string` | **The NEW opportunity**, on the alternative product. Persist it — it replaces the Final Expense id for every subsequent call |
2830
+ | `productCode` | `string` | Which product the new opportunity belongs to, e.g. `"InstaGIGDB"` |
2831
+
2832
+ **Business Rules:**
2833
+
2834
+ - The response carries **no premium by design**. Call the alternative product's get-existing-quote with the new `opportunityId` to read the current amount.
2835
+ - **Do not retry after a successful conversion** — a second attempt on the same opportunity returns `PivotNotAvailable`.
2836
+ - The Final Expense `opportunityId` is finished at this point. Everything that follows — quote, payment, signing, final submit — uses the new one.
2837
+
2838
+ **Error Codes:**
2839
+
2840
+ | Code | HTTP | When |
2841
+ |---|---|---|
2842
+ | `InvalidRequestFormat` | `400` | Missing / malformed body fields, unknown `opportunityId` (`OpportunityId does not exist.`), unsupported product, or an invalid `pivotProductCode` |
2843
+ | `CoverageNotAvailable` | `400` | `faceAmount` outside range or off-increment |
2844
+ | `PivotNotAvailable` | `400` | No longer fit to pivot — e.g. already converted |
2845
+ | — | `403` | `opportunityId` not authorized for this token |
2846
+
2847
+ > An unknown `opportunityId` is `InvalidRequestFormat`, not a dedicated business code. Handle `CoverageNotAvailable` and `PivotNotAvailable` separately from format failures — they arrive top-level with `value: null`.
2848
+
2849
+ **Example — full pivot flow:**
2850
+
2851
+ ```typescript
2852
+ const converted = await client.convertPivotToApplication({
2853
+ opportunityId, // the DECLINED Final Expense id
2854
+ pivotProductCode,
2855
+ faceAmount: 25000,
2856
+ paymentFreq: PaymentFrequency.Monthly,
2857
+ });
2858
+
2859
+ console.log(converted.productCode); // 'InstaGIGDB'
2860
+ const gigdbOpportunityId = converted.opportunityId; // NEW id — persist it
2861
+
2862
+ // No premium in the convert response — read it from the new product.
2863
+ const quote = await client.getExistingGigdbQuote(gigdbOpportunityId);
2864
+ console.log(quote.selectedQuote.quoteAmount);
2865
+
2866
+ // Continue the GIGDB lifecycle with the new id.
2867
+ await client.saveEftPayment({ opportunityId: gigdbOpportunityId, /* … */ } as any);
2868
+ ```
2869
+
2870
+ ---
2871
+
2644
2872
  ## Shared methods — GIGDB, ADB & Final Expense
2645
2873
 
2646
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.
@@ -3593,7 +3821,9 @@ Some enum members remain in the package for backward compatibility but are **not
3593
3821
  | `InvalidRequestFormat` | `'InvalidRequestFormat'` | Any field validation failure — inspect `value.fields` |
3594
3822
  | `StateNotFound` | `'stateNotFound'` | State code not recognized |
3595
3823
  | `AgeNotFound` | `'AgeNotFound'` | Neither age nor date of birth supplied, or age could not be derived |
3596
- | `NotAvailableForState` | `'NotAvailableForState'` | Product not available in state |
3824
+ | `ProductNotAvailableForState` | `'ProductNotAvailableForState'` | **Request validation** — product has no carrier config for the state, or is flagged unavailable there. `value.fields.StateCode` |
3825
+ | `AgentNotLicensedForState` | `'AgentNotLicensedForState'` | **Request validation** — authenticated agent is not licensed in that state, or the agent could not be resolved. `value.fields.StateCode` |
3826
+ | `NotAvailableForState` | `'NotAvailableForState'` | **Post-validation eligibility** — product not available in state, determined after validation passed. `value: null` |
3597
3827
  | `QuoteNotEligibleForGivenConditions` | `'QuoteNotEligibleForGivenConditions'` | State/age/nicotine combo not eligible |
3598
3828
  | `CoverageNotAvailable` | `'CoverageNotAvailable'` | Face amount out of range |
3599
3829
  | `RiderNotAvailable` | `'RiderNotAvailable'` | Rider unavailable for product/state |
@@ -3602,6 +3832,16 @@ Some enum members remain in the package for backward compatibility but are **not
3602
3832
  | `OutsideBuildChart` | `'outsideBuildChart'` | Height & weight provided and outside carrier build chart |
3603
3833
  | `HeightNotValid` | `'HeightNotValid'` | `height.feet` / `height.inches` out of range (feet 1–8, inches 0–11) |
3604
3834
 
3835
+ > **`stateCode` is checked as a cascade, stopping at the first failure**, on every product's Get Quote:
3836
+ >
3837
+ > 1. required / recognized state → `InvalidRequestFormat`
3838
+ > 2. product available in that state → `ProductNotAvailableForState`
3839
+ > 3. agent licensed in that state → `AgentNotLicensedForState`
3840
+ >
3841
+ > Because it stops at the first failure, an agent-licensing problem is only visible once product availability passes — a state can fail both, and you will only see the first.
3842
+ >
3843
+ > **`ProductNotAvailableForState` and `NotAvailableForState` are different codes at different stages** and must not be collapsed. The first is request validation with the message under `value.fields.StateCode`; the second is post-validation eligibility with `value: null`. The cascade codes apply to **Get Quote only** — not start-application, update quote, or get-existing-quote.
3844
+
3605
3845
  **Which codes each product returns** — the rider codes are the main difference, so branch per product rather than assuming one shared list:
3606
3846
 
3607
3847
  | Product | Business codes returned as top-level `error` |
@@ -3624,6 +3864,7 @@ Some enum members remain in the package for backward compatibility but are **not
3624
3864
  | `AgentNotFound` | `'agentNotFound'` | All | Quote cannot be linked to agent account — verify credentials |
3625
3865
  | `InternalServerError` | `'internalServerError'` | All | Unexpected backend failure — retry; if persistent contact support |
3626
3866
  | `DataNotFound` | `'dataNotFound'` | IB Term, Pure Term | The quote referenced by `quoteResponseId` could not be found — create a new quote |
3867
+ | `PivotNotAvailable` | `'PivotNotAvailable'` | Pivot methods | The opportunity cannot be pivoted — not eligible, pricing produced no quote, or it was already converted once. Top-level with `value: null` — a business state, not a malformed request |
3627
3868
 
3628
3869
  **Three outcome shapes — do not conflate them.** Start Application distinguishes field validation, business failure, and knockout:
3629
3870
 
@@ -8,8 +8,9 @@ import { IBTermService } from '../services/ibterm.service';
8
8
  import { PureTermService } from '../services/pureterm.service';
9
9
  import { FinalExpenseService } from '../services/finalexpense.service';
10
10
  import { PaymentService } from '../services/payment.service';
11
+ import { PivotService } from '../services/pivot.service';
11
12
  import { SecureSignService } from '../services/secure-sign.service';
12
- import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
13
+ import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, PivotQuotesResp, CustomizePivotQuoteReq, CustomizePivotQuoteResp, ConvertPivotToApplicationReq, ConvertPivotToApplicationResp, ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
13
14
  /**
14
15
  * Main InstaBrain SDK client
15
16
  */
@@ -25,6 +26,7 @@ export declare class InstaBrainClient {
25
26
  readonly pureTerm: PureTermService;
26
27
  readonly finalExpense: FinalExpenseService;
27
28
  readonly payment: PaymentService;
29
+ readonly pivot: PivotService;
28
30
  readonly secureSign: SecureSignService;
29
31
  constructor(config?: InstaBrainConfig);
30
32
  /**
@@ -322,6 +324,50 @@ export declare class InstaBrainClient {
322
324
  * @returns Promise with the final ping response (terminal status, or last `'InProgress'` on timeout)
323
325
  */
324
326
  pollFinalExpenseUnderwritingStatus(opportunityId: string, options?: PollUnderwritingStatusOptions): Promise<ThirdPartyFinalExpensePingRes>;
327
+ /**
328
+ * Get alternative-product quotes for a declined application.
329
+ *
330
+ * Only call this when `startFinalExpenseApplication()` returned
331
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
332
+ * no application was created and there is nothing to pivot from.
333
+ *
334
+ * **Persist `quotes[n].pivotProductCode`** — both {@link customizePivotQuote}
335
+ * and {@link convertPivotToApplication} require it. Calling this repeatedly for
336
+ * the same opportunity is safe.
337
+ *
338
+ * @param opportunityId - The non-zero `opportunityId` from the declined application
339
+ * @returns Promise with `pivotReason` and the available `quotes`
340
+ */
341
+ getPivotQuotes(opportunityId: string): Promise<PivotQuotesResp>;
342
+ /**
343
+ * Re-price an alternative-product quote for a different coverage amount or
344
+ * billing frequency.
345
+ *
346
+ * Optional — only needed when the applicant wants something other than the
347
+ * default quote from {@link getPivotQuotes}. This does not persist the choice:
348
+ * `convertPivotToApplication()` still needs `faceAmount` and `paymentFreq`
349
+ * sent explicitly.
350
+ *
351
+ * @param request - Opportunity, product code, and the desired coverage / frequency
352
+ * @returns Promise with the recalculated quote
353
+ */
354
+ customizePivotQuote(request: CustomizePivotQuoteReq): Promise<CustomizePivotQuoteResp>;
355
+ /**
356
+ * Create the alternative-product application.
357
+ *
358
+ * **The returned `opportunityId` is new** and belongs to the alternative
359
+ * product — use it for everything that follows; the Final Expense id is
360
+ * finished at this point. The response carries no premium by design: call the
361
+ * alternative product's get-existing-quote with the new id, then continue that
362
+ * product's normal lifecycle.
363
+ *
364
+ * Do not retry after a successful conversion — a second attempt on the same
365
+ * opportunity returns `PivotNotAvailable`.
366
+ *
367
+ * @param request - Opportunity, product code, and confirmed coverage / frequency
368
+ * @returns Promise with the new `opportunityId` and its `productCode`
369
+ */
370
+ convertPivotToApplication(request: ConvertPivotToApplicationReq): Promise<ConvertPivotToApplicationResp>;
325
371
  /**
326
372
  * Get the TrustCommerce hosted iframe URL for credit card capture.
327
373
  *
@@ -12,6 +12,7 @@ const ibterm_service_1 = require("../services/ibterm.service");
12
12
  const pureterm_service_1 = require("../services/pureterm.service");
13
13
  const finalexpense_service_1 = require("../services/finalexpense.service");
14
14
  const payment_service_1 = require("../services/payment.service");
15
+ const pivot_service_1 = require("../services/pivot.service");
15
16
  const secure_sign_service_1 = require("../services/secure-sign.service");
16
17
  /**
17
18
  * Main InstaBrain SDK client
@@ -29,6 +30,7 @@ class InstaBrainClient {
29
30
  this.pureTerm = new pureterm_service_1.PureTermService(this.httpClient);
30
31
  this.finalExpense = new finalexpense_service_1.FinalExpenseService(this.httpClient);
31
32
  this.payment = new payment_service_1.PaymentService(this.httpClient);
33
+ this.pivot = new pivot_service_1.PivotService(this.httpClient);
32
34
  this.secureSign = new secure_sign_service_1.SecureSignService(this.httpClient);
33
35
  }
34
36
  /**
@@ -397,6 +399,57 @@ class InstaBrainClient {
397
399
  async pollFinalExpenseUnderwritingStatus(opportunityId, options) {
398
400
  return this.finalExpense.pollUnderwritingStatus(opportunityId, options);
399
401
  }
402
+ // ── Pivot Methods (Final Expense decline → GIGDB alternative) ──────────
403
+ /**
404
+ * Get alternative-product quotes for a declined application.
405
+ *
406
+ * Only call this when `startFinalExpenseApplication()` returned
407
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
408
+ * no application was created and there is nothing to pivot from.
409
+ *
410
+ * **Persist `quotes[n].pivotProductCode`** — both {@link customizePivotQuote}
411
+ * and {@link convertPivotToApplication} require it. Calling this repeatedly for
412
+ * the same opportunity is safe.
413
+ *
414
+ * @param opportunityId - The non-zero `opportunityId` from the declined application
415
+ * @returns Promise with `pivotReason` and the available `quotes`
416
+ */
417
+ async getPivotQuotes(opportunityId) {
418
+ return this.pivot.getPivotQuotes(opportunityId);
419
+ }
420
+ /**
421
+ * Re-price an alternative-product quote for a different coverage amount or
422
+ * billing frequency.
423
+ *
424
+ * Optional — only needed when the applicant wants something other than the
425
+ * default quote from {@link getPivotQuotes}. This does not persist the choice:
426
+ * `convertPivotToApplication()` still needs `faceAmount` and `paymentFreq`
427
+ * sent explicitly.
428
+ *
429
+ * @param request - Opportunity, product code, and the desired coverage / frequency
430
+ * @returns Promise with the recalculated quote
431
+ */
432
+ async customizePivotQuote(request) {
433
+ return this.pivot.customizePivotQuote(request);
434
+ }
435
+ /**
436
+ * Create the alternative-product application.
437
+ *
438
+ * **The returned `opportunityId` is new** and belongs to the alternative
439
+ * product — use it for everything that follows; the Final Expense id is
440
+ * finished at this point. The response carries no premium by design: call the
441
+ * alternative product's get-existing-quote with the new id, then continue that
442
+ * product's normal lifecycle.
443
+ *
444
+ * Do not retry after a successful conversion — a second attempt on the same
445
+ * opportunity returns `PivotNotAvailable`.
446
+ *
447
+ * @param request - Opportunity, product code, and confirmed coverage / frequency
448
+ * @returns Promise with the new `opportunityId` and its `productCode`
449
+ */
450
+ async convertPivotToApplication(request) {
451
+ return this.pivot.convertPivotToApplication(request);
452
+ }
400
453
  // ── Credit Card Payment Methods (ADB / GIGDB / Final Expense) ──────────
401
454
  /**
402
455
  * Get the TrustCommerce hosted iframe URL for credit card capture.
@@ -35,11 +35,29 @@ export declare class FinalExpenseService extends BaseService {
35
35
  /**
36
36
  * Start a Final Expense application from a prior Final Expense quote.
37
37
  *
38
- * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller. Note:
39
- * `isDeclined: true` is a valid success response (knockout), not an error —
40
- * any health question set to `true`, or `isPayerAlsoOwnerAndInsured` /
41
- * `isHoldingValidDriverLicense` set to `false`, returns HTTP 200 with
42
- * `isDeclined: true`.
38
+ * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller.
39
+ * `isDeclined: true` is a valid success response (knockout), not an error.
40
+ *
41
+ * **Branch on `isDeclined` AND whether `opportunityId` is all-zero — a
42
+ * decline alone no longer tells you whether an application exists:**
43
+ *
44
+ * | Response | Meaning |
45
+ * |---|---|
46
+ * | `isDeclined: true` + **all-zero** `opportunityId` | No application was created. Stop. No pivot available. |
47
+ * | `isDeclined: true` + **non-zero** `opportunityId` | Application exists but Final Expense declined it. Stop the FE sale path, but **retain the `opportunityId`** — it is the input to the GIGDB pivot flow. |
48
+ * | `isDeclined: false` + non-zero `opportunityId` | Continue the normal Final Expense flow. |
49
+ *
50
+ * Health, questionnaire, and later underwriting declines now return a **real**
51
+ * `opportunityId`. Only these hard stops, which fire before an application is
52
+ * created, still return all-zero:
53
+ * - `isPayerAlsoOwnerAndInsured = false`
54
+ * - `isUsCitizen = false` AND `isLegalUsResident = false`
55
+ * - `isHoldingValidDriverLicense = false`
56
+ * - height/weight outside the Final Expense build chart
57
+ *
58
+ * On any decline, do NOT call Final Expense payment, SecureSign, or
59
+ * `finalSubmit()`. With a non-zero id, call
60
+ * {@link PivotService.getPivotQuotes} instead to offer a GIGDB alternative.
43
61
  *
44
62
  * @param request - The Final Expense start-application request payload.
45
63
  * @returns Promise with `opportunityId`, `isDeclined`, and `isQuoteChanged`.
@@ -53,11 +53,29 @@ class FinalExpenseService extends base_service_1.BaseService {
53
53
  /**
54
54
  * Start a Final Expense application from a prior Final Expense quote.
55
55
  *
56
- * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller. Note:
57
- * `isDeclined: true` is a valid success response (knockout), not an error —
58
- * any health question set to `true`, or `isPayerAlsoOwnerAndInsured` /
59
- * `isHoldingValidDriverLicense` set to `false`, returns HTTP 200 with
60
- * `isDeclined: true`.
56
+ * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller.
57
+ * `isDeclined: true` is a valid success response (knockout), not an error.
58
+ *
59
+ * **Branch on `isDeclined` AND whether `opportunityId` is all-zero — a
60
+ * decline alone no longer tells you whether an application exists:**
61
+ *
62
+ * | Response | Meaning |
63
+ * |---|---|
64
+ * | `isDeclined: true` + **all-zero** `opportunityId` | No application was created. Stop. No pivot available. |
65
+ * | `isDeclined: true` + **non-zero** `opportunityId` | Application exists but Final Expense declined it. Stop the FE sale path, but **retain the `opportunityId`** — it is the input to the GIGDB pivot flow. |
66
+ * | `isDeclined: false` + non-zero `opportunityId` | Continue the normal Final Expense flow. |
67
+ *
68
+ * Health, questionnaire, and later underwriting declines now return a **real**
69
+ * `opportunityId`. Only these hard stops, which fire before an application is
70
+ * created, still return all-zero:
71
+ * - `isPayerAlsoOwnerAndInsured = false`
72
+ * - `isUsCitizen = false` AND `isLegalUsResident = false`
73
+ * - `isHoldingValidDriverLicense = false`
74
+ * - height/weight outside the Final Expense build chart
75
+ *
76
+ * On any decline, do NOT call Final Expense payment, SecureSign, or
77
+ * `finalSubmit()`. With a non-zero id, call
78
+ * {@link PivotService.getPivotQuotes} instead to offer a GIGDB alternative.
61
79
  *
62
80
  * @param request - The Final Expense start-application request payload.
63
81
  * @returns Promise with `opportunityId`, `isDeclined`, and `isQuoteChanged`.
@@ -0,0 +1,104 @@
1
+ import { HttpClient } from '../utils/http-client';
2
+ import { BaseService } from './base.service';
3
+ import { PivotQuotesResp, CustomizePivotQuoteReq, CustomizePivotQuoteResp, ConvertPivotToApplicationReq, ConvertPivotToApplicationResp } from '../types/pivot.types';
4
+ /**
5
+ * Pivot service — offering an alternative product after a decline.
6
+ *
7
+ * Today this covers the Final Expense → GIGDB pivot. It is not a product of its
8
+ * own: every call keys off an `opportunityId` that a Final Expense
9
+ * `startApplication()` returned alongside `isDeclined: true`.
10
+ *
11
+ * Flow:
12
+ * 1. getPivotQuotes(opportunityId) → alternative quote options
13
+ * 2. customizePivotQuote(request) → optional re-price
14
+ * 3. convertPivotToApplication(request) → new opportunityId on the new product
15
+ *
16
+ * **Entry condition:** Final Expense start-application returned
17
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
18
+ * no application was created and there is nothing to pivot from.
19
+ *
20
+ * After a successful conversion, leave this service behind — continue with the
21
+ * alternative product's own lifecycle using the new `opportunityId`.
22
+ */
23
+ export declare class PivotService extends BaseService {
24
+ constructor(httpClient: HttpClient);
25
+ /**
26
+ * Get alternative-product quotes for a declined application.
27
+ *
28
+ * Only call this when Final Expense start-application returned
29
+ * `isDeclined: true` with a **non-zero** `opportunityId`. Do not call it for
30
+ * approved applications, all-zero declines, or products that do not support
31
+ * pivot (today, Final Expense is the only source product).
32
+ *
33
+ * Calling repeatedly for the same opportunity is safe.
34
+ *
35
+ * **Persist `quotes[n].pivotProductCode`** — it is required by both
36
+ * {@link customizePivotQuote} and {@link convertPivotToApplication}.
37
+ *
38
+ * Errors:
39
+ * - `InvalidRequestFormat` — missing/malformed/unknown `opportunityId`, or a
40
+ * source product that does not support pivot. Inspect `value.fields`.
41
+ * - `PivotNotAvailable` — the opportunity cannot be pivoted. Top-level,
42
+ * `value: null`. This is a business state, not a malformed request.
43
+ * - HTTP 403 — the `opportunityId` is not authorized for this token. No body.
44
+ *
45
+ * @param opportunityId - The non-zero `opportunityId` from the declined application.
46
+ * @returns Promise with `pivotReason` and the available `quotes`.
47
+ */
48
+ getPivotQuotes(opportunityId: string): Promise<PivotQuotesResp>;
49
+ /**
50
+ * Re-price an alternative-product quote for a different coverage amount or
51
+ * billing frequency.
52
+ *
53
+ * Optional — only needed when the applicant wants something other than the
54
+ * default quote returned by {@link getPivotQuotes}. The response is a single
55
+ * quote item with the same shape as one element of that list.
56
+ *
57
+ * This does **not** persist the choice. `convertPivotToApplication()` still
58
+ * requires `faceAmount` and `paymentFreq` to be sent explicitly.
59
+ *
60
+ * Errors:
61
+ * - `InvalidRequestFormat` — missing/malformed body fields, unknown
62
+ * `opportunityId`, or an invalid `pivotProductCode`.
63
+ * - `CoverageNotAvailable` — `faceAmount` is outside the alternative
64
+ * product's range or off its required increment (GIGDB: $5,000–$25,000 in
65
+ * $1,000 steps). Top-level, `value: null`.
66
+ * - `PivotNotAvailable` — the opportunity cannot be pivoted, or pricing
67
+ * could not produce a quote. Top-level, `value: null`.
68
+ * - HTTP 403 — `opportunityId` not authorized for this token.
69
+ *
70
+ * @param request - Opportunity, product code, and the desired coverage / frequency.
71
+ * @returns Promise with the recalculated quote.
72
+ */
73
+ customizePivotQuote(request: CustomizePivotQuoteReq): Promise<CustomizePivotQuoteResp>;
74
+ /**
75
+ * Create the alternative-product application.
76
+ *
77
+ * Call only once the applicant has confirmed the coverage amount and payment
78
+ * frequency they want. `faceAmount` and `paymentFreq` are required on every
79
+ * call — they are not inherited from a prior {@link customizePivotQuote}.
80
+ *
81
+ * **The returned `opportunityId` is new** and belongs to the alternative
82
+ * product. Persist it and use it for everything that follows; the Final
83
+ * Expense id is finished at this point.
84
+ *
85
+ * The response carries no premium by design. Call the alternative product's
86
+ * own get-existing-quote with the new id to read the current amount, then
87
+ * continue that product's normal lifecycle.
88
+ *
89
+ * **Do not retry after a successful conversion** — a second attempt on the
90
+ * same opportunity returns `PivotNotAvailable`.
91
+ *
92
+ * Errors:
93
+ * - `InvalidRequestFormat` — missing/malformed body fields, unknown
94
+ * `opportunityId` (`OpportunityId does not exist.`), unsupported product,
95
+ * or an invalid `pivotProductCode`.
96
+ * - `CoverageNotAvailable` — `faceAmount` outside range or off-increment.
97
+ * - `PivotNotAvailable` — no longer fit to pivot, e.g. already converted.
98
+ * - HTTP 403 — `opportunityId` not authorized for this token.
99
+ *
100
+ * @param request - Opportunity, product code, and confirmed coverage / frequency.
101
+ * @returns Promise with the new `opportunityId` and its `productCode`.
102
+ */
103
+ convertPivotToApplication(request: ConvertPivotToApplicationReq): Promise<ConvertPivotToApplicationResp>;
104
+ }
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PivotService = void 0;
4
+ const base_service_1 = require("./base.service");
5
+ /**
6
+ * Pivot service — offering an alternative product after a decline.
7
+ *
8
+ * Today this covers the Final Expense → GIGDB pivot. It is not a product of its
9
+ * own: every call keys off an `opportunityId` that a Final Expense
10
+ * `startApplication()` returned alongside `isDeclined: true`.
11
+ *
12
+ * Flow:
13
+ * 1. getPivotQuotes(opportunityId) → alternative quote options
14
+ * 2. customizePivotQuote(request) → optional re-price
15
+ * 3. convertPivotToApplication(request) → new opportunityId on the new product
16
+ *
17
+ * **Entry condition:** Final Expense start-application returned
18
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
19
+ * no application was created and there is nothing to pivot from.
20
+ *
21
+ * After a successful conversion, leave this service behind — continue with the
22
+ * alternative product's own lifecycle using the new `opportunityId`.
23
+ */
24
+ class PivotService extends base_service_1.BaseService {
25
+ constructor(httpClient) {
26
+ super(httpClient);
27
+ }
28
+ /**
29
+ * Get alternative-product quotes for a declined application.
30
+ *
31
+ * Only call this when Final Expense start-application returned
32
+ * `isDeclined: true` with a **non-zero** `opportunityId`. Do not call it for
33
+ * approved applications, all-zero declines, or products that do not support
34
+ * pivot (today, Final Expense is the only source product).
35
+ *
36
+ * Calling repeatedly for the same opportunity is safe.
37
+ *
38
+ * **Persist `quotes[n].pivotProductCode`** — it is required by both
39
+ * {@link customizePivotQuote} and {@link convertPivotToApplication}.
40
+ *
41
+ * Errors:
42
+ * - `InvalidRequestFormat` — missing/malformed/unknown `opportunityId`, or a
43
+ * source product that does not support pivot. Inspect `value.fields`.
44
+ * - `PivotNotAvailable` — the opportunity cannot be pivoted. Top-level,
45
+ * `value: null`. This is a business state, not a malformed request.
46
+ * - HTTP 403 — the `opportunityId` is not authorized for this token. No body.
47
+ *
48
+ * @param opportunityId - The non-zero `opportunityId` from the declined application.
49
+ * @returns Promise with `pivotReason` and the available `quotes`.
50
+ */
51
+ async getPivotQuotes(opportunityId) {
52
+ return this.get('get pivot quotes', '/api/ThirdPartyPivot/get-pivot-quotes', {
53
+ params: { opportunityId },
54
+ });
55
+ }
56
+ /**
57
+ * Re-price an alternative-product quote for a different coverage amount or
58
+ * billing frequency.
59
+ *
60
+ * Optional — only needed when the applicant wants something other than the
61
+ * default quote returned by {@link getPivotQuotes}. The response is a single
62
+ * quote item with the same shape as one element of that list.
63
+ *
64
+ * This does **not** persist the choice. `convertPivotToApplication()` still
65
+ * requires `faceAmount` and `paymentFreq` to be sent explicitly.
66
+ *
67
+ * Errors:
68
+ * - `InvalidRequestFormat` — missing/malformed body fields, unknown
69
+ * `opportunityId`, or an invalid `pivotProductCode`.
70
+ * - `CoverageNotAvailable` — `faceAmount` is outside the alternative
71
+ * product's range or off its required increment (GIGDB: $5,000–$25,000 in
72
+ * $1,000 steps). Top-level, `value: null`.
73
+ * - `PivotNotAvailable` — the opportunity cannot be pivoted, or pricing
74
+ * could not produce a quote. Top-level, `value: null`.
75
+ * - HTTP 403 — `opportunityId` not authorized for this token.
76
+ *
77
+ * @param request - Opportunity, product code, and the desired coverage / frequency.
78
+ * @returns Promise with the recalculated quote.
79
+ */
80
+ async customizePivotQuote(request) {
81
+ return this.post('customize pivot quote', '/api/ThirdPartyPivot/customize-pivot-quote', request);
82
+ }
83
+ /**
84
+ * Create the alternative-product application.
85
+ *
86
+ * Call only once the applicant has confirmed the coverage amount and payment
87
+ * frequency they want. `faceAmount` and `paymentFreq` are required on every
88
+ * call — they are not inherited from a prior {@link customizePivotQuote}.
89
+ *
90
+ * **The returned `opportunityId` is new** and belongs to the alternative
91
+ * product. Persist it and use it for everything that follows; the Final
92
+ * Expense id is finished at this point.
93
+ *
94
+ * The response carries no premium by design. Call the alternative product's
95
+ * own get-existing-quote with the new id to read the current amount, then
96
+ * continue that product's normal lifecycle.
97
+ *
98
+ * **Do not retry after a successful conversion** — a second attempt on the
99
+ * same opportunity returns `PivotNotAvailable`.
100
+ *
101
+ * Errors:
102
+ * - `InvalidRequestFormat` — missing/malformed body fields, unknown
103
+ * `opportunityId` (`OpportunityId does not exist.`), unsupported product,
104
+ * or an invalid `pivotProductCode`.
105
+ * - `CoverageNotAvailable` — `faceAmount` outside range or off-increment.
106
+ * - `PivotNotAvailable` — no longer fit to pivot, e.g. already converted.
107
+ * - HTTP 403 — `opportunityId` not authorized for this token.
108
+ *
109
+ * @param request - Opportunity, product code, and confirmed coverage / frequency.
110
+ * @returns Promise with the new `opportunityId` and its `productCode`.
111
+ */
112
+ async convertPivotToApplication(request) {
113
+ return this.post('convert pivot to application', '/api/ThirdPartyPivot/convert-pivot-to-application', request);
114
+ }
115
+ }
116
+ exports.PivotService = PivotService;
@@ -454,9 +454,37 @@ export declare enum AdbRiderType {
454
454
  export declare enum APIErrorCode {
455
455
  /** Top-level code for every FluentValidation failure across all products. Inspect `value.fields` for field-level details. */
456
456
  InvalidRequestFormat = "InvalidRequestFormat",
457
+ /**
458
+ * Get Quote — the product has no carrier configuration for the requested
459
+ * state, or its configuration is flagged unavailable there. Field message:
460
+ * "This product is not available for the selected state."
461
+ *
462
+ * Previously surfaced as a plain `InvalidRequestFormat` field message; it is
463
+ * now its own top-level code. Not returned by start-application, update
464
+ * quote, or get-existing-quote.
465
+ */
466
+ ProductNotAvailableForState = "ProductNotAvailableForState",
467
+ /**
468
+ * Get Quote — the authenticated agent is not licensed in the requested
469
+ * state, or the agent could not be resolved from the token. Field message:
470
+ * "Agent is not licensed for the selected state."
471
+ *
472
+ * Distinct from `ProductNotApprovedForHierarchy`, which is a
473
+ * start-application product-hierarchy check, not state licensing. Because
474
+ * the cascade stops at the first failure, this is only reachable once
475
+ * product availability has passed.
476
+ */
477
+ AgentNotLicensedForState = "AgentNotLicensedForState",
457
478
  /** State code missing or not recognized for the product. */
458
479
  StateNotFound = "stateNotFound",
459
- /** Product not offered for the selected state. */
480
+ /**
481
+ * Post-validation eligibility — the product is not offered for the selected
482
+ * state, determined after request validation passed. Carries `value: null`.
483
+ *
484
+ * NOT the same as `ProductNotAvailableForState`, which is a request-validation
485
+ * failure carrying `value.fields.StateCode`. Both can occur for the same
486
+ * state; they are raised at different stages and must stay separate.
487
+ */
460
488
  NotAvailableForState = "NotAvailableForState",
461
489
  /** Quote not eligible for the given combination of state, age, and smoker status. */
462
490
  QuoteNotEligibleForGivenConditions = "QuoteNotEligibleForGivenConditions",
@@ -472,6 +500,15 @@ export declare enum APIErrorCode {
472
500
  BenefitPeriodNotAvailable = "BenefitPeriodNotAvailable",
473
501
  /** IB Term Quote only — height + weight fall outside the carrier's acceptable build chart. */
474
502
  OutsideBuildChart = "outsideBuildChart",
503
+ /**
504
+ * The opportunity cannot be pivoted to an alternative product — not eligible,
505
+ * pricing could not produce a quote, or it has already been converted once.
506
+ * Top-level with `value: null`.
507
+ *
508
+ * A business state, not a malformed request — do not lump it in with
509
+ * `InvalidRequestFormat` handling.
510
+ */
511
+ PivotNotAvailable = "PivotNotAvailable",
475
512
  /** ADB / GIGDB / Final Expense Start Application only — same SSN, email, or phone already has a policy generated within the last 30 days. IB Term does NOT use this code. */
476
513
  ApplicationLimitReached = "ApplicationLimitReached",
477
514
  /** Quote state and `Address.State` on Start Application refer to different US states (case-insensitive compare). Returned only after request validation passes. */
@@ -487,10 +487,47 @@ var APIErrorCode;
487
487
  // ─── Universal validation envelope ───────────────────────────────────────
488
488
  /** Top-level code for every FluentValidation failure across all products. Inspect `value.fields` for field-level details. */
489
489
  APIErrorCode["InvalidRequestFormat"] = "InvalidRequestFormat";
490
+ // ─── Get Quote — request-validation state cascade (all five products) ────
491
+ // Checked in this order against `stateCode`, stopping at the first failure:
492
+ // 1. required / recognized state → InvalidRequestFormat
493
+ // 2. product available there → ProductNotAvailableForState
494
+ // 3. agent licensed there → AgentNotLicensedForState
495
+ // Both carry HTTP 400 with the message under `value.fields.StateCode`.
496
+ // These fire during REQUEST VALIDATION. Do not confuse either with
497
+ // `NotAvailableForState`, which is a post-validation eligibility failure
498
+ // carrying `value: null` — different stage, different code.
499
+ /**
500
+ * Get Quote — the product has no carrier configuration for the requested
501
+ * state, or its configuration is flagged unavailable there. Field message:
502
+ * "This product is not available for the selected state."
503
+ *
504
+ * Previously surfaced as a plain `InvalidRequestFormat` field message; it is
505
+ * now its own top-level code. Not returned by start-application, update
506
+ * quote, or get-existing-quote.
507
+ */
508
+ APIErrorCode["ProductNotAvailableForState"] = "ProductNotAvailableForState";
509
+ /**
510
+ * Get Quote — the authenticated agent is not licensed in the requested
511
+ * state, or the agent could not be resolved from the token. Field message:
512
+ * "Agent is not licensed for the selected state."
513
+ *
514
+ * Distinct from `ProductNotApprovedForHierarchy`, which is a
515
+ * start-application product-hierarchy check, not state licensing. Because
516
+ * the cascade stops at the first failure, this is only reachable once
517
+ * product availability has passed.
518
+ */
519
+ APIErrorCode["AgentNotLicensedForState"] = "AgentNotLicensedForState";
490
520
  // ─── Quote business errors (ADB / GIGDB / IB Term, value: null) ──────────
491
521
  /** State code missing or not recognized for the product. */
492
522
  APIErrorCode["StateNotFound"] = "stateNotFound";
493
- /** Product not offered for the selected state. */
523
+ /**
524
+ * Post-validation eligibility — the product is not offered for the selected
525
+ * state, determined after request validation passed. Carries `value: null`.
526
+ *
527
+ * NOT the same as `ProductNotAvailableForState`, which is a request-validation
528
+ * failure carrying `value.fields.StateCode`. Both can occur for the same
529
+ * state; they are raised at different stages and must stay separate.
530
+ */
494
531
  APIErrorCode["NotAvailableForState"] = "NotAvailableForState";
495
532
  /** Quote not eligible for the given combination of state, age, and smoker status. */
496
533
  APIErrorCode["QuoteNotEligibleForGivenConditions"] = "QuoteNotEligibleForGivenConditions";
@@ -507,6 +544,16 @@ var APIErrorCode;
507
544
  APIErrorCode["BenefitPeriodNotAvailable"] = "BenefitPeriodNotAvailable";
508
545
  /** IB Term Quote only — height + weight fall outside the carrier's acceptable build chart. */
509
546
  APIErrorCode["OutsideBuildChart"] = "outsideBuildChart";
547
+ // ─── Pivot (Final Expense → GIGDB alternative offer) ─────────────────────
548
+ /**
549
+ * The opportunity cannot be pivoted to an alternative product — not eligible,
550
+ * pricing could not produce a quote, or it has already been converted once.
551
+ * Top-level with `value: null`.
552
+ *
553
+ * A business state, not a malformed request — do not lump it in with
554
+ * `InvalidRequestFormat` handling.
555
+ */
556
+ APIErrorCode["PivotNotAvailable"] = "PivotNotAvailable";
510
557
  // ─── Start Application — duplicate-detection limit ───────────────────────
511
558
  /** ADB / GIGDB / Final Expense Start Application only — same SSN, email, or phone already has a policy generated within the last 30 days. IB Term does NOT use this code. */
512
559
  APIErrorCode["ApplicationLimitReached"] = "ApplicationLimitReached";
@@ -54,6 +54,10 @@ class APIValidationError extends InstaBrainError {
54
54
  // Quote business errors (ADB / GIGDB / IB Term)
55
55
  'stateNotFound': 'The state code provided is not recognized by the system.',
56
56
  'NotAvailableForState': 'Product is not available in the specified state.',
57
+ // Get Quote request-validation state cascade — distinct from the
58
+ // post-validation NotAvailableForState above.
59
+ 'ProductNotAvailableForState': 'This product is not available in the selected state. Try a different state, or a product offered there.',
60
+ 'AgentNotLicensedForState': 'The agent is not licensed in the selected state. Quotes can only be run in states the agent is licensed for.',
57
61
  'QuoteNotEligibleForGivenConditions': 'Product is not available for the given combination of state, age, or tobacco usage.',
58
62
  'CoverageNotAvailable': 'The requested coverage amount is not available for the given conditions.',
59
63
  'RiderNotAvailable': 'The requested rider is not available in this state or for this age.',
@@ -68,6 +72,7 @@ class APIValidationError extends InstaBrainError {
68
72
  'agentNotFound': 'The quote cannot be linked to an agent account. Please verify the agent token and try again.',
69
73
  'internalServerError': 'An unexpected error occurred while processing the application. Please retry; if the issue persists, contact InstaBrain support.',
70
74
  'InvalidRequestFormat': 'The request format is invalid. Inspect value.fields for per-field details.',
75
+ 'PivotNotAvailable': 'This application cannot be switched to an alternative product. It may not be eligible, or it may already have been converted.',
71
76
  'QuoteNotFound': 'No previous quote found for this opportunity. Please create a quote first.',
72
77
  'ApplicationLimitReached': 'An application with the same SSN, email, or phone already has a policy generated within the last 30 days.',
73
78
  'SecureSignRelatedError': 'A signing-related error occurred. Please try again.',
@@ -12,6 +12,7 @@ export * from './ibterm.types';
12
12
  export * from './pureterm.types';
13
13
  export * from './finalexpense.types';
14
14
  export * from './payment.types';
15
+ export * from './pivot.types';
15
16
  export * from './secure-sign.types';
16
17
  /**
17
18
  * Base configuration for the InstaBrain SDK
@@ -29,4 +29,5 @@ __exportStar(require("./ibterm.types"), exports);
29
29
  __exportStar(require("./pureterm.types"), exports);
30
30
  __exportStar(require("./finalexpense.types"), exports);
31
31
  __exportStar(require("./payment.types"), exports);
32
+ __exportStar(require("./pivot.types"), exports);
32
33
  __exportStar(require("./secure-sign.types"), exports);
@@ -0,0 +1,122 @@
1
+ import { PaymentFrequency } from './enums';
2
+ /**
3
+ * GIGDB pivot — offering an alternative product after a Final Expense decline.
4
+ *
5
+ * The flow starts from a Final Expense `startApplication()` that returned
6
+ * `isDeclined: true` with a **non-zero** `opportunityId`. That id is the key for
7
+ * every call below.
8
+ *
9
+ * 1. `getPivotQuotes(opportunityId)` → alternative quote options
10
+ * 2. `customizePivotQuote(request)` → optional re-price on a new
11
+ * face amount / payment frequency
12
+ * 3. `convertPivotToApplication(request)` → creates the alternative-product
13
+ * application, returns a NEW id
14
+ *
15
+ * After conversion, continue with the alternative product's own lifecycle using
16
+ * the **new** `opportunityId` — starting with its get-existing-quote, since the
17
+ * convert response deliberately carries no premium.
18
+ */
19
+ /**
20
+ * A single alternative-product quote option.
21
+ *
22
+ * Returned both as an element of {@link PivotQuotesResp.quotes} and as the whole
23
+ * body of {@link CustomizePivotQuoteResp} — the shapes are identical.
24
+ */
25
+ export interface PivotQuote {
26
+ /**
27
+ * Product identifier for the alternative product, e.g. `"InstaGIGDB"`.
28
+ *
29
+ * **Persist this.** It is required on both `customizePivotQuote()` and
30
+ * `convertPivotToApplication()`. Always use the value the API returned — do
31
+ * not construct or assume a code.
32
+ */
33
+ pivotProductCode: string;
34
+ /** Display title, e.g. `"InstaBrain Guaranteed Issue"`. */
35
+ productTitle: string;
36
+ /** Total premium at the requested payment frequency. */
37
+ quoteAmount: number;
38
+ /** Coverage amount in dollars. */
39
+ coverageAmount: number;
40
+ /** Payment frequency (Monthly or Annually). */
41
+ paymentFrequency: PaymentFrequency;
42
+ /** Term length in years, or `null` for whole-life products such as GIGDB. */
43
+ termLength: number | null;
44
+ /** Riders included in the quote. Empty array when none apply. */
45
+ riders: Array<{
46
+ riderValue: string;
47
+ riderLabel: string | null;
48
+ }>;
49
+ }
50
+ /**
51
+ * Response from `GET /api/ThirdPartyPivot/get-pivot-quotes`.
52
+ *
53
+ * Calling this repeatedly for the same opportunity is safe.
54
+ */
55
+ export interface PivotQuotesResp {
56
+ /**
57
+ * Why the pivot was offered, e.g. `"ApplicationDeclineOrNotEligible"`.
58
+ * Display or log only — do not branch business logic on it.
59
+ */
60
+ pivotReason: string;
61
+ /** Available alternative-product quotes. */
62
+ quotes: PivotQuote[];
63
+ }
64
+ /**
65
+ * Request body for `POST /api/ThirdPartyPivot/customize-pivot-quote`.
66
+ *
67
+ * Optional step — only call it when the applicant wants a different coverage
68
+ * amount or billing frequency than the default pivot quote offered.
69
+ */
70
+ export interface CustomizePivotQuoteReq {
71
+ /** The declined Final Expense `opportunityId`. Must be non-zero. */
72
+ opportunityId: string;
73
+ /** **Required.** Use the value returned by `getPivotQuotes()`. */
74
+ pivotProductCode: string;
75
+ /**
76
+ * Desired coverage in dollars. Outside the alternative product's allowed
77
+ * range, or off its required increment, returns `CoverageNotAvailable`.
78
+ * GIGDB is $5,000–$25,000 in $1,000 increments.
79
+ */
80
+ faceAmount: number;
81
+ /** `Monthly` or `Annually` only. */
82
+ paymentFreq: PaymentFrequency;
83
+ }
84
+ /**
85
+ * Response from `POST /api/ThirdPartyPivot/customize-pivot-quote` — the same
86
+ * shape as one {@link PivotQuote} from the pivot-quotes list.
87
+ */
88
+ export type CustomizePivotQuoteResp = PivotQuote;
89
+ /**
90
+ * Request body for `POST /api/ThirdPartyPivot/convert-pivot-to-application`.
91
+ *
92
+ * `faceAmount` and `paymentFreq` are required on **every** call — they are not
93
+ * carried over from a prior `customizePivotQuote()`, so send the values the
94
+ * applicant actually confirmed.
95
+ */
96
+ export interface ConvertPivotToApplicationReq {
97
+ /** The declined Final Expense `opportunityId`. Must be non-zero. */
98
+ opportunityId: string;
99
+ /** **Required.** Use the value returned by `getPivotQuotes()`. */
100
+ pivotProductCode: string;
101
+ /** Confirmed coverage in dollars. Required every call. */
102
+ faceAmount: number;
103
+ /** Confirmed billing frequency. Required every call. */
104
+ paymentFreq: PaymentFrequency;
105
+ }
106
+ /**
107
+ * Response from `POST /api/ThirdPartyPivot/convert-pivot-to-application`.
108
+ *
109
+ * Deliberately carries no premium — fetch it from the alternative product's own
110
+ * get-existing-quote endpoint using the new `opportunityId`.
111
+ */
112
+ export interface ConvertPivotToApplicationResp {
113
+ /**
114
+ * The **new** opportunity for the alternative-product application.
115
+ *
116
+ * This replaces the Final Expense id for all subsequent calls on that
117
+ * product — get-existing-quote, update quote, payment, signing, final submit.
118
+ */
119
+ opportunityId: string;
120
+ /** Which product the new opportunity belongs to, e.g. `"InstaGIGDB"`. */
121
+ productCode: string;
122
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@instabrain-sdks/api-client",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Official Node.js SDK for InstaBrain APIs - Insurance quotes and application processing",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
8
  "dist",
9
9
  "README.md",
10
- "LICENSE"
10
+ "LICENSE.md"
11
11
  ],
12
12
  "scripts": {
13
13
  "build": "tsc",
@@ -30,9 +30,14 @@
30
30
  "typescript"
31
31
  ],
32
32
  "author": "InstaBrain",
33
- "license": "UNLICENSED",
33
+ "license": "LicenseRef-InstaBrain-Proprietary",
34
+ "homepage": "https://www.instabrain.io",
35
+ "bugs": {
36
+ "email": "helpdesk@instabrain.io",
37
+ "url": "https://www.instabrain.io"
38
+ },
34
39
  "publishConfig": {
35
- "access": "restricted"
40
+ "access": "public"
36
41
  },
37
42
  "engines": {
38
43
  "node": ">=14.0.0"