@instabrain-sdks/api-client 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +568 -70
- package/dist/client/instabrain-client.d.ts +124 -9
- package/dist/client/instabrain-client.js +136 -8
- package/dist/services/application.service.d.ts +29 -2
- package/dist/services/application.service.js +29 -2
- package/dist/services/gigdb.service.d.ts +25 -3
- package/dist/services/gigdb.service.js +25 -3
- package/dist/services/payment.service.d.ts +94 -0
- package/dist/services/payment.service.js +161 -0
- package/dist/services/pureterm.service.d.ts +96 -10
- package/dist/services/pureterm.service.js +100 -8
- package/dist/services/secure-sign.service.d.ts +19 -3
- package/dist/services/secure-sign.service.js +19 -3
- package/dist/types/enums.d.ts +74 -2
- package/dist/types/enums.js +86 -3
- package/dist/types/errors.js +26 -2
- package/dist/types/gigdb.types.d.ts +32 -0
- package/dist/types/ibterm.types.d.ts +5 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/payment.types.d.ts +52 -0
- package/dist/types/payment.types.js +3 -0
- package/dist/types/pureterm.types.d.ts +186 -31
- package/dist/utils/error-utils.d.ts +9 -1
- package/dist/utils/error-utils.js +18 -3
- package/dist/utils/http-client.js +11 -2
- package/package.json +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentService = void 0;
|
|
4
|
+
const errors_1 = require("../types/errors");
|
|
5
|
+
const base_service_1 = require("./base.service");
|
|
6
|
+
/** Default polling cadence for {@link PaymentService.pollCcPaymentStatus}. */
|
|
7
|
+
const DEFAULT_POLL_OPTIONS = {
|
|
8
|
+
intervalMs: 10 * 1000, // 10s — matches the documented rate limit
|
|
9
|
+
maxTotalDurationMs: 30 * 60 * 1000, // 30 min client-side safety net — matches the Final Expense poller
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Wait applied before retrying a rate-limited (HTTP 429) status request.
|
|
13
|
+
* The endpoint documents `Retry-After: 10` — note this is a **different** value
|
|
14
|
+
* from the Final Expense underwriting poller's 2s.
|
|
15
|
+
*/
|
|
16
|
+
const RATE_LIMIT_RETRY_MS = 10 * 1000;
|
|
17
|
+
/**
|
|
18
|
+
* Credit card payment service (shared — **ADB, GIGDB, and Final Expense only**).
|
|
19
|
+
*
|
|
20
|
+
* Card capture happens in a TrustCommerce hosted iframe. The SDK never touches
|
|
21
|
+
* card data — it hands you a URL to render, then reports when capture completes.
|
|
22
|
+
*
|
|
23
|
+
* Flow (slots between Start Application and Prepare Signing Docs):
|
|
24
|
+
* 1. getIframeUrl(opportunityId) → URL to render; **persist it**
|
|
25
|
+
* 2. applicant submits the hosted form
|
|
26
|
+
* 3. pollCcPaymentStatus(...) → until `approved`
|
|
27
|
+
* 4. Secure Sign → InstaBrainClient.finalSubmit()
|
|
28
|
+
*
|
|
29
|
+
* Key rules:
|
|
30
|
+
* - **Persist and reuse the URL.** A new link is only issued once the latest
|
|
31
|
+
* attempt has `failed`. Calling {@link getIframeUrl} again while capture is
|
|
32
|
+
* `pending` **or** already `approved` returns `TcIframeLinkAlreadyGenerated`.
|
|
33
|
+
* - **EFT and credit card are mutually exclusive** per opportunity. After a
|
|
34
|
+
* successful `saveEftPayment()`, this endpoint returns `EftPaymentAlreadyCompleted`.
|
|
35
|
+
* - `'approved'` means the card was **captured**, not charged. ADB/GIGDB charge
|
|
36
|
+
* at `finalSubmit()`; for Final Expense the carrier collects after underwriting.
|
|
37
|
+
* - **Not supported for IB Term / Pure Term** — returns
|
|
38
|
+
* `CcPaymentIframeNotSupportedForProduct`. Those products use the shared EFT
|
|
39
|
+
* endpoint or hand off via their returned links.
|
|
40
|
+
*/
|
|
41
|
+
class PaymentService extends base_service_1.BaseService {
|
|
42
|
+
constructor(httpClient) {
|
|
43
|
+
super(httpClient);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the TrustCommerce hosted iframe URL for card capture.
|
|
47
|
+
*
|
|
48
|
+
* Call after Start Application has completed successfully and before Prepare
|
|
49
|
+
* Signing Docs. **Persist the returned URL keyed by `opportunityId`** and
|
|
50
|
+
* reuse it while {@link pollCcPaymentStatus} reports `'pending'` — requesting
|
|
51
|
+
* a second link before the current attempt fails returns
|
|
52
|
+
* `TcIframeLinkAlreadyGenerated`.
|
|
53
|
+
*
|
|
54
|
+
* Errors (all HTTP 400, each a distinct top-level code):
|
|
55
|
+
* - `InvalidRequestFormat` — `opportunityId` missing or unknown
|
|
56
|
+
* - `CcPaymentIframeNotSupportedForProduct` — product is not ADB / GIGDB / Final Expense
|
|
57
|
+
* - `ApplicationNotReady` — Start Application has not completed successfully
|
|
58
|
+
* - `EftPaymentAlreadyCompleted` — a successful EFT payment already exists
|
|
59
|
+
* - `TcIframeLinkAlreadyGenerated` — a link exists and the latest attempt has not failed
|
|
60
|
+
*
|
|
61
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
62
|
+
* @returns Promise resolving to the fully-qualified iframe URL.
|
|
63
|
+
*/
|
|
64
|
+
async getIframeUrl(opportunityId) {
|
|
65
|
+
return this.get('get credit card iframe URL', '/api/ThirdPartyPayment/get-iframe-url', {
|
|
66
|
+
params: { opportunityId },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Single check of credit card capture status.
|
|
71
|
+
*
|
|
72
|
+
* Rate-limited to 1 request per 10 seconds per `opportunityId`; exceeding it
|
|
73
|
+
* throws an `InstaBrainError` with `statusCode: 429`. This method does **not**
|
|
74
|
+
* auto-retry — use {@link pollCcPaymentStatus} for a managed loop.
|
|
75
|
+
*
|
|
76
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
77
|
+
* @returns Promise with the current `status` and `shouldContinuePolling`.
|
|
78
|
+
*/
|
|
79
|
+
async getCcPaymentStatus(opportunityId) {
|
|
80
|
+
return this.get('get credit card payment status', '/api/ThirdPartyPayment/cc-payment-status', {
|
|
81
|
+
params: { opportunityId },
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Poll card-capture status until it resolves or the time budget is exhausted.
|
|
86
|
+
*
|
|
87
|
+
* Polls every 10s (configurable) and stops as soon as `shouldContinuePolling`
|
|
88
|
+
* is `false` — i.e. `'approved'` or `'failed'`. A `429` is transparently
|
|
89
|
+
* retried after the documented `Retry-After: 10` rather than aborting the poll.
|
|
90
|
+
*
|
|
91
|
+
* This method **never requests a new iframe URL**. On `'failed'` it returns and
|
|
92
|
+
* the caller needs to call {@link getIframeUrl} again for a fresh capture.
|
|
93
|
+
*
|
|
94
|
+
* On budget expiry it resolves with the last response (still `'pending'`)
|
|
95
|
+
* rather than throwing — inspect `status` to detect it.
|
|
96
|
+
*
|
|
97
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
98
|
+
* @param options - Optional cadence overrides.
|
|
99
|
+
* @returns Promise with the terminal response, or the last `'pending'` one on timeout.
|
|
100
|
+
*/
|
|
101
|
+
async pollCcPaymentStatus(opportunityId, options = {}) {
|
|
102
|
+
const { intervalMs, maxTotalDurationMs } = { ...DEFAULT_POLL_OPTIONS, ...options };
|
|
103
|
+
const onPoll = options.onPoll;
|
|
104
|
+
const start = Date.now();
|
|
105
|
+
const deadline = start + maxTotalDurationMs;
|
|
106
|
+
let attempt = 1;
|
|
107
|
+
let last = await this.getStatusWithRateLimitRetry(opportunityId, deadline);
|
|
108
|
+
onPoll === null || onPoll === void 0 ? void 0 : onPoll(last, attempt, Date.now() - start);
|
|
109
|
+
while (last.shouldContinuePolling) {
|
|
110
|
+
const elapsed = Date.now() - start;
|
|
111
|
+
if (elapsed >= maxTotalDurationMs) {
|
|
112
|
+
// Budget exhausted — return the last response rather than throwing.
|
|
113
|
+
return last;
|
|
114
|
+
}
|
|
115
|
+
// Never sleep past the remaining budget.
|
|
116
|
+
const wait = Math.min(intervalMs, maxTotalDurationMs - elapsed);
|
|
117
|
+
await this.delay(wait);
|
|
118
|
+
attempt += 1;
|
|
119
|
+
last = await this.getStatusWithRateLimitRetry(opportunityId, deadline, last);
|
|
120
|
+
onPoll === null || onPoll === void 0 ? void 0 : onPoll(last, attempt, Date.now() - start);
|
|
121
|
+
}
|
|
122
|
+
return last;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Single status call that transparently retries a `429` (rate limit) after
|
|
126
|
+
* {@link RATE_LIMIT_RETRY_MS}, as long as another attempt fits within the poll
|
|
127
|
+
* deadline.
|
|
128
|
+
*
|
|
129
|
+
* When the retry budget is exhausted on a `429`, resolves with `fallback` (the
|
|
130
|
+
* last known response) rather than aborting the managed poll. If no `fallback`
|
|
131
|
+
* exists (the very first call), the `429` propagates. Any non-`429` error
|
|
132
|
+
* always propagates.
|
|
133
|
+
*/
|
|
134
|
+
async getStatusWithRateLimitRetry(opportunityId, deadline, fallback) {
|
|
135
|
+
for (;;) {
|
|
136
|
+
try {
|
|
137
|
+
return await this.getCcPaymentStatus(opportunityId);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
const isRateLimited = error instanceof errors_1.InstaBrainError && error.statusCode === 429;
|
|
141
|
+
if (isRateLimited) {
|
|
142
|
+
if (Date.now() + RATE_LIMIT_RETRY_MS <= deadline) {
|
|
143
|
+
await this.delay(RATE_LIMIT_RETRY_MS);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (fallback !== undefined) {
|
|
147
|
+
return fallback;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Promise-based sleep. Extracted so tests can drive polling with fake timers.
|
|
156
|
+
*/
|
|
157
|
+
delay(ms) {
|
|
158
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.PaymentService = PaymentService;
|
|
@@ -1,31 +1,117 @@
|
|
|
1
1
|
import { HttpClient } from '../utils/http-client';
|
|
2
2
|
import { BaseService } from './base.service';
|
|
3
|
-
import { ThirdPartyPureTermQuoteReq } from '../types/pureterm.types';
|
|
4
|
-
import { ThirdPartyQuoteResp } from '../types';
|
|
3
|
+
import { ThirdPartyPureTermQuoteReq, PureTermRiderDetailsResp, PureTermStartApplicationReq } from '../types/pureterm.types';
|
|
4
|
+
import { ThirdPartyQuoteResp, ThirdPartyStartAppResp } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Pure Term (InstaBrain Pure Term) service
|
|
7
|
-
* Handles quoting for the Pure Term product.
|
|
7
|
+
* Handles lookup, quoting, and application for the Pure Term product (ages 18–60).
|
|
8
8
|
*
|
|
9
9
|
* Flow:
|
|
10
|
-
* 1.
|
|
11
|
-
* 2.
|
|
10
|
+
* 1. (optional) getRiderDetails(stateCode, age, flagNicotineUse) → rider availability + codes
|
|
11
|
+
* 2. getQuote() → quoteResponseId
|
|
12
|
+
* 3. startApplication() → opportunityId + links (or isDeclined=true)
|
|
13
|
+
* 4. (optional) getExistingQuote(opportunityId) → re-fetch the stored quote
|
|
12
14
|
*
|
|
13
15
|
* After startApplication(), direct the agent or applicant to the returned link.
|
|
14
16
|
* All remaining steps (underwriting, payment, signing) complete inside the
|
|
15
|
-
* InstaBrain frontend. Do NOT
|
|
16
|
-
* finalSubmit()
|
|
17
|
+
* InstaBrain frontend — the same hand-off family as IB Term. Do NOT wire a Pure
|
|
18
|
+
* Term `opportunityId` into the shared SecureSign, finalSubmit(), or credit-card
|
|
19
|
+
* iframe clients. Shared EFT (`saveEftPayment()`) is allowed; the credit-card
|
|
20
|
+
* iframe is not supported for Pure Term and returns
|
|
21
|
+
* `CcPaymentIframeNotSupportedForProduct`.
|
|
17
22
|
*/
|
|
18
23
|
export declare class PureTermService extends BaseService {
|
|
19
24
|
constructor(httpClient: HttpClient);
|
|
25
|
+
/**
|
|
26
|
+
* Get available riders for Pure Term in a given state, filtered by the
|
|
27
|
+
* applicant's age and nicotine-use status.
|
|
28
|
+
*
|
|
29
|
+
* Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
|
|
30
|
+
* in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
|
|
31
|
+
* do not proceed to the Quote API. The empty `riders` array in that case is a
|
|
32
|
+
* valid business state, not an error, and is returned as-is by the SDK.
|
|
33
|
+
*
|
|
34
|
+
* Use `riderCode` from the response as `riders[n].rider` on the Pure Term quote.
|
|
35
|
+
*
|
|
36
|
+
* @param stateCode - Two-letter US state code (e.g. "TX").
|
|
37
|
+
* @param age - Applicant's age, integer, 18–60 inclusive.
|
|
38
|
+
* @param flagNicotineUse - Whether the applicant uses nicotine; required by the backend.
|
|
39
|
+
* @returns Rider list + product availability flag.
|
|
40
|
+
*/
|
|
41
|
+
getRiderDetails(stateCode: string, age: number, flagNicotineUse: boolean): Promise<PureTermRiderDetailsResp>;
|
|
20
42
|
/**
|
|
21
43
|
* Get a Pure Term insurance quote.
|
|
22
44
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
45
|
+
* `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
|
|
46
|
+
* required. Supply at least one rating group — `rateClass`, `healthClass`, or
|
|
47
|
+
* both `height` and `weightInLbs`; passing more than one is allowed. Supply
|
|
48
|
+
* `age` OR `dateOfBirth` (18–60); `dateOfBirth` wins when both are sent.
|
|
49
|
+
* `flagTobaccoUse` defaults to `false`.
|
|
50
|
+
*
|
|
51
|
+
* Pure Term uses the same quote request shape as IB Term but different product
|
|
52
|
+
* rules (rate classes including Rated C/D, term lengths including 15,
|
|
53
|
+
* coverage/benefit tables) — see {@link ThirdPartyPureTermQuoteReq} for the
|
|
54
|
+
* exact rules in check order.
|
|
55
|
+
*
|
|
56
|
+
* **Errors come from two stages.** Request validation issues dedicated
|
|
57
|
+
* top-level codes only for `BenefitPeriodNotAvailable` and
|
|
58
|
+
* `CoverageNotAvailable`; every other field failure surfaces as
|
|
59
|
+
* `InvalidRequestFormat` with PascalCase keys under `value.fields`. Once
|
|
60
|
+
* validation passes, the shared quote-eligibility pipeline can still return
|
|
61
|
+
* `NotAvailableForState`, `QuoteNotEligibleForGivenConditions`,
|
|
62
|
+
* `RiderNotAvailable`, `RiderFaceAmountNotValid`, or `outsideBuildChart` —
|
|
63
|
+
* do not assume those never occur for Pure Term.
|
|
26
64
|
*
|
|
27
65
|
* @param request - The Pure Term quote request payload.
|
|
28
66
|
* @returns Promise with the quote response including `quoteResponseId`.
|
|
29
67
|
*/
|
|
30
68
|
getQuote(request: ThirdPartyPureTermQuoteReq): Promise<ThirdPartyQuoteResp>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the existing quote for an in-flight Pure Term opportunity.
|
|
71
|
+
*
|
|
72
|
+
* Use to resume or review a previously generated Pure Term quote by its
|
|
73
|
+
* opportunity ID without re-quoting. The response reuses the same shape as
|
|
74
|
+
* `getQuote()` — `productName` is `"InstaBrain Pure Term"`.
|
|
75
|
+
*
|
|
76
|
+
* Unlike rider-details product-unavailability, a not-found result here is an
|
|
77
|
+
* error (surfaced via the SDK error model), not a valid business state:
|
|
78
|
+
* - missing / empty / non-GUID `opportunityId` → `InvalidRequestFormat`
|
|
79
|
+
* ("OpportunityId is required." / "OpportunityId does not exist.")
|
|
80
|
+
* - opportunity belongs to a different product → "OpportunityId does not
|
|
81
|
+
* match selected product." (field-level message under `InvalidRequestFormat`)
|
|
82
|
+
* - opportunity exists but has no stored quote → `QuoteNotFound` (top-level, `value: null`)
|
|
83
|
+
*
|
|
84
|
+
* @param opportunityId - UUID from a prior Pure Term application/quote flow.
|
|
85
|
+
* @returns Promise with the current quote response.
|
|
86
|
+
*/
|
|
87
|
+
getExistingQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
|
|
88
|
+
/**
|
|
89
|
+
* Start a Pure Term application from a prior Pure Term quote.
|
|
90
|
+
*
|
|
91
|
+
* This is a dedicated endpoint, separate from the generic
|
|
92
|
+
* `InstaBrainClient.startApplication()` (`/api/ThirdPartyStartApp/start-application`),
|
|
93
|
+
* which remains unchanged for other products.
|
|
94
|
+
*
|
|
95
|
+
* Notes:
|
|
96
|
+
* - `isDeclined: true` is a valid success response (knockout), not an error.
|
|
97
|
+
* Knockouts: `isUsCitizenOrIsPermanentResident=false`,
|
|
98
|
+
* `isPayerAlsoOwnerAndInsured=false`, `isHoldingValidDriverLicense=false`,
|
|
99
|
+
* `areListedConditionsNotApplicable=false`, any of the four `childRiderInfo`
|
|
100
|
+
* knockout questions `=true`, or height/weight outside allowed limits.
|
|
101
|
+
* - `quoteResponseId` must belong to the Pure Term product.
|
|
102
|
+
* - `childRiderInfo` is required only when the Dependent Child Rider was on the
|
|
103
|
+
* quote, and must NOT be sent otherwise.
|
|
104
|
+
* - Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense only).
|
|
105
|
+
* - Start Application is one shared service across both Term products, so the
|
|
106
|
+
* error set matches IB Term. Business failures return HTTP 400 with
|
|
107
|
+
* `value: null` and a top-level `agentNotFound` (missing user context),
|
|
108
|
+
* `StateMismatchIdentified` (quote state differs from `address.state`),
|
|
109
|
+
* `dataNotFound` (quote response not found), or `internalServerError`.
|
|
110
|
+
* - After a successful, non-declined start, hand off via the returned links —
|
|
111
|
+
* do not continue into shared SecureSign / finalSubmit with this `opportunityId`.
|
|
112
|
+
*
|
|
113
|
+
* @param request - The Pure Term application request payload.
|
|
114
|
+
* @returns Promise with opportunityId, links, isDeclined flag, and `isQuoteChanged`.
|
|
115
|
+
*/
|
|
116
|
+
startApplication(request: PureTermStartApplicationReq): Promise<ThirdPartyStartAppResp>;
|
|
31
117
|
}
|
|
@@ -4,27 +4,67 @@ exports.PureTermService = void 0;
|
|
|
4
4
|
const base_service_1 = require("./base.service");
|
|
5
5
|
/**
|
|
6
6
|
* Pure Term (InstaBrain Pure Term) service
|
|
7
|
-
* Handles quoting for the Pure Term product.
|
|
7
|
+
* Handles lookup, quoting, and application for the Pure Term product (ages 18–60).
|
|
8
8
|
*
|
|
9
9
|
* Flow:
|
|
10
|
-
* 1.
|
|
11
|
-
* 2.
|
|
10
|
+
* 1. (optional) getRiderDetails(stateCode, age, flagNicotineUse) → rider availability + codes
|
|
11
|
+
* 2. getQuote() → quoteResponseId
|
|
12
|
+
* 3. startApplication() → opportunityId + links (or isDeclined=true)
|
|
13
|
+
* 4. (optional) getExistingQuote(opportunityId) → re-fetch the stored quote
|
|
12
14
|
*
|
|
13
15
|
* After startApplication(), direct the agent or applicant to the returned link.
|
|
14
16
|
* All remaining steps (underwriting, payment, signing) complete inside the
|
|
15
|
-
* InstaBrain frontend. Do NOT
|
|
16
|
-
* finalSubmit()
|
|
17
|
+
* InstaBrain frontend — the same hand-off family as IB Term. Do NOT wire a Pure
|
|
18
|
+
* Term `opportunityId` into the shared SecureSign, finalSubmit(), or credit-card
|
|
19
|
+
* iframe clients. Shared EFT (`saveEftPayment()`) is allowed; the credit-card
|
|
20
|
+
* iframe is not supported for Pure Term and returns
|
|
21
|
+
* `CcPaymentIframeNotSupportedForProduct`.
|
|
17
22
|
*/
|
|
18
23
|
class PureTermService extends base_service_1.BaseService {
|
|
19
24
|
constructor(httpClient) {
|
|
20
25
|
super(httpClient);
|
|
21
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Get available riders for Pure Term in a given state, filtered by the
|
|
29
|
+
* applicant's age and nicotine-use status.
|
|
30
|
+
*
|
|
31
|
+
* Optional pre-quote step. When `flagProductNotAvailableForState` is `true`
|
|
32
|
+
* in the response, Pure Term is not available for these inputs (e.g. WY, NY) —
|
|
33
|
+
* do not proceed to the Quote API. The empty `riders` array in that case is a
|
|
34
|
+
* valid business state, not an error, and is returned as-is by the SDK.
|
|
35
|
+
*
|
|
36
|
+
* Use `riderCode` from the response as `riders[n].rider` on the Pure Term quote.
|
|
37
|
+
*
|
|
38
|
+
* @param stateCode - Two-letter US state code (e.g. "TX").
|
|
39
|
+
* @param age - Applicant's age, integer, 18–60 inclusive.
|
|
40
|
+
* @param flagNicotineUse - Whether the applicant uses nicotine; required by the backend.
|
|
41
|
+
* @returns Rider list + product availability flag.
|
|
42
|
+
*/
|
|
43
|
+
async getRiderDetails(stateCode, age, flagNicotineUse) {
|
|
44
|
+
return this.get('get Pure Term rider details', '/api/ThirdPartyIbPureTermLookup/get-rider-details', { params: { stateCode, age, flagNicotineUse } });
|
|
45
|
+
}
|
|
22
46
|
/**
|
|
23
47
|
* Get a Pure Term insurance quote.
|
|
24
48
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
49
|
+
* `faceAmount`, `benefitPeriod`, `gender`, `stateCode`, and `paymentFreq` are
|
|
50
|
+
* required. Supply at least one rating group — `rateClass`, `healthClass`, or
|
|
51
|
+
* both `height` and `weightInLbs`; passing more than one is allowed. Supply
|
|
52
|
+
* `age` OR `dateOfBirth` (18–60); `dateOfBirth` wins when both are sent.
|
|
53
|
+
* `flagTobaccoUse` defaults to `false`.
|
|
54
|
+
*
|
|
55
|
+
* Pure Term uses the same quote request shape as IB Term but different product
|
|
56
|
+
* rules (rate classes including Rated C/D, term lengths including 15,
|
|
57
|
+
* coverage/benefit tables) — see {@link ThirdPartyPureTermQuoteReq} for the
|
|
58
|
+
* exact rules in check order.
|
|
59
|
+
*
|
|
60
|
+
* **Errors come from two stages.** Request validation issues dedicated
|
|
61
|
+
* top-level codes only for `BenefitPeriodNotAvailable` and
|
|
62
|
+
* `CoverageNotAvailable`; every other field failure surfaces as
|
|
63
|
+
* `InvalidRequestFormat` with PascalCase keys under `value.fields`. Once
|
|
64
|
+
* validation passes, the shared quote-eligibility pipeline can still return
|
|
65
|
+
* `NotAvailableForState`, `QuoteNotEligibleForGivenConditions`,
|
|
66
|
+
* `RiderNotAvailable`, `RiderFaceAmountNotValid`, or `outsideBuildChart` —
|
|
67
|
+
* do not assume those never occur for Pure Term.
|
|
28
68
|
*
|
|
29
69
|
* @param request - The Pure Term quote request payload.
|
|
30
70
|
* @returns Promise with the quote response including `quoteResponseId`.
|
|
@@ -32,5 +72,57 @@ class PureTermService extends base_service_1.BaseService {
|
|
|
32
72
|
async getQuote(request) {
|
|
33
73
|
return this.post('get Pure Term quote', '/api/ThirdPartyIbPureTermQuote/get', request);
|
|
34
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the existing quote for an in-flight Pure Term opportunity.
|
|
77
|
+
*
|
|
78
|
+
* Use to resume or review a previously generated Pure Term quote by its
|
|
79
|
+
* opportunity ID without re-quoting. The response reuses the same shape as
|
|
80
|
+
* `getQuote()` — `productName` is `"InstaBrain Pure Term"`.
|
|
81
|
+
*
|
|
82
|
+
* Unlike rider-details product-unavailability, a not-found result here is an
|
|
83
|
+
* error (surfaced via the SDK error model), not a valid business state:
|
|
84
|
+
* - missing / empty / non-GUID `opportunityId` → `InvalidRequestFormat`
|
|
85
|
+
* ("OpportunityId is required." / "OpportunityId does not exist.")
|
|
86
|
+
* - opportunity belongs to a different product → "OpportunityId does not
|
|
87
|
+
* match selected product." (field-level message under `InvalidRequestFormat`)
|
|
88
|
+
* - opportunity exists but has no stored quote → `QuoteNotFound` (top-level, `value: null`)
|
|
89
|
+
*
|
|
90
|
+
* @param opportunityId - UUID from a prior Pure Term application/quote flow.
|
|
91
|
+
* @returns Promise with the current quote response.
|
|
92
|
+
*/
|
|
93
|
+
async getExistingQuote(opportunityId) {
|
|
94
|
+
return this.get('get existing Pure Term quote', '/api/ThirdPartyIbPureTermQuote/get-existing-quote', { params: { opportunityId } });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Start a Pure Term application from a prior Pure Term quote.
|
|
98
|
+
*
|
|
99
|
+
* This is a dedicated endpoint, separate from the generic
|
|
100
|
+
* `InstaBrainClient.startApplication()` (`/api/ThirdPartyStartApp/start-application`),
|
|
101
|
+
* which remains unchanged for other products.
|
|
102
|
+
*
|
|
103
|
+
* Notes:
|
|
104
|
+
* - `isDeclined: true` is a valid success response (knockout), not an error.
|
|
105
|
+
* Knockouts: `isUsCitizenOrIsPermanentResident=false`,
|
|
106
|
+
* `isPayerAlsoOwnerAndInsured=false`, `isHoldingValidDriverLicense=false`,
|
|
107
|
+
* `areListedConditionsNotApplicable=false`, any of the four `childRiderInfo`
|
|
108
|
+
* knockout questions `=true`, or height/weight outside allowed limits.
|
|
109
|
+
* - `quoteResponseId` must belong to the Pure Term product.
|
|
110
|
+
* - `childRiderInfo` is required only when the Dependent Child Rider was on the
|
|
111
|
+
* quote, and must NOT be sent otherwise.
|
|
112
|
+
* - Pure Term does NOT use `ApplicationLimitReached` (ADB / GIGDB / Final Expense only).
|
|
113
|
+
* - Start Application is one shared service across both Term products, so the
|
|
114
|
+
* error set matches IB Term. Business failures return HTTP 400 with
|
|
115
|
+
* `value: null` and a top-level `agentNotFound` (missing user context),
|
|
116
|
+
* `StateMismatchIdentified` (quote state differs from `address.state`),
|
|
117
|
+
* `dataNotFound` (quote response not found), or `internalServerError`.
|
|
118
|
+
* - After a successful, non-declined start, hand off via the returned links —
|
|
119
|
+
* do not continue into shared SecureSign / finalSubmit with this `opportunityId`.
|
|
120
|
+
*
|
|
121
|
+
* @param request - The Pure Term application request payload.
|
|
122
|
+
* @returns Promise with opportunityId, links, isDeclined flag, and `isQuoteChanged`.
|
|
123
|
+
*/
|
|
124
|
+
async startApplication(request) {
|
|
125
|
+
return this.post('start Pure Term application', '/api/ThirdPartyPureTermApplication/start-application', request);
|
|
126
|
+
}
|
|
35
127
|
}
|
|
36
128
|
exports.PureTermService = PureTermService;
|
|
@@ -15,9 +15,25 @@ import { ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, T
|
|
|
15
15
|
export declare class SecureSignService extends BaseService {
|
|
16
16
|
constructor(httpClient: HttpClient);
|
|
17
17
|
/**
|
|
18
|
-
* Prepare the signing package and check available delivery channels
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* Prepare the signing package and check available delivery channels.
|
|
19
|
+
*
|
|
20
|
+
* Applies to **ADB, GIGDB, and Final Expense**. Always call this first — it
|
|
21
|
+
* prepares the documents server-side. If `isSignCompleted` is `true`, the
|
|
22
|
+
* documents are already signed: skip the PIN flow entirely and go straight to
|
|
23
|
+
* `finalSubmit()`.
|
|
24
|
+
*
|
|
25
|
+
* `isSmsAvailable` / `isEmailAvailable` determine which channels may be
|
|
26
|
+
* selected in `sendPinAndGetDocumentsLink()` — only an available channel is
|
|
27
|
+
* accepted.
|
|
28
|
+
*
|
|
29
|
+
* Errors:
|
|
30
|
+
* - `ApplicationNotReady` — Start Application has not completed
|
|
31
|
+
* successfully, or payment/signing was called too early. This is the same
|
|
32
|
+
* lifecycle gate `getCcPaymentIframeUrl()` applies. Complete Start
|
|
33
|
+
* Application, then retry.
|
|
34
|
+
* - `InvalidRequestFormat` — `opportunityId` missing, non-existent, or the
|
|
35
|
+
* documents are already signed (`Documents are already signed.`).
|
|
36
|
+
*
|
|
21
37
|
* @param opportunityId - The OpportunityId from the Start Application response
|
|
22
38
|
* @returns Promise with delivery channels and sign completion status
|
|
23
39
|
*/
|
|
@@ -18,9 +18,25 @@ class SecureSignService extends base_service_1.BaseService {
|
|
|
18
18
|
super(httpClient);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Prepare the signing package and check available delivery channels
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Prepare the signing package and check available delivery channels.
|
|
22
|
+
*
|
|
23
|
+
* Applies to **ADB, GIGDB, and Final Expense**. Always call this first — it
|
|
24
|
+
* prepares the documents server-side. If `isSignCompleted` is `true`, the
|
|
25
|
+
* documents are already signed: skip the PIN flow entirely and go straight to
|
|
26
|
+
* `finalSubmit()`.
|
|
27
|
+
*
|
|
28
|
+
* `isSmsAvailable` / `isEmailAvailable` determine which channels may be
|
|
29
|
+
* selected in `sendPinAndGetDocumentsLink()` — only an available channel is
|
|
30
|
+
* accepted.
|
|
31
|
+
*
|
|
32
|
+
* Errors:
|
|
33
|
+
* - `ApplicationNotReady` — Start Application has not completed
|
|
34
|
+
* successfully, or payment/signing was called too early. This is the same
|
|
35
|
+
* lifecycle gate `getCcPaymentIframeUrl()` applies. Complete Start
|
|
36
|
+
* Application, then retry.
|
|
37
|
+
* - `InvalidRequestFormat` — `opportunityId` missing, non-existent, or the
|
|
38
|
+
* documents are already signed (`Documents are already signed.`).
|
|
39
|
+
*
|
|
24
40
|
* @param opportunityId - The OpportunityId from the Start Application response
|
|
25
41
|
* @returns Promise with delivery channels and sign completion status
|
|
26
42
|
*/
|
package/dist/types/enums.d.ts
CHANGED
|
@@ -480,8 +480,60 @@ export declare enum APIErrorCode {
|
|
|
480
480
|
AgentNotFound = "agentNotFound",
|
|
481
481
|
/** Unexpected backend failure while processing a Start Application request. */
|
|
482
482
|
InternalServerError = "internalServerError",
|
|
483
|
-
/**
|
|
483
|
+
/**
|
|
484
|
+
* IB Term / Pure Term Start Application — the quote response referenced by
|
|
485
|
+
* `quoteResponseId` could not be found. HTTP 400 with `value: null`.
|
|
486
|
+
*
|
|
487
|
+
* Note: this code was removed in the 2.3.0 cleanup as "not returned by the
|
|
488
|
+
* API". That was true for the products checked at the time; it **is** returned
|
|
489
|
+
* by the IB Term and Pure Term start-application endpoints, so it is back and
|
|
490
|
+
* scoped. Do not delete it again without checking those two products.
|
|
491
|
+
*/
|
|
492
|
+
DataNotFound = "dataNotFound",
|
|
493
|
+
/**
|
|
494
|
+
* Update quote or `saveEftPayment()` when a **successful** payment already
|
|
495
|
+
* exists for the opportunity — a prior EFT save, or a credit card that has
|
|
496
|
+
* already been charged.
|
|
497
|
+
*
|
|
498
|
+
* A credit card that was only captured and not yet charged does not trigger
|
|
499
|
+
* this on request validation. Do not rely on that edge case: treat EFT and
|
|
500
|
+
* credit card as mutually exclusive per `opportunityId`.
|
|
501
|
+
*/
|
|
484
502
|
PaymentAlreadyMade = "PaymentAlreadyMade",
|
|
503
|
+
/** `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. */
|
|
504
|
+
TcIframeLinkAlreadyGenerated = "TcIframeLinkAlreadyGenerated",
|
|
505
|
+
/** `getCcPaymentIframeUrl()` — the product does not support the credit card iframe. Returned for IB Term / Pure Term, which use shared EFT or their hand-off links instead. */
|
|
506
|
+
CcPaymentIframeNotSupportedForProduct = "CcPaymentIframeNotSupportedForProduct",
|
|
507
|
+
/** `getCcPaymentIframeUrl()` / `prepareDocsAndGetDeliveryChannels()` — Start Application has not completed successfully yet. */
|
|
508
|
+
ApplicationNotReady = "ApplicationNotReady",
|
|
509
|
+
/** `getCcPaymentIframeUrl()` — a successful EFT payment already exists. EFT and credit card are mutually exclusive per opportunity. */
|
|
510
|
+
EftPaymentAlreadyCompleted = "EftPaymentAlreadyCompleted",
|
|
511
|
+
/** Card CVV was rejected. */
|
|
512
|
+
PaymentCvvInvalid = "PaymentCvvInvalid",
|
|
513
|
+
/** Declined — the applicant must contact their bank. */
|
|
514
|
+
PaymentDeclinedContactBank = "PaymentDeclinedContactBank",
|
|
515
|
+
/** Card declined. */
|
|
516
|
+
PaymentDeclined = "PaymentDeclined",
|
|
517
|
+
/** Card declined permanently — do not retry the same card. */
|
|
518
|
+
PaymentDeclinedPermanent = "PaymentDeclinedPermanent",
|
|
519
|
+
/** Card PIN is locked. */
|
|
520
|
+
PaymentPinLocked = "PaymentPinLocked",
|
|
521
|
+
/** Insufficient funds on the card. */
|
|
522
|
+
PaymentInsufficientFunds = "PaymentInsufficientFunds",
|
|
523
|
+
/** Processor-side error while charging the card. */
|
|
524
|
+
PaymentProcessingError = "PaymentProcessingError",
|
|
525
|
+
/** Charge blocked as suspected fraud. */
|
|
526
|
+
PaymentSuspectedFraud = "PaymentSuspectedFraud",
|
|
527
|
+
/** Card is expired. */
|
|
528
|
+
PaymentCardExpired = "PaymentCardExpired",
|
|
529
|
+
/** Card data supplied in the iframe was invalid. */
|
|
530
|
+
PaymentInvalidCardData = "PaymentInvalidCardData",
|
|
531
|
+
/** Generic card error. */
|
|
532
|
+
PaymentCardError = "PaymentCardError",
|
|
533
|
+
/** Issuer requires the applicant to contact their bank. */
|
|
534
|
+
PaymentContactBank = "PaymentContactBank",
|
|
535
|
+
/** Generic payment-related failure at final submit. */
|
|
536
|
+
PaymentRelatedError = "PaymentRelatedError",
|
|
485
537
|
/** Generic Secure Sign failure. */
|
|
486
538
|
SecureSignRelatedError = "SecureSignRelatedError",
|
|
487
539
|
/** Signing package missing — call `prepareDocsAndGetDeliveryChannels()` first. */
|
|
@@ -498,8 +550,28 @@ export declare enum APIErrorCode {
|
|
|
498
550
|
EmailDeliveryFailed = "EmailDeliveryFailed",
|
|
499
551
|
/** SMS delivery failed on Send PIN / Resend PIN. */
|
|
500
552
|
MessageNotDelivered = "MessageNotDelivered",
|
|
501
|
-
/**
|
|
553
|
+
/** Secure signing has not been completed for the opportunity — finish the PIN flow (or confirm `isSignCompleted`) before `finalSubmit()`. */
|
|
554
|
+
SecureSignNotCompleted = "SecureSignNotCompleted",
|
|
555
|
+
/**
|
|
556
|
+
* No payment has been completed for the opportunity. Covers **two** cases:
|
|
557
|
+
* no payment was ever started (neither `saveEftPayment()` nor
|
|
558
|
+
* `getCcPaymentIframeUrl()`), **or** a credit card capture is still pending
|
|
559
|
+
* (iframe issued, `cc-payment-status` is `'pending'`).
|
|
560
|
+
*
|
|
561
|
+
* Recovery: complete the payment — finish the iframe and poll to `'approved'`,
|
|
562
|
+
* or save EFT — then retry. While capture is pending, reuse the stored iframe
|
|
563
|
+
* URL; do not request a new one.
|
|
564
|
+
*/
|
|
502
565
|
PaymentNotMade = "paymentNotMade",
|
|
566
|
+
/**
|
|
567
|
+
* A payment was attempted and the most recent attempt finished unsuccessfully
|
|
568
|
+
* (`cc-payment-status` is `'failed'` after a capture or charge decline).
|
|
569
|
+
*
|
|
570
|
+
* Recovery: call `getCcPaymentIframeUrl()` for a new capture, poll to
|
|
571
|
+
* `'approved'`, then retry `finalSubmit()`. Retrying `finalSubmit()` without a
|
|
572
|
+
* new successful capture returns this code again, not a fresh decline code.
|
|
573
|
+
*/
|
|
574
|
+
LatestPaymentNotSuccessful = "LatestPaymentNotSuccessful",
|
|
503
575
|
/** Fidelity carrier rejected or failed to process final submit. */
|
|
504
576
|
FidelityFinalSubmitError = "FidelityFinalSubmitError",
|
|
505
577
|
/** Underwriting status polling is not supported for the product (ADB/GIGDB) — Final Expense only. Returned by `pingFinalExpenseUnderwritingStatus()` / `pollFinalExpenseUnderwritingStatus()` for a non-Final-Expense opportunity. */
|