@sparkvault/sdk-js 8.11.3 → 8.11.4

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.
@@ -714,6 +714,24 @@ function base64urlEncode(data) {
714
714
  function arrayBufferToBase64url(buffer) {
715
715
  return base64urlEncode(new Uint8Array(buffer));
716
716
  }
717
+ /**
718
+ * Encode a string as STANDARD base64 (with padding) of its UTF-8 bytes.
719
+ *
720
+ * Unlike base64urlEncode this keeps `+`/`/` and padding, so it round-trips
721
+ * through a server-side standard-base64 decoder. Used to carry arbitrary
722
+ * Unicode through an HTTP header value (which is limited to latin1 bytes).
723
+ *
724
+ * @param value - String to encode
725
+ * @returns Standard base64 string
726
+ */
727
+ function base64EncodeUtf8(value) {
728
+ const bytes = new TextEncoder().encode(value);
729
+ let binary = '';
730
+ for (let i = 0; i < bytes.length; i++) {
731
+ binary += String.fromCharCode(bytes[i]);
732
+ }
733
+ return btoa(binary);
734
+ }
717
735
  /**
718
736
  * Decode base64url string to Uint8Array
719
737
  *
@@ -12308,6 +12326,14 @@ class VaultUploadModule {
12308
12326
  * operations live in their own modules; this module owns the vault record,
12309
12327
  * its sharing/upload configuration, and the browser upload widget.
12310
12328
  */
12329
+ /** A string every char of which fits in a single header byte (latin1). */
12330
+ function isLatin1(value) {
12331
+ for (let i = 0; i < value.length; i++) {
12332
+ if (value.charCodeAt(i) > 0xff)
12333
+ return false;
12334
+ }
12335
+ return true;
12336
+ }
12311
12337
  class VaultsModule {
12312
12338
  constructor(config, http) {
12313
12339
  this.http = http;
@@ -12449,9 +12475,12 @@ class VaultsModule {
12449
12475
  /**
12450
12476
  * Delete a vault and all its ingots. This action is irreversible!
12451
12477
  *
12452
- * Requires the vault's exact name as confirmation. It is sent as the
12453
- * `X-Confirm-Name` header and must match the vault name exactly
12454
- * (case-sensitive).
12478
+ * Requires the vault's exact name as confirmation, matched case-sensitively.
12479
+ * The name is sent base64(UTF-8) as the `X-Confirm-Name-B64` header so a vault
12480
+ * named with any Unicode (emoji, CJK, the U+202F in macOS-style names) is
12481
+ * deletable — an HTTP header value cannot carry non-latin1 characters. The
12482
+ * legacy raw `X-Confirm-Name` header is included only for latin1 names, so
12483
+ * older API servers keep working.
12455
12484
  *
12456
12485
  * @example
12457
12486
  * await sv.vaults.delete('vlt_abc', 'My Vault');
@@ -12461,9 +12490,13 @@ class VaultsModule {
12461
12490
  if (!name) {
12462
12491
  throw new ValidationError('Vault name is required to confirm deletion');
12463
12492
  }
12464
- await this.http.delete(`/v1/vaults/${cleanId}`, {
12465
- headers: { 'X-Confirm-Name': name },
12466
- });
12493
+ const headers = {
12494
+ 'X-Confirm-Name-B64': base64EncodeUtf8(name),
12495
+ };
12496
+ if (isLatin1(name)) {
12497
+ headers['X-Confirm-Name'] = name;
12498
+ }
12499
+ await this.http.delete(`/v1/vaults/${cleanId}`, { headers });
12467
12500
  }
12468
12501
  /**
12469
12502
  * Get a vault's public-sharing configuration.