@mdbase-dev/sdk 0.1.0-beta.189 → 0.1.0-beta.193

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");
@@ -39530,10 +39552,17 @@ ${end.comment}` : end.comment;
39530
39552
  }
39531
39553
  return out;
39532
39554
  }
39555
+ function awaitingKeyGrant(status) {
39556
+ if (initialSyncWait(status) !== "waiting_for_key") return false;
39557
+ const key3 = keyWaitDetail(status)?.key;
39558
+ return key3 === "reading" || key3 === "no_grant";
39559
+ }
39560
+ var KEY_GRANT_WAIT_MS;
39533
39561
  var init_initial_sync = __esm({
39534
39562
  "src/app-host/initial-sync.ts"() {
39535
39563
  "use strict";
39536
39564
  init_plain();
39565
+ KEY_GRANT_WAIT_MS = 15e4;
39537
39566
  }
39538
39567
  });
39539
39568
 
@@ -45120,8 +45149,10 @@ ${end.comment}` : end.comment;
45120
45149
  this.readVerified = false;
45121
45150
  try {
45122
45151
  if (pump()) {
45152
+ let granting = false;
45123
45153
  const progress2 = () => {
45124
45154
  const observation = observe();
45155
+ granting = cold && awaitingKeyGrant(observation.status);
45125
45156
  return [
45126
45157
  observation.status.confirmedThrough,
45127
45158
  observation.status.installing?.done ?? 0,
@@ -45147,7 +45178,7 @@ ${end.comment}` : end.comment;
45147
45178
  const prior = bodies.get(body.id);
45148
45179
  if (body.bytes > (prior?.bytes ?? 0)) bodies.set(body.id, { bytes: body.bytes, at: now });
45149
45180
  }
45150
- let left = timeoutMs - (now - lastProgress);
45181
+ let left = (granting ? Math.max(timeoutMs, KEY_GRANT_WAIT_MS) : timeoutMs) - (now - lastProgress);
45151
45182
  if (left <= 0) {
45152
45183
  deferred2 ??= new Set(bodies.keys());
45153
45184
  left = Math.max(0, ...[...deferred2].map((id6) => {
@@ -50264,12 +50295,12 @@ ${end.comment}` : end.comment;
50264
50295
  // src/application/asset-pins.json
50265
50296
  var asset_pins_default = {
50266
50297
  runtime: {
50267
- sha256: "7004351583c3a79411e644fafe9f5786816d32ea058605d1905fd50666012f40",
50268
- bytes: 3875815,
50269
- maxBytes: 3875815,
50298
+ sha256: "247410a98e3a31adcd9c453cae4b607ba0528cce617d6a288bfec8745352d0b1",
50299
+ bytes: 3877699,
50300
+ maxBytes: 3877699,
50270
50301
  source: {
50271
50302
  repository: "mdbase-dev/mdbase-connect",
50272
- commit: "aae332572834fbfa065c0f696017c0de3540649d"
50303
+ commit: "7cbf82a4f5b1ef39947ddee6424b436bc8d3daa7"
50273
50304
  }
50274
50305
  },
50275
50306
  sqlite: {
@@ -54399,8 +54430,8 @@ ${end.comment}` : end.comment;
54399
54430
  this.check();
54400
54431
  const view2 = this.flow.view();
54401
54432
  if (view2.state === "paired") {
54402
- if (this.flow.pendingNativeSelection?.() && !view2.nativeSelection) throw failure2("recovery_required");
54403
54433
  await this.openDevice(false, this.options.recoveryFor !== void 0);
54434
+ await this.abandonUnfinishedNativeChoice();
54404
54435
  if (this.flow.collectionConsentView()?.state === "pending") {
54405
54436
  this.consentPending = true;
54406
54437
  this.publish({ status: "authorizing" });
@@ -54458,9 +54489,9 @@ ${end.comment}` : end.comment;
54458
54489
  return this.operation(async () => {
54459
54490
  try {
54460
54491
  if (view2.state === "paired") {
54461
- if (this.flow.pendingNativeSelection?.() && !view2.nativeSelection) throw failure2("recovery_required");
54462
54492
  await this.openDevice();
54463
54493
  this.check();
54494
+ await this.abandonUnfinishedNativeChoice();
54464
54495
  const consent = await this.flow.startCollectionConsent(this.installation, this.options.requestedCreateCollections ?? this.options.freshRequestedCreateCollections ?? false, hint, this.options.freshRequestedPrivateDevice === true);
54465
54496
  this.check();
54466
54497
  this.consentPending = true;
@@ -54624,8 +54655,15 @@ ${end.comment}` : end.comment;
54624
54655
  if (consent.state === "scope_updated") {
54625
54656
  if (consent.accountSelectionConfirmed !== true) throw failure2("account_confirmation_required");
54626
54657
  const native = this.flow.pendingNativeSelection?.();
54627
- if (native?.requestId === consent.requestId) await this.finishNativeChoice(native);
54628
- else if (this.flow.view().collectionSelection?.requestId !== consent.requestId && !this.deviceAccessWithoutPick(consent.requestedPrivateDevice === true ? consent.addedCollectionIds : [])) throw failure2("response");
54658
+ if (native?.requestId === consent.requestId) {
54659
+ if (!await this.settleNativeChoice(native)) {
54660
+ this.consentPending = false;
54661
+ this.closeApprovalWindow();
54662
+ this.publish({ status: "unselected", problem: null, approval: Object.freeze({ outcome: "closed" }) });
54663
+ await this.refreshCollections();
54664
+ return;
54665
+ }
54666
+ } else if (this.flow.view().collectionSelection?.requestId !== consent.requestId && !this.deviceAccessWithoutPick(consent.requestedPrivateDevice === true ? consent.addedCollectionIds : [])) throw failure2("response");
54629
54667
  this.consentPending = false;
54630
54668
  this.freshApproval = true;
54631
54669
  this.closeApprovalWindow();
@@ -54664,12 +54702,13 @@ ${end.comment}` : end.comment;
54664
54702
  }
54665
54703
  if (view2.state === "paired") {
54666
54704
  const native = this.flow.pendingNativeSelection?.();
54667
- if (native?.requestId === view2.requestId) await this.finishNativeChoice(native);
54668
- else if (view2.collectionSelection?.requestId !== view2.requestId && !this.deviceAccessWithoutPick(view2.privateDeviceCollectionIds ?? [])) throw failure2("response");
54705
+ const unfinished = native?.requestId === view2.requestId && !await this.settleNativeChoice(native);
54706
+ if (native?.requestId !== view2.requestId && view2.collectionSelection?.requestId !== view2.requestId && !this.deviceAccessWithoutPick(view2.privateDeviceCollectionIds ?? [])) throw failure2("response");
54669
54707
  this.freshApproval = true;
54670
54708
  this.closeApprovalWindow();
54671
54709
  await this.openDevice();
54672
54710
  this.check();
54711
+ if (unfinished) this.publish({ approval: Object.freeze({ outcome: "closed" }) });
54673
54712
  await this.refreshCollections();
54674
54713
  } else this.publish({ status: "authorizing", problem: null });
54675
54714
  }
@@ -54730,6 +54769,44 @@ ${end.comment}` : end.comment;
54730
54769
  await this.flow.completeNativeAuthorization(this.installation, completion);
54731
54770
  this.check();
54732
54771
  }
54772
+ /** Finish the Private pick, or forget it when it can no longer be finished:
54773
+ * its window closed before the grant returned, its keys went with a reload,
54774
+ * or the grant exchange failed. The grant is consumed once and its keys live
54775
+ * only in the page that prepared them, so a failed finish is never repeated.
54776
+ * Resolves false when the pick was forgotten; the sign-in itself is intact.
54777
+ * A closing session, or a pick that could not be forgotten, still rejects. */
54778
+ async settleNativeChoice(selection) {
54779
+ try {
54780
+ await this.finishNativeChoice(selection);
54781
+ return true;
54782
+ } catch (error5) {
54783
+ this.check();
54784
+ let abandoned = false;
54785
+ try {
54786
+ abandoned = this.installation !== null && await this.flow.abandonNativeSelection?.(this.installation) === true;
54787
+ } catch {
54788
+ abandoned = false;
54789
+ }
54790
+ this.check();
54791
+ if (!abandoned) throw error5;
54792
+ try {
54793
+ console.warn("mdbase: a Private collection pick was not finished", webSignInProblem(error5).detail.code);
54794
+ } catch {
54795
+ }
54796
+ return false;
54797
+ }
54798
+ }
54799
+ /** A stored Private pick with no grant, found outside the turn that received
54800
+ * it: nothing here holds its keys. Forget the pick (never the installation)
54801
+ * so the session starts; one that cannot be forgotten stays a refusal. */
54802
+ async abandonUnfinishedNativeChoice() {
54803
+ const flow = this.flow;
54804
+ if (!flow.pendingNativeSelection?.() || flow.view().nativeSelection) return;
54805
+ if (!this.installation || !flow.abandonNativeSelection) throw failure2("recovery_required");
54806
+ const abandoned = await flow.abandonNativeSelection(this.installation);
54807
+ this.check();
54808
+ if (!abandoned) throw failure2("recovery_required");
54809
+ }
54733
54810
  holdApprovalWindow(portal) {
54734
54811
  if (this.approvalWindow !== portal) this.closeApprovalWindow();
54735
54812
  this.approvalWindow = portal;