@clinia/context-engine-js 0.5.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ import type { components } from "./context-engine";
2
+ export type ServiceInfo = components["schemas"]["ServiceInfo"];
3
+ export type PatientList = components["schemas"]["PatientList"];
4
+ export type PatientDetail = components["schemas"]["PatientDetail"];
5
+ export type ApiError = components["schemas"]["ApiError"];
6
+ export type Patient = components["schemas"]["Patient"];
7
+ export type ResolutionReport = components["schemas"]["ResolutionReport"];
8
+ export type ReconciliationData = components["schemas"]["ReconciliationData"];
9
+ export type IngestExecutionEnvelope = components["schemas"]["IngestExecutionEnvelope"];
10
+ export type IngestExecutionStatus = components["schemas"]["IngestExecutionStatus"];
11
+ export type IngestSourceLabel = components["schemas"]["IngestSourceLabel"];
12
+ export type PatientRef = components["schemas"]["PatientRef"];
13
+ export type IngestDocumentBody = components["schemas"]["IngestDocumentBody"];
14
+ export type IngestBatchBody = components["schemas"]["IngestBatchBody"];
15
+ export type IngestStatusResponse = components["schemas"]["IngestStatusResponse"];
16
+ export type IngestStats = components["schemas"]["IngestStats"];
17
+ export type IngestExecutionList = components["schemas"]["IngestExecutionList"];
18
+ export type IngestExecutionListItem = components["schemas"]["IngestExecutionListItem"];
19
+ export type IngestExecutionDetail = components["schemas"]["IngestExecutionDetail"];
20
+ export type Session = components["schemas"]["Session"];
21
+ export type AppendMessagesBody = components["schemas"]["AppendMessagesBody"];
22
+ export type SessionMemoryList = components["schemas"]["SessionMemoryList"];
23
+ export type SessionMemory = components["schemas"]["SessionMemory"];
24
+ export type IngestSessionBody = components["schemas"]["IngestSessionBody"];
25
+ export type BrowseResult = components["schemas"]["BrowseResult"];
26
+ export type ReadResponse = components["schemas"]["ReadResponse"];
@@ -0,0 +1,40 @@
1
+ import { type Client, type Middleware } from "openapi-fetch";
2
+ import { type ClientCredentialsConfig } from "./auth";
3
+ import type { paths } from "./generated/context-engine";
4
+ export type HttpClientOptions = {
5
+ baseUrl: string;
6
+ /**
7
+ * Custom fetch implementation. Defaults to `globalThis.fetch`.
8
+ * Works in Node 20+ and all modern browsers out of the box.
9
+ * Useful for injecting a mock or a custom fetch in tests.
10
+ */
11
+ fetch?: typeof globalThis.fetch;
12
+ /**
13
+ * How to authenticate against a secured Context Engine server. Accepts either
14
+ * shape:
15
+ *
16
+ * - A {@link ClientCredentialsConfig} — the common case. Pass just your OAuth2
17
+ * client credentials and the client sets up token acquisition, caching, and
18
+ * refresh for you.
19
+ * - A token function `() => string | Promise<string>` — the escape hatch for
20
+ * full control (a token from elsewhere, a different grant, or a custom
21
+ * refresh strategy). Called per request, so a provider can cache and refresh
22
+ * internally (e.g. {@link createClientCredentialsTokenProvider}); a falsy
23
+ * return value leaves the header unset.
24
+ *
25
+ * Either way the resolved token is attached as `Authorization: Bearer <token>`
26
+ * on every request. Omit for an unsecured server.
27
+ */
28
+ auth?: ClientCredentialsConfig | (() => string | Promise<string>);
29
+ };
30
+ export declare class HttpClient {
31
+ #private;
32
+ constructor(options: HttpClientOptions);
33
+ get GET(): Client<paths>["GET"];
34
+ get POST(): Client<paths>["POST"];
35
+ get PUT(): Client<paths>["PUT"];
36
+ get PATCH(): Client<paths>["PATCH"];
37
+ get DELETE(): Client<paths>["DELETE"];
38
+ use(...middleware: Middleware[]): this;
39
+ eject(...middleware: Middleware[]): this;
40
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./auth";
2
+ export * from "./generated/context-engine";
3
+ export * from "./generated/types";
4
+ export * from "./http-client";
5
+ export * from "./context-engine-client";
package/dist/index.js ADDED
@@ -0,0 +1,164 @@
1
+ // src/auth.ts
2
+ import * as oauth from "oauth4webapi";
3
+ var CLINIA_OAUTH_TOKEN_URL = "https://console.clinia.cloud/api/auth/oauth2/token";
4
+ var CLINIA_OAUTH_RESOURCE = "https://console.clinia.cloud";
5
+ var DEFAULT_EXPIRY_MARGIN_MS = 6e4;
6
+ var DEFAULT_TTL_MS = 5 * 6e4;
7
+ function describeOAuthError(err) {
8
+ if (err instanceof oauth.ResponseBodyError) {
9
+ return `${err.status} ${err.error}${err.error_description ? ` \u2014 ${err.error_description}` : ""}`;
10
+ }
11
+ if (err instanceof oauth.WWWAuthenticateChallengeError) {
12
+ return `${err.status} ${err.message}`;
13
+ }
14
+ return err instanceof Error ? err.message : String(err);
15
+ }
16
+ function createClientCredentialsTokenProvider(config) {
17
+ const expiryMarginMs = config.expiryMarginMs ?? DEFAULT_EXPIRY_MARGIN_MS;
18
+ const usesCliniaAuthServer = !config.tokenUrl && !config.issuer;
19
+ const resource = config.resource ?? (usesCliniaAuthServer ? CLINIA_OAUTH_RESOURCE : void 0);
20
+ const client = { client_id: config.clientId };
21
+ const clientAuth = config.authMethod === "basic" ? oauth.ClientSecretBasic(config.clientSecret) : oauth.ClientSecretPost(config.clientSecret);
22
+ const fetchImpl = config.fetch;
23
+ const isInsecure = (url) => !!url && new URL(url).protocol === "http:";
24
+ function withHttpOptions(opts, insecure) {
25
+ const o = opts;
26
+ if (fetchImpl) {
27
+ o[oauth.customFetch] = ((url, options) => fetchImpl(url, options));
28
+ }
29
+ if (insecure) o[oauth.allowInsecureRequests] = true;
30
+ return o;
31
+ }
32
+ let resolvedAs = null;
33
+ let asInFlight = null;
34
+ async function resolveAuthServer() {
35
+ if (!config.issuer || config.tokenUrl) {
36
+ const tokenUrl = config.tokenUrl ?? CLINIA_OAUTH_TOKEN_URL;
37
+ return {
38
+ issuer: config.issuer ?? new URL(tokenUrl).origin,
39
+ token_endpoint: tokenUrl
40
+ };
41
+ }
42
+ const issuerUrl = new URL(config.issuer);
43
+ const response = await oauth.discoveryRequest(
44
+ issuerUrl,
45
+ withHttpOptions(
46
+ { algorithm: config.discoveryAlgorithm ?? "oidc" },
47
+ isInsecure(config.issuer)
48
+ )
49
+ );
50
+ return oauth.processDiscoveryResponse(issuerUrl, response);
51
+ }
52
+ function getAuthServer() {
53
+ if (resolvedAs) return Promise.resolve(resolvedAs);
54
+ if (!asInFlight) {
55
+ asInFlight = resolveAuthServer().then((as) => resolvedAs = as).finally(() => {
56
+ asInFlight = null;
57
+ });
58
+ }
59
+ return asInFlight;
60
+ }
61
+ let cachedToken = null;
62
+ let expiresAt = 0;
63
+ let inFlight = null;
64
+ async function fetchToken() {
65
+ const params = new URLSearchParams();
66
+ if (resource) params.set("resource", resource);
67
+ if (config.audience) params.set("audience", config.audience);
68
+ if (config.scope) params.set("scope", config.scope);
69
+ let result;
70
+ try {
71
+ const as = await getAuthServer();
72
+ const response = await oauth.clientCredentialsGrantRequest(
73
+ as,
74
+ client,
75
+ clientAuth,
76
+ params,
77
+ withHttpOptions(
78
+ {},
79
+ isInsecure(as.token_endpoint)
80
+ )
81
+ );
82
+ result = await oauth.processClientCredentialsResponse(as, client, response);
83
+ } catch (err) {
84
+ throw new Error(`client_credentials token request failed: ${describeOAuthError(err)}`, {
85
+ cause: err
86
+ });
87
+ }
88
+ const ttlMs = result.expires_in ? result.expires_in * 1e3 : DEFAULT_TTL_MS;
89
+ cachedToken = result.access_token;
90
+ expiresAt = Date.now() + Math.max(0, ttlMs - expiryMarginMs);
91
+ return cachedToken;
92
+ }
93
+ return async function getAccessToken() {
94
+ if (cachedToken && Date.now() < expiresAt) return cachedToken;
95
+ if (inFlight) return inFlight;
96
+ inFlight = fetchToken().finally(() => {
97
+ inFlight = null;
98
+ });
99
+ return inFlight;
100
+ };
101
+ }
102
+
103
+ // src/http-client.ts
104
+ import createFetchClient from "openapi-fetch";
105
+ var HttpClient = class {
106
+ #client;
107
+ constructor(options) {
108
+ this.#client = createFetchClient({
109
+ baseUrl: options.baseUrl,
110
+ fetch: options.fetch
111
+ });
112
+ const getAccessToken = typeof options.auth === "function" ? options.auth : options.auth ? createClientCredentialsTokenProvider({ fetch: options.fetch, ...options.auth }) : void 0;
113
+ if (getAccessToken) {
114
+ const authMiddleware = {
115
+ async onRequest({ request }) {
116
+ const token = await getAccessToken();
117
+ if (token) request.headers.set("Authorization", `Bearer ${token}`);
118
+ return request;
119
+ }
120
+ };
121
+ this.#client.use(authMiddleware);
122
+ }
123
+ }
124
+ get GET() {
125
+ return this.#client.GET;
126
+ }
127
+ get POST() {
128
+ return this.#client.POST;
129
+ }
130
+ get PUT() {
131
+ return this.#client.PUT;
132
+ }
133
+ get PATCH() {
134
+ return this.#client.PATCH;
135
+ }
136
+ get DELETE() {
137
+ return this.#client.DELETE;
138
+ }
139
+ use(...middleware) {
140
+ this.#client.use(...middleware);
141
+ return this;
142
+ }
143
+ eject(...middleware) {
144
+ this.#client.eject(...middleware);
145
+ return this;
146
+ }
147
+ };
148
+
149
+ // src/context-engine-client.ts
150
+ var ContextEngineClient = class {
151
+ /**
152
+ * Low-level http client. Use when a resource method does not cover your use case.
153
+ */
154
+ http;
155
+ constructor(options) {
156
+ this.http = new HttpClient(options);
157
+ }
158
+ };
159
+ export {
160
+ ContextEngineClient,
161
+ HttpClient,
162
+ createClientCredentialsTokenProvider
163
+ };
164
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/auth.ts","../src/http-client.ts","../src/context-engine-client.ts"],"sourcesContent":["import * as oauth from \"oauth4webapi\";\n\n/**\n * OAuth2 client-credentials helpers for authenticating against a secured\n * Context Engine workspace.\n *\n * The server validates a bearer JWT in the `Authorization` header against a\n * JWKS. This module provides the client half: a token provider that exchanges\n * a `client_id`/`client_secret` for an access token, caches it, and refreshes\n * it before expiry. The token exchange itself is delegated to `oauth4webapi`\n * (standards-compliant request building + response validation); this module\n * only adds caching, concurrent-request de-duplication, and a small config\n * surface. Pass the raw config as {@link HttpClientOptions.auth}, or — for full\n * control — pass the returned provider as the {@link HttpClientOptions.auth}\n * token function.\n */\n\n/**\n * Resolves to a currently-valid bearer access token. Called per request; a\n * well-behaved provider caches internally and only hits the network when the\n * cached token is missing or about to expire.\n */\nexport type TokenProvider = () => Promise<string>;\n\n/**\n * Clinia's authorization server, applied when a config names neither a\n * `tokenUrl` nor an `issuer` — so `{ clientId, clientSecret }` is a complete\n * config for a Clinia workspace, which is the overwhelmingly common case.\n *\n * `RESOURCE` is only defaulted alongside `TOKEN_URL`: it is an RFC 8707\n * indicator naming Clinia's protected resource, and sending it to somebody\n * else's authorization server would be wrong.\n */\nconst CLINIA_OAUTH_TOKEN_URL = \"https://console.clinia.cloud/api/auth/oauth2/token\";\nconst CLINIA_OAUTH_RESOURCE = \"https://console.clinia.cloud\";\n\n/** Fields common to both ways of locating the authorization server. */\ntype ClientCredentialsBase = {\n clientId: string;\n clientSecret: string;\n /**\n * Optional `resource` indicator (RFC 8707) naming the protected resource the\n * token is for. This is what the Clinia authorization server expects (e.g.\n * `https://console.clinia.cloud`).\n */\n resource?: string;\n /** Optional `audience` parameter (used by some IdPs, e.g. Auth0). */\n audience?: string;\n /** Optional space-delimited `scope`. */\n scope?: string;\n /**\n * How the client credentials are presented to the token endpoint. `post`\n * (the default) sends them in the request body — what the Clinia\n * authorization server expects; `basic` sends them in the `Authorization`\n * header (RFC 6749 §2.3.1) for IdPs that require it.\n */\n authMethod?: \"basic\" | \"post\";\n /**\n * Custom fetch implementation. Defaults to `globalThis.fetch`. Useful for\n * injecting a mock in tests.\n */\n fetch?: typeof globalThis.fetch;\n /**\n * Refresh the token this many milliseconds before it actually expires, to\n * avoid handing out a token that expires mid-flight. Defaults to 60_000.\n */\n expiryMarginMs?: number;\n};\n\n/**\n * Client-credentials configuration.\n *\n * For a Clinia workspace, `{ clientId, clientSecret }` is enough — the token\n * endpoint and `resource` indicator default to Clinia's authorization server.\n * Naming an {@link issuer} instead locates a different authorization server by\n * OIDC/OAuth2 discovery; naming a {@link tokenUrl} points at one explicitly.\n */\nexport type ClientCredentialsConfig =\n | (ClientCredentialsBase & {\n /**\n * Issuer identifier of the authorization server. Its metadata (token\n * endpoint, etc.) is resolved via discovery on first use.\n */\n issuer: string;\n /** Discovery transformation: `oidc` (default) or `oauth2` (RFC 8414). */\n discoveryAlgorithm?: \"oidc\" | \"oauth2\";\n tokenUrl?: never;\n })\n | (ClientCredentialsBase & {\n /**\n * Explicit OAuth2 token endpoint; discovery is skipped. Omit it — along\n * with `issuer` — to use Clinia's.\n */\n tokenUrl?: string;\n /** Issuer identifier for response validation; defaults to the token URL's origin. */\n issuer?: string;\n discoveryAlgorithm?: never;\n });\n\nconst DEFAULT_EXPIRY_MARGIN_MS = 60_000;\n/** Fallback lifetime when the token endpoint omits `expires_in`. */\nconst DEFAULT_TTL_MS = 5 * 60_000;\n\n/** Turns an `oauth4webapi` failure into a concise, stable error message. */\nfunction describeOAuthError(err: unknown): string {\n if (err instanceof oauth.ResponseBodyError) {\n return `${err.status} ${err.error}${err.error_description ? ` — ${err.error_description}` : \"\"}`;\n }\n if (err instanceof oauth.WWWAuthenticateChallengeError) {\n return `${err.status} ${err.message}`;\n }\n return err instanceof Error ? err.message : String(err);\n}\n\n/**\n * Builds a {@link TokenProvider} backed by the OAuth2 client-credentials grant.\n *\n * The provider caches the access token and reuses it until it is within\n * `expiryMarginMs` of expiry. Concurrent calls while a fetch is in flight share\n * the same request rather than each hitting the token endpoint. When configured\n * with an {@link ClientCredentialsConfig.issuer}, the authorization server\n * metadata is discovered once and memoized.\n */\nexport function createClientCredentialsTokenProvider(\n config: ClientCredentialsConfig,\n): TokenProvider {\n const expiryMarginMs = config.expiryMarginMs ?? DEFAULT_EXPIRY_MARGIN_MS;\n\n // Defaulted only when the token endpoint is also defaulted. `resource` names\n // Clinia's protected resource, so attaching it to a request aimed at somebody\n // else's authorization server would be both wrong and a small disclosure.\n const usesCliniaAuthServer = !config.tokenUrl && !config.issuer;\n const resource = config.resource ?? (usesCliniaAuthServer ? CLINIA_OAUTH_RESOURCE : undefined);\n\n const client: oauth.Client = { client_id: config.clientId };\n const clientAuth =\n config.authMethod === \"basic\"\n ? oauth.ClientSecretBasic(config.clientSecret)\n : oauth.ClientSecretPost(config.clientSecret);\n\n // Shared HTTP options (custom fetch + insecure opt-in) applied to every\n // oauth4webapi call. The `as never` bridges the customFetch signature, which\n // is generic over method/body per call site but is the same fn at runtime.\n // oauth4webapi rejects non-TLS endpoints by default; we relax that per call\n // when — and only when — the target URL is itself `http://` (local dev),\n // rather than exposing a separate flag.\n const fetchImpl = config.fetch;\n const isInsecure = (url: string | undefined): boolean =>\n !!url && new URL(url).protocol === \"http:\";\n function withHttpOptions<T extends object>(opts: T, insecure: boolean): T {\n const o = opts as T & {\n [oauth.customFetch]?: unknown;\n [oauth.allowInsecureRequests]?: boolean;\n };\n if (fetchImpl) {\n o[oauth.customFetch] = ((url: string, options: RequestInit) =>\n fetchImpl(url, options)) as never;\n }\n if (insecure) o[oauth.allowInsecureRequests] = true;\n return o;\n }\n\n // Authorization server metadata, resolved once. For an explicit tokenUrl it's\n // synchronous; for an issuer it requires a discovery request, so it's async\n // and memoized (with retry on failure — a rejected attempt isn't cached).\n let resolvedAs: oauth.AuthorizationServer | null = null;\n let asInFlight: Promise<oauth.AuthorizationServer> | null = null;\n\n async function resolveAuthServer(): Promise<oauth.AuthorizationServer> {\n // Discovery only when an issuer is named and no explicit endpoint overrides\n // it. There is no \"neither given\" case left to handle — that is the Clinia\n // default, which is why this no longer throws.\n if (!config.issuer || config.tokenUrl) {\n const tokenUrl = config.tokenUrl ?? CLINIA_OAUTH_TOKEN_URL;\n return {\n issuer: config.issuer ?? new URL(tokenUrl).origin,\n token_endpoint: tokenUrl,\n };\n }\n const issuerUrl = new URL(config.issuer);\n const response = await oauth.discoveryRequest(\n issuerUrl,\n withHttpOptions<oauth.DiscoveryRequestOptions>(\n { algorithm: config.discoveryAlgorithm ?? \"oidc\" },\n isInsecure(config.issuer),\n ),\n );\n return oauth.processDiscoveryResponse(issuerUrl, response);\n }\n\n function getAuthServer(): Promise<oauth.AuthorizationServer> {\n if (resolvedAs) return Promise.resolve(resolvedAs);\n if (!asInFlight) {\n asInFlight = resolveAuthServer()\n .then((as) => (resolvedAs = as))\n .finally(() => {\n asInFlight = null;\n });\n }\n return asInFlight;\n }\n\n let cachedToken: string | null = null;\n /** Absolute epoch ms at which the cached token should be considered stale. */\n let expiresAt = 0;\n /** In-flight fetch, shared across concurrent callers to dedupe requests. */\n let inFlight: Promise<string> | null = null;\n\n async function fetchToken(): Promise<string> {\n const params = new URLSearchParams();\n if (resource) params.set(\"resource\", resource);\n if (config.audience) params.set(\"audience\", config.audience);\n if (config.scope) params.set(\"scope\", config.scope);\n\n let result: oauth.TokenEndpointResponse;\n try {\n const as = await getAuthServer();\n const response = await oauth.clientCredentialsGrantRequest(\n as,\n client,\n clientAuth,\n params,\n withHttpOptions<oauth.ClientCredentialsGrantRequestOptions>(\n {},\n isInsecure(as.token_endpoint),\n ),\n );\n result = await oauth.processClientCredentialsResponse(as, client, response);\n } catch (err) {\n throw new Error(`client_credentials token request failed: ${describeOAuthError(err)}`, {\n cause: err,\n });\n }\n\n const ttlMs = result.expires_in ? result.expires_in * 1000 : DEFAULT_TTL_MS;\n cachedToken = result.access_token;\n expiresAt = Date.now() + Math.max(0, ttlMs - expiryMarginMs);\n return cachedToken;\n }\n\n return async function getAccessToken(): Promise<string> {\n if (cachedToken && Date.now() < expiresAt) return cachedToken;\n if (inFlight) return inFlight;\n\n inFlight = fetchToken().finally(() => {\n inFlight = null;\n });\n return inFlight;\n };\n}\n","import createFetchClient, { type Client, type Middleware } from \"openapi-fetch\";\n\nimport { createClientCredentialsTokenProvider, type ClientCredentialsConfig } from \"./auth\";\nimport type { paths } from \"./generated/context-engine\";\n\nexport type HttpClientOptions = {\n baseUrl: string;\n /**\n * Custom fetch implementation. Defaults to `globalThis.fetch`.\n * Works in Node 20+ and all modern browsers out of the box.\n * Useful for injecting a mock or a custom fetch in tests.\n */\n fetch?: typeof globalThis.fetch;\n /**\n * How to authenticate against a secured Context Engine server. Accepts either\n * shape:\n *\n * - A {@link ClientCredentialsConfig} — the common case. Pass just your OAuth2\n * client credentials and the client sets up token acquisition, caching, and\n * refresh for you.\n * - A token function `() => string | Promise<string>` — the escape hatch for\n * full control (a token from elsewhere, a different grant, or a custom\n * refresh strategy). Called per request, so a provider can cache and refresh\n * internally (e.g. {@link createClientCredentialsTokenProvider}); a falsy\n * return value leaves the header unset.\n *\n * Either way the resolved token is attached as `Authorization: Bearer <token>`\n * on every request. Omit for an unsecured server.\n */\n auth?: ClientCredentialsConfig | (() => string | Promise<string>);\n};\n\nexport class HttpClient {\n readonly #client: Client<paths>;\n\n constructor(options: HttpClientOptions) {\n this.#client = createFetchClient<paths>({\n baseUrl: options.baseUrl,\n fetch: options.fetch,\n });\n\n // A token function is used as-is; a config object builds a client-credentials\n // provider. The custom `fetch` is threaded into the token exchange too so\n // tests/proxies apply to both hops.\n const getAccessToken =\n typeof options.auth === \"function\"\n ? options.auth\n : options.auth\n ? createClientCredentialsTokenProvider({ fetch: options.fetch, ...options.auth })\n : undefined;\n\n if (getAccessToken) {\n const authMiddleware: Middleware = {\n async onRequest({ request }) {\n const token = await getAccessToken();\n if (token) request.headers.set(\"Authorization\", `Bearer ${token}`);\n return request;\n },\n };\n this.#client.use(authMiddleware);\n }\n }\n\n get GET(): Client<paths>[\"GET\"] {\n return this.#client.GET;\n }\n\n get POST(): Client<paths>[\"POST\"] {\n return this.#client.POST;\n }\n\n get PUT(): Client<paths>[\"PUT\"] {\n return this.#client.PUT;\n }\n\n get PATCH(): Client<paths>[\"PATCH\"] {\n return this.#client.PATCH;\n }\n\n get DELETE(): Client<paths>[\"DELETE\"] {\n return this.#client.DELETE;\n }\n\n use(...middleware: Middleware[]): this {\n this.#client.use(...middleware);\n return this;\n }\n\n eject(...middleware: Middleware[]): this {\n this.#client.eject(...middleware);\n return this;\n }\n}\n","import { HttpClient, type HttpClientOptions } from \"./http-client\";\n\nexport type ContextEngineClientOptions = HttpClientOptions;\n\n/**\n * Client for the Clinia Context Engine API.\n *\n * For now this client only exposes a low-level `http` client for making requests to the API. Higher-level resource methods can be added as the API surface stabilizes.\n */\nexport class ContextEngineClient {\n /**\n * Low-level http client. Use when a resource method does not cover your use case.\n */\n readonly http: HttpClient;\n\n constructor(options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AAO,YAAgC;AACrC,SAAK,QAAQ,IAAI,GAAG,UAAU;AAC9B,WAAO;AAAA,EACT;AAAA,EAEA,SAAS,YAAgC;AACvC,SAAK,QAAQ,MAAM,GAAG,UAAU;AAChC,WAAO;AAAA,EACT;AACF;;;ACnFO,IAAM,sBAAN,MAA0B;AAAA;AAAA;AAAA;AAAA,EAItB;AAAA,EAET,YAAY,SAAqC;AAC/C,SAAK,OAAO,IAAI,WAAW,OAAO;AAAA,EACpC;AACF;","names":[]}
@@ -0,0 +1,5 @@
1
+ export { InfoResource } from "./info";
2
+ export { PatientsResource } from "./patients";
3
+ export { IngestResource } from "./ingest";
4
+ export { SessionsResource } from "./sessions";
5
+ export { VFSResource } from "./vfs";
@@ -0,0 +1,24 @@
1
+ import type { HttpClient } from "../http-client";
2
+ export declare class InfoResource {
3
+ #private;
4
+ constructor(http: HttpClient);
5
+ getServiceInfo(): Promise<import("openapi-fetch").FetchResponse<{
6
+ parameters: {
7
+ query?: never;
8
+ header?: never;
9
+ path?: never;
10
+ cookie?: never;
11
+ };
12
+ requestBody?: never;
13
+ responses: {
14
+ 200: {
15
+ headers: {
16
+ [name: string]: unknown;
17
+ };
18
+ content: {
19
+ "application/json": import("..").components["schemas"]["ServiceInfo"];
20
+ };
21
+ };
22
+ };
23
+ }, undefined, `${string}/${string}`>>;
24
+ }
@@ -0,0 +1,323 @@
1
+ import type { HttpClient } from "../http-client";
2
+ import type { operations } from "../generated/context-engine";
3
+ import type { IngestDocumentBody, IngestBatchBody } from "../generated/types";
4
+ export declare class IngestResource {
5
+ #private;
6
+ constructor(http: HttpClient);
7
+ listExecutions(patientId: string, params?: {
8
+ query?: {
9
+ limit?: number;
10
+ cursor?: number;
11
+ };
12
+ }): Promise<import("openapi-fetch").FetchResponse<{
13
+ parameters: {
14
+ query?: {
15
+ limit?: number;
16
+ cursor?: number | null;
17
+ };
18
+ header?: never;
19
+ path: {
20
+ patientId: string;
21
+ };
22
+ cookie?: never;
23
+ };
24
+ requestBody?: never;
25
+ responses: {
26
+ 200: {
27
+ headers: {
28
+ [name: string]: unknown;
29
+ };
30
+ content: {
31
+ "application/json": import("..").components["schemas"]["IngestExecutionList"];
32
+ };
33
+ };
34
+ };
35
+ }, {
36
+ params: {
37
+ query?: {
38
+ limit?: number;
39
+ cursor?: number;
40
+ } | undefined;
41
+ path: {
42
+ patientId: string;
43
+ };
44
+ };
45
+ }, `${string}/${string}`>>;
46
+ getIngestStatus(patientId: string): Promise<import("openapi-fetch").FetchResponse<{
47
+ parameters: {
48
+ query?: never;
49
+ header?: never;
50
+ path: {
51
+ patientId: string;
52
+ };
53
+ cookie?: never;
54
+ };
55
+ requestBody?: never;
56
+ responses: {
57
+ 200: {
58
+ headers: {
59
+ [name: string]: unknown;
60
+ };
61
+ content: {
62
+ "application/json": import("..").components["schemas"]["IngestStatusResponse"];
63
+ };
64
+ };
65
+ };
66
+ }, {
67
+ params: {
68
+ path: {
69
+ patientId: string;
70
+ };
71
+ };
72
+ }, `${string}/${string}`>>;
73
+ getExecution(patientId: string, executionId: string): Promise<import("openapi-fetch").FetchResponse<{
74
+ parameters: {
75
+ query?: never;
76
+ header?: never;
77
+ path: {
78
+ patientId: string;
79
+ executionId: string;
80
+ };
81
+ cookie?: never;
82
+ };
83
+ requestBody?: never;
84
+ responses: {
85
+ 200: {
86
+ headers: {
87
+ [name: string]: unknown;
88
+ };
89
+ content: {
90
+ "application/json": import("..").components["schemas"]["IngestExecutionDetail"];
91
+ };
92
+ };
93
+ 404: {
94
+ headers: {
95
+ [name: string]: unknown;
96
+ };
97
+ content: {
98
+ "application/json": import("..").components["schemas"]["ApiError"];
99
+ };
100
+ };
101
+ };
102
+ }, {
103
+ params: {
104
+ path: {
105
+ patientId: string;
106
+ executionId: string;
107
+ };
108
+ };
109
+ }, `${string}/${string}`>>;
110
+ ingestFhir(patientId: string, body: NonNullable<operations["ingest-fhir"]["requestBody"]>["content"]["application/json"], params?: {
111
+ query?: {
112
+ wait?: number;
113
+ };
114
+ }): Promise<import("openapi-fetch").FetchResponse<{
115
+ parameters: {
116
+ query?: {
117
+ wait?: number | null;
118
+ };
119
+ header?: never;
120
+ path: {
121
+ patientId: string;
122
+ };
123
+ cookie?: never;
124
+ };
125
+ requestBody: {
126
+ content: {
127
+ "application/json": {
128
+ [key: string]: unknown;
129
+ };
130
+ };
131
+ };
132
+ responses: {
133
+ 202: {
134
+ headers: {
135
+ [name: string]: unknown;
136
+ };
137
+ content: {
138
+ "application/json": import("..").components["schemas"]["IngestExecutionEnvelope"];
139
+ };
140
+ };
141
+ 422: {
142
+ headers: {
143
+ [name: string]: unknown;
144
+ };
145
+ content: {
146
+ "application/json": import("..").components["schemas"]["ApiError"];
147
+ };
148
+ };
149
+ };
150
+ }, {
151
+ params: {
152
+ query?: {
153
+ wait?: number;
154
+ } | undefined;
155
+ path: {
156
+ patientId: string;
157
+ };
158
+ };
159
+ body: {
160
+ [key: string]: unknown;
161
+ };
162
+ }, `${string}/${string}`>>;
163
+ ingestCda(patientId: string, body: NonNullable<operations["ingest-cda"]["requestBody"]>["content"]["text/plain"], params?: {
164
+ query?: {
165
+ wait?: number;
166
+ };
167
+ }): Promise<import("openapi-fetch").FetchResponse<{
168
+ parameters: {
169
+ query?: {
170
+ wait?: number | null;
171
+ };
172
+ header?: never;
173
+ path: {
174
+ patientId: string;
175
+ };
176
+ cookie?: never;
177
+ };
178
+ requestBody: {
179
+ content: {
180
+ "text/plain": string;
181
+ };
182
+ };
183
+ responses: {
184
+ 202: {
185
+ headers: {
186
+ [name: string]: unknown;
187
+ };
188
+ content: {
189
+ "application/json": import("..").components["schemas"]["IngestExecutionEnvelope"];
190
+ };
191
+ };
192
+ 400: {
193
+ headers: {
194
+ [name: string]: unknown;
195
+ };
196
+ content: {
197
+ "application/json": import("..").components["schemas"]["ApiError"];
198
+ };
199
+ };
200
+ 422: {
201
+ headers: {
202
+ [name: string]: unknown;
203
+ };
204
+ content: {
205
+ "application/json": import("..").components["schemas"]["ApiError"];
206
+ };
207
+ };
208
+ };
209
+ }, {
210
+ params: {
211
+ query?: {
212
+ wait?: number;
213
+ } | undefined;
214
+ path: {
215
+ patientId: string;
216
+ };
217
+ };
218
+ body: string;
219
+ bodySerializer: (b: BodyInit) => BodyInit;
220
+ headers: {
221
+ "Content-Type": string;
222
+ };
223
+ }, `${string}/${string}`>>;
224
+ ingestDocument(patientId: string, body: IngestDocumentBody, params?: {
225
+ query?: {
226
+ wait?: number;
227
+ };
228
+ }): Promise<import("openapi-fetch").FetchResponse<{
229
+ parameters: {
230
+ query?: {
231
+ wait?: number | null;
232
+ };
233
+ header?: never;
234
+ path: {
235
+ patientId: string;
236
+ };
237
+ cookie?: never;
238
+ };
239
+ requestBody: {
240
+ content: {
241
+ "application/json": import("..").components["schemas"]["IngestDocumentBody"];
242
+ };
243
+ };
244
+ responses: {
245
+ 202: {
246
+ headers: {
247
+ [name: string]: unknown;
248
+ };
249
+ content: {
250
+ "application/json": import("..").components["schemas"]["IngestExecutionEnvelope"];
251
+ };
252
+ };
253
+ };
254
+ }, {
255
+ params: {
256
+ query?: {
257
+ wait?: number;
258
+ } | undefined;
259
+ path: {
260
+ patientId: string;
261
+ };
262
+ };
263
+ body: {
264
+ name: string;
265
+ mimeType?: string;
266
+ };
267
+ }, `${string}/${string}`>>;
268
+ ingestBatch(patientId: string, body: IngestBatchBody, params?: {
269
+ query?: {
270
+ wait?: number;
271
+ };
272
+ }): Promise<import("openapi-fetch").FetchResponse<{
273
+ parameters: {
274
+ query?: {
275
+ wait?: number | null;
276
+ };
277
+ header?: never;
278
+ path: {
279
+ patientId: string;
280
+ };
281
+ cookie?: never;
282
+ };
283
+ requestBody: {
284
+ content: {
285
+ "application/json": import("..").components["schemas"]["IngestBatchBody"];
286
+ };
287
+ };
288
+ responses: {
289
+ 202: {
290
+ headers: {
291
+ [name: string]: unknown;
292
+ };
293
+ content: {
294
+ "application/json": import("..").components["schemas"]["IngestExecutionEnvelope"];
295
+ };
296
+ };
297
+ 400: {
298
+ headers: {
299
+ [name: string]: unknown;
300
+ };
301
+ content: {
302
+ "application/json": import("..").components["schemas"]["ApiError"];
303
+ };
304
+ };
305
+ };
306
+ }, {
307
+ params: {
308
+ query?: {
309
+ wait?: number;
310
+ } | undefined;
311
+ path: {
312
+ patientId: string;
313
+ };
314
+ };
315
+ body: {
316
+ fhir?: {
317
+ [key: string]: unknown;
318
+ }[];
319
+ cda?: string[];
320
+ documents?: import("..").components["schemas"]["IngestDocumentBody"][];
321
+ };
322
+ }, `${string}/${string}`>>;
323
+ }