@pkcprotocol/pkc-js 0.0.154 → 0.0.156
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 +2 -2
- package/dist/browser/clients/rpc-client/schema.js +2 -2
- package/dist/browser/clients/rpc-client/schema.js.map +1 -1
- package/dist/browser/community/remote-community.js +8 -2
- package/dist/browser/community/remote-community.js.map +1 -1
- package/dist/browser/community/schema.js +4 -0
- package/dist/browser/community/schema.js.map +1 -1
- package/dist/browser/community-list/community-list.js +3 -2
- package/dist/browser/community-list/community-list.js.map +1 -1
- package/dist/browser/errors.d.ts +14 -0
- package/dist/browser/errors.js +14 -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/pkc/pkc.js +13 -4
- package/dist/browser/pkc/pkc.js.map +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment.js +25 -9
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/comment/crosspost-runtime.js +10 -2
- package/dist/browser/publications/comment/crosspost-runtime.js.map +1 -1
- package/dist/browser/publications/comment/schema.d.ts +1 -1
- package/dist/browser/publications/comment/schema.js +30 -1
- package/dist/browser/publications/comment/schema.js.map +1 -1
- package/dist/browser/publications/publication.d.ts +4 -0
- package/dist/browser/publications/publication.js +135 -38
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/rpc/src/index.js +3 -3
- package/dist/browser/rpc/src/index.js.map +1 -1
- package/dist/browser/runtime/browser/util.d.ts +3 -1
- package/dist/browser/runtime/browser/util.js +8 -2
- package/dist/browser/runtime/browser/util.js.map +1 -1
- package/dist/browser/runtime/node/blockstore.d.ts +2 -2
- package/dist/browser/runtime/node/blockstore.js +2 -2
- package/dist/browser/runtime/node/community/challenges/validate-challenge-result.js +2 -1
- package/dist/browser/runtime/node/community/challenges/validate-challenge-result.js.map +1 -1
- package/dist/browser/runtime/node/community/communities-registry.d.ts +96 -0
- package/dist/browser/runtime/node/community/communities-registry.js +964 -0
- package/dist/browser/runtime/node/community/communities-registry.js.map +1 -0
- package/dist/browser/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/browser/runtime/node/community/db-handler.js +82 -35
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.js +16 -8
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +68 -19
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/publication-validation.d.ts +1 -2
- package/dist/browser/runtime/node/community/local-community/publication-validation.js +23 -0
- package/dist/browser/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +2 -1
- package/dist/browser/runtime/node/community/local-community.js +5 -9
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/community/pkc-instance-lock.d.ts +17 -0
- package/dist/browser/runtime/node/community/pkc-instance-lock.js +142 -0
- package/dist/browser/runtime/node/community/pkc-instance-lock.js.map +1 -0
- package/dist/browser/runtime/node/storage.js +5 -0
- package/dist/browser/runtime/node/storage.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +4 -6
- package/dist/browser/runtime/node/util.js +32 -278
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/schema/schema-util.js +18 -4
- package/dist/browser/schema/schema-util.js.map +1 -1
- package/dist/browser/signer/author-wallet-proof.d.ts +19 -0
- package/dist/browser/signer/author-wallet-proof.js +89 -0
- package/dist/browser/signer/author-wallet-proof.js.map +1 -0
- package/dist/browser/signer/signatures.js +29 -0
- package/dist/browser/signer/signatures.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +12 -0
- package/dist/browser/test/test-util.js +23 -0
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/browser/unknown-props.d.ts +24 -0
- package/dist/browser/unknown-props.js +95 -0
- package/dist/browser/unknown-props.js.map +1 -0
- package/dist/browser/util.js +7 -0
- package/dist/browser/util.js.map +1 -1
- package/dist/browser/version.js +1 -1
- package/dist/bundled/bundle-manifest.json +66 -59
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-CG9YohPs.js → helia-for-pkc-CceaAEzV.js} +4 -4
- package/dist/bundled/chunks/{local-community-V8_VyEhO.js → local-community-BzZbcwm-.js} +128 -57
- package/dist/bundled/chunks/{local-community-CaQmhX8D.js → local-community-C8Qwak8F.js} +1 -1
- package/dist/bundled/chunks/{node-c4vpD2VN.js → node-CleFjKjX.js} +161 -49
- package/dist/bundled/chunks/{page-sort-scoring-d1frahfd.js → page-sort-scoring-BAl6dNeR.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-DDAibWpE.js → rpc-local-community-CW6GnMsd.js} +4482 -1673
- package/dist/bundled/chunks/{util-BwEIge-b.js → util-C0MpIK71.js} +62 -16
- package/dist/bundled/chunks/{util-B_dKP7Te.js → util-C29b1mlK.js} +1 -1
- package/dist/bundled/chunks/{validate-package-factories-DfpNf4oq.js → validate-package-factories-CAwF_8n6.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +5 -6
- package/dist/node/clients/rpc-client/schema.js +2 -2
- package/dist/node/clients/rpc-client/schema.js.map +1 -1
- package/dist/node/community/remote-community.js +8 -2
- package/dist/node/community/remote-community.js.map +1 -1
- package/dist/node/community/schema.js +4 -0
- package/dist/node/community/schema.js.map +1 -1
- package/dist/node/community-list/community-list.js +3 -2
- package/dist/node/community-list/community-list.js.map +1 -1
- package/dist/node/errors.d.ts +14 -0
- package/dist/node/errors.js +14 -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/pkc/pkc.js +13 -4
- package/dist/node/pkc/pkc.js.map +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment.js +25 -9
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/comment/crosspost-runtime.js +10 -2
- package/dist/node/publications/comment/crosspost-runtime.js.map +1 -1
- package/dist/node/publications/comment/schema.d.ts +1 -1
- package/dist/node/publications/comment/schema.js +30 -1
- package/dist/node/publications/comment/schema.js.map +1 -1
- package/dist/node/publications/publication.d.ts +4 -0
- package/dist/node/publications/publication.js +135 -38
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/rpc/src/index.js +3 -3
- package/dist/node/rpc/src/index.js.map +1 -1
- package/dist/node/runtime/browser/util.d.ts +3 -1
- package/dist/node/runtime/browser/util.js +8 -2
- package/dist/node/runtime/browser/util.js.map +1 -1
- package/dist/node/runtime/node/blockstore.d.ts +2 -2
- package/dist/node/runtime/node/blockstore.js +2 -2
- package/dist/node/runtime/node/community/challenges/validate-challenge-result.js +2 -1
- package/dist/node/runtime/node/community/challenges/validate-challenge-result.js.map +1 -1
- package/dist/node/runtime/node/community/communities-registry.d.ts +96 -0
- package/dist/node/runtime/node/community/communities-registry.js +964 -0
- package/dist/node/runtime/node/community/communities-registry.js.map +1 -0
- package/dist/node/runtime/node/community/db-handler.d.ts +3 -0
- package/dist/node/runtime/node/community/db-handler.js +82 -35
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.js +16 -8
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.js +68 -19
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/publication-validation.d.ts +1 -2
- package/dist/node/runtime/node/community/local-community/publication-validation.js +23 -0
- package/dist/node/runtime/node/community/local-community/publication-validation.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +2 -1
- package/dist/node/runtime/node/community/local-community.js +5 -9
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/community/pkc-instance-lock.d.ts +17 -0
- package/dist/node/runtime/node/community/pkc-instance-lock.js +142 -0
- package/dist/node/runtime/node/community/pkc-instance-lock.js.map +1 -0
- package/dist/node/runtime/node/storage.js +5 -0
- package/dist/node/runtime/node/storage.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +4 -6
- package/dist/node/runtime/node/util.js +32 -278
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/schema/schema-util.js +18 -4
- package/dist/node/schema/schema-util.js.map +1 -1
- package/dist/node/signer/author-wallet-proof.d.ts +19 -0
- package/dist/node/signer/author-wallet-proof.js +89 -0
- package/dist/node/signer/author-wallet-proof.js.map +1 -0
- package/dist/node/signer/signatures.js +29 -0
- package/dist/node/signer/signatures.js.map +1 -1
- package/dist/node/test/test-util.d.ts +12 -0
- package/dist/node/test/test-util.js +23 -0
- package/dist/node/test/test-util.js.map +1 -1
- package/dist/node/unknown-props.d.ts +24 -0
- package/dist/node/unknown-props.js +95 -0
- package/dist/node/unknown-props.js.map +1 -0
- package/dist/node/util.js +7 -0
- package/dist/node/util.js.map +1 -1
- package/dist/node/version.js +1 -1
- package/package.json +3 -2
- package/dist/browser/runtime/node/community/start-lock.d.ts +0 -17
- package/dist/browser/runtime/node/community/start-lock.js +0 -161
- package/dist/browser/runtime/node/community/start-lock.js.map +0 -1
- package/dist/node/runtime/node/community/start-lock.d.ts +0 -17
- package/dist/node/runtime/node/community/start-lock.js +0 -161
- package/dist/node/runtime/node/community/start-lock.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as __toESM } from "./chunk-2rV9d50f.js";
|
|
2
|
-
import { $n as CommentEditsTableRowSchema, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Ct as trackUpdatingCommunity, Dt as require_sha256, En as VotePubsubReservedFields, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely,
|
|
3
|
-
import { $ as createSchemaRowParser,
|
|
4
|
-
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-
|
|
2
|
+
import { $n as CommentEditsTableRowSchema, Ar as t$4, At as ChallengeAnswerMessageSchema, B as pubsubTopicToDhtKey, Br as messages, Bt as DecryptedChallengeRequestSchema, C as hideClassPrivateProps, Cr as e$1, Ct as trackUpdatingCommunity, Dr as t$3, Dt as require_sha256, En as VotePubsubReservedFields, Er as r$1, Et as untrackUpdatingCommunity, F as isLinkOfVideo, G as removeBlocksFromKuboNode, Hn as CommentsTableRowSchema, I as isLinkValid, It as ChallengeVerificationMessageSchema, J as removeNullUndefinedValues, Jt as version_default, K as removeMfsFilesSafely, M as isLinkOfAudio, Mn as CommentPubsubMessageReservedFields, Mt as ChallengeMessageSchema, N as isLinkOfImage, Nr as require_retry, On as VoteTablesRowSchema, P as isLinkOfMedia, Pt as ChallengeRequestMessageSchema, Q as retryKuboBlockPutPinAndProvidePubsubTopic, Sr as t$6, T as ipnsNameToIpnsOverPubsubTopic, Tn as VotePubsubMessagePublicationSchema, Vn as CommentUpdateTableRowSchema, Vr as logger_default, Xn as CommentEditPubsubMessagePublicationWithFlexibleAuthorSchema, Xt as CommunityEditPublicationPubsubReservedFields, Yn as CommentEditPubsubMessagePublicationSchema, Zn as CommentEditReservedFields, _ as genToArray, b as getIpnsRecordInLocalKuboNode, br as n$2, bt as syncCommunityRegistryEntry, c as contentContainsMarkdownImages, ct as withSortedKeys, dt as findStartedCommunity, et as retryKuboIpfsAddAndProvide, f as derivePublicationFromChallengeRequest, g as findMalformedUnicodeString, gr as isStringDomain, i as calculateStringSizeSameAsIpfsAddCidV0, in as CommentModerationsTableRowSchema, ir as AuthorReservedFields, it as statMfsPathSafely, j as isLinkOfAnimatedImage, jn as CommentIpfsSchema, jr as t$2, kt as pTimeout, l as contentContainsMarkdownVideos, lt as withSortedKeysDeep, mn as CommunitySignedPropertyNames, nn as CommentModerationReservedFields, o as calculateUnixFsDagSizeCidV0, ot as timestamp, p as doesDomainAddressHaveCapitalLetter, pn as CommunityIpfsSchema, pt as findUpdatingCommunity, r as calculateIpfsCidV0, ri as ZodError, rt as sleepUntilTimeoutOrAbort, s as contentContainsMarkdownAudio, tn as CommentModerationPubsubMessagePublicationSchema, ut as findCommunityInRegistry, v as getEquivalentCommunityAddresses, vr as n$3, wr as e, wt as untrackStartedCommunity, xr as t$5, xt as trackStartedCommunity, y as getErrorCodeFromMessage, yr as t$7, zn as CommentUpdateSchema, zr as PKCError, zt as DecryptedChallengeRequestPublicationSchema } from "./util-C0MpIK71.js";
|
|
3
|
+
import { $ as createSchemaRowParser, $n as stringify, Ar as getThumbnailPropsOfLink, Bn as verifyCommunity, Cn as signCommentEdit, Cr as deriveCommentIpfsFromCommentTableRow, Dn as signCommunity, Dr as forgetCommunityThatFailedToBeDeleted, Dt as parseJsonWithPKCErrorIfFails, En as signCommentUpdateForChallengeVerification, Fn as verifyCommentEdit, Fr as moveCommunityDbToDeletedDirectory, Gn as forbiddenKeysOf, Hr as getCommunitiesRegistry, In as verifyCommentIpfs, Jn as buildRuntimeAuthor, Jr as t$11, Ln as verifyCommentModeration, Lr as removeFileRetryingWhileBusy, N as MAX_PAGE_SIZE_BYTES, Nn as verifyChallengeRequest, Or as getDefaultCommunityDbConfig, Q as collectSchemaRowCoercions, Qr as n$4, Rn as verifyCommentPubsubMessage, Rr as resolveDbPostsCidRefs, S as MAX_FILE_SIZE_BYTES_FOR_COMMUNITY_IPFS, Sn as signComment, Sr as deleteOldCommunityInWindows, Tn as signCommentUpdate, Tr as deriveDbReplies, Un as verifyVote, Ur as markCommunityDbAsBeingWritten, Vn as verifyCommunityEdit, Vr as unregisterLocalCommunity, W as pLimit, Wr as findCommunitiesEntry, X as coerceSchemaRowBoolean, Xr as t$8, Yn as cleanWireAuthor, Yr as r$2, Z as coerceSchemaRowJson, Zn as getAuthorNameFromWire, Zr as n$5, _ as createAuthorIdentityMatcher, _n as cleanUpBeforePublishing, _r as BackupAbortError, a as generatePagesReportingFailedSorts, ai as STORAGE_KEYS, b as KeyvBetterSqlite3, br as calculateInlineRepliesBudget, c as resolvePageSortsOrThrow, cr as getCommunityPublicKeyFromWire, d as getChallengeVerification, dr as encode, dt as parseCommunityEditOptionsSchemaWithPKCErrorIfItFails, ei as t$9, f as getCommunityChallengeFromCommunityChallengeSettings, g as authorNameResolveFailureReason, gn as _validateSignatureOfPKCRecord, gr as getPublicKeyFromPrivateKey, h as authorIdentityMatcherForRequest, hn as encryptEd25519AesGcmPublicKeyBuffer, hr as getPKCAddressFromPublicKeySync, i as derivePublicPageSorts, ir as effectiveMaxCrosspostDepth, j as iterateOverPageCidsToFindAllCids, jn as verifyChallengeAnswer, jr as importSignerIntoKuboNode, ln as SignerWithPublicKeyAddress, m as pkcJsChallenges, mr as getPKCAddressFromPublicKey, o as loadPageSortsForStartedCommunity, oi as require_lodash_merge, p as loadChallengeFileFromCommunityChallengeSettings, pn as decryptEd25519AesGcmPublicKeyBuffer, pr as getIpfsKeyFromPrivateKey, pt as parseCommunityIpfsSchemaPassthroughWithPKCErrorIfItFails, qr as t$10, r as computePageSortsFingerprint, rr as crosspostChainDepthUpTo, s as lookupPageSortFactories, sn as verifyAuthorWalletEntry, sr as getCommunityNameFromWire, t as RpcLocalCommunity, u as deriveCommunityChallengesOrThrow, ur as decode, v as TrackedInstanceRegistry, vr as backupCommunityDb, w as TIMEFRAMES_TO_SECONDS, wr as deriveDbPosts, wt as parseDecryptedChallengeAnswerWithPKCErrorIfItFails, xn as signChallengeVerification, y as LRUCache, yn as signChallengeMessage, yr as calculateExpectedSignatureSize, zn as verifyCommentUpdate } from "./rpc-local-community-CW6GnMsd.js";
|
|
4
|
+
import { a as scorePageCommentsWithFile, i as partitionPageCommentsForSort, n as filterRepliesForPageSort, o as stripRepliesFromPageComment, r as orderPageCommentsByScore, t as createDescendantsLookup } from "./page-sort-scoring-BAl6dNeR.js";
|
|
5
5
|
import { c as prepare, n as decode$1, r as encode$1 } from "./src-BSYNGtIQ.js";
|
|
6
6
|
import { t as UnixFS } from "./src-CAvdjq_i.js";
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -1559,8 +1559,8 @@ var DbHandler = class {
|
|
|
1559
1559
|
}
|
|
1560
1560
|
destoryConnection() {
|
|
1561
1561
|
const log = logger_default("pkc-js:local-community:dbHandler:destroyConnection");
|
|
1562
|
-
if (this.holdsStartLock()) {
|
|
1563
|
-
const error = /* @__PURE__ */ new Error(`Refused to close the DB connection of community (${this._startLockAddress}) while it
|
|
1562
|
+
if (this.holdsStartLock() && this._db?.open) {
|
|
1563
|
+
const error = /* @__PURE__ */ new Error(`Refused to close the DB connection of community (${this._startLockAddress}) while it has the community started (issue #561)`);
|
|
1564
1564
|
log.error(error);
|
|
1565
1565
|
if (process.env["VITEST"]) throw error;
|
|
1566
1566
|
return;
|
|
@@ -1890,6 +1890,7 @@ var DbHandler = class {
|
|
|
1890
1890
|
if (currentDbVersion < 29) this._backfillApprovedCommentNumbers();
|
|
1891
1891
|
if (currentDbVersion < 31) this._backfillTargetAuthorSignerAddress();
|
|
1892
1892
|
if (currentDbVersion < 32) this._backfillTargetAuthorDomain();
|
|
1893
|
+
if (currentDbVersion < 47) this._stripForbiddenKeysFromChallengeCommentUpdates();
|
|
1893
1894
|
this._db.exec("PRAGMA foreign_keys = ON");
|
|
1894
1895
|
this._db.pragma(`user_version = ${version_default.DB_VERSION}`);
|
|
1895
1896
|
await this.initDbIfNeeded();
|
|
@@ -1974,6 +1975,33 @@ var DbHandler = class {
|
|
|
1974
1975
|
})(moderationsToUpdate);
|
|
1975
1976
|
log(`Backfilled targetAuthorSignerAddress for ${moderationsToUpdate.length} comment moderations`);
|
|
1976
1977
|
}
|
|
1978
|
+
_stripForbiddenKeysFromChallengeCommentUpdates() {
|
|
1979
|
+
const log = logger_default("pkc-js:local-community:db-handler:_stripForbiddenKeysFromChallengeCommentUpdates");
|
|
1980
|
+
const rows = this._db.prepare(`SELECT cid, challengeCommentUpdate FROM ${TABLES.COMMENTS} WHERE challengeCommentUpdate IS NOT NULL`).all();
|
|
1981
|
+
const update = this._db.prepare(`UPDATE ${TABLES.COMMENTS} SET challengeCommentUpdate = ? WHERE cid = ?`);
|
|
1982
|
+
for (const row of rows) {
|
|
1983
|
+
let extras;
|
|
1984
|
+
try {
|
|
1985
|
+
extras = JSON.parse(row.challengeCommentUpdate);
|
|
1986
|
+
} catch {
|
|
1987
|
+
continue;
|
|
1988
|
+
}
|
|
1989
|
+
if (typeof extras !== "object" || extras === null) continue;
|
|
1990
|
+
const topLevel = forbiddenKeysOf(extras);
|
|
1991
|
+
const author = extras.author;
|
|
1992
|
+
const authorKeys = forbiddenKeysOf(author);
|
|
1993
|
+
if (topLevel.length === 0 && authorKeys.length === 0) continue;
|
|
1994
|
+
log(`Comment ${row.cid} has challenge commentUpdate keys that are no longer allowed, dropping`, [...topLevel, ...authorKeys]);
|
|
1995
|
+
const cleaned = {};
|
|
1996
|
+
for (const [key, value] of Object.entries(extras)) if (!topLevel.includes(key)) cleaned[key] = value;
|
|
1997
|
+
if (author && authorKeys.length > 0) {
|
|
1998
|
+
const cleanedAuthor = {};
|
|
1999
|
+
for (const [key, value] of Object.entries(author)) if (!authorKeys.includes(key)) cleanedAuthor[key] = value;
|
|
2000
|
+
cleaned.author = cleanedAuthor;
|
|
2001
|
+
}
|
|
2002
|
+
update.run(Object.keys(cleaned).length > 0 ? JSON.stringify(cleaned) : null, row.cid);
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
1977
2005
|
_backfillTargetAuthorDomain() {
|
|
1978
2006
|
const log = logger_default("pkc-js:local-community:db-handler:_backfillTargetAuthorDomain");
|
|
1979
2007
|
const moderationsToUpdate = this._db.prepare(`
|
|
@@ -3908,6 +3936,10 @@ var DbHandler = class {
|
|
|
3908
3936
|
const newPathString = path$1.join(dataPath, "communities", newDbName);
|
|
3909
3937
|
await fs$1.promises.mkdir(path$1.dirname(oldPathString), { recursive: true });
|
|
3910
3938
|
await fs$1.promises.mkdir(path$1.dirname(newPathString), { recursive: true });
|
|
3939
|
+
const doneWritingNewDbFile = markCommunityDbAsBeingWritten({
|
|
3940
|
+
dataPath,
|
|
3941
|
+
communityAddress: newDbName
|
|
3942
|
+
});
|
|
3911
3943
|
try {
|
|
3912
3944
|
if (!fs$1.existsSync(oldPathString)) log(`Old DB file ${oldPathString} does not exist. Cannot backup/rename.`);
|
|
3913
3945
|
else {
|
|
@@ -3920,14 +3952,12 @@ var DbHandler = class {
|
|
|
3920
3952
|
});
|
|
3921
3953
|
if (os.type() === "Windows_NT") await deleteOldCommunityInWindows(oldPathString, this._community._pkc);
|
|
3922
3954
|
else await fs$1.promises.rm(oldPathString, { force: true });
|
|
3923
|
-
if (!fs$1.existsSync(oldPathString)) await fs$1.promises.rm(getStartLockPath({
|
|
3924
|
-
dataPath,
|
|
3925
|
-
communityAddress: oldDbName
|
|
3926
|
-
}), { force: true });
|
|
3927
3955
|
}
|
|
3928
3956
|
} catch (error) {
|
|
3929
3957
|
log.error(`Failed to backup/rename database from ${oldPathString} to ${newPathString}: `, error);
|
|
3930
3958
|
throw error;
|
|
3959
|
+
} finally {
|
|
3960
|
+
doneWritingNewDbFile();
|
|
3931
3961
|
}
|
|
3932
3962
|
this._dbConfig = {
|
|
3933
3963
|
...this._dbConfig,
|
|
@@ -3940,25 +3970,11 @@ var DbHandler = class {
|
|
|
3940
3970
|
const communityAddress = this._community.address;
|
|
3941
3971
|
const dataPath = this._community._pkc.dataPath;
|
|
3942
3972
|
await this.initDbIfNeeded();
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
});
|
|
3947
|
-
if (!takeStartLock({
|
|
3948
|
-
db: this._db,
|
|
3949
|
-
dataPath,
|
|
3950
|
-
communityAddress
|
|
3951
|
-
})) throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { communityAddress });
|
|
3973
|
+
if (this._db.readonly) throw Error("The start of a community can't be claimed on a read-only connection to its DB");
|
|
3974
|
+
const registry = getCommunitiesRegistry(this._community._pkc);
|
|
3975
|
+
if (!registry.claimStart(communityAddress)) throw new PKCError("ERR_COMMUNITY_ALREADY_STARTED", { communityAddress });
|
|
3952
3976
|
if (!fs$1.existsSync(path$1.join(dataPath, "communities", communityAddress))) {
|
|
3953
|
-
|
|
3954
|
-
db: this._db,
|
|
3955
|
-
dataPath,
|
|
3956
|
-
communityAddress
|
|
3957
|
-
});
|
|
3958
|
-
fs$1.rmSync(getStartLockPath({
|
|
3959
|
-
dataPath,
|
|
3960
|
-
communityAddress
|
|
3961
|
-
}), { force: true });
|
|
3977
|
+
registry.unregisterCommunity(communityAddress);
|
|
3962
3978
|
throw new PKCError("CAN_NOT_LOAD_LOCAL_COMMUNITY_IF_DB_DOES_NOT_EXIST", {
|
|
3963
3979
|
communityAddress,
|
|
3964
3980
|
dataPath
|
|
@@ -3968,26 +3984,22 @@ var DbHandler = class {
|
|
|
3968
3984
|
log(`Locked the start of community (${communityAddress}) successfully`);
|
|
3969
3985
|
}
|
|
3970
3986
|
holdsStartLock() {
|
|
3971
|
-
return this._startLockAddress !== void 0
|
|
3987
|
+
return this._startLockAddress !== void 0;
|
|
3972
3988
|
}
|
|
3973
3989
|
async unlockCommunityStart() {
|
|
3974
3990
|
const log = logger_default("pkc-js:local-community:db-handler:unlock:start");
|
|
3975
3991
|
const communityAddress = this._startLockAddress;
|
|
3976
3992
|
if (communityAddress === void 0) return;
|
|
3977
3993
|
this._startLockAddress = void 0;
|
|
3978
|
-
|
|
3979
|
-
releaseStartLock({
|
|
3980
|
-
db: this._db,
|
|
3981
|
-
dataPath: this._community._pkc.dataPath,
|
|
3982
|
-
communityAddress
|
|
3983
|
-
});
|
|
3994
|
+
getCommunitiesRegistry(this._community._pkc).releaseStart(communityAddress);
|
|
3984
3995
|
log(`Unlocked start of community (${communityAddress})`);
|
|
3985
3996
|
}
|
|
3986
3997
|
async isCommunityStartLocked(communityAddress = this._community.address) {
|
|
3987
|
-
return
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3998
|
+
return getCommunitiesRegistry(this._community._pkc).isStarted(communityAddress);
|
|
3999
|
+
}
|
|
4000
|
+
confirmCommunityStartIsStillOurs() {
|
|
4001
|
+
if (this._startLockAddress === void 0) return "owned";
|
|
4002
|
+
return getCommunitiesRegistry(this._community._pkc).confirmStart(this._startLockAddress);
|
|
3991
4003
|
}
|
|
3992
4004
|
runInWriteTransaction(write) {
|
|
3993
4005
|
if (this._db.inTransaction) return write();
|
|
@@ -5771,6 +5783,22 @@ async function checkWireFormatAndCommunityAuthor(community, publication, log, au
|
|
|
5771
5783
|
if (publication.timestamp <= timestamp() - 300 || publication.timestamp >= timestamp() + 300) return messages.ERR_PUBLICATION_TIMESTAMP_IS_NOT_IN_PROPER_RANGE;
|
|
5772
5784
|
if (typeof authorCommunity?.banExpiresAt === "number" && authorCommunity.banExpiresAt > timestamp()) return messages.ERR_AUTHOR_IS_BANNED;
|
|
5773
5785
|
}
|
|
5786
|
+
async function checkAuthorWalletProofs(publication, log) {
|
|
5787
|
+
const wallets = publication.author?.wallets;
|
|
5788
|
+
if (!wallets) return void 0;
|
|
5789
|
+
const authorPublicKey = await getPKCAddressFromPublicKey(publication.signature.publicKey);
|
|
5790
|
+
for (const [chainTicker, entry] of Object.entries(wallets)) {
|
|
5791
|
+
const result = verifyAuthorWalletEntry({
|
|
5792
|
+
entry,
|
|
5793
|
+
authorPublicKey,
|
|
5794
|
+
nowSeconds: timestamp()
|
|
5795
|
+
});
|
|
5796
|
+
if (result.outcome === "invalid") {
|
|
5797
|
+
log("Rejecting publication: invalid author.wallets proof", chainTicker, result.reason);
|
|
5798
|
+
return `${messages.ERR_AUTHOR_WALLET_PROOF_IS_INVALID}. Chain ticker: ${chainTicker}. ${result.reason}`;
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
}
|
|
5774
5802
|
async function checkAuthorIdentity(community, publication, log) {
|
|
5775
5803
|
if (publication.author && Object.keys(publication.author).length === 0) return messages.ERR_PUBLICATION_AUTHOR_IS_AN_EMPTY_OBJECT;
|
|
5776
5804
|
if (publication.author && r$2(t$6(publication.author), AuthorReservedFields).length > 0) return messages.ERR_PUBLICATION_AUTHOR_HAS_RESERVED_FIELD;
|
|
@@ -6024,6 +6052,8 @@ async function checkPublicationValidity({ community, request, publication, autho
|
|
|
6024
6052
|
if (wireResult) return wireResult;
|
|
6025
6053
|
const authorResult = await checkAuthorIdentity(community, publication, log);
|
|
6026
6054
|
if (authorResult) return authorResult;
|
|
6055
|
+
const walletProofResult = await checkAuthorWalletProofs(publication, log);
|
|
6056
|
+
if (walletProofResult) return walletProofResult;
|
|
6027
6057
|
const parentResult = await checkParentAndPostState(community, request, publication, authorIdentityMatcher);
|
|
6028
6058
|
if (parentResult) return parentResult;
|
|
6029
6059
|
if (Buffer.byteLength(JSON.stringify(publication)) / 1e3 > 40) return messages.ERR_REQUEST_PUBLICATION_OVER_ALLOWED_SIZE;
|
|
@@ -7017,6 +7047,21 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
7017
7047
|
});
|
|
7018
7048
|
};
|
|
7019
7049
|
while (!shouldStopPublishLoop()) {
|
|
7050
|
+
if (isCommunityStartTakenByAnotherInstance(community, log)) {
|
|
7051
|
+
const error = new PKCError("ERR_COMMUNITY_START_TAKEN_BY_ANOTHER_PKC_INSTANCE", {
|
|
7052
|
+
address: community.address,
|
|
7053
|
+
dataPath: community._pkc.dataPath
|
|
7054
|
+
});
|
|
7055
|
+
log.error(error);
|
|
7056
|
+
community._startTakenByAnotherInstance = true;
|
|
7057
|
+
try {
|
|
7058
|
+
community.emit("error", error);
|
|
7059
|
+
} catch (e) {
|
|
7060
|
+
log.error(`A listener of the error of community (${community.address}) threw, or there is none`, e);
|
|
7061
|
+
}
|
|
7062
|
+
community.stop().catch((e) => log.error(`Failed to stop community (${community.address}) after its start was taken`, e));
|
|
7063
|
+
break;
|
|
7064
|
+
}
|
|
7020
7065
|
let lastSyncFailed = false;
|
|
7021
7066
|
try {
|
|
7022
7067
|
await syncIpnsWithDb(community);
|
|
@@ -7032,6 +7077,14 @@ async function publishLoop(community, syncIntervalMs) {
|
|
|
7032
7077
|
}
|
|
7033
7078
|
log("Stopping the publishing loop of community", community.address);
|
|
7034
7079
|
}
|
|
7080
|
+
function isCommunityStartTakenByAnotherInstance(community, log) {
|
|
7081
|
+
try {
|
|
7082
|
+
return community._dbHandler.confirmCommunityStartIsStillOurs() === "taken";
|
|
7083
|
+
} catch (e) {
|
|
7084
|
+
log.error(`Failed to confirm that community (${community.address}) is still started by this PKC instance`, e);
|
|
7085
|
+
return false;
|
|
7086
|
+
}
|
|
7087
|
+
}
|
|
7035
7088
|
async function initBeforeStarting(community) {
|
|
7036
7089
|
community.protocolVersion = version_default.PROTOCOL_VERSION;
|
|
7037
7090
|
if (!community.signer?.address) throw new PKCError("ERR_COMMUNITY_SIGNER_NOT_DEFINED");
|
|
@@ -7106,6 +7159,7 @@ async function startCommunity({ community, releaseMark }) {
|
|
|
7106
7159
|
const log = logger_default("pkc-js:local-community:start");
|
|
7107
7160
|
while (community._stoppedEditsInFlight.size > 0) await Promise.allSettled([...community._stoppedEditsInFlight]);
|
|
7108
7161
|
community._stopHasBeenCalled = false;
|
|
7162
|
+
community._startTakenByAnotherInstance = false;
|
|
7109
7163
|
community._lastProvidedBrowserDialableSelfAddrs = void 0;
|
|
7110
7164
|
community._lastAddressReprovideCheckAt = void 0;
|
|
7111
7165
|
if (!community._clientsManager.getDefaultKuboRpcClientOrHelia()) throw Error("You need to define an IPFS client in your pkc instance to be able to start a local community");
|
|
@@ -7338,15 +7392,19 @@ async function stopCommunity(community) {
|
|
|
7338
7392
|
}
|
|
7339
7393
|
community._publishLoopPromise = void 0;
|
|
7340
7394
|
}
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7395
|
+
const startTakenByAnotherInstance = community._startTakenByAnotherInstance || isCommunityStartTakenByAnotherInstance(community, log);
|
|
7396
|
+
community._startTakenByAnotherInstance = false;
|
|
7397
|
+
if (!startTakenByAnotherInstance) {
|
|
7398
|
+
try {
|
|
7399
|
+
await unpinStaleCids(community, { bypassGracePeriod: true });
|
|
7400
|
+
} catch (e) {
|
|
7401
|
+
log.error("Failed to unpin stale cids and remove mfs paths before stopping", e);
|
|
7402
|
+
}
|
|
7403
|
+
try {
|
|
7404
|
+
await updateDbInternalState(community, () => community.updateCid ? community.toJSONInternalAfterFirstUpdate() : community.toJSONInternalBeforeFirstUpdate());
|
|
7405
|
+
} catch (e) {
|
|
7406
|
+
log.error("Failed to update db internal state before stopping", e);
|
|
7407
|
+
}
|
|
7350
7408
|
}
|
|
7351
7409
|
try {
|
|
7352
7410
|
await community._dbHandler.unlockCommunityStart();
|
|
@@ -7466,7 +7524,11 @@ async function deleteCommunityWhileMarked(community) {
|
|
|
7466
7524
|
community._dbHandler.destoryConnection();
|
|
7467
7525
|
}
|
|
7468
7526
|
await moveCommunityDbToDeletedDirectory(community.address, community._pkc);
|
|
7469
|
-
|
|
7527
|
+
try {
|
|
7528
|
+
unregisterLocalCommunity(community._pkc, community.address);
|
|
7529
|
+
} catch (e) {
|
|
7530
|
+
log.error(`Failed to remove deleted community (${community.address}) from the communities registry`, e);
|
|
7531
|
+
}
|
|
7470
7532
|
log(`Deleted community (${community.address}) successfully`);
|
|
7471
7533
|
}
|
|
7472
7534
|
//#endregion
|
|
@@ -7578,8 +7640,15 @@ function deriveNameAndAddressEdit(community, editOptions) {
|
|
|
7578
7640
|
name: isStringDomain(address) ? address : void 0
|
|
7579
7641
|
};
|
|
7580
7642
|
}
|
|
7581
|
-
function listRenamedCommunityNow(community) {
|
|
7582
|
-
|
|
7643
|
+
function listRenamedCommunityNow(community, { oldAddress, newAddress }) {
|
|
7644
|
+
try {
|
|
7645
|
+
getCommunitiesRegistry(community._pkc).renameCommunity({
|
|
7646
|
+
oldAddress,
|
|
7647
|
+
newAddress
|
|
7648
|
+
});
|
|
7649
|
+
} catch (error) {
|
|
7650
|
+
logger_default("pkc-js:local-community:edit").error(`Failed to list the renamed community under its new address (${newAddress}) in the communities registry`, error);
|
|
7651
|
+
}
|
|
7583
7652
|
}
|
|
7584
7653
|
async function movePostUpdatesFolderBack({ community, oldAddress, newAddress, log }) {
|
|
7585
7654
|
try {
|
|
@@ -7708,7 +7777,10 @@ async function editPropsOnStartedCommunity(community, parsedEditOptions, pagesEd
|
|
|
7708
7777
|
});
|
|
7709
7778
|
throw error;
|
|
7710
7779
|
}
|
|
7711
|
-
listRenamedCommunityNow(community
|
|
7780
|
+
listRenamedCommunityNow(community, {
|
|
7781
|
+
oldAddress,
|
|
7782
|
+
newAddress
|
|
7783
|
+
});
|
|
7712
7784
|
community.setAddress(newAddress);
|
|
7713
7785
|
await community._dbHandler.initDbIfNeeded();
|
|
7714
7786
|
await updateDbInternalState(community, { ...parsedEditOptions });
|
|
@@ -7798,7 +7870,10 @@ async function editPropsOnNotStartedCommunityWhileMarked(community, parsedEditOp
|
|
|
7798
7870
|
log
|
|
7799
7871
|
})).error;
|
|
7800
7872
|
}
|
|
7801
|
-
listRenamedCommunityNow(community
|
|
7873
|
+
listRenamedCommunityNow(community, {
|
|
7874
|
+
oldAddress,
|
|
7875
|
+
newAddress
|
|
7876
|
+
});
|
|
7802
7877
|
await community._dbHandler.initDbIfNeeded();
|
|
7803
7878
|
community.setAddress(parsedEditOptions.address);
|
|
7804
7879
|
}
|
|
@@ -8076,6 +8151,7 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8076
8151
|
this._pageSorts = void 0;
|
|
8077
8152
|
this._pageSortFactories = void 0;
|
|
8078
8153
|
this._reportedChallengeLoadFailures = void 0;
|
|
8154
|
+
this._startTakenByAnotherInstance = false;
|
|
8079
8155
|
this._publishLoopPromise = void 0;
|
|
8080
8156
|
this._updateLoopPromise = void 0;
|
|
8081
8157
|
this._startOrUpdateInFlight = void 0;
|
|
@@ -8186,11 +8262,6 @@ var LocalCommunity = class extends RpcLocalCommunity {
|
|
|
8186
8262
|
}
|
|
8187
8263
|
async _updateStartedValue() {
|
|
8188
8264
|
this.started = await this._dbHandler.isCommunityStartLocked(this.address);
|
|
8189
|
-
try {
|
|
8190
|
-
refreshCommunitiesList(this._pkc);
|
|
8191
|
-
} catch (e) {
|
|
8192
|
-
logger_default("pkc-js:local-community:_updateStartedValue").error("Failed to refresh pkc.communities", e);
|
|
8193
|
-
}
|
|
8194
8265
|
}
|
|
8195
8266
|
async initNewLocalCommunityPropsNoMerge(newProps) {
|
|
8196
8267
|
return initNewLocalCommunityPropsNoMerge(this, newProps);
|
|
@@ -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-BzZbcwm-.js";
|
|
2
2
|
export { LocalCommunity, createNewLocalCommunityDb, updateInstancePropsWithStartedCommunityOrDb };
|