@crvouga/mockingbird-service-medplum 0.1.1 → 0.1.2
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/README.md +13 -13
- package/dist/index.d.ts +93 -11
- package/dist/index.js +718 -116
- package/dist/index.js.map +7 -1
- package/package.json +5 -6
- package/dist/config.d.ts +0 -51
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -46
- package/dist/config.js.map +0 -1
- package/dist/ensure-medplum-build.d.ts +0 -13
- package/dist/ensure-medplum-build.d.ts.map +0 -1
- package/dist/ensure-medplum-build.js +0 -109
- package/dist/ensure-medplum-build.js.map +0 -1
- package/dist/generated/openapi.d.ts +0 -7
- package/dist/generated/openapi.d.ts.map +0 -1
- package/dist/generated/openapi.js +0 -5
- package/dist/generated/openapi.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/paths.d.ts +0 -14
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js +0 -27
- package/dist/paths.js.map +0 -1
- package/dist/ports.d.ts +0 -8
- package/dist/ports.d.ts.map +0 -1
- package/dist/ports.js +0 -26
- package/dist/ports.js.map +0 -1
- package/dist/process.d.ts +0 -50
- package/dist/process.d.ts.map +0 -1
- package/dist/process.js +0 -283
- package/dist/process.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Stateful Medplum "mock" that runs the **real [Medplum](https://www.medplum.com/) server** rather
|
|
4
4
|
than reimplementing its FHIR API. It self-hosts a pinned Medplum build as a child process on
|
|
5
|
-
embedded Postgres and
|
|
5
|
+
embedded Postgres and a throwaway `redis-server` process, and exposes it through a Fetch-style
|
|
6
6
|
contract (`fetch(Request) -> Response`) plus explicit `start` / `reset` / `stop` lifecycle calls.
|
|
7
7
|
|
|
8
8
|
Use it for integration tests that need genuine Medplum/FHIR behaviour (search, validation,
|
|
@@ -27,12 +27,12 @@ Requirements:
|
|
|
27
27
|
- `git` and `npm` on `PATH` for the one-time clone and build
|
|
28
28
|
(`git clone` -> `npm ci` -> `npm run build:fast`, following Medplum's
|
|
29
29
|
[install-from-scratch](https://www.medplum.com/docs/self-hosting/install-from-scratch) flow).
|
|
30
|
-
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
- **
|
|
35
|
-
|
|
30
|
+
- A `redis-server` binary on `PATH` (macOS: `brew install redis`, Debian/Ubuntu:
|
|
31
|
+
`apt-get install redis-server`). Set `MOCKINGBIRD_REDIS_SERVER` to point at it if it lives
|
|
32
|
+
elsewhere. It is spawned per run with persistence disabled; nothing is compiled or downloaded.
|
|
33
|
+
- The postinstall script of `embedded-postgres` must run:
|
|
34
|
+
- **Bun**: list it under `trustedDependencies` in your root `package.json`.
|
|
35
|
+
- **pnpm**: approve it once with `pnpm approve-builds`.
|
|
36
36
|
- Disk under `~/.cache/mockingbird/medplum-server/<version>` for the Medplum clone and build.
|
|
37
37
|
|
|
38
38
|
## Usage
|
|
@@ -42,7 +42,7 @@ Requirements:
|
|
|
42
42
|
| Call | Behaviour |
|
|
43
43
|
| --- | --- |
|
|
44
44
|
| `await createMedplumAPI(options?)` | Construct a `MedplumAPI` and `await start()` it. |
|
|
45
|
-
| `await medplum.start()` | Pick free ports; boot embedded Postgres (database `medplum`) and
|
|
45
|
+
| `await medplum.start()` | Pick free ports; boot embedded Postgres (database `medplum`) and a `redis-server` child process; ensure the Medplum build exists in the cache (clone/build on first run); write a per-run `medplum.config.json` into a temp dir; spawn `packages/server/dist/index.js` with the current runtime (`process.execPath`); poll `GET /healthcheck` (up to 5 minutes). Idempotent and safe to call concurrently. |
|
|
46
46
|
| `medplum.fetch(request)` | Proxy the request to the running server. Only the path and query of `request.url` are used, so any origin works. Redirects are returned, not followed. |
|
|
47
47
|
| `await medplum.reset()` | Stop the server, drop and recreate the `medplum` database, restart and wait for healthy. The server re-runs migrations and seeding on boot, so state is pristine. Clears the cached access token. Throws if not started. |
|
|
48
48
|
| `await medplum.stop()` | SIGTERM the server (SIGKILL after 10s), stop Redis and Postgres, delete the temp dir. No-op if not started. |
|
|
@@ -78,7 +78,7 @@ try {
|
|
|
78
78
|
})
|
|
79
79
|
const patient = (await created.json()) as { id: string }
|
|
80
80
|
|
|
81
|
-
// Through
|
|
81
|
+
// Through fetch(request) (any origin; path and query are forwarded):
|
|
82
82
|
const read = await medplum.fetch(
|
|
83
83
|
new Request(`https://medplum.test/fhir/R4/Patient/${patient.id}`, { headers }),
|
|
84
84
|
)
|
|
@@ -136,7 +136,7 @@ test("starts clean after reset", async () => {
|
|
|
136
136
|
|
|
137
137
|
| Export | Description |
|
|
138
138
|
| --- | --- |
|
|
139
|
-
| `MedplumAPI` | Class. `new MedplumAPI(options?)`; implements `
|
|
139
|
+
| `MedplumAPI` | Class. `new MedplumAPI(options?)`; implements the Fetch contract `fetch(request: Request): Promise<Response>`. Does not start anything until `start()`. |
|
|
140
140
|
| `createMedplumAPI` | `(options?) => Promise<MedplumAPI>` — construct and `start()`. |
|
|
141
141
|
| `SUPER_ADMIN_EMAIL` | `"admin@example.com"` — seeded super admin email. |
|
|
142
142
|
| `SUPER_ADMIN_PASSWORD` | `"medplum_admin"` — seeded super admin password. |
|
|
@@ -187,7 +187,7 @@ bun test
|
|
|
187
187
|
MOCKINGBIRD_MEDPLUM_E2E=1 bun test # first run pays the clone/build cost (several minutes, logged)
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
-
In this repo, the root `package.json` already lists `embedded-postgres`
|
|
191
|
-
|
|
190
|
+
In this repo, the root `package.json` already lists `embedded-postgres` under
|
|
191
|
+
`trustedDependencies`.
|
|
192
192
|
|
|
193
|
-
Part of [mockingbird](https://github.com/crvouga/mockingbird) — agent integration guide: [
|
|
193
|
+
Part of [mockingbird](https://github.com/crvouga/mockingbird) — agent integration guide: [README](https://github.com/crvouga/mockingbird#readme) · [llms.txt](https://github.com/crvouga/mockingbird/blob/main/llms.txt).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Anything that can answer a Fetch `Request` with a `Response`.
|
|
3
|
+
*
|
|
4
|
+
* Every Mockingbird service implements this, and every runtime adapter consumes it.
|
|
5
|
+
* It is the only contract shared across the whole graph.
|
|
6
|
+
*/
|
|
7
|
+
interface FetchAPI {
|
|
8
|
+
fetch(request: Request): Promise<Response>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type ServerConfigInput = {
|
|
12
|
+
apiPort: number;
|
|
13
|
+
dbPort: number;
|
|
14
|
+
redisPort: number;
|
|
15
|
+
dataDir: string;
|
|
16
|
+
superAdminEmail?: string | undefined;
|
|
17
|
+
superAdminPassword?: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
type MedplumDatabaseConfig = {
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
dbname: string;
|
|
23
|
+
username: string;
|
|
24
|
+
password: string;
|
|
25
|
+
};
|
|
26
|
+
type MedplumRedisConfig = {
|
|
27
|
+
host: string;
|
|
28
|
+
port: number;
|
|
29
|
+
};
|
|
30
|
+
type MedplumServerConfig = {
|
|
31
|
+
port: number;
|
|
32
|
+
baseUrl: string;
|
|
33
|
+
appBaseUrl: string;
|
|
34
|
+
binaryStorage: string;
|
|
35
|
+
storageBaseUrl: string;
|
|
36
|
+
supportEmail: string;
|
|
37
|
+
emailProvider: "none";
|
|
38
|
+
botLambdaRoleArn: "";
|
|
39
|
+
botLambdaLayerName: string;
|
|
40
|
+
vmContextBotsEnabled: true;
|
|
41
|
+
defaultBotRuntimeVersion: "vmcontext";
|
|
42
|
+
allowedOrigins: "*";
|
|
43
|
+
introspectionEnabled: true;
|
|
44
|
+
rateLimitsEnabled: false;
|
|
45
|
+
database: MedplumDatabaseConfig;
|
|
46
|
+
redis: MedplumRedisConfig;
|
|
47
|
+
shutdownTimeoutMilliseconds: number;
|
|
48
|
+
defaultSuperAdminEmail?: string | undefined;
|
|
49
|
+
defaultSuperAdminPassword?: string | undefined;
|
|
50
|
+
defaultSuperAdminClientId?: string | undefined;
|
|
51
|
+
defaultSuperAdminClientSecret?: string | undefined;
|
|
52
|
+
superAdminSecurity: {
|
|
53
|
+
blockAdmin: false;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
declare const SUPER_ADMIN_EMAIL = "admin@example.com";
|
|
57
|
+
declare const SUPER_ADMIN_PASSWORD = "medplum_admin";
|
|
58
|
+
declare const buildServerConfig: (input: ServerConfigInput) => MedplumServerConfig;
|
|
59
|
+
|
|
60
|
+
type MedplumPathsOptions = {
|
|
61
|
+
version?: string | undefined;
|
|
62
|
+
cacheDir?: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
type MedplumPaths = {
|
|
65
|
+
version: string;
|
|
66
|
+
cacheRoot: string;
|
|
67
|
+
cloneDir: string;
|
|
68
|
+
serverEntry: string;
|
|
69
|
+
buildMarker: string;
|
|
70
|
+
};
|
|
71
|
+
declare const resolveMedplumPaths: (options?: MedplumPathsOptions) => MedplumPaths;
|
|
72
|
+
|
|
73
|
+
type MedplumProcessOptions = {
|
|
74
|
+
version?: string | undefined;
|
|
75
|
+
cacheDir?: string | undefined;
|
|
76
|
+
onLog?: ((message: string) => void) | undefined;
|
|
77
|
+
};
|
|
78
|
+
type MedplumProcessInfo = {
|
|
79
|
+
apiPort: number;
|
|
80
|
+
dbPort: number;
|
|
81
|
+
redisPort: number;
|
|
82
|
+
baseUrl: string;
|
|
83
|
+
dataDir: string;
|
|
84
|
+
paths: MedplumPaths;
|
|
85
|
+
config: MedplumServerConfig;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
type MedplumAPIOptions = MedplumProcessOptions & {
|
|
9
89
|
/** Username for the seeded super admin. Defaults match Medplum's dev seed. */
|
|
10
90
|
email?: string | undefined;
|
|
11
91
|
/** Password for the seeded super admin. */
|
|
@@ -17,7 +97,7 @@ export type MedplumAPIOptions = MedplumProcessOptions & {
|
|
|
17
97
|
* FetchAPI contract by proxying every request to the running server, with
|
|
18
98
|
* explicit async lifecycle calls following the adapter convention.
|
|
19
99
|
*/
|
|
20
|
-
|
|
100
|
+
declare class MedplumAPI implements FetchAPI {
|
|
21
101
|
private readonly process;
|
|
22
102
|
private readonly options;
|
|
23
103
|
private cachedToken;
|
|
@@ -42,5 +122,7 @@ export declare class MedplumAPI implements FetchAPI {
|
|
|
42
122
|
private rewriteUrl;
|
|
43
123
|
}
|
|
44
124
|
/** Async factory that boots the server before returning, pairing with the parity runner's async `mock.create`. */
|
|
45
|
-
|
|
46
|
-
|
|
125
|
+
declare const createMedplumAPI: (options?: MedplumAPIOptions) => Promise<MedplumAPI>;
|
|
126
|
+
|
|
127
|
+
export { MedplumAPI, SUPER_ADMIN_EMAIL, SUPER_ADMIN_PASSWORD, buildServerConfig, createMedplumAPI, resolveMedplumPaths };
|
|
128
|
+
export type { FetchAPI, MedplumAPIOptions, MedplumPaths, MedplumProcessInfo, MedplumProcessOptions, MedplumServerConfig };
|