@instabrain-sdks/api-client 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +1228 -348
  2. package/dist/client/instabrain-client.d.ts +34 -2
  3. package/dist/client/instabrain-client.js +42 -1
  4. package/dist/index.d.ts +0 -1
  5. package/dist/index.js +0 -1
  6. package/dist/services/adb.service.d.ts +48 -0
  7. package/dist/services/adb.service.js +64 -0
  8. package/dist/services/application.service.d.ts +2 -3
  9. package/dist/services/application.service.js +5 -52
  10. package/dist/services/auth.service.d.ts +0 -1
  11. package/dist/services/auth.service.js +0 -1
  12. package/dist/services/base.service.d.ts +45 -0
  13. package/dist/services/base.service.js +92 -0
  14. package/dist/services/gigdb.service.d.ts +2 -3
  15. package/dist/services/gigdb.service.js +12 -133
  16. package/dist/services/quote.service.d.ts +2 -3
  17. package/dist/services/quote.service.js +4 -35
  18. package/dist/services/reports.service.d.ts +2 -3
  19. package/dist/services/reports.service.js +6 -86
  20. package/dist/services/secure-sign.service.d.ts +2 -3
  21. package/dist/services/secure-sign.service.js +7 -109
  22. package/dist/types/adb.types.d.ts +119 -0
  23. package/dist/types/adb.types.js +2 -0
  24. package/dist/types/application.types.d.ts +0 -1
  25. package/dist/types/application.types.js +0 -1
  26. package/dist/types/auth.types.d.ts +0 -1
  27. package/dist/types/auth.types.js +0 -1
  28. package/dist/types/beneficiary.types.d.ts +54 -0
  29. package/dist/types/beneficiary.types.js +2 -0
  30. package/dist/types/constants.d.ts +0 -1
  31. package/dist/types/constants.js +0 -1
  32. package/dist/types/enums.d.ts +379 -5
  33. package/dist/types/enums.js +392 -8
  34. package/dist/types/errors.d.ts +0 -1
  35. package/dist/types/errors.js +0 -1
  36. package/dist/types/gigdb.types.d.ts +3 -17
  37. package/dist/types/gigdb.types.js +0 -1
  38. package/dist/types/index.d.ts +2 -1
  39. package/dist/types/index.js +2 -1
  40. package/dist/types/quote.types.d.ts +0 -1
  41. package/dist/types/quote.types.js +0 -1
  42. package/dist/types/reports.types.d.ts +0 -1
  43. package/dist/types/reports.types.js +0 -1
  44. package/dist/types/secure-sign.types.d.ts +0 -1
  45. package/dist/types/secure-sign.types.js +0 -1
  46. package/dist/utils/error-utils.d.ts +0 -1
  47. package/dist/utils/error-utils.js +0 -1
  48. package/dist/utils/http-client.d.ts +0 -1
  49. package/dist/utils/http-client.js +0 -4
  50. package/package.json +2 -2
@@ -3,8 +3,9 @@ import { QuoteService } from '../services/quote.service';
3
3
  import { ApplicationService } from '../services/application.service';
4
4
  import { ReportsService } from '../services/reports.service';
5
5
  import { GigdbService } from '../services/gigdb.service';
6
+ import { AdbService } from '../services/adb.service';
6
7
  import { SecureSignService } from '../services/secure-sign.service';
7
- import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
8
+ import { InstaBrainConfig, Environment, ThirdPartyQuoteReq, ThirdPartyQuoteResp, ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, AgentPortalReq, ThirdPartyProspectsResp, ThirdPartySalesReportRes, ThirdPartyApplicationReportRes, ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyAdbQuoteRequest, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, AdbRiderDetailsResp, ThirdPartySendPinReq, ThirdPartyResendPinReq, ThirdPartyVerifyPinReq, ThirdPartyPrepareDocsResp, ThirdPartySendPinResp, ThirdPartyResendPinResp, ThirdPartyVerifyPinResp, ThirdPartyFinalSubmitResp } from '../types';
8
9
  /**
9
10
  * Main InstaBrain SDK client
10
11
  */
@@ -15,6 +16,7 @@ export declare class InstaBrainClient {
15
16
  readonly application: ApplicationService;
16
17
  readonly reports: ReportsService;
17
18
  readonly gigdb: GigdbService;
19
+ readonly adb: AdbService;
18
20
  readonly secureSign: SecureSignService;
19
21
  constructor(config?: InstaBrainConfig);
20
22
  /**
@@ -92,6 +94,37 @@ export declare class InstaBrainClient {
92
94
  * @returns Promise with the current quote response
93
95
  */
94
96
  getExistingGigdbQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
97
+ /**
98
+ * Get an ADB (Accidental Death Benefit) insurance quote (ages 20-59)
99
+ * @param request - The ADB quote request parameters
100
+ * @returns Promise with the quote response containing quoteResponseId
101
+ */
102
+ getAdbQuote(request: ThirdPartyAdbQuoteRequest): Promise<ThirdPartyQuoteResp>;
103
+ /**
104
+ * Start an ADB application from a quote
105
+ * Note: isDeclined=true is a valid success response (knockout), not an error.
106
+ * Knockout conditions: isPayerAlsoOwnerAndInsured=false, or isUsCitizen=false AND isLegalUsResident=false.
107
+ * After this, call saveAdbEftPayment() then the shared SecureSign flow then finalSubmit().
108
+ * @param request - The ADB application request parameters
109
+ * @returns Promise with opportunityId and isDeclined flag
110
+ */
111
+ startAdbApplication(request: ThirdPartyAdbAppReq): Promise<ThirdPartyAdbStartAppResp>;
112
+ /**
113
+ * Save EFT payment details for an ADB application
114
+ * Must be called after startAdbApplication (when not declined) and before the SecureSign flow.
115
+ * @param request - The EFT payment request with opportunityId and bank account details
116
+ * @returns Promise resolving to true on success
117
+ */
118
+ saveAdbEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>;
119
+ /**
120
+ * Get available riders for the ADB product in a given US state.
121
+ * Call this before getAdbQuote() to check if ADB is available in the state
122
+ * and to collect riderCodes to include in the quote request.
123
+ * CA is not a supported state.
124
+ * @param stateCode - Two-letter US state abbreviation (e.g. "AZ")
125
+ * @returns Promise with riders list and product availability flag
126
+ */
127
+ getAdbRiderDetails(stateCode: string): Promise<AdbRiderDetailsResp>;
95
128
  /**
96
129
  * Prepare the signing package and check available delivery channels
97
130
  * Always call this first in the signing flow. If isSignCompleted is true, skip to finalSubmit().
@@ -152,4 +185,3 @@ export declare class InstaBrainClient {
152
185
  */
153
186
  getBaseUrl(): string;
154
187
  }
155
- //# sourceMappingURL=instabrain-client.d.ts.map
@@ -7,6 +7,7 @@ const quote_service_1 = require("../services/quote.service");
7
7
  const application_service_1 = require("../services/application.service");
8
8
  const reports_service_1 = require("../services/reports.service");
9
9
  const gigdb_service_1 = require("../services/gigdb.service");
10
+ const adb_service_1 = require("../services/adb.service");
10
11
  const secure_sign_service_1 = require("../services/secure-sign.service");
11
12
  /**
12
13
  * Main InstaBrain SDK client
@@ -19,6 +20,7 @@ class InstaBrainClient {
19
20
  this.application = new application_service_1.ApplicationService(this.httpClient);
20
21
  this.reports = new reports_service_1.ReportsService(this.httpClient);
21
22
  this.gigdb = new gigdb_service_1.GigdbService(this.httpClient);
23
+ this.adb = new adb_service_1.AdbService(this.httpClient);
22
24
  this.secureSign = new secure_sign_service_1.SecureSignService(this.httpClient);
23
25
  }
24
26
  /**
@@ -125,6 +127,46 @@ class InstaBrainClient {
125
127
  async getExistingGigdbQuote(opportunityId) {
126
128
  return this.gigdb.getExistingQuote(opportunityId);
127
129
  }
130
+ // ── ADB Methods ────────────────────────────────────────────────────
131
+ /**
132
+ * Get an ADB (Accidental Death Benefit) insurance quote (ages 20-59)
133
+ * @param request - The ADB quote request parameters
134
+ * @returns Promise with the quote response containing quoteResponseId
135
+ */
136
+ async getAdbQuote(request) {
137
+ return this.adb.getQuote(request);
138
+ }
139
+ /**
140
+ * Start an ADB application from a quote
141
+ * Note: isDeclined=true is a valid success response (knockout), not an error.
142
+ * Knockout conditions: isPayerAlsoOwnerAndInsured=false, or isUsCitizen=false AND isLegalUsResident=false.
143
+ * After this, call saveAdbEftPayment() then the shared SecureSign flow then finalSubmit().
144
+ * @param request - The ADB application request parameters
145
+ * @returns Promise with opportunityId and isDeclined flag
146
+ */
147
+ async startAdbApplication(request) {
148
+ return this.adb.startApplication(request);
149
+ }
150
+ /**
151
+ * Save EFT payment details for an ADB application
152
+ * Must be called after startAdbApplication (when not declined) and before the SecureSign flow.
153
+ * @param request - The EFT payment request with opportunityId and bank account details
154
+ * @returns Promise resolving to true on success
155
+ */
156
+ async saveAdbEftPayment(request) {
157
+ return this.adb.saveEftPayment(request);
158
+ }
159
+ /**
160
+ * Get available riders for the ADB product in a given US state.
161
+ * Call this before getAdbQuote() to check if ADB is available in the state
162
+ * and to collect riderCodes to include in the quote request.
163
+ * CA is not a supported state.
164
+ * @param stateCode - Two-letter US state abbreviation (e.g. "AZ")
165
+ * @returns Promise with riders list and product availability flag
166
+ */
167
+ async getAdbRiderDetails(stateCode) {
168
+ return this.adb.getRiderDetails(stateCode);
169
+ }
128
170
  // ── Secure Sign Methods ─────────────────────────────────────────────
129
171
  /**
130
172
  * Prepare the signing package and check available delivery channels
@@ -208,4 +250,3 @@ class InstaBrainClient {
208
250
  }
209
251
  }
210
252
  exports.InstaBrainClient = InstaBrainClient;
211
- //# sourceMappingURL=instabrain-client.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export { InstaBrainClient } from './client/instabrain-client';
2
2
  export * from './types';
3
3
  export { InstaBrainClient as default } from './client/instabrain-client';
4
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -23,4 +23,3 @@ __exportStar(require("./types"), exports);
23
23
  // Default export
24
24
  var instabrain_client_2 = require("./client/instabrain-client");
25
25
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return instabrain_client_2.InstaBrainClient; } });
26
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,48 @@
1
+ import { HttpClient } from '../utils/http-client';
2
+ import { BaseService } from './base.service';
3
+ import { ThirdPartyAdbQuoteRequest, ThirdPartyAdbAppReq, ThirdPartyAdbStartAppResp, ThirdPartyQuoteResp, ThirdPartyEftPaymentReq, AdbRiderDetailsResp } from '../types';
4
+ /**
5
+ * ADB (Accidental Death Benefit) service
6
+ * Handles quote, application, and EFT payment for the ADB product (ages 20-59)
7
+ * Distributed through Fidelity Life — no medical exam required
8
+ *
9
+ * Flow:
10
+ * 1. getQuote() → quoteResponseId
11
+ * 2. startApplication() → opportunityId (or isDeclined=true)
12
+ * 3. saveEftPayment() → true (payment recorded)
13
+ * 4. SecureSign flow → (shared — use SecureSignService)
14
+ * 5. Final Submit → (shared — use ApplicationService.finalSubmit)
15
+ */
16
+ export declare class AdbService extends BaseService {
17
+ constructor(httpClient: HttpClient);
18
+ /**
19
+ * Get an ADB insurance quote
20
+ * @param request - The ADB quote request (ages 20-59)
21
+ * @returns Promise with the quote response containing quoteResponseId
22
+ */
23
+ getQuote(request: ThirdPartyAdbQuoteRequest): Promise<ThirdPartyQuoteResp>;
24
+ /**
25
+ * Start an ADB application from a quote
26
+ * Note: isDeclined=true is a valid success response (knockout), not an error.
27
+ * Knockout conditions:
28
+ * - isPayerAlsoOwnerAndInsured = false
29
+ * - isUsCitizen = false AND isLegalUsResident = false
30
+ * @param request - The ADB application request parameters
31
+ * @returns Promise with opportunityId and isDeclined flag
32
+ */
33
+ startApplication(request: ThirdPartyAdbAppReq): Promise<ThirdPartyAdbStartAppResp>;
34
+ /**
35
+ * Get available riders for the ADB product in a given state.
36
+ * Call before getQuote() to check state availability and collect rider codes.
37
+ * @param stateCode - Two-letter US state abbreviation (e.g. "AZ"). CA is not supported.
38
+ * @returns Promise with riders list and flagProductNotAvailableForState flag
39
+ */
40
+ getRiderDetails(stateCode: string): Promise<AdbRiderDetailsResp>;
41
+ /**
42
+ * Save EFT payment details for an ADB application
43
+ * Must be called after startApplication and before the SecureSign flow.
44
+ * @param request - The EFT payment request with opportunityId and bank account details
45
+ * @returns Promise resolving to true on success
46
+ */
47
+ saveEftPayment(request: ThirdPartyEftPaymentReq): Promise<boolean>;
48
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AdbService = void 0;
4
+ const base_service_1 = require("./base.service");
5
+ /**
6
+ * ADB (Accidental Death Benefit) service
7
+ * Handles quote, application, and EFT payment for the ADB product (ages 20-59)
8
+ * Distributed through Fidelity Life — no medical exam required
9
+ *
10
+ * Flow:
11
+ * 1. getQuote() → quoteResponseId
12
+ * 2. startApplication() → opportunityId (or isDeclined=true)
13
+ * 3. saveEftPayment() → true (payment recorded)
14
+ * 4. SecureSign flow → (shared — use SecureSignService)
15
+ * 5. Final Submit → (shared — use ApplicationService.finalSubmit)
16
+ */
17
+ class AdbService extends base_service_1.BaseService {
18
+ constructor(httpClient) {
19
+ super(httpClient);
20
+ }
21
+ /**
22
+ * Get an ADB insurance quote
23
+ * @param request - The ADB quote request (ages 20-59)
24
+ * @returns Promise with the quote response containing quoteResponseId
25
+ */
26
+ async getQuote(request) {
27
+ return this.post('get ADB quote', '/api/ThirdPartyIbAdbQuote/get', request);
28
+ }
29
+ /**
30
+ * Start an ADB application from a quote
31
+ * Note: isDeclined=true is a valid success response (knockout), not an error.
32
+ * Knockout conditions:
33
+ * - isPayerAlsoOwnerAndInsured = false
34
+ * - isUsCitizen = false AND isLegalUsResident = false
35
+ * @param request - The ADB application request parameters
36
+ * @returns Promise with opportunityId and isDeclined flag
37
+ */
38
+ async startApplication(request) {
39
+ return this.post('start ADB application', '/api/ThirdPartyAdbApplication/start-application', request);
40
+ }
41
+ /**
42
+ * Get available riders for the ADB product in a given state.
43
+ * Call before getQuote() to check state availability and collect rider codes.
44
+ * @param stateCode - Two-letter US state abbreviation (e.g. "AZ"). CA is not supported.
45
+ * @returns Promise with riders list and flagProductNotAvailableForState flag
46
+ */
47
+ async getRiderDetails(stateCode) {
48
+ return this.get('get ADB rider details', '/api/ThirdPartyAdbLookup/get-rider-details', {
49
+ params: { stateCode },
50
+ });
51
+ }
52
+ /**
53
+ * Save EFT payment details for an ADB application
54
+ * Must be called after startApplication and before the SecureSign flow.
55
+ * @param request - The EFT payment request with opportunityId and bank account details
56
+ * @returns Promise resolving to true on success
57
+ */
58
+ async saveEftPayment(request) {
59
+ const result = await this.post('save ADB EFT payment', '/api/ThirdPartyPayment/save-eft-payment', request, undefined, true // allowNullValue — API returns BaseResponse<boolean>
60
+ );
61
+ return result !== null && result !== void 0 ? result : true;
62
+ }
63
+ }
64
+ exports.AdbService = AdbService;
@@ -1,10 +1,10 @@
1
1
  import { HttpClient } from '../utils/http-client';
2
+ import { BaseService } from './base.service';
2
3
  import { ThirdPartyStartApplicationReq, ThirdPartyStartAppResp, ThirdPartyFinalSubmitResp } from '../types';
3
4
  /**
4
5
  * Application service for starting insurance applications from quotes
5
6
  */
6
- export declare class ApplicationService {
7
- private readonly httpClient;
7
+ export declare class ApplicationService extends BaseService {
8
8
  constructor(httpClient: HttpClient);
9
9
  /**
10
10
  * Start an insurance application based on a quote response ID
@@ -21,4 +21,3 @@ export declare class ApplicationService {
21
21
  */
22
22
  finalSubmit(opportunityId: string): Promise<ThirdPartyFinalSubmitResp>;
23
23
  }
24
- //# sourceMappingURL=application.service.d.ts.map
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApplicationService = void 0;
4
- const error_utils_1 = require("../utils/error-utils");
5
- const types_1 = require("../types");
4
+ const base_service_1 = require("./base.service");
6
5
  /**
7
6
  * Application service for starting insurance applications from quotes
8
7
  */
9
- class ApplicationService {
8
+ class ApplicationService extends base_service_1.BaseService {
10
9
  constructor(httpClient) {
11
- this.httpClient = httpClient;
10
+ super(httpClient);
12
11
  }
13
12
  /**
14
13
  * Start an insurance application based on a quote response ID
@@ -16,27 +15,7 @@ class ApplicationService {
16
15
  * @returns Promise with the application response containing links
17
16
  */
18
17
  async startApplication(applicationRequest) {
19
- // Check if authenticated
20
- if (!this.httpClient.isAuthenticated()) {
21
- throw new types_1.AuthenticationError('Must be authenticated to start applications. Call authenticate() first.');
22
- }
23
- try {
24
- const response = await this.httpClient.post('/api/ThirdPartyIbTermStartApp/start-application', applicationRequest);
25
- // Check if the response was successful
26
- if (!response.flagStatus) {
27
- throw new types_1.InstaBrainError(response.error || 'Failed to start application');
28
- }
29
- if (!response.value) {
30
- throw new types_1.InstaBrainError('No application data received from server');
31
- }
32
- return response.value;
33
- }
34
- catch (error) {
35
- if (error instanceof types_1.InstaBrainError) {
36
- throw error;
37
- }
38
- throw new types_1.InstaBrainError('Failed to start application: ' + error.message);
39
- }
18
+ return this.post('start application', '/api/ThirdPartyIbTermStartApp/start-application', applicationRequest);
40
19
  }
41
20
  /**
42
21
  * Submit the application to the carrier for a final underwriting decision
@@ -46,33 +25,7 @@ class ApplicationService {
46
25
  * @returns Promise with the final submit response containing policyNumber
47
26
  */
48
27
  async finalSubmit(opportunityId) {
49
- if (!this.httpClient.isAuthenticated()) {
50
- throw new types_1.AuthenticationError('Must be authenticated to submit application. Call authenticate() first.');
51
- }
52
- try {
53
- const response = await this.httpClient.post('/api/ThirdPartyApplication/final-submit', null, { params: { opportunityId } });
54
- if (!response.flagStatus) {
55
- const errorMessage = response.error || 'Failed to submit application';
56
- const errorCode = (0, error_utils_1.extractErrorCode)(response);
57
- if (errorCode) {
58
- throw new types_1.APIValidationError(errorMessage, errorCode, response);
59
- }
60
- else {
61
- throw new types_1.InstaBrainError(errorMessage, 400, response);
62
- }
63
- }
64
- if (!response.value) {
65
- throw new types_1.InstaBrainError('No final submit data received from server');
66
- }
67
- return response.value;
68
- }
69
- catch (error) {
70
- if (error instanceof types_1.InstaBrainError) {
71
- throw error;
72
- }
73
- throw new types_1.InstaBrainError('Failed to submit application: ' + error.message);
74
- }
28
+ return this.post('submit application', '/api/ThirdPartyApplication/final-submit', null, { params: { opportunityId } });
75
29
  }
76
30
  }
77
31
  exports.ApplicationService = ApplicationService;
78
- //# sourceMappingURL=application.service.js.map
@@ -32,4 +32,3 @@ export declare class AuthService {
32
32
  */
33
33
  setToken(token: string): void;
34
34
  }
35
- //# sourceMappingURL=auth.service.d.ts.map
@@ -71,4 +71,3 @@ class AuthService {
71
71
  }
72
72
  }
73
73
  exports.AuthService = AuthService;
74
- //# sourceMappingURL=auth.service.js.map
@@ -0,0 +1,45 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { HttpClient } from '../utils/http-client';
3
+ /**
4
+ * Base service class that provides shared request execution logic.
5
+ * All API services extend this to eliminate duplicated auth checks,
6
+ * response validation, error extraction, and catch wrapping.
7
+ */
8
+ export declare abstract class BaseService {
9
+ protected readonly httpClient: HttpClient;
10
+ constructor(httpClient: HttpClient);
11
+ /**
12
+ * Ensure the client is authenticated before making an API call.
13
+ * @param action - Human-readable action name for the error message
14
+ */
15
+ protected requireAuth(action: string): void;
16
+ /**
17
+ * Execute a POST request with standard response handling.
18
+ * Handles: auth check, flagStatus validation, error code extraction, value null check, and error wrapping.
19
+ *
20
+ * @param action - Human-readable action name (e.g. "get quote")
21
+ * @param url - API endpoint path
22
+ * @param data - Request body (null for query-param-only calls)
23
+ * @param config - Optional Axios config (e.g. { params: { opportunityId } })
24
+ * @param allowNullValue - If true, skips the null-value check (used by saveEftPayment)
25
+ * @returns The response value of type T
26
+ */
27
+ protected post<T>(action: string, url: string, data: unknown, config?: AxiosRequestConfig, allowNullValue?: boolean): Promise<T>;
28
+ /**
29
+ * Execute a GET request with standard response handling.
30
+ *
31
+ * @param action - Human-readable action name
32
+ * @param url - API endpoint path
33
+ * @param config - Optional Axios config (e.g. { params: { opportunityId } })
34
+ * @returns The response value of type T
35
+ */
36
+ protected get<T>(action: string, url: string, config?: AxiosRequestConfig): Promise<T>;
37
+ /**
38
+ * Validate an API response: check flagStatus, extract error codes, and verify value.
39
+ */
40
+ private handleResponse;
41
+ /**
42
+ * Re-throw InstaBrainError subclasses as-is; wrap anything else.
43
+ */
44
+ private rethrowOrWrap;
45
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseService = void 0;
4
+ const error_utils_1 = require("../utils/error-utils");
5
+ const types_1 = require("../types");
6
+ /**
7
+ * Base service class that provides shared request execution logic.
8
+ * All API services extend this to eliminate duplicated auth checks,
9
+ * response validation, error extraction, and catch wrapping.
10
+ */
11
+ class BaseService {
12
+ constructor(httpClient) {
13
+ this.httpClient = httpClient;
14
+ }
15
+ /**
16
+ * Ensure the client is authenticated before making an API call.
17
+ * @param action - Human-readable action name for the error message
18
+ */
19
+ requireAuth(action) {
20
+ if (!this.httpClient.isAuthenticated()) {
21
+ throw new types_1.AuthenticationError(`Must be authenticated to ${action}. Call authenticate() first.`);
22
+ }
23
+ }
24
+ /**
25
+ * Execute a POST request with standard response handling.
26
+ * Handles: auth check, flagStatus validation, error code extraction, value null check, and error wrapping.
27
+ *
28
+ * @param action - Human-readable action name (e.g. "get quote")
29
+ * @param url - API endpoint path
30
+ * @param data - Request body (null for query-param-only calls)
31
+ * @param config - Optional Axios config (e.g. { params: { opportunityId } })
32
+ * @param allowNullValue - If true, skips the null-value check (used by saveEftPayment)
33
+ * @returns The response value of type T
34
+ */
35
+ async post(action, url, data, config, allowNullValue = false) {
36
+ this.requireAuth(action);
37
+ try {
38
+ const response = await this.httpClient.post(url, data, config);
39
+ return this.handleResponse(response, action, allowNullValue);
40
+ }
41
+ catch (error) {
42
+ this.rethrowOrWrap(error, action);
43
+ }
44
+ }
45
+ /**
46
+ * Execute a GET request with standard response handling.
47
+ *
48
+ * @param action - Human-readable action name
49
+ * @param url - API endpoint path
50
+ * @param config - Optional Axios config (e.g. { params: { opportunityId } })
51
+ * @returns The response value of type T
52
+ */
53
+ async get(action, url, config) {
54
+ this.requireAuth(action);
55
+ try {
56
+ const response = await this.httpClient.get(url, config);
57
+ return this.handleResponse(response, action);
58
+ }
59
+ catch (error) {
60
+ this.rethrowOrWrap(error, action);
61
+ }
62
+ }
63
+ /**
64
+ * Validate an API response: check flagStatus, extract error codes, and verify value.
65
+ */
66
+ handleResponse(response, action, allowNullValue = false) {
67
+ if (!response.flagStatus) {
68
+ const errorMessage = response.error || `Failed to ${action}`;
69
+ const errorCode = (0, error_utils_1.extractErrorCode)(response);
70
+ if (errorCode) {
71
+ throw new types_1.APIValidationError(errorMessage, errorCode, response);
72
+ }
73
+ else {
74
+ throw new types_1.InstaBrainError(errorMessage, 400, response);
75
+ }
76
+ }
77
+ if (!allowNullValue && !response.value) {
78
+ throw new types_1.InstaBrainError(`No ${action} data received from server`);
79
+ }
80
+ return response.value;
81
+ }
82
+ /**
83
+ * Re-throw InstaBrainError subclasses as-is; wrap anything else.
84
+ */
85
+ rethrowOrWrap(error, action) {
86
+ if (error instanceof types_1.InstaBrainError) {
87
+ throw error;
88
+ }
89
+ throw new types_1.InstaBrainError(`Failed to ${action}: ${error.message}`);
90
+ }
91
+ }
92
+ exports.BaseService = BaseService;
@@ -1,11 +1,11 @@
1
1
  import { HttpClient } from '../utils/http-client';
2
+ import { BaseService } from './base.service';
2
3
  import { ThirdPartyGigdbQuoteRequest, ThirdPartyGigdbUpdateQuoteReq, ThirdPartyGigdbAppReq, ThirdPartyEftPaymentReq, ThirdPartyQuoteResp, ThirdPartyStartAppResp } from '../types';
3
4
  /**
4
5
  * GIGDB (Guaranteed Issue Group Decreasing Benefit) service
5
6
  * Handles quote, application, and EFT payment for the GIGDB product (ages 50-85, $5k-$25k)
6
7
  */
7
- export declare class GigdbService {
8
- private readonly httpClient;
8
+ export declare class GigdbService extends BaseService {
9
9
  constructor(httpClient: HttpClient);
10
10
  /**
11
11
  * Get a GIGDB insurance quote
@@ -41,4 +41,3 @@ export declare class GigdbService {
41
41
  */
42
42
  getExistingQuote(opportunityId: string): Promise<ThirdPartyQuoteResp>;
43
43
  }
44
- //# sourceMappingURL=gigdb.service.d.ts.map