@instabrain-sdks/api-client 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE.md +31 -0
  2. package/README.md +820 -81
  3. package/dist/client/instabrain-client.d.ts +170 -9
  4. package/dist/client/instabrain-client.js +189 -8
  5. package/dist/services/application.service.d.ts +29 -2
  6. package/dist/services/application.service.js +29 -2
  7. package/dist/services/finalexpense.service.d.ts +23 -5
  8. package/dist/services/finalexpense.service.js +23 -5
  9. package/dist/services/gigdb.service.d.ts +25 -3
  10. package/dist/services/gigdb.service.js +25 -3
  11. package/dist/services/payment.service.d.ts +94 -0
  12. package/dist/services/payment.service.js +161 -0
  13. package/dist/services/pivot.service.d.ts +104 -0
  14. package/dist/services/pivot.service.js +116 -0
  15. package/dist/services/pureterm.service.d.ts +96 -10
  16. package/dist/services/pureterm.service.js +100 -8
  17. package/dist/services/secure-sign.service.d.ts +19 -3
  18. package/dist/services/secure-sign.service.js +19 -3
  19. package/dist/types/enums.d.ts +112 -3
  20. package/dist/types/enums.js +134 -4
  21. package/dist/types/errors.js +31 -2
  22. package/dist/types/gigdb.types.d.ts +32 -0
  23. package/dist/types/ibterm.types.d.ts +5 -2
  24. package/dist/types/index.d.ts +2 -0
  25. package/dist/types/index.js +2 -0
  26. package/dist/types/payment.types.d.ts +52 -0
  27. package/dist/types/payment.types.js +3 -0
  28. package/dist/types/pivot.types.d.ts +122 -0
  29. package/dist/types/pivot.types.js +2 -0
  30. package/dist/types/pureterm.types.d.ts +186 -31
  31. package/dist/utils/error-utils.d.ts +9 -1
  32. package/dist/utils/error-utils.js +18 -3
  33. package/dist/utils/http-client.js +11 -2
  34. package/package.json +9 -4
@@ -7,8 +7,10 @@ import { AdbService } from '../services/adb.service';
7
7
  import { IBTermService } from '../services/ibterm.service';
8
8
  import { PureTermService } from '../services/pureterm.service';
9
9
  import { FinalExpenseService } from '../services/finalexpense.service';
10
+ import { PaymentService } from '../services/payment.service';
11
+ import { PivotService } from '../services/pivot.service';
10
12
  import { SecureSignService } from '../services/secure-sign.service';
11
- import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
13
+ import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, PivotQuotesResp, CustomizePivotQuoteReq, CustomizePivotQuoteResp, ConvertPivotToApplicationReq, ConvertPivotToApplicationResp, ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
12
14
  /**
13
15
  * Main InstaBrain SDK client
14
16
  */
@@ -23,6 +25,8 @@ export declare class InstaBrainClient {
23
25
  readonly ibterm: IBTermService;
24
26
  readonly pureTerm: PureTermService;
25
27
  readonly finalExpense: FinalExpenseService;
28
+ readonly payment: PaymentService;
29
+ readonly pivot: PivotService;
26
30
  readonly secureSign: SecureSignService;
27
31
  constructor(config?: InstaBrainConfig);
28
32
  /**
@@ -84,6 +88,16 @@ export declare class InstaBrainClient {
84
88
  * Save EFT payment details for a GIGDB, ADB, or Final Expense application.
85
89
  * Must be called after startGigdbApplication / startAdbApplication /
86
90
  * startFinalExpenseApplication and before the SecureSign flow.
91
+ *
92
+ * `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
93
+ * apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
94
+ *
95
+ * EFT and credit card are mutually exclusive per opportunity — a successful
96
+ * payment that already exists returns `PaymentAlreadyMade`, and after a
97
+ * successful EFT save `getCcPaymentIframeUrl()` returns
98
+ * `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
99
+ * prerequisite for `finalSubmit()`; no charge runs again at final submit.
100
+ *
87
101
  * @param request - The EFT payment request with opportunityId and bank account details
88
102
  * @returns Promise resolving to true on success
89
103
  */
@@ -185,21 +199,73 @@ export declare class InstaBrainClient {
185
199
  * @returns Promise with the current quote response
186
200
  */
187
201
  getExistingIBTermQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
202
+ /**
203
+ * Get available riders for Pure Term in a given state, filtered by the
204
+ * applicant's age and nicotine-use status.
205
+ *
206
+ * Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
207
+ * in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
208
+ * do not proceed to the Quote API. The empty `riders` array is a valid business
209
+ * state, not an error.
210
+ *
211
+ * @param stateCode - Two-letter US state code (e.g. "TX")
212
+ * @param age - Applicant's age, integer, 18–60 inclusive
213
+ * @param flagNicotineUse - Whether the applicant uses nicotine
214
+ * @returns Promise with riders list and product availability flag
215
+ */
216
+ getPureTermRiderDetails(stateCode: string, age: number, flagNicotineUse: boolean): Promise<PureTermRiderDetailsResp>;
188
217
  /**
189
218
  * Get a Pure Term insurance quote.
190
219
  *
191
- * Provide exactly one rating group: `rateClass`, OR `healthClass`, OR
192
- * both `height` and `weightInLbs`. `benefitPeriod` and `stateCode` are
193
- * required. Supply `age` OR `dateOfBirth` (18–60).
220
+ * `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
221
+ * required. Supply at least one rating group — `rateClass`, `healthClass`, or
222
+ * both `height` and `weightInLbs`; passing more than one is allowed. Supply
223
+ * `age` OR `dateOfBirth` (18–60). `flagTobaccoUse` defaults to `false` when
224
+ * omitted.
225
+ *
226
+ * Pure Term uses the same quote request shape as IB Term but different product
227
+ * rules (rate classes including Rated C/D, term lengths including 15,
228
+ * coverage/benefit tables). FluentValidation uses dedicated top-level codes
229
+ * only for `BenefitPeriodNotAvailable` and `CoverageNotAvailable`; other field
230
+ * failures use `InvalidRequestFormat`. Post-validation eligibility can still
231
+ * return codes such as `NotAvailableForState`, `RiderNotAvailable`, and
232
+ * `outsideBuildChart`.
194
233
  *
195
- * After the quote, call `startApplication()` with the returned
196
- * `quoteResponseId` to receive the pre-fill links for the InstaBrain
197
- * frontend.
234
+ * After the quote, call `startPureTermApplication()` with the returned
235
+ * `quoteResponseId`.
198
236
  *
199
237
  * @param request - The Pure Term quote request parameters
200
238
  * @returns Promise with the quote response containing quoteResponseId
201
239
  */
202
240
  getPureTermQuote(request: ThirdPartyPureTermQuoteReq): Promise<ThirdPartyQuoteResp>;
241
+ /**
242
+ * Get the existing quote for an in-flight Pure Term opportunity.
243
+ *
244
+ * Use to resume or review a previously generated Pure Term quote by its
245
+ * opportunity ID without re-quoting. A not-found result is an error (surfaced
246
+ * via the SDK error model), not a valid business state.
247
+ *
248
+ * @param opportunityId - UUID from a prior Pure Term application/quote flow
249
+ * @returns Promise with the current quote response
250
+ */
251
+ getPureTermExistingQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
252
+ /**
253
+ * Start a Pure Term application from a prior Pure Term quote.
254
+ *
255
+ * Dedicated endpoint — separate from the generic `startApplication()`, which is
256
+ * unchanged and still serves other products.
257
+ *
258
+ * `isDeclined: true` is a valid success response (knockout), not an error.
259
+ * Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
260
+ * only). `childRiderInfo` must be sent only when the Dependent Child Rider was
261
+ * on the quote. After a non-declined start, hand off via the returned links —
262
+ * do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
263
+ * credit-card iframe.
264
+ *
265
+ * @param request - The Pure Term application request payload
266
+ * @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
267
+ */
268
+ startPureTermApplication(request: PureTermStartApplicationReq): Promise<ThirdPartyStartAppResp>;
203
269
  /**
204
270
  * Get a Final Expense insurance quote (simplified-issue whole life, ages 50–85).
205
271
  *
@@ -258,6 +324,88 @@ export declare class InstaBrainClient {
258
324
  * @returns Promise with the final ping response (terminal status, or last `'InProgress'` on timeout)
259
325
  */
260
326
  pollFinalExpenseUnderwritingStatus(opportunityId: string, options?: PollUnderwritingStatusOptions): Promise<ThirdPartyFinalExpensePingRes>;
327
+ /**
328
+ * Get alternative-product quotes for a declined application.
329
+ *
330
+ * Only call this when `startFinalExpenseApplication()` returned
331
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
332
+ * no application was created and there is nothing to pivot from.
333
+ *
334
+ * **Persist `quotes[n].pivotProductCode`** — both {@link customizePivotQuote}
335
+ * and {@link convertPivotToApplication} require it. Calling this repeatedly for
336
+ * the same opportunity is safe.
337
+ *
338
+ * @param opportunityId - The non-zero `opportunityId` from the declined application
339
+ * @returns Promise with `pivotReason` and the available `quotes`
340
+ */
341
+ getPivotQuotes(opportunityId: string): Promise<PivotQuotesResp>;
342
+ /**
343
+ * Re-price an alternative-product quote for a different coverage amount or
344
+ * billing frequency.
345
+ *
346
+ * Optional — only needed when the applicant wants something other than the
347
+ * default quote from {@link getPivotQuotes}. This does not persist the choice:
348
+ * `convertPivotToApplication()` still needs `faceAmount` and `paymentFreq`
349
+ * sent explicitly.
350
+ *
351
+ * @param request - Opportunity, product code, and the desired coverage / frequency
352
+ * @returns Promise with the recalculated quote
353
+ */
354
+ customizePivotQuote(request: CustomizePivotQuoteReq): Promise<CustomizePivotQuoteResp>;
355
+ /**
356
+ * Create the alternative-product application.
357
+ *
358
+ * **The returned `opportunityId` is new** and belongs to the alternative
359
+ * product — use it for everything that follows; the Final Expense id is
360
+ * finished at this point. The response carries no premium by design: call the
361
+ * alternative product's get-existing-quote with the new id, then continue that
362
+ * product's normal lifecycle.
363
+ *
364
+ * Do not retry after a successful conversion — a second attempt on the same
365
+ * opportunity returns `PivotNotAvailable`.
366
+ *
367
+ * @param request - Opportunity, product code, and confirmed coverage / frequency
368
+ * @returns Promise with the new `opportunityId` and its `productCode`
369
+ */
370
+ convertPivotToApplication(request: ConvertPivotToApplicationReq): Promise<ConvertPivotToApplicationResp>;
371
+ /**
372
+ * Get the TrustCommerce hosted iframe URL for credit card capture.
373
+ *
374
+ * Call after Start Application and before the Secure Sign flow. **Persist the
375
+ * returned URL keyed by `opportunityId`** and reuse it while
376
+ * `pollCcPaymentStatus()` reports `'pending'` — requesting a second link
377
+ * before the current attempt fails returns `TcIframeLinkAlreadyGenerated`.
378
+ *
379
+ * Supported for ADB, GIGDB, and Final Expense only. IB Term / Pure Term
380
+ * return `CcPaymentIframeNotSupportedForProduct`.
381
+ *
382
+ * @param opportunityId - The OpportunityId from the Start Application response
383
+ * @returns Promise resolving to the fully-qualified iframe URL
384
+ */
385
+ getCcPaymentIframeUrl(opportunityId: string): Promise<string>;
386
+ /**
387
+ * Check credit card capture status once.
388
+ *
389
+ * Rate-limited to 1 request per 10 seconds per `opportunityId`. Prefer
390
+ * `pollCcPaymentStatus()` for a managed loop that handles the rate limit.
391
+ *
392
+ * @param opportunityId - The OpportunityId from the Start Application response
393
+ * @returns Promise with the current `status` and `shouldContinuePolling`
394
+ */
395
+ getCcPaymentStatus(opportunityId: string): Promise<ThirdPartyCcPaymentStatusRes>;
396
+ /**
397
+ * Poll credit card capture status until it resolves (`'approved'` or
398
+ * `'failed'`) or the time budget expires.
399
+ *
400
+ * Polls every 10s by default and transparently retries HTTP 429. Never
401
+ * requests a new iframe URL — on `'failed'`, call `getCcPaymentIframeUrl()`
402
+ * again for a fresh capture, then poll again.
403
+ *
404
+ * @param opportunityId - The OpportunityId from the Start Application response
405
+ * @param options - Optional polling cadence overrides
406
+ * @returns Promise with the terminal response, or the last `'pending'` one on timeout
407
+ */
408
+ pollCcPaymentStatus(opportunityId: string, options?: PollCcPaymentStatusOptions): Promise<ThirdPartyCcPaymentStatusRes>;
261
409
  /**
262
410
  * Prepare the signing package and check available delivery channels
263
411
  * Always call this first in the signing flow. If isSignCompleted is true, skip to finalSubmit().
@@ -286,9 +434,22 @@ export declare class InstaBrainClient {
286
434
  */
287
435
  verifyPin(request: ThirdPartyVerifyPinReq): Promise<ThirdPartyVerifyPinResp>;
288
436
  /**
289
- * Submit the application to the carrier for a final underwriting decision
437
+ * Submit the application to the carrier for a final underwriting decision.
290
438
  * Call after the signing flow is complete or when isSignCompleted is true.
291
- * Note: A null policyNumber means the carrier has not yet issued a number (pending decision) — not an error.
439
+ *
440
+ * Note: A null policyNumber means the carrier has not yet issued a number
441
+ * (pending decision) — not an error.
442
+ *
443
+ * Calling this again after a successful submit is **idempotent** — it does not
444
+ * re-submit or re-charge, and returns the existing result including the same
445
+ * `policyNumber`. No client-side guard is needed.
446
+ *
447
+ * Three distinct pre-submit gates, in order: `SecureSignNotCompleted` →
448
+ * `paymentNotMade` (no payment started, or card capture still pending) →
449
+ * `LatestPaymentNotSuccessful` (payment attempted and failed). Handle the last
450
+ * two separately: the first means "keep waiting or start a payment", the
451
+ * second means "start a new capture".
452
+ *
292
453
  * @param opportunityId - The OpportunityId from the Start Application response
293
454
  * @returns Promise with the final submit response containing policyNumber
294
455
  */
@@ -11,6 +11,8 @@ 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
13
  const finalexpense_service_1 = require("../services/finalexpense.service");
14
+ const payment_service_1 = require("../services/payment.service");
15
+ const pivot_service_1 = require("../services/pivot.service");
14
16
  const secure_sign_service_1 = require("../services/secure-sign.service");
15
17
  /**
16
18
  * Main InstaBrain SDK client
@@ -27,6 +29,8 @@ class InstaBrainClient {
27
29
  this.ibterm = new ibterm_service_1.IBTermService(this.httpClient);
28
30
  this.pureTerm = new pureterm_service_1.PureTermService(this.httpClient);
29
31
  this.finalExpense = new finalexpense_service_1.FinalExpenseService(this.httpClient);
32
+ this.payment = new payment_service_1.PaymentService(this.httpClient);
33
+ this.pivot = new pivot_service_1.PivotService(this.httpClient);
30
34
  this.secureSign = new secure_sign_service_1.SecureSignService(this.httpClient);
31
35
  }
32
36
  /**
@@ -111,6 +115,16 @@ class InstaBrainClient {
111
115
  * Save EFT payment details for a GIGDB, ADB, or Final Expense application.
112
116
  * Must be called after startGigdbApplication / startAdbApplication /
113
117
  * startFinalExpenseApplication and before the SecureSign flow.
118
+ *
119
+ * `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
120
+ * apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
121
+ *
122
+ * EFT and credit card are mutually exclusive per opportunity — a successful
123
+ * payment that already exists returns `PaymentAlreadyMade`, and after a
124
+ * successful EFT save `getCcPaymentIframeUrl()` returns
125
+ * `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
126
+ * prerequisite for `finalSubmit()`; no charge runs again at final submit.
127
+ *
114
128
  * @param request - The EFT payment request with opportunityId and bank account details
115
129
  * @returns Promise resolving to true on success
116
130
  */
@@ -239,16 +253,42 @@ class InstaBrainClient {
239
253
  return this.ibterm.getExistingQuote(opportunityId);
240
254
  }
241
255
  // ── Pure Term Methods ──────────────────────────────────────────────
256
+ /**
257
+ * Get available riders for Pure Term in a given state, filtered by the
258
+ * applicant's age and nicotine-use status.
259
+ *
260
+ * Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
261
+ * in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
262
+ * do not proceed to the Quote API. The empty `riders` array is a valid business
263
+ * state, not an error.
264
+ *
265
+ * @param stateCode - Two-letter US state code (e.g. "TX")
266
+ * @param age - Applicant's age, integer, 18–60 inclusive
267
+ * @param flagNicotineUse - Whether the applicant uses nicotine
268
+ * @returns Promise with riders list and product availability flag
269
+ */
270
+ async getPureTermRiderDetails(stateCode, age, flagNicotineUse) {
271
+ return this.pureTerm.getRiderDetails(stateCode, age, flagNicotineUse);
272
+ }
242
273
  /**
243
274
  * Get a Pure Term insurance quote.
244
275
  *
245
- * Provide exactly one rating group: `rateClass`, OR `healthClass`, OR
246
- * both `height` and `weightInLbs`. `benefitPeriod` and `stateCode` are
247
- * required. Supply `age` OR `dateOfBirth` (18–60).
276
+ * `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
277
+ * required. Supply at least one rating group — `rateClass`, `healthClass`, or
278
+ * both `height` and `weightInLbs`; passing more than one is allowed. Supply
279
+ * `age` OR `dateOfBirth` (18–60). `flagTobaccoUse` defaults to `false` when
280
+ * omitted.
248
281
  *
249
- * After the quote, call `startApplication()` with the returned
250
- * `quoteResponseId` to receive the pre-fill links for the InstaBrain
251
- * frontend.
282
+ * Pure Term uses the same quote request shape as IB Term but different product
283
+ * rules (rate classes including Rated C/D, term lengths including 15,
284
+ * coverage/benefit tables). FluentValidation uses dedicated top-level codes
285
+ * only for `BenefitPeriodNotAvailable` and `CoverageNotAvailable`; other field
286
+ * failures use `InvalidRequestFormat`. Post-validation eligibility can still
287
+ * return codes such as `NotAvailableForState`, `RiderNotAvailable`, and
288
+ * `outsideBuildChart`.
289
+ *
290
+ * After the quote, call `startPureTermApplication()` with the returned
291
+ * `quoteResponseId`.
252
292
  *
253
293
  * @param request - The Pure Term quote request parameters
254
294
  * @returns Promise with the quote response containing quoteResponseId
@@ -256,6 +296,38 @@ class InstaBrainClient {
256
296
  async getPureTermQuote(request) {
257
297
  return this.pureTerm.getQuote(request);
258
298
  }
299
+ /**
300
+ * Get the existing quote for an in-flight Pure Term opportunity.
301
+ *
302
+ * Use to resume or review a previously generated Pure Term quote by its
303
+ * opportunity ID without re-quoting. A not-found result is an error (surfaced
304
+ * via the SDK error model), not a valid business state.
305
+ *
306
+ * @param opportunityId - UUID from a prior Pure Term application/quote flow
307
+ * @returns Promise with the current quote response
308
+ */
309
+ async getPureTermExistingQuote(opportunityId) {
310
+ return this.pureTerm.getExistingQuote(opportunityId);
311
+ }
312
+ /**
313
+ * Start a Pure Term application from a prior Pure Term quote.
314
+ *
315
+ * Dedicated endpoint — separate from the generic `startApplication()`, which is
316
+ * unchanged and still serves other products.
317
+ *
318
+ * `isDeclined: true` is a valid success response (knockout), not an error.
319
+ * Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
320
+ * only). `childRiderInfo` must be sent only when the Dependent Child Rider was
321
+ * on the quote. After a non-declined start, hand off via the returned links —
322
+ * do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
323
+ * credit-card iframe.
324
+ *
325
+ * @param request - The Pure Term application request payload
326
+ * @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
327
+ */
328
+ async startPureTermApplication(request) {
329
+ return this.pureTerm.startApplication(request);
330
+ }
259
331
  // ── Final Expense Methods ──────────────────────────────────────────────
260
332
  /**
261
333
  * Get a Final Expense insurance quote (simplified-issue whole life, ages 50–85).
@@ -327,6 +399,102 @@ class InstaBrainClient {
327
399
  async pollFinalExpenseUnderwritingStatus(opportunityId, options) {
328
400
  return this.finalExpense.pollUnderwritingStatus(opportunityId, options);
329
401
  }
402
+ // ── Pivot Methods (Final Expense decline → GIGDB alternative) ──────────
403
+ /**
404
+ * Get alternative-product quotes for a declined application.
405
+ *
406
+ * Only call this when `startFinalExpenseApplication()` returned
407
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
408
+ * no application was created and there is nothing to pivot from.
409
+ *
410
+ * **Persist `quotes[n].pivotProductCode`** — both {@link customizePivotQuote}
411
+ * and {@link convertPivotToApplication} require it. Calling this repeatedly for
412
+ * the same opportunity is safe.
413
+ *
414
+ * @param opportunityId - The non-zero `opportunityId` from the declined application
415
+ * @returns Promise with `pivotReason` and the available `quotes`
416
+ */
417
+ async getPivotQuotes(opportunityId) {
418
+ return this.pivot.getPivotQuotes(opportunityId);
419
+ }
420
+ /**
421
+ * Re-price an alternative-product quote for a different coverage amount or
422
+ * billing frequency.
423
+ *
424
+ * Optional — only needed when the applicant wants something other than the
425
+ * default quote from {@link getPivotQuotes}. This does not persist the choice:
426
+ * `convertPivotToApplication()` still needs `faceAmount` and `paymentFreq`
427
+ * sent explicitly.
428
+ *
429
+ * @param request - Opportunity, product code, and the desired coverage / frequency
430
+ * @returns Promise with the recalculated quote
431
+ */
432
+ async customizePivotQuote(request) {
433
+ return this.pivot.customizePivotQuote(request);
434
+ }
435
+ /**
436
+ * Create the alternative-product application.
437
+ *
438
+ * **The returned `opportunityId` is new** and belongs to the alternative
439
+ * product — use it for everything that follows; the Final Expense id is
440
+ * finished at this point. The response carries no premium by design: call the
441
+ * alternative product's get-existing-quote with the new id, then continue that
442
+ * product's normal lifecycle.
443
+ *
444
+ * Do not retry after a successful conversion — a second attempt on the same
445
+ * opportunity returns `PivotNotAvailable`.
446
+ *
447
+ * @param request - Opportunity, product code, and confirmed coverage / frequency
448
+ * @returns Promise with the new `opportunityId` and its `productCode`
449
+ */
450
+ async convertPivotToApplication(request) {
451
+ return this.pivot.convertPivotToApplication(request);
452
+ }
453
+ // ── Credit Card Payment Methods (ADB / GIGDB / Final Expense) ──────────
454
+ /**
455
+ * Get the TrustCommerce hosted iframe URL for credit card capture.
456
+ *
457
+ * Call after Start Application and before the Secure Sign flow. **Persist the
458
+ * returned URL keyed by `opportunityId`** and reuse it while
459
+ * `pollCcPaymentStatus()` reports `'pending'` — requesting a second link
460
+ * before the current attempt fails returns `TcIframeLinkAlreadyGenerated`.
461
+ *
462
+ * Supported for ADB, GIGDB, and Final Expense only. IB Term / Pure Term
463
+ * return `CcPaymentIframeNotSupportedForProduct`.
464
+ *
465
+ * @param opportunityId - The OpportunityId from the Start Application response
466
+ * @returns Promise resolving to the fully-qualified iframe URL
467
+ */
468
+ async getCcPaymentIframeUrl(opportunityId) {
469
+ return this.payment.getIframeUrl(opportunityId);
470
+ }
471
+ /**
472
+ * Check credit card capture status once.
473
+ *
474
+ * Rate-limited to 1 request per 10 seconds per `opportunityId`. Prefer
475
+ * `pollCcPaymentStatus()` for a managed loop that handles the rate limit.
476
+ *
477
+ * @param opportunityId - The OpportunityId from the Start Application response
478
+ * @returns Promise with the current `status` and `shouldContinuePolling`
479
+ */
480
+ async getCcPaymentStatus(opportunityId) {
481
+ return this.payment.getCcPaymentStatus(opportunityId);
482
+ }
483
+ /**
484
+ * Poll credit card capture status until it resolves (`'approved'` or
485
+ * `'failed'`) or the time budget expires.
486
+ *
487
+ * Polls every 10s by default and transparently retries HTTP 429. Never
488
+ * requests a new iframe URL — on `'failed'`, call `getCcPaymentIframeUrl()`
489
+ * again for a fresh capture, then poll again.
490
+ *
491
+ * @param opportunityId - The OpportunityId from the Start Application response
492
+ * @param options - Optional polling cadence overrides
493
+ * @returns Promise with the terminal response, or the last `'pending'` one on timeout
494
+ */
495
+ async pollCcPaymentStatus(opportunityId, options) {
496
+ return this.payment.pollCcPaymentStatus(opportunityId, options);
497
+ }
330
498
  // ── Secure Sign Methods ─────────────────────────────────────────────
331
499
  /**
332
500
  * Prepare the signing package and check available delivery channels
@@ -365,9 +533,22 @@ class InstaBrainClient {
365
533
  }
366
534
  // ── Final Submit ───────────────────────────────────────────────────
367
535
  /**
368
- * Submit the application to the carrier for a final underwriting decision
536
+ * Submit the application to the carrier for a final underwriting decision.
369
537
  * Call after the signing flow is complete or when isSignCompleted is true.
370
- * Note: A null policyNumber means the carrier has not yet issued a number (pending decision) — not an error.
538
+ *
539
+ * Note: A null policyNumber means the carrier has not yet issued a number
540
+ * (pending decision) — not an error.
541
+ *
542
+ * Calling this again after a successful submit is **idempotent** — it does not
543
+ * re-submit or re-charge, and returns the existing result including the same
544
+ * `policyNumber`. No client-side guard is needed.
545
+ *
546
+ * Three distinct pre-submit gates, in order: `SecureSignNotCompleted` →
547
+ * `paymentNotMade` (no payment started, or card capture still pending) →
548
+ * `LatestPaymentNotSuccessful` (payment attempted and failed). Handle the last
549
+ * two separately: the first means "keep waiting or start a payment", the
550
+ * second means "start a new capture".
551
+ *
371
552
  * @param opportunityId - The OpportunityId from the Start Application response
372
553
  * @returns Promise with the final submit response containing policyNumber
373
554
  */
@@ -24,8 +24,35 @@ export declare class ApplicationService extends BaseService {
24
24
  * `pollFinalExpenseUnderwritingStatus(opportunityId)` for the terminal decision.
25
25
  *
26
26
  * Note: a `null` policyNumber does not indicate failure.
27
- * Note: `finalSubmit` can only be called once per `opportunityId` — subsequent
28
- * calls return `"Application has already been final submitted."`.
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.
29
56
  *
30
57
  * @param opportunityId - The OpportunityId from the Start Application response
31
58
  * @returns Promise with the final submit response (`policyNumber`, optional `applicationStatus`)
@@ -29,8 +29,35 @@ class ApplicationService extends base_service_1.BaseService {
29
29
  * `pollFinalExpenseUnderwritingStatus(opportunityId)` for the terminal decision.
30
30
  *
31
31
  * Note: a `null` policyNumber does not indicate failure.
32
- * Note: `finalSubmit` can only be called once per `opportunityId` — subsequent
33
- * calls return `"Application has already been final submitted."`.
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.
34
61
  *
35
62
  * @param opportunityId - The OpportunityId from the Start Application response
36
63
  * @returns Promise with the final submit response (`policyNumber`, optional `applicationStatus`)
@@ -35,11 +35,29 @@ export declare class FinalExpenseService extends BaseService {
35
35
  /**
36
36
  * Start a Final Expense application from a prior Final Expense quote.
37
37
  *
38
- * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller. Note:
39
- * `isDeclined: true` is a valid success response (knockout), not an error —
40
- * any health question set to `true`, or `isPayerAlsoOwnerAndInsured` /
41
- * `isHoldingValidDriverLicense` set to `false`, returns HTTP 200 with
42
- * `isDeclined: true`.
38
+ * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller.
39
+ * `isDeclined: true` is a valid success response (knockout), not an error.
40
+ *
41
+ * **Branch on `isDeclined` AND whether `opportunityId` is all-zero — a
42
+ * decline alone no longer tells you whether an application exists:**
43
+ *
44
+ * | Response | Meaning |
45
+ * |---|---|
46
+ * | `isDeclined: true` + **all-zero** `opportunityId` | No application was created. Stop. No pivot available. |
47
+ * | `isDeclined: true` + **non-zero** `opportunityId` | Application exists but Final Expense declined it. Stop the FE sale path, but **retain the `opportunityId`** — it is the input to the GIGDB pivot flow. |
48
+ * | `isDeclined: false` + non-zero `opportunityId` | Continue the normal Final Expense flow. |
49
+ *
50
+ * Health, questionnaire, and later underwriting declines now return a **real**
51
+ * `opportunityId`. Only these hard stops, which fire before an application is
52
+ * created, still return all-zero:
53
+ * - `isPayerAlsoOwnerAndInsured = false`
54
+ * - `isUsCitizen = false` AND `isLegalUsResident = false`
55
+ * - `isHoldingValidDriverLicense = false`
56
+ * - height/weight outside the Final Expense build chart
57
+ *
58
+ * On any decline, do NOT call Final Expense payment, SecureSign, or
59
+ * `finalSubmit()`. With a non-zero id, call
60
+ * {@link PivotService.getPivotQuotes} instead to offer a GIGDB alternative.
43
61
  *
44
62
  * @param request - The Final Expense start-application request payload.
45
63
  * @returns Promise with `opportunityId`, `isDeclined`, and `isQuoteChanged`.
@@ -53,11 +53,29 @@ class FinalExpenseService extends base_service_1.BaseService {
53
53
  /**
54
54
  * Start a Final Expense application from a prior Final Expense quote.
55
55
  *
56
- * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller. Note:
57
- * `isDeclined: true` is a valid success response (knockout), not an error —
58
- * any health question set to `true`, or `isPayerAlsoOwnerAndInsured` /
59
- * `isHoldingValidDriverLicense` set to `false`, returns HTTP 200 with
60
- * `isDeclined: true`.
56
+ * Uses the dedicated `ThirdPartyFinalExpenseApplication` controller.
57
+ * `isDeclined: true` is a valid success response (knockout), not an error.
58
+ *
59
+ * **Branch on `isDeclined` AND whether `opportunityId` is all-zero — a
60
+ * decline alone no longer tells you whether an application exists:**
61
+ *
62
+ * | Response | Meaning |
63
+ * |---|---|
64
+ * | `isDeclined: true` + **all-zero** `opportunityId` | No application was created. Stop. No pivot available. |
65
+ * | `isDeclined: true` + **non-zero** `opportunityId` | Application exists but Final Expense declined it. Stop the FE sale path, but **retain the `opportunityId`** — it is the input to the GIGDB pivot flow. |
66
+ * | `isDeclined: false` + non-zero `opportunityId` | Continue the normal Final Expense flow. |
67
+ *
68
+ * Health, questionnaire, and later underwriting declines now return a **real**
69
+ * `opportunityId`. Only these hard stops, which fire before an application is
70
+ * created, still return all-zero:
71
+ * - `isPayerAlsoOwnerAndInsured = false`
72
+ * - `isUsCitizen = false` AND `isLegalUsResident = false`
73
+ * - `isHoldingValidDriverLicense = false`
74
+ * - height/weight outside the Final Expense build chart
75
+ *
76
+ * On any decline, do NOT call Final Expense payment, SecureSign, or
77
+ * `finalSubmit()`. With a non-zero id, call
78
+ * {@link PivotService.getPivotQuotes} instead to offer a GIGDB alternative.
61
79
  *
62
80
  * @param request - The Final Expense start-application request payload.
63
81
  * @returns Promise with `opportunityId`, `isDeclined`, and `isQuoteChanged`.