@haex-space/vault-sdk 2.5.111 → 2.5.113

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.js CHANGED
@@ -676,6 +676,22 @@ var LOCALSEND_COMMANDS = {
676
676
  cancelSend: "localsend_cancel_send"
677
677
  };
678
678
 
679
+ // src/commands/spaces.ts
680
+ var SPACE_COMMANDS = {
681
+ /** Bulk assign rows to spaces */
682
+ assign: "extension_space_assign",
683
+ /** Bulk unassign rows from spaces */
684
+ unassign: "extension_space_unassign",
685
+ /** Get space assignments for a table */
686
+ getAssignments: "extension_space_get_assignments",
687
+ /** List all spaces the user is a member of (with decrypted names) */
688
+ list: "extension_space_list",
689
+ /** Create a new shared space */
690
+ create: "extension_space_create",
691
+ /** List available sync backends */
692
+ listBackends: "extension_space_list_backends"
693
+ };
694
+
679
695
  // src/commands/index.ts
680
696
  var TAURI_COMMANDS = {
681
697
  database: DATABASE_COMMANDS,
@@ -686,7 +702,8 @@ var TAURI_COMMANDS = {
686
702
  externalBridge: EXTERNAL_BRIDGE_COMMANDS,
687
703
  extension: EXTENSION_COMMANDS,
688
704
  remoteStorage: REMOTE_STORAGE_COMMANDS,
689
- localsend: LOCALSEND_COMMANDS
705
+ localsend: LOCALSEND_COMMANDS,
706
+ spaces: SPACE_COMMANDS
690
707
  };
691
708
 
692
709
  // src/api/storage.ts
@@ -1688,6 +1705,112 @@ var LocalSendAPI = class {
1688
1705
  }
1689
1706
  };
1690
1707
 
1708
+ // src/api/spaces.ts
1709
+ var SpacesAPI = class {
1710
+ constructor(client) {
1711
+ this.client = client;
1712
+ }
1713
+ /**
1714
+ * Bulk assign rows to spaces.
1715
+ * @param assignments - Array of row-to-space mappings
1716
+ * @returns Number of assignments created
1717
+ */
1718
+ async assignAsync(assignments) {
1719
+ return this.client.request(SPACE_COMMANDS.assign, {
1720
+ assignments: assignments.map(toSnakeCase)
1721
+ });
1722
+ }
1723
+ /**
1724
+ * Bulk unassign rows from spaces.
1725
+ * @param assignments - Array of row-to-space mappings to remove
1726
+ * @returns Number of assignments removed
1727
+ */
1728
+ async unassignAsync(assignments) {
1729
+ return this.client.request(SPACE_COMMANDS.unassign, {
1730
+ assignments: assignments.map(toSnakeCase)
1731
+ });
1732
+ }
1733
+ /**
1734
+ * Get space assignments for a table, optionally filtered by row.
1735
+ * @param tableName - The table to query assignments for
1736
+ * @param rowPks - Optional row primary key(s) to filter by
1737
+ * @returns Array of space assignments
1738
+ */
1739
+ async getAssignmentsAsync(tableName, rowPks) {
1740
+ const result = await this.client.request(
1741
+ SPACE_COMMANDS.getAssignments,
1742
+ {
1743
+ table_name: tableName,
1744
+ row_pks: rowPks
1745
+ }
1746
+ );
1747
+ return result.map(fromSnakeCase);
1748
+ }
1749
+ /**
1750
+ * Convenience method to assign a single row to a space.
1751
+ * @param tableName - The table name
1752
+ * @param rowPks - The row primary key(s)
1753
+ * @param spaceId - The space ID to assign to
1754
+ * @returns Number of assignments created (0 or 1)
1755
+ */
1756
+ async assignRowAsync(tableName, rowPks, spaceId) {
1757
+ return this.assignAsync([{ tableName, rowPks, spaceId }]);
1758
+ }
1759
+ /**
1760
+ * Convenience method to unassign a single row from a space.
1761
+ * @param tableName - The table name
1762
+ * @param rowPks - The row primary key(s)
1763
+ * @param spaceId - The space ID to unassign from
1764
+ * @returns Number of assignments removed (0 or 1)
1765
+ */
1766
+ async unassignRowAsync(tableName, rowPks, spaceId) {
1767
+ return this.unassignAsync([{ tableName, rowPks, spaceId }]);
1768
+ }
1769
+ // ==========================================================================
1770
+ // Space Management
1771
+ // ==========================================================================
1772
+ /**
1773
+ * List all shared spaces the user is a member of.
1774
+ * Returns spaces with decrypted names (decryption happens vault-side).
1775
+ */
1776
+ async listSpacesAsync() {
1777
+ return this.client.request(SPACE_COMMANDS.list);
1778
+ }
1779
+ /**
1780
+ * Create a new shared space.
1781
+ * @param name - Human-readable space name
1782
+ * @param serverUrl - The sync server URL to create the space on
1783
+ * @returns The created space with decrypted name
1784
+ */
1785
+ async createSpaceAsync(name, serverUrl) {
1786
+ return this.client.request(SPACE_COMMANDS.create, {
1787
+ name,
1788
+ server_url: serverUrl
1789
+ });
1790
+ }
1791
+ /**
1792
+ * List available sync backends that can host shared spaces.
1793
+ * @returns Array of backend info with server URLs
1794
+ */
1795
+ async listSyncBackendsAsync() {
1796
+ return this.client.request(SPACE_COMMANDS.listBackends);
1797
+ }
1798
+ };
1799
+ function toSnakeCase(assignment) {
1800
+ return {
1801
+ table_name: assignment.tableName,
1802
+ row_pks: assignment.rowPks,
1803
+ space_id: assignment.spaceId
1804
+ };
1805
+ }
1806
+ function fromSnakeCase(assignment) {
1807
+ return {
1808
+ tableName: assignment.table_name,
1809
+ rowPks: assignment.row_pks,
1810
+ spaceId: assignment.space_id
1811
+ };
1812
+ }
1813
+
1691
1814
  // src/client/tableName.ts
1692
1815
  function validatePublicKey(publicKey) {
1693
1816
  if (!publicKey || typeof publicKey !== "string" || publicKey.trim() === "") {
@@ -2312,6 +2435,7 @@ var HaexVaultSdk = class {
2312
2435
  this.permissions = new PermissionsAPI(this);
2313
2436
  this.remoteStorage = new RemoteStorageAPI(this);
2314
2437
  this.localsend = new LocalSendAPI(this);
2438
+ this.spaces = new SpacesAPI(this);
2315
2439
  installConsoleForwarding(this.config.debug);
2316
2440
  this.readyPromise = new Promise((resolve) => {
2317
2441
  this.resolveReady = resolve;
@@ -2861,6 +2985,27 @@ async function decryptSpaceKeyAsync(encrypted, ownPrivateKeyBase64) {
2861
2985
  );
2862
2986
  return new Uint8Array(decrypted);
2863
2987
  }
2988
+ async function encryptSpaceNameAsync(spaceKey, spaceName) {
2989
+ const cryptoKey = await crypto.subtle.importKey(
2990
+ "raw",
2991
+ new Uint8Array(spaceKey).buffer,
2992
+ { name: "AES-GCM" },
2993
+ false,
2994
+ ["encrypt"]
2995
+ );
2996
+ const { encryptedData, nonce } = await encryptString(spaceName, cryptoKey);
2997
+ return { encryptedName: encryptedData, nameNonce: nonce };
2998
+ }
2999
+ async function decryptSpaceNameAsync(spaceKey, encryptedName, nameNonce) {
3000
+ const cryptoKey = await crypto.subtle.importKey(
3001
+ "raw",
3002
+ new Uint8Array(spaceKey).buffer,
3003
+ { name: "AES-GCM" },
3004
+ false,
3005
+ ["decrypt"]
3006
+ );
3007
+ return decryptString(encryptedName, nameNonce, cryptoKey);
3008
+ }
2864
3009
 
2865
3010
  // src/crypto/recordSigning.ts
2866
3011
  function canonicalize(record) {
@@ -3114,6 +3259,7 @@ exports.PermissionStatus = PermissionStatus;
3114
3259
  exports.PermissionsAPI = PermissionsAPI;
3115
3260
  exports.RemoteStorageAPI = RemoteStorageAPI;
3116
3261
  exports.SIGNING_ALGO = SIGNING_ALGO;
3262
+ exports.SpacesAPI = SpacesAPI;
3117
3263
  exports.TABLE_SEPARATOR = TABLE_SEPARATOR;
3118
3264
  exports.TAURI_COMMANDS = TAURI_COMMANDS;
3119
3265
  exports.WebAPI = WebAPI;
@@ -3124,6 +3270,7 @@ exports.createHaexVaultSdk = createHaexVaultSdk;
3124
3270
  exports.decryptCrdtData = decryptCrdtData;
3125
3271
  exports.decryptPrivateKeyAsync = decryptPrivateKeyAsync;
3126
3272
  exports.decryptSpaceKeyAsync = decryptSpaceKeyAsync;
3273
+ exports.decryptSpaceNameAsync = decryptSpaceNameAsync;
3127
3274
  exports.decryptString = decryptString;
3128
3275
  exports.decryptVaultKey = decryptVaultKey;
3129
3276
  exports.decryptVaultName = decryptVaultName;
@@ -3131,6 +3278,7 @@ exports.deriveKeyFromPassword = deriveKeyFromPassword;
3131
3278
  exports.encryptCrdtData = encryptCrdtData;
3132
3279
  exports.encryptPrivateKeyAsync = encryptPrivateKeyAsync;
3133
3280
  exports.encryptSpaceKeyForRecipientAsync = encryptSpaceKeyForRecipientAsync;
3281
+ exports.encryptSpaceNameAsync = encryptSpaceNameAsync;
3134
3282
  exports.encryptString = encryptString;
3135
3283
  exports.encryptVaultKey = encryptVaultKey;
3136
3284
  exports.exportKeyPairAsync = exportKeyPairAsync;