@instabrain-sdks/api-client 2.0.1 → 2.1.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.
Files changed (50) hide show
  1. package/README.md +1228 -346
  2. package/dist/client/instabrain-client.d.ts +34 -2
  3. package/dist/client/instabrain-client.js +42 -1
  4. package/dist/index.d.ts +0 -1
  5. package/dist/index.js +0 -1
  6. package/dist/services/adb.service.d.ts +48 -0
  7. package/dist/services/adb.service.js +64 -0
  8. package/dist/services/application.service.d.ts +2 -3
  9. package/dist/services/application.service.js +5 -52
  10. package/dist/services/auth.service.d.ts +0 -1
  11. package/dist/services/auth.service.js +0 -1
  12. package/dist/services/base.service.d.ts +45 -0
  13. package/dist/services/base.service.js +92 -0
  14. package/dist/services/gigdb.service.d.ts +2 -3
  15. package/dist/services/gigdb.service.js +12 -133
  16. package/dist/services/quote.service.d.ts +2 -3
  17. package/dist/services/quote.service.js +4 -35
  18. package/dist/services/reports.service.d.ts +2 -3
  19. package/dist/services/reports.service.js +6 -86
  20. package/dist/services/secure-sign.service.d.ts +2 -3
  21. package/dist/services/secure-sign.service.js +7 -109
  22. package/dist/types/adb.types.d.ts +119 -0
  23. package/dist/types/adb.types.js +2 -0
  24. package/dist/types/application.types.d.ts +0 -1
  25. package/dist/types/application.types.js +0 -1
  26. package/dist/types/auth.types.d.ts +0 -1
  27. package/dist/types/auth.types.js +0 -1
  28. package/dist/types/beneficiary.types.d.ts +54 -0
  29. package/dist/types/beneficiary.types.js +2 -0
  30. package/dist/types/constants.d.ts +0 -1
  31. package/dist/types/constants.js +0 -1
  32. package/dist/types/enums.d.ts +379 -5
  33. package/dist/types/enums.js +392 -8
  34. package/dist/types/errors.d.ts +0 -1
  35. package/dist/types/errors.js +0 -1
  36. package/dist/types/gigdb.types.d.ts +3 -17
  37. package/dist/types/gigdb.types.js +0 -1
  38. package/dist/types/index.d.ts +2 -1
  39. package/dist/types/index.js +2 -1
  40. package/dist/types/quote.types.d.ts +0 -1
  41. package/dist/types/quote.types.js +0 -1
  42. package/dist/types/reports.types.d.ts +0 -1
  43. package/dist/types/reports.types.js +0 -1
  44. package/dist/types/secure-sign.types.d.ts +0 -1
  45. package/dist/types/secure-sign.types.js +0 -1
  46. package/dist/utils/error-utils.d.ts +0 -1
  47. package/dist/utils/error-utils.js +0 -1
  48. package/dist/utils/http-client.d.ts +0 -1
  49. package/dist/utils/http-client.js +0 -4
  50. package/package.json +2 -3
package/README.md CHANGED
@@ -1,9 +1,40 @@
1
- # InstaBrain Node.js SDK
1
+ # @instabrain-sdks/api-client
2
2
 
3
- [![npm version](https://badge.fury.io/js/instabrain.svg)](https://badge.fury.io/js/instabrain)
4
- [![License: Commercial](https://img.shields.io/badge/License-Commercial-red.svg)]()
3
+ [npm version](https://badge.fury.io/js/%40instabrain-sdks%2Fapi-client)
5
4
 
6
- Official Node.js SDK for the InstaBrain API - Insurance quotes and application processing made simple.
5
+ TypeScript/Node.js SDK for integrating with the InstaBrain insurance platform. Covers three products: **GIGDB** (Guaranteed Issue Graded Death Benefit), **ADB** (Accidental Death Benefit), and IB Term life insurance.
6
+
7
+ **Primary products for third-party integration: GIGDB and ADB.**
8
+
9
+ Credentials (`userId` and `accessToken`) are provisioned during onboarding.
10
+
11
+ ---
12
+
13
+ ## Table of Contents
14
+
15
+ 1. [Installation](#installation)
16
+ 2. [Requirements](#requirements)
17
+ 3. [Authentication](#authentication)
18
+ 4. [Product Comparison](#product-comparison)
19
+ 5. [GIGDB Flow](#gigdb-flow)
20
+ 6. [ADB Flow](#adb-flow)
21
+ 7. [IB Term Flow](#ib-term-flow)
22
+ 8. [Secure Sign Flow](#secure-sign-flow)
23
+ 9. [Final Submit](#final-submit)
24
+ 10. [Reporting API](#reporting-api)
25
+ 11. [Request Type Reference](#request-type-reference)
26
+ 12. [Response Type Reference](#response-type-reference)
27
+ 13. [Enums and Constants](#enums-and-constants)
28
+ 14. [Beneficiary Reference](#beneficiary-reference)
29
+ 15. [Error Handling](#error-handling)
30
+ 16. [APIErrorCode Reference](#apierrorcode-reference)
31
+ 17. [Environment Configuration](#environment-configuration)
32
+ 18. [Token Management](#token-management)
33
+ 19. [Examples Directory](#examples-directory)
34
+ 20. [Changelog](#changelog)
35
+ 21. [Support](#support)
36
+
37
+ ---
7
38
 
8
39
  ## Installation
9
40
 
@@ -11,523 +42,1374 @@ Official Node.js SDK for the InstaBrain API - Insurance quotes and application p
11
42
  npm install @instabrain-sdks/api-client
12
43
  ```
13
44
 
14
- ## Quick Start
45
+ > **Note:** This is a restricted-access package. Access must be granted during the InstaBrain onboarding process.
15
46
 
16
- ```typescript
17
- import { InstaBrainClient,
18
- Gender,
19
- PaymentFrequency,
20
- RateClass,
21
- HealthClass,
22
- ThirdPartyQuoteReq,
23
- ThirdPartyStartApplicationReq,
24
- ThirdPartyGigdbQuoteRequest,
25
- ThirdPartyGigdbUpdateQuoteReq,
26
- ThirdPartyGigdbAppReq,
27
- ThirdPartyEftPaymentReq,
28
- ThirdPartySendPinReq,
29
- ThirdPartyVerifyPinReq,
30
- AgentPortalReq }
31
- from '@instabrain-sdks/api-client';
32
-
33
- // Create a client instance
34
- const client = InstaBrainClient.forEnvironment('production');
47
+ ---
35
48
 
36
- // Authenticate
37
- await client.authenticate(12345, 'your-access-token-uuid');
49
+ ## Requirements
38
50
 
39
- // Get a quote
40
- const quote = await client.getQuote(quoteReq);
51
+ - Node.js >= 14.0.0
52
+ - TypeScript >= 4.0 *(optional - the SDK ships with full type definitions)*
41
53
 
42
- // Start an application
43
- const application = await client.startApplication(startApplicationReq);
54
+ ---
44
55
 
45
- // Get reporting data
46
- const reportingReq : AgentPortalReq = {
47
- "startDate": null,
48
- "endDate": null,
49
- "dayCount": 10,
50
- "pageSize": 10,
51
- "pageIndex": 1
52
- };
53
- const prospects = await client.getProspects(reportingReq);
54
- const sales = await client.getSales(reportingReq);
55
- const applications = await client.getApplications(reportingReq);
56
-
57
- console.log(`Dashboard Summary:`);
58
- console.log(`- Prospects: ${prospects.prospectCount}`);
59
- console.log(`- Sales: ${sales.applicationCount} ($${sales.totalPremiumAmount})`);
60
- console.log(`- Applications: ${applications.applicationCount}`);
61
-
62
- // GIGDB Product (Guaranteed Issue — ages 50-85, $5k-$25k)
63
- const gigdbQuote = await client.getGigdbQuote(gigdbQuoteReq);
64
- const gigdbApp = await client.startGigdbApplication(gigdbAppReq);
65
- const eftPayment = await client.saveEftPayment(eftPaymentReq);
66
-
67
- // Update GIGDB quote (change face amount or payment frequency)
68
- const updatedQuote = await client.updateGigdbQuote({
69
- opportunityId: gigdbApp.opportunityId,
70
- faceAmount: 20000,
71
- paymentFreq: PaymentFrequency.Annual
72
- });
56
+ ## Authentication
73
57
 
74
- // Get existing GIGDB quote (when isQuoteChanged=true)
75
- const existingQuote = await client.getExistingGigdbQuote(gigdbApp.opportunityId);
76
-
77
- // Secure Sign flow (shared across all products)
78
- const docs = await client.prepareDocsAndGetDeliveryChannels(gigdbApp.opportunityId);
79
- if (!docs.isSignCompleted) {
80
- const pin = await client.sendPinAndGetDocumentsLink({
81
- opportunityId: gigdbApp.opportunityId,
82
- flagSendSms: docs.isSmsAvailable,
83
- flagSendEmail: docs.isEmailAvailable
84
- });
85
- await client.verifyPin({
86
- opportunityId: gigdbApp.opportunityId,
87
- pin: '123456',
88
- isScriptReadConfirmed: true
89
- });
90
- }
91
- const result = await client.finalSubmit(gigdbApp.opportunityId);
92
- console.log('Policy Number:', result.policyNumber || 'pending');
93
- ```
58
+ Credentials are issued during onboarding:
94
59
 
95
- ## Features
96
60
 
97
- - ✅ **TypeScript Support** - Full type safety with TypeScript definitions
98
- - ✅ **Environment Management** - Easy switching between production and sandbox
99
- - ✅ **Automatic JWT Management** - Handles authentication tokens automatically
100
- - ✅ **Error Handling** - Comprehensive error handling with custom error types
101
- - ✅ **Request Validation** - Built-in validation for API requests
102
- - ✅ **Comprehensive Testing** - Well-tested with Jest
103
- - ✅ **GIGDB Product Support** - Guaranteed Issue quotes, applications, and EFT payments
104
- - ✅ **GIGDB Quote Management** - Update quotes and get existing quotes for GIGDB opportunities
105
- - ✅ **Secure Sign & Final Submit** - Document signing flow and carrier submission (shared across all products)
106
- - ✅ **Modern Promise API** - Uses async/await patterns
61
+ | Credential | Type | Description |
62
+ | ------------- | --------------- | ------------------------ |
63
+ | `userId` | `number` | Your account user ID |
64
+ | `accessToken` | `string` (UUID) | Your secret access token |
107
65
 
108
- ## API Reference
109
66
 
110
- ### Authentication
67
+ ```typescript
68
+ import { InstaBrainClient } from '@instabrain-sdks/api-client';
111
69
 
112
- #### `authenticate(userId: number, accessToken: string): Promise<string>`
70
+ const client = InstaBrainClient.forEnvironment('sandbox');
71
+ const jwt = await client.authenticate(userId, accessToken);
72
+ // JWT is stored internally and automatically attached to all subsequent calls
73
+ // No need to manually set it after authenticate()
74
+ ```
113
75
 
114
- Authenticate with the InstaBrain API and obtain a JWT token.
76
+ > Call `authenticate()` once at startup. The returned JWT is stored internally - every subsequent API call uses it automatically.
115
77
 
116
- ```typescript
117
- const jwtToken = await client.authenticate(12345, 'uuid-access-token');
118
- ```
78
+ ---
119
79
 
120
- ### IB Term Quote Flow
80
+ ## Product Comparison
121
81
 
122
- #### `getQuote(request: ThirdPartyQuoteReq): Promise<ThirdPartyQuoteResp>`
123
82
 
124
- Get an IB Term insurance quote based on the provided parameters.
83
+ | Feature | GIGDB | ADB | IB Term |
84
+ | -------------------- | ------------------------- | ------------------------------- | --------------------------------------------- |
85
+ | Eligible ages | 50–85 | 20–59 | 18–60 |
86
+ | Face amount | $5,000–$25,000 | $50,000-$300,000 | $50,000–$1,000,000 (age-scaled) |
87
+ | Medical exam | No | No | No (build chart used) |
88
+ | Smoker/tobacco field | `isSmoker` (required) | N/A | `flagTobaccoUse` (required) |
89
+ | Birth jurisdiction | Yes (`birthJurisdiction`) | No | No |
90
+ | App response type | `ThirdPartyStartAppResp` | `ThirdPartyAdbStartAppResp` | `ThirdPartyStartAppResp` |
91
+ | `isDeclined` | Yes | Yes | No |
92
+ | `isQuoteChanged` | Yes | No | No |
93
+ | Response links | None | None | `agentLink`, `eAppAgentLink`, `applicantLink` |
94
+ | EFT method | `saveEftPayment()` | `saveAdbEftPayment()` | N/A |
95
+ | Unavailable states | NY, MT | MA, NH, AK *(CA: next release)* | WY, NY |
96
+ | Status | **Primary** | **Primary** | Secondary *(not fully live yet)* |
125
97
 
126
- ```typescript
127
- const quoteReq : ThirdPartyQuoteReq = {
128
- faceAmount: 500000,
129
- benefitPeriod: 20,
130
- flagTobaccoUse: false,
131
- gender: Gender.Female,
132
- stateCode: 'NY',
133
- zipCode: '10001',
134
- rateClass: RateClass.Preferred,
135
- healthClass: HealthClass.Preferred,
136
- height: { feet: 5, inches: 6 },
137
- weightInLbs: 140,
138
- age: 30,
139
- paymentFreq: PaymentFrequency.Annual,
140
- firstName: 'Jane',
141
- lastName: 'Smith',
142
- email: 'jane.smith@example.com',
143
- phoneNum: '555-0123'
144
- };
145
- const quote = await client.getQuote(quoteReq);
146
- ```
147
98
 
148
- #### `startApplication(request: ThirdPartyStartApplicationReq): Promise<ThirdPartyStartAppResp>`
99
+ ---
149
100
 
150
- Start an IB Term insurance application from a quote.
101
+ ## GIGDB Flow
151
102
 
152
- ```typescript
153
- const startApplicationReq : ThirdPartyStartApplicationReq = {
154
- quoteResponseId: quote.selectedQuote.quoteResponseId,
155
- firstName: 'John',
156
- lastName: 'Doe',
157
- email: 'john.doe@example.com',
158
- phoneNumber: '555-1234'
159
- };
160
- const application = await client.startApplication(startApplicationReq);
103
+ > **Not available in:** NY, MT
161
104
 
162
- // Access the generated links
163
- console.log('Agent Link:', application.agentLink);
164
- console.log('Applicant Link:', application.applicantLink);
165
- ```
105
+ GIGDB (Guaranteed Issue Graded Death Benefit) is a simplified-issue whole life product for ages 50–85 with no medical exam.
166
106
 
167
- ### GIGDB (Guaranteed Issue)
107
+ ### Complete flow
168
108
 
169
- #### `getGigdbQuote(request: ThirdPartyGigdbQuoteRequest): Promise<ThirdPartyQuoteResp>`
109
+ ```
110
+ getGigdbQuote()
111
+ ↓
112
+ startGigdbApplication()
113
+ ↓
114
+ [if isDeclined = true] → stop - applicant not eligible
115
+ [if isQuoteChanged = true] → getExistingGigdbQuote() (conditional)
116
+ ↓
117
+ updateGigdbQuote() ← optional; MUST be called before saveEftPayment
118
+ ↓
119
+ saveEftPayment() ← quote cannot be updated after this point
120
+ ↓
121
+ prepareDocsAndGetDeliveryChannels()
122
+ ↓
123
+ sendPinAndGetDocumentsLink() → verifyPin()
124
+ ↓
125
+ finalSubmit()
126
+ ```
170
127
 
171
- Get a Guaranteed Issue quote (ages 50-85, face amount $5k-$25k).
128
+ ### Step 1 - `getGigdbQuote(request: ThirdPartyGigdbQuoteRequest)`
172
129
 
173
130
  ```typescript
174
- const gigdbQuoteReq: ThirdPartyGigdbQuoteRequest = {
131
+ import { InstaBrainClient, Gender, PaymentFrequency } from '@instabrain-sdks/api-client';
132
+
133
+ const quoteResp = await client.getGigdbQuote({
175
134
  faceAmount: 15000,
176
135
  gender: Gender.Female,
177
136
  stateCode: 'TX',
178
137
  age: 65,
179
- dateOfBirth: '1961-01-15',
138
+ dateOfBirth: null,
180
139
  paymentFreq: PaymentFrequency.Monthly,
140
+ isSmoker: false,
181
141
  firstName: 'Jane',
182
- lastName: 'Smith',
183
- email: 'jane.smith@example.com',
184
- phoneNum: '555-0123',
185
- isSmoker: false
186
- };
187
- const quote = await client.getGigdbQuote(gigdbQuoteReq);
188
- ```
142
+ lastName: 'Doe',
143
+ email: 'jane.doe@example.com',
144
+ phoneNum: null
145
+ });
189
146
 
190
- #### `startGigdbApplication(request: ThirdPartyGigdbAppReq): Promise<ThirdPartyStartAppResp>`
147
+ const { quoteResponseId, quoteAmount } = quoteResp.selectedQuote;
148
+ ```
191
149
 
192
- Start a GIGDB application. Note: `isDeclined: true` is a valid response (knockout), not an error.
150
+ ### Step 2 - `startGigdbApplication(request: ThirdPartyGigdbAppReq)`
193
151
 
194
152
  ```typescript
195
- const gigdbAppReq: ThirdPartyGigdbAppReq = {
196
- quoteResponseId: quote.selectedQuote.quoteResponseId,
153
+ import { BeneficiaryType, BeneficiaryRelationship } from '@instabrain-sdks/api-client';
154
+
155
+ const appResp = await client.startGigdbApplication({
156
+ quoteResponseId: quoteResp.selectedQuote.quoteResponseId,
197
157
  firstName: 'Jane',
198
- lastName: 'Smith',
199
- email: 'jane.smith@example.com',
200
- phoneNumber: '555-0123',
158
+ lastName: 'Doe',
159
+ email: 'jane.doe@example.com',
160
+ phoneNumber: '5551234567',
201
161
  isUsCitizen: true,
202
162
  isPayerAlsoOwnerAndInsured: true,
203
- isSmoker: false,
204
- dateOfBirth: '1961-01-15',
205
- socialSecurityNumber: '123456789',
163
+ isLegalUsResident: true,
206
164
  address: {
207
165
  addressLine1: '123 Main St',
208
- city: 'Dallas',
166
+ city: 'Austin',
209
167
  state: 'TX',
210
- zipcode: '75001'
168
+ zipcode: '73301'
211
169
  },
170
+ dateOfBirth: '1958-06-15',
171
+ socialSecurityNumber: '123-45-6789',
212
172
  birthJurisdiction: {
213
- country: 'US',
214
- state: 'TX'
173
+ state: 'TX',
174
+ country: 'US'
215
175
  },
176
+ isSmoker: false,
177
+ nicotineInfo: null,
216
178
  hasExistingCoverage: false,
217
- existingCoverageData: null,
218
179
  willOtherCoverageBeReplacedOrFinanced: null,
180
+ existingCoverageData: null,
219
181
  beneficiaryDetails: {
220
- beneficiaryType: 'Person',
182
+ beneficiaryType: BeneficiaryType.Person,
221
183
  beneficiaryPerson: {
222
184
  firstName: 'John',
223
- lastName: 'Smith',
224
- relationship: 'Spouse'
225
- },
226
- namedEntity: null
185
+ lastName: 'Doe',
186
+ relationship: BeneficiaryRelationship.Spouse
187
+ }
227
188
  }
228
- };
229
- const app = await client.startGigdbApplication(gigdbAppReq);
230
- console.log('Opportunity ID:', app.opportunityId);
231
- console.log('Declined:', app.isDeclined);
189
+ });
190
+
191
+ if (appResp.isDeclined) {
192
+ // Valid knockout - the applicant did not meet eligibility criteria.
193
+ // This is NOT an error - do not throw.
194
+ console.log('Application declined');
195
+ return;
196
+ }
197
+
198
+ const { opportunityId, isQuoteChanged } = appResp;
232
199
  ```
233
200
 
234
- #### `updateGigdbQuote(request: ThirdPartyGigdbUpdateQuoteReq): Promise<ThirdPartyQuoteResp>`
201
+ `**isDeclined: true**` - the applicant did not meet eligibility criteria. This is a valid response, not an error. Stop the flow.
202
+
203
+ `**isQuoteChanged: true**` - the carrier adjusted the premium based on application data. Proceed to Step 3.
235
204
 
236
- Update a GIGDB quote with a different face amount or payment frequency.
205
+ ### Step 3 - Handle quote change (conditional)
237
206
 
238
207
  ```typescript
239
- const updateReq: ThirdPartyGigdbUpdateQuoteReq = {
240
- opportunityId: app.opportunityId,
241
- faceAmount: 20000,
242
- paymentFreq: PaymentFrequency.Annual
243
- };
244
- const updatedQuote = await client.updateGigdbQuote(updateReq);
245
- console.log('Updated face amount:', updatedQuote.selectedQuote.faceAmount);
208
+ let currentQuote = quoteResp.selectedQuote;
209
+
210
+ if (isQuoteChanged) {
211
+ const updatedQuoteResp = await client.getExistingGigdbQuote(opportunityId);
212
+ currentQuote = updatedQuoteResp.selectedQuote;
213
+ // Show the updated premium to the applicant before continuing
214
+ }
246
215
  ```
247
216
 
248
- #### `getExistingGigdbQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>`
217
+ ### Step 4 - `updateGigdbQuote` (optional - must be called BEFORE `saveEftPayment`)
249
218
 
250
- Get the existing quote for a GIGDB opportunity. Use when `isQuoteChanged=true` after `startGigdbApplication`.
219
+ If the applicant wants to change the face amount or payment frequency after the application has started:
251
220
 
252
221
  ```typescript
253
- const existingQuote = await client.getExistingGigdbQuote(app.opportunityId);
254
- console.log('Current quote:', existingQuote.selectedQuote.quoteAmount);
222
+ const updatedQuoteResp = await client.updateGigdbQuote({
223
+ opportunityId,
224
+ faceAmount: 20000,
225
+ paymentFreq: PaymentFrequency.Annually
226
+ });
227
+ // updatedQuoteResp.selectedQuote.quoteAmount reflects the new premium
255
228
  ```
256
229
 
257
- #### `saveEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>`
230
+ > **Important:** The quote cannot be updated after EFT payment details are saved. `updateGigdbQuote()` must be called before `saveEftPayment()`.
258
231
 
259
- Returns `true` when payment details saved successfully.
232
+ ### Step 5 - `saveEftPayment(request: ThirdPartyEftPaymentReq)`
260
233
 
261
234
  ```typescript
262
- const eftReq: ThirdPartyEftPaymentReq = {
263
- opportunityId: app.opportunityId,
264
- accountHolderName: 'Jane Smith',
235
+ await client.saveEftPayment({
236
+ opportunityId,
237
+ accountHolderName: 'Jane Doe',
265
238
  routingNumber: '021000021',
266
239
  accountNumber: '123456789'
267
- };
268
- const success = await client.saveEftPayment(eftReq);
269
- console.log('Payment saved:', success);
240
+ });
241
+ // After this point, the quote can no longer be updated.
270
242
  ```
271
243
 
272
- ### Secure Sign (Document Signing)
244
+ ### Steps 6–7 - Secure Sign → Final Submit
245
+
246
+ See [Secure Sign Flow](#secure-sign-flow) and [Final Submit](#final-submit).
247
+
248
+ ---
273
249
 
274
- The signing flow is shared across all products. Call after EFT payment has been saved.
250
+ ## ADB Flow
275
251
 
276
- #### `prepareDocsAndGetDeliveryChannels(opportunityId: string): Promise<ThirdPartyPrepareDocsResp>`
252
+ > **Not available in:** MA, NH, AK
253
+ >
254
+ > **CA:** Support is planned for the next SDK release. Do not use for California at this time.
277
255
 
278
- Prepare the signing package and check available delivery channels. If `isSignCompleted` is true, skip directly to `finalSubmit()`.
256
+ ADB (Accidental Death Benefit) provides coverage for accidental deaths for ages 20–59.
257
+
258
+ ### Complete flow
259
+
260
+ ```
261
+ getAdbRiderDetails() ← check state availability & collect riderCodes
262
+ ↓
263
+ getAdbQuote()
264
+ ↓
265
+ startAdbApplication()
266
+ ↓
267
+ [if isDeclined = true] → stop - applicant not eligible
268
+ ↓
269
+ updateAdbQuote() ← COMING IN FUTURE RELEASE; MUST be before saveAdbEftPayment
270
+ ↓
271
+ saveAdbEftPayment() ← quote cannot be updated after this point
272
+ ↓
273
+ prepareDocsAndGetDeliveryChannels()
274
+ ↓
275
+ sendPinAndGetDocumentsLink() → verifyPin()
276
+ ↓
277
+ finalSubmit()
278
+ ```
279
+
280
+ ### Step 0 - `getAdbRiderDetails(stateCode: string)` (optional pre-step)
281
+
282
+ Call before `getAdbQuote()` to check whether ADB is available in the applicant's state and to retrieve the `riderCode` values to pass into the quote request. Skip this step only if you already know which riders (if any) are available for the state.
283
+
284
+ > **Note:** California (`CA`) is not supported — the API will return a 400 error for `stateCode = "CA"`.
279
285
 
280
286
  ```typescript
281
- const docs = await client.prepareDocsAndGetDeliveryChannels(app.opportunityId);
282
- console.log('SMS available:', docs.isSmsAvailable);
283
- console.log('Already signed:', docs.isSignCompleted);
287
+ import { InstaBrainClient } from '@instabrain-sdks/api-client';
288
+
289
+ const riderDetails = await client.getAdbRiderDetails('TX');
290
+
291
+ if (riderDetails.flagProductNotAvailableForState) {
292
+ // ADB not available in this state — do not proceed to quote
293
+ return;
294
+ }
295
+
296
+ // Collect riderCodes the user wants to include (may be an empty array)
297
+ const selectedRiderCodes = riderDetails.riders.map(r => r.riderCode);
298
+ // Pass selectedRiderCodes into ThirdPartyAdbQuoteRequest.riders
284
299
  ```
285
300
 
286
- #### `sendPinAndGetDocumentsLink(request: ThirdPartySendPinReq): Promise<ThirdPartySendPinResp>`
301
+ > **Note:** `riders` may be an empty array even when `flagProductNotAvailableForState = false` — this means no optional riders are configured for that state.
287
302
 
288
- Send a verification PIN via SMS and/or Email and receive the documents link.
303
+ ### Step 1 - `getAdbQuote(request: ThirdPartyAdbQuoteRequest)`
289
304
 
290
305
  ```typescript
291
- const pinResp = await client.sendPinAndGetDocumentsLink({
292
- opportunityId: app.opportunityId,
293
- flagSendSms: true,
294
- flagSendEmail: true
306
+ import { InstaBrainClient, Gender, PaymentFrequency, RiderType } from '@instabrain-sdks/api-client';
307
+
308
+ const quoteResp = await client.getAdbQuote({
309
+ faceAmount: 100000,
310
+ gender: Gender.Male,
311
+ stateCode: 'TX',
312
+ age: 35,
313
+ paymentFreq: PaymentFrequency.Monthly,
314
+ riders: [RiderType.ADBRider],
315
+ firstName: 'John',
316
+ lastName: 'Smith',
317
+ email: 'john.smith@example.com'
295
318
  });
296
- console.log('Documents link:', pinResp.link);
297
- console.log('Script to read:', pinResp.script);
319
+
320
+ const { quoteResponseId } = quoteResp.selectedQuote;
298
321
  ```
299
322
 
300
- #### `resendPin(request: ThirdPartyResendPinReq): Promise<ThirdPartyResendPinResp>`
323
+ **Rider notes:**
301
324
 
302
- Resend the verification PIN if the signer did not receive it.
325
+ - `riders` is `string[]` - use `RiderType` enum values: `RiderType.ADBRider` (`'ADB Rider'`), `RiderType.DependentChildRider` (`'Dependent Child Rider'`)
326
+ - Rider availability varies by state - see [ADB Rider Availability](#adb-rider-availability)
327
+
328
+ ### Step 2 - `startAdbApplication(request: ThirdPartyAdbAppReq)`
303
329
 
304
330
  ```typescript
305
- const resendResp = await client.resendPin({
306
- opportunityId: app.opportunityId,
307
- flagSendSms: true,
308
- flagSendEmail: false
331
+ import { BeneficiaryType, BeneficiaryRelationship } from '@instabrain-sdks/api-client';
332
+
333
+ const appResp = await client.startAdbApplication({
334
+ quoteResponseId: quoteResp.selectedQuote.quoteResponseId,
335
+ firstName: 'John',
336
+ lastName: 'Smith',
337
+ email: 'john.smith@example.com',
338
+ phoneNumber: '5559876543',
339
+ isUsCitizen: true,
340
+ isPayerAlsoOwnerAndInsured: true, // must be true - knockout if false
341
+ address: {
342
+ addressLine1: '456 Oak Ave',
343
+ city: 'Dallas',
344
+ state: 'TX',
345
+ zipcode: '75201'
346
+ },
347
+ dateOfBirth: '1988-03-20',
348
+ socialSecurityNumber: '987-65-4321',
349
+ hasExistingCoverage: false,
350
+ beneficiaryDetails: {
351
+ beneficiaryType: BeneficiaryType.Person,
352
+ beneficiaryPerson: {
353
+ firstName: 'Mary',
354
+ lastName: 'Smith',
355
+ relationship: BeneficiaryRelationship.Spouse
356
+ }
357
+ }
309
358
  });
310
- console.log('PIN resent:', resendResp.flagPinSent);
359
+
360
+ if (appResp.isDeclined) {
361
+ // Valid knockout - stop the flow
362
+ return;
363
+ }
364
+
365
+ const { opportunityId } = appResp;
311
366
  ```
312
367
 
313
- #### `verifyPin(request: ThirdPartyVerifyPinReq): Promise<ThirdPartyVerifyPinResp>`
368
+ **Knockout rules - returns `isDeclined: true` (not an error, not thrown):**
369
+
370
+ - `isPayerAlsoOwnerAndInsured === false` → declined
371
+ - `isUsCitizen === false` AND `isLegalUsResident === false` → declined
372
+
373
+ **ADB response differences from GIGDB/IB Term:**
374
+
375
+ - Response type is `ThirdPartyAdbStartAppResp` - contains only `opportunityId` and `isDeclined`
376
+ - No `agentLink`, `eAppAgentLink`, `applicantLink`
377
+ - No `isQuoteChanged`
378
+ - No `birthJurisdiction` field in the application request (unlike GIGDB)
314
379
 
315
- Verify the PIN entered by the signer to complete document signing.
380
+ ### Step 3 - Update quote (optional - must be called BEFORE `saveAdbEftPayment`)
381
+
382
+ > **Note:** `updateAdbQuote()` is planned for a future SDK release. Once available, it must be called before `saveAdbEftPayment()`. The quote cannot be updated after EFT payment details are saved. This section will be updated when the function is released.
383
+
384
+ ### Step 4 - `saveAdbEftPayment(request: ThirdPartyEftPaymentReq)`
316
385
 
317
386
  ```typescript
318
- const verifyResp = await client.verifyPin({
319
- opportunityId: app.opportunityId,
320
- pin: '123456',
321
- isScriptReadConfirmed: true
387
+ await client.saveAdbEftPayment({
388
+ opportunityId,
389
+ accountHolderName: 'John Smith',
390
+ routingNumber: '021000021',
391
+ accountNumber: '987654321'
322
392
  });
323
- console.log('Verified:', verifyResp.isVerified);
393
+ // After this point, the quote can no longer be updated.
324
394
  ```
325
395
 
326
- ### Final Submit
396
+ > **Important:** Use `saveAdbEftPayment()` for ADB - not `saveEftPayment()`. Both accept the same `ThirdPartyEftPaymentReq` type but call different backend endpoints.
397
+
398
+ ### Steps 5–6 - Secure Sign → Final Submit
399
+
400
+ See [Secure Sign Flow](#secure-sign-flow) and [Final Submit](#final-submit).
401
+
402
+ ---
403
+
404
+ ## IB Term Flow
327
405
 
328
- #### `finalSubmit(opportunityId: string): Promise<ThirdPartyFinalSubmitResp>`
406
+ > **Note:** IB Term is not yet fully available in this SDK release. This section is provided for reference only. Primary products for integration are GIGDB and ADB.
407
+ >
408
+ > **Not available in:** WY, NY
329
409
 
330
- Submit the application to the carrier for a final underwriting decision. Call after the signing flow is complete. Note: `policyNumber: null` means the carrier has not yet issued a number (pending decision) — this is not an error.
410
+ ### Complete flow
411
+
412
+ ```
413
+ getQuote()
414
+ ↓
415
+ startApplication()
416
+ ↓
417
+ prepareDocsAndGetDeliveryChannels()
418
+ ↓
419
+ sendPinAndGetDocumentsLink() → verifyPin()
420
+ ↓
421
+ finalSubmit()
422
+ ```
423
+
424
+ ### Step 1 - `getQuote(request: ThirdPartyQuoteReq)`
425
+
426
+ Provide exactly one of three mutually exclusive rating inputs:
427
+
428
+ - `rateClass` - use `RateClass` enum
429
+ - `healthClass` - use `HealthClass` enum *(note: `HealthClass.Preferred` does not exist; valid values: Excellent, Great, Good, Average)*
430
+ - `height` + `weightInLbs` - build chart rating
331
431
 
332
432
  ```typescript
333
- const result = await client.finalSubmit(app.opportunityId);
334
- console.log('Policy Number:', result.policyNumber || 'pending carrier decision');
433
+ import { Gender, PaymentFrequency, HealthClass } from '@instabrain-sdks/api-client';
434
+
435
+ const quoteResp = await client.getQuote({
436
+ faceAmount: 500000,
437
+ benefitPeriod: 20,
438
+ flagTobaccoUse: false,
439
+ gender: Gender.Male,
440
+ stateCode: 'TX',
441
+ zipCode: null,
442
+ healthClass: HealthClass.Great,
443
+ rateClass: null,
444
+ height: { feet: 5, inches: 10 },
445
+ weightInLbs: null,
446
+ age: 40,
447
+ dateOfBirth: null,
448
+ riders: null,
449
+ paymentFreq: PaymentFrequency.Monthly,
450
+ firstName: 'John',
451
+ lastName: null,
452
+ email: null,
453
+ phoneNum: null
454
+ });
455
+
456
+ const { quoteResponseId } = quoteResp.selectedQuote;
335
457
  ```
336
458
 
337
- ### Reports
459
+ **Field priority rules:**
338
460
 
339
- #### `getProspects(request?: AgentPortalReq): Promise<ThirdPartyProspectsResp>`
461
+ - `zipCode` takes priority over `stateCode` if both are provided
462
+ - `dateOfBirth` takes priority over `age` if both are provided
340
463
 
341
- Get prospects data - quotes that haven't been converted to applications yet.
464
+ ### Step 2 - `startApplication(request: ThirdPartyStartApplicationReq)`
342
465
 
343
466
  ```typescript
344
- const portalReq : AgentPortalReq = {
345
- "startDate": null,
346
- "endDate": null,
347
- "dayCount": 10,
348
- "pageSize": 10,
349
- "pageIndex": 1
350
- };
351
- const prospects = await client.getProspects(portalReq);
467
+ const appResp = await client.startApplication({
468
+ quoteResponseId: quoteResp.selectedQuote.quoteResponseId,
469
+ firstName: 'John',
470
+ lastName: 'Smith',
471
+ email: 'john.smith@example.com',
472
+ phoneNumber: '5559876543'
473
+ });
352
474
 
353
- console.log(`Found ${prospects.prospectCount} prospects`);
475
+ const { opportunityId, agentLink, eAppAgentLink, applicantLink } = appResp;
354
476
  ```
355
477
 
356
- #### `getSales(request?: AgentPortalReq): Promise<ThirdPartySalesReportRes>`
478
+ **Response links:**
479
+
480
+
481
+ | Field | Description |
482
+ | --------------- | -------------------------------------------------------------------- |
483
+ | `agentLink` | URL for the agent to complete their section in the InstaBrain portal |
484
+ | `eAppAgentLink` | Alternate agent URL used in eApp mode (some partner configurations) |
485
+ | `applicantLink` | URL sent to the proposed insured for their self-service section |
357
486
 
358
- Get sales data - completed/sold policies.
487
+
488
+ ### Steps 3–4 - Secure Sign → Final Submit
489
+
490
+ See [Secure Sign Flow](#secure-sign-flow) and [Final Submit](#final-submit).
491
+
492
+ ---
493
+
494
+ ## Secure Sign Flow
495
+
496
+ Shared across all products. Used to electronically sign application documents after EFT payment.
497
+
498
+ ### Complete flow
499
+
500
+ ```
501
+ prepareDocsAndGetDeliveryChannels(opportunityId)
502
+ ↓
503
+ [if isSignCompleted = true] → skip directly to finalSubmit()
504
+ ↓
505
+ sendPinAndGetDocumentsLink()
506
+ ↓
507
+ [agent reads script aloud; applicant reviews and signs documents via link]
508
+ ↓
509
+ verifyPin() [or resendPin() if PIN was not received]
510
+ ↓
511
+ finalSubmit()
512
+ ```
513
+
514
+ ### Step 1 - `prepareDocsAndGetDeliveryChannels(opportunityId: string)`
515
+
516
+ Always call this first in the signing flow. If `isSignCompleted` is `true`, skip directly to `finalSubmit()`.
359
517
 
360
518
  ```typescript
361
- const salesReq : AgentPortalReq = {
362
- "startDate": null,
363
- "endDate": null,
364
- "dayCount": 10,
365
- "pageSize": 10,
366
- "pageIndex": 1
367
- };
368
- const sales = await client.getSales(salesReq);
519
+ const prepResp = await client.prepareDocsAndGetDeliveryChannels(opportunityId);
369
520
 
370
- console.log(`Total sales: ${sales.applicationCount}`);
371
- console.log(`Total premium: $${sales.totalPremiumAmount}`);
521
+ if (prepResp.isSignCompleted) {
522
+ // Documents already signed - go to finalSubmit()
523
+ } else {
524
+ console.log('SMS available:', prepResp.isSmsAvailable);
525
+ console.log('Email available:', prepResp.isEmailAvailable);
526
+ }
372
527
  ```
373
528
 
374
- #### `getApplications(request?: AgentPortalReq): Promise<ThirdPartyApplicationReportRes>`
529
+ ### Step 2 - `sendPinAndGetDocumentsLink(request: ThirdPartySendPinReq)`
375
530
 
376
- Get applications data - applications in progress.
531
+ At least one of `flagSendSms` or `flagSendEmail` must be `true`.
377
532
 
378
533
  ```typescript
379
- const applicationsReq : AgentPortalReq = {
380
- "startDate": null,
381
- "endDate": null,
382
- "dayCount": 10,
383
- "pageSize": 10,
384
- "pageIndex": 1
385
- };
386
- const applications = await client.getApplications(applicationsReq);
534
+ const pinResp = await client.sendPinAndGetDocumentsLink({
535
+ opportunityId,
536
+ flagSendSms: true,
537
+ flagSendEmail: false
538
+ });
387
539
 
388
- console.log(`Applications needing attention: ${applications.applicationCount}`);
540
+ // pinResp.link - URL for the applicant to review and sign documents
541
+ // pinResp.scriptHeader - header for the disclosure section
542
+ // pinResp.script - array of disclosure statements to read aloud
543
+ // pinResp.consentMessage - consent statement with the applicant's name
389
544
  ```
390
545
 
391
- ## Environment Configuration
546
+ ### Step 3 - Agent reads script; applicant signs
547
+
548
+ 1. The agent reads each item in `pinResp.script` aloud to the proposed insured
549
+ 2. The applicant opens `pinResp.link` in their browser to review and sign documents
550
+ 3. *(Non-code step - the SDK does not manage the applicant's browser session)*
551
+
552
+ ### Step 4 - `verifyPin(request: ThirdPartyVerifyPinReq)`
392
553
 
393
- The SDK supports production and sandbox environments:
554
+ `isScriptReadConfirmed: true` is required - confirms the agent has read the disclosure aloud.
394
555
 
395
556
  ```typescript
396
- // Production environment (default)
397
- const prodClient = InstaBrainClient.forEnvironment('production');
557
+ const verifyResp = await client.verifyPin({
558
+ opportunityId,
559
+ pin: '123456',
560
+ isScriptReadConfirmed: true
561
+ });
398
562
 
399
- // Sandbox environment for testing
400
- const sandboxClient = InstaBrainClient.forEnvironment('sandbox');
563
+ if (verifyResp.isVerified) {
564
+ // Signing complete - proceed to finalSubmit()
565
+ }
401
566
  ```
402
567
 
403
- ## Error Handling
568
+ **Optional - `resendPin` (if PIN was not received):**
569
+
570
+ ```typescript
571
+ await client.resendPin({
572
+ opportunityId,
573
+ flagSendSms: true,
574
+ flagSendEmail: false
575
+ });
576
+ ```
577
+
578
+ ---
404
579
 
405
- The SDK provides specific error types for different scenarios:
580
+ ## Final Submit
581
+
582
+ Shared across all products. Submits the completed application to the carrier for underwriting.
406
583
 
407
584
  ```typescript
408
- import {
409
- InstaBrainError,
410
- AuthenticationError,
411
- ValidationError,
412
- APIValidationError,
413
- APIErrorCode
414
- } from '@instabrain-sdks/api-client';
585
+ const submitResp = await client.finalSubmit(opportunityId);
586
+ console.log('Policy number:', submitResp.policyNumber);
587
+ ```
415
588
 
416
- try {
417
- await client.authenticate(userId, accessToken);
418
- } catch (error) {
419
- if (error instanceof APIValidationError) {
420
- // Business-logic error with a specific error code
421
- console.error('API validation error:', error.errorCode);
422
- console.error('Friendly message:', error.getUserFriendlyMessage());
423
- if (error.isErrorType(APIErrorCode.SecureSignPinMismatch)) {
424
- console.error('PIN did not match — please try again');
425
- }
426
- } else if (error instanceof AuthenticationError) {
427
- console.error('Authentication failed:', error.message);
428
- } else if (error instanceof ValidationError) {
429
- console.error('Validation error:', error.message);
430
- } else if (error instanceof InstaBrainError) {
431
- console.error('API error:', error.message, error.statusCode);
432
- } else {
433
- console.error('Unexpected error:', error);
434
- }
589
+ > `**policyNumber: null**` is normal - the carrier may not issue a policy number immediately (pending underwriting decision). This is **not** an error.
590
+
591
+ > **Throws `PaymentNotMade`** if `saveEftPayment()` / `saveAdbEftPayment()` was not called before this step.
592
+
593
+ ---
594
+
595
+ ## Reporting API
596
+
597
+ Three methods for retrieving data from the agent portal. `pageSize` and `pageIndex` are required.
598
+
599
+ ```typescript
600
+ import { AgentPortalReq } from '@instabrain-sdks/api-client';
601
+
602
+ const request: AgentPortalReq = {
603
+ pageSize: 20, // required
604
+ pageIndex: 0 // required, 0-based
605
+ };
606
+ ```
607
+
608
+ ### Methods
609
+
610
+ ```typescript
611
+ // Quotes not yet converted to applications
612
+ const prospects = await client.getProspects(request);
613
+ // Returns: { prospectCount: number, prospects: ThirdPartyProspectsDetails[] }
614
+
615
+ // Completed / sold policies
616
+ const sales = await client.getSales(request);
617
+ // Returns: { applicationCount: number, salesReport: ThirdPartySalesReport[], totalPremiumAmount: number }
618
+
619
+ // Applications in progress
620
+ const applications = await client.getApplications(request);
621
+ // Returns: { applicationCount: number, applications: ThirdPartyApplicationsReport[] }
622
+ ```
623
+
624
+ ### Full `AgentPortalReq` field reference
625
+
626
+
627
+ | Field | Type | Required | Description |
628
+ | -------------- | ------------------------- | -------- | --------------------------------------------- |
629
+ | `pageSize` | `number` | **Yes** | Items per page |
630
+ | `pageIndex` | `number` | **Yes** | Page index, 0-based |
631
+ | `startDate` | `string` (ISO) | No | Start of date range |
632
+ | `endDate` | `string` (ISO) | No | End of date range |
633
+ | `dayCount` | `number` | No | Alternative to date range - fetch last N days |
634
+ | `userTimeZone` | `string` | No | IANA timezone (e.g., `'America/Chicago'`) |
635
+ | `sort` | `AgentPortalReqSorting` | No | Sort configuration |
636
+ | `filters` | `AgentPortalReqFilters[]` | No | Array of filters |
637
+ | `searchParam` | `string` | No | Text search |
638
+
639
+
640
+ ### Sorting (`AgentPortalReqSorting`)
641
+
642
+ ```typescript
643
+ sort: {
644
+ value: 'createdOn',
645
+ sortDescending: true
435
646
  }
436
647
  ```
437
648
 
438
- ## Types and Enums
649
+ ### Filtering (`AgentPortalReqFilters[]`)
650
+
651
+ ```typescript
652
+ import { SQLOperator } from '@instabrain-sdks/api-client';
653
+
654
+ filters: [
655
+ {
656
+ field: 'stateCode',
657
+ operator: SQLOperator.Equal,
658
+ value: 'TX'
659
+ }
660
+ ]
661
+ ```
662
+
663
+ `**SQLOperator` enum values:**
664
+
665
+
666
+ | Enum Member | Numeric Value | Description |
667
+ | -------------------- | ------------- | --------------------- |
668
+ | `Equal` | `0` | Exact match |
669
+ | `NotEqual` | `1` | Not equal |
670
+ | `GreaterThan` | `2` | Greater than |
671
+ | `GreaterThanOrEqual` | `3` | Greater than or equal |
672
+ | `LessThan` | `4` | Less than |
673
+ | `LessThanOrEqual` | `5` | Less than or equal |
674
+ | `Contains` | `6` | Contains substring |
675
+ | `StartsWith` | `7` | Starts with |
676
+ | `EndsWith` | `8` | Ends with |
677
+ | `In` | `9` | In list |
678
+ | `NotIn` | `10` | Not in list |
679
+
680
+
681
+ ---
682
+
683
+ ## Request Type Reference
684
+
685
+ ### `ThirdPartyGigdbQuoteRequest`
686
+
687
+
688
+ | Field | Type | Required | Constraints |
689
+ | ------------- | ------------------ | -------- | ----------- |
690
+ | `faceAmount` | `number | null` | Yes |
691
+ | `gender` | `Gender` | Yes | |
692
+ | `stateCode` | `string | null` | Yes |
693
+ | `age` | `number | null` | Yes* |
694
+ | `dateOfBirth` | `string | null` | Yes* |
695
+ | `paymentFreq` | `PaymentFrequency` | Yes | |
696
+ | `isSmoker` | `boolean | null` | Yes |
697
+ | `firstName` | `string | null` | No |
698
+ | `lastName` | `string | null` | No |
699
+ | `email` | `string | null` | No |
700
+ | `phoneNum` | `string | null` | No |
701
+
702
+
703
+ ### `ThirdPartyGigdbAppReq`
704
+
705
+
706
+ | Field | Type | Required | Constraints |
707
+ | --------------------------------------- | -------------------------- | -------- | --------------------------------------------------- |
708
+ | `quoteResponseId` | `string` | Yes | UUID from quote response |
709
+ | `firstName` | `string | null` | No |
710
+ | `lastName` | `string | null` | No |
711
+ | `email` | `string | null` | No |
712
+ | `phoneNumber` | `string | null` | No |
713
+ | `isUsCitizen` | `boolean | null` | Yes |
714
+ | `isPayerAlsoOwnerAndInsured` | `boolean | null` | Yes |
715
+ | `isLegalUsResident` | `boolean | null` | No |
716
+ | `address` | `GigdbAddress` | Yes | See sub-fields below |
717
+ | `dateOfBirth` | `string | null` | Yes |
718
+ | `socialSecurityNumber` | `string | null` | Yes |
719
+ | `birthJurisdiction` | `GigdbBirthJurisdiction` | Yes | See sub-fields below |
720
+ | `isSmoker` | `boolean | null` | Yes |
721
+ | `nicotineInfo` | `GigdbNicotineInfo | null` | No |
722
+ | `hasExistingCoverage` | `boolean | null` | Yes |
723
+ | `willOtherCoverageBeReplacedOrFinanced` | `boolean | null` | No |
724
+ | `existingCoverageData` | `GigdbExistingCoverageData | null` | No |
725
+ | `beneficiaryDetails` | `BeneficiaryDetails` | Yes | See [Beneficiary Reference](#beneficiary-reference) |
439
726
 
440
- ### Gender
727
+
728
+ `**GigdbAddress`:**
729
+
730
+
731
+ | Field | Type |
732
+ | -------------- | ------- |
733
+ | `addressLine1` | `string |
734
+ | `city` | `string |
735
+ | `state` | `string |
736
+ | `zipcode` | `string |
737
+
738
+
739
+ `**GigdbBirthJurisdiction`:**
740
+
741
+
742
+ | Field | Type | Description |
743
+ | --------- | ------- | ----------- |
744
+ | `state` | `string | null` |
745
+ | `country` | `string | null` |
746
+
747
+
748
+ `**GigdbExistingCoverageData`:**
749
+
750
+
751
+ | Field | Type |
752
+ | --------------------------------- | ---------------------------- |
753
+ | `isExistingPolicyBeingTerminated` | `boolean |
754
+ | `existingCoverages` | `GigdbExistingCoverageInfo[] |
755
+
756
+
757
+ `**GigdbExistingCoverageInfo`:**
758
+
759
+
760
+ | Field | Type |
761
+ | ------------------ | -------- |
762
+ | `nameOfTheCompany` | `string |
763
+ | `insuranceAmount` | `string |
764
+ | `dateOfIssue` | `string |
765
+ | `toBeReplaced` | `boolean |
766
+ | `toBeFinanced` | `boolean |
767
+
768
+
769
+ ### `ThirdPartyGigdbUpdateQuoteReq`
770
+
771
+
772
+ | Field | Type | Required | Constraints |
773
+ | --------------- | ------------------ | -------- | ------------------------------------ |
774
+ | `opportunityId` | `string` | Yes | UUID from start application response |
775
+ | `faceAmount` | `number` | Yes | $5,000–$25,000 |
776
+ | `paymentFreq` | `PaymentFrequency` | Yes | |
777
+
778
+
779
+ > Must be called before `saveEftPayment()`. Cannot update after EFT payment is saved.
780
+
781
+ ### `ThirdPartyAdbQuoteRequest`
782
+
783
+
784
+ | Field | Type | Required | Constraints |
785
+ | ------------- | ------------------ | -------- | --------------------------------------------------------- |
786
+ | `faceAmount` | `number` | Yes | |
787
+ | `gender` | `Gender` | Yes | |
788
+ | `stateCode` | `string` | Yes | 2-char US state; not MA, NH, AK; CA not yet supported |
789
+ | `age` | `number` | Yes* | 20–59; required if `dateOfBirth` not provided |
790
+ | `dateOfBirth` | `string` | Yes* | ISO 8601; required if `age` not provided |
791
+ | `paymentFreq` | `PaymentFrequency` | Yes | |
792
+ | `riders` | `string[]` | No | Use `RiderType` enum values; availability varies by state |
793
+ | `firstName` | `string` | No | Max 35 chars |
794
+ | `lastName` | `string` | No | Max 35 chars |
795
+ | `email` | `string` | No | Valid email format |
796
+ | `phoneNum` | `string` | No | 10-digit numeric |
797
+
798
+
799
+ ### `ThirdPartyAdbAppReq`
800
+
801
+
802
+ | Field | Type | Required | Constraints |
803
+ | --------------------------------------- | ------------------------- | -------- | --------------------------------------------------- |
804
+ | `quoteResponseId` | `string` | Yes | UUID from ADB quote response |
805
+ | `firstName` | `string` | Yes | Max 35 chars |
806
+ | `lastName` | `string` | Yes | Max 35 chars |
807
+ | `email` | `string` | Yes | Valid email format |
808
+ | `phoneNumber` | `string` | Yes | 10-digit numeric |
809
+ | `isUsCitizen` | `boolean` | Yes | |
810
+ | `isLegalUsResident` | `boolean` | No | Required when `isUsCitizen = false` |
811
+ | `isPayerAlsoOwnerAndInsured` | `boolean` | Yes | Must be `true`; knockout if `false` |
812
+ | `address` | `AdbAddress` | Yes | See sub-fields below |
813
+ | `dateOfBirth` | `string` | Yes | ISO 8601; age must be 20–59 |
814
+ | `socialSecurityNumber` | `string` | Yes | Format: XXX-XX-XXXX |
815
+ | `hasExistingCoverage` | `boolean` | Yes | |
816
+ | `willOtherCoverageBeReplacedOrFinanced` | `boolean` | No | Required if `hasExistingCoverage = true` |
817
+ | `existingCoverageData` | `AdbExistingCoverageData` | No | Required if `hasExistingCoverage = true` |
818
+ | `beneficiaryDetails` | `BeneficiaryDetails` | Yes | See [Beneficiary Reference](#beneficiary-reference) |
819
+
820
+
821
+ `**AdbAddress`:**
822
+
823
+
824
+ | Field | Type | Constraints |
825
+ | -------------- | -------- | ------------------------------------------- |
826
+ | `addressLine1` | `string` | |
827
+ | `city` | `string` | |
828
+ | `state` | `string` | 2-char; must match state used at quote time |
829
+ | `zipcode` | `string` | 5-digit numeric |
830
+
831
+
832
+ ### `ThirdPartyEftPaymentReq` (shared - GIGDB and ADB)
833
+
834
+
835
+ | Field | Type | Required | Description |
836
+ | ------------------- | -------- | -------- | ------------------------------------ |
837
+ | `opportunityId` | `string` | Yes | UUID from start application response |
838
+ | `accountHolderName` | `string | null` | Yes |
839
+ | `routingNumber` | `string | null` | Yes |
840
+ | `accountNumber` | `string | null` | Yes |
841
+
842
+
843
+ > Use `saveEftPayment()` for GIGDB and `saveAdbEftPayment()` for ADB. Both methods accept this same type but call different backend endpoints.
844
+
845
+ ### `ThirdPartyQuoteReq` (IB Term - Secondary)
846
+
847
+
848
+ | Field | Type | Required | Constraints |
849
+ | ---------------- | ---------------------------------- | -------- | ----------------------------------------------- |
850
+ | `faceAmount` | `number` | Yes | See age-based limits below |
851
+ | `benefitPeriod` | `number` | Yes | 10, 20, or 30 (age-dependent - see table below) |
852
+ | `flagTobaccoUse` | `boolean` | Yes | |
853
+ | `gender` | `Gender` | Yes | |
854
+ | `stateCode` | `string | null` | Yes* |
855
+ | `zipCode` | `string | null` | Yes* |
856
+ | `rateClass` | `RateClass | null` | Yes* |
857
+ | `healthClass` | `HealthClass | null` | Yes* |
858
+ | `height` | `{ feet: number, inches: number }` | Yes* | Required if `weightInLbs` provided |
859
+ | `weightInLbs` | `number | null` | Yes* |
860
+ | `age` | `number | null` | Yes* |
861
+ | `dateOfBirth` | `string | null` | Yes* |
862
+ | `riders` | `ThirdPartyQuoteReqRider[] | null` | No |
863
+ | `paymentFreq` | `PaymentFrequency` | Yes | |
864
+ | `firstName` | `string | null` | No |
865
+ | `lastName` | `string | null` | No |
866
+ | `email` | `string | null` | No |
867
+ | `phoneNum` | `string | null` | No |
868
+
869
+
870
+ **Face amount limits (age-based):**
871
+
872
+
873
+ | Age | Min | Max |
874
+ | -------- | ------- | ---------- |
875
+ | Up to 55 | $50,000 | $1,000,000 |
876
+ | 56 | $50,000 | $900,000 |
877
+ | 57 | $50,000 | $800,000 |
878
+ | 58 | $50,000 | $700,000 |
879
+ | 59 | $50,000 | $600,000 |
880
+ | 60 | $50,000 | $500,000 |
881
+
882
+
883
+ **Benefit period availability:**
884
+
885
+
886
+ | Age | Tobacco use | Available periods |
887
+ | -------- | ----------- | ----------------- |
888
+ | Up to 45 | Any | 10, 20, 30 |
889
+ | 45–50 | Non-tobacco | 10, 20, 30 |
890
+ | 45–50 | Tobacco | 10, 20 |
891
+ | 51–60 | Any | 10, 20 |
892
+
893
+
894
+ ### `ThirdPartySendPinReq`
895
+
896
+
897
+ | Field | Type | Required | Constraints |
898
+ | --------------- | --------- | -------- | --------------------------------------------------------------- |
899
+ | `opportunityId` | `string` | Yes | |
900
+ | `flagSendSms` | `boolean` | Yes | At least one of `flagSendSms` or `flagSendEmail` must be `true` |
901
+ | `flagSendEmail` | `boolean` | Yes | At least one of `flagSendSms` or `flagSendEmail` must be `true` |
902
+
903
+
904
+ ### `ThirdPartyResendPinReq`
905
+
906
+
907
+ | Field | Type | Required | Constraints |
908
+ | --------------- | --------- | -------- | ----------------------------------------- |
909
+ | `opportunityId` | `string` | Yes | |
910
+ | `flagSendSms` | `boolean` | Yes | At least one delivery flag must be `true` |
911
+ | `flagSendEmail` | `boolean` | Yes | At least one delivery flag must be `true` |
912
+
913
+
914
+ ### `ThirdPartyVerifyPinReq`
915
+
916
+
917
+ | Field | Type | Required | Constraints |
918
+ | ----------------------- | --------- | -------- | -------------------------------------------------- |
919
+ | `opportunityId` | `string` | Yes | |
920
+ | `pin` | `string` | Yes | PIN entered by the signer |
921
+ | `isScriptReadConfirmed` | `boolean` | Yes | Must be `true`; confirms disclosure was read aloud |
922
+
923
+
924
+ ---
925
+
926
+ ## Response Type Reference
927
+
928
+ ### `BaseResponse<T>`
929
+
930
+ All InstaBrain API responses are wrapped in this envelope:
441
931
 
442
932
  ```typescript
443
- enum Gender {
444
- Male = 1,
445
- Female = 2
933
+ interface BaseResponse<T> {
934
+ flagStatus: boolean; // true = success, false = API-level error
935
+ value: T; // the actual response data
936
+ error: string | null; // error message when flagStatus = false
937
+ errorCode?: string; // error code when flagStatus = false
446
938
  }
447
939
  ```
448
940
 
449
- ### Payment Frequency
941
+ The SDK unwraps this envelope automatically - integrators receive `value` directly. When `flagStatus = false`, the SDK throws `APIValidationError`. You never check `flagStatus` manually.
942
+
943
+ ### `ThirdPartyQuoteResp`
944
+
945
+ Returned by `getGigdbQuote()`, `getAdbQuote()`, `getQuote()`, `updateGigdbQuote()`, `getExistingGigdbQuote()`.
450
946
 
451
947
  ```typescript
452
- enum PaymentFrequency {
453
- Annual = 1,
454
- Monthly = 12
948
+ interface ThirdPartyQuoteResp {
949
+ productName: string | null;
950
+ selectedQuote: Quote;
455
951
  }
456
952
  ```
457
953
 
458
- ### Rate Class
954
+ **Key `Quote` fields:**
955
+
956
+
957
+ | Field | Type | Description |
958
+ | ------------------- | ------------- | -------------------------------------- |
959
+ | `quoteResponseId` | `string` | UUID - pass to `startXxxApplication()` |
960
+ | `quoteAmount` | `number | null` |
961
+ | `faceAmount` | `number` | Coverage amount |
962
+ | `benefitPeriod` | `number | null` |
963
+ | `paymentFrequency` | `string | null` |
964
+ | `isMedicalRequired` | `boolean` | Whether a medical exam is required |
965
+ | `selectedRiders` | `RidersList[] | null` |
966
+
967
+
968
+ ### `ThirdPartyStartAppResp` (GIGDB, IB Term)
969
+
970
+ Returned by `startGigdbApplication()` and `startApplication()`.
971
+
972
+
973
+ | Field | Type | Description |
974
+ | ---------------- | --------- | --------------------------------------------- |
975
+ | `opportunityId` | `string` | UUID - used for all subsequent calls |
976
+ | `agentLink` | `string | null` |
977
+ | `eAppAgentLink` | `string | null` |
978
+ | `applicantLink` | `string | null` |
979
+ | `isDeclined` | `boolean` | `true` = valid knockout (GIGDB); not an error |
980
+ | `isQuoteChanged` | `boolean` | `true` = premium was adjusted (GIGDB) |
981
+
982
+
983
+ ### `AdbRiderDetailsResp` (ADB only)
984
+
985
+ Returned by `getAdbRiderDetails()`.
986
+
987
+ | Field | Type | Description |
988
+ |---|---|---|
989
+ | `riders` | `AdbRiderResp[]` | Available riders for the state. May be empty even when product is available. |
990
+ | `flagProductNotAvailableForState` | `boolean` | `true` = ADB not available in this state; stop. `false` = available; proceed to quote. |
991
+
992
+ ### `AdbRiderResp`
993
+
994
+ | Field | Type | Description |
995
+ |---|---|---|
996
+ | `riderCode` | `string` | Pass into `ThirdPartyAdbQuoteRequest.riders` to include this rider in the quote. |
997
+ | `riderTitle` | `string` | Display title for UI rendering. |
998
+ | `riderDescription` | `string` | Display description for UI rendering. |
999
+
1000
+ ### `ThirdPartyAdbStartAppResp` (ADB only)
1001
+
1002
+ Returned by `startAdbApplication()`. Contains only two fields - no links, no `isQuoteChanged`:
1003
+
1004
+
1005
+ | Field | Type | Description |
1006
+ | --------------- | --------- | ------------------------------------------ |
1007
+ | `opportunityId` | `string` | UUID - empty GUID when `isDeclined = true` |
1008
+ | `isDeclined` | `boolean` | `true` = knockout; stop the flow |
1009
+
1010
+
1011
+ ### `ThirdPartyPrepareDocsResp`
1012
+
1013
+
1014
+ | Field | Type | Description |
1015
+ | ------------------ | --------- | ---------------------------------- |
1016
+ | `isSignCompleted` | `boolean` | If `true`, skip to `finalSubmit()` |
1017
+ | `isSmsAvailable` | `boolean` | SMS delivery channel available |
1018
+ | `isEmailAvailable` | `boolean` | Email delivery channel available |
1019
+ | `productName` | `string | null` |
1020
+
1021
+
1022
+ ### `ThirdPartySendPinResp`
1023
+
1024
+
1025
+ | Field | Type | Description |
1026
+ | ---------------- | --------- | ----------- |
1027
+ | `link` | `string | null` |
1028
+ | `scriptHeader` | `string | null` |
1029
+ | `script` | `string[] | null` |
1030
+ | `consentMessage` | `string | null` |
1031
+
1032
+
1033
+ ### `ThirdPartyResendPinResp`
1034
+
1035
+
1036
+ | Field | Type | Description |
1037
+ | ------------- | --------- | ----------------------------------- |
1038
+ | `flagPinSent` | `boolean` | `true` when PIN resent successfully |
1039
+
1040
+
1041
+ ### `ThirdPartyVerifyPinResp`
1042
+
1043
+
1044
+ | Field | Type | Description |
1045
+ | ------------ | --------- | ------------------------------------------------ |
1046
+ | `isVerified` | `boolean` | `true` when PIN matched and documents are signed |
1047
+
1048
+
1049
+ ### `ThirdPartyFinalSubmitResp`
1050
+
1051
+
1052
+ | Field | Type | Description |
1053
+ | -------------- | ------- | ----------- |
1054
+ | `policyNumber` | `string | null` |
1055
+
1056
+
1057
+ ---
1058
+
1059
+ ## Enums and Constants
1060
+
1061
+ ### `Gender`
1062
+
1063
+
1064
+ | Enum Member | Value |
1065
+ | --------------- | ---------- |
1066
+ | `Gender.Male` | `'Male'` |
1067
+ | `Gender.Female` | `'Female'` |
1068
+
1069
+
1070
+ ### `PaymentFrequency`
1071
+
1072
+
1073
+ | Enum Member | Value |
1074
+ | --------------------------- | ------------ |
1075
+ | `PaymentFrequency.Monthly` | `'Monthly'` |
1076
+ | `PaymentFrequency.Annually` | `'Annually'` |
1077
+
1078
+
1079
+ ### `HealthClass`
1080
+
1081
+
1082
+ | Enum Member | Value |
1083
+ | ----------------------- | ------------- |
1084
+ | `HealthClass.Excellent` | `'Excellent'` |
1085
+ | `HealthClass.Great` | `'Great'` |
1086
+ | `HealthClass.Good` | `'Good'` |
1087
+ | `HealthClass.Average` | `'Average'` |
1088
+
1089
+
1090
+ > **Note:** `HealthClass.Preferred` does **not** exist and will cause an API error if used.
1091
+
1092
+ ### `RateClass`
1093
+
1094
+
1095
+ | Enum Member | Value |
1096
+ | ------------------------- | ------------------ |
1097
+ | `RateClass.PreferredPlus` | `'Preferred Plus'` |
1098
+ | `RateClass.Preferred` | `'Preferred'` |
1099
+ | `RateClass.Standard` | `'Standard'` |
1100
+ | `RateClass.StandardExtra` | `'Standard Extra'` |
1101
+
1102
+
1103
+ > **Note:** Values contain spaces - always use enum members, not raw strings.
1104
+
1105
+ ### `RiderType`
1106
+
1107
+
1108
+ | Enum Member | Value | Coverage Range |
1109
+ | ------------------------------- | ------------------------- | ---------------- |
1110
+ | `RiderType.ADBRider` | `'ADB Rider'` | $25,000–$250,000 |
1111
+ | `RiderType.DependentChildRider` | `'Dependent Child Rider'` | $5,000–$25,000 |
1112
+
1113
+
1114
+ > **Note:** Values contain spaces - always use enum members.
1115
+
1116
+ ### `State`
1117
+
1118
+ All 50 US states + DC and 12 Canadian provinces/territories:
1119
+
1120
+ **US:** `AK`, `AL`, `AR`, `AZ`, `CA`, `CO`, `CT`, `DC`, `DE`, `FL`, `GA`, `HI`, `IA`, `ID`, `IL`, `IN`, `KS`, `KY`, `LA`, `MA`, `MD`, `ME`, `MI`, `MN`, `MO`, `MS`, `MT`, `NC`, `ND`, `NE`, `NH`, `NJ`, `NM`, `NV`, `NY`, `OH`, `OK`, `OR`, `PA`, `RI`, `SC`, `SD`, `TN`, `TX`, `UT`, `VA`, `VT`, `WA`, `WI`, `WV`, `WY`
1121
+
1122
+ **Canadian provinces/territories:** `AB`, `BC`, `MB`, `NB`, `NS`, `NT`, `NUNAVUT`, `ON`, `PE`, `PQ`, `SK`, `YT`
1123
+
1124
+ ### `Country`
1125
+
1126
+ Full ISO country code enum. Common values: `Country.UnitedStates` (`'US'`), `Country.Canada` (`'CA'`). Used in GIGDB's `birthJurisdiction.country`.
1127
+
1128
+ ### `BeneficiaryType`
1129
+
1130
+
1131
+ | Enum Member | Value |
1132
+ | --------------------------------- | ---------------------------------------- |
1133
+ | `Person` | `'Person'` |
1134
+ | `AllChildrenOfTheInsuredEqually` | `'All Children Of The Insured Equally'` |
1135
+ | `AllChildrenOfTheMarriageEqually` | `'All Children Of The Marriage Equally'` |
1136
+ | `InsuredEstate` | `'Insured Estate'` |
1137
+ | `Business` | `'Business'` |
1138
+ | `Corporation` | `'Corporation'` |
1139
+ | `CharitableOrganization` | `'Charitable Organization'` |
1140
+ | `Employer` | `'Employer'` |
1141
+ | `Other` | `'Other'` |
1142
+ | `Trust` | `'Trust'` |
1143
+
1144
+
1145
+ ### `BeneficiaryRelationship`
1146
+
1147
+ 36 values: `Aunt`, `Boyfriend`, `Brother`, `BrotherInLaw`, `CommonLawHusband`, `CommonLawWife`, `Cousin`, `Daughter`, `DaughterInLaw`, `DomesticPartner`, `Father`, `FatherInLaw`, `FatherOfChild`, `Fiance`, `Fiancee`, `FormerSpouse`, `Friend`, `Girlfriend`, `Granddaughter`, `Grandfather`, `Grandmother`, `Grandson`, `Husband`, `LifePartner`, `Mother`, `MotherInLaw`, `MotherOfChild`, `Nephew`, `Niece`, `Sister`, `SisterInLaw`, `Son`, `SonInLaw`, `Spouse`, `Uncle`, `Wife`
1148
+
1149
+ ### ADB Rider Availability
1150
+
1151
+ #### `ADB_RIDER_AVAILABLE_STATES`
1152
+
1153
+ ADB Rider available in: `AL`, `AZ`, `AR`, `CA`*, `CO`, `CT`, `DC`, `DE`, `FL`, `GA`, `HI`, `ID`, `IL`, `IN`, `IA`, `KS`, `KY`, `LA`, `ME`, `MD`, `MI`, `MN`, `MS`, `MO`, `MT`, `NE`, `NV`, `NJ`, `NM`, `NC`, `ND`, `OH`, `OK`, `OR`, `PA`, `RI`, `SC`, `SD`, `TN`, `TX`, `UT`, `VT`, `VA`, `WV`, `WI`
1154
+
1155
+ > CA: ADB product support is coming in the next SDK release and is not yet available.
1156
+
1157
+ #### `CHILD_RIDER_AVAILABLE_STATES`
1158
+
1159
+ Dependent Child Rider available in: `AL`, `AK`, `AZ`, `AR`, `CO`, `CT`, `DC`, `DE`, `GA`, `HI`, `ID`, `IL`, `IN`, `IA`, `KS`, `KY`, `LA`, `MD`, `MA`, `MI`, `MN`, `MS`, `MO`, `MT`, `NE`, `NV`, `NH`, `NJ`, `NM`, `NC`, `OH`, `OK`, `OR`, `PA`, `RI`, `SC`, `TN`, `TX`, `UT`, `VA`, `WV`, `WI`
1160
+
1161
+ #### `NO_RIDERS_AVAILABLE_STATES`
1162
+
1163
+ No riders available in: `WA`
1164
+
1165
+ > **Coming in a future release:** `getAvailableRidersForState(stateCode)` - programmatically query rider availability for a given state.
1166
+
1167
+ ---
1168
+
1169
+ ## Beneficiary Reference
1170
+
1171
+ The `beneficiaryDetails` field uses a TypeScript discriminated union. Required fields differ by `beneficiaryType`. TypeScript enforces the correct shape at compile time.
1172
+
1173
+ ### Variant 1 - No extra fields
1174
+
1175
+ Used for `InsuredEstate`, `AllChildrenOfTheInsuredEqually`, `AllChildrenOfTheMarriageEqually`:
459
1176
 
460
1177
  ```typescript
461
- enum RateClass {
462
- Standard = 'Standard',
463
- Preferred = 'Preferred',
464
- PreferredPlus = 'Preferred Plus',
465
- SuperPreferred = 'Super Preferred'
1178
+ beneficiaryDetails: {
1179
+ beneficiaryType: BeneficiaryType.InsuredEstate
466
1180
  }
467
1181
  ```
468
1182
 
469
- ### Health Class
1183
+ ### Variant 2 - Named person
1184
+
1185
+ Used when `beneficiaryType = Person`:
470
1186
 
471
1187
  ```typescript
472
- enum HealthClass {
473
- Standard = 'Standard',
474
- Preferred = 'Preferred',
475
- Excellent = 'Excellent',
476
- PreferredPlus = 'Preferred Plus',
477
- SuperPreferred = 'Super Preferred'
1188
+ beneficiaryDetails: {
1189
+ beneficiaryType: BeneficiaryType.Person,
1190
+ beneficiaryPerson: {
1191
+ firstName: 'Jane',
1192
+ lastName: 'Doe',
1193
+ relationship: BeneficiaryRelationship.Spouse
1194
+ }
478
1195
  }
479
1196
  ```
480
1197
 
481
- ## Advanced Usage
1198
+ ### Variant 3 - Named entity (organization)
482
1199
 
483
- ### Manual Token Management
1200
+ Used for `Business`, `Corporation`, `CharitableOrganization`, `Employer`, `Other`, `Trust`:
484
1201
 
485
1202
  ```typescript
486
- // Set a token manually (if you have one from elsewhere)
487
- client.setToken('your-jwt-token');
1203
+ // Business / Corporation / etc.
1204
+ beneficiaryDetails: {
1205
+ beneficiaryType: BeneficiaryType.Business,
1206
+ namedEntity: {
1207
+ name: 'Acme Corp',
1208
+ taxId: '12-3456789' // optional
1209
+ }
1210
+ }
488
1211
 
489
- // Check authentication status
490
- if (client.isAuthenticated()) {
491
- // Make API calls
1212
+ // Trust - trustDate is required (format: YYYY-MM)
1213
+ beneficiaryDetails: {
1214
+ beneficiaryType: BeneficiaryType.Trust,
1215
+ namedEntity: {
1216
+ name: 'Smith Family Trust',
1217
+ trustDate: '2020-01' // required for Trust only; format: YYYY-MM
1218
+ }
492
1219
  }
1220
+ ```
1221
+
1222
+ ---
1223
+
1224
+ ## Error Handling
1225
+
1226
+ ### Error class hierarchy
1227
+
1228
+ ```
1229
+ InstaBrainError
1230
+ ├── AuthenticationError (statusCode: 401 - credentials invalid or session expired)
1231
+ ├── ValidationError (statusCode: 400 - request-level validation failure)
1232
+ └── APIValidationError (statusCode: 400 - API returned flagStatus: false)
1233
+ ```
1234
+
1235
+ ### Field reference
493
1236
 
494
- // Get current token
495
- const currentToken = client.getCurrentToken();
496
1237
 
497
- // Logout (clear token)
498
- client.logout();
1238
+ | Class | `message` | `statusCode` | `errorCode` | `response` |
1239
+ | --------------------- | --------- | ------------ | ----------- | ---------- |
1240
+ | `InstaBrainError` | Yes | Yes | Yes | Yes |
1241
+ | `AuthenticationError` | Yes | `401` | - | - |
1242
+ | `ValidationError` | Yes | `400` | Yes | - |
1243
+ | `APIValidationError` | Yes | `400` | Yes | Yes |
1244
+
1245
+
1246
+ ### Using `APIValidationError`
1247
+
1248
+ Thrown when the API returns `flagStatus: false`. Always use `isErrorType(APIErrorCode.X)` for comparison - do **not** compare `errorCode` as a raw string, as the API uses inconsistent casing across error codes.
1249
+
1250
+ ```typescript
1251
+ import {
1252
+ APIValidationError,
1253
+ AuthenticationError,
1254
+ InstaBrainError,
1255
+ APIErrorCode
1256
+ } from '@instabrain-sdks/api-client';
1257
+
1258
+ try {
1259
+ const quoteResp = await client.getGigdbQuote(request);
1260
+ } catch (err) {
1261
+ if (err instanceof APIValidationError) {
1262
+ if (err.isErrorType(APIErrorCode.NotAvailableForState)) {
1263
+ console.error('Product not available in this state');
1264
+ } else if (err.isErrorType(APIErrorCode.AgeNotFound)) {
1265
+ console.error('Age is outside the eligible range for this product');
1266
+ } else {
1267
+ // getUserFriendlyMessage() returns a human-readable description
1268
+ console.error(err.getUserFriendlyMessage());
1269
+ }
1270
+ } else if (err instanceof AuthenticationError) {
1271
+ console.error('Authentication failed - re-authenticate');
1272
+ } else if (err instanceof InstaBrainError) {
1273
+ console.error(`SDK error: ${err.message} (status: ${err.statusCode})`);
1274
+ }
1275
+ }
499
1276
  ```
500
1277
 
501
- ### Base URL
1278
+ > `**isDeclined: true` is not an error.** It is a response field on `ThirdPartyStartAppResp` and `ThirdPartyAdbStartAppResp`, indicating the application was declined due to knockout criteria. Always check this field in the response - it is never thrown as an exception.
1279
+
1280
+ ---
1281
+
1282
+ ## APIErrorCode Reference
1283
+
1284
+ Always use `APIErrorCode` enum members with `err.isErrorType()`. Do not compare `errorCode` as a raw string - the API uses inconsistent casing.
1285
+
1286
+ ### General / Quote
1287
+
1288
+
1289
+ | Enum Member | String Value | Description |
1290
+ | ------------------------------------ | -------------------------------------- | ---------------------------------------------------------------- |
1291
+ | `StateNotFound` | `'stateNotFound'` | State code not recognized |
1292
+ | `RateClassNotFound` | `'RateClassNotFound'` | Rating input required (rateClass, healthClass, or height/weight) |
1293
+ | `RiderNotAvailable` | `'RiderNotAvailable'` | Rider not available in this state or for this age |
1294
+ | `HeightNotValid` | `'HeightNotValid'` | Height value is not valid |
1295
+ | `InvalidRateclass` | `'InvalidRateclass'` | Rate class value not recognized |
1296
+ | `InvalidHealthClass` | `'InvalidHealthClass'` | Health class value not recognized |
1297
+ | `ZipCodeNotFound` | `'ZipCodeNotFound'` | ZIP code not recognized |
1298
+ | `OutsideBuildChart` | `'outsideBuildChart'` | Height/weight combination not eligible |
1299
+ | `QuoteNotEligibleForGivenConditions` | `'QuoteNotEligibleForGivenConditions'` | Product not available for this state/age/tobacco combination |
1300
+ | `NotAvailableForState` | `'NotAvailableForState'` | Product not available in the specified state |
1301
+ | `BenefitPeriodNotAvailable` | `'BenefitPeriodNotAvailable'` | Benefit period not available for this age/tobacco combination |
1302
+ | `CoverageNotAvailable` | `'CoverageNotAvailable'` | Coverage amount not available for the given conditions |
1303
+ | `RiderFaceAmountNotValid` | `'RiderFaceAmountNotValid'` | Rider coverage amount outside permitted range |
1304
+ | `ThirdPartyQuoteError` | `'ThirdPartyQuoteError'` | General quote generation error |
1305
+ | `InvalidQuoteParameters` | `'InvalidQuoteParameters'` | Quote parameters are not valid |
1306
+ | `InvalidRequestFormat` | `'InvalidRequestFormat'` | Request format invalid; check required fields |
1307
+ | `QuoteNotFound` | `'QuoteNotFound'` | No previous quote found; create a quote first |
1308
+
1309
+
1310
+ ### GIGDB
1311
+
1312
+
1313
+ | Enum Member | String Value | Description |
1314
+ | -------------------------------------------- | ---------------------------------------------- | ----------------------------------------------- |
1315
+ | `AgeNotFound` | `'AgeNotFound'` | Age outside 50–85 range |
1316
+ | `AgentLogout` | `'AgentLogout'` | Agent session expired; re-authenticate |
1317
+ | `DataNotFound` | `'dataNotFound'` | Requested data not found |
1318
+ | `StateMismatchIdentified` | `'StateMismatchIdentified'` | State mismatch between quote and application |
1319
+ | `InvalidBirthCountry` | `'InvalidBirthCountry'` | Birth country not recognized |
1320
+ | `InvalidBirthState` | `'InvalidBirthState'` | Birth state not recognized |
1321
+ | `InvalidResidenceState` | `'InvalidResidenceState'` | Residence state not valid |
1322
+ | `OneOfTheExistingCoveragesQuestionsNotFound` | `'OneOfTheExistingCoveragesQuestionsNotFound'` | Existing coverage questions incomplete |
1323
+ | `PaymentAlreadyMade` | `'PaymentAlreadyMade'` | Payment already submitted for this application |
1324
+ | `ErrorInSaveEftPaymentDetails` | `'ErrorInSaveEftPaymentDetails'` | Failed to save EFT details; verify account info |
1325
+ | `InvalidPaymentScheduledDate` | `'InvalidPaymentScheduledDate'` | Scheduled payment date is not valid |
1326
+
1327
+
1328
+ ### ADB
1329
+
1330
+
1331
+ | Enum Member | String Value | Description |
1332
+ | -------------------- | ---------------------- | ---------------------------------------------------------------------------- |
1333
+ | `InvalidStateCode` | `'InvalidStateCode'` | State not supported for ADB (MA, NH, AK unavailable; CA coming next release) |
1334
+ | `InvalidAdbAgeRange` | `'InvalidAdbAgeRange'` | Age outside 20–59 range |
1335
+
1336
+
1337
+ ### Final Submit
1338
+
1339
+
1340
+ | Enum Member | String Value | Description |
1341
+ | ---------------- | ------------------ | ------------------------------------------------- |
1342
+ | `PaymentNotMade` | `'paymentNotMade'` | EFT payment must be completed before final submit |
1343
+
1344
+
1345
+ ### Secure Sign
1346
+
1347
+
1348
+ | Enum Member | String Value | Description |
1349
+ | -------------------------- | ---------------------------- | -------------------------------------------------------- |
1350
+ | `SecureSignRelatedError` | `'SecureSignRelatedError'` | General signing error |
1351
+ | `SigningPackageNotCreated` | `'SigningPackageNotCreated'` | No signing package exists; complete previous steps first |
1352
+ | `SecureSignPinMismatch` | `'SecureSignPinMismatch'` | PIN entered is incorrect |
1353
+ | `PinExpired` | `'PinExpired'` | PIN has expired; request a new one |
1354
+ | `DocumentsNotViewed` | `'DocumentsNotViewed'` | All documents must be viewed before verifying PIN |
1355
+ | `DocumentsAlreadySigned` | `'DocumentsAlreadySigned'` | Documents already signed for this application |
1356
+
1357
+
1358
+ ---
1359
+
1360
+ ## Environment Configuration
1361
+
1362
+ Pass `'sandbox'` or `'production'` to `InstaBrainClient.forEnvironment()`. The SDK handles all routing internally.
502
1363
 
503
1364
  ```typescript
504
- // Get current base URL
505
- const currentUrl = client.getBaseUrl();
1365
+ // Sandbox - for development and testing
1366
+ const client = InstaBrainClient.forEnvironment('sandbox');
1367
+
1368
+ // Production
1369
+ const client = InstaBrainClient.forEnvironment('production');
506
1370
  ```
507
1371
 
508
- ## Examples
1372
+ > Sandbox credentials are separate from production credentials. Both are provisioned independently during onboarding.
509
1373
 
510
- Check out the [examples](./examples) directory for more detailed usage examples:
1374
+ ---
511
1375
 
512
- - [Basic Usage](./examples/basic-usage.ts) - Complete workflow from authentication to application
513
- - [Error Handling](./examples/error-handling.ts) - Comprehensive error handling patterns
514
- - [Environment Switching](./examples/environment-switching.ts) - Working with different environments
1376
+ ## Token Management
515
1377
 
516
- ## Requirements
517
1378
 
518
- - Node.js 14.0.0 or higher
519
- - TypeScript 4.0 or higher (for TypeScript projects)
1379
+ | Method | Signature | Description |
1380
+ | ------------------- | ------------------------- | ----------------------------------------------------------- |
1381
+ | `isAuthenticated()` | `() => boolean` | Returns `true` if a JWT is currently stored |
1382
+ | `getCurrentToken()` | `() => string | null` |
1383
+ | `setToken(token)` | `(token: string) => void` | Manually set a JWT (e.g., restored from persistent storage) |
1384
+ | `logout()` | `() => void` | Clears the stored JWT |
1385
+ | `getBaseUrl()` | `() => string` | Returns the configured base URL (for debugging only) |
520
1386
 
521
- ## License
522
- This software is proprietary and confidential. Unauthorized copying, distribution, or modification is strictly prohibited.
523
1387
 
524
- ## Support
1388
+ ---
1389
+
1390
+ ## Examples Directory
1391
+
1392
+ Working examples are in the `./examples/` directory:
525
1393
 
526
- For technical support and questions:
527
1394
 
528
- - **Email**: helpdesk@instabrain.io
529
- - **Website**: https://www.instabrain.io
1395
+ | File | Description |
1396
+ | ---------------------------- | ---------------------------------------------------- |
1397
+ | `basic-usage.ts` | Authentication and basic quote/application flows |
1398
+ | `error-handling.ts` | Error catching and handling patterns |
1399
+ | `api-constraints-example.ts` | State restrictions, age limits, and validation rules |
1400
+ | `reports-example.ts` | Prospects, sales, and applications reporting |
1401
+
1402
+
1403
+ ---
530
1404
 
531
1405
  ## Changelog
532
1406
 
533
- See [CHANGELOG.md](CHANGELOG.md) for a list of changes in each version.
1407
+ See [CHANGELOG.md](./CHANGELOG.md).
1408
+
1409
+ ---
1410
+
1411
+ ## Support
1412
+
1413
+ - **Email:** [helpdesk@instabrain.io](mailto:helpdesk@instabrain.io)
1414
+ - **Website:** [https://www.instabrain.io](https://www.instabrain.io)
1415
+