@instabrain-sdks/api-client 2.3.3 → 2.5.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.
@@ -6,8 +6,10 @@ import { GigdbService } from '../services/gigdb.service';
6
6
  import { AdbService } from '../services/adb.service';
7
7
  import { IBTermService } from '../services/ibterm.service';
8
8
  import { PureTermService } from '../services/pureterm.service';
9
+ import { FinalExpenseService } from '../services/finalexpense.service';
10
+ import { PaymentService } from '../services/payment.service';
9
11
  import { SecureSignService } from '../services/secure-sign.service';
10
- import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
12
+ import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
11
13
  /**
12
14
  * Main InstaBrain SDK client
13
15
  */
@@ -21,6 +23,8 @@ export declare class InstaBrainClient {
21
23
  readonly adb: AdbService;
22
24
  readonly ibterm: IBTermService;
23
25
  readonly pureTerm: PureTermService;
26
+ readonly finalExpense: FinalExpenseService;
27
+ readonly payment: PaymentService;
24
28
  readonly secureSign: SecureSignService;
25
29
  constructor(config?: InstaBrainConfig);
26
30
  /**
@@ -79,8 +83,19 @@ export declare class InstaBrainClient {
79
83
  */
80
84
  startGigdbApplication(request: ThirdPartyGigdbAppReq): Promise<ThirdPartyStartAppResp>;
81
85
  /**
82
- * Save EFT payment details for a GIGDB or ADB application
83
- * Must be called after startGigdbApplication / startAdbApplication and before the SecureSign flow.
86
+ * Save EFT payment details for a GIGDB, ADB, or Final Expense application.
87
+ * Must be called after startGigdbApplication / startAdbApplication /
88
+ * startFinalExpenseApplication and before the SecureSign flow.
89
+ *
90
+ * `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
91
+ * apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
92
+ *
93
+ * EFT and credit card are mutually exclusive per opportunity — a successful
94
+ * payment that already exists returns `PaymentAlreadyMade`, and after a
95
+ * successful EFT save `getCcPaymentIframeUrl()` returns
96
+ * `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
97
+ * prerequisite for `finalSubmit()`; no charge runs again at final submit.
98
+ *
84
99
  * @param request - The EFT payment request with opportunityId and bank account details
85
100
  * @returns Promise resolving to true on success
86
101
  */
@@ -182,21 +197,169 @@ export declare class InstaBrainClient {
182
197
  * @returns Promise with the current quote response
183
198
  */
184
199
  getExistingIBTermQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
200
+ /**
201
+ * Get available riders for Pure Term in a given state, filtered by the
202
+ * applicant's age and nicotine-use status.
203
+ *
204
+ * Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
205
+ * in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
206
+ * do not proceed to the Quote API. The empty `riders` array is a valid business
207
+ * state, not an error.
208
+ *
209
+ * @param stateCode - Two-letter US state code (e.g. "TX")
210
+ * @param age - Applicant's age, integer, 18–60 inclusive
211
+ * @param flagNicotineUse - Whether the applicant uses nicotine
212
+ * @returns Promise with riders list and product availability flag
213
+ */
214
+ getPureTermRiderDetails(stateCode: string, age: number, flagNicotineUse: boolean): Promise<PureTermRiderDetailsResp>;
185
215
  /**
186
216
  * Get a Pure Term insurance quote.
187
217
  *
188
- * Provide exactly one rating group: `rateClass`, OR `healthClass`, OR
189
- * both `height` and `weightInLbs`. `benefitPeriod` and `stateCode` are
190
- * required. Supply `age` OR `dateOfBirth` (18–60).
218
+ * `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
219
+ * required. Supply at least one rating group — `rateClass`, `healthClass`, or
220
+ * both `height` and `weightInLbs`; passing more than one is allowed. Supply
221
+ * `age` OR `dateOfBirth` (18–60). `flagTobaccoUse` defaults to `false` when
222
+ * omitted.
191
223
  *
192
- * After the quote, call `startApplication()` with the returned
193
- * `quoteResponseId` to receive the pre-fill links for the InstaBrain
194
- * frontend.
224
+ * Pure Term uses the same quote request shape as IB Term but different product
225
+ * rules (rate classes including Rated C/D, term lengths including 15,
226
+ * coverage/benefit tables). FluentValidation uses dedicated top-level codes
227
+ * only for `BenefitPeriodNotAvailable` and `CoverageNotAvailable`; other field
228
+ * failures use `InvalidRequestFormat`. Post-validation eligibility can still
229
+ * return codes such as `NotAvailableForState`, `RiderNotAvailable`, and
230
+ * `outsideBuildChart`.
231
+ *
232
+ * After the quote, call `startPureTermApplication()` with the returned
233
+ * `quoteResponseId`.
195
234
  *
196
235
  * @param request - The Pure Term quote request parameters
197
236
  * @returns Promise with the quote response containing quoteResponseId
198
237
  */
199
238
  getPureTermQuote(request: ThirdPartyPureTermQuoteReq): Promise<ThirdPartyQuoteResp>;
239
+ /**
240
+ * Get the existing quote for an in-flight Pure Term opportunity.
241
+ *
242
+ * Use to resume or review a previously generated Pure Term quote by its
243
+ * opportunity ID without re-quoting. A not-found result is an error (surfaced
244
+ * via the SDK error model), not a valid business state.
245
+ *
246
+ * @param opportunityId - UUID from a prior Pure Term application/quote flow
247
+ * @returns Promise with the current quote response
248
+ */
249
+ getPureTermExistingQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
250
+ /**
251
+ * Start a Pure Term application from a prior Pure Term quote.
252
+ *
253
+ * Dedicated endpoint — separate from the generic `startApplication()`, which is
254
+ * unchanged and still serves other products.
255
+ *
256
+ * `isDeclined: true` is a valid success response (knockout), not an error.
257
+ * Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
258
+ * only). `childRiderInfo` must be sent only when the Dependent Child Rider was
259
+ * on the quote. After a non-declined start, hand off via the returned links —
260
+ * do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
261
+ * credit-card iframe.
262
+ *
263
+ * @param request - The Pure Term application request payload
264
+ * @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
265
+ */
266
+ startPureTermApplication(request: PureTermStartApplicationReq): Promise<ThirdPartyStartAppResp>;
267
+ /**
268
+ * Get a Final Expense insurance quote (simplified-issue whole life, ages 50–85).
269
+ *
270
+ * `faceAmount`, `gender`, `stateCode`, `paymentFreq`, and `flagTobaccoUse` are
271
+ * required. Supply `age` OR `dateOfBirth` (resolved age 50–85). The response
272
+ * `selectedQuote.quoteResponseId` is the token for `startFinalExpenseApplication()`.
273
+ *
274
+ * @param request - The Final Expense quote request parameters
275
+ * @returns Promise with the quote response containing quoteResponseId
276
+ */
277
+ getFinalExpenseQuote(request: ThirdPartyFinalExpenseQuoteReq): Promise<ThirdPartyFinalExpenseQuoteRes>;
278
+ /**
279
+ * Start a Final Expense application from a prior Final Expense quote.
280
+ *
281
+ * `isDeclined: true` is a valid success response (knockout), not an error.
282
+ * After a non-declined start, continue with `saveEftPayment()`, the Secure
283
+ * Sign flow, then `finalSubmit()` — and poll `pollFinalExpenseUnderwritingStatus()`
284
+ * because Final Expense underwrites asynchronously.
285
+ *
286
+ * @param request - The Final Expense start-application request payload
287
+ * @returns Promise with `opportunityId`, `isDeclined`, and `isQuoteChanged`
288
+ */
289
+ startFinalExpenseApplication(request: ThirdPartyFinalExpenseStartApplicationReq): Promise<ThirdPartyFinalExpenseStartApplicationRes>;
290
+ /**
291
+ * Get the existing Final Expense quote for an in-flight opportunity by ID.
292
+ * Use `selectedQuote.quoteResponseId` as `quoteResponseId` on start application.
293
+ *
294
+ * @param opportunityId - UUID from a prior Final Expense quote/application flow
295
+ * @returns Promise with the current quote response
296
+ */
297
+ getFinalExpenseExistingQuote(opportunityId: string): Promise<ThirdPartyFinalExpenseQuoteRes>;
298
+ /**
299
+ * Update the face amount and/or payment frequency on an existing Final Expense
300
+ * quote. Blocked once EFT payment is recorded for the opportunity.
301
+ *
302
+ * @param request - The update-quote request (`opportunityId`, `faceAmount`, `paymentFreq`)
303
+ * @returns Promise with the recalculated quote response
304
+ */
305
+ updateFinalExpenseQuote(request: ThirdPartyFinalExpenseUpdateQuoteReq): Promise<ThirdPartyFinalExpenseQuoteRes>;
306
+ /**
307
+ * Single poll of the Final Expense asynchronous underwriting status. Call after
308
+ * `finalSubmit()` returns `applicationStatus: 'InProgress'`. Final Expense only —
309
+ * ADB/GIGDB return `400 FinalSubmitStatusNotSupported`.
310
+ *
311
+ * @param opportunityId - The `opportunityId` from the start-application response
312
+ * @returns Promise with the current `applicationStatus` and `policyNumber`
313
+ */
314
+ pingFinalExpenseUnderwritingStatus(opportunityId: string): Promise<ThirdPartyFinalExpensePingRes>;
315
+ /**
316
+ * Poll the Final Expense asynchronous underwriting decision until a terminal
317
+ * status is reached or the time budget is exhausted (two-phase: every 10s for
318
+ * 7 min, then every 5 min up to 30 min total; all configurable).
319
+ *
320
+ * @param opportunityId - The `opportunityId` from the start-application response
321
+ * @param options - Optional polling cadence overrides
322
+ * @returns Promise with the final ping response (terminal status, or last `'InProgress'` on timeout)
323
+ */
324
+ pollFinalExpenseUnderwritingStatus(opportunityId: string, options?: PollUnderwritingStatusOptions): Promise<ThirdPartyFinalExpensePingRes>;
325
+ /**
326
+ * Get the TrustCommerce hosted iframe URL for credit card capture.
327
+ *
328
+ * Call after Start Application and before the Secure Sign flow. **Persist the
329
+ * returned URL keyed by `opportunityId`** and reuse it while
330
+ * `pollCcPaymentStatus()` reports `'pending'` — requesting a second link
331
+ * before the current attempt fails returns `TcIframeLinkAlreadyGenerated`.
332
+ *
333
+ * Supported for ADB, GIGDB, and Final Expense only. IB Term / Pure Term
334
+ * return `CcPaymentIframeNotSupportedForProduct`.
335
+ *
336
+ * @param opportunityId - The OpportunityId from the Start Application response
337
+ * @returns Promise resolving to the fully-qualified iframe URL
338
+ */
339
+ getCcPaymentIframeUrl(opportunityId: string): Promise<string>;
340
+ /**
341
+ * Check credit card capture status once.
342
+ *
343
+ * Rate-limited to 1 request per 10 seconds per `opportunityId`. Prefer
344
+ * `pollCcPaymentStatus()` for a managed loop that handles the rate limit.
345
+ *
346
+ * @param opportunityId - The OpportunityId from the Start Application response
347
+ * @returns Promise with the current `status` and `shouldContinuePolling`
348
+ */
349
+ getCcPaymentStatus(opportunityId: string): Promise<ThirdPartyCcPaymentStatusRes>;
350
+ /**
351
+ * Poll credit card capture status until it resolves (`'approved'` or
352
+ * `'failed'`) or the time budget expires.
353
+ *
354
+ * Polls every 10s by default and transparently retries HTTP 429. Never
355
+ * requests a new iframe URL — on `'failed'`, call `getCcPaymentIframeUrl()`
356
+ * again for a fresh capture, then poll again.
357
+ *
358
+ * @param opportunityId - The OpportunityId from the Start Application response
359
+ * @param options - Optional polling cadence overrides
360
+ * @returns Promise with the terminal response, or the last `'pending'` one on timeout
361
+ */
362
+ pollCcPaymentStatus(opportunityId: string, options?: PollCcPaymentStatusOptions): Promise<ThirdPartyCcPaymentStatusRes>;
200
363
  /**
201
364
  * Prepare the signing package and check available delivery channels
202
365
  * Always call this first in the signing flow. If isSignCompleted is true, skip to finalSubmit().
@@ -225,9 +388,22 @@ export declare class InstaBrainClient {
225
388
  */
226
389
  verifyPin(request: ThirdPartyVerifyPinReq): Promise<ThirdPartyVerifyPinResp>;
227
390
  /**
228
- * Submit the application to the carrier for a final underwriting decision
391
+ * Submit the application to the carrier for a final underwriting decision.
229
392
  * Call after the signing flow is complete or when isSignCompleted is true.
230
- * Note: A null policyNumber means the carrier has not yet issued a number (pending decision) — not an error.
393
+ *
394
+ * Note: A null policyNumber means the carrier has not yet issued a number
395
+ * (pending decision) — not an error.
396
+ *
397
+ * Calling this again after a successful submit is **idempotent** — it does not
398
+ * re-submit or re-charge, and returns the existing result including the same
399
+ * `policyNumber`. No client-side guard is needed.
400
+ *
401
+ * Three distinct pre-submit gates, in order: `SecureSignNotCompleted` →
402
+ * `paymentNotMade` (no payment started, or card capture still pending) →
403
+ * `LatestPaymentNotSuccessful` (payment attempted and failed). Handle the last
404
+ * two separately: the first means "keep waiting or start a payment", the
405
+ * second means "start a new capture".
406
+ *
231
407
  * @param opportunityId - The OpportunityId from the Start Application response
232
408
  * @returns Promise with the final submit response containing policyNumber
233
409
  */
@@ -10,6 +10,8 @@ const gigdb_service_1 = require("../services/gigdb.service");
10
10
  const adb_service_1 = require("../services/adb.service");
11
11
  const ibterm_service_1 = require("../services/ibterm.service");
12
12
  const pureterm_service_1 = require("../services/pureterm.service");
13
+ const finalexpense_service_1 = require("../services/finalexpense.service");
14
+ const payment_service_1 = require("../services/payment.service");
13
15
  const secure_sign_service_1 = require("../services/secure-sign.service");
14
16
  /**
15
17
  * Main InstaBrain SDK client
@@ -25,6 +27,8 @@ class InstaBrainClient {
25
27
  this.adb = new adb_service_1.AdbService(this.httpClient);
26
28
  this.ibterm = new ibterm_service_1.IBTermService(this.httpClient);
27
29
  this.pureTerm = new pureterm_service_1.PureTermService(this.httpClient);
30
+ this.finalExpense = new finalexpense_service_1.FinalExpenseService(this.httpClient);
31
+ this.payment = new payment_service_1.PaymentService(this.httpClient);
28
32
  this.secureSign = new secure_sign_service_1.SecureSignService(this.httpClient);
29
33
  }
30
34
  /**
@@ -106,8 +110,19 @@ class InstaBrainClient {
106
110
  return this.gigdb.startApplication(request);
107
111
  }
108
112
  /**
109
- * Save EFT payment details for a GIGDB or ADB application
110
- * Must be called after startGigdbApplication / startAdbApplication and before the SecureSign flow.
113
+ * Save EFT payment details for a GIGDB, ADB, or Final Expense application.
114
+ * Must be called after startGigdbApplication / startAdbApplication /
115
+ * startFinalExpenseApplication and before the SecureSign flow.
116
+ *
117
+ * `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
118
+ * apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
119
+ *
120
+ * EFT and credit card are mutually exclusive per opportunity — a successful
121
+ * payment that already exists returns `PaymentAlreadyMade`, and after a
122
+ * successful EFT save `getCcPaymentIframeUrl()` returns
123
+ * `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
124
+ * prerequisite for `finalSubmit()`; no charge runs again at final submit.
125
+ *
111
126
  * @param request - The EFT payment request with opportunityId and bank account details
112
127
  * @returns Promise resolving to true on success
113
128
  */
@@ -236,16 +251,42 @@ class InstaBrainClient {
236
251
  return this.ibterm.getExistingQuote(opportunityId);
237
252
  }
238
253
  // ── Pure Term Methods ──────────────────────────────────────────────
254
+ /**
255
+ * Get available riders for Pure Term in a given state, filtered by the
256
+ * applicant's age and nicotine-use status.
257
+ *
258
+ * Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
259
+ * in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
260
+ * do not proceed to the Quote API. The empty `riders` array is a valid business
261
+ * state, not an error.
262
+ *
263
+ * @param stateCode - Two-letter US state code (e.g. "TX")
264
+ * @param age - Applicant's age, integer, 18–60 inclusive
265
+ * @param flagNicotineUse - Whether the applicant uses nicotine
266
+ * @returns Promise with riders list and product availability flag
267
+ */
268
+ async getPureTermRiderDetails(stateCode, age, flagNicotineUse) {
269
+ return this.pureTerm.getRiderDetails(stateCode, age, flagNicotineUse);
270
+ }
239
271
  /**
240
272
  * Get a Pure Term insurance quote.
241
273
  *
242
- * Provide exactly one rating group: `rateClass`, OR `healthClass`, OR
243
- * both `height` and `weightInLbs`. `benefitPeriod` and `stateCode` are
244
- * required. Supply `age` OR `dateOfBirth` (18–60).
274
+ * `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
275
+ * required. Supply at least one rating group — `rateClass`, `healthClass`, or
276
+ * both `height` and `weightInLbs`; passing more than one is allowed. Supply
277
+ * `age` OR `dateOfBirth` (18–60). `flagTobaccoUse` defaults to `false` when
278
+ * omitted.
279
+ *
280
+ * Pure Term uses the same quote request shape as IB Term but different product
281
+ * rules (rate classes including Rated C/D, term lengths including 15,
282
+ * coverage/benefit tables). FluentValidation uses dedicated top-level codes
283
+ * only for `BenefitPeriodNotAvailable` and `CoverageNotAvailable`; other field
284
+ * failures use `InvalidRequestFormat`. Post-validation eligibility can still
285
+ * return codes such as `NotAvailableForState`, `RiderNotAvailable`, and
286
+ * `outsideBuildChart`.
245
287
  *
246
- * After the quote, call `startApplication()` with the returned
247
- * `quoteResponseId` to receive the pre-fill links for the InstaBrain
248
- * frontend.
288
+ * After the quote, call `startPureTermApplication()` with the returned
289
+ * `quoteResponseId`.
249
290
  *
250
291
  * @param request - The Pure Term quote request parameters
251
292
  * @returns Promise with the quote response containing quoteResponseId
@@ -253,6 +294,154 @@ class InstaBrainClient {
253
294
  async getPureTermQuote(request) {
254
295
  return this.pureTerm.getQuote(request);
255
296
  }
297
+ /**
298
+ * Get the existing quote for an in-flight Pure Term opportunity.
299
+ *
300
+ * Use to resume or review a previously generated Pure Term quote by its
301
+ * opportunity ID without re-quoting. A not-found result is an error (surfaced
302
+ * via the SDK error model), not a valid business state.
303
+ *
304
+ * @param opportunityId - UUID from a prior Pure Term application/quote flow
305
+ * @returns Promise with the current quote response
306
+ */
307
+ async getPureTermExistingQuote(opportunityId) {
308
+ return this.pureTerm.getExistingQuote(opportunityId);
309
+ }
310
+ /**
311
+ * Start a Pure Term application from a prior Pure Term quote.
312
+ *
313
+ * Dedicated endpoint — separate from the generic `startApplication()`, which is
314
+ * unchanged and still serves other products.
315
+ *
316
+ * `isDeclined: true` is a valid success response (knockout), not an error.
317
+ * Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
318
+ * only). `childRiderInfo` must be sent only when the Dependent Child Rider was
319
+ * on the quote. After a non-declined start, hand off via the returned links —
320
+ * do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
321
+ * credit-card iframe.
322
+ *
323
+ * @param request - The Pure Term application request payload
324
+ * @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
325
+ */
326
+ async startPureTermApplication(request) {
327
+ return this.pureTerm.startApplication(request);
328
+ }
329
+ // ── Final Expense Methods ──────────────────────────────────────────────
330
+ /**
331
+ * Get a Final Expense insurance quote (simplified-issue whole life, ages 50–85).
332
+ *
333
+ * `faceAmount`, `gender`, `stateCode`, `paymentFreq`, and `flagTobaccoUse` are
334
+ * required. Supply `age` OR `dateOfBirth` (resolved age 50–85). The response
335
+ * `selectedQuote.quoteResponseId` is the token for `startFinalExpenseApplication()`.
336
+ *
337
+ * @param request - The Final Expense quote request parameters
338
+ * @returns Promise with the quote response containing quoteResponseId
339
+ */
340
+ async getFinalExpenseQuote(request) {
341
+ return this.finalExpense.getQuote(request);
342
+ }
343
+ /**
344
+ * Start a Final Expense application from a prior Final Expense quote.
345
+ *
346
+ * `isDeclined: true` is a valid success response (knockout), not an error.
347
+ * After a non-declined start, continue with `saveEftPayment()`, the Secure
348
+ * Sign flow, then `finalSubmit()` — and poll `pollFinalExpenseUnderwritingStatus()`
349
+ * because Final Expense underwrites asynchronously.
350
+ *
351
+ * @param request - The Final Expense start-application request payload
352
+ * @returns Promise with `opportunityId`, `isDeclined`, and `isQuoteChanged`
353
+ */
354
+ async startFinalExpenseApplication(request) {
355
+ return this.finalExpense.startApplication(request);
356
+ }
357
+ /**
358
+ * Get the existing Final Expense quote for an in-flight opportunity by ID.
359
+ * Use `selectedQuote.quoteResponseId` as `quoteResponseId` on start application.
360
+ *
361
+ * @param opportunityId - UUID from a prior Final Expense quote/application flow
362
+ * @returns Promise with the current quote response
363
+ */
364
+ async getFinalExpenseExistingQuote(opportunityId) {
365
+ return this.finalExpense.getExistingQuote(opportunityId);
366
+ }
367
+ /**
368
+ * Update the face amount and/or payment frequency on an existing Final Expense
369
+ * quote. Blocked once EFT payment is recorded for the opportunity.
370
+ *
371
+ * @param request - The update-quote request (`opportunityId`, `faceAmount`, `paymentFreq`)
372
+ * @returns Promise with the recalculated quote response
373
+ */
374
+ async updateFinalExpenseQuote(request) {
375
+ return this.finalExpense.updateQuote(request);
376
+ }
377
+ /**
378
+ * Single poll of the Final Expense asynchronous underwriting status. Call after
379
+ * `finalSubmit()` returns `applicationStatus: 'InProgress'`. Final Expense only —
380
+ * ADB/GIGDB return `400 FinalSubmitStatusNotSupported`.
381
+ *
382
+ * @param opportunityId - The `opportunityId` from the start-application response
383
+ * @returns Promise with the current `applicationStatus` and `policyNumber`
384
+ */
385
+ async pingFinalExpenseUnderwritingStatus(opportunityId) {
386
+ return this.finalExpense.pingUnderwritingStatus(opportunityId);
387
+ }
388
+ /**
389
+ * Poll the Final Expense asynchronous underwriting decision until a terminal
390
+ * status is reached or the time budget is exhausted (two-phase: every 10s for
391
+ * 7 min, then every 5 min up to 30 min total; all configurable).
392
+ *
393
+ * @param opportunityId - The `opportunityId` from the start-application response
394
+ * @param options - Optional polling cadence overrides
395
+ * @returns Promise with the final ping response (terminal status, or last `'InProgress'` on timeout)
396
+ */
397
+ async pollFinalExpenseUnderwritingStatus(opportunityId, options) {
398
+ return this.finalExpense.pollUnderwritingStatus(opportunityId, options);
399
+ }
400
+ // ── Credit Card Payment Methods (ADB / GIGDB / Final Expense) ──────────
401
+ /**
402
+ * Get the TrustCommerce hosted iframe URL for credit card capture.
403
+ *
404
+ * Call after Start Application and before the Secure Sign flow. **Persist the
405
+ * returned URL keyed by `opportunityId`** and reuse it while
406
+ * `pollCcPaymentStatus()` reports `'pending'` — requesting a second link
407
+ * before the current attempt fails returns `TcIframeLinkAlreadyGenerated`.
408
+ *
409
+ * Supported for ADB, GIGDB, and Final Expense only. IB Term / Pure Term
410
+ * return `CcPaymentIframeNotSupportedForProduct`.
411
+ *
412
+ * @param opportunityId - The OpportunityId from the Start Application response
413
+ * @returns Promise resolving to the fully-qualified iframe URL
414
+ */
415
+ async getCcPaymentIframeUrl(opportunityId) {
416
+ return this.payment.getIframeUrl(opportunityId);
417
+ }
418
+ /**
419
+ * Check credit card capture status once.
420
+ *
421
+ * Rate-limited to 1 request per 10 seconds per `opportunityId`. Prefer
422
+ * `pollCcPaymentStatus()` for a managed loop that handles the rate limit.
423
+ *
424
+ * @param opportunityId - The OpportunityId from the Start Application response
425
+ * @returns Promise with the current `status` and `shouldContinuePolling`
426
+ */
427
+ async getCcPaymentStatus(opportunityId) {
428
+ return this.payment.getCcPaymentStatus(opportunityId);
429
+ }
430
+ /**
431
+ * Poll credit card capture status until it resolves (`'approved'` or
432
+ * `'failed'`) or the time budget expires.
433
+ *
434
+ * Polls every 10s by default and transparently retries HTTP 429. Never
435
+ * requests a new iframe URL — on `'failed'`, call `getCcPaymentIframeUrl()`
436
+ * again for a fresh capture, then poll again.
437
+ *
438
+ * @param opportunityId - The OpportunityId from the Start Application response
439
+ * @param options - Optional polling cadence overrides
440
+ * @returns Promise with the terminal response, or the last `'pending'` one on timeout
441
+ */
442
+ async pollCcPaymentStatus(opportunityId, options) {
443
+ return this.payment.pollCcPaymentStatus(opportunityId, options);
444
+ }
256
445
  // ── Secure Sign Methods ─────────────────────────────────────────────
257
446
  /**
258
447
  * Prepare the signing package and check available delivery channels
@@ -291,9 +480,22 @@ class InstaBrainClient {
291
480
  }
292
481
  // ── Final Submit ───────────────────────────────────────────────────
293
482
  /**
294
- * Submit the application to the carrier for a final underwriting decision
483
+ * Submit the application to the carrier for a final underwriting decision.
295
484
  * Call after the signing flow is complete or when isSignCompleted is true.
296
- * Note: A null policyNumber means the carrier has not yet issued a number (pending decision) — not an error.
485
+ *
486
+ * Note: A null policyNumber means the carrier has not yet issued a number
487
+ * (pending decision) — not an error.
488
+ *
489
+ * Calling this again after a successful submit is **idempotent** — it does not
490
+ * re-submit or re-charge, and returns the existing result including the same
491
+ * `policyNumber`. No client-side guard is needed.
492
+ *
493
+ * Three distinct pre-submit gates, in order: `SecureSignNotCompleted` →
494
+ * `paymentNotMade` (no payment started, or card capture still pending) →
495
+ * `LatestPaymentNotSuccessful` (payment attempted and failed). Handle the last
496
+ * two separately: the first means "keep waiting or start a payment", the
497
+ * second means "start a new capture".
498
+ *
297
499
  * @param opportunityId - The OpportunityId from the Start Application response
298
500
  * @returns Promise with the final submit response containing policyNumber
299
501
  */
@@ -13,11 +13,49 @@ export declare class ApplicationService extends BaseService {
13
13
  */
14
14
  startApplication(applicationRequest: ThirdPartyStartApplicationReq): Promise<ThirdPartyStartAppResp>;
15
15
  /**
16
- * Submit the application to the carrier for a final underwriting decision
16
+ * Submit the application to the carrier for a final underwriting decision.
17
17
  * Shared across all products. Call after the signing flow is complete.
18
- * Note: A null policyNumber does not indicate failure — it means the carrier has not yet issued a number (pending decision).
18
+ *
19
+ * Response shape differs by product:
20
+ * - **ADB / GIGDB (synchronous):** `policyNumber` is non-null; `applicationStatus` is absent.
21
+ * - **Final Expense (asynchronous):** `policyNumber` is `null` and
22
+ * `applicationStatus` is `'InProgress'`. Callers must check
23
+ * `applicationStatus === 'InProgress'` and then poll
24
+ * `pollFinalExpenseUnderwritingStatus(opportunityId)` for the terminal decision.
25
+ *
26
+ * Note: a `null` policyNumber does not indicate failure.
27
+ *
28
+ * **Calling `finalSubmit()` again after a successful submit is idempotent.**
29
+ * The API does not re-submit to the carrier or re-charge payment — it returns
30
+ * the existing result, including the same `policyNumber` for ADB / GIGDB (or
31
+ * the issued number for Final Expense once underwriting completes). Do not
32
+ * treat a repeat call as an error or guard against it client-side.
33
+ *
34
+ * **Three pre-submit gates, checked in this order.** They are distinct and
35
+ * separately actionable — do not collapse the last two into one case:
36
+ * 1. `SecureSignNotCompleted` — signing is not finished. Complete the PIN
37
+ * flow (or confirm `isSignCompleted`) first.
38
+ * 2. `paymentNotMade` — nothing to submit yet. Either no payment was ever
39
+ * started, **or** a credit card capture is still pending (`cc-payment-status`
40
+ * is `'pending'`). Finish the capture and poll to `'approved'`, or save
41
+ * EFT, then retry. While pending, reuse the stored iframe URL.
42
+ * 3. `LatestPaymentNotSuccessful` — a payment was attempted and the latest
43
+ * attempt failed. Call `getCcPaymentIframeUrl()` for a new capture, poll
44
+ * to `'approved'`, then retry.
45
+ *
46
+ * **Payment behavior by product:**
47
+ * - **ADB / GIGDB with credit card** — the captured card is charged here,
48
+ * and the application is submitted only if the charge succeeds. A declined
49
+ * charge returns one of the `Payment*` decline codes and the application
50
+ * is NOT submitted; `cc-payment-status` then reports `'failed'`.
51
+ * - **Final Expense with credit card** — capture to `'approved'` is still
52
+ * required, but InstaBrain does not charge here; the carrier collects
53
+ * after underwriting. Final Expense never returns a `Payment*` decline code.
54
+ * - **EFT (all products)** — payment was collected at `saveEftPayment()`,
55
+ * so the prerequisite is already met and no charge runs here.
56
+ *
19
57
  * @param opportunityId - The OpportunityId from the Start Application response
20
- * @returns Promise with the final submit response containing policyNumber
58
+ * @returns Promise with the final submit response (`policyNumber`, optional `applicationStatus`)
21
59
  */
22
60
  finalSubmit(opportunityId: string): Promise<ThirdPartyFinalSubmitResp>;
23
61
  }
@@ -18,11 +18,49 @@ class ApplicationService extends base_service_1.BaseService {
18
18
  return this.post('start application', '/api/ThirdPartyStartApp/start-application', applicationRequest);
19
19
  }
20
20
  /**
21
- * Submit the application to the carrier for a final underwriting decision
21
+ * Submit the application to the carrier for a final underwriting decision.
22
22
  * Shared across all products. Call after the signing flow is complete.
23
- * Note: A null policyNumber does not indicate failure — it means the carrier has not yet issued a number (pending decision).
23
+ *
24
+ * Response shape differs by product:
25
+ * - **ADB / GIGDB (synchronous):** `policyNumber` is non-null; `applicationStatus` is absent.
26
+ * - **Final Expense (asynchronous):** `policyNumber` is `null` and
27
+ * `applicationStatus` is `'InProgress'`. Callers must check
28
+ * `applicationStatus === 'InProgress'` and then poll
29
+ * `pollFinalExpenseUnderwritingStatus(opportunityId)` for the terminal decision.
30
+ *
31
+ * Note: a `null` policyNumber does not indicate failure.
32
+ *
33
+ * **Calling `finalSubmit()` again after a successful submit is idempotent.**
34
+ * The API does not re-submit to the carrier or re-charge payment — it returns
35
+ * the existing result, including the same `policyNumber` for ADB / GIGDB (or
36
+ * the issued number for Final Expense once underwriting completes). Do not
37
+ * treat a repeat call as an error or guard against it client-side.
38
+ *
39
+ * **Three pre-submit gates, checked in this order.** They are distinct and
40
+ * separately actionable — do not collapse the last two into one case:
41
+ * 1. `SecureSignNotCompleted` — signing is not finished. Complete the PIN
42
+ * flow (or confirm `isSignCompleted`) first.
43
+ * 2. `paymentNotMade` — nothing to submit yet. Either no payment was ever
44
+ * started, **or** a credit card capture is still pending (`cc-payment-status`
45
+ * is `'pending'`). Finish the capture and poll to `'approved'`, or save
46
+ * EFT, then retry. While pending, reuse the stored iframe URL.
47
+ * 3. `LatestPaymentNotSuccessful` — a payment was attempted and the latest
48
+ * attempt failed. Call `getCcPaymentIframeUrl()` for a new capture, poll
49
+ * to `'approved'`, then retry.
50
+ *
51
+ * **Payment behavior by product:**
52
+ * - **ADB / GIGDB with credit card** — the captured card is charged here,
53
+ * and the application is submitted only if the charge succeeds. A declined
54
+ * charge returns one of the `Payment*` decline codes and the application
55
+ * is NOT submitted; `cc-payment-status` then reports `'failed'`.
56
+ * - **Final Expense with credit card** — capture to `'approved'` is still
57
+ * required, but InstaBrain does not charge here; the carrier collects
58
+ * after underwriting. Final Expense never returns a `Payment*` decline code.
59
+ * - **EFT (all products)** — payment was collected at `saveEftPayment()`,
60
+ * so the prerequisite is already met and no charge runs here.
61
+ *
24
62
  * @param opportunityId - The OpportunityId from the Start Application response
25
- * @returns Promise with the final submit response containing policyNumber
63
+ * @returns Promise with the final submit response (`policyNumber`, optional `applicationStatus`)
26
64
  */
27
65
  async finalSubmit(opportunityId) {
28
66
  return this.post('submit application', '/api/ThirdPartyApplication/final-submit', null, { params: { opportunityId } });