@mdbase-dev/sdk 0.2.65 → 0.2.66

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.
@@ -15698,12 +15698,12 @@ function appReleaseTrust() {
15698
15698
  // src/application/asset-pins.json
15699
15699
  var asset_pins_default = {
15700
15700
  runtime: {
15701
- sha256: "044b15729862adabe70cfdd4211dec076790644be4948c4f0d634f44a0d0bd2c",
15702
- bytes: 4139739,
15703
- maxBytes: 4139739,
15701
+ sha256: "706948a8956ce46d7ad10ddee88952f4b48f0f6abe5a7f24cb776580930d3d88",
15702
+ bytes: 4142151,
15703
+ maxBytes: 4142151,
15704
15704
  source: {
15705
15705
  repository: "mdbase-dev/mdbase-connect",
15706
- commit: "e2cc27deeb692eddd893aec98aa228e693092911"
15706
+ commit: "b3b9cc5da096a69df565983808295dc1cdd35f55"
15707
15707
  }
15708
15708
  },
15709
15709
  sqlite: {
@@ -24148,6 +24148,7 @@ function collectionHint(options) {
24148
24148
  function verificationUri(value2, base, hint) {
24149
24149
  return value2 === base || hint !== null && value2 === `${base}?collection_hint=${hint}` ? value2 : null;
24150
24150
  }
24151
+ var replaceRefusedAppInstallation;
24151
24152
  var AppProtectedInstallationSignIn = class _AppProtectedInstallationSignIn {
24152
24153
  constructor(store2, state, options) {
24153
24154
  this.store = store2;
@@ -24161,9 +24162,13 @@ var AppProtectedInstallationSignIn = class _AppProtectedInstallationSignIn {
24161
24162
  store;
24162
24163
  state;
24163
24164
  options;
24165
+ static {
24166
+ replaceRefusedAppInstallation = (flow, stop) => flow.replaceRefusedInstallation(stop);
24167
+ }
24164
24168
  closed = false;
24165
24169
  busy = false;
24166
24170
  nativeAcknowledged = false;
24171
+ credentialRefused = false;
24167
24172
  closedPairing = null;
24168
24173
  /** Definite authenticated pre-proof refusal only, never an HTTP unknown. */
24169
24174
  wrongAccountRequestId = null;
@@ -24193,13 +24198,7 @@ var AppProtectedInstallationSignIn = class _AppProtectedInstallationSignIn {
24193
24198
  if (!isAppEnvironmentSelection(selection) || selection.environment !== p.environment || selection.appOrigin !== p.origin || selection.cpOrigin !== p.cpOrigin || p.allowLoopbackHttp === true && !selection.allowLoopbackHttp) throw fail3("binding");
24194
24199
  }
24195
24200
  opened = await AppInstallationStore.open({ ...p, allowLoopbackHttp: selection?.allowLoopbackHttp ?? p.allowLoopbackHttp }, () => {
24196
- const bytes10 = crypto.getRandomValues(new Uint8Array(32));
24197
- try {
24198
- const secret = `pair_${btoa(String.fromCharCode(...bytes10)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`;
24199
- return new TextEncoder().encode(JSON.stringify({ version: 3, renewal: null, requestedCreateCollections: p.requestedCreateCollections ?? p.freshRequestedCreateCollections ?? false, collectionIds: [], createCollections: false, consentRequest: null, ...p.freshRequestedPrivateDevice === true ? { requestedPrivateDevice: true } : {}, requestId: crypto.randomUUID(), installationId: crypto.randomUUID(), deviceId: crypto.randomUUID(), secret, appId: p.appId, ...p.owner === void 0 ? {} : { owner: p.owner }, kind: p.installationKind ?? "app-runtime", origin: p.origin, cpOrigin: p.cpOrigin, environment: p.environment, selection: null, confirmed: false, nativeStarted: false, proof: null, token: null, ...p.recoveryFor ? { recoveryFor: p.recoveryFor } : {} }));
24200
- } finally {
24201
- bytes10.fill(0);
24202
- }
24201
+ return new TextEncoder().encode(JSON.stringify(this.freshState(p)));
24203
24202
  });
24204
24203
  const state = this.decode(opened.plaintext, p);
24205
24204
  return new _AppProtectedInstallationSignIn(opened.store, state, p);
@@ -24212,6 +24211,15 @@ var AppProtectedInstallationSignIn = class _AppProtectedInstallationSignIn {
24212
24211
  opened?.plaintext.fill(0);
24213
24212
  }
24214
24213
  }
24214
+ static freshState(p) {
24215
+ const bytes10 = crypto.getRandomValues(new Uint8Array(32));
24216
+ try {
24217
+ const secret = `pair_${btoa(String.fromCharCode(...bytes10)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`;
24218
+ return { version: 3, renewal: null, requestedCreateCollections: p.requestedCreateCollections ?? p.freshRequestedCreateCollections ?? false, collectionIds: [], createCollections: false, consentRequest: null, ...p.freshRequestedPrivateDevice === true ? { requestedPrivateDevice: true } : {}, requestId: crypto.randomUUID(), installationId: crypto.randomUUID(), deviceId: crypto.randomUUID(), secret, appId: p.appId, ...p.owner === void 0 ? {} : { owner: p.owner }, kind: p.installationKind ?? "app-runtime", origin: p.origin, cpOrigin: p.cpOrigin, environment: p.environment, selection: null, confirmed: false, nativeStarted: false, proof: null, token: null, ...p.recoveryFor ? { recoveryFor: p.recoveryFor } : {} };
24219
+ } finally {
24220
+ bytes10.fill(0);
24221
+ }
24222
+ }
24215
24223
  static decode(bytes10, p) {
24216
24224
  const parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes10));
24217
24225
  const base = "version,requestId,installationId,deviceId,secret,appId,kind,origin,cpOrigin,environment,selection,confirmed,nativeStarted,proof,token";
@@ -24422,6 +24430,7 @@ var AppProtectedInstallationSignIn = class _AppProtectedInstallationSignIn {
24422
24430
  throw fail3(reason);
24423
24431
  }
24424
24432
  const server = appServerProblem(response2.status, value2, response2.headers);
24433
+ if (this.state.token && auth?.bearer === this.state.token && server.status === 401 && server.code === "invalid_connector") this.credentialRefused = true;
24425
24434
  const refusal2 = new AppInstallationSignInError(appServerOutcome(server) ?? "refused", server);
24426
24435
  if (path === "/v1/pairing-requests" && unknownPrivateDeviceField(response2.status, error4)) privateDeviceFieldRefused.add(refusal2);
24427
24436
  throw refusal2;
@@ -24452,6 +24461,19 @@ var AppProtectedInstallationSignIn = class _AppProtectedInstallationSignIn {
24452
24461
  }
24453
24462
  return this.exclusive(() => this.startRequest(hint));
24454
24463
  }
24464
+ /** Replace the protected identity in place under the sign-in ledger lease.
24465
+ * The old replica and custody stores remain under the original IDs.
24466
+ */
24467
+ replaceRefusedInstallation(stop) {
24468
+ return this.exclusive(async () => {
24469
+ if (!this.credentialRefused || !this.state.token || Object.values(this.state.collectionRecoveries ?? {}).some((reference) => reference !== null)) throw fail3("recovery_required");
24470
+ await stop();
24471
+ await this.save(_AppProtectedInstallationSignIn.freshState(this.options));
24472
+ this.credentialRefused = false;
24473
+ this.nativeAcknowledged = false;
24474
+ this.closedPairing = null;
24475
+ });
24476
+ }
24455
24477
  /** Explicit user retry after an exact typed expiry. Renew ONLY the pairing
24456
24478
  * window; installation/device/account/challenge/keys/proof remain original.
24457
24479
  * Persist the new request and its parent capability BEFORE HTTP. Unknown
@@ -38861,7 +38883,11 @@ var closedView = Object.freeze({ status: "unselected", problem: null, transport:
38861
38883
  var failure = (reason) => new AppInstallationSignInError(reason);
38862
38884
  var keptDetail = (update, previous, detail) => update.problem === void 0 || update.problem === previous ? detail : void 0;
38863
38885
  var liveOutcomes = /* @__PURE__ */ new Set(["collection_not_yet_migrated", "collection_migrating", "account_suspended", "update_required"]);
38886
+ var authorizeAppWebInstallation;
38864
38887
  var AppWebSignInSession = class {
38888
+ static {
38889
+ authorizeAppWebInstallation = (session, options, recoverScope) => session.authorizeInstallation(options, recoverScope);
38890
+ }
38865
38891
  lifetime = new AbortController();
38866
38892
  // Origin store closes only AFTER native shutdown, not on the host abort.
38867
38893
  // Replaced by signOut, so Sign in works again in the same session.
@@ -39118,13 +39144,15 @@ var AppWebSignInSession = class {
39118
39144
  /** Call from the app's single sign-in user gesture after start(). No manual
39119
39145
  * exchange, confirmation or attestation controls are needed by consumers. */
39120
39146
  authorize(options = {}) {
39147
+ return this.authorizeInstallation(options, false);
39148
+ }
39149
+ authorizeInstallation(options, recoverScope) {
39121
39150
  this.check();
39122
- if (this.base.problem === "installation_removed") return Promise.reject(failure("refused"));
39123
39151
  if (this.authorizationRateLimit && Date.now() < this.authorizationRetryAt) return Promise.reject(this.authorizationRateLimit);
39124
39152
  const poll = this.pending !== null && this.pending === this.polling ? this.pending : null;
39125
39153
  if (!this.flow || this.pending && !poll) return Promise.reject(failure("busy"));
39126
39154
  const portal = this.options.openPortal();
39127
- if (!poll) return this.beginAuthorization(portal, options);
39155
+ if (!poll) return this.beginAuthorization(portal, options, recoverScope);
39128
39156
  return poll.catch(() => {
39129
39157
  }).then(() => {
39130
39158
  try {
@@ -39142,37 +39170,41 @@ var AppWebSignInSession = class {
39142
39170
  portal.close();
39143
39171
  return this.getSnapshot();
39144
39172
  }
39145
- return this.beginAuthorization(portal, options);
39173
+ return this.beginAuthorization(portal, options, recoverScope);
39146
39174
  });
39147
39175
  }
39148
- beginAuthorization(portal, options) {
39176
+ beginAuthorization(portal, options, recoverScope) {
39149
39177
  const hint = { collectionHint: options.collectionHint ?? null };
39150
- const view = this.flow.view();
39151
39178
  this.restoredPending = false;
39152
39179
  this.authorizationStartedAt = performance.now();
39153
39180
  this.publish({ timing: Object.freeze({ firstScreenMs: null, readyMs: null }), approval: null });
39154
39181
  return this.operation(async () => {
39155
39182
  try {
39156
- if (view.state === "paired") {
39183
+ if (this.base.problem === "installation_removed") await this.replaceRemovedInstallation();
39184
+ let verificationUri2 = null;
39185
+ if (this.flow.view().state === "paired") {
39157
39186
  await this.openDevice();
39158
39187
  this.check();
39159
39188
  await this.abandonUnfinishedNativeChoice();
39160
- let consent;
39161
39189
  try {
39162
- consent = await this.flow.startCollectionConsent(this.installation, this.options.requestedCreateCollections ?? this.options.freshRequestedCreateCollections ?? false, hint, this.options.freshRequestedPrivateDevice === true);
39190
+ const consent = await this.flow.startCollectionConsent(this.installation, this.options.requestedCreateCollections ?? this.options.freshRequestedCreateCollections ?? false, hint, this.options.freshRequestedPrivateDevice === true);
39191
+ this.consentPending = true;
39192
+ verificationUri2 = consent.verificationUri;
39163
39193
  } catch (error4) {
39164
39194
  if (!await this.handleRemovedInstallation(error4)) throw error4;
39165
- portal.close();
39166
- return this.getSnapshot();
39195
+ if (recoverScope) {
39196
+ portal.close();
39197
+ return this.getSnapshot();
39198
+ }
39199
+ await this.replaceRemovedInstallation();
39167
39200
  }
39168
- this.check();
39169
- this.consentPending = true;
39170
- portal.navigate(consent.verificationUri);
39171
- } else {
39201
+ }
39202
+ if (verificationUri2 === null) {
39172
39203
  const started = await this.flow.start(hint).catch((error4) => this.renewFromGesture(error4));
39173
- this.check();
39174
- portal.navigate(started.verificationUri);
39204
+ verificationUri2 = started.verificationUri;
39175
39205
  }
39206
+ this.check();
39207
+ portal.navigate(verificationUri2);
39176
39208
  this.holdApprovalWindow(portal);
39177
39209
  this.publish({ status: "authorizing", problem: null });
39178
39210
  await this.advance();
@@ -39535,7 +39567,8 @@ var AppWebSignInSession = class {
39535
39567
  const scope = Object.freeze({ account: selected.accountId, installation: selected.installationId });
39536
39568
  this.installationLease = await acquireAppInstallationLease(this.options.locks, scope, this.lifetime.signal);
39537
39569
  this.check();
39538
- this.installation = Object.freeze({ scope, isCurrent: () => !this.closing && !this.options.signal.aborted && !this.lifetime.signal.aborted && this.installationLease !== null });
39570
+ const lease = this.installationLease;
39571
+ this.installation = Object.freeze({ scope, isCurrent: () => !this.closing && !this.options.signal.aborted && !this.lifetime.signal.aborted && this.installationLease === lease });
39539
39572
  }
39540
39573
  if (metadataOnly) return;
39541
39574
  if (!this.host && !forCollection && this.acknowledged && this.flow.view().state === "paired" && [...this.slots.values()].some((slot) => slot.host !== null)) return;
@@ -39611,6 +39644,30 @@ var AppWebSignInSession = class {
39611
39644
  this.changed();
39612
39645
  return true;
39613
39646
  }
39647
+ async replaceRemovedInstallation() {
39648
+ const flow = this.flow;
39649
+ try {
39650
+ await replaceRefusedAppInstallation(flow, async () => {
39651
+ await this.closeSlots();
39652
+ this.check();
39653
+ await this.installationLease?.release();
39654
+ this.installationLease = null;
39655
+ this.installation = null;
39656
+ this.check();
39657
+ });
39658
+ } catch (error4) {
39659
+ if (!flow.isCurrent()) this.flow = null;
39660
+ throw error4;
39661
+ }
39662
+ this.check();
39663
+ this.attested = false;
39664
+ this.acknowledged = false;
39665
+ this.freshApproval = false;
39666
+ this.fileAccess = null;
39667
+ this.forgotten.clear();
39668
+ this.removedScopes.clear();
39669
+ this.publish({ status: "signed_out", problem: null, fileAccess: void 0 });
39670
+ }
39614
39671
  schedulePoll() {
39615
39672
  if (this.pending && !this.closing && !this.options.signal.aborted) return;
39616
39673
  const read = this.foregroundRead;
@@ -40048,9 +40105,8 @@ var AppWebSignInSession = class {
40048
40105
  await this.closeSlot(slot);
40049
40106
  this.deleteSlot(slot);
40050
40107
  }
40051
- const host = this.host;
40108
+ await this.host?.close();
40052
40109
  this.host = null;
40053
- await host?.close();
40054
40110
  }
40055
40111
  clearSelection() {
40056
40112
  return this.operation(async () => {
@@ -40455,7 +40511,8 @@ var AppScopedSignInSession = class {
40455
40511
  const context = this.original.scopeRecoveryContext(), actor = id4 === null ? void 0 : this.scoped.get(id4);
40456
40512
  if (id4 === null || !context || !Object.hasOwn(context.references, id4) && !this.removed(this.original, id4)) {
40457
40513
  this.approvalOwner = this.original;
40458
- await this.original.authorize(options);
40514
+ const recoverScope = id4 !== null && (!this.original.collectionListCached() && this.original.connection(id4) !== null || Object.values(context?.references ?? {}).some((reference2) => reference2 !== null));
40515
+ await authorizeAppWebInstallation(this.original, options, recoverScope);
40459
40516
  this.check();
40460
40517
  return this.getSnapshot();
40461
40518
  }
@@ -40660,6 +40717,7 @@ var SqliteIndex = class _SqliteIndex {
40660
40717
  const synchronous = opts.synchronous ?? "NORMAL";
40661
40718
  if (synchronous !== "NORMAL" && synchronous !== "FULL") throw new IndexError("Other", "unsupported synchronous profile");
40662
40719
  if (opts.pragmas !== false) {
40720
+ db.exec("PRAGMA page_size=32768");
40663
40721
  db.exec("PRAGMA locking_mode=EXCLUSIVE");
40664
40722
  db.exec("PRAGMA journal_mode=WAL");
40665
40723
  db.exec(`PRAGMA synchronous=${synchronous}`);
@@ -27243,7 +27243,7 @@ ${end.comment}` : end.comment;
27243
27243
  function verificationUri(value2, base, hint) {
27244
27244
  return value2 === base || hint !== null && value2 === `${base}?collection_hint=${hint}` ? value2 : null;
27245
27245
  }
27246
- var AppInstallationSignInError, fail3, nonOkResponses, privateDeviceFieldRefused, hex2, UUID4, FILE_ACTIONS, AppProtectedInstallationSignIn;
27246
+ var AppInstallationSignInError, fail3, nonOkResponses, privateDeviceFieldRefused, hex2, UUID4, FILE_ACTIONS, replaceRefusedAppInstallation, AppProtectedInstallationSignIn;
27247
27247
  var init_installation_sign_in = __esm({
27248
27248
  "src/app-host/installation-sign-in.ts"() {
27249
27249
  "use strict";
@@ -27285,9 +27285,13 @@ ${end.comment}` : end.comment;
27285
27285
  store;
27286
27286
  state;
27287
27287
  options;
27288
+ static {
27289
+ replaceRefusedAppInstallation = (flow, stop) => flow.replaceRefusedInstallation(stop);
27290
+ }
27288
27291
  closed = false;
27289
27292
  busy = false;
27290
27293
  nativeAcknowledged = false;
27294
+ credentialRefused = false;
27291
27295
  closedPairing = null;
27292
27296
  /** Definite authenticated pre-proof refusal only, never an HTTP unknown. */
27293
27297
  wrongAccountRequestId = null;
@@ -27317,13 +27321,7 @@ ${end.comment}` : end.comment;
27317
27321
  if (!isAppEnvironmentSelection(selection) || selection.environment !== p.environment || selection.appOrigin !== p.origin || selection.cpOrigin !== p.cpOrigin || p.allowLoopbackHttp === true && !selection.allowLoopbackHttp) throw fail3("binding");
27318
27322
  }
27319
27323
  opened = await AppInstallationStore.open({ ...p, allowLoopbackHttp: selection?.allowLoopbackHttp ?? p.allowLoopbackHttp }, () => {
27320
- const bytes10 = crypto.getRandomValues(new Uint8Array(32));
27321
- try {
27322
- const secret = `pair_${btoa(String.fromCharCode(...bytes10)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`;
27323
- return new TextEncoder().encode(JSON.stringify({ version: 3, renewal: null, requestedCreateCollections: p.requestedCreateCollections ?? p.freshRequestedCreateCollections ?? false, collectionIds: [], createCollections: false, consentRequest: null, ...p.freshRequestedPrivateDevice === true ? { requestedPrivateDevice: true } : {}, requestId: crypto.randomUUID(), installationId: crypto.randomUUID(), deviceId: crypto.randomUUID(), secret, appId: p.appId, ...p.owner === void 0 ? {} : { owner: p.owner }, kind: p.installationKind ?? "app-runtime", origin: p.origin, cpOrigin: p.cpOrigin, environment: p.environment, selection: null, confirmed: false, nativeStarted: false, proof: null, token: null, ...p.recoveryFor ? { recoveryFor: p.recoveryFor } : {} }));
27324
- } finally {
27325
- bytes10.fill(0);
27326
- }
27324
+ return new TextEncoder().encode(JSON.stringify(this.freshState(p)));
27327
27325
  });
27328
27326
  const state2 = this.decode(opened.plaintext, p);
27329
27327
  return new _AppProtectedInstallationSignIn(opened.store, state2, p);
@@ -27336,6 +27334,15 @@ ${end.comment}` : end.comment;
27336
27334
  opened?.plaintext.fill(0);
27337
27335
  }
27338
27336
  }
27337
+ static freshState(p) {
27338
+ const bytes10 = crypto.getRandomValues(new Uint8Array(32));
27339
+ try {
27340
+ const secret = `pair_${btoa(String.fromCharCode(...bytes10)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "")}`;
27341
+ return { version: 3, renewal: null, requestedCreateCollections: p.requestedCreateCollections ?? p.freshRequestedCreateCollections ?? false, collectionIds: [], createCollections: false, consentRequest: null, ...p.freshRequestedPrivateDevice === true ? { requestedPrivateDevice: true } : {}, requestId: crypto.randomUUID(), installationId: crypto.randomUUID(), deviceId: crypto.randomUUID(), secret, appId: p.appId, ...p.owner === void 0 ? {} : { owner: p.owner }, kind: p.installationKind ?? "app-runtime", origin: p.origin, cpOrigin: p.cpOrigin, environment: p.environment, selection: null, confirmed: false, nativeStarted: false, proof: null, token: null, ...p.recoveryFor ? { recoveryFor: p.recoveryFor } : {} };
27342
+ } finally {
27343
+ bytes10.fill(0);
27344
+ }
27345
+ }
27339
27346
  static decode(bytes10, p) {
27340
27347
  const parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes10));
27341
27348
  const base = "version,requestId,installationId,deviceId,secret,appId,kind,origin,cpOrigin,environment,selection,confirmed,nativeStarted,proof,token";
@@ -27546,6 +27553,7 @@ ${end.comment}` : end.comment;
27546
27553
  throw fail3(reason);
27547
27554
  }
27548
27555
  const server = appServerProblem(response2.status, value2, response2.headers);
27556
+ if (this.state.token && auth?.bearer === this.state.token && server.status === 401 && server.code === "invalid_connector") this.credentialRefused = true;
27549
27557
  const refusal2 = new AppInstallationSignInError(appServerOutcome(server) ?? "refused", server);
27550
27558
  if (path === "/v1/pairing-requests" && unknownPrivateDeviceField(response2.status, error5)) privateDeviceFieldRefused.add(refusal2);
27551
27559
  throw refusal2;
@@ -27576,6 +27584,19 @@ ${end.comment}` : end.comment;
27576
27584
  }
27577
27585
  return this.exclusive(() => this.startRequest(hint));
27578
27586
  }
27587
+ /** Replace the protected identity in place under the sign-in ledger lease.
27588
+ * The old replica and custody stores remain under the original IDs.
27589
+ */
27590
+ replaceRefusedInstallation(stop) {
27591
+ return this.exclusive(async () => {
27592
+ if (!this.credentialRefused || !this.state.token || Object.values(this.state.collectionRecoveries ?? {}).some((reference) => reference !== null)) throw fail3("recovery_required");
27593
+ await stop();
27594
+ await this.save(_AppProtectedInstallationSignIn.freshState(this.options));
27595
+ this.credentialRefused = false;
27596
+ this.nativeAcknowledged = false;
27597
+ this.closedPairing = null;
27598
+ });
27599
+ }
27579
27600
  /** Explicit user retry after an exact typed expiry. Renew ONLY the pairing
27580
27601
  * window; installation/device/account/challenge/keys/proof remain original.
27581
27602
  * Persist the new request and its parent capability BEFORE HTTP. Unknown
@@ -30019,6 +30040,7 @@ ${end.comment}` : end.comment;
30019
30040
  const synchronous = opts.synchronous ?? "NORMAL";
30020
30041
  if (synchronous !== "NORMAL" && synchronous !== "FULL") throw new IndexError("Other", "unsupported synchronous profile");
30021
30042
  if (opts.pragmas !== false) {
30043
+ db.exec("PRAGMA page_size=32768");
30022
30044
  db.exec("PRAGMA locking_mode=EXCLUSIVE");
30023
30045
  db.exec("PRAGMA journal_mode=WAL");
30024
30046
  db.exec(`PRAGMA synchronous=${synchronous}`);
@@ -51215,12 +51237,12 @@ ${end.comment}` : end.comment;
51215
51237
  // src/application/asset-pins.json
51216
51238
  var asset_pins_default = {
51217
51239
  runtime: {
51218
- sha256: "044b15729862adabe70cfdd4211dec076790644be4948c4f0d634f44a0d0bd2c",
51219
- bytes: 4139739,
51220
- maxBytes: 4139739,
51240
+ sha256: "706948a8956ce46d7ad10ddee88952f4b48f0f6abe5a7f24cb776580930d3d88",
51241
+ bytes: 4142151,
51242
+ maxBytes: 4142151,
51221
51243
  source: {
51222
51244
  repository: "mdbase-dev/mdbase-connect",
51223
- commit: "e2cc27deeb692eddd893aec98aa228e693092911"
51245
+ commit: "b3b9cc5da096a69df565983808295dc1cdd35f55"
51224
51246
  }
51225
51247
  },
51226
51248
  sqlite: {
@@ -55062,7 +55084,11 @@ ${end.comment}` : end.comment;
55062
55084
  var failure2 = (reason) => new AppInstallationSignInError(reason);
55063
55085
  var keptDetail = (update, previous, detail) => update.problem === void 0 || update.problem === previous ? detail : void 0;
55064
55086
  var liveOutcomes = /* @__PURE__ */ new Set(["collection_not_yet_migrated", "collection_migrating", "account_suspended", "update_required"]);
55087
+ var authorizeAppWebInstallation;
55065
55088
  var AppWebSignInSession = class {
55089
+ static {
55090
+ authorizeAppWebInstallation = (session, options, recoverScope) => session.authorizeInstallation(options, recoverScope);
55091
+ }
55066
55092
  lifetime = new AbortController();
55067
55093
  // Origin store closes only AFTER native shutdown, not on the host abort.
55068
55094
  // Replaced by signOut, so Sign in works again in the same session.
@@ -55319,13 +55345,15 @@ ${end.comment}` : end.comment;
55319
55345
  /** Call from the app's single sign-in user gesture after start(). No manual
55320
55346
  * exchange, confirmation or attestation controls are needed by consumers. */
55321
55347
  authorize(options = {}) {
55348
+ return this.authorizeInstallation(options, false);
55349
+ }
55350
+ authorizeInstallation(options, recoverScope) {
55322
55351
  this.check();
55323
- if (this.base.problem === "installation_removed") return Promise.reject(failure2("refused"));
55324
55352
  if (this.authorizationRateLimit && Date.now() < this.authorizationRetryAt) return Promise.reject(this.authorizationRateLimit);
55325
55353
  const poll = this.pending !== null && this.pending === this.polling ? this.pending : null;
55326
55354
  if (!this.flow || this.pending && !poll) return Promise.reject(failure2("busy"));
55327
55355
  const portal = this.options.openPortal();
55328
- if (!poll) return this.beginAuthorization(portal, options);
55356
+ if (!poll) return this.beginAuthorization(portal, options, recoverScope);
55329
55357
  return poll.catch(() => {
55330
55358
  }).then(() => {
55331
55359
  try {
@@ -55343,37 +55371,41 @@ ${end.comment}` : end.comment;
55343
55371
  portal.close();
55344
55372
  return this.getSnapshot();
55345
55373
  }
55346
- return this.beginAuthorization(portal, options);
55374
+ return this.beginAuthorization(portal, options, recoverScope);
55347
55375
  });
55348
55376
  }
55349
- beginAuthorization(portal, options) {
55377
+ beginAuthorization(portal, options, recoverScope) {
55350
55378
  const hint = { collectionHint: options.collectionHint ?? null };
55351
- const view2 = this.flow.view();
55352
55379
  this.restoredPending = false;
55353
55380
  this.authorizationStartedAt = performance.now();
55354
55381
  this.publish({ timing: Object.freeze({ firstScreenMs: null, readyMs: null }), approval: null });
55355
55382
  return this.operation(async () => {
55356
55383
  try {
55357
- if (view2.state === "paired") {
55384
+ if (this.base.problem === "installation_removed") await this.replaceRemovedInstallation();
55385
+ let verificationUri2 = null;
55386
+ if (this.flow.view().state === "paired") {
55358
55387
  await this.openDevice();
55359
55388
  this.check();
55360
55389
  await this.abandonUnfinishedNativeChoice();
55361
- let consent;
55362
55390
  try {
55363
- consent = await this.flow.startCollectionConsent(this.installation, this.options.requestedCreateCollections ?? this.options.freshRequestedCreateCollections ?? false, hint, this.options.freshRequestedPrivateDevice === true);
55391
+ const consent = await this.flow.startCollectionConsent(this.installation, this.options.requestedCreateCollections ?? this.options.freshRequestedCreateCollections ?? false, hint, this.options.freshRequestedPrivateDevice === true);
55392
+ this.consentPending = true;
55393
+ verificationUri2 = consent.verificationUri;
55364
55394
  } catch (error5) {
55365
55395
  if (!await this.handleRemovedInstallation(error5)) throw error5;
55366
- portal.close();
55367
- return this.getSnapshot();
55396
+ if (recoverScope) {
55397
+ portal.close();
55398
+ return this.getSnapshot();
55399
+ }
55400
+ await this.replaceRemovedInstallation();
55368
55401
  }
55369
- this.check();
55370
- this.consentPending = true;
55371
- portal.navigate(consent.verificationUri);
55372
- } else {
55402
+ }
55403
+ if (verificationUri2 === null) {
55373
55404
  const started = await this.flow.start(hint).catch((error5) => this.renewFromGesture(error5));
55374
- this.check();
55375
- portal.navigate(started.verificationUri);
55405
+ verificationUri2 = started.verificationUri;
55376
55406
  }
55407
+ this.check();
55408
+ portal.navigate(verificationUri2);
55377
55409
  this.holdApprovalWindow(portal);
55378
55410
  this.publish({ status: "authorizing", problem: null });
55379
55411
  await this.advance();
@@ -55736,7 +55768,8 @@ ${end.comment}` : end.comment;
55736
55768
  const scope = Object.freeze({ account: selected.accountId, installation: selected.installationId });
55737
55769
  this.installationLease = await acquireAppInstallationLease(this.options.locks, scope, this.lifetime.signal);
55738
55770
  this.check();
55739
- this.installation = Object.freeze({ scope, isCurrent: () => !this.closing && !this.options.signal.aborted && !this.lifetime.signal.aborted && this.installationLease !== null });
55771
+ const lease = this.installationLease;
55772
+ this.installation = Object.freeze({ scope, isCurrent: () => !this.closing && !this.options.signal.aborted && !this.lifetime.signal.aborted && this.installationLease === lease });
55740
55773
  }
55741
55774
  if (metadataOnly) return;
55742
55775
  if (!this.host && !forCollection && this.acknowledged && this.flow.view().state === "paired" && [...this.slots.values()].some((slot) => slot.host !== null)) return;
@@ -55812,6 +55845,30 @@ ${end.comment}` : end.comment;
55812
55845
  this.changed();
55813
55846
  return true;
55814
55847
  }
55848
+ async replaceRemovedInstallation() {
55849
+ const flow = this.flow;
55850
+ try {
55851
+ await replaceRefusedAppInstallation(flow, async () => {
55852
+ await this.closeSlots();
55853
+ this.check();
55854
+ await this.installationLease?.release();
55855
+ this.installationLease = null;
55856
+ this.installation = null;
55857
+ this.check();
55858
+ });
55859
+ } catch (error5) {
55860
+ if (!flow.isCurrent()) this.flow = null;
55861
+ throw error5;
55862
+ }
55863
+ this.check();
55864
+ this.attested = false;
55865
+ this.acknowledged = false;
55866
+ this.freshApproval = false;
55867
+ this.fileAccess = null;
55868
+ this.forgotten.clear();
55869
+ this.removedScopes.clear();
55870
+ this.publish({ status: "signed_out", problem: null, fileAccess: void 0 });
55871
+ }
55815
55872
  schedulePoll() {
55816
55873
  if (this.pending && !this.closing && !this.options.signal.aborted) return;
55817
55874
  const read2 = this.foregroundRead;
@@ -56249,9 +56306,8 @@ ${end.comment}` : end.comment;
56249
56306
  await this.closeSlot(slot);
56250
56307
  this.deleteSlot(slot);
56251
56308
  }
56252
- const host = this.host;
56309
+ await this.host?.close();
56253
56310
  this.host = null;
56254
- await host?.close();
56255
56311
  }
56256
56312
  clearSelection() {
56257
56313
  return this.operation(async () => {