@meistrari/vault-sdk 1.8.2 → 1.8.3

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.8.3";
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,7 @@ 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
416
420
  * @param options - The options for the request
417
421
  * @param options.signal - The signal to abort the request
418
422
  *
@@ -428,6 +432,7 @@ class VaultFile {
428
432
  size: metadata.size,
429
433
  mimeType: metadata.mimeType,
430
434
  parentId: metadata.parentId,
435
+ onMissingParent: metadata.onMissingParent,
431
436
  fileName: this.name,
432
437
  sha256sum: this.id ?? this.metadata?.id ?? (this.content ? await getFileHash(this.content) : void 0)
433
438
  }),
@@ -518,6 +523,7 @@ class VaultFile {
518
523
  * @param params.mimeType - The MIME type of the file (optional)
519
524
  * @param params.upload - Whether to upload the file (default: false)
520
525
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
526
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
521
527
  * @param options - The options for the request
522
528
  * @param options.signal - The signal to abort the request
523
529
  *
@@ -570,7 +576,7 @@ class VaultFile {
570
576
  * ```
571
577
  */
572
578
  static async fromContent(params, options) {
573
- const { content, config: vaultConfig, upload = false, parentId } = params;
579
+ const { content, config: vaultConfig, upload = false, parentId, onMissingParent } = params;
574
580
  const name = basename(params.name) ?? getFileName(content);
575
581
  const config = resolveConfig(vaultConfig);
576
582
  const { vaultUrl, authStrategy } = config;
@@ -589,7 +595,8 @@ class VaultFile {
589
595
  const createdFile = await file._createFile({
590
596
  size,
591
597
  mimeType,
592
- parentId
598
+ parentId,
599
+ onMissingParent
593
600
  }, { signal: options?.signal });
594
601
  if (upload) {
595
602
  await file.upload(file.content, createdFile.uploadUrl, { signal: options?.signal });
@@ -606,6 +613,7 @@ class VaultFile {
606
613
  * @param params.config - The configuration for the VaultFile
607
614
  * @param params.contentType - The MIME type of the content (optional)
608
615
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
616
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
609
617
  * @param options - The options for the request
610
618
  * @param options.signal - The signal to abort the request
611
619
  *
@@ -642,14 +650,15 @@ class VaultFile {
642
650
  * ```
643
651
  */
644
652
  static async fromStream(params, options) {
645
- const { contentLength, config: vaultConfig, contentType, parentId } = params;
653
+ const { contentLength, config: vaultConfig, contentType, parentId, onMissingParent } = params;
646
654
  const name = basename(params.name);
647
655
  const config = resolveConfig(vaultConfig);
648
656
  const file = new VaultFile({ config, name });
649
657
  await file._createFile({
650
658
  size: contentLength,
651
659
  mimeType: contentType || "application/octet-stream",
652
- parentId
660
+ parentId,
661
+ onMissingParent
653
662
  }, { signal: options?.signal });
654
663
  return file;
655
664
  }
package/dist/index.d.cts CHANGED
@@ -87,6 +87,7 @@ type VaultFileParams = {
87
87
  metadata?: FileMetadata | null;
88
88
  config: VaultConfig;
89
89
  };
90
+ type OnMissingParent = 'error' | 'create-as-root';
90
91
  /**
91
92
  * Represents a file in the vault and allows interacting with it.
92
93
  *
@@ -152,6 +153,7 @@ declare class VaultFile {
152
153
  * @param metadata.size - The size of the file
153
154
  * @param metadata.mimeType - The mime type of the file
154
155
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
156
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
155
157
  * @param options - The options for the request
156
158
  * @param options.signal - The signal to abort the request
157
159
  *
@@ -216,6 +218,7 @@ declare class VaultFile {
216
218
  * @param params.mimeType - The MIME type of the file (optional)
217
219
  * @param params.upload - Whether to upload the file (default: false)
218
220
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
221
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
219
222
  * @param options - The options for the request
220
223
  * @param options.signal - The signal to abort the request
221
224
  *
@@ -274,6 +277,7 @@ declare class VaultFile {
274
277
  mimeType?: string;
275
278
  upload?: boolean;
276
279
  parentId?: string;
280
+ onMissingParent?: OnMissingParent;
277
281
  }, options?: {
278
282
  signal?: AbortSignal;
279
283
  }): Promise<VaultFile>;
@@ -287,6 +291,7 @@ declare class VaultFile {
287
291
  * @param params.config - The configuration for the VaultFile
288
292
  * @param params.contentType - The MIME type of the content (optional)
289
293
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
294
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
290
295
  * @param options - The options for the request
291
296
  * @param options.signal - The signal to abort the request
292
297
  *
@@ -328,6 +333,7 @@ declare class VaultFile {
328
333
  config: VaultConfig;
329
334
  contentType?: string;
330
335
  parentId?: string;
336
+ onMissingParent?: OnMissingParent;
331
337
  }, options?: {
332
338
  signal?: AbortSignal;
333
339
  }): Promise<VaultFile>;
package/dist/index.d.mts CHANGED
@@ -87,6 +87,7 @@ type VaultFileParams = {
87
87
  metadata?: FileMetadata | null;
88
88
  config: VaultConfig;
89
89
  };
90
+ type OnMissingParent = 'error' | 'create-as-root';
90
91
  /**
91
92
  * Represents a file in the vault and allows interacting with it.
92
93
  *
@@ -152,6 +153,7 @@ declare class VaultFile {
152
153
  * @param metadata.size - The size of the file
153
154
  * @param metadata.mimeType - The mime type of the file
154
155
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
156
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
155
157
  * @param options - The options for the request
156
158
  * @param options.signal - The signal to abort the request
157
159
  *
@@ -216,6 +218,7 @@ declare class VaultFile {
216
218
  * @param params.mimeType - The MIME type of the file (optional)
217
219
  * @param params.upload - Whether to upload the file (default: false)
218
220
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
221
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
219
222
  * @param options - The options for the request
220
223
  * @param options.signal - The signal to abort the request
221
224
  *
@@ -274,6 +277,7 @@ declare class VaultFile {
274
277
  mimeType?: string;
275
278
  upload?: boolean;
276
279
  parentId?: string;
280
+ onMissingParent?: OnMissingParent;
277
281
  }, options?: {
278
282
  signal?: AbortSignal;
279
283
  }): Promise<VaultFile>;
@@ -287,6 +291,7 @@ declare class VaultFile {
287
291
  * @param params.config - The configuration for the VaultFile
288
292
  * @param params.contentType - The MIME type of the content (optional)
289
293
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
294
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
290
295
  * @param options - The options for the request
291
296
  * @param options.signal - The signal to abort the request
292
297
  *
@@ -328,6 +333,7 @@ declare class VaultFile {
328
333
  config: VaultConfig;
329
334
  contentType?: string;
330
335
  parentId?: string;
336
+ onMissingParent?: OnMissingParent;
331
337
  }, options?: {
332
338
  signal?: AbortSignal;
333
339
  }): Promise<VaultFile>;
package/dist/index.d.ts CHANGED
@@ -87,6 +87,7 @@ type VaultFileParams = {
87
87
  metadata?: FileMetadata | null;
88
88
  config: VaultConfig;
89
89
  };
90
+ type OnMissingParent = 'error' | 'create-as-root';
90
91
  /**
91
92
  * Represents a file in the vault and allows interacting with it.
92
93
  *
@@ -152,6 +153,7 @@ declare class VaultFile {
152
153
  * @param metadata.size - The size of the file
153
154
  * @param metadata.mimeType - The mime type of the file
154
155
  * @param metadata.parentId - The ID of the parent file for hierarchical file relationships
156
+ * @param metadata.onMissingParent - What to do if the parent file does not exist or has been deleted
155
157
  * @param options - The options for the request
156
158
  * @param options.signal - The signal to abort the request
157
159
  *
@@ -216,6 +218,7 @@ declare class VaultFile {
216
218
  * @param params.mimeType - The MIME type of the file (optional)
217
219
  * @param params.upload - Whether to upload the file (default: false)
218
220
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
221
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
219
222
  * @param options - The options for the request
220
223
  * @param options.signal - The signal to abort the request
221
224
  *
@@ -274,6 +277,7 @@ declare class VaultFile {
274
277
  mimeType?: string;
275
278
  upload?: boolean;
276
279
  parentId?: string;
280
+ onMissingParent?: OnMissingParent;
277
281
  }, options?: {
278
282
  signal?: AbortSignal;
279
283
  }): Promise<VaultFile>;
@@ -287,6 +291,7 @@ declare class VaultFile {
287
291
  * @param params.config - The configuration for the VaultFile
288
292
  * @param params.contentType - The MIME type of the content (optional)
289
293
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
294
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
290
295
  * @param options - The options for the request
291
296
  * @param options.signal - The signal to abort the request
292
297
  *
@@ -328,6 +333,7 @@ declare class VaultFile {
328
333
  config: VaultConfig;
329
334
  contentType?: string;
330
335
  parentId?: string;
336
+ onMissingParent?: OnMissingParent;
331
337
  }, options?: {
332
338
  signal?: AbortSignal;
333
339
  }): 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.8.3";
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,7 @@ 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
410
414
  * @param options - The options for the request
411
415
  * @param options.signal - The signal to abort the request
412
416
  *
@@ -422,6 +426,7 @@ class VaultFile {
422
426
  size: metadata.size,
423
427
  mimeType: metadata.mimeType,
424
428
  parentId: metadata.parentId,
429
+ onMissingParent: metadata.onMissingParent,
425
430
  fileName: this.name,
426
431
  sha256sum: this.id ?? this.metadata?.id ?? (this.content ? await getFileHash(this.content) : void 0)
427
432
  }),
@@ -512,6 +517,7 @@ class VaultFile {
512
517
  * @param params.mimeType - The MIME type of the file (optional)
513
518
  * @param params.upload - Whether to upload the file (default: false)
514
519
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
520
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
515
521
  * @param options - The options for the request
516
522
  * @param options.signal - The signal to abort the request
517
523
  *
@@ -564,7 +570,7 @@ class VaultFile {
564
570
  * ```
565
571
  */
566
572
  static async fromContent(params, options) {
567
- const { content, config: vaultConfig, upload = false, parentId } = params;
573
+ const { content, config: vaultConfig, upload = false, parentId, onMissingParent } = params;
568
574
  const name = basename(params.name) ?? getFileName(content);
569
575
  const config = resolveConfig(vaultConfig);
570
576
  const { vaultUrl, authStrategy } = config;
@@ -583,7 +589,8 @@ class VaultFile {
583
589
  const createdFile = await file._createFile({
584
590
  size,
585
591
  mimeType,
586
- parentId
592
+ parentId,
593
+ onMissingParent
587
594
  }, { signal: options?.signal });
588
595
  if (upload) {
589
596
  await file.upload(file.content, createdFile.uploadUrl, { signal: options?.signal });
@@ -600,6 +607,7 @@ class VaultFile {
600
607
  * @param params.config - The configuration for the VaultFile
601
608
  * @param params.contentType - The MIME type of the content (optional)
602
609
  * @param params.parentId - The ID of the parent file for hierarchical file relationships
610
+ * @param params.onMissingParent - What to do if the parent file does not exist or has been deleted
603
611
  * @param options - The options for the request
604
612
  * @param options.signal - The signal to abort the request
605
613
  *
@@ -636,14 +644,15 @@ class VaultFile {
636
644
  * ```
637
645
  */
638
646
  static async fromStream(params, options) {
639
- const { contentLength, config: vaultConfig, contentType, parentId } = params;
647
+ const { contentLength, config: vaultConfig, contentType, parentId, onMissingParent } = params;
640
648
  const name = basename(params.name);
641
649
  const config = resolveConfig(vaultConfig);
642
650
  const file = new VaultFile({ config, name });
643
651
  await file._createFile({
644
652
  size: contentLength,
645
653
  mimeType: contentType || "application/octet-stream",
646
- parentId
654
+ parentId,
655
+ onMissingParent
647
656
  }, { signal: options?.signal });
648
657
  return file;
649
658
  }
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.8.3",
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
+ }