@instabrain-sdks/api-client 2.0.0 → 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 -348
  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 -2
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,525 +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
- });
73
-
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
- ```
56
+ ## Authentication
94
57
 
95
- ## Features
58
+ Credentials are issued during onboarding:
96
59
 
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
107
60
 
108
- ## API Reference
61
+ | Credential | Type | Description |
62
+ | ------------- | --------------- | ------------------------ |
63
+ | `userId` | `number` | Your account user ID |
64
+ | `accessToken` | `string` (UUID) | Your secret access token |
109
65
 
110
- ### Authentication
111
-
112
- #### `authenticate(userId: number, accessToken: string): Promise<string>`
113
-
114
- Authenticate with the InstaBrain API and obtain a JWT token.
115
66
 
116
67
  ```typescript
117
- const jwtToken = await client.authenticate(12345, 'uuid-access-token');
68
+ import { InstaBrainClient } from '@instabrain-sdks/api-client';
69
+
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()
118
74
  ```
119
75
 
120
- ### Quotes
76
+ > Call `authenticate()` once at startup. The returned JWT is stored internally - every subsequent API call uses it automatically.
121
77
 
122
- #### `getQuote(request: ThirdPartyQuoteReq): Promise<ThirdPartyQuoteResp>`
78
+ ---
123
79
 
124
- Get an insurance quote based on the provided parameters.
80
+ ## Product Comparison
125
81
 
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
82
 
148
- ### Applications
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)* |
149
97
 
150
- #### `startApplication(request: ThirdPartyStartApplicationReq): Promise<ThirdPartyStartAppResp>`
151
98
 
152
- Start an insurance application from a quote.
99
+ ---
153
100
 
154
- ```typescript
155
- const startApplicationReq : ThirdPartyStartApplicationReq = {
156
- quoteResponseId: quote.selectedQuote.quoteResponseId,
157
- firstName: 'John',
158
- lastName: 'Doe',
159
- email: 'john.doe@example.com',
160
- phoneNumber: '555-1234'
161
- };
162
- const application = await client.startApplication(startApplicationReq);
101
+ ## GIGDB Flow
163
102
 
164
- // Access the generated links
165
- console.log('Agent Link:', application.agentLink);
166
- console.log('Applicant Link:', application.applicantLink);
167
- ```
103
+ > **Not available in:** NY, MT
104
+
105
+ GIGDB (Guaranteed Issue Graded Death Benefit) is a simplified-issue whole life product for ages 50–85 with no medical exam.
168
106
 
169
- ### GIGDB (Guaranteed Issue)
107
+ ### Complete flow
170
108
 
171
- #### `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
+ ```
172
127
 
173
- Get a Guaranteed Issue quote (ages 50-85, face amount $5k-$25k).
128
+ ### Step 1 - `getGigdbQuote(request: ThirdPartyGigdbQuoteRequest)`
174
129
 
175
130
  ```typescript
176
- const gigdbQuoteReq: ThirdPartyGigdbQuoteRequest = {
131
+ import { InstaBrainClient, Gender, PaymentFrequency } from '@instabrain-sdks/api-client';
132
+
133
+ const quoteResp = await client.getGigdbQuote({
177
134
  faceAmount: 15000,
178
135
  gender: Gender.Female,
179
136
  stateCode: 'TX',
180
137
  age: 65,
181
- dateOfBirth: '1961-01-15',
138
+ dateOfBirth: null,
182
139
  paymentFreq: PaymentFrequency.Monthly,
140
+ isSmoker: false,
183
141
  firstName: 'Jane',
184
- lastName: 'Smith',
185
- email: 'jane.smith@example.com',
186
- phoneNum: '555-0123',
187
- isSmoker: false
188
- };
189
- const quote = await client.getGigdbQuote(gigdbQuoteReq);
190
- ```
142
+ lastName: 'Doe',
143
+ email: 'jane.doe@example.com',
144
+ phoneNum: null
145
+ });
191
146
 
192
- #### `startGigdbApplication(request: ThirdPartyGigdbAppReq): Promise<ThirdPartyStartAppResp>`
147
+ const { quoteResponseId, quoteAmount } = quoteResp.selectedQuote;
148
+ ```
193
149
 
194
- Start a GIGDB application. Note: `isDeclined: true` is a valid response (knockout), not an error.
150
+ ### Step 2 - `startGigdbApplication(request: ThirdPartyGigdbAppReq)`
195
151
 
196
152
  ```typescript
197
- const gigdbAppReq: ThirdPartyGigdbAppReq = {
198
- 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,
199
157
  firstName: 'Jane',
200
- lastName: 'Smith',
201
- email: 'jane.smith@example.com',
202
- phoneNumber: '555-0123',
158
+ lastName: 'Doe',
159
+ email: 'jane.doe@example.com',
160
+ phoneNumber: '5551234567',
203
161
  isUsCitizen: true,
204
162
  isPayerAlsoOwnerAndInsured: true,
205
- isSmoker: false,
206
- dateOfBirth: '1961-01-15',
207
- socialSecurityNumber: '123456789',
163
+ isLegalUsResident: true,
208
164
  address: {
209
165
  addressLine1: '123 Main St',
210
- city: 'Dallas',
166
+ city: 'Austin',
211
167
  state: 'TX',
212
- zipcode: '75001'
168
+ zipcode: '73301'
213
169
  },
170
+ dateOfBirth: '1958-06-15',
171
+ socialSecurityNumber: '123-45-6789',
214
172
  birthJurisdiction: {
215
- country: 'US',
216
- state: 'TX'
173
+ state: 'TX',
174
+ country: 'US'
217
175
  },
176
+ isSmoker: false,
177
+ nicotineInfo: null,
218
178
  hasExistingCoverage: false,
219
- existingCoverageData: null,
220
179
  willOtherCoverageBeReplacedOrFinanced: null,
180
+ existingCoverageData: null,
221
181
  beneficiaryDetails: {
222
- beneficiaryType: 'Person',
182
+ beneficiaryType: BeneficiaryType.Person,
223
183
  beneficiaryPerson: {
224
184
  firstName: 'John',
225
- lastName: 'Smith',
226
- relationship: 'Spouse'
227
- },
228
- namedEntity: null
185
+ lastName: 'Doe',
186
+ relationship: BeneficiaryRelationship.Spouse
187
+ }
229
188
  }
230
- };
231
- const app = await client.startGigdbApplication(gigdbAppReq);
232
- console.log('Opportunity ID:', app.opportunityId);
233
- 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;
234
199
  ```
235
200
 
236
- #### `saveEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>`
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.
237
204
 
238
- Returns `true` when payment saved successfully.
205
+ ### Step 3 - Handle quote change (conditional)
239
206
 
240
207
  ```typescript
241
- const eftReq: ThirdPartyEftPaymentReq = {
242
- opportunityId: app.opportunityId,
243
- accountHolderName: 'Jane Smith',
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
+ }
215
+ ```
216
+
217
+ ### Step 4 - `updateGigdbQuote` (optional - must be called BEFORE `saveEftPayment`)
218
+
219
+ If the applicant wants to change the face amount or payment frequency after the application has started:
220
+
221
+ ```typescript
222
+ const updatedQuoteResp = await client.updateGigdbQuote({
223
+ opportunityId,
224
+ faceAmount: 20000,
225
+ paymentFreq: PaymentFrequency.Annually
226
+ });
227
+ // updatedQuoteResp.selectedQuote.quoteAmount reflects the new premium
228
+ ```
229
+
230
+ > **Important:** The quote cannot be updated after EFT payment details are saved. `updateGigdbQuote()` must be called before `saveEftPayment()`.
231
+
232
+ ### Step 5 - `saveEftPayment(request: ThirdPartyEftPaymentReq)`
233
+
234
+ ```typescript
235
+ await client.saveEftPayment({
236
+ opportunityId,
237
+ accountHolderName: 'Jane Doe',
244
238
  routingNumber: '021000021',
245
239
  accountNumber: '123456789'
246
- };
247
- const success = await client.saveEftPayment(eftReq);
248
- console.log('Payment saved:', success);
240
+ });
241
+ // After this point, the quote can no longer be updated.
242
+ ```
243
+
244
+ ### Steps 6–7 - Secure Sign → Final Submit
245
+
246
+ See [Secure Sign Flow](#secure-sign-flow) and [Final Submit](#final-submit).
247
+
248
+ ---
249
+
250
+ ## ADB Flow
251
+
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.
255
+
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()
249
278
  ```
250
279
 
251
- #### `updateGigdbQuote(request: ThirdPartyGigdbUpdateQuoteReq): Promise<ThirdPartyQuoteResp>`
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.
252
283
 
253
- Update a GIGDB quote with a different face amount or payment frequency.
284
+ > **Note:** California (`CA`) is not supported — the API will return a 400 error for `stateCode = "CA"`.
254
285
 
255
286
  ```typescript
256
- const updateReq: ThirdPartyGigdbUpdateQuoteReq = {
257
- opportunityId: app.opportunityId,
258
- faceAmount: 20000,
259
- paymentFreq: PaymentFrequency.Annual
260
- };
261
- const updatedQuote = await client.updateGigdbQuote(updateReq);
262
- console.log('Updated face amount:', updatedQuote.selectedQuote.faceAmount);
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
263
299
  ```
264
300
 
265
- #### `getExistingGigdbQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>`
301
+ > **Note:** `riders` may be an empty array even when `flagProductNotAvailableForState = false` — this means no optional riders are configured for that state.
266
302
 
267
- Get the existing quote for a GIGDB opportunity. Use when `isQuoteChanged=true` after `startGigdbApplication`.
303
+ ### Step 1 - `getAdbQuote(request: ThirdPartyAdbQuoteRequest)`
268
304
 
269
305
  ```typescript
270
- const existingQuote = await client.getExistingGigdbQuote(app.opportunityId);
271
- console.log('Current quote:', existingQuote.selectedQuote.quoteAmount);
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'
318
+ });
319
+
320
+ const { quoteResponseId } = quoteResp.selectedQuote;
272
321
  ```
273
322
 
274
- ### Secure Sign (Document Signing)
323
+ **Rider notes:**
275
324
 
276
- The signing flow is shared across all products. Call after EFT payment has been saved.
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)
277
327
 
278
- #### `prepareDocsAndGetDeliveryChannels(opportunityId: string): Promise<ThirdPartyPrepareDocsResp>`
328
+ ### Step 2 - `startAdbApplication(request: ThirdPartyAdbAppReq)`
279
329
 
280
- Prepare the signing package and check available delivery channels. If `isSignCompleted` is true, skip directly to `finalSubmit()`.
330
+ ```typescript
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
+ }
358
+ });
359
+
360
+ if (appResp.isDeclined) {
361
+ // Valid knockout - stop the flow
362
+ return;
363
+ }
364
+
365
+ const { opportunityId } = appResp;
366
+ ```
367
+
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)
379
+
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)`
281
385
 
282
386
  ```typescript
283
- const docs = await client.prepareDocsAndGetDeliveryChannels(app.opportunityId);
284
- console.log('SMS available:', docs.isSmsAvailable);
285
- console.log('Already signed:', docs.isSignCompleted);
387
+ await client.saveAdbEftPayment({
388
+ opportunityId,
389
+ accountHolderName: 'John Smith',
390
+ routingNumber: '021000021',
391
+ accountNumber: '987654321'
392
+ });
393
+ // After this point, the quote can no longer be updated.
286
394
  ```
287
395
 
288
- #### `sendPinAndGetDocumentsLink(request: ThirdPartySendPinReq): Promise<ThirdPartySendPinResp>`
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
289
399
 
290
- Send a verification PIN via SMS and/or Email and receive the documents link.
400
+ See [Secure Sign Flow](#secure-sign-flow) and [Final Submit](#final-submit).
401
+
402
+ ---
403
+
404
+ ## IB Term Flow
405
+
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
409
+
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
291
431
 
292
432
  ```typescript
293
- const pinResp = await client.sendPinAndGetDocumentsLink({
294
- opportunityId: app.opportunityId,
295
- flagSendSms: true,
296
- flagSendEmail: true
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;
457
+ ```
458
+
459
+ **Field priority rules:**
460
+
461
+ - `zipCode` takes priority over `stateCode` if both are provided
462
+ - `dateOfBirth` takes priority over `age` if both are provided
463
+
464
+ ### Step 2 - `startApplication(request: ThirdPartyStartApplicationReq)`
465
+
466
+ ```typescript
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'
297
473
  });
298
- console.log('Documents link:', pinResp.link);
299
- console.log('Script to read:', pinResp.script);
474
+
475
+ const { opportunityId, agentLink, eAppAgentLink, applicantLink } = appResp;
476
+ ```
477
+
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 |
486
+
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()`.
517
+
518
+ ```typescript
519
+ const prepResp = await client.prepareDocsAndGetDeliveryChannels(opportunityId);
520
+
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
+ }
300
527
  ```
301
528
 
302
- #### `resendPin(request: ThirdPartyResendPinReq): Promise<ThirdPartyResendPinResp>`
529
+ ### Step 2 - `sendPinAndGetDocumentsLink(request: ThirdPartySendPinReq)`
303
530
 
304
- Resend the verification PIN if the signer did not receive it.
531
+ At least one of `flagSendSms` or `flagSendEmail` must be `true`.
305
532
 
306
533
  ```typescript
307
- const resendResp = await client.resendPin({
308
- opportunityId: app.opportunityId,
534
+ const pinResp = await client.sendPinAndGetDocumentsLink({
535
+ opportunityId,
309
536
  flagSendSms: true,
310
537
  flagSendEmail: false
311
538
  });
312
- console.log('PIN resent:', resendResp.flagPinSent);
539
+
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
313
544
  ```
314
545
 
315
- #### `verifyPin(request: ThirdPartyVerifyPinReq): Promise<ThirdPartyVerifyPinResp>`
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)`
316
553
 
317
- Verify the PIN entered by the signer to complete document signing.
554
+ `isScriptReadConfirmed: true` is required - confirms the agent has read the disclosure aloud.
318
555
 
319
556
  ```typescript
320
557
  const verifyResp = await client.verifyPin({
321
- opportunityId: app.opportunityId,
558
+ opportunityId,
322
559
  pin: '123456',
323
560
  isScriptReadConfirmed: true
324
561
  });
325
- console.log('Verified:', verifyResp.isVerified);
562
+
563
+ if (verifyResp.isVerified) {
564
+ // Signing complete - proceed to finalSubmit()
565
+ }
326
566
  ```
327
567
 
328
- ### Final Submit
568
+ **Optional - `resendPin` (if PIN was not received):**
329
569
 
330
- #### `finalSubmit(opportunityId: string): Promise<ThirdPartyFinalSubmitResp>`
570
+ ```typescript
571
+ await client.resendPin({
572
+ opportunityId,
573
+ flagSendSms: true,
574
+ flagSendEmail: false
575
+ });
576
+ ```
577
+
578
+ ---
579
+
580
+ ## Final Submit
331
581
 
332
- 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.
582
+ Shared across all products. Submits the completed application to the carrier for underwriting.
333
583
 
334
584
  ```typescript
335
- const result = await client.finalSubmit(app.opportunityId);
336
- console.log('Policy Number:', result.policyNumber || 'pending carrier decision');
585
+ const submitResp = await client.finalSubmit(opportunityId);
586
+ console.log('Policy number:', submitResp.policyNumber);
337
587
  ```
338
588
 
339
- ### Reports
589
+ > `**policyNumber: null**` is normal - the carrier may not issue a policy number immediately (pending underwriting decision). This is **not** an error.
340
590
 
341
- #### `getProspects(request?: AgentPortalReq): Promise<ThirdPartyProspectsResp>`
591
+ > **Throws `PaymentNotMade`** if `saveEftPayment()` / `saveAdbEftPayment()` was not called before this step.
342
592
 
343
- Get prospects data - quotes that haven't been converted to applications yet.
593
+ ---
594
+
595
+ ## Reporting API
596
+
597
+ Three methods for retrieving data from the agent portal. `pageSize` and `pageIndex` are required.
344
598
 
345
599
  ```typescript
346
- const portalReq : AgentPortalReq = {
347
- "startDate": null,
348
- "endDate": null,
349
- "dayCount": 10,
350
- "pageSize": 10,
351
- "pageIndex": 1
352
- };
353
- const prospects = await client.getProspects(portalReq);
600
+ import { AgentPortalReq } from '@instabrain-sdks/api-client';
354
601
 
355
- console.log(`Found ${prospects.prospectCount} prospects`);
602
+ const request: AgentPortalReq = {
603
+ pageSize: 20, // required
604
+ pageIndex: 0 // required, 0-based
605
+ };
356
606
  ```
357
607
 
358
- #### `getSales(request?: AgentPortalReq): Promise<ThirdPartySalesReportRes>`
359
-
360
- Get sales data - completed/sold policies.
608
+ ### Methods
361
609
 
362
610
  ```typescript
363
- const salesReq : AgentPortalReq = {
364
- "startDate": null,
365
- "endDate": null,
366
- "dayCount": 10,
367
- "pageSize": 10,
368
- "pageIndex": 1
369
- };
370
- const sales = await client.getSales(salesReq);
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 }
371
618
 
372
- console.log(`Total sales: ${sales.applicationCount}`);
373
- console.log(`Total premium: $${sales.totalPremiumAmount}`);
619
+ // Applications in progress
620
+ const applications = await client.getApplications(request);
621
+ // Returns: { applicationCount: number, applications: ThirdPartyApplicationsReport[] }
374
622
  ```
375
623
 
376
- #### `getApplications(request?: AgentPortalReq): Promise<ThirdPartyApplicationReportRes>`
624
+ ### Full `AgentPortalReq` field reference
377
625
 
378
- Get applications data - applications in progress.
379
626
 
380
- ```typescript
381
- const applicationsReq : AgentPortalReq = {
382
- "startDate": null,
383
- "endDate": null,
384
- "dayCount": 10,
385
- "pageSize": 10,
386
- "pageIndex": 1
387
- };
388
- const applications = await client.getApplications(applicationsReq);
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 |
389
638
 
390
- console.log(`Applications needing attention: ${applications.applicationCount}`);
391
- ```
392
639
 
393
- ## Environment Configuration
640
+ ### Sorting (`AgentPortalReqSorting`)
641
+
642
+ ```typescript
643
+ sort: {
644
+ value: 'createdOn',
645
+ sortDescending: true
646
+ }
647
+ ```
394
648
 
395
- The SDK supports production and sandbox environments:
649
+ ### Filtering (`AgentPortalReqFilters[]`)
396
650
 
397
651
  ```typescript
398
- // Production environment (default)
399
- const prodClient = InstaBrainClient.forEnvironment('production');
652
+ import { SQLOperator } from '@instabrain-sdks/api-client';
400
653
 
401
- // Sandbox environment for testing
402
- const sandboxClient = InstaBrainClient.forEnvironment('sandbox');
654
+ filters: [
655
+ {
656
+ field: 'stateCode',
657
+ operator: SQLOperator.Equal,
658
+ value: 'TX'
659
+ }
660
+ ]
403
661
  ```
404
662
 
405
- ## Error Handling
663
+ `**SQLOperator` enum values:**
406
664
 
407
- The SDK provides specific error types for different scenarios:
408
665
 
409
- ```typescript
410
- import {
411
- InstaBrainError,
412
- AuthenticationError,
413
- ValidationError,
414
- APIValidationError,
415
- APIErrorCode
416
- } from '@instabrain-sdks/api-client';
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 |
417
679
 
418
- try {
419
- await client.authenticate(userId, accessToken);
420
- } catch (error) {
421
- if (error instanceof APIValidationError) {
422
- // Business-logic error with a specific error code
423
- console.error('API validation error:', error.errorCode);
424
- console.error('Friendly message:', error.getUserFriendlyMessage());
425
- if (error.isErrorType(APIErrorCode.SecureSignPinMismatch)) {
426
- console.error('PIN did not match — please try again');
427
- }
428
- } else if (error instanceof AuthenticationError) {
429
- console.error('Authentication failed:', error.message);
430
- } else if (error instanceof ValidationError) {
431
- console.error('Validation error:', error.message);
432
- } else if (error instanceof InstaBrainError) {
433
- console.error('API error:', error.message, error.statusCode);
434
- } else {
435
- console.error('Unexpected error:', error);
436
- }
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) |
726
+
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:
931
+
932
+ ```typescript
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
437
938
  }
438
939
  ```
439
940
 
440
- ## Types and Enums
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`
441
944
 
442
- ### Gender
945
+ Returned by `getGigdbQuote()`, `getAdbQuote()`, `getQuote()`, `updateGigdbQuote()`, `getExistingGigdbQuote()`.
443
946
 
444
947
  ```typescript
445
- enum Gender {
446
- Male = 1,
447
- Female = 2
948
+ interface ThirdPartyQuoteResp {
949
+ productName: string | null;
950
+ selectedQuote: Quote;
448
951
  }
449
952
  ```
450
953
 
451
- ### Payment Frequency
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`:
452
1176
 
453
1177
  ```typescript
454
- enum PaymentFrequency {
455
- Annual = 1,
456
- Monthly = 12
1178
+ beneficiaryDetails: {
1179
+ beneficiaryType: BeneficiaryType.InsuredEstate
457
1180
  }
458
1181
  ```
459
1182
 
460
- ### Rate Class
1183
+ ### Variant 2 - Named person
1184
+
1185
+ Used when `beneficiaryType = Person`:
461
1186
 
462
1187
  ```typescript
463
- enum RateClass {
464
- Standard = 'Standard',
465
- Preferred = 'Preferred',
466
- PreferredPlus = 'Preferred Plus',
467
- SuperPreferred = 'Super Preferred'
1188
+ beneficiaryDetails: {
1189
+ beneficiaryType: BeneficiaryType.Person,
1190
+ beneficiaryPerson: {
1191
+ firstName: 'Jane',
1192
+ lastName: 'Doe',
1193
+ relationship: BeneficiaryRelationship.Spouse
1194
+ }
468
1195
  }
469
1196
  ```
470
1197
 
471
- ### Health Class
1198
+ ### Variant 3 - Named entity (organization)
1199
+
1200
+ Used for `Business`, `Corporation`, `CharitableOrganization`, `Employer`, `Other`, `Trust`:
472
1201
 
473
1202
  ```typescript
474
- enum HealthClass {
475
- Standard = 'Standard',
476
- Preferred = 'Preferred',
477
- Excellent = 'Excellent',
478
- PreferredPlus = 'Preferred Plus',
479
- SuperPreferred = 'Super Preferred'
1203
+ // Business / Corporation / etc.
1204
+ beneficiaryDetails: {
1205
+ beneficiaryType: BeneficiaryType.Business,
1206
+ namedEntity: {
1207
+ name: 'Acme Corp',
1208
+ taxId: '12-3456789' // optional
1209
+ }
480
1210
  }
1211
+
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
+ }
1219
+ }
1220
+ ```
1221
+
1222
+ ---
1223
+
1224
+ ## Error Handling
1225
+
1226
+ ### Error class hierarchy
1227
+
481
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
482
1236
 
483
- ## Advanced Usage
484
1237
 
485
- ### Manual Token Management
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.
486
1249
 
487
1250
  ```typescript
488
- // Set a token manually (if you have one from elsewhere)
489
- client.setToken('your-jwt-token');
1251
+ import {
1252
+ APIValidationError,
1253
+ AuthenticationError,
1254
+ InstaBrainError,
1255
+ APIErrorCode
1256
+ } from '@instabrain-sdks/api-client';
490
1257
 
491
- // Check authentication status
492
- if (client.isAuthenticated()) {
493
- // Make API calls
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
+ }
494
1275
  }
1276
+ ```
495
1277
 
496
- // Get current token
497
- const currentToken = client.getCurrentToken();
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.
498
1279
 
499
- // Logout (clear token)
500
- client.logout();
501
- ```
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
502
1329
 
503
- ### Base URL
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.
504
1363
 
505
1364
  ```typescript
506
- // Get current base URL
507
- 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');
508
1370
  ```
509
1371
 
510
- ## Examples
1372
+ > Sandbox credentials are separate from production credentials. Both are provisioned independently during onboarding.
511
1373
 
512
- Check out the [examples](./examples) directory for more detailed usage examples:
1374
+ ---
513
1375
 
514
- - [Basic Usage](./examples/basic-usage.ts) - Complete workflow from authentication to application
515
- - [Error Handling](./examples/error-handling.ts) - Comprehensive error handling patterns
516
- - [Environment Switching](./examples/environment-switching.ts) - Working with different environments
1376
+ ## Token Management
517
1377
 
518
- ## Requirements
519
1378
 
520
- - Node.js 14.0.0 or higher
521
- - 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) |
522
1386
 
523
- ## License
524
- This software is proprietary and confidential. Unauthorized copying, distribution, or modification is strictly prohibited.
525
1387
 
526
- ## Support
1388
+ ---
1389
+
1390
+ ## Examples Directory
1391
+
1392
+ Working examples are in the `./examples/` directory:
527
1393
 
528
- For technical support and questions:
529
1394
 
530
- - **Email**: helpdesk@instabrain.io
531
- - **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
+ ---
532
1404
 
533
1405
  ## Changelog
534
1406
 
535
- 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
+