vintasend-medplum 0.4.17 → 0.4.18

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.
@@ -59,7 +59,7 @@ export declare class MedplumAttachmentFile implements AttachmentFile {
59
59
  *
60
60
  * Works with Binary resources that have either:
61
61
  * - Inline data (base64 encoded)
62
- * - A presigned URL to download from
62
+ * - External storage (downloaded via Medplum client)
63
63
  */
64
64
  read(): Promise<Buffer>;
65
65
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"medplum-attachment-manager.d.ts","sourceRoot":"","sources":["../src/medplum-attachment-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,oEAAoE,CAAC;AAC3G,OAAO,KAAK,EACV,oBAAoB,EACpB,cAAc,EACd,cAAc,EACf,MAAM,iCAAiC,CAAC;AAEzC;;;;;;;;GAQG;AACH,qBAAa,wBAAyB,SAAQ,qBAAqB;IACrD,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,aAAa;IAI1C;;;;;;;OAOG;IACG,UAAU,CACd,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,oBAAoB,CAAC;IAkEhC;;;;;OAKG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IA+CnE;;;;;;OAMG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwB/C;;;;;OAKG;IACH,yBAAyB,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,cAAc;CAiBpF;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,cAAc;IAExD,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,QAAQ;gBADR,OAAO,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EAAE,MAAM;IAG1B;;;;;;OAMG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IA2C7B;;;;;OAKG;IACG,MAAM,IAAI,OAAO,CAAC,cAAc,CAAC;IAUvC;;;;;;;OAOG;IACG,GAAG,CAAC,SAAS,SAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAWtC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAG9B"}
@@ -188,25 +188,48 @@ export class MedplumAttachmentFile {
188
188
  *
189
189
  * Works with Binary resources that have either:
190
190
  * - Inline data (base64 encoded)
191
- * - A presigned URL to download from
191
+ * - External storage (downloaded via Medplum client)
192
192
  */
193
193
  async read() {
194
- const binary = await this.medplum.readResource('Binary', this.binaryId);
195
- // If data is embedded in the Binary resource, use it directly
196
- if (binary.data) {
197
- return Buffer.from(binary.data, 'base64');
194
+ try {
195
+ // Use Medplum's download method which handles both inline and external storage
196
+ const data = await this.medplum.download(`Binary/${this.binaryId}`);
197
+ // Convert to Buffer
198
+ if (data instanceof ArrayBuffer) {
199
+ return Buffer.from(data);
200
+ }
201
+ else if (data instanceof Blob) {
202
+ const arrayBuffer = await data.arrayBuffer();
203
+ return Buffer.from(arrayBuffer);
204
+ }
205
+ else if (typeof data === 'string') {
206
+ // If it's a base64 string
207
+ return Buffer.from(data, 'base64');
208
+ }
209
+ else if (Buffer.isBuffer(data)) {
210
+ return data;
211
+ }
212
+ throw new Error(`Unexpected data type from Medplum download: ${typeof data}`);
198
213
  }
199
- // If data is not embedded but a URL is available, download it
200
- if (binary.url) {
201
- const response = await fetch(binary.url);
202
- if (!response.ok) {
203
- throw new Error(`Failed to download binary from URL: ${response.statusText}`);
214
+ catch (error) {
215
+ // Fallback to reading the Binary resource directly if download fails
216
+ const binary = await this.medplum.readResource('Binary', this.binaryId);
217
+ // If data is embedded in the Binary resource, use it directly
218
+ if (binary.data) {
219
+ return Buffer.from(binary.data, 'base64');
220
+ }
221
+ // If data is not embedded but a URL is available, download it
222
+ if (binary.url) {
223
+ const response = await fetch(binary.url);
224
+ if (!response.ok) {
225
+ throw new Error(`Failed to download binary from URL: ${response.statusText}`);
226
+ }
227
+ const arrayBuffer = await response.arrayBuffer();
228
+ return Buffer.from(arrayBuffer);
204
229
  }
205
- const arrayBuffer = await response.arrayBuffer();
206
- return Buffer.from(arrayBuffer);
230
+ // Re-throw original error if fallback also fails
231
+ throw error;
207
232
  }
208
- // Neither data nor URL available
209
- throw new Error('Binary resource has neither data nor url');
210
233
  }
211
234
  /**
212
235
  * Get a readable stream for the file.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vintasend-medplum",
3
- "version": "0.4.17",
3
+ "version": "0.4.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {