@opendatalabs/personal-server-ts-server 0.0.1-canary.eecb7d7 → 0.0.1-canary.eefd1bc
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/ui/ps-lite-debug.js +185 -88
- package/package.json +3 -3
package/dist/ui/ps-lite-debug.js
CHANGED
|
@@ -125498,6 +125498,12 @@ async function uploadOne(deps, entry) {
|
|
|
125498
125498
|
dataPointId = record2.id;
|
|
125499
125499
|
const adoptedVersion = Number(record2.expectedVersion);
|
|
125500
125500
|
if (adoptedVersion !== entry.version) {
|
|
125501
|
+
const adoptedKey = `${entry.scope}/${adoptedVersion}`;
|
|
125502
|
+
const adoptedBlobExists = await storageAdapter.exists(storageAdapter.urlForKey(adoptedKey));
|
|
125503
|
+
if (!adoptedBlobExists) {
|
|
125504
|
+
logger.warn({ scope: entry.scope, version: adoptedVersion, dataPointId }, "Adopted registry version has no blob in storage; re-uploading from local content");
|
|
125505
|
+
url2 = await storageAdapter.upload(adoptedKey, encrypted);
|
|
125506
|
+
}
|
|
125501
125507
|
await storage.updateEntryVersion(entry.path, adoptedVersion);
|
|
125502
125508
|
}
|
|
125503
125509
|
} else {
|
|
@@ -125555,7 +125561,7 @@ var DETERMINISTIC_STAGES = /* @__PURE__ */ new Set([
|
|
|
125555
125561
|
"envelope_validate",
|
|
125556
125562
|
"block_build"
|
|
125557
125563
|
]);
|
|
125558
|
-
var
|
|
125564
|
+
var DETERMINISTIC_DOWNLOAD_STATUSES = /* @__PURE__ */ new Set([404, 410]);
|
|
125559
125565
|
function classifySyncFailure(input) {
|
|
125560
125566
|
const stage = input.stage ?? inferStage(input.error);
|
|
125561
125567
|
const disposition = classifyDisposition(input.error, stage);
|
|
@@ -125614,9 +125620,9 @@ function inferPayloadKind(bytes2) {
|
|
|
125614
125620
|
}
|
|
125615
125621
|
function classifyDisposition(error51, stage) {
|
|
125616
125622
|
if (stage === "download") {
|
|
125617
|
-
const status2 = getNumericProperty(error51, "status") ?? getNumericProperty(error51, "statusCode");
|
|
125623
|
+
const status2 = getNumericProperty(error51, "status") ?? getNumericProperty(error51, "statusCode") ?? getDownloadStatusFromMessage(error51);
|
|
125618
125624
|
if (status2 !== void 0) {
|
|
125619
|
-
return
|
|
125625
|
+
return DETERMINISTIC_DOWNLOAD_STATUSES.has(status2) ? "deterministic" : "transient";
|
|
125620
125626
|
}
|
|
125621
125627
|
return "transient";
|
|
125622
125628
|
}
|
|
@@ -125662,6 +125668,10 @@ function getStringProperty(value, key) {
|
|
|
125662
125668
|
const property = value[key];
|
|
125663
125669
|
return typeof property === "string" ? property : "";
|
|
125664
125670
|
}
|
|
125671
|
+
function getDownloadStatusFromMessage(error51) {
|
|
125672
|
+
const match = /download failed: ([1-5]\d{2})\b/.exec(getRawMessage(error51));
|
|
125673
|
+
return match ? Number(match[1]) : void 0;
|
|
125674
|
+
}
|
|
125665
125675
|
function getNumericProperty(value, key) {
|
|
125666
125676
|
if (typeof value !== "object" || value === null || !(key in value)) {
|
|
125667
125677
|
return void 0;
|
|
@@ -125693,6 +125703,52 @@ function getSafeIssueMessage(stage, disposition) {
|
|
|
125693
125703
|
}
|
|
125694
125704
|
}
|
|
125695
125705
|
|
|
125706
|
+
// ../core/dist/sync/retry-memory.js
|
|
125707
|
+
var DEFAULT_MAX_TRANSIENT_ATTEMPTS = 5;
|
|
125708
|
+
var DEFAULT_BACKOFF_BASE_MS = 3e4;
|
|
125709
|
+
function downloadRetryKey(record2) {
|
|
125710
|
+
return `${record2.id}@${record2.expectedVersion}`;
|
|
125711
|
+
}
|
|
125712
|
+
function createDownloadRetryMemory(options = {}) {
|
|
125713
|
+
const maxTransientAttempts = options.maxTransientAttempts ?? DEFAULT_MAX_TRANSIENT_ATTEMPTS;
|
|
125714
|
+
const backoffBaseMs = options.backoffBaseMs ?? DEFAULT_BACKOFF_BASE_MS;
|
|
125715
|
+
const now = options.now ?? Date.now;
|
|
125716
|
+
const entries = /* @__PURE__ */ new Map();
|
|
125717
|
+
return {
|
|
125718
|
+
decide(key) {
|
|
125719
|
+
const entry = entries.get(key);
|
|
125720
|
+
if (!entry)
|
|
125721
|
+
return "attempt";
|
|
125722
|
+
if (entry.permanent || entry.attempts >= maxTransientAttempts) {
|
|
125723
|
+
return "give-up";
|
|
125724
|
+
}
|
|
125725
|
+
return now() < entry.nextRetryAtMs ? "backoff" : "attempt";
|
|
125726
|
+
},
|
|
125727
|
+
recordFailure(key, retryable) {
|
|
125728
|
+
if (!retryable) {
|
|
125729
|
+
entries.set(key, { attempts: 0, nextRetryAtMs: 0, permanent: true });
|
|
125730
|
+
return;
|
|
125731
|
+
}
|
|
125732
|
+
const attempts = (entries.get(key)?.attempts ?? 0) + 1;
|
|
125733
|
+
entries.set(key, {
|
|
125734
|
+
attempts,
|
|
125735
|
+
nextRetryAtMs: now() + backoffBaseMs * 2 ** (attempts - 1),
|
|
125736
|
+
permanent: false
|
|
125737
|
+
});
|
|
125738
|
+
},
|
|
125739
|
+
recordSuccess(key) {
|
|
125740
|
+
entries.delete(key);
|
|
125741
|
+
},
|
|
125742
|
+
onListingReset() {
|
|
125743
|
+
for (const [key, entry] of entries) {
|
|
125744
|
+
if (!entry.permanent) {
|
|
125745
|
+
entries.delete(key);
|
|
125746
|
+
}
|
|
125747
|
+
}
|
|
125748
|
+
}
|
|
125749
|
+
};
|
|
125750
|
+
}
|
|
125751
|
+
|
|
125696
125752
|
// ../core/dist/sync/workers/download.js
|
|
125697
125753
|
async function downloadOne(deps, record2) {
|
|
125698
125754
|
const { storage, storageAdapter, masterKey, logger, diagnostics } = deps;
|
|
@@ -125720,7 +125776,10 @@ async function downloadOne(deps, record2) {
|
|
|
125720
125776
|
} catch (err2) {
|
|
125721
125777
|
const detail = err2.message;
|
|
125722
125778
|
diagnostics?.onDownloadError(record2.id, detail);
|
|
125723
|
-
throw err2
|
|
125779
|
+
throw withSyncFailureMetadata(err2, {
|
|
125780
|
+
stage: "download",
|
|
125781
|
+
scope: record2.scope
|
|
125782
|
+
});
|
|
125724
125783
|
}
|
|
125725
125784
|
diagnostics?.onDownloadEnd(record2.id, record2.scope);
|
|
125726
125785
|
const scopeKey = deriveScopeKey(masterKey, record2.scope);
|
|
@@ -125828,12 +125887,26 @@ async function downloadAll(deps, options = {}) {
|
|
|
125828
125887
|
if (repairSummary.missingEnvelopeEntries > 0) {
|
|
125829
125888
|
logger.warn({ missingEnvelopeEntries: repairSummary.missingEnvelopeEntries }, "Resetting this sync listing to repair stale local index entries");
|
|
125830
125889
|
}
|
|
125890
|
+
if (options.fullReconcile || repairSummary.missingEnvelopeEntries > 0) {
|
|
125891
|
+
options.retryMemory?.onListingReset();
|
|
125892
|
+
}
|
|
125831
125893
|
const { dataPoints, cursor: nextCursor } = await gateway.listDataPointsByOwner(serverOwner, lastCursor);
|
|
125832
125894
|
const results = [];
|
|
125833
125895
|
let failed = false;
|
|
125834
125896
|
for (const dataPoint of dataPoints) {
|
|
125897
|
+
const retryKey = downloadRetryKey(dataPoint);
|
|
125898
|
+
const decision = options.retryMemory?.decide(retryKey) ?? "attempt";
|
|
125899
|
+
if (decision === "give-up") {
|
|
125900
|
+
logger.debug({ dataPointId: dataPoint.id, scope: dataPoint.scope }, "Skipping data point after exhausted download retries");
|
|
125901
|
+
continue;
|
|
125902
|
+
}
|
|
125903
|
+
if (decision === "backoff") {
|
|
125904
|
+
failed = true;
|
|
125905
|
+
continue;
|
|
125906
|
+
}
|
|
125835
125907
|
try {
|
|
125836
125908
|
const result = await downloadOne(deps, dataPoint);
|
|
125909
|
+
options.retryMemory?.recordSuccess(retryKey);
|
|
125837
125910
|
if (result) {
|
|
125838
125911
|
results.push(result);
|
|
125839
125912
|
}
|
|
@@ -125848,6 +125921,7 @@ async function downloadAll(deps, options = {}) {
|
|
|
125848
125921
|
payloadKind: metadata.payloadKind,
|
|
125849
125922
|
encryptedSizeBytes: metadata.encryptedSizeBytes
|
|
125850
125923
|
});
|
|
125924
|
+
options.retryMemory?.recordFailure(retryKey, classified.issue.retryable);
|
|
125851
125925
|
if (!classified.issue.retryable) {
|
|
125852
125926
|
logger.warn({
|
|
125853
125927
|
dataPointId: dataPoint.id,
|
|
@@ -126071,6 +126145,7 @@ function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
126071
126145
|
let cycleInFlight = null;
|
|
126072
126146
|
let rerunRequested = false;
|
|
126073
126147
|
let needsFullReconcile = true;
|
|
126148
|
+
const downloadRetryMemory = createDownloadRetryMemory();
|
|
126074
126149
|
async function runCycle() {
|
|
126075
126150
|
if (cycleInFlight) {
|
|
126076
126151
|
rerunRequested = true;
|
|
@@ -126112,7 +126187,8 @@ function createSyncManager(uploadDeps, downloadDeps, options) {
|
|
|
126112
126187
|
try {
|
|
126113
126188
|
const fullReconcile = needsFullReconcile;
|
|
126114
126189
|
const downloadResults = await downloadAll(downloadDeps, {
|
|
126115
|
-
fullReconcile
|
|
126190
|
+
fullReconcile,
|
|
126191
|
+
retryMemory: downloadRetryMemory
|
|
126116
126192
|
});
|
|
126117
126193
|
needsFullReconcile = false;
|
|
126118
126194
|
downloadDeps.logger.debug({ downloaded: downloadResults.length, fullReconcile }, "Download cycle complete");
|
|
@@ -126256,12 +126332,30 @@ function createSdkStorageAdapter(providerOrFactory, options) {
|
|
|
126256
126332
|
try {
|
|
126257
126333
|
await provider().download(storageUrl);
|
|
126258
126334
|
return true;
|
|
126259
|
-
} catch {
|
|
126260
|
-
|
|
126335
|
+
} catch (err2) {
|
|
126336
|
+
if (isDefinitiveNotFound(err2)) {
|
|
126337
|
+
return false;
|
|
126338
|
+
}
|
|
126339
|
+
throw err2;
|
|
126261
126340
|
}
|
|
126262
126341
|
}
|
|
126263
126342
|
};
|
|
126264
126343
|
}
|
|
126344
|
+
function isDefinitiveNotFound(err2) {
|
|
126345
|
+
const status2 = numericProperty(err2, "status") ?? numericProperty(err2, "statusCode");
|
|
126346
|
+
if (status2 !== void 0) {
|
|
126347
|
+
return status2 === 404 || status2 === 410;
|
|
126348
|
+
}
|
|
126349
|
+
const message = err2 instanceof Error ? err2.message : String(err2);
|
|
126350
|
+
return /download failed: (404|410)\b/.test(message);
|
|
126351
|
+
}
|
|
126352
|
+
function numericProperty(value, key) {
|
|
126353
|
+
if (typeof value !== "object" || value === null || !(key in value)) {
|
|
126354
|
+
return void 0;
|
|
126355
|
+
}
|
|
126356
|
+
const property = value[key];
|
|
126357
|
+
return typeof property === "number" ? property : void 0;
|
|
126358
|
+
}
|
|
126265
126359
|
function copyBytes(data) {
|
|
126266
126360
|
const copy = new Uint8Array(data.byteLength);
|
|
126267
126361
|
copy.set(data);
|
|
@@ -126326,13 +126420,22 @@ async function resolvePsLiteOwner(input) {
|
|
|
126326
126420
|
|
|
126327
126421
|
// ../lite/dist/sync.js
|
|
126328
126422
|
var SYNC_CURSOR_KEY = "sync-cursor-v1";
|
|
126329
|
-
function createBrowserLogger() {
|
|
126330
|
-
|
|
126423
|
+
function createBrowserLogger(logger) {
|
|
126424
|
+
const fallback = {
|
|
126331
126425
|
info: console.info.bind(console),
|
|
126332
126426
|
error: console.error.bind(console),
|
|
126333
126427
|
warn: console.warn.bind(console),
|
|
126334
126428
|
debug: console.debug.bind(console)
|
|
126335
126429
|
};
|
|
126430
|
+
if (!logger) {
|
|
126431
|
+
return fallback;
|
|
126432
|
+
}
|
|
126433
|
+
return {
|
|
126434
|
+
debug: logger.debug?.bind(logger) ?? fallback.debug,
|
|
126435
|
+
info: logger.info?.bind(logger) ?? fallback.info,
|
|
126436
|
+
warn: logger.warn?.bind(logger) ?? fallback.warn,
|
|
126437
|
+
error: logger.error?.bind(logger) ?? fallback.error
|
|
126438
|
+
};
|
|
126336
126439
|
}
|
|
126337
126440
|
function createPsLiteSyncCursor(stateStore) {
|
|
126338
126441
|
return {
|
|
@@ -126431,7 +126534,7 @@ async function createPsLiteSyncManager(options) {
|
|
|
126431
126534
|
contracts: options.config.gateway.contracts
|
|
126432
126535
|
});
|
|
126433
126536
|
const cursor = createPsLiteSyncCursor(options.stateStore);
|
|
126434
|
-
const logger = createBrowserLogger();
|
|
126537
|
+
const logger = createBrowserLogger(options.logger);
|
|
126435
126538
|
const downloadDiagnostics = options.diagnostics ? buildDownloadDiagnosticsHook(options.diagnostics) : void 0;
|
|
126436
126539
|
const syncManager = createSyncManager({
|
|
126437
126540
|
storage: options.storage,
|
|
@@ -126462,7 +126565,7 @@ async function createPsLiteSyncManager(options) {
|
|
|
126462
126565
|
message: "Register this Personal Server before syncing."
|
|
126463
126566
|
};
|
|
126464
126567
|
} catch (err2) {
|
|
126465
|
-
logger.warn("Could not verify server registration for sync"
|
|
126568
|
+
logger.warn({ error: err2 instanceof Error ? err2.message : String(err2) }, "Could not verify server registration for sync");
|
|
126466
126569
|
return {
|
|
126467
126570
|
ok: false,
|
|
126468
126571
|
reason: "registration_check_failed",
|
|
@@ -126520,7 +126623,8 @@ async function createIndexedDbPsLiteRuntime(options) {
|
|
|
126520
126623
|
ownerAddress: options.ownerAddress,
|
|
126521
126624
|
serverAccount: identity.account,
|
|
126522
126625
|
gateway,
|
|
126523
|
-
diagnostics
|
|
126626
|
+
diagnostics,
|
|
126627
|
+
logger: options.logger
|
|
126524
126628
|
})).syncManager;
|
|
126525
126629
|
}
|
|
126526
126630
|
let runtimeRef = null;
|
|
@@ -127125,7 +127229,20 @@ async function readJsonBody(response) {
|
|
|
127125
127229
|
}
|
|
127126
127230
|
}
|
|
127127
127231
|
function toClientErrorBody(value) {
|
|
127128
|
-
|
|
127232
|
+
if (!value || typeof value !== "object")
|
|
127233
|
+
return null;
|
|
127234
|
+
const record2 = value;
|
|
127235
|
+
if (record2.error && typeof record2.error === "object") {
|
|
127236
|
+
return record2;
|
|
127237
|
+
}
|
|
127238
|
+
const message = typeof record2.message === "string" ? record2.message : void 0;
|
|
127239
|
+
if (typeof record2.error === "string") {
|
|
127240
|
+
return { ...record2, error: { errorCode: record2.error, message } };
|
|
127241
|
+
}
|
|
127242
|
+
if (message !== void 0) {
|
|
127243
|
+
return { ...record2, error: { message } };
|
|
127244
|
+
}
|
|
127245
|
+
return record2;
|
|
127129
127246
|
}
|
|
127130
127247
|
function assertRegistrationMatches(existing, candidate) {
|
|
127131
127248
|
if (existing.serverUrl === candidate.serverUrl)
|
|
@@ -127568,7 +127685,7 @@ async function __wbg_init(module_or_path) {
|
|
|
127568
127685
|
// ../lite/dist/relay-tls.js
|
|
127569
127686
|
var TLS_IDENTITY_CACHE_KEY = "personal-server-lite-tls-identity-v1";
|
|
127570
127687
|
var DEFAULT_PUBLIC_SUFFIX = "34.16.49.200.sslip.io";
|
|
127571
|
-
var DEFAULT_ISSUE_CERT_TIMEOUT_MS =
|
|
127688
|
+
var DEFAULT_ISSUE_CERT_TIMEOUT_MS = 6e4;
|
|
127572
127689
|
var rustlsInitPromise;
|
|
127573
127690
|
function createRustlsPsLiteRelayTlsFactory(options) {
|
|
127574
127691
|
let trustedIdentity;
|
|
@@ -127595,7 +127712,7 @@ function createRustlsPsLiteRelayTlsFactory(options) {
|
|
|
127595
127712
|
} else if (trustedIdentity) {
|
|
127596
127713
|
return trustedIdentity;
|
|
127597
127714
|
} else {
|
|
127598
|
-
options.logger?.(`serving self-signed cert for ${identity.hostname};
|
|
127715
|
+
options.logger?.(`serving self-signed cert for ${identity.hostname}; relay certificate unavailable this attempt, will retry on the next stream/reconnect`);
|
|
127599
127716
|
}
|
|
127600
127717
|
return identity;
|
|
127601
127718
|
}
|
|
@@ -127645,23 +127762,20 @@ async function createTlsIdentity(input, options) {
|
|
|
127645
127762
|
if (cached2) {
|
|
127646
127763
|
return cached2;
|
|
127647
127764
|
}
|
|
127648
|
-
const
|
|
127649
|
-
|
|
127650
|
-
const csrPem = createCsrPem(hostname3, keys);
|
|
127651
|
-
const issued = await requestAcmeCertificate({
|
|
127652
|
-
issuerUrl: resolveCertIssuerUrl(options),
|
|
127765
|
+
const wildcard = await requestSessionCertificate({
|
|
127766
|
+
issuerUrl: resolveSessionCertUrl(options),
|
|
127653
127767
|
sessionId: input.sessionId,
|
|
127654
|
-
csrPem,
|
|
127655
|
-
keyPem,
|
|
127656
127768
|
issueToken: input.issueToken ?? "",
|
|
127657
127769
|
hostname: hostname3,
|
|
127658
127770
|
storage: options.storage,
|
|
127659
127771
|
logger: options.logger,
|
|
127660
127772
|
timeoutMs: options.issueCertTimeoutMs ?? DEFAULT_ISSUE_CERT_TIMEOUT_MS
|
|
127661
127773
|
});
|
|
127662
|
-
if (
|
|
127663
|
-
return
|
|
127774
|
+
if (wildcard) {
|
|
127775
|
+
return wildcard;
|
|
127664
127776
|
}
|
|
127777
|
+
const keys = await generateKeyPair();
|
|
127778
|
+
const keyPem = import_node_forge.default.pki.privateKeyToPem(keys.privateKey);
|
|
127665
127779
|
return createSelfSignedIdentity(hostname3, keyPem, keys);
|
|
127666
127780
|
}
|
|
127667
127781
|
function generateKeyPair() {
|
|
@@ -127675,24 +127789,6 @@ function generateKeyPair() {
|
|
|
127675
127789
|
});
|
|
127676
127790
|
});
|
|
127677
127791
|
}
|
|
127678
|
-
function createCsrPem(hostname3, keys) {
|
|
127679
|
-
const csr = import_node_forge.default.pki.createCertificationRequest();
|
|
127680
|
-
csr.publicKey = keys.publicKey;
|
|
127681
|
-
csr.setSubject([{ name: "commonName", value: hostname3 }]);
|
|
127682
|
-
csr.setAttributes([
|
|
127683
|
-
{
|
|
127684
|
-
name: "extensionRequest",
|
|
127685
|
-
extensions: [
|
|
127686
|
-
{
|
|
127687
|
-
name: "subjectAltName",
|
|
127688
|
-
altNames: [{ type: 2, value: hostname3 }]
|
|
127689
|
-
}
|
|
127690
|
-
]
|
|
127691
|
-
}
|
|
127692
|
-
]);
|
|
127693
|
-
csr.sign(keys.privateKey, import_node_forge.default.md.sha256.create());
|
|
127694
|
-
return import_node_forge.default.pki.certificationRequestToPem(csr);
|
|
127695
|
-
}
|
|
127696
127792
|
function createSelfSignedIdentity(hostname3, keyPem, keys) {
|
|
127697
127793
|
const cert = import_node_forge.default.pki.createCertificate();
|
|
127698
127794
|
cert.publicKey = keys.publicKey;
|
|
@@ -127720,48 +127816,71 @@ function createSelfSignedIdentity(hostname3, keyPem, keys) {
|
|
|
127720
127816
|
trusted: false
|
|
127721
127817
|
};
|
|
127722
127818
|
}
|
|
127723
|
-
|
|
127819
|
+
function issueCertAbortSignal(timeoutMs) {
|
|
127820
|
+
return typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function" ? AbortSignal.timeout(timeoutMs) : void 0;
|
|
127821
|
+
}
|
|
127822
|
+
function withIssueCertTimeout(promise2, timeoutMs) {
|
|
127823
|
+
return new Promise((resolve, reject) => {
|
|
127824
|
+
const timer = setTimeout(() => {
|
|
127825
|
+
reject(new Error(`certificate issuer did not respond within ${timeoutMs}ms`));
|
|
127826
|
+
}, timeoutMs);
|
|
127827
|
+
promise2.then((value) => {
|
|
127828
|
+
clearTimeout(timer);
|
|
127829
|
+
resolve(value);
|
|
127830
|
+
}, (error51) => {
|
|
127831
|
+
clearTimeout(timer);
|
|
127832
|
+
reject(error51);
|
|
127833
|
+
});
|
|
127834
|
+
});
|
|
127835
|
+
}
|
|
127836
|
+
function resolveSessionCertUrl(options) {
|
|
127837
|
+
const base = options.certIssuerUrl ? options.certIssuerUrl.replace(/\/+$/, "").replace(/\/issue-cert$/, "") : (() => {
|
|
127838
|
+
const url2 = new URL(options.controlUrl);
|
|
127839
|
+
url2.protocol = url2.protocol === "wss:" ? "https:" : "http:";
|
|
127840
|
+
url2.pathname = "";
|
|
127841
|
+
url2.search = "";
|
|
127842
|
+
url2.hash = "";
|
|
127843
|
+
return url2.toString().replace(/\/+$/, "");
|
|
127844
|
+
})();
|
|
127845
|
+
return `${base}/session-cert`;
|
|
127846
|
+
}
|
|
127847
|
+
async function requestSessionCertificate(input) {
|
|
127724
127848
|
if (!input.issueToken) {
|
|
127725
|
-
input.logger?.("
|
|
127849
|
+
input.logger?.("session issue token unavailable; using self-signed certificate");
|
|
127726
127850
|
return void 0;
|
|
127727
127851
|
}
|
|
127728
127852
|
try {
|
|
127729
|
-
return await withIssueCertTimeout(
|
|
127853
|
+
return await withIssueCertTimeout(fetchSessionCert(input), input.timeoutMs);
|
|
127730
127854
|
} catch (error51) {
|
|
127731
127855
|
input.logger?.(error51 instanceof Error ? error51.message : String(error51));
|
|
127732
|
-
input.logger?.("
|
|
127856
|
+
input.logger?.("session certificate request failed; using self-signed certificate");
|
|
127733
127857
|
return void 0;
|
|
127734
127858
|
}
|
|
127735
127859
|
}
|
|
127736
|
-
async function
|
|
127860
|
+
async function fetchSessionCert(input) {
|
|
127737
127861
|
const response = await fetch(input.issuerUrl, {
|
|
127738
127862
|
method: "POST",
|
|
127739
127863
|
headers: { "content-type": "application/json" },
|
|
127740
127864
|
body: JSON.stringify({
|
|
127741
127865
|
sessionId: input.sessionId,
|
|
127742
|
-
csrPem: input.csrPem,
|
|
127743
127866
|
issueToken: input.issueToken
|
|
127744
127867
|
}),
|
|
127745
|
-
// Belt: cancels the request in flight where supported. The
|
|
127746
|
-
// withIssueCertTimeout race is the load-bearing guard — a fetch whose
|
|
127747
|
-
// implementation ignores `signal` must still not wedge identity
|
|
127748
|
-
// resolution.
|
|
127749
127868
|
signal: issueCertAbortSignal(input.timeoutMs)
|
|
127750
127869
|
});
|
|
127751
127870
|
if (!response.ok) {
|
|
127752
127871
|
const detail = await response.text();
|
|
127753
|
-
input.logger?.(`
|
|
127872
|
+
input.logger?.(`session-cert unavailable (${response.status}); using self-signed certificate`);
|
|
127754
127873
|
input.logger?.(detail.slice(0, 240));
|
|
127755
127874
|
return void 0;
|
|
127756
127875
|
}
|
|
127757
127876
|
const payload = await response.json();
|
|
127758
|
-
if (!payload.certPem) {
|
|
127759
|
-
input.logger?.("
|
|
127877
|
+
if (!payload.certPem || !payload.keyPem) {
|
|
127878
|
+
input.logger?.("session-cert returned no certificate; using self-signed certificate");
|
|
127760
127879
|
return void 0;
|
|
127761
127880
|
}
|
|
127762
127881
|
const identity = {
|
|
127763
127882
|
certPem: payload.certPem,
|
|
127764
|
-
keyPem:
|
|
127883
|
+
keyPem: payload.keyPem,
|
|
127765
127884
|
hostname: input.hostname,
|
|
127766
127885
|
source: "acme",
|
|
127767
127886
|
trusted: true
|
|
@@ -127769,38 +127888,10 @@ async function issueCertificate(input) {
|
|
|
127769
127888
|
try {
|
|
127770
127889
|
cacheTlsIdentity(identity, input.storage);
|
|
127771
127890
|
} catch (error51) {
|
|
127772
|
-
input.logger?.(`failed to persist
|
|
127891
|
+
input.logger?.(`failed to persist session certificate (${error51 instanceof Error ? error51.message : String(error51)}); continuing with the in-memory identity`);
|
|
127773
127892
|
}
|
|
127774
127893
|
return identity;
|
|
127775
127894
|
}
|
|
127776
|
-
function issueCertAbortSignal(timeoutMs) {
|
|
127777
|
-
return typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function" ? AbortSignal.timeout(timeoutMs) : void 0;
|
|
127778
|
-
}
|
|
127779
|
-
function withIssueCertTimeout(promise2, timeoutMs) {
|
|
127780
|
-
return new Promise((resolve, reject) => {
|
|
127781
|
-
const timer = setTimeout(() => {
|
|
127782
|
-
reject(new Error(`certificate issuer did not respond within ${timeoutMs}ms (hung /issue-cert)`));
|
|
127783
|
-
}, timeoutMs);
|
|
127784
|
-
promise2.then((value) => {
|
|
127785
|
-
clearTimeout(timer);
|
|
127786
|
-
resolve(value);
|
|
127787
|
-
}, (error51) => {
|
|
127788
|
-
clearTimeout(timer);
|
|
127789
|
-
reject(error51);
|
|
127790
|
-
});
|
|
127791
|
-
});
|
|
127792
|
-
}
|
|
127793
|
-
function resolveCertIssuerUrl(options) {
|
|
127794
|
-
if (options.certIssuerUrl) {
|
|
127795
|
-
return options.certIssuerUrl.replace(/\/+$/, "");
|
|
127796
|
-
}
|
|
127797
|
-
const url2 = new URL(options.controlUrl);
|
|
127798
|
-
url2.protocol = url2.protocol === "wss:" ? "https:" : "http:";
|
|
127799
|
-
url2.pathname = "/issue-cert";
|
|
127800
|
-
url2.search = "";
|
|
127801
|
-
url2.hash = "";
|
|
127802
|
-
return url2.toString();
|
|
127803
|
-
}
|
|
127804
127895
|
function readCachedTlsIdentity(hostname3, storage = globalThis.localStorage) {
|
|
127805
127896
|
try {
|
|
127806
127897
|
const raw = storage.getItem(`${TLS_IDENTITY_CACHE_KEY}:${hostname3}`);
|
|
@@ -128479,7 +128570,7 @@ async function startPersonalServer(options) {
|
|
|
128479
128570
|
}
|
|
128480
128571
|
async function callFetch(input, init) {
|
|
128481
128572
|
const origin = (await info()).urls.apiOrigin ?? localOrigin;
|
|
128482
|
-
return runtime.fetch(toRuntimeRequest(input, origin, init));
|
|
128573
|
+
return runtime.fetch(await toRuntimeRequest(input, origin, init));
|
|
128483
128574
|
}
|
|
128484
128575
|
async function postData2(scope, body, postOptions) {
|
|
128485
128576
|
const current = await info();
|
|
@@ -128714,10 +128805,16 @@ function requiredApiOrigin(info) {
|
|
|
128714
128805
|
}
|
|
128715
128806
|
return info.urls.apiOrigin;
|
|
128716
128807
|
}
|
|
128717
|
-
function toRuntimeRequest(input, origin, init) {
|
|
128808
|
+
async function toRuntimeRequest(input, origin, init) {
|
|
128718
128809
|
const url2 = `${origin}${requestPath(input)}`;
|
|
128719
128810
|
if (input instanceof Request) {
|
|
128720
|
-
const
|
|
128811
|
+
const buffered = input.method === "GET" || input.method === "HEAD" ? void 0 : await input.clone().arrayBuffer();
|
|
128812
|
+
const base = new Request(url2, {
|
|
128813
|
+
method: input.method,
|
|
128814
|
+
headers: input.headers,
|
|
128815
|
+
body: buffered && buffered.byteLength > 0 ? buffered : void 0,
|
|
128816
|
+
signal: input.signal
|
|
128817
|
+
});
|
|
128721
128818
|
return init ? new Request(base, init) : base;
|
|
128722
128819
|
}
|
|
128723
128820
|
return new Request(url2, init);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendatalabs/personal-server-ts-server",
|
|
3
|
-
"version": "0.0.1-canary.
|
|
3
|
+
"version": "0.0.1-canary.eefd1bc",
|
|
4
4
|
"description": "Hono HTTP server for the Vana Personal Server — routes, middleware, composition root",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@hono/node-server": "^1.19.13",
|
|
47
|
-
"@opendatalabs/personal-server-ts-core": "0.0.1-canary.
|
|
48
|
-
"@opendatalabs/personal-server-ts-lite": "0.0.1-canary.
|
|
47
|
+
"@opendatalabs/personal-server-ts-core": "0.0.1-canary.eefd1bc",
|
|
48
|
+
"@opendatalabs/personal-server-ts-lite": "0.0.1-canary.eefd1bc",
|
|
49
49
|
"@opendatalabs/vana-sdk": "3.13.0",
|
|
50
50
|
"better-sqlite3": "^12.11.1",
|
|
51
51
|
"hono": "^4.12.27",
|