@mdbase-dev/sdk 0.2.65 → 0.2.68

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