@healthcloudai/hc-sdk 3.24.0 → 3.24.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 +70 -5
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +67 -5
- package/docs/configuration.md +2 -2
- package/docs/docs-manifest.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21,12 +21,67 @@ function isServiceName(value) {
|
|
|
21
21
|
return SERVICES.includes(value);
|
|
22
22
|
}
|
|
23
23
|
function resolveBaseUrl(environment, service) {
|
|
24
|
+
assertEnvironment(environment);
|
|
24
25
|
if (service === "ams") {
|
|
26
|
+
if (environment === "dev") return "https://dev-ams-services.health.cloud/api/ams";
|
|
25
27
|
const prefix = environment === "prod" ? "" : `${environment}-`;
|
|
26
28
|
return `https://${prefix}amsservices.health.cloud/api/ams`;
|
|
27
29
|
}
|
|
28
30
|
return `https://${environment}-api-${service}.health.cloud`;
|
|
29
31
|
}
|
|
32
|
+
function normalizeBaseUrl(value) {
|
|
33
|
+
const message = "Invalid service base URL: expected HTTPS (or literal loopback HTTP); no credentials, query or fragment";
|
|
34
|
+
try {
|
|
35
|
+
if (typeof value !== "string" || /[^\x21-\x7e]|[\\?#]/.test(value) || !/^https?:\/\//i.test(value)) {
|
|
36
|
+
throw new Error();
|
|
37
|
+
}
|
|
38
|
+
const authority = value.slice(value.indexOf("://") + 3).split("/")[0];
|
|
39
|
+
if (!authority || /[@%]/.test(authority) || authority.endsWith(":")) throw new Error();
|
|
40
|
+
const url = new URL(value);
|
|
41
|
+
const host = url.hostname;
|
|
42
|
+
const allowedScheme = url.protocol === "https:" || url.protocol === "http:" && (host === "127.0.0.1" || host === "[::1]");
|
|
43
|
+
if (!allowedScheme || !host || url.username || url.password || url.port && Number(url.port) < 1) {
|
|
44
|
+
throw new Error();
|
|
45
|
+
}
|
|
46
|
+
if (!host.startsWith("[") && (!/^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$/.test(host) || host.split(".").some(
|
|
47
|
+
(label) => !label || label.length > 63 || label.startsWith("-") || label.endsWith("-")
|
|
48
|
+
))) throw new Error();
|
|
49
|
+
const rawHost = authority.startsWith("[") ? authority.slice(0, authority.indexOf("]") + 1) : authority.split(":")[0];
|
|
50
|
+
if (!host.startsWith("[") && host !== rawHost.toLowerCase()) throw new Error();
|
|
51
|
+
const rawPath = value.slice(value.indexOf("://") + 3 + authority.length);
|
|
52
|
+
if (rawPath.includes("//") || /%(?![0-9a-f]{2})|%2f/i.test(rawPath)) throw new Error();
|
|
53
|
+
const decoded = decodePathBytes(rawPath);
|
|
54
|
+
if (hasControls(decoded) || /[\\?#%]/.test(decoded) || decoded.split("/").some((s) => s === "." || s === "..")) {
|
|
55
|
+
throw new Error();
|
|
56
|
+
}
|
|
57
|
+
return `${url.origin}${rawPath.replace(/\/+$/, "")}`;
|
|
58
|
+
} catch {
|
|
59
|
+
throw new Error(message);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function normalizeOverrides(values) {
|
|
63
|
+
if (values === void 0) return {};
|
|
64
|
+
if (values === null || typeof values !== "object" || Array.isArray(values)) throw new Error("Invalid service URL overrides");
|
|
65
|
+
const result = {};
|
|
66
|
+
for (const [service, value] of Object.entries(values)) {
|
|
67
|
+
if (!isServiceName(service)) throw new Error("Invalid service URL overrides: expected known service names");
|
|
68
|
+
result[service] = normalizeBaseUrl(value);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
function joinServiceUrl(base, path) {
|
|
73
|
+
if (hasControls(path) || /[\\?#]/.test(path) || path.includes("://") || path.startsWith("//") || path.split("/").some((segment) => {
|
|
74
|
+
const decoded = decodePathBytes(segment);
|
|
75
|
+
return decoded === "." || decoded === "..";
|
|
76
|
+
})) throw new Error("Invalid service request path");
|
|
77
|
+
return `${base.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
78
|
+
}
|
|
79
|
+
function hasControls(value) {
|
|
80
|
+
return Array.from(value).some((character) => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
|
81
|
+
}
|
|
82
|
+
function decodePathBytes(value) {
|
|
83
|
+
return value.replace(/%([0-9a-f]{2})/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
84
|
+
}
|
|
30
85
|
function assertTimeout(timeout, label = "timeout") {
|
|
31
86
|
if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0) {
|
|
32
87
|
throw new Error(`Invalid HealthCloud SDK ${label}: expected a positive number of milliseconds, got ${String(timeout)}`);
|
|
@@ -62,12 +117,13 @@ var SDKError = class extends Error {
|
|
|
62
117
|
var HttpClient = class {
|
|
63
118
|
constructor(state) {
|
|
64
119
|
this.state = state;
|
|
120
|
+
this.baseUrlOverrides = normalizeOverrides(state.baseUrlOverrides);
|
|
65
121
|
}
|
|
66
122
|
async request(service, method, path, options = {}) {
|
|
67
123
|
var _a, _b;
|
|
68
124
|
const url = this.buildUrl(service, path, options);
|
|
69
125
|
const headers = this.buildHeaders(options);
|
|
70
|
-
const init = { method, headers };
|
|
126
|
+
const init = { method, headers, redirect: "error" };
|
|
71
127
|
if (method !== "GET" && method !== "DELETE" && options.body !== void 0) {
|
|
72
128
|
init.body = this.serializeBody(options.body, headers);
|
|
73
129
|
}
|
|
@@ -84,6 +140,9 @@ var HttpClient = class {
|
|
|
84
140
|
let payload;
|
|
85
141
|
try {
|
|
86
142
|
response = await fetch(url, init);
|
|
143
|
+
if (response.redirected || response.status >= 300 && response.status < 400 || response.type === "opaqueredirect") {
|
|
144
|
+
throw new SDKError({ message: "Service redirects are not allowed", statusCode: response.status });
|
|
145
|
+
}
|
|
87
146
|
payload = await this.parseResponse(response);
|
|
88
147
|
} catch (error) {
|
|
89
148
|
if (didTimeout) {
|
|
@@ -97,7 +156,7 @@ var HttpClient = class {
|
|
|
97
156
|
throw error;
|
|
98
157
|
}
|
|
99
158
|
throw new SDKError({
|
|
100
|
-
message:
|
|
159
|
+
message: "Network request failed.",
|
|
101
160
|
statusCode: 0,
|
|
102
161
|
cause: error
|
|
103
162
|
});
|
|
@@ -133,8 +192,8 @@ var HttpClient = class {
|
|
|
133
192
|
buildUrl(service, path, options) {
|
|
134
193
|
var _a, _b, _c;
|
|
135
194
|
const normalizedPath = this.resolvePath(path, (_a = options.pathParams) != null ? _a : {});
|
|
136
|
-
const base = (_c = (_b = this.
|
|
137
|
-
const url = new URL(
|
|
195
|
+
const base = (_c = (_b = this.baseUrlOverrides) == null ? void 0 : _b[service]) != null ? _c : resolveBaseUrl(this.state.environment, service);
|
|
196
|
+
const url = new URL(joinServiceUrl(base, normalizedPath));
|
|
138
197
|
if (options.query) {
|
|
139
198
|
for (const [key, value] of Object.entries(options.query)) {
|
|
140
199
|
this.appendQuery(url, key, value);
|
|
@@ -7041,7 +7100,7 @@ var HCSDK = class {
|
|
|
7041
7100
|
environment: config.environment,
|
|
7042
7101
|
tenantId: config.tenantId,
|
|
7043
7102
|
accessToken: config.accessToken,
|
|
7044
|
-
baseUrlOverrides: config.baseUrlOverrides,
|
|
7103
|
+
baseUrlOverrides: normalizeOverrides(config.baseUrlOverrides),
|
|
7045
7104
|
timeout: (_b = config.timeout) != null ? _b : DEFAULT_TIMEOUT_MS
|
|
7046
7105
|
};
|
|
7047
7106
|
this.http = new HttpClient(this.state);
|
|
@@ -7214,6 +7273,9 @@ export {
|
|
|
7214
7273
|
assertTimeout,
|
|
7215
7274
|
isJsonRpcError,
|
|
7216
7275
|
isServiceName,
|
|
7276
|
+
joinServiceUrl,
|
|
7277
|
+
normalizeBaseUrl,
|
|
7278
|
+
normalizeOverrides,
|
|
7217
7279
|
resolveBaseUrl,
|
|
7218
7280
|
withTenantId
|
|
7219
7281
|
};
|
package/docs/configuration.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# Configuration
|
|
2
2
|
|
|
3
|
-
- `environment`:
|
|
3
|
+
- `environment`: API defaults use https://{environment}-api-{service}.health.cloud. AMS DEV uses https://dev-ams-services.health.cloud/api/ams (AWS); UAT remains https://uat-amsservices.health.cloud/api/ams and PROD remains https://amsservices.health.cloud/api/ams. No fallback to another deployment.
|
|
4
4
|
- `tenantId`: Tenant used by tenant-aware authentication operations.
|
|
5
5
|
- `accessToken`: Optional bearer token for authenticated APIs.
|
|
6
|
-
- `baseUrlOverrides`: Optional
|
|
6
|
+
- `baseUrlOverrides`: Optional service-to-URL mapping. Complete HTTPS service base URL including any base path (HTTP allowed only for literal loopback 127.0.0.1 or [::1]); trailing slash is normalized. Credentials, query, fragment, ambiguous paths and redirects are refused. TLS verification stays enabled. Overrides are copied per SDK instance and take precedence over environment defaults; configure before construction. An AMS/MCP override does not change patient authentication or Tenant Admin login/refresh URLs. Native fetch must enforce redirect: error and normal certificate validation. Node/browser transport behavior is covered; React Native adapters need a separate runtime verification.
|
|
7
7
|
- `timeout`: Optional request timeout in milliseconds. Defaults to 30000; timed-out requests are aborted and reject with SDKError.
|
|
8
8
|
|
|
9
9
|
## Initialization
|
package/docs/docs-manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"docsDataContentDigest": "sha256:
|
|
2
|
+
"docsDataContentDigest": "sha256:71c4ff351e248aa74fa2dc1635a1c9d4b36f70ff8b78a449a319420451327802",
|
|
3
3
|
"generatedFiles": [
|
|
4
4
|
"authentication.md",
|
|
5
5
|
"clients/AmsClient.md",
|
package/package.json
CHANGED