@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.
- package/CHANGELOG.md +57 -0
- package/LICENSE +201 -0
- package/README.md +154 -0
- package/dist/auth.d.ts +90 -0
- package/dist/context-engine-client.d.ts +14 -0
- package/dist/generated/context-engine.d.ts +1706 -0
- package/dist/generated/types.d.ts +26 -0
- package/dist/http-client.d.ts +40 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +164 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/index.d.ts +5 -0
- package/dist/resources/info.d.ts +24 -0
- package/dist/resources/ingest.d.ts +323 -0
- package/dist/resources/patients.d.ts +211 -0
- package/dist/resources/sessions.d.ts +316 -0
- package/dist/resources/vfs.d.ts +99 -0
- package/package.json +53 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @clinia/context-engine-js
|
|
2
|
+
|
|
3
|
+
## 0.5.0-rc.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- db7bdab: **`@clinia/context-engine-js` is now published to the public npm registry.** Install it with `npm install @clinia/context-engine-js` — no registry configuration, no `.npmrc`, no authentication. Previously it existed only on GitHub Packages, so a clone outside the Clinia org could not install it at all.
|
|
8
|
+
|
|
9
|
+
Publishing continues to GitHub Packages as well, at the same version, so anything already resolving from there keeps working. The npm publish is the source of truth; the mirror is best-effort.
|
|
10
|
+
|
|
11
|
+
The package now declares `license: "Apache-2.0"` and ships a `LICENSE` file and its `CHANGELOG.md`. It carries no `repository` field on purpose: the source monorepo is private, so the link npm would render 404s for every consumer.
|
|
12
|
+
|
|
13
|
+
Two packaging defects are fixed while the consumer base is still small. `exports` listed the `import` condition before `types`, and there was no top-level `types` — so consumers on `moduleResolution: "node"` resolved the package with no type declarations at all. Both are corrected; the package remains ESM-only, which the README now states outright, since `require()` of it throws `ERR_REQUIRE_ESM`.
|
|
14
|
+
|
|
15
|
+
**`{ clientId, clientSecret }` is now a complete `auth` config.** The token endpoint and the RFC 8707 `resource` indicator default to Clinia's authorization server, so connecting to a workspace no longer means copying two console URLs into your code. `tokenUrl` and `issuer` still override it for a different authorization server, and `resource` is only defaulted when the endpoint is too — a third-party token endpoint never receives Clinia's resource value. Nothing breaks: every config that was valid before still means what it meant, and `tokenUrl` merely became optional.
|
|
16
|
+
|
|
17
|
+
- 405af06: **Renamed: `@clinia/patient-memory-js` is now `@clinia/context-engine-js`.**
|
|
18
|
+
|
|
19
|
+
To upgrade, change the dependency name and your imports, and rename two symbols:
|
|
20
|
+
- `PatientMemoryClient` → `ContextEngineClient`
|
|
21
|
+
- `PatientMemoryClientOptions` → `ContextEngineClientOptions`
|
|
22
|
+
|
|
23
|
+
Nothing else about the surface changed: same constructor options, same `http` client, same generated types and resource classes. Versions 0.4.0 and earlier remain published under the old name and are not being withdrawn, but no further versions will be released there.
|
|
24
|
+
|
|
25
|
+
The types are now generated from `openapi/context-engine.yaml`, which is the spec attached to each release under that name.
|
|
26
|
+
|
|
27
|
+
The retired name is also gone from everything the package ships, which the rename had missed: the `auth` module's doc comment (carried into `dist/auth.d.ts` and into the sourcemap's inlined source), and the README's `audience` example, `baseUrl` sample host, and options table. `CHANGELOG.md` still names `@clinia/patient-memory-js` on purpose — an upgrading consumer needs to know what the package used to be called.
|
|
28
|
+
|
|
29
|
+
> Renamed from `@clinia/patient-memory-js`. Versions 0.4.0 and earlier were
|
|
30
|
+
> published under the old name; entries below them predate the rename and still
|
|
31
|
+
> refer to it.
|
|
32
|
+
|
|
33
|
+
## 0.4.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- 750b6ff: Every API operation now declares an OpenAPI `operationId` (kebab-case, enforced by lint), emitted as `http.operation_id` on HTTP server spans, as a label on the `http.server.request.duration` histogram, and as `httpOperationId` on request logs. The mapping is derived at runtime from the app's OpenAPI route definitions — no hand-maintained registry. The published spec includes the ids, which activates the client's resource generation: `@clinia/patient-memory-js` now ships generated resource classes (`PatientsResource`, `IngestResource`, `SessionsResource`, `VFSResource`; not yet wired into `PatientMemoryClient`) with camelCase method names derived from the full operationId, and the generator was fixed for case-sensitive filesystems and enum query params. Inline-schema and non-JSON request bodies are supported too: `ingestFhir` types its body off the generated `operations` interface, and `ingestCda` sends `text/plain` with a passthrough serializer.
|
|
38
|
+
- 29b6fb3: Add OAuth2 client-credentials authentication to the JS client (PAM-468). Pass
|
|
39
|
+
`auth` a `ClientCredentialsConfig` and the client acquires, caches, and refreshes
|
|
40
|
+
a bearer token for you; or pass `auth` a `() => string | Promise<string>` token
|
|
41
|
+
function for full control (a token from elsewhere, a different grant, or a custom
|
|
42
|
+
refresh strategy). The `createClientCredentialsTokenProvider` helper is exported
|
|
43
|
+
for sharing one cached provider across clients or transports.
|
|
44
|
+
|
|
45
|
+
## 0.4.0-rc.1
|
|
46
|
+
|
|
47
|
+
## 0.4.0-rc.0
|
|
48
|
+
|
|
49
|
+
### Minor Changes
|
|
50
|
+
|
|
51
|
+
- 750b6ff: Every API operation now declares an OpenAPI `operationId` (kebab-case, enforced by lint), emitted as `http.operation_id` on HTTP server spans, as a label on the `http.server.request.duration` histogram, and as `httpOperationId` on request logs. The mapping is derived at runtime from the app's OpenAPI route definitions — no hand-maintained registry. The published spec includes the ids, which activates the client's resource generation: `@clinia/patient-memory-js` now ships generated resource classes (`PatientsResource`, `IngestResource`, `SessionsResource`, `VFSResource`; not yet wired into `PatientMemoryClient`) with camelCase method names derived from the full operationId, and the generator was fixed for case-sensitive filesystems and enum query params. Inline-schema and non-JSON request bodies are supported too: `ingestFhir` types its body off the generated `operations` interface, and `ingestCda` sends `text/plain` with a passthrough serializer.
|
|
52
|
+
- 29b6fb3: Add OAuth2 client-credentials authentication to the JS client (PAM-468). Pass
|
|
53
|
+
`auth` a `ClientCredentialsConfig` and the client acquires, caches, and refreshes
|
|
54
|
+
a bearer token for you; or pass `auth` a `() => string | Promise<string>` token
|
|
55
|
+
function for full control (a token from elsewhere, a different grant, or a custom
|
|
56
|
+
refresh strategy). The `createClientCredentialsTokenProvider` helper is exported
|
|
57
|
+
for sharing one cached provider across clients or transports.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Clinia Health Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @clinia/context-engine-js
|
|
2
|
+
|
|
3
|
+
TypeScript client for the Clinia Context Engine API. A thin, typed wrapper over
|
|
4
|
+
[`openapi-fetch`](https://openapi-ts.dev/openapi-fetch/) — request/response
|
|
5
|
+
shapes are generated from the OpenAPI contract, so paths, params, and bodies are
|
|
6
|
+
fully type-checked. Works in Node 20+ and modern browsers on the standard
|
|
7
|
+
`fetch`.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @clinia/context-engine-js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Published on [npm](https://www.npmjs.com/package/@clinia/context-engine-js). No
|
|
16
|
+
registry configuration or authentication is needed.
|
|
17
|
+
|
|
18
|
+
While the engine is in release-candidate phase, the newest build is under the
|
|
19
|
+
`rc` dist-tag:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm install @clinia/context-engine-js@rc
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**This package is ESM-only** (`"type": "module"`). `require()` of it throws
|
|
26
|
+
`ERR_REQUIRE_ESM`; use `import`, or a dynamic `await import()` from CommonJS.
|
|
27
|
+
|
|
28
|
+
## Exports
|
|
29
|
+
|
|
30
|
+
| Export | Description |
|
|
31
|
+
| ------------------------------------------ | --------------------------------------------------------------------------- |
|
|
32
|
+
| `ContextEngineClient` | Entry point. Holds a low-level `http` client. |
|
|
33
|
+
| `HttpClient` | Typed `openapi-fetch` wrapper (`GET`/`POST`/`PUT`/`PATCH`/`DELETE`, `use`). |
|
|
34
|
+
| `ContextEngineClientOptions` | Constructor options (alias of `HttpClientOptions`). |
|
|
35
|
+
| `createClientCredentialsTokenProvider` | Builds a caching OAuth2 client-credentials token provider. |
|
|
36
|
+
| `TokenProvider`, `ClientCredentialsConfig` | Auth types. |
|
|
37
|
+
| `paths`, generated request/response types | Emitted from the OpenAPI spec. |
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
Every Clinia workspace requires authentication. Create OAuth credentials in the
|
|
42
|
+
[Console](https://console.clinia.cloud) — scoped to your workspace, with **Read &
|
|
43
|
+
Write** if you intend to ingest data or create patients — then point `baseUrl` at
|
|
44
|
+
your workspace:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { ContextEngineClient } from "@clinia/context-engine-js";
|
|
48
|
+
|
|
49
|
+
const client = new ContextEngineClient({
|
|
50
|
+
baseUrl: "https://<workspace-id>.w.clinia.cloud",
|
|
51
|
+
auth: {
|
|
52
|
+
clientId: "your-client-id",
|
|
53
|
+
clientSecret: "your-client-secret",
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const { data, error } = await client.http.GET("/v1/patients");
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
That is the whole configuration. The client resolves Clinia's authorization
|
|
61
|
+
server, acquires a bearer token, caches it, refreshes it before expiry, and
|
|
62
|
+
attaches `Authorization: Bearer <token>` to every request. Tokens last an hour;
|
|
63
|
+
you do not manage them.
|
|
64
|
+
|
|
65
|
+
The `http` client exposes the typed verbs directly, and the path, path params,
|
|
66
|
+
query, and body are all checked against the OpenAPI contract:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
await client.http.GET("/v1/patients/{patientId}/read", {
|
|
70
|
+
params: { path: { patientId: "abc" } },
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Responses are `{ data, error }` — nothing throws on a non-2xx.
|
|
75
|
+
|
|
76
|
+
### Without authentication
|
|
77
|
+
|
|
78
|
+
Omit `auth` entirely and the client sends no `Authorization` header. Useful
|
|
79
|
+
against a server that does not require one — a stub or recorded fixture in your
|
|
80
|
+
own tests:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const client = new ContextEngineClient({ baseUrl: "http://localhost:8000" });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
An `http://` base URL is fine here. Note this is about the _client_ sending no
|
|
87
|
+
credentials: a Clinia workspace always requires them, so pointing an
|
|
88
|
+
unauthenticated client at one yields 401s on every request rather than a clear
|
|
89
|
+
startup failure.
|
|
90
|
+
|
|
91
|
+
### Bring your own token
|
|
92
|
+
|
|
93
|
+
For a token you obtained elsewhere, a different grant, or a custom refresh
|
|
94
|
+
strategy, pass `auth` a function instead of a config object. It is called per
|
|
95
|
+
request and returns the token to attach:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const client = new ContextEngineClient({
|
|
99
|
+
baseUrl: "https://<workspace-id>.w.clinia.cloud",
|
|
100
|
+
auth: async () => myTokenStore.getValidAccessToken(),
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`createClientCredentialsTokenProvider` returns exactly such a function, so you can
|
|
105
|
+
share one cached provider across several clients (or transports):
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import {
|
|
109
|
+
ContextEngineClient,
|
|
110
|
+
createClientCredentialsTokenProvider,
|
|
111
|
+
} from "@clinia/context-engine-js";
|
|
112
|
+
|
|
113
|
+
const getAccessToken = createClientCredentialsTokenProvider({
|
|
114
|
+
clientId: "your-client-id",
|
|
115
|
+
clientSecret: "your-client-secret",
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const client = new ContextEngineClient({ baseUrl, auth: getAccessToken });
|
|
119
|
+
// The same provider can also feed a non-REST channel, e.g. an MCP transport.
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Middleware
|
|
123
|
+
|
|
124
|
+
`http.use(...)` / `http.eject(...)` accept
|
|
125
|
+
[`openapi-fetch` middleware](https://openapi-ts.dev/openapi-fetch/middleware-auth)
|
|
126
|
+
for cross-cutting concerns (logging, tracing, custom headers). The `auth` option
|
|
127
|
+
is implemented as such a middleware internally.
|
|
128
|
+
|
|
129
|
+
## Options
|
|
130
|
+
|
|
131
|
+
| Option | Type | Description |
|
|
132
|
+
| --------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
133
|
+
| `baseUrl` | `string` | Context Engine workspace base URL. Required. |
|
|
134
|
+
| `fetch` | `typeof fetch` | Custom fetch (also used for the token exchange). Defaults to global. |
|
|
135
|
+
| `auth` | `ClientCredentialsConfig \| (() => string \| Promise<string>)` | OAuth2 client-credentials config (common case) **or** a per-request token function (escape hatch). |
|
|
136
|
+
|
|
137
|
+
## Development
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
pnpm generate # regenerate types from ../../openapi/context-engine.yaml
|
|
141
|
+
pnpm build # bundle (tsup) + emit declarations (tsc)
|
|
142
|
+
pnpm typecheck
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Tests run from the repo root (Vitest discovers this package's `vitest.config.ts`):
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
pnpm test # whole workspace
|
|
149
|
+
pnpm vitest run --project context-engine-js # this package only
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
[Apache-2.0](LICENSE) © Clinia Health Inc.
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth2 client-credentials helpers for authenticating against a secured
|
|
3
|
+
* Context Engine workspace.
|
|
4
|
+
*
|
|
5
|
+
* The server validates a bearer JWT in the `Authorization` header against a
|
|
6
|
+
* JWKS. This module provides the client half: a token provider that exchanges
|
|
7
|
+
* a `client_id`/`client_secret` for an access token, caches it, and refreshes
|
|
8
|
+
* it before expiry. The token exchange itself is delegated to `oauth4webapi`
|
|
9
|
+
* (standards-compliant request building + response validation); this module
|
|
10
|
+
* only adds caching, concurrent-request de-duplication, and a small config
|
|
11
|
+
* surface. Pass the raw config as {@link HttpClientOptions.auth}, or — for full
|
|
12
|
+
* control — pass the returned provider as the {@link HttpClientOptions.auth}
|
|
13
|
+
* token function.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Resolves to a currently-valid bearer access token. Called per request; a
|
|
17
|
+
* well-behaved provider caches internally and only hits the network when the
|
|
18
|
+
* cached token is missing or about to expire.
|
|
19
|
+
*/
|
|
20
|
+
export type TokenProvider = () => Promise<string>;
|
|
21
|
+
/** Fields common to both ways of locating the authorization server. */
|
|
22
|
+
type ClientCredentialsBase = {
|
|
23
|
+
clientId: string;
|
|
24
|
+
clientSecret: string;
|
|
25
|
+
/**
|
|
26
|
+
* Optional `resource` indicator (RFC 8707) naming the protected resource the
|
|
27
|
+
* token is for. This is what the Clinia authorization server expects (e.g.
|
|
28
|
+
* `https://console.clinia.cloud`).
|
|
29
|
+
*/
|
|
30
|
+
resource?: string;
|
|
31
|
+
/** Optional `audience` parameter (used by some IdPs, e.g. Auth0). */
|
|
32
|
+
audience?: string;
|
|
33
|
+
/** Optional space-delimited `scope`. */
|
|
34
|
+
scope?: string;
|
|
35
|
+
/**
|
|
36
|
+
* How the client credentials are presented to the token endpoint. `post`
|
|
37
|
+
* (the default) sends them in the request body — what the Clinia
|
|
38
|
+
* authorization server expects; `basic` sends them in the `Authorization`
|
|
39
|
+
* header (RFC 6749 §2.3.1) for IdPs that require it.
|
|
40
|
+
*/
|
|
41
|
+
authMethod?: "basic" | "post";
|
|
42
|
+
/**
|
|
43
|
+
* Custom fetch implementation. Defaults to `globalThis.fetch`. Useful for
|
|
44
|
+
* injecting a mock in tests.
|
|
45
|
+
*/
|
|
46
|
+
fetch?: typeof globalThis.fetch;
|
|
47
|
+
/**
|
|
48
|
+
* Refresh the token this many milliseconds before it actually expires, to
|
|
49
|
+
* avoid handing out a token that expires mid-flight. Defaults to 60_000.
|
|
50
|
+
*/
|
|
51
|
+
expiryMarginMs?: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Client-credentials configuration.
|
|
55
|
+
*
|
|
56
|
+
* For a Clinia workspace, `{ clientId, clientSecret }` is enough — the token
|
|
57
|
+
* endpoint and `resource` indicator default to Clinia's authorization server.
|
|
58
|
+
* Naming an {@link issuer} instead locates a different authorization server by
|
|
59
|
+
* OIDC/OAuth2 discovery; naming a {@link tokenUrl} points at one explicitly.
|
|
60
|
+
*/
|
|
61
|
+
export type ClientCredentialsConfig = (ClientCredentialsBase & {
|
|
62
|
+
/**
|
|
63
|
+
* Issuer identifier of the authorization server. Its metadata (token
|
|
64
|
+
* endpoint, etc.) is resolved via discovery on first use.
|
|
65
|
+
*/
|
|
66
|
+
issuer: string;
|
|
67
|
+
/** Discovery transformation: `oidc` (default) or `oauth2` (RFC 8414). */
|
|
68
|
+
discoveryAlgorithm?: "oidc" | "oauth2";
|
|
69
|
+
tokenUrl?: never;
|
|
70
|
+
}) | (ClientCredentialsBase & {
|
|
71
|
+
/**
|
|
72
|
+
* Explicit OAuth2 token endpoint; discovery is skipped. Omit it — along
|
|
73
|
+
* with `issuer` — to use Clinia's.
|
|
74
|
+
*/
|
|
75
|
+
tokenUrl?: string;
|
|
76
|
+
/** Issuer identifier for response validation; defaults to the token URL's origin. */
|
|
77
|
+
issuer?: string;
|
|
78
|
+
discoveryAlgorithm?: never;
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Builds a {@link TokenProvider} backed by the OAuth2 client-credentials grant.
|
|
82
|
+
*
|
|
83
|
+
* The provider caches the access token and reuses it until it is within
|
|
84
|
+
* `expiryMarginMs` of expiry. Concurrent calls while a fetch is in flight share
|
|
85
|
+
* the same request rather than each hitting the token endpoint. When configured
|
|
86
|
+
* with an {@link ClientCredentialsConfig.issuer}, the authorization server
|
|
87
|
+
* metadata is discovered once and memoized.
|
|
88
|
+
*/
|
|
89
|
+
export declare function createClientCredentialsTokenProvider(config: ClientCredentialsConfig): TokenProvider;
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpClient, type HttpClientOptions } from "./http-client";
|
|
2
|
+
export type ContextEngineClientOptions = HttpClientOptions;
|
|
3
|
+
/**
|
|
4
|
+
* Client for the Clinia Context Engine API.
|
|
5
|
+
*
|
|
6
|
+
* 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.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ContextEngineClient {
|
|
9
|
+
/**
|
|
10
|
+
* Low-level http client. Use when a resource method does not cover your use case.
|
|
11
|
+
*/
|
|
12
|
+
readonly http: HttpClient;
|
|
13
|
+
constructor(options: ContextEngineClientOptions);
|
|
14
|
+
}
|