@mdbase-dev/sdk 0.2.76 → 0.2.78
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.
- package/dist/app-grant/client.js +42 -22
- package/dist/app-grant/client.js.map +1 -1
- package/dist/app-host/web-sign-in-session.js +3 -3
- package/dist/app-host/web-sign-in-session.js.map +1 -1
- package/dist/application/asset-pins.json +4 -4
- package/dist/application/collection-selection.d.ts +2 -2
- package/dist/application/collection-selection.js +11 -6
- package/dist/application/collection-selection.js.map +1 -1
- package/dist/application/entry.d.ts +2 -2
- package/dist/application/entry.js +12 -4
- package/dist/application/entry.js.map +1 -1
- package/dist/application/phase.js +4 -0
- package/dist/application/phase.js.map +1 -1
- package/dist/application/private-collections.d.ts +4 -7
- package/dist/application/private-collections.js +41 -20
- package/dist/application/private-collections.js.map +1 -1
- package/dist/application/return-url.d.ts +3 -0
- package/dist/application/return-url.js +21 -0
- package/dist/application/return-url.js.map +1 -1
- package/dist/application/worker.js +33 -29
- package/dist/browser/mdbase-sdk.js +177 -108
- package/dist/browser/mdbase-sdk.min.js +60 -60
- package/dist/cbor.js +3 -4
- package/dist/cbor.js.map +1 -1
- package/dist/describe-error.d.ts +1 -1
- package/dist/describe-error.js +2 -1
- package/dist/describe-error.js.map +1 -1
- package/dist/native/provenance.json +5 -5
- package/dist/native/runtime.wasm +0 -0
- package/node_modules/@mdbase-dev/connect-protocol/dist/application-authorization.js +6 -9
- package/node_modules/@mdbase-dev/connect-protocol/dist/manifest.js +35 -24
- package/node_modules/@mdbase-dev/connect-protocol/dist/mutation-fingerprint.js +4 -12
- package/package.json +2 -2
- package/vendor/mdbase-connect-sdk-9b36f55c7774.json +13 -0
- package/vendor/mdbase-dev-connect-protocol-0.1.0-beta.152-9b36f55c7774.tgz +0 -0
- package/vendor/mdbase-connect-sdk-3d3f95b80c9a.json +0 -13
- package/vendor/mdbase-dev-connect-protocol-0.1.0-beta.152-3d3f95b80c9a.tgz +0 -0
|
@@ -118,11 +118,10 @@ var MdbaseSDK = (() => {
|
|
|
118
118
|
}
|
|
119
119
|
return true;
|
|
120
120
|
}
|
|
121
|
-
function encodeInt(w,
|
|
122
|
-
const big = typeof v === "bigint" ? v : BigInt(v);
|
|
121
|
+
function encodeInt(w, big) {
|
|
123
122
|
if (big >= 0n) {
|
|
124
123
|
if (big > U64_MAX) throw new CborError("unencodable", "integer above 2^64-1");
|
|
125
|
-
w.head(0,
|
|
124
|
+
w.head(0, big);
|
|
126
125
|
} else {
|
|
127
126
|
if (big < I64_MIN) throw new CborError("unencodable", "integer below -2^63");
|
|
128
127
|
const n = -1n - big;
|
|
@@ -180,7 +179,7 @@ var MdbaseSDK = (() => {
|
|
|
180
179
|
case "boolean":
|
|
181
180
|
return w.byte(v ? 245 : 244);
|
|
182
181
|
case "number":
|
|
183
|
-
if (Number.isSafeInteger(v) && !Object.is(v, -0)) return
|
|
182
|
+
if (Number.isSafeInteger(v) && !Object.is(v, -0)) return v >= 0 ? w.head(0, v) : w.head(1, -1 - v);
|
|
184
183
|
return w.float(v);
|
|
185
184
|
case "bigint":
|
|
186
185
|
return encodeInt(w, v);
|
|
@@ -9891,6 +9890,7 @@ var MdbaseSDK = (() => {
|
|
|
9891
9890
|
"refused",
|
|
9892
9891
|
"expired",
|
|
9893
9892
|
"approval_window_closed",
|
|
9893
|
+
"private_authorization_failed",
|
|
9894
9894
|
"account_confirmation_required",
|
|
9895
9895
|
"recovery_required",
|
|
9896
9896
|
"installation_removed",
|
|
@@ -10031,6 +10031,7 @@ var MdbaseSDK = (() => {
|
|
|
10031
10031
|
installation_removed: ["This app's access was removed", "Sign out of this app on this device, then sign in to approve a new installation.", "none", "warning"],
|
|
10032
10032
|
expired: ["Sign-in timed out", "The sign-in request expired. Start again to get a new one.", "sign_in", "warning"],
|
|
10033
10033
|
approval_window_closed: ["Sign-in wasn't finished", "The mdbase window was closed before access was approved. Sign in again to continue.", "sign_in", "info"],
|
|
10034
|
+
private_authorization_failed: ["Couldn't prepare Private collection access", "This app couldn't prepare its authorization request. Check for an app update and start sign-in again.", "update_app", "warning"],
|
|
10034
10035
|
account_confirmation_required: ["Confirm your account", "Confirm which mdbase account to use, then continue.", "sign_in", "info"],
|
|
10035
10036
|
recovery_account_mismatch: ["Use a different account", "Sign in with the account you originally used for this collection to continue.", "approve", "info", false, "Use a different account"],
|
|
10036
10037
|
recovery_required: ["Reload required", "The app stopped to keep your data safe. Reload to continue.", "reload", "error"],
|
|
@@ -25031,10 +25032,11 @@ ${end.comment}` : end.comment;
|
|
|
25031
25032
|
});
|
|
25032
25033
|
|
|
25033
25034
|
// node_modules/@mdbase-dev/connect-protocol/dist/mutation-fingerprint.js
|
|
25034
|
-
var encoder;
|
|
25035
|
+
var encoder, isWellFormed2;
|
|
25035
25036
|
var init_mutation_fingerprint = __esm({
|
|
25036
25037
|
"node_modules/@mdbase-dev/connect-protocol/dist/mutation-fingerprint.js"() {
|
|
25037
25038
|
encoder = new TextEncoder();
|
|
25039
|
+
({ isWellFormed: isWellFormed2 } = String.prototype);
|
|
25038
25040
|
}
|
|
25039
25041
|
});
|
|
25040
25042
|
|
|
@@ -25196,10 +25198,13 @@ ${end.comment}` : end.comment;
|
|
|
25196
25198
|
throw new Error("Invalid base64url value.");
|
|
25197
25199
|
const normalized = value2.replaceAll("-", "+").replaceAll("_", "/");
|
|
25198
25200
|
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
|
|
25199
|
-
const
|
|
25200
|
-
if (
|
|
25201
|
+
const binary2 = atob(padded);
|
|
25202
|
+
if (btoa(binary2) !== padded)
|
|
25201
25203
|
throw new Error("Non-canonical base64url value.");
|
|
25202
|
-
|
|
25204
|
+
const bytes10 = new Uint8Array(binary2.length);
|
|
25205
|
+
for (let index = 0; index < binary2.length; index++)
|
|
25206
|
+
bytes10[index] = binary2.charCodeAt(index);
|
|
25207
|
+
return bytes10;
|
|
25203
25208
|
}
|
|
25204
25209
|
function uuidBytes(value2) {
|
|
25205
25210
|
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(value2)) {
|
|
@@ -25231,9 +25236,6 @@ ${end.comment}` : end.comment;
|
|
|
25231
25236
|
}
|
|
25232
25237
|
return output;
|
|
25233
25238
|
}
|
|
25234
|
-
function base64Url(value2) {
|
|
25235
|
-
return btoa(String.fromCharCode(...value2)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
|
|
25236
|
-
}
|
|
25237
25239
|
function equalBytes(left, right) {
|
|
25238
25240
|
return left.byteLength === right.byteLength && left.every((value2, index) => value2 === right[index]);
|
|
25239
25241
|
}
|
|
@@ -25407,36 +25409,40 @@ ${end.comment}` : end.comment;
|
|
|
25407
25409
|
return `${parent}/${escaped}`;
|
|
25408
25410
|
}
|
|
25409
25411
|
function validateSerializedSize(value2, maxBytes2) {
|
|
25410
|
-
const jsonIssue = validateJsonValue(value2,
|
|
25412
|
+
const jsonIssue = validateJsonValue(value2, /* @__PURE__ */ new WeakSet());
|
|
25411
25413
|
if (jsonIssue)
|
|
25412
|
-
return jsonIssue;
|
|
25414
|
+
return { ...jsonIssue, path: jsonIssue.path || "/" };
|
|
25413
25415
|
try {
|
|
25414
25416
|
const serialized = JSON.stringify(value2);
|
|
25417
|
+
if (serialized.length * 3 <= maxBytes2)
|
|
25418
|
+
return void 0;
|
|
25415
25419
|
const bytes10 = new TextEncoder().encode(serialized).byteLength;
|
|
25416
25420
|
return bytes10 <= maxBytes2 ? void 0 : issue2("/", "maxBytes", `must not exceed ${maxBytes2} UTF-8 bytes`, { maxBytes: maxBytes2, actualBytes: bytes10 });
|
|
25417
25421
|
} catch {
|
|
25418
25422
|
return issue2("/", "json", "must be serializable as JSON");
|
|
25419
25423
|
}
|
|
25420
25424
|
}
|
|
25421
|
-
function validateJsonValue(value2,
|
|
25425
|
+
function validateJsonValue(value2, ancestors) {
|
|
25422
25426
|
if (value2 === null || typeof value2 === "string" || typeof value2 === "boolean" || typeof value2 === "number" && Number.isFinite(value2))
|
|
25423
25427
|
return void 0;
|
|
25424
25428
|
if (typeof value2 !== "object") {
|
|
25425
|
-
return issue2(
|
|
25429
|
+
return issue2("", "json", "must be a JSON value");
|
|
25426
25430
|
}
|
|
25427
25431
|
if (ancestors.has(value2)) {
|
|
25428
|
-
return issue2(
|
|
25432
|
+
return issue2("", "json", "must not contain circular references");
|
|
25429
25433
|
}
|
|
25430
25434
|
const prototype = Object.getPrototypeOf(value2);
|
|
25431
25435
|
if (!Array.isArray(value2) && prototype !== Object.prototype && prototype !== null) {
|
|
25432
|
-
return issue2(
|
|
25436
|
+
return issue2("", "json", "must be a plain JSON object");
|
|
25433
25437
|
}
|
|
25434
25438
|
ancestors.add(value2);
|
|
25435
|
-
const entries = Array.isArray(value2) ?
|
|
25439
|
+
const entries = Array.isArray(value2) ? Array.prototype.entries.call(value2) : Object.entries(value2);
|
|
25436
25440
|
for (const [key3, child] of entries) {
|
|
25437
|
-
const childIssue = validateJsonValue(child,
|
|
25438
|
-
if (childIssue)
|
|
25441
|
+
const childIssue = validateJsonValue(child, ancestors);
|
|
25442
|
+
if (childIssue) {
|
|
25443
|
+
childIssue.path = joinPointer("", String(key3)) + childIssue.path;
|
|
25439
25444
|
return childIssue;
|
|
25445
|
+
}
|
|
25440
25446
|
}
|
|
25441
25447
|
ancestors.delete(value2);
|
|
25442
25448
|
return void 0;
|
|
@@ -25499,7 +25505,11 @@ ${end.comment}` : end.comment;
|
|
|
25499
25505
|
return [issue2(`/redirect_uris/${index}`, "protocol", "must use HTTPS (or loopback HTTP in local mode)")];
|
|
25500
25506
|
}
|
|
25501
25507
|
const nativeAllowed = nativeRedirectMatchesApplication(url2, String(manifest.id));
|
|
25502
|
-
|
|
25508
|
+
const mobileAllowed = !native && url2.protocol === "capacitor:" && !url2.username && !url2.password && !url2.port && !url2.search && !url2.hash && url2.href === redirect && Object.values(asObject(manifest.installation_origins)).some((policy) => {
|
|
25509
|
+
const mobile = asObject(policy).mobile;
|
|
25510
|
+
return Array.isArray(mobile) && mobile.includes(`capacitor://${url2.hostname}`);
|
|
25511
|
+
});
|
|
25512
|
+
if (url2.origin !== homepage.origin && !nativeAllowed && !mobileAllowed) {
|
|
25503
25513
|
return [issue2(`/redirect_uris/${index}`, "origin", "must use the homepage origin or a private-use scheme matching the application ID")];
|
|
25504
25514
|
}
|
|
25505
25515
|
}
|
|
@@ -25671,23 +25681,20 @@ ${end.comment}` : end.comment;
|
|
|
25671
25681
|
if (path === RECORD_EXTENSIONS_CONFIGURATION_PATH) {
|
|
25672
25682
|
return APPLICATION_RECORD_EXTENSIONS.includes(value2) ? void 0 : "accepts only the record extensions md and base";
|
|
25673
25683
|
}
|
|
25674
|
-
if (!path.startsWith("/") || new TextEncoder().encode(path).byteLength > 1024) {
|
|
25684
|
+
if (!path.startsWith("/") || path.length * 3 > 1024 && new TextEncoder().encode(path).byteLength > 1024) {
|
|
25675
25685
|
return "must be a bounded RFC 6901 JSON pointer";
|
|
25676
25686
|
}
|
|
25677
25687
|
const encoded = path.slice(1).split("/");
|
|
25678
25688
|
if (encoded.length < 2 || encoded.length > 16) {
|
|
25679
25689
|
return "must address a value below an x-* extension namespace";
|
|
25680
25690
|
}
|
|
25681
|
-
const
|
|
25682
|
-
|
|
25683
|
-
if (/~(?:[^01]|$)/u.test(value3))
|
|
25691
|
+
for (const segment2 of encoded) {
|
|
25692
|
+
if (/~(?:[^01]|$)/u.test(segment2))
|
|
25684
25693
|
return "contains an invalid RFC 6901 escape";
|
|
25685
|
-
|
|
25686
|
-
if (segment2.length === 0 || segment2 === "-" || /^\d+$/u.test(segment2) || [...segment2].some((character) => /\p{Cc}/u.test(character)))
|
|
25694
|
+
if (segment2.length === 0 || segment2 === "-" || /^\d+$/u.test(segment2) || /\p{Cc}/u.test(segment2))
|
|
25687
25695
|
return "contains a disallowed object-key segment";
|
|
25688
|
-
segments.push(segment2);
|
|
25689
25696
|
}
|
|
25690
|
-
return /^x-[a-z0-9][a-z0-9-]*$/u.test(
|
|
25697
|
+
return /^x-[a-z0-9][a-z0-9-]*$/u.test(encoded[0]) ? void 0 : "must be inside a top-level x-* extension namespace";
|
|
25691
25698
|
}
|
|
25692
25699
|
function validateCapabilityRequirements(value2) {
|
|
25693
25700
|
const manifest = asObject(value2);
|
|
@@ -26085,6 +26092,54 @@ ${end.comment}` : end.comment;
|
|
|
26085
26092
|
}
|
|
26086
26093
|
});
|
|
26087
26094
|
|
|
26095
|
+
// src/application/return-url.ts
|
|
26096
|
+
function declaredReturnUrl(value2, manifest) {
|
|
26097
|
+
if (typeof value2 !== "string" || !value2 || value2.length > 2048 || value2.includes("*")) return false;
|
|
26098
|
+
const declared = manifest && typeof manifest === "object" ? manifest.redirect_uris : void 0;
|
|
26099
|
+
if (!Array.isArray(declared) || !declared.includes(value2)) return false;
|
|
26100
|
+
const { id: id6, homepage } = manifest;
|
|
26101
|
+
let url2;
|
|
26102
|
+
try {
|
|
26103
|
+
url2 = new URL(value2);
|
|
26104
|
+
} catch {
|
|
26105
|
+
return false;
|
|
26106
|
+
}
|
|
26107
|
+
if (url2.username || url2.password || url2.hash) return false;
|
|
26108
|
+
if (url2.protocol === "https:" || url2.protocol === "http:") {
|
|
26109
|
+
let home;
|
|
26110
|
+
try {
|
|
26111
|
+
home = new URL(String(homepage));
|
|
26112
|
+
} catch {
|
|
26113
|
+
return false;
|
|
26114
|
+
}
|
|
26115
|
+
return url2.origin === home.origin && (url2.protocol === "https:" || loopbackHttpOrigin(url2.origin));
|
|
26116
|
+
}
|
|
26117
|
+
const scheme = url2.protocol.slice(0, -1);
|
|
26118
|
+
return typeof id6 === "string" && scheme.includes(".") && /^[a-z][a-z0-9+.-]*$/.test(scheme) && !RESERVED.includes(scheme) && (scheme === id6 || scheme.startsWith(`${id6}.`)) && url2.hostname.length > 0;
|
|
26119
|
+
}
|
|
26120
|
+
function mobileGrantReturnUrl(value2, origin4, manifest) {
|
|
26121
|
+
if (!origin4.startsWith("capacitor://")) return false;
|
|
26122
|
+
const redirects = manifest?.redirect_uris;
|
|
26123
|
+
if (!Array.isArray(redirects) || !redirects.includes(value2) || value2.includes("*")) return false;
|
|
26124
|
+
let url2;
|
|
26125
|
+
try {
|
|
26126
|
+
url2 = new URL(value2);
|
|
26127
|
+
} catch {
|
|
26128
|
+
return false;
|
|
26129
|
+
}
|
|
26130
|
+
if (url2.href !== value2 || url2.username || url2.password || url2.search || url2.hash) return false;
|
|
26131
|
+
if (url2.protocol === "capacitor:") return `capacitor://${url2.host}` === origin4;
|
|
26132
|
+
return url2.protocol !== "http:" && url2.protocol !== "https:" && declaredReturnUrl(value2, manifest);
|
|
26133
|
+
}
|
|
26134
|
+
var RESERVED;
|
|
26135
|
+
var init_return_url = __esm({
|
|
26136
|
+
"src/application/return-url.ts"() {
|
|
26137
|
+
"use strict";
|
|
26138
|
+
init_local_build2();
|
|
26139
|
+
RESERVED = ["http", "https", "file", "javascript", "data", "blob", "about", "capacitor", "chrome-extension", "moz-extension"];
|
|
26140
|
+
}
|
|
26141
|
+
});
|
|
26142
|
+
|
|
26088
26143
|
// src/app-host/app-environment.ts
|
|
26089
26144
|
function origin(value2, loopbackAllowed) {
|
|
26090
26145
|
if (typeof value2 !== "string" || !value2.length) throw invalid6();
|
|
@@ -38420,6 +38475,8 @@ ${end.comment}` : end.comment;
|
|
|
38420
38475
|
"src/app-grant/client.ts"() {
|
|
38421
38476
|
"use strict";
|
|
38422
38477
|
init_dist2();
|
|
38478
|
+
init_return_url();
|
|
38479
|
+
init_app_origin();
|
|
38423
38480
|
init_app_environment();
|
|
38424
38481
|
init_declaration();
|
|
38425
38482
|
init_storage_scope();
|
|
@@ -38484,8 +38541,9 @@ ${end.comment}` : end.comment;
|
|
|
38484
38541
|
} catch {
|
|
38485
38542
|
throw mdbaseError("invalid_request", "redirectUri must be an absolute URL", "redirect_uri");
|
|
38486
38543
|
}
|
|
38487
|
-
|
|
38488
|
-
|
|
38544
|
+
const validRedirect = this.declaration.origin.startsWith("capacitor://") ? mobileGrantReturnUrl(options.redirectUri, this.declaration.origin, this.declaration.manifest) : this.redirect.protocol === new URL(this.declaration.origin).protocol && this.redirect.origin === this.declaration.origin && !this.redirect.hash;
|
|
38545
|
+
if (!validRedirect) {
|
|
38546
|
+
throw mdbaseError("invalid_request", "redirectUri must be a valid callback for this app", "redirect_uri");
|
|
38489
38547
|
}
|
|
38490
38548
|
this.fetcher = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
38491
38549
|
this.callbacks = options.callbacks ?? broadcastCallbacks();
|
|
@@ -38703,7 +38761,7 @@ ${end.comment}` : end.comment;
|
|
|
38703
38761
|
declarationId: binding2.application_declaration_id,
|
|
38704
38762
|
manifestDigest: registration.manifestDigest,
|
|
38705
38763
|
applicationInstallationId: binding2.application_installation_id,
|
|
38706
|
-
applicationOrigin: this.
|
|
38764
|
+
applicationOrigin: this.declaration.origin,
|
|
38707
38765
|
collectionId: collection2,
|
|
38708
38766
|
grantSigningPublicKey: grantSigning.publicKey,
|
|
38709
38767
|
clientNoisePublicKey: b64u(noise.publicKey)
|
|
@@ -38737,7 +38795,7 @@ ${end.comment}` : end.comment;
|
|
|
38737
38795
|
} catch {
|
|
38738
38796
|
return;
|
|
38739
38797
|
}
|
|
38740
|
-
if (url2
|
|
38798
|
+
if (urlOrigin(url2) !== urlOrigin(this.redirect) || url2.username || url2.password || url2.hash || url2.pathname !== this.redirect.pathname || url2.searchParams.get("state") !== state2) return;
|
|
38741
38799
|
const error5 = url2.searchParams.get("error");
|
|
38742
38800
|
if (error5) return finish(() => reject(mdbaseError("forbidden", "access was not approved", "authorization_denied")));
|
|
38743
38801
|
const code = url2.searchParams.get("code");
|
|
@@ -38766,7 +38824,7 @@ ${end.comment}` : end.comment;
|
|
|
38766
38824
|
async saveTokens(res, from) {
|
|
38767
38825
|
const b = res.body;
|
|
38768
38826
|
if (res.status !== 200 || !b) {
|
|
38769
|
-
if (res.status === 400 && b &&
|
|
38827
|
+
if (res.status === 400 && b && (b.error === "invalid_grant" || fieldOf(b.error, "code") === "invalid_grant")) {
|
|
38770
38828
|
throw mdbaseError("unauthenticated", "the grant is no longer valid", "grant_invalid");
|
|
38771
38829
|
}
|
|
38772
38830
|
if (res.status === 400) throw collectionUnavailableError("sync_required");
|
|
@@ -38926,31 +38984,42 @@ ${end.comment}` : end.comment;
|
|
|
38926
38984
|
if (options.bindings === void 0 || options.bindings.some((c) => c.collection_id === record5.collection && c.application_origin === this.declaration.origin && b64u(record5.noisePublicKey) === c.client_noise_public_key)) local.push(record5);
|
|
38927
38985
|
}
|
|
38928
38986
|
const held = new Set(local.map((g) => g.collection));
|
|
38929
|
-
|
|
38930
|
-
|
|
38931
|
-
|
|
38932
|
-
|
|
38933
|
-
|
|
38934
|
-
|
|
38935
|
-
|
|
38936
|
-
|
|
38937
|
-
|
|
38938
|
-
|
|
38939
|
-
|
|
38940
|
-
|
|
38987
|
+
const denied = /* @__PURE__ */ new Set();
|
|
38988
|
+
grants: for (const grant of local) {
|
|
38989
|
+
let res;
|
|
38990
|
+
for (let attempt = 0; ; attempt++) {
|
|
38991
|
+
let token;
|
|
38992
|
+
try {
|
|
38993
|
+
token = await this.accessToken(grant.collection);
|
|
38994
|
+
} catch (e) {
|
|
38995
|
+
if (isMdbaseError(e, "unauthenticated") && e.reason === "grant_invalid") {
|
|
38996
|
+
denied.add(grant.collection);
|
|
38997
|
+
continue grants;
|
|
38998
|
+
}
|
|
38999
|
+
if (isMdbaseError(e, "forbidden") && e.reason === "sync_required") continue grants;
|
|
39000
|
+
throw e;
|
|
39001
|
+
}
|
|
39002
|
+
await this.assertCurrent(grant);
|
|
39003
|
+
res = await this.request("/v1/next/apps/collections", { headers: { authorization: `Bearer ${token}` } }, options.signal);
|
|
39004
|
+
await this.assertCurrent(grant);
|
|
39005
|
+
if (res.status === 403) {
|
|
39006
|
+
denied.add(grant.collection);
|
|
39007
|
+
continue grants;
|
|
39008
|
+
}
|
|
39009
|
+
if (res.status !== 401) break;
|
|
38941
39010
|
await this.withLock(grant.collection, "commit", async () => {
|
|
38942
39011
|
await this.assertCurrent(grant);
|
|
38943
39012
|
const cached = this.tokens.get(grant.collection);
|
|
38944
39013
|
if (cached?.access !== token || !sameGrant(grant, cached)) throw grantChanged();
|
|
38945
39014
|
this.tokens.delete(grant.collection);
|
|
38946
39015
|
});
|
|
38947
|
-
throw mdbaseError("unauthenticated", "the control plane refused the collection listing token");
|
|
39016
|
+
if (attempt > 0) throw mdbaseError("unauthenticated", "the control plane refused the collection listing token");
|
|
38948
39017
|
}
|
|
38949
39018
|
if (res.status !== 200 || !Array.isArray(res.body?.collections)) throw mdbaseError("unavailable", `control plane answered ${res.status}`, "control_error");
|
|
38950
39019
|
const out = [];
|
|
38951
39020
|
for (const raw of res.body.collections) {
|
|
38952
39021
|
const id6 = typeof raw.collection === "string" ? raw.collection.toLowerCase() : "";
|
|
38953
|
-
if (!UUID10.test(id6) || out.some((c) => c.collectionId === id6)) continue;
|
|
39022
|
+
if (!UUID10.test(id6) || denied.has(id6) || out.some((c) => c.collectionId === id6)) continue;
|
|
38954
39023
|
const parsed = parseCollectionAvailability(raw.availability);
|
|
38955
39024
|
if (raw.state !== "synced_e2e" && !parsed) continue;
|
|
38956
39025
|
const availability = !held.has(id6) ? { state: "unavailable", reason: "sync_required" } : parsed ?? { state: "opening" };
|
|
@@ -51136,6 +51205,7 @@ ${end.comment}` : end.comment;
|
|
|
51136
51205
|
if (sel?.state === "invalid") return { kind: "problem", collectionId: null, problem: fallback(sel.problem ?? "application_selection_invalid", cp) };
|
|
51137
51206
|
const paired = s.signIn?.state === "paired";
|
|
51138
51207
|
if (sel?.state === "approving" || s.status === "authorizing") {
|
|
51208
|
+
if (s.problem === "private_authorization_failed") return { kind: "problem", collectionId: requested?.collectionId ?? null, problem: fallback(s.problem, cp) };
|
|
51139
51209
|
const approval = sel?.approval ?? null;
|
|
51140
51210
|
if (!paired) return { kind: "authorizing", purpose: "sign_in", collectionId: approval?.collectionId ?? requested?.collectionId ?? null };
|
|
51141
51211
|
return approval?.kind === "add" ? { kind: "authorizing", purpose: "add", collectionId: null } : { kind: "authorizing", purpose: "approve", collectionId: approval?.collectionId ?? requested?.collectionId ?? null };
|
|
@@ -51174,6 +51244,8 @@ ${end.comment}` : end.comment;
|
|
|
51174
51244
|
return { kind: "problem", collectionId: requested.collectionId, problem: fallback("installation_scope_removed", cp) };
|
|
51175
51245
|
if (sel?.state === "approval_required" && requested?.collectionId)
|
|
51176
51246
|
return { kind: "needs_approval", collectionId: requested.collectionId, displayName: requested.displayName, declined: sel.problem === "application_selection_not_approved" };
|
|
51247
|
+
if (sel?.state === "blocked" && requested?.collectionId && !requested.approved)
|
|
51248
|
+
return { kind: "problem", collectionId: requested.collectionId, problem: fallback("unavailable", cp) };
|
|
51177
51249
|
if (sel?.state === "pending" && requested?.collectionId)
|
|
51178
51250
|
return { kind: "opening", collectionId: requested.collectionId, displayName: requested.displayName, slow: !!o.slow };
|
|
51179
51251
|
const usable = sel?.usable ?? (s.status === "ready" || s.status === "setup_required" ? s.collections.find((c) => c.collectionId === s.selectedCollectionId) ?? null : null);
|
|
@@ -51223,36 +51295,7 @@ ${end.comment}` : end.comment;
|
|
|
51223
51295
|
init_describe_error();
|
|
51224
51296
|
init_app_origin();
|
|
51225
51297
|
init_manifest2();
|
|
51226
|
-
|
|
51227
|
-
// src/application/return-url.ts
|
|
51228
|
-
init_local_build2();
|
|
51229
|
-
var RESERVED = ["http", "https", "file", "javascript", "data", "blob", "about", "capacitor", "chrome-extension", "moz-extension"];
|
|
51230
|
-
function declaredReturnUrl(value2, manifest) {
|
|
51231
|
-
if (typeof value2 !== "string" || !value2 || value2.length > 2048 || value2.includes("*")) return false;
|
|
51232
|
-
const declared = manifest && typeof manifest === "object" ? manifest.redirect_uris : void 0;
|
|
51233
|
-
if (!Array.isArray(declared) || !declared.includes(value2)) return false;
|
|
51234
|
-
const { id: id6, homepage } = manifest;
|
|
51235
|
-
let url2;
|
|
51236
|
-
try {
|
|
51237
|
-
url2 = new URL(value2);
|
|
51238
|
-
} catch {
|
|
51239
|
-
return false;
|
|
51240
|
-
}
|
|
51241
|
-
if (url2.username || url2.password || url2.hash) return false;
|
|
51242
|
-
if (url2.protocol === "https:" || url2.protocol === "http:") {
|
|
51243
|
-
let home;
|
|
51244
|
-
try {
|
|
51245
|
-
home = new URL(String(homepage));
|
|
51246
|
-
} catch {
|
|
51247
|
-
return false;
|
|
51248
|
-
}
|
|
51249
|
-
return url2.origin === home.origin && (url2.protocol === "https:" || loopbackHttpOrigin(url2.origin));
|
|
51250
|
-
}
|
|
51251
|
-
const scheme = url2.protocol.slice(0, -1);
|
|
51252
|
-
return typeof id6 === "string" && scheme.includes(".") && /^[a-z][a-z0-9+.-]*$/.test(scheme) && !RESERVED.includes(scheme) && (scheme === id6 || scheme.startsWith(`${id6}.`)) && url2.hostname.length > 0;
|
|
51253
|
-
}
|
|
51254
|
-
|
|
51255
|
-
// src/application/entry.ts
|
|
51298
|
+
init_return_url();
|
|
51256
51299
|
init_registration();
|
|
51257
51300
|
|
|
51258
51301
|
// src/application/asset-loader.ts
|
|
@@ -51372,12 +51415,12 @@ ${end.comment}` : end.comment;
|
|
|
51372
51415
|
// src/application/asset-pins.json
|
|
51373
51416
|
var asset_pins_default = {
|
|
51374
51417
|
runtime: {
|
|
51375
|
-
sha256: "
|
|
51376
|
-
bytes:
|
|
51377
|
-
maxBytes:
|
|
51418
|
+
sha256: "b7307cff2e6d318cba1e9396248f110a327cd0aef6f7e759d25468273ec3346b",
|
|
51419
|
+
bytes: 4186215,
|
|
51420
|
+
maxBytes: 4186215,
|
|
51378
51421
|
source: {
|
|
51379
51422
|
repository: "mdbase-dev/mdbase-connect",
|
|
51380
|
-
commit: "
|
|
51423
|
+
commit: "31732b22a4d16d66da93164a4737c15e901a5193"
|
|
51381
51424
|
}
|
|
51382
51425
|
},
|
|
51383
51426
|
sqlite: {
|
|
@@ -51876,10 +51919,14 @@ ${end.comment}` : end.comment;
|
|
|
51876
51919
|
else if (s.selectedCollectionId === id6 && (s.status === "blocked" || s.status === "opening" || isLocked(s))) state2 = s.status === "blocked" ? "blocked" : "opening";
|
|
51877
51920
|
else if (!settled(s)) state2 = "pending";
|
|
51878
51921
|
else if (wanted) state2 = "opening";
|
|
51879
|
-
else if (this.session.listing?.()) state2 = "pending";
|
|
51880
51922
|
else {
|
|
51881
|
-
|
|
51882
|
-
if (
|
|
51923
|
+
const listing = this.session.listing?.();
|
|
51924
|
+
if (listing === "unavailable") state2 = "blocked";
|
|
51925
|
+
else if (listing) state2 = "pending";
|
|
51926
|
+
else {
|
|
51927
|
+
state2 = "approval_required";
|
|
51928
|
+
if (this.declined === id6) problem7 = "application_selection_not_approved";
|
|
51929
|
+
}
|
|
51883
51930
|
}
|
|
51884
51931
|
const approval = this.approval ? Object.freeze({ kind: this.approval.kind, collectionId: this.approval.collectionId, reopenable: this.approval.settled }) : null;
|
|
51885
51932
|
return Object.freeze({
|
|
@@ -51927,7 +51974,7 @@ ${end.comment}` : end.comment;
|
|
|
51927
51974
|
} else {
|
|
51928
51975
|
if (!this.approval.settled || inFlight(s)) return;
|
|
51929
51976
|
const native = s.signIn?.nativeSelection;
|
|
51930
|
-
if (native && native.requestId !== this.approval.receipt && !approved(s, native.collectionId) && this.session.listing?.()) return;
|
|
51977
|
+
if (native && native.requestId !== this.approval.receipt && !approved(s, native.collectionId) && this.session.listing?.() === true) return;
|
|
51931
51978
|
this.finishApproval(s);
|
|
51932
51979
|
}
|
|
51933
51980
|
}
|
|
@@ -52968,6 +53015,7 @@ ${end.comment}` : end.comment;
|
|
|
52968
53015
|
// src/application/private-collections.ts
|
|
52969
53016
|
init_relay_close();
|
|
52970
53017
|
init_errors();
|
|
53018
|
+
init_return_url();
|
|
52971
53019
|
init_app_origin();
|
|
52972
53020
|
init_plain();
|
|
52973
53021
|
function assessmentDelay(signal, ms) {
|
|
@@ -53012,6 +53060,11 @@ ${end.comment}` : end.comment;
|
|
|
53012
53060
|
function appGrantRedirectUri(declaration) {
|
|
53013
53061
|
const declared = declaration.manifest?.redirect_uris;
|
|
53014
53062
|
const uris = Array.isArray(declared) ? declared.filter((uri) => typeof uri === "string") : [];
|
|
53063
|
+
if (declaration.origin.startsWith("capacitor://")) {
|
|
53064
|
+
const callback = uris.find((uri) => mobileGrantReturnUrl(uri, declaration.origin, declaration.manifest));
|
|
53065
|
+
if (!callback) throw mdbaseError("invalid_request", "Declare an iOS Private collection callback in redirect_uris", "redirect_uri");
|
|
53066
|
+
return callback;
|
|
53067
|
+
}
|
|
53015
53068
|
return uris.find((uri) => {
|
|
53016
53069
|
try {
|
|
53017
53070
|
return urlOrigin(new URL(uri)) === declaration.origin;
|
|
@@ -53045,9 +53098,7 @@ ${end.comment}` : end.comment;
|
|
|
53045
53098
|
list = Object.freeze([]);
|
|
53046
53099
|
open = null;
|
|
53047
53100
|
listed = null;
|
|
53048
|
-
|
|
53049
|
-
* requested collection missing from the list may still be in it. */
|
|
53050
|
-
settled = null;
|
|
53101
|
+
failedListing = null;
|
|
53051
53102
|
refreshing = null;
|
|
53052
53103
|
closed = false;
|
|
53053
53104
|
bindings = null;
|
|
@@ -53083,7 +53134,7 @@ ${end.comment}` : end.comment;
|
|
|
53083
53134
|
const previous = this.bindings;
|
|
53084
53135
|
this.bindingsAccount = account;
|
|
53085
53136
|
this.bindings = Object.freeze([...next]);
|
|
53086
|
-
this.
|
|
53137
|
+
this.failedListing = null;
|
|
53087
53138
|
this.listed = null;
|
|
53088
53139
|
const open2 = this.open;
|
|
53089
53140
|
if (open2) {
|
|
@@ -53141,39 +53192,48 @@ ${end.comment}` : end.comment;
|
|
|
53141
53192
|
const open2 = this.open;
|
|
53142
53193
|
return open2 && open2.id === collectionId && open2.state.status === "ready" ? open2.connection : null;
|
|
53143
53194
|
}
|
|
53144
|
-
/**
|
|
53145
|
-
* read): a collection not yet listed may still be one of them. */
|
|
53195
|
+
/** Only a successful read settles whether an unlisted collection is absent. */
|
|
53146
53196
|
listing(account) {
|
|
53147
|
-
|
|
53197
|
+
if (this.closed || account === null) return false;
|
|
53198
|
+
if (this.failedListing === account) return "unavailable";
|
|
53199
|
+
return this.listed !== account;
|
|
53148
53200
|
}
|
|
53149
|
-
/** Read
|
|
53201
|
+
/** Read once per binding. Explicit refreshes and reconnects can retry a failure. */
|
|
53150
53202
|
ensure(account) {
|
|
53151
|
-
if (this.
|
|
53203
|
+
if (this.listing(account) === true && !this.refreshing) void this.refresh(account).catch(() => {
|
|
53152
53204
|
});
|
|
53153
53205
|
}
|
|
53154
|
-
refresh(account = this.listed) {
|
|
53206
|
+
refresh(account = this.bindings === null ? this.listed : this.bindingsAccount) {
|
|
53155
53207
|
if (this.closed) return Promise.resolve();
|
|
53156
53208
|
if (this.refreshing) return this.refreshing;
|
|
53209
|
+
const bindings = this.bindings;
|
|
53210
|
+
const current3 = () => !this.closed && bindings === this.bindings;
|
|
53157
53211
|
const pending = (async () => {
|
|
53158
53212
|
try {
|
|
53159
53213
|
const grants = await this.grants();
|
|
53160
|
-
const bindings = this.bindings;
|
|
53161
53214
|
const verified = [];
|
|
53162
53215
|
if (bindings) {
|
|
53163
53216
|
for (const c of bindings) if (c.account_id === account && await grants.verifiedStoredNativeGrant?.(c)) verified.push(c);
|
|
53164
53217
|
}
|
|
53165
53218
|
const found = await grants.collections(bindings === null ? {} : { bindings: verified });
|
|
53166
|
-
if (
|
|
53219
|
+
if (!current3()) return;
|
|
53220
|
+
const changed3 = this.listing(account) !== false;
|
|
53167
53221
|
this.listed = account;
|
|
53222
|
+
this.failedListing = null;
|
|
53223
|
+
const revision = this.revision;
|
|
53168
53224
|
this.setList(found);
|
|
53169
|
-
|
|
53170
|
-
|
|
53171
|
-
|
|
53225
|
+
if (changed3 && revision === this.revision) this.changed();
|
|
53226
|
+
} catch (error5) {
|
|
53227
|
+
if (current3() && account !== null && this.failedListing !== account) {
|
|
53228
|
+
this.failedListing = account;
|
|
53172
53229
|
this.changed();
|
|
53173
53230
|
}
|
|
53231
|
+
throw error5;
|
|
53174
53232
|
}
|
|
53175
53233
|
})().finally(() => {
|
|
53176
|
-
if (this.refreshing
|
|
53234
|
+
if (this.refreshing !== pending) return;
|
|
53235
|
+
this.refreshing = null;
|
|
53236
|
+
if (!current3() && this.bindingsAccount !== null) this.ensure(this.bindingsAccount);
|
|
53177
53237
|
});
|
|
53178
53238
|
this.refreshing = pending;
|
|
53179
53239
|
return pending;
|
|
@@ -53374,7 +53434,7 @@ ${end.comment}` : end.comment;
|
|
|
53374
53434
|
} finally {
|
|
53375
53435
|
this.list = Object.freeze([]);
|
|
53376
53436
|
this.listed = null;
|
|
53377
|
-
this.
|
|
53437
|
+
this.failedListing = null;
|
|
53378
53438
|
this.changed();
|
|
53379
53439
|
}
|
|
53380
53440
|
}
|
|
@@ -53517,7 +53577,7 @@ ${end.comment}` : end.comment;
|
|
|
53517
53577
|
if (returnUrl !== void 0) {
|
|
53518
53578
|
if (!declaredReturnUrl(returnUrl, declaration.manifest)) fail20();
|
|
53519
53579
|
}
|
|
53520
|
-
if (grantReturnUrl !== void 0 && (!declaredReturnUrl(grantReturnUrl, declaration.manifest) || new URL(grantReturnUrl).origin !== declaration.origin)) fail20();
|
|
53580
|
+
if (grantReturnUrl !== void 0 && !mobileGrantReturnUrl(grantReturnUrl, declaration.origin, declaration.manifest) && (!declaredReturnUrl(grantReturnUrl, declaration.manifest) || new URL(grantReturnUrl).origin !== declaration.origin)) fail20();
|
|
53521
53581
|
const open2 = value2.open.bind(value2), close = value2.close?.bind(value2);
|
|
53522
53582
|
return Object.freeze({ open: open2, ...close ? { close } : {}, ...returnUrl !== void 0 ? { returnUrl } : {}, ...grantReturnUrl !== void 0 ? { grantReturnUrl } : {} });
|
|
53523
53583
|
}
|
|
@@ -53674,6 +53734,9 @@ ${end.comment}` : end.comment;
|
|
|
53674
53734
|
this.notify(false);
|
|
53675
53735
|
}
|
|
53676
53736
|
return this.call(async (runtime2) => {
|
|
53737
|
+
const account = this.account();
|
|
53738
|
+
if (this.privates?.listing(account) === "unavailable") await this.privates.refresh(account).catch(() => {
|
|
53739
|
+
});
|
|
53677
53740
|
const native = runtime2.getNativeSnapshot();
|
|
53678
53741
|
if (native.status === "blocked" && native.signIn && native.selectedCollectionId === null)
|
|
53679
53742
|
await runtime2.queue(() => runtime2.start(options2));
|
|
@@ -54431,7 +54494,13 @@ ${end.comment}` : end.comment;
|
|
|
54431
54494
|
this.revision++;
|
|
54432
54495
|
this.notify(false);
|
|
54433
54496
|
};
|
|
54434
|
-
scope.addEventListener("online",
|
|
54497
|
+
scope.addEventListener("online", () => {
|
|
54498
|
+
const account = this.account();
|
|
54499
|
+
if (!this.closed && !this.hidden && this.privates?.listing(account) === "unavailable")
|
|
54500
|
+
void this.privates.refresh(account).catch(() => {
|
|
54501
|
+
});
|
|
54502
|
+
changed3();
|
|
54503
|
+
}, { signal: this.lifetime.signal });
|
|
54435
54504
|
scope.addEventListener("offline", changed3, { signal: this.lifetime.signal });
|
|
54436
54505
|
}
|
|
54437
54506
|
/** Back/forward cache: a page parked there is frozen with its Worker, which
|
|
@@ -55711,7 +55780,7 @@ ${end.comment}` : end.comment;
|
|
|
55711
55780
|
} else {
|
|
55712
55781
|
await this.prepareNativeChoice();
|
|
55713
55782
|
this.resumeApprovalWindow();
|
|
55714
|
-
this.publish({ status: "authorizing", problem: null });
|
|
55783
|
+
this.publish({ status: "authorizing", problem: this.nativePending?.failed ? "private_authorization_failed" : null });
|
|
55715
55784
|
}
|
|
55716
55785
|
return;
|
|
55717
55786
|
}
|
|
@@ -55752,7 +55821,7 @@ ${end.comment}` : end.comment;
|
|
|
55752
55821
|
this.check();
|
|
55753
55822
|
if (unfinished) this.publish({ approval: Object.freeze({ outcome: "closed" }) });
|
|
55754
55823
|
await this.refreshCollections();
|
|
55755
|
-
} else this.publish({ status: "authorizing", problem: null });
|
|
55824
|
+
} else this.publish({ status: "authorizing", problem: this.nativePending?.failed ? "private_authorization_failed" : null });
|
|
55756
55825
|
}
|
|
55757
55826
|
/** A receipt with no collection pick is complete only for device access:
|
|
55758
55827
|
* Connect never names a Private device collection as the selection, so an
|
|
@@ -55784,7 +55853,7 @@ ${end.comment}` : end.comment;
|
|
|
55784
55853
|
if (!this.attested) return false;
|
|
55785
55854
|
if (!this.approvalWindow?.nativeAuthorization || !this.installation || !this.flow.nativeAuthorizationContext(this.installation)) return true;
|
|
55786
55855
|
const slot = this.nativePending;
|
|
55787
|
-
return slot !== null &&
|
|
55856
|
+
return slot !== null && slot.attempted && !slot.failed;
|
|
55788
55857
|
}
|
|
55789
55858
|
/** Preparation is optional and never blocks a genuine Hosted approval. Only
|
|
55790
55859
|
* the original lifecycle turn attaches after observing its matching context. */
|