@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.
- package/LICENSE.md +31 -0
- package/README.md +684 -66
- package/dist/client/instabrain-client.d.ts +96 -14
- package/dist/client/instabrain-client.js +102 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -1
- package/dist/services/adb.service.d.ts +1 -1
- package/dist/services/adb.service.js +1 -1
- package/dist/services/application.service.d.ts +9 -2
- package/dist/services/application.service.js +9 -2
- package/dist/services/finalexpense.service.d.ts +24 -6
- package/dist/services/finalexpense.service.js +24 -6
- package/dist/services/gigdb.service.d.ts +19 -8
- package/dist/services/gigdb.service.js +20 -9
- package/dist/services/ibterm.service.d.ts +17 -5
- package/dist/services/ibterm.service.js +17 -5
- package/dist/services/pivot.service.d.ts +104 -0
- package/dist/services/pivot.service.js +116 -0
- package/dist/services/pureterm.service.d.ts +12 -4
- package/dist/services/pureterm.service.js +12 -4
- package/dist/types/application.types.d.ts +27 -5
- package/dist/types/constants.d.ts +11 -0
- package/dist/types/constants.js +12 -1
- package/dist/types/enums.d.ts +55 -5
- package/dist/types/enums.js +66 -5
- package/dist/types/errors.d.ts +4 -4
- package/dist/types/errors.js +8 -2
- package/dist/types/gigdb.types.d.ts +34 -7
- package/dist/types/ibterm.types.d.ts +9 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/pivot.types.d.ts +122 -0
- package/dist/types/pivot.types.js +2 -0
- package/dist/types/webhook.types.d.ts +55 -0
- package/dist/types/webhook.types.js +3 -0
- package/dist/utils/webhook-signature.d.ts +72 -0
- package/dist/utils/webhook-signature.js +172 -0
- package/package.json +27 -16
package/dist/types/enums.js
CHANGED
|
@@ -487,10 +487,47 @@ var APIErrorCode;
|
|
|
487
487
|
// ─── Universal validation envelope ───────────────────────────────────────
|
|
488
488
|
/** Top-level code for every FluentValidation failure across all products. Inspect `value.fields` for field-level details. */
|
|
489
489
|
APIErrorCode["InvalidRequestFormat"] = "InvalidRequestFormat";
|
|
490
|
+
// ─── Get Quote — request-validation state cascade (all five products) ────
|
|
491
|
+
// Checked in this order against `stateCode`, stopping at the first failure:
|
|
492
|
+
// 1. required / recognized state → InvalidRequestFormat
|
|
493
|
+
// 2. product available there → ProductNotAvailableForState
|
|
494
|
+
// 3. agent licensed there → AgentNotLicensedForState
|
|
495
|
+
// Both carry HTTP 400 with the message under `value.fields.StateCode`.
|
|
496
|
+
// These fire during REQUEST VALIDATION. Do not confuse either with
|
|
497
|
+
// `NotAvailableForState`, which is a post-validation eligibility failure
|
|
498
|
+
// carrying `value: null` — different stage, different code.
|
|
499
|
+
/**
|
|
500
|
+
* Get Quote — the product has no carrier configuration for the requested
|
|
501
|
+
* state, or its configuration is flagged unavailable there. Field message:
|
|
502
|
+
* "This product is not available for the selected state."
|
|
503
|
+
*
|
|
504
|
+
* Previously surfaced as a plain `InvalidRequestFormat` field message; it is
|
|
505
|
+
* now its own top-level code. Not returned by start-application, update
|
|
506
|
+
* quote, or get-existing-quote.
|
|
507
|
+
*/
|
|
508
|
+
APIErrorCode["ProductNotAvailableForState"] = "ProductNotAvailableForState";
|
|
509
|
+
/**
|
|
510
|
+
* Get Quote — the authenticated agent is not licensed in the requested
|
|
511
|
+
* state, or the agent could not be resolved from the token. Field message:
|
|
512
|
+
* "Agent is not licensed for the selected state."
|
|
513
|
+
*
|
|
514
|
+
* Distinct from `ProductNotApprovedForHierarchy`, which is a
|
|
515
|
+
* start-application product-hierarchy check, not state licensing. Because
|
|
516
|
+
* the cascade stops at the first failure, this is only reachable once
|
|
517
|
+
* product availability has passed.
|
|
518
|
+
*/
|
|
519
|
+
APIErrorCode["AgentNotLicensedForState"] = "AgentNotLicensedForState";
|
|
490
520
|
// ─── Quote business errors (ADB / GIGDB / IB Term, value: null) ──────────
|
|
491
521
|
/** State code missing or not recognized for the product. */
|
|
492
522
|
APIErrorCode["StateNotFound"] = "stateNotFound";
|
|
493
|
-
/**
|
|
523
|
+
/**
|
|
524
|
+
* Post-validation eligibility — the product is not offered for the selected
|
|
525
|
+
* state, determined after request validation passed. Carries `value: null`.
|
|
526
|
+
*
|
|
527
|
+
* NOT the same as `ProductNotAvailableForState`, which is a request-validation
|
|
528
|
+
* failure carrying `value.fields.StateCode`. Both can occur for the same
|
|
529
|
+
* state; they are raised at different stages and must stay separate.
|
|
530
|
+
*/
|
|
494
531
|
APIErrorCode["NotAvailableForState"] = "NotAvailableForState";
|
|
495
532
|
/** Quote not eligible for the given combination of state, age, and smoker status. */
|
|
496
533
|
APIErrorCode["QuoteNotEligibleForGivenConditions"] = "QuoteNotEligibleForGivenConditions";
|
|
@@ -507,6 +544,16 @@ var APIErrorCode;
|
|
|
507
544
|
APIErrorCode["BenefitPeriodNotAvailable"] = "BenefitPeriodNotAvailable";
|
|
508
545
|
/** IB Term Quote only — height + weight fall outside the carrier's acceptable build chart. */
|
|
509
546
|
APIErrorCode["OutsideBuildChart"] = "outsideBuildChart";
|
|
547
|
+
// ─── Pivot (Final Expense → GIGDB alternative offer) ─────────────────────
|
|
548
|
+
/**
|
|
549
|
+
* The opportunity cannot be pivoted to an alternative product — not eligible,
|
|
550
|
+
* pricing could not produce a quote, or it has already been converted once.
|
|
551
|
+
* Top-level with `value: null`.
|
|
552
|
+
*
|
|
553
|
+
* A business state, not a malformed request — do not lump it in with
|
|
554
|
+
* `InvalidRequestFormat` handling.
|
|
555
|
+
*/
|
|
556
|
+
APIErrorCode["PivotNotAvailable"] = "PivotNotAvailable";
|
|
510
557
|
// ─── Start Application — duplicate-detection limit ───────────────────────
|
|
511
558
|
/** ADB / GIGDB / Final Expense Start Application only — same SSN, email, or phone already has a policy generated within the last 30 days. IB Term does NOT use this code. */
|
|
512
559
|
APIErrorCode["ApplicationLimitReached"] = "ApplicationLimitReached";
|
|
@@ -538,6 +585,24 @@ var APIErrorCode;
|
|
|
538
585
|
* credit card as mutually exclusive per `opportunityId`.
|
|
539
586
|
*/
|
|
540
587
|
APIErrorCode["PaymentAlreadyMade"] = "PaymentAlreadyMade";
|
|
588
|
+
// ─── Save EFT payment — business errors (all products) ────────────────────
|
|
589
|
+
/**
|
|
590
|
+
* `saveEftPayment()` — `payLaterDate` was sent, but Pay Later is switched off
|
|
591
|
+
* on the platform. The switch is environment-wide, not specific to the
|
|
592
|
+
* opportunity, despite the message wording. Retry without `payLaterDate` to
|
|
593
|
+
* draft immediately. HTTP 400 with the message under `value.fields.PayLaterDate`.
|
|
594
|
+
*/
|
|
595
|
+
APIErrorCode["PayLaterNotAvailable"] = "PayLaterNotAvailable";
|
|
596
|
+
/**
|
|
597
|
+
* `saveEftPayment()` — `payLaterDate` is outside the allowed range: today
|
|
598
|
+
* (UTC) or earlier, beyond the platform's pay later window (30 days by
|
|
599
|
+
* default), after the applicant's next birthday, or sent on the applicant's
|
|
600
|
+
* birthday (UTC date). HTTP 400 with the message under
|
|
601
|
+
* `value.fields.PayLaterDate`.
|
|
602
|
+
*/
|
|
603
|
+
APIErrorCode["InvalidPaymentScheduledDate"] = "InvalidPaymentScheduledDate";
|
|
604
|
+
/** `saveEftPayment()` — the EFT details could not be saved. */
|
|
605
|
+
APIErrorCode["ErrorInSaveEftPaymentDetails"] = "ErrorInSaveEftPaymentDetails";
|
|
541
606
|
// ─── Credit card payment — iframe gates (ADB / GIGDB / Final Expense) ─────
|
|
542
607
|
/** `getCcPaymentIframeUrl()` — a link already exists and the latest attempt has not failed (capture is `pending` or already `approved`). Reuse the URL you already have; a new one is only issued after a `failed` attempt. */
|
|
543
608
|
APIErrorCode["TcIframeLinkAlreadyGenerated"] = "TcIframeLinkAlreadyGenerated";
|
|
@@ -647,10 +712,6 @@ var APIErrorCode;
|
|
|
647
712
|
APIErrorCode["InvalidResidenceState"] = "InvalidResidenceState";
|
|
648
713
|
/** @deprecated No longer returned as a top-level code. */
|
|
649
714
|
APIErrorCode["OneOfTheExistingCoveragesQuestionsNotFound"] = "OneOfTheExistingCoveragesQuestionsNotFound";
|
|
650
|
-
/** @deprecated Prefer `InvalidRequestFormat` on EFT fields. */
|
|
651
|
-
APIErrorCode["ErrorInSaveEftPaymentDetails"] = "ErrorInSaveEftPaymentDetails";
|
|
652
|
-
/** @deprecated Prefer `InvalidRequestFormat` on EFT fields. */
|
|
653
|
-
APIErrorCode["InvalidPaymentScheduledDate"] = "InvalidPaymentScheduledDate";
|
|
654
715
|
/** @deprecated Legacy get-existing-quote code; prefer `InvalidRequestFormat`. */
|
|
655
716
|
APIErrorCode["ThirdPartyQuoteError"] = "ThirdPartyQuoteError";
|
|
656
717
|
/** @deprecated No longer returned as a top-level code. */
|
package/dist/types/errors.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class InstaBrainError extends Error {
|
|
2
2
|
statusCode?: number | undefined;
|
|
3
|
-
response?: any;
|
|
3
|
+
response?: any | undefined;
|
|
4
4
|
errorCode?: string | undefined;
|
|
5
|
-
constructor(message: string, statusCode?: number | undefined, response?: any, errorCode?: string | undefined);
|
|
5
|
+
constructor(message: string, statusCode?: number | undefined, response?: any | undefined, errorCode?: string | undefined);
|
|
6
6
|
}
|
|
7
7
|
export declare class AuthenticationError extends InstaBrainError {
|
|
8
8
|
constructor(message?: string);
|
|
@@ -16,8 +16,8 @@ export declare class ValidationError extends InstaBrainError {
|
|
|
16
16
|
*/
|
|
17
17
|
export declare class APIValidationError extends InstaBrainError {
|
|
18
18
|
errorCode: string;
|
|
19
|
-
response?: any;
|
|
20
|
-
constructor(message: string, errorCode: string, response?: any);
|
|
19
|
+
response?: any | undefined;
|
|
20
|
+
constructor(message: string, errorCode: string, response?: any | undefined);
|
|
21
21
|
/**
|
|
22
22
|
* Check if this is a specific type of API error
|
|
23
23
|
*/
|
package/dist/types/errors.js
CHANGED
|
@@ -54,6 +54,10 @@ class APIValidationError extends InstaBrainError {
|
|
|
54
54
|
// Quote business errors (ADB / GIGDB / IB Term)
|
|
55
55
|
'stateNotFound': 'The state code provided is not recognized by the system.',
|
|
56
56
|
'NotAvailableForState': 'Product is not available in the specified state.',
|
|
57
|
+
// Get Quote request-validation state cascade — distinct from the
|
|
58
|
+
// post-validation NotAvailableForState above.
|
|
59
|
+
'ProductNotAvailableForState': 'This product is not available in the selected state. Try a different state, or a product offered there.',
|
|
60
|
+
'AgentNotLicensedForState': 'The agent is not licensed in the selected state. Quotes can only be run in states the agent is licensed for.',
|
|
57
61
|
'QuoteNotEligibleForGivenConditions': 'Product is not available for the given combination of state, age, or tobacco usage.',
|
|
58
62
|
'CoverageNotAvailable': 'The requested coverage amount is not available for the given conditions.',
|
|
59
63
|
'RiderNotAvailable': 'The requested rider is not available in this state or for this age.',
|
|
@@ -68,6 +72,7 @@ class APIValidationError extends InstaBrainError {
|
|
|
68
72
|
'agentNotFound': 'The quote cannot be linked to an agent account. Please verify the agent token and try again.',
|
|
69
73
|
'internalServerError': 'An unexpected error occurred while processing the application. Please retry; if the issue persists, contact InstaBrain support.',
|
|
70
74
|
'InvalidRequestFormat': 'The request format is invalid. Inspect value.fields for per-field details.',
|
|
75
|
+
'PivotNotAvailable': 'This application cannot be switched to an alternative product. It may not be eligible, or it may already have been converted.',
|
|
71
76
|
'QuoteNotFound': 'No previous quote found for this opportunity. Please create a quote first.',
|
|
72
77
|
'ApplicationLimitReached': 'An application with the same SSN, email, or phone already has a policy generated within the last 30 days.',
|
|
73
78
|
'SecureSignRelatedError': 'A signing-related error occurred. Please try again.',
|
|
@@ -111,8 +116,9 @@ class APIValidationError extends InstaBrainError {
|
|
|
111
116
|
'InvalidResidenceState': 'The residence state provided is not valid.',
|
|
112
117
|
'OneOfTheExistingCoveragesQuestionsNotFound': 'One or more existing coverage questions were not answered.',
|
|
113
118
|
'PaymentAlreadyMade': 'A successful payment already exists for this application. EFT and credit card are mutually exclusive per opportunity.',
|
|
114
|
-
'ErrorInSaveEftPaymentDetails': '
|
|
115
|
-
'InvalidPaymentScheduledDate': 'The
|
|
119
|
+
'ErrorInSaveEftPaymentDetails': 'The EFT payment details could not be saved. Please retry; if the issue persists, contact InstaBrain support.',
|
|
120
|
+
'InvalidPaymentScheduledDate': 'The pay later date must be after today (UTC) and within the pay later window for this application.',
|
|
121
|
+
'PayLaterNotAvailable': 'Pay later is not available right now. Save the EFT payment without a pay later date to draft it immediately.',
|
|
116
122
|
'ThirdPartyQuoteError': 'An error occurred while retrieving the quote.',
|
|
117
123
|
'InvalidQuoteParameters': 'The quote parameters provided are not valid.',
|
|
118
124
|
'InvalidStateCode': 'State not supported for ADB (MA, NH, AK unavailable; CA coming next release).',
|
|
@@ -128,12 +128,13 @@ export interface ThirdPartyGigdbAppReq {
|
|
|
128
128
|
/**
|
|
129
129
|
* Request body for `POST /api/ThirdPartyPayment/save-eft-payment`.
|
|
130
130
|
*
|
|
131
|
-
* Shared across all
|
|
132
|
-
*
|
|
133
|
-
*
|
|
131
|
+
* Shared across all products. Call after Start Application and, for full-flow
|
|
132
|
+
* products, before Prepare Signing Docs. Once EFT is saved, quote updates for
|
|
133
|
+
* the same `opportunityId` are blocked.
|
|
134
134
|
*
|
|
135
|
-
* Every field is required server-side. Format failures
|
|
136
|
-
* `InvalidRequestFormat` with the offending PascalCase key under
|
|
135
|
+
* Every field except `payLaterDate` is required server-side. Format failures
|
|
136
|
+
* return `InvalidRequestFormat` with the offending PascalCase key under
|
|
137
|
+
* `value.fields`.
|
|
137
138
|
*/
|
|
138
139
|
export interface ThirdPartyEftPaymentReq {
|
|
139
140
|
/**
|
|
@@ -150,16 +151,42 @@ export interface ThirdPartyEftPaymentReq {
|
|
|
150
151
|
*/
|
|
151
152
|
opportunityId: string;
|
|
152
153
|
/**
|
|
153
|
-
* Name on the bank account.
|
|
154
|
-
*
|
|
154
|
+
* Name on the bank account. Must be at most 100 characters **and** pass the
|
|
155
|
+
* name format rules, which in practice cap it at about **35** characters:
|
|
156
|
+
* letters, spaces, hyphens, apostrophes, and `*`; no consecutive special
|
|
157
|
+
* characters; must end with a letter.
|
|
155
158
|
*
|
|
156
159
|
* Errors: `Account holder name is required.` /
|
|
157
160
|
* `Account holder name must be 100 characters or fewer.` /
|
|
158
161
|
* `Account holder name may only contain letters, spaces, hyphens, and apostrophes.`
|
|
162
|
+
* (the last one is also returned when the name fails the format rules,
|
|
163
|
+
* including a length over about 35).
|
|
159
164
|
*/
|
|
160
165
|
accountHolderName: string | null;
|
|
161
166
|
/** 9-digit US bank routing number. Error: `Routing number must be 9 digits.` */
|
|
162
167
|
routingNumber: string | null;
|
|
163
168
|
/** Bank account number, 4–17 digits. Error: `Account number must be 4 to 17 digits.` */
|
|
164
169
|
accountNumber: string | null;
|
|
170
|
+
/**
|
|
171
|
+
* Optional — schedule the bank draft for a future date (Pay Later). Omit it to
|
|
172
|
+
* draft immediately. There is no separate flag: sending the date is the opt-in.
|
|
173
|
+
*
|
|
174
|
+
* Format: `yyyy-MM-dd`, date only. If a time is included only the date part is
|
|
175
|
+
* used, and a UTC offset can shift the value to a different day first — so
|
|
176
|
+
* never send one.
|
|
177
|
+
*
|
|
178
|
+
* Allowed range, evaluated against the current **UTC** date:
|
|
179
|
+
* - Earliest: tomorrow (UTC). Today (UTC) or earlier is rejected.
|
|
180
|
+
* - Latest: whichever comes first of the platform's pay later window
|
|
181
|
+
* (30 days after today, UTC, by default) and the applicant's next
|
|
182
|
+
* birthday. The birthday itself is allowed.
|
|
183
|
+
* - On the applicant's birthday (UTC date) no `payLaterDate` is accepted.
|
|
184
|
+
* Omit it to draft immediately, or retry the next day (UTC).
|
|
185
|
+
* - A `Time-Zone` request header cannot widen the range.
|
|
186
|
+
*
|
|
187
|
+
* Errors (HTTP 400, message under `value.fields.PayLaterDate`):
|
|
188
|
+
* `PayLaterNotAvailable` when Pay Later is switched off on the platform, or
|
|
189
|
+
* `InvalidPaymentScheduledDate` when the date is outside the range.
|
|
190
|
+
*/
|
|
191
|
+
payLaterDate?: string;
|
|
165
192
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Gender, TobaccoNicotineLastUsedPeriod, TobaccoNicotineProductType } from './enums';
|
|
2
2
|
import { BeneficiaryDetails } from './beneficiary.types';
|
|
3
|
+
import { WebhookRegistrationDetails } from './webhook.types';
|
|
3
4
|
/** A single IB Term rider option returned for a state/age/nicotine combination. */
|
|
4
5
|
export interface IBTermRider {
|
|
5
6
|
/**
|
|
@@ -366,4 +367,12 @@ export interface IBTermStartApplicationReq {
|
|
|
366
367
|
* the application.
|
|
367
368
|
*/
|
|
368
369
|
childRiderInfo?: IBTermChildRiderInfo;
|
|
370
|
+
/**
|
|
371
|
+
* Optional. Opt in to application-status webhooks for the opportunity this
|
|
372
|
+
* call creates. Omit or pass `null` for no callbacks. When sent, both
|
|
373
|
+
* `callbackUrl` (absolute HTTPS) and `secretKey` (16–256 characters) are
|
|
374
|
+
* required. Also applies to Pure Term, whose request type is an alias of this
|
|
375
|
+
* one. See {@link WebhookRegistrationDetails}.
|
|
376
|
+
*/
|
|
377
|
+
webhookRegistrationDetails?: WebhookRegistrationDetails | null;
|
|
369
378
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ export * from './ibterm.types';
|
|
|
12
12
|
export * from './pureterm.types';
|
|
13
13
|
export * from './finalexpense.types';
|
|
14
14
|
export * from './payment.types';
|
|
15
|
+
export * from './pivot.types';
|
|
15
16
|
export * from './secure-sign.types';
|
|
17
|
+
export * from './webhook.types';
|
|
16
18
|
/**
|
|
17
19
|
* Base configuration for the InstaBrain SDK
|
|
18
20
|
*/
|
package/dist/types/index.js
CHANGED
|
@@ -29,4 +29,6 @@ __exportStar(require("./ibterm.types"), exports);
|
|
|
29
29
|
__exportStar(require("./pureterm.types"), exports);
|
|
30
30
|
__exportStar(require("./finalexpense.types"), exports);
|
|
31
31
|
__exportStar(require("./payment.types"), exports);
|
|
32
|
+
__exportStar(require("./pivot.types"), exports);
|
|
32
33
|
__exportStar(require("./secure-sign.types"), exports);
|
|
34
|
+
__exportStar(require("./webhook.types"), exports);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { PaymentFrequency } from './enums';
|
|
2
|
+
/**
|
|
3
|
+
* GIGDB pivot — offering an alternative product after a Final Expense decline.
|
|
4
|
+
*
|
|
5
|
+
* The flow starts from a Final Expense `startApplication()` that returned
|
|
6
|
+
* `isDeclined: true` with a **non-zero** `opportunityId`. That id is the key for
|
|
7
|
+
* every call below.
|
|
8
|
+
*
|
|
9
|
+
* 1. `getPivotQuotes(opportunityId)` → alternative quote options
|
|
10
|
+
* 2. `customizePivotQuote(request)` → optional re-price on a new
|
|
11
|
+
* face amount / payment frequency
|
|
12
|
+
* 3. `convertPivotToApplication(request)` → creates the alternative-product
|
|
13
|
+
* application, returns a NEW id
|
|
14
|
+
*
|
|
15
|
+
* After conversion, continue with the alternative product's own lifecycle using
|
|
16
|
+
* the **new** `opportunityId` — starting with its get-existing-quote, since the
|
|
17
|
+
* convert response deliberately carries no premium.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* A single alternative-product quote option.
|
|
21
|
+
*
|
|
22
|
+
* Returned both as an element of {@link PivotQuotesResp.quotes} and as the whole
|
|
23
|
+
* body of {@link CustomizePivotQuoteResp} — the shapes are identical.
|
|
24
|
+
*/
|
|
25
|
+
export interface PivotQuote {
|
|
26
|
+
/**
|
|
27
|
+
* Product identifier for the alternative product, e.g. `"InstaGIGDB"`.
|
|
28
|
+
*
|
|
29
|
+
* **Persist this.** It is required on both `customizePivotQuote()` and
|
|
30
|
+
* `convertPivotToApplication()`. Always use the value the API returned — do
|
|
31
|
+
* not construct or assume a code.
|
|
32
|
+
*/
|
|
33
|
+
pivotProductCode: string;
|
|
34
|
+
/** Display title, e.g. `"InstaBrain Guaranteed Issue"`. */
|
|
35
|
+
productTitle: string;
|
|
36
|
+
/** Total premium at the requested payment frequency. */
|
|
37
|
+
quoteAmount: number;
|
|
38
|
+
/** Coverage amount in dollars. */
|
|
39
|
+
coverageAmount: number;
|
|
40
|
+
/** Payment frequency (Monthly or Annually). */
|
|
41
|
+
paymentFrequency: PaymentFrequency;
|
|
42
|
+
/** Term length in years, or `null` for whole-life products such as GIGDB. */
|
|
43
|
+
termLength: number | null;
|
|
44
|
+
/** Riders included in the quote. Empty array when none apply. */
|
|
45
|
+
riders: Array<{
|
|
46
|
+
riderValue: string;
|
|
47
|
+
riderLabel: string | null;
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Response from `GET /api/ThirdPartyPivot/get-pivot-quotes`.
|
|
52
|
+
*
|
|
53
|
+
* Calling this repeatedly for the same opportunity is safe.
|
|
54
|
+
*/
|
|
55
|
+
export interface PivotQuotesResp {
|
|
56
|
+
/**
|
|
57
|
+
* Why the pivot was offered, e.g. `"ApplicationDeclineOrNotEligible"`.
|
|
58
|
+
* Display or log only — do not branch business logic on it.
|
|
59
|
+
*/
|
|
60
|
+
pivotReason: string;
|
|
61
|
+
/** Available alternative-product quotes. */
|
|
62
|
+
quotes: PivotQuote[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Request body for `POST /api/ThirdPartyPivot/customize-pivot-quote`.
|
|
66
|
+
*
|
|
67
|
+
* Optional step — only call it when the applicant wants a different coverage
|
|
68
|
+
* amount or billing frequency than the default pivot quote offered.
|
|
69
|
+
*/
|
|
70
|
+
export interface CustomizePivotQuoteReq {
|
|
71
|
+
/** The declined Final Expense `opportunityId`. Must be non-zero. */
|
|
72
|
+
opportunityId: string;
|
|
73
|
+
/** **Required.** Use the value returned by `getPivotQuotes()`. */
|
|
74
|
+
pivotProductCode: string;
|
|
75
|
+
/**
|
|
76
|
+
* Desired coverage in dollars. Outside the alternative product's allowed
|
|
77
|
+
* range, or off its required increment, returns `CoverageNotAvailable`.
|
|
78
|
+
* GIGDB is $5,000–$25,000 in $1,000 increments.
|
|
79
|
+
*/
|
|
80
|
+
faceAmount: number;
|
|
81
|
+
/** `Monthly` or `Annually` only. */
|
|
82
|
+
paymentFreq: PaymentFrequency;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Response from `POST /api/ThirdPartyPivot/customize-pivot-quote` — the same
|
|
86
|
+
* shape as one {@link PivotQuote} from the pivot-quotes list.
|
|
87
|
+
*/
|
|
88
|
+
export type CustomizePivotQuoteResp = PivotQuote;
|
|
89
|
+
/**
|
|
90
|
+
* Request body for `POST /api/ThirdPartyPivot/convert-pivot-to-application`.
|
|
91
|
+
*
|
|
92
|
+
* `faceAmount` and `paymentFreq` are required on **every** call — they are not
|
|
93
|
+
* carried over from a prior `customizePivotQuote()`, so send the values the
|
|
94
|
+
* applicant actually confirmed.
|
|
95
|
+
*/
|
|
96
|
+
export interface ConvertPivotToApplicationReq {
|
|
97
|
+
/** The declined Final Expense `opportunityId`. Must be non-zero. */
|
|
98
|
+
opportunityId: string;
|
|
99
|
+
/** **Required.** Use the value returned by `getPivotQuotes()`. */
|
|
100
|
+
pivotProductCode: string;
|
|
101
|
+
/** Confirmed coverage in dollars. Required every call. */
|
|
102
|
+
faceAmount: number;
|
|
103
|
+
/** Confirmed billing frequency. Required every call. */
|
|
104
|
+
paymentFreq: PaymentFrequency;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Response from `POST /api/ThirdPartyPivot/convert-pivot-to-application`.
|
|
108
|
+
*
|
|
109
|
+
* Deliberately carries no premium — fetch it from the alternative product's own
|
|
110
|
+
* get-existing-quote endpoint using the new `opportunityId`.
|
|
111
|
+
*/
|
|
112
|
+
export interface ConvertPivotToApplicationResp {
|
|
113
|
+
/**
|
|
114
|
+
* The **new** opportunity for the alternative-product application.
|
|
115
|
+
*
|
|
116
|
+
* This replaces the Final Expense id for all subsequent calls on that
|
|
117
|
+
* product — get-existing-quote, update quote, payment, signing, final submit.
|
|
118
|
+
*/
|
|
119
|
+
opportunityId: string;
|
|
120
|
+
/** Which product the new opportunity belongs to, e.g. `"InstaGIGDB"`. */
|
|
121
|
+
productCode: string;
|
|
122
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in details for application-status webhooks, sent on start-application.
|
|
3
|
+
*
|
|
4
|
+
* Accepted by `startIBTermApplication()`, `startPureTermApplication()`, and the
|
|
5
|
+
* generic `startApplication()`. ADB, GIGDB, and Final Expense start-application
|
|
6
|
+
* **silently ignore** it — no error is returned, and no callbacks are registered.
|
|
7
|
+
*
|
|
8
|
+
* - Omit the field or pass `null` for no callbacks — both are treated the same.
|
|
9
|
+
* - When the object is sent, both fields are required. `{}` fails validation.
|
|
10
|
+
* - One callback per opportunity, set at start-application only. There is no API
|
|
11
|
+
* to change the URL or secret afterwards.
|
|
12
|
+
* - Invalid details fail the whole request with HTTP 400 `InvalidRequestFormat`
|
|
13
|
+
* (messages under `value.fields['WebhookRegistrationDetails.CallbackUrl']` /
|
|
14
|
+
* `['WebhookRegistrationDetails.SecretKey']`), and no application is created.
|
|
15
|
+
* - A knockout decline (all-zero `opportunityId`) registers nothing.
|
|
16
|
+
* - Delivery is best-effort. A successful start-application does not guarantee
|
|
17
|
+
* that events will be delivered.
|
|
18
|
+
*
|
|
19
|
+
* On the receiving side, verify every delivery with `verifyWebhookSignature()`.
|
|
20
|
+
*/
|
|
21
|
+
export interface WebhookRegistrationDetails {
|
|
22
|
+
/**
|
|
23
|
+
* Absolute HTTPS URL that InstaBrain POSTs events to. Max 2048 characters.
|
|
24
|
+
*
|
|
25
|
+
* HTTPS is required in **both sandbox and production** — `http://` and
|
|
26
|
+
* relative URLs are rejected with `callbackUrl must be an absolute HTTPS URL.`
|
|
27
|
+
* For local testing, use a public HTTPS tunnel.
|
|
28
|
+
*/
|
|
29
|
+
callbackUrl: string;
|
|
30
|
+
/**
|
|
31
|
+
* Shared secret, 16–256 characters, used to sign every delivery (HMAC-SHA256).
|
|
32
|
+
*
|
|
33
|
+
* Treat it like an API key: keep it server-side, never log it, and never build
|
|
34
|
+
* start-application requests in a browser. Keep a copy — it cannot be rotated
|
|
35
|
+
* for an existing opportunity, and it is copied to the new opportunity on pivot.
|
|
36
|
+
*/
|
|
37
|
+
secretKey: string;
|
|
38
|
+
}
|
|
39
|
+
/** Options for `verifyWebhookSignature()`. */
|
|
40
|
+
export interface VerifyWebhookSignatureOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Maximum allowed difference, in seconds, between `X-InstaBrain-Timestamp` and
|
|
43
|
+
* the current time, in either direction. Defaults to `300` (5 minutes).
|
|
44
|
+
*
|
|
45
|
+
* InstaBrain signs every delivery attempt — retries included — with a fresh
|
|
46
|
+
* timestamp, so a legitimate retry is never older than this window. Must be a
|
|
47
|
+
* positive number. Pass `Infinity` to disable the check.
|
|
48
|
+
*/
|
|
49
|
+
toleranceSeconds?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Current Unix time in **seconds** (not milliseconds). Defaults to the system
|
|
52
|
+
* clock. Mainly useful in tests.
|
|
53
|
+
*/
|
|
54
|
+
nowSeconds?: number;
|
|
55
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { VerifyWebhookSignatureOptions } from '../types/webhook.types';
|
|
2
|
+
/**
|
|
3
|
+
* Header names InstaBrain sends on every webhook delivery, in the lowercase form
|
|
4
|
+
* Node.js uses for `req.headers`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const WEBHOOK_HEADERS: {
|
|
7
|
+
/** Unix time in seconds (UTC) the signature was computed at. Fresh on every attempt. */
|
|
8
|
+
readonly TIMESTAMP: "x-instabrain-timestamp";
|
|
9
|
+
/** Lowercase hex HMAC-SHA256 of `{timestamp}.{rawBody}`. */
|
|
10
|
+
readonly SIGNATURE: "x-instabrain-signature";
|
|
11
|
+
/**
|
|
12
|
+
* Same value as the envelope `eventId`. **Not covered by the signature** — after
|
|
13
|
+
* verifying, deduplicate on the `eventId` inside the body, not on this header.
|
|
14
|
+
*/
|
|
15
|
+
readonly EVENT_ID: "x-instabrain-event-id";
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Verify that a webhook delivery really came from InstaBrain.
|
|
19
|
+
*
|
|
20
|
+
* Computes HMAC-SHA256 of `{timestamp}.{rawBody}` with the `secretKey` you sent
|
|
21
|
+
* in `webhookRegistrationDetails`, and compares it to `X-InstaBrain-Signature` in
|
|
22
|
+
* constant time. It also rejects a timestamp more than 5 minutes from now
|
|
23
|
+
* (configurable via `options.toleranceSeconds`).
|
|
24
|
+
*
|
|
25
|
+
* Pass the body **exactly as received** — never `JSON.stringify(JSON.parse(body))`,
|
|
26
|
+
* which can change spacing or escaping and break the signature. Parse the JSON
|
|
27
|
+
* only after this returns `true`, then deduplicate on the body's `eventId`.
|
|
28
|
+
*
|
|
29
|
+
* Returns `false` for a missing, malformed, stale, or wrong signature or
|
|
30
|
+
* timestamp. Throws `TypeError` for programming mistakes — an empty secret, a
|
|
31
|
+
* body that is not a string or bytes (e.g. an already-parsed object), or invalid
|
|
32
|
+
* options — so a misconfigured endpoint fails loudly instead of silently
|
|
33
|
+
* rejecting every event. Note that a stray request with a non-JSON
|
|
34
|
+
* `Content-Type` or no body can also reach the body check, because body parsers
|
|
35
|
+
* then leave `req.body` as `{}` or `undefined`. A single `TypeError` is
|
|
36
|
+
* therefore not proof of misconfiguration; one on every InstaBrain delivery is.
|
|
37
|
+
*
|
|
38
|
+
* @param rawBody - Raw request body: a string, or the raw bytes (`Buffer`,
|
|
39
|
+
* `Uint8Array`, or `ArrayBuffer`).
|
|
40
|
+
* @param timestampHeader - Value of the `X-InstaBrain-Timestamp` header.
|
|
41
|
+
* @param signatureHeader - Value of the `X-InstaBrain-Signature` header.
|
|
42
|
+
* @param secretKey - The `secretKey` registered on start-application.
|
|
43
|
+
* @param options - Optional timestamp tolerance and clock override.
|
|
44
|
+
* @returns `true` only when the signature matches and the timestamp is within tolerance.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import express from 'express';
|
|
49
|
+
* import { verifyWebhookSignature, WEBHOOK_HEADERS } from '@instabrain-sdks/api-client';
|
|
50
|
+
*
|
|
51
|
+
* // express.raw() on this route, ahead of any app-wide express.json(), keeps
|
|
52
|
+
* // req.body as the raw Buffer. If that is ever misconfigured, the helper throws,
|
|
53
|
+
* // Express answers 500, and InstaBrain retries (5 times, over ~31 minutes) —
|
|
54
|
+
* // a 4xx would drop the event.
|
|
55
|
+
* app.post('/webhooks/instabrain', express.raw({ type: 'application/json' }), (req, res) => {
|
|
56
|
+
* const ok = verifyWebhookSignature(
|
|
57
|
+
* req.body,
|
|
58
|
+
* req.headers[WEBHOOK_HEADERS.TIMESTAMP],
|
|
59
|
+
* req.headers[WEBHOOK_HEADERS.SIGNATURE],
|
|
60
|
+
* process.env.INSTABRAIN_WEBHOOK_SECRET!
|
|
61
|
+
* );
|
|
62
|
+
* if (!ok) {
|
|
63
|
+
* res.sendStatus(401);
|
|
64
|
+
* return;
|
|
65
|
+
* }
|
|
66
|
+
* const event = JSON.parse(req.body.toString('utf8'));
|
|
67
|
+
* // Store event.eventId, then respond 2xx quickly and process asynchronously.
|
|
68
|
+
* res.sendStatus(200);
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function verifyWebhookSignature(rawBody: string | Uint8Array | ArrayBuffer, timestampHeader: string | string[] | null | undefined, signatureHeader: string | string[] | null | undefined, secretKey: string, options?: VerifyWebhookSignatureOptions): boolean;
|