@mdbase-dev/sdk 0.1.0-beta.191 → 0.1.0-beta.197

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.
@@ -27272,6 +27272,28 @@ ${end.comment}` : end.comment;
27272
27272
  check3();
27273
27273
  });
27274
27274
  }
27275
+ /** Connect's receipt stores a Private pick; its grant is stored only after the
27276
+ * SAME window returned it to the page that prepared the keys. A window closed,
27277
+ * a page reloaded or an exchange that failed in between leaves a pick that
27278
+ * nothing can finish. Forget that pick and its preparation only: the
27279
+ * installation, its collections and its stored grants stay, and the person
27280
+ * picks the collection again in a new window with new keys. A recovery slot
27281
+ * holds nothing but its one collection, so it is never rewritten here.
27282
+ * Resolves true when a pick was forgotten. */
27283
+ abandonNativeSelection(installation) {
27284
+ const callback = installation.isCurrent;
27285
+ return this.exclusive(async () => {
27286
+ this.owned(installation);
27287
+ const s = this.state, n = s.nativeSelection;
27288
+ if (!n || s.nativeGrants?.some((c) => c.authorization_request_id === n.authorizationRequestId && c.collection_id === n.collectionId)) return false;
27289
+ if (s.recoveryFor) throw fail3("recovery_required");
27290
+ const { nativeSelection: _pick, nativeAuthorization: _preparation, ...kept } = s;
27291
+ await this.save(kept);
27292
+ this.owned(installation);
27293
+ if (installation.isCurrent !== callback) throw fail3("fenced");
27294
+ return true;
27295
+ });
27296
+ }
27275
27297
  collectionSelection(v, approved2, requestId) {
27276
27298
  const selectedCollectionId = id2(v.selected_collection_id), createdCollectionIds = _AppProtectedInstallationSignIn.collectionIds(v.created_collection_ids);
27277
27299
  if (!approved2.includes(selectedCollectionId) || createdCollectionIds.some((value2) => !approved2.includes(value2))) throw fail3("response");
@@ -44284,16 +44306,18 @@ ${end.comment}` : end.comment;
44284
44306
  init_device_registration();
44285
44307
  init_wasm_runtime();
44286
44308
  AppCloudCopyHostError = class extends Error {
44287
- constructor(reason) {
44288
- super(`app cloud copy host: ${reason}`);
44309
+ constructor(reason, stage, options) {
44310
+ super(`app cloud copy host: ${reason}`, options);
44289
44311
  this.reason = reason;
44312
+ this.stage = stage;
44290
44313
  this.name = "AppCloudCopyHostError";
44291
44314
  }
44292
44315
  reason;
44316
+ stage;
44293
44317
  };
44294
44318
  MAX_FACADES = 32;
44295
44319
  DRIVE_TURNS = 8;
44296
- fail16 = (r) => new AppCloudCopyHostError(r);
44320
+ fail16 = (r, stage) => new AppCloudCopyHostError(r, stage);
44297
44321
  equal10 = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
44298
44322
  AppWebCloudCopyHost = class _AppWebCloudCopyHost {
44299
44323
  constructor(source, installation, originalRelease, origin4, lifetime) {
@@ -44484,7 +44508,7 @@ ${end.comment}` : end.comment;
44484
44508
  await host?.close();
44485
44509
  if (e instanceof AppCloudCopyHostError || e instanceof AppStrictDeviceApprovalError)
44486
44510
  throw e;
44487
- throw fail16("unavailable");
44511
+ throw new AppCloudCopyHostError("unavailable", "device_open", { cause: e });
44488
44512
  }
44489
44513
  }
44490
44514
  /** SAME protected installation flow -> SAME original native lifetime. No
@@ -45030,7 +45054,7 @@ ${end.comment}` : end.comment;
45030
45054
  nonce: async ({ signal }) => {
45031
45055
  const r = await request3(`${origin4}/v1/nonce`, { signal, cache: "no-store", credentials: "omit", redirect: "error", referrerPolicy: "no-referrer" });
45032
45056
  const text9 = (await r.text()).trim();
45033
- if (!r.ok || !/^[0-9a-f]{64}$/.test(text9)) throw fail16("unavailable");
45057
+ if (!r.ok || !/^[0-9a-f]{64}$/.test(text9)) throw fail16("unavailable", "push_nonce");
45034
45058
  return Uint8Array.from(text9.match(/../g).map((v) => parseInt(v, 16)));
45035
45059
  },
45036
45060
  signHello: (nonce, token) => current3() ? native.signLogHello(nonce, token) : null
@@ -45077,7 +45101,7 @@ ${end.comment}` : end.comment;
45077
45101
  this.checkCollection(signal);
45078
45102
  if (!this.native || !this.collectionScope || this.adoptedEndpoint === null || !Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 15e3 || typeof cold !== "boolean" || typeof local !== "boolean" || cold && (local || !this.pump))
45079
45103
  throw fail16("binding");
45080
- if (local && !this.holdsLog()) return Promise.reject(fail16("unavailable"));
45104
+ if (local && !this.holdsLog()) return Promise.reject(fail16("unavailable", "local_read_without_log"));
45081
45105
  if (this.readWork)
45082
45106
  return this.readWork.then(() => {
45083
45107
  this.checkCollection(signal);
@@ -45096,20 +45120,22 @@ ${end.comment}` : end.comment;
45096
45120
  this.readAbort = ctrl;
45097
45121
  signal.addEventListener("abort", abort, { once: true });
45098
45122
  let timer2 = null;
45099
- let stopError = fail16(cold ? "sync_stalled" : "unavailable");
45123
+ let stage = "read_connect";
45124
+ let stopError = null;
45125
+ const stopped = () => stopError ??= fail16(cold ? "sync_stalled" : "unavailable", stage);
45100
45126
  let rejectAbort;
45101
45127
  const aborted = new Promise((_resolve, reject) => {
45102
- rejectAbort = () => reject(stopError);
45128
+ rejectAbort = () => reject(stopped());
45103
45129
  ctrl.signal.addEventListener("abort", rejectAbort, { once: true });
45104
45130
  });
45105
45131
  void aborted.catch(() => {
45106
45132
  });
45107
45133
  let shown = null;
45108
- const report = (stage) => {
45109
- if (stage === shown) return;
45110
- shown = stage;
45134
+ const report = (stage2) => {
45135
+ if (stage2 === shown) return;
45136
+ shown = stage2;
45111
45137
  try {
45112
- onProgress?.(stage);
45138
+ onProgress?.(stage2);
45113
45139
  } catch {
45114
45140
  }
45115
45141
  };
@@ -45184,7 +45210,7 @@ ${end.comment}` : end.comment;
45184
45210
  }).then((client) => {
45185
45211
  if (ctrl.signal.aborted) {
45186
45212
  client.close();
45187
- throw fail16("unavailable");
45213
+ throw stopped();
45188
45214
  }
45189
45215
  return client;
45190
45216
  }),
@@ -45193,6 +45219,7 @@ ${end.comment}` : end.comment;
45193
45219
  this.checkCollection(signal);
45194
45220
  let delay = 250;
45195
45221
  while (!ctrl.signal.aborted) {
45222
+ stage = "read_catch_up";
45196
45223
  this.native.tick();
45197
45224
  const turn = pump();
45198
45225
  if (turn) await Promise.race([turn.pump(), aborted]);
@@ -45203,13 +45230,14 @@ ${end.comment}` : end.comment;
45203
45230
  delay = Math.min(1e3, delay * 2);
45204
45231
  continue;
45205
45232
  }
45233
+ stage = "read_query";
45206
45234
  try {
45207
45235
  await Promise.race([
45208
45236
  this.readClient.query({ limit: 1 }, { signal: ctrl.signal }),
45209
45237
  aborted
45210
45238
  ]);
45211
45239
  this.checkCollection(signal);
45212
- if (ctrl.signal.aborted) throw fail16("unavailable");
45240
+ if (ctrl.signal.aborted) throw stopped();
45213
45241
  this.readVerified = true;
45214
45242
  return;
45215
45243
  } catch (error5) {
@@ -45220,10 +45248,10 @@ ${end.comment}` : end.comment;
45220
45248
  await waitForOpenRetry(delay, ctrl.signal);
45221
45249
  delay = Math.min(1e3, delay * 2);
45222
45250
  }
45223
- throw fail16("unavailable");
45251
+ throw stopped();
45224
45252
  } catch (error5) {
45225
45253
  this.checkCollection(signal);
45226
- if (ctrl.signal.aborted) throw stopError;
45254
+ if (ctrl.signal.aborted) throw stopped();
45227
45255
  throw error5;
45228
45256
  } finally {
45229
45257
  if (timer2 !== null) clearTimeout(timer2);
@@ -45274,7 +45302,7 @@ ${end.comment}` : end.comment;
45274
45302
  const observation = this.native.observations();
45275
45303
  if (observation.requiresReopen || observation.keyringRebuildFailed) throw fail16("recovery_required");
45276
45304
  const wait2 = initialSyncWait(observation.status);
45277
- if (wait2 === "offline" || this.pump?.transportHealth?.kind === "offline") throw fail16("unavailable");
45305
+ if (wait2 === "offline" || this.pump?.transportHealth?.kind === "offline") throw fail16("unavailable", "key_wait_offline");
45278
45306
  const reason = wait2 === "waiting_for_key" ? keyWaitDetail(observation.status)?.key : void 0;
45279
45307
  if (wait2 === null || reason !== void 0 && reason !== "reading") {
45280
45308
  if (await locked()) return "locked";
@@ -45436,7 +45464,7 @@ ${end.comment}` : end.comment;
45436
45464
  this.collectionSql.fence();
45437
45465
  this.authority?.close();
45438
45466
  await this.sqlClose?.();
45439
- if (fenceFailed) throw fail16("unavailable");
45467
+ if (fenceFailed) throw fail16("unavailable", "close_fence");
45440
45468
  } finally {
45441
45469
  this.key = null;
45442
45470
  this.noise = null;
@@ -49004,7 +49032,21 @@ ${end.comment}` : end.comment;
49004
49032
  }
49005
49033
  return Object.freeze([id6, password ? "password" : "recoveryKey", bytes10]);
49006
49034
  }
49007
- var ApplicationRuntimeError, emptyReadiness, ApplicationRuntime;
49035
+ function nativeCause(detail) {
49036
+ try {
49037
+ if (!detail || !NAME3.test(String(detail.name))) return void 0;
49038
+ const name3 = (value2) => typeof value2 === "string" && NAME3.test(value2) ? value2 : "-";
49039
+ let token = `${detail.name}:${name3(detail.code)}`;
49040
+ if (typeof detail.stage === "string" && NAME3.test(detail.stage)) token += `@${detail.stage}`;
49041
+ if (detail.cause && NAME3.test(String(detail.cause.name))) token += ` cause=${detail.cause.name}:${name3(detail.cause.code)}`;
49042
+ const status = detail.server?.status;
49043
+ if (Number.isInteger(status) && status >= 100 && status <= 599) token += ` http=${status}${detail.server.code && NAME3.test(detail.server.code) ? `:${detail.server.code}` : ""}`;
49044
+ return token;
49045
+ } catch {
49046
+ return void 0;
49047
+ }
49048
+ }
49049
+ var ApplicationRuntimeError, NAME3, emptyReadiness, ApplicationRuntime;
49008
49050
  var init_runtime = __esm({
49009
49051
  "src/application/runtime.ts"() {
49010
49052
  "use strict";
@@ -49025,6 +49067,7 @@ ${end.comment}` : end.comment;
49025
49067
  }
49026
49068
  code;
49027
49069
  };
49070
+ NAME3 = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
49028
49071
  emptyReadiness = () => {
49029
49072
  const facet3 = Object.freeze({ checking: false, assessment: null, problem: null });
49030
49073
  return Object.freeze({ checking: false, assessment: null, problem: null, facets: Object.freeze({ capabilities: facet3, contracts: facet3, configuration: facet3, files: facet3, people: facet3, notifications: facet3 }) });
@@ -49172,7 +49215,7 @@ ${end.comment}` : end.comment;
49172
49215
  this.snapshot = Object.freeze({ ...this.raw, status: this.stopped ? "closed" : "blocked", problem: this.stopped ? null : this.stopFailed ? "application_stop_failed" : "application_closing", selectedCollectionId: null, unlock: null, readiness: emptyReadiness() });
49173
49216
  } else {
49174
49217
  const readiness3 = this.scope.getReadiness() ?? emptyReadiness();
49175
- let status = this.raw.status, problem7 = this.raw.problem, detail;
49218
+ let status = this.raw.status, problem7 = this.raw.problem, detail, native = this.raw.problemDetail;
49176
49219
  const id6 = this.raw.selectedCollectionId;
49177
49220
  const released = this.retiring && readiness3.problem?.code === "readiness_fenced";
49178
49221
  const waiting = id6 !== null && (this.scope.getReadiness() === null || released) && this.portsFailed !== id6;
@@ -49184,18 +49227,21 @@ ${end.comment}` : end.comment;
49184
49227
  const blocked = readiness3.problem ?? readiness3.assessment?.problem;
49185
49228
  problem7 = blocked?.code ?? "application_readiness_unavailable";
49186
49229
  detail = blocked?.detail;
49230
+ native = void 0;
49187
49231
  }
49188
49232
  }
49189
- const diagnostic2 = `${problem7}:${detail ?? ""}`;
49233
+ const diagnostic2 = `${problem7}:${detail ?? nativeCause(native) ?? ""}`;
49190
49234
  if (status === "blocked" && problem7 && diagnostic2 !== this.loggedProblem) {
49191
49235
  this.loggedProblem = diagnostic2;
49192
49236
  try {
49193
- if (detail) console.error("mdbase application blocked:", problem7, detail);
49237
+ const cause = detail ?? nativeCause(native);
49238
+ if (cause) console.error("mdbase application blocked:", problem7, cause);
49194
49239
  else console.error("mdbase application blocked:", problem7);
49195
49240
  } catch {
49196
49241
  }
49197
49242
  } else if (status !== "blocked") this.loggedProblem = null;
49198
- this.snapshot = Object.freeze({ ...this.raw, status, problem: problem7, openingProgress: status === "opening" ? readiness3.checking ? "checking_setup" : this.raw.openingProgress ?? null : null, collections: Object.freeze(this.raw.collections.map((value2) => Object.freeze({ ...value2 }))), readiness: readiness3 });
49243
+ const { problemDetail: _native, ...raw } = this.raw;
49244
+ this.snapshot = Object.freeze({ ...raw, ...native ? { problemDetail: native } : {}, status, problem: problem7, openingProgress: status === "opening" ? readiness3.checking ? "checking_setup" : this.raw.openingProgress ?? null : null, collections: Object.freeze(this.raw.collections.map((value2) => Object.freeze({ ...value2 }))), readiness: readiness3 });
49199
49245
  }
49200
49246
  for (const listener of [...this.listeners]) try {
49201
49247
  listener();
@@ -50273,12 +50319,12 @@ ${end.comment}` : end.comment;
50273
50319
  // src/application/asset-pins.json
50274
50320
  var asset_pins_default = {
50275
50321
  runtime: {
50276
- sha256: "7004351583c3a79411e644fafe9f5786816d32ea058605d1905fd50666012f40",
50277
- bytes: 3875815,
50278
- maxBytes: 3875815,
50322
+ sha256: "78cf586d0550931a912e986bc79b94b4cfdbeffa8abab0faec57824f4c5da35f",
50323
+ bytes: 3885861,
50324
+ maxBytes: 3885861,
50279
50325
  source: {
50280
50326
  repository: "mdbase-dev/mdbase-connect",
50281
- commit: "aae332572834fbfa065c0f696017c0de3540649d"
50327
+ commit: "ebfd22bfff3dd268c404637a4aefd1b876acaa2b"
50282
50328
  }
50283
50329
  },
50284
50330
  sqlite: {
@@ -54023,7 +54069,14 @@ ${end.comment}` : end.comment;
54023
54069
  init_cp_problem();
54024
54070
  var reasons = /* @__PURE__ */ new Set(["binding", "fenced", "busy", "open_in_another_tab", "account_confirmation_required", "recovery_account_mismatch", "outcome_unknown", "response", "refused", "expired", "recovery_required", "unavailable", "collection_migrating", "collection_not_yet_migrated", "account_suspended", "update_required", "private_device_limit", "private_device_not_allowed"]);
54025
54071
  var domCodes = /* @__PURE__ */ new Set(["AbortError", "ConstraintError", "DataCloneError", "InvalidStateError", "NotAllowedError", "NotFoundError", "NotReadableError", "OperationError", "QuotaExceededError", "SecurityError", "TimeoutError", "TransactionInactiveError", "UnknownError", "VersionError"]);
54026
- var result = (problem7, name3, code, server) => Object.freeze({ problem: problem7, detail: Object.freeze({ name: name3, code, ...server ? { server } : {} }) });
54072
+ var stages2 = /* @__PURE__ */ new Set(["device_open", "push_nonce", "local_read_without_log", "read_connect", "read_catch_up", "read_query", "key_wait_offline", "close_fence"]);
54073
+ var result = (problem7, name3, code, extra = {}) => Object.freeze({ problem: problem7, detail: Object.freeze({ name: name3, code, ...Object.fromEntries(Object.entries(extra).filter(([, v]) => v !== void 0)) }) });
54074
+ function hostExtra(error5) {
54075
+ const stage = stages2.has(error5.stage) ? error5.stage : void 0;
54076
+ if (stage !== "device_open" || error5.cause instanceof AppCloudCopyHostError) return { stage };
54077
+ const { name: name3, code } = webSignInProblem(error5.cause).detail;
54078
+ return { stage, cause: Object.freeze({ name: name3, code }) };
54079
+ }
54027
54080
  function webSignInProblem(error5) {
54028
54081
  try {
54029
54082
  for (const [type, name3] of [
@@ -54042,8 +54095,9 @@ ${end.comment}` : end.comment;
54042
54095
  if (error5 instanceof type) {
54043
54096
  const code = error5.reason;
54044
54097
  const server = ("server" in error5 ? sanitizeAppServerProblem(error5.server) : null) ?? void 0;
54045
- if (code === "sync_stalled") return result("unavailable", name3, code, server);
54046
- return reasons.has(code) ? result(code, name3, code, server) : result("open_failed", name3, null, server);
54098
+ const extra = { server, ...error5 instanceof AppCloudCopyHostError ? hostExtra(error5) : {} };
54099
+ if (code === "sync_stalled") return result("unavailable", name3, code, extra);
54100
+ return reasons.has(code) ? result(code, name3, code, extra) : result("open_failed", name3, null, extra);
54047
54101
  }
54048
54102
  }
54049
54103
  if (error5 instanceof AppReplicaOwnerError && error5.reason === "busy") return result("open_in_another_tab", "AppReplicaOwnerError", "busy");
@@ -54177,6 +54231,7 @@ ${end.comment}` : end.comment;
54177
54231
  init_errors();
54178
54232
  var closedView = Object.freeze({ status: "unselected", problem: null, transport: null, live: null });
54179
54233
  var failure2 = (reason) => new AppInstallationSignInError(reason);
54234
+ var keptDetail = (update, previous, detail) => update.problem === void 0 || update.problem === previous ? detail : void 0;
54180
54235
  var liveOutcomes = /* @__PURE__ */ new Set(["collection_not_yet_migrated", "collection_migrating", "account_suspended", "update_required"]);
54181
54236
  var AppWebSignInSession = class {
54182
54237
  lifetime = new AbortController();
@@ -54303,7 +54358,7 @@ ${end.comment}` : end.comment;
54303
54358
  }
54304
54359
  setBase(update) {
54305
54360
  const { problemDetail: previousDetail, ...previous } = this.base;
54306
- const detail = update.problem === null ? void 0 : update.problemDetail ?? previousDetail;
54361
+ const detail = update.problemDetail ?? keptDetail(update, previous.problem, previousDetail);
54307
54362
  this.base = Object.freeze({ ...previous, ...update, selectedCollectionId: null, signIn: this.flow?.view() ?? null, ...detail ? { problemDetail: detail } : {} });
54308
54363
  }
54309
54364
  /** One open collection's status, problem and transport. */
@@ -54318,7 +54373,7 @@ ${end.comment}` : end.comment;
54318
54373
  this.setBase({ timing });
54319
54374
  const { problemDetail: previousDetail, unlock: previousLock, ...previous } = slot.view;
54320
54375
  const { unlock: nextLock, ...rest } = update;
54321
- const detail = update.problem === null ? void 0 : update.problemDetail ?? previousDetail;
54376
+ const detail = update.problemDetail ?? keptDetail(update, previous.problem, previousDetail);
54322
54377
  const openingProgress = (update.status ?? previous.status) === "opening" ? "openingProgress" in update ? update.openingProgress ?? null : previous.openingProgress ?? null : null;
54323
54378
  const lock = (update.status ?? previous.status) === "needs_unlock" ? nextLock ?? previousLock ?? null : null;
54324
54379
  slot.view = Object.freeze({ ...previous, ...rest, openingProgress, ...lock ? { unlock: lock } : {}, ...detail ? { problemDetail: detail } : {} });
@@ -54408,8 +54463,8 @@ ${end.comment}` : end.comment;
54408
54463
  this.check();
54409
54464
  const view2 = this.flow.view();
54410
54465
  if (view2.state === "paired") {
54411
- if (this.flow.pendingNativeSelection?.() && !view2.nativeSelection) throw failure2("recovery_required");
54412
54466
  await this.openDevice(false, this.options.recoveryFor !== void 0);
54467
+ await this.abandonUnfinishedNativeChoice();
54413
54468
  if (this.flow.collectionConsentView()?.state === "pending") {
54414
54469
  this.consentPending = true;
54415
54470
  this.publish({ status: "authorizing" });
@@ -54467,9 +54522,9 @@ ${end.comment}` : end.comment;
54467
54522
  return this.operation(async () => {
54468
54523
  try {
54469
54524
  if (view2.state === "paired") {
54470
- if (this.flow.pendingNativeSelection?.() && !view2.nativeSelection) throw failure2("recovery_required");
54471
54525
  await this.openDevice();
54472
54526
  this.check();
54527
+ await this.abandonUnfinishedNativeChoice();
54473
54528
  const consent = await this.flow.startCollectionConsent(this.installation, this.options.requestedCreateCollections ?? this.options.freshRequestedCreateCollections ?? false, hint, this.options.freshRequestedPrivateDevice === true);
54474
54529
  this.check();
54475
54530
  this.consentPending = true;
@@ -54633,8 +54688,15 @@ ${end.comment}` : end.comment;
54633
54688
  if (consent.state === "scope_updated") {
54634
54689
  if (consent.accountSelectionConfirmed !== true) throw failure2("account_confirmation_required");
54635
54690
  const native = this.flow.pendingNativeSelection?.();
54636
- if (native?.requestId === consent.requestId) await this.finishNativeChoice(native);
54637
- else if (this.flow.view().collectionSelection?.requestId !== consent.requestId && !this.deviceAccessWithoutPick(consent.requestedPrivateDevice === true ? consent.addedCollectionIds : [])) throw failure2("response");
54691
+ if (native?.requestId === consent.requestId) {
54692
+ if (!await this.settleNativeChoice(native)) {
54693
+ this.consentPending = false;
54694
+ this.closeApprovalWindow();
54695
+ this.publish({ status: "unselected", problem: null, approval: Object.freeze({ outcome: "closed" }) });
54696
+ await this.refreshCollections();
54697
+ return;
54698
+ }
54699
+ } else if (this.flow.view().collectionSelection?.requestId !== consent.requestId && !this.deviceAccessWithoutPick(consent.requestedPrivateDevice === true ? consent.addedCollectionIds : [])) throw failure2("response");
54638
54700
  this.consentPending = false;
54639
54701
  this.freshApproval = true;
54640
54702
  this.closeApprovalWindow();
@@ -54673,12 +54735,13 @@ ${end.comment}` : end.comment;
54673
54735
  }
54674
54736
  if (view2.state === "paired") {
54675
54737
  const native = this.flow.pendingNativeSelection?.();
54676
- if (native?.requestId === view2.requestId) await this.finishNativeChoice(native);
54677
- else if (view2.collectionSelection?.requestId !== view2.requestId && !this.deviceAccessWithoutPick(view2.privateDeviceCollectionIds ?? [])) throw failure2("response");
54738
+ const unfinished = native?.requestId === view2.requestId && !await this.settleNativeChoice(native);
54739
+ if (native?.requestId !== view2.requestId && view2.collectionSelection?.requestId !== view2.requestId && !this.deviceAccessWithoutPick(view2.privateDeviceCollectionIds ?? [])) throw failure2("response");
54678
54740
  this.freshApproval = true;
54679
54741
  this.closeApprovalWindow();
54680
54742
  await this.openDevice();
54681
54743
  this.check();
54744
+ if (unfinished) this.publish({ approval: Object.freeze({ outcome: "closed" }) });
54682
54745
  await this.refreshCollections();
54683
54746
  } else this.publish({ status: "authorizing", problem: null });
54684
54747
  }
@@ -54739,6 +54802,44 @@ ${end.comment}` : end.comment;
54739
54802
  await this.flow.completeNativeAuthorization(this.installation, completion);
54740
54803
  this.check();
54741
54804
  }
54805
+ /** Finish the Private pick, or forget it when it can no longer be finished:
54806
+ * its window closed before the grant returned, its keys went with a reload,
54807
+ * or the grant exchange failed. The grant is consumed once and its keys live
54808
+ * only in the page that prepared them, so a failed finish is never repeated.
54809
+ * Resolves false when the pick was forgotten; the sign-in itself is intact.
54810
+ * A closing session, or a pick that could not be forgotten, still rejects. */
54811
+ async settleNativeChoice(selection) {
54812
+ try {
54813
+ await this.finishNativeChoice(selection);
54814
+ return true;
54815
+ } catch (error5) {
54816
+ this.check();
54817
+ let abandoned = false;
54818
+ try {
54819
+ abandoned = this.installation !== null && await this.flow.abandonNativeSelection?.(this.installation) === true;
54820
+ } catch {
54821
+ abandoned = false;
54822
+ }
54823
+ this.check();
54824
+ if (!abandoned) throw error5;
54825
+ try {
54826
+ console.warn("mdbase: a Private collection pick was not finished", webSignInProblem(error5).detail.code);
54827
+ } catch {
54828
+ }
54829
+ return false;
54830
+ }
54831
+ }
54832
+ /** A stored Private pick with no grant, found outside the turn that received
54833
+ * it: nothing here holds its keys. Forget the pick (never the installation)
54834
+ * so the session starts; one that cannot be forgotten stays a refusal. */
54835
+ async abandonUnfinishedNativeChoice() {
54836
+ const flow = this.flow;
54837
+ if (!flow.pendingNativeSelection?.() || flow.view().nativeSelection) return;
54838
+ if (!this.installation || !flow.abandonNativeSelection) throw failure2("recovery_required");
54839
+ const abandoned = await flow.abandonNativeSelection(this.installation);
54840
+ this.check();
54841
+ if (!abandoned) throw failure2("recovery_required");
54842
+ }
54742
54843
  holdApprovalWindow(portal) {
54743
54844
  if (this.approvalWindow !== portal) this.closeApprovalWindow();
54744
54845
  this.approvalWindow = portal;