@haex-space/vault-sdk 4.6.0 → 4.7.1

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.mjs CHANGED
@@ -1217,6 +1217,12 @@ var MAIL_COMMANDS = {
1217
1217
  fetchMessage: "extension_mail_fetch_message",
1218
1218
  /** Fetch a single attachment's bytes (base64) by part index */
1219
1219
  fetchAttachment: "extension_mail_fetch_attachment",
1220
+ /** Search a mailbox on the server by criteria; answers UIDs, newest first */
1221
+ search: "extension_mail_search",
1222
+ /** CREATE a mailbox (reports whether it was already there) */
1223
+ createMailbox: "extension_mail_create_mailbox",
1224
+ /** Delete messages for good: `\Deleted` plus UID EXPUNGE of exactly those UIDs */
1225
+ deleteMessages: "extension_mail_delete_messages",
1220
1226
  /** Set or unset IMAP flags on a UID set */
1221
1227
  setFlags: "extension_mail_set_flags",
1222
1228
  /** MOVE messages between mailboxes (COPY+EXPUNGE fallback) */
@@ -2548,6 +2554,45 @@ var MailAPI = class {
2548
2554
  partIndex
2549
2555
  });
2550
2556
  }
2557
+ /**
2558
+ * Search a whole mailbox on the server. Answers the UIDs of the newest `limit` hits (1 to 1000;
2559
+ * all that fit one answer when omitted), newest first, and the number of all hits. Fetch their
2560
+ * envelopes with `fetchEnvelopesAsync` and a `uidList` range.
2561
+ */
2562
+ async searchMessagesAsync(imap, mailbox, criteria, limit) {
2563
+ return this.client.request(MAIL_COMMANDS.search, {
2564
+ imap,
2565
+ mailbox,
2566
+ criteria,
2567
+ limit
2568
+ });
2569
+ }
2570
+ /**
2571
+ * Create a mailbox. Resolves to `false`, not an error, when it already existed. The name may
2572
+ * contain the server's hierarchy delimiter; `*` and `%` are not allowed.
2573
+ */
2574
+ async createMailboxAsync(imap, mailbox) {
2575
+ const { created } = await this.client.request(
2576
+ MAIL_COMMANDS.createMailbox,
2577
+ { imap, mailbox }
2578
+ );
2579
+ return created;
2580
+ }
2581
+ /**
2582
+ * Delete messages for good: flags exactly these UIDs `\Deleted` and expunges exactly them, so
2583
+ * other messages marked `\Deleted` stay. Refused with an error on a server without UIDPLUS,
2584
+ * before anything is marked. If the expunge fails after marking, the messages stay in the
2585
+ * mailbox flagged `\Deleted` and the call rejects; do not show them as deleted. At most 1000 UIDs
2586
+ * per call. For a message that can still be recovered, use `moveMessagesAsync` into the trash
2587
+ * instead.
2588
+ */
2589
+ async deleteMessagesAsync(imap, mailbox, uids) {
2590
+ return this.client.request(MAIL_COMMANDS.deleteMessages, {
2591
+ imap,
2592
+ mailbox,
2593
+ uids
2594
+ });
2595
+ }
2551
2596
  /**
2552
2597
  * Set or unset IMAP flags. Use `flags=["\\Seen"]` + `add=true` to
2553
2598
  * mark messages as read; `add=false` removes the flag(s).
@@ -3486,6 +3531,11 @@ var PermissionWaiterRegistry = class {
3486
3531
  for (const callback of [...set]) callback(decision);
3487
3532
  }
3488
3533
  };
3534
+ function promptedKey(error) {
3535
+ const details = error.details ?? {};
3536
+ const field = (name) => typeof details[name] === "string" ? details[name] : error[name];
3537
+ return permissionKey(field("resourceType"), field("action"), field("target"));
3538
+ }
3489
3539
  function toDeniedError(error) {
3490
3540
  return { ...error, code: 1002 /* DENIED */ };
3491
3541
  }
@@ -3498,7 +3548,7 @@ async function withPermissionRetry(send, registry, log, timeoutMs = PERMISSION_D
3498
3548
  if (!isPermissionPromptError(error) || attempt >= MAX_PERMISSION_PROMPTS) {
3499
3549
  throw error;
3500
3550
  }
3501
- const key = permissionKey(error.resourceType, error.action, error.target);
3551
+ const key = promptedKey(error);
3502
3552
  const times = asked.get(key) ?? 0;
3503
3553
  if (times >= MAX_PERMISSION_RETRIES) throw error;
3504
3554
  asked.set(key, times + 1);