vintasend-aws-s3-attachments 0.4.17 → 0.5.0-alpha2

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.
@@ -1,5 +1,5 @@
1
1
  import { BaseAttachmentManager } from 'vintasend/dist/services/attachment-manager/base-attachment-manager';
2
- import type { AttachmentFileRecord, AttachmentFile, FileAttachment } from 'vintasend/dist/types/attachment';
2
+ import type { AttachmentFileRecord, AttachmentFile, FileAttachment, StorageIdentifiers } from 'vintasend/dist/types/attachment';
3
3
  export interface S3AttachmentManagerConfig {
4
4
  /**
5
5
  * S3 bucket name where attachments will be stored
@@ -72,36 +72,24 @@ export declare class S3AttachmentManager extends BaseAttachmentManager {
72
72
  */
73
73
  getFile(fileId: string): Promise<AttachmentFileRecord | null>;
74
74
  /**
75
- * Reconstruct an AttachmentFile accessor from storage metadata.
75
+ * Reconstruct an AttachmentFile accessor from storage identifiers.
76
76
  *
77
77
  * This allows the system to recreate file access objects when loading
78
78
  * notifications from the database.
79
79
  *
80
- * @param storageMetadata - S3 storage metadata (bucket, key, region)
80
+ * @param storageIdentifiers - S3 storage identifiers (bucket, key, region)
81
81
  * @returns An S3AttachmentFile instance for accessing the file
82
82
  */
83
- reconstructAttachmentFile(storageMetadata: Record<string, unknown>): AttachmentFile;
83
+ reconstructAttachmentFile(storageIdentifiers: StorageIdentifiers): AttachmentFile;
84
84
  /**
85
- * Delete a file from S3.
85
+ * Delete a file from S3 using storage identifiers.
86
86
  *
87
- * Note: This implementation requires the Backend to pass full storage metadata
88
- * through a separate deleteFileWithMetadata() method, since the fileId alone
89
- * doesn't contain the S3 key needed for deletion.
87
+ * The Backend should call this method to delete files, passing the
88
+ * storage identifiers that were returned from uploadFile().
90
89
  *
91
- * For S3, the Backend should call deleteFileWithMetadata() instead.
92
- *
93
- * @param fileId - The unique identifier of the file
94
- */
95
- deleteFile(fileId: string): Promise<void>;
96
- /**
97
- * Delete a file from S3 using storage metadata.
98
- *
99
- * The Backend should call this method instead of deleteFile() for S3.
100
- *
101
- * @param fileId - The unique identifier of the file
102
- * @param storageMetadata - The storage metadata containing S3 key
90
+ * @param storageIdentifiers - The storage identifiers containing S3 key
103
91
  */
104
- deleteFileWithMetadata(fileId: string, storageMetadata: Record<string, unknown>): Promise<void>;
92
+ deleteFileByIdentifiers(storageIdentifiers: StorageIdentifiers): Promise<void>;
105
93
  /**
106
94
  * Build the S3 key for a file.
107
95
  *
@@ -1 +1 @@
1
- {"version":3,"file":"aws-s3-attachment-manager.d.ts","sourceRoot":"","sources":["../src/aws-s3-attachment-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oEAAoE,CAAC;AAC3G,OAAO,KAAK,EACX,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,MAAM,iCAAiC,CAAC;AAWzC,MAAM,WAAW,yBAAyB;IACzC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,WAAW,CAAC,EAAE;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;KACxB,CAAC;IAEF;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAoB,SAAQ,qBAAqB;IAC7D,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,yBAAyB;IAc7C;;;;;;;OAOG;IACG,UAAU,CACf,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,o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,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,yBAAyB;IAc7C;;;;;;;OAOG;IACG,UAAU,CACf,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,oBAAoB,CAAC;IAgDhC;;;;;;;;;;;OAWG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IA0DnE;;;;;;;;OAQG;IACH,yBAAyB,CACxB,kBAAkB,EAAE,kBAAkB,GACpC,cAAc;IAgBjB;;;;;;;OAOG;IACG,uBAAuB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBpF;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;CAMlB"}
@@ -58,17 +58,19 @@ export class S3AttachmentManager extends BaseAttachmentManager {
58
58
  });
59
59
  await this.s3Client.send(putCommand);
60
60
  // Return file record with S3 metadata
61
+ const storageIdentifiers = {
62
+ id: fileId,
63
+ awsS3Bucket: this.bucket,
64
+ awsS3Key: key,
65
+ awsS3Region: this.s3Client.config.region,
66
+ };
61
67
  return {
62
68
  id: fileId,
63
69
  filename,
64
70
  contentType: finalContentType,
65
71
  size: buffer.length,
66
72
  checksum,
67
- storageMetadata: {
68
- bucket: this.bucket,
69
- key,
70
- region: this.s3Client.config.region,
71
- },
73
+ storageIdentifiers,
72
74
  createdAt: new Date(),
73
75
  updatedAt: new Date(),
74
76
  };
@@ -120,10 +122,11 @@ export class S3AttachmentManager extends BaseAttachmentManager {
120
122
  contentType: headResponse.ContentType || 'application/octet-stream',
121
123
  size: headResponse.ContentLength || 0,
122
124
  checksum,
123
- storageMetadata: {
124
- bucket: this.bucket,
125
- key,
126
- region: this.s3Client.config.region,
125
+ storageIdentifiers: {
126
+ id: fileId,
127
+ awsS3Bucket: this.bucket,
128
+ awsS3Key: key,
129
+ awsS3Region: this.s3Client.config.region,
127
130
  },
128
131
  createdAt: headResponse.LastModified || new Date(),
129
132
  updatedAt: headResponse.LastModified || new Date(),
@@ -134,49 +137,37 @@ export class S3AttachmentManager extends BaseAttachmentManager {
134
137
  }
135
138
  }
136
139
  /**
137
- * Reconstruct an AttachmentFile accessor from storage metadata.
140
+ * Reconstruct an AttachmentFile accessor from storage identifiers.
138
141
  *
139
142
  * This allows the system to recreate file access objects when loading
140
143
  * notifications from the database.
141
144
  *
142
- * @param storageMetadata - S3 storage metadata (bucket, key, region)
145
+ * @param storageIdentifiers - S3 storage identifiers (bucket, key, region)
143
146
  * @returns An S3AttachmentFile instance for accessing the file
144
147
  */
145
- reconstructAttachmentFile(storageMetadata) {
146
- if (!storageMetadata.key || !storageMetadata.bucket) {
147
- throw new Error('Storage metadata must contain bucket and key for S3 files');
148
+ reconstructAttachmentFile(storageIdentifiers) {
149
+ const s3Identifiers = storageIdentifiers;
150
+ if (!s3Identifiers.awsS3Key || !s3Identifiers.awsS3Bucket) {
151
+ throw new Error('Storage identifiers must contain awsS3Bucket and awsS3Key for S3 files');
148
152
  }
149
- return new S3AttachmentFile(this.s3Client, storageMetadata.bucket, storageMetadata.key);
153
+ return new S3AttachmentFile(this.s3Client, s3Identifiers.awsS3Bucket, s3Identifiers.awsS3Key);
150
154
  }
151
155
  /**
152
- * Delete a file from S3.
156
+ * Delete a file from S3 using storage identifiers.
153
157
  *
154
- * Note: This implementation requires the Backend to pass full storage metadata
155
- * through a separate deleteFileWithMetadata() method, since the fileId alone
156
- * doesn't contain the S3 key needed for deletion.
158
+ * The Backend should call this method to delete files, passing the
159
+ * storage identifiers that were returned from uploadFile().
157
160
  *
158
- * For S3, the Backend should call deleteFileWithMetadata() instead.
159
- *
160
- * @param fileId - The unique identifier of the file
161
- */
162
- async deleteFile(fileId) {
163
- throw new Error('deleteFile() requires storage metadata for S3. Use deleteFileWithMetadata() or delete directly via AttachmentFile.delete()');
164
- }
165
- /**
166
- * Delete a file from S3 using storage metadata.
167
- *
168
- * The Backend should call this method instead of deleteFile() for S3.
169
- *
170
- * @param fileId - The unique identifier of the file
171
- * @param storageMetadata - The storage metadata containing S3 key
161
+ * @param storageIdentifiers - The storage identifiers containing S3 key
172
162
  */
173
- async deleteFileWithMetadata(fileId, storageMetadata) {
174
- if (!storageMetadata.key) {
175
- throw new Error('Storage metadata must contain key for S3 file deletion');
163
+ async deleteFileByIdentifiers(storageIdentifiers) {
164
+ const s3Identifiers = storageIdentifiers;
165
+ if (!s3Identifiers.awsS3Key) {
166
+ throw new Error('Storage identifiers must contain awsS3Key for S3 file deletion');
176
167
  }
177
168
  const deleteCommand = new DeleteObjectCommand({
178
169
  Bucket: this.bucket,
179
- Key: storageMetadata.key,
170
+ Key: s3Identifiers.awsS3Key,
180
171
  });
181
172
  await this.s3Client.send(deleteCommand);
182
173
  }
@@ -0,0 +1,18 @@
1
+ import type { StorageIdentifiers } from 'vintasend/dist/types/attachment';
2
+ /**
3
+ * AWS S3-specific storage identifiers.
4
+ * Contains S3 bucket, key, and region information needed to access files.
5
+ *
6
+ * Used when S3AttachmentManager uploads files:
7
+ * - Uploads file to S3 with a specific key
8
+ * - Returns bucket, key, and region so backend can reconstruct file access later
9
+ * - Does not create any database records (unlike MedplumAttachmentManager)
10
+ */
11
+ export interface S3StorageIdentifiers extends StorageIdentifiers {
12
+ id: string;
13
+ awsS3Bucket: string;
14
+ awsS3Key: string;
15
+ awsS3Region: string;
16
+ [key: string]: unknown;
17
+ }
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB;IAE9D,EAAE,EAAE,MAAM,CAAC;IAGX,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IAGpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vintasend-aws-s3-attachments",
3
- "version": "0.4.17",
3
+ "version": "0.5.0-alpha2",
4
4
  "description": "Implementation of AWS S3 Attachments for VintaSend",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@aws-sdk/client-s3": "^3.981.0",
20
20
  "@aws-sdk/s3-request-presigner": "^3.981.0",
21
- "vintasend": "^0.4.17"
21
+ "vintasend": "^0.5.0-alpha2"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/jest": "^30.0.0",