@healthcloudai/hc-safe-cdx 0.1.3 → 0.2.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.js CHANGED
@@ -13,10 +13,15 @@ var ENV_HOST = {
13
13
  prod: "api-hcs.healthcloud-services.com"
14
14
  };
15
15
  var ROUTE_PREFIX = "api/console/hcservice/safecdx";
16
- function buildUrl(host, route, query) {
17
- const url = new URL(
18
- `https://${host}/${ROUTE_PREFIX}/${route.replace(/^\/+/, "")}`
19
- );
16
+ function buildSafeCdxBaseUrl(environment) {
17
+ const host = ENV_HOST[environment];
18
+ if (!host) {
19
+ throw new SafeCDXError("Invalid Safe CDX environment.");
20
+ }
21
+ return `https://${host}/${ROUTE_PREFIX}`;
22
+ }
23
+ function buildUrl(baseUrl, route, query) {
24
+ const url = new URL(`${baseUrl}/${route.replace(/^\/+/, "")}`);
20
25
  if (query) {
21
26
  for (const [key, value] of Object.entries(query)) {
22
27
  if (value !== void 0 && value !== "") {
@@ -26,30 +31,11 @@ function buildUrl(host, route, query) {
26
31
  }
27
32
  return url.toString();
28
33
  }
29
- function wrapData(payload) {
30
- return { Data: payload };
31
- }
32
- function assertApiResponse(envelope, route) {
33
- var _a;
34
- if (!envelope.IsOK) {
35
- throw new SafeCDXError(
36
- (_a = envelope.ErrorMessage) != null ? _a : `${route} returned IsOK=false.`,
37
- envelope
38
- );
39
- }
40
- return envelope;
41
- }
42
34
  var HCSafeCDXClient = class {
43
- constructor(httpClient, authClient, config) {
44
- var _a;
45
- if (!ENV_HOST[config.environment]) {
46
- throw new SafeCDXError(`Invalid environment: ${config.environment}`);
47
- }
35
+ constructor(httpClient, authClient) {
48
36
  this.http = httpClient;
49
37
  this.auth = authClient;
50
- this.host = ENV_HOST[config.environment];
51
- this.defaultLanguage = config.defaultLanguage;
52
- this.defaultImageType = (_a = config.defaultImageType) != null ? _a : "jpg";
38
+ this.baseUrl = buildSafeCdxBaseUrl(authClient.getEnvironment());
53
39
  }
54
40
  setApiKey(headerName, value) {
55
41
  const trimmedHeaderName = headerName == null ? void 0 : headerName.trim();
@@ -87,7 +73,7 @@ var HCSafeCDXClient = class {
87
73
  };
88
74
  }
89
75
  url(route, query) {
90
- return buildUrl(this.host, route, query);
76
+ return buildUrl(this.baseUrl, route, query);
91
77
  }
92
78
  // ---------------------------------------------------------------------------
93
79
  // Scan
@@ -96,30 +82,15 @@ var HCSafeCDXClient = class {
96
82
  * GET gs1/:gtin
97
83
  * Resolves a test profile by GTIN barcode and creates a UserTestResultId.
98
84
  */
99
- async getTestProfileByGTIN(gtin, language) {
100
- const envelope = await this.http.get(
101
- this.url(`gs1/${encodeURIComponent(gtin)}`, {
102
- language: language != null ? language : this.defaultLanguage
103
- }),
85
+ async getTestProfileByGTIN(gtin) {
86
+ return this.http.get(
87
+ this.url(`gs1/${encodeURIComponent(gtin)}`),
104
88
  this.getAuthHeaders()
105
89
  );
106
- return assertApiResponse(envelope, "gs1/:gtin");
107
90
  }
108
91
  // ---------------------------------------------------------------------------
109
92
  // Test Profiles
110
93
  // ---------------------------------------------------------------------------
111
- /**
112
- * POST test/profile
113
- * Returns the full test profile for a given GTIN.
114
- */
115
- async getTestProfile(payload) {
116
- const envelope = await this.http.post(
117
- this.url("test/profile"),
118
- wrapData(payload),
119
- this.getJsonHeaders()
120
- );
121
- return assertApiResponse(envelope, "test/profile");
122
- }
123
94
  /**
124
95
  * POST test/profiles/by-account
125
96
  * Lists all test profiles available to the authenticated account.
@@ -127,12 +98,14 @@ var HCSafeCDXClient = class {
127
98
  async getTestProfilesByAccount(payload = {
128
99
  IncludeRegisterTestDetails: true
129
100
  }) {
130
- const envelope = await this.http.post(
101
+ const request = {
102
+ Data: payload
103
+ };
104
+ return this.http.post(
131
105
  this.url("test/profiles/by-account"),
132
- wrapData(payload),
106
+ request,
133
107
  this.getJsonHeaders()
134
108
  );
135
- return assertApiResponse(envelope, "test/profiles/by-account");
136
109
  }
137
110
  // ---------------------------------------------------------------------------
138
111
  // Upload
@@ -147,15 +120,17 @@ var HCSafeCDXClient = class {
147
120
  Gtin: gtin,
148
121
  UserTestResultId: userTestResultId,
149
122
  Metadata: {
150
- ImageType: imageType != null ? imageType : this.defaultImageType
123
+ ImageType: imageType != null ? imageType : "jpg"
151
124
  }
152
125
  };
153
- const envelope = await this.http.post(
126
+ const request = {
127
+ Data: payload
128
+ };
129
+ return this.http.post(
154
130
  this.url("upload/url"),
155
- wrapData(payload),
131
+ request,
156
132
  this.getJsonHeaders()
157
133
  );
158
- return assertApiResponse(envelope, "upload/url");
159
134
  }
160
135
  /**
161
136
  * PUT preSignedURL — direct S3 upload, not a SafeCDX API route.
@@ -200,9 +175,12 @@ var HCSafeCDXClient = class {
200
175
  ImageOfCaptureId: imageOfCaptureId,
201
176
  CvmlStatus: cvmlStatus
202
177
  };
178
+ const request = {
179
+ Data: payload
180
+ };
203
181
  return this.http.post(
204
182
  this.url("cvml/status"),
205
- wrapData(payload),
183
+ request,
206
184
  this.getJsonHeaders()
207
185
  );
208
186
  }
@@ -227,38 +205,48 @@ var HCSafeCDXClient = class {
227
205
  * Returns test results in a pending/incomplete state.
228
206
  */
229
207
  async getPendingResults(payload = {
230
- ExcludeStatus: "Started"
208
+ ExcludeStatus: "Invalid,Canceled"
231
209
  }) {
232
- const envelope = await this.http.post(
210
+ const request = {
211
+ Data: payload
212
+ };
213
+ return this.http.post(
233
214
  this.url("test/result/pending"),
234
- wrapData(payload),
215
+ request,
235
216
  this.getJsonHeaders()
236
217
  );
237
- return assertApiResponse(envelope, "test/result/pending");
238
218
  }
239
219
  /**
240
220
  * POST test/result/last
241
221
  * Returns the most recent test result for the authenticated patient.
242
222
  */
243
- async getLastResults(payload = {}) {
244
- const envelope = await this.http.post(
223
+ async getLastResults(payload = {
224
+ ExcludeStatus: "Invalid"
225
+ }) {
226
+ const request = {
227
+ Data: payload
228
+ };
229
+ return this.http.post(
245
230
  this.url("test/result/last"),
246
- wrapData(payload),
231
+ request,
247
232
  this.getJsonHeaders()
248
233
  );
249
- return assertApiResponse(envelope, "test/result/last");
250
234
  }
251
235
  /**
252
236
  * POST test/result/history
253
237
  * Returns the full test history for the authenticated patient.
254
238
  */
255
- async getTestHistory(payload = {}) {
256
- const envelope = await this.http.post(
239
+ async getTestHistory(payload = {
240
+ ExcludeStatus: "Invalid"
241
+ }) {
242
+ const request = {
243
+ Data: payload
244
+ };
245
+ return this.http.post(
257
246
  this.url("test/result/history"),
258
- wrapData(payload),
247
+ request,
259
248
  this.getJsonHeaders()
260
249
  );
261
- return assertApiResponse(envelope, "test/result/history");
262
250
  }
263
251
  /**
264
252
  * POST test/result/details
@@ -269,51 +257,47 @@ var HCSafeCDXClient = class {
269
257
  const payload = {
270
258
  UserTestResultId: userTestResultId
271
259
  };
260
+ const request = {
261
+ Data: payload
262
+ };
272
263
  return this.http.post(
273
264
  this.url("test/result/details"),
274
- wrapData(payload),
265
+ request,
275
266
  this.getJsonHeaders()
276
267
  );
277
268
  }
278
269
  /**
279
270
  * POST test/result/pdf
280
- * Generates a PDF report for a specific test result.
271
+ * Requests the PDF result for a specific test result.
281
272
  */
282
273
  async getResultPdf(payload) {
283
- const envelope = await this.http.post(
274
+ const request = {
275
+ Data: payload
276
+ };
277
+ return this.http.post(
284
278
  this.url("test/result/pdf"),
285
- wrapData(payload),
279
+ request,
286
280
  this.getJsonHeaders()
287
281
  );
288
- return assertApiResponse(envelope, "test/result/pdf");
289
282
  }
290
283
  /**
291
284
  * POST test/result/image/capture
292
- * Returns the image capture URL for a specific test result.
285
+ * Requests image capture data for a specific test result.
293
286
  * NOTE: Returns raw service result — no ApiResponse wrapper on this endpoint.
294
287
  */
295
288
  async getImageCaptureUrl(userTestResultId) {
296
289
  const payload = {
297
290
  UserTestResultId: userTestResultId
298
291
  };
292
+ const request = {
293
+ Data: payload
294
+ };
299
295
  return this.http.post(
300
296
  this.url("test/result/image/capture"),
301
- wrapData(payload),
297
+ request,
302
298
  this.getJsonHeaders()
303
299
  );
304
300
  }
305
- /**
306
- * POST test/result/analytics
307
- * Returns analytics data for test results.
308
- */
309
- async getAnalytics(payload = {}) {
310
- const envelope = await this.http.post(
311
- this.url("test/result/analytics"),
312
- wrapData(payload),
313
- this.getJsonHeaders()
314
- );
315
- return assertApiResponse(envelope, "test/result/analytics");
316
- }
317
301
  // ---------------------------------------------------------------------------
318
302
  // Resume / Answers / Finalize
319
303
  // ---------------------------------------------------------------------------
@@ -326,36 +310,42 @@ var HCSafeCDXClient = class {
326
310
  UserTestResultId: userTestResultId,
327
311
  Resumed: resumed
328
312
  };
329
- const envelope = await this.http.post(
313
+ const request = {
314
+ Data: payload
315
+ };
316
+ return this.http.post(
330
317
  this.url("test/resume"),
331
- wrapData(payload),
318
+ request,
332
319
  this.getJsonHeaders()
333
320
  );
334
- return assertApiResponse(envelope, "test/resume");
335
321
  }
336
322
  /**
337
323
  * POST test/answers
338
324
  * Submits analyte answers for a test attempt.
339
325
  */
340
326
  async submitAnswers(payload) {
341
- const envelope = await this.http.post(
327
+ const request = {
328
+ Data: payload
329
+ };
330
+ return this.http.post(
342
331
  this.url("test/answers"),
343
- wrapData(payload),
332
+ request,
344
333
  this.getJsonHeaders()
345
334
  );
346
- return assertApiResponse(envelope, "test/answers");
347
335
  }
348
336
  /**
349
337
  * POST test/finalize
350
- * Finalizes a test attempt with CTA, indication, and decision results.
338
+ * Finalizes a test by UserTestResultId.
351
339
  */
352
340
  async finalizeTest(payload) {
353
- const envelope = await this.http.post(
341
+ const request = {
342
+ Data: payload
343
+ };
344
+ return this.http.post(
354
345
  this.url("test/finalize"),
355
- wrapData(payload),
346
+ request,
356
347
  this.getJsonHeaders()
357
348
  );
358
- return assertApiResponse(envelope, "test/finalize");
359
349
  }
360
350
  };
361
351
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@healthcloudai/hc-safe-cdx",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Healthcheck Safe CDX connector.",
5
5
  "author": "Healthcheck Systems Inc",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@healthcloudai/hc-http": "^0.0.6",
37
- "@healthcloudai/hc-login-connector": "^0.0.15"
37
+ "@healthcloudai/hc-login-connector": "^0.1.0"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react-native": ">=0.70.0"