@healthcloudai/hc-sdk 3.5.0 → 3.5.1

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
@@ -31,6 +31,7 @@ __export(index_exports, {
31
31
  ConnectorFactory: () => ConnectorFactory,
32
32
  ConnectorsNamespace: () => ConnectorsNamespace,
33
33
  ConnectureClient: () => ConnectureClient,
34
+ DEFAULT_TIMEOUT_MS: () => DEFAULT_TIMEOUT_MS,
34
35
  ElevenLabsClient: () => ElevenLabsClient,
35
36
  FedExClient: () => FedExClient,
36
37
  GoogleAIClient: () => GoogleAIClient,
@@ -64,6 +65,7 @@ __export(index_exports, {
64
65
  ZocdocClient: () => ZocdocClient,
65
66
  ZusClient: () => ZusClient,
66
67
  assertEnvironment: () => assertEnvironment,
68
+ assertTimeout: () => assertTimeout,
67
69
  isJsonRpcError: () => isJsonRpcError,
68
70
  isServiceName: () => isServiceName,
69
71
  resolveBaseUrl: () => resolveBaseUrl,
@@ -72,6 +74,7 @@ __export(index_exports, {
72
74
  module.exports = __toCommonJS(index_exports);
73
75
 
74
76
  // src/config/SDKConfig.ts
77
+ var DEFAULT_TIMEOUT_MS = 3e4;
75
78
  var SERVICES = [
76
79
  "patient",
77
80
  "vitals",
@@ -100,6 +103,11 @@ function resolveBaseUrl(environment, service) {
100
103
  const prefix = environment === "prod" ? "" : `${environment}-`;
101
104
  return `https://${prefix}api-${service}.health.cloud`;
102
105
  }
106
+ function assertTimeout(timeout, label = "timeout") {
107
+ if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0) {
108
+ throw new Error(`Invalid HealthCloud SDK ${label}: expected a positive number of milliseconds, got ${String(timeout)}`);
109
+ }
110
+ }
103
111
  function assertEnvironment(environment) {
104
112
  if (environment !== "dev" && environment !== "uat" && environment !== "prod") {
105
113
  throw new Error(`Unsupported HealthCloud environment: "${environment}"`);
@@ -132,23 +140,46 @@ var HttpClient = class {
132
140
  this.state = state;
133
141
  }
134
142
  async request(service, method, path, options = {}) {
143
+ var _a, _b;
135
144
  const url = this.buildUrl(service, path, options);
136
145
  const headers = this.buildHeaders(options);
137
146
  const init = { method, headers };
138
147
  if (method !== "GET" && method !== "DELETE" && options.body !== void 0) {
139
148
  init.body = this.serializeBody(options.body, headers);
140
149
  }
150
+ const timeoutMs = (_b = (_a = options.timeoutMs) != null ? _a : this.state.timeout) != null ? _b : DEFAULT_TIMEOUT_MS;
151
+ assertTimeout(timeoutMs, options.timeoutMs !== void 0 ? "timeoutMs" : "timeout");
152
+ let didTimeout = false;
153
+ const controller = new AbortController();
154
+ init.signal = controller.signal;
155
+ const timer = setTimeout(() => {
156
+ didTimeout = true;
157
+ controller.abort();
158
+ }, timeoutMs);
141
159
  let response;
160
+ let payload;
142
161
  try {
143
162
  response = await fetch(url, init);
163
+ payload = await this.parseResponse(response);
144
164
  } catch (error) {
165
+ if (didTimeout) {
166
+ throw new SDKError({
167
+ message: `Request timed out after ${timeoutMs}ms: ${method} ${path}`,
168
+ statusCode: 0,
169
+ cause: error
170
+ });
171
+ }
172
+ if (error instanceof SDKError) {
173
+ throw error;
174
+ }
145
175
  throw new SDKError({
146
176
  message: error instanceof Error ? error.message : "Network request failed.",
147
177
  statusCode: 0,
148
178
  cause: error
149
179
  });
180
+ } finally {
181
+ clearTimeout(timer);
150
182
  }
151
- const payload = await this.parseResponse(response);
152
183
  if (!response.ok) {
153
184
  throw new SDKError({
154
185
  message: this.resolveErrorMessage(response, payload),
@@ -6004,12 +6035,15 @@ var ConnectorsNamespace = class {
6004
6035
  // src/HCSDK.ts
6005
6036
  var HCSDK = class {
6006
6037
  constructor(config) {
6038
+ var _a, _b;
6007
6039
  assertEnvironment(config.environment);
6040
+ assertTimeout((_a = config.timeout) != null ? _a : DEFAULT_TIMEOUT_MS);
6008
6041
  this.state = {
6009
6042
  environment: config.environment,
6010
6043
  tenantId: config.tenantId,
6011
6044
  accessToken: config.accessToken,
6012
- baseUrlOverrides: config.baseUrlOverrides
6045
+ baseUrlOverrides: config.baseUrlOverrides,
6046
+ timeout: (_b = config.timeout) != null ? _b : DEFAULT_TIMEOUT_MS
6013
6047
  };
6014
6048
  this.http = new HttpClient(this.state);
6015
6049
  this.auth = new AuthClient(
@@ -6145,6 +6179,7 @@ var HCSDK_SWAGGER_OPERATION_COUNTS = {
6145
6179
  ConnectorFactory,
6146
6180
  ConnectorsNamespace,
6147
6181
  ConnectureClient,
6182
+ DEFAULT_TIMEOUT_MS,
6148
6183
  ElevenLabsClient,
6149
6184
  FedExClient,
6150
6185
  GoogleAIClient,
@@ -6178,6 +6213,7 @@ var HCSDK_SWAGGER_OPERATION_COUNTS = {
6178
6213
  ZocdocClient,
6179
6214
  ZusClient,
6180
6215
  assertEnvironment,
6216
+ assertTimeout,
6181
6217
  isJsonRpcError,
6182
6218
  isServiceName,
6183
6219
  resolveBaseUrl,