@mdbase-dev/sdk 0.3.1 → 0.4.0
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.d.ts +3 -0
- package/dist/app-grant/client.js +7 -0
- package/dist/app-grant/client.js.map +1 -1
- package/dist/app-host/cp-problem.d.ts +6 -0
- package/dist/app-host/cp-problem.js +17 -2
- package/dist/app-host/cp-problem.js.map +1 -1
- package/dist/application/entry.js +14 -3
- package/dist/application/entry.js.map +1 -1
- package/dist/application/file-access.d.ts +13 -5
- package/dist/application/file-access.js +30 -24
- package/dist/application/file-access.js.map +1 -1
- package/dist/application/private-collections.js +1 -0
- package/dist/application/private-collections.js.map +1 -1
- package/dist/application/worker.js +12 -1
- package/dist/browser/mdbase-sdk.js +101 -62
- package/dist/browser/mdbase-sdk.min.js +45 -45
- package/dist/collection-quota-copy.generated.d.ts +1 -1
- package/dist/collection-quota-copy.generated.js +1 -1
- package/dist/collection-quota-copy.generated.js.map +1 -1
- package/dist/describe-error.d.ts +1 -1
- package/dist/describe-error.js +9 -3
- package/dist/describe-error.js.map +1 -1
- package/dist/native/provenance.json +1 -1
- package/dist/testing/application.js +1 -1
- package/dist/testing/application.js.map +1 -1
- package/package.json +1 -1
|
@@ -4021,10 +4021,10 @@ var MdbaseSDK = (() => {
|
|
|
4021
4021
|
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 2147483647) {
|
|
4022
4022
|
throw mdbaseError("invalid_request", "Invalid request deadline.");
|
|
4023
4023
|
}
|
|
4024
|
-
const
|
|
4025
|
-
if (caller?.aborted) throw
|
|
4024
|
+
const cancelled6 = () => mdbaseError("cancelled", "Request cancelled.");
|
|
4025
|
+
if (caller?.aborted) throw cancelled6();
|
|
4026
4026
|
const controller = new AbortController();
|
|
4027
|
-
const abort = () => controller.abort(
|
|
4027
|
+
const abort = () => controller.abort(cancelled6());
|
|
4028
4028
|
let stop;
|
|
4029
4029
|
const stopped = new Promise((_, reject) => {
|
|
4030
4030
|
stop = () => reject(controller.signal.reason);
|
|
@@ -4494,7 +4494,7 @@ var MdbaseSDK = (() => {
|
|
|
4494
4494
|
const self = this;
|
|
4495
4495
|
const pending = new AbortController();
|
|
4496
4496
|
const cancelledError = mdbaseError("cancelled", "file download cancelled");
|
|
4497
|
-
let
|
|
4497
|
+
let cancelled6 = false;
|
|
4498
4498
|
let finished = false;
|
|
4499
4499
|
let cancelSent = false;
|
|
4500
4500
|
let detachAbort = () => {
|
|
@@ -4511,7 +4511,7 @@ var MdbaseSDK = (() => {
|
|
|
4511
4511
|
};
|
|
4512
4512
|
const cancel = () => {
|
|
4513
4513
|
if (finished) return;
|
|
4514
|
-
|
|
4514
|
+
cancelled6 = true;
|
|
4515
4515
|
detachAbort();
|
|
4516
4516
|
fileReject(cancelledError);
|
|
4517
4517
|
pending.abort();
|
|
@@ -4520,7 +4520,7 @@ var MdbaseSDK = (() => {
|
|
|
4520
4520
|
const stream = new ReadableStream({
|
|
4521
4521
|
async start(ctrl) {
|
|
4522
4522
|
const onAbort = () => {
|
|
4523
|
-
if (finished ||
|
|
4523
|
+
if (finished || cancelled6) return;
|
|
4524
4524
|
cancel();
|
|
4525
4525
|
ctrl.error(cancelledError);
|
|
4526
4526
|
};
|
|
@@ -4532,7 +4532,7 @@ var MdbaseSDK = (() => {
|
|
|
4532
4532
|
}
|
|
4533
4533
|
try {
|
|
4534
4534
|
session = await self.session(pending.signal, true);
|
|
4535
|
-
if (
|
|
4535
|
+
if (cancelled6) return;
|
|
4536
4536
|
const p = m([[0, fileRef(f)]]);
|
|
4537
4537
|
if (o.range) p.set(1, [o.range[0], o.range[1]]);
|
|
4538
4538
|
if (o.revision) p.set(2, hash.enc(o.revision));
|
|
@@ -4563,7 +4563,7 @@ var MdbaseSDK = (() => {
|
|
|
4563
4563
|
self.early.clear();
|
|
4564
4564
|
self.earlyFailures.clear();
|
|
4565
4565
|
}
|
|
4566
|
-
if (
|
|
4566
|
+
if (cancelled6) {
|
|
4567
4567
|
cancelRemote();
|
|
4568
4568
|
finished = true;
|
|
4569
4569
|
return;
|
|
@@ -4572,14 +4572,14 @@ var MdbaseSDK = (() => {
|
|
|
4572
4572
|
fileResolve(view2);
|
|
4573
4573
|
total = o.range ? o.range[1] : view2.size;
|
|
4574
4574
|
const deliver = (c) => {
|
|
4575
|
-
if (
|
|
4575
|
+
if (cancelled6 || finished) return;
|
|
4576
4576
|
ctrl.enqueue(c.bytes);
|
|
4577
4577
|
received += c.bytes.length;
|
|
4578
4578
|
o.onProgress?.({ id: streamId, phase: "streaming", done: received, total });
|
|
4579
|
-
if (
|
|
4579
|
+
if (cancelled6 || finished) return;
|
|
4580
4580
|
void session.request("ack_chunks", m([[0, streamId], [1, c.offset + c.bytes.length]])).catch(() => {
|
|
4581
4581
|
});
|
|
4582
|
-
if (c.last && !
|
|
4582
|
+
if (c.last && !cancelled6 && !finished) {
|
|
4583
4583
|
finished = true;
|
|
4584
4584
|
detachAbort();
|
|
4585
4585
|
self.streams.delete(streamId);
|
|
@@ -9784,7 +9784,7 @@ var MdbaseSDK = (() => {
|
|
|
9784
9784
|
var init_collection_quota_copy_generated = __esm({
|
|
9785
9785
|
"src/collection-quota-copy.generated.ts"() {
|
|
9786
9786
|
"use strict";
|
|
9787
|
-
ACCOUNT_COLLECTION_QUOTA_MESSAGE = "Your account has reached its synced collection limit. Open an existing collection
|
|
9787
|
+
ACCOUNT_COLLECTION_QUOTA_MESSAGE = "Your account has reached its synced collection limit. Open an existing collection or delete one you own if Delete is available.";
|
|
9788
9788
|
}
|
|
9789
9789
|
});
|
|
9790
9790
|
|
|
@@ -9858,18 +9858,27 @@ var MdbaseSDK = (() => {
|
|
|
9858
9858
|
return null;
|
|
9859
9859
|
}
|
|
9860
9860
|
}
|
|
9861
|
+
function collectionQuota(status, code, details) {
|
|
9862
|
+
if (status !== 429 || code !== "account_collection_quota_exceeded" || !details || typeof details !== "object") return void 0;
|
|
9863
|
+
const { limit, used: used2, plan } = details;
|
|
9864
|
+
if (typeof limit !== "number" || !Number.isSafeInteger(limit) || limit < 0 || typeof used2 !== "number" || !Number.isSafeInteger(used2) || used2 < limit || plan !== null && name(plan) === null) return void 0;
|
|
9865
|
+
return Object.freeze({ limit, used: used2, plan: name(plan) });
|
|
9866
|
+
}
|
|
9861
9867
|
function sanitizeAppServerProblem(value2, cpOrigin = null) {
|
|
9862
9868
|
try {
|
|
9863
9869
|
if (isAppServerProblem(value2)) return value2;
|
|
9864
|
-
if (typeof value2 !== "object" || value2 === null || Array.isArray(value2) || Object.getPrototypeOf(value2) !== Object.prototype || Object.keys(value2).sort().join(",") !== FIELDS) return null;
|
|
9870
|
+
if (typeof value2 !== "object" || value2 === null || Array.isArray(value2) || Object.getPrototypeOf(value2) !== Object.prototype || Object.keys(value2).filter((key3) => key3 !== "details").sort().join(",") !== FIELDS) return null;
|
|
9865
9871
|
const v = value2;
|
|
9866
9872
|
const status = v.status, retry2 = v.retryAfterMs;
|
|
9867
9873
|
if (typeof status !== "number" || !Number.isSafeInteger(status) || status < 0 || status > 999) return null;
|
|
9868
9874
|
if (v.code !== null && name(v.code) === null || v.reason !== null && name(v.reason) === null) return null;
|
|
9869
9875
|
if (retry2 !== null && (typeof retry2 !== "number" || !Number.isFinite(retry2) || retry2 < 0)) return null;
|
|
9870
9876
|
if (v.updateUrl !== null && typeof v.updateUrl !== "string") return null;
|
|
9877
|
+
const details = collectionQuota(status, v.code, v.details);
|
|
9878
|
+
if ("details" in v && !details) return null;
|
|
9871
9879
|
const problem7 = Object.freeze({
|
|
9872
9880
|
status,
|
|
9881
|
+
...details ? { details } : {},
|
|
9873
9882
|
code: name(v.code),
|
|
9874
9883
|
reason: name(v.reason),
|
|
9875
9884
|
retryAfterMs: retry2 === null ? null : clampRetry(retry2),
|
|
@@ -9885,7 +9894,9 @@ var MdbaseSDK = (() => {
|
|
|
9885
9894
|
const error5 = body && typeof body === "object" && !Array.isArray(body) ? body.error : void 0;
|
|
9886
9895
|
const e = error5 && typeof error5 === "object" && !Array.isArray(error5) ? error5 : null;
|
|
9887
9896
|
const d = e?.details && typeof e.details === "object" && !Array.isArray(e.details) ? e.details : null;
|
|
9897
|
+
const details = collectionQuota(status, e?.code, d);
|
|
9888
9898
|
const problem7 = Object.freeze({
|
|
9899
|
+
...details ? { details } : {},
|
|
9889
9900
|
status: Number.isSafeInteger(status) ? status : 0,
|
|
9890
9901
|
code: name(e?.code),
|
|
9891
9902
|
reason: name(d?.reason),
|
|
@@ -9959,7 +9970,7 @@ var MdbaseSDK = (() => {
|
|
|
9959
9970
|
if (typeof o.kind === "string" && "problem" in o && obj3(o.problem) && typeof obj3(o.problem).code === "string") return problemOf2(obj3(o.problem).code, cpOrigin);
|
|
9960
9971
|
const detail = obj3(o.problemDetail), server = sanitizeAppServerProblem(o.server ?? detail?.server, cpOrigin);
|
|
9961
9972
|
const serverCodes = [server?.reason ?? null, server?.code ?? null].filter((c) => c !== null);
|
|
9962
|
-
const extra = { retryAfterMs: server?.retryAfterMs ?? retry(o.retryAfterMs), updateUrl: trustedUpdateUrl(server?.updateUrl, cpOrigin), hasServer: o.server != null || detail?.server != null };
|
|
9973
|
+
const extra = { quota: server?.details, retryAfterMs: server?.retryAfterMs ?? retry(o.retryAfterMs), updateUrl: trustedUpdateUrl(server?.updateUrl, cpOrigin), hasServer: o.server != null || detail?.server != null };
|
|
9963
9974
|
if ("problem" in o || "readiness" in o || "assessment" in o) {
|
|
9964
9975
|
const own2 = str2(o.problem) ?? str2(obj3(o.problem)?.code);
|
|
9965
9976
|
if (own2) return { codes: [...serverCodes, own2], ...extra, refusal: registrationRefusal(detail?.registration) };
|
|
@@ -10008,7 +10019,10 @@ var MdbaseSDK = (() => {
|
|
|
10008
10019
|
}
|
|
10009
10020
|
const text9 = (v, fallback2) => typeof v === "string" && v.trim() ? v : fallback2;
|
|
10010
10021
|
const accountLabel = typeof options.recoveryAccountLabel === "string" && options.recoveryAccountLabel.trim().length > 0 && options.recoveryAccountLabel.length <= 320 && !Array.from(options.recoveryAccountLabel).some((c) => c.charCodeAt(0) < 32 || c.charCodeAt(0) === 127) ? options.recoveryAccountLabel : null;
|
|
10011
|
-
const
|
|
10022
|
+
const quota = key3 === "account_collection_quota_exceeded" ? found.quota : void 0;
|
|
10023
|
+
const plan = quota?.plan && Object.hasOwn(COLLECTION_PLANS, quota.plan) ? COLLECTION_PLANS[quota.plan] : null;
|
|
10024
|
+
const quotaMessage = quota ? `You are using ${quota.used} synced ${quota.used === 1 ? "collection" : "collections"}. The limit for ${plan ? "the " + plan + " plan" : "your account"} is ${quota.limit}. Open an existing collection or delete one you own if Delete is available.` : message3;
|
|
10025
|
+
const accountMessage = key3 === "recovery_account_mismatch" && accountLabel ? `This collection belongs to ${accountLabel}. Sign in as ${accountLabel} to continue.` : quotaMessage;
|
|
10012
10026
|
const actionLabel = key3 === "recovery_account_mismatch" && accountLabel ? `Sign in as ${accountLabel}` : label ?? LABELS[action];
|
|
10013
10027
|
return Object.freeze({
|
|
10014
10028
|
key: key3,
|
|
@@ -10036,7 +10050,7 @@ var MdbaseSDK = (() => {
|
|
|
10036
10050
|
const { key: key3, original } = resolve(found);
|
|
10037
10051
|
return key3 === null ? null : diagnostic(key3, original, found.refusal ?? null);
|
|
10038
10052
|
}
|
|
10039
|
-
var LABELS, PROBLEM_CODES, GENERIC, BUSY, UNAVAILABLE, UPDATE, CHOOSE, APPROVE, SET_UP, UNFINISHED_SIGN_IN, COPY, ALIASES, READINESS, NON_PROBLEM_CODES, NON_PROBLEMS, DEVELOPER, NAME2, str2, obj3, retry, isProblemCode;
|
|
10053
|
+
var LABELS, PROBLEM_CODES, COLLECTION_PLANS, GENERIC, BUSY, UNAVAILABLE, UPDATE, CHOOSE, APPROVE, SET_UP, UNFINISHED_SIGN_IN, COPY, ALIASES, READINESS, NON_PROBLEM_CODES, NON_PROBLEMS, DEVELOPER, NAME2, str2, obj3, retry, isProblemCode;
|
|
10040
10054
|
var init_describe_error = __esm({
|
|
10041
10055
|
"src/describe-error.ts"() {
|
|
10042
10056
|
"use strict";
|
|
@@ -10195,6 +10209,13 @@ var MdbaseSDK = (() => {
|
|
|
10195
10209
|
"private_device_limit",
|
|
10196
10210
|
"private_device_not_allowed"
|
|
10197
10211
|
];
|
|
10212
|
+
COLLECTION_PLANS = {
|
|
10213
|
+
beta_v1: "Beta",
|
|
10214
|
+
open_beta_v1: "Open Beta",
|
|
10215
|
+
free_v1: "Free",
|
|
10216
|
+
plus_v1: "Plus",
|
|
10217
|
+
trial_v1: "Trial"
|
|
10218
|
+
};
|
|
10198
10219
|
GENERIC = ["Something went wrong", "An unexpected problem occurred. Reload the app, and contact support if it keeps happening.", "reload", "error"];
|
|
10199
10220
|
BUSY = ["Another step hasn't finished", "The app couldn't finish this step yet. Try again, or reload if it keeps happening.", "retry", "warning", true];
|
|
10200
10221
|
UNAVAILABLE = ["Can't complete this request", "mdbase couldn't complete this request. Try again.", "retry", "warning"];
|
|
@@ -10454,7 +10475,7 @@ var MdbaseSDK = (() => {
|
|
|
10454
10475
|
budget: "readiness_budget",
|
|
10455
10476
|
unsupported: "readiness_unsupported"
|
|
10456
10477
|
});
|
|
10457
|
-
NON_PROBLEM_CODES = ["application_registration_id_superseded", "application_closing", "cancelled", "aborted"];
|
|
10478
|
+
NON_PROBLEM_CODES = ["application_registration_id_superseded", "application_closing", "cancelled", "aborted", "private_relay", "until_connected"];
|
|
10458
10479
|
NON_PROBLEMS = new Set(NON_PROBLEM_CODES);
|
|
10459
10480
|
DEVELOPER = Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
10460
10481
|
device_offline: "Collection availability device_offline: no device serving this Private collection is connected to the relay.",
|
|
@@ -26998,15 +27019,15 @@ ${end.comment}` : end.comment;
|
|
|
26998
27019
|
acquiredResolve = resolve2;
|
|
26999
27020
|
acquiredReject = reject;
|
|
27000
27021
|
});
|
|
27001
|
-
let
|
|
27022
|
+
let cancelled6 = false;
|
|
27002
27023
|
const onAbort = () => {
|
|
27003
|
-
|
|
27024
|
+
cancelled6 = true;
|
|
27004
27025
|
acquiredReject(new AppReplicaOwnerError("aborted"));
|
|
27005
27026
|
};
|
|
27006
27027
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
27007
27028
|
const request3 = Promise.resolve().then(() => locks.request(name3, { mode: "exclusive", ifAvailable: true }, async (lock) => {
|
|
27008
27029
|
signal?.removeEventListener("abort", onAbort);
|
|
27009
|
-
if (
|
|
27030
|
+
if (cancelled6 || signal?.aborted) {
|
|
27010
27031
|
acquiredReject(new AppReplicaOwnerError("aborted"));
|
|
27011
27032
|
return;
|
|
27012
27033
|
}
|
|
@@ -32941,7 +32962,7 @@ ${end.comment}` : end.comment;
|
|
|
32941
32962
|
let wire;
|
|
32942
32963
|
let pending = null;
|
|
32943
32964
|
const queued = [];
|
|
32944
|
-
const
|
|
32965
|
+
const cancelled6 = () => mdbaseError("cancelled", "Bases read cancelled");
|
|
32945
32966
|
let nextBasesId = 1;
|
|
32946
32967
|
return {
|
|
32947
32968
|
description: "app-local",
|
|
@@ -32962,8 +32983,8 @@ ${end.comment}` : end.comment;
|
|
|
32962
32983
|
const stopped = pending;
|
|
32963
32984
|
pending = null;
|
|
32964
32985
|
const waiting = queued.splice(0);
|
|
32965
|
-
stopped?.finish(void 0,
|
|
32966
|
-
for (const read2 of waiting) read2.finish(void 0,
|
|
32986
|
+
stopped?.finish(void 0, cancelled6());
|
|
32987
|
+
for (const read2 of waiting) read2.finish(void 0, cancelled6());
|
|
32967
32988
|
port?.onclose?.(unavailable2());
|
|
32968
32989
|
}, (kind, id6, bytes10) => {
|
|
32969
32990
|
if (!pending || kind !== pending.response || id6 !== pending.id) {
|
|
@@ -33000,7 +33021,7 @@ ${end.comment}` : end.comment;
|
|
|
33000
33021
|
const readBases = (kind, request3, signal2) => {
|
|
33001
33022
|
try {
|
|
33002
33023
|
active.current();
|
|
33003
|
-
if (signal2?.aborted) throw
|
|
33024
|
+
if (signal2?.aborted) throw cancelled6();
|
|
33004
33025
|
if (!(request3 instanceof Uint8Array) || !request3.length || request3.length > 128 * 1024) throw mdbaseError("invalid_request", "Bases request bytes exceed bound");
|
|
33005
33026
|
if (queued.length >= 32) throw mdbaseError("unavailable", "Bases read queue is full", "bases_read_backpressure");
|
|
33006
33027
|
} catch (error5) {
|
|
@@ -33025,7 +33046,7 @@ ${end.comment}` : end.comment;
|
|
|
33025
33046
|
const index = queued.indexOf(read2);
|
|
33026
33047
|
if (index !== -1) queued.splice(index, 1);
|
|
33027
33048
|
if (pending === read2 && read2.id === void 0) pending = null;
|
|
33028
|
-
finish(void 0,
|
|
33049
|
+
finish(void 0, cancelled6());
|
|
33029
33050
|
};
|
|
33030
33051
|
queued.push(read2);
|
|
33031
33052
|
signal2?.addEventListener("abort", abort, { once: true });
|
|
@@ -34636,7 +34657,7 @@ ${end.comment}` : end.comment;
|
|
|
34636
34657
|
}
|
|
34637
34658
|
function missingFileActions(declaration, request3, options, consented) {
|
|
34638
34659
|
const files = request3?.files, reason = options?.reason;
|
|
34639
|
-
if (!Array.isArray(files) || !files.length || files.some((a) => !
|
|
34660
|
+
if (!Array.isArray(files) || !files.length || files.some((a) => !FILE_ACTIONS2.includes(a)) || new Set(files).size !== files.length)
|
|
34640
34661
|
throw mdbaseError("invalid_request", "Invalid file actions", "access_invalid");
|
|
34641
34662
|
if (typeof reason !== "string" || !reason.trim() || reason.length > 140 || /[\u0000-\u001f\u007f\u2028\u2029]/.test(reason))
|
|
34642
34663
|
throw mdbaseError("invalid_request", "Reason must be one line, 1-140 characters", "access_invalid");
|
|
@@ -34667,7 +34688,7 @@ ${end.comment}` : end.comment;
|
|
|
34667
34688
|
signal.addEventListener("abort", abort, { once: true });
|
|
34668
34689
|
});
|
|
34669
34690
|
}
|
|
34670
|
-
async function awaitFileAccess(port, portal, signal) {
|
|
34691
|
+
async function awaitFileAccess(port, portal, signal, callerSignal = signal) {
|
|
34671
34692
|
const finish = (result2) => {
|
|
34672
34693
|
try {
|
|
34673
34694
|
portal.close();
|
|
@@ -34675,40 +34696,44 @@ ${end.comment}` : end.comment;
|
|
|
34675
34696
|
}
|
|
34676
34697
|
return result2;
|
|
34677
34698
|
};
|
|
34699
|
+
const stopped = (id7) => callerSignal?.aborted ? cancelled2("aborted") : unknownOutcome(id7);
|
|
34678
34700
|
let started;
|
|
34679
34701
|
try {
|
|
34680
34702
|
started = await port.start();
|
|
34681
34703
|
} catch (error5) {
|
|
34682
|
-
if (signal.aborted) return finish(
|
|
34704
|
+
if (signal.aborted) return finish(stopped(null));
|
|
34683
34705
|
throw error5;
|
|
34684
34706
|
}
|
|
34685
|
-
const id6 = started.fileAccess?.requestId;
|
|
34686
|
-
let missedFinalReads = 0;
|
|
34687
|
-
for (
|
|
34707
|
+
const id6 = started.fileAccess?.requestId ?? null;
|
|
34708
|
+
let missedFinalReads = 0, last = false;
|
|
34709
|
+
for (; ; ) {
|
|
34688
34710
|
const current3 = port.native().fileAccess;
|
|
34689
|
-
if (!id6 || current3?.requestId !== id6) return finish(
|
|
34711
|
+
if (!id6 || current3?.requestId !== id6) return finish(signal.aborted ? stopped(id6) : unknownOutcome(id6));
|
|
34690
34712
|
if (current3.state === "granted") return finish(port.granted());
|
|
34691
34713
|
if (current3.state === "declined") return finish(DECLINED);
|
|
34692
|
-
if (current3.state === "expired"
|
|
34714
|
+
if (current3.state === "expired") return finish(cancelled2("expired"));
|
|
34715
|
+
if (signal.aborted) return finish(stopped(id6));
|
|
34716
|
+
if (last) return finish(cancelled2("closed"));
|
|
34693
34717
|
const closed = await tick(signal, portal);
|
|
34694
|
-
if (signal.aborted) return finish(
|
|
34718
|
+
if (signal.aborted) return finish(stopped(id6));
|
|
34695
34719
|
try {
|
|
34696
34720
|
await port.poll(id6);
|
|
34697
34721
|
last = closed;
|
|
34698
|
-
} catch
|
|
34699
|
-
if (signal.aborted) return finish(
|
|
34700
|
-
if (closed && ++missedFinalReads === 3)
|
|
34722
|
+
} catch {
|
|
34723
|
+
if (signal.aborted) return finish(stopped(id6));
|
|
34724
|
+
if (closed && ++missedFinalReads === 3) return finish(unknownOutcome(id6));
|
|
34701
34725
|
}
|
|
34702
34726
|
}
|
|
34703
34727
|
}
|
|
34704
|
-
var
|
|
34728
|
+
var FILE_ACTIONS2, refused3, cancelled2, unknownOutcome, DECLINED;
|
|
34705
34729
|
var init_file_access = __esm({
|
|
34706
34730
|
"src/application/file-access.ts"() {
|
|
34707
34731
|
"use strict";
|
|
34708
34732
|
init_errors();
|
|
34709
|
-
|
|
34733
|
+
FILE_ACTIONS2 = ["list", "read", "add", "replace", "move", "delete"];
|
|
34710
34734
|
refused3 = (action, declared) => declared ? mdbaseError("forbidden", `File action ${action} needs requestAccess first`, "access_required") : mdbaseError("forbidden", `File action ${action} is not declared`, "access_undeclared");
|
|
34711
|
-
|
|
34735
|
+
cancelled2 = (reason) => Object.freeze({ status: "cancelled", reason });
|
|
34736
|
+
unknownOutcome = (requestId) => Object.freeze({ status: "outcome_unknown", requestId });
|
|
34712
34737
|
DECLINED = Object.freeze({ status: "declined" });
|
|
34713
34738
|
}
|
|
34714
34739
|
});
|
|
@@ -39065,6 +39090,7 @@ ${end.comment}` : end.comment;
|
|
|
39065
39090
|
"src/app-grant/client.ts"() {
|
|
39066
39091
|
"use strict";
|
|
39067
39092
|
init_dist2();
|
|
39093
|
+
init_file_access();
|
|
39068
39094
|
init_return_url();
|
|
39069
39095
|
init_app_origin();
|
|
39070
39096
|
init_app_environment();
|
|
@@ -39613,7 +39639,12 @@ ${end.comment}` : end.comment;
|
|
|
39613
39639
|
const parsed = parseCollectionAvailability(raw.availability);
|
|
39614
39640
|
if (raw.state !== "synced_e2e" && !parsed) continue;
|
|
39615
39641
|
const availability = !held.has(id6) ? { state: "unavailable", reason: "sync_required" } : parsed ?? { state: "opening" };
|
|
39642
|
+
const grantId = raw.authorization_grant ?? raw.grant;
|
|
39643
|
+
const record5 = local.find((g) => g.collection === id6);
|
|
39644
|
+
const reviewed2 = raw.reviewed_file_actions;
|
|
39645
|
+
const matches2 = record5 && options.bindings?.some((b) => b.collection_id === id6 && b.grant_id === grantId && b.application_origin === this.declaration.origin && b.client_noise_public_key === b64u(record5.noisePublicKey));
|
|
39616
39646
|
out.push(Object.freeze({
|
|
39647
|
+
...matches2 && Array.isArray(reviewed2) ? { fileActions: Object.freeze(FILE_ACTIONS2.filter((action) => reviewed2.includes(action))) } : {},
|
|
39617
39648
|
collectionId: id6,
|
|
39618
39649
|
displayName: typeof raw.name === "string" ? raw.name : "Collection",
|
|
39619
39650
|
operations: Object.freeze(Array.isArray(raw.operations) ? raw.operations.filter((x) => typeof x === "string") : []),
|
|
@@ -44280,7 +44311,7 @@ ${end.comment}` : end.comment;
|
|
|
44280
44311
|
} catch (error5) {
|
|
44281
44312
|
throw mapPortError(error5);
|
|
44282
44313
|
}
|
|
44283
|
-
if (signal.aborted) throw
|
|
44314
|
+
if (signal.aborted) throw cancelled3();
|
|
44284
44315
|
const r = raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {}, mode = r.mode;
|
|
44285
44316
|
if (mode !== "password" && mode !== "strict" && mode !== "none") throw unavailable7("response");
|
|
44286
44317
|
return {
|
|
@@ -44308,7 +44339,7 @@ ${end.comment}` : end.comment;
|
|
|
44308
44339
|
if (password === recovery2 || typeof (password ? secret.password : secret.recoveryKey) !== "string" || !Number.isSafeInteger(settleMs) || settleMs < 1)
|
|
44309
44340
|
throw new AppAccountKeyUnlockError("unavailable", "binding");
|
|
44310
44341
|
const current3 = () => {
|
|
44311
|
-
if (signal.aborted) throw
|
|
44342
|
+
if (signal.aborted) throw cancelled3();
|
|
44312
44343
|
if (session.isCurrent() !== true) throw unavailable7("fenced");
|
|
44313
44344
|
};
|
|
44314
44345
|
current3();
|
|
@@ -44425,7 +44456,7 @@ ${end.comment}` : end.comment;
|
|
|
44425
44456
|
}
|
|
44426
44457
|
}
|
|
44427
44458
|
}
|
|
44428
|
-
var AppAccountKeyUnlockError, AppAccountKeySealedBundle, MAX_BODY, REQUEST_MS3, SETTLE_MS, unavailable7,
|
|
44459
|
+
var AppAccountKeyUnlockError, AppAccountKeySealedBundle, MAX_BODY, REQUEST_MS3, SETTLE_MS, unavailable7, cancelled3, unsupported2, hex12, HEX322, AppCpAccountKeyControl;
|
|
44429
44460
|
var init_account_key_host = __esm({
|
|
44430
44461
|
"src/app-host/account-key-host.ts"() {
|
|
44431
44462
|
"use strict";
|
|
@@ -44480,7 +44511,7 @@ ${end.comment}` : end.comment;
|
|
|
44480
44511
|
REQUEST_MS3 = 15e3;
|
|
44481
44512
|
SETTLE_MS = 45e3;
|
|
44482
44513
|
unavailable7 = (reason) => new AccountKeyError("unavailable", "The account key service refused or was unreachable.", { reason });
|
|
44483
|
-
|
|
44514
|
+
cancelled3 = () => new AccountKeyError("cancelled", "Account key request cancelled.");
|
|
44484
44515
|
unsupported2 = () => unavailable7("not_supported");
|
|
44485
44516
|
hex12 = (b) => Array.from(b, (v) => v.toString(16).padStart(2, "0")).join("");
|
|
44486
44517
|
HEX322 = /^[0-9a-f]{64}$/;
|
|
@@ -44507,7 +44538,7 @@ ${end.comment}` : end.comment;
|
|
|
44507
44538
|
fetchImpl;
|
|
44508
44539
|
now;
|
|
44509
44540
|
check(signal) {
|
|
44510
|
-
if (signal.aborted || this.lifetime.signal.aborted) throw
|
|
44541
|
+
if (signal.aborted || this.lifetime.signal.aborted) throw cancelled3();
|
|
44511
44542
|
let current3 = false;
|
|
44512
44543
|
try {
|
|
44513
44544
|
current3 = this.session.isCurrent() === true && this.session.accountId === this.accountId && this.session.deviceId === this.deviceId && this.session.cpOrigin === this.origin;
|
|
@@ -49632,7 +49663,7 @@ ${end.comment}` : end.comment;
|
|
|
49632
49663
|
lifetime.addEventListener("abort", close, { once: true });
|
|
49633
49664
|
if (lifetime.aborted) close();
|
|
49634
49665
|
function deliver(work, signal) {
|
|
49635
|
-
if (!current3() || signal?.aborted) return Promise.reject(
|
|
49666
|
+
if (!current3() || signal?.aborted) return Promise.reject(cancelled4());
|
|
49636
49667
|
return new Promise((resolve2, reject) => {
|
|
49637
49668
|
let settled2 = false;
|
|
49638
49669
|
const finish = (result2, error5) => {
|
|
@@ -49644,7 +49675,7 @@ ${end.comment}` : end.comment;
|
|
|
49644
49675
|
if (error5 !== void 0) reject(error5);
|
|
49645
49676
|
else resolve2(result2);
|
|
49646
49677
|
};
|
|
49647
|
-
const abort = () => finish(void 0,
|
|
49678
|
+
const abort = () => finish(void 0, cancelled4()), ended = () => {
|
|
49648
49679
|
if (!current3()) abort();
|
|
49649
49680
|
};
|
|
49650
49681
|
listeners.add(ended);
|
|
@@ -49655,14 +49686,14 @@ ${end.comment}` : end.comment;
|
|
|
49655
49686
|
if (!current3() || signal?.aborted) abort();
|
|
49656
49687
|
else finish(getSnapshot());
|
|
49657
49688
|
},
|
|
49658
|
-
() => finish(void 0,
|
|
49689
|
+
() => finish(void 0, cancelled4())
|
|
49659
49690
|
);
|
|
49660
49691
|
if (!current3() || signal?.aborted) abort();
|
|
49661
49692
|
});
|
|
49662
49693
|
}
|
|
49663
49694
|
function refresh(options = {}) {
|
|
49664
49695
|
const signal = options.signal;
|
|
49665
|
-
if (!current3() || signal?.aborted) return Promise.reject(
|
|
49696
|
+
if (!current3() || signal?.aborted) return Promise.reject(cancelled4());
|
|
49666
49697
|
if (pending)
|
|
49667
49698
|
return Promise.reject(
|
|
49668
49699
|
mdbaseError(
|
|
@@ -49734,7 +49765,7 @@ ${end.comment}` : end.comment;
|
|
|
49734
49765
|
options.signal
|
|
49735
49766
|
);
|
|
49736
49767
|
if (!current3() || options.signal?.aborted)
|
|
49737
|
-
return Promise.reject(
|
|
49768
|
+
return Promise.reject(cancelled4());
|
|
49738
49769
|
started = true;
|
|
49739
49770
|
return refresh(options);
|
|
49740
49771
|
},
|
|
@@ -49742,7 +49773,7 @@ ${end.comment}` : end.comment;
|
|
|
49742
49773
|
close
|
|
49743
49774
|
});
|
|
49744
49775
|
}
|
|
49745
|
-
var snapshot2, fenced2, ready,
|
|
49776
|
+
var snapshot2, fenced2, ready, cancelled4;
|
|
49746
49777
|
var init_people_readiness = __esm({
|
|
49747
49778
|
"src/application/people-readiness.ts"() {
|
|
49748
49779
|
"use strict";
|
|
@@ -49759,7 +49790,7 @@ ${end.comment}` : end.comment;
|
|
|
49759
49790
|
assessment: Object.freeze({ status: "ready", problem: null }),
|
|
49760
49791
|
problem: null
|
|
49761
49792
|
});
|
|
49762
|
-
|
|
49793
|
+
cancelled4 = () => mdbaseError(
|
|
49763
49794
|
"cancelled",
|
|
49764
49795
|
"People readiness ended",
|
|
49765
49796
|
"people_readiness_fenced"
|
|
@@ -49833,7 +49864,7 @@ ${end.comment}` : end.comment;
|
|
|
49833
49864
|
lifetime.addEventListener("abort", close, { once: true });
|
|
49834
49865
|
if (lifetime.aborted) close();
|
|
49835
49866
|
function deliver(work, signal) {
|
|
49836
|
-
if (!current3() || signal?.aborted) return Promise.reject(
|
|
49867
|
+
if (!current3() || signal?.aborted) return Promise.reject(cancelled5());
|
|
49837
49868
|
return new Promise((resolve2, reject) => {
|
|
49838
49869
|
let settled2 = false;
|
|
49839
49870
|
const finish = (result2, error5) => {
|
|
@@ -49845,7 +49876,7 @@ ${end.comment}` : end.comment;
|
|
|
49845
49876
|
if (error5 !== void 0) reject(error5);
|
|
49846
49877
|
else resolve2(result2);
|
|
49847
49878
|
};
|
|
49848
|
-
const abort = () => finish(void 0,
|
|
49879
|
+
const abort = () => finish(void 0, cancelled5());
|
|
49849
49880
|
const ended = () => {
|
|
49850
49881
|
if (!current3()) abort();
|
|
49851
49882
|
};
|
|
@@ -49857,14 +49888,14 @@ ${end.comment}` : end.comment;
|
|
|
49857
49888
|
if (!current3() || signal?.aborted) abort();
|
|
49858
49889
|
else finish(getSnapshot());
|
|
49859
49890
|
},
|
|
49860
|
-
() => finish(void 0,
|
|
49891
|
+
() => finish(void 0, cancelled5())
|
|
49861
49892
|
);
|
|
49862
49893
|
if (!current3() || signal?.aborted) abort();
|
|
49863
49894
|
});
|
|
49864
49895
|
}
|
|
49865
49896
|
function refresh(options = {}) {
|
|
49866
49897
|
const signal = options.signal;
|
|
49867
|
-
if (!current3() || signal?.aborted) return Promise.reject(
|
|
49898
|
+
if (!current3() || signal?.aborted) return Promise.reject(cancelled5());
|
|
49868
49899
|
if (pending)
|
|
49869
49900
|
return Promise.reject(
|
|
49870
49901
|
mdbaseError(
|
|
@@ -49937,7 +49968,7 @@ ${end.comment}` : end.comment;
|
|
|
49937
49968
|
options.signal
|
|
49938
49969
|
);
|
|
49939
49970
|
if (!current3() || options.signal?.aborted)
|
|
49940
|
-
return Promise.reject(
|
|
49971
|
+
return Promise.reject(cancelled5());
|
|
49941
49972
|
started = true;
|
|
49942
49973
|
return refresh(options);
|
|
49943
49974
|
},
|
|
@@ -49945,7 +49976,7 @@ ${end.comment}` : end.comment;
|
|
|
49945
49976
|
close
|
|
49946
49977
|
});
|
|
49947
49978
|
}
|
|
49948
|
-
var problem5, snapshot3, fenced3,
|
|
49979
|
+
var problem5, snapshot3, fenced3, cancelled5;
|
|
49949
49980
|
var init_notification_readiness = __esm({
|
|
49950
49981
|
"src/application/notification-readiness.ts"() {
|
|
49951
49982
|
"use strict";
|
|
@@ -49958,7 +49989,7 @@ ${end.comment}` : end.comment;
|
|
|
49958
49989
|
problem: code === null ? null : problem5(code)
|
|
49959
49990
|
});
|
|
49960
49991
|
fenced3 = snapshot3("notifications_fenced");
|
|
49961
|
-
|
|
49992
|
+
cancelled5 = () => mdbaseError(
|
|
49962
49993
|
"cancelled",
|
|
49963
49994
|
"Notification readiness ended",
|
|
49964
49995
|
"notification_readiness_fenced"
|
|
@@ -53712,6 +53743,7 @@ ${end.comment}` : end.comment;
|
|
|
53712
53743
|
const next = Object.freeze(found.filter((c) => UUID11.test(c.collectionId)).map((c) => Object.freeze({
|
|
53713
53744
|
collectionId: c.collectionId,
|
|
53714
53745
|
displayName: c.displayName,
|
|
53746
|
+
...c.fileActions ? { fileActions: c.fileActions } : {},
|
|
53715
53747
|
// Display only (Connect checks every action); an unreported role reads as editor.
|
|
53716
53748
|
role: c.role ?? "editor",
|
|
53717
53749
|
availability: c.availability,
|
|
@@ -54763,20 +54795,27 @@ ${end.comment}` : end.comment;
|
|
|
54763
54795
|
requestAccess(request3, options) {
|
|
54764
54796
|
try {
|
|
54765
54797
|
this.check();
|
|
54766
|
-
const runtime2 = this.runtime, native = runtime2?.getNativeSnapshot()
|
|
54798
|
+
const runtime2 = this.runtime, native = runtime2?.getNativeSnapshot();
|
|
54799
|
+
const privateId = this.privates?.state()?.collectionId, id6 = privateId ?? native?.selectedCollectionId ?? null;
|
|
54767
54800
|
const declaration = fileAccessDeclaration(this.compiled), consented = () => id6 && runtime2 ? consentedFileActions(runtime2.getNativeSnapshot(), id6) : [];
|
|
54768
54801
|
const missing = missingFileActions(declaration, request3, options, consented());
|
|
54769
|
-
const connection = id6 ?
|
|
54802
|
+
const connection = id6 ? this.connection(id6) : null;
|
|
54770
54803
|
if (!runtime2 || !id6 || !connection) throw mdbaseError("invalid_request", "requestAccess needs an open collection", "access_no_collection");
|
|
54804
|
+
if (privateId) {
|
|
54805
|
+
const reviewed2 = this.privates?.entries().find((c) => c.collectionId === privateId)?.fileActions ?? [];
|
|
54806
|
+
const actions2 = (connection.files.grant?.actions ?? []).filter((action) => declaration?.required.includes(action) || declaration?.optional.includes(action) && reviewed2.includes(action));
|
|
54807
|
+
return Promise.resolve(request3.files.every((action) => actions2.includes(action)) ? Object.freeze({ status: "granted", actions: Object.freeze(actions2) }) : Object.freeze({ status: "unavailable", reason: "private_relay" }));
|
|
54808
|
+
}
|
|
54771
54809
|
const granted = () => grantedResult(connection.files, declaration, consented());
|
|
54772
54810
|
if (!missing.length) return Promise.resolve(granted());
|
|
54811
|
+
if (native?.unsynced?.collectionId === id6) return Promise.resolve(Object.freeze({ status: "unavailable", reason: "until_connected" }));
|
|
54773
54812
|
const { portal, signal } = this.reservePortal(options);
|
|
54774
54813
|
return awaitFileAccess({
|
|
54775
54814
|
granted,
|
|
54776
54815
|
native: () => runtime2.getNativeSnapshot(),
|
|
54777
54816
|
start: () => runtime2.queue(() => runtime2.requestFileAccess(portal, id6, missing, options.reason, { signal })),
|
|
54778
54817
|
poll: (requestId) => runtime2.queue(() => runtime2.pollFileAccess(requestId))
|
|
54779
|
-
}, portal, signal);
|
|
54818
|
+
}, portal, signal, options.signal ?? null);
|
|
54780
54819
|
} catch (error5) {
|
|
54781
54820
|
return Promise.reject(error5);
|
|
54782
54821
|
}
|