@fhirfly-io/terminology 0.1.3 → 0.1.5
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 +106 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +99 -22
- package/dist/index.d.ts +99 -22
- package/dist/index.js +106 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -103,12 +103,71 @@ var TimeoutError = class _TimeoutError extends FhirflyError {
|
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
// src/http.ts
|
|
106
|
+
var TokenManager = class {
|
|
107
|
+
credentials;
|
|
108
|
+
accessToken = null;
|
|
109
|
+
expiresAt = 0;
|
|
110
|
+
refreshPromise = null;
|
|
111
|
+
constructor(credentials) {
|
|
112
|
+
this.credentials = credentials;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get a valid access token, refreshing if needed.
|
|
116
|
+
* Deduplicates concurrent refresh calls.
|
|
117
|
+
*/
|
|
118
|
+
async getToken() {
|
|
119
|
+
if (this.accessToken && Date.now() < this.expiresAt) {
|
|
120
|
+
return this.accessToken;
|
|
121
|
+
}
|
|
122
|
+
if (this.refreshPromise) {
|
|
123
|
+
return this.refreshPromise;
|
|
124
|
+
}
|
|
125
|
+
this.refreshPromise = this.fetchToken();
|
|
126
|
+
try {
|
|
127
|
+
return await this.refreshPromise;
|
|
128
|
+
} finally {
|
|
129
|
+
this.refreshPromise = null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Invalidate the cached token (e.g., after a 401 response).
|
|
134
|
+
*/
|
|
135
|
+
invalidate() {
|
|
136
|
+
this.accessToken = null;
|
|
137
|
+
this.expiresAt = 0;
|
|
138
|
+
}
|
|
139
|
+
async fetchToken() {
|
|
140
|
+
const body = new URLSearchParams({
|
|
141
|
+
grant_type: "client_credentials",
|
|
142
|
+
client_id: this.credentials.clientId,
|
|
143
|
+
client_secret: this.credentials.clientSecret
|
|
144
|
+
});
|
|
145
|
+
if (this.credentials.scopes?.length) {
|
|
146
|
+
body.set("scope", this.credentials.scopes.join(" "));
|
|
147
|
+
}
|
|
148
|
+
const response = await fetch(this.credentials.tokenUrl, {
|
|
149
|
+
method: "POST",
|
|
150
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
151
|
+
body: body.toString()
|
|
152
|
+
});
|
|
153
|
+
if (!response.ok) {
|
|
154
|
+
const text = await response.text().catch(() => "");
|
|
155
|
+
throw new AuthenticationError(
|
|
156
|
+
`OAuth2 token exchange failed (${response.status}): ${text}`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const data = await response.json();
|
|
160
|
+
this.accessToken = data.access_token;
|
|
161
|
+
this.expiresAt = Date.now() + (data.expires_in - 60) * 1e3;
|
|
162
|
+
return this.accessToken;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
106
165
|
var HttpClient = class {
|
|
107
166
|
config;
|
|
108
167
|
constructor(config) {
|
|
109
168
|
this.config = {
|
|
110
169
|
baseUrl: config.baseUrl,
|
|
111
|
-
|
|
170
|
+
auth: config.auth,
|
|
112
171
|
timeout: config.timeout ?? 3e4,
|
|
113
172
|
maxRetries: config.maxRetries ?? 3,
|
|
114
173
|
retryDelay: config.retryDelay ?? 1e3,
|
|
@@ -182,10 +241,20 @@ var HttpClient = class {
|
|
|
182
241
|
sleep(ms) {
|
|
183
242
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
184
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Get auth headers for the current request.
|
|
246
|
+
*/
|
|
247
|
+
async getAuthHeaders() {
|
|
248
|
+
if (this.config.auth.type === "api-key") {
|
|
249
|
+
return { "x-api-key": this.config.auth.apiKey };
|
|
250
|
+
}
|
|
251
|
+
const token = await this.config.auth.tokenManager.getToken();
|
|
252
|
+
return { "Authorization": `Bearer ${token}` };
|
|
253
|
+
}
|
|
185
254
|
/**
|
|
186
255
|
* Make an HTTP request with retries.
|
|
187
256
|
*/
|
|
188
|
-
async request(method, endpoint, body) {
|
|
257
|
+
async request(method, endpoint, body, isRetryAfter401 = false) {
|
|
189
258
|
const url = `${this.config.baseUrl}${endpoint}`;
|
|
190
259
|
let lastError;
|
|
191
260
|
for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
|
|
@@ -195,10 +264,11 @@ var HttpClient = class {
|
|
|
195
264
|
() => controller.abort(),
|
|
196
265
|
this.config.timeout
|
|
197
266
|
);
|
|
267
|
+
const authHeaders = await this.getAuthHeaders();
|
|
198
268
|
const response = await fetch(url, {
|
|
199
269
|
method,
|
|
200
270
|
headers: {
|
|
201
|
-
|
|
271
|
+
...authHeaders,
|
|
202
272
|
"Content-Type": "application/json",
|
|
203
273
|
"User-Agent": this.config.userAgent,
|
|
204
274
|
"Accept": "application/json"
|
|
@@ -208,6 +278,10 @@ var HttpClient = class {
|
|
|
208
278
|
});
|
|
209
279
|
clearTimeout(timeoutId);
|
|
210
280
|
if (!response.ok) {
|
|
281
|
+
if (response.status === 401 && this.config.auth.type === "oauth" && !isRetryAfter401) {
|
|
282
|
+
this.config.auth.tokenManager.invalidate();
|
|
283
|
+
return this.request(method, endpoint, body, true);
|
|
284
|
+
}
|
|
211
285
|
if (response.status < 500 && response.status !== 429) {
|
|
212
286
|
await this.parseErrorResponse(response, endpoint);
|
|
213
287
|
}
|
|
@@ -675,22 +749,39 @@ var Fhirfly = class {
|
|
|
675
749
|
/**
|
|
676
750
|
* Create a new FHIRfly client.
|
|
677
751
|
*
|
|
678
|
-
* @param config - Client configuration
|
|
679
|
-
* @throws {Error} If apiKey is
|
|
752
|
+
* @param config - Client configuration (API key or OAuth2 client credentials)
|
|
753
|
+
* @throws {Error} If neither apiKey nor clientId+clientSecret is provided
|
|
680
754
|
*/
|
|
681
755
|
constructor(config) {
|
|
682
|
-
|
|
756
|
+
const baseUrl = config.baseUrl ?? "https://api.fhirfly.io";
|
|
757
|
+
let httpConfig;
|
|
758
|
+
if ("apiKey" in config && config.apiKey) {
|
|
759
|
+
httpConfig = {
|
|
760
|
+
baseUrl,
|
|
761
|
+
auth: { type: "api-key", apiKey: config.apiKey },
|
|
762
|
+
timeout: config.timeout,
|
|
763
|
+
maxRetries: config.maxRetries,
|
|
764
|
+
retryDelay: config.retryDelay
|
|
765
|
+
};
|
|
766
|
+
} else if ("clientId" in config && config.clientId && config.clientSecret) {
|
|
767
|
+
const tokenManager = new TokenManager({
|
|
768
|
+
clientId: config.clientId,
|
|
769
|
+
clientSecret: config.clientSecret,
|
|
770
|
+
tokenUrl: config.tokenUrl ?? `${baseUrl}/oauth2/token`,
|
|
771
|
+
scopes: config.scopes
|
|
772
|
+
});
|
|
773
|
+
httpConfig = {
|
|
774
|
+
baseUrl,
|
|
775
|
+
auth: { type: "oauth", tokenManager },
|
|
776
|
+
timeout: config.timeout,
|
|
777
|
+
maxRetries: config.maxRetries,
|
|
778
|
+
retryDelay: config.retryDelay
|
|
779
|
+
};
|
|
780
|
+
} else {
|
|
683
781
|
throw new Error(
|
|
684
|
-
"FHIRfly
|
|
782
|
+
"FHIRfly requires either an apiKey or clientId+clientSecret. Get credentials at https://fhirfly.io/dashboard"
|
|
685
783
|
);
|
|
686
784
|
}
|
|
687
|
-
const httpConfig = {
|
|
688
|
-
baseUrl: config.baseUrl ?? "https://api.fhirfly.io",
|
|
689
|
-
apiKey: config.apiKey,
|
|
690
|
-
timeout: config.timeout,
|
|
691
|
-
maxRetries: config.maxRetries,
|
|
692
|
-
retryDelay: config.retryDelay
|
|
693
|
-
};
|
|
694
785
|
this.http = new HttpClient(httpConfig);
|
|
695
786
|
this.ndc = new NdcEndpoint(this.http);
|
|
696
787
|
this.npi = new NpiEndpoint(this.http);
|
|
@@ -713,6 +804,7 @@ exports.QuotaExceededError = QuotaExceededError;
|
|
|
713
804
|
exports.RateLimitError = RateLimitError;
|
|
714
805
|
exports.ServerError = ServerError;
|
|
715
806
|
exports.TimeoutError = TimeoutError;
|
|
807
|
+
exports.TokenManager = TokenManager;
|
|
716
808
|
exports.ValidationError = ValidationError;
|
|
717
809
|
//# sourceMappingURL=index.cjs.map
|
|
718
810
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/endpoints/ndc.ts","../src/endpoints/npi.ts","../src/endpoints/rxnorm.ts","../src/endpoints/loinc.ts","../src/endpoints/icd10.ts","../src/endpoints/cvx.ts","../src/endpoints/mvx.ts","../src/endpoints/fda-labels.ts","../src/client.ts"],"names":[],"mappings":";;;AAGO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AACZ,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,aAAA,CAAa,SAAS,CAAA;AAAA,EACpD;AACF;AAKO,IAAM,QAAA,GAAN,MAAM,SAAA,SAAiB,YAAA,CAAa;AAAA,EAChC,UAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA,EAET,WAAA,CACE,OAAA,EACA,UAAA,EACA,IAAA,EACA,OAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AACZ,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAClB,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AACf,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,SAAA,CAAS,SAAS,CAAA;AAAA,EAChD;AACF;AAKO,IAAM,mBAAA,GAAN,MAAM,oBAAA,SAA4B,QAAA,CAAS;AAAA,EAChD,WAAA,CAAY,UAAU,4CAAA,EAA8C;AAClE,IAAA,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,IAAA,GAAO,IAAI,UAAA,CAAW,UAAU,CAAA;AAGrC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,IAAI,cAAA,CAAe,IAAA,CAAK,IAAI,CAAA;AAC1C,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,iBAAA,CAAkB,IAAA,CAAK,IAAI,CAAA;AAAA,EAClD;AACF","file":"index.cjs","sourcesContent":["/**\n * Base error class for all FHIRfly SDK errors.\n */\nexport class FhirflyError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"FhirflyError\";\n Object.setPrototypeOf(this, FhirflyError.prototype);\n }\n}\n\n/**\n * Error thrown when the API returns an error response.\n */\nexport class ApiError extends FhirflyError {\n readonly statusCode: number;\n readonly code?: string;\n readonly details?: unknown;\n\n constructor(\n message: string,\n statusCode: number,\n code?: string,\n details?: unknown\n ) {\n super(message);\n this.name = \"ApiError\";\n this.statusCode = statusCode;\n this.code = code;\n this.details = details;\n Object.setPrototypeOf(this, ApiError.prototype);\n }\n}\n\n/**\n * Error thrown when authentication fails (401).\n */\nexport class AuthenticationError extends ApiError {\n constructor(message = \"Authentication failed. Check your API key.\") {\n super(message, 401, \"AUTHENTICATION_ERROR\");\n this.name = \"AuthenticationError\";\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n\n/**\n * Error thrown when a resource is not found (404).\n */\nexport class NotFoundError extends ApiError {\n readonly code_type: string;\n readonly code_value: string;\n\n constructor(codeType: string, codeValue: string) {\n super(`${codeType} not found: ${codeValue}`, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n this.code_type = codeType;\n this.code_value = codeValue;\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n\n/**\n * Error thrown when the request is invalid (400).\n */\nexport class ValidationError extends ApiError {\n readonly field?: string;\n\n constructor(message: string, field?: string) {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n this.field = field;\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\n/**\n * Error thrown when rate limited (429).\n */\nexport class RateLimitError extends ApiError {\n readonly retryAfter?: number;\n readonly limit?: number;\n readonly remaining?: number;\n readonly reset?: Date;\n\n constructor(\n message = \"Rate limit exceeded\",\n retryAfter?: number,\n limit?: number,\n remaining?: number,\n reset?: Date\n ) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n this.limit = limit;\n this.remaining = remaining;\n this.reset = reset;\n Object.setPrototypeOf(this, RateLimitError.prototype);\n }\n}\n\n/**\n * Error thrown when quota is exceeded (429 with quota context).\n */\nexport class QuotaExceededError extends ApiError {\n readonly quotaLimit?: number;\n readonly quotaUsed?: number;\n readonly quotaResetDate?: Date;\n\n constructor(\n message = \"Monthly quota exceeded\",\n quotaLimit?: number,\n quotaUsed?: number,\n quotaResetDate?: Date\n ) {\n super(message, 429, \"QUOTA_EXCEEDED\");\n this.name = \"QuotaExceededError\";\n this.quotaLimit = quotaLimit;\n this.quotaUsed = quotaUsed;\n this.quotaResetDate = quotaResetDate;\n Object.setPrototypeOf(this, QuotaExceededError.prototype);\n }\n}\n\n/**\n * Error thrown when the server returns a 5xx error.\n */\nexport class ServerError extends ApiError {\n constructor(message = \"Server error\", statusCode = 500) {\n super(message, statusCode, \"SERVER_ERROR\");\n this.name = \"ServerError\";\n Object.setPrototypeOf(this, ServerError.prototype);\n }\n}\n\n/**\n * Error thrown when a network error occurs.\n */\nexport class NetworkError extends FhirflyError {\n readonly cause?: Error;\n\n constructor(message = \"Network error\", cause?: Error) {\n super(message);\n this.name = \"NetworkError\";\n this.cause = cause;\n Object.setPrototypeOf(this, NetworkError.prototype);\n }\n}\n\n/**\n * Error thrown when a request times out.\n */\nexport class TimeoutError extends FhirflyError {\n readonly timeoutMs: number;\n\n constructor(timeoutMs: number) {\n super(`Request timed out after ${timeoutMs}ms`);\n this.name = \"TimeoutError\";\n this.timeoutMs = timeoutMs;\n Object.setPrototypeOf(this, TimeoutError.prototype);\n }\n}\n","import {\n ApiError,\n AuthenticationError,\n NetworkError,\n NotFoundError,\n QuotaExceededError,\n RateLimitError,\n ServerError,\n TimeoutError,\n ValidationError,\n} from \"./errors.js\";\nimport type { LookupOptions } from \"./types/common.js\";\n\n/**\n * HTTP client configuration.\n */\nexport interface HttpClientConfig {\n baseUrl: string;\n apiKey: string;\n timeout?: number;\n maxRetries?: number;\n retryDelay?: number;\n userAgent?: string;\n}\n\n/**\n * HTTP response from the API.\n */\ninterface HttpResponse<T> {\n data: T;\n status: number;\n headers: Headers;\n}\n\n/**\n * Internal HTTP client for making API requests.\n */\nexport class HttpClient {\n private readonly config: Required<HttpClientConfig>;\n\n constructor(config: HttpClientConfig) {\n this.config = {\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n timeout: config.timeout ?? 30000,\n maxRetries: config.maxRetries ?? 3,\n retryDelay: config.retryDelay ?? 1000,\n userAgent: config.userAgent ?? `@fhirfly/sdk/0.1.0 Node.js/${process.version}`,\n };\n }\n\n /**\n * Build query string from options.\n */\n private buildQueryString(options?: LookupOptions): string {\n if (!options) return \"\";\n\n const params = new URLSearchParams();\n\n if (options.shape) {\n params.set(\"shape\", options.shape);\n }\n\n if (options.include?.length) {\n params.set(\"include\", options.include.join(\",\"));\n }\n\n const queryString = params.toString();\n return queryString ? `?${queryString}` : \"\";\n }\n\n /**\n * Parse error response from API.\n */\n private async parseErrorResponse(\n response: Response,\n endpoint: string\n ): Promise<never> {\n const status = response.status;\n let body: { message?: string; code?: string; error?: string; details?: unknown } = {};\n\n try {\n body = await response.json() as typeof body;\n } catch {\n // Response body is not JSON\n }\n\n const message = body.message || body.error || response.statusText;\n\n // Handle specific status codes\n switch (status) {\n case 401:\n throw new AuthenticationError(message);\n\n case 404: {\n // Extract code type and value from endpoint\n const match = endpoint.match(/\\/v1\\/(\\w+)\\/(.+)/);\n if (match) {\n throw new NotFoundError(match[1]!.toUpperCase(), match[2]!);\n }\n throw new NotFoundError(\"Resource\", endpoint);\n }\n\n case 400:\n throw new ValidationError(message);\n\n case 429: {\n const retryAfter = response.headers.get(\"retry-after\");\n const limit = response.headers.get(\"x-ratelimit-limit\");\n const remaining = response.headers.get(\"x-ratelimit-remaining\");\n const reset = response.headers.get(\"x-ratelimit-reset\");\n\n // Check if it's a quota error vs rate limit\n if (body.code === \"QUOTA_EXCEEDED\") {\n throw new QuotaExceededError(message);\n }\n\n throw new RateLimitError(\n message,\n retryAfter ? parseInt(retryAfter, 10) : undefined,\n limit ? parseInt(limit, 10) : undefined,\n remaining ? parseInt(remaining, 10) : undefined,\n reset ? new Date(parseInt(reset, 10) * 1000) : undefined\n );\n }\n\n default:\n if (status >= 500) {\n throw new ServerError(message, status);\n }\n throw new ApiError(message, status, body.code, body.details);\n }\n }\n\n /**\n * Sleep for a given number of milliseconds.\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Make an HTTP request with retries.\n */\n private async request<T>(\n method: \"GET\" | \"POST\",\n endpoint: string,\n body?: unknown\n ): Promise<HttpResponse<T>> {\n const url = `${this.config.baseUrl}${endpoint}`;\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n this.config.timeout\n );\n\n const response = await fetch(url, {\n method,\n headers: {\n \"Authorization\": `Bearer ${this.config.apiKey}`,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": this.config.userAgent,\n \"Accept\": \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n // Don't retry client errors (except rate limits)\n if (response.status < 500 && response.status !== 429) {\n await this.parseErrorResponse(response, endpoint);\n }\n\n // For rate limits, check retry-after header\n if (response.status === 429) {\n const retryAfter = response.headers.get(\"retry-after\");\n if (retryAfter && attempt < this.config.maxRetries) {\n await this.sleep(parseInt(retryAfter, 10) * 1000);\n continue;\n }\n await this.parseErrorResponse(response, endpoint);\n }\n\n // Retry server errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n\n await this.parseErrorResponse(response, endpoint);\n }\n\n const data = await response.json() as T;\n return { data, status: response.status, headers: response.headers };\n } catch (error) {\n if (error instanceof ApiError) {\n throw error;\n }\n\n if (error instanceof Error) {\n if (error.name === \"AbortError\") {\n throw new TimeoutError(this.config.timeout);\n }\n\n lastError = error;\n\n // Retry on network errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Unknown network error\",\n lastError\n );\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Request failed after retries\",\n lastError\n );\n }\n\n /**\n * Make a GET request.\n */\n async get<T>(endpoint: string, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"GET\", `${endpoint}${queryString}`);\n return response.data;\n }\n\n /**\n * Make a POST request.\n */\n async post<T>(endpoint: string, body: unknown, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"POST\", `${endpoint}${queryString}`, body);\n return response.data;\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NdcData } from \"../types/ndc.js\";\n\n/**\n * NDC (National Drug Code) API endpoint.\n */\nexport class NdcEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NDC code.\n *\n * @param code - NDC code (10-digit, 11-digit, or hyphenated format)\n * @param options - Response shape and include options\n * @returns NDC data\n *\n * @example\n * ```ts\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n * ```\n */\n async lookup(code: string, options?: LookupOptions): Promise<ApiResponse<NdcData>> {\n return this.http.get<ApiResponse<NdcData>>(`/v1/ndc/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple NDC codes in a single request.\n *\n * @param codes - Array of NDC codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n *\n * @example\n * ```ts\n * const results = await client.ndc.lookupMany([\n * \"0069-0151-01\",\n * \"0069-0151-02\",\n * \"invalid-code\"\n * ]);\n *\n * for (const item of results.results) {\n * if (item.found) {\n * console.log(item.data.product_name);\n * } else {\n * console.log(`Not found: ${item.code}`);\n * }\n * }\n * ```\n */\n async lookupMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NdcData>> {\n return this.http.post<BatchResponse<NdcData>>(\n \"/v1/ndc/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NpiData } from \"../types/npi.js\";\n\n/**\n * NPI (National Provider Identifier) API endpoint.\n */\nexport class NpiEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NPI.\n *\n * @param npi - 10-digit NPI number\n * @param options - Response shape and include options\n * @returns NPI data\n *\n * @example\n * ```ts\n * const npi = await client.npi.lookup(\"1234567890\");\n * console.log(npi.data.name);\n * ```\n */\n async lookup(npi: string, options?: LookupOptions): Promise<ApiResponse<NpiData>> {\n return this.http.get<ApiResponse<NpiData>>(`/v1/npi/${encodeURIComponent(npi)}`, options);\n }\n\n /**\n * Look up multiple NPIs in a single request.\n *\n * @param npis - Array of 10-digit NPI numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each NPI\n *\n * @example\n * ```ts\n * const results = await client.npi.lookupMany([\n * \"1234567890\",\n * \"0987654321\"\n * ]);\n * ```\n */\n async lookupMany(\n npis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NpiData>> {\n return this.http.post<BatchResponse<NpiData>>(\n \"/v1/npi/_batch\",\n { codes: npis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { RxNormData } from \"../types/rxnorm.js\";\n\n/**\n * RxNorm API endpoint.\n */\nexport class RxNormEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single RxCUI.\n *\n * @param rxcui - RxNorm Concept Unique Identifier\n * @param options - Response shape and include options\n * @returns RxNorm data\n *\n * @example\n * ```ts\n * const rx = await client.rxnorm.lookup(\"213169\");\n * console.log(rx.data.name); // \"atorvastatin 10 MG Oral Tablet\"\n * ```\n */\n async lookup(rxcui: string, options?: LookupOptions): Promise<ApiResponse<RxNormData>> {\n return this.http.get<ApiResponse<RxNormData>>(`/v1/rxnorm/${encodeURIComponent(rxcui)}`, options);\n }\n\n /**\n * Look up multiple RxCUIs in a single request.\n *\n * @param rxcuis - Array of RxCUIs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each RxCUI\n */\n async lookupMany(\n rxcuis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<RxNormData>> {\n return this.http.post<BatchResponse<RxNormData>>(\n \"/v1/rxnorm/_batch\",\n { codes: rxcuis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { LoincData } from \"../types/loinc.js\";\n\n/**\n * LOINC API endpoint.\n */\nexport class LoincEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single LOINC code.\n *\n * @param loincNum - LOINC number (e.g., \"2345-7\")\n * @param options - Response shape and include options\n * @returns LOINC data\n *\n * @example\n * ```ts\n * const loinc = await client.loinc.lookup(\"2345-7\");\n * console.log(loinc.data.long_common_name); // \"Glucose [Mass/volume] in Serum or Plasma\"\n * ```\n */\n async lookup(loincNum: string, options?: LookupOptions): Promise<ApiResponse<LoincData>> {\n return this.http.get<ApiResponse<LoincData>>(`/v1/loinc/${encodeURIComponent(loincNum)}`, options);\n }\n\n /**\n * Look up multiple LOINC codes in a single request.\n *\n * @param loincNums - Array of LOINC numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each LOINC\n */\n async lookupMany(\n loincNums: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<LoincData>> {\n return this.http.post<BatchResponse<LoincData>>(\n \"/v1/loinc/_batch\",\n { codes: loincNums },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { Icd10Data } from \"../types/icd10.js\";\n\n/**\n * ICD-10 API endpoint.\n */\nexport class Icd10Endpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single ICD-10-CM code (diagnoses).\n *\n * @param code - ICD-10-CM code (e.g., \"E11.9\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupCm(\"E11.9\");\n * console.log(icd.data.description); // \"Type 2 diabetes mellitus without complications\"\n * ```\n */\n async lookupCm(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/cm/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up a single ICD-10-PCS code (procedures).\n *\n * @param code - ICD-10-PCS code (e.g., \"0BJ08ZZ\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupPcs(\"0BJ08ZZ\");\n * console.log(icd.data.description);\n * ```\n */\n async lookupPcs(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/pcs/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple ICD-10-CM codes in a single request.\n *\n * @param codes - Array of ICD-10-CM codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupCmMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/cm/_batch\",\n { codes },\n options\n );\n }\n\n /**\n * Look up multiple ICD-10-PCS codes in a single request.\n *\n * @param codes - Array of ICD-10-PCS codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupPcsMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/pcs/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { CvxData } from \"../types/cvx.js\";\n\n/**\n * CVX (Vaccine Codes) API endpoint.\n */\nexport class CvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single CVX code.\n *\n * @param cvxCode - CVX vaccine code\n * @param options - Response shape and include options\n * @returns CVX data\n *\n * @example\n * ```ts\n * const cvx = await client.cvx.lookup(\"208\");\n * console.log(cvx.data.short_description); // \"COVID-19, mRNA, LNP-S, PF, 30 mcg/0.3 mL dose\"\n * ```\n */\n async lookup(cvxCode: string, options?: LookupOptions): Promise<ApiResponse<CvxData>> {\n return this.http.get<ApiResponse<CvxData>>(`/v1/cvx/${encodeURIComponent(cvxCode)}`, options);\n }\n\n /**\n * Look up multiple CVX codes in a single request.\n *\n * @param cvxCodes - Array of CVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n cvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<CvxData>> {\n return this.http.post<BatchResponse<CvxData>>(\n \"/v1/cvx/_batch\",\n { codes: cvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { MvxData } from \"../types/mvx.js\";\n\n/**\n * MVX (Vaccine Manufacturer Codes) API endpoint.\n */\nexport class MvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single MVX code.\n *\n * @param mvxCode - MVX manufacturer code\n * @param options - Response shape and include options\n * @returns MVX data\n *\n * @example\n * ```ts\n * const mvx = await client.mvx.lookup(\"PFR\");\n * console.log(mvx.data.manufacturer_name); // \"Pfizer, Inc\"\n * ```\n */\n async lookup(mvxCode: string, options?: LookupOptions): Promise<ApiResponse<MvxData>> {\n return this.http.get<ApiResponse<MvxData>>(`/v1/mvx/${encodeURIComponent(mvxCode)}`, options);\n }\n\n /**\n * Look up multiple MVX codes in a single request.\n *\n * @param mvxCodes - Array of MVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n mvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<MvxData>> {\n return this.http.post<BatchResponse<MvxData>>(\n \"/v1/mvx/_batch\",\n { codes: mvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { FdaLabelData } from \"../types/fda-labels.js\";\n\n/**\n * FDA Labels API endpoint.\n */\nexport class FdaLabelsEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up FDA label by Set ID.\n *\n * @param setId - FDA SPL Set ID\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookup(\"abc123-def456\");\n * console.log(label.data.indications_and_usage);\n * ```\n */\n async lookup(setId: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/${encodeURIComponent(setId)}`, options);\n }\n\n /**\n * Look up FDA label by NDC code.\n *\n * @param ndc - NDC code\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookupByNdc(\"0069-0151-01\");\n * console.log(label.data.product_name);\n * ```\n */\n async lookupByNdc(ndc: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/ndc/${encodeURIComponent(ndc)}`, options);\n }\n\n /**\n * Look up multiple FDA labels by Set IDs in a single request.\n *\n * @param setIds - Array of Set IDs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each Set ID\n */\n async lookupMany(\n setIds: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<FdaLabelData>> {\n return this.http.post<BatchResponse<FdaLabelData>>(\n \"/v1/fda-labels/_batch\",\n { codes: setIds },\n options\n );\n }\n}\n","import { HttpClient, type HttpClientConfig } from \"./http.js\";\nimport { NdcEndpoint } from \"./endpoints/ndc.js\";\nimport { NpiEndpoint } from \"./endpoints/npi.js\";\nimport { RxNormEndpoint } from \"./endpoints/rxnorm.js\";\nimport { LoincEndpoint } from \"./endpoints/loinc.js\";\nimport { Icd10Endpoint } from \"./endpoints/icd10.js\";\nimport { CvxEndpoint } from \"./endpoints/cvx.js\";\nimport { MvxEndpoint } from \"./endpoints/mvx.js\";\nimport { FdaLabelsEndpoint } from \"./endpoints/fda-labels.js\";\n\n/**\n * Configuration options for the FHIRfly client.\n */\nexport interface FhirflyConfig {\n /**\n * Your FHIRfly API key.\n * Get one at https://fhirfly.io/dashboard\n */\n apiKey: string;\n\n /**\n * Base URL for the API.\n * @default \"https://api.fhirfly.io\"\n */\n baseUrl?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n\n /**\n * Maximum number of retry attempts for failed requests.\n * @default 3\n */\n maxRetries?: number;\n\n /**\n * Base delay between retries in milliseconds (exponential backoff).\n * @default 1000\n */\n retryDelay?: number;\n}\n\n/**\n * FHIRfly API client.\n *\n * Provides access to healthcare reference data including drug codes (NDC, RxNorm),\n * provider identifiers (NPI), lab codes (LOINC), diagnosis codes (ICD-10),\n * vaccine codes (CVX, MVX), and FDA drug labels.\n *\n * @example\n * ```ts\n * import { Fhirfly } from \"@fhirfly/sdk\";\n *\n * const client = new Fhirfly({ apiKey: \"your-api-key\" });\n *\n * // Look up a drug by NDC\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n *\n * // Look up a provider by NPI\n * const npi = await client.npi.lookup(\"1234567890\");\n * console.log(npi.data.name);\n *\n * // Batch lookups\n * const results = await client.ndc.lookupMany([\n * \"0069-0151-01\",\n * \"0069-0151-02\"\n * ]);\n * ```\n */\nexport class Fhirfly {\n private readonly http: HttpClient;\n\n /**\n * NDC (National Drug Code) lookups.\n */\n readonly ndc: NdcEndpoint;\n\n /**\n * NPI (National Provider Identifier) lookups.\n */\n readonly npi: NpiEndpoint;\n\n /**\n * RxNorm drug terminology lookups.\n */\n readonly rxnorm: RxNormEndpoint;\n\n /**\n * LOINC laboratory and clinical observation code lookups.\n */\n readonly loinc: LoincEndpoint;\n\n /**\n * ICD-10 diagnosis and procedure code lookups.\n */\n readonly icd10: Icd10Endpoint;\n\n /**\n * CVX vaccine code lookups.\n */\n readonly cvx: CvxEndpoint;\n\n /**\n * MVX vaccine manufacturer code lookups.\n */\n readonly mvx: MvxEndpoint;\n\n /**\n * FDA drug label lookups.\n */\n readonly fdaLabels: FdaLabelsEndpoint;\n\n /**\n * Create a new FHIRfly client.\n *\n * @param config - Client configuration\n * @throws {Error} If apiKey is not provided\n */\n constructor(config: FhirflyConfig) {\n if (!config.apiKey) {\n throw new Error(\n \"FHIRfly API key is required. Get one at https://fhirfly.io/dashboard\"\n );\n }\n\n const httpConfig: HttpClientConfig = {\n baseUrl: config.baseUrl ?? \"https://api.fhirfly.io\",\n apiKey: config.apiKey,\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n };\n\n this.http = new HttpClient(httpConfig);\n\n // Initialize endpoints\n this.ndc = new NdcEndpoint(this.http);\n this.npi = new NpiEndpoint(this.http);\n this.rxnorm = new RxNormEndpoint(this.http);\n this.loinc = new LoincEndpoint(this.http);\n this.icd10 = new Icd10Endpoint(this.http);\n this.cvx = new CvxEndpoint(this.http);\n this.mvx = new MvxEndpoint(this.http);\n this.fdaLabels = new FdaLabelsEndpoint(this.http);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/endpoints/ndc.ts","../src/endpoints/npi.ts","../src/endpoints/rxnorm.ts","../src/endpoints/loinc.ts","../src/endpoints/icd10.ts","../src/endpoints/cvx.ts","../src/endpoints/mvx.ts","../src/endpoints/fda-labels.ts","../src/client.ts"],"names":[],"mappings":";;;AAGO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO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;AAAA,OAChB,CAAA;AACD,MAAA,UAAA,GAAa;AAAA,QACX,OAAA;AAAA,QACA,IAAA,EAAM,EAAE,IAAA,EAAM,OAAA,EAAS,YAAA,EAAa;AAAA,QACpC,SAAS,MAAA,CAAO,OAAA;AAAA,QAChB,YAAY,MAAA,CAAO,UAAA;AAAA,QACnB,YAAY,MAAA,CAAO;AAAA,OACrB;AAAA,IACF,CAAA,MAAO;AACL,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,IAAA,GAAO,IAAI,UAAA,CAAW,UAAU,CAAA;AAGrC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,IAAI,cAAA,CAAe,IAAA,CAAK,IAAI,CAAA;AAC1C,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,iBAAA,CAAkB,IAAA,CAAK,IAAI,CAAA;AAAA,EAClD;AACF","file":"index.cjs","sourcesContent":["/**\n * Base error class for all FHIRfly SDK errors.\n */\nexport class FhirflyError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"FhirflyError\";\n Object.setPrototypeOf(this, FhirflyError.prototype);\n }\n}\n\n/**\n * Error thrown when the API returns an error response.\n */\nexport class ApiError extends FhirflyError {\n readonly statusCode: number;\n readonly code?: string;\n readonly details?: unknown;\n\n constructor(\n message: string,\n statusCode: number,\n code?: string,\n details?: unknown\n ) {\n super(message);\n this.name = \"ApiError\";\n this.statusCode = statusCode;\n this.code = code;\n this.details = details;\n Object.setPrototypeOf(this, ApiError.prototype);\n }\n}\n\n/**\n * Error thrown when authentication fails (401).\n */\nexport class AuthenticationError extends ApiError {\n constructor(message = \"Authentication failed. Check your API key.\") {\n super(message, 401, \"AUTHENTICATION_ERROR\");\n this.name = \"AuthenticationError\";\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n\n/**\n * Error thrown when a resource is not found (404).\n */\nexport class NotFoundError extends ApiError {\n readonly code_type: string;\n readonly code_value: string;\n\n constructor(codeType: string, codeValue: string) {\n super(`${codeType} not found: ${codeValue}`, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n this.code_type = codeType;\n this.code_value = codeValue;\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n\n/**\n * Error thrown when the request is invalid (400).\n */\nexport class ValidationError extends ApiError {\n readonly field?: string;\n\n constructor(message: string, field?: string) {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n this.field = field;\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\n/**\n * Error thrown when rate limited (429).\n */\nexport class RateLimitError extends ApiError {\n readonly retryAfter?: number;\n readonly limit?: number;\n readonly remaining?: number;\n readonly reset?: Date;\n\n constructor(\n message = \"Rate limit exceeded\",\n retryAfter?: number,\n limit?: number,\n remaining?: number,\n reset?: Date\n ) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n this.limit = limit;\n this.remaining = remaining;\n this.reset = reset;\n Object.setPrototypeOf(this, RateLimitError.prototype);\n }\n}\n\n/**\n * Error thrown when quota is exceeded (429 with quota context).\n */\nexport class QuotaExceededError extends ApiError {\n readonly quotaLimit?: number;\n readonly quotaUsed?: number;\n readonly quotaResetDate?: Date;\n\n constructor(\n message = \"Monthly quota exceeded\",\n quotaLimit?: number,\n quotaUsed?: number,\n quotaResetDate?: Date\n ) {\n super(message, 429, \"QUOTA_EXCEEDED\");\n this.name = \"QuotaExceededError\";\n this.quotaLimit = quotaLimit;\n this.quotaUsed = quotaUsed;\n this.quotaResetDate = quotaResetDate;\n Object.setPrototypeOf(this, QuotaExceededError.prototype);\n }\n}\n\n/**\n * Error thrown when the server returns a 5xx error.\n */\nexport class ServerError extends ApiError {\n constructor(message = \"Server error\", statusCode = 500) {\n super(message, statusCode, \"SERVER_ERROR\");\n this.name = \"ServerError\";\n Object.setPrototypeOf(this, ServerError.prototype);\n }\n}\n\n/**\n * Error thrown when a network error occurs.\n */\nexport class NetworkError extends FhirflyError {\n readonly cause?: Error;\n\n constructor(message = \"Network error\", cause?: Error) {\n super(message);\n this.name = \"NetworkError\";\n this.cause = cause;\n Object.setPrototypeOf(this, NetworkError.prototype);\n }\n}\n\n/**\n * Error thrown when a request times out.\n */\nexport class TimeoutError extends FhirflyError {\n readonly timeoutMs: number;\n\n constructor(timeoutMs: number) {\n super(`Request timed out after ${timeoutMs}ms`);\n this.name = \"TimeoutError\";\n this.timeoutMs = timeoutMs;\n Object.setPrototypeOf(this, TimeoutError.prototype);\n }\n}\n","import {\n ApiError,\n AuthenticationError,\n NetworkError,\n NotFoundError,\n QuotaExceededError,\n RateLimitError,\n ServerError,\n TimeoutError,\n ValidationError,\n} from \"./errors.js\";\nimport type { LookupOptions } from \"./types/common.js\";\n\n/**\n * OAuth2 token response from the token endpoint.\n */\ninterface TokenResponse {\n access_token: string;\n token_type: string;\n expires_in: number;\n scope?: string;\n}\n\n/**\n * OAuth2 client credentials configuration.\n */\nexport interface OAuthCredentials {\n clientId: string;\n clientSecret: string;\n tokenUrl: string;\n scopes?: string[];\n}\n\n/**\n * Manages OAuth2 access tokens with automatic refresh.\n */\nexport class TokenManager {\n private readonly credentials: OAuthCredentials;\n private accessToken: string | null = null;\n private expiresAt = 0;\n private refreshPromise: Promise<string> | null = null;\n\n constructor(credentials: OAuthCredentials) {\n this.credentials = credentials;\n }\n\n /**\n * Get a valid access token, refreshing if needed.\n * Deduplicates concurrent refresh calls.\n */\n async getToken(): Promise<string> {\n if (this.accessToken && Date.now() < this.expiresAt) {\n return this.accessToken;\n }\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n this.refreshPromise = this.fetchToken();\n try {\n return await this.refreshPromise;\n } finally {\n this.refreshPromise = null;\n }\n }\n\n /**\n * Invalidate the cached token (e.g., after a 401 response).\n */\n invalidate(): void {\n this.accessToken = null;\n this.expiresAt = 0;\n }\n\n private async fetchToken(): Promise<string> {\n const body = new URLSearchParams({\n grant_type: \"client_credentials\",\n client_id: this.credentials.clientId,\n client_secret: this.credentials.clientSecret,\n });\n if (this.credentials.scopes?.length) {\n body.set(\"scope\", this.credentials.scopes.join(\" \"));\n }\n\n const response = await fetch(this.credentials.tokenUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body: body.toString(),\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n throw new AuthenticationError(\n `OAuth2 token exchange failed (${response.status}): ${text}`\n );\n }\n\n const data = (await response.json()) as TokenResponse;\n this.accessToken = data.access_token;\n // Refresh 60s before expiry\n this.expiresAt = Date.now() + (data.expires_in - 60) * 1000;\n return this.accessToken;\n }\n}\n\n/**\n * Authentication mode for the HTTP client.\n */\ntype AuthMode =\n | { type: \"api-key\"; apiKey: string }\n | { type: \"oauth\"; tokenManager: TokenManager };\n\n/**\n * HTTP client configuration.\n */\nexport interface HttpClientConfig {\n baseUrl: string;\n auth: AuthMode;\n timeout?: number;\n maxRetries?: number;\n retryDelay?: number;\n userAgent?: string;\n}\n\n/**\n * HTTP response from the API.\n */\ninterface HttpResponse<T> {\n data: T;\n status: number;\n headers: Headers;\n}\n\n/**\n * Internal HTTP client for making API requests.\n */\nexport class HttpClient {\n private readonly config: Required<Omit<HttpClientConfig, \"auth\">> & { auth: AuthMode };\n\n constructor(config: HttpClientConfig) {\n this.config = {\n baseUrl: config.baseUrl,\n auth: config.auth,\n timeout: config.timeout ?? 30000,\n maxRetries: config.maxRetries ?? 3,\n retryDelay: config.retryDelay ?? 1000,\n userAgent: config.userAgent ?? `@fhirfly/sdk/0.1.0 Node.js/${process.version}`,\n };\n }\n\n /**\n * Build query string from options.\n */\n private buildQueryString(options?: LookupOptions): string {\n if (!options) return \"\";\n\n const params = new URLSearchParams();\n\n if (options.shape) {\n params.set(\"shape\", options.shape);\n }\n\n if (options.include?.length) {\n params.set(\"include\", options.include.join(\",\"));\n }\n\n const queryString = params.toString();\n return queryString ? `?${queryString}` : \"\";\n }\n\n /**\n * Parse error response from API.\n */\n private async parseErrorResponse(\n response: Response,\n endpoint: string\n ): Promise<never> {\n const status = response.status;\n let body: { message?: string; code?: string; error?: string; details?: unknown } = {};\n\n try {\n body = await response.json() as typeof body;\n } catch {\n // Response body is not JSON\n }\n\n const message = body.message || body.error || response.statusText;\n\n // Handle specific status codes\n switch (status) {\n case 401:\n throw new AuthenticationError(message);\n\n case 404: {\n // Extract code type and value from endpoint\n const match = endpoint.match(/\\/v1\\/(\\w+)\\/(.+)/);\n if (match) {\n throw new NotFoundError(match[1]!.toUpperCase(), match[2]!);\n }\n throw new NotFoundError(\"Resource\", endpoint);\n }\n\n case 400:\n throw new ValidationError(message);\n\n case 429: {\n const retryAfter = response.headers.get(\"retry-after\");\n const limit = response.headers.get(\"x-ratelimit-limit\");\n const remaining = response.headers.get(\"x-ratelimit-remaining\");\n const reset = response.headers.get(\"x-ratelimit-reset\");\n\n // Check if it's a quota error vs rate limit\n if (body.code === \"QUOTA_EXCEEDED\") {\n throw new QuotaExceededError(message);\n }\n\n throw new RateLimitError(\n message,\n retryAfter ? parseInt(retryAfter, 10) : undefined,\n limit ? parseInt(limit, 10) : undefined,\n remaining ? parseInt(remaining, 10) : undefined,\n reset ? new Date(parseInt(reset, 10) * 1000) : undefined\n );\n }\n\n default:\n if (status >= 500) {\n throw new ServerError(message, status);\n }\n throw new ApiError(message, status, body.code, body.details);\n }\n }\n\n /**\n * Sleep for a given number of milliseconds.\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Get auth headers for the current request.\n */\n private async getAuthHeaders(): Promise<Record<string, string>> {\n if (this.config.auth.type === \"api-key\") {\n return { \"x-api-key\": this.config.auth.apiKey };\n }\n const token = await this.config.auth.tokenManager.getToken();\n return { \"Authorization\": `Bearer ${token}` };\n }\n\n /**\n * Make an HTTP request with retries.\n */\n private async request<T>(\n method: \"GET\" | \"POST\",\n endpoint: string,\n body?: unknown,\n isRetryAfter401 = false\n ): Promise<HttpResponse<T>> {\n const url = `${this.config.baseUrl}${endpoint}`;\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n this.config.timeout\n );\n\n const authHeaders = await this.getAuthHeaders();\n\n const response = await fetch(url, {\n method,\n headers: {\n ...authHeaders,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": this.config.userAgent,\n \"Accept\": \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n // On 401 with OAuth, invalidate token and retry once\n if (\n response.status === 401 &&\n this.config.auth.type === \"oauth\" &&\n !isRetryAfter401\n ) {\n this.config.auth.tokenManager.invalidate();\n return this.request<T>(method, endpoint, body, true);\n }\n\n // Don't retry client errors (except rate limits)\n if (response.status < 500 && response.status !== 429) {\n await this.parseErrorResponse(response, endpoint);\n }\n\n // For rate limits, check retry-after header\n if (response.status === 429) {\n const retryAfter = response.headers.get(\"retry-after\");\n if (retryAfter && attempt < this.config.maxRetries) {\n await this.sleep(parseInt(retryAfter, 10) * 1000);\n continue;\n }\n await this.parseErrorResponse(response, endpoint);\n }\n\n // Retry server errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n\n await this.parseErrorResponse(response, endpoint);\n }\n\n const data = await response.json() as T;\n return { data, status: response.status, headers: response.headers };\n } catch (error) {\n if (error instanceof ApiError) {\n throw error;\n }\n\n if (error instanceof Error) {\n if (error.name === \"AbortError\") {\n throw new TimeoutError(this.config.timeout);\n }\n\n lastError = error;\n\n // Retry on network errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Unknown network error\",\n lastError\n );\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Request failed after retries\",\n lastError\n );\n }\n\n /**\n * Make a GET request.\n */\n async get<T>(endpoint: string, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"GET\", `${endpoint}${queryString}`);\n return response.data;\n }\n\n /**\n * Make a POST request.\n */\n async post<T>(endpoint: string, body: unknown, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"POST\", `${endpoint}${queryString}`, body);\n return response.data;\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NdcData } from \"../types/ndc.js\";\n\n/**\n * NDC (National Drug Code) API endpoint.\n */\nexport class NdcEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NDC code.\n *\n * @param code - NDC code (10-digit, 11-digit, or hyphenated format)\n * @param options - Response shape and include options\n * @returns NDC data\n *\n * @example\n * ```ts\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n * ```\n */\n async lookup(code: string, options?: LookupOptions): Promise<ApiResponse<NdcData>> {\n return this.http.get<ApiResponse<NdcData>>(`/v1/ndc/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple NDC codes in a single request.\n *\n * @param codes - Array of NDC codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n *\n * @example\n * ```ts\n * const results = await client.ndc.lookupMany([\n * \"0069-0151-01\",\n * \"0069-0151-02\",\n * \"invalid-code\"\n * ]);\n *\n * for (const item of results.results) {\n * if (item.found) {\n * console.log(item.data.product_name);\n * } else {\n * console.log(`Not found: ${item.code}`);\n * }\n * }\n * ```\n */\n async lookupMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NdcData>> {\n return this.http.post<BatchResponse<NdcData>>(\n \"/v1/ndc/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NpiData } from \"../types/npi.js\";\n\n/**\n * NPI (National Provider Identifier) API endpoint.\n */\nexport class NpiEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NPI.\n *\n * @param npi - 10-digit NPI number\n * @param options - Response shape and include options\n * @returns NPI data\n *\n * @example\n * ```ts\n * const npi = await client.npi.lookup(\"1234567890\");\n * console.log(npi.data.name);\n * ```\n */\n async lookup(npi: string, options?: LookupOptions): Promise<ApiResponse<NpiData>> {\n return this.http.get<ApiResponse<NpiData>>(`/v1/npi/${encodeURIComponent(npi)}`, options);\n }\n\n /**\n * Look up multiple NPIs in a single request.\n *\n * @param npis - Array of 10-digit NPI numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each NPI\n *\n * @example\n * ```ts\n * const results = await client.npi.lookupMany([\n * \"1234567890\",\n * \"0987654321\"\n * ]);\n * ```\n */\n async lookupMany(\n npis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NpiData>> {\n return this.http.post<BatchResponse<NpiData>>(\n \"/v1/npi/_batch\",\n { codes: npis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { RxNormData } from \"../types/rxnorm.js\";\n\n/**\n * RxNorm API endpoint.\n */\nexport class RxNormEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single RxCUI.\n *\n * @param rxcui - RxNorm Concept Unique Identifier\n * @param options - Response shape and include options\n * @returns RxNorm data\n *\n * @example\n * ```ts\n * const rx = await client.rxnorm.lookup(\"213169\");\n * console.log(rx.data.name); // \"atorvastatin 10 MG Oral Tablet\"\n * ```\n */\n async lookup(rxcui: string, options?: LookupOptions): Promise<ApiResponse<RxNormData>> {\n return this.http.get<ApiResponse<RxNormData>>(`/v1/rxnorm/${encodeURIComponent(rxcui)}`, options);\n }\n\n /**\n * Look up multiple RxCUIs in a single request.\n *\n * @param rxcuis - Array of RxCUIs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each RxCUI\n */\n async lookupMany(\n rxcuis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<RxNormData>> {\n return this.http.post<BatchResponse<RxNormData>>(\n \"/v1/rxnorm/_batch\",\n { codes: rxcuis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { LoincData } from \"../types/loinc.js\";\n\n/**\n * LOINC API endpoint.\n */\nexport class LoincEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single LOINC code.\n *\n * @param loincNum - LOINC number (e.g., \"2345-7\")\n * @param options - Response shape and include options\n * @returns LOINC data\n *\n * @example\n * ```ts\n * const loinc = await client.loinc.lookup(\"2345-7\");\n * console.log(loinc.data.long_common_name); // \"Glucose [Mass/volume] in Serum or Plasma\"\n * ```\n */\n async lookup(loincNum: string, options?: LookupOptions): Promise<ApiResponse<LoincData>> {\n return this.http.get<ApiResponse<LoincData>>(`/v1/loinc/${encodeURIComponent(loincNum)}`, options);\n }\n\n /**\n * Look up multiple LOINC codes in a single request.\n *\n * @param loincNums - Array of LOINC numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each LOINC\n */\n async lookupMany(\n loincNums: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<LoincData>> {\n return this.http.post<BatchResponse<LoincData>>(\n \"/v1/loinc/_batch\",\n { codes: loincNums },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { Icd10Data } from \"../types/icd10.js\";\n\n/**\n * ICD-10 API endpoint.\n */\nexport class Icd10Endpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single ICD-10-CM code (diagnoses).\n *\n * @param code - ICD-10-CM code (e.g., \"E11.9\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupCm(\"E11.9\");\n * console.log(icd.data.description); // \"Type 2 diabetes mellitus without complications\"\n * ```\n */\n async lookupCm(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/cm/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up a single ICD-10-PCS code (procedures).\n *\n * @param code - ICD-10-PCS code (e.g., \"0BJ08ZZ\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupPcs(\"0BJ08ZZ\");\n * console.log(icd.data.description);\n * ```\n */\n async lookupPcs(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/pcs/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple ICD-10-CM codes in a single request.\n *\n * @param codes - Array of ICD-10-CM codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupCmMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/cm/_batch\",\n { codes },\n options\n );\n }\n\n /**\n * Look up multiple ICD-10-PCS codes in a single request.\n *\n * @param codes - Array of ICD-10-PCS codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupPcsMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/pcs/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { CvxData } from \"../types/cvx.js\";\n\n/**\n * CVX (Vaccine Codes) API endpoint.\n */\nexport class CvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single CVX code.\n *\n * @param cvxCode - CVX vaccine code\n * @param options - Response shape and include options\n * @returns CVX data\n *\n * @example\n * ```ts\n * const cvx = await client.cvx.lookup(\"208\");\n * console.log(cvx.data.short_description); // \"COVID-19, mRNA, LNP-S, PF, 30 mcg/0.3 mL dose\"\n * ```\n */\n async lookup(cvxCode: string, options?: LookupOptions): Promise<ApiResponse<CvxData>> {\n return this.http.get<ApiResponse<CvxData>>(`/v1/cvx/${encodeURIComponent(cvxCode)}`, options);\n }\n\n /**\n * Look up multiple CVX codes in a single request.\n *\n * @param cvxCodes - Array of CVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n cvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<CvxData>> {\n return this.http.post<BatchResponse<CvxData>>(\n \"/v1/cvx/_batch\",\n { codes: cvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { MvxData } from \"../types/mvx.js\";\n\n/**\n * MVX (Vaccine Manufacturer Codes) API endpoint.\n */\nexport class MvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single MVX code.\n *\n * @param mvxCode - MVX manufacturer code\n * @param options - Response shape and include options\n * @returns MVX data\n *\n * @example\n * ```ts\n * const mvx = await client.mvx.lookup(\"PFR\");\n * console.log(mvx.data.manufacturer_name); // \"Pfizer, Inc\"\n * ```\n */\n async lookup(mvxCode: string, options?: LookupOptions): Promise<ApiResponse<MvxData>> {\n return this.http.get<ApiResponse<MvxData>>(`/v1/mvx/${encodeURIComponent(mvxCode)}`, options);\n }\n\n /**\n * Look up multiple MVX codes in a single request.\n *\n * @param mvxCodes - Array of MVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n mvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<MvxData>> {\n return this.http.post<BatchResponse<MvxData>>(\n \"/v1/mvx/_batch\",\n { codes: mvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { FdaLabelData } from \"../types/fda-labels.js\";\n\n/**\n * FDA Labels API endpoint.\n */\nexport class FdaLabelsEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up FDA label by Set ID.\n *\n * @param setId - FDA SPL Set ID\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookup(\"abc123-def456\");\n * console.log(label.data.indications_and_usage);\n * ```\n */\n async lookup(setId: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/${encodeURIComponent(setId)}`, options);\n }\n\n /**\n * Look up FDA label by NDC code.\n *\n * @param ndc - NDC code\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookupByNdc(\"0069-0151-01\");\n * console.log(label.data.product_name);\n * ```\n */\n async lookupByNdc(ndc: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/ndc/${encodeURIComponent(ndc)}`, options);\n }\n\n /**\n * Look up multiple FDA labels by Set IDs in a single request.\n *\n * @param setIds - Array of Set IDs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each Set ID\n */\n async lookupMany(\n setIds: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<FdaLabelData>> {\n return this.http.post<BatchResponse<FdaLabelData>>(\n \"/v1/fda-labels/_batch\",\n { codes: setIds },\n options\n );\n }\n}\n","import { HttpClient, TokenManager, type HttpClientConfig } from \"./http.js\";\nimport { NdcEndpoint } from \"./endpoints/ndc.js\";\nimport { NpiEndpoint } from \"./endpoints/npi.js\";\nimport { RxNormEndpoint } from \"./endpoints/rxnorm.js\";\nimport { LoincEndpoint } from \"./endpoints/loinc.js\";\nimport { Icd10Endpoint } from \"./endpoints/icd10.js\";\nimport { CvxEndpoint } from \"./endpoints/cvx.js\";\nimport { MvxEndpoint } from \"./endpoints/mvx.js\";\nimport { FdaLabelsEndpoint } from \"./endpoints/fda-labels.js\";\n\n/**\n * Base configuration options shared by all auth modes.\n */\ninterface FhirflyBaseConfig {\n /**\n * Base URL for the API.\n * @default \"https://api.fhirfly.io\"\n */\n baseUrl?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n\n /**\n * Maximum number of retry attempts for failed requests.\n * @default 3\n */\n maxRetries?: number;\n\n /**\n * Base delay between retries in milliseconds (exponential backoff).\n * @default 1000\n */\n retryDelay?: number;\n}\n\n/**\n * Configuration using an API key (simple credentials).\n */\nexport interface FhirflyApiKeyConfig extends FhirflyBaseConfig {\n /**\n * Your FHIRfly API key.\n * Get one at https://fhirfly.io/dashboard\n */\n apiKey: string;\n clientId?: never;\n clientSecret?: never;\n tokenUrl?: never;\n scopes?: never;\n}\n\n/**\n * Configuration using OAuth2 client credentials (secure credentials).\n */\nexport interface FhirflyOAuthConfig extends FhirflyBaseConfig {\n /**\n * OAuth2 client ID from your secure credential.\n */\n clientId: string;\n\n /**\n * OAuth2 client secret from your secure credential.\n */\n clientSecret: string;\n\n /**\n * OAuth2 token endpoint URL.\n * @default \"{baseUrl}/oauth2/token\"\n */\n tokenUrl?: string;\n\n /**\n * OAuth2 scopes to request.\n */\n scopes?: string[];\n\n apiKey?: never;\n}\n\n/**\n * Configuration options for the FHIRfly client.\n * Provide either `apiKey` OR `clientId`+`clientSecret`, not both.\n */\nexport type FhirflyConfig = FhirflyApiKeyConfig | FhirflyOAuthConfig;\n\n/**\n * FHIRfly API client.\n *\n * Provides access to healthcare reference data including drug codes (NDC, RxNorm),\n * provider identifiers (NPI), lab codes (LOINC), diagnosis codes (ICD-10),\n * vaccine codes (CVX, MVX), and FDA drug labels.\n *\n * @example\n * ```ts\n * import { Fhirfly } from \"@fhirfly/sdk\";\n *\n * // Option A: API key (simple)\n * const client = new Fhirfly({ apiKey: \"ffly_sk_live_...\" });\n *\n * // Option B: Client credentials (secure)\n * const client = new Fhirfly({\n * clientId: \"ffly_client_...\",\n * clientSecret: \"ffly_secret_...\",\n * });\n *\n * // Look up a drug by NDC\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n * ```\n */\nexport class Fhirfly {\n private readonly http: HttpClient;\n\n /**\n * NDC (National Drug Code) lookups.\n */\n readonly ndc: NdcEndpoint;\n\n /**\n * NPI (National Provider Identifier) lookups.\n */\n readonly npi: NpiEndpoint;\n\n /**\n * RxNorm drug terminology lookups.\n */\n readonly rxnorm: RxNormEndpoint;\n\n /**\n * LOINC laboratory and clinical observation code lookups.\n */\n readonly loinc: LoincEndpoint;\n\n /**\n * ICD-10 diagnosis and procedure code lookups.\n */\n readonly icd10: Icd10Endpoint;\n\n /**\n * CVX vaccine code lookups.\n */\n readonly cvx: CvxEndpoint;\n\n /**\n * MVX vaccine manufacturer code lookups.\n */\n readonly mvx: MvxEndpoint;\n\n /**\n * FDA drug label lookups.\n */\n readonly fdaLabels: FdaLabelsEndpoint;\n\n /**\n * Create a new FHIRfly client.\n *\n * @param config - Client configuration (API key or OAuth2 client credentials)\n * @throws {Error} If neither apiKey nor clientId+clientSecret is provided\n */\n constructor(config: FhirflyConfig) {\n const baseUrl = config.baseUrl ?? \"https://api.fhirfly.io\";\n\n let httpConfig: HttpClientConfig;\n\n if (\"apiKey\" in config && config.apiKey) {\n httpConfig = {\n baseUrl,\n auth: { type: \"api-key\", apiKey: config.apiKey },\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n };\n } else if (\"clientId\" in config && config.clientId && config.clientSecret) {\n const tokenManager = new TokenManager({\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n tokenUrl: config.tokenUrl ?? `${baseUrl}/oauth2/token`,\n scopes: config.scopes,\n });\n httpConfig = {\n baseUrl,\n auth: { type: \"oauth\", tokenManager },\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n };\n } else {\n throw new Error(\n \"FHIRfly requires either an apiKey or clientId+clientSecret. Get credentials at https://fhirfly.io/dashboard\"\n );\n }\n\n this.http = new HttpClient(httpConfig);\n\n // Initialize endpoints\n this.ndc = new NdcEndpoint(this.http);\n this.npi = new NpiEndpoint(this.http);\n this.rxnorm = new RxNormEndpoint(this.http);\n this.loinc = new LoincEndpoint(this.http);\n this.icd10 = new Icd10Endpoint(this.http);\n this.cvx = new CvxEndpoint(this.http);\n this.mvx = new MvxEndpoint(this.http);\n this.fdaLabels = new FdaLabelsEndpoint(this.http);\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -72,12 +72,51 @@ interface DisplayField {
|
|
|
72
72
|
display?: string;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* OAuth2 client credentials configuration.
|
|
77
|
+
*/
|
|
78
|
+
interface OAuthCredentials {
|
|
79
|
+
clientId: string;
|
|
80
|
+
clientSecret: string;
|
|
81
|
+
tokenUrl: string;
|
|
82
|
+
scopes?: string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Manages OAuth2 access tokens with automatic refresh.
|
|
86
|
+
*/
|
|
87
|
+
declare class TokenManager {
|
|
88
|
+
private readonly credentials;
|
|
89
|
+
private accessToken;
|
|
90
|
+
private expiresAt;
|
|
91
|
+
private refreshPromise;
|
|
92
|
+
constructor(credentials: OAuthCredentials);
|
|
93
|
+
/**
|
|
94
|
+
* Get a valid access token, refreshing if needed.
|
|
95
|
+
* Deduplicates concurrent refresh calls.
|
|
96
|
+
*/
|
|
97
|
+
getToken(): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Invalidate the cached token (e.g., after a 401 response).
|
|
100
|
+
*/
|
|
101
|
+
invalidate(): void;
|
|
102
|
+
private fetchToken;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Authentication mode for the HTTP client.
|
|
106
|
+
*/
|
|
107
|
+
type AuthMode = {
|
|
108
|
+
type: "api-key";
|
|
109
|
+
apiKey: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: "oauth";
|
|
112
|
+
tokenManager: TokenManager;
|
|
113
|
+
};
|
|
75
114
|
/**
|
|
76
115
|
* HTTP client configuration.
|
|
77
116
|
*/
|
|
78
117
|
interface HttpClientConfig {
|
|
79
118
|
baseUrl: string;
|
|
80
|
-
|
|
119
|
+
auth: AuthMode;
|
|
81
120
|
timeout?: number;
|
|
82
121
|
maxRetries?: number;
|
|
83
122
|
retryDelay?: number;
|
|
@@ -101,6 +140,10 @@ declare class HttpClient {
|
|
|
101
140
|
* Sleep for a given number of milliseconds.
|
|
102
141
|
*/
|
|
103
142
|
private sleep;
|
|
143
|
+
/**
|
|
144
|
+
* Get auth headers for the current request.
|
|
145
|
+
*/
|
|
146
|
+
private getAuthHeaders;
|
|
104
147
|
/**
|
|
105
148
|
* Make an HTTP request with retries.
|
|
106
149
|
*/
|
|
@@ -812,14 +855,9 @@ declare class FdaLabelsEndpoint {
|
|
|
812
855
|
}
|
|
813
856
|
|
|
814
857
|
/**
|
|
815
|
-
*
|
|
858
|
+
* Base configuration options shared by all auth modes.
|
|
816
859
|
*/
|
|
817
|
-
interface
|
|
818
|
-
/**
|
|
819
|
-
* Your FHIRfly API key.
|
|
820
|
-
* Get one at https://fhirfly.io/dashboard
|
|
821
|
-
*/
|
|
822
|
-
apiKey: string;
|
|
860
|
+
interface FhirflyBaseConfig {
|
|
823
861
|
/**
|
|
824
862
|
* Base URL for the API.
|
|
825
863
|
* @default "https://api.fhirfly.io"
|
|
@@ -841,6 +879,48 @@ interface FhirflyConfig {
|
|
|
841
879
|
*/
|
|
842
880
|
retryDelay?: number;
|
|
843
881
|
}
|
|
882
|
+
/**
|
|
883
|
+
* Configuration using an API key (simple credentials).
|
|
884
|
+
*/
|
|
885
|
+
interface FhirflyApiKeyConfig extends FhirflyBaseConfig {
|
|
886
|
+
/**
|
|
887
|
+
* Your FHIRfly API key.
|
|
888
|
+
* Get one at https://fhirfly.io/dashboard
|
|
889
|
+
*/
|
|
890
|
+
apiKey: string;
|
|
891
|
+
clientId?: never;
|
|
892
|
+
clientSecret?: never;
|
|
893
|
+
tokenUrl?: never;
|
|
894
|
+
scopes?: never;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Configuration using OAuth2 client credentials (secure credentials).
|
|
898
|
+
*/
|
|
899
|
+
interface FhirflyOAuthConfig extends FhirflyBaseConfig {
|
|
900
|
+
/**
|
|
901
|
+
* OAuth2 client ID from your secure credential.
|
|
902
|
+
*/
|
|
903
|
+
clientId: string;
|
|
904
|
+
/**
|
|
905
|
+
* OAuth2 client secret from your secure credential.
|
|
906
|
+
*/
|
|
907
|
+
clientSecret: string;
|
|
908
|
+
/**
|
|
909
|
+
* OAuth2 token endpoint URL.
|
|
910
|
+
* @default "{baseUrl}/oauth2/token"
|
|
911
|
+
*/
|
|
912
|
+
tokenUrl?: string;
|
|
913
|
+
/**
|
|
914
|
+
* OAuth2 scopes to request.
|
|
915
|
+
*/
|
|
916
|
+
scopes?: string[];
|
|
917
|
+
apiKey?: never;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Configuration options for the FHIRfly client.
|
|
921
|
+
* Provide either `apiKey` OR `clientId`+`clientSecret`, not both.
|
|
922
|
+
*/
|
|
923
|
+
type FhirflyConfig = FhirflyApiKeyConfig | FhirflyOAuthConfig;
|
|
844
924
|
/**
|
|
845
925
|
* FHIRfly API client.
|
|
846
926
|
*
|
|
@@ -852,21 +932,18 @@ interface FhirflyConfig {
|
|
|
852
932
|
* ```ts
|
|
853
933
|
* import { Fhirfly } from "@fhirfly/sdk";
|
|
854
934
|
*
|
|
855
|
-
*
|
|
935
|
+
* // Option A: API key (simple)
|
|
936
|
+
* const client = new Fhirfly({ apiKey: "ffly_sk_live_..." });
|
|
937
|
+
*
|
|
938
|
+
* // Option B: Client credentials (secure)
|
|
939
|
+
* const client = new Fhirfly({
|
|
940
|
+
* clientId: "ffly_client_...",
|
|
941
|
+
* clientSecret: "ffly_secret_...",
|
|
942
|
+
* });
|
|
856
943
|
*
|
|
857
944
|
* // Look up a drug by NDC
|
|
858
945
|
* const ndc = await client.ndc.lookup("0069-0151-01");
|
|
859
946
|
* console.log(ndc.data.product_name); // "Lipitor"
|
|
860
|
-
*
|
|
861
|
-
* // Look up a provider by NPI
|
|
862
|
-
* const npi = await client.npi.lookup("1234567890");
|
|
863
|
-
* console.log(npi.data.name);
|
|
864
|
-
*
|
|
865
|
-
* // Batch lookups
|
|
866
|
-
* const results = await client.ndc.lookupMany([
|
|
867
|
-
* "0069-0151-01",
|
|
868
|
-
* "0069-0151-02"
|
|
869
|
-
* ]);
|
|
870
947
|
* ```
|
|
871
948
|
*/
|
|
872
949
|
declare class Fhirfly {
|
|
@@ -906,8 +983,8 @@ declare class Fhirfly {
|
|
|
906
983
|
/**
|
|
907
984
|
* Create a new FHIRfly client.
|
|
908
985
|
*
|
|
909
|
-
* @param config - Client configuration
|
|
910
|
-
* @throws {Error} If apiKey is
|
|
986
|
+
* @param config - Client configuration (API key or OAuth2 client credentials)
|
|
987
|
+
* @throws {Error} If neither apiKey nor clientId+clientSecret is provided
|
|
911
988
|
*/
|
|
912
989
|
constructor(config: FhirflyConfig);
|
|
913
990
|
}
|
|
@@ -988,4 +1065,4 @@ declare class TimeoutError extends FhirflyError {
|
|
|
988
1065
|
constructor(timeoutMs: number);
|
|
989
1066
|
}
|
|
990
1067
|
|
|
991
|
-
export { type ActiveIngredient, ApiError, type ApiResponse, AuthenticationError, type BatchLookupOptions, type BatchResponse, type BatchResultItem, type CvxCompact, type CvxData, type CvxFull, type CvxStandard, type DisplayField, type FdaLabelCompact, type FdaLabelData, type FdaLabelFull, type FdaLabelStandard, Fhirfly, type FhirflyConfig, FhirflyError, type Icd10Compact, type Icd10Data, type Icd10Full, type Icd10Standard, type Icd10Type, type IncludeOption, type LegalInfo, type LoincCompact, type LoincData, type LoincFull, type LoincStandard, type LookupOptions, type MvxCompact, type MvxData, type MvxFull, type MvxStandard, type NdcCompact, type NdcData, type NdcFull, type NdcPackaging, type NdcStandard, NetworkError, NotFoundError, type NpiAddress, type NpiCompact, type NpiData, type NpiFull, type NpiIdentifier, type NpiStandard, type NpiTaxonomy, QuotaExceededError, RateLimitError, type ResponseMeta, type ResponseShape, type RxNormCompact, type RxNormData, type RxNormFull, type RxNormStandard, type RxTermType, ServerError, TimeoutError, ValidationError };
|
|
1068
|
+
export { type ActiveIngredient, ApiError, type ApiResponse, AuthenticationError, type BatchLookupOptions, type BatchResponse, type BatchResultItem, type CvxCompact, type CvxData, type CvxFull, type CvxStandard, type DisplayField, type FdaLabelCompact, type FdaLabelData, type FdaLabelFull, type FdaLabelStandard, Fhirfly, type FhirflyApiKeyConfig, type FhirflyConfig, FhirflyError, type FhirflyOAuthConfig, type Icd10Compact, type Icd10Data, type Icd10Full, type Icd10Standard, type Icd10Type, type IncludeOption, type LegalInfo, type LoincCompact, type LoincData, type LoincFull, type LoincStandard, type LookupOptions, type MvxCompact, type MvxData, type MvxFull, type MvxStandard, type NdcCompact, type NdcData, type NdcFull, type NdcPackaging, type NdcStandard, NetworkError, NotFoundError, type NpiAddress, type NpiCompact, type NpiData, type NpiFull, type NpiIdentifier, type NpiStandard, type NpiTaxonomy, QuotaExceededError, RateLimitError, type ResponseMeta, type ResponseShape, type RxNormCompact, type RxNormData, type RxNormFull, type RxNormStandard, type RxTermType, ServerError, TimeoutError, TokenManager, ValidationError };
|
package/dist/index.d.ts
CHANGED
|
@@ -72,12 +72,51 @@ interface DisplayField {
|
|
|
72
72
|
display?: string;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* OAuth2 client credentials configuration.
|
|
77
|
+
*/
|
|
78
|
+
interface OAuthCredentials {
|
|
79
|
+
clientId: string;
|
|
80
|
+
clientSecret: string;
|
|
81
|
+
tokenUrl: string;
|
|
82
|
+
scopes?: string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Manages OAuth2 access tokens with automatic refresh.
|
|
86
|
+
*/
|
|
87
|
+
declare class TokenManager {
|
|
88
|
+
private readonly credentials;
|
|
89
|
+
private accessToken;
|
|
90
|
+
private expiresAt;
|
|
91
|
+
private refreshPromise;
|
|
92
|
+
constructor(credentials: OAuthCredentials);
|
|
93
|
+
/**
|
|
94
|
+
* Get a valid access token, refreshing if needed.
|
|
95
|
+
* Deduplicates concurrent refresh calls.
|
|
96
|
+
*/
|
|
97
|
+
getToken(): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Invalidate the cached token (e.g., after a 401 response).
|
|
100
|
+
*/
|
|
101
|
+
invalidate(): void;
|
|
102
|
+
private fetchToken;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Authentication mode for the HTTP client.
|
|
106
|
+
*/
|
|
107
|
+
type AuthMode = {
|
|
108
|
+
type: "api-key";
|
|
109
|
+
apiKey: string;
|
|
110
|
+
} | {
|
|
111
|
+
type: "oauth";
|
|
112
|
+
tokenManager: TokenManager;
|
|
113
|
+
};
|
|
75
114
|
/**
|
|
76
115
|
* HTTP client configuration.
|
|
77
116
|
*/
|
|
78
117
|
interface HttpClientConfig {
|
|
79
118
|
baseUrl: string;
|
|
80
|
-
|
|
119
|
+
auth: AuthMode;
|
|
81
120
|
timeout?: number;
|
|
82
121
|
maxRetries?: number;
|
|
83
122
|
retryDelay?: number;
|
|
@@ -101,6 +140,10 @@ declare class HttpClient {
|
|
|
101
140
|
* Sleep for a given number of milliseconds.
|
|
102
141
|
*/
|
|
103
142
|
private sleep;
|
|
143
|
+
/**
|
|
144
|
+
* Get auth headers for the current request.
|
|
145
|
+
*/
|
|
146
|
+
private getAuthHeaders;
|
|
104
147
|
/**
|
|
105
148
|
* Make an HTTP request with retries.
|
|
106
149
|
*/
|
|
@@ -812,14 +855,9 @@ declare class FdaLabelsEndpoint {
|
|
|
812
855
|
}
|
|
813
856
|
|
|
814
857
|
/**
|
|
815
|
-
*
|
|
858
|
+
* Base configuration options shared by all auth modes.
|
|
816
859
|
*/
|
|
817
|
-
interface
|
|
818
|
-
/**
|
|
819
|
-
* Your FHIRfly API key.
|
|
820
|
-
* Get one at https://fhirfly.io/dashboard
|
|
821
|
-
*/
|
|
822
|
-
apiKey: string;
|
|
860
|
+
interface FhirflyBaseConfig {
|
|
823
861
|
/**
|
|
824
862
|
* Base URL for the API.
|
|
825
863
|
* @default "https://api.fhirfly.io"
|
|
@@ -841,6 +879,48 @@ interface FhirflyConfig {
|
|
|
841
879
|
*/
|
|
842
880
|
retryDelay?: number;
|
|
843
881
|
}
|
|
882
|
+
/**
|
|
883
|
+
* Configuration using an API key (simple credentials).
|
|
884
|
+
*/
|
|
885
|
+
interface FhirflyApiKeyConfig extends FhirflyBaseConfig {
|
|
886
|
+
/**
|
|
887
|
+
* Your FHIRfly API key.
|
|
888
|
+
* Get one at https://fhirfly.io/dashboard
|
|
889
|
+
*/
|
|
890
|
+
apiKey: string;
|
|
891
|
+
clientId?: never;
|
|
892
|
+
clientSecret?: never;
|
|
893
|
+
tokenUrl?: never;
|
|
894
|
+
scopes?: never;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Configuration using OAuth2 client credentials (secure credentials).
|
|
898
|
+
*/
|
|
899
|
+
interface FhirflyOAuthConfig extends FhirflyBaseConfig {
|
|
900
|
+
/**
|
|
901
|
+
* OAuth2 client ID from your secure credential.
|
|
902
|
+
*/
|
|
903
|
+
clientId: string;
|
|
904
|
+
/**
|
|
905
|
+
* OAuth2 client secret from your secure credential.
|
|
906
|
+
*/
|
|
907
|
+
clientSecret: string;
|
|
908
|
+
/**
|
|
909
|
+
* OAuth2 token endpoint URL.
|
|
910
|
+
* @default "{baseUrl}/oauth2/token"
|
|
911
|
+
*/
|
|
912
|
+
tokenUrl?: string;
|
|
913
|
+
/**
|
|
914
|
+
* OAuth2 scopes to request.
|
|
915
|
+
*/
|
|
916
|
+
scopes?: string[];
|
|
917
|
+
apiKey?: never;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Configuration options for the FHIRfly client.
|
|
921
|
+
* Provide either `apiKey` OR `clientId`+`clientSecret`, not both.
|
|
922
|
+
*/
|
|
923
|
+
type FhirflyConfig = FhirflyApiKeyConfig | FhirflyOAuthConfig;
|
|
844
924
|
/**
|
|
845
925
|
* FHIRfly API client.
|
|
846
926
|
*
|
|
@@ -852,21 +932,18 @@ interface FhirflyConfig {
|
|
|
852
932
|
* ```ts
|
|
853
933
|
* import { Fhirfly } from "@fhirfly/sdk";
|
|
854
934
|
*
|
|
855
|
-
*
|
|
935
|
+
* // Option A: API key (simple)
|
|
936
|
+
* const client = new Fhirfly({ apiKey: "ffly_sk_live_..." });
|
|
937
|
+
*
|
|
938
|
+
* // Option B: Client credentials (secure)
|
|
939
|
+
* const client = new Fhirfly({
|
|
940
|
+
* clientId: "ffly_client_...",
|
|
941
|
+
* clientSecret: "ffly_secret_...",
|
|
942
|
+
* });
|
|
856
943
|
*
|
|
857
944
|
* // Look up a drug by NDC
|
|
858
945
|
* const ndc = await client.ndc.lookup("0069-0151-01");
|
|
859
946
|
* console.log(ndc.data.product_name); // "Lipitor"
|
|
860
|
-
*
|
|
861
|
-
* // Look up a provider by NPI
|
|
862
|
-
* const npi = await client.npi.lookup("1234567890");
|
|
863
|
-
* console.log(npi.data.name);
|
|
864
|
-
*
|
|
865
|
-
* // Batch lookups
|
|
866
|
-
* const results = await client.ndc.lookupMany([
|
|
867
|
-
* "0069-0151-01",
|
|
868
|
-
* "0069-0151-02"
|
|
869
|
-
* ]);
|
|
870
947
|
* ```
|
|
871
948
|
*/
|
|
872
949
|
declare class Fhirfly {
|
|
@@ -906,8 +983,8 @@ declare class Fhirfly {
|
|
|
906
983
|
/**
|
|
907
984
|
* Create a new FHIRfly client.
|
|
908
985
|
*
|
|
909
|
-
* @param config - Client configuration
|
|
910
|
-
* @throws {Error} If apiKey is
|
|
986
|
+
* @param config - Client configuration (API key or OAuth2 client credentials)
|
|
987
|
+
* @throws {Error} If neither apiKey nor clientId+clientSecret is provided
|
|
911
988
|
*/
|
|
912
989
|
constructor(config: FhirflyConfig);
|
|
913
990
|
}
|
|
@@ -988,4 +1065,4 @@ declare class TimeoutError extends FhirflyError {
|
|
|
988
1065
|
constructor(timeoutMs: number);
|
|
989
1066
|
}
|
|
990
1067
|
|
|
991
|
-
export { type ActiveIngredient, ApiError, type ApiResponse, AuthenticationError, type BatchLookupOptions, type BatchResponse, type BatchResultItem, type CvxCompact, type CvxData, type CvxFull, type CvxStandard, type DisplayField, type FdaLabelCompact, type FdaLabelData, type FdaLabelFull, type FdaLabelStandard, Fhirfly, type FhirflyConfig, FhirflyError, type Icd10Compact, type Icd10Data, type Icd10Full, type Icd10Standard, type Icd10Type, type IncludeOption, type LegalInfo, type LoincCompact, type LoincData, type LoincFull, type LoincStandard, type LookupOptions, type MvxCompact, type MvxData, type MvxFull, type MvxStandard, type NdcCompact, type NdcData, type NdcFull, type NdcPackaging, type NdcStandard, NetworkError, NotFoundError, type NpiAddress, type NpiCompact, type NpiData, type NpiFull, type NpiIdentifier, type NpiStandard, type NpiTaxonomy, QuotaExceededError, RateLimitError, type ResponseMeta, type ResponseShape, type RxNormCompact, type RxNormData, type RxNormFull, type RxNormStandard, type RxTermType, ServerError, TimeoutError, ValidationError };
|
|
1068
|
+
export { type ActiveIngredient, ApiError, type ApiResponse, AuthenticationError, type BatchLookupOptions, type BatchResponse, type BatchResultItem, type CvxCompact, type CvxData, type CvxFull, type CvxStandard, type DisplayField, type FdaLabelCompact, type FdaLabelData, type FdaLabelFull, type FdaLabelStandard, Fhirfly, type FhirflyApiKeyConfig, type FhirflyConfig, FhirflyError, type FhirflyOAuthConfig, type Icd10Compact, type Icd10Data, type Icd10Full, type Icd10Standard, type Icd10Type, type IncludeOption, type LegalInfo, type LoincCompact, type LoincData, type LoincFull, type LoincStandard, type LookupOptions, type MvxCompact, type MvxData, type MvxFull, type MvxStandard, type NdcCompact, type NdcData, type NdcFull, type NdcPackaging, type NdcStandard, NetworkError, NotFoundError, type NpiAddress, type NpiCompact, type NpiData, type NpiFull, type NpiIdentifier, type NpiStandard, type NpiTaxonomy, QuotaExceededError, RateLimitError, type ResponseMeta, type ResponseShape, type RxNormCompact, type RxNormData, type RxNormFull, type RxNormStandard, type RxTermType, ServerError, TimeoutError, TokenManager, ValidationError };
|
package/dist/index.js
CHANGED
|
@@ -101,12 +101,71 @@ var TimeoutError = class _TimeoutError extends FhirflyError {
|
|
|
101
101
|
};
|
|
102
102
|
|
|
103
103
|
// src/http.ts
|
|
104
|
+
var TokenManager = class {
|
|
105
|
+
credentials;
|
|
106
|
+
accessToken = null;
|
|
107
|
+
expiresAt = 0;
|
|
108
|
+
refreshPromise = null;
|
|
109
|
+
constructor(credentials) {
|
|
110
|
+
this.credentials = credentials;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get a valid access token, refreshing if needed.
|
|
114
|
+
* Deduplicates concurrent refresh calls.
|
|
115
|
+
*/
|
|
116
|
+
async getToken() {
|
|
117
|
+
if (this.accessToken && Date.now() < this.expiresAt) {
|
|
118
|
+
return this.accessToken;
|
|
119
|
+
}
|
|
120
|
+
if (this.refreshPromise) {
|
|
121
|
+
return this.refreshPromise;
|
|
122
|
+
}
|
|
123
|
+
this.refreshPromise = this.fetchToken();
|
|
124
|
+
try {
|
|
125
|
+
return await this.refreshPromise;
|
|
126
|
+
} finally {
|
|
127
|
+
this.refreshPromise = null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Invalidate the cached token (e.g., after a 401 response).
|
|
132
|
+
*/
|
|
133
|
+
invalidate() {
|
|
134
|
+
this.accessToken = null;
|
|
135
|
+
this.expiresAt = 0;
|
|
136
|
+
}
|
|
137
|
+
async fetchToken() {
|
|
138
|
+
const body = new URLSearchParams({
|
|
139
|
+
grant_type: "client_credentials",
|
|
140
|
+
client_id: this.credentials.clientId,
|
|
141
|
+
client_secret: this.credentials.clientSecret
|
|
142
|
+
});
|
|
143
|
+
if (this.credentials.scopes?.length) {
|
|
144
|
+
body.set("scope", this.credentials.scopes.join(" "));
|
|
145
|
+
}
|
|
146
|
+
const response = await fetch(this.credentials.tokenUrl, {
|
|
147
|
+
method: "POST",
|
|
148
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
149
|
+
body: body.toString()
|
|
150
|
+
});
|
|
151
|
+
if (!response.ok) {
|
|
152
|
+
const text = await response.text().catch(() => "");
|
|
153
|
+
throw new AuthenticationError(
|
|
154
|
+
`OAuth2 token exchange failed (${response.status}): ${text}`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
const data = await response.json();
|
|
158
|
+
this.accessToken = data.access_token;
|
|
159
|
+
this.expiresAt = Date.now() + (data.expires_in - 60) * 1e3;
|
|
160
|
+
return this.accessToken;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
104
163
|
var HttpClient = class {
|
|
105
164
|
config;
|
|
106
165
|
constructor(config) {
|
|
107
166
|
this.config = {
|
|
108
167
|
baseUrl: config.baseUrl,
|
|
109
|
-
|
|
168
|
+
auth: config.auth,
|
|
110
169
|
timeout: config.timeout ?? 3e4,
|
|
111
170
|
maxRetries: config.maxRetries ?? 3,
|
|
112
171
|
retryDelay: config.retryDelay ?? 1e3,
|
|
@@ -180,10 +239,20 @@ var HttpClient = class {
|
|
|
180
239
|
sleep(ms) {
|
|
181
240
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
182
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Get auth headers for the current request.
|
|
244
|
+
*/
|
|
245
|
+
async getAuthHeaders() {
|
|
246
|
+
if (this.config.auth.type === "api-key") {
|
|
247
|
+
return { "x-api-key": this.config.auth.apiKey };
|
|
248
|
+
}
|
|
249
|
+
const token = await this.config.auth.tokenManager.getToken();
|
|
250
|
+
return { "Authorization": `Bearer ${token}` };
|
|
251
|
+
}
|
|
183
252
|
/**
|
|
184
253
|
* Make an HTTP request with retries.
|
|
185
254
|
*/
|
|
186
|
-
async request(method, endpoint, body) {
|
|
255
|
+
async request(method, endpoint, body, isRetryAfter401 = false) {
|
|
187
256
|
const url = `${this.config.baseUrl}${endpoint}`;
|
|
188
257
|
let lastError;
|
|
189
258
|
for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
|
|
@@ -193,10 +262,11 @@ var HttpClient = class {
|
|
|
193
262
|
() => controller.abort(),
|
|
194
263
|
this.config.timeout
|
|
195
264
|
);
|
|
265
|
+
const authHeaders = await this.getAuthHeaders();
|
|
196
266
|
const response = await fetch(url, {
|
|
197
267
|
method,
|
|
198
268
|
headers: {
|
|
199
|
-
|
|
269
|
+
...authHeaders,
|
|
200
270
|
"Content-Type": "application/json",
|
|
201
271
|
"User-Agent": this.config.userAgent,
|
|
202
272
|
"Accept": "application/json"
|
|
@@ -206,6 +276,10 @@ var HttpClient = class {
|
|
|
206
276
|
});
|
|
207
277
|
clearTimeout(timeoutId);
|
|
208
278
|
if (!response.ok) {
|
|
279
|
+
if (response.status === 401 && this.config.auth.type === "oauth" && !isRetryAfter401) {
|
|
280
|
+
this.config.auth.tokenManager.invalidate();
|
|
281
|
+
return this.request(method, endpoint, body, true);
|
|
282
|
+
}
|
|
209
283
|
if (response.status < 500 && response.status !== 429) {
|
|
210
284
|
await this.parseErrorResponse(response, endpoint);
|
|
211
285
|
}
|
|
@@ -673,22 +747,39 @@ var Fhirfly = class {
|
|
|
673
747
|
/**
|
|
674
748
|
* Create a new FHIRfly client.
|
|
675
749
|
*
|
|
676
|
-
* @param config - Client configuration
|
|
677
|
-
* @throws {Error} If apiKey is
|
|
750
|
+
* @param config - Client configuration (API key or OAuth2 client credentials)
|
|
751
|
+
* @throws {Error} If neither apiKey nor clientId+clientSecret is provided
|
|
678
752
|
*/
|
|
679
753
|
constructor(config) {
|
|
680
|
-
|
|
754
|
+
const baseUrl = config.baseUrl ?? "https://api.fhirfly.io";
|
|
755
|
+
let httpConfig;
|
|
756
|
+
if ("apiKey" in config && config.apiKey) {
|
|
757
|
+
httpConfig = {
|
|
758
|
+
baseUrl,
|
|
759
|
+
auth: { type: "api-key", apiKey: config.apiKey },
|
|
760
|
+
timeout: config.timeout,
|
|
761
|
+
maxRetries: config.maxRetries,
|
|
762
|
+
retryDelay: config.retryDelay
|
|
763
|
+
};
|
|
764
|
+
} else if ("clientId" in config && config.clientId && config.clientSecret) {
|
|
765
|
+
const tokenManager = new TokenManager({
|
|
766
|
+
clientId: config.clientId,
|
|
767
|
+
clientSecret: config.clientSecret,
|
|
768
|
+
tokenUrl: config.tokenUrl ?? `${baseUrl}/oauth2/token`,
|
|
769
|
+
scopes: config.scopes
|
|
770
|
+
});
|
|
771
|
+
httpConfig = {
|
|
772
|
+
baseUrl,
|
|
773
|
+
auth: { type: "oauth", tokenManager },
|
|
774
|
+
timeout: config.timeout,
|
|
775
|
+
maxRetries: config.maxRetries,
|
|
776
|
+
retryDelay: config.retryDelay
|
|
777
|
+
};
|
|
778
|
+
} else {
|
|
681
779
|
throw new Error(
|
|
682
|
-
"FHIRfly
|
|
780
|
+
"FHIRfly requires either an apiKey or clientId+clientSecret. Get credentials at https://fhirfly.io/dashboard"
|
|
683
781
|
);
|
|
684
782
|
}
|
|
685
|
-
const httpConfig = {
|
|
686
|
-
baseUrl: config.baseUrl ?? "https://api.fhirfly.io",
|
|
687
|
-
apiKey: config.apiKey,
|
|
688
|
-
timeout: config.timeout,
|
|
689
|
-
maxRetries: config.maxRetries,
|
|
690
|
-
retryDelay: config.retryDelay
|
|
691
|
-
};
|
|
692
783
|
this.http = new HttpClient(httpConfig);
|
|
693
784
|
this.ndc = new NdcEndpoint(this.http);
|
|
694
785
|
this.npi = new NpiEndpoint(this.http);
|
|
@@ -701,6 +792,6 @@ var Fhirfly = class {
|
|
|
701
792
|
}
|
|
702
793
|
};
|
|
703
794
|
|
|
704
|
-
export { ApiError, AuthenticationError, Fhirfly, FhirflyError, NetworkError, NotFoundError, QuotaExceededError, RateLimitError, ServerError, TimeoutError, ValidationError };
|
|
795
|
+
export { ApiError, AuthenticationError, Fhirfly, FhirflyError, NetworkError, NotFoundError, QuotaExceededError, RateLimitError, ServerError, TimeoutError, TokenManager, ValidationError };
|
|
705
796
|
//# sourceMappingURL=index.js.map
|
|
706
797
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/endpoints/ndc.ts","../src/endpoints/npi.ts","../src/endpoints/rxnorm.ts","../src/endpoints/loinc.ts","../src/endpoints/icd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,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,iBAAA,CAAkB,IAAA,CAAK,IAAI,CAAA;AAAA,EAClD;AACF","file":"index.js","sourcesContent":["/**\n * Base error class for all FHIRfly SDK errors.\n */\nexport class FhirflyError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"FhirflyError\";\n Object.setPrototypeOf(this, FhirflyError.prototype);\n }\n}\n\n/**\n * Error thrown when the API returns an error response.\n */\nexport class ApiError extends FhirflyError {\n readonly statusCode: number;\n readonly code?: string;\n readonly details?: unknown;\n\n constructor(\n message: string,\n statusCode: number,\n code?: string,\n details?: unknown\n ) {\n super(message);\n this.name = \"ApiError\";\n this.statusCode = statusCode;\n this.code = code;\n this.details = details;\n Object.setPrototypeOf(this, ApiError.prototype);\n }\n}\n\n/**\n * Error thrown when authentication fails (401).\n */\nexport class AuthenticationError extends ApiError {\n constructor(message = \"Authentication failed. Check your API key.\") {\n super(message, 401, \"AUTHENTICATION_ERROR\");\n this.name = \"AuthenticationError\";\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n\n/**\n * Error thrown when a resource is not found (404).\n */\nexport class NotFoundError extends ApiError {\n readonly code_type: string;\n readonly code_value: string;\n\n constructor(codeType: string, codeValue: string) {\n super(`${codeType} not found: ${codeValue}`, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n this.code_type = codeType;\n this.code_value = codeValue;\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n\n/**\n * Error thrown when the request is invalid (400).\n */\nexport class ValidationError extends ApiError {\n readonly field?: string;\n\n constructor(message: string, field?: string) {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n this.field = field;\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\n/**\n * Error thrown when rate limited (429).\n */\nexport class RateLimitError extends ApiError {\n readonly retryAfter?: number;\n readonly limit?: number;\n readonly remaining?: number;\n readonly reset?: Date;\n\n constructor(\n message = \"Rate limit exceeded\",\n retryAfter?: number,\n limit?: number,\n remaining?: number,\n reset?: Date\n ) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n this.limit = limit;\n this.remaining = remaining;\n this.reset = reset;\n Object.setPrototypeOf(this, RateLimitError.prototype);\n }\n}\n\n/**\n * Error thrown when quota is exceeded (429 with quota context).\n */\nexport class QuotaExceededError extends ApiError {\n readonly quotaLimit?: number;\n readonly quotaUsed?: number;\n readonly quotaResetDate?: Date;\n\n constructor(\n message = \"Monthly quota exceeded\",\n quotaLimit?: number,\n quotaUsed?: number,\n quotaResetDate?: Date\n ) {\n super(message, 429, \"QUOTA_EXCEEDED\");\n this.name = \"QuotaExceededError\";\n this.quotaLimit = quotaLimit;\n this.quotaUsed = quotaUsed;\n this.quotaResetDate = quotaResetDate;\n Object.setPrototypeOf(this, QuotaExceededError.prototype);\n }\n}\n\n/**\n * Error thrown when the server returns a 5xx error.\n */\nexport class ServerError extends ApiError {\n constructor(message = \"Server error\", statusCode = 500) {\n super(message, statusCode, \"SERVER_ERROR\");\n this.name = \"ServerError\";\n Object.setPrototypeOf(this, ServerError.prototype);\n }\n}\n\n/**\n * Error thrown when a network error occurs.\n */\nexport class NetworkError extends FhirflyError {\n readonly cause?: Error;\n\n constructor(message = \"Network error\", cause?: Error) {\n super(message);\n this.name = \"NetworkError\";\n this.cause = cause;\n Object.setPrototypeOf(this, NetworkError.prototype);\n }\n}\n\n/**\n * Error thrown when a request times out.\n */\nexport class TimeoutError extends FhirflyError {\n readonly timeoutMs: number;\n\n constructor(timeoutMs: number) {\n super(`Request timed out after ${timeoutMs}ms`);\n this.name = \"TimeoutError\";\n this.timeoutMs = timeoutMs;\n Object.setPrototypeOf(this, TimeoutError.prototype);\n }\n}\n","import {\n ApiError,\n AuthenticationError,\n NetworkError,\n NotFoundError,\n QuotaExceededError,\n RateLimitError,\n ServerError,\n TimeoutError,\n ValidationError,\n} from \"./errors.js\";\nimport type { LookupOptions } from \"./types/common.js\";\n\n/**\n * HTTP client configuration.\n */\nexport interface HttpClientConfig {\n baseUrl: string;\n apiKey: string;\n timeout?: number;\n maxRetries?: number;\n retryDelay?: number;\n userAgent?: string;\n}\n\n/**\n * HTTP response from the API.\n */\ninterface HttpResponse<T> {\n data: T;\n status: number;\n headers: Headers;\n}\n\n/**\n * Internal HTTP client for making API requests.\n */\nexport class HttpClient {\n private readonly config: Required<HttpClientConfig>;\n\n constructor(config: HttpClientConfig) {\n this.config = {\n baseUrl: config.baseUrl,\n apiKey: config.apiKey,\n timeout: config.timeout ?? 30000,\n maxRetries: config.maxRetries ?? 3,\n retryDelay: config.retryDelay ?? 1000,\n userAgent: config.userAgent ?? `@fhirfly/sdk/0.1.0 Node.js/${process.version}`,\n };\n }\n\n /**\n * Build query string from options.\n */\n private buildQueryString(options?: LookupOptions): string {\n if (!options) return \"\";\n\n const params = new URLSearchParams();\n\n if (options.shape) {\n params.set(\"shape\", options.shape);\n }\n\n if (options.include?.length) {\n params.set(\"include\", options.include.join(\",\"));\n }\n\n const queryString = params.toString();\n return queryString ? `?${queryString}` : \"\";\n }\n\n /**\n * Parse error response from API.\n */\n private async parseErrorResponse(\n response: Response,\n endpoint: string\n ): Promise<never> {\n const status = response.status;\n let body: { message?: string; code?: string; error?: string; details?: unknown } = {};\n\n try {\n body = await response.json() as typeof body;\n } catch {\n // Response body is not JSON\n }\n\n const message = body.message || body.error || response.statusText;\n\n // Handle specific status codes\n switch (status) {\n case 401:\n throw new AuthenticationError(message);\n\n case 404: {\n // Extract code type and value from endpoint\n const match = endpoint.match(/\\/v1\\/(\\w+)\\/(.+)/);\n if (match) {\n throw new NotFoundError(match[1]!.toUpperCase(), match[2]!);\n }\n throw new NotFoundError(\"Resource\", endpoint);\n }\n\n case 400:\n throw new ValidationError(message);\n\n case 429: {\n const retryAfter = response.headers.get(\"retry-after\");\n const limit = response.headers.get(\"x-ratelimit-limit\");\n const remaining = response.headers.get(\"x-ratelimit-remaining\");\n const reset = response.headers.get(\"x-ratelimit-reset\");\n\n // Check if it's a quota error vs rate limit\n if (body.code === \"QUOTA_EXCEEDED\") {\n throw new QuotaExceededError(message);\n }\n\n throw new RateLimitError(\n message,\n retryAfter ? parseInt(retryAfter, 10) : undefined,\n limit ? parseInt(limit, 10) : undefined,\n remaining ? parseInt(remaining, 10) : undefined,\n reset ? new Date(parseInt(reset, 10) * 1000) : undefined\n );\n }\n\n default:\n if (status >= 500) {\n throw new ServerError(message, status);\n }\n throw new ApiError(message, status, body.code, body.details);\n }\n }\n\n /**\n * Sleep for a given number of milliseconds.\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Make an HTTP request with retries.\n */\n private async request<T>(\n method: \"GET\" | \"POST\",\n endpoint: string,\n body?: unknown\n ): Promise<HttpResponse<T>> {\n const url = `${this.config.baseUrl}${endpoint}`;\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n this.config.timeout\n );\n\n const response = await fetch(url, {\n method,\n headers: {\n \"Authorization\": `Bearer ${this.config.apiKey}`,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": this.config.userAgent,\n \"Accept\": \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n // Don't retry client errors (except rate limits)\n if (response.status < 500 && response.status !== 429) {\n await this.parseErrorResponse(response, endpoint);\n }\n\n // For rate limits, check retry-after header\n if (response.status === 429) {\n const retryAfter = response.headers.get(\"retry-after\");\n if (retryAfter && attempt < this.config.maxRetries) {\n await this.sleep(parseInt(retryAfter, 10) * 1000);\n continue;\n }\n await this.parseErrorResponse(response, endpoint);\n }\n\n // Retry server errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n\n await this.parseErrorResponse(response, endpoint);\n }\n\n const data = await response.json() as T;\n return { data, status: response.status, headers: response.headers };\n } catch (error) {\n if (error instanceof ApiError) {\n throw error;\n }\n\n if (error instanceof Error) {\n if (error.name === \"AbortError\") {\n throw new TimeoutError(this.config.timeout);\n }\n\n lastError = error;\n\n // Retry on network errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Unknown network error\",\n lastError\n );\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Request failed after retries\",\n lastError\n );\n }\n\n /**\n * Make a GET request.\n */\n async get<T>(endpoint: string, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"GET\", `${endpoint}${queryString}`);\n return response.data;\n }\n\n /**\n * Make a POST request.\n */\n async post<T>(endpoint: string, body: unknown, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"POST\", `${endpoint}${queryString}`, body);\n return response.data;\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NdcData } from \"../types/ndc.js\";\n\n/**\n * NDC (National Drug Code) API endpoint.\n */\nexport class NdcEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NDC code.\n *\n * @param code - NDC code (10-digit, 11-digit, or hyphenated format)\n * @param options - Response shape and include options\n * @returns NDC data\n *\n * @example\n * ```ts\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n * ```\n */\n async lookup(code: string, options?: LookupOptions): Promise<ApiResponse<NdcData>> {\n return this.http.get<ApiResponse<NdcData>>(`/v1/ndc/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple NDC codes in a single request.\n *\n * @param codes - Array of NDC codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n *\n * @example\n * ```ts\n * const results = await client.ndc.lookupMany([\n * \"0069-0151-01\",\n * \"0069-0151-02\",\n * \"invalid-code\"\n * ]);\n *\n * for (const item of results.results) {\n * if (item.found) {\n * console.log(item.data.product_name);\n * } else {\n * console.log(`Not found: ${item.code}`);\n * }\n * }\n * ```\n */\n async lookupMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NdcData>> {\n return this.http.post<BatchResponse<NdcData>>(\n \"/v1/ndc/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NpiData } from \"../types/npi.js\";\n\n/**\n * NPI (National Provider Identifier) API endpoint.\n */\nexport class NpiEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NPI.\n *\n * @param npi - 10-digit NPI number\n * @param options - Response shape and include options\n * @returns NPI data\n *\n * @example\n * ```ts\n * const npi = await client.npi.lookup(\"1234567890\");\n * console.log(npi.data.name);\n * ```\n */\n async lookup(npi: string, options?: LookupOptions): Promise<ApiResponse<NpiData>> {\n return this.http.get<ApiResponse<NpiData>>(`/v1/npi/${encodeURIComponent(npi)}`, options);\n }\n\n /**\n * Look up multiple NPIs in a single request.\n *\n * @param npis - Array of 10-digit NPI numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each NPI\n *\n * @example\n * ```ts\n * const results = await client.npi.lookupMany([\n * \"1234567890\",\n * \"0987654321\"\n * ]);\n * ```\n */\n async lookupMany(\n npis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NpiData>> {\n return this.http.post<BatchResponse<NpiData>>(\n \"/v1/npi/_batch\",\n { codes: npis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { RxNormData } from \"../types/rxnorm.js\";\n\n/**\n * RxNorm API endpoint.\n */\nexport class RxNormEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single RxCUI.\n *\n * @param rxcui - RxNorm Concept Unique Identifier\n * @param options - Response shape and include options\n * @returns RxNorm data\n *\n * @example\n * ```ts\n * const rx = await client.rxnorm.lookup(\"213169\");\n * console.log(rx.data.name); // \"atorvastatin 10 MG Oral Tablet\"\n * ```\n */\n async lookup(rxcui: string, options?: LookupOptions): Promise<ApiResponse<RxNormData>> {\n return this.http.get<ApiResponse<RxNormData>>(`/v1/rxnorm/${encodeURIComponent(rxcui)}`, options);\n }\n\n /**\n * Look up multiple RxCUIs in a single request.\n *\n * @param rxcuis - Array of RxCUIs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each RxCUI\n */\n async lookupMany(\n rxcuis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<RxNormData>> {\n return this.http.post<BatchResponse<RxNormData>>(\n \"/v1/rxnorm/_batch\",\n { codes: rxcuis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { LoincData } from \"../types/loinc.js\";\n\n/**\n * LOINC API endpoint.\n */\nexport class LoincEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single LOINC code.\n *\n * @param loincNum - LOINC number (e.g., \"2345-7\")\n * @param options - Response shape and include options\n * @returns LOINC data\n *\n * @example\n * ```ts\n * const loinc = await client.loinc.lookup(\"2345-7\");\n * console.log(loinc.data.long_common_name); // \"Glucose [Mass/volume] in Serum or Plasma\"\n * ```\n */\n async lookup(loincNum: string, options?: LookupOptions): Promise<ApiResponse<LoincData>> {\n return this.http.get<ApiResponse<LoincData>>(`/v1/loinc/${encodeURIComponent(loincNum)}`, options);\n }\n\n /**\n * Look up multiple LOINC codes in a single request.\n *\n * @param loincNums - Array of LOINC numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each LOINC\n */\n async lookupMany(\n loincNums: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<LoincData>> {\n return this.http.post<BatchResponse<LoincData>>(\n \"/v1/loinc/_batch\",\n { codes: loincNums },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { Icd10Data } from \"../types/icd10.js\";\n\n/**\n * ICD-10 API endpoint.\n */\nexport class Icd10Endpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single ICD-10-CM code (diagnoses).\n *\n * @param code - ICD-10-CM code (e.g., \"E11.9\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupCm(\"E11.9\");\n * console.log(icd.data.description); // \"Type 2 diabetes mellitus without complications\"\n * ```\n */\n async lookupCm(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/cm/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up a single ICD-10-PCS code (procedures).\n *\n * @param code - ICD-10-PCS code (e.g., \"0BJ08ZZ\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupPcs(\"0BJ08ZZ\");\n * console.log(icd.data.description);\n * ```\n */\n async lookupPcs(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/pcs/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple ICD-10-CM codes in a single request.\n *\n * @param codes - Array of ICD-10-CM codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupCmMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/cm/_batch\",\n { codes },\n options\n );\n }\n\n /**\n * Look up multiple ICD-10-PCS codes in a single request.\n *\n * @param codes - Array of ICD-10-PCS codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupPcsMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/pcs/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { CvxData } from \"../types/cvx.js\";\n\n/**\n * CVX (Vaccine Codes) API endpoint.\n */\nexport class CvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single CVX code.\n *\n * @param cvxCode - CVX vaccine code\n * @param options - Response shape and include options\n * @returns CVX data\n *\n * @example\n * ```ts\n * const cvx = await client.cvx.lookup(\"208\");\n * console.log(cvx.data.short_description); // \"COVID-19, mRNA, LNP-S, PF, 30 mcg/0.3 mL dose\"\n * ```\n */\n async lookup(cvxCode: string, options?: LookupOptions): Promise<ApiResponse<CvxData>> {\n return this.http.get<ApiResponse<CvxData>>(`/v1/cvx/${encodeURIComponent(cvxCode)}`, options);\n }\n\n /**\n * Look up multiple CVX codes in a single request.\n *\n * @param cvxCodes - Array of CVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n cvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<CvxData>> {\n return this.http.post<BatchResponse<CvxData>>(\n \"/v1/cvx/_batch\",\n { codes: cvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { MvxData } from \"../types/mvx.js\";\n\n/**\n * MVX (Vaccine Manufacturer Codes) API endpoint.\n */\nexport class MvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single MVX code.\n *\n * @param mvxCode - MVX manufacturer code\n * @param options - Response shape and include options\n * @returns MVX data\n *\n * @example\n * ```ts\n * const mvx = await client.mvx.lookup(\"PFR\");\n * console.log(mvx.data.manufacturer_name); // \"Pfizer, Inc\"\n * ```\n */\n async lookup(mvxCode: string, options?: LookupOptions): Promise<ApiResponse<MvxData>> {\n return this.http.get<ApiResponse<MvxData>>(`/v1/mvx/${encodeURIComponent(mvxCode)}`, options);\n }\n\n /**\n * Look up multiple MVX codes in a single request.\n *\n * @param mvxCodes - Array of MVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n mvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<MvxData>> {\n return this.http.post<BatchResponse<MvxData>>(\n \"/v1/mvx/_batch\",\n { codes: mvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { FdaLabelData } from \"../types/fda-labels.js\";\n\n/**\n * FDA Labels API endpoint.\n */\nexport class FdaLabelsEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up FDA label by Set ID.\n *\n * @param setId - FDA SPL Set ID\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookup(\"abc123-def456\");\n * console.log(label.data.indications_and_usage);\n * ```\n */\n async lookup(setId: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/${encodeURIComponent(setId)}`, options);\n }\n\n /**\n * Look up FDA label by NDC code.\n *\n * @param ndc - NDC code\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookupByNdc(\"0069-0151-01\");\n * console.log(label.data.product_name);\n * ```\n */\n async lookupByNdc(ndc: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/ndc/${encodeURIComponent(ndc)}`, options);\n }\n\n /**\n * Look up multiple FDA labels by Set IDs in a single request.\n *\n * @param setIds - Array of Set IDs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each Set ID\n */\n async lookupMany(\n setIds: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<FdaLabelData>> {\n return this.http.post<BatchResponse<FdaLabelData>>(\n \"/v1/fda-labels/_batch\",\n { codes: setIds },\n options\n );\n }\n}\n","import { HttpClient, type HttpClientConfig } from \"./http.js\";\nimport { NdcEndpoint } from \"./endpoints/ndc.js\";\nimport { NpiEndpoint } from \"./endpoints/npi.js\";\nimport { RxNormEndpoint } from \"./endpoints/rxnorm.js\";\nimport { LoincEndpoint } from \"./endpoints/loinc.js\";\nimport { Icd10Endpoint } from \"./endpoints/icd10.js\";\nimport { CvxEndpoint } from \"./endpoints/cvx.js\";\nimport { MvxEndpoint } from \"./endpoints/mvx.js\";\nimport { FdaLabelsEndpoint } from \"./endpoints/fda-labels.js\";\n\n/**\n * Configuration options for the FHIRfly client.\n */\nexport interface FhirflyConfig {\n /**\n * Your FHIRfly API key.\n * Get one at https://fhirfly.io/dashboard\n */\n apiKey: string;\n\n /**\n * Base URL for the API.\n * @default \"https://api.fhirfly.io\"\n */\n baseUrl?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n\n /**\n * Maximum number of retry attempts for failed requests.\n * @default 3\n */\n maxRetries?: number;\n\n /**\n * Base delay between retries in milliseconds (exponential backoff).\n * @default 1000\n */\n retryDelay?: number;\n}\n\n/**\n * FHIRfly API client.\n *\n * Provides access to healthcare reference data including drug codes (NDC, RxNorm),\n * provider identifiers (NPI), lab codes (LOINC), diagnosis codes (ICD-10),\n * vaccine codes (CVX, MVX), and FDA drug labels.\n *\n * @example\n * ```ts\n * import { Fhirfly } from \"@fhirfly/sdk\";\n *\n * const client = new Fhirfly({ apiKey: \"your-api-key\" });\n *\n * // Look up a drug by NDC\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n *\n * // Look up a provider by NPI\n * const npi = await client.npi.lookup(\"1234567890\");\n * console.log(npi.data.name);\n *\n * // Batch lookups\n * const results = await client.ndc.lookupMany([\n * \"0069-0151-01\",\n * \"0069-0151-02\"\n * ]);\n * ```\n */\nexport class Fhirfly {\n private readonly http: HttpClient;\n\n /**\n * NDC (National Drug Code) lookups.\n */\n readonly ndc: NdcEndpoint;\n\n /**\n * NPI (National Provider Identifier) lookups.\n */\n readonly npi: NpiEndpoint;\n\n /**\n * RxNorm drug terminology lookups.\n */\n readonly rxnorm: RxNormEndpoint;\n\n /**\n * LOINC laboratory and clinical observation code lookups.\n */\n readonly loinc: LoincEndpoint;\n\n /**\n * ICD-10 diagnosis and procedure code lookups.\n */\n readonly icd10: Icd10Endpoint;\n\n /**\n * CVX vaccine code lookups.\n */\n readonly cvx: CvxEndpoint;\n\n /**\n * MVX vaccine manufacturer code lookups.\n */\n readonly mvx: MvxEndpoint;\n\n /**\n * FDA drug label lookups.\n */\n readonly fdaLabels: FdaLabelsEndpoint;\n\n /**\n * Create a new FHIRfly client.\n *\n * @param config - Client configuration\n * @throws {Error} If apiKey is not provided\n */\n constructor(config: FhirflyConfig) {\n if (!config.apiKey) {\n throw new Error(\n \"FHIRfly API key is required. Get one at https://fhirfly.io/dashboard\"\n );\n }\n\n const httpConfig: HttpClientConfig = {\n baseUrl: config.baseUrl ?? \"https://api.fhirfly.io\",\n apiKey: config.apiKey,\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n };\n\n this.http = new HttpClient(httpConfig);\n\n // Initialize endpoints\n this.ndc = new NdcEndpoint(this.http);\n this.npi = new NpiEndpoint(this.http);\n this.rxnorm = new RxNormEndpoint(this.http);\n this.loinc = new LoincEndpoint(this.http);\n this.icd10 = new Icd10Endpoint(this.http);\n this.cvx = new CvxEndpoint(this.http);\n this.mvx = new MvxEndpoint(this.http);\n this.fdaLabels = new FdaLabelsEndpoint(this.http);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/endpoints/ndc.ts","../src/endpoints/npi.ts","../src/endpoints/rxnorm.ts","../src/endpoints/loinc.ts","../src/endpoints/icd10.ts","../src/endpoints/cvx.ts","../src/endpoints/mvx.ts","../src/endpoints/fda-labels.ts","../src/client.ts"],"names":[],"mappings":";AAGO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AACZ,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,aAAA,CAAa,SAAS,CAAA;AAAA,EACpD;AACF;AAKO,IAAM,QAAA,GAAN,MAAM,SAAA,SAAiB,YAAA,CAAa;AAAA,EAChC,UAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA,EAET,WAAA,CACE,OAAA,EACA,UAAA,EACA,IAAA,EACA,OAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,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F;AAEA,IAAA,IAAA,CAAK,IAAA,GAAO,IAAI,UAAA,CAAW,UAAU,CAAA;AAGrC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,MAAA,GAAS,IAAI,cAAA,CAAe,IAAA,CAAK,IAAI,CAAA;AAC1C,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,KAAA,GAAQ,IAAI,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AACxC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,GAAA,GAAM,IAAI,WAAA,CAAY,IAAA,CAAK,IAAI,CAAA;AACpC,IAAA,IAAA,CAAK,SAAA,GAAY,IAAI,iBAAA,CAAkB,IAAA,CAAK,IAAI,CAAA;AAAA,EAClD;AACF","file":"index.js","sourcesContent":["/**\n * Base error class for all FHIRfly SDK errors.\n */\nexport class FhirflyError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"FhirflyError\";\n Object.setPrototypeOf(this, FhirflyError.prototype);\n }\n}\n\n/**\n * Error thrown when the API returns an error response.\n */\nexport class ApiError extends FhirflyError {\n readonly statusCode: number;\n readonly code?: string;\n readonly details?: unknown;\n\n constructor(\n message: string,\n statusCode: number,\n code?: string,\n details?: unknown\n ) {\n super(message);\n this.name = \"ApiError\";\n this.statusCode = statusCode;\n this.code = code;\n this.details = details;\n Object.setPrototypeOf(this, ApiError.prototype);\n }\n}\n\n/**\n * Error thrown when authentication fails (401).\n */\nexport class AuthenticationError extends ApiError {\n constructor(message = \"Authentication failed. Check your API key.\") {\n super(message, 401, \"AUTHENTICATION_ERROR\");\n this.name = \"AuthenticationError\";\n Object.setPrototypeOf(this, AuthenticationError.prototype);\n }\n}\n\n/**\n * Error thrown when a resource is not found (404).\n */\nexport class NotFoundError extends ApiError {\n readonly code_type: string;\n readonly code_value: string;\n\n constructor(codeType: string, codeValue: string) {\n super(`${codeType} not found: ${codeValue}`, 404, \"NOT_FOUND\");\n this.name = \"NotFoundError\";\n this.code_type = codeType;\n this.code_value = codeValue;\n Object.setPrototypeOf(this, NotFoundError.prototype);\n }\n}\n\n/**\n * Error thrown when the request is invalid (400).\n */\nexport class ValidationError extends ApiError {\n readonly field?: string;\n\n constructor(message: string, field?: string) {\n super(message, 400, \"VALIDATION_ERROR\");\n this.name = \"ValidationError\";\n this.field = field;\n Object.setPrototypeOf(this, ValidationError.prototype);\n }\n}\n\n/**\n * Error thrown when rate limited (429).\n */\nexport class RateLimitError extends ApiError {\n readonly retryAfter?: number;\n readonly limit?: number;\n readonly remaining?: number;\n readonly reset?: Date;\n\n constructor(\n message = \"Rate limit exceeded\",\n retryAfter?: number,\n limit?: number,\n remaining?: number,\n reset?: Date\n ) {\n super(message, 429, \"RATE_LIMIT_EXCEEDED\");\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n this.limit = limit;\n this.remaining = remaining;\n this.reset = reset;\n Object.setPrototypeOf(this, RateLimitError.prototype);\n }\n}\n\n/**\n * Error thrown when quota is exceeded (429 with quota context).\n */\nexport class QuotaExceededError extends ApiError {\n readonly quotaLimit?: number;\n readonly quotaUsed?: number;\n readonly quotaResetDate?: Date;\n\n constructor(\n message = \"Monthly quota exceeded\",\n quotaLimit?: number,\n quotaUsed?: number,\n quotaResetDate?: Date\n ) {\n super(message, 429, \"QUOTA_EXCEEDED\");\n this.name = \"QuotaExceededError\";\n this.quotaLimit = quotaLimit;\n this.quotaUsed = quotaUsed;\n this.quotaResetDate = quotaResetDate;\n Object.setPrototypeOf(this, QuotaExceededError.prototype);\n }\n}\n\n/**\n * Error thrown when the server returns a 5xx error.\n */\nexport class ServerError extends ApiError {\n constructor(message = \"Server error\", statusCode = 500) {\n super(message, statusCode, \"SERVER_ERROR\");\n this.name = \"ServerError\";\n Object.setPrototypeOf(this, ServerError.prototype);\n }\n}\n\n/**\n * Error thrown when a network error occurs.\n */\nexport class NetworkError extends FhirflyError {\n readonly cause?: Error;\n\n constructor(message = \"Network error\", cause?: Error) {\n super(message);\n this.name = \"NetworkError\";\n this.cause = cause;\n Object.setPrototypeOf(this, NetworkError.prototype);\n }\n}\n\n/**\n * Error thrown when a request times out.\n */\nexport class TimeoutError extends FhirflyError {\n readonly timeoutMs: number;\n\n constructor(timeoutMs: number) {\n super(`Request timed out after ${timeoutMs}ms`);\n this.name = \"TimeoutError\";\n this.timeoutMs = timeoutMs;\n Object.setPrototypeOf(this, TimeoutError.prototype);\n }\n}\n","import {\n ApiError,\n AuthenticationError,\n NetworkError,\n NotFoundError,\n QuotaExceededError,\n RateLimitError,\n ServerError,\n TimeoutError,\n ValidationError,\n} from \"./errors.js\";\nimport type { LookupOptions } from \"./types/common.js\";\n\n/**\n * OAuth2 token response from the token endpoint.\n */\ninterface TokenResponse {\n access_token: string;\n token_type: string;\n expires_in: number;\n scope?: string;\n}\n\n/**\n * OAuth2 client credentials configuration.\n */\nexport interface OAuthCredentials {\n clientId: string;\n clientSecret: string;\n tokenUrl: string;\n scopes?: string[];\n}\n\n/**\n * Manages OAuth2 access tokens with automatic refresh.\n */\nexport class TokenManager {\n private readonly credentials: OAuthCredentials;\n private accessToken: string | null = null;\n private expiresAt = 0;\n private refreshPromise: Promise<string> | null = null;\n\n constructor(credentials: OAuthCredentials) {\n this.credentials = credentials;\n }\n\n /**\n * Get a valid access token, refreshing if needed.\n * Deduplicates concurrent refresh calls.\n */\n async getToken(): Promise<string> {\n if (this.accessToken && Date.now() < this.expiresAt) {\n return this.accessToken;\n }\n if (this.refreshPromise) {\n return this.refreshPromise;\n }\n this.refreshPromise = this.fetchToken();\n try {\n return await this.refreshPromise;\n } finally {\n this.refreshPromise = null;\n }\n }\n\n /**\n * Invalidate the cached token (e.g., after a 401 response).\n */\n invalidate(): void {\n this.accessToken = null;\n this.expiresAt = 0;\n }\n\n private async fetchToken(): Promise<string> {\n const body = new URLSearchParams({\n grant_type: \"client_credentials\",\n client_id: this.credentials.clientId,\n client_secret: this.credentials.clientSecret,\n });\n if (this.credentials.scopes?.length) {\n body.set(\"scope\", this.credentials.scopes.join(\" \"));\n }\n\n const response = await fetch(this.credentials.tokenUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body: body.toString(),\n });\n\n if (!response.ok) {\n const text = await response.text().catch(() => \"\");\n throw new AuthenticationError(\n `OAuth2 token exchange failed (${response.status}): ${text}`\n );\n }\n\n const data = (await response.json()) as TokenResponse;\n this.accessToken = data.access_token;\n // Refresh 60s before expiry\n this.expiresAt = Date.now() + (data.expires_in - 60) * 1000;\n return this.accessToken;\n }\n}\n\n/**\n * Authentication mode for the HTTP client.\n */\ntype AuthMode =\n | { type: \"api-key\"; apiKey: string }\n | { type: \"oauth\"; tokenManager: TokenManager };\n\n/**\n * HTTP client configuration.\n */\nexport interface HttpClientConfig {\n baseUrl: string;\n auth: AuthMode;\n timeout?: number;\n maxRetries?: number;\n retryDelay?: number;\n userAgent?: string;\n}\n\n/**\n * HTTP response from the API.\n */\ninterface HttpResponse<T> {\n data: T;\n status: number;\n headers: Headers;\n}\n\n/**\n * Internal HTTP client for making API requests.\n */\nexport class HttpClient {\n private readonly config: Required<Omit<HttpClientConfig, \"auth\">> & { auth: AuthMode };\n\n constructor(config: HttpClientConfig) {\n this.config = {\n baseUrl: config.baseUrl,\n auth: config.auth,\n timeout: config.timeout ?? 30000,\n maxRetries: config.maxRetries ?? 3,\n retryDelay: config.retryDelay ?? 1000,\n userAgent: config.userAgent ?? `@fhirfly/sdk/0.1.0 Node.js/${process.version}`,\n };\n }\n\n /**\n * Build query string from options.\n */\n private buildQueryString(options?: LookupOptions): string {\n if (!options) return \"\";\n\n const params = new URLSearchParams();\n\n if (options.shape) {\n params.set(\"shape\", options.shape);\n }\n\n if (options.include?.length) {\n params.set(\"include\", options.include.join(\",\"));\n }\n\n const queryString = params.toString();\n return queryString ? `?${queryString}` : \"\";\n }\n\n /**\n * Parse error response from API.\n */\n private async parseErrorResponse(\n response: Response,\n endpoint: string\n ): Promise<never> {\n const status = response.status;\n let body: { message?: string; code?: string; error?: string; details?: unknown } = {};\n\n try {\n body = await response.json() as typeof body;\n } catch {\n // Response body is not JSON\n }\n\n const message = body.message || body.error || response.statusText;\n\n // Handle specific status codes\n switch (status) {\n case 401:\n throw new AuthenticationError(message);\n\n case 404: {\n // Extract code type and value from endpoint\n const match = endpoint.match(/\\/v1\\/(\\w+)\\/(.+)/);\n if (match) {\n throw new NotFoundError(match[1]!.toUpperCase(), match[2]!);\n }\n throw new NotFoundError(\"Resource\", endpoint);\n }\n\n case 400:\n throw new ValidationError(message);\n\n case 429: {\n const retryAfter = response.headers.get(\"retry-after\");\n const limit = response.headers.get(\"x-ratelimit-limit\");\n const remaining = response.headers.get(\"x-ratelimit-remaining\");\n const reset = response.headers.get(\"x-ratelimit-reset\");\n\n // Check if it's a quota error vs rate limit\n if (body.code === \"QUOTA_EXCEEDED\") {\n throw new QuotaExceededError(message);\n }\n\n throw new RateLimitError(\n message,\n retryAfter ? parseInt(retryAfter, 10) : undefined,\n limit ? parseInt(limit, 10) : undefined,\n remaining ? parseInt(remaining, 10) : undefined,\n reset ? new Date(parseInt(reset, 10) * 1000) : undefined\n );\n }\n\n default:\n if (status >= 500) {\n throw new ServerError(message, status);\n }\n throw new ApiError(message, status, body.code, body.details);\n }\n }\n\n /**\n * Sleep for a given number of milliseconds.\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n\n /**\n * Get auth headers for the current request.\n */\n private async getAuthHeaders(): Promise<Record<string, string>> {\n if (this.config.auth.type === \"api-key\") {\n return { \"x-api-key\": this.config.auth.apiKey };\n }\n const token = await this.config.auth.tokenManager.getToken();\n return { \"Authorization\": `Bearer ${token}` };\n }\n\n /**\n * Make an HTTP request with retries.\n */\n private async request<T>(\n method: \"GET\" | \"POST\",\n endpoint: string,\n body?: unknown,\n isRetryAfter401 = false\n ): Promise<HttpResponse<T>> {\n const url = `${this.config.baseUrl}${endpoint}`;\n let lastError: Error | undefined;\n\n for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {\n try {\n const controller = new AbortController();\n const timeoutId = setTimeout(\n () => controller.abort(),\n this.config.timeout\n );\n\n const authHeaders = await this.getAuthHeaders();\n\n const response = await fetch(url, {\n method,\n headers: {\n ...authHeaders,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": this.config.userAgent,\n \"Accept\": \"application/json\",\n },\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n // On 401 with OAuth, invalidate token and retry once\n if (\n response.status === 401 &&\n this.config.auth.type === \"oauth\" &&\n !isRetryAfter401\n ) {\n this.config.auth.tokenManager.invalidate();\n return this.request<T>(method, endpoint, body, true);\n }\n\n // Don't retry client errors (except rate limits)\n if (response.status < 500 && response.status !== 429) {\n await this.parseErrorResponse(response, endpoint);\n }\n\n // For rate limits, check retry-after header\n if (response.status === 429) {\n const retryAfter = response.headers.get(\"retry-after\");\n if (retryAfter && attempt < this.config.maxRetries) {\n await this.sleep(parseInt(retryAfter, 10) * 1000);\n continue;\n }\n await this.parseErrorResponse(response, endpoint);\n }\n\n // Retry server errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n\n await this.parseErrorResponse(response, endpoint);\n }\n\n const data = await response.json() as T;\n return { data, status: response.status, headers: response.headers };\n } catch (error) {\n if (error instanceof ApiError) {\n throw error;\n }\n\n if (error instanceof Error) {\n if (error.name === \"AbortError\") {\n throw new TimeoutError(this.config.timeout);\n }\n\n lastError = error;\n\n // Retry on network errors\n if (attempt < this.config.maxRetries) {\n await this.sleep(this.config.retryDelay * Math.pow(2, attempt));\n continue;\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Unknown network error\",\n lastError\n );\n }\n }\n\n throw new NetworkError(\n lastError?.message || \"Request failed after retries\",\n lastError\n );\n }\n\n /**\n * Make a GET request.\n */\n async get<T>(endpoint: string, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"GET\", `${endpoint}${queryString}`);\n return response.data;\n }\n\n /**\n * Make a POST request.\n */\n async post<T>(endpoint: string, body: unknown, options?: LookupOptions): Promise<T> {\n const queryString = this.buildQueryString(options);\n const response = await this.request<T>(\"POST\", `${endpoint}${queryString}`, body);\n return response.data;\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NdcData } from \"../types/ndc.js\";\n\n/**\n * NDC (National Drug Code) API endpoint.\n */\nexport class NdcEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NDC code.\n *\n * @param code - NDC code (10-digit, 11-digit, or hyphenated format)\n * @param options - Response shape and include options\n * @returns NDC data\n *\n * @example\n * ```ts\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n * ```\n */\n async lookup(code: string, options?: LookupOptions): Promise<ApiResponse<NdcData>> {\n return this.http.get<ApiResponse<NdcData>>(`/v1/ndc/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple NDC codes in a single request.\n *\n * @param codes - Array of NDC codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n *\n * @example\n * ```ts\n * const results = await client.ndc.lookupMany([\n * \"0069-0151-01\",\n * \"0069-0151-02\",\n * \"invalid-code\"\n * ]);\n *\n * for (const item of results.results) {\n * if (item.found) {\n * console.log(item.data.product_name);\n * } else {\n * console.log(`Not found: ${item.code}`);\n * }\n * }\n * ```\n */\n async lookupMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NdcData>> {\n return this.http.post<BatchResponse<NdcData>>(\n \"/v1/ndc/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { NpiData } from \"../types/npi.js\";\n\n/**\n * NPI (National Provider Identifier) API endpoint.\n */\nexport class NpiEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single NPI.\n *\n * @param npi - 10-digit NPI number\n * @param options - Response shape and include options\n * @returns NPI data\n *\n * @example\n * ```ts\n * const npi = await client.npi.lookup(\"1234567890\");\n * console.log(npi.data.name);\n * ```\n */\n async lookup(npi: string, options?: LookupOptions): Promise<ApiResponse<NpiData>> {\n return this.http.get<ApiResponse<NpiData>>(`/v1/npi/${encodeURIComponent(npi)}`, options);\n }\n\n /**\n * Look up multiple NPIs in a single request.\n *\n * @param npis - Array of 10-digit NPI numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each NPI\n *\n * @example\n * ```ts\n * const results = await client.npi.lookupMany([\n * \"1234567890\",\n * \"0987654321\"\n * ]);\n * ```\n */\n async lookupMany(\n npis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<NpiData>> {\n return this.http.post<BatchResponse<NpiData>>(\n \"/v1/npi/_batch\",\n { codes: npis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { RxNormData } from \"../types/rxnorm.js\";\n\n/**\n * RxNorm API endpoint.\n */\nexport class RxNormEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single RxCUI.\n *\n * @param rxcui - RxNorm Concept Unique Identifier\n * @param options - Response shape and include options\n * @returns RxNorm data\n *\n * @example\n * ```ts\n * const rx = await client.rxnorm.lookup(\"213169\");\n * console.log(rx.data.name); // \"atorvastatin 10 MG Oral Tablet\"\n * ```\n */\n async lookup(rxcui: string, options?: LookupOptions): Promise<ApiResponse<RxNormData>> {\n return this.http.get<ApiResponse<RxNormData>>(`/v1/rxnorm/${encodeURIComponent(rxcui)}`, options);\n }\n\n /**\n * Look up multiple RxCUIs in a single request.\n *\n * @param rxcuis - Array of RxCUIs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each RxCUI\n */\n async lookupMany(\n rxcuis: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<RxNormData>> {\n return this.http.post<BatchResponse<RxNormData>>(\n \"/v1/rxnorm/_batch\",\n { codes: rxcuis },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { LoincData } from \"../types/loinc.js\";\n\n/**\n * LOINC API endpoint.\n */\nexport class LoincEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single LOINC code.\n *\n * @param loincNum - LOINC number (e.g., \"2345-7\")\n * @param options - Response shape and include options\n * @returns LOINC data\n *\n * @example\n * ```ts\n * const loinc = await client.loinc.lookup(\"2345-7\");\n * console.log(loinc.data.long_common_name); // \"Glucose [Mass/volume] in Serum or Plasma\"\n * ```\n */\n async lookup(loincNum: string, options?: LookupOptions): Promise<ApiResponse<LoincData>> {\n return this.http.get<ApiResponse<LoincData>>(`/v1/loinc/${encodeURIComponent(loincNum)}`, options);\n }\n\n /**\n * Look up multiple LOINC codes in a single request.\n *\n * @param loincNums - Array of LOINC numbers (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each LOINC\n */\n async lookupMany(\n loincNums: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<LoincData>> {\n return this.http.post<BatchResponse<LoincData>>(\n \"/v1/loinc/_batch\",\n { codes: loincNums },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { Icd10Data } from \"../types/icd10.js\";\n\n/**\n * ICD-10 API endpoint.\n */\nexport class Icd10Endpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single ICD-10-CM code (diagnoses).\n *\n * @param code - ICD-10-CM code (e.g., \"E11.9\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupCm(\"E11.9\");\n * console.log(icd.data.description); // \"Type 2 diabetes mellitus without complications\"\n * ```\n */\n async lookupCm(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/cm/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up a single ICD-10-PCS code (procedures).\n *\n * @param code - ICD-10-PCS code (e.g., \"0BJ08ZZ\")\n * @param options - Response shape and include options\n * @returns ICD-10 data\n *\n * @example\n * ```ts\n * const icd = await client.icd10.lookupPcs(\"0BJ08ZZ\");\n * console.log(icd.data.description);\n * ```\n */\n async lookupPcs(code: string, options?: LookupOptions): Promise<ApiResponse<Icd10Data>> {\n return this.http.get<ApiResponse<Icd10Data>>(`/v1/icd10/pcs/${encodeURIComponent(code)}`, options);\n }\n\n /**\n * Look up multiple ICD-10-CM codes in a single request.\n *\n * @param codes - Array of ICD-10-CM codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupCmMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/cm/_batch\",\n { codes },\n options\n );\n }\n\n /**\n * Look up multiple ICD-10-PCS codes in a single request.\n *\n * @param codes - Array of ICD-10-PCS codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupPcsMany(\n codes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<Icd10Data>> {\n return this.http.post<BatchResponse<Icd10Data>>(\n \"/v1/icd10/pcs/_batch\",\n { codes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { CvxData } from \"../types/cvx.js\";\n\n/**\n * CVX (Vaccine Codes) API endpoint.\n */\nexport class CvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single CVX code.\n *\n * @param cvxCode - CVX vaccine code\n * @param options - Response shape and include options\n * @returns CVX data\n *\n * @example\n * ```ts\n * const cvx = await client.cvx.lookup(\"208\");\n * console.log(cvx.data.short_description); // \"COVID-19, mRNA, LNP-S, PF, 30 mcg/0.3 mL dose\"\n * ```\n */\n async lookup(cvxCode: string, options?: LookupOptions): Promise<ApiResponse<CvxData>> {\n return this.http.get<ApiResponse<CvxData>>(`/v1/cvx/${encodeURIComponent(cvxCode)}`, options);\n }\n\n /**\n * Look up multiple CVX codes in a single request.\n *\n * @param cvxCodes - Array of CVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n cvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<CvxData>> {\n return this.http.post<BatchResponse<CvxData>>(\n \"/v1/cvx/_batch\",\n { codes: cvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { MvxData } from \"../types/mvx.js\";\n\n/**\n * MVX (Vaccine Manufacturer Codes) API endpoint.\n */\nexport class MvxEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up a single MVX code.\n *\n * @param mvxCode - MVX manufacturer code\n * @param options - Response shape and include options\n * @returns MVX data\n *\n * @example\n * ```ts\n * const mvx = await client.mvx.lookup(\"PFR\");\n * console.log(mvx.data.manufacturer_name); // \"Pfizer, Inc\"\n * ```\n */\n async lookup(mvxCode: string, options?: LookupOptions): Promise<ApiResponse<MvxData>> {\n return this.http.get<ApiResponse<MvxData>>(`/v1/mvx/${encodeURIComponent(mvxCode)}`, options);\n }\n\n /**\n * Look up multiple MVX codes in a single request.\n *\n * @param mvxCodes - Array of MVX codes (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each code\n */\n async lookupMany(\n mvxCodes: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<MvxData>> {\n return this.http.post<BatchResponse<MvxData>>(\n \"/v1/mvx/_batch\",\n { codes: mvxCodes },\n options\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type {\n ApiResponse,\n BatchResponse,\n LookupOptions,\n BatchLookupOptions,\n} from \"../types/common.js\";\nimport type { FdaLabelData } from \"../types/fda-labels.js\";\n\n/**\n * FDA Labels API endpoint.\n */\nexport class FdaLabelsEndpoint {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Look up FDA label by Set ID.\n *\n * @param setId - FDA SPL Set ID\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookup(\"abc123-def456\");\n * console.log(label.data.indications_and_usage);\n * ```\n */\n async lookup(setId: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/${encodeURIComponent(setId)}`, options);\n }\n\n /**\n * Look up FDA label by NDC code.\n *\n * @param ndc - NDC code\n * @param options - Response shape and include options\n * @returns FDA Label data\n *\n * @example\n * ```ts\n * const label = await client.fdaLabels.lookupByNdc(\"0069-0151-01\");\n * console.log(label.data.product_name);\n * ```\n */\n async lookupByNdc(ndc: string, options?: LookupOptions): Promise<ApiResponse<FdaLabelData>> {\n return this.http.get<ApiResponse<FdaLabelData>>(`/v1/fda-labels/ndc/${encodeURIComponent(ndc)}`, options);\n }\n\n /**\n * Look up multiple FDA labels by Set IDs in a single request.\n *\n * @param setIds - Array of Set IDs (max 500)\n * @param options - Response shape, include, and batch options\n * @returns Batch response with results for each Set ID\n */\n async lookupMany(\n setIds: string[],\n options?: BatchLookupOptions\n ): Promise<BatchResponse<FdaLabelData>> {\n return this.http.post<BatchResponse<FdaLabelData>>(\n \"/v1/fda-labels/_batch\",\n { codes: setIds },\n options\n );\n }\n}\n","import { HttpClient, TokenManager, type HttpClientConfig } from \"./http.js\";\nimport { NdcEndpoint } from \"./endpoints/ndc.js\";\nimport { NpiEndpoint } from \"./endpoints/npi.js\";\nimport { RxNormEndpoint } from \"./endpoints/rxnorm.js\";\nimport { LoincEndpoint } from \"./endpoints/loinc.js\";\nimport { Icd10Endpoint } from \"./endpoints/icd10.js\";\nimport { CvxEndpoint } from \"./endpoints/cvx.js\";\nimport { MvxEndpoint } from \"./endpoints/mvx.js\";\nimport { FdaLabelsEndpoint } from \"./endpoints/fda-labels.js\";\n\n/**\n * Base configuration options shared by all auth modes.\n */\ninterface FhirflyBaseConfig {\n /**\n * Base URL for the API.\n * @default \"https://api.fhirfly.io\"\n */\n baseUrl?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 30000\n */\n timeout?: number;\n\n /**\n * Maximum number of retry attempts for failed requests.\n * @default 3\n */\n maxRetries?: number;\n\n /**\n * Base delay between retries in milliseconds (exponential backoff).\n * @default 1000\n */\n retryDelay?: number;\n}\n\n/**\n * Configuration using an API key (simple credentials).\n */\nexport interface FhirflyApiKeyConfig extends FhirflyBaseConfig {\n /**\n * Your FHIRfly API key.\n * Get one at https://fhirfly.io/dashboard\n */\n apiKey: string;\n clientId?: never;\n clientSecret?: never;\n tokenUrl?: never;\n scopes?: never;\n}\n\n/**\n * Configuration using OAuth2 client credentials (secure credentials).\n */\nexport interface FhirflyOAuthConfig extends FhirflyBaseConfig {\n /**\n * OAuth2 client ID from your secure credential.\n */\n clientId: string;\n\n /**\n * OAuth2 client secret from your secure credential.\n */\n clientSecret: string;\n\n /**\n * OAuth2 token endpoint URL.\n * @default \"{baseUrl}/oauth2/token\"\n */\n tokenUrl?: string;\n\n /**\n * OAuth2 scopes to request.\n */\n scopes?: string[];\n\n apiKey?: never;\n}\n\n/**\n * Configuration options for the FHIRfly client.\n * Provide either `apiKey` OR `clientId`+`clientSecret`, not both.\n */\nexport type FhirflyConfig = FhirflyApiKeyConfig | FhirflyOAuthConfig;\n\n/**\n * FHIRfly API client.\n *\n * Provides access to healthcare reference data including drug codes (NDC, RxNorm),\n * provider identifiers (NPI), lab codes (LOINC), diagnosis codes (ICD-10),\n * vaccine codes (CVX, MVX), and FDA drug labels.\n *\n * @example\n * ```ts\n * import { Fhirfly } from \"@fhirfly/sdk\";\n *\n * // Option A: API key (simple)\n * const client = new Fhirfly({ apiKey: \"ffly_sk_live_...\" });\n *\n * // Option B: Client credentials (secure)\n * const client = new Fhirfly({\n * clientId: \"ffly_client_...\",\n * clientSecret: \"ffly_secret_...\",\n * });\n *\n * // Look up a drug by NDC\n * const ndc = await client.ndc.lookup(\"0069-0151-01\");\n * console.log(ndc.data.product_name); // \"Lipitor\"\n * ```\n */\nexport class Fhirfly {\n private readonly http: HttpClient;\n\n /**\n * NDC (National Drug Code) lookups.\n */\n readonly ndc: NdcEndpoint;\n\n /**\n * NPI (National Provider Identifier) lookups.\n */\n readonly npi: NpiEndpoint;\n\n /**\n * RxNorm drug terminology lookups.\n */\n readonly rxnorm: RxNormEndpoint;\n\n /**\n * LOINC laboratory and clinical observation code lookups.\n */\n readonly loinc: LoincEndpoint;\n\n /**\n * ICD-10 diagnosis and procedure code lookups.\n */\n readonly icd10: Icd10Endpoint;\n\n /**\n * CVX vaccine code lookups.\n */\n readonly cvx: CvxEndpoint;\n\n /**\n * MVX vaccine manufacturer code lookups.\n */\n readonly mvx: MvxEndpoint;\n\n /**\n * FDA drug label lookups.\n */\n readonly fdaLabels: FdaLabelsEndpoint;\n\n /**\n * Create a new FHIRfly client.\n *\n * @param config - Client configuration (API key or OAuth2 client credentials)\n * @throws {Error} If neither apiKey nor clientId+clientSecret is provided\n */\n constructor(config: FhirflyConfig) {\n const baseUrl = config.baseUrl ?? \"https://api.fhirfly.io\";\n\n let httpConfig: HttpClientConfig;\n\n if (\"apiKey\" in config && config.apiKey) {\n httpConfig = {\n baseUrl,\n auth: { type: \"api-key\", apiKey: config.apiKey },\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n };\n } else if (\"clientId\" in config && config.clientId && config.clientSecret) {\n const tokenManager = new TokenManager({\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n tokenUrl: config.tokenUrl ?? `${baseUrl}/oauth2/token`,\n scopes: config.scopes,\n });\n httpConfig = {\n baseUrl,\n auth: { type: \"oauth\", tokenManager },\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n retryDelay: config.retryDelay,\n };\n } else {\n throw new Error(\n \"FHIRfly requires either an apiKey or clientId+clientSecret. Get credentials at https://fhirfly.io/dashboard\"\n );\n }\n\n this.http = new HttpClient(httpConfig);\n\n // Initialize endpoints\n this.ndc = new NdcEndpoint(this.http);\n this.npi = new NpiEndpoint(this.http);\n this.rxnorm = new RxNormEndpoint(this.http);\n this.loinc = new LoincEndpoint(this.http);\n this.icd10 = new Icd10Endpoint(this.http);\n this.cvx = new CvxEndpoint(this.http);\n this.mvx = new MvxEndpoint(this.http);\n this.fdaLabels = new FdaLabelsEndpoint(this.http);\n }\n}\n"]}
|