@instabrain-sdks/api-client 2.5.0 → 2.7.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 (38) hide show
  1. package/LICENSE.md +31 -0
  2. package/README.md +684 -66
  3. package/dist/client/instabrain-client.d.ts +96 -14
  4. package/dist/client/instabrain-client.js +102 -13
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +5 -1
  7. package/dist/services/adb.service.d.ts +1 -1
  8. package/dist/services/adb.service.js +1 -1
  9. package/dist/services/application.service.d.ts +9 -2
  10. package/dist/services/application.service.js +9 -2
  11. package/dist/services/finalexpense.service.d.ts +24 -6
  12. package/dist/services/finalexpense.service.js +24 -6
  13. package/dist/services/gigdb.service.d.ts +19 -8
  14. package/dist/services/gigdb.service.js +20 -9
  15. package/dist/services/ibterm.service.d.ts +17 -5
  16. package/dist/services/ibterm.service.js +17 -5
  17. package/dist/services/pivot.service.d.ts +104 -0
  18. package/dist/services/pivot.service.js +116 -0
  19. package/dist/services/pureterm.service.d.ts +12 -4
  20. package/dist/services/pureterm.service.js +12 -4
  21. package/dist/types/application.types.d.ts +27 -5
  22. package/dist/types/constants.d.ts +11 -0
  23. package/dist/types/constants.js +12 -1
  24. package/dist/types/enums.d.ts +55 -5
  25. package/dist/types/enums.js +66 -5
  26. package/dist/types/errors.d.ts +4 -4
  27. package/dist/types/errors.js +8 -2
  28. package/dist/types/gigdb.types.d.ts +34 -7
  29. package/dist/types/ibterm.types.d.ts +9 -0
  30. package/dist/types/index.d.ts +2 -0
  31. package/dist/types/index.js +2 -0
  32. package/dist/types/pivot.types.d.ts +122 -0
  33. package/dist/types/pivot.types.js +2 -0
  34. package/dist/types/webhook.types.d.ts +55 -0
  35. package/dist/types/webhook.types.js +3 -0
  36. package/dist/utils/webhook-signature.d.ts +72 -0
  37. package/dist/utils/webhook-signature.js +172 -0
  38. package/package.json +27 -16
@@ -8,8 +8,9 @@ import { IBTermService } from '../services/ibterm.service';
8
8
  import { PureTermService } from '../services/pureterm.service';
9
9
  import { FinalExpenseService } from '../services/finalexpense.service';
10
10
  import { PaymentService } from '../services/payment.service';
11
+ import { PivotService } from '../services/pivot.service';
11
12
  import { SecureSignService } from '../services/secure-sign.service';
12
- import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
13
+ import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, IBTermRiderDetailsResp, IBTermStartApplicationReq, ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq, ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPartyFinalExpenseUpdateQuoteReq, ThirdPartyFinalExpenseStartApplicationReq, ThirdPartyFinalExpenseStartApplicationRes, ThirdPartyFinalExpensePingRes, PollUnderwritingStatusOptions, PivotQuotesResp, CustomizePivotQuoteReq, CustomizePivotQuoteResp, ConvertPivotToApplicationReq, ConvertPivotToApplicationResp, ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
13
14
  /**
14
15
  * Main InstaBrain SDK client
15
16
  */
@@ -25,6 +26,7 @@ export declare class InstaBrainClient {
25
26
  readonly pureTerm: PureTermService;
26
27
  readonly finalExpense: FinalExpenseService;
27
28
  readonly payment: PaymentService;
29
+ readonly pivot: PivotService;
28
30
  readonly secureSign: SecureSignService;
29
31
  constructor(config?: InstaBrainConfig);
30
32
  /**
@@ -46,9 +48,20 @@ export declare class InstaBrainClient {
46
48
  */
47
49
  getQuote(quoteRequest: ThirdPartyQuoteReq): Promise<ThirdPartyQuoteResp>;
48
50
  /**
49
- * Start an insurance application from a quote
51
+ * Start an application from a quote via the generic
52
+ * `POST /api/ThirdPartyStartApp/start-application` endpoint.
53
+ *
54
+ * Returns `opportunityId` plus `agentLink`, `applicantLink`, and `eAppAgentLink`.
55
+ * Pass `proCode` to start a specific product variant. For IB Term and Pure Term,
56
+ * InstaBrain recommends the dedicated `startIBTermApplication()` /
57
+ * `startPureTermApplication()` instead.
58
+ *
59
+ * Optionally opt in to application-status webhooks with
60
+ * `webhookRegistrationDetails`, and verify each delivery with
61
+ * `verifyWebhookSignature()`.
62
+ *
50
63
  * @param applicationRequest - The application request parameters
51
- * @returns Promise with the application response containing links
64
+ * @returns Promise with `opportunityId` and the application links
52
65
  */
53
66
  startApplication(applicationRequest: ThirdPartyStartApplicationReq): Promise<ThirdPartyStartAppResp>;
54
67
  /**
@@ -83,12 +96,21 @@ export declare class InstaBrainClient {
83
96
  */
84
97
  startGigdbApplication(request: ThirdPartyGigdbAppReq): Promise<ThirdPartyStartAppResp>;
85
98
  /**
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.
99
+ * Save EFT (bank account) payment details for an application. Shared across
100
+ * all products. Call after start-application and, for full-flow products,
101
+ * before the SecureSign flow.
89
102
  *
90
- * `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
91
- * apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
103
+ * `accountHolderName` is required: at most 100 characters and, in practice,
104
+ * about 35 under the name format rules. `routingNumber` is 9 digits;
105
+ * `accountNumber` is 4–17.
106
+ *
107
+ * **Pay Later:** send `payLaterDate` (`yyyy-MM-dd`, date only) to schedule the
108
+ * draft; omit it to draft immediately. The date must be after today in **UTC**
109
+ * and no later than the earlier of the pay later window (30 days by default)
110
+ * and the applicant's next birthday (the birthday itself is allowed); nothing
111
+ * is accepted on the applicant's birthday (UTC date). Failures return
112
+ * `InvalidPaymentScheduledDate`, or `PayLaterNotAvailable` when Pay Later is
113
+ * switched off on the platform; both carry `value.fields.PayLaterDate`.
92
114
  *
93
115
  * EFT and credit card are mutually exclusive per opportunity — a successful
94
116
  * payment that already exists returns `PaymentAlreadyMade`, and after a
@@ -96,8 +118,10 @@ export declare class InstaBrainClient {
96
118
  * `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
97
119
  * prerequisite for `finalSubmit()`; no charge runs again at final submit.
98
120
  *
99
- * @param request - The EFT payment request with opportunityId and bank account details
100
- * @returns Promise resolving to true on success
121
+ * @param request - The EFT payment request with opportunityId, bank account details, and optional payLaterDate
122
+ * @returns Resolves on success; failures throw. The declared type is `boolean`
123
+ * for backward compatibility — at runtime the value is the API's per-field
124
+ * validation result object, which is truthy.
101
125
  */
102
126
  saveEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>;
103
127
  /**
@@ -179,9 +203,16 @@ export declare class InstaBrainClient {
179
203
  /**
180
204
  * Start an IB Term application from a prior IB Term quote.
181
205
  *
182
- * `isDeclined: true` is a valid success response (knockout), not an error.
206
+ * `isDeclined: true` is a valid success response, not an error. Read it together
207
+ * with `opportunityId`: an empty or all-zero id is a knockout — no application
208
+ * exists, so stop. A real id means the application exists but was declined —
209
+ * keep the id and any returned links.
183
210
  * IB Term does NOT use `ApplicationLimitReached` (that applies to ADB/GIGDB only).
184
211
  *
212
+ * Optionally opt in to application-status webhooks with
213
+ * `webhookRegistrationDetails`, and verify each delivery with
214
+ * `verifyWebhookSignature()`.
215
+ *
185
216
  * @param request - The IB Term application request payload
186
217
  * @returns Promise with opportunityId, isDeclined flag, and isQuoteChanged
187
218
  */
@@ -250,16 +281,23 @@ export declare class InstaBrainClient {
250
281
  /**
251
282
  * Start a Pure Term application from a prior Pure Term quote.
252
283
  *
253
- * Dedicated endpoint — separate from the generic `startApplication()`, which is
254
- * unchanged and still serves other products.
284
+ * Dedicated endpoint — separate from the generic `startApplication()`. Do not
285
+ * substitute one for the other.
255
286
  *
256
- * `isDeclined: true` is a valid success response (knockout), not an error.
287
+ * `isDeclined: true` is a valid success response, not an error. Read it together
288
+ * with `opportunityId`: an empty or all-zero id is a knockout — no application
289
+ * exists, so stop. A real id means the application exists but was declined —
290
+ * keep the id and any returned links.
257
291
  * Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
258
292
  * only). `childRiderInfo` must be sent only when the Dependent Child Rider was
259
293
  * on the quote. After a non-declined start, hand off via the returned links —
260
294
  * do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
261
295
  * credit-card iframe.
262
296
  *
297
+ * Optionally opt in to application-status webhooks with
298
+ * `webhookRegistrationDetails`, and verify each delivery with
299
+ * `verifyWebhookSignature()`.
300
+ *
263
301
  * @param request - The Pure Term application request payload
264
302
  * @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
265
303
  */
@@ -322,6 +360,50 @@ export declare class InstaBrainClient {
322
360
  * @returns Promise with the final ping response (terminal status, or last `'InProgress'` on timeout)
323
361
  */
324
362
  pollFinalExpenseUnderwritingStatus(opportunityId: string, options?: PollUnderwritingStatusOptions): Promise<ThirdPartyFinalExpensePingRes>;
363
+ /**
364
+ * Get alternative-product quotes for a declined application.
365
+ *
366
+ * Only call this when `startFinalExpenseApplication()` returned
367
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
368
+ * no application was created and there is nothing to pivot from.
369
+ *
370
+ * **Persist `quotes[n].pivotProductCode`** — both {@link customizePivotQuote}
371
+ * and {@link convertPivotToApplication} require it. Calling this repeatedly for
372
+ * the same opportunity is safe.
373
+ *
374
+ * @param opportunityId - The non-zero `opportunityId` from the declined application
375
+ * @returns Promise with `pivotReason` and the available `quotes`
376
+ */
377
+ getPivotQuotes(opportunityId: string): Promise<PivotQuotesResp>;
378
+ /**
379
+ * Re-price an alternative-product quote for a different coverage amount or
380
+ * billing frequency.
381
+ *
382
+ * Optional — only needed when the applicant wants something other than the
383
+ * default quote from {@link getPivotQuotes}. This does not persist the choice:
384
+ * `convertPivotToApplication()` still needs `faceAmount` and `paymentFreq`
385
+ * sent explicitly.
386
+ *
387
+ * @param request - Opportunity, product code, and the desired coverage / frequency
388
+ * @returns Promise with the recalculated quote
389
+ */
390
+ customizePivotQuote(request: CustomizePivotQuoteReq): Promise<CustomizePivotQuoteResp>;
391
+ /**
392
+ * Create the alternative-product application.
393
+ *
394
+ * **The returned `opportunityId` is new** and belongs to the alternative
395
+ * product — use it for everything that follows; the Final Expense id is
396
+ * finished at this point. The response carries no premium by design: call the
397
+ * alternative product's get-existing-quote with the new id, then continue that
398
+ * product's normal lifecycle.
399
+ *
400
+ * Do not retry after a successful conversion — a second attempt on the same
401
+ * opportunity returns `PivotNotAvailable`.
402
+ *
403
+ * @param request - Opportunity, product code, and confirmed coverage / frequency
404
+ * @returns Promise with the new `opportunityId` and its `productCode`
405
+ */
406
+ convertPivotToApplication(request: ConvertPivotToApplicationReq): Promise<ConvertPivotToApplicationResp>;
325
407
  /**
326
408
  * Get the TrustCommerce hosted iframe URL for credit card capture.
327
409
  *
@@ -12,6 +12,7 @@ const ibterm_service_1 = require("../services/ibterm.service");
12
12
  const pureterm_service_1 = require("../services/pureterm.service");
13
13
  const finalexpense_service_1 = require("../services/finalexpense.service");
14
14
  const payment_service_1 = require("../services/payment.service");
15
+ const pivot_service_1 = require("../services/pivot.service");
15
16
  const secure_sign_service_1 = require("../services/secure-sign.service");
16
17
  /**
17
18
  * Main InstaBrain SDK client
@@ -29,6 +30,7 @@ class InstaBrainClient {
29
30
  this.pureTerm = new pureterm_service_1.PureTermService(this.httpClient);
30
31
  this.finalExpense = new finalexpense_service_1.FinalExpenseService(this.httpClient);
31
32
  this.payment = new payment_service_1.PaymentService(this.httpClient);
33
+ this.pivot = new pivot_service_1.PivotService(this.httpClient);
32
34
  this.secureSign = new secure_sign_service_1.SecureSignService(this.httpClient);
33
35
  }
34
36
  /**
@@ -61,9 +63,20 @@ class InstaBrainClient {
61
63
  return this.quote.getQuote(quoteRequest);
62
64
  }
63
65
  /**
64
- * Start an insurance application from a quote
66
+ * Start an application from a quote via the generic
67
+ * `POST /api/ThirdPartyStartApp/start-application` endpoint.
68
+ *
69
+ * Returns `opportunityId` plus `agentLink`, `applicantLink`, and `eAppAgentLink`.
70
+ * Pass `proCode` to start a specific product variant. For IB Term and Pure Term,
71
+ * InstaBrain recommends the dedicated `startIBTermApplication()` /
72
+ * `startPureTermApplication()` instead.
73
+ *
74
+ * Optionally opt in to application-status webhooks with
75
+ * `webhookRegistrationDetails`, and verify each delivery with
76
+ * `verifyWebhookSignature()`.
77
+ *
65
78
  * @param applicationRequest - The application request parameters
66
- * @returns Promise with the application response containing links
79
+ * @returns Promise with `opportunityId` and the application links
67
80
  */
68
81
  async startApplication(applicationRequest) {
69
82
  return this.application.startApplication(applicationRequest);
@@ -110,12 +123,21 @@ class InstaBrainClient {
110
123
  return this.gigdb.startApplication(request);
111
124
  }
112
125
  /**
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.
126
+ * Save EFT (bank account) payment details for an application. Shared across
127
+ * all products. Call after start-application and, for full-flow products,
128
+ * before the SecureSign flow.
129
+ *
130
+ * `accountHolderName` is required: at most 100 characters and, in practice,
131
+ * about 35 under the name format rules. `routingNumber` is 9 digits;
132
+ * `accountNumber` is 4–17.
116
133
  *
117
- * `accountHolderName` is required, max 100 characters, letters/spaces/hyphens/
118
- * apostrophes only. `routingNumber` is 9 digits; `accountNumber` is 4–17.
134
+ * **Pay Later:** send `payLaterDate` (`yyyy-MM-dd`, date only) to schedule the
135
+ * draft; omit it to draft immediately. The date must be after today in **UTC**
136
+ * and no later than the earlier of the pay later window (30 days by default)
137
+ * and the applicant's next birthday (the birthday itself is allowed); nothing
138
+ * is accepted on the applicant's birthday (UTC date). Failures return
139
+ * `InvalidPaymentScheduledDate`, or `PayLaterNotAvailable` when Pay Later is
140
+ * switched off on the platform; both carry `value.fields.PayLaterDate`.
119
141
  *
120
142
  * EFT and credit card are mutually exclusive per opportunity — a successful
121
143
  * payment that already exists returns `PaymentAlreadyMade`, and after a
@@ -123,8 +145,10 @@ class InstaBrainClient {
123
145
  * `EftPaymentAlreadyCompleted`. A successful save satisfies the payment
124
146
  * prerequisite for `finalSubmit()`; no charge runs again at final submit.
125
147
  *
126
- * @param request - The EFT payment request with opportunityId and bank account details
127
- * @returns Promise resolving to true on success
148
+ * @param request - The EFT payment request with opportunityId, bank account details, and optional payLaterDate
149
+ * @returns Resolves on success; failures throw. The declared type is `boolean`
150
+ * for backward compatibility — at runtime the value is the API's per-field
151
+ * validation result object, which is truthy.
128
152
  */
129
153
  async saveEftPayment(request) {
130
154
  return this.gigdb.saveEftPayment(request);
@@ -228,9 +252,16 @@ class InstaBrainClient {
228
252
  /**
229
253
  * Start an IB Term application from a prior IB Term quote.
230
254
  *
231
- * `isDeclined: true` is a valid success response (knockout), not an error.
255
+ * `isDeclined: true` is a valid success response, not an error. Read it together
256
+ * with `opportunityId`: an empty or all-zero id is a knockout — no application
257
+ * exists, so stop. A real id means the application exists but was declined —
258
+ * keep the id and any returned links.
232
259
  * IB Term does NOT use `ApplicationLimitReached` (that applies to ADB/GIGDB only).
233
260
  *
261
+ * Optionally opt in to application-status webhooks with
262
+ * `webhookRegistrationDetails`, and verify each delivery with
263
+ * `verifyWebhookSignature()`.
264
+ *
234
265
  * @param request - The IB Term application request payload
235
266
  * @returns Promise with opportunityId, isDeclined flag, and isQuoteChanged
236
267
  */
@@ -310,16 +341,23 @@ class InstaBrainClient {
310
341
  /**
311
342
  * Start a Pure Term application from a prior Pure Term quote.
312
343
  *
313
- * Dedicated endpoint — separate from the generic `startApplication()`, which is
314
- * unchanged and still serves other products.
344
+ * Dedicated endpoint — separate from the generic `startApplication()`. Do not
345
+ * substitute one for the other.
315
346
  *
316
- * `isDeclined: true` is a valid success response (knockout), not an error.
347
+ * `isDeclined: true` is a valid success response, not an error. Read it together
348
+ * with `opportunityId`: an empty or all-zero id is a knockout — no application
349
+ * exists, so stop. A real id means the application exists but was declined —
350
+ * keep the id and any returned links.
317
351
  * Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense
318
352
  * only). `childRiderInfo` must be sent only when the Dependent Child Rider was
319
353
  * on the quote. After a non-declined start, hand off via the returned links —
320
354
  * do not wire this `opportunityId` into SecureSign, `finalSubmit()`, or the
321
355
  * credit-card iframe.
322
356
  *
357
+ * Optionally opt in to application-status webhooks with
358
+ * `webhookRegistrationDetails`, and verify each delivery with
359
+ * `verifyWebhookSignature()`.
360
+ *
323
361
  * @param request - The Pure Term application request payload
324
362
  * @returns Promise with opportunityId, links, isDeclined flag, and isQuoteChanged
325
363
  */
@@ -397,6 +435,57 @@ class InstaBrainClient {
397
435
  async pollFinalExpenseUnderwritingStatus(opportunityId, options) {
398
436
  return this.finalExpense.pollUnderwritingStatus(opportunityId, options);
399
437
  }
438
+ // ── Pivot Methods (Final Expense decline → GIGDB alternative) ──────────
439
+ /**
440
+ * Get alternative-product quotes for a declined application.
441
+ *
442
+ * Only call this when `startFinalExpenseApplication()` returned
443
+ * `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
444
+ * no application was created and there is nothing to pivot from.
445
+ *
446
+ * **Persist `quotes[n].pivotProductCode`** — both {@link customizePivotQuote}
447
+ * and {@link convertPivotToApplication} require it. Calling this repeatedly for
448
+ * the same opportunity is safe.
449
+ *
450
+ * @param opportunityId - The non-zero `opportunityId` from the declined application
451
+ * @returns Promise with `pivotReason` and the available `quotes`
452
+ */
453
+ async getPivotQuotes(opportunityId) {
454
+ return this.pivot.getPivotQuotes(opportunityId);
455
+ }
456
+ /**
457
+ * Re-price an alternative-product quote for a different coverage amount or
458
+ * billing frequency.
459
+ *
460
+ * Optional — only needed when the applicant wants something other than the
461
+ * default quote from {@link getPivotQuotes}. This does not persist the choice:
462
+ * `convertPivotToApplication()` still needs `faceAmount` and `paymentFreq`
463
+ * sent explicitly.
464
+ *
465
+ * @param request - Opportunity, product code, and the desired coverage / frequency
466
+ * @returns Promise with the recalculated quote
467
+ */
468
+ async customizePivotQuote(request) {
469
+ return this.pivot.customizePivotQuote(request);
470
+ }
471
+ /**
472
+ * Create the alternative-product application.
473
+ *
474
+ * **The returned `opportunityId` is new** and belongs to the alternative
475
+ * product — use it for everything that follows; the Final Expense id is
476
+ * finished at this point. The response carries no premium by design: call the
477
+ * alternative product's get-existing-quote with the new id, then continue that
478
+ * product's normal lifecycle.
479
+ *
480
+ * Do not retry after a successful conversion — a second attempt on the same
481
+ * opportunity returns `PivotNotAvailable`.
482
+ *
483
+ * @param request - Opportunity, product code, and confirmed coverage / frequency
484
+ * @returns Promise with the new `opportunityId` and its `productCode`
485
+ */
486
+ async convertPivotToApplication(request) {
487
+ return this.pivot.convertPivotToApplication(request);
488
+ }
400
489
  // ── Credit Card Payment Methods (ADB / GIGDB / Final Expense) ──────────
401
490
  /**
402
491
  * Get the TrustCommerce hosted iframe URL for credit card capture.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { InstaBrainClient } from './client/instabrain-client';
2
2
  export * from './types';
3
+ export { verifyWebhookSignature, WEBHOOK_HEADERS } from './utils/webhook-signature';
3
4
  export { InstaBrainClient as default } from './client/instabrain-client';
package/dist/index.js CHANGED
@@ -14,12 +14,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.default = exports.InstaBrainClient = void 0;
17
+ exports.default = exports.WEBHOOK_HEADERS = exports.verifyWebhookSignature = exports.InstaBrainClient = void 0;
18
18
  // Main exports
19
19
  var instabrain_client_1 = require("./client/instabrain-client");
20
20
  Object.defineProperty(exports, "InstaBrainClient", { enumerable: true, get: function () { return instabrain_client_1.InstaBrainClient; } });
21
21
  // Type exports
22
22
  __exportStar(require("./types"), exports);
23
+ // Webhook signature verification (receiving side of application-status webhooks)
24
+ var webhook_signature_1 = require("./utils/webhook-signature");
25
+ Object.defineProperty(exports, "verifyWebhookSignature", { enumerable: true, get: function () { return webhook_signature_1.verifyWebhookSignature; } });
26
+ Object.defineProperty(exports, "WEBHOOK_HEADERS", { enumerable: true, get: function () { return webhook_signature_1.WEBHOOK_HEADERS; } });
23
27
  // Default export
24
28
  var instabrain_client_2 = require("./client/instabrain-client");
25
29
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return instabrain_client_2.InstaBrainClient; } });
@@ -9,7 +9,7 @@ import { ThirdPartyAdbQuoteRequest, ThirdPartyAdbUpdateQuoteReq, ThirdPartyAdbAp
9
9
  * Flow:
10
10
  * 1. getQuote() → quoteResponseId
11
11
  * 2. startApplication() → opportunityId (or isDeclined=true)
12
- * 3. GigdbService.saveEftPayment() → true (shared endpoint — use via InstaBrainClient.saveEftPayment)
12
+ * 3. GigdbService.saveEftPayment() → resolves on success (shared endpoint — use via InstaBrainClient.saveEftPayment)
13
13
  * 4. SecureSign flow → (shared — use SecureSignService)
14
14
  * 5. Final Submit → (shared — use ApplicationService.finalSubmit)
15
15
  */
@@ -10,7 +10,7 @@ const base_service_1 = require("./base.service");
10
10
  * Flow:
11
11
  * 1. getQuote() → quoteResponseId
12
12
  * 2. startApplication() → opportunityId (or isDeclined=true)
13
- * 3. GigdbService.saveEftPayment() → true (shared endpoint — use via InstaBrainClient.saveEftPayment)
13
+ * 3. GigdbService.saveEftPayment() → resolves on success (shared endpoint — use via InstaBrainClient.saveEftPayment)
14
14
  * 4. SecureSign flow → (shared — use SecureSignService)
15
15
  * 5. Final Submit → (shared — use ApplicationService.finalSubmit)
16
16
  */
@@ -7,9 +7,16 @@ import { ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, ThirdPartyFinalS
7
7
  export declare class ApplicationService extends BaseService {
8
8
  constructor(httpClient: HttpClient);
9
9
  /**
10
- * Start an insurance application based on a quote response ID
10
+ * Start an application via the generic
11
+ * `POST /api/ThirdPartyStartApp/start-application` endpoint.
12
+ *
13
+ * Accepts optional `webhookRegistrationDetails` to opt in to application-status
14
+ * webhooks. When sent, both `callbackUrl` (absolute HTTPS) and `secretKey` are
15
+ * required; invalid details fail with HTTP 400 `InvalidRequestFormat` and no
16
+ * application is created.
17
+ *
11
18
  * @param applicationRequest - The application request parameters
12
- * @returns Promise with the application response containing links
19
+ * @returns Promise with `opportunityId` and the application links
13
20
  */
14
21
  startApplication(applicationRequest: ThirdPartyStartApplicationReq): Promise<ThirdPartyStartAppResp>;
15
22
  /**
@@ -10,9 +10,16 @@ class ApplicationService extends base_service_1.BaseService {
10
10
  super(httpClient);
11
11
  }
12
12
  /**
13
- * Start an insurance application based on a quote response ID
13
+ * Start an application via the generic
14
+ * `POST /api/ThirdPartyStartApp/start-application` endpoint.
15
+ *
16
+ * Accepts optional `webhookRegistrationDetails` to opt in to application-status
17
+ * webhooks. When sent, both `callbackUrl` (absolute HTTPS) and `secretKey` are
18
+ * required; invalid details fail with HTTP 400 `InvalidRequestFormat` and no
19
+ * application is created.
20
+ *
14
21
  * @param applicationRequest - The application request parameters
15
- * @returns Promise with the application response containing links
22
+ * @returns Promise with `opportunityId` and the application links
16
23
  */
17
24
  async startApplication(applicationRequest) {
18
25
  return this.post('start application', '/api/ThirdPartyStartApp/start-application', applicationRequest);
@@ -8,7 +8,7 @@ import { ThirdPartyFinalExpenseQuoteReq, ThirdPartyFinalExpenseQuoteRes, ThirdPa
8
8
  * Fidelity Life. Full flow (same as GIGDB / ADB):
9
9
  * 1. getQuote() → quoteResponseId
10
10
  * 2. startApplication() → opportunityId (or isDeclined=true)
11
- * 3. InstaBrainClient.saveEftPayment() → true (shared endpoint)
11
+ * 3. InstaBrainClient.saveEftPayment() → resolves on success (shared endpoint)
12
12
  * 4. SecureSign flow → (shared — use SecureSignService)
13
13
  * 5. InstaBrainClient.finalSubmit() → applicationStatus: 'InProgress' (async!)
14
14
  * 6. pollUnderwritingStatus() → terminal status + policyNumber
@@ -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`.
@@ -22,7 +22,7 @@ const RATE_LIMIT_RETRY_MS = 2000;
22
22
  * Fidelity Life. Full flow (same as GIGDB / ADB):
23
23
  * 1. getQuote() → quoteResponseId
24
24
  * 2. startApplication() → opportunityId (or isDeclined=true)
25
- * 3. InstaBrainClient.saveEftPayment() → true (shared endpoint)
25
+ * 3. InstaBrainClient.saveEftPayment() → resolves on success (shared endpoint)
26
26
  * 4. SecureSign flow → (shared — use SecureSignService)
27
27
  * 5. InstaBrainClient.finalSubmit() → applicationStatus: 'InProgress' (async!)
28
28
  * 6. pollUnderwritingStatus() → terminal status + policyNumber
@@ -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`.
@@ -23,15 +23,24 @@ export declare class GigdbService extends BaseService {
23
23
  /**
24
24
  * Save bank-account (EFT) payment details for an in-progress application.
25
25
  *
26
- * Shared endpoint — used by GIGDB, ADB, and Final Expense. Call after Start
27
- * Application and before `prepareDocsAndGetDeliveryChannels()`.
26
+ * Shared endpoint — used by every product. Call after Start Application and,
27
+ * for full-flow products, before `prepareDocsAndGetDeliveryChannels()`.
28
28
  *
29
- * Validation: `accountHolderName` is required, max 100 characters, and may
30
- * contain only letters, spaces, hyphens, and apostrophes; `routingNumber` is
31
- * exactly 9 digits; `accountNumber` is 4–17 digits. Failures return
32
- * `InvalidRequestFormat` with the field under `value.fields`.
29
+ * Validation: `accountHolderName` is required, at most 100 characters, and
30
+ * must pass the name format rules (in practice about 35 characters: letters,
31
+ * spaces, hyphens, apostrophes, and `*`; no consecutive special characters;
32
+ * must end with a letter); `routingNumber` is exactly 9 digits;
33
+ * `accountNumber` is 4–17 digits. Failures return `InvalidRequestFormat` with
34
+ * the field under `value.fields`.
33
35
  *
34
36
  * Business rules:
37
+ * - **Pay Later:** `payLaterDate` (`yyyy-MM-dd`, date only) schedules the
38
+ * draft; omit it to draft immediately. It must be after today (UTC) and no
39
+ * later than the earlier of the pay later window (30 days by default) and
40
+ * the applicant's next birthday, and is refused on the applicant's
41
+ * birthday (UTC date). Failures return
42
+ * `InvalidPaymentScheduledDate`; `PayLaterNotAvailable` means Pay Later is
43
+ * switched off on the platform. Both carry `value.fields.PayLaterDate`.
35
44
  * - **EFT and credit card are mutually exclusive** per `opportunityId`.
36
45
  * A successful payment that already exists (a prior EFT save, or a card
37
46
  * that has already been charged) returns `PaymentAlreadyMade`. Afterwards,
@@ -44,8 +53,10 @@ export declare class GigdbService extends BaseService {
44
53
  * `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for
45
54
  * payment reasons.
46
55
  *
47
- * @param request - The EFT payment request with opportunityId and bank account details
48
- * @returns Promise resolving to true on success
56
+ * @param request - The EFT payment request with opportunityId, bank account details, and optional payLaterDate
57
+ * @returns Resolves on success; failures throw. The declared type is `boolean`
58
+ * for backward compatibility — at runtime the value is the API's per-field
59
+ * validation result object, which is truthy.
49
60
  */
50
61
  saveEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>;
51
62
  /**
@@ -30,15 +30,24 @@ class GigdbService extends base_service_1.BaseService {
30
30
  /**
31
31
  * Save bank-account (EFT) payment details for an in-progress application.
32
32
  *
33
- * Shared endpoint — used by GIGDB, ADB, and Final Expense. Call after Start
34
- * Application and before `prepareDocsAndGetDeliveryChannels()`.
33
+ * Shared endpoint — used by every product. Call after Start Application and,
34
+ * for full-flow products, before `prepareDocsAndGetDeliveryChannels()`.
35
35
  *
36
- * Validation: `accountHolderName` is required, max 100 characters, and may
37
- * contain only letters, spaces, hyphens, and apostrophes; `routingNumber` is
38
- * exactly 9 digits; `accountNumber` is 4–17 digits. Failures return
39
- * `InvalidRequestFormat` with the field under `value.fields`.
36
+ * Validation: `accountHolderName` is required, at most 100 characters, and
37
+ * must pass the name format rules (in practice about 35 characters: letters,
38
+ * spaces, hyphens, apostrophes, and `*`; no consecutive special characters;
39
+ * must end with a letter); `routingNumber` is exactly 9 digits;
40
+ * `accountNumber` is 4–17 digits. Failures return `InvalidRequestFormat` with
41
+ * the field under `value.fields`.
40
42
  *
41
43
  * Business rules:
44
+ * - **Pay Later:** `payLaterDate` (`yyyy-MM-dd`, date only) schedules the
45
+ * draft; omit it to draft immediately. It must be after today (UTC) and no
46
+ * later than the earlier of the pay later window (30 days by default) and
47
+ * the applicant's next birthday, and is refused on the applicant's
48
+ * birthday (UTC date). Failures return
49
+ * `InvalidPaymentScheduledDate`; `PayLaterNotAvailable` means Pay Later is
50
+ * switched off on the platform. Both carry `value.fields.PayLaterDate`.
42
51
  * - **EFT and credit card are mutually exclusive** per `opportunityId`.
43
52
  * A successful payment that already exists (a prior EFT save, or a card
44
53
  * that has already been charged) returns `PaymentAlreadyMade`. Afterwards,
@@ -51,11 +60,13 @@ class GigdbService extends base_service_1.BaseService {
51
60
  * `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for
52
61
  * payment reasons.
53
62
  *
54
- * @param request - The EFT payment request with opportunityId and bank account details
55
- * @returns Promise resolving to true on success
63
+ * @param request - The EFT payment request with opportunityId, bank account details, and optional payLaterDate
64
+ * @returns Resolves on success; failures throw. The declared type is `boolean`
65
+ * for backward compatibility — at runtime the value is the API's per-field
66
+ * validation result object, which is truthy.
56
67
  */
57
68
  async saveEftPayment(request) {
58
- const result = await this.post('save EFT payment', '/api/ThirdPartyPayment/save-eft-payment', request, undefined, true // allowNullValue — API returns BaseResponse<boolean>
69
+ const result = await this.post('save EFT payment', '/api/ThirdPartyPayment/save-eft-payment', request, undefined, true // allowNullValue — value is the per-field validation object (typed boolean for back-compat); a null value resolves to true
59
70
  );
60
71
  return result !== null && result !== void 0 ? result : true;
61
72
  }