@meistrari/vault-sdk 1.0.1 → 1.2.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.cjs +142 -70
- package/dist/index.d.cts +77 -20
- package/dist/index.d.mts +77 -20
- package/dist/index.d.ts +77 -20
- package/dist/index.mjs +142 -70
- package/package.json +14 -11
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(
|
|
212
|
+
populateMetadata(options?: {
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
}): Promise<this | undefined>;
|
|
186
215
|
/**
|
|
187
216
|
* Gets the vault reference for this file.
|
|
188
217
|
*
|
|
@@ -192,49 +221,77 @@ 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(
|
|
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(
|
|
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(
|
|
256
|
+
getDownloadUrl(options?: {
|
|
257
|
+
signal?: AbortSignal;
|
|
258
|
+
}): Promise<URL>;
|
|
218
259
|
/**
|
|
219
260
|
* Uploads a file to the vault.
|
|
220
261
|
*
|
|
221
262
|
* @example
|
|
222
263
|
* ```ts
|
|
223
264
|
* const file = new File(['content'], 'document.txt')
|
|
224
|
-
* const vaultFile = await VaultFile.
|
|
265
|
+
* const vaultFile = await VaultFile.fromContent({
|
|
266
|
+
* name: 'document.txt',
|
|
267
|
+
* content: file,
|
|
268
|
+
* config: {
|
|
269
|
+
* vaultUrl,
|
|
270
|
+
* authStrategy,
|
|
271
|
+
* },
|
|
272
|
+
* })
|
|
225
273
|
* await vaultFile.upload(file)
|
|
226
274
|
* ```
|
|
227
275
|
*
|
|
228
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
|
+
*
|
|
229
281
|
* @throws {FetchError} If the upload fails
|
|
230
282
|
* @throws {Error} If the file content is not set and no file is provided
|
|
231
283
|
* @returns Promise that resolves when upload is complete
|
|
232
284
|
*/
|
|
233
|
-
upload(file?: Blob, url?: string
|
|
285
|
+
upload(file?: Blob, url?: string, options?: {
|
|
286
|
+
signal?: AbortSignal;
|
|
287
|
+
}): Promise<void>;
|
|
234
288
|
/**
|
|
235
289
|
* Downloads a file from the vault.
|
|
236
290
|
*
|
|
237
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
|
+
*
|
|
238
295
|
* @returns The response from the vault
|
|
239
296
|
*
|
|
240
297
|
* @example
|
|
@@ -243,22 +300,22 @@ declare class VaultFile {
|
|
|
243
300
|
* const content = await vaultFile.download()
|
|
244
301
|
* ```
|
|
245
302
|
*/
|
|
246
|
-
download(responseType?: 'blob'
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
readonly url: string;
|
|
253
|
-
readonly method: string;
|
|
254
|
-
readonly response: Response;
|
|
255
|
-
constructor(message: string, url: string, method: string, response: Response);
|
|
256
|
-
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>;
|
|
257
309
|
}
|
|
258
310
|
|
|
259
311
|
declare function vaultClient(config: VaultConfig): {
|
|
260
|
-
createFromContent: (name: string, content: Blob | File
|
|
261
|
-
|
|
312
|
+
createFromContent: (name: string, content: Blob | File, options?: {
|
|
313
|
+
signal?: AbortSignal;
|
|
314
|
+
}) => Promise<VaultFile>;
|
|
315
|
+
createFromReference: (reference: string, options?: {
|
|
316
|
+
signal?: AbortSignal;
|
|
317
|
+
}) => Promise<VaultFile>;
|
|
262
318
|
};
|
|
263
319
|
|
|
264
|
-
export { APIKeyAuthStrategy,
|
|
320
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, vaultClient };
|
|
321
|
+
export type { AuthStrategy, VaultConfig };
|
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(
|
|
212
|
+
populateMetadata(options?: {
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
}): Promise<this | undefined>;
|
|
186
215
|
/**
|
|
187
216
|
* Gets the vault reference for this file.
|
|
188
217
|
*
|
|
@@ -192,49 +221,77 @@ 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(
|
|
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(
|
|
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(
|
|
256
|
+
getDownloadUrl(options?: {
|
|
257
|
+
signal?: AbortSignal;
|
|
258
|
+
}): Promise<URL>;
|
|
218
259
|
/**
|
|
219
260
|
* Uploads a file to the vault.
|
|
220
261
|
*
|
|
221
262
|
* @example
|
|
222
263
|
* ```ts
|
|
223
264
|
* const file = new File(['content'], 'document.txt')
|
|
224
|
-
* const vaultFile = await VaultFile.
|
|
265
|
+
* const vaultFile = await VaultFile.fromContent({
|
|
266
|
+
* name: 'document.txt',
|
|
267
|
+
* content: file,
|
|
268
|
+
* config: {
|
|
269
|
+
* vaultUrl,
|
|
270
|
+
* authStrategy,
|
|
271
|
+
* },
|
|
272
|
+
* })
|
|
225
273
|
* await vaultFile.upload(file)
|
|
226
274
|
* ```
|
|
227
275
|
*
|
|
228
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
|
+
*
|
|
229
281
|
* @throws {FetchError} If the upload fails
|
|
230
282
|
* @throws {Error} If the file content is not set and no file is provided
|
|
231
283
|
* @returns Promise that resolves when upload is complete
|
|
232
284
|
*/
|
|
233
|
-
upload(file?: Blob, url?: string
|
|
285
|
+
upload(file?: Blob, url?: string, options?: {
|
|
286
|
+
signal?: AbortSignal;
|
|
287
|
+
}): Promise<void>;
|
|
234
288
|
/**
|
|
235
289
|
* Downloads a file from the vault.
|
|
236
290
|
*
|
|
237
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
|
+
*
|
|
238
295
|
* @returns The response from the vault
|
|
239
296
|
*
|
|
240
297
|
* @example
|
|
@@ -243,22 +300,22 @@ declare class VaultFile {
|
|
|
243
300
|
* const content = await vaultFile.download()
|
|
244
301
|
* ```
|
|
245
302
|
*/
|
|
246
|
-
download(responseType?: 'blob'
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
readonly url: string;
|
|
253
|
-
readonly method: string;
|
|
254
|
-
readonly response: Response;
|
|
255
|
-
constructor(message: string, url: string, method: string, response: Response);
|
|
256
|
-
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>;
|
|
257
309
|
}
|
|
258
310
|
|
|
259
311
|
declare function vaultClient(config: VaultConfig): {
|
|
260
|
-
createFromContent: (name: string, content: Blob | File
|
|
261
|
-
|
|
312
|
+
createFromContent: (name: string, content: Blob | File, options?: {
|
|
313
|
+
signal?: AbortSignal;
|
|
314
|
+
}) => Promise<VaultFile>;
|
|
315
|
+
createFromReference: (reference: string, options?: {
|
|
316
|
+
signal?: AbortSignal;
|
|
317
|
+
}) => Promise<VaultFile>;
|
|
262
318
|
};
|
|
263
319
|
|
|
264
|
-
export { APIKeyAuthStrategy,
|
|
320
|
+
export { APIKeyAuthStrategy, DataTokenAuthStrategy, FetchError, VaultFile, vaultClient };
|
|
321
|
+
export type { AuthStrategy, VaultConfig };
|