@meistrari/vault-sdk 1.1.0 → 1.3.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/dist/index.d.mts CHANGED
@@ -14,6 +14,15 @@ declare class APIKeyAuthStrategy implements AuthStrategy {
14
14
  constructor(apiKey: string);
15
15
  }
16
16
 
17
+ declare class FetchError extends Error {
18
+ readonly message: string;
19
+ readonly url: string;
20
+ readonly method: string;
21
+ readonly response: Response;
22
+ constructor(message: string, url: string, method: string, response: Response);
23
+ static from(url: string, method: string, response: Response): Promise<FetchError>;
24
+ }
25
+
17
26
  type VaultConfig = {
18
27
  vaultUrl: string;
19
28
  authStrategy: AuthStrategy;
@@ -76,12 +85,18 @@ declare class VaultFile {
76
85
  * @param params.method - The method to use for the fetch
77
86
  * @param params.path - The path to fetch
78
87
  * @param params.body - The body of the request
88
+ * @param params.signal - The signal to abort the request
79
89
  * @returns The response from the vault
80
90
  * @throws {FetchError} If the fetch fails
81
91
  */
82
92
  private _fetch;
83
93
  /**
84
94
  * Creates a new file in the vault.
95
+ * @param metadata - The metadata for creating a file
96
+ * @param metadata.size - The size of the file
97
+ * @param metadata.mimeType - The mime type of the file
98
+ * @param options - The options for the request
99
+ * @param options.signal - The signal to abort the request
85
100
  *
86
101
  * @returns The metadata of the file
87
102
  * @throws {Error} If the file ID is not set
@@ -95,6 +110,9 @@ declare class VaultFile {
95
110
  * @param params.reference - The reference to the file in the vault
96
111
  * @param params.config - The configuration for the VaultFile
97
112
  * @param params.download - Whether to download the file content (default: false)
113
+ * @param options - The options for the request
114
+ * @param options.signal - The signal to abort the request
115
+ *
98
116
  * @returns A new VaultFile instance
99
117
  *
100
118
  * @example
@@ -128,6 +146,8 @@ declare class VaultFile {
128
146
  reference: string;
129
147
  config: VaultConfig;
130
148
  download?: boolean;
149
+ }, options?: {
150
+ signal?: AbortSignal;
131
151
  }): Promise<VaultFile>;
132
152
  /**
133
153
  * Creates a new VaultFile instance from given content.
@@ -137,6 +157,9 @@ declare class VaultFile {
137
157
  * @param params.content - The content of the file
138
158
  * @param params.config - The configuration for the VaultFile
139
159
  * @param params.upload - Whether to upload the file (default: false)
160
+ * @param options - The options for the request
161
+ * @param options.signal - The signal to abort the request
162
+ *
140
163
  * @returns A new VaultFile instance
141
164
  *
142
165
  * @example
@@ -174,15 +197,21 @@ declare class VaultFile {
174
197
  content: Blob | File;
175
198
  config: VaultConfig;
176
199
  upload?: boolean;
200
+ }, options?: {
201
+ signal?: AbortSignal;
177
202
  }): Promise<VaultFile>;
178
203
  /**
179
204
  * Populates the metadata of the file instance.
205
+ * @param options - The options for the request
206
+ * @param options.signal - The signal to abort the request
180
207
  *
181
208
  * @returns The file instance
182
209
  * @throws {Error} If the file ID is not set
183
210
  * @throws {FetchError} If the metadata fetch fails
184
211
  */
185
- populateMetadata(): Promise<this | undefined>;
212
+ populateMetadata(options?: {
213
+ signal?: AbortSignal;
214
+ }): Promise<this | undefined>;
186
215
  /**
187
216
  * Gets the vault reference for this file.
188
217
  *
@@ -192,29 +221,41 @@ declare class VaultFile {
192
221
  getVaultReference(): string;
193
222
  /**
194
223
  * Fetches the metadata of the file.
224
+ * @param options - The options for the request
225
+ * @param options.signal - The signal to abort the request
195
226
  *
196
227
  * @returns The metadata of the file
197
228
  * @throws {Error} If the file ID is not set
198
229
  * @throws {FetchError} If the metadata fetch fails
199
230
  */
200
- getFileMetadata(): Promise<FileMetadata>;
231
+ getFileMetadata(options?: {
232
+ signal?: AbortSignal;
233
+ }): Promise<FileMetadata>;
201
234
  /**
202
235
  * Fetches a upload URL for the file.
236
+ * @param options - The options for the request
237
+ * @param options.signal - The signal to abort the request
203
238
  *
204
239
  * @returns The upload URL for the file
205
240
  * @throws {Error} If the vault service returns an invalid response
206
241
  * @throws {FetchError} If the upload URL fetch fails
207
242
  */
208
- getUploadUrl(): Promise<URL>;
243
+ getUploadUrl(options?: {
244
+ signal?: AbortSignal;
245
+ }): Promise<URL>;
209
246
  /**
210
247
  * Fetches a download URL for the file.
248
+ * @param options - The options for the request
249
+ * @param options.signal - The signal to abort the request
211
250
  *
212
251
  * @returns The download URL for the file
213
252
  * @throws {Error} If the vault service returns an invalid response
214
253
  * @throws {Error} If not file ID, name or content is set
215
254
  * @throws {FetchError} If the download URL fetch fails
216
255
  */
217
- getDownloadUrl(): Promise<URL>;
256
+ getDownloadUrl(options?: {
257
+ signal?: AbortSignal;
258
+ }): Promise<URL>;
218
259
  /**
219
260
  * Uploads a file to the vault.
220
261
  *
@@ -233,15 +274,24 @@ declare class VaultFile {
233
274
  * ```
234
275
  *
235
276
  * @param file - The file to upload to the vault. If not provided, the file content will be taken from the `content` property.
277
+ * @param url - The URL to upload the file to. If not provided, the upload URL will be fetched from the vault.
278
+ * @param options - The options for the request
279
+ * @param options.signal - The signal to abort the request
280
+ *
236
281
  * @throws {FetchError} If the upload fails
237
282
  * @throws {Error} If the file content is not set and no file is provided
238
283
  * @returns Promise that resolves when upload is complete
239
284
  */
240
- upload(file?: Blob, url?: string): Promise<void>;
285
+ upload(file?: Blob, url?: string, options?: {
286
+ signal?: AbortSignal;
287
+ }): Promise<void>;
241
288
  /**
242
289
  * Downloads a file from the vault.
243
290
  *
244
291
  * @param responseType - The type of the response
292
+ * @param options - The options for the request
293
+ * @param options.signal - The signal to abort the request
294
+ *
245
295
  * @returns The response from the vault
246
296
  *
247
297
  * @example
@@ -250,22 +300,30 @@ declare class VaultFile {
250
300
  * const content = await vaultFile.download()
251
301
  * ```
252
302
  */
253
- download(responseType?: 'blob'): Promise<Blob>;
254
- download(responseType: 'base64'): Promise<string>;
255
- }
256
-
257
- declare class FetchError extends Error {
258
- readonly message: string;
259
- readonly url: string;
260
- readonly method: string;
261
- readonly response: Response;
262
- constructor(message: string, url: string, method: string, response: Response);
263
- static from(url: string, method: string, response: Response): Promise<FetchError>;
303
+ download(responseType?: 'blob', options?: {
304
+ signal?: AbortSignal;
305
+ }): Promise<Blob>;
306
+ download(responseType: 'base64', options?: {
307
+ signal?: AbortSignal;
308
+ }): Promise<string>;
309
+ /**
310
+ * Deletes the file from the vault.
311
+ * @param options - The options for the request
312
+ * @param options.signal - The signal to abort the request
313
+ *
314
+ */
315
+ delete(options?: {
316
+ signal?: AbortSignal;
317
+ }): Promise<void>;
264
318
  }
265
319
 
266
320
  declare function vaultClient(config: VaultConfig): {
267
- createFromContent: (name: string, content: Blob | File) => Promise<VaultFile>;
268
- createFromReference: (reference: string) => Promise<VaultFile>;
321
+ createFromContent: (name: string, content: Blob | File, options?: {
322
+ signal?: AbortSignal;
323
+ }) => Promise<VaultFile>;
324
+ createFromReference: (reference: string, options?: {
325
+ signal?: AbortSignal;
326
+ }) => Promise<VaultFile>;
269
327
  };
270
328
 
271
329
  export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, vaultClient };
package/dist/index.d.ts CHANGED
@@ -14,6 +14,15 @@ declare class APIKeyAuthStrategy implements AuthStrategy {
14
14
  constructor(apiKey: string);
15
15
  }
16
16
 
17
+ declare class FetchError extends Error {
18
+ readonly message: string;
19
+ readonly url: string;
20
+ readonly method: string;
21
+ readonly response: Response;
22
+ constructor(message: string, url: string, method: string, response: Response);
23
+ static from(url: string, method: string, response: Response): Promise<FetchError>;
24
+ }
25
+
17
26
  type VaultConfig = {
18
27
  vaultUrl: string;
19
28
  authStrategy: AuthStrategy;
@@ -76,12 +85,18 @@ declare class VaultFile {
76
85
  * @param params.method - The method to use for the fetch
77
86
  * @param params.path - The path to fetch
78
87
  * @param params.body - The body of the request
88
+ * @param params.signal - The signal to abort the request
79
89
  * @returns The response from the vault
80
90
  * @throws {FetchError} If the fetch fails
81
91
  */
82
92
  private _fetch;
83
93
  /**
84
94
  * Creates a new file in the vault.
95
+ * @param metadata - The metadata for creating a file
96
+ * @param metadata.size - The size of the file
97
+ * @param metadata.mimeType - The mime type of the file
98
+ * @param options - The options for the request
99
+ * @param options.signal - The signal to abort the request
85
100
  *
86
101
  * @returns The metadata of the file
87
102
  * @throws {Error} If the file ID is not set
@@ -95,6 +110,9 @@ declare class VaultFile {
95
110
  * @param params.reference - The reference to the file in the vault
96
111
  * @param params.config - The configuration for the VaultFile
97
112
  * @param params.download - Whether to download the file content (default: false)
113
+ * @param options - The options for the request
114
+ * @param options.signal - The signal to abort the request
115
+ *
98
116
  * @returns A new VaultFile instance
99
117
  *
100
118
  * @example
@@ -128,6 +146,8 @@ declare class VaultFile {
128
146
  reference: string;
129
147
  config: VaultConfig;
130
148
  download?: boolean;
149
+ }, options?: {
150
+ signal?: AbortSignal;
131
151
  }): Promise<VaultFile>;
132
152
  /**
133
153
  * Creates a new VaultFile instance from given content.
@@ -137,6 +157,9 @@ declare class VaultFile {
137
157
  * @param params.content - The content of the file
138
158
  * @param params.config - The configuration for the VaultFile
139
159
  * @param params.upload - Whether to upload the file (default: false)
160
+ * @param options - The options for the request
161
+ * @param options.signal - The signal to abort the request
162
+ *
140
163
  * @returns A new VaultFile instance
141
164
  *
142
165
  * @example
@@ -174,15 +197,21 @@ declare class VaultFile {
174
197
  content: Blob | File;
175
198
  config: VaultConfig;
176
199
  upload?: boolean;
200
+ }, options?: {
201
+ signal?: AbortSignal;
177
202
  }): Promise<VaultFile>;
178
203
  /**
179
204
  * Populates the metadata of the file instance.
205
+ * @param options - The options for the request
206
+ * @param options.signal - The signal to abort the request
180
207
  *
181
208
  * @returns The file instance
182
209
  * @throws {Error} If the file ID is not set
183
210
  * @throws {FetchError} If the metadata fetch fails
184
211
  */
185
- populateMetadata(): Promise<this | undefined>;
212
+ populateMetadata(options?: {
213
+ signal?: AbortSignal;
214
+ }): Promise<this | undefined>;
186
215
  /**
187
216
  * Gets the vault reference for this file.
188
217
  *
@@ -192,29 +221,41 @@ declare class VaultFile {
192
221
  getVaultReference(): string;
193
222
  /**
194
223
  * Fetches the metadata of the file.
224
+ * @param options - The options for the request
225
+ * @param options.signal - The signal to abort the request
195
226
  *
196
227
  * @returns The metadata of the file
197
228
  * @throws {Error} If the file ID is not set
198
229
  * @throws {FetchError} If the metadata fetch fails
199
230
  */
200
- getFileMetadata(): Promise<FileMetadata>;
231
+ getFileMetadata(options?: {
232
+ signal?: AbortSignal;
233
+ }): Promise<FileMetadata>;
201
234
  /**
202
235
  * Fetches a upload URL for the file.
236
+ * @param options - The options for the request
237
+ * @param options.signal - The signal to abort the request
203
238
  *
204
239
  * @returns The upload URL for the file
205
240
  * @throws {Error} If the vault service returns an invalid response
206
241
  * @throws {FetchError} If the upload URL fetch fails
207
242
  */
208
- getUploadUrl(): Promise<URL>;
243
+ getUploadUrl(options?: {
244
+ signal?: AbortSignal;
245
+ }): Promise<URL>;
209
246
  /**
210
247
  * Fetches a download URL for the file.
248
+ * @param options - The options for the request
249
+ * @param options.signal - The signal to abort the request
211
250
  *
212
251
  * @returns The download URL for the file
213
252
  * @throws {Error} If the vault service returns an invalid response
214
253
  * @throws {Error} If not file ID, name or content is set
215
254
  * @throws {FetchError} If the download URL fetch fails
216
255
  */
217
- getDownloadUrl(): Promise<URL>;
256
+ getDownloadUrl(options?: {
257
+ signal?: AbortSignal;
258
+ }): Promise<URL>;
218
259
  /**
219
260
  * Uploads a file to the vault.
220
261
  *
@@ -233,15 +274,24 @@ declare class VaultFile {
233
274
  * ```
234
275
  *
235
276
  * @param file - The file to upload to the vault. If not provided, the file content will be taken from the `content` property.
277
+ * @param url - The URL to upload the file to. If not provided, the upload URL will be fetched from the vault.
278
+ * @param options - The options for the request
279
+ * @param options.signal - The signal to abort the request
280
+ *
236
281
  * @throws {FetchError} If the upload fails
237
282
  * @throws {Error} If the file content is not set and no file is provided
238
283
  * @returns Promise that resolves when upload is complete
239
284
  */
240
- upload(file?: Blob, url?: string): Promise<void>;
285
+ upload(file?: Blob, url?: string, options?: {
286
+ signal?: AbortSignal;
287
+ }): Promise<void>;
241
288
  /**
242
289
  * Downloads a file from the vault.
243
290
  *
244
291
  * @param responseType - The type of the response
292
+ * @param options - The options for the request
293
+ * @param options.signal - The signal to abort the request
294
+ *
245
295
  * @returns The response from the vault
246
296
  *
247
297
  * @example
@@ -250,22 +300,30 @@ declare class VaultFile {
250
300
  * const content = await vaultFile.download()
251
301
  * ```
252
302
  */
253
- download(responseType?: 'blob'): Promise<Blob>;
254
- download(responseType: 'base64'): Promise<string>;
255
- }
256
-
257
- declare class FetchError extends Error {
258
- readonly message: string;
259
- readonly url: string;
260
- readonly method: string;
261
- readonly response: Response;
262
- constructor(message: string, url: string, method: string, response: Response);
263
- static from(url: string, method: string, response: Response): Promise<FetchError>;
303
+ download(responseType?: 'blob', options?: {
304
+ signal?: AbortSignal;
305
+ }): Promise<Blob>;
306
+ download(responseType: 'base64', options?: {
307
+ signal?: AbortSignal;
308
+ }): Promise<string>;
309
+ /**
310
+ * Deletes the file from the vault.
311
+ * @param options - The options for the request
312
+ * @param options.signal - The signal to abort the request
313
+ *
314
+ */
315
+ delete(options?: {
316
+ signal?: AbortSignal;
317
+ }): Promise<void>;
264
318
  }
265
319
 
266
320
  declare function vaultClient(config: VaultConfig): {
267
- createFromContent: (name: string, content: Blob | File) => Promise<VaultFile>;
268
- createFromReference: (reference: string) => Promise<VaultFile>;
321
+ createFromContent: (name: string, content: Blob | File, options?: {
322
+ signal?: AbortSignal;
323
+ }) => Promise<VaultFile>;
324
+ createFromReference: (reference: string, options?: {
325
+ signal?: AbortSignal;
326
+ }) => Promise<VaultFile>;
269
327
  };
270
328
 
271
329
  export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, vaultClient };