@healthcloudai/hc-settings-connector 0.0.14 → 0.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.
package/dist/index.cjs CHANGED
@@ -20,36 +20,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- AuthError: () => AuthError,
24
- ConfigError: () => ConfigError,
23
+ APIError: () => import_hc_http2.APIError,
24
+ ConfigError: () => import_hc_http2.ConfigError,
25
+ HCServiceError: () => import_hc_http2.HCServiceError,
25
26
  HCSettingsClient: () => HCSettingsClient,
26
- HttpError: () => HttpError,
27
- UserStatus: () => UserStatus
27
+ NetworkError: () => import_hc_http2.NetworkError,
28
+ UserStatus: () => UserStatus,
29
+ ValidationError: () => import_hc_http2.ValidationError,
30
+ errorFromHttpStatus: () => import_hc_http2.errorFromHttpStatus
28
31
  });
29
32
  module.exports = __toCommonJS(index_exports);
30
33
 
31
- // src/errors.ts
32
- var ConfigError = class extends Error {
33
- constructor(message) {
34
- super(message);
35
- this.name = "ConfigError";
36
- }
37
- };
38
- var AuthError = class extends Error {
39
- constructor(message) {
40
- super(message);
41
- this.name = "AuthError";
42
- }
43
- };
44
- var HttpError = class extends Error {
45
- constructor(status, message) {
46
- super(message);
47
- this.name = "HttpError";
48
- this.status = status;
49
- }
50
- };
51
-
52
34
  // src/client.ts
35
+ var import_hc_http = require("@healthcloudai/hc-http");
53
36
  var HCSettingsClient = class {
54
37
  constructor(httpClient, loginClient) {
55
38
  this.httpClient = httpClient;
@@ -59,12 +42,12 @@ var HCSettingsClient = class {
59
42
  const trimmedHeaderName = headerName == null ? void 0 : headerName.trim();
60
43
  const trimmedValue = value == null ? void 0 : value.trim();
61
44
  if (!trimmedHeaderName) {
62
- throw new ConfigError(
45
+ throw new import_hc_http.ConfigError(
63
46
  "API key header name is required."
64
47
  );
65
48
  }
66
49
  if (!trimmedValue) {
67
- throw new ConfigError(
50
+ throw new import_hc_http.ConfigError(
68
51
  "API key value is required."
69
52
  );
70
53
  }
@@ -75,9 +58,12 @@ var HCSettingsClient = class {
75
58
  // Dashboard
76
59
  // ===========================================================================
77
60
  async getDashboard() {
78
- return this.httpClient.get(
79
- `${this.getBaseUrl()}/patient/dashboard`,
80
- this.getAuthHeaders()
61
+ return this.execute(
62
+ "getDashboard",
63
+ () => this.httpClient.get(
64
+ `${this.getBaseUrl()}/api/patient/dashboard`,
65
+ this.getAuthHeaders()
66
+ )
81
67
  );
82
68
  }
83
69
  // ===========================================================================
@@ -93,10 +79,13 @@ var HCSettingsClient = class {
93
79
  Extension: resolvedExtension
94
80
  }
95
81
  };
96
- return this.httpClient.put(
97
- `${this.getBaseUrl()}/patient/image/cannedurl`,
98
- requestPayload,
99
- this.getJsonHeaders()
82
+ return this.execute(
83
+ "getUserImageCannedUrl",
84
+ () => this.httpClient.put(
85
+ `${this.getBaseUrl()}/api/patient/image/cannedurl`,
86
+ requestPayload,
87
+ this.getJsonHeaders()
88
+ )
100
89
  );
101
90
  }
102
91
  async updateUserImage(fileName) {
@@ -109,10 +98,13 @@ var HCSettingsClient = class {
109
98
  FileName: resolvedFileName
110
99
  }
111
100
  };
112
- return this.httpClient.put(
113
- `${this.getBaseUrl()}/patient/image/url`,
114
- requestPayload,
115
- this.getJsonHeaders()
101
+ return this.execute(
102
+ "updateUserImage",
103
+ () => this.httpClient.put(
104
+ `${this.getBaseUrl()}/api/patient/image/url`,
105
+ requestPayload,
106
+ this.getJsonHeaders()
107
+ )
116
108
  );
117
109
  }
118
110
  // ===========================================================================
@@ -128,10 +120,13 @@ var HCSettingsClient = class {
128
120
  Extension: resolvedExtension
129
121
  }
130
122
  };
131
- return this.httpClient.put(
132
- `${this.getBaseUrl()}/patient/id/cannedurl`,
133
- requestPayload,
134
- this.getJsonHeaders()
123
+ return this.execute(
124
+ "getDrivingLicenseCannedUrl",
125
+ () => this.httpClient.put(
126
+ `${this.getBaseUrl()}/api/patient/id/cannedurl`,
127
+ requestPayload,
128
+ this.getJsonHeaders()
129
+ )
135
130
  );
136
131
  }
137
132
  async captureDrivingLicense(fileKey) {
@@ -145,10 +140,13 @@ var HCSettingsClient = class {
145
140
  FileID: resolvedFileKey
146
141
  }
147
142
  };
148
- return this.httpClient.post(
149
- `${this.getBaseUrl()}/patient/capture`,
150
- requestPayload,
151
- this.getJsonHeaders()
143
+ return this.execute(
144
+ "captureDrivingLicense",
145
+ () => this.httpClient.post(
146
+ `${this.getBaseUrl()}/api/patient/capture`,
147
+ requestPayload,
148
+ this.getJsonHeaders()
149
+ )
152
150
  );
153
151
  }
154
152
  async submitDrivingLicense(image) {
@@ -161,10 +159,13 @@ var HCSettingsClient = class {
161
159
  Image: resolvedImage
162
160
  }
163
161
  };
164
- return this.httpClient.put(
165
- `${this.getBaseUrl()}/ehr/patient/drivinglicense`,
166
- requestPayload,
167
- this.getJsonHeaders()
162
+ return this.execute(
163
+ "submitDrivingLicense",
164
+ () => this.httpClient.put(
165
+ `${this.getBaseUrl()}/api/ehr/patient/drivinglicense`,
166
+ requestPayload,
167
+ this.getJsonHeaders()
168
+ )
168
169
  );
169
170
  }
170
171
  // ===========================================================================
@@ -180,10 +181,13 @@ var HCSettingsClient = class {
180
181
  Extension: resolvedExtension
181
182
  }
182
183
  };
183
- return this.httpClient.put(
184
- `${this.getBaseUrl()}/patient/insurance/cannedurl`,
185
- requestPayload,
186
- this.getJsonHeaders()
184
+ return this.execute(
185
+ "getInsuranceCannedUrl",
186
+ () => this.httpClient.put(
187
+ `${this.getBaseUrl()}/api/patient/insurance/cannedurl`,
188
+ requestPayload,
189
+ this.getJsonHeaders()
190
+ )
187
191
  );
188
192
  }
189
193
  async captureInsurance(fileKey) {
@@ -197,31 +201,41 @@ var HCSettingsClient = class {
197
201
  FileID: resolvedFileKey
198
202
  }
199
203
  };
200
- return this.httpClient.post(
201
- `${this.getBaseUrl()}/patient/capture`,
202
- requestPayload,
203
- this.getJsonHeaders()
204
+ return this.execute(
205
+ "captureInsurance",
206
+ () => this.httpClient.post(
207
+ `${this.getBaseUrl()}/api/patient/capture`,
208
+ requestPayload,
209
+ this.getJsonHeaders()
210
+ )
204
211
  );
205
212
  }
206
213
  async submitInsurance(coverage) {
207
214
  if (!coverage) {
208
- throw new ConfigError(
209
- "Insurance coverage data is required."
210
- );
215
+ throw new import_hc_http.ValidationError({
216
+ message: "Insurance coverage data is required.",
217
+ code: "INVALID_INPUT"
218
+ });
211
219
  }
212
220
  const requestPayload = {
213
221
  Data: coverage
214
222
  };
215
- return this.httpClient.put(
216
- `${this.getBaseUrl()}/patient/coverage`,
217
- requestPayload,
218
- this.getJsonHeaders()
223
+ return this.execute(
224
+ "submitInsurance",
225
+ () => this.httpClient.put(
226
+ `${this.getBaseUrl()}/api/patient/coverage`,
227
+ requestPayload,
228
+ this.getJsonHeaders()
229
+ )
219
230
  );
220
231
  }
221
232
  async getInsurances() {
222
- return this.httpClient.get(
223
- `${this.getBaseUrl()}/ehr/patient/insurances`,
224
- this.getAuthHeaders()
233
+ return this.execute(
234
+ "getInsurances",
235
+ () => this.httpClient.get(
236
+ `${this.getBaseUrl()}/api/ehr/patient/insurances`,
237
+ this.getAuthHeaders()
238
+ )
225
239
  );
226
240
  }
227
241
  // ===========================================================================
@@ -238,25 +252,85 @@ var HCSettingsClient = class {
238
252
  FileID: resolvedFileKey
239
253
  }
240
254
  };
241
- return this.httpClient.post(
242
- `${this.getBaseUrl()}/patient/capture`,
243
- requestPayload,
244
- this.getJsonHeaders()
255
+ return this.execute(
256
+ "captureUserPhoto",
257
+ () => this.httpClient.post(
258
+ `${this.getBaseUrl()}/api/patient/capture`,
259
+ requestPayload,
260
+ this.getJsonHeaders()
261
+ )
245
262
  );
246
263
  }
247
264
  // ===========================================================================
248
265
  // Account
249
266
  // ===========================================================================
250
267
  async deactivateUser() {
251
- return this.httpClient.put(
252
- `${this.getBaseUrl()}/patient/deactivate`,
253
- void 0,
254
- this.getJsonHeaders()
268
+ return this.execute(
269
+ "deactivateUser",
270
+ () => this.httpClient.put(
271
+ `${this.getBaseUrl()}/api/patient/deactivate`,
272
+ void 0,
273
+ this.getJsonHeaders()
274
+ )
255
275
  );
256
276
  }
257
277
  // ===========================================================================
258
278
  // Helpers
259
279
  // ===========================================================================
280
+ async execute(operation, request) {
281
+ let response;
282
+ try {
283
+ response = await request();
284
+ } catch (err) {
285
+ if (err instanceof import_hc_http.APIError) {
286
+ throw err;
287
+ }
288
+ if (err instanceof Error) {
289
+ throw new import_hc_http.APIError({
290
+ message: `${operation}: ${err.message}`,
291
+ code: "UNKNOWN_ERROR",
292
+ details: err
293
+ });
294
+ }
295
+ throw new import_hc_http.APIError({
296
+ message: `${operation}: unexpected runtime failure`,
297
+ code: "UNKNOWN_ERROR",
298
+ details: err
299
+ });
300
+ }
301
+ if (response == null) {
302
+ throw new import_hc_http.APIError({
303
+ message: `${operation}: empty response received`,
304
+ code: "EMPTY_RESPONSE",
305
+ details: response
306
+ });
307
+ }
308
+ if (!this.isApiResponse(response)) {
309
+ throw new import_hc_http.APIError({
310
+ message: `${operation}: invalid API response structure`,
311
+ code: "INVALID_RESPONSE",
312
+ details: response
313
+ });
314
+ }
315
+ if (!response.IsOK) {
316
+ throw this.mapBackendError(operation, response);
317
+ }
318
+ return response;
319
+ }
320
+ mapBackendError(operation, response) {
321
+ return new import_hc_http.HCServiceError(
322
+ operation,
323
+ response.ErrorMessage,
324
+ response
325
+ );
326
+ }
327
+ isApiResponse(value) {
328
+ if (!value || typeof value !== "object") {
329
+ return false;
330
+ }
331
+ const response = value;
332
+ return "IsOK" in response && typeof response.IsOK === "boolean" && "Data" in response && "ErrorMessage" in response;
333
+ }
260
334
  getBaseUrl() {
261
335
  return this.loginClient.getBaseUrl();
262
336
  }
@@ -283,14 +357,18 @@ var HCSettingsClient = class {
283
357
  requireValue(value, parameterName) {
284
358
  const trimmedValue = value == null ? void 0 : value.trim();
285
359
  if (!trimmedValue) {
286
- throw new ConfigError(
287
- `${parameterName} is required.`
288
- );
360
+ throw new import_hc_http.ValidationError({
361
+ message: `${parameterName} is required.`,
362
+ code: "INVALID_INPUT"
363
+ });
289
364
  }
290
365
  return trimmedValue;
291
366
  }
292
367
  };
293
368
 
369
+ // src/errors.ts
370
+ var import_hc_http2 = require("@healthcloudai/hc-http");
371
+
294
372
  // src/types.ts
295
373
  var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
296
374
  UserStatus2[UserStatus2["INACTIVE"] = 0] = "INACTIVE";
@@ -300,9 +378,12 @@ var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
300
378
  })(UserStatus || {});
301
379
  // Annotate the CommonJS export names for ESM import in node:
302
380
  0 && (module.exports = {
303
- AuthError,
381
+ APIError,
304
382
  ConfigError,
383
+ HCServiceError,
305
384
  HCSettingsClient,
306
- HttpError,
307
- UserStatus
385
+ NetworkError,
386
+ UserStatus,
387
+ ValidationError,
388
+ errorFromHttpStatus
308
389
  });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HCLoginClient } from '@healthcloudai/hc-login-connector';
2
- import { HttpClient } from '@healthcloudai/hc-http';
2
+ import { HttpClient, APIError } from '@healthcloudai/hc-http';
3
+ export { APIError, ConfigError, HCServiceError, NetworkError, ValidationError, errorFromHttpStatus } from '@healthcloudai/hc-http';
3
4
 
4
5
  interface APIRequest<T> {
5
6
  Data: T;
@@ -139,6 +140,9 @@ declare class HCSettingsClient {
139
140
  getInsurances(): Promise<APIResponse<InsuranceRecord[]>>;
140
141
  captureUserPhoto(fileKey: string): Promise<APIResponse<CaptureResult<UserPhotoCaptureData>>>;
141
142
  deactivateUser(): Promise<APIResponse<boolean>>;
143
+ protected execute<T>(operation: string, request: () => Promise<APIResponse<T>>): Promise<APIResponse<T>>;
144
+ protected mapBackendError(operation: string, response: APIResponse<unknown>): APIError;
145
+ private isApiResponse;
142
146
  private getBaseUrl;
143
147
  private getAuthHeaders;
144
148
  private getJsonHeaders;
@@ -146,15 +150,4 @@ declare class HCSettingsClient {
146
150
  private requireValue;
147
151
  }
148
152
 
149
- declare class ConfigError extends Error {
150
- constructor(message: string);
151
- }
152
- declare class AuthError extends Error {
153
- constructor(message: string);
154
- }
155
- declare class HttpError extends Error {
156
- status: number;
157
- constructor(status: number, message: string);
158
- }
159
-
160
- export { type APIRequest, type APIResponse, AuthError, type CaptureResult, type CaptureType, ConfigError, type CoverageData, type Encounter, HCSettingsClient, HttpError, type IdentificationCaptureData, type InsuranceCaptureData, type InsuranceRecord, type PatientDashboard, type PatientRecord, type UserImage, type UserPhotoCaptureData, UserStatus };
153
+ export { type APIRequest, type APIResponse, type CaptureResult, type CaptureType, type CoverageData, type Encounter, HCSettingsClient, type IdentificationCaptureData, type InsuranceCaptureData, type InsuranceRecord, type PatientDashboard, type PatientRecord, type UserImage, type UserPhotoCaptureData, UserStatus };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HCLoginClient } from '@healthcloudai/hc-login-connector';
2
- import { HttpClient } from '@healthcloudai/hc-http';
2
+ import { HttpClient, APIError } from '@healthcloudai/hc-http';
3
+ export { APIError, ConfigError, HCServiceError, NetworkError, ValidationError, errorFromHttpStatus } from '@healthcloudai/hc-http';
3
4
 
4
5
  interface APIRequest<T> {
5
6
  Data: T;
@@ -139,6 +140,9 @@ declare class HCSettingsClient {
139
140
  getInsurances(): Promise<APIResponse<InsuranceRecord[]>>;
140
141
  captureUserPhoto(fileKey: string): Promise<APIResponse<CaptureResult<UserPhotoCaptureData>>>;
141
142
  deactivateUser(): Promise<APIResponse<boolean>>;
143
+ protected execute<T>(operation: string, request: () => Promise<APIResponse<T>>): Promise<APIResponse<T>>;
144
+ protected mapBackendError(operation: string, response: APIResponse<unknown>): APIError;
145
+ private isApiResponse;
142
146
  private getBaseUrl;
143
147
  private getAuthHeaders;
144
148
  private getJsonHeaders;
@@ -146,15 +150,4 @@ declare class HCSettingsClient {
146
150
  private requireValue;
147
151
  }
148
152
 
149
- declare class ConfigError extends Error {
150
- constructor(message: string);
151
- }
152
- declare class AuthError extends Error {
153
- constructor(message: string);
154
- }
155
- declare class HttpError extends Error {
156
- status: number;
157
- constructor(status: number, message: string);
158
- }
159
-
160
- export { type APIRequest, type APIResponse, AuthError, type CaptureResult, type CaptureType, ConfigError, type CoverageData, type Encounter, HCSettingsClient, HttpError, type IdentificationCaptureData, type InsuranceCaptureData, type InsuranceRecord, type PatientDashboard, type PatientRecord, type UserImage, type UserPhotoCaptureData, UserStatus };
153
+ export { type APIRequest, type APIResponse, type CaptureResult, type CaptureType, type CoverageData, type Encounter, HCSettingsClient, type IdentificationCaptureData, type InsuranceCaptureData, type InsuranceRecord, type PatientDashboard, type PatientRecord, type UserImage, type UserPhotoCaptureData, UserStatus };
package/dist/index.js CHANGED
@@ -1,25 +1,10 @@
1
- // src/errors.ts
2
- var ConfigError = class extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = "ConfigError";
6
- }
7
- };
8
- var AuthError = class extends Error {
9
- constructor(message) {
10
- super(message);
11
- this.name = "AuthError";
12
- }
13
- };
14
- var HttpError = class extends Error {
15
- constructor(status, message) {
16
- super(message);
17
- this.name = "HttpError";
18
- this.status = status;
19
- }
20
- };
21
-
22
1
  // src/client.ts
2
+ import {
3
+ APIError,
4
+ ConfigError,
5
+ HCServiceError,
6
+ ValidationError
7
+ } from "@healthcloudai/hc-http";
23
8
  var HCSettingsClient = class {
24
9
  constructor(httpClient, loginClient) {
25
10
  this.httpClient = httpClient;
@@ -45,9 +30,12 @@ var HCSettingsClient = class {
45
30
  // Dashboard
46
31
  // ===========================================================================
47
32
  async getDashboard() {
48
- return this.httpClient.get(
49
- `${this.getBaseUrl()}/patient/dashboard`,
50
- this.getAuthHeaders()
33
+ return this.execute(
34
+ "getDashboard",
35
+ () => this.httpClient.get(
36
+ `${this.getBaseUrl()}/api/patient/dashboard`,
37
+ this.getAuthHeaders()
38
+ )
51
39
  );
52
40
  }
53
41
  // ===========================================================================
@@ -63,10 +51,13 @@ var HCSettingsClient = class {
63
51
  Extension: resolvedExtension
64
52
  }
65
53
  };
66
- return this.httpClient.put(
67
- `${this.getBaseUrl()}/patient/image/cannedurl`,
68
- requestPayload,
69
- this.getJsonHeaders()
54
+ return this.execute(
55
+ "getUserImageCannedUrl",
56
+ () => this.httpClient.put(
57
+ `${this.getBaseUrl()}/api/patient/image/cannedurl`,
58
+ requestPayload,
59
+ this.getJsonHeaders()
60
+ )
70
61
  );
71
62
  }
72
63
  async updateUserImage(fileName) {
@@ -79,10 +70,13 @@ var HCSettingsClient = class {
79
70
  FileName: resolvedFileName
80
71
  }
81
72
  };
82
- return this.httpClient.put(
83
- `${this.getBaseUrl()}/patient/image/url`,
84
- requestPayload,
85
- this.getJsonHeaders()
73
+ return this.execute(
74
+ "updateUserImage",
75
+ () => this.httpClient.put(
76
+ `${this.getBaseUrl()}/api/patient/image/url`,
77
+ requestPayload,
78
+ this.getJsonHeaders()
79
+ )
86
80
  );
87
81
  }
88
82
  // ===========================================================================
@@ -98,10 +92,13 @@ var HCSettingsClient = class {
98
92
  Extension: resolvedExtension
99
93
  }
100
94
  };
101
- return this.httpClient.put(
102
- `${this.getBaseUrl()}/patient/id/cannedurl`,
103
- requestPayload,
104
- this.getJsonHeaders()
95
+ return this.execute(
96
+ "getDrivingLicenseCannedUrl",
97
+ () => this.httpClient.put(
98
+ `${this.getBaseUrl()}/api/patient/id/cannedurl`,
99
+ requestPayload,
100
+ this.getJsonHeaders()
101
+ )
105
102
  );
106
103
  }
107
104
  async captureDrivingLicense(fileKey) {
@@ -115,10 +112,13 @@ var HCSettingsClient = class {
115
112
  FileID: resolvedFileKey
116
113
  }
117
114
  };
118
- return this.httpClient.post(
119
- `${this.getBaseUrl()}/patient/capture`,
120
- requestPayload,
121
- this.getJsonHeaders()
115
+ return this.execute(
116
+ "captureDrivingLicense",
117
+ () => this.httpClient.post(
118
+ `${this.getBaseUrl()}/api/patient/capture`,
119
+ requestPayload,
120
+ this.getJsonHeaders()
121
+ )
122
122
  );
123
123
  }
124
124
  async submitDrivingLicense(image) {
@@ -131,10 +131,13 @@ var HCSettingsClient = class {
131
131
  Image: resolvedImage
132
132
  }
133
133
  };
134
- return this.httpClient.put(
135
- `${this.getBaseUrl()}/ehr/patient/drivinglicense`,
136
- requestPayload,
137
- this.getJsonHeaders()
134
+ return this.execute(
135
+ "submitDrivingLicense",
136
+ () => this.httpClient.put(
137
+ `${this.getBaseUrl()}/api/ehr/patient/drivinglicense`,
138
+ requestPayload,
139
+ this.getJsonHeaders()
140
+ )
138
141
  );
139
142
  }
140
143
  // ===========================================================================
@@ -150,10 +153,13 @@ var HCSettingsClient = class {
150
153
  Extension: resolvedExtension
151
154
  }
152
155
  };
153
- return this.httpClient.put(
154
- `${this.getBaseUrl()}/patient/insurance/cannedurl`,
155
- requestPayload,
156
- this.getJsonHeaders()
156
+ return this.execute(
157
+ "getInsuranceCannedUrl",
158
+ () => this.httpClient.put(
159
+ `${this.getBaseUrl()}/api/patient/insurance/cannedurl`,
160
+ requestPayload,
161
+ this.getJsonHeaders()
162
+ )
157
163
  );
158
164
  }
159
165
  async captureInsurance(fileKey) {
@@ -167,31 +173,41 @@ var HCSettingsClient = class {
167
173
  FileID: resolvedFileKey
168
174
  }
169
175
  };
170
- return this.httpClient.post(
171
- `${this.getBaseUrl()}/patient/capture`,
172
- requestPayload,
173
- this.getJsonHeaders()
176
+ return this.execute(
177
+ "captureInsurance",
178
+ () => this.httpClient.post(
179
+ `${this.getBaseUrl()}/api/patient/capture`,
180
+ requestPayload,
181
+ this.getJsonHeaders()
182
+ )
174
183
  );
175
184
  }
176
185
  async submitInsurance(coverage) {
177
186
  if (!coverage) {
178
- throw new ConfigError(
179
- "Insurance coverage data is required."
180
- );
187
+ throw new ValidationError({
188
+ message: "Insurance coverage data is required.",
189
+ code: "INVALID_INPUT"
190
+ });
181
191
  }
182
192
  const requestPayload = {
183
193
  Data: coverage
184
194
  };
185
- return this.httpClient.put(
186
- `${this.getBaseUrl()}/patient/coverage`,
187
- requestPayload,
188
- this.getJsonHeaders()
195
+ return this.execute(
196
+ "submitInsurance",
197
+ () => this.httpClient.put(
198
+ `${this.getBaseUrl()}/api/patient/coverage`,
199
+ requestPayload,
200
+ this.getJsonHeaders()
201
+ )
189
202
  );
190
203
  }
191
204
  async getInsurances() {
192
- return this.httpClient.get(
193
- `${this.getBaseUrl()}/ehr/patient/insurances`,
194
- this.getAuthHeaders()
205
+ return this.execute(
206
+ "getInsurances",
207
+ () => this.httpClient.get(
208
+ `${this.getBaseUrl()}/api/ehr/patient/insurances`,
209
+ this.getAuthHeaders()
210
+ )
195
211
  );
196
212
  }
197
213
  // ===========================================================================
@@ -208,25 +224,85 @@ var HCSettingsClient = class {
208
224
  FileID: resolvedFileKey
209
225
  }
210
226
  };
211
- return this.httpClient.post(
212
- `${this.getBaseUrl()}/patient/capture`,
213
- requestPayload,
214
- this.getJsonHeaders()
227
+ return this.execute(
228
+ "captureUserPhoto",
229
+ () => this.httpClient.post(
230
+ `${this.getBaseUrl()}/api/patient/capture`,
231
+ requestPayload,
232
+ this.getJsonHeaders()
233
+ )
215
234
  );
216
235
  }
217
236
  // ===========================================================================
218
237
  // Account
219
238
  // ===========================================================================
220
239
  async deactivateUser() {
221
- return this.httpClient.put(
222
- `${this.getBaseUrl()}/patient/deactivate`,
223
- void 0,
224
- this.getJsonHeaders()
240
+ return this.execute(
241
+ "deactivateUser",
242
+ () => this.httpClient.put(
243
+ `${this.getBaseUrl()}/api/patient/deactivate`,
244
+ void 0,
245
+ this.getJsonHeaders()
246
+ )
225
247
  );
226
248
  }
227
249
  // ===========================================================================
228
250
  // Helpers
229
251
  // ===========================================================================
252
+ async execute(operation, request) {
253
+ let response;
254
+ try {
255
+ response = await request();
256
+ } catch (err) {
257
+ if (err instanceof APIError) {
258
+ throw err;
259
+ }
260
+ if (err instanceof Error) {
261
+ throw new APIError({
262
+ message: `${operation}: ${err.message}`,
263
+ code: "UNKNOWN_ERROR",
264
+ details: err
265
+ });
266
+ }
267
+ throw new APIError({
268
+ message: `${operation}: unexpected runtime failure`,
269
+ code: "UNKNOWN_ERROR",
270
+ details: err
271
+ });
272
+ }
273
+ if (response == null) {
274
+ throw new APIError({
275
+ message: `${operation}: empty response received`,
276
+ code: "EMPTY_RESPONSE",
277
+ details: response
278
+ });
279
+ }
280
+ if (!this.isApiResponse(response)) {
281
+ throw new APIError({
282
+ message: `${operation}: invalid API response structure`,
283
+ code: "INVALID_RESPONSE",
284
+ details: response
285
+ });
286
+ }
287
+ if (!response.IsOK) {
288
+ throw this.mapBackendError(operation, response);
289
+ }
290
+ return response;
291
+ }
292
+ mapBackendError(operation, response) {
293
+ return new HCServiceError(
294
+ operation,
295
+ response.ErrorMessage,
296
+ response
297
+ );
298
+ }
299
+ isApiResponse(value) {
300
+ if (!value || typeof value !== "object") {
301
+ return false;
302
+ }
303
+ const response = value;
304
+ return "IsOK" in response && typeof response.IsOK === "boolean" && "Data" in response && "ErrorMessage" in response;
305
+ }
230
306
  getBaseUrl() {
231
307
  return this.loginClient.getBaseUrl();
232
308
  }
@@ -253,14 +329,25 @@ var HCSettingsClient = class {
253
329
  requireValue(value, parameterName) {
254
330
  const trimmedValue = value == null ? void 0 : value.trim();
255
331
  if (!trimmedValue) {
256
- throw new ConfigError(
257
- `${parameterName} is required.`
258
- );
332
+ throw new ValidationError({
333
+ message: `${parameterName} is required.`,
334
+ code: "INVALID_INPUT"
335
+ });
259
336
  }
260
337
  return trimmedValue;
261
338
  }
262
339
  };
263
340
 
341
+ // src/errors.ts
342
+ import {
343
+ APIError as APIError2,
344
+ ConfigError as ConfigError2,
345
+ HCServiceError as HCServiceError2,
346
+ NetworkError,
347
+ ValidationError as ValidationError2,
348
+ errorFromHttpStatus
349
+ } from "@healthcloudai/hc-http";
350
+
264
351
  // src/types.ts
265
352
  var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
266
353
  UserStatus2[UserStatus2["INACTIVE"] = 0] = "INACTIVE";
@@ -269,9 +356,12 @@ var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
269
356
  return UserStatus2;
270
357
  })(UserStatus || {});
271
358
  export {
272
- AuthError,
273
- ConfigError,
359
+ APIError2 as APIError,
360
+ ConfigError2 as ConfigError,
361
+ HCServiceError2 as HCServiceError,
274
362
  HCSettingsClient,
275
- HttpError,
276
- UserStatus
363
+ NetworkError,
364
+ UserStatus,
365
+ ValidationError2 as ValidationError,
366
+ errorFromHttpStatus
277
367
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@healthcloudai/hc-settings-connector",
3
- "version": "0.0.14",
3
+ "version": "0.1.0",
4
4
  "description": "Healthcheck Settings SDK with TypeScript",
5
5
  "author": "Healthcheck Systems Inc",
6
6
  "license": "MIT",
@@ -36,8 +36,8 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "axios": "^1.13.4",
39
- "@healthcloudai/hc-login-connector": "^0.1.0",
40
- "@healthcloudai/hc-http": "^0.0.6"
39
+ "@healthcloudai/hc-login-connector": "^0.2.0",
40
+ "@healthcloudai/hc-http": "^0.1.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react-native": ">=0.70.0"