@haex-space/vault-sdk 4.8.1 → 4.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/dist/node.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { H as HaextensionConfig, g as getExtensionDir, r as readHaextensionConfig } from './config-P_6DqTHl.mjs';
2
- import { a as ExtensionManifest } from './types-3iifP-Q1.mjs';
2
+ import { a as ExtensionManifest } from './types-BZVkX0Wf.mjs';
3
3
 
4
4
  interface ReadManifestOptions {
5
5
  /** Root directory of the project */
package/dist/node.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { H as HaextensionConfig, g as getExtensionDir, r as readHaextensionConfig } from './config-P_6DqTHl.js';
2
- import { a as ExtensionManifest } from './types-3iifP-Q1.js';
2
+ import { a as ExtensionManifest } from './types-BZVkX0Wf.js';
3
3
 
4
4
  interface ReadManifestOptions {
5
5
  /** Root directory of the project */
package/dist/react.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StorageAPI } from './client-DOAj36ga.mjs';
1
+ import { S as StorageAPI } from './client-CS0AdXto.mjs';
2
2
  import { HaexVaultSdk } from './index.mjs';
3
3
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
4
4
  import { HaexHubConfig, ExtensionInfo, ApplicationContext } from './index.mjs';
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StorageAPI } from './client-CNbwFQjB.js';
1
+ import { S as StorageAPI } from './client-BzgCo_Ch.js';
2
2
  import { HaexVaultSdk } from './index.js';
3
3
  import * as drizzle_orm_sqlite_proxy from 'drizzle-orm/sqlite-proxy';
4
4
  import { HaexHubConfig, ExtensionInfo, ApplicationContext } from './index.js';
package/dist/react.js CHANGED
@@ -459,6 +459,18 @@ var MODEL_JOB_EVENTS = {
459
459
  /** A job of this frame ended: completed, failed or cancelled. */
460
460
  COMPLETED: "haextension:model-job:completed"
461
461
  };
462
+ var PEERS_EVENTS = {
463
+ /** The outcome of an invitation, once per invitation (inviting side). */
464
+ INVITE_STATUS: "peers:invite-status",
465
+ /** A channel opened after the user accepted an invitation in holzi's prompt (invited side). */
466
+ CHANNEL_OPENED: "peers:channel-opened",
467
+ /** A device joined one of this device's lobbies by code (host). */
468
+ JOINED: "peers:joined",
469
+ /** A message on a channel; `data` is Base64 on the bridge. */
470
+ MESSAGE: "peers:message",
471
+ /** A channel ended: closed, lost or timed out. */
472
+ CHANNEL_CLOSED: "peers:channel-closed"
473
+ };
462
474
  var EXTERNAL_EVENTS = {
463
475
  /** External request from authorized client */
464
476
  REQUEST: "haextension:external:request",
@@ -796,6 +808,27 @@ var MODEL_COMMANDS = {
796
808
  cancel: "extension_model_job_cancel"
797
809
  };
798
810
 
811
+ // src/commands/peers.ts
812
+ init_cjs_shims();
813
+ var PEER_COMMANDS = {
814
+ /** Invites a contact; the outcome follows as `peers:invite-status` */
815
+ invite: "extension_peers_invite",
816
+ /** Withdraws an open invitation on all devices of the contact */
817
+ inviteCancel: "extension_peers_invite_cancel",
818
+ /** Opens a lobby and returns its join code */
819
+ lobbyOpen: "extension_peers_lobby_open",
820
+ /** Closes a lobby; its code stops working, its channels stay open */
821
+ lobbyClose: "extension_peers_lobby_close",
822
+ /** Joins a lobby by its code; waits at most 15 s for the host */
823
+ join: "extension_peers_join",
824
+ /** Closes a channel of an own lobby and keeps the device out of that lobby */
825
+ remove: "extension_peers_remove",
826
+ /** Sends a fast or a reliable message over a channel */
827
+ send: "extension_peers_send",
828
+ /** Closes a channel on both sides */
829
+ close: "extension_peers_close"
830
+ };
831
+
799
832
  // src/commands/mail.ts
800
833
  init_cjs_shims();
801
834
  var MAIL_COMMANDS = {
@@ -2091,6 +2124,158 @@ var ModelsAPI = class {
2091
2124
  }
2092
2125
  };
2093
2126
 
2127
+ // src/api/peers.ts
2128
+ init_cjs_shims();
2129
+ init_vaultKey();
2130
+ var PEER_ERROR_KINDS = {
2131
+ contact_unknown: "PEER_CONTACT_UNKNOWN",
2132
+ invite_not_open: "PEER_INVITE_UNKNOWN",
2133
+ channel_unknown: "PEER_CHANNEL_CLOSED",
2134
+ channel_closed: "PEER_CHANNEL_CLOSED",
2135
+ too_large: "PEER_PAYLOAD_TOO_LARGE",
2136
+ lobby_closed: "PEER_LOBBY_CLOSED",
2137
+ not_admitted: "PEER_NOT_ALLOWED",
2138
+ limit: "PEER_LIMIT",
2139
+ network_unavailable: "PEER_NETWORK_UNAVAILABLE",
2140
+ invalid_input: "PEER_INVALID_INPUT"
2141
+ };
2142
+ var PeerError = class extends Error {
2143
+ constructor(code, reason, message, details = {}, options) {
2144
+ super(message, options);
2145
+ this.code = code;
2146
+ this.reason = reason;
2147
+ this.details = details;
2148
+ this.name = "PeerError";
2149
+ this.kind = PEER_ERROR_KINDS[reason];
2150
+ if (typeof details.limit === "number") this.limit = details.limit;
2151
+ }
2152
+ };
2153
+ function isPeerErrorReason(value) {
2154
+ return typeof value === "string" && Object.hasOwn(PEER_ERROR_KINDS, value);
2155
+ }
2156
+ function toPeerError(error) {
2157
+ if (typeof error !== "object" || error === null) return error;
2158
+ const { code, message, details } = error;
2159
+ if (typeof code !== "number" || typeof details !== "object" || details === null) return error;
2160
+ const reason = details.reason;
2161
+ if (!isPeerErrorReason(reason)) return error;
2162
+ return new PeerError(
2163
+ code,
2164
+ reason,
2165
+ typeof message === "string" ? message : reason,
2166
+ details,
2167
+ { cause: error }
2168
+ );
2169
+ }
2170
+ var EVENT_NAMES = {
2171
+ "invite-status": PEERS_EVENTS.INVITE_STATUS,
2172
+ "channel-opened": PEERS_EVENTS.CHANNEL_OPENED,
2173
+ joined: PEERS_EVENTS.JOINED,
2174
+ message: PEERS_EVENTS.MESSAGE,
2175
+ "channel-closed": PEERS_EVENTS.CHANNEL_CLOSED
2176
+ };
2177
+ function decodeEvent(type, data) {
2178
+ if (typeof data !== "object" || data === null) return void 0;
2179
+ if (type !== "message") return data;
2180
+ const message = data;
2181
+ if (typeof message.channelId !== "string" || typeof message.data !== "string") return void 0;
2182
+ let decoded;
2183
+ try {
2184
+ decoded = base64ToArrayBuffer(message.data);
2185
+ } catch {
2186
+ return void 0;
2187
+ }
2188
+ if (arrayBufferToBase64(decoded) !== message.data) return void 0;
2189
+ return {
2190
+ channelId: message.channelId,
2191
+ data: decoded,
2192
+ reliable: message.reliable === true
2193
+ };
2194
+ }
2195
+ var PeersAPI = class {
2196
+ constructor(client) {
2197
+ this.client = client;
2198
+ /** Largest fast message (`reliable: false`) in bytes. */
2199
+ this.MAX_FAST_BYTES = 1024;
2200
+ /** Largest reliable message in bytes. */
2201
+ this.MAX_RELIABLE_BYTES = 65536;
2202
+ /** Largest `payload` of an invitation or a join, as JSON, in bytes. */
2203
+ this.MAX_PAYLOAD_BYTES = 4096;
2204
+ }
2205
+ async call(method, params) {
2206
+ try {
2207
+ return await this.client.request(method, params);
2208
+ } catch (error) {
2209
+ throw toPeerError(error);
2210
+ }
2211
+ }
2212
+ /** Invites a contact; the outcome follows as `invite-status` with this `inviteId`. */
2213
+ async inviteAsync(contactId, payload) {
2214
+ const answer = await this.call(PEER_COMMANDS.invite, { contactId, payload });
2215
+ return { inviteId: answer.inviteId };
2216
+ }
2217
+ /** Withdraws an open invitation on all devices of the contact; no `invite-status` follows. */
2218
+ async cancelInviteAsync(inviteId) {
2219
+ await this.call(PEER_COMMANDS.inviteCancel, { inviteId });
2220
+ }
2221
+ /**
2222
+ * Opens a lobby; `lobbyId` is 1–64 characters of `[A-Za-z0-9._-]`. The join code is opaque:
2223
+ * hand it on as it is.
2224
+ */
2225
+ async openLobbyAsync(lobbyId, visibility) {
2226
+ const answer = await this.call(PEER_COMMANDS.lobbyOpen, { lobbyId, visibility });
2227
+ return { joinCode: answer.joinCode };
2228
+ }
2229
+ /** Closes a lobby: its code stops working, its channels stay open. An unknown lobby is fine. */
2230
+ async closeLobbyAsync(lobbyId) {
2231
+ await this.call(PEER_COMMANDS.lobbyClose, { lobbyId });
2232
+ }
2233
+ /**
2234
+ * Joins a lobby by its code with a self-chosen `displayName` (1–64 characters). The host
2235
+ * answers within 15 s; a lobby that cannot be joined for any reason rejects as `lobby_closed`.
2236
+ */
2237
+ async joinAsync(joinCode, displayName, payload) {
2238
+ const answer = await this.call(PEER_COMMANDS.join, {
2239
+ joinCode,
2240
+ displayName,
2241
+ payload
2242
+ });
2243
+ return { channelId: answer.channelId, lobbyId: answer.lobbyId };
2244
+ }
2245
+ /** Closes a channel of an own lobby and keeps that device (and vault) out of the lobby. */
2246
+ async removeAsync(channelId) {
2247
+ await this.call(PEER_COMMANDS.remove, { channelId });
2248
+ }
2249
+ /**
2250
+ * Sends bytes over a channel: fast (default, at most {@link MAX_FAST_BYTES}, may be lost) or
2251
+ * `reliable` (at most {@link MAX_RELIABLE_BYTES}, in order; 16 may wait per channel).
2252
+ */
2253
+ async sendAsync(channelId, data, options = {}) {
2254
+ await this.call(PEER_COMMANDS.send, {
2255
+ channelId,
2256
+ data: { $bytes: arrayBufferToBase64(data) },
2257
+ reliable: options.reliable ?? false
2258
+ });
2259
+ }
2260
+ /** Closes a channel; both sides get `channel-closed` with `reason: "closed"`. */
2261
+ async closeAsync(channelId) {
2262
+ await this.call(PEER_COMMANDS.close, { channelId });
2263
+ }
2264
+ /**
2265
+ * Listens for one of the peers events (`invite-status`, `channel-opened`, `joined`, `message`,
2266
+ * `channel-closed`); `message.data` arrives as bytes. Returns an unsubscribe function.
2267
+ */
2268
+ on(type, handler) {
2269
+ const name = EVENT_NAMES[type];
2270
+ const wrapped = (event) => {
2271
+ const decoded = decodeEvent(type, event.data);
2272
+ if (decoded) handler(decoded);
2273
+ };
2274
+ this.client.on(name, wrapped);
2275
+ return () => this.client.off(name, wrapped);
2276
+ }
2277
+ };
2278
+
2094
2279
  // src/api/mail.ts
2095
2280
  init_cjs_shims();
2096
2281
  var MailAPI = class {
@@ -3208,6 +3393,7 @@ var HaexVaultSdk = class {
3208
3393
  this.passwords = new PasswordsAPI(this);
3209
3394
  this.contacts = new ContactsAPI(this);
3210
3395
  this.models = new ModelsAPI(this);
3396
+ this.peers = new PeersAPI(this);
3211
3397
  this.mail = new MailAPI(this);
3212
3398
  this.notifications = new NotificationsAPI(this);
3213
3399
  this.tab = new TabAPI(this);