@instabrain-sdks/api-client 2.4.0 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +31 -0
- package/README.md +820 -81
- package/dist/client/instabrain-client.d.ts +170 -9
- package/dist/client/instabrain-client.js +189 -8
- package/dist/services/application.service.d.ts +29 -2
- package/dist/services/application.service.js +29 -2
- package/dist/services/finalexpense.service.d.ts +23 -5
- package/dist/services/finalexpense.service.js +23 -5
- 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/pivot.service.d.ts +104 -0
- package/dist/services/pivot.service.js +116 -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 +112 -3
- package/dist/types/enums.js +134 -4
- package/dist/types/errors.js +31 -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 +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/payment.types.d.ts +52 -0
- package/dist/types/payment.types.js +3 -0
- package/dist/types/pivot.types.d.ts +122 -0
- package/dist/types/pivot.types.js +2 -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 +9 -4
|
@@ -21,9 +21,31 @@ export declare class GigdbService extends BaseService {
|
|
|
21
21
|
*/
|
|
22
22
|
startApplication(request: ThirdPartyGigdbAppReq): Promise<ThirdPartyStartAppResp>;
|
|
23
23
|
/**
|
|
24
|
-
* Save EFT payment details for
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* Save bank-account (EFT) payment details for an in-progress application.
|
|
25
|
+
*
|
|
26
|
+
* Shared endpoint — used by GIGDB, ADB, and Final Expense. Call after Start
|
|
27
|
+
* Application and before `prepareDocsAndGetDeliveryChannels()`.
|
|
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`.
|
|
33
|
+
*
|
|
34
|
+
* Business rules:
|
|
35
|
+
* - **EFT and credit card are mutually exclusive** per `opportunityId`.
|
|
36
|
+
* A successful payment that already exists (a prior EFT save, or a card
|
|
37
|
+
* that has already been charged) returns `PaymentAlreadyMade`. Afterwards,
|
|
38
|
+
* `getCcPaymentIframeUrl()` returns `EftPaymentAlreadyCompleted`.
|
|
39
|
+
* - No application-readiness gate here, unlike `getCcPaymentIframeUrl()` —
|
|
40
|
+
* only that the opportunity exists and payment has not completed.
|
|
41
|
+
* - Once saved, quote updates for the same opportunity are blocked.
|
|
42
|
+
* - A successful save **satisfies the payment prerequisite for
|
|
43
|
+
* `finalSubmit()`** — no charge runs again at final submit, and neither
|
|
44
|
+
* `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for
|
|
45
|
+
* payment reasons.
|
|
46
|
+
*
|
|
47
|
+
* @param request - The EFT payment request with opportunityId and bank account details
|
|
48
|
+
* @returns Promise resolving to true on success
|
|
27
49
|
*/
|
|
28
50
|
saveEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>;
|
|
29
51
|
/**
|
|
@@ -28,9 +28,31 @@ class GigdbService extends base_service_1.BaseService {
|
|
|
28
28
|
return this.post('start GIGDB application', '/api/ThirdPartyGigdbApplication/start-application', request);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* Save EFT payment details for
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Save bank-account (EFT) payment details for an in-progress application.
|
|
32
|
+
*
|
|
33
|
+
* Shared endpoint — used by GIGDB, ADB, and Final Expense. Call after Start
|
|
34
|
+
* Application and before `prepareDocsAndGetDeliveryChannels()`.
|
|
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`.
|
|
40
|
+
*
|
|
41
|
+
* Business rules:
|
|
42
|
+
* - **EFT and credit card are mutually exclusive** per `opportunityId`.
|
|
43
|
+
* A successful payment that already exists (a prior EFT save, or a card
|
|
44
|
+
* that has already been charged) returns `PaymentAlreadyMade`. Afterwards,
|
|
45
|
+
* `getCcPaymentIframeUrl()` returns `EftPaymentAlreadyCompleted`.
|
|
46
|
+
* - No application-readiness gate here, unlike `getCcPaymentIframeUrl()` —
|
|
47
|
+
* only that the opportunity exists and payment has not completed.
|
|
48
|
+
* - Once saved, quote updates for the same opportunity are blocked.
|
|
49
|
+
* - A successful save **satisfies the payment prerequisite for
|
|
50
|
+
* `finalSubmit()`** — no charge runs again at final submit, and neither
|
|
51
|
+
* `paymentNotMade` nor `LatestPaymentNotSuccessful` will be returned for
|
|
52
|
+
* payment reasons.
|
|
53
|
+
*
|
|
54
|
+
* @param request - The EFT payment request with opportunityId and bank account details
|
|
55
|
+
* @returns Promise resolving to true on success
|
|
34
56
|
*/
|
|
35
57
|
async saveEftPayment(request) {
|
|
36
58
|
const result = await this.post('save EFT payment', '/api/ThirdPartyPayment/save-eft-payment', request, undefined, true // allowNullValue — API returns BaseResponse<boolean>
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { HttpClient } from '../utils/http-client';
|
|
2
|
+
import { BaseService } from './base.service';
|
|
3
|
+
import { ThirdPartyCcPaymentStatusRes, PollCcPaymentStatusOptions } from '../types/payment.types';
|
|
4
|
+
/**
|
|
5
|
+
* Credit card payment service (shared — **ADB, GIGDB, and Final Expense only**).
|
|
6
|
+
*
|
|
7
|
+
* Card capture happens in a TrustCommerce hosted iframe. The SDK never touches
|
|
8
|
+
* card data — it hands you a URL to render, then reports when capture completes.
|
|
9
|
+
*
|
|
10
|
+
* Flow (slots between Start Application and Prepare Signing Docs):
|
|
11
|
+
* 1. getIframeUrl(opportunityId) → URL to render; **persist it**
|
|
12
|
+
* 2. applicant submits the hosted form
|
|
13
|
+
* 3. pollCcPaymentStatus(...) → until `approved`
|
|
14
|
+
* 4. Secure Sign → InstaBrainClient.finalSubmit()
|
|
15
|
+
*
|
|
16
|
+
* Key rules:
|
|
17
|
+
* - **Persist and reuse the URL.** A new link is only issued once the latest
|
|
18
|
+
* attempt has `failed`. Calling {@link getIframeUrl} again while capture is
|
|
19
|
+
* `pending` **or** already `approved` returns `TcIframeLinkAlreadyGenerated`.
|
|
20
|
+
* - **EFT and credit card are mutually exclusive** per opportunity. After a
|
|
21
|
+
* successful `saveEftPayment()`, this endpoint returns `EftPaymentAlreadyCompleted`.
|
|
22
|
+
* - `'approved'` means the card was **captured**, not charged. ADB/GIGDB charge
|
|
23
|
+
* at `finalSubmit()`; for Final Expense the carrier collects after underwriting.
|
|
24
|
+
* - **Not supported for IB Term / Pure Term** — returns
|
|
25
|
+
* `CcPaymentIframeNotSupportedForProduct`. Those products use the shared EFT
|
|
26
|
+
* endpoint or hand off via their returned links.
|
|
27
|
+
*/
|
|
28
|
+
export declare class PaymentService extends BaseService {
|
|
29
|
+
constructor(httpClient: HttpClient);
|
|
30
|
+
/**
|
|
31
|
+
* Get the TrustCommerce hosted iframe URL for card capture.
|
|
32
|
+
*
|
|
33
|
+
* Call after Start Application has completed successfully and before Prepare
|
|
34
|
+
* Signing Docs. **Persist the returned URL keyed by `opportunityId`** and
|
|
35
|
+
* reuse it while {@link pollCcPaymentStatus} reports `'pending'` — requesting
|
|
36
|
+
* a second link before the current attempt fails returns
|
|
37
|
+
* `TcIframeLinkAlreadyGenerated`.
|
|
38
|
+
*
|
|
39
|
+
* Errors (all HTTP 400, each a distinct top-level code):
|
|
40
|
+
* - `InvalidRequestFormat` — `opportunityId` missing or unknown
|
|
41
|
+
* - `CcPaymentIframeNotSupportedForProduct` — product is not ADB / GIGDB / Final Expense
|
|
42
|
+
* - `ApplicationNotReady` — Start Application has not completed successfully
|
|
43
|
+
* - `EftPaymentAlreadyCompleted` — a successful EFT payment already exists
|
|
44
|
+
* - `TcIframeLinkAlreadyGenerated` — a link exists and the latest attempt has not failed
|
|
45
|
+
*
|
|
46
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
47
|
+
* @returns Promise resolving to the fully-qualified iframe URL.
|
|
48
|
+
*/
|
|
49
|
+
getIframeUrl(opportunityId: string): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Single check of credit card capture status.
|
|
52
|
+
*
|
|
53
|
+
* Rate-limited to 1 request per 10 seconds per `opportunityId`; exceeding it
|
|
54
|
+
* throws an `InstaBrainError` with `statusCode: 429`. This method does **not**
|
|
55
|
+
* auto-retry — use {@link pollCcPaymentStatus} for a managed loop.
|
|
56
|
+
*
|
|
57
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
58
|
+
* @returns Promise with the current `status` and `shouldContinuePolling`.
|
|
59
|
+
*/
|
|
60
|
+
getCcPaymentStatus(opportunityId: string): Promise<ThirdPartyCcPaymentStatusRes>;
|
|
61
|
+
/**
|
|
62
|
+
* Poll card-capture status until it resolves or the time budget is exhausted.
|
|
63
|
+
*
|
|
64
|
+
* Polls every 10s (configurable) and stops as soon as `shouldContinuePolling`
|
|
65
|
+
* is `false` — i.e. `'approved'` or `'failed'`. A `429` is transparently
|
|
66
|
+
* retried after the documented `Retry-After: 10` rather than aborting the poll.
|
|
67
|
+
*
|
|
68
|
+
* This method **never requests a new iframe URL**. On `'failed'` it returns and
|
|
69
|
+
* the caller needs to call {@link getIframeUrl} again for a fresh capture.
|
|
70
|
+
*
|
|
71
|
+
* On budget expiry it resolves with the last response (still `'pending'`)
|
|
72
|
+
* rather than throwing — inspect `status` to detect it.
|
|
73
|
+
*
|
|
74
|
+
* @param opportunityId - The `opportunityId` from the Start Application response.
|
|
75
|
+
* @param options - Optional cadence overrides.
|
|
76
|
+
* @returns Promise with the terminal response, or the last `'pending'` one on timeout.
|
|
77
|
+
*/
|
|
78
|
+
pollCcPaymentStatus(opportunityId: string, options?: PollCcPaymentStatusOptions): Promise<ThirdPartyCcPaymentStatusRes>;
|
|
79
|
+
/**
|
|
80
|
+
* Single status call that transparently retries a `429` (rate limit) after
|
|
81
|
+
* {@link RATE_LIMIT_RETRY_MS}, as long as another attempt fits within the poll
|
|
82
|
+
* deadline.
|
|
83
|
+
*
|
|
84
|
+
* When the retry budget is exhausted on a `429`, resolves with `fallback` (the
|
|
85
|
+
* last known response) rather than aborting the managed poll. If no `fallback`
|
|
86
|
+
* exists (the very first call), the `429` propagates. Any non-`429` error
|
|
87
|
+
* always propagates.
|
|
88
|
+
*/
|
|
89
|
+
private getStatusWithRateLimitRetry;
|
|
90
|
+
/**
|
|
91
|
+
* Promise-based sleep. Extracted so tests can drive polling with fake timers.
|
|
92
|
+
*/
|
|
93
|
+
protected delay(ms: number): Promise<void>;
|
|
94
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { HttpClient } from '../utils/http-client';
|
|
2
|
+
import { BaseService } from './base.service';
|
|
3
|
+
import { PivotQuotesResp, CustomizePivotQuoteReq, CustomizePivotQuoteResp, ConvertPivotToApplicationReq, ConvertPivotToApplicationResp } from '../types/pivot.types';
|
|
4
|
+
/**
|
|
5
|
+
* Pivot service — offering an alternative product after a decline.
|
|
6
|
+
*
|
|
7
|
+
* Today this covers the Final Expense → GIGDB pivot. It is not a product of its
|
|
8
|
+
* own: every call keys off an `opportunityId` that a Final Expense
|
|
9
|
+
* `startApplication()` returned alongside `isDeclined: true`.
|
|
10
|
+
*
|
|
11
|
+
* Flow:
|
|
12
|
+
* 1. getPivotQuotes(opportunityId) → alternative quote options
|
|
13
|
+
* 2. customizePivotQuote(request) → optional re-price
|
|
14
|
+
* 3. convertPivotToApplication(request) → new opportunityId on the new product
|
|
15
|
+
*
|
|
16
|
+
* **Entry condition:** Final Expense start-application returned
|
|
17
|
+
* `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
|
|
18
|
+
* no application was created and there is nothing to pivot from.
|
|
19
|
+
*
|
|
20
|
+
* After a successful conversion, leave this service behind — continue with the
|
|
21
|
+
* alternative product's own lifecycle using the new `opportunityId`.
|
|
22
|
+
*/
|
|
23
|
+
export declare class PivotService extends BaseService {
|
|
24
|
+
constructor(httpClient: HttpClient);
|
|
25
|
+
/**
|
|
26
|
+
* Get alternative-product quotes for a declined application.
|
|
27
|
+
*
|
|
28
|
+
* Only call this when Final Expense start-application returned
|
|
29
|
+
* `isDeclined: true` with a **non-zero** `opportunityId`. Do not call it for
|
|
30
|
+
* approved applications, all-zero declines, or products that do not support
|
|
31
|
+
* pivot (today, Final Expense is the only source product).
|
|
32
|
+
*
|
|
33
|
+
* Calling repeatedly for the same opportunity is safe.
|
|
34
|
+
*
|
|
35
|
+
* **Persist `quotes[n].pivotProductCode`** — it is required by both
|
|
36
|
+
* {@link customizePivotQuote} and {@link convertPivotToApplication}.
|
|
37
|
+
*
|
|
38
|
+
* Errors:
|
|
39
|
+
* - `InvalidRequestFormat` — missing/malformed/unknown `opportunityId`, or a
|
|
40
|
+
* source product that does not support pivot. Inspect `value.fields`.
|
|
41
|
+
* - `PivotNotAvailable` — the opportunity cannot be pivoted. Top-level,
|
|
42
|
+
* `value: null`. This is a business state, not a malformed request.
|
|
43
|
+
* - HTTP 403 — the `opportunityId` is not authorized for this token. No body.
|
|
44
|
+
*
|
|
45
|
+
* @param opportunityId - The non-zero `opportunityId` from the declined application.
|
|
46
|
+
* @returns Promise with `pivotReason` and the available `quotes`.
|
|
47
|
+
*/
|
|
48
|
+
getPivotQuotes(opportunityId: string): Promise<PivotQuotesResp>;
|
|
49
|
+
/**
|
|
50
|
+
* Re-price an alternative-product quote for a different coverage amount or
|
|
51
|
+
* billing frequency.
|
|
52
|
+
*
|
|
53
|
+
* Optional — only needed when the applicant wants something other than the
|
|
54
|
+
* default quote returned by {@link getPivotQuotes}. The response is a single
|
|
55
|
+
* quote item with the same shape as one element of that list.
|
|
56
|
+
*
|
|
57
|
+
* This does **not** persist the choice. `convertPivotToApplication()` still
|
|
58
|
+
* requires `faceAmount` and `paymentFreq` to be sent explicitly.
|
|
59
|
+
*
|
|
60
|
+
* Errors:
|
|
61
|
+
* - `InvalidRequestFormat` — missing/malformed body fields, unknown
|
|
62
|
+
* `opportunityId`, or an invalid `pivotProductCode`.
|
|
63
|
+
* - `CoverageNotAvailable` — `faceAmount` is outside the alternative
|
|
64
|
+
* product's range or off its required increment (GIGDB: $5,000–$25,000 in
|
|
65
|
+
* $1,000 steps). Top-level, `value: null`.
|
|
66
|
+
* - `PivotNotAvailable` — the opportunity cannot be pivoted, or pricing
|
|
67
|
+
* could not produce a quote. Top-level, `value: null`.
|
|
68
|
+
* - HTTP 403 — `opportunityId` not authorized for this token.
|
|
69
|
+
*
|
|
70
|
+
* @param request - Opportunity, product code, and the desired coverage / frequency.
|
|
71
|
+
* @returns Promise with the recalculated quote.
|
|
72
|
+
*/
|
|
73
|
+
customizePivotQuote(request: CustomizePivotQuoteReq): Promise<CustomizePivotQuoteResp>;
|
|
74
|
+
/**
|
|
75
|
+
* Create the alternative-product application.
|
|
76
|
+
*
|
|
77
|
+
* Call only once the applicant has confirmed the coverage amount and payment
|
|
78
|
+
* frequency they want. `faceAmount` and `paymentFreq` are required on every
|
|
79
|
+
* call — they are not inherited from a prior {@link customizePivotQuote}.
|
|
80
|
+
*
|
|
81
|
+
* **The returned `opportunityId` is new** and belongs to the alternative
|
|
82
|
+
* product. Persist it and use it for everything that follows; the Final
|
|
83
|
+
* Expense id is finished at this point.
|
|
84
|
+
*
|
|
85
|
+
* The response carries no premium by design. Call the alternative product's
|
|
86
|
+
* own get-existing-quote with the new id to read the current amount, then
|
|
87
|
+
* continue that product's normal lifecycle.
|
|
88
|
+
*
|
|
89
|
+
* **Do not retry after a successful conversion** — a second attempt on the
|
|
90
|
+
* same opportunity returns `PivotNotAvailable`.
|
|
91
|
+
*
|
|
92
|
+
* Errors:
|
|
93
|
+
* - `InvalidRequestFormat` — missing/malformed body fields, unknown
|
|
94
|
+
* `opportunityId` (`OpportunityId does not exist.`), unsupported product,
|
|
95
|
+
* or an invalid `pivotProductCode`.
|
|
96
|
+
* - `CoverageNotAvailable` — `faceAmount` outside range or off-increment.
|
|
97
|
+
* - `PivotNotAvailable` — no longer fit to pivot, e.g. already converted.
|
|
98
|
+
* - HTTP 403 — `opportunityId` not authorized for this token.
|
|
99
|
+
*
|
|
100
|
+
* @param request - Opportunity, product code, and confirmed coverage / frequency.
|
|
101
|
+
* @returns Promise with the new `opportunityId` and its `productCode`.
|
|
102
|
+
*/
|
|
103
|
+
convertPivotToApplication(request: ConvertPivotToApplicationReq): Promise<ConvertPivotToApplicationResp>;
|
|
104
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PivotService = void 0;
|
|
4
|
+
const base_service_1 = require("./base.service");
|
|
5
|
+
/**
|
|
6
|
+
* Pivot service — offering an alternative product after a decline.
|
|
7
|
+
*
|
|
8
|
+
* Today this covers the Final Expense → GIGDB pivot. It is not a product of its
|
|
9
|
+
* own: every call keys off an `opportunityId` that a Final Expense
|
|
10
|
+
* `startApplication()` returned alongside `isDeclined: true`.
|
|
11
|
+
*
|
|
12
|
+
* Flow:
|
|
13
|
+
* 1. getPivotQuotes(opportunityId) → alternative quote options
|
|
14
|
+
* 2. customizePivotQuote(request) → optional re-price
|
|
15
|
+
* 3. convertPivotToApplication(request) → new opportunityId on the new product
|
|
16
|
+
*
|
|
17
|
+
* **Entry condition:** Final Expense start-application returned
|
|
18
|
+
* `isDeclined: true` with a **non-zero** `opportunityId`. An all-zero id means
|
|
19
|
+
* no application was created and there is nothing to pivot from.
|
|
20
|
+
*
|
|
21
|
+
* After a successful conversion, leave this service behind — continue with the
|
|
22
|
+
* alternative product's own lifecycle using the new `opportunityId`.
|
|
23
|
+
*/
|
|
24
|
+
class PivotService extends base_service_1.BaseService {
|
|
25
|
+
constructor(httpClient) {
|
|
26
|
+
super(httpClient);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get alternative-product quotes for a declined application.
|
|
30
|
+
*
|
|
31
|
+
* Only call this when Final Expense start-application returned
|
|
32
|
+
* `isDeclined: true` with a **non-zero** `opportunityId`. Do not call it for
|
|
33
|
+
* approved applications, all-zero declines, or products that do not support
|
|
34
|
+
* pivot (today, Final Expense is the only source product).
|
|
35
|
+
*
|
|
36
|
+
* Calling repeatedly for the same opportunity is safe.
|
|
37
|
+
*
|
|
38
|
+
* **Persist `quotes[n].pivotProductCode`** — it is required by both
|
|
39
|
+
* {@link customizePivotQuote} and {@link convertPivotToApplication}.
|
|
40
|
+
*
|
|
41
|
+
* Errors:
|
|
42
|
+
* - `InvalidRequestFormat` — missing/malformed/unknown `opportunityId`, or a
|
|
43
|
+
* source product that does not support pivot. Inspect `value.fields`.
|
|
44
|
+
* - `PivotNotAvailable` — the opportunity cannot be pivoted. Top-level,
|
|
45
|
+
* `value: null`. This is a business state, not a malformed request.
|
|
46
|
+
* - HTTP 403 — the `opportunityId` is not authorized for this token. No body.
|
|
47
|
+
*
|
|
48
|
+
* @param opportunityId - The non-zero `opportunityId` from the declined application.
|
|
49
|
+
* @returns Promise with `pivotReason` and the available `quotes`.
|
|
50
|
+
*/
|
|
51
|
+
async getPivotQuotes(opportunityId) {
|
|
52
|
+
return this.get('get pivot quotes', '/api/ThirdPartyPivot/get-pivot-quotes', {
|
|
53
|
+
params: { opportunityId },
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Re-price an alternative-product quote for a different coverage amount or
|
|
58
|
+
* billing frequency.
|
|
59
|
+
*
|
|
60
|
+
* Optional — only needed when the applicant wants something other than the
|
|
61
|
+
* default quote returned by {@link getPivotQuotes}. The response is a single
|
|
62
|
+
* quote item with the same shape as one element of that list.
|
|
63
|
+
*
|
|
64
|
+
* This does **not** persist the choice. `convertPivotToApplication()` still
|
|
65
|
+
* requires `faceAmount` and `paymentFreq` to be sent explicitly.
|
|
66
|
+
*
|
|
67
|
+
* Errors:
|
|
68
|
+
* - `InvalidRequestFormat` — missing/malformed body fields, unknown
|
|
69
|
+
* `opportunityId`, or an invalid `pivotProductCode`.
|
|
70
|
+
* - `CoverageNotAvailable` — `faceAmount` is outside the alternative
|
|
71
|
+
* product's range or off its required increment (GIGDB: $5,000–$25,000 in
|
|
72
|
+
* $1,000 steps). Top-level, `value: null`.
|
|
73
|
+
* - `PivotNotAvailable` — the opportunity cannot be pivoted, or pricing
|
|
74
|
+
* could not produce a quote. Top-level, `value: null`.
|
|
75
|
+
* - HTTP 403 — `opportunityId` not authorized for this token.
|
|
76
|
+
*
|
|
77
|
+
* @param request - Opportunity, product code, and the desired coverage / frequency.
|
|
78
|
+
* @returns Promise with the recalculated quote.
|
|
79
|
+
*/
|
|
80
|
+
async customizePivotQuote(request) {
|
|
81
|
+
return this.post('customize pivot quote', '/api/ThirdPartyPivot/customize-pivot-quote', request);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create the alternative-product application.
|
|
85
|
+
*
|
|
86
|
+
* Call only once the applicant has confirmed the coverage amount and payment
|
|
87
|
+
* frequency they want. `faceAmount` and `paymentFreq` are required on every
|
|
88
|
+
* call — they are not inherited from a prior {@link customizePivotQuote}.
|
|
89
|
+
*
|
|
90
|
+
* **The returned `opportunityId` is new** and belongs to the alternative
|
|
91
|
+
* product. Persist it and use it for everything that follows; the Final
|
|
92
|
+
* Expense id is finished at this point.
|
|
93
|
+
*
|
|
94
|
+
* The response carries no premium by design. Call the alternative product's
|
|
95
|
+
* own get-existing-quote with the new id to read the current amount, then
|
|
96
|
+
* continue that product's normal lifecycle.
|
|
97
|
+
*
|
|
98
|
+
* **Do not retry after a successful conversion** — a second attempt on the
|
|
99
|
+
* same opportunity returns `PivotNotAvailable`.
|
|
100
|
+
*
|
|
101
|
+
* Errors:
|
|
102
|
+
* - `InvalidRequestFormat` — missing/malformed body fields, unknown
|
|
103
|
+
* `opportunityId` (`OpportunityId does not exist.`), unsupported product,
|
|
104
|
+
* or an invalid `pivotProductCode`.
|
|
105
|
+
* - `CoverageNotAvailable` — `faceAmount` outside range or off-increment.
|
|
106
|
+
* - `PivotNotAvailable` — no longer fit to pivot, e.g. already converted.
|
|
107
|
+
* - HTTP 403 — `opportunityId` not authorized for this token.
|
|
108
|
+
*
|
|
109
|
+
* @param request - Opportunity, product code, and confirmed coverage / frequency.
|
|
110
|
+
* @returns Promise with the new `opportunityId` and its `productCode`.
|
|
111
|
+
*/
|
|
112
|
+
async convertPivotToApplication(request) {
|
|
113
|
+
return this.post('convert pivot to application', '/api/ThirdPartyPivot/convert-pivot-to-application', request);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.PivotService = PivotService;
|