@medplum/core 5.0.10 → 5.0.12

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.
@@ -370,6 +370,22 @@ export declare interface BotEvent<T = unknown> {
370
370
  readonly requester?: Reference<Bot | ClientApplication | Patient | Practitioner | RelatedPerson>;
371
371
  /** Headers from the original request, when invoked by HTTP request */
372
372
  readonly headers?: Record<string, string | string[] | undefined>;
373
+ /** Optional response stream when invoked with SSE (Server Side Events) */
374
+ readonly responseStream?: BotResponseStream;
375
+ }
376
+
377
+ /**
378
+ * Response stream interface for bot streaming responses.
379
+ * Compatible with both VMContext and AWS Lambda runtimes.
380
+ */
381
+ export declare interface BotResponseStream extends NodeJS.WritableStream {
382
+ /**
383
+ * Starts streaming with the given status code and headers.
384
+ * Must be called before write() to commit the HTTP response.
385
+ * @param statusCode - HTTP status code (e.g., 200)
386
+ * @param headers - HTTP headers to send
387
+ */
388
+ startStreaming(statusCode: number, headers: Record<string, string>): void;
373
389
  }
374
390
 
375
391
  /**
@@ -1102,6 +1118,9 @@ export declare interface EmailPasswordLoginRequest extends BaseLoginRequest {
1102
1118
  readonly remember?: boolean;
1103
1119
  }
1104
1120
 
1121
+ /** Constant empty array. */
1122
+ export declare const EMPTY: readonly [];
1123
+
1105
1124
  export declare class EmptySetAtom implements Atom {
1106
1125
  eval(): [];
1107
1126
  toString(): string;
@@ -1911,6 +1930,16 @@ export declare function formatTime(time: string | undefined, locales?: Intl.Loca
1911
1930
  */
1912
1931
  export declare function formatTiming(timing: Timing | undefined): string;
1913
1932
 
1933
+ /**
1934
+ * Formats a FHIR time string as a human readable string.
1935
+ * The viewer's timezone does not affect the display.
1936
+ * @param time - The time to format, a string like `HH:mm` or `HH:mm:ss`
1937
+ * @param locales - Optional locales.
1938
+ * @param options - Optional time format options.
1939
+ * @returns The formatted time string.
1940
+ */
1941
+ export declare function formatWallTime(time: string | undefined, locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
1942
+
1914
1943
  export declare class FunctionAtom implements Atom {
1915
1944
  readonly name: string;
1916
1945
  readonly args: Atom[];
@@ -3383,7 +3412,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
3383
3412
  private readonly fetch;
3384
3413
  private readonly createPdfImpl?;
3385
3414
  private readonly storage;
3386
- private readonly requestCache;
3415
+ protected readonly requestCache: LRUCache<RequestCacheEntry> | undefined;
3387
3416
  private readonly cacheTime;
3388
3417
  private readonly baseUrl;
3389
3418
  private readonly fhirBaseUrl;
@@ -3842,7 +3871,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
3842
3871
  * @param reference - The FHIR reference.
3843
3872
  * @returns The resource if it is available in the cache; undefined otherwise.
3844
3873
  */
3845
- getCachedReference<T extends Resource>(reference: Reference<T>): T | undefined;
3874
+ getCachedReference<T extends Resource>(reference: Reference<T>): WithId<T> | undefined;
3846
3875
  /**
3847
3876
  * Reads a resource by resource type and ID.
3848
3877
  *
@@ -3889,9 +3918,10 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
3889
3918
  * If the schema is already cached, the promise is resolved immediately.
3890
3919
  * @category Schema
3891
3920
  * @param resourceType - The FHIR resource type.
3921
+ * @param options - Optional fetch options.
3892
3922
  * @returns Promise to a schema with the requested resource type.
3893
3923
  */
3894
- requestSchema(resourceType: string): Promise<void>;
3924
+ requestSchema(resourceType: string, options?: MedplumRequestOptions): Promise<void>;
3895
3925
  /**
3896
3926
  * Requests the schema for a profile.
3897
3927
  * If the schema is already cached, the promise is resolved immediately.
@@ -4618,6 +4648,12 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4618
4648
  * @returns Promise to the bundle.
4619
4649
  */
4620
4650
  private getBundle;
4651
+ /**
4652
+ * Returns true if caching is enabled for the given request options.
4653
+ * @param options - Optional fetch options for cache settings.
4654
+ * @returns True if caching is enabled.
4655
+ */
4656
+ private isCacheEnabled;
4621
4657
  /**
4622
4658
  * Returns the cache entry if available and not expired.
4623
4659
  * @param key - The cache key to retrieve.
@@ -4629,6 +4665,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4629
4665
  * Adds a readable promise to the cache.
4630
4666
  * @param key - The cache key to store.
4631
4667
  * @param value - The readable promise to store.
4668
+ * @param options - Optional fetch options for cache settings.
4632
4669
  */
4633
4670
  private setCacheEntry;
4634
4671
  /**
@@ -4636,6 +4673,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4636
4673
  * This is used in cases where the resource is loaded indirectly.
4637
4674
  * For example, when a resource is loaded as part of a Bundle.
4638
4675
  * @param resource - The resource to cache.
4676
+ * @param options - Optional fetch options for cache settings.
4639
4677
  */
4640
4678
  private cacheResource;
4641
4679
  /**
@@ -4679,6 +4717,13 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4679
4717
  * @param contentType - The new content type to set.
4680
4718
  */
4681
4719
  private setRequestContentType;
4720
+ /**
4721
+ * Returns a header from fetch options.
4722
+ * @param options - The fetch options.
4723
+ * @param key - The header key.
4724
+ * @returns The header value if found.
4725
+ */
4726
+ private getRequestHeader;
4682
4727
  /**
4683
4728
  * Sets a header on fetch options.
4684
4729
  * @param options - The fetch options.
@@ -4908,6 +4953,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4908
4953
  * @returns Promise that returns a project membership or an operation outcome.
4909
4954
  */
4910
4955
  invite(projectId: string, body: InviteRequest): Promise<ProjectMembership | OperationOutcome>;
4956
+ private handleTokenError;
4911
4957
  /**
4912
4958
  * Makes a POST request to the tokens endpoint.
4913
4959
  * See {@link https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint | OpenID Connect Core 1.0 TokenEndpoint} for full details.
@@ -5231,7 +5277,7 @@ export declare interface MedplumClientOptions {
5231
5277
  * - 'basic': Log method, URL, and status code only (no sensitive headers)
5232
5278
  * - 'verbose': Log all details including headers (may include sensitive data like tokens)
5233
5279
  *
5234
- * @default 'none'
5280
+ * @defaultValue 'none'
5235
5281
  */
5236
5282
  logLevel?: ClientLogLevel;
5237
5283
  /**
@@ -5719,14 +5765,14 @@ export declare class OperationOutcomeError extends Error {
5719
5765
  }
5720
5766
 
5721
5767
  /**
5722
- * Returns a string represenation of the operation outcome issue.
5768
+ * Returns a string representation of the operation outcome issue.
5723
5769
  * @param issue - The operation outcome issue.
5724
5770
  * @returns The string representation of the operation outcome issue.
5725
5771
  */
5726
5772
  export declare function operationOutcomeIssueToString(issue: OperationOutcomeIssue): string;
5727
5773
 
5728
5774
  /**
5729
- * Returns a string represenation of the operation outcome.
5775
+ * Returns a string representation of the operation outcome.
5730
5776
  * @param outcome - The operation outcome.
5731
5777
  * @returns The string representation of the operation outcome.
5732
5778
  */
@@ -6391,7 +6437,12 @@ export declare class ParserBuilder {
6391
6437
  */
6392
6438
  export declare function replaceQueryVariables(user: CdsUserResource, context: Record<string, unknown>, query: string): string;
6393
6439
 
6394
- export declare interface RequestProfileSchemaOptions {
6440
+ export declare interface RequestCacheEntry {
6441
+ readonly requestTime: number;
6442
+ readonly value: ReadablePromise<any>;
6443
+ }
6444
+
6445
+ export declare interface RequestProfileSchemaOptions extends MedplumRequestOptions {
6395
6446
  /** (optional) Whether to include nested profiles, e.g. from extensions. Defaults to false. */
6396
6447
  expandProfile?: boolean;
6397
6448
  }
@@ -6551,10 +6602,21 @@ export declare class ParserBuilder {
6551
6602
 
6552
6603
  /**
6553
6604
  * Sleeps for the specified number of milliseconds.
6554
- * @param ms - Time delay in milliseconds
6605
+ * @param ms - Time delay in milliseconds.
6606
+ * @param options - Optional sleep options.
6555
6607
  * @returns A promise that resolves after the specified number of milliseconds.
6556
6608
  */
6557
- export declare const sleep: (ms: number) => Promise<void>;
6609
+ export declare const sleep: (ms: number, options?: SleepOptions) => Promise<void>;
6610
+
6611
+ /**
6612
+ * Sleep options.
6613
+ */
6614
+ export declare interface SleepOptions {
6615
+ /**
6616
+ * Optional `AbortSignal` that can be used to cancel the scheduled sleep.
6617
+ */
6618
+ readonly signal?: AbortSignal | null;
6619
+ }
6558
6620
 
6559
6621
  export declare interface SliceDefinition extends Omit<InternalSchemaElement, 'slicing'> {
6560
6622
  name: string;
@@ -7058,6 +7120,7 @@ export declare class ParserBuilder {
7058
7120
  collect?: {
7059
7121
  tokens?: Record<string, TypedValueWithPath[]>;
7060
7122
  };
7123
+ base64BinaryMaxBytes?: number;
7061
7124
  }
7062
7125
 
7063
7126
  export declare type ValueOrExternalSecret<T extends ExternalSecretPrimitive> = T | ExternalSecret<T>;
@@ -7072,6 +7135,7 @@ export declare class ParserBuilder {
7072
7135
  date?: string;
7073
7136
  offset?: number;
7074
7137
  count?: number;
7138
+ displayLanguage?: string;
7075
7139
  }
7076
7140
 
7077
7141
  /**
@@ -370,6 +370,22 @@ export declare interface BotEvent<T = unknown> {
370
370
  readonly requester?: Reference<Bot | ClientApplication | Patient | Practitioner | RelatedPerson>;
371
371
  /** Headers from the original request, when invoked by HTTP request */
372
372
  readonly headers?: Record<string, string | string[] | undefined>;
373
+ /** Optional response stream when invoked with SSE (Server Side Events) */
374
+ readonly responseStream?: BotResponseStream;
375
+ }
376
+
377
+ /**
378
+ * Response stream interface for bot streaming responses.
379
+ * Compatible with both VMContext and AWS Lambda runtimes.
380
+ */
381
+ export declare interface BotResponseStream extends NodeJS.WritableStream {
382
+ /**
383
+ * Starts streaming with the given status code and headers.
384
+ * Must be called before write() to commit the HTTP response.
385
+ * @param statusCode - HTTP status code (e.g., 200)
386
+ * @param headers - HTTP headers to send
387
+ */
388
+ startStreaming(statusCode: number, headers: Record<string, string>): void;
373
389
  }
374
390
 
375
391
  /**
@@ -1102,6 +1118,9 @@ export declare interface EmailPasswordLoginRequest extends BaseLoginRequest {
1102
1118
  readonly remember?: boolean;
1103
1119
  }
1104
1120
 
1121
+ /** Constant empty array. */
1122
+ export declare const EMPTY: readonly [];
1123
+
1105
1124
  export declare class EmptySetAtom implements Atom {
1106
1125
  eval(): [];
1107
1126
  toString(): string;
@@ -1911,6 +1930,16 @@ export declare function formatTime(time: string | undefined, locales?: Intl.Loca
1911
1930
  */
1912
1931
  export declare function formatTiming(timing: Timing | undefined): string;
1913
1932
 
1933
+ /**
1934
+ * Formats a FHIR time string as a human readable string.
1935
+ * The viewer's timezone does not affect the display.
1936
+ * @param time - The time to format, a string like `HH:mm` or `HH:mm:ss`
1937
+ * @param locales - Optional locales.
1938
+ * @param options - Optional time format options.
1939
+ * @returns The formatted time string.
1940
+ */
1941
+ export declare function formatWallTime(time: string | undefined, locales?: Intl.LocalesArgument, options?: Intl.DateTimeFormatOptions): string;
1942
+
1914
1943
  export declare class FunctionAtom implements Atom {
1915
1944
  readonly name: string;
1916
1945
  readonly args: Atom[];
@@ -3383,7 +3412,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
3383
3412
  private readonly fetch;
3384
3413
  private readonly createPdfImpl?;
3385
3414
  private readonly storage;
3386
- private readonly requestCache;
3415
+ protected readonly requestCache: LRUCache<RequestCacheEntry> | undefined;
3387
3416
  private readonly cacheTime;
3388
3417
  private readonly baseUrl;
3389
3418
  private readonly fhirBaseUrl;
@@ -3842,7 +3871,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
3842
3871
  * @param reference - The FHIR reference.
3843
3872
  * @returns The resource if it is available in the cache; undefined otherwise.
3844
3873
  */
3845
- getCachedReference<T extends Resource>(reference: Reference<T>): T | undefined;
3874
+ getCachedReference<T extends Resource>(reference: Reference<T>): WithId<T> | undefined;
3846
3875
  /**
3847
3876
  * Reads a resource by resource type and ID.
3848
3877
  *
@@ -3889,9 +3918,10 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
3889
3918
  * If the schema is already cached, the promise is resolved immediately.
3890
3919
  * @category Schema
3891
3920
  * @param resourceType - The FHIR resource type.
3921
+ * @param options - Optional fetch options.
3892
3922
  * @returns Promise to a schema with the requested resource type.
3893
3923
  */
3894
- requestSchema(resourceType: string): Promise<void>;
3924
+ requestSchema(resourceType: string, options?: MedplumRequestOptions): Promise<void>;
3895
3925
  /**
3896
3926
  * Requests the schema for a profile.
3897
3927
  * If the schema is already cached, the promise is resolved immediately.
@@ -4618,6 +4648,12 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4618
4648
  * @returns Promise to the bundle.
4619
4649
  */
4620
4650
  private getBundle;
4651
+ /**
4652
+ * Returns true if caching is enabled for the given request options.
4653
+ * @param options - Optional fetch options for cache settings.
4654
+ * @returns True if caching is enabled.
4655
+ */
4656
+ private isCacheEnabled;
4621
4657
  /**
4622
4658
  * Returns the cache entry if available and not expired.
4623
4659
  * @param key - The cache key to retrieve.
@@ -4629,6 +4665,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4629
4665
  * Adds a readable promise to the cache.
4630
4666
  * @param key - The cache key to store.
4631
4667
  * @param value - The readable promise to store.
4668
+ * @param options - Optional fetch options for cache settings.
4632
4669
  */
4633
4670
  private setCacheEntry;
4634
4671
  /**
@@ -4636,6 +4673,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4636
4673
  * This is used in cases where the resource is loaded indirectly.
4637
4674
  * For example, when a resource is loaded as part of a Bundle.
4638
4675
  * @param resource - The resource to cache.
4676
+ * @param options - Optional fetch options for cache settings.
4639
4677
  */
4640
4678
  private cacheResource;
4641
4679
  /**
@@ -4679,6 +4717,13 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4679
4717
  * @param contentType - The new content type to set.
4680
4718
  */
4681
4719
  private setRequestContentType;
4720
+ /**
4721
+ * Returns a header from fetch options.
4722
+ * @param options - The fetch options.
4723
+ * @param key - The header key.
4724
+ * @returns The header value if found.
4725
+ */
4726
+ private getRequestHeader;
4682
4727
  /**
4683
4728
  * Sets a header on fetch options.
4684
4729
  * @param options - The fetch options.
@@ -4908,6 +4953,7 @@ export declare class MedplumClient extends TypedEventTarget<MedplumClientEventMa
4908
4953
  * @returns Promise that returns a project membership or an operation outcome.
4909
4954
  */
4910
4955
  invite(projectId: string, body: InviteRequest): Promise<ProjectMembership | OperationOutcome>;
4956
+ private handleTokenError;
4911
4957
  /**
4912
4958
  * Makes a POST request to the tokens endpoint.
4913
4959
  * See {@link https://openid.net/specs/openid-connect-core-1_0.html#TokenEndpoint | OpenID Connect Core 1.0 TokenEndpoint} for full details.
@@ -5231,7 +5277,7 @@ export declare interface MedplumClientOptions {
5231
5277
  * - 'basic': Log method, URL, and status code only (no sensitive headers)
5232
5278
  * - 'verbose': Log all details including headers (may include sensitive data like tokens)
5233
5279
  *
5234
- * @default 'none'
5280
+ * @defaultValue 'none'
5235
5281
  */
5236
5282
  logLevel?: ClientLogLevel;
5237
5283
  /**
@@ -5719,14 +5765,14 @@ export declare class OperationOutcomeError extends Error {
5719
5765
  }
5720
5766
 
5721
5767
  /**
5722
- * Returns a string represenation of the operation outcome issue.
5768
+ * Returns a string representation of the operation outcome issue.
5723
5769
  * @param issue - The operation outcome issue.
5724
5770
  * @returns The string representation of the operation outcome issue.
5725
5771
  */
5726
5772
  export declare function operationOutcomeIssueToString(issue: OperationOutcomeIssue): string;
5727
5773
 
5728
5774
  /**
5729
- * Returns a string represenation of the operation outcome.
5775
+ * Returns a string representation of the operation outcome.
5730
5776
  * @param outcome - The operation outcome.
5731
5777
  * @returns The string representation of the operation outcome.
5732
5778
  */
@@ -6391,7 +6437,12 @@ export declare class ParserBuilder {
6391
6437
  */
6392
6438
  export declare function replaceQueryVariables(user: CdsUserResource, context: Record<string, unknown>, query: string): string;
6393
6439
 
6394
- export declare interface RequestProfileSchemaOptions {
6440
+ export declare interface RequestCacheEntry {
6441
+ readonly requestTime: number;
6442
+ readonly value: ReadablePromise<any>;
6443
+ }
6444
+
6445
+ export declare interface RequestProfileSchemaOptions extends MedplumRequestOptions {
6395
6446
  /** (optional) Whether to include nested profiles, e.g. from extensions. Defaults to false. */
6396
6447
  expandProfile?: boolean;
6397
6448
  }
@@ -6551,10 +6602,21 @@ export declare class ParserBuilder {
6551
6602
 
6552
6603
  /**
6553
6604
  * Sleeps for the specified number of milliseconds.
6554
- * @param ms - Time delay in milliseconds
6605
+ * @param ms - Time delay in milliseconds.
6606
+ * @param options - Optional sleep options.
6555
6607
  * @returns A promise that resolves after the specified number of milliseconds.
6556
6608
  */
6557
- export declare const sleep: (ms: number) => Promise<void>;
6609
+ export declare const sleep: (ms: number, options?: SleepOptions) => Promise<void>;
6610
+
6611
+ /**
6612
+ * Sleep options.
6613
+ */
6614
+ export declare interface SleepOptions {
6615
+ /**
6616
+ * Optional `AbortSignal` that can be used to cancel the scheduled sleep.
6617
+ */
6618
+ readonly signal?: AbortSignal | null;
6619
+ }
6558
6620
 
6559
6621
  export declare interface SliceDefinition extends Omit<InternalSchemaElement, 'slicing'> {
6560
6622
  name: string;
@@ -7058,6 +7120,7 @@ export declare class ParserBuilder {
7058
7120
  collect?: {
7059
7121
  tokens?: Record<string, TypedValueWithPath[]>;
7060
7122
  };
7123
+ base64BinaryMaxBytes?: number;
7061
7124
  }
7062
7125
 
7063
7126
  export declare type ValueOrExternalSecret<T extends ExternalSecretPrimitive> = T | ExternalSecret<T>;
@@ -7072,6 +7135,7 @@ export declare class ParserBuilder {
7072
7135
  date?: string;
7073
7136
  offset?: number;
7074
7137
  count?: number;
7138
+ displayLanguage?: string;
7075
7139
  }
7076
7140
 
7077
7141
  /**