@meistrari/vault-sdk 1.8.2 → 1.9.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/README.md CHANGED
@@ -5,7 +5,7 @@ This is the SDK for Vault V2.
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- ni @meistrari/vault-sdk-sdk
8
+ ni @meistrari/vault-sdk
9
9
  ```
10
10
 
11
11
  ## Table of Contents
package/dist/index.cjs CHANGED
@@ -237,7 +237,7 @@ function getFileName(content) {
237
237
  }
238
238
 
239
239
  const name = "@meistrari/vault-sdk";
240
- const version = "1.8.2";
240
+ const version = "1.9.0";
241
241
  const license = "UNLICENSED";
242
242
  const repository = {
243
243
  type: "git",
@@ -299,6 +299,9 @@ const packageJson = {
299
299
  publishConfig: publishConfig
300
300
  };
301
301
 
302
+ const serviceName = typeof process !== "undefined" ? process?.env?.SERVICE_NAME : "";
303
+ const userAgent = `vault-js-sdk:${packageJson.version}${serviceName ? `@${serviceName}` : ""}`.trim();
304
+
302
305
  var __defProp = Object.defineProperty;
303
306
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
304
307
  var __publicField = (obj, key, value) => {
@@ -322,7 +325,7 @@ async function wrappedFetch(url, requestInit) {
322
325
  duplex: requestInit.body instanceof ReadableStream ? "half" : void 0
323
326
  };
324
327
  const request = new Request(url, options);
325
- request.headers.set("User-Agent", `vault-js-sdk:${packageJson.version}`);
328
+ request.headers.set("User-Agent", userAgent);
326
329
  const response = await fetch(request);
327
330
  if (!response.ok) {
328
331
  throw await FetchError.from(request.url, request.method, response);
@@ -367,7 +370,7 @@ class VaultFile {
367
370
  */
368
371
  get headers() {
369
372
  const headers = this.config.authStrategy.getHeaders();
370
- headers.set("User-Agent", `vault-js-sdk:${packageJson.version}`);
373
+ headers.set("User-Agent", userAgent);
371
374
  return headers;
372
375
  }
373
376
  /**
@@ -413,6 +416,8 @@ class VaultFile {
413
416
  * @param metadata.size - The size of the file
414
417
  * @param metadata.mimeType - The mime type of the file
415
418
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
419
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
420
+ * @param metadata.onParentConflict - What to do if the file already exists as an active child of another file
416
421
  * @param options - The options for the request
417
422
  * @param options.signal - The signal to abort the request
418
423
  *
@@ -428,6 +433,8 @@ class VaultFile {
428
433
  size: metadata.size,
429
434
  mimeType: metadata.mimeType,
430
435
  parentId: metadata.parentId,
436
+ onMissingParent: metadata.onMissingParent,
437
+ onParentConflict: metadata.onParentConflict,
431
438
  fileName: this.name,
432
439
  sha256sum: this.id ?? this.metadata?.id ?? (this.content ? await getFileHash(this.content) : void 0)
433
440
  }),
@@ -518,6 +525,8 @@ class VaultFile {
518
525
  * @param params.mimeType - The MIME type of the file (optional)
519
526
  * @param params.upload - Whether to upload the file (default: false)
520
527
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
528
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
529
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
521
530
  * @param options - The options for the request
522
531
  * @param options.signal - The signal to abort the request
523
532
  *
@@ -570,7 +579,7 @@ class VaultFile {
570
579
  * ```
571
580
  */
572
581
  static async fromContent(params, options) {
573
- const { content, config: vaultConfig, upload = false, parentId } = params;
582
+ const { content, config: vaultConfig, upload = false, parentId, onMissingParent, onParentConflict } = params;
574
583
  const name = basename(params.name) ?? getFileName(content);
575
584
  const config = resolveConfig(vaultConfig);
576
585
  const { vaultUrl, authStrategy } = config;
@@ -589,7 +598,9 @@ class VaultFile {
589
598
  const createdFile = await file._createFile({
590
599
  size,
591
600
  mimeType,
592
- parentId
601
+ parentId,
602
+ onMissingParent,
603
+ onParentConflict
593
604
  }, { signal: options?.signal });
594
605
  if (upload) {
595
606
  await file.upload(file.content, createdFile.uploadUrl, { signal: options?.signal });
@@ -606,6 +617,8 @@ class VaultFile {
606
617
  * @param params.config - The configuration for the VaultFile
607
618
  * @param params.contentType - The MIME type of the content (optional)
608
619
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
620
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
621
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
609
622
  * @param options - The options for the request
610
623
  * @param options.signal - The signal to abort the request
611
624
  *
@@ -642,14 +655,23 @@ class VaultFile {
642
655
  * ```
643
656
  */
644
657
  static async fromStream(params, options) {
645
- const { contentLength, config: vaultConfig, contentType, parentId } = params;
658
+ const {
659
+ contentLength,
660
+ config: vaultConfig,
661
+ contentType,
662
+ parentId,
663
+ onMissingParent,
664
+ onParentConflict
665
+ } = params;
646
666
  const name = basename(params.name);
647
667
  const config = resolveConfig(vaultConfig);
648
668
  const file = new VaultFile({ config, name });
649
669
  await file._createFile({
650
670
  size: contentLength,
651
671
  mimeType: contentType || "application/octet-stream",
652
- parentId
672
+ parentId,
673
+ onMissingParent,
674
+ onParentConflict
653
675
  }, { signal: options?.signal });
654
676
  return file;
655
677
  }
package/dist/index.d.cts CHANGED
@@ -87,6 +87,8 @@ type VaultFileParams = {
87
87
  metadata?: FileMetadata | null;
88
88
  config: VaultConfig;
89
89
  };
90
+ type OnMissingParent = 'error' | 'create-as-root';
91
+ type OnParentConflict = 'error' | 'update-parent-id' | 'ignore';
90
92
  /**
91
93
  * Represents a file in the vault and allows interacting with it.
92
94
  *
@@ -152,6 +154,8 @@ declare class VaultFile {
152
154
  * @param metadata.size - The size of the file
153
155
  * @param metadata.mimeType - The mime type of the file
154
156
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
157
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
158
+ * @param metadata.onParentConflict - What to do if the file already exists as an active child of another file
155
159
  * @param options - The options for the request
156
160
  * @param options.signal - The signal to abort the request
157
161
  *
@@ -216,6 +220,8 @@ declare class VaultFile {
216
220
  * @param params.mimeType - The MIME type of the file (optional)
217
221
  * @param params.upload - Whether to upload the file (default: false)
218
222
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
223
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
224
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
219
225
  * @param options - The options for the request
220
226
  * @param options.signal - The signal to abort the request
221
227
  *
@@ -274,6 +280,8 @@ declare class VaultFile {
274
280
  mimeType?: string;
275
281
  upload?: boolean;
276
282
  parentId?: string;
283
+ onMissingParent?: OnMissingParent;
284
+ onParentConflict?: OnParentConflict;
277
285
  }, options?: {
278
286
  signal?: AbortSignal;
279
287
  }): Promise<VaultFile>;
@@ -287,6 +295,8 @@ declare class VaultFile {
287
295
  * @param params.config - The configuration for the VaultFile
288
296
  * @param params.contentType - The MIME type of the content (optional)
289
297
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
298
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
299
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
290
300
  * @param options - The options for the request
291
301
  * @param options.signal - The signal to abort the request
292
302
  *
@@ -328,6 +338,8 @@ declare class VaultFile {
328
338
  config: VaultConfig;
329
339
  contentType?: string;
330
340
  parentId?: string;
341
+ onMissingParent?: OnMissingParent;
342
+ onParentConflict?: OnParentConflict;
331
343
  }, options?: {
332
344
  signal?: AbortSignal;
333
345
  }): Promise<VaultFile>;
package/dist/index.d.mts CHANGED
@@ -87,6 +87,8 @@ type VaultFileParams = {
87
87
  metadata?: FileMetadata | null;
88
88
  config: VaultConfig;
89
89
  };
90
+ type OnMissingParent = 'error' | 'create-as-root';
91
+ type OnParentConflict = 'error' | 'update-parent-id' | 'ignore';
90
92
  /**
91
93
  * Represents a file in the vault and allows interacting with it.
92
94
  *
@@ -152,6 +154,8 @@ declare class VaultFile {
152
154
  * @param metadata.size - The size of the file
153
155
  * @param metadata.mimeType - The mime type of the file
154
156
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
157
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
158
+ * @param metadata.onParentConflict - What to do if the file already exists as an active child of another file
155
159
  * @param options - The options for the request
156
160
  * @param options.signal - The signal to abort the request
157
161
  *
@@ -216,6 +220,8 @@ declare class VaultFile {
216
220
  * @param params.mimeType - The MIME type of the file (optional)
217
221
  * @param params.upload - Whether to upload the file (default: false)
218
222
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
223
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
224
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
219
225
  * @param options - The options for the request
220
226
  * @param options.signal - The signal to abort the request
221
227
  *
@@ -274,6 +280,8 @@ declare class VaultFile {
274
280
  mimeType?: string;
275
281
  upload?: boolean;
276
282
  parentId?: string;
283
+ onMissingParent?: OnMissingParent;
284
+ onParentConflict?: OnParentConflict;
277
285
  }, options?: {
278
286
  signal?: AbortSignal;
279
287
  }): Promise<VaultFile>;
@@ -287,6 +295,8 @@ declare class VaultFile {
287
295
  * @param params.config - The configuration for the VaultFile
288
296
  * @param params.contentType - The MIME type of the content (optional)
289
297
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
298
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
299
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
290
300
  * @param options - The options for the request
291
301
  * @param options.signal - The signal to abort the request
292
302
  *
@@ -328,6 +338,8 @@ declare class VaultFile {
328
338
  config: VaultConfig;
329
339
  contentType?: string;
330
340
  parentId?: string;
341
+ onMissingParent?: OnMissingParent;
342
+ onParentConflict?: OnParentConflict;
331
343
  }, options?: {
332
344
  signal?: AbortSignal;
333
345
  }): Promise<VaultFile>;
package/dist/index.d.ts CHANGED
@@ -87,6 +87,8 @@ type VaultFileParams = {
87
87
  metadata?: FileMetadata | null;
88
88
  config: VaultConfig;
89
89
  };
90
+ type OnMissingParent = 'error' | 'create-as-root';
91
+ type OnParentConflict = 'error' | 'update-parent-id' | 'ignore';
90
92
  /**
91
93
  * Represents a file in the vault and allows interacting with it.
92
94
  *
@@ -152,6 +154,8 @@ declare class VaultFile {
152
154
  * @param metadata.size - The size of the file
153
155
  * @param metadata.mimeType - The mime type of the file
154
156
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
157
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
158
+ * @param metadata.onParentConflict - What to do if the file already exists as an active child of another file
155
159
  * @param options - The options for the request
156
160
  * @param options.signal - The signal to abort the request
157
161
  *
@@ -216,6 +220,8 @@ declare class VaultFile {
216
220
  * @param params.mimeType - The MIME type of the file (optional)
217
221
  * @param params.upload - Whether to upload the file (default: false)
218
222
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
223
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
224
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
219
225
  * @param options - The options for the request
220
226
  * @param options.signal - The signal to abort the request
221
227
  *
@@ -274,6 +280,8 @@ declare class VaultFile {
274
280
  mimeType?: string;
275
281
  upload?: boolean;
276
282
  parentId?: string;
283
+ onMissingParent?: OnMissingParent;
284
+ onParentConflict?: OnParentConflict;
277
285
  }, options?: {
278
286
  signal?: AbortSignal;
279
287
  }): Promise<VaultFile>;
@@ -287,6 +295,8 @@ declare class VaultFile {
287
295
  * @param params.config - The configuration for the VaultFile
288
296
  * @param params.contentType - The MIME type of the content (optional)
289
297
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
298
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
299
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
290
300
  * @param options - The options for the request
291
301
  * @param options.signal - The signal to abort the request
292
302
  *
@@ -328,6 +338,8 @@ declare class VaultFile {
328
338
  config: VaultConfig;
329
339
  contentType?: string;
330
340
  parentId?: string;
341
+ onMissingParent?: OnMissingParent;
342
+ onParentConflict?: OnParentConflict;
331
343
  }, options?: {
332
344
  signal?: AbortSignal;
333
345
  }): Promise<VaultFile>;
package/dist/index.mjs CHANGED
@@ -231,7 +231,7 @@ function getFileName(content) {
231
231
  }
232
232
 
233
233
  const name = "@meistrari/vault-sdk";
234
- const version = "1.8.2";
234
+ const version = "1.9.0";
235
235
  const license = "UNLICENSED";
236
236
  const repository = {
237
237
  type: "git",
@@ -293,6 +293,9 @@ const packageJson = {
293
293
  publishConfig: publishConfig
294
294
  };
295
295
 
296
+ const serviceName = typeof process !== "undefined" ? process?.env?.SERVICE_NAME : "";
297
+ const userAgent = `vault-js-sdk:${packageJson.version}${serviceName ? `@${serviceName}` : ""}`.trim();
298
+
296
299
  var __defProp = Object.defineProperty;
297
300
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
298
301
  var __publicField = (obj, key, value) => {
@@ -316,7 +319,7 @@ async function wrappedFetch(url, requestInit) {
316
319
  duplex: requestInit.body instanceof ReadableStream ? "half" : void 0
317
320
  };
318
321
  const request = new Request(url, options);
319
- request.headers.set("User-Agent", `vault-js-sdk:${packageJson.version}`);
322
+ request.headers.set("User-Agent", userAgent);
320
323
  const response = await fetch(request);
321
324
  if (!response.ok) {
322
325
  throw await FetchError.from(request.url, request.method, response);
@@ -361,7 +364,7 @@ class VaultFile {
361
364
  */
362
365
  get headers() {
363
366
  const headers = this.config.authStrategy.getHeaders();
364
- headers.set("User-Agent", `vault-js-sdk:${packageJson.version}`);
367
+ headers.set("User-Agent", userAgent);
365
368
  return headers;
366
369
  }
367
370
  /**
@@ -407,6 +410,8 @@ class VaultFile {
407
410
  * @param metadata.size - The size of the file
408
411
  * @param metadata.mimeType - The mime type of the file
409
412
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
413
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
414
+ * @param metadata.onParentConflict - What to do if the file already exists as an active child of another file
410
415
  * @param options - The options for the request
411
416
  * @param options.signal - The signal to abort the request
412
417
  *
@@ -422,6 +427,8 @@ class VaultFile {
422
427
  size: metadata.size,
423
428
  mimeType: metadata.mimeType,
424
429
  parentId: metadata.parentId,
430
+ onMissingParent: metadata.onMissingParent,
431
+ onParentConflict: metadata.onParentConflict,
425
432
  fileName: this.name,
426
433
  sha256sum: this.id ?? this.metadata?.id ?? (this.content ? await getFileHash(this.content) : void 0)
427
434
  }),
@@ -512,6 +519,8 @@ class VaultFile {
512
519
  * @param params.mimeType - The MIME type of the file (optional)
513
520
  * @param params.upload - Whether to upload the file (default: false)
514
521
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
522
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
523
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
515
524
  * @param options - The options for the request
516
525
  * @param options.signal - The signal to abort the request
517
526
  *
@@ -564,7 +573,7 @@ class VaultFile {
564
573
  * ```
565
574
  */
566
575
  static async fromContent(params, options) {
567
- const { content, config: vaultConfig, upload = false, parentId } = params;
576
+ const { content, config: vaultConfig, upload = false, parentId, onMissingParent, onParentConflict } = params;
568
577
  const name = basename(params.name) ?? getFileName(content);
569
578
  const config = resolveConfig(vaultConfig);
570
579
  const { vaultUrl, authStrategy } = config;
@@ -583,7 +592,9 @@ class VaultFile {
583
592
  const createdFile = await file._createFile({
584
593
  size,
585
594
  mimeType,
586
- parentId
595
+ parentId,
596
+ onMissingParent,
597
+ onParentConflict
587
598
  }, { signal: options?.signal });
588
599
  if (upload) {
589
600
  await file.upload(file.content, createdFile.uploadUrl, { signal: options?.signal });
@@ -600,6 +611,8 @@ class VaultFile {
600
611
  * @param params.config - The configuration for the VaultFile
601
612
  * @param params.contentType - The MIME type of the content (optional)
602
613
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
614
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
615
+ * @param params.onParentConflict - What to do if the file already exists as an active child of another file
603
616
  * @param options - The options for the request
604
617
  * @param options.signal - The signal to abort the request
605
618
  *
@@ -636,14 +649,23 @@ class VaultFile {
636
649
  * ```
637
650
  */
638
651
  static async fromStream(params, options) {
639
- const { contentLength, config: vaultConfig, contentType, parentId } = params;
652
+ const {
653
+ contentLength,
654
+ config: vaultConfig,
655
+ contentType,
656
+ parentId,
657
+ onMissingParent,
658
+ onParentConflict
659
+ } = params;
640
660
  const name = basename(params.name);
641
661
  const config = resolveConfig(vaultConfig);
642
662
  const file = new VaultFile({ config, name });
643
663
  await file._createFile({
644
664
  size: contentLength,
645
665
  mimeType: contentType || "application/octet-stream",
646
- parentId
666
+ parentId,
667
+ onMissingParent,
668
+ onParentConflict
647
669
  }, { signal: options?.signal });
648
670
  return file;
649
671
  }
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
1
  {
2
- "name": "@meistrari/vault-sdk",
3
- "version": "1.8.2",
4
- "license": "UNLICENSED",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/meistrari/vault.git"
8
- },
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs",
13
- "require": "./dist/index.cjs"
14
- }
15
- },
16
- "main": "dist/index.mjs",
17
- "types": "dist/index.d.ts",
18
- "files": [
19
- "dist"
20
- ],
21
- "scripts": {
22
- "test": "vitest --no-watch",
23
- "test:watch": "vitest",
24
- "build": "unbuild",
25
- "lint": "eslint .",
26
- "lint:fix": "eslint . --fix",
27
- "check": "bun run lint && bun tsc --noEmit"
28
- },
29
- "dependencies": {
30
- "@meistrari/vault-shared": "0.0.7",
31
- "@meistrari/file-type": "22.0.0",
32
- "mime-types": "3.0.1",
33
- "ofetch": "1.4.1",
34
- "zod": "3.23.8"
35
- },
36
- "devDependencies": {
37
- "@types/bun": "latest",
38
- "@types/mime-types": "3.0.1",
39
- "msw": "2.6.8",
40
- "unbuild": "2.0.0",
41
- "vitest": "2.1.9"
42
- },
43
- "peerDependencies": {
44
- "typescript": "^5.0.0"
45
- },
46
- "publishConfig": {
47
- "access": "public"
2
+ "name": "@meistrari/vault-sdk",
3
+ "version": "1.9.0",
4
+ "license": "UNLICENSED",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/meistrari/vault.git"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.cjs"
48
14
  }
49
- }
15
+ },
16
+ "main": "dist/index.mjs",
17
+ "types": "dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "scripts": {
22
+ "test": "vitest --no-watch",
23
+ "test:watch": "vitest",
24
+ "build": "unbuild",
25
+ "lint": "eslint .",
26
+ "lint:fix": "eslint . --fix",
27
+ "check": "bun run lint && bun tsc --noEmit"
28
+ },
29
+ "dependencies": {
30
+ "@meistrari/vault-shared": "0.0.7",
31
+ "@meistrari/file-type": "22.0.0",
32
+ "mime-types": "3.0.1",
33
+ "ofetch": "1.4.1",
34
+ "zod": "3.23.8"
35
+ },
36
+ "devDependencies": {
37
+ "@types/bun": "latest",
38
+ "@types/mime-types": "3.0.1",
39
+ "msw": "2.6.8",
40
+ "unbuild": "2.0.0",
41
+ "vitest": "2.1.9"
42
+ },
43
+ "peerDependencies": {
44
+ "typescript": "^5.0.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }