@pkcprotocol/pkc-js 0.0.83 → 0.0.85
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 +16 -0
- package/dist/browser/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/browser/clients/rpc-client/schema.d.ts +1 -0
- package/dist/browser/community/rpc-remote-community.js +15 -8
- package/dist/browser/community/rpc-remote-community.js.map +1 -1
- package/dist/browser/community/schema.d.ts +106 -2
- package/dist/browser/community/schema.js +28 -7
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/errors.d.ts +9 -1
- package/dist/browser/errors.js +11 -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/index-with-compile-cache.d.ts +88 -2
- package/dist/browser/index.d.ts +88 -2
- package/dist/browser/pkc/pkc-with-rpc-client.d.ts +5 -3
- package/dist/browser/pkc/pkc-with-rpc-client.js +45 -7
- package/dist/browser/pkc/pkc-with-rpc-client.js.map +1 -1
- package/dist/browser/pkc/pkc.d.ts +6 -3
- package/dist/browser/pkc/pkc.js +71 -9
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/schema.d.ts +1 -1
- package/dist/browser/publications/comment/schema.js +5 -1
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/publications/community-edit/schema.d.ts +4 -0
- package/dist/browser/publications/publication-client-manager.js +10 -2
- package/dist/browser/publications/publication-client-manager.js.map +1 -1
- package/dist/browser/publications/publication.d.ts +4 -0
- package/dist/browser/publications/publication.js +36 -2
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/pubsub-messages/schema.d.ts +2 -0
- package/dist/browser/rpc/src/index.js +4 -1
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/rpc/src/lib/pkc-js/index.d.ts +44 -1
- package/dist/browser/rpc/src/schema.d.ts +265 -7
- package/dist/browser/rpc/src/schema.js +4 -2
- package/dist/browser/rpc/src/schema.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.d.ts +2 -2
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.js +5 -1
- package/dist/browser/runtime/node/community/challenges/exclude/exclude.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/index.d.ts +7 -3
- package/dist/browser/runtime/node/community/challenges/index.js +29 -6
- package/dist/browser/runtime/node/community/challenges/index.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/address-list-validation.d.ts +4 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/address-list-validation.js +27 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/address-list-validation.js.map +1 -0
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +2 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +34 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js +8 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +2 -1
- package/dist/browser/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/validate-challenge-settings.d.ts +22 -0
- package/dist/browser/runtime/node/community/challenges/validate-challenge-settings.js +92 -0
- package/dist/browser/runtime/node/community/challenges/validate-challenge-settings.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/db-state.js +8 -0
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.js +8 -0
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +29 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/schema/schema-util.d.ts +9 -0
- package/dist/browser/schema.d.ts +352 -8
- package/dist/browser/test/test-util.d.ts +2 -0
- package/dist/browser/types.d.ts +5 -0
- package/dist/browser/util.d.ts +20 -1
- package/dist/browser/util.js +100 -2
- package/dist/browser/util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +33 -31
- package/dist/bundled/chunks/{helia-for-pkc-BtjQ8rfd.js → helia-for-pkc-C5Oe_ZSx.js} +2 -2
- package/dist/bundled/chunks/{local-community-DJM47U8C.js → local-community-BqxmCg5p.js} +107 -2
- package/dist/bundled/chunks/{local-community-B_Yg8LQH.js → local-community-D4SjlAKS.js} +1 -1
- package/dist/bundled/chunks/{node-lb4SvdBh.js → node-C2DKW30L.js} +110 -22
- package/dist/bundled/chunks/{rpc-local-community-a464veDe.js → rpc-local-community-o0teUvw_.js} +91 -19
- package/dist/bundled/chunks/{schema-mdv9_FG5.js → schema-qhSDu1BU.js} +126 -10
- package/dist/bundled/chunks/{util-y9-A9BnM.js → util-BVGNNIgn.js} +1 -1
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/rpc/src/index.js +5 -5
- package/dist/node/clients/rpc-client/rpc-schema-util.d.ts +1 -0
- package/dist/node/clients/rpc-client/schema.d.ts +1 -0
- package/dist/node/community/rpc-remote-community.js +15 -8
- package/dist/node/community/rpc-remote-community.js.map +1 -1
- package/dist/node/community/schema.d.ts +106 -2
- package/dist/node/community/schema.js +28 -7
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/errors.d.ts +9 -1
- package/dist/node/errors.js +11 -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/index-with-compile-cache.d.ts +88 -2
- package/dist/node/index.d.ts +88 -2
- package/dist/node/pkc/pkc-with-rpc-client.d.ts +5 -3
- package/dist/node/pkc/pkc-with-rpc-client.js +45 -7
- package/dist/node/pkc/pkc-with-rpc-client.js.map +1 -1
- package/dist/node/pkc/pkc.d.ts +6 -3
- package/dist/node/pkc/pkc.js +71 -9
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/schema.d.ts +1 -1
- package/dist/node/publications/comment/schema.js +5 -1
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/publications/community-edit/schema.d.ts +4 -0
- package/dist/node/publications/publication-client-manager.js +10 -2
- package/dist/node/publications/publication-client-manager.js.map +1 -1
- package/dist/node/publications/publication.d.ts +4 -0
- package/dist/node/publications/publication.js +36 -2
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/pubsub-messages/schema.d.ts +2 -0
- package/dist/node/rpc/src/index.js +4 -1
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/rpc/src/lib/pkc-js/index.d.ts +44 -1
- package/dist/node/rpc/src/schema.d.ts +265 -7
- package/dist/node/rpc/src/schema.js +4 -2
- package/dist/node/rpc/src/schema.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/exclude/exclude.d.ts +2 -2
- package/dist/node/runtime/node/community/challenges/exclude/exclude.js +5 -1
- package/dist/node/runtime/node/community/challenges/exclude/exclude.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/index.d.ts +7 -3
- package/dist/node/runtime/node/community/challenges/index.js +29 -6
- package/dist/node/runtime/node/community/challenges/index.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/address-list-validation.d.ts +4 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/address-list-validation.js +27 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/address-list-validation.js.map +1 -0
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js +2 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/blacklist.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js +34 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/publication-match.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js +8 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/question.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js +2 -1
- package/dist/node/runtime/node/community/challenges/pkc-js-challenges/whitelist.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/validate-challenge-settings.d.ts +22 -0
- package/dist/node/runtime/node/community/challenges/validate-challenge-settings.js +92 -0
- package/dist/node/runtime/node/community/challenges/validate-challenge-settings.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/db-state.js +8 -0
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.js +8 -0
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +29 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/schema/schema-util.d.ts +9 -0
- package/dist/node/schema.d.ts +352 -8
- package/dist/node/test/test-util.d.ts +2 -0
- package/dist/node/types.d.ts +5 -0
- package/dist/node/util.d.ts +20 -1
- package/dist/node/util.js +100 -2
- package/dist/node/util.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $ as pubsubTopicToDhtKey, $n as n$
|
|
3
|
-
import { $
|
|
2
|
+
import { $ as pubsubTopicToDhtKey, $n as n$4, Bn as CommentEditReservedFields, C as contentContainsMarkdownAudio, Ct as findStartedCommunity, F as getIpnsRecordInLocalKuboNode, Fr as ZodError, Ft as untrackStartedCommunity, G as isLinkOfAudio, Hn as CommentEditsTableRowSchema, Ht as CommunityEditPublicationPubsubReservedFields, J as isLinkOfVideo, Jt as CommentModerationReservedFields, K as isLinkOfImage, Kn as AuthorReservedFields, L as hideClassPrivateProps, Lt as untrackUpdatingCommunity, M as genToArray, Mn as CommentsTableRowSchema, Mt as trackStartedCommunity, N as getEquivalentCommunityAddresses, O as derivePublicationFromChallengeRequest, P as getErrorCodeFromMessage, Pt as trackUpdatingCommunity, Q as isStringDomain, R as ipnsNameToIpnsOverPubsubTopic, Rn as CommentEditPubsubMessagePublicationSchema, Rt as require_sha256, S as calculateStringSizeSameAsIpfsAddCidV0, Sn as CommentPubsubMessageReservedFields, Sr as logger_default, St as findCommunityInRegistry, T as contentContainsMarkdownVideos, Tt as findUpdatingCommunity, W as isLinkOfAnimatedImage, Xt as CommentModerationsTableRowSchema, Y as isLinkValid, _t as statMfsPathSafely, a as ChallengeRequestMessageSchema, an as CommunityIpfsSchema, ar as e$1, at as removeMfsFilesSafely, b as areEquivalentCommunityAddresses, br as PKCError, cr as t$4, d as DecryptedChallengeRequestSchema, dr as t$5, dt as retryKuboBlockPutPinAndProvidePubsubTopic, er as t$8, fr as t$3, gn as VotePubsubReservedFields, gt as sleepUntilTimeoutOrAbort, hn as VotePubsubMessagePublicationSchema, ir as e, it as removeBlocksFromKuboNode, jn as CommentUpdateTableRowSchema, jt as syncCommunityRegistryEntry, k as doesDomainAddressHaveCapitalLetter, kn as CommentUpdateSchema, mr as require_retry, nr as t$7, on as CommunitySignedPropertyNames, pt as retryKuboIpfsAddAndProvide, q as isLinkOfMedia, qt as CommentModerationPubsubMessagePublicationSchema, r as ChallengeMessageSchema, rr as t$6, s as ChallengeVerificationMessageSchema, sr as r$1, st as removeNullUndefinedValues, t as ChallengeAnswerMessageSchema, tr as n$3, u as DecryptedChallengeRequestPublicationSchema, vn as VoteTablesRowSchema, w as contentContainsMarkdownImages, x as calculateIpfsCidV0, xn as CommentIpfsSchema, xr as messages, xt as writeKuboFilesWithTimeout, y as version_default, yt as timestamp, zn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema } from "./schema-qhSDu1BU.js";
|
|
3
|
+
import { $t as getPublicKeyFromPrivateKey, A as deriveDbPosts, At as verifyCommentIpfs, Bt as getAuthorNameFromWire, C as BackupAbortError, Cn as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, Dt as verifyChallengeRequest, E as calculateInlineRepliesBudget, En as parseJsonWithPKCErrorIfFails, F as importSignerIntoKuboNode, Ft as verifyCommunityEdit, G as REPLY_REPLIES_SORT_TYPES, Gt as getCommunityPublicKeyFromWire, It as verifyVote, Jt as encode, K as TIMEFRAMES_TO_SECONDS, Lt as buildRuntimeAuthor, M as getDefaultCommunityDbConfig, Mt as verifyCommentPubsubMessage, Nt as verifyCommentUpdate, O as deleteOldCommunityInWindows, P as getThumbnailPropsOfLink, Pt as verifyCommunity, Qt as getPKCAddressFromPublicKeySync, R as moveCommunityDbToDeletedDirectory, Rt as cleanWireAuthor, S as encryptEd25519AesGcmPublicKeyBuffer, St as signCommunity, T as calculateExpectedSignatureSize, Tt as verifyChallengeAnswer, U as POSTS_SORT_TYPES, W as POST_REPLIES_SORT_TYPES, Wt as getCommunityNameFromWire, Xt as getIpfsKeyFromPrivateKey, Z as iterateOverPageCidsToFindAllCids, Zt as getPKCAddressFromPublicKey, _t as signComment, a as loadChallengeFileFromCommunityChallengeSettings, ar as t$11, b as decryptEd25519AesGcmPublicKeyBuffer, bt as signCommentUpdate, c as LRUCache, d as KeyvBetterSqlite3, dn as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, dr as STORAGE_KEYS, en as createSchemaRowParser, er as crosspostChainDepthUpTo, fr as require_lodash_merge, ft as cleanUpBeforePublishing, g as SignerWithPublicKeyAddress, gt as signChallengeVerification, i as getCommunityChallengeFromCommunityChallengeSettings, ir as r$2, j as deriveDbReplies, jt as verifyCommentModeration, k as deriveCommentIpfsFromCommentTableRow, kt as verifyCommentEdit, lr as t$10, lt as pLimit, mt as signChallengeMessage, nr as t$9, o as pkcJsChallenges, or as n$6, pn as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, qt as decode, r as getChallengeVerification, rr as t$12, s as TrackedInstanceRegistry, sr as n$5, t as RpcLocalCommunity, tr as effectiveMaxCrosspostDepth, u as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, ur as stringify, vt as signCommentEdit, w as backupCommunityDb, xt as signCommentUpdateForChallengeVerification, z as resolveDbPostsCidRefs } from "./rpc-local-community-o0teUvw_.js";
|
|
4
4
|
import { randomFillSync, randomUUID } from "node:crypto";
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
import Path from "node:path";
|
|
@@ -1739,6 +1739,77 @@ async function storePublication(community, request, pendingApproval, challengeAg
|
|
|
1739
1739
|
else throw Error("Don't know how to store this publication" + request);
|
|
1740
1740
|
}
|
|
1741
1741
|
//#endregion
|
|
1742
|
+
//#region dist/node/runtime/node/community/challenges/validate-challenge-settings.js
|
|
1743
|
+
const describeChallenge = (communityChallengeSettings) => communityChallengeSettings.name || communityChallengeSettings.path || "unknown challenge";
|
|
1744
|
+
const isOptionSet = (value) => value !== void 0 && value !== null;
|
|
1745
|
+
function validateChallengeSettingsAgainstChallengeFile({ challengeSettings, challengeFile, challengeIndex }) {
|
|
1746
|
+
const baseDetails = {
|
|
1747
|
+
challengeIndex,
|
|
1748
|
+
challengeName: describeChallenge(challengeSettings)
|
|
1749
|
+
};
|
|
1750
|
+
const { optionInputs } = challengeFile;
|
|
1751
|
+
if (optionInputs) {
|
|
1752
|
+
const declaredOptions = new Set(optionInputs.map((optionInput) => optionInput.option));
|
|
1753
|
+
for (const optionName of Object.keys(challengeSettings.options ?? {})) if (!declaredOptions.has(optionName)) return new PKCError("ERR_CHALLENGE_OPTION_NOT_DECLARED_IN_OPTION_INPUTS", {
|
|
1754
|
+
...baseDetails,
|
|
1755
|
+
offendingOption: optionName,
|
|
1756
|
+
declaredOptions: [...declaredOptions]
|
|
1757
|
+
});
|
|
1758
|
+
for (const optionInput of optionInputs) if (optionInput.required && !isOptionSet(challengeSettings.options?.[optionInput.option])) return new PKCError("ERR_CHALLENGE_REQUIRED_OPTION_MISSING", {
|
|
1759
|
+
...baseDetails,
|
|
1760
|
+
missingOption: optionInput.option
|
|
1761
|
+
});
|
|
1762
|
+
for (const optionName of challengeSettings.publicOptions ?? []) if (!declaredOptions.has(optionName)) return new PKCError("ERR_CHALLENGE_PUBLIC_OPTION_NOT_DECLARED_IN_OPTION_INPUTS", {
|
|
1763
|
+
...baseDetails,
|
|
1764
|
+
offendingOption: optionName,
|
|
1765
|
+
declaredOptions: [...declaredOptions]
|
|
1766
|
+
});
|
|
1767
|
+
}
|
|
1768
|
+
if (challengeFile.validateChallengeSettings) try {
|
|
1769
|
+
challengeFile.validateChallengeSettings({ challengeSettings });
|
|
1770
|
+
} catch (e) {
|
|
1771
|
+
const wrapped = new PKCError("ERR_CHALLENGE_SETTINGS_VALIDATION_FAILED", {
|
|
1772
|
+
...baseDetails,
|
|
1773
|
+
validationError: e instanceof Error ? e.message : String(e)
|
|
1774
|
+
});
|
|
1775
|
+
Object.assign(wrapped, { cause: e });
|
|
1776
|
+
return wrapped;
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
async function collectChallengeSettingsValidationFailures({ challengeSettings, pkc }) {
|
|
1780
|
+
const failures = [];
|
|
1781
|
+
for (const [challengeIndex, communityChallengeSettings] of challengeSettings.entries()) {
|
|
1782
|
+
const error = validateChallengeSettingsAgainstChallengeFile({
|
|
1783
|
+
challengeSettings: communityChallengeSettings,
|
|
1784
|
+
challengeFile: await loadChallengeFileFromCommunityChallengeSettings({
|
|
1785
|
+
communityChallengeSettings,
|
|
1786
|
+
pkc
|
|
1787
|
+
}),
|
|
1788
|
+
challengeIndex
|
|
1789
|
+
});
|
|
1790
|
+
if (error) failures.push({
|
|
1791
|
+
challengeIndex,
|
|
1792
|
+
challengeName: describeChallenge(communityChallengeSettings),
|
|
1793
|
+
error
|
|
1794
|
+
});
|
|
1795
|
+
}
|
|
1796
|
+
return failures;
|
|
1797
|
+
}
|
|
1798
|
+
async function throwIfChallengeSettingsAreInvalid({ challengeSettings, pkc, communityAddress }) {
|
|
1799
|
+
const failures = await collectChallengeSettingsValidationFailures({
|
|
1800
|
+
challengeSettings,
|
|
1801
|
+
pkc
|
|
1802
|
+
});
|
|
1803
|
+
if (failures.length) throw new PKCError("ERR_CHALLENGE_SETTINGS_VALIDATION_FAILED_FOR_CHALLENGES", {
|
|
1804
|
+
communityAddress,
|
|
1805
|
+
failures: failures.map(({ challengeIndex, challengeName, error }) => ({
|
|
1806
|
+
challengeIndex,
|
|
1807
|
+
challengeName,
|
|
1808
|
+
error
|
|
1809
|
+
}))
|
|
1810
|
+
});
|
|
1811
|
+
}
|
|
1812
|
+
//#endregion
|
|
1742
1813
|
//#region dist/node/runtime/node/community/local-community/registry.js
|
|
1743
1814
|
const processStartedCommunities = new TrackedInstanceRegistry();
|
|
1744
1815
|
//#endregion
|
|
@@ -6091,6 +6162,11 @@ async function createNewLocalCommunityDb(community) {
|
|
|
6091
6162
|
...community.settings,
|
|
6092
6163
|
purgeDisapprovedCommentsOlderThan: 121e4
|
|
6093
6164
|
};
|
|
6165
|
+
await throwIfChallengeSettingsAreInvalid({
|
|
6166
|
+
challengeSettings: community.settings.challenges,
|
|
6167
|
+
pkc: community._pkc,
|
|
6168
|
+
communityAddress: community.address
|
|
6169
|
+
});
|
|
6094
6170
|
community.challenges = await Promise.all(community.settings.challenges.map(async (cs) => (await getCommunityChallengeFromCommunityChallengeSettings({
|
|
6095
6171
|
communityChallengeSettings: cs,
|
|
6096
6172
|
pkc: community._pkc
|
|
@@ -6633,6 +6709,29 @@ async function initBeforeStarting(community) {
|
|
|
6633
6709
|
});
|
|
6634
6710
|
await community._dbHandler.initDbIfNeeded();
|
|
6635
6711
|
}
|
|
6712
|
+
async function emitChallengeSettingsValidationErrors(community, log) {
|
|
6713
|
+
let failures;
|
|
6714
|
+
try {
|
|
6715
|
+
failures = await collectChallengeSettingsValidationFailures({
|
|
6716
|
+
challengeSettings: community.settings?.challenges ?? [],
|
|
6717
|
+
pkc: community._pkc
|
|
6718
|
+
});
|
|
6719
|
+
} catch (e) {
|
|
6720
|
+
log.error("Failed to validate settings.challenges on start", community.address, e);
|
|
6721
|
+
community.emit("error", e);
|
|
6722
|
+
return;
|
|
6723
|
+
}
|
|
6724
|
+
for (const { error, challengeIndex, challengeName } of failures) {
|
|
6725
|
+
error.details = {
|
|
6726
|
+
...error.details,
|
|
6727
|
+
challengeIndex,
|
|
6728
|
+
challengeName,
|
|
6729
|
+
communityAddress: community.address
|
|
6730
|
+
};
|
|
6731
|
+
log.error("Invalid challenge settings on start", community.address, error);
|
|
6732
|
+
community.emit("error", error);
|
|
6733
|
+
}
|
|
6734
|
+
}
|
|
6636
6735
|
async function start(community) {
|
|
6637
6736
|
const log = logger_default("pkc-js:local-community:start");
|
|
6638
6737
|
if (community.state === "updating") throw new PKCError("ERR_NEED_TO_STOP_UPDATING_COMMUNITY_BEFORE_STARTING", { address: community.address });
|
|
@@ -6680,6 +6779,7 @@ async function start(community) {
|
|
|
6680
6779
|
communityChallengeSettings: cs,
|
|
6681
6780
|
pkc: community._pkc
|
|
6682
6781
|
})).communityChallenge));
|
|
6782
|
+
await emitChallengeSettingsValidationErrors(community, log);
|
|
6683
6783
|
} catch (e) {
|
|
6684
6784
|
await community.stop();
|
|
6685
6785
|
e.details = {
|
|
@@ -6991,6 +7091,11 @@ async function parseRolesToEdit(community, newRawRoles) {
|
|
|
6991
7091
|
return t$8(newRawRoles, (val, key) => val === void 0 || val === null);
|
|
6992
7092
|
}
|
|
6993
7093
|
async function parseChallengesToEdit(community, newChallengeSettings) {
|
|
7094
|
+
await throwIfChallengeSettingsAreInvalid({
|
|
7095
|
+
challengeSettings: newChallengeSettings,
|
|
7096
|
+
pkc: community._pkc,
|
|
7097
|
+
communityAddress: community.address
|
|
7098
|
+
});
|
|
6994
7099
|
return {
|
|
6995
7100
|
challenges: await Promise.all(newChallengeSettings.map(async (cs) => (await getCommunityChallengeFromCommunityChallengeSettings({
|
|
6996
7101
|
communityChallengeSettings: cs,
|
|
@@ -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-BqxmCg5p.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $n as n$
|
|
3
|
-
import { $ as
|
|
4
|
-
import { o as getHeliaDebugContext } from "./util-
|
|
2
|
+
import { $n as n$2, B as isIpfsCid, Bt as pTimeout, Ct as findStartedCommunity, D as deepMergeRuntimeFields, Dt as listUpdatingComments, E as createAbortError, En as CommentUpdateForChallengeVerificationSchema, Et as listStartedCommunities, H as isIpns, Ir as joinValues, It as untrackUpdatingComment, L as hideClassPrivateProps, Lr as parsedType, Nt as trackUpdatingComment, Ot as listUpdatingCommunities, Q as isStringDomain, R as ipnsNameToIpnsOverPubsubTopic, Rr as stringifyPrimitive, Rt as require_sha256, Sr as logger_default, Tr as setErrorMap, Tt as findUpdatingCommunity, a as ChallengeRequestMessageSchema, an as CommunityIpfsSchema, ar as e$1, b as areEquivalentCommunityAddresses, br as PKCError, bt as waitForUpdateInCommunityInstanceWithErrorAndTimeout, ct as removeUndefinedValuesRecursively, dn as PubsubTopicSchema, en as CommunityAnchorSchema, ft as retryKuboIpfsAdd, gt as sleepUntilTimeoutOrAbort, hr as FailedToFetchCommentIpfsFromGatewaysError, ht as shortifyCid, ir as e, k as doesDomainAddressHaveCapitalLetter, kn as CommentUpdateSchema, kt as refreshTrackedCommentAliases, lt as replaceXWithY, mr as require_retry, mt as shortifyAddress, nt as rejectWhenAbortSignalFires, r as ChallengeMessageSchema, rr as t$1, rt as rejectWhenCommunityStopsOrAborts, s as ChallengeVerificationMessageSchema, sr as r, t as ChallengeAnswerMessageSchema, tr as n$1, ut as resolveWhenPredicateIsTrue, vt as throwIfAbortSignalAborted, wt as findUpdatingComment, xn as CommentIpfsSchema, xr as messages, y as version_default, yt as timestamp, z as isAbortError, zt as TimeoutError } from "./schema-qhSDu1BU.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-o0teUvw_.js";
|
|
4
|
+
import { o as getHeliaDebugContext } from "./util-BVGNNIgn.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import assert from "assert";
|
|
7
7
|
import fs from "fs";
|
|
@@ -612,6 +612,17 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
612
612
|
if (typeof encryptionPublicKey !== "string") throw Error("Failed to load the encryption public key of community");
|
|
613
613
|
return getPKCAddressFromPublicKeySync(encryptionPublicKey);
|
|
614
614
|
}
|
|
615
|
+
_getCommunityFetchAbortSignal() {
|
|
616
|
+
if (!this._communityFetchAbortSignal) {
|
|
617
|
+
this._communityFetchAbortController = new AbortController();
|
|
618
|
+
this._communityFetchAbortSignal = AbortSignal.any([this._communityFetchAbortController.signal, this._pkc._getDestroyAbortSignal()]);
|
|
619
|
+
}
|
|
620
|
+
return this._communityFetchAbortSignal;
|
|
621
|
+
}
|
|
622
|
+
_resetCommunityFetchAbortSignal() {
|
|
623
|
+
this._communityFetchAbortController = void 0;
|
|
624
|
+
this._communityFetchAbortSignal = void 0;
|
|
625
|
+
}
|
|
615
626
|
_getCommunityCache() {
|
|
616
627
|
const cached = this._pkc._memCaches.communityForPublishing.get(this.communityAddress, { allowStale: true });
|
|
617
628
|
if (cached) return cached;
|
|
@@ -639,8 +650,12 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
639
650
|
log("The cache of community is stale, we will use the cached and update in the background");
|
|
640
651
|
const refresh = this._pkc.getCommunity({
|
|
641
652
|
publicKey: this.communityPublicKey,
|
|
642
|
-
name: this.communityName
|
|
643
|
-
|
|
653
|
+
name: this.communityName,
|
|
654
|
+
abortSignal: this._getCommunityFetchAbortSignal()
|
|
655
|
+
}).catch((e) => {
|
|
656
|
+
if (e?.code === "ERR_GET_COMMUNITY_ABORTED") log("Stopped the background refresh of the community cache", this.communityAddress);
|
|
657
|
+
else log.error("Failed to update cache of community", this.communityAddress, e);
|
|
658
|
+
}).finally(() => {
|
|
644
659
|
if (this._backgroundCommunityRefresh === refresh) this._backgroundCommunityRefresh = void 0;
|
|
645
660
|
});
|
|
646
661
|
this._backgroundCommunityRefresh = refresh;
|
|
@@ -649,6 +664,10 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
649
664
|
} else return this._clientsManager.fetchCommunityForPublishingWithCacheGuard();
|
|
650
665
|
}
|
|
651
666
|
async stop() {
|
|
667
|
+
this._communityFetchAbortController?.abort(new PKCError("ERR_GET_COMMUNITY_ABORTED", {
|
|
668
|
+
publicationType: this.getType(),
|
|
669
|
+
communityAddress: this.communityAddress
|
|
670
|
+
}));
|
|
652
671
|
try {
|
|
653
672
|
await this._postSucessOrFailurePublishing();
|
|
654
673
|
} finally {
|
|
@@ -985,6 +1004,7 @@ var Publication = class extends import_lib.TypedEmitter {
|
|
|
985
1004
|
}
|
|
986
1005
|
async publish() {
|
|
987
1006
|
this._validatePublicationFields();
|
|
1007
|
+
if (this._getCommunityFetchAbortSignal().aborted) this._resetCommunityFetchAbortSignal();
|
|
988
1008
|
this._pkc._publishingPublications.add(this);
|
|
989
1009
|
try {
|
|
990
1010
|
return await this._publishAfterRegistering();
|
|
@@ -6928,7 +6948,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
6928
6948
|
this.clients.libp2pJsClients = {};
|
|
6929
6949
|
if (!this.libp2pJsClientsOptions) return;
|
|
6930
6950
|
if (!this.httpRoutersOptions) throw Error("httpRoutersOptions is required for libp2pJsClient");
|
|
6931
|
-
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-
|
|
6951
|
+
const { createLibp2pJsClientOrUseExistingOne } = await import("./helia-for-pkc-C5Oe_ZSx.js");
|
|
6932
6952
|
for (const clientOptions of this.libp2pJsClientsOptions) {
|
|
6933
6953
|
const heliaNode = await createLibp2pJsClientOrUseExistingOne({
|
|
6934
6954
|
...clientOptions,
|
|
@@ -6987,32 +7007,63 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
6987
7007
|
hideClassPrivateProps(this);
|
|
6988
7008
|
}
|
|
6989
7009
|
async getCommunity(getCommunityArgs) {
|
|
6990
|
-
|
|
6991
|
-
|
|
7010
|
+
const { abortSignal, ...communityIdentifier } = getCommunityArgs;
|
|
7011
|
+
if (!communityIdentifier.address && !communityIdentifier.name && !communityIdentifier.publicKey) throw new Error("At least one of address, name, or publicKey must be provided");
|
|
7012
|
+
if (abortSignal?.aborted) throw new PKCError("ERR_GET_COMMUNITY_ABORTED", {
|
|
7013
|
+
communityIdentifier,
|
|
7014
|
+
abortReason: abortSignal.reason
|
|
7015
|
+
});
|
|
7016
|
+
const community = await this.createCommunity(communityIdentifier, { abortSignal });
|
|
6992
7017
|
if (typeof community.createdAt === "number") return community;
|
|
6993
7018
|
const timeoutMs = this._timeouts["community-ipns"];
|
|
6994
|
-
await waitForUpdateInCommunityInstanceWithErrorAndTimeout(
|
|
7019
|
+
await waitForUpdateInCommunityInstanceWithErrorAndTimeout({
|
|
7020
|
+
community,
|
|
7021
|
+
timeoutMs,
|
|
7022
|
+
abortSignal
|
|
7023
|
+
});
|
|
6995
7024
|
return community;
|
|
6996
7025
|
}
|
|
6997
|
-
async getComment(
|
|
7026
|
+
async getComment(getCommentArgs) {
|
|
6998
7027
|
logger_default("pkc-js:pkc:getComment");
|
|
6999
|
-
const
|
|
7028
|
+
const { abortSignal, ...cidArgs } = getCommentArgs;
|
|
7029
|
+
const parsedGetCommentArgs = parseRpcCidParam(cidArgs);
|
|
7030
|
+
if (abortSignal?.aborted) throw new PKCError("ERR_GET_COMMENT_ABORTED", {
|
|
7031
|
+
getCommentArgs: parsedGetCommentArgs,
|
|
7032
|
+
abortReason: abortSignal.reason
|
|
7033
|
+
});
|
|
7000
7034
|
const comment = await this.createComment(parsedGetCommentArgs);
|
|
7001
7035
|
let lastUpdateError;
|
|
7002
7036
|
const errorListener = (err) => lastUpdateError = err;
|
|
7003
7037
|
comment.on("error", errorListener);
|
|
7038
|
+
let abortError;
|
|
7039
|
+
let abortReject;
|
|
7040
|
+
const abortListener = () => {
|
|
7041
|
+
abortError = new PKCError("ERR_GET_COMMENT_ABORTED", {
|
|
7042
|
+
getCommentArgs: parsedGetCommentArgs,
|
|
7043
|
+
abortReason: abortSignal?.reason,
|
|
7044
|
+
lastUpdateError
|
|
7045
|
+
});
|
|
7046
|
+
abortReject?.(abortError);
|
|
7047
|
+
};
|
|
7048
|
+
const abortPromise = new Promise((_, reject) => {
|
|
7049
|
+
abortReject = reject;
|
|
7050
|
+
});
|
|
7051
|
+
abortPromise.catch(() => {});
|
|
7052
|
+
abortSignal?.addEventListener("abort", abortListener);
|
|
7004
7053
|
const commentTimeout = this._timeouts["comment-ipfs"];
|
|
7005
7054
|
try {
|
|
7006
|
-
await pTimeout(comment._attemptInfintelyToLoadCommentIpfs(), {
|
|
7055
|
+
await pTimeout(Promise.race([comment._attemptInfintelyToLoadCommentIpfs(), abortPromise]), {
|
|
7007
7056
|
milliseconds: commentTimeout,
|
|
7008
7057
|
message: lastUpdateError || new TimeoutError(`pkc.getComment({cid: ${parsedGetCommentArgs}}) timed out after ${commentTimeout}ms`)
|
|
7009
7058
|
});
|
|
7010
7059
|
if (!comment.signature) throw Error("Failed to load CommentIpfs");
|
|
7011
7060
|
return comment;
|
|
7012
7061
|
} catch (e) {
|
|
7062
|
+
if (abortError) throw abortError;
|
|
7013
7063
|
if (lastUpdateError) throw lastUpdateError;
|
|
7014
7064
|
throw e;
|
|
7015
7065
|
} finally {
|
|
7066
|
+
abortSignal?.removeEventListener("abort", abortListener);
|
|
7016
7067
|
comment.removeListener("error", errorListener);
|
|
7017
7068
|
await comment.stop();
|
|
7018
7069
|
}
|
|
@@ -7176,7 +7227,7 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7176
7227
|
const log = logger_default("pkc-js:pkc:createLocalCommunity");
|
|
7177
7228
|
log.trace("Received community options to create a local community instance:", options);
|
|
7178
7229
|
if (!this._canCreateNewLocalCommunity()) throw new PKCError("ERR_CAN_NOT_CREATE_A_LOCAL_COMMUNITY", { pkcOptions: this._userPKCOptions });
|
|
7179
|
-
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-
|
|
7230
|
+
const { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb } = await import("./local-community-D4SjlAKS.js");
|
|
7180
7231
|
const isLocalCommunity = (await listCommunitiesSync(this)).includes(options.address);
|
|
7181
7232
|
const community = new LocalCommunity(this);
|
|
7182
7233
|
if (isLocalCommunity) {
|
|
@@ -7199,8 +7250,9 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7199
7250
|
if (this.communities.includes(jsonfied.address)) return this._createLocalCommunity(jsonfied);
|
|
7200
7251
|
else return this._createRemoteCommunityInstance(jsonfied);
|
|
7201
7252
|
}
|
|
7202
|
-
async createCommunity(options = {}) {
|
|
7253
|
+
async createCommunity(options = {}, opts) {
|
|
7203
7254
|
const log = logger_default("pkc-js:pkc:createCommunity");
|
|
7255
|
+
throwIfAbortSignalAborted(opts?.abortSignal);
|
|
7204
7256
|
if ("clients" in options) return this._createCommunityInstanceFromJsonifiedCommunity(options);
|
|
7205
7257
|
const parsedOptions = options;
|
|
7206
7258
|
log.trace("Received options: ", parsedOptions);
|
|
@@ -7532,9 +7584,16 @@ var PKC$1 = class extends PKCTypedEmitter {
|
|
|
7532
7584
|
return this._storageLRUs[opts.cacheName];
|
|
7533
7585
|
}
|
|
7534
7586
|
_getDestroyAbortSignal() {
|
|
7535
|
-
if (!this._destroyAbortController)
|
|
7587
|
+
if (!this._destroyAbortController) {
|
|
7588
|
+
this._destroyAbortController = new AbortController();
|
|
7589
|
+
if (this.destroyed) this._destroyAbortController.abort(new PKCError("ERR_PKC_IS_DESTROYED"));
|
|
7590
|
+
}
|
|
7536
7591
|
return this._destroyAbortController.signal;
|
|
7537
7592
|
}
|
|
7593
|
+
_combineWithDestroyAbortSignal(abortSignal) {
|
|
7594
|
+
const destroySignal = this._getDestroyAbortSignal();
|
|
7595
|
+
return abortSignal ? AbortSignal.any([abortSignal, destroySignal]) : destroySignal;
|
|
7596
|
+
}
|
|
7538
7597
|
async destroy() {
|
|
7539
7598
|
const log = logger_default("pkc-js:pkc:destroy");
|
|
7540
7599
|
if (this.destroyed) return;
|
|
@@ -7624,9 +7683,22 @@ var PKCWithRpcClient = class extends PKC$1 {
|
|
|
7624
7683
|
await super.destroy();
|
|
7625
7684
|
await this._pkcRpcClient.destroy();
|
|
7626
7685
|
}
|
|
7627
|
-
async getComment(
|
|
7628
|
-
const
|
|
7629
|
-
const
|
|
7686
|
+
async getComment(getCommentArgs) {
|
|
7687
|
+
const { abortSignal, ...cidArgs } = getCommentArgs;
|
|
7688
|
+
const parsedArgs = parseRpcCidParam(cidArgs);
|
|
7689
|
+
const cancellation = rejectWhenAbortSignalFires({
|
|
7690
|
+
abortSignal: this._combineWithDestroyAbortSignal(abortSignal),
|
|
7691
|
+
error: () => new PKCError("ERR_GET_COMMENT_ABORTED", {
|
|
7692
|
+
getCommentArgs: parsedArgs,
|
|
7693
|
+
abortReason: abortSignal?.reason
|
|
7694
|
+
})
|
|
7695
|
+
});
|
|
7696
|
+
let commentIpfs;
|
|
7697
|
+
try {
|
|
7698
|
+
commentIpfs = await Promise.race([this._pkcRpcClient.getComment(parsedArgs), cancellation.promise]);
|
|
7699
|
+
} finally {
|
|
7700
|
+
cancellation.cleanup();
|
|
7701
|
+
}
|
|
7630
7702
|
return this.createComment({
|
|
7631
7703
|
...parsedArgs,
|
|
7632
7704
|
raw: {
|
|
@@ -7639,8 +7711,9 @@ var PKCWithRpcClient = class extends PKC$1 {
|
|
|
7639
7711
|
if (!getCommunityArgs.address && !getCommunityArgs.name && !getCommunityArgs.publicKey) throw new Error("At least one of address, name, or publicKey must be provided");
|
|
7640
7712
|
return super.getCommunity(getCommunityArgs);
|
|
7641
7713
|
}
|
|
7642
|
-
async createCommunity(options = {}) {
|
|
7714
|
+
async createCommunity(options = {}, opts) {
|
|
7643
7715
|
const log = logger_default("pkc-js:pkc-with-rpc-client:createCommunity");
|
|
7716
|
+
throwIfAbortSignalAborted(opts?.abortSignal);
|
|
7644
7717
|
const parsedRpcOptions = "clients" in options ? options : parseCreateRpcCommunityFunctionArgumentSchemaWithPKCErrorIfItFails(options);
|
|
7645
7718
|
log.trace("Received community options to create a community instance over RPC:", options);
|
|
7646
7719
|
const hasIdentifier = "address" in parsedRpcOptions && typeof parsedRpcOptions.address === "string" || "name" in parsedRpcOptions && typeof parsedRpcOptions.name === "string" || "publicKey" in parsedRpcOptions && typeof parsedRpcOptions.publicKey === "string";
|
|
@@ -7663,9 +7736,24 @@ var PKCWithRpcClient = class extends PKC$1 {
|
|
|
7663
7736
|
const updatePromise = new Promise((resolve) => community.once("update", resolve));
|
|
7664
7737
|
let error;
|
|
7665
7738
|
const errorPromise = new Promise((resolve) => community.once("error", (err) => resolve(error = err)));
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7739
|
+
const cancellation = rejectWhenCommunityStopsOrAborts({
|
|
7740
|
+
community,
|
|
7741
|
+
abortSignal: this._combineWithDestroyAbortSignal(opts?.abortSignal)
|
|
7742
|
+
});
|
|
7743
|
+
try {
|
|
7744
|
+
await Promise.race([community._createAndSubscribeToNewUpdatingCommunity(community), cancellation.promise]);
|
|
7745
|
+
await Promise.race([community.update(), cancellation.promise]);
|
|
7746
|
+
await Promise.race([
|
|
7747
|
+
updatePromise,
|
|
7748
|
+
errorPromise,
|
|
7749
|
+
cancellation.promise
|
|
7750
|
+
]);
|
|
7751
|
+
} catch (e) {
|
|
7752
|
+
await community.stop().catch((stopErr) => log.error("Failed to stop a cancelled community instance", stopErr));
|
|
7753
|
+
throw e;
|
|
7754
|
+
} finally {
|
|
7755
|
+
cancellation.cleanup();
|
|
7756
|
+
}
|
|
7669
7757
|
await community.stop();
|
|
7670
7758
|
if (error) throw error;
|
|
7671
7759
|
await community._attachExportsSubscription();
|