@mdbase-dev/sdk 0.1.0-beta.155 → 0.1.0-beta.157

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.
@@ -955,6 +955,7 @@ var MdbaseSDK = (() => {
955
955
  fenceResult: () => fenceResult,
956
956
  fileChunk: () => fileChunk,
957
957
  fileInclusion: () => fileInclusion,
958
+ fileStreamFailure: () => fileStreamFailure,
958
959
  fileView: () => fileView,
959
960
  fmMap: () => fmMap,
960
961
  grantInfo: () => grantInfo,
@@ -1016,7 +1017,7 @@ var MdbaseSDK = (() => {
1016
1017
  function bad(ty) {
1017
1018
  throw new SchemaError(ty, "wrong type");
1018
1019
  }
1019
- var version, RECOVERY, recovery, severity, issue, problem, clientFrame, helloParams, ROLES, role, grantInfo, INCIDENT_KINDS, incident, progress, resyncing, confirmedHead, appliedPrefixParams, appliedPrefix, syncStatus, helloResult, blobRef, textOrBlob, HOLD_REASONS, holdReason, holdRef, hold, HOLD_RESOLUTIONS, holdResolution, recordState, linkResolution, linkView, authorRef, fmMap, recordView, include, viewRef, queryGroup, queryMetadata, queryResult, queryUpdate, change, changesResult, MEDIA_CLASSES, mediaClass, conflictMode, baseField, bodyEdit, docVersion, fileInclusion, listsByField, op, submitParams, CONFLICT_FORMS, conflictValue, conflict, publishState, preflight, receipt, submitResult, conflictEntry, fileContentProfile, knownFileView, fileView, listFilesResult, openUploadParams, openUploadResult, uploadChunkParams, fileChunk, TRANSFER_PHASES, transferProgress, materialization, peer, presencePush, fenceApply, fenceReport, fenceResult, PUSH_CODECS, opClock, mutation, confirmation, resourceView, listResourcesResult, backlinksResult, listViewsResult, viewSourceDocument, newTypeFile, describeResult, pendingOp, listPendingResult, target, queryParams, executeViewParams, TEMPORAL_HINTS, temporalHint, typingEntry, describeTypingResult, DESCRIBE_TYPING_MAX_TYPES, DESCRIBE_TYPING_MAX_PATHS;
1020
+ var version, RECOVERY, recovery, severity, issue, problem, clientFrame, helloParams, ROLES, role, grantInfo, INCIDENT_KINDS, incident, progress, resyncing, confirmedHead, appliedPrefixParams, appliedPrefix, syncStatus, helloResult, blobRef, textOrBlob, HOLD_REASONS, holdReason, holdRef, hold, HOLD_RESOLUTIONS, holdResolution, recordState, linkResolution, linkView, authorRef, fmMap, recordView, include, viewRef, queryGroup, queryMetadata, queryResult, queryUpdate, change, changesResult, MEDIA_CLASSES, mediaClass, conflictMode, baseField, bodyEdit, docVersion, fileInclusion, listsByField, op, submitParams, CONFLICT_FORMS, conflictValue, conflict, publishState, preflight, receipt, submitResult, conflictEntry, fileContentProfile, knownFileView, fileView, listFilesResult, openUploadParams, openUploadResult, uploadChunkParams, fileChunk, fileStreamFailure, TRANSFER_PHASES, transferProgress, materialization, peer, presencePush, fenceApply, fenceReport, fenceResult, PUSH_CODECS, opClock, mutation, confirmation, resourceView, listResourcesResult, backlinksResult, listViewsResult, viewSourceDocument, newTypeFile, describeResult, pendingOp, listPendingResult, target, queryParams, executeViewParams, TEMPORAL_HINTS, temporalHint, typingEntry, describeTypingResult, DESCRIBE_TYPING_MAX_TYPES, DESCRIBE_TYPING_MAX_PATHS;
1020
1021
  var init_wire = __esm({
1021
1022
  "src/wire.ts"() {
1022
1023
  "use strict";
@@ -1641,6 +1642,10 @@ var MdbaseSDK = (() => {
1641
1642
  [2, "bytes", { name: "bstr", enc: (v) => v, dec: (c) => c instanceof Uint8Array ? c : bad("bstr") }],
1642
1643
  [3, "last", bool]
1643
1644
  ]);
1645
+ fileStreamFailure = struct("file-stream-failure", [
1646
+ [0, "stream", uint],
1647
+ [1, "problem", problem]
1648
+ ]);
1644
1649
  TRANSFER_PHASES = [
1645
1650
  "receiving",
1646
1651
  "sealing",
@@ -1718,6 +1723,7 @@ var MdbaseSDK = (() => {
1718
1723
  conflicts: list(conflictEntry),
1719
1724
  presence: presencePush,
1720
1725
  file_chunk: fileChunk,
1726
+ file_stream_failed: fileStreamFailure,
1721
1727
  transfer_progress: transferProgress,
1722
1728
  changes: changesResult
1723
1729
  };
@@ -3619,6 +3625,7 @@ var MdbaseSDK = (() => {
3619
3625
  wired = /* @__PURE__ */ new WeakSet();
3620
3626
  opening = 0;
3621
3627
  early = /* @__PURE__ */ new Map();
3628
+ earlyFailures = /* @__PURE__ */ new Map();
3622
3629
  /** The current session's file actions and folder scope ({@link fileGrant}). */
3623
3630
  get grant() {
3624
3631
  const grant = fileGrant(this.client.hello), gate = gates.get(this);
@@ -3671,6 +3678,19 @@ var MdbaseSDK = (() => {
3671
3678
  } catch {
3672
3679
  }
3673
3680
  });
3681
+ s.onPush("file_stream_failed", (p) => {
3682
+ try {
3683
+ const { stream, problem: problem6 } = fileStreamFailure.dec(p);
3684
+ const st = this.streams.get(stream);
3685
+ if (st) {
3686
+ this.streams.delete(stream);
3687
+ st.onEnd(new MdbaseError(problem6));
3688
+ } else if (this.opening > 0 && this.earlyFailures.size < 16) {
3689
+ this.earlyFailures.set(stream, new MdbaseError(problem6));
3690
+ }
3691
+ } catch {
3692
+ }
3693
+ });
3674
3694
  s.onClose((e) => {
3675
3695
  for (const st of this.streams.values()) st.onEnd(e ?? mdbaseError("unavailable", "connection closed"));
3676
3696
  this.streams.clear();
@@ -3895,8 +3915,13 @@ var MdbaseSDK = (() => {
3895
3915
  }
3896
3916
  streamId = uint.dec(r.get(0) ?? null);
3897
3917
  const early = self.early.get(streamId) ?? [];
3918
+ const earlyFailure = self.earlyFailures.get(streamId);
3898
3919
  self.early.delete(streamId);
3899
- if (self.opening === 0) self.early.clear();
3920
+ self.earlyFailures.delete(streamId);
3921
+ if (self.opening === 0) {
3922
+ self.early.clear();
3923
+ self.earlyFailures.clear();
3924
+ }
3900
3925
  if (cancelled3) {
3901
3926
  cancelRemote();
3902
3927
  finished = true;
@@ -3929,10 +3954,19 @@ var MdbaseSDK = (() => {
3929
3954
  }
3930
3955
  });
3931
3956
  for (const c of early) deliver(c);
3957
+ if (earlyFailure && !finished) {
3958
+ self.streams.delete(streamId);
3959
+ finished = true;
3960
+ detachAbort();
3961
+ ctrl.error(earlyFailure);
3962
+ }
3932
3963
  } catch (e) {
3933
3964
  finished = true;
3934
3965
  detachAbort();
3935
- if (self.opening === 0) self.early.clear();
3966
+ if (self.opening === 0) {
3967
+ self.early.clear();
3968
+ self.earlyFailures.clear();
3969
+ }
3936
3970
  cancelRemote();
3937
3971
  fileReject(e);
3938
3972
  ctrl.error(e);
@@ -6396,11 +6430,11 @@ var MdbaseSDK = (() => {
6396
6430
  return new _MdbaseClient(opts, session);
6397
6431
  } catch (e) {
6398
6432
  if (signal?.aborted) throw stopped();
6399
- const pending = nextRelay2 && isMdbaseError(e, "unavailable") && e.reason === "grant_inactive" && e.details instanceof Map && e.details.get("relayCloseCode") === 4e3;
6433
+ const pending = nextRelay2 && isMdbaseError(e, "unavailable") && (e.reason === "grant_lease_expired" || e.reason === "authorization_unavailable");
6400
6434
  if (!(pending || opts.waitForDevice && isMdbaseError(e, "unavailable") && e.reason === "no_device_online")) throw e;
6401
6435
  if (pending && !deadline2) {
6402
6436
  deadline2 = new AbortController();
6403
- timeout2 = mdbaseError("unavailable", "The approved grant did not become live within 30 seconds", { reason: "grant_activation_timeout", details: e.details });
6437
+ timeout2 = mdbaseError("unavailable", "The approved grant did not become live within 30 seconds", { reason: "grant_activation_timeout", details: e.toProblem().details });
6404
6438
  signal = opts.signal ? AbortSignal.any([opts.signal, deadline2.signal]) : deadline2.signal;
6405
6439
  timer2 = setTimeout(() => deadline2.abort(), 3e4);
6406
6440
  }
@@ -6434,7 +6468,7 @@ var MdbaseSDK = (() => {
6434
6468
  versions: API_VERSIONS,
6435
6469
  clientName: opts.app.name,
6436
6470
  clientVersion: opts.app.version,
6437
- features: [.../* @__PURE__ */ new Set([...opts.features ?? [], "declared-collection-setup-v1"])],
6471
+ features: [.../* @__PURE__ */ new Set([...opts.features ?? [], "declared-collection-setup-v1", "file-stream-failure-v1"])],
6438
6472
  ...tz ? { timezone: tz } : {}
6439
6473
  };
6440
6474
  }
@@ -10726,6 +10760,7 @@ var MdbaseSDK = (() => {
10726
10760
  case 4429:
10727
10761
  return error4("rate_limited", r ?? "relay: busy", r ?? "connector_busy", 5e3);
10728
10762
  case 4e3:
10763
+ if (r === "grant_lease_expired") return error4("unavailable", "grant lease expired", r, 1e3);
10729
10764
  if (r === "device_key_mismatch") return error4("unauthenticated", "relay: the routed key is not the device's", r);
10730
10765
  return error4("unavailable", `relay closed the pipe: ${r ?? "unknown"}`, r ?? "pipe_closed");
10731
10766
  default:
@@ -10862,7 +10897,7 @@ var MdbaseSDK = (() => {
10862
10897
  init_relay_close();
10863
10898
  init_cbor();
10864
10899
  MAX_PIPE_FRAME = 4 + 65535;
10865
- CLOSE_REASONS = new Set("unauthenticated grant_inactive connector_offline connector_busy device_mismatch device_key_mismatch closed client_closed handshake_timeout idle lifetime frame_too_large invalid_frame not_served relay_closing authorization_unavailable grant_revoked".split(" "));
10900
+ CLOSE_REASONS = new Set("unauthenticated grant_inactive connector_offline connector_busy device_mismatch device_key_mismatch closed client_closed handshake_timeout idle lifetime frame_too_large invalid_frame not_served relay_closing authorization_unavailable grant_revoked grant_lease_expired grant_pending_approval grant_revoked_on_device unknown_grant".split(" "));
10866
10901
  }
10867
10902
  });
10868
10903
 
@@ -11545,6 +11580,15 @@ var MdbaseSDK = (() => {
11545
11580
  }
11546
11581
  });
11547
11582
 
11583
+ // src/collection-quota-copy.generated.ts
11584
+ var ACCOUNT_COLLECTION_QUOTA_MESSAGE;
11585
+ var init_collection_quota_copy_generated = __esm({
11586
+ "src/collection-quota-copy.generated.ts"() {
11587
+ "use strict";
11588
+ ACCOUNT_COLLECTION_QUOTA_MESSAGE = "Your account has reached its synced collection limit. Open an existing collection, delete one you own if Delete is available, or contact mdbase support to raise your limit.";
11589
+ }
11590
+ });
11591
+
11548
11592
  // src/app-host/cp-problem.ts
11549
11593
  function isAppServerProblem(value2) {
11550
11594
  return typeof value2 === "object" && value2 !== null && genuine.has(value2);
@@ -11668,7 +11712,7 @@ var MdbaseSDK = (() => {
11668
11712
  if (typeof o.kind === "string" && "problem" in o && obj3(o.problem) && typeof obj3(o.problem).code === "string") return problemOf(obj3(o.problem).code, cpOrigin);
11669
11713
  const detail = obj3(o.problemDetail), server = sanitizeAppServerProblem(o.server ?? detail?.server, cpOrigin);
11670
11714
  const serverCodes = [server?.reason ?? null, server?.code ?? null].filter((c) => c !== null);
11671
- const extra = { retryAfterMs: server?.retryAfterMs ?? retry(o.retryAfterMs), updateUrl: trustedUpdateUrl(server?.updateUrl, cpOrigin) };
11715
+ const extra = { retryAfterMs: server?.retryAfterMs ?? retry(o.retryAfterMs), updateUrl: trustedUpdateUrl(server?.updateUrl, cpOrigin), hasServer: o.server != null || detail?.server != null };
11672
11716
  if ("problem" in o || "readiness" in o || "assessment" in o) {
11673
11717
  const own2 = str2(o.problem) ?? str2(obj3(o.problem)?.code);
11674
11718
  if (own2) return { codes: [...serverCodes, own2], ...extra, refusal: registrationRefusal(detail?.registration) };
@@ -11707,7 +11751,7 @@ var MdbaseSDK = (() => {
11707
11751
  if (!found) return null;
11708
11752
  const { key: key3, original } = resolve(found);
11709
11753
  if (key3 === null) return null;
11710
- const [title, message2, action, severity2, transient2 = false, label] = key3 === "unknown" ? GENERIC : COPY[key3];
11754
+ const [title, message2, action, severity2, transient2 = false, label] = key3 === "unknown" ? GENERIC : key3 === "refused" && !found.hasServer ? UNFINISHED_SIGN_IN : COPY[key3];
11711
11755
  let translated;
11712
11756
  try {
11713
11757
  const messages = options.messages;
@@ -11745,11 +11789,12 @@ var MdbaseSDK = (() => {
11745
11789
  const { key: key3, original } = resolve(found);
11746
11790
  return key3 === null ? null : diagnostic(key3, original, found.refusal ?? null);
11747
11791
  }
11748
- var LABELS, PROBLEM_CODES, GENERIC, BUSY, OFFLINE, UPDATE, CHOOSE, APPROVE, SET_UP, COPY, ALIASES, READINESS, NON_PROBLEM_CODES, NON_PROBLEMS, DEVELOPER, NAME2, str2, obj3, retry, isProblemCode;
11792
+ var LABELS, PROBLEM_CODES, GENERIC, BUSY, OFFLINE, UPDATE, CHOOSE, APPROVE, SET_UP, UNFINISHED_SIGN_IN, COPY, ALIASES, READINESS, NON_PROBLEM_CODES, NON_PROBLEMS, DEVELOPER, NAME2, str2, obj3, retry, isProblemCode;
11749
11793
  var init_describe_error = __esm({
11750
11794
  "src/describe-error.ts"() {
11751
11795
  "use strict";
11752
11796
  init_registration_refusal();
11797
+ init_collection_quota_copy_generated();
11753
11798
  init_collection_availability();
11754
11799
  init_cp_problem();
11755
11800
  LABELS = {
@@ -11895,6 +11940,7 @@ var MdbaseSDK = (() => {
11895
11940
  CHOOSE = ["Choose a collection", "Pick the collection you want this app to use.", "choose_collection", "info"];
11896
11941
  APPROVE = ["Approval needed", "This app needs your approval for extra access to your collection.", "approve", "info"];
11897
11942
  SET_UP = ["Set up this collection", "This collection needs a one-time setup before the app can use it.", "set_up", "info"];
11943
+ UNFINISHED_SIGN_IN = ["Sign-in wasn't finished", "Access wasn't approved. Sign in again when you're ready.", "sign_in", "info"];
11898
11944
  COPY = {
11899
11945
  // Private collections served by one of the account's computers (collection availability).
11900
11946
  device_offline: ["Your computer isn't online", "This collection is kept on your computer. Open the mdbase desktop app on a computer that has it, and this app connects as soon as it's online.", "wait", "info", true],
@@ -11923,8 +11969,8 @@ var MdbaseSDK = (() => {
11923
11969
  collection_invalid: ["Your collection needs repair", "Something in this collection isn't valid. Contact support if this keeps happening.", "contact_support", "error"],
11924
11970
  unavailable: OFFLINE,
11925
11971
  rate_limited: ["Too many requests", "Wait a moment, then try again.", "retry", "warning", true],
11926
- quota_exceeded: ["Out of storage", "Your collection has reached its storage limit. Free up space to keep saving.", "free_space", "error"],
11927
- account_collection_quota_exceeded: ["Synced collection limit reached", "Your account has reached its synced collection limit. Delete a synced collection before creating another.", "free_space", "error", false, "Manage collections"],
11972
+ quota_exceeded: ["Out of storage", "You've reached your storage limit. Free up space to keep saving.", "free_space", "error"],
11973
+ account_collection_quota_exceeded: ["Synced collection limit reached", ACCOUNT_COLLECTION_QUOTA_MESSAGE, "free_space", "error", false, "Manage collections"],
11928
11974
  too_large: ["That's too large", "This item is larger than mdbase allows.", "none", "warning"],
11929
11975
  outcome_unknown: ["Not sure that worked", "The connection dropped before mdbase confirmed it. Check whether it went through before trying again.", "resolve_outcome", "warning"],
11930
11976
  internal: GENERIC,
@@ -40923,12 +40969,12 @@ ${end.comment}` : end.comment;
40923
40969
  // src/application/asset-pins.json
40924
40970
  var asset_pins_default = {
40925
40971
  runtime: {
40926
- sha256: "b4e5b26f101072655d8c880c2355a044cb7afb6e4ffbbdef403db2dda9358010",
40927
- bytes: 3782199,
40928
- maxBytes: 3782199,
40972
+ sha256: "d375ce16a48dec718801704f56ffb6a545247a2793912c2c8e68ceb171ff2537",
40973
+ bytes: 3797530,
40974
+ maxBytes: 3797530,
40929
40975
  source: {
40930
40976
  repository: "mdbase-dev/mdbase-connect",
40931
- commit: "1e6b83c6b338b8ce708de7e2cbddb05992d8dc11"
40977
+ commit: "3e433313e0a234513478789686a4f4274e4dd76c"
40932
40978
  }
40933
40979
  },
40934
40980
  sqlite: {
@@ -42808,10 +42854,13 @@ ${end.comment}` : end.comment;
42808
42854
  const sync = this.trackSync(phase, base.problem, base.transport ?? null, base.live ?? null);
42809
42855
  const writes = this.syncing?.writes() ?? null;
42810
42856
  const saveWarning = this.trackSaveWarning();
42811
- const value2 = Object.freeze({ ...base, selection, phase, sync, writes, storage: this.storagePolicy, saveWarning, links: this.links });
42857
+ const value2 = Object.freeze({ ...base, selection, phase, sync, writes, storage: this.storagePolicy, saveWarning, links: this.linksFor(id6) });
42812
42858
  this.composed = { base: raw, selection, revision: this.revision, hint, value: value2 };
42813
42859
  return value2;
42814
42860
  }
42861
+ linksFor(id6) {
42862
+ return this.links && id6 ? Object.freeze({ ...this.links, manageAccess: `${this.cpOrigin}/access?collection=${encodeURIComponent(id6)}` }) : this.links;
42863
+ }
42815
42864
  /** One grace window per continuously pending replica, not per edit or request. */
42816
42865
  trackSaveWarning() {
42817
42866
  const syncing = this.syncing, status = syncing?.status, count = status?.pending ?? 0;