@pkcprotocol/pkc-js 0.0.56 → 0.0.57
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/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +10 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/pubsub.js +1 -1
- package/dist/browser/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.d.ts +60 -0
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js +95 -0
- package/dist/browser/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -0
- package/dist/browser/runtime/node/community/local-community.d.ts +2 -0
- package/dist/browser/runtime/node/community/local-community.js +5 -0
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +33 -31
- package/dist/bundled/chunks/{helia-for-pkc-CcmiATPg.js → helia-for-pkc-DxnB3FKD.js} +2 -2
- package/dist/bundled/chunks/{local-community-DdB4oPEw.js → local-community-DoCgfUYZ.js} +85 -3
- package/dist/bundled/chunks/{local-community-DzFaedmf.js → local-community-K4gwxMtl.js} +1 -1
- package/dist/bundled/chunks/{node-DNJqRHLq.js → node-DjTc94sT.js} +10 -533
- package/dist/bundled/chunks/{rpc-local-community-OVRYzYQ3.js → rpc-local-community-Bw7ZxESs.js} +563 -40
- package/dist/bundled/chunks/{schema-lNZ3-tdE.js → schema-DGX0DsS6.js} +1 -1
- package/dist/bundled/chunks/{util-MtD9fpa8.js → util-SCefBhSi.js} +1 -1
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +10 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/pubsub.js +1 -1
- package/dist/node/runtime/node/community/local-community/pubsub.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.d.ts +60 -0
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js +95 -0
- package/dist/node/runtime/node/community/local-community/reprovide-on-address-change.js.map +1 -0
- package/dist/node/runtime/node/community/local-community.d.ts +2 -0
- package/dist/node/runtime/node/community/local-community.js +5 -0
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { $ as pubsubTopicToDhtKey, At as trackStartedCommunity, Bt as CommunityEditPublicationPubsubReservedFields, C as contentContainsMarkdownAudio, Ct as findUpdatingCommunity, Dr as __require, En as CommentUpdateSchema, F as getIpnsRecordInLocalKuboNode, Fn as CommentEditPubsubMessagePublicationSchema, Ft as untrackUpdatingCommunity, G as isLinkOfAudio, Gt as CommentModerationPubsubMessagePublicationSchema, In as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, It as require_sha256, J as isLinkOfVideo, Jt as CommentModerationsTableRowSchema, K as isLinkOfImage, Kt as CommentModerationReservedFields, L as hideClassPrivateProps, Ln as CommentEditReservedFields, M as genToArray, Mt as trackUpdatingCommunity, N as getEquivalentCommunityAddresses, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, On as CommentUpdateTableRowSchema, Or as __toESM, P as getErrorCodeFromMessage, Q as isStringDomain, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, S as calculateStringSizeSameAsIpfsAddCidV0, T as contentContainsMarkdownVideos, Tr as __commonJSMin, Un as AuthorReservedFields, W as isLinkOfAnimatedImage, Xn as require_commonjs, Y as isLinkValid, Zn as require_retry, _t as timestamp, a as ChallengeRequestMessageSchema, at as removeNullUndefinedValues, b as areEquivalentCommunityAddresses, bt as findCommunityInRegistry, cr as logger_default, d as DecryptedChallengeRequestSchema, dt as retryKuboIpfsAddAndProvide, fn as VotePubsubMessagePublicationSchema, hn as VoteTablesRowSchema, ht as statMfsPathSafely, k as doesDomainAddressHaveCapitalLetter, kn as CommentsTableRowSchema, kt as syncCommunityRegistryEntry, lt as retryKuboBlockPutPinAndProvidePubsubTopic, mt as sleepUntilTimeoutOrAbort, nn as CommunityIpfsSchema, nt as removeBlocksFromKuboNode, or as PKCError, pn as VotePubsubReservedFields, q as isLinkOfMedia, r as ChallengeMessageSchema, rn as CommunitySignedPropertyNames, rt as removeMfsFilesSafely, s as ChallengeVerificationMessageSchema, sr as messages, t as ChallengeAnswerMessageSchema, u as DecryptedChallengeRequestPublicationSchema, vn as CommentIpfsSchema, w as contentContainsMarkdownImages, x as calculateIpfsCidV0, xr as ZodError, xt as findStartedCommunity, y as version_default, yn as CommentPubsubMessageReservedFields, yt as writeKuboFilesWithTimeout, zn as CommentEditsTableRowSchema } from "./schema-
|
|
2
|
-
import { A as
|
|
1
|
+
import { $ as pubsubTopicToDhtKey, At as trackStartedCommunity, Bt as CommunityEditPublicationPubsubReservedFields, C as contentContainsMarkdownAudio, Ct as findUpdatingCommunity, Dr as __require, En as CommentUpdateSchema, F as getIpnsRecordInLocalKuboNode, Fn as CommentEditPubsubMessagePublicationSchema, Ft as untrackUpdatingCommunity, G as isLinkOfAudio, Gt as CommentModerationPubsubMessagePublicationSchema, In as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, It as require_sha256, J as isLinkOfVideo, Jt as CommentModerationsTableRowSchema, K as isLinkOfImage, Kt as CommentModerationReservedFields, L as hideClassPrivateProps, Ln as CommentEditReservedFields, M as genToArray, Mt as trackUpdatingCommunity, N as getEquivalentCommunityAddresses, Nt as untrackStartedCommunity, O as derivePublicationFromChallengeRequest, On as CommentUpdateTableRowSchema, Or as __toESM, P as getErrorCodeFromMessage, Q as isStringDomain, R as ipnsNameToIpnsOverPubsubTopic, Rt as pTimeout, S as calculateStringSizeSameAsIpfsAddCidV0, T as contentContainsMarkdownVideos, Tr as __commonJSMin, Un as AuthorReservedFields, W as isLinkOfAnimatedImage, Xn as require_commonjs, Y as isLinkValid, Zn as require_retry, _t as timestamp, a as ChallengeRequestMessageSchema, at as removeNullUndefinedValues, b as areEquivalentCommunityAddresses, bt as findCommunityInRegistry, cr as logger_default, d as DecryptedChallengeRequestSchema, dt as retryKuboIpfsAddAndProvide, fn as VotePubsubMessagePublicationSchema, hn as VoteTablesRowSchema, ht as statMfsPathSafely, k as doesDomainAddressHaveCapitalLetter, kn as CommentsTableRowSchema, kt as syncCommunityRegistryEntry, lt as retryKuboBlockPutPinAndProvidePubsubTopic, mt as sleepUntilTimeoutOrAbort, nn as CommunityIpfsSchema, nt as removeBlocksFromKuboNode, or as PKCError, pn as VotePubsubReservedFields, q as isLinkOfMedia, r as ChallengeMessageSchema, rn as CommunitySignedPropertyNames, rt as removeMfsFilesSafely, s as ChallengeVerificationMessageSchema, sr as messages, t as ChallengeAnswerMessageSchema, u as DecryptedChallengeRequestPublicationSchema, vn as CommentIpfsSchema, w as contentContainsMarkdownImages, x as calculateIpfsCidV0, xr as ZodError, xt as findStartedCommunity, y as version_default, yn as CommentPubsubMessageReservedFields, yt as writeKuboFilesWithTimeout, zn as CommentEditsTableRowSchema } from "./schema-DGX0DsS6.js";
|
|
2
|
+
import { A as deriveDbPosts, At as verifyCommunityEdit, Bt as getCommunityPublicKeyFromWire, C as BackupAbortError, Dt as verifyCommentPubsubMessage, E as calculateInlineRepliesBudget, Et as verifyCommentModeration, F as importSignerIntoKuboNode, Ft as getAuthorNameFromWire, G as REPLY_REPLIES_SORT_TYPES, Gt as getIpfsKeyFromPrivateKey, Ht as decode, Jn as require_lodash_merge, Jt as getPublicKeyFromPrivateKey, K as TIMEFRAMES_TO_SECONDS, Kn as stringify, Kt as getPKCAddressFromPublicKey, M as getDefaultCommunityDbConfig, Mt as buildRuntimeAuthor, Nt as cleanWireAuthor, O as deleteOldCommunityInWindows, Ot as verifyCommentUpdate, P as getThumbnailPropsOfLink, R as moveCommunityDbToDeletedDirectory, S as encryptEd25519AesGcmPublicKeyBuffer, St as verifyChallengeRequest, T as calculateExpectedSignatureSize, Tt as verifyCommentIpfs, U as POSTS_SORT_TYPES, Ut as encode, W as POST_REPLIES_SORT_TYPES, Yt as createSchemaRowParser, Z as iterateOverPageCidsToFindAllCids, _ as SignerWithPublicKeyAddress, _t as signCommunity, a as pkcJsChallenges, b as decryptEd25519AesGcmPublicKeyBuffer, bt as verifyChallengeAnswer, cn as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, d as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, dt as signChallengeVerification, f as KeyvBetterSqlite3, ft as signComment, gt as signCommentUpdateForChallengeVerification, ht as signCommentUpdate, i as getCommunityChallengeFromCommunityChallengeSettings, it as pLimit, j as deriveDbReplies, jt as verifyVote, k as deriveCommentIpfsFromCommentTableRow, kt as verifyCommunity, l as normalizeSelfAddrsForProvider, lt as signChallengeMessage, o as TrackedInstanceRegistry, on as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, pt as signCommentEdit, qn as STORAGE_KEYS, qt as getPKCAddressFromPublicKeySync, r as getChallengeVerification, s as LRUCache, st as cleanUpBeforePublishing, t as RpcLocalCommunity, vn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, w as backupCommunityDb, wt as verifyCommentEdit, xn as parseJsonWithPKCErrorIfFails, z as resolveDbPostsCidRefs, zt as getCommunityNameFromWire } from "./rpc-local-community-Bw7ZxESs.js";
|
|
3
3
|
import { randomFillSync, randomUUID } from "node:crypto";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
import path from "node:path";
|
|
@@ -8,6 +8,7 @@ import { existsSync, promises } from "node:fs";
|
|
|
8
8
|
import path$1 from "path";
|
|
9
9
|
import assert from "assert";
|
|
10
10
|
import fs from "fs";
|
|
11
|
+
import { CID } from "multiformats/cid";
|
|
11
12
|
import Database from "better-sqlite3";
|
|
12
13
|
import { of } from "typestub-ipfs-only-hash";
|
|
13
14
|
//#region dist/node/runtime/node/community/local-community/comment-updates.js
|
|
@@ -5923,7 +5924,7 @@ async function listenToIncomingRequests(community) {
|
|
|
5923
5924
|
}
|
|
5924
5925
|
async function providePubsubTopicRoutingCidsIfNeeded(community, force = false) {
|
|
5925
5926
|
const log = logger_default("pkc-js:local-community:_providePubsubTopicRoutingCidsIfNeeded");
|
|
5926
|
-
const reprovideIntervalMs =
|
|
5927
|
+
const reprovideIntervalMs = 3600 * 1e3;
|
|
5927
5928
|
const now = Date.now();
|
|
5928
5929
|
if (!force && community._lastPubsubTopicRoutingProvideAt && now - community._lastPubsubTopicRoutingProvideAt < reprovideIntervalMs) return;
|
|
5929
5930
|
const topics = [pubsubTopicWithfallback(community), community.ipnsPubsubTopic].filter((topic) => typeof topic === "string");
|
|
@@ -6208,6 +6209,82 @@ async function syncIpnsWithDb(community) {
|
|
|
6208
6209
|
throw e;
|
|
6209
6210
|
}
|
|
6210
6211
|
}
|
|
6212
|
+
function isBrowserDialableAddr(addr) {
|
|
6213
|
+
return addr.includes("/webrtc") || addr.includes("/ws");
|
|
6214
|
+
}
|
|
6215
|
+
async function getBrowserDialableSelfAddrs(client) {
|
|
6216
|
+
const idRes = await client.id();
|
|
6217
|
+
const peerId = idRes.id.toString();
|
|
6218
|
+
const swarmListeningAddresses = (await client.swarm.addrs()).filter((swarmAddr) => swarmAddr.id.toString() === peerId);
|
|
6219
|
+
const normalized = normalizeSelfAddrsForProvider([...idRes.addresses.map((addr) => addr.toString()), ...import_commonjs.flatten(swarmListeningAddresses.map((swarmAddr) => swarmAddr.addrs.map((addr) => addr.toString())))], peerId);
|
|
6220
|
+
return import_commonjs.unique(normalized.filter(isBrowserDialableAddr)).sort();
|
|
6221
|
+
}
|
|
6222
|
+
function connectionCriticalCids(community) {
|
|
6223
|
+
return import_commonjs.unique([community.pubsubTopicRoutingCid, community.ipnsPubsubTopicRoutingCid].filter((cid) => typeof cid === "string"));
|
|
6224
|
+
}
|
|
6225
|
+
/**
|
|
6226
|
+
* Re-provide the connection-critical CIDs when the node's browser-dialable (WSS/WebRTC) self-addresses
|
|
6227
|
+
* have changed since the last provide. This pushes the current addresses to the HTTP routers (via the
|
|
6228
|
+
* address-rewriter proxy) so browsers don't get NoValidAddressesError against stale/dead addresses.
|
|
6229
|
+
*
|
|
6230
|
+
* The first observation only establishes a baseline (start() already force-provides these CIDs with fresh
|
|
6231
|
+
* addresses via providePubsubTopicRoutingCidsIfNeeded); subsequent changes trigger a re-provide.
|
|
6232
|
+
*/
|
|
6233
|
+
async function reprovideConnectionCidsIfBrowserAddrsChanged(community) {
|
|
6234
|
+
const log = logger_default("pkc-js:local-community:_reprovideConnectionCidsIfBrowserAddrsChanged");
|
|
6235
|
+
const client = community._clientsManager.getDefaultKuboRpcClient()._client;
|
|
6236
|
+
const current = await getBrowserDialableSelfAddrs(client);
|
|
6237
|
+
const previous = community._lastProvidedBrowserDialableSelfAddrs;
|
|
6238
|
+
if (previous === void 0) {
|
|
6239
|
+
community._lastProvidedBrowserDialableSelfAddrs = current;
|
|
6240
|
+
return {
|
|
6241
|
+
reprovided: false,
|
|
6242
|
+
providedCids: [],
|
|
6243
|
+
browserAddrs: current
|
|
6244
|
+
};
|
|
6245
|
+
}
|
|
6246
|
+
if (import_commonjs.isDeepEqual(previous, current)) return {
|
|
6247
|
+
reprovided: false,
|
|
6248
|
+
providedCids: [],
|
|
6249
|
+
browserAddrs: current
|
|
6250
|
+
};
|
|
6251
|
+
community._lastProvidedBrowserDialableSelfAddrs = current;
|
|
6252
|
+
const cidStrings = connectionCriticalCids(community);
|
|
6253
|
+
const providedCids = [];
|
|
6254
|
+
for (const cidString of cidStrings) {
|
|
6255
|
+
let cid;
|
|
6256
|
+
try {
|
|
6257
|
+
cid = CID.parse(cidString);
|
|
6258
|
+
} catch (e) {
|
|
6259
|
+
log.error(`Failed to parse connection-critical CID (${cidString}) for community (${community.address})`, e);
|
|
6260
|
+
continue;
|
|
6261
|
+
}
|
|
6262
|
+
try {
|
|
6263
|
+
const provideEvents = client.routing.provide(cid, { recursive: true });
|
|
6264
|
+
for await (const event of provideEvents) log.trace(`Provide event for ${cidString}:`, event);
|
|
6265
|
+
providedCids.push(cidString);
|
|
6266
|
+
} catch (e) {
|
|
6267
|
+
log.error(`Failed to re-provide connection-critical CID (${cidString}) for community (${community.address})`, e);
|
|
6268
|
+
}
|
|
6269
|
+
}
|
|
6270
|
+
log(`Browser-dialable addresses of community (${community.address}) changed; re-provided ${providedCids.length}/${cidStrings.length} connection-critical CIDs`, { browserAddrs: current });
|
|
6271
|
+
return {
|
|
6272
|
+
reprovided: providedCids.length > 0,
|
|
6273
|
+
providedCids,
|
|
6274
|
+
browserAddrs: current
|
|
6275
|
+
};
|
|
6276
|
+
}
|
|
6277
|
+
/**
|
|
6278
|
+
* Publish-loop entry point. The publish loop runs once per sync cycle (and faster during bursts), so this
|
|
6279
|
+
* throttles the kubo id()/swarm.addrs() poll to ADDRESS_REPROVIDE_POLL_INTERVAL_MS before delegating to the
|
|
6280
|
+
* core change-detection. Lives inside the publish loop so it's torn down together with the loop on stop().
|
|
6281
|
+
*/
|
|
6282
|
+
async function reprovideOnAddressChangeIfDue(community) {
|
|
6283
|
+
const now = Date.now();
|
|
6284
|
+
if (typeof community._lastAddressReprovideCheckAt === "number" && now - community._lastAddressReprovideCheckAt < 6e4) return;
|
|
6285
|
+
community._lastAddressReprovideCheckAt = now;
|
|
6286
|
+
await reprovideConnectionCidsIfBrowserAddrsChanged(community);
|
|
6287
|
+
}
|
|
6211
6288
|
//#endregion
|
|
6212
6289
|
//#region dist/node/runtime/node/community/local-community/lifecycle.js
|
|
6213
6290
|
async function publishLoop(community, syncIntervalMs) {
|
|
@@ -6230,6 +6307,7 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
6230
6307
|
};
|
|
6231
6308
|
while (!shouldStopPublishLoop()) try {
|
|
6232
6309
|
await syncIpnsWithDb(community);
|
|
6310
|
+
await reprovideOnAddressChangeIfDue(community).catch((e) => log.error("Failed to re-provide connection CIDs on address change", e));
|
|
6233
6311
|
} catch (e) {
|
|
6234
6312
|
community.emit("error", e);
|
|
6235
6313
|
} finally {
|
|
@@ -6263,6 +6341,8 @@ async function start(community) {
|
|
|
6263
6341
|
if (community.state === "updating") throw new PKCError("ERR_NEED_TO_STOP_UPDATING_COMMUNITY_BEFORE_STARTING", { address: community.address });
|
|
6264
6342
|
community._stopHasBeenCalled = false;
|
|
6265
6343
|
community._firstUpdateAfterStart = true;
|
|
6344
|
+
community._lastProvidedBrowserDialableSelfAddrs = void 0;
|
|
6345
|
+
community._lastAddressReprovideCheckAt = void 0;
|
|
6266
6346
|
if (!community._clientsManager.getDefaultKuboRpcClientOrHelia()) throw Error("You need to define an IPFS client in your pkc instance to be able to start a local community");
|
|
6267
6347
|
await community.initDbHandlerIfNeeded();
|
|
6268
6348
|
await community._updateStartedValue();
|
|
@@ -6938,6 +7018,8 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
6938
7018
|
this._firstUpdateAfterStart = true;
|
|
6939
7019
|
this._internalStateUpdateId = "";
|
|
6940
7020
|
this._lastPubsubTopicRoutingProvideAt = void 0;
|
|
7021
|
+
this._lastProvidedBrowserDialableSelfAddrs = void 0;
|
|
7022
|
+
this._lastAddressReprovideCheckAt = void 0;
|
|
6941
7023
|
this._mirroredStartedOrUpdatingCommunity = void 0;
|
|
6942
7024
|
this._pendingEditProps = [];
|
|
6943
7025
|
this._blocksToRm = [];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-
|
|
1
|
+
import { n as createNewLocalCommunityDb, r as updateInstancePropsWithStartedCommunityOrDb, t as LocalCommunity } from "./local-community-DoCgfUYZ.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|