@pkcprotocol/pkc-js 0.0.92 → 0.0.94
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/README.md +5 -0
- package/dist/browser/clients/base-client-manager.d.ts +1 -0
- package/dist/browser/clients/base-client-manager.js +7 -1
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/clients/rpc-client/pkc-rpc-client.d.ts +16 -0
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js +97 -1
- package/dist/browser/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/browser/community/community-client-manager.d.ts +16 -0
- package/dist/browser/community/community-client-manager.js +307 -31
- package/dist/browser/community/community-client-manager.js.map +1 -1
- package/dist/browser/community/remote-community.js +7 -0
- package/dist/browser/community/remote-community.js.map +1 -1
- package/dist/browser/community/rpc-local-community.js +43 -15
- package/dist/browser/community/rpc-local-community.js.map +1 -1
- package/dist/browser/community/rpc-remote-community.js +30 -10
- package/dist/browser/community/rpc-remote-community.js.map +1 -1
- package/dist/browser/errors.d.ts +1 -0
- package/dist/browser/errors.js +1 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/helia/helia-for-pkc.js +56 -1
- package/dist/browser/helia/helia-for-pkc.js.map +1 -1
- package/dist/browser/helia/types.d.ts +16 -0
- package/dist/browser/helia/util.d.ts +1 -0
- package/dist/browser/helia/util.js +21 -1
- package/dist/browser/helia/util.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment.js +30 -11
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/publication.js +46 -17
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/rpc/src/index.d.ts +2 -0
- package/dist/browser/rpc/src/index.js +52 -19
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/rpc/src/schema.js +3 -1
- package/dist/browser/rpc/src/schema.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +353 -5
- package/dist/browser/test/test-util.js +88 -5
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/browser/util.d.ts +7 -0
- package/dist/browser/util.js +22 -12
- package/dist/browser/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +25 -25
- package/dist/bundled/chunks/{helia-for-pkc-COFAbh3C.js → helia-for-pkc-Bj-Zb4JN.js} +70 -33
- package/dist/bundled/chunks/{local-community-CyA7I22X.js → local-community-BrMLMEmt.js} +1 -1
- package/dist/bundled/chunks/{local-community-DLeQ8V3i.js → local-community-Ce7303vY.js} +30 -30
- package/dist/bundled/chunks/{node-i4Twbtvv.js → node-C37nDOa8.js} +98 -21
- package/dist/bundled/chunks/{rpc-local-community-CZSOMq_6.js → rpc-local-community-Dr_-Lb8I.js} +188 -32
- package/dist/bundled/chunks/{schema-Bbq796q3.js → schema-5-rYJ-bC.js} +30 -12
- package/dist/bundled/chunks/{util-DdrJVp4E.js → util-_-fNQNIV.js} +11 -3
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/rpc/src/index.js +43 -22
- package/dist/node/clients/base-client-manager.d.ts +1 -0
- package/dist/node/clients/base-client-manager.js +7 -1
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/clients/rpc-client/pkc-rpc-client.d.ts +16 -0
- package/dist/node/clients/rpc-client/pkc-rpc-client.js +97 -1
- package/dist/node/clients/rpc-client/pkc-rpc-client.js.map +1 -1
- package/dist/node/community/community-client-manager.d.ts +16 -0
- package/dist/node/community/community-client-manager.js +307 -31
- package/dist/node/community/community-client-manager.js.map +1 -1
- package/dist/node/community/remote-community.js +7 -0
- package/dist/node/community/remote-community.js.map +1 -1
- package/dist/node/community/rpc-local-community.js +43 -15
- package/dist/node/community/rpc-local-community.js.map +1 -1
- package/dist/node/community/rpc-remote-community.js +30 -10
- package/dist/node/community/rpc-remote-community.js.map +1 -1
- package/dist/node/errors.d.ts +1 -0
- package/dist/node/errors.js +1 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/helia/helia-for-pkc.js +56 -1
- package/dist/node/helia/helia-for-pkc.js.map +1 -1
- package/dist/node/helia/types.d.ts +16 -0
- package/dist/node/helia/util.d.ts +1 -0
- package/dist/node/helia/util.js +21 -1
- package/dist/node/helia/util.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment.js +30 -11
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/publication.js +46 -17
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/rpc/src/index.d.ts +2 -0
- package/dist/node/rpc/src/index.js +52 -19
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/rpc/src/schema.js +3 -1
- package/dist/node/rpc/src/schema.js.map +1 -1
- package/dist/node/test/test-util.d.ts +353 -5
- package/dist/node/test/test-util.js +88 -5
- package/dist/node/test/test-util.js.map +1 -1
- package/dist/node/util.d.ts +7 -0
- package/dist/node/util.js +22 -12
- package/dist/node/util.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import {
|
|
3
|
-
import { $ as RepliesPages, $n as RpcUnsubscribeParamSchema, An as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, At as verifyCommentIpfs, B as setNativeFunctions$1, Bn as RpcEditCommunityParamSchema, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Ct as signCommunityEdit, D as createKuboRpcClient, Dn as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, En as parseJsonWithPKCErrorIfFails, Et as verifyChallengeMessage, Fn as RpcCancelExportParamSchema, Ft as verifyCommunityEdit, Gn as RpcFetchCidParamSchema, Gt as getCommunityPublicKeyFromWire, H as CommentClientsManager, Hn as RpcExportCommunityModLogsResultSchema, Ht as buildRuntimeCommunityFields, I as listCommunitiesSync, In as RpcCidParamSchema, It as verifyVote, Jn as RpcPublishChallengeAnswersParamSchema, Kn as RpcFetchCidResultSchema, Kt as normalizeCommunityInputFromCommunity, L as monitorCommunitiesDirectory, Ln as RpcCommentRepliesPageParamSchema, Lt as buildRuntimeAuthor, Mn as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Mt as verifyCommentPubsubMessage, N as getDefaultDataPath, Nn as RpcAnchorPublishPreparationResultSchema, Nt as verifyCommentUpdate, On as parseRpcCommentEventWithPKCErrorIfItFails, Ot as verifyChallengeVerification, Pn as RpcAuthorNameParamSchema, Q as parseRawPages, Qn as RpcSuccessResultSchema, Qt as getPKCAddressFromPublicKeySync, Rn as RpcCommunityIdentifierParamSchema, Rt as cleanWireAuthor, Sn as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, Tn as parseDecryptedChallengeWithPKCErrorIfItFails, Un as RpcExportCommunityParamSchema, Ut as getCommunityAddressFromRecord, V as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Vn as RpcExportCommunityModLogsParamSchema, Vt as normalizeCreatePublicationAuthor, Wn as RpcExportCommunityResultSchema, Wt as getCommunityNameFromWire, X as findCommentInPageInstanceRecursively, Xn as RpcResolveAuthorNameResultSchema, Y as extractCommunityRuntimeFieldsFromParsedPages, Yn as RpcPublishedAnchorRecordResultSchema, Yt as getBufferedPKCAddressFromPublicKey, Zn as RpcSubscriptionIdResultSchema, _ as createSigner, _n as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, _t as signComment, an as parseCommentIpfsSchemaWithPKCErrorIfItFails, ar as t$3, at as PublicationClientsManager, bn as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, c as LRUCache, cn as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, cr as t$2, d as KeyvBetterSqlite3, dt as require_lib$1, et as applyNameResolvedCacheToCrosspost, f as decodeRpcChallengeAnswerPubsubMsg, fn as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, ft as cleanUpBeforePublishing, gn as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, h as decodeRpcChallengeVerificationPubsubMsg, hn as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, ht as signChallengeRequest, in as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, it as stripNameResolvedFromCrosspost, jt as verifyCommentModeration, kn as parseRpcCommentUpdateEventWithPKCErrorIfItFails, kt as verifyCommentEdit, l as RemoteCommunity, ln as parseCommunityAddressWithPKCErrorIfItFails, lr as t$5, m as decodeRpcChallengeRequestPubsubMsg, mn as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, mr as require_undici, n as RpcRemoteCommunity, nr as t$4, nt as collectCrosspostAuthorsToResolve, o as pkcJsChallenges, or as n$3, ot as PKCClientsManager, p as decodeRpcChallengePubsubMsg, pr as nativeFunctions$2, pt as signChallengeAnswer, qn as RpcPublishAnchorRecordParamSchema, qt as decode, s as TrackedInstanceRegistry, sn as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as InflightFetchManager, t as RpcLocalCommunity, tn as parseCidStringSchemaWithPKCErrorIfItFails, tt as cloneCrosspostForRuntime, ut as PKCTypedEmitter, v as createAnchorIpnsRecord$1, vt as signCommentEdit, wn as parseDecryptedChallengeVerification, wt as signVote, x as encryptEd25519AesGcm, xn as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as decryptEd25519AesGcm, yt as signCommentModeration, zn as RpcCommunityPageParamSchema, zt as getAuthorNameFromRuntime } from "./rpc-local-community-
|
|
4
|
-
import { o as getHeliaDebugContext } from "./util-
|
|
2
|
+
import { A as doesDomainAddressHaveCapitalLetter, At as listUpdatingCommunities, B as ipnsNameToIpnsOverPubsubTopic, Br as stringifyPrimitive, Bt as require_sha256, Cn as CommentIpfsSchema, Cr as messages, D as createAbortError, Dr as setErrorMap, Dt as findUpdatingCommunity, Et as findUpdatingComment, Ft as trackUpdatingComment, H as isIpfsCid, Ht as pTimeout, O as deepMergeRuntimeFields, On as CommentUpdateForChallengeVerificationSchema, Ot as listStartedCommunities, R as hideClassPrivateProps, Rr as joinValues, Rt as untrackUpdatingComment, Sr as PKCError, St as waitForUpdateInCommunityInstanceWithErrorAndTimeout, Tt as findStartedCommunity, V as isAbortError, Vt as TimeoutError, W as isIpns, _r as FailedToFetchCommentIpfsFromGatewaysError, _t as shortifyCid, a as ChallengeRequestMessageSchema, ar as t$1, at as rejectWhenCommunityStopsOrAborts, b as areEquivalentCommunityAddresses, bt as throwIfAbortSignalAborted, dt as replaceXWithY, et as isStringDomain, ft as resolveWhenPredicateIsTrue, gr as require_retry, gt as shortifyAddress, it as rejectWhenAbortSignalFires, jn as CommentUpdateSchema, jt as refreshTrackedCommentAliases, kt as listUpdatingComments, lr as r, mt as retryKuboIpfsAdd, nn as CommunityAnchorSchema, or as e, pn as PubsubTopicSchema, r as ChallengeMessageSchema, rr as n$1, s as ChallengeVerificationMessageSchema, sn as CommunityIpfsSchema, sr as e$1, t as ChallengeAnswerMessageSchema, tr as n$2, ut as removeUndefinedValuesRecursively, vt as sleepUntilTimeoutOrAbort, wr as logger_default, xt as timestamp, y as version_default, zr as parsedType } from "./schema-5-rYJ-bC.js";
|
|
3
|
+
import { $ as RepliesPages, $n as RpcUnsubscribeParamSchema, An as parseSetNewSettingsPKCWsServerSchemaWithPKCErrorIfItFails, At as verifyCommentIpfs, B as setNativeFunctions$1, Bn as RpcEditCommunityParamSchema, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Ct as signCommunityEdit, D as createKuboRpcClient, Dn as parsePKCUserOptionsSchemaWithPKCErrorIfItFails, En as parseJsonWithPKCErrorIfFails, Et as verifyChallengeMessage, Fn as RpcCancelExportParamSchema, Ft as verifyCommunityEdit, Gn as RpcFetchCidParamSchema, Gt as getCommunityPublicKeyFromWire, H as CommentClientsManager, Hn as RpcExportCommunityModLogsResultSchema, Ht as buildRuntimeCommunityFields, I as listCommunitiesSync, In as RpcCidParamSchema, It as verifyVote, Jn as RpcPublishChallengeAnswersParamSchema, Kn as RpcFetchCidResultSchema, Kt as normalizeCommunityInputFromCommunity, L as monitorCommunitiesDirectory, Ln as RpcCommentRepliesPageParamSchema, Lt as buildRuntimeAuthor, Mn as parseVotePubsubMessagePublicationSchemaWithPKCErrorIfItFails, Mt as verifyCommentPubsubMessage, N as getDefaultDataPath, Nn as RpcAnchorPublishPreparationResultSchema, Nt as verifyCommentUpdate, On as parseRpcCommentEventWithPKCErrorIfItFails, Ot as verifyChallengeVerification, Pn as RpcAuthorNameParamSchema, Q as parseRawPages, Qn as RpcSuccessResultSchema, Qt as getPKCAddressFromPublicKeySync, Rn as RpcCommunityIdentifierParamSchema, Rt as cleanWireAuthor, Sn as parseCreateVoteOptionsSchemaWithPKCErrorIfItFails, Tn as parseDecryptedChallengeWithPKCErrorIfItFails, Un as RpcExportCommunityParamSchema, Ut as getCommunityAddressFromRecord, V as tryToDeleteCommunitiesThatFailedToBeDeletedBefore, Vn as RpcExportCommunityModLogsParamSchema, Vt as normalizeCreatePublicationAuthor, Wn as RpcExportCommunityResultSchema, Wt as getCommunityNameFromWire, X as findCommentInPageInstanceRecursively, Xn as RpcResolveAuthorNameResultSchema, Y as extractCommunityRuntimeFieldsFromParsedPages, Yn as RpcPublishedAnchorRecordResultSchema, Yt as getBufferedPKCAddressFromPublicKey, Zn as RpcSubscriptionIdResultSchema, _ as createSigner, _n as parseCreateCommunityEditPublicationOptionsSchemaWithPKCErrorIfItFails, _t as signComment, an as parseCommentIpfsSchemaWithPKCErrorIfItFails, ar as t$3, at as PublicationClientsManager, bn as parseCreateRemoteCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, c as LRUCache, cn as parseCommentPubsubMessagePublicationWithPKCErrorIfItFails, cr as t$2, d as KeyvBetterSqlite3, dt as require_lib$1, et as applyNameResolvedCacheToCrosspost, f as decodeRpcChallengeAnswerPubsubMsg, fn as parseCommunityEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, ft as cleanUpBeforePublishing, gn as parseCreateCommentOptionsSchemaWithPKCErrorIfItFails, h as decodeRpcChallengeVerificationPubsubMsg, hn as parseCreateCommentModerationOptionsSchemaWithPKCErrorIfItFails, ht as signChallengeRequest, in as parseCommentEditPubsubMessagePublicationSchemaWithPKCErrorIfItFails, it as stripNameResolvedFromCrosspost, jt as verifyCommentModeration, kn as parseRpcCommentUpdateEventWithPKCErrorIfItFails, kt as verifyCommentEdit, l as RemoteCommunity, ln as parseCommunityAddressWithPKCErrorIfItFails, lr as t$5, m as decodeRpcChallengeRequestPubsubMsg, mn as parseCreateCommentEditOptionsSchemaWithPKCErrorIfItFails, mr as require_undici, n as RpcRemoteCommunity, nr as t$4, nt as collectCrosspostAuthorsToResolve, o as pkcJsChallenges, or as n$3, ot as PKCClientsManager, p as decodeRpcChallengePubsubMsg, pr as nativeFunctions$2, pt as signChallengeAnswer, qn as RpcPublishAnchorRecordParamSchema, qt as decode, s as TrackedInstanceRegistry, sn as parseCommentModerationPubsubMessagePublicationSchemaWithPKCErrorIfItFails, st as InflightFetchManager, t as RpcLocalCommunity, tn as parseCidStringSchemaWithPKCErrorIfItFails, tt as cloneCrosspostForRuntime, ut as PKCTypedEmitter, v as createAnchorIpnsRecord$1, vt as signCommentEdit, wn as parseDecryptedChallengeVerification, wt as signVote, x as encryptEd25519AesGcm, xn as parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails, y as decryptEd25519AesGcm, yt as signCommentModeration, zn as RpcCommunityPageParamSchema, zt as getAuthorNameFromRuntime } from "./rpc-local-community-Dr_-Lb8I.js";
|
|
4
|
+
import { o as getHeliaDebugContext } from "./util-_-fNQNIV.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -276,12 +276,13 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
276
276
|
}
|
|
277
277
|
});
|
|
278
278
|
if (this._rpcPublishSubscriptionId) {
|
|
279
|
+
const subscriptionId = this._rpcPublishSubscriptionId;
|
|
280
|
+
this._rpcPublishSubscriptionId = void 0;
|
|
279
281
|
try {
|
|
280
|
-
await this._pkc._pkcRpcClient.unsubscribe(
|
|
282
|
+
await this._pkc._pkcRpcClient.unsubscribe(subscriptionId);
|
|
281
283
|
} catch (e) {
|
|
282
284
|
log.error("Failed to unsubscribe from publication publish", e);
|
|
283
285
|
}
|
|
284
|
-
this._rpcPublishSubscriptionId = void 0;
|
|
285
286
|
}
|
|
286
287
|
}
|
|
287
288
|
async _handleIncomingChallengePubsubMessage(msg) {
|
|
@@ -486,10 +487,13 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
486
487
|
async publishChallengeAnswers({ challengeAnswers }) {
|
|
487
488
|
const log = logger_default("pkc-js:publication:publishChallengeAnswers");
|
|
488
489
|
const toEncryptAnswers = parseDecryptedChallengeAnswerWithPKCErrorIfItFails({ challengeAnswers });
|
|
489
|
-
if (this._pkc._pkcRpcClient
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
490
|
+
if (this._pkc._pkcRpcClient) {
|
|
491
|
+
if (typeof this._rpcPublishSubscriptionId !== "number") throw new PKCError("ERR_RPC_CLIENT_NO_ACTIVE_PUBLISH_SUBSCRIPTION", { publishingState: this.publishingState });
|
|
492
|
+
return this._pkc._pkcRpcClient.publishChallengeAnswers({
|
|
493
|
+
subscriptionId: this._rpcPublishSubscriptionId,
|
|
494
|
+
challengeAnswers: toEncryptAnswers.challengeAnswers
|
|
495
|
+
});
|
|
496
|
+
}
|
|
493
497
|
const challengeExchangesWithChallenge = Object.values(this._challengeExchanges).filter((exchange) => exchange.challenge);
|
|
494
498
|
if (challengeExchangesWithChallenge.length === 0) throw Error("No challenge exchanges with challenge");
|
|
495
499
|
if (challengeExchangesWithChallenge.length > 1) throw Error("We should only have one challenge exchange with challenge");
|
|
@@ -704,14 +708,15 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
704
708
|
this._unregisterFromPkcOncePublishWorkSettles();
|
|
705
709
|
this._setStateWithEmission("stopped");
|
|
706
710
|
if (this._rpcPublishSubscriptionId) {
|
|
711
|
+
const subscriptionId = this._rpcPublishSubscriptionId;
|
|
712
|
+
this._rpcPublishSubscriptionId = void 0;
|
|
707
713
|
try {
|
|
708
|
-
await this._pkc._pkcRpcClient.unsubscribe(
|
|
714
|
+
await this._pkc._pkcRpcClient.unsubscribe(subscriptionId);
|
|
709
715
|
} catch (e) {
|
|
710
716
|
log.error("Failed to unsubscribe from publication publish", e);
|
|
711
717
|
}
|
|
712
|
-
this._rpcPublishSubscriptionId = void 0;
|
|
713
718
|
this._setRpcClientState("stopped");
|
|
714
|
-
} else if (typeof this._community?.pubsubTopic === "string") {
|
|
719
|
+
} else if (!this._pkc._pkcRpcClient && typeof this._community?.pubsubTopic === "string") {
|
|
715
720
|
await this._clientsManager.pubsubUnsubscribe(this._community.pubsubTopic, this._handleChallengeExchange);
|
|
716
721
|
Object.values(this._challengeExchanges).forEach((exchange) => this._updatePubsubState("stopped", exchange.providerUrl));
|
|
717
722
|
}
|
|
@@ -787,8 +792,17 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
787
792
|
communityEdit: rpcClient.publishCommunityEdit
|
|
788
793
|
}[this.getType()].bind(rpcClient)(this.toJSONPubsubRequestToEncrypt());
|
|
789
794
|
this._rpcPublishSubscriptionId = subscriptionId;
|
|
790
|
-
|
|
791
|
-
|
|
795
|
+
rpcClient.attachSubscriptionHandlersDeferred({
|
|
796
|
+
subscriptionId,
|
|
797
|
+
isStale: () => this._rpcPublishSubscriptionId !== subscriptionId,
|
|
798
|
+
attach: (subscription) => subscription.on("challengerequest", this._handleIncomingChallengeRequestFromRpc.bind(this)).on("challenge", this._handleIncomingChallengeFromRpc.bind(this)).on("challengeanswer", this._handleIncomingChallengeAnswerFromRpc.bind(this)).on("challengeverification", this._handleIncomingChallengeVerificationFromRpc.bind(this)).on("publishingstatechange", this._handleIncomingPublishingStateFromRpc.bind(this)).on("statechange", this._handleIncomingStateFromRpc.bind(this)).on("error", this._handleIncomingErrorFromRpc.bind(this)),
|
|
799
|
+
replayErrorContainment: {
|
|
800
|
+
entityName: "publication",
|
|
801
|
+
log: logger_default("pkc-js:publication:publish:_publishWithRpc"),
|
|
802
|
+
emitError: (error) => this.emit("error", error),
|
|
803
|
+
stop: () => this.stop()
|
|
804
|
+
}
|
|
805
|
+
});
|
|
792
806
|
}
|
|
793
807
|
_changePublicationStateEmitEventEmitStateChangeEvent(opts) {
|
|
794
808
|
const shouldEmitStateChange = opts.newState && opts.newState !== this.state;
|
|
@@ -1764,8 +1778,18 @@ var Comment = class extends Publication {
|
|
|
1764
1778
|
throw e;
|
|
1765
1779
|
}
|
|
1766
1780
|
this._setStateWithEmission("updating");
|
|
1767
|
-
|
|
1768
|
-
this._pkc._pkcRpcClient.
|
|
1781
|
+
const subscriptionId = this._updateRpcSubscriptionId;
|
|
1782
|
+
this._pkc._pkcRpcClient.attachSubscriptionHandlersDeferred({
|
|
1783
|
+
subscriptionId,
|
|
1784
|
+
isStale: () => this._updateRpcSubscriptionId !== subscriptionId,
|
|
1785
|
+
attach: (subscription) => subscription.on("update", this._handleUpdateEventFromRpc.bind(this)).on("comment", this._handleCommentEventFromRpc.bind(this)).on("runtimeupdate", this._handleRuntimeUpdateEventFromRpc.bind(this)).on("updatingstatechange", this._handleUpdatingStateChangeFromRpc.bind(this)).on("statechange", this._handleStateChangeFromRpc.bind(this)).on("error", this._handleErrorEventFromRpc.bind(this)),
|
|
1786
|
+
replayErrorContainment: {
|
|
1787
|
+
entityName: "comment",
|
|
1788
|
+
log,
|
|
1789
|
+
emitError: (error) => this.emit("error", error),
|
|
1790
|
+
stop: () => this.stop()
|
|
1791
|
+
}
|
|
1792
|
+
});
|
|
1769
1793
|
}
|
|
1770
1794
|
_useUpdatePropsFromUpdatingStartedCommunityIfPossible() {
|
|
1771
1795
|
if (!this.cid) throw Error("Need to have comment.cid defined");
|
|
@@ -1912,12 +1936,13 @@ var Comment = class extends Publication {
|
|
|
1912
1936
|
if (!this.cid) return;
|
|
1913
1937
|
this._commentIpfsloadingOperation?.stop();
|
|
1914
1938
|
if (this._updateRpcSubscriptionId) {
|
|
1939
|
+
const subscriptionId = this._updateRpcSubscriptionId;
|
|
1940
|
+
this._updateRpcSubscriptionId = void 0;
|
|
1915
1941
|
try {
|
|
1916
|
-
await this._pkc._pkcRpcClient.unsubscribe(
|
|
1942
|
+
await this._pkc._pkcRpcClient.unsubscribe(subscriptionId);
|
|
1917
1943
|
} catch (e) {
|
|
1918
1944
|
log.error("Failed to unsubscribe from commentUpdate", e);
|
|
1919
1945
|
}
|
|
1920
|
-
this._updateRpcSubscriptionId = void 0;
|
|
1921
1946
|
this._setRpcClientState("stopped");
|
|
1922
1947
|
untrackUpdatingComment(this._pkc, this);
|
|
1923
1948
|
}
|
|
@@ -2196,6 +2221,9 @@ const parseRpcExportCommunityModLogsResult = (result) => RpcExportCommunityModLo
|
|
|
2196
2221
|
//#endregion
|
|
2197
2222
|
//#region dist/node/clients/rpc-client/pkc-rpc-client.js
|
|
2198
2223
|
const log = logger_default("pkc-js:PKCRpcClient");
|
|
2224
|
+
const WEBSOCKET_READY_STATE_CLOSED = 3;
|
|
2225
|
+
const DESTROY_SOCKET_CLOSE_TIMEOUT_MS = 5e3;
|
|
2226
|
+
const scheduleMacrotask = setTimeout.bind(globalThis);
|
|
2199
2227
|
var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
2200
2228
|
constructor(rpcServerUrl) {
|
|
2201
2229
|
super();
|
|
@@ -2267,7 +2295,7 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
2267
2295
|
this.emit("error", error);
|
|
2268
2296
|
});
|
|
2269
2297
|
this._webSocketClient.on("close", () => {
|
|
2270
|
-
log.error("connection with web socket has been closed", this._websocketServerUrl);
|
|
2298
|
+
if (!this._destroyRequested) log.error("connection with web socket has been closed", this._websocketServerUrl);
|
|
2271
2299
|
this._openConnectionPromise = void 0;
|
|
2272
2300
|
this.setState("stopped");
|
|
2273
2301
|
});
|
|
@@ -2337,7 +2365,10 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
2337
2365
|
try {
|
|
2338
2366
|
if (this._webSocketClient instanceof Client) {
|
|
2339
2367
|
this._webSocketClient.setAutoReconnect(false);
|
|
2368
|
+
const socketClosed = this._waitForSocketClose();
|
|
2340
2369
|
this._webSocketClient.close();
|
|
2370
|
+
await socketClosed;
|
|
2371
|
+
log("Closed websocket connection to", this._websocketServerUrl);
|
|
2341
2372
|
}
|
|
2342
2373
|
} catch (e) {
|
|
2343
2374
|
log.error("Failed to close websocket", e);
|
|
@@ -2345,6 +2376,16 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
2345
2376
|
this._openConnectionPromise = void 0;
|
|
2346
2377
|
this.setState("stopped");
|
|
2347
2378
|
}
|
|
2379
|
+
async _waitForSocketClose() {
|
|
2380
|
+
const socket = this._webSocketClient.socket;
|
|
2381
|
+
if (!socket || socket.readyState === WEBSOCKET_READY_STATE_CLOSED) return;
|
|
2382
|
+
const closed = new Promise((resolve) => socket.addEventListener("close", () => resolve(), { once: true }));
|
|
2383
|
+
try {
|
|
2384
|
+
await pTimeout(closed, { milliseconds: DESTROY_SOCKET_CLOSE_TIMEOUT_MS });
|
|
2385
|
+
} catch {
|
|
2386
|
+
log.error("Websocket did not close within", DESTROY_SOCKET_CLOSE_TIMEOUT_MS, "ms of destroy()", this._websocketServerUrl);
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2348
2389
|
toJSON() {}
|
|
2349
2390
|
getSubscription(subscriptionId) {
|
|
2350
2391
|
if (!this._subscriptionEvents[subscriptionId]) throw Error(`No subscription to RPC with id (${subscriptionId})`);
|
|
@@ -2400,7 +2441,43 @@ var PKCRpcClient = class extends import_lib.TypedEmitter {
|
|
|
2400
2441
|
_assignAdditionalProps(target, rest) {
|
|
2401
2442
|
if (rest && Object.keys(rest).length > 0) Object.assign(target, rest);
|
|
2402
2443
|
}
|
|
2444
|
+
subscriptionActive(subscriptionId) {
|
|
2445
|
+
return Boolean(this._subscriptionEvents[subscriptionId]);
|
|
2446
|
+
}
|
|
2447
|
+
attachSubscriptionHandlersDeferred(opts) {
|
|
2448
|
+
scheduleMacrotask(() => {
|
|
2449
|
+
const ownsSubscription = () => !opts.isStale() && this.subscriptionActive(opts.subscriptionId);
|
|
2450
|
+
if (!ownsSubscription()) return;
|
|
2451
|
+
try {
|
|
2452
|
+
opts.attach(this.getSubscription(opts.subscriptionId));
|
|
2453
|
+
this._emitPendingMessagesWhile(opts.subscriptionId, ownsSubscription);
|
|
2454
|
+
} catch (e) {
|
|
2455
|
+
this._containReplayError(e, opts.replayErrorContainment);
|
|
2456
|
+
}
|
|
2457
|
+
}, 0);
|
|
2458
|
+
}
|
|
2459
|
+
_containReplayError(e, containment) {
|
|
2460
|
+
const { entityName, log: siteLog, emitError, stop } = containment;
|
|
2461
|
+
siteLog.error(`Error thrown while replaying buffered subscribe-time notifications, stopping the ${entityName}`, e);
|
|
2462
|
+
try {
|
|
2463
|
+
emitError(e instanceof Error ? e : new Error(String(e)));
|
|
2464
|
+
} catch (emitFailure) {
|
|
2465
|
+
siteLog.error("No listener received the replay error", emitFailure);
|
|
2466
|
+
}
|
|
2467
|
+
stop().catch((stopError) => siteLog.error(`Failed to stop the ${entityName} after a replay error`, stopError));
|
|
2468
|
+
}
|
|
2469
|
+
_emitPendingMessagesWhile(subscriptionId, shouldDeliver) {
|
|
2470
|
+
const pendingMessages = this._pendingSubscriptionMsgs[subscriptionId];
|
|
2471
|
+
if (!pendingMessages) return;
|
|
2472
|
+
while (pendingMessages.length > 0) {
|
|
2473
|
+
if (!shouldDeliver()) return;
|
|
2474
|
+
const message = pendingMessages.shift();
|
|
2475
|
+
this._subscriptionEvents[subscriptionId].emit(message?.params?.event, message);
|
|
2476
|
+
}
|
|
2477
|
+
delete this._pendingSubscriptionMsgs[subscriptionId];
|
|
2478
|
+
}
|
|
2403
2479
|
emitAllPendingMessages(subscriptionId) {
|
|
2480
|
+
if (!this._pendingSubscriptionMsgs[subscriptionId]) return;
|
|
2404
2481
|
this._pendingSubscriptionMsgs[subscriptionId].forEach((message) => this._subscriptionEvents[subscriptionId].emit(message?.params?.event, message));
|
|
2405
2482
|
delete this._pendingSubscriptionMsgs[subscriptionId];
|
|
2406
2483
|
}
|
|
@@ -6948,7 +7025,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
6948
7025
|
this.clients.libp2pJsClients = {};
|
|
6949
7026
|
if (!this.libp2pJsClientsOptions) return;
|
|
6950
7027
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
6951
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
7028
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-Bj-Zb4JN.js");
|
|
6952
7029
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
6953
7030
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
6954
7031
|
...clientOptions,
|
|
@@ -7227,7 +7304,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7227
7304
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
7228
7305
|
log.trace("Received community options to create a local community instance:", options);
|
|
7229
7306
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
7230
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
7307
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-BrMLMEmt.js");
|
|
7231
7308
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
7232
7309
|
const community = new LocalCommunity(this);
|
|
7233
7310
|
if (isLocalCommunity) {
|
package/dist/bundled/chunks/{rpc-local-community-CZSOMq_6.js → rpc-local-community-Dr_-Lb8I.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as __toESM, n as __exportAll, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as isRequestPubsubPublicationOfReply, $n as CommunityAuthorChallengeReservedFieldNames, $t as CreateCommentModerationOptionsWithRefinementSchema, A as doesDomainAddressHaveCapitalLetter, An as CommentUpdateReservedFields, Ar as boolean, At as listUpdatingCommunities, B as ipnsNameToIpnsOverPubsubTopic, Bt as require_sha256$1, Cn as CommentIpfsSchema, Cr as messages, D as createAbortError, Dn as CommentUpdateChallengeReservedFieldNames, Dt as findUpdatingCommunity, En as CommentSignedPropertyNames, Er as require_ms$1, Et as findUpdatingComment, Fn as CreateCommentOptionsWithRefinementSchema, Fr as record, G as isIpnsPath, Gn as CreateCommentEditOptionsWithRefinementSchema, Gt as CommunityEditPublicationSignedPropertyNames, H as isIpfsCid, Ht as pTimeout, In as GetPageParamSchema, Ir as string, It as trackUpdatingCommunity, Jt as CommentModerationChallengeRequestToEncryptSchema, Kn as AuthorAddressSchema, Kt as CommunityEditPubsubMessagePublicationSchema, L as getPostUpdateTimestampRange, Ln as ModQueuePageIpfsSchema, Lt as untrackStartedCommunity, M as fetchAndValidateIpnsRecordFromGateway, Mn as CommentUpdateSignedPropertyNames, Mr as literal, Mt as refreshTrackedCommunityAliases, Nr as number, O as deepMergeRuntimeFields, Or as _enum, Ot as listStartedCommunities, Pr as object, Pt as trackStartedCommunity, Q as isRequestPubsubPublicationOfPost, Qn as CommunityAddressSchema, Qt as CommentModerationsTableRowSchema, R as hideClassPrivateProps, Rn as PageIpfsSchema, Rt as untrackUpdatingComment, S as calculateIpfsCidV0, Sn as CommentIpfsReservedFields, Sr as PKCError, St as waitForUpdateInCommunityInstanceWithErrorAndTimeout, Tn as CommentPubsubMessageWithFlexibleAuthorRefinementSchema, Tr as require_supports_color, Tt as findStartedCommunity, U as isIpfsPath, Un as CommentEditSignedPropertyNames, Ut as CommunityEditPublicationChallengeRequestToEncryptSchema, V as isAbortError, Vn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, W as isIpns, Xn as CidPathSchema, Yn as ChallengeAnswersSchema, Yt as CommentModerationPubsubMessagePublicationSchema, Zn as CidStringSchema, Zt as CommentModerationSignedPropertyNames, _ as PKCUserOptionBaseSchema, _n as VotePubsubMessagePublicationSchema, _r as FailedToFetchCommentIpfsFromGatewaysError, _t as shortifyCid, an as CommunityExportRecordsSchema, ar as t$13, b as areEquivalentCommunityAddresses, br as FailedToFetchGenericIpfsFromGatewaysError, bt as throwIfAbortSignalAborted, c as ChallengeVerificationMessageSignedPropertyNames, cn as CommunitySignedPropertyNames, cr as t$11, ct as removeNullUndefinedEmptyObjectsValuesRecursively, dn as CreateRpcCommunityFunctionArgumentSchema, dr as n$8, en as ChallengeFileFactorySchema, er as CreateSignerSchema, et as isStringDomain, f as DecryptedChallengeSchema, fn as ExportCommunityModLogsOptionsSchema, fr as r$7, ft as resolveWhenPredicateIsTrue, g as PKCParsedOptionsSchema, gn as VoteChallengeRequestToEncryptSchema, gr as require_retry$1, gt as shortifyAddress, h as NameResolverSerializedSchema, hn as CreateVoteUserOptionsWithRefinementSchema, hr as e$4, i as ChallengeMessageSignedPropertyNames, in as CommunityEditOptionsSchema, j as extractNetworkErrorDetails, jn as CommentUpdateSchema, jr as custom, k as derivePublicationFromChallengeRequest, kn as CommentUpdateForChallengeVerificationSignedPropertyNames, kr as array, l as DecryptedChallengeAnswerSchema, ln as CreateNewLocalCommunityUserOptionsSchema, lr as r$8, m as NameResolveCacheOptionsSchema, mn as RpcRemoteCommunityUpdateEventResultSchema, mr as t$9, n as ChallengeAnswerMessageSignedPropertyNames, o as ChallengeRequestMessageSignedPropertyNames, on as CommunityIpfsReservedFields, or as e$6, p as DecryptedChallengeVerificationSchema, pr as t$10, qn as AuthorCommentIpfsReservedFields, qt as CreateCommunityEditPublicationOptionsWithRefinementSchema, rn as CommunityChallengeSettingSchema, rr as n$9, rt as raceAgainstAbort, sn as CommunityIpfsSchema, sr as e$5, tn as ChallengeFileSchema, tr as n$10, tt as pubsubTopicToDhtKey, un as CreateRemoteCommunityFunctionArgumentSchema, ur as t$12, v as PKCUserOptionsSchema, vr as FailedToFetchCommentUpdateFromGatewaysError, vt as sleepUntilTimeoutOrAbort, wr as logger_default, xn as CommentChallengeRequestToEncryptSchema, xr as FailedToFetchPageIpfsFromGatewaysError, xt as timestamp, yn as VoteSignedPropertyNames, yr as FailedToFetchCommunityFromGatewaysError, z as interruptibleSleep, zn as CommentEditChallengeRequestToEncryptSchema, zt as untrackUpdatingCommunity } from "./schema-5-rYJ-bC.js";
|
|
3
3
|
import { t as all } from "./src-CYIMjhjK.js";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
@@ -92191,7 +92191,7 @@ const RpcExportCommunityModLogsResultSchema = object({ moderations: array(Commen
|
|
|
92191
92191
|
//#endregion
|
|
92192
92192
|
//#region dist/node/rpc/src/schema.js
|
|
92193
92193
|
const WsServerClassOptions = object({
|
|
92194
|
-
port: number().int().
|
|
92194
|
+
port: number().int().nonnegative().optional(),
|
|
92195
92195
|
server: custom().optional()
|
|
92196
92196
|
});
|
|
92197
92197
|
const CreatePKCWsServerOptionsSchema = object({
|
|
@@ -125415,12 +125415,18 @@ function selectWinningGatewayCommunity(opts) {
|
|
|
125415
125415
|
//#endregion
|
|
125416
125416
|
//#region dist/node/community/community-client-manager.js
|
|
125417
125417
|
const MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS = 1024 * 1024;
|
|
125418
|
+
const FORCED_IPNS_NETWORK_REVALIDATION_MIN_INTERVAL_MS = 3e4;
|
|
125418
125419
|
var CommunityClientsManager = class extends PKCClientsManager {
|
|
125419
125420
|
constructor(community) {
|
|
125420
125421
|
super(community._pkc);
|
|
125421
125422
|
this._suppressUpdatingStateForNameResolution = 0;
|
|
125422
125423
|
this._ipnsLoadingOperation = void 0;
|
|
125423
125424
|
this._updateCidsAlreadyLoaded = new LimitedSet(30);
|
|
125425
|
+
this._subscribedIpnsArrivalTopics = /* @__PURE__ */ new Set();
|
|
125426
|
+
this._pendingIpnsArrivalCids = /* @__PURE__ */ new Set();
|
|
125427
|
+
this._pendingIpnsArrivalHopTargets = /* @__PURE__ */ new Set();
|
|
125428
|
+
this._nextResolveRevalidatesNetwork = false;
|
|
125429
|
+
this._lastForcedIpnsNetworkRevalidationAtMs = 0;
|
|
125424
125430
|
this._community = community;
|
|
125425
125431
|
this._initPKCRpcClients();
|
|
125426
125432
|
hideClassPrivateProps(this);
|
|
@@ -125583,20 +125589,127 @@ var CommunityClientsManager = class extends PKCClientsManager {
|
|
|
125583
125589
|
async startUpdatingLoop() {
|
|
125584
125590
|
const log = logger_default("pkc-js:remote-community:update");
|
|
125585
125591
|
this._community._createStopAbortController();
|
|
125586
|
-
const
|
|
125592
|
+
const areWeConnectedToKuboOrHelia = Object.keys(this._pkc.clients.kuboRpcClients).length > 0 || Object.keys(this._pkc.clients.libp2pJsClients).length > 0;
|
|
125593
|
+
const defaultIpfsClient = areWeConnectedToKuboOrHelia ? this.getDefaultKuboRpcClientOrHelia() : void 0;
|
|
125594
|
+
const defaultLibp2pJsClient = defaultIpfsClient && "_helia" in defaultIpfsClient ? defaultIpfsClient : void 0;
|
|
125595
|
+
if (defaultLibp2pJsClient) {
|
|
125596
|
+
try {
|
|
125597
|
+
this._syncIpnsArrivalSubscriptions(defaultLibp2pJsClient);
|
|
125598
|
+
} catch (e) {
|
|
125599
|
+
log.error(`Failed to arm IPNS record arrival subscriptions of community ${this._community.address} before its first update`, e);
|
|
125600
|
+
}
|
|
125601
|
+
this._lastForcedIpnsNetworkRevalidationAtMs = Date.now();
|
|
125602
|
+
}
|
|
125587
125603
|
while (this._community.state === "updating" && !this._community._getStopAbortSignal()?.aborted) try {
|
|
125588
125604
|
await this.updateOnce();
|
|
125589
125605
|
} catch (e) {
|
|
125590
125606
|
log.error(`Failed to update community ${this._community.address} for this iteration, will retry later`, e);
|
|
125591
125607
|
} finally {
|
|
125592
|
-
|
|
125608
|
+
if (defaultLibp2pJsClient) {
|
|
125609
|
+
try {
|
|
125610
|
+
this._syncIpnsArrivalSubscriptions(defaultLibp2pJsClient);
|
|
125611
|
+
} catch (e) {
|
|
125612
|
+
log.error(`Failed to sync IPNS record arrival subscriptions of community ${this._community.address}`, e);
|
|
125613
|
+
}
|
|
125614
|
+
const safetyNetMs = this._pkc.updateInterval * (.75 + Math.random() * .5);
|
|
125615
|
+
await this._sleepUntilIpnsArrivalOrTimeoutOrAbort({
|
|
125616
|
+
ms: safetyNetMs,
|
|
125617
|
+
signal: this._community._getStopAbortSignal()
|
|
125618
|
+
});
|
|
125619
|
+
} else await sleepUntilTimeoutOrAbort(areWeConnectedToKuboOrHelia ? 1e3 : this._pkc.updateInterval, this._community._getStopAbortSignal());
|
|
125593
125620
|
}
|
|
125621
|
+
this._clearIpnsArrivalSubscriptions();
|
|
125594
125622
|
this._community._clearStopAbortController();
|
|
125595
125623
|
log("Community", this._community.address, "is no longer updating");
|
|
125596
125624
|
}
|
|
125597
125625
|
async stopUpdatingLoop() {
|
|
125598
125626
|
this._ipnsLoadingOperation?.stop();
|
|
125599
125627
|
this._updateCidsAlreadyLoaded.clear();
|
|
125628
|
+
this._clearIpnsArrivalSubscriptions();
|
|
125629
|
+
}
|
|
125630
|
+
_onIpnsRecordArrival(arrival) {
|
|
125631
|
+
const value = arrival.record.value;
|
|
125632
|
+
if (isIpfsPath(value)) {
|
|
125633
|
+
const cid = value.split("/")[2];
|
|
125634
|
+
if (this._updateCidsAlreadyLoaded.has(cid) || this._community.updateCid === cid) return;
|
|
125635
|
+
this._pendingIpnsArrivalCids.add(cid);
|
|
125636
|
+
} else if (isIpnsPath(value)) {
|
|
125637
|
+
const hopTarget = value.split("/")[2];
|
|
125638
|
+
if (this._community.ipnsHops?.includes(hopTarget)) return;
|
|
125639
|
+
this._pendingIpnsArrivalHopTargets.add(hopTarget);
|
|
125640
|
+
} else return;
|
|
125641
|
+
this._wakeUpdateLoopForIpnsArrival?.();
|
|
125642
|
+
}
|
|
125643
|
+
_consumePendingIpnsArrivals() {
|
|
125644
|
+
for (const cid of this._pendingIpnsArrivalCids) if (this._updateCidsAlreadyLoaded.has(cid) || this._community.updateCid === cid) this._pendingIpnsArrivalCids.delete(cid);
|
|
125645
|
+
for (const hopTarget of this._pendingIpnsArrivalHopTargets) if (this._community.ipnsHops?.includes(hopTarget)) this._pendingIpnsArrivalHopTargets.delete(hopTarget);
|
|
125646
|
+
if (this._pendingIpnsArrivalCids.size === 0 && this._pendingIpnsArrivalHopTargets.size === 0) return false;
|
|
125647
|
+
this._pendingIpnsArrivalCids.clear();
|
|
125648
|
+
this._pendingIpnsArrivalHopTargets.clear();
|
|
125649
|
+
return true;
|
|
125650
|
+
}
|
|
125651
|
+
_syncIpnsArrivalSubscriptions(client) {
|
|
125652
|
+
if (!this._ipnsArrivalListener) this._ipnsArrivalListener = (arrival) => this._onIpnsRecordArrival(arrival);
|
|
125653
|
+
this._ipnsArrivalClient = client;
|
|
125654
|
+
const preResolveIpnsName = this._community.ipnsName ?? this._pinnedIpnsName() ?? (!isStringDomain(this._community.address) ? this._community.address : void 0);
|
|
125655
|
+
const ipnsNamesToWatch = this._community.ipnsHops?.length ? this._community.ipnsHops : preResolveIpnsName ? [preResolveIpnsName] : [];
|
|
125656
|
+
const desiredTopics = new Set(ipnsNamesToWatch.map(ipnsNameToIpnsOverPubsubTopic));
|
|
125657
|
+
for (const topic of this._subscribedIpnsArrivalTopics) if (!desiredTopics.has(topic)) {
|
|
125658
|
+
client.heliaWithKuboRpcClientFunctions.ipnsRecordArrivals.unsubscribe({
|
|
125659
|
+
pubsubTopic: topic,
|
|
125660
|
+
listener: this._ipnsArrivalListener
|
|
125661
|
+
});
|
|
125662
|
+
this._subscribedIpnsArrivalTopics.delete(topic);
|
|
125663
|
+
}
|
|
125664
|
+
for (const topic of desiredTopics) if (!this._subscribedIpnsArrivalTopics.has(topic)) {
|
|
125665
|
+
client.heliaWithKuboRpcClientFunctions.ipnsRecordArrivals.subscribe({
|
|
125666
|
+
pubsubTopic: topic,
|
|
125667
|
+
listener: this._ipnsArrivalListener
|
|
125668
|
+
});
|
|
125669
|
+
this._subscribedIpnsArrivalTopics.add(topic);
|
|
125670
|
+
}
|
|
125671
|
+
}
|
|
125672
|
+
_resyncIpnsArrivalSubscriptionsIfArmed() {
|
|
125673
|
+
if (!this._ipnsArrivalClient) return;
|
|
125674
|
+
try {
|
|
125675
|
+
this._syncIpnsArrivalSubscriptions(this._ipnsArrivalClient);
|
|
125676
|
+
} catch (e) {
|
|
125677
|
+
logger_default("pkc-js:remote-community:update").error(`Failed to sync IPNS record arrival subscriptions of community ${this._community.address}`, e);
|
|
125678
|
+
}
|
|
125679
|
+
}
|
|
125680
|
+
_clearIpnsArrivalSubscriptions() {
|
|
125681
|
+
if (this._ipnsArrivalClient && this._ipnsArrivalListener) for (const topic of this._subscribedIpnsArrivalTopics) this._ipnsArrivalClient.heliaWithKuboRpcClientFunctions.ipnsRecordArrivals.unsubscribe({
|
|
125682
|
+
pubsubTopic: topic,
|
|
125683
|
+
listener: this._ipnsArrivalListener
|
|
125684
|
+
});
|
|
125685
|
+
this._subscribedIpnsArrivalTopics.clear();
|
|
125686
|
+
this._ipnsArrivalClient = void 0;
|
|
125687
|
+
this._pendingIpnsArrivalCids.clear();
|
|
125688
|
+
this._pendingIpnsArrivalHopTargets.clear();
|
|
125689
|
+
this._nextResolveRevalidatesNetwork = false;
|
|
125690
|
+
}
|
|
125691
|
+
async _sleepUntilIpnsArrivalOrTimeoutOrAbort({ ms, signal }) {
|
|
125692
|
+
if (this._consumePendingIpnsArrivals()) {
|
|
125693
|
+
this._nextResolveRevalidatesNetwork = false;
|
|
125694
|
+
return;
|
|
125695
|
+
}
|
|
125696
|
+
const { promise, wake } = interruptibleSleep({
|
|
125697
|
+
ms,
|
|
125698
|
+
signal
|
|
125699
|
+
});
|
|
125700
|
+
let wokenByArrival = false;
|
|
125701
|
+
const wakeForArrival = () => {
|
|
125702
|
+
wokenByArrival = true;
|
|
125703
|
+
wake();
|
|
125704
|
+
};
|
|
125705
|
+
this._wakeUpdateLoopForIpnsArrival = wakeForArrival;
|
|
125706
|
+
await promise;
|
|
125707
|
+
if (this._wakeUpdateLoopForIpnsArrival === wakeForArrival) this._wakeUpdateLoopForIpnsArrival = void 0;
|
|
125708
|
+
if (wokenByArrival) {
|
|
125709
|
+
this._pendingIpnsArrivalCids.clear();
|
|
125710
|
+
this._pendingIpnsArrivalHopTargets.clear();
|
|
125711
|
+
}
|
|
125712
|
+
this._nextResolveRevalidatesNetwork = !wokenByArrival && Date.now() - this._lastForcedIpnsNetworkRevalidationAtMs >= FORCED_IPNS_NETWORK_REVALIDATION_MIN_INTERVAL_MS;
|
|
125600
125713
|
}
|
|
125601
125714
|
async _resolveCommunityNameWithoutUpdatingState({ communityName, abortSignal, cache }) {
|
|
125602
125715
|
this._suppressUpdatingStateForNameResolution++;
|
|
@@ -125618,6 +125731,25 @@ var CommunityClientsManager = class extends PKCClientsManager {
|
|
|
125618
125731
|
if (this._community.publicKey) chainKeys.delete(this._community.publicKey);
|
|
125619
125732
|
return [...chainKeys];
|
|
125620
125733
|
}
|
|
125734
|
+
_applyKeyMigration({ communityName, newPublicKey }) {
|
|
125735
|
+
logger_default("pkc-js:community-client-manager:_applyKeyMigration")("Key migration detected for", communityName, "old:", this._community.publicKey, "new:", newPublicKey);
|
|
125736
|
+
const previousPublicKey = this._community.publicKey;
|
|
125737
|
+
const error = new PKCError("ERR_COMMUNITY_NAME_RESOLVES_TO_DIFFERENT_PUBLIC_KEY", {
|
|
125738
|
+
communityName,
|
|
125739
|
+
previousPublicKey,
|
|
125740
|
+
newPublicKey
|
|
125741
|
+
});
|
|
125742
|
+
this._community._clearDataForKeyMigration(newPublicKey);
|
|
125743
|
+
this._updateCidsAlreadyLoaded.clear();
|
|
125744
|
+
this._community.nameResolved = true;
|
|
125745
|
+
this._pendingIpnsArrivalCids.clear();
|
|
125746
|
+
this._pendingIpnsArrivalHopTargets.clear();
|
|
125747
|
+
this._resyncIpnsArrivalSubscriptionsIfArmed();
|
|
125748
|
+
this._community._abortStopOperations("Key migration: name resolved to different public key");
|
|
125749
|
+
this._community._createStopAbortController();
|
|
125750
|
+
this._community.emit("update", this._community);
|
|
125751
|
+
this._community.emit("error", error);
|
|
125752
|
+
}
|
|
125621
125753
|
_resolveNameInBackground(name) {
|
|
125622
125754
|
const log = logger_default("pkc-js:community-client-manager:_resolveNameInBackground");
|
|
125623
125755
|
const setNameResolvedAndEmitUpdate = (newNameResolved) => {
|
|
@@ -125636,20 +125768,10 @@ var CommunityClientsManager = class extends PKCClientsManager {
|
|
|
125636
125768
|
setNameResolvedAndEmitUpdate(false);
|
|
125637
125769
|
return;
|
|
125638
125770
|
}
|
|
125639
|
-
|
|
125640
|
-
const previousPublicKey = this._community.publicKey;
|
|
125641
|
-
const error = new PKCError("ERR_COMMUNITY_NAME_RESOLVES_TO_DIFFERENT_PUBLIC_KEY", {
|
|
125771
|
+
this._applyKeyMigration({
|
|
125642
125772
|
communityName: name,
|
|
125643
|
-
previousPublicKey,
|
|
125644
125773
|
newPublicKey: resolved
|
|
125645
125774
|
});
|
|
125646
|
-
this._community._clearDataForKeyMigration(resolved);
|
|
125647
|
-
this._updateCidsAlreadyLoaded.clear();
|
|
125648
|
-
this._community.nameResolved = true;
|
|
125649
|
-
this._community._abortStopOperations("Key migration: name resolved to different public key");
|
|
125650
|
-
this._community._createStopAbortController();
|
|
125651
|
-
this._community.emit("update", this._community);
|
|
125652
|
-
this._community.emit("error", error);
|
|
125653
125775
|
} else if (resolved) setNameResolvedAndEmitUpdate(true);
|
|
125654
125776
|
if (!resolved && this._community.name) setNameResolvedAndEmitUpdate(false);
|
|
125655
125777
|
}).catch((e) => {
|
|
@@ -125681,13 +125803,18 @@ var CommunityClientsManager = class extends PKCClientsManager {
|
|
|
125681
125803
|
abortSignal: this._community._getStopAbortSignal()
|
|
125682
125804
|
});
|
|
125683
125805
|
}
|
|
125806
|
+
_pinnedIpnsName() {
|
|
125807
|
+
const isDomain = isStringDomain(this._community.address);
|
|
125808
|
+
const hasAnchorClaim = Boolean(this._community.anchor);
|
|
125809
|
+
if (this._community.publicKey && (isDomain || hasAnchorClaim || !isDomain && this._community.name && this._community.nameResolved === true)) return this._community.publicKey;
|
|
125810
|
+
}
|
|
125684
125811
|
async fetchNewUpdateForCommunity(communityAddress) {
|
|
125685
125812
|
return this._withInflightCommunityFetch(communityAddress, async () => {
|
|
125686
125813
|
let ipnsName;
|
|
125687
125814
|
const isDomain = isStringDomain(communityAddress);
|
|
125688
|
-
const
|
|
125689
|
-
if (
|
|
125690
|
-
ipnsName =
|
|
125815
|
+
const pinnedIpnsName = this._pinnedIpnsName();
|
|
125816
|
+
if (pinnedIpnsName) {
|
|
125817
|
+
ipnsName = pinnedIpnsName;
|
|
125691
125818
|
if (isDomain) this._resolveNameInBackground(communityAddress);
|
|
125692
125819
|
} else ipnsName = await this.resolveCommunityNameIfNeeded({
|
|
125693
125820
|
communityName: communityAddress,
|
|
@@ -125701,6 +125828,7 @@ var CommunityClientsManager = class extends PKCClientsManager {
|
|
|
125701
125828
|
this._community.ipnsHops = [ipnsName];
|
|
125702
125829
|
this._community.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(ipnsName);
|
|
125703
125830
|
this._community.ipnsPubsubTopicRoutingCid = pubsubTopicToDhtKey(this._community.ipnsPubsubTopic);
|
|
125831
|
+
this._resyncIpnsArrivalSubscriptionsIfArmed();
|
|
125704
125832
|
}
|
|
125705
125833
|
if (this._community.updateCid) this._updateCidsAlreadyLoaded.add(this._community.updateCid);
|
|
125706
125834
|
this._community._setUpdatingStateWithEventEmissionIfNewState("fetching-ipns");
|
|
@@ -125742,9 +125870,13 @@ var CommunityClientsManager = class extends PKCClientsManager {
|
|
|
125742
125870
|
const kuboRpcOrHelia = this.getDefaultKuboRpcClientOrHelia();
|
|
125743
125871
|
if ("_helia" in kuboRpcOrHelia) this.updateLibp2pJsClientState("fetching-ipns", kuboRpcOrHelia._libp2pJsClientsOptions.key);
|
|
125744
125872
|
else this.updateKuboRpcState("fetching-ipns", kuboRpcOrHelia.url);
|
|
125873
|
+
const forceNetworkRevalidation = this._nextResolveRevalidatesNetwork;
|
|
125874
|
+
this._nextResolveRevalidatesNetwork = false;
|
|
125875
|
+
if (forceNetworkRevalidation) this._lastForcedIpnsNetworkRevalidationAtMs = Date.now();
|
|
125745
125876
|
const { cid: latestCommunityCid, ipnsHops } = await this.resolveIpnsToCidP2P(ipnsName, {
|
|
125746
125877
|
timeoutMs: this._pkc._timeouts["community-ipns"],
|
|
125747
|
-
abortSignal: this._community._getStopAbortSignal()
|
|
125878
|
+
abortSignal: this._community._getStopAbortSignal(),
|
|
125879
|
+
...forceNetworkRevalidation ? { nocache: true } : {}
|
|
125748
125880
|
});
|
|
125749
125881
|
this._community.ipnsHops = ipnsHops;
|
|
125750
125882
|
ipnsHops[ipnsHops.length - 1];
|
|
@@ -126387,6 +126519,7 @@ var RemoteCommunity = class extends import_lib$1.TypedEmitter {
|
|
|
126387
126519
|
this.pubsubTopicRoutingCid = void 0;
|
|
126388
126520
|
this.publicKey = newPublicKey;
|
|
126389
126521
|
this.ipnsName = newPublicKey;
|
|
126522
|
+
this.ipnsHops = [newPublicKey];
|
|
126390
126523
|
this.ipnsPubsubTopic = ipnsNameToIpnsOverPubsubTopic(newPublicKey);
|
|
126391
126524
|
this.ipnsPubsubTopicRoutingCid = pubsubTopicToDhtKey(this.ipnsPubsubTopic);
|
|
126392
126525
|
this._assertHasIdentity();
|
|
@@ -129652,11 +129785,12 @@ var RpcRemoteCommunity = class extends RemoteCommunity {
|
|
|
129652
129785
|
async _initRpcUpdateSubscription() {
|
|
129653
129786
|
const log = logger_default("pkc-js:rpc-remote-community:_initRpcUpdateSubscription");
|
|
129654
129787
|
this._setState("updating");
|
|
129788
|
+
let subscriptionId;
|
|
129655
129789
|
try {
|
|
129656
|
-
|
|
129790
|
+
({subscriptionId} = await this._pkc._pkcRpcClient.communityUpdateSubscribe({
|
|
129657
129791
|
name: this.name,
|
|
129658
129792
|
publicKey: this.publicKey
|
|
129659
|
-
});
|
|
129793
|
+
}));
|
|
129660
129794
|
this._updateRpcSubscriptionId = subscriptionId;
|
|
129661
129795
|
} catch (e) {
|
|
129662
129796
|
log.error("Failed to receive communityUpdate from RPC due to error", e);
|
|
@@ -129664,8 +129798,17 @@ var RpcRemoteCommunity = class extends RemoteCommunity {
|
|
|
129664
129798
|
this._setUpdatingStateWithEventEmissionIfNewState("failed");
|
|
129665
129799
|
throw e;
|
|
129666
129800
|
}
|
|
129667
|
-
this._pkc._pkcRpcClient.
|
|
129668
|
-
|
|
129801
|
+
this._pkc._pkcRpcClient.attachSubscriptionHandlersDeferred({
|
|
129802
|
+
subscriptionId,
|
|
129803
|
+
isStale: () => this._updateRpcSubscriptionId !== subscriptionId,
|
|
129804
|
+
attach: (subscription) => subscription.on("update", this._processUpdateEventFromRpcUpdate.bind(this)).on("updatingstatechange", this._handleUpdatingStateChangeFromRpcUpdate.bind(this)).on("error", this._handleRpcErrorEvent.bind(this)),
|
|
129805
|
+
replayErrorContainment: {
|
|
129806
|
+
entityName: "community",
|
|
129807
|
+
log,
|
|
129808
|
+
emitError: (error) => this.emit("error", error),
|
|
129809
|
+
stop: () => this.stop()
|
|
129810
|
+
}
|
|
129811
|
+
});
|
|
129669
129812
|
}
|
|
129670
129813
|
async _createAndSubscribeToNewUpdatingCommunity(updatingCommunity) {
|
|
129671
129814
|
const log = logger_default("pkc-js:rpc-remote-community:_createNewUpdatingCommunity");
|
|
@@ -129730,12 +129873,13 @@ var RpcRemoteCommunity = class extends RemoteCommunity {
|
|
|
129730
129873
|
if (this._updatingRpcCommunityInstanceWithListeners) await this._cleanupMirroringUpdatingCommunity();
|
|
129731
129874
|
else {
|
|
129732
129875
|
if (this._updateRpcSubscriptionId) {
|
|
129876
|
+
const subscriptionId = this._updateRpcSubscriptionId;
|
|
129877
|
+
this._updateRpcSubscriptionId = void 0;
|
|
129733
129878
|
try {
|
|
129734
|
-
await this._pkc._pkcRpcClient.unsubscribe(
|
|
129879
|
+
await this._pkc._pkcRpcClient.unsubscribe(subscriptionId);
|
|
129735
129880
|
} catch (e) {
|
|
129736
129881
|
log.error("Failed to unsubscribe from communityUpdate", e);
|
|
129737
129882
|
}
|
|
129738
|
-
this._updateRpcSubscriptionId = void 0;
|
|
129739
129883
|
log.trace(`Stopped the update of remote community (${this.address}) via RPC`);
|
|
129740
129884
|
}
|
|
129741
129885
|
untrackUpdatingCommunity(this._pkc, this);
|
|
@@ -129926,19 +130070,29 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
|
|
|
129926
130070
|
}
|
|
129927
130071
|
trackStartedCommunity(this._pkc, this);
|
|
129928
130072
|
this.started = true;
|
|
129929
|
-
|
|
129930
|
-
this._pkc._pkcRpcClient.
|
|
130073
|
+
const subscriptionId = this._startRpcSubscriptionId;
|
|
130074
|
+
this._pkc._pkcRpcClient.attachSubscriptionHandlersDeferred({
|
|
130075
|
+
subscriptionId,
|
|
130076
|
+
isStale: () => this._startRpcSubscriptionId !== subscriptionId,
|
|
130077
|
+
attach: (subscription) => subscription.on("update", this._handleRpcUpdateEventFromStart.bind(this)).on("startedstatechange", this._handleRpcStartedStateChangeEvent.bind(this)).on("challengerequest", this._handleRpcChallengeRequestEvent.bind(this)).on("challenge", this._handleRpcChallengeEvent.bind(this)).on("challengeanswer", this._handleRpcChallengeAnswerEvent.bind(this)).on("challengeverification", this._handleRpcChallengeVerificationEvent.bind(this)).on("error", this._handleRpcErrorEvent.bind(this)),
|
|
130078
|
+
replayErrorContainment: {
|
|
130079
|
+
entityName: "community",
|
|
130080
|
+
log,
|
|
130081
|
+
emitError: (error) => this.emit("error", error),
|
|
130082
|
+
stop: () => this.stopWithoutRpcCall()
|
|
130083
|
+
}
|
|
130084
|
+
});
|
|
129931
130085
|
}
|
|
129932
|
-
async _cleanUpRpcConnection(log) {
|
|
129933
|
-
|
|
129934
|
-
|
|
130086
|
+
async _cleanUpRpcConnection(log, subscriptionId = this._startRpcSubscriptionId) {
|
|
130087
|
+
this._startRpcSubscriptionId = void 0;
|
|
130088
|
+
if (subscriptionId) try {
|
|
130089
|
+
await this._pkc._pkcRpcClient.unsubscribe(subscriptionId);
|
|
129935
130090
|
} catch (e) {
|
|
129936
130091
|
log.error("Failed to unsubscribe from communityStart", e);
|
|
129937
130092
|
}
|
|
129938
130093
|
this._setStartedStateWithEmission("stopped");
|
|
129939
130094
|
this._setRpcClientStateWithEmission("stopped");
|
|
129940
130095
|
this.started = false;
|
|
129941
|
-
this._startRpcSubscriptionId = void 0;
|
|
129942
130096
|
log(`Stopped the running of local community (${this.address}) via RPC`);
|
|
129943
130097
|
this._setState("stopped");
|
|
129944
130098
|
}
|
|
@@ -129972,6 +130126,8 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
|
|
|
129972
130126
|
if (this.state === "updating") return super.stop();
|
|
129973
130127
|
else if (this.state === "started") {
|
|
129974
130128
|
const log = logger_default("pkc-js:rpc-local-community:stop");
|
|
130129
|
+
const subscriptionId = this._startRpcSubscriptionId;
|
|
130130
|
+
this._startRpcSubscriptionId = void 0;
|
|
129975
130131
|
try {
|
|
129976
130132
|
await this._pkc._pkcRpcClient.stopCommunity({
|
|
129977
130133
|
name: this.name,
|
|
@@ -129980,7 +130136,7 @@ var RpcLocalCommunity = class extends RpcRemoteCommunity {
|
|
|
129980
130136
|
} catch (e) {
|
|
129981
130137
|
log.error("RPC client received an error when asking rpc server to stop community", e);
|
|
129982
130138
|
}
|
|
129983
|
-
await this._cleanUpRpcConnection(log);
|
|
130139
|
+
await this._cleanUpRpcConnection(log, subscriptionId);
|
|
129984
130140
|
untrackStartedCommunity(this._pkc, this);
|
|
129985
130141
|
}
|
|
129986
130142
|
}
|